From c622641218155c2d6b89112476bd4fa46037203d Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Wed, 7 Jan 2009 17:53:53 +0000 Subject: [PATCH] import CVS -- 7 january 2009 5:54 --- Changes | 2390 ++ INSTALL | 322 + LICENSE | 626 + Makefile | 773 + Makefile.nt | 656 + README | 138 + README.win32 | 375 + Upgrading | 109 + VERSION | 6 + _tags | 85 + asmcomp/.cvsignore | 6 + asmcomp/alpha/arch.ml | 83 + asmcomp/alpha/emit.mlp | 861 + asmcomp/alpha/proc.ml | 217 + asmcomp/alpha/reload.ml | 18 + asmcomp/alpha/scheduling.ml | 70 + asmcomp/alpha/selection.ml | 83 + asmcomp/amd64/arch.ml | 111 + asmcomp/amd64/emit.mlp | 812 + asmcomp/amd64/emit_nt.mlp | 771 + asmcomp/amd64/proc.ml | 201 + asmcomp/amd64/proc_nt.ml | 233 + asmcomp/amd64/reload.ml | 121 + asmcomp/amd64/scheduling.ml | 20 + asmcomp/amd64/selection.ml | 235 + asmcomp/arm/arch.ml | 86 + asmcomp/arm/emit.mlp | 676 + asmcomp/arm/proc.ml | 197 + asmcomp/arm/reload.ml | 18 + asmcomp/arm/scheduling.ml | 53 + asmcomp/arm/selection.ml | 132 + asmcomp/asmgen.ml | 138 + asmcomp/asmgen.mli | 25 + asmcomp/asmlibrarian.ml | 74 + asmcomp/asmlibrarian.mli | 27 + asmcomp/asmlink.ml | 383 + asmcomp/asmlink.mli | 42 + asmcomp/asmpackager.ml | 208 + asmcomp/asmpackager.mli | 30 + asmcomp/clambda.ml | 66 + asmcomp/clambda.mli | 66 + asmcomp/closure.ml | 803 + asmcomp/closure.mli | 18 + asmcomp/cmm.ml | 132 + asmcomp/cmm.mli | 118 + asmcomp/cmmgen.ml | 2082 ++ asmcomp/cmmgen.mli | 32 + asmcomp/codegen.ml | 101 + asmcomp/codegen.mli | 29 + asmcomp/coloring.ml | 278 + asmcomp/coloring.mli | 17 + asmcomp/comballoc.ml | 90 + asmcomp/comballoc.mli | 17 + asmcomp/compilenv.ml | 243 + asmcomp/compilenv.mli | 110 + asmcomp/debuginfo.ml | 52 + asmcomp/debuginfo.mli | 31 + asmcomp/emit.mli | 20 + asmcomp/emitaux.ml | 158 + asmcomp/emitaux.mli | 47 + asmcomp/hppa/arch.ml | 74 + asmcomp/hppa/emit.mlp | 1040 + asmcomp/hppa/proc.ml | 224 + asmcomp/hppa/reload.ml | 38 + asmcomp/hppa/scheduling.ml | 59 + asmcomp/hppa/selection.ml | 109 + asmcomp/i386/arch.ml | 154 + asmcomp/i386/emit.mlp | 990 + asmcomp/i386/emit_nt.mlp | 906 + asmcomp/i386/proc.ml | 188 + asmcomp/i386/proc_nt.ml | 186 + asmcomp/i386/reload.ml | 83 + asmcomp/i386/scheduling.ml | 22 + asmcomp/i386/selection.ml | 327 + asmcomp/ia64/arch.ml | 88 + asmcomp/ia64/emit.mlp | 1327 + asmcomp/ia64/proc.ml | 217 + asmcomp/ia64/reload.ml | 18 + asmcomp/ia64/scheduling.ml | 20 + asmcomp/ia64/selection.ml | 178 + asmcomp/interf.ml | 173 + asmcomp/interf.mli | 18 + asmcomp/linearize.ml | 267 + asmcomp/linearize.mli | 55 + asmcomp/liveness.ml | 120 + asmcomp/liveness.mli | 20 + asmcomp/m68k/README | 8 + asmcomp/mach.ml | 132 + asmcomp/mach.mli | 93 + asmcomp/mips/arch.ml | 71 + asmcomp/mips/emit.mlp | 594 + asmcomp/mips/proc.ml | 210 + asmcomp/mips/reload.ml | 18 + asmcomp/mips/scheduling.ml | 20 + asmcomp/mips/selection.ml | 43 + asmcomp/power/arch.ml | 87 + asmcomp/power/emit.mlp | 964 + asmcomp/power/proc.ml | 241 + asmcomp/power/reload.ml | 18 + asmcomp/power/scheduling.ml | 66 + asmcomp/power/selection.ml | 103 + asmcomp/printcmm.ml | 204 + asmcomp/printcmm.mli | 27 + asmcomp/printlinear.ml | 77 + asmcomp/printlinear.mli | 21 + asmcomp/printmach.ml | 219 + asmcomp/printmach.mli | 31 + asmcomp/proc.mli | 50 + asmcomp/reg.ml | 144 + asmcomp/reg.mli | 56 + asmcomp/reload.mli | 18 + asmcomp/reloadgen.ml | 140 + asmcomp/reloadgen.mli | 26 + asmcomp/schedgen.ml | 356 + asmcomp/schedgen.mli | 46 + asmcomp/scheduling.mli | 17 + asmcomp/selectgen.ml | 826 + asmcomp/selectgen.mli | 75 + asmcomp/selection.mli | 18 + asmcomp/sparc/arch.ml | 75 + asmcomp/sparc/emit.mlp | 775 + asmcomp/sparc/proc.ml | 215 + asmcomp/sparc/reload.ml | 18 + asmcomp/sparc/scheduling.ml | 65 + asmcomp/sparc/selection.ml | 86 + asmcomp/spill.ml | 403 + asmcomp/spill.mli | 18 + asmcomp/split.ml | 210 + asmcomp/split.mli | 17 + asmrun/.cvsignore | 34 + asmrun/.depend | 1164 + asmrun/Makefile | 190 + asmrun/Makefile.nt | 81 + asmrun/alpha.S | 440 + asmrun/amd64.S | 392 + asmrun/amd64nt.asm | 464 + asmrun/arm.S | 344 + asmrun/backtrace.c | 225 + asmrun/fail.c | 207 + asmrun/hppa.S | 534 + asmrun/i386.S | 431 + asmrun/i386nt.asm | 323 + asmrun/ia64.S | 530 + asmrun/m68k.S | 244 + asmrun/mips.s | 386 + asmrun/natdynlink.c | 126 + asmrun/natdynlink.h | 0 asmrun/power-aix.S | 513 + asmrun/power-elf.S | 421 + asmrun/power-rhapsody.S | 474 + asmrun/roots.c | 359 + asmrun/signals_asm.c | 257 + asmrun/signals_osdep.h | 254 + asmrun/sparc.S | 407 + asmrun/stack.h | 129 + asmrun/startup.c | 181 + boot/.cvsignore | 5 + boot/myocamlbuild.boot | Bin 0 -> 394071 bytes boot/ocamlc | Bin 0 -> 1040659 bytes boot/ocamldep | Bin 0 -> 288221 bytes boot/ocamllex | Bin 0 -> 164510 bytes build/.cvsignore | 1 + build/boot-c-parts-windows.sh | 25 + build/boot-c-parts.sh | 22 + build/boot.sh | 23 + build/buildbot | 113 + build/camlp4-bootstrap.sh | 34 + build/camlp4-byte-only.sh | 22 + build/camlp4-native-only.sh | 22 + build/camlp4-targets.sh | 34 + build/distclean.sh | 45 + build/fastworld.sh | 52 + build/install.sh | 567 + build/mixed-boot.sh | 22 + build/mkconfig.sh | 12 + build/mkmyocamlbuild_config.sh | 40 + build/mkruntimedef.sh | 9 + build/myocamlbuild.sh | 19 + build/new-build-system | 41 + build/ocamlbuild-byte-only.sh | 22 + build/ocamlbuild-native-only.sh | 22 + build/ocamlbuildlib-native-only.sh | 22 + build/otherlibs-targets.sh | 109 + build/partial-install.sh | 186 + build/targets.sh | 63 + build/tolower.sed | 11 + build/world.all.sh | 12 + build/world.byte.sh | 9 + build/world.native.sh | 10 + build/world.sh | 34 + bytecomp/.cvsignore | 2 + bytecomp/bytegen.ml | 867 + bytecomp/bytegen.mli | 21 + bytecomp/bytelibrarian.ml | 122 + bytecomp/bytelibrarian.mli | 34 + bytecomp/bytelink.ml | 535 + bytecomp/bytelink.mli | 36 + bytecomp/bytepackager.ml | 251 + bytecomp/bytepackager.mli | 29 + bytecomp/bytesections.ml | 99 + bytecomp/bytesections.mli | 54 + bytecomp/cmo_format.mli | 61 + bytecomp/dll.ml | 172 + bytecomp/dll.mli | 61 + bytecomp/emitcode.ml | 409 + bytecomp/emitcode.mli | 40 + bytecomp/instruct.ml | 110 + bytecomp/instruct.mli | 126 + bytecomp/lambda.ml | 427 + bytecomp/lambda.mli | 208 + bytecomp/matching.ml | 2706 ++ bytecomp/matching.mli | 43 + bytecomp/meta.ml | 26 + bytecomp/meta.mli | 28 + bytecomp/printinstr.ml | 115 + bytecomp/printinstr.mli | 22 + bytecomp/printlambda.ml | 315 + bytecomp/printlambda.mli | 20 + bytecomp/runtimedef.mli | 18 + bytecomp/simplif.ml | 412 + bytecomp/simplif.mli | 19 + bytecomp/switch.ml | 811 + bytecomp/switch.mli | 82 + bytecomp/symtable.ml | 378 + bytecomp/symtable.mli | 59 + bytecomp/translclass.ml | 821 + bytecomp/translclass.mli | 28 + bytecomp/translcore.ml | 1048 + bytecomp/translcore.mli | 51 + bytecomp/translmod.ml | 712 + bytecomp/translmod.mli | 41 + bytecomp/translobj.ml | 160 + bytecomp/translobj.mli | 30 + bytecomp/typeopt.ml | 134 + bytecomp/typeopt.mli | 22 + byterun/.cvsignore | 17 + byterun/.depend | 410 + byterun/Makefile | 73 + byterun/Makefile.common | 93 + byterun/Makefile.nt | 54 + byterun/alloc.c | 186 + byterun/alloc.h | 47 + byterun/array.c | 193 + byterun/backtrace.c | 306 + byterun/backtrace.h | 32 + byterun/callback.c | 248 + byterun/callback.h | 49 + byterun/compact.c | 441 + byterun/compact.h | 27 + byterun/compare.c | 293 + byterun/compare.h | 21 + byterun/compatibility.h | 372 + byterun/config.h | 168 + byterun/custom.c | 102 + byterun/custom.h | 62 + byterun/debugger.c | 419 + byterun/debugger.h | 110 + byterun/dynlink.c | 267 + byterun/dynlink.h | 38 + byterun/exec.h | 62 + byterun/extern.c | 726 + byterun/fail.c | 157 + byterun/fail.h | 77 + byterun/finalise.c | 249 + byterun/finalise.h | 29 + byterun/fix_code.c | 162 + byterun/fix_code.h | 42 + byterun/floats.c | 441 + byterun/freelist.c | 545 + byterun/freelist.h | 36 + byterun/gc.h | 58 + byterun/gc_ctrl.c | 494 + byterun/gc_ctrl.h | 42 + byterun/globroots.c | 261 + byterun/globroots.h | 27 + byterun/hash.c | 157 + byterun/instrtrace.c | 265 + byterun/instrtrace.h | 31 + byterun/instruct.h | 61 + byterun/int64_emul.h | 272 + byterun/int64_format.h | 107 + byterun/int64_native.h | 50 + byterun/intern.c | 715 + byterun/interp.c | 1147 + byterun/interp.h | 33 + byterun/intext.h | 162 + byterun/ints.c | 738 + byterun/io.c | 768 + byterun/io.h | 126 + byterun/lexing.c | 231 + byterun/main.c | 59 + byterun/major_gc.c | 509 + byterun/major_gc.h | 62 + byterun/md5.c | 311 + byterun/md5.h | 41 + byterun/memory.c | 548 + byterun/memory.h | 459 + byterun/meta.c | 174 + byterun/minor_gc.c | 321 + byterun/minor_gc.h | 58 + byterun/misc.c | 125 + byterun/misc.h | 136 + byterun/mlvalues.h | 295 + byterun/obj.c | 247 + byterun/osdeps.h | 72 + byterun/parsing.c | 302 + byterun/prims.h | 36 + byterun/printexc.c | 126 + byterun/printexc.h | 27 + byterun/reverse.h | 88 + byterun/roots.c | 104 + byterun/roots.h | 38 + byterun/signals.c | 307 + byterun/signals.h | 51 + byterun/signals_byt.c | 95 + byterun/signals_machdep.h | 62 + byterun/stacks.c | 104 + byterun/stacks.h | 41 + byterun/startup.c | 478 + byterun/startup.h | 40 + byterun/str.c | 156 + byterun/sys.c | 346 + byterun/sys.h | 30 + byterun/terminfo.c | 132 + byterun/ui.h | 28 + byterun/unix.c | 322 + byterun/weak.c | 193 + byterun/weak.h | 26 + byterun/win32.c | 545 + camlp4/.cvsignore | 3 + camlp4/.vcs | 4 + camlp4/CHANGES | 898 + camlp4/Camlp4.mlpack | 9 + camlp4/Camlp4/.cvsignore | 0 camlp4/Camlp4/Camlp4Ast.partial.ml | 346 + camlp4/Camlp4/Debug.ml | 73 + camlp4/Camlp4/Debug.mli | 22 + camlp4/Camlp4/ErrorHandler.ml | 171 + camlp4/Camlp4/ErrorHandler.mli | 36 + camlp4/Camlp4/OCamlInitSyntax.ml | 256 + camlp4/Camlp4/Options.ml | 191 + camlp4/Camlp4/Options.mli | 26 + camlp4/Camlp4/PreCast.ml | 68 + camlp4/Camlp4/PreCast.mli | 76 + camlp4/Camlp4/Printers.mlpack | 5 + camlp4/Camlp4/Printers/DumpCamlp4Ast.ml | 51 + camlp4/Camlp4/Printers/DumpCamlp4Ast.mli | 21 + camlp4/Camlp4/Printers/DumpOCamlAst.ml | 53 + camlp4/Camlp4/Printers/DumpOCamlAst.mli | 21 + camlp4/Camlp4/Printers/Null.ml | 30 + camlp4/Camlp4/Printers/Null.mli | 22 + camlp4/Camlp4/Printers/OCaml.ml | 1092 + camlp4/Camlp4/Printers/OCaml.mli | 163 + camlp4/Camlp4/Printers/OCamlr.ml | 308 + camlp4/Camlp4/Printers/OCamlr.mli | 47 + camlp4/Camlp4/Register.ml | 170 + camlp4/Camlp4/Register.mli | 94 + camlp4/Camlp4/Sig.ml | 1370 + camlp4/Camlp4/Struct.mlpack | 15 + camlp4/Camlp4/Struct/.cvsignore | 2 + camlp4/Camlp4/Struct/AstFilters.ml | 37 + camlp4/Camlp4/Struct/Camlp4Ast.mlast | 543 + camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml | 1047 + camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli | 32 + camlp4/Camlp4/Struct/CleanAst.ml | 145 + camlp4/Camlp4/Struct/CommentFilter.ml | 56 + camlp4/Camlp4/Struct/CommentFilter.mli | 33 + camlp4/Camlp4/Struct/DynAst.ml | 91 + camlp4/Camlp4/Struct/DynLoader.ml | 84 + camlp4/Camlp4/Struct/DynLoader.mli | 20 + camlp4/Camlp4/Struct/EmptyError.ml | 22 + camlp4/Camlp4/Struct/EmptyError.mli | 19 + camlp4/Camlp4/Struct/EmptyPrinter.ml | 22 + camlp4/Camlp4/Struct/EmptyPrinter.mli | 19 + camlp4/Camlp4/Struct/FreeVars.ml | 128 + camlp4/Camlp4/Struct/FreeVars.mli | 48 + camlp4/Camlp4/Struct/Grammar.mlpack | 14 + camlp4/Camlp4/Struct/Grammar/Context.ml | 90 + camlp4/Camlp4/Struct/Grammar/Delete.ml | 163 + camlp4/Camlp4/Struct/Grammar/Dynamic.ml | 72 + camlp4/Camlp4/Struct/Grammar/Entry.ml | 91 + camlp4/Camlp4/Struct/Grammar/Failed.ml | 134 + camlp4/Camlp4/Struct/Grammar/Find.ml | 68 + camlp4/Camlp4/Struct/Grammar/Fold.ml | 94 + camlp4/Camlp4/Struct/Grammar/Fold.mli | 30 + camlp4/Camlp4/Struct/Grammar/Insert.ml | 328 + camlp4/Camlp4/Struct/Grammar/Parser.ml | 382 + camlp4/Camlp4/Struct/Grammar/Parser.mli | 68 + camlp4/Camlp4/Struct/Grammar/Print.ml | 268 + camlp4/Camlp4/Struct/Grammar/Print.mli | 47 + camlp4/Camlp4/Struct/Grammar/Search.ml | 91 + camlp4/Camlp4/Struct/Grammar/Static.ml | 83 + camlp4/Camlp4/Struct/Grammar/Structure.ml | 280 + camlp4/Camlp4/Struct/Grammar/Tools.ml | 89 + camlp4/Camlp4/Struct/Lexer.mll | 483 + camlp4/Camlp4/Struct/Loc.ml | 307 + camlp4/Camlp4/Struct/Loc.mli | 19 + camlp4/Camlp4/Struct/Quotation.ml | 167 + camlp4/Camlp4/Struct/Token.ml | 244 + camlp4/Camlp4/Struct/Token.mli | 35 + camlp4/Camlp4Bin.ml | 323 + camlp4/Camlp4Filters/Camlp4AstLifter.ml | 44 + camlp4/Camlp4Filters/Camlp4ExceptionTracer.ml | 68 + camlp4/Camlp4Filters/Camlp4FoldGenerator.ml | 609 + .../Camlp4Filters/Camlp4LocationStripper.ml | 36 + camlp4/Camlp4Filters/Camlp4MapGenerator.ml | 5 + camlp4/Camlp4Filters/Camlp4MetaGenerator.ml | 197 + camlp4/Camlp4Filters/Camlp4Profiler.ml | 77 + camlp4/Camlp4Filters/Camlp4TrashRemover.ml | 41 + camlp4/Camlp4Parsers/Camlp4AstLoader.ml | 49 + camlp4/Camlp4Parsers/Camlp4DebugParser.ml | 83 + camlp4/Camlp4Parsers/Camlp4GrammarParser.ml | 893 + .../Camlp4Parsers/Camlp4ListComprehension.ml | 148 + camlp4/Camlp4Parsers/Camlp4MacroParser.ml | 434 + .../Camlp4OCamlOriginalQuotationExpander.ml | 25 + camlp4/Camlp4Parsers/Camlp4OCamlParser.ml | 682 + .../Camlp4Parsers/Camlp4OCamlParserParser.ml | 60 + .../Camlp4OCamlReloadedParser.ml | 94 + .../Camlp4Parsers/Camlp4OCamlRevisedParser.ml | 1786 ++ .../Camlp4OCamlRevisedParserParser.ml | 394 + .../Camlp4OCamlRevisedQuotationExpander.ml | 24 + camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml | 205 + .../Camlp4Parsers/Camlp4QuotationExpander.ml | 33 + camlp4/Camlp4Printers/Camlp4AstDumper.ml | 19 + camlp4/Camlp4Printers/Camlp4AutoPrinter.ml | 24 + camlp4/Camlp4Printers/Camlp4NullDumper.ml | 19 + camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml | 19 + camlp4/Camlp4Printers/Camlp4OCamlPrinter.ml | 19 + .../Camlp4OCamlRevisedPrinter.ml | 19 + camlp4/Camlp4Top.mlpack | 2 + camlp4/Camlp4Top/Rprint.ml | 472 + camlp4/Camlp4Top/Top.ml | 147 + camlp4/Camlp4_config.ml | 39 + camlp4/Camlp4_config.mli | 34 + camlp4/ICHANGES | 27 + camlp4/Makefile | 99 + camlp4/Makefile.ml | 359 + camlp4/boot/.cvsignore | 5 + camlp4/boot/Camlp4.ml | 20570 ++++++++++++++++ camlp4/boot/Camlp4.ml4 | 79 + camlp4/boot/Camlp4Ast.ml | 5692 +++++ camlp4/boot/Makefile | 24 + camlp4/boot/camlp4boot.ml | 14596 +++++++++++ camlp4/boot/camlp4boot.ml4 | 10 + camlp4/build/.cvsignore | 7 + camlp4/camlp4.odocl | 1 + camlp4/camlp4fulllib.mllib | 35 + camlp4/camlp4lib.mllib | 3 + camlp4/camlp4prof.ml | 24 + camlp4/camlp4prof.mli | 3 + camlp4/examples/_tags | 19 + camlp4/examples/all.itarget | 11 + camlp4/examples/apply_operator.ml | 6 + camlp4/examples/apply_operator_test.ml | 3 + camlp4/examples/arith.ml | 49 + camlp4/examples/debug_extension.ml | 37 + camlp4/examples/ex_str.ml | 22 + camlp4/examples/ex_str_test.ml | 1 + camlp4/examples/expression_closure.ml | 24 + camlp4/examples/expression_closure_filter.ml | 50 + camlp4/examples/expression_closure_test.ml | 14 + camlp4/examples/fancy_lambda_quot.ml | 159 + camlp4/examples/fancy_lambda_quot_test.ml | 22 + camlp4/examples/free_vars_test.ml | 72 + camlp4/examples/gen_match_case.ml | 12 + camlp4/examples/gen_type_N.ml | 33 + camlp4/examples/gettext_test.ml | 1 + camlp4/examples/global_handler.ml | 20 + camlp4/examples/global_handler_test.ml | 12 + camlp4/examples/lambda_parser.ml | 34 + camlp4/examples/lambda_quot.ml | 38 + camlp4/examples/lambda_quot_expr.ml | 41 + camlp4/examples/lambda_quot_patt.ml | 41 + camlp4/examples/lambda_test.ml | 13 + camlp4/examples/macros.ml | 67 + camlp4/examples/parse_files.ml | 29 + camlp4/examples/syb_fold.ml | 90 + camlp4/examples/syb_map.ml | 51 + camlp4/examples/test.itarget | 8 + camlp4/examples/test_macros.ml | 15 + camlp4/examples/test_type_quotation.ml | 3 + camlp4/examples/type_quotation.ml | 18 + camlp4/man/.cvsignore | 2 + camlp4/man/Makefile | 21 + camlp4/man/camlp4.1.tpl | 279 + camlp4/man/camlp4.help.tpl | 1 + camlp4/mkcamlp4.ml | 68 + camlp4/test/fixtures/assert.ml | 3 + .../fixtures/backquoted_irrefutable_tuple.ml | 3 + camlp4/test/fixtures/backquoted_record.ml | 4 + camlp4/test/fixtures/backquoted_tuple.ml | 3 + camlp4/test/fixtures/big-tab1.ml | 704 + camlp4/test/fixtures/big-tab2.ml | 18282 ++++++++++++++ camlp4/test/fixtures/big-tab3.ml | 20001 +++++++++++++++ camlp4/test/fixtures/bug-4058.ml | 4 + camlp4/test/fixtures/bug-4337.ml | 1 + camlp4/test/fixtures/bug-by-vincent-balat.ml | 1 + .../fixtures/bug-camlp4o-benjamin-monate.ml | 15 + .../fixtures/bug-camlp4o-constr-arity-expr.ml | 8 + .../test/fixtures/bug-camlp4o-constr-arity.ml | 75 + camlp4/test/fixtures/bug_escaping_quot.ml | 7 + camlp4/test/fixtures/chars.ml | 1 + camlp4/test/fixtures/class_expr_quot.ml | 27 + camlp4/test/fixtures/comments.ml | 66 + camlp4/test/fixtures/comments.mli | 106 + camlp4/test/fixtures/comments2.ml | 70 + camlp4/test/fixtures/constant-parser.ml | 90 + camlp4/test/fixtures/curry-constr.ml | 3 + camlp4/test/fixtures/default_quotation.ml | 4 + .../test/fixtures/exception-with-eqn-bug.ml | 1 + camlp4/test/fixtures/external.ml | 1 + camlp4/test/fixtures/fun.ml | 7 + camlp4/test/fixtures/functor-perf.ml | 2019 ++ camlp4/test/fixtures/functor-perf2.gen.ml | 3029 +++ camlp4/test/fixtures/functor-perf2.ml | 29 + camlp4/test/fixtures/functor-perf3.ml | 50 + camlp4/test/fixtures/gen_map.ml | 8 + camlp4/test/fixtures/gram-fold.ml | 21 + camlp4/test/fixtures/gram-list.ml | 13 + camlp4/test/fixtures/gram-loc-lost.ml | 30 + camlp4/test/fixtures/gram-sub-rule.ml | 33 + camlp4/test/fixtures/gram-tree.ml | 22 + camlp4/test/fixtures/gram-tree2.ml | 22 + camlp4/test/fixtures/gram-tree3.ml | 23 + camlp4/test/fixtures/gram.ml | 2 + camlp4/test/fixtures/idents | 38 + camlp4/test/fixtures/idents1 | 499 + camlp4/test/fixtures/idents2 | 1219 + camlp4/test/fixtures/if.ml | 8 + camlp4/test/fixtures/label.ml | 1 + camlp4/test/fixtures/lambda_free.ml | 68 + camlp4/test/fixtures/loc-bug.ml | 3 + camlp4/test/fixtures/macrotest.ml | 70 + camlp4/test/fixtures/macrotest.mli | 25 + camlp4/test/fixtures/macrotest2.ml | 6 + camlp4/test/fixtures/macrotest3.ml | 11 + camlp4/test/fixtures/make_extend.ml | 1 + camlp4/test/fixtures/match.ml | 9 + camlp4/test/fixtures/match_parser.ml | 10 + camlp4/test/fixtures/meta_multi_term.ml | 16 + camlp4/test/fixtures/metalib.ml | 5 + .../test/fixtures/method_private_virtual.ml | 9 + camlp4/test/fixtures/mod.ml | 15 + camlp4/test/fixtures/mod2.ml | 8 + camlp4/test/fixtures/operators.ml | 7 + camlp4/test/fixtures/operators.mli | 1 + camlp4/test/fixtures/original_syntax.ml | 17 + camlp4/test/fixtures/outside-scope.ml | 21 + camlp4/test/fixtures/parser.ml | 61 + camlp4/test/fixtures/pp_let_in.ml | 10 + camlp4/test/fixtures/pp_let_in2.ml | 1 + camlp4/test/fixtures/pp_xml.ml | 31 + camlp4/test/fixtures/pprecordtyp.ml | 26 + camlp4/test/fixtures/pr4314.ml | 1 + camlp4/test/fixtures/pr4314gram1.ml | 36 + camlp4/test/fixtures/pr4314gram2.ml | 36 + camlp4/test/fixtures/pr4314gram3.ml | 36 + camlp4/test/fixtures/pr4314gram4.ml | 36 + camlp4/test/fixtures/pr4314gram5.ml | 38 + camlp4/test/fixtures/pr4329.ml | 50 + camlp4/test/fixtures/pr4330.ml | 57 + camlp4/test/fixtures/pr4357.ml | 16 + camlp4/test/fixtures/pr4357sample.ml | 3 + camlp4/test/fixtures/pr4357sample2.ml | 5 + camlp4/test/fixtures/pr4452.ml | 24 + camlp4/test/fixtures/private_row.ml | 27 + camlp4/test/fixtures/rec.ml | 2 + camlp4/test/fixtures/seq.ml | 1003 + camlp4/test/fixtures/seq2.ml | 3003 +++ camlp4/test/fixtures/simplify.ml | 11 + camlp4/test/fixtures/simplify_r.ml | 11 + camlp4/test/fixtures/stream-parser-bug.ml | 6 + camlp4/test/fixtures/string.ml | 1 + camlp4/test/fixtures/superfluous.ml | 12 + camlp4/test/fixtures/transform-examples.ml | 3 + camlp4/test/fixtures/try.ml | 6 + camlp4/test/fixtures/tuple_as_retval.ml | 3 + camlp4/test/fixtures/type.ml | 3 + camlp4/test/fixtures/type_decl.ml | 22 + camlp4/test/fixtures/unit.ml | 4 + camlp4/test/fixtures/use.ml | 4 + camlp4/test/fixtures/where.o.ml | 1 + camlp4/test/fixtures/where.r.ml | 1 + camlp4/unmaintained/Makefile | 20 + camlp4/unmaintained/compile/.cvsignore | 4 + camlp4/unmaintained/compile/.depend | 0 camlp4/unmaintained/compile/Makefile | 37 + camlp4/unmaintained/compile/comp_head.ml | 70 + camlp4/unmaintained/compile/comp_trail.ml | 33 + camlp4/unmaintained/compile/compile.ml | 574 + camlp4/unmaintained/compile/compile.sh | 27 + camlp4/unmaintained/etc/.cvsignore | 7 + camlp4/unmaintained/etc/.depend | 6 + camlp4/unmaintained/etc/Makefile | 62 + camlp4/unmaintained/etc/pa_fstream.ml | 163 + camlp4/unmaintained/etc/pa_ifdef.ml | 91 + camlp4/unmaintained/etc/pa_oop.ml | 155 + camlp4/unmaintained/etc/pa_ru.ml | 46 + camlp4/unmaintained/etc/parserify.ml | 305 + camlp4/unmaintained/etc/parserify.mli | 12 + camlp4/unmaintained/etc/pr_depend.ml | 321 + camlp4/unmaintained/etc/pr_extend.ml | 518 + camlp4/unmaintained/etc/pr_extfun.ml | 92 + camlp4/unmaintained/etc/pr_null.ml | 16 + camlp4/unmaintained/etc/pr_op.ml | 210 + camlp4/unmaintained/etc/pr_op_main.ml | 214 + camlp4/unmaintained/etc/pr_rp.ml | 207 + camlp4/unmaintained/etc/pr_rp_main.ml | 206 + camlp4/unmaintained/etc/q_phony.ml | 38 + camlp4/unmaintained/extfold/README | 15 + camlp4/unmaintained/extfold/pa_extfold.ml | 42 + camlp4/unmaintained/format/.depend | 0 camlp4/unmaintained/format/Makefile | 61 + camlp4/unmaintained/format/README | 15 + camlp4/unmaintained/format/pa_format.ml | 52 + camlp4/unmaintained/lefteval/.depend | 0 camlp4/unmaintained/lefteval/Makefile | 61 + camlp4/unmaintained/lefteval/README | 15 + camlp4/unmaintained/lefteval/pa_lefteval.ml | 241 + camlp4/unmaintained/lib/.cvsignore | 3 + camlp4/unmaintained/lib/.depend | 14 + camlp4/unmaintained/lib/Makefile | 52 + camlp4/unmaintained/lib/extfun.ml | 107 + camlp4/unmaintained/lib/extfun.mli | 35 + camlp4/unmaintained/lib/fstream.ml | 77 + camlp4/unmaintained/lib/fstream.mli | 60 + camlp4/unmaintained/ocamllex/Makefile | 59 + camlp4/unmaintained/ocamllex/README | 15 + camlp4/unmaintained/ocamllex/pa_ocamllex.ml | 356 + camlp4/unmaintained/ocpp/.cvsignore | 3 + camlp4/unmaintained/ocpp/.depend | 0 camlp4/unmaintained/ocpp/Makefile | 24 + camlp4/unmaintained/ocpp/ocpp.ml | 129 + camlp4/unmaintained/odyl/.cvsignore | 4 + camlp4/unmaintained/odyl/.depend | 4 + camlp4/unmaintained/odyl/Makefile | 61 + camlp4/unmaintained/odyl/odyl.ml | 57 + camlp4/unmaintained/odyl/odyl_main.mli | 13 + camlp4/unmaintained/olabl/.depend | 0 camlp4/unmaintained/olabl/Makefile | 61 + camlp4/unmaintained/olabl/README | 15 + camlp4/unmaintained/olabl/pa_olabl.ml | 2022 ++ camlp4/unmaintained/scheme/.depend | 0 camlp4/unmaintained/scheme/Makefile | 85 + camlp4/unmaintained/scheme/README | 15 + camlp4/unmaintained/scheme/pa_scheme.ml | 1093 + camlp4/unmaintained/scheme/pa_scheme.sc | 1029 + camlp4/unmaintained/scheme/pr_scheme.ml | 826 + camlp4/unmaintained/scheme/pr_schp_main.ml | 132 + camlp4/unmaintained/sml/.depend | 0 camlp4/unmaintained/sml/Makefile | 68 + camlp4/unmaintained/sml/README | 15 + camlp4/unmaintained/sml/pa_sml.ml | 952 + camlp4/unmaintained/sml/smllib.sml | 395 + config/.cvsignore | 5 + config/Makefile-templ | 285 + config/Makefile.mingw | 157 + config/Makefile.msvc | 163 + config/Makefile.msvc64 | 158 + config/auto-aux/.cvsignore | 1 + config/auto-aux/align.c | 103 + config/auto-aux/ansi.c | 21 + config/auto-aux/async_io.c | 60 + config/auto-aux/bytecopy.c | 34 + config/auto-aux/dblalign.c | 55 + config/auto-aux/divmod.c | 47 + config/auto-aux/elf.c | 26 + config/auto-aux/endian.c | 41 + config/auto-aux/getgroups.c | 32 + config/auto-aux/gethostbyaddr.c | 51 + config/auto-aux/gethostbyname.c | 41 + config/auto-aux/hasgot | 29 + config/auto-aux/ia32sse2.c | 24 + config/auto-aux/int64align.c | 56 + config/auto-aux/longlong.c | 43 + config/auto-aux/runtest | 8 + config/auto-aux/schar.c | 23 + config/auto-aux/schar2.c | 23 + config/auto-aux/searchpath | 9 + config/auto-aux/sharpbang | 2 + config/auto-aux/sharpbang2 | 2 + config/auto-aux/sighandler.c | 23 + config/auto-aux/signals.c | 68 + config/auto-aux/sizes.c | 23 + config/auto-aux/solaris-ld | 7 + config/auto-aux/stackov.c | 68 + config/auto-aux/tclversion.c | 8 + config/auto-aux/trycompile | 7 + config/gnu/config.guess | 1457 ++ config/gnu/config.sub | 1545 ++ config/m-nt.h | 46 + config/m-templ.h | 83 + config/s-nt.h | 29 + config/s-templ.h | 203 + configure | 1646 ++ debugger/.cvsignore | 4 + debugger/.depend | 220 + debugger/Makefile | 16 + debugger/Makefile.nt | 17 + debugger/Makefile.shared | 116 + debugger/breakpoints.ml | 227 + debugger/breakpoints.mli | 61 + debugger/checkpoints.ml | 85 + debugger/checkpoints.mli | 58 + debugger/command_line.ml | 1099 + debugger/command_line.mli | 22 + debugger/debugcom.ml | 281 + debugger/debugcom.mli | 102 + debugger/debugger_config.ml | 80 + debugger/debugger_config.mli | 35 + debugger/dynlink.ml | 252 + debugger/dynlink.mli | 129 + debugger/envaux.ml | 83 + debugger/envaux.mli | 33 + debugger/eval.ml | 207 + debugger/eval.mli | 40 + debugger/events.ml | 50 + debugger/events.mli | 30 + debugger/exec.ml | 53 + debugger/exec.mli | 19 + debugger/frames.ml | 129 + debugger/frames.mli | 55 + debugger/history.ml | 44 + debugger/history.mli | 20 + debugger/input_handling.ml | 115 + debugger/input_handling.mli | 60 + debugger/int64ops.ml | 26 + debugger/int64ops.mli | 26 + debugger/lexer.mli | 19 + debugger/lexer.mll | 98 + debugger/loadprinter.ml | 172 + debugger/loadprinter.mli | 34 + debugger/main.ml | 189 + debugger/parameters.ml | 35 + debugger/parameters.mli | 26 + debugger/parser.mly | 239 + debugger/parser_aux.mli | 34 + debugger/pattern_matching.ml | 251 + debugger/pattern_matching.mli | 21 + debugger/pos.ml | 42 + debugger/pos.mli | 15 + debugger/primitives.ml | 194 + debugger/primitives.mli | 86 + debugger/printval.ml | 111 + debugger/printval.mli | 33 + debugger/program_loading.ml | 147 + debugger/program_loading.mli | 34 + debugger/program_management.ml | 159 + debugger/program_management.mli | 27 + debugger/question.ml | 36 + debugger/question.mli | 2 + debugger/show_information.ml | 94 + debugger/show_information.mli | 26 + debugger/show_source.ml | 86 + debugger/show_source.mli | 23 + debugger/source.ml | 167 + debugger/source.mli | 58 + debugger/symbols.ml | 194 + debugger/symbols.mli | 46 + debugger/time_travel.ml | 648 + debugger/time_travel.mli | 37 + debugger/trap_barrier.ml | 47 + debugger/trap_barrier.mli | 27 + debugger/unix_tools.ml | 143 + debugger/unix_tools.mli | 34 + driver/compile.ml | 152 + driver/compile.mli | 24 + driver/errors.ml | 81 + driver/errors.mli | 18 + driver/main.ml | 196 + driver/main.mli | 17 + driver/main_args.ml | 166 + driver/main_args.mli | 67 + driver/ocamlcomp.sh.in | 5 + driver/optcompile.ml | 147 + driver/optcompile.mli | 24 + driver/opterrors.ml | 83 + driver/opterrors.mli | 17 + driver/optmain.ml | 260 + driver/optmain.mli | 17 + driver/pparse.ml | 83 + driver/pparse.mli | 22 + emacs/.cvsignore | 2 + emacs/COPYING | 340 + emacs/Makefile | 76 + emacs/README | 206 + emacs/README.itz | 177 + emacs/caml-compat.el | 42 + emacs/caml-emacs.el | 43 + emacs/caml-font-old.el | 141 + emacs/caml-font.el | 114 + emacs/caml-help.el | 829 + emacs/caml-hilit.el | 67 + emacs/caml-types.el | 765 + emacs/caml-xemacs.el | 53 + emacs/caml.el | 1932 ++ emacs/camldebug.el | 784 + emacs/inf-caml.el | 362 + emacs/ocamltags.in | 142 + lex/.cvsignore | 6 + lex/.depend | 34 + lex/Makefile | 71 + lex/Makefile.nt | 73 + lex/common.ml | 163 + lex/common.mli | 27 + lex/compact.ml | 234 + lex/compact.mli | 33 + lex/cset.ml | 99 + lex/cset.mli | 37 + lex/lexer.mli | 22 + lex/lexer.mll | 301 + lex/lexgen.ml | 1193 + lex/lexgen.mli | 61 + lex/main.ml | 119 + lex/output.ml | 140 + lex/output.mli | 25 + lex/outputbis.ml | 193 + lex/outputbis.mli | 21 + lex/parser.mly | 192 + lex/syntax.ml | 44 + lex/syntax.mli | 41 + lex/table.ml | 56 + lex/table.mli | 33 + man/Makefile | 22 + man/ocaml.help | 138 + man/ocaml.m | 172 + man/ocamlc.m | 585 + man/ocamlcp.m | 99 + man/ocamldebug.m | 83 + man/ocamldep.m | 112 + man/ocamldoc.m | 434 + man/ocamllex.m | 84 + man/ocamlmktop.m | 80 + man/ocamlopt.m | 610 + man/ocamlprof.m | 73 + man/ocamlrun.m | 200 + man/ocamlyacc.m | 87 + myocamlbuild.ml | 1148 + myocamlbuild_config.mli | 59 + ocamlbuild/AUTHORS | 2 + ocamlbuild/ChangeLog | 3622 +++ ocamlbuild/FAQ | 35 + ocamlbuild/Makefile | 106 + ocamlbuild/TODO | 39 + ocamlbuild/_tags | 10 + ocamlbuild/bool.ml | 38 + ocamlbuild/bool.mli | 34 + ocamlbuild/command.ml | 391 + ocamlbuild/command.mli | 45 + ocamlbuild/configuration.ml | 69 + ocamlbuild/configuration.mli | 40 + ocamlbuild/digest_cache.ml | 41 + ocamlbuild/digest_cache.mli | 17 + ocamlbuild/discard_printf.ml | 16 + ocamlbuild/discard_printf.mli | 19 + ocamlbuild/display.ml | 387 + ocamlbuild/display.mli | 33 + ocamlbuild/examples/example1/hello.ml | 5 + ocamlbuild/examples/example2/greet.ml | 6 + ocamlbuild/examples/example2/hello.ml | 14 + ocamlbuild/examples/example3/epoch.ml | 6 + ocamlbuild/examples/example3/make.sh | 32 + ocamlbuild/exit_codes.ml | 15 + ocamlbuild/exit_codes.mli | 15 + ocamlbuild/fda.ml | 81 + ocamlbuild/fda.mli | 18 + ocamlbuild/flags.ml | 45 + ocamlbuild/flags.mli | 23 + ocamlbuild/glob.ml | 412 + ocamlbuild/glob.mli | 23 + ocamlbuild/glob_ast.ml | 31 + ocamlbuild/glob_ast.mli | 25 + ocamlbuild/glob_lexer.mli | 27 + ocamlbuild/glob_lexer.mll | 116 + ocamlbuild/hooks.ml | 26 + ocamlbuild/hooks.mli | 23 + ocamlbuild/hygiene.ml | 172 + ocamlbuild/hygiene.mli | 46 + ocamlbuild/lexers.mli | 39 + ocamlbuild/lexers.mll | 145 + ocamlbuild/log.ml | 55 + ocamlbuild/log.mli | 33 + ocamlbuild/main.ml | 289 + ocamlbuild/main.mli | 14 + ocamlbuild/man/ocamlbuild.1 | 253 + ocamlbuild/manual/.cvsignore | 6 + ocamlbuild/manual/Makefile | 15 + ocamlbuild/manual/manual.hva | 1 + ocamlbuild/manual/manual.tex | 1054 + ocamlbuild/manual/myocamlbuild.ml | 119 + ocamlbuild/manual/trace.out | 83 + ocamlbuild/misc/opentracer.ml | 101 + ocamlbuild/my_std.ml | 390 + ocamlbuild/my_std.mli | 65 + ocamlbuild/my_unix.ml | 141 + ocamlbuild/my_unix.mli | 73 + ocamlbuild/ocaml_arch.ml | 135 + ocamlbuild/ocaml_arch.mli | 16 + ocamlbuild/ocaml_compiler.ml | 347 + ocamlbuild/ocaml_compiler.mli | 84 + ocamlbuild/ocaml_dependencies.ml | 219 + ocamlbuild/ocaml_dependencies.mli | 43 + ocamlbuild/ocaml_specific.ml | 460 + ocamlbuild/ocaml_specific.mli | 16 + ocamlbuild/ocaml_tools.ml | 166 + ocamlbuild/ocaml_tools.mli | 33 + ocamlbuild/ocaml_utils.ml | 163 + ocamlbuild/ocaml_utils.mli | 44 + ocamlbuild/ocamlbuild-presentation.rslide | 350 + ocamlbuild/ocamlbuild.ml | 15 + ocamlbuild/ocamlbuild.mli | 15 + ocamlbuild/ocamlbuild.mltop | 3 + ocamlbuild/ocamlbuild.odocl | 40 + ocamlbuild/ocamlbuild_executor.ml | 343 + ocamlbuild/ocamlbuild_executor.mli | 54 + ocamlbuild/ocamlbuild_pack.mlpack | 39 + ocamlbuild/ocamlbuild_plugin.ml | 56 + ocamlbuild/ocamlbuild_plugin.mli | 5 + ocamlbuild/ocamlbuild_unix_plugin.ml | 83 + ocamlbuild/ocamlbuild_unix_plugin.mli | 14 + ocamlbuild/ocamlbuild_where.mli | 17 + ocamlbuild/ocamlbuildlib.mllib | 4 + ocamlbuild/ocamlbuildlight.ml | 14 + ocamlbuild/ocamlbuildlight.mli | 14 + ocamlbuild/ocamlbuildlightlib.mllib | 2 + ocamlbuild/options.ml | 261 + ocamlbuild/options.mli | 18 + ocamlbuild/pathname.ml | 159 + ocamlbuild/pathname.mli | 16 + ocamlbuild/plugin.ml | 113 + ocamlbuild/plugin.mli | 16 + ocamlbuild/ppcache.ml | 90 + ocamlbuild/ppcache.mli | 14 + ocamlbuild/report.ml | 61 + ocamlbuild/report.mli | 18 + ocamlbuild/resource.ml | 396 + ocamlbuild/resource.mli | 75 + ocamlbuild/rule.ml | 308 + ocamlbuild/rule.mli | 79 + ocamlbuild/shell.ml | 81 + ocamlbuild/shell.mli | 26 + ocamlbuild/signatures.mli | 638 + ocamlbuild/slurp.ml | 186 + ocamlbuild/slurp.mli | 48 + ocamlbuild/solver.ml | 123 + ocamlbuild/solver.mli | 23 + ocamlbuild/start.sh | 108 + ocamlbuild/std_signatures.mli | 94 + ocamlbuild/tags.ml | 43 + ocamlbuild/tags.mli | 15 + ocamlbuild/test/good-output | 1090 + ocamlbuild/test/runtest.sh | 36 + ocamlbuild/test/test1/foo.ml | 1 + ocamlbuild/test/test10/dbdi | 12 + ocamlbuild/test/test10/test.sh | 6 + ocamlbuild/test/test11/_tags | 2 + ocamlbuild/test/test11/a/aa.ml | 1 + ocamlbuild/test/test11/a/aa.mli | 1 + ocamlbuild/test/test11/b/bb.ml | 1 + ocamlbuild/test/test11/b/libb.mllib | 1 + ocamlbuild/test/test11/myocamlbuild.ml | 5 + ocamlbuild/test/test11/test.sh | 13 + ocamlbuild/test/test2/_tags | 3 + ocamlbuild/test/test2/tata.ml | 1 + ocamlbuild/test/test2/tata.mli | 2 + ocamlbuild/test/test2/test.sh | 18 + ocamlbuild/test/test2/titi.ml | 1 + ocamlbuild/test/test2/toto.ml | 5 + ocamlbuild/test/test2/tutu.ml | 2 + ocamlbuild/test/test2/tutu.mli | 3 + ocamlbuild/test/test2/tyty.mli | 1 + ocamlbuild/test/test2/vivi1.ml | 2 + ocamlbuild/test/test2/vivi2.ml | 2 + ocamlbuild/test/test2/vivi3.ml | 2 + ocamlbuild/test/test3/_tags | 1 + ocamlbuild/test/test3/a.ml | 1 + ocamlbuild/test/test3/a.mli | 1 + ocamlbuild/test/test3/b.ml | 1 + ocamlbuild/test/test3/b.mli | 1 + ocamlbuild/test/test3/c.ml | 1 + ocamlbuild/test/test3/c.mli | 1 + ocamlbuild/test/test3/d.ml | 1 + ocamlbuild/test/test3/d.mli | 1 + ocamlbuild/test/test3/e.ml | 1 + ocamlbuild/test/test3/e.mli | 1 + ocamlbuild/test/test3/f.ml | 2 + ocamlbuild/test/test3/f.mli | 1 + ocamlbuild/test/test3/proj.odocl | 1 + ocamlbuild/test/test3/test.sh | 11 + ocamlbuild/test/test4/_tags | 2 + ocamlbuild/test/test4/a/aa.ml | 1 + ocamlbuild/test/test4/a/aa.mli | 1 + ocamlbuild/test/test4/b/bb.ml | 2 + ocamlbuild/test/test4/test.sh | 11 + ocamlbuild/test/test5/_tags | 1 + ocamlbuild/test/test5/a.ml | 1 + ocamlbuild/test/test5/a.mli | 1 + ocamlbuild/test/test5/b.ml | 1 + ocamlbuild/test/test5/c.mlpack | 1 + ocamlbuild/test/test5/d.ml | 1 + ocamlbuild/test/test5/stack.ml | 1 + ocamlbuild/test/test5/test.sh | 11 + ocamlbuild/test/test6/a.ml | 1 + ocamlbuild/test/test6/a.mli | 1 + ocamlbuild/test/test6/b.ml | 1 + ocamlbuild/test/test6/b.mli | 1 + ocamlbuild/test/test6/b.mli.v1 | 1 + ocamlbuild/test/test6/b.mli.v2 | 2 + ocamlbuild/test/test6/d.ml | 2 + ocamlbuild/test/test6/d.mli | 1 + ocamlbuild/test/test6/d.mli.v1 | 2 + ocamlbuild/test/test6/d.mli.v2 | 1 + ocamlbuild/test/test6/main.ml | 1 + ocamlbuild/test/test6/main.mli | 1 + ocamlbuild/test/test6/test.sh | 26 + ocamlbuild/test/test7/_tags | 1 + ocamlbuild/test/test7/aa.ml | 1 + ocamlbuild/test/test7/bb.mli | 1 + ocamlbuild/test/test7/bb1.ml | 1 + ocamlbuild/test/test7/bb2.ml | 3 + ocamlbuild/test/test7/bb3.ml | 3 + ocamlbuild/test/test7/bbcc.mllib | 1 + ocamlbuild/test/test7/c2.ml | 1 + ocamlbuild/test/test7/c2.mli | 1 + ocamlbuild/test/test7/c3.ml | 1 + ocamlbuild/test/test7/cc.ml | 1 + ocamlbuild/test/test7/cool_plugin.ml | 1 + ocamlbuild/test/test7/main.ml | 1 + ocamlbuild/test/test7/myocamlbuild.ml | 7 + ocamlbuild/test/test7/test.sh | 18 + ocamlbuild/test/test8/a.ml | 1 + ocamlbuild/test/test8/myocamlbuild.ml | 16 + ocamlbuild/test/test8/test.sh | 11 + ocamlbuild/test/test9/dbgl | 10 + ocamlbuild/test/test9/test.sh | 6 + ocamlbuild/test/test9/testglob.ml | 134 + ocamlbuild/test/test_virtual/foo.itarget | 1 + ocamlbuild/test/test_virtual/foo1 | 1 + ocamlbuild/test/test_virtual/foo2 | 1 + ocamlbuild/test/test_virtual/myocamlbuild.ml | 11 + ocamlbuild/test/test_virtual/test.sh | 16 + ocamlbuild/tools.ml | 47 + ocamlbuild/tools.mli | 19 + ocamldoc/.cvsignore | 16 + ocamldoc/.depend | 251 + ocamldoc/Changes.txt | 205 + ocamldoc/Makefile | 354 + ocamldoc/Makefile.nt | 271 + ocamldoc/ocamldoc.hva | 19 + ocamldoc/ocamldoc.sty | 60 + ocamldoc/odoc.ml | 150 + ocamldoc/odoc_analyse.ml | 535 + ocamldoc/odoc_analyse.mli | 32 + ocamldoc/odoc_args.ml | 351 + ocamldoc/odoc_args.mli | 196 + ocamldoc/odoc_ast.ml | 1707 ++ ocamldoc/odoc_ast.mli | 104 + ocamldoc/odoc_class.ml | 253 + ocamldoc/odoc_comments.ml | 343 + ocamldoc/odoc_comments.mli | 74 + ocamldoc/odoc_comments_global.ml | 48 + ocamldoc/odoc_comments_global.mli | 47 + ocamldoc/odoc_config.ml | 18 + ocamldoc/odoc_config.mli | 20 + ocamldoc/odoc_control.ml | 13 + ocamldoc/odoc_cross.ml | 969 + ocamldoc/odoc_cross.mli | 20 + ocamldoc/odoc_dag2html.ml | 1750 ++ ocamldoc/odoc_dag2html.mli | 31 + ocamldoc/odoc_dep.ml | 219 + ocamldoc/odoc_dot.ml | 131 + ocamldoc/odoc_env.ml | 245 + ocamldoc/odoc_env.mli | 76 + ocamldoc/odoc_exception.ml | 32 + ocamldoc/odoc_global.ml | 22 + ocamldoc/odoc_global.mli | 20 + ocamldoc/odoc_html.ml | 2510 ++ ocamldoc/odoc_info.ml | 321 + ocamldoc/odoc_info.mli | 1087 + ocamldoc/odoc_inherit.ml | 13 + ocamldoc/odoc_latex.ml | 1145 + ocamldoc/odoc_latex_style.ml | 92 + ocamldoc/odoc_lexer.mll | 412 + ocamldoc/odoc_man.ml | 1057 + ocamldoc/odoc_merge.ml | 966 + ocamldoc/odoc_merge.mli | 32 + ocamldoc/odoc_messages.ml | 360 + ocamldoc/odoc_misc.ml | 486 + ocamldoc/odoc_misc.mli | 115 + ocamldoc/odoc_module.ml | 526 + ocamldoc/odoc_name.ml | 176 + ocamldoc/odoc_name.mli | 66 + ocamldoc/odoc_ocamlhtml.mll | 545 + ocamldoc/odoc_opt.ml | 81 + ocamldoc/odoc_parameter.ml | 123 + ocamldoc/odoc_parser.mly | 158 + ocamldoc/odoc_print.ml | 104 + ocamldoc/odoc_print.mli | 33 + ocamldoc/odoc_scan.ml | 156 + ocamldoc/odoc_search.ml | 635 + ocamldoc/odoc_search.mli | 199 + ocamldoc/odoc_see_lexer.mll | 102 + ocamldoc/odoc_sig.ml | 1313 + ocamldoc/odoc_sig.mli | 177 + ocamldoc/odoc_str.ml | 277 + ocamldoc/odoc_str.mli | 51 + ocamldoc/odoc_test.ml | 112 + ocamldoc/odoc_texi.ml | 1222 + ocamldoc/odoc_text.ml | 153 + ocamldoc/odoc_text.mli | 24 + ocamldoc/odoc_text_lexer.mll | 777 + ocamldoc/odoc_text_parser.mly | 225 + ocamldoc/odoc_to_text.ml | 574 + ocamldoc/odoc_type.ml | 56 + ocamldoc/odoc_types.ml | 133 + ocamldoc/odoc_types.mli | 133 + ocamldoc/odoc_value.ml | 145 + ocamldoc/remove_DEBUG | 21 + ocamldoc/runocamldoc | 12 + otherlibs/Makefile | 24 + otherlibs/Makefile.nt | 25 + otherlibs/Makefile.shared | 90 + otherlibs/bigarray/.cvsignore | 3 + otherlibs/bigarray/.depend | 32 + otherlibs/bigarray/Makefile | 29 + otherlibs/bigarray/Makefile.nt | 29 + otherlibs/bigarray/bigarray.h | 95 + otherlibs/bigarray/bigarray.ml | 253 + otherlibs/bigarray/bigarray.mli | 800 + otherlibs/bigarray/bigarray_stubs.c | 1083 + otherlibs/bigarray/dllbigarray.dlib | 1 + otherlibs/bigarray/libbigarray.clib | 1 + otherlibs/bigarray/libbigarraywin32.clib | 1 + otherlibs/bigarray/mmap_unix.c | 135 + otherlibs/bigarray/mmap_win32.c | 155 + otherlibs/db/.depend | 2 + otherlibs/dbm/.cvsignore | 1 + otherlibs/dbm/.depend | 3 + otherlibs/dbm/Makefile | 31 + otherlibs/dbm/cldbm.c | 166 + otherlibs/dbm/dbm.ml | 58 + otherlibs/dbm/dbm.mli | 80 + otherlibs/dbm/libmldbm.clib | 1 + otherlibs/dynlink/.cvsignore | 1 + otherlibs/dynlink/Makefile | 96 + otherlibs/dynlink/Makefile.nt | 18 + otherlibs/dynlink/dynlink.ml | 269 + otherlibs/dynlink/dynlink.mli | 143 + otherlibs/dynlink/dynlinkaux.mlpack | 5 + otherlibs/dynlink/extract_crc.ml | 55 + otherlibs/dynlink/natdynlink.ml | 259 + otherlibs/graph/.cvsignore | 1 + otherlibs/graph/.depend | 152 + otherlibs/graph/Makefile | 34 + otherlibs/graph/color.c | 228 + otherlibs/graph/draw.c | 123 + otherlibs/graph/dump_img.c | 55 + otherlibs/graph/events.c | 269 + otherlibs/graph/fill.c | 88 + otherlibs/graph/graphics.ml | 256 + otherlibs/graph/graphics.mli | 379 + otherlibs/graph/graphics.mllib | 1 + otherlibs/graph/graphicsX11.ml | 42 + otherlibs/graph/graphicsX11.mli | 31 + otherlibs/graph/image.c | 107 + otherlibs/graph/image.h | 29 + otherlibs/graph/libgraph.h | 85 + otherlibs/graph/libgraphics.clib | 3 + otherlibs/graph/make_img.c | 95 + otherlibs/graph/open.c | 395 + otherlibs/graph/point_col.c | 32 + otherlibs/graph/sound.c | 34 + otherlibs/graph/subwindow.c | 45 + otherlibs/graph/text.c | 84 + otherlibs/labltk/.cvsignore | 4 + otherlibs/labltk/Changes | 17 + otherlibs/labltk/Makefile | 83 + otherlibs/labltk/Makefile.nt | 64 + otherlibs/labltk/README | 152 + otherlibs/labltk/Widgets.src | 2288 ++ otherlibs/labltk/browser/.cvsignore | 2 + otherlibs/labltk/browser/.depend | 66 + otherlibs/labltk/browser/Makefile | 6 + otherlibs/labltk/browser/Makefile.nt | 21 + otherlibs/labltk/browser/Makefile.shared | 63 + otherlibs/labltk/browser/README | 170 + otherlibs/labltk/browser/dummyUnix.mli | 27 + otherlibs/labltk/browser/dummyWin.mli | 15 + otherlibs/labltk/browser/editor.ml | 667 + otherlibs/labltk/browser/editor.mli | 20 + otherlibs/labltk/browser/fileselect.ml | 290 + otherlibs/labltk/browser/fileselect.mli | 39 + otherlibs/labltk/browser/help.ml | 168 + otherlibs/labltk/browser/help.txt | 166 + otherlibs/labltk/browser/jg_bind.ml | 28 + otherlibs/labltk/browser/jg_bind.mli | 21 + otherlibs/labltk/browser/jg_box.ml | 82 + otherlibs/labltk/browser/jg_button.ml | 25 + otherlibs/labltk/browser/jg_completion.ml | 53 + otherlibs/labltk/browser/jg_completion.mli | 25 + otherlibs/labltk/browser/jg_config.ml | 40 + otherlibs/labltk/browser/jg_config.mli | 17 + otherlibs/labltk/browser/jg_entry.ml | 27 + otherlibs/labltk/browser/jg_memo.ml | 35 + otherlibs/labltk/browser/jg_memo.mli | 19 + otherlibs/labltk/browser/jg_menu.ml | 44 + otherlibs/labltk/browser/jg_message.ml | 111 + otherlibs/labltk/browser/jg_message.mli | 33 + otherlibs/labltk/browser/jg_multibox.ml | 185 + otherlibs/labltk/browser/jg_multibox.mli | 35 + otherlibs/labltk/browser/jg_text.ml | 104 + otherlibs/labltk/browser/jg_text.mli | 28 + otherlibs/labltk/browser/jg_tk.ml | 24 + otherlibs/labltk/browser/jg_toplevel.ml | 25 + otherlibs/labltk/browser/jglib.mllib | 13 + otherlibs/labltk/browser/lexical.ml | 143 + otherlibs/labltk/browser/lexical.mli | 20 + otherlibs/labltk/browser/list2.ml | 23 + otherlibs/labltk/browser/main.ml | 140 + otherlibs/labltk/browser/mytypes.mli | 29 + otherlibs/labltk/browser/searchid.ml | 533 + otherlibs/labltk/browser/searchid.mli | 45 + otherlibs/labltk/browser/searchpos.ml | 882 + otherlibs/labltk/browser/searchpos.mli | 78 + otherlibs/labltk/browser/setpath.ml | 162 + otherlibs/labltk/browser/setpath.mli | 25 + otherlibs/labltk/browser/shell.ml | 365 + otherlibs/labltk/browser/shell.mli | 46 + otherlibs/labltk/browser/typecheck.ml | 181 + otherlibs/labltk/browser/typecheck.mli | 23 + otherlibs/labltk/browser/useunix.ml | 69 + otherlibs/labltk/browser/useunix.mli | 23 + otherlibs/labltk/browser/viewer.ml | 631 + otherlibs/labltk/browser/viewer.mli | 31 + otherlibs/labltk/browser/winmain.c | 26 + otherlibs/labltk/builtin/LICENSE | 19 + .../labltk/builtin/builtin_FilePattern.ml | 20 + otherlibs/labltk/builtin/builtin_GetBitmap.ml | 22 + otherlibs/labltk/builtin/builtin_GetCursor.ml | 61 + otherlibs/labltk/builtin/builtin_GetPixel.ml | 28 + .../labltk/builtin/builtin_ScrollValue.ml | 22 + otherlibs/labltk/builtin/builtin_bind.ml | 469 + otherlibs/labltk/builtin/builtin_bindtags.ml | 21 + otherlibs/labltk/builtin/builtin_font.ml | 4 + otherlibs/labltk/builtin/builtin_grab.ml | 3 + otherlibs/labltk/builtin/builtin_index.ml | 92 + otherlibs/labltk/builtin/builtin_palette.ml | 20 + otherlibs/labltk/builtin/builtin_text.ml | 50 + otherlibs/labltk/builtin/builtina_empty.ml | 0 otherlibs/labltk/builtin/builtinf_GetPixel.ml | 23 + otherlibs/labltk/builtin/builtinf_bind.ml | 133 + .../labltk/builtin/builtini_GetBitmap.ml | 28 + .../labltk/builtin/builtini_GetCursor.ml | 55 + otherlibs/labltk/builtin/builtini_GetPixel.ml | 43 + .../labltk/builtin/builtini_ScrollValue.ml | 45 + otherlibs/labltk/builtin/builtini_bind.ml | 136 + otherlibs/labltk/builtin/builtini_bindtags.ml | 29 + otherlibs/labltk/builtin/builtini_font.ml | 3 + otherlibs/labltk/builtin/builtini_grab.ml | 2 + otherlibs/labltk/builtin/builtini_index.ml | 140 + otherlibs/labltk/builtin/builtini_palette.ml | 19 + otherlibs/labltk/builtin/builtini_text.ml | 64 + otherlibs/labltk/builtin/canvas_bind.ml | 52 + otherlibs/labltk/builtin/canvas_bind.mli | 16 + otherlibs/labltk/builtin/dialog.ml | 45 + otherlibs/labltk/builtin/dialog.mli | 24 + otherlibs/labltk/builtin/image.ml | 33 + otherlibs/labltk/builtin/image.mli | 9 + otherlibs/labltk/builtin/optionmenu.ml | 54 + otherlibs/labltk/builtin/optionmenu.mli | 21 + otherlibs/labltk/builtin/rawimg.ml | 142 + otherlibs/labltk/builtin/rawimg.mli | 44 + otherlibs/labltk/builtin/report.ml | 17 + .../labltk/builtin/selection_handle_set.ml | 41 + .../labltk/builtin/selection_handle_set.mli | 13 + otherlibs/labltk/builtin/selection_own_set.ml | 29 + .../labltk/builtin/selection_own_set.mli | 12 + otherlibs/labltk/builtin/text_tag_bind.ml | 55 + otherlibs/labltk/builtin/text_tag_bind.mli | 13 + otherlibs/labltk/builtin/winfo_contained.ml | 13 + otherlibs/labltk/builtin/winfo_contained.mli | 11 + otherlibs/labltk/camltk/.cvsignore | 3 + otherlibs/labltk/camltk/Makefile | 43 + otherlibs/labltk/camltk/Makefile.gen | 52 + otherlibs/labltk/camltk/Makefile.gen.nt | 1 + otherlibs/labltk/camltk/Makefile.nt | 1 + otherlibs/labltk/camltk/byte.itarget | 9 + otherlibs/labltk/camltk/modules | 80 + otherlibs/labltk/camltk/native.itarget | 7 + otherlibs/labltk/compiler/.cvsignore | 11 + otherlibs/labltk/compiler/.depend | 28 + otherlibs/labltk/compiler/Makefile | 63 + otherlibs/labltk/compiler/Makefile.nt | 1 + otherlibs/labltk/compiler/code.mli | 22 + otherlibs/labltk/compiler/compile.ml | 1074 + otherlibs/labltk/compiler/copyright | 15 + otherlibs/labltk/compiler/flags.ml | 17 + otherlibs/labltk/compiler/intf.ml | 191 + otherlibs/labltk/compiler/lexer.mll | 170 + otherlibs/labltk/compiler/maincompile.ml | 418 + otherlibs/labltk/compiler/parser.mly | 330 + otherlibs/labltk/compiler/pp.ml | 23 + otherlibs/labltk/compiler/ppexec.ml | 60 + otherlibs/labltk/compiler/pplex.mli | 18 + otherlibs/labltk/compiler/pplex.mll | 56 + otherlibs/labltk/compiler/ppparse.ml | 36 + otherlibs/labltk/compiler/ppyac.mly | 52 + otherlibs/labltk/compiler/printer.ml | 173 + otherlibs/labltk/compiler/tables.ml | 427 + otherlibs/labltk/compiler/tsort.ml | 89 + otherlibs/labltk/examples_camltk/.cvsignore | 8 + otherlibs/labltk/examples_camltk/Makefile | 52 + otherlibs/labltk/examples_camltk/Makefile.nt | 38 + otherlibs/labltk/examples_camltk/addition.ml | 53 + otherlibs/labltk/examples_camltk/eyes.ml | 67 + otherlibs/labltk/examples_camltk/fileinput.ml | 35 + otherlibs/labltk/examples_camltk/fileopen.ml | 56 + .../labltk/examples_camltk/helloworld.ml | 37 + .../examples_camltk/images/CamlBook.gif | Bin 0 -> 15168 bytes .../examples_camltk/images/Lambda2.back.gif | Bin 0 -> 53442 bytes .../examples_camltk/images/dojoji.back.gif | Bin 0 -> 49935 bytes otherlibs/labltk/examples_camltk/jptest.ml | 23 + otherlibs/labltk/examples_camltk/mytext.ml | 63 + .../labltk/examples_camltk/socketinput.ml | 43 + otherlibs/labltk/examples_camltk/taddition.ml | 53 + otherlibs/labltk/examples_camltk/tetris.ml | 685 + otherlibs/labltk/examples_camltk/text.ml | 55 + otherlibs/labltk/examples_camltk/winskel.ml | 63 + otherlibs/labltk/examples_labltk/.cvsignore | 8 + .../labltk/examples_labltk/Lambda2.back.gif | Bin 0 -> 53442 bytes otherlibs/labltk/examples_labltk/Makefile | 53 + otherlibs/labltk/examples_labltk/Makefile.nt | 50 + otherlibs/labltk/examples_labltk/README | 20 + otherlibs/labltk/examples_labltk/calc.ml | 129 + otherlibs/labltk/examples_labltk/clock.ml | 133 + otherlibs/labltk/examples_labltk/demo.ml | 167 + otherlibs/labltk/examples_labltk/eyes.ml | 65 + otherlibs/labltk/examples_labltk/hello.ml | 38 + otherlibs/labltk/examples_labltk/hello.tcl | 5 + otherlibs/labltk/examples_labltk/lang.ml | 75 + otherlibs/labltk/examples_labltk/taquin.ml | 143 + otherlibs/labltk/examples_labltk/tetris.ml | 710 + otherlibs/labltk/frx/.depend | 38 + otherlibs/labltk/frx/Makefile | 51 + otherlibs/labltk/frx/Makefile.nt | 1 + otherlibs/labltk/frx/README | 2 + otherlibs/labltk/frx/frx_after.ml | 24 + otherlibs/labltk/frx/frx_after.mli | 17 + otherlibs/labltk/frx/frx_color.ml | 35 + otherlibs/labltk/frx/frx_color.mli | 16 + otherlibs/labltk/frx/frx_ctext.ml | 66 + otherlibs/labltk/frx/frx_ctext.mli | 25 + otherlibs/labltk/frx/frx_dialog.ml | 115 + otherlibs/labltk/frx/frx_dialog.mli | 22 + otherlibs/labltk/frx/frx_entry.ml | 42 + otherlibs/labltk/frx/frx_entry.mli | 31 + otherlibs/labltk/frx/frx_fileinput.ml | 40 + otherlibs/labltk/frx/frx_fillbox.ml | 65 + otherlibs/labltk/frx/frx_fillbox.mli | 31 + otherlibs/labltk/frx/frx_fit.ml | 83 + otherlibs/labltk/frx/frx_fit.mli | 29 + otherlibs/labltk/frx/frx_focus.ml | 26 + otherlibs/labltk/frx/frx_focus.mli | 18 + otherlibs/labltk/frx/frx_font.ml | 51 + otherlibs/labltk/frx/frx_font.mli | 20 + otherlibs/labltk/frx/frx_group.ml | 22 + otherlibs/labltk/frx/frx_lbutton.ml | 50 + otherlibs/labltk/frx/frx_lbutton.mli | 24 + otherlibs/labltk/frx/frx_listbox.ml | 92 + otherlibs/labltk/frx/frx_listbox.mli | 32 + otherlibs/labltk/frx/frx_mem.ml | 89 + otherlibs/labltk/frx/frx_mem.mli | 22 + otherlibs/labltk/frx/frx_misc.ml | 69 + otherlibs/labltk/frx/frx_misc.mli | 21 + otherlibs/labltk/frx/frx_req.ml | 198 + otherlibs/labltk/frx/frx_req.mli | 43 + otherlibs/labltk/frx/frx_rpc.ml | 55 + otherlibs/labltk/frx/frx_rpc.mli | 25 + otherlibs/labltk/frx/frx_selection.ml | 45 + otherlibs/labltk/frx/frx_selection.mli | 17 + otherlibs/labltk/frx/frx_synth.ml | 88 + otherlibs/labltk/frx/frx_synth.mli | 31 + otherlibs/labltk/frx/frx_text.ml | 229 + otherlibs/labltk/frx/frx_text.mli | 46 + otherlibs/labltk/frx/frx_toplevel.mli | 17 + otherlibs/labltk/frx/frx_widget.ml | 24 + otherlibs/labltk/frx/frx_widget.mli | 18 + otherlibs/labltk/frx/frxlib.mllib | 4 + otherlibs/labltk/jpf/Makefile | 77 + otherlibs/labltk/jpf/Makefile.nt | 1 + otherlibs/labltk/jpf/README | 2 + otherlibs/labltk/jpf/balloon.ml | 102 + otherlibs/labltk/jpf/balloon.mli | 24 + otherlibs/labltk/jpf/balloontest.ml | 32 + otherlibs/labltk/jpf/fileselect.ml | 367 + otherlibs/labltk/jpf/fileselect.mli | 37 + otherlibs/labltk/jpf/jpf_font.ml | 218 + otherlibs/labltk/jpf/jpf_font.mli | 54 + otherlibs/labltk/jpf/jpflib.mllib | 1 + otherlibs/labltk/jpf/shell.ml | 36 + otherlibs/labltk/jpf/shell.mli | 17 + otherlibs/labltk/labl.gif | Bin 0 -> 1533 bytes otherlibs/labltk/labltk/.cvsignore | 3 + otherlibs/labltk/labltk/Makefile | 43 + otherlibs/labltk/labltk/Makefile.gen | 52 + otherlibs/labltk/labltk/Makefile.gen.nt | 1 + otherlibs/labltk/labltk/Makefile.nt | 1 + otherlibs/labltk/labltk/byte.itarget | 8 + otherlibs/labltk/labltk/modules | 77 + otherlibs/labltk/labltk/native.itarget | 6 + otherlibs/labltk/lib/.cvsignore | 8 + otherlibs/labltk/lib/Makefile | 74 + otherlibs/labltk/lib/Makefile.nt | 1 + otherlibs/labltk/support/.depend | 27 + otherlibs/labltk/support/Makefile | 75 + otherlibs/labltk/support/Makefile.common | 27 + otherlibs/labltk/support/Makefile.nt | 1 + otherlibs/labltk/support/byte.itarget | 3 + otherlibs/labltk/support/camltk.h | 61 + otherlibs/labltk/support/camltkwrap.ml | 77 + otherlibs/labltk/support/camltkwrap.mli | 251 + otherlibs/labltk/support/cltkCaml.c | 85 + otherlibs/labltk/support/cltkDMain.c | 247 + otherlibs/labltk/support/cltkEval.c | 243 + otherlibs/labltk/support/cltkEvent.c | 55 + otherlibs/labltk/support/cltkFile.c | 158 + otherlibs/labltk/support/cltkImg.c | 118 + otherlibs/labltk/support/cltkMain.c | 181 + otherlibs/labltk/support/cltkMisc.c | 64 + otherlibs/labltk/support/cltkTimer.c | 45 + otherlibs/labltk/support/cltkUtf.c | 89 + otherlibs/labltk/support/cltkVar.c | 128 + otherlibs/labltk/support/cltkWait.c | 102 + otherlibs/labltk/support/fileevent.ml | 81 + otherlibs/labltk/support/fileevent.mli | 25 + otherlibs/labltk/support/liblabltk.clib | 2 + otherlibs/labltk/support/native.itarget | 3 + otherlibs/labltk/support/protocol.ml | 276 + otherlibs/labltk/support/protocol.mli | 124 + otherlibs/labltk/support/rawwidget.ml | 176 + otherlibs/labltk/support/rawwidget.mli | 109 + otherlibs/labltk/support/slave.ml | 51 + otherlibs/labltk/support/support.ml | 48 + otherlibs/labltk/support/support.mli | 21 + otherlibs/labltk/support/textvariable.ml | 152 + otherlibs/labltk/support/textvariable.mli | 45 + otherlibs/labltk/support/timer.ml | 58 + otherlibs/labltk/support/timer.mli | 23 + otherlibs/labltk/support/tkthread.ml | 67 + otherlibs/labltk/support/tkthread.mli | 46 + otherlibs/labltk/support/tkwait.ml | 22 + otherlibs/labltk/support/widget.ml | 23 + otherlibs/labltk/support/widget.mli | 109 + otherlibs/labltk/tkanim/.cvsignore | 2 + otherlibs/labltk/tkanim/.depend | 2 + otherlibs/labltk/tkanim/Makefile | 71 + otherlibs/labltk/tkanim/Makefile.nt | 1 + otherlibs/labltk/tkanim/README | 5 + otherlibs/labltk/tkanim/cltkaniminit.c | 28 + otherlibs/labltk/tkanim/gifanimtest.ml | 71 + otherlibs/labltk/tkanim/libtkanim.clib | 1 + otherlibs/labltk/tkanim/mmm.anim.gif | Bin 0 -> 18501 bytes otherlibs/labltk/tkanim/tkAnimGIF.c | 914 + otherlibs/labltk/tkanim/tkAppInit.c | 141 + otherlibs/labltk/tkanim/tkanim.ml | 230 + otherlibs/labltk/tkanim/tkanim.mli | 95 + otherlibs/num/.cvsignore | 3 + otherlibs/num/.depend | 50 + otherlibs/num/.depend.nt | 66 + otherlibs/num/Makefile | 38 + otherlibs/num/Makefile.nt | 36 + otherlibs/num/README | 55 + otherlibs/num/arith_flags.ml | 25 + otherlibs/num/arith_flags.mli | 20 + otherlibs/num/arith_status.ml | 100 + otherlibs/num/arith_status.mli | 60 + otherlibs/num/big_int.ml | 658 + otherlibs/num/big_int.mli | 163 + otherlibs/num/bignum/.cvsignore | 1 + otherlibs/num/bng.c | 435 + otherlibs/num/bng.h | 157 + otherlibs/num/bng_alpha.c | 23 + otherlibs/num/bng_amd64.c | 196 + otherlibs/num/bng_digit.c | 171 + otherlibs/num/bng_ia32.c | 412 + otherlibs/num/bng_mips.c | 24 + otherlibs/num/bng_ppc.c | 94 + otherlibs/num/bng_sparc.c | 77 + otherlibs/num/dllnums.dlib | 1 + otherlibs/num/int_misc.ml | 36 + otherlibs/num/int_misc.mli | 25 + otherlibs/num/libnums.clib | 1 + otherlibs/num/nat.h | 19 + otherlibs/num/nat.ml | 572 + otherlibs/num/nat.mli | 73 + otherlibs/num/nat_stubs.c | 381 + otherlibs/num/num.ml | 445 + otherlibs/num/num.mli | 171 + otherlibs/num/nums.mllib | 1 + otherlibs/num/ratio.ml | 575 + otherlibs/num/ratio.mli | 88 + otherlibs/num/test/.depend | 10 + otherlibs/num/test/Makefile | 76 + otherlibs/num/test/Makefile.nt | 61 + otherlibs/num/test/end_test.ml | 1 + otherlibs/num/test/pi_big_int.ml | 78 + otherlibs/num/test/pi_num.ml | 73 + otherlibs/num/test/test.ml | 82 + otherlibs/num/test/test_big_ints.ml | 772 + otherlibs/num/test/test_bng.c | 408 + otherlibs/num/test/test_io.ml | 64 + otherlibs/num/test/test_nats.ml | 146 + otherlibs/num/test/test_nums.ml | 220 + otherlibs/num/test/test_ratios.ml | 1177 + otherlibs/str/.cvsignore | 3 + otherlibs/str/.depend | 17 + otherlibs/str/Makefile | 34 + otherlibs/str/Makefile.nt | 27 + otherlibs/str/dllstr.dlib | 1 + otherlibs/str/libstr.clib | 1 + otherlibs/str/str.ml | 737 + otherlibs/str/str.mli | 249 + otherlibs/str/strstubs.c | 524 + otherlibs/systhreads/.cvsignore | 3 + otherlibs/systhreads/.depend | 43 + otherlibs/systhreads/Makefile | 108 + otherlibs/systhreads/Makefile.nt | 102 + otherlibs/systhreads/Tests/Makefile | 44 + otherlibs/systhreads/Tests/Makefile.nt | 43 + otherlibs/systhreads/condition.ml | 20 + otherlibs/systhreads/condition.mli | 53 + otherlibs/systhreads/dllthreads.dlib | 1 + otherlibs/systhreads/event.ml | 274 + otherlibs/systhreads/event.mli | 82 + otherlibs/systhreads/libthreads.clib | 1 + otherlibs/systhreads/libthreadswin32.clib | 1 + otherlibs/systhreads/mutex.ml | 20 + otherlibs/systhreads/mutex.mli | 50 + otherlibs/systhreads/posix.c | 926 + otherlibs/systhreads/thread.mli | 134 + otherlibs/systhreads/threadUnix.ml | 59 + otherlibs/systhreads/threadUnix.mli | 85 + otherlibs/systhreads/thread_posix.ml | 74 + otherlibs/systhreads/thread_win32.ml | 77 + otherlibs/systhreads/threads.mllib | 1 + otherlibs/systhreads/win32.c | 664 + otherlibs/threads/.cvsignore | 3 + otherlibs/threads/.depend | 44 + otherlibs/threads/Makefile | 127 + otherlibs/threads/Tests/.cvsignore | 1 + otherlibs/threads/Tests/Makefile | 38 + otherlibs/threads/Tests/close.ml | 14 + otherlibs/threads/Tests/sieve.ml | 33 + otherlibs/threads/Tests/sorts.ml | 228 + otherlibs/threads/Tests/test1.ml | 57 + otherlibs/threads/Tests/test2.ml | 15 + otherlibs/threads/Tests/test3.ml | 8 + otherlibs/threads/Tests/test4.ml | 13 + otherlibs/threads/Tests/test5.ml | 21 + otherlibs/threads/Tests/test6.ml | 17 + otherlibs/threads/Tests/test7.ml | 28 + otherlibs/threads/Tests/test8.ml | 46 + otherlibs/threads/Tests/test9.ml | 26 + otherlibs/threads/Tests/testA.ml | 24 + otherlibs/threads/Tests/testexit.ml | 22 + otherlibs/threads/Tests/testio.ml | 120 + otherlibs/threads/Tests/testsieve.ml | 42 + otherlibs/threads/Tests/testsignal.ml | 13 + otherlibs/threads/Tests/testsignal2.ml | 11 + otherlibs/threads/Tests/testsocket.ml | 31 + otherlibs/threads/Tests/token1.ml | 36 + otherlibs/threads/Tests/token2.ml | 36 + otherlibs/threads/Tests/torture.ml | 46 + otherlibs/threads/condition.ml | 36 + otherlibs/threads/condition.mli | 53 + otherlibs/threads/event.ml | 274 + otherlibs/threads/event.mli | 82 + otherlibs/threads/libvmthreads.clib | 1 + otherlibs/threads/marshal.ml | 58 + otherlibs/threads/mutex.ml | 39 + otherlibs/threads/mutex.mli | 50 + otherlibs/threads/pervasives.ml | 542 + otherlibs/threads/scheduler.c | 876 + otherlibs/threads/thread.ml | 141 + otherlibs/threads/thread.mli | 141 + otherlibs/threads/threadUnix.ml | 61 + otherlibs/threads/threadUnix.mli | 90 + otherlibs/threads/threads.mllib | 1 + otherlibs/threads/unix.ml | 1113 + otherlibs/threads/unix.mllib | 1 + otherlibs/unix/.cvsignore | 1 + otherlibs/unix/.depend | 796 + otherlibs/unix/Makefile | 49 + otherlibs/unix/accept.c | 54 + otherlibs/unix/access.c | 52 + otherlibs/unix/addrofstr.c | 53 + otherlibs/unix/alarm.c | 22 + otherlibs/unix/bind.c | 41 + otherlibs/unix/chdir.c | 25 + otherlibs/unix/chmod.c | 27 + otherlibs/unix/chown.c | 25 + otherlibs/unix/chroot.c | 25 + otherlibs/unix/close.c | 23 + otherlibs/unix/closedir.c | 33 + otherlibs/unix/connect.c | 44 + otherlibs/unix/cst2constr.c | 26 + otherlibs/unix/cst2constr.h | 16 + otherlibs/unix/cstringv.c | 32 + otherlibs/unix/dup.c | 25 + otherlibs/unix/dup2.c | 49 + otherlibs/unix/envir.c | 26 + otherlibs/unix/errmsg.c | 28 + otherlibs/unix/execv.c | 32 + otherlibs/unix/execve.c | 35 + otherlibs/unix/execvp.c | 51 + otherlibs/unix/exit.c | 26 + otherlibs/unix/fchmod.c | 35 + otherlibs/unix/fchown.c | 34 + otherlibs/unix/fcntl.c | 78 + otherlibs/unix/fork.c | 26 + otherlibs/unix/ftruncate.c | 49 + otherlibs/unix/getaddrinfo.c | 136 + otherlibs/unix/getcwd.c | 58 + otherlibs/unix/getegid.c | 22 + otherlibs/unix/geteuid.c | 22 + otherlibs/unix/getgid.c | 22 + otherlibs/unix/getgr.c | 56 + otherlibs/unix/getgroups.c | 49 + otherlibs/unix/gethost.c | 183 + otherlibs/unix/gethostname.c | 58 + otherlibs/unix/getlogin.c | 29 + otherlibs/unix/getnameinfo.c | 67 + otherlibs/unix/getpeername.c | 41 + otherlibs/unix/getpid.c | 22 + otherlibs/unix/getppid.c | 22 + otherlibs/unix/getproto.c | 70 + otherlibs/unix/getpw.c | 65 + otherlibs/unix/getserv.c | 76 + otherlibs/unix/getsockname.c | 41 + otherlibs/unix/gettimeofday.c | 38 + otherlibs/unix/getuid.c | 22 + otherlibs/unix/gmtime.c | 95 + otherlibs/unix/isatty.c | 22 + otherlibs/unix/itimer.c | 75 + otherlibs/unix/kill.c | 29 + otherlibs/unix/libunix.clib | 16 + otherlibs/unix/link.c | 23 + otherlibs/unix/listen.c | 35 + otherlibs/unix/lockf.c | 116 + otherlibs/unix/lseek.c | 57 + otherlibs/unix/mkdir.c | 25 + otherlibs/unix/mkfifo.c | 53 + otherlibs/unix/nice.c | 30 + otherlibs/unix/open.c | 58 + otherlibs/unix/opendir.c | 35 + otherlibs/unix/pipe.c | 29 + otherlibs/unix/putenv.c | 46 + otherlibs/unix/read.c | 38 + otherlibs/unix/readdir.c | 39 + otherlibs/unix/readlink.c | 48 + otherlibs/unix/rename.c | 25 + otherlibs/unix/rewinddir.c | 42 + otherlibs/unix/rmdir.c | 23 + otherlibs/unix/select.c | 110 + otherlibs/unix/sendrecv.c | 148 + otherlibs/unix/setgid.c | 23 + otherlibs/unix/setsid.c | 31 + otherlibs/unix/setuid.c | 23 + otherlibs/unix/shutdown.c | 40 + otherlibs/unix/signals.c | 106 + otherlibs/unix/sleep.c | 26 + otherlibs/unix/socket.c | 56 + otherlibs/unix/socketaddr.c | 138 + otherlibs/unix/socketaddr.h | 49 + otherlibs/unix/socketpair.c | 46 + otherlibs/unix/sockopt.c | 300 + otherlibs/unix/stat.c | 140 + otherlibs/unix/strofaddr.c | 50 + otherlibs/unix/symlink.c | 34 + otherlibs/unix/termios.c | 317 + otherlibs/unix/time.c | 24 + otherlibs/unix/times.c | 67 + otherlibs/unix/truncate.c | 49 + otherlibs/unix/umask.c | 24 + otherlibs/unix/unix.ml | 966 + otherlibs/unix/unix.mli | 1312 + otherlibs/unix/unix.mllib | 1 + otherlibs/unix/unixLabels.ml | 18 + otherlibs/unix/unixLabels.mli | 1324 + otherlibs/unix/unixsupport.c | 293 + otherlibs/unix/unixsupport.h | 28 + otherlibs/unix/unlink.c | 23 + otherlibs/unix/utimes.c | 72 + otherlibs/unix/wait.c | 102 + otherlibs/unix/write.c | 87 + otherlibs/win32graph/Makefile.nt | 35 + otherlibs/win32graph/dib.c | 496 + otherlibs/win32graph/dllgraphics.dlib | 1 + otherlibs/win32graph/draw.c | 648 + otherlibs/win32graph/events.c | 200 + otherlibs/win32graph/libgraph.h | 78 + otherlibs/win32graph/libgraphics.clib | 1 + otherlibs/win32graph/open.c | 364 + otherlibs/win32unix/.cvsignore | 3 + otherlibs/win32unix/.depend | 5 + otherlibs/win32unix/Makefile.nt | 61 + otherlibs/win32unix/accept.c | 66 + otherlibs/win32unix/bind.c | 34 + otherlibs/win32unix/channels.c | 88 + otherlibs/win32unix/close.c | 33 + otherlibs/win32unix/close_on.c | 46 + otherlibs/win32unix/connect.c | 39 + otherlibs/win32unix/createprocess.c | 87 + otherlibs/win32unix/dllunix.dlib | 17 + otherlibs/win32unix/dup.c | 34 + otherlibs/win32unix/dup2.c | 42 + otherlibs/win32unix/errmsg.c | 44 + otherlibs/win32unix/getpeername.c | 35 + otherlibs/win32unix/getpid.c | 24 + otherlibs/win32unix/getsockname.c | 32 + otherlibs/win32unix/gettimeofday.c | 36 + otherlibs/win32unix/libunix.clib | 17 + otherlibs/win32unix/link.c | 42 + otherlibs/win32unix/listen.c | 27 + otherlibs/win32unix/lockf.c | 160 + otherlibs/win32unix/lseek.c | 70 + otherlibs/win32unix/mkdir.c | 24 + otherlibs/win32unix/nonblock.c | 42 + otherlibs/win32unix/open.c | 67 + otherlibs/win32unix/pipe.c | 45 + otherlibs/win32unix/read.c | 54 + otherlibs/win32unix/rename.c | 43 + otherlibs/win32unix/select.c | 1155 + otherlibs/win32unix/sendrecv.c | 141 + otherlibs/win32unix/shutdown.c | 32 + otherlibs/win32unix/sleep.c | 27 + otherlibs/win32unix/socket.c | 55 + otherlibs/win32unix/socketaddr.h | 37 + otherlibs/win32unix/sockopt.c | 229 + otherlibs/win32unix/startup.c | 54 + otherlibs/win32unix/stat.c | 115 + otherlibs/win32unix/system.c | 47 + otherlibs/win32unix/unix.ml | 943 + otherlibs/win32unix/unixsupport.c | 269 + otherlibs/win32unix/unixsupport.h | 53 + otherlibs/win32unix/windbug.c | 32 + otherlibs/win32unix/windbug.h | 50 + otherlibs/win32unix/windir.c | 80 + otherlibs/win32unix/winlist.c | 80 + otherlibs/win32unix/winlist.h | 54 + otherlibs/win32unix/winwait.c | 70 + otherlibs/win32unix/winworker.c | 338 + otherlibs/win32unix/winworker.h | 70 + otherlibs/win32unix/write.c | 101 + parsing/.cvsignore | 9 + parsing/asttypes.mli | 36 + parsing/lexer.mli | 36 + parsing/lexer.mll | 502 + parsing/linenum.mli | 23 + parsing/linenum.mll | 74 + parsing/location.ml | 259 + parsing/location.mli | 57 + parsing/longident.ml | 38 + parsing/longident.mli | 23 + parsing/parse.ml | 64 + parsing/parse.mli | 21 + parsing/parser.mly | 1536 ++ parsing/parsetree.mli | 276 + parsing/printast.ml | 702 + parsing/printast.mli | 20 + parsing/syntaxerr.ml | 39 + parsing/syntaxerr.mli | 26 + stdlib/.cvsignore | 6 + stdlib/.depend | 144 + stdlib/Compflags | 27 + stdlib/Makefile | 59 + stdlib/Makefile.nt | 32 + stdlib/Makefile.shared | 96 + stdlib/StdlibModules | 49 + stdlib/arg.ml | 252 + stdlib/arg.mli | 135 + stdlib/array.ml | 279 + stdlib/array.mli | 205 + stdlib/arrayLabels.ml | 18 + stdlib/arrayLabels.mli | 209 + stdlib/buffer.ml | 173 + stdlib/buffer.mli | 106 + stdlib/callback.ml | 25 + stdlib/callback.mli | 34 + stdlib/camlinternalLazy.ml | 64 + stdlib/camlinternalLazy.mli | 25 + stdlib/camlinternalMod.ml | 68 + stdlib/camlinternalMod.mli | 23 + stdlib/camlinternalOO.ml | 588 + stdlib/camlinternalOO.mli | 153 + stdlib/char.ml | 69 + stdlib/char.mli | 48 + stdlib/complex.ml | 87 + stdlib/complex.mli | 86 + stdlib/digest.ml | 51 + stdlib/digest.mli | 53 + stdlib/filename.ml | 220 + stdlib/filename.mli | 107 + stdlib/format.ml | 1328 + stdlib/format.mli | 668 + stdlib/gc.ml | 101 + stdlib/gc.mli | 268 + stdlib/genlex.ml | 202 + stdlib/genlex.mli | 66 + stdlib/hashtbl.ml | 279 + stdlib/hashtbl.mli | 177 + stdlib/header.c | 191 + stdlib/headernt.c | 175 + stdlib/int32.ml | 54 + stdlib/int32.mli | 164 + stdlib/int64.ml | 59 + stdlib/int64.mli | 186 + stdlib/lazy.ml | 75 + stdlib/lazy.mli | 73 + stdlib/lexing.ml | 239 + stdlib/lexing.mli | 171 + stdlib/list.ml | 316 + stdlib/list.mli | 277 + stdlib/listLabels.ml | 18 + stdlib/listLabels.mli | 279 + stdlib/map.ml | 198 + stdlib/map.mli | 111 + stdlib/marshal.ml | 53 + stdlib/marshal.mli | 136 + stdlib/moreLabels.ml | 22 + stdlib/moreLabels.mli | 124 + stdlib/nativeint.ml | 55 + stdlib/nativeint.mli | 185 + stdlib/obj.ml | 57 + stdlib/obj.mli | 58 + stdlib/oo.ml | 19 + stdlib/oo.mli | 29 + stdlib/parsing.ml | 199 + stdlib/parsing.mli | 103 + stdlib/pervasives.ml | 447 + stdlib/pervasives.mli | 883 + stdlib/printexc.ml | 127 + stdlib/printexc.mli | 59 + stdlib/printf.ml | 652 + stdlib/printf.mli | 209 + stdlib/queue.ml | 165 + stdlib/queue.mli | 78 + stdlib/random.ml | 268 + stdlib/random.mli | 101 + stdlib/scanf.ml | 1293 + stdlib/scanf.mli | 417 + stdlib/set.ml | 330 + stdlib/set.mli | 153 + stdlib/sharpbang | 1 + stdlib/sort.ml | 99 + stdlib/sort.mli | 41 + stdlib/stack.ml | 42 + stdlib/stack.mli | 57 + stdlib/stdLabels.ml | 22 + stdlib/stdLabels.mli | 141 + stdlib/std_exit.ml | 18 + stdlib/stdlib.mllib | 48 + stdlib/stream.ml | 200 + stdlib/stream.mli | 106 + stdlib/string.ml | 183 + stdlib/string.mli | 184 + stdlib/stringLabels.ml | 18 + stdlib/stringLabels.mli | 164 + stdlib/sys.mli | 204 + stdlib/sys.mlp | 86 + stdlib/weak.ml | 307 + stdlib/weak.mli | 159 + test/.cvsignore | 2 + test/.depend | 28 + test/KB/equations.ml | 115 + test/KB/equations.mli | 32 + test/KB/kb.ml | 188 + test/KB/kb.mli | 29 + test/KB/kbmain.ml | 82 + test/KB/orderings.ml | 99 + test/KB/orderings.mli | 31 + test/KB/terms.ml | 137 + test/KB/terms.mli | 31 + test/Lex/.cvsignore | 5 + test/Lex/gram_aux.ml | 47 + test/Lex/grammar.mly | 114 + test/Lex/lexgen.ml | 266 + test/Lex/main.ml | 118 + test/Lex/output.ml | 169 + test/Lex/scan_aux.ml | 60 + test/Lex/scanner.mll | 132 + test/Lex/syntax.ml | 40 + test/Lex/testmain.ml | 48 + test/Lex/testscanner.mll | 135 + test/Makefile | 194 + test/Moretest/.cvsignore | 3 + test/Moretest/.depend | 16 + test/Moretest/Makefile | 269 + test/Moretest/arrays.ml | 86 + test/Moretest/backtrace.ml | 57 + test/Moretest/backtrace2.ml | 59 + test/Moretest/bigarrays.ml | 775 + test/Moretest/bigarrf.f | 27 + test/Moretest/bigarrfml.ml | 63 + test/Moretest/bigarrfstub.c | 60 + test/Moretest/bigints.ml | 12 + test/Moretest/bounds.ml | 28 + test/Moretest/boxedints.ml | 568 + test/Moretest/callbackprim.c | 54 + test/Moretest/cmcaml.ml | 16 + test/Moretest/cmmain.c | 22 + test/Moretest/cmstub.c | 17 + test/Moretest/equality.ml | 80 + test/Moretest/fftba.ml | 191 + test/Moretest/float.ml | 1 + test/Moretest/float_record.ml | 7 + test/Moretest/float_record.mli | 6 + test/Moretest/globroots.ml | 80 + test/Moretest/globrootsprim.c | 56 + test/Moretest/graph_example.ml | 131 + test/Moretest/graph_test.ml | 288 + test/Moretest/includestruct.ml | 92 + test/Moretest/intext.ml | 459 + test/Moretest/intextaux.c | 13 + test/Moretest/io.ml | 103 + test/Moretest/length.ml | 16 + test/Moretest/length.mli | 13 + test/Moretest/manyargs.ml | 42 + test/Moretest/manyargsprim.c | 25 + test/Moretest/md5.ml | 219 + test/Moretest/morematch.ml | 1169 + test/Moretest/multdef.ml | 2 + test/Moretest/multdef.mli | 3 + test/Moretest/patmatch.ml | 78 + test/Moretest/recmod.ml | 511 + test/Moretest/recmod.mli | 134 + test/Moretest/recmod/01bad.ml | 2 + test/Moretest/recmod/02bad.ml | 4 + test/Moretest/recmod/03ok.ml | 3 + test/Moretest/recmod/04bad.ml | 2 + test/Moretest/recmod/05bad.ml | 3 + test/Moretest/recmod/06ok.ml | 3 + test/Moretest/recmod/07bad.ml | 3 + test/Moretest/recmod/08bad.ml | 5 + test/Moretest/recmod/09bad.ml | 5 + test/Moretest/recmod/10ok.ml | 5 + test/Moretest/recmod/11bad.ml | 5 + test/Moretest/recmod/12bad.ml | 13 + test/Moretest/recmod/13ok.ml | 5 + test/Moretest/recmod/14bad.ml | 17 + test/Moretest/recmod/15bad.ml | 3 + test/Moretest/recmod/16ok.ml | 31 + test/Moretest/recmod/17ok.ml | 42 + test/Moretest/recmod/18ok.ml | 26 + test/Moretest/recmod/19ok.ml | 13 + test/Moretest/recmod/20ok.ml | 30 + test/Moretest/recmod/21ok.ml | 27 + test/Moretest/recvalues.ml | 38 + test/Moretest/regexp.ml | 993 + test/Moretest/sets.ml | 39 + test/Moretest/signals.ml | 32 + test/Moretest/stackoverflow.ml | 15 + test/Moretest/syserror.ml | 1 + test/Moretest/tailcalls.ml | 28 + test/Moretest/tbuffer.ml | 27 + test/Moretest/tcallback.ml | 68 + test/Moretest/testing.ml | 96 + test/Moretest/testing.mli | 34 + test/Moretest/testrandom.ml | 13 + test/Moretest/tfloat_record.ml | 5 + test/Moretest/tlength.ml | 23 + test/Moretest/tprintf.ml | 72 + test/Moretest/tscanf.ml | 1177 + test/Moretest/tscanf2_io.ml | 18 + test/Moretest/tscanf2_master.ml | 40 + test/Moretest/tscanf2_slave.ml | 27 + test/Moretest/usemultdef.ml | 1 + test/Moretest/warnings.ml | 44 + test/Moretest/wc.ml | 54 + test/Results/almabench.fast.out | 8 + test/Results/almabench.out | 8 + test/Results/bdd.out | 1 + test/Results/boyer.out | 1 + test/Results/fft.fast.out | 16 + test/Results/fft.out | 16 + test/Results/fib.out | 1 + test/Results/hamming.out | 100 + test/Results/kb.out | 5460 ++++ test/Results/nucleic.out | 1 + test/Results/quicksort.fast.out | 2 + test/Results/quicksort.out | 2 + test/Results/sieve.out | 1 + test/Results/soli.fast.out | 50 + test/Results/soli.out | 50 + test/Results/sorts.out | 198 + test/Results/takc.out | 1 + test/Results/taku.out | 1 + test/Results/weaktest.out | 1 + test/alloc.ml | 51 + test/almabench.ml | 324 + test/bdd.ml | 231 + test/boyer.ml | 911 + test/dynlink/Makefile | 54 + test/dynlink/main.ml | 17 + test/dynlink/plug1.ml | 4 + test/dynlink/plug2.ml | 4 + test/dynlink/stub1.c | 11 + test/dynlink/stub2.c | 13 + test/fft.ml | 189 + test/fib.ml | 24 + test/hamming.ml | 105 + test/natdynlink/Makefile | 88 + test/natdynlink/a.ml | 5 + test/natdynlink/api.ml | 18 + test/natdynlink/b.ml | 5 + test/natdynlink/bug.ml | 2 + test/natdynlink/c.ml | 4 + test/natdynlink/factorial.c | 18 + test/natdynlink/main.ml | 20 + test/natdynlink/pack_client.ml | 2 + test/natdynlink/packed1.ml | 6 + test/natdynlink/packed1_client.ml | 3 + test/natdynlink/plugin.ml | 10 + test/natdynlink/plugin.mli | 1 + test/natdynlink/plugin2.ml | 8 + test/natdynlink/plugin4.ml | 5 + test/natdynlink/plugin_ext.ml | 5 + test/natdynlink/plugin_high_arity.ml | 6 + test/natdynlink/plugin_ref.ml | 11 + test/natdynlink/plugin_simple.ml | 3 + test/natdynlink/plugin_thread.ml | 21 + test/natdynlink/sub/api.ml | 3 + test/natdynlink/sub/api.mli | 1 + test/natdynlink/sub/plugin.ml | 7 + test/natdynlink/sub/plugin3.ml | 3 + test/nucleic.ml | 3238 +++ test/ocamldoc/Makefile | 40 + test/ocamldoc/t1.ml | 19 + test/outputobj/Makefile | 33 + test/outputobj/entry.c | 13 + test/outputobj/main.cs | 11 + test/outputobj/main.ml | 23 + test/outputobj/plugin.ml | 4 + test/quicksort.ml | 92 + test/sieve.ml | 56 + test/soli.ml | 111 + test/sorts.ml | 4477 ++++ test/takc.ml | 23 + test/taku.ml | 22 + test/testinterp/.cvsignore | 3 + test/testinterp/coverage | 133 + test/testinterp/lib.ml | 46 + test/testinterp/no68k.rez | 1 + test/testinterp/noppc.rez | 1 + test/testinterp/t000.ml | 7 + test/testinterp/t010-const0.ml | 8 + test/testinterp/t010-const1.ml | 8 + test/testinterp/t010-const2.ml | 8 + test/testinterp/t010-const3.ml | 8 + test/testinterp/t011-constint.ml | 8 + test/testinterp/t020.ml | 10 + test/testinterp/t021-pushconst1.ml | 10 + test/testinterp/t021-pushconst2.ml | 10 + test/testinterp/t021-pushconst3.ml | 10 + test/testinterp/t022-pushconstint.ml | 10 + test/testinterp/t040-makeblock1.ml | 13 + test/testinterp/t040-makeblock2.ml | 15 + test/testinterp/t040-makeblock3.ml | 17 + test/testinterp/t041-makeblock.ml | 19 + test/testinterp/t050-getglobal.ml | 8 + test/testinterp/t050-pushgetglobal.ml | 10 + test/testinterp/t051-getglobalfield.ml | 13 + test/testinterp/t051-pushgetglobalfield.ml | 15 + test/testinterp/t060-raise.ml | 15 + test/testinterp/t070-branch.ml | 20 + test/testinterp/t070-branchif.ml | 20 + test/testinterp/t070-branchifnot.ml | 18 + test/testinterp/t071-boolnot.ml | 19 + test/testinterp/t080-eq.ml | 21 + test/testinterp/t080-geint.ml | 21 + test/testinterp/t080-gtint.ml | 20 + test/testinterp/t080-leint.ml | 21 + test/testinterp/t080-ltint.ml | 20 + test/testinterp/t080-neq.ml | 20 + test/testinterp/t090-acc0.ml | 25 + test/testinterp/t090-acc1.ml | 27 + test/testinterp/t090-acc2.ml | 29 + test/testinterp/t090-acc3.ml | 31 + test/testinterp/t090-acc4.ml | 33 + test/testinterp/t090-acc5.ml | 35 + test/testinterp/t090-acc6.ml | 37 + test/testinterp/t090-acc7.ml | 39 + test/testinterp/t091-acc.ml | 41 + test/testinterp/t092-pushacc.ml | 38 + test/testinterp/t092-pushacc0.ml | 22 + test/testinterp/t092-pushacc1.ml | 24 + test/testinterp/t092-pushacc2.ml | 26 + test/testinterp/t092-pushacc3.ml | 28 + test/testinterp/t092-pushacc4.ml | 30 + test/testinterp/t092-pushacc5.ml | 32 + test/testinterp/t092-pushacc6.ml | 34 + test/testinterp/t092-pushacc7.ml | 36 + test/testinterp/t093-pushacc.ml | 38 + test/testinterp/t100-pushtrap.ml | 21 + test/testinterp/t101-poptrap.ml | 21 + test/testinterp/t110-addint.ml | 26 + test/testinterp/t110-andint.ml | 22 + test/testinterp/t110-asrint-1.ml | 22 + test/testinterp/t110-asrint-2.ml | 22 + test/testinterp/t110-divint-1.ml | 22 + test/testinterp/t110-divint-2.ml | 22 + test/testinterp/t110-divint-3.ml | 33 + test/testinterp/t110-lslint.ml | 22 + test/testinterp/t110-lsrint.ml | 22 + test/testinterp/t110-modint-1.ml | 22 + test/testinterp/t110-modint-2.ml | 34 + test/testinterp/t110-mulint.ml | 22 + test/testinterp/t110-negint.ml | 25 + test/testinterp/t110-offsetint.ml | 21 + test/testinterp/t110-orint.ml | 22 + test/testinterp/t110-subint.ml | 26 + test/testinterp/t110-xorint.ml | 22 + test/testinterp/t120-getstringchar.ml | 22 + test/testinterp/t121-setstringchar.ml | 31 + test/testinterp/t130-getvectitem.ml | 24 + test/testinterp/t130-vectlength.ml | 23 + test/testinterp/t131-setvectitem.ml | 33 + test/testinterp/t140-switch-1.ml | 32 + test/testinterp/t140-switch-2.ml | 32 + test/testinterp/t140-switch-3.ml | 31 + test/testinterp/t140-switch-4.ml | 31 + test/testinterp/t141-switch-5.ml | 38 + test/testinterp/t141-switch-6.ml | 38 + test/testinterp/t141-switch-7.ml | 37 + test/testinterp/t142-switch-8.ml | 34 + test/testinterp/t142-switch-9.ml | 34 + test/testinterp/t142-switch-A.ml | 34 + test/testinterp/t150-push-1.ml | 24 + test/testinterp/t150-push-2.ml | 39 + test/testinterp/t160-closure.ml | 19 + test/testinterp/t161-apply1.ml | 42 + test/testinterp/t162-return.ml | 21 + test/testinterp/t163.ml | 23 + test/testinterp/t164-apply2.ml | 24 + test/testinterp/t164-apply3.ml | 25 + test/testinterp/t165-apply.ml | 28 + test/testinterp/t170-envacc2.ml | 37 + test/testinterp/t170-envacc3.ml | 42 + test/testinterp/t170-envacc4.ml | 47 + test/testinterp/t171-envacc.ml | 52 + test/testinterp/t172-pushenvacc1.ml | 34 + test/testinterp/t172-pushenvacc2.ml | 37 + test/testinterp/t172-pushenvacc3.ml | 42 + test/testinterp/t172-pushenvacc4.ml | 47 + test/testinterp/t173-pushenvacc.ml | 52 + test/testinterp/t180-appterm1.ml | 35 + test/testinterp/t180-appterm2.ml | 38 + test/testinterp/t180-appterm3.ml | 39 + test/testinterp/t181-appterm.ml | 40 + test/testinterp/t190-makefloatblock-1.ml | 17 + test/testinterp/t190-makefloatblock-2.ml | 18 + test/testinterp/t190-makefloatblock-3.ml | 19 + test/testinterp/t191-vectlength.ml | 26 + test/testinterp/t192-getfloatfield-1.ml | 23 + test/testinterp/t192-getfloatfield-2.ml | 23 + test/testinterp/t193-setfloatfield-1.ml | 36 + test/testinterp/t193-setfloatfield-2.ml | 36 + test/testinterp/t200-getfield0.ml | 25 + test/testinterp/t200-getfield1.ml | 26 + test/testinterp/t200-getfield2.ml | 27 + test/testinterp/t200-getfield3.ml | 28 + test/testinterp/t201-getfield.ml | 29 + test/testinterp/t210-setfield0.ml | 36 + test/testinterp/t210-setfield1.ml | 38 + test/testinterp/t210-setfield2.ml | 40 + test/testinterp/t210-setfield3.ml | 42 + test/testinterp/t211-setfield.ml | 44 + test/testinterp/t220-assign.ml | 27 + test/testinterp/t230-check_signals.ml | 28 + test/testinterp/t240-c_call1.ml | 21 + test/testinterp/t240-c_call2.ml | 22 + test/testinterp/t240-c_call3.ml | 23 + test/testinterp/t240-c_call4.ml | 32 + test/testinterp/t240-c_call5.ml | 33 + test/testinterp/t250-closurerec-1.ml | 19 + test/testinterp/t250-closurerec-2.ml | 29 + test/testinterp/t251-pushoffsetclosure0.ml | 39 + test/testinterp/t251-pushoffsetclosure2.ml | 34 + test/testinterp/t251-pushoffsetclosurem2.ml | 34 + test/testinterp/t252-pushoffsetclosure.ml | 38 + test/testinterp/t253-offsetclosure0.ml | 34 + test/testinterp/t253-offsetclosure2.ml | 34 + test/testinterp/t253-offsetclosurem2.ml | 34 + test/testinterp/t254-offsetclosure.ml | 37 + test/testinterp/t260-offsetref.ml | 31 + test/testinterp/t270-push_retaddr.ml | 36 + test/testinterp/t300-getmethod.ml | 5885 +++++ test/testinterp/t301-object.ml | 29 + test/testinterp/t310-alloc-1.ml | 1587 ++ test/testinterp/t310-alloc-2.ml | 2313 ++ test/testinterp/t320-gc-1.ml | 1589 ++ test/testinterp/t320-gc-2.ml | 1589 ++ test/testinterp/t320-gc-3.ml | 1589 ++ test/testinterp/t330-compact-1.ml | 15 + test/testinterp/t330-compact-2.ml | 755 + test/testinterp/t330-compact-3.ml | 1589 ++ test/testinterp/t330-compact-4.ml | 1589 ++ test/testinterp/t340-weak.ml | 2551 ++ test/testinterp/t350-heapcheck.ml | 2554 ++ test/testinterp/t360-stacks-1.ml | 43 + test/testinterp/t360-stacks-2.ml | 54 + test/weaktest.ml | 73 + testasmcomp/.cvsignore | 5 + testasmcomp/.depend | 17 + testasmcomp/Makefile | 159 + testasmcomp/alpha.S | 62 + testasmcomp/amd64.S | 53 + testasmcomp/arith.cmm | 222 + testasmcomp/arm.S | 45 + testasmcomp/checkbound.cmm | 21 + testasmcomp/fib.cmm | 19 + testasmcomp/hppa.S | 162 + testasmcomp/i386.S | 56 + testasmcomp/i386nt.asm | 67 + testasmcomp/ia64.S | 118 + testasmcomp/integr.cmm | 30 + testasmcomp/lexcmm.mli | 24 + testasmcomp/lexcmm.mll | 228 + testasmcomp/m68k.S | 59 + testasmcomp/main.c | 126 + testasmcomp/main.ml | 60 + testasmcomp/mainarith.c | 304 + testasmcomp/mips.s | 71 + testasmcomp/parsecmm.mly | 325 + testasmcomp/parsecmmaux.ml | 40 + testasmcomp/parsecmmaux.mli | 26 + testasmcomp/power-aix.S | 152 + testasmcomp/power-elf.S | 131 + testasmcomp/power-rhapsody.S | 129 + testasmcomp/quicksort.cmm | 43 + testasmcomp/quicksort2.cmm | 49 + testasmcomp/soli.cmm | 109 + testasmcomp/sparc.S | 41 + testasmcomp/tagged-fib.cmm | 19 + testasmcomp/tagged-integr.cmm | 45 + testasmcomp/tagged-quicksort.cmm | 46 + testasmcomp/tagged-tak.cmm | 23 + testasmcomp/tak.cmm | 23 + testlabl/.cvsignore | 1 + testlabl/Makefile | 17 + testlabl/bugs/pr3918a.mli | 1 + testlabl/bugs/pr3918b.mli | 1 + testlabl/bugs/pr3918c.ml | 10 + testlabl/bugs/pr3968.ml | 21 + testlabl/bugs/pr4018.ml | 46 + testlabl/bugs/pr4435.ml | 11 + testlabl/bugs/privrows-abate.ml | 53 + testlabl/bugs/woodyatt.ml | 14 + testlabl/bugs/yamagata021012.ml | 193 + testlabl/coerce.diffs | 93 + testlabl/dirs_multimatch | 1 + testlabl/dirs_poly | 1 + testlabl/fixedtypes.ml | 77 + testlabl/marshal_objects.diffs | 800 + testlabl/mixin.ml | 146 + testlabl/mixin2.ml | 179 + testlabl/mixin3.ml | 173 + testlabl/multimatch.diffs | 1418 ++ testlabl/multimatch.ml | 158 + testlabl/newlabels.ps | 1458 ++ testlabl/objvariant.diffs | 354 + testlabl/objvariant.ml | 42 + testlabl/poly.exp | 446 + testlabl/poly.exp2 | 459 + testlabl/poly.ml | 590 + testlabl/printers.ml | 11 + testlabl/private.ml | 31 + testlabl/tests.ml | 22 + testlabl/valvirt.diffs | 2349 ++ testlabl/varunion.ml | 435 + testobjects/.cvsignore | 1 + testobjects/Exemples.exp | 301 + testobjects/Exemples.ml | 333 + testobjects/Makefile | 25 + testobjects/Tests.exp | 228 + testobjects/Tests.ml | 316 + tools/.cvsignore | 22 + tools/.depend | 64 + tools/Characters | 16 + tools/DoMake | 61 + tools/MakeDepend | 17 + tools/Makefile | 21 + tools/Makefile.nt | 23 + tools/Makefile.shared | 276 + tools/OCamlc-custom | 10 + tools/Time | 10 + tools/addlabels.ml | 452 + tools/checkstack.c | 42 + tools/cleanup-header | 15 + tools/cvt_emit.mll | 84 + tools/depend.ml | 293 + tools/depend.mli | 23 + tools/dumpapprox.ml | 100 + tools/dumpobj.ml | 560 + tools/keywords.r | 121 + tools/lexer299.mll | 460 + tools/lexer301.mll | 461 + tools/magic | 11 + tools/make-opcodes | 2 + tools/make-package-macosx | 129 + tools/objinfo.ml | 99 + tools/ocaml-objcopy-macosx | 54 + tools/ocaml299to3.ml | 139 + tools/ocamlcp.ml | 133 + tools/ocamldep.ml | 303 + tools/ocamlmklib.mlp | 269 + tools/ocamlmktop.ml | 17 + tools/ocamlmktop.tpl | 16 + tools/ocamlprof.ml | 491 + tools/ocamlsize | 49 + tools/primreq.ml | 90 + tools/profiling.ml | 57 + tools/profiling.mli | 20 + tools/scrapelabels.ml | 289 + toplevel/expunge.ml | 78 + toplevel/genprintval.ml | 363 + toplevel/genprintval.mli | 52 + toplevel/opttopdirs.ml | 189 + toplevel/opttopdirs.mli | 31 + toplevel/opttoploop.ml | 446 + toplevel/opttoploop.mli | 102 + toplevel/opttopmain.ml | 121 + toplevel/opttopmain.mli | 17 + toplevel/opttopstart.ml | 15 + toplevel/topdirs.ml | 304 + toplevel/topdirs.mli | 34 + toplevel/toplevellib.mllib | 19 + toplevel/toploop.ml | 437 + toplevel/toploop.mli | 112 + toplevel/topmain.ml | 100 + toplevel/topmain.mli | 17 + toplevel/topstart.ml | 15 + toplevel/trace.ml | 144 + toplevel/trace.mli | 35 + typing/annot.mli | 23 + typing/btype.ml | 511 + typing/btype.mli | 155 + typing/ctype.ml | 3456 +++ typing/ctype.mli | 244 + typing/datarepr.ml | 96 + typing/datarepr.mli | 34 + typing/env.ml | 862 + typing/env.mli | 146 + typing/ident.ml | 184 + typing/ident.mli | 59 + typing/includeclass.ml | 107 + typing/includeclass.mli | 31 + typing/includecore.ml | 193 + typing/includecore.mli | 31 + typing/includemod.ml | 390 + typing/includemod.mli | 47 + typing/mtype.ml | 213 + typing/mtype.mli | 39 + typing/oprint.ml | 461 + typing/oprint.mli | 24 + typing/outcometree.mli | 104 + typing/parmatch.ml | 1712 ++ typing/parmatch.mli | 59 + typing/path.ml | 49 + typing/path.mli | 29 + typing/predef.ml | 203 + typing/predef.mli | 65 + typing/primitive.ml | 64 + typing/primitive.mli | 29 + typing/printtyp.ml | 1012 + typing/printtyp.mli | 68 + typing/stypes.ml | 167 + typing/stypes.mli | 35 + typing/subst.ml | 296 + typing/subst.mli | 54 + typing/typeclass.ml | 1599 ++ typing/typeclass.mli | 81 + typing/typecore.ml | 2247 ++ typing/typecore.mli | 113 + typing/typedecl.ml | 928 + typing/typedecl.mli | 76 + typing/typedtree.ml | 232 + typing/typedtree.mli | 167 + typing/typemod.ml | 1007 + typing/typemod.mli | 57 + typing/types.ml | 208 + typing/types.mli | 206 + typing/typetexp.ml | 567 + typing/typetexp.mli | 60 + typing/unused_var.ml | 263 + typing/unused_var.mli | 16 + utils/.cvsignore | 1 + utils/ccomp.ml | 127 + utils/ccomp.mli | 32 + utils/clflags.ml | 92 + utils/clflags.mli | 76 + utils/config.mlbuild | 125 + utils/config.mli | 115 + utils/config.mlp | 110 + utils/consistbl.ml | 57 + utils/consistbl.mli | 60 + utils/misc.ml | 197 + utils/misc.mli | 104 + utils/tbl.ml | 104 + utils/tbl.mli | 30 + utils/terminfo.ml | 25 + utils/terminfo.mli | 25 + utils/warnings.ml | 195 + utils/warnings.mli | 57 + win32caml/Makefile | 57 + win32caml/editbuffer.c | 514 + win32caml/editbuffer.h | 47 + win32caml/history.c | 98 + win32caml/history.h | 35 + win32caml/inria.h | 134 + win32caml/inriares.h | 48 + win32caml/libgraph.h | 108 + win32caml/menu.c | 830 + win32caml/ocaml.c | 1599 ++ win32caml/ocaml.ico | Bin 0 -> 766 bytes win32caml/ocaml.rc | 255 + win32caml/resource.h | 16 + win32caml/startocaml.c | 362 + yacc/.cvsignore | 5 + yacc/Makefile | 49 + yacc/Makefile.nt | 52 + yacc/closure.c | 283 + yacc/defs.h | 359 + yacc/error.c | 314 + yacc/lalr.c | 663 + yacc/lr0.c | 621 + yacc/main.c | 412 + yacc/mkpar.c | 366 + yacc/output.c | 984 + yacc/reader.c | 1908 ++ yacc/skeleton.c | 58 + yacc/symtab.c | 129 + yacc/verbose.c | 350 + yacc/warshall.c | 96 + 2444 files changed, 463648 insertions(+) create mode 100644 Changes create mode 100644 INSTALL create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 Makefile.nt create mode 100644 README create mode 100644 README.win32 create mode 100644 Upgrading create mode 100644 VERSION create mode 100644 _tags create mode 100644 asmcomp/.cvsignore create mode 100644 asmcomp/alpha/arch.ml create mode 100644 asmcomp/alpha/emit.mlp create mode 100644 asmcomp/alpha/proc.ml create mode 100644 asmcomp/alpha/reload.ml create mode 100644 asmcomp/alpha/scheduling.ml create mode 100644 asmcomp/alpha/selection.ml create mode 100644 asmcomp/amd64/arch.ml create mode 100644 asmcomp/amd64/emit.mlp create mode 100644 asmcomp/amd64/emit_nt.mlp create mode 100644 asmcomp/amd64/proc.ml create mode 100644 asmcomp/amd64/proc_nt.ml create mode 100644 asmcomp/amd64/reload.ml create mode 100644 asmcomp/amd64/scheduling.ml create mode 100644 asmcomp/amd64/selection.ml create mode 100644 asmcomp/arm/arch.ml create mode 100644 asmcomp/arm/emit.mlp create mode 100644 asmcomp/arm/proc.ml create mode 100644 asmcomp/arm/reload.ml create mode 100644 asmcomp/arm/scheduling.ml create mode 100644 asmcomp/arm/selection.ml create mode 100644 asmcomp/asmgen.ml create mode 100644 asmcomp/asmgen.mli create mode 100644 asmcomp/asmlibrarian.ml create mode 100644 asmcomp/asmlibrarian.mli create mode 100644 asmcomp/asmlink.ml create mode 100644 asmcomp/asmlink.mli create mode 100644 asmcomp/asmpackager.ml create mode 100644 asmcomp/asmpackager.mli create mode 100644 asmcomp/clambda.ml create mode 100644 asmcomp/clambda.mli create mode 100644 asmcomp/closure.ml create mode 100644 asmcomp/closure.mli create mode 100644 asmcomp/cmm.ml create mode 100644 asmcomp/cmm.mli create mode 100644 asmcomp/cmmgen.ml create mode 100644 asmcomp/cmmgen.mli create mode 100644 asmcomp/codegen.ml create mode 100644 asmcomp/codegen.mli create mode 100644 asmcomp/coloring.ml create mode 100644 asmcomp/coloring.mli create mode 100644 asmcomp/comballoc.ml create mode 100644 asmcomp/comballoc.mli create mode 100644 asmcomp/compilenv.ml create mode 100644 asmcomp/compilenv.mli create mode 100644 asmcomp/debuginfo.ml create mode 100644 asmcomp/debuginfo.mli create mode 100644 asmcomp/emit.mli create mode 100644 asmcomp/emitaux.ml create mode 100644 asmcomp/emitaux.mli create mode 100644 asmcomp/hppa/arch.ml create mode 100644 asmcomp/hppa/emit.mlp create mode 100644 asmcomp/hppa/proc.ml create mode 100644 asmcomp/hppa/reload.ml create mode 100644 asmcomp/hppa/scheduling.ml create mode 100644 asmcomp/hppa/selection.ml create mode 100644 asmcomp/i386/arch.ml create mode 100644 asmcomp/i386/emit.mlp create mode 100644 asmcomp/i386/emit_nt.mlp create mode 100644 asmcomp/i386/proc.ml create mode 100644 asmcomp/i386/proc_nt.ml create mode 100644 asmcomp/i386/reload.ml create mode 100644 asmcomp/i386/scheduling.ml create mode 100644 asmcomp/i386/selection.ml create mode 100644 asmcomp/ia64/arch.ml create mode 100644 asmcomp/ia64/emit.mlp create mode 100644 asmcomp/ia64/proc.ml create mode 100644 asmcomp/ia64/reload.ml create mode 100644 asmcomp/ia64/scheduling.ml create mode 100644 asmcomp/ia64/selection.ml create mode 100644 asmcomp/interf.ml create mode 100644 asmcomp/interf.mli create mode 100644 asmcomp/linearize.ml create mode 100644 asmcomp/linearize.mli create mode 100644 asmcomp/liveness.ml create mode 100644 asmcomp/liveness.mli create mode 100644 asmcomp/m68k/README create mode 100644 asmcomp/mach.ml create mode 100644 asmcomp/mach.mli create mode 100644 asmcomp/mips/arch.ml create mode 100644 asmcomp/mips/emit.mlp create mode 100644 asmcomp/mips/proc.ml create mode 100644 asmcomp/mips/reload.ml create mode 100644 asmcomp/mips/scheduling.ml create mode 100644 asmcomp/mips/selection.ml create mode 100644 asmcomp/power/arch.ml create mode 100644 asmcomp/power/emit.mlp create mode 100644 asmcomp/power/proc.ml create mode 100644 asmcomp/power/reload.ml create mode 100644 asmcomp/power/scheduling.ml create mode 100644 asmcomp/power/selection.ml create mode 100644 asmcomp/printcmm.ml create mode 100644 asmcomp/printcmm.mli create mode 100644 asmcomp/printlinear.ml create mode 100644 asmcomp/printlinear.mli create mode 100644 asmcomp/printmach.ml create mode 100644 asmcomp/printmach.mli create mode 100644 asmcomp/proc.mli create mode 100644 asmcomp/reg.ml create mode 100644 asmcomp/reg.mli create mode 100644 asmcomp/reload.mli create mode 100644 asmcomp/reloadgen.ml create mode 100644 asmcomp/reloadgen.mli create mode 100644 asmcomp/schedgen.ml create mode 100644 asmcomp/schedgen.mli create mode 100644 asmcomp/scheduling.mli create mode 100644 asmcomp/selectgen.ml create mode 100644 asmcomp/selectgen.mli create mode 100644 asmcomp/selection.mli create mode 100644 asmcomp/sparc/arch.ml create mode 100644 asmcomp/sparc/emit.mlp create mode 100644 asmcomp/sparc/proc.ml create mode 100644 asmcomp/sparc/reload.ml create mode 100644 asmcomp/sparc/scheduling.ml create mode 100644 asmcomp/sparc/selection.ml create mode 100644 asmcomp/spill.ml create mode 100644 asmcomp/spill.mli create mode 100644 asmcomp/split.ml create mode 100644 asmcomp/split.mli create mode 100644 asmrun/.cvsignore create mode 100644 asmrun/.depend create mode 100644 asmrun/Makefile create mode 100644 asmrun/Makefile.nt create mode 100644 asmrun/alpha.S create mode 100644 asmrun/amd64.S create mode 100644 asmrun/amd64nt.asm create mode 100644 asmrun/arm.S create mode 100644 asmrun/backtrace.c create mode 100644 asmrun/fail.c create mode 100644 asmrun/hppa.S create mode 100644 asmrun/i386.S create mode 100644 asmrun/i386nt.asm create mode 100644 asmrun/ia64.S create mode 100644 asmrun/m68k.S create mode 100644 asmrun/mips.s create mode 100644 asmrun/natdynlink.c create mode 100644 asmrun/natdynlink.h create mode 100644 asmrun/power-aix.S create mode 100644 asmrun/power-elf.S create mode 100644 asmrun/power-rhapsody.S create mode 100644 asmrun/roots.c create mode 100644 asmrun/signals_asm.c create mode 100644 asmrun/signals_osdep.h create mode 100644 asmrun/sparc.S create mode 100644 asmrun/stack.h create mode 100644 asmrun/startup.c create mode 100644 boot/.cvsignore create mode 100755 boot/myocamlbuild.boot create mode 100755 boot/ocamlc create mode 100755 boot/ocamldep create mode 100755 boot/ocamllex create mode 100644 build/.cvsignore create mode 100755 build/boot-c-parts-windows.sh create mode 100755 build/boot-c-parts.sh create mode 100755 build/boot.sh create mode 100755 build/buildbot create mode 100755 build/camlp4-bootstrap.sh create mode 100755 build/camlp4-byte-only.sh create mode 100755 build/camlp4-native-only.sh create mode 100644 build/camlp4-targets.sh create mode 100755 build/distclean.sh create mode 100755 build/fastworld.sh create mode 100755 build/install.sh create mode 100644 build/mixed-boot.sh create mode 100755 build/mkconfig.sh create mode 100755 build/mkmyocamlbuild_config.sh create mode 100755 build/mkruntimedef.sh create mode 100755 build/myocamlbuild.sh create mode 100644 build/new-build-system create mode 100755 build/ocamlbuild-byte-only.sh create mode 100755 build/ocamlbuild-native-only.sh create mode 100755 build/ocamlbuildlib-native-only.sh create mode 100644 build/otherlibs-targets.sh create mode 100755 build/partial-install.sh create mode 100644 build/targets.sh create mode 100644 build/tolower.sed create mode 100755 build/world.all.sh create mode 100755 build/world.byte.sh create mode 100755 build/world.native.sh create mode 100755 build/world.sh create mode 100644 bytecomp/.cvsignore create mode 100644 bytecomp/bytegen.ml create mode 100644 bytecomp/bytegen.mli create mode 100644 bytecomp/bytelibrarian.ml create mode 100644 bytecomp/bytelibrarian.mli create mode 100644 bytecomp/bytelink.ml create mode 100644 bytecomp/bytelink.mli create mode 100644 bytecomp/bytepackager.ml create mode 100644 bytecomp/bytepackager.mli create mode 100644 bytecomp/bytesections.ml create mode 100644 bytecomp/bytesections.mli create mode 100644 bytecomp/cmo_format.mli create mode 100644 bytecomp/dll.ml create mode 100644 bytecomp/dll.mli create mode 100644 bytecomp/emitcode.ml create mode 100644 bytecomp/emitcode.mli create mode 100644 bytecomp/instruct.ml create mode 100644 bytecomp/instruct.mli create mode 100644 bytecomp/lambda.ml create mode 100644 bytecomp/lambda.mli create mode 100644 bytecomp/matching.ml create mode 100644 bytecomp/matching.mli create mode 100644 bytecomp/meta.ml create mode 100644 bytecomp/meta.mli create mode 100644 bytecomp/printinstr.ml create mode 100644 bytecomp/printinstr.mli create mode 100644 bytecomp/printlambda.ml create mode 100644 bytecomp/printlambda.mli create mode 100644 bytecomp/runtimedef.mli create mode 100644 bytecomp/simplif.ml create mode 100644 bytecomp/simplif.mli create mode 100644 bytecomp/switch.ml create mode 100644 bytecomp/switch.mli create mode 100644 bytecomp/symtable.ml create mode 100644 bytecomp/symtable.mli create mode 100644 bytecomp/translclass.ml create mode 100644 bytecomp/translclass.mli create mode 100644 bytecomp/translcore.ml create mode 100644 bytecomp/translcore.mli create mode 100644 bytecomp/translmod.ml create mode 100644 bytecomp/translmod.mli create mode 100644 bytecomp/translobj.ml create mode 100644 bytecomp/translobj.mli create mode 100644 bytecomp/typeopt.ml create mode 100644 bytecomp/typeopt.mli create mode 100644 byterun/.cvsignore create mode 100644 byterun/.depend create mode 100644 byterun/Makefile create mode 100755 byterun/Makefile.common create mode 100644 byterun/Makefile.nt create mode 100644 byterun/alloc.c create mode 100644 byterun/alloc.h create mode 100644 byterun/array.c create mode 100644 byterun/backtrace.c create mode 100644 byterun/backtrace.h create mode 100644 byterun/callback.c create mode 100644 byterun/callback.h create mode 100644 byterun/compact.c create mode 100644 byterun/compact.h create mode 100644 byterun/compare.c create mode 100644 byterun/compare.h create mode 100644 byterun/compatibility.h create mode 100644 byterun/config.h create mode 100644 byterun/custom.c create mode 100644 byterun/custom.h create mode 100644 byterun/debugger.c create mode 100644 byterun/debugger.h create mode 100644 byterun/dynlink.c create mode 100644 byterun/dynlink.h create mode 100644 byterun/exec.h create mode 100644 byterun/extern.c create mode 100644 byterun/fail.c create mode 100644 byterun/fail.h create mode 100644 byterun/finalise.c create mode 100644 byterun/finalise.h create mode 100644 byterun/fix_code.c create mode 100644 byterun/fix_code.h create mode 100644 byterun/floats.c create mode 100644 byterun/freelist.c create mode 100644 byterun/freelist.h create mode 100644 byterun/gc.h create mode 100644 byterun/gc_ctrl.c create mode 100644 byterun/gc_ctrl.h create mode 100644 byterun/globroots.c create mode 100644 byterun/globroots.h create mode 100644 byterun/hash.c create mode 100644 byterun/instrtrace.c create mode 100644 byterun/instrtrace.h create mode 100644 byterun/instruct.h create mode 100644 byterun/int64_emul.h create mode 100644 byterun/int64_format.h create mode 100644 byterun/int64_native.h create mode 100644 byterun/intern.c create mode 100644 byterun/interp.c create mode 100644 byterun/interp.h create mode 100644 byterun/intext.h create mode 100644 byterun/ints.c create mode 100644 byterun/io.c create mode 100644 byterun/io.h create mode 100644 byterun/lexing.c create mode 100644 byterun/main.c create mode 100644 byterun/major_gc.c create mode 100644 byterun/major_gc.h create mode 100644 byterun/md5.c create mode 100644 byterun/md5.h create mode 100644 byterun/memory.c create mode 100644 byterun/memory.h create mode 100644 byterun/meta.c create mode 100644 byterun/minor_gc.c create mode 100644 byterun/minor_gc.h create mode 100644 byterun/misc.c create mode 100644 byterun/misc.h create mode 100644 byterun/mlvalues.h create mode 100644 byterun/obj.c create mode 100644 byterun/osdeps.h create mode 100644 byterun/parsing.c create mode 100644 byterun/prims.h create mode 100644 byterun/printexc.c create mode 100644 byterun/printexc.h create mode 100644 byterun/reverse.h create mode 100644 byterun/roots.c create mode 100644 byterun/roots.h create mode 100644 byterun/signals.c create mode 100644 byterun/signals.h create mode 100644 byterun/signals_byt.c create mode 100644 byterun/signals_machdep.h create mode 100644 byterun/stacks.c create mode 100644 byterun/stacks.h create mode 100644 byterun/startup.c create mode 100644 byterun/startup.h create mode 100644 byterun/str.c create mode 100644 byterun/sys.c create mode 100644 byterun/sys.h create mode 100644 byterun/terminfo.c create mode 100644 byterun/ui.h create mode 100644 byterun/unix.c create mode 100644 byterun/weak.c create mode 100644 byterun/weak.h create mode 100644 byterun/win32.c create mode 100644 camlp4/.cvsignore create mode 100644 camlp4/.vcs create mode 100644 camlp4/CHANGES create mode 100644 camlp4/Camlp4.mlpack create mode 100644 camlp4/Camlp4/.cvsignore create mode 100644 camlp4/Camlp4/Camlp4Ast.partial.ml create mode 100644 camlp4/Camlp4/Debug.ml create mode 100644 camlp4/Camlp4/Debug.mli create mode 100644 camlp4/Camlp4/ErrorHandler.ml create mode 100644 camlp4/Camlp4/ErrorHandler.mli create mode 100644 camlp4/Camlp4/OCamlInitSyntax.ml create mode 100644 camlp4/Camlp4/Options.ml create mode 100644 camlp4/Camlp4/Options.mli create mode 100644 camlp4/Camlp4/PreCast.ml create mode 100644 camlp4/Camlp4/PreCast.mli create mode 100644 camlp4/Camlp4/Printers.mlpack create mode 100644 camlp4/Camlp4/Printers/DumpCamlp4Ast.ml create mode 100644 camlp4/Camlp4/Printers/DumpCamlp4Ast.mli create mode 100644 camlp4/Camlp4/Printers/DumpOCamlAst.ml create mode 100644 camlp4/Camlp4/Printers/DumpOCamlAst.mli create mode 100644 camlp4/Camlp4/Printers/Null.ml create mode 100644 camlp4/Camlp4/Printers/Null.mli create mode 100644 camlp4/Camlp4/Printers/OCaml.ml create mode 100644 camlp4/Camlp4/Printers/OCaml.mli create mode 100644 camlp4/Camlp4/Printers/OCamlr.ml create mode 100644 camlp4/Camlp4/Printers/OCamlr.mli create mode 100644 camlp4/Camlp4/Register.ml create mode 100644 camlp4/Camlp4/Register.mli create mode 100644 camlp4/Camlp4/Sig.ml create mode 100644 camlp4/Camlp4/Struct.mlpack create mode 100644 camlp4/Camlp4/Struct/.cvsignore create mode 100644 camlp4/Camlp4/Struct/AstFilters.ml create mode 100644 camlp4/Camlp4/Struct/Camlp4Ast.mlast create mode 100644 camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml create mode 100644 camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli create mode 100644 camlp4/Camlp4/Struct/CleanAst.ml create mode 100644 camlp4/Camlp4/Struct/CommentFilter.ml create mode 100644 camlp4/Camlp4/Struct/CommentFilter.mli create mode 100644 camlp4/Camlp4/Struct/DynAst.ml create mode 100644 camlp4/Camlp4/Struct/DynLoader.ml create mode 100644 camlp4/Camlp4/Struct/DynLoader.mli create mode 100644 camlp4/Camlp4/Struct/EmptyError.ml create mode 100644 camlp4/Camlp4/Struct/EmptyError.mli create mode 100644 camlp4/Camlp4/Struct/EmptyPrinter.ml create mode 100644 camlp4/Camlp4/Struct/EmptyPrinter.mli create mode 100644 camlp4/Camlp4/Struct/FreeVars.ml create mode 100644 camlp4/Camlp4/Struct/FreeVars.mli create mode 100644 camlp4/Camlp4/Struct/Grammar.mlpack create mode 100644 camlp4/Camlp4/Struct/Grammar/Context.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Delete.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Dynamic.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Entry.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Failed.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Find.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Fold.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Fold.mli create mode 100644 camlp4/Camlp4/Struct/Grammar/Insert.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Parser.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Parser.mli create mode 100644 camlp4/Camlp4/Struct/Grammar/Print.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Print.mli create mode 100644 camlp4/Camlp4/Struct/Grammar/Search.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Static.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Structure.ml create mode 100644 camlp4/Camlp4/Struct/Grammar/Tools.ml create mode 100644 camlp4/Camlp4/Struct/Lexer.mll create mode 100644 camlp4/Camlp4/Struct/Loc.ml create mode 100644 camlp4/Camlp4/Struct/Loc.mli create mode 100644 camlp4/Camlp4/Struct/Quotation.ml create mode 100644 camlp4/Camlp4/Struct/Token.ml create mode 100644 camlp4/Camlp4/Struct/Token.mli create mode 100644 camlp4/Camlp4Bin.ml create mode 100644 camlp4/Camlp4Filters/Camlp4AstLifter.ml create mode 100644 camlp4/Camlp4Filters/Camlp4ExceptionTracer.ml create mode 100644 camlp4/Camlp4Filters/Camlp4FoldGenerator.ml create mode 100644 camlp4/Camlp4Filters/Camlp4LocationStripper.ml create mode 100644 camlp4/Camlp4Filters/Camlp4MapGenerator.ml create mode 100644 camlp4/Camlp4Filters/Camlp4MetaGenerator.ml create mode 100644 camlp4/Camlp4Filters/Camlp4Profiler.ml create mode 100644 camlp4/Camlp4Filters/Camlp4TrashRemover.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4AstLoader.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4DebugParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4GrammarParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4ListComprehension.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4MacroParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlParserParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlRevisedParserParser.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4OCamlRevisedQuotationExpander.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml create mode 100644 camlp4/Camlp4Parsers/Camlp4QuotationExpander.ml create mode 100644 camlp4/Camlp4Printers/Camlp4AstDumper.ml create mode 100644 camlp4/Camlp4Printers/Camlp4AutoPrinter.ml create mode 100644 camlp4/Camlp4Printers/Camlp4NullDumper.ml create mode 100644 camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml create mode 100644 camlp4/Camlp4Printers/Camlp4OCamlPrinter.ml create mode 100644 camlp4/Camlp4Printers/Camlp4OCamlRevisedPrinter.ml create mode 100644 camlp4/Camlp4Top.mlpack create mode 100644 camlp4/Camlp4Top/Rprint.ml create mode 100644 camlp4/Camlp4Top/Top.ml create mode 100644 camlp4/Camlp4_config.ml create mode 100644 camlp4/Camlp4_config.mli create mode 100644 camlp4/ICHANGES create mode 100644 camlp4/Makefile create mode 100644 camlp4/Makefile.ml create mode 100644 camlp4/boot/.cvsignore create mode 100644 camlp4/boot/Camlp4.ml create mode 100644 camlp4/boot/Camlp4.ml4 create mode 100644 camlp4/boot/Camlp4Ast.ml create mode 100644 camlp4/boot/Makefile create mode 100644 camlp4/boot/camlp4boot.ml create mode 100644 camlp4/boot/camlp4boot.ml4 create mode 100644 camlp4/build/.cvsignore create mode 100644 camlp4/camlp4.odocl create mode 100644 camlp4/camlp4fulllib.mllib create mode 100644 camlp4/camlp4lib.mllib create mode 100644 camlp4/camlp4prof.ml create mode 100644 camlp4/camlp4prof.mli create mode 100644 camlp4/examples/_tags create mode 100644 camlp4/examples/all.itarget create mode 100644 camlp4/examples/apply_operator.ml create mode 100644 camlp4/examples/apply_operator_test.ml create mode 100644 camlp4/examples/arith.ml create mode 100644 camlp4/examples/debug_extension.ml create mode 100644 camlp4/examples/ex_str.ml create mode 100644 camlp4/examples/ex_str_test.ml create mode 100644 camlp4/examples/expression_closure.ml create mode 100644 camlp4/examples/expression_closure_filter.ml create mode 100644 camlp4/examples/expression_closure_test.ml create mode 100644 camlp4/examples/fancy_lambda_quot.ml create mode 100644 camlp4/examples/fancy_lambda_quot_test.ml create mode 100644 camlp4/examples/free_vars_test.ml create mode 100644 camlp4/examples/gen_match_case.ml create mode 100644 camlp4/examples/gen_type_N.ml create mode 100644 camlp4/examples/gettext_test.ml create mode 100644 camlp4/examples/global_handler.ml create mode 100644 camlp4/examples/global_handler_test.ml create mode 100644 camlp4/examples/lambda_parser.ml create mode 100644 camlp4/examples/lambda_quot.ml create mode 100644 camlp4/examples/lambda_quot_expr.ml create mode 100644 camlp4/examples/lambda_quot_patt.ml create mode 100644 camlp4/examples/lambda_test.ml create mode 100644 camlp4/examples/macros.ml create mode 100644 camlp4/examples/parse_files.ml create mode 100644 camlp4/examples/syb_fold.ml create mode 100644 camlp4/examples/syb_map.ml create mode 100644 camlp4/examples/test.itarget create mode 100644 camlp4/examples/test_macros.ml create mode 100644 camlp4/examples/test_type_quotation.ml create mode 100644 camlp4/examples/type_quotation.ml create mode 100644 camlp4/man/.cvsignore create mode 100644 camlp4/man/Makefile create mode 100644 camlp4/man/camlp4.1.tpl create mode 100644 camlp4/man/camlp4.help.tpl create mode 100644 camlp4/mkcamlp4.ml create mode 100644 camlp4/test/fixtures/assert.ml create mode 100644 camlp4/test/fixtures/backquoted_irrefutable_tuple.ml create mode 100644 camlp4/test/fixtures/backquoted_record.ml create mode 100644 camlp4/test/fixtures/backquoted_tuple.ml create mode 100644 camlp4/test/fixtures/big-tab1.ml create mode 100644 camlp4/test/fixtures/big-tab2.ml create mode 100644 camlp4/test/fixtures/big-tab3.ml create mode 100644 camlp4/test/fixtures/bug-4058.ml create mode 100644 camlp4/test/fixtures/bug-4337.ml create mode 100644 camlp4/test/fixtures/bug-by-vincent-balat.ml create mode 100644 camlp4/test/fixtures/bug-camlp4o-benjamin-monate.ml create mode 100644 camlp4/test/fixtures/bug-camlp4o-constr-arity-expr.ml create mode 100644 camlp4/test/fixtures/bug-camlp4o-constr-arity.ml create mode 100644 camlp4/test/fixtures/bug_escaping_quot.ml create mode 100644 camlp4/test/fixtures/chars.ml create mode 100644 camlp4/test/fixtures/class_expr_quot.ml create mode 100644 camlp4/test/fixtures/comments.ml create mode 100644 camlp4/test/fixtures/comments.mli create mode 100644 camlp4/test/fixtures/comments2.ml create mode 100644 camlp4/test/fixtures/constant-parser.ml create mode 100644 camlp4/test/fixtures/curry-constr.ml create mode 100644 camlp4/test/fixtures/default_quotation.ml create mode 100644 camlp4/test/fixtures/exception-with-eqn-bug.ml create mode 100644 camlp4/test/fixtures/external.ml create mode 100644 camlp4/test/fixtures/fun.ml create mode 100644 camlp4/test/fixtures/functor-perf.ml create mode 100644 camlp4/test/fixtures/functor-perf2.gen.ml create mode 100644 camlp4/test/fixtures/functor-perf2.ml create mode 100644 camlp4/test/fixtures/functor-perf3.ml create mode 100644 camlp4/test/fixtures/gen_map.ml create mode 100644 camlp4/test/fixtures/gram-fold.ml create mode 100644 camlp4/test/fixtures/gram-list.ml create mode 100644 camlp4/test/fixtures/gram-loc-lost.ml create mode 100644 camlp4/test/fixtures/gram-sub-rule.ml create mode 100644 camlp4/test/fixtures/gram-tree.ml create mode 100644 camlp4/test/fixtures/gram-tree2.ml create mode 100644 camlp4/test/fixtures/gram-tree3.ml create mode 100644 camlp4/test/fixtures/gram.ml create mode 100644 camlp4/test/fixtures/idents create mode 100644 camlp4/test/fixtures/idents1 create mode 100644 camlp4/test/fixtures/idents2 create mode 100644 camlp4/test/fixtures/if.ml create mode 100644 camlp4/test/fixtures/label.ml create mode 100644 camlp4/test/fixtures/lambda_free.ml create mode 100644 camlp4/test/fixtures/loc-bug.ml create mode 100644 camlp4/test/fixtures/macrotest.ml create mode 100644 camlp4/test/fixtures/macrotest.mli create mode 100644 camlp4/test/fixtures/macrotest2.ml create mode 100644 camlp4/test/fixtures/macrotest3.ml create mode 100644 camlp4/test/fixtures/make_extend.ml create mode 100644 camlp4/test/fixtures/match.ml create mode 100644 camlp4/test/fixtures/match_parser.ml create mode 100644 camlp4/test/fixtures/meta_multi_term.ml create mode 100644 camlp4/test/fixtures/metalib.ml create mode 100644 camlp4/test/fixtures/method_private_virtual.ml create mode 100644 camlp4/test/fixtures/mod.ml create mode 100644 camlp4/test/fixtures/mod2.ml create mode 100644 camlp4/test/fixtures/operators.ml create mode 100644 camlp4/test/fixtures/operators.mli create mode 100644 camlp4/test/fixtures/original_syntax.ml create mode 100644 camlp4/test/fixtures/outside-scope.ml create mode 100644 camlp4/test/fixtures/parser.ml create mode 100644 camlp4/test/fixtures/pp_let_in.ml create mode 100644 camlp4/test/fixtures/pp_let_in2.ml create mode 100644 camlp4/test/fixtures/pp_xml.ml create mode 100644 camlp4/test/fixtures/pprecordtyp.ml create mode 100644 camlp4/test/fixtures/pr4314.ml create mode 100644 camlp4/test/fixtures/pr4314gram1.ml create mode 100644 camlp4/test/fixtures/pr4314gram2.ml create mode 100644 camlp4/test/fixtures/pr4314gram3.ml create mode 100644 camlp4/test/fixtures/pr4314gram4.ml create mode 100644 camlp4/test/fixtures/pr4314gram5.ml create mode 100644 camlp4/test/fixtures/pr4329.ml create mode 100644 camlp4/test/fixtures/pr4330.ml create mode 100644 camlp4/test/fixtures/pr4357.ml create mode 100644 camlp4/test/fixtures/pr4357sample.ml create mode 100644 camlp4/test/fixtures/pr4357sample2.ml create mode 100644 camlp4/test/fixtures/pr4452.ml create mode 100644 camlp4/test/fixtures/private_row.ml create mode 100644 camlp4/test/fixtures/rec.ml create mode 100644 camlp4/test/fixtures/seq.ml create mode 100644 camlp4/test/fixtures/seq2.ml create mode 100644 camlp4/test/fixtures/simplify.ml create mode 100644 camlp4/test/fixtures/simplify_r.ml create mode 100644 camlp4/test/fixtures/stream-parser-bug.ml create mode 100644 camlp4/test/fixtures/string.ml create mode 100644 camlp4/test/fixtures/superfluous.ml create mode 100644 camlp4/test/fixtures/transform-examples.ml create mode 100644 camlp4/test/fixtures/try.ml create mode 100644 camlp4/test/fixtures/tuple_as_retval.ml create mode 100644 camlp4/test/fixtures/type.ml create mode 100644 camlp4/test/fixtures/type_decl.ml create mode 100644 camlp4/test/fixtures/unit.ml create mode 100644 camlp4/test/fixtures/use.ml create mode 100644 camlp4/test/fixtures/where.o.ml create mode 100644 camlp4/test/fixtures/where.r.ml create mode 100644 camlp4/unmaintained/Makefile create mode 100644 camlp4/unmaintained/compile/.cvsignore create mode 100644 camlp4/unmaintained/compile/.depend create mode 100644 camlp4/unmaintained/compile/Makefile create mode 100644 camlp4/unmaintained/compile/comp_head.ml create mode 100644 camlp4/unmaintained/compile/comp_trail.ml create mode 100644 camlp4/unmaintained/compile/compile.ml create mode 100755 camlp4/unmaintained/compile/compile.sh create mode 100644 camlp4/unmaintained/etc/.cvsignore create mode 100644 camlp4/unmaintained/etc/.depend create mode 100644 camlp4/unmaintained/etc/Makefile create mode 100644 camlp4/unmaintained/etc/pa_fstream.ml create mode 100644 camlp4/unmaintained/etc/pa_ifdef.ml create mode 100644 camlp4/unmaintained/etc/pa_oop.ml create mode 100644 camlp4/unmaintained/etc/pa_ru.ml create mode 100644 camlp4/unmaintained/etc/parserify.ml create mode 100644 camlp4/unmaintained/etc/parserify.mli create mode 100644 camlp4/unmaintained/etc/pr_depend.ml create mode 100644 camlp4/unmaintained/etc/pr_extend.ml create mode 100644 camlp4/unmaintained/etc/pr_extfun.ml create mode 100644 camlp4/unmaintained/etc/pr_null.ml create mode 100644 camlp4/unmaintained/etc/pr_op.ml create mode 100644 camlp4/unmaintained/etc/pr_op_main.ml create mode 100644 camlp4/unmaintained/etc/pr_rp.ml create mode 100644 camlp4/unmaintained/etc/pr_rp_main.ml create mode 100644 camlp4/unmaintained/etc/q_phony.ml create mode 100644 camlp4/unmaintained/extfold/README create mode 100644 camlp4/unmaintained/extfold/pa_extfold.ml create mode 100644 camlp4/unmaintained/format/.depend create mode 100644 camlp4/unmaintained/format/Makefile create mode 100644 camlp4/unmaintained/format/README create mode 100644 camlp4/unmaintained/format/pa_format.ml create mode 100644 camlp4/unmaintained/lefteval/.depend create mode 100644 camlp4/unmaintained/lefteval/Makefile create mode 100644 camlp4/unmaintained/lefteval/README create mode 100644 camlp4/unmaintained/lefteval/pa_lefteval.ml create mode 100644 camlp4/unmaintained/lib/.cvsignore create mode 100644 camlp4/unmaintained/lib/.depend create mode 100644 camlp4/unmaintained/lib/Makefile create mode 100644 camlp4/unmaintained/lib/extfun.ml create mode 100644 camlp4/unmaintained/lib/extfun.mli create mode 100644 camlp4/unmaintained/lib/fstream.ml create mode 100644 camlp4/unmaintained/lib/fstream.mli create mode 100644 camlp4/unmaintained/ocamllex/Makefile create mode 100644 camlp4/unmaintained/ocamllex/README create mode 100644 camlp4/unmaintained/ocamllex/pa_ocamllex.ml create mode 100644 camlp4/unmaintained/ocpp/.cvsignore create mode 100644 camlp4/unmaintained/ocpp/.depend create mode 100644 camlp4/unmaintained/ocpp/Makefile create mode 100644 camlp4/unmaintained/ocpp/ocpp.ml create mode 100644 camlp4/unmaintained/odyl/.cvsignore create mode 100644 camlp4/unmaintained/odyl/.depend create mode 100644 camlp4/unmaintained/odyl/Makefile create mode 100644 camlp4/unmaintained/odyl/odyl.ml create mode 100644 camlp4/unmaintained/odyl/odyl_main.mli create mode 100644 camlp4/unmaintained/olabl/.depend create mode 100644 camlp4/unmaintained/olabl/Makefile create mode 100644 camlp4/unmaintained/olabl/README create mode 100644 camlp4/unmaintained/olabl/pa_olabl.ml create mode 100644 camlp4/unmaintained/scheme/.depend create mode 100644 camlp4/unmaintained/scheme/Makefile create mode 100644 camlp4/unmaintained/scheme/README create mode 100644 camlp4/unmaintained/scheme/pa_scheme.ml create mode 100644 camlp4/unmaintained/scheme/pa_scheme.sc create mode 100644 camlp4/unmaintained/scheme/pr_scheme.ml create mode 100644 camlp4/unmaintained/scheme/pr_schp_main.ml create mode 100644 camlp4/unmaintained/sml/.depend create mode 100644 camlp4/unmaintained/sml/Makefile create mode 100644 camlp4/unmaintained/sml/README create mode 100644 camlp4/unmaintained/sml/pa_sml.ml create mode 100644 camlp4/unmaintained/sml/smllib.sml create mode 100644 config/.cvsignore create mode 100644 config/Makefile-templ create mode 100644 config/Makefile.mingw create mode 100644 config/Makefile.msvc create mode 100644 config/Makefile.msvc64 create mode 100644 config/auto-aux/.cvsignore create mode 100644 config/auto-aux/align.c create mode 100644 config/auto-aux/ansi.c create mode 100644 config/auto-aux/async_io.c create mode 100644 config/auto-aux/bytecopy.c create mode 100644 config/auto-aux/dblalign.c create mode 100644 config/auto-aux/divmod.c create mode 100644 config/auto-aux/elf.c create mode 100644 config/auto-aux/endian.c create mode 100644 config/auto-aux/getgroups.c create mode 100644 config/auto-aux/gethostbyaddr.c create mode 100644 config/auto-aux/gethostbyname.c create mode 100755 config/auto-aux/hasgot create mode 100644 config/auto-aux/ia32sse2.c create mode 100644 config/auto-aux/int64align.c create mode 100644 config/auto-aux/longlong.c create mode 100755 config/auto-aux/runtest create mode 100644 config/auto-aux/schar.c create mode 100644 config/auto-aux/schar2.c create mode 100755 config/auto-aux/searchpath create mode 100755 config/auto-aux/sharpbang create mode 100755 config/auto-aux/sharpbang2 create mode 100644 config/auto-aux/sighandler.c create mode 100644 config/auto-aux/signals.c create mode 100644 config/auto-aux/sizes.c create mode 100644 config/auto-aux/solaris-ld create mode 100644 config/auto-aux/stackov.c create mode 100644 config/auto-aux/tclversion.c create mode 100755 config/auto-aux/trycompile create mode 100755 config/gnu/config.guess create mode 100755 config/gnu/config.sub create mode 100644 config/m-nt.h create mode 100644 config/m-templ.h create mode 100644 config/s-nt.h create mode 100644 config/s-templ.h create mode 100755 configure create mode 100644 debugger/.cvsignore create mode 100644 debugger/.depend create mode 100644 debugger/Makefile create mode 100644 debugger/Makefile.nt create mode 100644 debugger/Makefile.shared create mode 100644 debugger/breakpoints.ml create mode 100644 debugger/breakpoints.mli create mode 100644 debugger/checkpoints.ml create mode 100644 debugger/checkpoints.mli create mode 100644 debugger/command_line.ml create mode 100644 debugger/command_line.mli create mode 100644 debugger/debugcom.ml create mode 100644 debugger/debugcom.mli create mode 100644 debugger/debugger_config.ml create mode 100644 debugger/debugger_config.mli create mode 100644 debugger/dynlink.ml create mode 100644 debugger/dynlink.mli create mode 100644 debugger/envaux.ml create mode 100644 debugger/envaux.mli create mode 100644 debugger/eval.ml create mode 100644 debugger/eval.mli create mode 100644 debugger/events.ml create mode 100644 debugger/events.mli create mode 100644 debugger/exec.ml create mode 100644 debugger/exec.mli create mode 100644 debugger/frames.ml create mode 100644 debugger/frames.mli create mode 100644 debugger/history.ml create mode 100644 debugger/history.mli create mode 100644 debugger/input_handling.ml create mode 100644 debugger/input_handling.mli create mode 100644 debugger/int64ops.ml create mode 100644 debugger/int64ops.mli create mode 100644 debugger/lexer.mli create mode 100644 debugger/lexer.mll create mode 100644 debugger/loadprinter.ml create mode 100644 debugger/loadprinter.mli create mode 100644 debugger/main.ml create mode 100644 debugger/parameters.ml create mode 100644 debugger/parameters.mli create mode 100644 debugger/parser.mly create mode 100644 debugger/parser_aux.mli create mode 100644 debugger/pattern_matching.ml create mode 100644 debugger/pattern_matching.mli create mode 100644 debugger/pos.ml create mode 100644 debugger/pos.mli create mode 100644 debugger/primitives.ml create mode 100644 debugger/primitives.mli create mode 100644 debugger/printval.ml create mode 100644 debugger/printval.mli create mode 100644 debugger/program_loading.ml create mode 100644 debugger/program_loading.mli create mode 100644 debugger/program_management.ml create mode 100644 debugger/program_management.mli create mode 100644 debugger/question.ml create mode 100644 debugger/question.mli create mode 100644 debugger/show_information.ml create mode 100644 debugger/show_information.mli create mode 100644 debugger/show_source.ml create mode 100644 debugger/show_source.mli create mode 100644 debugger/source.ml create mode 100644 debugger/source.mli create mode 100644 debugger/symbols.ml create mode 100644 debugger/symbols.mli create mode 100644 debugger/time_travel.ml create mode 100644 debugger/time_travel.mli create mode 100644 debugger/trap_barrier.ml create mode 100644 debugger/trap_barrier.mli create mode 100644 debugger/unix_tools.ml create mode 100644 debugger/unix_tools.mli create mode 100644 driver/compile.ml create mode 100644 driver/compile.mli create mode 100644 driver/errors.ml create mode 100644 driver/errors.mli create mode 100644 driver/main.ml create mode 100644 driver/main.mli create mode 100644 driver/main_args.ml create mode 100644 driver/main_args.mli create mode 100644 driver/ocamlcomp.sh.in create mode 100644 driver/optcompile.ml create mode 100644 driver/optcompile.mli create mode 100644 driver/opterrors.ml create mode 100644 driver/opterrors.mli create mode 100644 driver/optmain.ml create mode 100644 driver/optmain.mli create mode 100644 driver/pparse.ml create mode 100644 driver/pparse.mli create mode 100644 emacs/.cvsignore create mode 100644 emacs/COPYING create mode 100644 emacs/Makefile create mode 100644 emacs/README create mode 100644 emacs/README.itz create mode 100644 emacs/caml-compat.el create mode 100644 emacs/caml-emacs.el create mode 100644 emacs/caml-font-old.el create mode 100644 emacs/caml-font.el create mode 100644 emacs/caml-help.el create mode 100644 emacs/caml-hilit.el create mode 100644 emacs/caml-types.el create mode 100644 emacs/caml-xemacs.el create mode 100644 emacs/caml.el create mode 100644 emacs/camldebug.el create mode 100644 emacs/inf-caml.el create mode 100644 emacs/ocamltags.in create mode 100644 lex/.cvsignore create mode 100644 lex/.depend create mode 100644 lex/Makefile create mode 100644 lex/Makefile.nt create mode 100644 lex/common.ml create mode 100644 lex/common.mli create mode 100644 lex/compact.ml create mode 100644 lex/compact.mli create mode 100644 lex/cset.ml create mode 100644 lex/cset.mli create mode 100644 lex/lexer.mli create mode 100644 lex/lexer.mll create mode 100644 lex/lexgen.ml create mode 100644 lex/lexgen.mli create mode 100644 lex/main.ml create mode 100644 lex/output.ml create mode 100644 lex/output.mli create mode 100644 lex/outputbis.ml create mode 100644 lex/outputbis.mli create mode 100644 lex/parser.mly create mode 100644 lex/syntax.ml create mode 100644 lex/syntax.mli create mode 100644 lex/table.ml create mode 100644 lex/table.mli create mode 100644 man/Makefile create mode 100644 man/ocaml.help create mode 100644 man/ocaml.m create mode 100644 man/ocamlc.m create mode 100644 man/ocamlcp.m create mode 100644 man/ocamldebug.m create mode 100644 man/ocamldep.m create mode 100644 man/ocamldoc.m create mode 100644 man/ocamllex.m create mode 100644 man/ocamlmktop.m create mode 100644 man/ocamlopt.m create mode 100644 man/ocamlprof.m create mode 100644 man/ocamlrun.m create mode 100644 man/ocamlyacc.m create mode 100644 myocamlbuild.ml create mode 100644 myocamlbuild_config.mli create mode 100644 ocamlbuild/AUTHORS create mode 100644 ocamlbuild/ChangeLog create mode 100644 ocamlbuild/FAQ create mode 100644 ocamlbuild/Makefile create mode 100644 ocamlbuild/TODO create mode 100644 ocamlbuild/_tags create mode 100644 ocamlbuild/bool.ml create mode 100644 ocamlbuild/bool.mli create mode 100644 ocamlbuild/command.ml create mode 100644 ocamlbuild/command.mli create mode 100644 ocamlbuild/configuration.ml create mode 100644 ocamlbuild/configuration.mli create mode 100644 ocamlbuild/digest_cache.ml create mode 100644 ocamlbuild/digest_cache.mli create mode 100644 ocamlbuild/discard_printf.ml create mode 100644 ocamlbuild/discard_printf.mli create mode 100644 ocamlbuild/display.ml create mode 100644 ocamlbuild/display.mli create mode 100644 ocamlbuild/examples/example1/hello.ml create mode 100644 ocamlbuild/examples/example2/greet.ml create mode 100644 ocamlbuild/examples/example2/hello.ml create mode 100644 ocamlbuild/examples/example3/epoch.ml create mode 100755 ocamlbuild/examples/example3/make.sh create mode 100644 ocamlbuild/exit_codes.ml create mode 100644 ocamlbuild/exit_codes.mli create mode 100644 ocamlbuild/fda.ml create mode 100644 ocamlbuild/fda.mli create mode 100644 ocamlbuild/flags.ml create mode 100644 ocamlbuild/flags.mli create mode 100644 ocamlbuild/glob.ml create mode 100644 ocamlbuild/glob.mli create mode 100644 ocamlbuild/glob_ast.ml create mode 100644 ocamlbuild/glob_ast.mli create mode 100644 ocamlbuild/glob_lexer.mli create mode 100644 ocamlbuild/glob_lexer.mll create mode 100644 ocamlbuild/hooks.ml create mode 100644 ocamlbuild/hooks.mli create mode 100644 ocamlbuild/hygiene.ml create mode 100644 ocamlbuild/hygiene.mli create mode 100644 ocamlbuild/lexers.mli create mode 100644 ocamlbuild/lexers.mll create mode 100644 ocamlbuild/log.ml create mode 100644 ocamlbuild/log.mli create mode 100644 ocamlbuild/main.ml create mode 100644 ocamlbuild/main.mli create mode 100644 ocamlbuild/man/ocamlbuild.1 create mode 100644 ocamlbuild/manual/.cvsignore create mode 100644 ocamlbuild/manual/Makefile create mode 100644 ocamlbuild/manual/manual.hva create mode 100644 ocamlbuild/manual/manual.tex create mode 100644 ocamlbuild/manual/myocamlbuild.ml create mode 100644 ocamlbuild/manual/trace.out create mode 100644 ocamlbuild/misc/opentracer.ml create mode 100644 ocamlbuild/my_std.ml create mode 100644 ocamlbuild/my_std.mli create mode 100644 ocamlbuild/my_unix.ml create mode 100644 ocamlbuild/my_unix.mli create mode 100644 ocamlbuild/ocaml_arch.ml create mode 100644 ocamlbuild/ocaml_arch.mli create mode 100644 ocamlbuild/ocaml_compiler.ml create mode 100644 ocamlbuild/ocaml_compiler.mli create mode 100644 ocamlbuild/ocaml_dependencies.ml create mode 100644 ocamlbuild/ocaml_dependencies.mli create mode 100644 ocamlbuild/ocaml_specific.ml create mode 100644 ocamlbuild/ocaml_specific.mli create mode 100644 ocamlbuild/ocaml_tools.ml create mode 100644 ocamlbuild/ocaml_tools.mli create mode 100644 ocamlbuild/ocaml_utils.ml create mode 100644 ocamlbuild/ocaml_utils.mli create mode 100644 ocamlbuild/ocamlbuild-presentation.rslide create mode 100644 ocamlbuild/ocamlbuild.ml create mode 100644 ocamlbuild/ocamlbuild.mli create mode 100644 ocamlbuild/ocamlbuild.mltop create mode 100644 ocamlbuild/ocamlbuild.odocl create mode 100644 ocamlbuild/ocamlbuild_executor.ml create mode 100644 ocamlbuild/ocamlbuild_executor.mli create mode 100644 ocamlbuild/ocamlbuild_pack.mlpack create mode 100644 ocamlbuild/ocamlbuild_plugin.ml create mode 100644 ocamlbuild/ocamlbuild_plugin.mli create mode 100644 ocamlbuild/ocamlbuild_unix_plugin.ml create mode 100644 ocamlbuild/ocamlbuild_unix_plugin.mli create mode 100644 ocamlbuild/ocamlbuild_where.mli create mode 100644 ocamlbuild/ocamlbuildlib.mllib create mode 100644 ocamlbuild/ocamlbuildlight.ml create mode 100644 ocamlbuild/ocamlbuildlight.mli create mode 100644 ocamlbuild/ocamlbuildlightlib.mllib create mode 100644 ocamlbuild/options.ml create mode 100644 ocamlbuild/options.mli create mode 100644 ocamlbuild/pathname.ml create mode 100644 ocamlbuild/pathname.mli create mode 100644 ocamlbuild/plugin.ml create mode 100644 ocamlbuild/plugin.mli create mode 100644 ocamlbuild/ppcache.ml create mode 100644 ocamlbuild/ppcache.mli create mode 100644 ocamlbuild/report.ml create mode 100644 ocamlbuild/report.mli create mode 100644 ocamlbuild/resource.ml create mode 100644 ocamlbuild/resource.mli create mode 100644 ocamlbuild/rule.ml create mode 100644 ocamlbuild/rule.mli create mode 100644 ocamlbuild/shell.ml create mode 100644 ocamlbuild/shell.mli create mode 100644 ocamlbuild/signatures.mli create mode 100644 ocamlbuild/slurp.ml create mode 100644 ocamlbuild/slurp.mli create mode 100644 ocamlbuild/solver.ml create mode 100644 ocamlbuild/solver.mli create mode 100755 ocamlbuild/start.sh create mode 100644 ocamlbuild/std_signatures.mli create mode 100644 ocamlbuild/tags.ml create mode 100644 ocamlbuild/tags.mli create mode 100644 ocamlbuild/test/good-output create mode 100755 ocamlbuild/test/runtest.sh create mode 100644 ocamlbuild/test/test1/foo.ml create mode 100644 ocamlbuild/test/test10/dbdi create mode 100755 ocamlbuild/test/test10/test.sh create mode 100644 ocamlbuild/test/test11/_tags create mode 100644 ocamlbuild/test/test11/a/aa.ml create mode 100644 ocamlbuild/test/test11/a/aa.mli create mode 100644 ocamlbuild/test/test11/b/bb.ml create mode 100644 ocamlbuild/test/test11/b/libb.mllib create mode 100644 ocamlbuild/test/test11/myocamlbuild.ml create mode 100755 ocamlbuild/test/test11/test.sh create mode 100644 ocamlbuild/test/test2/_tags create mode 100644 ocamlbuild/test/test2/tata.ml create mode 100644 ocamlbuild/test/test2/tata.mli create mode 100755 ocamlbuild/test/test2/test.sh create mode 100644 ocamlbuild/test/test2/titi.ml create mode 100644 ocamlbuild/test/test2/toto.ml create mode 100644 ocamlbuild/test/test2/tutu.ml create mode 100644 ocamlbuild/test/test2/tutu.mli create mode 100644 ocamlbuild/test/test2/tyty.mli create mode 100644 ocamlbuild/test/test2/vivi1.ml create mode 100644 ocamlbuild/test/test2/vivi2.ml create mode 100644 ocamlbuild/test/test2/vivi3.ml create mode 100644 ocamlbuild/test/test3/_tags create mode 100644 ocamlbuild/test/test3/a.ml create mode 100644 ocamlbuild/test/test3/a.mli create mode 100644 ocamlbuild/test/test3/b.ml create mode 100644 ocamlbuild/test/test3/b.mli create mode 100644 ocamlbuild/test/test3/c.ml create mode 100644 ocamlbuild/test/test3/c.mli create mode 100644 ocamlbuild/test/test3/d.ml create mode 100644 ocamlbuild/test/test3/d.mli create mode 100644 ocamlbuild/test/test3/e.ml create mode 100644 ocamlbuild/test/test3/e.mli create mode 100644 ocamlbuild/test/test3/f.ml create mode 100644 ocamlbuild/test/test3/f.mli create mode 100644 ocamlbuild/test/test3/proj.odocl create mode 100755 ocamlbuild/test/test3/test.sh create mode 100644 ocamlbuild/test/test4/_tags create mode 100644 ocamlbuild/test/test4/a/aa.ml create mode 100644 ocamlbuild/test/test4/a/aa.mli create mode 100644 ocamlbuild/test/test4/b/bb.ml create mode 100755 ocamlbuild/test/test4/test.sh create mode 100644 ocamlbuild/test/test5/_tags create mode 100644 ocamlbuild/test/test5/a.ml create mode 100644 ocamlbuild/test/test5/a.mli create mode 100644 ocamlbuild/test/test5/b.ml create mode 100644 ocamlbuild/test/test5/c.mlpack create mode 100644 ocamlbuild/test/test5/d.ml create mode 100644 ocamlbuild/test/test5/stack.ml create mode 100755 ocamlbuild/test/test5/test.sh create mode 100644 ocamlbuild/test/test6/a.ml create mode 100644 ocamlbuild/test/test6/a.mli create mode 100644 ocamlbuild/test/test6/b.ml create mode 100644 ocamlbuild/test/test6/b.mli create mode 100644 ocamlbuild/test/test6/b.mli.v1 create mode 100644 ocamlbuild/test/test6/b.mli.v2 create mode 100644 ocamlbuild/test/test6/d.ml create mode 100644 ocamlbuild/test/test6/d.mli create mode 100644 ocamlbuild/test/test6/d.mli.v1 create mode 100644 ocamlbuild/test/test6/d.mli.v2 create mode 100644 ocamlbuild/test/test6/main.ml create mode 100644 ocamlbuild/test/test6/main.mli create mode 100755 ocamlbuild/test/test6/test.sh create mode 100644 ocamlbuild/test/test7/_tags create mode 100644 ocamlbuild/test/test7/aa.ml create mode 100644 ocamlbuild/test/test7/bb.mli create mode 100644 ocamlbuild/test/test7/bb1.ml create mode 100644 ocamlbuild/test/test7/bb2.ml create mode 100644 ocamlbuild/test/test7/bb3.ml create mode 100644 ocamlbuild/test/test7/bbcc.mllib create mode 100644 ocamlbuild/test/test7/c2.ml create mode 100644 ocamlbuild/test/test7/c2.mli create mode 100644 ocamlbuild/test/test7/c3.ml create mode 100644 ocamlbuild/test/test7/cc.ml create mode 100644 ocamlbuild/test/test7/cool_plugin.ml create mode 100644 ocamlbuild/test/test7/main.ml create mode 100644 ocamlbuild/test/test7/myocamlbuild.ml create mode 100755 ocamlbuild/test/test7/test.sh create mode 100644 ocamlbuild/test/test8/a.ml create mode 100644 ocamlbuild/test/test8/myocamlbuild.ml create mode 100755 ocamlbuild/test/test8/test.sh create mode 100644 ocamlbuild/test/test9/dbgl create mode 100755 ocamlbuild/test/test9/test.sh create mode 100644 ocamlbuild/test/test9/testglob.ml create mode 100644 ocamlbuild/test/test_virtual/foo.itarget create mode 100644 ocamlbuild/test/test_virtual/foo1 create mode 100644 ocamlbuild/test/test_virtual/foo2 create mode 100644 ocamlbuild/test/test_virtual/myocamlbuild.ml create mode 100644 ocamlbuild/test/test_virtual/test.sh create mode 100644 ocamlbuild/tools.ml create mode 100644 ocamlbuild/tools.mli create mode 100644 ocamldoc/.cvsignore create mode 100644 ocamldoc/.depend create mode 100644 ocamldoc/Changes.txt create mode 100644 ocamldoc/Makefile create mode 100644 ocamldoc/Makefile.nt create mode 100644 ocamldoc/ocamldoc.hva create mode 100644 ocamldoc/ocamldoc.sty create mode 100644 ocamldoc/odoc.ml create mode 100644 ocamldoc/odoc_analyse.ml create mode 100644 ocamldoc/odoc_analyse.mli create mode 100644 ocamldoc/odoc_args.ml create mode 100644 ocamldoc/odoc_args.mli create mode 100644 ocamldoc/odoc_ast.ml create mode 100644 ocamldoc/odoc_ast.mli create mode 100644 ocamldoc/odoc_class.ml create mode 100644 ocamldoc/odoc_comments.ml create mode 100644 ocamldoc/odoc_comments.mli create mode 100644 ocamldoc/odoc_comments_global.ml create mode 100644 ocamldoc/odoc_comments_global.mli create mode 100644 ocamldoc/odoc_config.ml create mode 100644 ocamldoc/odoc_config.mli create mode 100644 ocamldoc/odoc_control.ml create mode 100644 ocamldoc/odoc_cross.ml create mode 100644 ocamldoc/odoc_cross.mli create mode 100644 ocamldoc/odoc_dag2html.ml create mode 100644 ocamldoc/odoc_dag2html.mli create mode 100644 ocamldoc/odoc_dep.ml create mode 100644 ocamldoc/odoc_dot.ml create mode 100644 ocamldoc/odoc_env.ml create mode 100644 ocamldoc/odoc_env.mli create mode 100644 ocamldoc/odoc_exception.ml create mode 100644 ocamldoc/odoc_global.ml create mode 100644 ocamldoc/odoc_global.mli create mode 100644 ocamldoc/odoc_html.ml create mode 100644 ocamldoc/odoc_info.ml create mode 100644 ocamldoc/odoc_info.mli create mode 100644 ocamldoc/odoc_inherit.ml create mode 100644 ocamldoc/odoc_latex.ml create mode 100644 ocamldoc/odoc_latex_style.ml create mode 100644 ocamldoc/odoc_lexer.mll create mode 100644 ocamldoc/odoc_man.ml create mode 100644 ocamldoc/odoc_merge.ml create mode 100644 ocamldoc/odoc_merge.mli create mode 100644 ocamldoc/odoc_messages.ml create mode 100644 ocamldoc/odoc_misc.ml create mode 100644 ocamldoc/odoc_misc.mli create mode 100644 ocamldoc/odoc_module.ml create mode 100644 ocamldoc/odoc_name.ml create mode 100644 ocamldoc/odoc_name.mli create mode 100644 ocamldoc/odoc_ocamlhtml.mll create mode 100644 ocamldoc/odoc_opt.ml create mode 100644 ocamldoc/odoc_parameter.ml create mode 100644 ocamldoc/odoc_parser.mly create mode 100644 ocamldoc/odoc_print.ml create mode 100644 ocamldoc/odoc_print.mli create mode 100644 ocamldoc/odoc_scan.ml create mode 100644 ocamldoc/odoc_search.ml create mode 100644 ocamldoc/odoc_search.mli create mode 100644 ocamldoc/odoc_see_lexer.mll create mode 100644 ocamldoc/odoc_sig.ml create mode 100644 ocamldoc/odoc_sig.mli create mode 100644 ocamldoc/odoc_str.ml create mode 100644 ocamldoc/odoc_str.mli create mode 100644 ocamldoc/odoc_test.ml create mode 100644 ocamldoc/odoc_texi.ml create mode 100644 ocamldoc/odoc_text.ml create mode 100644 ocamldoc/odoc_text.mli create mode 100644 ocamldoc/odoc_text_lexer.mll create mode 100644 ocamldoc/odoc_text_parser.mly create mode 100644 ocamldoc/odoc_to_text.ml create mode 100644 ocamldoc/odoc_type.ml create mode 100644 ocamldoc/odoc_types.ml create mode 100644 ocamldoc/odoc_types.mli create mode 100644 ocamldoc/odoc_value.ml create mode 100755 ocamldoc/remove_DEBUG create mode 100644 ocamldoc/runocamldoc create mode 100644 otherlibs/Makefile create mode 100644 otherlibs/Makefile.nt create mode 100644 otherlibs/Makefile.shared create mode 100644 otherlibs/bigarray/.cvsignore create mode 100644 otherlibs/bigarray/.depend create mode 100644 otherlibs/bigarray/Makefile create mode 100644 otherlibs/bigarray/Makefile.nt create mode 100644 otherlibs/bigarray/bigarray.h create mode 100644 otherlibs/bigarray/bigarray.ml create mode 100644 otherlibs/bigarray/bigarray.mli create mode 100644 otherlibs/bigarray/bigarray_stubs.c create mode 100644 otherlibs/bigarray/dllbigarray.dlib create mode 100644 otherlibs/bigarray/libbigarray.clib create mode 100644 otherlibs/bigarray/libbigarraywin32.clib create mode 100644 otherlibs/bigarray/mmap_unix.c create mode 100644 otherlibs/bigarray/mmap_win32.c create mode 100644 otherlibs/db/.depend create mode 100644 otherlibs/dbm/.cvsignore create mode 100644 otherlibs/dbm/.depend create mode 100644 otherlibs/dbm/Makefile create mode 100644 otherlibs/dbm/cldbm.c create mode 100644 otherlibs/dbm/dbm.ml create mode 100644 otherlibs/dbm/dbm.mli create mode 100644 otherlibs/dbm/libmldbm.clib create mode 100644 otherlibs/dynlink/.cvsignore create mode 100644 otherlibs/dynlink/Makefile create mode 100644 otherlibs/dynlink/Makefile.nt create mode 100644 otherlibs/dynlink/dynlink.ml create mode 100644 otherlibs/dynlink/dynlink.mli create mode 100644 otherlibs/dynlink/dynlinkaux.mlpack create mode 100644 otherlibs/dynlink/extract_crc.ml create mode 100644 otherlibs/dynlink/natdynlink.ml create mode 100644 otherlibs/graph/.cvsignore create mode 100644 otherlibs/graph/.depend create mode 100644 otherlibs/graph/Makefile create mode 100644 otherlibs/graph/color.c create mode 100644 otherlibs/graph/draw.c create mode 100644 otherlibs/graph/dump_img.c create mode 100644 otherlibs/graph/events.c create mode 100644 otherlibs/graph/fill.c create mode 100644 otherlibs/graph/graphics.ml create mode 100644 otherlibs/graph/graphics.mli create mode 100644 otherlibs/graph/graphics.mllib create mode 100644 otherlibs/graph/graphicsX11.ml create mode 100644 otherlibs/graph/graphicsX11.mli create mode 100644 otherlibs/graph/image.c create mode 100644 otherlibs/graph/image.h create mode 100644 otherlibs/graph/libgraph.h create mode 100644 otherlibs/graph/libgraphics.clib create mode 100644 otherlibs/graph/make_img.c create mode 100644 otherlibs/graph/open.c create mode 100644 otherlibs/graph/point_col.c create mode 100644 otherlibs/graph/sound.c create mode 100644 otherlibs/graph/subwindow.c create mode 100644 otherlibs/graph/text.c create mode 100644 otherlibs/labltk/.cvsignore create mode 100644 otherlibs/labltk/Changes create mode 100644 otherlibs/labltk/Makefile create mode 100644 otherlibs/labltk/Makefile.nt create mode 100644 otherlibs/labltk/README create mode 100644 otherlibs/labltk/Widgets.src create mode 100644 otherlibs/labltk/browser/.cvsignore create mode 100644 otherlibs/labltk/browser/.depend create mode 100644 otherlibs/labltk/browser/Makefile create mode 100644 otherlibs/labltk/browser/Makefile.nt create mode 100644 otherlibs/labltk/browser/Makefile.shared create mode 100644 otherlibs/labltk/browser/README create mode 100644 otherlibs/labltk/browser/dummyUnix.mli create mode 100644 otherlibs/labltk/browser/dummyWin.mli create mode 100644 otherlibs/labltk/browser/editor.ml create mode 100644 otherlibs/labltk/browser/editor.mli create mode 100644 otherlibs/labltk/browser/fileselect.ml create mode 100644 otherlibs/labltk/browser/fileselect.mli create mode 100644 otherlibs/labltk/browser/help.ml create mode 100644 otherlibs/labltk/browser/help.txt create mode 100644 otherlibs/labltk/browser/jg_bind.ml create mode 100644 otherlibs/labltk/browser/jg_bind.mli create mode 100644 otherlibs/labltk/browser/jg_box.ml create mode 100644 otherlibs/labltk/browser/jg_button.ml create mode 100644 otherlibs/labltk/browser/jg_completion.ml create mode 100644 otherlibs/labltk/browser/jg_completion.mli create mode 100644 otherlibs/labltk/browser/jg_config.ml create mode 100644 otherlibs/labltk/browser/jg_config.mli create mode 100644 otherlibs/labltk/browser/jg_entry.ml create mode 100644 otherlibs/labltk/browser/jg_memo.ml create mode 100644 otherlibs/labltk/browser/jg_memo.mli create mode 100644 otherlibs/labltk/browser/jg_menu.ml create mode 100644 otherlibs/labltk/browser/jg_message.ml create mode 100644 otherlibs/labltk/browser/jg_message.mli create mode 100644 otherlibs/labltk/browser/jg_multibox.ml create mode 100644 otherlibs/labltk/browser/jg_multibox.mli create mode 100644 otherlibs/labltk/browser/jg_text.ml create mode 100644 otherlibs/labltk/browser/jg_text.mli create mode 100644 otherlibs/labltk/browser/jg_tk.ml create mode 100644 otherlibs/labltk/browser/jg_toplevel.ml create mode 100644 otherlibs/labltk/browser/jglib.mllib create mode 100644 otherlibs/labltk/browser/lexical.ml create mode 100644 otherlibs/labltk/browser/lexical.mli create mode 100644 otherlibs/labltk/browser/list2.ml create mode 100644 otherlibs/labltk/browser/main.ml create mode 100644 otherlibs/labltk/browser/mytypes.mli create mode 100644 otherlibs/labltk/browser/searchid.ml create mode 100644 otherlibs/labltk/browser/searchid.mli create mode 100644 otherlibs/labltk/browser/searchpos.ml create mode 100644 otherlibs/labltk/browser/searchpos.mli create mode 100644 otherlibs/labltk/browser/setpath.ml create mode 100644 otherlibs/labltk/browser/setpath.mli create mode 100644 otherlibs/labltk/browser/shell.ml create mode 100644 otherlibs/labltk/browser/shell.mli create mode 100644 otherlibs/labltk/browser/typecheck.ml create mode 100644 otherlibs/labltk/browser/typecheck.mli create mode 100644 otherlibs/labltk/browser/useunix.ml create mode 100644 otherlibs/labltk/browser/useunix.mli create mode 100644 otherlibs/labltk/browser/viewer.ml create mode 100644 otherlibs/labltk/browser/viewer.mli create mode 100644 otherlibs/labltk/browser/winmain.c create mode 100644 otherlibs/labltk/builtin/LICENSE create mode 100644 otherlibs/labltk/builtin/builtin_FilePattern.ml create mode 100644 otherlibs/labltk/builtin/builtin_GetBitmap.ml create mode 100644 otherlibs/labltk/builtin/builtin_GetCursor.ml create mode 100644 otherlibs/labltk/builtin/builtin_GetPixel.ml create mode 100644 otherlibs/labltk/builtin/builtin_ScrollValue.ml create mode 100644 otherlibs/labltk/builtin/builtin_bind.ml create mode 100644 otherlibs/labltk/builtin/builtin_bindtags.ml create mode 100644 otherlibs/labltk/builtin/builtin_font.ml create mode 100644 otherlibs/labltk/builtin/builtin_grab.ml create mode 100644 otherlibs/labltk/builtin/builtin_index.ml create mode 100644 otherlibs/labltk/builtin/builtin_palette.ml create mode 100644 otherlibs/labltk/builtin/builtin_text.ml create mode 100644 otherlibs/labltk/builtin/builtina_empty.ml create mode 100644 otherlibs/labltk/builtin/builtinf_GetPixel.ml create mode 100644 otherlibs/labltk/builtin/builtinf_bind.ml create mode 100644 otherlibs/labltk/builtin/builtini_GetBitmap.ml create mode 100644 otherlibs/labltk/builtin/builtini_GetCursor.ml create mode 100644 otherlibs/labltk/builtin/builtini_GetPixel.ml create mode 100644 otherlibs/labltk/builtin/builtini_ScrollValue.ml create mode 100644 otherlibs/labltk/builtin/builtini_bind.ml create mode 100644 otherlibs/labltk/builtin/builtini_bindtags.ml create mode 100644 otherlibs/labltk/builtin/builtini_font.ml create mode 100644 otherlibs/labltk/builtin/builtini_grab.ml create mode 100644 otherlibs/labltk/builtin/builtini_index.ml create mode 100644 otherlibs/labltk/builtin/builtini_palette.ml create mode 100644 otherlibs/labltk/builtin/builtini_text.ml create mode 100644 otherlibs/labltk/builtin/canvas_bind.ml create mode 100644 otherlibs/labltk/builtin/canvas_bind.mli create mode 100644 otherlibs/labltk/builtin/dialog.ml create mode 100644 otherlibs/labltk/builtin/dialog.mli create mode 100644 otherlibs/labltk/builtin/image.ml create mode 100644 otherlibs/labltk/builtin/image.mli create mode 100644 otherlibs/labltk/builtin/optionmenu.ml create mode 100644 otherlibs/labltk/builtin/optionmenu.mli create mode 100644 otherlibs/labltk/builtin/rawimg.ml create mode 100644 otherlibs/labltk/builtin/rawimg.mli create mode 100644 otherlibs/labltk/builtin/report.ml create mode 100644 otherlibs/labltk/builtin/selection_handle_set.ml create mode 100644 otherlibs/labltk/builtin/selection_handle_set.mli create mode 100644 otherlibs/labltk/builtin/selection_own_set.ml create mode 100644 otherlibs/labltk/builtin/selection_own_set.mli create mode 100644 otherlibs/labltk/builtin/text_tag_bind.ml create mode 100644 otherlibs/labltk/builtin/text_tag_bind.mli create mode 100644 otherlibs/labltk/builtin/winfo_contained.ml create mode 100644 otherlibs/labltk/builtin/winfo_contained.mli create mode 100644 otherlibs/labltk/camltk/.cvsignore create mode 100644 otherlibs/labltk/camltk/Makefile create mode 100644 otherlibs/labltk/camltk/Makefile.gen create mode 100644 otherlibs/labltk/camltk/Makefile.gen.nt create mode 100644 otherlibs/labltk/camltk/Makefile.nt create mode 100644 otherlibs/labltk/camltk/byte.itarget create mode 100644 otherlibs/labltk/camltk/modules create mode 100644 otherlibs/labltk/camltk/native.itarget create mode 100644 otherlibs/labltk/compiler/.cvsignore create mode 100644 otherlibs/labltk/compiler/.depend create mode 100644 otherlibs/labltk/compiler/Makefile create mode 100644 otherlibs/labltk/compiler/Makefile.nt create mode 100644 otherlibs/labltk/compiler/code.mli create mode 100644 otherlibs/labltk/compiler/compile.ml create mode 100644 otherlibs/labltk/compiler/copyright create mode 100644 otherlibs/labltk/compiler/flags.ml create mode 100644 otherlibs/labltk/compiler/intf.ml create mode 100644 otherlibs/labltk/compiler/lexer.mll create mode 100644 otherlibs/labltk/compiler/maincompile.ml create mode 100644 otherlibs/labltk/compiler/parser.mly create mode 100644 otherlibs/labltk/compiler/pp.ml create mode 100644 otherlibs/labltk/compiler/ppexec.ml create mode 100644 otherlibs/labltk/compiler/pplex.mli create mode 100644 otherlibs/labltk/compiler/pplex.mll create mode 100644 otherlibs/labltk/compiler/ppparse.ml create mode 100644 otherlibs/labltk/compiler/ppyac.mly create mode 100644 otherlibs/labltk/compiler/printer.ml create mode 100644 otherlibs/labltk/compiler/tables.ml create mode 100644 otherlibs/labltk/compiler/tsort.ml create mode 100644 otherlibs/labltk/examples_camltk/.cvsignore create mode 100644 otherlibs/labltk/examples_camltk/Makefile create mode 100644 otherlibs/labltk/examples_camltk/Makefile.nt create mode 100644 otherlibs/labltk/examples_camltk/addition.ml create mode 100644 otherlibs/labltk/examples_camltk/eyes.ml create mode 100644 otherlibs/labltk/examples_camltk/fileinput.ml create mode 100644 otherlibs/labltk/examples_camltk/fileopen.ml create mode 100644 otherlibs/labltk/examples_camltk/helloworld.ml create mode 100644 otherlibs/labltk/examples_camltk/images/CamlBook.gif create mode 100644 otherlibs/labltk/examples_camltk/images/Lambda2.back.gif create mode 100644 otherlibs/labltk/examples_camltk/images/dojoji.back.gif create mode 100644 otherlibs/labltk/examples_camltk/jptest.ml create mode 100644 otherlibs/labltk/examples_camltk/mytext.ml create mode 100644 otherlibs/labltk/examples_camltk/socketinput.ml create mode 100644 otherlibs/labltk/examples_camltk/taddition.ml create mode 100644 otherlibs/labltk/examples_camltk/tetris.ml create mode 100644 otherlibs/labltk/examples_camltk/text.ml create mode 100644 otherlibs/labltk/examples_camltk/winskel.ml create mode 100644 otherlibs/labltk/examples_labltk/.cvsignore create mode 100644 otherlibs/labltk/examples_labltk/Lambda2.back.gif create mode 100644 otherlibs/labltk/examples_labltk/Makefile create mode 100644 otherlibs/labltk/examples_labltk/Makefile.nt create mode 100644 otherlibs/labltk/examples_labltk/README create mode 100644 otherlibs/labltk/examples_labltk/calc.ml create mode 100644 otherlibs/labltk/examples_labltk/clock.ml create mode 100644 otherlibs/labltk/examples_labltk/demo.ml create mode 100644 otherlibs/labltk/examples_labltk/eyes.ml create mode 100644 otherlibs/labltk/examples_labltk/hello.ml create mode 100755 otherlibs/labltk/examples_labltk/hello.tcl create mode 100644 otherlibs/labltk/examples_labltk/lang.ml create mode 100644 otherlibs/labltk/examples_labltk/taquin.ml create mode 100644 otherlibs/labltk/examples_labltk/tetris.ml create mode 100644 otherlibs/labltk/frx/.depend create mode 100644 otherlibs/labltk/frx/Makefile create mode 100644 otherlibs/labltk/frx/Makefile.nt create mode 100644 otherlibs/labltk/frx/README create mode 100644 otherlibs/labltk/frx/frx_after.ml create mode 100644 otherlibs/labltk/frx/frx_after.mli create mode 100644 otherlibs/labltk/frx/frx_color.ml create mode 100644 otherlibs/labltk/frx/frx_color.mli create mode 100644 otherlibs/labltk/frx/frx_ctext.ml create mode 100644 otherlibs/labltk/frx/frx_ctext.mli create mode 100644 otherlibs/labltk/frx/frx_dialog.ml create mode 100644 otherlibs/labltk/frx/frx_dialog.mli create mode 100644 otherlibs/labltk/frx/frx_entry.ml create mode 100644 otherlibs/labltk/frx/frx_entry.mli create mode 100644 otherlibs/labltk/frx/frx_fileinput.ml create mode 100644 otherlibs/labltk/frx/frx_fillbox.ml create mode 100644 otherlibs/labltk/frx/frx_fillbox.mli create mode 100644 otherlibs/labltk/frx/frx_fit.ml create mode 100644 otherlibs/labltk/frx/frx_fit.mli create mode 100644 otherlibs/labltk/frx/frx_focus.ml create mode 100644 otherlibs/labltk/frx/frx_focus.mli create mode 100644 otherlibs/labltk/frx/frx_font.ml create mode 100644 otherlibs/labltk/frx/frx_font.mli create mode 100644 otherlibs/labltk/frx/frx_group.ml create mode 100644 otherlibs/labltk/frx/frx_lbutton.ml create mode 100644 otherlibs/labltk/frx/frx_lbutton.mli create mode 100644 otherlibs/labltk/frx/frx_listbox.ml create mode 100644 otherlibs/labltk/frx/frx_listbox.mli create mode 100644 otherlibs/labltk/frx/frx_mem.ml create mode 100644 otherlibs/labltk/frx/frx_mem.mli create mode 100644 otherlibs/labltk/frx/frx_misc.ml create mode 100644 otherlibs/labltk/frx/frx_misc.mli create mode 100644 otherlibs/labltk/frx/frx_req.ml create mode 100644 otherlibs/labltk/frx/frx_req.mli create mode 100644 otherlibs/labltk/frx/frx_rpc.ml create mode 100644 otherlibs/labltk/frx/frx_rpc.mli create mode 100644 otherlibs/labltk/frx/frx_selection.ml create mode 100644 otherlibs/labltk/frx/frx_selection.mli create mode 100644 otherlibs/labltk/frx/frx_synth.ml create mode 100644 otherlibs/labltk/frx/frx_synth.mli create mode 100644 otherlibs/labltk/frx/frx_text.ml create mode 100644 otherlibs/labltk/frx/frx_text.mli create mode 100644 otherlibs/labltk/frx/frx_toplevel.mli create mode 100644 otherlibs/labltk/frx/frx_widget.ml create mode 100644 otherlibs/labltk/frx/frx_widget.mli create mode 100644 otherlibs/labltk/frx/frxlib.mllib create mode 100644 otherlibs/labltk/jpf/Makefile create mode 100644 otherlibs/labltk/jpf/Makefile.nt create mode 100644 otherlibs/labltk/jpf/README create mode 100644 otherlibs/labltk/jpf/balloon.ml create mode 100644 otherlibs/labltk/jpf/balloon.mli create mode 100644 otherlibs/labltk/jpf/balloontest.ml create mode 100644 otherlibs/labltk/jpf/fileselect.ml create mode 100644 otherlibs/labltk/jpf/fileselect.mli create mode 100644 otherlibs/labltk/jpf/jpf_font.ml create mode 100644 otherlibs/labltk/jpf/jpf_font.mli create mode 100644 otherlibs/labltk/jpf/jpflib.mllib create mode 100644 otherlibs/labltk/jpf/shell.ml create mode 100644 otherlibs/labltk/jpf/shell.mli create mode 100644 otherlibs/labltk/labl.gif create mode 100644 otherlibs/labltk/labltk/.cvsignore create mode 100644 otherlibs/labltk/labltk/Makefile create mode 100644 otherlibs/labltk/labltk/Makefile.gen create mode 100644 otherlibs/labltk/labltk/Makefile.gen.nt create mode 100644 otherlibs/labltk/labltk/Makefile.nt create mode 100644 otherlibs/labltk/labltk/byte.itarget create mode 100644 otherlibs/labltk/labltk/modules create mode 100644 otherlibs/labltk/labltk/native.itarget create mode 100644 otherlibs/labltk/lib/.cvsignore create mode 100644 otherlibs/labltk/lib/Makefile create mode 100644 otherlibs/labltk/lib/Makefile.nt create mode 100644 otherlibs/labltk/support/.depend create mode 100644 otherlibs/labltk/support/Makefile create mode 100644 otherlibs/labltk/support/Makefile.common create mode 100644 otherlibs/labltk/support/Makefile.nt create mode 100644 otherlibs/labltk/support/byte.itarget create mode 100644 otherlibs/labltk/support/camltk.h create mode 100644 otherlibs/labltk/support/camltkwrap.ml create mode 100644 otherlibs/labltk/support/camltkwrap.mli create mode 100644 otherlibs/labltk/support/cltkCaml.c create mode 100644 otherlibs/labltk/support/cltkDMain.c create mode 100644 otherlibs/labltk/support/cltkEval.c create mode 100644 otherlibs/labltk/support/cltkEvent.c create mode 100644 otherlibs/labltk/support/cltkFile.c create mode 100644 otherlibs/labltk/support/cltkImg.c create mode 100644 otherlibs/labltk/support/cltkMain.c create mode 100644 otherlibs/labltk/support/cltkMisc.c create mode 100644 otherlibs/labltk/support/cltkTimer.c create mode 100644 otherlibs/labltk/support/cltkUtf.c create mode 100644 otherlibs/labltk/support/cltkVar.c create mode 100644 otherlibs/labltk/support/cltkWait.c create mode 100644 otherlibs/labltk/support/fileevent.ml create mode 100644 otherlibs/labltk/support/fileevent.mli create mode 100644 otherlibs/labltk/support/liblabltk.clib create mode 100644 otherlibs/labltk/support/native.itarget create mode 100644 otherlibs/labltk/support/protocol.ml create mode 100644 otherlibs/labltk/support/protocol.mli create mode 100644 otherlibs/labltk/support/rawwidget.ml create mode 100644 otherlibs/labltk/support/rawwidget.mli create mode 100644 otherlibs/labltk/support/slave.ml create mode 100644 otherlibs/labltk/support/support.ml create mode 100644 otherlibs/labltk/support/support.mli create mode 100644 otherlibs/labltk/support/textvariable.ml create mode 100644 otherlibs/labltk/support/textvariable.mli create mode 100644 otherlibs/labltk/support/timer.ml create mode 100644 otherlibs/labltk/support/timer.mli create mode 100644 otherlibs/labltk/support/tkthread.ml create mode 100644 otherlibs/labltk/support/tkthread.mli create mode 100644 otherlibs/labltk/support/tkwait.ml create mode 100644 otherlibs/labltk/support/widget.ml create mode 100644 otherlibs/labltk/support/widget.mli create mode 100644 otherlibs/labltk/tkanim/.cvsignore create mode 100644 otherlibs/labltk/tkanim/.depend create mode 100644 otherlibs/labltk/tkanim/Makefile create mode 100644 otherlibs/labltk/tkanim/Makefile.nt create mode 100644 otherlibs/labltk/tkanim/README create mode 100644 otherlibs/labltk/tkanim/cltkaniminit.c create mode 100644 otherlibs/labltk/tkanim/gifanimtest.ml create mode 100644 otherlibs/labltk/tkanim/libtkanim.clib create mode 100644 otherlibs/labltk/tkanim/mmm.anim.gif create mode 100644 otherlibs/labltk/tkanim/tkAnimGIF.c create mode 100644 otherlibs/labltk/tkanim/tkAppInit.c create mode 100644 otherlibs/labltk/tkanim/tkanim.ml create mode 100644 otherlibs/labltk/tkanim/tkanim.mli create mode 100644 otherlibs/num/.cvsignore create mode 100644 otherlibs/num/.depend create mode 100644 otherlibs/num/.depend.nt create mode 100644 otherlibs/num/Makefile create mode 100644 otherlibs/num/Makefile.nt create mode 100644 otherlibs/num/README create mode 100644 otherlibs/num/arith_flags.ml create mode 100644 otherlibs/num/arith_flags.mli create mode 100644 otherlibs/num/arith_status.ml create mode 100644 otherlibs/num/arith_status.mli create mode 100644 otherlibs/num/big_int.ml create mode 100644 otherlibs/num/big_int.mli create mode 100644 otherlibs/num/bignum/.cvsignore create mode 100644 otherlibs/num/bng.c create mode 100644 otherlibs/num/bng.h create mode 100644 otherlibs/num/bng_alpha.c create mode 100644 otherlibs/num/bng_amd64.c create mode 100644 otherlibs/num/bng_digit.c create mode 100644 otherlibs/num/bng_ia32.c create mode 100644 otherlibs/num/bng_mips.c create mode 100644 otherlibs/num/bng_ppc.c create mode 100644 otherlibs/num/bng_sparc.c create mode 100644 otherlibs/num/dllnums.dlib create mode 100644 otherlibs/num/int_misc.ml create mode 100644 otherlibs/num/int_misc.mli create mode 100644 otherlibs/num/libnums.clib create mode 100644 otherlibs/num/nat.h create mode 100644 otherlibs/num/nat.ml create mode 100644 otherlibs/num/nat.mli create mode 100644 otherlibs/num/nat_stubs.c create mode 100644 otherlibs/num/num.ml create mode 100644 otherlibs/num/num.mli create mode 100644 otherlibs/num/nums.mllib create mode 100644 otherlibs/num/ratio.ml create mode 100644 otherlibs/num/ratio.mli create mode 100644 otherlibs/num/test/.depend create mode 100644 otherlibs/num/test/Makefile create mode 100644 otherlibs/num/test/Makefile.nt create mode 100644 otherlibs/num/test/end_test.ml create mode 100644 otherlibs/num/test/pi_big_int.ml create mode 100644 otherlibs/num/test/pi_num.ml create mode 100644 otherlibs/num/test/test.ml create mode 100644 otherlibs/num/test/test_big_ints.ml create mode 100644 otherlibs/num/test/test_bng.c create mode 100644 otherlibs/num/test/test_io.ml create mode 100644 otherlibs/num/test/test_nats.ml create mode 100644 otherlibs/num/test/test_nums.ml create mode 100644 otherlibs/num/test/test_ratios.ml create mode 100644 otherlibs/str/.cvsignore create mode 100644 otherlibs/str/.depend create mode 100644 otherlibs/str/Makefile create mode 100644 otherlibs/str/Makefile.nt create mode 100644 otherlibs/str/dllstr.dlib create mode 100644 otherlibs/str/libstr.clib create mode 100644 otherlibs/str/str.ml create mode 100644 otherlibs/str/str.mli create mode 100644 otherlibs/str/strstubs.c create mode 100644 otherlibs/systhreads/.cvsignore create mode 100644 otherlibs/systhreads/.depend create mode 100644 otherlibs/systhreads/Makefile create mode 100644 otherlibs/systhreads/Makefile.nt create mode 100644 otherlibs/systhreads/Tests/Makefile create mode 100644 otherlibs/systhreads/Tests/Makefile.nt create mode 100644 otherlibs/systhreads/condition.ml create mode 100644 otherlibs/systhreads/condition.mli create mode 100644 otherlibs/systhreads/dllthreads.dlib create mode 100644 otherlibs/systhreads/event.ml create mode 100644 otherlibs/systhreads/event.mli create mode 100644 otherlibs/systhreads/libthreads.clib create mode 100644 otherlibs/systhreads/libthreadswin32.clib create mode 100644 otherlibs/systhreads/mutex.ml create mode 100644 otherlibs/systhreads/mutex.mli create mode 100644 otherlibs/systhreads/posix.c create mode 100644 otherlibs/systhreads/thread.mli create mode 100644 otherlibs/systhreads/threadUnix.ml create mode 100644 otherlibs/systhreads/threadUnix.mli create mode 100644 otherlibs/systhreads/thread_posix.ml create mode 100644 otherlibs/systhreads/thread_win32.ml create mode 100644 otherlibs/systhreads/threads.mllib create mode 100644 otherlibs/systhreads/win32.c create mode 100644 otherlibs/threads/.cvsignore create mode 100644 otherlibs/threads/.depend create mode 100644 otherlibs/threads/Makefile create mode 100644 otherlibs/threads/Tests/.cvsignore create mode 100644 otherlibs/threads/Tests/Makefile create mode 100644 otherlibs/threads/Tests/close.ml create mode 100644 otherlibs/threads/Tests/sieve.ml create mode 100644 otherlibs/threads/Tests/sorts.ml create mode 100644 otherlibs/threads/Tests/test1.ml create mode 100644 otherlibs/threads/Tests/test2.ml create mode 100644 otherlibs/threads/Tests/test3.ml create mode 100644 otherlibs/threads/Tests/test4.ml create mode 100644 otherlibs/threads/Tests/test5.ml create mode 100644 otherlibs/threads/Tests/test6.ml create mode 100644 otherlibs/threads/Tests/test7.ml create mode 100644 otherlibs/threads/Tests/test8.ml create mode 100644 otherlibs/threads/Tests/test9.ml create mode 100644 otherlibs/threads/Tests/testA.ml create mode 100644 otherlibs/threads/Tests/testexit.ml create mode 100644 otherlibs/threads/Tests/testio.ml create mode 100644 otherlibs/threads/Tests/testsieve.ml create mode 100644 otherlibs/threads/Tests/testsignal.ml create mode 100644 otherlibs/threads/Tests/testsignal2.ml create mode 100644 otherlibs/threads/Tests/testsocket.ml create mode 100644 otherlibs/threads/Tests/token1.ml create mode 100644 otherlibs/threads/Tests/token2.ml create mode 100644 otherlibs/threads/Tests/torture.ml create mode 100644 otherlibs/threads/condition.ml create mode 100644 otherlibs/threads/condition.mli create mode 100644 otherlibs/threads/event.ml create mode 100644 otherlibs/threads/event.mli create mode 100644 otherlibs/threads/libvmthreads.clib create mode 100644 otherlibs/threads/marshal.ml create mode 100644 otherlibs/threads/mutex.ml create mode 100644 otherlibs/threads/mutex.mli create mode 100644 otherlibs/threads/pervasives.ml create mode 100644 otherlibs/threads/scheduler.c create mode 100644 otherlibs/threads/thread.ml create mode 100644 otherlibs/threads/thread.mli create mode 100644 otherlibs/threads/threadUnix.ml create mode 100644 otherlibs/threads/threadUnix.mli create mode 100644 otherlibs/threads/threads.mllib create mode 100644 otherlibs/threads/unix.ml create mode 100644 otherlibs/threads/unix.mllib create mode 100644 otherlibs/unix/.cvsignore create mode 100644 otherlibs/unix/.depend create mode 100644 otherlibs/unix/Makefile create mode 100644 otherlibs/unix/accept.c create mode 100644 otherlibs/unix/access.c create mode 100644 otherlibs/unix/addrofstr.c create mode 100644 otherlibs/unix/alarm.c create mode 100644 otherlibs/unix/bind.c create mode 100644 otherlibs/unix/chdir.c create mode 100644 otherlibs/unix/chmod.c create mode 100644 otherlibs/unix/chown.c create mode 100644 otherlibs/unix/chroot.c create mode 100644 otherlibs/unix/close.c create mode 100644 otherlibs/unix/closedir.c create mode 100644 otherlibs/unix/connect.c create mode 100644 otherlibs/unix/cst2constr.c create mode 100644 otherlibs/unix/cst2constr.h create mode 100644 otherlibs/unix/cstringv.c create mode 100644 otherlibs/unix/dup.c create mode 100644 otherlibs/unix/dup2.c create mode 100644 otherlibs/unix/envir.c create mode 100644 otherlibs/unix/errmsg.c create mode 100644 otherlibs/unix/execv.c create mode 100644 otherlibs/unix/execve.c create mode 100644 otherlibs/unix/execvp.c create mode 100644 otherlibs/unix/exit.c create mode 100644 otherlibs/unix/fchmod.c create mode 100644 otherlibs/unix/fchown.c create mode 100644 otherlibs/unix/fcntl.c create mode 100644 otherlibs/unix/fork.c create mode 100644 otherlibs/unix/ftruncate.c create mode 100644 otherlibs/unix/getaddrinfo.c create mode 100644 otherlibs/unix/getcwd.c create mode 100644 otherlibs/unix/getegid.c create mode 100644 otherlibs/unix/geteuid.c create mode 100644 otherlibs/unix/getgid.c create mode 100644 otherlibs/unix/getgr.c create mode 100644 otherlibs/unix/getgroups.c create mode 100644 otherlibs/unix/gethost.c create mode 100644 otherlibs/unix/gethostname.c create mode 100644 otherlibs/unix/getlogin.c create mode 100644 otherlibs/unix/getnameinfo.c create mode 100644 otherlibs/unix/getpeername.c create mode 100644 otherlibs/unix/getpid.c create mode 100644 otherlibs/unix/getppid.c create mode 100644 otherlibs/unix/getproto.c create mode 100644 otherlibs/unix/getpw.c create mode 100644 otherlibs/unix/getserv.c create mode 100644 otherlibs/unix/getsockname.c create mode 100644 otherlibs/unix/gettimeofday.c create mode 100644 otherlibs/unix/getuid.c create mode 100644 otherlibs/unix/gmtime.c create mode 100644 otherlibs/unix/isatty.c create mode 100644 otherlibs/unix/itimer.c create mode 100644 otherlibs/unix/kill.c create mode 100644 otherlibs/unix/libunix.clib create mode 100644 otherlibs/unix/link.c create mode 100644 otherlibs/unix/listen.c create mode 100644 otherlibs/unix/lockf.c create mode 100644 otherlibs/unix/lseek.c create mode 100644 otherlibs/unix/mkdir.c create mode 100644 otherlibs/unix/mkfifo.c create mode 100644 otherlibs/unix/nice.c create mode 100644 otherlibs/unix/open.c create mode 100644 otherlibs/unix/opendir.c create mode 100644 otherlibs/unix/pipe.c create mode 100644 otherlibs/unix/putenv.c create mode 100644 otherlibs/unix/read.c create mode 100644 otherlibs/unix/readdir.c create mode 100644 otherlibs/unix/readlink.c create mode 100644 otherlibs/unix/rename.c create mode 100644 otherlibs/unix/rewinddir.c create mode 100644 otherlibs/unix/rmdir.c create mode 100644 otherlibs/unix/select.c create mode 100644 otherlibs/unix/sendrecv.c create mode 100644 otherlibs/unix/setgid.c create mode 100644 otherlibs/unix/setsid.c create mode 100644 otherlibs/unix/setuid.c create mode 100644 otherlibs/unix/shutdown.c create mode 100644 otherlibs/unix/signals.c create mode 100644 otherlibs/unix/sleep.c create mode 100644 otherlibs/unix/socket.c create mode 100644 otherlibs/unix/socketaddr.c create mode 100644 otherlibs/unix/socketaddr.h create mode 100644 otherlibs/unix/socketpair.c create mode 100644 otherlibs/unix/sockopt.c create mode 100644 otherlibs/unix/stat.c create mode 100644 otherlibs/unix/strofaddr.c create mode 100644 otherlibs/unix/symlink.c create mode 100644 otherlibs/unix/termios.c create mode 100644 otherlibs/unix/time.c create mode 100644 otherlibs/unix/times.c create mode 100644 otherlibs/unix/truncate.c create mode 100644 otherlibs/unix/umask.c create mode 100644 otherlibs/unix/unix.ml create mode 100644 otherlibs/unix/unix.mli create mode 100644 otherlibs/unix/unix.mllib create mode 100644 otherlibs/unix/unixLabels.ml create mode 100644 otherlibs/unix/unixLabels.mli create mode 100644 otherlibs/unix/unixsupport.c create mode 100644 otherlibs/unix/unixsupport.h create mode 100644 otherlibs/unix/unlink.c create mode 100644 otherlibs/unix/utimes.c create mode 100644 otherlibs/unix/wait.c create mode 100644 otherlibs/unix/write.c create mode 100644 otherlibs/win32graph/Makefile.nt create mode 100644 otherlibs/win32graph/dib.c create mode 100644 otherlibs/win32graph/dllgraphics.dlib create mode 100644 otherlibs/win32graph/draw.c create mode 100755 otherlibs/win32graph/events.c create mode 100644 otherlibs/win32graph/libgraph.h create mode 100644 otherlibs/win32graph/libgraphics.clib create mode 100644 otherlibs/win32graph/open.c create mode 100644 otherlibs/win32unix/.cvsignore create mode 100644 otherlibs/win32unix/.depend create mode 100644 otherlibs/win32unix/Makefile.nt create mode 100644 otherlibs/win32unix/accept.c create mode 100644 otherlibs/win32unix/bind.c create mode 100644 otherlibs/win32unix/channels.c create mode 100644 otherlibs/win32unix/close.c create mode 100644 otherlibs/win32unix/close_on.c create mode 100644 otherlibs/win32unix/connect.c create mode 100644 otherlibs/win32unix/createprocess.c create mode 100644 otherlibs/win32unix/dllunix.dlib create mode 100644 otherlibs/win32unix/dup.c create mode 100644 otherlibs/win32unix/dup2.c create mode 100644 otherlibs/win32unix/errmsg.c create mode 100644 otherlibs/win32unix/getpeername.c create mode 100644 otherlibs/win32unix/getpid.c create mode 100644 otherlibs/win32unix/getsockname.c create mode 100644 otherlibs/win32unix/gettimeofday.c create mode 100644 otherlibs/win32unix/libunix.clib create mode 100644 otherlibs/win32unix/link.c create mode 100644 otherlibs/win32unix/listen.c create mode 100644 otherlibs/win32unix/lockf.c create mode 100644 otherlibs/win32unix/lseek.c create mode 100644 otherlibs/win32unix/mkdir.c create mode 100755 otherlibs/win32unix/nonblock.c create mode 100644 otherlibs/win32unix/open.c create mode 100644 otherlibs/win32unix/pipe.c create mode 100644 otherlibs/win32unix/read.c create mode 100644 otherlibs/win32unix/rename.c create mode 100644 otherlibs/win32unix/select.c create mode 100644 otherlibs/win32unix/sendrecv.c create mode 100644 otherlibs/win32unix/shutdown.c create mode 100644 otherlibs/win32unix/sleep.c create mode 100644 otherlibs/win32unix/socket.c create mode 100644 otherlibs/win32unix/socketaddr.h create mode 100644 otherlibs/win32unix/sockopt.c create mode 100644 otherlibs/win32unix/startup.c create mode 100644 otherlibs/win32unix/stat.c create mode 100644 otherlibs/win32unix/system.c create mode 100644 otherlibs/win32unix/unix.ml create mode 100644 otherlibs/win32unix/unixsupport.c create mode 100644 otherlibs/win32unix/unixsupport.h create mode 100644 otherlibs/win32unix/windbug.c create mode 100644 otherlibs/win32unix/windbug.h create mode 100644 otherlibs/win32unix/windir.c create mode 100644 otherlibs/win32unix/winlist.c create mode 100644 otherlibs/win32unix/winlist.h create mode 100644 otherlibs/win32unix/winwait.c create mode 100644 otherlibs/win32unix/winworker.c create mode 100644 otherlibs/win32unix/winworker.h create mode 100644 otherlibs/win32unix/write.c create mode 100644 parsing/.cvsignore create mode 100644 parsing/asttypes.mli create mode 100644 parsing/lexer.mli create mode 100644 parsing/lexer.mll create mode 100644 parsing/linenum.mli create mode 100644 parsing/linenum.mll create mode 100644 parsing/location.ml create mode 100644 parsing/location.mli create mode 100644 parsing/longident.ml create mode 100644 parsing/longident.mli create mode 100644 parsing/parse.ml create mode 100644 parsing/parse.mli create mode 100644 parsing/parser.mly create mode 100644 parsing/parsetree.mli create mode 100644 parsing/printast.ml create mode 100644 parsing/printast.mli create mode 100644 parsing/syntaxerr.ml create mode 100644 parsing/syntaxerr.mli create mode 100644 stdlib/.cvsignore create mode 100644 stdlib/.depend create mode 100755 stdlib/Compflags create mode 100644 stdlib/Makefile create mode 100644 stdlib/Makefile.nt create mode 100755 stdlib/Makefile.shared create mode 100644 stdlib/StdlibModules create mode 100644 stdlib/arg.ml create mode 100644 stdlib/arg.mli create mode 100644 stdlib/array.ml create mode 100644 stdlib/array.mli create mode 100644 stdlib/arrayLabels.ml create mode 100644 stdlib/arrayLabels.mli create mode 100644 stdlib/buffer.ml create mode 100644 stdlib/buffer.mli create mode 100644 stdlib/callback.ml create mode 100644 stdlib/callback.mli create mode 100644 stdlib/camlinternalLazy.ml create mode 100644 stdlib/camlinternalLazy.mli create mode 100644 stdlib/camlinternalMod.ml create mode 100644 stdlib/camlinternalMod.mli create mode 100644 stdlib/camlinternalOO.ml create mode 100644 stdlib/camlinternalOO.mli create mode 100644 stdlib/char.ml create mode 100644 stdlib/char.mli create mode 100644 stdlib/complex.ml create mode 100644 stdlib/complex.mli create mode 100644 stdlib/digest.ml create mode 100644 stdlib/digest.mli create mode 100644 stdlib/filename.ml create mode 100644 stdlib/filename.mli create mode 100644 stdlib/format.ml create mode 100644 stdlib/format.mli create mode 100644 stdlib/gc.ml create mode 100644 stdlib/gc.mli create mode 100644 stdlib/genlex.ml create mode 100644 stdlib/genlex.mli create mode 100644 stdlib/hashtbl.ml create mode 100644 stdlib/hashtbl.mli create mode 100644 stdlib/header.c create mode 100644 stdlib/headernt.c create mode 100644 stdlib/int32.ml create mode 100644 stdlib/int32.mli create mode 100644 stdlib/int64.ml create mode 100644 stdlib/int64.mli create mode 100644 stdlib/lazy.ml create mode 100644 stdlib/lazy.mli create mode 100644 stdlib/lexing.ml create mode 100644 stdlib/lexing.mli create mode 100644 stdlib/list.ml create mode 100644 stdlib/list.mli create mode 100644 stdlib/listLabels.ml create mode 100644 stdlib/listLabels.mli create mode 100644 stdlib/map.ml create mode 100644 stdlib/map.mli create mode 100644 stdlib/marshal.ml create mode 100644 stdlib/marshal.mli create mode 100644 stdlib/moreLabels.ml create mode 100644 stdlib/moreLabels.mli create mode 100644 stdlib/nativeint.ml create mode 100644 stdlib/nativeint.mli create mode 100644 stdlib/obj.ml create mode 100644 stdlib/obj.mli create mode 100644 stdlib/oo.ml create mode 100644 stdlib/oo.mli create mode 100644 stdlib/parsing.ml create mode 100644 stdlib/parsing.mli create mode 100644 stdlib/pervasives.ml create mode 100644 stdlib/pervasives.mli create mode 100644 stdlib/printexc.ml create mode 100644 stdlib/printexc.mli create mode 100644 stdlib/printf.ml create mode 100644 stdlib/printf.mli create mode 100644 stdlib/queue.ml create mode 100644 stdlib/queue.mli create mode 100644 stdlib/random.ml create mode 100644 stdlib/random.mli create mode 100644 stdlib/scanf.ml create mode 100644 stdlib/scanf.mli create mode 100644 stdlib/set.ml create mode 100644 stdlib/set.mli create mode 100644 stdlib/sharpbang create mode 100644 stdlib/sort.ml create mode 100644 stdlib/sort.mli create mode 100644 stdlib/stack.ml create mode 100644 stdlib/stack.mli create mode 100644 stdlib/stdLabels.ml create mode 100644 stdlib/stdLabels.mli create mode 100644 stdlib/std_exit.ml create mode 100644 stdlib/stdlib.mllib create mode 100644 stdlib/stream.ml create mode 100644 stdlib/stream.mli create mode 100644 stdlib/string.ml create mode 100644 stdlib/string.mli create mode 100644 stdlib/stringLabels.ml create mode 100644 stdlib/stringLabels.mli create mode 100644 stdlib/sys.mli create mode 100644 stdlib/sys.mlp create mode 100644 stdlib/weak.ml create mode 100644 stdlib/weak.mli create mode 100644 test/.cvsignore create mode 100644 test/.depend create mode 100644 test/KB/equations.ml create mode 100644 test/KB/equations.mli create mode 100644 test/KB/kb.ml create mode 100644 test/KB/kb.mli create mode 100644 test/KB/kbmain.ml create mode 100644 test/KB/orderings.ml create mode 100644 test/KB/orderings.mli create mode 100644 test/KB/terms.ml create mode 100644 test/KB/terms.mli create mode 100644 test/Lex/.cvsignore create mode 100644 test/Lex/gram_aux.ml create mode 100644 test/Lex/grammar.mly create mode 100644 test/Lex/lexgen.ml create mode 100644 test/Lex/main.ml create mode 100644 test/Lex/output.ml create mode 100644 test/Lex/scan_aux.ml create mode 100644 test/Lex/scanner.mll create mode 100644 test/Lex/syntax.ml create mode 100644 test/Lex/testmain.ml create mode 100644 test/Lex/testscanner.mll create mode 100644 test/Makefile create mode 100644 test/Moretest/.cvsignore create mode 100644 test/Moretest/.depend create mode 100644 test/Moretest/Makefile create mode 100644 test/Moretest/arrays.ml create mode 100644 test/Moretest/backtrace.ml create mode 100644 test/Moretest/backtrace2.ml create mode 100644 test/Moretest/bigarrays.ml create mode 100644 test/Moretest/bigarrf.f create mode 100644 test/Moretest/bigarrfml.ml create mode 100644 test/Moretest/bigarrfstub.c create mode 100644 test/Moretest/bigints.ml create mode 100644 test/Moretest/bounds.ml create mode 100644 test/Moretest/boxedints.ml create mode 100644 test/Moretest/callbackprim.c create mode 100644 test/Moretest/cmcaml.ml create mode 100644 test/Moretest/cmmain.c create mode 100644 test/Moretest/cmstub.c create mode 100644 test/Moretest/equality.ml create mode 100644 test/Moretest/fftba.ml create mode 100644 test/Moretest/float.ml create mode 100644 test/Moretest/float_record.ml create mode 100644 test/Moretest/float_record.mli create mode 100644 test/Moretest/globroots.ml create mode 100644 test/Moretest/globrootsprim.c create mode 100644 test/Moretest/graph_example.ml create mode 100644 test/Moretest/graph_test.ml create mode 100644 test/Moretest/includestruct.ml create mode 100644 test/Moretest/intext.ml create mode 100644 test/Moretest/intextaux.c create mode 100644 test/Moretest/io.ml create mode 100644 test/Moretest/length.ml create mode 100644 test/Moretest/length.mli create mode 100644 test/Moretest/manyargs.ml create mode 100644 test/Moretest/manyargsprim.c create mode 100644 test/Moretest/md5.ml create mode 100644 test/Moretest/morematch.ml create mode 100644 test/Moretest/multdef.ml create mode 100644 test/Moretest/multdef.mli create mode 100644 test/Moretest/patmatch.ml create mode 100644 test/Moretest/recmod.ml create mode 100644 test/Moretest/recmod.mli create mode 100644 test/Moretest/recmod/01bad.ml create mode 100644 test/Moretest/recmod/02bad.ml create mode 100644 test/Moretest/recmod/03ok.ml create mode 100644 test/Moretest/recmod/04bad.ml create mode 100644 test/Moretest/recmod/05bad.ml create mode 100644 test/Moretest/recmod/06ok.ml create mode 100644 test/Moretest/recmod/07bad.ml create mode 100644 test/Moretest/recmod/08bad.ml create mode 100644 test/Moretest/recmod/09bad.ml create mode 100644 test/Moretest/recmod/10ok.ml create mode 100644 test/Moretest/recmod/11bad.ml create mode 100644 test/Moretest/recmod/12bad.ml create mode 100644 test/Moretest/recmod/13ok.ml create mode 100644 test/Moretest/recmod/14bad.ml create mode 100644 test/Moretest/recmod/15bad.ml create mode 100644 test/Moretest/recmod/16ok.ml create mode 100644 test/Moretest/recmod/17ok.ml create mode 100644 test/Moretest/recmod/18ok.ml create mode 100644 test/Moretest/recmod/19ok.ml create mode 100644 test/Moretest/recmod/20ok.ml create mode 100644 test/Moretest/recmod/21ok.ml create mode 100644 test/Moretest/recvalues.ml create mode 100644 test/Moretest/regexp.ml create mode 100644 test/Moretest/sets.ml create mode 100644 test/Moretest/signals.ml create mode 100644 test/Moretest/stackoverflow.ml create mode 100644 test/Moretest/syserror.ml create mode 100644 test/Moretest/tailcalls.ml create mode 100644 test/Moretest/tbuffer.ml create mode 100644 test/Moretest/tcallback.ml create mode 100644 test/Moretest/testing.ml create mode 100644 test/Moretest/testing.mli create mode 100644 test/Moretest/testrandom.ml create mode 100644 test/Moretest/tfloat_record.ml create mode 100644 test/Moretest/tlength.ml create mode 100644 test/Moretest/tprintf.ml create mode 100644 test/Moretest/tscanf.ml create mode 100644 test/Moretest/tscanf2_io.ml create mode 100644 test/Moretest/tscanf2_master.ml create mode 100644 test/Moretest/tscanf2_slave.ml create mode 100644 test/Moretest/usemultdef.ml create mode 100644 test/Moretest/warnings.ml create mode 100644 test/Moretest/wc.ml create mode 100644 test/Results/almabench.fast.out create mode 100644 test/Results/almabench.out create mode 100644 test/Results/bdd.out create mode 100644 test/Results/boyer.out create mode 100644 test/Results/fft.fast.out create mode 100644 test/Results/fft.out create mode 100644 test/Results/fib.out create mode 100644 test/Results/hamming.out create mode 100644 test/Results/kb.out create mode 100644 test/Results/nucleic.out create mode 100644 test/Results/quicksort.fast.out create mode 100644 test/Results/quicksort.out create mode 100644 test/Results/sieve.out create mode 100644 test/Results/soli.fast.out create mode 100644 test/Results/soli.out create mode 100644 test/Results/sorts.out create mode 100644 test/Results/takc.out create mode 100644 test/Results/taku.out create mode 100644 test/Results/weaktest.out create mode 100644 test/alloc.ml create mode 100644 test/almabench.ml create mode 100644 test/bdd.ml create mode 100644 test/boyer.ml create mode 100644 test/dynlink/Makefile create mode 100644 test/dynlink/main.ml create mode 100644 test/dynlink/plug1.ml create mode 100644 test/dynlink/plug2.ml create mode 100644 test/dynlink/stub1.c create mode 100644 test/dynlink/stub2.c create mode 100644 test/fft.ml create mode 100644 test/fib.ml create mode 100644 test/hamming.ml create mode 100644 test/natdynlink/Makefile create mode 100755 test/natdynlink/a.ml create mode 100644 test/natdynlink/api.ml create mode 100755 test/natdynlink/b.ml create mode 100644 test/natdynlink/bug.ml create mode 100755 test/natdynlink/c.ml create mode 100644 test/natdynlink/factorial.c create mode 100644 test/natdynlink/main.ml create mode 100644 test/natdynlink/pack_client.ml create mode 100644 test/natdynlink/packed1.ml create mode 100644 test/natdynlink/packed1_client.ml create mode 100644 test/natdynlink/plugin.ml create mode 100644 test/natdynlink/plugin.mli create mode 100644 test/natdynlink/plugin2.ml create mode 100644 test/natdynlink/plugin4.ml create mode 100644 test/natdynlink/plugin_ext.ml create mode 100644 test/natdynlink/plugin_high_arity.ml create mode 100644 test/natdynlink/plugin_ref.ml create mode 100644 test/natdynlink/plugin_simple.ml create mode 100644 test/natdynlink/plugin_thread.ml create mode 100644 test/natdynlink/sub/api.ml create mode 100644 test/natdynlink/sub/api.mli create mode 100644 test/natdynlink/sub/plugin.ml create mode 100644 test/natdynlink/sub/plugin3.ml create mode 100644 test/nucleic.ml create mode 100644 test/ocamldoc/Makefile create mode 100644 test/ocamldoc/t1.ml create mode 100755 test/outputobj/Makefile create mode 100755 test/outputobj/entry.c create mode 100755 test/outputobj/main.cs create mode 100755 test/outputobj/main.ml create mode 100755 test/outputobj/plugin.ml create mode 100644 test/quicksort.ml create mode 100644 test/sieve.ml create mode 100644 test/soli.ml create mode 100644 test/sorts.ml create mode 100644 test/takc.ml create mode 100644 test/taku.ml create mode 100644 test/testinterp/.cvsignore create mode 100644 test/testinterp/coverage create mode 100644 test/testinterp/lib.ml create mode 100644 test/testinterp/no68k.rez create mode 100644 test/testinterp/noppc.rez create mode 100644 test/testinterp/t000.ml create mode 100644 test/testinterp/t010-const0.ml create mode 100644 test/testinterp/t010-const1.ml create mode 100644 test/testinterp/t010-const2.ml create mode 100644 test/testinterp/t010-const3.ml create mode 100644 test/testinterp/t011-constint.ml create mode 100644 test/testinterp/t020.ml create mode 100644 test/testinterp/t021-pushconst1.ml create mode 100644 test/testinterp/t021-pushconst2.ml create mode 100644 test/testinterp/t021-pushconst3.ml create mode 100644 test/testinterp/t022-pushconstint.ml create mode 100644 test/testinterp/t040-makeblock1.ml create mode 100644 test/testinterp/t040-makeblock2.ml create mode 100644 test/testinterp/t040-makeblock3.ml create mode 100644 test/testinterp/t041-makeblock.ml create mode 100644 test/testinterp/t050-getglobal.ml create mode 100644 test/testinterp/t050-pushgetglobal.ml create mode 100644 test/testinterp/t051-getglobalfield.ml create mode 100644 test/testinterp/t051-pushgetglobalfield.ml create mode 100644 test/testinterp/t060-raise.ml create mode 100644 test/testinterp/t070-branch.ml create mode 100644 test/testinterp/t070-branchif.ml create mode 100644 test/testinterp/t070-branchifnot.ml create mode 100644 test/testinterp/t071-boolnot.ml create mode 100644 test/testinterp/t080-eq.ml create mode 100644 test/testinterp/t080-geint.ml create mode 100644 test/testinterp/t080-gtint.ml create mode 100644 test/testinterp/t080-leint.ml create mode 100644 test/testinterp/t080-ltint.ml create mode 100644 test/testinterp/t080-neq.ml create mode 100644 test/testinterp/t090-acc0.ml create mode 100644 test/testinterp/t090-acc1.ml create mode 100644 test/testinterp/t090-acc2.ml create mode 100644 test/testinterp/t090-acc3.ml create mode 100644 test/testinterp/t090-acc4.ml create mode 100644 test/testinterp/t090-acc5.ml create mode 100644 test/testinterp/t090-acc6.ml create mode 100644 test/testinterp/t090-acc7.ml create mode 100644 test/testinterp/t091-acc.ml create mode 100644 test/testinterp/t092-pushacc.ml create mode 100644 test/testinterp/t092-pushacc0.ml create mode 100644 test/testinterp/t092-pushacc1.ml create mode 100644 test/testinterp/t092-pushacc2.ml create mode 100644 test/testinterp/t092-pushacc3.ml create mode 100644 test/testinterp/t092-pushacc4.ml create mode 100644 test/testinterp/t092-pushacc5.ml create mode 100644 test/testinterp/t092-pushacc6.ml create mode 100644 test/testinterp/t092-pushacc7.ml create mode 100644 test/testinterp/t093-pushacc.ml create mode 100644 test/testinterp/t100-pushtrap.ml create mode 100644 test/testinterp/t101-poptrap.ml create mode 100644 test/testinterp/t110-addint.ml create mode 100644 test/testinterp/t110-andint.ml create mode 100644 test/testinterp/t110-asrint-1.ml create mode 100644 test/testinterp/t110-asrint-2.ml create mode 100644 test/testinterp/t110-divint-1.ml create mode 100644 test/testinterp/t110-divint-2.ml create mode 100644 test/testinterp/t110-divint-3.ml create mode 100644 test/testinterp/t110-lslint.ml create mode 100644 test/testinterp/t110-lsrint.ml create mode 100644 test/testinterp/t110-modint-1.ml create mode 100644 test/testinterp/t110-modint-2.ml create mode 100644 test/testinterp/t110-mulint.ml create mode 100644 test/testinterp/t110-negint.ml create mode 100644 test/testinterp/t110-offsetint.ml create mode 100644 test/testinterp/t110-orint.ml create mode 100644 test/testinterp/t110-subint.ml create mode 100644 test/testinterp/t110-xorint.ml create mode 100644 test/testinterp/t120-getstringchar.ml create mode 100644 test/testinterp/t121-setstringchar.ml create mode 100644 test/testinterp/t130-getvectitem.ml create mode 100644 test/testinterp/t130-vectlength.ml create mode 100644 test/testinterp/t131-setvectitem.ml create mode 100644 test/testinterp/t140-switch-1.ml create mode 100644 test/testinterp/t140-switch-2.ml create mode 100644 test/testinterp/t140-switch-3.ml create mode 100644 test/testinterp/t140-switch-4.ml create mode 100644 test/testinterp/t141-switch-5.ml create mode 100644 test/testinterp/t141-switch-6.ml create mode 100644 test/testinterp/t141-switch-7.ml create mode 100644 test/testinterp/t142-switch-8.ml create mode 100644 test/testinterp/t142-switch-9.ml create mode 100644 test/testinterp/t142-switch-A.ml create mode 100644 test/testinterp/t150-push-1.ml create mode 100644 test/testinterp/t150-push-2.ml create mode 100644 test/testinterp/t160-closure.ml create mode 100644 test/testinterp/t161-apply1.ml create mode 100644 test/testinterp/t162-return.ml create mode 100644 test/testinterp/t163.ml create mode 100644 test/testinterp/t164-apply2.ml create mode 100644 test/testinterp/t164-apply3.ml create mode 100644 test/testinterp/t165-apply.ml create mode 100644 test/testinterp/t170-envacc2.ml create mode 100644 test/testinterp/t170-envacc3.ml create mode 100644 test/testinterp/t170-envacc4.ml create mode 100644 test/testinterp/t171-envacc.ml create mode 100644 test/testinterp/t172-pushenvacc1.ml create mode 100644 test/testinterp/t172-pushenvacc2.ml create mode 100644 test/testinterp/t172-pushenvacc3.ml create mode 100644 test/testinterp/t172-pushenvacc4.ml create mode 100644 test/testinterp/t173-pushenvacc.ml create mode 100644 test/testinterp/t180-appterm1.ml create mode 100644 test/testinterp/t180-appterm2.ml create mode 100644 test/testinterp/t180-appterm3.ml create mode 100644 test/testinterp/t181-appterm.ml create mode 100644 test/testinterp/t190-makefloatblock-1.ml create mode 100644 test/testinterp/t190-makefloatblock-2.ml create mode 100644 test/testinterp/t190-makefloatblock-3.ml create mode 100644 test/testinterp/t191-vectlength.ml create mode 100644 test/testinterp/t192-getfloatfield-1.ml create mode 100644 test/testinterp/t192-getfloatfield-2.ml create mode 100644 test/testinterp/t193-setfloatfield-1.ml create mode 100644 test/testinterp/t193-setfloatfield-2.ml create mode 100644 test/testinterp/t200-getfield0.ml create mode 100644 test/testinterp/t200-getfield1.ml create mode 100644 test/testinterp/t200-getfield2.ml create mode 100644 test/testinterp/t200-getfield3.ml create mode 100644 test/testinterp/t201-getfield.ml create mode 100644 test/testinterp/t210-setfield0.ml create mode 100644 test/testinterp/t210-setfield1.ml create mode 100644 test/testinterp/t210-setfield2.ml create mode 100644 test/testinterp/t210-setfield3.ml create mode 100644 test/testinterp/t211-setfield.ml create mode 100644 test/testinterp/t220-assign.ml create mode 100644 test/testinterp/t230-check_signals.ml create mode 100644 test/testinterp/t240-c_call1.ml create mode 100644 test/testinterp/t240-c_call2.ml create mode 100644 test/testinterp/t240-c_call3.ml create mode 100644 test/testinterp/t240-c_call4.ml create mode 100644 test/testinterp/t240-c_call5.ml create mode 100644 test/testinterp/t250-closurerec-1.ml create mode 100644 test/testinterp/t250-closurerec-2.ml create mode 100644 test/testinterp/t251-pushoffsetclosure0.ml create mode 100644 test/testinterp/t251-pushoffsetclosure2.ml create mode 100644 test/testinterp/t251-pushoffsetclosurem2.ml create mode 100644 test/testinterp/t252-pushoffsetclosure.ml create mode 100644 test/testinterp/t253-offsetclosure0.ml create mode 100644 test/testinterp/t253-offsetclosure2.ml create mode 100644 test/testinterp/t253-offsetclosurem2.ml create mode 100644 test/testinterp/t254-offsetclosure.ml create mode 100644 test/testinterp/t260-offsetref.ml create mode 100644 test/testinterp/t270-push_retaddr.ml create mode 100644 test/testinterp/t300-getmethod.ml create mode 100644 test/testinterp/t301-object.ml create mode 100644 test/testinterp/t310-alloc-1.ml create mode 100644 test/testinterp/t310-alloc-2.ml create mode 100644 test/testinterp/t320-gc-1.ml create mode 100644 test/testinterp/t320-gc-2.ml create mode 100644 test/testinterp/t320-gc-3.ml create mode 100644 test/testinterp/t330-compact-1.ml create mode 100644 test/testinterp/t330-compact-2.ml create mode 100644 test/testinterp/t330-compact-3.ml create mode 100644 test/testinterp/t330-compact-4.ml create mode 100644 test/testinterp/t340-weak.ml create mode 100644 test/testinterp/t350-heapcheck.ml create mode 100644 test/testinterp/t360-stacks-1.ml create mode 100644 test/testinterp/t360-stacks-2.ml create mode 100644 test/weaktest.ml create mode 100644 testasmcomp/.cvsignore create mode 100644 testasmcomp/.depend create mode 100644 testasmcomp/Makefile create mode 100644 testasmcomp/alpha.S create mode 100644 testasmcomp/amd64.S create mode 100644 testasmcomp/arith.cmm create mode 100644 testasmcomp/arm.S create mode 100644 testasmcomp/checkbound.cmm create mode 100644 testasmcomp/fib.cmm create mode 100644 testasmcomp/hppa.S create mode 100644 testasmcomp/i386.S create mode 100644 testasmcomp/i386nt.asm create mode 100644 testasmcomp/ia64.S create mode 100644 testasmcomp/integr.cmm create mode 100644 testasmcomp/lexcmm.mli create mode 100644 testasmcomp/lexcmm.mll create mode 100644 testasmcomp/m68k.S create mode 100644 testasmcomp/main.c create mode 100644 testasmcomp/main.ml create mode 100644 testasmcomp/mainarith.c create mode 100644 testasmcomp/mips.s create mode 100644 testasmcomp/parsecmm.mly create mode 100644 testasmcomp/parsecmmaux.ml create mode 100644 testasmcomp/parsecmmaux.mli create mode 100644 testasmcomp/power-aix.S create mode 100644 testasmcomp/power-elf.S create mode 100644 testasmcomp/power-rhapsody.S create mode 100644 testasmcomp/quicksort.cmm create mode 100644 testasmcomp/quicksort2.cmm create mode 100644 testasmcomp/soli.cmm create mode 100644 testasmcomp/sparc.S create mode 100644 testasmcomp/tagged-fib.cmm create mode 100644 testasmcomp/tagged-integr.cmm create mode 100644 testasmcomp/tagged-quicksort.cmm create mode 100644 testasmcomp/tagged-tak.cmm create mode 100644 testasmcomp/tak.cmm create mode 100644 testlabl/.cvsignore create mode 100644 testlabl/Makefile create mode 100644 testlabl/bugs/pr3918a.mli create mode 100644 testlabl/bugs/pr3918b.mli create mode 100644 testlabl/bugs/pr3918c.ml create mode 100644 testlabl/bugs/pr3968.ml create mode 100644 testlabl/bugs/pr4018.ml create mode 100644 testlabl/bugs/pr4435.ml create mode 100644 testlabl/bugs/privrows-abate.ml create mode 100644 testlabl/bugs/woodyatt.ml create mode 100644 testlabl/bugs/yamagata021012.ml create mode 100644 testlabl/coerce.diffs create mode 100644 testlabl/dirs_multimatch create mode 100644 testlabl/dirs_poly create mode 100644 testlabl/fixedtypes.ml create mode 100644 testlabl/marshal_objects.diffs create mode 100644 testlabl/mixin.ml create mode 100644 testlabl/mixin2.ml create mode 100644 testlabl/mixin3.ml create mode 100644 testlabl/multimatch.diffs create mode 100644 testlabl/multimatch.ml create mode 100644 testlabl/newlabels.ps create mode 100644 testlabl/objvariant.diffs create mode 100644 testlabl/objvariant.ml create mode 100644 testlabl/poly.exp create mode 100644 testlabl/poly.exp2 create mode 100644 testlabl/poly.ml create mode 100644 testlabl/printers.ml create mode 100644 testlabl/private.ml create mode 100644 testlabl/tests.ml create mode 100644 testlabl/valvirt.diffs create mode 100644 testlabl/varunion.ml create mode 100644 testobjects/.cvsignore create mode 100644 testobjects/Exemples.exp create mode 100644 testobjects/Exemples.ml create mode 100644 testobjects/Makefile create mode 100644 testobjects/Tests.exp create mode 100644 testobjects/Tests.ml create mode 100644 tools/.cvsignore create mode 100644 tools/.depend create mode 100644 tools/Characters create mode 100644 tools/DoMake create mode 100644 tools/MakeDepend create mode 100644 tools/Makefile create mode 100644 tools/Makefile.nt create mode 100644 tools/Makefile.shared create mode 100644 tools/OCamlc-custom create mode 100644 tools/Time create mode 100644 tools/addlabels.ml create mode 100644 tools/checkstack.c create mode 100644 tools/cleanup-header create mode 100644 tools/cvt_emit.mll create mode 100644 tools/depend.ml create mode 100644 tools/depend.mli create mode 100644 tools/dumpapprox.ml create mode 100644 tools/dumpobj.ml create mode 100644 tools/keywords.r create mode 100644 tools/lexer299.mll create mode 100644 tools/lexer301.mll create mode 100644 tools/magic create mode 100644 tools/make-opcodes create mode 100755 tools/make-package-macosx create mode 100644 tools/objinfo.ml create mode 100755 tools/ocaml-objcopy-macosx create mode 100644 tools/ocaml299to3.ml create mode 100644 tools/ocamlcp.ml create mode 100644 tools/ocamldep.ml create mode 100644 tools/ocamlmklib.mlp create mode 100644 tools/ocamlmktop.ml create mode 100644 tools/ocamlmktop.tpl create mode 100644 tools/ocamlprof.ml create mode 100755 tools/ocamlsize create mode 100644 tools/primreq.ml create mode 100644 tools/profiling.ml create mode 100644 tools/profiling.mli create mode 100644 tools/scrapelabels.ml create mode 100644 toplevel/expunge.ml create mode 100644 toplevel/genprintval.ml create mode 100644 toplevel/genprintval.mli create mode 100644 toplevel/opttopdirs.ml create mode 100644 toplevel/opttopdirs.mli create mode 100644 toplevel/opttoploop.ml create mode 100644 toplevel/opttoploop.mli create mode 100644 toplevel/opttopmain.ml create mode 100644 toplevel/opttopmain.mli create mode 100644 toplevel/opttopstart.ml create mode 100644 toplevel/topdirs.ml create mode 100644 toplevel/topdirs.mli create mode 100644 toplevel/toplevellib.mllib create mode 100644 toplevel/toploop.ml create mode 100644 toplevel/toploop.mli create mode 100644 toplevel/topmain.ml create mode 100644 toplevel/topmain.mli create mode 100644 toplevel/topstart.ml create mode 100644 toplevel/trace.ml create mode 100644 toplevel/trace.mli create mode 100644 typing/annot.mli create mode 100644 typing/btype.ml create mode 100644 typing/btype.mli create mode 100644 typing/ctype.ml create mode 100644 typing/ctype.mli create mode 100644 typing/datarepr.ml create mode 100644 typing/datarepr.mli create mode 100644 typing/env.ml create mode 100644 typing/env.mli create mode 100644 typing/ident.ml create mode 100644 typing/ident.mli create mode 100644 typing/includeclass.ml create mode 100644 typing/includeclass.mli create mode 100644 typing/includecore.ml create mode 100644 typing/includecore.mli create mode 100644 typing/includemod.ml create mode 100644 typing/includemod.mli create mode 100644 typing/mtype.ml create mode 100644 typing/mtype.mli create mode 100644 typing/oprint.ml create mode 100644 typing/oprint.mli create mode 100644 typing/outcometree.mli create mode 100644 typing/parmatch.ml create mode 100644 typing/parmatch.mli create mode 100644 typing/path.ml create mode 100644 typing/path.mli create mode 100644 typing/predef.ml create mode 100644 typing/predef.mli create mode 100644 typing/primitive.ml create mode 100644 typing/primitive.mli create mode 100644 typing/printtyp.ml create mode 100644 typing/printtyp.mli create mode 100644 typing/stypes.ml create mode 100644 typing/stypes.mli create mode 100644 typing/subst.ml create mode 100644 typing/subst.mli create mode 100644 typing/typeclass.ml create mode 100644 typing/typeclass.mli create mode 100644 typing/typecore.ml create mode 100644 typing/typecore.mli create mode 100644 typing/typedecl.ml create mode 100644 typing/typedecl.mli create mode 100644 typing/typedtree.ml create mode 100644 typing/typedtree.mli create mode 100644 typing/typemod.ml create mode 100644 typing/typemod.mli create mode 100644 typing/types.ml create mode 100644 typing/types.mli create mode 100644 typing/typetexp.ml create mode 100644 typing/typetexp.mli create mode 100644 typing/unused_var.ml create mode 100644 typing/unused_var.mli create mode 100644 utils/.cvsignore create mode 100644 utils/ccomp.ml create mode 100644 utils/ccomp.mli create mode 100644 utils/clflags.ml create mode 100644 utils/clflags.mli create mode 100644 utils/config.mlbuild create mode 100644 utils/config.mli create mode 100644 utils/config.mlp create mode 100644 utils/consistbl.ml create mode 100644 utils/consistbl.mli create mode 100644 utils/misc.ml create mode 100644 utils/misc.mli create mode 100644 utils/tbl.ml create mode 100644 utils/tbl.mli create mode 100644 utils/terminfo.ml create mode 100644 utils/terminfo.mli create mode 100644 utils/warnings.ml create mode 100644 utils/warnings.mli create mode 100644 win32caml/Makefile create mode 100644 win32caml/editbuffer.c create mode 100644 win32caml/editbuffer.h create mode 100644 win32caml/history.c create mode 100644 win32caml/history.h create mode 100644 win32caml/inria.h create mode 100644 win32caml/inriares.h create mode 100644 win32caml/libgraph.h create mode 100644 win32caml/menu.c create mode 100644 win32caml/ocaml.c create mode 100644 win32caml/ocaml.ico create mode 100644 win32caml/ocaml.rc create mode 100644 win32caml/resource.h create mode 100644 win32caml/startocaml.c create mode 100644 yacc/.cvsignore create mode 100644 yacc/Makefile create mode 100644 yacc/Makefile.nt create mode 100644 yacc/closure.c create mode 100644 yacc/defs.h create mode 100644 yacc/error.c create mode 100644 yacc/lalr.c create mode 100644 yacc/lr0.c create mode 100644 yacc/main.c create mode 100644 yacc/mkpar.c create mode 100644 yacc/output.c create mode 100644 yacc/reader.c create mode 100644 yacc/skeleton.c create mode 100644 yacc/symtab.c create mode 100644 yacc/verbose.c create mode 100644 yacc/warshall.c diff --git a/Changes b/Changes new file mode 100644 index 0000000..5584518 --- /dev/null +++ b/Changes @@ -0,0 +1,2390 @@ +Objective Caml 3.11.0: +---------------------- + +(Changes that can break existing programs are marked with a "*" ) + +Language features: +- Addition of lazy patterns: "lazy " matches suspensions whose values, + after forcing, match the pattern . +- Introduction of private abbreviation types "type t = private ", + for abstracting the actual manifest type in type abbreviations. +- Subtyping is now allowed between a private abbreviation and its definition, + and between a polymorphic method and its monomorphic instance. + +Compilers: +- The file name for a compilation unit should correspond to a valid + identifier (Otherwise dynamic linking and other things can fail, and + a warning is emitted.) +* Revised -output-obj: the output name must now be provided; its + extension must be one of .o/.obj, .so/.dll, or .c for the + bytecode compiler. The compilers can now produce a shared library + (with all the needed -ccopts/-ccobjs options) directly. +- -dtypes renamed to -annot, records (in .annot files) which function calls + are tail calls. +- All compiler error messages now include a file name and location, for + better interaction with Emacs' compilation mode. +- Optimized compilation of "lazy e" when the argument "e" is + already evaluated. +- Optimized compilation of equality tests with a variant constant constructor. +- The -dllib options recorded in libraries are no longer ignored when + -use_runtime or -use_prims is used (unless -no_auto_link is + explicitly used). +- Check that at most one of -pack, -a, -shared, -c, -output-obj is + given on the command line. +- Optimized compilation of private types as regular manifest types + (e.g. abbreviation to float, float array or record types with only + float fields). + +Native-code compiler: +- New port: Mac OS X / Intel in 64-bit mode (configure with -cc "gcc -m64"). +- A new option "-shared" to produce a plugin that can be dynamically + loaded with the native version of Dynlink. +- A new option "-nodynlink" to enable optimizations valid only for code + that is never dynlinked (no-op except for AMD64). +- More aggressive unboxing of floats and boxed integers. +- Can select which assembler and asm options to use at configuration time. + +Run-time system: +- New implementation of the page table describing the heap (two-level + array in 32 bits, sparse hashtable in 64 bits), fixes issues with address + space randomization on 64-bit OS (PR#4448). +- New "generational" API for registering global memory roots with the GC, + enables faster scanning of global roots. + (The functions are caml_*_generational_global_root in .) +- New function "caml_raise_with_args" to raise an exception with several + arguments from C. +- Changes in implementation of dynamic linking of C code: + under Win32, use Alain Frisch's flexdll implementation of the dlopen + API; under MacOSX, use dlopen API instead of MacOSX bundle API. +- Programs may now choose a first-fit allocation policy instead of + the default next-fit. First-fit reduces fragmentation but is + slightly slower in some cases. + +Standard library: +- Parsing library: new function "set_trace" to programmatically turn + on or off the printing of a trace during parsing. +- Printexc library: new functions "print_backtrace" and "get_backtrace" + to obtain a stack backtrace of the most recently raised exception. + New function "record_backtrace" to turn the exception backtrace mechanism + on or off from within a program. +- Scanf library: fine-tuning of meta format implementation; + fscanf behaviour revisited: only one input buffer is allocated for any + given input channel; + the %n conversion does not count a lookahead character as read. + +Other libraries: +- Dynlink: on some platforms, the Dynlink library is now available in + native code. The boolean Dynlink.is_native allows the program to + know whether it has been compiled in bytecode or in native code. +- Bigarrays: added "unsafe_get" and "unsafe_set" + (non-bound-checking versions of "get" and "set"). +- Bigarrays: removed limitation "array dimension < 2^31". +- Labltk: added support for TK 8.5. +- Num: added conversions between big_int and int32, nativeint, int64. + More efficient implementation of Num.quo_num and Num.mod_num. +- Threads: improved efficiency of mutex and condition variable operations; + improved interaction with Unix.fork (PR#4577). +- Unix: added getsockopt_error returning type Unix.error. + Added support for TCP_NODELAY and IPV6_ONLY socket options. +- Win32 Unix: "select" now supports all kinds of file descriptors. + Improved emulation of "lockf" (PR#4609). + +Tools: +- ocamldebug now supported under Windows (MSVC and Mingw ports), + but without the replay feature. (Contributed by Dmitry Bely + and Sylvain Le Gall at OCamlCore with support from Lexifi.) +- ocamldoc: new option -no-module-constraint-filter to include functions + hidden by signature constraint in documentation. +- ocamlmklib and ocamldep.opt now available under Windows ports. +- ocamlmklib no longer supports the -implib option. +- ocamlnat: an experimental native toplevel (not built by default). + +Camlp4: +* programs linked with camlp4lib.cma now also need dynlink.cma. + +Bug fixes: +- Major GC and heap compaction: fixed bug involving lazy values and + out-of-heap pointers. +- PR#3915: updated most man pages. +- PR#4261: type-checking of recursive modules +- PR#4308: better stack backtraces for "spontaneous" exceptions such as + Stack_overflow, Out_of_memory, etc. +- PR#4338: Str.global_substitute, Str.global_replace and the Str.*split* + functions are now tail-recursive. +- PR#4503: fixed bug in classify_float on ARM. +- PR#4512: type-checking of recursive modules +- PR#4517: crash in ocamllex-generated lexers. +- PR#4542: problem with return value of Unix.nice. +- PR#4557: type-checking of recursive modules. +- PR#4562: strange %n semantics in scanf. +- PR#4564: add note "stack is not executable" to object files generated by + ocamlopt (Linux/x86, Linux/AMD64). +- PR#4566: bug in Ratio.approx_ratio_fix and Num.approx_num_fix. +- PR#4582: clarified the documentation of functions in the String module. +- PR#4583: stack overflow in "ocamlopt -g" during closure conversion pass. +- PR#4585: ocamldoc and "val virtual" declarations. +- PR#4587: ocamldoc and escaped @ characters. +- PR#4605: Buffer.add_substitute was sometime wrong when target string had + backslashes. +- PR#4614: Inconsistent declaration of CamlCBCmd in LablTk library. + + +Objective Caml 3.10.2: +---------------------- + +Bug fixes: +- PR#1217 (partial) Typo in ocamldep man page +- PR#3952 (partial) ocamlopt: allocation problems on ARM +- PR#4339 (continued) ocamlopt: problems on HPPA +- PR#4455 str.mli not installed under Windows +- PR#4473 crash when accessing float array with polymorphic method +- PR#4480 runtime would not compile without gcc extensions +- PR#4481 wrong typing of exceptions with object arguments +- PR#4490 typo in error message +- Random crash on 32-bit when major_heap_increment >= 2^22 +- Big performance bug in Weak hashtables +- Small bugs in the make-package-macosx script +- Bug in typing of polymorphic variants (reported on caml-list) + +Objective Caml 3.10.1: +---------------------- + +Bug fixes: +- PR#3830 small bugs in docs +- PR#4053 compilers: improved compilation time for large variant types +- PR#4174 ocamlopt: fixed ocamlopt -nopervasives +- PR#4199 otherlibs: documented a small problem in Unix.utimes +- PR#4280 camlp4: parsing of identifier (^) +- PR#4281 camlp4: parsing of type constraint +- PR#4285 runtime: cannot compile under AIX +- PR#4286 ocamlbuild: cannot compile under AIX and SunOS +- PR#4288 compilers: including a functor application with side effects +- PR#4295 camlp4 toplevel: synchronization after an error +- PR#4300 ocamlopt: crash with backtrace and illegal array access +- PR#4302 camlp4: list comprehension parsing problem +- PR#4304 ocamlbuild: handle -I correctly +- PR#4305 stdlib: alignment of Arg.Symbol +- PR#4307 camlp4: assertion failure +- PR#4312 camlp4: accept "let _ : int = 1" +- PR#4313 ocamlbuild: -log and missing directories +- PR#4315 camlp4: constraints in classes +- PR#4316 compilers: crash with recursive modules and Lazy +- PR#4318 ocamldoc: installation problem with Cygwin (tentative fix) +- PR#4322 ocamlopt: stack overflow under Windows +- PR#4325 compilers: wrong error message for unused var +- PR#4326 otherlibs: marshal Big_int on win64 +- PR#4327 ocamlbuild: make emacs look for .annot in _build directory +- PR#4328 camlp4: stack overflow with nil nodes +- PR#4331 camlp4: guards on fun expressions +- PR#4332 camlp4: parsing of negative 32/64 bit numbers +- PR#4336 compilers: unsafe recursive modules +- PR#4337 (note) camlp4: invalid character escapes +- PR#4339 ocamlopt: problems on HP-UX (tentative fix) +- PR#4340 camlp4: wrong pretty-printing of optional arguments +- PR#4348 ocamlopt: crash on Mac Intel +- PR#4349 camlp4: bug in private type definitions +- PR#4350 compilers: type errors with records and polymorphic variants +- PR#4352 compilers: terminal recursion under Windows (tentative fix) +- PR#4354 ocamlcp: mismatch with ocaml on polymorphic let +- PR#4358 ocamlopt: float constants wrong on ARM +- PR#4360 ocamldoc: string inside comment +- PR#4365 toplevel: wrong pretty-printing of polymorphic variants +- PR#4373 otherlibs: leaks in win32unix +- PR#4374 otherlibs: threads module not initialized +- PR#4375 configure: fails to build on bytecode-only architectures +- PR#4377 runtime: finalisation of infix pointers +- PR#4378 ocamlbuild: typo in plugin.ml +- PR#4379 ocamlbuild: problem with plugins under Windows +- PR#4382 compilers: typing of polymorphic record fields +- PR#4383 compilers: including module with private type +- PR#4385 stdlib: Int32/Int64.format are unsafe +- PR#4386 otherlibs: wrong signal numbers with Unix.sigprocmask etc. +- PR#4387 ocamlbuild: build directory not used properly +- PR#4392 ocamldep: optional argument of class +- PR#4394 otherlibs: infinite loops in Str +- PR#4397 otherlibs: wrong size for flag arrays in win32unix +- PR#4402 ocamldebug: doesn't work with -rectypes +- PR#4410 ocamlbuild: problem with plugin and -build +- PR#4411 otherlibs: crash with Unix.access under Windows +- PR#4412 stdlib: marshalling broken on 64 bit architectures +- PR#4413 ocamlopt: crash on AMD64 with out-of-bound access and reraise +- PR#4417 camlp4: pretty-printing of unary minus +- PR#4419 camlp4: problem with constraint in type class +- PR#4426 compilers: problem with optional labels +- PR#4427 camlp4: wrong pretty-printing of lists of functions +- PR#4433 ocamlopt: fails to build on MacOSX 10.5 +- PR#4435 compilers: crash with objects +- PR#4439 fails to build on MacOSX 10.5 +- PR#4441 crash when build on sparc64 linux +- PR#4442 stdlib: crash with weak pointers +- PR#4446 configure: fails to detect X11 on MacOSX 10.5 +- PR#4448 runtime: huge page table on 64-bit architectures +- PR#4450 compilers: stack overflow with recursive modules +- PR#4470 compilers: type-checking of recursive modules too restrictive +- PR#4472 configure: autodetection of libX11.so on Fedora x86_64 +- printf: removed (partially implemented) positional specifications +- polymorphic < and <= comparisons: some C compiler optimizations + were causing incorrect results when arguments are incomparable + +New features: +- made configure script work on PlayStation 3 +- ARM port: brought up-to-date for Debian 4.0 (Etch) +- many other small changes and bugfixes in camlp4, ocamlbuild, labltk, + emacs files + + +Objective Caml 3.10.0: +---------------------- + +(Changes that can break existing programs are marked with a "*" ) + +Language features: +- Added virtual instance variables in classes "val virtual v : t" +* Changed the behaviour of instance variable overriding; the new + definition replaces the old one, rather than creating a new + variable. + +New tools: +- ocamlbuild: compilation manager for OCaml applications and libraries. + See draft documentation at http://gallium.inria.fr/~pouillar/ +* Camlp4: heavily revised implementation, new API. + +New ports: +- MacOS X PowerPC 64 bits. +- MS Windows 64 bits (x64) using the Microsoft PSDK toolchain. +- MS Windows 32 bits using the Visual Studio 2005 toolchain. + +Compilers: +- Faster type-checking of functor applications. +- Referencing an interface compiled with -rectypes from a module + not compiled with -rectypes is now an error. +- Revised the "fragile matching" warning. + +Native-code compiler: +- Print a stack backtrace on an uncaught exception. + (Compile and link with ocamlopt -g; execute with OCAMLRUNPARAM=b.) + Supported on Intel/AMD in 32 and 64 bits, PPC in 32 and 64 bits. +- Stack overflow detection on MS Windows 32 bits (courtesy O. Andrieu). +- Stack overflow detection on MacOS X PPC and Intel. +- Intel/AMD 64 bits: generate position-independent code by default. +- Fixed bug involving -for-pack and missing .cmx files (PR#4124). +- Fixed bug causing duplication of literals (PR#4152). + +Run-time system: +- C/Caml interface functions take "char const *" arguments + instead of "char *" when appropriate. +- Faster string comparisons (fast case if strings are ==). + +Standard library: +- Refined typing of format strings (type format6). +- Printf, Format: new function ifprintf that consumes its arguments + and prints nothing (useful to print conditionally). +- Scanf: + new function format_from_string to convert a string to a format string; + new %r conversion to accomodate user defined scanners. +- Filename: improved Win32 implementation of Filename.quote. +- List: List.nth now tail-recursive. +- Sys: added Sys.is_directory. Some functions (e.g. Sys.command) that + could incorrectly raise Sys_io_blocked now raise Sys_error as intended. +- String and Char: the function ``escaped'' now escapes all the characters + especially handled by the compiler's lexer (PR#4220). + +Other libraries: +- Bigarray: mmap_file takes an optional argument specifying + the start position of the data in the mapped file. +- Dynlink: now defines only two modules, Dynlink and Dynlinkaux (internal), + reducing risks of name conflicts with user modules. +- Labltk under Win32: now uses Tcl/Tk 8.4 instead of 8.3 by default. +- VM threads: improved performance of I/O operations (less polling). +- Unix: new function Unix.isatty. +- Unix emulation under Win32: + fixed incorrect error reporting in several functions (PR#4097); + better handling of channels opened on sockets (PR#4098); + fixed GC bug in Unix.system (PR#4112). + +Documentation generator (OCamldoc): +- correctly handle '?' in value names (PR#4215) +- new option -hide-warnings not to print ocamldoc warnings + +Lexer generator (ocamllex): improved error reporting. + +License: fixed a typo in the "special exception" to the LGPL. + + +Objective Caml 3.09.3: +---------------------- + +Bug fixes: +- ocamldoc: -using modtype constraint to filter module elements displayed + in doc PR#4016 +- ocamldoc: error in merging of top dependencies of modules PR#4007 +- ocamldoc: -dot-colors has no effect PR#3981 +- ocamdloc: missing crossref in text from intro files PR#4066 +- compilers: segfault with recursive modules PR#4008 +- compilers: infinite loop when compiling objects PR#4018 +- compilers: bad error message when signature mismatch PR#4001 +- compilers: infinite loop with -rectypes PR#3999 +- compilers: contravariance bug in private rows +- compilers: unsafe cast with polymorphic exception PR#4002 +- native compiler: bad assembly code generated for AMD64 PR#4067 +- native compiler: stack alignment problems on MacOSX/i386 PR#4036 +- stdlib: crash in marshalling PR#4030 +- stdlib: crash when closing a channel twice PR#4039 +- stdlib: memory leak in Sys.readdir PR#4093 +- C interface: better definition of CAMLreturn PR#4068 +- otherlibs/unix: crash in gethostbyname PR#3043 +- tools: subtle problem with unset in makefile PR#4048 +- camlp4: install pa_o_fast.o PR#3812 +- camlp4: install more modules PR#3689 + +New features: +- ocamldoc: name resolution in cross-referencing {!name}: if name is not + found, then it is searched in the parent module/class, and in the parent + of the parent, and so on until it is found. +- ocamldoc: new option -short-functors to use a short form to display + functors in html generator PR#4017 +- ocamlprof: added "-version" option + + + +Objective Caml 3.09.2: +---------------------- + +Bug fixes: +- Makefile: problem with "make world.opt" PR#3954 +- compilers: problem compiling several modules with one command line PR#3979 +- compilers,ocamldoc: error message that Emacs cannot parse +- compilers: crash when printing type error PR#3968 +- compilers: -dtypes wrong for monomorphic type variables PR#3894 +- compilers: wrong warning on optional arguments PR#3980 +- compilers: crash when wrong use of type constructor in let rec PR#3976 +- compilers: better wording of "statement never returns" warning PR#3889 +- runtime: inefficiency of signal handling PR#3990 +- runtime: crashes with I/O in multithread programs PR#3906 +- camlp4: empty file name in error messages PR#3886 +- camlp4: stack overflow PR#3948 +- otherlibs/labltk: ocamlbrowser ignores its command line options PR#3961 +- otherlibs/unix: Unix.times wrong under Mac OS X PR#3960 +- otherlibs/unix: wrong doc for execvp and execvpe PR#3973 +- otherlibs/win32unix: random crash in Unix.stat PR#3998 +- stdlib: update_mod not found under Windows PR#3847 +- stdlib: Filename.dirname/basename wrong on Win32 PR#3933 +- stdlib: incomplete documentation of Pervasives.abs PR#3967 +- stdlib: Printf bugs PR#3902, PR#3955 +- tools/checkstack.c: missing include +- yacc: crash when given argument "-" PR#3956 + +New features: +- ported to MacOS X on Intel PR#3985 +- configure: added support for GNU Hurd PR#3991 + +Objective Caml 3.09.1: +---------------------- + +Bug fixes: +- compilers: raise not_found with -principal PR#3855 +- compilers: assert failure in typeclass.cml PR#3856 +- compilers: assert failure in typing/ctype.ml PR#3909 +- compilers: fatal error exception Ctype.Unify PR#3918 +- compilers: spurious warning Y in objects PR#3868 +- compilers: spurious warning Z on loop index PR#3907 +- compilers: error message that emacs cannot parse +- ocamlopt: problems with -for-pack/-pack PR#3825, PR#3826, PR#3919 +- ocamlopt: can't produce shared libraries on x86_64 PR#3869, PR#3924 +- ocamlopt: float alignment problem on SPARC PR#3944 +- ocamlopt: can't compile on MIPS PR#3936 +- runtime: missing dependence for ld.conf +- runtime: missing dependence for .depend.nt PR#3880 +- runtime: memory leak in caml_register_named_value PR#3940 +- runtime: crash in Marshal.to_buffer PR#3879 +- stdlib: Sys.time giving wrong results on Mac OS X PR#3850 +- stdlib: Weak.get_copy causing random crashes in rare cases +- stdlib, debugger, labltk: use TMPDIR if set PR#3895 +- stdlib: scanf bug on int32 and nativeint PR#3932 +- camlp4: mkcamlp4 option parsing problem PR#3941 +- camlp4: bug in pretty-printing of lazy/assert/new +- camlp4: update the unmaintained makefile for _loc name +- ocamldoc: several fixes see ocamldoc/Changes.txt +- otherlibs/str: bug in long sequences of alternatives PR#3783 +- otherlibs/systhreads: deadlock in Windows PR#3910 +- tools: update dumpobj to handle new event format PR#3873 +- toplevel: activate warning Y in toplevel PR#3832 + +New features: +- otherlibs/labltk: browser uses menu bars instead of menu buttons + +Objective Caml 3.09.0: +---------------------- + +(Changes that can break existing programs are marked with a "*" ) + +Language features: +- Introduction of private row types, for abstracting the row in object + and variant types. + +Type checking: +- Polymorphic variants with at most one constructor [< `A of t] are no + longer systematically promoted to the exact type [`A of t]. This was + more confusing than useful, and created problems with private row + types. + +Both compilers: +- Added warnings 'Y' and 'Z' for local variables that are bound but + never used. +- Added warning for some uses non-returning functions (e.g. raise), when they + are passed extra arguments, or followed by extra statements. +- Pattern matching: more prudent compilation in case of guards; fixed PR#3780. +- Compilation of classes: reduction in size of generated code. +- Compilation of "module rec" definitions: fixed a bad interaction with + structure coercion (to a more restrictive signature). + +Native-code compiler (ocamlopt): +* Revised implementation of the -pack option (packing of several compilation + units into one). The .cmx files that are to be packed with + "ocamlopt -pack -o P.cmx" must be compiled with "ocamlopt -for-pack P". + In exchange for this additional constraint, ocamlopt -pack is now + available on all platforms (no need for binutils). +* Fixed wrong evaluation order for arguments to certain inlined functions. +- Modified code generation for "let rec ... and ..." to reduce compilation + time (which was quadratic in the number of mutually-recursive functions). +- x86 port: support tail-calls for functions with up to 21 arguments. +- AMD64 port, Linux: recover from system stack overflow. +- Sparc port: more portable handling of out-of-bound conditions + on systems other than Solaris. + +Standard library: +- Pervasives: faster implementation of close_in, close_out. + set_binary_mode_{out,in} now working correctly under Cygwin. +- Printf: better handling of partial applications of the printf functions. +- Scanf: new function sscanf_format to read a format from a + string. The type of the resulting format is dynamically checked and + should be the type of the template format which is the second argument. +- Scanf: no more spurious lookahead attempt when the end of file condition + is set and a correct token has already been read and could be returned. + +Other libraries: +- System threads library: added Thread.sigmask; fixed race condition + in signal handling. +- Bigarray library: fixed bug in Array3.of_array. +- Unix library: use canonical signal numbers in results of Unix.wait*; + hardened Unix.establish_server against EINTR errors. + +Run-time system: +- Support platforms where sizeof(void *) = 8 and sizeof(long) = 4. +- Improved and cleaned up implementation of signal handling. + +Replay debugger: +- Improved handling of locations in source code. + +OCamldoc: +- extensible {foo } syntax +- user can give .txt files on the command line, containing ocamldoc formatted + text, to be able to include bigger texts out of source files +- -o option is now used by the html generator to indicate the prefix + of generated index files (to avoid conflict when a Index module exists + on case-insensitive file systems). + +Miscellaneous: +- Configuration information is installed in `ocamlc -where`/Makefile.config + and can be used by client Makefiles or shell scripts. + +Objective Caml 3.08.4: +---------------------- + +New features: +- configure: find X11 config in some 64-bit Linux distribs +- ocamldoc: (**/**) can be canceled with another (**/**) PR#3665 +- graphics: added resize_window +- graphics: check for invalid arguments to drawing primitives PR#3595 +- ocamlbrowser: use windows subsystem on mingw + +Bug fixes: +- ocamlopt: code generation problem on AMD64 PR#3640 +- wrong code generated for some classes PR#3576 +- fatal error when compiling some OO code PR#3745 +- problem with comparison on constant constructors PR#3608 +- camlp4: cryptic error message PR#3592 +- camlp4: line numbers in multi-line antiquotations PR#3549 +- camlp4: problem with make depend +- camlp4: parse error with :> PR#3561 +- camlp4: ident conversion problem with val/contents/contents__ +- camlp4: several small parsing problems PR#3688 +- ocamldebug: handling of spaces in executable file name PR#3736 +- emacs-mode: problem when caml-types-buffer is deleted by user PR#3704 +- ocamldoc: extra backslash in ocamldoc man page PR#3687 +- ocamldoc: improvements to HTML display PR#3698 +- ocamldoc: escaping of @ in info files +- ocamldoc: escaping of . and \ in man pages PR#3686 +- ocamldoc: better error reporting of misplaced comments +- graphics: fixed .depend file PR#3558 +- graphics: segfault with threads and graphics PR#3651 +- nums: several bugs: PR#3718, PR#3719, others +- nums: inline asm problems with gcc 4.0 PR#3604, PR#3637 +- threads: problem with backtrace +- unix: problem with getaddrinfo PR#3565 +- stdlib: documentation of Int32.rem and Int64.rem PR#3573 +- stdlib: documentation of List.rev_map2 PR#3685 +- stdlib: wrong order in Map.fold PR#3607 +- stdlib: documentation of maximum float array length PR#3714 +- better detection of cycles when using -rectypes +- missing case of module equality PR#3738 +- better error messages for unbound type variables +- stack overflow while printing type error message PR#3705 +- assert failure when typing some classes PR#3638 +- bug in type_approx +- better error messages related to type variance checking +- yacc: avoid name capture for idents of the Parsing module + + +Objective Caml 3.08.3: +---------------------- + +New features: +- support for ocamlopt -pack under Mac OS X (PR#2634, PR#3320) +- ignore unknown warning options for forward and backward compatibility +- runtime: export caml_compare_unordered (PR#3479) +- camlp4: install argl.* files (PR#3439) +- ocamldoc: add -man-section option +- labltk: add the "solid" relief option (PR#3343) + +Bug fixes: +- typing: fix unsoundness in type declaration variance inference. + Type parameters which are constrained must now have an explicit variant + annotation, otherwise they are invariant. This is not backward + compatible, so this might break code which either uses subtyping or + uses the relaxed value restriction (i.e. was not typable before 3.07) +- typing: erroneous partial match warning for polymorphic variants (PR#3424) +- runtime: handle the case of an empty command line (PR#3409, PR#3444) +- stdlib: make Sys.executable_name an absolute path in native code (PR#3303) +- runtime: fix memory leak in finalise.c +- runtime: auto-trigger compaction even if gc is called manually (PR#3392) +- stdlib: fix segfault in Obj.dup on zero-sized values (PR#3406) +- camlp4: correct parsing of the $ identifier (PR#3310, PR#3469) +- windows (MS tools): use link /lib instead of lib (PR#3333) +- windows (MS tools): change default install destination +- autoconf: better checking of SSE2 instructions (PR#3329, PR#3330) +- graphics: make close_graph close the X display as well as the window (PR#3312) +- num: fix big_int_of_string (empty string) (PR#3483) +- num: fix big bug on 64-bit architecture (PR#3299) +- str: better documentation of string_match and string_partial_match (PR#3395) +- unix: fix file descriptor leak in Unix.accept (PR#3423) +- unix: miscellaneous clean-ups +- unix: fix documentation of Unix.tm (PR#3341) +- graphics: fix problem when allocating lots of images under Windows (PR#3433) +- compiler: fix error message with -pack when .cmi is missing (PR#3028) +- cygwin: fix problem with compilation of camlheader (PR#3485) +- stdlib: Filename.basename doesn't return an empty string any more (PR#3451) +- stdlib: better documentation of Open_excl flag (PR#3450) +- ocamlcp: accept -thread option (PR#3511) +- ocamldep: handle spaces in file names (PR#3370) +- compiler: remove spurious warning in pattern-matching on variants (PR#3424) +- windows: better handling of InterpreterPath registry entry (PR#3334, PR#3432) + + +Objective Caml 3.08.2: +---------------------- + +Bug fixes: +- runtime: memory leak when unmarshalling big data structures (PR#3247) +- camlp4: incorrect line numbers in errors (PR#3188) +- emacs: xemacs-specific code, wrong call to "sit-for" +- ocamldoc: "Lexing: empty token" (PR#3173) +- unix: problem with close_process_* (PR#3191) +- unix: possible coredumps (PR#3252) +- stdlib: wrong order in Set.fold (PR#3161) +- ocamlcp: array out of bounds in profiled programs (PR#3267) +- yacc: problem with polymorphic variant types for grammar entries (PR#3033) + +Misc: +- export for caml_format_exception (PR#3080) +- clean up caml_search_exe_in_path (maybe PR#3079) +- camlp4: new function "make_lexer" for new-style locations +- unix: added missing #includes (PR#3088) + + +Objective Caml 3.08.1: +---------------------- + +Licence: +- The emacs files are now under GPL +- Slightly relaxed some conditions of the QPL + +Bug fixes: +- ld.conf now generated at compile-time instead of install-time +- fixed -pack on Windows XP (PR#2935) +- fixed Obj.tag (PR#2946) +- added support for multiple dlopen in Darwin +- run ranlib when installing camlp4 libraries (PR#2944) +- link camlp4opt with -linkall (PR#2949) +- camlp4 parsing of patterns now conforms to normal parsing (PR#3015) +- install camlp4 *.cmx files (PR#2955) +- fixed handling of linefeed in string constants in camlp4 (PR#3074) +- ocamldoc: fixed display of class parameters in HTML and LaTeX (PR#2994) +- ocamldoc: fixed display of link to class page in html (PR#2994) +- Windows toplevel GUI: assorted fixes (including PR#2932) + +Misc: +- added -v option to ocamllex +- ocamldoc: new -intf and -impl options supported (PR#3036) + +Objective Caml 3.08.0: +---------------------- + +(Changes that can break existing programs are marked with a "*" ) + +Language features: +- Support for immediate objects, i.e. objects defined without going + through a class. (Syntax is "object end".) + +Type-checking: +- When typing record construction and record patterns, can omit + the module qualification on all labels except one. I.e. + { M.l1 = ...; l2 = ... } is interpreted as { M.l1 = ...; M.l2 = ... } + +Both compilers: +- More compact compilation of classes. +- Much more efficient handling of class definitions inside functors + or local modules. +- Simpler representation for method tables. Objects can now be marshaled + between identical programs with the flag Marshal.Closures. +- Improved error messages for objects and variants. +- Improved printing of inferred module signatures (toplevel and ocamlc -i). + Recursion between type, class, class type and module definitions is now + correctly printed. +- The -pack option now accepts compiled interfaces (.cmi files) in addition + to compiled implementations (.cmo or .cmx). +* A compile-time error is signaled if an integer literal exceeds the + range of representable integers. +- Fixed code generation error for "module rec" definitions. +- The combination of options -c -o sets the name of the generated + .cmi / .cmo / .cmx files. + +Bytecode compiler: +- Option -output-obj is now compatible with Dynlink and + with embedded toplevels. + +Native-code compiler: +- Division and modulus by zero correctly raise exception Division_by_zero + (instead of causing a hardware trap). +- Improved compilation time for the register allocation phase. +- The float constant -0.0 was incorrectly treated as +0.0 on some processors. +- AMD64: fixed bugs in asm glue code for GC invocation and exception raising + from C. +- IA64: fixed incorrect code generated for "expr mod 1". +- PowerPC: minor performance tweaks for the G4 and G5 processors. + +Standard library: +* Revised handling of NaN floats in polymorphic comparisons. + The polymorphic boolean-valued comparisons (=, <, >, etc) now treat + NaN as uncomparable, as specified by the IEEE standard. + The 3-valued comparison (compare) treats NaN as equal to itself + and smaller than all other floats. As a consequence, x == y + no longer implies x = y but still implies compare x y = 0. +* String-to-integer conversions now fail if the result overflows + the range of integers representable in the result type. +* All array and string access functions now raise + Invalid_argument("index out of bounds") when a bounds check fails. + In earlier releases, different exceptions were raised + in bytecode and native-code. +- Module Buffer: new functions Buffer.sub, Buffer.nth +- Module Int32: new functions Int32.bits_of_float, Int32.float_of_bits. +- Module Map: new functions is_empty, compare, equal. +- Module Set: new function split. +* Module Gc: in-order finalisation, new function finalise_release. + +Other libraries: +- The Num library: complete reimplementation of the C/asm lowest + layer to work around potential licensing problems. + Improved speed on the PowerPC and AMD64 architectures. +- The Graphics library: improved event handling under MS Windows. +- The Str library: fixed bug in "split" functions with nullable regexps. +- The Unix library: + . Added Unix.single_write. + . Added support for IPv6. + . Bug fixes in Unix.closedir. + . Allow thread switching on Unix.lockf. + +Runtime System: +* Name space depollution: all global C identifiers are now prefixed + with "caml" to avoid name clashes with other libraries. This + includes the "external" primitives of the standard runtime. + +Ports: +- Windows ports: many improvements in the OCamlWin toplevel application + (history, save inputs to file, etc). Contributed by Christopher A. Watford. +- Native-code compilation supported for HPPA/Linux. Contributed by Guy Martin. +- Removed support for MacOS9. Mac OS 9 is obsolete and the port was not + updated since 3.05. +- Removed ocamlopt support for HPPA/Nextstep and Power/AIX. + +Ocamllex: +- #line directives in the input file are now accepted. +- Added character set concatenation operator "cset1 # cset2". + +Ocamlyacc: +- #line directives in the input file are now accepted. + +Camlp4: +* Support for new-style locations (line numbers, not just character numbers). +- See camlp4/CHANGES and camlp4/ICHANGES for more info. + + +Objective Caml 3.07: +-------------------- + +Language features: +- Experimental support for recursive module definitions + module rec A : SIGA = StructA and B : SIGB = StructB and ... +- Support for "private types", or more exactly concrete data types + with private constructors or labels. These data types can be + de-structured normally in pattern matchings, but values of these + types cannot be constructed directly outside of their defining module. +- Added integer literals of types int32, nativeint, int64 + (written with an 'l', 'n' or 'L' suffix respectively). + +Type-checking: +- Allow polymorphic generalization of covariant parts of expansive + expressions. For instance, if f: unit -> 'a list, "let x = f ()" + gives "x" the generalized type forall 'a. 'a list, instead of '_a list + as before. +- The typing of polymorphic variants in pattern matching has changed. + It is intended to be more regular, sticking to the principle of "closing + only the variants which would be otherwise incomplete". Two potential + consequences: (1) some types may be left open which were closed before, + and the resulting type might not match the interface anymore (expected to + be rare); (2) in some cases an incomplete match may be generated. +- Lots of bug fixes in the handling of polymorphism and recursion inside + types. +- Added a new "-dtypes" option to ocamlc/ocamlopt, and an emacs extension + "emacs/caml-types.el". The compiler option saves inferred type information + to file *.annot, and the emacs extension allows the user to look at the + type of any subexpression in the source file. Works even in the case + of a type error (all the types computed up to the error are available). + This new feature is also supported by ocamlbrowser. +- Disable "method is overriden" warning when the method was explicitly + redefined as virtual beforehand (i.e. not through inheritance). Typing + and semantics are unchanged. + +Both compilers: +- Added option "-dtypes" to dump detailed type information to a file. +- The "-i" option no longer generates compiled files, it only prints + the inferred types. +- The sources for the module named "Mod" can be placed either in Mod.ml or + in mod.ml. +- Compilation of "let rec" on non-functional values: tightened some checks, + relaxed some other checks. +- Fixed wrong code that was generated for "for i = a to max_int" + or "for i = a downto min_int". +- An explicit interface Mod.mli can now be provided for the module obtained + by ocamlc -pack -o Mod.cmo ... or ocamlopt -pack -o Mod.cmx ... +- Revised internal handling of source code locations, now handles + preprocessed code better. +- Pattern-matching bug on float literals fixed. +- Minor improvements on pattern-matching over variants. +- More efficient compilation of string comparisons and the "compare" function. +- More compact code generated for arrays of constants. +- Fixed GC bug with mutable record fields of type "exn". +- Added warning "E" for "fragile patterns": pattern matchings that would + not be flagged as partial if new constructors were added to the data type. + +Bytecode compiler: +- Added option -vmthread to select the threads library with VM-level + scheduling. The -thread option now selects the system threads library. + +Native-code compiler: +- New port: AMD64 (Opteron). +- Fixed instruction selection bug on expressions of the kind (raise Exn)(arg). +- Several bug fixes in ocamlopt -pack (tracking of imported modules, + command line too long). +- Signal handling bug fixed. +- x86 port: + Added -ffast-math option to use inline trigo and log functions. + Small performance tweaks for the Pentium 4. + Fixed illegal "imul" instruction generated by reloading phase. +- Sparc port: + Enhanced code generation for Sparc V8 (option -march=v8) and + Sparc V9 (option -march=v9). + Profiling support added for Solaris. +- PowerPC port: + Keep stack 16-aligned for compatibility with C calling conventions. + +Toplevel interactive system: +- Tightened interface consistency checks between .cmi files, .cm[oa] files + loaded by #load, and the running toplevel. +- #trace on mutually-recursive functions was broken, works again. +- Look for .ocamlinit file in home directory in addition to the current dir. + +Standard library: +- Match_failure and Assert_failure exceptions now report + (file, line, column), instead of (file, starting char, ending char). +- float_of_string, int_of_string: some ill-formed input strings were not + rejected. +- Added format concatenation, string_of_format, format_of_string. +- Module Arg: added new option handlers Set_string, Set_int, Set_float, + Symbol, Tuple. +- Module Format: tag handling is now turned off by default, + use [Format.set_tags true] to activate. +- Modules Lexing and Parsing: added better handling of positions + in source file. Added function Lexing.flush_input. +- Module Scanf: %n and %N formats to count characters / items read so far; + assorted bug fixes, %! to match end of input. New ``_'' special + flag to skip reresulting value. +- Module Format: tags are not activated by default. +- Modules Set and Map: fixed bugs causing trees to become unbalanced. +- Module Printf: less restrictive typing of kprintf. +- Module Random: better seeding; functions to generate random int32, int64, + nativeint; added support for explicit state management. +- Module Sys: added Sys.readdir for reading the contents of a directory. + +Runtime system: +- output_value/input_value: fixed bug with large blocks (>= 4 Mwords) + produced on a 64-bit platform and incorrectly read back on a 32-bit + platform. +- Fixed memory compaction bug involving input_value. +- Added MacOS X support for dynamic linking of C libraries. +- Improved stack backtraces on uncaught exceptions. +- Fixed float alignment problem on Sparc V9 with gcc 3.2. + +Other libraries: +- Dynlink: + By default, dynamically-loaded code now has access to all + modules defined by the program; new functions Dynlink.allow_only + and Dynlink.prohibit implement access control. + Fixed Dynlink problem with files generated with ocamlc -pack. + Protect against references to modules not yet fully initialized. +- LablTK/CamlTK: added support for TCL/TK 8.4. +- Str: reimplemented regexp matching engine, now less buggy, faster, + and LGPL instead of GPL. +- Graphics: fixed draw_rect and fill_rect bug under X11. +- System threads and bytecode threads libraries can be both installed. +- System threads: better implementation of Thread.exit. +- Bytecode threads: fixed two library initialization bugs. +- Unix: make Unix.openfile blocking to account for named pipes; + GC bug in Unix.*stat fixed; fixed problem with Unix.dup2 on Windows. + +Ocamllex: +- Can name parts of the matched input text, e.g. + "0" (['0'-'7']+ as s) { ... s ... } + +Ocamldebug: +- Handle programs that run for more than 2^30 steps. + +Emacs mode: +- Added file caml-types.el to interactively display the type information + saved by option -dtypes. + +Win32 ports: +- Cygwin port: recognize \ as directory separator in addition to / +- MSVC port: ocamlopt -pack works provided GNU binutils are installed. +- Graphics library: fixed bug in Graphics.blit_image; improved event handling. + +OCamldoc: +- new ty_code field for types, to keep code of a type (with option -keep-code) +- new ex_code field for types, to keep code of an exception + (with option -keep-code) +- some fixes in html generation +- don't overwrite existing style.css file when generating HTML +- create the ocamldoc.sty file when generating LaTeX (if nonexistent) +- man pages are now installed in man/man3 rather than man/mano +- fix: empty [] in generated HTML indexes + + +Objective Caml 3.06: +-------------------- + +Type-checking: +- Apply value restriction to polymorphic record fields. + +Run-time system: +- Fixed GC bug affecting lazy values. + +Both compilers: +- Added option "-version" to print just the version number. +- Fixed wrong dependencies in .cmi generated with the -pack option. + +Native-code compiler: +- Fixed wrong return value for inline bigarray assignments. + +Libraries: +- Unix.getsockopt: make sure result is a valid boolean. + +Tools: +- ocamlbrowser: improved error reporting; small Win32 fixes. + +Windows ports: +- Fixed two problems with the Mingw port under Cygwin 1.3. + + +Objective Caml 3.05: +-------------------- + +Language features: +- Support for polymorphic methods and record fields. +- Allows _ separators in integer and float literals, e.g. 1_000_000. + +Type-checker: +- New flag -principal to enforce principality of type inference. +- Fixed subtle typing bug with higher-order functors. +- Fixed several complexity problems; changed (again) the behaviour of + simple coercions. +- Fixed various bugs with objects and polymorphic variants. +- Improved some error messages. + +Both compilers: +- Added option "-pack" to assemble several compilation units as one unit + having the given units as sub-modules. +- More precise detection of unused sub-patterns in "or" patterns. +- Warnings for ill-formed \ escapes in string and character literals. +- Protect against spaces and other special characters in directory names. +- Added interface consistency check when building a .cma or .cmxa library. +- Minor reduction in code size for class initialization code. +- Added option "-nostdlib" to ignore standard library entirely. + +Bytecode compiler: +- Fixed issue with ocamlc.opt and dynamic linking. + +Native-code compiler: +- Added link-time check for multiply-defined module names. +- Fixed GC bug related to constant constructors of polymorphic variant types. +- Fixed compilation bug for top-level "include" statements. +- PowerPC port: work around limited range for relative branches, + thus removing assembler failures on large functions. +- IA64 port: fixed code generation bug for 3-way constructor matching. + +Toplevel interactive system: +- Can load object files given on command line before starting up. +- ocamlmktop: minimized possibility of name clashes with user-provided modules. + +Run-time system: +- Minor garbage collector no longer recursive. +- Better support for lazy data in the garbage collector. +- Fixed issues with the heap compactor. +- Fixed issues with finalized Caml values. +- The type "int64" is now supported on all platforms: we use software + emulation if the C compiler doesn't support 64-bit integers. +- Support for float formats that are neither big-endian nor little-endian + (one known example: the ARM). +- Fixed bug in callback*_exn functions in the exception-catching case. +- Work around gcc 2.96 bug on RedHat 7.2 and Mandrake 8.0, 8.1 among others. +- Stub DLLs now installed in subdir stublibs/ of standard library dir. + +Standard library: +- Protect against integer overflow in sub-string and sub-array bound checks. +- New module Complex implementing arithmetic over complex numbers. +- New module Scanf implementing format-based scanning a la scanf() in C. +- Module Arg: added alternate entry point Arg.parse_argv. +- Modules Char, Int32, Int64, Nativeint, String: added type "t" and function + "compare" so that these modules can be used directly with e.g. Set.Make. +- Module Digest: fixed issue with Digest.file on large files (>= 1Gb); + added Digest.to_hex. +- Module Filename: added Filename.open_temp_file to atomically create and + open the temp file; improved security of Filename.temp_file. +- Module Genlex: allow _ as first character of an identifier. +- Module Lazy: more efficient implementation. +- Module Lexing: improved performances for very large tokens. +- Module List: faster implementation of sorting functions. +- Module Printf: + added %S and %C formats (quoted, escaped strings and characters); + added kprintf (calls user-specified continuation on formatted string). +- Module Queue: faster implementation (courtesy of François Pottier). +- Module Random: added Random.bool. +- Module Stack: added Stack.is_empty. +- Module Pervasives: + added sub-module LargeFile to support files larger than 1Gb + (file offsets are int64 rather than int); + opening in "append" mode automatically sets "write" mode; + files are now opened in close-on-exec mode; + string_of_float distinguishes its output from a plain integer; + faster implementation of input_line for long lines. +- Module Sys: + added Sys.ocaml_version containing the OCaml version number; + added Sys.executable_name containing the (exact) path of the + file being executable; + Sys.argv.(0) is now unchanged w.r.t. what was provided as 0-th argument + by the shell. +- Module Weak: added weak hash tables. + +Other libraries: +- Bigarray: + support for bigarrays of complex numbers; + added functions Genarray.dims, + {Genarray,Array1,Array2,Array3}.{kind,layout}. +- Dynlink: fixed bug with loading of mixed-mode Caml/C libraries. +- LablTK: + now supports also the CamlTK API (no labels); + support for Activate and Deactivate events; + support for virtual events; + added UTF conversion; + export the tcl interpreter as caml value, to avoid DLL dependencies. +- Unix: + added sub-module LargeFile to support files larger than 1Gb + (file offsets are int64 rather than int); + added POSIX opening flags (O_NOCTTY, O_*SYNC); + use reentrant functions for gethostbyname and gethostbyaddr when available; + fixed bug in Unix.close_process and Unix.close_process_full; + removed some overhead in Unix.select. + +Tools: +- ocamldoc (the documentation generator) is now part of the distribution. +- Debugger: now supports the option -I +dir. +- ocamllex: supports the same identifiers as ocamlc; warns for + bad \ escapes in strings and characters. +- ocamlbrowser: + recenter the module boxes when showing a cross-reference; + include the current directory in the ocaml path. + +Windows port: +- Can now compile with Mingw (the GNU compilers without the Cygwin + runtime library) in addition to MSVC. +- Toplevel GUI: wrong filenames were given to #use and #load commands; + read_line() was buggy for short lines (2 characters or less). +- OCamlBrowser: now fully functional. +- Graphics library: fixed several bugs in event handling. +- Threads library: fixed preemption bug. +- Unix library: better handling of the underlying differences between + sockets and regular file descriptors; + added Unix.lockf and a better Unix.rename (thanks to Tracy Camp). +- LablTk library: fixed a bug in Fileinput + + +Objective Caml 3.04: +-------------------- + +Type-checker: +- Allowed coercing self to the type of the current class, avoiding + an obscure error message about "Self type cannot be unified..." + +Both compilers: +- Use OCAMLLIB environment variable to find standard library, falls + back on CAMLLIB if not defined. +- Report out-of-range ASCII escapes in character or string literals + such as "\256". + +Byte-code compiler: +- The -use-runtime and -make-runtime flags are back by popular demand + (same behavior as in 3.02). +- Dynamic loading (of the C part of mixed Caml/C libraries): arrange that + linking in -custom mode uses the static libraries for the C parts, + not the shared libraries, for maximal robustness and compatibility with + 3.02. + +Native-code compiler: +- Fixed bug in link-time consistency checking. + +Tools: +- ocamlyacc: added parser debugging support (set OCAMLRUNPARAM=p to get + a trace of the pushdown automaton actions). +- ocamlcp: was broken in 3.03 (Sys_error), fixed. + +Run-time system: +- More work on dynamic loading of the C part of mixed Caml/C libraries. +- On uncaught exception, flush output channels before printing exception + message and backtrace. +- Corrected several errors in exception backtraces. + +Standard library: +- Pervasives: integer division and modulus are now fully specified + on negative arguments (with round-towards-zero semantics). +- Pervasives.float_of_string: now raises Failure on ill-formed input. +- Pervasives: added useful float constants max_float, min_float, epsilon_float. +- printf functions in Printf and Format: added % formats for int32, nativeint, + int64; "*" in width and precision specifications now supported + (contributed by Thorsten Ohl). +- Added Hashtbl.copy, Stack.copy. +- Hashtbl: revised resizing strategy to avoid quadratic behavior + on Hashtbl.add. +- New module MoreLabels providing labelized versions of modules + Hashtbl, Map and Set. +- Pervasives.output_value and Marshal.to_* : improved hashing strategy + for internal data structures, avoid excessive slowness on + quasi-linearly-allocated inputs. + +Other libraries: +- Num: fixed bug in big integer exponentiation (Big_int.power_*). + +Windows port: +- New GUI for interactive toplevel (Jacob Navia). +- The Graphics library is now available for stand-alone executables + (Jacob Navia). +- Unix library: improved reporting of system error codes. +- Fixed error in "globbing" of * and ? patterns on command line. + +Emacs mode: small fixes; special color highlighting for ocamldoc comments. + +License: added special exception to the LGPL'ed code (libraries and + runtime system) allowing unrestricted linking, whether static or dynamic. + + +Objective Caml 3.03 ALPHA: +-------------------------- + +Language: +- Removed built-in syntactic sugar for streams and stream patterns + [< ... >], now supported via CamlP4, which is now included in the + distribution. +- Switched the default behaviour to labels mode (labels are compulsory), + but allows omitting labels when a function application is complete. + -nolabels mode is available but deprecated for programming. + (See also scrapelabels and addlabels tools below.) +- Removed all labels in the standard libraries, except labltk. + Labelized versions are kept for ArrayLabels, ListLabels, StringLabels + and UnixLabels. "open StdLabels" gives access to the first three. +- Extended polymorphic variant type syntax, allowing union types and + row abbreviations for both sub- and super-types. #t deprecated in types. +- See the Upgrading file for how to adapt to all the changes above. + +Type-checker: +- Fixed obscure bug in module typing causing the type-checker to loop + on signatures of the form + module type M + module A: sig module type T = sig module T: M end end + module B: A.T +- Improved efficiency of module type-checking via lazy computation of + certain signature summary information. +- An empty polymorphic variant type is now an error. + +Both compilers: +- Fixed wrong code generated for "struct include M ... end" when M + contains one or several "external" declarations. + +Byte-code compiler: +- Protect against VM stack overflow caused by module initialization code + with many local variables. +- Support for dynamic loading of the C part of mixed Caml/C libraries. +- Removed the -use-runtime and -make-runtime flags, obsoleted by dynamic + loading of C libraries. + +Native-code compiler: +- Attempt to recover gracefully from system stack overflow. Currently + works on x86 under Linux and BSD. +- Alpha: work around "as" bug in Tru64 5.1. + +Toplevel environment: +- Revised printing of inferred types and evaluation results + so that an external printer (e.g. Camlp4's) can be hooked in. + +Tools: +- The CamlP4 pre-processor-pretty-printer is now included in the standard + distribution. +- New tool ocamlmklib to help build mixed Caml/C libraries. +- New tool scrapelabels and addlabels, to either remove (non-optional) + labels in interfaces, or automatically add them in the definitions. + They provide easy transition from classic mode ocaml 3.02 sources, + depending on whether you want to keep labels or not. +- ocamldep: added -pp option to handle preprocessed source files. + +Run-time system: +- Support for dynamic loading of the C part of mixed Caml/C libraries. + Currently works under Linux, FreeBSD, Windows, Tru64, Solaris and Irix. +- Implemented registration of global C roots with a skip list, + runs much faster when there are many global C roots. +- Autoconfiguration script: fixed wrong detection of Mac OS X; problem + with the Sparc, gcc 3.0, and float alignment fixed. + +Standard library: +- Added Pervasives.flush_all to flush all opened output channels. + +Other libraries: +- All libraries revised to allow dynamic loading of the C part. +- Graphics under X Windows: revised event handling, should no longer lose + mouse events between two calls to wait_next_event(); wait_next_event() + now interruptible by signals. +- Bigarrays: fixed bug in marshaling of big arrays. + +Windows port: +- Fixed broken Unix.{get,set}sockopt* + + + +Objective Caml 3.02: +-------------------- + +Both compilers: +- Fixed embarrassing bug in pattern-matching compilation + (affected or-patterns containing variable bindings). +- More optimizations in pattern-matching compilation. + +Byte-code compiler: +- Protect against VM stack overflow caused by functions with many local + variables. + +Native-code compiler: +- Removed re-sharing of string literals, causes too many surprises with + in-place string modifications. +- Corrected wrong compilation of toplevel "include" statements. +- Fixed bug in runtime function "callbackN_exn". +- Signal handlers receive the conventional signal number as argument + instead of the system signal number (same behavior as with the + bytecode compiler). +- ARM port: fixed issue with immediate operand overflow in large functions. + +Toplevel environment: +- User-definer printers (for #install_printer) now receive as first argument + the pretty-printer formatter where to print their second argument. + Old printers (with only one argument) still supported for backward + compatibility. + +Standard library: +- Module Hashtbl: added Hashtbl.fold. + +Other libraries: +- Dynlink: better error reporting in add_interfaces for missing .cmi files. +- Graphics: added more drawing functions (multiple points, polygons, + multiple lines, splines). +- Bytecode threads: the module Unix is now thread-safe, ThreadUnix is + deprecated. Unix.exec* now resets standard descriptors to blocking mode. +- Native threads: fixed a context-switch-during-GC problem causing + certain C runtime functions to fail, most notably input_value. +- Unix.inet_addr_of_string: call inet_aton() when available so as to + handle correctly the address 255.255.255.255. +- Unix: added more getsockopt and setsockopt functions to get/set + options that have values other than booleans. +- Num: added documentation for the Big_int module. + +Tools: +- ocamldep: fixed wrong dependency issue with nested modules. + +Run-time system: +- Removed floating-point error at start-up on some non-IEEE platforms + (e.g. FreeBSD prior to 4.0R). +- Stack backtrace mechanism now works for threads that terminate on + an uncaught exception. + +Auto-configuration: +- Updated config.guess and config.sub scripts, should recognize a greater + number of recent platform. + +Windows port: +- Fixed broken Unix.waitpid. Unix.file_descr can now be compared or hashed. +- Toplevel application: issue with spaces in name of stdlib directory fixed. + +MacOS 9 port: +- Removed the last traces of support for 68k + + +Objective Caml 3.01: +-------------------- + +New language features: +- Variables are allowed in "or" patterns, e.g. + match l with [t] | [_;t] -> ... t ... +- "include " to re-export all components of a + structure inside another structure. +- Variance annotation on parameters of type declarations, e.g. + type (+'a,-'b,'c) t (covariant in 'a, contravariant in 'b, invariant in 'c) + +New ports: +- Intel IA64/Itanium under Linux (including the native-code compiler). +- Cygwin under MS Windows. This port is an alternative to the earlier + Windows port of OCaml, which relied on MS compilers; the Cygwin + Windows port does not need MS Visual C++ nor MASM, runs faster + in bytecode, and has a better implementation of the Unix library, + but currently lacks threads and COM component support. + +Type-checking: +- Relaxed "monomorphic restriction" on type constructors in a + mutually-recursive type definition, e.g. the following is again allowed + type u = C of int t | D of string t and 'a t = ... +- Fixed name-capture bug in "include SIG" and "SIG with ..." constructs. +- Improved implicit subtypes built by (... :> ty), closer to intuition. +- Several bug fixes in type-checking of variants. +- Typing of polymorphic variants is more restrictive: + do not allow conjunctive types inside the same pattern matching. + a type has either an upper bound, or all its tags are in the lower bound. + This may break some programs (this breaks lablgl-0.94). + +Both compilers: +- Revised compilation of pattern matching. +- Option -I + to search a subdirectory of the standard + library directory (i.e. write "ocamlc -I +labltk" instead of + "ocamlc -I /usr/local/lib/ocaml/labltk"). +- Option -warn-error to turn warnings into errors. +- Option -where to print the location of the standard library directory. +- Assertions are now type-checked even if the -noassert option is given, + thus -noassert can no longe change the types of modules. + +Bytecode compiler and bytecode interpreter: +- Print stack backtrace when a program aborts due to an uncaught exception + (requires compilation with -g and running with ocamlrun -b or + OCAMLRUNPARAM="b=1"). + +Native-code compiler: +- Better unboxing optimizations on the int32, int64, and nativeint types. +- Tail recursion preserved for functions having more parameters than + available registers (but tail calls to other functions are still + turned off if parameters do not fit entirely in registers). +- Fixed name-capture bug in function inlining. +- Improved spilling/reloading strategy for conditionals. +- IA32, Alpha: better alignment of branch targets. +- Removed spurious dependency on the -lcurses library. + +Toplevel environment: +- Revised handling of top-level value definitions, allows reclaimation + of definitions that are shadowed by later definitions with the same names. + (E.g. "let x = ;; let x = 1;;" allows to be reclaimed.) +- Revised the tracing facility so that for standard library functions, + only calls from user code are traced, not calls from the system. +- Added a "*" prompt when within a comment. + +Runtime system: +- Fixed portability issue on bcopy() vs memmove(), affecting Linux RedHat 7.0 + in particular. +- Structural comparisons (=, <>, <, <=, >, >=, compare) reimplemented + so as to avoid overflowing the C stack. +- Input/output functions: arrange so that reads and writes on closed + in_channel or out_channel raise Sys_error immediately. + +Standard library: +- Module Gc: changed some counters to float in order to avoid overflow; + added alarms +- Module Hashtbl: added Hashtbl.replace. +- Module Int64: added bits_of_float, float_of_bits (access to IEEE 754 + representation of floats). +- Module List: List.partition now tail-rec; + improved memory behavior of List.stable_sort. +- Module Nativeint: added Nativeint.size (number of bits in a nativeint). +- Module Obj: fixed incorrect resizing of float arrays in Obj.resize. +- Module Pervasives: added float constants "infinity", "neg_infinity", "nan"; + added a "classify_float" function to test a float for NaN, infinity, etc. +- Pervasives.input_value: fixed bug affecting shared custom objects. +- Pervasives.output_value: fixed size bug affecting "int64" values. +- Pervasives.int_of_string, {Int32,Int64,Nativeint}.of_string: + fixed bug causing bad digits to be accepted without error. +- Module Random: added get_state and set_state to checkpoint the generator. +- Module Sys: signal handling functions are passed the system-independent + signal number rather than the raw system signal number whenever possible. +- Module Weak: added Weak.get_copy. + +Other libraries: +- Bigarray: added Bigarray.reshape to take a view of the elements of a + bigarray with different dimensions or number of dimensions; + fixed bug causing "get" operations to be unavailable in custom + toplevels including Bigarray. +- Dynlink: raise an error instead of crashing when the loaded module + refers to the not-yet-initialized module performing a dynlink operation. +- Bytecode threads: added a thread-safe version of the Marshal module; + fixed a rare GC bug in the thread scheduler. +- POSIX threads: fixed compilation problem with threads.cmxa. +- Both thread libraries: better tail-recursion in Event.sync. +- Num library: fixed bug in square roots (Nat.sqrt_nat, Big_int.sqrt_big_int). + +Tools: +- ocamldep: fixed missing dependencies on labels of record patterns and + record construction operations + +Win32 port: +- Unix.waitpid now implements the WNOHANG option. + +Mac OS ports: +- Mac OS X public beta is supported. +- Int64.format works on Mac OS 8/9. + + +Objective Caml 3.00: +-------------------- + +Language: +- OCaml/OLabl merger: + * Support for labeled and optional arguments for functions and classes. + * Support for variant types (sum types compared by structure). + See tutorial (chapter 2 of the OCaml manual) for more information. +- Syntactic change: "?" in stream error handlers changed to "??". +- Added exception renaming in structures (exception E = F). +- (OCaml 2.99/OLabl users only) Label syntax changed to preserve + backward compatibility with 2.0x (labeled function application + is f ~lbl:arg instead of f lbl:arg). A tool is provided to help + convert labelized programs to OCaml 3.00. + +Both compilers: +- Option -labels to select commuting label mode (labels are mandatory, + but labeled arguments can be passed in a different order than in + the definition of the function; in default mode, labels may be omitted, + but argument reordering is only allowed for optional arguments). +- Libraries (.cma and .cmxa files) now "remember" C libraries given + at library construction time, and add them back at link time. + Allows linking with e.g. just unix.cma instead of + unix.cma -custom -cclib -lunix +- Revised printing of error messages, now use Format.fprintf; no visible + difference for users, but could facilitate internationalization later. +- Fixed bug in unboxing of records containing only floats. +- Fixed typing bug involving applicative functors as components of modules. +- Better error message for inconsistencies between compiled interfaces. + +Bytecode compiler: +- New "modular" format for bytecode executables; no visible differences + for users, but will facilitate further extensions later. +- Fixed problems in signal handling. + +Native-code compiler: +- Profiling support on x86 under FreeBSD +- Open-coding and unboxing optimizations for the new integer types + int32, int64, nativeint, and for bigarrays. +- Fixed instruction selection bug with "raise" appearing in arguments + of strict operators, e.g. "1 + raise E". +- Better error message when linking incomplete/incorrectly ordered set + of .cmx files. +- Optimized scanning of global roots during GC, can reduce total running + time by up to 8% on GC-intensive programs. + +Interactive toplevel: +- Better printing of exceptions, including arguments, when possible. +- Fixed rare GC bug occurring during interpretation of scripts. +- Added consistency checks between interfaces and implementations + during #load. + +Run-time system: +- Added support for "custom" heap blocks (heap blocks carrying + C functions for finalization, comparison, hashing, serialization + and deserialization). +- Support for finalisation functions written in Caml. + +Standard library: +- New modules Int32, Int64, Nativeint for 32-bit, 64-bit and + platform-native integers +- Module Array: added Array.sort, Array.stable_sort. +- Module Gc: added Gc.finalise to attach Caml finalisation functions to + arbitrary heap-allocated data. +- Module Hashtbl: do not bomb when resizing very large table. +- Module Lazy: raise Lazy.Undefined when a lazy evaluation needs itself. +- Module List: added List.sort, List.stable_sort; fixed bug in List.rev_map2. +- Module Map: added mapi (iteration with key and data). +- Module Set: added iterators for_all, exists, filter, partition. +- Module Sort: still here but deprecated in favor of new sorting functions + in Array and List. +- Module Stack: added Stack.top +- Module String: fixed boundary condition on String.rindex_from +- Added labels on function arguments where appropriate. + +New libraries and tools: +- ocamlbrowser: graphical browser for OCaml sources and compiled interfaces, + supports cross-referencing, editing, running the toplevel. +- LablTK: GUI toolkit based on TK, using labeled and optional arguments, + easier to use than CamlTK. +- Bigarray: large, multi-dimensional numerical arrays, facilitate + interfacing with C/Fortran numerical code, efficient support for + advanced array operations such as slicing and memory-mapping of files. + +Other libraries: +- Bytecode threads: timer-based preemption was broken, works back again; + fixed bug in Pervasives.input_line; exported Thread.yield. +- System threads: several GC / reentrancy bugs fixed in buffered I/O + and Unix I/O; revised Thread.join implementation for strict POSIX + conformance; exported Thread.yield. +- Graphics: added support for double buffering; added, current_x, current_y, + rmoveto, rlineto, and draw_rect. +- Num: fixed bug in Num.float_of_num. +- Str: worked around potential symbol conflicts with C standard library. +- Dbm: fixed bug with Dbm.iter on empty database. + +New or updated ports: +- Alpha/Digital Unix: lifted 256M limitation on total memory space + induced by -taso +- Port to AIX 4.3 on PowerPC +- Port to HPUX 10 on HPPA +- Deprecated 680x0 / SunOS port + +Macintosh port: +- Implemented the Unix and Thread libraries. +- The toplevel application does not work on 68k Macintoshes; maybe + later if there's a demand. +- Added a new tool, ocamlmkappli, to build an application from a + program written in O'Caml. + + +Objective Caml 2.04: +-------------------- + +- C interface: corrected inconsistent change in the CAMLparam* macros. +- Fixed internal error in ocamlc -g. +- Fixed type-checking of "S with ...", where S is a module type name + abbreviating another module type name. +- ocamldep: fixed stdout/stderr mismatch after failing on one file. +- Random.self_init more random. +- Windows port: + - Toplevel application: fixed spurious crash on exit. + - Native-code compiler: fixed bug in assembling certain + floating-point constants (masm doesn't grok 2e5, wants 2.0e5). + +Objective Caml 2.03: +-------------------- + +New ports: +- Ported to BeOS / Intel x86 (bytecode and native-code). +- BSD / Intel x86 port now supports both a.out and ELF binary formats. +- Added support for {Net,Open}BSD / Alpha. +- Revamped Rhapsody port, now works on MacOS X server. + +Syntax: +- Warning for "(*)" and "*)" outside comment. +- Removed "#line LINENO", too ambiguous with a method invocation; + the equivalent "# LINENO" is still supported. + +Typing: +- When an incomplete pattern-matching is detected, report also a + value or value template that is not covered by the cases of + the pattern-matching. +- Several bugs in class type matching and in type error reporting fixed. +- Added an option -rectypes to support general recursive types, + not just those involving object types. + +Bytecode compiler: +- Minor cleanups in the bytecode emitter. +- Do not remove "let x = y" bindings in -g mode; makes it easier to + debug the code. + +Native-code compiler: +- Fixed bug in grouping of allocations performed in the same basic block. +- Fixed bug in constant propagation involving expressions containing + side-effects. +- Fixed incorrect code generation for "for" loops whose upper bound is + a reference assigned inside the loop. +- MIPS code generator: work around a bug in the IRIX 6 assembler. + +Toplevel: +- Fixed incorrect redirection of standard formatter to stderr + while executing toplevel scripts. + +Standard library: +- Added List.rev_map, List.rev_map2. +- Documentation of List functions now says which functions are + tail-rec, and how much stack space is needed for non-tailrec functions. +- Wrong type for Printf.bprintf fixed. +- Fixed weird behavior of Printf.sprintf and Printf.bprintf in case of + partial applications. +- Added Random.self_init, which initializes the PRNG from the system date. +- Sort.array: serious bugs fixed. +- Stream.count: fixed incorrect behavior with ocamlopt. + +Run-time system and external interface: +- Fixed weird behavior of signal handlers w.r.t. signal masks and exceptions + raised from the signal handler. +- Fixed bug in the callback*_exn() functions. + +Debugger: +- Fixed wrong printing of float record fields and elements of float arrays. +- Supports identifiers starting with '_'. + +Profiler: +- Handles .mli files, so ocamlcp can be used to replace ocamlc (e.g. in a + makefile). +- Now works on programs that use stream expressions and stream parsers. + +Other libraries: +- Graphics: under X11, treat all mouse buttons equally; fixed problem + with current font reverting to the default font when the graphics + window is resized. +- Str: fixed reentrancy bugs in Str.replace and Str.full_split. +- Bytecode threads: set standard I/O descriptors to non-blocking mode. +- OS threads: revised implementation of Thread.wait_signal. +- All threads: added Event.wrap_abort, Event.choose []. +- Unix.localtime, Unix.gmtime: check for errors. +- Unix.create_process: now supports arbitrary redirections of std descriptors. +- Added Unix.open_process_full. +- Implemented Unix.chmod under Windows. +- Big_int.square_big_int now gives the proper sign to its result. + +Others: +- ocamldep: don't stop at first error, skip to next file. +- Emacs mode: updated with Garrigue and Zimmerman's snapshot of 1999/10/18. +- configure script: added -prefix option. +- Windows toplevel application: fixed problem with graphics library + not loading properly. + + +Objective Caml 2.02: +-------------------- + +* Type system: + - Check that all components of a signature have unique names. + - Fixed bug in signature matching involving a type component and + a module component, both sharing an abstract type. + - Bug involving recursive classes constrained by a class type fixed. + - Fixed bugs in printing class types and in printing unification errors. + +* Compilation: + - Changed compilation scheme for "{r with lbl = e}" when r has many fields + so as to avoid code size explosion. + +* Native-code compiler: + - Better constant propagation in boolean expressions and in conditionals. + - Removal of unused arguments during function inlining. + - Eliminated redundant tagging/untagging in bit shifts. + - Static allocation of closures for functions without free variables, + reduces the size of initialization code. + - Revised compilation scheme for definitions at top level of compilation + units, so that top level functions have no free variables. + - Coalesced multiple allocations of heap blocks inside one expression + (e.g. x :: y :: z allocates the two conses in one step). + - Ix86: better handling of large integer constants in instruction selection. + - MIPS: fixed wrong asm generated for String.length "literal". + +* Standard library: + - Added the "ignore" primitive function, which just throws away its + argument and returns "()". It allows to write + "ignore(f x); y" if "f x" doesn't have type unit and you don't + want the warning caused by "f x; y". + - Added the "Buffer" module (extensible string buffers). + - Module Format: added formatting to buffers and to strings. + - Added "mem" functions (membership test) to Hashtbl and Map. + - Module List: added find, filter, partition. + Renamed remove and removeq to remove_assoc and remove_assq. + - Module Marshal: fixed bug in marshaling functions when passed functional + values defined by mutual recursion with other functions. + - Module Printf: added Printf.bprintf (print to extensible buffer); + added %i format as synonymous for %d (as per the docs). + - Module Sort: added Sort.array (Quicksort). + +* Runtime system: + - New callback functions for callbacks with arbitrary many arguments + and for catching Caml exceptions escaping from a callback. + +* The ocamldep dependency generator: now performs full parsing of the + sources, taking into account the scope of module bindings. + +* The ocamlyacc parser generator: fixed sentinel error causing wrong + tables to be generated in some cases. + +* The str library: + - Added split_delim, full_split as variants of split that control + more precisely what happens to delimiters. + - Added replace_matched for separate matching and replacement operations. + +* The graphics library: + - Bypass color lookup for 16 bpp and 32 bpp direct-color displays. + - Larger color cache. + +* The thread library: + - Bytecode threads: more clever use of non-blocking I/O, makes I/O + operations faster. + - POSIX threads: gcc-ism removed, should now compile on any ANSI C compiler. + - Both: avoid memory leak in the Event module when a communication + offer is never selected. + +* The Unix library: + - Fixed inversion of ctime and mtime in Unix.stat, Unix.fstat, Unix.lstat. + - Unix.establish_connection: properly reclaim socket if connect fails. + +* The DBM library: no longer crashes when calling Dbm.close twice. + +* Emacs mode: + - Updated with Garrigue and Zimmerman's latest version. + - Now include an "ocamltags" script for using etags on OCaml sources. + +* Win32 port: + - Fixed end-of-line bug in ocamlcp causing problems with generated sources. + + +Objective Caml 2.01: +-------------------- + +* Typing: + - Added warning for expressions of the form "a; b" where a does not have + type "unit"; catches silly mistake such as + "record.lbl = newval; ..." instead of "record.lbl <- newval; ...". + - Typing bug in "let module" fixed. + +* Compilation: + - Fixed bug in compilation of recursive and mutually recursive classes. + - Option -w to turn specific warnings on/off. + - Option -cc to choose the C compiler used with ocamlc -custom and ocamlopt. + +* Bytecode compiler and bytecode interpreter: + - Intel x86: removed asm declaration causing "fixed or forbidden register + spilled" error with egcs and gcc 2.8 (but not with gcc 2.7, go figure). + - Revised handling of debugging information, allows faster linking with -g. + +* Native-code compiler: + - Fixed bugs in integer constant propagation. + - Out-of-bound accesses in array and strings now raise an Invalid_argument + exception (like the bytecode system) instead of stopping the program. + - Corrected scheduling of bound checks. + - Port to the StrongARM under Linux (e.g. Corel Netwinder). + - I386: fixed bug in profiled code (ocamlopt -p). + - Mips: switched to -n32 model under IRIX; dropped the Ultrix port. + - Sparc: simplified the addressing modes, allows for better scheduling. + - Fixed calling convention bug for Pervasives.modf. + +* Toplevel: + - #trace works again. + - ocamlmktop: use matching ocamlc, not any ocamlc from the search path. + +* Memory management: + - Fixed bug in heap expansion that could cause the GC to loop. + +* C interface: + - New macros CAMLparam... and CAMLlocal... to simplify the handling + of local roots in C code. + - Simplified procedure for allocating and filling Caml blocks from C. + - Declaration of string_length in . + +* Standard library: + - Module Format: added {get,set}_all_formatter_output_functions, + formatter_of_out_channel, and the control sequence @ in printf. + - Module List: added mem_assoc, mem_assq, remove, removeq. + - Module Pervasives: added float_of_int (synonymous for float), + int_of_float (truncate), int_of_char (Char.code), char_of_int (Char.chr), + bool_of_string. + - Module String: added contains, contains_from, rcontains_from. + +* Unix library: + - Unix.lockf: added F_RLOCK, F_TRLOCK; use POSIX locks whenever available. + - Unix.tc{get,set}attr: added non-standard speeds 57600, 115200, 230400. + - Unix.chroot: added. + +* Threads: + - Bytecode threads: improved speed of I/O scheduling. + - Native threads: fixed a bug involving signals and exceptions + generated from C. + +* The "str" library: + - Added Str.string_partial_match. + - Bumped size of internal stack. + +* ocamlyacc: emit correct '# lineno' directive for prelude part of .mly file. + +* Emacs editing mode: updated with Jacques Garrigue's newest code. + +* Windows port: + - Added support for the "-cclib -lfoo" option (instead of + -cclib /full/path/libfoo.lib as before). + - Threads: fixed a bug at initialization time. + +* Macintosh port: source code for Macintosh application merged in. + + +Objective Caml 2.00: +-------------------- + +* Language: + - New class language. See http://caml.inria.fr/ocaml/refman/ + for a tutorial (chapter 2) and for the reference manual (section 4.9). + - Local module definitions "let module X = in ". + - Record copying with update "{r with lbl1 = expr1; ...}". + - Array patterns "[|pat1; ...;patN|]" in pattern-matchings. + - New reserved keywords: "object", "initializer". + - No longer reserved: "closed", "protected". + +* Bytecode compiler: + - Use the same compact memory representations for float arrays, float + records and recursive closures as the native-code compiler. + - More type-dependent optimizations. + - Added the -use_runtime and -make_runtime flags to build separately + and reuse afterwards custom runtime systems + (inspired by Fabrice Le Fessant's patch). + +* Native-code compiler: + - Cross-module constant propagation of integer constants. + - More type-dependent optimizations. + - More compact code generated for "let rec" over data structures. + - Better code generated for "for" loops (test at bottom of code). + - More aggressive scheduling of stores. + - Added -p option for time profiling with gprof + (fully supported on Intel x86/Linux and Alpha/Digital Unix only) + (inspired by Aleksey Nogin's patch). + - A case of bad spilling with high register pressure fixed. + - Fixed GC bug when GC called from C without active Caml code. + - Alpha: $gp handling revised to follow Alpha's standard conventions, + allow running "atom" and "pixie" on ocamlopt-generated binaries. + - Intel x86: use movzbl and movsbl systematically to load 8-bit and 16-bit + quantities, no more hacks with partial registers (better for the + Pentium Pro, worse for the Pentium). + - PowerPC: more aggressive scheduling of return address reloading. + - Sparc: scheduling bug related to register pairs fixed. + +* Runtime system: + - Better printing of uncaught exceptions (print a fully qualified + name whenever possible). + +* New ports: + - Cray T3E (bytecode only) (in collaboration with CEA). + - PowerMac under Rhapsody. + - SparcStations under Linux. + +* Standard library: + - Added set_binary_mode_in and set_binary_mode_out in Pervasives + to toggle open channels between text and binary modes. + - output_value and input_value check that the given channel is in + binary mode. + - input_value no longer fails on very large marshalled data (> 16 Mbytes). + - Module Arg: added option Rest. + - Module Filename: temp_file no longer loops if temp dir doesn't exist. + - Module List: added rev_append (tail-rec alternative to @). + - Module Set: tell the truth about "elements" returning a sorted list; + added min_elt, max_elt, singleton. + - Module Sys: added Sys.time for simple measuring of CPU time. + +* ocamllex: + - Check for overflow when generating the tables for the automaton. + - Error messages in generated .ml file now point to .mll source. + - Added "let = " to name regular expressions + (inspired by Christian Lindig's patch). + +* ocamlyacc: + - Better error recovery in presence of EOF tokens. + - Error messages in generated .ml file now point to .mly source. + - Generated .ml file now type-safe even without the generated .mli file. + +* The Unix library: + - Use float instead of int to represent Unix times (number of seconds + from the epoch). This fixes a year 2005 problem on 32-bit platforms. + Functions affected: stat, lstat, fstat, time, gmtime, localtime, + mktime, utimes. + - Added putenv. + - Better handling of "unknown" error codes (EUNKNOWNERR). + - Fixed endianness bug in getservbyport. + - win32unix (the Win32 implementation of the Unix library) now has + the same interface as the unix implementation, this allows exchange + of compiled .cmo and .cmi files between Unix and Win32. + +* The thread libraries: + - Bytecode threads: bug with escaping exceptions fixed. + - System threads (POSIX, Win32): malloc/free bug fixed; signal bug fixed. + - Both: added Thread.wait_signal to wait synchronously for signals. + +* The graph library: bigger color cache. + +* The str library: added Str.quote, Str.regexp_string, + Str.regexp_string_case_fold. + +* Emacs mode: + - Fixed bug with paragraph fill. + - Fixed bug with next-error under Emacs 20. + + +Objective Caml 1.07: +-------------------- + +* Native-code compiler: + - Revised interface between generated code and GC, fixes serious GC + problems with signals and native threads. + - Added "-thread" option for compatibility with ocamlc. + +* Debugger: correctly print instance variables of objects. + +* Run-time system: ported to OpenBSD. + +* Standard library: fixed wrong interface for Marshal.to_buffer and + Obj.unmarshal. + +* Num library: added Intel x86 optimized asm code (courtesy of + Bernard Serpette). + +* Thread libraries: + - Native threads: fixed GC bugs and installation procedure. + - Bytecode threads: fixed problem with "Marshal" module. + - Both: added Event.always. + +* MS Windows port: better handling of long command lines in Sys.command + +Objective Caml 1.06: +-------------------- + +* Language: + - Added two new keywords: "assert" (check assertion) and "lazy" + (delay evaluation). + - Allow identifiers to start with "_" (such identifiers are treated + as lowercase idents). + +* Objects: + - Added "protected" methods (visible only from subclasses, can be hidden + in class type declared in module signature). + - Objects can be compared using generic comparison functions. + - Fixed compilation of partial application of object constructors. + +* Type system: + - Occur-check now more strict (all recursions must traverse an object). + - A few bugs fixed. + +* Run-time system: + - A heap compactor was implemented, so long-running programs can now + fight fragmentation. + - The meaning of the "space_overhead" parameter has changed. + - The macros Push_roots and Pop_roots are superseded by Begin_roots* and + End_roots. + - Bytecode executable includes list of primitives used, avoids crashes + on version mismatch. + - Reduced startup overhead for marshalling, much faster marshalling of + small objects. + - New exception Stack_overflow distinct from Out_of_memory. + - Maximum stack size configurable. + - I/O revised for compatibility with compactor and with native threads. + - All C code ANSIfied (new-style function declarations, etc). + - Threaded code work on all 64-bit processors, not just Alpha/Digital Unix. + - Better printing of uncaught exceptions. + +* Both compilers: + - Parsing: more detailed reporting of syntax errors (e.g. shows + unmatched opening parenthesis on missing closing parenthesis). + - Check consistency between interfaces (.cmi). + - Revised rules for determining dependencies between modules. + - Options "-verbose" for printing calls to C compiler, "-noassert" + for turning assertion checks off. + +* Native-code compiler: + - Machine-dependent parts rewritten using inheritance instead of + parameterized modules. + - GC bug in value let rec fixed. + - Port to Linux/Alpha. + - Sparc: cleaned up use of %g registers, now compatible with Solaris threads. + +* Top-level interactive system: + - Can execute Caml script files given on command line. + - Reads commands from ./.ocamlinit on startup. + - Now thread-compatible. + +* Standard library: + - New library module: Lazy (delayed computations). + - New library module: Marshal. Allows marshalling to strings and + transmission of closures between identical programs (SPMD parallelism). + - Filename: "is_absolute" is superseded by "is_implicit" and "is_relative". + To adapt old programs, change "is_absolute x" to "not (is_implicit x)" + (but the new "is_relative" is NOT the opposite of the old "is_absolute"). + - Array, Hashtbl, List, Map, Queue, Set, Stack, Stream: + the "iter" functions now take as argument a unit-returning function. + - Format: added "printf" interface to the formatter (see the documentation). + Revised behaviour of simple boxes: no more than one new line is output + when consecutive break hints should lead to multiple line breaks. + - Stream: revised implementation, renamed Parse_failure to Failure and + Parse_error to Error (don't you love gratuitous changes?). + - String: added index, rindex, index_from, rindex_from. + - Array: added mapi, iteri, fold_left, fold_right, init. + - Added Map.map, Set.subset, Printexc.to_string. + +* ocamllex: lexers generated by ocamllex can now handle all characters, + including '\000'. + +* ocamlyacc: fixed bug with function closures returned by parser rules. + +* Debugger: + - Revised generation of events. + - Break on function entrance. + - New commands start/previous. + - The command loadprinter now try to recursively load required + modules. + - Numerous small fixes. + +* External libraries: + - systhreads: can now use POSIX threads; POSIX and Win32 threads are + now supported by the native-code compiler. + - dbm and graph: work in native code. + - num: fixed bug in Nat.nat_of_string. + - str: fixed deallocation bug with case folding. + - win32unix: use Win32 handles instead of (buggy) VC++ emulation of Unix + file handles; added gettimeofday. + +* Emacs editing mode and debugger interface updated to July '97 version. + +Objective Caml 1.05: +-------------------- + +* Typing: fixed several bugs causing spurious type errors. + +* Native-code compiler: fixed instruction selection bug causing GC to +see ill-formed pointers; fixed callbacks to support invocation from a +main program in C. + +* Standard library: fixed String.lowercase; Weak now resists integers. + +* Toplevel: multiple phrases without intermediate ";;" now really supported; +fixed value printing problems where the wrong printer was selected. + +* Debugger: fixed printing problem with local references; revised +handling of checkpoints; various other small fixes. + +* Macintosh port: fixed signed division problem in bytecomp/emitcode.ml + +Objective Caml 1.04: +-------------------- + +* Replay debugger ported from Caml Light; added debugger support in + compiler (option -g) and runtime system. Debugger is alpha-quality + and needs testing. + +* Parsing: + - Support for "# linenum" directives. + - At toplevel, allow several phrases without intermediate ";;". + +* Typing: + - Allow constraints on datatype parameters, e.g. + type 'a foo = ... constraint 'a = 'b * 'c. + - Fixed bug in signature matching in presence of free type variables '_a. + - Extensive cleanup of internals of type inference. + +* Native-code compilation: + - Inlining of small functions at point of call (fairly conservative). + - MIPS code generator ported to SGI IRIX 6. + - Better code generated for large integer constants. + - Check for urgent GC when allocating large objects in major heap. + - PowerPC port: better scheduling, reduced TOC consumption. + - HPPA port: handle long conditional branches gracefully, + several span-dependent bugs fixed. + +* Standard library: + - More floating-point functions (all ANSI C float functions now available). + - Hashtbl: added functorial interface (allow providing own equality + and hash functions); rehash when resizing, avoid memory leak on + Hashtbl.remove. + - Added Char.uppercase, Char.lowercase, String.uppercase, String.lowercase, + String.capitalize, String.uncapitalize. + - New module Weak for manipulating weak pointers. + - New module Callback for registering closures and exceptions to be + used from C. + +* Foreign interface: + - Better support for callbacks (C calling Caml), exception raising + from C, and main() in C. Added function to remove a global root. + - Option -output-obj to package Caml code as a C library. + +* Thread library: fixed bug in timed_read and timed_write operations; + Lexing.from_function and Lexing.from_channel now reentrant. + +* Unix interface: renamed EACCESS to EACCES (the POSIX name); added setsid; + fixed bug in inet_addr_of_string for 64-bit platforms. + +* Ocamlyacc: default error function no longer prevents error recovery. + +* Ocamllex: fixed reentrancy problem w.r.t. exceptions during refill; + fixed output problem (\r\r\n) under Win32. + +* Macintosh port: + - The makefiles are provided for compiling and installing O'Caml on + a Macintosh with MPW 3.4.1. + - An application with the toplevel in a window is forthcoming. + +* Windows NT/95 port: updated toplevel GUI to that of Caml Light 0.73. + +* Emacs editing mode and debugger interface included in distribution. + + +Objective Caml 1.03: +-------------------- + +* Typing: + - bug with type names escaping their scope via unification with + non-generalized type variables '_a completely fixed; + - fixed bug in occur check : it was too restrictive; + - fixed bug of coercion operators; + - check that no two types of the same name are generated in a module + (there was no check for classes); + - "#install_printer" works again; + - fixed bug in printing of subtyping errors; + - in class interfaces, construct "method m" (without type) change + the status of method m from abstract to concrete; + - in a recursive definition of class interfaces, a class can now + inherit from a previous class; + - typing of a method make use of an eventual previously given type + of this method, yielding clearer type errors. + +* Compilation (ocamlc and ocamlopt): + - fixed bug in compilation of classes. + +* Native-code compilation: + - optimization of functions taking tuples of arguments; + - code emitter for the Motorola 680x0 processors (retrocomputing week); + - Alpha/OSF1: generate frame descriptors, avoids crashes when e.g. + exp() or log() cause a domain error; fixed bug with + String.length "literal"; + - Sparc, Mips, HPPA: removed marking of scanned stack frames + (benefits do not outweight cost). + +* Standard library: + - Arg.parse now prints documentation for command-line options; + - I/O buffers (types in_channel and out_channel) now heap-allocated, + avoids crashing when closing a channel several times; + - Overflow bug in compare() fixed; + - GC bug in raising Sys_error from I/O functions fixed; + - Parsing.symbol_start works even for epsilon productions. + +* Foreign interface: main() in C now working, fixed bug in library + order at link time. + +* Thread library: guard against calling thread functions before Thread.create. + +* Unix library: fixed getsockopt, setsockopt, open_process_{in,out}. + +* Perl-free, cpp-free, cholesterol-free installation procedure. + + +Objective Caml 1.02: +-------------------- +* Typing: + - fixed bug with type names escaping their scope via unification + with non-generalized type variables '_a; + - keep #class abbreviations longer; + - faster checking of well-formed abbreviation definitions; + - stricter checking of "with" constraints over signatures (arity + mismatch, overriding of an already manifest type). + +* Compilation (ocamlc and ocamlopt): + - fixed bug in compilation of recursive classes; + - [|...|] and let...rec... allowed inside definitions of recursive + data structures; + +* Bytecode compilation: fixed overflow in linker for programs with + more than 65535 globals and constants. + +* Native-code compilation: + - ocamlopt ported to HPPA under HP/UX, Intel x86 under Solaris 2, + PowerMacintosh under MkLinux; + - fixed two bugs related to floating-point arrays (one with "t array" + where t is an abstract type implemented as float, one with + comparison between two float arrays on 32 bit platforms); + - fixed reloading/spilling problem causing non-termination of + register allocation; + - fixed bugs in handling of () causing loss of tail recursion; + - fixed reloading bug in indirect calls. + +* Windows NT/95 port: + - complete port of the threads library (Pascal Cuoq); + - partial port of the Unix library (Pascal Cuoq); + - expansion of *, ? and @ on the command line. + +* Standard library: + - bug in in List.exists2 fixed; + - bug in "Random.int n" for very large n on 64-bit machines fixed; + - module Format: added a "general purpose" type of box (open_box); + can output on several formatters at the same time. + +* The "threads" library: + - implementation on top of native threads available for Win32 and + POSIX 1003.1c; + - added -thread option to select a thread-safe version of the + standard library, the ThreadIO module is no longer needed. + +* The "graph" library: avoid invalid pixmaps when doing + open_graph/close_graph several times. + +* The "dynlink" library: support for "private" (no re-export) dynamic loading. + +* ocamlyacc: skip '...' character literals correctly. + +* C interface: C code linked with O'Caml code can provide its own main() + and call caml_main() later. + + +Objective Caml 1.01: +-------------------- +* Typing: better report of type incompatibilities; + non-generalizable type variables in a struct...end no longer flagged + immediately as an error; + name clashes during "open" avoided. + +* Fixed bug in output_value where identical data structures + could have different external representations; this bug caused wrong + "inconsistent assumptions" errors when checking compatibility of + interfaces at link-time. + +* Standard library: fixed bug in Array.blit on overlapping array sections + +* Unmarshaling from strings now working. + +* ocamlc, ocamlopt: new flags -intf and -impl to force compilation as + an implementation/an interface, regardless of file extension; + overflow bug on wide-range integer pattern-matchings fixed. + +* ocamlc: fixed bytecode generation bug causing problems with compilation + units defining more than 256 values + +* ocamlopt, all platforms: + fixed GC bug in "let rec" over data structures; + link startup file first, fixes "undefined symbol" errors with some + libraries. + +* ocamlopt, Intel x86: + more efficient calling sequence for calling C functions; + floating-point wars, chapter 5: don't use float stack for holding + float pseudo-registers, stack-allocating them is just as efficient. + +* ocamlopt, Alpha and Intel x86: more compact calling sequence for garbage + collection. + +* ocamllex: generated automata no longer use callbacks for refilling + the input buffer (works better with threads); character literals + correctly skipped inside actions. + +* ocamldep: "-I" directories now searched in the right order + +* Thread library: incompatibilities with callbacks, signals, and + dynamic linking removed; scheduling bug with Thread.wait fixed. + +* New "dbm" library, interfaces with NDBM. + +* Object-oriented extensions: + instance variables can now be omitted in class types; + some error messages have been made clearer; + several bugs fixes. + +Objective Caml 1.00: +-------------------- + +* Merge of Jerome Vouillon and Didier Remy's object-oriented +extensions. + +* All libraries: all "new" functions renamed to "create" because "new" +is now a reserved keyword. + +* Compilation of "or" patterns (pat1 | pat2) completely revised to +avoid code size explosion. + +* Compiler support for preprocessing source files (-pp flag). + +* Library construction: flag -linkall to force linking of all units in +a library. + +* Native-code compiler: port to the Sparc under NetBSD. + +* Toplevel: fixed bug when tracing several times the same function +under different names. + +* New format for marshaling arbitrary data structures, allows +marshaling to/from strings. + +* Standard library: new module Genlex (configurable lexer for streams) + +* Thread library: much better support for I/O and blocking system calls. + +* Graphics library: faster reclaimation of unused pixmaps. + +* Unix library: new functions {set,clear}_nonblock, {set,clear}_close_on_exec, +{set,get}itimer, inet_addr_any, {get,set}sockopt. + +* Dynlink library: added support for linking libraries (.cma files). + +Caml Special Light 1.15: +------------------------ + +* Caml Special Light now runs under Windows NT and 95. Many thanks to +Kevin Gallo (Microsoft Research) who contributed his initial port. + +* csllex now generates tables for a table-driven automaton. +The resulting lexers are smaller and run faster. + +* Completely automatic configuration script. + +* Typing: more stringent checking of module type definitions against +manifest module type specifications. + +* Toplevel: recursive definitions of values now working. + +* Native-code compiler, all platforms: + toplevel "let"s with refutable patterns now working; + fixed bug in assignment to float record fields; + direct support for floating-point negation and absolute value. + +* Native-code compiler, x86: fixed bug with tail calls (with more than +4 arguments) from a function with a one-word stack frame. + +* Native-code compiler, Sparc: problem with -compact fixed. + +* Thread library: support for non-blocking writes; scheduler revised. + +* Unix library: bug in gethostbyaddr fixed; bounds checking for read, +write, etc. + +Caml Special Light 1.14: +------------------------ + +* cslopt ported to the PowerPC/RS6000 architecture. Better support for +AIX in the bytecode system as well. + +* cslopt, all platforms: fixed bug in live range splitting around catch/exit. + +* cslopt for the Intel (floating-point wars, chapter 4): +implemented Ershov's algorithm to minimize floating-point stack usage; +out-of-order pops fixed. + +* Several bug fixes in callbacks and signals. + +Caml Special Light 1.13: +------------------------ + +* Pattern-matching compilation revised to factor out accesses inside +matched structures. + +* Callbacks and signals now supported in cslopt. +Signals are only detected at allocation points, though. +Added callback functions with 2 and 3 arguments. + +* More explicit error messages when a native-code program aborts due +to array or string bound violations. + +* In patterns, "C _" allowed even if the constructor C has several arguments. + +* && and || allowed as alternate syntax for & and or. + +* cslopt for the Intel: code generation for floating-point +operations entirely redone for the third time (a pox on whomever at +Intel decided to organize the floating-point registers as a stack). + +* cslopt for the Sparc: don't use Sparc V8 smul and sdiv instructions, +emulation on V7 processors is abysmal. + +Caml Special Light 1.12: +------------------------ + +* Fixed an embarrassing bug with references to floats. + +Caml Special Light 1.11: +------------------------ + +* Streams and stream parsers a la Caml Light are back (thanks to +Daniel de Rauglaudre). + +* User-level concurrent threads, with low-level shared memory primitives +(locks and conditions) as well as channel-based communication primitives +with first-class synchronous events, in the style of Reppy's CML. + +* The native-code compiler has been ported to the HP PA-RISC processor +running under NextStep (sorry, no HPUX, its linker keeps dumping +core on me). + +* References not captured in a function are optimized into variables. + +* Fixed several bugs related to exceptions. + +* Floats behave a little more as specified in the IEEE standard +(believe it or not, but x < y is not the negation of x >= y). + +* Lower memory consumption for the native-code compiler. + +Caml Special Light 1.10: +------------------------ + +* Many bug fixes (too many to list here). + +* Module language: introduction of a "with module" notation over +signatures for concise sharing of all type components of a signature; +better support for concrete types in signatures. + +* Native-code compiler: the Intel 386 version has been ported to +NextStep and FreeBSD, and generates better code (especially for +floats) + +* Tools and libraries: the Caml Light profiler and library for +arbitrary-precision arithmetic have been ported (thanks to John +Malecki and Victor Manuel Gulias Fernandez); better docs for the Unix +and regexp libraries. + +Caml Special Light 1.07: +------------------------ + +* Syntax: optional ;; allowed in compilation units and structures +(back by popular demand) + +* cslopt: +generic handling of float arrays fixed +direct function application when the function expr is not a path fixed +compilation of "let rec" over values fixed +multiple definitions of a value name in a module correctly handled +no calls to ranlib in Solaris + +* csltop: #trace now working + +* Standard library: added List.memq; documentation of Array fixed. + +Caml Special Light 1.06: +------------------------ + +* First public release. + +$Id: Changes,v 1.184 2008-12-03 18:09:08 doligez Exp $ diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..cdb3436 --- /dev/null +++ b/INSTALL @@ -0,0 +1,322 @@ + Installing Objective Caml on a Unix machine + ------------------------------------------- + +PREREQUISITES + +* The GNU C compiler gcc is recommended, as the bytecode + interpreter takes advantage of gcc-specific features to enhance + performance. gcc is the standard compiler under Linux, MacOS X, + and many other systems. + +* Under MacOS X 10.5, you need version 3.1 or later of the XCode + development tools. The version of XCode found on MacOS X 10.5 + installation media causes linking problems. XCode updates + are available free of charge at http://developer.apple.com/tools/xcode/ + +* Under MacOS X up to version 10.2.8, you must raise the limit on the + stack size with one of the following commands: + + limit stacksize 64M # if your shell is zsh or tcsh + ulimit -s 65536 # if your shell is bash + +* If you do not have write access to /tmp, you should set the environment + variable TMPDIR to the name of some other temporary directory. + +* Under HP/UX, the GNU C compiler gcc, the GNU assembler gas, and GNU make + are all *required*. The vendor-provided compiler, assembler and make + have major problems. + + +INSTALLATION INSTRUCTIONS + +1- Configure the system. From the top directory, do: + + ./configure + +This generates the three configuration files "Makefile", "m.h" and "s.h" +in the config/ subdirectory. + +The "configure" script accepts the following options: + +-bindir (default: /usr/local/bin) + Directory where the binaries will be installed + +-libdir (default: /usr/local/lib/ocaml) + Directory where the Caml library will be installed + +-mandir (default: /usr/local/man/man1) + Directory where the manual pages will be installed + +-prefix (default: /usr/local) + Set bindir, libdir and mandir to + /bin, /lib/ocaml, /man/man1 respectively. + +-cc (default: gcc if available, cc otherwise) + C compiler to use for building the system + +-libs (default: none) + Extra libraries to link with the system + +-no-curses + Do not use the curses library. + +-host (default: determined automatically) + The type of the host machine, in GNU's "configuration name" + format (CPU-COMPANY-SYSTEM). This info is generally determined + automatically by the "configure" script, and rarely ever + needs to be provided by hand. The installation instructions + for gcc or emacs contain a complete list of configuration names. + +-x11include (default: determined automatically) +-x11lib (default: determined automatically) + Location of the X11 include directory (e.g. /usr/X11R6/include) + and the X11 library directory (e.g. /usr/X11R6/lib). + +-tkdefs (default: none) +-tklibs (default: determined automatically) + These options specify where to find the Tcl/Tk libraries for + LablTk. "-tkdefs" helps to find the headers, and "-tklibs" + the C libraries. "-tklibs" may contain either only -L/path and + -Wl,... flags, in which case the library names are determined + automatically, or the actual libraries, which are used as given. + Example: for a Japanese tcl/tk whose headers are in specific + directories and libraries in /usr/local/lib, you can use + ./configure -tklibs "-L/usr/local/lib -ltk8.0jp -ltcl8.0jp" + -tkdefs "-I/usr/local/include/tcl8.0jp -I/usr/local/include/tk8.0jp" + +-tk-no-x11 + Build LablTk without using X11. This option is needed on Cygwin. + +-no-tk + Do not attempt to build LablTk. + +-no-pthread + Do not attempt to use POSIX threads. + +-with-pthread + Attempt to use POSIX threads (this is the default). + +-no-shared-libs + Do not configure support for shared libraries + +-dldefs +-dllibs + These options specify where to find the libraries for dynamic + linking (i.e. use of shared libraries). "-dldefs" specifies + options for finding the header files, and "-dllibs" for finding + the C libraries. + +-as (default: determined automatically) + The assembler to use for assembling ocamlopt-generated code. + +-aspp (default: determined automatically> + The assembler to use for assembling the parts of the + run-time system manually written in assembly language. + This assembler must preprocess its input with the C preprocessor. + +-verbose + Verbose output of the configuration tests. Use it if the outcome + of configure is not what you were expecting. + +Examples: + + Standard installation in /usr/{bin,lib,man} instead of /usr/local: + ./configure -prefix /usr + + Installation in /usr, man pages in section "l": + ./configure -bindir /usr/bin -libdir /usr/lib/ocaml -mandir /usr/man/manl + + On a MacOSX/Intel Core 2 or MacOSX/PowerPC host, to build a 64-bit version + of OCaml: + ./configure -cc "gcc -m64" + + On a Linux x86/64 bits host, to build a 32-bit version of OCaml: + ./configure -cc "gcc -m32" -as "as --32" -aspp "gcc -m32 -c" + + For Sun Solaris with the "acc" compiler: + ./configure -cc "acc -fast" -libs "-lucb" + + For AIX 4.3 with the IBM compiler xlc: + ./configure -cc "xlc_r -D_AIX43 -Wl,-bexpall,-brtl -qmaxmem=8192" + + +If something goes wrong during the automatic configuration, or if the +generated files cause errors later on, then look at the template files + + config/Makefile-templ + config/m-templ.h + config/s-templ.h + +for guidance on how to edit the generated files by hand. + +2- From the top directory, do: + + make world + +This builds the Objective Caml bytecode compiler for the first time. +This phase is fairly verbose; consider redirecting the output to a file: + + make world > log.world 2>&1 # in sh + make world >& log.world # in csh + +3- (Optional) To be sure everything works well, you can try to +bootstrap the system --- that is, to recompile all Objective Caml +sources with the newly created compiler. From the top directory, do: + + make bootstrap + +or, better: + + make bootstrap > log.bootstrap 2>&1 # in sh + make bootstrap >& log.bootstrap # in csh + +The "make bootstrap" checks that the bytecode programs compiled with +the new compiler are identical to the bytecode programs compiled with +the old compiler. If this is the case, you can be pretty sure the +system has been correctly compiled. Otherwise, this does not +necessarily mean something went wrong. The best thing to do is to try +a second bootstrapping phase: just do "make bootstrap" again. It will +either crash almost immediately, or re-re-compile everything correctly +and reach the fixpoint. + +4- If your platform is supported by the native-code compiler (as +reported during the autoconfiguration), you can now build the +native-code compiler. From the top directory, do: + + make opt +or: + make opt > log.opt 2>&1 # in sh + make opt >& log.opt # in csh + +5- (Optional) If you want to compile fast versions of the Objective +Caml compilers, you can compile them with the native-code compiler +(they are compiled to bytecode by default). Just do: + + make opt.opt + +Later, you can compile your programs to bytecode using ocamlc.opt +instead of ocamlc, and to native-code using ocamlopt.opt instead of +ocamlopt. The ".opt" compilers should run faster than the normal +compilers, especially on large input files, but they may take longer +to start due to increased code size. If compilation times are an issue on +your programs, try the ".opt" compilers to see if they make a +significant difference. + +An alternative, and faster approach to steps 2 to 5 is + + make world.opt # to build using native-code compilers + +The result is equivalent to "make world opt opt.opt", but this may +fail if anything goes wrong in native-code generation. + +Another alternative, is to use the experimental build system that use +ocamlbuild instead of make (it replaces steps 2 to 5): + + ./build/fastworld.sh + +6- You can now install the Objective Caml system. This will create the +following commands (in the binary directory selected during +autoconfiguration): + + ocamlc the batch bytecode compiler + ocamlopt the batch native-code compiler (if supported) + ocamlrun the runtime system for the bytecode compiler + ocamlyacc the parser generator + ocamllex the lexer generator + ocaml the interactive, toplevel-based system + ocamlmktop a tool to make toplevel systems that integrate + user-defined C primitives and Caml code + ocamldebug the source-level replay debugger + ocamldep generator of "make" dependencies for Caml sources + ocamldoc documentation generator + ocamlprof execution count profiler + ocamlcp the bytecode compiler in profiling mode + +and also, if you built them during step 5, + + ocamlc.opt the batch bytecode compiler compiled with ocamlopt + ocamlopt.opt the batch native-code compiler compiled with ocamlopt + ocamllex.opt the lexer generator compiled with ocamlopt + +From the top directory, become superuser and do: + + umask 022 # make sure to give read & execute permission to all + make install + + In the ocamlbuild setting instead of make install do: + + ./build/install.sh + +7- Installation is complete. Time to clean up. From the toplevel +directory, do "make clean". + +8- (Optional) The emacs/ subdirectory contains Emacs-Lisp files for an +Objective Caml editing mode and an interface for the debugger. To +install these files, change to the emacs/ subdirectory and do + + make EMACSDIR= install +or + make install + +In the latter case, the destination directory defaults to the +"site-lisp" directory of your Emacs installation. + +9- After installation, do *not* strip the ocamldebug and ocamlbrowser +executables. (These are mixed-mode executables, containing both +compiled C code and Caml bytecode; stripping erases the bytecode!) +Other executables such as ocamlrun can safely be stripped. + +IF SOMETHING GOES WRONG: + +Read the "common problems" and "machine-specific hints" section at the +end of this file. + +Check the files m.h and s.h in config/. Wrong endianness or alignment +constraints in m.h will immediately crash the bytecode interpreter. + +If you get a "segmentation violation" signal, check the limits on the +stack size and data segment size (type "limit" under csh or +"ulimit -a" under bash). Make sure the limit on the stack size is +at least 4M. + +Try recompiling the runtime system with optimizations turned off +(change CFLAGS in byterun/Makefile and asmrun/Makefile). +The runtime system contains some complex, atypical pieces of C code +that can uncover bugs in optimizing compilers. Alternatively, try +another C compiler (e.g. gcc instead of the vendor-supplied cc). + +You can also build a debug version of the runtime system. Go to the +byterun/ directory and do "make ocamlrund". Then, copy ocamlrund to +../boot/ocamlrun, and try again. This version of the runtime system +contains lots of assertions and sanity checks that could help you +pinpoint the problem. + + +COMMON PROBLEMS: + +* The Makefiles do not support parallel make (e.g. make -j2). +Fix: do not pass the -j option to make, and be patient. + +* The Makefiles use the "include" directive, which is not supported by +all versions of make. Use GNU make if this is a problem. + +* The Makefiles assume that make executes commands by calling /bin/sh. They +won't work if /bin/csh is called instead. You may have to unset the SHELL +environment variable, or set it to /bin/sh. + +* On some systems, localization causes build problems. You should +try to set the C locale (export LC_ALL=C) before compiling if you have +strange errors while compiling OCaml. + +* gcc 2.7.2.1 generates incorrect code for the runtime system in -O mode +on some Intel x86 platforms (e.g. Linux RedHat 4.1 and 4.2). +If this causes a problem, the solution is to upgrade to 2.7.2.3 or above. + +* Some versions of gcc 2.96 for the Intel x86 (as found in RedHat 7.2, +Mandrake 8.0 and Mandrake 8.1) generates incorrect code for the runtime +system. The "configure" script tries to work around this problem. + +* On HP 9000/700 machines under HP/UX 9. Some versions of cc are +unable to compile correctly the runtime system (wrong code is +generated for (x - y) where x is a pointer and y an integer). +Fix: use gcc. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cecc326 --- /dev/null +++ b/LICENSE @@ -0,0 +1,626 @@ +In the following, "the Library" refers to all files marked "Copyright +INRIA" in the following directories and their sub-directories: + + asmrun, byterun, camlp4, config, otherlibs, stdlib, win32caml + +and "the Compiler" refers to all files marked "Copyright INRIA" in the +following directories and their sub-directories: + + asmcomp, boot, bytecomp, debugger, driver, lex, ocamldoc, parsing, + tools, toplevel, typing, utils, yacc + +The Compiler is distributed under the terms of the Q Public License +version 1.0 with a change to choice of law (included below). + +The Library is distributed under the terms of the GNU Library General +Public License version 2 (included below). + +As a special exception to the Q Public Licence, you may develop +application programs, reusable components and other software items +that link with the original or modified versions of the Compiler +and are not made available to the general public, without any of the +additional requirements listed in clause 6c of the Q Public licence. + +As a special exception to the GNU Library General Public License, you +may link, statically or dynamically, a "work that uses the Library" +with a publicly distributed version of the Library to produce an +executable file containing portions of the Library, and distribute +that executable file under terms of your choice, without any of the +additional requirements listed in clause 6 of the GNU Library General +Public License. By "a publicly distributed version of the Library", +we mean either the unmodified Library as distributed by INRIA, or a +modified version of the Library that is distributed under the +conditions defined in clause 2 of the GNU Library General Public +License. This exception does not however invalidate any other reasons +why the executable file might be covered by the GNU Library General +Public License. + +---------------------------------------------------------------------- + + THE Q PUBLIC LICENSE version 1.0 + + Copyright (C) 1999 Troll Tech AS, Norway. + Everyone is permitted to copy and + distribute this license document. + +The intent of this license is to establish freedom to share and change +the software regulated by this license under the open source model. + +This license applies to any software containing a notice placed by the +copyright holder saying that it may be distributed under the terms of +the Q Public License version 1.0. Such software is herein referred to +as the Software. This license covers modification and distribution of +the Software, use of third-party application programs based on the +Software, and development of free software which uses the Software. + + Granted Rights + +1. You are granted the non-exclusive rights set forth in this license +provided you agree to and comply with any and all conditions in this +license. Whole or partial distribution of the Software, or software +items that link with the Software, in any form signifies acceptance of +this license. + +2. You may copy and distribute the Software in unmodified form +provided that the entire package, including - but not restricted to - +copyright, trademark notices and disclaimers, as released by the +initial developer of the Software, is distributed. + +3. You may make modifications to the Software and distribute your +modifications, in a form that is separate from the Software, such as +patches. The following restrictions apply to modifications: + + a. Modifications must not alter or remove any copyright notices + in the Software. + + b. When modifications to the Software are released under this + license, a non-exclusive royalty-free right is granted to the + initial developer of the Software to distribute your + modification in future versions of the Software provided such + versions remain available under these terms in addition to any + other license(s) of the initial developer. + +4. You may distribute machine-executable forms of the Software or +machine-executable forms of modified versions of the Software, +provided that you meet these restrictions: + + a. You must include this license document in the distribution. + + b. You must ensure that all recipients of the machine-executable + forms are also able to receive the complete machine-readable + source code to the distributed Software, including all + modifications, without any charge beyond the costs of data + transfer, and place prominent notices in the distribution + explaining this. + + c. You must ensure that all modifications included in the + machine-executable forms are available under the terms of this + license. + +5. You may use the original or modified versions of the Software to +compile, link and run application programs legally developed by you or +by others. + +6. You may develop application programs, reusable components and other +software items that link with the original or modified versions of the +Software. These items, when distributed, are subject to the following +requirements: + + a. You must ensure that all recipients of machine-executable + forms of these items are also able to receive and use the + complete machine-readable source code to the items without any + charge beyond the costs of data transfer. + + b. You must explicitly license all recipients of your items to + use and re-distribute original and modified versions of the + items in both machine-executable and source code forms. The + recipients must be able to do so without any charges whatsoever, + and they must be able to re-distribute to anyone they choose. + + c. If the items are not available to the general public, and the + initial developer of the Software requests a copy of the items, + then you must supply one. + + Limitations of Liability + +In no event shall the initial developers or copyright holders be +liable for any damages whatsoever, including - but not restricted to - +lost revenue or profits or other direct, indirect, special, incidental +or consequential damages, even if they have been advised of the +possibility of such damages, except to the extent invariable law, if +any, provides otherwise. + + No Warranty + +The Software and this license document are provided AS IS with NO +WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + + Choice of Law + +This license is governed by the Laws of France. + +---------------------------------------------------------------------- + + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8b5330 --- /dev/null +++ b/Makefile @@ -0,0 +1,773 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.224 2008-12-03 18:09:08 doligez Exp $ + +# The main Makefile + +include config/Makefile +include stdlib/StdlibModules + +CAMLC=boot/ocamlrun boot/ocamlc -nostdlib -I boot +CAMLOPT=boot/ocamlrun ./ocamlopt -nostdlib -I stdlib -I otherlibs/dynlink +COMPFLAGS=-warn-error A $(INCLUDES) +LINKFLAGS= + +CAMLYACC=boot/ocamlyacc +YACCFLAGS=-v +CAMLLEX=boot/ocamlrun boot/ocamllex +CAMLDEP=boot/ocamlrun tools/ocamldep +DEPFLAGS=$(INCLUDES) +CAMLRUN=byterun/ocamlrun +SHELL=/bin/sh +MKDIR=mkdir -p + +INCLUDES=-I utils -I parsing -I typing -I bytecomp -I asmcomp -I driver \ + -I toplevel + +UTILS=utils/misc.cmo utils/tbl.cmo utils/config.cmo \ + utils/clflags.cmo utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \ + utils/consistbl.cmo + +OPTUTILS=$(UTILS) + +PARSING=parsing/linenum.cmo parsing/location.cmo parsing/longident.cmo \ + parsing/syntaxerr.cmo parsing/parser.cmo \ + parsing/lexer.cmo parsing/parse.cmo parsing/printast.cmo + +TYPING=typing/unused_var.cmo typing/ident.cmo typing/path.cmo \ + typing/primitive.cmo typing/types.cmo \ + typing/btype.cmo typing/oprint.cmo \ + typing/subst.cmo typing/predef.cmo \ + typing/datarepr.cmo typing/env.cmo \ + typing/typedtree.cmo typing/ctype.cmo \ + typing/printtyp.cmo typing/includeclass.cmo \ + typing/mtype.cmo typing/includecore.cmo \ + typing/includemod.cmo typing/parmatch.cmo \ + typing/typetexp.cmo typing/stypes.cmo typing/typecore.cmo \ + typing/typedecl.cmo typing/typeclass.cmo \ + typing/typemod.cmo + +COMP=bytecomp/lambda.cmo bytecomp/printlambda.cmo \ + bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo \ + bytecomp/translobj.cmo bytecomp/translcore.cmo \ + bytecomp/translclass.cmo bytecomp/translmod.cmo \ + bytecomp/simplif.cmo bytecomp/runtimedef.cmo + +BYTECOMP=bytecomp/meta.cmo bytecomp/instruct.cmo bytecomp/bytegen.cmo \ + bytecomp/printinstr.cmo bytecomp/opcodes.cmo bytecomp/emitcode.cmo \ + bytecomp/bytesections.cmo bytecomp/dll.cmo bytecomp/symtable.cmo \ + bytecomp/bytelink.cmo bytecomp/bytelibrarian.cmo bytecomp/bytepackager.cmo + +ASMCOMP=asmcomp/arch.cmo asmcomp/debuginfo.cmo \ + asmcomp/cmm.cmo asmcomp/printcmm.cmo \ + asmcomp/reg.cmo asmcomp/mach.cmo asmcomp/proc.cmo \ + asmcomp/clambda.cmo asmcomp/compilenv.cmo \ + asmcomp/closure.cmo asmcomp/cmmgen.cmo \ + asmcomp/printmach.cmo asmcomp/selectgen.cmo asmcomp/selection.cmo \ + asmcomp/comballoc.cmo asmcomp/liveness.cmo \ + asmcomp/spill.cmo asmcomp/split.cmo \ + asmcomp/interf.cmo asmcomp/coloring.cmo \ + asmcomp/reloadgen.cmo asmcomp/reload.cmo \ + asmcomp/printlinear.cmo asmcomp/linearize.cmo \ + asmcomp/schedgen.cmo asmcomp/scheduling.cmo \ + asmcomp/emitaux.cmo asmcomp/emit.cmo asmcomp/asmgen.cmo \ + asmcomp/asmlink.cmo asmcomp/asmlibrarian.cmo asmcomp/asmpackager.cmo + +DRIVER=driver/pparse.cmo driver/errors.cmo driver/compile.cmo \ + driver/main_args.cmo driver/main.cmo + +OPTDRIVER= driver/pparse.cmo driver/opterrors.cmo driver/optcompile.cmo \ + driver/optmain.cmo + +TOPLEVEL=driver/pparse.cmo driver/errors.cmo driver/compile.cmo \ + toplevel/genprintval.cmo toplevel/toploop.cmo \ + toplevel/trace.cmo toplevel/topdirs.cmo toplevel/topmain.cmo + +TOPLEVELLIB=toplevel/toplevellib.cma +TOPLEVELSTART=toplevel/topstart.cmo + +COMPOBJS=$(UTILS) $(PARSING) $(TYPING) $(COMP) $(BYTECOMP) $(DRIVER) + +TOPLIB=$(UTILS) $(PARSING) $(TYPING) $(COMP) $(BYTECOMP) $(TOPLEVEL) + +TOPOBJS=$(TOPLEVELLIB) $(TOPLEVELSTART) + +NATTOPOBJS=$(OPTUTILS) $(PARSING) $(TYPING) $(COMP) $(ASMCOMP) \ + driver/pparse.cmo driver/opterrors.cmo driver/optcompile.cmo \ + toplevel/genprintval.cmo toplevel/opttoploop.cmo toplevel/opttopdirs.cmo \ + toplevel/opttopmain.cmo toplevel/opttopstart.cmo + +OPTOBJS=$(OPTUTILS) $(PARSING) $(TYPING) $(COMP) $(ASMCOMP) $(OPTDRIVER) + +EXPUNGEOBJS=utils/misc.cmo utils/tbl.cmo \ + utils/config.cmo utils/clflags.cmo \ + typing/ident.cmo typing/path.cmo typing/types.cmo typing/btype.cmo \ + typing/predef.cmo bytecomp/runtimedef.cmo bytecomp/bytesections.cmo \ + bytecomp/dll.cmo bytecomp/meta.cmo bytecomp/symtable.cmo toplevel/expunge.cmo + +PERVASIVES=$(STDLIB_MODULES) outcometree topdirs toploop + +# For users who don't read the INSTALL file +defaultentry: + @echo "Please refer to the installation instructions in file INSTALL." + @echo "If you've just unpacked the distribution, something like" + @echo " ./configure" + @echo " make world" + @echo " make opt" + @echo " make install" + @echo "should work. But see the file INSTALL for more details." + +# Recompile the system using the bootstrap compiler +all: runtime ocamlc ocamllex ocamlyacc ocamltools library ocaml \ + otherlibraries ocamlbuild.byte camlp4out $(DEBUGGER) ocamldoc + +# Compile everything the first time +world: + $(MAKE) coldstart + $(MAKE) all + +# Compile also native code compiler and libraries, fast +world.opt: + $(MAKE) coldstart + $(MAKE) opt.opt + +# Hard bootstrap how-to: +# (only necessary in some cases, for example if you remove some primitive) +# +# make coreboot [old system -- you were in a stable state] +# +# make core [cross-compiler] +# make partialclean [if you get "inconsistent assumptions"] +# +# make core [cross-compiler] +# make coreboot [new system -- now you are in a stable state] + +# Core bootstrapping cycle +coreboot: +# Save the original bootstrap compiler + $(MAKE) backup +# Promote the new compiler but keep the old runtime +# This compiler runs on boot/ocamlrun and produces bytecode for +# byterun/ocamlrun + $(MAKE) promote-cross +# Rebuild ocamlc and ocamllex (run on byterun/ocamlrun) + $(MAKE) partialclean + $(MAKE) ocamlc ocamllex ocamltools +# Rebuild the library (using byterun/ocamlrun ./ocamlc) + $(MAKE) library-cross +# Promote the new compiler and the new runtime + $(MAKE) promote +# Rebuild the core system + $(MAKE) partialclean + $(MAKE) core +# Check if fixpoint reached + $(MAKE) compare + +# Bootstrap and rebuild the whole system. +# The compilation of ocaml will fail if the runtime has changed. +# Never mind, just do make bootstrap to reach fixpoint again. +bootstrap: + $(MAKE) coreboot + $(MAKE) all + $(MAKE) compare + +LIBFILES=stdlib.cma std_exit.cmo *.cmi camlheader + +# Start up the system from the distribution compiler +coldstart: + cd byterun; $(MAKE) all + cp byterun/ocamlrun$(EXE) boot/ocamlrun$(EXE) + cd yacc; $(MAKE) all + cp yacc/ocamlyacc$(EXE) boot/ocamlyacc$(EXE) + cd stdlib; $(MAKE) COMPILER=../boot/ocamlc all + cd stdlib; cp $(LIBFILES) ../boot + if test -f boot/libcamlrun.a; then :; else \ + ln -s ../byterun/libcamlrun.a boot/libcamlrun.a; fi + if test -d stdlib/caml; then :; else \ + ln -s ../byterun stdlib/caml; fi + +# Build the core system: the minimum needed to make depend and bootstrap +core: coldstart ocamlc ocamllex ocamlyacc ocamltools library + +# Recompile the core system using the bootstrap compiler +coreall: ocamlc ocamllex ocamlyacc ocamltools library + +# Save the current bootstrap compiler +MAXSAVED=boot/Saved/Saved.prev/Saved.prev/Saved.prev/Saved.prev/Saved.prev +backup: + if test -d boot/Saved; then : ; else mkdir boot/Saved; fi + if test -d $(MAXSAVED); then rm -r $(MAXSAVED); else : ; fi + mv boot/Saved boot/Saved.prev + mkdir boot/Saved + mv boot/Saved.prev boot/Saved/Saved.prev + cp boot/ocamlrun$(EXE) boot/Saved + mv boot/ocamlc boot/ocamllex boot/ocamlyacc$(EXE) boot/ocamldep \ + boot/Saved + cd boot; cp $(LIBFILES) Saved + +# Promote the newly compiled system to the rank of cross compiler +# (Runs on the old runtime, produces code for the new runtime) +promote-cross: + cp ocamlc boot/ocamlc + cp lex/ocamllex boot/ocamllex + cp yacc/ocamlyacc$(EXE) boot/ocamlyacc$(EXE) + cp tools/ocamldep boot/ocamldep + cd stdlib; cp $(LIBFILES) ../boot + +# Promote the newly compiled system to the rank of bootstrap compiler +# (Runs on the new runtime, produces code for the new runtime) +promote: promote-cross + cp byterun/ocamlrun$(EXE) boot/ocamlrun$(EXE) + +# Restore the saved bootstrap compiler if a problem arises +restore: + mv boot/Saved/* boot + rmdir boot/Saved + mv boot/Saved.prev boot/Saved + +# Check if fixpoint reached +compare: + @if cmp boot/ocamlc ocamlc && cmp boot/ocamllex lex/ocamllex \ + && cmp boot/ocamldep tools/ocamldep; \ + then echo "Fixpoint reached, bootstrap succeeded."; \ + else echo "Fixpoint not reached, try one more bootstrapping cycle."; \ + fi + +# Remove old bootstrap compilers +cleanboot: + rm -rf boot/Saved/Saved.prev/* + +# Compile the native-code compiler +opt-core: + $(MAKE) runtimeopt + $(MAKE) ocamlopt + $(MAKE) libraryopt + +opt: + $(MAKE) runtimeopt + $(MAKE) ocamlopt + $(MAKE) libraryopt + $(MAKE) otherlibrariesopt + $(MAKE) ocamlbuildlib.native + +# Native-code versions of the tools +opt.opt: checkstack runtime core ocaml opt-core ocamlc.opt otherlibraries \ + ocamlbuild.byte camlp4out $(DEBUGGER) ocamldoc ocamlopt.opt \ + otherlibrariesopt \ + ocamllex.opt ocamltoolsopt.opt ocamlbuild.native camlp4opt ocamldoc.opt + +# Installation +install: + if test -d $(BINDIR); then : ; else $(MKDIR) $(BINDIR); fi + if test -d $(LIBDIR); then : ; else $(MKDIR) $(LIBDIR); fi + if test -d $(STUBLIBDIR); then : ; else $(MKDIR) $(STUBLIBDIR); fi + if test -d $(MANDIR)/man$(MANEXT); then : ; \ + else $(MKDIR) $(MANDIR)/man$(MANEXT); fi + cd $(LIBDIR); rm -f dllbigarray.so dlllabltk.so dllnums.so \ + dllthreads.so dllunix.so dllgraphics.so dllmldbm.so dllstr.so \ + dlltkanim.so + cd byterun; $(MAKE) install + cp ocamlc $(BINDIR)/ocamlc$(EXE) + cp ocaml $(BINDIR)/ocaml$(EXE) + cd stdlib; $(MAKE) install + cp lex/ocamllex $(BINDIR)/ocamllex$(EXE) + cp yacc/ocamlyacc$(EXE) $(BINDIR)/ocamlyacc$(EXE) + cp toplevel/toplevellib.cma $(LIBDIR)/toplevellib.cma + cp expunge $(LIBDIR)/expunge$(EXE) + cp typing/outcometree.cmi typing/outcometree.mli $(LIBDIR) + cp toplevel/topstart.cmo $(LIBDIR) + cp toplevel/toploop.cmi toplevel/topdirs.cmi toplevel/topmain.cmi \ + $(LIBDIR) + cd tools; $(MAKE) install + -$(MAKE) -C man install + for i in $(OTHERLIBRARIES); do \ + (cd otherlibs/$$i; $(MAKE) install) || exit $$?; \ + done + cd ocamldoc; $(MAKE) install + if test -f ocamlopt; then $(MAKE) installopt; else :; fi + if test -f debugger/ocamldebug; then (cd debugger; $(MAKE) install); \ + else :; fi + cp config/Makefile $(LIBDIR)/Makefile.config + BINDIR=$(BINDIR) LIBDIR=$(LIBDIR) PREFIX=$(PREFIX) \ + ./build/partial-install.sh + +# Installation of the native-code compiler +installopt: + cd asmrun; $(MAKE) install + cp ocamlopt $(BINDIR)/ocamlopt$(EXE) + cd stdlib; $(MAKE) installopt + cd ocamldoc; $(MAKE) installopt + for i in $(OTHERLIBRARIES); \ + do (cd otherlibs/$$i; $(MAKE) installopt) || exit $$?; done + if test -f ocamlc.opt; \ + then cp ocamlc.opt $(BINDIR)/ocamlc.opt$(EXE); else :; fi + if test -f ocamlopt.opt; \ + then cp ocamlopt.opt $(BINDIR)/ocamlopt.opt$(EXE); else :; fi + if test -f lex/ocamllex.opt; \ + then cp lex/ocamllex.opt $(BINDIR)/ocamllex.opt$(EXE); else :; fi + +clean:: partialclean + +# The compiler + +ocamlc: $(COMPOBJS) + $(CAMLC) $(LINKFLAGS) -o ocamlc $(COMPOBJS) + @sed -e 's|@compiler@|$$topdir/boot/ocamlrun $$topdir/ocamlc|' \ + driver/ocamlcomp.sh.in > ocamlcomp.sh + @chmod +x ocamlcomp.sh + +partialclean:: + rm -f ocamlc ocamlcomp.sh + +# The native-code compiler + +ocamlopt: $(OPTOBJS) + $(CAMLC) $(LINKFLAGS) -o ocamlopt $(OPTOBJS) + @sed -e 's|@compiler@|$$topdir/boot/ocamlrun $$topdir/ocamlopt|' \ + driver/ocamlcomp.sh.in > ocamlcompopt.sh + @chmod +x ocamlcompopt.sh + +partialclean:: + rm -f ocamlopt ocamlcompopt.sh + +# The toplevel + +ocaml: $(TOPOBJS) expunge + $(CAMLC) $(LINKFLAGS) -linkall -o ocaml.tmp $(TOPOBJS) + - $(CAMLRUN) ./expunge ocaml.tmp ocaml $(PERVASIVES) + rm -f ocaml.tmp + +toplevel/toplevellib.cma: $(TOPLIB) + $(CAMLC) -a -o $@ $(TOPLIB) + +partialclean:: + rm -f ocaml toplevel/toplevellib.cma + +# The native toplevel + +ocamlnat: ocamlopt otherlibs/dynlink/dynlink.cmxa $(NATTOPOBJS:.cmo=.cmx) + $(CAMLOPT) $(LINKFLAGS) otherlibs/dynlink/dynlink.cmxa -o ocamlnat \ + $(NATTOPOBJS:.cmo=.cmx) -linkall + +toplevel/opttoploop.cmx: otherlibs/dynlink/dynlink.cmxa + +otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/natdynlink.ml + cd otherlibs/dynlink && make allopt + +# The configuration file + +utils/config.ml: utils/config.mlp config/Makefile + @rm -f utils/config.ml + sed -e 's|%%LIBDIR%%|$(LIBDIR)|' \ + -e 's|%%BYTERUN%%|$(BINDIR)/ocamlrun|' \ + -e 's|%%CCOMPTYPE%%|cc|' \ + -e 's|%%BYTECC%%|$(BYTECC) $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS)|' \ + -e 's|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|' \ + -e 's|%%PACKLD%%|$(PACKLD)|' \ + -e 's|%%BYTECCLIBS%%|$(BYTECCLIBS)|' \ + -e 's|%%NATIVECCLIBS%%|$(NATIVECCLIBS)|' \ + -e 's|%%RANLIBCMD%%|$(RANLIBCMD)|' \ + -e 's|%%CC_PROFILE%%|$(CC_PROFILE)|' \ + -e 's|%%ARCH%%|$(ARCH)|' \ + -e 's|%%MODEL%%|$(MODEL)|' \ + -e 's|%%SYSTEM%%|$(SYSTEM)|' \ + -e 's|%%EXT_OBJ%%|.o|' \ + -e 's|%%EXT_ASM%%|.s|' \ + -e 's|%%EXT_LIB%%|.a|' \ + -e 's|%%EXT_DLL%%|.so|' \ + -e 's|%%SYSTHREAD_SUPPORT%%|$(SYSTHREAD_SUPPORT)|' \ + -e 's|%%ASM%%|$(ASM)|' \ + -e 's|%%MKDLL%%|$(MKDLL)|' \ + -e 's|%%MKEXE%%|$(MKEXE)|' \ + -e 's|%%MKMAINDLL%%|$(MKMAINDLL)|' \ + utils/config.mlp > utils/config.ml + @chmod -w utils/config.ml + +partialclean:: + rm -f utils/config.ml + +beforedepend:: utils/config.ml + +# The parser + +parsing/parser.mli parsing/parser.ml: parsing/parser.mly + $(CAMLYACC) $(YACCFLAGS) parsing/parser.mly + +partialclean:: + rm -f parsing/parser.mli parsing/parser.ml parsing/parser.output + +beforedepend:: parsing/parser.mli parsing/parser.ml + +# The lexer + +parsing/lexer.ml: parsing/lexer.mll + $(CAMLLEX) parsing/lexer.mll + +partialclean:: + rm -f parsing/lexer.ml + +beforedepend:: parsing/lexer.ml + +# The auxiliary lexer for counting line numbers + +parsing/linenum.ml: parsing/linenum.mll + $(CAMLLEX) parsing/linenum.mll + +partialclean:: + rm -f parsing/linenum.ml + +beforedepend:: parsing/linenum.ml + +# The bytecode compiler compiled with the native-code compiler + +ocamlc.opt: $(COMPOBJS:.cmo=.cmx) + cd asmrun; $(MAKE) meta.o dynlink.o + $(CAMLOPT) $(LINKFLAGS) -ccopt "$(BYTECCLINKOPTS)" -o ocamlc.opt \ + $(COMPOBJS:.cmo=.cmx) \ + asmrun/meta.o asmrun/dynlink.o -cclib "$(BYTECCLIBS)" + @sed -e 's|@compiler@|$$topdir/ocamlc.opt|' \ + driver/ocamlcomp.sh.in > ocamlcomp.sh + @chmod +x ocamlcomp.sh + +partialclean:: + rm -f ocamlc.opt + +# The native-code compiler compiled with itself + +ocamlopt.opt: $(OPTOBJS:.cmo=.cmx) + $(CAMLOPT) $(LINKFLAGS) -o ocamlopt.opt $(OPTOBJS:.cmo=.cmx) + @sed -e 's|@compiler@|$$topdir/ocamlopt.opt|' \ + driver/ocamlcomp.sh.in > ocamlcompopt.sh + @chmod +x ocamlcompopt.sh + +partialclean:: + rm -f ocamlopt.opt + +$(OPTOBJS:.cmo=.cmx): ocamlopt + +# The numeric opcodes + +bytecomp/opcodes.ml: byterun/instruct.h + sed -n -e '/^enum/p' -e 's/,//g' -e '/^ /p' byterun/instruct.h | \ + awk -f tools/make-opcodes > bytecomp/opcodes.ml + +partialclean:: + rm -f bytecomp/opcodes.ml + +beforedepend:: bytecomp/opcodes.ml + +# The predefined exceptions and primitives + +byterun/primitives: + cd byterun; $(MAKE) primitives + +bytecomp/runtimedef.ml: byterun/primitives byterun/fail.h + (echo 'let builtin_exceptions = [|'; \ + sed -n -e 's|.*/\* \("[A-Za-z_]*"\) \*/$$| \1;|p' byterun/fail.h | \ + sed -e '$$s/;$$//'; \ + echo '|]'; \ + echo 'let builtin_primitives = [|'; \ + sed -e 's/.*/ "&";/' -e '$$s/;$$//' byterun/primitives; \ + echo '|]') > bytecomp/runtimedef.ml + +partialclean:: + rm -f bytecomp/runtimedef.ml + +beforedepend:: bytecomp/runtimedef.ml + +# Choose the right machine-dependent files + +asmcomp/arch.ml: asmcomp/$(ARCH)/arch.ml + ln -s $(ARCH)/arch.ml asmcomp/arch.ml + +partialclean:: + rm -f asmcomp/arch.ml + +beforedepend:: asmcomp/arch.ml + +asmcomp/proc.ml: asmcomp/$(ARCH)/proc.ml + ln -s $(ARCH)/proc.ml asmcomp/proc.ml + +partialclean:: + rm -f asmcomp/proc.ml + +beforedepend:: asmcomp/proc.ml + +asmcomp/selection.ml: asmcomp/$(ARCH)/selection.ml + ln -s $(ARCH)/selection.ml asmcomp/selection.ml + +partialclean:: + rm -f asmcomp/selection.ml + +beforedepend:: asmcomp/selection.ml + +asmcomp/reload.ml: asmcomp/$(ARCH)/reload.ml + ln -s $(ARCH)/reload.ml asmcomp/reload.ml + +partialclean:: + rm -f asmcomp/reload.ml + +beforedepend:: asmcomp/reload.ml + +asmcomp/scheduling.ml: asmcomp/$(ARCH)/scheduling.ml + ln -s $(ARCH)/scheduling.ml asmcomp/scheduling.ml + +partialclean:: + rm -f asmcomp/scheduling.ml + +beforedepend:: asmcomp/scheduling.ml + +# Preprocess the code emitters + +asmcomp/emit.ml: asmcomp/$(ARCH)/emit.mlp tools/cvt_emit + $(CAMLRUN) tools/cvt_emit < asmcomp/$(ARCH)/emit.mlp > asmcomp/emit.ml \ + || { rm -f asmcomp/emit.ml; exit 2; } + +partialclean:: + rm -f asmcomp/emit.ml + +beforedepend:: asmcomp/emit.ml + +tools/cvt_emit: tools/cvt_emit.mll + cd tools; \ + $(MAKE) CAMLC="../$(CAMLRUN) ../boot/ocamlc -I ../stdlib" cvt_emit + +# The "expunge" utility + +expunge: $(EXPUNGEOBJS) + $(CAMLC) $(LINKFLAGS) -o expunge $(EXPUNGEOBJS) + +partialclean:: + rm -f expunge + +# The runtime system for the bytecode compiler + +runtime: + cd byterun; $(MAKE) all + if test -f stdlib/libcamlrun.a; then :; else \ + ln -s ../byterun/libcamlrun.a stdlib/libcamlrun.a; fi + +clean:: + cd byterun; $(MAKE) clean + rm -f stdlib/libcamlrun.a + rm -f stdlib/caml + +alldepend:: + cd byterun; $(MAKE) depend + +# The runtime system for the native-code compiler + +runtimeopt: + cd asmrun; $(MAKE) all + if test -f stdlib/libasmrun.a; then :; else \ + ln -s ../asmrun/libasmrun.a stdlib/libasmrun.a; fi + +clean:: + cd asmrun; $(MAKE) clean + rm -f stdlib/libasmrun.a + +alldepend:: + cd asmrun; $(MAKE) depend + +# The library + +library: ocamlc + cd stdlib; $(MAKE) all + +library-cross: + cd stdlib; $(MAKE) RUNTIME=../byterun/ocamlrun all + +libraryopt: + cd stdlib; $(MAKE) allopt + +partialclean:: + cd stdlib; $(MAKE) clean + +alldepend:: + cd stdlib; $(MAKE) depend + +# The lexer and parser generators + +ocamllex: ocamlyacc ocamlc + cd lex; $(MAKE) all + +ocamllex.opt: ocamlopt + cd lex; $(MAKE) allopt + +partialclean:: + cd lex; $(MAKE) clean + +alldepend:: + cd lex; $(MAKE) depend + +ocamlyacc: + cd yacc; $(MAKE) all + +clean:: + cd yacc; $(MAKE) clean + +# Tools + +ocamltools: ocamlc ocamlyacc ocamllex + cd tools; $(MAKE) all + +ocamltoolsopt.opt: ocamlc.opt ocamlyacc ocamllex + cd tools; $(MAKE) opt.opt + +partialclean:: + cd tools; $(MAKE) clean + +alldepend:: + cd tools; $(MAKE) depend + +# OCamldoc + +ocamldoc: ocamlc ocamlyacc ocamllex otherlibraries + cd ocamldoc && $(MAKE) all + +ocamldoc.opt: ocamlc.opt ocamlyacc ocamllex + cd ocamldoc && $(MAKE) opt.opt + +partialclean:: + cd ocamldoc && $(MAKE) clean + +alldepend:: + cd ocamldoc && $(MAKE) depend + +# The extra libraries + +otherlibraries: ocamltools + for i in $(OTHERLIBRARIES); do \ + (cd otherlibs/$$i; $(MAKE) RUNTIME=$(RUNTIME) all) || exit $$?; \ + done + +otherlibrariesopt: + for i in $(OTHERLIBRARIES); do \ + (cd otherlibs/$$i; $(MAKE) allopt) || exit $$?; \ + done + +partialclean:: + for i in $(OTHERLIBRARIES); do \ + (cd otherlibs/$$i; $(MAKE) partialclean); \ + done + +clean:: + for i in $(OTHERLIBRARIES); do (cd otherlibs/$$i; $(MAKE) clean); done + +alldepend:: + for i in $(OTHERLIBRARIES); do (cd otherlibs/$$i; $(MAKE) depend); done + +# The replay debugger + +ocamldebugger: ocamlc ocamlyacc ocamllex otherlibraries + cd debugger; $(MAKE) all + +partialclean:: + cd debugger; $(MAKE) clean + +alldepend:: + cd debugger; $(MAKE) depend + +# Camlp4 + +camlp4out: ocamlc otherlibraries ocamlbuild-mixed-boot ocamlbuild.byte + ./build/camlp4-byte-only.sh + +camlp4opt: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot ocamlbuild.native + ./build/camlp4-native-only.sh + +# Ocamlbuild + +ocamlbuild.byte: ocamlc otherlibraries ocamlbuild-mixed-boot + ./build/ocamlbuild-byte-only.sh + +ocamlbuild.native: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot + ./build/ocamlbuild-native-only.sh +ocamlbuildlib.native: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot + ./build/ocamlbuildlib-native-only.sh + +ocamlbuild-mixed-boot: ocamlc otherlibraries + ./build/mixed-boot.sh + +partialclean:: + rm -rf _build + if test -d test; then \ + (cd test; $(MAKE) clean); \ + fi + +# Check that the stack limit is reasonable. + +checkstack: + @if $(BYTECC) -o tools/checkstack tools/checkstack.c; \ + then tools/checkstack; \ + else :; \ + fi + @rm -f tools/checkstack + +# Make MacOS X package + +package-macosx: + sudo rm -rf package-macosx/root + make PREFIX="`pwd`"/package-macosx/root install + tools/make-package-macosx + sudo rm -rf package-macosx/root + +clean:: + rm -rf package-macosx/*.pkg package-macosx/*.dmg + +# Default rules + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.ml.cmo: + $(CAMLC) $(COMPFLAGS) -c $< + +.mli.cmi: + $(CAMLC) $(COMPFLAGS) -c $< + +.ml.cmx: + $(CAMLOPT) $(COMPFLAGS) -c $< + +partialclean:: + rm -f utils/*.cm[iox] utils/*.[so] utils/*~ + rm -f parsing/*.cm[iox] parsing/*.[so] parsing/*~ + rm -f typing/*.cm[iox] typing/*.[so] typing/*~ + rm -f bytecomp/*.cm[iox] bytecomp/*.[so] bytecomp/*~ + rm -f asmcomp/*.cm[iox] asmcomp/*.[so] asmcomp/*~ + rm -f driver/*.cm[iox] driver/*.[so] driver/*~ + rm -f toplevel/*.cm[iox] toplevel/*.[so] toplevel/*~ + rm -f tools/*.cm[iox] tools/*.[so] tools/*~ + rm -f *~ + +depend: beforedepend + (for d in utils parsing typing bytecomp asmcomp driver toplevel; \ + do $(CAMLDEP) $(DEPFLAGS) $$d/*.mli $$d/*.ml; \ + done) > .depend + +alldepend:: depend + +distclean: + ./build/distclean.sh + +.PHONY: all backup bootstrap camlp4opt camlp4out checkstack clean +.PHONY: partialclean beforedepend alldepend cleanboot coldstart +.PHONY: compare core coreall +.PHONY: coreboot defaultentry depend distclean install installopt +.PHONY: library library-cross libraryopt ocamlbuild-mixed-boot +.PHONY: ocamlbuild.byte ocamlbuild.native ocamldebugger ocamldoc +.PHONY: ocamldoc.opt ocamllex ocamllex.opt ocamltools ocamltools.opt +.PHONY: ocamlyacc opt-core opt opt.opt otherlibraries +.PHONY: otherlibrariesopt package-macosx promote promote-cross +.PHONY: restore runtime runtimeopt world world.opt + +include .depend diff --git a/Makefile.nt b/Makefile.nt new file mode 100644 index 0000000..b5fc401 --- /dev/null +++ b/Makefile.nt @@ -0,0 +1,656 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.115 2008-12-03 18:09:08 doligez Exp $ + +# The main Makefile + +include config/Makefile +include stdlib/StdlibModules + +CAMLC=boot/ocamlrun boot/ocamlc -I boot +CAMLOPT=boot/ocamlrun ./ocamlopt -I stdlib -I otherlibs/dynlink +COMPFLAGS=$(INCLUDES) +LINKFLAGS= +CAMLYACC=boot/ocamlyacc +YACCFLAGS= +CAMLLEX=boot/ocamlrun boot/ocamllex +CAMLDEP=boot/ocamlrun tools/ocamldep +DEPFLAGS=$(INCLUDES) +CAMLRUN=byterun/ocamlrun + +INCLUDES=-I utils -I parsing -I typing -I bytecomp -I asmcomp -I driver \ + -I toplevel + +UTILS=utils/misc.cmo utils/tbl.cmo utils/config.cmo \ + utils/clflags.cmo utils/terminfo.cmo utils/ccomp.cmo utils/warnings.cmo \ + utils/consistbl.cmo + +OPTUTILS=$(UTILS) + +PARSING=parsing/linenum.cmo parsing/location.cmo parsing/longident.cmo \ + parsing/syntaxerr.cmo parsing/parser.cmo \ + parsing/lexer.cmo parsing/parse.cmo parsing/printast.cmo + +TYPING=typing/unused_var.cmo typing/ident.cmo typing/path.cmo \ + typing/primitive.cmo typing/types.cmo \ + typing/btype.cmo typing/oprint.cmo \ + typing/subst.cmo typing/predef.cmo \ + typing/datarepr.cmo typing/env.cmo \ + typing/typedtree.cmo typing/ctype.cmo \ + typing/printtyp.cmo typing/includeclass.cmo \ + typing/mtype.cmo typing/includecore.cmo \ + typing/includemod.cmo typing/parmatch.cmo \ + typing/typetexp.cmo typing/stypes.cmo typing/typecore.cmo \ + typing/typedecl.cmo typing/typeclass.cmo \ + typing/typemod.cmo + +COMP=bytecomp/lambda.cmo bytecomp/printlambda.cmo \ + bytecomp/typeopt.cmo bytecomp/switch.cmo bytecomp/matching.cmo \ + bytecomp/translobj.cmo bytecomp/translcore.cmo \ + bytecomp/translclass.cmo bytecomp/translmod.cmo \ + bytecomp/simplif.cmo bytecomp/runtimedef.cmo + +BYTECOMP=bytecomp/meta.cmo bytecomp/instruct.cmo bytecomp/bytegen.cmo \ + bytecomp/printinstr.cmo bytecomp/opcodes.cmo bytecomp/emitcode.cmo \ + bytecomp/bytesections.cmo bytecomp/dll.cmo bytecomp/symtable.cmo \ + bytecomp/bytelink.cmo bytecomp/bytelibrarian.cmo bytecomp/bytepackager.cmo + +ASMCOMP=asmcomp/arch.cmo asmcomp/debuginfo.cmo \ + asmcomp/cmm.cmo asmcomp/printcmm.cmo \ + asmcomp/reg.cmo asmcomp/mach.cmo asmcomp/proc.cmo \ + asmcomp/clambda.cmo asmcomp/compilenv.cmo \ + asmcomp/closure.cmo asmcomp/cmmgen.cmo \ + asmcomp/printmach.cmo asmcomp/selectgen.cmo asmcomp/selection.cmo \ + asmcomp/comballoc.cmo asmcomp/liveness.cmo \ + asmcomp/spill.cmo asmcomp/split.cmo \ + asmcomp/interf.cmo asmcomp/coloring.cmo \ + asmcomp/reloadgen.cmo asmcomp/reload.cmo \ + asmcomp/printlinear.cmo asmcomp/linearize.cmo \ + asmcomp/schedgen.cmo asmcomp/scheduling.cmo \ + asmcomp/emitaux.cmo asmcomp/emit.cmo asmcomp/asmgen.cmo \ + asmcomp/asmlink.cmo asmcomp/asmlibrarian.cmo asmcomp/asmpackager.cmo + +DRIVER=driver/pparse.cmo driver/errors.cmo driver/compile.cmo \ + driver/main_args.cmo driver/main.cmo + +OPTDRIVER=driver/pparse.cmo driver/opterrors.cmo driver/optcompile.cmo \ + driver/optmain.cmo + +TOPLEVEL=driver/pparse.cmo driver/errors.cmo driver/compile.cmo \ + toplevel/genprintval.cmo toplevel/toploop.cmo \ + toplevel/trace.cmo toplevel/topdirs.cmo toplevel/topmain.cmo + +TOPLEVELLIB=toplevel/toplevellib.cma +TOPLEVELSTART=toplevel/topstart.cmo + +COMPOBJS=$(UTILS) $(PARSING) $(TYPING) $(COMP) $(BYTECOMP) $(DRIVER) + +TOPLIB=$(UTILS) $(PARSING) $(TYPING) $(COMP) $(BYTECOMP) $(TOPLEVEL) + +TOPOBJS=$(TOPLEVELLIB) $(TOPLEVELSTART) + +NATTOPOBJS=$(OPTUTILS) $(PARSING) $(TYPING) $(COMP) $(ASMCOMP) \ + driver/pparse.cmo driver/opterrors.cmo driver/optcompile.cmo \ + toplevel/genprintval.cmo toplevel/opttoploop.cmo toplevel/opttopdirs.cmo \ + toplevel/opttopmain.cmo toplevel/opttopstart.cmo + +OPTOBJS=$(OPTUTILS) $(PARSING) $(TYPING) $(COMP) $(ASMCOMP) $(OPTDRIVER) + +EXPUNGEOBJS=utils/misc.cmo utils/tbl.cmo \ + utils/config.cmo utils/clflags.cmo \ + typing/ident.cmo typing/path.cmo typing/types.cmo typing/btype.cmo \ + typing/predef.cmo bytecomp/runtimedef.cmo bytecomp/bytesections.cmo \ + bytecomp/dll.cmo \ + bytecomp/symtable.cmo toplevel/expunge.cmo + +PERVASIVES=$(STDLIB_MODULES) topdirs toploop outcometree + +# For users who don't read the INSTALL file +defaultentry: + @echo "Please refer to the installation instructions in file README.win32." + +# Recompile the system using the bootstrap compiler +all: runtime ocamlc ocamllex ocamlyacc ocamltools library ocaml otherlibraries ocamldoc.byte ocamlbuild.byte camlp4out $(DEBUGGER) win32gui + +# The compilation of ocaml will fail if the runtime has changed. +# Never mind, just do make bootstrap to reach fixpoint again. + +# Compile everything the first time +world: coldstart all + +# Complete bootstrapping cycle +bootstrap: +# Save the original bootstrap compiler + $(MAKEREC) backup +# Promote the new compiler but keep the old runtime +# This compiler runs on boot/ocamlrun and produces bytecode for byterun/ocamlrun + $(MAKEREC) promote-cross +# Rebuild ocamlc and ocamllex (run on byterun/ocamlrun) + $(MAKEREC) partialclean + $(MAKEREC) ocamlc ocamllex ocamltools +# Rebuild the library (using byterun/ocamlrun ./ocamlc) + $(MAKEREC) library-cross +# Promote the new compiler and the new runtime + $(MAKEREC) promote +# Rebuild everything, including ocaml and the tools + $(MAKEREC) partialclean + $(MAKEREC) all +# Check if fixpoint reached + $(MAKEREC) compare + +LIBFILES=stdlib.cma std_exit.cmo *.cmi camlheader + +# Start up the system from the distribution compiler +coldstart: + cd byterun ; $(MAKEREC) all + cp byterun/ocamlrun.exe boot/ocamlrun.exe + cd yacc ; $(MAKEREC) all + cp yacc/ocamlyacc.exe boot/ocamlyacc.exe + cd stdlib ; $(MAKEREC) COMPILER=../boot/ocamlc all + cd stdlib ; cp $(LIBFILES) ../boot + +# Build the core system: the minimum needed to make depend and bootstrap +core : runtime ocamlc ocamllex ocamlyacc ocamltools library + +# Save the current bootstrap compiler +MAXSAVED=boot/Saved/Saved.prev/Saved.prev/Saved.prev/Saved.prev/Saved.prev +backup: + mkdir -p boot/Saved + if test -d $(MAXSAVED); then rm -r $(MAXSAVED); fi + mv boot/Saved boot/Saved.prev + mkdir boot/Saved + mv boot/Saved.prev boot/Saved/Saved.prev + cp boot/ocamlrun.exe boot/Saved/ocamlrun.exe + cd boot ; mv ocamlc ocamllex ocamldep ocamlyacc.exe Saved + cd boot ; cp $(LIBFILES) Saved + +# Promote the newly compiled system to the rank of cross compiler +# (Runs on the old runtime, produces code for the new runtime) +promote-cross: + cp ocamlc boot/ocamlc + cp lex/ocamllex boot/ocamllex + cp yacc/ocamlyacc.exe boot/ocamlyacc.exe + cp tools/ocamldep boot/ocamldep + cd stdlib ; cp $(LIBFILES) ../boot + +# Promote the newly compiled system to the rank of bootstrap compiler +# (Runs on the new runtime, produces code for the new runtime) +promote: promote-cross + cp byterun/ocamlrun.exe boot/ocamlrun.exe + +# Restore the saved bootstrap compiler if a problem arises +restore: + cd boot/Saved ; mv * .. + rmdir boot/Saved + mv boot/Saved.prev boot/Saved + +# Check if fixpoint reached +compare: + - cmp -i 4096 boot/ocamlc ocamlc + - cmp -i 4096 boot/ocamllex lex/ocamllex + - cmp -i 4096 boot/ocamldep tools/ocamldep + +# Remove old bootstrap compilers +cleanboot: + rm -rf boot/Saved/Saved.prev/* + +# Compile the native-code compiler +opt: runtimeopt ocamlopt libraryopt otherlibrariesopt ocamlbuildlib.native + +# Native-code versions of the tools +opt.opt: ocamlc.opt ocamlopt.opt ocamllex.opt ocamltoolsopt.opt \ + ocamlbuild.native camlp4opt ocamldoc.opt + +# Installation +install: installbyt installopt + +installbyt: + mkdir -p $(BINDIR) + mkdir -p $(LIBDIR) + cd byterun ; $(MAKEREC) install + cp ocamlc $(BINDIR)/ocamlc.exe + cp ocaml $(BINDIR)/ocaml.exe + cd stdlib ; $(MAKEREC) install + cp lex/ocamllex $(BINDIR)/ocamllex.exe + cp yacc/ocamlyacc.exe $(BINDIR)/ocamlyacc.exe + cp toplevel/toplevellib.cma $(LIBDIR)/toplevellib.cma + cp expunge $(LIBDIR)/expunge.exe + cp typing/outcometree.cmi typing/outcometree.mli $(LIBDIR) + cp toplevel/topstart.cmo $(LIBDIR) + cp toplevel/toploop.cmi toplevel/topdirs.cmi toplevel/topmain.cmi $(LIBDIR) + cd tools ; $(MAKEREC) install + cd ocamldoc ; $(MAKEREC) install + mkdir -p $(STUBLIBDIR) + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i install; done + if test -f debugger/ocamldebug.exe; then (cd debugger; $(MAKEREC) install); \ + else :; fi + cd win32caml ; $(MAKE) install + ./build/partial-install.sh + cp config/Makefile $(LIBDIR)/Makefile.config + cp README $(DISTRIB)/Readme.general.txt + cp README.win32 $(DISTRIB)/Readme.windows.txt + cp LICENSE $(DISTRIB)/License.txt + cp Changes $(DISTRIB)/Changes.txt + +# Installation of the native-code compiler +installopt: + cd asmrun ; $(MAKEREC) install + cp ocamlopt $(BINDIR)/ocamlopt.exe + cd stdlib ; $(MAKEREC) installopt + cd ocamldoc ; $(MAKEREC) installopt + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i installopt; done + if test -f ocamlc.opt; \ + then cp ocamlc.opt $(BINDIR)/ocamlc.opt.exe; else :; fi + if test -f ocamlopt.opt; \ + then cp ocamlopt.opt $(BINDIR)/ocamlopt.opt.exe; else :; fi + if test -f lex/ocamllex.opt; \ + then cp lex/ocamllex.opt $(BINDIR)/ocamllex.opt.exe; else :; fi + +clean:: partialclean + +# The compiler + +ocamlc: $(COMPOBJS) + $(CAMLC) $(LINKFLAGS) -o ocamlc $(COMPOBJS) + @sed -e 's|@compiler@|$$topdir/boot/ocamlrun $$topdir/ocamlc|' \ + driver/ocamlcomp.sh.in > ocamlcomp.sh + @chmod +x ocamlcomp.sh + +partialclean:: + rm -f ocamlc + +# The native-code compiler + +ocamlopt: $(OPTOBJS) + $(CAMLC) $(LINKFLAGS) -o ocamlopt $(OPTOBJS) + @sed -e 's|@compiler@|$$topdir/boot/ocamlrun $$topdir/ocamlopt|' \ + driver/ocamlcomp.sh.in > ocamlcompopt.sh + @chmod +x ocamlcompopt.sh + +partialclean:: + rm -f ocamlopt + +# The toplevel + +ocaml: $(TOPOBJS) expunge + $(CAMLC) $(LINKFLAGS) -linkall -o ocaml.tmp $(TOPOBJS) + - $(CAMLRUN) ./expunge ocaml.tmp ocaml $(PERVASIVES) + rm -f ocaml.tmp + +toplevel/toplevellib.cma: $(TOPLIB) + $(CAMLC) -a -o $@ $(TOPLIB) + +partialclean:: + rm -f ocaml + +# The native toplevel + +ocamlnat: ocamlopt otherlibs/dynlink/dynlink.cmxa $(NATTOPOBJS:.cmo=.cmx) + $(CAMLOPT) $(LINKFLAGS) otherlibs/dynlink/dynlink.cmxa -o ocamlnat $(NATTOPOBJS:.cmo=.cmx) -linkall + +toplevel/opttoploop.cmx: otherlibs/dynlink/dynlink.cmxa + +otherlibs/dynlink/dynlink.cmxa: otherlibs/dynlink/natdynlink.ml + cd otherlibs/dynlink && make allopt + + +# The configuration file + +utils/config.ml: utils/config.mlp config/Makefile + @rm -f utils/config.ml + sed -e "s|%%LIBDIR%%|$(LIBDIR)|" \ + -e "s|%%BYTERUN%%|ocamlrun|" \ + -e 's|%%CCOMPTYPE%%|$(CCOMPTYPE)|' \ + -e "s|%%BYTECC%%|$(BYTECC) $(BYTECCCOMPOPTS)|" \ + -e "s|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|" \ + -e "s|%%PARTIALLD%%|$(PARTIALLD)|" \ + -e "s|%%PACKLD%%|$(PACKLD)|" \ + -e "s|%%BYTECCLIBS%%|$(BYTECCLIBS)|" \ + -e "s|%%NATIVECCLIBS%%|$(NATIVECCLIBS)|" \ + -e 's|%%RANLIBCMD%%|$(RANLIBCMD)|' \ + -e 's|%%BINUTILS_NM%%|$(BINUTILS_NM)|' \ + -e 's|%%BINUTILS_OBJCOPY%%|$(BINUTILS_OBJCOPY)|' \ + -e "s|%%ARCH%%|$(ARCH)|" \ + -e "s|%%MODEL%%|$(MODEL)|" \ + -e "s|%%SYSTEM%%|$(SYSTEM)|" \ + -e "s|%%EXT_OBJ%%|.$(O)|" \ + -e "s|%%EXT_ASM%%|.$(S)|" \ + -e "s|%%EXT_LIB%%|.$(A)|" \ + -e "s|%%EXT_DLL%%|.dll|" \ + -e "s|%%SYSTHREAD_SUPPORT%%|true|" \ + -e 's|%%ASM%%|$(ASM)|' \ + -e 's|%%MKDLL%%|$(MKDLL)|' \ + -e 's|%%MKEXE%%|$(MKEXE)|' \ + -e 's|%%MKMAINDLL%%|$(MKMAINDLL)|' \ + -e 's|%%CC_PROFILE%%||' \ + utils/config.mlp > utils/config.ml + @chmod -w utils/config.ml + +partialclean:: + rm -f utils/config.ml + +beforedepend:: utils/config.ml + +# The parser + +parsing/parser.mli parsing/parser.ml: parsing/parser.mly + $(CAMLYACC) $(YACCFLAGS) parsing/parser.mly + +partialclean:: + rm -f parsing/parser.mli parsing/parser.ml parsing/parser.output + +beforedepend:: parsing/parser.mli parsing/parser.ml + +# The lexer + +parsing/lexer.ml: parsing/lexer.mll + $(CAMLLEX) parsing/lexer.mll + +partialclean:: + rm -f parsing/lexer.ml + +beforedepend:: parsing/lexer.ml + +# The auxiliary lexer for counting line numbers + +parsing/linenum.ml: parsing/linenum.mll + $(CAMLLEX) parsing/linenum.mll + +partialclean:: + rm -f parsing/linenum.ml + +beforedepend:: parsing/linenum.ml + +# The bytecode compiler compiled with the native-code compiler + +ocamlc.opt: $(COMPOBJS:.cmo=.cmx) + cd asmrun ; $(MAKEREC) meta.$(O) dynlink.$(O) + $(CAMLOPT) $(LINKFLAGS) -o ocamlc.opt $(COMPOBJS:.cmo=.cmx) asmrun/meta.$(O) asmrun/dynlink.$(O) + +partialclean:: + rm -f ocamlc.opt + +# The native-code compiler compiled with itself + +ocamlopt.opt: $(OPTOBJS:.cmo=.cmx) + $(CAMLOPT) $(LINKFLAGS) -o ocamlopt.opt $(OPTOBJS:.cmo=.cmx) + +partialclean:: + rm -f ocamlopt.opt + +$(OPTOBJS:.cmo=.cmx): ocamlopt + +# The numeric opcodes + +bytecomp/opcodes.ml: byterun/instruct.h + sed -n -e "/^enum/p" -e "s|,||g" -e "/^ /p" byterun/instruct.h | \ + gawk -f tools/make-opcodes > bytecomp/opcodes.ml + +partialclean:: + rm -f bytecomp/opcodes.ml + +beforedepend:: bytecomp/opcodes.ml + +# The predefined exceptions and primitives + +byterun/primitives: + cd byterun ; $(MAKEREC) primitives + +bytecomp/runtimedef.ml: byterun/primitives byterun/fail.h + (echo 'let builtin_exceptions = [|'; \ + sed -n -e 's|.*/\* \("[A-Za-z_]*"\) \*/$$| \1;|p' byterun/fail.h | \ + sed -e '$$s/;$$//'; \ + echo '|]'; \ + echo 'let builtin_primitives = [|'; \ + sed -e 's/.*/ "&";/' -e '$$s/;$$//' byterun/primitives; \ + echo '|]') > bytecomp/runtimedef.ml + +partialclean:: + rm -f bytecomp/runtimedef.ml + +beforedepend:: bytecomp/runtimedef.ml + +# Choose the right machine-dependent files + +asmcomp/arch.ml: asmcomp/$(ARCH)/arch.ml + cp asmcomp/$(ARCH)/arch.ml asmcomp/arch.ml + +partialclean:: + rm -f asmcomp/arch.ml + +beforedepend:: asmcomp/arch.ml + +ifeq ($(TOOLCHAIN),msvc) +ASMCOMP_PROC=asmcomp/$(ARCH)/proc_nt.ml +ASMCOMP_EMIT=asmcomp/$(ARCH)/emit_nt.mlp +else +ASMCOMP_PROC=asmcomp/$(ARCH)/proc.ml +ASMCOMP_EMIT=asmcomp/$(ARCH)/emit.mlp +endif + +asmcomp/proc.ml: $(ASMCOMP_PROC) + cp $(ASMCOMP_PROC) asmcomp/proc.ml + +partialclean:: + rm -f asmcomp/proc.ml + +beforedepend:: asmcomp/proc.ml + +asmcomp/selection.ml: asmcomp/$(ARCH)/selection.ml + cp asmcomp/$(ARCH)/selection.ml asmcomp/selection.ml + +partialclean:: + rm -f asmcomp/selection.ml + +beforedepend:: asmcomp/selection.ml + +asmcomp/reload.ml: asmcomp/$(ARCH)/reload.ml + cp asmcomp/$(ARCH)/reload.ml asmcomp/reload.ml + +partialclean:: + rm -f asmcomp/reload.ml + +beforedepend:: asmcomp/reload.ml + +asmcomp/scheduling.ml: asmcomp/$(ARCH)/scheduling.ml + cp asmcomp/$(ARCH)/scheduling.ml asmcomp/scheduling.ml + +partialclean:: + rm -f asmcomp/scheduling.ml + +beforedepend:: asmcomp/scheduling.ml + +# Preprocess the code emitters + +asmcomp/emit.ml: $(ASMCOMP_EMIT) tools/cvt_emit + boot/ocamlrun tools/cvt_emit < $(ASMCOMP_EMIT) > asmcomp/emit.ml + +partialclean:: + rm -f asmcomp/emit.ml + +beforedepend:: asmcomp/emit.ml + +tools/cvt_emit: tools/cvt_emit.mll + cd tools ; $(MAKEREC) cvt_emit + +# The "expunge" utility + +expunge: $(EXPUNGEOBJS) + $(CAMLC) $(LINKFLAGS) -o expunge $(EXPUNGEOBJS) + +partialclean:: + rm -f expunge + +# The runtime system for the bytecode compiler + +runtime: makeruntime stdlib/libcamlrun.$(A) + +makeruntime: + cd byterun ; $(MAKEREC) all +stdlib/libcamlrun.$(A): byterun/libcamlrun.$(A) + cp byterun/libcamlrun.$(A) stdlib/libcamlrun.$(A) +clean:: + cd byterun ; $(MAKEREC) clean + rm -f stdlib/libcamlrun.$(A) +alldepend:: + cd byterun ; $(MAKEREC) depend + +# The runtime system for the native-code compiler + +runtimeopt: makeruntimeopt stdlib/libasmrun.$(A) + +makeruntimeopt: + cd asmrun ; $(MAKEREC) all +stdlib/libasmrun.$(A): asmrun/libasmrun.$(A) + cp asmrun/libasmrun.$(A) stdlib/libasmrun.$(A) +clean:: + cd asmrun ; $(MAKEREC) clean + rm -f stdlib/libasmrun.$(A) +alldepend:: + cd asmrun ; $(MAKEREC) depend + +# The library + +library: + cd stdlib ; $(MAKEREC) all +library-cross: + cd stdlib ; $(MAKEREC) RUNTIME=../byterun/ocamlrun all +libraryopt: + cd stdlib ; $(MAKEREC) allopt +partialclean:: + cd stdlib ; $(MAKEREC) clean +alldepend:: + cd stdlib ; $(MAKEREC) depend + +# The lexer and parser generators + +ocamllex: + cd lex ; $(MAKEREC) all +ocamllex.opt: + cd lex ; $(MAKEREC) allopt +partialclean:: + cd lex ; $(MAKEREC) clean +alldepend:: + cd lex ; $(MAKEREC) depend + +ocamlyacc: + cd yacc ; $(MAKEREC) all +clean:: + cd yacc ; $(MAKEREC) clean + +# Tools + +ocamltools: + cd tools ; $(MAKEREC) all +ocamltoolsopt.opt: + cd tools ; $(MAKEREC) opt.opt +partialclean:: + cd tools ; $(MAKEREC) clean +alldepend:: + cd tools ; $(MAKEREC) depend + +# OCamldoc + +ocamldoc.byte: + cd ocamldoc ; $(MAKEREC) all +ocamldoc.opt: + cd ocamldoc ; $(MAKEREC) opt.opt +partialclean:: + cd ocamldoc ; $(MAKEREC) clean +alldepend:: + cd ocamldoc ; $(MAKEREC) depend + +# The extra libraries + +otherlibraries: + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i all; done +otherlibrariesopt: + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i allopt; done +partialclean:: + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i partialclean; done +clean:: + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i clean; done +alldepend:: + for i in $(OTHERLIBRARIES); do $(MAKEREC) -C otherlibs/$$i depend; done + +# The replay debugger + +ocamldebugger: ocamlc ocamlyacc ocamllex + cd debugger; $(MAKEREC) all +partialclean:: + cd debugger; $(MAKEREC) clean +alldepend:: + cd debugger; $(MAKEREC) depend + +# Camlp4 + +camlp4out: ocamlc otherlibraries ocamlbuild-mixed-boot ocamlbuild.byte + ./build/camlp4-byte-only.sh +camlp4opt: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot ocamlbuild.native + ./build/camlp4-native-only.sh + +# Ocamlbuild + +ocamlbuild.byte: ocamlc otherlibraries ocamlbuild-mixed-boot + ./build/ocamlbuild-byte-only.sh +ocamlbuild.native: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot + ./build/ocamlbuild-native-only.sh +ocamlbuildlib.native: ocamlopt otherlibrariesopt ocamlbuild-mixed-boot + ./build/ocamlbuildlib-native-only.sh + + +.PHONY: ocamlbuild-mixed-boot +ocamlbuild-mixed-boot: + ./build/mixed-boot.sh +partialclean:: + rm -rf _build + +# The Win32 toplevel GUI + +win32gui: + cd win32caml ; $(MAKE) all + +clean:: + cd win32caml ; $(MAKE) clean + +# Default rules + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.ml.cmo: + $(CAMLC) $(COMPFLAGS) -c $< + +.mli.cmi: + $(CAMLC) $(COMPFLAGS) -c $< + +.ml.cmx: + $(CAMLOPT) $(COMPFLAGS) -c $< + +partialclean:: + rm -f utils/*.cm* utils/*.$(O) utils/*.$(S) + rm -f parsing/*.cm* parsing/*.$(O) parsing/*.$(S) + rm -f typing/*.cm* typing/*.$(O) typing/*.$(S) + rm -f bytecomp/*.cm* bytecomp/*.$(O) bytecomp/*.$(S) + rm -f asmcomp/*.cm* asmcomp/*.$(O) asmcomp/*.$(S) + rm -f driver/*.cm* driver/*.$(O) driver/*.$(S) + rm -f toplevel/*.cm* toplevel/*.$(O) toplevel/*.$(S) + rm -f tools/*.cm* tools/*.$(O) tools/*.$(S) + +depend: beforedepend + (for d in utils parsing typing bytecomp asmcomp driver toplevel; \ + do $(CAMLDEP) $(DEPFLAGS) $$d/*.mli $$d/*.ml; \ + done) > .depend + +alldepend:: depend + +include .depend diff --git a/README b/README new file mode 100644 index 0000000..733fe1c --- /dev/null +++ b/README @@ -0,0 +1,138 @@ +OVERVIEW: + +Objective Caml is an implementation of the ML language, based on +the Caml Light dialect extended with a complete class-based object system +and a powerful module system in the style of Standard ML. + +Objective Caml comprises two compilers. One generates bytecode +which is then interpreted by a C program. This compiler runs quickly, +generates compact code with moderate memory requirements, and is +portable to essentially any 32 or 64 bit Unix platform. Performance of +generated programs is quite good for a bytecoded implementation. +This compiler can be used either as a standalone, batch-oriented +compiler that produces standalone programs, or as an interactive, +toplevel-based system. + +The other compiler generates high-performance native code for a number +of processors. Compilation takes longer and generates bigger code, but +the generated programs deliver excellent performance, while retaining +the moderate memory requirements of the bytecode compiler. The +native-code compiler currently runs on the following platforms: + +Tier 1 (actively used and maintained by the core Caml team): + + AMD64 (Opteron) Linux + IA32 (Pentium) Linux, FreeBSD, MacOS X, MS Windows + PowerPC MacOS X + +Tier 2 (maintained when possible, with help from users): + + Alpha Digital Unix/Compaq Tru64, Linux, all BSD + AMD64 FreeBSD, OpenBSD + HP PA-RISC HPUX 11, Linux + IA32 (Pentium) NetBSD, OpenBSD, Solaris 9 + IA64 Linux, FreeBSD + MIPS IRIX 6 + PowerPC Linux, NetBSD + SPARC Solaris 9, Linux, NetBSD + Strong ARM Linux + +Other operating systems for the processors above have not been tested, +but the compiler may work under other operating systems with little work. + +Before the introduction of objects, Objective Caml was known as Caml +Special Light. Objective Caml is almost upwards compatible with Caml +Special Light, except for a few additional reserved keywords that have +forced some renaming of standard library functions. + +CONTENTS: + + Changes what's new with each release + INSTALL instructions for installation + LICENSE license and copyright notice + Makefile main Makefile + README this file + README.win32 infos on the MS Windows ports of O.Caml + asmcomp/ native-code compiler and linker + asmrun/ native-code runtime library + boot/ bootstrap compiler + bytecomp/ bytecode compiler and linker + byterun/ bytecode interpreter and runtime system + camlp4/ the Camlp4 preprocessor + config/ autoconfiguration stuff + debugger/ source-level replay debugger + driver/ driver code for the compilers + emacs/ Caml editing mode and debugger interface for GNU Emacs + lex/ lexer generator + maccaml/ the Macintosh GUI + ocamldoc/ documentation generator + otherlibs/ several external libraries + parsing/ syntax analysis + stdlib/ standard library + tools/ various utilities + toplevel/ interactive system + typing/ typechecking + utils/ utility libraries + yacc/ parser generator + +COPYRIGHT: + +All files marked "Copyright INRIA" in this distribution are copyright +1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +2007, 2008 Institut National de Recherche en Informatique et en Automatique +(INRIA) and distributed under the conditions stated in file LICENSE. + +INSTALLATION: + +See the file INSTALL for installation instructions on Unix, Linux and +MacOS X machines. For MS Windows, see README.win32. + +DOCUMENTATION: + +The Objective Caml manual is distributed in HTML, PDF, Postscript, +DVI, and Emacs Info files. It is available on the World Wide Web, at + + http://caml.inria.fr/ + +AVAILABILITY: + +The complete Objective Caml distribution can be accessed at + + http://caml.inria.fr/ + +KEEPING IN TOUCH WITH THE CAML COMMUNITY: + +There exists a mailing list of users of the Caml implementations +developed at INRIA. The purpose of this list is to share +experience, exchange ideas (and even code), and report on applications +of the Caml language. Messages can be written in English or in +French. The list has about 750 subscribers. + +Messages to the list should be sent to: + + caml-list@inria.fr + +You can subscribe to this list via the Web interface at + + http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list + +Archives of the list are available on the Web site http://caml.inria.fr/ + +The Usenet news groups comp.lang.ml and comp.lang.functional +also contains discussions about the ML family of programming languages, +including Caml. + +BUG REPORTS AND USER FEEDBACK: + +Please report bugs using the Web interface to the bug-tracking system +at http://caml.inria.fr/bin/caml-bugs + +To be effective, bug reports should include a complete program +(preferably small) that exhibits the unexpected behavior, and the +configuration you are using (machine type, etc). + +You can also contact the implementors directly at caml@inria.fr. + + +---- +$Id: README,v 1.45 2008-12-03 18:09:08 doligez Exp $ diff --git a/README.win32 b/README.win32 new file mode 100644 index 0000000..7eac6f2 --- /dev/null +++ b/README.win32 @@ -0,0 +1,375 @@ + Release notes on the MS Windows ports of Objective Caml + ------------------------------------------------------- + +There are no less than four ports of Objective Caml for MS Windows available: + - a native Win32 port, built with the Microsoft development tools; + - a native Win32 port, built with the Cygwin/MinGW development tools; + - a port consisting of the Unix sources compiled under the Cygwin + Unix-like environment for Windows; + - a native Win64 port (64-bit Windows), built with the Microsoft + development tools. + +Here is a summary of the main differences between these ports: + + Native MS Native MinGW Cygwin + +64 bits? Win32 or Win64 Win32 only Win32 only + +Third-party software required + - for base bytecode system none none none + - for ocamlc -custom MSVC Cygwin Cygwin + - for native-code generation MSVC+MASM Cygwin Cygwin + +Speed of bytecode interpreter 70% 100% 100% + +Replay debugger yes (**) yes (**) yes + +The Unix library partial partial full + +The Threads library yes yes yes + +The Graphics library yes yes no + +Restrictions on generated executables? none none yes (*) + +(*) Cygwin-generated .exe files refer to a DLL that is distributed under +the GPL. Thus, these .exe files can only be distributed under a license +that is compatible with the GPL. Executables generated by MSVC or by +MinGW have no such restrictions. + +(**) The debugger is supported but the "replay" function of it are not enabled. +Other functions are available (step, goto, run...). + +The remainder of this document gives more information on each port. + +------------------------------------------------------------------------------ + + The native Win32 port built with Microsoft Visual C + --------------------------------------------------- + +REQUIREMENTS: + +This port runs under MS Windows Vista, XP, and 2000. + +The base bytecode system (ocamlc, ocaml, ocamllex, ocamlyacc, ...) +runs without any additional tools. + +Statically linking Caml bytecode with C code (ocamlc -custom) requires the +Microsoft Visual C++ compiler (items [1] and [2] in the section +"third-party software" below) and the flexdll tool (item [5]). + +The native-code compiler (ocamlopt) requires Visual C++ (items [1], [2]), +the Microsoft assembler MASM (item [3]) and the flexdll tool (item [5]). + +The LablTk GUI requires Tcl/Tk 8.4 (item [4]). + + +INSTALLATION: + +The binary distribution is a self-installing executable archive. +Just run it and it should install OCaml automatically. + +To run programs that use the LablTK GUI, the directory where the +DLLs tk84.dll and tcl84.dll were installed (by the Tcl/Tk +installer) must be added to the PATH environment variable. + +To compile programs that use the LablTK GUI, the directory where the +libraries tk84.lib and tcl84.lib were installed (by the Tcl/Tk +installer) must be added to the library search path in the LIB +environment variable. E.g. if Tcl/Tk was installed in C:\tcl, add +"C:\tcl\lib" to the LIB environment variable. + +THIRD-PARTY SOFTWARE: + +[1] Visual C++ version 2005, 2003, or 6. + We use Visual C++ 2005 Express Edition, which can be downloaded for free + from http://www.microsoft.com. + +[2] Windows header files and development libraries. We found them in + the Microsoft Windows Server 2003 SP1 Platform SDK, which can + be downloaded for free from http://www.microsoft.com/. + +[3] MASM version 6.11 or later. The full distribution of Visual C++ 2005 + contains MASM version 8. Users of the Express Edition of Visual C++ + 2005 can download MASM version 8 from +http://www.microsoft.com/downloads/details.aspx?FamilyID=7A1C9DA0-0510-44A2-B042-7EF370530C64&displaylang=en + To obtain MASM version 6.11, see + http://users.easystreet.com/jkirwan/new/pctools.html. + +[4] TCL/TK version 8.4. Windows binaries are available as part of the + ActiveTCL distribution at http://www.activestate.com/products/ActiveTcl/ + +[5] flexdll. + Can be downloaded from http://alain.frisch.fr/flexdll.html + +RECOMPILATION FROM THE SOURCES: + +The command-line tools can be recompiled from the Unix source +distribution (ocaml-X.YZ.tar.gz), which also contains the files modified +for Windows. + +You will need the following software components to perform the recompilation: +- Windows NT, 2000, XP, or Vista. +- Items [1], [2], [3], [4] and [5] from the list of recommended software above. +- The Cygwin port of GNU tools, available from http://www.cygwin.com/ + Install at least the following packages: diffutils, make, ncurses. + +Remember to add the directory where the libraries tk84.lib and +tcl84.lib were installed (by the Tcl/Tk installer) to the LIB variable +(library search path). + +To recompile, start a Cygwin shell and change to the top-level +directory of the OCaml distribution. Then, do + + cp config/m-nt.h config/m.h + cp config/s-nt.h config/s.h + cp config/Makefile.msvc config/Makefile + +Then, edit config/Makefile as needed, following the comments in this file. +Normally, the only variables that need to be changed are + PREFIX where to install everything + TK_ROOT where TCL/TK was installed + +Finally, use "make -f Makefile.nt" to build the system, e.g. + + make -f Makefile.nt world + make -f Makefile.nt bootstrap + make -f Makefile.nt opt + make -f Makefile.nt opt.opt + make -f Makefile.nt install + +Alternatively you can use the experimental build procedure using ocamlbuild: + + ./build/fastworld.sh + ./build/install.sh + +NOTES: + +* The VC++ compiler does not implement "computed gotos", and therefore +generates inefficient code for byterun/interp.c. Consequently, the +performance of bytecode programs is about 2/3 of that obtained under +Unix/GCC or Cygwin or Mingw on similar hardware. + +* Libraries available in this port: "num", "str", "threads", "graphics", +"labltk", and large parts of "unix". + +* The replay debugger is partially supported (no reverse execution). + +CREDITS: + +The initial port of Caml Special Light (the ancestor of Objective Caml) +to Windows NT was done by Kevin Gallo at Microsoft Research, who +kindly contributed his changes to the Caml project. + +The graphical user interface for the toplevel was initially developed +by Jacob Navia, then significantly improved by Christopher A. Watford. + +------------------------------------------------------------------------------ + + The native Win32 port built with Mingw + -------------------------------------- + +REQUIREMENTS: + +This port runs under MS Windows Vista, XP, and 2000. + +The base bytecode system (ocamlc, ocaml, ocamllex, ocamlyacc, ...) +runs without any additional tools. + +The native-code compiler (ocamlopt), as well as static linking of +Caml bytecode with C code (ocamlc -custom), require +the Cygwin development tools, available at + http://www.cygwin.com/ +and the flexdll tool, available at + http://alain.frisch.fr/flexdll.html +You will need to install at least the following Cygwin packages (use +the Setup tool from Cygwin): +binutils, gcc-core, gcc-mingw-core, mingw-runtime, w32-api. + +Do *not* install the Mingw/MSYS development tools from www.mingw.org: +these are not compatible with this Caml port (@responsefile not +recognized on the command line). + +The LablTk GUI requires Tcl/Tk 8.4. Windows binaries are available +as part of the ActiveTCL distribution at +http://www.activestate.com/products/ActiveTcl/ + +INSTALLATION: + +The binary distribution is a self-installing executable archive. +Just run it and it should install OCaml automatically. + +To run programs that use the LablTK GUI, the directory where the +DLLs tk84.dll and tcl84.dll were installed (by the Tcl/Tk +installer) must be added to the PATH environment variable. + +To compile programs that use the LablTK GUI, the directory where the +libraries tk84.lib and tcl84.lib were installed (by the Tcl/Tk +installer) must be added to the library search path in the LIB +environment variable. E.g. if Tcl/Tk was installed in C:\tcl, add +"C:\tcl\lib" to the LIB environment variable. + + +RECOMPILATION FROM THE SOURCES: + +You will need the following software components to perform the recompilation: +- Windows NT, 2000, XP, or Vista. +- Cygwin: http://sourceware.cygnus.com/cygwin/ + Install at least the following packages: binutils, diffutils, + gcc-core, gcc-mingw-core, make, mingw-runtime, ncurses, w32-api. +- TCL/TK version 8.4 (see above). +- The flexdll tool (see above). + +Do *not* install the standalone distribution of MinGW, nor the +companion MSYS tools: these have problems with long command lines. +Instead, use the version of MinGW provided by Cygwin. + +Start a Cygwin shell and unpack the source distribution +(ocaml-X.YZ.tar.gz) with "tar xzf". Change to the top-level +directory of the OCaml distribution. Then, do + + cp config/m-nt.h config/m.h + cp config/s-nt.h config/s.h + cp config/Makefile.mingw config/Makefile + +Then, edit config/Makefile as needed, following the comments in this file. +Normally, the only variables that need to be changed are + PREFIX where to install everything + TK_ROOT where TCL/TK was installed + +Finally, use "make -f Makefile.nt" to build the system, e.g. + + make -f Makefile.nt world + make -f Makefile.nt bootstrap + make -f Makefile.nt opt + make -f Makefile.nt opt.opt + make -f Makefile.nt install + + +NOTES: + +* Libraries available in this port: "num", "str", "threads", "graphics", + "labltk", and large parts of "unix". + +* The replay debugger is partially supported (no reverse execution). + +------------------------------------------------------------------------------ + + The Cygwin port of Objective Caml + --------------------------------- + +REQUIREMENTS: + +This port requires the Cygwin environment from Cygnus/RedHat, which +is freely available at: + http://www.cygwin.com/ + +It also requires the flexdll tool, available at: + http://alain.frisch.fr/flexdll.html + +This port runs under all versions of MS Windows supported by Cygwin. + + +INSTALLATION: + +We do not distribute binaries for this port, but they can be found +in the Cygwin distribution (use the Setup tool from Cygwin and select +the OCaml packages). Alternatively, recompile from the source distribution. + + +RECOMPILATION FROM THE SOURCES: + +Just follow the instructions for Unix machines given in the file INSTALL. + + +NOTES: + +The libraries available in this port are "num", "str", "threads", +"unix" and "labltk". "graph" is not available. +The replay debugger is supported. + +------------------------------------------------------------------------------ + + The native Win64 port built with the Microsoft Platform SDK compilers + --------------------------------------------------------------------- + +REQUIREMENTS: + +This port runs under MS Windows XP 64 and Server 64 on Intel64/AMD64 machines. + +The base bytecode system (ocamlc, ocaml, ocamllex, ocamlyacc, ...) +runs without any additional tools. + +Statically linking Caml bytecode with C code (ocamlc -custom) requires the +Microsoft Platform SDK compiler (item [1] in the section +"third-party software" below) and the flexdll tool (item [2]). + +The native-code compiler (ocamlopt) requires the Microsoft compiler +and the Microsoft assembler MASM64 (item [1]) and the flexdll tool (item [2]). + + +INSTALLATION: + +There is no binary distribution yet. Please compile from sources as +described below. + + +THIRD-PARTY SOFTWARE: + +[1] Microsoft Windows Server 2003 R2 Platform SDK for AMD64 (PSDK-amd64.exe). + Can be downloaded for free from http://www.microsoft.com/. + Includes all we need, namely a C compiler, the masm64 assembler, + Windows libraries and include files. + +[2] flexdll. + Can be downloaded from http://alain.frisch.fr/flexdll.html + + + +RECOMPILATION FROM THE SOURCES: + +The command-line tools can be recompiled from the Unix source +distribution (ocaml-X.YZ.tar.gz), which also contains the files modified +for Windows. + +You will need the following software components to perform the recompilation: +- Windows XP 64 or Server 64. +- The Platform SDK (item [1] from the list of recommended software above). +- The Cygwin port of GNU tools, available from http://www.cygwin.com/ + Install at least the following packages: diffutils, make, ncurses. +- The flexdll tool (see above). + +To recompile, start a Cygwin shell and change to the top-level +directory of the OCaml distribution. Then, do + + cp config/m-nt.h config/m.h + cp config/s-nt.h config/s.h + cp config/Makefile.msvc64 config/Makefile + +Then, edit config/Makefile as needed, following the comments in this file. +Normally, the only variable that need to be changed is + PREFIX where to install everything + +If, for whatever reason, you want to use the Microsoft Visual C++ 2005 +compiler for AMD64 instead of the Platform SDK compiler, replace the line + EXTRALIBS=bufferoverflowu.lib +by + EXTRALIBS= + +Finally, use "make -f Makefile.nt" to build the system, e.g. + + make -f Makefile.nt world + make -f Makefile.nt bootstrap + make -f Makefile.nt opt + make -f Makefile.nt opt.opt + make -f Makefile.nt install + + +NOTES: + +* Libraries available in this port: "num", "str", "threads", "graphics", + and large parts of "unix". + +* The replay debugger is partially supported (no reverse execution). + +* The graphical browser ocamlbrowser is not supported. diff --git a/Upgrading b/Upgrading new file mode 100644 index 0000000..10fdd47 --- /dev/null +++ b/Upgrading @@ -0,0 +1,109 @@ + + FAQ: how to upgrade from Objective Caml 3.02 to 3.03 + +I Installation + +Q1: When compiling the distribution, I am getting strange linking + errors in "otherlibraries". + +A1: This is probably a problem with dynamic linking. You can disable + it with ./configure -no-shared-libs. If you really want to use + shared libraries, look in the manual pages of your system for how + to get some debugging output from the dynamic linker. + +II Non-label changes + +Q2: I get a syntax error when I try to compile a program using stream + parsers. + +A2: Stream parser now require camlp4. It is included in the + distribution, and you just need to use "ocamlc -pp camlp4o" in + place of "ocamlc". You can also use it under the toplevel with + #load"camlp4o.cma". + +Q3: I get a warning when I use the syntax "#variant" inside type + expressions. + +A3: The new syntax is [< variant], which just a special case of + the more general new syntax, which allows type expressions like + [ variant1 | variant2] or [> variant]. See the reference manual + for details. + +III Label changes + +Q4: I was using labels before, and now I get lots of type errors. + +A4: The handling of labels changed with 3.03-alpha. The new default + is a more flexible version of the commuting label mode, allowing + one to omit labels in total applications. There is still a + -nolabels mode, but it does not allow non-optional labels in + applications (this was unsound). + To keep full compatibility with Objective Caml 2, labels were + removed from the standard libraries. Some labelized libraries are + kept as StdLabels (contains Array, List and String), MoreLabels + (contains Hashtbl, Map and Set), and UnixLabels. + Note that MoreLabels' status is not yet decided. + +Q5: Why isn't there a ThreadUnixLabels module ? + +A5: ThreadUnix is deprecated. It only calls directly the Unix module. + +Q6: I was using commuting label mode, how can I upgrade ? + +A6: The new behaviour is compatible with commuting label mode, but + standard libraries have no labels. You can add the following + lines at the beginning of your files (according to your needs): + open Stdlabels + open MoreLabels + module Unix = UnixLabels + Alternatively, if you already have a common module opened by + everybody, you can add these: + include StdLabels + include MoreLabels + module Unix = UnixLabels + + You will then need to remove labels in functions from other modules. + This can be automated by using the scrapelabels tool, installed + in the Objective Caml library directory, which both removes labels + and inserts needed `open' clauses (see -help for details). + $CAMLLIB/scrapelabels -keepstd *.ml + or + $CAMLLIB/scrapelabels -keepmore *.ml + Note that scrapelabels is not guaranteed to be sound for commuting + label programs, since it will just remove labels, and not reorder + arguments. + +Q7: I was using a few labels in classic mode, and now I get all these + errors. I just want to get rid of all these silly labels. + +A7: scrapelabels will do it for you. + $CAMLLIB/scrapelabels [-all] *.ml + $CAMLLIB/scrapelabels -intf *.mli + You should specify the -all option only if you are sure that your + sources do not contain calls to functions with optional + parameters, as those labels would also be removed. + +Q8: I was using labels in classic mode, and I was actually pretty fond + of them. How much more labels will I have to write now ? How can I + convert my programs and libraries ? + +A8: The new default mode is more flexible than the original commuting + mode, so that you shouldn't see too much differences when using + labeled libraries. Labels are only compulsory in partial + applications (including the special case of function with an + unknown return type), or if you wrote some of them. + + On the other hand, for definitions, labels present in the + interface must also be present in the implementation. + The addlabels tool can help you to do that. Suppose that you have + mymod.ml and mymod.mli, where mymod.mli adds some labels. Then + doing + $CAMLLIB/addlabels mymod.ml + will insert labels from the interface inside the implementation. + It also takes care of inserting them in recursive calls, as + the return type of the function is not known while typing it. + + If you used labels from standard libraries, you will also have + problems with them. You can proceed as described in A6. Since you + used classic mode, you do not need to bother about changed + argument order. \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..c4502f1 --- /dev/null +++ b/VERSION @@ -0,0 +1,6 @@ +3.12.0+dev1 (2008-12-03) + +# The version string is the first line of this file. +# It must be in the format described in stdlib/sys.mli + +# $Id: VERSION,v 1.29 2008-12-03 18:09:08 doligez Exp $ diff --git a/_tags b/_tags new file mode 100644 index 0000000..47121f8 --- /dev/null +++ b/_tags @@ -0,0 +1,85 @@ +# Ocamlbuild tags file + +true: -traverse + +# Traverse only these directories +<{bytecomp,driver,stdlib,tools,asmcomp,camlp4,ocamlbuild,toplevel,ocamldoc,typing,otherlibs,utils,debugger,lex,parsing,byterun,asmrun}/**>: traverse + +"boot" or "byterun" or "asmrun": not_hygienic + +# These should not be required but it fails on *BSD and Windows... +"yacc" or "win32caml": not_hygienic + +# We want -g everywhere it's possible +true: debug + +# By default everything we link needs the stdlib +true: use_stdlib + +# The stdlib neither requires the stdlib nor debug information +: -use_stdlib, -debug + +<**/*.ml*>: warn_Alez + +"toplevel/topstart.byte": linkall + +: -debug +: ocamldoc_sources +: include_unix, include_str, include_dynlink +"ocamldoc/odoc.byte": use_unix, use_str, use_dynlink +"ocamldoc/odoc_opt.native": use_unix, use_str + +: camlp4boot, -warn_Alez, warn_Ale +: -camlp4boot +"camlp4/Camlp4_import.ml": -warn_Ale + or or "camlp4/Camlp4/Struct/Lexer.ml": -camlp4boot, -warn_Ale, warn_a + or : use_dynlink +"camlp4/Camlp4/Printers/OCaml.ml" or "camlp4/Camlp4/Printers/OCamlr.ml": warn_Alezv +: include_unix +"camlp4/Camlp4/Struct/DynLoader.ml" or "camlp4/boot/Camlp4.ml": include_dynlink +: include_toplevel +: -debug + +: -warn_Alez, include_unix + +<**/pervasives.ml> or <**/pervasives.mli> or <**/camlinternalOO.mli>: nopervasives +<**/camlinternalOO*.cmx>: inline(0) +<**/scanf*.cmx>: inline(9) +<**/*Labels.ml*>: nolabels + +"tools/addlabels.ml": warn_s + + or : use_unix, use_dynlink, linkall +: include_unix + + or : ocamlmklib + or : ocamlmklib +: ocamlmklib +: ocamlmklib +: ocamlmklib + +: include_unix + +# See the remark about static linking of threads.cmxa in myocamlbuild.ml +: ocamlmklib + +"otherlibs/threads/pervasives.ml": include_unix + +: otherlibs +: otherlibs_unix +: otherlibs_win32unix +: otherlibs_bigarray +: otherlibs_num +: otherlibs_threads +: otherlibs_systhreads +: otherlibs_dbm +: otherlibs_graph +: otherlibs_win32graph +: otherlibs_labltk + + or : bootstrap_thread +: ocamlmklib +"otherlibs/labltk/browser/jglib.cma": -ocamlmklib +"otherlibs/labltk/browser/main.byte": use_unix, use_str, ocamlbrowser, bootstrap_thread +: include_unix, include_str +: include_unix diff --git a/asmcomp/.cvsignore b/asmcomp/.cvsignore new file mode 100644 index 0000000..31d0017 --- /dev/null +++ b/asmcomp/.cvsignore @@ -0,0 +1,6 @@ +emit.ml +arch.ml +proc.ml +selection.ml +reload.ml +scheduling.ml diff --git a/asmcomp/alpha/arch.ml b/asmcomp/alpha/arch.ml new file mode 100644 index 0000000..4ab8bba --- /dev/null +++ b/asmcomp/alpha/arch.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.10 2002-11-29 15:03:36 xleroy Exp $ *) + +(* Specific operations for the Alpha processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Addressing modes *) + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + +(* Specific operations *) + +type specific_operation = + Iadd4 | Iadd8 | Isub4 | Isub8 (* Scaled adds and subs *) + | Ireloadgp of bool (* The ldgp instruction *) + | Itrunc32 (* Truncate 64-bit int to 32 bit *) + +(* Sizes, endianness *) + +let big_endian = false + +let size_addr = 8 +let size_int = 8 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, n) -> + fprintf ppf "\"%s\"%s" s + (if n <> 0 then Printf.sprintf " + %i" n else "") + | Iindexed n -> + fprintf ppf "%a%s" printreg arg.(0) + (if n <> 0 then Printf.sprintf " + %i" n else "") + +let print_specific_operation printreg op ppf arg = + match op with + | Iadd4 -> fprintf ppf "%a * 4 + %a" printreg arg.(0) printreg arg.(1) + | Iadd8 -> fprintf ppf "%a * 8 + %a" printreg arg.(0) printreg arg.(1) + | Isub4 -> fprintf ppf "%a * 4 - %a" printreg arg.(0) printreg arg.(1) + | Isub8 -> fprintf ppf "%a * 8 - %a" printreg arg.(0) printreg arg.(1) + | Ireloadgp _ -> fprintf ppf "ldgp" + | Itrunc32 -> fprintf ppf "truncate32 %a" printreg arg.(0) + +(* Distinguish between the Digital assembler and other assemblers (e.g. gas) *) + +let digital_asm = + match Config.system with + "digital" -> true + | _ -> false diff --git a/asmcomp/alpha/emit.mlp b/asmcomp/alpha/emit.mlp new file mode 100644 index 0000000..0258025 --- /dev/null +++ b/asmcomp/alpha/emit.mlp @@ -0,0 +1,861 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.42 2006-04-16 23:28:14 doligez Exp $ *) + +module LabelSet = + Set.Make(struct type t = Linearize.label let compare = compare end) + +(* Emission of Alpha assembly code *) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* First pass: insert Iloadgp instructions where needed *) + +let insert_load_gp f = + + let labels_needing_gp = ref LabelSet.empty in + let fixpoint_reached = ref false in + + let label_needs_gp lbl = + LabelSet.mem lbl !labels_needing_gp in + let opt_label_needs_gp default = function + None -> default + | Some lbl -> label_needs_gp lbl in + let set_label_needs_gp lbl = + if not (label_needs_gp lbl) then begin + fixpoint_reached := false; + labels_needing_gp := LabelSet.add lbl !labels_needing_gp + end in + + let tailrec_entry_point = new_label() in + + (* Determine if $gp is needed before an instruction. + [next] says whether $gp is needed just after (i.e. by the following + instruction). *) + let instr_needs_gp next = function + Lend -> false + | Lop(Iconst_int n) -> (* for large n, turned into ldq ($gp) *) + next || n < Nativeint.of_int(-0x80000000) + || n > Nativeint.of_int 0x7FFFFFFF + | Lop(Iconst_float s) -> true (* turned into ldq ($gp) *) + | Lop(Iconst_symbol s) -> true (* turned into ldq ($gp) *) + | Lop(Icall_ind) -> false (* does ldgp if needed afterwards *) + | Lop(Icall_imm s) -> true (* does lda $27, *) + | Lop(Itailcall_ind) -> false + | Lop(Itailcall_imm s) -> + if s = f.fun_name then label_needs_gp tailrec_entry_point else true + | Lop(Iextcall(_, _)) -> true (* does lda $27, *) + | Lop(Iload(_, Ibased(_, _))) -> true (* loads address from ($gp) *) + | Lop(Istore(_, Ibased(_, _))) -> true (* loads address from ($gp) *) + | Lop(Iintop(Idiv | Imod)) -> true (* divq and remq can be turned into *) + | Lop(Iintop_imm((Idiv | Imod), _)) -> true (* a function call *) + | Lop(Iintop_imm(_, n)) -> (* for large n, turned into ldq ($gp) *) + next || n < -0x80000000 || n > 0x7FFFFFFF + | Lop _ -> next + | Lreloadretaddr -> next + | Lreturn -> false + | Llabel lbl -> if next then set_label_needs_gp lbl; next + | Lbranch lbl -> label_needs_gp lbl + | Lcondbranch(tst, lbl) -> next || label_needs_gp lbl + | Lcondbranch3(lbl1, lbl2, lbl3) -> + opt_label_needs_gp next lbl1 || + opt_label_needs_gp next lbl2 || + opt_label_needs_gp next lbl3 + | Lswitch lblv -> true + | Lsetuptrap lbl -> label_needs_gp lbl + | Lpushtrap -> next + | Lpoptrap -> next + | Lraise -> false in + + let rec needs_gp i = + if i.desc = Lend + then false + else instr_needs_gp (needs_gp i.next) i.desc in + + while not !fixpoint_reached do + fixpoint_reached := true; + if needs_gp f.fun_body then set_label_needs_gp tailrec_entry_point + done; + + (* Insert Ireloadgp instructions after calls where needed *) + let rec insert_reload_gp i = + if i.desc = Lend then (i, false) else begin + let (new_next, needs_next) = insert_reload_gp i.next in + let new_instr = + match i.desc with + (* If the instruction destroys $gp and $gp is needed afterwards, + insert a ldgp after the instructions. *) + Lop(Icall_ind | Icall_imm _) when needs_next -> + {i with next = + instr_cons (Lop(Ispecific(Ireloadgp true))) [||] [||] new_next } + | Lop(Iextcall(_, false)) | Lsetuptrap _ when needs_next -> + {i with next = + instr_cons (Lop(Ispecific(Ireloadgp false))) [||] [||] new_next } + | _ -> + {i with next = new_next} in + (new_instr, instr_needs_gp needs_next i.desc) + end in + + let (new_body, uses_gp) = insert_reload_gp f.fun_body in + ({f with fun_body = new_body}, uses_gp) + +(* Second pass: code generation proper *) + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Output a label *) + +let emit_label lbl = + emit_string "$"; emit_int lbl + +let emit_Llabel fallthrough lbl = + if (not fallthrough) then begin + emit_string " .align 4\n" + end ; + emit_label lbl + +(* Output a symbol *) + +let emit_symbol s = + Emitaux.emit_symbol '$' s + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit_alpha.emit_reg" + +(* Layout of the stack frame *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + + (if !contains_calls then 8 else 0) in + Misc.align size 16 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + n * 8 + else !stack_offset + (num_stack_slots.(0) + n) * 8 + | Outgoing n -> n + +(* Output a stack reference *) + +let emit_stack r = + match r.loc with + Stack s -> + let ofs = slot_offset s (register_class r) in `{emit_int ofs}($sp)` + | _ -> fatal_error "Emit_alpha.emit_stack" + +(* Output an addressing mode *) + +let emit_addressing addr r n = + match addr with + Iindexed ofs -> + `{emit_int ofs}({emit_reg r.(n)})` + | Ibased(s, ofs) -> + `{emit_symbol s}`; + if ofs > 0 then ` + {emit_int ofs}`; + if ofs < 0 then ` - {emit_int(-ofs)}` + +(* Immediate operands *) + +let is_immediate n = digital_asm || (n >= 0 && n <= 255) + +(* Communicate live registers at call points to the assembler *) + +let int_reg_number = [| + 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; + 16; 17; 18; 19; 20; 21; 22 +|] + +let float_reg_number = [| + 0; 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; 29; 30 +|] + +let liveregs instr extra_msk = + (* $13, $14, $15 always live *) + let int_mask = ref(0x00070000 lor extra_msk) + and float_mask = ref 0 in + let add_register = function + {loc = Reg r; typ = (Int | Addr)} -> + int_mask := !int_mask lor (1 lsl (31 - int_reg_number.(r))) + | {loc = Reg r; typ = Float} -> + float_mask := !float_mask lor (1 lsl (31 - float_reg_number.(r - 100))) + | _ -> () in + Reg.Set.iter add_register instr.live; + Array.iter add_register instr.arg; + emit_printf " .livereg 0x%08x, 0x%08x\n" !int_mask !float_mask + +let live_24 = 1 lsl (31 - 24) +let live_25 = 1 lsl (31 - 25) +let live_26 = 1 lsl (31 - 26) +let live_27 = 1 lsl (31 - 27) + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame_label live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((int_reg_number.(r) lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + lbl + +let record_frame live = + let lbl = record_frame_label live in `{emit_label lbl}:` + +let emit_frame fd = + ` .quad {emit_label fd.fd_lbl}\n`; + ` .word {emit_int fd.fd_frame_size}\n`; + ` .word {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` .word {emit_int n}\n`) + fd.fd_live_offset; + ` .align 3\n` + +(* Record calls to the GC -- we've moved them out of the way *) + +type gc_call = + { gc_lbl: label; (* Entry label *) + gc_return_lbl: label; (* Where to branch after GC *) + gc_frame: label; (* Label of frame descriptor *) + gc_instr: instruction } (* Record live registers *) + +let call_gc_sites = ref ([] : gc_call list) + +let emit_call_gc gc = + `{emit_label gc.gc_lbl}:`; + liveregs gc.gc_instr 0; + ` bsr $26, caml_call_gc\n`; + (* caml_call_gc preserves $gp *) + `{emit_label gc.gc_frame}: br {emit_label gc.gc_return_lbl}\n` + +(* Name of readonly data section *) + +let rdata_section = + match Config.system with + "digital" -> ".rdata" + | "linux" | "openbsd" | "netbsd" | "freebsd" | "gnu" -> ".section .rodata" + | _ -> assert false + +(* Names of various instructions *) + +let name_for_int_operation = function + Iadd -> "addq" + | Isub -> "subq" + | Imul -> "mulq" + | Idiv -> "divq" + | Imod -> "remq" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "sll" + | Ilsr -> "srl" + | Iasr -> "sra" + | _ -> Misc.fatal_error "Emit.name_for_int_operation" + +let name_for_float_operation = function + Inegf -> "fneg" + | Iabsf -> "fabs" + | Iaddf -> "addt" + | Isubf -> "subt" + | Imulf -> "mult" + | Idivf -> "divt" + | _ -> Misc.fatal_error "Emit.name_for_float_operation" + +let name_for_specific_operation = function + Iadd4 -> "s4addq" + | Iadd8 -> "s8addq" + | Isub4 -> "s4subq" + | Isub8 -> "s8subq" + | _ -> Misc.fatal_error "Emit.name_for_specific_operation" + +let name_for_int_comparison = function + Isigned Ceq -> "cmpeq", true | Isigned Cne -> "cmpeq", false + | Isigned Cle -> "cmple", true | Isigned Cgt -> "cmple", false + | Isigned Clt -> "cmplt", true | Isigned Cge -> "cmplt", false + | Iunsigned Ceq -> "cmpeq", true | Iunsigned Cne -> "cmpeq", false + | Iunsigned Cle -> "cmpule", true | Iunsigned Cgt -> "cmpule", false + | Iunsigned Clt -> "cmpult", true | Iunsigned Cge -> "cmpult", false + +(* Used for comparisons against 0 *) +let name_for_int_cond_branch = function + Isigned Ceq -> "beq" | Isigned Cne -> "bne" + | Isigned Cle -> "ble" | Isigned Cgt -> "bgt" + | Isigned Clt -> "blt" | Isigned Cge -> "bge" + | Iunsigned Ceq -> "beq" | Iunsigned Cne -> "bne" + | Iunsigned Cle -> "beq" | Iunsigned Cgt -> "bne" + | Iunsigned Clt -> "#" | Iunsigned Cge -> "br" + (* Always false *) (* Always true *) + +let name_for_float_comparison cmp neg = + match cmp with + Ceq -> ("cmpteq", false, neg) | Cne -> ("cmpteq", false, not neg) + | Cle -> ("cmptle", false, neg) | Cgt -> ("cmptlt", true, neg) + | Clt -> ("cmptlt", false, neg) | Cge -> ("cmptle", true, neg) + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Label of trap for out-of-range accesses *) +let range_check_trap = ref 0 +(* List of floating-point and big integer literals + (fon non-Digital assemblers) *) +let float_constants = ref ([] : (label * string) list) +let bigint_constants = ref ([] : (label * nativeint) list) + +let emit_instr fallthrough i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + match (src.loc, dst.loc) with + (Reg rs, Reg rd) -> + if src.typ = Float then + ` fmov {emit_reg src}, {emit_reg dst}\n` + else + ` mov {emit_reg src}, {emit_reg dst}\n` + | (Reg rs, Stack sd) -> + if src.typ = Float then + ` stt {emit_reg src}, {emit_stack dst}\n` + else + ` stq {emit_reg src}, {emit_stack dst}\n` + | (Stack ss, Reg rd) -> + if src.typ = Float then + ` ldt {emit_reg dst}, {emit_stack src}\n` + else + ` ldq {emit_reg dst}, {emit_stack src}\n` + | _ -> + fatal_error "Emit_alpha: Imove" + end + | Lop(Iconst_int n) -> + if n = 0n then + ` clr {emit_reg i.res.(0)}\n` + else if digital_asm || + (n >= Nativeint.of_int (-0x80000000) && + n <= Nativeint.of_int 0x7FFFFFFF) then + ` ldiq {emit_reg i.res.(0)}, {emit_nativeint n}\n` + else begin + (* Work around a bug in gas/gld concerning big integer constants *) + let lbl = new_label() in + bigint_constants := (lbl, n) :: !bigint_constants; + ` lda $25, {emit_label lbl}\n`; + ` ldq {emit_reg i.res.(0)}, 0($25)\n` + end + | Lop(Iconst_float s) -> + if digital_asm then + ` ldit {emit_reg i.res.(0)}, {emit_string s}\n` + else if Int64.bits_of_float (float_of_string s) = 0L then + ` fmov $f31, {emit_reg i.res.(0)}\n` + else begin + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` lda $25, {emit_label lbl}\n`; + ` ldt {emit_reg i.res.(0)}, 0($25)\n` + end + | Lop(Iconst_symbol s) -> + ` lda {emit_reg i.res.(0)}, {emit_symbol s}\n` + | Lop(Icall_ind) -> + liveregs i 0; + ` mov {emit_reg i.arg.(0)}, $27\n`; + ` jsr ({emit_reg i.arg.(0)})\n`; + `{record_frame i.live}\n` + | Lop(Icall_imm s) -> + liveregs i 0; + ` jsr {emit_symbol s}\n`; + `{record_frame i.live}\n` + | Lop(Itailcall_ind) -> + let n = frame_size() in + if !contains_calls then + ` ldq $26, {emit_int(n - 8)}($sp)\n`; + if n > 0 then + ` lda $sp, {emit_int n}($sp)\n`; + ` mov {emit_reg i.arg.(0)}, $27\n`; + liveregs i (live_26 + live_27); + ` jmp ({emit_reg i.arg.(0)})\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then begin + ` br {emit_label !tailrec_entry_point}\n` + end else begin + let n = frame_size() in + if !contains_calls then + ` ldq $26, {emit_int(n - 8)}($sp)\n`; + if n > 0 then + ` lda $sp, {emit_int n}($sp)\n`; + ` lda $27, {emit_symbol s}\n`; + liveregs i (live_26 + live_27); + ` br {emit_symbol s}\n` + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + ` lda $25, {emit_symbol s}\n`; + liveregs i live_25; + ` bsr $26, caml_c_call\n`; + `{record_frame i.live}\n` + end else begin + ` jsr {emit_symbol s}\n` + end + | Lop(Istackoffset n) -> + ` lda $sp, {emit_int (-n)}($sp)\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + let load_instr = + match chunk with + | Byte_unsigned -> "ldbu" + | Byte_signed -> "ldb" + | Sixteen_unsigned -> "ldwu" + | Sixteen_signed -> "ldw" + | Thirtytwo_unsigned -> "ldl" + | Thirtytwo_signed -> "ldl" + | Word -> "ldq" + | Single -> "lds" + | Double -> "ldt" + | Double_u -> "ldt" in + ` {emit_string load_instr} {emit_reg dest}, {emit_addressing addr i.arg 0}\n`; + if chunk = Thirtytwo_unsigned then + ` zapnot {emit_reg dest}, 15, {emit_reg dest}\n` + | Lop(Istore(chunk, addr)) -> + let store_instr = + match chunk with + | Byte_unsigned | Byte_signed -> "stb" + | Sixteen_unsigned | Sixteen_signed -> "stw" + | Thirtytwo_unsigned | Thirtytwo_signed -> "stl" + | Word -> "stq" + | Single -> "sts" + | Double -> "stt" + | Double_u -> "stt" in + ` {emit_string store_instr} {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_redo = new_label() in + let lbl_call_gc = new_label() in + let lbl_frame = record_frame_label i.live in + call_gc_sites := + { gc_lbl = lbl_call_gc; + gc_return_lbl = lbl_redo; + gc_frame = lbl_frame; + gc_instr = i } :: !call_gc_sites; + `{emit_label lbl_redo}: lda $13, -{emit_int n}($13)\n`; + ` cmpult $13, $14, $25\n`; + ` bne $25, {emit_label lbl_call_gc}\n`; + ` addq $13, 8, {emit_reg i.res.(0)}\n` + end else begin + begin match n with + 16 -> liveregs i 0; + ` bsr $26, caml_alloc1\n` + | 24 -> liveregs i 0; + ` bsr $26, caml_alloc2\n` + | 32 -> liveregs i 0; + ` bsr $26, caml_alloc3\n` + | _ -> ` ldiq $25, {emit_int n}\n`; + liveregs i live_25; + ` bsr $26, caml_allocN\n` + end; + (* $gp preserved by caml_alloc* *) + `{record_frame i.live} addq $13, 8, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop(Icomp cmp)) -> + let (comp, test) = name_for_int_comparison cmp in + ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`; + if not test then + ` xor {emit_reg i.res.(0)}, 1, {emit_reg i.res.(0)}\n` + | Lop(Iintop(Icheckbound)) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` cmpule {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, $25\n`; + ` bne $25, {emit_label !range_check_trap}\n` + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + if n = 1 lsl (Misc.log2 n) then begin + let l = Misc.log2 n in + if is_immediate n then + ` addq {emit_reg i.arg.(0)}, {emit_int(n-1)}, $25\n` + else begin + ` ldiq $25, {emit_int(n-1)}\n`; + ` addq {emit_reg i.arg.(0)}, $25, $25\n` + end; + ` cmovge {emit_reg i.arg.(0)}, {emit_reg i.arg.(0)}, $25\n`; + ` sra $25, {emit_int l}, {emit_reg i.res.(0)}\n` + end else begin + (* divq with immediate arg is incorrectly assembled in Tru64 5.1, + so emulate it ourselves *) + ` ldiq $25, {emit_int n}\n`; + ` divq {emit_reg i.arg.(0)}, $25, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop_imm(Imod, n)) -> + if n = 1 lsl (Misc.log2 n) then begin + if is_immediate n then + ` and {emit_reg i.arg.(0)}, {emit_int(n-1)}, $25\n` + else begin + ` ldiq $25, {emit_int (n-1)}\n`; + ` and {emit_reg i.arg.(0)}, $25, $25\n` + end; + ` subq $25, {emit_int n}, $24\n`; + ` cmovge {emit_reg i.arg.(0)}, $25, $24\n`; + ` cmoveq $25, $25, $24\n`; + ` mov $24, {emit_reg i.res.(0)}\n` + end else begin + (* remq with immediate arg is incorrectly assembled in Tru64 5.1, + so emulate it ourselves *) + ` ldiq $25, {emit_int n}\n`; + ` remq {emit_reg i.arg.(0)}, $25, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop_imm(Ilsl, 1)) -> + (* Turn x << 1 into x + x, slightly faster according to the docs *) + ` addq {emit_reg i.arg.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + let (comp, test) = name_for_int_comparison cmp in + ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_int n}, {emit_reg i.res.(0)}\n`; + if not test then + ` xor {emit_reg i.res.(0)}, 1, {emit_reg i.res.(0)}\n` + + | Lop(Iintop_imm(Icheckbound, n)) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` cmpule {emit_reg i.arg.(0)}, {emit_int n}, $25\n`; + ` bne $25, {emit_label !range_check_trap}\n` + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_int n}, {emit_reg i.res.(0)}\n` + | Lop(Inegf | Iabsf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Ifloatofint) -> + ` .set noat\n`; + ` lda $sp, -8($sp)\n`; + ` stq {emit_reg i.arg.(0)}, 0($sp)\n`; + ` ldt $f28, 0($sp)\n`; + ` cvtqt $f28, {emit_reg i.res.(0)}\n`; + ` lda $sp, 8($sp)\n`; + ` .set at\n` + | Lop(Iintoffloat) -> + ` .set noat\n`; + ` lda $sp, -8($sp)\n`; + ` cvttqc {emit_reg i.arg.(0)}, $f28\n`; + ` stt $f28, 0($sp)\n`; + ` ldq {emit_reg i.res.(0)}, 0($sp)\n`; + ` lda $sp, 8($sp)\n`; + ` .set at\n` + | Lop(Ispecific(Ireloadgp marked_r26)) -> + ` ldgp $gp, 0($26)\n`; + if marked_r26 then + ` bic $gp, 1, $gp\n` + | Lop(Ispecific Itrunc32) -> + ` addl {emit_reg i.arg.(0)}, 0, {emit_reg i.res.(0)}\n` + | Lop(Ispecific sop) -> + let instr = name_for_specific_operation sop in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lreloadretaddr -> + let n = frame_size() in + ` ldq $26, {emit_int(n - 8)}($sp)\n` + | Lreturn -> + let n = frame_size() in + if n > 0 then + ` lda $sp, {emit_int n}($sp)\n`; + liveregs i live_26; + ` ret ($26)\n` + | Llabel lbl -> + `{emit_Llabel fallthrough lbl}:\n` + | Lbranch lbl -> + ` br {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + ` bne {emit_reg i.arg.(0)}, {emit_label lbl}\n` + | Ifalsetest -> + ` beq {emit_reg i.arg.(0)}, {emit_label lbl}\n` + | Iinttest cmp -> + let (comp, test) = name_for_int_comparison cmp in + ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, $25\n`; + if test then + ` bne $25, {emit_label lbl}\n` + else + ` beq $25, {emit_label lbl}\n` + | Iinttest_imm(cmp, 0) -> + let branch = name_for_int_cond_branch cmp in + ` {emit_string branch} {emit_reg i.arg.(0)}, {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + let (comp, test) = name_for_int_comparison cmp in + ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_int n}, $25\n`; + if test then + ` bne $25, {emit_label lbl}\n` + else + ` beq $25, {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + ` .set noat\n`; + let (comp, swap, test) = name_for_float_comparison cmp neg in + ` {emit_string comp} `; + if swap + then `{emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}, $f28\n` + else `{emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, $f28\n`; + if test + then ` fbeq $f28, {emit_label lbl}\n` + else ` fbne $f28, {emit_label lbl}\n`; + ` .set at\n` + | Ioddtest -> + ` blbs {emit_reg i.arg.(0)}, {emit_label lbl}\n` + | Ieventest -> + ` blbc {emit_reg i.arg.(0)}, {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + begin match lbl0 with + None -> () + | Some lbl -> ` beq {emit_reg i.arg.(0)}, {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` blbs {emit_reg i.arg.(0)}, {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> + if lbl0 <> None then + ` blbc {emit_reg i.arg.(0)}, {emit_label lbl}\n` + else if lbl1 <> None then + ` bne {emit_reg i.arg.(0)}, {emit_label lbl}\n` + else begin + ` subq {emit_reg i.arg.(0)}, 2, $25\n`; + ` beq $25, {emit_label lbl}\n` + end + end + | Lswitch jumptbl -> + let lbl_jumptbl = new_label() in + ` lda $25, {emit_label lbl_jumptbl}\n`; + ` s4addq {emit_reg i.arg.(0)}, $25, $25\n`; + ` ldl $25, 0($25)\n`; + ` addq $gp, $25, $25\n`; + ` jmp ($25), {emit_label jumptbl.(0)}\n`; + ` {emit_string rdata_section}\n`; + `{emit_label lbl_jumptbl}:`; + for i = 0 to Array.length jumptbl - 1 do + ` .gprel32 {emit_label jumptbl.(i)}\n` + done; + ` .text\n` + | Lsetuptrap lbl -> + ` br $25, {emit_label lbl}\n` + | Lpushtrap -> + stack_offset := !stack_offset + 16; + ` lda $sp, -16($sp)\n`; + ` stq $15, 0($sp)\n`; + ` stq $25, 8($sp)\n`; + ` mov $sp, $15\n` + | Lpoptrap -> + ` ldq $15, 0($sp)\n`; + ` lda $sp, 16($sp)\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + ` ldq $26, 8($15)\n`; + ` mov $15, $sp\n`; + ` ldq $15, 0($sp)\n`; + ` lda $sp, 16($sp)\n`; + liveregs i live_26; + ` jmp $25, ($26)\n` (* Keep retaddr in $25 for debugging *) + +let rec emit_all fallthrough i = match i.desc with +| Lend -> () +| _ -> + emit_instr fallthrough i; + emit_all (has_fallthrough i.desc) i.next + +(* Emission of a function declaration *) + +let emit_fundecl (fundecl, needs_gp) = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + stack_offset := 0; + call_gc_sites := []; + range_check_trap := 0; + float_constants := []; + bigint_constants := []; + ` .text\n`; + ` .align 4\n`; + ` .globl {emit_symbol fundecl.fun_name}\n`; + ` .ent {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + if needs_gp then begin + ` .set noreorder\n`; + ` ldgp $gp, 0($27)\n`; + ` .set reorder\n` + end; + let n = frame_size() in + if n > 0 then + ` lda $sp, -{emit_int n}($sp)\n`; + if !contains_calls then begin + ` stq $26, {emit_int(n - 8)}($sp)\n`; + ` .mask 0x04000000, -8\n`; + ` .fmask 0x0, 0\n` + end; + ` .frame $sp, {emit_int n}, $26\n`; + ` .prologue {emit_int(if needs_gp then 1 else 0)}\n`; + tailrec_entry_point := new_label(); + `{emit_label !tailrec_entry_point}:\n`; + emit_all true fundecl.fun_body; + List.iter emit_call_gc !call_gc_sites; + if !range_check_trap > 0 then begin + `{emit_label !range_check_trap}:\n`; + ` br $26, caml_ml_array_bound_error\n` + (* Keep retaddr in $26 for debugging *) + end; + ` .end {emit_symbol fundecl.fun_name}\n`; + if !bigint_constants <> [] then begin + ` {emit_string rdata_section}\n`; + ` .align 3\n`; + List.iter + (fun (lbl, n) -> `{emit_label lbl}: .quad 0x{emit_string(Nativeint.format "%x" n)}\n`) + !bigint_constants + end; + if !float_constants <> [] then begin + ` {emit_string rdata_section}\n`; + ` .align 3\n`; + List.iter + (fun (lbl, s) -> `{emit_label lbl}: .t_floating {emit_string s}\n`) + !float_constants + end + +let fundecl f = + emit_fundecl (insert_load_gp f) + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .globl {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .word {emit_int n}\n` + | Cint32 n -> + let n' = Nativeint.shift_right (Nativeint.shift_left n 32) 32 in + ` .long {emit_nativeint n'}\n` + | Cint n -> + if digital_asm then + ` .quad {emit_nativeint n}\n` + else + (* Work around a bug in gas regarding the parsing of + long decimal constants *) + ` .quad 0x{emit_string(Nativeint.format "%x" n)}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .double {emit_string f}\n` + | Csymbol_address s -> + ` .quad {emit_symbol s}\n` + | Clabel_address lbl -> + ` .quad {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then ` .space {emit_int n}\n` + | Calign n -> + ` .align {emit_int(Misc.log2 n)}\n` + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + (* There are really two groups of registers: + $sp and $15 always point to stack locations + $0 - $14, $16-$23 never point to stack locations. *) + ` .noalias $0,$sp; .noalias $0,$15; .noalias $1,$sp; .noalias $1,$15\n`; + ` .noalias $2,$sp; .noalias $2,$15; .noalias $3,$sp; .noalias $3,$15\n`; + ` .noalias $4,$sp; .noalias $4,$15; .noalias $5,$sp; .noalias $5,$15\n`; + ` .noalias $6,$sp; .noalias $6,$15; .noalias $7,$sp; .noalias $7,$15\n`; + ` .noalias $8,$sp; .noalias $8,$15; .noalias $9,$sp; .noalias $9,$15\n`; + ` .noalias $10,$sp; .noalias $10,$15; .noalias $11,$sp; .noalias $11,$15\n`; + ` .noalias $12,$sp; .noalias $12,$15; .noalias $13,$sp; .noalias $13,$15\n`; + ` .noalias $14,$sp; .noalias $14,$15; .noalias $16,$sp; .noalias $16,$15\n`; + ` .noalias $17,$sp; .noalias $17,$15; .noalias $18,$sp; .noalias $18,$15\n`; + ` .noalias $19,$sp; .noalias $19,$15; .noalias $20,$sp; .noalias $20,$15\n`; + ` .noalias $21,$sp; .noalias $21,$15; .noalias $22,$sp; .noalias $22,$15\n`; + ` .noalias $23,$sp; .noalias $23,$15\n\n`; + (* The following .file directive is intended to prevent the generation + of line numbers for the debugger, 'cos they make .o files larger + and slow down linking. *) + ` .file 1 \"{emit_string !Location.input_name}\"\n\n`; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n` + +let end_assembly () = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .text\n`; + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .data\n`; + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .quad 0\n`; + let lbl_frame = Compilenv.make_symbol (Some "frametable") in + ` {emit_string rdata_section}\n`; + ` .globl {emit_symbol lbl_frame}\n`; + `{emit_symbol lbl_frame}:\n`; + ` .quad {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + frame_descriptors := [] diff --git a/asmcomp/alpha/proc.ml b/asmcomp/alpha/proc.ml new file mode 100644 index 0000000..807ed03 --- /dev/null +++ b/asmcomp/alpha/proc.ml @@ -0,0 +1,217 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.7 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the Alpha processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = true + +(* Registers available for register allocation *) + +(* Register map: + $0 - $7 0 - 7 function results + $8 - $12 8 - 12 general purpose ($9 - $15 are preserved by C) + $13 allocation pointer + $14 allocation limit + $15 trap pointer + $16 - $22 13 - 19 function arguments + $23 - $25 temporaries (for the code gen and for the asm) + $26 - $30 stack ptr, global ptr, etc + $31 always zero + + $f0 - $f7 100 - 107 function results + $f8 - $f15 108 - 115 general purpose ($f2 - $f9 preserved by C) + $f16 - $f23 116 - 123 function arguments + $f24 - $f30 124 - 129 general purpose + $f28 temporary + $f31 always zero *) + +let int_reg_name = [| + (* 0-7 *) "$0"; "$1"; "$2"; "$3"; "$4"; "$5"; "$6"; "$7"; + (* 8-12 *) "$8"; "$9"; "$10"; "$11"; "$12"; + (* 13-19 *) "$16"; "$17"; "$18"; "$19"; "$20"; "$21"; "$22" +|] + +let float_reg_name = [| + (* 100-107 *) "$f0"; "$f1"; "$f2"; "$f3"; "$f4"; "$f5"; "$f6"; "$f7"; + (* 108-115 *) "$f8"; "$f9"; "$f10"; "$f11"; "$f12"; "$f13"; "$f14"; "$f15"; + (* 116-123 *) "$f16"; "$f17"; "$f18"; "$f19"; "$f20"; "$f21"; "$f22"; "$f23"; + (* 124-129 *) "$f24"; "$f25"; "$f26"; "$f27"; "$f29"; "$f30" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 20; 30 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 20 Reg.dummy in + for i = 0 to 19 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 30 Reg.dummy in + for i = 0 to 29 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 13 18 116 123 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 13 18 116 123 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 7 100 107 not_supported res in loc + +(* On the Alpha, C functions have calling conventions similar to those + for Caml functions, except that integer and floating-point registers + for arguments are allocated "in sequence". E.g. a function + taking a float f1 and two ints i2 and i3 will put f1 in the + first float reg, i2 in the second int reg and i3 in the third int reg. *) + +let ext_calling_conventions first_int last_int first_float last_float + make_stack arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; incr int; incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; incr int; incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *) + +let loc_external_arguments arg = + ext_calling_conventions 13 18 116 121 outgoing arg +let loc_external_results res = + let (loc, ofs) = ext_calling_conventions 0 0 100 100 not_supported res in loc +let extcall_use_push = false + +let loc_exn_bucket = phys_reg 0 (* $0 *) + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* $9 - $12, $f2 - $f9 preserved *) + Array.of_list(List.map phys_reg + [0;1;2;3;4;5;6;7;8;13;14;15;16;17;18;19; + 100;101;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124; + 125;126;127;128;129]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 4 + | _ -> 19 +let max_register_pressure = function + Iextcall(_, _) -> [| 4; 8 |] + | _ -> [| 19; 29 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + let as_cmd = + if digital_asm && !Clflags.gprofile + then Config.as ^ " -pg" + else Config.as in + Ccomp.command (as_cmd ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/alpha/reload.ml b/asmcomp/alpha/reload.ml new file mode 100644 index 0000000..ca97bc6 --- /dev/null +++ b/asmcomp/alpha/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.3 1999-11-17 18:56:40 xleroy Exp $ *) + +(* Reloading for the Alpha *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/alpha/scheduling.ml b/asmcomp/alpha/scheduling.ml new file mode 100644 index 0000000..b58cac8 --- /dev/null +++ b/asmcomp/alpha/scheduling.ml @@ -0,0 +1,70 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.6 1999-11-17 18:56:40 xleroy Exp $ *) + +open Arch +open Mach + +(* The Digital Unix assembler does scheduling better than us. + However, the Linux-Alpha assembler does not do scheduling, so we do + a feeble attempt here. *) + +class scheduler = object (self) + +inherit Schedgen.scheduler_generic as super + +(* Latencies (in cycles). Based on the 21064, with some poetic license. *) + +method oper_latency = function + Ireload -> 3 + | Iload(_, _) -> 3 + | Iconst_symbol _ -> 3 (* turned into a load *) + | Iconst_float _ -> 3 (* ends up in a load *) + | Iintop(Imul) -> 23 + | Iintop_imm(Imul, _) -> 23 + | Iaddf -> 6 + | Isubf -> 6 + | Imulf -> 6 + | Idivf -> 63 + | _ -> 2 + (* Most arithmetic instructions can be executed back-to-back in 1 cycle. + However, some combinations (arith; load or arith; store) require 2 + cycles. Also, by claiming 2 cycles instead of 1, we might favor + dual issue. *) + +(* Issue cycles. Rough approximations. *) + +method oper_issue_cycles = function + Iconst_float _ -> 4 (* load from $gp, then load *) + | Ialloc _ -> 4 + | Iintop(Icheckbound) -> 2 + | Iintop_imm(Idiv, _) -> 3 + | Iintop_imm(Imod, _) -> 5 + | Iintop_imm(Icheckbound, _) -> 2 + | Ifloatofint -> 10 + | Iintoffloat -> 10 + | _ -> 1 + +(* Say that reloadgp is not part of a basic block (prevents moving it + past an operation that uses $gp) *) + +method oper_in_basic_block = function + Ispecific(Ireloadgp _) -> false + | op -> super#oper_in_basic_block op + +end + +let fundecl = + if digital_asm + then (fun f -> f) + else (new scheduler)#schedule_fundecl diff --git a/asmcomp/alpha/selection.ml b/asmcomp/alpha/selection.ml new file mode 100644 index 0000000..fd962c0 --- /dev/null +++ b/asmcomp/alpha/selection.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.12 2001-07-24 08:01:25 xleroy Exp $ *) + +(* Instruction selection for the Alpha processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = digital_asm || (n >= 0 && n <= 255) + +method select_addressing = function + (* Force an explicit lda for non-scheduling assemblers, + this allows our scheduler to do a better job. *) + Cconst_symbol s when digital_asm -> + (Ibased(s, 0), Ctuple []) + | Cop((Cadda | Caddi), [Cconst_symbol s; Cconst_int n]) when digital_asm -> + (Ibased(s, n), Ctuple []) + | Cop((Cadda | Caddi), [arg; Cconst_int n]) -> + (Iindexed n, arg) + | Cop((Cadda | Caddi), [arg1; Cop(Caddi, [arg2; Cconst_int n])]) -> + (Iindexed n, Cop(Cadda, [arg1; arg2])) + | arg -> + (Iindexed 0, arg) + +method select_operation op args = + match (op, args) with + (* Recognize shift-add operations *) + ((Caddi|Cadda), + [arg2; Cop(Clsl, [arg1; Cconst_int(2|3 as shift)])]) -> + (Ispecific(if shift = 2 then Iadd4 else Iadd8), [arg1; arg2]) + | ((Caddi|Cadda), + [arg2; Cop(Cmuli, [arg1; Cconst_int(4|8 as mult)])]) -> + (Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2]) + | ((Caddi|Cadda), + [arg2; Cop(Cmuli, [Cconst_int(4|8 as mult); arg1])]) -> + (Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2]) + | (Caddi, [Cop(Clsl, [arg1; Cconst_int(2|3 as shift)]); arg2]) -> + (Ispecific(if shift = 2 then Iadd4 else Iadd8), [arg1; arg2]) + | (Caddi, [Cop(Cmuli, [arg1; Cconst_int(4|8 as mult)]); arg2]) -> + (Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2]) + | (Caddi, [Cop(Cmuli, [Cconst_int(4|8 as mult); arg1]); arg2]) -> + (Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2]) + | (Csubi, [Cop(Clsl, [arg1; Cconst_int(2|3 as shift)]); arg2]) -> + (Ispecific(if shift = 2 then Isub4 else Isub8), [arg1; arg2]) + | (Csubi, [Cop(Cmuli, [Cconst_int(4|8 as mult); arg1]); arg2]) -> + (Ispecific(if mult = 4 then Isub4 else Isub8), [arg1; arg2]) + (* Recognize truncation/normalization of 64-bit integers to 32 bits *) + | (Casr, [Cop(Clsl, [arg; Cconst_int 32]); Cconst_int 32]) -> + (Ispecific Itrunc32, [arg]) + (* Work around various limitations of the GNU assembler *) + | ((Caddi|Cadda), [arg1; Cconst_int n]) + when not (self#is_immediate n) && self#is_immediate (-n) -> + (Iintop_imm(Isub, -n), [arg1]) + | (Cdivi, [arg1; Cconst_int n]) + when (not digital_asm) && n <> 1 lsl (Misc.log2 n) -> + (Iintop Idiv, args) + | (Cmodi, [arg1; Cconst_int n]) + when (not digital_asm) && n <> 1 lsl (Misc.log2 n) -> + (Iintop Imod, args) + | _ -> + super#select_operation op args + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/amd64/arch.ml b/asmcomp/amd64/arch.ml new file mode 100644 index 0000000..99a93eb --- /dev/null +++ b/asmcomp/amd64/arch.ml @@ -0,0 +1,111 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.3 2007-01-01 13:07:35 xleroy Exp $ *) + +(* Machine-specific command-line options *) + +let pic_code = ref true + +let command_line_options = + [ "-fPIC", Arg.Set pic_code, + " Generate position-independent machine code (default)"; + "-fno-PIC", Arg.Clear pic_code, + " Generate position-dependent machine code" ] + +(* Specific operations for the AMD64 processor *) + +open Format + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + | Iindexed2 of int (* reg + reg + displ *) + | Iscaled of int * int (* reg * scale + displ *) + | Iindexed2scaled of int * int (* reg + reg * scale + displ *) + +type specific_operation = + Ilea of addressing_mode (* "lea" gives scaled adds *) + | Istore_int of nativeint * addressing_mode (* Store an integer constant *) + | Istore_symbol of string * addressing_mode (* Store a symbol *) + | Ioffset_loc of int * addressing_mode (* Add a constant to a location *) + | Ifloatarithmem of float_operation * addressing_mode + (* Float arith operation with memory *) +and float_operation = + Ifloatadd | Ifloatsub | Ifloatmul | Ifloatdiv + +(* Sizes, endianness *) + +let big_endian = false + +let size_addr = 8 +let size_int = 8 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + | Iindexed2 n -> Iindexed2(n + delta) + | Iscaled(scale, n) -> Iscaled(scale, n + delta) + | Iindexed2scaled(scale, n) -> Iindexed2scaled(scale, n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + | Iindexed2 n -> 2 + | Iscaled(scale, n) -> 1 + | Iindexed2scaled(scale, n) -> 2 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, 0) -> + fprintf ppf "\"%s\"" s + | Ibased(s, n) -> + fprintf ppf "\"%s\" + %i" s n + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + | Iindexed2 n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a + %a%s" printreg arg.(0) printreg arg.(1) idx + | Iscaled(scale, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a * %i%s" printreg arg.(0) scale idx + | Iindexed2scaled(scale, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a + %a * %i%s" printreg arg.(0) printreg arg.(1) scale idx + +let print_specific_operation printreg op ppf arg = + match op with + | Ilea addr -> print_addressing printreg addr ppf arg + | Istore_int(n, addr) -> + fprintf ppf "[%a] := %nd" (print_addressing printreg addr) arg n + | Istore_symbol(lbl, addr) -> + fprintf ppf "[%a] := \"%s\"" (print_addressing printreg addr) arg lbl + | Ioffset_loc(n, addr) -> + fprintf ppf "[%a] +:= %i" (print_addressing printreg addr) arg n + | Ifloatarithmem(op, addr) -> + let op_name = function + | Ifloatadd -> "+f" + | Ifloatsub -> "-f" + | Ifloatmul -> "*f" + | Ifloatdiv -> "/f" in + fprintf ppf "%a %s float64[%a]" printreg arg.(0) (op_name op) + (print_addressing printreg addr) + (Array.sub arg 1 (Array.length arg - 1)) diff --git a/asmcomp/amd64/emit.mlp b/asmcomp/amd64/emit.mlp new file mode 100644 index 0000000..7f640ce --- /dev/null +++ b/asmcomp/amd64/emit.mlp @@ -0,0 +1,812 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.17 2008-12-03 18:09:08 doligez Exp $ *) + +(* Emission of x86-64 (AMD 64) assembly code *) + +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +let macosx = + match Config.system with + | "macosx" -> true + | _ -> false + + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +let stack_offset = ref 0 + +(* Layout of the stack frame *) + +let frame_required () = + !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0 + +let frame_size () = (* includes return address *) + if frame_required() then begin + let sz = + (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8) + in Misc.align sz 16 + end else + !stack_offset + 8 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + n * 8 + else !stack_offset + (num_stack_slots.(0) + n) * 8 + | Outgoing n -> n + +(* Symbols *) + +let emit_symbol s = + if macosx then emit_string "_"; + Emitaux.emit_symbol '$' s + +let emit_call s = + if !Clflags.dlcode && not macosx + then `call {emit_symbol s}@PLT` + else `call {emit_symbol s}` + +let emit_jump s = + if !Clflags.dlcode && not macosx + then `jmp {emit_symbol s}@PLT` + else `jmp {emit_symbol s}` + +let load_symbol_addr s = + if !Clflags.dlcode + then `movq {emit_symbol s}@GOTPCREL(%rip)` + else if !pic_code + then `leaq {emit_symbol s}(%rip)` + else `movq ${emit_symbol s}` + + +let emit_call s = + if !Clflags.dlcode + then `call {emit_symbol s}@PLT` + else `call {emit_symbol s}` + +let emit_jump s = + if !Clflags.dlcode + then `jmp {emit_symbol s}@PLT` + else `jmp {emit_symbol s}` + +let load_symbol_addr s = + if !Clflags.dlcode + then `movq {emit_symbol s}@GOTPCREL(%rip)` + else if !pic_code + then `leaq {emit_symbol s}(%rip)` + else `movq ${emit_symbol s}` + + +(* Output a label *) + +let emit_label lbl = + emit_string ".L"; emit_int lbl + +(* Output a .align directive. *) + +let emit_align n = + let n = if macosx then Misc.log2 n else n in + ` .align {emit_int n}\n` + +let emit_Llabel fallthrough lbl = + if not fallthrough && !fastcode_flag then emit_align 4; + emit_label lbl + +(* Output a pseudo-register *) + +let emit_reg = function + { loc = Reg r } -> + emit_string (register_name r) + | { loc = Stack s } as r -> + let ofs = slot_offset s (register_class r) in + `{emit_int ofs}(%rsp)` + | { loc = Unknown } -> + assert false + +(* Output a reference to the lower 8, 16 or 32 bits of a register *) + +let reg_low_8_name = + [| "%al"; "%bl"; "%dil"; "%sil"; "%dl"; "%cl"; "%r8b"; "%r9b"; + "%r10b"; "%r11b"; "%bpl"; "%r12b"; "%r13b" |] +let reg_low_16_name = + [| "%ax"; "%bx"; "%di"; "%si"; "%dx"; "%cx"; "%r8w"; "%r9w"; + "%r10w"; "%r11w"; "%bp"; "%r12w"; "%r13w" |] +let reg_low_32_name = + [| "%eax"; "%ebx"; "%edi"; "%esi"; "%edx"; "%ecx"; "%r8d"; "%r9d"; + "%r10d"; "%r11d"; "%ebp"; "%r12d"; "%r13d" |] + +let emit_subreg tbl r = + match r.loc with + Reg r when r < 13 -> + emit_string tbl.(r) + | Stack s -> + let ofs = slot_offset s (register_class r) in + `{emit_int ofs}(%rsp)` + | _ -> + assert false + +let emit_reg8 r = emit_subreg reg_low_8_name r +let emit_reg16 r = emit_subreg reg_low_16_name r +let emit_reg32 r = emit_subreg reg_low_32_name r + +(* Output an addressing mode *) + +let emit_addressing addr r n = + match addr with + | Ibased _ when !Clflags.dlcode -> assert false + | Ibased(s, d) -> + `{emit_symbol s}`; + if d <> 0 then ` + {emit_int d}`; + `(%rip)` + | Iindexed d -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)})` + | Iindexed2 d -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n+1)})` + | Iscaled(2, d) -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n)})` + | Iscaled(scale, d) -> + if d <> 0 then emit_int d; + `(, {emit_reg r.(n)}, {emit_int scale})` + | Iindexed2scaled(scale, d) -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n+1)}, {emit_int scale})` + +(* Record live pointers at call points -- see Emitaux *) + +let record_frame_label live dbg = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset; + fd_debuginfo = dbg } :: !frame_descriptors; + lbl + +let record_frame live dbg = + let lbl = record_frame_label live dbg in `{emit_label lbl}:\n` + +(* Record calls to the GC -- we've moved them out of the way *) + +type gc_call = + { gc_lbl: label; (* Entry label *) + gc_return_lbl: label; (* Where to branch after GC *) + gc_frame: label } (* Label of frame descriptor *) + +let call_gc_sites = ref ([] : gc_call list) + +let emit_call_gc gc = + `{emit_label gc.gc_lbl}: {emit_call "caml_call_gc"}\n`; + `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n` + +(* Record calls to caml_ml_array_bound_error. + In -g mode, we maintain one call to caml_ml_array_bound_error + per bound check site. Without -g, we can share a single call. *) + +type bound_error_call = + { bd_lbl: label; (* Entry label *) + bd_frame: label } (* Label of frame descriptor *) + +let bound_error_sites = ref ([] : bound_error_call list) +let bound_error_call = ref 0 + +let bound_error_label dbg = + if !Clflags.debug then begin + let lbl_bound_error = new_label() in + let lbl_frame = record_frame_label Reg.Set.empty dbg in + bound_error_sites := + { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites; + lbl_bound_error + end else begin + if !bound_error_call = 0 then bound_error_call := new_label(); + !bound_error_call + end + +let emit_call_bound_error bd = + `{emit_label bd.bd_lbl}: {emit_call "caml_ml_array_bound_error"}\n`; + `{emit_label bd.bd_frame}:\n` + +let emit_call_bound_errors () = + List.iter emit_call_bound_error !bound_error_sites; + if !bound_error_call > 0 then + `{emit_label !bound_error_call}: {emit_call "caml_ml_array_bound_error"}\n` + +(* Names for instructions *) + +let instr_for_intop = function + Iadd -> "addq" + | Isub -> "subq" + | Imul -> "imulq" + | Iand -> "andq" + | Ior -> "orq" + | Ixor -> "xorq" + | Ilsl -> "salq" + | Ilsr -> "shrq" + | Iasr -> "sarq" + | _ -> assert false + +let instr_for_floatop = function + Iaddf -> "addsd" + | Isubf -> "subsd" + | Imulf -> "mulsd" + | Idivf -> "divsd" + | _ -> assert false + +let instr_for_floatarithmem = function + Ifloatadd -> "addsd" + | Ifloatsub -> "subsd" + | Ifloatmul -> "mulsd" + | Ifloatdiv -> "divsd" + +let name_for_cond_branch = function + Isigned Ceq -> "e" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "g" + | Isigned Clt -> "l" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a" + | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae" + +(* Output an = 0 or <> 0 test. *) + +let output_test_zero arg = + match arg.loc with + Reg r -> ` testq {emit_reg arg}, {emit_reg arg}\n` + | _ -> ` cmpq $0, {emit_reg arg}\n` + +(* Output a floating-point compare and branch *) + +let emit_float_test cmp neg arg lbl = + begin match cmp with + | Ceq | Cne -> ` ucomisd ` + | _ -> ` comisd ` + end; + `{emit_reg arg.(1)}, {emit_reg arg.(0)}\n`; + let (branch_opcode, need_jp) = + match (cmp, neg) with + (Ceq, false) -> ("je", true) + | (Ceq, true) -> ("jne", true) + | (Cne, false) -> ("jne", true) + | (Cne, true) -> ("je", true) + | (Clt, false) -> ("jb", true) + | (Clt, true) -> ("jae", true) + | (Cle, false) -> ("jbe", true) + | (Cle, true) -> ("ja", true) + | (Cgt, false) -> ("ja", false) + | (Cgt, true) -> ("jbe", false) + | (Cge, false) -> ("jae", true) + | (Cge, true) -> ("jb", false) in + let branch_if_not_comparable = + if cmp = Cne then not neg else neg in + if need_jp then + if branch_if_not_comparable then begin + ` jp {emit_label lbl}\n`; + ` {emit_string branch_opcode} {emit_label lbl}\n` + end else begin + let next = new_label() in + ` jp {emit_label next}\n`; + ` {emit_string branch_opcode} {emit_label lbl}\n`; + `{emit_label next}:\n` + end + else begin + ` {emit_string branch_opcode} {emit_label lbl}\n` + end + +(* Deallocate the stack frame before a return or tail call *) + +let output_epilogue () = + if frame_required() then begin + let n = frame_size() - 8 in + ` addq ${emit_int n}, %rsp\n` + end + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 + +let float_constants = ref ([] : (int * string) list) + +let emit_instr fallthrough i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + if src.typ = Float then + ` movsd {emit_reg src}, {emit_reg dst}\n` + else + ` movq {emit_reg src}, {emit_reg dst}\n` + end + | Lop(Iconst_int n) -> + if n = 0n then begin + match i.res.(0).loc with + Reg n -> ` xorq {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> ` movq $0, {emit_reg i.res.(0)}\n` + end else if n <= 0x7FFFFFFFn && n >= -0x80000000n then + ` movq ${emit_nativeint n}, {emit_reg i.res.(0)}\n` + else + ` movabsq ${emit_nativeint n}, {emit_reg i.res.(0)}\n` + | Lop(Iconst_float s) -> + begin match Int64.bits_of_float (float_of_string s) with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + ` xorpd {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` movlpd {emit_label lbl}(%rip), {emit_reg i.res.(0)}\n` + end + | Lop(Iconst_symbol s) -> + ` {load_symbol_addr s}, {emit_reg i.res.(0)}\n` + | Lop(Icall_ind) -> + ` call *{emit_reg i.arg.(0)}\n`; + record_frame i.live i.dbg + | Lop(Icall_imm(s)) -> + ` {emit_call s}\n`; + record_frame i.live i.dbg + | Lop(Itailcall_ind) -> + output_epilogue(); + ` jmp *{emit_reg i.arg.(0)}\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then + ` jmp {emit_label !tailrec_entry_point}\n` + else begin + output_epilogue(); + ` {emit_jump s}\n` + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + ` {load_symbol_addr s}, %rax\n`; + ` {emit_call "caml_c_call"}\n`; + record_frame i.live i.dbg + end else begin + ` {emit_call s}\n` + end + | Lop(Istackoffset n) -> + if n < 0 + then ` addq ${emit_int(-n)}, %rsp\n` + else ` subq ${emit_int(n)}, %rsp\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + | Word -> + ` movq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Byte_unsigned -> + ` movzbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Byte_signed -> + ` movsbq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Sixteen_unsigned -> + ` movzwq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Sixteen_signed -> + ` movswq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Thirtytwo_unsigned -> + ` movl {emit_addressing addr i.arg 0}, {emit_reg32 dest}\n` + | Thirtytwo_signed -> + ` movslq {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Single -> + ` cvtss2sd {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Double | Double_u -> + ` movlpd {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + end + | Lop(Istore(chunk, addr)) -> + begin match chunk with + | Word -> + ` movq {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Byte_unsigned | Byte_signed -> + ` movb {emit_reg8 i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Sixteen_unsigned | Sixteen_signed -> + ` movw {emit_reg16 i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Thirtytwo_signed | Thirtytwo_unsigned -> + ` movl {emit_reg32 i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Single -> + ` cvtsd2ss {emit_reg i.arg.(0)}, %xmm15\n`; + ` movss %xmm15, {emit_addressing addr i.arg 1}\n` + | Double | Double_u -> + ` movlpd {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_redo = new_label() in + `{emit_label lbl_redo}: subq ${emit_int n}, %r15\n`; + if !Clflags.dlcode then begin + ` {load_symbol_addr "caml_young_limit"}, %rax\n`; + ` cmpq (%rax), %r15\n`; + end else + ` cmpq {emit_symbol "caml_young_limit"}(%rip), %r15\n`; + let lbl_call_gc = new_label() in + let lbl_frame = record_frame_label i.live Debuginfo.none in + ` jb {emit_label lbl_call_gc}\n`; + ` leaq 8(%r15), {emit_reg i.res.(0)}\n`; + call_gc_sites := + { gc_lbl = lbl_call_gc; + gc_return_lbl = lbl_redo; + gc_frame = lbl_frame } :: !call_gc_sites + end else begin + begin match n with + 16 -> ` {emit_call "caml_alloc1"}\n` + | 24 -> ` {emit_call "caml_alloc2"}\n` + | 32 -> ` {emit_call "caml_alloc3"}\n` + | _ -> ` movq ${emit_int n}, %rax\n`; + ` {emit_call "caml_allocN"}\n` + end; + `{record_frame i.live Debuginfo.none} leaq 8(%r15), {emit_reg i.res.(0)}\n` + end + | Lop(Iintop(Icomp cmp)) -> + ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} %al\n`; + ` movzbq %al, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} %al\n`; + ` movzbq %al, {emit_reg i.res.(0)}\n` + | Lop(Iintop Icheckbound) -> + let lbl = bound_error_label i.dbg in + ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + let lbl = bound_error_label i.dbg in + ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop(Idiv | Imod)) -> + ` cqto\n`; + ` idivq {emit_reg i.arg.(1)}\n` + | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) -> + (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %rcx *) + ` {emit_string(instr_for_intop op)} %cl, {emit_reg i.res.(0)}\n` + | Lop(Iintop op) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc -> + ` leaq {emit_int n}({emit_reg i.arg.(0)}), {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) -> + ` incq {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) -> + ` decq {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *) + let l = Misc.log2 n in + ` movq {emit_reg i.arg.(0)}, %rax\n`; + ` addq ${emit_int(n-1)}, {emit_reg i.arg.(0)}\n`; + ` testq %rax, %rax\n`; + ` cmovns %rax, {emit_reg i.arg.(0)}\n`; + ` sarq ${emit_int l}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Imod, n)) -> + (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *) + ` movq {emit_reg i.arg.(0)}, %rax\n`; + ` testq %rax, %rax\n`; + ` leaq {emit_int(n-1)}(%rax), %rax\n`; + ` cmovns {emit_reg i.arg.(0)}, %rax\n`; + ` andq ${emit_int (-n)}, %rax\n`; + ` subq %rax, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(op, n)) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} ${emit_int n}, {emit_reg i.res.(0)}\n` + | Lop(Inegf) -> + ` xorpd {emit_symbol "caml_negf_mask"}(%rip), {emit_reg i.res.(0)}\n` + | Lop(Iabsf) -> + ` andpd {emit_symbol "caml_absf_mask"}(%rip), {emit_reg i.res.(0)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as floatop) -> + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Ifloatofint) -> + ` cvtsi2sdq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintoffloat) -> + ` cvttsd2siq {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Ispecific(Ilea addr)) -> + ` leaq {emit_addressing addr i.arg 0}, {emit_reg i.res.(0)}\n` + | Lop(Ispecific(Istore_int(n, addr))) -> + ` movq ${emit_nativeint n}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Istore_symbol(s, addr))) -> + assert (not !pic_code && not !Clflags.dlcode); + ` movq ${emit_symbol s}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Ioffset_loc(n, addr))) -> + ` addq ${emit_int n}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Ifloatarithmem(op, addr))) -> + ` {emit_string(instr_for_floatarithmem op)} {emit_addressing addr i.arg 1}, {emit_reg i.res.(0)}\n` + | Lreloadretaddr -> + () + | Lreturn -> + output_epilogue(); + ` ret\n` + | Llabel lbl -> + `{emit_Llabel fallthrough lbl}:\n` + | Lbranch lbl -> + ` jmp {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + output_test_zero i.arg.(0); + ` jne {emit_label lbl}\n` + | Ifalsetest -> + output_test_zero i.arg.(0); + ` je {emit_label lbl}\n` + | Iinttest cmp -> + ` cmpq {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm((Isigned Ceq | Isigned Cne | + Iunsigned Ceq | Iunsigned Cne) as cmp, 0) -> + output_test_zero i.arg.(0); + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + ` cmpq ${emit_int n}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + emit_float_test cmp neg i.arg lbl + | Ioddtest -> + ` testb $1, {emit_reg8 i.arg.(0)}\n`; + ` jne {emit_label lbl}\n` + | Ieventest -> + ` testb $1, {emit_reg8 i.arg.(0)}\n`; + ` je {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmpq $1, {emit_reg i.arg.(0)}\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` jb {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` je {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` jg {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl = new_label() in + if !pic_code || !Clflags.dlcode then begin + (* PR#4424: r11 is known to be clobbered by the Lswitch, + meaning that no variable that is live across the Lswitch + is assigned to r11. However, the argument to Lswitch + can still be assigned to r11, so we need to special-case + this situation. *) + if i.arg.(0).loc = Reg 9 (* ie r11, cf amd64/proc.ml *) then begin + ` salq $3, %r11\n`; + ` pushq %r11\n`; + ` leaq {emit_label lbl}(%rip), %r11\n`; + ` addq 0(%rsp), %r11\n`; + ` addq $8, %rsp\n`; + ` jmp *(%r11)\n` + end else begin + ` leaq {emit_label lbl}(%rip), %r11\n`; + ` jmp *(%r11, {emit_reg i.arg.(0)}, 8)\n` + end + end else begin + ` jmp *{emit_label lbl}(, {emit_reg i.arg.(0)}, 8)\n` + end; + if macosx + then ` .const\n` + else ` .section .rodata\n`; + emit_align 8; + `{emit_label lbl}:`; + for i = 0 to Array.length jumptbl - 1 do + ` .quad {emit_label jumptbl.(i)}\n` + done; + ` .text\n` + | Lsetuptrap lbl -> + ` call {emit_label lbl}\n` + | Lpushtrap -> + ` pushq %r14\n`; + ` movq %rsp, %r14\n`; + stack_offset := !stack_offset + 16 + | Lpoptrap -> + ` popq %r14\n`; + ` addq $8, %rsp\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + if !Clflags.debug then begin + ` {emit_call "caml_raise_exn"}\n`; + record_frame Reg.Set.empty i.dbg + end else begin + ` movq %r14, %rsp\n`; + ` popq %r14\n`; + ` ret\n` + end + +let rec emit_all fallthrough i = + match i.desc with + | Lend -> () + | _ -> + emit_instr fallthrough i; + emit_all (Linearize.has_fallthrough i.desc) i.next + +(* Emission of the floating-point constants *) + +let emit_float_constant (lbl, cst) = + `{emit_label lbl}: .double {emit_string cst}\n` + +(* Emission of the profiling prelude *) + +let emit_profile () = + match Config.system with + | "linux" | "gnu" -> + (* mcount preserves rax, rcx, rdx, rsi, rdi, r8, r9 explicitly + and rbx, rbp, r12-r15 like all C functions. + We need to preserve r10 and r11 ourselves, since Caml can + use them for argument passing. *) + ` pushq %r10\n`; + ` movq %rsp, %rbp\n`; + ` pushq %r11\n`; + ` {emit_call "mcount"}\n`; + ` popq %r11\n`; + ` popq %r10\n` + | _ -> + () (*unsupported yet*) + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + float_constants := []; + call_gc_sites := []; + bound_error_sites := []; + bound_error_call := 0; + ` .text\n`; + emit_align 16; + ` .globl {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + if !Clflags.gprofile then emit_profile(); + if frame_required() then begin + let n = frame_size() - 8 in + ` subq ${emit_int n}, %rsp\n` + end; + `{emit_label !tailrec_entry_point}:\n`; + emit_all true fundecl.fun_body; + List.iter emit_call_gc !call_gc_sites; + emit_call_bound_errors (); + if !float_constants <> [] then begin + if macosx + then ` .literal8\n` + else ` .section .rodata.cst8,\"a\",@progbits\n`; + List.iter emit_float_constant !float_constants + end; + match Config.system with + "linux" | "gnu" -> + ` .type {emit_symbol fundecl.fun_name},@function\n`; + ` .size {emit_symbol fundecl.fun_name},.-{emit_symbol fundecl.fun_name}\n` + | _ -> () + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .globl {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .word {emit_int n}\n` + | Cint32 n -> + ` .long {emit_nativeint n}\n` + | Cint n -> + ` .quad {emit_nativeint n}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .double {emit_string f}\n` + | Csymbol_address s -> + ` .quad {emit_symbol s}\n` + | Clabel_address lbl -> + ` .quad {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then ` .space {emit_int n}\n` + | Calign n -> + emit_align n + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + if !Clflags.dlcode then begin + (* from amd64.S; could emit these constants on demand *) + if macosx then begin + ` .literal16\n`; + ` .align 4\n`; + `caml_negf_mask: .quad 0x8000000000000000, 0\n`; + ` .align 4\n`; + `caml_absf_mask: .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF\n`; + end else begin + ` .section .rodata.cst8,\"a\",@progbits\n`; + ` .align 16\n`; + `caml_negf_mask: .quad 0x8000000000000000, 0\n`; + ` .align 16\n`; + `caml_absf_mask: .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF\n`; + end; + end; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n` + +let end_assembly() = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .text\n`; + if macosx then ` NOP\n`; (* suppress "ld warning: atom sorting error" *) + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .data\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .long 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + ` .globl {emit_symbol lbl}\n`; + `{emit_symbol lbl}:\n`; + emit_frames + { efa_label = (fun l -> ` .quad {emit_label l}\n`); + efa_16 = (fun n -> ` .word {emit_int n}\n`); + efa_32 = (fun n -> ` .long {emit_int32 n}\n`); + efa_word = (fun n -> ` .quad {emit_int n}\n`); + efa_align = emit_align; + efa_label_rel = + if macosx then begin + let setcnt = ref 0 in + fun lbl ofs -> + incr setcnt; + ` .set L$set${emit_int !setcnt}, ({emit_label lbl} - .) + {emit_int32 ofs}\n`; + ` .long L$set${emit_int !setcnt}\n` + end else begin + fun lbl ofs -> + ` .long ({emit_label lbl} - .) + {emit_int32 ofs}\n` + end; + efa_def_label = (fun l -> `{emit_label l}:\n`); + efa_string = (fun s -> emit_string_directive " .asciz " s) }; + if Config.system = "linux" then + (* Mark stack as non-executable, PR#4564 *) + ` .section .note.GNU-stack,\"\",%progbits\n` + diff --git a/asmcomp/amd64/emit_nt.mlp b/asmcomp/amd64/emit_nt.mlp new file mode 100644 index 0000000..5717f9f --- /dev/null +++ b/asmcomp/amd64/emit_nt.mlp @@ -0,0 +1,771 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit_nt.mlp,v 1.7 2008-01-11 16:13:11 doligez Exp $ *) + +(* Emission of x86-64 (AMD 64) assembly code, MASM syntax *) + +module StringSet = + Set.Make(struct type t = string let compare = compare end) + +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +let stack_offset = ref 0 + +(* Layout of the stack frame *) + +let frame_required () = + !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0 + +let frame_size () = (* includes return address *) + if frame_required() then begin + let sz = + (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8) + in Misc.align sz 16 + end else + !stack_offset + 8 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + n * 8 + else !stack_offset + (num_stack_slots.(0) + n) * 8 + | Outgoing n -> n + +(* Output a 32 bit integer in hex *) + +let emit_int32 n = emit_printf "0%lxh" n + +(* Symbols *) + +let emit_symbol s = + Emitaux.emit_symbol '$' s + +(* Record symbols used and defined - at the end generate extern for those + used but not defined *) + +let symbols_defined = ref StringSet.empty +let symbols_used = ref StringSet.empty + +let add_def_symbol s = + symbols_defined := StringSet.add s !symbols_defined + +let add_used_symbol s = + symbols_used := StringSet.add s !symbols_used + +(* Output a label *) + +let emit_label lbl = + emit_string "L"; emit_int lbl + +(* Output a .align directive. *) + +let emit_align n = + ` ALIGN {emit_int n}\n` + +let emit_Llabel fallthrough lbl = + if not fallthrough && !fastcode_flag then emit_align 4; + emit_label lbl + +(* Output a pseudo-register *) + +let emit_reg = function + { loc = Reg r } -> + emit_string (register_name r) + | { loc = Stack s; typ = Float } as r -> + let ofs = slot_offset s (register_class r) in + `REAL8 PTR {emit_int ofs}[rsp]` + | { loc = Stack s; typ = _ } as r -> + let ofs = slot_offset s (register_class r) in + `QWORD PTR {emit_int ofs}[rsp]` + | { loc = Unknown } -> + assert false + +(* Output a reference to the lower 8, 16 or 32 bits of a register *) + +let reg_low_8_name = + [| "al"; "bl"; "dil"; "sil"; "dl"; "cl"; "r8b"; "r9b"; + "r10b"; "r11b"; "bpl"; "r12b"; "r13b" |] +let reg_low_16_name = + [| "ax"; "bx"; "di"; "si"; "dx"; "cx"; "r8w"; "r9w"; + "r10w"; "r11w"; "bp"; "r12w"; "r13w" |] +let reg_low_32_name = + [| "eax"; "ebx"; "edi"; "esi"; "edx"; "ecx"; "r8d"; "r9d"; + "r10d"; "r11d"; "ebp"; "r12d"; "r13d" |] + +let emit_subreg tbl pref r = + match r.loc with + Reg r when r < 13 -> + emit_string tbl.(r) + | Stack s -> + let ofs = slot_offset s (register_class r) in + `{emit_string pref} PTR {emit_int ofs}[rsp]` + | _ -> + assert false + +let emit_reg8 r = emit_subreg reg_low_8_name "BYTE" r +let emit_reg16 r = emit_subreg reg_low_16_name "WORD" r +let emit_reg32 r = emit_subreg reg_low_32_name "DWORD" r + +(* Output an addressing mode *) + +let emit_signed_int d = + if d > 0 then emit_char '+'; + if d <> 0 then emit_int d + +let emit_addressing addr r n = + match addr with + Ibased(s, d) -> + add_used_symbol s; + `{emit_symbol s}{emit_signed_int d}` + | Iindexed d -> + `[{emit_reg r.(n)}{emit_signed_int d}]` + | Iindexed2 d -> + `[{emit_reg r.(n)}+{emit_reg r.(n+1)}{emit_signed_int d}]` + | Iscaled(2, d) -> + `[{emit_reg r.(n)}+{emit_reg r.(n)}{emit_signed_int d}]` + | Iscaled(scale, d) -> + `[{emit_reg r.(n)}*{emit_int scale}{emit_signed_int d}]` + | Iindexed2scaled(scale, d) -> + `[{emit_reg r.(n)}+{emit_reg r.(n+1)}*{emit_int scale}{emit_signed_int d}]` + +(* Record live pointers at call points *) + +let record_frame_label live dbg = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset; + fd_debuginfo = dbg } :: !frame_descriptors; + lbl + +let record_frame live dbg = + let lbl = record_frame_label live dbg in `{emit_label lbl}:\n` + +(* Record calls to the GC -- we've moved them out of the way *) + +type gc_call = + { gc_lbl: label; (* Entry label *) + gc_return_lbl: label; (* Where to branch after GC *) + gc_frame: label } (* Label of frame descriptor *) + +let call_gc_sites = ref ([] : gc_call list) + +let emit_call_gc gc = + `{emit_label gc.gc_lbl}: call {emit_symbol "caml_call_gc"}\n`; + `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n` + +(* Record calls to caml_ml_array_bound_error. + In -g mode, we maintain one call to caml_ml_array_bound_error + per bound check site. Without -g, we can share a single call. *) + +type bound_error_call = + { bd_lbl: label; (* Entry label *) + bd_frame: label } (* Label of frame descriptor *) + +let bound_error_sites = ref ([] : bound_error_call list) +let bound_error_call = ref 0 + +let bound_error_label dbg = + if !Clflags.debug then begin + let lbl_bound_error = new_label() in + let lbl_frame = record_frame_label Reg.Set.empty dbg in + bound_error_sites := + { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites; + lbl_bound_error + end else begin + if !bound_error_call = 0 then bound_error_call := new_label(); + !bound_error_call + end + +let emit_call_bound_error bd = + `{emit_label bd.bd_lbl}: call caml_ml_array_bound_error\n`; + `{emit_label bd.bd_frame}:\n` + +let emit_call_bound_errors () = + List.iter emit_call_bound_error !bound_error_sites; + if !bound_error_call > 0 then + `{emit_label !bound_error_call}: call caml_ml_array_bound_error\n` + +(* Names for instructions *) + +let instr_for_intop = function + Iadd -> "add" + | Isub -> "sub" + | Imul -> "imul" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "sal" + | Ilsr -> "shr" + | Iasr -> "sar" + | _ -> assert false + +let instr_for_floatop = function + Iaddf -> "addsd" + | Isubf -> "subsd" + | Imulf -> "mulsd" + | Idivf -> "divsd" + | _ -> assert false + +let instr_for_floatarithmem = function + Ifloatadd -> "addsd" + | Ifloatsub -> "subsd" + | Ifloatmul -> "mulsd" + | Ifloatdiv -> "divsd" + +let name_for_cond_branch = function + Isigned Ceq -> "e" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "g" + | Isigned Clt -> "l" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a" + | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae" + +(* Output an = 0 or <> 0 test. *) + +let output_test_zero arg = + match arg.loc with + Reg r -> ` test {emit_reg arg}, {emit_reg arg}\n` + | _ -> ` cmp {emit_reg arg}, 0\n` + +(* Output a floating-point compare and branch *) + +let emit_float_test cmp neg arg lbl = + begin match cmp with + | Ceq | Cne -> ` ucomisd ` + | _ -> ` comisd ` + end; + `{emit_reg arg.(0)}, {emit_reg arg.(1)}\n`; + let (branch_opcode, need_jp) = + match (cmp, neg) with + (Ceq, false) -> ("je", true) + | (Ceq, true) -> ("jne", true) + | (Cne, false) -> ("jne", true) + | (Cne, true) -> ("je", true) + | (Clt, false) -> ("jb", true) + | (Clt, true) -> ("jae", true) + | (Cle, false) -> ("jbe", true) + | (Cle, true) -> ("ja", true) + | (Cgt, false) -> ("ja", false) + | (Cgt, true) -> ("jbe", false) + | (Cge, false) -> ("jae", true) + | (Cge, true) -> ("jb", false) in + let branch_if_not_comparable = + if cmp = Cne then not neg else neg in + if need_jp then + if branch_if_not_comparable then begin + ` jp {emit_label lbl}\n`; + ` {emit_string branch_opcode} {emit_label lbl}\n` + end else begin + let next = new_label() in + ` jp {emit_label next}\n`; + ` {emit_string branch_opcode} {emit_label lbl}\n`; + `{emit_label next}:\n` + end + else begin + ` {emit_string branch_opcode} {emit_label lbl}\n` + end + +(* Deallocate the stack frame before a return or tail call *) + +let output_epilogue () = + if frame_required() then begin + let n = frame_size() - 8 in + ` add rsp, {emit_int n}\n` + end + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 + +let float_constants = ref ([] : (int * string) list) + +let emit_instr fallthrough i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + if src.typ = Float then + ` movsd {emit_reg dst}, {emit_reg src}\n` + else + ` mov {emit_reg dst}, {emit_reg src}\n` + end + | Lop(Iconst_int n) -> + if n = 0n then begin + match i.res.(0).loc with + Reg n -> ` xor {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> ` mov {emit_reg i.res.(0)}, 0\n` + end else if n >= -0x80000000n && n <= 0x7FFFFFFFn then + ` mov {emit_reg i.res.(0)}, {emit_nativeint n}\n` + else if n >= 0x80000000n && n <= 0xFFFFFFFFn then + (* work around bug in ml64 *) + ` mov {emit_reg32 i.res.(0)}, {emit_nativeint n}\n` + else + (* force ml64 to use mov reg, imm64 instruction *) + ` mov {emit_reg i.res.(0)}, {emit_printf "0%nxH" n}\n` + | Lop(Iconst_float s) -> + begin match Int64.bits_of_float (float_of_string s) with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + ` xorpd {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` movlpd {emit_reg i.res.(0)}, {emit_label lbl}\n` + end + | Lop(Iconst_symbol s) -> + add_used_symbol s; + if !pic_code then + ` lea {emit_reg i.res.(0)}, {emit_symbol s}\n` + else + ` mov {emit_reg i.res.(0)}, OFFSET {emit_symbol s}\n` + | Lop(Icall_ind) -> + ` call {emit_reg i.arg.(0)}\n`; + record_frame i.live i.dbg + | Lop(Icall_imm s) -> + add_used_symbol s; + ` call {emit_symbol s}\n`; + record_frame i.live i.dbg + | Lop(Itailcall_ind) -> + output_epilogue(); + ` jmp {emit_reg i.arg.(0)}\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then + ` jmp {emit_label !tailrec_entry_point}\n` + else begin + add_used_symbol s; + output_epilogue(); + ` jmp {emit_symbol s}\n` + end + | Lop(Iextcall(s, alloc)) -> + add_used_symbol s; + if alloc then begin + ` lea rax, {emit_symbol s}\n`; + ` call {emit_symbol "caml_c_call"}\n`; + record_frame i.live i.dbg + end else begin + ` call {emit_symbol s}\n` + end + | Lop(Istackoffset n) -> + if n < 0 + then ` add rsp, {emit_int(-n)}\n` + else ` sub rsp, {emit_int(n)}\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + | Word -> + ` mov {emit_reg dest}, QWORD PTR {emit_addressing addr i.arg 0}\n` + | Byte_unsigned -> + ` movzx {emit_reg dest}, BYTE PTR {emit_addressing addr i.arg 0}\n` + | Byte_signed -> + ` movsx {emit_reg dest}, BYTE PTR {emit_addressing addr i.arg 0}\n` + | Sixteen_unsigned -> + ` movzx {emit_reg dest}, WORD PTR {emit_addressing addr i.arg 0}\n` + | Sixteen_signed -> + ` movsx {emit_reg dest}, WORD PTR {emit_addressing addr i.arg 0}\n` + | Thirtytwo_unsigned -> + (* load to low 32 bits sets high 32 bits to 0 *) + ` mov {emit_reg32 dest}, DWORD PTR {emit_addressing addr i.arg 0}\n` + | Thirtytwo_signed -> + ` movsxd {emit_reg dest}, DWORD PTR {emit_addressing addr i.arg 0}\n` + | Single -> + ` cvtss2sd {emit_reg dest}, REAL4 PTR {emit_addressing addr i.arg 0}\n` + | Double | Double_u -> + ` movlpd {emit_reg dest}, REAL8 PTR {emit_addressing addr i.arg 0}\n` + end + | Lop(Istore(chunk, addr)) -> + begin match chunk with + | Word -> + ` mov QWORD PTR {emit_addressing addr i.arg 1}, {emit_reg i.arg.(0)}\n` + | Byte_unsigned | Byte_signed -> + ` mov BYTE PTR {emit_addressing addr i.arg 1}, {emit_reg8 i.arg.(0)}\n` + | Sixteen_unsigned | Sixteen_signed -> + ` mov WORD PTR {emit_addressing addr i.arg 1}, {emit_reg16 i.arg.(0)}\n` + | Thirtytwo_signed | Thirtytwo_unsigned -> + ` mov DWORD PTR {emit_addressing addr i.arg 1}, {emit_reg32 i.arg.(0)}\n` + | Single -> + ` cvtsd2ss xmm15, {emit_reg i.arg.(0)}\n`; + ` movss REAL4 PTR {emit_addressing addr i.arg 1}, xmm15\n` + | Double | Double_u -> + ` movlpd REAL8 PTR {emit_addressing addr i.arg 1}, {emit_reg i.arg.(0)}\n` + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_redo = new_label() in + `{emit_label lbl_redo}: sub r15, {emit_int n}\n`; + ` cmp r15, {emit_symbol "caml_young_limit"}\n`; + let lbl_call_gc = new_label() in + let lbl_frame = record_frame_label i.live Debuginfo.none in + ` jb {emit_label lbl_call_gc}\n`; + ` lea {emit_reg i.res.(0)}, [r15+8]\n`; + call_gc_sites := + { gc_lbl = lbl_call_gc; + gc_return_lbl = lbl_redo; + gc_frame = lbl_frame } :: !call_gc_sites + end else begin + begin match n with + 16 -> ` call {emit_symbol "caml_alloc1"}\n` + | 24 -> ` call {emit_symbol "caml_alloc2"}\n` + | 32 -> ` call {emit_symbol "caml_alloc3"}\n` + | _ -> ` mov rax, {emit_int n}\n`; + ` call {emit_symbol "caml_allocN"}\n` + end; + `{record_frame i.live Debuginfo.none} lea {emit_reg i.res.(0)}, [r15+8]\n` + end + | Lop(Iintop(Icomp cmp)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} al\n`; + ` movzx {emit_reg i.res.(0)}, al\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} al\n`; + ` movzx {emit_reg i.res.(0)}, al\n` + | Lop(Iintop Icheckbound) -> + let lbl = bound_error_label i.dbg in + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + let lbl = bound_error_label i.dbg in + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop(Idiv | Imod)) -> + ` cqo\n`; + ` idiv {emit_reg i.arg.(1)}\n` + | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) -> + (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %rcx *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, cl\n` + | Lop(Iintop op) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc -> + ` lea {emit_reg i.res.(0)}, {emit_int n}[{emit_reg i.arg.(0)}]\n` + | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) -> + ` inc {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) -> + ` dec {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *) + let l = Misc.log2 n in + ` mov rax, {emit_reg i.arg.(0)}\n`; + ` add {emit_reg i.arg.(0)}, {emit_int(n-1)}\n`; + ` test rax, rax\n`; + ` cmovns {emit_reg i.arg.(0)}, rax\n`; + ` sar {emit_reg i.res.(0)}, {emit_int l}\n` + | Lop(Iintop_imm(Imod, n)) -> + (* Note: i.arg.(0) = i.res.(0) = rdx (cf. selection.ml) *) + ` mov rax, {emit_reg i.arg.(0)}\n`; + ` test rax, rax\n`; + ` lea rax, {emit_int(n-1)}[rax]\n`; + ` cmovns rax, {emit_reg i.arg.(0)}\n`; + ` and rax, {emit_int (-n)}\n`; + ` sub {emit_reg i.res.(0)}, rax\n` + | Lop(Iintop_imm(op, n)) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, {emit_int n}\n` + | Lop(Inegf) -> + ` xorpd {emit_reg i.res.(0)}, {emit_symbol "caml_negf_mask"}\n` + | Lop(Iabsf) -> + ` andpd {emit_reg i.res.(0)}, {emit_symbol "caml_absf_mask"}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as floatop) -> + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.res.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Ifloatofint) -> + ` cvtsi2sd {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n` + | Lop(Iintoffloat) -> + ` cvttsd2si {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n` + | Lop(Ispecific(Ilea addr)) -> + ` lea {emit_reg i.res.(0)}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Istore_int(n, addr))) -> + ` mov QWORD PTR {emit_addressing addr i.arg 0}, {emit_nativeint n}\n` + | Lop(Ispecific(Istore_symbol(s, addr))) -> + assert (not !pic_code); + add_used_symbol s; + ` mov QWORD PTR {emit_addressing addr i.arg 0}, OFFSET {emit_symbol s}\n` + | Lop(Ispecific(Ioffset_loc(n, addr))) -> + ` add QWORD PTR {emit_addressing addr i.arg 0}, {emit_int n}\n` + | Lop(Ispecific(Ifloatarithmem(op, addr))) -> + ` {emit_string(instr_for_floatarithmem op)} {emit_reg i.res.(0)}, REAL8 PTR {emit_addressing addr i.arg 1}\n` + | Lreloadretaddr -> + () + | Lreturn -> + output_epilogue(); + ` ret\n` + | Llabel lbl -> + `{emit_Llabel fallthrough lbl}:\n` + | Lbranch lbl -> + ` jmp {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + output_test_zero i.arg.(0); + ` jne {emit_label lbl}\n` + | Ifalsetest -> + output_test_zero i.arg.(0); + ` je {emit_label lbl}\n` + | Iinttest cmp -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm((Isigned Ceq | Isigned Cne | + Iunsigned Ceq | Iunsigned Cne) as cmp, 0) -> + output_test_zero i.arg.(0); + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + emit_float_test cmp neg i.arg lbl + | Ioddtest -> + ` test {emit_reg8 i.arg.(0)}, 1\n`; + ` jne {emit_label lbl}\n` + | Ieventest -> + ` test {emit_reg8 i.arg.(0)}, 1\n`; + ` je {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmp {emit_reg i.arg.(0)}, 1\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` jb {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` je {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` jg {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl = new_label() in + if !pic_code then begin + ` lea r11, {emit_label lbl}\n`; + ` jmp QWORD PTR [r11+{emit_reg i.arg.(0)}*8]\n` + end else begin + ` jmp QWORD PTR [{emit_reg i.arg.(0)}*8 + {emit_label lbl}]\n` + end; + ` .DATA\n`; + emit_align 8; + `{emit_label lbl} LABEL QWORD\n`; + for i = 0 to Array.length jumptbl - 1 do + ` QWORD {emit_label jumptbl.(i)}\n` + done; + ` .CODE\n` + | Lsetuptrap lbl -> + ` call {emit_label lbl}\n` + | Lpushtrap -> + ` push r14\n`; + ` mov r14, rsp\n`; + stack_offset := !stack_offset + 16 + | Lpoptrap -> + ` pop r14\n`; + ` add rsp, 8\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + if !Clflags.debug then begin + ` call caml_raise_exn\n`; + record_frame Reg.Set.empty i.dbg + end else begin + ` mov rsp, r14\n`; + ` pop r14\n`; + ` ret\n` + end + +let rec emit_all fallthrough i = + match i.desc with + | Lend -> () + | _ -> + emit_instr fallthrough i; + emit_all (Linearize.has_fallthrough i.desc) i.next + +(* Emission of the floating-point constants *) + +let emit_float s = + (* MASM doesn't like floating-point constants such as 2e9. + Turn them into 2.0e9. *) + let pos_e = ref (-1) and pos_dot = ref (-1) in + for i = 0 to String.length s - 1 do + match s.[i] with + 'e'|'E' -> pos_e := i + | '.' -> pos_dot := i + | _ -> () + done; + if !pos_dot < 0 && !pos_e >= 0 then begin + emit_string (String.sub s 0 !pos_e); + emit_string ".0"; + emit_string (String.sub s !pos_e (String.length s - !pos_e)) + end else + emit_string s + +let emit_float_constant (lbl, cst) = + `{emit_label lbl} REAL8 {emit_float cst}\n` + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + float_constants := []; + call_gc_sites := []; + bound_error_sites := []; + bound_error_call := 0; + ` .CODE\n`; + emit_align 16; + add_def_symbol fundecl.fun_name; + ` PUBLIC {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + if frame_required() then begin + let n = frame_size() - 8 in + ` sub rsp, {emit_int n}\n` + end; + `{emit_label !tailrec_entry_point}:\n`; + emit_all true fundecl.fun_body; + List.iter emit_call_gc !call_gc_sites; + emit_call_bound_errors(); + if !float_constants <> [] then begin + ` .DATA\n`; + List.iter emit_float_constant !float_constants + end + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` PUBLIC {emit_symbol s}\n`; + | Cdefine_symbol s -> + add_def_symbol s; + `{emit_symbol s} LABEL QWORD\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)} LABEL QWORD\n` + | Cint8 n -> + ` BYTE {emit_int n}\n` + | Cint16 n -> + ` WORD {emit_int n}\n` + | Cint32 n -> + ` DWORD {emit_nativeint n}\n` + | Cint n -> + ` QWORD {emit_nativeint n}\n` + | Csingle f -> + ` REAL4 {emit_float f}\n` + | Cdouble f -> + ` REAL8 {emit_float f}\n` + | Csymbol_address s -> + add_used_symbol s; + ` QWORD {emit_symbol s}\n` + | Clabel_address lbl -> + ` QWORD {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_bytes_directive " BYTE " s + | Cskip n -> + if n > 0 then ` BYTE {emit_int n} DUP (?)\n` + | Calign n -> + emit_align n + +let data l = + ` .DATA\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + ` EXTRN caml_young_ptr: QWORD\n`; + ` EXTRN caml_young_limit: QWORD\n`; + ` EXTRN caml_exception_pointer: QWORD\n`; + ` EXTRN caml_absf_mask: QWORD\n`; + ` EXTRN caml_negf_mask: QWORD\n`; + ` EXTRN caml_call_gc: NEAR\n`; + ` EXTRN caml_c_call: NEAR\n`; + ` EXTRN caml_allocN: NEAR\n`; + ` EXTRN caml_alloc1: NEAR\n`; + ` EXTRN caml_alloc2: NEAR\n`; + ` EXTRN caml_alloc3: NEAR\n`; + ` EXTRN caml_ml_array_bound_error: NEAR\n`; + ` EXTRN caml_raise_exn: NEAR\n`; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + add_def_symbol lbl_begin; + ` .DATA\n`; + ` PUBLIC {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin} LABEL QWORD\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + add_def_symbol lbl_begin; + ` .CODE\n`; + ` PUBLIC {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin} LABEL QWORD\n` + +let end_assembly() = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + add_def_symbol lbl_end; + ` .CODE\n`; + ` PUBLIC {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end} LABEL QWORD\n`; + ` .DATA\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + add_def_symbol lbl_end; + ` PUBLIC {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end} LABEL QWORD\n`; + ` QWORD 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + add_def_symbol lbl; + ` PUBLIC {emit_symbol lbl}\n`; + `{emit_symbol lbl} LABEL QWORD\n`; + emit_frames + { efa_label = (fun l -> ` QWORD {emit_label l}\n`); + efa_16 = (fun n -> ` WORD {emit_int n}\n`); + efa_32 = (fun n -> ` DWORD {emit_int32 n}\n`); + efa_word = (fun n -> ` QWORD {emit_int n}\n`); + efa_align = emit_align; + efa_label_rel = (fun lbl ofs -> + ` DWORD {emit_label lbl} - THIS BYTE + {emit_int32 ofs}\n`); + efa_def_label = (fun l -> `{emit_label l} LABEL QWORD\n`); + efa_string = (fun s -> emit_bytes_directive " BYTE " (s ^ "\000")) }; + `\n;External functions\n\n`; + StringSet.iter + (fun s -> + if not (StringSet.mem s !symbols_defined) then + ` EXTRN {emit_symbol s}: NEAR\n`) + !symbols_used; + symbols_used := StringSet.empty; + symbols_defined := StringSet.empty; + `END\n` diff --git a/asmcomp/amd64/proc.ml b/asmcomp/amd64/proc.ml new file mode 100644 index 0000000..ef810e2 --- /dev/null +++ b/asmcomp/amd64/proc.ml @@ -0,0 +1,201 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.5 2007-11-06 15:16:55 frisch Exp $ *) + +(* Description of the AMD64 processor *) + +open Misc +open Arch +open Cmm +open Reg +open Mach + +(* Registers available for register allocation *) + +(* Register map: + rax 0 rax - r11: Caml function arguments + rbx 1 rdi - r9: C function arguments + rdi 2 rax: Caml and C function results + rsi 3 rbx, rbp, r12-r15 are preserved by C + rdx 4 + rcx 5 + r8 6 + r9 7 + r10 8 + r11 9 + rbp 10 + r12 11 + r13 12 + r14 trap pointer + r15 allocation pointer + + xmm0 - xmm15 100 - 115 xmm0 - xmm9: Caml function arguments + xmm0 - xmm7: C function arguments + xmm0: Caml and C function results *) + +let int_reg_name = + [| "%rax"; "%rbx"; "%rdi"; "%rsi"; "%rdx"; "%rcx"; "%r8"; "%r9"; + "%r10"; "%r11"; "%rbp"; "%r12"; "%r13" |] + +let float_reg_name = + [| "%xmm0"; "%xmm1"; "%xmm2"; "%xmm3"; "%xmm4"; "%xmm5"; "%xmm6"; "%xmm7"; + "%xmm8"; "%xmm9"; "%xmm10"; "%xmm11"; + "%xmm12"; "%xmm13"; "%xmm14"; "%xmm15" |] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 13; 16 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +(* Pack registers starting at %rax so as to reduce the number of REX + prefixes and thus improve code density *) +let rotate_registers = false + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 13 Reg.dummy in + for i = 0 to 12 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 16 Reg.dummy in + for i = 0 to 15 do v.(i) <- Reg.at_location Float (Reg (100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let rax = phys_reg 0 +let rcx = phys_reg 5 +let rdx = phys_reg 4 +let r11 = phys_reg 9 +let rxmm15 = phys_reg 115 + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Instruction selection *) + +let word_addressed = false + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* keep stack 16-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 9 100 109 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 9 100 109 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +(* C calling convention: + first integer args in rdi, rsi, rdx, rcx, r8, r9 + first float args in xmm0 ... xmm7 + remaining args on stack. + Return value in rax or xmm0. *) + +let loc_external_arguments arg = + calling_conventions 2 7 100 107 outgoing arg +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = rax + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* rbp, rbx, r12-r15 preserved *) + Array.of_list(List.map phys_reg + [0;2;3;4;5;6;7;8;9; + 100;101;102;103;104;105;106;107; + 108;109;110;111;112;113;114;115]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |] + | Iop(Istore(Single, _)) -> [| rxmm15 |] + | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _)) + -> [| rax |] + | Iswitch(_, _) when !pic_code || !Clflags.dlcode -> [| r11 |] + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_,_) -> 0 + | _ -> 11 + +let max_register_pressure = function + Iextcall(_, _) -> [| 4; 0 |] + | Iintop(Idiv | Imod) -> [| 11; 16 |] + | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _) + -> [| 12; 16 |] + | Istore(Single, _) -> [| 13; 15 |] + | _ -> [| 13; 16 |] + +(* Layout of the stack frame *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ outfile ^ " " ^ infile) + diff --git a/asmcomp/amd64/proc_nt.ml b/asmcomp/amd64/proc_nt.ml new file mode 100644 index 0000000..e29e1f2 --- /dev/null +++ b/asmcomp/amd64/proc_nt.ml @@ -0,0 +1,233 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc_nt.ml,v 1.4 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the AMD64 processor with Win64 conventions *) + +open Misc +open Arch +open Cmm +open Reg +open Mach + +(* Registers available for register allocation *) + +(* Register map: + rax 0 rax - r11: Caml function arguments + rbx 1 rcx - r9: C function arguments + rdi 2 rax: Caml and C function results + rsi 3 rbx, rbp, rsi, rdi r12-r15 are preserved by C + rdx 4 + rcx 5 + r8 6 + r9 7 + r10 8 + r11 9 + rbp 10 + r12 11 + r13 12 + r14 trap pointer + r15 allocation pointer + + xmm0 - xmm15 100 - 115 xmm0 - xmm9: Caml function arguments + xmm0 - xmm3: C function arguments + xmm0: Caml and C function results + xmm6-xmm15 are preserved by C *) + +let int_reg_name = + [| "rax"; "rbx"; "rdi"; "rsi"; "rdx"; "rcx"; "r8"; "r9"; + "r10"; "r11"; "rbp"; "r12"; "r13" |] + +let float_reg_name = + [| "xmm0"; "xmm1"; "xmm2"; "xmm3"; "xmm4"; "xmm5"; "xmm6"; "xmm7"; + "xmm8"; "xmm9"; "xmm10"; "xmm11"; "xmm12"; "xmm13"; "xmm14"; "xmm15" |] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 13; 16 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +(* Pack registers starting at %rax so as to reduce the number of REX + prefixes and thus improve code density *) +let rotate_registers = false + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 13 Reg.dummy in + for i = 0 to 12 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 16 Reg.dummy in + for i = 0 to 15 do v.(i) <- Reg.at_location Float (Reg (100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let rax = phys_reg 0 +let rcx = phys_reg 5 +let rdx = phys_reg 4 +let r11 = phys_reg 9 +let rxmm15 = phys_reg 115 + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Instruction selection *) + +let word_addressed = false + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* keep stack 16-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 9 100 109 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 9 100 109 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +(* C calling conventions (Win64): + first integer args in rcx, rdx, r8, r9 (4 - 7) + first float args in xmm0 ... xmm3 (100 - 103) + each integer arg consumes a float reg, and conversely + remaining args on stack + always 32 bytes reserved at bottom of stack. + Return value in rax or xmm0 +*) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let int_external_arguments = + [| 5 (*rcx*); 4 (*rdx*); 6 (*r8*); 7 (*r9*) |] +let float_external_arguments = + [| 100 (*xmm0*); 101 (*xmm1*); 102 (*xmm2*); 103 (*xmm3*) |] + +let loc_external_arguments arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let reg = ref 0 + and ofs = ref 32 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !reg < 4 then begin + loc.(i) <- phys_reg int_external_arguments.(!reg); + incr reg + end else begin + loc.(i) <- stack_slot (Outgoing !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !reg < 4 then begin + loc.(i) <- phys_reg float_external_arguments.(!reg); + incr reg + end else begin + loc.(i) <- stack_slot (Outgoing !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* keep stack 16-aligned *) + +let loc_exn_bucket = rax + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = + (* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *) + Array.of_list(List.map phys_reg + [0;4;5;6;7;8;9; + 100;101;102;103;104;105]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Iintop(Idiv | Imod)) -> [| rax; rdx |] + | Iop(Istore(Single, _)) -> [| rxmm15 |] + | Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _)) + -> [| rax |] + | Iswitch(_, _) when !pic_code -> [| r11 |] + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_,_) -> 8 + | _ -> 11 + +let max_register_pressure = function + Iextcall(_, _) -> [| 8; 10 |] + | Iintop(Idiv | Imod) -> [| 11; 16 |] + | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _) + -> [| 12; 16 |] + | Istore(Single, _) -> [| 13; 15 |] + | _ -> [| 13; 16 |] + +(* Layout of the stack frame *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ + Filename.quote outfile ^ " " ^ + Filename.quote infile ^ "> NUL") diff --git a/asmcomp/amd64/reload.ml b/asmcomp/amd64/reload.ml new file mode 100644 index 0000000..43551be --- /dev/null +++ b/asmcomp/amd64/reload.ml @@ -0,0 +1,121 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.6 2007-11-06 15:16:55 frisch Exp $ *) + +open Cmm +open Arch +open Reg +open Mach + +(* Reloading for the AMD64 *) + +(* Summary of instruction set constraints: + "S" means either stack or register, "R" means register only. + Operation Res Arg1 Arg2 + Imove R S + or S R + Iconst_int S if 32-bit signed, R otherwise + Iconst_float R + Iconst_symbol (not PIC) S + Iconst_symbol (PIC) R + Icall_ind R + Itailcall_ind R + Iload R R R + Istore R R + Iintop(Icomp) R R S + or S S R + Iintop(Imul|Idiv|mod) R R S + Iintop(shift) S S R + Iintop(others) R R S + or S S R + Iintop_imm(Iadd, n)/lea R R + Iintop_imm(others) S S + Inegf...Idivf R R S + Ifloatofint R S + Iintoffloat R S + Ispecific(Ilea) R R R + Ispecific(Ifloatarithmem) R R R + + Conditional branches: + Iinttest S R + or R S + Ifloattest R S + other tests S +*) + +let stackp r = + match r.loc with + Stack _ -> true + | _ -> false + +class reload = object (self) + +inherit Reloadgen.reload_generic as super + +method reload_operation op arg res = + match op with + Iintop(Iadd|Isub|Iand|Ior|Ixor|Icomp _|Icheckbound) -> + (* One of the two arguments can reside in the stack, but not both *) + if stackp arg.(0) && stackp arg.(1) + then ([|arg.(0); self#makereg arg.(1)|], res) + else (arg, res) + | Iintop_imm(Iadd, _) when arg.(0).loc <> res.(0).loc -> + (* This add will be turned into a lea; args and results must be + in registers *) + super#reload_operation op arg res + | Iintop(Idiv | Imod | Ilsl | Ilsr | Iasr) + | Iintop_imm(_, _) -> + (* The argument(s) and results can be either in register or on stack *) + (* Note: Idiv, Imod: arg(0) and res(0) already forced in regs + Ilsl, Ilsr, Iasr: arg(1) already forced in regs *) + (arg, res) + | Iintop(Imul) | Iaddf | Isubf | Imulf | Idivf -> + (* First argument (= result) must be in register, second arg + can reside in the stack *) + if stackp arg.(0) + then (let r = self#makereg arg.(0) in ([|r; arg.(1)|], [|r|])) + else (arg, res) + | Ifloatofint | Iintoffloat -> + (* Result must be in register, but argument can be on stack *) + (arg, (if stackp res.(0) then [| self#makereg res.(0) |] else res)) + | Iconst_int n -> + if n <= 0x7FFFFFFFn && n >= -0x80000000n + then (arg, res) + else super#reload_operation op arg res + | Iconst_symbol _ -> + if !pic_code || !Clflags.dlcode + then super#reload_operation op arg res + else (arg, res) + | _ -> (* Other operations: all args and results in registers *) + super#reload_operation op arg res + +method reload_test tst arg = + match tst with + Iinttest cmp -> + (* One of the two arguments can reside on stack *) + if stackp arg.(0) && stackp arg.(1) + then [| self#makereg arg.(0); arg.(1) |] + else arg + | Ifloattest(_, _) -> + (* Second argument can be on stack, first must be in register *) + if stackp arg.(0) + then [| self#makereg arg.(0); arg.(1) |] + else arg + | _ -> + (* The argument(s) can be either in register or on stack *) + arg + +end + +let fundecl f = + (new reload)#fundecl f diff --git a/asmcomp/amd64/scheduling.ml b/asmcomp/amd64/scheduling.ml new file mode 100644 index 0000000..e09a275 --- /dev/null +++ b/asmcomp/amd64/scheduling.ml @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.1 2003-06-30 08:28:44 xleroy Exp $ *) + +open Schedgen (* to create a dependency *) + +(* Scheduling is turned off because the processor schedules dynamically + much better than what we could do. *) + +let fundecl f = f diff --git a/asmcomp/amd64/selection.ml b/asmcomp/amd64/selection.ml new file mode 100644 index 0000000..ab8f7f6 --- /dev/null +++ b/asmcomp/amd64/selection.ml @@ -0,0 +1,235 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.8 2008-12-03 18:09:08 doligez Exp $ *) + +(* Instruction selection for the AMD64 *) + +open Misc +open Arch +open Proc +open Cmm +open Reg +open Mach + +(* Auxiliary for recognizing addressing modes *) + +type addressing_expr = + Asymbol of string + | Alinear of expression + | Aadd of expression * expression + | Ascale of expression * int + | Ascaledadd of expression * expression * int + +let rec select_addr exp = + match exp with + Cconst_symbol s when not !Clflags.dlcode -> + (Asymbol s, 0) + | Cop((Caddi | Cadda), [arg; Cconst_int m]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop((Csubi | Csuba), [arg; Cconst_int m]) -> + let (a, n) = select_addr arg in (a, n - m) + | Cop((Caddi | Cadda), [Cconst_int m; arg]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop(Clsl, [arg; Cconst_int(1|2|3 as shift)]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, 1 lsl shift), n lsl shift) + | _ -> (Alinear exp, 0) + end + | Cop(Cmuli, [arg; Cconst_int(2|4|8 as mult)]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, mult), n * mult) + | _ -> (Alinear exp, 0) + end + | Cop(Cmuli, [Cconst_int(2|4|8 as mult); arg]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, mult), n * mult) + | _ -> (Alinear exp, 0) + end + | Cop((Caddi | Cadda), [arg1; arg2]) -> + begin match (select_addr arg1, select_addr arg2) with + ((Alinear e1, n1), (Alinear e2, n2)) -> + (Aadd(e1, e2), n1 + n2) + | ((Alinear e1, n1), (Ascale(e2, scale), n2)) -> + (Ascaledadd(e1, e2, scale), n1 + n2) + | ((Ascale(e1, scale), n1), (Alinear e2, n2)) -> + (Ascaledadd(e2, e1, scale), n1 + n2) + | (_, (Ascale(e2, scale), n2)) -> + (Ascaledadd(arg1, e2, scale), n2) + | ((Ascale(e1, scale), n1), _) -> + (Ascaledadd(arg2, e1, scale), n1) + | _ -> + (Aadd(arg1, arg2), 0) + end + | arg -> + (Alinear arg, 0) + +(* Special constraints on operand and result registers *) + +exception Use_default + +let rax = phys_reg 0 +let rcx = phys_reg 5 +let rdx = phys_reg 4 + +let pseudoregs_for_operation op arg res = + match op with + (* Two-address binary operations: arg.(0) and res.(0) must be the same *) + Iintop(Iadd|Isub|Imul|Iand|Ior|Ixor) | Iaddf|Isubf|Imulf|Idivf -> + ([|res.(0); arg.(1)|], res) + (* One-address unary operations: arg.(0) and res.(0) must be the same *) + | Iintop_imm((Iadd|Isub|Imul|Iand|Ior|Ixor|Ilsl|Ilsr|Iasr), _) + | Iabsf | Inegf -> + (res, res) + | Ispecific(Ifloatarithmem(_,_)) -> + let arg' = Array.copy arg in + arg'.(0) <- res.(0); + (arg', res) + (* For shifts with variable shift count, second arg must be in rcx *) + | Iintop(Ilsl|Ilsr|Iasr) -> + ([|res.(0); rcx|], res) + (* For div and mod, first arg must be in rax, rdx is clobbered, + and result is in rax or rdx respectively. + Keep it simple, just force second argument in rcx. *) + | Iintop(Idiv) -> + ([| rax; rcx |], [| rax |]) + | Iintop(Imod) -> + ([| rax; rcx |], [| rdx |]) + (* For div and mod with immediate operand, arg must not be in rax. + Keep it simple, force it in rdx. *) + | Iintop_imm((Idiv|Imod), _) -> + ([| rdx |], [| rdx |]) + (* Other instructions are regular *) + | _ -> raise Use_default + +(* The selector class *) + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = n <= 0x7FFFFFFF && n >= -0x80000000 + +method is_immediate_natint n = n <= 0x7FFFFFFFn && n >= -0x80000000n + +method select_addressing exp = + let (a, d) = select_addr exp in + (* PR#4625: displacement must be a signed 32-bit immediate *) + if d < -0x8000_0000 || d > 0x7FFF_FFFF + then (Iindexed 0, exp) + else match a with + | Asymbol s -> + (Ibased(s, d), Ctuple []) + | Alinear e -> + (Iindexed d, e) + | Aadd(e1, e2) -> + (Iindexed2 d, Ctuple[e1; e2]) + | Ascale(e, scale) -> + (Iscaled(scale, d), e) + | Ascaledadd(e1, e2, scale) -> + (Iindexed2scaled(scale, d), Ctuple[e1; e2]) + +method select_store addr exp = + match exp with + Cconst_int n when self#is_immediate n -> + (Ispecific(Istore_int(Nativeint.of_int n, addr)), Ctuple []) + | Cconst_natint n when self#is_immediate_natint n -> + (Ispecific(Istore_int(n, addr)), Ctuple []) + | Cconst_pointer n when self#is_immediate n -> + (Ispecific(Istore_int(Nativeint.of_int n, addr)), Ctuple []) + | Cconst_natpointer n when self#is_immediate_natint n -> + (Ispecific(Istore_int(n, addr)), Ctuple []) + | Cconst_symbol s when not (!pic_code || !Clflags.dlcode) -> + (Ispecific(Istore_symbol(s, addr)), Ctuple []) + | _ -> + super#select_store addr exp + +method select_operation op args = + match op with + (* Recognize the LEA instruction *) + Caddi | Cadda | Csubi | Csuba -> + begin match self#select_addressing (Cop(op, args)) with + (Iindexed d, _) -> super#select_operation op args + | (Iindexed2 0, _) -> super#select_operation op args + | (addr, arg) -> (Ispecific(Ilea addr), [arg]) + end + (* Recognize (x / cst) and (x % cst) only if cst is a power of 2. *) + | Cdivi -> + begin match args with + [arg1; Cconst_int n] when self#is_immediate n + && n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg1]) + | _ -> (Iintop Idiv, args) + end + | Cmodi -> + begin match args with + [arg1; Cconst_int n] when self#is_immediate n + && n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg1]) + | _ -> (Iintop Imod, args) + end + (* Recognize float arithmetic with memory. *) + | Caddf -> + self#select_floatarith true Iaddf Ifloatadd args + | Csubf -> + self#select_floatarith false Isubf Ifloatsub args + | Cmulf -> + self#select_floatarith true Imulf Ifloatmul args + | Cdivf -> + self#select_floatarith false Idivf Ifloatdiv args + (* Recognize store instructions *) + | Cstore Word -> + begin match args with + [loc; Cop(Caddi, [Cop(Cload _, [loc']); Cconst_int n])] + when loc = loc' && self#is_immediate n -> + let (addr, arg) = self#select_addressing loc in + (Ispecific(Ioffset_loc(n, addr)), [arg]) + | _ -> + super#select_operation op args + end + | _ -> super#select_operation op args + +(* Recognize float arithmetic with mem *) + +method select_floatarith commutative regular_op mem_op args = + match args with + [arg1; Cop(Cload (Double|Double_u), [loc2])] -> + let (addr, arg2) = self#select_addressing loc2 in + (Ispecific(Ifloatarithmem(mem_op, addr)), + [arg1; arg2]) + | [Cop(Cload (Double|Double_u), [loc1]); arg2] when commutative -> + let (addr, arg1) = self#select_addressing loc1 in + (Ispecific(Ifloatarithmem(mem_op, addr)), + [arg2; arg1]) + | [arg1; arg2] -> + (regular_op, [arg1; arg2]) + | _ -> + assert false + +(* Deal with register constraints *) + +method insert_op_debug op dbg rs rd = + try + let (rsrc, rdst) = pseudoregs_for_operation op rs rd in + self#insert_moves rs rsrc; + self#insert_debug (Iop op) dbg rsrc rdst; + self#insert_moves rdst rd; + rd + with Use_default -> + super#insert_op_debug op dbg rs rd + +method insert_op op rs rd = + self#insert_op_debug op Debuginfo.none rs rd + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/arm/arch.ml b/asmcomp/arm/arch.ml new file mode 100644 index 0000000..b8b668a --- /dev/null +++ b/asmcomp/arm/arch.ml @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.9 2002-11-29 15:03:36 xleroy Exp $ *) + +(* Specific operations for the ARM processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Addressing modes *) + +type addressing_mode = + Iindexed of int (* reg + displ *) + +(* We do not support the reg + shifted reg addressing mode, because + what we really need is reg + shifted reg + displ, + and this is decomposed in two instructions (reg + shifted reg -> tmp, + then addressing tmp + displ). *) + +(* Specific operations *) + +type specific_operation = + Ishiftarith of arith_operation * int + | Ishiftcheckbound of int + | Irevsubimm of int + +and arith_operation = + Ishiftadd + | Ishiftsub + | Ishiftsubrev + +(* Sizes, endianness *) + +let big_endian = false + +let size_addr = 4 +let size_int = 4 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing (Iindexed n) delta = Iindexed(n + delta) + +let num_args_addressing (Iindexed n) = 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Iindexed n -> + printreg ppf arg.(0); + if n <> 0 then fprintf ppf " + %i" n + +let print_specific_operation printreg op ppf arg = + match op with + | Ishiftarith(op, shift) -> + let op_name = function + | Ishiftadd -> "+" + | Ishiftsub -> "-" + | Ishiftsubrev -> "-rev" in + let shift_mark = + if shift >= 0 + then sprintf "<< %i" shift + else sprintf ">> %i" (-shift) in + fprintf ppf "%a %s %a %s" + printreg arg.(0) (op_name op) printreg arg.(1) shift_mark + | Ishiftcheckbound n -> + fprintf ppf "check %a >> %i > %a" printreg arg.(0) n printreg arg.(1) + | Irevsubimm n -> + fprintf ppf "%i %s %a" n "-" printreg arg.(0) diff --git a/asmcomp/arm/emit.mlp b/asmcomp/arm/emit.mlp new file mode 100644 index 0000000..d992c2c --- /dev/null +++ b/asmcomp/arm/emit.mlp @@ -0,0 +1,676 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.19 2008-01-11 16:13:11 doligez Exp $ *) + +(* Emission of ARM assembly code *) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Output a label *) + +let emit_label lbl = + emit_string ".L"; emit_int lbl + +(* Output a symbol *) + +let emit_symbol s = + Emitaux.emit_symbol '$' s + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit_arm.emit_reg" + +(* Output the next register after the given pseudo-register *) + +let emit_next_reg r = + match r.loc with + Reg r -> emit_string (register_name(r + 1)) + | _ -> fatal_error "Emit_arm.emit_next_reg" + +(* Layout of the stack frame *) + +let stack_offset = ref 0 + +let frame_size () = + !stack_offset + + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + + (if !contains_calls then 4 else 0) + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + num_stack_slots.(1) * 8 + n * 4 + else !stack_offset + n * 8 + | Outgoing n -> n + +(* Output a stack reference *) + +let emit_stack r = + match r.loc with + Stack s -> + let ofs = slot_offset s (register_class r) in `[sp, #{emit_int ofs}]` + | _ -> fatal_error "Emit_arm.emit_stack" + +(* Output an addressing mode *) + +let emit_addressing addr r n = + match addr with + Iindexed ofs -> + `[{emit_reg r.(n)}, #{emit_int ofs}]` + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := (r lsl 1) + 1 :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + `{emit_label lbl}:` + +let emit_frame fd = + ` .word {emit_label fd.fd_lbl} + 4\n`; + ` .short {emit_int fd.fd_frame_size}\n`; + ` .short {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` .short {emit_int n}\n`) + fd.fd_live_offset; + ` .align 2\n` + +(* Names of various instructions *) + +let name_for_comparison = function + Isigned Ceq -> "eq" | Isigned Cne -> "ne" | Isigned Cle -> "le" + | Isigned Cge -> "ge" | Isigned Clt -> "lt" | Isigned Cgt -> "gt" + | Iunsigned Ceq -> "eq" | Iunsigned Cne -> "ne" | Iunsigned Cle -> "ls" + | Iunsigned Cge -> "cs" | Iunsigned Clt -> "cc" | Iunsigned Cgt -> "hi" + +let name_for_float_comparison cmp neg = + match cmp with + Ceq -> if neg then "ne" else "eq" + | Cne -> if neg then "eq" else "ne" + | Cle -> if neg then "hi" else "ls" + | Cge -> if neg then "lt" else "ge" + | Clt -> if neg then "pl" else "mi" + | Cgt -> if neg then "le" else "gt" + +let name_for_int_operation = function + Iadd -> "add" + | Isub -> "sub" + | Imul -> "mul" + | Iand -> "and" + | Ior -> "orr" + | Ixor -> "eor" + | _ -> assert false + +let name_for_shift_operation = function + Ilsl -> "lsl" + | Ilsr -> "lsr" + | Iasr -> "asr" + | _ -> assert false + +let name_for_shift_int_operation = function + Ishiftadd -> "add" + | Ishiftsub -> "sub" + | Ishiftsubrev -> "rsb" + +let name_for_float_operation = function + Inegf -> "mnfd" + | Iabsf -> "absd" + | Iaddf -> "adfd" + | Isubf -> "sufd" + | Imulf -> "mufd" + | Idivf -> "dvfd" + | Ifloatofint -> "fltd" + | Iintoffloat -> "fixz" + | _ -> assert false + +(* Recognize immediate operands *) + +(* Immediate operands are 8-bit immediate values, zero-extended, and rotated + right by 0, 2, 4, ... 30 bits. + We check only with 8-bit values shifted left 0 to 24 bits. *) + +let rec is_immed n shift = + shift <= 24 && + (Nativeint.logand n (Nativeint.shift_left (Nativeint.of_int 0xFF) shift) = n + || is_immed n (shift + 2)) + +let is_immediate n = is_immed n 0 + +(* General functional to decompose a non-immediate integer constant + into 8-bit chunks shifted left 0 ... 24 bits *) + +let decompose_intconst n fn = + let i = ref n in + let shift = ref 0 in + let ninstr = ref 0 in + while !i <> 0n do + if Nativeint.to_int (Nativeint.shift_right !i !shift) land 3 = 0 then + shift := !shift + 2 + else begin + let mask = Nativeint.shift_left 0xFFn !shift in + let bits = Nativeint.logand !i mask in + fn bits; + shift := !shift + 8; + i := Nativeint.sub !i bits; + incr ninstr + end + done; + !ninstr + +(* Emit a non-immediate integer constant *) + +let emit_complex_intconst r n = + let first = ref true in + decompose_intconst n + (fun bits -> + if !first + then ` mov {emit_reg r}, #{emit_nativeint bits} @ {emit_nativeint n}\n` + else ` add {emit_reg r}, {emit_reg r}, #{emit_nativeint bits}\n`; + first := false) + +(* Adjust sp (up or down) by the given byte amount *) + +let emit_stack_adjustment instr n = + if n <= 0 then 0 else + decompose_intconst (Nativeint.of_int n) + (fun bits -> + ` {emit_string instr} sp, sp, #{emit_nativeint bits}\n`) + +(* Adjust alloc_ptr down by the given byte amount *) + +let emit_alloc_decrement n = + decompose_intconst (Nativeint.of_int n) + (fun bits -> + ` sub alloc_ptr, alloc_ptr, #{emit_nativeint bits}\n`) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Table of symbols referenced *) +let symbol_constants = (Hashtbl.create 11 : (string, int) Hashtbl.t) +(* Table of floating-point literals *) +let float_constants = (Hashtbl.create 11 : (string, int) Hashtbl.t) +(* Total space (in word) occupied by pending literals *) +let num_literals = ref 0 +(* True if we've at least one pending float literal *) +let pending_float = ref false + +(* Label a symbol or float constant *) +let label_constant tbl s size = + try + Hashtbl.find tbl s + with Not_found -> + let lbl = new_label() in + Hashtbl.add tbl s lbl; + num_literals := !num_literals + size; + lbl + +(* Emit all pending constants *) + +let emit_constants () = + Hashtbl.iter + (fun s lbl -> + `{emit_label lbl}: .word {emit_symbol s}\n`) + symbol_constants; + Hashtbl.iter + (fun s lbl -> + `{emit_label lbl}: .double {emit_string s}\n`) + float_constants; + Hashtbl.clear symbol_constants; + Hashtbl.clear float_constants; + num_literals := 0; + pending_float := false + +(* Output the assembly code for an instruction *) + +let emit_instr i = + match i.desc with + Lend -> 0 + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc = dst.loc then 0 else begin + match (src, dst) with + {loc = Reg rs; typ = Int|Addr}, {loc = Reg rd; typ = Int|Addr} -> + ` mov {emit_reg dst}, {emit_reg src}\n`; 1 + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} -> + ` mvfd {emit_reg dst}, {emit_reg src}\n`; 1 + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Int|Addr} -> + ` stfd {emit_reg src}, [sp, #-8]!\n`; + ` ldmfd sp!, \{{emit_reg dst}, {emit_next_reg dst}}\n`; 2 + | {loc = Reg rs; typ = Int|Addr}, {loc = Stack sd} -> + ` str {emit_reg src}, {emit_stack dst}\n`; 1 + | {loc = Reg rs; typ = Float}, {loc = Stack sd} -> + ` stfd {emit_reg src}, {emit_stack dst}\n`; 1 + | {loc = Stack ss; typ = Int|Addr}, {loc = Reg rd} -> + ` ldr {emit_reg dst}, {emit_stack src}\n`; 1 + | {loc = Stack ss; typ = Float}, {loc = Reg rd} -> + ` ldfd {emit_reg dst}, {emit_stack src}\n`; 1 + | _ -> + assert false + end + | Lop(Iconst_int n) -> + let r = i.res.(0) in + let nr = Nativeint.lognot n in + if is_immediate n then begin + ` mov {emit_reg r}, #{emit_nativeint n}\n`; 1 + end else if is_immediate nr then begin + ` mvn {emit_reg r}, #{emit_nativeint nr}\n`; 1 + end else + emit_complex_intconst r n + | Lop(Iconst_float s) -> + begin match Int64.bits_of_float (float_of_string s) with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + ` mvfd {emit_reg i.res.(0)}, #0.0\n` + | _ -> + let lbl = label_constant float_constants s 2 in + pending_float := true; + ` ldfd {emit_reg i.res.(0)}, {emit_label lbl} @ {emit_string s}\n` + end; + 1 + | Lop(Iconst_symbol s) -> + let lbl = label_constant symbol_constants s 1 in + ` ldr {emit_reg i.res.(0)}, {emit_label lbl} @ {emit_symbol s}\n`; 1 + | Lop(Icall_ind) -> + ` mov lr, pc\n`; + `{record_frame i.live} mov pc, {emit_reg i.arg.(0)}\n`; 2 + | Lop(Icall_imm s) -> + `{record_frame i.live} bl {emit_symbol s}\n`; 1 + | Lop(Itailcall_ind) -> + let n = frame_size() in + if !contains_calls then + ` ldr lr, [sp, #{emit_int (n-4)}]\n`; + ignore (emit_stack_adjustment "add" n); + ` mov pc, {emit_reg i.arg.(0)}\n`; 3 + | Lop(Itailcall_imm s) -> + if s = !function_name then begin + ` b {emit_label !tailrec_entry_point}\n`; 1 + end else begin + let n = frame_size() in + if !contains_calls then + ` ldr lr, [sp, #{emit_int (n-4)}]\n`; + ignore (emit_stack_adjustment "add" n); + ` b {emit_symbol s}\n`; 3 + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + let lbl = label_constant symbol_constants s 1 in + ` ldr r10, {emit_label lbl} @ {emit_symbol s}\n`; + `{record_frame i.live} bl caml_c_call\n`; 2 + end else begin + ` bl {emit_symbol s}\n`; 1 + end + | Lop(Istackoffset n) -> + let ninstr = + if n >= 0 + then emit_stack_adjustment "sub" n + else emit_stack_adjustment "add" (-n) in + stack_offset := !stack_offset + n; + ninstr + | Lop(Iload(Single, addr)) -> + let r = i.res.(0) in + ` ldfs {emit_reg r}, {emit_addressing addr i.arg 0}\n`; + ` mvfd {emit_reg r}, {emit_reg r}\n`; + 2 + | Lop(Iload(size, addr)) -> + let r = i.res.(0) in + let instr = + match size with + Byte_unsigned -> "ldrb" + | Byte_signed -> "ldrsb" + | Sixteen_unsigned -> "ldrh" + | Sixteen_signed -> "ldrsh" + | Double | Double_u -> "ldfd" + | _ (* Word | Thirtytwo_signed | Thirtytwo_unsigned *) -> "ldr" in + ` {emit_string instr} {emit_reg r}, {emit_addressing addr i.arg 0}\n`; + 1 + | Lop(Istore(Single, addr)) -> + let r = i.arg.(0) in + ` mvfs f7, {emit_reg r}\n`; + ` stfs f7, {emit_addressing addr i.arg 1}\n`; + 2 + | Lop(Istore(size, addr)) -> + let r = i.arg.(0) in + let instr = + match size with + Byte_unsigned | Byte_signed -> "strb" + | Sixteen_unsigned | Sixteen_signed -> "strh" + | Double | Double_u -> "stfd" + | _ (* Word | Thirtytwo_signed | Thirtytwo_unsigned *) -> "str" in + ` {emit_string instr} {emit_reg r}, {emit_addressing addr i.arg 1}\n`; + 1 + | Lop(Ialloc n) -> + if !fastcode_flag then begin + ` ldr r10, [alloc_limit, #0]\n`; + let ni = emit_alloc_decrement n in + ` cmp alloc_ptr, r10\n`; + `{record_frame i.live} blcc caml_call_gc\n`; + ` add {emit_reg i.res.(0)}, alloc_ptr, #4\n`; + 4 + ni + end else if n = 8 || n = 12 || n = 16 then begin + `{record_frame i.live} bl caml_alloc{emit_int ((n-4)/4)}\n`; + ` add {emit_reg i.res.(0)}, alloc_ptr, #4\n`; 2 + end else begin + let nn = Nativeint.of_int n in + let ni = + if is_immediate nn then begin + ` mov r10, #{emit_int n}\n`; 1 + end else + emit_complex_intconst (phys_reg 8 (*r10*)) nn in + `{record_frame i.live} bl caml_allocN\n`; + ` add {emit_reg i.res.(0)}, alloc_ptr, #4\n`; + 2 + ni + end + | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) -> + let shift = name_for_shift_operation op in + ` mov {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_string shift} {emit_reg i.arg.(1)}\n`; 1 + | Lop(Iintop(Icomp cmp)) -> + let comp = name_for_comparison cmp in + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` mov {emit_reg i.res.(0)}, #0\n`; + ` mov{emit_string comp} {emit_reg i.res.(0)}, #1\n`; 3 + | Lop(Iintop(Icheckbound)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` blls caml_ml_array_bound_error\n`; 2 + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; 1 + | Lop(Iintop_imm(Idiv, n)) -> (* n is a power of 2 *) + let l = Misc.log2 n in + let r = i.res.(0) in + ` movs {emit_reg r}, {emit_reg i.arg.(0)}\n`; + if n <= 256 then + ` addlt {emit_reg r}, {emit_reg r}, #{emit_int (n-1)}\n` + else begin + ` addlt {emit_reg r}, {emit_reg r}, #{emit_int n}\n`; + ` sublt {emit_reg r}, {emit_reg r}, #1\n` + end; + ` mov {emit_reg r}, {emit_reg r}, asr #{emit_int l}\n`; 4 + | Lop(Iintop_imm(Imod, n)) -> (* n is a power of 2 *) + let l = Misc.log2 n in + let a = i.arg.(0) in + let r = i.res.(0) in + let lbl = new_label() in + ` cmp {emit_reg a}, #0\n`; + ` mov {emit_reg r}, {emit_reg a}, lsl #{emit_int (32-l)}\n`; + ` mov {emit_reg r}, {emit_reg r}, lsr #{emit_int (32-l)}\n`; + ` bpl {emit_label lbl}\n`; + ` cmp {emit_reg r}, #0\n`; + ` subne {emit_reg r}, {emit_reg r}, #{emit_int n}\n`; + `{emit_label lbl}:\n`; 6 + | Lop(Iintop_imm((Ilsl | Ilsr | Iasr as op), n)) -> + let shift = name_for_shift_operation op in + ` mov {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_string shift} #{emit_int n}\n`; 1 + | Lop(Iintop_imm(Icomp cmp, n)) -> + let comp = name_for_comparison cmp in + ` cmp {emit_reg i.arg.(0)}, #{emit_int n}\n`; + ` mov {emit_reg i.res.(0)}, #0\n`; + ` mov{emit_string comp} {emit_reg i.res.(0)}, #1\n`; 3 + | Lop(Iintop_imm(Icheckbound, n)) -> + ` cmp {emit_reg i.arg.(0)}, #{emit_int n}\n`; + ` blls caml_ml_array_bound_error\n`; 2 + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, #{emit_int n}\n`; 1 + | Lop(Inegf | Iabsf | Ifloatofint | Iintoffloat as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n`; 1 + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; 1 + | Lop(Ispecific(Ishiftarith(op, shift))) -> + let instr = name_for_shift_int_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}`; + if shift >= 0 + then `, lsl #{emit_int shift}\n` + else `, asr #{emit_int (-shift)}\n`; + 1 + | Lop(Ispecific(Ishiftcheckbound shift)) -> + ` cmp {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}, lsr #{emit_int shift}\n`; + ` blcs caml_ml_array_bound_error\n`; 2 + | Lop(Ispecific(Irevsubimm n)) -> + ` rsb {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, #{emit_int n}\n`; 1 + | Lreloadretaddr -> + let n = frame_size() in + ` ldr lr, [sp, #{emit_int(n-4)}]\n`; 1 + | Lreturn -> + let n = frame_size() in + ignore(emit_stack_adjustment "add" n); + ` mov pc, lr\n`; 2 + | Llabel lbl -> + `{emit_label lbl}:\n`; 0 + | Lbranch lbl -> + ` b {emit_label lbl}\n`; 1 + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + ` cmp {emit_reg i.arg.(0)}, #0\n`; + ` bne {emit_label lbl}\n` + | Ifalsetest -> + ` cmp {emit_reg i.arg.(0)}, #0\n`; + ` beq {emit_label lbl}\n` + | Iinttest cmp -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + let comp = name_for_comparison cmp in + ` b{emit_string comp} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + ` cmp {emit_reg i.arg.(0)}, #{emit_int n}\n`; + let comp = name_for_comparison cmp in + ` b{emit_string comp} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + begin match cmp with + Ceq | Cne -> + ` cmf {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | _ -> + ` cmfe {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + end; + let comp = name_for_float_comparison cmp neg in + ` b{emit_string comp} {emit_label lbl}\n` + | Ioddtest -> + ` tst {emit_reg i.arg.(0)}, #1\n`; + ` bne {emit_label lbl}\n` + | Ieventest -> + ` tst {emit_reg i.arg.(0)}, #1\n`; + ` beq {emit_label lbl}\n` + end; + 2 + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmp {emit_reg i.arg.(0)}, #1\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` blt {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` beq {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` bgt {emit_label lbl}\n` + end; + 4 + | Lswitch jumptbl -> + ` ldr pc, [pc, {emit_reg i.arg.(0)}, lsl #2]\n`; + ` mov r0, r0\n`; (* nop *) + for i = 0 to Array.length jumptbl - 1 do + ` .word {emit_label jumptbl.(i)}\n` + done; + 2 + Array.length jumptbl + | Lsetuptrap lbl -> + ` bl {emit_label lbl}\n`; 1 + | Lpushtrap -> + stack_offset := !stack_offset + 8; + ` stmfd sp!, \{trap_ptr, lr}\n`; + ` mov trap_ptr, sp\n`; 2 + | Lpoptrap -> + ` ldmfd sp!, \{trap_ptr, lr}\n`; + stack_offset := !stack_offset - 8; 1 + | Lraise -> + ` mov sp, trap_ptr\n`; + ` ldmfd sp!, \{trap_ptr, pc}\n`; 2 + +(* Emission of an instruction sequence *) + +let no_fallthrough = function + Lop(Itailcall_ind | Itailcall_imm _) -> true + | Lreturn -> true + | Lbranch _ -> true + | Lswitch _ -> true + | Lraise -> true + | _ -> false + +let rec emit_all ninstr i = + if i.desc = Lend then () else begin + let n = emit_instr i in + let ninstr' = ninstr + n in + let limit = (if !pending_float then 127 else 511) - !num_literals in + if ninstr' >= limit - 32 && no_fallthrough i.desc then begin + emit_constants(); + emit_all 0 i.next + end else + if ninstr' >= limit then begin + let lbl = new_label() in + ` b {emit_label lbl}\n`; + emit_constants(); + `{emit_label lbl}:\n`; + emit_all 0 i.next + end else + emit_all ninstr' i.next + end + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + Hashtbl.clear symbol_constants; + Hashtbl.clear float_constants; + ` .text\n`; + ` .align 0\n`; + ` .global {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + let n = frame_size() in + ignore(emit_stack_adjustment "sub" n); + if !contains_calls then + ` str lr, [sp, #{emit_int(n - 4)}]\n`; + `{emit_label !tailrec_entry_point}:\n`; + emit_all 0 fundecl.fun_body; + emit_constants() + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .global {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (10000 + lbl)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .short {emit_int n}\n` + | Cint32 n -> + ` .word {emit_nativeint n}\n` + | Cint n -> + ` .word {emit_nativeint n}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .align 0\n`; + ` .double {emit_string f}\n` + | Csymbol_address s -> + ` .word {emit_symbol s}\n` + | Clabel_address lbl -> + ` .word {emit_label (10000 + lbl)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then ` .space {emit_int n}\n` + | Calign n -> + ` .align {emit_int(Misc.log2 n)}\n` + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + `trap_ptr .req r11\n`; + `alloc_ptr .req r8\n`; + `alloc_limit .req r9\n`; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .global {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .global {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n` + +let end_assembly () = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .text\n`; + ` .global {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .data\n`; + ` .global {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .word 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + ` .data\n`; + ` .global {emit_symbol lbl}\n`; + `{emit_symbol lbl}:\n`; + ` .word {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + frame_descriptors := [] diff --git a/asmcomp/arm/proc.ml b/asmcomp/arm/proc.ml new file mode 100644 index 0000000..ddf825e --- /dev/null +++ b/asmcomp/arm/proc.ml @@ -0,0 +1,197 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.9 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the ARM processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = false + +(* Registers available for register allocation *) + +(* Register map: + r0 - r7 general purpose (r4 - r7 preserved by C) + r8 allocation pointer (preserved by C) + r9 allocation limit (preserved by C) + r10 general purpose + r11 trap pointer (preserved by C) + r12 general purpose + r13 stack pointer + r14 return address + r15 program counter + + f0 - f6 general purpose (f4 - f6 preserved by C) + f7 temporary +*) + +let int_reg_name = [| + "r0"; "r1"; "r2"; "r3"; "r4"; "r5"; "r6"; "r7"; "r10"; "r12" +|] + +let float_reg_name = [| + "f0"; "f1"; "f2"; "f3"; "f4"; "f5"; "f6" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 10; 7 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 10 Reg.dummy in + for i = 0 to 9 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 7 Reg.dummy in + for i = 0 to 6 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float + make_stack arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, !ofs) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 7 100 103 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 7 100 103 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 7 100 103 not_supported res in loc + +(* Calling conventions for C are as for Caml, except that float arguments + are passed in pairs of integer registers. *) + +let loc_external_arguments arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let reg = ref 0 in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !reg <= 3 then begin + loc.(i) <- phys_reg !reg; + incr reg + end else begin + loc.(i) <- stack_slot (outgoing !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !reg <= 2 then begin + loc.(i) <- phys_reg !reg; + reg := !reg + 2 + end else begin + loc.(i) <- stack_slot (outgoing !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, !ofs) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = phys_reg 0 + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* r4-r9, f4-f6 preserved *) + Array.of_list(List.map phys_reg [0;1;2;3;8;9; 100;101;102;103]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Ialloc(_)) -> [|phys_reg 8|] (* r10 destroyed *) + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 4 + | _ -> 7 +let max_register_pressure = function + Iextcall(_, _) -> [| 4; 4 |] + | _ -> [| 10; 7 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/arm/reload.ml b/asmcomp/arm/reload.ml new file mode 100644 index 0000000..43ab15d --- /dev/null +++ b/asmcomp/arm/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.4 1999-11-17 18:56:41 xleroy Exp $ *) + +(* Reloading for the ARM *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/arm/scheduling.ml b/asmcomp/arm/scheduling.ml new file mode 100644 index 0000000..fc8c745 --- /dev/null +++ b/asmcomp/arm/scheduling.ml @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.4 1999-11-17 18:56:41 xleroy Exp $ *) + +open Mach + +(* Instruction scheduling for the Sparc *) + +class scheduler = object + +inherit Schedgen.scheduler_generic + +(* Scheduling -- based roughly on the Strong ARM *) + +method oper_latency = function + Ireload -> 2 + | Iload(_, _) -> 2 + | Iconst_symbol _ -> 2 (* turned into a load *) + | Iconst_float _ -> 2 (* turned into a load *) + | Iintop(Imul) -> 3 + | Iintop_imm(Imul, _) -> 3 + (* No data available for floatops, let's make educated guesses *) + | Iaddf -> 3 + | Isubf -> 3 + | Imulf -> 5 + | Idivf -> 15 + | _ -> 1 + +(* Issue cycles. Rough approximations *) + +method oper_issue_cycles = function + Ialloc _ -> 4 + | Iintop(Icomp _) -> 3 + | Iintop(Icheckbound) -> 2 + | Iintop_imm(Idiv, _) -> 4 + | Iintop_imm(Imod, _) -> 6 + | Iintop_imm(Icomp _, _) -> 3 + | Iintop_imm(Icheckbound, _) -> 2 + | _ -> 1 + +end + +let fundecl f = (new scheduler)#schedule_fundecl f diff --git a/asmcomp/arm/selection.ml b/asmcomp/arm/selection.ml new file mode 100644 index 0000000..a7af49b --- /dev/null +++ b/asmcomp/arm/selection.ml @@ -0,0 +1,132 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.7 2008-01-11 16:13:11 doligez Exp $ *) + +(* Instruction selection for the ARM processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Immediate operands are 8-bit immediate values, zero-extended, and rotated + right by 0, 2, 4, ... 30 bits. + To avoid problems with Caml's 31-bit arithmetic, + we check only with 8-bit values shifted left 0 to 22 bits. *) + +let rec is_immed n shift = + if shift > 22 then false + else if n land (0xFF lsl shift) = n then true + else is_immed n (shift + 2) + +(* We have 12-bit + sign byte offsets for word accesses, + 8-bit + sign word offsets for float accesses, + and 8-bit + sign byte offsets for bytes and shorts. + Use lowest common denominator. *) + +let is_offset n = n < 256 && n > -256 + +let is_intconst = function Cconst_int n -> true | _ -> false + +(* Instruction selection *) +class selector = object(self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = + n land 0xFF = n || is_immed n 2 + +method select_addressing = function + Cop(Cadda, [arg; Cconst_int n]) when is_offset n -> + (Iindexed n, arg) + | Cop(Cadda, [arg1; Cop(Caddi, [arg2; Cconst_int n])]) when is_offset n -> + (Iindexed n, Cop(Cadda, [arg1; arg2])) + | arg -> + (Iindexed 0, arg) + +method select_shift_arith op shiftop shiftrevop args = + match args with + [arg1; Cop(Clsl, [arg2; Cconst_int n])] + when n > 0 && n < 32 && not(is_intconst arg2) -> + (Ispecific(Ishiftarith(shiftop, n)), [arg1; arg2]) + | [arg1; Cop(Casr, [arg2; Cconst_int n])] + when n > 0 && n < 32 && not(is_intconst arg2) -> + (Ispecific(Ishiftarith(shiftop, -n)), [arg1; arg2]) + | [Cop(Clsl, [arg1; Cconst_int n]); arg2] + when n > 0 && n < 32 && not(is_intconst arg1) -> + (Ispecific(Ishiftarith(shiftrevop, n)), [arg2; arg1]) + | [Cop(Casr, [arg1; Cconst_int n]); arg2] + when n > 0 && n < 32 && not(is_intconst arg1) -> + (Ispecific(Ishiftarith(shiftrevop, -n)), [arg2; arg1]) + | _ -> + super#select_operation op args + +method select_operation op args = + match op with + Cadda | Caddi -> + begin match args with + [arg1; Cconst_int n] when n < 0 && self#is_immediate (-n) -> + (Iintop_imm(Isub, -n), [arg1]) + | _ -> + self#select_shift_arith op Ishiftadd Ishiftadd args + end + | Csuba | Csubi -> + begin match args with + [arg1; Cconst_int n] when n < 0 && self#is_immediate (-n) -> + (Iintop_imm(Iadd, -n), [arg1]) + | [Cconst_int n; arg2] when self#is_immediate n -> + (Ispecific(Irevsubimm n), [arg2]) + | _ -> + self#select_shift_arith op Ishiftsub Ishiftsubrev args + end + | Cmuli -> (* no multiply immediate *) + (Iintop Imul, args) + | Cdivi -> + begin match args with + [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg1]) + | _ -> + (Iextcall("__divsi3", false), args) + end + | Cmodi -> + begin match args with + [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg1]) + | _ -> + (Iextcall("__modsi3", false), args) + end + | Ccheckbound _ -> + begin match args with + [Cop(Clsr, [arg1; Cconst_int n]); arg2] + when n > 0 && n < 32 && not(is_intconst arg2) -> + (Ispecific(Ishiftcheckbound n), [arg1; arg2]) + | _ -> + super#select_operation op args + end + | _ -> super#select_operation op args + +(* In mul rd, rm, rs, the registers rm and rd must be different. + We deal with this by pretending that rm is also a result of the mul + operation. *) + +method insert_op_debug op dbg rs rd = + if op = Iintop(Imul) then begin + self#insert_debug (Iop op) dbg rs [| rd.(0); rs.(0) |]; rd + end else + super#insert_op_debug op dbg rs rd + +end + +let fundecl f = (new selector)#emit_fundecl f + diff --git a/asmcomp/asmgen.ml b/asmcomp/asmgen.ml new file mode 100644 index 0000000..402ed4a --- /dev/null +++ b/asmcomp/asmgen.ml @@ -0,0 +1,138 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmgen.ml,v 1.22 2008-07-24 05:35:22 frisch Exp $ *) + +(* From lambda to assembly code *) + +open Format +open Config +open Clflags +open Misc +open Cmm + +type error = Assembler_error of string + +exception Error of error + +let liveness ppf phrase = + Liveness.fundecl ppf phrase; phrase + +let dump_if ppf flag message phrase = + if !flag then Printmach.phase message ppf phrase + +let pass_dump_if ppf flag message phrase = + dump_if ppf flag message phrase; phrase + +let pass_dump_linear_if ppf flag message phrase = + if !flag then fprintf ppf "*** %s@.%a@." message Printlinear.fundecl phrase; + phrase + +let rec regalloc ppf round fd = + if round > 50 then + fatal_error(fd.Mach.fun_name ^ + ": function too complex, cannot complete register allocation"); + dump_if ppf dump_live "Liveness analysis" fd; + Interf.build_graph fd; + if !dump_interf then Printmach.interferences ppf (); + if !dump_prefer then Printmach.preferences ppf (); + Coloring.allocate_registers(); + dump_if ppf dump_regalloc "After register allocation" fd; + let (newfd, redo_regalloc) = Reload.fundecl fd in + dump_if ppf dump_reload "After insertion of reloading code" newfd; + if redo_regalloc then begin + Reg.reinit(); Liveness.fundecl ppf newfd; regalloc ppf (round + 1) newfd + end else newfd + +let (++) x f = f x + +let compile_fundecl (ppf : formatter) fd_cmm = + Reg.reset(); + fd_cmm + ++ Selection.fundecl + ++ pass_dump_if ppf dump_selection "After instruction selection" + ++ Comballoc.fundecl + ++ pass_dump_if ppf dump_combine "After allocation combining" + ++ liveness ppf + ++ pass_dump_if ppf dump_live "Liveness analysis" + ++ Spill.fundecl + ++ liveness ppf + ++ pass_dump_if ppf dump_spill "After spilling" + ++ Split.fundecl + ++ pass_dump_if ppf dump_split "After live range splitting" + ++ liveness ppf + ++ regalloc ppf 1 + ++ Linearize.fundecl + ++ pass_dump_linear_if ppf dump_linear "Linearized code" + ++ Scheduling.fundecl + ++ pass_dump_linear_if ppf dump_scheduling "After instruction scheduling" + ++ Emit.fundecl + +let compile_phrase ppf p = + if !dump_cmm then fprintf ppf "%a@." Printcmm.phrase p; + match p with + | Cfunction fd -> compile_fundecl ppf fd + | Cdata dl -> Emit.data dl + + +(* For the native toplevel: generates generic functions unless + they are already available in the process *) +let compile_genfuns ppf f = + List.iter + (function + | (Cfunction {fun_name = name}) as ph when f name -> + compile_phrase ppf ph + | _ -> ()) + (Cmmgen.generic_functions true [Compilenv.current_unit_infos ()]) + +let compile_implementation ?toplevel prefixname ppf (size, lam) = + let asmfile = + if !keep_asm_file + then prefixname ^ ext_asm + else Filename.temp_file "camlasm" ext_asm in + let oc = open_out asmfile in + begin try + Emitaux.output_channel := oc; + Emit.begin_assembly(); + Closure.intro size lam + ++ Cmmgen.compunit size + ++ List.iter (compile_phrase ppf) ++ (fun () -> ()); + (match toplevel with None -> () | Some f -> compile_genfuns ppf f); + + (* We add explicit references to external primitive symbols. This + is to ensure that the object files that define these symbols, + when part of a C library, won't be discarded by the linker. + This is important if a module that uses such a symbol is later + dynlinked. *) + + compile_phrase ppf + (Cmmgen.reference_symbols + (List.filter (fun s -> s <> "" && s.[0] <> '%') + (List.map Primitive.native_name !Translmod.primitive_declarations)) + ); + + Emit.end_assembly(); + close_out oc + with x -> + close_out oc; + if !keep_asm_file then () else remove_file asmfile; + raise x + end; + if Proc.assemble_file asmfile (prefixname ^ ext_obj) <> 0 + then raise(Error(Assembler_error asmfile)); + if !keep_asm_file then () else remove_file asmfile + +(* Error report *) + +let report_error ppf = function + | Assembler_error file -> + fprintf ppf "Assembler error, input left in file %s" file diff --git a/asmcomp/asmgen.mli b/asmcomp/asmgen.mli new file mode 100644 index 0000000..c419c01 --- /dev/null +++ b/asmcomp/asmgen.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmgen.mli,v 1.8 2007-11-06 15:16:55 frisch Exp $ *) + +(* From lambda to assembly code *) + +val compile_implementation : + ?toplevel:(string -> bool) -> + string -> Format.formatter -> int * Lambda.lambda -> unit +val compile_phrase : + Format.formatter -> Cmm.phrase -> unit + +type error = Assembler_error of string +exception Error of error +val report_error: Format.formatter -> error -> unit diff --git a/asmcomp/asmlibrarian.ml b/asmcomp/asmlibrarian.ml new file mode 100644 index 0000000..1a67d48 --- /dev/null +++ b/asmcomp/asmlibrarian.ml @@ -0,0 +1,74 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmlibrarian.ml,v 1.14 2005-09-24 16:45:56 xleroy Exp $ *) + +(* Build libraries of .cmx files *) + +open Misc +open Config +open Compilenv + +type error = + File_not_found of string + | Archiver_error of string + +exception Error of error + +let read_info name = + let filename = + try + find_in_path !load_path name + with Not_found -> + raise(Error(File_not_found name)) in + let (info, crc) = Compilenv.read_unit_info filename in + info.ui_force_link <- !Clflags.link_everything; + (* There is no need to keep the approximation in the .cmxa file, + since the compiler will go looking directly for .cmx files. + The linker, which is the only one that reads .cmxa files, does not + need the approximation. *) + info.ui_approx <- Clambda.Value_unknown; + (Filename.chop_suffix filename ".cmx" ^ ext_obj, (info, crc)) + +let create_archive file_list lib_name = + let archive_name = chop_extension_if_any lib_name ^ ext_lib in + let outchan = open_out_bin lib_name in + try + output_string outchan cmxa_magic_number; + let (objfile_list, descr_list) = + List.split (List.map read_info file_list) in + List.iter2 + (fun file_name (unit, crc) -> + Asmlink.check_consistency file_name unit crc) + file_list descr_list; + let infos = + { lib_units = descr_list; + lib_ccobjs = !Clflags.ccobjs; + lib_ccopts = !Clflags.ccopts } in + output_value outchan infos; + if Ccomp.create_archive archive_name objfile_list <> 0 + then raise(Error(Archiver_error archive_name)); + close_out outchan + with x -> + close_out outchan; + remove_file lib_name; + remove_file archive_name; + raise x + +open Format + +let report_error ppf = function + | File_not_found name -> + fprintf ppf "Cannot find file %s" name + | Archiver_error name -> + fprintf ppf "Error while creating the library %s" name + diff --git a/asmcomp/asmlibrarian.mli b/asmcomp/asmlibrarian.mli new file mode 100644 index 0000000..a94750a --- /dev/null +++ b/asmcomp/asmlibrarian.mli @@ -0,0 +1,27 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmlibrarian.mli,v 1.6 2000-04-21 08:10:27 weis Exp $ *) + +(* Build libraries of .cmx files *) + +open Format + +val create_archive: string list -> string -> unit + +type error = + File_not_found of string + | Archiver_error of string + +exception Error of error + +val report_error: formatter -> error -> unit diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml new file mode 100644 index 0000000..28e8d37 --- /dev/null +++ b/asmcomp/asmlink.ml @@ -0,0 +1,383 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmlink.ml,v 1.78 2008-01-31 09:13:07 frisch Exp $ *) + +(* Link a set of .cmx/.o files and produce an executable *) + +open Sys +open Misc +open Config +open Compilenv + +type error = + File_not_found of string + | Not_an_object_file of string + | Missing_implementations of (string * string list) list + | Inconsistent_interface of string * string * string + | Inconsistent_implementation of string * string * string + | Assembler_error of string + | Linking_error + | Multiple_definition of string * string * string + | Missing_cmx of string * string + +exception Error of error + +(* Consistency check between interfaces and implementations *) + +let crc_interfaces = Consistbl.create () +let crc_implementations = Consistbl.create () +let extra_implementations = ref ([] : string list) +let implementations_defined = ref ([] : (string * string) list) +let cmx_required = ref ([] : string list) + +let check_consistency file_name unit crc = + begin try + List.iter + (fun (name, crc) -> + if name = unit.ui_name + then Consistbl.set crc_interfaces name crc file_name + else Consistbl.check crc_interfaces name crc file_name) + unit.ui_imports_cmi + with Consistbl.Inconsistency(name, user, auth) -> + raise(Error(Inconsistent_interface(name, user, auth))) + end; + begin try + List.iter + (fun (name, crc) -> + if crc <> cmx_not_found_crc then + Consistbl.check crc_implementations name crc file_name + else if List.mem name !cmx_required then + raise(Error(Missing_cmx(file_name, name))) + else + extra_implementations := name :: !extra_implementations) + unit.ui_imports_cmx + with Consistbl.Inconsistency(name, user, auth) -> + raise(Error(Inconsistent_implementation(name, user, auth))) + end; + begin try + let source = List.assoc unit.ui_name !implementations_defined in + raise (Error(Multiple_definition(unit.ui_name, file_name, source))) + with Not_found -> () + end; + Consistbl.set crc_implementations unit.ui_name crc file_name; + implementations_defined := + (unit.ui_name, file_name) :: !implementations_defined; + if unit.ui_symbol <> unit.ui_name then + cmx_required := unit.ui_name :: !cmx_required + +let extract_crc_interfaces () = + Consistbl.extract crc_interfaces +let extract_crc_implementations () = + List.fold_left + (fun ncl n -> + if List.mem_assoc n ncl then ncl else (n, cmx_not_found_crc) :: ncl) + (Consistbl.extract crc_implementations) + !extra_implementations + +(* Add C objects and options and "custom" info from a library descriptor. + See bytecomp/bytelink.ml for comments on the order of C objects. *) + +let lib_ccobjs = ref [] +let lib_ccopts = ref [] + +let add_ccobjs l = + if not !Clflags.no_auto_link then begin + lib_ccobjs := l.lib_ccobjs @ !lib_ccobjs; + lib_ccopts := l.lib_ccopts @ !lib_ccopts + end + +let runtime_lib () = + let libname = + if !Clflags.gprofile + then "libasmrunp" ^ ext_lib + else "libasmrun" ^ ext_lib in + try + if !Clflags.nopervasives then [] + else [ find_in_path !load_path libname ] + with Not_found -> + raise(Error(File_not_found libname)) + +let object_file_name name = + let file_name = + try + find_in_path !load_path name + with Not_found -> + fatal_error "Asmlink.object_file_name: not found" in + if Filename.check_suffix file_name ".cmx" then + Filename.chop_suffix file_name ".cmx" ^ ext_obj + else if Filename.check_suffix file_name ".cmxa" then + Filename.chop_suffix file_name ".cmxa" ^ ext_lib + else + fatal_error "Asmlink.object_file_name: bad ext" + +(* First pass: determine which units are needed *) + +let missing_globals = (Hashtbl.create 17 : (string, string list ref) Hashtbl.t) + +let is_required name = + try ignore (Hashtbl.find missing_globals name); true + with Not_found -> false + +let add_required by (name, crc) = + try + let rq = Hashtbl.find missing_globals name in + rq := by :: !rq + with Not_found -> + Hashtbl.add missing_globals name (ref [by]) + +let remove_required name = + Hashtbl.remove missing_globals name + +let extract_missing_globals () = + let mg = ref [] in + Hashtbl.iter (fun md rq -> mg := (md, !rq) :: !mg) missing_globals; + !mg + +type file = + | Unit of string * Compilenv.unit_infos * Digest.t + | Library of string * Compilenv.library_infos + +let read_file obj_name = + let file_name = + try + find_in_path !load_path obj_name + with Not_found -> + raise(Error(File_not_found obj_name)) in + if Filename.check_suffix file_name ".cmx" then begin + (* This is a .cmx file. It must be linked in any case. + Read the infos to see which modules it requires. *) + let (info, crc) = Compilenv.read_unit_info file_name in + Unit (file_name,info,crc) + end + else if Filename.check_suffix file_name ".cmxa" then begin + let infos = + try Compilenv.read_library_info file_name + with Compilenv.Error(Not_a_unit_info _) -> + raise(Error(Not_an_object_file file_name)) + in + Library (file_name,infos) + end + else raise(Error(Not_an_object_file file_name)) + +let scan_file obj_name tolink = match read_file obj_name with + | Unit (file_name,info,crc) -> + (* This is a .cmx file. It must be linked in any case. *) + remove_required info.ui_name; + List.iter (add_required file_name) info.ui_imports_cmx; + (info, file_name, crc) :: tolink + | Library (file_name,infos) -> + (* This is an archive file. Each unit contained in it will be linked + in only if needed. *) + add_ccobjs infos; + List.fold_right + (fun (info, crc) reqd -> + if info.ui_force_link + || !Clflags.link_everything + || is_required info.ui_name + then begin + remove_required info.ui_name; + List.iter (add_required (Printf.sprintf "%s(%s)" + file_name info.ui_name)) + info.ui_imports_cmx; + (info, file_name, crc) :: reqd + end else + reqd) + infos.lib_units tolink + +(* Second pass: generate the startup file and link it with everything else *) + +let make_startup_file ppf filename units_list = + let compile_phrase p = Asmgen.compile_phrase ppf p in + let oc = open_out filename in + Emitaux.output_channel := oc; + Location.input_name := "caml_startup"; (* set name of "current" input *) + Compilenv.reset "_startup"; (* set the name of the "current" compunit *) + Emit.begin_assembly(); + let name_list = + List.flatten (List.map (fun (info,_,_) -> info.ui_defines) units_list) in + compile_phrase (Cmmgen.entry_point name_list); + let units = List.map (fun (info,_,_) -> info) units_list in + List.iter compile_phrase (Cmmgen.generic_functions false units); + Array.iter + (fun name -> compile_phrase (Cmmgen.predef_exception name)) + Runtimedef.builtin_exceptions; + compile_phrase (Cmmgen.global_table name_list); + compile_phrase + (Cmmgen.globals_map + (List.map + (fun (unit,_,crc) -> + try (unit.ui_name, List.assoc unit.ui_name unit.ui_imports_cmi, + crc, + unit.ui_defines) + with Not_found -> assert false) + units_list)); + compile_phrase(Cmmgen.data_segment_table ("_startup" :: name_list)); + compile_phrase(Cmmgen.code_segment_table ("_startup" :: name_list)); + compile_phrase + (Cmmgen.frame_table("_startup" :: "_system" :: name_list)); + + Emit.end_assembly(); + close_out oc + +let make_shared_startup_file ppf units filename = + let compile_phrase p = Asmgen.compile_phrase ppf p in + let oc = open_out filename in + Emitaux.output_channel := oc; + Location.input_name := "caml_startup"; + Compilenv.reset "_shared_startup"; + Emit.begin_assembly(); + List.iter compile_phrase + (Cmmgen.generic_functions true (List.map fst units)); + compile_phrase (Cmmgen.plugin_header units); + compile_phrase + (Cmmgen.global_table + (List.map (fun (ui,_) -> ui.Compilenv.ui_symbol) units)); + (* this is to force a reference to all units, otherwise the linker + might drop some of them (in case of libraries) *) + + Emit.end_assembly(); + close_out oc + + +let call_linker_shared file_list output_name = + if not (Ccomp.call_linker Ccomp.Dll output_name file_list "") + then raise(Error Linking_error) + +let link_shared ppf objfiles output_name = + let units_tolink = List.fold_right scan_file objfiles [] in + List.iter + (fun (info, file_name, crc) -> check_consistency file_name info crc) + units_tolink; + Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs; + let objfiles = List.rev (List.map object_file_name objfiles) @ + !Clflags.ccobjs in + + let startup = + if !Clflags.keep_startup_file + then output_name ^ ".startup" ^ ext_asm + else Filename.temp_file "camlstartup" ext_asm in + make_shared_startup_file ppf + (List.map (fun (ui,_,crc) -> (ui,crc)) units_tolink) startup; + let startup_obj = output_name ^ ".startup" ^ ext_obj in + if Proc.assemble_file startup startup_obj <> 0 + then raise(Error(Assembler_error startup)); + if not !Clflags.keep_startup_file then remove_file startup; + call_linker_shared (startup_obj :: objfiles) output_name; + remove_file startup_obj + +let call_linker file_list startup_file output_name = + let main_dll = !Clflags.output_c_object + && Filename.check_suffix output_name Config.ext_dll + in + let files = startup_file :: (List.rev file_list) in + let files, c_lib = + if (not !Clflags.output_c_object) || main_dll then + files @ (List.rev !Clflags.ccobjs) @ runtime_lib (), + (if !Clflags.nopervasives then "" else Config.native_c_libraries) + else + files, "" + in + let mode = + if main_dll then Ccomp.MainDll + else if !Clflags.output_c_object then Ccomp.Partial + else Ccomp.Exe + in + if not (Ccomp.call_linker mode output_name files c_lib) + then raise(Error Linking_error) + +(* Main entry point *) + +let link ppf objfiles output_name = + let stdlib = + if !Clflags.gprofile then "stdlib.p.cmxa" else "stdlib.cmxa" in + let stdexit = + if !Clflags.gprofile then "std_exit.p.cmx" else "std_exit.cmx" in + let objfiles = + if !Clflags.nopervasives then objfiles + else if !Clflags.output_c_object then stdlib :: objfiles + else stdlib :: (objfiles @ [stdexit]) in + let units_tolink = List.fold_right scan_file objfiles [] in + Array.iter remove_required Runtimedef.builtin_exceptions; + begin match extract_missing_globals() with + [] -> () + | mg -> raise(Error(Missing_implementations mg)) + end; + List.iter + (fun (info, file_name, crc) -> check_consistency file_name info crc) + units_tolink; + Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs; + Clflags.ccopts := !lib_ccopts @ !Clflags.ccopts; (* put user's opts first *) + let startup = + if !Clflags.keep_startup_file then output_name ^ ".startup" ^ ext_asm + else Filename.temp_file "camlstartup" ext_asm in + make_startup_file ppf startup units_tolink; + let startup_obj = Filename.temp_file "camlstartup" ext_obj in + if Proc.assemble_file startup startup_obj <> 0 then + raise(Error(Assembler_error startup)); + try + call_linker (List.map object_file_name objfiles) startup_obj output_name; + if not !Clflags.keep_startup_file then remove_file startup; + remove_file startup_obj + with x -> + remove_file startup_obj; + raise x + +(* Error report *) + +open Format + +let report_error ppf = function + | File_not_found name -> + fprintf ppf "Cannot find file %s" name + | Not_an_object_file name -> + fprintf ppf "The file %s is not a compilation unit description" name + | Missing_implementations l -> + let print_references ppf = function + | [] -> () + | r1 :: rl -> + fprintf ppf "%s" r1; + List.iter (fun r -> fprintf ppf ",@ %s" r) rl in + let print_modules ppf = + List.iter + (fun (md, rq) -> + fprintf ppf "@ @[%s referenced from %a@]" md + print_references rq) in + fprintf ppf + "@[No implementations provided for the following modules:%a@]" + print_modules l + | Inconsistent_interface(intf, file1, file2) -> + fprintf ppf + "@[Files %s@ and %s@ make inconsistent assumptions \ + over interface %s@]" + file1 file2 intf + | Inconsistent_implementation(intf, file1, file2) -> + fprintf ppf + "@[Files %s@ and %s@ make inconsistent assumptions \ + over implementation %s@]" + file1 file2 intf + | Assembler_error file -> + fprintf ppf "Error while assembling %s" file + | Linking_error -> + fprintf ppf "Error during linking" + | Multiple_definition(modname, file1, file2) -> + fprintf ppf + "@[Files %s@ and %s@ both define a module named %s@]" + file1 file2 modname + | Missing_cmx(filename, name) -> + fprintf ppf + "@[File %s@ was compiled without access@ \ + to the .cmx file@ for module %s,@ \ + which was produced by `ocamlopt -for-pack'.@ \ + Please recompile %s@ with the correct `-I' option@ \ + so that %s.cmx@ is found.@]" + filename name filename name diff --git a/asmcomp/asmlink.mli b/asmcomp/asmlink.mli new file mode 100644 index 0000000..b66713a --- /dev/null +++ b/asmcomp/asmlink.mli @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmlink.mli,v 1.12 2007-11-06 15:16:55 frisch Exp $ *) + +(* Link a set of .cmx/.o files and produce an executable or a plugin *) + +open Format + +val link: formatter -> string list -> string -> unit + +val link_shared: formatter -> string list -> string -> unit + +val call_linker_shared: string list -> string -> unit + +val check_consistency: string -> Compilenv.unit_infos -> Digest.t -> unit +val extract_crc_interfaces: unit -> (string * Digest.t) list +val extract_crc_implementations: unit -> (string * Digest.t) list + +type error = + File_not_found of string + | Not_an_object_file of string + | Missing_implementations of (string * string list) list + | Inconsistent_interface of string * string * string + | Inconsistent_implementation of string * string * string + | Assembler_error of string + | Linking_error + | Multiple_definition of string * string * string + | Missing_cmx of string * string + +exception Error of error + +val report_error: formatter -> error -> unit diff --git a/asmcomp/asmpackager.ml b/asmcomp/asmpackager.ml new file mode 100644 index 0000000..ef9a890 --- /dev/null +++ b/asmcomp/asmpackager.ml @@ -0,0 +1,208 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmpackager.ml,v 1.26 2007-11-15 16:09:57 frisch Exp $ *) + +(* "Package" a set of .cmx/.o files into one .cmx/.o file having the + original compilation units as sub-modules. *) + +open Printf +open Misc +open Lambda +open Clambda +open Compilenv + +type error = + Illegal_renaming of string * string + | Forward_reference of string * string + | Wrong_for_pack of string * string + | Linking_error + | Assembler_error of string + | File_not_found of string + + +exception Error of error + +(* Read the unit information from a .cmx file. *) + +type pack_member_kind = PM_intf | PM_impl of unit_infos + +type pack_member = + { pm_file: string; + pm_name: string; + pm_kind: pack_member_kind } + +let read_member_info pack_path file = + let name = + String.capitalize(Filename.basename(chop_extensions file)) in + let kind = + if Filename.check_suffix file ".cmx" then begin + let (info, crc) = Compilenv.read_unit_info file in + if info.ui_name <> name + then raise(Error(Illegal_renaming(file, info.ui_name))); + if info.ui_symbol <> + (Compilenv.current_unit_infos()).ui_symbol ^ "__" ^ info.ui_name + then raise(Error(Wrong_for_pack(file, pack_path))); + Asmlink.check_consistency file info crc; + Compilenv.cache_unit_info info; + PM_impl info + end else + PM_intf in + { pm_file = file; pm_name = name; pm_kind = kind } + +(* Check absence of forward references *) + +let check_units members = + let rec check forbidden = function + [] -> () + | mb :: tl -> + begin match mb.pm_kind with + | PM_intf -> () + | PM_impl infos -> + List.iter + (fun (unit, _) -> + if List.mem unit forbidden + then raise(Error(Forward_reference(mb.pm_file, unit)))) + infos.ui_imports_cmx + end; + check (list_remove mb.pm_name forbidden) tl in + check (List.map (fun mb -> mb.pm_name) members) members + +(* Make the .o file for the package *) + +let make_package_object ppf members targetobj targetname coercion = + let objtemp = + if !Clflags.keep_asm_file + then chop_extension_if_any targetobj ^ ".pack" ^ Config.ext_obj + else + (* Put the full name of the module in the temporary file name + to avoid collisions with MSVC's link /lib in case of successive + packs *) + Filename.temp_file (Compilenv.make_symbol (Some "")) Config.ext_obj in + let components = + List.map + (fun m -> + match m.pm_kind with + | PM_intf -> None + | PM_impl _ -> Some(Ident.create_persistent m.pm_name)) + members in + Asmgen.compile_implementation + (chop_extension_if_any objtemp) ppf + (Translmod.transl_store_package + components (Ident.create_persistent targetname) coercion); + let objfiles = + List.map + (fun m -> chop_extension_if_any m.pm_file ^ Config.ext_obj) + (List.filter (fun m -> m.pm_kind <> PM_intf) members) in + let ok = + Ccomp.call_linker Ccomp.Partial targetobj (objtemp :: objfiles) "" + in + remove_file objtemp; + if not ok then raise(Error Linking_error) + +(* Make the .cmx file for the package *) + +let build_package_cmx members cmxfile = + let unit_names = + List.map (fun m -> m.pm_name) members in + let filter lst = + List.filter (fun (name, crc) -> not (List.mem name unit_names)) lst in + let union lst = + List.fold_left + (List.fold_left + (fun accu n -> if List.mem n accu then accu else n :: accu)) + [] lst in + let units = + List.fold_right + (fun m accu -> + match m.pm_kind with PM_intf -> accu | PM_impl info -> info :: accu) + members [] in + let ui = Compilenv.current_unit_infos() in + let pkg_infos = + { ui_name = ui.ui_name; + ui_symbol = ui.ui_symbol; + ui_defines = + List.flatten (List.map (fun info -> info.ui_defines) units) @ + [ui.ui_symbol]; + ui_imports_cmi = + (ui.ui_name, Env.crc_of_unit ui.ui_name) :: + filter(Asmlink.extract_crc_interfaces()); + ui_imports_cmx = + filter(Asmlink.extract_crc_implementations()); + ui_approx = ui.ui_approx; + ui_curry_fun = + union(List.map (fun info -> info.ui_curry_fun) units); + ui_apply_fun = + union(List.map (fun info -> info.ui_apply_fun) units); + ui_send_fun = + union(List.map (fun info -> info.ui_send_fun) units); + ui_force_link = + List.exists (fun info -> info.ui_force_link) units; + } in + Compilenv.write_unit_info pkg_infos cmxfile + +(* Make the .cmx and the .o for the package *) + +let package_object_files ppf files targetcmx + targetobj targetname coercion = + let pack_path = + match !Clflags.for_package with + | None -> targetname + | Some p -> p ^ "." ^ targetname in + let members = map_left_right (read_member_info pack_path) files in + check_units members; + make_package_object ppf members targetobj targetname coercion; + build_package_cmx members targetcmx + +(* The entry point *) + +let package_files ppf files targetcmx = + let files = + List.map + (fun f -> + try find_in_path !Config.load_path f + with Not_found -> raise(Error(File_not_found f))) + files in + let prefix = chop_extensions targetcmx in + let targetcmi = prefix ^ ".cmi" in + let targetobj = chop_extension_if_any targetcmx ^ Config.ext_obj in + let targetname = String.capitalize(Filename.basename prefix) in + (* Set the name of the current "input" *) + Location.input_name := targetcmx; + (* Set the name of the current compunit *) + Compilenv.reset ?packname:!Clflags.for_package targetname; + try + let coercion = Typemod.package_units files targetcmi targetname in + package_object_files ppf files targetcmx targetobj targetname coercion + with x -> + remove_file targetcmx; remove_file targetobj; + raise x + +(* Error report *) + +open Format + +let report_error ppf = function + Illegal_renaming(file, id) -> + fprintf ppf "Wrong file naming: %s@ contains the code for@ %s" + file id + | Forward_reference(file, ident) -> + fprintf ppf "Forward reference to %s in file %s" ident file + | Wrong_for_pack(file, path) -> + fprintf ppf "File %s@ was not compiled with the `-for-pack %s' option" + file path + | File_not_found file -> + fprintf ppf "File %s not found" file + | Assembler_error file -> + fprintf ppf "Error while assembling %s" file + | Linking_error -> + fprintf ppf "Error during partial linking" diff --git a/asmcomp/asmpackager.mli b/asmcomp/asmpackager.mli new file mode 100644 index 0000000..9cfb360 --- /dev/null +++ b/asmcomp/asmpackager.mli @@ -0,0 +1,30 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asmpackager.mli,v 1.2 2005-08-01 15:51:09 xleroy Exp $ *) + +(* "Package" a set of .cmx/.o files into one .cmx/.o file having the + original compilation units as sub-modules. *) + +val package_files: Format.formatter -> string list -> string -> unit + +type error = + Illegal_renaming of string * string + | Forward_reference of string * string + | Wrong_for_pack of string * string + | Linking_error + | Assembler_error of string + | File_not_found of string + +exception Error of error + +val report_error: Format.formatter -> error -> unit diff --git a/asmcomp/clambda.ml b/asmcomp/clambda.ml new file mode 100644 index 0000000..d2103fe --- /dev/null +++ b/asmcomp/clambda.ml @@ -0,0 +1,66 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: clambda.ml,v 1.17 2007-01-29 12:10:50 xleroy Exp $ *) + +(* A variant of the "lambda" code with direct / indirect calls explicit + and closures explicit too *) + +open Asttypes +open Lambda + +type function_label = string + +type ulambda = + Uvar of Ident.t + | Uconst of structured_constant + | Udirect_apply of function_label * ulambda list * Debuginfo.t + | Ugeneric_apply of ulambda * ulambda list * Debuginfo.t + | Uclosure of (function_label * int * Ident.t list * ulambda) list + * ulambda list + | Uoffset of ulambda * int + | Ulet of Ident.t * ulambda * ulambda + | Uletrec of (Ident.t * ulambda) list * ulambda + | Uprim of primitive * ulambda list * Debuginfo.t + | Uswitch of ulambda * ulambda_switch + | Ustaticfail of int * ulambda list + | Ucatch of int * Ident.t list * ulambda * ulambda + | Utrywith of ulambda * Ident.t * ulambda + | Uifthenelse of ulambda * ulambda * ulambda + | Usequence of ulambda * ulambda + | Uwhile of ulambda * ulambda + | Ufor of Ident.t * ulambda * ulambda * direction_flag * ulambda + | Uassign of Ident.t * ulambda + | Usend of meth_kind * ulambda * ulambda * ulambda list * Debuginfo.t + +and ulambda_switch = + { us_index_consts: int array; + us_actions_consts : ulambda array; + us_index_blocks: int array; + us_actions_blocks: ulambda array} + +(* Description of known functions *) + +type function_description = + { fun_label: function_label; (* Label of direct entry point *) + fun_arity: int; (* Number of arguments *) + mutable fun_closed: bool; (* True if environment not used *) + mutable fun_inline: (Ident.t list * ulambda) option } + +(* Approximation of values *) + +type value_approximation = + Value_closure of function_description * value_approximation + | Value_tuple of value_approximation array + | Value_unknown + | Value_integer of int + | Value_constptr of int diff --git a/asmcomp/clambda.mli b/asmcomp/clambda.mli new file mode 100644 index 0000000..bbf7c0d --- /dev/null +++ b/asmcomp/clambda.mli @@ -0,0 +1,66 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: clambda.mli,v 1.17 2007-01-29 12:10:50 xleroy Exp $ *) + +(* A variant of the "lambda" code with direct / indirect calls explicit + and closures explicit too *) + +open Asttypes +open Lambda + +type function_label = string + +type ulambda = + Uvar of Ident.t + | Uconst of structured_constant + | Udirect_apply of function_label * ulambda list * Debuginfo.t + | Ugeneric_apply of ulambda * ulambda list * Debuginfo.t + | Uclosure of (function_label * int * Ident.t list * ulambda) list + * ulambda list + | Uoffset of ulambda * int + | Ulet of Ident.t * ulambda * ulambda + | Uletrec of (Ident.t * ulambda) list * ulambda + | Uprim of primitive * ulambda list * Debuginfo.t + | Uswitch of ulambda * ulambda_switch + | Ustaticfail of int * ulambda list + | Ucatch of int * Ident.t list * ulambda * ulambda + | Utrywith of ulambda * Ident.t * ulambda + | Uifthenelse of ulambda * ulambda * ulambda + | Usequence of ulambda * ulambda + | Uwhile of ulambda * ulambda + | Ufor of Ident.t * ulambda * ulambda * direction_flag * ulambda + | Uassign of Ident.t * ulambda + | Usend of meth_kind * ulambda * ulambda * ulambda list * Debuginfo.t + +and ulambda_switch = + { us_index_consts: int array; + us_actions_consts: ulambda array; + us_index_blocks: int array; + us_actions_blocks: ulambda array} + +(* Description of known functions *) + +type function_description = + { fun_label: function_label; (* Label of direct entry point *) + fun_arity: int; (* Number of arguments *) + mutable fun_closed: bool; (* True if environment not used *) + mutable fun_inline: (Ident.t list * ulambda) option } + +(* Approximation of values *) + +type value_approximation = + Value_closure of function_description * value_approximation + | Value_tuple of value_approximation array + | Value_unknown + | Value_integer of int + | Value_constptr of int diff --git a/asmcomp/closure.ml b/asmcomp/closure.ml new file mode 100644 index 0000000..a25a915 --- /dev/null +++ b/asmcomp/closure.ml @@ -0,0 +1,803 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: closure.ml,v 1.55 2008-08-01 12:52:14 xleroy Exp $ *) + +(* Introduction of closures, uncurrying, recognition of direct calls *) + +open Misc +open Asttypes +open Primitive +open Lambda +open Switch +open Clambda + +(* Auxiliaries for compiling functions *) + +let rec split_list n l = + if n <= 0 then ([], l) else begin + match l with + [] -> fatal_error "Closure.split_list" + | a::l -> let (l1, l2) = split_list (n-1) l in (a::l1, l2) + end + +let rec build_closure_env env_param pos = function + [] -> Tbl.empty + | id :: rem -> + Tbl.add id (Uprim(Pfield pos, [Uvar env_param], Debuginfo.none)) + (build_closure_env env_param (pos+1) rem) + +(* Auxiliary for accessing globals. We change the name of the global + to the name of the corresponding asm symbol. This is done here + and no longer in Cmmgen so that approximations stored in .cmx files + contain the right names if the -for-pack option is active. *) + +let getglobal id = + Uprim(Pgetglobal (Ident.create_persistent (Compilenv.symbol_for_global id)), + [], Debuginfo.none) + +(* Check if a variable occurs in a [clambda] term. *) + +let occurs_var var u = + let rec occurs = function + Uvar v -> v = var + | Uconst cst -> false + | Udirect_apply(lbl, args, _) -> List.exists occurs args + | Ugeneric_apply(funct, args, _) -> occurs funct || List.exists occurs args + | Uclosure(fundecls, clos) -> List.exists occurs clos + | Uoffset(u, ofs) -> occurs u + | Ulet(id, def, body) -> occurs def || occurs body + | Uletrec(decls, body) -> + List.exists (fun (id, u) -> occurs u) decls || occurs body + | Uprim(p, args, _) -> List.exists occurs args + | Uswitch(arg, s) -> + occurs arg || + occurs_array s.us_actions_consts || occurs_array s.us_actions_blocks + | Ustaticfail (_, args) -> List.exists occurs args + | Ucatch(_, _, body, hdlr) -> occurs body || occurs hdlr + | Utrywith(body, exn, hdlr) -> occurs body || occurs hdlr + | Uifthenelse(cond, ifso, ifnot) -> + occurs cond || occurs ifso || occurs ifnot + | Usequence(u1, u2) -> occurs u1 || occurs u2 + | Uwhile(cond, body) -> occurs cond || occurs body + | Ufor(id, lo, hi, dir, body) -> occurs lo || occurs hi || occurs body + | Uassign(id, u) -> id = var || occurs u + | Usend(_, met, obj, args, _) -> + occurs met || occurs obj || List.exists occurs args + and occurs_array a = + try + for i = 0 to Array.length a - 1 do + if occurs a.(i) then raise Exit + done; + false + with Exit -> + true + in occurs u + +(* Determine whether the estimated size of a clambda term is below + some threshold *) + +let prim_size prim args = + match prim with + Pidentity -> 0 + | Pgetglobal id -> 1 + | Psetglobal id -> 1 + | Pmakeblock(tag, mut) -> 5 + List.length args + | Pfield f -> 1 + | Psetfield(f, isptr) -> if isptr then 4 else 1 + | Pfloatfield f -> 1 + | Psetfloatfield f -> 1 + | Pduprecord _ -> 10 + List.length args + | Pccall p -> (if p.prim_alloc then 10 else 4) + List.length args + | Praise -> 4 + | Pstringlength -> 5 + | Pstringrefs | Pstringsets -> 6 + | Pmakearray kind -> 5 + List.length args + | Parraylength kind -> if kind = Pgenarray then 6 else 2 + | Parrayrefu kind -> if kind = Pgenarray then 12 else 2 + | Parraysetu kind -> if kind = Pgenarray then 16 else 4 + | Parrayrefs kind -> if kind = Pgenarray then 18 else 8 + | Parraysets kind -> if kind = Pgenarray then 22 else 10 + | Pbittest -> 3 + | Pbigarrayref(_, ndims, _, _) -> 4 + ndims * 6 + | Pbigarrayset(_, ndims, _, _) -> 4 + ndims * 6 + | _ -> 2 (* arithmetic and comparisons *) + +(* Very raw approximation of switch cost *) + +let lambda_smaller lam threshold = + let size = ref 0 in + let rec lambda_size lam = + if !size > threshold then raise Exit; + match lam with + Uvar v -> () + | Uconst(Const_base(Const_int _ | Const_char _ | Const_float _ | + Const_int32 _ | Const_int64 _ | Const_nativeint _) | + Const_pointer _) -> incr size + | Uconst _ -> + raise Exit (* avoid duplication of structured constants *) + | Udirect_apply(fn, args, _) -> + size := !size + 4; lambda_list_size args + | Ugeneric_apply(fn, args, _) -> + size := !size + 6; lambda_size fn; lambda_list_size args + | Uclosure(defs, vars) -> + raise Exit (* inlining would duplicate function definitions *) + | Uoffset(lam, ofs) -> + incr size; lambda_size lam + | Ulet(id, lam, body) -> + lambda_size lam; lambda_size body + | Uletrec(bindings, body) -> + raise Exit (* usually too large *) + | Uprim(prim, args, _) -> + size := !size + prim_size prim args; + lambda_list_size args + | Uswitch(lam, cases) -> + if Array.length cases.us_actions_consts > 1 then size := !size + 5 ; + if Array.length cases.us_actions_blocks > 1 then size := !size + 5 ; + lambda_size lam; + lambda_array_size cases.us_actions_consts ; + lambda_array_size cases.us_actions_blocks + | Ustaticfail (_,args) -> lambda_list_size args + | Ucatch(_, _, body, handler) -> + incr size; lambda_size body; lambda_size handler + | Utrywith(body, id, handler) -> + size := !size + 8; lambda_size body; lambda_size handler + | Uifthenelse(cond, ifso, ifnot) -> + size := !size + 2; + lambda_size cond; lambda_size ifso; lambda_size ifnot + | Usequence(lam1, lam2) -> + lambda_size lam1; lambda_size lam2 + | Uwhile(cond, body) -> + size := !size + 2; lambda_size cond; lambda_size body + | Ufor(id, low, high, dir, body) -> + size := !size + 4; lambda_size low; lambda_size high; lambda_size body + | Uassign(id, lam) -> + incr size; lambda_size lam + | Usend(_, met, obj, args, _) -> + size := !size + 8; + lambda_size met; lambda_size obj; lambda_list_size args + and lambda_list_size l = List.iter lambda_size l + and lambda_array_size a = Array.iter lambda_size a in + try + lambda_size lam; !size <= threshold + with Exit -> + false + +(* Check if a clambda term is ``pure'', + that is without side-effects *and* not containing function definitions *) + +let rec is_pure_clambda = function + Uvar v -> true + | Uconst cst -> true + | Uprim((Psetglobal _ | Psetfield _ | Psetfloatfield _ | Pduprecord _ | + Pccall _ | Praise | Poffsetref _ | Pstringsetu | Pstringsets | + Parraysetu _ | Parraysets _ | Pbigarrayset _), _, _) -> false + | Uprim(p, args, _) -> List.for_all is_pure_clambda args + | _ -> false + +(* Simplify primitive operations on integers *) + +let make_const_int n = (Uconst(Const_base(Const_int n)), Value_integer n) +let make_const_ptr n = (Uconst(Const_pointer n), Value_constptr n) +let make_const_bool b = make_const_ptr(if b then 1 else 0) + +let simplif_prim_pure p (args, approxs) dbg = + match approxs with + [Value_integer x] -> + begin match p with + Pidentity -> make_const_int x + | Pnegint -> make_const_int (-x) + | Poffsetint y -> make_const_int (x + y) + | _ -> (Uprim(p, args, dbg), Value_unknown) + end + | [Value_integer x; Value_integer y] -> + begin match p with + Paddint -> make_const_int(x + y) + | Psubint -> make_const_int(x - y) + | Pmulint -> make_const_int(x * y) + | Pdivint when y <> 0 -> make_const_int(x / y) + | Pmodint when y <> 0 -> make_const_int(x mod y) + | Pandint -> make_const_int(x land y) + | Porint -> make_const_int(x lor y) + | Pxorint -> make_const_int(x lxor y) + | Plslint -> make_const_int(x lsl y) + | Plsrint -> make_const_int(x lsr y) + | Pasrint -> make_const_int(x asr y) + | Pintcomp cmp -> + let result = match cmp with + Ceq -> x = y + | Cneq -> x <> y + | Clt -> x < y + | Cgt -> x > y + | Cle -> x <= y + | Cge -> x >= y in + make_const_bool result + | _ -> (Uprim(p, args, dbg), Value_unknown) + end + | [Value_constptr x] -> + begin match p with + Pidentity -> make_const_ptr x + | Pnot -> make_const_bool(x = 0) + | Pisint -> make_const_bool true + | _ -> (Uprim(p, args, dbg), Value_unknown) + end + | [Value_constptr x; Value_constptr y] -> + begin match p with + Psequand -> make_const_bool(x <> 0 && y <> 0) + | Psequor -> make_const_bool(x <> 0 || y <> 0) + | _ -> (Uprim(p, args, dbg), Value_unknown) + end + | _ -> + (Uprim(p, args, dbg), Value_unknown) + +let simplif_prim p (args, approxs as args_approxs) dbg = + if List.for_all is_pure_clambda args + then simplif_prim_pure p args_approxs dbg + else (Uprim(p, args, dbg), Value_unknown) + +(* Substitute variables in a [ulambda] term (a body of an inlined function) + and perform some more simplifications on integer primitives. + Also perform alpha-conversion on let-bound identifiers to avoid + clashes with locally-generated identifiers. + The variables must not be assigned in the term. + This is used to substitute "trivial" arguments for parameters + during inline expansion, and also for the translation of let rec + over functions. *) + +let approx_ulam = function + Uconst(Const_base(Const_int n)) -> Value_integer n + | Uconst(Const_base(Const_char c)) -> Value_integer(Char.code c) + | Uconst(Const_pointer n) -> Value_constptr n + | _ -> Value_unknown + +let rec substitute sb ulam = + match ulam with + Uvar v -> + begin try Tbl.find v sb with Not_found -> ulam end + | Uconst cst -> ulam + | Udirect_apply(lbl, args, dbg) -> + Udirect_apply(lbl, List.map (substitute sb) args, dbg) + | Ugeneric_apply(fn, args, dbg) -> + Ugeneric_apply(substitute sb fn, List.map (substitute sb) args, dbg) + | Uclosure(defs, env) -> + (* Question: should we rename function labels as well? Otherwise, + there is a risk that function labels are not globally unique. + This should not happen in the current system because: + - Inlined function bodies contain no Uclosure nodes + (cf. function [lambda_smaller]) + - When we substitute offsets for idents bound by let rec + in [close], case [Lletrec], we discard the original + let rec body and use only the substituted term. *) + Uclosure(defs, List.map (substitute sb) env) + | Uoffset(u, ofs) -> Uoffset(substitute sb u, ofs) + | Ulet(id, u1, u2) -> + let id' = Ident.rename id in + Ulet(id', substitute sb u1, substitute (Tbl.add id (Uvar id') sb) u2) + | Uletrec(bindings, body) -> + let bindings1 = + List.map (fun (id, rhs) -> (id, Ident.rename id, rhs)) bindings in + let sb' = + List.fold_right + (fun (id, id', _) s -> Tbl.add id (Uvar id') s) + bindings1 sb in + Uletrec( + List.map (fun (id, id', rhs) -> (id', substitute sb' rhs)) bindings1, + substitute sb' body) + | Uprim(p, args, dbg) -> + let sargs = List.map (substitute sb) args in + let (res, _) = simplif_prim p (sargs, List.map approx_ulam sargs) dbg in + res + | Uswitch(arg, sw) -> + Uswitch(substitute sb arg, + { sw with + us_actions_consts = + Array.map (substitute sb) sw.us_actions_consts; + us_actions_blocks = + Array.map (substitute sb) sw.us_actions_blocks; + }) + | Ustaticfail (nfail, args) -> + Ustaticfail (nfail, List.map (substitute sb) args) + | Ucatch(nfail, ids, u1, u2) -> + Ucatch(nfail, ids, substitute sb u1, substitute sb u2) + | Utrywith(u1, id, u2) -> + let id' = Ident.rename id in + Utrywith(substitute sb u1, id', substitute (Tbl.add id (Uvar id') sb) u2) + | Uifthenelse(u1, u2, u3) -> + begin match substitute sb u1 with + Uconst(Const_pointer n) -> + if n <> 0 then substitute sb u2 else substitute sb u3 + | su1 -> + Uifthenelse(su1, substitute sb u2, substitute sb u3) + end + | Usequence(u1, u2) -> Usequence(substitute sb u1, substitute sb u2) + | Uwhile(u1, u2) -> Uwhile(substitute sb u1, substitute sb u2) + | Ufor(id, u1, u2, dir, u3) -> + let id' = Ident.rename id in + Ufor(id', substitute sb u1, substitute sb u2, dir, + substitute (Tbl.add id (Uvar id') sb) u3) + | Uassign(id, u) -> + let id' = + try + match Tbl.find id sb with Uvar i -> i | _ -> assert false + with Not_found -> + id in + Uassign(id', substitute sb u) + | Usend(k, u1, u2, ul, dbg) -> + Usend(k, substitute sb u1, substitute sb u2, List.map (substitute sb) ul, dbg) + +(* Perform an inline expansion *) + +let is_simple_argument = function + Uvar _ -> true + | Uconst(Const_base(Const_int _ | Const_char _ | Const_float _ | + Const_int32 _ | Const_int64 _ | Const_nativeint _)) -> + true + | Uconst(Const_pointer _) -> true + | _ -> false + +let no_effects = function + Uclosure _ -> true + | Uconst(Const_base(Const_string _)) -> true + | u -> is_simple_argument u + +let rec bind_params_rec subst params args body = + match (params, args) with + ([], []) -> substitute subst body + | (p1 :: pl, a1 :: al) -> + if is_simple_argument a1 then + bind_params_rec (Tbl.add p1 a1 subst) pl al body + else begin + let p1' = Ident.rename p1 in + let body' = + bind_params_rec (Tbl.add p1 (Uvar p1') subst) pl al body in + if occurs_var p1 body then Ulet(p1', a1, body') + else if no_effects a1 then body' + else Usequence(a1, body') + end + | (_, _) -> assert false + +let bind_params params args body = + (* Reverse parameters and arguments to preserve right-to-left + evaluation order (PR#2910). *) + bind_params_rec Tbl.empty (List.rev params) (List.rev args) body + +(* Check if a lambda term is ``pure'', + that is without side-effects *and* not containing function definitions *) + +let rec is_pure = function + Lvar v -> true + | Lconst cst -> true + | Lprim((Psetglobal _ | Psetfield _ | Psetfloatfield _ | Pduprecord _ | + Pccall _ | Praise | Poffsetref _ | Pstringsetu | Pstringsets | + Parraysetu _ | Parraysets _ | Pbigarrayset _), _) -> false + | Lprim(p, args) -> List.for_all is_pure args + | Levent(lam, ev) -> is_pure lam + | _ -> false + +(* Generate a direct application *) + +let direct_apply fundesc funct ufunct uargs = + let app_args = + if fundesc.fun_closed then uargs else uargs @ [ufunct] in + let app = + match fundesc.fun_inline with + None -> Udirect_apply(fundesc.fun_label, app_args, Debuginfo.none) + | Some(params, body) -> bind_params params app_args body in + (* If ufunct can contain side-effects or function definitions, + we must make sure that it is evaluated exactly once. + If the function is not closed, we evaluate ufunct as part of the + arguments. + If the function is closed, we force the evaluation of ufunct first. *) + if not fundesc.fun_closed || is_pure funct + then app + else Usequence(ufunct, app) + +(* Add [Value_integer] or [Value_constptr] info to the approximation + of an application *) + +let strengthen_approx appl approx = + match approx_ulam appl with + (Value_integer _ | Value_constptr _) as intapprox -> intapprox + | _ -> approx + +(* If a term has approximation Value_integer or Value_constptr and is pure, + replace it by an integer constant *) + +let check_constant_result lam ulam approx = + match approx with + Value_integer n when is_pure lam -> make_const_int n + | Value_constptr n when is_pure lam -> make_const_ptr n + | _ -> (ulam, approx) + +(* Evaluate an expression with known value for its side effects only, + or discard it if it's pure *) + +let sequence_constant_expr lam ulam1 (ulam2, approx2 as res2) = + if is_pure lam then res2 else (Usequence(ulam1, ulam2), approx2) + +(* Maintain the approximation of the global structure being defined *) + +let global_approx = ref([||] : value_approximation array) + +(* Maintain the nesting depth for functions *) + +let function_nesting_depth = ref 0 +let excessive_function_nesting_depth = 5 + +(* Decorate clambda term with debug information *) + +let rec add_debug_info ev u = + match ev.lev_kind with + | Lev_after _ -> + begin match u with + | Udirect_apply(lbl, args, dinfo) -> + Udirect_apply(lbl, args, Debuginfo.from_call ev) + | Ugeneric_apply(Udirect_apply(lbl, args1, dinfo1), + args2, dinfo2) -> + Ugeneric_apply(Udirect_apply(lbl, args1, Debuginfo.from_call ev), + args2, Debuginfo.from_call ev) + | Ugeneric_apply(fn, args, dinfo) -> + Ugeneric_apply(fn, args, Debuginfo.from_call ev) + | Uprim(Praise, args, dinfo) -> + Uprim(Praise, args, Debuginfo.from_call ev) + | Uprim(p, args, dinfo) -> + Uprim(p, args, Debuginfo.from_call ev) + | Usend(kind, u1, u2, args, dinfo) -> + Usend(kind, u1, u2, args, Debuginfo.from_call ev) + | Usequence(u1, u2) -> + Usequence(u1, add_debug_info ev u2) + | _ -> u + end + | _ -> u + +(* Uncurry an expression and explicitate closures. + Also return the approximation of the expression. + The approximation environment [fenv] maps idents to approximations. + Idents not bound in [fenv] approximate to [Value_unknown]. + The closure environment [cenv] maps idents to [ulambda] terms. + It is used to substitute environment accesses for free identifiers. *) + +let close_approx_var fenv cenv id = + let approx = try Tbl.find id fenv with Not_found -> Value_unknown in + match approx with + Value_integer n -> + make_const_int n + | Value_constptr n -> + make_const_ptr n + | approx -> + let subst = try Tbl.find id cenv with Not_found -> Uvar id in + (subst, approx) + +let close_var fenv cenv id = + let (ulam, app) = close_approx_var fenv cenv id in ulam + +let rec close fenv cenv = function + Lvar id -> + close_approx_var fenv cenv id + | Lconst cst -> + begin match cst with + Const_base(Const_int n) -> (Uconst cst, Value_integer n) + | Const_base(Const_char c) -> (Uconst cst, Value_integer(Char.code c)) + | Const_pointer n -> (Uconst cst, Value_constptr n) + | _ -> (Uconst cst, Value_unknown) + end + | Lfunction(kind, params, body) as funct -> + close_one_function fenv cenv (Ident.create "fun") funct + | Lapply(funct, args, loc) -> + let nargs = List.length args in + begin match (close fenv cenv funct, close_list fenv cenv args) with + ((ufunct, Value_closure(fundesc, approx_res)), + [Uprim(Pmakeblock(_, _), uargs, _)]) + when List.length uargs = - fundesc.fun_arity -> + let app = direct_apply fundesc funct ufunct uargs in + (app, strengthen_approx app approx_res) + | ((ufunct, Value_closure(fundesc, approx_res)), uargs) + when nargs = fundesc.fun_arity -> + let app = direct_apply fundesc funct ufunct uargs in + (app, strengthen_approx app approx_res) + | ((ufunct, Value_closure(fundesc, approx_res)), uargs) + when fundesc.fun_arity > 0 && nargs > fundesc.fun_arity -> + let (first_args, rem_args) = split_list fundesc.fun_arity uargs in + (Ugeneric_apply(direct_apply fundesc funct ufunct first_args, + rem_args, Debuginfo.none), + Value_unknown) + | ((ufunct, _), uargs) -> + (Ugeneric_apply(ufunct, uargs, Debuginfo.none), Value_unknown) + end + | Lsend(kind, met, obj, args) -> + let (umet, _) = close fenv cenv met in + let (uobj, _) = close fenv cenv obj in + (Usend(kind, umet, uobj, close_list fenv cenv args, Debuginfo.none), + Value_unknown) + | Llet(str, id, lam, body) -> + let (ulam, alam) = close_named fenv cenv id lam in + begin match (str, alam) with + (Variable, _) -> + let (ubody, abody) = close fenv cenv body in + (Ulet(id, ulam, ubody), abody) + | (_, (Value_integer _ | Value_constptr _)) + when str = Alias || is_pure lam -> + close (Tbl.add id alam fenv) cenv body + | (_, _) -> + let (ubody, abody) = close (Tbl.add id alam fenv) cenv body in + (Ulet(id, ulam, ubody), abody) + end + | Lletrec(defs, body) -> + if List.for_all + (function (id, Lfunction(_, _, _)) -> true | _ -> false) + defs + then begin + (* Simple case: only function definitions *) + let (clos, infos) = close_functions fenv cenv defs in + let clos_ident = Ident.create "clos" in + let fenv_body = + List.fold_right + (fun (id, pos, approx) fenv -> Tbl.add id approx fenv) + infos fenv in + let (ubody, approx) = close fenv_body cenv body in + let sb = + List.fold_right + (fun (id, pos, approx) sb -> + Tbl.add id (Uoffset(Uvar clos_ident, pos)) sb) + infos Tbl.empty in + (Ulet(clos_ident, clos, substitute sb ubody), + approx) + end else begin + (* General case: recursive definition of values *) + let rec clos_defs = function + [] -> ([], fenv) + | (id, lam) :: rem -> + let (udefs, fenv_body) = clos_defs rem in + let (ulam, approx) = close fenv cenv lam in + ((id, ulam) :: udefs, Tbl.add id approx fenv_body) in + let (udefs, fenv_body) = clos_defs defs in + let (ubody, approx) = close fenv_body cenv body in + (Uletrec(udefs, ubody), approx) + end + | Lprim(Pgetglobal id, []) as lam -> + check_constant_result lam + (getglobal id) + (Compilenv.global_approx id) + | Lprim(Pmakeblock(tag, mut) as prim, lams) -> + let (ulams, approxs) = List.split (List.map (close fenv cenv) lams) in + (Uprim(prim, ulams, Debuginfo.none), + begin match mut with + Immutable -> Value_tuple(Array.of_list approxs) + | Mutable -> Value_unknown + end) + | Lprim(Pfield n, [lam]) -> + let (ulam, approx) = close fenv cenv lam in + let fieldapprox = + match approx with + Value_tuple a when n < Array.length a -> a.(n) + | _ -> Value_unknown in + check_constant_result lam (Uprim(Pfield n, [ulam], Debuginfo.none)) fieldapprox + | Lprim(Psetfield(n, _), [Lprim(Pgetglobal id, []); lam]) -> + let (ulam, approx) = close fenv cenv lam in + (!global_approx).(n) <- approx; + (Uprim(Psetfield(n, false), [getglobal id; ulam], Debuginfo.none), + Value_unknown) + | Lprim(Praise, [Levent(arg, ev)]) -> + let (ulam, approx) = close fenv cenv arg in + (Uprim(Praise, [ulam], Debuginfo.from_raise ev), + Value_unknown) + | Lprim(p, args) -> + simplif_prim p (close_list_approx fenv cenv args) Debuginfo.none + | Lswitch(arg, sw) -> +(* NB: failaction might get copied, thus it should be some Lstaticraise *) + let (uarg, _) = close fenv cenv arg in + let const_index, const_actions = + close_switch fenv cenv sw.sw_consts sw.sw_numconsts sw.sw_failaction + and block_index, block_actions = + close_switch fenv cenv sw.sw_blocks sw.sw_numblocks sw.sw_failaction in + (Uswitch(uarg, + {us_index_consts = const_index; + us_actions_consts = const_actions; + us_index_blocks = block_index; + us_actions_blocks = block_actions}), + Value_unknown) + | Lstaticraise (i, args) -> + (Ustaticfail (i, close_list fenv cenv args), Value_unknown) + | Lstaticcatch(body, (i, vars), handler) -> + let (ubody, _) = close fenv cenv body in + let (uhandler, _) = close fenv cenv handler in + (Ucatch(i, vars, ubody, uhandler), Value_unknown) + | Ltrywith(body, id, handler) -> + let (ubody, _) = close fenv cenv body in + let (uhandler, _) = close fenv cenv handler in + (Utrywith(ubody, id, uhandler), Value_unknown) + | Lifthenelse(arg, ifso, ifnot) -> + begin match close fenv cenv arg with + (uarg, Value_constptr n) -> + sequence_constant_expr arg uarg + (close fenv cenv (if n = 0 then ifnot else ifso)) + | (uarg, _ ) -> + let (uifso, _) = close fenv cenv ifso in + let (uifnot, _) = close fenv cenv ifnot in + (Uifthenelse(uarg, uifso, uifnot), Value_unknown) + end + | Lsequence(lam1, lam2) -> + let (ulam1, _) = close fenv cenv lam1 in + let (ulam2, approx) = close fenv cenv lam2 in + (Usequence(ulam1, ulam2), approx) + | Lwhile(cond, body) -> + let (ucond, _) = close fenv cenv cond in + let (ubody, _) = close fenv cenv body in + (Uwhile(ucond, ubody), Value_unknown) + | Lfor(id, lo, hi, dir, body) -> + let (ulo, _) = close fenv cenv lo in + let (uhi, _) = close fenv cenv hi in + let (ubody, _) = close fenv cenv body in + (Ufor(id, ulo, uhi, dir, ubody), Value_unknown) + | Lassign(id, lam) -> + let (ulam, _) = close fenv cenv lam in + (Uassign(id, ulam), Value_unknown) + | Levent(lam, ev) -> + let (ulam, approx) = close fenv cenv lam in + (add_debug_info ev ulam, approx) + | Lifused _ -> + assert false + +and close_list fenv cenv = function + [] -> [] + | lam :: rem -> + let (ulam, _) = close fenv cenv lam in + ulam :: close_list fenv cenv rem + +and close_list_approx fenv cenv = function + [] -> ([], []) + | lam :: rem -> + let (ulam, approx) = close fenv cenv lam in + let (ulams, approxs) = close_list_approx fenv cenv rem in + (ulam :: ulams, approx :: approxs) + +and close_named fenv cenv id = function + Lfunction(kind, params, body) as funct -> + close_one_function fenv cenv id funct + | lam -> + close fenv cenv lam + +(* Build a shared closure for a set of mutually recursive functions *) + +and close_functions fenv cenv fun_defs = + (* Update and check nesting depth *) + incr function_nesting_depth; + let initially_closed = + !function_nesting_depth < excessive_function_nesting_depth in + (* Determine the free variables of the functions *) + let fv = + IdentSet.elements (free_variables (Lletrec(fun_defs, lambda_unit))) in + (* Build the function descriptors for the functions. + Initially all functions are assumed not to need their environment + parameter. *) + let uncurried_defs = + List.map + (function + (id, Lfunction(kind, params, body)) -> + let label = Compilenv.make_symbol (Some (Ident.unique_name id)) in + let arity = List.length params in + let fundesc = + {fun_label = label; + fun_arity = (if kind = Tupled then -arity else arity); + fun_closed = initially_closed; + fun_inline = None } in + (id, params, body, fundesc) + | (_, _) -> fatal_error "Closure.close_functions") + fun_defs in + (* Build an approximate fenv for compiling the functions *) + let fenv_rec = + List.fold_right + (fun (id, params, body, fundesc) fenv -> + Tbl.add id (Value_closure(fundesc, Value_unknown)) fenv) + uncurried_defs fenv in + (* Determine the offsets of each function's closure in the shared block *) + let env_pos = ref (-1) in + let clos_offsets = + List.map + (fun (id, params, body, fundesc) -> + let pos = !env_pos + 1 in + env_pos := !env_pos + 1 + (if fundesc.fun_arity <> 1 then 3 else 2); + pos) + uncurried_defs in + let fv_pos = !env_pos in + (* This reference will be set to false if the hypothesis that a function + does not use its environment parameter is invalidated. *) + let useless_env = ref initially_closed in + (* Translate each function definition *) + let clos_fundef (id, params, body, fundesc) env_pos = + let env_param = Ident.create "env" in + let cenv_fv = + build_closure_env env_param (fv_pos - env_pos) fv in + let cenv_body = + List.fold_right2 + (fun (id, params, arity, body) pos env -> + Tbl.add id (Uoffset(Uvar env_param, pos - env_pos)) env) + uncurried_defs clos_offsets cenv_fv in + let (ubody, approx) = close fenv_rec cenv_body body in + if !useless_env && occurs_var env_param ubody then useless_env := false; + let fun_params = if !useless_env then params else params @ [env_param] in + ((fundesc.fun_label, fundesc.fun_arity, fun_params, ubody), + (id, env_pos, Value_closure(fundesc, approx))) in + (* Translate all function definitions. *) + let clos_info_list = + if initially_closed then begin + let cl = List.map2 clos_fundef uncurried_defs clos_offsets in + (* If the hypothesis that the environment parameters are useless has been + invalidated, then set [fun_closed] to false in all descriptions and + recompile *) + if !useless_env then cl else begin + List.iter + (fun (id, params, body, fundesc) -> fundesc.fun_closed <- false) + uncurried_defs; + List.map2 clos_fundef uncurried_defs clos_offsets + end + end else + (* Excessive closure nesting: assume environment parameter is used *) + List.map2 clos_fundef uncurried_defs clos_offsets + in + (* Update nesting depth *) + decr function_nesting_depth; + (* Return the Uclosure node and the list of all identifiers defined, + with offsets and approximations. *) + let (clos, infos) = List.split clos_info_list in + (Uclosure(clos, List.map (close_var fenv cenv) fv), infos) + +(* Same, for one non-recursive function *) + +and close_one_function fenv cenv id funct = + match close_functions fenv cenv [id, funct] with + ((Uclosure([_, _, params, body], _) as clos), + [_, _, (Value_closure(fundesc, _) as approx)]) -> + (* See if the function can be inlined *) + if lambda_smaller body (!Clflags.inline_threshold + List.length params) + then fundesc.fun_inline <- Some(params, body); + (clos, approx) + | _ -> fatal_error "Closure.close_one_function" + +(* Close a switch *) + +and close_switch fenv cenv cases num_keys default = + let index = Array.create num_keys 0 + and store = mk_store Lambda.same in + + (* First default case *) + begin match default with + | Some def when List.length cases < num_keys -> + ignore (store.act_store def) + | _ -> () + end ; + (* Then all other cases *) + List.iter + (fun (key,lam) -> + index.(key) <- store.act_store lam) + cases ; + (* Compile action *) + let actions = + Array.map + (fun lam -> + let ulam,_ = close fenv cenv lam in + ulam) + (store.act_get ()) in + match actions with + | [| |] -> [| |], [| |] (* May happen when default is None *) + | _ -> index, actions + + +(* The entry point *) + +let intro size lam = + function_nesting_depth := 0; + global_approx := Array.create size Value_unknown; + Compilenv.set_global_approx(Value_tuple !global_approx); + let (ulam, approx) = close Tbl.empty Tbl.empty lam in + global_approx := [||]; + ulam diff --git a/asmcomp/closure.mli b/asmcomp/closure.mli new file mode 100644 index 0000000..2b97e73 --- /dev/null +++ b/asmcomp/closure.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: closure.mli,v 1.5 1999-11-17 18:56:30 xleroy Exp $ *) + +(* Introduction of closures, uncurrying, recognition of direct calls *) + +val intro: int -> Lambda.lambda -> Clambda.ulambda + diff --git a/asmcomp/cmm.ml b/asmcomp/cmm.ml new file mode 100644 index 0000000..32fb9e5 --- /dev/null +++ b/asmcomp/cmm.ml @@ -0,0 +1,132 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cmm.ml,v 1.21 2007-01-29 12:10:50 xleroy Exp $ *) + +type machtype_component = + Addr + | Int + | Float + +type machtype = machtype_component array + +let typ_void = ([||] : machtype_component array) +let typ_addr = [|Addr|] +let typ_int = [|Int|] +let typ_float = [|Float|] + +let size_component = function + Addr -> Arch.size_addr + | Int -> Arch.size_int + | Float -> Arch.size_float + +let size_machtype mty = + let size = ref 0 in + for i = 0 to Array.length mty - 1 do + size := !size + size_component mty.(i) + done; + !size + +type comparison = + Ceq + | Cne + | Clt + | Cle + | Cgt + | Cge + +let negate_comparison = function + Ceq -> Cne | Cne -> Ceq + | Clt -> Cge | Cle -> Cgt + | Cgt -> Cle | Cge -> Clt + +let swap_comparison = function + Ceq -> Ceq | Cne -> Cne + | Clt -> Cgt | Cle -> Cge + | Cgt -> Clt | Cge -> Cle + +type memory_chunk = + Byte_unsigned + | Byte_signed + | Sixteen_unsigned + | Sixteen_signed + | Thirtytwo_unsigned + | Thirtytwo_signed + | Word + | Single + | Double + | Double_u + +type operation = + Capply of machtype * Debuginfo.t + | Cextcall of string * machtype * bool * Debuginfo.t + | Cload of memory_chunk + | Calloc + | Cstore of memory_chunk + | Caddi | Csubi | Cmuli | Cdivi | Cmodi + | Cand | Cor | Cxor | Clsl | Clsr | Casr + | Ccmpi of comparison + | Cadda | Csuba + | Ccmpa of comparison + | Cnegf | Cabsf + | Caddf | Csubf | Cmulf | Cdivf + | Cfloatofint | Cintoffloat + | Ccmpf of comparison + | Craise of Debuginfo.t + | Ccheckbound of Debuginfo.t + +type expression = + Cconst_int of int + | Cconst_natint of nativeint + | Cconst_float of string + | Cconst_symbol of string + | Cconst_pointer of int + | Cconst_natpointer of nativeint + | Cvar of Ident.t + | Clet of Ident.t * expression * expression + | Cassign of Ident.t * expression + | Ctuple of expression list + | Cop of operation * expression list + | Csequence of expression * expression + | Cifthenelse of expression * expression * expression + | Cswitch of expression * int array * expression array + | Cloop of expression + | Ccatch of int * Ident.t list * expression * expression + | Cexit of int * expression list + | Ctrywith of expression * Ident.t * expression + +type fundecl = + { fun_name: string; + fun_args: (Ident.t * machtype) list; + fun_body: expression; + fun_fast: bool } + +type data_item = + Cdefine_symbol of string + | Cdefine_label of int + | Cglobal_symbol of string + | Cint8 of int + | Cint16 of int + | Cint32 of nativeint + | Cint of nativeint + | Csingle of string + | Cdouble of string + | Csymbol_address of string + | Clabel_address of int + | Cstring of string + | Cskip of int + | Calign of int + +type phrase = + Cfunction of fundecl + | Cdata of data_item list + diff --git a/asmcomp/cmm.mli b/asmcomp/cmm.mli new file mode 100644 index 0000000..18980de --- /dev/null +++ b/asmcomp/cmm.mli @@ -0,0 +1,118 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cmm.mli,v 1.21 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Second intermediate language (machine independent) *) + +type machtype_component = + Addr + | Int + | Float + +type machtype = machtype_component array + +val typ_void: machtype +val typ_addr: machtype +val typ_int: machtype +val typ_float: machtype + +val size_component: machtype_component -> int +val size_machtype: machtype -> int + +type comparison = + Ceq + | Cne + | Clt + | Cle + | Cgt + | Cge + +val negate_comparison: comparison -> comparison +val swap_comparison: comparison -> comparison + +type memory_chunk = + Byte_unsigned + | Byte_signed + | Sixteen_unsigned + | Sixteen_signed + | Thirtytwo_unsigned + | Thirtytwo_signed + | Word + | Single + | Double (* 64-bit-aligned 64-bit float *) + | Double_u (* word-aligned 64-bit float *) + +type operation = + Capply of machtype * Debuginfo.t + | Cextcall of string * machtype * bool * Debuginfo.t + | Cload of memory_chunk + | Calloc + | Cstore of memory_chunk + | Caddi | Csubi | Cmuli | Cdivi | Cmodi + | Cand | Cor | Cxor | Clsl | Clsr | Casr + | Ccmpi of comparison + | Cadda | Csuba + | Ccmpa of comparison + | Cnegf | Cabsf + | Caddf | Csubf | Cmulf | Cdivf + | Cfloatofint | Cintoffloat + | Ccmpf of comparison + | Craise of Debuginfo.t + | Ccheckbound of Debuginfo.t + +type expression = + Cconst_int of int + | Cconst_natint of nativeint + | Cconst_float of string + | Cconst_symbol of string + | Cconst_pointer of int + | Cconst_natpointer of nativeint + | Cvar of Ident.t + | Clet of Ident.t * expression * expression + | Cassign of Ident.t * expression + | Ctuple of expression list + | Cop of operation * expression list + | Csequence of expression * expression + | Cifthenelse of expression * expression * expression + | Cswitch of expression * int array * expression array + | Cloop of expression + | Ccatch of int * Ident.t list * expression * expression + | Cexit of int * expression list + | Ctrywith of expression * Ident.t * expression + +type fundecl = + { fun_name: string; + fun_args: (Ident.t * machtype) list; + fun_body: expression; + fun_fast: bool } + +type data_item = + Cdefine_symbol of string + | Cdefine_label of int + | Cglobal_symbol of string + | Cint8 of int + | Cint16 of int + | Cint32 of nativeint + | Cint of nativeint + | Csingle of string + | Cdouble of string + | Csymbol_address of string + | Clabel_address of int + | Cstring of string + | Cskip of int + | Calign of int + +type phrase = + Cfunction of fundecl + | Cdata of data_item list + diff --git a/asmcomp/cmmgen.ml b/asmcomp/cmmgen.ml new file mode 100644 index 0000000..a6dbe69 --- /dev/null +++ b/asmcomp/cmmgen.ml @@ -0,0 +1,2082 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cmmgen.ml,v 1.114 2008-08-05 13:35:20 xleroy Exp $ *) + +(* Translation from closed lambda to C-- *) + +open Misc +open Arch +open Asttypes +open Primitive +open Types +open Lambda +open Clambda +open Cmm + +(* Local binding of complex expressions *) + +let bind name arg fn = + match arg with + Cvar _ | Cconst_int _ | Cconst_natint _ | Cconst_symbol _ + | Cconst_pointer _ | Cconst_natpointer _ -> fn arg + | _ -> let id = Ident.create name in Clet(id, arg, fn (Cvar id)) + +let bind_nonvar name arg fn = + match arg with + Cconst_int _ | Cconst_natint _ | Cconst_symbol _ + | Cconst_pointer _ | Cconst_natpointer _ -> fn arg + | _ -> let id = Ident.create name in Clet(id, arg, fn (Cvar id)) + +(* Block headers. Meaning of the tag field: see stdlib/obj.ml *) + +let float_tag = Cconst_int Obj.double_tag +let floatarray_tag = Cconst_int Obj.double_array_tag + +let block_header tag sz = + Nativeint.add (Nativeint.shift_left (Nativeint.of_int sz) 10) + (Nativeint.of_int tag) +let closure_header sz = block_header Obj.closure_tag sz +let infix_header ofs = block_header Obj.infix_tag ofs +let float_header = block_header Obj.double_tag (size_float / size_addr) +let floatarray_header len = + block_header Obj.double_array_tag (len * size_float / size_addr) +let string_header len = + block_header Obj.string_tag ((len + size_addr) / size_addr) +let boxedint_header = block_header Obj.custom_tag 2 + +let alloc_block_header tag sz = Cconst_natint(block_header tag sz) +let alloc_float_header = Cconst_natint(float_header) +let alloc_floatarray_header len = Cconst_natint(floatarray_header len) +let alloc_closure_header sz = Cconst_natint(closure_header sz) +let alloc_infix_header ofs = Cconst_natint(infix_header ofs) +let alloc_boxedint_header = Cconst_natint(boxedint_header) + +(* Integers *) + +let max_repr_int = max_int asr 1 +let min_repr_int = min_int asr 1 + +let int_const n = + if n <= max_repr_int && n >= min_repr_int + then Cconst_int((n lsl 1) + 1) + else Cconst_natint + (Nativeint.add (Nativeint.shift_left (Nativeint.of_int n) 1) 1n) + +let add_const c n = + if n = 0 then c else Cop(Caddi, [c; Cconst_int n]) + +let incr_int = function + Cconst_int n when n < max_int -> Cconst_int(n+1) + | Cop(Caddi, [c; Cconst_int n]) when n < max_int -> add_const c (n + 1) + | c -> add_const c 1 + +let decr_int = function + Cconst_int n when n > min_int -> Cconst_int(n-1) + | Cop(Caddi, [c; Cconst_int n]) when n > min_int -> add_const c (n - 1) + | c -> add_const c (-1) + +let add_int c1 c2 = + match (c1, c2) with + (Cop(Caddi, [c1; Cconst_int n1]), + Cop(Caddi, [c2; Cconst_int n2])) when no_overflow_add n1 n2 -> + add_const (Cop(Caddi, [c1; c2])) (n1 + n2) + | (Cop(Caddi, [c1; Cconst_int n1]), c2) -> + add_const (Cop(Caddi, [c1; c2])) n1 + | (c1, Cop(Caddi, [c2; Cconst_int n2])) -> + add_const (Cop(Caddi, [c1; c2])) n2 + | (Cconst_int _, _) -> + Cop(Caddi, [c2; c1]) + | (_, _) -> + Cop(Caddi, [c1; c2]) + +let sub_int c1 c2 = + match (c1, c2) with + (Cop(Caddi, [c1; Cconst_int n1]), + Cop(Caddi, [c2; Cconst_int n2])) when no_overflow_sub n1 n2 -> + add_const (Cop(Csubi, [c1; c2])) (n1 - n2) + | (Cop(Caddi, [c1; Cconst_int n1]), c2) -> + add_const (Cop(Csubi, [c1; c2])) n1 + | (c1, Cop(Caddi, [c2; Cconst_int n2])) when n2 <> min_int -> + add_const (Cop(Csubi, [c1; c2])) (-n2) + | (c1, Cconst_int n) when n <> min_int -> + add_const c1 (-n) + | (c1, c2) -> + Cop(Csubi, [c1; c2]) + +let mul_int c1 c2 = + match (c1, c2) with + (Cconst_int 0, _) -> c1 + | (Cconst_int 1, _) -> c2 + | (_, Cconst_int 0) -> c2 + | (_, Cconst_int 1) -> c1 + | (_, _) -> Cop(Cmuli, [c1; c2]) + +let tag_int = function + Cconst_int n -> int_const n + | c -> Cop(Caddi, [Cop(Clsl, [c; Cconst_int 1]); Cconst_int 1]) + +let force_tag_int = function + Cconst_int n -> int_const n + | c -> Cop(Cor, [Cop(Clsl, [c; Cconst_int 1]); Cconst_int 1]) + +let untag_int = function + Cconst_int n -> Cconst_int(n asr 1) + | Cop(Caddi, [Cop(Clsl, [c; Cconst_int 1]); Cconst_int 1]) -> c + | Cop(Cor, [Cop(Casr, [c; Cconst_int n]); Cconst_int 1]) + when n > 0 && n < size_int * 8 -> + Cop(Casr, [c; Cconst_int (n+1)]) + | Cop(Cor, [Cop(Clsr, [c; Cconst_int n]); Cconst_int 1]) + when n > 0 && n < size_int * 8 -> + Cop(Clsr, [c; Cconst_int (n+1)]) + | Cop(Cor, [c; Cconst_int 1]) -> Cop(Casr, [c; Cconst_int 1]) + | c -> Cop(Casr, [c; Cconst_int 1]) + +let lsl_int c1 c2 = + match (c1, c2) with + (Cop(Clsl, [c; Cconst_int n1]), Cconst_int n2) + when n1 > 0 && n2 > 0 && n1 + n2 < size_int * 8 -> + Cop(Clsl, [c; Cconst_int (n1 + n2)]) + | (_, _) -> + Cop(Clsl, [c1; c2]) + +let ignore_low_bit_int = function + Cop(Caddi, [(Cop(Clsl, [_; Cconst_int 1]) as c); Cconst_int 1]) -> c + | Cop(Cor, [c; Cconst_int 1]) -> c + | c -> c + +let is_nonzero_constant = function + Cconst_int n -> n <> 0 + | Cconst_natint n -> n <> 0n + | _ -> false + +let safe_divmod op c1 c2 dbg = + if !Clflags.fast || is_nonzero_constant c2 then + Cop(op, [c1; c2]) + else + bind "divisor" c2 (fun c2 -> + Cifthenelse(c2, + Cop(op, [c1; c2]), + Cop(Craise dbg, + [Cconst_symbol "caml_bucket_Division_by_zero"]))) + +(* Bool *) + +let test_bool = function + Cop(Caddi, [Cop(Clsl, [c; Cconst_int 1]); Cconst_int 1]) -> c + | Cop(Clsl, [c; Cconst_int 1]) -> c + | c -> Cop(Ccmpi Cne, [c; Cconst_int 1]) + +(* Float *) + +let box_float c = Cop(Calloc, [alloc_float_header; c]) + +let rec unbox_float = function + Cop(Calloc, [header; c]) -> c + | Clet(id, exp, body) -> Clet(id, exp, unbox_float body) + | Cifthenelse(cond, e1, e2) -> + Cifthenelse(cond, unbox_float e1, unbox_float e2) + | Csequence(e1, e2) -> Csequence(e1, unbox_float e2) + | Cswitch(e, tbl, el) -> Cswitch(e, tbl, Array.map unbox_float el) + | Ccatch(n, ids, e1, e2) -> Ccatch(n, ids, unbox_float e1, unbox_float e2) + | Ctrywith(e1, id, e2) -> Ctrywith(unbox_float e1, id, unbox_float e2) + | c -> Cop(Cload Double_u, [c]) + +(* Complex *) + +let box_complex c_re c_im = + Cop(Calloc, [alloc_floatarray_header 2; c_re; c_im]) + +let complex_re c = Cop(Cload Double_u, [c]) +let complex_im c = Cop(Cload Double_u, + [Cop(Cadda, [c; Cconst_int size_float])]) + +(* Unit *) + +let return_unit c = Csequence(c, Cconst_pointer 1) + +let rec remove_unit = function + Cconst_pointer 1 -> Ctuple [] + | Csequence(c, Cconst_pointer 1) -> c + | Csequence(c1, c2) -> + Csequence(c1, remove_unit c2) + | Cifthenelse(cond, ifso, ifnot) -> + Cifthenelse(cond, remove_unit ifso, remove_unit ifnot) + | Cswitch(sel, index, cases) -> + Cswitch(sel, index, Array.map remove_unit cases) + | Ccatch(io, ids, body, handler) -> + Ccatch(io, ids, remove_unit body, remove_unit handler) + | Ctrywith(body, exn, handler) -> + Ctrywith(remove_unit body, exn, remove_unit handler) + | Clet(id, c1, c2) -> + Clet(id, c1, remove_unit c2) + | Cop(Capply (mty, dbg), args) -> + Cop(Capply (typ_void, dbg), args) + | Cop(Cextcall(proc, mty, alloc, dbg), args) -> + Cop(Cextcall(proc, typ_void, alloc, dbg), args) + | Cexit (_,_) as c -> c + | Ctuple [] as c -> c + | c -> Csequence(c, Ctuple []) + +(* Access to block fields *) + +let field_address ptr n = + if n = 0 + then ptr + else Cop(Cadda, [ptr; Cconst_int(n * size_addr)]) + +let get_field ptr n = + Cop(Cload Word, [field_address ptr n]) + +let set_field ptr n newval = + Cop(Cstore Word, [field_address ptr n; newval]) + +let header ptr = + Cop(Cload Word, [Cop(Cadda, [ptr; Cconst_int(-size_int)])]) + +let tag_offset = + if big_endian then -1 else -size_int + +let get_tag ptr = + if Proc.word_addressed then (* If byte loads are slow *) + Cop(Cand, [header ptr; Cconst_int 255]) + else (* If byte loads are efficient *) + Cop(Cload Byte_unsigned, + [Cop(Cadda, [ptr; Cconst_int(tag_offset)])]) + +let get_size ptr = + Cop(Clsr, [header ptr; Cconst_int 10]) + +(* Array indexing *) + +let log2_size_addr = Misc.log2 size_addr +let log2_size_float = Misc.log2 size_float + +let wordsize_shift = 9 +let numfloat_shift = 9 + log2_size_float - log2_size_addr + +let is_addr_array_hdr hdr = + Cop(Ccmpi Cne, [Cop(Cand, [hdr; Cconst_int 255]); floatarray_tag]) + +let is_addr_array_ptr ptr = + Cop(Ccmpi Cne, [get_tag ptr; floatarray_tag]) + +let addr_array_length hdr = Cop(Clsr, [hdr; Cconst_int wordsize_shift]) +let float_array_length hdr = Cop(Clsr, [hdr; Cconst_int numfloat_shift]) + +let lsl_const c n = + Cop(Clsl, [c; Cconst_int n]) + +let array_indexing log2size ptr ofs = + match ofs with + Cconst_int n -> + let i = n asr 1 in + if i = 0 then ptr else Cop(Cadda, [ptr; Cconst_int(i lsl log2size)]) + | Cop(Caddi, [Cop(Clsl, [c; Cconst_int 1]); Cconst_int 1]) -> + Cop(Cadda, [ptr; lsl_const c log2size]) + | Cop(Caddi, [c; Cconst_int n]) -> + Cop(Cadda, [Cop(Cadda, [ptr; lsl_const c (log2size - 1)]); + Cconst_int((n-1) lsl (log2size - 1))]) + | _ -> + Cop(Cadda, [Cop(Cadda, [ptr; lsl_const ofs (log2size - 1)]); + Cconst_int((-1) lsl (log2size - 1))]) + +let addr_array_ref arr ofs = + Cop(Cload Word, [array_indexing log2_size_addr arr ofs]) +let unboxed_float_array_ref arr ofs = + Cop(Cload Double_u, [array_indexing log2_size_float arr ofs]) +let float_array_ref arr ofs = + box_float(unboxed_float_array_ref arr ofs) + +let addr_array_set arr ofs newval = + Cop(Cextcall("caml_modify", typ_void, false, Debuginfo.none), + [array_indexing log2_size_addr arr ofs; newval]) +let int_array_set arr ofs newval = + Cop(Cstore Word, [array_indexing log2_size_addr arr ofs; newval]) +let float_array_set arr ofs newval = + Cop(Cstore Double_u, [array_indexing log2_size_float arr ofs; newval]) + +(* String length *) + +let string_length exp = + bind "str" exp (fun str -> + let tmp_var = Ident.create "tmp" in + Clet(tmp_var, + Cop(Csubi, + [Cop(Clsl, + [Cop(Clsr, [header str; Cconst_int 10]); + Cconst_int log2_size_addr]); + Cconst_int 1]), + Cop(Csubi, + [Cvar tmp_var; + Cop(Cload Byte_unsigned, + [Cop(Cadda, [str; Cvar tmp_var])])]))) + +(* Message sending *) + +let lookup_tag obj tag = + bind "tag" tag (fun tag -> + Cop(Cextcall("caml_get_public_method", typ_addr, false, Debuginfo.none), + [obj; tag])) + +let lookup_label obj lab = + bind "lab" lab (fun lab -> + let table = Cop (Cload Word, [obj]) in + addr_array_ref table lab) + +let call_cached_method obj tag cache pos args dbg = + let arity = List.length args in + let cache = array_indexing log2_size_addr cache pos in + Compilenv.need_send_fun arity; + Cop(Capply (typ_addr, dbg), + Cconst_symbol("caml_send" ^ string_of_int arity) :: + obj :: tag :: cache :: args) + +(* Allocation *) + +let make_alloc_generic set_fn tag wordsize args = + if wordsize <= Config.max_young_wosize then + Cop(Calloc, Cconst_natint(block_header tag wordsize) :: args) + else begin + let id = Ident.create "alloc" in + let rec fill_fields idx = function + [] -> Cvar id + | e1::el -> Csequence(set_fn (Cvar id) (Cconst_int idx) e1, + fill_fields (idx + 2) el) in + Clet(id, + Cop(Cextcall("caml_alloc", typ_addr, true, Debuginfo.none), + [Cconst_int wordsize; Cconst_int tag]), + fill_fields 1 args) + end + +let make_alloc tag args = + make_alloc_generic addr_array_set tag (List.length args) args +let make_float_alloc tag args = + make_alloc_generic float_array_set tag + (List.length args * size_float / size_addr) args + +(* To compile "let rec" over values *) + +let fundecls_size fundecls = + let sz = ref (-1) in + List.iter + (fun (label, arity, params, body) -> + sz := !sz + 1 + (if arity = 1 then 2 else 3)) + fundecls; + !sz + +type rhs_kind = + | RHS_block of int + | RHS_nonrec +;; +let rec expr_size = function + | Uclosure(fundecls, clos_vars) -> + RHS_block (fundecls_size fundecls + List.length clos_vars) + | Ulet(id, exp, body) -> + expr_size body + | Uletrec(bindings, body) -> + expr_size body + | Uprim(Pmakeblock(tag, mut), args, _) -> + RHS_block (List.length args) + | Uprim(Pmakearray(Paddrarray | Pintarray), args, _) -> + RHS_block (List.length args) + | Usequence(exp, exp') -> + expr_size exp' + | _ -> RHS_nonrec + +(* Record application and currying functions *) + +let apply_function n = + Compilenv.need_apply_fun n; "caml_apply" ^ string_of_int n +let curry_function n = + Compilenv.need_curry_fun n; + if n >= 0 + then "caml_curry" ^ string_of_int n + else "caml_tuplify" ^ string_of_int (-n) + +(* Comparisons *) + +let transl_comparison = function + Lambda.Ceq -> Ceq + | Lambda.Cneq -> Cne + | Lambda.Cge -> Cge + | Lambda.Cgt -> Cgt + | Lambda.Cle -> Cle + | Lambda.Clt -> Clt + +(* Translate structured constants *) + +let const_label = ref 0 + +let new_const_label () = + incr const_label; + !const_label + +let new_const_symbol () = + incr const_label; + Compilenv.make_symbol (Some (string_of_int !const_label)) + +let structured_constants = ref ([] : (string * structured_constant) list) + +let transl_constant = function + Const_base(Const_int n) -> + int_const n + | Const_base(Const_char c) -> + Cconst_int(((Char.code c) lsl 1) + 1) + | Const_pointer n -> + if n <= max_repr_int && n >= min_repr_int + then Cconst_pointer((n lsl 1) + 1) + else Cconst_natpointer + (Nativeint.add (Nativeint.shift_left (Nativeint.of_int n) 1) 1n) + | cst -> + let lbl = new_const_symbol() in + structured_constants := (lbl, cst) :: !structured_constants; + Cconst_symbol lbl + +(* Translate constant closures *) + +let constant_closures = + ref ([] : (string * (string * int * Ident.t list * ulambda) list) list) + +(* Boxed integers *) + +let box_int_constant bi n = + match bi with + Pnativeint -> Const_base(Const_nativeint n) + | Pint32 -> Const_base(Const_int32 (Nativeint.to_int32 n)) + | Pint64 -> Const_base(Const_int64 (Int64.of_nativeint n)) + +let operations_boxed_int bi = + match bi with + Pnativeint -> "caml_nativeint_ops" + | Pint32 -> "caml_int32_ops" + | Pint64 -> "caml_int64_ops" + +let box_int bi arg = + match arg with + Cconst_int n -> + transl_constant (box_int_constant bi (Nativeint.of_int n)) + | Cconst_natint n -> + transl_constant (box_int_constant bi n) + | _ -> + let arg' = + if bi = Pint32 && size_int = 8 && big_endian + then Cop(Clsl, [arg; Cconst_int 32]) + else arg in + Cop(Calloc, [alloc_boxedint_header; + Cconst_symbol(operations_boxed_int bi); + arg']) + +let rec unbox_int bi arg = + match arg with + Cop(Calloc, [hdr; ops; Cop(Clsl, [contents; Cconst_int 32])]) + when bi = Pint32 && size_int = 8 && big_endian -> + (* Force sign-extension of low 32 bits *) + Cop(Casr, [Cop(Clsl, [contents; Cconst_int 32]); Cconst_int 32]) + | Cop(Calloc, [hdr; ops; contents]) + when bi = Pint32 && size_int = 8 && not big_endian -> + (* Force sign-extension of low 32 bits *) + Cop(Casr, [Cop(Clsl, [contents; Cconst_int 32]); Cconst_int 32]) + | Cop(Calloc, [hdr; ops; contents]) -> + contents + | Clet(id, exp, body) -> Clet(id, exp, unbox_int bi body) + | Cifthenelse(cond, e1, e2) -> + Cifthenelse(cond, unbox_int bi e1, unbox_int bi e2) + | Csequence(e1, e2) -> Csequence(e1, unbox_int bi e2) + | Cswitch(e, tbl, el) -> Cswitch(e, tbl, Array.map (unbox_int bi) el) + | Ccatch(n, ids, e1, e2) -> Ccatch(n, ids, unbox_int bi e1, unbox_int bi e2) + | Ctrywith(e1, id, e2) -> Ctrywith(unbox_int bi e1, id, unbox_int bi e2) + | _ -> + Cop(Cload(if bi = Pint32 then Thirtytwo_signed else Word), + [Cop(Cadda, [arg; Cconst_int size_addr])]) + +let make_unsigned_int bi arg = + if bi = Pint32 && size_int = 8 + then Cop(Cand, [arg; Cconst_natint 0xFFFFFFFFn]) + else arg + +(* Big arrays *) + +let bigarray_elt_size = function + Pbigarray_unknown -> assert false + | Pbigarray_float32 -> 4 + | Pbigarray_float64 -> 8 + | Pbigarray_sint8 -> 1 + | Pbigarray_uint8 -> 1 + | Pbigarray_sint16 -> 2 + | Pbigarray_uint16 -> 2 + | Pbigarray_int32 -> 4 + | Pbigarray_int64 -> 8 + | Pbigarray_caml_int -> size_int + | Pbigarray_native_int -> size_int + | Pbigarray_complex32 -> 8 + | Pbigarray_complex64 -> 16 + +let bigarray_indexing unsafe elt_kind layout b args dbg = + let check_bound a1 a2 k = + if unsafe then k else Csequence(Cop(Ccheckbound dbg, [a1;a2]), k) in + let rec ba_indexing dim_ofs delta_ofs = function + [] -> assert false + | [arg] -> + bind "idx" (untag_int arg) + (fun idx -> + check_bound (Cop(Cload Word,[field_address b dim_ofs])) idx idx) + | arg1 :: argl -> + let rem = ba_indexing (dim_ofs + delta_ofs) delta_ofs argl in + bind "idx" (untag_int arg1) + (fun idx -> + bind "bound" (Cop(Cload Word, [field_address b dim_ofs])) + (fun bound -> + check_bound bound idx (add_int (mul_int rem bound) idx))) in + let offset = + match layout with + Pbigarray_unknown_layout -> + assert false + | Pbigarray_c_layout -> + ba_indexing (4 + List.length args) (-1) (List.rev args) + | Pbigarray_fortran_layout -> + ba_indexing 5 1 (List.map (fun idx -> sub_int idx (Cconst_int 2)) args) + and elt_size = + bigarray_elt_size elt_kind in + let byte_offset = + if elt_size = 1 + then offset + else Cop(Clsl, [offset; Cconst_int(log2 elt_size)]) in + Cop(Cadda, [Cop(Cload Word, [field_address b 1]); byte_offset]) + +let bigarray_word_kind = function + Pbigarray_unknown -> assert false + | Pbigarray_float32 -> Single + | Pbigarray_float64 -> Double + | Pbigarray_sint8 -> Byte_signed + | Pbigarray_uint8 -> Byte_unsigned + | Pbigarray_sint16 -> Sixteen_signed + | Pbigarray_uint16 -> Sixteen_unsigned + | Pbigarray_int32 -> Thirtytwo_signed + | Pbigarray_int64 -> Word + | Pbigarray_caml_int -> Word + | Pbigarray_native_int -> Word + | Pbigarray_complex32 -> Single + | Pbigarray_complex64 -> Double + +let bigarray_get unsafe elt_kind layout b args dbg = + match elt_kind with + Pbigarray_complex32 | Pbigarray_complex64 -> + let kind = bigarray_word_kind elt_kind in + let sz = bigarray_elt_size elt_kind / 2 in + bind "addr" (bigarray_indexing unsafe elt_kind layout b args dbg) (fun addr -> + box_complex + (Cop(Cload kind, [addr])) + (Cop(Cload kind, [Cop(Cadda, [addr; Cconst_int sz])]))) + | _ -> + Cop(Cload (bigarray_word_kind elt_kind), + [bigarray_indexing unsafe elt_kind layout b args dbg]) + +let bigarray_set unsafe elt_kind layout b args newval dbg = + match elt_kind with + Pbigarray_complex32 | Pbigarray_complex64 -> + let kind = bigarray_word_kind elt_kind in + let sz = bigarray_elt_size elt_kind / 2 in + bind "newval" newval (fun newv -> + bind "addr" (bigarray_indexing unsafe elt_kind layout b args dbg) (fun addr -> + Csequence( + Cop(Cstore kind, [addr; complex_re newv]), + Cop(Cstore kind, + [Cop(Cadda, [addr; Cconst_int sz]); complex_im newv])))) + | _ -> + Cop(Cstore (bigarray_word_kind elt_kind), + [bigarray_indexing unsafe elt_kind layout b args dbg; newval]) + +(* Simplification of some primitives into C calls *) + +let default_prim name = + { prim_name = name; prim_arity = 0 (*ignored*); + prim_alloc = true; prim_native_name = ""; prim_native_float = false } + +let simplif_primitive_32bits = function + Pbintofint Pint64 -> Pccall (default_prim "caml_int64_of_int") + | Pintofbint Pint64 -> Pccall (default_prim "caml_int64_to_int") + | Pcvtbint(Pint32, Pint64) -> Pccall (default_prim "caml_int64_of_int32") + | Pcvtbint(Pint64, Pint32) -> Pccall (default_prim "caml_int64_to_int32") + | Pcvtbint(Pnativeint, Pint64) -> + Pccall (default_prim "caml_int64_of_nativeint") + | Pcvtbint(Pint64, Pnativeint) -> + Pccall (default_prim "caml_int64_to_nativeint") + | Pnegbint Pint64 -> Pccall (default_prim "caml_int64_neg") + | Paddbint Pint64 -> Pccall (default_prim "caml_int64_add") + | Psubbint Pint64 -> Pccall (default_prim "caml_int64_sub") + | Pmulbint Pint64 -> Pccall (default_prim "caml_int64_mul") + | Pdivbint Pint64 -> Pccall (default_prim "caml_int64_div") + | Pmodbint Pint64 -> Pccall (default_prim "caml_int64_mod") + | Pandbint Pint64 -> Pccall (default_prim "caml_int64_and") + | Porbint Pint64 -> Pccall (default_prim "caml_int64_or") + | Pxorbint Pint64 -> Pccall (default_prim "caml_int64_xor") + | Plslbint Pint64 -> Pccall (default_prim "caml_int64_shift_left") + | Plsrbint Pint64 -> Pccall (default_prim "caml_int64_shift_right_unsigned") + | Pasrbint Pint64 -> Pccall (default_prim "caml_int64_shift_right") + | Pbintcomp(Pint64, Lambda.Ceq) -> Pccall (default_prim "caml_equal") + | Pbintcomp(Pint64, Lambda.Cneq) -> Pccall (default_prim "caml_notequal") + | Pbintcomp(Pint64, Lambda.Clt) -> Pccall (default_prim "caml_lessthan") + | Pbintcomp(Pint64, Lambda.Cgt) -> Pccall (default_prim "caml_greaterthan") + | Pbintcomp(Pint64, Lambda.Cle) -> Pccall (default_prim "caml_lessequal") + | Pbintcomp(Pint64, Lambda.Cge) -> Pccall (default_prim "caml_greaterequal") + | Pbigarrayref(unsafe, n, Pbigarray_int64, layout) -> + Pccall (default_prim ("caml_ba_get_" ^ string_of_int n)) + | Pbigarrayset(unsafe, n, Pbigarray_int64, layout) -> + Pccall (default_prim ("caml_ba_set_" ^ string_of_int n)) + | p -> p + +let simplif_primitive p = + match p with + | Pduprecord _ -> + Pccall (default_prim "caml_obj_dup") + | Pbigarrayref(unsafe, n, Pbigarray_unknown, layout) -> + Pccall (default_prim ("caml_ba_get_" ^ string_of_int n)) + | Pbigarrayset(unsafe, n, Pbigarray_unknown, layout) -> + Pccall (default_prim ("caml_ba_set_" ^ string_of_int n)) + | Pbigarrayref(unsafe, n, kind, Pbigarray_unknown_layout) -> + Pccall (default_prim ("caml_ba_get_" ^ string_of_int n)) + | Pbigarrayset(unsafe, n, kind, Pbigarray_unknown_layout) -> + Pccall (default_prim ("caml_ba_set_" ^ string_of_int n)) + | p -> + if size_int = 8 then p else simplif_primitive_32bits p + +(* Build switchers both for constants and blocks *) + +(* constants first *) + +let transl_isout h arg = tag_int (Cop(Ccmpa Clt, [h ; arg])) + +exception Found of int + +let make_switch_gen arg cases acts = + let lcases = Array.length cases in + let new_cases = Array.create lcases 0 in + let store = Switch.mk_store (=) in + + for i = 0 to Array.length cases-1 do + let act = cases.(i) in + let new_act = store.Switch.act_store act in + new_cases.(i) <- new_act + done ; + Cswitch + (arg, new_cases, + Array.map + (fun n -> acts.(n)) + (store.Switch.act_get ())) + + +(* Then for blocks *) + +module SArgBlocks = +struct + type primitive = operation + + let eqint = Ccmpi Ceq + let neint = Ccmpi Cne + let leint = Ccmpi Cle + let ltint = Ccmpi Clt + let geint = Ccmpi Cge + let gtint = Ccmpi Cgt + + type act = expression + + let default = Cexit (0,[]) + let make_prim p args = Cop (p,args) + let make_offset arg n = add_const arg n + let make_isout h arg = Cop (Ccmpa Clt, [h ; arg]) + let make_isin h arg = Cop (Ccmpa Cge, [h ; arg]) + let make_if cond ifso ifnot = Cifthenelse (cond, ifso, ifnot) + let make_switch arg cases actions = + make_switch_gen arg cases actions + let bind arg body = bind "switcher" arg body + +end + +module SwitcherBlocks = Switch.Make(SArgBlocks) + +(* Auxiliary functions for optimizing "let" of boxed numbers (floats and + boxed integers *) + +type unboxed_number_kind = + No_unboxing + | Boxed_float + | Boxed_integer of boxed_integer + +let is_unboxed_number = function + Uconst(Const_base(Const_float f)) -> + Boxed_float + | Uprim(p, _, _) -> + begin match simplif_primitive p with + Pccall p -> if p.prim_native_float then Boxed_float else No_unboxing + | Pfloatfield _ -> Boxed_float + | Pfloatofint -> Boxed_float + | Pnegfloat -> Boxed_float + | Pabsfloat -> Boxed_float + | Paddfloat -> Boxed_float + | Psubfloat -> Boxed_float + | Pmulfloat -> Boxed_float + | Pdivfloat -> Boxed_float + | Parrayrefu Pfloatarray -> Boxed_float + | Parrayrefs Pfloatarray -> Boxed_float + | Pbintofint bi -> Boxed_integer bi + | Pcvtbint(src, dst) -> Boxed_integer dst + | Pnegbint bi -> Boxed_integer bi + | Paddbint bi -> Boxed_integer bi + | Psubbint bi -> Boxed_integer bi + | Pmulbint bi -> Boxed_integer bi + | Pdivbint bi -> Boxed_integer bi + | Pmodbint bi -> Boxed_integer bi + | Pandbint bi -> Boxed_integer bi + | Porbint bi -> Boxed_integer bi + | Pxorbint bi -> Boxed_integer bi + | Plslbint bi -> Boxed_integer bi + | Plsrbint bi -> Boxed_integer bi + | Pasrbint bi -> Boxed_integer bi + | Pbigarrayref(_, _, (Pbigarray_float32 | Pbigarray_float64), _) -> + Boxed_float + | Pbigarrayref(_, _, Pbigarray_int32, _) -> Boxed_integer Pint32 + | Pbigarrayref(_, _, Pbigarray_int64, _) -> Boxed_integer Pint64 + | Pbigarrayref(_, _, Pbigarray_native_int, _) -> Boxed_integer Pnativeint + | _ -> No_unboxing + end + | _ -> No_unboxing + +let subst_boxed_number unbox_fn boxed_id unboxed_id exp = + let need_boxed = ref false in + let assigned = ref false in + let rec subst = function + Cvar id as e -> + if Ident.same id boxed_id then need_boxed := true; e + | Clet(id, arg, body) -> Clet(id, subst arg, subst body) + | Cassign(id, arg) -> + if Ident.same id boxed_id then begin + assigned := true; + Cassign(unboxed_id, subst(unbox_fn arg)) + end else + Cassign(id, subst arg) + | Ctuple argv -> Ctuple(List.map subst argv) + | Cop(Cload _, [Cvar id]) as e -> + if Ident.same id boxed_id then Cvar unboxed_id else e + | Cop(Cload _, [Cop(Cadda, [Cvar id; _])]) as e -> + if Ident.same id boxed_id then Cvar unboxed_id else e + | Cop(op, argv) -> Cop(op, List.map subst argv) + | Csequence(e1, e2) -> Csequence(subst e1, subst e2) + | Cifthenelse(e1, e2, e3) -> Cifthenelse(subst e1, subst e2, subst e3) + | Cswitch(arg, index, cases) -> + Cswitch(subst arg, index, Array.map subst cases) + | Cloop e -> Cloop(subst e) + | Ccatch(nfail, ids, e1, e2) -> Ccatch(nfail, ids, subst e1, subst e2) + | Cexit (nfail, el) -> Cexit (nfail, List.map subst el) + | Ctrywith(e1, id, e2) -> Ctrywith(subst e1, id, subst e2) + | e -> e in + let res = subst exp in + (res, !need_boxed, !assigned) + +(* Translate an expression *) + +let functions = (Queue.create() : (string * Ident.t list * ulambda) Queue.t) + +let rec transl = function + Uvar id -> + Cvar id + | Uconst sc -> + transl_constant sc + | Uclosure(fundecls, []) -> + let lbl = new_const_symbol() in + constant_closures := (lbl, fundecls) :: !constant_closures; + List.iter + (fun (label, arity, params, body) -> + Queue.add (label, params, body) functions) + fundecls; + Cconst_symbol lbl + | Uclosure(fundecls, clos_vars) -> + let block_size = + fundecls_size fundecls + List.length clos_vars in + let rec transl_fundecls pos = function + [] -> + List.map transl clos_vars + | (label, arity, params, body) :: rem -> + Queue.add (label, params, body) functions; + let header = + if pos = 0 + then alloc_closure_header block_size + else alloc_infix_header pos in + if arity = 1 then + header :: + Cconst_symbol label :: + int_const 1 :: + transl_fundecls (pos + 3) rem + else + header :: + Cconst_symbol(curry_function arity) :: + int_const arity :: + Cconst_symbol label :: + transl_fundecls (pos + 4) rem in + Cop(Calloc, transl_fundecls 0 fundecls) + | Uoffset(arg, offset) -> + field_address (transl arg) offset + | Udirect_apply(lbl, args, dbg) -> + Cop(Capply(typ_addr, dbg), Cconst_symbol lbl :: List.map transl args) + | Ugeneric_apply(clos, [arg], dbg) -> + bind "fun" (transl clos) (fun clos -> + Cop(Capply(typ_addr, dbg), [get_field clos 0; transl arg; clos])) + | Ugeneric_apply(clos, args, dbg) -> + let arity = List.length args in + let cargs = Cconst_symbol(apply_function arity) :: + List.map transl (args @ [clos]) in + Cop(Capply(typ_addr, dbg), cargs) + | Usend(kind, met, obj, args, dbg) -> + let call_met obj args clos = + if args = [] then + Cop(Capply(typ_addr, dbg), [get_field clos 0;obj;clos]) + else + let arity = List.length args + 1 in + let cargs = Cconst_symbol(apply_function arity) :: obj :: + (List.map transl args) @ [clos] in + Cop(Capply(typ_addr, dbg), cargs) + in + bind "obj" (transl obj) (fun obj -> + match kind, args with + Self, _ -> + bind "met" (lookup_label obj (transl met)) (call_met obj args) + | Cached, cache :: pos :: args -> + call_cached_method obj (transl met) (transl cache) (transl pos) + (List.map transl args) dbg + | _ -> + bind "met" (lookup_tag obj (transl met)) (call_met obj args)) + | Ulet(id, exp, body) -> + begin match is_unboxed_number exp with + No_unboxing -> + Clet(id, transl exp, transl body) + | Boxed_float -> + transl_unbox_let box_float unbox_float transl_unbox_float + id exp body + | Boxed_integer bi -> + transl_unbox_let (box_int bi) (unbox_int bi) (transl_unbox_int bi) + id exp body + end + | Uletrec(bindings, body) -> + transl_letrec bindings (transl body) + + (* Primitives *) + | Uprim(prim, args, dbg) -> + begin match (simplif_primitive prim, args) with + (Pgetglobal id, []) -> + Cconst_symbol (Ident.name id) + | (Pmakeblock(tag, mut), []) -> + transl_constant(Const_block(tag, [])) + | (Pmakeblock(tag, mut), args) -> + make_alloc tag (List.map transl args) + | (Pccall prim, args) -> + if prim.prim_native_float then + box_float + (Cop(Cextcall(prim.prim_native_name, typ_float, false, dbg), + List.map transl_unbox_float args)) + else + Cop(Cextcall(Primitive.native_name prim, typ_addr, prim.prim_alloc, dbg), + List.map transl args) + | (Pmakearray kind, []) -> + transl_constant(Const_block(0, [])) + | (Pmakearray kind, args) -> + begin match kind with + Pgenarray -> + Cop(Cextcall("caml_make_array", typ_addr, true, Debuginfo.none), + [make_alloc 0 (List.map transl args)]) + | Paddrarray | Pintarray -> + make_alloc 0 (List.map transl args) + | Pfloatarray -> + make_float_alloc Obj.double_array_tag + (List.map transl_unbox_float args) + end + | (Pbigarrayref(unsafe, num_dims, elt_kind, layout), arg1 :: argl) -> + let elt = + bigarray_get unsafe elt_kind layout + (transl arg1) (List.map transl argl) dbg in + begin match elt_kind with + Pbigarray_float32 | Pbigarray_float64 -> box_float elt + | Pbigarray_complex32 | Pbigarray_complex64 -> elt + | Pbigarray_int32 -> box_int Pint32 elt + | Pbigarray_int64 -> box_int Pint64 elt + | Pbigarray_native_int -> box_int Pnativeint elt + | Pbigarray_caml_int -> force_tag_int elt + | _ -> tag_int elt + end + | (Pbigarrayset(unsafe, num_dims, elt_kind, layout), arg1 :: argl) -> + let (argidx, argnewval) = split_last argl in + return_unit(bigarray_set unsafe elt_kind layout + (transl arg1) + (List.map transl argidx) + (match elt_kind with + Pbigarray_float32 | Pbigarray_float64 -> + transl_unbox_float argnewval + | Pbigarray_complex32 | Pbigarray_complex64 -> transl argnewval + | Pbigarray_int32 -> transl_unbox_int Pint32 argnewval + | Pbigarray_int64 -> transl_unbox_int Pint64 argnewval + | Pbigarray_native_int -> transl_unbox_int Pnativeint argnewval + | _ -> untag_int (transl argnewval)) + dbg) + | (p, [arg]) -> + transl_prim_1 p arg dbg + | (p, [arg1; arg2]) -> + transl_prim_2 p arg1 arg2 dbg + | (p, [arg1; arg2; arg3]) -> + transl_prim_3 p arg1 arg2 arg3 dbg + | (_, _) -> + fatal_error "Cmmgen.transl:prim" + end + + (* Control structures *) + | Uswitch(arg, s) -> + (* As in the bytecode interpreter, only matching against constants + can be checked *) + if Array.length s.us_index_blocks = 0 then + Cswitch + (untag_int (transl arg), + s.us_index_consts, + Array.map transl s.us_actions_consts) + else if Array.length s.us_index_consts = 0 then + transl_switch (get_tag (transl arg)) + s.us_index_blocks s.us_actions_blocks + else + bind "switch" (transl arg) (fun arg -> + Cifthenelse( + Cop(Cand, [arg; Cconst_int 1]), + transl_switch + (untag_int arg) s.us_index_consts s.us_actions_consts, + transl_switch + (get_tag arg) s.us_index_blocks s.us_actions_blocks)) + | Ustaticfail (nfail, args) -> + Cexit (nfail, List.map transl args) + | Ucatch(nfail, [], body, handler) -> + make_catch nfail (transl body) (transl handler) + | Ucatch(nfail, ids, body, handler) -> + Ccatch(nfail, ids, transl body, transl handler) + | Utrywith(body, exn, handler) -> + Ctrywith(transl body, exn, transl handler) + | Uifthenelse(Uprim(Pnot, [arg], _), ifso, ifnot) -> + transl (Uifthenelse(arg, ifnot, ifso)) + | Uifthenelse(cond, ifso, Ustaticfail (nfail, [])) -> + exit_if_false cond (transl ifso) nfail + | Uifthenelse(cond, Ustaticfail (nfail, []), ifnot) -> + exit_if_true cond nfail (transl ifnot) + | Uifthenelse(Uprim(Psequand, _, _) as cond, ifso, ifnot) -> + let raise_num = next_raise_count () in + make_catch + raise_num + (exit_if_false cond (transl ifso) raise_num) + (transl ifnot) + | Uifthenelse(Uprim(Psequor, _, _) as cond, ifso, ifnot) -> + let raise_num = next_raise_count () in + make_catch + raise_num + (exit_if_true cond raise_num (transl ifnot)) + (transl ifso) + | Uifthenelse (Uifthenelse (cond, condso, condnot), ifso, ifnot) -> + let num_true = next_raise_count () in + make_catch + num_true + (make_catch2 + (fun shared_false -> + Cifthenelse + (test_bool (transl cond), + exit_if_true condso num_true shared_false, + exit_if_true condnot num_true shared_false)) + (transl ifnot)) + (transl ifso) + | Uifthenelse(cond, ifso, ifnot) -> + Cifthenelse(test_bool(transl cond), transl ifso, transl ifnot) + | Usequence(exp1, exp2) -> + Csequence(remove_unit(transl exp1), transl exp2) + | Uwhile(cond, body) -> + let raise_num = next_raise_count () in + return_unit + (Ccatch + (raise_num, [], + Cloop(exit_if_false cond (remove_unit(transl body)) raise_num), + Ctuple [])) + | Ufor(id, low, high, dir, body) -> + let tst = match dir with Upto -> Cgt | Downto -> Clt in + let inc = match dir with Upto -> Caddi | Downto -> Csubi in + let raise_num = next_raise_count () in + let id_prev = Ident.rename id in + return_unit + (Clet + (id, transl low, + bind_nonvar "bound" (transl high) (fun high -> + Ccatch + (raise_num, [], + Cifthenelse + (Cop(Ccmpi tst, [Cvar id; high]), Cexit (raise_num, []), + Cloop + (Csequence + (remove_unit(transl body), + Clet(id_prev, Cvar id, + Csequence + (Cassign(id, + Cop(inc, [Cvar id; Cconst_int 2])), + Cifthenelse + (Cop(Ccmpi Ceq, [Cvar id_prev; high]), + Cexit (raise_num,[]), Ctuple [])))))), + Ctuple [])))) + | Uassign(id, exp) -> + return_unit(Cassign(id, transl exp)) + +and transl_prim_1 p arg dbg = + match p with + (* Generic operations *) + Pidentity -> + transl arg + | Pignore -> + return_unit(remove_unit (transl arg)) + (* Heap operations *) + | Pfield n -> + get_field (transl arg) n + | Pfloatfield n -> + let ptr = transl arg in + box_float( + Cop(Cload Double_u, + [if n = 0 then ptr + else Cop(Cadda, [ptr; Cconst_int(n * size_float)])])) + (* Exceptions *) + | Praise -> + Cop(Craise dbg, [transl arg]) + (* Integer operations *) + | Pnegint -> + Cop(Csubi, [Cconst_int 2; transl arg]) + | Poffsetint n -> + if no_overflow_lsl n then + add_const (transl arg) (n lsl 1) + else + transl_prim_2 Paddint arg (Uconst (Const_base(Const_int n))) Debuginfo.none + | Poffsetref n -> + return_unit + (bind "ref" (transl arg) (fun arg -> + Cop(Cstore Word, + [arg; add_const (Cop(Cload Word, [arg])) (n lsl 1)]))) + (* Floating-point operations *) + | Pfloatofint -> + box_float(Cop(Cfloatofint, [untag_int(transl arg)])) + | Pintoffloat -> + tag_int(Cop(Cintoffloat, [transl_unbox_float arg])) + | Pnegfloat -> + box_float(Cop(Cnegf, [transl_unbox_float arg])) + | Pabsfloat -> + box_float(Cop(Cabsf, [transl_unbox_float arg])) + (* String operations *) + | Pstringlength -> + tag_int(string_length (transl arg)) + (* Array operations *) + | Parraylength kind -> + begin match kind with + Pgenarray -> + let len = + if wordsize_shift = numfloat_shift then + Cop(Clsr, [header(transl arg); Cconst_int wordsize_shift]) + else + bind "header" (header(transl arg)) (fun hdr -> + Cifthenelse(is_addr_array_hdr hdr, + Cop(Clsr, [hdr; Cconst_int wordsize_shift]), + Cop(Clsr, [hdr; Cconst_int numfloat_shift]))) in + Cop(Cor, [len; Cconst_int 1]) + | Paddrarray | Pintarray -> + Cop(Cor, [addr_array_length(header(transl arg)); Cconst_int 1]) + | Pfloatarray -> + Cop(Cor, [float_array_length(header(transl arg)); Cconst_int 1]) + end + (* Boolean operations *) + | Pnot -> + Cop(Csubi, [Cconst_int 4; transl arg]) (* 1 -> 3, 3 -> 1 *) + (* Test integer/block *) + | Pisint -> + tag_int(Cop(Cand, [transl arg; Cconst_int 1])) + (* Boxed integers *) + | Pbintofint bi -> + box_int bi (untag_int (transl arg)) + | Pintofbint bi -> + force_tag_int (transl_unbox_int bi arg) + | Pcvtbint(bi1, bi2) -> + box_int bi2 (transl_unbox_int bi1 arg) + | Pnegbint bi -> + box_int bi (Cop(Csubi, [Cconst_int 0; transl_unbox_int bi arg])) + | _ -> + fatal_error "Cmmgen.transl_prim_1" + +and transl_prim_2 p arg1 arg2 dbg = + match p with + (* Heap operations *) + Psetfield(n, ptr) -> + if ptr then + return_unit(Cop(Cextcall("caml_modify", typ_void, false, Debuginfo.none), + [field_address (transl arg1) n; transl arg2])) + else + return_unit(set_field (transl arg1) n (transl arg2)) + | Psetfloatfield n -> + let ptr = transl arg1 in + return_unit( + Cop(Cstore Double_u, + [if n = 0 then ptr + else Cop(Cadda, [ptr; Cconst_int(n * size_float)]); + transl_unbox_float arg2])) + + (* Boolean operations *) + | Psequand -> + Cifthenelse(test_bool(transl arg1), transl arg2, Cconst_int 1) + (* let id = Ident.create "res1" in + Clet(id, transl arg1, + Cifthenelse(test_bool(Cvar id), transl arg2, Cvar id)) *) + | Psequor -> + Cifthenelse(test_bool(transl arg1), Cconst_int 3, transl arg2) + + (* Integer operations *) + | Paddint -> + decr_int(add_int (transl arg1) (transl arg2)) + | Psubint -> + incr_int(sub_int (transl arg1) (transl arg2)) + | Pmulint -> + incr_int(Cop(Cmuli, [decr_int(transl arg1); untag_int(transl arg2)])) + | Pdivint -> + tag_int(safe_divmod Cdivi (untag_int(transl arg1)) (untag_int(transl arg2)) dbg) + | Pmodint -> + tag_int(safe_divmod Cmodi (untag_int(transl arg1)) (untag_int(transl arg2)) dbg) + | Pandint -> + Cop(Cand, [transl arg1; transl arg2]) + | Porint -> + Cop(Cor, [transl arg1; transl arg2]) + | Pxorint -> + Cop(Cor, [Cop(Cxor, [ignore_low_bit_int(transl arg1); + ignore_low_bit_int(transl arg2)]); + Cconst_int 1]) + | Plslint -> + incr_int(lsl_int (decr_int(transl arg1)) (untag_int(transl arg2))) + | Plsrint -> + Cop(Cor, [Cop(Clsr, [transl arg1; untag_int(transl arg2)]); + Cconst_int 1]) + | Pasrint -> + Cop(Cor, [Cop(Casr, [transl arg1; untag_int(transl arg2)]); + Cconst_int 1]) + | Pintcomp cmp -> + tag_int(Cop(Ccmpi(transl_comparison cmp), [transl arg1; transl arg2])) + | Pisout -> + transl_isout (transl arg1) (transl arg2) + (* Float operations *) + | Paddfloat -> + box_float(Cop(Caddf, + [transl_unbox_float arg1; transl_unbox_float arg2])) + | Psubfloat -> + box_float(Cop(Csubf, + [transl_unbox_float arg1; transl_unbox_float arg2])) + | Pmulfloat -> + box_float(Cop(Cmulf, + [transl_unbox_float arg1; transl_unbox_float arg2])) + | Pdivfloat -> + box_float(Cop(Cdivf, + [transl_unbox_float arg1; transl_unbox_float arg2])) + | Pfloatcomp cmp -> + tag_int(Cop(Ccmpf(transl_comparison cmp), + [transl_unbox_float arg1; transl_unbox_float arg2])) + + (* String operations *) + | Pstringrefu -> + tag_int(Cop(Cload Byte_unsigned, + [add_int (transl arg1) (untag_int(transl arg2))])) + | Pstringrefs -> + tag_int + (bind "str" (transl arg1) (fun str -> + bind "index" (untag_int (transl arg2)) (fun idx -> + Csequence( + Cop(Ccheckbound dbg, [string_length str; idx]), + Cop(Cload Byte_unsigned, [add_int str idx]))))) + + (* Array operations *) + | Parrayrefu kind -> + begin match kind with + Pgenarray -> + bind "arr" (transl arg1) (fun arr -> + bind "index" (transl arg2) (fun idx -> + Cifthenelse(is_addr_array_ptr arr, + addr_array_ref arr idx, + float_array_ref arr idx))) + | Paddrarray | Pintarray -> + addr_array_ref (transl arg1) (transl arg2) + | Pfloatarray -> + float_array_ref (transl arg1) (transl arg2) + end + | Parrayrefs kind -> + begin match kind with + Pgenarray -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + bind "header" (header arr) (fun hdr -> + Cifthenelse(is_addr_array_hdr hdr, + Csequence(Cop(Ccheckbound dbg, [addr_array_length hdr; idx]), + addr_array_ref arr idx), + Csequence(Cop(Ccheckbound dbg, [float_array_length hdr; idx]), + float_array_ref arr idx))))) + | Paddrarray | Pintarray -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + Csequence(Cop(Ccheckbound dbg, [addr_array_length(header arr); idx]), + addr_array_ref arr idx))) + | Pfloatarray -> + box_float( + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + Csequence(Cop(Ccheckbound dbg, + [float_array_length(header arr); idx]), + unboxed_float_array_ref arr idx)))) + end + + (* Operations on bitvects *) + | Pbittest -> + bind "index" (untag_int(transl arg2)) (fun idx -> + tag_int( + Cop(Cand, [Cop(Clsr, [Cop(Cload Byte_unsigned, + [add_int (transl arg1) + (Cop(Clsr, [idx; Cconst_int 3]))]); + Cop(Cand, [idx; Cconst_int 7])]); + Cconst_int 1]))) + + (* Boxed integers *) + | Paddbint bi -> + box_int bi (Cop(Caddi, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Psubbint bi -> + box_int bi (Cop(Csubi, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Pmulbint bi -> + box_int bi (Cop(Cmuli, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Pdivbint bi -> + box_int bi (safe_divmod Cdivi + (transl_unbox_int bi arg1) (transl_unbox_int bi arg2) + dbg) + | Pmodbint bi -> + box_int bi (safe_divmod Cmodi + (transl_unbox_int bi arg1) (transl_unbox_int bi arg2) + dbg) + | Pandbint bi -> + box_int bi (Cop(Cand, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Porbint bi -> + box_int bi (Cop(Cor, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Pxorbint bi -> + box_int bi (Cop(Cxor, + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | Plslbint bi -> + box_int bi (Cop(Clsl, + [transl_unbox_int bi arg1; untag_int(transl arg2)])) + | Plsrbint bi -> + box_int bi (Cop(Clsr, + [make_unsigned_int bi (transl_unbox_int bi arg1); + untag_int(transl arg2)])) + | Pasrbint bi -> + box_int bi (Cop(Casr, + [transl_unbox_int bi arg1; untag_int(transl arg2)])) + | Pbintcomp(bi, cmp) -> + tag_int (Cop(Ccmpi(transl_comparison cmp), + [transl_unbox_int bi arg1; transl_unbox_int bi arg2])) + | _ -> + fatal_error "Cmmgen.transl_prim_2" + +and transl_prim_3 p arg1 arg2 arg3 dbg = + match p with + (* String operations *) + Pstringsetu -> + return_unit(Cop(Cstore Byte_unsigned, + [add_int (transl arg1) (untag_int(transl arg2)); + untag_int(transl arg3)])) + | Pstringsets -> + return_unit + (bind "str" (transl arg1) (fun str -> + bind "index" (untag_int (transl arg2)) (fun idx -> + Csequence( + Cop(Ccheckbound dbg, [string_length str; idx]), + Cop(Cstore Byte_unsigned, + [add_int str idx; untag_int(transl arg3)]))))) + + (* Array operations *) + | Parraysetu kind -> + return_unit(begin match kind with + Pgenarray -> + bind "newval" (transl arg3) (fun newval -> + bind "index" (transl arg2) (fun index -> + bind "arr" (transl arg1) (fun arr -> + Cifthenelse(is_addr_array_ptr arr, + addr_array_set arr index newval, + float_array_set arr index (unbox_float newval))))) + | Paddrarray -> + addr_array_set (transl arg1) (transl arg2) (transl arg3) + | Pintarray -> + int_array_set (transl arg1) (transl arg2) (transl arg3) + | Pfloatarray -> + float_array_set (transl arg1) (transl arg2) (transl_unbox_float arg3) + end) + | Parraysets kind -> + return_unit(begin match kind with + Pgenarray -> + bind "newval" (transl arg3) (fun newval -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + bind "header" (header arr) (fun hdr -> + Cifthenelse(is_addr_array_hdr hdr, + Csequence(Cop(Ccheckbound dbg, [addr_array_length hdr; idx]), + addr_array_set arr idx newval), + Csequence(Cop(Ccheckbound dbg, [float_array_length hdr; idx]), + float_array_set arr idx + (unbox_float newval))))))) + | Paddrarray -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + Csequence(Cop(Ccheckbound dbg, [addr_array_length(header arr); idx]), + addr_array_set arr idx (transl arg3)))) + | Pintarray -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + Csequence(Cop(Ccheckbound dbg, [addr_array_length(header arr); idx]), + int_array_set arr idx (transl arg3)))) + | Pfloatarray -> + bind "index" (transl arg2) (fun idx -> + bind "arr" (transl arg1) (fun arr -> + Csequence(Cop(Ccheckbound dbg, [float_array_length(header arr);idx]), + float_array_set arr idx (transl_unbox_float arg3)))) + end) + | _ -> + fatal_error "Cmmgen.transl_prim_3" + +and transl_unbox_float = function + Uconst(Const_base(Const_float f)) -> Cconst_float f + | exp -> unbox_float(transl exp) + +and transl_unbox_int bi = function + Uconst(Const_base(Const_int32 n)) -> + Cconst_natint (Nativeint.of_int32 n) + | Uconst(Const_base(Const_nativeint n)) -> + Cconst_natint n + | Uconst(Const_base(Const_int64 n)) -> + assert (size_int = 8); Cconst_natint (Int64.to_nativeint n) + | Uprim(Pbintofint bi', [Uconst(Const_base(Const_int i))], _) when bi = bi' -> + Cconst_int i + | exp -> unbox_int bi (transl exp) + +and transl_unbox_let box_fn unbox_fn transl_unbox_fn id exp body = + let unboxed_id = Ident.create (Ident.name id) in + let trbody1 = transl body in + let (trbody2, need_boxed, is_assigned) = + subst_boxed_number unbox_fn id unboxed_id trbody1 in + if need_boxed && is_assigned then + Clet(id, transl exp, trbody1) + else + Clet(unboxed_id, transl_unbox_fn exp, + if need_boxed + then Clet(id, box_fn(Cvar unboxed_id), trbody2) + else trbody2) + +and make_catch ncatch body handler = match body with +| Cexit (nexit,[]) when nexit=ncatch -> handler +| _ -> Ccatch (ncatch, [], body, handler) + +and make_catch2 mk_body handler = match handler with +| Cexit (_,[])|Ctuple []|Cconst_int _|Cconst_pointer _ -> + mk_body handler +| _ -> + let nfail = next_raise_count () in + make_catch + nfail + (mk_body (Cexit (nfail,[]))) + handler + +and exit_if_true cond nfail otherwise = + match cond with + | Uconst (Const_pointer 0) -> otherwise + | Uconst (Const_pointer 1) -> Cexit (nfail,[]) + | Uprim(Psequor, [arg1; arg2], _) -> + exit_if_true arg1 nfail (exit_if_true arg2 nfail otherwise) + | Uprim(Psequand, _, _) -> + begin match otherwise with + | Cexit (raise_num,[]) -> + exit_if_false cond (Cexit (nfail,[])) raise_num + | _ -> + let raise_num = next_raise_count () in + make_catch + raise_num + (exit_if_false cond (Cexit (nfail,[])) raise_num) + otherwise + end + | Uprim(Pnot, [arg], _) -> + exit_if_false arg otherwise nfail + | Uifthenelse (cond, ifso, ifnot) -> + make_catch2 + (fun shared -> + Cifthenelse + (test_bool (transl cond), + exit_if_true ifso nfail shared, + exit_if_true ifnot nfail shared)) + otherwise + | _ -> + Cifthenelse(test_bool(transl cond), Cexit (nfail, []), otherwise) + +and exit_if_false cond otherwise nfail = + match cond with + | Uconst (Const_pointer 0) -> Cexit (nfail,[]) + | Uconst (Const_pointer 1) -> otherwise + | Uprim(Psequand, [arg1; arg2], _) -> + exit_if_false arg1 (exit_if_false arg2 otherwise nfail) nfail + | Uprim(Psequor, _, _) -> + begin match otherwise with + | Cexit (raise_num,[]) -> + exit_if_true cond raise_num (Cexit (nfail,[])) + | _ -> + let raise_num = next_raise_count () in + make_catch + raise_num + (exit_if_true cond raise_num (Cexit (nfail,[]))) + otherwise + end + | Uprim(Pnot, [arg], _) -> + exit_if_true arg nfail otherwise + | Uifthenelse (cond, ifso, ifnot) -> + make_catch2 + (fun shared -> + Cifthenelse + (test_bool (transl cond), + exit_if_false ifso shared nfail, + exit_if_false ifnot shared nfail)) + otherwise + | _ -> + Cifthenelse(test_bool(transl cond), otherwise, Cexit (nfail, [])) + +and transl_switch arg index cases = match Array.length cases with +| 0 -> fatal_error "Cmmgen.transl_switch" +| 1 -> transl cases.(0) +| _ -> + let n_index = Array.length index in + let actions = Array.map transl cases in + + let inters = ref [] + and this_high = ref (n_index-1) + and this_low = ref (n_index-1) + and this_act = ref index.(n_index-1) in + for i = n_index-2 downto 0 do + let act = index.(i) in + if act = !this_act then + decr this_low + else begin + inters := (!this_low, !this_high, !this_act) :: !inters ; + this_high := i ; + this_low := i ; + this_act := act + end + done ; + inters := (0, !this_high, !this_act) :: !inters ; + bind "switcher" arg + (fun a -> + SwitcherBlocks.zyva + (0,n_index-1) + (fun i -> Cconst_int i) + a + (Array.of_list !inters) actions) + +and transl_letrec bindings cont = + let bsz = List.map (fun (id, exp) -> (id, exp, expr_size exp)) bindings in + let rec init_blocks = function + | [] -> fill_nonrec bsz + | (id, exp, RHS_block sz) :: rem -> + Clet(id, Cop(Cextcall("caml_alloc_dummy", typ_addr, true, Debuginfo.none), + [int_const sz]), + init_blocks rem) + | (id, exp, RHS_nonrec) :: rem -> + Clet (id, Cconst_int 0, init_blocks rem) + and fill_nonrec = function + | [] -> fill_blocks bsz + | (id, exp, RHS_block sz) :: rem -> fill_nonrec rem + | (id, exp, RHS_nonrec) :: rem -> + Clet (id, transl exp, fill_nonrec rem) + and fill_blocks = function + | [] -> cont + | (id, exp, RHS_block _) :: rem -> + Csequence(Cop(Cextcall("caml_update_dummy", typ_void, false, Debuginfo.none), + [Cvar id; transl exp]), + fill_blocks rem) + | (id, exp, RHS_nonrec) :: rem -> + fill_blocks rem + in init_blocks bsz + +(* Translate a function definition *) + +let transl_function lbl params body = + Cfunction {fun_name = lbl; + fun_args = List.map (fun id -> (id, typ_addr)) params; + fun_body = transl body; + fun_fast = !Clflags.optimize_for_speed} + +(* Translate all function definitions *) + +module StringSet = + Set.Make(struct + type t = string + let compare = compare + end) + +let rec transl_all_functions already_translated cont = + try + let (lbl, params, body) = Queue.take functions in + if StringSet.mem lbl already_translated then + transl_all_functions already_translated cont + else begin + transl_all_functions (StringSet.add lbl already_translated) + (transl_function lbl params body :: cont) + end + with Queue.Empty -> + cont + +(* Emit structured constants *) + +let immstrings = Hashtbl.create 17 + +let rec emit_constant symb cst cont = + match cst with + Const_base(Const_float s) -> + Cint(float_header) :: Cdefine_symbol symb :: Cdouble s :: cont + | Const_base(Const_string s) | Const_immstring s -> + Cint(string_header (String.length s)) :: + Cdefine_symbol symb :: + emit_string_constant s cont + | Const_base(Const_int32 n) -> + Cint(boxedint_header) :: Cdefine_symbol symb :: + emit_boxed_int32_constant n cont + | Const_base(Const_int64 n) -> + Cint(boxedint_header) :: Cdefine_symbol symb :: + emit_boxed_int64_constant n cont + | Const_base(Const_nativeint n) -> + Cint(boxedint_header) :: Cdefine_symbol symb :: + emit_boxed_nativeint_constant n cont + | Const_block(tag, fields) -> + let (emit_fields, cont1) = emit_constant_fields fields cont in + Cint(block_header tag (List.length fields)) :: + Cdefine_symbol symb :: + emit_fields @ cont1 + | Const_float_array(fields) -> + Cint(floatarray_header (List.length fields)) :: + Cdefine_symbol symb :: + Misc.map_end (fun f -> Cdouble f) fields cont + | _ -> fatal_error "gencmm.emit_constant" + +and emit_constant_fields fields cont = + match fields with + [] -> ([], cont) + | f1 :: fl -> + let (data1, cont1) = emit_constant_field f1 cont in + let (datal, contl) = emit_constant_fields fl cont1 in + (data1 :: datal, contl) + +and emit_constant_field field cont = + match field with + Const_base(Const_int n) -> + (Cint(Nativeint.add (Nativeint.shift_left (Nativeint.of_int n) 1) 1n), + cont) + | Const_base(Const_char c) -> + (Cint(Nativeint.of_int(((Char.code c) lsl 1) + 1)), cont) + | Const_base(Const_float s) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(float_header) :: Cdefine_label lbl :: Cdouble s :: cont) + | Const_base(Const_string s) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(string_header (String.length s)) :: Cdefine_label lbl :: + emit_string_constant s cont) + | Const_immstring s -> + begin try + (Clabel_address (Hashtbl.find immstrings s), cont) + with Not_found -> + let lbl = new_const_label() in + Hashtbl.add immstrings s lbl; + (Clabel_address lbl, + Cint(string_header (String.length s)) :: Cdefine_label lbl :: + emit_string_constant s cont) + end + | Const_base(Const_int32 n) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(boxedint_header) :: Cdefine_label lbl :: + emit_boxed_int32_constant n cont) + | Const_base(Const_int64 n) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(boxedint_header) :: Cdefine_label lbl :: + emit_boxed_int64_constant n cont) + | Const_base(Const_nativeint n) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(boxedint_header) :: Cdefine_label lbl :: + emit_boxed_nativeint_constant n cont) + | Const_pointer n -> + (Cint(Nativeint.add (Nativeint.shift_left (Nativeint.of_int n) 1) 1n), + cont) + | Const_block(tag, fields) -> + let lbl = new_const_label() in + let (emit_fields, cont1) = emit_constant_fields fields cont in + (Clabel_address lbl, + Cint(block_header tag (List.length fields)) :: Cdefine_label lbl :: + emit_fields @ cont1) + | Const_float_array(fields) -> + let lbl = new_const_label() in + (Clabel_address lbl, + Cint(floatarray_header (List.length fields)) :: Cdefine_label lbl :: + Misc.map_end (fun f -> Cdouble f) fields cont) + +and emit_string_constant s cont = + let n = size_int - 1 - (String.length s) mod size_int in + Cstring s :: Cskip n :: Cint8 n :: cont + +and emit_boxed_int32_constant n cont = + let n = Nativeint.of_int32 n in + if size_int = 8 then + Csymbol_address("caml_int32_ops") :: Cint32 n :: Cint32 0n :: cont + else + Csymbol_address("caml_int32_ops") :: Cint n :: cont + +and emit_boxed_nativeint_constant n cont = + Csymbol_address("caml_nativeint_ops") :: Cint n :: cont + +and emit_boxed_int64_constant n cont = + let lo = Int64.to_nativeint n in + if size_int = 8 then + Csymbol_address("caml_int64_ops") :: Cint lo :: cont + else begin + let hi = Int64.to_nativeint (Int64.shift_right n 32) in + if big_endian then + Csymbol_address("caml_int64_ops") :: Cint hi :: Cint lo :: cont + else + Csymbol_address("caml_int64_ops") :: Cint lo :: Cint hi :: cont + end + +(* Emit constant closures *) + +let emit_constant_closure symb fundecls cont = + match fundecls with + [] -> assert false + | (label, arity, params, body) :: remainder -> + let rec emit_others pos = function + [] -> cont + | (label, arity, params, body) :: rem -> + if arity = 1 then + Cint(infix_header pos) :: + Csymbol_address label :: + Cint 3n :: + emit_others (pos + 3) rem + else + Cint(infix_header pos) :: + Csymbol_address(curry_function arity) :: + Cint(Nativeint.of_int (arity lsl 1 + 1)) :: + Csymbol_address label :: + emit_others (pos + 4) rem in + Cint(closure_header (fundecls_size fundecls)) :: + Cdefine_symbol symb :: + if arity = 1 then + Csymbol_address label :: + Cint 3n :: + emit_others 3 remainder + else + Csymbol_address(curry_function arity) :: + Cint(Nativeint.of_int (arity lsl 1 + 1)) :: + Csymbol_address label :: + emit_others 4 remainder + +(* Emit all structured constants *) + +let emit_all_constants cont = + let c = ref cont in + List.iter + (fun (lbl, cst) -> c := Cdata(emit_constant lbl cst []) :: !c) + !structured_constants; + structured_constants := []; + Hashtbl.clear immstrings; (* PR#3979 *) + List.iter + (fun (symb, fundecls) -> + c := Cdata(emit_constant_closure symb fundecls []) :: !c) + !constant_closures; + constant_closures := []; + !c + +(* Translate a compilation unit *) + +let compunit size ulam = + let glob = Compilenv.make_symbol None in + let init_code = transl ulam in + let c1 = [Cfunction {fun_name = Compilenv.make_symbol (Some "entry"); + fun_args = []; + fun_body = init_code; fun_fast = false}] in + let c2 = transl_all_functions StringSet.empty c1 in + let c3 = emit_all_constants c2 in + Cdata [Cint(block_header 0 size); + Cglobal_symbol glob; + Cdefine_symbol glob; + Cskip(size * size_addr)] :: c3 + +(* +CAMLprim value caml_cache_public_method (value meths, value tag, value *cache) +{ + int li = 3, hi = Field(meths,0), mi; + while (li < hi) { // no need to check the 1st time + mi = ((li+hi) >> 1) | 1; + if (tag < Field(meths,mi)) hi = mi-2; + else li = mi; + } + *cache = (li-3)*sizeof(value)+1; + return Field (meths, li-1); +} +*) + +let cache_public_method meths tag cache = + let raise_num = next_raise_count () in + let li = Ident.create "li" and hi = Ident.create "hi" + and mi = Ident.create "mi" and tagged = Ident.create "tagged" in + Clet ( + li, Cconst_int 3, + Clet ( + hi, Cop(Cload Word, [meths]), + Csequence( + Ccatch + (raise_num, [], + Cloop + (Clet( + mi, + Cop(Cor, + [Cop(Clsr, [Cop(Caddi, [Cvar li; Cvar hi]); Cconst_int 1]); + Cconst_int 1]), + Csequence( + Cifthenelse + (Cop (Ccmpi Clt, + [tag; + Cop(Cload Word, + [Cop(Cadda, + [meths; lsl_const (Cvar mi) log2_size_addr])])]), + Cassign(hi, Cop(Csubi, [Cvar mi; Cconst_int 2])), + Cassign(li, Cvar mi)), + Cifthenelse + (Cop(Ccmpi Cge, [Cvar li; Cvar hi]), Cexit (raise_num, []), + Ctuple [])))), + Ctuple []), + Clet ( + tagged, Cop(Cadda, [lsl_const (Cvar li) log2_size_addr; + Cconst_int(1 - 3 * size_addr)]), + Csequence(Cop (Cstore Word, [cache; Cvar tagged]), + Cvar tagged))))) + +(* Generate an application function: + (defun caml_applyN (a1 ... aN clos) + (if (= clos.arity N) + (app clos.direct a1 ... aN clos) + (let (clos1 (app clos.code a1 clos) + clos2 (app clos1.code a2 clos) + ... + closN-1 (app closN-2.code aN-1 closN-2)) + (app closN-1.code aN closN-1)))) +*) + +let apply_function_body arity = + let arg = Array.create arity (Ident.create "arg") in + for i = 1 to arity - 1 do arg.(i) <- Ident.create "arg" done; + let clos = Ident.create "clos" in + let rec app_fun clos n = + if n = arity-1 then + Cop(Capply(typ_addr, Debuginfo.none), + [get_field (Cvar clos) 0; Cvar arg.(n); Cvar clos]) + else begin + let newclos = Ident.create "clos" in + Clet(newclos, + Cop(Capply(typ_addr, Debuginfo.none), + [get_field (Cvar clos) 0; Cvar arg.(n); Cvar clos]), + app_fun newclos (n+1)) + end in + let args = Array.to_list arg in + let all_args = args @ [clos] in + (args, clos, + if arity = 1 then app_fun clos 0 else + Cifthenelse( + Cop(Ccmpi Ceq, [get_field (Cvar clos) 1; int_const arity]), + Cop(Capply(typ_addr, Debuginfo.none), + get_field (Cvar clos) 2 :: List.map (fun s -> Cvar s) all_args), + app_fun clos 0)) + +let send_function arity = + let (args, clos', body) = apply_function_body (1+arity) in + let cache = Ident.create "cache" + and obj = List.hd args + and tag = Ident.create "tag" in + let clos = + let cache = Cvar cache and obj = Cvar obj and tag = Cvar tag in + let meths = Ident.create "meths" and cached = Ident.create "cached" in + let real = Ident.create "real" in + let mask = get_field (Cvar meths) 1 in + let cached_pos = Cvar cached in + let tag_pos = Cop(Cadda, [Cop (Cadda, [cached_pos; Cvar meths]); + Cconst_int(3*size_addr-1)]) in + let tag' = Cop(Cload Word, [tag_pos]) in + Clet ( + meths, Cop(Cload Word, [obj]), + Clet ( + cached, Cop(Cand, [Cop(Cload Word, [cache]); mask]), + Clet ( + real, + Cifthenelse(Cop(Ccmpa Cne, [tag'; tag]), + cache_public_method (Cvar meths) tag cache, + cached_pos), + Cop(Cload Word, [Cop(Cadda, [Cop (Cadda, [Cvar real; Cvar meths]); + Cconst_int(2*size_addr-1)])])))) + + in + let body = Clet(clos', clos, body) in + let fun_args = + [obj, typ_addr; tag, typ_int; cache, typ_addr] + @ List.map (fun id -> (id, typ_addr)) (List.tl args) in + Cfunction + {fun_name = "caml_send" ^ string_of_int arity; + fun_args = fun_args; + fun_body = body; + fun_fast = true} + +let apply_function arity = + let (args, clos, body) = apply_function_body arity in + let all_args = args @ [clos] in + Cfunction + {fun_name = "caml_apply" ^ string_of_int arity; + fun_args = List.map (fun id -> (id, typ_addr)) all_args; + fun_body = body; + fun_fast = true} + +(* Generate tuplifying functions: + (defun caml_tuplifyN (arg clos) + (app clos.direct #0(arg) ... #N-1(arg) clos)) *) + +let tuplify_function arity = + let arg = Ident.create "arg" in + let clos = Ident.create "clos" in + let rec access_components i = + if i >= arity + then [] + else get_field (Cvar arg) i :: access_components(i+1) in + Cfunction + {fun_name = "caml_tuplify" ^ string_of_int arity; + fun_args = [arg, typ_addr; clos, typ_addr]; + fun_body = + Cop(Capply(typ_addr, Debuginfo.none), + get_field (Cvar clos) 2 :: access_components 0 @ [Cvar clos]); + fun_fast = true} + +(* Generate currying functions: + (defun caml_curryN (arg clos) + (alloc HDR caml_curryN_1 arg clos)) + (defun caml_curryN_1 (arg clos) + (alloc HDR caml_curryN_2 arg clos)) + ... + (defun caml_curryN_N-1 (arg clos) + (let (closN-2 clos.cdr + closN-3 closN-2.cdr + ... + clos1 clos2.cdr + clos clos1.cdr) + (app clos.direct + clos1.car clos2.car ... closN-2.car clos.car arg clos))) *) + +let final_curry_function arity = + let last_arg = Ident.create "arg" in + let last_clos = Ident.create "clos" in + let rec curry_fun args clos n = + if n = 0 then + Cop(Capply(typ_addr, Debuginfo.none), + get_field (Cvar clos) 2 :: + args @ [Cvar last_arg; Cvar clos]) + else begin + let newclos = Ident.create "clos" in + Clet(newclos, + get_field (Cvar clos) 3, + curry_fun (get_field (Cvar clos) 2 :: args) newclos (n-1)) + end in + Cfunction + {fun_name = "caml_curry" ^ string_of_int arity ^ + "_" ^ string_of_int (arity-1); + fun_args = [last_arg, typ_addr; last_clos, typ_addr]; + fun_body = curry_fun [] last_clos (arity-1); + fun_fast = true} + +let rec intermediate_curry_functions arity num = + if num = arity - 1 then + [final_curry_function arity] + else begin + let name1 = "caml_curry" ^ string_of_int arity in + let name2 = if num = 0 then name1 else name1 ^ "_" ^ string_of_int num in + let arg = Ident.create "arg" and clos = Ident.create "clos" in + Cfunction + {fun_name = name2; + fun_args = [arg, typ_addr; clos, typ_addr]; + fun_body = Cop(Calloc, + [alloc_closure_header 4; + Cconst_symbol(name1 ^ "_" ^ string_of_int (num+1)); + int_const 1; Cvar arg; Cvar clos]); + fun_fast = true} + :: intermediate_curry_functions arity (num+1) + end + +let curry_function arity = + if arity >= 0 + then intermediate_curry_functions arity 0 + else [tuplify_function (-arity)] + + +module IntSet = Set.Make( + struct + type t = int + let compare = compare + end) + +let default_apply = IntSet.add 2 (IntSet.add 3 IntSet.empty) + (* These apply funs are always present in the main program. + TODO: add more, and do the same for send and curry funs + (maybe up to 10-15?). *) + +let generic_functions shared units = + let (apply,send,curry) = + List.fold_left + (fun (apply,send,curry) ui -> + List.fold_right IntSet.add ui.Compilenv.ui_apply_fun apply, + List.fold_right IntSet.add ui.Compilenv.ui_send_fun send, + List.fold_right IntSet.add ui.Compilenv.ui_curry_fun curry) + (IntSet.empty,IntSet.empty,IntSet.empty) + units + in + let apply = + if shared then IntSet.diff apply default_apply + else IntSet.union apply default_apply + in + let accu = IntSet.fold (fun n accu -> apply_function n :: accu) apply [] in + let accu = IntSet.fold (fun n accu -> send_function n :: accu) send accu in + IntSet.fold (fun n accu -> curry_function n @ accu) curry accu + +(* Generate the entry point *) + +let entry_point namelist = + let incr_global_inited = + Cop(Cstore Word, + [Cconst_symbol "caml_globals_inited"; + Cop(Caddi, [Cop(Cload Word, [Cconst_symbol "caml_globals_inited"]); + Cconst_int 1])]) in + let body = + List.fold_right + (fun name next -> + let entry_sym = Compilenv.make_symbol ~unitname:name (Some "entry") in + Csequence(Cop(Capply(typ_void, Debuginfo.none), + [Cconst_symbol entry_sym]), + Csequence(incr_global_inited, next))) + namelist (Cconst_int 1) in + Cfunction {fun_name = "caml_program"; + fun_args = []; + fun_body = body; + fun_fast = false} + +(* Generate the table of globals *) + +let cint_zero = Cint 0n + +let global_table namelist = + let mksym name = + Csymbol_address (Compilenv.make_symbol ~unitname:name None) + in + Cdata(Cglobal_symbol "caml_globals" :: + Cdefine_symbol "caml_globals" :: + List.map mksym namelist @ + [cint_zero]) + +let reference_symbols namelist = + let mksym name = Csymbol_address name in + Cdata(List.map mksym namelist) + +let global_data name v = + Cdata(Cglobal_symbol name :: + emit_constant name + (Const_base (Const_string (Marshal.to_string v []))) []) + +let globals_map v = global_data "caml_globals_map" v + +(* Generate the master table of frame descriptors *) + +let frame_table namelist = + let mksym name = + Csymbol_address (Compilenv.make_symbol ~unitname:name (Some "frametable")) + in + Cdata(Cglobal_symbol "caml_frametable" :: + Cdefine_symbol "caml_frametable" :: + List.map mksym namelist + @ [cint_zero]) + +(* Generate the table of module data and code segments *) + +let segment_table namelist symbol begname endname = + let addsyms name lst = + Csymbol_address (Compilenv.make_symbol ~unitname:name (Some begname)) :: + Csymbol_address (Compilenv.make_symbol ~unitname:name (Some endname)) :: + lst + in + Cdata(Cglobal_symbol symbol :: + Cdefine_symbol symbol :: + List.fold_right addsyms namelist [cint_zero]) + +let data_segment_table namelist = + segment_table namelist "caml_data_segments" "data_begin" "data_end" + +let code_segment_table namelist = + segment_table namelist "caml_code_segments" "code_begin" "code_end" + +(* Initialize a predefined exception *) + +let predef_exception name = + let bucketname = "caml_bucket_" ^ name in + let symname = "caml_exn_" ^ name in + Cdata(Cglobal_symbol symname :: + emit_constant symname (Const_block(0,[Const_base(Const_string name)])) + [ Cglobal_symbol bucketname; + Cint(block_header 0 1); + Cdefine_symbol bucketname; + Csymbol_address symname ]) + +(* Header for a plugin *) + +let mapflat f l = List.flatten (List.map f l) + +type dynunit = { + name: string; + crc: Digest.t; + imports_cmi: (string * Digest.t) list; + imports_cmx: (string * Digest.t) list; + defines: string list; +} + +type dynheader = { + magic: string; + units: dynunit list; +} + +let dyn_magic_number = "Caml2007D001" + +let plugin_header units = + let mk (ui,crc) = + { name = ui.Compilenv.ui_name; + crc = crc; + imports_cmi = ui.Compilenv.ui_imports_cmi; + imports_cmx = ui.Compilenv.ui_imports_cmx; + defines = ui.Compilenv.ui_defines + } in + global_data "caml_plugin_header" + { magic = dyn_magic_number; units = List.map mk units } diff --git a/asmcomp/cmmgen.mli b/asmcomp/cmmgen.mli new file mode 100644 index 0000000..e24f330 --- /dev/null +++ b/asmcomp/cmmgen.mli @@ -0,0 +1,32 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cmmgen.mli,v 1.16 2008-01-31 09:13:08 frisch Exp $ *) + +(* Translation from closed lambda to C-- *) + +val compunit: int -> Clambda.ulambda -> Cmm.phrase list + +val apply_function: int -> Cmm.phrase +val send_function: int -> Cmm.phrase +val curry_function: int -> Cmm.phrase list +val generic_functions: bool -> Compilenv.unit_infos list -> Cmm.phrase list +val entry_point: string list -> Cmm.phrase +val global_table: string list -> Cmm.phrase +val reference_symbols: string list -> Cmm.phrase +val globals_map: (string * Digest.t * Digest.t * string list) list -> + Cmm.phrase +val frame_table: string list -> Cmm.phrase +val data_segment_table: string list -> Cmm.phrase +val code_segment_table: string list -> Cmm.phrase +val predef_exception: string -> Cmm.phrase +val plugin_header: (Compilenv.unit_infos * Digest.t) list -> Cmm.phrase diff --git a/asmcomp/codegen.ml b/asmcomp/codegen.ml new file mode 100644 index 0000000..c2a8375 --- /dev/null +++ b/asmcomp/codegen.ml @@ -0,0 +1,101 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: codegen.ml,v 1.7 2000-04-21 08:10:29 weis Exp $ *) + +(* From C-- to assembly code *) + +open Format +open Cmm + +let dump_cmm = ref false +let dump_selection = ref false +let dump_live = ref false +let dump_spill = ref false +let dump_split = ref false +let dump_interf = ref false +let dump_prefer = ref false +let dump_regalloc = ref false +let dump_reload = ref false +let dump_linear = ref false + +let rec regalloc fd = + if !dump_live then Printmach.phase "Liveness analysis" fd; + Interf.build_graph fd; + if !dump_interf then Printmach.interferences(); + if !dump_prefer then Printmach.preferences(); + Coloring.allocate_registers(); + if !dump_regalloc then + Printmach.phase "After register allocation" fd; + let (newfd, redo_regalloc) = Reload.fundecl fd in + if !dump_reload then + Printmach.phase "After insertion of reloading code" newfd; + if redo_regalloc + then begin Reg.reinit(); Liveness.fundecl newfd; regalloc newfd end + else newfd + +let fundecl ppf fd_cmm = + if !dump_cmm then begin + fprintf ppf "*** C-- code@."; + fprintf ppf "%a@." Printcmm.fundecl fd_cmm + end; + Reg.reset(); + let fd_sel = Sequence.fundecl fd_cmm in + if !dump_selection then + Printmach.phase "After instruction selection" fd_sel; + Liveness.fundecl fd_sel; + if !dump_live then Printmach.phase "Liveness analysis" fd_sel; + let fd_spill = Spill.fundecl fd_sel in + Liveness.fundecl fd_spill; + if !dump_spill then + Printmach.phase "After spilling" fd_spill; + let fd_split = Split.fundecl fd_spill in + Liveness.fundecl fd_split; + if !dump_split then + Printmach.phase "After live range splitting" fd_split; + let fd_reload = regalloc fd_split in + let fd_linear = Linearize.fundecl fd_reload in + if !dump_linear then begin + printf "*** Linearized code@."; + Printlinear.fundecl fd_linear; print_newline() + end; + Emit.fundecl fd_linear + +let phrase = function + Cfunction fd -> fundecl fd + | Cdata dl -> Emit.data dl + +let file filename = + let ic = open_in filename in + let lb = Lexing.from_channel ic in + try + while true do + phrase(Parsecmm.phrase Lexcmm.token lb) + done + with + End_of_file -> + close_in ic + | Lexcmm.Error msg -> + close_in ic; Lexcmm.report_error lb msg + | Parsing.Parse_error -> + close_in ic; + prerr_string "Syntax error near character "; + prerr_int (Lexing.lexeme_start lb); + prerr_newline() + | Parsecmmaux.Error msg -> + close_in ic; Parsecmmaux.report_error msg + | x -> + close_in ic; raise x + + + + diff --git a/asmcomp/codegen.mli b/asmcomp/codegen.mli new file mode 100644 index 0000000..7fea965 --- /dev/null +++ b/asmcomp/codegen.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: codegen.mli,v 1.4 1999-11-17 18:56:31 xleroy Exp $ *) + +(* From C-- to assembly code *) + +val phrase: Cmm.phrase -> unit +val file: string -> unit + +val dump_cmm: bool ref +val dump_selection: bool ref +val dump_live: bool ref +val dump_spill: bool ref +val dump_split: bool ref +val dump_interf: bool ref +val dump_prefer: bool ref +val dump_regalloc: bool ref +val dump_reload: bool ref +val dump_linear: bool ref diff --git a/asmcomp/coloring.ml b/asmcomp/coloring.ml new file mode 100644 index 0000000..fc5a3cc --- /dev/null +++ b/asmcomp/coloring.ml @@ -0,0 +1,278 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: coloring.ml,v 1.13 2004-08-12 13:34:42 xleroy Exp $ *) + +(* Register allocation by coloring of the interference graph *) + +open Reg + +(* Preallocation of spilled registers in the stack. *) + +let allocate_spilled reg = + if reg.spill then begin + let cl = Proc.register_class reg in + let nslots = Proc.num_stack_slots.(cl) in + let conflict = Array.create nslots false in + List.iter + (fun r -> + match r.loc with + Stack(Local n) -> + if Proc.register_class r = cl then conflict.(n) <- true + | _ -> ()) + reg.interf; + let slot = ref 0 in + while !slot < nslots && conflict.(!slot) do incr slot done; + reg.loc <- Stack(Local !slot); + if !slot >= nslots then Proc.num_stack_slots.(cl) <- !slot + 1 + end + +(* Compute the degree (= number of neighbours of the same type) + of each register, and split them in two sets: + unconstrained (degree < number of available registers) + and constrained (degree >= number of available registers). + Spilled registers are ignored in the process. *) + +let unconstrained = ref Reg.Set.empty +let constrained = ref Reg.Set.empty + +let find_degree reg = + if reg.spill then () else begin + let cl = Proc.register_class reg in + let avail_regs = Proc.num_available_registers.(cl) in + if avail_regs = 0 then + (* Don't bother computing the degree if there are no regs + in this class *) + unconstrained := Reg.Set.add reg !unconstrained + else begin + let deg = ref 0 in + List.iter + (fun r -> if not r.spill && Proc.register_class r = cl then incr deg) + reg.interf; + reg.degree <- !deg; + if !deg >= avail_regs + then constrained := Reg.Set.add reg !constrained + else unconstrained := Reg.Set.add reg !unconstrained + end + end + +(* Remove a register from the interference graph *) + +let remove_reg reg = + reg.degree <- 0; (* 0 means r is no longer part of the graph *) + let cl = Proc.register_class reg in + List.iter + (fun r -> + if Proc.register_class r = cl && r.degree > 0 then begin + let olddeg = r.degree in + r.degree <- olddeg - 1; + if olddeg = Proc.num_available_registers.(cl) then begin + (* r was constrained and becomes unconstrained *) + constrained := Reg.Set.remove r !constrained; + unconstrained := Reg.Set.add r !unconstrained + end + end) + reg.interf + +(* Remove all registers one by one, unconstrained if possible, otherwise + constrained with lowest spill cost. Return the list of registers removed + in reverse order. + The spill cost measure is [r.spill_cost / r.degree]. + [r.spill_cost] estimates the number of accesses to this register. *) + +let rec remove_all_regs stack = + if not (Reg.Set.is_empty !unconstrained) then begin + (* Pick any unconstrained register *) + let r = Reg.Set.choose !unconstrained in + unconstrained := Reg.Set.remove r !unconstrained; + remove_all_regs (r :: stack) + end else + if not (Reg.Set.is_empty !constrained) then begin + (* Find a constrained reg with minimal cost *) + let r = ref Reg.dummy in + let min_degree = ref 0 and min_spill_cost = ref 1 in + (* initially !min_spill_cost / !min_degree is +infty *) + Reg.Set.iter + (fun r2 -> + (* if r2.spill_cost / r2.degree < !min_spill_cost / !min_degree *) + if r2.spill_cost * !min_degree < !min_spill_cost * r2.degree + then begin + r := r2; min_degree := r2.degree; min_spill_cost := r2.spill_cost + end) + !constrained; + constrained := Reg.Set.remove !r !constrained; + remove_all_regs (!r :: stack) + end else + stack (* All regs have been removed *) + +(* Iterate over all registers preferred by the given register (transitively) *) + +let iter_preferred f reg = + let rec walk r w = + if not r.visited then begin + f r w; + begin match r.prefer with + [] -> () + | p -> r.visited <- true; + List.iter (fun (r1, w1) -> walk r1 (min w w1)) p; + r.visited <- false + end + end in + reg.visited <- true; + List.iter (fun (r, w) -> walk r w) reg.prefer; + reg.visited <- false + +(* Where to start the search for a suitable register. + Used to introduce some "randomness" in the choice between registers + with equal scores. This offers more opportunities for scheduling. *) + +let start_register = Array.create Proc.num_register_classes 0 + +(* Assign a location to a register, the best we can *) + +let assign_location reg = + let cl = Proc.register_class reg in + let first_reg = Proc.first_available_register.(cl) in + let num_regs = Proc.num_available_registers.(cl) in + let last_reg = first_reg + num_regs in + let score = Array.create num_regs 0 in + let best_score = ref (-1000000) and best_reg = ref (-1) in + let start = start_register.(cl) in + if num_regs > 0 then begin + (* Favor the registers that have been assigned to pseudoregs for which + we have a preference. If these pseudoregs have not been assigned + already, avoid the registers with which they conflict. *) + iter_preferred + (fun r w -> + match r.loc with + Reg n -> if n >= first_reg && n < last_reg then + score.(n - first_reg) <- score.(n - first_reg) + w + | Unknown -> + List.iter + (fun neighbour -> + match neighbour.loc with + Reg n -> if n >= first_reg && n < last_reg then + score.(n - first_reg) <- score.(n - first_reg) - w + | _ -> ()) + r.interf + | _ -> ()) + reg; + List.iter + (fun neighbour -> + (* Prohibit the registers that have been assigned + to our neighbours *) + begin match neighbour.loc with + Reg n -> if n >= first_reg && n < last_reg then + score.(n - first_reg) <- (-1000000) + | _ -> () + end; + (* Avoid the registers that have been assigned to pseudoregs + for which our neighbours have a preference *) + iter_preferred + (fun r w -> + match r.loc with + Reg n -> if n >= first_reg && n < last_reg then + score.(n - first_reg) <- score.(n - first_reg) - (w - 1) + (* w-1 to break the symmetry when two conflicting regs + have the same preference for a third reg. *) + | _ -> ()) + neighbour) + reg.interf; + (* Pick the register with the best score *) + for n = start to num_regs - 1 do + if score.(n) > !best_score then begin + best_score := score.(n); + best_reg := n + end + done; + for n = 0 to start - 1 do + if score.(n) > !best_score then begin + best_score := score.(n); + best_reg := n + end + done + end; + (* Found a register? *) + if !best_reg >= 0 then begin + reg.loc <- Reg(first_reg + !best_reg); + if Proc.rotate_registers then + start_register.(cl) <- (if start+1 >= num_regs then 0 else start+1) + end else begin + (* Sorry, we must put the pseudoreg in a stack location *) + let nslots = Proc.num_stack_slots.(cl) in + let score = Array.create nslots 0 in + (* Compute the scores as for registers *) + List.iter + (fun (r, w) -> + match r.loc with + Stack(Local n) -> if Proc.register_class r = cl then + score.(n) <- score.(n) + w + | Unknown -> + List.iter + (fun neighbour -> + match neighbour.loc with + Stack(Local n) -> + if Proc.register_class neighbour = cl + then score.(n) <- score.(n) - w + | _ -> ()) + r.interf + | _ -> ()) + reg.prefer; + List.iter + (fun neighbour -> + begin match neighbour.loc with + Stack(Local n) -> + if Proc.register_class neighbour = cl then + score.(n) <- (-1000000) + | _ -> () + end; + List.iter + (fun (r, w) -> + match r.loc with + Stack(Local n) -> if Proc.register_class r = cl then + score.(n) <- score.(n) - w + | _ -> ()) + neighbour.prefer) + reg.interf; + (* Pick the location with the best score *) + let best_score = ref (-1000000) and best_slot = ref (-1) in + for n = 0 to nslots - 1 do + if score.(n) > !best_score then begin + best_score := score.(n); + best_slot := n + end + done; + (* Found one? *) + if !best_slot >= 0 then + reg.loc <- Stack(Local !best_slot) + else begin + (* Allocate a new stack slot *) + reg.loc <- Stack(Local nslots); + Proc.num_stack_slots.(cl) <- nslots + 1 + end + end; + (* Cancel the preferences of this register so that they don't influence + transitively the allocation of registers that prefer this reg. *) + reg.prefer <- [] + +let allocate_registers() = + (* First pass: preallocate spill registers + Second pass: compute the degrees + Third pass: determine coloring order by successive removals of regs + Fourth pass: assign registers in that order *) + for i = 0 to Proc.num_register_classes - 1 do + Proc.num_stack_slots.(i) <- 0; + start_register.(i) <- 0 + done; + List.iter allocate_spilled (Reg.all_registers()); + List.iter find_degree (Reg.all_registers()); + List.iter assign_location (remove_all_regs []) diff --git a/asmcomp/coloring.mli b/asmcomp/coloring.mli new file mode 100644 index 0000000..6bbf192 --- /dev/null +++ b/asmcomp/coloring.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: coloring.mli,v 1.4 1999-11-17 18:56:31 xleroy Exp $ *) + +(* Register allocation by coloring of the interference graph *) + +val allocate_registers: unit -> unit diff --git a/asmcomp/comballoc.ml b/asmcomp/comballoc.ml new file mode 100644 index 0000000..dfb0958 --- /dev/null +++ b/asmcomp/comballoc.ml @@ -0,0 +1,90 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: comballoc.ml,v 1.4 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Combine heap allocations occurring in the same basic block *) + +open Mach + +type allocation_state = + No_alloc (* no allocation is pending *) + | Pending_alloc of Reg.t * int (* an allocation is pending *) +(* The arguments of Pending_alloc(reg, ofs) are: + reg the register holding the result of the last allocation + ofs the alloc position in the allocated block *) + +let allocated_size = function + No_alloc -> 0 + | Pending_alloc(reg, ofs) -> ofs + +let rec combine i allocstate = + match i.desc with + Iend | Ireturn | Iexit _ | Iraise -> + (i, allocated_size allocstate) + | Iop(Ialloc sz) -> + begin match allocstate with + No_alloc -> + let (newnext, newsz) = + combine i.next (Pending_alloc(i.res.(0), sz)) in + (instr_cons (Iop(Ialloc newsz)) i.arg i.res newnext, 0) + | Pending_alloc(reg, ofs) -> + if ofs + sz < Config.max_young_wosize then begin + let (newnext, newsz) = + combine i.next (Pending_alloc(reg, ofs + sz)) in + (instr_cons (Iop(Iintop_imm(Iadd, ofs))) [| reg |] i.res newnext, + newsz) + end else begin + let (newnext, newsz) = + combine i.next (Pending_alloc(i.res.(0), sz)) in + (instr_cons (Iop(Ialloc newsz)) i.arg i.res newnext, ofs) + end + end + | Iop(Icall_ind | Icall_imm _ | Iextcall _ | + Itailcall_ind | Itailcall_imm _) -> + let newnext = combine_restart i.next in + (instr_cons_debug i.desc i.arg i.res i.dbg newnext, + allocated_size allocstate) + | Iop op -> + let (newnext, sz) = combine i.next allocstate in + (instr_cons_debug i.desc i.arg i.res i.dbg newnext, sz) + | Iifthenelse(test, ifso, ifnot) -> + let newifso = combine_restart ifso in + let newifnot = combine_restart ifnot in + let newnext = combine_restart i.next in + (instr_cons (Iifthenelse(test, newifso, newifnot)) i.arg i.res newnext, + allocated_size allocstate) + | Iswitch(table, cases) -> + let newcases = Array.map combine_restart cases in + let newnext = combine_restart i.next in + (instr_cons (Iswitch(table, newcases)) i.arg i.res newnext, + allocated_size allocstate) + | Iloop(body) -> + let newbody = combine_restart body in + (instr_cons (Iloop(newbody)) i.arg i.res i.next, + allocated_size allocstate) + | Icatch(io, body, handler) -> + let (newbody, sz) = combine body allocstate in + let newhandler = combine_restart handler in + let newnext = combine_restart i.next in + (instr_cons (Icatch(io, newbody, newhandler)) i.arg i.res newnext, sz) + | Itrywith(body, handler) -> + let (newbody, sz) = combine body allocstate in + let newhandler = combine_restart handler in + let newnext = combine_restart i.next in + (instr_cons (Itrywith(newbody, newhandler)) i.arg i.res newnext, sz) + +and combine_restart i = + let (newi, _) = combine i No_alloc in newi + +let fundecl f = + {f with fun_body = combine_restart f.fun_body} diff --git a/asmcomp/comballoc.mli b/asmcomp/comballoc.mli new file mode 100644 index 0000000..6293c90 --- /dev/null +++ b/asmcomp/comballoc.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: comballoc.mli,v 1.2 1999-11-17 18:56:32 xleroy Exp $ *) + +(* Combine heap allocations occurring in the same basic block *) + +val fundecl: Mach.fundecl -> Mach.fundecl diff --git a/asmcomp/compilenv.ml b/asmcomp/compilenv.ml new file mode 100644 index 0000000..bc309ec --- /dev/null +++ b/asmcomp/compilenv.ml @@ -0,0 +1,243 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compilenv.ml,v 1.24 2007-11-06 15:16:55 frisch Exp $ *) + +(* Compilation environments for compilation units *) + +open Config +open Misc +open Clambda + +type error = + Not_a_unit_info of string + | Corrupted_unit_info of string + | Illegal_renaming of string * string + +exception Error of error + +(* Each .o file has a matching .cmx file that provides the following infos + on the compilation unit: + - list of other units imported, with CRCs of their .cmx files + - approximation of the structure implemented + (includes descriptions of known functions: arity and direct entry + points) + - list of currying functions and application functions needed + The .cmx file contains these infos (as an externed record) plus a CRC + of these infos *) + +type unit_infos = + { mutable ui_name: string; (* Name of unit implemented *) + mutable ui_symbol: string; (* Prefix for symbols *) + mutable ui_defines: string list; (* Unit and sub-units implemented *) + mutable ui_imports_cmi: (string * Digest.t) list; (* Interfaces imported *) + mutable ui_imports_cmx: (string * Digest.t) list; (* Infos imported *) + mutable ui_approx: value_approximation; (* Approx of the structure *) + mutable ui_curry_fun: int list; (* Currying functions needed *) + mutable ui_apply_fun: int list; (* Apply functions needed *) + mutable ui_send_fun: int list; (* Send functions needed *) + mutable ui_force_link: bool } (* Always linked *) + +(* Each .a library has a matching .cmxa file that provides the following + infos on the library: *) + +type library_infos = + { lib_units: (unit_infos * Digest.t) list; (* List of unit infos w/ CRCs *) + lib_ccobjs: string list; (* C object files needed *) + lib_ccopts: string list } (* Extra opts to C compiler *) + +let global_infos_table = + (Hashtbl.create 17 : (string, unit_infos option) Hashtbl.t) + +let current_unit = + { ui_name = ""; + ui_symbol = ""; + ui_defines = []; + ui_imports_cmi = []; + ui_imports_cmx = []; + ui_approx = Value_unknown; + ui_curry_fun = []; + ui_apply_fun = []; + ui_send_fun = []; + ui_force_link = false } + +let symbolname_for_pack pack name = + match pack with + | None -> name + | Some p -> + let b = Buffer.create 64 in + for i = 0 to String.length p - 1 do + match p.[i] with + | '.' -> Buffer.add_string b "__" + | c -> Buffer.add_char b c + done; + Buffer.add_string b "__"; + Buffer.add_string b name; + Buffer.contents b + +let reset ?packname name = + Hashtbl.clear global_infos_table; + let symbol = symbolname_for_pack packname name in + current_unit.ui_name <- name; + current_unit.ui_symbol <- symbol; + current_unit.ui_defines <- [symbol]; + current_unit.ui_imports_cmi <- []; + current_unit.ui_imports_cmx <- []; + current_unit.ui_curry_fun <- []; + current_unit.ui_apply_fun <- []; + current_unit.ui_send_fun <- []; + current_unit.ui_force_link <- false + +let current_unit_infos () = + current_unit + +let current_unit_name () = + current_unit.ui_name + +let make_symbol ?(unitname = current_unit.ui_symbol) idopt = + let prefix = "caml" ^ unitname in + match idopt with + | None -> prefix + | Some id -> prefix ^ "__" ^ id + +let read_unit_info filename = + let ic = open_in_bin filename in + try + let buffer = String.create (String.length cmx_magic_number) in + really_input ic buffer 0 (String.length cmx_magic_number); + if buffer <> cmx_magic_number then begin + close_in ic; + raise(Error(Not_a_unit_info filename)) + end; + let ui = (input_value ic : unit_infos) in + let crc = Digest.input ic in + close_in ic; + (ui, crc) + with End_of_file | Failure _ -> + close_in ic; + raise(Error(Corrupted_unit_info(filename))) + +let read_library_info filename = + let ic = open_in_bin filename in + let buffer = String.create (String.length cmxa_magic_number) in + really_input ic buffer 0 (String.length cmxa_magic_number); + if buffer <> cmxa_magic_number then + raise(Error(Not_a_unit_info filename)); + let infos = (input_value ic : library_infos) in + close_in ic; + infos + + +(* Read and cache info on global identifiers *) + +let cmx_not_found_crc = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + +let get_global_info global_ident = + let modname = Ident.name global_ident in + if modname = current_unit.ui_name then + Some current_unit + else begin + try + Hashtbl.find global_infos_table modname + with Not_found -> + let (infos, crc) = + try + let filename = + find_in_path_uncap !load_path (modname ^ ".cmx") in + let (ui, crc) = read_unit_info filename in + if ui.ui_name <> modname then + raise(Error(Illegal_renaming(ui.ui_name, filename))); + (Some ui, crc) + with Not_found -> + (None, cmx_not_found_crc) in + current_unit.ui_imports_cmx <- + (modname, crc) :: current_unit.ui_imports_cmx; + Hashtbl.add global_infos_table modname infos; + infos + end + +let cache_unit_info ui = + Hashtbl.add global_infos_table ui.ui_name (Some ui) + +(* Return the approximation of a global identifier *) + +let toplevel_approx = Hashtbl.create 16 + +let record_global_approx_toplevel id = + Hashtbl.add toplevel_approx current_unit.ui_name current_unit.ui_approx + +let global_approx id = + if Ident.is_predef_exn id then Value_unknown + else try Hashtbl.find toplevel_approx (Ident.name id) + with Not_found -> + match get_global_info id with + | None -> Value_unknown + | Some ui -> ui.ui_approx + +(* Return the symbol used to refer to a global identifier *) + +let symbol_for_global id = + if Ident.is_predef_exn id then + "caml_exn_" ^ Ident.name id + else begin + match get_global_info id with + | None -> make_symbol ~unitname:(Ident.name id) None + | Some ui -> make_symbol ~unitname:ui.ui_symbol None + end + +(* Register the approximation of the module being compiled *) + +let set_global_approx approx = + current_unit.ui_approx <- approx + +(* Record that a currying function or application function is needed *) + +let need_curry_fun n = + if not (List.mem n current_unit.ui_curry_fun) then + current_unit.ui_curry_fun <- n :: current_unit.ui_curry_fun + +let need_apply_fun n = + if not (List.mem n current_unit.ui_apply_fun) then + current_unit.ui_apply_fun <- n :: current_unit.ui_apply_fun + +let need_send_fun n = + if not (List.mem n current_unit.ui_send_fun) then + current_unit.ui_send_fun <- n :: current_unit.ui_send_fun + +(* Write the description of the current unit *) + +let write_unit_info info filename = + let oc = open_out_bin filename in + output_string oc cmx_magic_number; + output_value oc info; + flush oc; + let crc = Digest.file filename in + Digest.output oc crc; + close_out oc + +let save_unit_info filename = + current_unit.ui_imports_cmi <- Env.imported_units(); + write_unit_info current_unit filename + +(* Error report *) + +open Format + +let report_error ppf = function + | Not_a_unit_info filename -> + fprintf ppf "%s@ is not a compilation unit description." filename + | Corrupted_unit_info filename -> + fprintf ppf "Corrupted compilation unit description@ %s" filename + | Illegal_renaming(modname, filename) -> + fprintf ppf "%s@ contains the description for unit@ %s" filename modname + diff --git a/asmcomp/compilenv.mli b/asmcomp/compilenv.mli new file mode 100644 index 0000000..3afe97d --- /dev/null +++ b/asmcomp/compilenv.mli @@ -0,0 +1,110 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compilenv.mli,v 1.17 2007-11-06 15:16:55 frisch Exp $ *) + +(* Compilation environments for compilation units *) + +open Clambda + +(* Each .o file has a matching .cmx file that provides the following infos + on the compilation unit: + - list of other units imported, with CRCs of their .cmx files + - approximation of the structure implemented + (includes descriptions of known functions: arity and direct entry + points) + - list of currying functions and application functions needed + The .cmx file contains these infos (as an externed record) plus a CRC + of these infos *) + +type unit_infos = + { mutable ui_name: string; (* Name of unit implemented *) + mutable ui_symbol: string; (* Prefix for symbols *) + mutable ui_defines: string list; (* Unit and sub-units implemented *) + mutable ui_imports_cmi: (string * Digest.t) list; (* Interfaces imported *) + mutable ui_imports_cmx: (string * Digest.t) list; (* Infos imported *) + mutable ui_approx: value_approximation; (* Approx of the structure *) + mutable ui_curry_fun: int list; (* Currying functions needed *) + mutable ui_apply_fun: int list; (* Apply functions needed *) + mutable ui_send_fun: int list; (* Send functions needed *) + mutable ui_force_link: bool } (* Always linked *) + +(* Each .a library has a matching .cmxa file that provides the following + infos on the library: *) + +type library_infos = + { lib_units: (unit_infos * Digest.t) list; (* List of unit infos w/ CRCs *) + lib_ccobjs: string list; (* C object files needed *) + lib_ccopts: string list } (* Extra opts to C compiler *) + +val reset: ?packname:string -> string -> unit + (* Reset the environment and record the name of the unit being + compiled (arg). Optional argument is [-for-pack] prefix. *) + +val current_unit_infos: unit -> unit_infos + (* Return the infos for the unit being compiled *) + +val current_unit_name: unit -> string + (* Return the name of the unit being compiled *) + +val make_symbol: ?unitname:string -> string option -> string + (* [make_symbol ~unitname:u None] returns the asm symbol that + corresponds to the compilation unit [u] (default: the current unit). + [make_symbol ~unitname:u (Some id)] returns the asm symbol that + corresponds to symbol [id] in the compilation unit [u] + (or the current unit). *) + +val symbol_for_global: Ident.t -> string + (* Return the asm symbol that refers to the given global identifier *) + +val global_approx: Ident.t -> Clambda.value_approximation + (* Return the approximation for the given global identifier *) +val set_global_approx: Clambda.value_approximation -> unit + (* Record the approximation of the unit being compiled *) +val record_global_approx_toplevel: unit -> unit + (* Record the current approximation for the current toplevel phrase *) + + +val need_curry_fun: int -> unit +val need_apply_fun: int -> unit +val need_send_fun: int -> unit + (* Record the need of a currying (resp. application, + message sending) function with the given arity *) + + +val read_unit_info: string -> unit_infos * Digest.t + (* Read infos and CRC from a [.cmx] file. *) +val write_unit_info: unit_infos -> string -> unit + (* Save the given infos in the given file *) +val save_unit_info: string -> unit + (* Save the infos for the current unit in the given file *) +val cache_unit_info: unit_infos -> unit + (* Enter the given infos in the cache. The infos will be + honored by [symbol_for_global] and [global_approx] + without looking at the corresponding .cmx file. *) + +val cmx_not_found_crc: Digest.t + (* Special digest used in the [ui_imports_cmx] list to signal + that no [.cmx] file was found and used for the imported unit *) + +val read_library_info: string -> library_infos + +type error = + Not_a_unit_info of string + | Corrupted_unit_info of string + | Illegal_renaming of string * string + +exception Error of error + +val report_error: Format.formatter -> error -> unit + + diff --git a/asmcomp/debuginfo.ml b/asmcomp/debuginfo.ml new file mode 100644 index 0000000..8439044 --- /dev/null +++ b/asmcomp/debuginfo.ml @@ -0,0 +1,52 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Gallium, INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +open Lexing +open Location + +type kind = Dinfo_call | Dinfo_raise + +type t = { + dinfo_kind: kind; + dinfo_file: string; + dinfo_line: int; + dinfo_char_start: int; + dinfo_char_end: int +} + +let none = { + dinfo_kind = Dinfo_call; + dinfo_file = ""; + dinfo_line = 0; + dinfo_char_start = 0; + dinfo_char_end = 0 +} + +let to_string d = + if d == none + then "" + else Printf.sprintf "{%s:%d,%d-%d}" + d.dinfo_file d.dinfo_line d.dinfo_char_start d.dinfo_char_end + +let from_location kind loc = + if loc.loc_ghost then none else + { dinfo_kind = kind; + dinfo_file = loc.loc_start.pos_fname; + dinfo_line = loc.loc_start.pos_lnum; + dinfo_char_start = loc.loc_start.pos_cnum - loc.loc_start.pos_bol; + dinfo_char_end = + if loc.loc_end.pos_fname = loc.loc_start.pos_fname + then loc.loc_end.pos_cnum - loc.loc_start.pos_bol + else loc.loc_start.pos_cnum - loc.loc_start.pos_bol } + +let from_call ev = from_location Dinfo_call ev.Lambda.lev_loc +let from_raise ev = from_location Dinfo_raise ev.Lambda.lev_loc diff --git a/asmcomp/debuginfo.mli b/asmcomp/debuginfo.mli new file mode 100644 index 0000000..151cd0a --- /dev/null +++ b/asmcomp/debuginfo.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Gallium, INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +type kind = Dinfo_call | Dinfo_raise + +type t = { + dinfo_kind: kind; + dinfo_file: string; + dinfo_line: int; + dinfo_char_start: int; + dinfo_char_end: int +} + +val none: t + +val to_string: t -> string + +val from_location: kind -> Location.t -> t + +val from_call: Lambda.lambda_event -> t +val from_raise: Lambda.lambda_event -> t + diff --git a/asmcomp/emit.mli b/asmcomp/emit.mli new file mode 100644 index 0000000..6e89e7e --- /dev/null +++ b/asmcomp/emit.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mli,v 1.5 1999-11-17 18:56:32 xleroy Exp $ *) + +(* Generation of assembly code *) + +val fundecl: Linearize.fundecl -> unit +val data: Cmm.data_item list -> unit +val begin_assembly: unit -> unit +val end_assembly: unit -> unit diff --git a/asmcomp/emitaux.ml b/asmcomp/emitaux.ml new file mode 100644 index 0000000..9ab6a89 --- /dev/null +++ b/asmcomp/emitaux.ml @@ -0,0 +1,158 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emitaux.ml,v 1.12 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Common functions for emitting assembly code *) + +open Debuginfo +open Cmm +open Reg +open Linearize + +let output_channel = ref stdout + +let emit_string s = output_string !output_channel s + +let emit_int n = output_string !output_channel (string_of_int n) + +let emit_char c = output_char !output_channel c + +let emit_nativeint n = output_string !output_channel (Nativeint.to_string n) + +let emit_printf fmt = + Printf.fprintf !output_channel fmt + +let emit_int32 n = emit_printf "0x%lx" n + +let emit_symbol esc s = + for i = 0 to String.length s - 1 do + let c = s.[i] in + match c with + 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' -> + output_char !output_channel c + | _ -> + Printf.fprintf !output_channel "%c%02x" esc (Char.code c) + done + +let emit_string_literal s = + let last_was_escape = ref false in + emit_string "\""; + for i = 0 to String.length s - 1 do + let c = s.[i] in + if c >= '0' && c <= '9' then + if !last_was_escape + then Printf.fprintf !output_channel "\\%o" (Char.code c) + else output_char !output_channel c + else if c >= ' ' && c <= '~' && c <> '"' (* '"' *) && c <> '\\' then begin + output_char !output_channel c; + last_was_escape := false + end else begin + Printf.fprintf !output_channel "\\%o" (Char.code c); + last_was_escape := true + end + done; + emit_string "\"" + +let emit_string_directive directive s = + let l = String.length s in + if l = 0 then () + else if l < 80 then begin + emit_string directive; + emit_string_literal s; + emit_char '\n' + end else begin + let i = ref 0 in + while !i < l do + let n = min (l - !i) 80 in + emit_string directive; + emit_string_literal (String.sub s !i n); + emit_char '\n'; + i := !i + n + done + end + +let emit_bytes_directive directive s = + let pos = ref 0 in + for i = 0 to String.length s - 1 do + if !pos = 0 + then emit_string directive + else emit_char ','; + emit_int(Char.code s.[i]); + incr pos; + if !pos >= 16 then begin emit_char '\n'; pos := 0 end + done; + if !pos > 0 then emit_char '\n' + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list; (* Offsets/regs of live addresses *) + fd_debuginfo: Debuginfo.t } (* Location, if any *) + +let frame_descriptors = ref([] : frame_descr list) + +type emit_frame_actions = + { efa_label: int -> unit; + efa_16: int -> unit; + efa_32: int32 -> unit; + efa_word: int -> unit; + efa_align: int -> unit; + efa_label_rel: int -> int32 -> unit; + efa_def_label: int -> unit; + efa_string: string -> unit } + +let emit_frames a = + let filenames = Hashtbl.create 7 in + let lbl_filenames = ref 200000 in + let label_filename name = + try + Hashtbl.find filenames name + with Not_found -> + let lbl = !lbl_filenames in + Hashtbl.add filenames name lbl; + incr lbl_filenames; + lbl in + let emit_frame fd = + a.efa_label fd.fd_lbl; + a.efa_16 (if fd.fd_debuginfo == Debuginfo.none + then fd.fd_frame_size + else fd.fd_frame_size + 1); + a.efa_16 (List.length fd.fd_live_offset); + List.iter a.efa_16 fd.fd_live_offset; + a.efa_align Arch.size_addr; + if fd.fd_debuginfo != Debuginfo.none then begin + let d = fd.fd_debuginfo in + let line = min 0xFFFFF d.dinfo_line + and char_start = min 0xFF d.dinfo_char_start + and char_end = min 0x3FF d.dinfo_char_end + and kind = match d.dinfo_kind with Dinfo_call -> 0 | Dinfo_raise -> 1 in + let info = + Int64.add (Int64.shift_left (Int64.of_int line) 44) ( + Int64.add (Int64.shift_left (Int64.of_int char_start) 36) ( + Int64.add (Int64.shift_left (Int64.of_int char_end) 26) + (Int64.of_int kind))) in + a.efa_label_rel + (label_filename d.dinfo_file) + (Int64.to_int32 info); + a.efa_32 (Int64.to_int32 (Int64.shift_right info 32)) + end in + let emit_filename name lbl = + a.efa_def_label lbl; + a.efa_string name; + a.efa_align Arch.size_addr in + a.efa_word (List.length !frame_descriptors); + List.iter emit_frame !frame_descriptors; + Hashtbl.iter emit_filename filenames; + frame_descriptors := [] diff --git a/asmcomp/emitaux.mli b/asmcomp/emitaux.mli new file mode 100644 index 0000000..e1aaee3 --- /dev/null +++ b/asmcomp/emitaux.mli @@ -0,0 +1,47 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emitaux.mli,v 1.12 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Common functions for emitting assembly code *) + +val output_channel: out_channel ref +val emit_string: string -> unit +val emit_int: int -> unit +val emit_nativeint: nativeint -> unit +val emit_int32: int32 -> unit +val emit_symbol: char -> string -> unit +val emit_printf: ('a, out_channel, unit) format -> 'a +val emit_char: char -> unit +val emit_string_literal: string -> unit +val emit_string_directive: string -> string -> unit +val emit_bytes_directive: string -> string -> unit + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list; (* Offsets/regs of live addresses *) + fd_debuginfo: Debuginfo.t } (* Location, if any *) + +val frame_descriptors : frame_descr list ref + +type emit_frame_actions = + { efa_label: int -> unit; + efa_16: int -> unit; + efa_32: int32 -> unit; + efa_word: int -> unit; + efa_align: int -> unit; + efa_label_rel: int -> int32 -> unit; + efa_def_label: int -> unit; + efa_string: string -> unit } + +val emit_frames: emit_frame_actions -> unit diff --git a/asmcomp/hppa/arch.ml b/asmcomp/hppa/arch.ml new file mode 100644 index 0000000..52095fa --- /dev/null +++ b/asmcomp/hppa/arch.ml @@ -0,0 +1,74 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.7 2002-11-29 15:03:36 xleroy Exp $ *) + +(* Specific operations for the HP PA-RISC processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Specific operations *) + +type specific_operation = + Ishift1add + | Ishift2add + | Ishift3add + +(* Addressing modes *) + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + +(* Sizes, endianness *) + +let big_endian = true + +let size_addr = 4 +let size_int = 4 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "\"%s\"%s" s idx + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + +let print_specific_operation printreg op ppf arg = + match op with + | Ishift1add -> fprintf ppf "%a << 1 + %a" printreg arg.(0) printreg arg.(1) + | Ishift2add -> fprintf ppf "%a << 2 + %a" printreg arg.(0) printreg arg.(1) + | Ishift3add -> fprintf ppf "%a << 3 + %a" printreg arg.(0) printreg arg.(1) + diff --git a/asmcomp/hppa/emit.mlp b/asmcomp/hppa/emit.mlp new file mode 100644 index 0000000..9a11b39 --- /dev/null +++ b/asmcomp/hppa/emit.mlp @@ -0,0 +1,1040 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.20 2006-04-16 23:28:14 doligez Exp $ *) + +(* Emission of HP PA-RISC assembly code *) + +(* Must come before open Reg... *) +module StringSet = + Set.Make(struct + type t = string + let compare = compare + end) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Layout of the stack *) +(* Always keep the stack 8-aligned. *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + + (if !contains_calls then 4 else 0) in + Misc.align size 8 + +let slot_offset loc cl = + match loc with + Incoming n -> -frame_size() - n + | Local n -> + if cl = 0 + then - !stack_offset - num_stack_slots.(1) * 8 - n * 4 - 4 + else - !stack_offset - n * 8 - 8 + | Outgoing n -> -n + +(* Output a label *) + +let emit_label lbl = + emit_string "L$"; emit_int lbl + +(* Output a symbol *) + +let emit_symbol s = + Emitaux.emit_symbol '$' s + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> assert false + +(* Output low address / high address prefixes *) + +let low_prefix = "RR%" +let high_prefix = "LR%" + +let is_immediate n = (n < 16) && (n >= -16) (* 5 bits *) + +let emit_int_low n = emit_string low_prefix; emit_int n +let emit_int_high n = emit_string high_prefix; emit_int n + +let emit_nativeint_low n = emit_string low_prefix; emit_nativeint n +let emit_nativeint_high n = emit_string high_prefix; emit_nativeint n + +let emit_symbol_low s = + `RR%{emit_symbol s}-$global$` + +let load_symbol_high s = + ` addil LR%{emit_symbol s}-$global$, %r27\n` + +let load_symbol_offset_high s ofs = + ` addil LR%{emit_symbol s}-$global$+{emit_int ofs}, %r27\n` + +(* Record imported and defined symbols *) + +let used_symbols = ref StringSet.empty +let defined_symbols = ref StringSet.empty +let called_symbols = ref StringSet.empty + +let use_symbol s = + used_symbols := StringSet.add s !used_symbols +let define_symbol s = + defined_symbols := StringSet.add s !defined_symbols +let call_symbol s = + used_symbols := StringSet.add s !used_symbols; + called_symbols := StringSet.add s !called_symbols + +(* An external symbol is code if either it is branched to, or + it is one of the caml_apply* caml_curry* caml_tuplify* special functions. *) + +let code_imports = ["caml_apply"; "caml_curry"; "caml_tuplify"] + +let match_prefix s pref = + String.length s >= String.length pref + && String.sub s 0 (String.length pref) = pref + +let emit_import s = + if not(StringSet.mem s !defined_symbols) then begin + ` .import {emit_symbol s}`; + if StringSet.mem s !called_symbols + || List.exists (match_prefix s) code_imports + then `, code\n` + else `, data\n` + end + +let emit_imports () = + StringSet.iter emit_import !used_symbols; + used_symbols := StringSet.empty; + defined_symbols := StringSet.empty; + called_symbols := StringSet.empty + +(* Output an integer load / store *) + +let is_offset n = (n < 8192) && (n >= -8192) (* 14 bits *) + +let is_offset_native n = + n < Nativeint.of_int 8192 && n >= Nativeint.of_int (-8192) + +let emit_load instr addr arg dst = + match addr with + Ibased(s, 0) -> + use_symbol s; + load_symbol_high s; + ` {emit_string instr} {emit_symbol_low s}(%r1), {emit_reg dst}\n` + | Ibased(s, ofs) -> + use_symbol s; + load_symbol_offset_high s ofs; + ` {emit_string instr} {emit_symbol_low s}+{emit_int ofs}(%r1), {emit_reg dst}\n` + | Iindexed ofs -> + if is_offset ofs then + ` {emit_string instr} {emit_int ofs}({emit_reg arg.(0)}), {emit_reg dst}\n` + else begin + ` addil {emit_int_high ofs}, {emit_reg arg.(0)}\n`; + ` {emit_string instr} {emit_int_low ofs}(%r1), {emit_reg dst}\n` + end + +let emit_store instr addr arg src = + match addr with + Ibased(s, 0) -> + use_symbol s; + load_symbol_high s; + ` {emit_string instr} {emit_reg src}, {emit_symbol_low s}(%r1)\n` + | Ibased(s, ofs) -> + use_symbol s; + load_symbol_offset_high s ofs; + ` {emit_string instr} {emit_reg src}, {emit_symbol_low s}+{emit_int ofs}(%r1)\n` + | Iindexed ofs -> + if is_offset ofs then + ` {emit_string instr} {emit_reg src}, {emit_int ofs}({emit_reg arg.(1)})\n` + else begin + ` addil {emit_int_high ofs}, {emit_reg arg.(0)}\n`; + ` {emit_string instr} {emit_reg src}, {emit_int_low ofs}(%r1)\n` + end + +(* Output a floating-point load / store *) + +let emit_float_load addr arg dst doubleword = + match addr with + Ibased(s, 0) -> + use_symbol s; + load_symbol_high s; + ` ldo {emit_symbol_low s}(%r1), %r1\n`; + ` fldws 0(%r1), {emit_reg dst}L\n`; + if doubleword then + ` fldws 4(%r1), {emit_reg dst}R\n` + | Ibased(s, ofs) -> + use_symbol s; + load_symbol_offset_high s ofs; + ` ldo {emit_symbol_low s}+{emit_int ofs}(%r1), %r1\n`; + ` fldws 0(%r1), {emit_reg dst}L\n`; + if doubleword then + ` fldws 4(%r1), {emit_reg dst}R\n` + | Iindexed ofs -> + if is_immediate ofs && (is_immediate (ofs+4) || not doubleword) + then begin + ` fldws {emit_int ofs}({emit_reg arg.(0)}), {emit_reg dst}L\n`; + if doubleword then + ` fldws {emit_int (ofs+4)}({emit_reg arg.(0)}), {emit_reg dst}R\n` + end else begin + if is_offset ofs then + ` ldo {emit_int ofs}({emit_reg arg.(0)}), %r1\n` + else begin + ` addil {emit_int_high ofs}, {emit_reg arg.(0)}\n`; + ` ldo {emit_int_low ofs}(%r1), %r1\n` + end; + ` fldws 0(%r1), {emit_reg dst}L\n`; + if doubleword then + ` fldws 4(%r1), {emit_reg dst}R\n` + end + +let emit_float_store addr arg src doubleword = + match addr with + Ibased(s, 0) -> + use_symbol s; + load_symbol_high s; + ` ldo {emit_symbol_low s}(%r1), %r1\n`; + ` fstws {emit_reg src}L, 0(%r1)\n`; + if doubleword then + ` fstws {emit_reg src}R, 4(%r1)\n` + | Ibased(s, ofs) -> + use_symbol s; + load_symbol_offset_high s ofs; + ` ldo {emit_symbol_low s}+{emit_int ofs}(%r1), %r1\n`; + ` fstws {emit_reg src}L, 0(%r1)\n`; + if doubleword then + ` fstws {emit_reg src}R, 4(%r1)\n` + | Iindexed ofs -> + if is_immediate ofs && (is_immediate (ofs+4) || not doubleword) + then begin + ` fstws {emit_reg src}L, {emit_int ofs}({emit_reg arg.(1)})\n`; + if doubleword then + ` fstws {emit_reg src}R, {emit_int(ofs+4)}({emit_reg arg.(1)})\n` + end else begin + if is_offset ofs then + ` ldo {emit_int ofs}({emit_reg arg.(1)}), %r1\n` + else begin + ` addil {emit_int_high ofs}, {emit_reg arg.(1)}\n`; + ` ldo {emit_int_low ofs}(%r1), %r1\n` + end; + ` fstws {emit_reg src}L, 0(%r1)\n`; + if doubleword then + ` fstws {emit_reg src}R, 4(%r1)\n` + end + +(* Output an align directive. *) + +let emit_align n = + ` .align {emit_int n}\n` + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + `{emit_label lbl}:\n` + +let emit_frame fd = + ` .long {emit_label fd.fd_lbl} + 3\n`; + ` .short {emit_int fd.fd_frame_size}\n`; + ` .short {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` .short {emit_int n}\n`) + fd.fd_live_offset; + emit_align 4 + +(* Record floating-point constants *) + +let float_constants = ref ([] : (int * string) list) + +let emit_float_constants () = + if Config.system = "hpux" then begin + ` .space $TEXT$\n`; + ` .subspa $LIT$\n` + end else + ` .text\n`; + emit_align 8; + List.iter + (fun (lbl, cst) -> `{emit_label lbl}: .double {emit_string cst}\n`) + !float_constants; + float_constants := [] + +(* Describe the registers used to pass arguments to a C function *) + +let describe_call arg = + ` .CALL RTNVAL=NO`; + let pos = ref 0 in + for i = 0 to Array.length arg - 1 do + if !pos < 4 then begin + match arg.(i).typ with + Float -> `, ARGW{emit_int !pos}=FR, ARGW{emit_int(!pos + 1)}=FU`; + pos := !pos + 2 + | _ -> `, ARGW{emit_int !pos}=GR`; + pos := !pos + 1 + end + done; + `\n` + +(* Output a function call *) + +let emit_call s retreg = + call_symbol s; + ` bl {emit_symbol s}, {emit_string retreg}\n` + +(* Names of various instructions *) + +let name_for_int_operation = function + Iadd -> "add" + | Isub -> "sub" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | _ -> assert false + +let name_for_float_operation = function + Iaddf -> "fadd,dbl" + | Isubf -> "fsub,dbl" + | Imulf -> "fmpy,dbl" + | Idivf -> "fdiv,dbl" + | _ -> assert false + +let name_for_specific_operation = function + Ishift1add -> "sh1add" + | Ishift2add -> "sh2add" + | Ishift3add -> "sh3add" + +let name_for_int_comparison = function + Isigned Ceq -> "=" | Isigned Cne -> "<>" + | Isigned Cle -> "<=" | Isigned Cgt -> ">" + | Isigned Clt -> "<" | Isigned Cge -> ">=" + | Iunsigned Ceq -> "=" | Iunsigned Cne -> "<>" + | Iunsigned Cle -> "<<=" | Iunsigned Cgt -> ">>" + | Iunsigned Clt -> "<<" | Iunsigned Cge -> ">>=" + +let name_for_float_comparison cmp neg = + match cmp with + Ceq -> if neg then "=" else "!=" + | Cne -> if neg then "!=" else "=" + | Cle -> if neg then "<=" else "!<=" + | Cgt -> if neg then ">" else "!>" + | Clt -> if neg then "<" else "!<" + | Cge -> if neg then ">=" else "!>=" + +let negate_int_comparison = function + Isigned cmp -> Isigned(Cmm.negate_comparison cmp) + | Iunsigned cmp -> Iunsigned(Cmm.negate_comparison cmp) + +let swap_int_comparison = function + Isigned cmp -> Isigned(Cmm.swap_comparison cmp) + | Iunsigned cmp -> Iunsigned(Cmm.swap_comparison cmp) + + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Label of trap for out-of-range accesses *) +let range_check_trap = ref 0 + +let rec emit_instr i dslot = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + begin match (src, dst) with + {loc = Reg rs; typ = (Int | Addr)}, {loc = Reg rd} -> + ` copy {emit_reg src}, {emit_reg dst}\n` + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} -> + ` fcpy,dbl {emit_reg src}, {emit_reg dst}\n` + | {loc = Reg rs; typ = (Int | Addr)}, {loc = Stack sd} -> + let ofs = slot_offset sd 0 in + ` stw {emit_reg src}, {emit_int ofs}(%r30)\n` + | {loc = Reg rs; typ = Float}, {loc = Stack sd} -> + let ofs = slot_offset sd 1 in + if is_immediate ofs then + ` fstds {emit_reg src}, {emit_int ofs}(%r30)\n` + else begin + ` ldo {emit_int ofs}(%r30), %r1\n`; + ` fstds {emit_reg src}, 0(%r1)\n` + end + | {loc = Stack ss; typ = (Int | Addr)}, {loc = Reg rd} -> + let ofs = slot_offset ss 0 in + ` ldw {emit_int ofs}(%r30), {emit_reg dst}\n` + | {loc = Stack ss; typ = Float}, {loc = Reg rd} -> + let ofs = slot_offset ss 1 in + if is_immediate ofs then + ` fldds {emit_int ofs}(%r30), {emit_reg dst}\n` + else begin + ` ldo {emit_int ofs}(%r30), %r1\n`; + ` fldds 0(%r1), {emit_reg dst}\n` + end + | (_, _) -> + assert false + end + | Lop(Iconst_int n) -> + if is_offset_native n then + ` ldi {emit_nativeint n}, {emit_reg i.res.(0)}\n` + else begin + ` ldil {emit_nativeint_high n}, {emit_reg i.res.(0)}\n`; + ` ldo {emit_nativeint_low n}({emit_reg i.res.(0)}), {emit_reg i.res.(0)}\n` + end + | Lop(Iconst_float s) -> + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` ldil {emit_string high_prefix}{emit_label lbl}, %r1\n`; + ` ldo {emit_string low_prefix}{emit_label lbl}(%r1), %r1\n`; + ` fldds 0(%r1), {emit_reg i.res.(0)}\n` + | Lop(Iconst_symbol s) -> + use_symbol s; + load_symbol_high s; + ` ldo {emit_symbol_low s}(%r1), {emit_reg i.res.(0)}\n` + | Lop(Icall_ind) -> + ` ble 0(4, {emit_reg i.arg.(0)})\n`; (* retaddr in %r31 *) + ` copy %r31, %r2\n`; (* in delay slot: save retaddr in %r2 *) + record_frame i.live + | Lop(Icall_imm s) -> + emit_call s "%r2"; + fill_delay_slot dslot; + record_frame i.live + | Lop(Itailcall_ind) -> + let n = frame_size() in + ` bv 0({emit_reg i.arg.(0)})\n`; + if !contains_calls (* in delay slot *) + then ` ldwm {emit_int(-n)}(%r30), %r2\n` + else ` ldo {emit_int(-n)}(%r30), %r30\n` + | Lop(Itailcall_imm s) -> + let n = frame_size() in + if s = !function_name then begin + ` b,n {emit_label !tailrec_entry_point}\n` + end else begin + emit_call s "%r0"; + if !contains_calls (* in delay slot *) + then ` ldwm {emit_int(-n)}(%r30), %r2\n` + else ` ldo {emit_int(-n)}(%r30), %r30\n` + end + | Lop(Iextcall(s, alloc)) -> + call_symbol s; + if alloc then begin + ` ldil LR%{emit_symbol s}, %r22\n`; + describe_call i.arg; + emit_call "caml_c_call" "%r2"; + ` ldo RR%{emit_symbol s}(%r22), %r22\n`; (* in delay slot *) + record_frame i.live + end else begin + describe_call i.arg; + emit_call s "%r2"; + fill_delay_slot dslot + end + | Lop(Istackoffset n) -> + ` ldo {emit_int n}(%r30), %r30\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + Byte_unsigned -> + emit_load "ldb" addr i.arg dest + | Byte_signed -> + emit_load "ldb" addr i.arg dest; + ` extrs {emit_reg dest}, 31, 8, {emit_reg dest}\n` + | Sixteen_unsigned -> + emit_load "ldh" addr i.arg dest + | Sixteen_signed -> + emit_load "ldh" addr i.arg dest; + ` extrs {emit_reg dest}, 31, 16, {emit_reg dest}\n` + | Single -> + emit_float_load addr i.arg dest false; + ` fcnvff,sgl,dbl {emit_reg dest}L, {emit_reg dest}\n` + | Double | Double_u -> + emit_float_load addr i.arg dest true + | _ -> + emit_load "ldw" addr i.arg dest + end + | Lop(Istore(chunk, addr)) -> + let src = i.arg.(0) in + begin match chunk with + Byte_unsigned | Byte_signed -> + emit_store "stb" addr i.arg src + | Sixteen_unsigned | Sixteen_signed -> + emit_store "sth" addr i.arg src + | Single -> + ` fcnvff,dbl,sgl {emit_reg src}, %fr31L\n`; + emit_float_store addr i.arg (phys_reg 127) (* %fr31 *) false + | Double | Double_u -> + emit_float_store addr i.arg src true + | _ -> + emit_store "stw" addr i.arg src + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_cont = new_label() in + ` ldw 0(%r4), %r1\n`; + ` ldo {emit_int (-n)}(%r3), %r3\n`; + ` comb,>>= %r3, %r1, {emit_label lbl_cont}\n`; + ` addi 4, %r3, {emit_reg i.res.(0)}\n`; (* in delay slot *) + emit_call "caml_call_gc" "%r2"; + (* Cannot use %r1 to pass size, since clobbered by glue call code *) + ` ldi {emit_int n}, %r29\n`; (* in delay slot *) + record_frame i.live; + ` addi 4, %r3, {emit_reg i.res.(0)}\n`; + `{emit_label lbl_cont}:\n` + end else begin + emit_call "caml_allocN" "%r2"; + (* Cannot use %r1 either *) + ` ldi {emit_int n}, %r29\n`; (* in delay slot *) + record_frame i.live; + ` addi 4, %r3, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop Imul) -> + ` stws,ma {emit_reg i.arg.(0)}, 8(%r30)\n`; + ` stw {emit_reg i.arg.(1)}, -4(%r30)\n`; + ` fldws -8(%r30), %fr31L\n`; + ` fldws -4(%r30), %fr31R\n`; + ` xmpyu %fr31L, %fr31R, %fr31\n`; + ` fstws %fr31R, -8(%r30)\n`; (* poor scheduling *) + ` ldws,mb -8(%r30), {emit_reg i.res.(0)}\n` + | Lop(Iintop Idiv) -> + (* Arguments are assumed to be in %r26 and %r25, result in %r29 *) + ` bl $$divI, %r31\n`; + fill_delay_slot dslot + | Lop(Iintop Imod) -> + (* Arguments are assumed to be in %r26 and %r25, result in %r29 *) + ` bl $$remI, %r31\n`; + fill_delay_slot dslot + | Lop(Iintop Ilsl) -> + ` subi 31, {emit_reg i.arg.(1)}, %r1\n`; + ` mtsar %r1\n`; + ` zvdep {emit_reg i.arg.(0)}, 32, {emit_reg i.res.(0)}\n` + | Lop(Iintop Ilsr) -> + ` mtsar {emit_reg i.arg.(1)}\n`; + ` vshd %r0, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop Iasr) -> + ` subi 31, {emit_reg i.arg.(1)}, %r1\n`; + ` mtsar %r1\n`; + ` vextrs {emit_reg i.arg.(0)}, 32, {emit_reg i.res.(0)}\n` + | Lop(Iintop(Icomp cmp)) -> + let comp = name_for_int_comparison(negate_int_comparison cmp) in + ` comclr,{emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n`; + ` ldi 1, {emit_reg i.res.(0)}\n` + | Lop(Iintop Icheckbound) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` comclr,>> {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, %r0\n`; + ` b,n {emit_label !range_check_trap}\n` + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, n)) -> + ` addi {emit_int n}, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Isub, n)) -> + ` addi {emit_int(-n)}, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + let l = Misc.log2 n in + ` comclr,>= {emit_reg i.arg.(0)}, %r0, %r1\n`; + if not (l = 0) then + ` zdepi -1, 31, {emit_int l}, %r1\n` + else + ` xor %r1, %r1, %r1\n`; + ` add {emit_reg i.arg.(0)}, %r1, %r1\n`; + ` extrs %r1, {emit_int(31-l)}, {emit_int(32-l)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Imod, n)) -> + let l = Misc.log2 n in + ` comclr,>= {emit_reg i.arg.(0)}, %r0, %r1\n`; + if not (l = 0) then + ` zdepi -1, 31, {emit_int l}, %r1\n` + else + ` xor %r1, %r1, %r1\n`; + ` add {emit_reg i.arg.(0)}, %r1, %r1\n`; + ` depi 0, 31, {emit_int l}, %r1\n`; + ` sub {emit_reg i.arg.(0)}, %r1, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Ilsl, n)) -> + let n = n land 31 in + ` zdep {emit_reg i.arg.(0)}, {emit_int(31-n)}, {emit_int(32-n)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Ilsr, n)) -> + let n = n land 31 in + ` extru {emit_reg i.arg.(0)}, {emit_int(31-n)}, {emit_int(32-n)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iasr, n)) -> + let n = n land 31 in + ` extrs {emit_reg i.arg.(0)}, {emit_int(31-n)}, {emit_int(32-n)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + let comp = name_for_int_comparison(negate_int_comparison(swap_int_comparison cmp)) in + ` comiclr,{emit_string comp} {emit_int n}, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`; + ` ldi 1, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` comiclr,<< {emit_int n}, {emit_reg i.arg.(0)}, %r0\n`; + ` b,n {emit_label !range_check_trap}\n` + | Lop(Iintop_imm(op, n)) -> + assert false + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Inegf) -> + ` fsub,dbl 0, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iabsf) -> + ` fabs,dbl {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Ifloatofint) -> + ` stws,ma {emit_reg i.arg.(0)}, 8(%r30)\n`; + ` fldws,mb -8(%r30), %fr31L\n`; + ` fcnvxf,sgl,dbl %fr31L, {emit_reg i.res.(0)}\n` + | Lop(Iintoffloat) -> + ` fcnvfxt,dbl,sgl {emit_reg i.arg.(0)}, %fr31L\n`; + ` fstws,ma %fr31L, 8(%r30)\n`; + ` ldws,mb -8(%r30), {emit_reg i.res.(0)}\n` + | Lop(Ispecific sop) -> + let instr = name_for_specific_operation sop in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lreloadretaddr -> + let n = frame_size() in + ` ldw {emit_int(-n)}(%r30), %r2\n` + | Lreturn -> + let n = frame_size() in + ` bv 0(%r2)\n`; + ` ldo {emit_int(-n)}(%r30), %r30\n` (* in delay slot *) + | Llabel lbl -> + `{emit_label lbl}:\n` + | Lbranch lbl -> + begin match dslot with + None -> + ` b,n {emit_label lbl}\n` + | Some i -> + ` b {emit_label lbl}\n`; + emit_instr i None + end + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + emit_comib "<>" "=" 0 i.arg lbl dslot + | Ifalsetest -> + emit_comib "=" "<>" 0 i.arg lbl dslot + | Iinttest cmp -> + let comp = name_for_int_comparison cmp + and negcomp = + name_for_int_comparison(negate_int_comparison cmp) in + emit_comb comp negcomp i.arg lbl dslot + | Iinttest_imm(cmp, n) -> + let scmp = swap_int_comparison cmp in + let comp = name_for_int_comparison scmp + and negcomp = + name_for_int_comparison(negate_int_comparison scmp) in + emit_comib comp negcomp n i.arg lbl dslot + | Ifloattest(cmp, neg) -> + let comp = name_for_float_comparison cmp neg in + ` fcmp,dbl,{emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` ftest\n`; + ` b {emit_label lbl}\n`; + fill_delay_slot dslot + | Ioddtest -> + emit_comib "OD" "EV" 0 i.arg lbl dslot + | Ieventest -> + emit_comib "EV" "OD" 0 i.arg lbl dslot + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + begin match lbl0 with + None -> () + | Some lbl -> emit_comib "=" "<>" 0 i.arg lbl None + end; + begin match lbl1 with + None -> () + | Some lbl -> emit_comib "=" "<>" 1 i.arg lbl None + end; + begin match lbl2 with + None -> () + | Some lbl -> emit_comib "=" "<>" 2 i.arg lbl None + end + | Lswitch jumptbl -> + ` blr {emit_reg i.arg.(0)}, 0\n`; + fill_delay_slot dslot; + for i = 0 to Array.length jumptbl - 1 do + ` b {emit_label jumptbl.(i)}\n`; + ` nop\n` + done + | Lsetuptrap lbl -> + ` bl {emit_label lbl}, %r1\n`; + fill_delay_slot dslot + | Lpushtrap -> + stack_offset := !stack_offset + 8; + ` stws,ma %r5, 8(%r30)\n`; + ` stw %r1, -4(%r30)\n`; + ` copy %r30, %r5\n` + | Lpoptrap -> + ` ldws,mb -8(%r30), %r5\n`; + stack_offset := !stack_offset - 8 + | Lraise -> + ` ldw -4(%r5), %r1\n`; + ` copy %r5, %r30\n`; + ` bv 0(%r1)\n`; + ` ldws,mb -8(%r30), %r5\n` (* in delay slot *) + +and fill_delay_slot = function + None -> ` nop\n` + | Some i -> emit_instr i None + +and emit_delay_slot = function + None -> () + | Some i -> emit_instr i None + +and emit_comb comp negcomp arg lbl dslot = + if lbl >= 0 then begin + ` comb,{emit_string comp} {emit_reg arg.(0)}, {emit_reg arg.(1)}, {emit_label lbl}\n`; + fill_delay_slot dslot + end else begin + emit_delay_slot dslot; + ` comclr,{emit_string negcomp} {emit_reg arg.(0)}, {emit_reg arg.(1)}, %r0\n`; + ` b,n {emit_label (-lbl)}\n` + end + +and emit_comib comp negcomp cst arg lbl dslot = + if lbl >= 0 then begin + ` comib,{emit_string comp} {emit_int cst}, {emit_reg arg.(0)}, {emit_label lbl}\n`; + fill_delay_slot dslot + end else begin + emit_delay_slot dslot; + ` comiclr,{emit_string negcomp} {emit_int cst}, {emit_reg arg.(0)}, %r0\n`; + ` b,n {emit_label (-lbl)}\n` + end + +(* Checks if a pseudo-instruction expands to exactly one machine instruction + that does not branch. *) + +let is_one_instr i = + match i.desc with + Lop op -> + begin match op with + Imove | Ispill | Ireload -> + begin match (i.arg.(0), i.res.(0)) with + ({typ = Float; loc = Stack s}, _) -> is_immediate(slot_offset s 1) + | (_, {typ = Float; loc = Stack s}) -> is_immediate(slot_offset s 1) + | (_, _) -> true + end + | Iconst_int n -> is_offset_native n + | Istackoffset _ -> true + | Iload(_, Iindexed n) -> i.res.(0).typ <> Float & is_offset n + | Istore(_, Iindexed n) -> i.arg.(0).typ <> Float & is_offset n + | Iintop(Iadd | Isub | Iand | Ior | Ixor) -> true + | Iintop_imm((Iadd | Isub | Ilsl | Ilsr | Iasr), _) -> true + | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf -> true + | Ispecific _ -> true + | _ -> false + end + | Lreloadretaddr -> true + | _ -> false + +let no_interference res arg = + try + for i = 0 to Array.length arg - 1 do + for j = 0 to Array.length res - 1 do + if arg.(i).loc = res.(j).loc then raise Exit + done + done; + true + with Exit -> + false + +(* Emit a sequence of instructions, trying to fill delay slots for branches *) + +let rec emit_all i = + match i with + {desc = Lend} -> () + | {next = {desc = Lop(Icall_imm _) + | Lop(Iextcall(_, false)) + | Lop(Iintop(Idiv | Imod)) + | Lbranch _ + | Lsetuptrap _ }} + when is_one_instr i -> + emit_instr i.next (Some i); + emit_all i.next.next + | {next = {desc = Lcondbranch(_, _) | Lswitch _}} + when is_one_instr i & no_interference i.res i.next.arg -> + emit_instr i.next (Some i); + emit_all i.next.next + | _ -> + emit_instr i None; + emit_all i.next + +(* Estimate the size of an instruction, in actual HPPA instructions *) + +let is_float_stack r = + match r with {loc = Stack _; typ = Float} -> true | _ -> false + +let sizeof_instr i = + match i.desc with + Lend -> 0 + | Lop op -> + begin match op with + Imove | Ispill | Ireload -> + if is_float_stack i.arg.(0) || is_float_stack i.res.(0) + then 2 (* ldo/fxxx *) else 1 + | Iconst_int n -> + if is_offset_native n then 1 else 2 (* ldi or ldil/ldo *) + | Iconst_float _ -> 3 (* ldil/ldo/fldds *) + | Iconst_symbol _ -> 2 (* addil/ldo *) + | Icall_ind -> 2 (* ble/copy *) + | Icall_imm _ -> 2 (* bl/nop *) + | Itailcall_ind -> 2 (* bv/ldwm *) + | Itailcall_imm _ -> 2 (* bl/ldwm *) + | Iextcall(_, alloc) -> + if alloc then 3 (* ldil/bl/ldo *) else 2 (* bl/nop *) + | Istackoffset _ -> 1 (* ldo *) + | Iload(chunk, addr) -> + if i.res.(0).typ = Float + then 4 (* addil/ldo/fldws/fldws *) + else (match addr with Iindexed ofs when is_offset ofs -> 1 | _ -> 2) + + (match chunk with Byte_signed -> 1 | Sixteen_signed -> 1 | _ -> 0) + | Istore(chunk, addr) -> + if i.arg.(0).typ = Float + then 4 (* addil/ldo/fstws/fstws *) + else (match addr with Iindexed ofs when is_offset ofs -> 1 | _ -> 2) + | Ialloc _ -> if !fastcode_flag then 7 else 3 + | Iintop Imul -> 7 + | Iintop(Idiv | Imod) -> 3 (* ldil/ble/nop *) + | Iintop Ilsl -> 3 (* subi/mtsar/zvdep *) + | Iintop Ilsr -> 2 (* mtsar/vshd *) + | Iintop Iasr -> 3 (* subi/mtsar/vextrs *) + | Iintop(Icomp _) -> 2 (* comclr/ldi *) + | Iintop Icheckbound -> 2 (* comclr/b,n *) + | Iintop _ -> 1 + | Iintop_imm(Idiv, _) -> 4 (* comclr/zdepi/add/extrs *) + | Iintop_imm(Imod, _) -> 5 (* comclr/zdepi/add/extrs/sub *) + | Iintop_imm(Icomp _, _) -> 2 (* comiclr/ldi *) + | Iintop_imm(Icheckbound, _) -> 2 (* comiclr/b,n *) + | Iintop_imm(_, _) -> 1 + | Ifloatofint -> 3 (* stws,ma/fldws,mb/fcnvxf *) + | Iintoffloat -> 3 (* fcnfxt/fstws/ldws *) + | _ (* Inegf|Iabsf|Iaddf|Isubf|Imulf|Idivf|Ispecific _ *) -> 1 + end + | Lreloadretaddr -> 1 + | Lreturn -> 2 + | Llabel _ -> 0 + | Lbranch _ -> 1 (* b,n *) + | Lcondbranch(Ifloattest(_, _), _) -> 4 (* fcmp/ftest/b/nop *) + | Lcondbranch(_, _) -> 2 (* comb/nop or comclr/b,n *) + | Lcondbranch3(_, _, _) -> 6 (* worst case: three comib/nop or comclr/b,n *) + | Lswitch tbl -> 2 + 2 * Array.length tbl (* blr/nop b/nop *) + | Lsetuptrap _ -> 2 (* bl/nop *) + | Lpushtrap -> 3 (* stws,ma/stw/copy *) + | Lpoptrap -> 1 (* ldws,mb *) + | Lraise -> 4 (* ldw/copy/bv/ldws,mb *) + +(* Estimate the position of all labels in function body + and rewrite long conditional branches with a negative label. *) + +let fixup_cond_branches funbody = + let label_position = + (Hashtbl.create 87 : (label, int) Hashtbl.t) in + let rec estimate_labels pos i = + match i.desc with + Lend -> () + | Llabel lbl -> + Hashtbl.add label_position lbl pos; estimate_labels pos i.next + | _ -> estimate_labels (pos + sizeof_instr i) i.next in + let long_branch currpos lbl = + try + let displ = Hashtbl.find label_position lbl - currpos in + (* Branch offset is stored in 12 bits, giving a range of + -2048 to +2047. Here, we allow 10% error in estimating + the code positions. *) + displ < -1843 || displ > 1842 + with Not_found -> + assert false in + let rec fix_branches pos i = + match i.desc with + Lend -> () + | Lcondbranch(tst, lbl) -> + if long_branch pos lbl then i.desc <- Lcondbranch(tst, -lbl); + fix_branches (pos + sizeof_instr i) i.next + | Lcondbranch3(opt1, opt2, opt3) -> + let fix_opt = function + None -> None + | Some lbl -> Some(if long_branch pos lbl then -lbl else lbl) in + i.desc <- Lcondbranch3(fix_opt opt1, fix_opt opt2, fix_opt opt3); + fix_branches (pos + sizeof_instr i) i.next + | _ -> + fix_branches (pos + sizeof_instr i) i.next in + estimate_labels 0 funbody; + fix_branches 0 funbody + +(* Emission of a function declaration *) + +let fundecl fundecl = + fixup_cond_branches fundecl.fun_body; + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + float_constants := []; + define_symbol fundecl.fun_name; + range_check_trap := 0; + let n = frame_size() in + begin match Config.system with + | "hpux" -> + ` .code\n`; + ` .align 4\n`; + ` .export {emit_symbol fundecl.fun_name}, entry, priv_lev=3\n`; + `{emit_symbol fundecl.fun_name}:\n`; + ` .proc\n`; + if !contains_calls then + ` .callinfo frame={emit_int n}, calls, save_rp\n` + else + ` .callinfo frame={emit_int n}, no_calls\n`; + ` .entry\n` + | "linux" | "gnu" -> + ` .text\n`; + ` .align 8\n`; + ` .globl {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n` + | _ -> + assert false + end; + if !contains_calls then + ` stwm %r2, {emit_int n}(%r30)\n` + else if n > 0 then + ` ldo {emit_int n}(%r30), %r30\n`; + `{emit_label !tailrec_entry_point}:\n`; + emit_all fundecl.fun_body; + if !range_check_trap > 0 then begin + `{emit_label !range_check_trap}:\n`; + emit_call "caml_ml_array_bound_error" "%r31"; + ` nop\n` + end; + if Config.system = "hpux"then begin + ` .exit\n`; + ` .procend\n` + end; + emit_float_constants() + +(* Emission of data *) + +let declare_global s = + define_symbol s; + if Config.system = "hpux" + then ` .export {emit_symbol s}, data\n` + else ` .globl {emit_symbol s}\n` + +let emit_item = function + Cglobal_symbol s -> + declare_global s + | Cdefine_symbol s -> + define_symbol s; + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (lbl + 100000)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .short {emit_int n}\n` + | Cint32 n -> + ` .long {emit_nativeint n}\n` + | Cint n -> + ` .long {emit_nativeint n}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .double {emit_string f}\n` + | Csymbol_address s -> + use_symbol s; + ` .long {emit_symbol s}\n` + | Clabel_address lbl -> + ` .long {emit_label(lbl + 100000)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then + if Config.system = "hpux" + then ` .block {emit_int n}\n` + else ` .space {emit_int n}\n` + | Calign n -> + emit_align n + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + if Config.system = "hpux" then begin + ` .space $PRIVATE$\n`; + ` .subspa $DATA$,quad=1,align=8,access=31\n`; + ` .subspa $BSS$,quad=1,align=8,access=31,zero,sort=82\n`; + ` .space $TEXT$\n`; + ` .subspa $LIT$,quad=0,align=8,access=44\n`; + ` .subspa $CODE$,quad=0,align=8,access=44,code_only\n`; + ` .import $global$, data\n`; + ` .import $$divI, millicode\n`; + ` .import $$remI, millicode\n` + end; + used_symbols := StringSet.empty; + defined_symbols := StringSet.empty; + called_symbols := StringSet.empty; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + declare_global lbl_begin; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .code\n`; + declare_global lbl_begin; + `{emit_symbol lbl_begin}:\n` + + +let end_assembly() = + ` .code\n`; + let lbl_end = Compilenv.make_symbol (Some "code_end") in + declare_global lbl_end; + `{emit_symbol lbl_end}:\n`; + ` .data\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + declare_global lbl_end; + `{emit_symbol lbl_end}:\n`; + ` .long 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + declare_global lbl; + `{emit_symbol lbl}:\n`; + ` .long {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + frame_descriptors := []; + emit_imports() diff --git a/asmcomp/hppa/proc.ml b/asmcomp/hppa/proc.ml new file mode 100644 index 0000000..d66e4fe --- /dev/null +++ b/asmcomp/hppa/proc.ml @@ -0,0 +1,224 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.8 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the HP PA-RISC processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Registers available for register allocation *) + +(* Register map: + %r0 always zero + %r1 temporary, target of ADDIL + %r2 return address + %r3 allocation pointer + %r4 allocation limit + %r5 trap pointer + %r6 - %r26 general purpose + %r27 global pointer + %r28 - %r29 general purpose, C function results + %r30 stack pointer + %r31 temporary, used by BLE + + %fr0 - %fr3 float status info + %fr4 - %fr30 general purpose + %fr31 temporary *) + +let int_reg_name = [| + (* 0-4 *) "%r6"; "%r7"; "%r8"; "%r9"; "%r10"; + (* 5-10 *) "%r11"; "%r12"; "%r13"; "%r14"; "%r15"; "%r16"; + (* 11-16 *) "%r17"; "%r18"; "%r19"; "%r20"; "%r21"; "%r22"; + (* 17-20 *) "%r23"; "%r24"; "%r25"; "%r26"; + (* 21-22 *) "%r28"; "%r29" +|] + +let float_reg_name = [| + (* 100-105 *) "%fr4"; "%fr5"; "%fr6"; "%fr7"; "%fr8"; "%fr9"; + (* 106-111 *) "%fr10"; "%fr11"; "%fr12"; "%fr13"; "%fr14"; "%fr15"; + (* 112-117 *) "%fr16"; "%fr17"; "%fr18"; "%fr19"; "%fr20"; "%fr21"; + (* 118-123 *) "%fr22"; "%fr23"; "%fr24"; "%fr25"; "%fr26"; "%fr27"; + (* 124-127 *) "%fr28"; "%fr29"; "%fr30"; "%fr31" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 23; 27 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 23 Reg.dummy in + for i = 0 to 22 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 28 Reg.dummy in + for i = 0 to 27 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg (Array.sub hard_float_reg 0 27) + (* No need to include the left/right parts of float registers *) + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Instruction selection *) + +let word_addressed = false + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int >= last_int then begin + loc.(i) <- phys_reg !int; + decr int + end else begin + ofs := !ofs + size_int; + loc.(i) <- stack_slot (make_stack !ofs) ty + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + ofs := Misc.align (!ofs + size_float) 8; + loc.(i) <- stack_slot (make_stack !ofs) Float + end + done; + (loc, Misc.align !ofs 8) (* Keep stack 8-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +(* Arguments and results: %r26-%r19, %fr4-%fr11. *) + +let loc_arguments arg = + calling_conventions 20 13 100 107 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 20 13 100 107 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 20 13 100 107 not_supported res in loc + +(* Calling C functions: + when all arguments are integers, use %r26 - %r23, + then -52(%r30), -56(%r30), etc. + When some arguments are floats, we handle a couple of cases by hand + and fail otherwise. *) + +let loc_external_arguments arg = + match List.map register_class (Array.to_list arg) with + [1] -> ([| phys_reg 101 |], 56) (* %fr5 *) + | [1; 1] -> ([| phys_reg 101; phys_reg 103 |], 56) (* %fr5, %fr7 *) + | [1; 0] -> ([| phys_reg 101; phys_reg 18 |], 56) (* %fr5, %r24 *) + | [0; 1] -> ([| phys_reg 20; phys_reg 103 |], 56) (* %r26, %fr7 *) + | _ -> + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref 20 in + let ofs = ref 48 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int >= 17 then begin + loc.(i) <- phys_reg (!int); + decr int + end else begin + ofs := !ofs + 4; + loc.(i) <- stack_slot (Outgoing !ofs) ty + end + | Float -> + fatal_error "Proc.external_calling_conventions: cannot call" + done; + (loc, Misc.align !ofs 8) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 21 21 100 100 not_supported res in loc + +let loc_exn_bucket = phys_reg 20 (* %r26 *) + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* %r3 - %r18, %fr12 - %fr21 preserved *) + Array.of_list(List.map phys_reg + [13;14;15;16;17;18;19;20;21;22; + 100;101;102;103;104;105;106;107;118;119;120;121;122;123;124;125;126]) + +let destroyed_by_millicode = (* %r25, %r26, %r28, %r29 -- more? *) + [| phys_reg 19; phys_reg 20; phys_reg 21; phys_reg 22 |] + +let destroyed_by_alloc = [| phys_reg 22 |] (* %r29 *) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Iintop(Idiv | Imod)) -> destroyed_by_millicode + | Iop(Ialloc _) -> destroyed_by_alloc + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 16 + | Iintop(Idiv | Imod) -> 19 + | _ -> 23 + +let max_register_pressure = function + Iextcall(_, _) -> [| 16; 19 |] + | Iintop(Idiv | Imod) -> [| 19; 27 |] + | _ -> [| 23; 27 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/hppa/reload.ml b/asmcomp/hppa/reload.ml new file mode 100644 index 0000000..639f898 --- /dev/null +++ b/asmcomp/hppa/reload.ml @@ -0,0 +1,38 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.4 2008-01-11 16:13:11 doligez Exp $ *) + +(* Reloading for the HPPA *) + + +open Cmm +open Arch +open Reg +open Mach +open Proc + +class reload = object (self) + +inherit Reloadgen.reload_generic as super + +method reload_operation op arg res = + match op with + Iintop(Idiv | Imod) + | Iintop_imm((Idiv | Imod), _) -> (arg, res) + | _ -> super#reload_operation op arg res +end + + + +let fundecl f = + (new reload)#fundecl f diff --git a/asmcomp/hppa/scheduling.ml b/asmcomp/hppa/scheduling.ml new file mode 100644 index 0000000..0f249ef --- /dev/null +++ b/asmcomp/hppa/scheduling.ml @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.4 1999-11-17 18:56:42 xleroy Exp $ *) + +(* Instruction scheduling for the HPPA *) + +open Arch +open Mach + +class scheduler = object (self) + +inherit Schedgen.scheduler_generic + +(* Latencies (in cycles). Roughly based on the ``Mustang'' chips. *) + +method oper_latency = function + Ireload -> 2 + | Iload(_, _) -> 2 + | Iconst_float _ -> 2 (* turned into a load *) + | Iintop Imul -> 2 (* ends up with a load *) + | Iaddf | Isubf | Imulf -> 3 + | Idivf -> 12 + | _ -> 1 + +(* Issue cycles. Rough approximations. *) + +method oper_issue_cycles = function + Iconst_float _ -> 3 + | Iconst_symbol _ -> 2 + | Iload(_, Ibased(_, _)) -> 2 + | Istore(_, Ibased(_, _)) -> 2 + | Ialloc _ -> 5 + | Iintop Imul -> 10 + | Iintop Ilsl -> 3 + | Iintop Ilsr -> 2 + | Iintop Iasr -> 3 + | Iintop(Icomp _) -> 2 + | Iintop(Icheckbound) -> 2 + | Iintop_imm(Idiv, _) -> 4 + | Iintop_imm(Imod, _) -> 5 + | Iintop_imm(Icomp _, _) -> 2 + | Iintop_imm(Icheckbound, _) -> 2 + | Ifloatofint -> 4 + | Iintoffloat -> 4 + | _ -> 1 + +end + +let fundecl f = (new scheduler)#schedule_fundecl f diff --git a/asmcomp/hppa/selection.ml b/asmcomp/hppa/selection.ml new file mode 100644 index 0000000..b8891b4 --- /dev/null +++ b/asmcomp/hppa/selection.ml @@ -0,0 +1,109 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.6 2008-01-11 16:13:11 doligez Exp $ *) + +(* Instruction selection for the HPPA processor *) + +open Misc +open Cmm +open Reg +open Arch +open Proc +open Mach + +let shiftadd = function + 2 -> Ishift1add + | 4 -> Ishift2add + | 8 -> Ishift3add + | _ -> fatal_error "Proc_hppa.shiftadd" + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = (n < 16) && (n >= -16) (* 5 bits *) + +method select_addressing = function + Cconst_symbol s -> + (Ibased(s, 0), Ctuple []) + | Cop(Cadda, [Cconst_symbol s; Cconst_int n]) -> + (Ibased(s, n), Ctuple []) + | Cop(Cadda, [arg; Cconst_int n]) -> + (Iindexed n, arg) + | Cop(Cadda, [arg1; Cop(Caddi, [arg2; Cconst_int n])]) -> + (Iindexed n, Cop(Cadda, [arg1; arg2])) + | arg -> + (Iindexed 0, arg) + +method select_operation op args = + match (op, args) with + (* Recognize shift-add operations. *) + ((Caddi|Cadda), + [arg2; Cop(Clsl, [arg1; Cconst_int(1|2|3 as shift)])]) -> + (Ispecific(shiftadd(1 lsl shift)), [arg1; arg2]) + | ((Caddi|Cadda), + [arg2; Cop(Cmuli, [arg1; Cconst_int(2|4|8 as mult)])]) -> + (Ispecific(shiftadd mult), [arg1; arg2]) + | ((Caddi|Cadda), + [arg2; Cop(Cmuli, [Cconst_int(2|4|8 as mult); arg1])]) -> + (Ispecific(shiftadd mult), [arg1; arg2]) + | (Caddi, [Cop(Clsl, [arg1; Cconst_int(1|2|3 as shift)]); arg2]) -> + (Ispecific(shiftadd(1 lsl shift)), [arg1; arg2]) + | (Caddi, [Cop(Cmuli, [arg1; Cconst_int(2|4|8 as mult)]); arg2]) -> + (Ispecific(shiftadd mult), [arg1; arg2]) + | (Caddi, [Cop(Cmuli, [Cconst_int(2|4|8 as mult); arg1]); arg2]) -> + (Ispecific(shiftadd mult), [arg1; arg2]) + (* Prevent the recognition of some immediate arithmetic operations *) + (* Cmuli : -> Ilsl if power of 2 + Cdivi, Cmodi : only if power of 2 + Cand, Cor, Cxor : never *) + | (Cmuli, ([arg1; Cconst_int n] as args)) -> + let l = Misc.log2 n in + if n = 1 lsl l + then (Iintop_imm(Ilsl, l), [arg1]) + else (Iintop Imul, args) + | (Cmuli, ([Cconst_int n; arg1] as args)) -> + let l = Misc.log2 n in + if n = 1 lsl l + then (Iintop_imm(Ilsl, l), [arg1]) + else (Iintop Imul, args) + | (Cmuli, args) -> (Iintop Imul, args) + | (Cdivi, [arg1; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg1]) + | (Cdivi, args) -> (Iintop Idiv, args) + | (Cmodi, [arg1; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg1]) + | (Cmodi, args) -> (Iintop Imod, args) + | (Cand, args) -> (Iintop Iand, args) + | (Cor, args) -> (Iintop Ior, args) + | (Cxor, args) -> (Iintop Ixor, args) + | _ -> + super#select_operation op args + +(* Deal with register constraints *) + +method insert_op_debug op dbg rs rd = + match op with + Iintop(Idiv | Imod) -> (* handled via calls to millicode *) + let rs' = [|phys_reg 20; phys_reg 19|] (* %r26, %r25 *) + and rd' = [|phys_reg 22|] (* %r29 *) in + self#insert_moves rs rs'; + self#insert_debug (Iop op) dbg rs' rd'; + self#insert_moves rd' rd; + rd + | _ -> + super#insert_op_debug op dbg rs rd + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/i386/arch.ml b/asmcomp/i386/arch.ml new file mode 100644 index 0000000..f2284f3 --- /dev/null +++ b/asmcomp/i386/arch.ml @@ -0,0 +1,154 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.13 2006-04-16 23:28:14 doligez Exp $ *) + +(* Machine-specific command-line options *) + +let fast_math = ref false + +let command_line_options = + [ "-ffast-math", Arg.Set fast_math, + " Inline trigonometric and exponential functions" ] + +(* Specific operations for the Intel 386 processor *) + +open Misc +open Format + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + | Iindexed2 of int (* reg + reg + displ *) + | Iscaled of int * int (* reg * scale + displ *) + | Iindexed2scaled of int * int (* reg + reg * scale + displ *) + +type specific_operation = + Ilea of addressing_mode (* Lea gives scaled adds *) + | Istore_int of nativeint * addressing_mode (* Store an integer constant *) + | Istore_symbol of string * addressing_mode (* Store a symbol *) + | Ioffset_loc of int * addressing_mode (* Add a constant to a location *) + | Ipush (* Push regs on stack *) + | Ipush_int of nativeint (* Push an integer constant *) + | Ipush_symbol of string (* Push a symbol *) + | Ipush_load of addressing_mode (* Load a scalar and push *) + | Ipush_load_float of addressing_mode (* Load a float and push *) + | Isubfrev | Idivfrev (* Reversed float sub and div *) + | Ifloatarithmem of bool * float_operation * addressing_mode + (* Float arith operation with memory *) + (* bool: true=64 bits, false=32 *) + | Ifloatspecial of string + +and float_operation = + Ifloatadd | Ifloatsub | Ifloatsubrev | Ifloatmul | Ifloatdiv | Ifloatdivrev + +(* Sizes, endianness *) + +let big_endian = false + +let size_addr = 4 +let size_int = 4 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + | Iindexed2 n -> Iindexed2(n + delta) + | Iscaled(scale, n) -> Iscaled(scale, n + delta) + | Iindexed2scaled(scale, n) -> Iindexed2scaled(scale, n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + | Iindexed2 n -> 2 + | Iscaled(scale, n) -> 1 + | Iindexed2scaled(scale, n) -> 2 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, 0) -> + fprintf ppf "\"%s\"" s + | Ibased(s, n) -> + fprintf ppf "\"%s\" + %i" s n + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + | Iindexed2 n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a + %a%s" printreg arg.(0) printreg arg.(1) idx + | Iscaled(scale, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a * %i%s" printreg arg.(0) scale idx + | Iindexed2scaled(scale, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a + %a * %i%s" printreg arg.(0) printreg arg.(1) scale idx + +let print_specific_operation printreg op ppf arg = + match op with + | Ilea addr -> print_addressing printreg addr ppf arg + | Istore_int(n, addr) -> + fprintf ppf "[%a] := %s" (print_addressing printreg addr) arg + (Nativeint.to_string n) + | Istore_symbol(lbl, addr) -> + fprintf ppf "[%a] := \"%s\"" (print_addressing printreg addr) arg lbl + | Ioffset_loc(n, addr) -> + fprintf ppf "[%a] +:= %i" (print_addressing printreg addr) arg n + | Ipush -> + fprintf ppf "push "; + for i = 0 to Array.length arg - 1 do + if i > 0 then fprintf ppf ", "; + printreg ppf arg.(i) + done + | Ipush_int n -> + fprintf ppf "push %s" (Nativeint.to_string n) + | Ipush_symbol s -> + fprintf ppf "push \"%s\"" s + | Ipush_load addr -> + fprintf ppf "push [%a]" (print_addressing printreg addr) arg + | Ipush_load_float addr -> + fprintf ppf "pushfloat [%a]" (print_addressing printreg addr) arg + | Isubfrev -> + fprintf ppf "%a -f(rev) %a" printreg arg.(0) printreg arg.(1) + | Idivfrev -> + fprintf ppf "%a /f(rev) %a" printreg arg.(0) printreg arg.(1) + | Ifloatarithmem(double, op, addr) -> + let op_name = function + | Ifloatadd -> "+f" + | Ifloatsub -> "-f" + | Ifloatsubrev -> "-f(rev)" + | Ifloatmul -> "*f" + | Ifloatdiv -> "/f" + | Ifloatdivrev -> "/f(rev)" in + let long = if double then "float64" else "float32" in + fprintf ppf "%a %s %s[%a]" printreg arg.(0) (op_name op) long + (print_addressing printreg addr) (Array.sub arg 1 (Array.length arg - 1)) + | Ifloatspecial name -> + fprintf ppf "%s " name; + for i = 0 to Array.length arg - 1 do + if i > 0 then fprintf ppf ", "; + printreg ppf arg.(i) + done + +(* Stack alignment constraints *) + +let stack_alignment = + match Config.system with + | "macosx" -> 16 + | _ -> 4 + diff --git a/asmcomp/i386/emit.mlp b/asmcomp/i386/emit.mlp new file mode 100644 index 0000000..5324cb7 --- /dev/null +++ b/asmcomp/i386/emit.mlp @@ -0,0 +1,990 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.42 2008-12-03 18:09:08 doligez Exp $ *) + +(* Emission of Intel 386 assembly code *) + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +let stack_offset = ref 0 + +(* Layout of the stack frame *) + +let frame_size () = (* includes return address *) + let sz = + !stack_offset + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + 4 + in Misc.align sz stack_alignment + +let slot_offset loc cl = + match loc with + Incoming n -> + assert (n >= 0); + frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + n * 4 + else !stack_offset + num_stack_slots.(0) * 4 + n * 8 + | Outgoing n -> + assert (n >= 0); + n + +let trap_frame_size = Misc.align 8 stack_alignment + +(* Prefixing of symbols with "_" *) + +let symbol_prefix = + match Config.system with + "linux_elf" -> "" + | "bsd_elf" -> "" + | "solaris" -> "" + | "beos" -> "" + | "gnu" -> "" + | _ -> "_" + +let emit_symbol s = + emit_string symbol_prefix; Emitaux.emit_symbol '$' s + +(* Output a label *) + +let label_prefix = + match Config.system with + "linux_elf" -> ".L" + | "bsd_elf" -> ".L" + | "solaris" -> ".L" + | "beos" -> ".L" + | "gnu" -> ".L" + | _ -> "L" + +let emit_label lbl = + emit_string label_prefix; emit_int lbl + + +(* Some data directives have different names under Solaris *) + +let word_dir = + match Config.system with + "solaris" -> ".value" + | _ -> ".word" +let skip_dir = + match Config.system with + "solaris" -> ".zero" + | _ -> ".space" +let use_ascii_dir = + match Config.system with + "solaris" -> false + | _ -> true + +(* MacOSX has its own way to reference symbols potentially defined in + shared objects *) + +let macosx = + match Config.system with + | "macosx" -> true + | _ -> false + +(* Output a .align directive. + The numerical argument to .align is log2 of alignment size, except + under ELF, where it is the alignment size... *) + +let emit_align = + match Config.system with + "linux_elf" | "bsd_elf" | "solaris" | "beos" | "cygwin" | "mingw" | "gnu" -> + (fun n -> ` .align {emit_int n}\n`) + | _ -> + (fun n -> ` .align {emit_int(Misc.log2 n)}\n`) + +let emit_Llabel fallthrough lbl = + if not fallthrough && !fastcode_flag then + emit_align 16 ; + emit_label lbl + +(* Output a pseudo-register *) + +let emit_reg = function + { loc = Reg r } -> + emit_string (register_name r) + | { loc = Stack(Incoming n | Outgoing n) } when n < 0 -> + `{emit_symbol "caml_extra_params"} + {emit_int (n + 64)}` + | { loc = Stack s } as r -> + let ofs = slot_offset s (register_class r) in + `{emit_int ofs}(%esp)` + | { loc = Unknown } -> + fatal_error "Emit_i386.emit_reg" + +(* Output a reference to the lower 8 bits or lower 16 bits of a register *) + +let reg_low_byte_name = [| "%al"; "%bl"; "%cl"; "%dl" |] +let reg_low_half_name = [| "%ax"; "%bx"; "%cx"; "%dx"; "%si"; "%di"; "%bp" |] + +let emit_reg8 r = + match r.loc with + Reg r when r < 4 -> emit_string (reg_low_byte_name.(r)) + | _ -> fatal_error "Emit_i386.emit_reg8" + +let emit_reg16 r = + match r.loc with + Reg r when r < 7 -> emit_string (reg_low_half_name.(r)) + | _ -> fatal_error "Emit_i386.emit_reg16" + +(* Output an addressing mode *) + +let emit_addressing addr r n = + match addr with + Ibased(s, d) -> + `{emit_symbol s}`; + if d <> 0 then ` + {emit_int d}` + | Iindexed d -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)})` + | Iindexed2 d -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n+1)})` + | Iscaled(2, d) -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n)})` + | Iscaled(scale, d) -> + if d <> 0 then emit_int d; + `(, {emit_reg r.(n)}, {emit_int scale})` + | Iindexed2scaled(scale, d) -> + if d <> 0 then emit_int d; + `({emit_reg r.(n)}, {emit_reg r.(n+1)}, {emit_int scale})` + +(* Record live pointers at call points *) + +let record_frame_label live dbg = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset; + fd_debuginfo = dbg } :: !frame_descriptors; + lbl + +let record_frame live dbg = + let lbl = record_frame_label live dbg in `{emit_label lbl}:\n` + +(* Record calls to the GC -- we've moved them out of the way *) + +type gc_call = + { gc_lbl: label; (* Entry label *) + gc_return_lbl: label; (* Where to branch after GC *) + gc_frame: label } (* Label of frame descriptor *) + +let call_gc_sites = ref ([] : gc_call list) + +let emit_call_gc gc = + `{emit_label gc.gc_lbl}: call {emit_symbol "caml_call_gc"}\n`; + `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n` + +(* Record calls to caml_ml_array_bound_error. + In -g mode, we maintain one call to caml_ml_array_bound_error + per bound check site. Without -g, we can share a single call. *) + +type bound_error_call = + { bd_lbl: label; (* Entry label *) + bd_frame: label } (* Label of frame descriptor *) + +let bound_error_sites = ref ([] : bound_error_call list) +let bound_error_call = ref 0 + +let bound_error_label dbg = + if !Clflags.debug then begin + let lbl_bound_error = new_label() in + let lbl_frame = record_frame_label Reg.Set.empty dbg in + bound_error_sites := + { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites; + lbl_bound_error + end else begin + if !bound_error_call = 0 then bound_error_call := new_label(); + !bound_error_call + end + +let emit_call_bound_error bd = + `{emit_label bd.bd_lbl}: call {emit_symbol "caml_ml_array_bound_error"}\n`; + `{emit_label bd.bd_frame}:\n` + +let emit_call_bound_errors () = + List.iter emit_call_bound_error !bound_error_sites; + if !bound_error_call > 0 then + `{emit_label !bound_error_call}: call {emit_symbol "caml_ml_array_bound_error"}\n` + +(* Names for instructions *) + +let instr_for_intop = function + Iadd -> "addl" + | Isub -> "subl" + | Imul -> "imull" + | Iand -> "andl" + | Ior -> "orl" + | Ixor -> "xorl" + | Ilsl -> "sall" + | Ilsr -> "shrl" + | Iasr -> "sarl" + | _ -> fatal_error "Emit_i386: instr_for_intop" + +let instr_for_floatop = function + Inegf -> "fchs" + | Iabsf -> "fabs" + | Iaddf -> "faddl" + | Isubf -> "fsubl" + | Imulf -> "fmull" + | Idivf -> "fdivl" + | Ispecific Isubfrev -> "fsubrl" + | Ispecific Idivfrev -> "fdivrl" + | _ -> fatal_error "Emit_i386: instr_for_floatop" + +let instr_for_floatop_reversed = function + Iaddf -> "faddl" + | Isubf -> "fsubrl" + | Imulf -> "fmull" + | Idivf -> "fdivrl" + | Ispecific Isubfrev -> "fsubl" + | Ispecific Idivfrev -> "fdivl" + | _ -> fatal_error "Emit_i386: instr_for_floatop_reversed" + +let instr_for_floatop_pop = function + Iaddf -> "faddp" + | Isubf -> "fsubp" + | Imulf -> "fmulp" + | Idivf -> "fdivp" + | Ispecific Isubfrev -> "fsubrp" + | Ispecific Idivfrev -> "fdivrp" + | _ -> fatal_error "Emit_i386: instr_for_floatop_pop" + +let instr_for_floatarithmem double = function + Ifloatadd -> if double then "faddl" else "fadds" + | Ifloatsub -> if double then "fsubl" else "fsubs" + | Ifloatsubrev -> if double then "fsubrl" else "fsubrs" + | Ifloatmul -> if double then "fmull" else "fmuls" + | Ifloatdiv -> if double then "fdivl" else "fdivs" + | Ifloatdivrev -> if double then "fdivrl" else "fdivrs" + +let name_for_cond_branch = function + Isigned Ceq -> "e" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "g" + | Isigned Clt -> "l" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a" + | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae" + +(* Output an = 0 or <> 0 test. *) + +let output_test_zero arg = + match arg.loc with + Reg r -> ` testl {emit_reg arg}, {emit_reg arg}\n` + | _ -> ` cmpl $0, {emit_reg arg}\n` + +(* Deallocate the stack frame before a return or tail call *) + +let output_epilogue () = + let n = frame_size() - 4 in + if n > 0 then ` addl ${emit_int n}, %esp\n` + +(* Determine if the given register is the top of the floating-point stack *) + +let is_tos = function { loc = Reg _; typ = Float } -> true | _ -> false + +(* Emit the code for a floating-point comparison *) + +let emit_float_test cmp neg arg lbl = + let actual_cmp = + match (is_tos arg.(0), is_tos arg.(1)) with + (true, true) -> + (* both args on top of FP stack *) + ` fcompp\n`; + cmp + | (true, false) -> + (* first arg on top of FP stack *) + ` fcompl {emit_reg arg.(1)}\n`; + cmp + | (false, true) -> + (* second arg on top of FP stack *) + ` fcompl {emit_reg arg.(0)}\n`; + Cmm.swap_comparison cmp + | (false, false) -> + ` fldl {emit_reg arg.(0)}\n`; + ` fcompl {emit_reg arg.(1)}\n`; + cmp + in + ` fnstsw %ax\n`; + begin match actual_cmp with + Ceq -> + if neg then begin + ` andb $68, %ah\n`; + ` xorb $64, %ah\n`; + ` jne ` + end else begin + ` andb $69, %ah\n`; + ` cmpb $64, %ah\n`; + ` je ` + end + | Cne -> + if neg then begin + ` andb $69, %ah\n`; + ` cmpb $64, %ah\n`; + ` je ` + end else begin + ` andb $68, %ah\n`; + ` xorb $64, %ah\n`; + ` jne ` + end + | Cle -> + ` andb $69, %ah\n`; + ` decb %ah\n`; + ` cmpb $64, %ah\n`; + if neg + then ` jae ` + else ` jb ` + | Cge -> + ` andb $5, %ah\n`; + if neg + then ` jne ` + else ` je ` + | Clt -> + ` andb $69, %ah\n`; + ` cmpb $1, %ah\n`; + if neg + then ` jne ` + else ` je ` + | Cgt -> + ` andb $69, %ah\n`; + if neg + then ` jne ` + else ` je ` + end; + `{emit_label lbl}\n` + +(* Emit a Ifloatspecial instruction *) + +let emit_floatspecial = function + "atan" -> ` fld1; fpatan\n` + | "atan2" -> ` fpatan\n` + | "cos" -> ` fcos\n` + | "log" -> ` fldln2; fxch; fyl2x\n` + | "log10" -> ` fldlg2; fxch; fyl2x\n` + | "sin" -> ` fsin\n` + | "sqrt" -> ` fsqrt\n` + | "tan" -> ` fptan; fstp %st(0)\n` + | _ -> assert false + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Label of trap for out-of-range accesses *) +let range_check_trap = ref 0 +(* Record float literals to be emitted later *) +let float_constants = ref ([] : (int * string) list) +(* Record references to external C functions (for MacOSX) *) +let external_symbols_direct = ref StringSet.empty +let external_symbols_indirect = ref StringSet.empty + +let emit_instr fallthrough i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + if src.typ = Float then + if is_tos src then + ` fstpl {emit_reg dst}\n` + else if is_tos dst then + ` fldl {emit_reg src}\n` + else begin + ` fldl {emit_reg src}\n`; + ` fstpl {emit_reg dst}\n` + end + else + ` movl {emit_reg src}, {emit_reg dst}\n` + end + | Lop(Iconst_int n) -> + if n = 0n then begin + match i.res.(0).loc with + Reg n -> ` xorl {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> ` movl $0, {emit_reg i.res.(0)}\n` + end else + ` movl ${emit_nativeint n}, {emit_reg i.res.(0)}\n` + | Lop(Iconst_float s) -> + begin match Int64.bits_of_float (float_of_string s) with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + ` fldz\n` + | 0x8000_0000_0000_0000L -> (* -0.0 *) + ` fldz\n fchs\n` + | 0x3FF0_0000_0000_0000L -> (* 1.0 *) + ` fld1\n` + | 0xBFF0_0000_0000_0000L -> (* -1.0 *) + ` fld1\n fchs\n` + | _ -> + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` fldl {emit_label lbl}\n` + end + | Lop(Iconst_symbol s) -> + ` movl ${emit_symbol s}, {emit_reg i.res.(0)}\n` + | Lop(Icall_ind) -> + ` call *{emit_reg i.arg.(0)}\n`; + record_frame i.live i.dbg + | Lop(Icall_imm s) -> + ` call {emit_symbol s}\n`; + record_frame i.live i.dbg + | Lop(Itailcall_ind) -> + output_epilogue(); + ` jmp *{emit_reg i.arg.(0)}\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then + ` jmp {emit_label !tailrec_entry_point}\n` + else begin + output_epilogue(); + ` jmp {emit_symbol s}\n` + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + if not macosx then + ` movl ${emit_symbol s}, %eax\n` + else begin + external_symbols_indirect := + StringSet.add s !external_symbols_indirect; + ` movl L{emit_symbol s}$non_lazy_ptr, %eax\n` + end; + ` call {emit_symbol "caml_c_call"}\n`; + record_frame i.live i.dbg + end else begin + if not macosx then + ` call {emit_symbol s}\n` + else begin + external_symbols_direct := + StringSet.add s !external_symbols_direct; + ` call L{emit_symbol s}$stub\n` + end + end + | Lop(Istackoffset n) -> + if n < 0 + then ` addl ${emit_int(-n)}, %esp\n` + else ` subl ${emit_int(n)}, %esp\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + | Word | Thirtytwo_signed | Thirtytwo_unsigned -> + ` movl {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Byte_unsigned -> + ` movzbl {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Byte_signed -> + ` movsbl {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Sixteen_unsigned -> + ` movzwl {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Sixteen_signed -> + ` movswl {emit_addressing addr i.arg 0}, {emit_reg dest}\n` + | Single -> + ` flds {emit_addressing addr i.arg 0}\n` + | Double | Double_u -> + ` fldl {emit_addressing addr i.arg 0}\n` + end + | Lop(Istore(chunk, addr)) -> + begin match chunk with + | Word | Thirtytwo_signed | Thirtytwo_unsigned -> + ` movl {emit_reg i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Byte_unsigned | Byte_signed -> + ` movb {emit_reg8 i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Sixteen_unsigned | Sixteen_signed -> + ` movw {emit_reg16 i.arg.(0)}, {emit_addressing addr i.arg 1}\n` + | Single -> + if is_tos i.arg.(0) then + ` fstps {emit_addressing addr i.arg 1}\n` + else begin + ` fldl {emit_reg i.arg.(0)}\n`; + ` fstps {emit_addressing addr i.arg 1}\n` + end + | Double | Double_u -> + if is_tos i.arg.(0) then + ` fstpl {emit_addressing addr i.arg 1}\n` + else begin + ` fldl {emit_reg i.arg.(0)}\n`; + ` fstpl {emit_addressing addr i.arg 1}\n` + end + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_redo = new_label() in + `{emit_label lbl_redo}: movl {emit_symbol "caml_young_ptr"}, %eax\n`; + ` subl ${emit_int n}, %eax\n`; + ` movl %eax, {emit_symbol "caml_young_ptr"}\n`; + ` cmpl {emit_symbol "caml_young_limit"}, %eax\n`; + let lbl_call_gc = new_label() in + let lbl_frame = record_frame_label i.live Debuginfo.none in + ` jb {emit_label lbl_call_gc}\n`; + ` leal 4(%eax), {emit_reg i.res.(0)}\n`; + call_gc_sites := + { gc_lbl = lbl_call_gc; + gc_return_lbl = lbl_redo; + gc_frame = lbl_frame } :: !call_gc_sites + end else begin + begin match n with + 8 -> ` call {emit_symbol "caml_alloc1"}\n` + | 12 -> ` call {emit_symbol "caml_alloc2"}\n` + | 16 -> ` call {emit_symbol "caml_alloc3"}\n` + | _ -> ` movl ${emit_int n}, %eax\n`; + ` call {emit_symbol "caml_allocN"}\n` + end; + `{record_frame i.live Debuginfo.none} leal 4(%eax), {emit_reg i.res.(0)}\n` + end + | Lop(Iintop(Icomp cmp)) -> + ` cmpl {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} %al\n`; + ` movzbl %al, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + ` cmpl ${emit_int n}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} %al\n`; + ` movzbl %al, {emit_reg i.res.(0)}\n` + | Lop(Iintop Icheckbound) -> + let lbl = bound_error_label i.dbg in + ` cmpl {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + let lbl = bound_error_label i.dbg in + ` cmpl ${emit_int n}, {emit_reg i.arg.(0)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop(Idiv | Imod)) -> + ` cltd\n`; + ` idivl {emit_reg i.arg.(1)}\n` + | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) -> + (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %ecx *) + ` {emit_string(instr_for_intop op)} %cl, {emit_reg i.res.(0)}\n` + | Lop(Iintop op) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc -> + ` leal {emit_int n}({emit_reg i.arg.(0)}), {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) -> + ` incl {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) -> + ` decl {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + let l = Misc.log2 n in + let lbl = new_label() in + output_test_zero i.arg.(0); + ` jge {emit_label lbl}\n`; + ` addl ${emit_int(n-1)}, {emit_reg i.arg.(0)}\n`; + `{emit_label lbl}: sarl ${emit_int l}, {emit_reg i.arg.(0)}\n` + | Lop(Iintop_imm(Imod, n)) -> + let lbl = new_label() in + ` movl {emit_reg i.arg.(0)}, %eax\n`; + ` testl %eax, %eax\n`; + ` jge {emit_label lbl}\n`; + ` addl ${emit_int(n-1)}, %eax\n`; + `{emit_label lbl}: andl ${emit_int(-n)}, %eax\n`; + ` subl %eax, {emit_reg i.arg.(0)}\n` + | Lop(Iintop_imm(op, n)) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} ${emit_int n}, {emit_reg i.res.(0)}\n` + | Lop(Inegf | Iabsf as floatop) -> + if not (is_tos i.arg.(0)) then + ` fldl {emit_reg i.arg.(0)}\n`; + ` {emit_string(instr_for_floatop floatop)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf | Ispecific(Isubfrev | Idivfrev) + as floatop) -> + begin match (is_tos i.arg.(0), is_tos i.arg.(1)) with + (true, true) -> + (* both operands on top of FP stack *) + ` {emit_string(instr_for_floatop_pop floatop)} %st, %st(1)\n` + | (true, false) -> + (* first operand on stack *) + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}\n` + | (false, true) -> + (* second operand on stack *) + ` {emit_string(instr_for_floatop_reversed floatop)} {emit_reg i.arg.(0)}\n` + | (false, false) -> + (* both operands in memory *) + ` fldl {emit_reg i.arg.(0)}\n`; + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}\n` + end + | Lop(Ifloatofint) -> + begin match i.arg.(0).loc with + Stack s -> + ` fildl {emit_reg i.arg.(0)}\n` + | _ -> + ` pushl {emit_reg i.arg.(0)}\n`; + ` fildl (%esp)\n`; + ` addl $4, %esp\n` + end + | Lop(Iintoffloat) -> + if not (is_tos i.arg.(0)) then + ` fldl {emit_reg i.arg.(0)}\n`; + stack_offset := !stack_offset - 8; + ` subl $8, %esp\n`; + ` fnstcw 4(%esp)\n`; + ` movw 4(%esp), %ax\n`; + ` movb $12, %ah\n`; + ` movw %ax, 0(%esp)\n`; + ` fldcw 0(%esp)\n`; + begin match i.res.(0).loc with + Stack s -> + ` fistpl {emit_reg i.res.(0)}\n` + | _ -> + ` fistpl (%esp)\n`; + ` movl (%esp), {emit_reg i.res.(0)}\n` + end; + ` fldcw 4(%esp)\n`; + ` addl $8, %esp\n`; + stack_offset := !stack_offset + 8 + | Lop(Ispecific(Ilea addr)) -> + ` lea {emit_addressing addr i.arg 0}, {emit_reg i.res.(0)}\n` + | Lop(Ispecific(Istore_int(n, addr))) -> + ` movl ${emit_nativeint n}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Istore_symbol(s, addr))) -> + ` movl ${emit_symbol s}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Ioffset_loc(n, addr))) -> + ` addl ${emit_int n}, {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Ipush)) -> + (* Push arguments in reverse order *) + for n = Array.length i.arg - 1 downto 0 do + let r = i.arg.(n) in + match r with + {loc = Reg _; typ = Float} -> + ` subl $8, %esp\n`; + ` fstpl 0(%esp)\n`; + stack_offset := !stack_offset + 8 + | {loc = Stack sl; typ = Float} -> + let ofs = slot_offset sl 1 in + ` pushl {emit_int(ofs + 4)}(%esp)\n`; + ` pushl {emit_int(ofs + 4)}(%esp)\n`; + stack_offset := !stack_offset + 8 + | _ -> + ` pushl {emit_reg r}\n`; + stack_offset := !stack_offset + 4 + done + | Lop(Ispecific(Ipush_int n)) -> + ` pushl ${emit_nativeint n}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_symbol s)) -> + ` pushl ${emit_symbol s}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_load addr)) -> + ` pushl {emit_addressing addr i.arg 0}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_load_float addr)) -> + ` pushl {emit_addressing (offset_addressing addr 4) i.arg 0}\n`; + ` pushl {emit_addressing addr i.arg 0}\n`; + stack_offset := !stack_offset + 8 + | Lop(Ispecific(Ifloatarithmem(double, op, addr))) -> + if not (is_tos i.arg.(0)) then + ` fldl {emit_reg i.arg.(0)}\n`; + ` {emit_string(instr_for_floatarithmem double op)} {emit_addressing addr i.arg 1}\n` + | Lop(Ispecific(Ifloatspecial s)) -> + (* Push args on float stack if necessary *) + for k = 0 to Array.length i.arg - 1 do + if not (is_tos i.arg.(k)) then ` fldl {emit_reg i.arg.(k)}\n` + done; + (* Fix-up for binary instrs whose args were swapped *) + if Array.length i.arg = 2 && is_tos i.arg.(1) then + ` fxch %st(1)\n`; + emit_floatspecial s + | Lreloadretaddr -> + () + | Lreturn -> + output_epilogue(); + ` ret\n` + | Llabel lbl -> + `{emit_Llabel fallthrough lbl}:\n` + | Lbranch lbl -> + ` jmp {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + output_test_zero i.arg.(0); + ` jne {emit_label lbl}\n` + | Ifalsetest -> + output_test_zero i.arg.(0); + ` je {emit_label lbl}\n` + | Iinttest cmp -> + ` cmpl {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm((Isigned Ceq | Isigned Cne | + Iunsigned Ceq | Iunsigned Cne) as cmp, 0) -> + output_test_zero i.arg.(0); + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + ` cmpl ${emit_int n}, {emit_reg i.arg.(0)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + emit_float_test cmp neg i.arg lbl + | Ioddtest -> + ` testl $1, {emit_reg i.arg.(0)}\n`; + ` jne {emit_label lbl}\n` + | Ieventest -> + ` testl $1, {emit_reg i.arg.(0)}\n`; + ` je {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmpl $1, {emit_reg i.arg.(0)}\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` jb {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` je {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` jg {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl = new_label() in + ` jmp *{emit_label lbl}(, {emit_reg i.arg.(0)}, 4)\n`; + ` .data\n`; + `{emit_label lbl}:`; + for i = 0 to Array.length jumptbl - 1 do + ` .long {emit_label jumptbl.(i)}\n` + done; + ` .text\n` + | Lsetuptrap lbl -> + ` call {emit_label lbl}\n` + | Lpushtrap -> + if trap_frame_size > 8 then + ` subl ${emit_int (trap_frame_size - 8)}, %esp\n`; + ` pushl {emit_symbol "caml_exception_pointer"}\n`; + ` movl %esp, {emit_symbol "caml_exception_pointer"}\n`; + stack_offset := !stack_offset + trap_frame_size + | Lpoptrap -> + ` popl {emit_symbol "caml_exception_pointer"}\n`; + ` addl ${emit_int (trap_frame_size - 4)}, %esp\n`; + stack_offset := !stack_offset - trap_frame_size + | Lraise -> + if !Clflags.debug then begin + ` call {emit_symbol "caml_raise_exn"}\n`; + record_frame Reg.Set.empty i.dbg + end else begin + ` movl {emit_symbol "caml_exception_pointer"}, %esp\n`; + ` popl {emit_symbol "caml_exception_pointer"}\n`; + if trap_frame_size > 8 then + ` addl ${emit_int (trap_frame_size - 8)}, %esp\n`; + ` ret\n` + end + +let rec emit_all fallthrough i = + match i.desc with + | Lend -> () + | _ -> + emit_instr fallthrough i; + emit_all + (Linearize.has_fallthrough i.desc) + i.next + +(* Emission of the floating-point constants *) + +let emit_float_constant (lbl, cst) = + ` .data\n`; + `{emit_label lbl}: .double {emit_string cst}\n` + +(* Emission of external symbol references (for MacOSX) *) + +let emit_external_symbol_direct s = + `L{emit_symbol s}$stub:\n`; + ` .indirect_symbol {emit_symbol s}\n`; + ` hlt ; hlt ; hlt ; hlt ; hlt\n` + +let emit_external_symbol_indirect s = + `L{emit_symbol s}$non_lazy_ptr:\n`; + ` .indirect_symbol {emit_symbol s}\n`; + ` .long 0\n` + +let emit_external_symbols () = + ` .section __IMPORT,__pointers,non_lazy_symbol_pointers\n`; + StringSet.iter emit_external_symbol_indirect !external_symbols_indirect; + external_symbols_indirect := StringSet.empty; + ` .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5\n`; + StringSet.iter emit_external_symbol_direct !external_symbols_direct; + external_symbols_direct := StringSet.empty; + if !Clflags.gprofile then begin + `Lmcount$stub:\n`; + ` .indirect_symbol mcount\n`; + ` hlt ; hlt ; hlt ; hlt ; hlt\n` + end + +(* Emission of the profiling prelude *) + +let emit_profile () = + match Config.system with + "linux_elf" | "gnu" -> + ` pushl %eax\n`; + ` movl %esp, %ebp\n`; + ` pushl %ecx\n`; + ` pushl %edx\n`; + ` call {emit_symbol "mcount"}\n`; + ` popl %edx\n`; + ` popl %ecx\n`; + ` popl %eax\n` + | "bsd_elf" -> + ` pushl %eax\n`; + ` movl %esp, %ebp\n`; + ` pushl %ecx\n`; + ` pushl %edx\n`; + ` call .mcount\n`; + ` popl %edx\n`; + ` popl %ecx\n`; + ` popl %eax\n` + | "macosx" -> + ` pushl %eax\n`; + ` movl %esp, %ebp\n`; + ` pushl %ecx\n`; + ` pushl %edx\n`; + ` call Lmcount$stub\n`; + ` popl %edx\n`; + ` popl %ecx\n`; + ` popl %eax\n` + | _ -> () (*unsupported yet*) + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + float_constants := []; + call_gc_sites := []; + bound_error_sites := []; + bound_error_call := 0; + ` .text\n`; + emit_align 16; + ` .globl {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + if !Clflags.gprofile then emit_profile(); + let n = frame_size() - 4 in + if n > 0 then + ` subl ${emit_int n}, %esp\n`; + `{emit_label !tailrec_entry_point}:\n`; + emit_all true fundecl.fun_body; + List.iter emit_call_gc !call_gc_sites; + emit_call_bound_errors (); + List.iter emit_float_constant !float_constants; + match Config.system with + "linux_elf" | "bsd_elf" | "gnu" -> + ` .type {emit_symbol fundecl.fun_name},@function\n`; + ` .size {emit_symbol fundecl.fun_name},.-{emit_symbol fundecl.fun_name}\n` + | _ -> () + + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .globl {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` {emit_string word_dir} {emit_int n}\n` + | Cint32 n -> + ` .long {emit_nativeint n}\n` + | Cint n -> + ` .long {emit_nativeint n}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .double {emit_string f}\n` + | Csymbol_address s -> + ` .long {emit_symbol s}\n` + | Clabel_address lbl -> + ` .long {emit_label (100000 + lbl)}\n` + | Cstring s -> + if use_ascii_dir + then emit_string_directive " .ascii " s + else emit_bytes_directive " .byte " s + | Cskip n -> + if n > 0 then ` {emit_string skip_dir} {emit_int n}\n` + | Calign n -> + emit_align n + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n` + +let end_assembly() = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .text\n`; + if macosx then ` NOP\n`; (* suppress "ld warning: atom sorting error" *) + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .data\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .long 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + ` .globl {emit_symbol lbl}\n`; + `{emit_symbol lbl}:\n`; + emit_frames + { efa_label = (fun l -> ` .long {emit_label l}\n`); + efa_16 = (fun n -> ` {emit_string word_dir} {emit_int n}\n`); + efa_32 = (fun n -> ` .long {emit_int32 n}\n`); + efa_word = (fun n -> ` .long {emit_int n}\n`); + efa_align = emit_align; + efa_label_rel = (fun lbl ofs -> + ` .long {emit_label lbl} - . + {emit_int32 ofs}\n`); + efa_def_label = (fun l -> `{emit_label l}:\n`); + efa_string = (fun s -> + let s = s ^ "\000" in + if use_ascii_dir + then emit_string_directive " .ascii " s + else emit_bytes_directive " .byte " s) }; + if macosx then emit_external_symbols (); + if Config.system = "linux_elf" then + (* Mark stack as non-executable, PR#4564 *) + `\n .section .note.GNU-stack,\"\",%progbits\n` diff --git a/asmcomp/i386/emit_nt.mlp b/asmcomp/i386/emit_nt.mlp new file mode 100644 index 0000000..d4b8dab --- /dev/null +++ b/asmcomp/i386/emit_nt.mlp @@ -0,0 +1,906 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit_nt.mlp,v 1.28 2008-01-11 16:13:11 doligez Exp $ *) + +(* Emission of Intel 386 assembly code, MASM syntax. *) + +module StringSet = + Set.Make(struct type t = string let compare = compare end) + +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Layout of the stack frame *) + +let stack_offset = ref 0 + +let frame_size () = (* includes return address *) + !stack_offset + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + 4 + +let slot_offset loc cl = + match loc with + Incoming n -> + assert (n >= 0); + frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + n * 4 + else !stack_offset + num_stack_slots.(0) * 4 + n * 8 + | Outgoing n -> + assert (n >= 0); + n +(* Record symbols used and defined - at the end generate extern for those + used but not defined *) + +let symbols_defined = ref StringSet.empty +let symbols_used = ref StringSet.empty + +let add_def_symbol s = + symbols_defined := StringSet.add s !symbols_defined + +let add_used_symbol s = + symbols_used := StringSet.add s !symbols_used + +let emit_symbol s = + emit_string "_"; Emitaux.emit_symbol '$' s + +let emit_int32 n = emit_printf "0%lxh" n + +(* Output a label *) + +let emit_label lbl = + emit_string "L"; emit_int lbl + +(* Output an align directive. *) + +let emit_align n = ` ALIGN {emit_int n}\n` + +(* Output a pseudo-register *) + +let emit_reg = function + { loc = Reg r } -> + emit_string (register_name r) + | { loc = Stack(Incoming n | Outgoing n) } when n < 0 -> + `{emit_symbol "caml_extra_params"} + {emit_int (n + 64)}` + | { loc = Stack s; typ = Float } as r -> + let ofs = slot_offset s (register_class r) in + `REAL8 PTR {emit_int ofs}[esp]` + | { loc = Stack s } as r -> + let ofs = slot_offset s (register_class r) in + `DWORD PTR {emit_int ofs}[esp]` + | { loc = Unknown } -> + fatal_error "Emit.emit_reg" + +(* Output a reference to the lower 8 bits or lower 16 bits of a register *) + +let reg_low_byte_name = [| "al"; "bl"; "cl"; "dl" |] +let reg_low_half_name = [| "ax"; "bx"; "cx"; "dx"; "si"; "di"; "bp" |] + +let emit_reg8 r = + match r.loc with + Reg r when r < 4 -> emit_string (reg_low_byte_name.(r)) + | _ -> fatal_error "Emit.emit_reg8" + +let emit_reg16 r = + match r.loc with + Reg r when r < 7 -> emit_string (reg_low_half_name.(r)) + | _ -> fatal_error "Emit.emit_reg16" + +(* Check if the given register overlaps (same location) with the given + array of registers *) + +let register_overlap reg arr = + try + for i = 0 to Array.length arr - 1 do + if reg.loc = arr.(i).loc then raise Exit + done; + false + with Exit -> + true + +(* Output an addressing mode *) + +let emit_signed_int d = + if d > 0 then emit_char '+'; + if d <> 0 then emit_int d + +let emit_addressing addr r n = + match addr with + Ibased(s, d) -> + add_used_symbol s; + `{emit_symbol s}{emit_signed_int d}` + | Iindexed d -> + `[{emit_reg r.(n)}{emit_signed_int d}]` + | Iindexed2 d -> + `[{emit_reg r.(n)}+{emit_reg r.(n+1)}{emit_signed_int d}]` + | Iscaled(2, d) -> + `[{emit_reg r.(n)}+{emit_reg r.(n)}{emit_signed_int d}]` + | Iscaled(scale, d) -> + `[{emit_reg r.(n)}*{emit_int scale}{emit_signed_int d}]` + | Iindexed2scaled(scale, d) -> + `[{emit_reg r.(n)}+{emit_reg r.(n+1)}*{emit_int scale}{emit_signed_int d}]` + +(* Record live pointers at call points *) + +let record_frame_label live dbg = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset; + fd_debuginfo = dbg } :: !frame_descriptors; + lbl + +let record_frame live dbg = + let lbl = record_frame_label live dbg in `{emit_label lbl}:\n` + +(* Record calls to the GC -- we've moved them out of the way *) + +type gc_call = + { gc_lbl: label; (* Entry label *) + gc_return_lbl: label; (* Where to branch after GC *) + gc_frame: label } (* Label of frame descriptor *) + +let call_gc_sites = ref ([] : gc_call list) + +let emit_call_gc gc = + `{emit_label gc.gc_lbl}: call _caml_call_gc\n`; + `{emit_label gc.gc_frame}: jmp {emit_label gc.gc_return_lbl}\n` + +(* Record calls to caml_ml_array_bound_error. + In -g mode, we maintain one call to caml_ml_array_bound_error + per bound check site. Without -g, we can share a single call. *) + +type bound_error_call = + { bd_lbl: label; (* Entry label *) + bd_frame: label } (* Label of frame descriptor *) + +let bound_error_sites = ref ([] : bound_error_call list) +let bound_error_call = ref 0 + +let bound_error_label dbg = + if !Clflags.debug then begin + let lbl_bound_error = new_label() in + let lbl_frame = record_frame_label Reg.Set.empty dbg in + bound_error_sites := + { bd_lbl = lbl_bound_error; bd_frame = lbl_frame } :: !bound_error_sites; + lbl_bound_error + end else begin + if !bound_error_call = 0 then bound_error_call := new_label(); + !bound_error_call + end + +let emit_call_bound_error bd = + `{emit_label bd.bd_lbl}: call _caml_ml_array_bound_error\n`; + `{emit_label bd.bd_frame}:\n` + +let emit_call_bound_errors () = + List.iter emit_call_bound_error !bound_error_sites; + if !bound_error_call > 0 then + `{emit_label !bound_error_call}: call _caml_ml_array_bound_error\n` + +(* Names for instructions *) + +let instr_for_intop = function + Iadd -> "add" + | Isub -> "sub" + | Imul -> "imul" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "sal" + | Ilsr -> "shr" + | Iasr -> "sar" + | _ -> fatal_error "Emit: instr_for_intop" + +let instr_for_floatop = function + Inegf -> "fchs" + | Iabsf -> "fabs" + | Iaddf -> "fadd" + | Isubf -> "fsub" + | Imulf -> "fmul" + | Idivf -> "fdiv" + | Ispecific Isubfrev -> "fsubr" + | Ispecific Idivfrev -> "fdivr" + | _ -> fatal_error "Emit: instr_for_floatop" + +let instr_for_floatop_reversed = function + Iaddf -> "fadd" + | Isubf -> "fsubr" + | Imulf -> "fmul" + | Idivf -> "fdivr" + | Ispecific Isubfrev -> "fsub" + | Ispecific Idivfrev -> "fdiv" + | _ -> fatal_error "Emit: instr_for_floatop_reversed" + +let instr_for_floatarithmem = function + Ifloatadd -> "fadd" + | Ifloatsub -> "fsub" + | Ifloatsubrev -> "fsubr" + | Ifloatmul -> "fmul" + | Ifloatdiv -> "fdiv" + | Ifloatdivrev -> "fdivr" + +let name_for_cond_branch = function + Isigned Ceq -> "e" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "g" + | Isigned Clt -> "l" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "be" | Iunsigned Cgt -> "a" + | Iunsigned Clt -> "b" | Iunsigned Cge -> "ae" + +(* Output an = 0 or <> 0 test. *) + +let output_test_zero arg = + match arg.loc with + Reg r -> ` test {emit_reg arg}, {emit_reg arg}\n` + | _ -> ` cmp {emit_reg arg}, 0\n` + +(* Deallocate the stack frame before a return or tail call *) + +let output_epilogue () = + let n = frame_size() - 4 in + if n > 0 then ` add esp, {emit_int n}\n` + +(* Determine if the given register is the top of the floating-point stack *) + +let is_tos = function { loc = Reg _; typ = Float } -> true | _ -> false + +(* Emit the code for a floating-point comparison *) + +let emit_float_test cmp neg arg lbl = + let actual_cmp = + match (is_tos arg.(0), is_tos arg.(1)) with + (true, true) -> + (* both args on top of FP stack *) + ` fcompp\n`; + cmp + | (true, false) -> + (* first arg on top of FP stack *) + ` fcomp {emit_reg arg.(1)}\n`; + cmp + | (false, true) -> + (* second arg on top of FP stack *) + ` fcomp {emit_reg arg.(0)}\n`; + Cmm.swap_comparison cmp + | (false, false) -> + ` fld {emit_reg arg.(0)}\n`; + ` fcomp {emit_reg arg.(1)}\n`; + cmp + in + ` fnstsw ax\n`; + begin match actual_cmp with + Ceq -> + if neg then begin + ` and ah, 68\n`; + ` xor ah, 64\n`; + ` jne ` + end else begin + ` and ah, 69\n`; + ` cmp ah, 64\n`; + ` je ` + end + | Cne -> + if neg then begin + ` and ah, 69\n`; + ` cmp ah, 64\n`; + ` je ` + end else begin + ` and ah, 68\n`; + ` xor ah, 64\n`; + ` jne ` + end + | Cle -> + ` and ah, 69\n`; + ` dec ah\n`; + ` cmp ah, 64\n`; + if neg + then ` jae ` + else ` jb ` + | Cge -> + ` and ah, 5\n`; + if neg + then ` jne ` + else ` je ` + | Clt -> + ` and ah, 69\n`; + ` cmp ah, 1\n`; + if neg + then ` jne ` + else ` je ` + | Cgt -> + ` and ah, 69\n`; + if neg + then ` jne ` + else ` je ` + end; + `{emit_label lbl}\n` + +(* Emit a Ifloatspecial instruction *) + +let emit_floatspecial = function + "atan" -> ` fld1\n\tfpatan\n` + | "atan2" -> ` fpatan\n` + | "cos" -> ` fcos\n` + | "log" -> ` fldln2\n\tfxch\n\tfyl2x\n` + | "log10" -> ` fldlg2\n\tfxch\n\tfyl2x\n` + | "sin" -> ` fsin\n` + | "sqrt" -> ` fsqrt\n` + | "tan" -> ` fptan\n\tfstp st(0)\n` + | _ -> assert false + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Label of trap for out-of-range accesses *) +let range_check_trap = ref 0 + +let float_constants = ref ([] : (int * string) list) + +let emit_instr i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + if src.typ = Float then + if is_tos src then + ` fstp {emit_reg dst}\n` + else if is_tos dst then + ` fld {emit_reg dst}\n` + else begin + ` fld {emit_reg src}\n`; + ` fstp {emit_reg dst}\n` + end + else + ` mov {emit_reg dst}, {emit_reg src}\n` + end + | Lop(Iconst_int n) -> + if n = 0n then begin + match i.res.(0).loc with + Reg n -> ` xor {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | _ -> ` mov {emit_reg i.res.(0)}, 0\n` + end else + ` mov {emit_reg i.res.(0)}, {emit_nativeint n}\n` + | Lop(Iconst_float s) -> + begin match Int64.bits_of_float (float_of_string s) with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + ` fldz\n` + | 0x8000_0000_0000_0000L -> (* -0.0 *) + ` fldz\n fchs\n` + | 0x3FF0_0000_0000_0000L -> (* 1.0 *) + ` fld1\n` + | 0xBFF0_0000_0000_0000L -> (* -1.0 *) + ` fld1\n fchs\n` + | _ -> + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` fld {emit_label lbl}\n` + end + | Lop(Iconst_symbol s) -> + add_used_symbol s; + ` mov {emit_reg i.res.(0)}, OFFSET {emit_symbol s}\n` + | Lop(Icall_ind) -> + ` call {emit_reg i.arg.(0)}\n`; + record_frame i.live i.dbg + | Lop(Icall_imm s) -> + add_used_symbol s; + ` call {emit_symbol s}\n`; + record_frame i.live i.dbg + | Lop(Itailcall_ind) -> + output_epilogue(); + ` jmp {emit_reg i.arg.(0)}\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then + ` jmp {emit_label !tailrec_entry_point}\n` + else begin + output_epilogue(); + add_used_symbol s; + ` jmp {emit_symbol s}\n` + end + | Lop(Iextcall(s, alloc)) -> + add_used_symbol s ; + if alloc then begin + ` mov eax, OFFSET {emit_symbol s}\n`; + ` call _caml_c_call\n`; + record_frame i.live i.dbg + end else begin + ` call {emit_symbol s}\n` + end + | Lop(Istackoffset n) -> + if n >= 0 + then ` sub esp, {emit_int n}\n` + else ` add esp, {emit_int(-n)}\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + | Word | Thirtytwo_signed | Thirtytwo_unsigned -> + ` mov {emit_reg dest}, DWORD PTR {emit_addressing addr i.arg 0}\n` + | Byte_unsigned -> + ` movzx {emit_reg dest}, BYTE PTR {emit_addressing addr i.arg 0}\n` + | Byte_signed -> + ` movsx {emit_reg dest}, BYTE PTR {emit_addressing addr i.arg 0}\n` + | Sixteen_unsigned -> + ` movzx {emit_reg dest}, WORD PTR {emit_addressing addr i.arg 0}\n` + | Sixteen_signed -> + ` movsx {emit_reg dest}, WORD PTR {emit_addressing addr i.arg 0}\n` + | Single -> + ` fld REAL4 PTR {emit_addressing addr i.arg 0}\n` + | Double | Double_u -> + ` fld REAL8 PTR {emit_addressing addr i.arg 0}\n` + end + | Lop(Istore(chunk, addr)) -> + begin match chunk with + | Word | Thirtytwo_signed | Thirtytwo_unsigned -> + ` mov DWORD PTR {emit_addressing addr i.arg 1}, {emit_reg i.arg.(0)}\n` + | Byte_unsigned | Byte_signed -> + ` mov BYTE PTR {emit_addressing addr i.arg 1}, {emit_reg8 i.arg.(0)}\n` + | Sixteen_unsigned | Sixteen_signed -> + ` mov WORD PTR {emit_addressing addr i.arg 1}, {emit_reg16 i.arg.(0)}\n` + | Single -> + if is_tos i.arg.(0) then + ` fstp REAL4 PTR {emit_addressing addr i.arg 1}\n` + else begin + ` fld {emit_reg i.arg.(0)}\n`; + ` fstp REAL4 PTR {emit_addressing addr i.arg 1}\n` + end + | Double | Double_u -> + if is_tos i.arg.(0) then + ` fstp REAL8 PTR {emit_addressing addr i.arg 1}\n` + else begin + ` fld {emit_reg i.arg.(0)}\n`; + ` fstp REAL8 PTR {emit_addressing addr i.arg 1}\n` + end + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_redo = new_label() in + `{emit_label lbl_redo}: mov eax, _caml_young_ptr\n`; + ` sub eax, {emit_int n}\n`; + ` mov _caml_young_ptr, eax\n`; + ` cmp eax, _caml_young_limit\n`; + let lbl_call_gc = new_label() in + let lbl_frame = record_frame_label i.live Debuginfo.none in + ` jb {emit_label lbl_call_gc}\n`; + ` lea {emit_reg i.res.(0)}, [eax+4]\n`; + call_gc_sites := + { gc_lbl = lbl_call_gc; + gc_return_lbl = lbl_redo; + gc_frame = lbl_frame } :: !call_gc_sites + end else begin + begin match n with + 8 -> ` call _caml_alloc1\n` + | 12 -> ` call _caml_alloc2\n` + | 16 -> ` call _caml_alloc3\n` + | _ -> ` mov eax, {emit_int n}\n`; + ` call _caml_allocN\n` + end; + `{record_frame i.live Debuginfo.none} lea {emit_reg i.res.(0)}, [eax+4]\n` + end + | Lop(Iintop(Icomp cmp)) -> + ` cmp {emit_reg i.arg.(0)},{emit_reg i.arg.(1)}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} al\n`; + ` movzx {emit_reg i.res.(0)}, al\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + let b = name_for_cond_branch cmp in + ` set{emit_string b} al\n`; + ` movzx {emit_reg i.res.(0)}, al\n` + | Lop(Iintop Icheckbound) -> + let lbl = bound_error_label i.dbg in + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + let lbl = bound_error_label i.dbg in + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + ` jbe {emit_label lbl}\n` + | Lop(Iintop(Idiv | Imod)) -> + ` cdq\n`; + ` idiv {emit_reg i.arg.(1)}\n` + | Lop(Iintop(Ilsl | Ilsr | Iasr as op)) -> + (* We have i.arg.(0) = i.res.(0) and i.arg.(1) = %ecx *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, cl\n` + | Lop(Iintop op) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Iintop_imm(Iadd, n)) when i.arg.(0).loc <> i.res.(0).loc -> + ` lea {emit_reg i.res.(0)}, [{emit_reg i.arg.(0)}+{emit_int n}]\n` + | Lop(Iintop_imm(Iadd, 1) | Iintop_imm(Isub, -1)) -> + ` inc {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Iadd, -1) | Iintop_imm(Isub, 1)) -> + ` dec {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + let l = Misc.log2 n in + let lbl = new_label() in + output_test_zero i.arg.(0); + ` jge {emit_label lbl}\n`; + ` add {emit_reg i.arg.(0)}, {emit_int(n-1)}\n`; + `{emit_label lbl}: sar {emit_reg i.arg.(0)}, {emit_int l}\n` + | Lop(Iintop_imm(Imod, n)) -> + let lbl = new_label() in + ` mov eax, {emit_reg i.arg.(0)}\n`; + ` test eax, eax\n`; + ` jge {emit_label lbl}\n`; + ` add eax, {emit_int(n-1)}\n`; + `{emit_label lbl}: and eax, {emit_int(-n)}\n`; + ` sub {emit_reg i.arg.(0)}, eax\n` + | Lop(Iintop_imm(op, n)) -> + (* We have i.arg.(0) = i.res.(0) *) + ` {emit_string(instr_for_intop op)} {emit_reg i.res.(0)}, {emit_int n}\n` + | Lop(Inegf | Iabsf as floatop) -> + if not (is_tos i.arg.(0)) then + ` fld {emit_reg i.arg.(0)}\n`; + ` {emit_string(instr_for_floatop floatop)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf | Ispecific(Isubfrev | Idivfrev) + as floatop) -> + begin match (is_tos i.arg.(0), is_tos i.arg.(1)) with + (true, true) -> + (* both operands on top of FP stack *) + ` {emit_string(instr_for_floatop_reversed floatop)}\n` + | (true, false) -> + (* first operand on stack *) + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}\n` + | (false, true) -> + (* second operand on stack *) + ` {emit_string(instr_for_floatop_reversed floatop)} {emit_reg i.arg.(0)}\n` + | (false, false) -> + (* both operands in memory *) + ` fld {emit_reg i.arg.(0)}\n`; + ` {emit_string(instr_for_floatop floatop)} {emit_reg i.arg.(1)}\n` + end + | Lop(Ifloatofint) -> + begin match i.arg.(0).loc with + Stack s -> + ` fild {emit_reg i.arg.(0)}\n` + | _ -> + ` push {emit_reg i.arg.(0)}\n`; + ` fild DWORD PTR [esp]\n`; + ` add esp, 4\n` + end + | Lop(Iintoffloat) -> + if not (is_tos i.arg.(0)) then + ` fld {emit_reg i.arg.(0)}\n`; + stack_offset := !stack_offset - 8; + ` sub esp, 8\n`; + ` fnstcw [esp+4]\n`; + ` mov ax, [esp+4]\n`; + ` mov ah, 12\n`; + ` mov [esp], ax\n`; + ` fldcw [esp]\n`; + begin match i.res.(0).loc with + Stack s -> + ` fistp {emit_reg i.res.(0)}\n` + | _ -> + ` fistp DWORD PTR [esp]\n`; + ` mov {emit_reg i.res.(0)}, [esp]\n` + end; + ` fldcw [esp+4]\n`; + ` add esp, 8\n`; + stack_offset := !stack_offset + 8 + | Lop(Ispecific(Ilea addr)) -> + ` lea {emit_reg i.res.(0)}, DWORD PTR {emit_addressing addr i.arg 0}\n` + | Lop(Ispecific(Istore_int(n, addr))) -> + ` mov DWORD PTR {emit_addressing addr i.arg 0},{emit_nativeint n}\n` + | Lop(Ispecific(Istore_symbol(s, addr))) -> + add_used_symbol s ; + ` mov DWORD PTR {emit_addressing addr i.arg 0},OFFSET {emit_symbol s}\n` + | Lop(Ispecific(Ioffset_loc(n, addr))) -> + ` add DWORD PTR {emit_addressing addr i.arg 0},{emit_int n}\n` + | Lop(Ispecific(Ipush)) -> + (* Push arguments in reverse order *) + for n = Array.length i.arg - 1 downto 0 do + let r = i.arg.(n) in + match r with + {loc = Reg rn; typ = Float} -> + ` sub esp, 8\n`; + ` fstp REAL8 PTR 0[esp]\n`; + stack_offset := !stack_offset + 8 + | {loc = Stack sl; typ = Float} -> + let ofs = slot_offset sl 1 in + ` push DWORD PTR {emit_int (ofs + 4)}[esp]\n`; + ` push DWORD PTR {emit_int (ofs + 4)}[esp]\n`; + stack_offset := !stack_offset + 8 + | _ -> + ` push {emit_reg r}\n`; + stack_offset := !stack_offset + 4 + done + | Lop(Ispecific(Ipush_int n)) -> + ` push {emit_nativeint n}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_symbol s)) -> + add_used_symbol s; + ` push OFFSET {emit_symbol s}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_load addr)) -> + ` push DWORD PTR {emit_addressing addr i.arg 0}\n`; + stack_offset := !stack_offset + 4 + | Lop(Ispecific(Ipush_load_float addr)) -> + ` push DWORD PTR {emit_addressing (offset_addressing addr 4) i.arg 0}\n`; + ` push DWORD PTR {emit_addressing addr i.arg 0}\n`; + stack_offset := !stack_offset + 8 + | Lop(Ispecific(Ifloatarithmem(double, op, addr))) -> + if not (is_tos i.arg.(0)) then + ` fld {emit_reg i.arg.(0)}\n`; + let size = if double then "REAL8" else "REAL4" in + ` {emit_string(instr_for_floatarithmem op)} {emit_string size} PTR {emit_addressing addr i.arg 1}\n` + | Lop(Ispecific(Ifloatspecial s)) -> + (* Push args on float stack if necessary *) + for k = 0 to Array.length i.arg - 1 do + if not (is_tos i.arg.(k)) then ` fld {emit_reg i.arg.(k)}\n` + done; + (* Fix-up for binary instrs whose args were swapped *) + if Array.length i.arg = 2 && is_tos i.arg.(1) then + ` fxch st(1)\n`; + emit_floatspecial s + | Lreloadretaddr -> + () + | Lreturn -> + output_epilogue(); + ` ret\n` + | Llabel lbl -> + `{emit_label lbl}:\n` + | Lbranch lbl -> + ` jmp {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + output_test_zero i.arg.(0); + ` jne {emit_label lbl}\n` + | Ifalsetest -> + output_test_zero i.arg.(0); + ` je {emit_label lbl}\n` + | Iinttest cmp -> + ` cmp {emit_reg i.arg.(0)},{emit_reg i.arg.(1)}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm((Isigned Ceq | Isigned Cne | + Iunsigned Ceq | Iunsigned Cne) as cmp, 0) -> + output_test_zero i.arg.(0); + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + let b = name_for_cond_branch cmp in + ` j{emit_string b} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + emit_float_test cmp neg i.arg lbl + | Ioddtest -> + ` test {emit_reg i.arg.(0)}, 1\n`; + ` jne {emit_label lbl}\n` + | Ieventest -> + ` test {emit_reg i.arg.(0)}, 1\n`; + ` je {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmp {emit_reg i.arg.(0)}, 1\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` jb {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` je {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` jg {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl = new_label() in + ` jmp [{emit_reg i.arg.(0)} * 4 + {emit_label lbl}]\n`; + ` .DATA\n`; + `{emit_label lbl}`; + for i = 0 to Array.length jumptbl - 1 do + ` DWORD {emit_label jumptbl.(i)}\n` + done; + ` .CODE\n` + | Lsetuptrap lbl -> + ` call {emit_label lbl}\n` + | Lpushtrap -> + ` push _caml_exception_pointer\n`; + ` mov _caml_exception_pointer, esp\n`; + stack_offset := !stack_offset + 8 + | Lpoptrap -> + ` pop _caml_exception_pointer\n`; + ` add esp, 4\n`; + stack_offset := !stack_offset - 8 + | Lraise -> + if !Clflags.debug then begin + ` call _caml_raise_exn\n`; + record_frame Reg.Set.empty i.dbg + end else begin + ` mov esp, _caml_exception_pointer\n`; + ` pop _caml_exception_pointer\n`; + ` ret\n` + end + +let rec emit_all i = + match i.desc with Lend -> () | _ -> emit_instr i; emit_all i.next + +(* Emission of the floating-point constants *) + +let emit_float s = + (* MASM doesn't like floating-point constants such as 2e9. + Turn them into 2.0e9. *) + let pos_e = ref (-1) and pos_dot = ref (-1) in + for i = 0 to String.length s - 1 do + match s.[i] with + 'e'|'E' -> pos_e := i + | '.' -> pos_dot := i + | _ -> () + done; + if !pos_dot < 0 && !pos_e >= 0 then begin + emit_string (String.sub s 0 !pos_e); + emit_string ".0"; + emit_string (String.sub s !pos_e (String.length s - !pos_e)) + end else + emit_string s + +let emit_float_constant (lbl, cst) = + `{emit_label lbl} REAL8 {emit_float cst}\n` + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + stack_offset := 0; + float_constants := []; + call_gc_sites := []; + bound_error_sites := []; + bound_error_call := 0; + ` .CODE\n`; + add_def_symbol fundecl.fun_name; + emit_align 4; + ` PUBLIC {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + let n = frame_size() - 4 in + if n > 0 then + ` sub esp, {emit_int n}\n`; + `{emit_label !tailrec_entry_point}:\n`; + emit_all fundecl.fun_body; + List.iter emit_call_gc !call_gc_sites; + emit_call_bound_errors (); + begin match !float_constants with + [] -> () + | _ -> + ` .DATA\n`; + List.iter emit_float_constant !float_constants; + float_constants := [] + end + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` PUBLIC {emit_symbol s}\n`; + | Cdefine_symbol s -> + add_def_symbol s ; + `{emit_symbol s} LABEL DWORD\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)} ` + | Cint8 n -> + ` BYTE {emit_int n}\n` + | Cint16 n -> + ` WORD {emit_int n}\n` + | Cint n -> + ` DWORD {emit_nativeint n}\n` + | Cint32 n -> + ` DWORD {emit_nativeint n}\n` + | Csingle f -> + ` REAL4 {emit_float f}\n` + | Cdouble f -> + ` REAL8 {emit_float f}\n` + | Csymbol_address s -> + add_used_symbol s ; + ` DWORD {emit_symbol s}\n` + | Clabel_address lbl -> + ` DWORD {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_bytes_directive " BYTE " s + | Cskip n -> + if n > 0 then ` BYTE {emit_int n} DUP (?)\n` + | Calign n -> + emit_align n + +let data l = + ` .DATA\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + `.386\n`; + ` .MODEL FLAT\n\n`; + ` EXTERN _caml_young_ptr: DWORD\n`; + ` EXTERN _caml_young_limit: DWORD\n`; + ` EXTERN _caml_exception_pointer: DWORD\n`; + ` EXTERN _caml_extra_params: DWORD\n`; + ` EXTERN _caml_call_gc: PROC\n`; + ` EXTERN _caml_c_call: PROC\n`; + ` EXTERN _caml_allocN: PROC\n`; + ` EXTERN _caml_alloc1: PROC\n`; + ` EXTERN _caml_alloc2: PROC\n`; + ` EXTERN _caml_alloc3: PROC\n`; + ` EXTERN _caml_ml_array_bound_error: PROC\n`; + ` EXTERN _caml_raise_exn: PROC\n`; + ` .DATA\n`; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + add_def_symbol lbl_begin; + ` PUBLIC {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin} LABEL DWORD\n`; + ` .CODE\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + add_def_symbol lbl_begin; + ` PUBLIC {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin} LABEL DWORD\n` + +let end_assembly() = + ` .CODE\n`; + let lbl_end = Compilenv.make_symbol (Some "code_end") in + add_def_symbol lbl_end; + ` PUBLIC {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end} LABEL DWORD\n`; + ` .DATA\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + add_def_symbol lbl_end; + ` PUBLIC {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end} LABEL DWORD\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + add_def_symbol lbl; + ` PUBLIC {emit_symbol lbl}\n`; + `{emit_symbol lbl}`; + emit_frames + { efa_label = (fun l -> ` DWORD {emit_label l}\n`); + efa_16 = (fun n -> ` WORD {emit_int n}\n`); + efa_32 = (fun n -> ` DWORD {emit_int32 n}\n`); + efa_word = (fun n -> ` DWORD {emit_int n}\n`); + efa_align = emit_align; + efa_label_rel = (fun lbl ofs -> + ` DWORD {emit_label lbl} - THIS BYTE + {emit_int32 ofs}\n`); + efa_def_label = (fun l -> `{emit_label l} LABEL DWORD\n`); + efa_string = (fun s -> emit_bytes_directive " BYTE " (s ^ "\000")) }; + `\n;External functions\n\n`; + StringSet.iter + (fun s -> + if not (StringSet.mem s !symbols_defined) then + ` EXTERN {emit_symbol s}: PROC\n`) + !symbols_used; + symbols_used := StringSet.empty; + symbols_defined := StringSet.empty; + `END\n` diff --git a/asmcomp/i386/proc.ml b/asmcomp/i386/proc.ml new file mode 100644 index 0000000..d399b61 --- /dev/null +++ b/asmcomp/i386/proc.ml @@ -0,0 +1,188 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.14 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the Intel 386 processor *) + +open Misc +open Arch +open Cmm +open Reg +open Mach + +(* Registers available for register allocation *) + +(* Register map: + eax 0 eax - edi: function arguments and results + ebx 1 eax: C function results + ecx 2 ebx, esi, edi, ebp: preserved by C + edx 3 + esi 4 + edi 5 + ebp 6 + + tos 100 top of floating-point stack. *) + +let int_reg_name = + [| "%eax"; "%ebx"; "%ecx"; "%edx"; "%esi"; "%edi"; "%ebp" |] + +let float_reg_name = + [| "%tos" |] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 7; 0 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +(* There is little scheduling, and some operations are more compact + when their argument is %eax. *) + +let rotate_registers = false + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 7 Reg.dummy in + for i = 0 to 6 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = [| Reg.at_location Float (Reg 100) |] + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let eax = phys_reg 0 +let ecx = phys_reg 2 +let edx = phys_reg 3 +let tos = phys_reg 100 + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Instruction selection *) + +let word_addressed = false + +(* Calling conventions *) + +(* To supplement the processor's meagre supply of registers, we also + use some global memory locations to pass arguments beyond the 6th. + These globals are denoted by Incoming and Outgoing stack locations + with negative offsets, starting at -64. + Unlike arguments passed on stack, arguments passed in globals + do not prevent tail-call elimination. The caller stores arguments + in these globals immediately before the call, and the first thing the + callee does is copy them to registers or stack locations. + Neither GC nor thread context switches can occur between these two + times. *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref (-64) in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align (max 0 !ofs) stack_alignment) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 5 100 99 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 5 100 99 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 5 100 100 not_supported res in loc +let extcall_use_push = true +let loc_external_arguments arg = + fatal_error "Proc.loc_external_arguments" +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = eax + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* ebx, esi, edi, ebp preserved *) + [|eax; ecx; edx|] + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Iintop(Idiv | Imod)) -> [| eax; edx |] + | Iop(Iintop_imm(Imod, _)) -> [| eax |] + | Iop(Ialloc _) -> [| eax |] + | Iop(Iintop(Icomp _) | Iintop_imm(Icomp _, _)) -> [| eax |] + | Iop(Iintoffloat) -> [| eax |] + | Iifthenelse(Ifloattest(_, _), _, _) -> [| eax |] + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure op = 4 + +let max_register_pressure = function + Iextcall(_, _) -> [| 4; max_int |] + | Iintop(Idiv | Imod) -> [| 5; max_int |] + | Ialloc _ | Iintop(Icomp _) | Iintop_imm(Icomp _, _) | + Iintoffloat -> [| 6; max_int |] + | _ -> [|7; max_int |] + +(* Layout of the stack frame *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/i386/proc_nt.ml b/asmcomp/i386/proc_nt.ml new file mode 100644 index 0000000..17ea56e --- /dev/null +++ b/asmcomp/i386/proc_nt.ml @@ -0,0 +1,186 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc_nt.ml,v 1.8 2008-01-11 16:13:11 doligez Exp $ *) + +(* Description of the Intel 386 processor, for Windows NT *) + +open Misc +open Arch +open Cmm +open Reg +open Mach + +(* Registers available for register allocation *) + +(* Register map: + eax 0 eax - edi: function arguments and results + ebx 1 eax: C function results + ecx 2 ebx, esi, edi, ebp: preserved by C + edx 3 + esi 4 + edi 5 + ebp 6 + + tos 100 top of floating-point stack. *) + +let int_reg_name = + [| "eax"; "ebx"; "ecx"; "edx"; "esi"; "edi"; "ebp" |] + +let float_reg_name = + [| "tos" |] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 7; 0 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +(* There is little scheduling, and some operations are more compact + when their argument is %eax. *) + +let rotate_registers = false + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 7 Reg.dummy in + for i = 0 to 6 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = [| Reg.at_location Float (Reg 100) |] + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let eax = phys_reg 0 +let ecx = phys_reg 2 +let edx = phys_reg 3 +let tos = phys_reg 100 + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Instruction selection *) + +let word_addressed = false + +(* Calling conventions *) + +(* To supplement the processor's meagre supply of registers, we also + use some global memory locations to pass arguments beyond the 6th. + These globals are denoted by Incoming and Outgoing stack locations + with negative offsets, starting at -64. + Unlike arguments passed on stack, arguments passed in globals + do not prevent tail-call elimination. The caller stores arguments + in these globals immediately before the call, and the first thing the + callee does is copy them to registers or stack locations. + Neither GC nor thread context switches can occur between these two + times. *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref (-64) in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, max 0 !ofs) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 5 100 99 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 5 100 99 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 5 100 100 not_supported res in loc +let extcall_use_push = true +let loc_external_arguments arg = + fatal_error "Proc.loc_external_arguments" +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = eax + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* ebx, esi, edi, ebp preserved *) + Array.of_list(List.map phys_reg [0;2;3]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | Iop(Iintop(Idiv | Imod)) -> [| eax; edx |] + | Iop(Iintop_imm(Imod, _)) -> [| eax |] + | Iop(Ialloc _) -> [| eax |] + | Iop(Iintop(Icomp _) | Iintop_imm(Icomp _, _)) -> [| eax |] + | Iop(Iintoffloat) -> [| eax |] + | Iifthenelse(Ifloattest(_, _), _, _) -> [| eax |] + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure op = 4 + +let max_register_pressure = function + Iextcall(_, _) -> [| 4; max_int |] + | Iintop(Idiv | Imod) -> [| 5; max_int |] + | Ialloc _ | Iintop(Icomp _) | Iintop_imm(Icomp _, _) | + Iintoffloat -> [| 6; max_int |] + | _ -> [|7; max_int |] + +(* Layout of the stack frame *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ + Filename.quote outfile ^ " " ^ Filename.quote infile ^ + (if !Clflags.verbose then "" else ">NUL")) diff --git a/asmcomp/i386/reload.ml b/asmcomp/i386/reload.ml new file mode 100644 index 0000000..21dbd49 --- /dev/null +++ b/asmcomp/i386/reload.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.6 2007-01-29 12:10:50 xleroy Exp $ *) + +open Cmm +open Arch +open Reg +open Mach + +(* Reloading for the Intel x86 *) + +let stackp r = + match r.loc with + Stack _ -> true + | _ -> false + +class reload = object (self) + +inherit Reloadgen.reload_generic as super + +method makereg r = + match r.typ with + Float -> r + | _ -> super#makereg r + +(* By overriding makereg, we make sure that pseudoregs of type float + will never be reloaded. Hence there is no need to make special cases for + floating-point operations. *) + +method reload_operation op arg res = + match op with + Iintop(Iadd|Isub|Iand|Ior|Ixor|Icomp _|Icheckbound) -> + (* One of the two arguments can reside in the stack *) + if stackp arg.(0) && stackp arg.(1) + then ([|arg.(0); self#makereg arg.(1)|], res) + else (arg, res) + | Iintop(Imul) -> + (* First argument (and destination) must be in register, + second arg can reside in stack *) + if stackp arg.(0) + then let r = self#makereg arg.(0) in ([|r; arg.(1)|], [|r|]) + else (arg, res) + | Iintop_imm(Iadd, _) when arg.(0).loc <> res.(0).loc -> + (* This add will be turned into a lea; args and results must be + in registers *) + super#reload_operation op arg res + | Iintop_imm(Imul, _) -> + (* First argument and destination must be in register *) + if stackp arg.(0) + then let r = self#makereg arg.(0) in ([|r|], [|r|]) + else (arg, res) + | Iintop(Ilsl|Ilsr|Iasr) | Iintop_imm(_, _) | Ifloatofint | Iintoffloat | + Ispecific(Ipush) -> + (* The argument(s) can be either in register or on stack *) + (arg, res) + | _ -> (* Other operations: all args and results in registers *) + super#reload_operation op arg res + +method reload_test tst arg = + match tst with + Iinttest cmp -> + (* One of the two arguments can reside on stack *) + if stackp arg.(0) && stackp arg.(1) + then [| self#makereg arg.(0); arg.(1) |] + else arg + | _ -> + (* The argument(s) can be either in register or on stack *) + arg + +end + +let fundecl f = + (new reload)#fundecl f diff --git a/asmcomp/i386/scheduling.ml b/asmcomp/i386/scheduling.ml new file mode 100644 index 0000000..1d204d8 --- /dev/null +++ b/asmcomp/i386/scheduling.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.3 2000-02-04 12:43:18 xleroy Exp $ *) + +open Schedgen (* to create a dependency *) + +(* Scheduling is turned off because our model does not fit the 486 + nor the Pentium very well. In particular, it messes up with the + float reg stack. The Pentiums Pro / II / III / etc schedule + at run-time much better than what we could do. *) + +let fundecl f = f diff --git a/asmcomp/i386/selection.ml b/asmcomp/i386/selection.ml new file mode 100644 index 0000000..aec462d --- /dev/null +++ b/asmcomp/i386/selection.ml @@ -0,0 +1,327 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.15 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Instruction selection for the Intel x86 *) + +open Misc +open Arch +open Proc +open Cmm +open Reg +open Mach + +(* Auxiliary for recognizing addressing modes *) + +type addressing_expr = + Asymbol of string + | Alinear of expression + | Aadd of expression * expression + | Ascale of expression * int + | Ascaledadd of expression * expression * int + +let rec select_addr exp = + match exp with + Cconst_symbol s -> + (Asymbol s, 0) + | Cop((Caddi | Cadda), [arg; Cconst_int m]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop((Csubi | Csuba), [arg; Cconst_int m]) -> + let (a, n) = select_addr arg in (a, n - m) + | Cop((Caddi | Cadda), [Cconst_int m; arg]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop(Clsl, [arg; Cconst_int(1|2|3 as shift)]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, 1 lsl shift), n lsl shift) + | _ -> (Alinear exp, 0) + end + | Cop(Cmuli, [arg; Cconst_int(2|4|8 as mult)]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, mult), n * mult) + | _ -> (Alinear exp, 0) + end + | Cop(Cmuli, [Cconst_int(2|4|8 as mult); arg]) -> + begin match select_addr arg with + (Alinear e, n) -> (Ascale(e, mult), n * mult) + | _ -> (Alinear exp, 0) + end + | Cop((Caddi | Cadda), [arg1; arg2]) -> + begin match (select_addr arg1, select_addr arg2) with + ((Alinear e1, n1), (Alinear e2, n2)) -> + (Aadd(e1, e2), n1 + n2) + | ((Alinear e1, n1), (Ascale(e2, scale), n2)) -> + (Ascaledadd(e1, e2, scale), n1 + n2) + | ((Ascale(e1, scale), n1), (Alinear e2, n2)) -> + (Ascaledadd(e2, e1, scale), n1 + n2) + | (_, (Ascale(e2, scale), n2)) -> + (Ascaledadd(arg1, e2, scale), n2) + | ((Ascale(e1, scale), n1), _) -> + (Ascaledadd(arg2, e1, scale), n1) + | _ -> + (Aadd(arg1, arg2), 0) + end + | arg -> + (Alinear arg, 0) + +(* C functions to be turned into Ifloatspecial instructions if -ffast-math *) + +let inline_float_ops = + ["atan"; "atan2"; "cos"; "log"; "log10"; "sin"; "sqrt"; "tan"] + +(* Estimate number of float temporaries needed to evaluate expression + (Ershov's algorithm) *) + +let rec float_needs = function + Cop((Cnegf | Cabsf), [arg]) -> + float_needs arg + | Cop((Caddf | Csubf | Cmulf | Cdivf), [arg1; arg2]) -> + let n1 = float_needs arg1 in + let n2 = float_needs arg2 in + if n1 = n2 then 1 + n1 else if n1 > n2 then n1 else n2 + | Cop(Cextcall(fn, ty_res, alloc, dbg), args) + when !fast_math && List.mem fn inline_float_ops -> + begin match args with + [arg] -> float_needs arg + | [arg1; arg2] -> max (float_needs arg2 + 1) (float_needs arg1) + | _ -> assert false + end + | _ -> + 1 + +(* Special constraints on operand and result registers *) + +exception Use_default + +let eax = phys_reg 0 +let ecx = phys_reg 2 +let edx = phys_reg 3 +let tos = phys_reg 100 + +let pseudoregs_for_operation op arg res = + match op with + (* Two-address binary operations *) + Iintop(Iadd|Isub|Imul|Iand|Ior|Ixor) -> + ([|res.(0); arg.(1)|], res, false) + (* Two-address unary operations *) + | Iintop_imm((Iadd|Isub|Imul|Idiv|Iand|Ior|Ixor|Ilsl|Ilsr|Iasr), _) -> + (res, res, false) + (* For shifts with variable shift count, second arg must be in ecx *) + | Iintop(Ilsl|Ilsr|Iasr) -> + ([|res.(0); ecx|], res, false) + (* For div and mod, first arg must be in eax, edx is clobbered, + and result is in eax or edx respectively. + Keep it simple, just force second argument in ecx. *) + | Iintop(Idiv) -> + ([| eax; ecx |], [| eax |], true) + | Iintop(Imod) -> + ([| eax; ecx |], [| edx |], true) + (* For mod with immediate operand, arg must not be in eax. + Keep it simple, force it in edx. *) + | Iintop_imm(Imod, _) -> + ([| edx |], [| edx |], true) + (* For floating-point operations and floating-point loads, + the result is always left at the top of the floating-point stack *) + | Iconst_float _ | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf + | Ifloatofint | Iload((Single | Double | Double_u), _) + | Ispecific(Isubfrev | Idivfrev | Ifloatarithmem(_, _, _) | Ifloatspecial _) -> + (arg, [| tos |], false) (* don't move it immediately *) + (* For storing a byte, the argument must be in eax...edx. + (But for a short, any reg will do!) + Keep it simple, just force the argument to be in edx. *) + | Istore((Byte_unsigned | Byte_signed), addr) -> + let newarg = Array.copy arg in + newarg.(0) <- edx; + (newarg, res, false) + (* Other instructions are regular *) + | _ -> raise Use_default + +let chunk_double = function + Single -> false + | Double -> true + | Double_u -> true + | _ -> assert false + +(* The selector class *) + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate (n : int) = true + +method is_simple_expr e = + match e with + | Cop(Cextcall(fn, _, alloc, _), args) + when !fast_math && List.mem fn inline_float_ops -> + (* inlined float ops are simple if their arguments are *) + List.for_all self#is_simple_expr args + | _ -> + super#is_simple_expr e + +method select_addressing exp = + match select_addr exp with + (Asymbol s, d) -> + (Ibased(s, d), Ctuple []) + | (Alinear e, d) -> + (Iindexed d, e) + | (Aadd(e1, e2), d) -> + (Iindexed2 d, Ctuple[e1; e2]) + | (Ascale(e, scale), d) -> + (Iscaled(scale, d), e) + | (Ascaledadd(e1, e2, scale), d) -> + (Iindexed2scaled(scale, d), Ctuple[e1; e2]) + +method select_store addr exp = + match exp with + Cconst_int n -> + (Ispecific(Istore_int(Nativeint.of_int n, addr)), Ctuple []) + | Cconst_natint n -> + (Ispecific(Istore_int(n, addr)), Ctuple []) + | Cconst_pointer n -> + (Ispecific(Istore_int(Nativeint.of_int n, addr)), Ctuple []) + | Cconst_natpointer n -> + (Ispecific(Istore_int(n, addr)), Ctuple []) + | Cconst_symbol s -> + (Ispecific(Istore_symbol(s, addr)), Ctuple []) + | _ -> + super#select_store addr exp + +method select_operation op args = + match op with + (* Recognize the LEA instruction *) + Caddi | Cadda | Csubi | Csuba -> + begin match self#select_addressing (Cop(op, args)) with + (Iindexed d, _) -> super#select_operation op args + | (Iindexed2 0, _) -> super#select_operation op args + | (addr, arg) -> (Ispecific(Ilea addr), [arg]) + end + (* Recognize (x / cst) and (x % cst) only if cst is a power of 2. *) + | Cdivi -> + begin match args with + [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg1]) + | _ -> (Iintop Idiv, args) + end + | Cmodi -> + begin match args with + [arg1; Cconst_int n] when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg1]) + | _ -> (Iintop Imod, args) + end + (* Recognize float arithmetic with memory. + In passing, apply Ershov's algorithm to reduce stack usage *) + | Caddf -> + self#select_floatarith Iaddf Iaddf Ifloatadd Ifloatadd args + | Csubf -> + self#select_floatarith Isubf (Ispecific Isubfrev) Ifloatsub Ifloatsubrev args + | Cmulf -> + self#select_floatarith Imulf Imulf Ifloatmul Ifloatmul args + | Cdivf -> + self#select_floatarith Idivf (Ispecific Idivfrev) Ifloatdiv Ifloatdivrev args + (* Recognize store instructions *) + | Cstore Word -> + begin match args with + [loc; Cop(Caddi, [Cop(Cload _, [loc']); Cconst_int n])] + when loc = loc' -> + let (addr, arg) = self#select_addressing loc in + (Ispecific(Ioffset_loc(n, addr)), [arg]) + | _ -> + super#select_operation op args + end + (* Recognize inlined floating point operations *) + | Cextcall(fn, ty_res, false, dbg) + when !fast_math && List.mem fn inline_float_ops -> + (Ispecific(Ifloatspecial fn), args) + (* Default *) + | _ -> super#select_operation op args + +(* Recognize float arithmetic with mem *) + +method select_floatarith regular_op reversed_op mem_op mem_rev_op args = + match args with + [arg1; Cop(Cload chunk, [loc2])] -> + let (addr, arg2) = self#select_addressing loc2 in + (Ispecific(Ifloatarithmem(chunk_double chunk, mem_op, addr)), + [arg1; arg2]) + | [Cop(Cload chunk, [loc1]); arg2] -> + let (addr, arg1) = self#select_addressing loc1 in + (Ispecific(Ifloatarithmem(chunk_double chunk, mem_rev_op, addr)), + [arg2; arg1]) + | [arg1; arg2] -> + (* Evaluate bigger subexpression first to minimize stack usage. + Because of right-to-left evaluation, rightmost arg is evaluated + first *) + if float_needs arg1 <= float_needs arg2 + then (regular_op, [arg1; arg2]) + else (reversed_op, [arg2; arg1]) + | _ -> + fatal_error "Proc_i386: select_floatarith" + +(* Deal with register constraints *) + +method insert_op_debug op dbg rs rd = + try + let (rsrc, rdst, move_res) = pseudoregs_for_operation op rs rd in + self#insert_moves rs rsrc; + self#insert_debug (Iop op) dbg rsrc rdst; + if move_res then begin + self#insert_moves rdst rd; + rd + end else + rdst + with Use_default -> + super#insert_op_debug op dbg rs rd + +method insert_op op rs rd = + self#insert_op_debug op Debuginfo.none rs rd + +(* Selection of push instructions for external calls *) + +method select_push exp = + match exp with + Cconst_int n -> (Ispecific(Ipush_int(Nativeint.of_int n)), Ctuple []) + | Cconst_natint n -> (Ispecific(Ipush_int n), Ctuple []) + | Cconst_pointer n -> (Ispecific(Ipush_int(Nativeint.of_int n)), Ctuple []) + | Cconst_natpointer n -> (Ispecific(Ipush_int n), Ctuple []) + | Cconst_symbol s -> (Ispecific(Ipush_symbol s), Ctuple []) + | Cop(Cload Word, [loc]) -> + let (addr, arg) = self#select_addressing loc in + (Ispecific(Ipush_load addr), arg) + | Cop(Cload Double_u, [loc]) -> + let (addr, arg) = self#select_addressing loc in + (Ispecific(Ipush_load_float addr), arg) + | _ -> (Ispecific(Ipush), exp) + +method emit_extcall_args env args = + let rec size_pushes = function + | [] -> 0 + | e :: el -> Selectgen.size_expr env e + size_pushes el in + let sz1 = size_pushes args in + let sz2 = Misc.align sz1 stack_alignment in + let rec emit_pushes = function + | [] -> + if sz2 > sz1 then + self#insert (Iop (Istackoffset (sz2 - sz1))) [||] [||] + | e :: el -> + emit_pushes el; + let (op, arg) = self#select_push e in + match self#emit_expr env arg with + | None -> () + | Some r -> self#insert (Iop op) r [||] in + emit_pushes args; + ([||], sz2) + +end + +let fundecl f = (new selector)#emit_fundecl f + diff --git a/asmcomp/ia64/arch.ml b/asmcomp/ia64/arch.ml new file mode 100644 index 0000000..d977551 --- /dev/null +++ b/asmcomp/ia64/arch.ml @@ -0,0 +1,88 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.5 2002-11-29 15:03:36 xleroy Exp $ *) + +(* Specific operations for the IA64 processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Addressing modes -- only one! (register with no displacement) *) + +type addressing_mode = Iindexed + +(* Specific operations *) + +type specific_operation = + Iadd1 (* x + y + 1 or x + x + 1 *) + | Isub1 (* x - y - 1 *) + | Ishladd of int (* x << N + y *) + | Isignextend of int (* truncate 64-bit int to 8N-bit int *) + | Imultaddf (* x *. y +. z *) + | Imultsubf (* x *. y -. z *) + | Isubmultf (* z -. x *. y *) + | Istoreincr of int (* store y at x; x <- x + N *) + | Iinitbarrier (* end of object initialization *) + +(* Sizes, endianness *) + +let big_endian = false + +let size_addr = 8 +let size_int = 8 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed + +let offset_addressing addr delta = assert false + +let num_args_addressing = function Iindexed -> 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + printreg ppf arg.(0) + +let print_specific_operation printreg op ppf arg = + match op with + | Iadd1 -> + if Array.length arg >= 2 then + fprintf ppf "%a + %a + 1 " printreg arg.(0) printreg arg.(1) + else + fprintf ppf "%a << 1 + 1 " printreg arg.(0) + | Isub1 -> + fprintf ppf "%a - %a - 1 " printreg arg.(0) printreg arg.(1) + | Ishladd n -> + fprintf ppf "%a << %d + %a" printreg arg.(0) n printreg arg.(1) + | Isignextend n -> + fprintf ppf "truncate%d %a" (n * 8) printreg arg.(0) + | Imultaddf -> + fprintf ppf "%a * %a + %a" + printreg arg.(0) printreg arg.(1) printreg arg.(2) + | Imultsubf -> + fprintf ppf "%a * %a - %a" + printreg arg.(0) printreg arg.(1) printreg arg.(2) + | Isubmultf -> + fprintf ppf "%a - %a * %a" + printreg arg.(2) printreg arg.(0) printreg arg.(1) + | Istoreincr n -> + fprintf ppf "[%a] := %a; %a += %d" + printreg arg.(0) printreg arg.(1) printreg arg.(0) n + | Iinitbarrier -> + fprintf ppf "initbarrier" diff --git a/asmcomp/ia64/emit.mlp b/asmcomp/ia64/emit.mlp new file mode 100644 index 0000000..50eee48 --- /dev/null +++ b/asmcomp/ia64/emit.mlp @@ -0,0 +1,1327 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.17 2004-07-13 12:18:53 xleroy Exp $ *) + +(* Emission of IA64 assembly code *) + +open Location +open Printf +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(************** Part 1: assembly-level scheduler *******************) + +(* Representation of resources accessed or produced by instructions *) + +type resource = string + (* A resource is either: + - a register name + - "stkN" for a stack location + - "heap" for the Caml heap + - "chkN" for the result of a checkbound instruction *) + +let is_memory_resource rsrc = + String.length rsrc >= 4 && + begin match String.sub rsrc 0 3 with + "stk" -> true + | "hea" -> true + | "chk" -> true + | _ -> false + end + +let is_mutable_resource rsrc = + rsrc <> "r0" && rsrc <> "p0" + +(* Description of instructions *) + +type instruction_kind = + KA (* A type instruction (int or mem unit) *) + | KB (* B type instruction (branch unit) *) + | KI (* I type instruction (int unit *) + | KF (* F type instruction (FP unit) *) + | KM (* M type instruction (mem unit) *) + | KB_exc (* B type instruction, exceptional condition, + can be moved around *) + +type instruction_format = + F_i (* op imm *) + | F_i_pred (* (pred) op imm *) + | F_ir_rr (* op p1,p2 = imm, r *) + | F_ir_r (* op r = imm, r *) + | F_ir_r_pred (* (pred) op r = imm, r *) + | F_ld (* op r = [r] *) + | F_ld_post (* op r = [r], imm *) + | F_r (* op r *) + | F_i_r (* op r = imm *) + | F_i_r_pred (* (pred) op r = imm *) + | F_ri_rr (* op p1,p2 = imm, r *) + | F_ri_r (* op r = imm, r *) + | F_r_r (* op r = r *) + | F_r_r_pred (* (pred) op r = r *) + | F_rr_rr (* op p1,p2 = r1, r2 *) + | F_r_rir (* op r = r1, imm, r2 *) + | F_rr_r (* op r = r1, r2 *) + | F_rr_r_pred (* (pred) op r = r1, r2 *) + | F_rri_r (* op r = r1, r2, imm *) + | F_rrr_r (* op r = r1, r2, r3 *) + | F_rrr_r_pred (* (pred) op r = r1, r2, r3 *) + | F_st (* op [r] = r *) + | F_st_post (* op [r] = r, imm *) + +type instruction_descr = + { opcode: string; (* actual opcode *) + latency: int; (* latency in cycles *) + kind: instruction_kind; (* kind of instruction *) + format: instruction_format } (* how to generate asm for it *) + +let instruction_table = create_hashtable 73 [ + "add", {opcode = "add"; latency = 1; kind = KA; format = F_rr_r}; + "add1", {opcode = "add"; latency = 1; kind = KA; format = F_rri_r}; + "addcond", {opcode = "add"; latency = 1; kind = KA; format = F_rr_r_pred}; + "addi", {opcode = "add"; latency = 1; kind = KA; format = F_ir_r}; + "addicond", {opcode = "add"; latency = 1; kind = KA; format = F_ir_r_pred}; + "and", {opcode = "and"; latency = 1; kind = KA; format = F_rr_r}; + "andi", {opcode = "and"; latency = 1; kind = KA; format = F_ir_r}; + "br", {opcode = "br.sptk.many"; latency = 1; kind = KB; format = F_i}; + "brret", {opcode = "br.ret.sptk"; latency = 1; kind = KB; format = F_r}; + "brcall", {opcode = "br.call.sptk.many"; latency = 1; kind = KB; format = F_i_r}; + "brcallcond", {opcode = "br.call.spnt.many"; latency = 1; kind = KB; format = F_i_r_pred}; + "brcallcondexc", {opcode = "br.call.spnt.many"; latency = 1; kind = KB_exc; format = F_i_r_pred}; + "brcallind", {opcode = "br.call.sptk.many"; latency = 1; kind = KB; format = F_r_r}; + "brcond", {opcode = "br.dpnt.many"; latency = 1; kind = KB; format = F_i_pred}; + "brind", {opcode = "br.sptk.many"; latency = 1; kind = KB; format = F_r}; + "cmp.eq", {opcode = "cmp.eq"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.ge", {opcode = "cmp.ge"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.geu", {opcode = "cmp.geu"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.gt", {opcode = "cmp.gt"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.gtu", {opcode = "cmp.gtu"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.le", {opcode = "cmp.le"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.leu", {opcode = "cmp.leu"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.lt", {opcode = "cmp.lt"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.ltu", {opcode = "cmp.ltu"; latency = 0; kind = KA; format = F_rr_rr}; + "cmp.ne", {opcode = "cmp.ne"; latency = 0; kind = KA; format = F_rr_rr}; + "cmpi.eq", {opcode = "cmp.eq"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.ge", {opcode = "cmp.ge"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.geu", {opcode = "cmp.geu"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.gt", {opcode = "cmp.gt"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.gtu", {opcode = "cmp.gtu"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.le", {opcode = "cmp.le"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.leu", {opcode = "cmp.leu"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.lt", {opcode = "cmp.lt"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.ltu", {opcode = "cmp.ltu"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpi.ne", {opcode = "cmp.ne"; latency = 0; kind = KA; format = F_ir_rr}; + "cmpp.eq", {opcode = "cmp.eq"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.ge", {opcode = "cmp.ge"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.geu", {opcode = "cmp.geu"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.gt", {opcode = "cmp.gt"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.gtu", {opcode = "cmp.gtu"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.le", {opcode = "cmp.le"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.leu", {opcode = "cmp.leu"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.lt", {opcode = "cmp.lt"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.ltu", {opcode = "cmp.ltu"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.ne", {opcode = "cmp.ne"; latency = 1; kind = KA; format = F_rr_rr}; + "cmpp.ne.and", {opcode = "cmp.ne.and"; latency = 1; kind = KA; format = F_rr_rr}; + "cmppi.eq", {opcode = "cmp.eq"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.ge", {opcode = "cmp.ge"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.geu", {opcode = "cmp.geu"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.gt", {opcode = "cmp.gt"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.gtu", {opcode = "cmp.gtu"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.le", {opcode = "cmp.le"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.leu", {opcode = "cmp.leu"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.lt", {opcode = "cmp.lt"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.ltu", {opcode = "cmp.ltu"; latency = 1; kind = KA; format = F_ir_rr}; + "cmppi.ne", {opcode = "cmp.ne"; latency = 1; kind = KA; format = F_ir_rr}; + "extr.u", {opcode = "extr.u"; latency = 1; kind = KI; format = F_ri_r}; + "fabs", {opcode = "fabs"; latency = 1; kind = KF; format = F_r_r}; + "fadd.d", {opcode = "fadd.d"; latency = 5; kind = KF; format = F_rr_r}; + "fcmp.eq", {opcode = "fcmp.eq"; latency = 1; kind = KF; format = F_rr_rr}; + "fcmp.ge", {opcode = "fcmp.ge"; latency = 1; kind = KF; format = F_rr_rr}; + "fcmp.gt", {opcode = "fcmp.gt"; latency = 1; kind = KF; format = F_rr_rr}; + "fcmp.le", {opcode = "fcmp.le"; latency = 1; kind = KF; format = F_rr_rr}; + "fcmp.lt", {opcode = "fcmp.lt"; latency = 1; kind = KF; format = F_rr_rr}; + "fcmp.neq", {opcode = "fcmp.neq"; latency = 1; kind = KF; format = F_rr_rr}; + "fcvt.fx.trunc", {opcode = "fcvt.fx.trunc"; latency = 7; kind = KF; format = F_r_r}; + "fcvt.xf", {opcode = "fcvt.xf"; latency = 5; kind = KF; format = F_r_r}; + "fma.d", {opcode = "fma.d"; latency = 5; kind = KF; format = F_rrr_r}; + "fmacond", {opcode = "fma.d.s0"; latency = 5; kind = KF; format = F_rrr_r_pred}; + "fmas1cond", {opcode = "fma.s1"; latency = 5; kind = KF; format = F_rrr_r_pred}; + "fmads1cond", {opcode = "fma.d.s1"; latency = 5; kind = KF; format = F_rrr_r_pred}; + "fmpy.d", {opcode = "fmpy.d"; latency = 5; kind = KF; format = F_rr_r}; + "fms.d", {opcode = "fms.d"; latency = 5; kind = KF; format = F_rrr_r}; + "fneg", {opcode = "fneg"; latency = 1; kind = KF; format = F_r_r}; + "fnma.d", {opcode = "fnma.d"; latency = 5; kind = KF; format = F_rrr_r}; + "fnmas1cond", {opcode = "fnma.s1"; latency = 5; kind = KF; format = F_rrr_r_pred}; + "fnmads1cond", {opcode = "fnma.d.s1"; latency = 5; kind = KF; format = F_rrr_r_pred}; + "fnorm.d", {opcode = "fnorm.d"; latency = 5; kind = KF; format = F_r_r}; + "frcpa", {opcode = "frcpa.s0"; latency = 5; kind = KF; format = F_rr_rr}; + "fsub.d", {opcode = "fsub.d"; latency = 5; kind = KF; format = F_rr_r}; + "getf.sig", {opcode = "getf.sig"; latency = 2; kind = KM; format = F_r_r}; + "ld1", {opcode = "ld1"; latency = 2; kind = KM; format = F_ld}; + "ld2", {opcode = "ld2"; latency = 2; kind = KM; format = F_ld}; + "ld4", {opcode = "ld4"; latency = 2; kind = KM; format = F_ld}; + "ld8", {opcode = "ld8"; latency = 2; kind = KM; format = F_ld}; + "ld8+", {opcode = "ld8"; latency = 2; kind = KM; format = F_ld_post}; + "ldfd", {opcode = "ldfd"; latency = 9; kind = KM; format = F_ld}; + "ldfd+", {opcode = "ldfd"; latency = 9; kind = KM; format = F_ld_post}; + "ldfs", {opcode = "ldfs"; latency = 9; kind = KM; format = F_ld}; + "mov", {opcode = "mov"; latency = 1; kind = KA; format = F_r_r}; + "movcond", {opcode = "mov"; latency = 1; kind = KA; format = F_r_r_pred}; + "movtb", {opcode = "mov"; latency = 9; kind = KI; format = F_r_r}; + "movfb", {opcode = "mov"; latency = 2; kind = KI; format = F_r_r}; + "movi", {opcode = "mov"; latency = 1; kind = KA; format = F_i_r}; + "movicond", {opcode = "mov"; latency = 1; kind = KA; format = F_i_r_pred}; + "movil", {opcode = "movl"; latency = 1; kind = KI; format = F_i_r}; + "movpr", {opcode = "mov"; latency = 1; kind = KI; format = F_ri_r}; + "or", {opcode = "or"; latency = 1; kind = KA; format = F_rr_r}; + "ori", {opcode = "or"; latency = 1; kind = KA; format = F_ir_r}; + "setf.d", {opcode = "setf.d"; latency = 8; kind = KM; format = F_r_r}; + "setf.sig", {opcode = "setf.sig"; latency = 8; kind = KM; format = F_r_r}; + "shl", {opcode = "shl"; latency = 2; kind = KI; format = F_rr_r}; + "shladd", {opcode = "shladd"; latency = 1; kind = KA; format = F_r_rir}; + "shli", {opcode = "shl"; latency = 1; kind = KI; format = F_ri_r}; + "shr", {opcode = "shr"; latency = 2; kind = KI; format = F_rr_r}; + "shri", {opcode = "shr"; latency = 1; kind = KI; format = F_ri_r}; + "shru", {opcode = "shr.u"; latency = 2; kind = KI; format = F_rr_r}; + "shrui", {opcode = "shr.u"; latency = 1; kind = KI; format = F_ri_r}; + "st1", {opcode = "st1"; latency = 0; kind = KM; format = F_st}; + "st2", {opcode = "st2"; latency = 0; kind = KM; format = F_st}; + "st4", {opcode = "st4"; latency = 0; kind = KM; format = F_st}; + "st8", {opcode = "st8"; latency = 0; kind = KM; format = F_st}; + "st8+", {opcode = "st8"; latency = 1; kind = KM; format = F_st_post}; + "stfd", {opcode = "stfd"; latency = 0; kind = KM; format = F_st}; + "stfd+", {opcode = "stfd"; latency = 1; kind = KM; format = F_st_post}; + "stfs", {opcode = "stfs"; latency = 0; kind = KM; format = F_st}; + "sub", {opcode = "sub"; latency = 1; kind = KA; format = F_rr_r}; + "sub1", {opcode = "sub"; latency = 1; kind = KA; format = F_rri_r}; + "subi", {opcode = "sub"; latency = 1; kind = KA; format = F_ir_r}; + "sxt1", {opcode = "sxt1"; latency = 1; kind = KI; format = F_r_r}; + "sxt2", {opcode = "sxt2"; latency = 1; kind = KI; format = F_r_r}; + "sxt4", {opcode = "sxt4"; latency = 1; kind = KI; format = F_r_r}; + "tbit.nz", {opcode = "tbit.nz"; latency = 0; kind = KI; format = F_ri_rr}; + "tbit.z", {opcode = "tbit.z"; latency = 0; kind = KI; format = F_ri_rr}; + "xmpy.l", {opcode = "xmpy.l"; latency = 7; kind = KF; format = F_rr_r}; + "xor", {opcode = "xor"; latency = 1; kind = KA; format = F_rr_r}; + "xori", {opcode = "xor"; latency = 1; kind = KA; format = F_ir_r}; + "#initbarrier", {opcode = "# init barrier"; latency = 0; kind = KI; format = F_i}; +] + +(* Nodes of the code DAG. Each node represents one instruction to be + emitted. *) + +type code_dag_node = + { instr: instruction_descr; (* the instruction *) + imm: string; (* its immediate argument, if any *) + iarg: resource array; (* arguments *) + ires: resource array; (* results *) + delay: int; (* how many cycles before result is available *) + mutable sons: (code_dag_node * int) list; + (* nodes that depend on this node *) + mutable date: int; (* start date *) + mutable length: int; (* length of longest path to result *) + mutable ancestors: int; (* number of ancestors *) + mutable emitted_ancestors: int } (* number of emitted ancestors *) + +(* The code dag itself is represented by two tables from resources to nodes: + - "results" maps resources to the instructions that produced them; + - "uses" maps resources to the instructions that use them. *) + +let code_results = (Hashtbl.create 31 : (resource, code_dag_node) Hashtbl.t) +let code_uses = (Hashtbl.create 31 : (resource, code_dag_node) Hashtbl.t) + +let clear_code_dag () = + Hashtbl.clear code_results; + Hashtbl.clear code_uses + +(* The ready queue: a list of nodes that can be computed immediately + (all arguments are available), kept sorted by decreasing length to results. + + The in progress queue: a list of nodes whose arguments are being computed, + and thus can be computed at a later date, kept sorted by increasing + availability date + + The branch list: a list of all branch instructions (to be emitted last) *) + +let ready_queue = ref ([] : code_dag_node list) +let in_progress_queue = ref ([] : code_dag_node list) +let branch_list = ref ([] : code_dag_node list) (* built in reverse order *) + +let clear_queues () = + ready_queue := []; in_progress_queue := []; branch_list := [] + +let rec insert_queue prio node = function + [] -> [node] + | hd :: tl as queue -> + if prio node hd then node :: queue else hd :: insert_queue prio node tl + +let length_prio n1 n2 = n1.length > n2.length +let date_prio n1 n2 = n1.date < n2.date + +let add_ready node = + ready_queue := insert_queue length_prio node !ready_queue +let add_in_progress node = + in_progress_queue := insert_queue date_prio node !in_progress_queue +let add_branch node = + branch_list := node :: !branch_list + +(* Add an edge to the code DAG *) + +let add_edge ancestor son delay = + ancestor.sons <- (son, delay) :: ancestor.sons; + son.ancestors <- son.ancestors + 1 + +let add_edge_after son ancestor = add_edge ancestor son 0 + +(* Add an instruction to the code DAG *) + +let insimm opc arg imm res = + let instr = + try + Hashtbl.find instruction_table opc + with Not_found -> + fatal_error ("Unknown instruction " ^ opc) in + let node = + { instr = instr; + imm = imm; + iarg = arg; + ires = res; + delay = instr.latency; + sons = []; (* to be filled later *) + date = 0; (* to be adjusted later *) + length = -1; (* to be computed later *) + ancestors = 0; (* ditto *) + emitted_ancestors = 0 } in (* ditto *) + (* RAW dependencies: add edges from all instrs that define one of the + resources used *) + for i = 0 to Array.length arg - 1 do + try + let rsrc = arg.(i) in + if is_mutable_resource rsrc then begin + let anc = Hashtbl.find code_results rsrc in + let delay = if is_memory_resource rsrc then 0 else anc.delay in + (* Memory accesses are ordered by the hardware, so we can emit + a memop 1, then a dependent memop 2 in the same cycle *) + add_edge anc node delay + end + with Not_found -> + () + done; + (* WAR dependencies: add edges from all instrs that use one of the + resources defined by this instruction + WAW dependencies: add edges from all instrs that define one of the + resources defined by this instruction *) + for i = 0 to Array.length res - 1 do + let rsrc = res.(i) in + if is_mutable_resource rsrc then begin + (* WAR *) + let anc = Hashtbl.find_all code_uses res.(i) in + List.iter (add_edge_after node) anc; + (* WAW *) + try + let anc = Hashtbl.find code_results rsrc in + let delay = if is_memory_resource rsrc then 0 else 1 in + add_edge anc node delay + with Not_found -> + () + end + done; + (* Remember the results and uses of this instruction *) + for i = 0 to Array.length res - 1 do + Hashtbl.add code_results res.(i) node + done; + for i = 0 to Array.length arg - 1 do + Hashtbl.add code_uses arg.(i) node + done; + (* Insert in appropriate queue *) + if node.instr.kind = KB + then add_branch node + else if node.ancestors = 0 then add_ready node + +let insert opc arg res = + insimm opc arg "" res + +(* Compute length of longest path to a result. *) + +let rec longest_path node = + if node.length < 0 then begin + node.length <- + List.fold_left + (fun len (son, delay) -> max len (longest_path son + delay)) + 0 node.sons + end; + node.length + +(* Emit the assembly code for a node *) + +let emit_r = emit_string + +let emit_instr node = + let opc = node.instr.opcode + and a = node.iarg + and r = node.ires + and imm = node.imm in + match node.instr.format with + F_i -> + ` {emit_string opc} {emit_string imm}\n` + | F_i_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_string imm}\n` + | F_ir_rr -> + ` {emit_string opc} {emit_r r.(0)}, {emit_r r.(1)} = {emit_string imm}, {emit_r a.(0)}\n` + | F_ir_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_string imm}, {emit_r a.(0)}\n` + | F_ir_r_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_r r.(0)} = {emit_string imm}, {emit_r a.(1)}\n` + | F_ld -> + ` {emit_string opc} {emit_r r.(0)} = [{emit_r a.(0)}]\n` + | F_ld_post -> + ` {emit_string opc} {emit_r r.(0)} = [{emit_r a.(0)}], {emit_string imm}\n` + | F_r -> + ` {emit_string opc} {emit_r a.(0)}\n` + | F_i_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_string imm}\n` + | F_i_r_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_r r.(0)} = {emit_string imm}\n` + | F_ri_rr -> + ` {emit_string opc} {emit_r r.(0)}, {emit_r r.(1)} = {emit_r a.(0)}, {emit_string imm}\n` + | F_ri_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}, {emit_string imm}\n` + | F_r_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}\n` + | F_r_r_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_r r.(0)} = {emit_r a.(1)}\n` + | F_rr_rr -> + ` {emit_string opc} {emit_r r.(0)}, {emit_r r.(1)} = {emit_r a.(0)}, {emit_r a.(1)}\n` + | F_r_rir -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}, {emit_string imm}, {emit_r a.(1)}\n` + | F_rr_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}, {emit_r a.(1)}\n` + | F_rr_r_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_r r.(0)} = {emit_r a.(1)}, {emit_r a.(2)}\n` + | F_rri_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}, {emit_r a.(1)}, {emit_string imm}\n` + | F_rrr_r -> + ` {emit_string opc} {emit_r r.(0)} = {emit_r a.(0)}, {emit_r a.(1)}, {emit_r a.(2)}\n` + | F_rrr_r_pred -> + ` ({emit_r a.(0)}) {emit_string opc} {emit_r r.(0)} = {emit_r a.(1)}, {emit_r a.(2)}, {emit_r a.(3)}\n` + | F_st -> + ` {emit_string opc} [{emit_r a.(0)}] = {emit_r a.(1)}\n` + | F_st_post -> + ` {emit_string opc} [{emit_r a.(0)}] = {emit_r a.(1)}, {emit_string imm}\n` + +(* Little state machine reflecting how many instructions the chip can + issue in one cycle. We roughly follow the Itanium model: + 2 int units, 2 mem units, 2 FP units, and 3 branch units, + with a maximum of 6 instructions dispatched per clock cycle. *) + +let num_A = ref 0 +let num_I = ref 0 +let num_M = ref 0 +let num_F = ref 0 +let num_B = ref 0 + +let reset_issue () = + num_A := 0; num_I := 0; num_M := 0; num_F := 0; num_B := 0 + +let can_issue instr = + if !num_A + !num_I + !num_M + !num_F + !num_B >= 6 then false else begin + match instr.kind with + KA -> + if !num_A + !num_I + !num_M < 4 + then (incr num_A; true) + else false + | KF -> + if !num_F < 2 then (incr num_F; true) else false + | KI -> + if !num_I < 2 && !num_A + !num_I + !num_M < 4 + then (incr num_I; true) else false + | KM -> + if !num_M < 2 && !num_A + !num_I + !num_M < 4 + then (incr num_M; true) else false + | _ (* KB | KB_exc *) -> + if !num_B < 3 then (incr num_B; true) else false + end + +(* Emit one node, updating the completion date and number of ancestors + emitted for all nodes that depend on this node. Enter the nodes + that are no longer waiting on anything (all ancestors emitted) + in the ready queue or in the in_progress queue, depending on + latency. *) + +let emit_node date node = + begin try + (*`# Date: {emit_int date}; distance: {emit_int node.length}\n`;*) + emit_instr node + with x -> + fatal_error ("Error while emitting " ^ node.instr.opcode) + end; + List.iter + (fun (son, delay) -> + let completion_date = date + delay in + if son.date < completion_date then son.date <- completion_date; + son.emitted_ancestors <- son.emitted_ancestors + 1; + if son.emitted_ancestors = son.ancestors && son.instr.kind <> KB then + begin + (*`# {emit_string son.instr.opcode} will be ready at {emit_int son.date}\n`;*) + if son.date = date then add_ready son else add_in_progress son + end) + node.sons + +(* Emit all ready nodes that we can emit given the architectural + constraints. *) + +let rec emit_ready_nodes filter date = + match !ready_queue with + [] -> [] + | node :: rem -> + ready_queue := rem; + if filter node && can_issue node.instr then begin + emit_node date node; + emit_ready_nodes filter date + end else + node :: emit_ready_nodes filter date + +let filter_MF node = + match node.instr.kind with KM -> true | KF -> true | _ -> false +let filter_non_MF node = + not(filter_MF node) + +(* Add all instructions with date <= d to the ready queue, and remove them *) + +let rec extract_ready d = function + [] -> [] + | node :: rem as queue -> + if node.date <= d then (add_ready node; extract_ready d rem) else queue + +(* Say if a branch is ready to be emitted now *) + +let branch_is_ready date br = + br.emitted_ancestors = br.ancestors && br.date <= date + +(* Schedule the basic block, emitting all of its instructions *) + +let rec reschedule date = + match (!ready_queue, !in_progress_queue) with + ([], []) -> + (* We're done with the regular instructions; finish with the branches *) + begin match !branch_list with + [] -> () + | br -> List.iter emit_instr br; emit_string " ;;\n" + end + | ([], node :: _) -> + (* Advance to the time node.date, extracting from in_progress_queue + all instructions ready at that time and adding them to the + ready queue *) + in_progress_queue := extract_ready node.date !in_progress_queue; + (* Try again *) + reschedule node.date + | (_, _) -> + ` # time {emit_int date}\n`; + (* Emit and remove as many ready instructions as we can *) + (* Give priority to M and F instructions *) + reset_issue(); + ready_queue := emit_ready_nodes filter_MF date; + ready_queue := emit_ready_nodes filter_non_MF date; + (* Special hack: if the only remaining instructions are branches + and they are all ready now, emit them in the current + group of instructions *) + if !ready_queue = [] + && !in_progress_queue = [] + && List.for_all (branch_is_ready date) !branch_list + then begin + List.iter emit_instr !branch_list; + branch_list := [] + end; + (* Emit a stop to pause the processor *) + emit_string " ;;\n"; + (* Advance to the time date + 1, extracting from in_progress_queue + all instructions ready at that time and adding them to the + ready queue *) + in_progress_queue := extract_ready (date + 1) !in_progress_queue; + (* Try again *) + reschedule (date + 1) + +(* Emit the code for the current basic block *) + +let end_basic_block () = + (* Compute critical paths and rebuild ready queue sorted by + decreasing criticality *) + let r = !ready_queue in + ready_queue := []; + let max_length = + List.fold_left (fun len node -> max len (longest_path node)) 0 r in + List.iter add_ready r; + branch_list := List.rev !branch_list; + (* Emit the instructions by traversing the code DAG *) + reschedule 0; + if max_length > 0 then ` # basic block length {emit_int max_length}\n`; + clear_code_dag (); + clear_queues () + +(************** Part 2: the code emitter *******************) + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Translate or output a label *) + +let label lbl = sprintf ".L%d" lbl + +let emit_label lbl = emit_string ".L"; emit_int lbl + +(* Translate or output a symbol *) + +let symbol s = + let b = Buffer.create (String.length s + 1) in + for i = 0 to String.length s - 1 do + let c = s.[i] in + match c with + 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' -> + Buffer.add_char b c + | _ -> + Buffer.add_string b (sprintf "$%02x" (Char.code c)) + done; + Buffer.add_char b '#'; + Buffer.contents b + +let emit_symbol s = Emitaux.emit_symbol '$' s + +(* Translate a pseudo-register *) + +let reg r = + match r.loc with Reg r -> register_name r | _ -> assert false + +let regs r = + Array.map reg r + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit_ia64.emit_reg" + +(* Translate a float as a 64-bit integer *) + +let float_bits f = + let b = Buffer.create 18 in + let bytes = (Obj.magic f : string) in + Buffer.add_string b "0x"; + for i = 7 downto 0 do (* little-endian *) + Buffer.add_string b + (sprintf "%02x" (Char.code (String.unsafe_get bytes i))) + done; + Buffer.contents b + +(* Translate an "ltoffset" reference to a global *) + +let ltoffset s = sprintf "@ltoff(%s)" (symbol s) +let ltoffset_fptr s = sprintf "@ltoff(@fptr(%s))" (symbol s) + +(* Layout of the stack frame. + All stack offsets are shifted by 16 to preserve the scratch area at + bottom of stack. *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + + (if !contains_calls then 8 else 0) in + Misc.align size 16 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + 16 + | Local n -> + if cl = 0 + then !stack_offset + n * 8 + 16 + else !stack_offset + (num_stack_slots.(0) + n) * 8 + 16 + | Outgoing n -> n + 16 + +let slot_offset_reg r = + match r.loc with + Stack l -> slot_offset l (register_class r) + | _ -> assert false + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame_label live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + lbl + +let record_frame live = + let lbl = record_frame_label live in `{emit_label lbl}:` + +let emit_frame fd = + ` data8 {emit_label fd.fd_lbl}\n`; + ` data2 {emit_int fd.fd_frame_size}\n`; + ` data2 {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` data2 {emit_int n}\n`) + fd.fd_live_offset; + ` .align 8\n` + +(* Names of various instructions *) + +let name_for_int_operation = function + Iadd -> "add" + | Isub -> "sub" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "shl" + | Ilsr -> "shru" + | Iasr -> "shr" + | _ -> Misc.fatal_error "Emit.name_for_int_operation" + +let name_for_float_operation = function + Inegf -> "fneg" + | Iabsf -> "fabs" + | Iaddf -> "fadd.d" + | Isubf -> "fsub.d" + | Imulf -> "fmpy.d" + | _ -> Misc.fatal_error "Emit.name_for_float_operation" + +let name_for_specific_operation = function + Imultaddf -> "fma.d" + | Imultsubf -> "fms.d" + | Isubmultf -> "fnma.d" + | _ -> Misc.fatal_error "Emit.name_for_specific_operation" + +let name_for_int_comparison = function + Isigned Ceq -> "eq" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "gt" + | Isigned Clt -> "lt" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "eq" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "leu" | Iunsigned Cgt -> "gtu" + | Iunsigned Clt -> "ltu" | Iunsigned Cge -> "geu" + +let name_for_swapped_int_comparison = function + Isigned Ceq -> "eq" | Isigned Cne -> "ne" + | Isigned Cle -> "ge" | Isigned Cgt -> "lt" + | Isigned Clt -> "gt" | Isigned Cge -> "le" + | Iunsigned Ceq -> "eq" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "geu" | Iunsigned Cgt -> "ltu" + | Iunsigned Clt -> "gtu" | Iunsigned Cge -> "leu" + +let name_for_float_comparison cmp = + match cmp with + Ceq -> "eq" | Cne -> "neq" + | Cle -> "le" | Cgt -> "gt" + | Clt -> "lt" | Cge -> "ge" + +(* Immediate range for addl (move) and adds (general add) instructions *) + +let is_immediate_addl n = n >= -0x200000 && n < 0x200000 +let is_immediate_addl_nat n = + n >= Nativeint.of_int (-0x200000) && n < Nativeint.of_int 0x200000 +let is_immediate_adds n = n >= -0x2000 && n < 0x2000 + +(* Return the positions of all "1" bits in the given integer, + most significant bits first *) + +let ones_pos n = + let rec ones p accu = + if p >= 63 + then accu + else ones (p+1) (if n land (1 lsl p) = 0 then accu else p :: accu) in + ones 0 [] + +(* Generate temporary registers *) + +let temp_generator temporaries = + let counter = ref 0 in + fun () -> + let r = temporaries.(!counter) in + incr counter; + if !counter >= Array.length temporaries then counter := 0; + r + +let new_temp_reg = + temp_generator [| "r2"; "r3"; "r14"; "r15" |] +let new_temp_float = + temp_generator [| "f64"; "f65"; "f66"; "f67"; + "f68"; "f69"; "f70"; "f71" |] +let new_pred = + temp_generator [| "p2"; "p3"; "p4"; "p5" |] + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 + +let emit_instr i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + match (src.loc, dst.loc) with + (Reg _, Reg _) -> + insert "mov" (regs i.arg) (regs i.res) + | (Reg _, Stack _) -> + let offset = string_of_int (slot_offset_reg dst) in + let r = new_temp_reg() in + insimm "addi" [| "sp" |] offset [| r |]; + insert (if i.res.(0).typ = Float then "stfd" else "st8") + [| r; reg src |] [| "stk" ^ offset |] + | (Stack _, Reg _) -> + let offset = string_of_int (slot_offset_reg src) in + let r = new_temp_reg() in + insimm "addi" [| "sp" |] offset [| r |]; + insert (if i.arg.(0).typ = Float then "ldfd" else "ld8") + [| r; "stk" ^ offset |] (regs i.res) + | (_, _) -> + assert false + end + | Lop(Iconst_int n) -> + let instr = + if is_immediate_addl_nat n then "movi" else "movil" in + insimm instr [||] (Nativeint.to_string n) (regs i.res) + | Lop(Iconst_float s) -> + let f = float_of_string s in + begin match Int64.bits_of_float f with + | 0x0000_0000_0000_0000L -> (* +0.0 *) + insert "mov" [| "f0" |] (regs i.res) + | 0x3FF0_0000_0000_0000L -> (* 1.0 *) + insert "mov" [| "f1" |] (regs i.res) + | _ -> + let tmp = new_temp_reg() in + insimm "movil" [||] (float_bits f) [| tmp |]; + insert "setf.d" [| tmp |] (regs i.res) + end + | Lop(Iconst_symbol s) -> + insimm "addi" [| "gp" |] (ltoffset s) (regs i.res); + insert "ld8" (regs i.res) (regs i.res) + | Lop(Icall_ind) -> + insert "movtb" (regs i.arg) [| "b0" |]; + insert "brcallind" [| "b0" |] [| "b0" |]; + end_basic_block(); + `{record_frame i.live}\n` + | Lop(Icall_imm s) -> + insimm "brcall" [||] (symbol s) [| "b0" |]; + end_basic_block(); + `{record_frame i.live}\n` + | Lop(Itailcall_ind) -> + let n = frame_size() in + insert "movtb" (regs i.arg) [| "b6" |]; + if !contains_calls then begin + let tmp = new_temp_reg() in + insimm "addi" [| "sp" |] (string_of_int (n + 8)) [| tmp |]; + insert "ld8" [| tmp |] [| tmp |]; + insert "mov" [| tmp |] [| "b0" |] + end; + if n > 0 then + insimm "addi" [| "sp" |] (string_of_int n) [| "sp" |]; + insert "brind" [| "b6" |] [||]; + end_basic_block() + | Lop(Itailcall_imm s) -> + if s = !function_name then begin + insimm "br" [||] (label !tailrec_entry_point) [||] + end else begin + let n = frame_size() in + if !contains_calls then begin + let tmp = new_temp_reg() in + insimm "addi" [| "sp" |] (string_of_int (n + 8)) [| tmp |]; + insert "ld8" [| tmp |] [| tmp |]; + insert "mov" [| tmp |] [| "b0" |] + end; + if n > 0 then + insimm "addi" [| "sp" |] (string_of_int n) [| "sp" |]; + insimm "br" [||] (symbol s) [||] + end; + end_basic_block() + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + let tmp = new_temp_reg() in + insimm "addi" [| "gp" |] (ltoffset_fptr s) [| tmp |]; + insert "ld8" [| tmp |] [| "r2" |]; + insimm "brcall" [||] "caml_c_call#" [| "b0" |]; + end_basic_block(); + `{record_frame i.live}\n` + end else begin + insert "mov" [| "gp" |] [| "r7" |]; + insimm "brcall" [||] (symbol s) [| "b0" |]; + end_basic_block(); + insert "mov" [| "r7" |] [| "gp" |] + end + | Lop(Istackoffset n) -> + end_basic_block(); + insimm "addi" [| "sp" |] (string_of_int (-n)) [| "sp" |]; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let load_instr = + match chunk with + | Byte_unsigned -> "ld1" + | Byte_signed -> "ld1" + | Sixteen_unsigned -> "ld2" + | Sixteen_signed -> "ld2" + | Thirtytwo_unsigned -> "ld4" + | Thirtytwo_signed -> "ld4" + | Word -> "ld8" + | Single -> "ldfs" + | Double -> "ldfd" + | Double_u -> "ldfd" in + insert load_instr [| reg i.arg.(0); "heap" |] (regs i.res); + let sext_instr = + match chunk with + Byte_signed -> "sxt1" + | Sixteen_signed -> "sxt2" + | Thirtytwo_signed -> "sxt4" + | _ -> "" in + if sext_instr <> "" then + insert sext_instr (regs i.res) (regs i.res) + | Lop(Istore(chunk, addr)) -> + let store_instr = + match chunk with + | Byte_unsigned -> "st1" + | Byte_signed -> "st1" + | Sixteen_unsigned -> "st2" + | Sixteen_signed -> "st2" + | Thirtytwo_unsigned -> "st4" + | Thirtytwo_signed -> "st4" + | Word -> "st8" + | Single -> "stfs" + | Double -> "stfd" + | Double_u -> "stfd" in + insert store_instr [| reg i.arg.(1); reg i.arg.(0) |] [| "heap" |] + | Lop(Ialloc n) -> + if !fastcode_flag then begin + insimm "addi" [| "r4" |] (string_of_int (-n)) [| "r4" |]; + insert "cmp.ltu" [| "r4"; "r5" |] [| "p6"; "p0" |]; + insimm "movi" [||] (string_of_int n) [| "r2" |]; + insimm "brcallcond" [| "p6" |] "caml_call_gc#" [| "b0" |]; + end_basic_block(); + `{record_frame i.live}\n`; + insimm "addi" [| "r4" |] "8" (regs i.res) + end else begin + insimm "movi" [||] (string_of_int n) [| "r2" |]; + insimm "brcall" [||] "caml_allocN#" [| "b0" |]; + end_basic_block(); + `{record_frame i.live}\n`; + insimm "addi" [| "r4" |] "8" (regs i.res) + end + | Lop(Iintop Imul) -> + let t1 = new_temp_float() and t2 = new_temp_float() in + insert "setf.sig" [|reg i.arg.(0)|] [| t1 |]; + insert "setf.sig" [|reg i.arg.(1)|] [| t2 |]; + insert "xmpy.l" [| t1; t2 |] [| t1 |]; + insert "getf.sig" [| t1 |] (regs i.res) + | Lop(Iintop(Icomp cmp)) -> + let comp = "cmpp." ^ name_for_int_comparison cmp in + let p1 = new_pred() and p2 = new_pred() in + insert comp (regs i.arg) [| p1; p2 |]; + insimm "movicond" [| p1 |] "1" (regs i.res); + insimm "movicond" [| p2 |] "0" (regs i.res) + | Lop(Iintop(Icheckbound)) -> + insert "cmp.leu" (regs i.arg) [| "p6"; "p0" |]; + insimm "brcallcondexc" [| "p6" |] "caml_ml_array_bound_error#" + [| "b0"; "heap" |] + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + insert instr (regs i.arg) (regs i.res) + | Lop(Iintop_imm(Imul, n)) -> + let src = reg i.arg.(0) and dst = reg i.res.(0) in + begin match ones_pos n with + [] -> + insimm "movi" [||] "0" [|dst|] + | [n] -> + insimm "shli" [|src|] (string_of_int n) [|dst|] + | [n; 0] when n <= 4 -> + insimm "shladd" [|src; src|] (string_of_int n) [|dst|] + | n1::n2::lst -> + let acc1 = new_temp_reg() and acc2 = new_temp_reg() + and tmp1 = new_temp_reg() and tmp2 = new_temp_reg() in + insimm "shli" [|src|] (string_of_int n1) [|acc1|]; + insimm "shli" [|src|] (string_of_int n2) [|acc2|]; + let rec add_shifts a1 t1 a2 t2 = function + [] -> + insert "add" [|a1; a2|] [|dst|] + | n::rem -> + if n = 0 then + insert "add" [|src; a1|] [|a1|] + else if n <= 4 then + insimm "shladd" [|src; a1|] (string_of_int n) [|a1|] + else begin + insimm "shli" [|src|] (string_of_int n) [|t1|]; + insert "add" [|t1; a1|] [|a1|] + end; + add_shifts a2 t2 a1 t1 rem in + add_shifts acc1 tmp1 acc2 tmp2 lst + end + | Lop(Iintop_imm(Idiv, n)) -> (* n must be a power of 2 *) + let src = regs i.arg and dst = regs i.res in + let p1 = new_pred() and p2 = new_pred() in + let l = Misc.log2 n in + insert "cmpp.lt" [| src.(0); "r0" |] [| p1; p2 |]; + if is_immediate_adds (n-1) then + insimm "addicond" [| p1; src.(0) |] (string_of_int (n-1)) dst + else begin + let moveop = if is_immediate_addl (n-1) then "movi" else "movil" in + insimm moveop [||] (string_of_int (n-1)) [| "r2" |]; + insert "addcond" [| p1; src.(0); "r2" |] dst + end; + insert "movcond" [| p2; src.(0) |] dst; + insimm "shri" dst (string_of_int l) dst + | Lop(Iintop_imm(Imod, n)) -> (* n must be a power of 2 *) + let src = regs i.arg and dst = regs i.res in + let p = new_pred() in + let l = Misc.log2 n in + insert "cmpp.lt" [| src.(0); "r0" |] [| p; "p0" |]; + insimm "extr.u" src (sprintf "0, %d" l) dst; + insert "cmpp.ne.and" [| dst.(0); "r0"; p |] [| p; "p0" |]; + if is_immediate_adds (-n) then + insimm "addicond" [| p; dst.(0) |] (string_of_int (-n)) dst + else begin + let moveop = if is_immediate_addl (-n) then "movi" else "movil" in + insimm moveop [||] (string_of_int (-n)) [| "r2" |]; + insert "addcond" [| p; dst.(0); "r2" |] dst + end + | Lop(Iintop_imm(Icomp cmp, n)) -> + let comp = "cmppi." ^ name_for_swapped_int_comparison cmp in + let p1 = new_pred() and p2 = new_pred() in + insimm comp (regs i.arg) (string_of_int n) [| p1; p2 |]; + insimm "movicond" [| p1 |] "1" (regs i.res); + insimm "movicond" [| p2 |] "0" (regs i.res) + | Lop(Iintop_imm(Icheckbound, n)) -> + insimm "cmpi.geu" (regs i.arg) (string_of_int n) [| "p6"; "p0" |]; + insimm "brcallcondexc" [| "p6" |] "caml_ml_array_bound_error#" + [| "b0"; "heap" |] + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_int_operation op ^ "i" in + insimm instr (regs i.arg) (string_of_int n) (regs i.res) + | Lop(Inegf | Iabsf | Iaddf | Isubf | Imulf as op) -> + let instr = name_for_float_operation op in + insert instr (regs i.arg) (regs i.res) + | Lop(Idivf) -> + (* Straight from the IA64 application developer's architecture guide, + section 13.3.3.1. Modified so that the destination may be equal + to one of the operands *) + let a = reg i.arg.(0) and b = reg i.arg.(1) and r = reg i.res.(0) + and t1 = new_temp_float() and t2 = new_temp_float() + and t3 = new_temp_float() and t4 = new_temp_float() + and p = new_pred() in + insert "frcpa" [| a; b |] [| t1; p |]; + insert "fmas1cond" [| p; a; t1; "f0" |] [| t2 |]; + insert "fnmas1cond" [| p; b; t1; "f1" |] [| t3 |]; + insert "fmas1cond" [| p; t3; t3; t2 |] [| t2 |]; + insert "fmas1cond" [| p; t3; t3; "f0" |] [| t4 |]; + insert "fmas1cond" [| p; t3; t1; t1 |] [| t1 |]; + insert "fmas1cond" [| p; t4; t2; t2 |] [| t2 |]; + insert "fmas1cond" [| p; t4; t4; "f0" |] [| t3 |]; + insert "fmas1cond" [| p; t4; t1; t1 |] [| t1 |]; + insert "fmads1cond" [| p; t3; t2; t2 |] [| t2 |]; + insert "fmas1cond" [| p; t3; t1; t1 |] [| t1 |]; + insert "fnmads1cond" [| p; b; t2; a |] [| t3 |]; + insert "mov" [| t1 |] [| r |]; + insert "fmacond" [| p; t3; t1; t2 |] [| r |] + | Lop(Ifloatofint) -> + let src = regs i.arg and dst = regs i.res in + insert "setf.sig" src dst; + insert "fcvt.xf" dst dst; + insert "fnorm.d" dst dst + | Lop(Iintoffloat) -> + let src = regs i.arg and dst = regs i.res and tmp = new_temp_float() in + insert "fcvt.fx.trunc" src [| tmp |]; + insert "getf.sig" [| tmp |] dst + | Lop(Ispecific(Iadd1)) -> + let s = if Array.length i.arg >= 2 then 1 else 0 in + insimm "add1" [| reg i.arg.(0); reg i.arg.(s) |] "1" (regs i.res) + | Lop(Ispecific(Isub1)) -> + insimm "sub1" (regs i.arg) "1" (regs i.res) + | Lop(Ispecific(Ishladd n)) -> + insimm "shladd" (regs i.arg) (string_of_int n) (regs i.res) + | Lop(Ispecific(Isignextend n)) -> + let op = "sxt" ^ string_of_int n in + insert op (regs i.arg) (regs i.res) + | Lop(Ispecific (Imultaddf | Imultsubf | Isubmultf as sop)) -> + let name = name_for_specific_operation sop in + insert name (regs i.arg) (regs i.res) + | Lop(Ispecific (Istoreincr n)) -> + let op = if i.arg.(1).typ = Float then "stfd+" else "st8+" in + insimm op [| reg i.arg.(0); reg i.arg.(1) |] + (string_of_int n) + [| reg i.res.(0); "heapinit" |] + | Lop(Ispecific Iinitbarrier) -> + insert "#initbarrier" [| "heapinit" |] [| "heap" |] + | Lreloadretaddr -> + let n = frame_size() + 8 in + let tmp = new_temp_reg() in + insimm "addi" [| "sp" |] (string_of_int n) [| tmp |]; + insert "ld8" [| tmp |] [| tmp |]; + insert "movtb" [| tmp |] [| "b0" |] + | Lreturn -> + let n = frame_size() in + if n > 0 then + insimm "addi" [| "sp" |] (string_of_int n) [| "sp" |]; + insert "brret" [| "b0" |] [||]; + end_basic_block() + | Llabel lbl -> + end_basic_block(); + `{emit_label lbl}:\n` + | Lbranch lbl -> + insimm "br" [||] (label lbl) [||]; + end_basic_block() + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + insimm "cmpi.ne" (regs i.arg) "0" [| "p6"; "p0" |] + | Ifalsetest -> + insimm "cmpi.eq" (regs i.arg) "0" [| "p6"; "p0" |] + | Iinttest cmp -> + let comp = "cmp." ^ name_for_int_comparison cmp in + insert comp (regs i.arg) [| "p6"; "p0" |] + | Iinttest_imm(cmp, n) -> + let comp = "cmpi." ^ name_for_swapped_int_comparison cmp in + insimm comp (regs i.arg) (string_of_int n) [| "p6"; "p0" |] + | Ifloattest(cmp, neg) -> + let comp = "fcmp." ^ name_for_float_comparison cmp in + insert comp (regs i.arg) + (if neg then [| "p0"; "p6" |] + else [| "p6"; "p0" |]) + | Ioddtest -> + insimm "tbit.nz" (regs i.arg) "0" [| "p6"; "p0" |] + | Ieventest -> + insimm "tbit.z" (regs i.arg) "0" [| "p6"; "p0" |] + end; + insimm "brcond" [| "p6" |] (label lbl) [||]; + end_basic_block() + | Lcondbranch3(lbl0, lbl1, lbl2) -> + end_basic_block(); + let emit_compare n p = function + None -> () + | Some lbl -> + ` cmp.eq p{emit_int p}, p0 = {emit_int n}, {emit_reg i.arg.(0)}\n` in + let emit_branch p = function + None -> () + | Some lbl -> + ` (p{emit_int p}) br {emit_label lbl}\n` in + emit_compare 0 5 lbl0; emit_compare 1 6 lbl1; emit_compare 2 7 lbl2; + emit_branch 5 lbl0; emit_branch 6 lbl1; emit_branch 7 lbl2; + ` ;;\n` + | Lswitch jumptbl -> + end_basic_block(); + let numcases = Array.length jumptbl in + if numcases <= 9 then begin + for j = 0 to numcases / 3 do + let n = j * 3 in + for k = 0 to 2 do + if n + k < numcases - 1 then + ` cmp.eq p{emit_int(k+5)}, p0 = {emit_int (n+k)}, {emit_reg i.arg.(0)}\n` + done; + for k = 0 to 2 do + if n + k < numcases - 1 then + ` (p{emit_int(k+5)}) br {emit_label jumptbl.(n+k)}\n` + else if n + k = numcases - 1 then + ` br {emit_label jumptbl.(n+k)}\n` + done; + ` ;;\n` + done + end else if numcases <= 47 then begin + ` mov r2 = 1\n`; + ` cmp.eq p6, p0 = 0, {emit_reg i.arg.(0)}\n`; + ` (p6) br {emit_label jumptbl.(0)} ;;\n`; + ` shl r2 = r2, {emit_reg i.arg.(0)}\n`; + ` cmp.eq p7, p0 = 1, {emit_reg i.arg.(0)}\n`; + ` (p7) br {emit_label jumptbl.(1)} ;;\n`; + ` mov pr = r2, -1 ;;\n`; + for i = 2 to numcases - 1 do + ` (p{emit_int i}) br {emit_label jumptbl.(i)}\n` + done; + ` ;;\n` + end else begin + let lbl_jumptbl = new_label() in + let lbl_ip = new_label() in + `{emit_label lbl_ip}: mov r2 = ip ;;\n`; + ` add r2 = {emit_label lbl_jumptbl} - {emit_label lbl_ip}, r2 ;;\n`; + ` shladd r3 = {emit_reg i.arg.(0)}, 2, r2 ;;\n`; + ` ld4 r3 = [r3] ;;\n`; + ` sxt4 r3 = r3 ;;\n`; + ` add r2 = r2, r3 ;;\n`; + ` mov b6 = r2 ;;\n`; + ` br b6 ;;\n`; + ` .align 4\n`; + `{emit_label lbl_jumptbl}:\n`; + for i = 0 to numcases - 1 do + ` data4 {emit_label jumptbl.(i)} - {emit_label lbl_jumptbl}\n` + done; + ` .align 16\n` + end + | Lsetuptrap lbl -> + end_basic_block(); + let lbl_ip = new_label() in + let lbl_next = new_label() in + `{emit_label lbl_ip}: mov r2 = ip ;;\n`; + ` add r2 = {emit_label lbl_next} - {emit_label lbl_ip}, r2\n`; + ` br.sptk {emit_label lbl} ;;\n`; + `{emit_label lbl_next}:\n` + | Lpushtrap -> + end_basic_block(); + stack_offset := !stack_offset + 16; + (* Store trap pointer at sp, handler addr at sp+8, + and decrement sp by 16. Remember, the bottom 16 bytes + of the stack must be left free. *) + ` add r3 = 8, sp\n`; + ` st8 [sp] = r6, -16 ;;\n`; + ` st8 [r3] = r2\n`; + ` add r6 = 16, sp ;;\n` + | Lpoptrap -> + end_basic_block(); + ` add sp = 16, sp ;;\n`; + ` ld8 r6 = [sp] ;;\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + end_basic_block(); + ` mov sp = r6\n`; + ` add r2 = 8, r6\n`; + ` ld8 r6 = [r6] ;;\n`; + ` ld8 r2 = [r2] ;;\n`; + ` mov b6 = r2 ;;\n`; + ` br b6\n` + +let rec emit_all i = + match i.desc with Lend -> () | _ -> emit_instr i; emit_all i.next + +(* Check if a function contains a tail call to itself *) + +let rec is_tailrec i = + match i.desc with + Lend -> false + | Lop(Itailcall_imm s) when s = !function_name -> true + | _ -> is_tailrec i.next + +(* Emission of a function declaration *) + +let fundecl f = + function_name := f.fun_name; + fastcode_flag := f.fun_fast; + stack_offset := 0; + ` .text\n`; + ` .align 4\n`; + ` .global {emit_symbol f.fun_name}#\n`; + ` .proc {emit_symbol f.fun_name}#\n`; + `{emit_symbol f.fun_name}:\n`; + let n = frame_size() in + if !contains_calls then begin + insert "movfb" [| "b0" |] [| "r2" |]; + insimm "addi" [| "sp" |] "8" [| "r3" |]; + insimm "addi" [| "sp" |] (string_of_int (-n)) [| "sp" |]; + insert "st8" [| "r3"; "r2" |] [||] + end + else if n > 0 then + insimm "addi" [| "sp" |] (string_of_int (-n)) [| "sp" |]; + if is_tailrec f.fun_body then begin + tailrec_entry_point := new_label(); + end_basic_block(); + `{emit_label !tailrec_entry_point}:\n` + end; + emit_all f.fun_body; + end_basic_block(); + ` .endp {emit_symbol f.fun_name}#\n` + +(* Emission of data *) + +let emit_global_symbol s = + ` .global {emit_symbol s}#\n`; + ` .type {emit_symbol s}#, @object\n`; + ` .size {emit_symbol s}#, 8\n` + +let emit_define_symbol s = + emit_global_symbol s; + `{emit_symbol s}:\n` + +let emit_item = function + Cglobal_symbol s -> + emit_global_symbol s + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)}:\n` + | Cint8 n -> + ` data1 {emit_int n}\n` + | Cint16 n -> + ` data2 {emit_int n}\n` + | Cint32 n -> + let n' = Nativeint.shift_right (Nativeint.shift_left n 32) 32 in + ` data4 {emit_nativeint n'}\n` + | Cint n -> + ` data8 {emit_nativeint n}\n` + | Csingle f -> + ` real4 {emit_string f}\n` + | Cdouble f -> + ` real8 {emit_string f}\n` + | Csymbol_address s -> + ` data8 {emit_symbol s}#\n` + | Clabel_address lbl -> + ` data8 {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_string_directive " string " s + | Cskip n -> + if n > 0 then ` .skip {emit_int n}\n` + | Calign n -> + ` .align {emit_int n}\n` + +let data l = + ` .data\n`; + ` .align 8\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + ` .data\n`; + emit_define_symbol (Compilenv.make_symbol (Some "data_begin")); + ` .text\n`; + emit_define_symbol (Compilenv.make_symbol (Some "code_begin")) + +let end_assembly () = + ` .data\n`; + emit_define_symbol (Compilenv.make_symbol (Some "data_end")); + ` .text\n`; + emit_define_symbol (Compilenv.make_symbol (Some "code_end")); + ` .rodata\n`; + ` .align 8\n`; + emit_define_symbol (Compilenv.make_symbol (Some "frametable")); + ` data8 {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + frame_descriptors := [] diff --git a/asmcomp/ia64/proc.ml b/asmcomp/ia64/proc.ml new file mode 100644 index 0000000..00b969b --- /dev/null +++ b/asmcomp/ia64/proc.ml @@ -0,0 +1,217 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.6 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the IA64 processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = false + +(* Registers available for register allocation *) + +(* Register map: + r0 always 0 + r1 global pointer (gp) + r2 - r3 temporaries (for the code generator) + r4 allocation pointer + r5 allocation limit + r6 trap pointer + r7 saved gp during C calls (preserved by C) + r8 - r11 0 - 3 function results + r12 stack pointer + r13 reserved by C (thread-specific data) + r14 - r15 80 - 81 temporaries (for accessing stack variables) + r16 - r31 4 - 19 general purpose + r32 - r63 20 - 51 function arguments + r64 - r91 52 - 79 general purpose + r92 - r95 used by C glue code + + We do not use register windows, but instead allocate 64 "out" registers + (r32-r95) when entering Caml code. + + f0 always 0.0 + f1 always 1.0 + f2 - f5 100 - 103 general purpose (preserved by C) + f6 - f7 104 - 105 general purpose + f8 - f15 106 - 113 function results + f16 - f31 114 - 129 function arguments (preserved by C) + f32 - f63 130 - 161 general purpose + f64 - f66 temporaries + f67 - f127 unused +*) + +let int_reg_name = [| + (* 0-3 *) "r8"; "r9"; "r10"; "r11"; + (* 4-19 *) "r16"; "r17"; "r18"; "r19"; "r20"; "r21"; "r22"; "r23"; + "r24"; "r25"; "r26"; "r27"; "r28"; "r29"; "r30"; "r31"; + (* 20-51 *) "r32"; "r33"; "r34"; "r35"; "r36"; "r37"; "r38"; "r39"; + "r40"; "r41"; "r42"; "r43"; "r44"; "r45"; "r46"; "r47"; + "r48"; "r49"; "r50"; "r51"; "r52"; "r53"; "r54"; "r55"; + "r56"; "r57"; "r58"; "r59"; "r60"; "r61"; "r62"; "r63"; + (* 52-79 *) "r64"; "r65"; "r66"; "r67"; "r68"; "r69"; "r70"; "r71"; + "r72"; "r73"; "r74"; "r75"; "r76"; "r77"; "r78"; "r79"; + "r80"; "r81"; "r82"; "r83"; "r84"; "r85"; "r86"; "r87"; + "r88"; "r89"; "r90"; "r91"; + (* 80-81 *) "r14"; "r15" +|] + +let float_reg_name = [| + (* 0-13 *) "f2"; "f3"; "f4"; "f5"; "f6"; "f7"; + "f8"; "f9"; "f10"; "f11"; "f12"; "f13"; "f14"; "f15"; + (* 14-29 *) "f16"; "f17"; "f18"; "f19"; "f20"; "f21"; "f22"; "f23"; + "f24"; "f25"; "f26"; "f27"; "f28"; "f29"; "f30"; "f31"; + (* 30-61 *) "f32"; "f33"; "f34"; "f35"; "f36"; "f37"; "f38"; "f39"; + "f40"; "f41"; "f42"; "f43"; "f44"; "f45"; "f46"; "f47"; + "f48"; "f49"; "f50"; "f51"; "f52"; "f53"; "f54"; "f55"; + "f56"; "f57"; "f58"; "f59"; "f60"; "f61"; "f62"; "f63" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 80; 62 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 82 Reg.dummy in + for i = 0 to 81 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 62 Reg.dummy in + for i = 0 to 61 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float + lockstep make_stack arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int; + if lockstep then incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float; + if lockstep then incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 20 51 114 129 false outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 20 51 114 129 false incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 3 106 113 false not_supported res + in loc +(* Arguments in r32...r39, f8...f15 + Results in r8...r11, f8...f15 *) +let loc_external_arguments arg = + calling_conventions 20 27 106 113 true outgoing arg +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 3 106 113 false not_supported res + in loc +let extcall_use_push = false + +let loc_exn_bucket = phys_reg 0 (* r8 *) + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* f2...f5, f16...f31 preserved by C *) + Array.append + hard_int_reg + (Array.of_list(List.map phys_reg + [100;101;102;103;104;105;106;107;108;109;110;111;112;113; + 130;131;132;133;134;135;136;137;138;139; + 140;141;142;143;144;145;146;147;148;149; + 150;151;152;153;154;155;156;157;158;159; + 160;161])) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 0 + | _ -> 62 +let max_register_pressure = function + Iextcall(_, _) -> [| 0; 20 |] + | _ -> num_available_registers + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/ia64/reload.ml b/asmcomp/ia64/reload.ml new file mode 100644 index 0000000..8a75ca8 --- /dev/null +++ b/asmcomp/ia64/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.2 2000-07-16 02:57:31 xleroy Exp $ *) + +(* Reloading for the IA64. *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/ia64/scheduling.ml b/asmcomp/ia64/scheduling.ml new file mode 100644 index 0000000..85f9ea5 --- /dev/null +++ b/asmcomp/ia64/scheduling.ml @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.3 2000-07-16 02:57:31 xleroy Exp $ *) + +open Schedgen (* to create a dependency *) + +(* We don't schedule here on the linearized code, but instead schedule the + assembly code generated in Emit. *) + +let fundecl f = f diff --git a/asmcomp/ia64/selection.ml b/asmcomp/ia64/selection.ml new file mode 100644 index 0000000..a41247e --- /dev/null +++ b/asmcomp/ia64/selection.ml @@ -0,0 +1,178 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.7 2004-05-03 12:27:07 xleroy Exp $ *) + +(* Instruction selection for the IA64 processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Helper function for add selection *) + +let reassociate_add = function + [Cconst_int n; arg] -> + [arg; Cconst_int n] + | [Cop(Caddi, [arg1; Cconst_int n]); arg3] -> + [Cop(Caddi, [arg1; arg3]); Cconst_int n] + | [Cop(Caddi, [Cconst_int n; arg1]); arg3] -> + [Cop(Caddi, [arg1; arg3]); Cconst_int n] + | [arg1; Cop(Caddi, [Cconst_int n; arg3])] -> + [Cop(Caddi, [arg1; arg3]); Cconst_int n] + | [arg1; Cop(Caddi, [arg2; arg3])] -> + [Cop(Caddi, [arg1; arg2]); arg3] + | args -> args + +(* Helper function for mult-immediate selection *) + +let rec count_one_bits n = + if n = 0 then 0 + else if n land 1 = 0 then count_one_bits (n lsr 1) + else 1 + count_one_bits (n lsr 1) + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +(* Range of immediate arguments: + add 14-bit signed + sub turned into add + sub reversed 8-bit signed + mul at most 16 "one" bits + div, mod powers of 2 + and, or, xor 8-bit signed + lsl, lsr, asr 6-bit unsigned + cmp 8-bit signed + For is_immediate, we put 8-bit signed and treat adds specially + (selectgen already does the right thing for shifts) *) + +method is_immediate n = n >= -128 && n < 128 + +method is_immediate_add n = n >= -8192 && n < 8192 + +method select_addressing arg = (Iindexed, arg) + +method select_operation op args = + let norm_op = + match op with Cadda -> Caddi | Csuba -> Csubi | _ -> op in + let norm_args = + match norm_op with Caddi -> reassociate_add args | _ -> args in + match (norm_op, norm_args) with + (* Recognize x + y + 1 and x - y - 1 *) + | (Caddi, [Cop(Caddi, [arg1; arg2]); Cconst_int 1]) -> + (Ispecific Iadd1, [arg1; arg2]) + | (Caddi, [Cop(Clsl, [arg1; Cconst_int 1]); Cconst_int 1]) -> + (Ispecific Iadd1, [arg1]) + | (Csubi, [Cop(Csubi, [arg1; arg2]); Cconst_int 1]) -> + (Ispecific Isub1, [arg1; arg2]) + | (Csubi, [Cop(Csubi, [arg1; Cconst_int 1]); arg2]) -> + (Ispecific Isub1, [arg1; arg2]) + (* Recognize add immediate *) + | (Caddi, [arg; Cconst_int n]) when self#is_immediate_add n -> + (Iintop_imm(Iadd, n), [arg]) + (* Turn sub immediate into add immediate *) + | (Csubi, [arg; Cconst_int n]) when self#is_immediate_add (-n) -> + (Iintop_imm(Iadd, -n), [arg]) + (* Recognize imm - arg *) + | (Csubi, [Cconst_int n; arg]) when self#is_immediate n -> + (Iintop_imm(Isub, n), [arg]) + (* Recognize shift-add operations *) + | (Caddi, [arg2; Cop(Clsl, [arg1; Cconst_int(1|2|3|4 as shift)])]) -> + (Ispecific(Ishladd shift), [arg1; arg2]) + | (Caddi, [Cop(Clsl, [arg1; Cconst_int(1|2|3|4 as shift)]); arg2]) -> + (Ispecific(Ishladd shift), [arg1; arg2]) + (* Recognize truncation/normalization of 64-bit integers to 32 bits *) + | (Casr, [Cop(Clsl, [arg; Cconst_int 32]); Cconst_int 32]) -> + (Ispecific (Isignextend 4), [arg]) + (* Recognize x * cst and cst * x *) + | (Cmuli, [arg; Cconst_int n]) -> + self#select_imul_imm arg n + | (Cmuli, [Cconst_int n; arg]) -> + self#select_imul_imm arg n + (* Prevent the recognition of (x / cst) and (x % cst) when cst is not + a power of 2, which do not correspond to an instruction. + Turn general division and modulus into calls to C library functions *) + | (Cdivi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg]) + | (Cdivi, _) -> + (Iextcall("__divdi3", false), args) + | (Cmodi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) && n <> 1 -> + (Iintop_imm(Imod, n), [arg]) + | (Cmodi, _) -> + (Iextcall("__moddi3", false), args) + (* Recognize mult-add and mult-sub instructions *) + | (Caddf, [Cop(Cmulf, [arg1; arg2]); arg3]) -> + (Ispecific Imultaddf, [arg1; arg2; arg3]) + | (Caddf, [arg3; Cop(Cmulf, [arg1; arg2])]) -> + (Ispecific Imultaddf, [arg1; arg2; arg3]) + | (Csubf, [Cop(Cmulf, [arg1; arg2]); arg3]) -> + (Ispecific Imultsubf, [arg1; arg2; arg3]) + | (Csubf, [arg3; Cop(Cmulf, [arg1; arg2])]) -> + (Ispecific Isubmultf, [arg1; arg2; arg3]) + (* Use default selector otherwise *) + | _ -> + super#select_operation op args + +method private select_imul_imm arg n = + if count_one_bits n <= 16 + then (Iintop_imm(Imul, n), [arg]) + else (Iintop Imul, [arg; Cconst_int n]) + +(* To palliate the lack of addressing with displacement, multiple + stores to the address r are translated as follows + (t1 and t2 are two temp regs) + t1 := r - 8 + t2 := r + compute data1 in reg1 + compute data2 in reg2 + store reg1 at t1 and increment t1 by 16 + store reg2 at t2 and increment t2 by 16 + compute data3 in reg3 + compute data4 in reg4 + store reg3 at t1 and increment t1 by 16 + store reg4 at t2 and increment t2 by 16 + ... + Note: we use two temp regs and perform stores by groups of 2 + in order to expose more instruction-level parallelism. *) +method emit_stores env data regs_addr = + let t1 = Reg.create Addr and t2 = Reg.create Addr in + self#insert (Iop(Iintop_imm(Iadd, -8))) regs_addr [|t1|]; + self#insert (Iop Imove) regs_addr [|t2|]; + (* Store components by batch of 2 *) + let backlog = ref None in + let do_store r = + match !backlog with + None -> (* keep it for later *) + backlog := Some r + | Some r' -> (* store r' at t1 and r at t2 *) + self#insert (Iop(Ispecific(Istoreincr 16))) [| t1; r' |] [| t1 |]; + self#insert (Iop(Ispecific(Istoreincr 16))) [| t2; r |] [| t2 |]; + backlog := None in + List.iter + (fun exp -> + match self#emit_expr env exp with + None -> assert false + | Some regs -> Array.iter do_store regs) + data; + (* Store the backlog if any *) + begin match !backlog with + None -> () + | Some r -> self#insert (Iop(Ispecific(Istoreincr 16))) [| t1; r |] [| t1 |] + end; + (* Insert an init barrier *) + self#insert (Iop(Ispecific Iinitbarrier)) [||] [||] +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/interf.ml b/asmcomp/interf.ml new file mode 100644 index 0000000..5fadcb5 --- /dev/null +++ b/asmcomp/interf.ml @@ -0,0 +1,173 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: interf.ml,v 1.15 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Construction of the interference graph. + Annotate pseudoregs with interference lists and preference lists. *) + +module IntPairSet = + Set.Make(struct type t = int * int let compare = compare end) + +open Misc +open Reg +open Mach + +let build_graph fundecl = + + (* The interference graph is represented in two ways: + - by adjacency lists for each register + - by a sparse bit matrix (a set of pairs of register stamps) *) + + let mat = ref IntPairSet.empty in + + (* Record an interference between two registers *) + let add_interf ri rj = + let i = ri.stamp and j = rj.stamp in + if i <> j then begin + let p = if i < j then (i, j) else (j, i) in + if not(IntPairSet.mem p !mat) then begin + mat := IntPairSet.add p !mat; + if ri.loc = Unknown then ri.interf <- rj :: ri.interf; + if rj.loc = Unknown then rj.interf <- ri :: rj.interf + end + end in + + (* Record interferences between a register array and a set of registers *) + let add_interf_set v s = + for i = 0 to Array.length v - 1 do + let r1 = v.(i) in + Reg.Set.iter (add_interf r1) s + done in + + (* Record interferences between elements of an array *) + let add_interf_self v = + for i = 0 to Array.length v - 2 do + let ri = v.(i) in + for j = i+1 to Array.length v - 1 do + add_interf ri v.(j) + done + done in + + (* Record interferences between the destination of a move and a set + of live registers. Since the destination is equal to the source, + do not add an interference between them if the source is still live + afterwards. *) + let add_interf_move src dst s = + Reg.Set.iter (fun r -> if r.stamp <> src.stamp then add_interf dst r) s in + + (* Compute interferences *) + + let rec interf i = + let destroyed = Proc.destroyed_at_oper i.desc in + if Array.length destroyed > 0 then add_interf_set destroyed i.live; + match i.desc with + Iend -> () + | Ireturn -> () + | Iop(Imove | Ispill | Ireload) -> + add_interf_move i.arg.(0) i.res.(0) i.live; + interf i.next + | Iop(Itailcall_ind) -> () + | Iop(Itailcall_imm lbl) -> () + | Iop op -> + add_interf_set i.res i.live; + add_interf_self i.res; + interf i.next + | Iifthenelse(tst, ifso, ifnot) -> + interf ifso; + interf ifnot; + interf i.next + | Iswitch(index, cases) -> + for i = 0 to Array.length cases - 1 do + interf cases.(i) + done; + interf i.next + | Iloop body -> + interf body; interf i.next + | Icatch(_, body, handler) -> + interf body; interf handler; interf i.next + | Iexit _ -> + () + | Itrywith(body, handler) -> + add_interf_set Proc.destroyed_at_raise handler.live; + interf body; interf handler; interf i.next + | Iraise -> () in + + (* Add a preference from one reg to another. + Do not add anything if the two registers conflict, + or if the source register already has a location. *) + + let add_pref weight r1 r2 = + if weight > 0 then begin + let i = r1.stamp and j = r2.stamp in + if i <> j + && r1.loc = Unknown + && (let p = if i < j then (i, j) else (j, i) in + not (IntPairSet.mem p !mat)) + then r1.prefer <- (r2, weight) :: r1.prefer + end in + + (* Add a mutual preference between two regs *) + let add_mutual_pref weight r1 r2 = + add_pref weight r1 r2; add_pref weight r2 r1 in + + (* Update the spill cost of the registers involved in an operation *) + + let add_spill_cost cost arg = + for i = 0 to Array.length arg - 1 do + let r = arg.(i) in r.spill_cost <- r.spill_cost + cost + done in + + (* Compute preferences and spill costs *) + + let rec prefer weight i = + add_spill_cost weight i.arg; + add_spill_cost weight i.res; + match i.desc with + Iend -> () + | Ireturn -> () + | Iop(Imove) -> + add_mutual_pref weight i.arg.(0) i.res.(0); + prefer weight i.next + | Iop(Ispill) -> + add_pref (weight / 4) i.arg.(0) i.res.(0); + prefer weight i.next + | Iop(Ireload) -> + add_pref (weight / 4) i.res.(0) i.arg.(0); + prefer weight i.next + | Iop(Itailcall_ind) -> () + | Iop(Itailcall_imm lbl) -> () + | Iop op -> + prefer weight i.next + | Iifthenelse(tst, ifso, ifnot) -> + prefer (weight / 2) ifso; + prefer (weight / 2) ifnot; + prefer weight i.next + | Iswitch(index, cases) -> + for i = 0 to Array.length cases - 1 do + prefer (weight / 2) cases.(i) + done; + prefer weight i.next + | Iloop body -> + (* Avoid overflow of weight and spill_cost *) + prefer (if weight < 1000 then 8 * weight else weight) body; + prefer weight i.next + | Icatch(_, body, handler) -> + prefer weight body; prefer weight handler; prefer weight i.next + | Iexit _ -> + () + | Itrywith(body, handler) -> + prefer weight body; prefer weight handler; prefer weight i.next + | Iraise -> () + in + + interf fundecl.fun_body; prefer 8 fundecl.fun_body diff --git a/asmcomp/interf.mli b/asmcomp/interf.mli new file mode 100644 index 0000000..2f36552 --- /dev/null +++ b/asmcomp/interf.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: interf.mli,v 1.4 1999-11-17 18:56:33 xleroy Exp $ *) + +(* Construction of the interference graph. + Annotate pseudoregs with interference lists and preference lists. *) + +val build_graph: Mach.fundecl -> unit diff --git a/asmcomp/linearize.ml b/asmcomp/linearize.ml new file mode 100644 index 0000000..a562faa --- /dev/null +++ b/asmcomp/linearize.ml @@ -0,0 +1,267 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: linearize.ml,v 1.25 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Transformation of Mach code into a list of pseudo-instructions. *) + +open Reg +open Mach + +type label = int + +let label_counter = ref 99 + +let new_label() = incr label_counter; !label_counter + +type instruction = + { mutable desc: instruction_desc; + mutable next: instruction; + arg: Reg.t array; + res: Reg.t array; + dbg: Debuginfo.t; + live: Reg.Set.t } + +and instruction_desc = + Lend + | Lop of operation + | Lreloadretaddr + | Lreturn + | Llabel of label + | Lbranch of label + | Lcondbranch of test * label + | Lcondbranch3 of label option * label option * label option + | Lswitch of label array + | Lsetuptrap of label + | Lpushtrap + | Lpoptrap + | Lraise + +let has_fallthrough = function + | Lreturn | Lbranch _ | Lswitch _ | Lraise + | Lop Itailcall_ind | Lop (Itailcall_imm _) -> false + | _ -> true + +type fundecl = + { fun_name: string; + fun_body: instruction; + fun_fast: bool } + +(* Invert a test *) + +let invert_integer_test = function + Isigned cmp -> Isigned(Cmm.negate_comparison cmp) + | Iunsigned cmp -> Iunsigned(Cmm.negate_comparison cmp) + +let invert_test = function + Itruetest -> Ifalsetest + | Ifalsetest -> Itruetest + | Iinttest(cmp) -> Iinttest(invert_integer_test cmp) + | Iinttest_imm(cmp, n) -> Iinttest_imm(invert_integer_test cmp, n) + | Ifloattest(cmp, neg) -> Ifloattest(cmp, not neg) + | Ieventest -> Ioddtest + | Ioddtest -> Ieventest + +(* The "end" instruction *) + +let rec end_instr = + { desc = Lend; + next = end_instr; + arg = [||]; + res = [||]; + dbg = Debuginfo.none; + live = Reg.Set.empty } + +(* Cons an instruction (live, debug empty) *) + +let instr_cons d a r n = + { desc = d; next = n; arg = a; res = r; + dbg = Debuginfo.none; live = Reg.Set.empty } + +(* Cons a simple instruction (arg, res, live empty) *) + +let cons_instr d n = + { desc = d; next = n; arg = [||]; res = [||]; + dbg = Debuginfo.none; live = Reg.Set.empty } + +(* Build an instruction with arg, res, dbg, live taken from + the given Mach.instruction *) + +let copy_instr d i n = + { desc = d; next = n; + arg = i.Mach.arg; res = i.Mach.res; + dbg = i.Mach.dbg; live = i.Mach.live } + +(* + Label the beginning of the given instruction sequence. + - If the sequence starts with a branch, jump over it. + - If the sequence is the end, (tail call position), just do nothing +*) + +let get_label n = match n.desc with + Lbranch lbl -> (lbl, n) + | Llabel lbl -> (lbl, n) + | Lend -> (-1, n) + | _ -> let lbl = new_label() in (lbl, cons_instr (Llabel lbl) n) + +(* Check the fallthrough label *) +let check_label n = match n.desc with + | Lbranch lbl -> lbl + | Llabel lbl -> lbl + | _ -> -1 + +(* Discard all instructions up to the next label. + This function is to be called before adding a non-terminating + instruction. *) + +let rec discard_dead_code n = + match n.desc with + Lend -> n + | Llabel _ -> n +(* Do not discard Lpoptrap or Istackoffset instructions, + as this may cause a stack imbalance later during assembler generation. *) + | Lpoptrap -> n + | Lop(Istackoffset _) -> n + | _ -> discard_dead_code n.next + +(* + Add a branch in front of a continuation. + Discard dead code in the continuation. + Does not insert anything if we're just falling through + or if we jump to dead code after the end of function (lbl=-1) +*) + +let add_branch lbl n = + if lbl >= 0 then + let n1 = discard_dead_code n in + match n1.desc with + | Llabel lbl1 when lbl1 = lbl -> n1 + | _ -> cons_instr (Lbranch lbl) n1 + else + discard_dead_code n + +(* Current labels for exit handler *) + +let exit_label = ref [] + +let find_exit_label k = + try + List.assoc k !exit_label + with + | Not_found -> Misc.fatal_error "Linearize.find_exit_label" + +let is_next_catch n = match !exit_label with +| (n0,_)::_ when n0=n -> true +| _ -> false + +(* Linearize an instruction [i]: add it in front of the continuation [n] *) + +let rec linear i n = + match i.Mach.desc with + Iend -> n + | Iop(Itailcall_ind | Itailcall_imm _ as op) -> + copy_instr (Lop op) i (discard_dead_code n) + | Iop(Imove | Ireload | Ispill) + when i.Mach.arg.(0).loc = i.Mach.res.(0).loc -> + linear i.Mach.next n + | Iop op -> + copy_instr (Lop op) i (linear i.Mach.next n) + | Ireturn -> + let n1 = copy_instr Lreturn i (discard_dead_code n) in + if !Proc.contains_calls + then cons_instr Lreloadretaddr n1 + else n1 + | Iifthenelse(test, ifso, ifnot) -> + let n1 = linear i.Mach.next n in + begin match (ifso.Mach.desc, ifnot.Mach.desc, n1.desc) with + Iend, _, Lbranch lbl -> + copy_instr (Lcondbranch(test, lbl)) i (linear ifnot n1) + | _, Iend, Lbranch lbl -> + copy_instr (Lcondbranch(invert_test test, lbl)) i (linear ifso n1) + | Iexit nfail1, Iexit nfail2, _ + when is_next_catch nfail1 -> + let lbl2 = find_exit_label nfail2 in + copy_instr + (Lcondbranch (invert_test test, lbl2)) i (linear ifso n1) + | Iexit nfail, _, _ -> + let n2 = linear ifnot n1 + and lbl = find_exit_label nfail in + copy_instr (Lcondbranch(test, lbl)) i n2 + | _, Iexit nfail, _ -> + let n2 = linear ifso n1 in + let lbl = find_exit_label nfail in + copy_instr (Lcondbranch(invert_test test, lbl)) i n2 + | Iend, _, _ -> + let (lbl_end, n2) = get_label n1 in + copy_instr (Lcondbranch(test, lbl_end)) i (linear ifnot n2) + | _, Iend, _ -> + let (lbl_end, n2) = get_label n1 in + copy_instr (Lcondbranch(invert_test test, lbl_end)) i + (linear ifso n2) + | _, _, _ -> + (* Should attempt branch prediction here *) + let (lbl_end, n2) = get_label n1 in + let (lbl_else, nelse) = get_label (linear ifnot n2) in + copy_instr (Lcondbranch(invert_test test, lbl_else)) i + (linear ifso (add_branch lbl_end nelse)) + end + | Iswitch(index, cases) -> + let lbl_cases = Array.create (Array.length cases) 0 in + let (lbl_end, n1) = get_label(linear i.Mach.next n) in + let n2 = ref (discard_dead_code n1) in + for i = Array.length cases - 1 downto 0 do + let (lbl_case, ncase) = + get_label(linear cases.(i) (add_branch lbl_end !n2)) in + lbl_cases.(i) <- lbl_case; + n2 := discard_dead_code ncase + done; + (* Switches with 1 and 2 branches have been eliminated earlier. + Here, we do something for switches with 3 branches. *) + if Array.length index = 3 then begin + let fallthrough_lbl = check_label !n2 in + let find_label n = + let lbl = lbl_cases.(index.(n)) in + if lbl = fallthrough_lbl then None else Some lbl in + copy_instr (Lcondbranch3(find_label 0, find_label 1, find_label 2)) + i !n2 + end else + copy_instr (Lswitch(Array.map (fun n -> lbl_cases.(n)) index)) i !n2 + | Iloop body -> + let lbl_head = new_label() in + let n1 = linear i.Mach.next n in + let n2 = linear body (cons_instr (Lbranch lbl_head) n1) in + cons_instr (Llabel lbl_head) n2 + | Icatch(io, body, handler) -> + let (lbl_end, n1) = get_label(linear i.Mach.next n) in + let (lbl_handler, n2) = get_label(linear handler n1) in + exit_label := (io, lbl_handler) :: !exit_label ; + let n3 = linear body (add_branch lbl_end n2) in + exit_label := List.tl !exit_label; + n3 + | Iexit nfail -> + let n1 = linear i.Mach.next n in + let lbl = find_exit_label nfail in + add_branch lbl n1 + | Itrywith(body, handler) -> + let (lbl_join, n1) = get_label (linear i.Mach.next n) in + let (lbl_body, n2) = + get_label (cons_instr Lpushtrap + (linear body (cons_instr Lpoptrap n1))) in + cons_instr (Lsetuptrap lbl_body) + (linear handler (add_branch lbl_join n2)) + | Iraise -> + copy_instr Lraise i (discard_dead_code n) + +let fundecl f = + { fun_name = f.Mach.fun_name; + fun_body = linear f.Mach.fun_body end_instr; + fun_fast = f.Mach.fun_fast } diff --git a/asmcomp/linearize.mli b/asmcomp/linearize.mli new file mode 100644 index 0000000..de87d87 --- /dev/null +++ b/asmcomp/linearize.mli @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: linearize.mli,v 1.14 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Transformation of Mach code into a list of pseudo-instructions. *) + +type label = int +val new_label: unit -> label + +type instruction = + { mutable desc: instruction_desc; + mutable next: instruction; + arg: Reg.t array; + res: Reg.t array; + dbg: Debuginfo.t; + live: Reg.Set.t } + +and instruction_desc = + Lend + | Lop of Mach.operation + | Lreloadretaddr + | Lreturn + | Llabel of label + | Lbranch of label + | Lcondbranch of Mach.test * label + | Lcondbranch3 of label option * label option * label option + | Lswitch of label array + | Lsetuptrap of label + | Lpushtrap + | Lpoptrap + | Lraise + +val has_fallthrough : instruction_desc -> bool +val end_instr: instruction +val instr_cons: + instruction_desc -> Reg.t array -> Reg.t array -> instruction -> instruction +val invert_test: Mach.test -> Mach.test + +type fundecl = + { fun_name: string; + fun_body: instruction; + fun_fast: bool } + +val fundecl: Mach.fundecl -> fundecl + diff --git a/asmcomp/liveness.ml b/asmcomp/liveness.ml new file mode 100644 index 0000000..4a00523 --- /dev/null +++ b/asmcomp/liveness.ml @@ -0,0 +1,120 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: liveness.ml,v 1.15 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Liveness analysis. + Annotate mach code with the set of regs live at each point. *) + +open Mach + +let live_at_exit = ref [] +let find_live_at_exit k = + try + List.assoc k !live_at_exit + with + | Not_found -> Misc.fatal_error "Spill.find_live_at_exit" + +let live_at_break = ref Reg.Set.empty +let live_at_raise = ref Reg.Set.empty + +let rec live i finally = + (* finally is the set of registers live after execution of the + instruction sequence. + The result of the function is the set of registers live just + before the instruction sequence. + The instruction i is annotated by the set of registers live across + the instruction. *) + match i.desc with + Iend -> + i.live <- finally; + finally + | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> + (* i.live remains empty since no regs are live across *) + Reg.set_of_array i.arg + | Iifthenelse(test, ifso, ifnot) -> + let at_join = live i.next finally in + let at_fork = Reg.Set.union (live ifso at_join) (live ifnot at_join) in + i.live <- at_fork; + Reg.add_set_array at_fork i.arg + | Iswitch(index, cases) -> + let at_join = live i.next finally in + let at_fork = ref Reg.Set.empty in + for i = 0 to Array.length cases - 1 do + at_fork := Reg.Set.union !at_fork (live cases.(i) at_join) + done; + i.live <- !at_fork; + Reg.add_set_array !at_fork i.arg + | Iloop(body) -> + let at_top = ref Reg.Set.empty in + (* Yes, there are better algorithms, but we'll just iterate till + reaching a fixpoint. *) + begin try + while true do + let new_at_top = Reg.Set.union !at_top (live body !at_top) in + if Reg.Set.equal !at_top new_at_top then raise Exit; + at_top := new_at_top + done + with Exit -> () + end; + i.live <- !at_top; + !at_top + | Icatch(nfail, body, handler) -> + let at_join = live i.next finally in + let before_handler = live handler at_join in + let before_body = + live_at_exit := (nfail,before_handler) :: !live_at_exit ; + let before_body = live body at_join in + live_at_exit := List.tl !live_at_exit ; + before_body in + i.live <- before_body; + before_body + | Iexit nfail -> + let this_live = find_live_at_exit nfail in + i.live <- this_live ; + this_live + | Itrywith(body, handler) -> + let at_join = live i.next finally in + let before_handler = live handler at_join in + let saved_live_at_raise = !live_at_raise in + live_at_raise := Reg.Set.remove Proc.loc_exn_bucket before_handler; + let before_body = live body at_join in + live_at_raise := saved_live_at_raise; + i.live <- before_body; + before_body + | Iraise -> + (* i.live remains empty since no regs are live across *) + Reg.add_set_array !live_at_raise i.arg + | _ -> + let across_after = Reg.diff_set_array (live i.next finally) i.res in + let across = + match i.desc with + Iop Icall_ind | Iop(Icall_imm _) | Iop(Iextcall _) + | Iop(Iintop Icheckbound) | Iop(Iintop_imm(Icheckbound, _)) -> + (* The function call may raise an exception, branching to the + nearest enclosing try ... with. Similarly for bounds checks. + Hence, everything that must be live at the beginning of + the exception handler must also be live across this instr. *) + Reg.Set.union across_after !live_at_raise + | _ -> + across_after in + i.live <- across; + Reg.add_set_array across i.arg + +let fundecl ppf f = + let initially_live = live f.fun_body Reg.Set.empty in + (* Sanity check: only function parameters can be live at entrypoint *) + let wrong_live = Reg.Set.diff initially_live (Reg.set_of_array f.fun_args) in + if not (Reg.Set.is_empty wrong_live) then begin + Format.fprintf ppf "%a@." Printmach.regset wrong_live; + Misc.fatal_error "Liveness.fundecl" + end diff --git a/asmcomp/liveness.mli b/asmcomp/liveness.mli new file mode 100644 index 0000000..e643e45 --- /dev/null +++ b/asmcomp/liveness.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: liveness.mli,v 1.5 2000-04-21 08:10:33 weis Exp $ *) + +(* Liveness analysis. + Annotate mach code with the set of regs live at each point. *) + +open Format + +val fundecl: formatter -> Mach.fundecl -> unit diff --git a/asmcomp/m68k/README b/asmcomp/m68k/README new file mode 100644 index 0000000..fe5479d --- /dev/null +++ b/asmcomp/m68k/README @@ -0,0 +1,8 @@ +As of Feb 4th 2000, the native-code compiler for the Motorola 680x0 is +no longer maintained and thus deprecated. + +The only machines on which we could test this port (Sun 3, SunOS 4) +here at INRIA are being retired, and were so slow that the port wasn't +kept up-to-date with the remainder of the system. + +- Xavier Leroy, for the Objective Caml development team. diff --git a/asmcomp/mach.ml b/asmcomp/mach.ml new file mode 100644 index 0000000..60a0cf9 --- /dev/null +++ b/asmcomp/mach.ml @@ -0,0 +1,132 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: mach.ml,v 1.18 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Representation of machine code by sequences of pseudoinstructions *) + +type integer_comparison = + Isigned of Cmm.comparison + | Iunsigned of Cmm.comparison + +type integer_operation = + Iadd | Isub | Imul | Idiv | Imod + | Iand | Ior | Ixor | Ilsl | Ilsr | Iasr + | Icomp of integer_comparison + | Icheckbound + +type test = + Itruetest + | Ifalsetest + | Iinttest of integer_comparison + | Iinttest_imm of integer_comparison * int + | Ifloattest of Cmm.comparison * bool + | Ioddtest + | Ieventest + +type operation = + Imove + | Ispill + | Ireload + | Iconst_int of nativeint + | Iconst_float of string + | Iconst_symbol of string + | Icall_ind + | Icall_imm of string + | Itailcall_ind + | Itailcall_imm of string + | Iextcall of string * bool + | Istackoffset of int + | Iload of Cmm.memory_chunk * Arch.addressing_mode + | Istore of Cmm.memory_chunk * Arch.addressing_mode + | Ialloc of int + | Iintop of integer_operation + | Iintop_imm of integer_operation * int + | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf + | Ifloatofint | Iintoffloat + | Ispecific of Arch.specific_operation + +type instruction = + { desc: instruction_desc; + next: instruction; + arg: Reg.t array; + res: Reg.t array; + dbg: Debuginfo.t; + mutable live: Reg.Set.t } + +and instruction_desc = + Iend + | Iop of operation + | Ireturn + | Iifthenelse of test * instruction * instruction + | Iswitch of int array * instruction array + | Iloop of instruction + | Icatch of int * instruction * instruction + | Iexit of int + | Itrywith of instruction * instruction + | Iraise + +type fundecl = + { fun_name: string; + fun_args: Reg.t array; + fun_body: instruction; + fun_fast: bool } + +let rec dummy_instr = + { desc = Iend; + next = dummy_instr; + arg = [||]; + res = [||]; + dbg = Debuginfo.none; + live = Reg.Set.empty } + +let end_instr () = + { desc = Iend; + next = dummy_instr; + arg = [||]; + res = [||]; + dbg = Debuginfo.none; + live = Reg.Set.empty } + +let instr_cons d a r n = + { desc = d; next = n; arg = a; res = r; + dbg = Debuginfo.none; live = Reg.Set.empty } + +let instr_cons_debug d a r dbg n = + { desc = d; next = n; arg = a; res = r; dbg = dbg; live = Reg.Set.empty } + +let rec instr_iter f i = + match i.desc with + Iend -> () + | _ -> + f i; + match i.desc with + Iend -> () + | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> () + | Iifthenelse(tst, ifso, ifnot) -> + instr_iter f ifso; instr_iter f ifnot; instr_iter f i.next + | Iswitch(index, cases) -> + for i = 0 to Array.length cases - 1 do + instr_iter f cases.(i) + done; + instr_iter f i.next + | Iloop(body) -> + instr_iter f body; instr_iter f i.next + | Icatch(_, body, handler) -> + instr_iter f body; instr_iter f handler; instr_iter f i.next + | Iexit _ -> () + | Itrywith(body, handler) -> + instr_iter f body; instr_iter f handler; instr_iter f i.next + | Iraise -> () + | _ -> + instr_iter f i.next + diff --git a/asmcomp/mach.mli b/asmcomp/mach.mli new file mode 100644 index 0000000..3cf6308 --- /dev/null +++ b/asmcomp/mach.mli @@ -0,0 +1,93 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: mach.mli,v 1.18 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Representation of machine code by sequences of pseudoinstructions *) + +type integer_comparison = + Isigned of Cmm.comparison + | Iunsigned of Cmm.comparison + +type integer_operation = + Iadd | Isub | Imul | Idiv | Imod + | Iand | Ior | Ixor | Ilsl | Ilsr | Iasr + | Icomp of integer_comparison + | Icheckbound + +type test = + Itruetest + | Ifalsetest + | Iinttest of integer_comparison + | Iinttest_imm of integer_comparison * int + | Ifloattest of Cmm.comparison * bool + | Ioddtest + | Ieventest + +type operation = + Imove + | Ispill + | Ireload + | Iconst_int of nativeint + | Iconst_float of string + | Iconst_symbol of string + | Icall_ind + | Icall_imm of string + | Itailcall_ind + | Itailcall_imm of string + | Iextcall of string * bool + | Istackoffset of int + | Iload of Cmm.memory_chunk * Arch.addressing_mode + | Istore of Cmm.memory_chunk * Arch.addressing_mode + | Ialloc of int + | Iintop of integer_operation + | Iintop_imm of integer_operation * int + | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf + | Ifloatofint | Iintoffloat + | Ispecific of Arch.specific_operation + +type instruction = + { desc: instruction_desc; + next: instruction; + arg: Reg.t array; + res: Reg.t array; + dbg: Debuginfo.t; + mutable live: Reg.Set.t } + +and instruction_desc = + Iend + | Iop of operation + | Ireturn + | Iifthenelse of test * instruction * instruction + | Iswitch of int array * instruction array + | Iloop of instruction + | Icatch of int * instruction * instruction + | Iexit of int + | Itrywith of instruction * instruction + | Iraise + +type fundecl = + { fun_name: string; + fun_args: Reg.t array; + fun_body: instruction; + fun_fast: bool } + +val dummy_instr: instruction +val end_instr: unit -> instruction +val instr_cons: + instruction_desc -> Reg.t array -> Reg.t array -> instruction -> + instruction +val instr_cons_debug: + instruction_desc -> Reg.t array -> Reg.t array -> Debuginfo.t -> + instruction -> instruction +val instr_iter: (instruction -> unit) -> instruction -> unit + diff --git a/asmcomp/mips/arch.ml b/asmcomp/mips/arch.ml new file mode 100644 index 0000000..f26319b --- /dev/null +++ b/asmcomp/mips/arch.ml @@ -0,0 +1,71 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.6 2002-11-29 15:03:36 xleroy Exp $ *) + +(* Specific operations for the Mips processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Addressing modes *) + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + +(* Specific operations *) + +type specific_operation = unit (* none *) + +(* Sizes, endianness *) + +let big_endian = + match Config.system with + "ultrix" -> false + | "irix" -> true + | _ -> fatal_error "Arch_mips.big_endian" + +let size_addr = 4 +let size_int = 4 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "\"%s\"%s" s idx + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + +let print_specific_operation printreg op ppf arg = + fatal_error "Arch_mips.print_specific_operation" diff --git a/asmcomp/mips/emit.mlp b/asmcomp/mips/emit.mlp new file mode 100644 index 0000000..6df9550 --- /dev/null +++ b/asmcomp/mips/emit.mlp @@ -0,0 +1,594 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.18 2004-01-05 20:25:56 doligez Exp $ *) + +(* Emission of Mips assembly code *) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Output a label *) + +let emit_label lbl = + emit_string "$"; emit_int lbl + +(* Output a symbol *) + +let emit_symbol s = + Emitaux.emit_symbol '$' s + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit_mips.emit_reg" + +(* Record if $gp is needed *) + +let uses_gp = ref false + +(* Layout of the stack frame *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + + (if !contains_calls then if !uses_gp then 8 else 4 else 0) in + Misc.align size 16 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + | Local n -> + if cl = 0 + then !stack_offset + num_stack_slots.(1) * 8 + n * 4 + else !stack_offset + n * 8 + | Outgoing n -> n + +(* Output a stack reference *) + +let emit_stack r = + match r.loc with + Stack s -> + let ofs = slot_offset s (register_class r) in `{emit_int ofs}($sp)` + | _ -> fatal_error "Emit_mips.emit_stack" + +(* Output an addressing mode *) + +let emit_addressing addr r n = + match addr with + Iindexed ofs -> + `{emit_int ofs}({emit_reg r.(n)})` + | Ibased(s, 0) -> + `{emit_symbol s}` + | Ibased(s, ofs) -> + `{emit_symbol s}`; + if ofs > 0 then ` + {emit_int ofs}`; + if ofs < 0 then ` - {emit_int(-ofs)}` + +(* Communicate live registers at call points to the assembler *) + +let int_reg_number = + [| 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21 |] + +let float_reg_number = + [| 0; 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 |] + +let liveregs instr extra_msk = + (* $22, $23, $30 always live *) + let int_mask = ref(0x00000302 lor extra_msk) + and float_mask = ref 0 in + let add_register = function + {loc = Reg r; typ = (Int | Addr)} -> + int_mask := !int_mask lor (1 lsl (31 - int_reg_number.(r))) + | {loc = Reg r; typ = Float} -> + float_mask := !float_mask lor (1 lsl (31 - float_reg_number.(r - 100))) + | _ -> () in + Reg.Set.iter add_register instr.live; + Array.iter add_register instr.arg; + emit_printf " .livereg 0x%08x, 0x%08x\n" !int_mask !float_mask + +let live_25 = 1 lsl (31 - 25) +let live_24 = 1 lsl (31 - 24) + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((int_reg_number.(r) lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + `{emit_label lbl}:` + +let emit_frame fd = + ` .word {emit_label fd.fd_lbl}\n`; + ` .half {emit_int fd.fd_frame_size}\n`; + ` .half {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` .half {emit_int n}\n`) + fd.fd_live_offset; + ` .align 2\n` + +(* Determine if $gp is used in the function *) + +let rec instr_uses_gp i = + match i.desc with + Lend -> false + | Lop(Iconst_symbol s) -> true + | Lop(Icall_imm s) -> true + | Lop(Itailcall_imm s) -> true + | Lop(Iextcall(_, _)) -> true + | Lop(Iload(_, Ibased(_, _))) -> true + | Lop(Istore(_, Ibased(_, _))) -> true + | Lop(Ialloc _) -> true + | Lop(Iintop(Icheckbound)) -> true + | Lop(Iintop_imm(Icheckbound, _)) -> true + | Lswitch jumptbl -> true + | _ -> instr_uses_gp i.next + +(* Names of various instructions *) + +let name_for_comparison = function + Isigned Ceq -> "eq" | Isigned Cne -> "ne" | Isigned Cle -> "le" + | Isigned Cge -> "ge" | Isigned Clt -> "lt" | Isigned Cgt -> "gt" + | Iunsigned Ceq -> "eq" | Iunsigned Cne -> "ne" | Iunsigned Cle -> "leu" + | Iunsigned Cge -> "geu" | Iunsigned Clt -> "ltu" | Iunsigned Cgt -> "gtu" + +let name_for_float_comparison cmp neg = + match cmp with + Ceq -> ("eq", neg) | Cne -> ("eq", not neg) + | Cle -> ("le", neg) | Cge -> ("ult", not neg) + | Clt -> ("lt", neg) | Cgt -> ("ule", not neg) + +let name_for_int_operation = function + Iadd -> "addu" + | Isub -> "subu" + | Imul -> "mul" + | Idiv -> "div" + | Imod -> "rem" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "sll" + | Ilsr -> "srl" + | Iasr -> "sra" + | Icomp cmp -> "s" ^ name_for_comparison cmp + | _ -> Misc.fatal_error "Emit.name_for_int_operation" + +let name_for_float_operation = function + Inegf -> "neg.d" + | Iabsf -> "abs.d" + | Iaddf -> "add.d" + | Isubf -> "sub.d" + | Imulf -> "mul.d" + | Idivf -> "div.d" + | _ -> Misc.fatal_error "Emit.name_for_float_operation" + +(* Output the assembly code for an instruction *) + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Label of jump to caml_call_gc *) +let call_gc_label = ref 0 +(* Label of trap for out-of-range accesses *) +let range_check_trap = ref 0 + +let emit_instr i = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + match (src, dst) with + {loc = Reg rs; typ = Int|Addr}, {loc = Reg rd; typ = Int|Addr} -> + ` move {emit_reg dst}, {emit_reg src}\n` + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} -> + ` mov.d {emit_reg dst}, {emit_reg src}\n` + | {loc = Reg rs; typ = Int|Addr}, {loc = Stack sd} -> + ` sw {emit_reg src}, {emit_stack dst}\n` + | {loc = Reg rs; typ = Float}, {loc = Stack sd} -> + ` s.d {emit_reg src}, {emit_stack dst}\n` + | {loc = Stack ss; typ = Int|Addr}, {loc = Reg rd} -> + ` lw {emit_reg dst}, {emit_stack src}\n` + | {loc = Stack ss; typ = Float}, {loc = Reg rd} -> + ` l.d {emit_reg dst}, {emit_stack src}\n` + | _ -> + fatal_error "Emit_mips: Imove" + end + | Lop(Iconst_int n) -> + if n = 0n then + ` move {emit_reg i.res.(0)}, $0\n` + else + ` li {emit_reg i.res.(0)}, {emit_nativeint n}\n` + | Lop(Iconst_float s) -> + ` li.d {emit_reg i.res.(0)}, {emit_string s}\n` + | Lop(Iconst_symbol s) -> + ` la {emit_reg i.res.(0)}, {emit_symbol s}\n` + | Lop(Icall_ind) -> + ` move $25, {emit_reg i.arg.(0)}\n`; + liveregs i live_25; + ` jal {emit_reg i.arg.(0)}\n`; + `{record_frame i.live}\n` + | Lop(Icall_imm s) -> + liveregs i 0; + ` jal {emit_symbol s}\n`; + `{record_frame i.live}\n` + | Lop(Itailcall_ind) -> + let n = frame_size() in + if !contains_calls then + ` lw $31, {emit_int(n - 4)}($sp)\n`; + if !uses_gp then + ` lw $gp, {emit_int(n - 8)}($sp)\n`; + if n > 0 then + ` addu $sp, $sp, {emit_int n}\n`; + liveregs i 0; + ` move $25, {emit_reg i.arg.(0)}\n`; + liveregs i live_25; + ` j {emit_reg i.arg.(0)}\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then begin + ` b {emit_label !tailrec_entry_point}\n` + end else begin + let n = frame_size() in + if !contains_calls then + ` lw $31, {emit_int(n - 4)}($sp)\n`; + if !uses_gp then + ` lw $gp, {emit_int(n - 8)}($sp)\n`; + if n > 0 then + ` addu $sp, $sp, {emit_int n}\n`; + ` la $25, {emit_symbol s}\n`; + liveregs i live_25; + ` j $25\n` + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + ` la $24, {emit_symbol s}\n`; + liveregs i live_24; + ` jal caml_c_call\n`; + `{record_frame i.live}\n` + end else begin + ` jal {emit_symbol s}\n` + end + | Lop(Istackoffset n) -> + if n >= 0 then + ` subu $sp, $sp, {emit_int n}\n` + else + ` addu $sp, $sp, {emit_int (-n)}\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + Double_u -> + (* Destination is not 8-aligned, hence cannot use l.d *) + ` ldl $24, {emit_addressing addr i.arg 0}\n`; + ` ldr $24, {emit_addressing (offset_addressing addr 7) i.arg 0}\n`; + ` dmtc1 $24, {emit_reg dest}\n` + | Single -> + ` l.s {emit_reg dest}, {emit_addressing addr i.arg 0}\n`; + ` cvt.d.s {emit_reg dest}, {emit_reg dest}\n` + | _ -> + let load_instr = + match chunk with + Byte_unsigned -> "lbu" + | Byte_signed -> "lb" + | Sixteen_unsigned -> "lhu" + | Sixteen_signed -> "lh" + | Double -> "l.d" + | _ -> "lw" in + ` {emit_string load_instr} {emit_reg dest}, {emit_addressing addr i.arg 0}\n` + end + | Lop(Istore(chunk, addr)) -> + let src = i.arg.(0) in + begin match chunk with + Double_u -> + (* Destination is not 8-aligned, hence cannot use l.d *) + ` dmfc1 $24, {emit_reg src}\n`; + ` sdl $24, {emit_addressing addr i.arg 1}\n`; + ` sdr $24, {emit_addressing (offset_addressing addr 7) i.arg 1}\n` + | Single -> + ` cvt.s.d $f31, {emit_reg src}\n`; + ` s.s $f31, {emit_addressing addr i.arg 1}\n` + | _ -> + let store_instr = + match chunk with + Byte_unsigned | Byte_signed -> "sb" + | Sixteen_unsigned | Sixteen_signed -> "sh" + | Double -> "s.d" + | _ -> "sw" in + ` {emit_string store_instr} {emit_reg src}, {emit_addressing addr i.arg 1}\n` + end + | Lop(Ialloc n) -> + if !call_gc_label = 0 then call_gc_label := new_label(); + ` .set noreorder\n`; + ` subu $22, $22, {emit_int n}\n`; + ` subu $24, $22, $23\n`; + ` bltzal $24, {emit_label !call_gc_label}\n`; + ` addu {emit_reg i.res.(0)}, $22, 4\n`; + `{record_frame i.live}\n`; + ` .set reorder\n` + | Lop(Iintop(Icheckbound)) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` bleu {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_label !range_check_trap}\n` + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Iintop_imm(Icheckbound, n)) -> + if !range_check_trap = 0 then range_check_trap := new_label(); + ` bleu {emit_reg i.arg.(0)}, {emit_int n}, {emit_label !range_check_trap}\n` + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int n}\n` + | Lop(Inegf | Iabsf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Ifloatofint) -> + ` mtc1 {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`; + ` cvt.d.w {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintoffloat) -> + ` trunc.w.d $f31, {emit_reg i.arg.(0)}, $24\n`; + ` mfc1 {emit_reg i.res.(0)}, $f31\n` + | Lop(Ispecific sop) -> + fatal_error "Emit_mips: Ispecific" + | Lreloadretaddr -> + let n = frame_size() in + ` lw $31, {emit_int(n - 4)}($sp)\n`; + | Lreturn -> + let n = frame_size() in + if !uses_gp then + ` lw $gp, {emit_int(n - 8)}($sp)\n`; + if n > 0 then + ` addu $sp, $sp, {emit_int n}\n`; + liveregs i 0; + ` j $31\n` + | Llabel lbl -> + `{emit_label lbl}:\n` + | Lbranch lbl -> + ` b {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + ` bne {emit_reg i.arg.(0)}, $0, {emit_label lbl}\n` + | Ifalsetest -> + ` beq {emit_reg i.arg.(0)}, $0, {emit_label lbl}\n` + | Iinttest cmp -> + let comp = name_for_comparison cmp in + ` b{emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + let comp = name_for_comparison cmp in + ` b{emit_string comp} {emit_reg i.arg.(0)}, {emit_int n}, {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + let (comp, branch) = name_for_float_comparison cmp neg in + ` c.{emit_string comp}.d {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + if branch + then ` bc1f {emit_label lbl}\n` + else ` bc1t {emit_label lbl}\n` + | Ioddtest -> + ` and $24, {emit_reg i.arg.(0)}, 1\n`; + ` bne $24, $0, {emit_label lbl}\n` + | Ieventest -> + ` and $24, {emit_reg i.arg.(0)}, 1\n`; + ` beq $24, $0, {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` subu $24, {emit_reg i.arg.(0)}, 1\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` beq {emit_reg i.arg.(0)}, $0, {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` beq $24, $0, {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` bgtz $24, {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl_jumptbl = new_label() in + ` sll $24, {emit_reg i.arg.(0)}, 2\n`; + ` lw $24, {emit_label lbl_jumptbl}($24)\n`; + liveregs i live_24; + ` j $24\n`; + ` .rdata\n`; + `{emit_label lbl_jumptbl}:\n`; + for i = 0 to Array.length jumptbl - 1 do + ` .word {emit_label jumptbl.(i)}\n` + done; + ` .text\n` + | Lsetuptrap lbl -> + ` subu $sp, $sp, 16\n`; + ` bal {emit_label lbl}\n` + | Lpushtrap -> + stack_offset := !stack_offset + 16; + ` sw $30, 0($sp)\n`; + ` sw $31, 4($sp)\n`; + ` sw $gp, 8($sp)\n`; + ` move $30, $sp\n` + | Lpoptrap -> + ` lw $30, 0($sp)\n`; + ` addu $sp, $sp, 16\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + ` lw $25, 4($30)\n`; + ` move $sp, $30\n`; + ` lw $30, 0($sp)\n`; + ` lw $gp, 8($sp)\n`; + ` addu $sp, $sp, 16\n`; + liveregs i live_25; + ` jal $25\n` (* Keep retaddr in $31 for debugging *) + +let rec emit_all i = + match i.desc with Lend -> () | _ -> emit_instr i; emit_all i.next + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + uses_gp := instr_uses_gp fundecl.fun_body; + if !uses_gp then contains_calls := true; + tailrec_entry_point := new_label(); + stack_offset := 0; + call_gc_label := 0; + range_check_trap := 0; + ` .text\n`; + ` .align 2\n`; + ` .globl {emit_symbol fundecl.fun_name}\n`; + ` .ent {emit_symbol fundecl.fun_name}\n`; + `{emit_symbol fundecl.fun_name}:\n`; + let n = frame_size() in + if n > 0 then + ` subu $sp, $sp, {emit_int n}\n`; + if !contains_calls then + ` sw $31, {emit_int(n - 4)}($sp)\n`; + if !uses_gp then begin + ` sw $gp, {emit_int(n - 8)}($sp)\n`; + ` lui $24, %hi(%neg(%gp_rel({emit_symbol fundecl.fun_name})))\n`; + ` addiu $24, $24, %lo(%neg(%gp_rel({emit_symbol fundecl.fun_name})))\n`; + ` daddu $gp, $25, $24\n` + end; + `{emit_label !tailrec_entry_point}:\n`; + emit_all fundecl.fun_body; + if !call_gc_label > 0 then begin + `{emit_label !call_gc_label}:\n`; + ` la $25, caml_call_gc\n`; + ` j $25\n` + end; + if !range_check_trap > 0 then begin + `{emit_label !range_check_trap}:\n`; + ` la $25, caml_ml_array_bound_error\n`; + ` j $25\n` + end; + ` .end {emit_symbol fundecl.fun_name}\n` + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .globl {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (100000 + lbl)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .half {emit_int n}\n` + | Cint32 n -> + ` .word {emit_nativeint n}\n` + | Cint n -> + ` .word {emit_nativeint n}\n` + | Csingle f -> + ` .float {emit_string f}\n` + | Cdouble f -> + ` .align 0\n`; (* Prevent alignment on 8-byte boundary *) + ` .double {emit_string f}\n` + | Csymbol_address s -> + ` .word {emit_symbol s}\n` + | Clabel_address lbl -> + ` .word {emit_label (100000 + lbl)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then ` .space {emit_int n}\n` + | Calign n -> + ` .align {emit_int(Misc.log2 n)}\n` + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + (* There are really two groups of registers: + $sp and $30 always point to stack locations + $2 - $21 never point to stack locations. *) + ` .noalias $2,$sp; .noalias $2,$30; .noalias $3,$sp; .noalias $3,$30\n`; + ` .noalias $4,$sp; .noalias $4,$30; .noalias $5,$sp; .noalias $5,$30\n`; + ` .noalias $6,$sp; .noalias $6,$30; .noalias $7,$sp; .noalias $7,$30\n`; + ` .noalias $8,$sp; .noalias $8,$30; .noalias $9,$sp; .noalias $9,$30\n`; + ` .noalias $10,$sp; .noalias $10,$30; .noalias $11,$sp; .noalias $11,$30\n`; + ` .noalias $12,$sp; .noalias $12,$30; .noalias $13,$sp; .noalias $13,$30\n`; + ` .noalias $14,$sp; .noalias $14,$30; .noalias $15,$sp; .noalias $15,$30\n`; + ` .noalias $16,$sp; .noalias $16,$30; .noalias $17,$sp; .noalias $17,$30\n`; + ` .noalias $18,$sp; .noalias $18,$30; .noalias $19,$sp; .noalias $19,$30\n`; + ` .noalias $20,$sp; .noalias $20,$30; .noalias $21,$sp; .noalias $21,$30\n\n`; + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .globl {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .globl {emit_symbol lbl_begin}\n`; + ` .ent {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + ` .end {emit_symbol lbl_begin}\n` + +let end_assembly () = + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .text\n`; + ` .globl {emit_symbol lbl_end}\n`; + ` .ent {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .end {emit_symbol lbl_end}\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .data\n`; + ` .globl {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .word 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + ` .rdata\n`; + ` .globl {emit_symbol lbl}\n`; + `{emit_symbol lbl}:\n`; + ` .word {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + frame_descriptors := [] diff --git a/asmcomp/mips/proc.ml b/asmcomp/mips/proc.ml new file mode 100644 index 0000000..65b589c --- /dev/null +++ b/asmcomp/mips/proc.ml @@ -0,0 +1,210 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.7 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the Mips processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = false + +(* Registers available for register allocation *) + +(* Register map: + $0 always 0 + $1 temporary for the assembler + $2 - $7 0 - 5 function results + $8 - $15 6 - 13 function arguments + $16 - $21 14 - 19 general purpose (preserved by C) + $22 allocation pointer (preserved by C) + $23 allocation limit (preserved by C) + $24 - $25 temporaries + $26 - $29 kernel regs, stack pointer, global pointer + $30 trap pointer (preserved by C) + $31 return address + + $f0 - $f3 100 - 103 function results + $f4 - $f11 104 - 111 general purpose + $f12 - $f19 112 - 119 function arguments + $f20 - $f30 120 - 130 general purpose (even numbered preserved by C) + $f31 temporary *) + +let int_reg_name = [| + (* 0-5 *) "$2"; "$3"; "$4"; "$5"; "$6"; "$7"; + (* 6-13 *) "$8"; "$9"; "$10"; "$11"; "$12"; "$13"; "$14"; "$15"; + (* 14-19 *) "$16"; "$17"; "$18"; "$19"; "$20"; "$21" +|] + +let float_reg_name = [| + "$f0"; "$f1"; "$f2"; "$f3"; "$f4"; + "$f5"; "$f6"; "$f7"; "$f8"; "$f9"; + "$f10"; "$f11"; "$f12"; "$f13"; "$f14"; + "$f15"; "$f16"; "$f17"; "$f18"; "$f19"; + "$f20"; "$f21"; "$f22"; "$f23"; "$f24"; + "$f25"; "$f26"; "$f27"; "$f28"; "$f29"; "$f30" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 20; 31 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 20 Reg.dummy in + for i = 0 to 19 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 31 Reg.dummy in + for i = 0 to 30 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float + make_stack arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 6 13 112 119 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 6 13 112 119 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 5 100 103 not_supported res in loc + +(* The C calling conventions are as follows: + the first 8 arguments are passed either in integer regs $4...$11 + or float regs $f12...$f19. Each argument "consumes" both one slot + in the int register file and one slot in the float register file. + Extra arguments are passed on stack, in a 64-bits slot, right-justified + (i.e. at +4 from natural address). *) + +let loc_external_arguments arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref 2 in + let float = ref 112 in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + if i < 8 then begin + loc.(i) <- phys_reg (if arg.(i).typ = Float then !float else !int); + incr int; + incr float + end else begin + begin match arg.(i).typ with + Float -> loc.(i) <- stack_slot (Outgoing !ofs) Float + | ty -> loc.(i) <- stack_slot (Outgoing (!ofs + 4)) ty + end; + ofs := !ofs + 8 + end + done; + (loc, Misc.align !ofs 16) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = phys_reg 0 (* $2 *) + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = + (* $16 - $21, $f20, $f22, $f24, $f26, $f28, $f30 preserved *) + Array.of_list(List.map phys_reg + [0;1;2;3;4;5;6;7;8;9;10;11;12;13; + 100;101;102;103;104;105;106;107;108;109;110;111;112;113;114; + 115;116;117;118;119;121;123;125;127;129]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 6 + | _ -> 20 +let max_register_pressure = function + Iextcall(_, _) -> [| 6; 6 |] + | _ -> [| 20; 31 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/mips/reload.ml b/asmcomp/mips/reload.ml new file mode 100644 index 0000000..197fa06 --- /dev/null +++ b/asmcomp/mips/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.3 1999-11-17 18:56:45 xleroy Exp $ *) + +(* Reloading for the Mips *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/mips/scheduling.ml b/asmcomp/mips/scheduling.ml new file mode 100644 index 0000000..695aeb0 --- /dev/null +++ b/asmcomp/mips/scheduling.ml @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.2 1999-11-17 18:56:45 xleroy Exp $ *) + +open Schedgen (* to create a dependency *) + +(* No scheduling is needed for the Mips, the assembler + does it better than us. *) + +let fundecl f = f diff --git a/asmcomp/mips/selection.ml b/asmcomp/mips/selection.ml new file mode 100644 index 0000000..20fea01 --- /dev/null +++ b/asmcomp/mips/selection.ml @@ -0,0 +1,43 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.4 1999-11-17 18:56:46 xleroy Exp $ *) + +(* Instruction selection for the Mips processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +class selector = object + +inherit Selectgen.selector_generic + +method is_immediate (n : int) = true + +method select_addressing = function + Cconst_symbol s -> + (Ibased(s, 0), Ctuple []) + | Cop(Cadda, [Cconst_symbol s; Cconst_int n]) -> + (Ibased(s, n), Ctuple []) + | Cop(Cadda, [arg; Cconst_int n]) -> + (Iindexed n, arg) + | Cop(Cadda, [arg1; Cop(Caddi, [arg2; Cconst_int n])]) -> + (Iindexed n, Cop(Cadda, [arg1; arg2])) + | arg -> + (Iindexed 0, arg) + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/power/arch.ml b/asmcomp/power/arch.ml new file mode 100644 index 0000000..17dd049 --- /dev/null +++ b/asmcomp/power/arch.ml @@ -0,0 +1,87 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.12 2006-05-31 08:16:34 xleroy Exp $ *) + +(* Specific operations for the PowerPC processor *) + +open Misc +open Format + +(* Machine-specific command-line options *) + +let command_line_options = [] + +(* Specific operations *) + +type specific_operation = + Imultaddf (* multiply and add *) + | Imultsubf (* multiply and subtract *) + | Ialloc_far of int (* allocation in large functions *) + +(* Addressing modes *) + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + | Iindexed2 (* reg + reg *) + +(* Sizes, endianness *) + +let big_endian = true + +let ppc64 = + match Config.model with "ppc64" -> true | _ -> false + +let size_addr = if ppc64 then 8 else 4 +let size_int = size_addr +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + | Iindexed2 -> assert false + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + | Iindexed2 -> 2 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "\"%s\"%s" s idx + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + | Iindexed2 -> + fprintf ppf "%a + %a" printreg arg.(0) printreg arg.(1) + +let print_specific_operation printreg op ppf arg = + match op with + | Imultaddf -> + fprintf ppf "%a *f %a +f %a" + printreg arg.(0) printreg arg.(1) printreg arg.(2) + | Imultsubf -> + fprintf ppf "%a *f %a -f %a" + printreg arg.(0) printreg arg.(1) printreg arg.(2) + | Ialloc_far n -> + fprintf ppf "alloc_far %d" n + diff --git a/asmcomp/power/emit.mlp b/asmcomp/power/emit.mlp new file mode 100644 index 0000000..cb13f29 --- /dev/null +++ b/asmcomp/power/emit.mlp @@ -0,0 +1,964 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.26 2007-11-09 15:06:57 frisch Exp $ *) + +(* Emission of PowerPC assembly code *) + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Layout of the stack. The stack is kept 16-aligned. *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + (* Trap frame, outgoing parameters *) + size_int * num_stack_slots.(0) + (* Local int variables *) + size_float * num_stack_slots.(1) + (* Local float variables *) + (if !contains_calls then size_int else 0) in (* The return address *) + Misc.align size 16 + +let slot_offset loc cls = + match loc with + Local n -> + if cls = 0 + then !stack_offset + num_stack_slots.(1) * size_float + n * size_int + else !stack_offset + n * size_float + | Incoming n -> frame_size() + n + | Outgoing n -> n + +(* Whether stack backtraces are supported *) + +let supports_backtraces = + match Config.system with + | "rhapsody" -> true + | _ -> false + +(* Output a symbol *) + +let emit_symbol = + match Config.system with + | "elf" | "bsd" -> (fun s -> Emitaux.emit_symbol '.' s) + | "rhapsody" -> (fun s -> emit_char '_'; Emitaux.emit_symbol '$' s) + | _ -> assert false + +(* Output a label *) + +let label_prefix = + match Config.system with + | "elf" | "bsd" -> ".L" + | "rhapsody" -> "L" + | _ -> assert false + +let emit_label lbl = + emit_string label_prefix; emit_int lbl + +(* Section switching *) + +let data_space = + match Config.system with + | "elf" | "bsd" -> " .section \".data\"\n" + | "rhapsody" -> " .data\n" + | _ -> assert false + +let code_space = + match Config.system with + | "elf" | "bsd" -> " .section \".text\"\n" + | "rhapsody" -> " .text\n" + | _ -> assert false + +let rodata_space = + match Config.system with + | "elf" | "bsd" -> " .section \".rodata\"\n" + | "rhapsody" -> " .const\n" + | _ -> assert false + +(* Names of instructions that differ in 32 and 64-bit modes *) + +let lg = if ppc64 then "ld" else "lwz" +let stg = if ppc64 then "std" else "stw" +let lwa = if ppc64 then "lwa" else "lwz" +let cmpg = if ppc64 then "cmpd" else "cmpw" +let cmplg = if ppc64 then "cmpld" else "cmplw" +let datag = if ppc64 then ".quad" else ".long" +let aligng = if ppc64 then 3 else 2 +let mullg = if ppc64 then "mulld" else "mullw" +let divg = if ppc64 then "divd" else "divw" +let tglle = if ppc64 then "tdlle" else "twlle" +let sragi = if ppc64 then "sradi" else "srawi" +let slgi = if ppc64 then "sldi" else "slwi" +let fctigz = if ppc64 then "fctidz" else "fctiwz" + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit.emit_reg" + +let use_full_regnames = + Config.system = "rhapsody" + +let emit_gpr r = + if use_full_regnames then emit_char 'r'; + emit_int r + +let emit_fpr r = + if use_full_regnames then emit_char 'f'; + emit_int r + +let emit_ccr r = + if use_full_regnames then emit_string "cr"; + emit_int r + +(* Output a stack reference *) + +let emit_stack r = + match r.loc with + Stack s -> + let ofs = slot_offset s (register_class r) in `{emit_int ofs}({emit_gpr 1})` + | _ -> fatal_error "Emit.emit_stack" + +(* Split a 32-bit integer constants in two 16-bit halves *) + +let low n = n land 0xFFFF +let high n = n asr 16 + +let nativelow n = Nativeint.to_int n land 0xFFFF +let nativehigh n = Nativeint.to_int (Nativeint.shift_right n 16) + +let is_immediate n = + n <= 32767 && n >= -32768 + +let is_native_immediate n = + n <= 32767n && n >= -32768n + +(* Output a "upper 16 bits" or "lower 16 bits" operator. *) + +let emit_upper emit_fun arg = + match Config.system with + | "elf" | "bsd" -> + emit_fun arg; emit_string "@ha" + | "rhapsody" -> + emit_string "ha16("; emit_fun arg; emit_string ")" + | _ -> assert false + +let emit_lower emit_fun arg = + match Config.system with + | "elf" | "bsd" -> + emit_fun arg; emit_string "@l" + | "rhapsody" -> + emit_string "lo16("; emit_fun arg; emit_string ")" + | _ -> assert false + +(* Output a load or store operation *) + +let emit_symbol_offset (s, d) = + emit_symbol s; + if d > 0 then `+`; + if d <> 0 then emit_int d + +let valid_offset instr ofs = + ofs land 3 = 0 || (instr <> "ld" && instr <> "std") + +let emit_load_store instr addressing_mode addr n arg = + match addressing_mode with + Ibased(s, d) -> + ` addis {emit_gpr 11}, 0, {emit_upper emit_symbol_offset (s,d)}\n`; + ` {emit_string instr} {emit_reg arg}, {emit_lower emit_symbol_offset (s,d)}({emit_gpr 11})\n` + | Iindexed ofs -> + if is_immediate ofs && valid_offset instr ofs then + ` {emit_string instr} {emit_reg arg}, {emit_int ofs}({emit_reg addr.(n)})\n` + else begin + ` lis {emit_gpr 0}, {emit_int(high ofs)}\n`; + if low ofs <> 0 then + ` ori {emit_gpr 0}, {emit_gpr 0}, {emit_int(low ofs)}\n`; + ` {emit_string instr}x {emit_reg arg}, {emit_reg addr.(n)}, {emit_gpr 0}\n` + end + | Iindexed2 -> + ` {emit_string instr}x {emit_reg arg}, {emit_reg addr.(n)}, {emit_reg addr.(n+1)}\n` + +(* After a comparison, extract the result as 0 or 1 *) + +let emit_set_comp cmp res = + ` mfcr {emit_gpr 0}\n`; + let bitnum = + match cmp with + Ceq | Cne -> 2 + | Cgt | Cle -> 1 + | Clt | Cge -> 0 in +` rlwinm {emit_reg res}, {emit_gpr 0}, {emit_int(bitnum+1)}, 31, 31\n`; + begin match cmp with + Cne | Cle | Cge -> ` xori {emit_reg res}, {emit_reg res}, 1\n` + | _ -> () + end + +(* Record live pointers at call points *) + +let record_frame live dbg = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := (r lsl 1) + 1 :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset; + fd_debuginfo = dbg } :: !frame_descriptors; + `{emit_label lbl}:\n` + +(* Record floating-point and large integer literals *) + +let float_literals = ref ([] : (string * int) list) +let int_literals = ref ([] : (nativeint * int) list) + +(* Record external C functions to be called in a position-independent way + (for MacOSX) *) + +let pic_externals = (Config.system = "rhapsody") + +let external_functions = ref StringSet.empty + +let emit_external s = + ` .non_lazy_symbol_pointer\n`; + `L{emit_symbol s}$non_lazy_ptr:\n`; + ` .indirect_symbol {emit_symbol s}\n`; + ` {emit_string datag} 0\n` + +(* Names for conditional branches after comparisons *) + +let branch_for_comparison = function + Ceq -> "beq" | Cne -> "bne" + | Cle -> "ble" | Cgt -> "bgt" + | Cge -> "bge" | Clt -> "blt" + +let name_for_int_comparison = function + Isigned cmp -> (cmpg, branch_for_comparison cmp) + | Iunsigned cmp -> (cmplg, branch_for_comparison cmp) + +(* Names for various instructions *) + +let name_for_intop = function + Iadd -> "add" + | Imul -> if ppc64 then "mulld" else "mullw" + | Idiv -> if ppc64 then "divd" else "divw" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> if ppc64 then "sld" else "slw" + | Ilsr -> if ppc64 then "srd" else "srw" + | Iasr -> if ppc64 then "srad" else "sraw" + | _ -> Misc.fatal_error "Emit.Intop" + +let name_for_intop_imm = function + Iadd -> "addi" + | Imul -> "mulli" + | Iand -> "andi." + | Ior -> "ori" + | Ixor -> "xori" + | Ilsl -> if ppc64 then "sldi" else "slwi" + | Ilsr -> if ppc64 then "srdi" else "srwi" + | Iasr -> if ppc64 then "sradi" else "srawi" + | _ -> Misc.fatal_error "Emit.Intop_imm" + +let name_for_floatop1 = function + Inegf -> "fneg" + | Iabsf -> "fabs" + | _ -> Misc.fatal_error "Emit.Iopf1" + +let name_for_floatop2 = function + Iaddf -> "fadd" + | Isubf -> "fsub" + | Imulf -> "fmul" + | Idivf -> "fdiv" + | _ -> Misc.fatal_error "Emit.Iopf2" + +let name_for_specific = function + Imultaddf -> "fmadd" + | Imultsubf -> "fmsub" + | _ -> Misc.fatal_error "Emit.Ispecific" + +(* Name of current function *) +let function_name = ref "" +(* Entry point for tail recursive calls *) +let tailrec_entry_point = ref 0 +(* Names of functions defined in the current file *) +let defined_functions = ref StringSet.empty +(* Label of glue code for calling the GC *) +let call_gc_label = ref 0 + +(* Fixup conditional branches that exceed hardware allowed range *) + +let load_store_size = function + Ibased(s, d) -> 2 + | Iindexed ofs -> if is_immediate ofs then 1 else 3 + | Iindexed2 -> 1 + +let instr_size = function + Lend -> 0 + | Lop(Imove | Ispill | Ireload) -> 1 + | Lop(Iconst_int n) -> if is_native_immediate n then 1 else 2 + | Lop(Iconst_float s) -> 2 + | Lop(Iconst_symbol s) -> 2 + | Lop(Icall_ind) -> 2 + | Lop(Icall_imm s) -> 1 + | Lop(Itailcall_ind) -> 5 + | Lop(Itailcall_imm s) -> if s = !function_name then 1 else 4 + | Lop(Iextcall(s, true)) -> 3 + | Lop(Iextcall(s, false)) -> if pic_externals then 4 else 1 + | Lop(Istackoffset n) -> 1 + | Lop(Iload(chunk, addr)) -> + if chunk = Byte_signed + then load_store_size addr + 1 + else load_store_size addr + | Lop(Istore(chunk, addr)) -> load_store_size addr + | Lop(Ialloc n) -> 4 + | Lop(Ispecific(Ialloc_far n)) -> 5 + | Lop(Iintop Imod) -> 3 + | Lop(Iintop(Icomp cmp)) -> 4 + | Lop(Iintop op) -> 1 + | Lop(Iintop_imm(Idiv, n)) -> 2 + | Lop(Iintop_imm(Imod, n)) -> 4 + | Lop(Iintop_imm(Icomp cmp, n)) -> 4 + | Lop(Iintop_imm(op, n)) -> 1 + | Lop(Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf) -> 1 + | Lop(Ifloatofint) -> 9 + | Lop(Iintoffloat) -> 4 + | Lop(Ispecific sop) -> 1 + | Lreloadretaddr -> 2 + | Lreturn -> 2 + | Llabel lbl -> 0 + | Lbranch lbl -> 1 + | Lcondbranch(tst, lbl) -> 2 + | Lcondbranch3(lbl0, lbl1, lbl2) -> + 1 + (if lbl0 = None then 0 else 1) + + (if lbl1 = None then 0 else 1) + + (if lbl2 = None then 0 else 1) + | Lswitch jumptbl -> 8 + | Lsetuptrap lbl -> 1 + | Lpushtrap -> 4 + | Lpoptrap -> 2 + | Lraise -> 6 + +let label_map code = + let map = Hashtbl.create 37 in + let rec fill_map pc instr = + match instr.desc with + Lend -> (pc, map) + | Llabel lbl -> Hashtbl.add map lbl pc; fill_map pc instr.next + | op -> fill_map (pc + instr_size op) instr.next + in fill_map 0 code + +let max_branch_offset = 8180 +(* 14-bit signed offset in words. Remember to cut some slack + for multi-word instructions where the branch can be anywhere in + the middle. 12 words of slack is plenty. *) + +let branch_overflows map pc_branch lbl_dest = + let pc_dest = Hashtbl.find map lbl_dest in + let delta = pc_dest - (pc_branch + 1) in + delta <= -max_branch_offset || delta >= max_branch_offset + +let opt_branch_overflows map pc_branch opt_lbl_dest = + match opt_lbl_dest with + None -> false + | Some lbl_dest -> branch_overflows map pc_branch lbl_dest + +let fixup_branches codesize map code = + let expand_optbranch lbl n arg next = + match lbl with + None -> next + | Some l -> + instr_cons (Lcondbranch(Iinttest_imm(Isigned Ceq, n), l)) + arg [||] next in + let rec fixup did_fix pc instr = + match instr.desc with + Lend -> did_fix + | Lcondbranch(test, lbl) when branch_overflows map pc lbl -> + let lbl2 = new_label() in + let cont = + instr_cons (Lbranch lbl) [||] [||] + (instr_cons (Llabel lbl2) [||] [||] instr.next) in + instr.desc <- Lcondbranch(invert_test test, lbl2); + instr.next <- cont; + fixup true (pc + 2) instr.next + | Lcondbranch3(lbl0, lbl1, lbl2) + when opt_branch_overflows map pc lbl0 + || opt_branch_overflows map pc lbl1 + || opt_branch_overflows map pc lbl2 -> + let cont = + expand_optbranch lbl0 0 instr.arg + (expand_optbranch lbl1 1 instr.arg + (expand_optbranch lbl2 2 instr.arg instr.next)) in + instr.desc <- cont.desc; + instr.next <- cont.next; + fixup true pc instr + | Lop(Ialloc n) when codesize - pc >= max_branch_offset -> + instr.desc <- Lop(Ispecific(Ialloc_far n)); + fixup true (pc + 4) instr.next + | op -> + fixup did_fix (pc + instr_size op) instr.next + in fixup false 0 code + +(* Iterate branch expansion till all conditional branches are OK *) + +let rec branch_normalization code = + let (codesize, map) = label_map code in + if codesize >= max_branch_offset && fixup_branches codesize map code + then branch_normalization code + else () + + +(* Output the assembly code for an instruction *) + +let rec emit_instr i dslot = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + if src.loc <> dst.loc then begin + match (src, dst) with + {loc = Reg rs; typ = (Int | Addr)}, {loc = Reg rd} -> + ` mr {emit_reg dst}, {emit_reg src}\n` + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} -> + ` fmr {emit_reg dst}, {emit_reg src}\n` + | {loc = Reg rs; typ = (Int | Addr)}, {loc = Stack sd} -> + ` {emit_string stg} {emit_reg src}, {emit_stack dst}\n` + | {loc = Reg rs; typ = Float}, {loc = Stack sd} -> + ` stfd {emit_reg src}, {emit_stack dst}\n` + | {loc = Stack ss; typ = (Int | Addr)}, {loc = Reg rd} -> + ` {emit_string lg} {emit_reg dst}, {emit_stack src}\n` + | {loc = Stack ss; typ = Float}, {loc = Reg rd} -> + ` lfd {emit_reg dst}, {emit_stack src}\n` + | (_, _) -> + fatal_error "Emit: Imove" + end + | Lop(Iconst_int n) -> + if is_native_immediate n then + ` li {emit_reg i.res.(0)}, {emit_nativeint n}\n` + else if n >= -0x8000_0000n && n <= 0x7FFF_FFFFn then begin + ` lis {emit_reg i.res.(0)}, {emit_int(nativehigh n)}\n`; + if nativelow n <> 0 then + ` ori {emit_reg i.res.(0)}, {emit_reg i.res.(0)}, {emit_int(nativelow n)}\n` + end else begin + let lbl = new_label() in + int_literals := (n, lbl) :: !int_literals; + ` addis {emit_gpr 11}, 0, {emit_upper emit_label lbl}\n`; + ` {emit_string lg} {emit_reg i.res.(0)}, {emit_lower emit_label lbl}({emit_gpr 11})\n` + end + | Lop(Iconst_float s) -> + let lbl = new_label() in + float_literals := (s, lbl) :: !float_literals; + ` addis {emit_gpr 11}, 0, {emit_upper emit_label lbl}\n`; + ` lfd {emit_reg i.res.(0)}, {emit_lower emit_label lbl}({emit_gpr 11})\n` + | Lop(Iconst_symbol s) -> + ` addis {emit_reg i.res.(0)}, 0, {emit_upper emit_symbol s}\n`; + ` addi {emit_reg i.res.(0)}, {emit_reg i.res.(0)}, {emit_lower emit_symbol s}\n` + | Lop(Icall_ind) -> + ` mtctr {emit_reg i.arg.(0)}\n`; + ` bctrl\n`; + record_frame i.live i.dbg + | Lop(Icall_imm s) -> + ` bl {emit_symbol s}\n`; + record_frame i.live i.dbg + | Lop(Itailcall_ind) -> + let n = frame_size() in + ` mtctr {emit_reg i.arg.(0)}\n`; + if !contains_calls then begin + ` {emit_string lg} {emit_gpr 11}, {emit_int(n - size_addr)}({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int n}\n`; + ` mtlr {emit_gpr 11}\n` + end else begin + if n > 0 then + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int n}\n` + end; + ` bctr\n` + | Lop(Itailcall_imm s) -> + if s = !function_name then + ` b {emit_label !tailrec_entry_point}\n` + else begin + let n = frame_size() in + if !contains_calls then begin + ` {emit_string lg} {emit_gpr 11}, {emit_int(n - size_addr)}({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int n}\n`; + ` mtlr {emit_gpr 11}\n` + end else begin + if n > 0 then + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int n}\n` + end; + ` b {emit_symbol s}\n` + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + if pic_externals then begin + external_functions := StringSet.add s !external_functions; + ` addis {emit_gpr 11}, 0, ha16(L{emit_symbol s}$non_lazy_ptr)\n`; + ` {emit_string lg} {emit_gpr 11}, lo16(L{emit_symbol s}$non_lazy_ptr)({emit_gpr 11})\n` + end else begin + ` addis {emit_gpr 11}, 0, {emit_upper emit_symbol s}\n`; + ` addi {emit_gpr 11}, {emit_gpr 11}, {emit_lower emit_symbol s}\n` + end; + ` bl {emit_symbol "caml_c_call"}\n`; + record_frame i.live i.dbg + end else begin + if pic_externals then begin + external_functions := StringSet.add s !external_functions; + ` addis {emit_gpr 11}, 0, ha16(L{emit_symbol s}$non_lazy_ptr)\n`; + ` {emit_string lg} {emit_gpr 11}, lo16(L{emit_symbol s}$non_lazy_ptr)({emit_gpr 11})\n`; + ` mtctr {emit_gpr 11}\n`; + ` bctrl\n` + end else + ` bl {emit_symbol s}\n` + end + | Lop(Istackoffset n) -> + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int (-n)}\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let loadinstr = + match chunk with + Byte_unsigned -> "lbz" + | Byte_signed -> "lbz" + | Sixteen_unsigned -> "lhz" + | Sixteen_signed -> "lha" + | Thirtytwo_unsigned -> "lwz" + | Thirtytwo_signed -> if ppc64 then "lwa" else "lwz" + | Word -> lg + | Single -> "lfs" + | Double | Double_u -> "lfd" in + emit_load_store loadinstr addr i.arg 0 i.res.(0); + if chunk = Byte_signed then + ` extsb {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Istore(chunk, addr)) -> + let storeinstr = + match chunk with + Byte_unsigned | Byte_signed -> "stb" + | Sixteen_unsigned | Sixteen_signed -> "sth" + | Thirtytwo_unsigned | Thirtytwo_signed -> "stw" + | Word -> stg + | Single -> "stfs" + | Double | Double_u -> "stfd" in + emit_load_store storeinstr addr i.arg 1 i.arg.(0) + | Lop(Ialloc n) -> + if !call_gc_label = 0 then call_gc_label := new_label(); + ` addi {emit_gpr 31}, {emit_gpr 31}, {emit_int(-n)}\n`; + ` {emit_string cmplg} {emit_gpr 31}, {emit_gpr 30}\n`; + ` addi {emit_reg i.res.(0)}, {emit_gpr 31}, {emit_int size_addr}\n`; + ` bltl {emit_label !call_gc_label}\n`; + record_frame i.live Debuginfo.none + | Lop(Ispecific(Ialloc_far n)) -> + if !call_gc_label = 0 then call_gc_label := new_label(); + let lbl = new_label() in + ` addi {emit_gpr 31}, {emit_gpr 31}, {emit_int(-n)}\n`; + ` {emit_string cmplg} {emit_gpr 31}, {emit_gpr 30}\n`; + ` bge {emit_label lbl}\n`; + ` bl {emit_label !call_gc_label}\n`; + record_frame i.live Debuginfo.none; + `{emit_label lbl}: addi {emit_reg i.res.(0)}, {emit_gpr 31}, {emit_int size_addr}\n` + | Lop(Iintop Isub) -> (* subfc has swapped arguments *) + ` subfc {emit_reg i.res.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.arg.(0)}\n` + | Lop(Iintop Imod) -> + ` {emit_string divg} {emit_gpr 0}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` {emit_string mullg} {emit_gpr 0}, {emit_gpr 0}, {emit_reg i.arg.(1)}\n`; + ` subfc {emit_reg i.res.(0)}, {emit_gpr 0}, {emit_reg i.arg.(0)}\n` + | Lop(Iintop(Icomp cmp)) -> + begin match cmp with + Isigned c -> + ` {emit_string cmpg} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + emit_set_comp c i.res.(0) + | Iunsigned c -> + ` {emit_string cmplg} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + emit_set_comp c i.res.(0) + end + | Lop(Iintop Icheckbound) -> + if !Clflags.debug && supports_backtraces then + record_frame Reg.Set.empty i.dbg; + ` {emit_string tglle} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Iintop op) -> + let instr = name_for_intop op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Iintop_imm(Isub, n)) -> + ` addi {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int(-n)}\n` + | Lop(Iintop_imm(Idiv, n)) -> (* n is guaranteed to be a power of 2 *) + let l = Misc.log2 n in + ` {emit_string sragi} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int l}\n`; + ` addze {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Imod, n)) -> (* n is guaranteed to be a power of 2 *) + let l = Misc.log2 n in + ` {emit_string sragi} {emit_gpr 0}, {emit_reg i.arg.(0)}, {emit_int l}\n`; + ` addze {emit_gpr 0}, {emit_gpr 0}\n`; + ` {emit_string slgi} {emit_gpr 0}, {emit_gpr 0}, {emit_int l}\n`; + ` subfc {emit_reg i.res.(0)}, {emit_gpr 0}, {emit_reg i.arg.(0)}\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + begin match cmp with + Isigned c -> + ` {emit_string cmpg}i {emit_reg i.arg.(0)}, {emit_int n}\n`; + emit_set_comp c i.res.(0) + | Iunsigned c -> + ` {emit_string cmplg}i {emit_reg i.arg.(0)}, {emit_int n}\n`; + emit_set_comp c i.res.(0) + end + | Lop(Iintop_imm(Icheckbound, n)) -> + if !Clflags.debug && supports_backtraces then + record_frame Reg.Set.empty i.dbg; + ` {emit_string tglle}i {emit_reg i.arg.(0)}, {emit_int n}\n` + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_intop_imm op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_int n}\n` + | Lop(Inegf | Iabsf as op) -> + let instr = name_for_floatop1 op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_floatop2 op in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n` + | Lop(Ifloatofint) -> + if ppc64 then begin + ` stdu {emit_reg i.arg.(0)}, -16({emit_gpr 1})\n`; + ` lfd {emit_reg i.res.(0)}, 0({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 16\n`; + ` fcfid {emit_reg i.res.(0)}, {emit_reg i.res.(0)}\n` + end else begin + let lbl = new_label() in + float_literals := ("4.503601774854144e15", lbl) :: !float_literals; + (* That float above represents 0x4330000080000000 *) + ` addis {emit_gpr 11}, 0, {emit_upper emit_label lbl}\n`; + ` lfd {emit_fpr 0}, {emit_lower emit_label lbl}({emit_gpr 11})\n`; + ` lis {emit_gpr 0}, 0x4330\n`; + ` stwu {emit_gpr 0}, -16({emit_gpr 1})\n`; + ` xoris {emit_gpr 0}, {emit_reg i.arg.(0)}, 0x8000\n`; + ` stw {emit_gpr 0}, 4({emit_gpr 1})\n`; + ` lfd {emit_reg i.res.(0)}, 0({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 16\n`; + ` fsub {emit_reg i.res.(0)}, {emit_reg i.res.(0)}, {emit_fpr 0}\n` + end + | Lop(Iintoffloat) -> + let ofs = if ppc64 then 0 else 4 in + ` {emit_string fctigz} {emit_fpr 0}, {emit_reg i.arg.(0)}\n`; + ` stfdu {emit_fpr 0}, -16({emit_gpr 1})\n`; + ` {emit_string lg} {emit_reg i.res.(0)}, {emit_int ofs}({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 16\n` + | Lop(Ispecific sop) -> + let instr = name_for_specific sop in + ` {emit_string instr} {emit_reg i.res.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.arg.(2)}\n` + | Lreloadretaddr -> + let n = frame_size() in + ` {emit_string lg} {emit_gpr 11}, {emit_int(n - size_addr)}({emit_gpr 1})\n`; + ` mtlr {emit_gpr 11}\n` + | Lreturn -> + let n = frame_size() in + if n > 0 then + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int n}\n`; + ` blr\n` + | Llabel lbl -> + `{emit_label lbl}:\n` + | Lbranch lbl -> + ` b {emit_label lbl}\n` + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + ` {emit_string cmpg}i {emit_reg i.arg.(0)}, 0\n`; + emit_delay dslot; + ` bne {emit_label lbl}\n` + | Ifalsetest -> + ` {emit_string cmpg}i {emit_reg i.arg.(0)}, 0\n`; + emit_delay dslot; + ` beq {emit_label lbl}\n` + | Iinttest cmp -> + let (comp, branch) = name_for_int_comparison cmp in + ` {emit_string comp} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + emit_delay dslot; + ` {emit_string branch} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + let (comp, branch) = name_for_int_comparison cmp in + ` {emit_string comp}i {emit_reg i.arg.(0)}, {emit_int n}\n`; + emit_delay dslot; + ` {emit_string branch} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + ` fcmpu {emit_ccr 0}, {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + (* bit 0 = lt, bit 1 = gt, bit 2 = eq *) + let (bitnum, negtst) = + match cmp with + Ceq -> (2, neg) + | Cne -> (2, not neg) + | Cle -> ` cror 3, 0, 2\n`; (* lt or eq *) + (3, neg) + | Cgt -> (1, neg) + | Cge -> ` cror 3, 1, 2\n`; (* gt or eq *) + (3, neg) + | Clt -> (0, neg) in + emit_delay dslot; + if negtst + then ` bf {emit_int bitnum}, {emit_label lbl}\n` + else ` bt {emit_int bitnum}, {emit_label lbl}\n` + | Ioddtest -> + ` andi. {emit_gpr 0}, {emit_reg i.arg.(0)}, 1\n`; + emit_delay dslot; + ` bne {emit_label lbl}\n` + | Ieventest -> + ` andi. {emit_gpr 0}, {emit_reg i.arg.(0)}, 1\n`; + emit_delay dslot; + ` beq {emit_label lbl}\n` + end + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` {emit_string cmpg}i {emit_reg i.arg.(0)}, 1\n`; + emit_delay dslot; + begin match lbl0 with + None -> () + | Some lbl -> ` blt {emit_label lbl}\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` beq {emit_label lbl}\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` bgt {emit_label lbl}\n` + end + | Lswitch jumptbl -> + let lbl = new_label() in + ` addis {emit_gpr 11}, 0, {emit_upper emit_label lbl}\n`; + ` addi {emit_gpr 11}, {emit_gpr 11}, {emit_lower emit_label lbl}\n`; + ` {emit_string slgi} {emit_gpr 0}, {emit_reg i.arg.(0)}, 2\n`; + ` {emit_string lwa}x {emit_gpr 0}, {emit_gpr 11}, {emit_gpr 0}\n`; + ` add {emit_gpr 0}, {emit_gpr 11}, {emit_gpr 0}\n`; + ` mtctr {emit_gpr 0}\n`; + ` bctr\n`; + emit_string rodata_space; + `{emit_label lbl}:`; + for i = 0 to Array.length jumptbl - 1 do + ` .long {emit_label jumptbl.(i)} - {emit_label lbl}\n` + done; + emit_string code_space + | Lsetuptrap lbl -> + ` bl {emit_label lbl}\n` + | Lpushtrap -> + stack_offset := !stack_offset + 16; + ` mflr {emit_gpr 0}\n`; + ` {emit_string stg}u {emit_gpr 0}, -16({emit_gpr 1})\n`; + ` {emit_string stg} {emit_gpr 29}, {emit_int size_addr}({emit_gpr 1})\n`; + ` mr {emit_gpr 29}, {emit_gpr 1}\n` + | Lpoptrap -> + ` {emit_string lg} {emit_gpr 29}, {emit_int size_addr}({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 16\n`; + stack_offset := !stack_offset - 16 + | Lraise -> + if !Clflags.debug && supports_backtraces then begin + ` bl {emit_symbol "caml_raise_exn"}\n`; + record_frame Reg.Set.empty i.dbg + end else begin + ` {emit_string lg} {emit_gpr 0}, 0({emit_gpr 29})\n`; + ` mr {emit_gpr 1}, {emit_gpr 29}\n`; + ` mtlr {emit_gpr 0}\n`; + ` {emit_string lg} {emit_gpr 29}, {emit_int size_addr}({emit_gpr 1})\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, 16\n`; + ` blr\n` + end + +and emit_delay = function + None -> () + | Some i -> emit_instr i None + +(* Checks if a pseudo-instruction expands to instructions + that do not branch and do not affect CR0 nor R12. *) + +let is_simple_instr i = + match i.desc with + Lop op -> + begin match op with + Icall_imm _ | Icall_ind | Itailcall_imm _ | Itailcall_ind | + Iextcall(_, _) -> false + | Ialloc(_) -> false + | Iintop(Icomp _) -> false + | Iintop_imm(Iand, _) -> false + | Iintop_imm(Icomp _, _) -> false + | _ -> true + end + | Lreloadretaddr -> true + | _ -> false + +let no_interference res arg = + try + for i = 0 to Array.length arg - 1 do + for j = 0 to Array.length res - 1 do + if arg.(i).loc = res.(j).loc then raise Exit + done + done; + true + with Exit -> + false + +(* Emit a sequence of instructions, trying to fill delay slots for branches *) + +let rec emit_all i = + match i with + {desc = Lend} -> () + | {next = {desc = (Lcondbranch(_, _) | Lcondbranch3(_, _, _))}} + when is_simple_instr i & no_interference i.res i.next.arg -> + emit_instr i.next (Some i); + emit_all i.next.next + | _ -> + emit_instr i None; + emit_all i.next + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + defined_functions := StringSet.add fundecl.fun_name !defined_functions; + tailrec_entry_point := new_label(); + stack_offset := 0; + call_gc_label := 0; + float_literals := []; + int_literals := []; + ` .globl {emit_symbol fundecl.fun_name}\n`; + begin match Config.system with + | "elf" | "bsd" -> + ` .type {emit_symbol fundecl.fun_name}, @function\n` + | _ -> () + end; + emit_string code_space; + ` .align 2\n`; + `{emit_symbol fundecl.fun_name}:\n`; + let n = frame_size() in + if !contains_calls then begin + ` mflr {emit_gpr 0}\n`; + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int(-n)}\n`; + ` {emit_string stg} {emit_gpr 0}, {emit_int(n - size_addr)}({emit_gpr 1})\n` + end else begin + if n > 0 then + ` addi {emit_gpr 1}, {emit_gpr 1}, {emit_int(-n)}\n` + end; + `{emit_label !tailrec_entry_point}:\n`; + branch_normalization fundecl.fun_body; + emit_all fundecl.fun_body; + (* Emit the glue code to call the GC *) + if !call_gc_label > 0 then begin + `{emit_label !call_gc_label}:\n`; + ` b {emit_symbol "caml_call_gc"}\n` + end; + (* Emit the numeric literals *) + if !float_literals <> [] || !int_literals <> [] then begin + emit_string rodata_space; + ` .align 3\n`; + List.iter + (fun (f, lbl) -> + `{emit_label lbl}: .double 0d{emit_string f}\n`) + !float_literals; + List.iter + (fun (n, lbl) -> + `{emit_label lbl}: {emit_string datag} {emit_nativeint n}\n`) + !int_literals + end + +(* Emission of data *) + +let declare_global_data s = + ` .globl {emit_symbol s}\n`; + if Config.system = "elf" || Config.system = "bsd" then + ` .type {emit_symbol s}, @object\n` + +let emit_item = function + Cglobal_symbol s -> + declare_global_data s + | Cdefine_symbol s -> + `{emit_symbol s}:\n`; + | Cdefine_label lbl -> + `{emit_label (lbl + 100000)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .short {emit_int n}\n` + | Cint32 n -> + ` .long {emit_nativeint n}\n` + | Cint n -> + ` {emit_string datag} {emit_nativeint n}\n` + | Csingle f -> + ` .float 0d{emit_string f}\n` + | Cdouble f -> + ` .double 0d{emit_string f}\n` + | Csymbol_address s -> + ` {emit_string datag} {emit_symbol s}\n` + | Clabel_address lbl -> + ` {emit_string datag} {emit_label (lbl + 100000)}\n` + | Cstring s -> + emit_bytes_directive " .byte " s + | Cskip n -> + if n > 0 then ` .space {emit_int n}\n` + | Calign n -> + ` .align {emit_int (Misc.log2 n)}\n` + +let data l = + emit_string data_space; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + defined_functions := StringSet.empty; + external_functions := StringSet.empty; + (* Emit the beginning of the segments *) + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + emit_string data_space; + declare_global_data lbl_begin; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + emit_string code_space; + declare_global_data lbl_begin; + `{emit_symbol lbl_begin}:\n` + +let end_assembly() = + if pic_externals then + (* Emit the pointers to external functions *) + StringSet.iter emit_external !external_functions; + (* Emit the end of the segments *) + emit_string code_space; + let lbl_end = Compilenv.make_symbol (Some "code_end") in + declare_global_data lbl_end; + `{emit_symbol lbl_end}:\n`; + ` .long 0\n`; + emit_string data_space; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + declare_global_data lbl_end; + `{emit_symbol lbl_end}:\n`; + ` {emit_string datag} 0\n`; + (* Emit the frame descriptors *) + emit_string rodata_space; + let lbl = Compilenv.make_symbol (Some "frametable") in + declare_global_data lbl; + `{emit_symbol lbl}:\n`; + emit_frames + { efa_label = (fun l -> ` {emit_string datag} {emit_label l}\n`); + efa_16 = (fun n -> ` .short {emit_int n}\n`); + efa_32 = (fun n -> ` .long {emit_int32 n}\n`); + efa_word = (fun n -> ` {emit_string datag} {emit_int n}\n`); + efa_align = (fun n -> ` .align {emit_int (Misc.log2 n)}\n`); + efa_label_rel = (fun lbl ofs -> + ` .long ({emit_label lbl} - .) + {emit_int32 ofs}\n`); + efa_def_label = (fun l -> `{emit_label l}:\n`); + efa_string = (fun s -> emit_bytes_directive " .byte " (s ^ "\000")) + } diff --git a/asmcomp/power/proc.ml b/asmcomp/power/proc.ml new file mode 100644 index 0000000..8b5bcb2 --- /dev/null +++ b/asmcomp/power/proc.ml @@ -0,0 +1,241 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.14 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the Power PC *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = false + +(* Registers available for register allocation *) + +(* Integer register map: + 0 temporary, null register for some operations + 1 stack pointer + 2 pointer to table of contents + 3 - 10 function arguments and results + 11 - 12 temporaries + 13 pointer to small data area + 14 - 28 general purpose, preserved by C + 29 trap pointer + 30 allocation limit + 31 allocation pointer + Floating-point register map: + 0 temporary + 1 - 13 function arguments and results + 14 - 31 general purpose, preserved by C +*) + +let int_reg_name = + if Config.system = "rhapsody" then + [| "r3"; "r4"; "r5"; "r6"; "r7"; "r8"; "r9"; "r10"; + "r14"; "r15"; "r16"; "r17"; "r18"; "r19"; "r20"; "r21"; + "r22"; "r23"; "r24"; "r25"; "r26"; "r27"; "r28" |] + else + [| "3"; "4"; "5"; "6"; "7"; "8"; "9"; "10"; + "14"; "15"; "16"; "17"; "18"; "19"; "20"; "21"; + "22"; "23"; "24"; "25"; "26"; "27"; "28" |] + +let float_reg_name = + if Config.system = "rhapsody" then + [| "f1"; "f2"; "f3"; "f4"; "f5"; "f6"; "f7"; "f8"; + "f9"; "f10"; "f11"; "f12"; "f13"; "f14"; "f15"; "f16"; + "f17"; "f18"; "f19"; "f20"; "f21"; "f22"; "f23"; "f24"; + "f25"; "f26"; "f27"; "f28"; "f29"; "f30"; "f31" |] + else + [| "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" |] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 23; 31 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 23 Reg.dummy in + for i = 0 to 22 do v.(i) <- Reg.at_location Int (Reg i) done; v + +let hard_float_reg = + let v = Array.create 31 Reg.dummy in + for i = 0 to 30 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; v + +let all_phys_regs = + Array.append hard_int_reg hard_float_reg + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions + first_int last_int first_float last_float make_stack stack_ofs arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref stack_ofs in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 16) + (* Keep stack 16-aligned. *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 0 7 100 112 outgoing 0 arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 0 7 100 112 incoming 0 arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 7 100 112 not_supported 0 res in loc + +(* C calling conventions under PowerOpen: + use GPR 3-10 and FPR 1-13 just like ML calling + conventions, but always reserve stack space for all arguments. + Also, using a float register automatically reserves two int registers + (in 32-bit mode) or one int register (in 64-bit mode). + (If we were to call a non-prototyped C function, each float argument + would have to go both in a float reg and in the matching pair + of integer regs.) + + C calling conventions under SVR4: + use GPR 3-10 and FPR 1-8 just like ML calling conventions. + Using a float register does not affect the int registers. + Always reserve 8 bytes at bottom of stack, plus whatever is needed + to hold the overflow arguments. *) + +let poweropen_external_conventions first_int last_int + first_float last_float arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref (14 * size_addr) in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (Outgoing !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (Outgoing !ofs) Float; + ofs := !ofs + size_float + end; + int := !int + (if ppc64 then 1 else 2) + done; + (loc, Misc.align !ofs 16) (* Keep stack 16-aligned *) + +let loc_external_arguments = + match Config.system with + | "rhapsody" -> poweropen_external_conventions 0 7 100 112 + | "elf" | "bsd" -> calling_conventions 0 7 100 107 outgoing 8 + | _ -> assert false + +let extcall_use_push = false + +(* Results are in GPR 3 and FPR 1 *) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported 0 res in loc + +(* Exceptions are in GPR 3 *) + +let loc_exn_bucket = phys_reg 0 + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = + Array.of_list(List.map phys_reg + [0; 1; 2; 3; 4; 5; 6; 7; + 100; 101; 102; 103; 104; 105; 106; 107; 108; 109; 110; 111; 112]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 15 + | _ -> 23 + +let max_register_pressure = function + Iextcall(_, _) -> [| 15; 18 |] + | _ -> [| 23; 30 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler *) + +let assemble_file infile outfile = + Ccomp.command (Config.asm ^ " -o " ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) + +open Clflags;; +open Config;; diff --git a/asmcomp/power/reload.ml b/asmcomp/power/reload.ml new file mode 100644 index 0000000..9259cb2 --- /dev/null +++ b/asmcomp/power/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.3 1999-11-17 18:56:46 xleroy Exp $ *) + +(* Reloading for the PowerPC *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/power/scheduling.ml b/asmcomp/power/scheduling.ml new file mode 100644 index 0000000..acb5777 --- /dev/null +++ b/asmcomp/power/scheduling.ml @@ -0,0 +1,66 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.6 2004-06-19 16:13:33 xleroy Exp $ *) + +(* Instruction scheduling for the Power PC *) + +open Arch +open Mach + +class scheduler = object + +inherit Schedgen.scheduler_generic + +(* Latencies (in cycles). Based roughly on the "common model". *) + +method oper_latency = function + Ireload -> 2 + | Iload(_, _) -> 2 + | Iconst_float _ -> 2 (* turned into a load *) + | Iconst_symbol _ -> 1 + | Iintop Imul -> 9 + | Iintop_imm(Imul, _) -> 5 + | Iintop(Idiv | Imod) -> 36 + | Iaddf | Isubf -> 4 + | Imulf -> 5 + | Idivf -> 33 + | Ispecific(Imultaddf | Imultsubf) -> 5 + | _ -> 1 + +method reload_retaddr_latency = 12 + (* If we can have that many cycles between the reloadretaddr and the + return, we can expect that the blr branch will be completely folded. *) + +(* Issue cycles. Rough approximations. *) + +method oper_issue_cycles = function + Iconst_float _ | Iconst_symbol _ -> 2 + | Iload(_, Ibased(_, _)) -> 2 + | Istore(_, Ibased(_, _)) -> 2 + | Ialloc _ -> 4 + | Iintop(Imod) -> 40 (* assuming full stall *) + | Iintop(Icomp _) -> 4 + | Iintop_imm(Idiv, _) -> 2 + | Iintop_imm(Imod, _) -> 4 + | Iintop_imm(Icomp _, _) -> 4 + | Ifloatofint -> 9 + | Iintoffloat -> 4 + | _ -> 1 + +method reload_retaddr_issue_cycles = 3 + (* load then stalling mtlr *) + +end + +let fundecl f = (new scheduler)#schedule_fundecl f + diff --git a/asmcomp/power/selection.ml b/asmcomp/power/selection.ml new file mode 100644 index 0000000..fe632af --- /dev/null +++ b/asmcomp/power/selection.ml @@ -0,0 +1,103 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.8 2007-11-09 15:06:57 frisch Exp $ *) + +(* Instruction selection for the Power PC processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Recognition of addressing modes *) + +type addressing_expr = + Asymbol of string + | Alinear of expression + | Aadd of expression * expression + +let rec select_addr = function + Cconst_symbol s -> + (Asymbol s, 0) + | Cop((Caddi | Cadda), [arg; Cconst_int m]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop((Caddi | Cadda), [Cconst_int m; arg]) -> + let (a, n) = select_addr arg in (a, n + m) + | Cop((Caddi | Cadda), [arg1; arg2]) -> + begin match (select_addr arg1, select_addr arg2) with + ((Alinear e1, n1), (Alinear e2, n2)) -> + (Aadd(e1, e2), n1 + n2) + | _ -> + (Aadd(arg1, arg2), 0) + end + | exp -> + (Alinear exp, 0) + +(* Instruction selection *) + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = (n <= 32767) && (n >= -32768) + +method select_addressing exp = + match select_addr exp with + (Asymbol s, d) -> + (Ibased(s, d), Ctuple []) + | (Alinear e, d) -> + (Iindexed d, e) + | (Aadd(e1, e2), d) -> + if d = 0 + then (Iindexed2, Ctuple[e1; e2]) + else (Iindexed d, Cop(Cadda, [e1; e2])) + +method select_operation op args = + match (op, args) with + (* Prevent the recognition of (x / cst) and (x % cst) when cst is not + a power of 2, which do not correspond to an instruction. *) + (Cdivi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg]) + | (Cdivi, _) -> + (Iintop Idiv, args) + | (Cmodi, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg]) + | (Cmodi, _) -> + (Iintop Imod, args) + (* The and, or and xor instructions have a different range of immediate + operands than the other instructions *) + | (Cand, _) -> self#select_logical Iand args + | (Cor, _) -> self#select_logical Ior args + | (Cxor, _) -> self#select_logical Ixor args + (* Recognize mult-add and mult-sub instructions *) + | (Caddf, [Cop(Cmulf, [arg1; arg2]); arg3]) -> + (Ispecific Imultaddf, [arg1; arg2; arg3]) + | (Caddf, [arg3; Cop(Cmulf, [arg1; arg2])]) -> + (Ispecific Imultaddf, [arg1; arg2; arg3]) + | (Csubf, [Cop(Cmulf, [arg1; arg2]); arg3]) -> + (Ispecific Imultsubf, [arg1; arg2; arg3]) + | _ -> + super#select_operation op args + +method select_logical op = function + [arg; Cconst_int n] when n >= 0 && n <= 0xFFFF -> + (Iintop_imm(op, n), [arg]) + | [Cconst_int n; arg] when n >= 0 && n <= 0xFFFF -> + (Iintop_imm(op, n), [arg]) + | args -> + (Iintop op, args) + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/printcmm.ml b/asmcomp/printcmm.ml new file mode 100644 index 0000000..f58c19e --- /dev/null +++ b/asmcomp/printcmm.ml @@ -0,0 +1,204 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printcmm.ml,v 1.25 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Pretty-printing of C-- code *) + +open Format +open Cmm + +let machtype_component ppf = function + | Addr -> fprintf ppf "addr" + | Int -> fprintf ppf "int" + | Float -> fprintf ppf "float" + +let machtype ppf mty = + match Array.length mty with + | 0 -> fprintf ppf "unit" + | n -> machtype_component ppf mty.(0); + for i = 1 to n-1 do + fprintf ppf "*%a" machtype_component mty.(i) + done + +let comparison = function + | Ceq -> "==" + | Cne -> "!=" + | Clt -> "<" + | Cle -> "<=" + | Cgt -> ">" + | Cge -> ">=" + +let chunk = function + | Byte_unsigned -> "unsigned int8" + | Byte_signed -> "signed int8" + | Sixteen_unsigned -> "unsigned int16" + | Sixteen_signed -> "signed int16" + | Thirtytwo_unsigned -> "unsigned int32" + | Thirtytwo_signed -> "signed int32" + | Word -> "" + | Single -> "float32" + | Double -> "float64" + | Double_u -> "float64u" + +let operation = function + | Capply(ty, d) -> "app" ^ Debuginfo.to_string d + | Cextcall(lbl, ty, alloc, d) -> + Printf.sprintf "extcall \"%s\"%s" lbl (Debuginfo.to_string d) + | Cload Word -> "load" + | Cload c -> Printf.sprintf "load %s" (chunk c) + | Calloc -> "alloc" + | Cstore Word -> "store" + | Cstore c -> Printf.sprintf "store %s" (chunk c) + | Caddi -> "+" + | Csubi -> "-" + | Cmuli -> "*" + | Cdivi -> "/" + | Cmodi -> "mod" + | Cand -> "and" + | Cor -> "or" + | Cxor -> "xor" + | Clsl -> "<<" + | Clsr -> ">>u" + | Casr -> ">>s" + | Ccmpi c -> comparison c + | Cadda -> "+a" + | Csuba -> "-a" + | Ccmpa c -> Printf.sprintf "%sa" (comparison c) + | Cnegf -> "~f" + | Cabsf -> "absf" + | Caddf -> "+f" + | Csubf -> "-f" + | Cmulf -> "*f" + | Cdivf -> "/f" + | Cfloatofint -> "floatofint" + | Cintoffloat -> "intoffloat" + | Ccmpf c -> Printf.sprintf "%sf" (comparison c) + | Craise d -> "raise" ^ Debuginfo.to_string d + | Ccheckbound d -> "checkbound" ^ Debuginfo.to_string d + +let rec expr ppf = function + | Cconst_int n -> fprintf ppf "%i" n + | Cconst_natint n -> fprintf ppf "%s" (Nativeint.to_string n) + | Cconst_float s -> fprintf ppf "%s" s + | Cconst_symbol s -> fprintf ppf "\"%s\"" s + | Cconst_pointer n -> fprintf ppf "%ia" n + | Cconst_natpointer n -> fprintf ppf "%sa" (Nativeint.to_string n) + | Cvar id -> Ident.print ppf id + | Clet(id, def, (Clet(_, _, _) as body)) -> + let print_binding id ppf def = + fprintf ppf "@[<2>%a@ %a@]" Ident.print id expr def in + let rec in_part ppf = function + | Clet(id, def, body) -> + fprintf ppf "@ %a" (print_binding id) def; + in_part ppf body + | exp -> exp in + fprintf ppf "@[<2>(let@ @[<1>(%a" (print_binding id) def; + let exp = in_part ppf body in + fprintf ppf ")@]@ %a)@]" sequence exp + | Clet(id, def, body) -> + fprintf ppf + "@[<2>(let@ @[<2>%a@ %a@]@ %a)@]" + Ident.print id expr def sequence body + | Cassign(id, exp) -> + fprintf ppf "@[<2>(assign @[<2>%a@ %a@])@]" Ident.print id expr exp + | Ctuple el -> + let tuple ppf el = + let first = ref true in + List.iter + (fun e -> + if !first then first := false else fprintf ppf "@ "; + expr ppf e) + el in + fprintf ppf "@[<1>[%a]@]" tuple el + | Cop(op, el) -> + fprintf ppf "@[<2>(%s" (operation op); + List.iter (fun e -> fprintf ppf "@ %a" expr e) el; + begin match op with + | Capply (mty, _) -> fprintf ppf "@ %a" machtype mty + | Cextcall(_, mty, _, _) -> fprintf ppf "@ %a" machtype mty + | _ -> () + end; + fprintf ppf ")@]" + | Csequence(e1, e2) -> + fprintf ppf "@[<2>(seq@ %a@ %a)@]" sequence e1 sequence e2 + | Cifthenelse(e1, e2, e3) -> + fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" expr e1 expr e2 expr e3 + | Cswitch(e1, index, cases) -> + let print_case i ppf = + for j = 0 to Array.length index - 1 do + if index.(j) = i then fprintf ppf "case %i:" j + done in + let print_cases ppf = + for i = 0 to Array.length cases - 1 do + fprintf ppf "@ @[<2>%t@ %a@]" (print_case i) sequence cases.(i) + done in + fprintf ppf "@[@[<2>(switch@ %a@ @]%t)@]" expr e1 print_cases + | Cloop e -> + fprintf ppf "@[<2>(loop@ %a)@]" sequence e + | Ccatch(i, ids, e1, e2) -> + fprintf ppf + "@[<2>(catch@ %a@;<1 -2>with(%d%a)@ %a)@]" + sequence e1 i + (fun ppf ids -> + List.iter + (fun id -> fprintf ppf " %a" Ident.print id) + ids) ids + sequence e2 + | Cexit (i, el) -> + fprintf ppf "@[<2>(exit %d" i ; + List.iter (fun e -> fprintf ppf "@ %a" expr e) el; + fprintf ppf ")@]" + | Ctrywith(e1, id, e2) -> + fprintf ppf "@[<2>(try@ %a@;<1 -2>with@ %a@ %a)@]" + sequence e1 Ident.print id sequence e2 + +and sequence ppf = function + | Csequence(e1, e2) -> fprintf ppf "%a@ %a" sequence e1 sequence e2 + | e -> expression ppf e + +and expression ppf e = fprintf ppf "%a" expr e + +let fundecl ppf f = + let print_cases ppf cases = + let first = ref true in + List.iter + (fun (id, ty) -> + if !first then first := false else fprintf ppf "@ "; + fprintf ppf "%a: %a" Ident.print id machtype ty) + cases in + fprintf ppf "@[<1>(function %s@;<1 4>@[<1>(%a)@]@ @[%a@])@]@." + f.fun_name print_cases f.fun_args sequence f.fun_body + +let data_item ppf = function + | Cdefine_symbol s -> fprintf ppf "\"%s\":" s + | Cdefine_label l -> fprintf ppf "L%i:" l + | Cglobal_symbol s -> fprintf ppf "global \"%s\"" s + | Cint8 n -> fprintf ppf "byte %i" n + | Cint16 n -> fprintf ppf "int16 %i" n + | Cint32 n -> fprintf ppf "int32 %s" (Nativeint.to_string n) + | Cint n -> fprintf ppf "int %s" (Nativeint.to_string n) + | Csingle f -> fprintf ppf "single %s" f + | Cdouble f -> fprintf ppf "double %s" f + | Csymbol_address s -> fprintf ppf "addr \"%s\"" s + | Clabel_address l -> fprintf ppf "addr L%i" l + | Cstring s -> fprintf ppf "string \"%s\"" s + | Cskip n -> fprintf ppf "skip %i" n + | Calign n -> fprintf ppf "align %i" n + +let data ppf dl = + let items ppf = List.iter (fun d -> fprintf ppf "@ %a" data_item d) dl in + fprintf ppf "@[(data%t)@]" items + +let phrase ppf = function + | Cfunction f -> fundecl ppf f + | Cdata dl -> data ppf dl diff --git a/asmcomp/printcmm.mli b/asmcomp/printcmm.mli new file mode 100644 index 0000000..d58ab25 --- /dev/null +++ b/asmcomp/printcmm.mli @@ -0,0 +1,27 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printcmm.mli,v 1.6 2000-04-21 08:10:34 weis Exp $ *) + +(* Pretty-printing of C-- code *) + +open Format + +val machtype_component : formatter -> Cmm.machtype_component -> unit +val machtype : formatter -> Cmm.machtype_component array -> unit +val comparison : Cmm.comparison -> string +val chunk : Cmm.memory_chunk -> string +val operation : Cmm.operation -> string +val expression : formatter -> Cmm.expression -> unit +val fundecl : formatter -> Cmm.fundecl -> unit +val data : formatter -> Cmm.data_item list -> unit +val phrase : formatter -> Cmm.phrase -> unit diff --git a/asmcomp/printlinear.ml b/asmcomp/printlinear.ml new file mode 100644 index 0000000..d59b9e6 --- /dev/null +++ b/asmcomp/printlinear.ml @@ -0,0 +1,77 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printlinear.ml,v 1.13 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Pretty-printing of linearized machine code *) + +open Format +open Mach +open Printmach +open Linearize + +let label ppf l = + Format.fprintf ppf "L%i" l + +let instr ppf i = + begin match i.desc with + | Lend -> () + | Lop op -> + begin match op with + | Ialloc _ | Icall_ind | Icall_imm _ | Iextcall(_, _) -> + fprintf ppf "@[<1>{%a}@]@," regsetaddr i.live + | _ -> () + end; + operation op i.arg ppf i.res + | Lreloadretaddr -> + fprintf ppf "reload retaddr" + | Lreturn -> + fprintf ppf "return %a" regs i.arg + | Llabel lbl -> + fprintf ppf "%a:" label lbl + | Lbranch lbl -> + fprintf ppf "goto %a" label lbl + | Lcondbranch(tst, lbl) -> + fprintf ppf "if %a goto %a" (test tst) i.arg label lbl + | Lcondbranch3(lbl0, lbl1, lbl2) -> + fprintf ppf "switch3 %a" reg i.arg.(0); + let case n = function + | None -> () + | Some lbl -> + fprintf ppf "@,case %i: goto %a" n label lbl in + case 0 lbl0; case 1 lbl1; case 2 lbl2; + fprintf ppf "@,endswitch" + | Lswitch lblv -> + fprintf ppf "switch %a" reg i.arg.(0); + for i = 0 to Array.length lblv - 1 do + fprintf ppf "case %i: goto %a" i label lblv.(i) + done; + fprintf ppf "@,endswitch" + | Lsetuptrap lbl -> + fprintf ppf "setup trap %a" label lbl + | Lpushtrap -> + fprintf ppf "push trap" + | Lpoptrap -> + fprintf ppf "pop trap" + | Lraise -> + fprintf ppf "raise %a" reg i.arg.(0) + end; + if i.dbg != Debuginfo.none then + fprintf ppf " %s" (Debuginfo.to_string i.dbg) + +let rec all_instr ppf i = + match i.desc with + | Lend -> () + | _ -> fprintf ppf "%a@,%a" instr i all_instr i.next + +let fundecl ppf f = + fprintf ppf "@[%s:@,%a@]" f.fun_name all_instr f.fun_body diff --git a/asmcomp/printlinear.mli b/asmcomp/printlinear.mli new file mode 100644 index 0000000..4c287bf --- /dev/null +++ b/asmcomp/printlinear.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printlinear.mli,v 1.5 2000-04-21 08:10:35 weis Exp $ *) + +(* Pretty-printing of linearized machine code *) + +open Format +open Linearize + +val instr: formatter -> instruction -> unit +val fundecl: formatter -> fundecl -> unit diff --git a/asmcomp/printmach.ml b/asmcomp/printmach.ml new file mode 100644 index 0000000..36b5efe --- /dev/null +++ b/asmcomp/printmach.ml @@ -0,0 +1,219 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printmach.ml,v 1.23 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Pretty-printing of pseudo machine code *) + +open Format +open Cmm +open Reg +open Mach + +let reg ppf r = + if String.length r.name > 0 then + fprintf ppf "%s" r.name + else + fprintf ppf "%s" (match r.typ with Addr -> "A" | Int -> "I" | Float -> "F"); + fprintf ppf "/%i" r.stamp; + begin match r.loc with + | Unknown -> () + | Reg r -> + fprintf ppf "[%s]" (Proc.register_name r) + | Stack(Local s) -> + fprintf ppf "[s%i]" s + | Stack(Incoming s) -> + fprintf ppf "[si%i]" s + | Stack(Outgoing s) -> + fprintf ppf "[so%i]" s + end + +let regs ppf v = + match Array.length v with + | 0 -> () + | 1 -> reg ppf v.(0) + | n -> reg ppf v.(0); + for i = 1 to n-1 do fprintf ppf " %a" reg v.(i) done + +let regset ppf s = + let first = ref true in + Reg.Set.iter + (fun r -> + if !first then begin first := false; fprintf ppf "%a" reg r end + else fprintf ppf "@ %a" reg r) + s + +let regsetaddr ppf s = + let first = ref true in + Reg.Set.iter + (fun r -> + if !first then begin first := false; fprintf ppf "%a" reg r end + else fprintf ppf "@ %a" reg r; + match r.typ with Addr -> fprintf ppf "*" | _ -> ()) + s + +let intcomp = function + | Isigned c -> Printf.sprintf " %ss " (Printcmm.comparison c) + | Iunsigned c -> Printf.sprintf " %su " (Printcmm.comparison c) + +let floatcomp c = + Printf.sprintf " %sf " (Printcmm.comparison c) + +let intop = function + | Iadd -> " + " + | Isub -> " - " + | Imul -> " * " + | Idiv -> " div " + | Imod -> " mod " + | Iand -> " & " + | Ior -> " | " + | Ixor -> " ^ " + | Ilsl -> " << " + | Ilsr -> " >>u " + | Iasr -> " >>s " + | Icomp cmp -> intcomp cmp + | Icheckbound -> " check > " + +let test tst ppf arg = + match tst with + | Itruetest -> reg ppf arg.(0) + | Ifalsetest -> fprintf ppf "not %a" reg arg.(0) + | Iinttest cmp -> fprintf ppf "%a%s%a" reg arg.(0) (intcomp cmp) reg arg.(1) + | Iinttest_imm(cmp, n) -> fprintf ppf "%a%s%i" reg arg.(0) (intcomp cmp) n + | Ifloattest(cmp, neg) -> + fprintf ppf "%s%a%s%a" + (if neg then "not " else "") + reg arg.(0) (floatcomp cmp) reg arg.(1) + | Ieventest -> fprintf ppf "%a & 1 == 0" reg arg.(0) + | Ioddtest -> fprintf ppf "%a & 1 == 1" reg arg.(0) + +let print_live = ref false + +let operation op arg ppf res = + if Array.length res > 0 then fprintf ppf "%a := " regs res; + match op with + | Imove -> regs ppf arg + | Ispill -> fprintf ppf "%a (spill)" regs arg + | Ireload -> fprintf ppf "%a (reload)" regs arg + | Iconst_int n -> fprintf ppf "%s" (Nativeint.to_string n) + | Iconst_float s -> fprintf ppf "%s" s + | Iconst_symbol s -> fprintf ppf "\"%s\"" s + | Icall_ind -> fprintf ppf "call %a" regs arg + | Icall_imm lbl -> fprintf ppf "call \"%s\" %a" lbl regs arg + | Itailcall_ind -> fprintf ppf "tailcall %a" regs arg + | Itailcall_imm lbl -> fprintf ppf "tailcall \"%s\" %a" lbl regs arg + | Iextcall(lbl, alloc) -> + fprintf ppf "extcall \"%s\" %a%s" lbl regs arg + (if not alloc then "" else " (noalloc)") + | Istackoffset n -> + fprintf ppf "offset stack %i" n + | Iload(chunk, addr) -> + fprintf ppf "%s[%a]" + (Printcmm.chunk chunk) (Arch.print_addressing reg addr) arg + | Istore(chunk, addr) -> + fprintf ppf "%s[%a] := %a" + (Printcmm.chunk chunk) + (Arch.print_addressing reg addr) + (Array.sub arg 1 (Array.length arg - 1)) + reg arg.(0) + | Ialloc n -> fprintf ppf "alloc %i" n + | Iintop(op) -> fprintf ppf "%a%s%a" reg arg.(0) (intop op) reg arg.(1) + | Iintop_imm(op, n) -> fprintf ppf "%a%s%i" reg arg.(0) (intop op) n + | Inegf -> fprintf ppf "-f %a" reg arg.(0) + | Iabsf -> fprintf ppf "absf %a" reg arg.(0) + | Iaddf -> fprintf ppf "%a +f %a" reg arg.(0) reg arg.(1) + | Isubf -> fprintf ppf "%a -f %a" reg arg.(0) reg arg.(1) + | Imulf -> fprintf ppf "%a *f %a" reg arg.(0) reg arg.(1) + | Idivf -> fprintf ppf "%a /f %a" reg arg.(0) reg arg.(1) + | Ifloatofint -> fprintf ppf "floatofint %a" reg arg.(0) + | Iintoffloat -> fprintf ppf "intoffloat %a" reg arg.(0) + | Ispecific op -> + Arch.print_specific_operation reg op ppf arg + +let rec instr ppf i = + if !print_live then begin + fprintf ppf "@[<1>{%a" regsetaddr i.live; + if Array.length i.arg > 0 then fprintf ppf "@ +@ %a" regs i.arg; + fprintf ppf "}@]@,"; + end; + begin match i.desc with + | Iend -> () + | Iop op -> + operation op i.arg ppf i.res + | Ireturn -> + fprintf ppf "return %a" regs i.arg + | Iifthenelse(tst, ifso, ifnot) -> + fprintf ppf "@[if %a then@,%a" (test tst) i.arg instr ifso; + begin match ifnot.desc with + | Iend -> () + | _ -> fprintf ppf "@;<0 -2>else@,%a" instr ifnot + end; + fprintf ppf "@;<0 -2>endif@]" + | Iswitch(index, cases) -> + fprintf ppf "switch %a" reg i.arg.(0); + for i = 0 to Array.length cases - 1 do + fprintf ppf "@,@[@["; + for j = 0 to Array.length index - 1 do + if index.(j) = i then fprintf ppf "case %i:@," j + done; + fprintf ppf "@]@,%a@]" instr cases.(i) + done; + fprintf ppf "@,endswitch" + | Iloop(body) -> + fprintf ppf "@[loop@,%a@;<0 -2>endloop@]" instr body + | Icatch(i, body, handler) -> + fprintf + ppf "@[catch@,%a@;<0 -2>with(%d)@,%a@;<0 -2>endcatch@]" + instr body i instr handler + | Iexit i -> + fprintf ppf "exit(%d)" i + | Itrywith(body, handler) -> + fprintf ppf "@[try@,%a@;<0 -2>with@,%a@;<0 -2>endtry@]" + instr body instr handler + | Iraise -> + fprintf ppf "raise %a" reg i.arg.(0) + end; + if i.dbg != Debuginfo.none then + fprintf ppf " %s" (Debuginfo.to_string i.dbg); + begin match i.next.desc with + Iend -> () + | _ -> fprintf ppf "@,%a" instr i.next + end + +let fundecl ppf f = + fprintf ppf "@[%s(%a)@,%a@]" + f.fun_name regs f.fun_args instr f.fun_body + +let phase msg ppf f = + fprintf ppf "*** %s@.%a@." msg fundecl f + +let interference ppf r = + let interf ppf = + List.iter + (fun r -> fprintf ppf "@ %a" reg r) + r.interf in + fprintf ppf "@[<2>%a:%t@]@." reg r interf + +let interferences ppf () = + fprintf ppf "*** Interferences@."; + List.iter (interference ppf) (Reg.all_registers()) + +let preference ppf r = + let prefs ppf = + List.iter + (fun (r, w) -> fprintf ppf "@ %a weight %i" reg r w) + r.prefer in + fprintf ppf "@[<2>%a: %t@]@." reg r prefs + +let preferences ppf () = + fprintf ppf "*** Preferences@."; + List.iter (preference ppf) (Reg.all_registers()) diff --git a/asmcomp/printmach.mli b/asmcomp/printmach.mli new file mode 100644 index 0000000..309ad85 --- /dev/null +++ b/asmcomp/printmach.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printmach.mli,v 1.6 2000-04-21 08:10:37 weis Exp $ *) + +(* Pretty-printing of pseudo machine code *) + +open Format + +val reg: formatter -> Reg.t -> unit +val regs: formatter -> Reg.t array -> unit +val regset: formatter -> Reg.Set.t -> unit +val regsetaddr: formatter -> Reg.Set.t -> unit +val operation: Mach.operation -> Reg.t array -> formatter -> Reg.t array -> unit +val test: Mach.test -> formatter -> Reg.t array -> unit +val instr: formatter -> Mach.instruction -> unit +val fundecl: formatter -> Mach.fundecl -> unit +val phase: string -> formatter -> Mach.fundecl -> unit +val interferences: formatter -> unit -> unit +val preferences: formatter -> unit -> unit + +val print_live: bool ref diff --git a/asmcomp/proc.mli b/asmcomp/proc.mli new file mode 100644 index 0000000..f8162a4 --- /dev/null +++ b/asmcomp/proc.mli @@ -0,0 +1,50 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.mli,v 1.16 1999-11-17 18:56:35 xleroy Exp $ *) + +(* Processor descriptions *) + +(* Instruction selection *) +val word_addressed: bool + +(* Registers available for register allocation *) +val num_register_classes: int +val register_class: Reg.t -> int +val num_available_registers: int array +val first_available_register: int array +val register_name: int -> string +val phys_reg: int -> Reg.t +val rotate_registers: bool + +(* Calling conventions *) +val loc_arguments: Reg.t array -> Reg.t array * int +val loc_results: Reg.t array -> Reg.t array +val loc_parameters: Reg.t array -> Reg.t array +val loc_external_arguments: Reg.t array -> Reg.t array * int +val loc_external_results: Reg.t array -> Reg.t array +val loc_exn_bucket: Reg.t + +(* Maximal register pressures for pre-spilling *) +val safe_register_pressure: Mach.operation -> int +val max_register_pressure: Mach.operation -> int array + +(* Registers destroyed by operations *) +val destroyed_at_oper: Mach.instruction_desc -> Reg.t array +val destroyed_at_raise: Reg.t array + +(* Info for laying out the stack frame *) +val num_stack_slots: int array +val contains_calls: bool ref + +(* Calling the assembler *) +val assemble_file: string -> string -> int diff --git a/asmcomp/reg.ml b/asmcomp/reg.ml new file mode 100644 index 0000000..71b75bd --- /dev/null +++ b/asmcomp/reg.ml @@ -0,0 +1,144 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reg.ml,v 1.10 2000-06-29 11:44:06 xleroy Exp $ *) + +open Cmm + +type t = + { mutable name: string; + stamp: int; + typ: Cmm.machtype_component; + mutable loc: location; + mutable spill: bool; + mutable interf: t list; + mutable prefer: (t * int) list; + mutable degree: int; + mutable spill_cost: int; + mutable visited: bool } + +and location = + Unknown + | Reg of int + | Stack of stack_location + +and stack_location = + Local of int + | Incoming of int + | Outgoing of int + +type reg = t + +let dummy = + { name = ""; stamp = 0; typ = Int; loc = Unknown; spill = false; + interf = []; prefer = []; degree = 0; spill_cost = 0; visited = false } + +let currstamp = ref 0 +let reg_list = ref([] : t list) + +let create ty = + let r = { name = ""; stamp = !currstamp; typ = ty; loc = Unknown; + spill = false; interf = []; prefer = []; degree = 0; + spill_cost = 0; visited = false } in + reg_list := r :: !reg_list; + incr currstamp; + r + +let createv tyv = + let n = Array.length tyv in + let rv = Array.create n dummy in + for i = 0 to n-1 do rv.(i) <- create tyv.(i) done; + rv + +let clone r = + let nr = create r.typ in + nr.name <- r.name; + nr + +let at_location ty loc = + let r = { name = "R"; stamp = !currstamp; typ = ty; loc = loc; spill = false; + interf = []; prefer = []; degree = 0; spill_cost = 0; + visited = false } in + incr currstamp; + r + +let first_virtual_reg_stamp = ref (-1) + +let reset() = + (* When reset() is called for the first time, the current stamp reflects + all hard pseudo-registers that have been allocated by Proc, so + remember it and use it as the base stamp for allocating + soft pseudo-registers *) + if !first_virtual_reg_stamp = -1 then first_virtual_reg_stamp := !currstamp; + currstamp := !first_virtual_reg_stamp; + reg_list := [] + +let all_registers() = !reg_list +let num_registers() = !currstamp + +let reinit_reg r = + r.loc <- Unknown; + r.interf <- []; + r.prefer <- []; + r.degree <- 0; + (* Preserve the very high spill costs introduced by the reloading pass *) + if r.spill_cost >= 100000 + then r.spill_cost <- 100000 + else r.spill_cost <- 0 + +let reinit() = + List.iter reinit_reg !reg_list + +module RegOrder = + struct + type t = reg + let compare r1 r2 = r1.stamp - r2.stamp + end + +module Set = Set.Make(RegOrder) +module Map = Map.Make(RegOrder) + +let add_set_array s v = + match Array.length v with + 0 -> s + | 1 -> Set.add v.(0) s + | n -> let rec add_all i = + if i >= n then s else Set.add v.(i) (add_all(i+1)) + in add_all 0 + +let diff_set_array s v = + match Array.length v with + 0 -> s + | 1 -> Set.remove v.(0) s + | n -> let rec remove_all i = + if i >= n then s else Set.remove v.(i) (remove_all(i+1)) + in remove_all 0 + +let inter_set_array s v = + match Array.length v with + 0 -> Set.empty + | 1 -> if Set.mem v.(0) s + then Set.add v.(0) Set.empty + else Set.empty + | n -> let rec inter_all i = + if i >= n then Set.empty + else if Set.mem v.(i) s then Set.add v.(i) (inter_all(i+1)) + else inter_all(i+1) + in inter_all 0 + +let set_of_array v = + match Array.length v with + 0 -> Set.empty + | 1 -> Set.add v.(0) Set.empty + | n -> let rec add_all i = + if i >= n then Set.empty else Set.add v.(i) (add_all(i+1)) + in add_all 0 diff --git a/asmcomp/reg.mli b/asmcomp/reg.mli new file mode 100644 index 0000000..f63a1b4 --- /dev/null +++ b/asmcomp/reg.mli @@ -0,0 +1,56 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reg.mli,v 1.7 1999-11-17 18:56:35 xleroy Exp $ *) + +(* Pseudo-registers *) + +type t = + { mutable name: string; (* Name (for printing) *) + stamp: int; (* Unique stamp *) + typ: Cmm.machtype_component; (* Type of contents *) + mutable loc: location; (* Actual location *) + mutable spill: bool; (* "true" to force stack allocation *) + mutable interf: t list; (* Other regs live simultaneously *) + mutable prefer: (t * int) list; (* Preferences for other regs *) + mutable degree: int; (* Number of other regs live sim. *) + mutable spill_cost: int; (* Estimate of spilling cost *) + mutable visited: bool } (* For graph walks *) + +and location = + Unknown + | Reg of int + | Stack of stack_location + +and stack_location = + Local of int + | Incoming of int + | Outgoing of int + +val dummy: t +val create: Cmm.machtype_component -> t +val createv: Cmm.machtype -> t array +val clone: t -> t +val at_location: Cmm.machtype_component -> location -> t + +module Set: Set.S with type elt = t +module Map: Map.S with type key = t + +val add_set_array: Set.t -> t array -> Set.t +val diff_set_array: Set.t -> t array -> Set.t +val inter_set_array: Set.t -> t array -> Set.t +val set_of_array: t array -> Set.t + +val reset: unit -> unit +val all_registers: unit -> t list +val num_registers: unit -> int +val reinit: unit -> unit diff --git a/asmcomp/reload.mli b/asmcomp/reload.mli new file mode 100644 index 0000000..e695bd3 --- /dev/null +++ b/asmcomp/reload.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.mli,v 1.6 1999-11-17 18:56:35 xleroy Exp $ *) + +(* Insert load/stores for pseudoregs that got assigned to stack locations. *) + +val fundecl: Mach.fundecl -> Mach.fundecl * bool + diff --git a/asmcomp/reloadgen.ml b/asmcomp/reloadgen.ml new file mode 100644 index 0000000..55ef69c --- /dev/null +++ b/asmcomp/reloadgen.ml @@ -0,0 +1,140 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reloadgen.ml,v 1.6 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Insert load/stores for pseudoregs that got assigned to stack locations. *) + +open Misc +open Reg +open Mach + +let access_stack r = + try + for i = 0 to Array.length r - 1 do + match r.(i).loc with Stack _ -> raise Exit | _ -> () + done; + false + with Exit -> + true + +let insert_move src dst next = + if src.loc = dst.loc + then next + else instr_cons (Iop Imove) [|src|] [|dst|] next + +let insert_moves src dst next = + let rec insmoves i = + if i >= Array.length src + then next + else insert_move src.(i) dst.(i) (insmoves (i+1)) + in insmoves 0 + +class reload_generic = object (self) + +val mutable redo_regalloc = false + +method makereg r = + match r.loc with + Unknown -> fatal_error "Reload.makereg" + | Reg _ -> r + | Stack _ -> + redo_regalloc <- true; + let newr = Reg.clone r in + (* Strongly discourage spilling this register *) + newr.spill_cost <- 100000; + newr + +method private makeregs rv = + let n = Array.length rv in + let newv = Array.create n Reg.dummy in + for i = 0 to n-1 do newv.(i) <- self#makereg rv.(i) done; + newv + +method private makereg1 rv = + let newv = Array.copy rv in + newv.(0) <- self#makereg rv.(0); + newv + +method reload_operation op arg res = + (* By default, assume that arguments and results must reside + in hardware registers. For moves, allow one arg or one + res to be stack-allocated, but do something for + stack-to-stack moves *) + match op with + Imove | Ireload | Ispill -> + begin match arg.(0), res.(0) with + {loc = Stack s1}, {loc = Stack s2} when s1 <> s2 -> + ([| self#makereg arg.(0) |], res) + | _ -> + (arg, res) + end + | _ -> + (self#makeregs arg, self#makeregs res) + +method reload_test tst args = + self#makeregs args + +method private reload i = + match i.desc with + (* For function calls, returns, etc: the arguments and results are + already at the correct position (e.g. on stack for some arguments). + However, something needs to be done for the function pointer in + indirect calls. *) + Iend | Ireturn | Iop(Itailcall_imm _) | Iraise -> i + | Iop(Itailcall_ind) -> + let newarg = self#makereg1 i.arg in + insert_moves i.arg newarg + {i with arg = newarg} + | Iop(Icall_imm _ | Iextcall _) -> + {i with next = self#reload i.next} + | Iop(Icall_ind) -> + let newarg = self#makereg1 i.arg in + insert_moves i.arg newarg + {i with arg = newarg; next = self#reload i.next} + | Iop op -> + let (newarg, newres) = self#reload_operation op i.arg i.res in + insert_moves i.arg newarg + {i with arg = newarg; res = newres; next = + (insert_moves newres i.res + (self#reload i.next))} + | Iifthenelse(tst, ifso, ifnot) -> + let newarg = self#reload_test tst i.arg in + insert_moves i.arg newarg + (instr_cons + (Iifthenelse(tst, self#reload ifso, self#reload ifnot)) newarg [||] + (self#reload i.next)) + | Iswitch(index, cases) -> + let newarg = self#makeregs i.arg in + insert_moves i.arg newarg + (instr_cons (Iswitch(index, Array.map (self#reload) cases)) newarg [||] + (self#reload i.next)) + | Iloop body -> + instr_cons (Iloop(self#reload body)) [||] [||] (self#reload i.next) + | Icatch(nfail, body, handler) -> + instr_cons + (Icatch(nfail, self#reload body, self#reload handler)) [||] [||] + (self#reload i.next) + | Iexit i -> + instr_cons (Iexit i) [||] [||] dummy_instr + | Itrywith(body, handler) -> + instr_cons (Itrywith(self#reload body, self#reload handler)) [||] [||] + (self#reload i.next) + +method fundecl f = + redo_regalloc <- false; + let new_body = self#reload f.fun_body in + ({fun_name = f.fun_name; fun_args = f.fun_args; + fun_body = new_body; fun_fast = f.fun_fast}, + redo_regalloc) + +end diff --git a/asmcomp/reloadgen.mli b/asmcomp/reloadgen.mli new file mode 100644 index 0000000..339a384 --- /dev/null +++ b/asmcomp/reloadgen.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reloadgen.mli,v 1.4 1999-11-17 18:56:36 xleroy Exp $ *) + +class reload_generic : object + method reload_operation : + Mach.operation -> Reg.t array -> Reg.t array -> Reg.t array * Reg.t array + method reload_test : Mach.test -> Reg.t array -> Reg.t array + (* Can be overriden to reflect instructions that can operate + directly on stack locations *) + method makereg : Reg.t -> Reg.t + (* Can be overriden to avoid creating new registers of some class + (i.e. if all "registers" of that class are actually on stack) *) + method fundecl : Mach.fundecl -> Mach.fundecl * bool + (* The entry point *) +end diff --git a/asmcomp/schedgen.ml b/asmcomp/schedgen.ml new file mode 100644 index 0000000..fa3cde6 --- /dev/null +++ b/asmcomp/schedgen.ml @@ -0,0 +1,356 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: schedgen.ml,v 1.12 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Instruction scheduling *) + +open Misc +open Reg +open Mach +open Linearize + +(* Representation of the code DAG. *) + +type code_dag_node = + { instr: instruction; (* The instruction *) + delay: int; (* How many cycles before result is available *) + mutable sons: (code_dag_node * int) list; + (* Instructions that depend on it *) + mutable date: int; (* Start date *) + mutable length: int; (* Length of longest path to result *) + mutable ancestors: int; (* Number of ancestors *) + mutable emitted_ancestors: int } (* Number of emitted ancestors *) + +let dummy_node = + { instr = end_instr; delay = 0; sons = []; date = 0; + length = -1; ancestors = 0; emitted_ancestors = 0 } + +(* The code dag itself is represented by two tables from registers to nodes: + - "results" maps registers to the instructions that produced them; + - "uses" maps registers to the instructions that use them. + In addition: + - code_stores contains the latest store nodes emitted so far + - code_loads contains all load nodes emitted since the last store + - code_checkbounds contains the latest checkbound node not matched + by a subsequent load or store. *) + +let code_results = (Hashtbl.create 31 : (location, code_dag_node) Hashtbl.t) +let code_uses = (Hashtbl.create 31 : (location, code_dag_node) Hashtbl.t) +let code_stores = ref ([] : code_dag_node list) +let code_loads = ref ([] : code_dag_node list) +let code_checkbounds = ref ([] : code_dag_node list) + +let clear_code_dag () = + Hashtbl.clear code_results; + Hashtbl.clear code_uses; + code_stores := []; + code_loads := []; + code_checkbounds := [] + +(* Add an edge to the code DAG *) + +let add_edge ancestor son delay = + ancestor.sons <- (son, delay) :: ancestor.sons; + son.ancestors <- son.ancestors + 1 + +let add_edge_after son ancestor = add_edge ancestor son 0 + +(* Compute length of longest path to a result. + For leafs of the DAG, see whether their result is used in the instruction + immediately following the basic block (a "critical" output). *) + +let is_critical critical_outputs results = + try + for i = 0 to Array.length results - 1 do + let r = results.(i).loc in + for j = 0 to Array.length critical_outputs - 1 do + if critical_outputs.(j).loc = r then raise Exit + done + done; + false + with Exit -> + true + +let rec longest_path critical_outputs node = + if node.length < 0 then begin + match node.sons with + [] -> + node.length <- + if is_critical critical_outputs node.instr.res + || node.instr.desc = Lreloadretaddr (* alway critical *) + then node.delay + else 0 + | sons -> + node.length <- + List.fold_left + (fun len (son, delay) -> + max len (longest_path critical_outputs son + delay)) + 0 sons + end; + node.length + +(* Remove an instruction from the ready queue *) + +let rec remove_instr node = function + [] -> [] + | instr :: rem -> + if instr == node then rem else instr :: remove_instr node rem + +(* We treat Lreloadretaddr as a word-sized load *) + +let some_load = (Iload(Cmm.Word, Arch.identity_addressing)) + +(* The generic scheduler *) + +class virtual scheduler_generic = object (self) + +(* Determine whether an operation ends a basic block or not. + Can be overriden for some processors to signal specific instructions + that terminate a basic block. *) + +method oper_in_basic_block = function + Icall_ind -> false + | Icall_imm _ -> false + | Itailcall_ind -> false + | Itailcall_imm _ -> false + | Iextcall _ -> false + | Istackoffset _ -> false + | Ialloc _ -> false + | _ -> true + +(* Determine whether an instruction ends a basic block or not *) + +method private instr_in_basic_block instr = + match instr.desc with + Lop op -> self#oper_in_basic_block op + | Lreloadretaddr -> true + | _ -> false + +(* Determine whether an operation is a memory store or a memory load. + Can be overriden for some processors to signal specific + load or store instructions (e.g. on the I386). *) + +method is_store = function + Istore(_, _) -> true + | _ -> false + +method is_load = function + Iload(_, _) -> true + | _ -> false + +method is_checkbound = function + Iintop Icheckbound -> true + | Iintop_imm(Icheckbound, _) -> true + | _ -> false + +method private instr_is_store instr = + match instr.desc with + Lop op -> self#is_store op + | _ -> false + +method private instr_is_load instr = + match instr.desc with + Lop op -> self#is_load op + | _ -> false + +method private instr_is_checkbound instr = + match instr.desc with + Lop op -> self#is_checkbound op + | _ -> false + +(* Estimate the latency of an operation. *) + +method virtual oper_latency : Mach.operation -> int + +(* Estimate the latency of a Lreloadretaddr operation. *) + +method reload_retaddr_latency = self#oper_latency some_load + +(* Estimate the delay needed to evaluate an instruction *) + +method private instr_latency instr = + match instr.desc with + Lop op -> self#oper_latency op + | Lreloadretaddr -> self#reload_retaddr_latency + | _ -> assert false + +(* Estimate the number of cycles consumed by emitting an operation. *) + +method virtual oper_issue_cycles : Mach.operation -> int + +(* Estimate the number of cycles consumed by emitting a Lreloadretaddr. *) + +method reload_retaddr_issue_cycles = self#oper_issue_cycles some_load + +(* Estimate the number of cycles consumed by emitting an instruction. *) + +method private instr_issue_cycles instr = + match instr.desc with + Lop op -> self#oper_issue_cycles op + | Lreloadretaddr -> self#reload_retaddr_issue_cycles + | _ -> assert false + +(* Add an instruction to the code dag *) + +method private add_instruction ready_queue instr = + let delay = self#instr_latency instr in + let node = + { instr = instr; + delay = delay; + sons = []; + date = 0; + length = -1; + ancestors = 0; + emitted_ancestors = 0 } in + (* Add edges from all instructions that define one of the registers used + (RAW dependencies) *) + for i = 0 to Array.length instr.arg - 1 do + try + let ancestor = Hashtbl.find code_results instr.arg.(i).loc in + add_edge ancestor node ancestor.delay + with Not_found -> + () + done; + (* Also add edges from all instructions that use one of the result regs + of this instruction (WAR dependencies). *) + for i = 0 to Array.length instr.res - 1 do + let ancestors = Hashtbl.find_all code_uses instr.res.(i).loc in + List.iter (add_edge_after node) ancestors + done; + (* Also add edges from all instructions that have already defined one + of the results of this instruction (WAW dependencies). *) + for i = 0 to Array.length instr.res - 1 do + try + let ancestor = Hashtbl.find code_results instr.res.(i).loc in + add_edge ancestor node 0 + with Not_found -> + () + done; + (* If this is a load, add edges from the most recent store viewed so + far (if any) and remember the load. Also add edges from the most + recent checkbound and forget that checkbound. *) + if self#instr_is_load instr then begin + List.iter (add_edge_after node) !code_stores; + code_loads := node :: !code_loads; + List.iter (add_edge_after node) !code_checkbounds; + code_checkbounds := [] + end + (* If this is a store, add edges from the most recent store, + as well as all loads viewed since then, and also the most recent + checkbound. Remember the store, + discarding the previous stores, loads and checkbounds. *) + else if self#instr_is_store instr then begin + List.iter (add_edge_after node) !code_stores; + List.iter (add_edge_after node) !code_loads; + List.iter (add_edge_after node) !code_checkbounds; + code_stores := [node]; + code_loads := []; + code_checkbounds := [] + end + else if self#instr_is_checkbound instr then begin + code_checkbounds := [node] + end; + (* Remember the registers used and produced by this instruction *) + for i = 0 to Array.length instr.res - 1 do + Hashtbl.add code_results instr.res.(i).loc node + done; + for i = 0 to Array.length instr.arg - 1 do + Hashtbl.add code_uses instr.arg.(i).loc node + done; + (* If this is a root instruction (all arguments already computed), + add it to the ready queue *) + if node.ancestors = 0 then node :: ready_queue else ready_queue + +(* Given a list of instructions and a date, choose one or several + that are ready to be computed (start date <= current date) + and that we can emit in one cycle. Favor instructions with + maximal distance to result. If we can't find any, return None. + This does not take multiple issues into account, though. *) + +method private ready_instruction date queue = + let rec extract best = function + [] -> + if best == dummy_node then None else Some best + | instr :: rem -> + let new_best = + if instr.date <= date && instr.length > best.length + then instr else best in + extract new_best rem in + extract dummy_node queue + +(* Schedule a basic block, adding its instructions in front of the given + instruction sequence *) + +method private reschedule ready_queue date cont = + if ready_queue = [] then cont else begin + match self#ready_instruction date ready_queue with + None -> + self#reschedule ready_queue (date + 1) cont + | Some node -> + (* Remove node from queue *) + let new_queue = ref (remove_instr node ready_queue) in + (* Update the start date and number of ancestors emitted of + all descendents of this node. Enter those that become ready + in the queue. *) + let issue_cycles = self#instr_issue_cycles node.instr in + List.iter + (fun (son, delay) -> + let completion_date = date + issue_cycles + delay - 1 in + if son.date < completion_date then son.date <- completion_date; + son.emitted_ancestors <- son.emitted_ancestors + 1; + if son.emitted_ancestors = son.ancestors then + new_queue := son :: !new_queue) + node.sons; + instr_cons node.instr.desc node.instr.arg node.instr.res + (self#reschedule !new_queue (date + issue_cycles) cont) + end + +(* Entry point *) +(* Don't bother to schedule for initialization code and the like. *) + +method schedule_fundecl f = + + let rec schedule i = + match i.desc with + Lend -> i + | _ -> + if self#instr_in_basic_block i then begin + clear_code_dag(); + schedule_block [] i + end else + { i with next = schedule i.next } + + and schedule_block ready_queue i = + if self#instr_in_basic_block i then + schedule_block (self#add_instruction ready_queue i) i.next + else begin + let critical_outputs = + match i.desc with + Lop(Icall_ind | Itailcall_ind) -> [| i.arg.(0) |] + | Lop(Icall_imm _ | Itailcall_imm _ | Iextcall _) -> [||] + | Lreturn -> [||] + | _ -> i.arg in + List.iter (fun x -> ignore (longest_path critical_outputs x)) ready_queue; + self#reschedule ready_queue 0 (schedule i) + end in + + if f.fun_fast then begin + let new_body = schedule f.fun_body in + clear_code_dag(); + { fun_name = f.fun_name; + fun_body = new_body; + fun_fast = f.fun_fast } + end else + f + +end diff --git a/asmcomp/schedgen.mli b/asmcomp/schedgen.mli new file mode 100644 index 0000000..8dd34bd --- /dev/null +++ b/asmcomp/schedgen.mli @@ -0,0 +1,46 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: schedgen.mli,v 1.6 1999-11-17 18:56:36 xleroy Exp $ *) + +(* Instruction scheduling *) + +type code_dag_node = + { instr: Linearize.instruction; + delay: int; + mutable sons: (code_dag_node * int) list; + mutable date: int; + mutable length: int; + mutable ancestors: int; + mutable emitted_ancestors: int } + +class virtual scheduler_generic : object + (* Can be overriden by processor description *) + method virtual oper_issue_cycles : Mach.operation -> int + (* Number of cycles needed to issue the given operation *) + method virtual oper_latency : Mach.operation -> int + (* Number of cycles needed to complete the given operation *) + method reload_retaddr_issue_cycles : int + (* Number of cycles needed to issue a Lreloadretaddr operation *) + method reload_retaddr_latency : int + (* Number of cycles needed to complete a Lreloadretaddr operation *) + method oper_in_basic_block : Mach.operation -> bool + (* Says whether the given operation terminates a basic block *) + method is_store : Mach.operation -> bool + (* Says whether the given operation is a memory store *) + method is_load : Mach.operation -> bool + (* Says whether the given operation is a memory load *) + method is_checkbound : Mach.operation -> bool + (* Says whether the given operation is a checkbound *) + (* Entry point *) + method schedule_fundecl : Linearize.fundecl -> Linearize.fundecl +end diff --git a/asmcomp/scheduling.mli b/asmcomp/scheduling.mli new file mode 100644 index 0000000..f183032 --- /dev/null +++ b/asmcomp/scheduling.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.mli,v 1.3 1999-11-17 18:56:36 xleroy Exp $ *) + +(* Instruction scheduling *) + +val fundecl: Linearize.fundecl -> Linearize.fundecl diff --git a/asmcomp/selectgen.ml b/asmcomp/selectgen.ml new file mode 100644 index 0000000..47fba7f --- /dev/null +++ b/asmcomp/selectgen.ml @@ -0,0 +1,826 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selectgen.ml,v 1.32 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Selection of pseudo-instructions, assignment of pseudo-registers, + sequentialization. *) + +open Misc +open Cmm +open Reg +open Mach + +type environment = (Ident.t, Reg.t array) Tbl.t + +(* Infer the type of the result of an operation *) + +let oper_result_type = function + Capply(ty, _) -> ty + | Cextcall(s, ty, alloc, _) -> ty + | Cload c -> + begin match c with + Word -> typ_addr + | Single | Double | Double_u -> typ_float + | _ -> typ_int + end + | Calloc -> typ_addr + | Cstore c -> typ_void + | Caddi | Csubi | Cmuli | Cdivi | Cmodi | + Cand | Cor | Cxor | Clsl | Clsr | Casr | + Ccmpi _ | Ccmpa _ | Ccmpf _ -> typ_int + | Cadda | Csuba -> typ_addr + | Cnegf | Cabsf | Caddf | Csubf | Cmulf | Cdivf -> typ_float + | Cfloatofint -> typ_float + | Cintoffloat -> typ_int + | Craise _ -> typ_void + | Ccheckbound _ -> typ_void + +(* Infer the size in bytes of the result of a simple expression *) + +let size_expr env exp = + let rec size localenv = function + Cconst_int _ | Cconst_natint _ -> Arch.size_int + | Cconst_symbol _ | Cconst_pointer _ | Cconst_natpointer _ -> + Arch.size_addr + | Cconst_float _ -> Arch.size_float + | Cvar id -> + begin try + Tbl.find id localenv + with Not_found -> + try + let regs = Tbl.find id env in + size_machtype (Array.map (fun r -> r.typ) regs) + with Not_found -> + fatal_error("Selection.size_expr: unbound var " ^ + Ident.unique_name id) + end + | Ctuple el -> + List.fold_right (fun e sz -> size localenv e + sz) el 0 + | Cop(op, args) -> + size_machtype(oper_result_type op) + | Clet(id, arg, body) -> + size (Tbl.add id (size localenv arg) localenv) body + | Csequence(e1, e2) -> + size localenv e2 + | _ -> + fatal_error "Selection.size_expr" + in size Tbl.empty exp + +(* Swap the two arguments of an integer comparison *) + +let swap_intcomp = function + Isigned cmp -> Isigned(swap_comparison cmp) + | Iunsigned cmp -> Iunsigned(swap_comparison cmp) + +(* Naming of registers *) + +let all_regs_anonymous rv = + try + for i = 0 to Array.length rv - 1 do + if String.length rv.(i).name > 0 then raise Exit + done; + true + with Exit -> + false + +let name_regs id rv = + if Array.length rv = 1 then + rv.(0).name <- Ident.name id + else + for i = 0 to Array.length rv - 1 do + rv.(i).name <- Ident.name id ^ "#" ^ string_of_int i + done + +(* "Join" two instruction sequences, making sure they return their results + in the same registers. *) + +let join opt_r1 seq1 opt_r2 seq2 = + match (opt_r1, opt_r2) with + (None, _) -> opt_r2 + | (_, None) -> opt_r1 + | (Some r1, Some r2) -> + let l1 = Array.length r1 in + assert (l1 = Array.length r2); + let r = Array.create l1 Reg.dummy in + for i = 0 to l1-1 do + if String.length r1.(i).name = 0 then begin + r.(i) <- r1.(i); + seq2#insert_move r2.(i) r1.(i) + end else if String.length r2.(i).name = 0 then begin + r.(i) <- r2.(i); + seq1#insert_move r1.(i) r2.(i) + end else begin + r.(i) <- Reg.create r1.(i).typ; + seq1#insert_move r1.(i) r.(i); + seq2#insert_move r2.(i) r.(i) + end + done; + Some r + +(* Same, for N branches *) + +let join_array rs = + let some_res = ref None in + for i = 0 to Array.length rs - 1 do + let (r, s) = rs.(i) in + if r <> None then some_res := r + done; + match !some_res with + None -> None + | Some template -> + let size_res = Array.length template in + let res = Array.create size_res Reg.dummy in + for i = 0 to size_res - 1 do + res.(i) <- Reg.create template.(i).typ + done; + for i = 0 to Array.length rs - 1 do + let (r, s) = rs.(i) in + match r with + None -> () + | Some r -> s#insert_moves r res + done; + Some res + +(* Extract debug info contained in a C-- operation *) +let debuginfo_op = function + | Capply(_, dbg) -> dbg + | Cextcall(_, _, _, dbg) -> dbg + | Craise dbg -> dbg + | Ccheckbound dbg -> dbg + | _ -> Debuginfo.none + +(* Registers for catch constructs *) +let catch_regs = ref [] + +(* Name of function being compiled *) +let current_function_name = ref "" + +(* The default instruction selection class *) + +class virtual selector_generic = object (self) + +(* Says if an expression is "simple". A "simple" expression has no + side-effects and its execution can be delayed until its value + is really needed. In the case of e.g. an [alloc] instruction, + the non-simple arguments are computed in right-to-left order + first, then the block is allocated, then the simple arguments are + evaluated and stored. *) + +method is_simple_expr = function + Cconst_int _ -> true + | Cconst_natint _ -> true + | Cconst_float _ -> true + | Cconst_symbol _ -> true + | Cconst_pointer _ -> true + | Cconst_natpointer _ -> true + | Cvar _ -> true + | Ctuple el -> List.for_all self#is_simple_expr el + | Clet(id, arg, body) -> self#is_simple_expr arg && self#is_simple_expr body + | Csequence(e1, e2) -> self#is_simple_expr e1 && self#is_simple_expr e2 + | Cop(op, args) -> + begin match op with + (* The following may have side effects *) + | Capply _ | Cextcall _ | Calloc | Cstore _ | Craise _ -> false + (* The remaining operations are simple if their args are *) + | _ -> + List.for_all self#is_simple_expr args + end + | _ -> false + +(* Says whether an integer constant is a suitable immediate argument *) + +method virtual is_immediate : int -> bool + +(* Selection of addressing modes *) + +method virtual select_addressing : + Cmm.expression -> Arch.addressing_mode * Cmm.expression + +(* Default instruction selection for stores (of words) *) + +method select_store addr arg = + (Istore(Word, addr), arg) + +(* Default instruction selection for operators *) + +method select_operation op args = + match (op, args) with + (Capply(ty, dbg), Cconst_symbol s :: rem) -> (Icall_imm s, rem) + | (Capply(ty, dbg), _) -> (Icall_ind, args) + | (Cextcall(s, ty, alloc, dbg), _) -> (Iextcall(s, alloc), args) + | (Cload chunk, [arg]) -> + let (addr, eloc) = self#select_addressing arg in + (Iload(chunk, addr), [eloc]) + | (Cstore chunk, [arg1; arg2]) -> + let (addr, eloc) = self#select_addressing arg1 in + if chunk = Word then begin + let (op, newarg2) = self#select_store addr arg2 in + (op, [newarg2; eloc]) + end else begin + (Istore(chunk, addr), [arg2; eloc]) + (* Inversion addr/datum in Istore *) + end + | (Calloc, _) -> (Ialloc 0, args) + | (Caddi, _) -> self#select_arith_comm Iadd args + | (Csubi, _) -> self#select_arith Isub args + | (Cmuli, [arg1; Cconst_int n]) -> + let l = Misc.log2 n in + if n = 1 lsl l + then (Iintop_imm(Ilsl, l), [arg1]) + else self#select_arith_comm Imul args + | (Cmuli, [Cconst_int n; arg1]) -> + let l = Misc.log2 n in + if n = 1 lsl l + then (Iintop_imm(Ilsl, l), [arg1]) + else self#select_arith_comm Imul args + | (Cmuli, _) -> self#select_arith_comm Imul args + | (Cdivi, _) -> self#select_arith Idiv args + | (Cmodi, _) -> self#select_arith_comm Imod args + | (Cand, _) -> self#select_arith_comm Iand args + | (Cor, _) -> self#select_arith_comm Ior args + | (Cxor, _) -> self#select_arith_comm Ixor args + | (Clsl, _) -> self#select_shift Ilsl args + | (Clsr, _) -> self#select_shift Ilsr args + | (Casr, _) -> self#select_shift Iasr args + | (Ccmpi comp, _) -> self#select_arith_comp (Isigned comp) args + | (Cadda, _) -> self#select_arith_comm Iadd args + | (Csuba, _) -> self#select_arith Isub args + | (Ccmpa comp, _) -> self#select_arith_comp (Iunsigned comp) args + | (Cnegf, _) -> (Inegf, args) + | (Cabsf, _) -> (Iabsf, args) + | (Caddf, _) -> (Iaddf, args) + | (Csubf, _) -> (Isubf, args) + | (Cmulf, _) -> (Imulf, args) + | (Cdivf, _) -> (Idivf, args) + | (Cfloatofint, _) -> (Ifloatofint, args) + | (Cintoffloat, _) -> (Iintoffloat, args) + | (Ccheckbound _, _) -> self#select_arith Icheckbound args + | _ -> fatal_error "Selection.select_oper" + +method private select_arith_comm op = function + [arg; Cconst_int n] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | [arg; Cconst_pointer n] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | [Cconst_int n; arg] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | [Cconst_pointer n; arg] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | args -> + (Iintop op, args) + +method private select_arith op = function + [arg; Cconst_int n] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | [arg; Cconst_pointer n] when self#is_immediate n -> + (Iintop_imm(op, n), [arg]) + | args -> + (Iintop op, args) + +method private select_shift op = function + [arg; Cconst_int n] when n >= 0 && n < Arch.size_int * 8 -> + (Iintop_imm(op, n), [arg]) + | args -> + (Iintop op, args) + +method private select_arith_comp cmp = function + [arg; Cconst_int n] when self#is_immediate n -> + (Iintop_imm(Icomp cmp, n), [arg]) + | [arg; Cconst_pointer n] when self#is_immediate n -> + (Iintop_imm(Icomp cmp, n), [arg]) + | [Cconst_int n; arg] when self#is_immediate n -> + (Iintop_imm(Icomp(swap_intcomp cmp), n), [arg]) + | [Cconst_pointer n; arg] when self#is_immediate n -> + (Iintop_imm(Icomp(swap_intcomp cmp), n), [arg]) + | args -> + (Iintop(Icomp cmp), args) + +(* Instruction selection for conditionals *) + +method select_condition = function + Cop(Ccmpi cmp, [arg1; Cconst_int n]) when self#is_immediate n -> + (Iinttest_imm(Isigned cmp, n), arg1) + | Cop(Ccmpi cmp, [Cconst_int n; arg2]) when self#is_immediate n -> + (Iinttest_imm(Isigned(swap_comparison cmp), n), arg2) + | Cop(Ccmpi cmp, [arg1; Cconst_pointer n]) when self#is_immediate n -> + (Iinttest_imm(Isigned cmp, n), arg1) + | Cop(Ccmpi cmp, [Cconst_pointer n; arg2]) when self#is_immediate n -> + (Iinttest_imm(Isigned(swap_comparison cmp), n), arg2) + | Cop(Ccmpi cmp, args) -> + (Iinttest(Isigned cmp), Ctuple args) + | Cop(Ccmpa cmp, [arg1; Cconst_pointer n]) when self#is_immediate n -> + (Iinttest_imm(Iunsigned cmp, n), arg1) + | Cop(Ccmpa cmp, [arg1; Cconst_int n]) when self#is_immediate n -> + (Iinttest_imm(Iunsigned cmp, n), arg1) + | Cop(Ccmpa cmp, [Cconst_pointer n; arg2]) when self#is_immediate n -> + (Iinttest_imm(Iunsigned(swap_comparison cmp), n), arg2) + | Cop(Ccmpa cmp, [Cconst_int n; arg2]) when self#is_immediate n -> + (Iinttest_imm(Iunsigned(swap_comparison cmp), n), arg2) + | Cop(Ccmpa cmp, args) -> + (Iinttest(Iunsigned cmp), Ctuple args) + | Cop(Ccmpf cmp, args) -> + (Ifloattest(cmp, false), Ctuple args) + | Cop(Cand, [arg; Cconst_int 1]) -> + (Ioddtest, arg) + | arg -> + (Itruetest, arg) + +(* Buffering of instruction sequences *) + +val mutable instr_seq = dummy_instr + +method insert_debug desc dbg arg res = + instr_seq <- instr_cons_debug desc arg res dbg instr_seq + +method insert desc arg res = + instr_seq <- instr_cons desc arg res instr_seq + +method extract = + let rec extract res i = + if i == dummy_instr + then res + else extract {i with next = res} i.next in + extract (end_instr()) instr_seq + +(* Insert a sequence of moves from one pseudoreg set to another. *) + +method insert_move src dst = + if src.stamp <> dst.stamp then + self#insert (Iop Imove) [|src|] [|dst|] + +method insert_moves src dst = + for i = 0 to Array.length src - 1 do + self#insert_move src.(i) dst.(i) + done + +(* Insert moves and stack offsets for function arguments and results *) + +method insert_move_args arg loc stacksize = + if stacksize <> 0 then self#insert (Iop(Istackoffset stacksize)) [||] [||]; + self#insert_moves arg loc + +method insert_move_results loc res stacksize = + if stacksize <> 0 then self#insert(Iop(Istackoffset(-stacksize))) [||] [||]; + self#insert_moves loc res + +(* Add an Iop opcode. Can be overriden by processor description + to insert moves before and after the operation, i.e. for two-address + instructions, or instructions using dedicated registers. *) + +method insert_op_debug op dbg rs rd = + self#insert_debug (Iop op) dbg rs rd; + rd + +method insert_op op rs rd = + self#insert (Iop op) rs rd; + rd + +(* Add the instructions for the given expression + at the end of the self sequence *) + +method emit_expr env exp = + match exp with + Cconst_int n -> + let r = Reg.createv typ_int in + Some(self#insert_op (Iconst_int(Nativeint.of_int n)) [||] r) + | Cconst_natint n -> + let r = Reg.createv typ_int in + Some(self#insert_op (Iconst_int n) [||] r) + | Cconst_float n -> + let r = Reg.createv typ_float in + Some(self#insert_op (Iconst_float n) [||] r) + | Cconst_symbol n -> + let r = Reg.createv typ_addr in + Some(self#insert_op (Iconst_symbol n) [||] r) + | Cconst_pointer n -> + let r = Reg.createv typ_addr in + Some(self#insert_op (Iconst_int(Nativeint.of_int n)) [||] r) + | Cconst_natpointer n -> + let r = Reg.createv typ_addr in + Some(self#insert_op (Iconst_int n) [||] r) + | Cvar v -> + begin try + Some(Tbl.find v env) + with Not_found -> + fatal_error("Selection.emit_expr: unbound var " ^ Ident.unique_name v) + end + | Clet(v, e1, e2) -> + begin match self#emit_expr env e1 with + None -> None + | Some r1 -> self#emit_expr (self#bind_let env v r1) e2 + end + | Cassign(v, e1) -> + let rv = + try + Tbl.find v env + with Not_found -> + fatal_error ("Selection.emit_expr: unbound var " ^ Ident.name v) in + begin match self#emit_expr env e1 with + None -> None + | Some r1 -> self#insert_moves r1 rv; Some [||] + end + | Ctuple [] -> + Some [||] + | Ctuple exp_list -> + begin match self#emit_parts_list env exp_list with + None -> None + | Some(simple_list, ext_env) -> + Some(self#emit_tuple ext_env simple_list) + end + | Cop(Craise dbg, [arg]) -> + begin match self#emit_expr env arg with + None -> None + | Some r1 -> + let rd = [|Proc.loc_exn_bucket|] in + self#insert (Iop Imove) r1 rd; + self#insert_debug Iraise dbg rd [||]; + None + end + | Cop(Ccmpf comp, args) -> + self#emit_expr env (Cifthenelse(exp, Cconst_int 1, Cconst_int 0)) + | Cop(op, args) -> + begin match self#emit_parts_list env args with + None -> None + | Some(simple_args, env) -> + let ty = oper_result_type op in + let (new_op, new_args) = self#select_operation op simple_args in + let dbg = debuginfo_op op in + match new_op with + Icall_ind -> + Proc.contains_calls := true; + let r1 = self#emit_tuple env new_args in + let rarg = Array.sub r1 1 (Array.length r1 - 1) in + let rd = Reg.createv ty in + let (loc_arg, stack_ofs) = Proc.loc_arguments rarg in + let loc_res = Proc.loc_results rd in + self#insert_move_args rarg loc_arg stack_ofs; + self#insert_debug (Iop Icall_ind) dbg + (Array.append [|r1.(0)|] loc_arg) loc_res; + self#insert_move_results loc_res rd stack_ofs; + Some rd + | Icall_imm lbl -> + Proc.contains_calls := true; + let r1 = self#emit_tuple env new_args in + let rd = Reg.createv ty in + let (loc_arg, stack_ofs) = Proc.loc_arguments r1 in + let loc_res = Proc.loc_results rd in + self#insert_move_args r1 loc_arg stack_ofs; + self#insert_debug (Iop(Icall_imm lbl)) dbg loc_arg loc_res; + self#insert_move_results loc_res rd stack_ofs; + Some rd + | Iextcall(lbl, alloc) -> + Proc.contains_calls := true; + let (loc_arg, stack_ofs) = + self#emit_extcall_args env new_args in + let rd = Reg.createv ty in + let loc_res = Proc.loc_external_results rd in + self#insert_debug (Iop(Iextcall(lbl, alloc))) dbg + loc_arg loc_res; + self#insert_move_results loc_res rd stack_ofs; + Some rd + | Ialloc _ -> + Proc.contains_calls := true; + let rd = Reg.createv typ_addr in + let size = size_expr env (Ctuple new_args) in + self#insert (Iop(Ialloc size)) [||] rd; + self#emit_stores env new_args rd; + Some rd + | op -> + let r1 = self#emit_tuple env new_args in + let rd = Reg.createv ty in + Some (self#insert_op_debug op dbg r1 rd) + end + | Csequence(e1, e2) -> + begin match self#emit_expr env e1 with + None -> None + | Some r1 -> self#emit_expr env e2 + end + | Cifthenelse(econd, eif, eelse) -> + let (cond, earg) = self#select_condition econd in + begin match self#emit_expr env earg with + None -> None + | Some rarg -> + let (rif, sif) = self#emit_sequence env eif in + let (relse, selse) = self#emit_sequence env eelse in + let r = join rif sif relse selse in + self#insert (Iifthenelse(cond, sif#extract, selse#extract)) + rarg [||]; + r + end + | Cswitch(esel, index, ecases) -> + begin match self#emit_expr env esel with + None -> None + | Some rsel -> + let rscases = Array.map (self#emit_sequence env) ecases in + let r = join_array rscases in + self#insert (Iswitch(index, + Array.map (fun (r, s) -> s#extract) rscases)) + rsel [||]; + r + end + | Cloop(ebody) -> + let (rarg, sbody) = self#emit_sequence env ebody in + self#insert (Iloop(sbody#extract)) [||] [||]; + Some [||] + | Ccatch(nfail, ids, e1, e2) -> + let rs = + List.map + (fun id -> + let r = Reg.createv typ_addr in name_regs id r; r) + ids in + catch_regs := (nfail, Array.concat rs) :: !catch_regs ; + let (r1, s1) = self#emit_sequence env e1 in + catch_regs := List.tl !catch_regs ; + let new_env = + List.fold_left + (fun env (id,r) -> Tbl.add id r env) + env (List.combine ids rs) in + let (r2, s2) = self#emit_sequence new_env e2 in + let r = join r1 s1 r2 s2 in + self#insert (Icatch(nfail, s1#extract, s2#extract)) [||] [||]; + r + | Cexit (nfail,args) -> + begin match self#emit_parts_list env args with + None -> None + | Some (simple_list, ext_env) -> + let src = self#emit_tuple ext_env simple_list in + let dest = + try List.assoc nfail !catch_regs + with Not_found -> + Misc.fatal_error + ("Selectgen.emit_expr, on exit("^string_of_int nfail^")") in + self#insert_moves src dest ; + self#insert (Iexit nfail) [||] [||]; + None + end + | Ctrywith(e1, v, e2) -> + Proc.contains_calls := true; + let (r1, s1) = self#emit_sequence env e1 in + let rv = Reg.createv typ_addr in + let (r2, s2) = self#emit_sequence (Tbl.add v rv env) e2 in + let r = join r1 s1 r2 s2 in + self#insert + (Itrywith(s1#extract, + instr_cons (Iop Imove) [|Proc.loc_exn_bucket|] rv + (s2#extract))) + [||] [||]; + r + +method private emit_sequence env exp = + let s = {< instr_seq = dummy_instr >} in + let r = s#emit_expr env exp in + (r, s) + +method private bind_let env v r1 = + if all_regs_anonymous r1 then begin + name_regs v r1; + Tbl.add v r1 env + end else begin + let rv = Array.create (Array.length r1) Reg.dummy in + for i = 0 to Array.length r1 - 1 do + rv.(i) <- Reg.create r1.(i).typ + done; + name_regs v rv; + self#insert_moves r1 rv; + Tbl.add v rv env + end + +method private emit_parts env exp = + if self#is_simple_expr exp then + Some (exp, env) + else begin + match self#emit_expr env exp with + None -> None + | Some r -> + match Array.length r with + 0 -> + Some (Ctuple [], env) + | 1 -> + (* The normal case *) + let id = Ident.create "bind" in + let r0 = r.(0) in + if String.length r0.name = 0 then + (* r0 is an anonymous, unshared register; use it directly *) + Some (Cvar id, Tbl.add id r env) + else begin + (* Introduce a fresh temp reg to hold the result *) + let v0 = Reg.create r0.typ in + self#insert_move r0 v0; + Some (Cvar id, Tbl.add id [|v0|] env) + end + | _ -> + (* Must not happen, we no longer support nested tuples *) + assert false + end + +method private emit_parts_list env exp_list = + match exp_list with + [] -> Some ([], env) + | exp :: rem -> + (* This ensures right-to-left evaluation, consistent with the + bytecode compiler *) + match self#emit_parts_list env rem with + None -> None + | Some(new_rem, new_env) -> + match self#emit_parts new_env exp with + None -> None + | Some(new_exp, fin_env) -> Some(new_exp :: new_rem, fin_env) + +method private emit_tuple env exp_list = + let rec emit_list = function + [] -> [] + | exp :: rem -> + (* Again, force right-to-left evaluation *) + let loc_rem = emit_list rem in + match self#emit_expr env exp with + None -> assert false (* should have been caught in emit_parts *) + | Some loc_exp -> loc_exp :: loc_rem in + Array.concat(emit_list exp_list) + +method emit_extcall_args env args = + let r1 = self#emit_tuple env args in + let (loc_arg, stack_ofs as arg_stack) = Proc.loc_external_arguments r1 in + self#insert_move_args r1 loc_arg stack_ofs; + arg_stack + +method emit_stores env data regs_addr = + let a = + ref (Arch.offset_addressing Arch.identity_addressing (-Arch.size_int)) in + List.iter + (fun e -> + let (op, arg) = self#select_store !a e in + match self#emit_expr env arg with + None -> assert false + | Some regs -> + match op with + Istore(_, _) -> + for i = 0 to Array.length regs - 1 do + let r = regs.(i) in + let kind = if r.typ = Float then Double_u else Word in + self#insert (Iop(Istore(kind, !a))) + (Array.append [|r|] regs_addr) [||]; + a := Arch.offset_addressing !a (size_component r.typ) + done + | _ -> + self#insert (Iop op) (Array.append regs regs_addr) [||]; + a := Arch.offset_addressing !a (size_expr env e)) + data + +(* Same, but in tail position *) + +method private emit_return env exp = + match self#emit_expr env exp with + None -> () + | Some r -> + let loc = Proc.loc_results r in + self#insert_moves r loc; + self#insert Ireturn loc [||] + +method emit_tail env exp = + match exp with + Clet(v, e1, e2) -> + begin match self#emit_expr env e1 with + None -> () + | Some r1 -> self#emit_tail (self#bind_let env v r1) e2 + end + | Cop(Capply(ty, dbg) as op, args) -> + begin match self#emit_parts_list env args with + None -> () + | Some(simple_args, env) -> + let (new_op, new_args) = self#select_operation op simple_args in + match new_op with + Icall_ind -> + let r1 = self#emit_tuple env new_args in + let rarg = Array.sub r1 1 (Array.length r1 - 1) in + let (loc_arg, stack_ofs) = Proc.loc_arguments rarg in + if stack_ofs = 0 then begin + self#insert_moves rarg loc_arg; + self#insert (Iop Itailcall_ind) + (Array.append [|r1.(0)|] loc_arg) [||] + end else begin + Proc.contains_calls := true; + let rd = Reg.createv ty in + let loc_res = Proc.loc_results rd in + self#insert_move_args rarg loc_arg stack_ofs; + self#insert_debug (Iop Icall_ind) dbg + (Array.append [|r1.(0)|] loc_arg) loc_res; + self#insert(Iop(Istackoffset(-stack_ofs))) [||] [||]; + self#insert Ireturn loc_res [||] + end + | Icall_imm lbl -> + let r1 = self#emit_tuple env new_args in + let (loc_arg, stack_ofs) = Proc.loc_arguments r1 in + if stack_ofs = 0 then begin + self#insert_moves r1 loc_arg; + self#insert (Iop(Itailcall_imm lbl)) loc_arg [||] + end else if lbl = !current_function_name then begin + let loc_arg' = Proc.loc_parameters r1 in + self#insert_moves r1 loc_arg'; + self#insert (Iop(Itailcall_imm lbl)) loc_arg' [||] + end else begin + Proc.contains_calls := true; + let rd = Reg.createv ty in + let loc_res = Proc.loc_results rd in + self#insert_move_args r1 loc_arg stack_ofs; + self#insert_debug (Iop(Icall_imm lbl)) dbg loc_arg loc_res; + self#insert(Iop(Istackoffset(-stack_ofs))) [||] [||]; + self#insert Ireturn loc_res [||] + end + | _ -> fatal_error "Selection.emit_tail" + end + | Csequence(e1, e2) -> + begin match self#emit_expr env e1 with + None -> () + | Some r1 -> self#emit_tail env e2 + end + | Cifthenelse(econd, eif, eelse) -> + let (cond, earg) = self#select_condition econd in + begin match self#emit_expr env earg with + None -> () + | Some rarg -> + self#insert (Iifthenelse(cond, self#emit_tail_sequence env eif, + self#emit_tail_sequence env eelse)) + rarg [||] + end + | Cswitch(esel, index, ecases) -> + begin match self#emit_expr env esel with + None -> () + | Some rsel -> + self#insert + (Iswitch(index, Array.map (self#emit_tail_sequence env) ecases)) + rsel [||] + end + | Ccatch(nfail, ids, e1, e2) -> + let rs = + List.map + (fun id -> + let r = Reg.createv typ_addr in + name_regs id r ; + r) + ids in + catch_regs := (nfail, Array.concat rs) :: !catch_regs ; + let s1 = self#emit_tail_sequence env e1 in + catch_regs := List.tl !catch_regs ; + let new_env = + List.fold_left + (fun env (id,r) -> Tbl.add id r env) + env (List.combine ids rs) in + let s2 = self#emit_tail_sequence new_env e2 in + self#insert (Icatch(nfail, s1, s2)) [||] [||] + | Ctrywith(e1, v, e2) -> + Proc.contains_calls := true; + let (opt_r1, s1) = self#emit_sequence env e1 in + let rv = Reg.createv typ_addr in + let s2 = self#emit_tail_sequence (Tbl.add v rv env) e2 in + self#insert + (Itrywith(s1#extract, + instr_cons (Iop Imove) [|Proc.loc_exn_bucket|] rv s2)) + [||] [||]; + begin match opt_r1 with + None -> () + | Some r1 -> + let loc = Proc.loc_results r1 in + self#insert_moves r1 loc; + self#insert Ireturn loc [||] + end + | _ -> + self#emit_return env exp + +method private emit_tail_sequence env exp = + let s = {< instr_seq = dummy_instr >} in + s#emit_tail env exp; + s#extract + +(* Sequentialization of a function definition *) + +method emit_fundecl f = + Proc.contains_calls := false; + current_function_name := f.Cmm.fun_name; + let rargs = + List.map + (fun (id, ty) -> let r = Reg.createv ty in name_regs id r; r) + f.Cmm.fun_args in + let rarg = Array.concat rargs in + let loc_arg = Proc.loc_parameters rarg in + let env = + List.fold_right2 + (fun (id, ty) r env -> Tbl.add id r env) + f.Cmm.fun_args rargs Tbl.empty in + self#insert_moves loc_arg rarg; + self#emit_tail env f.Cmm.fun_body; + { fun_name = f.Cmm.fun_name; + fun_args = loc_arg; + fun_body = self#extract; + fun_fast = f.Cmm.fun_fast } + +end diff --git a/asmcomp/selectgen.mli b/asmcomp/selectgen.mli new file mode 100644 index 0000000..c5b2723 --- /dev/null +++ b/asmcomp/selectgen.mli @@ -0,0 +1,75 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selectgen.mli,v 1.8 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Selection of pseudo-instructions, assignment of pseudo-registers, + sequentialization. *) + +type environment = (Ident.t, Reg.t array) Tbl.t + +val size_expr : environment -> Cmm.expression -> int + +class virtual selector_generic : object + (* The following methods must or can be overriden by the processor + description *) + method virtual is_immediate : int -> bool + (* Must be defined to indicate whether a constant is a suitable + immediate operand to arithmetic instructions *) + method virtual select_addressing : + Cmm.expression -> Arch.addressing_mode * Cmm.expression + (* Must be defined to select addressing modes *) + method is_simple_expr: Cmm.expression -> bool + (* Can be overriden to reflect special extcalls known to be pure *) + method select_operation : + Cmm.operation -> + Cmm.expression list -> Mach.operation * Cmm.expression list + (* Can be overriden to deal with special arithmetic instructions *) + method select_condition : Cmm.expression -> Mach.test * Cmm.expression + (* Can be overriden to deal with special test instructions *) + method select_store : + Arch.addressing_mode -> Cmm.expression -> Mach.operation * Cmm.expression + (* Can be overriden to deal with special store constant instructions *) + method insert_op : + Mach.operation -> Reg.t array -> Reg.t array -> Reg.t array + (* Can be overriden to deal with 2-address instructions + or instructions with hardwired input/output registers *) + method insert_op_debug : + Mach.operation -> Debuginfo.t -> Reg.t array -> Reg.t array -> Reg.t array + (* Can be overriden to deal with 2-address instructions + or instructions with hardwired input/output registers *) + method emit_extcall_args : + environment -> Cmm.expression list -> Reg.t array * int + (* Can be overriden to deal with stack-based calling conventions *) + method emit_stores : + environment -> Cmm.expression list -> Reg.t array -> unit + (* Fill a freshly allocated block. Can be overriden for architectures + that do not provide Arch.offset_addressing. *) + + (* The following method is the entry point and should not be overriden *) + method emit_fundecl : Cmm.fundecl -> Mach.fundecl + + (* The following methods should not be overriden. They cannot be + declared "private" in the current implementation because they + are not always applied to "self", but ideally they should be private. *) + method extract : Mach.instruction + method insert : Mach.instruction_desc -> Reg.t array -> Reg.t array -> unit + method insert_debug : Mach.instruction_desc -> Debuginfo.t -> + Reg.t array -> Reg.t array -> unit + method insert_move : Reg.t -> Reg.t -> unit + method insert_move_args : Reg.t array -> Reg.t array -> int -> unit + method insert_move_results : Reg.t array -> Reg.t array -> int -> unit + method insert_moves : Reg.t array -> Reg.t array -> unit + method emit_expr : + (Ident.t, Reg.t array) Tbl.t -> Cmm.expression -> Reg.t array option + method emit_tail : (Ident.t, Reg.t array) Tbl.t -> Cmm.expression -> unit +end diff --git a/asmcomp/selection.mli b/asmcomp/selection.mli new file mode 100644 index 0000000..229b92e --- /dev/null +++ b/asmcomp/selection.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.mli,v 1.6 1999-11-17 18:56:37 xleroy Exp $ *) + +(* Selection of pseudo-instructions, assignment of pseudo-registers, + sequentialization. *) + +val fundecl: Cmm.fundecl -> Mach.fundecl diff --git a/asmcomp/sparc/arch.ml b/asmcomp/sparc/arch.ml new file mode 100644 index 0000000..b257a55 --- /dev/null +++ b/asmcomp/sparc/arch.ml @@ -0,0 +1,75 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arch.ml,v 1.8 2002-11-29 15:03:08 xleroy Exp $ *) + +(* Specific operations for the Sparc processor *) + +open Misc +open Format + +(* SPARC V8 adds multiply and divide. + SPARC V9 adds double precision float operations, conditional + move, and more instructions that are only useful in 64 bit mode. + Sun calls 32 bit V9 "V8+". *) +type arch_version = SPARC_V7 | SPARC_V8 | SPARC_V9 + +let arch_version = ref SPARC_V7 + +let command_line_options = + [ "-march=v8", Arg.Unit (fun () -> arch_version := SPARC_V8), + " Generate code for SPARC V8 processors"; + "-march=v9", Arg.Unit (fun () -> arch_version := SPARC_V9), + " Generate code for SPARC V9 processors" ] + +type specific_operation = unit (* None worth mentioning *) + +(* Addressing modes *) + +type addressing_mode = + Ibased of string * int (* symbol + displ *) + | Iindexed of int (* reg + displ *) + +(* Sizes, endianness *) + +let big_endian = true + +let size_addr = 4 +let size_int = 4 +let size_float = 8 + +(* Operations on addressing modes *) + +let identity_addressing = Iindexed 0 + +let offset_addressing addr delta = + match addr with + Ibased(s, n) -> Ibased(s, n + delta) + | Iindexed n -> Iindexed(n + delta) + +let num_args_addressing = function + Ibased(s, n) -> 0 + | Iindexed n -> 1 + +(* Printing operations and addressing modes *) + +let print_addressing printreg addr ppf arg = + match addr with + | Ibased(s, n) -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "\"%s\"%s" s idx + | Iindexed n -> + let idx = if n <> 0 then Printf.sprintf " + %i" n else "" in + fprintf ppf "%a%s" printreg arg.(0) idx + +let print_specific_operation printreg op ppf arg = + Misc.fatal_error "Arch_sparc.print_specific_operation" diff --git a/asmcomp/sparc/emit.mlp b/asmcomp/sparc/emit.mlp new file mode 100644 index 0000000..776123b --- /dev/null +++ b/asmcomp/sparc/emit.mlp @@ -0,0 +1,775 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emit.mlp,v 1.24 2006-04-16 23:28:15 doligez Exp $ *) + +(* Emission of Sparc assembly code *) + +open Location +open Misc +open Cmm +open Arch +open Proc +open Reg +open Mach +open Linearize +open Emitaux + +(* Solaris vs. the other ports *) + +let solaris = Config.system = "solaris" + +(* Tradeoff between code size and code speed *) + +let fastcode_flag = ref true + +(* Layout of the stack *) +(* Always keep the stack 8-aligned. + Always leave 96 bytes at the bottom of the stack *) + +let stack_offset = ref 0 + +let frame_size () = + let size = + !stack_offset + + 4 * num_stack_slots.(0) + 8 * num_stack_slots.(1) + + (if !contains_calls then 4 else 0) in + Misc.align size 8 + +let slot_offset loc cl = + match loc with + Incoming n -> frame_size() + n + 96 + | Local n -> + if cl = 0 + then !stack_offset + num_stack_slots.(1) * 8 + n * 4 + 96 + else !stack_offset + n * 8 + 96 + | Outgoing n -> n + 96 + +(* Return the other register in a register pair *) + +let next_in_pair = function + {loc = Reg r; typ = (Int | Addr)} -> phys_reg (r + 1) + | {loc = Reg r; typ = Float} -> phys_reg (r + 16) + | _ -> fatal_error "Emit.next_in_pair" + +(* Symbols are prefixed with _ under SunOS *) + +let symbol_prefix = + if Config.system = "sunos" then "_" else "" + +let emit_symbol s = + if String.length s >= 1 & s.[0] = '.' + then emit_string s + else begin emit_string symbol_prefix; Emitaux.emit_symbol '$' s end + +let emit_size lbl = + if Config.system = "solaris" then + ` .size {emit_symbol lbl},.-{emit_symbol lbl}\n` + +let rodata () = + if Config.system = "solaris" (* || Config.system = "linux" *) + (* || Config.system = "gnu" *) then + ` .section \".rodata\"\n` + else + ` .data\n` + +(* Check if an integer or native integer is an immediate operand *) + +let is_immediate n = + n <= 4095 && n >= -4096 + +let is_native_immediate n = + n <= Nativeint.of_int 4095 && n >= Nativeint.of_int (-4096) + +(* Output a label *) + +let label_prefix = + if Config.system = "sunos" then "L" else ".L" + +let emit_label lbl = + emit_string label_prefix; emit_int lbl + +(* Output a pseudo-register *) + +let emit_reg r = + match r.loc with + Reg r -> emit_string (register_name r) + | _ -> fatal_error "Emit.emit_reg" + +(* Output a stack reference *) + +let emit_stack r = + match r.loc with + Stack s -> + let ofs = slot_offset s (register_class r) in `[%sp + {emit_int ofs}]` + | _ -> fatal_error "Emit.emit_stack" + +(* Output a load *) + +let emit_load instr addr arg dst = + match addr with + Ibased(s, 0) -> + ` sethi %hi({emit_symbol s}), %g1\n`; + ` {emit_string instr} [%g1 + %lo({emit_symbol s})], {emit_reg dst}\n` + | Ibased(s, ofs) -> + ` sethi %hi({emit_symbol s} + {emit_int ofs}), %g1\n`; + ` {emit_string instr} [%g1 + %lo({emit_symbol s} + {emit_int ofs})], {emit_reg dst}\n` + | Iindexed ofs -> + if is_immediate ofs then + ` {emit_string instr} [{emit_reg arg.(0)} + {emit_int ofs}], {emit_reg dst}\n` + else begin + ` sethi %hi({emit_int ofs}), %g1\n`; + ` or %g1, %lo({emit_int ofs}), %g1\n`; + ` {emit_string instr} [{emit_reg arg.(0)} + %g1], {emit_reg dst}\n` + end + +(* Output a store *) + +let emit_store instr addr arg src = + match addr with + Ibased(s, 0) -> + ` sethi %hi({emit_symbol s}), %g1\n`; + ` {emit_string instr} {emit_reg src}, [%g1 + %lo({emit_symbol s})]\n` + | Ibased(s, ofs) -> + ` sethi %hi({emit_symbol s} + {emit_int ofs}), %g1\n`; + ` {emit_string instr} {emit_reg src}, [%g1 + %lo({emit_symbol s} + {emit_int ofs})]\n` + | Iindexed ofs -> + if is_immediate ofs then + ` {emit_string instr} {emit_reg src}, [{emit_reg arg.(1)} + {emit_int ofs}]\n` + else begin + ` sethi %hi({emit_int ofs}), %g1\n`; + ` or %g1, %lo({emit_int ofs}), %g1\n`; + ` {emit_string instr} {emit_reg src}, [{emit_reg arg.(1)} + %g1]\n` + end + +(* Record live pointers at call points *) + +type frame_descr = + { fd_lbl: int; (* Return address *) + fd_frame_size: int; (* Size of stack frame *) + fd_live_offset: int list } (* Offsets/regs of live addresses *) + +let frame_descriptors = ref([] : frame_descr list) + +let record_frame live = + let lbl = new_label() in + let live_offset = ref [] in + Reg.Set.iter + (function + {typ = Addr; loc = Reg r} -> + live_offset := ((r lsl 1) + 1) :: !live_offset + | {typ = Addr; loc = Stack s} as reg -> + live_offset := + slot_offset s (register_class reg) :: !live_offset + | _ -> ()) + live; + frame_descriptors := + { fd_lbl = lbl; + fd_frame_size = frame_size(); + fd_live_offset = !live_offset } :: !frame_descriptors; + `{emit_label lbl}:` + +let emit_frame fd = + ` .word {emit_label fd.fd_lbl}\n`; + ` .half {emit_int fd.fd_frame_size}\n`; + ` .half {emit_int (List.length fd.fd_live_offset)}\n`; + List.iter + (fun n -> + ` .half {emit_int n}\n`) + fd.fd_live_offset; + ` .align 4\n` + +(* Record floating-point constants *) + +let float_constants = ref ([] : (int * string) list) + +let emit_float_constant (lbl, cst) = + rodata (); + ` .align 8\n`; + `{emit_label lbl}: .double 0r{emit_string cst}\n` + +(* Emission of the profiling prelude *) +let emit_profile () = + begin match Config.system with + "solaris" -> + let lbl = new_label() in + ` .section \".bss\"\n`; + `{emit_label lbl}: .skip 4\n`; + ` .text\n`; + ` save %sp,-96,%sp\n`; + ` sethi %hi({emit_label lbl}),%o0\n`; + ` call _mcount\n`; + ` or %o0,%lo({emit_label lbl}),%o0\n`; + ` restore\n` + | _ -> () + end + +(* Names of various instructions *) + +let name_for_int_operation = function + Iadd -> "add" + | Isub -> "sub" + | Iand -> "and" + | Ior -> "or" + | Ixor -> "xor" + | Ilsl -> "sll" + | Ilsr -> "srl" + | Iasr -> "sra" + | Imul -> "smul" + | _ -> Misc.fatal_error "Emit.name_for_int_operation" + +let name_for_float_operation = function + Inegf -> if !arch_version = SPARC_V9 then "fnegd" else "fnegs" + | Iabsf -> if !arch_version = SPARC_V9 then "fabsd" else "fabss" + | Iaddf -> "faddd" + | Isubf -> "fsubd" + | Imulf -> "fmuld" + | Idivf -> "fdivd" + | _ -> Misc.fatal_error "Emit.name_for_float_operation" + +let name_for_int_movcc = function + Isigned Ceq -> "e" | Isigned Cne -> "ne" + | Isigned Cle -> "le" | Isigned Cgt -> "g" + | Isigned Clt -> "l" | Isigned Cge -> "ge" + | Iunsigned Ceq -> "e" | Iunsigned Cne -> "ne" + | Iunsigned Cle -> "leu" | Iunsigned Cgt -> "gu" + | Iunsigned Clt -> "lu" | Iunsigned Cge -> "geu" + +let name_for_int_comparison = function + Isigned Ceq -> "be" | Isigned Cne -> "bne" + | Isigned Cle -> "ble" | Isigned Cgt -> "bg" + | Isigned Clt -> "bl" | Isigned Cge -> "bge" + | Iunsigned Ceq -> "be" | Iunsigned Cne -> "bne" + | Iunsigned Cle -> "bleu" | Iunsigned Cgt -> "bgu" + | Iunsigned Clt -> "blu" | Iunsigned Cge -> "bgeu" + +let name_for_float_comparison cmp neg = + match cmp with + Ceq -> if neg then "fbne" else "fbe" + | Cne -> if neg then "fbe" else "fbne" + | Cle -> if neg then "fbug" else "fble" + | Cgt -> if neg then "fbule" else "fbg" + | Clt -> if neg then "fbuge" else "fbl" + | Cge -> if neg then "fbul" else "fbge" + +(* Output the assembly code for an instruction *) + +let function_name = ref "" +let tailrec_entry_point = ref 0 +let range_check_trap = ref 0 + +let rec emit_instr i dslot = + match i.desc with + Lend -> () + | Lop(Imove | Ispill | Ireload) -> + let src = i.arg.(0) and dst = i.res.(0) in + begin match (src, dst) with + {loc = Reg rs; typ = (Int | Addr)}, {loc = Reg rd} -> + ` mov {emit_reg src}, {emit_reg dst}\n` + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = Float} -> + if !arch_version = SPARC_V9 then + ` fmovd {emit_reg src}, {emit_reg dst}\n` + else begin + ` fmovs {emit_reg src}, {emit_reg dst}\n`; + ` fmovs {emit_reg(next_in_pair src)}, {emit_reg(next_in_pair dst)}\n` + end + | {loc = Reg rs; typ = Float}, {loc = Reg rd; typ = (Int | Addr)} -> + (* This happens when calling C functions and passing a float arg + in %o0...%o5 *) + ` sub %sp, 8, %sp\n`; + ` std {emit_reg src}, [%sp + 96]\n`; + ` ld [%sp + 96], {emit_reg dst}\n`; + ` ld [%sp + 100], {emit_reg(next_in_pair dst)}\n`; + ` add %sp, 8, %sp\n` + | {loc = Reg rs; typ = (Int | Addr)}, {loc = Stack sd} -> + ` st {emit_reg src}, {emit_stack dst}\n` + | {loc = Reg rs; typ = Float}, {loc = Stack sd} -> + ` std {emit_reg src}, {emit_stack dst}\n` + | {loc = Stack ss; typ = (Int | Addr)}, {loc = Reg rd} -> + ` ld {emit_stack src}, {emit_reg dst}\n` + | {loc = Stack ss; typ = Float}, {loc = Reg rd} -> + ` ldd {emit_stack src}, {emit_reg dst}\n` + | (_, _) -> + fatal_error "Emit: Imove" + end + | Lop(Iconst_int n) -> + if is_native_immediate n then + ` mov {emit_nativeint n}, {emit_reg i.res.(0)}\n` + else begin + ` sethi %hi({emit_nativeint n}), %g1\n`; + ` or %g1, %lo({emit_nativeint n}), {emit_reg i.res.(0)}\n` + end + | Lop(Iconst_float s) -> + (* On UltraSPARC, the fzero instruction could be used to set a + floating point register pair to zero. *) + let lbl = new_label() in + float_constants := (lbl, s) :: !float_constants; + ` sethi %hi({emit_label lbl}), %g1\n`; + ` ldd [%g1 + %lo({emit_label lbl})], {emit_reg i.res.(0)}\n` + | Lop(Iconst_symbol s) -> + ` sethi %hi({emit_symbol s}), %g1\n`; + ` or %g1, %lo({emit_symbol s}), {emit_reg i.res.(0)}\n` + | Lop(Icall_ind) -> + `{record_frame i.live} call {emit_reg i.arg.(0)}\n`; + fill_delay_slot dslot + | Lop(Icall_imm s) -> + `{record_frame i.live} call {emit_symbol s}\n`; + fill_delay_slot dslot + | Lop(Itailcall_ind) -> + let n = frame_size() in + if !contains_calls then + ` ld [%sp + {emit_int(n - 4 + 96)}], %o7\n`; + ` jmp {emit_reg i.arg.(0)}\n`; + ` add %sp, {emit_int n}, %sp\n` (* in delay slot *) + | Lop(Itailcall_imm s) -> + let n = frame_size() in + if s = !function_name then begin + ` b {emit_label !tailrec_entry_point}\n`; + fill_delay_slot dslot + end else begin + if !contains_calls then + ` ld [%sp + {emit_int(n - 4 + 96)}], %o7\n`; + ` sethi %hi({emit_symbol s}), %g1\n`; + ` jmp %g1 + %lo({emit_symbol s})\n`; + ` add %sp, {emit_int n}, %sp\n` (* in delay slot *) + end + | Lop(Iextcall(s, alloc)) -> + if alloc then begin + ` sethi %hi({emit_symbol s}), %g2\n`; + `{record_frame i.live} call {emit_symbol "caml_c_call"}\n`; + ` or %g2, %lo({emit_symbol s}), %g2\n` (* in delay slot *) + end else begin + ` call {emit_symbol s}\n`; + fill_delay_slot dslot + end + | Lop(Istackoffset n) -> + ` add %sp, {emit_int (-n)}, %sp\n`; + stack_offset := !stack_offset + n + | Lop(Iload(chunk, addr)) -> + let dest = i.res.(0) in + begin match chunk with + Double_u -> + emit_load "ld" addr i.arg dest; + emit_load "ld" (offset_addressing addr 4) i.arg (next_in_pair dest) + | Single -> + emit_load "ld" addr i.arg dest; + ` fstod {emit_reg dest}, {emit_reg dest}\n` + | _ -> + let loadinstr = + match chunk with + Byte_unsigned -> "ldub" + | Byte_signed -> "ldsb" + | Sixteen_unsigned -> "lduh" + | Sixteen_signed -> "ldsh" + | Double -> "ldd" + | _ -> "ld" in + emit_load loadinstr addr i.arg dest + end + | Lop(Istore(chunk, addr)) -> + let src = i.arg.(0) in + begin match chunk with + Double_u -> + emit_store "st" addr i.arg src; + emit_store "st" (offset_addressing addr 4) i.arg (next_in_pair src) + | Single -> + ` fdtos {emit_reg src}, %f30\n`; + emit_store "st" addr i.arg (phys_reg 115) (* %f30 *) + | _ -> + let storeinstr = + match chunk with + | Byte_unsigned | Byte_signed -> "stb" + | Sixteen_unsigned | Sixteen_signed -> "sth" + | Double -> "std" + | _ -> "st" in + emit_store storeinstr addr i.arg src + end + | Lop(Ialloc n) -> + if !fastcode_flag then begin + let lbl_cont = new_label() in + if solaris then begin + ` sub %l6, {emit_int n}, %l6\n`; + ` cmp %l6, %l7\n` + end else begin + ` ld [%l7], %g1\n`; + ` sub %l6, {emit_int n}, %l6\n`; + ` cmp %l6, %g1\n` + end; + ` bgeu {emit_label lbl_cont}\n`; + ` add %l6, 4, {emit_reg i.res.(0)}\n`; (* in delay slot *) + `{record_frame i.live} call {emit_symbol "caml_call_gc"}\n`; + ` mov {emit_int n}, %g2\n`; (* in delay slot *) + ` add %l6, 4, {emit_reg i.res.(0)}\n`; + `{emit_label lbl_cont}:\n` + end else begin + `{record_frame i.live} call {emit_symbol "caml_allocN"}\n`; + ` mov {emit_int n}, %g2\n`; (* in delay slot *) + ` add %l6, 4, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop(Icomp cmp)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + if !arch_version = SPARC_V9 then begin + let comp = name_for_int_movcc cmp in + ` mov 0, {emit_reg i.res.(0)}\n`; + ` mov{emit_string comp} %icc, 1, {emit_reg i.res.(0)}\n` + end + else begin + let comp = name_for_int_comparison cmp + and lbl = new_label() in + ` {emit_string comp},a {emit_label lbl}\n`; + ` mov 1, {emit_reg i.res.(0)}\n`; + ` mov 0, {emit_reg i.res.(0)}\n`; + `{emit_label lbl}:\n` + end + | Lop(Iintop Icheckbound) -> + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + if solaris then + ` tleu 5\n` (* 5 = ST_RANGE_CHECK *) + else begin + if !range_check_trap = 0 then range_check_trap := new_label(); + ` bleu {emit_label !range_check_trap}\n`; + ` nop\n` (* delay slot *) + end + | Lop(Iintop Idiv) -> + ` sra {emit_reg i.arg.(0)}, 31, %g1\n`; + ` wr %g1, %y\n`; + ` sdiv {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop op) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Ilsl, 1)) -> + (* UltraSPARC has two add units but only one shifter. *) + ` add {emit_reg i.arg.(0)}, {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n` + | Lop(Iintop_imm(Idiv, n)) -> + let l = Misc.log2 n in + if n = 1 lsl l then begin + let lbl = new_label() in + ` cmp {emit_reg i.arg.(0)}, 0\n`; + ` bge {emit_label lbl}\n`; + ` mov {emit_reg i.arg.(0)}, %g1\n`; (* in delay slot *) + ` add %g1, {emit_int (n-1)}, %g1\n`; + `{emit_label lbl}:\n`; + ` sra %g1, {emit_int l}, {emit_reg i.res.(0)}\n` + end else begin + ` sra {emit_reg i.arg.(0)}, 31, %g1\n`; + ` wr %g1, %y\n`; + ` sdiv {emit_reg i.arg.(0)}, {emit_int n}, {emit_reg i.res.(0)}\n` + end + | Lop(Iintop_imm(Imod, n)) -> (* n is a power of 2 *) + let lbl = new_label() in + ` tst {emit_reg i.arg.(0)}\n`; + ` bge {emit_label lbl}\n`; + ` andcc {emit_reg i.arg.(0)}, {emit_int (n-1)}, {emit_reg i.res.(0)}\n`; (* in delay slot *) + ` be {emit_label lbl}\n`; + ` nop\n`; + ` sub {emit_reg i.res.(0)}, {emit_int n}, {emit_reg i.res.(0)}\n`; + `{emit_label lbl}:\n` + | Lop(Iintop_imm(Icomp cmp, n)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + if !arch_version = SPARC_V9 then begin + let comp = name_for_int_movcc cmp in + ` mov 0, {emit_reg i.res.(0)}\n`; + ` mov{emit_string comp} %icc, 1, {emit_reg i.res.(0)}\n` + end else begin + let comp = name_for_int_comparison cmp + and lbl = new_label() in + ` {emit_string comp},a {emit_label lbl}\n`; + ` mov 1, {emit_reg i.res.(0)}\n`; + ` mov 0, {emit_reg i.res.(0)}\n`; + `{emit_label lbl}:\n` + end + | Lop(Iintop_imm(Icheckbound, n)) -> + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + if solaris then + ` tleu 5\n` (* 5 = ST_RANGE_CHECK *) + else begin + if !range_check_trap = 0 then range_check_trap := new_label(); + ` bleu {emit_label !range_check_trap}\n`; + ` nop\n` (* delay slot *) + end + | Lop(Iintop_imm(op, n)) -> + let instr = name_for_int_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_int n}, {emit_reg i.res.(0)}\n` + | Lop(Inegf | Iabsf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.res.(0)}\n`; + if !arch_version <> SPARC_V9 then + ` fmovs {emit_reg(next_in_pair i.arg.(0))}, {emit_reg(next_in_pair i.res.(0))}\n` + | Lop(Iaddf | Isubf | Imulf | Idivf as op) -> + let instr = name_for_float_operation op in + ` {emit_string instr} {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}, {emit_reg i.res.(0)}\n` + | Lop(Ifloatofint) -> + ` sub %sp, 8, %sp\n`; + ` st {emit_reg i.arg.(0)}, [%sp + 96]\n`; + ` ld [%sp + 96], %f30\n`; + ` add %sp, 8, %sp\n`; + ` fitod %f30, {emit_reg i.res.(0)}\n` + | Lop(Iintoffloat) -> + ` fdtoi {emit_reg i.arg.(0)}, %f30\n`; + ` sub %sp, 8, %sp\n`; + ` st %f30, [%sp + 96]\n`; + ` ld [%sp + 96], {emit_reg i.res.(0)}\n`; + ` add %sp, 8, %sp\n` + | Lop(Ispecific sop) -> + assert false + | Lreloadretaddr -> + let n = frame_size() in + ` ld [%sp + {emit_int(n - 4 + 96)}], %o7\n` + | Lreturn -> + let n = frame_size() in + ` retl\n`; + if n = 0 then + ` nop\n` + else + ` add %sp, {emit_int n}, %sp\n` + | Llabel lbl -> + `{emit_label lbl}:\n` + | Lbranch lbl -> + ` b {emit_label lbl}\n`; + fill_delay_slot dslot + | Lcondbranch(tst, lbl) -> + begin match tst with + Itruetest -> + ` tst {emit_reg i.arg.(0)}\n`; + ` bne {emit_label lbl}\n` + | Ifalsetest -> + ` tst {emit_reg i.arg.(0)}\n`; + ` be {emit_label lbl}\n` + | Iinttest cmp -> + let comp = name_for_int_comparison cmp in + ` cmp {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` {emit_string comp} {emit_label lbl}\n` + | Iinttest_imm(cmp, n) -> + let comp = name_for_int_comparison cmp in + ` cmp {emit_reg i.arg.(0)}, {emit_int n}\n`; + ` {emit_string comp} {emit_label lbl}\n` + | Ifloattest(cmp, neg) -> + let comp = name_for_float_comparison cmp neg in + ` fcmpd {emit_reg i.arg.(0)}, {emit_reg i.arg.(1)}\n`; + ` nop\n`; + ` {emit_string comp} {emit_label lbl}\n` + | Ioddtest -> + ` andcc {emit_reg i.arg.(0)}, 1, %g0\n`; + ` bne {emit_label lbl}\n` + | Ieventest -> + ` andcc {emit_reg i.arg.(0)}, 1, %g0\n`; + ` be {emit_label lbl}\n` + end; + fill_delay_slot dslot + | Lcondbranch3(lbl0, lbl1, lbl2) -> + ` cmp {emit_reg i.arg.(0)}, 1\n`; + begin match lbl0 with + None -> () + | Some lbl -> ` bl {emit_label lbl}\n nop\n` + end; + begin match lbl1 with + None -> () + | Some lbl -> ` be {emit_label lbl}\n nop\n` + end; + begin match lbl2 with + None -> () + | Some lbl -> ` bg {emit_label lbl}\n nop\n` + end + | Lswitch jumptbl -> + let lbl_jumptbl = new_label() in + ` sethi %hi({emit_label lbl_jumptbl}), %g1\n`; + ` or %g1, %lo({emit_label lbl_jumptbl}), %g1\n`; + ` sll {emit_reg i.arg.(0)}, 2, %g2\n`; + ` ld [%g1 + %g2], %g1\n`; + ` jmp %g1\n`; (* poor scheduling *) + ` nop\n`; + `{emit_label lbl_jumptbl}:`; + for i = 0 to Array.length jumptbl - 1 do + ` .word {emit_label jumptbl.(i)}\n` + done + | Lsetuptrap lbl -> + ` call {emit_label lbl}\n`; + ` sub %sp, 8, %sp\n` (* in delay slot *) + | Lpushtrap -> + stack_offset := !stack_offset + 8; + ` st %o7, [%sp + 96]\n`; + ` st %l5, [%sp + 100]\n`; + ` mov %sp, %l5\n` + | Lpoptrap -> + ` ld [%sp + 100], %l5\n`; + ` add %sp, 8, %sp\n`; + stack_offset := !stack_offset - 8 + | Lraise -> + ` ld [%l5 + 96], %g1\n`; + ` mov %l5, %sp\n`; + ` ld [%sp + 100], %l5\n`; + ` jmp %g1 + 8\n`; + ` add %sp, 8, %sp\n` + +and fill_delay_slot = function + None -> ` nop\n` + | Some i -> emit_instr i None + +(* Checks if a pseudo-instruction expands to exactly one machine instruction + that does not branch. *) + +let is_one_instr_op = function + Idiv | Imod | Icomp _ | Icheckbound -> false + | _ -> true + +let is_one_instr i = + match i.desc with + Lop op -> + begin match op with + Imove | Ispill | Ireload -> + i.arg.(0).typ <> Float && i.res.(0).typ <> Float + | Iconst_int n -> is_native_immediate n + | Istackoffset _ -> true + | Iload(_, Iindexed n) -> i.res.(0).typ <> Float & is_immediate n + | Istore(_, Iindexed n) -> i.arg.(0).typ <> Float & is_immediate n + | Iintop(op) -> is_one_instr_op op + | Iintop_imm(op, _) -> is_one_instr_op op + | Iaddf | Isubf | Imulf | Idivf -> true + | Iabsf | Inegf -> !arch_version = SPARC_V9 + | _ -> false + end + | _ -> false + +let no_interference res arg = + try + for i = 0 to Array.length arg - 1 do + for j = 0 to Array.length res - 1 do + if arg.(i).loc = res.(j).loc then raise Exit + done + done; + true + with Exit -> + false + +(* Emit a sequence of instructions, trying to fill delay slots for branches *) + +let rec emit_all i = + match i with + {desc = Lend} -> () + | {next = {desc = Lop(Icall_imm _) | Lop(Iextcall(_, false)) | Lbranch _}} + when is_one_instr i -> + emit_instr i.next (Some i); + emit_all i.next.next + | {next = {desc = Lop(Itailcall_imm s)}} + when s = !function_name & is_one_instr i -> + emit_instr i.next (Some i); + emit_all i.next.next + | {next = {desc = Lop(Icall_ind)}} + when is_one_instr i & no_interference i.res i.next.arg -> + emit_instr i.next (Some i); + emit_all i.next.next + | {next = {desc = Lcondbranch(_, _)}} + when is_one_instr i & no_interference i.res i.next.arg -> + emit_instr i.next (Some i); + emit_all i.next.next + | _ -> + emit_instr i None; + emit_all i.next + +(* Emission of a function declaration *) + +let fundecl fundecl = + function_name := fundecl.fun_name; + fastcode_flag := fundecl.fun_fast; + tailrec_entry_point := new_label(); + range_check_trap := 0; + stack_offset := 0; + float_constants := []; + ` .text\n`; + ` .align 4\n`; + ` .global {emit_symbol fundecl.fun_name}\n`; + if Config.system = "solaris" then + ` .type {emit_symbol fundecl.fun_name},#function\n`; + `{emit_symbol fundecl.fun_name}:\n`; + if !Clflags.gprofile then emit_profile(); + let n = frame_size() in + if n > 0 then + ` sub %sp, {emit_int n}, %sp\n`; + if !contains_calls then + ` st %o7, [%sp + {emit_int(n - 4 + 96)}]\n`; + `{emit_label !tailrec_entry_point}:\n`; + emit_all fundecl.fun_body; + if !range_check_trap > 0 then begin + `{emit_label !range_check_trap}:\n`; + ` call {emit_symbol "caml_ml_array_bound_error"}\n`; + ` nop\n` + end; + emit_size fundecl.fun_name; + List.iter emit_float_constant !float_constants + +(* Emission of data *) + +let emit_item = function + Cglobal_symbol s -> + ` .global {emit_symbol s}\n`; + | Cdefine_symbol s -> + `{emit_symbol s}:\n` + | Cdefine_label lbl -> + `{emit_label (lbl + 100000)}:\n` + | Cint8 n -> + ` .byte {emit_int n}\n` + | Cint16 n -> + ` .half {emit_int n}\n` + | Cint32 n -> + ` .word {emit_nativeint n}\n` + | Cint n -> + ` .word {emit_nativeint n}\n` + | Csingle f -> + ` .single 0r{emit_string f}\n` + | Cdouble f -> + ` .double 0r{emit_string f}\n` + | Csymbol_address s -> + ` .word {emit_symbol s}\n` + | Clabel_address lbl -> + ` .word {emit_label (lbl + 100000)}\n` + | Cstring s -> + emit_string_directive " .ascii " s + | Cskip n -> + if n > 0 then ` .skip {emit_int n}\n` + | Calign n -> + ` .align {emit_int n}\n` + +let data l = + ` .data\n`; + List.iter emit_item l + +(* Beginning / end of an assembly file *) + +let begin_assembly() = + let lbl_begin = Compilenv.make_symbol (Some "data_begin") in + ` .data\n`; + ` .global {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n`; + let lbl_begin = Compilenv.make_symbol (Some "code_begin") in + ` .text\n`; + ` .global {emit_symbol lbl_begin}\n`; + `{emit_symbol lbl_begin}:\n` + +let end_assembly() = + ` .text\n`; + let lbl_end = Compilenv.make_symbol (Some "code_end") in + ` .global {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .data\n`; + let lbl_end = Compilenv.make_symbol (Some "data_end") in + ` .global {emit_symbol lbl_end}\n`; + `{emit_symbol lbl_end}:\n`; + ` .word 0\n`; + let lbl = Compilenv.make_symbol (Some "frametable") in + rodata (); + ` .global {emit_symbol lbl}\n`; + if Config.system = "solaris" then + ` .type {emit_symbol lbl},#object\n`; + `{emit_symbol lbl}:\n`; + ` .word {emit_int (List.length !frame_descriptors)}\n`; + List.iter emit_frame !frame_descriptors; + emit_size lbl; + frame_descriptors := [] diff --git a/asmcomp/sparc/proc.ml b/asmcomp/sparc/proc.ml new file mode 100644 index 0000000..f776978 --- /dev/null +++ b/asmcomp/sparc/proc.ml @@ -0,0 +1,215 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: proc.ml,v 1.8 2007-10-30 12:37:16 xleroy Exp $ *) + +(* Description of the Sparc processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +(* Instruction selection *) + +let word_addressed = false + +(* Registers available for register allocation *) + +(* Register map: + %o0 - %o5 0 - 5 function results, C functions args / res + %i0 - %i5 6 - 11 function arguments, preserved by C + %l0 - %l4 12 - 16 general purpose, preserved by C + %g3 - %g4 17 - 18 general purpose, not preserved by C + + %l5 exception pointer + %l6 allocation pointer + %l7 address of allocation limit + + %g0 always zero + %g1 - %g2 temporaries + %g5 - %g7 reserved for system libraries + + %f0 - %f10 100 - 105 function arguments and results + %f12 - %f28 106 - 114 general purpose + %f30 temporary *) + +let int_reg_name = [| + (* 0-5 *) "%o0"; "%o1"; "%o2"; "%o3"; "%o4"; "%o5"; + (* 6-11 *) "%i0"; "%i1"; "%i2"; "%i3"; "%i4"; "%i5"; + (* 12-16 *) "%l0"; "%l1"; "%l2"; "%l3"; "%l4"; + (* 17-18 *) "%g3"; "%g4" +|] + +let float_reg_name = [| + (* 100-105 *) "%f0"; "%f2"; "%f4"; "%f6"; "%f8"; "%f10"; + (* 106-109 *) "%f12"; "%f14"; "%f16"; "%f18"; + (* 110-114 *) "%f20"; "%f22"; "%f24"; "%f26"; "%f28"; + (* 115 *) "%f30"; + (* Odd parts of register pairs *) + (* 116-121 *) "%f1"; "%f3"; "%f5"; "%f7"; "%f9"; "%f11"; + (* 122-125 *) "%f13"; "%f15"; "%f17"; "%f19"; + (* 126-130 *) "%f21"; "%f23"; "%f25"; "%f27"; "%f29"; + (* 131 *) "%f31" +|] + +let num_register_classes = 2 + +let register_class r = + match r.typ with + Int -> 0 + | Addr -> 0 + | Float -> 1 + +let num_available_registers = [| 19; 15 |] + +let first_available_register = [| 0; 100 |] + +let register_name r = + if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100) + +let rotate_registers = true + +(* Representation of hard registers by pseudo-registers *) + +let hard_int_reg = + let v = Array.create 19 Reg.dummy in + for i = 0 to 18 do v.(i) <- Reg.at_location Int (Reg i) done; + v + +let hard_float_reg = + let v = Array.create 32 Reg.dummy in + for i = 0 to 31 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done; + v + +let all_phys_regs = + Array.append hard_int_reg (Array.sub hard_float_reg 0 15) + (* No need to include the odd parts of float register pairs, + nor the temporary register %f30 *) + +let phys_reg n = + if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100) + +let stack_slot slot ty = + Reg.at_location ty (Stack slot) + +(* Calling conventions *) + +let calling_conventions first_int last_int first_float last_float make_stack + arg = + let loc = Array.create (Array.length arg) Reg.dummy in + let int = ref first_int in + let float = ref first_float in + let ofs = ref 0 in + for i = 0 to Array.length arg - 1 do + match arg.(i).typ with + Int | Addr as ty -> + if !int <= last_int then begin + loc.(i) <- phys_reg !int; + incr int + end else begin + loc.(i) <- stack_slot (make_stack !ofs) ty; + ofs := !ofs + size_int + end + | Float -> + if !float <= last_float then begin + loc.(i) <- phys_reg !float; + incr float + end else begin + loc.(i) <- stack_slot (make_stack !ofs) Float; + ofs := !ofs + size_float + end + done; + (loc, Misc.align !ofs 8) (* Keep stack 8-aligned *) + +let incoming ofs = Incoming ofs +let outgoing ofs = Outgoing ofs +let not_supported ofs = fatal_error "Proc.loc_results: cannot call" + +let loc_arguments arg = + calling_conventions 6 15 100 105 outgoing arg +let loc_parameters arg = + let (loc, ofs) = calling_conventions 6 15 100 105 incoming arg in loc +let loc_results res = + let (loc, ofs) = calling_conventions 0 5 100 105 not_supported res in loc + +(* On the Sparc, all arguments to C functions, even floating-point arguments, + are passed in %o0..%o5, then on the stack *) + +let loc_external_arguments arg = + let loc = ref [] in + let reg = ref 0 (* %o0 *) in + let ofs = ref (-4) in (* start at sp + 92 = sp + 96 - 4 *) + for i = 0 to Array.length arg - 1 do + if !reg <= 5 (* %o5 *) then begin + match arg.(i).typ with + Int | Addr -> + loc := phys_reg !reg :: !loc; + incr reg + | Float -> + if !reg = 5 then fatal_error "Proc_sparc: cannot call"; + loc := phys_reg (!reg + 1) :: phys_reg !reg :: !loc; + reg := !reg + 2 + end else begin + loc := stack_slot (outgoing !ofs) arg.(i).typ :: !loc; + ofs := !ofs + size_component arg.(i).typ + end + done; + (* Keep stack 8-aligned *) + (Array.of_list(List.rev !loc), Misc.align (!ofs + 4) 8) + +let loc_external_results res = + let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc + +let loc_exn_bucket = phys_reg 0 (* $o0 *) + +(* Registers destroyed by operations *) + +let destroyed_at_c_call = (* %l0-%l4, %i0-%i5 preserved *) + Array.of_list(List.map phys_reg + [0; 1; 2; 3; 4; 5; 17; 18; + 100; 101; 102; 103; 104; 105; 106; 107; + 108; 109; 110; 111; 112; 113; 114]) + +let destroyed_at_oper = function + Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs + | Iop(Iextcall(_, false)) -> destroyed_at_c_call + | _ -> [||] + +let destroyed_at_raise = all_phys_regs + +(* Maximal register pressure *) + +let safe_register_pressure = function + Iextcall(_, _) -> 0 + | _ -> 15 + +let max_register_pressure = function + Iextcall(_, _) -> [| 11; 0 |] + | _ -> [| 19; 15 |] + +(* Layout of the stack *) + +let num_stack_slots = [| 0; 0 |] +let contains_calls = ref false + +(* Calling the assembler and the archiver *) + +let assemble_file infile outfile = + let asflags = begin match !arch_version with + SPARC_V7 -> " -o " + | SPARC_V8 -> " -xarch=v8 -o " + | SPARC_V9 -> " -xarch=v8plus -o " + end in + Ccomp.command (Config.asm ^ asflags ^ + Filename.quote outfile ^ " " ^ Filename.quote infile) diff --git a/asmcomp/sparc/reload.ml b/asmcomp/sparc/reload.ml new file mode 100644 index 0000000..b870751 --- /dev/null +++ b/asmcomp/sparc/reload.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: reload.ml,v 1.3 1999-11-17 18:56:47 xleroy Exp $ *) + +(* Reloading for the Sparc *) + +let fundecl f = + (new Reloadgen.reload_generic)#fundecl f diff --git a/asmcomp/sparc/scheduling.ml b/asmcomp/sparc/scheduling.ml new file mode 100644 index 0000000..8e7fa76 --- /dev/null +++ b/asmcomp/sparc/scheduling.ml @@ -0,0 +1,65 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scheduling.ml,v 1.5 2002-11-29 15:03:08 xleroy Exp $ *) + +open Cmm +open Mach + +(* Instruction scheduling for the Sparc *) + +class scheduler = object + +inherit Schedgen.scheduler_generic + +(* Latencies (in cycles). *) + +(* UltraSPARC issues two integer operations, plus a single load or store, + per cycle. At most one of the integer instructions may be a shift. + Most integer operations have one cycle latency. Unsigned loads take + two cycles. Signed loads take three cycles. Conditional moves have + two cycle latency and may not issue in the same cycle as any other + instruction. Floating point issue rules are complicated, but in + general independent add and multiply can dual issue with four cycle + latency. *) + +method oper_latency = function + Ireload -> 2 + | Iload((Byte_signed|Sixteen_signed|Thirtytwo_signed), _) -> 3 + | Iload(_, _) -> 2 + | Iconst_float _ -> 2 (* turned into a load *) + | Inegf | Iabsf | Iaddf | Isubf | Imulf -> 4 + | Idivf -> 15 + | _ -> 1 + +(* Issue cycles. Rough approximations. *) + +method oper_issue_cycles = function + Iconst_float _ -> 2 + | Iconst_symbol _ -> 2 + | Ialloc _ -> 6 + | Iintop(Icomp _) -> 4 + | Iintop(Icheckbound) -> 2 + | Iintop_imm(Idiv, _) -> 5 + | Iintop_imm(Imod, _) -> 5 + | Iintop_imm(Icomp _, _) -> 4 + | Iintop_imm(Icheckbound, _) -> 2 + | Inegf -> 2 + | Iabsf -> 2 + | Ifloatofint -> 6 + | Iintoffloat -> 6 + | _ -> 1 + +end + +let fundecl f = (new scheduler)#schedule_fundecl f + diff --git a/asmcomp/sparc/selection.ml b/asmcomp/sparc/selection.ml new file mode 100644 index 0000000..4d62328 --- /dev/null +++ b/asmcomp/sparc/selection.ml @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: selection.ml,v 1.8 2002-11-29 15:03:08 xleroy Exp $ *) + +(* Instruction selection for the Sparc processor *) + +open Misc +open Cmm +open Reg +open Arch +open Mach + +class selector = object (self) + +inherit Selectgen.selector_generic as super + +method is_immediate n = (n <= 4095) && (n >= -4096) + +method select_addressing = function + Cconst_symbol s -> + (Ibased(s, 0), Ctuple []) + | Cop(Cadda, [Cconst_symbol s; Cconst_int n]) -> + (Ibased(s, n), Ctuple []) + | Cop(Cadda, [arg; Cconst_int n]) -> + (Iindexed n, arg) + | Cop(Cadda, [arg1; Cop(Caddi, [arg2; Cconst_int n])]) -> + (Iindexed n, Cop(Cadda, [arg1; arg2])) + | arg -> + (Iindexed 0, arg) + +method select_operation op args = + match (op, args) with + (* For SPARC V7 multiplication, division and modulus are turned into + calls to C library routines, except if the dividend is a power of 2. + For SPARC V8 and V9, use hardware multiplication and division, + but C library routine for modulus. *) + (Cmuli, [arg; Cconst_int n]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Ilsl, Misc.log2 n), [arg]) + | (Cmuli, [Cconst_int n; arg]) when n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Ilsl, Misc.log2 n), [arg]) + | (Cmuli, _) when !arch_version = SPARC_V7 -> + (Iextcall(".umul", false), args) + | (Cdivi, [arg; Cconst_int n]) + when self#is_immediate n && n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Idiv, n), [arg]) + | (Cdivi, _) when !arch_version = SPARC_V7 -> + (Iextcall(".div", false), args) + | (Cmodi, [arg; Cconst_int n]) + when self#is_immediate n && n = 1 lsl (Misc.log2 n) -> + (Iintop_imm(Imod, n), [arg]) + | (Cmodi, _) -> + (Iextcall(".rem", false), args) + | _ -> + super#select_operation op args + +(* Override insert_move_args to deal correctly with floating-point + arguments being passed into pairs of integer registers. *) +method insert_move_args arg loc stacksize = + if stacksize <> 0 then self#insert (Iop(Istackoffset stacksize)) [||] [||]; + let locpos = ref 0 in + for i = 0 to Array.length arg - 1 do + let src = arg.(i) in + let dst = loc.(!locpos) in + match (src, dst) with + ({typ = Float}, {typ = Int}) -> + let dst2 = loc.(!locpos + 1) in + self#insert (Iop Imove) [|src|] [|dst; dst2|]; + locpos := !locpos + 2 + | (_, _) -> + self#insert_move src dst; + incr locpos + done + +end + +let fundecl f = (new selector)#emit_fundecl f diff --git a/asmcomp/spill.ml b/asmcomp/spill.ml new file mode 100644 index 0000000..7c41fc9 --- /dev/null +++ b/asmcomp/spill.ml @@ -0,0 +1,403 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: spill.ml,v 1.19 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Insertion of moves to suggest possible spilling / reloading points + before register allocation. *) + +open Reg +open Mach + +(* We say that a register is "destroyed" if it is live across a construct + that potentially destroys all physical registers: function calls or + try...with constructs. + + The "destroyed" registers must therefore reside in the stack during + these instructions.. We will insert spills (stores) just after they + are defined, and reloads just before their first use following a + "destroying" construct. + + Instructions with more live registers than actual registers also + "destroy" registers: we mark as "destroyed" the registers live + across the instruction that haven't been used for the longest time. + These registers will be spilled and reloaded as described above. *) + +(* Association of spill registers to registers *) + +let spill_env = ref (Reg.Map.empty : Reg.t Reg.Map.t) + +let spill_reg r = + try + Reg.Map.find r !spill_env + with Not_found -> + let spill_r = Reg.create r.typ in + spill_r.spill <- true; + if String.length r.name > 0 then spill_r.name <- "spilled-" ^ r.name; + spill_env := Reg.Map.add r spill_r !spill_env; + spill_r + +(* Record the position of last use of registers *) + +let use_date = ref (Reg.Map.empty : int Reg.Map.t) +let current_date = ref 0 + +let record_use regv = + for i = 0 to Array.length regv - 1 do + let r = regv.(i) in + let prev_date = try Reg.Map.find r !use_date with Not_found -> 0 in + if !current_date > prev_date then + use_date := Reg.Map.add r !current_date !use_date + done + +(* Check if the register pressure overflows the maximum pressure allowed + at that point. If so, spill enough registers to lower the pressure. *) + +let add_superpressure_regs op live_regs res_regs spilled = + let max_pressure = Proc.max_register_pressure op in + let regs = Reg.add_set_array live_regs res_regs in + (* Compute the pressure in each register class *) + let pressure = Array.create Proc.num_register_classes 0 in + Reg.Set.iter + (fun r -> + if Reg.Set.mem r spilled then () else begin + match r.loc with + Stack s -> () + | _ -> let c = Proc.register_class r in + pressure.(c) <- pressure.(c) + 1 + end) + regs; + (* Check if pressure is exceeded for each class. *) + let rec check_pressure cl spilled = + if cl >= Proc.num_register_classes then + spilled + else if pressure.(cl) <= max_pressure.(cl) then + check_pressure (cl+1) spilled + else begin + (* Find the least recently used, unspilled, unallocated, live register + in the class *) + let lru_date = ref 1000000 and lru_reg = ref Reg.dummy in + Reg.Set.iter + (fun r -> + if Proc.register_class r = cl && + not (Reg.Set.mem r spilled) && + r.loc = Unknown + then begin + try + let d = Reg.Map.find r !use_date in + if d < !lru_date then begin + lru_date := d; + lru_reg := r + end + with Not_found -> (* Should not happen *) + () + end) + live_regs; + if !lru_reg != Reg.dummy then begin + pressure.(cl) <- pressure.(cl) - 1; + check_pressure cl (Reg.Set.add !lru_reg spilled) + end else + (* Couldn't find any spillable register, give up for this class *) + check_pressure (cl+1) spilled + end in + check_pressure 0 spilled + +(* A-list recording what is destroyed at if-then-else points. *) + +let destroyed_at_fork = ref ([] : (instruction * Reg.Set.t) list) + +(* First pass: insert reload instructions based on an approximation of + what is destroyed at pressure points. *) + +let add_reloads regset i = + Reg.Set.fold + (fun r i -> instr_cons (Iop Ireload) [|spill_reg r|] [|r|] i) + regset i + +let reload_at_exit = ref [] + +let find_reload_at_exit k = + try + List.assoc k !reload_at_exit + with + | Not_found -> Misc.fatal_error "Spill.find_reload_at_exit" + +let reload_at_break = ref Reg.Set.empty + +let rec reload i before = + incr current_date; + record_use i.arg; + record_use i.res; + match i.desc with + Iend -> + (i, before) + | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> + (add_reloads (Reg.inter_set_array before i.arg) i, + Reg.Set.empty) + | Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> + (* All regs live across must be spilled *) + let (new_next, finally) = reload i.next i.live in + (add_reloads (Reg.inter_set_array before i.arg) + (instr_cons_debug i.desc i.arg i.res i.dbg new_next), + finally) + | Iop op -> + let new_before = + (* Quick check to see if the register pressure is below the maximum *) + if Reg.Set.cardinal i.live + Array.length i.res <= + Proc.safe_register_pressure op + then before + else add_superpressure_regs op i.live i.res before in + let after = + Reg.diff_set_array (Reg.diff_set_array new_before i.arg) i.res in + let (new_next, finally) = reload i.next after in + (add_reloads (Reg.inter_set_array new_before i.arg) + (instr_cons_debug i.desc i.arg i.res i.dbg new_next), + finally) + | Iifthenelse(test, ifso, ifnot) -> + let at_fork = Reg.diff_set_array before i.arg in + let date_fork = !current_date in + let (new_ifso, after_ifso) = reload ifso at_fork in + let date_ifso = !current_date in + current_date := date_fork; + let (new_ifnot, after_ifnot) = reload ifnot at_fork in + current_date := max date_ifso !current_date; + let (new_next, finally) = + reload i.next (Reg.Set.union after_ifso after_ifnot) in + let new_i = + instr_cons (Iifthenelse(test, new_ifso, new_ifnot)) + i.arg i.res new_next in + destroyed_at_fork := (new_i, at_fork) :: !destroyed_at_fork; + (add_reloads (Reg.inter_set_array before i.arg) new_i, + finally) + | Iswitch(index, cases) -> + let at_fork = Reg.diff_set_array before i.arg in + let date_fork = !current_date in + let date_join = ref 0 in + let after_cases = ref Reg.Set.empty in + let new_cases = + Array.map + (fun c -> + current_date := date_fork; + let (new_c, after_c) = reload c at_fork in + after_cases := Reg.Set.union !after_cases after_c; + date_join := max !date_join !current_date; + new_c) + cases in + current_date := !date_join; + let (new_next, finally) = reload i.next !after_cases in + (add_reloads (Reg.inter_set_array before i.arg) + (instr_cons (Iswitch(index, new_cases)) + i.arg i.res new_next), + finally) + | Iloop(body) -> + let date_start = !current_date in + let at_head = ref before in + let final_body = ref body in + begin try + while true do + current_date := date_start; + let (new_body, new_at_head) = reload body !at_head in + let merged_at_head = Reg.Set.union !at_head new_at_head in + if Reg.Set.equal merged_at_head !at_head then begin + final_body := new_body; + raise Exit + end; + at_head := merged_at_head + done + with Exit -> () + end; + let (new_next, finally) = reload i.next Reg.Set.empty in + (instr_cons (Iloop(!final_body)) i.arg i.res new_next, + finally) + | Icatch(nfail, body, handler) -> + let new_set = ref Reg.Set.empty in + reload_at_exit := (nfail, new_set) :: !reload_at_exit ; + let (new_body, after_body) = reload body before in + let at_exit = !new_set in + reload_at_exit := List.tl !reload_at_exit ; + let (new_handler, after_handler) = reload handler at_exit in + let (new_next, finally) = + reload i.next (Reg.Set.union after_body after_handler) in + (instr_cons (Icatch(nfail, new_body, new_handler)) i.arg i.res new_next, + finally) + | Iexit nfail -> + let set = find_reload_at_exit nfail in + set := Reg.Set.union !set before; + (i, Reg.Set.empty) + | Itrywith(body, handler) -> + let (new_body, after_body) = reload body before in + let (new_handler, after_handler) = reload handler handler.live in + let (new_next, finally) = + reload i.next (Reg.Set.union after_body after_handler) in + (instr_cons (Itrywith(new_body, new_handler)) i.arg i.res new_next, + finally) + | Iraise -> + (add_reloads (Reg.inter_set_array before i.arg) i, Reg.Set.empty) + +(* Second pass: add spill instructions based on what we've decided to reload. + That is, any register that may be reloaded in the future must be spilled + just after its definition. *) + +(* + As an optimization, if a register needs to be spilled in one branch of + a conditional but not in the other, then we spill it late on entrance + in the branch that needs it spilled. + NB: This strategy is turned off in loops, as it may prevent a spill from + being lifted up all the way out of the loop. + NB again: This strategy is also off in switch arms + as it generates many useless spills inside switch arms + NB ter: is it the same thing for catch bodies ? +*) + + +let spill_at_exit = ref [] +let find_spill_at_exit k = + try + List.assoc k !spill_at_exit + with + | Not_found -> Misc.fatal_error "Spill.find_spill_at_exit" + +let spill_at_raise = ref Reg.Set.empty +let inside_loop = ref false +and inside_arm = ref false +and inside_catch = ref false + +let add_spills regset i = + Reg.Set.fold + (fun r i -> instr_cons (Iop Ispill) [|r|] [|spill_reg r|] i) + regset i + +let rec spill i finally = + match i.desc with + Iend -> + (i, finally) + | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> + (i, Reg.Set.empty) + | Iop Ireload -> + let (new_next, after) = spill i.next finally in + let before1 = Reg.diff_set_array after i.res in + (instr_cons i.desc i.arg i.res new_next, + Reg.add_set_array before1 i.res) + | Iop _ -> + let (new_next, after) = spill i.next finally in + let before1 = Reg.diff_set_array after i.res in + let before = + match i.desc with + Iop Icall_ind | Iop(Icall_imm _) | Iop(Iextcall _) + | Iop(Iintop Icheckbound) | Iop(Iintop_imm(Icheckbound, _)) -> + Reg.Set.union before1 !spill_at_raise + | _ -> + before1 in + (instr_cons_debug i.desc i.arg i.res i.dbg + (add_spills (Reg.inter_set_array after i.res) new_next), + before) + | Iifthenelse(test, ifso, ifnot) -> + let (new_next, at_join) = spill i.next finally in + let (new_ifso, before_ifso) = spill ifso at_join in + let (new_ifnot, before_ifnot) = spill ifnot at_join in + if + !inside_loop || !inside_arm + then + (instr_cons (Iifthenelse(test, new_ifso, new_ifnot)) + i.arg i.res new_next, + Reg.Set.union before_ifso before_ifnot) + else begin + let destroyed = List.assq i !destroyed_at_fork in + let spill_ifso_branch = + Reg.Set.diff (Reg.Set.diff before_ifso before_ifnot) destroyed + and spill_ifnot_branch = + Reg.Set.diff (Reg.Set.diff before_ifnot before_ifso) destroyed in + (instr_cons + (Iifthenelse(test, add_spills spill_ifso_branch new_ifso, + add_spills spill_ifnot_branch new_ifnot)) + i.arg i.res new_next, + Reg.Set.diff (Reg.Set.diff (Reg.Set.union before_ifso before_ifnot) + spill_ifso_branch) + spill_ifnot_branch) + end + | Iswitch(index, cases) -> + let (new_next, at_join) = spill i.next finally in + let saved_inside_arm = !inside_arm in + inside_arm := true ; + let before = ref Reg.Set.empty in + let new_cases = + Array.map + (fun c -> + let (new_c, before_c) = spill c at_join in + before := Reg.Set.union !before before_c; + new_c) + cases in + inside_arm := saved_inside_arm ; + (instr_cons (Iswitch(index, new_cases)) i.arg i.res new_next, + !before) + | Iloop(body) -> + let (new_next, _) = spill i.next finally in + let saved_inside_loop = !inside_loop in + inside_loop := true; + let at_head = ref Reg.Set.empty in + let final_body = ref body in + begin try + while true do + let (new_body, before_body) = spill body !at_head in + let new_at_head = Reg.Set.union !at_head before_body in + if Reg.Set.equal new_at_head !at_head then begin + final_body := new_body; raise Exit + end; + at_head := new_at_head + done + with Exit -> () + end; + inside_loop := saved_inside_loop; + (instr_cons (Iloop(!final_body)) i.arg i.res new_next, + !at_head) + | Icatch(nfail, body, handler) -> + let (new_next, at_join) = spill i.next finally in + let (new_handler, at_exit) = spill handler at_join in + let saved_inside_catch = !inside_catch in + inside_catch := true ; + spill_at_exit := (nfail, at_exit) :: !spill_at_exit ; + let (new_body, before) = spill body at_join in + spill_at_exit := List.tl !spill_at_exit; + inside_catch := saved_inside_catch ; + (instr_cons (Icatch(nfail, new_body, new_handler)) i.arg i.res new_next, + before) + | Iexit nfail -> + (i, find_spill_at_exit nfail) + | Itrywith(body, handler) -> + let (new_next, at_join) = spill i.next finally in + let (new_handler, before_handler) = spill handler at_join in + let saved_spill_at_raise = !spill_at_raise in + spill_at_raise := before_handler; + let (new_body, before_body) = spill body at_join in + spill_at_raise := saved_spill_at_raise; + (instr_cons (Itrywith(new_body, new_handler)) i.arg i.res new_next, + before_body) + | Iraise -> + (i, !spill_at_raise) + +(* Entry point *) + +let fundecl f = + spill_env := Reg.Map.empty; + use_date := Reg.Map.empty; + current_date := 0; + let (body1, _) = reload f.fun_body Reg.Set.empty in + let (body2, tospill_at_entry) = spill body1 Reg.Set.empty in + let new_body = + add_spills (Reg.inter_set_array tospill_at_entry f.fun_args) body2 in + spill_env := Reg.Map.empty; + use_date := Reg.Map.empty; + { fun_name = f.fun_name; + fun_args = f.fun_args; + fun_body = new_body; + fun_fast = f.fun_fast } + diff --git a/asmcomp/spill.mli b/asmcomp/spill.mli new file mode 100644 index 0000000..ce7c27c --- /dev/null +++ b/asmcomp/spill.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: spill.mli,v 1.4 1999-11-17 18:56:38 xleroy Exp $ *) + +(* Insertion of moves to suggest possible spilling / reloading points + before register allocation. *) + +val fundecl: Mach.fundecl -> Mach.fundecl diff --git a/asmcomp/split.ml b/asmcomp/split.ml new file mode 100644 index 0000000..ca954a2 --- /dev/null +++ b/asmcomp/split.ml @@ -0,0 +1,210 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: split.ml,v 1.10 2007-01-29 12:10:50 xleroy Exp $ *) + +(* Renaming of registers at reload points to split live ranges. *) + +open Reg +open Mach + +(* Substitutions are represented by register maps *) + +type subst = Reg.t Reg.Map.t + +let subst_reg r sub = + try + Reg.Map.find r sub + with Not_found -> + r + +let subst_regs rv sub = + match sub with + None -> rv + | Some s -> + let n = Array.length rv in + let nv = Array.create n Reg.dummy in + for i = 0 to n-1 do nv.(i) <- subst_reg rv.(i) s done; + nv + +(* We maintain equivalence classes of registers using a standard + union-find algorithm *) + +let equiv_classes = ref (Reg.Map.empty : Reg.t Reg.Map.t) + +let rec repres_reg r = + try + repres_reg(Reg.Map.find r !equiv_classes) + with Not_found -> + r + +let repres_regs rv = + let n = Array.length rv in + for i = 0 to n-1 do rv.(i) <- repres_reg rv.(i) done + +(* Identify two registers. + The second register is chosen as canonical representative. *) + +let identify r1 r2 = + let repres1 = repres_reg r1 in + let repres2 = repres_reg r2 in + if repres1.stamp = repres2.stamp then () else begin + equiv_classes := Reg.Map.add repres1 repres2 !equiv_classes + end + +(* Identify the image of a register by two substitutions. + Be careful to use the original register as canonical representative + in case it does not belong to the domain of one of the substitutions. *) + +let identify_sub sub1 sub2 reg = + try + let r1 = Reg.Map.find reg sub1 in + try + let r2 = Reg.Map.find reg sub2 in + identify r1 r2 + with Not_found -> + identify r1 reg + with Not_found -> + try + let r2 = Reg.Map.find reg sub2 in + identify r2 reg + with Not_found -> + () + +(* Identify registers so that the two substitutions agree on the + registers live before the given instruction. *) + +let merge_substs sub1 sub2 i = + match (sub1, sub2) with + (None, None) -> None + | (Some s1, None) -> sub1 + | (None, Some s2) -> sub2 + | (Some s1, Some s2) -> + Reg.Set.iter (identify_sub s1 s2) (Reg.add_set_array i.live i.arg); + sub1 + +(* Same, for N substitutions *) + +let merge_subst_array subv instr = + let rec find_one_subst i = + if i >= Array.length subv then None else begin + match subv.(i) with + None -> find_one_subst (i+1) + | Some si as sub -> + for j = i+1 to Array.length subv - 1 do + match subv.(j) with + None -> () + | Some sj -> + Reg.Set.iter (identify_sub si sj) + (Reg.add_set_array instr.live instr.arg) + done; + sub + end in + find_one_subst 0 + +(* First pass: rename registers at reload points *) + +let exit_subst = ref [] + +let find_exit_subst k = + try + List.assoc k !exit_subst with + | Not_found -> Misc.fatal_error "Split.find_exit_subst" + +let rec rename i sub = + match i.desc with + Iend -> + (i, sub) + | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> + (instr_cons i.desc (subst_regs i.arg sub) [||] i.next, + None) + | Iop Ireload when i.res.(0).loc = Unknown -> + begin match sub with + None -> rename i.next sub + | Some s -> + let oldr = i.res.(0) in + let newr = Reg.clone i.res.(0) in + let (new_next, sub_next) = + rename i.next (Some(Reg.Map.add oldr newr s)) in + (instr_cons i.desc i.arg [|newr|] new_next, + sub_next) + end + | Iop _ -> + let (new_next, sub_next) = rename i.next sub in + (instr_cons_debug i.desc (subst_regs i.arg sub) (subst_regs i.res sub) + i.dbg new_next, + sub_next) + | Iifthenelse(tst, ifso, ifnot) -> + let (new_ifso, sub_ifso) = rename ifso sub in + let (new_ifnot, sub_ifnot) = rename ifnot sub in + let (new_next, sub_next) = + rename i.next (merge_substs sub_ifso sub_ifnot i.next) in + (instr_cons (Iifthenelse(tst, new_ifso, new_ifnot)) + (subst_regs i.arg sub) [||] new_next, + sub_next) + | Iswitch(index, cases) -> + let new_sub_cases = Array.map (fun c -> rename c sub) cases in + let sub_merge = + merge_subst_array (Array.map (fun (n, s) -> s) new_sub_cases) i.next in + let (new_next, sub_next) = rename i.next sub_merge in + (instr_cons (Iswitch(index, Array.map (fun (n, s) -> n) new_sub_cases)) + (subst_regs i.arg sub) [||] new_next, + sub_next) + | Iloop(body) -> + let (new_body, sub_body) = rename body sub in + let (new_next, sub_next) = rename i.next (merge_substs sub sub_body i) in + (instr_cons (Iloop(new_body)) [||] [||] new_next, + sub_next) + | Icatch(nfail, body, handler) -> + let new_subst = ref None in + exit_subst := (nfail, new_subst) :: !exit_subst ; + let (new_body, sub_body) = rename body sub in + let sub_entry_handler = !new_subst in + exit_subst := List.tl !exit_subst; + let (new_handler, sub_handler) = rename handler sub_entry_handler in + let (new_next, sub_next) = + rename i.next (merge_substs sub_body sub_handler i.next) in + (instr_cons (Icatch(nfail, new_body, new_handler)) [||] [||] new_next, + sub_next) + | Iexit nfail -> + let r = find_exit_subst nfail in + r := merge_substs !r sub i; + (i, None) + | Itrywith(body, handler) -> + let (new_body, sub_body) = rename body sub in + let (new_handler, sub_handler) = rename handler sub in + let (new_next, sub_next) = + rename i.next (merge_substs sub_body sub_handler i.next) in + (instr_cons (Itrywith(new_body, new_handler)) [||] [||] new_next, + sub_next) + | Iraise -> + (instr_cons_debug Iraise (subst_regs i.arg sub) [||] i.dbg i.next, + None) + +(* Second pass: replace registers by their final representatives *) + +let set_repres i = + instr_iter (fun i -> repres_regs i.arg; repres_regs i.res) i + +(* Entry point *) + +let fundecl f = + equiv_classes := Reg.Map.empty; + let new_args = Array.copy f.fun_args in + let (new_body, sub_body) = rename f.fun_body (Some Reg.Map.empty) in + repres_regs new_args; + set_repres new_body; + equiv_classes := Reg.Map.empty; + { fun_name = f.fun_name; + fun_args = new_args; + fun_body = new_body; + fun_fast = f.fun_fast } diff --git a/asmcomp/split.mli b/asmcomp/split.mli new file mode 100644 index 0000000..95c868d --- /dev/null +++ b/asmcomp/split.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: split.mli,v 1.4 1999-11-17 18:56:38 xleroy Exp $ *) + +(* Renaming of registers at reload points to split live ranges. *) + +val fundecl: Mach.fundecl -> Mach.fundecl diff --git a/asmrun/.cvsignore b/asmrun/.cvsignore new file mode 100644 index 0000000..55f30ce --- /dev/null +++ b/asmrun/.cvsignore @@ -0,0 +1,34 @@ +main.c +misc.c +freelist.c +major_gc.c +minor_gc.c +memory.c +alloc.c +array.c +compare.c +ints.c +floats.c +str.c +io.c +extern.c +intern.c +hash.c +sys.c +parsing.c +gc_ctrl.c +terminfo.c +md5.c +obj.c +lexing.c +printexc.c +callback.c +weak.c +compact.c +finalise.c +custom.c +meta.c +globroots.c +unix.c +dynlink.c +signals.c diff --git a/asmrun/.depend b/asmrun/.depend new file mode 100644 index 0000000..6b66a0c --- /dev/null +++ b/asmrun/.depend @@ -0,0 +1,1164 @@ +alloc.o: alloc.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +array.o: array.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +backtrace.o: backtrace.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/backtrace.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h +callback.o: callback.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +compact.o: compact.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/weak.h ../byterun/mlvalues.h +compare.o: compare.c ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +custom.o: custom.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +dynlink.o: dynlink.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/dynlink.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/prims.h +extern.o: extern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h +fail.o: fail.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/io.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h stack.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h +finalise.o: finalise.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/signals.h \ + ../byterun/misc.h ../byterun/mlvalues.h +floats.o: floats.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +freelist.o: freelist.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +gc_ctrl.o: gc_ctrl.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/compact.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +globroots.o: globroots.c ../byterun/memory.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h +hash.o: hash.c ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +intern.o: intern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h +ints.o: ints.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/int64_native.h +io.o: io.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h +lexing.o: lexing.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +main.o: main.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/sys.h \ + ../byterun/misc.h +major_gc.o: major_gc.c ../byterun/compact.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/weak.h \ + ../byterun/mlvalues.h +md5.o: md5.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/reverse.h +memory.o: memory.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h +meta.o: meta.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/fix_code.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/interp.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/intext.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +minor_gc.o: minor_gc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/weak.h ../byterun/mlvalues.h +misc.o: misc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +natdynlink.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/alloc.h \ + ../byterun/misc.h ../byterun/mlvalues.h natdynlink.h \ + ../byterun/osdeps.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +obj.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/interp.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h +parsing.o: parsing.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/alloc.h ../byterun/misc.h ../byterun/mlvalues.h +printexc.o: printexc.c ../byterun/backtrace.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/callback.h \ + ../byterun/mlvalues.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +roots.o: roots.c ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h stack.h +signals.o: signals.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h ../byterun/sys.h ../byterun/misc.h +signals_asm.o: signals_asm.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h signals_osdep.h stack.h +startup.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/backtrace.h \ + ../byterun/mlvalues.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h natdynlink.h +str.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +sys.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/instruct.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/stacks.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/sys.h \ + ../byterun/misc.h +terminfo.o: terminfo.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h +unix.o: unix.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h +weak.o: weak.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +alloc.d.o: alloc.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +array.d.o: array.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +backtrace.d.o: backtrace.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/backtrace.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h +callback.d.o: callback.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +compact.d.o: compact.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/weak.h ../byterun/mlvalues.h +compare.d.o: compare.c ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +custom.d.o: custom.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +dynlink.d.o: dynlink.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/dynlink.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/prims.h +extern.d.o: extern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h +fail.d.o: fail.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/io.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h stack.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h +finalise.d.o: finalise.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/signals.h \ + ../byterun/misc.h ../byterun/mlvalues.h +floats.d.o: floats.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +freelist.d.o: freelist.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +gc_ctrl.d.o: gc_ctrl.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/compact.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +globroots.d.o: globroots.c ../byterun/memory.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h +hash.d.o: hash.c ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +intern.d.o: intern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h +ints.d.o: ints.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/int64_native.h +io.d.o: io.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h +lexing.d.o: lexing.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +main.d.o: main.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/sys.h \ + ../byterun/misc.h +major_gc.d.o: major_gc.c ../byterun/compact.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/weak.h \ + ../byterun/mlvalues.h +md5.d.o: md5.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/reverse.h +memory.d.o: memory.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h +meta.d.o: meta.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/fix_code.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/interp.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/intext.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +minor_gc.d.o: minor_gc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/weak.h ../byterun/mlvalues.h +misc.d.o: misc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +natdynlink.d.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/alloc.h \ + ../byterun/misc.h ../byterun/mlvalues.h natdynlink.h \ + ../byterun/osdeps.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +obj.d.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/interp.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h +parsing.d.o: parsing.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/alloc.h ../byterun/misc.h ../byterun/mlvalues.h +printexc.d.o: printexc.c ../byterun/backtrace.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/callback.h \ + ../byterun/mlvalues.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +roots.d.o: roots.c ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h stack.h +signals.d.o: signals.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h ../byterun/sys.h ../byterun/misc.h +signals_asm.d.o: signals_asm.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h signals_osdep.h stack.h +startup.d.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/backtrace.h \ + ../byterun/mlvalues.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h natdynlink.h +str.d.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +sys.d.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/instruct.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/stacks.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/sys.h \ + ../byterun/misc.h +terminfo.d.o: terminfo.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h +unix.d.o: unix.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h +weak.d.o: weak.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +alloc.p.o: alloc.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +array.p.o: array.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +backtrace.p.o: backtrace.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/backtrace.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h +callback.p.o: callback.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +compact.p.o: compact.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/weak.h ../byterun/mlvalues.h +compare.p.o: compare.c ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +custom.p.o: custom.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +dynlink.p.o: dynlink.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/dynlink.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/prims.h +extern.p.o: extern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h +fail.p.o: fail.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/io.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h stack.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h +finalise.p.o: finalise.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/signals.h \ + ../byterun/misc.h ../byterun/mlvalues.h +floats.p.o: floats.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +freelist.p.o: freelist.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +gc_ctrl.p.o: gc_ctrl.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/compact.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/stacks.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h +globroots.p.o: globroots.c ../byterun/memory.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/roots.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h +hash.p.o: hash.c ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +intern.p.o: intern.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/custom.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/reverse.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h +ints.p.o: ints.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/custom.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/intext.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/int64_native.h +io.p.o: io.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h +lexing.p.o: lexing.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +main.p.o: main.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/sys.h \ + ../byterun/misc.h +major_gc.p.o: major_gc.c ../byterun/compact.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/finalise.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc_ctrl.h ../byterun/misc.h ../byterun/weak.h \ + ../byterun/mlvalues.h +md5.p.o: md5.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/md5.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/reverse.h +memory.p.o: memory.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h +meta.p.o: meta.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/fix_code.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/interp.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/intext.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/io.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h \ + ../byterun/stacks.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/memory.h +minor_gc.p.o: minor_gc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/weak.h ../byterun/mlvalues.h +misc.p.o: misc.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h +natdynlink.p.o: natdynlink.c ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h stack.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/alloc.h \ + ../byterun/misc.h ../byterun/mlvalues.h natdynlink.h \ + ../byterun/osdeps.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +obj.p.o: obj.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/interp.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/major_gc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/prims.h +parsing.p.o: parsing.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/alloc.h ../byterun/misc.h ../byterun/mlvalues.h +printexc.p.o: printexc.c ../byterun/backtrace.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/callback.h \ + ../byterun/mlvalues.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h +roots.p.o: roots.c ../byterun/finalise.h ../byterun/roots.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/globroots.h ../byterun/mlvalues.h \ + ../byterun/roots.h stack.h +signals.p.o: signals.c ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/callback.h ../byterun/mlvalues.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/memory.h \ + ../byterun/config.h ../byterun/gc.h ../byterun/mlvalues.h \ + ../byterun/major_gc.h ../byterun/freelist.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/misc.h ../byterun/minor_gc.h \ + ../byterun/misc.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/roots.h ../byterun/misc.h ../byterun/memory.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h ../byterun/sys.h ../byterun/misc.h +signals_asm.p.o: signals_asm.c ../byterun/fail.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/mlvalues.h ../byterun/config.h ../byterun/misc.h \ + ../byterun/memory.h ../byterun/config.h ../byterun/gc.h \ + ../byterun/mlvalues.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/misc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/osdeps.h ../byterun/misc.h \ + ../byterun/signals.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/signals_machdep.h signals_osdep.h stack.h +startup.p.o: startup.c ../byterun/callback.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/../config/m.h ../byterun/../config/s.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/backtrace.h \ + ../byterun/mlvalues.h ../byterun/custom.h ../byterun/mlvalues.h \ + ../byterun/fail.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/gc_ctrl.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/major_gc.h ../byterun/freelist.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/printexc.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/sys.h ../byterun/misc.h natdynlink.h +str.p.o: str.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h +sys.p.o: sys.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/debugger.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/instruct.h ../byterun/osdeps.h \ + ../byterun/misc.h ../byterun/signals.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/stacks.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/sys.h \ + ../byterun/misc.h +terminfo.p.o: terminfo.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/alloc.h ../byterun/misc.h \ + ../byterun/config.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/fail.h ../byterun/misc.h \ + ../byterun/mlvalues.h ../byterun/io.h ../byterun/misc.h \ + ../byterun/mlvalues.h +unix.p.o: unix.c ../byterun/config.h ../byterun/../config/m.h \ + ../byterun/../config/s.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/config.h \ + ../byterun/misc.h ../byterun/config.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/minor_gc.h ../byterun/misc.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/osdeps.h \ + ../byterun/misc.h +weak.p.o: weak.c ../byterun/alloc.h ../byterun/misc.h ../byterun/config.h \ + ../byterun/../config/m.h ../byterun/../config/s.h ../byterun/mlvalues.h \ + ../byterun/config.h ../byterun/misc.h ../byterun/fail.h \ + ../byterun/misc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/freelist.h ../byterun/misc.h ../byterun/mlvalues.h \ + ../byterun/misc.h ../byterun/memory.h ../byterun/config.h \ + ../byterun/gc.h ../byterun/mlvalues.h ../byterun/major_gc.h \ + ../byterun/minor_gc.h ../byterun/misc.h ../byterun/misc.h \ + ../byterun/mlvalues.h diff --git a/asmrun/Makefile b/asmrun/Makefile new file mode 100644 index 0000000..c89b4a6 --- /dev/null +++ b/asmrun/Makefile @@ -0,0 +1,190 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.59 2007-11-15 13:21:15 frisch Exp $ + +include ../config/Makefile + +CC=$(NATIVECC) +FLAGS=-I../byterun -DCAML_NAME_SPACE -DNATIVE_CODE \ + -DTARGET_$(ARCH) -DSYS_$(SYSTEM) $(IFLEXDIR) +CFLAGS=$(FLAGS) -O $(NATIVECCCOMPOPTS) +DFLAGS=$(FLAGS) -g -DDEBUG $(NATIVECCCOMPOPTS) +PFLAGS=$(FLAGS) -pg -O -DPROFILING $(NATIVECCPROFOPTS) + +COBJS=startup.o main.o fail.o roots.o globroots.o signals.o signals_asm.o \ + misc.o freelist.o major_gc.o minor_gc.o memory.o alloc.o compare.o ints.o \ + floats.o str.o array.o io.o extern.o intern.o hash.o sys.o parsing.o \ + gc_ctrl.o terminfo.o md5.o obj.o lexing.o printexc.o callback.o weak.o \ + compact.o finalise.o custom.o unix.o backtrace.o natdynlink.o + +ASMOBJS=$(ARCH).o + +OBJS=$(COBJS) $(ASMOBJS) +DOBJS=$(COBJS:.o=.d.o) $(ASMOBJS) +POBJS=$(COBJS:.o=.p.o) $(ASMOBJS:.o=.p.o) + +all: libasmrun.a all-$(PROFILING) + +libasmrun.a: $(OBJS) + rm -f libasmrun.a + ar rc libasmrun.a $(OBJS) + $(RANLIB) libasmrun.a + +libasmrund.a: $(DOBJS) + rm -f libasmrund.a + ar rc libasmrund.a $(DOBJS) + $(RANLIB) libasmrund.a + +all-noprof: + +all-prof: libasmrunp.a + +libasmrunp.a: $(POBJS) + rm -f libasmrunp.a + ar rc libasmrunp.a $(POBJS) + $(RANLIB) libasmrunp.a + +install: install-default install-$(PROFILING) + +install-default: + cp libasmrun.a $(LIBDIR)/libasmrun.a + cd $(LIBDIR); $(RANLIB) libasmrun.a + +install-noprof: + rm -f $(LIBDIR)/libasmrunp.a; ln -s libasmrun.a $(LIBDIR)/libasmrunp.a + +install-prof: + cp libasmrunp.a $(LIBDIR)/libasmrunp.a + cd $(LIBDIR); $(RANLIB) libasmrunp.a + +power.o: power-$(SYSTEM).o + cp power-$(SYSTEM).o power.o + +power.p.o: power-$(SYSTEM).o + cp power-$(SYSTEM).o power.p.o + +main.c: ../byterun/main.c + ln -s ../byterun/main.c main.c +misc.c: ../byterun/misc.c + ln -s ../byterun/misc.c misc.c +freelist.c: ../byterun/freelist.c + ln -s ../byterun/freelist.c freelist.c +major_gc.c: ../byterun/major_gc.c + ln -s ../byterun/major_gc.c major_gc.c +minor_gc.c: ../byterun/minor_gc.c + ln -s ../byterun/minor_gc.c minor_gc.c +memory.c: ../byterun/memory.c + ln -s ../byterun/memory.c memory.c +alloc.c: ../byterun/alloc.c + ln -s ../byterun/alloc.c alloc.c +array.c: ../byterun/array.c + ln -s ../byterun/array.c array.c +compare.c: ../byterun/compare.c + ln -s ../byterun/compare.c compare.c +ints.c: ../byterun/ints.c + ln -s ../byterun/ints.c ints.c +floats.c: ../byterun/floats.c + ln -s ../byterun/floats.c floats.c +str.c: ../byterun/str.c + ln -s ../byterun/str.c str.c +io.c: ../byterun/io.c + ln -s ../byterun/io.c io.c +extern.c: ../byterun/extern.c + ln -s ../byterun/extern.c extern.c +intern.c: ../byterun/intern.c + ln -s ../byterun/intern.c intern.c +hash.c: ../byterun/hash.c + ln -s ../byterun/hash.c hash.c +sys.c: ../byterun/sys.c + ln -s ../byterun/sys.c sys.c +parsing.c: ../byterun/parsing.c + ln -s ../byterun/parsing.c parsing.c +gc_ctrl.c: ../byterun/gc_ctrl.c + ln -s ../byterun/gc_ctrl.c gc_ctrl.c +terminfo.c: ../byterun/terminfo.c + ln -s ../byterun/terminfo.c terminfo.c +md5.c: ../byterun/md5.c + ln -s ../byterun/md5.c md5.c +obj.c: ../byterun/obj.c + ln -s ../byterun/obj.c obj.c +lexing.c: ../byterun/lexing.c + ln -s ../byterun/lexing.c lexing.c +printexc.c: ../byterun/printexc.c + ln -s ../byterun/printexc.c printexc.c +callback.c: ../byterun/callback.c + ln -s ../byterun/callback.c callback.c +weak.c: ../byterun/weak.c + ln -s ../byterun/weak.c weak.c +compact.c: ../byterun/compact.c + ln -s ../byterun/compact.c compact.c +finalise.c: ../byterun/finalise.c + ln -s ../byterun/finalise.c finalise.c +custom.c: ../byterun/custom.c + ln -s ../byterun/custom.c custom.c +meta.c: ../byterun/meta.c + ln -s ../byterun/meta.c meta.c +globroots.c: ../byterun/globroots.c + ln -s ../byterun/globroots.c globroots.c +unix.c: ../byterun/unix.c + ln -s ../byterun/unix.c unix.c +dynlink.c: ../byterun/dynlink.c + ln -s ../byterun/dynlink.c dynlink.c +signals.c: ../byterun/signals.c + ln -s ../byterun/signals.c signals.c + +LINKEDFILES=misc.c freelist.c major_gc.c minor_gc.c memory.c alloc.c array.c \ + compare.c ints.c floats.c str.c io.c extern.c intern.c hash.c sys.c \ + parsing.c gc_ctrl.c terminfo.c md5.c obj.c lexing.c printexc.c callback.c \ + weak.c compact.c finalise.c meta.c custom.c main.c globroots.c unix.c \ + dynlink.c signals.c + +clean:: + rm -f $(LINKEDFILES) + +.SUFFIXES: .S .d.o .p.o + +.S.o: + $(ASPP) -DSYS_$(SYSTEM) -o $*.o $*.S || \ + { echo "If your assembler produced syntax errors, it is probably unhappy with the"; echo "preprocessor. Check your assembler, or try producing $*.o by hand."; exit 2; } + +.S.p.o: + $(ASPP) -DSYS_$(SYSTEM) $(ASPPPROFFLAGS) -o $*.p.o $*.S + +.c.d.o: + @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi + $(CC) -c $(DFLAGS) $< + mv $*.o $*.d.o + @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi + +.c.p.o: + @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi + $(CC) -c $(PFLAGS) $< + mv $*.o $*.p.o + @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi + +.s.o: + $(ASPP) -DSYS_$(SYSTEM) -o $*.o $*.s + +.s.p.o: + $(ASPP) -DSYS_$(SYSTEM) $(ASPPPROFFLAGS) -o $*.p.o $*.s + +clean:: + rm -f *.o *.a *~ + +depend: $(COBJS:.o=.c) ${LINKEDFILES} + -gcc -MM $(FLAGS) *.c > .depend + gcc -MM $(FLAGS) -DDEBUG *.c | sed -e 's/\.o/.d.o/' >> .depend + gcc -MM $(FLAGS) -DDEBUG *.c | sed -e 's/\.o/.p.o/' >> .depend + +include .depend diff --git a/asmrun/Makefile.nt b/asmrun/Makefile.nt new file mode 100644 index 0000000..f041873 --- /dev/null +++ b/asmrun/Makefile.nt @@ -0,0 +1,81 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.28 2007-11-15 13:21:15 frisch Exp $ + +include ../config/Makefile + +CC=$(NATIVECC) +CFLAGS=-I../byterun -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) $(NATIVECCCOMPOPTS) + +COBJS=startup.$(O) main.$(O) fail.$(O) roots.$(O) signals.$(O) signals_asm.$(O) \ + misc.$(O) freelist.$(O) major_gc.$(O) minor_gc.$(O) memory.$(O) alloc.$(O) \ + compare.$(O) ints.$(O) floats.$(O) str.$(O) array.$(O) io.$(O) extern.$(O) \ + intern.$(O) hash.$(O) sys.$(O) parsing.$(O) gc_ctrl.$(O) terminfo.$(O) \ + md5.$(O) obj.$(O) lexing.$(O) win32.$(O) printexc.$(O) callback.$(O) \ + weak.$(O) compact.$(O) finalise.$(O) custom.$(O) globroots.$(O) \ + backtrace.$(O) natdynlink.$(O) + +LINKEDFILES=misc.c freelist.c major_gc.c minor_gc.c memory.c alloc.c array.c \ + compare.c ints.c floats.c str.c io.c extern.c intern.c hash.c sys.c \ + parsing.c gc_ctrl.c terminfo.c md5.c obj.c lexing.c printexc.c callback.c \ + weak.c compact.c meta.c finalise.c custom.c main.c globroots.c \ + dynlink.c signals.c + +ifeq ($(TOOLCHAIN),mingw) +ASMOBJS=$(ARCH).o +else +ASMOBJS=$(ARCH)nt.obj +endif + +OBJS=$(COBJS) $(ASMOBJS) + +all: libasmrun.$(A) + +libasmrun.$(A): $(OBJS) + $(call MKLIB,libasmrun.$(A), $(OBJS)) + +i386nt.obj: i386nt.asm + $(ASM)i386nt.obj i386nt.asm + +amd64nt.obj: amd64nt.asm + $(ASM)amd64nt.obj amd64nt.asm + +i386.o: i386.S + $(CC) -c -DSYS_$(SYSTEM) i386.S + +install: + cp libasmrun.$(A) $(LIBDIR) + +$(LINKEDFILES): %.c: ../byterun/%.c + cp ../byterun/$*.c $*.c + +# Need special compilation rule so as not to do -I../byterun +win32.$(O): ../byterun/win32.c + $(CC) -c $(NATIVECCCOMPOPTS) -DNATIVE_CODE $(IFLEXDIR) ../byterun/win32.c + +.SUFFIXES: .c .$(O) + +.c.$(O): + $(CC) $(CFLAGS) -c $< + +clean:: + rm -f $(LINKEDFILES) + +clean:: + rm -f *.$(O) *.$(A) *~ + +.depend.nt: .depend + sed -e 's/\.o/.$(O)/g' .depend > .depend.nt + +include .depend.nt diff --git a/asmrun/alpha.S b/asmrun/alpha.S new file mode 100644 index 0000000..d8c2978 --- /dev/null +++ b/asmrun/alpha.S @@ -0,0 +1,440 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: alpha.S,v 1.29 2004-01-03 12:51:18 doligez Exp $ */ + +/* Asm part of the runtime system, Alpha processor */ + +/* Allocation */ + + .text + .globl caml_alloc2 + .globl caml_alloc3 + .globl caml_allocN + .globl caml_call_gc + +/* Note: the profiling code sets $27 to the address of the "normal" entrypoint. + So don't pass parameters to those routines in $27. */ + +/* caml_alloc* : all code generator registers preserved, + $gp preserved, $27 not necessarily valid on entry */ + + .globl caml_alloc1 + .ent caml_alloc1 + .align 3 +caml_alloc1: + .prologue 0 + subq $13, 16, $13 + cmpult $13, $14, $25 + bne $25, $100 + ret ($26) +$100: ldiq $25, 16 + br $110 + .end caml_alloc1 + + .globl caml_alloc2 + .ent caml_alloc2 + .align 3 +caml_alloc2: + .prologue 0 + subq $13, 24, $13 + cmpult $13, $14, $25 + bne $25, $101 + ret ($26) +$101: ldiq $25, 24 + br $110 + .end caml_alloc2 + + .globl caml_alloc3 + .ent caml_alloc3 + .align 3 +caml_alloc3: + .prologue 0 + subq $13, 32, $13 + cmpult $13, $14, $25 + bne $25, $102 + ret ($26) +$102: ldiq $25, 32 + br $110 + .end caml_alloc3 + + .globl caml_allocN + .ent caml_allocN + .align 3 +caml_allocN: + .prologue 0 + subq $13, $25, $13 + .set noat + cmpult $13, $14, $at + bne $at, $110 + .set at + ret ($26) + .end caml_allocN + + .globl caml_call_gc + .ent caml_call_gc + .align 3 +caml_call_gc: + .prologue 0 + ldiq $25, 0 +$110: lda $sp, -0x200($sp) + /* 0x200 = 32*8 (ints) + 32*8 (floats) */ + stq $26, 0x1F8($sp) /* return address */ + stq $gp, 0x1F0($sp) /* caller's $gp */ + stq $25, 0x1E8($sp) /* desired size */ + /* Rebuild $gp */ + br $27, $103 +$103: ldgp $gp, 0($27) + /* Record lowest stack address, return address, GC regs */ + stq $26, caml_last_return_address + lda $24, 0x200($sp) + stq $24, caml_bottom_of_stack + lda $24, 0x100($sp) + stq $24, caml_gc_regs + /* Save current allocation pointer for debugging purposes */ +$113: stq $13, caml_young_ptr + /* Save trap pointer in case an exception is raised (e.g. sighandler) */ + stq $15, caml_exception_pointer + /* Save all integer regs used by the code generator in the context */ + stq $0, 0 * 8 ($24) + stq $1, 1 * 8 ($24) + stq $2, 2 * 8 ($24) + stq $3, 3 * 8 ($24) + stq $4, 4 * 8 ($24) + stq $5, 5 * 8 ($24) + stq $6, 6 * 8 ($24) + stq $7, 7 * 8 ($24) + stq $8, 8 * 8 ($24) + stq $9, 9 * 8 ($24) + stq $10, 10 * 8 ($24) + stq $11, 11 * 8 ($24) + stq $12, 12 * 8 ($24) + stq $16, 16 * 8 ($24) + stq $17, 17 * 8 ($24) + stq $18, 18 * 8 ($24) + stq $19, 19 * 8 ($24) + stq $20, 20 * 8 ($24) + stq $21, 21 * 8 ($24) + stq $22, 22 * 8 ($24) + /* Save all float regs that are not callee-save on the stack */ + stt $f0, 0 * 8 ($sp) + stt $f1, 1 * 8 ($sp) + stt $f10, 10 * 8 ($sp) + stt $f11, 11 * 8 ($sp) + stt $f12, 12 * 8 ($sp) + stt $f13, 13 * 8 ($sp) + stt $f14, 14 * 8 ($sp) + stt $f15, 15 * 8 ($sp) + stt $f16, 16 * 8 ($sp) + stt $f17, 17 * 8 ($sp) + stt $f18, 18 * 8 ($sp) + stt $f19, 19 * 8 ($sp) + stt $f20, 20 * 8 ($sp) + stt $f21, 21 * 8 ($sp) + stt $f22, 22 * 8 ($sp) + stt $f23, 23 * 8 ($sp) + stt $f24, 24 * 8 ($sp) + stt $f25, 25 * 8 ($sp) + stt $f26, 26 * 8 ($sp) + stt $f27, 27 * 8 ($sp) + stt $f29, 29 * 8 ($sp) + stt $f30, 30 * 8 ($sp) + /* Call the garbage collector */ + jsr caml_garbage_collection + ldgp $gp, 0($26) + /* Restore all regs used by the code generator */ + lda $24, 0x100($sp) + ldq $0, 0 * 8 ($24) + ldq $1, 1 * 8 ($24) + ldq $2, 2 * 8 ($24) + ldq $3, 3 * 8 ($24) + ldq $4, 4 * 8 ($24) + ldq $5, 5 * 8 ($24) + ldq $6, 6 * 8 ($24) + ldq $7, 7 * 8 ($24) + ldq $8, 8 * 8 ($24) + ldq $9, 9 * 8 ($24) + ldq $10, 10 * 8 ($24) + ldq $11, 11 * 8 ($24) + ldq $12, 12 * 8 ($24) + ldq $16, 16 * 8 ($24) + ldq $17, 17 * 8 ($24) + ldq $18, 18 * 8 ($24) + ldq $19, 19 * 8 ($24) + ldq $20, 20 * 8 ($24) + ldq $21, 21 * 8 ($24) + ldq $22, 22 * 8 ($24) + ldt $f0, 0 * 8 ($sp) + ldt $f1, 1 * 8 ($sp) + ldt $f10, 10 * 8 ($sp) + ldt $f11, 11 * 8 ($sp) + ldt $f12, 12 * 8 ($sp) + ldt $f13, 13 * 8 ($sp) + ldt $f14, 14 * 8 ($sp) + ldt $f15, 15 * 8 ($sp) + ldt $f16, 16 * 8 ($sp) + ldt $f17, 17 * 8 ($sp) + ldt $f18, 18 * 8 ($sp) + ldt $f19, 19 * 8 ($sp) + ldt $f20, 20 * 8 ($sp) + ldt $f21, 21 * 8 ($sp) + ldt $f22, 22 * 8 ($sp) + ldt $f23, 23 * 8 ($sp) + ldt $f24, 24 * 8 ($sp) + ldt $f25, 25 * 8 ($sp) + ldt $f26, 26 * 8 ($sp) + ldt $f27, 27 * 8 ($sp) + ldt $f29, 29 * 8 ($sp) + ldt $f30, 30 * 8 ($sp) + /* Reload new allocation pointer and allocation limit */ + ldq $13, caml_young_ptr + ldq $14, caml_young_limit + /* Allocate space for the block */ + ldq $25, 0x1E8($sp) + subq $13, $25, $13 + cmpult $13, $14, $25 /* Check that we have enough free space */ + bne $25, $113 /* If not, call GC again */ + /* Say that we are back into Caml code */ + stq $31, caml_last_return_address + /* Return to caller */ + ldq $26, 0x1F8($sp) + ldq $gp, 0x1F0($sp) + lda $sp, 0x200($sp) + ret ($26) + + .end caml_call_gc + +/* Call a C function from Caml */ +/* Function to call is in $25 */ + + .globl caml_c_call + .ent caml_c_call + .align 3 +caml_c_call: + .prologue 0 + /* Preserve return address and caller's $gp in callee-save registers */ + mov $26, $9 + mov $gp, $10 + /* Rebuild $gp */ + br $27, $104 +$104: ldgp $gp, 0($27) + /* Record lowest stack address and return address */ + lda $11, caml_last_return_address + stq $26, 0($11) + stq $sp, caml_bottom_of_stack + /* Make the exception handler and alloc ptr available to the C code */ + lda $12, caml_young_ptr + stq $13, 0($12) + lda $14, caml_young_limit + stq $15, caml_exception_pointer + /* Call the function */ + mov $25, $27 + jsr ($25) + /* Reload alloc ptr and alloc limit */ + ldq $13, 0($12) /* $12 still points to caml_young_ptr */ + ldq $14, 0($14) /* $14 still points to caml_young_limit */ + /* Say that we are back into Caml code */ + stq $31, 0($11) /* $11 still points to caml_last_return_address */ + /* Restore $gp */ + mov $10, $gp + /* Return */ + ret ($9) + + .end caml_c_call + +/* Start the Caml program */ + + .globl caml_start_program + .ent caml_start_program + .align 3 +caml_start_program: + ldgp $gp, 0($27) + lda $25, caml_program + +/* Code shared with caml_callback* */ +$107: + /* Save return address */ + lda $sp, -128($sp) + stq $26, 0($sp) + /* Save all callee-save registers */ + stq $9, 8($sp) + stq $10, 16($sp) + stq $11, 24($sp) + stq $12, 32($sp) + stq $13, 40($sp) + stq $14, 48($sp) + stq $15, 56($sp) + stt $f2, 64($sp) + stt $f3, 72($sp) + stt $f4, 80($sp) + stt $f5, 88($sp) + stt $f6, 96($sp) + stt $f7, 104($sp) + stt $f8, 112($sp) + stt $f9, 120($sp) + /* Set up a callback link on the stack. */ + lda $sp, -32($sp) + ldq $0, caml_bottom_of_stack + stq $0, 0($sp) + ldq $1, caml_last_return_address + stq $1, 8($sp) + ldq $1, caml_gc_regs + stq $1, 16($sp) + /* Set up a trap frame to catch exceptions escaping the Caml code */ + lda $sp, -16($sp) + ldq $15, caml_exception_pointer + stq $15, 0($sp) + lda $0, $109 + stq $0, 8($sp) + mov $sp, $15 + /* Reload allocation pointers */ + ldq $13, caml_young_ptr + ldq $14, caml_young_limit + /* We are back into Caml code */ + stq $31, caml_last_return_address + /* Call the Caml code */ + mov $25, $27 +$108: jsr ($25) + /* Reload $gp, masking off low bit in retaddr (might have been marked) */ + bic $26, 1, $26 + ldgp $gp, 4($26) + /* Pop the trap frame, restoring caml_exception_pointer */ + ldq $15, 0($sp) + stq $15, caml_exception_pointer + lda $sp, 16($sp) + /* Pop the callback link, restoring the global variables */ +$112: ldq $24, 0($sp) + stq $24, caml_bottom_of_stack + ldq $25, 8($sp) + stq $25, caml_last_return_address + ldq $24, 16($sp) + stq $24, caml_gc_regs + lda $sp, 32($sp) + /* Update allocation pointer */ + stq $13, caml_young_ptr + /* Reload callee-save registers */ + ldq $9, 8($sp) + ldq $10, 16($sp) + ldq $11, 24($sp) + ldq $12, 32($sp) + ldq $13, 40($sp) + ldq $14, 48($sp) + ldq $15, 56($sp) + ldt $f2, 64($sp) + ldt $f3, 72($sp) + ldt $f4, 80($sp) + ldt $f5, 88($sp) + ldt $f6, 96($sp) + ldt $f7, 104($sp) + ldt $f8, 112($sp) + ldt $f9, 120($sp) + /* Return to caller */ + ldq $26, 0($sp) + lda $sp, 128($sp) + ret ($26) + + /* The trap handler */ +$109: ldgp $gp, 0($26) + /* Save exception pointer */ + stq $15, caml_exception_pointer + /* Encode exception bucket as an exception result */ + or $0, 2, $0 + /* Return it */ + br $112 + + .end caml_start_program + +/* Raise an exception from C */ + + .globl caml_raise_exception + .ent caml_raise_exception + .align 3 +caml_raise_exception: + ldgp $gp, 0($27) + mov $16, $0 /* Move exn bucket */ + ldq $13, caml_young_ptr + ldq $14, caml_young_limit + stq $31, caml_last_return_address /* We're back into Caml */ + ldq $sp, caml_exception_pointer + ldq $15, 0($sp) + ldq $26, 8($sp) + lda $sp, 16($sp) + jmp $25, ($26) /* Keep retaddr in $25 to help debugging */ + .end caml_raise_exception + +/* Callback from C to Caml */ + + .globl caml_callback_exn + .ent caml_callback_exn + .align 3 +caml_callback_exn: + /* Initial shuffling of arguments */ + ldgp $gp, 0($27) + mov $16, $25 + mov $17, $16 /* first arg */ + mov $25, $17 /* environment */ + ldq $25, 0($25) /* code pointer */ + br $107 + .end caml_callback_exn + + .globl caml_callback2_exn + .ent caml_callback2_exn + .align 3 +caml_callback2_exn: + ldgp $gp, 0($27) + mov $16, $25 + mov $17, $16 /* first arg */ + mov $18, $17 /* second arg */ + mov $25, $18 /* environment */ + lda $25, caml_apply2 + br $107 + .end caml_callback2_exn + + .globl caml_callback3_exn + .ent caml_callback3_exn + .align 3 +caml_callback3_exn: + ldgp $gp, 0($27) + mov $16, $25 + mov $17, $16 /* first arg */ + mov $18, $17 /* second arg */ + mov $19, $18 /* third arg */ + mov $25, $19 /* environment */ + lda $25, caml_apply3 + br $107 + .end caml_callback3_exn + +/* Glue code to call [caml_array_bound_error] */ + + .globl caml_ml_array_bound_error + .ent caml_ml_array_bound_error + .align 3 +caml_ml_array_bound_error: + br $27, $111 +$111: ldgp $gp, 0($27) + lda $25, caml_array_bound_error + br caml_c_call /* never returns */ + .end caml_ml_array_bound_error + +#if defined(SYS_digital) + .rdata +#else + .section .rodata +#endif + .globl caml_system__frametable +caml_system__frametable: + .quad 1 /* one descriptor */ + .quad $108 + 4 /* return address into callback */ + .word -1 /* negative frame size => use callback link */ + .word 0 /* no roots here */ + .align 3 diff --git a/asmrun/amd64.S b/asmrun/amd64.S new file mode 100644 index 0000000..64f53ae --- /dev/null +++ b/asmrun/amd64.S @@ -0,0 +1,392 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: amd64.S,v 1.13 2008-12-03 18:09:08 doligez Exp $ */ + +/* Asm part of the runtime system, AMD64 processor */ +/* Must be preprocessed by cpp */ + +#ifdef SYS_macosx + +#define G(r) _##r +#define FUNCTION_ALIGN 2 +#define EIGHT_ALIGN 3 +#define SIXTEEN_ALIGN 4 +#define FUNCTION(name) \ + .globl name; \ + .align FUNCTION_ALIGN; \ + name: + +#else + +#define G(r) r +#define FUNCTION_ALIGN 4 +#define EIGHT_ALIGN 8 +#define SIXTEEN_ALIGN 16 +#define FUNCTION(name) \ + .globl name; \ + .type name,@function; \ + .align FUNCTION_ALIGN; \ + name: + +#endif + + + .text + +/* Allocation */ + +FUNCTION(G(caml_call_gc)) + /* Record lowest stack address and return address */ + movq 0(%rsp), %rax + movq %rax, G(caml_last_return_address)(%rip) + leaq 8(%rsp), %rax + movq %rax, G(caml_bottom_of_stack)(%rip) +.L105: + /* Save caml_young_ptr, caml_exception_pointer */ + movq %r15, G(caml_young_ptr)(%rip) + movq %r14, G(caml_exception_pointer)(%rip) + /* Build array of registers, save it into caml_gc_regs */ + pushq %r13 + pushq %r12 + pushq %rbp + pushq %r11 + pushq %r10 + pushq %r9 + pushq %r8 + pushq %rcx + pushq %rdx + pushq %rsi + pushq %rdi + pushq %rbx + pushq %rax + movq %rsp, G(caml_gc_regs)(%rip) + /* Save floating-point registers */ + subq $(16*8), %rsp + movlpd %xmm0, 0*8(%rsp) + movlpd %xmm1, 1*8(%rsp) + movlpd %xmm2, 2*8(%rsp) + movlpd %xmm3, 3*8(%rsp) + movlpd %xmm4, 4*8(%rsp) + movlpd %xmm5, 5*8(%rsp) + movlpd %xmm6, 6*8(%rsp) + movlpd %xmm7, 7*8(%rsp) + movlpd %xmm8, 8*8(%rsp) + movlpd %xmm9, 9*8(%rsp) + movlpd %xmm10, 10*8(%rsp) + movlpd %xmm11, 11*8(%rsp) + movlpd %xmm12, 12*8(%rsp) + movlpd %xmm13, 13*8(%rsp) + movlpd %xmm14, 14*8(%rsp) + movlpd %xmm15, 15*8(%rsp) + /* Call the garbage collector */ + call G(caml_garbage_collection) + /* Restore all regs used by the code generator */ + movlpd 0*8(%rsp), %xmm0 + movlpd 1*8(%rsp), %xmm1 + movlpd 2*8(%rsp), %xmm2 + movlpd 3*8(%rsp), %xmm3 + movlpd 4*8(%rsp), %xmm4 + movlpd 5*8(%rsp), %xmm5 + movlpd 6*8(%rsp), %xmm6 + movlpd 7*8(%rsp), %xmm7 + movlpd 8*8(%rsp), %xmm8 + movlpd 9*8(%rsp), %xmm9 + movlpd 10*8(%rsp), %xmm10 + movlpd 11*8(%rsp), %xmm11 + movlpd 12*8(%rsp), %xmm12 + movlpd 13*8(%rsp), %xmm13 + movlpd 14*8(%rsp), %xmm14 + movlpd 15*8(%rsp), %xmm15 + addq $(16*8), %rsp + popq %rax + popq %rbx + popq %rdi + popq %rsi + popq %rdx + popq %rcx + popq %r8 + popq %r9 + popq %r10 + popq %r11 + popq %rbp + popq %r12 + popq %r13 + /* Restore caml_young_ptr, caml_exception_pointer */ + movq G(caml_young_ptr)(%rip), %r15 + movq G(caml_exception_pointer)(%rip), %r14 + /* Return to caller */ + ret + +FUNCTION(G(caml_alloc1)) + subq $16, %r15 + cmpq G(caml_young_limit)(%rip), %r15 + jb .L100 + ret +.L100: + movq 0(%rsp), %rax + movq %rax, G(caml_last_return_address)(%rip) + leaq 8(%rsp), %rax + movq %rax, G(caml_bottom_of_stack)(%rip) + subq $8, %rsp + call .L105 + addq $8, %rsp + jmp G(caml_alloc1) + +FUNCTION(G(caml_alloc2)) + subq $24, %r15 + cmpq G(caml_young_limit)(%rip), %r15 + jb .L101 + ret +.L101: + movq 0(%rsp), %rax + movq %rax, G(caml_last_return_address)(%rip) + leaq 8(%rsp), %rax + movq %rax, G(caml_bottom_of_stack)(%rip) + subq $8, %rsp + call .L105 + addq $8, %rsp + jmp G(caml_alloc2) + +FUNCTION(G(caml_alloc3)) + subq $32, %r15 + cmpq G(caml_young_limit)(%rip), %r15 + jb .L102 + ret +.L102: + movq 0(%rsp), %rax + movq %rax, G(caml_last_return_address)(%rip) + leaq 8(%rsp), %rax + movq %rax, G(caml_bottom_of_stack)(%rip) + subq $8, %rsp + call .L105 + addq $8, %rsp + jmp G(caml_alloc3) + +FUNCTION(G(caml_allocN)) + subq %rax, %r15 + cmpq G(caml_young_limit)(%rip), %r15 + jb .L103 + ret +.L103: + pushq %rax /* save desired size */ + movq 8(%rsp), %rax + movq %rax, G(caml_last_return_address)(%rip) + leaq 16(%rsp), %rax + movq %rax, G(caml_bottom_of_stack)(%rip) + call .L105 + popq %rax /* recover desired size */ + jmp G(caml_allocN) + +/* Call a C function from Caml */ + +FUNCTION(G(caml_c_call)) + /* Record lowest stack address and return address */ + popq %r12 + movq %r12, G(caml_last_return_address)(%rip) + movq %rsp, G(caml_bottom_of_stack)(%rip) + /* Make the exception handler and alloc ptr available to the C code */ + movq %r15, G(caml_young_ptr)(%rip) + movq %r14, G(caml_exception_pointer)(%rip) + /* Call the function (address in %rax) */ + call *%rax + /* Reload alloc ptr */ + movq G(caml_young_ptr)(%rip), %r15 + /* Return to caller */ + pushq %r12 + ret + +/* Start the Caml program */ + +FUNCTION(G(caml_start_program)) + /* Save callee-save registers */ + pushq %rbx + pushq %rbp + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + subq $8, %rsp /* stack 16-aligned */ + /* Initial entry point is G(caml_program) */ + leaq G(caml_program)(%rip), %r12 + /* Common code for caml_start_program and caml_callback* */ +.L106: + /* Build a callback link */ + subq $8, %rsp /* stack 16-aligned */ + pushq G(caml_gc_regs)(%rip) + pushq G(caml_last_return_address)(%rip) + pushq G(caml_bottom_of_stack)(%rip) + /* Setup alloc ptr and exception ptr */ + movq G(caml_young_ptr)(%rip), %r15 + movq G(caml_exception_pointer)(%rip), %r14 + /* Build an exception handler */ + lea .L108(%rip), %r13 + pushq %r13 + pushq %r14 + movq %rsp, %r14 + /* Call the Caml code */ + call *%r12 +.L107: + /* Pop the exception handler */ + popq %r14 + popq %r12 /* dummy register */ +.L109: + /* Update alloc ptr and exception ptr */ + movq %r15, G(caml_young_ptr)(%rip) + movq %r14, G(caml_exception_pointer)(%rip) + /* Pop the callback link, restoring the global variables */ + popq G(caml_bottom_of_stack)(%rip) + popq G(caml_last_return_address)(%rip) + popq G(caml_gc_regs)(%rip) + addq $8, %rsp + /* Restore callee-save registers. */ + addq $8, %rsp + popq %r15 + popq %r14 + popq %r13 + popq %r12 + popq %rbp + popq %rbx + /* Return to caller. */ + ret +.L108: + /* Exception handler*/ + /* Mark the bucket as an exception result and return it */ + orq $2, %rax + jmp .L109 + +/* Raise an exception from Caml */ + +FUNCTION(G(caml_raise_exn)) + testl $1, G(caml_backtrace_active)(%rip) + jne .L110 + movq %r14, %rsp + popq %r14 + ret +.L110: + movq %rax, %r12 /* Save exception bucket */ + movq %rax, %rdi /* arg 1: exception bucket */ + movq 0(%rsp), %rsi /* arg 2: pc of raise */ + leaq 8(%rsp), %rdx /* arg 3: sp of raise */ + movq %r14, %rcx /* arg 4: sp of handler */ + call G(caml_stash_backtrace) + movq %r12, %rax /* Recover exception bucket */ + movq %r14, %rsp + popq %r14 + ret + +/* Raise an exception from C */ + +FUNCTION(G(caml_raise_exception)) + testl $1, G(caml_backtrace_active)(%rip) + jne .L111 + movq %rdi, %rax + movq G(caml_exception_pointer)(%rip), %rsp + popq %r14 /* Recover previous exception handler */ + movq G(caml_young_ptr)(%rip), %r15 /* Reload alloc ptr */ + ret +.L111: + movq %rdi, %r12 /* Save exception bucket */ + /* arg 1: exception bucket */ + movq G(caml_last_return_address)(%rip), %rsi /* arg 2: pc of raise */ + movq G(caml_bottom_of_stack)(%rip), %rdx /* arg 3: sp of raise */ + movq G(caml_exception_pointer)(%rip), %rcx /* arg 4: sp of handler */ + call G(caml_stash_backtrace) + movq %r12, %rax /* Recover exception bucket */ + movq G(caml_exception_pointer)(%rip), %rsp + popq %r14 /* Recover previous exception handler */ + movq G(caml_young_ptr)(%rip), %r15 /* Reload alloc ptr */ + ret + +/* Callback from C to Caml */ + +FUNCTION(G(caml_callback_exn)) + /* Save callee-save registers */ + pushq %rbx + pushq %rbp + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + subq $8, %rsp /* stack 16-aligned */ + /* Initial loading of arguments */ + movq %rdi, %rbx /* closure */ + movq %rsi, %rax /* argument */ + movq 0(%rbx), %r12 /* code pointer */ + jmp .L106 + +FUNCTION(G(caml_callback2_exn)) + /* Save callee-save registers */ + pushq %rbx + pushq %rbp + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + subq $8, %rsp /* stack 16-aligned */ + /* Initial loading of arguments */ + /* closure stays in %rdi */ + movq %rsi, %rax /* first argument */ + movq %rdx, %rbx /* second argument */ + leaq G(caml_apply2)(%rip), %r12 /* code pointer */ + jmp .L106 + +FUNCTION(G(caml_callback3_exn)) + /* Save callee-save registers */ + pushq %rbx + pushq %rbp + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + subq $8, %rsp /* stack 16-aligned */ + /* Initial loading of arguments */ + movq %rsi, %rax /* first argument */ + movq %rdx, %rbx /* second argument */ + movq %rdi, %rsi /* closure */ + movq %rcx, %rdi /* third argument */ + leaq G(caml_apply3)(%rip), %r12 /* code pointer */ + jmp .L106 + +FUNCTION(G(caml_ml_array_bound_error)) + leaq G(caml_array_bound_error)(%rip), %rax + jmp G(caml_c_call) + + .data + .globl G(caml_system__frametable) + .align EIGHT_ALIGN +G(caml_system__frametable): + .quad 1 /* one descriptor */ + .quad .L107 /* return address into callback */ + .value -1 /* negative frame size => use callback link */ + .value 0 /* no roots here */ + .align EIGHT_ALIGN + +#ifdef SYS_macosx + .literal16 +#else + .section .rodata.cst8,"a",@progbits +#endif + .globl G(caml_negf_mask) + .align SIXTEEN_ALIGN +G(caml_negf_mask): + .quad 0x8000000000000000, 0 + .globl G(caml_absf_mask) + .align SIXTEEN_ALIGN +G(caml_absf_mask): + .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF + +#if defined(SYS_linux) + /* Mark stack as non-executable, PR#4564 */ + .section .note.GNU-stack,"",%progbits +#endif diff --git a/asmrun/amd64nt.asm b/asmrun/amd64nt.asm new file mode 100644 index 0000000..c24227c --- /dev/null +++ b/asmrun/amd64nt.asm @@ -0,0 +1,464 @@ +;********************************************************************* +; +; Objective Caml +; +; Xavier Leroy, projet Gallium, INRIA Rocquencourt +; +; Copyright 2006 Institut National de Recherche en Informatique et +; en Automatique. All rights reserved. This file is distributed +; under the terms of the GNU Library General Public License, with +; the special exception on linking described in file ../LICENSE. +; +;********************************************************************* + +; $Id: amd64nt.asm,v 1.5 2007-03-01 10:26:51 xleroy Exp $ + +; Asm part of the runtime system, AMD64 processor, Intel syntax + +; Notes on Win64 calling conventions: +; function arguments in RCX, RDX, R8, R9 / XMM0 - XMM3 +; caller must reserve 32 bytes of stack space +; callee must preserve RBX, RBP, RSI, RDI, R12-R15, XMM6-XMM15 + + EXTRN caml_garbage_collection: NEAR + EXTRN caml_apply2: NEAR + EXTRN caml_apply3: NEAR + EXTRN caml_program: NEAR + EXTRN caml_array_bound_error: NEAR + EXTRN caml_young_limit: QWORD + EXTRN caml_young_ptr: QWORD + EXTRN caml_bottom_of_stack: QWORD + EXTRN caml_last_return_address: QWORD + EXTRN caml_gc_regs: QWORD + EXTRN caml_exception_pointer: QWORD + EXTRN caml_backtrace_active: DWORD + EXTRN caml_stash_backtrace: NEAR + + .CODE + +; Allocation + + PUBLIC caml_call_gc + ALIGN 16 +caml_call_gc: + ; Record lowest stack address and return address + mov rax, [rsp] + mov caml_last_return_address, rax + lea rax, [rsp+8] + mov caml_bottom_of_stack, rax +L105: + ; Save caml_young_ptr, caml_exception_pointer + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 + ; Build array of registers, save it into caml_gc_regs + push r13 + push r12 + push rbp + push r11 + push r10 + push r9 + push r8 + push rcx + push rdx + push rsi + push rdi + push rbx + push rax + mov caml_gc_regs, rsp + ; Save floating-point registers + sub rsp, 16*8 + movlpd QWORD PTR [rsp + 0*8], xmm0 + movlpd QWORD PTR [rsp + 1*8], xmm1 + movlpd QWORD PTR [rsp + 2*8], xmm2 + movlpd QWORD PTR [rsp + 3*8], xmm3 + movlpd QWORD PTR [rsp + 4*8], xmm4 + movlpd QWORD PTR [rsp + 5*8], xmm5 + movlpd QWORD PTR [rsp + 6*8], xmm6 + movlpd QWORD PTR [rsp + 7*8], xmm7 + movlpd QWORD PTR [rsp + 8*8], xmm8 + movlpd QWORD PTR [rsp + 9*8], xmm9 + movlpd QWORD PTR [rsp + 10*8], xmm10 + movlpd QWORD PTR [rsp + 11*8], xmm11 + movlpd QWORD PTR [rsp + 12*8], xmm12 + movlpd QWORD PTR [rsp + 13*8], xmm13 + movlpd QWORD PTR [rsp + 14*8], xmm14 + movlpd QWORD PTR [rsp + 15*8], xmm15 + ; Call the garbage collector + call caml_garbage_collection + ; Restore all regs used by the code generator + movlpd xmm0, QWORD PTR [rsp + 0*8] + movlpd xmm1, QWORD PTR [rsp + 1*8] + movlpd xmm2, QWORD PTR [rsp + 2*8] + movlpd xmm3, QWORD PTR [rsp + 3*8] + movlpd xmm4, QWORD PTR [rsp + 4*8] + movlpd xmm5, QWORD PTR [rsp + 5*8] + movlpd xmm6, QWORD PTR [rsp + 6*8] + movlpd xmm7, QWORD PTR [rsp + 7*8] + movlpd xmm8, QWORD PTR [rsp + 8*8] + movlpd xmm9, QWORD PTR [rsp + 9*8] + movlpd xmm10, QWORD PTR [rsp + 10*8] + movlpd xmm11, QWORD PTR [rsp + 11*8] + movlpd xmm12, QWORD PTR [rsp + 12*8] + movlpd xmm13, QWORD PTR [rsp + 13*8] + movlpd xmm14, QWORD PTR [rsp + 14*8] + movlpd xmm15, QWORD PTR [rsp + 15*8] + add rsp, 16*8 + pop rax + pop rbx + pop rdi + pop rsi + pop rdx + pop rcx + pop r8 + pop r9 + pop r10 + pop r11 + pop rbp + pop r12 + pop r13 + ; Restore caml_young_ptr, caml_exception_pointer + mov r15, caml_young_ptr + mov r14, caml_exception_pointer + ; Return to caller + ret + + PUBLIC caml_alloc1 + ALIGN 16 +caml_alloc1: + sub r15, 16 + cmp r15, caml_young_limit + jb L100 + ret +L100: + mov rax, [rsp + 0] + mov caml_last_return_address, rax + lea rax, [rsp + 8] + mov caml_bottom_of_stack, rax + sub rsp, 8 + call L105 + add rsp, 8 + jmp caml_alloc1 + + PUBLIC caml_alloc2 + ALIGN 16 +caml_alloc2: + sub r15, 24 + cmp r15, caml_young_limit + jb L101 + ret +L101: + mov rax, [rsp + 0] + mov caml_last_return_address, rax + lea rax, [rsp + 8] + mov caml_bottom_of_stack, rax + sub rsp, 8 + call L105 + add rsp, 8 + jmp caml_alloc2 + + PUBLIC caml_alloc3 + ALIGN 16 +caml_alloc3: + sub r15, 32 + cmp r15, caml_young_limit + jb L102 + ret +L102: + mov rax, [rsp + 0] + mov caml_last_return_address, rax + lea rax, [rsp + 8] + mov caml_bottom_of_stack, rax + sub rsp, 8 + call L105 + add rsp, 8 + jmp caml_alloc3 + + PUBLIC caml_allocN + ALIGN 16 +caml_allocN: + sub r15, rax + cmp r15, caml_young_limit + jb L103 + ret +L103: + push rax ; save desired size + mov rax, [rsp + 8] + mov caml_last_return_address, rax + lea rax, [rsp + 16] + mov caml_bottom_of_stack, rax + call L105 + pop rax ; recover desired size + jmp caml_allocN + +; Call a C function from Caml + + PUBLIC caml_c_call + ALIGN 16 +caml_c_call: + ; Record lowest stack address and return address + pop r12 + mov caml_last_return_address, r12 + mov caml_bottom_of_stack, rsp + ; Make the exception handler and alloc ptr available to the C code + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 + ; Call the function (address in rax) + call rax + ; Reload alloc ptr + mov r15, caml_young_ptr + ; Return to caller + push r12 + ret + +; Start the Caml program + + PUBLIC caml_start_program + ALIGN 16 +caml_start_program: + ; Save callee-save registers + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 8+10*16 ; stack 16-aligned + 10 saved xmm regs + movapd OWORD PTR [rsp + 0*16], xmm6 + movapd OWORD PTR [rsp + 1*16], xmm7 + movapd OWORD PTR [rsp + 2*16], xmm8 + movapd OWORD PTR [rsp + 3*16], xmm9 + movapd OWORD PTR [rsp + 4*16], xmm10 + movapd OWORD PTR [rsp + 5*16], xmm11 + movapd OWORD PTR [rsp + 6*16], xmm12 + movapd OWORD PTR [rsp + 7*16], xmm13 + movapd OWORD PTR [rsp + 8*16], xmm14 + movapd OWORD PTR [rsp + 9*16], xmm15 + ; Initial entry point is caml_program + lea r12, caml_program + ; Common code for caml_start_program and caml_callback* +L106: + ; Build a callback link + sub rsp, 8 ; stack 16-aligned + push caml_gc_regs + push caml_last_return_address + push caml_bottom_of_stack + ; Setup alloc ptr and exception ptr + mov r15, caml_young_ptr + mov r14, caml_exception_pointer + ; Build an exception handler + lea r13, L108 + push r13 + push r14 + mov r14, rsp + ; Call the Caml code + call r12 +L107: + ; Pop the exception handler + pop r14 + pop r12 ; dummy register +L109: + ; Update alloc ptr and exception ptr + mov caml_young_ptr, r15 + mov caml_exception_pointer, r14 + ; Pop the callback restoring, link the global variables + pop caml_bottom_of_stack + pop caml_last_return_address + pop caml_gc_regs + add rsp, 8 + ; Restore callee-save registers. + movapd xmm6, OWORD PTR [rsp + 0*16] + movapd xmm7, OWORD PTR [rsp + 1*16] + movapd xmm8, OWORD PTR [rsp + 2*16] + movapd xmm9, OWORD PTR [rsp + 3*16] + movapd xmm10, OWORD PTR [rsp + 4*16] + movapd xmm11, OWORD PTR [rsp + 5*16] + movapd xmm12, OWORD PTR [rsp + 6*16] + movapd xmm13, OWORD PTR [rsp + 7*16] + movapd xmm14, OWORD PTR [rsp + 8*16] + movapd xmm15, OWORD PTR [rsp + 9*16] + add rsp, 8+10*16 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + pop rbx + ; Return to caller + ret +L108: + ; Exception handler + ; Mark the bucket as an exception result and return it + or rax, 2 + jmp L109 + +; Raise an exception from Caml + + PUBLIC caml_raise_exn + ALIGN 16 +caml_raise_exn: + test caml_backtrace_active, 1 + jne L110 + mov rsp, r14 ; Cut stack + pop r14 ; Recover previous exception handler + ret ; Branch to handler +L110: + mov r12, rax ; Save exception bucket in r12 + mov rcx, rax ; Arg 1: exception bucket + mov rdx, [rsp] ; Arg 2: PC of raise + lea r8, [rsp+8] ; Arg 3: SP of raise + mov r9, r14 ; Arg 4: SP of handler + sub rsp, 32 ; Reserve 32 bytes on stack + call caml_stash_backtrace + mov rax, r12 ; Recover exception bucket + mov rsp, r14 ; Cut stack + pop r14 ; Recover previous exception handler + ret ; Branch to handler + +; Raise an exception from C + + PUBLIC caml_raise_exception + ALIGN 16 +caml_raise_exception: + test caml_backtrace_active, 1 + jne L111 + mov rax, rcx ; First argument is exn bucket + mov rsp, caml_exception_pointer + pop r14 ; Recover previous exception handler + mov r15, caml_young_ptr ; Reload alloc ptr + ret +L111: + mov r12, rcx ; Save exception bucket in r12 + ; Arg 1: exception bucket + mov rdx, caml_last_return_address ; Arg 2: PC of raise + mov r8, caml_bottom_of_stack ; Arg 3: SP of raise + mov r9, caml_exception_pointer ; Arg 4: SP of handler + sub rsp, 32 ; Reserve 32 bytes on stack + call caml_stash_backtrace + mov rax, r12 ; Recover exception bucket + mov rsp, caml_exception_pointer + pop r14 ; Recover previous exception handler + mov r15, caml_young_ptr ; Reload alloc ptr + ret + +; Callback from C to Caml + + PUBLIC caml_callback_exn + ALIGN 16 +caml_callback_exn: + ; Save callee-save registers + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 8+10*16 ; stack 16-aligned + 10 saved xmm regs + movapd OWORD PTR [rsp + 0*16], xmm6 + movapd OWORD PTR [rsp + 1*16], xmm7 + movapd OWORD PTR [rsp + 2*16], xmm8 + movapd OWORD PTR [rsp + 3*16], xmm9 + movapd OWORD PTR [rsp + 4*16], xmm10 + movapd OWORD PTR [rsp + 5*16], xmm11 + movapd OWORD PTR [rsp + 6*16], xmm12 + movapd OWORD PTR [rsp + 7*16], xmm13 + movapd OWORD PTR [rsp + 8*16], xmm14 + movapd OWORD PTR [rsp + 9*16], xmm15 + ; Initial loading of arguments + mov rbx, rcx ; closure + mov rax, rdx ; argument + mov r12, [rbx] ; code pointer + jmp L106 + + PUBLIC caml_callback2_exn + ALIGN 16 +caml_callback2_exn: + ; Save callee-save registers + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 8+10*16 ; stack 16-aligned + 10 saved xmm regs + movapd OWORD PTR [rsp + 0*16], xmm6 + movapd OWORD PTR [rsp + 1*16], xmm7 + movapd OWORD PTR [rsp + 2*16], xmm8 + movapd OWORD PTR [rsp + 3*16], xmm9 + movapd OWORD PTR [rsp + 4*16], xmm10 + movapd OWORD PTR [rsp + 5*16], xmm11 + movapd OWORD PTR [rsp + 6*16], xmm12 + movapd OWORD PTR [rsp + 7*16], xmm13 + movapd OWORD PTR [rsp + 8*16], xmm14 + movapd OWORD PTR [rsp + 9*16], xmm15 + ; Initial loading of arguments + mov rdi, rcx ; closure + mov rax, rdx ; first argument + mov rbx, r8 ; second argument + lea r12, caml_apply2 ; code pointer + jmp L106 + + PUBLIC caml_callback3_exn + ALIGN 16 +caml_callback3_exn: + ; Save callee-save registers + push rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 8+10*16 ; stack 16-aligned + 10 saved xmm regs + movapd OWORD PTR [rsp + 0*16], xmm6 + movapd OWORD PTR [rsp + 1*16], xmm7 + movapd OWORD PTR [rsp + 2*16], xmm8 + movapd OWORD PTR [rsp + 3*16], xmm9 + movapd OWORD PTR [rsp + 4*16], xmm10 + movapd OWORD PTR [rsp + 5*16], xmm11 + movapd OWORD PTR [rsp + 6*16], xmm12 + movapd OWORD PTR [rsp + 7*16], xmm13 + movapd OWORD PTR [rsp + 8*16], xmm14 + movapd OWORD PTR [rsp + 9*16], xmm15 + ; Initial loading of arguments + mov rsi, rcx ; closure + mov rax, rdx ; first argument + mov rbx, r8 ; second argument + mov rdi, r9 ; third argument + lea r12, caml_apply3 ; code pointer + jmp L106 + + PUBLIC caml_ml_array_bound_error + ALIGN 16 +caml_ml_array_bound_error: + lea rax, caml_array_bound_error + jmp caml_c_call + + .DATA + PUBLIC caml_system__frametable +caml_system__frametable LABEL QWORD + QWORD 1 ; one descriptor + QWORD L107 ; return address into callback + WORD -1 ; negative frame size => use callback link + WORD 0 ; no roots here + ALIGN 8 + + PUBLIC caml_negf_mask + ALIGN 16 +caml_negf_mask LABEL QWORD + QWORD 8000000000000000H, 0 + + PUBLIC caml_absf_mask + ALIGN 16 +caml_absf_mask LABEL QWORD + QWORD 7FFFFFFFFFFFFFFFH, 0FFFFFFFFFFFFFFFFH + + END diff --git a/asmrun/arm.S b/asmrun/arm.S new file mode 100644 index 0000000..8e03c42 --- /dev/null +++ b/asmrun/arm.S @@ -0,0 +1,344 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: arm.S,v 1.16 2008-02-29 14:21:21 doligez Exp $ */ + +/* Asm part of the runtime system, ARM processor */ + +trap_ptr .req r11 +alloc_ptr .req r8 +alloc_limit .req r9 +sp .req r13 +lr .req r14 +pc .req r15 + + .text + +/* Allocation functions and GC interface */ + + .global caml_call_gc +caml_call_gc: + /* Record return address */ + /* We can use r10 as a temp reg since it's not live here */ + ldr r10, .Lcaml_last_return_address + str lr, [r10, #0] + /* Branch to shared GC code */ + bl .Linvoke_gc + /* Restart allocation sequence (4 instructions before) */ + sub lr, lr, #16 + mov pc, lr + + .global caml_alloc1 +caml_alloc1: + ldr r10, [alloc_limit, #0] + sub alloc_ptr, alloc_ptr, #8 + cmp alloc_ptr, r10 + movcs pc, lr /* Return if alloc_ptr >= alloc_limit */ + /* Record return address */ + ldr r10, .Lcaml_last_return_address + str lr, [r10, #0] + /* Invoke GC */ + bl .Linvoke_gc + /* Try again */ + b caml_alloc1 + + .global caml_alloc2 +caml_alloc2: + ldr r10, [alloc_limit, #0] + sub alloc_ptr, alloc_ptr, #12 + cmp alloc_ptr, r10 + movcs pc, lr /* Return if alloc_ptr >= alloc_limit */ + /* Record return address */ + ldr r10, .Lcaml_last_return_address + str lr, [r10, #0] + /* Invoke GC */ + bl .Linvoke_gc + /* Try again */ + b caml_alloc2 + + .global caml_alloc3 +caml_alloc3: + ldr r10, [alloc_limit, #0] + sub alloc_ptr, alloc_ptr, #16 + cmp alloc_ptr, r10 + movcs pc, lr /* Return if alloc_ptr >= alloc_limit */ + /* Record return address */ + ldr r10, .Lcaml_last_return_address + str lr, [r10, #0] + /* Invoke GC */ + bl .Linvoke_gc + /* Try again */ + b caml_alloc3 + + .global caml_allocN +caml_allocN: + str r12, [sp, #-4]! + ldr r12, [alloc_limit, #0] + sub alloc_ptr, alloc_ptr, r10 + cmp alloc_ptr, r12 + ldr r12, [sp], #4 + movcs pc, lr /* Return if alloc_ptr >= alloc_limit */ + /* Record return address and desired size */ + ldr alloc_limit, .Lcaml_last_return_address + str lr, [alloc_limit, #0] + ldr alloc_limit, .LLcaml_requested_size + str r10, [alloc_limit, #0] + /* Invoke GC */ + bl .Linvoke_gc + /* Try again */ + ldr r10, .LLcaml_requested_size + ldr r10, [r10, #0] + b caml_allocN + +/* Shared code to invoke the GC */ +.Linvoke_gc: + /* Record lowest stack address */ + ldr r10, .Lcaml_bottom_of_stack + str sp, [r10, #0] + /* Save integer registers and return address on stack */ + stmfd sp!, {r0,r1,r2,r3,r4,r5,r6,r7,r10,r12,lr} + /* Store pointer to saved integer registers in caml_gc_regs */ + ldr r10, .Lcaml_gc_regs + str sp, [r10, #0] + /* Save non-callee-save float registers */ + stfd f0, [sp, #-8]! + stfd f1, [sp, #-8]! + stfd f2, [sp, #-8]! + stfd f3, [sp, #-8]! + /* Save current allocation pointer for debugging purposes */ + ldr r10, .Lcaml_young_ptr + str alloc_ptr, [r10, #0] + /* Save trap pointer in case an exception is raised during GC */ + ldr r10, .Lcaml_exception_pointer + str trap_ptr, [r10, #0] + /* Call the garbage collector */ + bl caml_garbage_collection + /* Restore the registers from the stack */ + ldfd f4, [sp], #8 + ldfd f5, [sp], #8 + ldfd f6, [sp], #8 + ldfd f7, [sp], #8 + ldmfd sp!, {r0,r1,r2,r3,r4,r5,r6,r7,r10,r12} + /* Reload return address */ + ldr r10, .Lcaml_last_return_address + ldr lr, [r10, #0] + /* Say that we are back into Caml code */ + mov alloc_ptr, #0 + str alloc_ptr, [r10, #0] + /* Reload new allocation pointer and allocation limit */ + ldr r10, .Lcaml_young_ptr + ldr alloc_ptr, [r10, #0] + ldr alloc_limit, .Lcaml_young_limit + /* Return to caller */ + ldmfd sp!, {pc} + +/* Call a C function from Caml */ +/* Function to call is in r10 */ + + .global caml_c_call +caml_c_call: + /* Preserve return address in callee-save register r4 */ + mov r4, lr + /* Record lowest stack address and return address */ + ldr r5, .Lcaml_last_return_address + ldr r6, .Lcaml_bottom_of_stack + str lr, [r5, #0] + str sp, [r6, #0] + /* Make the exception handler and alloc ptr available to the C code */ + ldr r6, .Lcaml_young_ptr + ldr r7, .Lcaml_exception_pointer + str alloc_ptr, [r6, #0] + str trap_ptr, [r7, #0] + /* Call the function */ + mov lr, pc + mov pc, r10 + /* Reload alloc ptr */ + ldr alloc_ptr, [r6, #0] /* r6 still points to caml_young_ptr */ + /* Say that we are back into Caml code */ + mov r6, #0 + str r6, [r5, #0] /* r5 still points to caml_last_return_address */ + /* Return */ + mov pc, r4 + +/* Start the Caml program */ + + .global caml_start_program +caml_start_program: + ldr r10, .Lcaml_program + +/* Code shared with caml_callback* */ +/* Address of Caml code to call is in r10 */ +/* Arguments to the Caml code are in r0...r3 */ + +.Ljump_to_caml: + /* Save return address and callee-save registers */ + stmfd sp!, {r4,r5,r6,r7,r8,r9,r11,lr} + stfd f7, [sp, #-8]! + stfd f6, [sp, #-8]! + stfd f5, [sp, #-8]! + stfd f4, [sp, #-8]! + /* Setup a callback link on the stack */ + sub sp, sp, #4*3 + ldr r4, .Lcaml_bottom_of_stack + ldr r4, [r4, #0] + str r4, [sp, #0] + ldr r4, .Lcaml_last_return_address + ldr r4, [r4, #0] + str r4, [sp, #4] + ldr r4, .Lcaml_gc_regs + ldr r4, [r4, #0] + str r4, [sp, #8] + /* Setup a trap frame to catch exceptions escaping the Caml code */ + sub sp, sp, #4*2 + ldr r4, .Lcaml_exception_pointer + ldr r4, [r4, #0] + str r4, [sp, #0] + ldr r4, .LLtrap_handler + str r4, [sp, #4] + mov trap_ptr, sp + /* Reload allocation pointers */ + ldr r4, .Lcaml_young_ptr + ldr alloc_ptr, [r4, #0] + ldr alloc_limit, .Lcaml_young_limit + /* We are back into Caml code */ + ldr r4, .Lcaml_last_return_address + mov r5, #0 + str r5, [r4, #0] + /* Call the Caml code */ + mov lr, pc + mov pc, r10 +.Lcaml_retaddr: + /* Pop the trap frame, restoring caml_exception_pointer */ + ldr r4, .Lcaml_exception_pointer + ldr r5, [sp, #0] + str r5, [r4, #0] + add sp, sp, #2 * 4 + /* Pop the callback link, restoring the global variables */ +.Lreturn_result: + ldr r4, .Lcaml_bottom_of_stack + ldr r5, [sp, #0] + str r5, [r4, #0] + ldr r4, .Lcaml_last_return_address + ldr r5, [sp, #4] + str r5, [r4, #0] + ldr r4, .Lcaml_gc_regs + ldr r5, [sp, #8] + str r5, [r4, #0] + add sp, sp, #4*3 + /* Update allocation pointer */ + ldr r4, .Lcaml_young_ptr + str alloc_ptr, [r4, #0] + /* Reload callee-save registers and return */ + ldfd f4, [sp], #8 + ldfd f5, [sp], #8 + ldfd f6, [sp], #8 + ldfd f7, [sp], #8 + ldmfd sp!, {r4,r5,r6,r7,r8,r9,r11,pc} + + /* The trap handler */ +.Ltrap_handler: + /* Save exception pointer */ + ldr r4, .Lcaml_exception_pointer + str trap_ptr, [r4, #0] + /* Encode exception bucket as an exception result */ + orr r0, r0, #2 + /* Return it */ + b .Lreturn_result + +/* Raise an exception from C */ + + .global caml_raise_exception +caml_raise_exception: + /* Reload Caml allocation pointers */ + ldr r1, .Lcaml_young_ptr + ldr alloc_ptr, [r1, #0] + ldr alloc_limit, .Lcaml_young_limit + /* Say we're back into Caml */ + ldr r1, .Lcaml_last_return_address + mov r2, #0 + str r2, [r1, #0] + /* Cut stack at current trap handler */ + ldr r1, .Lcaml_exception_pointer + ldr sp, [r1, #0] + /* Pop previous handler and addr of trap, and jump to it */ + ldmfd sp!, {trap_ptr, pc} + +/* Callback from C to Caml */ + + .global caml_callback_exn +caml_callback_exn: + /* Initial shuffling of arguments (r0 = closure, r1 = first arg) */ + mov r10, r0 + mov r0, r1 /* r0 = first arg */ + mov r1, r10 /* r1 = closure environment */ + ldr r10, [r10, #0] /* code pointer */ + b .Ljump_to_caml + + .global caml_callback2_exn +caml_callback2_exn: + /* Initial shuffling of arguments (r0 = closure, r1 = arg1, r2 = arg2) */ + mov r10, r0 + mov r0, r1 /* r0 = first arg */ + mov r1, r2 /* r1 = second arg */ + mov r2, r10 /* r2 = closure environment */ + ldr r10, .Lcaml_apply2 + b .Ljump_to_caml + + .global caml_callback3_exn +caml_callback3_exn: + /* Initial shuffling of arguments */ + /* (r0 = closure, r1 = arg1, r2 = arg2, r3 = arg3) */ + mov r10, r0 + mov r0, r1 /* r0 = first arg */ + mov r1, r2 /* r1 = second arg */ + mov r2, r3 /* r2 = third arg */ + mov r3, r10 /* r3 = closure environment */ + ldr r10, .Lcaml_apply3 + b .Ljump_to_caml + + .global caml_ml_array_bound_error +caml_ml_array_bound_error: + /* Load address of [caml_array_bound_error] in r10 */ + ldr r10, .Lcaml_array_bound_error + /* Call that function */ + b caml_c_call + +/* Global references */ + +.Lcaml_last_return_address: .word caml_last_return_address +.Lcaml_bottom_of_stack: .word caml_bottom_of_stack +.Lcaml_gc_regs: .word caml_gc_regs +.Lcaml_young_ptr: .word caml_young_ptr +.Lcaml_young_limit: .word caml_young_limit +.Lcaml_exception_pointer: .word caml_exception_pointer +.Lcaml_program: .word caml_program +.LLtrap_handler: .word .Ltrap_handler +.Lcaml_apply2: .word caml_apply2 +.Lcaml_apply3: .word caml_apply3 +.LLcaml_requested_size: .word .Lcaml_requested_size +.Lcaml_array_bound_error: .word caml_array_bound_error + +.data +.Lcaml_requested_size: .word 0 + +/* GC roots for callback */ + + .data + + .global caml_system__frametable +caml_system__frametable: + .word 1 /* one descriptor */ + .word .Lcaml_retaddr /* return address into callback */ + .short -1 /* negative frame size => use callback link */ + .short 0 /* no roots */ + .align 2 diff --git a/asmrun/backtrace.c b/asmrun/backtrace.c new file mode 100644 index 0000000..a5bae18 --- /dev/null +++ b/asmrun/backtrace.c @@ -0,0 +1,225 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Gallium, INRIA Rocquencourt */ +/* */ +/* Copyright 2006 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: backtrace.c,v 1.4 2008-03-14 13:47:13 xleroy Exp $ */ + +/* Stack backtrace for uncaught exceptions */ + +#include +#include "alloc.h" +#include "backtrace.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "stack.h" + +int caml_backtrace_active = 0; +int caml_backtrace_pos = 0; +code_t * caml_backtrace_buffer = NULL; +value caml_backtrace_last_exn = Val_unit; +#define BACKTRACE_BUFFER_SIZE 1024 + +/* Start or stop the backtrace machinery */ + +CAMLprim value caml_record_backtrace(value vflag) +{ + int flag = Int_val(vflag); + + if (flag != caml_backtrace_active) { + caml_backtrace_active = flag; + caml_backtrace_pos = 0; + if (flag) { + caml_register_global_root(&caml_backtrace_last_exn); + } else { + caml_remove_global_root(&caml_backtrace_last_exn); + } + } + return Val_unit; +} + +/* Return the status of the backtrace machinery */ + +CAMLprim value caml_backtrace_status(value vunit) +{ + return Val_bool(caml_backtrace_active); +} + +/* Store the return addresses contained in the given stack fragment + into the backtrace array */ + +void caml_stash_backtrace(value exn, uintnat pc, char * sp, char * trapsp) +{ + frame_descr * d; + uintnat h; + + if (exn != caml_backtrace_last_exn) { + caml_backtrace_pos = 0; + caml_backtrace_last_exn = exn; + } + if (caml_backtrace_buffer == NULL) { + caml_backtrace_buffer = malloc(BACKTRACE_BUFFER_SIZE * sizeof(code_t)); + if (caml_backtrace_buffer == NULL) return; + } + if (caml_frame_descriptors == NULL) caml_init_frame_descriptors(); + + while (1) { + /* Find the descriptor corresponding to the return address */ + h = Hash_retaddr(pc); + while(1) { + d = caml_frame_descriptors[h]; + if (d == 0) return; /* can happen if some code not compiled with -g */ + if (d->retaddr == pc) break; + h = (h+1) & caml_frame_descriptors_mask; + } + /* Skip to next frame */ + if (d->frame_size != 0xFFFF) { + /* Regular frame, store its descriptor in the backtrace buffer */ + if (caml_backtrace_pos >= BACKTRACE_BUFFER_SIZE) return; + caml_backtrace_buffer[caml_backtrace_pos++] = (code_t) d; +#ifndef Stack_grows_upwards + sp += (d->frame_size & 0xFFFC); +#else + sp -= (d->frame_size & 0xFFFC); +#endif + pc = Saved_return_address(sp); +#ifdef Mask_already_scanned + pc = Mask_already_scanned(pc); +#endif + } else { + /* Special frame marking the top of a stack chunk for an ML callback. + Skip C portion of stack and continue with next ML stack chunk. */ + struct caml_context * next_context = Callback_link(sp); + sp = next_context->bottom_of_stack; + pc = next_context->last_retaddr; + /* A null sp means no more ML stack chunks; stop here. */ + if (sp == NULL) return; + } + /* Stop when we reach the current exception handler */ +#ifndef Stack_grows_upwards + if (sp > trapsp) return; +#else + if (sp < trapsp) return; +#endif + } +} + +/* Extract location information for the given frame descriptor */ + +struct loc_info { + int loc_valid; + int loc_is_raise; + char * loc_filename; + int loc_lnum; + int loc_startchr; + int loc_endchr; +}; + +static void extract_location_info(frame_descr * d, + /*out*/ struct loc_info * li) +{ + uintnat infoptr; + uint32 info1, info2; + + /* If no debugging information available, print nothing. + When everything is compiled with -g, this corresponds to + compiler-inserted re-raise operations. */ + if ((d->frame_size & 1) == 0) { + li->loc_valid = 0; + li->loc_is_raise = 1; + return; + } + /* Recover debugging info */ + infoptr = ((uintnat) d + + sizeof(char *) + sizeof(short) + sizeof(short) + + sizeof(short) * d->num_live + sizeof(frame_descr *) - 1) + & -sizeof(frame_descr *); + info1 = ((uint32 *)infoptr)[0]; + info2 = ((uint32 *)infoptr)[1]; + /* Format of the two info words: + llllllllllllllllllll aaaaaaaa bbbbbbbbbb nnnnnnnnnnnnnnnnnnnnnnnn kk + 44 36 26 2 0 + (32+12) (32+4) + k ( 2 bits): 0 if it's a call, 1 if it's a raise + n (24 bits): offset (in 4-byte words) of file name relative to infoptr + l (20 bits): line number + a ( 8 bits): beginning of character range + b (10 bits): end of character range */ + li->loc_valid = 1; + li->loc_is_raise = (info1 & 3) != 0; + li->loc_filename = (char *) infoptr + (info1 & 0x3FFFFFC); + li->loc_lnum = info2 >> 12; + li->loc_startchr = (info2 >> 4) & 0xFF; + li->loc_endchr = ((info2 & 0xF) << 6) | (info1 >> 26); +} + +static void print_location(struct loc_info * li, int index) +{ + char * info; + + /* Ignore compiler-inserted raise */ + if (!li->loc_valid) return; + + if (index == 0) + info = "Raised at"; + else if (li->loc_is_raise) + info = "Re-raised at"; + else + info = "Called from"; + fprintf (stderr, "%s file \"%s\", line %d, characters %d-%d\n", + info, li->loc_filename, li->loc_lnum, + li->loc_startchr, li->loc_endchr); +} + +/* Print a backtrace */ + +void caml_print_exception_backtrace(void) +{ + int i; + struct loc_info li; + + for (i = 0; i < caml_backtrace_pos; i++) { + extract_location_info((frame_descr *) (caml_backtrace_buffer[i]), &li); + print_location(&li, i); + } +} + +/* Convert the backtrace to a data structure usable from Caml */ + +CAMLprim value caml_get_exception_backtrace(value unit) +{ + CAMLparam0(); + CAMLlocal4(res, arr, p, fname); + int i; + struct loc_info li; + + arr = caml_alloc(caml_backtrace_pos, 0); + for (i = 0; i < caml_backtrace_pos; i++) { + extract_location_info((frame_descr *) (caml_backtrace_buffer[i]), &li); + if (li.loc_valid) { + fname = caml_copy_string(li.loc_filename); + p = caml_alloc_small(5, 0); + Field(p, 0) = Val_bool(li.loc_is_raise); + Field(p, 1) = fname; + Field(p, 2) = Val_int(li.loc_lnum); + Field(p, 3) = Val_int(li.loc_startchr); + Field(p, 4) = Val_int(li.loc_endchr); + } else { + p = caml_alloc_small(1, 1); + Field(p, 0) = Val_bool(li.loc_is_raise); + } + caml_modify(&Field(arr, i), p); + } + res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */ + CAMLreturn(res); +} + diff --git a/asmrun/fail.c b/asmrun/fail.c new file mode 100644 index 0000000..c3e088d --- /dev/null +++ b/asmrun/fail.c @@ -0,0 +1,207 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fail.c,v 1.40 2008-09-18 11:23:28 xleroy Exp $ */ + +/* Raising exceptions from C. */ + +#include +#include "alloc.h" +#include "fail.h" +#include "io.h" +#include "gc.h" +#include "memory.h" +#include "mlvalues.h" +#include "printexc.h" +#include "signals.h" +#include "stack.h" +#include "roots.h" + +/* The globals holding predefined exceptions */ + +typedef value caml_generated_constant[1]; + +extern caml_generated_constant + caml_exn_Out_of_memory, + caml_exn_Sys_error, + caml_exn_Failure, + caml_exn_Invalid_argument, + caml_exn_End_of_file, + caml_exn_Division_by_zero, + caml_exn_Not_found, + caml_exn_Match_failure, + caml_exn_Sys_blocked_io, + caml_exn_Stack_overflow; +extern caml_generated_constant + caml_bucket_Out_of_memory, + caml_bucket_Stack_overflow; + +/* Exception raising */ + +extern void caml_raise_exception (value bucket) Noreturn; + +char * caml_exception_pointer = NULL; + +void caml_raise(value v) +{ + Unlock_exn(); + if (caml_exception_pointer == NULL) caml_fatal_uncaught_exception(v); + +#ifndef Stack_grows_upwards +#define PUSHED_AFTER < +#else +#define PUSHED_AFTER > +#endif + while (caml_local_roots != NULL && + (char *) caml_local_roots PUSHED_AFTER caml_exception_pointer) { + caml_local_roots = caml_local_roots->next; + } +#undef PUSHED_AFTER + + caml_raise_exception(v); +} + +void caml_raise_constant(value tag) +{ + CAMLparam1 (tag); + CAMLlocal1 (bucket); + + bucket = caml_alloc_small (1, 0); + Field(bucket, 0) = tag; + caml_raise(bucket); + CAMLnoreturn; +} + +void caml_raise_with_arg(value tag, value arg) +{ + CAMLparam2 (tag, arg); + CAMLlocal1 (bucket); + + bucket = caml_alloc_small (2, 0); + Field(bucket, 0) = tag; + Field(bucket, 1) = arg; + caml_raise(bucket); + CAMLnoreturn; +} + +void caml_raise_with_args(value tag, int nargs, value args[]) +{ + CAMLparam1 (tag); + CAMLxparamN (args, nargs); + value bucket; + int i; + + Assert(1 + nargs <= Max_young_wosize); + bucket = caml_alloc_small (1 + nargs, 0); + Field(bucket, 0) = tag; + for (i = 0; i < nargs; i++) Field(bucket, 1 + i) = args[i]; + caml_raise(bucket); + CAMLnoreturn; +} + +void caml_raise_with_string(value tag, char const *msg) +{ + caml_raise_with_arg(tag, caml_copy_string(msg)); +} + +void caml_failwith (char const *msg) +{ + caml_raise_with_string((value) caml_exn_Failure, msg); +} + +void caml_invalid_argument (char const *msg) +{ + caml_raise_with_string((value) caml_exn_Invalid_argument, msg); +} + +/* To raise [Out_of_memory], we can't use [caml_raise_constant], + because it allocates and we're out of memory... + We therefore use a statically-allocated bucket constructed + by the ocamlopt linker. + This works OK because the exception value for [Out_of_memory] is also + statically allocated out of the heap. + The same applies to Stack_overflow. */ + +void caml_raise_out_of_memory(void) +{ + caml_raise((value) &caml_bucket_Out_of_memory); +} + +void caml_raise_stack_overflow(void) +{ + caml_raise((value) &caml_bucket_Stack_overflow); +} + +void caml_raise_sys_error(value msg) +{ + caml_raise_with_arg((value) caml_exn_Sys_error, msg); +} + +void caml_raise_end_of_file(void) +{ + caml_raise_constant((value) caml_exn_End_of_file); +} + +void caml_raise_zero_divide(void) +{ + caml_raise_constant((value) caml_exn_Division_by_zero); +} + +void caml_raise_not_found(void) +{ + caml_raise_constant((value) caml_exn_Not_found); +} + +void caml_raise_sys_blocked_io(void) +{ + caml_raise_constant((value) caml_exn_Sys_blocked_io); +} + +/* We allocate statically the bucket for the exception because we can't + do a GC before the exception is raised (lack of stack descriptors + for the ccall to [caml_array_bound_error]. */ + +#define BOUND_MSG "index out of bounds" +#define BOUND_MSG_LEN (sizeof(BOUND_MSG) - 1) + +static struct { + header_t hdr; + value exn; + value arg; +} array_bound_error_bucket; + +static struct { + header_t hdr; + char data[BOUND_MSG_LEN + sizeof(value)]; +} array_bound_error_msg = { 0, BOUND_MSG }; + +static int array_bound_error_bucket_inited = 0; + +void caml_array_bound_error(void) +{ + if (! array_bound_error_bucket_inited) { + mlsize_t wosize = (BOUND_MSG_LEN + sizeof(value)) / sizeof(value); + mlsize_t offset_index = Bsize_wsize(wosize) - 1; + array_bound_error_msg.hdr = Make_header(wosize, String_tag, Caml_white); + array_bound_error_msg.data[offset_index] = offset_index - BOUND_MSG_LEN; + array_bound_error_bucket.hdr = Make_header(2, 0, Caml_white); + array_bound_error_bucket.exn = (value) caml_exn_Invalid_argument; + array_bound_error_bucket.arg = (value) array_bound_error_msg.data; + array_bound_error_bucket_inited = 1; + caml_page_table_add(In_static_data, + &array_bound_error_msg, + &array_bound_error_msg + 1); + array_bound_error_bucket_inited = 1; + } + caml_raise((value) &array_bound_error_bucket.exn); +} diff --git a/asmrun/hppa.S b/asmrun/hppa.S new file mode 100644 index 0000000..8877ad5 --- /dev/null +++ b/asmrun/hppa.S @@ -0,0 +1,534 @@ +;********************************************************************* +;* * +;* Objective Caml * +;* * +;* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +;* * +;* Copyright 1996 Institut National de Recherche en Informatique et * +;* en Automatique. All rights reserved. This file is distributed * +;* under the terms of the GNU Library General Public License, with * +;* the special exception on linking described in file ../LICENSE. * +;* * +;********************************************************************* + +; $Id: hppa.S,v 1.26 2006-04-16 23:28:15 doligez Exp $ + +; Asm part of the runtime system for the HP PA-RISC processor. +; Must be preprocessed by cpp + +#ifdef SYS_hpux +#define G(x) x +#define CODESPACE .code +#define CODE_ALIGN 4 +#define EXPORT_CODE(x) .export x, entry, priv_lev=3 +#define EXPORT_DATA(x) .export x, data +#define STARTPROC .proc ! .callinfo frame=0, no_calls ! .entry +#define ENDPROC .exit ! .procend +#define LOADHIGH(x) addil LR%x-$global$, %r27 +#define LOW(x) RR%x-$global$ +#define LOADHIGHLABEL(x) ldil LR%x, %r1 +#define LOWLABEL(x) RR%x +#endif + +#if defined(SYS_linux) || defined(SYS_gnu) +#define G(x) x +#define CODESPACE .text +#define CODE_ALIGN 8 +#define EXPORT_CODE(x) .globl x +#define EXPORT_DATA(x) .globl x +#define STARTPROC +#define ENDPROC +#define LOADHIGH(x) addil LR%x-$global$, %r27 +#define LOW(x) RR%x-$global$ +#define LOADHIGHLABEL(x) ldil LR%x, %r1 +#define LOWLABEL(x) RR%x +#endif + +#ifdef SYS_hpux + .space $PRIVATE$ + .subspa $DATA$,quad=1,align=8,access=31 + .subspa $BSS$,quad=1,align=8,access=31,zero,sort=82 + .space $TEXT$ + .subspa $LIT$,quad=0,align=8,access=44 + .subspa $CODE$,quad=0,align=8,access=44,code_only + .import $global$, data + .import $$dyncall, millicode + .import caml_garbage_collection, code + .import caml_program, code + .import caml_raise, code + .import caml_apply2, code + .import caml_apply3, code + .import caml_array_bound_error, code + +caml_young_limit .comm 8 +caml_young_ptr .comm 8 +caml_bottom_of_stack .comm 8 +caml_last_return_address .comm 8 +caml_gc_regs .comm 8 +caml_exception_pointer .comm 8 +caml_required_size .comm 8 +#endif + +#if defined(SYS_linux) || defined(SYS_gnu) + .align 8 + .comm G(young_limit), 4 + .comm G(young_ptr), 4 + .comm G(caml_bottom_of_stack), 4 + .comm G(caml_last_return_address), 4 + .comm G(caml_gc_regs), 4 + .comm G(caml_exception_pointer), 4 + .comm G(caml_required_size), 4 +#endif + +; Allocation functions + + CODESPACE + .align CODE_ALIGN + EXPORT_CODE(G(caml_allocN)) +G(caml_allocN): + STARTPROC +; Required size in %r29 + ldw 0(%r4), %r1 + sub %r3, %r29, %r3 + comb,<<,n %r3, %r1, G(caml_call_gc) ; nullify if taken (forward br.) + bv 0(%r2) + nop + ENDPROC + + EXPORT_CODE(G(caml_call_gc)) +G(caml_call_gc): + STARTPROC +; Save required size (%r29) + LOADHIGH(G(caml_required_size)) + stw %r29, LOW(G(caml_required_size))(%r1) +; Save current allocation pointer for debugging purposes + LOADHIGH(G(caml_young_ptr)) + stw %r3, LOW(G(caml_young_ptr))(%r1) +; Record lowest stack address + LOADHIGH(G(caml_bottom_of_stack)) + stw %r30, LOW(G(caml_bottom_of_stack))(%r1) +; Record return address + LOADHIGH(G(caml_last_return_address)) + stw %r2, LOW(G(caml_last_return_address))(%r1) +; Save the exception handler (if e.g. a sighandler raises) + LOADHIGH(G(caml_exception_pointer)) + stw %r5, LOW(G(caml_exception_pointer))(%r1) +; Reserve stack space +; 0x1C0 = 4 * 32 (int regs) + 8 * 32 (float regs) + 64 (for calling C) + ldo 0x1C0(%r30), %r30 +; Save caml_gc_regs +L100: ldo -(64 + 4*32)(%r30), %r31 + LOADHIGH(G(caml_gc_regs)) + stw %r31, LOW(G(caml_gc_regs))(%r1) +; Save all regs used by the code generator + copy %r31, %r1 + stws,ma %r6, 4(%r1) + stws,ma %r7, 4(%r1) + stws,ma %r8, 4(%r1) + stws,ma %r9, 4(%r1) + stws,ma %r10, 4(%r1) + stws,ma %r11, 4(%r1) + stws,ma %r12, 4(%r1) + stws,ma %r13, 4(%r1) + stws,ma %r14, 4(%r1) + stws,ma %r15, 4(%r1) + stws,ma %r16, 4(%r1) + stws,ma %r17, 4(%r1) + stws,ma %r18, 4(%r1) + stws,ma %r19, 4(%r1) + stws,ma %r20, 4(%r1) + stws,ma %r21, 4(%r1) + stws,ma %r22, 4(%r1) + stws,ma %r23, 4(%r1) + stws,ma %r24, 4(%r1) + stws,ma %r25, 4(%r1) + stws,ma %r26, 4(%r1) + stws,ma %r28, 4(%r1) + ldo -0x1C0(%r30), %r1 + fstds,ma %fr4, 8(%r1) + fstds,ma %fr5, 8(%r1) + fstds,ma %fr6, 8(%r1) + fstds,ma %fr7, 8(%r1) + fstds,ma %fr8, 8(%r1) + fstds,ma %fr9, 8(%r1) + fstds,ma %fr10, 8(%r1) + fstds,ma %fr11, 8(%r1) + fstds,ma %fr12, 8(%r1) + fstds,ma %fr13, 8(%r1) + fstds,ma %fr14, 8(%r1) + fstds,ma %fr15, 8(%r1) + fstds,ma %fr16, 8(%r1) + fstds,ma %fr17, 8(%r1) + fstds,ma %fr18, 8(%r1) + fstds,ma %fr19, 8(%r1) + fstds,ma %fr20, 8(%r1) + fstds,ma %fr21, 8(%r1) + fstds,ma %fr22, 8(%r1) + fstds,ma %fr23, 8(%r1) + fstds,ma %fr24, 8(%r1) + fstds,ma %fr25, 8(%r1) + fstds,ma %fr26, 8(%r1) + fstds,ma %fr27, 8(%r1) + fstds,ma %fr28, 8(%r1) + fstds,ma %fr29, 8(%r1) + fstds,ma %fr30, 8(%r1) + +; Call the garbage collector + bl G(caml_garbage_collection), %r2 + nop + +; Restore all regs used by the code generator + ldo -(64 + 4*32)(%r30), %r1 + ldws,ma 4(%r1), %r6 + ldws,ma 4(%r1), %r7 + ldws,ma 4(%r1), %r8 + ldws,ma 4(%r1), %r9 + ldws,ma 4(%r1), %r10 + ldws,ma 4(%r1), %r11 + ldws,ma 4(%r1), %r12 + ldws,ma 4(%r1), %r13 + ldws,ma 4(%r1), %r14 + ldws,ma 4(%r1), %r15 + ldws,ma 4(%r1), %r16 + ldws,ma 4(%r1), %r17 + ldws,ma 4(%r1), %r18 + ldws,ma 4(%r1), %r19 + ldws,ma 4(%r1), %r20 + ldws,ma 4(%r1), %r21 + ldws,ma 4(%r1), %r22 + ldws,ma 4(%r1), %r23 + ldws,ma 4(%r1), %r24 + ldws,ma 4(%r1), %r25 + ldws,ma 4(%r1), %r26 + ldws,ma 4(%r1), %r28 + ldo -0x1C0(%r30), %r1 + fldds,ma 8(%r1), %fr4 + fldds,ma 8(%r1), %fr5 + fldds,ma 8(%r1), %fr6 + fldds,ma 8(%r1), %fr7 + fldds,ma 8(%r1), %fr8 + fldds,ma 8(%r1), %fr9 + fldds,ma 8(%r1), %fr10 + fldds,ma 8(%r1), %fr11 + fldds,ma 8(%r1), %fr12 + fldds,ma 8(%r1), %fr13 + fldds,ma 8(%r1), %fr14 + fldds,ma 8(%r1), %fr15 + fldds,ma 8(%r1), %fr16 + fldds,ma 8(%r1), %fr17 + fldds,ma 8(%r1), %fr18 + fldds,ma 8(%r1), %fr19 + fldds,ma 8(%r1), %fr20 + fldds,ma 8(%r1), %fr21 + fldds,ma 8(%r1), %fr22 + fldds,ma 8(%r1), %fr23 + fldds,ma 8(%r1), %fr24 + fldds,ma 8(%r1), %fr25 + fldds,ma 8(%r1), %fr26 + fldds,ma 8(%r1), %fr27 + fldds,ma 8(%r1), %fr28 + fldds,ma 8(%r1), %fr29 + fldds,ma 8(%r1), %fr30 + +; Reload the allocation pointer + LOADHIGH(G(caml_young_ptr)) + ldw LOW(G(caml_young_ptr))(%r1), %r3 +; Allocate space for block + LOADHIGH(G(caml_required_size)) + ldw LOW(G(caml_required_size))(%r1), %r29 + ldw 0(%r4), %r1 + sub %r3, %r29, %r3 + comb,<< %r3, %r1, L100 + nop +; Return to caller + LOADHIGH(G(caml_last_return_address)) + ldw LOW(G(caml_last_return_address))(%r1), %r2 + bv 0(%r2) + ldo -0x1C0(%r30), %r30 + ENDPROC + +; Call a C function from Caml +; Function to call is in %r22 + + .align CODE_ALIGN +#ifdef SYS_hpux + .export G(caml_c_call), ENTRY, ARGW0=GR, ARGW1=GR, ARGW2=GR, ARGW3=GR +#else + EXPORT_CODE(G(caml_c_call)) +#endif +G(caml_c_call): + STARTPROC +; Record lowest stack address + LOADHIGH(G(caml_bottom_of_stack)) + stw %r30, LOW(G(caml_bottom_of_stack))(%r1) +; Record return address + LOADHIGH(G(caml_last_return_address)) + stw %r2, LOW(G(caml_last_return_address))(%r1) +; Save the exception handler + LOADHIGH(G(caml_exception_pointer)) + stw %r5, LOW(G(caml_exception_pointer))(%r1) +; Save the allocation pointer + LOADHIGH(G(caml_young_ptr)) + stw %r3, LOW(G(caml_young_ptr))(%r1) +; Call the C function +#ifdef SYS_hpux + bl $$dyncall, %r31 +#else + ble 0(4, %r22) +#endif + copy %r31, %r2 ; in delay slot +; Reload return address + LOADHIGH(G(caml_last_return_address)) + ldw LOW(G(caml_last_return_address))(%r1), %r2 +; Reload allocation pointer + LOADHIGH(G(caml_young_ptr)) +; Return to caller + bv 0(%r2) + ldw LOW(G(caml_young_ptr))(%r1), %r3 ; in delay slot + ENDPROC + +; Start the Caml program + + .align CODE_ALIGN + EXPORT_CODE(G(caml_start_program)) +G(caml_start_program): + STARTPROC + LOADHIGH(G(caml_program)) + ldo LOW(G(caml_program))(%r1), %r22 + +; Code shared with caml_callback* +L102: +; Save return address + stw %r2,-20(%r30) + ldo 256(%r30), %r30 +; Save the callee-save registers + ldo -32(%r30), %r1 + stws,ma %r3, -4(%r1) + stws,ma %r4, -4(%r1) + stws,ma %r5, -4(%r1) + stws,ma %r6, -4(%r1) + stws,ma %r7, -4(%r1) + stws,ma %r8, -4(%r1) + stws,ma %r9, -4(%r1) + stws,ma %r10, -4(%r1) + stws,ma %r11, -4(%r1) + stws,ma %r12, -4(%r1) + stws,ma %r13, -4(%r1) + stws,ma %r14, -4(%r1) + stws,ma %r15, -4(%r1) + stws,ma %r16, -4(%r1) + stws,ma %r17, -4(%r1) + stws,ma %r18, -4(%r1) + fstds,ma %fr12, -8(%r1) + fstds,ma %fr13, -8(%r1) + fstds,ma %fr14, -8(%r1) + fstds,ma %fr15, -8(%r1) + fstds,ma %fr16, -8(%r1) + fstds,ma %fr17, -8(%r1) + fstds,ma %fr18, -8(%r1) + fstds,ma %fr19, -8(%r1) + fstds,ma %fr20, -8(%r1) + fstds,ma %fr21, -8(%r1) + fstds,ma %fr22, -8(%r1) + fstds,ma %fr23, -8(%r1) + fstds,ma %fr24, -8(%r1) + fstds,ma %fr25, -8(%r1) + fstds,ma %fr26, -8(%r1) + fstds,ma %fr27, -8(%r1) + fstds,ma %fr28, -8(%r1) + fstds,ma %fr29, -8(%r1) + fstds,ma %fr30, -8(%r1) + fstds,ma %fr31, -8(%r1) +; Set up a callback link + ldo 16(%r30), %r30 + LOADHIGH(G(caml_bottom_of_stack)) + ldw LOW(G(caml_bottom_of_stack))(%r1), %r1 + stw %r1, -16(%r30) + LOADHIGH(G(caml_last_return_address)) + ldw LOW(G(caml_last_return_address))(%r1), %r1 + stw %r1, -12(%r30) + LOADHIGH(G(caml_gc_regs)) + ldw LOW(G(caml_gc_regs))(%r1), %r1 + stw %r1, -8(%r30) +; Set up a trap frame to catch exceptions escaping the Caml code + ldo 8(%r30), %r30 + LOADHIGH(G(caml_exception_pointer)) + ldw LOW(G(caml_exception_pointer))(%r1), %r1 + stw %r1, -8(%r30) + LOADHIGHLABEL(L103) + ldo LOWLABEL(L103)(%r1), %r1 + stw %r1, -4(%r30) + copy %r30, %r5 +; Reload allocation pointers + LOADHIGH(G(caml_young_ptr)) + ldw LOW(G(caml_young_ptr))(%r1), %r3 + LOADHIGH(G(caml_young_limit)) + ldo LOW(G(caml_young_limit))(%r1), %r4 +; Call the Caml code + ble 0(4, %r22) + copy %r31, %r2 +L104: +; Pop the trap frame + ldw -8(%r30), %r31 + LOADHIGH(G(caml_exception_pointer)) + stw %r31, LOW(G(caml_exception_pointer))(%r1) + ldo -8(%r30), %r30 +; Pop the callback link +L105: + ldw -16(%r30), %r31 + LOADHIGH(G(caml_bottom_of_stack)) + stw %r31, LOW(G(caml_bottom_of_stack))(%r1) + ldw -12(%r30), %r31 + LOADHIGH(G(caml_last_return_address)) + stw %r31, LOW(G(caml_last_return_address))(%r1) + ldw -8(%r30), %r31 + LOADHIGH(G(caml_gc_regs)) + stw %r31, LOW(G(caml_gc_regs))(%r1) + ldo -16(%r30), %r30 +; Save allocation pointer + LOADHIGH(G(caml_young_ptr)) + stw %r3, LOW(G(caml_young_ptr))(%r1) +; Move result where C function expects it + copy %r26, %r28 +; Reload callee-save registers + ldo -32(%r30), %r1 + ldws,ma -4(%r1), %r3 + ldws,ma -4(%r1), %r4 + ldws,ma -4(%r1), %r5 + ldws,ma -4(%r1), %r6 + ldws,ma -4(%r1), %r7 + ldws,ma -4(%r1), %r8 + ldws,ma -4(%r1), %r9 + ldws,ma -4(%r1), %r10 + ldws,ma -4(%r1), %r11 + ldws,ma -4(%r1), %r12 + ldws,ma -4(%r1), %r13 + ldws,ma -4(%r1), %r14 + ldws,ma -4(%r1), %r15 + ldws,ma -4(%r1), %r16 + ldws,ma -4(%r1), %r17 + ldws,ma -4(%r1), %r18 + fldds,ma -8(%r1), %fr12 + fldds,ma -8(%r1), %fr13 + fldds,ma -8(%r1), %fr14 + fldds,ma -8(%r1), %fr15 + fldds,ma -8(%r1), %fr16 + fldds,ma -8(%r1), %fr17 + fldds,ma -8(%r1), %fr18 + fldds,ma -8(%r1), %fr19 + fldds,ma -8(%r1), %fr20 + fldds,ma -8(%r1), %fr21 + fldds,ma -8(%r1), %fr22 + fldds,ma -8(%r1), %fr23 + fldds,ma -8(%r1), %fr24 + fldds,ma -8(%r1), %fr25 + fldds,ma -8(%r1), %fr26 + fldds,ma -8(%r1), %fr27 + fldds,ma -8(%r1), %fr28 + fldds,ma -8(%r1), %fr29 + fldds,ma -8(%r1), %fr30 + fldds,ma -8(%r1), %fr31 +; Return to C + ldo -256(%r30), %r30 + ldw -20(%r30), %r2 + bv 0(%r2) + nop +; The trap handler +L103: +; Save exception pointer + LOADHIGH(G(caml_exception_pointer)) + stw %r5, LOW(G(caml_exception_pointer))(%r1) +; Encode exception bucket as an exception result and return it + ldi 2, %r1 + or %r26, %r1, %r26 +; Return it + b L105 + nop + +; Re-raise the exception through caml_raise, to clean up local C roots + ldo 64(%r30), %r30 + bl G(caml_raise), %r2 + nop + ENDPROC + +; Raise an exception from C + + .align CODE_ALIGN + EXPORT_CODE(G(caml_raise_exception)) +G(caml_raise_exception): + STARTPROC +; Cut the stack + LOADHIGH(G(caml_exception_pointer)) + ldw LOW(G(caml_exception_pointer))(%r1), %r30 +; Reload allocation registers + LOADHIGH(G(caml_young_ptr)) + ldw LOW(G(caml_young_ptr))(%r1), %r3 + LOADHIGH(G(caml_young_limit)) + ldo LOW(G(caml_young_limit))(%r1), %r4 +; Raise the exception + ldw -4(%r30), %r1 + ldw -8(%r30), %r5 + bv 0(%r1) + ldo -8(%r30), %r30 ; in delay slot + ENDPROC + +; Callbacks C -> ML + + .align CODE_ALIGN + EXPORT_CODE(G(caml_callback_exn)) +G(caml_callback_exn): + STARTPROC +; Initial shuffling of arguments + copy %r26, %r1 ; Closure + copy %r25, %r26 ; Argument + copy %r1, %r25 + b L102 + ldw 0(%r1), %r22 ; Code to call (in delay slot) + ENDPROC + + .align CODE_ALIGN + EXPORT_CODE(G(caml_callback2_exn)) +G(caml_callback2_exn): + STARTPROC + copy %r26, %r1 ; Closure + copy %r25, %r26 ; First argument + copy %r24, %r25 ; Second argument + copy %r1, %r24 + LOADHIGH(G(caml_apply2)) + b L102 + ldo LOW(G(caml_apply2))(%r1), %r22 + ENDPROC + + .align CODE_ALIGN + EXPORT_CODE(G(caml_callback3_exn)) +G(caml_callback3_exn): + STARTPROC + copy %r26, %r1 ; Closure + copy %r25, %r26 ; First argument + copy %r24, %r25 ; Second argument + copy %r23, %r24 ; Third argument + copy %r1, %r23 + LOADHIGH(G(caml_apply3)) + b L102 + ldo LOW(G(caml_apply3))(%r1), %r22 + ENDPROC + + .align CODE_ALIGN + EXPORT_CODE(G(caml_ml_array_bound_error)) +G(caml_ml_array_bound_error): + STARTPROC +; Load address of [caml_array_bound_error] in %r22 + ldil LR%caml_array_bound_error, %r22 + ldo RR%caml_array_bound_error(%r22), %r22 +; Reserve 48 bytes of stack space and jump to caml_c_call + b G(caml_c_call) + ldo 48(%r30), %r30 /* in delay slot */ + ENDPROC + + .data + EXPORT_DATA(G(caml_system__frametable)) +G(caml_system__frametable): + .long 1 /* one descriptor */ + .long L104 + 3 /* return address into callback */ + .short -1 /* negative frame size => use callback link */ + .short 0 /* no roots */ diff --git a/asmrun/i386.S b/asmrun/i386.S new file mode 100644 index 0000000..c13cb2e --- /dev/null +++ b/asmrun/i386.S @@ -0,0 +1,431 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: i386.S,v 1.50 2008-08-01 08:04:57 xleroy Exp $ */ + +/* Asm part of the runtime system, Intel 386 processor */ +/* Must be preprocessed by cpp */ + +/* Linux/BSD with ELF binaries and Solaris do not prefix identifiers with _. + Linux/BSD with a.out binaries and NextStep do. */ + +#if defined(SYS_solaris) +#define CONCAT(a,b) a/**/b +#else +#define CONCAT(a,b) a##b +#endif + +#if defined(SYS_linux_elf) || defined(SYS_bsd_elf) \ + || defined(SYS_solaris) || defined(SYS_beos) || defined(SYS_gnu) +#define G(x) x +#define LBL(x) CONCAT(.L,x) +#else +#define G(x) CONCAT(_,x) +#define LBL(x) CONCAT(L,x) +#endif + +#if defined(SYS_linux_elf) || defined(SYS_bsd_elf) \ + || defined(SYS_solaris) || defined(SYS_beos) || defined(SYS_cygwin) \ + || defined(SYS_mingw) || defined(SYS_gnu) +#define FUNCTION_ALIGN 4 +#else +#define FUNCTION_ALIGN 2 +#endif + +#if defined(PROFILING) +#if defined(SYS_linux_elf) || defined(SYS_gnu) +#define PROFILE_CAML \ + pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \ + call mcount; \ + popl %edx; popl %ecx; popl %eax; popl %ebp +#define PROFILE_C \ + pushl %ebp; movl %esp, %ebp; call mcount; popl %ebp +#elif defined(SYS_bsd_elf) +#define PROFILE_CAML \ + pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \ + call .mcount; \ + popl %edx; popl %ecx; popl %eax; popl %ebp +#define PROFILE_C \ + pushl %ebp; movl %esp, %ebp; call .mcount; popl %ebp +#elif defined(SYS_macosx) +#define PROFILE_CAML \ + pushl %ebp; movl %esp, %ebp; pushl %eax; pushl %ecx; pushl %edx; \ + call Lmcount$stub; \ + popl %edx; popl %ecx; popl %eax; popl %ebp +#define PROFILE_C \ + pushl %ebp; movl %esp, %ebp; call Lmcount$stub; popl %ebp +#endif +#else +#define PROFILE_CAML +#define PROFILE_C +#endif + +#ifdef SYS_macosx +#define ALIGN_STACK(amount) subl $ amount, %esp +#define UNDO_ALIGN_STACK(amount) addl $ amount, %esp +#else +#define ALIGN_STACK(amount) +#define UNDO_ALIGN_STACK(amount) +#endif + +/* Allocation */ + + .text + .globl G(caml_call_gc) + .globl G(caml_alloc1) + .globl G(caml_alloc2) + .globl G(caml_alloc3) + .globl G(caml_allocN) + + .align FUNCTION_ALIGN +G(caml_call_gc): + PROFILE_CAML + /* Record lowest stack address and return address */ + movl 0(%esp), %eax + movl %eax, G(caml_last_return_address) + leal 4(%esp), %eax + movl %eax, G(caml_bottom_of_stack) + /* Build array of registers, save it into caml_gc_regs */ +LBL(105): + pushl %ebp + pushl %edi + pushl %esi + pushl %edx + pushl %ecx + pushl %ebx + pushl %eax + movl %esp, G(caml_gc_regs) + /* MacOSX note: 16-alignment of stack preserved at this point */ + /* Call the garbage collector */ + call G(caml_garbage_collection) + /* Restore all regs used by the code generator */ + popl %eax + popl %ebx + popl %ecx + popl %edx + popl %esi + popl %edi + popl %ebp + /* Return to caller */ + ret + + .align FUNCTION_ALIGN +G(caml_alloc1): + PROFILE_CAML + movl G(caml_young_ptr), %eax + subl $8, %eax + movl %eax, G(caml_young_ptr) + cmpl G(caml_young_limit), %eax + jb LBL(100) + ret +LBL(100): + movl 0(%esp), %eax + movl %eax, G(caml_last_return_address) + leal 4(%esp), %eax + movl %eax, G(caml_bottom_of_stack) + ALIGN_STACK(12) + call LBL(105) + UNDO_ALIGN_STACK(12) + jmp G(caml_alloc1) + + .align FUNCTION_ALIGN +G(caml_alloc2): + PROFILE_CAML + movl G(caml_young_ptr), %eax + subl $12, %eax + movl %eax, G(caml_young_ptr) + cmpl G(caml_young_limit), %eax + jb LBL(101) + ret +LBL(101): + movl 0(%esp), %eax + movl %eax, G(caml_last_return_address) + leal 4(%esp), %eax + movl %eax, G(caml_bottom_of_stack) + ALIGN_STACK(12) + call LBL(105) + UNDO_ALIGN_STACK(12) + jmp G(caml_alloc2) + + .align FUNCTION_ALIGN +G(caml_alloc3): + PROFILE_CAML + movl G(caml_young_ptr), %eax + subl $16, %eax + movl %eax, G(caml_young_ptr) + cmpl G(caml_young_limit), %eax + jb LBL(102) + ret +LBL(102): + movl 0(%esp), %eax + movl %eax, G(caml_last_return_address) + leal 4(%esp), %eax + movl %eax, G(caml_bottom_of_stack) + ALIGN_STACK(12) + call LBL(105) + UNDO_ALIGN_STACK(12) + jmp G(caml_alloc3) + + .align FUNCTION_ALIGN +G(caml_allocN): + PROFILE_CAML + subl G(caml_young_ptr), %eax /* eax = size - caml_young_ptr */ + negl %eax /* eax = caml_young_ptr - size */ + cmpl G(caml_young_limit), %eax + jb LBL(103) + movl %eax, G(caml_young_ptr) + ret +LBL(103): + subl G(caml_young_ptr), %eax /* eax = - size */ + negl %eax /* eax = size */ + pushl %eax /* save desired size */ + subl %eax, G(caml_young_ptr) /* must update young_ptr */ + movl 4(%esp), %eax + movl %eax, G(caml_last_return_address) + leal 8(%esp), %eax + movl %eax, G(caml_bottom_of_stack) + ALIGN_STACK(8) + call LBL(105) + UNDO_ALIGN_STACK(8) + popl %eax /* recover desired size */ + jmp G(caml_allocN) + +/* Call a C function from Caml */ + + .globl G(caml_c_call) + .align FUNCTION_ALIGN +G(caml_c_call): + PROFILE_CAML + /* Record lowest stack address and return address */ + movl (%esp), %edx + movl %edx, G(caml_last_return_address) + leal 4(%esp), %edx + movl %edx, G(caml_bottom_of_stack) + /* Call the function (address in %eax) */ + jmp *%eax + +/* Start the Caml program */ + + .globl G(caml_start_program) + .align FUNCTION_ALIGN +G(caml_start_program): + PROFILE_C + /* Save callee-save registers */ + pushl %ebx + pushl %esi + pushl %edi + pushl %ebp + /* Initial entry point is caml_program */ + movl $ G(caml_program), %esi + /* Common code for caml_start_program and caml_callback* */ +LBL(106): + /* Build a callback link */ + pushl G(caml_gc_regs) + pushl G(caml_last_return_address) + pushl G(caml_bottom_of_stack) + /* Note: 16-alignment preserved on MacOSX at this point */ + /* Build an exception handler */ + pushl $ LBL(108) + ALIGN_STACK(8) + pushl G(caml_exception_pointer) + movl %esp, G(caml_exception_pointer) + /* Call the Caml code */ + call *%esi +LBL(107): + /* Pop the exception handler */ + popl G(caml_exception_pointer) +#ifdef SYS_macosx + addl $12, %esp +#else + addl $4, %esp +#endif +LBL(109): + /* Pop the callback link, restoring the global variables */ + popl G(caml_bottom_of_stack) + popl G(caml_last_return_address) + popl G(caml_gc_regs) + /* Restore callee-save registers. */ + popl %ebp + popl %edi + popl %esi + popl %ebx + /* Return to caller. */ + ret +LBL(108): + /* Exception handler*/ + /* Mark the bucket as an exception result and return it */ + orl $2, %eax + jmp LBL(109) + +/* Raise an exception from Caml */ + + .globl G(caml_raise_exn) + .align FUNCTION_ALIGN +G(caml_raise_exn): + testl $1, G(caml_backtrace_active) + jne LBL(110) + movl G(caml_exception_pointer), %esp + popl G(caml_exception_pointer) + UNDO_ALIGN_STACK(8) + ret +LBL(110): + movl %eax, %esi /* Save exception bucket in esi */ + movl G(caml_exception_pointer), %edi /* SP of handler */ + movl 0(%esp), %eax /* PC of raise */ + leal 4(%esp), %edx /* SP of raise */ + ALIGN_STACK(12) + pushl %edi /* arg 4: sp of handler */ + pushl %edx /* arg 3: sp of raise */ + pushl %eax /* arg 2: pc of raise */ + pushl %esi /* arg 1: exception bucket */ + call G(caml_stash_backtrace) + movl %esi, %eax /* Recover exception bucket */ + movl %edi, %esp + popl G(caml_exception_pointer) + UNDO_ALIGN_STACK(8) + ret + +/* Raise an exception from C */ + + .globl G(caml_raise_exception) + .align FUNCTION_ALIGN +G(caml_raise_exception): + PROFILE_C + testl $1, G(caml_backtrace_active) + jne LBL(111) + movl 4(%esp), %eax + movl G(caml_exception_pointer), %esp + popl G(caml_exception_pointer) + UNDO_ALIGN_STACK(8) + ret +LBL(111): + movl 4(%esp), %esi /* Save exception bucket in esi */ + ALIGN_STACK(12) + pushl G(caml_exception_pointer) /* arg 4: sp of handler */ + pushl G(caml_bottom_of_stack) /* arg 3: sp of raise */ + pushl G(caml_last_return_address) /* arg 2: pc of raise */ + pushl %esi /* arg 1: exception bucket */ + call G(caml_stash_backtrace) + movl %esi, %eax /* Recover exception bucket */ + movl G(caml_exception_pointer), %esp + popl G(caml_exception_pointer) + UNDO_ALIGN_STACK(8) + ret + +/* Callback from C to Caml */ + + .globl G(caml_callback_exn) + .align FUNCTION_ALIGN +G(caml_callback_exn): + PROFILE_C + /* Save callee-save registers */ + pushl %ebx + pushl %esi + pushl %edi + pushl %ebp + /* Initial loading of arguments */ + movl 20(%esp), %ebx /* closure */ + movl 24(%esp), %eax /* argument */ + movl 0(%ebx), %esi /* code pointer */ + jmp LBL(106) + + .globl G(caml_callback2_exn) + .align FUNCTION_ALIGN +G(caml_callback2_exn): + PROFILE_C + /* Save callee-save registers */ + pushl %ebx + pushl %esi + pushl %edi + pushl %ebp + /* Initial loading of arguments */ + movl 20(%esp), %ecx /* closure */ + movl 24(%esp), %eax /* first argument */ + movl 28(%esp), %ebx /* second argument */ + movl $ G(caml_apply2), %esi /* code pointer */ + jmp LBL(106) + + .globl G(caml_callback3_exn) + .align FUNCTION_ALIGN +G(caml_callback3_exn): + PROFILE_C + /* Save callee-save registers */ + pushl %ebx + pushl %esi + pushl %edi + pushl %ebp + /* Initial loading of arguments */ + movl 20(%esp), %edx /* closure */ + movl 24(%esp), %eax /* first argument */ + movl 28(%esp), %ebx /* second argument */ + movl 32(%esp), %ecx /* third argument */ + movl $ G(caml_apply3), %esi /* code pointer */ + jmp LBL(106) + + .globl G(caml_ml_array_bound_error) + .align FUNCTION_ALIGN +G(caml_ml_array_bound_error): + /* Empty the floating-point stack */ + ffree %st(0) + ffree %st(1) + ffree %st(2) + ffree %st(3) + ffree %st(4) + ffree %st(5) + ffree %st(6) + ffree %st(7) + /* Record lowest stack address and return address */ + movl (%esp), %edx + movl %edx, G(caml_last_return_address) + leal 4(%esp), %edx + movl %edx, G(caml_bottom_of_stack) + /* For MacOS X: re-align the stack */ +#ifdef SYS_macosx + andl $-16, %esp +#endif + /* Branch to [caml_array_bound_error] (never returns) */ + call G(caml_array_bound_error) + + .data + .globl G(caml_system__frametable) +G(caml_system__frametable): + .long 1 /* one descriptor */ + .long LBL(107) /* return address into callback */ +#ifndef SYS_solaris + .word -1 /* negative frame size => use callback link */ + .word 0 /* no roots here */ +#else + .value -1 /* negative frame size => use callback link */ + .value 0 /* no roots here */ +#endif + + .globl G(caml_extra_params) +G(caml_extra_params): +#ifndef SYS_solaris + .space 64 +#else + .zero 64 +#endif + +#if defined(PROFILING) && defined(SYS_macosx) + .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 +Lmcount$stub: + .indirect_symbol mcount + hlt ; hlt ; hlt ; hlt ; hlt + .subsections_via_symbols +#endif + +#if defined(SYS_linux_elf) + /* Mark stack as non-executable, PR#4564 */ + .section .note.GNU-stack,"",%progbits +#endif diff --git a/asmrun/i386nt.asm b/asmrun/i386nt.asm new file mode 100644 index 0000000..fdb767d --- /dev/null +++ b/asmrun/i386nt.asm @@ -0,0 +1,323 @@ +;********************************************************************* +; +; Objective Caml +; +; Xavier Leroy, projet Cristal, INRIA Rocquencourt +; +; Copyright 1996 Institut National de Recherche en Informatique et +; en Automatique. All rights reserved. This file is distributed +; under the terms of the GNU Library General Public License, with +; the special exception on linking described in file ../LICENSE. +; +;********************************************************************* + +; $Id: i386nt.asm,v 1.20 2007-01-29 12:10:52 xleroy Exp $ + +; Asm part of the runtime system, Intel 386 processor, Intel syntax + + .386 + .MODEL FLAT + + EXTERN _caml_garbage_collection: PROC + EXTERN _caml_apply2: PROC + EXTERN _caml_apply3: PROC + EXTERN _caml_program: PROC + EXTERN _caml_array_bound_error: PROC + EXTERN _caml_young_limit: DWORD + EXTERN _caml_young_ptr: DWORD + EXTERN _caml_bottom_of_stack: DWORD + EXTERN _caml_last_return_address: DWORD + EXTERN _caml_gc_regs: DWORD + EXTERN _caml_exception_pointer: DWORD + EXTERN _caml_backtrace_active: DWORD + EXTERN _caml_stash_backtrace: PROC + +; Allocation + + .CODE + PUBLIC _caml_alloc1 + PUBLIC _caml_alloc2 + PUBLIC _caml_alloc3 + PUBLIC _caml_allocN + PUBLIC _caml_call_gc + +_caml_call_gc: + ; Record lowest stack address and return address + mov eax, [esp] + mov _caml_last_return_address, eax + lea eax, [esp+4] + mov _caml_bottom_of_stack, eax + ; Save all regs used by the code generator +L105: push ebp + push edi + push esi + push edx + push ecx + push ebx + push eax + mov _caml_gc_regs, esp + ; Call the garbage collector + call _caml_garbage_collection + ; Restore all regs used by the code generator + pop eax + pop ebx + pop ecx + pop edx + pop esi + pop edi + pop ebp + ; Return to caller + ret + + ALIGN 4 +_caml_alloc1: + mov eax, _caml_young_ptr + sub eax, 8 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L100 + ret +L100: mov eax, [esp] + mov _caml_last_return_address, eax + lea eax, [esp+4] + mov _caml_bottom_of_stack, eax + call L105 + jmp _caml_alloc1 + + ALIGN 4 +_caml_alloc2: + mov eax, _caml_young_ptr + sub eax, 12 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L101 + ret +L101: mov eax, [esp] + mov _caml_last_return_address, eax + lea eax, [esp+4] + mov _caml_bottom_of_stack, eax + call L105 + jmp _caml_alloc2 + + ALIGN 4 +_caml_alloc3: + mov eax, _caml_young_ptr + sub eax, 16 + mov _caml_young_ptr, eax + cmp eax, _caml_young_limit + jb L102 + ret +L102: mov eax, [esp] + mov _caml_last_return_address, eax + lea eax, [esp+4] + mov _caml_bottom_of_stack, eax + call L105 + jmp _caml_alloc3 + + ALIGN 4 +_caml_allocN: + sub eax, _caml_young_ptr ; eax = size - young_ptr + neg eax ; eax = young_ptr - size + cmp eax, _caml_young_limit + jb L103 + mov _caml_young_ptr, eax + ret +L103: sub eax, _caml_young_ptr ; eax = - size + neg eax ; eax = size + push eax ; save desired size + sub _caml_young_ptr, eax ; must update young_ptr + mov eax, [esp+4] + mov _caml_last_return_address, eax + lea eax, [esp+8] + mov _caml_bottom_of_stack, eax + call L105 + pop eax ; recover desired size + jmp _caml_allocN + +; Call a C function from Caml + + PUBLIC _caml_c_call + ALIGN 4 +_caml_c_call: + ; Record lowest stack address and return address + mov edx, [esp] + mov _caml_last_return_address, edx + lea edx, [esp+4] + mov _caml_bottom_of_stack, edx + ; Call the function (address in %eax) + jmp eax + +; Start the Caml program + + PUBLIC _caml_start_program + ALIGN 4 +_caml_start_program: + ; Save callee-save registers + push ebx + push esi + push edi + push ebp + ; Initial code pointer is caml_program + mov esi, offset _caml_program + +; Code shared between caml_start_program and callback* + +L106: + ; Build a callback link + push _caml_gc_regs + push _caml_last_return_address + push _caml_bottom_of_stack + ; Build an exception handler + push L108 + push _caml_exception_pointer + mov _caml_exception_pointer, esp + ; Call the Caml code + call esi +L107: + ; Pop the exception handler + pop _caml_exception_pointer + pop esi ; dummy register +L109: + ; Pop the callback link, restoring the global variables + ; used by caml_c_call + pop _caml_bottom_of_stack + pop _caml_last_return_address + pop _caml_gc_regs + ; Restore callee-save registers. + pop ebp + pop edi + pop esi + pop ebx + ; Return to caller. + ret +L108: + ; Exception handler + ; Mark the bucket as an exception result and return it + or eax, 2 + jmp L109 + +; Raise an exception for Caml + + PUBLIC _caml_raise_exn + ALIGN 4 +_caml_raise_exn: + test _caml_backtrace_active, 1 + jne L110 + mov esp, _caml_exception_pointer + pop _caml_exception_pointer + ret +L110: + mov esi, eax ; Save exception bucket in esi + mov edi, _caml_exception_pointer ; SP of handler + mov eax, [esp] ; PC of raise + lea edx, [esp+4] + push edi ; arg 4: SP of handler + push edx ; arg 3: SP of raise + push eax ; arg 2: PC of raise + push esi ; arg 1: exception bucket + call _caml_stash_backtrace + mov eax, esi ; recover exception bucket + mov esp, edi ; cut the stack + pop _caml_exception_pointer + ret + +; Raise an exception from C + + PUBLIC _caml_raise_exception + ALIGN 4 +_caml_raise_exception: + test _caml_backtrace_active, 1 + jne L111 + mov eax, [esp+4] + mov esp, _caml_exception_pointer + pop _caml_exception_pointer + ret +L111: + mov esi, [esp+4] ; Save exception bucket in esi + push _caml_exception_pointer ; arg 4: SP of handler + push _caml_bottom_of_stack ; arg 3: SP of raise + push _caml_last_return_address ; arg 2: PC of raise + push esi ; arg 1: exception bucket + call _caml_stash_backtrace + mov eax, esi ; recover exception bucket + mov esp, _caml_exception_pointer ; cut the stack + pop _caml_exception_pointer + ret + +; Callback from C to Caml + + PUBLIC _caml_callback_exn + ALIGN 4 +_caml_callback_exn: + ; Save callee-save registers + push ebx + push esi + push edi + push ebp + ; Initial loading of arguments + mov ebx, [esp+20] ; closure + mov eax, [esp+24] ; argument + mov esi, [ebx] ; code pointer + jmp L106 + + PUBLIC _caml_callback2_exn + ALIGN 4 +_caml_callback2_exn: + ; Save callee-save registers + push ebx + push esi + push edi + push ebp + ; Initial loading of arguments + mov ecx, [esp+20] ; closure + mov eax, [esp+24] ; first argument + mov ebx, [esp+28] ; second argument + mov esi, offset _caml_apply2 ; code pointer + jmp L106 + + PUBLIC _caml_callback3_exn + ALIGN 4 +_caml_callback3_exn: + ; Save callee-save registers + push ebx + push esi + push edi + push ebp + ; Initial loading of arguments + mov edx, [esp+20] ; closure + mov eax, [esp+24] ; first argument + mov ebx, [esp+28] ; second argument + mov ecx, [esp+32] ; third argument + mov esi, offset _caml_apply3 ; code pointer + jmp L106 + + PUBLIC _caml_ml_array_bound_error + ALIGN 4 +_caml_ml_array_bound_error: + ; Empty the floating-point stack + ffree st(0) + ffree st(1) + ffree st(2) + ffree st(3) + ffree st(4) + ffree st(5) + ffree st(6) + ffree st(7) + ; Branch to caml_array_bound_error + mov eax, offset _caml_array_bound_error + jmp _caml_c_call + + .DATA + PUBLIC _caml_system__frametable +_caml_system__frametable LABEL DWORD + DWORD 1 ; one descriptor + DWORD L107 ; return address into callback + WORD -1 ; negative frame size => use callback link + WORD 0 ; no roots here + + PUBLIC _caml_extra_params +_caml_extra_params LABEL DWORD + BYTE 64 DUP (?) + + END + diff --git a/asmrun/ia64.S b/asmrun/ia64.S new file mode 100644 index 0000000..ad70f8f --- /dev/null +++ b/asmrun/ia64.S @@ -0,0 +1,530 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: ia64.S,v 1.13 2004-01-03 12:51:19 doligez Exp $ */ + +/* Asm part of the runtime system, Alpha processor */ + +#undef BROKEN_POSTINCREMENT + +#define ADDRGLOBAL(reg,symb) \ + add reg = @ltoff(symb), gp;; ld8 reg = [reg] +#define LOADGLOBAL(reg,symb) \ + add r3 = @ltoff(symb), gp;; ld8 r3 = [r3];; ld8 reg = [r3] +#define STOREGLOBAL(reg,symb) \ + add r3 = @ltoff(symb), gp;; ld8 r3 = [r3];; st8 [r3] = reg + +#define ST8OFF(a,b,d) st8 [a] = b, d +#define LD8OFF(a,b,d) ld8 a = [b], d +#define STFDOFF(a,b,d) stfd [a] = b, d +#define LDFDOFF(a,b,d) ldfd a = [b], d +#define STFSPILLOFF(a,b,d) stf.spill [a] = b, d +#define LDFFILLOFF(a,b,d) ldf.fill a = [b], d + +#define SAVE2(a,b) ST8OFF(r2, a, 16); ST8OFF(r3, b, 16) +#define SAVE4(a,b,c,d) SAVE2(a,b);; SAVE2(c,d) +#define SAVE8(a,b,c,d,e,f,g,h) SAVE4(a,b,c,d);; SAVE4(e,f,g,h) + +#define LOAD2(a,b) LD8OFF(a, r2, 16); LD8OFF(b, r3, 16) +#define LOAD4(a,b,c,d) LOAD2(a,b);; LOAD2(c,d) +#define LOAD8(a,b,c,d,e,f,g,h) LOAD4(a,b,c,d);; LOAD4(e,f,g,h) + +#define FSAVE2(a,b) STFDOFF(r2, a, 16); STFDOFF(r3, b, 16) +#define FSAVE4(a,b,c,d) FSAVE2(a,b);; FSAVE2(c,d) +#define FSAVE8(a,b,c,d,e,f,g,h) FSAVE4(a,b,c,d);; FSAVE4(e,f,g,h) + +#define FLOAD2(a,b) LDFDOFF(a, r2, 16); LDFDOFF(b, r3, 16) +#define FLOAD4(a,b,c,d) FLOAD2(a,b);; FLOAD2(c,d) +#define FLOAD8(a,b,c,d,e,f,g,h) FLOAD4(a,b,c,d);; FLOAD4(e,f,g,h) + +#define FSPILL2(a,b) STFSPILLOFF(r2, a, 32); STFSPILLOFF(r3, b, 32) +#define FSPILL4(a,b,c,d) FSPILL2(a,b);; FSPILL2(c,d) +#define FSPILL8(a,b,c,d,e,f,g,h) FSPILL4(a,b,c,d);; FSPILL4(e,f,g,h) + +#define FFILL2(a,b) LDFFILLOFF(a, r2, 32); LDFFILLOFF(b, r3, 32) +#define FFILL4(a,b,c,d) FFILL2(a,b);; FFILL2(c,d) +#define FFILL8(a,b,c,d,e,f,g,h) FFILL4(a,b,c,d);; FFILL4(e,f,g,h) + +/* Allocation */ + .text + + .global caml_allocN# + .proc caml_allocN# + .align 16 + +/* caml_allocN: all code generator registers preserved, + gp preserved, r2 = requested size */ + +caml_allocN: + sub r4 = r4, r2 ;; + cmp.ltu p0, p6 = r4, r5 + (p6) br.ret.sptk b0 ;; + /* Stash return address at sp (in stack scratch area) */ + mov r3 = b0 ;; + st8 [sp] = r3 + /* Call GC */ + br.call.sptk b0 = caml_call_gc# ;; + /* Return to caller */ + ld8 r3 = [sp] ;; + mov b0 = r3 ;; + br.ret.sptk b0 + + .endp caml_allocN# + +/* caml_call_gc: all code generator registers preserved, + gp preserved, r2 = requested size */ + + .global caml_call_gc# + .proc caml_call_gc# + .align 16 +caml_call_gc: + /* Allocate stack frame */ + add sp = -(16 + 16 + 80*8 + 42*8), sp ;; + + /* Save requested size and GP on stack */ + add r3 = 16, sp ;; + ST8OFF(r3, r2, 8) ;; + st8 [r3] = gp + + /* Record lowest stack address, return address, GC regs */ + mov r2 = b0 ;; + STOREGLOBAL(r2, caml_last_return_address#) + add r2 = (16 + 16 + 80*8 + 42*8), sp ;; + STOREGLOBAL(r2, caml_bottom_of_stack#) + add r2 = (16 + 16), sp ;; + STOREGLOBAL(r2, caml_gc_regs#) + + /* Save all integer regs used by the code generator in the context */ +.L100: add r3 = 8, r2 ;; + SAVE4(r8,r9,r10,r11) ;; + SAVE8(r16,r17,r18,r19,r20,r21,r22,r23) ;; + SAVE8(r24,r25,r26,r27,r28,r29,r30,r31) ;; + SAVE8(r32,r33,r34,r35,r36,r37,r38,r39) ;; + SAVE8(r40,r41,r42,r43,r44,r45,r46,r47) ;; + SAVE8(r48,r49,r50,r51,r52,r53,r54,r55) ;; + SAVE8(r56,r57,r58,r59,r60,r61,r62,r63) ;; + SAVE8(r64,r65,r66,r67,r68,r69,r70,r71) ;; + SAVE8(r72,r73,r74,r75,r76,r77,r78,r79) ;; + SAVE8(r80,r81,r82,r83,r84,r85,r86,r87) ;; + SAVE4(r88,r89,r90,r91) ;; + + /* Save all floating-point registers not preserved by C */ + FSAVE2(f6,f7) ;; + FSAVE8(f8,f9,f10,f11,f12,f13,f14,f15) ;; + FSAVE8(f32,f33,f34,f35,f36,f37,f38,f39) ;; + FSAVE8(f40,f41,f42,f43,f44,f45,f46,f47) ;; + FSAVE8(f48,f49,f50,f51,f52,f53,f54,f55) ;; + FSAVE8(f56,f57,f58,f59,f60,f61,f62,f63) ;; + + /* Save current allocation pointer for debugging purposes */ + STOREGLOBAL(r4, caml_young_ptr#) + + /* Save trap pointer in case an exception is raised */ + STOREGLOBAL(r6, caml_exception_pointer#) + + /* Call the garbage collector */ + br.call.sptk b0 = caml_garbage_collection# ;; + + /* Restore gp */ + add r3 = 24, sp ;; + ld8 gp = [r3] + + /* Restore all integer regs from GC context */ + add r2 = (16 + 16), sp ;; + add r3 = 8, r2 ;; + LOAD4(r8,r9,r10,r11) ;; + LOAD8(r16,r17,r18,r19,r20,r21,r22,r23) ;; + LOAD8(r24,r25,r26,r27,r28,r29,r30,r31) ;; + LOAD8(r32,r33,r34,r35,r36,r37,r38,r39) ;; + LOAD8(r40,r41,r42,r43,r44,r45,r46,r47) ;; + LOAD8(r48,r49,r50,r51,r52,r53,r54,r55) ;; + LOAD8(r56,r57,r58,r59,r60,r61,r62,r63) ;; + LOAD8(r64,r65,r66,r67,r68,r69,r70,r71) ;; + LOAD8(r72,r73,r74,r75,r76,r77,r78,r79) ;; + LOAD8(r80,r81,r82,r83,r84,r85,r86,r87) ;; + LOAD4(r88,r89,r90,r91) ;; + + /* Restore all floating-point registers not preserved by C */ + FLOAD2(f6,f7) ;; + FLOAD8(f8,f9,f10,f11,f12,f13,f14,f15) ;; + FLOAD8(f32,f33,f34,f35,f36,f37,f38,f39) ;; + FLOAD8(f40,f41,f42,f43,f44,f45,f46,f47) ;; + FLOAD8(f48,f49,f50,f51,f52,f53,f54,f55) ;; + FLOAD8(f56,f57,f58,f59,f60,f61,f62,f63) ;; + + /* Reload new allocation pointer and allocation limit */ + LOADGLOBAL(r4, caml_young_ptr#) + LOADGLOBAL(r5, caml_young_limit#) + + /* Allocate space for the block */ + add r3 = 16, sp ;; + ld8 r2 = [r3] ;; + sub r4 = r4, r2 ;; + cmp.ltu p6, p0 = r4, r5 /* enough space? */ + (p6) br.cond.spnt .L100 ;; /* no: call GC again */ + + /* Reload return address and say that we are back into Caml code */ + ADDRGLOBAL(r3, caml_last_return_address#) ;; + ld8 r2 = [r3] + st8 [r3] = r0 ;; + + /* Return to caller */ + mov b0 = r2 + add sp = (16 + 16 + 80*8 + 42*8), sp ;; + br.ret.sptk b0 + + .endp caml_call_gc# + +/* Call a C function from Caml */ +/* Function to call is in r2 */ + + .global caml_c_call# + .proc caml_c_call# + .align 16 + +caml_c_call: + /* The Caml code that called us does not expect any + code-generator registers to be preserved */ + + /* Recover entry point from the function pointer in r2 */ + LD8OFF(r3, r2, 8) ;; + mov b6 = r3 + + /* Preserve gp in r7 */ + mov r7 = gp + + /* Record lowest stack address and return address */ + mov r14 = b0 + STOREGLOBAL(sp, caml_bottom_of_stack#) ;; + STOREGLOBAL(r14, caml_last_return_address#) + + /* Make the exception handler and alloc ptr available to the C code */ + STOREGLOBAL(r4, caml_young_ptr#) + STOREGLOBAL(r6, caml_exception_pointer#) + + /* Recover gp from the function pointer in r2 */ + ld8 gp = [r2] + + /* Call the function */ + br.call.sptk b0 = b6 ;; + + /* Restore gp */ + mov gp = r7 ;; + + /* Reload alloc ptr and alloc limit */ + LOADGLOBAL(r4, caml_young_ptr#) + LOADGLOBAL(r5, caml_young_limit#) + + /* Reload return address and say that we are back into Caml code */ + ADDRGLOBAL(r3, caml_last_return_address#) ;; + ld8 r2 = [r3] + st8 [r3] = r0 ;; + + /* Return to caller */ + mov b0 = r2 ;; + br.ret.sptk b0 + + .endp caml_c_call# + +/* Start the Caml program */ + + .global caml_start_program# + .proc caml_start_program# + .align 16 + +caml_start_program: + ADDRGLOBAL(r2, caml_program#) ;; + mov b6 = r2 + + /* Code shared with caml_callback* */ +.L103: + /* Allocate 64 "out" registers (for the Caml code) and no locals */ + alloc r3 = ar.pfs, 0, 0, 64, 0 + add sp = -(56 * 8), sp ;; + + /* Save all callee-save registers on stack */ + add r2 = 16, sp ;; + ST8OFF(r2, r3, 8) /* 0 : ar.pfs */ + mov r3 = b0 ;; + ST8OFF(r2, r3, 8) ;; /* 1 : return address */ + ST8OFF(r2, gp, 8) /* 2 : gp */ + mov r3 = pr ;; + ST8OFF(r2, r3, 8) /* 3 : predicates */ + mov r3 = ar.fpsr ;; + ST8OFF(r2, r3, 8) /* 4 : ar.fpsr */ + mov r3 = ar.unat ;; + ST8OFF(r2, r3, 8) /* 5 : ar.unat */ + mov r3 = ar.lc ;; + ST8OFF(r2, r3, 8) /* 6 : ar.lc */ + mov r3 = b1 ;; + ST8OFF(r2, r3, 8) /* 7 - 11 : b1 - b5 */ + mov r3 = b2 ;; + ST8OFF(r2, r3, 8) + mov r3 = b3 ;; + ST8OFF(r2, r3, 8) + mov r3 = b4 ;; + ST8OFF(r2, r3, 8) + mov r3 = b5 ;; + ST8OFF(r2, r3, 8) ;; + + add r3 = 8, r2 ;; + SAVE4(r4,r5,r6,r7) ;; /* 12 - 15 : r4 - r7 */ + + add r3 = 16, r2 ;; /* 16 - 55 : f2 - f5, f16 - f31 */ + FSPILL4(f2,f3,f4,f5) ;; + FSPILL8(f16,f17,f18,f19,f20,f21,f22,f23) ;; + FSPILL8(f24,f25,f26,f27,f28,f29,f30,f31) ;; + + /* Set up a callback link on the stack. In addition to + the normal callback link contents (saved values of + caml_bottom_of_stack, caml_last_return_address and + caml_gc_regs), we also save there caml_saved_bsp + and caml_saved_rnat */ + add sp = -48, sp + LOADGLOBAL(r3, caml_bottom_of_stack#) + add r2 = 16, sp ;; + ST8OFF(r2, r3, 8) + LOADGLOBAL(r3, caml_last_return_address#) ;; + ST8OFF(r2, r3, 8) + LOADGLOBAL(r3, caml_gc_regs#) ;; + ST8OFF(r2, r3, 8) + LOADGLOBAL(r3, caml_saved_bsp#) ;; + ST8OFF(r2, r3, 8) + LOADGLOBAL(r3, caml_saved_rnat#) ;; + ST8OFF(r2, r3, 8) + + /* Set up a trap frame to catch exceptions escaping the Caml code */ + mov r6 = sp + add sp = -16, sp ;; + LOADGLOBAL(r3, caml_exception_pointer#) + add r2 = 16, sp ;; + ST8OFF(r2, r3, 8) +.L110: mov r3 = ip ;; + add r3 = .L101 - .L110, r3 ;; + ST8OFF(r2, r3, 8) ;; + + /* Save ar.bsp, flush register window, and save ar.rnat */ + mov r2 = ar.bsp ;; + STOREGLOBAL(r2, caml_saved_bsp#) ;; + mov r14 = ar.rsc ;; + and r2 = ~0x3, r14;; /* set rsc.mode = 0 */ + mov ar.rsc = r2 ;; /* RSE is in enforced lazy mode */ + flushrs ;; /* must be first instr in group */ + mov r2 = ar.rnat ;; + STOREGLOBAL(r2, caml_saved_rnat#) + mov ar.rsc = r14 /* restore original RSE mode */ + + /* Reload allocation pointers */ + LOADGLOBAL(r4, caml_young_ptr#) + LOADGLOBAL(r5, caml_young_limit#) + + /* We are back into Caml code */ + STOREGLOBAL(r0, caml_last_return_address#) + + /* Call the Caml code */ + br.call.sptk b0 = b6 ;; +.L102: + + /* Pop the trap frame, restoring caml_exception_pointer */ + add sp = 16, sp ;; + ld8 r2 = [sp] ;; + STOREGLOBAL(r2, caml_exception_pointer#) + +.L104: + /* Pop the callback link, restoring the global variables */ + add r14 = 16, sp ;; + LD8OFF(r2, r14, 8) ;; + STOREGLOBAL(r2, caml_bottom_of_stack#) + LD8OFF(r2, r14, 8) ;; + STOREGLOBAL(r2, caml_last_return_address#) + LD8OFF(r2, r14, 8) ;; + STOREGLOBAL(r2, caml_gc_regs#) + LD8OFF(r2, r14, 8) ;; + STOREGLOBAL(r2, caml_saved_bsp#) + LD8OFF(r2, r14, 8) ;; + STOREGLOBAL(r2, caml_saved_rnat#) + add sp = 48, sp + + /* Update allocation pointer */ + STOREGLOBAL(r4, caml_young_ptr#) + + /* Restore all callee-save registers from stack */ + add r2 = 16, sp ;; + LD8OFF(r3, r2, 8) ;; /* 0 : ar.pfs */ + mov ar.pfs = r3 + LD8OFF(r3, r2, 8) ;; /* 1 : return address */ + mov b0 = r3 + LD8OFF(gp, r2, 8) ;; /* 2 : gp */ + LD8OFF(r3, r2, 8) ;; /* 3 : predicates */ + mov pr = r3, -1 + LD8OFF(r3, r2, 8) ;; /* 4 : ar.fpsr */ + mov ar.fpsr = r3 + LD8OFF(r3, r2, 8) ;; /* 5 : ar.unat */ + mov ar.unat = r3 + LD8OFF(r3, r2, 8) ;; /* 6 : ar.lc */ + mov ar.lc = r3 + LD8OFF(r3, r2, 8) ;; /* 7 - 11 : b1 - b5 */ + mov b1 = r3 + LD8OFF(r3, r2, 8) ;; + mov b2 = r3 + LD8OFF(r3, r2, 8) ;; + mov b3 = r3 + LD8OFF(r3, r2, 8) ;; + mov b4 = r3 + LD8OFF(r3, r2, 8) ;; + mov b5 = r3 + + add r3 = 8, r2 ;; + LOAD4(r4,r5,r6,r7) ;; /* 12 - 15 : r4 - r7 */ + + add r3 = 16, r2 ;; /* 16 - 55 : f2 - f5, f16 - f31 */ + FFILL4(f2,f3,f4,f5) ;; + FFILL8(f16,f17,f18,f19,f20,f21,f22,f23) ;; + FFILL8(f24,f25,f26,f27,f28,f29,f30,f31) ;; + + /* Pop stack frame and return */ + add sp = (56 * 8), sp + br.ret.sptk.many b0 ;; + + /* The trap handler */ +.L101: + /* Save exception pointer */ + STOREGLOBAL(r6, caml_exception_pointer#) + + /* Encode exception bucket as exception result */ + or r8 = 2, r8 + + /* Return it */ + br.sptk .L104 ;; + + .endp caml_start_program# + +/* Raise an exception from C */ + + .global caml_raise_exception# + .proc caml_raise_exception# + .align 16 +caml_raise_exception: + /* Allocate 64 "out" registers (for the Caml code) and no locals */ + /* Since we don't return, don't bother saving the PFS */ + alloc r2 = ar.pfs, 0, 0, 64, 0 + + /* Move exn bucket where Caml expects it */ + mov r8 = r32 ;; + + /* Perform "context switch" as per the Software Conventions Guide, + chapter 10 */ + flushrs ;; /* flush dirty registers to stack */ + mov r14 = ar.rsc ;; + and r2 = ~0x3, r14;; /* set rsc.mode = 0 */ + dep r2 = r0, r2, 16, 4 ;; /* clear rsc.loadrs */ + mov ar.rsc = r2 ;; /* RSE is in enforced lazy mode */ + invala ;; /* Invalidate ALAT */ + LOADGLOBAL(r2, caml_saved_bsp#) ;; + mov ar.bspstore = r2 /* Restore ar.bspstore */ + LOADGLOBAL(r2, caml_saved_rnat#) ;; + mov ar.rnat = r2 /* Restore ar.rnat */ + mov ar.rsc = r14 ;; /* Restore original RSE mode */ + + /* Reload allocation pointers and exception pointer */ + LOADGLOBAL(r4, caml_young_ptr#) + LOADGLOBAL(r5, caml_young_limit#) + LOADGLOBAL(r6, caml_exception_pointer#) + + /* Say that we're back into Caml */ + STOREGLOBAL(r0, caml_last_return_address#) + + /* Raise the exception proper */ + mov sp = r6 + add r2 = 8, r6 ;; + ld8 r6 = [r6] + ld8 r2 = [r2] ;; + mov b6 = r2 ;; + + /* Branch to handler. Must use a call so as to set up the + CFM and PFS correctly. */ + br.call.sptk.many b0 = b6 + + .endp caml_raise_exception + +/* Callbacks from C to Caml */ + + .global caml_callback_exn# + .proc caml_callback_exn# + .align 16 +caml_callback_exn: + /* Initial shuffling of arguments */ + ld8 r3 = [r32] /* code pointer */ + mov r2 = r32 + mov r32 = r33 ;; /* first arg */ + mov r33 = r2 /* environment */ + mov b6 = r3 + br.sptk .L103 ;; + + .endp caml_callback_exn# + + .global caml_callback2_exn# + .proc caml_callback2_exn# + .align 16 +caml_callback2_exn: + /* Initial shuffling of arguments */ + ADDRGLOBAL(r3, caml_apply2) /* code pointer */ + mov r2 = r32 + mov r32 = r33 /* first arg */ + mov r33 = r34 ;; /* second arg */ + mov r34 = r2 /* environment */ + mov b6 = r3 + br.sptk .L103 ;; + + .endp caml_callback2_exn# + + .global caml_callback3_exn# + .proc caml_callback3_exn# + .align 16 +caml_callback3_exn: + /* Initial shuffling of arguments */ + ADDRGLOBAL(r3, caml_apply3) /* code pointer */ + mov r2 = r32 + mov r32 = r33 /* first arg */ + mov r33 = r34 /* second arg */ + mov r34 = r35 ;; /* third arg */ + mov r35 = r2 /* environment */ + mov b6 = r3 + br.sptk .L103 ;; + + .endp caml_callback3_exn# + +/* Glue code to call [caml_array_bound_error] */ + + .global caml_ml_array_bound_error# + .proc caml_ml_array_bound_error# + .align 16 +caml_ml_array_bound_error: + ADDRGLOBAL(r2, @fptr(caml_array_bound_error#)) + br.sptk caml_c_call /* never returns */ + + .rodata + + .global caml_system__frametable# + .type caml_system__frametable#, @object + .size caml_system__frametable#, 8 +caml_system__frametable: + data8 1 /* one descriptor */ + data8 .L102 /* return address into callback */ + data2 -1 /* negative frame size => use callback link */ + data2 0 /* no roots here */ + .align 8 + +/* Global variables used by caml_raise_exception */ + + .common caml_saved_bsp#, 8, 8 + .common caml_saved_rnat#, 8, 8 diff --git a/asmrun/m68k.S b/asmrun/m68k.S new file mode 100644 index 0000000..8abe110 --- /dev/null +++ b/asmrun/m68k.S @@ -0,0 +1,244 @@ +|*********************************************************************** +|* * +|* Objective Caml * +|* * +|* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +|* * +|* Copyright 1996 Institut National de Recherche en Informatique et * +|* en Automatique. All rights reserved. This file is distributed * +|* under the terms of the GNU Library General Public License, with * +|* the special exception on linking described in file ../LICENSE. * +|* * +|*********************************************************************** + +| $Id: m68k.S,v 1.15 2004-01-03 12:51:19 doligez Exp $ + +| Asm part of the runtime system, Motorola 68k processor + + .comm _caml_requested_size, 4 + +| Allocation + + .text + .globl _caml_call_gc + .globl _caml_alloc1 + .globl _caml_alloc2 + .globl _caml_alloc3 + .globl _caml_allocN + +_caml_call_gc: + | Save desired size + movel d5, _caml_requested_size + | Record lowest stack address and return address + movel a7@, _caml_last_return_address + movel a7, d5 + addql #4, d5 + movel d5, _caml_bottom_of_stack + | Record current allocation pointer (for debugging) + movel d6, _caml_young_ptr + | Save all regs used by the code generator + movel d4, a7@- + movel d3, a7@- + movel d2, a7@- + movel d1, a7@- + movel d0, a7@- + movel a6, a7@- + movel a5, a7@- + movel a4, a7@- + movel a3, a7@- + movel a2, a7@- + movel a1, a7@- + movel a0, a7@- + movel a7, _caml_gc_regs + fmovem fp0-fp7, a7@- + | Call the garbage collector + jbsr _caml_garbage_collection + | Restore all regs used by the code generator + fmovem a7@+, fp0-fp7 + movel a7@+, a0 + movel a7@+, a1 + movel a7@+, a2 + movel a7@+, a3 + movel a7@+, a4 + movel a7@+, a5 + movel a7@+, a6 + movel a7@+, d0 + movel a7@+, d1 + movel a7@+, d2 + movel a7@+, d3 + movel a7@+, d4 + | Reload allocation pointer and allocate block + movel _caml_young_ptr, d6 + subl _caml_requested_size, d6 + | Return to caller + rts + +_caml_alloc1: + subql #8, d6 + cmpl _caml_young_limit, d6 + bcs L100 + rts +L100: moveq #8, d5 + bra _caml_call_gc + +_caml_alloc2: + subl #12, d6 + cmpl _caml_young_limit, d6 + bcs L101 + rts +L101: moveq #12, d5 + bra _caml_call_gc + +_caml_alloc3: + subl #16, d6 + cmpl _caml_young_limit, d6 + bcs L102 + rts +L102: moveq #16, d5 + bra _caml_call_gc + +_caml_allocN: + subl d5, d6 + cmpl _caml_young_limit, d6 + bcs _caml_call_gc + rts + +| Call a C function from Caml + + .globl _caml_c_call + +_caml_c_call: + | Record lowest stack address and return address + movel a7@+, _caml_last_return_address + movel a7, _caml_bottom_of_stack + | Save allocation pointer and exception pointer + movel d6, _caml_young_ptr + movel d7, _caml_exception_pointer + | Call the function (address in a0) + jbsr a0@ + | Reload allocation pointer + movel _caml_young_ptr, d6 + | Return to caller + movel _caml_last_return_address, a1 + jmp a1@ + +| Start the Caml program + + .globl _caml_start_program + +_caml_start_program: + | Save callee-save registers + moveml a2-a6/d2-d7, a7@- + fmovem fp2-fp7, a7@- + | Initial code point is caml_program + lea _caml_program, a5 + +| Code shared between caml_start_program and caml_callback* + +L106: + | Build a callback link + movel _caml_gc_regs, a7@- + movel _caml_last_return_address, a7@- + movel _caml_bottom_of_stack, a7@- + | Build an exception handler + pea L108 + movel _caml_exception_pointer, a7@- + movel a7, d7 + | Load allocation pointer + movel _caml_young_ptr, d6 + | Call the Caml code + jbsr a5@ +L107: + | Move result where C code expects it + movel a0, d0 + | Save allocation pointer + movel d6, _caml_young_ptr + | Pop the exception handler + movel a7@+, _caml_exception_pointer + addql #4, a7 +L109: + | Pop the callback link, restoring the global variables + | used by caml_c_call + movel a7@+, _caml_bottom_of_stack + movel a7@+, _caml_last_return_address + movel a7@+, _caml_gc_regs + | Restore callee-save registers and return + fmovem a7@+, fp2-fp7 + moveml a7@+, a2-a6/d2-d7 + unlk a6 + rts +L108: + | Exception handler + | Save allocation pointer and exception pointer + movel d6, _caml_young_ptr + movel d7, _caml_exception_pointer + | Encode exception bucket as an exception result + movel a0, d0 + orl #2, d0 + | Return it + bra L109 + +| Raise an exception from C + + .globl _caml_raise_exception +_caml_raise_exception: + movel a7@(4), a0 | exception bucket + movel _caml_young_ptr, d6 + movel _caml_exception_pointer, a7 + movel a7@+, d7 + rts + +| Callback from C to Caml + + .globl _caml_callback_exn +_caml_callback_exn: + link a6, #0 + | Save callee-save registers + moveml a2-a6/d2-d7, a7@- + fmovem fp2-fp7, a7@- + | Initial loading of arguments + movel a6@(8), a1 | closure + movel a6@(12), a0 | argument + movel a1@(0), a5 | code pointer + bra L106 + + .globl _caml_callback2_exn +_caml_callback2_exn: + link a6, #0 + | Save callee-save registers + moveml a2-a6/d2-d7, a7@- + fmovem fp2-fp7, a7@- + | Initial loading of arguments + movel a6@(8), a2 | closure + movel a6@(12), a0 | first argument + movel a6@(16), a1 | second argument + lea _caml_apply2, a5 | code pointer + bra L106 + + .globl _caml_callback3_exn +_caml_callback3_exn: + link a6, #0 + | Save callee-save registers + moveml a2-a6/d2-d7, a7@- + fmovem fp2-fp7, a7@- + | Initial loading of arguments + movel a6@(8), a3 | closure + movel a6@(12), a0 | first argument + movel a6@(16), a1 | second argument + movel a6@(20), a2 | third argument + lea _caml_apply3, a5 | code pointer + bra L106 + + .globl _caml_ml_array_bound_error +_caml_ml_array_bound_error: + | Load address of [caml_array_bound_error] in a0 and call it + lea _caml_array_bound_error, a0 + bra _caml_c_call + + .data + .globl _caml_system__frametable +_caml_system__frametable: + .long 1 | one descriptor + .long L107 | return address into callback + .word -1 | negative frame size => use callback link + .word 0 | no roots here diff --git a/asmrun/mips.s b/asmrun/mips.s new file mode 100644 index 0000000..f223812 --- /dev/null +++ b/asmrun/mips.s @@ -0,0 +1,386 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mips.s,v 1.12 2004-07-13 12:18:53 xleroy Exp $ */ + +/* Asm part of the runtime system, Mips processor, IRIX n32 conventions */ + +/* Allocation */ + + .text + + .globl caml_call_gc + .ent caml_call_gc + +caml_call_gc: + /* Reserve stack space for registers and saved $gp */ + /* 32 * 8 = 0x100 for float regs + 22 * 4 = 0x58 for integer regs + 8 = 0x8 for saved $gp ====> 0x160 total */ + subu $sp, $sp, 0x160 + /* Reinit $gp */ + .cpsetup $25, 0x158, caml_call_gc + /* Record return address */ + sw $31, caml_last_return_address + /* Record lowest stack address */ + addu $24, $sp, 0x160 + sw $24, caml_bottom_of_stack + /* Save pointer to register array */ + addu $24, $sp, 0x100 + sw $24, caml_gc_regs + /* Save current allocation pointer for debugging purposes */ + sw $22, caml_young_ptr + /* Save the exception handler (if e.g. a sighandler raises) */ + sw $30, caml_exception_pointer + /* Save all regs used by the code generator on the stack */ + sw $2, 2 * 4($24) + sw $3, 3 * 4($24) + sw $4, 4 * 4($24) + sw $5, 5 * 4($24) + sw $6, 6 * 4($24) + sw $7, 7 * 4($24) + sw $8, 8 * 4($24) + sw $9, 9 * 4($24) + sw $10, 10 * 4($24) + sw $11, 11 * 4($24) + sw $12, 12 * 4($24) + sw $13, 13 * 4($24) + sw $14, 14 * 4($24) + sw $15, 15 * 4($24) + sw $16, 16 * 4($24) + sw $17, 17 * 4($24) + sw $18, 18 * 4($24) + sw $19, 19 * 4($24) + sw $20, 20 * 4($24) + sw $21, 21 * 4($24) + s.d $f0, 0 * 8($sp) + s.d $f1, 1 * 8($sp) + s.d $f2, 2 * 8($sp) + s.d $f3, 3 * 8($sp) + s.d $f4, 4 * 8($sp) + s.d $f5, 5 * 8($sp) + s.d $f6, 6 * 8($sp) + s.d $f7, 7 * 8($sp) + s.d $f8, 8 * 8($sp) + s.d $f9, 9 * 8($sp) + s.d $f10, 10 * 8($sp) + s.d $f11, 11 * 8($sp) + s.d $f12, 12 * 8($sp) + s.d $f13, 13 * 8($sp) + s.d $f14, 14 * 8($sp) + s.d $f15, 15 * 8($sp) + s.d $f16, 16 * 8($sp) + s.d $f17, 17 * 8($sp) + s.d $f18, 18 * 8($sp) + s.d $f19, 19 * 8($sp) + s.d $f20, 20 * 8($sp) + s.d $f21, 21 * 8($sp) + s.d $f22, 22 * 8($sp) + s.d $f23, 23 * 8($sp) + s.d $f24, 24 * 8($sp) + s.d $f25, 25 * 8($sp) + s.d $f26, 26 * 8($sp) + s.d $f27, 27 * 8($sp) + s.d $f28, 28 * 8($sp) + s.d $f29, 29 * 8($sp) + s.d $f30, 30 * 8($sp) + s.d $f31, 31 * 8($sp) + /* Call the garbage collector */ + jal caml_garbage_collection + /* Restore all regs used by the code generator */ + addu $24, $sp, 0x100 + lw $2, 2 * 4($24) + lw $3, 3 * 4($24) + lw $4, 4 * 4($24) + lw $5, 5 * 4($24) + lw $6, 6 * 4($24) + lw $7, 7 * 4($24) + lw $8, 8 * 4($24) + lw $9, 9 * 4($24) + lw $10, 10 * 4($24) + lw $11, 11 * 4($24) + lw $12, 12 * 4($24) + lw $13, 13 * 4($24) + lw $14, 14 * 4($24) + lw $15, 15 * 4($24) + lw $16, 16 * 4($24) + lw $17, 17 * 4($24) + lw $18, 18 * 4($24) + lw $19, 19 * 4($24) + lw $20, 20 * 4($24) + lw $21, 21 * 4($24) + l.d $f0, 0 * 8($sp) + l.d $f1, 1 * 8($sp) + l.d $f2, 2 * 8($sp) + l.d $f3, 3 * 8($sp) + l.d $f4, 4 * 8($sp) + l.d $f5, 5 * 8($sp) + l.d $f6, 6 * 8($sp) + l.d $f7, 7 * 8($sp) + l.d $f8, 8 * 8($sp) + l.d $f9, 9 * 8($sp) + l.d $f10, 10 * 8($sp) + l.d $f11, 11 * 8($sp) + l.d $f12, 12 * 8($sp) + l.d $f13, 13 * 8($sp) + l.d $f14, 14 * 8($sp) + l.d $f15, 15 * 8($sp) + l.d $f16, 16 * 8($sp) + l.d $f17, 17 * 8($sp) + l.d $f18, 18 * 8($sp) + l.d $f19, 19 * 8($sp) + l.d $f20, 20 * 8($sp) + l.d $f21, 21 * 8($sp) + l.d $f22, 22 * 8($sp) + l.d $f23, 23 * 8($sp) + l.d $f24, 24 * 8($sp) + l.d $f25, 25 * 8($sp) + l.d $f26, 26 * 8($sp) + l.d $f27, 27 * 8($sp) + l.d $f28, 28 * 8($sp) + l.d $f29, 29 * 8($sp) + l.d $f30, 30 * 8($sp) + l.d $f31, 31 * 8($sp) + /* Reload new allocation pointer and allocation limit */ + lw $22, caml_young_ptr + lw $23, caml_young_limit + /* Reload return address */ + lw $31, caml_last_return_address + /* Say that we are back into Caml code */ + sw $0, caml_last_return_address + /* Adjust return address to restart the allocation sequence */ + subu $31, $31, 16 + /* Return */ + .cpreturn + addu $sp, $sp, 0x160 + j $31 + + .end caml_call_gc + +/* Call a C function from Caml */ + + .globl caml_c_call + .ent caml_c_call + +caml_c_call: + /* Function to call is in $24 */ + /* Set up $gp, saving caller's $gp in callee-save register $19 */ + .cpsetup $25, $19, caml_c_call + /* Preload addresses of interesting global variables + in callee-save registers */ + la $16, caml_last_return_address + la $17, caml_young_ptr + /* Save return address, bottom of stack, alloc ptr, exn ptr */ + sw $31, 0($16) /* caml_last_return_address */ + sw $sp, caml_bottom_of_stack + sw $22, 0($17) /* caml_young_ptr */ + sw $30, caml_exception_pointer + /* Call C function */ + move $25, $24 + jal $24 + /* Reload return address, alloc ptr, alloc limit */ + lw $31, 0($16) /* caml_last_return_address */ + lw $22, 0($17) /* caml_young_ptr */ + lw $23, caml_young_limit /* caml_young_limit */ + /* Zero caml_last_return_address, indicating we're back in Caml code */ + sw $0, 0($16) /* caml_last_return_address */ + /* Restore $gp and return */ + move $gp, $19 + j $31 + .end caml_c_call + +/* Start the Caml program */ + + .globl caml_start_program + .globl stray_exn_handler + .ent caml_start_program +caml_start_program: + /* Reserve space for callee-save registers */ + subu $sp, $sp, 0x90 + /* Setup $gp */ + .cpsetup $25, 0x80, caml_start_program + /* Load in $24 the code address to call */ + la $24, caml_program + /* Code shared with caml_callback* */ +$103: + /* Save return address */ + sd $31, 0x88($sp) + /* Save all callee-save registers */ + sd $16, 0x0($sp) + sd $17, 0x8($sp) + sd $18, 0x10($sp) + sd $19, 0x18($sp) + sd $20, 0x20($sp) + sd $21, 0x28($sp) + sd $22, 0x30($sp) + sd $23, 0x38($sp) + sd $30, 0x40($sp) + s.d $f20, 0x48($sp) + s.d $f22, 0x50($sp) + s.d $f24, 0x58($sp) + s.d $f26, 0x60($sp) + s.d $f28, 0x68($sp) + s.d $f30, 0x70($sp) + /* Set up a callback link on the stack. */ + subu $sp, $sp, 16 + lw $2, caml_bottom_of_stack + sw $2, 0($sp) + lw $3, caml_last_return_address + sw $3, 4($sp) + lw $4, caml_gc_regs + sw $4, 8($sp) + /* Set up a trap frame to catch exceptions escaping the Caml code */ + subu $sp, $sp, 16 + lw $30, caml_exception_pointer + sw $30, 0($sp) + la $2, $105 + sw $2, 4($sp) + sw $gp, 8($sp) + move $30, $sp + /* Reload allocation pointers */ + lw $22, caml_young_ptr + lw $23, caml_young_limit + /* Say that we are back into Caml code */ + sw $0, caml_last_return_address + /* Call the Caml code */ + move $25, $24 + jal $24 +$104: + /* Pop the trap frame, restoring caml_exception_pointer */ + lw $24, 0($sp) + sw $24, caml_exception_pointer + addu $sp, $sp, 16 +$106: + /* Pop the callback link, restoring the global variables */ + lw $24, 0($sp) + sw $24, caml_bottom_of_stack + lw $25, 4($sp) + sw $25, caml_last_return_address + lw $24, 8($sp) + sw $24, caml_gc_regs + addu $sp, $sp, 16 + /* Update allocation pointer */ + sw $22, caml_young_ptr + /* Reload callee-save registers and return */ + ld $31, 0x88($sp) + ld $16, 0x0($sp) + ld $17, 0x8($sp) + ld $18, 0x10($sp) + ld $19, 0x18($sp) + ld $20, 0x20($sp) + ld $21, 0x28($sp) + ld $22, 0x30($sp) + ld $23, 0x38($sp) + ld $30, 0x40($sp) + l.d $f20, 0x48($sp) + l.d $f22, 0x50($sp) + l.d $f24, 0x58($sp) + l.d $f26, 0x60($sp) + l.d $f28, 0x68($sp) + l.d $f30, 0x70($sp) + .cpreturn + addu $sp, $sp, 0x90 + j $31 + + /* The trap handler: encode exception bucket as an exception result + and return it */ +$105: + sw $30, caml_exception_pointer + or $2, $2, 2 + b $106 + + .end caml_start_program + +/* Raise an exception from C */ + + .globl caml_raise_exception + .ent caml_raise_exception +caml_raise_exception: + /* Setup $gp, discarding caller's $gp (we won't return) */ + .cpsetup $25, $24, caml_raise_exception + /* Branch to exn handler */ + move $2, $4 + lw $22, caml_young_ptr + lw $23, caml_young_limit + lw $sp, caml_exception_pointer + lw $30, 0($sp) + lw $24, 4($sp) + lw $gp, 8($sp) + addu $sp, $sp, 16 + j $24 + + .end caml_raise_exception + +/* Callback from C to Caml */ + + .globl caml_callback_exn + .ent caml_callback_exn +caml_callback_exn: + subu $sp, $sp, 0x90 + .cpsetup $25, 0x80, caml_callback_exn + /* Initial shuffling of arguments */ + move $9, $4 /* closure */ + move $8, $5 /* argument */ + lw $24, 0($4) /* code pointer */ + b $103 + .end caml_callback_exn + + .globl caml_callback2_exn + .ent caml_callback2_exn +caml_callback2_exn: + subu $sp, $sp, 0x90 + .cpsetup $25, 0x80, caml_callback2_exn + /* Initial shuffling of arguments */ + move $10, $4 /* closure */ + move $8, $5 /* first argument */ + move $9, $6 /* second argument */ + la $24, caml_apply2 /* code pointer */ + b $103 + + .end caml_callback2_exn + + .globl caml_callback3_exn + .ent caml_callback3_exn +caml_callback3_exn: + subu $sp, $sp, 0x90 + .cpsetup $25, 0x80, caml_callback3_exn + /* Initial shuffling of arguments */ + move $11, $4 /* closure */ + move $8, $5 /* first argument */ + move $9, $6 /* second argument */ + move $10, $7 /* third argument */ + la $24, caml_apply3 /* code pointer */ + b $103 + + .end caml_callback3_exn + +/* Glue code to call [caml_array_bound_error] */ + + .globl caml_ml_array_bound_error + .ent caml_ml_array_bound_error + +caml_ml_array_bound_error: + /* Setup $gp, discarding caller's $gp (we won't return) */ + .cpsetup $25, $24, caml_ml_array_bound_error + la $24, caml_array_bound_error + jal caml_c_call /* never returns */ + + .end caml_ml_array_bound_error + + .rdata + .globl caml_system__frametable +caml_system__frametable: + .word 1 /* one descriptor */ + .word $104 /* return address into callback */ + .half -1 /* negative frame size => use callback link */ + .half 0 /* no roots here */ diff --git a/asmrun/natdynlink.c b/asmrun/natdynlink.c new file mode 100644 index 0000000..84cfb59 --- /dev/null +++ b/asmrun/natdynlink.c @@ -0,0 +1,126 @@ +#include "misc.h" +#include "mlvalues.h" +#include "memory.h" +#include "stack.h" +#include "callback.h" +#include "alloc.h" +#include "natdynlink.h" +#include "osdeps.h" +#include "fail.h" + +#include +#include + +static void *getsym(void *handle, char *module, char *name){ + char *fullname = malloc(strlen(module) + strlen(name) + 5); + void *sym; + sprintf(fullname, "caml%s%s", module, name); + sym = caml_dlsym (handle, fullname); + /* printf("%s => %lx\n", fullname, (uintnat) sym); */ + free(fullname); + return sym; +} + +extern char caml_globals_map[]; + +CAMLprim value caml_natdynlink_getmap(value unit) +{ + return (value)caml_globals_map; +} + +CAMLprim value caml_natdynlink_globals_inited(value unit) +{ + return Val_int(caml_globals_inited); +} + +CAMLprim value caml_natdynlink_open(value filename, value global) +{ + CAMLparam1 (filename); + CAMLlocal1 (res); + void *sym; + void *handle; + + /* TODO: dlclose in case of error... */ + + handle = caml_dlopen(String_val(filename), 1, Int_val(global)); + + if (NULL == handle) + CAMLreturn(caml_copy_string(caml_dlerror())); + + sym = caml_dlsym(handle, "caml_plugin_header"); + if (NULL == sym) + CAMLreturn(caml_copy_string("not an OCaml plugin")); + + res = caml_alloc_tuple(2); + Field(res, 0) = (value) handle; + Field(res, 1) = (value) (sym); + CAMLreturn(res); +} + +CAMLprim value caml_natdynlink_run(void *handle, value symbol) { + CAMLparam1 (symbol); + CAMLlocal1 (result); + void *sym,*sym2; + +#define optsym(n) getsym(handle,unit,n) + char *unit; + void (*entrypoint)(void); + + unit = String_val(symbol); + + sym = optsym("__frametable"); + if (NULL != sym) caml_register_frametable(sym); + + sym = optsym(""); + if (NULL != sym) caml_register_dyn_global(sym); + + sym = optsym("__data_begin"); + sym2 = optsym("__data_end"); + if (NULL != sym && NULL != sym2) + caml_page_table_add(In_static_data, sym, sym2); + + sym = optsym("__code_begin"); + sym2 = optsym("__code_end"); + if (NULL != sym && NULL != sym2) + caml_page_table_add(In_code_area, sym, sym2); + + entrypoint = optsym("__entry"); + if (NULL != entrypoint) result = caml_callback((value)(&entrypoint), 0); + else result = Val_unit; + +#undef optsym + + CAMLreturn (result); +} + +CAMLprim value caml_natdynlink_run_toplevel(value filename, value symbol) +{ + CAMLparam2 (filename, symbol); + CAMLlocal2 (res, v); + void *handle; + + /* TODO: dlclose in case of error... */ + + handle = caml_dlopen(String_val(filename), 1, 1); + + if (NULL == handle) { + res = caml_alloc(1,1); + v = caml_copy_string(caml_dlerror()); + Store_field(res, 0, v); + } else { + res = caml_alloc(1,0); + v = caml_natdynlink_run(handle, symbol); + Store_field(res, 0, v); + } + CAMLreturn(res); +} + +CAMLprim value caml_natdynlink_loadsym(value symbol) +{ + CAMLparam1 (symbol); + CAMLlocal1 (sym); + + sym = (value) caml_globalsym(String_val(symbol)); + if (!sym) caml_failwith(String_val(symbol)); + CAMLreturn(sym); +} diff --git a/asmrun/natdynlink.h b/asmrun/natdynlink.h new file mode 100644 index 0000000..e69de29 diff --git a/asmrun/power-aix.S b/asmrun/power-aix.S new file mode 100644 index 0000000..cccba0a --- /dev/null +++ b/asmrun/power-aix.S @@ -0,0 +1,513 @@ +#********************************************************************* +#* * +#* Objective Caml * +#* * +#* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +#* * +#* Copyright 1996 Institut National de Recherche en Informatique et * +#* en Automatique. All rights reserved. This file is distributed * +#* under the terms of the GNU Library General Public License, with * +#* the special exception on linking described in file ../LICENSE. * +#* * +#********************************************************************* + +# $Id: power-aix.S,v 1.15 2004-01-03 12:51:19 doligez Exp $ + + .csect .text[PR] + +#### Invoke the garbage collector. r0 contains the return address + + .globl .caml_call_gc +.caml_call_gc: + # Set up stack frame + stwu 1, -0x1C0(1) + # 0x1C0 = 4*32 (int regs) + 8*32 (float regs) + 64 (space for C call) + # Record last return address into Caml code + lwz 11, L..caml_last_return_address(2) + stw 0, 0(11) + # Record return address into call_gc stub code + mflr 0 + stw 0, 0x1C0+8(1) + # Record lowest stack address + lwz 11, L..caml_bottom_of_stack(2) + addi 0, 1, 0x1C0 + stw 0, 0(11) + # Record pointer to register array + lwz 11, L..caml_gc_regs(2) + addi 0, 1, 8*32 + 64 + stw 0, 0(11) + # Save current allocation pointer for debugging purposes + lwz 11, L..caml_young_ptr(2) + stw 31, 0(11) + # Save exception pointer (if e.g. a sighandler raises) + lwz 11, L..caml_exception_pointer(2) + stw 29, 0(11) + # Save all registers used by the code generator + addi 11, 1, 8*32 + 64 - 4 + stwu 3, 4(11) + stwu 4, 4(11) + stwu 5, 4(11) + stwu 6, 4(11) + stwu 7, 4(11) + stwu 8, 4(11) + stwu 9, 4(11) + stwu 10, 4(11) + stwu 14, 4(11) + stwu 15, 4(11) + stwu 16, 4(11) + stwu 17, 4(11) + stwu 18, 4(11) + stwu 19, 4(11) + stwu 20, 4(11) + stwu 21, 4(11) + stwu 22, 4(11) + stwu 23, 4(11) + stwu 24, 4(11) + stwu 25, 4(11) + stwu 26, 4(11) + stwu 27, 4(11) + stwu 28, 4(11) + addi 11, 1, 64 - 8 + stfdu 1, 8(11) + stfdu 2, 8(11) + stfdu 3, 8(11) + stfdu 4, 8(11) + stfdu 5, 8(11) + stfdu 6, 8(11) + stfdu 7, 8(11) + stfdu 8, 8(11) + stfdu 9, 8(11) + stfdu 10, 8(11) + stfdu 11, 8(11) + stfdu 12, 8(11) + stfdu 13, 8(11) + stfdu 14, 8(11) + stfdu 15, 8(11) + stfdu 16, 8(11) + stfdu 17, 8(11) + stfdu 18, 8(11) + stfdu 19, 8(11) + stfdu 20, 8(11) + stfdu 21, 8(11) + stfdu 22, 8(11) + stfdu 23, 8(11) + stfdu 24, 8(11) + stfdu 25, 8(11) + stfdu 26, 8(11) + stfdu 27, 8(11) + stfdu 28, 8(11) + stfdu 29, 8(11) + stfdu 30, 8(11) + stfdu 31, 8(11) + # Call the GC + bl .caml_garbage_collection + or 0, 0, 0 + # Reload new allocation pointer and allocation limit + lwz 11, L..caml_young_ptr(2) + lwz 31, 0(11) + lwz 11, L..caml_young_limit(2) + lwz 30, 0(11) + # Restore all regs used by the code generator + addi 11, 1, 8*32 + 64 - 4 + lwzu 3, 4(11) + lwzu 4, 4(11) + lwzu 5, 4(11) + lwzu 6, 4(11) + lwzu 7, 4(11) + lwzu 8, 4(11) + lwzu 9, 4(11) + lwzu 10, 4(11) + lwzu 14, 4(11) + lwzu 15, 4(11) + lwzu 16, 4(11) + lwzu 17, 4(11) + lwzu 18, 4(11) + lwzu 19, 4(11) + lwzu 20, 4(11) + lwzu 21, 4(11) + lwzu 22, 4(11) + lwzu 23, 4(11) + lwzu 24, 4(11) + lwzu 25, 4(11) + lwzu 26, 4(11) + lwzu 27, 4(11) + lwzu 28, 4(11) + addi 11, 1, 64 - 8 + lfdu 1, 8(11) + lfdu 2, 8(11) + lfdu 3, 8(11) + lfdu 4, 8(11) + lfdu 5, 8(11) + lfdu 6, 8(11) + lfdu 7, 8(11) + lfdu 8, 8(11) + lfdu 9, 8(11) + lfdu 10, 8(11) + lfdu 11, 8(11) + lfdu 12, 8(11) + lfdu 13, 8(11) + lfdu 14, 8(11) + lfdu 15, 8(11) + lfdu 16, 8(11) + lfdu 17, 8(11) + lfdu 18, 8(11) + lfdu 19, 8(11) + lfdu 20, 8(11) + lfdu 21, 8(11) + lfdu 22, 8(11) + lfdu 23, 8(11) + lfdu 24, 8(11) + lfdu 25, 8(11) + lfdu 26, 8(11) + lfdu 27, 8(11) + lfdu 28, 8(11) + lfdu 29, 8(11) + lfdu 30, 8(11) + lfdu 31, 8(11) + # Return to caller (the stub code), leaving return address into + # Caml code in the link register + lwz 0, 0x1C0+8(1) + mtctr 0 + lwz 11, L..caml_last_return_address(2) + lwz 0, 0(11) + addic 0, 0, -16 # Restart the allocation (4 instructions) + mtlr 0 + # Say we are back into Caml code + li 12, 0 + stw 12, 0(11) # 11 still points to caml_last_return_address + # Deallocate stack frame + addi 1, 1, 0x1C0 + # Return + bctr + +#### Call a C function from Caml + + .globl .caml_c_call +.caml_c_call: + # Save return address in 25 + mflr 25 + # Record lowest stack address and return address + lwz 27, L..caml_bottom_of_stack(2) + lwz 24, L..caml_last_return_address(2) + stw 1, 0(27) + stw 25, 0(24) + # Make the exception handler and alloc ptr available to the C code + lwz 27, L..caml_young_ptr(2) + lwz 26, L..caml_exception_pointer(2) + stw 31, 0(27) + stw 29, 0(26) + # Preserve RTOC and return address in callee-save registers + # The C function will preserve them, and the Caml code does not + # expect them to be preserved + # Return address is in 25, RTOC is in 26, pointer to caml_young_ptr in 27, + # pointer to caml_last_return_address is in 24 + # Call the function (descriptor in 11) + lwz 0, 0(11) + mr 26, 2 + mtlr 0 + lwz 2, 4(11) + lwz 11, 8(11) + blrl + # Restore return address + mtlr 25 + # Restore RTOC + mr 2, 26 + # Reload allocation pointer + lwz 31, 0(27) # 27 still points to caml_young_ptr + # Say we are back into Caml code + li 12, 0 + stw 12, 0(24) # 24 still points to caml_last_return_address + # Return to caller + blr + +#### Raise an exception from C + + .globl .caml_raise_exception +.caml_raise_exception: + # Reload Caml global registers + lwz 4, L..caml_exception_pointer(2) + lwz 5, L..caml_young_ptr(2) + lwz 6, L..caml_young_limit(2) + lwz 1, 0(4) + lwz 31, 0(5) + lwz 30, 0(6) + # Say we are back into Caml code + lwz 4, L..caml_last_return_address(2) + li 0, 0 + stw 0, 0(4) + # Pop trap frame + lwz 0, 0(1) + lwz 29, 4(1) + mtlr 0 + lwz 2, 20(1) + addi 1, 1, 32 + # Branch to handler + blr + +#### Start the Caml program + + .globl .caml_start_program +.caml_start_program: + lwz 11, L..caml_program(2) + +#### Code shared between caml_start_program and caml_callback* + +L..102: + mflr 0 + # Save return address + stw 0, 8(1) + # Save all callee-save registers + stw 13, -76(1) + stw 14, -72(1) + stw 15, -68(1) + stw 16, -64(1) + stw 17, -60(1) + stw 18, -56(1) + stw 19, -52(1) + stw 20, -48(1) + stw 21, -44(1) + stw 22, -40(1) + stw 23, -36(1) + stw 24, -32(1) + stw 25, -28(1) + stw 26, -24(1) + stw 27, -20(1) + stw 28, -16(1) + stw 29, -12(1) + stw 30, -8(1) + stw 31, -4(1) + stfd 14, -224(1) + stfd 15, -216(1) + stfd 16, -208(1) + stfd 17, -200(1) + stfd 18, -192(1) + stfd 19, -184(1) + stfd 20, -176(1) + stfd 21, -168(1) + stfd 22, -160(1) + stfd 23, -152(1) + stfd 24, -144(1) + stfd 25, -136(1) + stfd 26, -128(1) + stfd 27, -120(1) + stfd 28, -112(1) + stfd 29, -104(1) + stfd 30, -96(1) + stfd 31, -88(1) + # Allocate and link stack frame + stwu 1, -288(1) + # Set up a callback link + addi 1, 1, -32 + lwz 9, L..caml_bottom_of_stack(2) + lwz 10, L..caml_last_return_address(2) + lwz 12, L..caml_gc_regs(2) + lwz 9, 0(9) + lwz 10, 0(10) + lwz 12, 0(12) + stw 9, 0(1) + stw 10, 4(1) + stw 12, 8(1) + # Build an exception handler to catch exceptions escaping out of Caml + bl L..103 + b L..104 +L..103: + addi 1, 1, -32 + lwz 9, L..caml_exception_pointer(2) + mflr 0 + lwz 29, 0(9) + stw 0, 0(1) + stw 29, 4(1) + stw 2, 20(1) + mr 29, 1 + # Reload allocation pointers + lwz 9, L..caml_young_ptr(2) + lwz 10, L..caml_young_limit(2) + lwz 31, 0(9) + lwz 30, 0(10) + # Say we are back into Caml code + lwz 9, L..caml_last_return_address(2) + li 0, 0 + stw 0, 0(9) + # Call the Caml code + lwz 0, 0(11) + stw 2, 20(1) + mtlr 0 + lwz 2, 4(11) +L..105: + blrl + lwz 2, 20(1) + # Pop the trap frame, restoring caml_exception_pointer + lwz 9, 4(1) + lwz 10, L..caml_exception_pointer(2) + addi 1, 1, 32 + stw 9, 0(10) + # Pop the callback link, restoring the global variables +L..106: + lwz 7, 0(1) + lwz 8, 4(1) + lwz 9, 8(1) + lwz 10, L..caml_bottom_of_stack(2) + lwz 11, L..caml_last_return_address(2) + lwz 12, L..caml_gc_regs(2) + stw 7, 0(10) + stw 8, 0(11) + stw 9, 0(12) + addi 1, 1, 32 + # Update allocation pointer + lwz 11, L..caml_young_ptr(2) + stw 31, 0(11) + # Deallocate stack frame + addi 1, 1, 288 + # Restore callee-save registers + lwz 13, -76(1) + lwz 14, -72(1) + lwz 15, -68(1) + lwz 16, -64(1) + lwz 17, -60(1) + lwz 18, -56(1) + lwz 19, -52(1) + lwz 20, -48(1) + lwz 21, -44(1) + lwz 22, -40(1) + lwz 23, -36(1) + lwz 24, -32(1) + lwz 25, -28(1) + lwz 26, -24(1) + lwz 27, -20(1) + lwz 28, -16(1) + lwz 29, -12(1) + lwz 30, -8(1) + lwz 31, -4(1) + lfd 14, -224(1) + lfd 15, -216(1) + lfd 16, -208(1) + lfd 17, -200(1) + lfd 18, -192(1) + lfd 19, -184(1) + lfd 20, -176(1) + lfd 21, -168(1) + lfd 22, -160(1) + lfd 23, -152(1) + lfd 24, -144(1) + lfd 25, -136(1) + lfd 26, -128(1) + lfd 27, -120(1) + lfd 28, -112(1) + lfd 29, -104(1) + lfd 30, -96(1) + lfd 31, -88(1) + # Reload return address + lwz 0, 8(1) + mtlr 0 + # Return + blr + # The trap handler: +L..104: + # Update caml_exception_pointer + lwz 9, L..caml_exception_pointer(2) + stw 29, 0(9) + # Encode exception bucket as an exception result and return it + ori 3, 3, 2 + b L..106 + +#### Callback from C to Caml + + .globl .caml_callback_exn +.caml_callback_exn: + # Initial shuffling of arguments + mr 0, 3 # Closure + mr 3, 4 # Argument + mr 4, 0 + lwz 11, 0(4) # Code pointer + b L..102 + + .globl .caml_callback2_exn +.caml_callback2_exn: + mr 0, 3 # Closure + mr 3, 4 # First argument + mr 4, 5 # Second argument + mr 5, 0 + lwz 11, L..caml_apply2(2) + b L..102 + + .globl .caml_callback3_exn +.caml_callback3_exn: + mr 0, 3 # Closure + mr 3, 4 # First argument + mr 4, 5 # Second argument + mr 5, 6 # Third argument + mr 6, 0 + lwz 11, L..caml_apply3(2) + b L..102 + +#### Frame table + + .csect .data[RW] + .globl caml_system__frametable +caml_system__frametable: + .long 1 # one descriptor + .long L..105 + 4 # return address into callback + .short -1 # negative size count => use callback link + .short 0 # no roots here + +#### TOC entries + + .toc +L..caml_young_limit: + .tc caml_young_limit[TC], caml_young_limit +L..caml_young_ptr: + .tc caml_young_ptr[TC], caml_young_ptr +L..caml_bottom_of_stack: + .tc caml_bottom_of_stack[TC], caml_bottom_of_stack +L..caml_last_return_address: + .tc caml_last_return_address[TC], caml_last_return_address +L..caml_gc_regs: + .tc caml_gc_regs[TC], caml_gc_regs +L..caml_exception_pointer: + .tc caml_exception_pointer[TC], caml_exception_pointer +L..gc_entry_regs: + .tc gc_entry_regs[TC], gc_entry_regs +L..gc_entry_float_regs: + .tc gc_entry_float_regs[TC], gc_entry_float_regs +L..caml_program: + .tc caml_program[TC], caml_program +L..caml_apply2: + .tc caml_apply2[TC], caml_apply2 +L..caml_apply3: + .tc caml_apply3[TC], caml_apply3 + +#### Function closures + + .csect caml_call_gc[DS] +caml_call_gc: + .long .caml_call_gc, TOC[tc0], 0 + + .globl caml_c_call + .csect caml_c_call[DS] +caml_c_call: + .long .caml_c_call, TOC[tc0], 0 + + .globl caml_raise_exception + .csect caml_raise_exception[DS] +caml_raise_exception: + .long .caml_raise_exception, TOC[tc0], 0 + + .globl caml_start_program + .csect caml_start_program[DS] +caml_start_program: + .long .caml_start_program, TOC[tc0], 0 + + .globl caml_callback_exn + .csect caml_callback_exn[DS] +caml_callback_exn: + .long .caml_callback_exn, TOC[tc0], 0 + + .globl caml_callback2_exn + .csect caml_callback2_exn[DS] +caml_callback2_exn: + .long .caml_callback2_exn, TOC[tc0], 0 + + .globl caml_callback3_exn + .csect caml_callback3_exn[DS] +caml_callback3_exn: + .long .caml_callback3_exn, TOC[tc0], 0 diff --git a/asmrun/power-elf.S b/asmrun/power-elf.S new file mode 100644 index 0000000..a0c059a --- /dev/null +++ b/asmrun/power-elf.S @@ -0,0 +1,421 @@ +/*********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/*********************************************************************/ + +/* $Id: power-elf.S,v 1.18 2004-01-03 12:51:19 doligez Exp $ */ + +#define Addrglobal(reg,glob) \ + addis reg, 0, glob@ha; \ + addi reg, reg, glob@l +#define Loadglobal(reg,glob,tmp) \ + addis tmp, 0, glob@ha; \ + lwz reg, glob@l(tmp) +#define Storeglobal(reg,glob,tmp) \ + addis tmp, 0, glob@ha; \ + stw reg, glob@l(tmp) + + .section ".text" + +/* Invoke the garbage collector. */ + + .globl caml_call_gc + .type caml_call_gc, @function +caml_call_gc: + /* Set up stack frame */ + stwu 1, -0x1A0(1) + /* 0x1A0 = 4*32 (int regs) + 8*32 (float regs) + 32 (space for C call) */ + /* Record return address into Caml code */ + mflr 0 + Storeglobal(0, caml_last_return_address, 11) + /* Record lowest stack address */ + addi 0, 1, 0x1A0 + Storeglobal(0, caml_bottom_of_stack, 11) + /* Record pointer to register array */ + addi 0, 1, 8*32 + 32 + Storeglobal(0, caml_gc_regs, 11) + /* Save current allocation pointer for debugging purposes */ + Storeglobal(31, caml_young_ptr, 11) + /* Save exception pointer (if e.g. a sighandler raises) */ + Storeglobal(29, caml_exception_pointer, 11) + /* Save all registers used by the code generator */ + addi 11, 1, 8*32 + 32 - 4 + stwu 3, 4(11) + stwu 4, 4(11) + stwu 5, 4(11) + stwu 6, 4(11) + stwu 7, 4(11) + stwu 8, 4(11) + stwu 9, 4(11) + stwu 10, 4(11) + stwu 14, 4(11) + stwu 15, 4(11) + stwu 16, 4(11) + stwu 17, 4(11) + stwu 18, 4(11) + stwu 19, 4(11) + stwu 20, 4(11) + stwu 21, 4(11) + stwu 22, 4(11) + stwu 23, 4(11) + stwu 24, 4(11) + stwu 25, 4(11) + stwu 26, 4(11) + stwu 27, 4(11) + stwu 28, 4(11) + addi 11, 1, 32 - 8 + stfdu 1, 8(11) + stfdu 2, 8(11) + stfdu 3, 8(11) + stfdu 4, 8(11) + stfdu 5, 8(11) + stfdu 6, 8(11) + stfdu 7, 8(11) + stfdu 8, 8(11) + stfdu 9, 8(11) + stfdu 10, 8(11) + stfdu 11, 8(11) + stfdu 12, 8(11) + stfdu 13, 8(11) + stfdu 14, 8(11) + stfdu 15, 8(11) + stfdu 16, 8(11) + stfdu 17, 8(11) + stfdu 18, 8(11) + stfdu 19, 8(11) + stfdu 20, 8(11) + stfdu 21, 8(11) + stfdu 22, 8(11) + stfdu 23, 8(11) + stfdu 24, 8(11) + stfdu 25, 8(11) + stfdu 26, 8(11) + stfdu 27, 8(11) + stfdu 28, 8(11) + stfdu 29, 8(11) + stfdu 30, 8(11) + stfdu 31, 8(11) + /* Call the GC */ + bl caml_garbage_collection + /* Reload new allocation pointer and allocation limit */ + Loadglobal(31, caml_young_ptr, 11) + Loadglobal(30, caml_young_limit, 11) + /* Restore all regs used by the code generator */ + addi 11, 1, 8*32 + 32 - 4 + lwzu 3, 4(11) + lwzu 4, 4(11) + lwzu 5, 4(11) + lwzu 6, 4(11) + lwzu 7, 4(11) + lwzu 8, 4(11) + lwzu 9, 4(11) + lwzu 10, 4(11) + lwzu 14, 4(11) + lwzu 15, 4(11) + lwzu 16, 4(11) + lwzu 17, 4(11) + lwzu 18, 4(11) + lwzu 19, 4(11) + lwzu 20, 4(11) + lwzu 21, 4(11) + lwzu 22, 4(11) + lwzu 23, 4(11) + lwzu 24, 4(11) + lwzu 25, 4(11) + lwzu 26, 4(11) + lwzu 27, 4(11) + lwzu 28, 4(11) + addi 11, 1, 32 - 8 + lfdu 1, 8(11) + lfdu 2, 8(11) + lfdu 3, 8(11) + lfdu 4, 8(11) + lfdu 5, 8(11) + lfdu 6, 8(11) + lfdu 7, 8(11) + lfdu 8, 8(11) + lfdu 9, 8(11) + lfdu 10, 8(11) + lfdu 11, 8(11) + lfdu 12, 8(11) + lfdu 13, 8(11) + lfdu 14, 8(11) + lfdu 15, 8(11) + lfdu 16, 8(11) + lfdu 17, 8(11) + lfdu 18, 8(11) + lfdu 19, 8(11) + lfdu 20, 8(11) + lfdu 21, 8(11) + lfdu 22, 8(11) + lfdu 23, 8(11) + lfdu 24, 8(11) + lfdu 25, 8(11) + lfdu 26, 8(11) + lfdu 27, 8(11) + lfdu 28, 8(11) + lfdu 29, 8(11) + lfdu 30, 8(11) + lfdu 31, 8(11) + /* Return to caller, restarting the allocation */ + Loadglobal(0, caml_last_return_address, 11) + addic 0, 0, -16 /* Restart the allocation (4 instructions) */ + mtlr 0 + /* Say we are back into Caml code */ + li 12, 0 + Storeglobal(12, caml_last_return_address, 11) + /* Deallocate stack frame */ + addi 1, 1, 0x1A0 + /* Return */ + blr + +/* Call a C function from Caml */ + + .globl caml_c_call + .type caml_c_call, @function +caml_c_call: + /* Save return address */ + mflr 25 + /* Get ready to call C function (address in 11) */ + mtlr 11 + /* Record lowest stack address and return address */ + Storeglobal(1, caml_bottom_of_stack, 12) + Storeglobal(25, caml_last_return_address, 12) + /* Make the exception handler and alloc ptr available to the C code */ + Storeglobal(31, caml_young_ptr, 11) + Storeglobal(29, caml_exception_pointer, 11) + /* Call the function (address in link register) */ + blrl + /* Restore return address (in 25, preserved by the C function) */ + mtlr 25 + /* Reload allocation pointer and allocation limit*/ + Loadglobal(31, caml_young_ptr, 11) + Loadglobal(30, caml_young_limit, 11) + /* Say we are back into Caml code */ + li 12, 0 + Storeglobal(12, caml_last_return_address, 11) + /* Return to caller */ + blr + +/* Raise an exception from C */ + + .globl caml_raise_exception + .type caml_raise_exception, @function +caml_raise_exception: + /* Reload Caml global registers */ + Loadglobal(1, caml_exception_pointer, 11) + Loadglobal(31, caml_young_ptr, 11) + Loadglobal(30, caml_young_limit, 11) + /* Say we are back into Caml code */ + li 0, 0 + Storeglobal(0, caml_last_return_address, 11) + /* Pop trap frame */ + lwz 0, 0(1) + lwz 29, 4(1) + mtlr 0 + addi 1, 1, 16 + /* Branch to handler */ + blr + +/* Start the Caml program */ + + .globl caml_start_program + .type caml_start_program, @function +caml_start_program: + Addrglobal(12, caml_program) + +/* Code shared between caml_start_program and caml_callback */ +.L102: + /* Allocate and link stack frame */ + stwu 1, -256(1) + /* Save return address */ + mflr 0 + stw 0, 256+4(1) + /* Save all callee-save registers */ + /* GPR 14 at sp+16 ... GPR 31 at sp+84 + FPR 14 at sp+92 ... FPR 31 at sp+228 */ + addi 11, 1, 16-4 + stwu 14, 4(11) + stwu 15, 4(11) + stwu 16, 4(11) + stwu 17, 4(11) + stwu 18, 4(11) + stwu 19, 4(11) + stwu 20, 4(11) + stwu 21, 4(11) + stwu 22, 4(11) + stwu 23, 4(11) + stwu 24, 4(11) + stwu 25, 4(11) + stwu 26, 4(11) + stwu 27, 4(11) + stwu 28, 4(11) + stwu 29, 4(11) + stwu 30, 4(11) + stwu 31, 4(11) + stfdu 14, 8(11) + stfdu 15, 8(11) + stfdu 16, 8(11) + stfdu 17, 8(11) + stfdu 18, 8(11) + stfdu 19, 8(11) + stfdu 20, 8(11) + stfdu 21, 8(11) + stfdu 22, 8(11) + stfdu 23, 8(11) + stfdu 24, 8(11) + stfdu 25, 8(11) + stfdu 26, 8(11) + stfdu 27, 8(11) + stfdu 28, 8(11) + stfdu 29, 8(11) + stfdu 30, 8(11) + stfdu 31, 8(11) + /* Set up a callback link */ + addi 1, 1, -16 + Loadglobal(9, caml_bottom_of_stack, 11) + Loadglobal(10, caml_last_return_address, 11) + Loadglobal(11, caml_gc_regs, 11) + stw 9, 0(1) + stw 10, 4(1) + stw 11, 8(1) + /* Build an exception handler to catch exceptions escaping out of Caml */ + bl .L103 + b .L104 +.L103: + addi 1, 1, -16 + mflr 0 + stw 0, 0(1) + Loadglobal(11, caml_exception_pointer, 11) + stw 11, 4(1) + mr 29, 1 + /* Reload allocation pointers */ + Loadglobal(31, caml_young_ptr, 11) + Loadglobal(30, caml_young_limit, 11) + /* Say we are back into Caml code */ + li 0, 0 + Storeglobal(0, caml_last_return_address, 11) + /* Call the Caml code */ + mtlr 12 +.L105: + blrl + /* Pop the trap frame, restoring caml_exception_pointer */ + lwz 9, 4(1) + Storeglobal(9, caml_exception_pointer, 11) + addi 1, 1, 16 + /* Pop the callback link, restoring the global variables */ +.L106: + lwz 9, 0(1) + lwz 10, 4(1) + lwz 11, 8(1) + Storeglobal(9, caml_bottom_of_stack, 12) + Storeglobal(10, caml_last_return_address, 12) + Storeglobal(11, caml_gc_regs, 12) + addi 1, 1, 16 + /* Update allocation pointer */ + Storeglobal(31, caml_young_ptr, 11) + /* Restore callee-save registers */ + addi 11, 1, 16-4 + lwzu 14, 4(11) + lwzu 15, 4(11) + lwzu 16, 4(11) + lwzu 17, 4(11) + lwzu 18, 4(11) + lwzu 19, 4(11) + lwzu 20, 4(11) + lwzu 21, 4(11) + lwzu 22, 4(11) + lwzu 23, 4(11) + lwzu 24, 4(11) + lwzu 25, 4(11) + lwzu 26, 4(11) + lwzu 27, 4(11) + lwzu 28, 4(11) + lwzu 29, 4(11) + lwzu 30, 4(11) + lwzu 31, 4(11) + lfdu 14, 8(11) + lfdu 15, 8(11) + lfdu 16, 8(11) + lfdu 17, 8(11) + lfdu 18, 8(11) + lfdu 19, 8(11) + lfdu 20, 8(11) + lfdu 21, 8(11) + lfdu 22, 8(11) + lfdu 23, 8(11) + lfdu 24, 8(11) + lfdu 25, 8(11) + lfdu 26, 8(11) + lfdu 27, 8(11) + lfdu 28, 8(11) + lfdu 29, 8(11) + lfdu 30, 8(11) + lfdu 31, 8(11) + /* Reload return address */ + lwz 0, 256+4(1) + mtlr 0 + /* Return */ + addi 1, 1, 256 + blr + + /* The trap handler: */ +.L104: + /* Update caml_exception_pointer */ + Storeglobal(29, caml_exception_pointer, 11) + /* Encode exception bucket as an exception result and return it */ + ori 3, 3, 2 + b .L106 + +/* Callback from C to Caml */ + + .globl caml_callback_exn + .type caml_callback_exn, @function +caml_callback_exn: + /* Initial shuffling of arguments */ + mr 0, 3 /* Closure */ + mr 3, 4 /* Argument */ + mr 4, 0 + lwz 12, 0(4) /* Code pointer */ + b .L102 + + .globl caml_callback2_exn + .type caml_callback2_exn, @function +caml_callback2_exn: + mr 0, 3 /* Closure */ + mr 3, 4 /* First argument */ + mr 4, 5 /* Second argument */ + mr 5, 0 + Addrglobal(12, caml_apply2) + b .L102 + + .globl caml_callback3_exn + .type caml_callback3_exn, @function +caml_callback3_exn: + mr 0, 3 /* Closure */ + mr 3, 4 /* First argument */ + mr 4, 5 /* Second argument */ + mr 5, 6 /* Third argument */ + mr 6, 0 + Addrglobal(12, caml_apply3) + b .L102 + +/* Frame table */ + + .section ".data" + .globl caml_system__frametable + .type caml_system__frametable, @object +caml_system__frametable: + .long 1 /* one descriptor */ + .long .L105 + 4 /* return address into callback */ + .short -1 /* negative size count => use callback link */ + .short 0 /* no roots here */ + diff --git a/asmrun/power-rhapsody.S b/asmrun/power-rhapsody.S new file mode 100644 index 0000000..102068e --- /dev/null +++ b/asmrun/power-rhapsody.S @@ -0,0 +1,474 @@ +/*********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/*********************************************************************/ + +/* $Id: power-rhapsody.S,v 1.15 2007-01-29 12:10:52 xleroy Exp $ */ + +#ifdef __ppc64__ +#define X(a,b) b +#else +#define X(a,b) a +#endif + +#define WORD X(4,8) +#define lg X(lwz,ld) +#define lgu X(lwzu,ldu) +#define stg X(stw,std) +#define stgu X(stwu,stdu) +#define gdata X(.long,.quad) + +.macro Addrglobal /* reg, glob */ + addis $0, 0, ha16($1) + addi $0, $0, lo16($1) +.endmacro +.macro Loadglobal /* reg,glob,tmp */ + addis $2, 0, ha16($1) + lg $0, lo16($1)($2) +.endmacro +.macro Storeglobal /* reg,glob,tmp */ + addis $2, 0, ha16($1) + stg $0, lo16($1)($2) +.endmacro + + .text + +/* Invoke the garbage collector. */ + + .globl _caml_call_gc +_caml_call_gc: + /* Set up stack frame */ +#define FRAMESIZE (32*WORD + 32*8 + 32) + stwu r1, -FRAMESIZE(r1) + /* Record return address into Caml code */ + mflr r0 + Storeglobal r0, _caml_last_return_address, r11 + /* Record lowest stack address */ + addi r0, r1, FRAMESIZE + Storeglobal r0, _caml_bottom_of_stack, r11 + /* Record pointer to register array */ + addi r0, r1, 8*32 + 32 + Storeglobal r0, _caml_gc_regs, r11 + /* Save current allocation pointer for debugging purposes */ + Storeglobal r31, _caml_young_ptr, r11 + /* Save exception pointer (if e.g. a sighandler raises) */ + Storeglobal r29, _caml_exception_pointer, r11 + /* Save all registers used by the code generator */ + addi r11, r1, 8*32 + 32 - WORD + stgu r3, WORD(r11) + stgu r4, WORD(r11) + stgu r5, WORD(r11) + stgu r6, WORD(r11) + stgu r7, WORD(r11) + stgu r8, WORD(r11) + stgu r9, WORD(r11) + stgu r10, WORD(r11) + stgu r14, WORD(r11) + stgu r15, WORD(r11) + stgu r16, WORD(r11) + stgu r17, WORD(r11) + stgu r18, WORD(r11) + stgu r19, WORD(r11) + stgu r20, WORD(r11) + stgu r21, WORD(r11) + stgu r22, WORD(r11) + stgu r23, WORD(r11) + stgu r24, WORD(r11) + stgu r25, WORD(r11) + stgu r26, WORD(r11) + stgu r27, WORD(r11) + stgu r28, WORD(r11) + addi r11, r1, 32 - 8 + stfdu f1, 8(r11) + stfdu f2, 8(r11) + stfdu f3, 8(r11) + stfdu f4, 8(r11) + stfdu f5, 8(r11) + stfdu f6, 8(r11) + stfdu f7, 8(r11) + stfdu f8, 8(r11) + stfdu f9, 8(r11) + stfdu f10, 8(r11) + stfdu f11, 8(r11) + stfdu f12, 8(r11) + stfdu f13, 8(r11) + stfdu f14, 8(r11) + stfdu f15, 8(r11) + stfdu f16, 8(r11) + stfdu f17, 8(r11) + stfdu f18, 8(r11) + stfdu f19, 8(r11) + stfdu f20, 8(r11) + stfdu f21, 8(r11) + stfdu f22, 8(r11) + stfdu f23, 8(r11) + stfdu f24, 8(r11) + stfdu f25, 8(r11) + stfdu f26, 8(r11) + stfdu f27, 8(r11) + stfdu f28, 8(r11) + stfdu f29, 8(r11) + stfdu f30, 8(r11) + stfdu f31, 8(r11) + /* Call the GC */ + bl _caml_garbage_collection + /* Reload new allocation pointer and allocation limit */ + Loadglobal r31, _caml_young_ptr, r11 + Loadglobal r30, _caml_young_limit, r11 + /* Restore all regs used by the code generator */ + addi r11, r1, 8*32 + 32 - WORD + lgu r3, WORD(r11) + lgu r4, WORD(r11) + lgu r5, WORD(r11) + lgu r6, WORD(r11) + lgu r7, WORD(r11) + lgu r8, WORD(r11) + lgu r9, WORD(r11) + lgu r10, WORD(r11) + lgu r14, WORD(r11) + lgu r15, WORD(r11) + lgu r16, WORD(r11) + lgu r17, WORD(r11) + lgu r18, WORD(r11) + lgu r19, WORD(r11) + lgu r20, WORD(r11) + lgu r21, WORD(r11) + lgu r22, WORD(r11) + lgu r23, WORD(r11) + lgu r24, WORD(r11) + lgu r25, WORD(r11) + lgu r26, WORD(r11) + lgu r27, WORD(r11) + lgu r28, WORD(r11) + addi r11, r1, 32 - 8 + lfdu f1, 8(r11) + lfdu f2, 8(r11) + lfdu f3, 8(r11) + lfdu f4, 8(r11) + lfdu f5, 8(r11) + lfdu f6, 8(r11) + lfdu f7, 8(r11) + lfdu f8, 8(r11) + lfdu f9, 8(r11) + lfdu f10, 8(r11) + lfdu f11, 8(r11) + lfdu f12, 8(r11) + lfdu f13, 8(r11) + lfdu f14, 8(r11) + lfdu f15, 8(r11) + lfdu f16, 8(r11) + lfdu f17, 8(r11) + lfdu f18, 8(r11) + lfdu f19, 8(r11) + lfdu f20, 8(r11) + lfdu f21, 8(r11) + lfdu f22, 8(r11) + lfdu f23, 8(r11) + lfdu f24, 8(r11) + lfdu f25, 8(r11) + lfdu f26, 8(r11) + lfdu f27, 8(r11) + lfdu f28, 8(r11) + lfdu f29, 8(r11) + lfdu f30, 8(r11) + lfdu f31, 8(r11) + /* Return to caller, restarting the allocation */ + Loadglobal r0, _caml_last_return_address, r11 + addic r0, r0, -16 /* Restart the allocation (4 instructions) */ + mtlr r0 + /* Say we are back into Caml code */ + li r12, 0 + Storeglobal r12, _caml_last_return_address, r11 + /* Deallocate stack frame */ + addi r1, r1, FRAMESIZE + /* Return */ + blr +#undef FRAMESIZE + +/* Call a C function from Caml */ + + .globl _caml_c_call +_caml_c_call: + /* Save return address */ + mflr r25 + /* Get ready to call C function (address in 11) */ + mtctr r11 + /* Record lowest stack address and return address */ + Storeglobal r1, _caml_bottom_of_stack, r12 + Storeglobal r25, _caml_last_return_address, r12 + /* Make the exception handler and alloc ptr available to the C code */ + Storeglobal r31, _caml_young_ptr, r11 + Storeglobal r29, _caml_exception_pointer, r11 + /* Call the function (address in link register) */ + bctrl + /* Restore return address (in 25, preserved by the C function) */ + mtlr r25 + /* Reload allocation pointer and allocation limit*/ + Loadglobal r31, _caml_young_ptr, r11 + Loadglobal r30, _caml_young_limit, r11 + /* Say we are back into Caml code */ + li r12, 0 + Storeglobal r12, _caml_last_return_address, r11 + /* Return to caller */ + blr + +/* Raise an exception from Caml */ + .globl _caml_raise_exn +_caml_raise_exn: + addis r11, 0, ha16(_caml_backtrace_active) + lwz r11, lo16(_caml_backtrace_active)(r11) + cmpwi r11, 0 + bne L110 +L111: + /* Pop trap frame */ + lg r0, 0(r29) + mr r1, r29 + mtlr r0 + lg r29, WORD(r1) + addi r1, r1, 16 + /* Branch to handler */ + blr + +L110: + mr r28, r3 /* preserve exn bucket in callee-save */ + /* arg 1: exception bucket (already in r3) */ + mflr r4 /* arg 2: PC of raise */ + mr r5, r1 /* arg 3: SP of raise */ + mr r6, r29 /* arg 4: SP of handler */ + addi r1, r1, -(16*WORD) /* reserve stack space for C call */ + bl _caml_stash_backtrace + mr r3, r28 + b L111 + +/* Raise an exception from C */ + + .globl _caml_raise_exception +_caml_raise_exception: + addis r11, 0, ha16(_caml_backtrace_active) + lwz r11, lo16(_caml_backtrace_active)(r11) + cmpwi r11, 0 + bne L112 +L113: + /* Reload Caml global registers */ + Loadglobal r1, _caml_exception_pointer, r11 + Loadglobal r31, _caml_young_ptr, r11 + Loadglobal r30, _caml_young_limit, r11 + /* Say we are back into Caml code */ + li r0, 0 + Storeglobal r0, _caml_last_return_address, r11 + /* Pop trap frame */ + lg r0, 0(r1) + lg r29, WORD(r1) + mtlr r0 + addi r1, r1, 16 + /* Branch to handler */ + blr +L112: + mr r28, r3 /* preserve exn bucket in callee-save */ + /* arg 1: exception bucket (already in r3) */ + Loadglobal r4, _caml_last_return_address, r11 /* arg 2: PC of raise */ + Loadglobal r5, _caml_bottom_of_stack, r11 /* arg 3: SP of raise */ + Loadglobal r6, _caml_exception_pointer, r11 /* arg 4: SP of handler */ + addi r1, r1, -(16*WORD) /* reserve stack space for C call */ + bl _caml_stash_backtrace + mr r3, r28 + b L113 + +/* Start the Caml program */ + + .globl _caml_start_program +_caml_start_program: + Addrglobal r12, _caml_program + +/* Code shared between caml_start_program and caml_callback */ +L102: + /* Allocate and link stack frame */ +#define FRAMESIZE (16 + 20*WORD + 18*8) + stgu r1, -FRAMESIZE(r1) + /* Save return address */ + mflr r0 + stg r0, WORD(r1) + /* Save all callee-save registers */ + /* GPR14 ... GPR31, then FPR14 ... FPR31 starting at sp+16 */ + addi r11, r1, 16-WORD + stgu r14, WORD(r11) + stgu r15, WORD(r11) + stgu r16, WORD(r11) + stgu r17, WORD(r11) + stgu r18, WORD(r11) + stgu r19, WORD(r11) + stgu r20, WORD(r11) + stgu r21, WORD(r11) + stgu r22, WORD(r11) + stgu r23, WORD(r11) + stgu r24, WORD(r11) + stgu r25, WORD(r11) + stgu r26, WORD(r11) + stgu r27, WORD(r11) + stgu r28, WORD(r11) + stgu r29, WORD(r11) + stgu r30, WORD(r11) + stgu r31, WORD(r11) + stfdu f14, 8(r11) + stfdu f15, 8(r11) + stfdu f16, 8(r11) + stfdu f17, 8(r11) + stfdu f18, 8(r11) + stfdu f19, 8(r11) + stfdu f20, 8(r11) + stfdu f21, 8(r11) + stfdu f22, 8(r11) + stfdu f23, 8(r11) + stfdu f24, 8(r11) + stfdu f25, 8(r11) + stfdu f26, 8(r11) + stfdu f27, 8(r11) + stfdu f28, 8(r11) + stfdu f29, 8(r11) + stfdu f30, 8(r11) + stfdu f31, 8(r11) + /* Set up a callback link */ + addi r1, r1, -32 + Loadglobal r9, _caml_bottom_of_stack, r11 + Loadglobal r10, _caml_last_return_address, r11 + Loadglobal r11, _caml_gc_regs, r11 + stg r9, 0(r1) + stg r10, WORD(r1) + stg r11, 2*WORD(r1) + /* Build an exception handler to catch exceptions escaping out of Caml */ + bl L103 + b L104 +L103: + addi r1, r1, -16 + mflr r0 + stg r0, 0(r1) + Loadglobal r11, _caml_exception_pointer, r11 + stg r11, WORD(r1) + mr r29, r1 + /* Reload allocation pointers */ + Loadglobal r31, _caml_young_ptr, r11 + Loadglobal r30, _caml_young_limit, r11 + /* Say we are back into Caml code */ + li r0, 0 + Storeglobal r0, _caml_last_return_address, r11 + /* Call the Caml code */ + mtctr r12 +L105: + bctrl + /* Pop the trap frame, restoring caml_exception_pointer */ + lg r9, WORD(r1) + Storeglobal r9, _caml_exception_pointer, r11 + addi r1, r1, 16 + /* Pop the callback link, restoring the global variables */ +L106: + lg r9, 0(r1) + lg r10, WORD(r1) + lg r11, 2*WORD(r1) + Storeglobal r9, _caml_bottom_of_stack, r12 + Storeglobal r10, _caml_last_return_address, r12 + Storeglobal r11, _caml_gc_regs, r12 + addi r1, r1, 32 + /* Update allocation pointer */ + Storeglobal r31, _caml_young_ptr, r11 + /* Restore callee-save registers */ + addi r11, r1, 16-WORD + lgu r14, WORD(r11) + lgu r15, WORD(r11) + lgu r16, WORD(r11) + lgu r17, WORD(r11) + lgu r18, WORD(r11) + lgu r19, WORD(r11) + lgu r20, WORD(r11) + lgu r21, WORD(r11) + lgu r22, WORD(r11) + lgu r23, WORD(r11) + lgu r24, WORD(r11) + lgu r25, WORD(r11) + lgu r26, WORD(r11) + lgu r27, WORD(r11) + lgu r28, WORD(r11) + lgu r29, WORD(r11) + lgu r30, WORD(r11) + lgu r31, WORD(r11) + lfdu f14, 8(r11) + lfdu f15, 8(r11) + lfdu f16, 8(r11) + lfdu f17, 8(r11) + lfdu f18, 8(r11) + lfdu f19, 8(r11) + lfdu f20, 8(r11) + lfdu f21, 8(r11) + lfdu f22, 8(r11) + lfdu f23, 8(r11) + lfdu f24, 8(r11) + lfdu f25, 8(r11) + lfdu f26, 8(r11) + lfdu f27, 8(r11) + lfdu f28, 8(r11) + lfdu f29, 8(r11) + lfdu f30, 8(r11) + lfdu f31, 8(r11) + /* Reload return address */ + lg r0, WORD(r1) + mtlr r0 + /* Return */ + addi r1, r1, FRAMESIZE + blr + + /* The trap handler: */ +L104: + /* Update caml_exception_pointer */ + Storeglobal r29, _caml_exception_pointer, r11 + /* Encode exception bucket as an exception result and return it */ + ori r3, r3, 2 + b L106 +#undef FRAMESIZE + +/* Callback from C to Caml */ + + .globl _caml_callback_exn +_caml_callback_exn: + /* Initial shuffling of arguments */ + mr r0, r3 /* Closure */ + mr r3, r4 /* Argument */ + mr r4, r0 + lg r12, 0(r4) /* Code pointer */ + b L102 + + .globl _caml_callback2_exn +_caml_callback2_exn: + mr r0, r3 /* Closure */ + mr r3, r4 /* First argument */ + mr r4, r5 /* Second argument */ + mr r5, r0 + Addrglobal r12, _caml_apply2 + b L102 + + .globl _caml_callback3_exn +_caml_callback3_exn: + mr r0, r3 /* Closure */ + mr r3, r4 /* First argument */ + mr r4, r5 /* Second argument */ + mr r5, r6 /* Third argument */ + mr r6, r0 + Addrglobal r12, _caml_apply3 + b L102 + +/* Frame table */ + + .const + .globl _caml_system__frametable +_caml_system__frametable: + gdata 1 /* one descriptor */ + gdata L105 + 4 /* return address into callback */ + .short -1 /* negative size count => use callback link */ + .short 0 /* no roots here */ + .align X(2,3) diff --git a/asmrun/roots.c b/asmrun/roots.c new file mode 100644 index 0000000..cf491a1 --- /dev/null +++ b/asmrun/roots.c @@ -0,0 +1,359 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: roots.c,v 1.45 2008-03-10 19:56:39 xleroy Exp $ */ + +/* To walk the memory roots for garbage collection */ + +#include "finalise.h" +#include "globroots.h" +#include "memory.h" +#include "major_gc.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "stack.h" +#include "roots.h" +#include +#include + +/* Roots registered from C functions */ + +struct caml__roots_block *caml_local_roots = NULL; + +void (*caml_scan_roots_hook) (scanning_action) = NULL; + +/* The hashtable of frame descriptors */ + +frame_descr ** caml_frame_descriptors = NULL; +int caml_frame_descriptors_mask; + +/* Linked-list */ + +typedef struct link { + void *data; + struct link *next; +} link; + +static link *cons(void *data, link *tl) { + link *lnk = caml_stat_alloc(sizeof(link)); + lnk->data = data; + lnk->next = tl; + return lnk; +} + +#define iter_list(list,lnk) \ + for (lnk = list; lnk != NULL; lnk = lnk->next) + +/* Linked-list of frametables */ + +static link *frametables = NULL; + +void caml_register_frametable(intnat *table) { + frametables = cons(table,frametables); + + if (NULL != caml_frame_descriptors) { + caml_stat_free(caml_frame_descriptors); + caml_frame_descriptors = NULL; + /* force caml_init_frame_descriptors to be called */ + } +} + +void caml_init_frame_descriptors(void) +{ + intnat num_descr, tblsize, i, j, len; + intnat * tbl; + frame_descr * d; + uintnat nextd; + uintnat h; + link *lnk; + + static int inited = 0; + + if (!inited) { + for (i = 0; caml_frametable[i] != 0; i++) + caml_register_frametable(caml_frametable[i]); + inited = 1; + } + + /* Count the frame descriptors */ + num_descr = 0; + iter_list(frametables,lnk) { + num_descr += *((intnat*) lnk->data); + } + + /* The size of the hashtable is a power of 2 greater or equal to + 2 times the number of descriptors */ + tblsize = 4; + while (tblsize < 2 * num_descr) tblsize *= 2; + + /* Allocate the hash table */ + caml_frame_descriptors = + (frame_descr **) caml_stat_alloc(tblsize * sizeof(frame_descr *)); + for (i = 0; i < tblsize; i++) caml_frame_descriptors[i] = NULL; + caml_frame_descriptors_mask = tblsize - 1; + + /* Fill the hash table */ + iter_list(frametables,lnk) { + tbl = (intnat*) lnk->data; + len = *tbl; + d = (frame_descr *)(tbl + 1); + for (j = 0; j < len; j++) { + h = Hash_retaddr(d->retaddr); + while (caml_frame_descriptors[h] != NULL) { + h = (h+1) & caml_frame_descriptors_mask; + } + caml_frame_descriptors[h] = d; + nextd = + ((uintnat)d + + sizeof(char *) + sizeof(short) + sizeof(short) + + sizeof(short) * d->num_live + sizeof(frame_descr *) - 1) + & -sizeof(frame_descr *); + if (d->frame_size & 1) nextd += 8; + d = (frame_descr *) nextd; + } + } +} + +/* Communication with [caml_start_program] and [caml_call_gc]. */ + +char * caml_bottom_of_stack = NULL; /* no stack initially */ +uintnat caml_last_return_address = 1; /* not in Caml code initially */ +value * caml_gc_regs; +intnat caml_globals_inited = 0; +static intnat caml_globals_scanned = 0; +static link * caml_dyn_globals = NULL; + +void caml_register_dyn_global(void *v) { + caml_dyn_globals = cons((void*) v,caml_dyn_globals); +} + +/* Call [caml_oldify_one] on (at least) all the roots that point to the minor + heap. */ +void caml_oldify_local_roots (void) +{ + char * sp; + uintnat retaddr; + value * regs; + frame_descr * d; + uintnat h; + int i, j, n, ofs; +#ifdef Stack_grows_upwards + short * p; /* PR#4339: stack offsets are negative in this case */ +#else + unsigned short * p; +#endif + value glob; + value * root; + struct caml__roots_block *lr; + link *lnk; + + /* The global roots */ + for (i = caml_globals_scanned; + i <= caml_globals_inited && caml_globals[i] != 0; + i++) { + glob = caml_globals[i]; + for (j = 0; j < Wosize_val(glob); j++){ + Oldify (&Field (glob, j)); + } + } + caml_globals_scanned = caml_globals_inited; + + /* Dynamic global roots */ + iter_list(caml_dyn_globals, lnk) { + glob = (value) lnk->data; + for (j = 0; j < Wosize_val(glob); j++){ + Oldify (&Field (glob, j)); + } + } + + /* The stack and local roots */ + if (caml_frame_descriptors == NULL) caml_init_frame_descriptors(); + sp = caml_bottom_of_stack; + retaddr = caml_last_return_address; + regs = caml_gc_regs; + if (sp != NULL) { + while (1) { + /* Find the descriptor corresponding to the return address */ + h = Hash_retaddr(retaddr); + while(1) { + d = caml_frame_descriptors[h]; + if (d->retaddr == retaddr) break; + h = (h+1) & caml_frame_descriptors_mask; + } + if (d->frame_size != 0xFFFF) { + /* Scan the roots in this frame */ + for (p = d->live_ofs, n = d->num_live; n > 0; n--, p++) { + ofs = *p; + if (ofs & 1) { + root = regs + (ofs >> 1); + } else { + root = (value *)(sp + ofs); + } + Oldify (root); + } + /* Move to next frame */ +#ifndef Stack_grows_upwards + sp += (d->frame_size & 0xFFFC); +#else + sp -= (d->frame_size & 0xFFFC); +#endif + retaddr = Saved_return_address(sp); +#ifdef Already_scanned + /* Stop here if the frame has been scanned during earlier GCs */ + if (Already_scanned(sp, retaddr)) break; + /* Mark frame as already scanned */ + Mark_scanned(sp, retaddr); +#endif + } else { + /* This marks the top of a stack chunk for an ML callback. + Skip C portion of stack and continue with next ML stack chunk. */ + struct caml_context * next_context = Callback_link(sp); + sp = next_context->bottom_of_stack; + retaddr = next_context->last_retaddr; + regs = next_context->gc_regs; + /* A null sp means no more ML stack chunks; stop here. */ + if (sp == NULL) break; + } + } + } + /* Local C roots */ + for (lr = caml_local_roots; lr != NULL; lr = lr->next) { + for (i = 0; i < lr->ntables; i++){ + for (j = 0; j < lr->nitems; j++){ + root = &(lr->tables[i][j]); + Oldify (root); + } + } + } + /* Global C roots */ + caml_scan_global_young_roots(&caml_oldify_one); + /* Finalised values */ + caml_final_do_young_roots (&caml_oldify_one); + /* Hook */ + if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(&caml_oldify_one); +} + +/* Call [darken] on all roots */ + +void caml_darken_all_roots (void) +{ + caml_do_roots (caml_darken); +} + +void caml_do_roots (scanning_action f) +{ + int i, j; + value glob; + link *lnk; + + /* The global roots */ + for (i = 0; caml_globals[i] != 0; i++) { + glob = caml_globals[i]; + for (j = 0; j < Wosize_val(glob); j++) + f (Field (glob, j), &Field (glob, j)); + } + + /* Dynamic global roots */ + iter_list(caml_dyn_globals, lnk) { + glob = (value) lnk->data; + for (j = 0; j < Wosize_val(glob); j++){ + f (Field (glob, j), &Field (glob, j)); + } + } + + /* The stack and local roots */ + if (caml_frame_descriptors == NULL) caml_init_frame_descriptors(); + caml_do_local_roots(f, caml_bottom_of_stack, caml_last_return_address, + caml_gc_regs, caml_local_roots); + /* Global C roots */ + caml_scan_global_roots(f); + /* Finalised values */ + caml_final_do_strong_roots (f); + /* Hook */ + if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(f); +} + +void caml_do_local_roots(scanning_action f, char * bottom_of_stack, + uintnat last_retaddr, value * gc_regs, + struct caml__roots_block * local_roots) +{ + char * sp; + uintnat retaddr; + value * regs; + frame_descr * d; + uintnat h; + int i, j, n, ofs; +#ifdef Stack_grows_upwards + short * p; /* PR#4339: stack offsets are negative in this case */ +#else + unsigned short * p; +#endif + value * root; + struct caml__roots_block *lr; + + sp = bottom_of_stack; + retaddr = last_retaddr; + regs = gc_regs; + if (sp != NULL) { + while (1) { + /* Find the descriptor corresponding to the return address */ + h = Hash_retaddr(retaddr); + while(1) { + d = caml_frame_descriptors[h]; + if (d->retaddr == retaddr) break; + h = (h+1) & caml_frame_descriptors_mask; + } + if (d->frame_size != 0xFFFF) { + /* Scan the roots in this frame */ + for (p = d->live_ofs, n = d->num_live; n > 0; n--, p++) { + ofs = *p; + if (ofs & 1) { + root = regs + (ofs >> 1); + } else { + root = (value *)(sp + ofs); + } + f (*root, root); + } + /* Move to next frame */ +#ifndef Stack_grows_upwards + sp += (d->frame_size & 0xFFFC); +#else + sp -= (d->frame_size & 0xFFFC); +#endif + retaddr = Saved_return_address(sp); +#ifdef Mask_already_scanned + retaddr = Mask_already_scanned(retaddr); +#endif + } else { + /* This marks the top of a stack chunk for an ML callback. + Skip C portion of stack and continue with next ML stack chunk. */ + struct caml_context * next_context = Callback_link(sp); + sp = next_context->bottom_of_stack; + retaddr = next_context->last_retaddr; + regs = next_context->gc_regs; + /* A null sp means no more ML stack chunks; stop here. */ + if (sp == NULL) break; + } + } + } + /* Local C roots */ + for (lr = local_roots; lr != NULL; lr = lr->next) { + for (i = 0; i < lr->ntables; i++){ + for (j = 0; j < lr->nitems; j++){ + root = &(lr->tables[i][j]); + f (*root, root); + } + } + } +} diff --git a/asmrun/signals_asm.c b/asmrun/signals_asm.c new file mode 100644 index 0000000..16ffb4a --- /dev/null +++ b/asmrun/signals_asm.c @@ -0,0 +1,257 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Gallium, INRIA Rocquencourt */ +/* */ +/* Copyright 2007 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals_asm.c,v 1.6 2008-01-11 16:13:11 doligez Exp $ */ + +/* Signal handling, code specific to the native-code compiler */ + +#if defined(TARGET_amd64) && defined (SYS_linux) +#define _GNU_SOURCE +#endif +#include +#include +#include "fail.h" +#include "memory.h" +#include "osdeps.h" +#include "signals.h" +#include "signals_machdep.h" +#include "signals_osdep.h" +#include "stack.h" + +#ifdef HAS_STACK_OVERFLOW_DETECTION +#include +#include +#endif + +#ifndef NSIG +#define NSIG 64 +#endif + +typedef void (*signal_handler)(int signo); + +#ifdef _WIN32 +extern signal_handler caml_win32_signal(int sig, signal_handler action); +#define signal(sig,act) caml_win32_signal(sig,act) +extern void caml_win32_overflow_detection(); +#endif + +extern char * caml_code_area_start, * caml_code_area_end; + +#define Is_in_code_area(pc) \ + ( ((char *)(pc) >= caml_code_area_start && \ + (char *)(pc) <= caml_code_area_end) \ + || (Classify_addr(pc) & In_code_area) ) + +/* This routine is the common entry point for garbage collection + and signal handling. It can trigger a callback to Caml code. + With system threads, this callback can cause a context switch. + Hence [caml_garbage_collection] must not be called from regular C code + (e.g. the [caml_alloc] function) because the context of the call + (e.g. [intern_val]) may not allow context switching. + Only generated assembly code can call [caml_garbage_collection], + via the caml_call_gc assembly stubs. */ + +void caml_garbage_collection(void) +{ + caml_young_limit = caml_young_start; + if (caml_young_ptr < caml_young_start || caml_force_major_slice) { + caml_minor_collection(); + } + caml_process_pending_signals(); +} + +DECLARE_SIGNAL_HANDLER(handle_signal) +{ +#if !defined(POSIX_SIGNALS) && !defined(BSD_SIGNALS) + signal(sig, handle_signal); +#endif + if (sig < 0 || sig >= NSIG) return; + if (caml_try_leave_blocking_section_hook ()) { + caml_execute_signal(sig, 1); + caml_enter_blocking_section_hook(); + } else { + caml_record_signal(sig); + /* Some ports cache [caml_young_limit] in a register. + Use the signal context to modify that register too, but only if + we are inside Caml code (not inside C code). */ +#if defined(CONTEXT_PC) && defined(CONTEXT_YOUNG_LIMIT) + if (Is_in_code_area(CONTEXT_PC)) + CONTEXT_YOUNG_LIMIT = (context_reg) caml_young_limit; +#endif + } +} + +int caml_set_signal_action(int signo, int action) +{ + signal_handler oldact; +#ifdef POSIX_SIGNALS + struct sigaction sigact, oldsigact; +#else + signal_handler act; +#endif + +#ifdef POSIX_SIGNALS + switch(action) { + case 0: + sigact.sa_handler = SIG_DFL; + sigact.sa_flags = 0; + break; + case 1: + sigact.sa_handler = SIG_IGN; + sigact.sa_flags = 0; + break; + default: + SET_SIGACT(sigact, handle_signal); + break; + } + sigemptyset(&sigact.sa_mask); + if (sigaction(signo, &sigact, &oldsigact) == -1) return -1; + oldact = oldsigact.sa_handler; +#else + switch(action) { + case 0: act = SIG_DFL; break; + case 1: act = SIG_IGN; break; + default: act = handle_signal; break; + } + oldact = signal(signo, act); + if (oldact == SIG_ERR) return -1; +#endif + if (oldact == (signal_handler) handle_signal) + return 2; + else if (oldact == SIG_IGN) + return 1; + else + return 0; +} + +/* Machine- and OS-dependent handling of bound check trap */ + +#if defined(TARGET_power) || (defined(TARGET_sparc) && defined(SYS_solaris)) +DECLARE_SIGNAL_HANDLER(trap_handler) +{ +#if defined(SYS_solaris) + if (info->si_code != ILL_ILLTRP) { + /* Deactivate our exception handler and return. */ + struct sigaction act; + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(sig, &act, NULL); + return; + } +#endif +#if defined(SYS_rhapsody) + /* Unblock SIGTRAP */ + { sigset_t mask; + sigemptyset(&mask); + sigaddset(&mask, SIGTRAP); + sigprocmask(SIG_UNBLOCK, &mask, NULL); + } +#endif + caml_exception_pointer = (char *) CONTEXT_EXCEPTION_POINTER; + caml_young_ptr = (char *) CONTEXT_YOUNG_PTR; +#if defined(SYS_rhapsody) + caml_bottom_of_stack = (char *) CONTEXT_SP; + caml_last_return_address = (uintnat) CONTEXT_PC; +#endif + caml_array_bound_error(); +} +#endif + +/* Machine- and OS-dependent handling of stack overflow */ + +#ifdef HAS_STACK_OVERFLOW_DETECTION + +static char * system_stack_top; +static char sig_alt_stack[SIGSTKSZ]; + +DECLARE_SIGNAL_HANDLER(segv_handler) +{ + struct rlimit limit; + struct sigaction act; + char * fault_addr; + + /* Sanity checks: + - faulting address is word-aligned + - faulting address is within the stack + - we are in Caml code */ + fault_addr = CONTEXT_FAULTING_ADDRESS; + if (((uintnat) fault_addr & (sizeof(intnat) - 1)) == 0 + && getrlimit(RLIMIT_STACK, &limit) == 0 + && fault_addr < system_stack_top + && fault_addr >= system_stack_top - limit.rlim_cur - 0x2000 +#ifdef CONTEXT_PC + && Is_in_code_area(CONTEXT_PC) +#endif + ) { + /* Turn this into a Stack_overflow exception */ +#if defined(CONTEXT_YOUNG_PTR) && defined(CONTEXT_EXCEPTION_POINTER) + caml_exception_pointer = (char *) CONTEXT_EXCEPTION_POINTER; + caml_young_ptr = (char *) CONTEXT_YOUNG_PTR; +#endif + caml_raise_stack_overflow(); + } + /* Otherwise, deactivate our exception handler and return, + causing fatal signal to be generated at point of error. */ + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGSEGV, &act, NULL); +} + +#endif + +/* Initialization of signal stuff */ + +void caml_init_signals(void) +{ + /* Bound-check trap handling */ +#if defined(TARGET_sparc) && defined(SYS_solaris) + { struct sigaction act; + sigemptyset(&act.sa_mask); + SET_SIGACT(act, trap_handler); + act.sa_flags |= SA_NODEFER; + sigaction(SIGILL, &act, NULL); + } +#endif + +#if defined(TARGET_power) + { struct sigaction act; + sigemptyset(&act.sa_mask); + SET_SIGACT(act, trap_handler); +#if !defined(SYS_rhapsody) + act.sa_flags |= SA_NODEFER; +#endif + sigaction(SIGTRAP, &act, NULL); + } +#endif + + /* Stack overflow handling */ +#ifdef HAS_STACK_OVERFLOW_DETECTION + { + stack_t stk; + struct sigaction act; + stk.ss_sp = sig_alt_stack; + stk.ss_size = SIGSTKSZ; + stk.ss_flags = 0; + SET_SIGACT(act, segv_handler); + act.sa_flags |= SA_ONSTACK | SA_NODEFER; + sigemptyset(&act.sa_mask); + system_stack_top = (char *) &act; + if (sigaltstack(&stk, NULL) == 0) { sigaction(SIGSEGV, &act, NULL); } + } +#endif +#if defined(_WIN32) && !defined(_WIN64) + caml_win32_overflow_detection(); +#endif +} diff --git a/asmrun/signals_osdep.h b/asmrun/signals_osdep.h new file mode 100644 index 0000000..711c052 --- /dev/null +++ b/asmrun/signals_osdep.h @@ -0,0 +1,254 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2004 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals_osdep.h,v 1.12 2008-12-03 18:09:08 doligez Exp $ */ + +/* Processor- and OS-dependent signal interface */ + +/****************** Alpha, all OS */ + +#if defined(TARGET_alpha) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, int code, struct sigcontext * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (void (*)(int)) (name); \ + sigact.sa_flags = 0 + + typedef long context_reg; + #define CONTEXT_PC (context->sc_pc) + #define CONTEXT_EXCEPTION_POINTER (context->sc_regs[15]) + #define CONTEXT_YOUNG_LIMIT (context->sc_regs[13]) + #define CONTEXT_YOUNG_PTR (context->sc_regs[14]) + +/****************** AMD64, Linux */ + +#elif defined(TARGET_amd64) && defined (SYS_linux) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, ucontext_t * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (void (*)(int,siginfo_t *,void *)) (name); \ + sigact.sa_flags = SA_SIGINFO + + typedef greg_t context_reg; + #define CONTEXT_PC (context->uc_mcontext.gregs[REG_RIP]) + #define CONTEXT_EXCEPTION_POINTER (context->uc_mcontext.gregs[REG_R14]) + #define CONTEXT_YOUNG_PTR (context->uc_mcontext.gregs[REG_R15]) + #define CONTEXT_FAULTING_ADDRESS ((char *) context->uc_mcontext.gregs[REG_CR2]) + +/****************** AMD64, MacOSX */ + +#elif defined(TARGET_amd64) && defined (SYS_macosx) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, void * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO | SA_64REGSET + + #include + #include + +#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #define CONTEXT_REG(r) r + #else + #define CONTEXT_REG(r) __##r + #endif + + #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss)) + #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(rip)) + #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r14)) + #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.CONTEXT_REG(r15)) + #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(rsp)) + #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) + +/****************** I386, Linux */ + +#elif defined(TARGET_i386) && defined(SYS_linux_elf) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, struct sigcontext context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (void (*)(int)) (name); \ + sigact.sa_flags = 0 + + #define CONTEXT_FAULTING_ADDRESS ((char *) context.cr2) + +/****************** I386, BSD */ + +#elif defined(TARGET_i386) && defined(SYS_bsd) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, void * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO + + #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) + +/****************** I386, MacOS X */ + +#elif defined(TARGET_i386) && defined(SYS_macosx) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, void * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO + + #include + #include + +#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #define CONTEXT_REG(r) r + #else + #define CONTEXT_REG(r) __##r + #endif + + #define CONTEXT_STATE (((ucontext_t *)context)->uc_mcontext->CONTEXT_REG(ss)) + #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(eip)) + #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) + +/****************** MIPS, all OS */ + +#elif defined(TARGET_mips) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, int code, struct sigcontext * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (void (*)(int)) (name); \ + sigact.sa_flags = 0 + + typedef int context_reg; + #define CONTEXT_PC (context->sc_pc) + #define CONTEXT_EXCEPTION_POINTER (context->sc_regs[30]) + #define CONTEXT_YOUNG_LIMIT (context->sc_regs[22]) + #define CONTEXT_YOUNG_PTR (context->sc_regs[23]) + +/****************** PowerPC, MacOS X */ + +#elif defined(TARGET_power) && defined(SYS_rhapsody) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, void * context) + + #include + #include + + #ifdef __LP64__ + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO | SA_64REGSET + + typedef unsigned long long context_reg; + + #define CONTEXT_MCONTEXT (((ucontext64_t *)context)->uc_mcontext64) + #else + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (name); \ + sigact.sa_flags = SA_SIGINFO + + typedef unsigned long context_reg; + + #define CONTEXT_MCONTEXT (((ucontext_t *)context)->uc_mcontext) + #endif + +#if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 + #define CONTEXT_REG(r) r + #else + #define CONTEXT_REG(r) __##r + #endif + + #define CONTEXT_STATE (CONTEXT_MCONTEXT->CONTEXT_REG(ss)) + #define CONTEXT_PC (CONTEXT_STATE.CONTEXT_REG(srr0)) + #define CONTEXT_EXCEPTION_POINTER (CONTEXT_STATE.CONTEXT_REG(r29)) + #define CONTEXT_YOUNG_LIMIT (CONTEXT_STATE.CONTEXT_REG(r30)) + #define CONTEXT_YOUNG_PTR (CONTEXT_STATE.CONTEXT_REG(r31)) + #define CONTEXT_SP (CONTEXT_STATE.CONTEXT_REG(r1)) + #define CONTEXT_FAULTING_ADDRESS ((char *) info->si_addr) + +/****************** PowerPC, ELF (Linux) */ + +#elif defined(TARGET_power) && defined(SYS_elf) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, struct sigcontext * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (void (*)(int)) (name); \ + sigact.sa_flags = 0 + + typedef unsigned long context_reg; + #define CONTEXT_PC (context->regs->nip) + #define CONTEXT_EXCEPTION_POINTER (context->regs->gpr[29]) + #define CONTEXT_YOUNG_LIMIT (context->regs->gpr[30]) + #define CONTEXT_YOUNG_PTR (context->regs->gpr[31]) + +/****************** PowerPC, BSD */ + +#elif defined(TARGET_power) && defined(SYS_bsd) + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, int code, struct sigcontext * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (void (*)(int)) (name); \ + sigact.sa_flags = 0 + + typedef unsigned long context_reg; + #define CONTEXT_EXCEPTION_POINTER (context->sc_frame.fixreg[29]) + #define CONTEXT_YOUNG_LIMIT (context->sc_frame.fixreg[30]) + #define CONTEXT_YOUNG_PTR (context->sc_frame.fixreg[31]) + +/****************** SPARC, Solaris */ + +#elif defined(TARGET_sparc) && defined(SYS_solaris) + + #include + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig, siginfo_t * info, ucontext_t * context) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_sigaction = (void (*)(int,siginfo_t *,void *)) (name); \ + sigact.sa_flags = SA_SIGINFO + + typedef long context_reg; + #define CONTEXT_PC (context->uc_mcontext.gregs[REG_PC]) + /* Local register number N is saved on the stack N words + after the stack pointer */ + #define SPARC_L_REG(n) ((long *)(context->uc_mcontext.gregs[REG_SP]))[n] + #define CONTEXT_EXCEPTION_POINTER (SPARC_L_REG(5)) + #define CONTEXT_YOUNG_LIMIT (SPARC_L_REG(7)) + #define CONTEXT_YOUNG_PTR (SPARC_L_REG(6)) + +/******************** Default */ + +#else + + #define DECLARE_SIGNAL_HANDLER(name) \ + static void name(int sig) + + #define SET_SIGACT(sigact,name) \ + sigact.sa_handler = (name); \ + sigact.sa_flags = 0 + +#endif diff --git a/asmrun/sparc.S b/asmrun/sparc.S new file mode 100644 index 0000000..956985e --- /dev/null +++ b/asmrun/sparc.S @@ -0,0 +1,407 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sparc.S,v 1.26 2004-10-06 06:33:25 garrigue Exp $ */ + +/* Asm part of the runtime system for the Sparc processor. */ +/* Must be preprocessed by cpp */ + +/* SunOS 4 prefixes identifiers with _ */ + +#if defined(SYS_sunos) + +#define Caml_young_limit _caml_young_limit +#define Caml_young_ptr _caml_young_ptr +#define Caml_bottom_of_stack _caml_bottom_of_stack +#define Caml_last_return_address _caml_last_return_address +#define Caml_gc_regs _caml_gc_regs +#define Caml_exception_pointer _caml_exception_pointer +#define Caml_allocN _caml_allocN +#define Caml_call_gc _caml_call_gc +#define Caml_garbage_collection _caml_garbage_collection +#define Caml_c_call _caml_c_call +#define Caml_start_program _caml_start_program +#define Caml_program _caml_program +#define Caml_raise_exception _caml_raise_exception +#define Caml_callback_exn _caml_callback_exn +#define Caml_callback2_exn _caml_callback2_exn +#define Caml_callback3_exn _caml_callback3_exn +#define Caml_apply2 _caml_apply2 +#define Caml_apply3 _caml_apply3 +#define Caml_raise _caml_raise +#define Caml_system__frametable _caml_system__frametable +#define Caml_ml_array_bound_error _caml_ml_array_bound_error +#define Caml_array_bound_error _caml_array_bound_error + +#else + +#define Caml_young_limit caml_young_limit +#define Caml_young_ptr caml_young_ptr +#define Caml_bottom_of_stack caml_bottom_of_stack +#define Caml_last_return_address caml_last_return_address +#define Caml_gc_regs caml_gc_regs +#define Caml_exception_pointer caml_exception_pointer +#define Caml_allocN caml_allocN +#define Caml_call_gc caml_call_gc +#define Caml_garbage_collection caml_garbage_collection +#define Caml_c_call caml_c_call +#define Caml_start_program caml_start_program +#define Caml_program caml_program +#define Caml_raise_exception caml_raise_exception +#define Caml_callback_exn caml_callback_exn +#define Caml_callback2_exn caml_callback2_exn +#define Caml_callback3_exn caml_callback3_exn +#define Caml_apply2 caml_apply2 +#define Caml_apply3 caml_apply3 +#define Caml_raise caml_raise +#define Caml_system__frametable caml_system__frametable +#define Caml_ml_array_bound_error caml_ml_array_bound_error +#define Caml_array_bound_error caml_array_bound_error + +#endif + +#ifndef SYS_solaris +#define INDIRECT_LIMIT +#endif + +#define Exn_ptr %l5 +#define Alloc_ptr %l6 +#define Alloc_limit %l7 + +#define Load(symb,reg) sethi %hi(symb), %g1; ld [%g1 + %lo(symb)], reg +#define Store(reg,symb) sethi %hi(symb), %g1; st reg, [%g1 + %lo(symb)] +#define Address(symb,reg) sethi %hi(symb), reg; or reg, %lo(symb), reg + +/* Allocation functions */ + + .text + .global Caml_allocN + .global Caml_call_gc + +/* Required size in %g2 */ +Caml_allocN: +#ifdef INDIRECT_LIMIT + ld [Alloc_limit], %g1 + sub Alloc_ptr, %g2, Alloc_ptr + cmp Alloc_ptr, %g1 +#else + sub Alloc_ptr, %g2, Alloc_ptr + cmp Alloc_ptr, Alloc_limit +#endif + /*blu,pt %icc, Caml_call_gc*/ + blu Caml_call_gc + nop + retl + nop + +/* Required size in %g2 */ +Caml_call_gc: + /* Save exception pointer if GC raises */ + Store(Exn_ptr, Caml_exception_pointer) + /* Save current allocation pointer for debugging purposes */ + Store(Alloc_ptr, Caml_young_ptr) + /* Record lowest stack address */ + Store(%sp, Caml_bottom_of_stack) + /* Record last return address */ + Store(%o7, Caml_last_return_address) + /* Allocate space on stack for caml_context structure and float regs */ + sub %sp, 20*4 + 15*8, %sp + /* Save int regs on stack and save it into caml_gc_regs */ +L100: add %sp, 96 + 15*8, %g1 + st %o0, [%g1] + st %o1, [%g1 + 0x4] + st %o2, [%g1 + 0x8] + st %o3, [%g1 + 0xc] + st %o4, [%g1 + 0x10] + st %o5, [%g1 + 0x14] + st %i0, [%g1 + 0x18] + st %i1, [%g1 + 0x1c] + st %i2, [%g1 + 0x20] + st %i3, [%g1 + 0x24] + st %i4, [%g1 + 0x28] + st %i5, [%g1 + 0x2c] + st %l0, [%g1 + 0x30] + st %l1, [%g1 + 0x34] + st %l2, [%g1 + 0x38] + st %l3, [%g1 + 0x3c] + st %l4, [%g1 + 0x40] + st %g3, [%g1 + 0x44] + st %g4, [%g1 + 0x48] + st %g2, [%g1 + 0x4C] /* Save required size */ + mov %g1, %g2 + Store(%g2, Caml_gc_regs) + /* Save the floating-point registers */ + add %sp, 96, %g1 + std %f0, [%g1] + std %f2, [%g1 + 0x8] + std %f4, [%g1 + 0x10] + std %f6, [%g1 + 0x18] + std %f8, [%g1 + 0x20] + std %f10, [%g1 + 0x28] + std %f12, [%g1 + 0x30] + std %f14, [%g1 + 0x38] + std %f16, [%g1 + 0x40] + std %f18, [%g1 + 0x48] + std %f20, [%g1 + 0x50] + std %f22, [%g1 + 0x58] + std %f24, [%g1 + 0x60] + std %f26, [%g1 + 0x68] + std %f28, [%g1 + 0x70] + /* Call the garbage collector */ + call Caml_garbage_collection + nop + /* Restore all regs used by the code generator */ + add %sp, 96 + 15*8, %g1 + ld [%g1], %o0 + ld [%g1 + 0x4], %o1 + ld [%g1 + 0x8], %o2 + ld [%g1 + 0xc], %o3 + ld [%g1 + 0x10], %o4 + ld [%g1 + 0x14], %o5 + ld [%g1 + 0x18], %i0 + ld [%g1 + 0x1c], %i1 + ld [%g1 + 0x20], %i2 + ld [%g1 + 0x24], %i3 + ld [%g1 + 0x28], %i4 + ld [%g1 + 0x2c], %i5 + ld [%g1 + 0x30], %l0 + ld [%g1 + 0x34], %l1 + ld [%g1 + 0x38], %l2 + ld [%g1 + 0x3c], %l3 + ld [%g1 + 0x40], %l4 + ld [%g1 + 0x44], %g3 + ld [%g1 + 0x48], %g4 + ld [%g1 + 0x4C], %g2 /* Recover desired size */ + add %sp, 96, %g1 + ldd [%g1], %f0 + ldd [%g1 + 0x8], %f2 + ldd [%g1 + 0x10], %f4 + ldd [%g1 + 0x18], %f6 + ldd [%g1 + 0x20], %f8 + ldd [%g1 + 0x28], %f10 + ldd [%g1 + 0x30], %f12 + ldd [%g1 + 0x38], %f14 + ldd [%g1 + 0x40], %f16 + ldd [%g1 + 0x48], %f18 + ldd [%g1 + 0x50], %f20 + ldd [%g1 + 0x58], %f22 + ldd [%g1 + 0x60], %f24 + ldd [%g1 + 0x68], %f26 + ldd [%g1 + 0x70], %f28 + /* Reload alloc ptr */ + Load(Caml_young_ptr, Alloc_ptr) + /* Allocate space for block */ +#ifdef INDIRECT_LIMIT + ld [Alloc_limit], %g1 + sub Alloc_ptr, %g2, Alloc_ptr + cmp Alloc_ptr, %g1 /* Check that we have enough free space */ +#else + Load(Caml_young_limit,Alloc_limit) + sub Alloc_ptr, %g2, Alloc_ptr + cmp Alloc_ptr, Alloc_limit +#endif + blu L100 /* If not, call GC again */ + nop + /* Return to caller */ + Load(Caml_last_return_address, %o7) + retl + add %sp, 20*4 + 15*8, %sp /* in delay slot */ + +/* Call a C function from Caml */ + + .global Caml_c_call +/* Function to call is in %g2 */ +Caml_c_call: + /* Record lowest stack address and return address */ + Store(%sp, Caml_bottom_of_stack) + Store(%o7, Caml_last_return_address) + /* Save the exception handler and alloc pointer */ + Store(Exn_ptr, Caml_exception_pointer) + sethi %hi(Caml_young_ptr), %g1 + /* Call the C function */ + call %g2 + st Alloc_ptr, [%g1 + %lo(Caml_young_ptr)] /* in delay slot */ + /* Reload return address */ + Load(Caml_last_return_address, %o7) + /* Reload alloc pointer */ + sethi %hi(Caml_young_ptr), %g1 + /* Return to caller */ + retl + ld [%g1 + %lo(Caml_young_ptr)], Alloc_ptr /* in delay slot */ + +/* Start the Caml program */ + + .global Caml_start_program +Caml_start_program: + /* Save all callee-save registers */ + save %sp, -96, %sp + /* Address of code to call */ + Address(Caml_program, %l2) + + /* Code shared with caml_callback* */ +L108: + /* Set up a callback link on the stack. */ + sub %sp, 16, %sp + Load(Caml_bottom_of_stack, %l0) + Load(Caml_last_return_address, %l1) + Load(Caml_gc_regs, %l3) + st %l0, [%sp + 96] + st %l1, [%sp + 100] + /* Set up a trap frame to catch exceptions escaping the Caml code */ + call L111 + st %l3, [%sp + 104] + b L110 + nop +L111: sub %sp, 8, %sp + Load(Caml_exception_pointer, Exn_ptr) + st %o7, [%sp + 96] + st Exn_ptr, [%sp + 100] + mov %sp, Exn_ptr + /* Reload allocation pointers */ + Load(Caml_young_ptr, Alloc_ptr) +#ifdef INDIRECT_LIMIT + Address(Caml_young_limit, Alloc_limit) +#else + Load(Caml_young_limit, Alloc_limit) +#endif + /* Call the Caml code */ +L109: call %l2 + nop + /* Pop trap frame and restore caml_exception_pointer */ + ld [%sp + 100], Exn_ptr + add %sp, 8, %sp + Store(Exn_ptr, Caml_exception_pointer) + /* Pop callback link, restoring the global variables */ +L112: ld [%sp + 96], %l0 + ld [%sp + 100], %l1 + ld [%sp + 104], %l2 + Store(%l0, Caml_bottom_of_stack) + Store(%l1, Caml_last_return_address) + Store(%l2, Caml_gc_regs) + add %sp, 16, %sp + /* Save allocation pointer */ + Store(Alloc_ptr, Caml_young_ptr) + /* Reload callee-save registers and return */ + ret + restore %o0, 0, %o0 /* copy %o0 in this window to caller's %o0 */ +L110: + /* The trap handler */ + Store(Exn_ptr, Caml_exception_pointer) + /* Encode exception bucket as an exception result */ + b L112 + or %o0, 2, %o0 + +/* Raise an exception from C */ + + .global Caml_raise_exception +Caml_raise_exception: + /* Save exception bucket in a register outside the reg windows */ + mov %o0, %g2 + /* Load exception pointer in a register outside the reg windows */ + Load(Caml_exception_pointer, %g3) + /* Pop some frames until the trap pointer is in the current frame. */ + cmp %g3, %fp + blt L107 /* if Exn_ptr < %fp, over */ + nop +L106: restore + cmp %fp, %g3 /* if %fp <= Exn_ptr, loop */ + ble L106 + nop +L107: + /* Reload allocation registers */ + Load(Caml_young_ptr, Alloc_ptr) +#ifdef INDIRECT_LIMIT + Address(Caml_young_limit, Alloc_limit) +#else + Load(Caml_young_limit, Alloc_limit) +#endif + /* Branch to exception handler */ + mov %g3, %sp + ld [%sp + 96], %g1 + ld [%sp + 100], Exn_ptr + add %sp, 8, %sp + jmp %g1 + 8 + /* Restore bucket, in delay slot */ + mov %g2, %o0 + +/* Callbacks C -> ML */ + + .global Caml_callback_exn +Caml_callback_exn: + /* Save callee-save registers and return address */ + save %sp, -96, %sp + /* Initial shuffling of arguments */ + mov %i0, %g1 + mov %i1, %i0 /* first arg */ + mov %g1, %i1 /* environment */ + b L108 + ld [%g1], %l2 /* code pointer */ + + .global Caml_callback2_exn +Caml_callback2_exn: + /* Save callee-save registers and return address */ + save %sp, -104, %sp + /* Initial shuffling of arguments */ + mov %i0, %g1 + mov %i1, %i0 /* first arg */ + mov %i2, %i1 /* second arg */ + mov %g1, %i2 /* environment */ + sethi %hi(Caml_apply2), %l2 + b L108 + or %l2, %lo(Caml_apply2), %l2 + + .global Caml_callback3_exn +Caml_callback3_exn: + /* Save callee-save registers and return address */ + save %sp, -104, %sp + /* Initial shuffling of arguments */ + mov %i0, %g1 + mov %i1, %i0 /* first arg */ + mov %i2, %i1 /* second arg */ + mov %i3, %i2 /* third arg */ + mov %g1, %i3 /* environment */ + sethi %hi(Caml_apply3), %l2 + b L108 + or %l2, %lo(Caml_apply3), %l2 + +#ifndef SYS_solaris +/* Glue code to call [caml_array_bound_error] */ + + .global Caml_ml_array_bound_error +Caml_ml_array_bound_error: + Address(Caml_array_bound_error, %g2) + b Caml_c_call + nop +#endif + +#ifdef SYS_solaris + .section ".rodata" +#else + .data +#endif + .global Caml_system__frametable + .align 4 /* required for gas? */ +Caml_system__frametable: + .word 1 /* one descriptor */ + .word L109 /* return address into callback */ + .half -1 /* negative frame size => use callback link */ + .half 0 /* no roots */ + +#ifdef SYS_solaris + .type Caml_allocN, #function + .type Caml_call_gc, #function + .type Caml_c_call, #function + .type Caml_start_program, #function + .type Caml_raise_exception, #function + .type Caml_system__frametable, #object +#endif diff --git a/asmrun/stack.h b/asmrun/stack.h new file mode 100644 index 0000000..0f9db2a --- /dev/null +++ b/asmrun/stack.h @@ -0,0 +1,129 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stack.h,v 1.35 2007-11-06 15:16:55 frisch Exp $ */ + +/* Machine-dependent interface with the asm code */ + +#ifndef CAML_STACK_H +#define CAML_STACK_H + +/* Macros to access the stack frame */ +#ifdef TARGET_alpha +#define Saved_return_address(sp) *((intnat *)((sp) - 8)) +#define Already_scanned(sp, retaddr) ((retaddr) & 1L) +#define Mark_scanned(sp, retaddr) (*((intnat *)((sp) - 8)) = (retaddr) | 1L) +#define Mask_already_scanned(retaddr) ((retaddr) & ~1L) +#define Callback_link(sp) ((struct caml_context *)((sp) + 16)) +#endif + +#ifdef TARGET_sparc +#define Saved_return_address(sp) *((intnat *)((sp) + 92)) +#define Callback_link(sp) ((struct caml_context *)((sp) + 104)) +#endif + +#ifdef TARGET_i386 +#define Saved_return_address(sp) *((intnat *)((sp) - 4)) +#ifdef SYS_macosx +#define Callback_link(sp) ((struct caml_context *)((sp) + 16)) +#else +#define Callback_link(sp) ((struct caml_context *)((sp) + 8)) +#endif +#endif + +#ifdef TARGET_mips +#define Saved_return_address(sp) *((intnat *)((sp) - 4)) +#define Callback_link(sp) ((struct caml_context *)((sp) + 16)) +#endif + +#ifdef TARGET_hppa +#define Stack_grows_upwards +#define Saved_return_address(sp) *((intnat *)(sp)) +#define Callback_link(sp) ((struct caml_context *)((sp) - 24)) +#endif + +#ifdef TARGET_power +#define Saved_return_address(sp) *((intnat *)((sp) - SIZEOF_PTR)) +#define Already_scanned(sp, retaddr) ((retaddr) & 1) +#define Mark_scanned(sp, retaddr) (*((intnat *)((sp) - SIZEOF_PTR)) = (retaddr) | 1) +#define Mask_already_scanned(retaddr) ((retaddr) & ~1) +#ifdef SYS_aix +#define Trap_frame_size 32 +#else +#define Trap_frame_size 16 +#endif +#define Callback_link(sp) ((struct caml_context *)((sp) + Trap_frame_size)) +#endif + +#ifdef TARGET_m68k +#define Saved_return_address(sp) *((intnat *)((sp) - 4)) +#define Callback_link(sp) ((struct caml_context *)((sp) + 8)) +#endif + +#ifdef TARGET_arm +#define Saved_return_address(sp) *((intnat *)((sp) - 4)) +#define Callback_link(sp) ((struct caml_context *)((sp) + 8)) +#endif + +#ifdef TARGET_ia64 +#define Saved_return_address(sp) *((intnat *)((sp) + 8)) +#define Already_scanned(sp, retaddr) ((retaddr) & 1L) +#define Mark_scanned(sp, retaddr) (*((intnat *)((sp) + 8)) = (retaddr) | 1L) +#define Mask_already_scanned(retaddr) ((retaddr) & ~1L) +#define Callback_link(sp) ((struct caml_context *)((sp) + 32)) +#endif + +#ifdef TARGET_amd64 +#define Saved_return_address(sp) *((intnat *)((sp) - 8)) +#define Callback_link(sp) ((struct caml_context *)((sp) + 16)) +#endif + +/* Structure of Caml callback contexts */ + +struct caml_context { + char * bottom_of_stack; /* beginning of Caml stack chunk */ + uintnat last_retaddr; /* last return address in Caml code */ + value * gc_regs; /* pointer to register block */ +}; + +/* Structure of frame descriptors */ + +typedef struct { + uintnat retaddr; + unsigned short frame_size; + unsigned short num_live; + unsigned short live_ofs[1]; +} frame_descr; + +/* Hash table of frame descriptors */ + +extern frame_descr ** caml_frame_descriptors; +extern int caml_frame_descriptors_mask; + +#define Hash_retaddr(addr) \ + (((uintnat)(addr) >> 3) & caml_frame_descriptors_mask) + +extern void caml_init_frame_descriptors(void); +extern void caml_register_frametable(intnat *); +extern void caml_register_dyn_global(void *); + +/* Declaration of variables used in the asm code */ +extern char * caml_bottom_of_stack; +extern uintnat caml_last_return_address; +extern value * caml_gc_regs; +extern char * caml_exception_pointer; +extern value caml_globals[]; +extern intnat caml_globals_inited; +extern intnat * caml_frametable[]; + +#endif /* CAML_STACK_H */ diff --git a/asmrun/startup.c b/asmrun/startup.c new file mode 100644 index 0000000..09f1cbd --- /dev/null +++ b/asmrun/startup.c @@ -0,0 +1,181 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: startup.c,v 1.37 2008-12-03 18:09:08 doligez Exp $ */ + +/* Start-up code */ + +#include +#include +#include "callback.h" +#include "backtrace.h" +#include "custom.h" +#include "fail.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "osdeps.h" +#include "printexc.h" +#include "sys.h" +#include "natdynlink.h" +#ifdef HAS_UI +#include "ui.h" +#endif + +extern int caml_parser_trace; +CAMLexport header_t caml_atom_table[256]; +char * caml_code_area_start, * caml_code_area_end; + +/* Initialize the atom table and the static data and code area limits. */ + +struct segment { char * begin; char * end; }; + +static void init_atoms(void) +{ + extern struct segment caml_data_segments[], caml_code_segments[]; + int i; + + for (i = 0; i < 256; i++) { + caml_atom_table[i] = Make_header(0, i, Caml_white); + } + if (caml_page_table_add(In_static_data, + caml_atom_table, caml_atom_table + 256) != 0) + caml_fatal_error("Fatal error: not enough memory for the initial page table"); + + for (i = 0; caml_data_segments[i].begin != 0; i++) { + if (caml_page_table_add(In_static_data, + caml_data_segments[i].begin, + caml_data_segments[i].end) != 0) + caml_fatal_error("Fatal error: not enough memory for the initial page table"); + } + + caml_code_area_start = caml_code_segments[0].begin; + caml_code_area_end = caml_code_segments[0].end; + for (i = 1; caml_code_segments[i].begin != 0; i++) { + if (caml_code_segments[i].begin < caml_code_area_start) + caml_code_area_start = caml_code_segments[i].begin; + if (caml_code_segments[i].end > caml_code_area_end) + caml_code_area_end = caml_code_segments[i].end; + } +} + +/* Configuration parameters and flags */ + +static uintnat percent_free_init = Percent_free_def; +static uintnat max_percent_free_init = Max_percent_free_def; +static uintnat minor_heap_init = Minor_heap_def; +static uintnat heap_chunk_init = Heap_chunk_def; +static uintnat heap_size_init = Init_heap_def; +static uintnat max_stack_init = Max_stack_def; + +/* Parse the CAMLRUNPARAM variable */ +/* The option letter for each runtime option is the first letter of the + last word of the ML name of the option (see [stdlib/gc.mli]). + Except for l (maximum stack size) and h (initial heap size). +*/ +/* Note: option l is irrelevant to the native-code runtime. */ + +/* If you change these functions, see also their copy in byterun/startup.c */ + +static void scanmult (char *opt, uintnat *var) +{ + char mult = ' '; + int val; + sscanf (opt, "=%u%c", &val, &mult); + sscanf (opt, "=0x%x%c", &val, &mult); + switch (mult) { + case 'k': *var = (uintnat) val * 1024; break; + case 'M': *var = (uintnat) val * 1024 * 1024; break; + case 'G': *var = (uintnat) val * 1024 * 1024 * 1024; break; + default: *var = (uintnat) val; break; + } +} + +static void parse_camlrunparam(void) +{ + char *opt = getenv ("OCAMLRUNPARAM"); + uintnat p; + + if (opt == NULL) opt = getenv ("CAMLRUNPARAM"); + + if (opt != NULL){ + while (*opt != '\0'){ + switch (*opt++){ + case 's': scanmult (opt, &minor_heap_init); break; + case 'i': scanmult (opt, &heap_chunk_init); break; + case 'h': scanmult (opt, &heap_size_init); break; + case 'l': scanmult (opt, &max_stack_init); break; + case 'o': scanmult (opt, &percent_free_init); break; + case 'O': scanmult (opt, &max_percent_free_init); break; + case 'v': scanmult (opt, &caml_verb_gc); break; + case 'b': caml_record_backtrace(Val_true); break; + case 'p': caml_parser_trace = 1; break; + case 'a': scanmult (opt, &p); caml_set_allocation_policy (p); break; + } + } + } +} + +/* These are termination hooks used by the systhreads library */ +struct longjmp_buffer caml_termination_jmpbuf; +void (*caml_termination_hook)(void *) = NULL; + +extern value caml_start_program (void); +extern void caml_init_ieee_floats (void); +extern void caml_init_signals (void); + +void caml_main(char **argv) +{ + char * exe_name; +#ifdef __linux__ + static char proc_self_exe[256]; +#endif + value res; + + caml_init_ieee_floats(); + caml_init_custom_operations(); +#ifdef DEBUG + caml_verb_gc = 63; +#endif + parse_camlrunparam(); + caml_init_gc (minor_heap_init, heap_size_init, heap_chunk_init, + percent_free_init, max_percent_free_init); + init_atoms(); + caml_init_signals(); + exe_name = argv[0]; + if (exe_name == NULL) exe_name = ""; +#ifdef __linux__ + if (caml_executable_name(proc_self_exe, sizeof(proc_self_exe)) == 0) + exe_name = proc_self_exe; + else + exe_name = caml_search_exe_in_path(exe_name); +#else + exe_name = caml_search_exe_in_path(exe_name); +#endif + caml_sys_init(exe_name, argv); + if (sigsetjmp(caml_termination_jmpbuf.buf, 0)) { + if (caml_termination_hook != NULL) caml_termination_hook(NULL); + return; + } + res = caml_start_program(); + if (Is_exception_result(res)) + caml_fatal_uncaught_exception(Extract_exception(res)); +} + +void caml_startup(char **argv) +{ + caml_main(argv); +} diff --git a/boot/.cvsignore b/boot/.cvsignore new file mode 100644 index 0000000..b9c6f85 --- /dev/null +++ b/boot/.cvsignore @@ -0,0 +1,5 @@ +Saved +ocamlrun +ocamlyacc +camlheader +myocamlbuild diff --git a/boot/myocamlbuild.boot b/boot/myocamlbuild.boot new file mode 100755 index 0000000000000000000000000000000000000000..2ee22ef5dfbd950ec21c3f782b463785fb9229ea GIT binary patch literal 394071 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�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
A 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

l@}VJK3WC_p{S{*WEG3&Z*Y@rgbmz zN1Vufd;Iu_{LzCq2HzjZ~IxdGNs-0&CS%Ummyc<)7vE0<iqKU^Xu=MhfkXK;w2Za9RI|xJ-oKRB7CjeXJp+S z)HB#x+sqs}a;+U>{i1n3&B{+QUJ$%HHRt}nGn>w)Js0o`?cIYPvf{sx@ymm^1>Y9@ zV(`IX{D|O6@CCsS2mdoT9|t}rcx&+2f?o)3NI-87vivZ)cW3Ug0J)a}`P9m(@A=x+bfwoAQov>o)l!20DtOtjX;#b*rS za#Nr#*V*~2F}z@F`;Vqw+S&N9(|x(LbIjdn@2T+G;~d&^Yrr=x-^zLe`Z7kIftP}|V@$n2?B~;?y>oJHukIT9#yjWn8M|}j zi_ShbzdnPbfd7Z_Eqxh%eZs7FJcHvM+B)l<@<{H@PmbcFf*%L*9^^ys!_kM)$46uP z?~cMp0`~96e~|69ZE5>KXZI-)_(;LNb$cFb+x~O(JQ}cXxo>IPy1G=K_?Gc&-S(Nf ztlO@){%?znJ}bxPfcIwdZx2q)JngHogYxv3vi@ix9^>Al#NyG^(tD!kHv)Ec|I)@W zj=qOIC{N^A-!D&n9*=nv|M9)zpm)-jhW9rLHj=UQbG&QD=dtGtyVa(C<8dba;{iFn z@72*`fyS}Awd>B!$yxvM+$`()O89E;+4TE8-ZBP9)$#1eSn4=PZeupSyN@8#_ID5HvjANeJ?LAZTr6R5t)-0HE2!SHSbi`=(g5&tiMy4XD5H~-WK3(yN>s1 zS!Y-86z>P^s~z&lK>9v+LZkg`i*V$ff#Vo4Jhu@kJbO46LD} z%q{cQTK4lDMOrh3L z`M!7`zSfTCmU?--%^`Z#mY6&)kpB~b*woMZy)J%Bp8ES}_KbPiPfq35A9+}}Z=7q4 z*gpkGZ0VQ+M9zLWs*ja}`Gj-tvWQtKMFH;4jYy&-3D_rXClJ>(1Z3!5Ay@JQwRzV@c+I_XZgw z=orUi|I|KfubSuS=^5|ySuKd`2L_je-x09$MZt*~^}+uCw{mbgx)59LU-jNM#(pM> z*u5?X{l0YR+r{v!d46pK{31gv=+ibnQ~Gk<7(6fi&&dPDdGWa)l23BbUTyCEtn0}c z+lR4Zz^4AJWlG;YRlVt6UF%%;kj-B5rT~#8SL8+AYQFNA&5!r2 z@xxhL)*>67S^LH~(P2$|k(Ld7Q%8*k1gU)?=t>; zLbZ1*{rdi#^q2NenG?&=-tJxUR*pSly4)isw+ANzeR0kevZ66Yy~FxEB$v*H7t-9Lqwj7P#R7bAc3UYX5lbJzLiu;XRUj7Pca?4H8o?2mjsGt1gx#~5?= zj53$!$TMV=i9>m*cMD4gad)z0+ zUz6X%`d8WiAA%DZ^YzBS*>zXGGr*_MzfphhZ{OelM&OKhf4VC@59ow;_L@~b)O&S4 zDSi7MEAa6Z!O7rCFy<%2mEZ0HYhw(Y-SYwZ-o&tvJP`muhXe(fk^V_qlPEQ3s z=TWz8MUD5zr(cNsX7Kc3&f13un~S-ZWPImhF2hy*RTo?2Ts{0yVp^NT`gE`nj6Ph> z*q$-Il{LmVEGxgeHtPAhee~EvKCIjKIs5Dz?Gx*x*tc$voXA;qkN#ZAeCy|I`sadU zL2Iecc<0)k%LX;ze!?fOZ;k!psYbT~^Xw(p`Y6{LzSji3qvdGH^UBQ0ePxaJio8Bn z=k$4z^|^VGP#?ZuLwr!X@}=c><1nRO;sSp;vDea1M`ezCGJW;T?WF%$#_sdh#7?fnjUV-UU3}(nuWAKf z{gso?k6d!ZoqyK^{O+D_%sV~Mj|}uB1OGi)uMTVCf=@2q z6Cgg|VIR5j`TTjGG5#;i^Z5hPc6=pc{0<+Jy=gVyok(R%;TdhTo0 zu-5ZId+pr1TZ}j7);Ti1X>QNX?U}UB6uC%#$aYTtXyWHx;FlO364O7HIXdOn)um_Px_7_IByKj{3Ea7v8*U7h6UewIL-$%!C-`=xv@82uZ z|M=kD!8Zo%z7)vM9^c;ov*{g{ZO)JH&&3BH(z5@HV!tyv+AlVb4^a93_!0TO_=tR8 zazwr_JtE(qI3nMd9l+N(ip!UWPn|F0BB%H+2iC<$&Ac+WE_g;Dw|L%_+~UED$9cei zA@KbTJzo($YW$jD)U}gwmR35_ta$%qCde51Zps*6ZC3+qA(I{GC9#A4+9BV~>sMy8 zb3DqVo1biQ=YCaqma*vbqFPj(7_MSYyPw8Yocp;_W5@r zVAt}TiJe&SODl%@|8}2q>MnAQQT_Yc-z5Lsaq`ASd6t{6TcgXp=?>)My@7l7jsRT_ z*xA|@qd&by#!lwN$33u4@7J%{^GNl6!x|Z*-Z3{e~w zer^lobICvcf2Sk=?cqHU^gQ`lLu-AE|2M{m<^8#g1A7~P`D>m0ne25BEYBXj9$#up zA9c?+?GrP6>*|@$jgL6&_qV^lyY}OI?RC*Jjvq-sTd#gkbVK@{uWIhrK#b+`aa^w_Me(%rInd9Ht;9Q{oy>roX ze}J3|a{qkf%F$>ax%UR+xosZLXP&R)|LfoLN8VqEyn~)OmF z>)#%zkv_-7*7^F*=y5M>%;WFM*j-3IJO0m%pODsbXpHYp##vhF8h!hF`TnwT8hs<{ zyR%_kyxBs2eX_rKuPpiHC;GDJXw1|_{iNfs&h{?rfxYI)qo?xaPaMa(8e>Q1_e3T= zOaIv{p6lc_?xStrdjvUbc}~EtaqnN-Cw6Llj2*qpy?^}(dvDLa6G8VkK4Rhg+#evh zQa9fhnPc62f5z?&_LK31fL(kTV=JD2BfQqdZW&WG!~WJn?O7-1y^*u7p2nCohH8h* zf0xfQ=y)JN_2>VZ{jrA6y1S$6KQOOvWRCwon6VlZ8#T4g_r}l~zyD_T@SBdM-)fV* z`YkqMsr~HWm4UdR`}dlww*Am-Tbh+^e`_As*1w%`&-7Ru?bE}Lo+&ZwnB9LT`R*@^v=*&jn%t<1_S;yq{g4z5DT#%id=Pr-KuLxuxy=;QJ3h3Y$;m z4elk``|{wf;Nybb;12|UICy99p5TjuuL!;__~zi-gYORhM)0?T9}j*i_!q&y34SH` zwSd9?9l+liTpw%(XM$%19~Ml(OM;gNcLg68_`5)#5%^m}UmJX9@cqHx34SX0`QWK3 z_?v=f2X72MHF$e)fAIOimjquGd_(Z(g1;PmZ}0=b4+lRH{7mrk!7l~B8vKu7BZc?@ z!G{EQ1g{L7p}&{dF3&=9V*N)BS^v>P)_?4f^&dZE{qG;L{tpgW|A|A^|KTC)KY7Ud zKRRUnA0M**Q-`eolS9^j`jGXXIb{834_W`GhphjzL)QQKA?yF*koBKCWc^uU^?!ZH`Y#@`{%;Oh|F?&%|KEqK|I#7r|L&0We}BmOe>h-0*V)>4k6+Fn z&%F-|-W$9w*afzOg=zh3}yHXxxq;f$u1B+c>~3aXoR!`r{5+fBYfq?|;bp z$wSt!Ib{8}9kTubhphkhL)Jg=koDhjzrXyp{dXO*{**)3KXjjUd6B2_ zJbIR08_4%|;Cm>9*Zup{K~|qLU3=OAYd0LQwt2wX)&XnVi#2t7TcB?EackgS?%i}M z{65F@3>xqKgZAvK*|Yq<^8Uy}zUOu~-IzUW7@uXH2`A?D(+8|qHeQgMjTyPhS90mN zDKb2NtMkk}=9l%e^H@y8f*dXQ?CFWYlLMc#Zv{67bU!`ty(}4iuK&Whe{Po7we#~B zKi-??F&V~BpU31HKVu%#W&F%}+|T)+HILb3{n_*QiSzivJZ8J~=gedN7(aI&Hy+QM z$BoA=^SJSNW%hWN%D0oNx_*Av0== z>3`uGKg5A8YIKy7;rr}=QTDHU7wdj|M*qjUe{uGn$vXSweOin!4&$3=zBKQ5DSwyi zyiVxfP0(Uh1 z>{NHBg5AJ+@AJ-2nL}p+=V+9tZj6PAe0q#qJD28KF~6+Y#<6i@%NR5EE#cl+&UH)& z8c)Ja%r(?{4P7o}P{7Z*0Y49Jl}U%#Zc<2^lvhJr_^R91_cQXW-7& z>Ryi6#xF6DGh^~v!>>r6AI5l$#SRaCIIL#(^My~N+-GKt*nOBU^39g*0FAcur{j(E z$9Sm+wAmO?|OV9jR+^L~?&kaNZzvU)}@Ad_kc0TA$?0hrP}w zn_8Q_KjrC`fG+-#tv>4q-TY{+-;+K$=E(25KDr$225$@SsA-}oJyy7m$@*&53I%=M;5AQ~xMfH;n z{6S-`|Ll-!u@SFje#Lw_C;!d4Tpg72d$TTgY6Ho6^W8Nz%j3D=vC6Uh*8h)9U!M86 zgt#o{I_6vJ_`}lgU3NNsxw#V5H~B(8ws? z-jlI--+FQ{?zg4oD?i-3_KD~D@R?UT&U)X)wZ0d6QP7+?$9UD=?UDD2v|IB9;SSph ztlu6yH(;OsbAl;A;-D_ZJn~QNk)eM%V5hv0VU5iQ54$b|{Ci34V1l@ROMrF)cL!S# ze*5IZ{C+k(Eo+_u{18j$i(dJ)*7Nn!dCobYLtNN>cR;qdvW+hG^W&`nKRza~{<6T{ z`vb)O>fsL?@U!Piup3MP(jUi@$c?v`D35&N$kUO z*gi74ud&j~dFRP_UT{Y`;==DKK+bvNXI`$Bu|A%;Qvo^?v>xqU){(frA>ivL2V}B` zOml474ekr304>LA@A5qV?6mffV@@k3YQgix-u-y!wZ~aH8L+{A@>=KX*0OxnX8Z6r zXV%omC`-=dZ)44x+~c1DL?0XcJ}Dcf0G$cMeqB7pW1XLD;G=l3@AHEzf!MqzU=Nw^ z2y(rx{$HrhvqAjG)|zK0Id2U3Lyo<<`W}=o`s_P3w_+=&^j8i$)pLGT=|OSBzs%ch znLCV+Ezom&B7MGz_3_}|V636$vF%a!Ip6hzeA|Z5XG-0O zNA28Af2@_|m>jt_|J)$|8|A*W>#Q8cx9;9)t*pCux)#w_@0}Crk1@7Zzsld*Qmf0g zlbKT=Jr8ZC%%Rpxb$CA8!*+QU6Jz;TOCOzqXXH+BeK0=nPi0)*Yty%PdGDELk2;h) zanP!Dee1{P{@c>Z=@%pqSJJk2(_P7)bV8kPjq-_ZwPybp2Com))0^gYU0sc5Zdq5K zl6~rme_iW2Fvs`m=O5j@d%Vx0qtpzUw*|YwbA$bA(E5GB6rkmJd7rgbHo`mJXPp=G z-e=32vnHP6TK-qeeRs`rO+3T^_%j7)S!1EH_j>E7cbECr7$5m9M&icTbv1_PD0M~7QR>S5 z0j*uNa3v5Ab#QMm)?IySd(?gZU)QI29JM~xhq@CNc@T4BKA>fNlC6%&KT2KRzo^Tj z?0Ms2PgJe!SXax-duhTPVxQWvZr}2JnwS4e!HWZS@muSR=$FPAoXMm(Jt?>xkW0=K zAbOt?c-Gt$So^KOdp35Q3)DHV-JQgLv3S|sz9%hWch3fYeQ))9)A5|dKLyD5N9ch- z?D%i*Za}^`YzK1inm}xC3_LsW;}gT)y=2!W&z62>NY+o!eD&_bI90Q z+Y9Nl-`JUDk3JbwfV$T9LgvOj?6>#LGcUf%(HAE%+zG_%x?r@?-YG!%k76HrQ-JIt zqwR(CAE|xvH`;eR<7I45XHK0}kCv_Uoexd~&&*v@TdbFNZ3TkW#+>xmRj?T zr~A>IRxH<h+L`Kx@5vmp1+9d^1{^+5-QDptk?>@cl;Y60gy&46mL&waa!f+786q zeQM9;pl8Z>H^9p;yw1>ajt}ktd$m)5%+qC_FH?Zbi|GS_d*T`M7_XRX#k=crjlb*k zSEu`!UFA=Ab$5`9r!j0E)FQvEHAjuTwaT{6ZY_wxvMx6=hlkDL(*Ae{*oVkiXNy={ zTW3q>$+yl&bFj3{S=b4BrXQ{Uk3^@Oj5_-qq8ptFjt89=FZT_9#98j{2#~({*92^E zf2z4B2EJE&X+Z8)a3XN$oDa~?=M3X<--@St_#MF%AbB&Ua|)2LJe>;INmuP8-&tl4 zyLukzsK4y^jDVeN;TOKk!8$&=>Z|@yeU(pjKLv;{YRWttjOkRFV3huuStI+pac5cdvf|njLJiwyTo2Lu+bhiHjWq5M{i|IPu$1{(_>+OO3^2xmKb5d%npPRIQA#oGayfGwr?!HQ-E4q^z_`&Augyo$;I=U zpth6ssz6>&1awx0@pd2<>}j6vPM=JBZwcg(J$PCt?Cp7C-#Y{R>|(?Dx&JeBY^RKo zoQ*at{n%J>?Y*Zq=6KNMpmwnNWdZwMmN?5jzxny5zj>8|Q#H|>iJLip|Pm|V8G zry_1;KU@CNY`-;o_+|bJGtUOKOP76gYb(c^Slk?ljrx6R_K{Ct>#aIFwohK@LZ6g9 zbc=s|^xPo>&nm~^slU#>{iw31)o3rT?36ossExPJ{hQLN3q&8DPYT`=@b~@z*?)b| zGs+He$v=O)`v29Jd&NZl#DgxeU}MK>%$cLRa+iD9%09K-+Tc4Pr*)5y-LDPA`b?mP zoC7}4fxq!GX3O0HUNZNqdvSNp>fbxluMO-S<D%OQKdD>+m*=C$OjDQ!O=61!Iibd|Su*>`K8 z&bH?D?&k+PyQeueSDxy?LkFAaHWn9oRWEegQ=feXfY^y4&RWD0}|y zu!lVR>86X1>W@8qX`Gw0+SpirY-F|0?B5R12L*Uf25JWXst&`iR>(u|-fLEC?6AfM zWM5-G&a>-f0lhncSczM0-A$kU9b2QHT<=}hTEgnERJxUS8N^ewnxD%UD?^&~FjHQ14ozh2gH{NMbUnH{ht-c4<7G6FOM)eX5;SZ9eQRUx_*r|$9MVl^>qu>kb<}lxzwE99#Itp6(G>^S1`%YQ;}M7Z19W|0j-5-8bv~f?ALV?~!!|9S>9{?xF4rB?cRDy3h(qrr zac;jdjOB#Q^wnlQ*Jg17dy4A9H|iFfn*uhW|39{mKDO?;{bJkPs4tMiLT=QDdTLJ9 zgxnmq&p9}3U+Y(GsfTs?)us7$vdX`kbvCz_dJYb;4R_CFzM&Ie)PgePty7#kn zjMu2!S*om2_pO;fs?WFW!@EwWSnsEEKRLB;^mRY`s#Dw=JNw4_VagcsZ_){k`8%2M zcF=tGF1Q9`=-qqGDsK0te8{E&!U@bacErd0$V(j^qm#Fpg-DcFS;DCj~+UV*~I?S z0lp^&_KShm`V^pP^>xqYJJP={DDOMdX9uc|(O&ao%&*LR>_Fnc=8ZsXZVmWS8|g9b zb5||&8LN-fLSxOR?V!&HEuT&WQ-Ij{_*L(b@7>M5Y2I5o^_Nd#!QL?s{Azq_4;x<` zpvG-K9x}@#e%;5G_UVwb))ZSlHFcC`6^rv}&3T676|<4|OEa$y)b2Zi4BzMX3+2LI z?=UBW@~T&7kWXxoLw?Gk*7;e+-~PspfAF!ZcJKe25JT~JUhpwtHujGBEdf%uCj$G} z<$d?}g^&J`@1~6THS)dU0KVEJR=`KP`PVw-llXOPP0Z-9_LjhU=lH*TKelH#Xe^iO zy)W>ob22NB?EUufU)=2zmlp-%gw6!&zCN-Sy)3X#%h&q@^bIpZ$A2p0#-ugE-^M|0 ztUJG>pNH|XL%i_y-u>qEuLOK%Uu76yGt9p^{n~|RjIn*z)T%x7d}eTGpw3<$aFpnN}_l()w?|o0EFE-WxIq4(!(sFI|&mOrHhuTl)+XK&l-eI-n z6`7MC&#CI}oHM|;+7S~Ud{4&YJvq2HSo)6lQlM3X)w51Nd84kS{*CN!zWAbUE(XZF zG5O?-@vdF+(Dh~hoRu+utsgq=Bfs{O|K@r8+O$W_ssHbL%&9n^37kdei+uGYFZh7o zF`xCn^X&MoRHy1@jI%h7Icg1xA-=}1zK*rE%+dAXA9Eyb;~5hZc^4CHWvkD_&YRE8 z$J}JgDmQ8hv9-DRg!F6gqsh&;Y%-OK#05B7|6OC4RWO#Y+V#P0T& zdq-dU{XzAzg>0?0qsZtpjt%z?d)Tl}*EN}6#$Q1@0s=t+7Ro^!?_!>G$qc@4a{J_rB)YHO`UU`-Qwag8J6Ft#5Q~ z1a!YGPzz!Pbal?N1ziqC*=nxu3UrXy^=s1?JM-jtSNqZUDSq8!UHs@f8=MR9<6-L< zAF{`|JT+r+xgih(GRAiYwQAnEyX)lMT}8%t_BJziryRxhUzlxQXRrO@&OR}c8-2Q8 z72O|{cGSC*F?+N0Fu%!>vt>T%l&3L9>v+{edDC6lBo6GjJIdHV_w~U#d&FYYag;oK zWcD0XpZpOM@em_p=sA}oIec0`zq(`ZJ+asG#lF$j&5Xs)`>K4~E57z>oA>(t>RHY* z2b<~&z^f9&A*=!^T6obGk!@prlRH3#fv zw|KoaJj+=1+4B0VXZh;q4R1;}yjUHnti-=at@2)j|(%gRN+@6}-8`H8|9sc&<9kKgYg3JFgi3!w= zGgjL^C$`Z~CSMxkdo%w5^StL==PzcST>Nx){zEg*2lHyB^ZzY>3#&e`t@A&hdH&*e zZaV*CnIGrG{(CZ48_x{9pEL7z4)0w9@412Z#(AEN&I%o3p{?xN=~-vqGfBHSx6YsO z)93b?X~mjeG5Miieegkd!^cH%bNj}O+aK%XTk~Q;R`HDV8-sUdjZI{-iM`h3^xV8= zOz(H)@1c?L?4WZWnmPMB{`mZxm&VOc{q@dhZ~few_c-UD_+R$qvKf#2SKHdzNdH23 zmUiM<#NOu@f7x9ZYZy=m2vRy}CX&8-|6i?Q}ub9-TK zpF6kiUF*)b_QU7aGtu}(b34uL@1EPsb9>v|zGQAcYHmMzZeKdLFQ40wnOo03@?SZ( zcg^kHbL)9*-Ft-g4>CkB@S{)vs;Ig`hOvw=A^1#H=z z`}WAe2Lx(H+^wq!=$?Q)F_HIo1b8k4_R-n3DSbpP9aDhVdm^|J&^rYP-=q`5 zb9~j?vxyDzOxH&6Bf0KgmDauKt|VVv)ZTVbJIKEyKzQ7*WQcurkX;-5Ecbqb_=1m4 z#Q!Tn&pbWiK*sq1pMRH(JY%}PavqzT0z{@5$l=GIe7L;s``6hw-YK4Y^mYC3=O2Ej zdkPTW=zl@*36ZJpPNW#t65b?Oaba1^J>i9u%E8&tTm79xD>c!v{Qhl)z^n|B%W7J?wtpFyDo2|oz?G-uYR#4 z+rGB+IhX2;y%GI>#{<0LGX;oWYGxx~t3C2zk2r|gZZHL?{AAIwJU{O8DM0moT8;Mh zI-7jGHwKYK&N~0D&-{M=(J}hQM!e*;kEgb=V+s)8=v=4UI=}A-8fWo5$PTe=ZX18P z8_UN3$(a-9(Jt>9_M6kX|8@fR;dbC`n)~nB*!y8TH&fOSUrq*N4$0sPo8)oSJId%@ zwz0J_W7`y<^0Y60jki9c%YBCULa#Y;kU6rqg4P9_#FwA^odQJPIvwWeMP%EL$TsFD zB99*WZVYN8U84;9%3GVJ%%SovYZKr3fE~Y_yG4H7Tm0=ElkUo-EF9e$~#O9qha&>$TH4eEk73$sJ>e zfA;|X(Vu19_I%s>cP-iVoim;>w`?}|O>^7zgW6YxS3XVz&Ify&5ATj*eRpss5PLCv zd|(gWw+8CQe(U%)0_5J6&`dP(}f)$q~3MQrN3koN>oZz1BOXbs(yNl&9)ITC zo=96?-0f3<*v3hRI`m(f= z{S2MZDBF3IQ&fH0o;mh7b3orZbS=wQ?-X{b>&8SKvGI-j*l6ud`>Z`bYdvS{Vka(i zu}!Q_2lS2c#Z&+48-D&hDbU{uo*u{@K9F_yCXlz} z-Oil&tlMKA{|f^9Zwk~QBFo%iJnBw<-D!wD&TMs(Cr|u35un>_6h5I@zzslc5>p8JGP$p1Uq z_|h#G&iGdFNbjg@S?R7Fe4k8)dRLCE*zN@KLKk9tdD!WB^n^fs$kXT3QCm7T13D^K zYkt(-_#GCn&p#wy>=I+=NnC&M#9mE_>lC1A_4T1vJ@B>lpw>Xms(1a?Mq6u73y`_m zO^-D`ZUkaxjlb69*c=<}W9Jm0Y4vrlUd6-y-Czn3JLAsP@1NPVTtA*Uq=rc#<7A+w z5S_OMWZ93*0UNgh^?GAaSzUk1Fh9mB(<`5^(+S~s4uG%qy*_uIyz0|V0h(4{_iWrq zpPlSwPxYDyv3}Rwr&oO2TKlv>EE{ue&!`-!d!O@d2l(#}klfnGF7s@47UWAj=}~KK z)eqUNar@Q$W06; zPBver09D^o?zoSQ6XsC)+dfwNJfA-)0k|ct*iQj+H?yU8saVP#pN}&4obWm8a@HCn z55(x^K>o#EK6eK^JN?ao&eorGdcCiUV{N&de(O&=1!!7*-CMggeQRm~zuJ>4d82<> zW6kGI)|%%lGr#)kKJvhrpUZuC>-$Ff#{#v3k3HK#Wte|%z#i+~Yqj2CwAan8+A>!A zHwWTL&j;lm|K`AWj3s`4oCxfxJ@`N_o;CL`rER>m*0uwCF9*GEs$UN9s8c+A7|%W# zhz-SLBBXxR2iuW#v6up6Jo2d1Hzzo^q$PI>kUB+2smc0u+uoLk`NVd3{XiI*C;w{u!DM)_05$X@4MZ0r?VvBqnhFs#9b?3Z_o1TrVF*UwUdcZbv=^$ zeoG8ff8;&RXmU@fJt2Os$>unvsIJSm1(nn;(;<@9-=#c$nt)YeA!8`E)faD486OMXA*_T0ntvVksr@f&Tl<~hXg%Ry_8jqI?F zA2o+#eX-5CHHX&mkX0W3vC%#H2NLvK(vm*~NS!slVghFZdr<9X7oV-yZtWDH?xE+C z57E;+lKI6phsa`=xz7zyb+_Gn7yppe{lKrs3heRu>!$}N0yfCEKD*ond{>`hTd0wp z0G~W+@tqIQx9{^k*2weq;ZaXyZwJ=AAMuS{>M!A3+0p)#F=9vO#K>KYyifT1^_ywg zB(9f()|!@&rvkFAx2~^CpB;GYVVgQun`&=)pU|l$E(VA_WZ|oAWVqAmtF9@1q;A~N z?4Z-0b?q2yev1#i@@B8P`;>HUNlV8RAoVSd>?uZB_MQ#S1^7l@c3bEBc$d`IgPwij zj+&D*>9ZG&`OmKrz0cxXV|cyXM@P>~dB-Lwbjf zHSlTs_)7=h#@PS4HL+LYY#Q&}DPz>U%K>{%1X}?=`V5Wwl^%CIU&i^{GiLL;c`+hu zH|QR=jPiYE%6D_(dOkQ7_?yb?W%q@^Ivb69S82%xXN=8LfTq>ghyQ$_bK-SFz!tuV zV`b1`UR=q<+w&_vZ1qmC8Sr}w(3yaoh+K8@ zkpW(ET4UnCHafJ;CEJZ7a`jv%Q~#F4b|Wo*aU~1nXeW4LupQK2JYoXsmmm5|{)?GI zW8Bza5BcmA8+k2n?~;zEtRXSr2jB4n8J+|AmC*;;DGqoVCowt}u+RK>t}kQ^WVAoF z*U$6fLO0oDHE*v;pU-k2E+gNoGNw;Gu(R-&uHr|xJ zHRR5hm&R*+$2p4Mqpy{3?kIl$Nces$`Yk``fxTuGe{;LRG|!297S&@B@ecfBf^Nv8R=mWoY0|uktnF7Sl=GxvVKzPWW0yM3@KE!Xx7d|&8?iD)F za_v;+$mgrpdh0+u?M*uOeZGh<;>TTqv3#m9H8$e>V*C+{@yOf0debLY?A{xA&g=WP z&dqNJSLQkE^0F1&61+7$cy|Idjn{ar&5ex7=~-wUiGyd4gUa}{^0TDOj#5{z@LbN0cQ8@wMi!+VQ9 z-?e<~+F>oZd{94P>)#H)CM~8V)mV}bjpa2FIzqj6On>{@zqS~UYx?AhW#jXo(l;kQ zzb#NV^1B^4b7GcoUp?>lrO)sFzSmCrCxVj!KCx6^AYP{eGMtUef&I(+wx12w*`V!N zu$LV#3>sTwcb7QO`HJ9g1Z2>^ZvDG6Z~vvB_S8?cuoaMXd%zz0$zr$I>;~r8_Jn|) zZR;mq@}~eztFL=!%sju@jl_8h)S&!p`9n8#sCku5InkM36kOF!+Og8GSvpW?vJkD15y;iVb#n{0c@ zZY_v|etlxQn0IV#^x66Y0XiSZ|NRCbexk0QN}o;SH3n@jWX`&^i-G!)Gx0)|Nk19( z@w4r?f1M1xP?;Tff7|`eo;Zmae_=m9IXD}f3&aA%x%DM>=u#l=Wbw7}-JR#Av~1KO zcAp457vGiz_rv)7vsS(A1oeCG+^4H`#uoa;a@1`epE>Kb`S+y%s^D3{4Z#xww&BC? zx%2oy46m76IiUYUa3xTO8^MzU`LoB`=G@v#pIR3aay{F&=P`SB1ANw}02w#mbYBQg z1?pey?+(Pyn$LCW+gsCTpZ#nXo8Gx%S6%#^0)*H8i$QhWl)k;_o?yS)#K&$nkue2` zZQ^n^I2YItY`ZnEW*@M>?*=!gPZrz#n`ZK3U4HPgTg&FLtzYIg139Q)&8Ic-Hc!sF zc&hVt@w_hc*4QsE`f^!WZ@KH#%r^&=j9&_4)SUdf<`9q4k<@y0w>C;U7e@Uu0V?$viL{Tl;&>We;H z3TpdTrH?wN-u>-rA2&VhkIBn7ixSzUgwuialqru^U3_#;9OuG z_THuUe(!KIWB!;I|K>z1*UfS7fM;iJGr-TL%K^Lir{9_y`T5Bvcg0Si?(vf`>J*FW zQqQ)YX1E*o8;z z^wsA0xr#Y4G5>-9iHkjQPRD*ew2t^8p2n3o+TD6}?lyzwO`J!*qxzR^SKpUggXD-8 zUCpucCzg#fpVVY)toj;f?S63;3q&?P_ldY~1hqliSnKZ>Ycg&R8V503#+g3xIu>|e zyD<03ygk9DmmhqqetmHeS9W+eJQbKX#`kD_AM2LA^;3W8r!{$?Ygs$)@6U++x1<%v zDM0S;v%$GQtwQe{v5_lxH(&TJhICvG_}pA-pBt?E{e{*c*<`M}FVu1E;IsJC#n#>r zjd9<(#F(rR{4nP4XGW+Pjo%}%fgkFz@iQl8Q-IC{Y6M?x<-c0EDR8%qYg5K(xlfF` zueM$q<|@nH+XA|74VL%4=W@R{dQtjpL-dK$7&oyKFBYuh>QY?6PU@u3?7IuTvFL4BRlN7L%-Lvjp{%G(@KcO`HpdM?z{b|A+0 z2gq5*#}07bo!xiF?kTP3nifr~uX{Ysq5PqrT9d!#=}lSB@`Dq`kh|_#0iEJ9{@ynI z;#pgIZcb!w3edFr`o3-VxC7b$*$3Ez|s(>{f5=kb7(AgN=il7*bL)ItqsyAU`)@N)Q|n?#&+`NFo)p|4AaPd%WRm6C zYm zY+XFFb!ERej&>R^|%W~x&k?7@3JV1vK)-r84( zjqA8C)2ljXAENutAfdP_lg+im`-_-~*So_+{`juNhf)5OjLC-4wtq3$CZ?5}?kYy? zb^g>bs$Jyp^(ZkC19pDS5$s$SzkfQ|xL^G26Cdm9*k@?!PcDil4*kxxwf5ow-4l=} zroL|!=Np3)0is9l#aLX)=-w%PWStCmHyQSJu6eN^#J$hM-Sp{Qz5}S)Yl8Cu^7qWg zno`4)g%BCd^<*M6t-kJ^$x+UauaV=7UYz;ydVZe^oPTTHncSc3t_|s~?%>`@TN&eF z2Yb}*W*`n^lGSGp9{b$a-6y8VpNADGXd zOI!WjX0iUqCPJewepimTfO-LP#C|KNKjU68=-yfMDt4DL?>YCL2*>l9;70>@0r|-D zT0Yb`yTsYP=EXi^vA7%<-x~1ow%{#+*cEK;Ichs)4)LXPZ6^yMc{O)@ZqrD8R8HGHibwvF$npO@IOnGaKdoJVviI1`X}#S#wujoaN(lPo4_IOD#JO_XT6T$YrxuO^-1nqkGvz20pQo zbMYAOLN&J;h?9=hd*FV=VG z{*)H+;bOp^k)K`7mzwV0DSb4pzV7Xz3pp>X0sh_?91qS0=YsOl)tvpOA!pZSemfXz zkxgXS+x}AC-h1(fyx(Sc=zT0epZI^l$-UUJOP<|hNPH%p5W6;3y@&ES&Euub`1n(s zZ%Y5Mu$K&Uf53M3(Ivk{bE6h^0<{tM9>(WBV3V_P)cs*y<^8>BpF8&t`n|nnU8pZ` zhS=6vyVLsKCH9vBwZS*kJK)x#-#I?ufdV`}3tp02Bz))c*LaF@~9=LtL9e{97g{-cd*&sy(ZeKPT=fwoin$QUjLVsIgl zN6#vKB-VJ?)BBW7$LD$RILJYpzF<5GN27A*c_>(idNP`;4$pe6-DT{UQsm)_U#YE7>pw2oK*c292Hbp$?H+rk{=}KxcxD z;B0U%;FmF;+N4!$TDjJ;NsC_{i?^D%IiQ0b&&i#SPo6>E*~7N#!wb&T%jdpa^z4vh zJhphJ;8nr10y@-$Sm3RF+vzuMjSabY*xK_qrH?KI_Rw`}(7pOofW&3Ak6(1-t<6*V zXj*-J=p9bpj|a_rV|gNT%e-4N&nI@B4#W+~qa3N*uBnYH0XePx-SjU8NS^5)<8J<- z9E$6gCx`Zt#XokKuN-}LHpi8BDsyZXo5oD-?gYNa-wtjG{%8z0-=9HjrO(fvPqMpD zOxQtg?`LtxPY=K4bThzPIo>xm0(;9prH_o|n>;>DfxUFx7xcVY+YH##JlY%cSM{K_ z)rq>|8=t2Doe9`-HaHg?pCO)XvUdv5n}W??3fOTmAd3t>pvwWf{&ptl-wOEP8E`Dp z-C<;x|5Ez*2S~mU8FvPB$j3W_V*x$vyE61^x4l3fn`%R!Lwspotlt(mtNbIo`_9i} ze}kP2_p1182kuffJwMo)`()h_*oXdN_L(D3UMeHqRV>_{=GB7O;N`0ri5IZ-Z2|lE zd+*%0CLY$|Vu0Ay{o2+|+p+Ggv#og$Yc}$SY<}YDJ;g?2e4}4%W{-HVQ|$H0X3uK_ zWX<=^hz$Fl9EiEK>*jvfK0M5Y`X9I703JXs8u|4*v}q$8f}z|u3N*W zhV2{AzIidib8F!Kkz2k^0Xh@dgL*c`mQQ%JJ!gD=Uhu~fG*8@=@S@{;ivc_3TTPQC9_v1H!^5vBKxF>$ z$ez;5gBF?p;$i+`#$t6QVAt8;Two8-@66CG*S7~^_U-`P7N}u7;B4A=D&UiS{HQO@ z=Myux9nk&CASSH{pFPuRw0DO%KL{V0h+WOG{uCg04q0ORCF$^Y8Qa=rzr8(k=hK(B zFG`KD)3a{8ORT9UaX9D>u?JO#{#IbG_^E64+gQFieKzsk^H86!;wnzN!4x3=+3Sq3 zgRk`U-qTuVpFSQrA!{>`J9CZQG9PsJer2=q7;C!vtgfB>LGs4FZw+c!eXK3U`00Nj z5L33IjxVOa5r~01OrLD}wD$*yobg%noQ(O$UVE48@@vl8=G;F>?(y*O=ea@8!YH@v zH)ow6^zuu~U*~}@=0-c0b}h$ug`XdH2J$c0zb{~e8hS^N5?%d#gC4Tg$av5FWd2T+ zJd(W`*vl98kiE>|PUet!kV7Zg@(6rc>TPX~dcSRrUbZzJQ~Kyl!DcW8Y-^m@cwKNM zP{;N`>xLc1*Uoc%Q6v0B*2HKEkQm_E3Yr70+;wb^+M@4ru;04@KBNY2S@j;OOZ((m z{G1Wv3jw`kFW37#u=b>2BY0l$r3p6K=BEI89vlnEXCu%v1!!7*eW*Q?vGZ<^Sim}d z@}>ZF4;%hOY%sRJwVm$!y*D*iJGL^eU!FV0^}pjObBHYdp%?Ep4{OP+KFe$+doM=s zzw*VM#iu3M`(?3rznG12pTdjiI=K$dhDgGR!|D&>>T(KdS{5J;fK5|b6eTU=& zn_n2%^ASP!sI9LEv-VG>-EZ$RvTm<4Gw%J$dGA*pu-88D{n@zpPtAM3`hdOe1AEoQ zxc6)3yYTO%JwjB@l(Q-G$`*Y#)9k~@HX>}6Z?!!Gi~oV>nUsK3UUjpu{o!5CZXr-Ih3xTq1Ie`(#n zYNO-Yy`4FCx45xGjq-~uJX3(q1ng@J$YcXO`1Q%~oKz3S{L{zFAH2?)F`s%C#em&Y zKu2@Kr;7n%|8+C)FW2n1-ZkSsOWIb}lr_|`GkR-a?-Zcsr+a(n^-Rh`>zqI1v$we* zw{aB<^TySCCjFBE5}WH+y}h{6PrmmA-z)c?F>lWAm0X*4I~eDjg{@%RcRFMCJ}>yX zD7+;tc~gMy37Xeq=>vQ4=(D}?P!oJ$oAb+ea{u%Z<&v`-OaW>P=^20blO8q52Kvtg z8v&xP_A=n8{1pE+lHJ}FRAftSn>EkmlE~byB z)z^pa)GHa&QLN)5>xqHd`~*rv?B>(W!Lb?Nmv|pfpAWs4*ZI!g%K;gDUDmX<(I>S{ z*Ji*Lc@`h_#2n}C8`8NYExsv0?v~wvZ|tB?ocVDsz-w*_(3ybzbvY%A&f2!lubvM) z)g>?Q2#y8KFFWP!k>)&GuKv78UfH7-`1hRPRAAniPW5kmF+kJm>qEIeY7HG#p7*fP zU%Ko2XrK9m?DCxESK}p4R|0kv>wJgPHi*@F1xOdxji zgFi?0>tuNAmwT<}fN$201?Jx#(B&@K&tG}l4A%Ke#yUUT_w=)yzw%DbPC$-3Mo!r= zp6&haH2d9a&HMk#XP@s#z%#YVoptq#hfF%YE$doqmxHZ99@wNWcYW3xn?L9tVsmY+ z9b%_;jJ4vi9kdSRYzh#6#e{uyO#$k>{)>GHjV=CVtmp$e;bK7M|K{#a;5<9aI?*Rx z9jF)-g-)jpZ$H$`Bzm} zN>xR~Ta;Ns=L9OlfF9uye&eZ-)58p$(cYhyxR@@cvjQPI# zwVbs-3wA~-eyy!^ibp-8((Qd|b7Tz<8EQrz`B(A7dpJ-hem1DKmIHOBw%WLnb4!5i zmxtCKbL^z63)=W)I2lVaOU9UAExOYYJIe>{+V?Q;-Ph()#*C zyKJMoo)c``5QwF_)q9#)wR08UF7t>D*3}Y!+n8?7n0)%4AMjb+k=ni@u*ZF`U-g)7 zZv!4SkdN3ko~u~-{^WXK=X&eyT3C<9>OzAMKh6xU3FJsz*rK++Y#1-4y*5yn?y5b3 zn2zIY?@EAgE0|%uAV=IwAN%C!)&N}?)Epmn4`Xu+*)Mh#2Qe-E-j&H@yY$BfnpiZhUFI|AT{_EQJHteID+|sit{hEJn`t|gxc2}(3-`fJU zc7AZrq0ct&cI2v4c8VMO_XXse=hwo}pCy;w;<_PdeKF5I_KS_Uh*|3kUF6Db+03@$ zvEP_oz@FU!+3frA)Qvch{k)*=H*@&QzlW!f@R@J*(a%1u7>LoO0U3yI^40pLKKVip z9c*N4E0->HkFUP~2VU~6mp3o@1uab!Pg9`%s@Q^7! zVu;QQ#6_##w0QOnee#zBZONS4W9`C$FHQe*X1N(Z8=jrHy0_T9KhQoPSPZK6YP^~` zXQbqaKR)(}71EmT0#v?q{pgra#(diwh_%>?RppD1#`G1)GVk7Ur|b^IQmkH^oWCO= zlTYkozj(_<$z>a`nO-fQ*WMrR-hcmoOU6KM^|kgDpPUu&RbM-n&z@}o+pN)hec;^k zn@wZazpfG$Anu+P2H1!Aa0UH|o% z{_;;eft}6)+sI}QIs9PH?!cP3{z~F)kC=?(u#`EuvbUaP`tsvvIPy<+$>lG8bNYJ& zRIPZO89X?6!~B|@_U~-)v3%K({^^03RGrrU_v`+dn+5sepLPE6tL&9Kwiz!6J_D*R zdJ$dt`BOERZoj8}*ATDbY2}EAdz;-p+tA0J%Kvrg)7g&8UwhElU-H%iJ8E6bjL8`L z$QE(`{=|JxS~2Yc#4a?}?frc{&{gZTzm3}knVbvg{ec;J%YS_6F+tUAd$*`twb$0D z_ZjCzPSvMe$R)ePnJoSG?8?XfKrL3x$+$jXgScE4h?o8?0g_w%2Lt)DUO8^($*3Bj z`#{jjQ9Dl!?3J%WLGknP=77AqN61(W__uFBmllan7w}n&y8i3zyYH&3Zwcro+gYK{ z_$P7~=!+X$tkb&~h|yBO7xvI?UVm?Z#FQ=a{e$ysHQ1hSzE{5Kql-^udcHW{?pAuW zvmjp9#9F=8-zi`-doK*+OAWMV4L_bS--&Ee<7}FOT5ad~{>Jz|b;jryFZwH<<8vy0 z_{iKBoQO9peLWYy`Xu{F0a znFr^FP5SI=&y9B$^Wrx?FKjW-NBzA4k{5APFF!Q@f9_fN!uTg%Q{ej#$M;!hMcnFq zyKlwtMCWB{y=uR5NiL|%sz=Y3sajOywg2?=K`r-&+260dmjm4fsctZpLPivJ=eoy64jZ_Z#*~Yl?-?pcRrwfqS z)LLgE#K#|tk6qd}mSm4>;Kv)jR<{_J+_pU#-9ORDtUQi&J3r)x^{AcVa5zvmm1ngM z_P6ufGv?bh!I8kZ5jS~fyK=hyJFzi8)!K&O+Q8h- zfPS%Zp7>Coz0Oac-9NdG-9I&9%PhNpdV+V#Zt+6b1$8!7(}!_Av%3pW-G}yffi?S$ z`MW(3gIWIKqgWN2r>`?EFj*jDeJYHwRm&!DPhamK5bTb>iyvfg_-8w+A7u0NaD?Mds5bO9>e zt({%JvKAAuWE)xgf-XSfWv#Wb;@iq<-#OU9Kj%qp#GKphzbbR$fbiP06qwr|tOk1n z#0IwU?dKwFst(5X)t+qWpT)1z3GuDHL)h_B3!(9v`=!1&Q!#E^_ewj~SKAu{XWsc1 zJN~#+wdJ2NeR3O@`n8MFE(T`??n7(m2A{a({EzsEosO!J3#lg8C&t1c3 z_aGa$1m^{8uG-i7zKA+o2-vP>mV?qa*45@KZhTv(Clt^vTEnsN7}j5vL0RaYJ;GQ#HFa{VCWtp3hXj z-x?d`k}OoVR<0{&e4gt$rg)twe~{nz8~qrJl%|Kx;!zmUD`sCNUo zA*cM?kiHz!+vZ8kFPeb*s`>j4eeo_|#i|PsJB$%u$rs0}(en5D%)NV9i@E(C`q|V4 zh%D!+?f`d#7`9{Un}a%2@_6=WTz<0)*dv$Xa98GaHS#JS)$*b8^0qj-US8w`#G%fd zyNAu~{X$;(BoDx+%ZI+Wt4*;4K9-!t^yTE>(AIma`wYl(_o-<$ntt>*9OHW26cYwnJR{CkbgGVw=EzGt#?+|i^E&8w}t$*WAQZ>hsviK z?gCUc>$9uw2=5WdoLI<9)rJ~-dBCpq;y0glK36Qd^bwtGXyrX`H2#K+#oOMgc-I{x z?(C8Oskqa#GVrhkiFN6g&(b4D>YLA%*Sks&Kg99=LB*}+!~Q`*)F3D7%v#Qmq2lMo>Uww@4 zdT0FYQLra1U%CL@(OTb~y)DiejoD$HFV1eo#ybG}#8#}91Ga7p%p-n?seRh^9&neD zDeh`xO2+2QSFKF>m*w6bak#}GWDhcybG4|wPoS1}1#`jAy zIeM0-c-}PP!Ov&*)Vtw5(;tJ+<2hqwf7vD1zm!~yP5Z9H{uABjRda1iZ#%C3iSodX zUydD9HJ7E^`Rt60LHBsh81Y$sw0^&1hCcO4*7Jj_0_Sf_V6PmZn*)9K&0-+8tAQHm z0;K-bmRNSd-G(;JQJ#`nv8D^$i}pj+jQRJcrpRO81ws2B!yd5aJc#8x<0G5c=-EmJ zTbBc8sNGL4@EL!}BIj2kr}i&pOg3RQ>AX;akZP1J7%5*c!CwMZ7C^E9vt?ek)EJ(+9S+Xye7+UrfB{ zl&7h)OosOxcM(4JsHaPU`d$%R><6(vGw1?Drui#^$~QZ&4cJVkIEEZn*!_3 zusp5?^4bNc_{p9d#_f8SIn?I(x{NDE>;U$W)dh$?GOgLWA!zrUpD}*1IS@E|`vbbk z(u(s!fJc0+m%Vtp0Flr3RzAJbj|%uLhIP)Z zRgIWqW4nK2##;mXw+GHdtyfN8(d5*jdj-eRWad%nAY>MOCPzLw*}&PSK7t*6X`qAdfnZv zUHm`QxOLfs#7nH|tf?7j?|yyq*{`iS!Y7{2mvg>5s2aW3@H}13oI9lAS$gmlZ=FH; zSPImu*du$}b#mw}yVE^-7ue@cLe8AHXzO!^T0Rlf0v>T@pL6Nig!sx&HeMN!k7s`% zE)_RpF=30Cv2`vuH1yke>jOWbV!11Q^8DT~|1SyH#DDRxINFQqzQMB?Tpd&#+2{;c z9NArR%C?e+7sR0W^_K!Nr{Z4m9oNj%m@M;cELKh+SN!dRvx6;xTzHXQd_kLk1?C<-xZ*# z_dw^zS;1?+`^wn)lq+|ebES`0pKSLl-<(J9spz`3rkCUQcGy<7x4*wdS2yrFgU(0A zL2W?YtL|;~N8D+@-Q20|U08d`L2UI|077d-9~<JM@ zv!(ZwJr(OS)2AQ(W22w^r9cdPFUGj~-bvLipU}R*dOeR`l|HC1v1;*%VO()+bCjh% zk8HXo*c><~2Ltc22LjKe`9R#w8RKWeMZsdw1>{~Ds9|(%PKY_jL3fGwWi{Gp58 zbk)0S-2qi&W7*_&0je`pEgcm%cC$~u=uubnkWaR;v&iSx_Od(EJ%8C={#LwvzPFdG zS`#07>C?wsag;N>HO~%x^LqpPT0839tYWz_>r=6GcCFDVhV-c!x{S+Tb5nX|#Z%nJ zYwoYzfi-wSYFO=fKR6?xZ!svFH>5vhGhW2THr|y-^YG3|k9_U$by^voNC#8+Ik&aUTJ<<9)|fqQ`-@jOx9#c(B%pSb|Z`8eLr z#fjpr7Vb(LBJSwjq|ayZkmIUB@8jjOd(8Pq_$~@A2*iPZ^5#yh=Y7p(s@HR0oshkC z$5fx}#X#-V`DRDe9^ciU@$P^w@$~n2okjBOALj)RUrL{x(zP*I3D~HQh--X?SqCs-Kh4yui3khd3sj@cG^e2Ib*&p1g(5NwKo3g3>$x=(Zj!1 zM!WyRqy6GP7a;Y=4kW)-n`)dLYTTT2cXoiEY<1zx@xwjP1!#L9x0{37r*`cllivD% zPM1FF`me|Kl1(Oi@K&7YUkcQVIdOLm&9So!P}hGwCT}I<^>m(|^&P>^U_)TcUN-3S zgU|5#$m7i;1kQ~JI9H(&DXFL_BqEkDd+;^If|zXP}hGw_Dtn} z`Rd)3fB4%w9FG{W6S-HN_1_xu(|)gL?8{2{sxB%9{uTtCmjrZ(WPE|Mkwtq|G58*v@x$RUL}uJ5SPo`xk@N zpkm0ER#tn@S1iQ_sht<~y|s9#Co!$M`iAs340G~sjUM^OQ*C`Fw2qHm`cv3B%=42y zm4l7xcLAz=b^Ykre7)<)U+ph@iuY9avhhTF*?C9x)U%>$b4z4-S7N6)Ed_E`@l~Jn ziEXuA`l#!_9&0^c)X}xU_CQ?Zo-F&@Gl~xnJJ5B3Gy2=vBnRU&ir1dDW;5(8KaFLRRW*U9-l65X^;N#e zYiplve7GZg+1C5h=5--+vp{#dmSMlY?t=M@#X$YzJu}!9Aiv{Ov9i8380S_T_);~{ z?tkk^>=*Ag4jJCgKXxrmz_}jJmn~h^P+JFbaAn}RjMRlX^4|IGz#Z+rm?dMqJZIaa z-R`6@)beR>r~x*Ur_QGQ5j%Ud>&cbJs%PH=u&2g%#P2W4{ubwq z#e8I6hC} zj=#>+$?%`d`8hu_L5!+D)t2rqe5gG??5~)&@jjI^LnfbmuCmYFqmIdL@3gBkE{LsK z6sx7+A;I3j`j-dD-EDnWAcjAiyQj6?x;6g!yQ<^0cJCFVbv48WHfq%vTb()M_C0W8 z#-GaX3X|{i8gk#X@_%`>-rDw}VT}){;v#14GmC!v#=0+DNA@TG<(S_O&feddU(3b# zeI!f0kB`s^l?~PM-)Agj?#jUDA0$@BY+D&xb9;i{jlM1|>iVz8>Psx~IlEf-quLu+po z)r5DljR9ic%lqE3Sem;zD8KFDH`^=D)jq!G`>fu7eD0Q|6JRdu{8Ts28e6&mb^X`1 z7_-wkEdJ78Jk`oa%Uk*JyuT)(i;jB*3G30;eZkf)K-UK1NvHVnhoAKhMuwQ+A!l6)xdqocCqgQ)b(GFt09+%x#7!VVBha&pZWGoTHhXwYtWd!Iv-VwV)&GGYB4H$;ul?YugLF)U?nJh z>GpXlKK}5NO^A#-lkOrmiDl)id{h@p!+aZSdg$c)AH=Y!n6>Awd{#S)!PqXokNMfi z9(&lJ#>X};XHE`h*;xLPG1ggYZ7kH(I2K*z5L;%&;16fSz`h#;&+K|nWUG55TY6Fl zvutw?+ckU3m--%On^*Q#Uh93?T-^_3&AM0Goc_@|{tAvoUCOe;~T?EC&mLdPJ>`4H=tP-+wZLztz?9|F4FBYxdXq zO!v6YY3=_T&wbqHv3y{A7a%_H72)62_f9*l{T`}#l$>_G<^QAHG40sjyKl$0j>b0( zOg{VRl)wKxlKJtxcd75P>ERjMH1M=>{`JJA9na+#GFQUe#^O_-JYLsdW=ytwrELG7!<_r1 z0!@32HA4<%h^X)<;mR3GKWW9l5g%YnZwiO?xX*3e2x7<#%%cWkqu?z4-EXR zP3QgE@o{-z#`w`+ed74MymvHy>o6{P_Bs-~npcdm!e@3j;S3I=Zdjsi}u2y-7&QEn!n%Bvd#EO z0sGGgd`|jUY~26u+iv@B!4uwd+ij1|FDkgh?H8+${p~2`qwyOu=0ov+TgLZj#(OiS z_ws;VGU2A^so4D4$Bx(Wdl{b<9_O|8YQHqFhkf4{p2~g2P7T%iw~l1qG#Wp2G~PTK zf8u|y+5Onar28ud*>e7_td;J{SMh!2z$d-iY_c zzdk10XUEd{Wy8F@(^s{-I`HuI!QpB3&Ns4rPpV}7@kiF~;14C4E&scR`M=D(JNmEE z(zg`wx4r+r_ru3Of9{{L_o*9Gco(PL7l;YFkob$8x+JU4=ArZ}7XS2D$9!iOKNp6! z_{jS}_*%Q)((J2v&~>Dle_F=n{}YG#s{Q3bNA0C!VWeZ@u!jsjyfZ(fuNwH8j7#=+ zHS;$%^UoRPOXrTP@vrvM`FY`K{rc#KjvxPO#`ZjW*!#6#xfk`Ns0|`5Cvd{EhswV>|w-(Rg3RbblnewSPUd zA067i8QT9nv>!{`%6nCQz}=3YKN>%DG`=unK9s%p9<85|vHbAqtU%qg&osKMThmru zRbK0SdHz^;=V(1+FAeY`>*C0k%Z5Ig`dVxHRa^RWvrFIen@;_^2kvV9gr`5_`tE7E z%^9mTV{#4-eew?seR}r~efr%ct(Ev#UX!uC^#9H8t?AdtTPWLKnK``9%i-{j>-u+wI{A16v~@yG z`AdfJ4+JG^e`J+?-#n}rpIqVpuA%+jq5YwueRJBf|EJ!+CP)13sknH5`jy|ky}f5Q zcleKGoegbGKY3Ks&j}B?uO0C{Gk?fI%qniy@v*h!vEgsSSK|y%>)w0(J@7@5-_}p% zPAvKcZt$WJ+6+`=&q4n-#{z*f-GPE}g?Q@3qc|-f%L;IGY{mG$y z$I$+dq5bu={Nt;dd1(Cm(_qtY9D7!N;CGI{f8LofTiy`JqjU78%(XRay<%I>jUOKP zoyED4%vb;RvHfH^KeuE~981U73}Z1Zo=0X*?RaLiI@w}e@fT-%=>FZ`TC@KZ!yNnH zkh$^M`1t$Q{{I`L|7GDhtJ(A9jOnTMJ;S)}7d~ui=ERvU^E(sYiVr(|ZY0Or`+oCS zELtC`w(72{xSpFmB}04RFn-a{zJ6%mnwAbR{o3fq`@}$d`OsF}UN?-}d$D4SAJnpE zs<kQA>F*58 zqt(DWqJI-hP8Xn)o!b-Mzt0)y(z4Y#x*-sEc9yMVmu_~7$G(7%;^mCjSRU|@#b0Be z@10A&xWBImVsifuAy)jT`E-xw=-TwfiXCH~>oP~K+>-0=B$vLDWuNa+n_mge3(Of` z9Ms=DVY@YZ$F|iTJnq#q1NRepU4Hf;*6tGb)z*NWWeXi|r!Z7@=&M079s75peSAJA zC|kPpQOT}6kb|cSkQl0&9fA6p3swTQvb)Y#m%cjCqFTe>1=cFI=HyuZO5c(6k=!Ed zoleL(+1>Zn^wJG%C!-5c$r{gB9@sh`bU|w?S?+{czF5C!&;?SWt^NFD>&<~UbpdkM z><_9o*r^8g1zmu)2jo<2H>3~v*g_uJhl5K4y1_m%L}J?3)klZAawoH4YruZ7VFR+C z9#lTJExmZO$Qu4xJZeWR(`gSqD*>HX4E?IJl3PCGhsqg$#K`@i7Mz3j`(^HS^W=+D z7a(%y0I8b>MChM|Z$Og1VF3Gj%4tuPg;(TX&E>Z1Zj)wqxF!@3Mxj4b(2* z_5|#x8n`KaK6>XdU$%*znxd!mPaTLQYM(=VM%M*3UoHI=ms$GV2^BN`(O>6iHGQ^p z0jm7hSuof65~^J5)9F4$?5gY?jL$J;~ChGAYV{Jnkl z@}X>PTXOBuqR01N&p7(Kv~2cF0JJ~2rSGksQFTDRII*j0-gqe}T@`nFX2o5O9vpmP zeoapM_Z-xge78FIxivtghc9utCvisBT0hzBd^$(;2<$z9d>HXy3b32c3{5wmT>g#8hPUzja+ipzj%v9{nvrWwK@#UMt zx0<%%gty*vYOY;x`_6mmyCHJ;;MrhK4j!F3Ji7zBddkn^wZ&VXBg!Uq<##s8skO7x zCsY1@G;6Ki*N?`p%2?d~DREO5?wQu67i68T(r>-^#GM{Cd~Wz!U&W~mt-l_!+{@UWR{qfbpvLONSUxTawgr4g zVp?bYg7ocg?ai?NelJ@N1Z0pU-fUY9_6Br_#l`^9ZLVaIYs~k59s2y{GkIEL^0oA> z#o`P4?@fMN#^5>l)kDALJ{_$*vE$Z&-OmWji9y*~_OYpj+_vLSM_)a#M~z(;cn1+j z@s-sn3YyJtXF7a+B6UhOOg8w2_Go`BCg&BFrr7&{N=2lUJZ z&W~7cvbymFDQF7b8UFK2Oe?4YH*>X|lmjn6a zvzTlT__tx`TiX%r4Acxdvexus{1FlWEL=GC%1>hBN4@8%#Wyp8UqpyFmt-LXU4 z1*q%4uGux0zW1JgiGgZhIUxIjz#6ib%vtAsA#104#_c(keTTyDtc$}+Q0JRnb>`Xq zz@Tiev3!ex`r@N!lly|N8v{9N^I@OZ?GMxl|2^}n9@O^MpbM;5e$qV}tFo!)ibt&f zHTs4Iu`;u_*D9weerHTFV-G*EC=Mt1tND`XKZ~}@EgIO z1%mP91mK5)cLW~^_RO7j+6#m44&EAkBzSC$d13I%;Pt`J2frPBZWQhe_6Cm$ZVtXZ zcysW+1X8T`2YgrzE(jv7C-YD?ZivUP&G9z^6VS$br!GB_}u{+o*QQd zYC@-Kt$5UsJRtqJdfK6Y%+td!w)O79R`VMs=H-g)s^7Nn{<}2T7(WQ9k6k~rb_W!n`=I(aq<^w8 zu&)bHJ&*Orv5BdDEuEKkbD)mY$WsF`RY%r5XT%g;7l`Nl;Ai{!OMXrd)Rer}=Rk6; zA#3H67QZ~H8+0I0cMk{_194-6yL%}RGj_3$tOo_=E)3X?tlI}-frm_Tob6q~8NuJ? zvkf`s&kxAQN3OjkM@xr!ahMC(Oa?Mv`?U28dSskqxAxx(QPX**_Z#0dtdv`#J2e95L>)+18>Dw?5$Po%kFwt zk-PZ-AIROt;BfQ#)!c^QnjxR;R@>&$zQz{*moCp?emLi6W`jDn_xj-7fxA!rTpYB| zhpRK@i)Vtf@L3ak>9Jpn=dAGXi7%}Va?TBqK0gix>aF4@w(MLD#O-k49<24b^!dcr zO9Sz-&L3w_%Z7WbW5eF8)58Y->Q^qz-9JF>oHK{oIXOb+>~luspN(p4Ay^6cAr4)D z>U?$mXzkvz&L`~+LF-$^l7ITG4tX&aOFHLqn{!BT+l zg#mxu6X-}l?tO;V+Locu_bY=o*Qiyok-3((VpE^t2a@lig}lpPx~ z&kij+JvL@~a0x{+b`!@!BsTzOa zF#g=Mcq$L#upHo*ll5egUol!uUp!k`86JIiO&WW$E>3%bduCEB)s5WCVQZ^#J*UgQ z(;MD8mu17=tdYGvU_X+N@|6wO1bntmw|lS7g}vF@^1>% z+kC)2zI|?#b!pW{YmYOI#G&jeIR`Vx2DL*IUDo)A=qh`vZDm_;eWZJqkM&MA<)d>m z%SZOHYc-JnE+9i&zG@L)#iRTa=XxJoOuq||czxcCc!^WHzx`Q>d2xS8Ko9?`7Ag+s zWNszkZ^fe3trn`rs_im|_}B&ft9Vx(tQVuYbDcH&kyw@dwqmL>3iJJw)1nDa}S%Vx?*$XvP&PycNbKhu^Al*tnu$;Z6Sj#_~n;>m&IW=ECyo4 z?k=EbY~R?n@m*ve8rv)ebd)~2>BGn8x)Z8?FV7tP_%8_%{u=}HF9_tDKkl+ELDiS@ zho|bkWbk<@kn75o?@f?#Yak!|LH1f3@1+A@)uC9{9y#m+zP0PKY{Xx2O1Ia!Y1o^T z^s?-g12XFjmT!En_|;u3e&Sr`uI?&wwg>Wn>OO93NbcoAE4Jj*YfkJc_jHO+eJ-S< z*2H4g+TN_$%MSK<*R7xP(OELcYh|=+t&H+zfB4t4uly?cUHHwhLoU%Bk-^SZM%^bT zvgKg**(>&Clen>=#`TVRY3BH8z14-ca<4|k(cRa^>SW^B=5ky1%L{7dmrZ!rp3xin zx;Q^$wWdC-vBURH)yz^L4i(oU>7$Lop}@Jp_td~%{sCF+<~LqvRsGA8J=RtNd-U-; zYiKoS_u*$BJL);8uK4MWR)6jP2e#tKt}Z}imY!Otdokz&>T z**~Xsuf9LfKR3#>E&gsaZrAQeKPviIwzkaWjrw~t|KmZm`h2T7^R=cGs~=60i?a`jV$+X32Y4 z!?$@IKJPyz@0@k`b~Joj*5PwEm%MY=;bVL8dEc4khx#qP`^?~TX51|s0=0iZ;0&z< zeJ$N;{*KtrC*)im z2#y$p=7Prs?hj|LWQ)h1V9Uh4++`l&ai5T(FE3qyjKy;`Lgl;*_^xf^SvuuMd>ZL_}Yo?fV8l*e4Eh+6AcVzpnXt#n7+!5;o5T?5sGI{Tng| z?vy_n`sB-ZwbndS#91urd8J?Z=+Z}B|8!VK-{^zOd0-_3?S(sWU{Tdb&?G zv6)?-q2|THT={iw15uTj^eW>c^tI`KPRR2`k#q4|Fu-Cg1-++B=Qd{Qv zVV=EvgAKv&5$Z6L*t(u6w=iZ0|W=m||@2s|zwm zFPf@3KcjQUE(KkHZ$X}$mYsOjYwh=3I4^NNFReR3>@w_sek&&xAI}%M+$-vS zb?DwdYVhb4orN_#n4vA)v#4`J#J#7j~ILUH^5h z2IRBiV|p!@pViADtH8$Uk6Zi2R1TgUh>dvO7$ElW-SbZUT4(zu0TTa;AKANt(}PD% zoC$XcS$NQwOz>2k*(^Nrr|-;pSEtXIPHPoMb}a;2b{r160CoM>wOH}>+F*M?SM6`( ze^chgU`N0Pd}`|abf#)*)4(Sm?2=#h`V3I^Rt?m8#jNy)y|H_ZBLT{AcUJ3|sMe@1vhz>)B}?pBUU3JKbM9f}O$X0oot9hrS>XBYm-Dzt3As z!PS90(0?cp6Z<@m_XddXNX$E((Dr~Fq<(LI-+fkJL*l2FPK2=Za>!LbE5UlUuz7QU zTK%=>qRjJ|e&@V=GFRh@_lC?Z2mFyYa@lcuP%*`WZVAlOV@_`KXY7vty$*Bv^Bl+h z&2aT*kJ#()8pb~sJ~lY#;6#TTYKoq zpR4Q7PnSL-ldP$qWwWIVQ0Z)ct|%w$I}|)F5R0b<&ZT>)3)E@lxNH&|v_GJu^66Q` zcCit6BtQ7QXOT-DU3lnYdutPa@OA;)oK5@1Z*^$Z`eM)p$l0j7q%#pBrwi!Q8dq%7 z?QK4g_Hf{Cv)1}mI?6vb(etE$%;K+@%w-NeCg2-;E63^f_TG^8S;5nTX9O<@-;@Z)F`@JcBI?O*eV0ZouN&k0p?Xkul zemyAgZ?$)&HUEnAE9PV_1>~698JJrP*r9J9dS0`Se*46gOlJe{HG%kv!Qr5uhkQFX zm=DT-_b(gW1NN3p>Vj;~53#8;B5w#ko-seU;;rS6TsT)q?7M)iwO+BkHgk9v02+v@EyE*^FwF(^Cgxhkgjv=}nSSGGJTkVm<( zPWGjNSi|-JFRH%xuC1|8tlBeyujK7cU%c4-zI;w$BO4Y1^OZ04z^974THPA3gPrri z*v>92 z4z>m2WqsQT)-POVy=)LSHi%i+`@T5P`IZ<&*J7YH_>3wawI&Aa6l?M-=2fd*=8#xy zkCHAeS=$3L5S@T$$6)vM>AxpnTk)~OxpSBLnWtFWS9MsmFXsCL;{$=*9}J!uu(u$G zt-To@&6T{*T2oKfT7SEY5!qc(YvOB+#Lmy^oK^j)XSx{dY~s{qjGi8JLB&oSkoxg= zk1kL9?}0CkUN~9ZC(D1bd?(Uda#mvF_CP)kHT@mw*LhS|ejc6h_jRTA76N<6wV=k- z&tg#ZC8uvse(&GRA5Pz$rylFBNVl&|b6wzmIV(`hU4YmcQAgjqFGznbIFY@Z!-LfO z*q+tQvDKLJo7lAxhU(06l>+VXo-(RtGm+wl!$yNJ1k7AD6*q)Pd z8>2hgKRa?N|DH*RPi$fueI@Bd+epR z-CMG)s|)(X*t2Oqt$6aY;zjPs)&-w_e}KNbNxeUIn5(sF-!U=&Tf^L;w5|Q)JXf68 z%QIgq#_}o_2ZM2*#q(5hEOz8pj_Ii!|HNI8TNTLWhRuQ_t*kazQRxI1R)P@mfa zwK6_`WYBeI&MujCZu2)-`;Y8=Zp8I^C(#L-~OJDvs07pNs zm%j3oJ~`p@k z{XSaoLT&x3J2cMW9ldMln}S+#9(D)pX>C}{7@2F&keavW{J^=oN5IaiLA<^PgUowB zAD^%J%z5ULjTbzdoh>!%Y&m0WE`4k@R@*B99&>fp*v}7g(a+_Fv-|S5+8&ngJst|4 z6D;J6lk2R&wtznLO>0fBujG@7ZVs}w|9e5=vM1P`OTsg~{r+c{F=AWot0&^TU`dHfizHK67}l2$1#Sbr(-3M~!cI8``LA57lk%HCj|)B=h(pcWYyN{lySHkGF8%WPWb=Dh z)<>JCx*N*3aUM6v);n7ZW0~I_nW$oL|MX7=Vs$cnC&NQOpRWu)H)wNJv5?ow^Rv@8 z9_RV#C$aY_;kh`de~09*anFta9g;dLKF_BqzOnu|F>-r+ayp&UP;u_VTUvx}Q#FFFE$gA+&XGjLfmmGkJSp zeotVpd^oQ+1>(MvgW&n{m1)^!ZR+`6=le7LbEMk2{3P&<@Vqp5L-2FKZv`i_Z#|yB zj*KlXmXI8MGVnYWXLpkR{y;3vZ3>V%V>z?kUY`q*eAKzJwiu`r^Ic$1)r0l+`Skvb zk@es1du#h{8T$4j>+cE5R?mpCwd~4N&-Y8iT5Fg3Vwd+Sc9Zur0n-1;zBgOH3{xkdD zZ2O;<^^=t^cVs&INdNJDZ|$C(vi~u|`oXkQ>z8G|^lu*eVo`Oej^tlm?+@yZ@t$j} zCh%Vx;N2Rub$Y*y5nFfnz1g-d59_mR^?R0grLFX}wz40wwLNcj*Un{rPcU`YnsZj1 zllfqKQ1X2KLE3uv$LllAee?28rucRNn&P|P3_ddMpEY_>x<@~s_}#;)`42SnbUz@Q zZcHn;^6uxB&dO3?{i0$0lJuw6ADDG~4@&F)QWLuZKE5NLsnv?JU2~7hTv(6V`GpzV z|KLoPz2bpi9)3LEXlwbuWf-d`>*#Iyf0Sx#&itn`M+UllBxCDn{PBM{UdQW3<3|qT zl27Je=Kss8EuY1#-odqe&|24ui?;amVbjoV9@;HK`}sqw?(r=StutnPLBO8U^U>Jz z;{5+;pO=47`O4sp!Ob7P?Y1`u_x=0ZZhLa@YeB{2++J&HOFP+{W z%KqXzD|7hEzw*cXuY18da@P2uj`l>cbM|OXhUDFOac<-e9a(GocNcYjarU(9t?hp^ z@mYK|d%8d!s#|{_foyRzw5l9l8MF-y67twhwJxqQ6{wwS12JZ^I~KpVR}JTX&)WZ6 zQSnia{HYilZw$m>A+Y~&KyTR~4svNs_TB)oAOBpyW@qfGfF0&ahCTAlpVD9PF4=g; za@*$)f5nUqYJ|R47CHQ-_f<`ule;yrhkoahJyoapt&`j87o$VN{M1_6GPSmnead;Pe15-?~6-wTL|R)&)p>$XE{CLrZ}ejdh6^`E*vDXuAM){nxei>Q^gv^dNf* ze7`8DobF10KKKvG2R%@Ezc78VL1Laz_UHPXwCX~xoh>|5ExGDo?CY49Jqv-Dk!4TW z!oCf`E&0Aaf7Wt-@1B1lV{k6DcNC{*FaM4Nh@a;8rw-Vol_$?XHE3O4YrgJ=s+%rr zNFMlfejo?xgDx?k=R|EA8*!}fo40mVj6LVXYHJ`?^mGAYhkUR@owMU$FiXFB<^NRf zTDx2ODtBd@9I}B7w$ZsYm}Og*dj6`_wxwq|P$T5-2zCx*KGQ>gdne#6JZjGp=e6{uzulsc&U|;2-;=Dg|_}nq&N7>9Sc2qr=+%9v-9kdjXIo8WA`DEj)efD$# z+8)^B8Kk}n>^eA%txwe*-iw0ez<&1_S}*VX5|8qaezk(^BkzJ>F4z(548#HCPF@fn z@LwOWqs?o{v`3u9oLn(G96Tc^9<|4ws*~%|KR4iyJJ(u0Gv&YTVRtoI^$Zn*`G8-o z-5K`xdYwD`?6^5#U&*VS;$!m-!KJ~*0cG!4cG<=rITMr8!Ov5b@7X6_&f?D|3GyKK zY`!{R2fGnnYOwg7UG^>pU4W+SwqI?@A=%|~*{@x@GuGZ?J=eb?_<`W9f&G<>Gt%e# z)9<+vDF{H8+DmOUH^5Bk8Opq4!+Ytf61!*Uo6GzaKH!kF4xxE zzje4 z&WL!F?8=vREMLy#p8w#ElRx%(ZdZK7hM$!;eP?3qmz+Fo$VvP64ZF;vdav!$7dtw~ zHqo&o*cq@7*u>BF8Gl8_-x~Ot!Fz)ZF;=Y9&_e=LzO?_=N1WA)c$80D(|7h_dcU7- zD*?aR*ae7xmxifJ%T6sKYaENIy$_$*TQRBFv)SH?3!m7$Kj;FqJrEDil`b;bW!wem zy0xbFf0n;=0AI`Z(rLSSw(#G2@l`vYxr+iZ)YqyB{-{%Pugkl8oi%dAnVo!5tLmD4 zCBwQLoFCwy3*^c>f3Lh`dA3Wsci1jN81B($n#7mkIveEs_jMDyAZI0ezved zzx?FiQc!-diEVh*$qm8bfNs3@TVDvoZ^{Sq(Z0Yw`cJiG`|_|?t+g?!_|ik}skG!S z1QiqU{kMz>+u19=Vn@GrS8#gp!TgR`xmG zHJ($?!KH!yfYd^}UJ<)87~%`^6IB6PNb9icf*P`eKRvOpjj&gDybiZRmSz^B1Mh9=?OU z)_*g5jmN&sW$xm@*_=;H_K9p{gY&TzY#Z8E1|4PBc)n~9E9abj=#PhY(0bQ(hgugq z=NGw)os*c_6FtU!Kx`LJF;G_(^R@V{{eMw5WnNs7{ciVy1wRkX!s#Z)d1$3VuIMbU0ev#ohJ0*udrN4BEFS&Q- zXG{FzgE)=r^r4yC8$3Vwj^Kv^gx8&LIJhZr=EdWhfG={#A2zekzp*yQ@A9+unV%Ko zYqKWz&Z0AYx1eh4WcG*sxZh3YtNmSo5{LO`#&U`Ofj7zrsx3VjS;#;v~Tb&pCwgzQamp-c8 zm0Wwqa?O#yJ5b~B_xXIm9=RlQF_1I5+0X@ue6^{rcLwy}E17G#UHf^Gx-6VK^i%SE zt*95zi>*QVx;m_NX_5236ioR@u6x3L!5;F&&^-Ziv=Go&^6yA2=|NSq-Vt6i0s5xq z*PF|hK5lZ_elO0MzATRM`}*KLfxCoXD?!b_EBzaTy}|PWJnD6d$DQ$lK>p+l$r-== z{-ZsgDY(3`D#$$?r#=8T;yb%WQvEk{WF)y)OL zTu?mxEZKF=?1iesT^Y2n*Vq|o=TD|ju5-`+l7CM6WZqSvgYW+m=+~K6`;fca+k$ai|2%VKiz`3W^`E5uKLyUkUG0l_wYB^086z?Lbk>9Xs)w6` zu?^429Qt(IurWH=aCI=Y;flQ)cbRnIkYFZJVHBzkh{p8=6nIZoCcetEI{2qRe%d?bV8*D8t6gf<-n$BFjt%b*%7*qV)%tt0zBy>0LEgXG zbL8{qO3A0b zyvdJxwqE(_(nsQQr0=c$ofh2#!KX7{a>SWI{OTnJt(aDQ_^wzrA)%urZeLUY~9kI*an0}mXerKI+ zt-V_^MrE(~jqP&|y8u-z+4z`~u%SI~&tg!hbcrFKP4i8>O8+=!;y~wPPoR^1bXNZS z`@pJa`Fu>qYK6Qb0rEYHas6!SS8iVyY$Zqj(C)w-d|Q4N;2p``z#l$r3;0wvOr0sZ z?ZH=PfwB4Vv#)aNynOiy&I?(sO}7qXe*Ig(ok7UmI3Mu2WIr-}d62s+ht~K&KxP|rcc*-I0cvCYl_!Wb|4L8Q$c|ph zv2(!pg=TIl7Cuvv#Xfg)Yo9Y3GiKWOxD(iDZyTGrVSIX8wvXe{`hVpKWV3lkurnYJ z_~(9cFJ6`Xawop^?k9hb&%9c9KHe65b+8<;hfI5~4i8&eo^2VcnbIlWhXS&}vzc72 zcNa3%d_*1HLkF1iE{0$IK)p}QYROy(?59KRs4+JB*)`kgWTSf69N1HznU~VH&s-NE zJG#Y?T{6w7FTySYEmS$>-R= z-qQob=CWTbu1zeuv~*}uE3fNk*5Y`4dETqId>8jA+59=#SU$OtSFz0YqyDZpS2{WyLX|VVbtXdW z7u#8PLYFl(wU@tNHDO=ny7tV6??A8=Tpg6n-bvNOu0TxuziaGK3!WMHuL``g@WnY& zGvi#FcUO$-f_+bkePqu1-JT1wCLZLMy~bUD$aYqzbWYhKmZu`8z5lYcuc4JDrsT0f z?Tu~V-=P!uSLehTSx?ri*p_`22Qn@V*aKyoc0Q={E4O&t^I^O8!E1COxUKLcLY0!zA?S_Ox5XEpM>67 zy2PQ?Rp&}voh6^smje66<@(?~fwN_d>KUldzWsrC$rrjV;FsLBy7)!UuVkUk+jx%7 z#{^`w_UdmA*rJ|{OOJlS(!VFElP$sFpx%$vhBGLp3xWOgdM@#2DXn0J$&R zEA1I}uRH52LCF>aa*VCfe`!D-&{Hz4v$^VuJo3rI*UB(bI;pS~EEj@BOeeth7D{=s}LxUZ{!M_O{* z{JbJ#bNd516oZ!pd_NGVTWfr>j~}b?L;l;}j}@EBkJ!!y^1@#IZ0YNZJoO+3s{#M5 zdB?6=SV*6YagE`-CfFX#2kgB%xH6DudAl*r;A3m$^TFxUS2=OU&JWn8KH0#owr=P* zPe<7~KD%@*1bD9v$}TaYk4!u_1#Gz}SP8_kd}HfkP@j|P_Z`K4Dc~FV@*$q?9DO#4 zm$mY%OCR}MHlAbC;VA3Uvd#C34hQWStM31iHg?DLU-g?cK%quddCTmOwUt5_6hjD8g-EEDOZna8>^;QNS z<$}Fx7JtQIIsLN(`)Z9{{J1&DtKiYU$5ZRI*ZC%wEwv_3yMip8_LAm35|3PID_7zU z;%Z*KIul!ivVX%ccYRtqoD(&Twg-GxUr#@CEqC^{zmH|iM>;D0?Y&g7k^^xOBXj$M ztAp~3ZBcRDI-AR$mGqrIJnC;>;LK{-;P*xO!UpHy#xRzx86M3|#eofFi<+dL-xb>f ziS25}b&m1d%g?$ijn$Jq^7-uioTlBwj<1=p!~8QQ=IN+-XxUZv?1^l-Gsgz&Vxe_! zwDz;*PxEgQ=y~RZ9{bJ@_#r3ilbn*JHLvwf#V39H=us03LtD9In_Ot|ZVtrX@4B-` zUgZ0#fE@Y6r=Hb~<#D$F|a?t+-g@8~>k`O^4H3S1;_hzA&_7 z`;TNE(aAjI;fG##44!jdsFa2Z~ z7sQdR>fqMcLM9umi<6dqEnl^CjD02F|KPdhSHEP7&3iw!w#I&b;ujx%zMUS>&4=BA z_2OlR=Ucriw{cj=eC<)6|JOvlsIUJpG0#?U+ZR-zdx}@CTf3YgapX(g zr}*Wzl{K|bKFKfMwzi+2*j0^I?eggx!qlZDZ^{?8Aa>PVQvSB`pFAO-zg>Xnx~b7c z79Z){6qIfB$yqD=ArrFspr-h&KGeavLw#&bUu~(0_MChy|1)m-yxVEjx4rE6!>pAJ z^5#s?(c1CL4Nt|e>bjl_Te64j_DsA!`^3ULdD{C0WgDNL9-da$<1(g$fA~v}SQ)cX z%TKNPEqQ8S%b>H)p>u(+o&(G2^IeQS^~trkJTUzu0m8d7v~+g?S`Dn#^MUPR)dh$R z@~2)d57@#6XLLt!M`Rw(zV&pLO?>PERCDf1F`8v(mo>y*xtp?2UDUnNrH@MftT;^V zaR#27BzI}+yvezE@$W%F#oszx_*C)SnZ9`9y)q~s`6(W4`M|ciL%Q^ly`HaA^Zc(n znVc>_?Ea52luzDGQM+C_SF7e*-z!em+C1#d*qP`8_OsPq_T4v7&kqT91pGdI0NLIP z_^$7rr_Q3btyOkEZ?OB3>8tgnz`o^RYe0|MC_NF~pIvU!!R~@Hw-Df`YhOUe^P__= z*9Y$jt_uD&@GN=3#M;M)wVNl_J~XU- zUowoHZ)0bWK4;7LLBXM+|A4e#J@nlLPaXQ6SN6CQ?YVFmJEz9ZvvqgA@%h789E{z2 z*4;J6d^5iLFlMW?K4hz`?0&j*ga#9nBY|t?yqXQ^wIW!3^B(i zCgbm^U7b06_U{OG4t?Xt2j0rq?YS=33qz}aN04p3?d~@AxL?J|y;-(wNMEklrOy`p zM*^e<%pC~ICox(K_zAlLJa22hFT;;*f%sW--(C=iYxz#!HNnRM{=F)K>1e-?qSjwM zF^{kQo#kr!awI3H>%XqmR?T^?Z4KCde!%Yez&>@XRU`a$M%Cd$urW|Wm4C6Z*B&i9 zPV`y7>PHOr2FRHe3${BqU4Yc}Qecl~5PRtN9Ad9nRvzeI4Ak#y12O#16R{G**UXsz zFEi#}J7fO4Cg%C@^nf2?C+B?V0(3(#Yt3G84^*zY^pSjw=g5~6es=*n5nsvgdhTN} zHt+rz>o}Y_`JE4@{Aq2Vo19Anc0tMQ(npokt{<(fqu zp4i9Nsds1Rdod70cOSpSs`T@j4;3^0)qpOt|LfqpeO-XqIj&E<|Mw}_Ar6Rtzk+r7h7k70J&bYXdMb237g_)yQyh?_B zsC3XrrZXtdhl4uvYGFB`gRk!H?;Ud5KL5y2AI}J?4)B*w`|W*w_Nwtsf%w%KZ)5oC z=K0L_r9iIv*ab*!eP1?p1|f3DsJ8AHwx1o4!9KpLmtBDz9&U75mnXjL55!{1zQ;Fv zX4zMER4ls4LUPpFBu4v&`Ss4KI$_Vars>}i>Vs1MtWro1B*$f>wsuiCgW{hvJWENAJ!2FEEaNFSO1f zzI_3?d{#g1dFMxd<)vh^3E?N#`?|YNzU*~>h*^6_9?WDK z99@vT?5cR^vw@BNUwPuQ7|>zuP(VJOrv~)nb+=i^TjO;5v3e`adJc%i*tZ)qCpKN6 zHneE!tk-_`OBb~KQ*kT)upX7m7dANmT|frAr|vBCU4X|v<8f`=J#!V;4e7(l#+5uZ zgx}}X%0rhiTF-v#oiCyCz4d8(=H&|USDzlwJ9^XvTg!HHD?!Oh_o)1eS<>Ini3j=P z{q5%nd#(@UvFa+_qx-*B~4d}#cf7xyhJ-+{X?Eh!)OnS$^ zGa#FN(CQb9c8#6lyByTJmpx;IQ~f*AlFP2rtM<(u z2-wUQ?bx5y%M(Ap?ZQ)}Km-kiFwGoS9!XWuX6j%>#-8;xHu8b56`{>st#;4t1D z9ehEr`QWktht!r4|Ig=lSDY{Pxhs&%*JRFnnlTwiGOqWFntMX#_*>(<4?OL@=jL|~ zjLEiNEVa&h*|#zM7ytR%|Ch^}9Ml?HUi25Y-8P?=oZ3sLwMWd5PX=DVdq(ie;phBx zn|DW)oO@+W4oYvjr+p}T+wnhUj350=e(uYjdj#Z>MJ7A7tq$YDIYZxhH0OJ$rQ@vh z_vilyR^tp$JM`h>$KN~}Z~VxyxRF_V#pa#O+E}mWKK-8a+J%5`cMIM={9L$XW$Lt# z4zlp5hyOVIthjj0-9LZmGR@I?xFSE}6{D*8`W{1D>)XP^?}}gL_#T;KSH*GjFkTqi zrJ-FOTJIJ3cMdJP*hg$(%W;-9K3em>K(^<& zeZ3F+GZu%6>yW-im;L7L83J)Izc+Y9P&TJKnIp#@)U!xj*jHeKxRhM6z&iw*c+sWF zt9JrpIiZuB%5&)&GN;)~e(#(4vcsDEYz`hB^!d>*zOPIlulj_tR~+S?E%QO?M=K}% z=|5lKT?i_+DyDarhjuV?LA6u{dB7>|36Hv zYC^waKo@(&8ny3drtIVINr5|3%^e8%AjbO6^blyqy94=TEA`~Qt;y|cojiI=E}zAs zWV5egTJfm5p!3?`oPZ3VTip(UHnxQy+XDI32QijEG2tEmJTv+G$iO|O;ZqyVF}vmi zy4c}-I5QePwgUa`gT;V-8v^aTpz=&NePTeyLf~Gtj)EGXXGg%k*X2Io`>{d7I`i)w zlOYd#gNjY{$z=!Gn}Z?H>OQ~^wJxXPRX+2d4W3u$2V&!MgtIsHw_;*1ope|3`Af&C zfxQ|VD<|$2eiYVYNF$TZ@tvpMtf`@^0`aOEB18SiSIMcht(miTTp!LCU-@2suup#Z zGX$FP!GMg4nfR5TrDw>ThTq&=Fa&Z>o|v8!un*XUo*eLnZneNaapccpfT!ZePIa*{ z@V;s7f=1Pve94&p2-U2Yc9A=T$7&EYJMVrtKFG z5cdlsNFQI-gUE^9e4Bq#=w-pnf;R;p2+YA>Ho7Tt#DZI5RQ~cA~ys>|!_U4cMzcrs6pS+Sm{K_=Cr}5J$0*&x*IX%>ljx z!T2nwM@>AAv~6q{-|zRd4b$SohDQWzjSCrSQhas<+G3s={OjL+Yb>UBwMONXjg?n= z)#*Rvv#>cj`kIwL_1oL{XW=cIto1gXkgq6P@Y|5+JmseCw%t7Vbyz%%P zu!G$GT~3_&3~c<_W@G;j$PR5BBQdO6dGwSRoSF4^glPzs%dG)D+E|wH_COBBUwru{ zHl7Fch{Mq{^t^MVr)(yJUVdxiv1i7!CM!#8^e?^FEj=^Tig*IM3hb$Qan}FZfF8M0 zFI$4Spr5m!Pk8w3{^yr@ zS>^lK*UHnj*sT`$1pHv<6-lbGx_VcP5p(nJ3!W2@CuVA`WQYyOvs~)auf7fj`!#^|RKRD}Chc52}9ad|j0}d%e%h2jsJ(-gSobwF80YviCe~ z2>63)*2x|MzM|IIu`ZZq2OV?{fkp;9?y3&@b_RUbeke7;$Nqlt9UVKt{ql3koBXN2 zA<(V}$Y7T{j%{_`e=Rb_YIDHvs^4_)dctqaO${hCX65~qaw9{Ehx$D?$!MGVIA5s&h_sCba!eQnmW zSG|jdcpMj~QFwUZ8G2FR9M${_TmOxrn!1t4`Wa{C&zd~lC$Qc>Q_VdzV3W0~5qXdU z_f0QX-uNJI-4HO^@wWrlpT2H1C-33pBUl2k9QuVQqO*S&FQ4UVXTSz$^6$EL@X9wE>s*`bV{hL0oPaFY z8qhuMEQ#HGz>jJB*r44vsM--Hd+aUW>-T`fXG7*M2-u>Y*`QUekY%sh9NVSt`=7s% zF$5YLs}{*(TggPlYzQ>I06oPsq_0L$t?p1Z41u-X0l8Zn9outH+rTH^7m1m7^F4w0 zgsLBN3&G_9oAG;A^2HwfHwB(6NzG)v_R5QUjQ`pdLFur!_{f?M_+E4F(9MDP?h8tH zUt=Y!_IS1z|Nivlc5hJk;E=v%zQ0Rqk2QMO-RrqJ;{(CCR_s%M&Yva*gHD>bICJ$} z@J?p`p`d?P*`B>(&mVf|?APV!#J1+W^yC1~t%1fTG4bBBAvh!W#T+!bWakiQa-^|e zT_SR*6Y&eBVO^QzkeUvpK;|1 zU*%n&eQK(77|VOvK#v&l^}GNt;PKfhp_rU~w(SVm{O!4Kt>fdX?=Z?H^2!HwTRzOC z4{~%u>$9Qq&Mz{DKvNg|Enlkc@gEHM=Dng6b}tRTpl;V^9@yc2(x-?2dmB}o zex9Ii3iv8_^}P*U_8Jd?HcbA!Pmt?6+53uL{ibnGI;2dEd#nKjg?fxQFD1 z&qJW~cT>d*?==1Fo(n2gsQOt9_$lX=H+Jp}Q0+Czy?(_=4Y+UY1Lx;G5g>2<_es{) z1y#SE!OlkIeKCDJe8p$Kvn?<4jfzRxg6Gw-g&*R`|7o(#lP$hv^?va~9V`U;&3h+A#TZDZb{|Xiojub8T==z+c!J;BhzcpZ+?pDBJDv4Bi~b z)hU6!8oLwnd*m|%Tg7S|N3kiJ*(XL~C2nF=wwFKhJH9J3HSuMZ4!QFG^P!*5@~I9* zS`E{AL2z;KwBY98hlAe?%)vi3x-&x7r7zZUvMXRKKgecZf5(&G+l+Sz?5+HzJCVmO zyyMR#kIbB$vC}^HU9W2{0cN0zN;s7 zHfugh6I;c{zRLHp>62UW*XI{I=&Cr9&30?{qrGqJ?0vKM^q`NGIGhu#Zx}-Hi9h+; zo}g^3d>NB7Er<7{J!^>>AH`5!r^U-XpcYn&*N}B_p-&A}9QZFU756@t;~1)8cgl`H zJ9)}ytUh-1m2Df+?{mqHzV?TV@dNw#TXn>5W3o}UvO#`7lh0)4>^U`{N0alhy`Px! zGXp%m9c2UgM+HAQWzUd#y6IH6XvObHoXImI@4X4M9QB_|`7dsCiAm{lCY=AB0h>K9 z9@jprsvSPbvHjv=4#cf$3SDbW)cs+<_lbSMS%Le;U9mMleOB5Qc!t$GO8MmdfK6go z&q%(BC%JKdvd&KPL!k9`*S;b1Y(h0WV#L=Wa5tcMykD#fE)Uo#UgB+y9(!&IJXhFk zy=<2A`2hd>T7DMO=fgsPuYbRp%UHW&iA;VjS2328Qvy6b5p{7wz%sy%E0ak57o@q4cG%l;wI z@Tf(0&59+SS+zD~jgGAWJIe+!V1s%iUo25}qT-CQ$2*dDCOO_2;EAbU@}B(8_O{%= z*9XrJ{7lc!NZ4w<;CF{aF4U;oA zV{ID0IgL*BL;n9w|KG(6B8>Sr@~H1(ioRbQkpNTQYW+$n&&y-)G5(9Mtn{NM9qL zZ1T`)w0obvS@-@*&)Hv&0q&s1U@gztZQLZch>h} zSz5l|@XrSa0zPjH+==`WOS;{|cL@rIA(n zLV>=8z!UoED+KlF`b zDIW9>fmZRUGdN6U?}#z~YEGO#kT_RO?ar7!>-?!&GB=K?XM}a}s9MtpF{$?yF@qaZ zYknW(mjh!tmkV*$Dk}r zyk{K@V#?(2so{NTa7nN+xH6#Ee*5S-I>6_A)L1Tj)?v3CECg&|8#}B1^%Lgh?^};c zUrf!vD4^Hh?Pi}l)|#5NXHQVRuz_y2i68s=ILLi(-|mdHVe;n^KbiZ2X9p#h{S~9F z>6dN2taCH3+2d{~JLI|aT#-H>N=CYq-xD|Ht0qqUc<*S;-+rCF?knx{iIJH1_m%PX zK)uWdYOmjuzh=1V9zOMZetQjj#J}J3D{I)p#;O^6%Xaz~0{MGla3J7^7@IS$_>+O( zywB>#1{)f+W^5hBQ|D0p>D&@K<;dE>Aj2;>13oJ`1NL~{Rj$eJ&m_Ip)eCvz?_GiI z-UWU&3f(dG4S`lQGJfYM``DyE?Tmb~*rtp|;oEX^fs5X!2kA6Gy(Fy8?2^9|BG6qIMEnd~Ao>!%ud+KTIcvZVt#f zB`90Qy0f&rzvPgqetUWD-;!5$;ql#q@epW-VxzNIGRwwwnJeEa2F}cf6T=}?s~Q^f zmJI9Gb~YOFCA)K0o*i74zOy6_=LO!e&u?@gR9@7ed3LaIJ{SV6@^*RpWe5Ant6I1z zefdusmhXRkO};g;1$#dd-|Tg-d@QKF=}u}+?$n%jM$c;d)C@aIr}}2EF~8)HUpEE^ z0`p~i(IImh-kK{qSV)s&bK*H(BX{W5*dr$F73VrD>QQqy^7o@Hm-wq**&zOWGv_^m z&GSLU8o&M1Vl5ud)~`i2S!65*bdqb|$Feq_H=gy~@%*7M)8F5gFU zlfCrwV|QS0#Z7F)ahhED>v=1$L)$Z!k?Cc*{TdmXTBtj3T`Y6If!I|al_R$H`ZAo< z{l3t$d4Jaz=Z`0rr8nI>oweKYclF;H?96=G^QRe;QG3|7qpg3UJ#&q<4~@oeAC13n zGG~kv6bz5r_G}opEhY^X#1F<84iD={bbWUyo_F~8d~*2cuDyKxslQp8D_L*KSbmMQZ)@vhd4Du---VgKZ>V`^tLFbE zdFc1QDq}kF;VFL9GYRFhGpx^Vv}Cj2_`!{C4m~HZu8BLjX9vF##olfHsx7)Z?4xHP zFuf-j0*&2uuI~=sZIQpd>7eJ*fW>U)$0@<1gC_*f4E{y%mN5Qt@VVgV1p4@3Yj9?; zH+Xt*Ab5H3nn06JepM}s|3cuNmv?t#)u!imL@(cm z{vB_3#!M1dlx+Jv1KC859Mqg#(|0Jgp5J7!%RV-i%{9j+_Pa~is9x4L^tRz)PwlHX zmft(F#*bTa50CvHGB38hJi5e3o_#NVY69@Zhzn!itAkm#eQJfZS$hs=K58cUxm73a zlYw~4i#V!Z?*u9;;A#I zM$}3#=Z$Sl7royfX#A{re0Tcec&K#^U)9>(8INy{o{C51WK-s}ag6xPmurLdL7k^* zF%mzGAMXD;gZe|86F0FGw~~GFXzcE^UU9rA{c+6b(9nA#X4|5tVm7UY=CjV9m1^kN ztnUxpVO2*%`dZz+=J_)O;)GXU45!r`ofWH!QQdWH8sBm38v?S)v%mbJ_kuv4_4&CW z(DnrVbD``n-Q=F%@$5*SJrAAoyEyDq^L3|Jt<;`-P1)1m`_7$KG3)IbGVgtI>>K;k z$C1XcWe_G(_-sge#~1oRejkv1jlx~=`MfY{sZ1f|c@QL6L8vZo&^TGcP?wvA!ry5aP<%@Z~s|~*K z~lk535j$h%r)KY2H_{=U$K~cHm1AoW_I zdo-UL%=NY#v*AEME??cJTJMwf7YFpRiQdW$pV(S?BhT870N>NQcW<`vUz5X%#UrKWk=a{D0{X<{x~LM zIW?|(cWh6^p_j#Hb;Fh+(2Vg8fkw_a4&&VRGWk8LR@ALFwne=hHCg$>caX=ld2-#W z_Le=C_+4jkJYRRUeO0gK)(3p%Yt3&+UyL6SkXe1cvD==q!JaxB(`1?3A9!~r_l)2- zQ|!*JdL07oieRiqEX-+p19v-n*h>EpXno9%G+%#@?u@R72Sf0<;OCR5j|HC$zAT1r z3LY6eHn=$O9me+tZwcNNd_4Hwz#S+LV#ANB5jpGc!n*4se&$_AhV?#HVyX3UsT_+> zU&nH=5U__W*5-rVK}`Ju8MR(#qxRvS8}XBek8XM@mM5m~K0i|6zxr~=PkTlkmwAmn z^-L%~oEI?}=Ya2<1GMf#^)KG_EJ}CclR5Z};FuV*7_e#V_bh)8Hy-8p(K>1Tt2lqL z{qEw0u??J?>i=_7`H)|=^R_?}!&@f3rRRCi^Al}ey%f(A(-(eoV(&dby=dm@y?~s# zfUfTirq$^qGp~;9t2?gh)Vp=n;e7hu7u+M>m+bLA{or6B=)Z6N`i##B@Ic)u8`5{5 zmLBgoY$b<32LjKBA<*2{zZIoJsAmAZczW4eGiI0O4(ffrax{Kg8&~|rg%7YmK4;zg-mEcO*jF<3uMNiW5Ubv=y&2E) zM@+?|WEzV@jc4gNy4%O@UT5vCnAW&ri;it(gT~h4uR1Z_5%B4>Dc?^FnP-n$z@wF% zdMDxkLQpb?^w~V#Q|rAAC97fB)lqNjU*u=REh(CQ44%Rhc<<;U2j@_7gkdDCJ-=Qt+pp?e54zV$xr&e+)` zukyQ+oRV)Je|tNo?JNGWqsI30so&2oGA|9>65@I!;7rR;#dbb@y33X!efCuhinn53 zcg(B8qv6$Rzi}^n$hhRqrLW=L60A2!>-kGh$s4jRPkn5v9*f5wwMP%d# z_KbVEJ#X1Dgh%c6e06T7)n%`L9E+;Ax=ZT2ATieHFTLg4kU7trUOykkc^ID=@m0g_ z`u^|j(dC)Qw)KJM8$X`V#_pV#1^DVYsPEZEN7+};LgTB0I{)PMGTCryaCD$~=FxB8 zEdBgji*Eb(2Vzs_mHcahCkN$My35bS9qIGu)A_v4h8n*+p9%5VFL+;vMm$Q6oK#%60(8_Lm zd%F*0{NjM`_X;ZZRpWed@9;rmd&x4Er{bks8}o?m;qKXzy(M>+9P!sK2-rEcr}p)- z)VUb3e+V>VyhEUoGpmlv$C9}}yy7IjTG^t8#n%0#*{AO5DcR{xYDg~GHJ*1**S^Y? zIli)=-8H`l^bOt_{u!=m7k4!8HD=b^FA|?;#u)s?PbO?F~Ff_$(fL90HB(%FB`FtLIYPJtssL zyG{@2l6x`yzQD8RKLoxj{Alny!DoWM57s9*Umh$9Qd)0w<(Ry_Cgoru5EuT|8QYyc zF=H9EUUgpk@F%2q;#Y?~KO1UnA6v%ndFwOR>nwZcGhaC&V@D8|zvM@{XG{4qWd7)2 znw&Zp#alA%Q3vBawO)1`mrZ5Ei>KJYzw*EMu9?Ee|M59@mb5+}Rljx5v!9N;`kAr( zL)DqHEUx?=$12Bm@_hR0Q1N|m<9R};ys0C0u^X*(rY@$*+L(FIGwo{fId8AILC4)FZR>rJzi|tWKYGam)rk4`Mq2*CcmDg`tB<_Dqi(YFIVD4 z*AQ$7)R6dS?lsT!x@%{}jO~@%(kpJW^s>o1UHTeb8d>6xmc4b(#6gbT!}d9oc*l1T zTc+V~-;qv^JdI82Onk~;&jz2{G<7#090-O$V|yRBbs29Cs!q40FAvlF88Sc3kHeXx zx1JATc1xhKMKflTnl9V;Vhlr|sfF@$clv5l9;=pWZMNG2gwP932?jSmM)+e;_Lg>o^`L26Sf7ZQ5$JIeS@5t?Cs_#<+G1c68^xHQ}zdWo( zxBdGA@ux>4|C+%4RDPv9xuewbj(|U(&NGS)HD2jElK+zLNba5QkNLpA`Cug-YGP+V z54*l8dyfgFZ%g3*aG(FjbSiFat3CE@%ilp@oA%LWs~Ry!=C{Nqd)QNR?`nUSqGY-= z*?e~J+tEeme+u>Y(%%=z>F;#ok~d^tv!5>ee>Z%OZvFq9KL69+dwu?hdFQUQ_mkoG z%y>%*V_WFO$C>uRD zzao;w=$-`qrSEZFzviAcWvro@^(XD&zN8Q z)jPkf6p)wceuI^ci${KDt_e3rF%*)G;voinmnmrt&iIU8Q+s&Z|Up%HOG(Y-`zB- zmhYvC+trz?xT)9b*Bw>yyw&Ek^?^Bj;;t{&&uo3MKGgfmo|W=_xNF{V#(SSQWp2!K zq{jXIb#nBIm$=QfzTDRx;(l=VsOeJz=O6zx9`gFGj1XU9TtAQ%G8dy3D$^svFbIs{tjuvYzEpZWf?;D<6^E8L;8c(b(pEWRpz z?^C6pPPJ9_=uJURrr}UOf0hh7JfGeWX!P;(i}m-KE{tv9ZtQ8z-;=aIAL?8~<;$Jo z`yg$c!^6#0&i01% zw+7w|ds*x-UKi{S@aSuGcD^&NKxYio}yJ}YS_={ zG5U6LL_2pcwZwWLtta%<-+ZwD7G;>+#{4wi!gDYz8Z@y-;WM92Xc?{eF!wQ@?R2!!61!a z{Ilms$^TR*zuphjfYwv?4<^&@4m&=57wm9;71G4QG^U9&mANnA7n*w^|RgSHTpSdB>*d)f}^!Z=R7+*p#p|xIe z@B%$OFTd^K_l97a-{z&2KicXRUS|YK+wN@5k^VRO6diIVVG)9S8=Uv~k?r zCw&~;QDWe1ID-oTAL@MB-|rC*Ft3^$zUr zE0ACP!=auXe~@^I8+(U9yCT>hl>NQW{N?}pKzuz1)V6wM>p6j%*2IkOj|yHN@K+4& z#cRJ>U}rXcAVvB11p4#AM>gc&DNG)> z1ZM>=430}eFABCN0q+gSr9VrPpY5C&O20XGupIe)f#XBv;n)DL{OPNY8-wwA5*xBF z55$H{_2kUhOa4s(fBAJ;a9m(rp487Y-SpW{pBN2+Hr7YZEPZEZt@NqM^8$4`O&?vQ zudl(eK5}O1Q|}4kvV3vF`-cf6o$m_{1e=4NPt4{6ynobq7t@y)xv;nYxAo*jb56CM zlFR-*f!L8T1e*M;59CWM@X0~lP5h@z+%z_cm-^(3@l%6`1^WZ%cL>O|?<~nk!?!Uw zIY?de-;Dci<2)jTS$2Lm;6LtxIi zLh0BQYzp|?$I-gn)Lvt8sClv76xfHaYE2yvfwnbZzdGR)K0e8X*!TY?SB>eoAaLgJ zvI(vY)F^+-7WJ!7$KK$aK>RfNW<7hvuWab+Ts($Ad{9lz(M!jUKzqfMzsrQLuQ$HR zoBF4Z{cPgbLV#avk81t%8!dlot;YPbpWT~-UBRYcoHw?D*r50p1AJmjA6ewc8DGV| zj|1C#e|L8Nmi_Jkc|9wrzuQ6P5U7F5Cpq$1<8glN>2=+|)5SKiLh;E@7-pzK! z{mGdWGv`WNwY`C{+IH^5)^{Rb8GFo$yIhI4zC11lS)Rnd-?KTBV?EyUw7tPJJtt%j zJ!-=H+I(;*I`1__r~6QwrStC+_tIJK3fG5UoehC@C^r1p$Q%3p!6h+wiurrGxjq*5 ziurFvjwaR>b9r));D2rF8{?_^|L6D}mUE;3?gHQBW3BT08ayxi#78dWUtPH~)Rno7 zftU)lb$OkI@#fVCR?uY zq3W^v_G}7P)5Wi{RlnE820CC`EZ9)7D7|a3!Dsd%(Ck~y205xaKRF8foE@LBwY@>z zPajNQ>*wCHG&Pxa(HT=&R|)plZ68^Zp1P*TJ>n)!1Hl>(`k`>+{Vbve=3q z3Cu+fe}90(X?NCl^yJ+0y9d2|v+s3N_Z>5dvp7wI{p8tyF#FlS_x^cN>n|9|cfQ?y z^NruRbneAXKGlWwA<(Q_^StC+jr$zAv)ClZY`Q!;jpfPsscp;@TP;>ausr%NR!v|#lN;$mONd9wU<2aAv-RBX{k;vs|Bd5>hAGI-) z^f~BcZZ128YzAO6JI6fER%2&GY&|;N23> z5NO`H2Awo#0iSc@Su7{85DbAPe80VoE55g7ye{Ztd0NKW*tgo_ zxv0->XSc7FOEUIe>#Vwqdw=TuXL=HYqT(_bq>0I(leU(7o9*IFFF(u1uT8)FqPJ|l zC4Ft{5?TIz53yr2d*$owK${Qb%l$M2TG@s6v8IO%KFHTt&X75KP;DhS{J3?(wRG;t zJu~=B3SwyUd`MYMbXxnb-P)0`q2eb$e4AB+*2N9&95R*36p|TXS_z z(w+35wLx!bjX!l(u4;XAk@O>Bv^~P7Vx#pRb@A-Ev!$-PPZf{$ije%!!kn^YfuW z<-O|JocH?qpw6>eCet2gk8bkFk$?G`3-H-5XA1#a=@j1^18Zu;ntAnsx9m0U?Pb%U z%I$UXt@J-KeKo%rIO}{73-xIaU&j8*A=|9ieUa`YHYJx&_@>2+{kH`4JUQ4Hc#eu4 z+xmEvt>SS*Kz`+vd}C0LPnvt z>QG*d`Gc1qX9Ry7M$c0EhCsU_u)lI*@3q0$ZnlkM&UW)C+xm4n$q?6ZP7Y*l2sAv? z@yD#92*v$oE!p0%c$gLW4PHVg?{Y`Su!PGro-=S4S^p z?kqLC7}%q~F%U~*`2{|sz3!4tmcBJ|*u{taL7$%kqjBZy)XdX)LSP@C>^m-y*Yca6 z?t~%G%;PP}j_U79e^bDgX?eg$S5f{|zuzlA{h5|?c4))o&pUF!{+ipGzW5y#oF9yR zACJksCD7ax*93Vy-|miC7hD~Paq;l$*+H#8C;f`&H>59~^zxDa*9Cq3kK=3a*e~(m z`#A3IxzA?95ULsf$!PrFx^cyo9Ci(XCI*8}8X12&+QaUH0sqM`z98UxjZt?FKC!N` zTHvF&ZVq+@n*w{sIklf{+A#TZsn*T)^;UI6Zt=1E&pNw%pZY$#)M{_1aev?RHjejh z2rn7v-mY)YV!$u;;n}sNjm5y3McuLe@BYQ)NiID9$Ycxu=n%6T1OAgc1e&$}ypnzdP4eiiwE2Aj`fv)S(@;;1Jriq&^~i~+7$4qVoTQ1 z!4PO$12!BL&?&Zi0{rw?W2g6z9RXRN$^Xk2AAY&JIgp=61llc2WOBD|OrI=%;AI;s z#?{}I{-%KJ1HrWcy$gZ8zy^2qDFNMwDwj;MSCgw|=wjP^z%RKm&u05kHZKNjX3x5y z?gM87<2xODgYms4ry4#rjqm(m%y%$z^4#+q%SYwC)+$co!2do6 z^0HDcD=z9sO|l8tj`p!r7u$mE0p6a!>|dXGxv=;2pyZGD@vgx6U1H;mt;WOGtpV8;1AP$x!Z;4*D-QI~ z*YB@5sAImev+9?R-aFMW>}|CCB(L<|nEtr|dxk(0H`voC-#_2^u2%5#i>$Is|E!?@ z_ZQen*Hr;qFQK41q?TSoLz*K9<|(bL`8y@Rv_T z$&k;g=aRRWxvCFxoUhjh<@^5h#eH9(@7brX4#@OA`{!}|+EBiDFX6NOn*y>A1m?Ua zh-c+uNMCb4#A92qJy4Hojf~aosra%GN4*<7I(&&!+_Pe`SDI>?;QN>1W46z%D#j z2hL9Z*YJ~{8(f|~IsC1?=`P;^H>K}9+siM!Wy=-mSIwk5u~R*53*<&0>{rM7djmGt zeRxCq&e7&T9Ms&NfGy*HQ`tRO|E_Drq;wsXHLdoZy)>M}K+JXq#q+!Ioh=sxa(P`q zud%wjKFF`*-~PN%cCroiZg6d&c8gcs^u_1KfGqnC1`%;Px%QV|WSb`gtnCgocB(`3 z#{^`n8+9@SnmOm)oLCym`=)>m?0i+gS2@?{E_=wMX9zU9&I`CE*1M;sYKwK0GB z(^Iw&nA6xR_gdd)gMSZDdr3eio7J9qwy0BU_8FJY`r4&|-~a!Hbzd?Q7l!9?!IJ`K z>S=*<{B^bYN6%l%kR`|*QD zWA{$K?(Fnq_g6nYZZvk!_Uk8f<1^C#i_}D|8~^2K{69zIzZ#AIdNlr<(fD(t@&6i) z|F#>8r9e;+CGwO`>dFto;eAT=hKPu?& z=po}icNs3r?sL}9_qprm`yBT3$7fK!@#P<;_;R1j?+w(Y`)3HeTiZ7mXy*CsU7+Np zyF9;f#{8x!^X>{c0=mVEzv|4L#?F82>@@!0qwznD#8b7cbXLzT*_IXCs-UoHO_I_zM&hQKN+V}PV@39@P z@t1Yu^4H(hUnw5Pud;r^D(fe%vVPJk>nE?W{^hHzKX{e(uUKXMA*-xEbd~juGuD%i z<=m}y|7?nkx+COqel%VfjW>_Ri=*+DZd`U`YWZEy-Rt?V7`Wrrxc9wN!c_B~`wPJk zjPGY>q2#IgS@KR@gFOCjZG8RDV4Ra}!S;X-tEl+lG_E0X z9v0s5yzw~anVS6Et&cTZo*Fzk&}WM{i2wg>e-Bdr)(UYDb1_l>^5m?jpURm!Q9E+$ zbKfaJJrD8J+_d^WKkMRrb0GfC7x{9|Mly#$t9rAJ_a_7W%2mnu;mm2bERl&Vy$?T_ z`MH1(bd&XlKr31QFYilv7bkhYSa8xRJ{P3FA*h%S>C3r!dG2#+d`uvJ_FNsvttQ_a z1Mkdq)x7s2wNvu0P2XJA+NSi$t^Mv9WBb*rd#(1`N3UAbw@1Bh3heQjWp6;A{e8_H z$an~}Sv6^&`XWoL_-d>+jrmpeXKt1peA|NU0UtCr<45VKc%Pg;o?8NqPO`;u2sFCq zC%rrN)jfV|n|Du7+s9t5^o{q?$6omu0*yX=E{VYdN;R`eZxD_3segEB&p3hLR%iWxDFQ>PI4Ra&@6Gvn9+wU(s_^Z{Knx?yAQ1S50JuQhEKR4MtE#~%D z%=OuObKp+h5U}f(K(nruF8!X@xaYOEc-i&vRqPTcV1pWv$FfZ<)RB3 zfrbyiChpIi^bRlXM>19y#g3I?amgy{v-Td&zKWrmJUI}{>jQVf5NH)gYw~d*aKBVc z(w)3xEQZRF`=@d;q_33>eYqk7yqnZMcatDkvpPJefx zku?__AG|DJr@p<`jQ0oPqqzfj1m^vmx8(A7R=;$qQ+u`F%wDo~24un6|8?o#!YcU( z!o&8S=YsHLYT1Ur$q!R|xvy{I+JpD~+0&2j|HpS8Uy*Uy<=cr`08zZVa9yFU%)@Q(<*)p|GQYr7eCFi%@ALmYI}kc8AHUlE zzi74p4UJb`ULUY?J~%V@$_OqQy}aJeuN%qxRDP+bU;jwPWuND%ca{1agWk7|`DBa- zExwc5*n72k-@~9A8)d8U=0>+PdTOKF84!wfy}2rMoBOmyn(wye{~` z;8y~7n0S-#P0&omp!-Vj_98Dc~(-iph3@58cY z4}Z>XdezPlXwDuzX9tgnQJxRCrJ%O8d3lF=uIldz*kA86k5B)egxb3&^{u2!KHZtS z0&x`^XJl6bq-LF;_XW=hJpa^<{Ehdy!|gjg`@F-C_sO60vo)}HoS)kN$n3v=*2nwT zXO0Ywo-@K{PtWIU;2XF?dPv%E0du`2Uc{Zquy~_Gmt+M`@Ro1_H zmGyI0SwDA`^uXk7 zf7~kTk6&f|39GC>ah3Hat+M{LtE^wV!g`MI@}2$U@VUeLb9idT?(ClLDQo1rWQ}}J zT_fM6Yvg;{8u>0;g>P^C?w@IwhkvDKOCO^vR*_xL$tzdk8{6>oRcvryUKO5ky)Se* zw6>#-FV6e6e0%@#d@VkDJ;BUlk=+kPj*n;w|?KHiHN*XNe1uLrd6A$DespYZ&A=Mb`dxBgE14ni#q z7Sep)oD1ByFNv;eLKn07>7kzs_6OGn*9Bi6Tpz4&lnuuBYV?>!U2*2!-zdLP{-XD5 zlpV%u4do~59H2f!qwZ&vt>|%$9^a@sHGg8GCpGGORr5Yqp}w0y{VWjm9R;e!(T$C6 zYIMF)&milY8x?=!Esd&wWA7%Y&xEMYZRqw!<;r+xqYrD;*)sp|M!&LA-+h?(Sr$FL z(MLAwJeqeWpl3CzR*dBoeRQK=)#zgy{pv>jEDGPbjSh|OZuGH@s!4q67gejM+C?vD z^uk8>HF{B_U(@L08hw1DPiXXsjXtT-uWj_=MxWfM??mXkq|v7~>i#nSv_>y$^zufp zX!OcP)j0mE8hu8iU)Sg}8+}%z&I10c8+~@8&uP@zv3{UY=f>FCLF@eJ!*d(Gq0t)~ zeO{yA(C9Zd`b~{KztMlu=r=d|f<|B1=uM5jsL>ZU`jSRp+UU15da%)#HF|TSFK_gg zMsIEO6^*{K(c2n*Rioe9=(jcc?Tx;=(bqKk+D2d3=<6H(m!bCw?iV~Dcu?Rj*wCmo zW9uj$wD|PFeSx|sQ1=7sUO?RksCxk2)TncB?7XASIl8sc?Tzki^t495ve8|QIOIZI+v*Ph&qSp(CA|ub>7T7XXu5EUexI08ht{ePipkyMx7V?oD_g7sNx1E{-0}yTmv~;&e}f4ewo}&OZvDdSl;BjUEYGUo^K=SL-78DZw|4;&W@} zH18^S_68M8@zlN;V!2W**tgR9kz8{|E0zyRzv}P4ElvkR^COeV{~vZk`a_`Y3bq91 z$god)WnfOswMPZczVQvgmk0BK+?n$ZZrwdnYw1qjEu} zZ@X%iZ6KcwJt)x&W?)u!B3%*9N7sPXwgqubo9 zdc|9^&P=~#rF$n?WLJ$JlfLn^+&w)D*6!)t9f=s<)g0OX(O@j6&)x9}PTd*q81;U0 zpxx6k8{2tzj`{YCV68gDY%WmmA8h@v2%QhatUm+ao^jQ!J?h<^hF7E8oV(fFQGwd6 zdX|S?-XR*O z)YO5hSNBf}o)^5fA>>YXi{EtTi~HVPJ_fnsA)YS^G_i3`eDBI1XYe6`cH0t}d}pJp zR@sMNtM`Wk>5tzZ#HXG=*Qa0SD&0xUuq87@IUjJ6g)Ak0w4;5>z?74MmIC;L8?8juTVkRcNUT2}!Y@MaI-=ikR zd(?*TKC(&pQIGe7!XNf3A1Fe;3^_ z?XDTm;bXJ;weA_qm^D@#YF^Af6^OsusF+=zzDB>ff6kcA^5IbCD~^YRYD>(H z3o2&rnIX{JeS=P#J7dsEb3Y9_X;tUqT4%ImJs@*Kp!Kq*?cWd{`<-_-x#NuI+Ss0w zZ~f|^^i-aGU!eWJJl}C9#cW+5W+w(`1wN~zb$?kGGxwf6%m-S{$%(m&cjdgEGv+n> z`@2o)>o^ZnTvs+BW?=V%Fp8MWoLR~ z!(8Y}HsI@R7~52~sJC|ooNA4;xEm@az3*(; z5R{BQN9?>l3cP2EooAc(Lp~LM>8!ZmqrcYGVfob0*FHa6?C+ia{+P>}pCx}w3RcbT zZM<~wfsWsZaqKr|{O)YBPhSr0qrdpypQMVjnDV9eP0M%11{M2r0vOt4V>&+= z<(osvS3l+!gYuWJ{h6rv;O*y6&$!~&&&&HM0l&0MgL=0(Fa56xzP8P)eRf?Nh_j!| zzBsr!@IL70oZlIIZ}5Y`4+lRH{8aFc;1`1T2OkPP9{k7PlffSZpAG&zIQpoie`Dgb z(6fWR!BxS_gVzM#6Z}~4!QfAW&jkwT+ky`SzZd*XaKFUu#9$$KSn#Nh?n(dp;03|= z1#b%89K0j=K%h?DmvZB*Zdp>XJil$m{1a!)KWWCixK5LQ@r?N=&zOJOjCt=s)8t<< zWB$q+^Us|zf5VJa*sZ!Z@-vmdjoM~N9B^figm@7ZDW0Gke6Pry%od7^m|{6 zZ?%0}NBb&9WLJzz$M!?u-7(_bn{jVbhRd}+Eguz&og+EsJ%csA^)kh0tVf;lN!$T{ zz3-GPXUVhj=s>Id+>-uUes)CevjfzfSGJ#)zC2Dl8(-Px`Jj~_Vm=pC%+E-_&nw&T zvU!{zahb-e)`~aXW&bWUh}TEw&+~$31}|<18SyQBf5vY48p9bD|EC1k1X{(>`x8IC z7qU;gZHY|YH+5eT@Oyl(?ay2vL$+3I=;{6KV~CGU?hZCRHkh@qVp=tiYGwc7+DgtW zoxQE4Z*TZ72~G^O(tqpHa1!&9_vp;=eM`{m`KmTQt*&~$ab2;;bAr6NKx2=Z9^2te z$@SsdW$!fqJ=@qgz7NmM+@aow=VZ^c+7Opn`p14A6W(d@7N43|SJU+LaV)vz-?+xD z_ch+jzu*YS-?xJN$FCy4{Je0)$L2nV{WJOrhrsJ>_VFvZVlRfhTxVmgymi;ew>C|# z`M$>M-o7;RrRSRT9~Agp_r$=vr8A)~XB7i_oC|uagSGxyh|aJf27PR{SqZ zzidi(P5zMois0zLnNs)VqtATP&Qzu+cH1ld&STl|tn|x<{tQ)&`P=WyaM{lLr$5f8 zcgK>~^U^uyec2)KzGekpw(buqZ>1+w%eKmOKd&C-0<8I*e^NlkVo>q9C4Jv#)!v%F zb;kTFX3XCD>zi7t%i)YNgbjJKkX3T%fXkJdl&Ryl% zbTBV1*M~ZLR|O9U)QWYy-YKeIxit1Zt2X2q2< z&TrLj*rv&`j7Px=dbYeiBJB&=Za9wp&a`F?PuV!6uMLwwm*P*S`=azd zBYm~JKj`IEeE7kJ@}qRw&j-yux@Y-t@2si2m&G}E>PO>a z=`8!znRsbrT^Hcn8x(KFO^o|Ek@3;M^JqiBU-89rFc7nfY0vBYjCt8GjrXJ}ymM1{ z`C-0%7JqT@Ece{LGSK+9m{#gHxX<8E{=$Y$ruV<&ynYU7H`%S|7{ z>ocx*hZm-AOqSX+ zrSUC&MwBCUFh>6wk?)%Qy}h%>a-$Z`4K#l7^+3b4SZ>Rj+L#OKuBf{4{_~+guGOPF z^RMcy*7ZFeMQwdk=(sNHvnjvWPFo56=Qx?UmWYcnHS62x1;glah8hjeofw^GdE4&@8*je?`dpAd)wcbwep8t z>t%!ZT$lB->r2~u*<}5+w!hyeCi9se#|%%|J;`ggx8i61AM^KL?;DCA<)`^SZ-4LF zeDA}jGOy;%qs9O6%ulmH{TI)>I$ax@4E~XIa^vIY_l3`#GhwehU)$zNp1HG{JTa_z z$+f-rZM1Byb@gAeQ8kHrzM>0_ZV9E^{wMt19eKmk=hj%9QSUb>U(k~6d>hXPI|H_p zG2|bQ3z?i@>*JVg%v|kbi+7Rl%)iCOx6)bh8}m-?^zh1E`CfZAWsY3Fl8g6Y?ceyS z`rDm3O}sV*X9u^&XwTYjjsx35w+DQIy#c#!2(|`lsO~g%(VxNmZ(5iCtqS@!2X$w7 zUeKk@2iFJU^1J}A^~K=4!1}?!zvXmeDA3KGv3+c#gU?#Yd2IS}?G9LJk9^fV#TW4= zQ@!%9^1#-TeQx@j0z4Yq^v8NU1IT0do`9~sf%@UIIqxXH7T`6fsZBoft90TmA4?zK z$YZawV$ZI?JGz=Wqfz#1R|I1l?cEu$QEq=dF|YitC3kEs8>i)tPwY{PB^SS15HmTV zSDPhA+{mf*iUpf%Zg=|gZR~d(oC$gTP@^9Xt^CUAS;3gE&o|zZ-RHaCCwB7pu|WR# z=pO6i&Bp5k^`q7+xAIl;%b)$36Z3t+)d8Q`fxa}jBzSn>eb_Tr{KmD5x7K=p%$L62 zA9Ygm6~oFq|JXYO+A#U^4jbJea>qw@9&CN@=QaPL^x6GesVn}eT{<;>(^dLUOMfBI z)OEl1h>X?ITrjPU<}=UU9RYj(q`QmQM(%iDrY1FGU)ewp-f^C5y=?4r#V0zq1>0Lc zWLf4T(`R4B)%oYUoH(;;VFrV}?<_U`-i+_tt-mT` z&oTBD&;GVY%*2a)JR2Id-?%6qT(yJWeCUYSYHzY7xtvGUH~EXx^r#y)!( zSKQUoLLi>j)%3J=IhQ+foz=e&$k-mJOMCj<`3#BQ`6t&IuiPJ%zUHnmPbRyoPY!u( zs?VZhd&{1!;URDGt{%!yYjwud|Ko$XK)!EFjPP6)d@NuC{xgDCO<5CPYu`F$P0p-+ zTh_=9S+4sl(r43G1$?95_|XBGY!0RL+IoEWFkLP&Bvhs6I=H&U+351w< z-m+cazj4XWg*ILcbr$D?+ApSRfZd*X>c*NlS6zQ~`t}Tgc3gnx>fn;VJ1HB*jx2k{ zj;*t5q3SLylQ>lTjZ5$O>C;cWYbkKa_&DL9B6Z;Lk+TPZ=klz=5&{3(u=R27xZa6 z1AE~Qlc(~H&R!1x{x)D^9|L*b5oo^qlN+%!udev6-uJcsgImAk^l>GZUi|YxFYAZt-V}R%?BKT?Y25Q+=&! zVO)peP8QvjGkT(K`F>6JPId0tf!{v*#q`90&ZhUYkI&bup+MOv_90@L!FIk5*@Z&OWyl1Nk{R zYhv)!K;CBYk*Q|p0I|A|jZ?VrgFxGs>XT9Fv z%!^TdCs+F(9KN1MJmxZ|o{Hx$<9u&JTwPv!d)9irSB%DAlX1`gEA9KHlKt-P`=@$` zEL-2$*5s?+E$PDN44`s_ilcqU1lMIBo&2|^M$y_^^W*ncvOGsO1e!5D&g8$0KzG0= z6lR**aF!}x=ITDHGim)90sEclmj!aw@3}N%)lMw_jloy7e#qqf@@0wdm^*zhf8WgW zw~+3HpL}`L_5{7H{d{kSvrUh>)KAF~bM;+* zJM$Wueck*-w}&0}kg+{5c7L#aTVRenSc=Q~$^9jtCk3UC4rlW_B7m*ry)Sr9aB3jt zWE9_bu95EzYvlV^EAaJx#DwMAasPY8r|}W4uMA3Tu}FzHS*Ax25eW0X9V9B-^IIr-Zr1U#)f)6_p-Fw*5jHtR(9k4;2!Tz9PlmECx1uYSdNNMEZp{R6?h1NqeQzZ6+Md+gmDh!0=H6CYcD zDty-aIFRGH#s9I*`0VE|o$i#M37!#b2-u{av}t_q4|4JGNyE1#u+RIA8rmN`G{8&O znZb9*0s8m0xvG72_C0M)O!1Rh?>}Vm$-VuM;L6~dKqF6m%jHFZ7;O&B!;OLXxKoOU zop{(+xli{_-^KCGa{~o&`cOdTi-SvoPbKzj<1_pC@x3v?vu01gkIMsgd+v$By#g|< z-xR1vF|zkxXD{BlKvR2V1Hahs`K7+drq{f^-Mq)nKAz(P^NYdxfqC-G zlWFbjKm7mixzqqT#_GiPf$FWspU!x9##-gFkK3%g zYz)8q|M3C2<=>;zmj`h(C+7SyrI5UZaFo*3Bo(m<`N56$||2K!qdFS+*PclP-rkIosJ@GR{V*|V8pKtFR z#Zvy%QOOfSpdX$bcs^_hJR4pZm_HcM+w+L=n5SfwoRg;T%yn|A{@fL0JGXC*f#T@y ztU7o|`U}D3f&2EjVAlCp=Vt^zkfN}^?mRMQ-PP)+@^>J8ew`ce2i1njpG#*{-&)nR zeAqJt+A#TZX}!*wxbyFK8JJf2k}I;_({d%xmoK)8z5VQD*G+*t%DotKm*t+H zzGn*F@jM;c6+!t>@f`bkZFuDL-^6&je=wBoz9-?2Se2ibreD5^UCFfXjcwnLH=fO* zbp25v?=K4Y!LPARRS)D1fyVaIwV3|h5py|vNWgx&#xYlS(_-uVSN*$h#ha`R!8HC% z-|4+cz2Lh%sJzoXmYJ#L9I9=5s*dn(5A1XI%mw=cF=P*)-jtj;`*`I=lTUp1c@DaN zQihZ7S@6CzP@5+PYMD-PxGJE7+4?j9%?XLRpV@KGBAD>|-AO8K6wR-09qw22e*qJ>o zm{yzDXI}Ev<@e~Psaf}g8eFL^-R)JE&R*4}8ZCLwp*r`x)%rE}sI|4!s?WQ8t6EKW zS%>{~|87fvdtgrEgLph6a97kB7ssDS9IfqXU_U=%EKo`2fGYWP5hSoXOqy&_>zic`Zhl2gU2$^M!4A>bc}Dulthstx+qvr&fL!i+y_GNqyX30|TRnuf{4(MA=$6R>EI@rgSk|(BB zXU^N3Q(NbTYQ>{}AQ*Jg?j7uy^uF+C9e!`7U-z?e_eselr}}*GT&(Xr$Yk@Yvxkk= z%(3z1ZB8t_?-%d&nXmmN*BPz3+VA(I@7w0tXT8Q`;!{7zgwK9svG)HWW`B)8Ir3EnXDp6z9iekFoD|%HG8`SA1kWICEvQJHp!WZ4Wtr^$&Np{f9CxU(0uU;G{;q zN7Bjm&;0$89Tg8cKiTF=kGYSwId@3e`*WGQZ^mSAZ1d{n`x~!2sCb{;=G+Z6x3A5) zH)?K2=K5URe>8r7`~7J;w*+FNR>jfWxW1~!`@G@f8_I8VzR{CMX88DtZfmsG zo#S%?ay7YP-`T-WCLx{^Z{Bd{J3(A84UWpw$}@R=(T=N;W1cQ8KBc<~ZLHA3I!!1-XCd7oP=XU4tUetloo%5HhFzn;aj z_TlUIIk)!JyGPkDO())duNdIJBoM2s1M&^dMTYvYI^?PUivfzSXe^7THd&-8*>8}qeCR@{=4iG zUilcyimES|%hcpua;~k(1KZdm7C#^7`&xHz@tf=e;oTHky3|jt+w=6`lL4Rk5cbJC ziM)*CBzBe88`I}Q?<d~hIm zQDCoi_Ka;~}$ZRi91r#fGXoIj&ln#T%AMz486=fx6@Sds>}c zmHx*9c_2%^-#cZEO>txLd1qbdHNj~?)x<@u&pxuo{N%nba*Ka4W3_uqYfb#hS2kCC**%vro1Bf40(;o%-l*7oXcbxBHOOGs zhr>IBYQyBuJL_X_@qT0#-u_wf(J8$2{aWVxIE;N2*Yd6S#{PY51sQA*!~U5rz8_!1 z9=6n(^BfiHy3h3M4EKDQp4?%5ZCB3Jhv(jhf`dUyXYv`xJ@eAwl3-_WWpGrW*7^RC zfE~Xco2&l&dRdn>^6c>(F^1~{vR@KBHDE8_e@(fvFIi6s9{c~X_uc_^6;=HBow=Kk1R%%1bAZ5Fpef zu)N)U*?q7r@9n10k*1&$q=<-us3=H@m7*vpihzKKAkur2js``-{yv|Xd)}RQ_q~AS z`~Cg#`_0X{GjrOUIdf+2+_EnK=^t&7{*hPOa{Eo65zqecIwky+C7$EJm=`={i7x@L zFSKh6fc#v4s6&80{bLvh;t%m_02=xC0GtkBzgb=YpkGOI{mN?$ROQXtI@HSm^wFMx zr2xheZDV4ePXf@F{LVmpN&0XAWn_$|pj-;*0?^;INBm9Suufk0nm`kz4^o`gv6Xj9>=Q!nLZhg}Ak^W@=R{_{Q$DDoT_)rJi+ytPHsh76GoPIRg&9oZO z44_`}aV%&fzYk%ejm3P@1{%kcKIEDj=i3K3SrcU*R{%#p(-#s$E=^*Hc0URmghqR4 zALYbG>XJC2EwtOcwha$)?zK&9qz`3$_-vbr^1Ozz%62$5j2HHA0zhQxYgd+a@l$;4 zshcrFI%ABwX}{P@y7VhPrnJ!=Q`$j$m=*%&0;rqwCIMjLcrr1UF{OPHcl14NVLZz9 zr50tjH3oB1`pkB@7I6$|Fa06@p$)7L0+5e(u?@x%dDtiF6Q9UFKy-^O6Tw40l>1-P z7(ai89j;zChFseN@XFZIW{$1MvH$EF?WE4fwxg4ME++Sv?a0v<0{z1Hm3U!$k8ej# z{7o4jytG}~7aunOC$>Ma9bIu7IOfzx8=l;b9BtS;TxyjtTqW;ww;}8sg>p#JN`uV80pD;y>Y|e~ELiH>l?38)>}vmT_Po z(7Z`)IP*I4EI{~Z*H{4gnb1z*G<9)Z zqkk#GJ~Ax;xH>1H&RAhu2ykh%L)zN|Wy*?P6pfEvzlkp4b!~bsW)s_#{w+mWd?Ed! zuLws1SYny$7jxRlb&B>dC(!N+0Q<@7Pcc4Tvs^yL`ZE|b+A94co!6i;0At}<&}D1{ zFYy`2)8Ab4IWM>;qiusiAdY2OUzpQg&L!Fv02uSD0Q3j@K>eKSj9Ia96UuI^EkvEZ zNdPEAU$D&NUK_->KJcQOeVqv?1&HmmMQmn&Wsb*l^0BR2z(Bwa1;&{D6CW)`ne9mb z*jM%`P6x`^{b}tT34YoC(r)Uct&+1}tjqO}x$EywvT=K3K>u+573u@Wh4ciV(6|(n z|&GWAOzU|LR}+lS%6 zQ$PDae%=?A0ulhGggM)ISc zl)h1y+)HxK)B=3Kp9;)%nb+b2_K|&;KFPYpxMh;qT7)wDvJfy2K>h4j0>H%iz~s&g z+RDUOpdSwh(9ZZ+5zp9QVte8*jt}pn$^i5$$AyVJ^gVqlV@Mt*(&&RYjkd6l2>=tv zS_6oea@@!C0ewqd@%snvH|P(xOP}(dk8wE_z`n-)NguN<#ywLp-$`t{b7dy@O97l$ z9Q%s^^dW8Hnko0f@%hMkSBS3-c$t&5ll^0?xpUH$Baa*3wW!N{qTDXC+hY0)@q<0LHc&su>_{TfD%&M+9c11N zpj~WZIDq_O7yH6>g#If7(7(JE2tSI3KdxVNe;WPl*0X;V1ydWi~))^a*J)|JzWO@#9({e51C*$5>=q2%vt(PYZzK&i1*+ z(a&6aWjxpyi3{TCGulEvciiaDIG>E$2+%|y$CZAG^KyPrCw)RcalSr>0hTqC{r#je z&!+4a!FvEe433y#w|AOC$bnDl}>ZinhLsD$tF>GUGmAlLpkF#zL` z*8n&cgd+irOpZ5Wg*e9VRKN?6BaX3kCtxk03cxm8z8AN{7jKWc*k9sH0rcn5fOY`a zBJNjcJNqNN^(fOY+Y&EZu#O^jl(z{uBEeP-fqK0OP`? zO%7?u`q9K^^aDZkF$U-tjt70e3Q!H8ezqUyBc8ZI&)GQM5_cSLt}~1y^8YXP%^WLP zbLsa4fN8bOOwN9A3^@K``%IMCM~TBrQIjZ#_KGXoNC*%=d5l_Bj z0rvxr0Fd^-=nMNQw$eW75A9=}bDHBve=u<#lg1>n@&1xGE?cPoqQmVs=Lr4Ic%xtA z@g{L5^M!MVbBQ^9M4L7N=p)Vp>WKTDJ}#!e5I@*WjML|Z_Jo{&ObY>Qm-e>+*si;W zL)Co$%0AIfvCCc4mXZmHjzmE>CXcI;s^0J@yh}1H+3!oaJ?n4k6g1DW90zSX*1)Y4R8{GK4YI;+P`BH+onE| zXABi;zY2KTDC_LLD8Gc@m9=d!>a_qS{;dS*!yOG5zI&%fq&5do_SE;tRGzI1)e#X~O}GiAezN2}oz3IhL-CC8*QJ zseo7DEVe=W?*yy`&_438@6=I9mO81MI$r%0I)wK%@KV-ok2ceOY0K69`oE$3uiMcr z`v~@nZGX}}g8rsG>>vHW@n;`oE#}yh&bdUL@pT<2v&OpPMI8A!Hz@lA<`ivVyu);} zPKj^0#*6~46hIr^00V6xe+7VXR|XIq-$~LY@{{KP0Aq@E#w`2KHHo&$944N;=U}m6 zAIky6an4Y$4`AF9$DD04XWUX(0HD73HH^C026Y$O-*Mfie)^L`~xVQv(nA|oNI`wfV*8tdeCf*Y;HmRF^VSi~SOfr6{Mb7kA zfw3eHeMTOLnr|wp#~p9_Qu@KR-SPSv>by3|b6M&V-g=a22kjA@T-Vxw6aUj^To1@A z{UAJnMDMOnrh`y>3!CDwKi@$3WjAmof5>SHl5+BLHl3cvz=>CjyA4je@5f{Y$^lm$ZR8M1KRy^abrD2wwa_y~J_fsF8~f z`bEa^U}vluhtx+pp$kBJ2&VvOA8lbg9R{GzW&nLaJo_el9q}FK2W|K@80wIV4eVnA zz?3j&yPi-7`Q!a&{7L_57t5Rz%tr#|0O%Vg;bkAFs{$at;uulJrAJF* zm+gtZsVK8ATrW80s{qx2VtgRw?#ULSOkZ~bsFQt80GOyl0mcDp!ZNbFy#Ql}wo;Gm ze<!8uE|HdyS|8z9)bc4pW&r%Ikx1T#0nC9=i>SQ zh0s3Y*-!RQ#)^Ejg?+r;v4wc@i+^Q5P5Gq&_K!Sn|7er&&qSHy!M+|1=mBsnD8n&j zPF}f(Vp~FAj56hTtze&tXD+ee=JXX~JOD`hj8)20C+%i`DZ@T50dOqD&UnAX2J$gB zWsbF=%eMCP6CiV5)h{s zYG3?N0si>_jsyG8wq$J}jyAcza^*M%+~Vpk3NWKhZCo{~Ew~k^nHR2DmXd z4|V#4bAZ=1@uS2K<4$ny_^}Q8oqWdvq;2Aui03#{Zvx;0;&#wR(d~|#tXo_^DaWzq zHAUJiB*T8m{)}yM?6?-Oe@xW?>KX^A0dV{Xw39Y>0w}{dCG(W^1b~UQlSVxnAbJ?5 z1nObC9D8DjWB(GSh7%I|u+Ee$|6r849+d;gEAxl*U^Ji%Aah0LEomb{8poRB!$hC4 zKWu|`aEvKSpCtfHasP|I#J_Bxu}_^cwwq99JM0hpP5tyElk0QQMLNfai9V4&mZJQh z_OVcZ*w=V}fXc>c8{6Frz`k+5EDUprp9Jbm33HCtX~qrvzc1izbVy>n4fTJg z%xf{nsTRQTXvB4rIM!*~Qq&nMQojSwB{-HMN1I9GctpY?20DD4v(z;Yz{GJRj&c7E{Koj& z35Lr2V=U5cSrcZWTndo5qi>}@#nxf!Cl75Do;H-Fuk54fr@jC{|51kRkj^#met^uC z7L;i#W3&}OKI#;oQQrXo`lB4s4iFypKTdb`b8d5ulDKi_p&RdPo3=4lWgbfmz6)Qn z4ekS&=rfr!;ycDR`^i3$&TAU)RUm3~5>Ne%>Gyz~iu`@#>?3_c{dWS^0@z3Qx-%bj z>Lkyfp_6tk1r*|;AGud(2FN;CfinA52B2&)Jtu<(^`He+pnmqD znEwApb|Un0Z2uOH?cb5p2JVMwKmEp783SNHXpf8!c^Jp^C2{N*<6~>6<64v%TS1sp zA9eF@PMIjz1~?HwKaoz7>jUz{=K*=>6Y7>S{lk8I03|YKsINBUxdUq^`@uRBzx8$N z7otwv|4~H#=>pG%8B5eL2f&zSVodSc%C+pD(8ajsxQ|0#1E9Se$Gc!KZDt(MZ!&l3 zNAfHJxG~JWa4bk$=+LN#V=@*%e^B>xWI~GTrmb;#^3o1ho^~_E<++A3aeUY(+E)so z-#>(m*n21HYXPoK-v3Vm?$hdo`n-Npz9FXbAHb0>u9IWH6t|PS^eg!n0yy6Pg59zf zi`^B#L$w)4`t#<2b{`OLN5+b}r0?{LJ67&EQV(Os^-Cpi3Mc9RW`xp1cziT)3#OFDm>)_vit($rnXRg2HZ$9F7f7&sm{O&QGe0IaN?myK@ zdB&A%C*RE#^6#g$lk#!Dau568=%l=>lk00CeT)I7LhBso1J}2Ypo{(@&z*p^fGPmz zhgsX8xX@htG`hEKM>lQ$7<5?|rR_4{*%$7o#sO-=dM$FMX}HePUdqvae*DF;aP6-^ zoi=mMi5%ZqfHimRm%SaY!&JuWa21Y7`&3zu*AYJy#%sB>SP?3#mdd7b5GB)83>U0r#wtF zen4ho(9A8w2jiV>&}Ozro%Ffj#J{wizWOeJYc)aa<8yB&%2MuR)Lnm60Vn-({UJW0 zj672>4Ry>%1FjCPUF7F@xH>5ND2+p6IWEU|r5yX|%84$@a2;o2+bnX7*be(hIr4H| zG3R(mPT6=okjDEU(ypS@k)%(>;)LtHYn#}>wzn52!$D_zqX2C0)5ZzgDilBeD?H(>VPC?ofl zt}X7oV7q?UF8wdI%AAO|3zmLsIdQa^F~^}F2dD|l3i$#6*B!1ij4|5FdCGC7PfCDb znQh$(SPKXM^d0q8hh@>rzELmvx&Nj=mjdYj|F_m$`i|>FCm_DoFfcTF-k~vDhkcV@NiGCaqjwAg{+MNK`m#Fr;HgFzOMHxWaq(7z2Jy2$w zTnD60%1C@uW;H5YA85ls*dT3BL|w|R9nB%$ohO{{?se)Y)Q!oDFhI^DTJ zKXM+(yy5k+7WHxf0kFo1f=7a%VK z$ULDOd8jLHC;iNMIyjW)b%%*D0TWGP+=^}Vo!CZQf@e$-&vu4@kU-8vdpVDUk3Rk+ z`5j~O)GhMTj>G`>q%@g*r|rD{m4@{h$jL`vw1qgXRr{e#9@zv8A6l*0lhppN4Z->Sx93PlnGY8K>N{kt)T}uFU0M1YL zpR}Q%%|p(VFlUP&=EwxVyE3~Jk=fOe86V0}CEMAph|KPeOl?eNk0LU|9hsV#%!nc~ zBORG>F_}?CWcGAq7&r6*6Z^AQ5t+Rm8Lp46%;+LA`#3UVLm3&LF-2qoM~3n2j!$V3 znKDO)`*7E`@**-7j!Z>Nrm~34SVyKjCR0^JrrMF=oOW#+S45`9k>T3l`k=Om%=qod z)D@AbcVx!IY@1L-W}+j*Yo^>@IA9GT&6CtXD5 zct?hNIoGxmipaD(GK^o%`>yjGIV zJ^ot&rgA_tfH>YiaGoXrOoH=KP7r}4IPN_XL?8){ahD(h$(<*U<352rw3pXW%1RwY zbH9>CeiGma0ON}HZ5z-x?!P$x+_%Vm65C-v$jg3-{oLQjd08hf^)U9RN9;v0=MUN@ zvZV8!8WU}$f6oU<`^5d9ZlCYpn56v^P?q+6l-d4K0Q!J)S7<02S{riS=abH7EJEk_ zitYP3_+ozI{b2w;xYqd1{YLq4;COwfZt|5QFUH62a7;IXp%4%4qzz2;H?M!LUXF>_ zG8N@bP(s|b0Lrm#H&$ehP#5Dx`tSCWamIL{uc*t7A5=e8obY`v6URx~Y(|;-Dges> zY{PwCK@rmL1WXFc#wjRMPb$QTd?o5WfQf!$95XEdR0H7poUbS&I24QWb1Y7T4>=#H zUjvxLZu*mU7qZ3W<(feqO95`X)I-{+0yJ62gopbhSH1;xp)p=bb8*}kxcsQ*)>n}$ ziSZPYcX7P;h_}NyjkiPnj6?3VT$;oe$A;rV*#v+|Y$DB-aogt{ji-PI$uava50^70uI*HiKr(?yv=y0|A4T?v$#qT;eJ3p;{>N$Bkdj8w~x?{n%PC;9o@3cF9?U8HB zsYQ6WR?@$;NqkQkt|k`D^S%s_05DO9$Vg22z=>bU zPhExjK>Miklk5Xao_%beIw{Y4*g|%n{vX;+pP%8#7W4UMi}27U&iA-Y?0*8lRLEx< zc(#4!cJ#_#gZ_4X@SnCPV-%p>LgRBd@GvJgmTa>SU%by8PZ{$B%1qK{(j-pUXR)Ci zM>97nJ``=lQvgpWJp6(83=kVA$8lyN5BIp#%l@;>ab#Kcqm-vCukRy~^BP6{ zwE(6kaeqc0)+xvTtB58`{d=ghFH*lO_WmXvtFMgJXQR$>{T!6ijynO|_i}A41-Llw z1>-n*7exGE0PSGfGuF<~SlvgRx;buxkh2e>n>gy_b-=~ZFN|&C+_qlEJ-A!v@AtX& zU!X2+u^sAWn{hqgjLDtv$Wb5V;HG|Zy)n6#Sp8^65B*9#(hsqVdWq+~Rot%Wj{F`W zA9-Ehh+f8(iw{D6uFo!>>i~67U%b8DV)pw^`&>IHH?n}-J9zIW{o!7fd@|<+&*vP( zyL(xVH|-{#bk|PWO+4=bTs-Fl@v=vA$NTQs`^cZ8-UeRUz;8&Hs4ESKd}DD*9O`p6iaw&pPqEUn8F7@c_mL=L5%?^N@In$thu- zbmAoz7-OvS`3dv=!d!eReHVtM z1Jaf2?aU_ErcAT_SR+~ii9!vA0tMTRXjWNA@`P05`c!jhjj5WRS#on%M|U!lvX#`j z-ekKic6RkRwf0mt+tZfpv^3TnVrwP^7iS`Rh;UfCdV9Kidm7g#+k3;NTuft6S7Wv( zlkRM_`s1{w-nDB};Yh9R%5)_2+-=<1*tIrKMY^+xD96<~Hju(DrdnNwWK%Y;+S1}y zv%O7jwWGJ)t+u4syVcajZnui2yE1u*j;=iAYcny4_LexJE6>*UuGUEtU5!wf*W2v6 zOrDdvyEdfqOvt7?U3pa7+?dj%l)63RK;pK-KX*YVJ^=T3{%0*!-c$ zNB18J(BT=^@xa7}!t&(1-E#HASzVJGT$fpG`8e=(CVSHBQ~g^mh>s63nvV^!HPW3+ zPz_|^A*MVxHSBye#JQ%UVUAF_p^i|w;f_$bA&*eGVUJL`p^s3x;g3)f0ud$`1`#SA z3UP`P4h2cEkcfEPu!yj3Xhc}>I-wBZ^Ji;>x4I=HB7A?o4Jjae)Xg9pGQv-ir$pu1P&<*;5KOCmU|`pgO!L z+D`D=m78Y~Dz3{)=agkrsT1geehAmvZtQDZp0Mt+*h^)eO%~;vWH9+HIfGNY9_RWtU)HztzI^O5Bws$p! zm-h&n#Vr9g5sf{`ruMM4Op05drcFJm=G;hPZ*T6jtd2;$xi^zZVS|wBT%XQ#b#|a^ ziRsSuUAW`u$t0Uo*yQ$hI(rrFqteax-pz7{7;Jz;8$v`T)t*WsH1mzg5u;5?SJUy0 z>1<;Y?gme=Dv9Yy%B=({jL;=2vfel>0HzYIRroa%) zy;L5W-tO*g!iKG}Bh}L;7feJh`r-~GZ8F%5^^|Qc-H9Gz7s%}g1`LDP(k?eXmA=Xd~2i+#qs+Xll7I zl^QzI9lG7hx20ren>ypfYFmq|PCNQ(o6pCY)x)Avo!Q<@3Xz2VH8v-^lg;U#uz{9M zomgve)!_BEJssYb2-aR4`=N0&4?i_#H+3|1g?BC@fh`w9v?I-(qHSGB=x3v>nNS&q z8=|Z$)6z)Sn+4O#gLu&YsP+ zi#l7(Ee58>=7|f_>(g0YCYm-io|wvXZ60?}7jB|)zuU68Zh5k&8Tb96s`{12!Qn02>I5?GAkH;44Q`!1OSU+}cJl;F)9XxDAV!6*Lhj?Xp-o^_t zB$my?*N}hK79;BI>*#IiYQzSft5af2wRr?r-+^}#e^^*Ek53xw8QEcxYu`AF#h!h< zEzR%h>FMf7j9Z53R^O5AZm2P(H0EBz1XIM7s>R&!HcX7_W<%Xj7a}se`ZkO=HM{UN zT$M=JI+h;nZ7qqiHBDt}ddk*x zmaWN@tyxpHrmA`Y99!SqmPzcp(yZV08LUn{NnGB{!-pv$HV@e#tZ9VBM#DELL`9gO zHbl`^Ql_(NLOi^cV4T;_M+luTeKI1VeqwD)YW<|3x?$qP>2;GD>LyMemq^sC?8@}i zC+Yaaq~-PjNWFbBf(`EEe2nQtjw|<=WN?kJ;Xc4Vq?{SRf~?^W5T`-c+MtP(C7Vbf zEO%{8o44{xI@?VTR-p9X~0g{TaZi9RYsa>^z`E!K0({dinGr-uS2 zx|=QKm?qKulsSuV2*B-Lok%a{=B|U~x%haG_d; ztz>;}$xCb*XFG=_z)LTkGT%JnuIB|L7eI3&WFfcIgk;P_DKh#?D}&N9995-NgU6Zu z(%P9pQ?ez%EeEbkT`(occBh)tYtz{0q8?OF9EUZtaZAW;7NraJFROz5!Q5{_z8fCI zl_--6Qk^XfYI`Regpq#Sap0a3q&xfJCyfu1JpmWmptHB5DU}JPi%!~v6#$nDUSNXC z!PP6R)_ObN?ZP}Wz{5oI_C_cigzOG6tnXzLi)| zT3vJ$KyLy1KShdv~QdK40=0H=1@C&7~|Bc&RU*OZu_huQ`lB@fR^!Z zNa-o1Czqa76IOv3JF62uno~6|(^@}2*;37Xe|X6hR`zstCn_o@Hf+QWsug!9^|@J{ zh!%Tn8EjH~&5HDgdCuzXjX%`v^)VgrTu?3<4svosO~g^U5wC8a^z=SWht}#5_b;BJ z2mI~BKj?u!IN$+YvGH4X>3x3JzC>3Z*7~U4ee{KQ>+xTIcY~fd_0EfQ)wJ4o^@u?i z4%Ygd14rtai*G$y?|R|m`)lvvo@Tx4s^5H554d#91U+ZxhmY2Ko^fY`o-=TLr{3w! zFPx*RzSdNx=RWt7EA@_ZH$JCF?X=f9dd7pZf35eq{EUnBu$H@)>8W?kJw=z_xN?Qw zVcYvh>q(<`JXKe`deEu5YLUo>0mWq-I? zk9xarZ#~4{cAYN!>)rKww=dT>=v_8_=}BE(a@8{3&^7CJJ?zaTqx9&1&U#eWJo5Dw zdfMB6ZqqZGPMfL+c8&bC-tn|cPfQH1Iud(<`sH{LIy2zw5?oiBPe@@|axOL4A*aR} zK3;~n&oukWMF~V-<;1BQE3?xUV@J#t1v{IrZtUZ5L&ueCN<_6Azd;XHKvf?{V7gC30pk zaXCo_6gFVZ%H)2DV-mqc;M&#)4Rcnnu1p?tOyZa=5SwR*RE4Yeblj+Pw&3Xq@1in%7Kp8VvbViwVw?~m@Sugawl&Rs z#L(EYsXH~MiZ5J4 zMNr^Q#yp@fcf*sZs?FSqXM4N5vExj&OqtM|%}l`Ks$}~FsG5L6M|<^(1@o3KTeft5 zRhUn6xUeU;T<};~bMxTktu zT)cGIqQ(`A7q47&SmXSqhpn7FbqdjkE?RWZVTaB;=&+!nuAMhusccZ!-ffK?TxVMN z)GBJ)TY|bw5Y%-Ap@+-sx?2YyV6-%0_uHO=z3sU9;q=L3Ku`zT-u+?6+zqp{Fu-`K ztFwI*c7yOxHb*Lls{f_F@!XkBnlWR>QMf0_RhCYiG$~hEF>&J5TxH(GiPLhGqg}RD z6DLi~QI=1f)R3zj1hxvyopeQd^7N@yVTg?F;LGrhWyx$=eOFmM&dKunY}eR+bG@2z zfhcXQOxEL0V!TxA5n~DLRd5S~m5J9T{3{L0>Xrq;mU=sB&6GmZUhnFepkrKw(JhqK zwU;9TD>}04n`^N_%QTC!S)48b!!wxB*@ce{x`GL?fx56csauMFr2($?L0u>kstvGp zuqzcW%z^0wMz*^&QC1ry##T1-IzHE2pmB}vX-i=Pi5CRCP$#h$?BD~4`oX2b!219) zg?rA3Wv1Z>Zv~*KCB?YMQ`?sM!AlHHo;wH0?ruDdwHsY<;+ZSoM~olRk=)dT=DV+S5#q8Izw4)!+Hbtlno2AjMbZE!g* zP}mco0ont4 z9xSvaXyTSC6^KXc2T!%e;n7rz1BNXdt^z>@j}$YVS?nA$yvTA3hxh2b_cdLvA2)aw z_t4p%O;~jUu1@&a0u5xXPtDkvuGSfka9hpcXzj&Sg=VfXt=b1>^oFb+FfSP#w;|or zR>iGl=<@MHnsE2s*%ho!r`oxpgsP@4+!1a-k9eDJ`qYJIBYcQhj|=nQ<4gmgzat~i z)Y?q471xUTAxnD#;~w4(!PlvcZRi1?^#vQ+Qk}e;f%|*;;Mlf^+c`AX(`5%e4D9W- zP(E`=FnFSIw|VJ6FW46eRv{m*WzsEZD;yQ`!AfZ`IG{@+Y8a+j-VYg;`dTWrs)8+( z>@tDZ8J%b$izU5;C}^@#4A>&+6-k!(o?_T^5HMvv2Y zj@-Tp12##z+LD5=GYHnnREPIsJ@}kXoZcW@ydP{%cO&YiBAW1$2!Wcz;n8&c>@s0Z z!c07z4eV1KhY6ONQ|Uc^Tt*~GL3 z2vpo4VQaUvlR=AesolkyL?lG19={Mr0m*8%vuaAGPTLMm&2IHGk zf~U_h_d>Cgk3UoJ@#hSK00U4OWJ){aespa|)S39llQ!|sAebcQXSI^}2`rj2X&^q1 z{WM4a7D5FDGq;6;4F5l}s0a9T(L7-^917*AW`*MQqN@I5g0i8=V2vmKRSn~J2b}r8 z!!l~^*>WQ(;J$3zu+GTl^>#nmgkAe9GE0OWRB2`gEMz)AIjK8b^-n znN98}3r@yP>i_$EM-SV5q(n779!+)QV{1GoICObgWpaGDvg0m3QD0?N_nE;}iFv_f zzJW2%BC%sn*HxxxChGYhgGai8C*C}yE3=7u?Bathf!CKPC{z{%6^Z&FC`;g>XHZri z;5@dGPre$T9m@wFL0NU#csy>yeS87I(%}nxoqalTQ--iJ|>Z1@yE6})?5`c<+x25YxjSp<4UUq zh%Uzm9jqG`JWoJhh5XIU)iv12U^iPc*6!9z=N7^RuI$`Wa|8jcAe7dY)|J)Om)4Zd zE}exZ%w3tXlTR)kTQ+uV+05ApopQW%uQYEF!^+r|<{g!*6!xKS)p$2XY-JPPt9L>Y zFRra5Ew=Sgxb&FP)p#s=5~1wmW6D;a{PhHJLD`&B%1)Yv>v745L_kw>W|A8mUrAVg zal)3wJid{+isyNSdS3_^T%5Q$fq_UM(ze%qbO|1E-UxHl*wM`vx7oZBz9@0gJmbTf z=np99HBP)>ta07ssMwH0PC|)%)l2YPj&Bo19)6?mA{mNXMUb`y2$Lr#ySaLPy47f@ z3au!u3rbJLDX_K<@>I8{n6y&9QYA_aP->u3J18|ssliGOQR*{F?WEMsN)1(Nm{Pka zwX0IQDYd&&dnh$rsS!$zRBBX0sXdk2OR2q;8m-hAr2?f&l`2!JT&W7BDwP_mRFzWI zO4TbhL8&Q9?W@#OrKTx0U8xyL%~WbXrDiELTdBE9LFYWB<}0;8sf9`{QfjeM`zy6n zsRNWcP^slg9i-I3N*$uqp-Qb(>M*4aSLz6*j#TO>rH)o=l~SvfTBFplN;N8VoKi`p znv`l*szs@_O0_E0rc_#~4uQMhy7VXy0fSNJIPO1&~175K}=z3^9l)#j+e-|yAo7#AM(_**jfXz(VR zV+#HcYWJ9mzonjrV>*r*IA-Fg$sO~tQ|GY=|HIf~{NibJ><`E8kH3@K4}X_fj{iGu zZyX1jt@j}ORayRVh5_sK^Z ze+k-wqaDZYIQGENiT|Z@o!8y(=)(Vc-G%=>xYr!xakG`du^#^?_i!(ZV-tS;d<=fw z=|ucu)=Bs^?NjgzD0A^wb-Q_|=8n_w%g?8O;&B#!pZaVZXW}>)$LDZ-7RNa_7T}nO zVSM!{{$R6;W*hG`{1u{ z7vh+NW3Y1^g%59r;TO)1_7XT|;~0zMFdWC>SY>{1$=(N;39m8T<=~x#&Vk%x62tN! zvlMWmvqnzdm$1wQW1u;gnEC*eiQ~Bh6mkv7X|Z~F+u$2&wA@%ZD`}-{OC?4R+q12) zZQl2mggV70O4|EdYlpRhcJRKJ`~%FrZ3&h&g%azuA?gJkW81L0NSFRHSE$(qlC~0P z8$D$2%B-(gwjN@8)Ms0_cH4Fb13SpjNH2b{6)wX&fJgdcTeDVM@3X&bLk{ZW!cF_E zg*LZVQJ%WQa;t;-ERG&w$$F9U)(dtFrO(n=a@xL#AJ_^tuuXf2F4{-itnJp9EVCsh ztBWx+(0E58j5!Z0$?>$U+p(iZt;LqEOkKv;_Dd`he{ozm{?sqyq~rfGM9de z)lw&)dsyG`Y_a73G>7op-sQ_neok06W;s4@vpD{mZR~} z(BH$_VDEaAo&@G8@B8XH^_+Unih6$qo_{&M{ZtLEDr|RPpEq888{3~ZQ7)dgdRG|w z@67pa!}tQqzfiZUpCkXJx<%clZc2 zFz2z}Pt;Gx=I|HiN_N&fqWJ4UZkppgqn=Vvs%O#W(`qN|g8BOZOfTBZ z{O!Ii@)suD)T4SKb*W=5UOt#qlf#WgsWewB%ax|0v~R9vrFKI7Gr04yHU7@Wp4e0I zcLm(^ckgegzU#e%Uk-ZHC3pjHA4SC8IFH8N&Gn_949BFEY=5SIt16nUvn?l_eBhQBA^Q_0a5!g@e67pzuleYtICvpFtlbY=Cb~|Mj8*~4| zJZtUP*)koeex-hG@IIQ8Jp5SDD+^S+G2(Wa8Zxy4Ij zXPgO%_^SaY-4RM2gFEqsVfhj-5ppCQy=R&KIfsP9aChN(XR9xOdYZ%WC3T@w`vvyx zN16YTh%%DaOCgp&rp^E+dKYv){-2*y4bPdl^KVrrL-Wr~{TSTIHQ~-=6KcFu+F-Ew zzmM>|0l!*`hY-tf2lPer{~cM0khs>k)a z-u`-lzEmyL$9O&-*c_^F)NksY^a-lYzezvmHR~;Ui}wSs6^}+H`#0-bbd|2w-_z5) zulhUd4*$n`sD4ZTLA|3_`)m9g{lO(K`j_De&~)#0b&me4dJPXg_Ea=U=7nV)Y(|_)_cFhGojJyXK>{NeYd_#U+&-T{lfc= z{;j@8ea(MD|HYrAI{k-mnY&LNr%U|5>A&l(y2oGZ|I|mk8AW#)XUKN z5-d4Y@u18ISa&50VVc;tT5|<#h5n^_jdy0<>H0K%i5_43yc$xou;!_;L-jY*ZTe;P zBseYu;L2vKvNEtG+`|Q!CJqU3|(O2Ps-XFWjlGG<~W8z94!qx7LZ!?a*+jy#KBh*P$2 zhxtpv@vyp5?di`}6ZivKCT$&kWA(wX5dW8szrY{lkFULG?5Q<7n|>YY4@N%NAF8J@#J zYRtHEVcWjYux-y)Y!Sw=)OWn!i@ecat}a)5p!B->v$0}#bN-v22mhb1oBV0eY%NlC zJJs)0|4iLqeO32N-RPa|F;E@iAL5VRc_1FdK2yi5#39Dc8><)kSLVgtGj$KE(~O^H z_$T=Xpk?+gK-=84RH3D<80Q-QEQ2AI`+7-sT=APR{EA*)~JQ!oA*1Xnt zBfPW~BezYT3u`}cv* z^S+1k@qLf^JQ&F~4TRK<)nE26f($V~0wDHb?{d`%-ApouQp4R_-PX}<{x?7m{LArp z{9^wBXnb(o*3mEO$Ms`@z9_Acl+J~ZifFN z&ObNQU*r5+j1KokD@rtD;WE?e@USPm zqF|rE6Ru1=p9WjEj(*mE*I0jJ_0IlG|2_ZKx(l$%;7$ShniQW246PtHQ&~w>34K&k zQd@Fk_0W=?y*DBI7Dn=Uqk~ro>H8qP$S;KtEA&9Ux8CNzZ8&ySLo1@y6u*WBj&;z? zxqhMHcozO14I3-aZzWrN>!A_b?YR*taBA7P0Mh%mLGrd+hI35C>H@YiB4<<-(r}^~F&nYVv^-EE z=b0l`4!n4e5B3aMpB|JJVf&ohTw zy^JJ)<&9PhvdhU?j6)^pDIZ_p9}P z;PUa_`Aic^8sHt9Y$VA8qA?h&W9lqrzq0-wz!DC>UGRy%8-(}jC*<0Ywhjp~D(5Ak zxcS$@eiHZk@H_XY7=G^X3tWc(usp)d#xC^GO`Ov|^M2#q5)eD1WCCoQmGjS;xf#p{ z2p^QJ0(E&QHi`ot$9do&%4BhVX3)|C!*Z{hiaF7<54o7W67$xqt}z zaO1nWa3sZpdzjd}ckhuMch85g(yOlu3DOTZF$Sh{{pv#L`nB8^ujTv87vJ z$+da?;{%8PJWb8bG~6vCjZ|xj*xSF2D-7x;jL<~mHC%2-Wkx+Rsz0Y-PSH{t2Pyn# zEQ;qXX1ZEmUy-wil)}k+=V>E*?LO(e@uLJ|tAF|sn#=vq6zJW=k~@qw{bgq7A~d31 zxA)z-NQ$`l1o0G zp&t3z^FGATzwf6J%uL_6&e3O=Z0(!dx1ayqwts!}uf8vqG{T90)&JV|eBWEfo!5lH z_7?cJe)M|Z$J^3$l}4`B0Ms=(c2xL#2k%B zrx`@UC{>EDZw~ePyo=N(JVrY}?X5@ZWq5eJT=8RzoAIU3HQx8|Anmi>U_78WS|6`# zbi4X79(}Czeu~#%`{`eLN9rGW@9DYz+xlL0ls+6c*kd63b^kq_cY~ha;1&L@>Ur;* z{>$E<^uN51@Z#Ygc(D5~{cZh`?$#gZYrI-LM?Z-VeRjbshK1@^-mkqM`i)BKr&Wh; zz>9|^-no7jpO_ry{T`dzNsDJ*M9G|K=a7>is3?(}&&*>Lve0JYxKjccGr<&xXdAA-kV{nSU6*v#Ro^s?Ymd z)ywei6Dk4BvuX$baCM{({3Fy({s(wKdL-;UQvXZ6s*dr$sqe?*qM;?X`+mtxeUa8B zuuwJNQEwU#uU|GJ@v=J7SN=*o!2A+!dr#93=;yswf3*H99=q&aGEfikW{0ou_EYox zx6tabcuDh|9?R6@Uj55q>_#zK9QCr!dfG1o$J_dCHBXn6jKxi#(r<$E zZS{`2Pml55Qa#=!{&oK8`Vj92{yvDmhY%m1Df!Uf2NtZuCoOk)`>CV#k^X*)9}$i5 zHs~I-KU}@)9p%5N@X?1q&fm>HO79N(27jZ!yZSBq^*Uasz2{HVN9y0}w>2$21lCPL zD{r8*7hYiO;I-*q*fmG>=yhs;Z;m=w?d|_upQumLC+pvOr|47l#h~n~r|OsVTlk9Y zP49L+0M@L#OfwtLs%tzvI85*5M&oBRugo zp0$ot?|7H`AA1MtWqPH)%XgdYL!SN$LRqYyD86+c-?gX5R} zOx5HcsWec#&=51dxQ$Mo+X{pb9Vs#5<3 zv-=4BJ$(MNSiSFkULB#Y^^d?9JdXMV|00a#6rF@sUEa<9D0Qm$IlK;8=lw*V;SKd~ zSBH7ErtRnbS~XVx0 z6;3(`udn7yS%8QRn^6 zKN&H3j9%%#<4u77>hKcuN9r*D$M{U3O`qsz{S}bi6_3o1(XZ>j!}~jwWc-iRac0Kb zXg}6O{j2y;GmHONa#!^w%-IY5di7=h5qM#Yp1^1WPnjy!E8qpL3|uF6!<&fD)8TB@38TE7H^|5$uNsk@o zd+OVMLZ7D}^;2p$_;Dm2%ioGvxEl{4&eH?bc{+p8-DTKaKYz_ri}u z5m~qC-PCyRI{08WwTte?2W9p{z14{N9dwsB4C6mVouSv@N@ZH82>f!(i$9ZshiQ}ppskg((Yi4_&>0+^@3_Y_?xG0^(gf% zP_73oMIYAT^MD1on$)3u2spouPZO5HqQz?0l9kYSIKHik?OlT!qw4$mdfWll;^pzvp!MR~ zdjtOS%k#Y(^eVL)U*paM_HuJRUUlH(h)&4thEHg^fa}Ki+tJu;@`K^!I`0DLo#DOW z@e3V(u<uOevZ--JluaoJqo!hJfMFbbKyB~^J7Uy z0zZDq;Cu+|dtdz>BiRKFyJD0^=uvu4y_eoc&+zK?4Oo@3Y8uKj^kB$a|IX60buX^j z^MUU+?Jw2mc?apW`Z|2*(d(u4=Ri3@x8vNUH|n#Ie?f27U({D)gf7vS;?>9mc;zdI zf-CjGDp23iL-g--pdM5Y;ruY*Y5k0T7I^@PS766K_4E24c%iaQ5Ar|OeW3Vw4Z_bN z)~gL_BVPHRs7_KRt5fju>NLFQJwts~ovF@JXRC9d;dAisXZ#^}l=igR#jo{;`y>1s z|6 z5F;;R6}!fJRXqSNEy1i>g5woj|9ZXG5Y4^l&s@FL`z~hV5_L7M^{Rw1FdgG|n>q{D zovGi~2m6!J*Dmj8>Pi1P^{!rm53+i_DgGq?1-uCO1M15W7jNNnuyawq39G@Eyf5R; z=w*7F`Wh(q7-QP5)64x`N>+F`cn9b!@RHy7q@*l%ZeYa)su13qNP3td&l<`L94$S`Rls%6}jwedM*plV& zJYv}%{*DvC+8u_|KDFufzF{c0c{ z2aP7How%`(qBU}6bdfq&JwS3U%{BH|tKDZwb0E)Ty>Kw(NPWP-1Be6SA22vtO+2HE z6qci8F~sq8s_hkPqoM!mP_EQ3L&Qds?V!DjXzdPdpf;ge?Y6eUG_wLU+urqIP7HB8 zONp&}-U{!t{tBE0OWY1Qd8?1ODE%2Wd{?iAwj+F=nN}lurDStTu7*#(4{oc4ysHs6 zq~D=_;@@dL*deW69d7iIVw07yXX_`n=9v#3so^x-ci~kNpcgu=41L7%1VvhYqL-y@ zOZkR>C2n@#HSIoN`Nm4J%PZK+V5yjJFJjIupEPfCSzO2jF|F%d6$oX6H9 zS<5GN$;tIf0X?LP=7`sp3f0L={ELVH9!yd$miOl{Vxi>rHAJ$OPwJAh&6f&TLb_;< zcx|ar-7p)O*YMnh2a}YG<^4IV9*f_;hDg@(NnLWb`C$P|NEgi!uPqg-8)hT(3U-)0 zn50}R@6TcNSp4=iM6#Ao>XNg~j|x~qx@eAgZK+V*Fhl00@L*la#q$0fR*S`NUqd8o z`J^s6+w3zImgk*!W*xXgYv>_^N$b#_Q0-hy9f2fIf!E-Uh+7Ptw*w!PwJAB>!|{INEgk*8?TeY zT3~ru>&qSZ6Z!2P)E4I;j){25<2<$=$yz?COHQsE3+N$TGz)LMP7Z5<<+UZKJ zA`!{O>5(qWh4ZK0%{ew{HHQdo6kfK(6zPfT7XK)ogYd8^Dhoc!$r05=B9e>KBVCrq zJyTjVL^^NDu~@or5KS&=-`3@9x!kkW{b$b}i9{q9r$@Rhk9(%HXoz(FD#v2! z!a+2-q}y)L`aCXpAl@#`E9X;$YS zJo}8%)*_u^5BZqn%x8?Y_5=K#1P_}Y%asKm<&T3Us)>Y^6AdoimP5s{jMAbZlDRv_ zW$D5}v~59nMLN=Bc}0TxufoGBwKbLnALVhZm9S@W^`{Hg%%FCr4BhiAXM=E;UP!pD8UG zBAs{T*eqQ*h$dImzA##xrAKG-{U$str>(Ip_$ZHKt%N<3E1xbkOOKz)Es+~HI@Y*<#DW)uxE1R)1_wV@iVz4@}d@gmt(VZ;UL9M>b!Thf9u)Ma$vf!gUjsCs*g&xOBJ<6?aTelI&7VgL~xOCxi?GeU^PqYX(_ulrfn5fKB zM76d4b!j1=9>+>O%B^l&w-HDU_v9E{x^TJn2xG)2T7>(ThyWfoMP-Y#^?a=0L^pHG zZFA8TVO>sJCJ*8MFpu*J-E#A6TZp$E@v&reN`40-fQL;{+2U+HA1k;}#AKG+%hP3R z5!dgdqG|7rux@kFV3EXGyse8aa`BMF5+VO=Yxf`mc-Rz`EzZ{Sv4RUlOlG<9`E#gi zm?B!RE~hQCy{Jv%@_AjlNLZY-AXw3Jj~Rb^ChmT7kc%aIwm8wdGPZ9mT5L2$K zj&jp0o^46;`@?!9DHQ6r5VeqRkKl#x_eR2=@rT-|*@*Z(@^Zzq9F(+Wo3l-88_$u{ zP-8Xz{>n%*CnwJYCY%30mlH?LLJ@7mOR{v=7E&lf7>2gwY;zkC!|>ylGXc>7HgNN> zIoq_h@f=A#LPn$+A@2-hKhFe9;dvN-;L_&yObx!<9ywe-=(oo(W7gm&l7Gg(BK4w>`6EXW0OfBKn_l$o^b85(-vA@_b&QMf_2_E+_d24>@OBvk~zSC`>%FEHzt_ zx?wS=i2iU6*`F&%LcvN%p3f_^h(BuAb( zY((4!3KP#PyETh3^UC6b({}Xrwb)jL-#Vb63Ov!`_3f+WNZA_49+SOAJZkw6tyRiH>ow$trwwqsi|E!#?D8%dmWC*2ui zCR_K6lXj;QXF3x*o|$yKbeuTu>4_(?vw70lU472I@BQ~{Aqi5Fm$ZKY|G$6VefQma z-+lY?6;t7jWFm#FLXSA4%BRXicePCP|70Dfmw~5iWEtYU@PDuT^o{g*S-Vg_h3Q=( z*5AS`hJ&vG4g1ze7VD=^i>tB_7M5jal>VPIoYJ=_|3&P@pe#lBn0ZGXQ?Q}`fJ=8nixufE>a^F-Aa?sf_ZnC8iKe? zf3*Tfh3lRPr@!UY`EG?De@g8#a4yS_7?%w_x=5E#{?x5^g*Z&b(im+x<%*bdChQss zOt{8vG1r)ww#rk(sUJhE!A~#c!p803#@kS_oL-jn&*Pr=NrBd&m%e{heAMlH6kp#j zBHWs)a0*vydD#`<%9xatF*XM7lVA*Al^^4#i@tf^l`(w(r0_wwjhlFG%{r+t{js-6 ze)?vq6|f76RMd|yz0MeHXE%fw%xZgUPZL2{T`6C^B3>ye1=0(@*Sjr*c*>0p$@HIt z70e;_f>?w4%o&>2Pbu)O5QfvW{JhU$|Eylto-C$988WGj~d22HKTAKE$DBM503daM##=92> zGTZBZI9_XC@Z{QjehA?~xL=0@S0Bc4cvjgMCJV&AEiAcZs6<)d=}M!jQc5-?o71g8zT8%uEZrV@BJl)&rUemnEe}V_9sB)v|ofUutUHOqSoko>lBS5 z^HYBZS63K&I7F$QnvFqi(E3{{j*hyle|0Du_VIvUh2Y3RA>=+maS*)la*(rv!%tu6 z#Srv$kU^XwYcKlpjlPbC_2tvzDyCA$nm3>C)(YrWOhRl3;_f$8&jMF}f(j@vaqHy!vp7LRe~uq|GyQpII8y(t*&nBH`q7urJtp@3 z*kik2?1p~7Eg|XR^|=6!173x)-bwv)2uFN{Xw1V1{oDSKaJ^rAhH*b&xKf(-?!u9` zy%vn;<9Ofi>z!bWNr=856kl3_`qAfcz^q*m>mXuwz6bq5`0}nWOB2V4BdiT)V~}Xz z^EmM7kK^WrD~GA!>^tM8`vDDz^yj72NP~WiL*abiCm7^MY3%m~;Je?zaUK!;HSPhp z7;Ya&6@TAtiXlS82EV}cRhd* zeW-uwN4WLnr-|Iv8o)h)SNkd+(_i6A$JV`TtKxHUKOh#fR_=`VfvPwxe4~W6RzRLK z4hv!2Ywzx!* zLPX>4mGq}CsW1dT*Tsu=;V#BaI5FwNPiry689x~yDHXzr>EL{KJ%^O|BysN%YC&+k zGj0tRj$Qfjkp6mU+%5)%_aJ0zKuoF7ho2*Ja3U~nUi586+l!wLbJXa=tIPXJq}7ZO z5%d3xaEypo7eev_XT1IxXO{5DEgQpEBV95^r0;Use`vV-iO{UZJk=y;c?+sw>{#3Ryl3i=r$a#>pce_WAZnyQi{nQz>$$KHjXQj|y`0*f z!3D%=c_FX-uk9Hql&Kc(r!iDx3#3nV&*0YmG|OM7>AAQ(X8UQR$}9CM^jvPnpV~cR zUV;Dj(SeUlkiReZ@5jBKKWF#E<)wD7?#6leK|c%c3+D4O%)>mJ;dPQW34f(YBU`?a zC+6W*IM>YaO% znt#%}bzWdxwO4(bs{KsC-oho6hC6~!p|V`e;m(h7O(NfoiFC*Pivj6N#%0(9|A&hlIXk$!OQE<1hKC#4D8Sr*veNR-Q ztBm*!OR)%jBt4$lq%8=ABC1uHGuZuy*OCc?3$XU@6Q z98&4pkW5v}Z#bll-Rf808SBkcm3S&C&YQ2Q?UVv*JC*beVo7016(f9q2VShCgoo{x z?@qr;e8j4uzayzt#pBaG=uf7PwJtiL{2c%vrg+VoT`hil(0#HOb! z85|8Q8LVy@Lo3d+3a>xlc~<0#mn)IOy8X}ap>BWOR~urAe**K{ZhleMFpz?q8&s}- z5A*$Y#^Te6_t!-O`~)`R`lM)r;n+IS>x)98124aif3+^-Wj+F_mi;9FZHn8ta87vD z>IZOWEqUi2uFNp}T$qdnZ(fbp1#1 zU|jzZI}iR3Jbw%S&c)K6pg<3eRqys$)eeH?u#o8yNNON(5DXazZq zIOM|et+Ls;NUJ(7Vyi@|N1P@V(9*b+Rwyn8F_+RxM)lR{ajAS;I`;Vma}tBq!7myQ z^3Bs3sxRfc7HUs#_yRtMcwIv2xeo8E3e5hUy&MJh@2cameJMg+|IUR_8owCmTl;rb z-*=;b_nS7F;HiBntM348()K5X){XS-u&s^=S-QSy7r$oG>*En;x4#3sa2NIc%f=2I zpVsoN4HDn+Nm|t<@^AUS68Si&IJ;m7wP#%)@XL{Z7tzubGdA?ZRbL{1LiqgmIMZGI zZK+Qhj03p>u1iKLAtEKR#=&u_NF`RFRR?g7+?FG%`D9Js#Ae@}GETkR|FML^s9Rp5C9xF>LI ze$iWwFj@cKBg|ENEt?fCaW45k6kXvj_mBIX-X$F1J|kHFIAGPgr_F@e-il@E-7g6JKik8SiHz`!M7=jPLq>Ec!-#mHH>VzxIC)$$81&1m1r! zG7x2`)qV~%Jn;HD97eng-x7Yr&qY@GqmdKXAd-jc4 zei{b=kNL~-MMMwjv&lanJ%Pj6pNkCm_ln7mL8fETlfEp_fHp_K`AJCf6{O0;{wE_p z34MJfG79Uu3kMpX^xpo|X^(lGu(T(k`{nqs=w~6@ zD2{lJf&Y`B`tAsi^ zkg5>riA;GPHJ0`Oa6N>296q1)|M%!Uu(Z|q9`VPSF=1)bkp2OD)%+I#;RjHOy%M(b zP~_JE`C>E*d;A1oV>tN!0Z8{e^!j?}c?^dicSlwL+Jr;r&tf^u{m^R`yzhc_{UKnd z{bPprG2#6rEG>maktg7ji8RGlNNQ5|Yaq#L@IDHk75G-|0DLC=Rj`|^e*n4ZL}W#5 z05J}GN0Ab({@sz4I9z%KaDfwfJUS(oHjVdBME?-{J_J8?S}`_;dof8}pAvI>8fCEs_PN9XNLX z7(OGxT=GJ60BJjbS+sIExc0@Z7`x#(8i4gdFPvl`g5+!!l z|5&60hfLoay)W7Z_a5-yf|Q&>d8=jB5b!raA6f8w0BJM^3pxRNCm*|DK~YHf3`#ii zzYFe|_^d!#a=_m$Rz?Z>0l&|$L{`9pz7jbM$qylA??D)T;N;_=-r>Iq?gtUeG~WIW zQk+7p{dm9NpNy`IM)8@Ak4Z`TAoA=fSlWy~1=ud1ylXCL6-(=f<@MqSaD>JGWBA`5 z{Sh3}-w(Q5asRsi252G+oGj#70|>i4{r*P0p8!?jY>ck;*WtkTetg=2dRzs5{uFYr z^s@e6$|A0;{~w|c0s5rqaUb;i4IHA!lw1v4AteubybG3=^)E#yqTe6=RnU*Z2Vbm| zG*b(@1j~B_TKD{N^kLjj_|L$92$r%1xSjrsD5d@uKKwldUShCD41FVxhoPHOxL-%E zX2|;xa~knc>yJVQd+|Pn5=+x@2L3G19>krcXcXzV7A52g)Ghy8^eXIaCBmKe$Nhg3 zok5<_^qm3^9;pASNXhc~N&m~y-FQClt@J;Ga&!tMn8xsce^^2t2mU!J@rtmt32?!$ zPhZ6sfOjGW%JeamZp&gUi&xPXwaZ^YO2(J~Kg(mUjeSpSHDZYQzb54%ZR;dL68|1( zXbWUH09solzw{%_$Du)n=l?y>%EwR+eA4IQxnW6-2Y@-{{|Rb}X}m}Aagu&m&}aRx z;^6fAaDcgI%BtgHK^4TD1+5j($qpoz9@2l0SQ<;Eufy+QaLycb%G5bgz#f65cSF0Y zA!7_2vkbov7SxOUw<@v*=|mg657xz6jn?=Obg~O_oPcCegrkhB@oA7glqowPV-zKK zw<&8@0rL@KTO)|~G{TI5;#tJX8gUhVQ+Qtu8P9?u?T~c$AWgU6jlZn_M5F^2bT87; zgI^RMy@^TwBtLP1tj7HwSPJN%6w87Gl(eAI3VBvzBk3ytlhOd!4kx$MhC7kJBh6Pf zgrD@k;JpMpJcm&CfcMqlhQI#`?XHG(&Oo~}h-VMz-wzpf0PEwhv@uxZM=EoC#IOqG z(je{!kdB|jXHF>F9^6;KekozZ|7+3i_W-&Y9GpN5C!o=$$P~ljLnEw__e%^15NZ^7 z52557ftxxdhok<($fb`&z7F0_AvDYF?#MB*Am%OV0c8cO;9=;MlJ?`tvZfy~JnMZ3 zpLhB*dk;ous8O0wKCD9duhu&a?oRu2{^uiTWTVCNbNFCF z0rl3De>nPoMyC-&rSdz`3hoK~w?t;}h2To)+KF!{qYlTXAQU)+_e$k$!1;dUXu5Y8 zpPx2QwvMQi)Bdo5c!K9i4&?{or=?V?R4zf2_dte91vQ6U_sjDE+*jitHFkxX!&jW~ zU%@x7?-z={icc<7DxH9>M2n|V`F%jYWa6q+z7MWHg8V-uwI#!;43)|rp;D=^g}6oV zABX0MQK@_c@3g~8g?3n}u+E_jD7QVu(EAWHSE=M6L#1NF(&yiq_YK}2ysBDwIZ(ffc{ZfO9kHte*vH4SQBN-MMM1~ z{LaHBe8E;2OG~;2+{g)f-FIv%p`<>7wnMxLe`{t4{ z##c@FE# zv$pt8H^rz0wjjf;kDJ%g8ba?kuA|kTb#(aJj(6AkaCNlBv2`@xZ&XLqPwQy9rX&V! zK~~q%^!=wKnYG1R%SDWE+e1U>{Z=U!#-;n#DORblRpr9fx2ovZsJ%#dxK+jXo2MB4 zzda-)Cuc?KmnRwfE7fg$t)ofbUf+Ic_MK>p)aEOZV)ebUZ*_|Ok1g3Z%NFkmm2tOI zF4~@JxLmwhim_H~R4yLANgYkQ{`M#rb(Dwly}WYqPIFnM;>NGYMfiI4>#|qR7QeM} zRrjM`**f~$OR`Gk#w}sm(sxcStG2~|I&!_5wy5Ka;WERyS$f#(#v`ZSo-JYW{c4tr zs+Sv=_|>*}v)(2tEj^DB`&%j3t7nVfm8^QKoBH6zS)H5rHx=*BY_U=a&rXoiQf*OV zU8*e-TW2RUoR!PI@fmI}vQ?$mjpe$zE#9eQHs0?_MoqlZX?C-6@zqZ;&ic8U%%=2r znk~Ay%i3OmNGs4!lT6}Kb`aD_vz!jSs*QL-r`kt!UX8LP+Zl!Q# zY59 z`L0D#3%tH-Q8zE6R7wW#nq+AvS9zHm?{g~F<3 zdF669TeMU7=h{kLAIte=w%qix>qKw1KGx!L1)_D^wUyO&wFUmVo|JgHKCjXG*h=M~ zP+|?vRSjHEsuyeU(^%1cQr3;z`APb5Jt;Rjauxsa=sH z$2Z@2x!9P~HO0v{_t|m%v5n2O4DAZPaLbTZtZ87an0bV;sa@$@qr?YU^s3L1`1?82V3% z=B(rl?^adQzgm{?s%rYGEN+eXCFD+P5sW9CE6L|_V-Zegj4!-iKzB6Mmo&^Jl&evG zR8DjU!4}A+Wf0@jGKgv9${1pwu3L#uf463xyXmOA>QdACuQb}V_NMU@zgiZBx5_RA zx;2e7Wz@Q>b#3X`daTo=kxgUu59>}L)oDZ+)_H?}&6(Wa#dOd#UTJm}DDPbNZ!gC? zWmo*xz>cha(nooxt5IrL`&9d~yf3A6WL~j+Yid;Qf96ii3T+lW!{B<8+@77tY@{W z{NJ2Qi(_M|59?A|xwIkN(}t~7mSJbL!gcS03rpxFNE~itZ zHOeU6yHKfY#2!_*cY#!Ng?}1hbOi|WGxshG<7v}_dlzaiTh5&e{P-~fwj8Vk7tQXA z+K}P*rAfdL^%B^!_r?<7@MObXBMEd*O{G#Vf#vXGAWNm9sbPJ>Ps_*4k;T%hmIa4F zga4(Z#?55GhEQ0*MeN$rT^2f?X!pfveQx8|r_BlBeK8KBv2AVeX z!$(^W`{3fmHMi=z(VAPEGUtIe0U2mpy4y*|uxt*eT)b>L=s2=KWH%c3s|i9-=Y}vm zw_lBN*_y(Yy&6*QR&wTWVrbdR-Ot)aA(mPkF<8>L(%J4JB!<iq& z)RMMlVHj72aZjdFQT;l~*7E6VHATvQs!lK!Md1fNnTWT8E zqa`GFp;OAn8n(RHm>8a#845IGWpEf8hW21vf(L>W(p0di%`hsZ^2ab1gZxuU%b%5i z`fyY@Bb*hn7EbW8$v$EBur-mVA)d#6rSuHn~n)=y$ST@2m{WP@{M=eL)%BQ-C zqwh{OO|P&`S{zrtFf>PDJ)AqCDeA_NYOp-l>bFv8-0n^tDi*DWCu69eOC7#D8Fq$J zhxv0Tuzq6M`0OaL(sJd4wK~Gt>Q|kThj1RS@i}ap<_t$`t(J!2m6EmvEjGiul)(8# zc-PB@r_36Q<^gSeYj~EaQ$fCTypRI1iN)}i7J1O{8i&SavBKf2b!Nl!WC#tZcg3>2 zI3J5esd*{q$_w8$rbfKjn8Lic@Qlgj4;u?9@>+@hTc_!tQEJ;it4=w5C(aXWnZR^P@XRM+oPhiQb-Rx;tXT}HRv z;Y+u@n3MF}#Kua>-esrv9{F+fQSd z#uiAQ>Yjn-Qfq;>tPJ;ZEPtm=FYKJ*N>hz(X;S5Nv5r55zgqk;4{Hp|@w`jicT1{h z9=82R#UX#r?k!C7u)f_m54+xouA;T&U^ove4f3RUILwo_X{}^X{SCHZ!lhA zsoLi&$J-dvPS1h(_Tx=CvNf3P?-J^23B~#5>y7cA2x`~=QF-HuOj`5bEoXaZYTPI< zgi8a(Y@|0^vt6tkFR?AP<%o;D?n>ouf1j+1V|{uM?|SJT<#2t<(!j=5U9%C+n$5<_ z(@R{rNZ;yM`R-!1b5w-hZmbORYR1ZvT4iMm(2fn=C{~*`OihNQhAF9QJ5W~3?-QZ4 z(U7Ob4p_47#z`%E3=hl34b-%;EeZHNJl*-Ndb}^}od>^@?o!ngCVOqD(w~qDL@t}Kf zHm9YxUB*i68|~y#<7e%{>f6~Mv7KFzR(*-g5g5lOL#RD#YvWOz{i&sCrDAuE)|bc= z!lx~fT^yvLrH7?K`g)y)Uv-NnyyBx#91N#%xEM&omQRi1sE@(Yuw}eqCwMRh9MT_o ze&Eo^&{4U0az8e37#|?!|1ta>8#+4b?H(9B@Wj}W(IL2w^4~m;?mh~iAs`Ix8$Rp} z9t6HOc;w&_xOopbhn^T4IH=HlM~4PRhmPXq(4hg`4<8#nIxu{A)Z23ee}{)~qkB{z zCk~Gu@rDi_!^eri)6fxordUV~og5q*868GcLnlG)FsSbxAllv|N4>pchxtD!{^9`8 z#%rF!{E&qPq73i#Aj{(V@fMp@GrC{obLW(fvpEcWCWxj_{c#}A2~XF9BTKT7#lh!YOxOcgb!2L zs3p+H(V;=_sB(2|=+Lmon>zLn93AnF4e#@gjY3i+;uxYG-H$j&hYvz`NH@UnJbKC- zJvB1qjUC=IboAKZk)uQ2aU|FA;iIE8iW3ZSV*fDsKQTPI-;2L>5Tw1m2agO;@q33) z9vN9{9qX)Py>)D`j*W0Iz~~10jc(qEl-fOX&^tK1X9ymL2S$gF4-w_a$f){^932ws zWPbSYK5tAh)7M*b`SSH7ZX4FiWAn!AUHMEocO?thds~`!F0Q+rDVB2i={2+2tJz{| zZg$r9KRD75{1ZnTg8%Kv=E1_;TsB`$2;M=CbjR4f*X3k$88{M7D+g_cZdaABc6Qz~VPu z>4k;P>{VzjpP4-avKKNyJPX7Nh2l9r=JRg?3LcY0A75DL5O<+?9Ib<{cvd>EVq6a3wSA zL1!ITa>epI+)!NGQw)6)tUooAo6UNs2+EabJm|3%tiQk;V6#ZR7vv83Y@zr9Z-ifk zTkeFHX5Y`7IE!=wr8QH66SwqT{JJR>D4Sk2mP`djkMJhL7oN#B&Y4q}hvaxwYeiKD+SF>k)6Y*Nl(#yg`CD z;ahPOFN#C=F-H#AZiBbnJQ?P0<8DIQHQ}4cgoUpMJpRIvO65Vk?=`T8Lw-W&4L z_^O%<(HC-W5%++%Q=Uz7XPkF8h}lu7cTs}7B=j;!h(@fKisD5CPSdfMsFEtMs}ks8 z-S%mb1uY1S?-d1Zi($j6kK#ANs#MY@Y?!7EWqIJc=N%JFK1cC?Twpdn8-rrnH-=JL zd3o~fnt{+=9a`TMYVYqLn#A;+aaqaqsdz7W9{~>k356;j{C@edE3q$MW3quxnm zP2S(-J>i|e*QMR1-<$V^~T-hyu~*8dvO%HF2zZ?3_=UD53om z_~+jDZ@V40j6KGy@aRzuC2Pl5T(L+`F{yCE_t&O!iEV;WU&?B@vCsNJFoiQ=*oa;ajwdg{7K8p_-E7keX7rbQxyC;M0~W6@Hi5 zQnH+c!)OY*lzB$d;c48@;6Hqk3jb|dofS;QApBX0_mlz*58;>`rcxpu`%^!)Wz7kM zpwDRR%-T821P`ClvuPCt1;yum9sFv`I==JE?Df}LgtfYf3dWWjQdk4bKKzpwul4v} ziytp?9rf6TAjSrQs;-SyZ%TpTNg;e`92-!=R9_ow${a1Nt8s3>1ZOOopXs`j@av$h z+TSLx{&!jAEEtBv{uutK`*~hTFqxJ`Zyxt@m7c=k4awW&{?4Rz8cNi~*Qge-yy>$M z#;stMLIRFk;WqLQYs$JUO?_G@pYBR|dmH@J|6TIVL#j-yS@_uffl2&@$O7(uQvx@`dPb+;8`{)x>Z4 zP^#o<#Q415tN%H^RYDKgA87D%Jl409j=-}6A0>S!{%`-su==lY+^*dGrgrsjKf1WJ zKgT~^Vc%+>rM)!@f4h<=>U33Wmwd0j8e!ZDW+{-?t#BLpSGSfoTXOOo#>ZG|e-=S& z(6F!d2|ugpg?+SC2#0UP-Hl=19ZBox)rZ%zKy$frs(B_12}@utTm3aO{X46X1X6E3 zT_G&yuG{}90fxP^@NE6_V(VY8AMomb)=yjiVSnqR&&K6OHI7$B-}&91?9}kf`E}QY zt}b8nt=F*!S0jvD!7PF9I}HDWUj5I~)Mwbg+Nb_4+*h-{OAUW3Nvr+uOk0jdefV4D z%s~jmf4%6^I>+YB-Cq6gkRTsIk3wCZafKn_dW-&w<1k#D;rNvc%Y((?Q{9I!)@U#G zI2!fY>ibC=;t={M{I@@a*7n)7XWgiOt@y6b=K6WJL&^1%w0Evl)J-}|d*za%@ z9F?W(#!}*#fz^zLw*9%VKIyL3xs#og90kRsuZ|vsM;dND_P}ui`_mY1P34~fk^jo! zKMTU!n7`Mn|0(T8cRTiA`L{SPh~s_s6;H-#udv(mu7d~uE6#QEv^a0|-rL}3DJ}K+ zL9hPDnCx}E%HKlCn_hfc_w(M14Sr$zUX{P2wscoGhNXx4)?hX&_rEoqxL9SNTZf~< zcOoPOi-X$*8LR(cx&N39geoqFKY2NF-(1(-uSj&OFyy|yKbEWDH>*flqj#Td8oO3%k3d@F&)oxGdxm6Blt9FaN6ty6J|JFp;A!Lg)%ZlnS}#{|eAhUl%4WRN|P_Q5W{Zh${?H zD&&>_anMj-7ls%*m8g@L8iH=Z^{FuBP-AhvVGOKb6rS$ERFk?0p-Um7!h?&OVV$pH zeh4_P5h}02l$E*&q02%vt(6DmjgwpI>%zQNsJs@_V(Kc2OYaKNu*x<0cr9osz72yD zegQ9fualqR(@nTOEe++GT)qx8)YoC?MDN3xsH=842nV_u6FKAm!=RzQygv#^qk(R$ z5rj|e^{C;Ha1FafrnTRId+m?m`Og@5ar*mF!Dd(u&nZRqQ5<_GuDkRte7AmtG2S;; z;S=TtS)I#<(x-zj-9LY_ z;qVsbcv_0<&ZKpemp0ICdDEvGa9O&`Qb<4tOAqBR!^6 zZ7_nle8pkkifb$4Z4o|N@N5wYDiyj$DaRl^g ze;Uu*O+1d?Qd|tH|4su-k=NpA+SoTf2O9j8w!McjEbMlkjlwTQ)-X$d)z#bzv&PwNwYDpnX`-SpX9H6>BY+0EbY zOj<{?K75Brpo3$|CEYk<26y$dyxXVq4P$iHX`=D4tfj&j8e`lXYI(fVfo={>lZM{u z;_AZMAK|=+b)?Ey;r8BWpxgSnXPCN!-dxUFU!0b5NBXj%mNwAcU6qP%7 zJ(R-?PbyfqrKwK~<+IwS{>`Pb^IK|o$J0_=cP6c)Tpzwir0encQ|{GeA=?1uzg~0^ zPknjc*5G$Y@O98y!_kfXMKa)RY1#Pr?tB$99A~v#Ln{xKFUR8{aAWD864xn@KZU6) z46(R;9s(Z!?N9wqOIRH&wh+R?5QW?OX;5&3%NAOxoDoWAu&7C0gwPd+;H)D+lwU4? zvc4|NS)p>)<4oDkgnrg~}|J-l>Za zx*X&x-uO>mXRv^ai}ci2F|Ptv`wPcj?N$z5%+~kapkAryU15yVUST(}Wq+S)&DG|r9Pkc>VIMG-d*MIs9GF8ojW|JZQWt|m5PP(>8LH;^>V{6J*JnBY4!5* zDZO$OFwo5{8{f`X6Na2|h_kR5k^3XxM0Wj9TpD`_Q04p%P$l_QMJngtOhs1dO4{+& zknr1gh$@xk*M>R&wsS+3k;m(~qFJ{|#$x8W)uoxh$JUAJYlWviI=6A_dpI*yQ_{Ca z6dK`u7xt~vfS6N#_45!Wz}}7NFW&2YYatH-XA}}}8Y_Gq!EhJf>n8{wYOp)TVuvYI zyK4u}_+E|i-M2f@0H?uTnJeC1iD7~e^MjS;n6#{TF@G7{c)^V?(dCg96`bAR`IU4c zkw~{BOUYy=l`ORQOLu zEI(!3<@w9A*`_rD*Nw@EWX1&2-MdXG_2l+t`mI$Ov$;$u0Zv+)wg><*;! zj_aL>Ok=)Wn7xKj8-%?Jx$Nvzz+~@;yepL+eHjOxrk=~0GIuyLx~>tth$Ja-Q4)!E zt$H{<)(Jp_AR`FdBM=pFz4PVHVtOmcGA=}W1q+*zv60*a&lHQ9YfYWvQ7A%HZt>xU>84cnDmRapumM|DhWByZ6E6F;QzHcArnuuCjI5K_Fz3Aj!KQ0^Z;%(e zquZ)WNM61?dkuWjEnBmpF1oQZ+CZ)Fgeud4@C4NePf#E{UnGHG0d$wLWqsB7R4;4A zD|dmLw7F$HzTbfSW8w zIB%dFn1u3KxRNavq1&d7f&?Y%7WFE{$^Lv*7E?^)rL7u{)%Mq8NBMkqdr&xf( z<}&%*g>0z|EXk7D@yrCz3YaWwF3j2lYw8=37)@fOK#Wz6SbS%eOqvZh)uc(;fm~A4O`tR6o6DEg<@1C z1wb|_pnSXq%C~OirdK>oI3=8_3qF@M=%(yW5;BslZBDs0%F1>B^awO!o+!<9Qqb z1Fg^rv3Tl^Xr)&mC^ZtvDFmcY5pY=xTP1@z@&I$l4ueqCV5XESd2w{?`;Q~r`ecZlguSc&|x$F zTbtK3kEfec&0Wo%izyQjZNM3XyL>#I=*Sl`v$KWCL{fyYuliOEOC+{K)0%x!JhiE+ zArazhf+i38zW4LP!q|TqS&T(}@6S#z#$vwrjWdg}Wxn^fcr5q*H}74Ht?>OnJF;fC z1mpQhY%^S1jKzKb-kG*mH1`){cl+KukEBhPLHiG|fK>WSGLz;3Nf0}IZhiX9j+w%h z#QJ`yHH}=7K9^|TmRJL<66*cFeucFpy1Rh67Fg+X-RbQ+)+PGZ_dlEHBsIb|Sy+EU zDGFxuc%nxzpj#jX*nPlR-@gOVCHm9nz!eaa;0KOG%Z@|~GS;pHVB49ZB@(>SuXmC` zsB`IaAiQH;Kf6O|rhH->sBI^=pd&A>cms_#$eilLF;3}3JG{k_Xi2oM6M_)@JmM`2 zdl02W3eCM_&=OCB1T@x?PIRXsoW^KTAU=3WJ4H0oUL1l$1jL2s`hIO{GDcCZQ6|oP zN}t;%2$R8qQPj{*!8+H;dLM@zB@&(H9Hm4;(e-F1WGemuLm=qdp_}ZQNNf@6Y*SR@ z#+hd8`%N_hVT=a5T>2+7JAflHpaQJp8&*ab6wETHGi{n}oe9eYPs`F1v9?NFWPl-f zw;Wd?cS|uZM{m`KFe=#~q+A6=xi<;SR5Q#TkTrd7djqIdtU1uC+k{~`2xgfvkSWju z4pd68oIS;Jr-C!NHU@|pm4sZhr4!H6V)_z0@yZlt23yCs#4`qh4D{w||IUO-S(-3y zvR!#>?M)}v!t$7vVC~QwMC#_7I-&C&G)*wv&~!B2;VK#QbElH&{X^(;z%E)K($z*EX z`f1)b$$jf|AZ%|wJB-5XLFZJxsq!Dl;+XDW&_~riN0g%)+YNJePfA%ZfJQX{Ux*;2GV>y zXHVTr<9s+CMi=sE>Ff&Lh`z8mFfhP7Lbq(&w$O40EfKY&+~}Lj=hT3b+}L-zfhRZPjwx; zRvJe}E);u)@>2|Y0Y~kv-IKeLWA+=LxHgW{1Pdw2y5lzMrWk4h4W~<4^k@pH0U469 zOl%v=qos_43a8j3U_QQ*HNA!O^XbR-WXc&H(5THwHl7VH>0LB4oCnF{A2U3g@-ldt zlJgsj7c!ICcw(?%%A5wi$b6-E|A}G&*<1oQrppl18XQP8Vj; z!{~!zXrCpDTg*N=pDSjk;sYk~F_;8GCvtO_3&nCNaiLg1pSjeVz*yYm43EWRAfs8S zSJ4)f=oZir?E_&pkhA$KY=%Z3*pp~WP0r=e{PdohMC;Qloj~K$yL`TD2q<)6r6Y@5y0ySF~E7+dK# z{r%&Mu~mLkrMMWo$G`g&TDdqbaMRwcN-9tD<}sC04%0{$WB2*1-n4r$cE7)B|L*42 z#n|`wO&>qFjzfeQj7277uoH)QF2)}8n@&xbGc4=`^J46czMr%_6_I0LrrMyB@v6mGv+utKG+KP$f74>D)%TY{ac#c$b-X2g z@2^iS#@c=Fm(Y~&@Vy_(_o#G8y$jd6)jgV-F7>Gsg%b6+LEi@DkW&tWv4K(rlm7l@ z1s%1ijKRc-V)n}O=~VaB{M_6%RJ1(AvwN-Lp{zk?nxpr10295*`G&_Mldzs@pEL^G zs;P1zzXieEw1%UD4LT!lmxP*WEuBiK6Z88zz~7Nwo^=;f_T3e|O;HPEhPf^oNv zf}gh0d~UX56s0O&;;ova*7c8~bS*rE*09hCZY9*^>^%TMM%x()GA)@zDFCQ8!W;+6 z22jvgGAL>?7Db2^vlo)(^f?fZvu;&VG5}9B;lVPpeaG5FA1hlRYrQ*4r70tZHL2+o z(gi8RI(K%{bs={Z6E;0`n#mhMK;fTNs6<-Y8Q*2uc!t^~t?g`mR=ptoC)n-MhX?{U zQ#EHJ2$~8mA4GSdJt**LNinAL!gMlbgZ}P5+hvuUyO`cVCba z=j!Ecjo_M)EIw6hiOzLh&!raz2AX#*qzBMhvs4$?1BXQ{N)p2b%GuQ3mUJ&oXB62y z=qO0JYNJ53@f-ww2Y*rPpG|$s!$w- zR2_^W)GJ%E5{*HX7a{>=Q+1|dk=8`KuSQchM{h@=jTB~&!t_PaUot%ijQ4TWNz(xN ziJ5AP>FC-~j9~O2=(Hv__=oxQesJi9{)v`1Kn~&tP2^o*Zz-w`7 zVYV|2W53;i@$~~R3QqDHV}#A1yMfctr?l~C$8I1ZOkM_q6!_qP-F7IYX}c5l0b64)cY4 zpEZa^>ET31Ns5Hlp=~L;B)k=U31O{j5Ew&2j9hbxV_MQt3Z$BLspc1$_{~B&BRm&3 zsM;iT=INwKXcY!tpchiLf}jk=pG)Wf&lHO{CMgO+oyC*ewPRvl8pW^3(qfKd_#@0g zAV`u_cU zL7*-_$2;uT1}@`c2S{$2$%m0@y@p;ek_~HBO7R{|47gD)W#m%>wy%|7=4VB5xmdV@ zse~!i3aBJFuzQ?yl0l9T`_*AhR+kv*Glp&WX7^Ovs__Gs!YH$FXqmyC5F4??f|0M6 zOHq246!4Io`hO=(9kxs<2`#IZCTLJIi$aaY&^%-kp`SaO<@kgqCCk`qbSXN})WX0a zh5=yy+u~1HRtBZqlT!1}IUzssgViKo9<|M5`3VlNBy_}4Rh7(ONJhTgKy#O#_ofga zoIQdjW`;vSlbo^gE}%0S@h%!SD2sg}t2KM>@j8Rb;5i6|?K-sG^nR$+Eboj9h`uLrG?Ek`}%U}M^ zfB#=3cb~0Z=%F%W_mtTM5)306T>kW7($Pn$plM9`M_cCY^p2ac$u8Z zPF~`o7=EB*F}BW+{p|k5*m^(q&krxgHu$k8@wU;A&Ec`hk6k#p7~AZ}P9IM6$~Q;73m%S&Z%WBi}gTq@~fIWxN>M<41?yyciquqv>ml zvAuqDJ0AP|=o4dRRQJz!EyjlZ=z+1t*yDcmQII;|M>jvUaNc{%!sTlV*gbuE!OM70 z2ZO+NtUEl+9gJ}IbO-Z0-8}>OYeQEt)rk?3cz2Kxs6|i|l(S~N&NkCsabtvAZ-lxS zJLyOM1(bQpkK~_lIpo6p?5tKfi?K6)J*0iQKi`gq3y^f#J>Zvv;Xr@iC0Zp+SI$1ipj;A~!+>a5PR4#4R8)K@RlR1=Hs6m5$Gw>q zD*N3~6I5pF2=t7l+84dj!=yqc!LcQbU0ud7cU7+(>e_SMEK)|vRbn?&N9Eywc#uds zED&_Y6u#-ipmcx|7#Nfu%uIGJ#jjqO9#+s9m!*lIVwvE;0g?=AMbmJai$XVHG+ul6 z{LB>aWN;+j3@~0KH)tAXU`t5%AZ<1(hKxr9K(7>j=7ve z`og7Db4POrGV110q=V#5V>IKE^-=*?ni6R)Zb+@2L=n}QP9>=CR98AB&~8~SBj8pG z>mm<|DTuxJHWkXY3lb3Ra{I!>OZ6aAz(d?^NbA`odO(wx+H-jfS7x!+qpzM`gBp6QjNR)mD;?JOo@np>U;zqXk_|a9$BSVFXvEIkg038OAwHR%_sgEag!#bFm%^XKpeO(NKfJ z%8;l;k$I<7P;H9BppT#@7OMRL-Wk-U(weJLV!Y#2Vcr(ZI&_4Vdl~Vd&7kQZjjpL0?js$6fhH8WhyQIxfdNYt2PmW+} zTK0Y<*!@GLrmI8jcQwzSPaf;&i1+W#pf_5`bFP88FPThE_9n1ESC;Xbk=&%TYwE(6 z5T2t$)Mag2*rF{cOwqIH9oEvcX0{;FC~O!f$eOlA8{fbYZ&QHla;2cpU~JBfdj^4e z26e{81PB$3(5W5KltKaR;y#0n!Ew}pCYM9Y?2*)?@34hJqtRj(aE<2#YSL_LV8EEU z6-G?|N86u`Xp;h$k6`l?<}GUsta*?NPFPr))&YjcFfa?vnZ{7cG%8Cnk`{myPsx-H zN>+4&ui08TwH{0Af|j{7%P~zYX&2-jWJb)1um)+6kGG%9?48jqKyLaq-LYQuC|ocDHOy0 zLY+bA?2|F!Q2$6eEq1OmXaT#XD~8J#V{iApk6@(c9lrPD$DYIc5BuJ~m|2Xy%X?<{ zIc?!d^KUWsUhnbI#n^Rk=(uzwq>-*2iK>AEj)Th3{9m0##cf#Vnk*O>Hm~L}Vqo5S z=dt^Mi`+P)*0L?pMme8P%cJ=`0Eup=gZQ?<64&=5Nu+~_wdzvVV5FTI6S`*76nSJ` zM^%yFNih!5QMe+7Nnu5ewtbMeH*4&T!vCf-?a2W(%*)&xi2fHUMQsIDm;Z-GZ7$(l zl`tc_Y27G9Dbd%5`tWLQZhnqA9fJWkM2)v&TueR@oX`#hdP-<`NzIH*WV2`~USuA= z(m#-gp_>5KQ=4{N1p?bfOKX#>hwW-J^kQ}PyHuW^2&krIs$REhKoT_cI4qKzl{R4d z+|E%<(TB9HRU2~&*T-$4uW3(mmfyld)~u_T(2$ZUN*XDX*Cx@(WV7BRHtZYA1x(Y{ z8B6_?04g_Au1dMlHz*3{EUbL_a9R9G4&e4+VFz-!akx?{ z-o}D9qnVaCus#_iAvugJ%*sT2yww)JE_KmV(Y$5_$GAS2k^e63KO*DAn?-h)A6db< zN~C~Vrlma7QYyFPr&@|r=yGLuXu*Vn7@vZhUO&zvT94kO_mn1?lK{Bo-Do7m^Z~bOs>U@?ezV> z7JT_h}Zh$;!TyyUgcTbl}tPmm(V6kV! zkG$?sFgg(PBR_ByA-F0udS(=ZCyCn{ZFv4U$o;6l?Ap6T z9pB+bAC@HOX<|={EuMvUBMlZ#(GVPn1qgM~c#1+6W>(R0b<4Rp;s}U2_^l|$_iM0l zT`k-(3x?ZP3N#~D)n=*EB$5*ACLJn*e(hpAWX4j5fp*yvzZA#v0+*P`gh3XuYhN&c zf|_-`uFfxTFo->VV6tcrde{l+Vxx(8AuNBWmXqpU%M)pfN#3=If2&!XT4cm?zFuJx zMOAJMDibvTWMRw}*Di+Cj2+53s>qvnONUK|NyZ<9y+EZ#F*;EfZUJqxg&G!$QmHga zNRqdtg4K*FuBT-NoUx?Yr0l%y^x6dP1V+!TDJ|Co&mLy{t^vyowxnH)N*3BkXQY^$#+=-22pcVKof-&;g1dm{Z7l6r*2O2&XAVJ!IV?8` zg_aH_ghZ8M#(tpR!|30-4mj3g<9sB>l1WTs#W4o!>{&2uUI$T8%crUfA}QWnGv{TM zaj#CvIo5z-wV#*8tSKGCEBKI}EDm7FDAl>(vR87~MNUAlMCR-dhBj)J2HH^&yK0k4 z#-g-ASxds)iEW1%O+*TE#~a>|y4-va#EjGj<#Vzj&fPY37A9EDs3Bj*yf)euT{3Yl zNE^AI6@#;3Q|i*-_rZjdfn9}7O{P>a3w_U$lsJ!W)!>c)eaxrwO^PL<$J zPP4LXy#boVIPja{EHnR~Pyb7F6Q$e0TLycK!>jpnT+Nr`YQ9{)HJQtB6~?;$GszrE zAy)J>f7JDDfSlukKKMP$b}8Xplb6Kuyl2m~wkD4W^;X27(Qtb|$2Ah``Z?4fJ353a zLt?jdwJ%hTaV}Hx!B-Z8Ff4L5PbD!vmbC7B1|`X!YfMAWzAGoN!Ing4bCe1lF=4h434UaO{Z8w@HV!*l9L&%a!GI}7-(PvA;wQEj>OX~ zsns`8n7YB{$WsD;<)cG?`5n zGr3Z>rM?nLi}?aEeYo^aDE zN5k+H(3ZEP+OV@N)zXt{=}WbAr&`ve`Z(O3pH9tY^V8*-b>?k8U&>s_j$_qc4FoF- zvFJiVz|%SbO=8D&o_BQPJIWYDpU9QFre_NisNc{Q21f9LU2m7Nrcns(^zv1^nQCp`nQGaQYUxk4?!a6B&Qv!UlYQ-pUU?WLt<@K&qiO&+ z=~4`6$hZJ&*EDD^7nl^SIB%deGd0zUIkwih`PtT~+?AW8X&vhz-3p@Sl%HaDdLFe= zhuOW_JlL@pTd%PYvcq(8Iz%@c*6VZg#v~JKYjU3VcDmPXZs*Io&EZY@9g~?ktdAEJ!E!+h}kq)tnHVWGzeGoGC-57^hu8~M6>VS!7(w#tzj*uf9b;KBmh z^8kTO+$4N>o8W)A1?F^b6z2dm^9X-e;8V*tw4->h16cyjzdIqO-NHP-wwla%$zT ze01IEePjP=SMM>YQBr%k>oi*&V05)Z&--fV$#(e=&al7ihxc!GiZeTd|Dy#WXe3 zBkg`Uj3m{Z>K?I&tR-&f(TAbFU`8d?aY*~Oi?P%GvWNF?t7ZXd5n}SJAN$Jw>jUwQ zIwYQd93b*MKj}W+5>c=av_^y4_YCMQ#xj2Fg`=B;SZSj$d_`M~O=ABC(qanxKZe^; zjbYxmjfu7^2p~ylBMayzcMt5@mROAC{Mdfj;YC04m*-uMK?OI?MYEUJb$2KB4DB5l zJ2=W>s=K=>1;Vgx=^CNT+sG24C$UEx<|Qc_dNv8L_ST$8^j^e?CpPHXfW^u3)$!T+ zi46e&oi7xOW_E?090YOBc!X1}MifMVI*p^;`~9 z27IQM^*0X%;f9$3wB*-Hs}fZV&fbw0*V;j?;bq4DAiy8|%ti^MZ9MK=!SODc+1&{I zV*15_7x%ol`^BLb2VMLFv$JagX2$Z;uKn@!Kzj-21!bq6ONApiawME9LYd_=DT!3< z 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 O2^k|sjF_V9=l?JMIUQL5 literal 0 HcmV?d00001 diff --git a/boot/ocamldep b/boot/ocamldep new file mode 100755 index 0000000000000000000000000000000000000000..fb5c37fbe235fb16986d330f27210410451f6d91 GIT binary patch literal 288221 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 literal 0 HcmV?d00001 diff --git a/build/.cvsignore b/build/.cvsignore new file mode 100644 index 0000000..274c6e5 --- /dev/null +++ b/build/.cvsignore @@ -0,0 +1 @@ +ocamlbuild_mixed_mode diff --git a/build/boot-c-parts-windows.sh b/build/boot-c-parts-windows.sh new file mode 100755 index 0000000..14b2477 --- /dev/null +++ b/build/boot-c-parts-windows.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# $Id: boot-c-parts-windows.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +cd `dirname $0`/.. +set -ex + +. config/config.sh + +(cd byterun && make -f Makefile.nt) +(cd asmrun && make -f Makefile.nt all meta.$O dynlink.$O) +(cd yacc && make -f Makefile.nt) +(cd win32caml && make) + +mkdir -p _build/boot +cp -f byterun/ocamlrun.exe \ + byterun/libcamlrun.$A \ + byterun/ocamlrun.dll \ + asmrun/libasmrun.$A \ + yacc/ocamlyacc.exe \ + boot/ocamlc \ + boot/ocamllex \ + boot/ocamldep \ + _build/boot +mkdir -p _build/byterun +cp -f byterun/ocamlrun.exe byterun/ocamlrun.dll boot +cp -f byterun/ocamlrun.$A _build/byterun diff --git a/build/boot-c-parts.sh b/build/boot-c-parts.sh new file mode 100755 index 0000000..12941fb --- /dev/null +++ b/build/boot-c-parts.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# $Id: boot-c-parts.sh,v 1.2 2007-10-08 14:19:34 doligez Exp $ +cd `dirname $0`/.. +set -ex + +# Create a bunch of symlinks to _build/boot +mkdir -p _build/boot +ln -sf ../../byterun/ocamlrun \ + ../../byterun/libcamlrun.a \ + ../../asmrun/libasmrun.a \ + ../../asmrun/libasmrunp.a \ + ../../yacc/ocamlyacc \ + ../../boot/ocamlc \ + ../../boot/ocamllex \ + ../../boot/ocamldep \ + _build/boot + +[ -f boot/ocamlrun ] || ln -sf ../byterun/ocamlrun boot + +(cd byterun && make) +(cd asmrun && make all meta.o dynlink.o) +(cd yacc && make) diff --git a/build/boot.sh b/build/boot.sh new file mode 100755 index 0000000..bda800f --- /dev/null +++ b/build/boot.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# $Id: boot.sh,v 1.2 2007-10-08 14:19:34 doligez Exp $ +cd `dirname $0`/.. +set -ex +TAGLINE='true: -use_stdlib' +./boot/ocamlrun boot/myocamlbuild.boot \ + -tag-line "$TAG_LINE" \ + boot/stdlib.cma boot/std_exit.cmo + +boot/ocamlrun boot/myocamlbuild.boot \ + -tag-line "$TAG_LINE" -log _boot_log1 \ + ocamlbuild/ocamlbuildlightlib.cma ocamlbuild/ocamlbuildlight.byte + +rm -f _build/myocamlbuild + +boot/ocamlrun boot/myocamlbuild.boot \ + -just-plugin -install-lib-dir _build/ocamlbuild -byte-plugin + +cp _build/myocamlbuild boot/myocamlbuild + +./boot/ocamlrun boot/myocamlbuild \ + -tag-line "$TAG_LINE" \ + $@ -log _boot_log2 boot/camlheader ocamlc diff --git a/build/buildbot b/build/buildbot new file mode 100755 index 0000000..f337e3f --- /dev/null +++ b/build/buildbot @@ -0,0 +1,113 @@ +#!/bin/sh + +# If you want to help me by participating to the build/test effort: +# http://gallium.inria.fr/~pouillar/ocaml-testing.html +# -- Nicolas Pouillard + +usage() { + echo "Usage: $0 (make|ocb|ocamlbuild) (win (mingw|msvc|msvc64) | *)" + exit 1 +} + +logfile="buildbot.log" + +finish() { + curl -s -0 -F "log=@$logfile" \ + -F "host=`hostname`" \ + -F "mode=$mode-$opt_win-$opt_win2" \ + http://buildbot.feydakins.org/dropbox || : +} + +rm -f buildbot.failed +rm -f $logfile + +bad() { + touch buildbot.failed +} + +finish_if_bad() { + if [ -f buildbot.failed ]; then + finish + exit 2 + fi +} + +if figlet "test" > /dev/null 2> /dev/null; then + draw="figlet" +else + draw="echo ----------- " +fi + +if echo | tee -a tee.log > /dev/null 2> /dev/null; then + tee="tee -a $logfile" +else + tee=: +fi + +rm -f tee.log + +log() { + $draw $@ + $tee +} + +mode=$1 +shift 1 + +case "$mode" in + make|ocb|ocamlbuild) : ;; + *) usage;; +esac + +case "$1" in + win) + opt_win=win + opt_win2=$2 + shift 2 + Makefile=Makefile.nt;; + *) Makefile=Makefile;; +esac + +( [ -f config/Makefile ] && make -f $Makefile clean || : ) 2>&1 | log clean + +( ./build/distclean.sh || : ) 2>&1 | log distclean + +(cvs -q up -dP -r release311 || bad) 2>&1 | log cvs up +finish_if_bad + +case "$opt_win" in +win) + + # FIXME + sed -e 's/\(OTHERLIBRARIES=.*\) labltk/\1/' \ + < "config/Makefile.$opt_win2" > config/Makefile || bad + finish_if_bad + + cp config/m-nt.h config/m.h || bad + finish_if_bad + cp config/s-nt.h config/s.h || bad + finish_if_bad + ;; + +*) + (./configure --prefix `pwd`/_install $@ || bad) 2>&1 | log configure + finish_if_bad + ;; +esac + +case "$mode" in + make) + (make -f $Makefile world opt opt.opt install || bad) 2>&1 | log build install + finish_if_bad + ;; + ocb|ocamlbuild) + (./build/fastworld.sh || bad) 2>&1 | log build + finish_if_bad + (./build/install.sh || bad) 2>&1 | log install + finish_if_bad + ;; +esac + +(cat _build/not_installed || bad) 2>&1 | log not_installed + +finish diff --git a/build/camlp4-bootstrap.sh b/build/camlp4-bootstrap.sh new file mode 100755 index 0000000..af530cf --- /dev/null +++ b/build/camlp4-bootstrap.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# $Id: camlp4-bootstrap.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +set -e +cd `dirname $0`/.. + +TMPTARGETS="\ + camlp4/boot/Lexer.ml" + +TARGETS="\ + camlp4/Camlp4/Struct/Camlp4Ast.ml \ + camlp4/boot/Camlp4.ml \ + camlp4/boot/camlp4boot.ml" + +for target in $TARGETS camlp4/boot/Camlp4Ast.ml; do + [ -f "$target" ] && mv "$target" "$target.old" + rm -f "_build/$target" +done + +if [ -x ./boot/myocamlbuild.native ]; then + OCAMLBUILD=./boot/myocamlbuild.native +else + OCAMLBUILD="./boot/ocamlrun boot/myocamlbuild" +fi +$OCAMLBUILD $TMPTARGETS $TARGETS + +for t in $TARGETS; do + echo promote $t + cp _build/$t camlp4/boot/`basename $t` + if cmp _build/$t camlp4/boot/`basename $t`.old; then + echo fixpoint for $t + else + echo $t is different, you should rebootstrap it by cleaning, building and call this script + fi +done diff --git a/build/camlp4-byte-only.sh b/build/camlp4-byte-only.sh new file mode 100755 index 0000000..80d17e1 --- /dev/null +++ b/build/camlp4-byte-only.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: camlp4-byte-only.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ byte_stdlib_mixed_mode $OCAMLC_BYTE $OCAMLLEX_BYTE $CAMLP4_BYTE diff --git a/build/camlp4-native-only.sh b/build/camlp4-native-only.sh new file mode 100755 index 0000000..da34432 --- /dev/null +++ b/build/camlp4-native-only.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: camlp4-native-only.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ native_stdlib_mixed_mode $OCAMLOPT_BYTE $OCAMLLEX_BYTE $CAMLP4_NATIVE diff --git a/build/camlp4-targets.sh b/build/camlp4-targets.sh new file mode 100644 index 0000000..ed1391c --- /dev/null +++ b/build/camlp4-targets.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# $Id: camlp4-targets.sh,v 1.2 2007-10-08 14:19:34 doligez Exp $ +CAMLP4_COMMON="\ + camlp4/Camlp4/Camlp4Ast.partial.ml \ + camlp4/boot/camlp4boot.byte" +CAMLP4_BYTE="$CAMLP4_COMMON \ + camlp4/Camlp4.cmo \ + camlp4/Camlp4Top.cmo \ + camlp4/camlp4prof.byte$EXE \ + camlp4/mkcamlp4.byte$EXE \ + camlp4/camlp4.byte$EXE \ + camlp4/camlp4fulllib.cma" +CAMLP4_NATIVE="$CAMLP4_COMMON \ + camlp4/Camlp4.cmx \ + camlp4/Camlp4Top.cmx \ + camlp4/camlp4prof.native$EXE \ + camlp4/mkcamlp4.native$EXE \ + camlp4/camlp4.native$EXE \ + camlp4/camlp4fulllib.cmxa" + +for i in camlp4boot camlp4r camlp4rf camlp4o camlp4of camlp4oof camlp4orf; do + CAMLP4_BYTE="$CAMLP4_BYTE camlp4/$i.byte$EXE camlp4/$i.cma" + CAMLP4_NATIVE="$CAMLP4_NATIVE camlp4/$i.native$EXE" +done + +cd camlp4 +for dir in Camlp4Parsers Camlp4Printers Camlp4Filters; do + for file in $dir/*.ml; do + base=camlp4/$dir/`basename $file .ml` + CAMLP4_BYTE="$CAMLP4_BYTE $base.cmo" + CAMLP4_NATIVE="$CAMLP4_NATIVE $base.cmx $base.$O" + done +done +cd .. diff --git a/build/distclean.sh b/build/distclean.sh new file mode 100755 index 0000000..01bcb8e --- /dev/null +++ b/build/distclean.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: distclean.sh,v 1.9 2008-12-03 18:09:09 doligez Exp $ + +cd `dirname $0`/.. +set -ex +(cd byterun && make clean) || : +(cd asmrun && make clean) || : +(cd yacc && make clean) || : +rm -f build/ocamlbuild_mixed_mode +rm -rf _build +rm -f boot/ocamlrun boot/ocamlrun.exe boot/camlheader \ + boot/myocamlbuild boot/myocamlbuild.native boot/myocamlbuild.native.exe \ + myocamlbuild_config.ml config/config.sh config/Makefile \ + boot/ocamlyacc tools/cvt_emit.bak tools/*.bak \ + config/s.h config/m.h boot/*.cm* _log _*_log* + +# from partial boot +rm -f driver/main.byte driver/optmain.byte lex/main.byte \ + tools/ocamlmklib.byte camlp4/build/location.ml \ + camlp4/build/location.mli \ + tools/myocamlbuild_config.ml camlp4/build/linenum.mli \ + camlp4/build/linenum.mll \ + camlp4/build/terminfo.mli camlp4/build/terminfo.ml + +# from ocamlbuild bootstrap +rm -f ocamlbuild/_log ocamlbuild/,ocamlbuild.byte.start \ + ocamlbuild/boot/ocamlbuild ocamlbuild/myocamlbuild_config.ml \ + ocamlbuild/myocamlbuild_config.mli +rm -rf ocamlbuild/_build ocamlbuild/_start + +# from the old build system +rm -f camlp4/build/camlp4_config.ml camlp4/**/*.cm* diff --git a/build/fastworld.sh b/build/fastworld.sh new file mode 100755 index 0000000..d2d5f5b --- /dev/null +++ b/build/fastworld.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: fastworld.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +cd `dirname $0` +set -e +if [ -e ocamlbuild_mixed_mode ]; then + echo ocamlbuild mixed mode detected + echo 'please cleanup and re-launch (make clean ; ./build/distclean.sh)' + exit 1 +fi +./mkconfig.sh +./mkmyocamlbuild_config.sh +. ../config/config.sh +if [ "x$EXE" = "x.exe" ]; then + ./boot-c-parts-windows.sh +else + ./boot-c-parts.sh +fi +./boot.sh $@ + +cd .. +. build/targets.sh +OCAMLMKLIB_BYTE="tools/ocamlmklib.byte" +set -x +$OCAMLBUILD $@ -log _boot_fast_log \ + $STDLIB_BYTE $OCAMLOPT_BYTE $STDLIB_NATIVE \ + $OCAMLOPT_NATIVE $OCAMLMKLIB_BYTE $OTHERLIBS_UNIX_NATIVE $OCAMLBUILD_NATIVE + +rm -f _build/myocamlbuild +boot/ocamlrun boot/myocamlbuild \ + -just-plugin -install-lib-dir _build/ocamlbuild \ + -ocamlopt "../_build/ocamlopt.opt -nostdlib -I boot -I stdlib -I $UNIXDIR" +cp _build/myocamlbuild boot/myocamlbuild.native + +./boot/myocamlbuild.native $@ \ + $OCAMLC_NATIVE $TOPLEVEL $OTHERLIBS_BYTE $OTHERLIBS_NATIVE $OCAMLLEX_BYTE \ + $OCAMLLEX_NATIVE $TOOLS_BYTE $TOOLS_NATIVE $DEBUGGER \ + $OCAMLDOC_BYTE $OCAMLDOC_NATIVE $OCAMLBUILD_BYTE $CAMLP4_BYTE $CAMLP4_NATIVE diff --git a/build/install.sh b/build/install.sh new file mode 100755 index 0000000..164640d --- /dev/null +++ b/build/install.sh @@ -0,0 +1,567 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: install.sh,v 1.11 2008-08-05 13:05:23 ertai Exp $ + +set -e + +cd `dirname $0`/.. + +. config/config.sh + +not_installed=$PWD/_build/not_installed + +rm -f "$not_installed" +touch "$not_installed" + +wontinstall() { + echo "$1" >> "$not_installed" + echo " don't install $1" +} + +installbin() { + if [ -f "$1" ]; then + echo " install binary $2" + cp -f "$1" "$2" + [ -x "$2" ] || chmod +x "$2" + else + wontinstall "$1" + fi +} + +installbestbin() { + if [ -f "$1" ]; then + echo " install binary $3 (with `basename $1`)" + cp -f "$1" "$3" + else + if [ -f "$2" ]; then + echo " install binary $3 (with `basename $2`)" + cp -f "$2" "$3" + else + echo "None of $1, $2 exists" + exit 3 + fi + fi + [ -x "$3" ] || chmod +x "$3" +} + +installlib() { + if [ -f "$1" ]; then + dest="$2/`basename $1`" + echo " install library $dest" + cp -f "$1" "$2" + if [ "$RANLIB" != "" ]; then + "$RANLIB" "$dest" + fi + else + wontinstall "$1" + fi +} + +installdir() { + args="" + while [ $# -gt 1 ]; do + if [ -f "$1" ]; then + args="$args $1" + else + wontinstall "$1" + fi + shift + done + last="$1" + for file in $args; do + echo " install $last/`basename $file`" + cp -f "$file" "$last" + done +} + +installlibdir() { + args="" + while [ $# -gt 1 ]; do + args="$args $1" + shift + done + last="$1" + for file in $args; do + installlib "$file" "$last" + done +} + +mkdir -p $BINDIR +mkdir -p $LIBDIR +mkdir -p $LIBDIR/caml +mkdir -p $LIBDIR/camlp4 +mkdir -p $LIBDIR/vmthreads +mkdir -p $LIBDIR/threads +mkdir -p $LIBDIR/labltk +mkdir -p $LIBDIR/ocamlbuild +mkdir -p $LIBDIR/ocamldoc +mkdir -p $LIBDIR/ocamldoc/custom +mkdir -p $STUBLIBDIR +mkdir -p $MANDIR/man1 +mkdir -p $MANDIR/man3 +mkdir -p $MANDIR/man$MANEXT + +echo "Installing core libraries..." +installlibdir byterun/libcamlrun.$A asmrun/libasmrun.$A asmrun/libasmrunp.$A \ + $LIBDIR + +PUBLIC_INCLUDES="\ + alloc.h callback.h config.h custom.h fail.h intext.h \ + memory.h misc.h mlvalues.h printexc.h signals.h compatibility.h" + +cd byterun +for i in $PUBLIC_INCLUDES; do + echo " install caml/$i" + sed -f ../tools/cleanup-header $i > $LIBDIR/caml/$i +done +cd .. + +WIN32="" +if [ "x$EXE" = "x.exe" ]; then + installbin win32caml/ocamlwin.exe $PREFIX/OCamlWin.exe + installdir byterun/ocamlrun.dll $BINDIR + WIN32=win32 +fi + +installdir otherlibs/"$WIN32"unix/unixsupport.h \ + otherlibs/bigarray/bigarray.h \ + $LIBDIR/caml + +installdir yacc/ocamlyacc byterun/ocamlrun $BINDIR + +installdir config/Makefile $LIBDIR/Makefile.config +installdir byterun/ld.conf $LIBDIR + +cd _build + +echo "Installing the toplevel and compilers..." +installbin ocaml$EXE $BINDIR/ocaml$EXE +installbin ocamlc$EXE $BINDIR/ocamlc$EXE +installbin ocamlopt$EXE $BINDIR/ocamlopt$EXE +installbin ocamlc.opt$EXE $BINDIR/ocamlc.opt$EXE +installbin ocamlopt.opt$EXE $BINDIR/ocamlopt.opt$EXE + +set=set # coloration workaround + +echo "Installing the standard library..." +installdir \ + stdlib/stdlib.cma \ + stdlib/stdlib.cmxa stdlib/stdlib.p.cmxa \ + stdlib/camlheader \ + stdlib/camlheader_ur \ + stdlib/std_exit.cm[io] \ + stdlib/arg.cmi stdlib/arg.mli \ + stdlib/array.cmi stdlib/array.mli \ + stdlib/arrayLabels.cmi stdlib/arrayLabels.mli \ + stdlib/buffer.cmi stdlib/buffer.mli \ + stdlib/callback.cmi stdlib/callback.mli \ + stdlib/camlinternalLazy.cmi stdlib/camlinternalLazy.mli \ + stdlib/camlinternalMod.cmi stdlib/camlinternalMod.mli \ + stdlib/camlinternalOO.cmi stdlib/camlinternalOO.mli \ + stdlib/char.cmi stdlib/char.mli \ + stdlib/complex.cmi stdlib/complex.mli \ + stdlib/digest.cmi stdlib/digest.mli \ + stdlib/filename.cmi stdlib/filename.mli \ + stdlib/format.cmi stdlib/format.mli \ + stdlib/gc.cmi stdlib/gc.mli \ + stdlib/genlex.cmi stdlib/genlex.mli \ + stdlib/hashtbl.cmi stdlib/hashtbl.mli \ + stdlib/int32.cmi stdlib/int32.mli \ + stdlib/int64.cmi stdlib/int64.mli \ + stdlib/lazy.cmi stdlib/lazy.mli \ + stdlib/lexing.cmi stdlib/lexing.mli \ + stdlib/list.cmi stdlib/list.mli \ + stdlib/listLabels.cmi stdlib/listLabels.mli \ + stdlib/map.cmi stdlib/map.mli \ + stdlib/marshal.cmi stdlib/marshal.mli \ + stdlib/moreLabels.cmi stdlib/moreLabels.mli \ + stdlib/nativeint.cmi stdlib/nativeint.mli \ + stdlib/obj.cmi stdlib/obj.mli \ + stdlib/oo.cmi stdlib/oo.mli \ + stdlib/parsing.cmi stdlib/parsing.mli \ + stdlib/pervasives.cmi stdlib/pervasives.mli \ + stdlib/printexc.cmi stdlib/printexc.mli \ + stdlib/printf.cmi stdlib/printf.mli \ + stdlib/queue.cmi stdlib/queue.mli \ + stdlib/random.cmi stdlib/random.mli \ + stdlib/scanf.cmi stdlib/scanf.mli \ + stdlib/sort.cmi stdlib/sort.mli \ + stdlib/stack.cmi stdlib/stack.mli \ + stdlib/stdLabels.cmi stdlib/stdLabels.mli \ + stdlib/stream.cmi stdlib/stream.mli \ + stdlib/string.cmi stdlib/string.mli \ + stdlib/stringLabels.cmi stdlib/stringLabels.mli \ + stdlib/sys.cmi stdlib/sys.mli \ + stdlib/weak.cmi stdlib/weak.mli \ + stdlib/$set.cmi stdlib/$set.mli \ + stdlib/arg.cmx stdlib/arg.p.cmx stdlib/arg.$O stdlib/arg.p.$O \ + stdlib/array.cmx stdlib/array.p.cmx stdlib/array.$O stdlib/array.p.$O \ + stdlib/arrayLabels.cmx stdlib/arrayLabels.p.cmx stdlib/arrayLabels.$O stdlib/arrayLabels.p.$O \ + stdlib/buffer.cmx stdlib/buffer.p.cmx stdlib/buffer.$O stdlib/buffer.p.$O \ + stdlib/callback.cmx stdlib/callback.p.cmx stdlib/callback.$O stdlib/callback.p.$O \ + stdlib/camlinternalLazy.cmx stdlib/camlinternalLazy.p.cmx stdlib/camlinternalLazy.$O stdlib/camlinternalLazy.p.$O \ + stdlib/camlinternalMod.cmx stdlib/camlinternalMod.p.cmx stdlib/camlinternalMod.$O stdlib/camlinternalMod.p.$O \ + stdlib/camlinternalOO.cmx stdlib/camlinternalOO.p.cmx stdlib/camlinternalOO.$O stdlib/camlinternalOO.p.$O \ + stdlib/char.cmx stdlib/char.p.cmx stdlib/char.$O stdlib/char.p.$O \ + stdlib/complex.cmx stdlib/complex.p.cmx stdlib/complex.$O stdlib/complex.p.$O \ + stdlib/digest.cmx stdlib/digest.p.cmx stdlib/digest.$O stdlib/digest.p.$O \ + stdlib/filename.cmx stdlib/filename.p.cmx stdlib/filename.$O stdlib/filename.p.$O \ + stdlib/format.cmx stdlib/format.p.cmx stdlib/format.$O stdlib/format.p.$O \ + stdlib/gc.cmx stdlib/gc.p.cmx stdlib/gc.$O stdlib/gc.p.$O \ + stdlib/genlex.cmx stdlib/genlex.p.cmx stdlib/genlex.$O stdlib/genlex.p.$O \ + stdlib/hashtbl.cmx stdlib/hashtbl.p.cmx stdlib/hashtbl.$O stdlib/hashtbl.p.$O \ + stdlib/int32.cmx stdlib/int32.p.cmx stdlib/int32.$O stdlib/int32.p.$O \ + stdlib/int64.cmx stdlib/int64.p.cmx stdlib/int64.$O stdlib/int64.p.$O \ + stdlib/lazy.cmx stdlib/lazy.p.cmx stdlib/lazy.$O stdlib/lazy.p.$O \ + stdlib/lexing.cmx stdlib/lexing.p.cmx stdlib/lexing.$O stdlib/lexing.p.$O \ + stdlib/list.cmx stdlib/list.p.cmx stdlib/list.$O stdlib/list.p.$O \ + stdlib/listLabels.cmx stdlib/listLabels.p.cmx stdlib/listLabels.$O stdlib/listLabels.p.$O \ + stdlib/map.cmx stdlib/map.p.cmx stdlib/map.$O stdlib/map.p.$O \ + stdlib/marshal.cmx stdlib/marshal.p.cmx stdlib/marshal.$O stdlib/marshal.p.$O \ + stdlib/moreLabels.cmx stdlib/moreLabels.p.cmx stdlib/moreLabels.$O stdlib/moreLabels.p.$O \ + stdlib/nativeint.cmx stdlib/nativeint.p.cmx stdlib/nativeint.$O stdlib/nativeint.p.$O \ + stdlib/obj.cmx stdlib/obj.p.cmx stdlib/obj.$O stdlib/obj.p.$O \ + stdlib/oo.cmx stdlib/oo.p.cmx stdlib/oo.$O stdlib/oo.p.$O \ + stdlib/parsing.cmx stdlib/parsing.p.cmx stdlib/parsing.$O stdlib/parsing.p.$O \ + stdlib/pervasives.cmx stdlib/pervasives.p.cmx stdlib/pervasives.$O stdlib/pervasives.p.$O \ + stdlib/printexc.cmx stdlib/printexc.p.cmx stdlib/printexc.$O stdlib/printexc.p.$O \ + stdlib/printf.cmx stdlib/printf.p.cmx stdlib/printf.$O stdlib/printf.p.$O \ + stdlib/queue.cmx stdlib/queue.p.cmx stdlib/queue.$O stdlib/queue.p.$O \ + stdlib/random.cmx stdlib/random.p.cmx stdlib/random.$O stdlib/random.p.$O \ + stdlib/scanf.cmx stdlib/scanf.p.cmx stdlib/scanf.$O stdlib/scanf.p.$O \ + stdlib/sort.cmx stdlib/sort.p.cmx stdlib/sort.$O stdlib/sort.p.$O \ + stdlib/stack.cmx stdlib/stack.p.cmx stdlib/stack.$O stdlib/stack.p.$O \ + stdlib/stdLabels.cmx stdlib/stdLabels.p.cmx stdlib/stdLabels.$O stdlib/stdLabels.p.$O \ + stdlib/std_exit.cmx stdlib/std_exit.p.cmx stdlib/std_exit.$O stdlib/std_exit.p.$O \ + stdlib/stream.cmx stdlib/stream.p.cmx stdlib/stream.$O stdlib/stream.p.$O \ + stdlib/string.cmx stdlib/string.p.cmx stdlib/string.$O stdlib/string.p.$O \ + stdlib/stringLabels.cmx stdlib/stringLabels.p.cmx stdlib/stringLabels.$O stdlib/stringLabels.p.$O \ + stdlib/sys.cmx stdlib/sys.p.cmx stdlib/sys.$O stdlib/sys.p.$O \ + stdlib/weak.cmx stdlib/weak.p.cmx stdlib/weak.$O stdlib/weak.p.$O \ + stdlib/$set.cmx stdlib/$set.p.cmx stdlib/$set.$O stdlib/$set.p.$O \ + $LIBDIR + +installlibdir \ + stdlib/stdlib.$A stdlib/stdlib.p.$A \ + $LIBDIR + +echo "Installing ocamllex, ocamldebug..." +installbin lex/ocamllex$EXE $BINDIR/ocamllex$EXE +installbin debugger/ocamldebug$EXE $BINDIR/ocamldebug$EXE +installbin lex/ocamllex.opt$EXE $BINDIR/ocamllex.opt$EXE +installbin tools/ocamldep.native$EXE $BINDIR/ocamldep.opt$EXE + +echo "Installing some tools..." +installbin tools/ocamlcp.byte$EXE $BINDIR/ocamlcp$EXE +installbin tools/ocamldep.byte$EXE $BINDIR/ocamldep$EXE +installbin tools/ocamlmklib.byte$EXE $BINDIR/ocamlmklib$EXE +installbin tools/ocamlmktop.byte$EXE $BINDIR/ocamlmktop$EXE +installbin tools/ocamlprof.byte$EXE $BINDIR/ocamlprof$EXE +installbin toplevel/expunge.byte$EXE $LIBDIR/expunge$EXE +installbin tools/addlabels.byte $LIBDIR/addlabels +installbin tools/scrapelabels.byte $LIBDIR/scrapelabels +installbin otherlibs/dynlink/extract_crc.byte $LIBDIR/extract_crc +installbin otherlibs/labltk/lib/labltk$EXE $BINDIR/labltk$EXE +installbin otherlibs/labltk/compiler/tkcompiler$EXE $BINDIR/tkcompiler$EXE +installbin otherlibs/labltk/browser/ocamlbrowser$EXE $BINDIR/ocamlbrowser$EXE +installbin otherlibs/labltk/compiler/pp$EXE $LIBDIR/labltk/pp$EXE +installbin otherlibs/labltk/lib/labltktop$EXE $LIBDIR/labltk/labltktop$EXE + +echo "Installing libraries..." +installdir \ + otherlibs/bigarray/bigarray.cma \ + otherlibs/dbm/dbm.cma \ + otherlibs/dynlink/dynlink.cma \ + otherlibs/"$WIN32"graph/graphics.cma \ + otherlibs/num/nums.cma \ + otherlibs/str/str.cma \ + otherlibs/"$WIN32"unix/unix.cma \ + otherlibs/bigarray/bigarray.cmxa \ + otherlibs/dbm/dbm.cmxa \ + otherlibs/"$WIN32"graph/graphics.cmxa \ + otherlibs/num/nums.cmxa \ + otherlibs/str/str.cmxa \ + otherlibs/"$WIN32"unix/unix.cmxa \ + toplevel/toplevellib.cma \ + otherlibs/systhreads/thread.mli \ + otherlibs/systhreads/mutex.mli \ + otherlibs/systhreads/condition.mli \ + otherlibs/systhreads/event.mli \ + otherlibs/systhreads/threadUnix.mli \ + $LIBDIR + +installdir \ + otherlibs/labltk/support/fileevent.mli \ + otherlibs/labltk/support/fileevent.cmi \ + otherlibs/labltk/support/fileevent.cmx \ + otherlibs/labltk/support/protocol.mli \ + otherlibs/labltk/support/protocol.cmi \ + otherlibs/labltk/support/protocol.cmx \ + otherlibs/labltk/support/textvariable.mli \ + otherlibs/labltk/support/textvariable.cmi \ + otherlibs/labltk/support/textvariable.cmx \ + otherlibs/labltk/support/timer.mli \ + otherlibs/labltk/support/timer.cmi \ + otherlibs/labltk/support/timer.cmx \ + otherlibs/labltk/support/rawwidget.mli \ + otherlibs/labltk/support/rawwidget.cmi \ + otherlibs/labltk/support/rawwidget.cmx \ + otherlibs/labltk/support/widget.mli \ + otherlibs/labltk/support/widget.cmi \ + otherlibs/labltk/support/widget.cmx \ + otherlibs/labltk/support/tkthread.mli \ + otherlibs/labltk/support/tkthread.cmi \ + otherlibs/labltk/support/tkthread.cmo \ + otherlibs/labltk/support/tkthread.$O \ + otherlibs/labltk/labltk/*.mli \ + otherlibs/labltk/labltk/*.cmi \ + otherlibs/labltk/labltk/*.cmx \ + otherlibs/labltk/camltk/*.mli \ + otherlibs/labltk/camltk/*.cmi \ + otherlibs/labltk/camltk/*.cmx \ + otherlibs/labltk/frx/frxlib.cma \ + otherlibs/labltk/frx/frxlib.cmxa \ + otherlibs/labltk/frx/*.mli \ + otherlibs/labltk/frx/*.cmi \ + otherlibs/labltk/frx/*.cmx \ + otherlibs/labltk/jpf/jpflib.cma \ + otherlibs/labltk/jpf/jpflib.cmxa \ + otherlibs/labltk/jpf/*.mli \ + otherlibs/labltk/jpf/*.cmi \ + otherlibs/labltk/jpf/*.cmx \ + otherlibs/labltk/lib/labltk.cma \ + otherlibs/labltk/lib/labltk.cmxa \ + otherlibs/labltk/tkanim/*.mli \ + otherlibs/labltk/tkanim/*.cmi \ + otherlibs/labltk/tkanim/tkanim.cma \ + otherlibs/labltk/tkanim/tkanim.cmxa \ + $LIBDIR/labltk + +installdir \ + otherlibs/systhreads/threads.cma \ + otherlibs/systhreads/threads.cmxa \ + otherlibs/systhreads/thread.cmi \ + otherlibs/systhreads/mutex.cmi \ + otherlibs/systhreads/condition.cmi \ + otherlibs/systhreads/event.cmi \ + otherlibs/systhreads/threadUnix.cmi \ + $LIBDIR/threads + +installdir \ + otherlibs/bigarray/dllbigarray$EXT_DLL \ + otherlibs/dbm/dllmldbm$EXT_DLL \ + otherlibs/"$WIN32"graph/dllgraphics$EXT_DLL \ + otherlibs/num/dllnums$EXT_DLL \ + otherlibs/str/dllstr$EXT_DLL \ + otherlibs/systhreads/dllthreads$EXT_DLL \ + otherlibs/"$WIN32"unix/dllunix$EXT_DLL \ + otherlibs/threads/dllvmthreads$EXT_DLL \ + otherlibs/labltk/support/dlllabltk$EXT_DLL \ + otherlibs/labltk/tkanim/dlltkanim$EXT_DLL \ + $STUBLIBDIR + +installlibdir \ + otherlibs/threads/libvmthreads.$A \ + $LIBDIR/vmthreads + +installdir \ + otherlibs/threads/thread.cmi \ + otherlibs/threads/thread.mli \ + otherlibs/threads/mutex.cmi \ + otherlibs/threads/mutex.mli \ + otherlibs/threads/condition.cmi \ + otherlibs/threads/condition.mli \ + otherlibs/threads/event.cmi \ + otherlibs/threads/event.mli \ + otherlibs/threads/threadUnix.cmi \ + otherlibs/threads/threadUnix.mli \ + otherlibs/threads/threads.cma \ + otherlibs/threads/stdlib.cma \ + otherlibs/threads/unix.cma \ + $LIBDIR/vmthreads + +installlibdir \ + otherlibs/labltk/support/liblabltk.$A \ + otherlibs/labltk/lib/labltk.$A \ + otherlibs/labltk/jpf/jpflib.$A \ + otherlibs/labltk/tkanim/libtkanim.$A \ + otherlibs/labltk/tkanim/tkanim.$A \ + otherlibs/labltk/frx/frxlib.$A \ + $LIBDIR/labltk + +installlibdir \ + otherlibs/bigarray/libbigarray.$A \ + otherlibs/dbm/libmldbm.$A \ + otherlibs/"$WIN32"graph/libgraphics.$A \ + otherlibs/num/libnums.$A \ + otherlibs/str/libstr.$A \ + otherlibs/systhreads/libthreads.$A \ + otherlibs/systhreads/libthreadsnat.$A \ + otherlibs/"$WIN32"unix/libunix.$A \ + $LIBDIR + +echo "Installing object files and interfaces..." +installdir \ + tools/profiling.cm[oi] \ + toplevel/topstart.cmo \ + toplevel/toploop.cmi \ + toplevel/topdirs.cmi \ + toplevel/topmain.cmi \ + typing/outcometree.cmi \ + otherlibs/graph/graphicsX11.cmi \ + otherlibs/dynlink/dynlink.cmi \ + otherlibs/num/arith_status.cmi \ + otherlibs/num/big_int.cmi \ + otherlibs/num/nat.cmi \ + otherlibs/num/num.cmi \ + otherlibs/num/ratio.cmi \ + otherlibs/bigarray/bigarray.cmi \ + otherlibs/dbm/dbm.cmi \ + otherlibs/"$WIN32"graph/graphics.cmi \ + otherlibs/str/str.cmi \ + otherlibs/"$WIN32"unix/unix.cmi \ + otherlibs/"$WIN32"unix/unixLabels.cmi \ + otherlibs/num/arith_flags.cmx \ + otherlibs/num/arith_flags.$O \ + otherlibs/num/int_misc.cmx \ + otherlibs/num/int_misc.$O \ + otherlibs/num/arith_status.cmx \ + otherlibs/num/arith_status.$O \ + otherlibs/num/big_int.cmx \ + otherlibs/num/big_int.$O \ + otherlibs/num/nat.cmx \ + otherlibs/num/nat.$O \ + otherlibs/num/num.cmx \ + otherlibs/num/num.$O \ + otherlibs/num/ratio.cmx \ + otherlibs/num/ratio.$O \ + otherlibs/bigarray/bigarray.cmx \ + otherlibs/bigarray/bigarray.$O \ + otherlibs/dbm/dbm.cmx \ + otherlibs/dbm/dbm.$O \ + otherlibs/"$WIN32"graph/graphics.cmx \ + otherlibs/"$WIN32"graph/graphics.$O \ + otherlibs/str/str.cmx \ + otherlibs/str/str.$O \ + otherlibs/"$WIN32"unix/unix.cmx \ + otherlibs/"$WIN32"unix/unix.$O \ + otherlibs/"$WIN32"unix/unixLabels.cmx \ + otherlibs/"$WIN32"unix/unixLabels.$O \ + $LIBDIR + +installlibdir \ + otherlibs/bigarray/bigarray.$A \ + otherlibs/dbm/dbm.$A \ + otherlibs/"$WIN32"graph/graphics.$A \ + otherlibs/num/nums.$A \ + otherlibs/str/str.$A \ + otherlibs/"$WIN32"unix/unix.$A \ + stdlib/stdlib.$A \ + $LIBDIR + +installlibdir \ + otherlibs/systhreads/threads.$A \ + $LIBDIR/threads + +echo "Installing manuals..." +(cd ../man && make install) + +echo "Installing ocamldoc..." +installbin ocamldoc/ocamldoc $BINDIR/ocamldoc$EXE +installbin ocamldoc/ocamldoc.opt $BINDIR/ocamldoc.opt$EXE + +installdir \ + ../ocamldoc/ocamldoc.hva \ + ocamldoc/*.cmi \ + ocamldoc/odoc_info.mli ocamldoc/odoc_info.cm[ia] ocamldoc/odoc_info.cmxa \ + ocamldoc/odoc_info.$A \ + $LIBDIR/ocamldoc + +installdir \ + ocamldoc/stdlib_man/* \ + $MANDIR/man3 + +echo "Installing camlp4..." +installbin camlp4/camlp4prof.byte$EXE $BINDIR/camlp4prof$EXE +installbin camlp4/mkcamlp4.byte$EXE $BINDIR/mkcamlp4$EXE +installbin camlp4/camlp4.byte$EXE $BINDIR/camlp4$EXE +installbin camlp4/camlp4boot.byte$EXE $BINDIR/camlp4boot$EXE +installbin camlp4/camlp4o.byte$EXE $BINDIR/camlp4o$EXE +installbin camlp4/camlp4of.byte$EXE $BINDIR/camlp4of$EXE +installbin camlp4/camlp4oof.byte$EXE $BINDIR/camlp4oof$EXE +installbin camlp4/camlp4orf.byte$EXE $BINDIR/camlp4orf$EXE +installbin camlp4/camlp4r.byte$EXE $BINDIR/camlp4r$EXE +installbin camlp4/camlp4rf.byte$EXE $BINDIR/camlp4rf$EXE +installbin camlp4/camlp4o.native$EXE $BINDIR/camlp4o.opt$EXE +installbin camlp4/camlp4of.native$EXE $BINDIR/camlp4of.opt$EXE +installbin camlp4/camlp4oof.native$EXE $BINDIR/camlp4oof.opt$EXE +installbin camlp4/camlp4orf.native$EXE $BINDIR/camlp4orf.opt$EXE +installbin camlp4/camlp4r.native$EXE $BINDIR/camlp4r.opt$EXE +installbin camlp4/camlp4rf.native$EXE $BINDIR/camlp4rf.opt$EXE + +cd camlp4 +CAMLP4DIR=$LIBDIR/camlp4 +for dir in Camlp4Parsers Camlp4Printers Camlp4Filters Camlp4Top; do + echo "Installing $dir..." + mkdir -p $CAMLP4DIR/$dir + installdir \ + $dir/*.cm* \ + $dir/*.$O \ + $CAMLP4DIR/$dir +done +installdir \ + camlp4lib.cma camlp4lib.cmxa Camlp4.cmi \ + camlp4fulllib.cma camlp4fulllib.cmxa \ + camlp4o.cma camlp4of.cma camlp4oof.cma \ + camlp4orf.cma camlp4r.cma camlp4rf.cma \ + Camlp4Bin.cm[iox] Camlp4Bin.$O Camlp4Top.cm[io] \ + Camlp4_config.cmi camlp4prof.cm[iox] camlp4prof.$O Camlp4_import.cmi \ + $CAMLP4DIR +installlibdir camlp4lib.$A camlp4fulllib.$A $CAMLP4DIR +cd .. + +echo "Installing ocamlbuild..." + +cd ocamlbuild +installbin ocamlbuild.byte$EXE $BINDIR/ocamlbuild.byte$EXE +installbin ocamlbuild.native$EXE $BINDIR/ocamlbuild.native$EXE +installbestbin ocamlbuild.native$EXE ocamlbuild.byte$EXE $BINDIR/ocamlbuild$EXE + +installlibdir \ + ocamlbuildlib.$A \ + $LIBDIR/ocamlbuild + +installdir \ + ocamlbuildlib.cmxa \ + ocamlbuildlib.cma \ + ocamlbuild_plugin.cmi \ + ocamlbuild_pack.cmi \ + ocamlbuild_unix_plugin.cmi \ + ocamlbuild_unix_plugin.cmo \ + ocamlbuild_unix_plugin.cmx \ + ocamlbuild_unix_plugin.$O \ + ocamlbuild_executor.cmi \ + ocamlbuild_executor.cmo \ + ocamlbuild_executor.cmx \ + ocamlbuild_executor.$O \ + ocamlbuild.cmo \ + ocamlbuild.cmx \ + ocamlbuild.$O \ + $LIBDIR/ocamlbuild +cd .. + +installdir \ + ../ocamlbuild/man/ocamlbuild.1 \ + $MANDIR/man1 diff --git a/build/mixed-boot.sh b/build/mixed-boot.sh new file mode 100644 index 0000000..122ff41 --- /dev/null +++ b/build/mixed-boot.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +set -ex +cd `dirname $0`/.. +touch build/ocamlbuild_mixed_mode +mkdir -p _build +cp -rf boot _build/ +./build/mkconfig.sh +./build/mkmyocamlbuild_config.sh +./build/boot.sh diff --git a/build/mkconfig.sh b/build/mkconfig.sh new file mode 100755 index 0000000..e774ae2 --- /dev/null +++ b/build/mkconfig.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# $Id: mkconfig.sh,v 1.3 2007-11-06 15:16:56 frisch Exp $ + +cd `dirname $0`/.. + +sed -e 's/^\(.*\$([0-9]).*\)$/# \1/' \ + -e 's/\$(\([^)]*\))/${\1}/g' \ + -e 's/^FLEX.*$//g' \ + -e 's/^\([^#=]*\)=\([^"]*\)$/if [ "x$\1" = "x" ]; then \1="\2"; fi/' \ + config/Makefile > config/config.sh + + diff --git a/build/mkmyocamlbuild_config.sh b/build/mkmyocamlbuild_config.sh new file mode 100755 index 0000000..1cae269 --- /dev/null +++ b/build/mkmyocamlbuild_config.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: mkmyocamlbuild_config.sh,v 1.10 2008-01-11 16:13:16 doligez Exp $ + +cd `dirname $0`/.. + +sed \ + -e 's/^.*FLEXDIR.*$//g' \ + -e 's/^#ml \(.*\)/\1/' \ + -e 's/^\(#.*\)$/(* \1 *)/' \ + -e 's/^\(.*\$([0-9]).*\)$/(* \1 *)/' \ + -e 's/^\([^(=]*\)=\([^"]*\)$/let <:lower<\1>> = "\2";;/' \ + -e 's/\$(AS)/as/g' \ + -e 's/\$(\([^)]*\))/"\^<:lower<\1>>\^"/g' \ + -e 's/""\^//g' \ + -e 's/\^""//g' \ + -e 's/^let <:lower myocamlbuild_config.ml diff --git a/build/mkruntimedef.sh b/build/mkruntimedef.sh new file mode 100755 index 0000000..74ce22e --- /dev/null +++ b/build/mkruntimedef.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# $Id: mkruntimedef.sh,v 1.2 2007-10-08 14:19:34 doligez Exp $ +echo 'let builtin_exceptions = [|'; \ +sed -n -e 's|.*/\* \("[A-Za-z_]*"\) \*/$| \1;|p' byterun/fail.h | \ +sed -e '$s/;$//'; \ +echo '|]'; \ +echo 'let builtin_primitives = [|'; \ +sed -e 's/.*/ "&";/' -e '$s/;$//' byterun/primitives; \ +echo '|]' diff --git a/build/myocamlbuild.sh b/build/myocamlbuild.sh new file mode 100755 index 0000000..28f4155 --- /dev/null +++ b/build/myocamlbuild.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# $Id: myocamlbuild.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +cd `dirname $0`/.. +set -xe +if [ ! -x _build/ocamlbuild/ocamlbuildlight.byte ]; then + if [ ! -x ocamlbuild/_build/ocamlbuildlight.byte ]; then + (cd ocamlbuild && make) + fi + mkdir -p _build/ocamlbuild + for i in "light.cmo" "light.byte" "lightlib.cma" "_plugin.cmi" "_pack.cmi" + do + cp ocamlbuild/_build/ocamlbuild$i _build/ocamlbuild + done +fi +rm -f ocamlbuild/myocamlbuild_config.ml ocamlbuild/myocamlbuild_config.mli +rm -rf _build/myocamlbuild boot/myocamlbuild boot/myocamlbuild.native +./boot/ocamlrun _build/ocamlbuild/ocamlbuildlight.byte -no-hygiene \ + -tag debug -install-lib-dir _build/ocamlbuild -byte-plugin -just-plugin +cp _build/myocamlbuild boot/myocamlbuild.boot diff --git a/build/new-build-system b/build/new-build-system new file mode 100644 index 0000000..b16f6de --- /dev/null +++ b/build/new-build-system @@ -0,0 +1,41 @@ +_tags # Defines tags to setup exceptions +myocamlbuild.ml # Contains all needed rules that are differents +boot/ocamldep +myocamlbuild_config.mli +utils/config.mlbuild # Should be renamed as utils/config.ml + +# Files that just contain module names of object files. +**/*.mllib # Files that describe the contents of an OCaml library +**/*.mlpack # Files that describe the contents of an OCaml package +**/*.cilb # Files that describe the contents of an C static library +**/*.dilb # Files that describe the contents of an C dynamic library + +build/ + world.sh # Build all the OCaml world + fastworld.sh # Same as above but faster + boot-c-parts.sh # Compile byterun, ocamlyacc and asmrun with the Makefiles + boot-c-parts-windows.sh # Same as boot-c-parts.sh but for windows + boot.sh # Compile the stdlib and ocamlc + camlp4-targets.sh # Setup camlp4 targets + otherlibs-targets.sh # Setup otherlibs targets + targets.sh # All targets of the OCaml distribution + + world.byte.sh # Build the bytecode world + world.native.sh # Build the native world + world.all.sh # Build all the world the don't bootstrap + + install.sh # Install all needed files + distclean.sh # Clean all generated files + + myocamlbuild.sh # Regenerate the boot/myocamlbuild program + mkconfig.sh # Generate config/config.sh + mkmyocamlbuild_config.sh # Generate myocamlbuild_config.ml + + camlp4-bootstrap.sh + + # Partial stuffs (just camlp4 and ocamlbuild) + partial-boot.sh + camlp4-byte-only.sh + camlp4-native-only.sh + ocamlbuild-byte-only.sh + ocamlbuild-native-only.sh diff --git a/build/ocamlbuild-byte-only.sh b/build/ocamlbuild-byte-only.sh new file mode 100755 index 0000000..eaf403f --- /dev/null +++ b/build/ocamlbuild-byte-only.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: ocamlbuild-byte-only.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ byte_stdlib_mixed_mode $OCAMLC_BYTE $OCAMLLEX_BYTE $OCAMLBUILD_BYTE diff --git a/build/ocamlbuild-native-only.sh b/build/ocamlbuild-native-only.sh new file mode 100755 index 0000000..72e732f --- /dev/null +++ b/build/ocamlbuild-native-only.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: ocamlbuild-native-only.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ native_stdlib_mixed_mode $OCAMLOPT_BYTE $OCAMLLEX_BYTE $OCAMLBUILD_NATIVE diff --git a/build/ocamlbuildlib-native-only.sh b/build/ocamlbuildlib-native-only.sh new file mode 100755 index 0000000..ab51915 --- /dev/null +++ b/build/ocamlbuildlib-native-only.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: ocamlbuildlib-native-only.sh,v 1.4 2008-12-03 18:09:09 doligez Exp $ + +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ native_stdlib_mixed_mode $OCAMLOPT_BYTE $OCAMLLEX_BYTE $OCAMLBUILDLIB_NATIVE diff --git a/build/otherlibs-targets.sh b/build/otherlibs-targets.sh new file mode 100644 index 0000000..ad8e524 --- /dev/null +++ b/build/otherlibs-targets.sh @@ -0,0 +1,109 @@ +#!/bin/sh +# $Id: otherlibs-targets.sh,v 1.4 2007-11-29 10:32:38 ertai Exp $ +OTHERLIBS_BYTE="" +OTHERLIBS_NATIVE="" +OTHERLIBS_UNIX_NATIVE="" +UNIXDIR="otherlibs/unix" + +add_native() { + for native_file in $@; do + OTHERLIBS_NATIVE="$OTHERLIBS_NATIVE otherlibs/$lib/$native_file" + case $lib in + unix|win32unix) + OTHERLIBS_UNIX_NATIVE="$OTHERLIBS_UNIX_NATIVE otherlibs/$lib/$native_file";; + esac + done +} + +add_byte() { + for byte_file in $@; do + OTHERLIBS_BYTE="$OTHERLIBS_BYTE otherlibs/$lib/$byte_file" + done +} + +add_file() { + add_byte $@ + add_native $@ +} + +add_bin() { + for bin_file in $@; do + add_byte $bin_file.byte$EXE + add_native $bin_file.native$EXE + done +} + +add_c_lib() { + add_file "lib$1.$A" +} + +add_ocaml_lib() { + add_native "$1.cmxa" + add_byte "$1.cma" +} + +add_dll() { + add_file "dll$1$EXT_DLL" +} + +add() { + add_c_lib $1 + add_ocaml_lib $1 + add_dll $1 +} + +THREADS_CMIS="thread.cmi mutex.cmi condition.cmi event.cmi threadUnix.cmi" + +for lib in $OTHERLIBRARIES; do + case $lib in + num) + add nums;; + systhreads) + add_ocaml_lib threads + add_dll threads + add_file $THREADS_CMIS + add_byte libthreads.$A + add_native libthreadsnat.$A;; + graph|win32graph) + add graphics;; + threads) + add_byte pervasives.cmi pervasives.mli \ + $THREADS_CMIS marshal.cmi marshal.mli \ + stdlib.cma unix.cma threads.cma libvmthreads.$A;; + labltk) + add_file support/camltk.h + add_byte support/byte.otarget + add_native support/native.otarget + add_file support/liblabltk.$A + add_byte compiler/tkcompiler$EXE compiler/pp$EXE + add_file labltk/tk.ml labltk/labltk.ml + add_byte labltk/byte.otarget + add_native labltk/native.otarget + add_byte camltk/byte.otarget + add_native camltk/native.otarget + add_ocaml_lib lib/labltk + add_byte lib/labltktop$EXE lib/labltk$EXE + add_ocaml_lib jpf/jpflib + add_ocaml_lib frx/frxlib + add_ocaml_lib tkanim/tkanim + add_file tkanim/libtkanim.$A + add_byte browser/ocamlbrowser$EXE + ;; + dbm) + add_ocaml_lib dbm + add_c_lib mldbm;; + dynlink) + add_ocaml_lib dynlink + add_native dynlink.cmx + add_file $lib.cmi extract_crc;; + win32unix) + UNIXDIR="otherlibs/win32unix" + add_file unixsupport.h cst2constr.h socketaddr.h + add unix;; + unix) + add_file unixsupport.h + add unix;; + *) + add $lib + esac +done diff --git a/build/partial-install.sh b/build/partial-install.sh new file mode 100755 index 0000000..e56df8d --- /dev/null +++ b/build/partial-install.sh @@ -0,0 +1,186 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: partial-install.sh,v 1.9 2008-01-11 16:13:16 doligez Exp $ + +###################################### +######### Copied from build/install.sh +###################################### + +set -e + +cd `dirname $0`/.. + +. config/config.sh + +not_installed=$PWD/_build/not_installed + +rm -f "$not_installed" +touch "$not_installed" + +wontinstall() { + echo "$1" >> "$not_installed" + echo " don't install $1" +} + +installbin() { + if [ -f "$1" ]; then + echo " install binary $2" + cp -f "$1" "$2" + [ -x "$2" ] || chmod +x "$2" + else + wontinstall "$1" + fi +} + +installbestbin() { + if [ -f "$1" ]; then + echo " install binary $3 (with `basename $1`)" + cp -f "$1" "$3" + else + if [ -f "$2" ]; then + echo " install binary $3 (with `basename $2`)" + cp -f "$2" "$3" + else + echo "None of $1, $2 exists" + exit 3 + fi + fi + [ -x "$3" ] || chmod +x "$3" +} + +installlib() { + if [ -f "$1" ]; then + dest="$2/`basename $1`" + echo " install library $dest" + cp -f "$1" "$2" + if [ "$RANLIB" != "" ]; then + "$RANLIB" "$dest" + fi + else + wontinstall "$1" + fi +} + +installdir() { + args="" + while [ $# -gt 1 ]; do + if [ -f "$1" ]; then + args="$args $1" + else + wontinstall "$1" + fi + shift + done + last="$1" + for file in $args; do + echo " install $last/`basename $file`" + cp -f "$file" "$last" + done +} + +installlibdir() { + args="" + while [ $# -gt 1 ]; do + args="$args $1" + shift + done + last="$1" + for file in $args; do + installlib "$file" "$last" + done +} + +mkdir -p $BINDIR +mkdir -p $LIBDIR +mkdir -p $LIBDIR/camlp4 +mkdir -p $LIBDIR/ocamlbuild +mkdir -p $STUBLIBDIR +mkdir -p $MANDIR/man1 +mkdir -p $MANDIR/man3 +mkdir -p $MANDIR/man$MANEXT + +cd _build + +echo "Installing camlp4..." +installbin camlp4/camlp4prof.byte$EXE $BINDIR/camlp4prof$EXE +installbin camlp4/mkcamlp4.byte$EXE $BINDIR/mkcamlp4$EXE +installbin camlp4/camlp4.byte$EXE $BINDIR/camlp4$EXE +installbin camlp4/camlp4boot.byte$EXE $BINDIR/camlp4boot$EXE +installbin camlp4/camlp4o.byte$EXE $BINDIR/camlp4o$EXE +installbin camlp4/camlp4of.byte$EXE $BINDIR/camlp4of$EXE +installbin camlp4/camlp4oof.byte$EXE $BINDIR/camlp4oof$EXE +installbin camlp4/camlp4orf.byte$EXE $BINDIR/camlp4orf$EXE +installbin camlp4/camlp4r.byte$EXE $BINDIR/camlp4r$EXE +installbin camlp4/camlp4rf.byte$EXE $BINDIR/camlp4rf$EXE +installbin camlp4/camlp4o.native$EXE $BINDIR/camlp4o.opt$EXE +installbin camlp4/camlp4of.native$EXE $BINDIR/camlp4of.opt$EXE +installbin camlp4/camlp4oof.native$EXE $BINDIR/camlp4oof.opt$EXE +installbin camlp4/camlp4orf.native$EXE $BINDIR/camlp4orf.opt$EXE +installbin camlp4/camlp4r.native$EXE $BINDIR/camlp4r.opt$EXE +installbin camlp4/camlp4rf.native$EXE $BINDIR/camlp4rf.opt$EXE + +cd camlp4 +CAMLP4DIR=$LIBDIR/camlp4 +for dir in Camlp4Parsers Camlp4Printers Camlp4Filters Camlp4Top; do + echo "Installing $dir..." + mkdir -p $CAMLP4DIR/$dir + installdir \ + $dir/*.cm* \ + $dir/*.$O \ + $CAMLP4DIR/$dir +done +installdir \ + camlp4lib.cma camlp4lib.cmxa Camlp4.cmi \ + camlp4fulllib.cma camlp4fulllib.cmxa \ + camlp4o.cma camlp4of.cma camlp4oof.cma \ + camlp4orf.cma camlp4r.cma camlp4rf.cma \ + Camlp4Bin.cm[iox] Camlp4Bin.$O Camlp4Top.cm[io] \ + Camlp4_config.cmi camlp4prof.cm[iox] camlp4prof.$O Camlp4_import.cmi \ + $CAMLP4DIR +installlibdir camlp4lib.$A camlp4fulllib.$A $CAMLP4DIR +cd .. + +echo "Installing ocamlbuild..." +cd ocamlbuild +installbin ocamlbuild.byte$EXE $BINDIR/ocamlbuild.byte$EXE +installbin ocamlbuild.native$EXE $BINDIR/ocamlbuild.native$EXE +installbestbin ocamlbuild.native$EXE ocamlbuild.byte$EXE $BINDIR/ocamlbuild$EXE + +installlibdir \ + ocamlbuildlib.$A \ + $LIBDIR/ocamlbuild + +installdir \ + ocamlbuildlib.cmxa \ + ocamlbuildlib.cma \ + ocamlbuild_plugin.cmi \ + ocamlbuild_pack.cmi \ + ocamlbuild_unix_plugin.cmi \ + ocamlbuild_unix_plugin.cmo \ + ocamlbuild_unix_plugin.cmx \ + ocamlbuild_unix_plugin.$O \ + ocamlbuild_executor.cmi \ + ocamlbuild_executor.cmo \ + ocamlbuild_executor.cmx \ + ocamlbuild_executor.$O \ + ocamlbuild.cmo \ + ocamlbuild.cmx \ + ocamlbuild.$O \ + $LIBDIR/ocamlbuild +cd .. + +installdir \ + ../ocamlbuild/man/ocamlbuild.1 \ + $MANDIR/man1 diff --git a/build/targets.sh b/build/targets.sh new file mode 100644 index 0000000..a0da0ad --- /dev/null +++ b/build/targets.sh @@ -0,0 +1,63 @@ +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2007 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: targets.sh,v 1.5 2008-01-11 16:13:16 doligez Exp $ + +. config/config.sh +. build/otherlibs-targets.sh +. build/camlp4-targets.sh + +INSTALL_BIN="$BINDIR" +export INSTALL_BIN + +STDLIB_BYTE="stdlib/libcamlrun.$A stdlib/stdlib.cma \ + stdlib/std_exit.cmo stdlib/camlheader stdlib/camlheader_ur" +OCAMLLEX_BYTE=lex/ocamllex$EXE +OCAMLC_BYTE=ocamlc$EXE +OCAMLOPT_BYTE=ocamlopt$EXE +OCAMLBUILD_BYTE="ocamlbuild/ocamlbuildlib.cma \ + ocamlbuild/ocamlbuildlightlib.cma \ + ocamlbuild/ocamlbuild.byte$EXE \ + ocamlbuild/ocamlbuildlight.byte$EXE" +TOPLEVEL=ocaml$EXE +TOOLS_BYTE="tools/ocamldep.byte$EXE tools/profiling.cmo \ + tools/ocamlprof.byte$EXE tools/ocamlcp.byte$EXE \ + tools/ocamlmktop.byte$EXE tools/ocamlmklib$EXE \ + tools/scrapelabels.byte tools/addlabels.byte \ + tools/dumpobj.byte$EXE" +if [ ! -z "$DEBUGGER" ]; then + DEBUGGER=debugger/ocamldebug$EXE +fi +OCAMLDOC_BYTE="ocamldoc/ocamldoc$EXE ocamldoc/odoc_info.cma" +STDLIB_NATIVE="stdlib/stdlib.cmxa stdlib/std_exit.cmx asmrun/libasmrun.$A" +case $PROFILING in +prof) + STDLIB_NATIVE="$STDLIB_NATIVE asmrun/libasmrunp.$A \ + stdlib/stdlib.p.cmxa stdlib/std_exit.p.cmx";; +noprof) ;; +*) echo "unexpected PROFILING value $PROFILING"; exit 1;; +esac +OCAMLC_NATIVE=ocamlc.opt$EXE +OCAMLOPT_NATIVE=ocamlopt.opt$EXE +OCAMLLEX_NATIVE=lex/ocamllex.opt$EXE +TOOLS_NATIVE=tools/ocamldep.native$EXE +OCAMLDOC_NATIVE="ocamldoc/ocamldoc.opt$EXE ocamldoc/odoc_info.cmxa ocamldoc/stdlib_man/Pervasives.3o" +OCAMLBUILDLIB_NATIVE="ocamlbuild/ocamlbuildlib.cmxa \ + ocamlbuild/ocamlbuildlightlib.cmxa" +OCAMLBUILD_NATIVE="$OCAMLBUILDLIB_NATIVE \ + ocamlbuild/ocamlbuild.native$EXE \ + ocamlbuild/ocamlbuildlight.native$EXE" +if [ -x boot/myocamlbuild.native ]; then + OCAMLBUILD=./boot/myocamlbuild.native +else + OCAMLBUILD="./boot/ocamlrun boot/myocamlbuild" +fi diff --git a/build/tolower.sed b/build/tolower.sed new file mode 100644 index 0000000..ccd55fc --- /dev/null +++ b/build/tolower.sed @@ -0,0 +1,11 @@ +# tolower.sed expands one ...<:lower>... to ...foo... per line +h +s/.*<:lower<\(.*\)>>.*/\1/ +t cont +b end +:cont +y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ +s/$/|/ +G +s/\(.*\)|\n\(.*\)<:lower<\(.*\)>>/\2\1/ +:end diff --git a/build/world.all.sh b/build/world.all.sh new file mode 100755 index 0000000..a1731d8 --- /dev/null +++ b/build/world.all.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# $Id: world.all.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ \ + $STDLIB_BYTE $OCAMLC_BYTE $OCAMLLEX_BYTE $OCAMLOPT_BYTE $TOPLEVEL \ + $TOOLS_BYTE $OTHERLIBS_BYTE $OCAMLBUILD_BYTE $DEBUGGER $OCAMLDOC_BYTE \ + $CAMLP4_BYTE $STDLIB_NATIVE $OCAMLC_NATIVE $OCAMLOPT_NATIVE \ + $OCAMLLEX_NATIVE $TOOLS_NATIVE $OTHERLIBS_NATIVE \ + $OCAMLBUILD_NATIVE $OCAMLDOC_NATIVE $CAMLP4_NATIVE diff --git a/build/world.byte.sh b/build/world.byte.sh new file mode 100755 index 0000000..d2c83ae --- /dev/null +++ b/build/world.byte.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# $Id: world.byte.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ \ + $STDLIB_BYTE $OCAMLC_BYTE $OCAMLLEX_BYTE $OCAMLOPT_BYTE $TOPLEVEL $TOOLS_BYTE \ + $OTHERLIBS_BYTE $OCAMLBUILD_BYTE $DEBUGGER $OCAMLDOC_BYTE $CAMLP4_BYTE diff --git a/build/world.native.sh b/build/world.native.sh new file mode 100755 index 0000000..78387d6 --- /dev/null +++ b/build/world.native.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# $Id: world.native.sh,v 1.3 2007-10-08 14:19:34 doligez Exp $ +set -e +cd `dirname $0`/.. +. build/targets.sh +set -x +$OCAMLBUILD $@ \ + $STDLIB_NATIVE $OCAMLC_NATIVE $OCAMLOPT_NATIVE \ + $OCAMLLEX_NATIVE $TOOLS_NATIVE $OTHERLIBS_NATIVE \ + $OCAMLBUILD_NATIVE $OCAMLDOC_NATIVE $CAMLP4_NATIVE diff --git a/build/world.sh b/build/world.sh new file mode 100755 index 0000000..c015677 --- /dev/null +++ b/build/world.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2008 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: world.sh,v 1.5 2008-12-03 18:09:09 doligez Exp $ + +cd `dirname $0` +set -e +if [ -e ocamlbuild_mixed_mode ]; then + echo ocamlbuild mixed mode detected + echo 'please cleanup and re-launch (make clean ; ./build/distclean.sh)' + exit 1 +fi +./mkconfig.sh +./mkmyocamlbuild_config.sh +. ../config/config.sh +if [ "x$EXE" = "x.exe" ]; then + ./boot-c-parts-windows.sh +else + ./boot-c-parts.sh +fi +./boot.sh $@ +./world.all.sh $@ diff --git a/bytecomp/.cvsignore b/bytecomp/.cvsignore new file mode 100644 index 0000000..d2f18a8 --- /dev/null +++ b/bytecomp/.cvsignore @@ -0,0 +1,2 @@ +runtimedef.ml +opcodes.ml diff --git a/bytecomp/bytegen.ml b/bytecomp/bytegen.ml new file mode 100644 index 0000000..849a1db --- /dev/null +++ b/bytecomp/bytegen.ml @@ -0,0 +1,867 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytegen.ml,v 1.72 2008-10-03 15:02:55 maranget Exp $ *) + +(* bytegen.ml : translation of lambda terms to lists of instructions. *) + +open Misc +open Asttypes +open Primitive +open Types +open Lambda +open Switch +open Instruct + +(**** Label generation ****) + +let label_counter = ref 0 + +let new_label () = + incr label_counter; !label_counter + +(**** Operations on compilation environments. ****) + +let empty_env = + { ce_stack = Ident.empty; ce_heap = Ident.empty; ce_rec = Ident.empty } + +(* Add a stack-allocated variable *) + +let add_var id pos env = + { ce_stack = Ident.add id pos env.ce_stack; + ce_heap = env.ce_heap; + ce_rec = env.ce_rec } + +let rec add_vars idlist pos env = + match idlist with + [] -> env + | id :: rem -> add_vars rem (pos + 1) (add_var id pos env) + +(**** Examination of the continuation ****) + +(* Return a label to the beginning of the given continuation. + If the sequence starts with a branch, use the target of that branch + as the label, thus avoiding a jump to a jump. *) + +let label_code = function + Kbranch lbl :: _ as cont -> (lbl, cont) + | Klabel lbl :: _ as cont -> (lbl, cont) + | cont -> let lbl = new_label() in (lbl, Klabel lbl :: cont) + +(* Return a branch to the continuation. That is, an instruction that, + when executed, branches to the continuation or performs what the + continuation performs. We avoid generating branches to branches and + branches to returns. *) + +let rec make_branch_2 lbl n cont = + function + Kreturn m :: _ -> (Kreturn (n + m), cont) + | Klabel _ :: c -> make_branch_2 lbl n cont c + | Kpop m :: c -> make_branch_2 lbl (n + m) cont c + | _ -> + match lbl with + Some lbl -> (Kbranch lbl, cont) + | None -> let lbl = new_label() in (Kbranch lbl, Klabel lbl :: cont) + +let make_branch cont = + match cont with + (Kbranch _ as branch) :: _ -> (branch, cont) + | (Kreturn _ as return) :: _ -> (return, cont) + | Kraise :: _ -> (Kraise, cont) + | Klabel lbl :: _ -> make_branch_2 (Some lbl) 0 cont cont + | _ -> make_branch_2 (None) 0 cont cont + +(* Avoid a branch to a label that follows immediately *) + +let branch_to label cont = match cont with +| Klabel label0::_ when label = label0 -> cont +| _ -> Kbranch label::cont + +(* Discard all instructions up to the next label. + This function is to be applied to the continuation before adding a + non-terminating instruction (branch, raise, return) in front of it. *) + +let rec discard_dead_code = function + [] -> [] + | (Klabel _ | Krestart | Ksetglobal _) :: _ as cont -> cont + | _ :: cont -> discard_dead_code cont + +(* Check if we're in tailcall position *) + +let rec is_tailcall = function + Kreturn _ :: _ -> true + | Klabel _ :: c -> is_tailcall c + | Kpop _ :: c -> is_tailcall c + | _ -> false + +(* Add a Kpop N instruction in front of a continuation *) + +let rec add_pop n cont = + if n = 0 then cont else + match cont with + Kpop m :: cont -> add_pop (n + m) cont + | Kreturn m :: cont -> Kreturn(n + m) :: cont + | Kraise :: _ -> cont + | _ -> Kpop n :: cont + +(* Add the constant "unit" in front of a continuation *) + +let add_const_unit = function + (Kacc _ | Kconst _ | Kgetglobal _ | Kpush_retaddr _) :: _ as cont -> cont + | cont -> Kconst const_unit :: cont + +let rec push_dummies n k = match n with +| 0 -> k +| _ -> Kconst const_unit::Kpush::push_dummies (n-1) k + + +(**** Auxiliary for compiling "let rec" ****) + +type rhs_kind = + | RHS_block of int + | RHS_floatblock of int + | RHS_nonrec +;; + +let rec check_recordwith_updates id e = + match e with + | Lsequence (Lprim ((Psetfield _ | Psetfloatfield _), [Lvar id2; _]), cont) + -> id2 = id && check_recordwith_updates id cont + | Lvar id2 -> id2 = id + | _ -> false +;; + +let rec size_of_lambda = function + | Lfunction(kind, params, body) as funct -> + RHS_block (1 + IdentSet.cardinal(free_variables funct)) + | Llet (Strict, id, Lprim (Pduprecord (kind, size), _), body) + when check_recordwith_updates id body -> + begin match kind with + | Record_regular -> RHS_block size + | Record_float -> RHS_floatblock size + end + | Llet(str, id, arg, body) -> size_of_lambda body + | Lletrec(bindings, body) -> size_of_lambda body + | Lprim(Pmakeblock(tag, mut), args) -> RHS_block (List.length args) + | Lprim (Pmakearray (Paddrarray|Pintarray), args) -> + RHS_block (List.length args) + | Lprim (Pmakearray Pfloatarray, args) -> RHS_floatblock (List.length args) + | Lprim (Pmakearray Pgenarray, args) -> assert false + | Lprim (Pduprecord (Record_regular, size), args) -> RHS_block size + | Lprim (Pduprecord (Record_float, size), args) -> RHS_floatblock size + | Levent (lam, _) -> size_of_lambda lam + | Lsequence (lam, lam') -> size_of_lambda lam' + | _ -> RHS_nonrec + +(**** Merging consecutive events ****) + +let copy_event ev kind info repr = + { ev_pos = 0; (* patched in emitcode *) + ev_module = ev.ev_module; + ev_loc = ev.ev_loc; + ev_kind = kind; + ev_info = info; + ev_typenv = ev.ev_typenv; + ev_compenv = ev.ev_compenv; + ev_stacksize = ev.ev_stacksize; + ev_repr = repr } + +let merge_infos ev ev' = + match ev.ev_info, ev'.ev_info with + Event_other, info -> info + | info, Event_other -> info + | _ -> fatal_error "Bytegen.merge_infos" + +let merge_repr ev ev' = + match ev.ev_repr, ev'.ev_repr with + Event_none, x -> x + | x, Event_none -> x + | Event_parent r, Event_child r' when r == r' && !r = 1 -> Event_none + | Event_child r, Event_parent r' when r == r' -> Event_parent r + | _, _ -> fatal_error "Bytegen.merge_repr" + +let merge_events ev ev' = + let (maj, min) = + match ev.ev_kind, ev'.ev_kind with + (* Discard pseudo-events *) + Event_pseudo, _ -> ev', ev + | _, Event_pseudo -> ev, ev' + (* Keep following event, supposedly more informative *) + | Event_before, (Event_after _ | Event_before) -> ev', ev + (* Discard following events, supposedly less informative *) + | Event_after _, (Event_after _ | Event_before) -> ev, ev' + in + copy_event maj maj.ev_kind (merge_infos maj min) (merge_repr maj min) + +let weaken_event ev cont = + match ev.ev_kind with + Event_after _ -> + begin match cont with + Kpush :: Kevent ({ev_repr = Event_none} as ev') :: c -> + begin match ev.ev_info with + Event_return _ -> + (* Weaken event *) + let repr = ref 1 in + let ev = + copy_event ev Event_pseudo ev.ev_info (Event_parent repr) + and ev' = + copy_event ev' ev'.ev_kind ev'.ev_info (Event_child repr) + in + Kevent ev :: Kpush :: Kevent ev' :: c + | _ -> + (* Only keep following event, equivalent *) + cont + end + | _ -> + Kevent ev :: cont + end + | _ -> + Kevent ev :: cont + +let add_event ev = + function + Kevent ev' :: cont -> weaken_event (merge_events ev ev') cont + | cont -> weaken_event ev cont + +(**** Compilation of a lambda expression ****) + +(* association staticraise numbers -> (lbl,size of stack *) + +let sz_static_raises = ref [] +let find_raise_label i = + try + List.assoc i !sz_static_raises + with + | Not_found -> + Misc.fatal_error + ("exit("^string_of_int i^") outside appropriated catch") + +(* Will the translation of l lead to a jump to label ? *) +let code_as_jump l sz = match l with +| Lstaticraise (i,[]) -> + let label,size = find_raise_label i in + if sz = size then + Some label + else + None +| _ -> None + +(* Function bodies that remain to be compiled *) + +type function_to_compile = + { params: Ident.t list; (* function parameters *) + body: lambda; (* the function body *) + label: label; (* the label of the function entry *) + free_vars: Ident.t list; (* free variables of the function *) + num_defs: int; (* number of mutually recursive definitions *) + rec_vars: Ident.t list; (* mutually recursive fn names *) + rec_pos: int } (* rank in recursive definition *) + +let functions_to_compile = (Stack.create () : function_to_compile Stack.t) + +(* Name of current compilation unit (for debugging events) *) + +let compunit_name = ref "" + +(* Maximal stack size reached during the current function body *) + +let max_stack_used = ref 0 + +(* Translate a primitive to a bytecode instruction (possibly a call to a C + function) *) + +let comp_bint_primitive bi suff args = + let pref = + match bi with Pnativeint -> "caml_nativeint_" + | Pint32 -> "caml_int32_" + | Pint64 -> "caml_int64_" in + Kccall(pref ^ suff, List.length args) + +let comp_primitive p args = + match p with + Pgetglobal id -> Kgetglobal id + | Psetglobal id -> Ksetglobal id + | Pintcomp cmp -> Kintcomp cmp + | Pmakeblock(tag, mut) -> Kmakeblock(List.length args, tag) + | Pfield n -> Kgetfield n + | Psetfield(n, ptr) -> Ksetfield n + | Pfloatfield n -> Kgetfloatfield n + | Psetfloatfield n -> Ksetfloatfield n + | Pduprecord _ -> Kccall("caml_obj_dup", 1) + | Pccall p -> Kccall(p.prim_name, p.prim_arity) + | Pnegint -> Knegint + | Paddint -> Kaddint + | Psubint -> Ksubint + | Pmulint -> Kmulint + | Pdivint -> Kdivint + | Pmodint -> Kmodint + | Pandint -> Kandint + | Porint -> Korint + | Pxorint -> Kxorint + | Plslint -> Klslint + | Plsrint -> Klsrint + | Pasrint -> Kasrint + | Poffsetint n -> Koffsetint n + | Poffsetref n -> Koffsetref n + | Pintoffloat -> Kccall("caml_int_of_float", 1) + | Pfloatofint -> Kccall("caml_float_of_int", 1) + | Pnegfloat -> Kccall("caml_neg_float", 1) + | Pabsfloat -> Kccall("caml_abs_float", 1) + | Paddfloat -> Kccall("caml_add_float", 2) + | Psubfloat -> Kccall("caml_sub_float", 2) + | Pmulfloat -> Kccall("caml_mul_float", 2) + | Pdivfloat -> Kccall("caml_div_float", 2) + | Pfloatcomp Ceq -> Kccall("caml_eq_float", 2) + | Pfloatcomp Cneq -> Kccall("caml_neq_float", 2) + | Pfloatcomp Clt -> Kccall("caml_lt_float", 2) + | Pfloatcomp Cgt -> Kccall("caml_gt_float", 2) + | Pfloatcomp Cle -> Kccall("caml_le_float", 2) + | Pfloatcomp Cge -> Kccall("caml_ge_float", 2) + | Pstringlength -> Kccall("caml_ml_string_length", 1) + | Pstringrefs -> Kccall("caml_string_get", 2) + | Pstringsets -> Kccall("caml_string_set", 3) + | Pstringrefu -> Kgetstringchar + | Pstringsetu -> Ksetstringchar + | Parraylength kind -> Kvectlength + | Parrayrefs Pgenarray -> Kccall("caml_array_get", 2) + | Parrayrefs Pfloatarray -> Kccall("caml_array_get_float", 2) + | Parrayrefs _ -> Kccall("caml_array_get_addr", 2) + | Parraysets Pgenarray -> Kccall("caml_array_set", 3) + | Parraysets Pfloatarray -> Kccall("caml_array_set_float", 3) + | Parraysets _ -> Kccall("caml_array_set_addr", 3) + | Parrayrefu Pgenarray -> Kccall("caml_array_unsafe_get", 2) + | Parrayrefu Pfloatarray -> Kccall("caml_array_unsafe_get_float", 2) + | Parrayrefu _ -> Kgetvectitem + | Parraysetu Pgenarray -> Kccall("caml_array_unsafe_set", 3) + | Parraysetu Pfloatarray -> Kccall("caml_array_unsafe_set_float", 3) + | Parraysetu _ -> Ksetvectitem + | Pisint -> Kisint + | Pisout -> Kisout + | Pbittest -> Kccall("caml_bitvect_test", 2) + | Pbintofint bi -> comp_bint_primitive bi "of_int" args + | Pintofbint bi -> comp_bint_primitive bi "to_int" args + | Pcvtbint(Pint32, Pnativeint) -> Kccall("caml_nativeint_of_int32", 1) + | Pcvtbint(Pnativeint, Pint32) -> Kccall("caml_nativeint_to_int32", 1) + | Pcvtbint(Pint32, Pint64) -> Kccall("caml_int64_of_int32", 1) + | Pcvtbint(Pint64, Pint32) -> Kccall("caml_int64_to_int32", 1) + | Pcvtbint(Pnativeint, Pint64) -> Kccall("caml_int64_of_nativeint", 1) + | Pcvtbint(Pint64, Pnativeint) -> Kccall("caml_int64_to_nativeint", 1) + | Pnegbint bi -> comp_bint_primitive bi "neg" args + | Paddbint bi -> comp_bint_primitive bi "add" args + | Psubbint bi -> comp_bint_primitive bi "sub" args + | Pmulbint bi -> comp_bint_primitive bi "mul" args + | Pdivbint bi -> comp_bint_primitive bi "div" args + | Pmodbint bi -> comp_bint_primitive bi "mod" args + | Pandbint bi -> comp_bint_primitive bi "and" args + | Porbint bi -> comp_bint_primitive bi "or" args + | Pxorbint bi -> comp_bint_primitive bi "xor" args + | Plslbint bi -> comp_bint_primitive bi "shift_left" args + | Plsrbint bi -> comp_bint_primitive bi "shift_right_unsigned" args + | Pasrbint bi -> comp_bint_primitive bi "shift_right" args + | Pbintcomp(bi, Ceq) -> Kccall("caml_equal", 2) + | Pbintcomp(bi, Cneq) -> Kccall("caml_notequal", 2) + | Pbintcomp(bi, Clt) -> Kccall("caml_lessthan", 2) + | Pbintcomp(bi, Cgt) -> Kccall("caml_greaterthan", 2) + | Pbintcomp(bi, Cle) -> Kccall("caml_lessequal", 2) + | Pbintcomp(bi, Cge) -> Kccall("caml_greaterequal", 2) + | Pbigarrayref(_, n, _, _) -> Kccall("caml_ba_get_" ^ string_of_int n, n + 1) + | Pbigarrayset(_, n, _, _) -> Kccall("caml_ba_set_" ^ string_of_int n, n + 2) + | _ -> fatal_error "Bytegen.comp_primitive" + +let is_immed n = immed_min <= n && n <= immed_max + + +(* Compile an expression. + The value of the expression is left in the accumulator. + env = compilation environment + exp = the lambda expression to compile + sz = current size of the stack frame + cont = list of instructions to execute afterwards + Result = list of instructions that evaluate exp, then perform cont. *) + +let rec comp_expr env exp sz cont = + if sz > !max_stack_used then max_stack_used := sz; + match exp with + Lvar id -> + begin try + let pos = Ident.find_same id env.ce_stack in + Kacc(sz - pos) :: cont + with Not_found -> + try + let pos = Ident.find_same id env.ce_heap in + Kenvacc(pos) :: cont + with Not_found -> + try + let ofs = Ident.find_same id env.ce_rec in + Koffsetclosure(ofs) :: cont + with Not_found -> + Format.eprintf "%a@." Ident.print id; + fatal_error ("Bytegen.comp_expr: var " ^ Ident.unique_name id) + end + | Lconst cst -> + Kconst cst :: cont + | Lapply(func, args, loc) -> + let nargs = List.length args in + if is_tailcall cont then begin + Stypes.record (Stypes.An_call (loc, Annot.Tail)); + comp_args env args sz + (Kpush :: comp_expr env func (sz + nargs) + (Kappterm(nargs, sz + nargs) :: discard_dead_code cont)) + end else begin + Stypes.record (Stypes.An_call (loc, Annot.Stack)); + if nargs < 4 then + comp_args env args sz + (Kpush :: comp_expr env func (sz + nargs) (Kapply nargs :: cont)) + else begin + let (lbl, cont1) = label_code cont in + Kpush_retaddr lbl :: + comp_args env args (sz + 3) + (Kpush :: comp_expr env func (sz + 3 + nargs) + (Kapply nargs :: cont1)) + end + end + | Lsend(kind, met, obj, args) -> + let args = if kind = Cached then List.tl args else args in + let nargs = List.length args + 1 in + let getmethod, args' = + if kind = Self then (Kgetmethod, met::obj::args) else + match met with + Lconst(Const_base(Const_int n)) -> (Kgetpubmet n, obj::args) + | _ -> (Kgetdynmet, met::obj::args) + in + if is_tailcall cont then + comp_args env args' sz + (getmethod :: Kappterm(nargs, sz + nargs) :: discard_dead_code cont) + else + if nargs < 4 then + comp_args env args' sz + (getmethod :: Kapply nargs :: cont) + else begin + let (lbl, cont1) = label_code cont in + Kpush_retaddr lbl :: + comp_args env args' (sz + 3) + (getmethod :: Kapply nargs :: cont1) + end + | Lfunction(kind, params, body) -> (* assume kind = Curried *) + let lbl = new_label() in + let fv = IdentSet.elements(free_variables exp) in + let to_compile = + { params = params; body = body; label = lbl; + free_vars = fv; num_defs = 1; rec_vars = []; rec_pos = 0 } in + Stack.push to_compile functions_to_compile; + comp_args env (List.map (fun n -> Lvar n) fv) sz + (Kclosure(lbl, List.length fv) :: cont) + | Llet(str, id, arg, body) -> + comp_expr env arg sz + (Kpush :: comp_expr (add_var id (sz+1) env) body (sz+1) + (add_pop 1 cont)) + | Lletrec(decl, body) -> + let ndecl = List.length decl in + if List.for_all (function (_, Lfunction(_,_,_)) -> true | _ -> false) + decl then begin + (* let rec of functions *) + let fv = + IdentSet.elements (free_variables (Lletrec(decl, lambda_unit))) in + let rec_idents = List.map (fun (id, lam) -> id) decl in + let rec comp_fun pos = function + [] -> [] + | (id, Lfunction(kind, params, body)) :: rem -> + let lbl = new_label() in + let to_compile = + { params = params; body = body; label = lbl; free_vars = fv; + num_defs = ndecl; rec_vars = rec_idents; rec_pos = pos} in + Stack.push to_compile functions_to_compile; + lbl :: comp_fun (pos + 1) rem + | _ -> assert false in + let lbls = comp_fun 0 decl in + comp_args env (List.map (fun n -> Lvar n) fv) sz + (Kclosurerec(lbls, List.length fv) :: + (comp_expr (add_vars rec_idents (sz+1) env) body (sz + ndecl) + (add_pop ndecl cont))) + end else begin + let decl_size = + List.map (fun (id, exp) -> (id, exp, size_of_lambda exp)) decl in + let rec comp_init new_env sz = function + | [] -> comp_nonrec new_env sz ndecl decl_size + | (id, exp, RHS_floatblock blocksize) :: rem -> + Kconst(Const_base(Const_int blocksize)) :: + Kccall("caml_alloc_dummy_float", 1) :: Kpush :: + comp_init (add_var id (sz+1) new_env) (sz+1) rem + | (id, exp, RHS_block blocksize) :: rem -> + Kconst(Const_base(Const_int blocksize)) :: + Kccall("caml_alloc_dummy", 1) :: Kpush :: + comp_init (add_var id (sz+1) new_env) (sz+1) rem + | (id, exp, RHS_nonrec) :: rem -> + Kconst(Const_base(Const_int 0)) :: Kpush :: + comp_init (add_var id (sz+1) new_env) (sz+1) rem + and comp_nonrec new_env sz i = function + | [] -> comp_rec new_env sz ndecl decl_size + | (id, exp, (RHS_block _ | RHS_floatblock _)) :: rem -> + comp_nonrec new_env sz (i-1) rem + | (id, exp, RHS_nonrec) :: rem -> + comp_expr new_env exp sz + (Kassign (i-1) :: comp_nonrec new_env sz (i-1) rem) + and comp_rec new_env sz i = function + | [] -> comp_expr new_env body sz (add_pop ndecl cont) + | (id, exp, (RHS_block _ | RHS_floatblock _)) :: rem -> + comp_expr new_env exp sz + (Kpush :: Kacc i :: Kccall("caml_update_dummy", 2) :: + comp_rec new_env sz (i-1) rem) + | (id, exp, RHS_nonrec) :: rem -> + comp_rec new_env sz (i-1) rem + in + comp_init env sz decl_size + end + | Lprim(Pidentity, [arg]) -> + comp_expr env arg sz cont + | Lprim(Pignore, [arg]) -> + comp_expr env arg sz (add_const_unit cont) + | Lprim(Pnot, [arg]) -> + let newcont = + match cont with + Kbranchif lbl :: cont1 -> Kbranchifnot lbl :: cont1 + | Kbranchifnot lbl :: cont1 -> Kbranchif lbl :: cont1 + | _ -> Kboolnot :: cont in + comp_expr env arg sz newcont + | Lprim(Psequand, [exp1; exp2]) -> + begin match cont with + Kbranchifnot lbl :: _ -> + comp_expr env exp1 sz (Kbranchifnot lbl :: + comp_expr env exp2 sz cont) + | Kbranchif lbl :: cont1 -> + let (lbl2, cont2) = label_code cont1 in + comp_expr env exp1 sz (Kbranchifnot lbl2 :: + comp_expr env exp2 sz (Kbranchif lbl :: cont2)) + | _ -> + let (lbl, cont1) = label_code cont in + comp_expr env exp1 sz (Kstrictbranchifnot lbl :: + comp_expr env exp2 sz cont1) + end + | Lprim(Psequor, [exp1; exp2]) -> + begin match cont with + Kbranchif lbl :: _ -> + comp_expr env exp1 sz (Kbranchif lbl :: + comp_expr env exp2 sz cont) + | Kbranchifnot lbl :: cont1 -> + let (lbl2, cont2) = label_code cont1 in + comp_expr env exp1 sz (Kbranchif lbl2 :: + comp_expr env exp2 sz (Kbranchifnot lbl :: cont2)) + | _ -> + let (lbl, cont1) = label_code cont in + comp_expr env exp1 sz (Kstrictbranchif lbl :: + comp_expr env exp2 sz cont1) + end + | Lprim(Praise, [arg]) -> + comp_expr env arg sz (Kraise :: discard_dead_code cont) + | Lprim(Paddint, [arg; Lconst(Const_base(Const_int n))]) + when is_immed n -> + comp_expr env arg sz (Koffsetint n :: cont) + | Lprim(Psubint, [arg; Lconst(Const_base(Const_int n))]) + when is_immed (-n) -> + comp_expr env arg sz (Koffsetint (-n) :: cont) + | Lprim (Poffsetint n, [arg]) + when not (is_immed n) -> + comp_expr env arg sz + (Kpush:: + Kconst (Const_base (Const_int n)):: + Kaddint::cont) + | Lprim(Pmakearray kind, args) -> + begin match kind with + Pintarray | Paddrarray -> + comp_args env args sz (Kmakeblock(List.length args, 0) :: cont) + | Pfloatarray -> + comp_args env args sz (Kmakefloatblock(List.length args) :: cont) + | Pgenarray -> + if args = [] + then Kmakeblock(0, 0) :: cont + else comp_args env args sz + (Kmakeblock(List.length args, 0) :: + Kccall("caml_make_array", 1) :: cont) + end +(* Integer first for enabling futher optimization (cf. emitcode.ml) *) + | Lprim (Pintcomp c, [arg ; (Lconst _ as k)]) -> + let p = Pintcomp (commute_comparison c) + and args = [k ; arg] in + comp_args env args sz (comp_primitive p args :: cont) + | Lprim(p, args) -> + comp_args env args sz (comp_primitive p args :: cont) + | Lstaticcatch (body, (i, vars) , handler) -> + let nvars = List.length vars in + let branch1, cont1 = make_branch cont in + let r = + if nvars <> 1 then begin (* general case *) + let lbl_handler, cont2 = + label_code + (comp_expr + (add_vars vars (sz+1) env) + handler (sz+nvars) (add_pop nvars cont1)) in + sz_static_raises := + (i, (lbl_handler, sz+nvars)) :: !sz_static_raises ; + push_dummies nvars + (comp_expr env body (sz+nvars) + (add_pop nvars (branch1 :: cont2))) + end else begin (* small optimization for nvars = 1 *) + let var = match vars with [var] -> var | _ -> assert false in + let lbl_handler, cont2 = + label_code + (Kpush::comp_expr + (add_var var (sz+1) env) + handler (sz+1) (add_pop 1 cont1)) in + sz_static_raises := + (i, (lbl_handler, sz)) :: !sz_static_raises ; + comp_expr env body sz (branch1 :: cont2) + end in + sz_static_raises := List.tl !sz_static_raises ; + r + | Lstaticraise (i, args) -> + let cont = discard_dead_code cont in + let label,size = find_raise_label i in + begin match args with + | [arg] -> (* optim, argument passed in accumulator *) + comp_expr env arg sz + (add_pop (sz-size) (branch_to label cont)) + | _ -> + comp_exit_args env args sz size + (add_pop (sz-size) (branch_to label cont)) + end + | Ltrywith(body, id, handler) -> + let (branch1, cont1) = make_branch cont in + let lbl_handler = new_label() in + Kpushtrap lbl_handler :: + comp_expr env body (sz+4) (Kpoptrap :: branch1 :: + Klabel lbl_handler :: Kpush :: + comp_expr (add_var id (sz+1) env) handler (sz+1) (add_pop 1 cont1)) + | Lifthenelse(cond, ifso, ifnot) -> + comp_binary_test env cond ifso ifnot sz cont + | Lsequence(exp1, exp2) -> + comp_expr env exp1 sz (comp_expr env exp2 sz cont) + | Lwhile(cond, body) -> + let lbl_loop = new_label() in + let lbl_test = new_label() in + Kbranch lbl_test :: Klabel lbl_loop :: Kcheck_signals :: + comp_expr env body sz + (Klabel lbl_test :: + comp_expr env cond sz (Kbranchif lbl_loop :: add_const_unit cont)) + | Lfor(param, start, stop, dir, body) -> + let lbl_loop = new_label() in + let lbl_exit = new_label() in + let offset = match dir with Upto -> 1 | Downto -> -1 in + let comp = match dir with Upto -> Cgt | Downto -> Clt in + comp_expr env start sz + (Kpush :: comp_expr env stop (sz+1) + (Kpush :: Kpush :: Kacc 2 :: Kintcomp comp :: Kbranchif lbl_exit :: + Klabel lbl_loop :: Kcheck_signals :: + comp_expr (add_var param (sz+1) env) body (sz+2) + (Kacc 1 :: Kpush :: Koffsetint offset :: Kassign 2 :: + Kacc 1 :: Kintcomp Cneq :: Kbranchif lbl_loop :: + Klabel lbl_exit :: add_const_unit (add_pop 2 cont)))) + | Lswitch(arg, sw) -> + let (branch, cont1) = make_branch cont in + let c = ref (discard_dead_code cont1) in +(* Build indirection vectors *) + let store = mk_store Lambda.same in + let act_consts = Array.create sw.sw_numconsts 0 + and act_blocks = Array.create sw.sw_numblocks 0 in + begin match sw.sw_failaction with (* default is index 0 *) + | Some fail -> ignore (store.act_store fail) + | None -> () + end ; + List.iter + (fun (n, act) -> act_consts.(n) <- store.act_store act) sw.sw_consts; + List.iter + (fun (n, act) -> act_blocks.(n) <- store.act_store act) sw.sw_blocks; + +(* Compile and label actions *) + let acts = store.act_get () in + let lbls = Array.create (Array.length acts) 0 in + for i = Array.length acts-1 downto 0 do + let lbl,c1 = label_code (comp_expr env acts.(i) sz (branch :: !c)) in + lbls.(i) <- lbl ; + c := discard_dead_code c1 + done ; + +(* Build label vectors *) + let lbl_blocks = Array.create sw.sw_numblocks 0 in + for i = sw.sw_numblocks - 1 downto 0 do + lbl_blocks.(i) <- lbls.(act_blocks.(i)) + done; + let lbl_consts = Array.create sw.sw_numconsts 0 in + for i = sw.sw_numconsts - 1 downto 0 do + lbl_consts.(i) <- lbls.(act_consts.(i)) + done; + comp_expr env arg sz (Kswitch(lbl_consts, lbl_blocks) :: !c) + | Lassign(id, expr) -> + begin try + let pos = Ident.find_same id env.ce_stack in + comp_expr env expr sz (Kassign(sz - pos) :: cont) + with Not_found -> + fatal_error "Bytegen.comp_expr: assign" + end + | Levent(lam, lev) -> + let event kind info = + { ev_pos = 0; (* patched in emitcode *) + ev_module = !compunit_name; + ev_loc = lev.lev_loc; + ev_kind = kind; + ev_info = info; + ev_typenv = lev.lev_env; + ev_compenv = env; + ev_stacksize = sz; + ev_repr = + begin match lev.lev_repr with + None -> + Event_none + | Some ({contents = 1} as repr) when lev.lev_kind = Lev_function -> + Event_child repr + | Some ({contents = 1} as repr) -> + Event_parent repr + | Some repr when lev.lev_kind = Lev_function -> + Event_parent repr + | Some repr -> + Event_child repr + end } + in + begin match lev.lev_kind with + Lev_before -> + let c = comp_expr env lam sz cont in + let ev = event Event_before Event_other in + add_event ev c + | Lev_function -> + let c = comp_expr env lam sz cont in + let ev = event Event_pseudo Event_function in + add_event ev c + | Lev_after _ when is_tailcall cont -> (* don't destroy tail call opt *) + comp_expr env lam sz cont + | Lev_after ty -> + let info = + match lam with + Lapply(_, args, _) -> Event_return (List.length args) + | Lsend(_, _, _, args) -> Event_return (List.length args + 1) + | _ -> Event_other + in + let ev = event (Event_after ty) info in + let cont1 = add_event ev cont in + comp_expr env lam sz cont1 + end + | Lifused (_, exp) -> + comp_expr env exp sz cont + +(* Compile a list of arguments [e1; ...; eN] to a primitive operation. + The values of eN ... e2 are pushed on the stack, e2 at top of stack, + then e3, then ... The value of e1 is left in the accumulator. *) + +and comp_args env argl sz cont = + comp_expr_list env (List.rev argl) sz cont + +and comp_expr_list env exprl sz cont = match exprl with + [] -> cont + | [exp] -> comp_expr env exp sz cont + | exp :: rem -> + comp_expr env exp sz (Kpush :: comp_expr_list env rem (sz+1) cont) + +and comp_exit_args env argl sz pos cont = + comp_expr_list_assign env (List.rev argl) sz pos cont + +and comp_expr_list_assign env exprl sz pos cont = match exprl with + | [] -> cont + | exp :: rem -> + comp_expr env exp sz + (Kassign (sz-pos)::comp_expr_list_assign env rem sz (pos-1) cont) + +(* Compile an if-then-else test. *) + +and comp_binary_test env cond ifso ifnot sz cont = + let cont_cond = + if ifnot = Lconst const_unit then begin + let (lbl_end, cont1) = label_code cont in + Kstrictbranchifnot lbl_end :: comp_expr env ifso sz cont1 + end else + match code_as_jump ifso sz with + | Some label -> + let cont = comp_expr env ifnot sz cont in + Kbranchif label :: cont + | _ -> + match code_as_jump ifnot sz with + | Some label -> + let cont = comp_expr env ifso sz cont in + Kbranchifnot label :: cont + | _ -> + let (branch_end, cont1) = make_branch cont in + let (lbl_not, cont2) = label_code(comp_expr env ifnot sz cont1) in + Kbranchifnot lbl_not :: + comp_expr env ifso sz (branch_end :: cont2) in + + comp_expr env cond sz cont_cond + +(**** Compilation of a code block (with tracking of stack usage) ****) + +let comp_block env exp sz cont = + max_stack_used := 0; + let code = comp_expr env exp sz cont in + (* +1 because comp_expr may have pushed one more word *) + if !max_stack_used + 1 > Config.stack_threshold then + Kconst(Const_base(Const_int(!max_stack_used + 1))) :: + Kccall("caml_ensure_stack_capacity", 1) :: + code + else + code + +(**** Compilation of functions ****) + +let comp_function tc cont = + let arity = List.length tc.params in + let rec positions pos delta = function + [] -> Ident.empty + | id :: rem -> Ident.add id pos (positions (pos + delta) delta rem) in + let env = + { ce_stack = positions arity (-1) tc.params; + ce_heap = positions (2 * (tc.num_defs - tc.rec_pos) - 1) 1 tc.free_vars; + ce_rec = positions (-2 * tc.rec_pos) 2 tc.rec_vars } in + let cont = + comp_block env tc.body arity (Kreturn arity :: cont) in + if arity > 1 then + Krestart :: Klabel tc.label :: Kgrab(arity - 1) :: cont + else + Klabel tc.label :: cont + +let comp_remainder cont = + let c = ref cont in + begin try + while true do + c := comp_function (Stack.pop functions_to_compile) !c + done + with Stack.Empty -> + () + end; + !c + +(**** Compilation of a lambda phrase ****) + +let compile_implementation modulename expr = + Stack.clear functions_to_compile; + label_counter := 0; + sz_static_raises := [] ; + compunit_name := modulename; + let init_code = comp_block empty_env expr 0 [] in + if Stack.length functions_to_compile > 0 then begin + let lbl_init = new_label() in + Kbranch lbl_init :: comp_remainder (Klabel lbl_init :: init_code) + end else + init_code + +let compile_phrase expr = + Stack.clear functions_to_compile; + label_counter := 0; + sz_static_raises := [] ; + let init_code = comp_block empty_env expr 1 [Kreturn 1] in + let fun_code = comp_remainder [] in + (init_code, fun_code) diff --git a/bytecomp/bytegen.mli b/bytecomp/bytegen.mli new file mode 100644 index 0000000..f7ede9f --- /dev/null +++ b/bytecomp/bytegen.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytegen.mli,v 1.6 1999-11-17 18:56:59 xleroy Exp $ *) + +(* Generation of bytecode from lambda terms *) + +open Lambda +open Instruct + +val compile_implementation: string -> lambda -> instruction list +val compile_phrase: lambda -> instruction list * instruction list diff --git a/bytecomp/bytelibrarian.ml b/bytecomp/bytelibrarian.ml new file mode 100644 index 0000000..e3bcbed --- /dev/null +++ b/bytecomp/bytelibrarian.ml @@ -0,0 +1,122 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytelibrarian.ml,v 1.19 2006-05-11 15:50:53 xleroy Exp $ *) + +(* Build libraries of .cmo files *) + +open Misc +open Config +open Cmo_format + +type error = + File_not_found of string + | Not_an_object_file of string + +exception Error of error + +(* Copy a compilation unit from a .cmo or .cma into the archive *) +let copy_compunit ic oc compunit = + seek_in ic compunit.cu_pos; + compunit.cu_pos <- pos_out oc; + compunit.cu_force_link <- !Clflags.link_everything; + copy_file_chunk ic oc compunit.cu_codesize; + if compunit.cu_debug > 0 then begin + seek_in ic compunit.cu_debug; + compunit.cu_debug <- pos_out oc; + copy_file_chunk ic oc compunit.cu_debugsize + end + +(* Add C objects and options and "custom" info from a library descriptor *) + +let lib_sharedobjs = ref [] +let lib_ccobjs = ref [] +let lib_ccopts = ref [] +let lib_dllibs = ref [] + +(* See Bytelink.add_ccobjs for explanations on how options are ordered. + Notice that here we scan .cma files given on the command line from + left to right, hence options must be added after. *) + +let add_ccobjs l = + if not !Clflags.no_auto_link then begin + if l.lib_custom then Clflags.custom_runtime := true; + lib_ccobjs := !lib_ccobjs @ l.lib_ccobjs; + lib_ccopts := !lib_ccopts @ l.lib_ccopts; + lib_dllibs := !lib_dllibs @ l.lib_dllibs + end + +let copy_object_file oc name = + let file_name = + try + find_in_path !load_path name + with Not_found -> + raise(Error(File_not_found name)) in + let ic = open_in_bin file_name in + try + let buffer = String.create (String.length cmo_magic_number) in + really_input ic buffer 0 (String.length cmo_magic_number); + if buffer = cmo_magic_number then begin + let compunit_pos = input_binary_int ic in + seek_in ic compunit_pos; + let compunit = (input_value ic : compilation_unit) in + Bytelink.check_consistency file_name compunit; + copy_compunit ic oc compunit; + close_in ic; + [compunit] + end else + if buffer = cma_magic_number then begin + let toc_pos = input_binary_int ic in + seek_in ic toc_pos; + let toc = (input_value ic : library) in + List.iter (Bytelink.check_consistency file_name) toc.lib_units; + add_ccobjs toc; + List.iter (copy_compunit ic oc) toc.lib_units; + close_in ic; + toc.lib_units + end else + raise(Error(Not_an_object_file file_name)) + with + End_of_file -> close_in ic; raise(Error(Not_an_object_file file_name)) + | x -> close_in ic; raise x + +let create_archive file_list lib_name = + let outchan = open_out_bin lib_name in + try + output_string outchan cma_magic_number; + let ofs_pos_toc = pos_out outchan in + output_binary_int outchan 0; + let units = List.flatten(List.map (copy_object_file outchan) file_list) in + let toc = + { lib_units = units; + lib_custom = !Clflags.custom_runtime; + lib_ccobjs = !Clflags.ccobjs @ !lib_ccobjs; + lib_ccopts = !Clflags.ccopts @ !lib_ccopts; + lib_dllibs = !Clflags.dllibs @ !lib_dllibs } in + let pos_toc = pos_out outchan in + output_value outchan toc; + seek_out outchan ofs_pos_toc; + output_binary_int outchan pos_toc; + close_out outchan + with x -> + close_out outchan; + remove_file lib_name; + raise x + +open Format + +let report_error ppf = function + | File_not_found name -> + fprintf ppf "Cannot find file %s" name + | Not_an_object_file name -> + fprintf ppf "The file %s is not a bytecode object file" name + diff --git a/bytecomp/bytelibrarian.mli b/bytecomp/bytelibrarian.mli new file mode 100644 index 0000000..845bf76 --- /dev/null +++ b/bytecomp/bytelibrarian.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytelibrarian.mli,v 1.6 2000-03-06 22:11:06 weis Exp $ *) + +(* Build libraries of .cmo files *) + +(* Format of a library file: + magic number (Config.cma_magic_number) + absolute offset of content table + blocks of relocatable bytecode + content table = list of compilation units +*) + +val create_archive: string list -> string -> unit + +type error = + File_not_found of string + | Not_an_object_file of string + +exception Error of error + +open Format + +val report_error: formatter -> error -> unit diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml new file mode 100644 index 0000000..32eea93 --- /dev/null +++ b/bytecomp/bytelink.ml @@ -0,0 +1,535 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytelink.ml,v 1.95 2007-11-15 15:18:28 frisch Exp $ *) + +(* Link a set of .cmo files and produce a bytecode executable. *) + +open Sys +open Misc +open Config +open Instruct +open Cmo_format + +type error = + File_not_found of string + | Not_an_object_file of string + | Symbol_error of string * Symtable.error + | Inconsistent_import of string * string * string + | Custom_runtime + | File_exists of string + | Cannot_open_dll of string + +exception Error of error + +type link_action = + Link_object of string * compilation_unit + (* Name of .cmo file and descriptor of the unit *) + | Link_archive of string * compilation_unit list + (* Name of .cma file and descriptors of the units to be linked. *) + +(* Add C objects and options from a library descriptor *) +(* Ignore them if -noautolink or -use-runtime or -use-prim was given *) + +let lib_ccobjs = ref [] +let lib_ccopts = ref [] +let lib_dllibs = ref [] + +let add_ccobjs l = + if not !Clflags.no_auto_link then begin + if + String.length !Clflags.use_runtime = 0 + && String.length !Clflags.use_prims = 0 + then begin + if l.lib_custom then Clflags.custom_runtime := true; + lib_ccobjs := l.lib_ccobjs @ !lib_ccobjs; + lib_ccopts := l.lib_ccopts @ !lib_ccopts; + end; + lib_dllibs := l.lib_dllibs @ !lib_dllibs + end + +(* A note on ccobj ordering: + - Clflags.ccobjs is in reverse order w.r.t. what was given on the + ocamlc command line; + - l.lib_ccobjs is also in reverse order w.r.t. what was given on the + ocamlc -a command line when the library was created; + - Clflags.ccobjs is reversed just before calling the C compiler for the + custom link; + - .cma files on the command line of ocamlc are scanned right to left; + - Before linking, we add lib_ccobjs after Clflags.ccobjs. + Thus, for ocamlc a.cma b.cma obj1 obj2 + where a.cma was built with ocamlc -i ... obja1 obja2 + and b.cma was built with ocamlc -i ... objb1 objb2 + lib_ccobjs starts as [], + becomes objb2 objb1 when b.cma is scanned, + then obja2 obja1 objb2 objb1 when a.cma is scanned. + Clflags.ccobjs was initially obj2 obj1. + and is set to obj2 obj1 obja2 obja1 objb2 objb1. + Finally, the C compiler is given objb1 objb2 obja1 obja2 obj1 obj2, + which is what we need. (If b depends on a, a.cma must appear before + b.cma, but b's C libraries must appear before a's C libraries.) +*) + +(* First pass: determine which units are needed *) + +module IdentSet = + Set.Make(struct + type t = Ident.t + let compare = compare + end) + +let missing_globals = ref IdentSet.empty + +let is_required (rel, pos) = + match rel with + Reloc_setglobal id -> + IdentSet.mem id !missing_globals + | _ -> false + +let add_required (rel, pos) = + match rel with + Reloc_getglobal id -> + missing_globals := IdentSet.add id !missing_globals + | _ -> () + +let remove_required (rel, pos) = + match rel with + Reloc_setglobal id -> + missing_globals := IdentSet.remove id !missing_globals + | _ -> () + +let scan_file obj_name tolink = + let file_name = + try + find_in_path !load_path obj_name + with Not_found -> + raise(Error(File_not_found obj_name)) in + let ic = open_in_bin file_name in + try + let buffer = String.create (String.length cmo_magic_number) in + really_input ic buffer 0 (String.length cmo_magic_number); + if buffer = cmo_magic_number then begin + (* This is a .cmo file. It must be linked in any case. + Read the relocation information to see which modules it + requires. *) + let compunit_pos = input_binary_int ic in (* Go to descriptor *) + seek_in ic compunit_pos; + let compunit = (input_value ic : compilation_unit) in + close_in ic; + List.iter add_required compunit.cu_reloc; + Link_object(file_name, compunit) :: tolink + end + else if buffer = cma_magic_number then begin + (* This is an archive file. Each unit contained in it will be linked + in only if needed. *) + let pos_toc = input_binary_int ic in (* Go to table of contents *) + seek_in ic pos_toc; + let toc = (input_value ic : library) in + close_in ic; + add_ccobjs toc; + let required = + List.fold_right + (fun compunit reqd -> + if compunit.cu_force_link + || !Clflags.link_everything + || List.exists is_required compunit.cu_reloc + then begin + List.iter remove_required compunit.cu_reloc; + List.iter add_required compunit.cu_reloc; + compunit :: reqd + end else + reqd) + toc.lib_units [] in + Link_archive(file_name, required) :: tolink + end + else raise(Error(Not_an_object_file file_name)) + with + End_of_file -> close_in ic; raise(Error(Not_an_object_file file_name)) + | x -> close_in ic; raise x + +(* Second pass: link in the required units *) + +(* Consistency check between interfaces *) + +let crc_interfaces = Consistbl.create () + +let check_consistency file_name cu = + try + List.iter + (fun (name, crc) -> + if name = cu.cu_name + then Consistbl.set crc_interfaces name crc file_name + else Consistbl.check crc_interfaces name crc file_name) + cu.cu_imports + with Consistbl.Inconsistency(name, user, auth) -> + raise(Error(Inconsistent_import(name, user, auth))) + +let extract_crc_interfaces () = + Consistbl.extract crc_interfaces + +(* Record compilation events *) + +let debug_info = ref ([] : (int * string) list) + +(* Link in a compilation unit *) + +let link_compunit output_fun currpos_fun inchan file_name compunit = + check_consistency file_name compunit; + seek_in inchan compunit.cu_pos; + let code_block = String.create compunit.cu_codesize in + really_input inchan code_block 0 compunit.cu_codesize; + Symtable.patch_object code_block compunit.cu_reloc; + if !Clflags.debug && compunit.cu_debug > 0 then begin + seek_in inchan compunit.cu_debug; + let buffer = String.create compunit.cu_debugsize in + really_input inchan buffer 0 compunit.cu_debugsize; + debug_info := (currpos_fun(), buffer) :: !debug_info + end; + output_fun code_block; + if !Clflags.link_everything then + List.iter Symtable.require_primitive compunit.cu_primitives + +(* Link in a .cmo file *) + +let link_object output_fun currpos_fun file_name compunit = + let inchan = open_in_bin file_name in + try + link_compunit output_fun currpos_fun inchan file_name compunit; + close_in inchan + with + Symtable.Error msg -> + close_in inchan; raise(Error(Symbol_error(file_name, msg))) + | x -> + close_in inchan; raise x + +(* Link in a .cma file *) + +let link_archive output_fun currpos_fun file_name units_required = + let inchan = open_in_bin file_name in + try + List.iter + (fun cu -> + let name = file_name ^ "(" ^ cu.cu_name ^ ")" in + try + link_compunit output_fun currpos_fun inchan name cu + with Symtable.Error msg -> + raise(Error(Symbol_error(name, msg)))) + units_required; + close_in inchan + with x -> close_in inchan; raise x + +(* Link in a .cmo or .cma file *) + +let link_file output_fun currpos_fun = function + Link_object(file_name, unit) -> + link_object output_fun currpos_fun file_name unit + | Link_archive(file_name, units) -> + link_archive output_fun currpos_fun file_name units + +(* Output the debugging information *) +(* Format is: + number of event lists + offset of first event list + first event list + ... + offset of last event list + last event list *) + +let output_debug_info oc = + output_binary_int oc (List.length !debug_info); + List.iter + (fun (ofs, evl) -> output_binary_int oc ofs; output_string oc evl) + !debug_info; + debug_info := [] + +(* Output a list of strings with 0-termination *) + +let output_stringlist oc l = + List.iter (fun s -> output_string oc s; output_byte oc 0) l + +(* Transform a file name into an absolute file name *) + +let make_absolute file = + if Filename.is_relative file + then Filename.concat (Sys.getcwd()) file + else file + +(* Create a bytecode executable file *) + +let link_bytecode tolink exec_name standalone = + Misc.remove_file exec_name; (* avoid permission problems, cf PR#1911 *) + let outchan = + open_out_gen [Open_wronly; Open_trunc; Open_creat; Open_binary] + 0o777 exec_name in + try + if standalone then begin + (* Copy the header *) + try + let header = + if String.length !Clflags.use_runtime > 0 + then "camlheader_ur" else "camlheader" in + let inchan = open_in_bin (find_in_path !load_path header) in + copy_file inchan outchan; + close_in inchan + with Not_found | Sys_error _ -> () + end; + Bytesections.init_record outchan; + (* The path to the bytecode interpreter (in use_runtime mode) *) + if String.length !Clflags.use_runtime > 0 then begin + output_string outchan (make_absolute !Clflags.use_runtime); + output_char outchan '\n'; + Bytesections.record outchan "RNTM" + end; + (* The bytecode *) + let start_code = pos_out outchan in + Symtable.init(); + Consistbl.clear crc_interfaces; + let sharedobjs = List.map Dll.extract_dll_name !Clflags.dllibs in + if standalone then begin + (* Initialize the DLL machinery *) + Dll.init_compile !Clflags.no_std_include; + Dll.add_path !load_path; + try Dll.open_dlls Dll.For_checking sharedobjs + with Failure reason -> raise(Error(Cannot_open_dll reason)) + end; + let output_fun = output_string outchan + and currpos_fun () = pos_out outchan - start_code in + List.iter (link_file output_fun currpos_fun) tolink; + if standalone then Dll.close_all_dlls(); + (* The final STOP instruction *) + output_byte outchan Opcodes.opSTOP; + output_byte outchan 0; output_byte outchan 0; output_byte outchan 0; + Bytesections.record outchan "CODE"; + (* DLL stuff *) + if standalone then begin + (* The extra search path for DLLs *) + output_stringlist outchan !Clflags.dllpaths; + Bytesections.record outchan "DLPT"; + (* The names of the DLLs *) + output_stringlist outchan sharedobjs; + Bytesections.record outchan "DLLS" + end; + (* The names of all primitives *) + Symtable.output_primitive_names outchan; + Bytesections.record outchan "PRIM"; + (* The table of global data *) + output_value outchan (Symtable.initial_global_table()); + Bytesections.record outchan "DATA"; + (* The map of global identifiers *) + Symtable.output_global_map outchan; + Bytesections.record outchan "SYMB"; + (* CRCs for modules *) + output_value outchan (extract_crc_interfaces()); + Bytesections.record outchan "CRCS"; + (* Debug info *) + if !Clflags.debug then begin + output_debug_info outchan; + Bytesections.record outchan "DBUG" + end; + (* The table of contents and the trailer *) + Bytesections.write_toc_and_trailer outchan; + close_out outchan + with x -> + close_out outchan; + remove_file exec_name; + raise x + +(* Output a string as a C array of unsigned ints *) + +let output_code_string_counter = ref 0 + +let output_code_string outchan code = + let pos = ref 0 in + let len = String.length code in + while !pos < len do + let c1 = Char.code(code.[!pos]) in + let c2 = Char.code(code.[!pos + 1]) in + let c3 = Char.code(code.[!pos + 2]) in + let c4 = Char.code(code.[!pos + 3]) in + pos := !pos + 4; + Printf.fprintf outchan "0x%02x%02x%02x%02x, " c4 c3 c2 c1; + incr output_code_string_counter; + if !output_code_string_counter >= 6 then begin + output_char outchan '\n'; + output_code_string_counter := 0 + end + done + +(* Output a string as a C string *) + +let output_data_string outchan data = + let counter = ref 0 in + for i = 0 to String.length data - 1 do + Printf.fprintf outchan "%d, " (Char.code(data.[i])); + incr counter; + if !counter >= 12 then begin + output_string outchan "\n"; + counter := 0 + end + done + +(* Output a bytecode executable as a C file *) + +let link_bytecode_as_c tolink outfile = + let outchan = open_out outfile in + try + (* The bytecode *) + output_string outchan "#include \n"; + output_string outchan "\ +CAMLextern void caml_startup_code( + code_t code, asize_t code_size, + char *data, asize_t data_size, + char *section_table, asize_t section_table_size, + char **argv);\n"; + output_string outchan "static int caml_code[] = {\n"; + Symtable.init(); + Consistbl.clear crc_interfaces; + let output_fun = output_code_string outchan + and currpos_fun () = 0 in + List.iter (link_file output_fun currpos_fun) tolink; + (* The final STOP instruction *) + Printf.fprintf outchan "\n0x%x};\n\n" Opcodes.opSTOP; + (* The table of global data *) + output_string outchan "static char caml_data[] = {\n"; + output_data_string outchan + (Marshal.to_string (Symtable.initial_global_table()) []); + output_string outchan "\n};\n\n"; + (* The sections *) + let sections = + [ "SYMB", Symtable.data_global_map(); + "PRIM", Obj.repr(Symtable.data_primitive_names()); + "CRCS", Obj.repr(extract_crc_interfaces()) ] in + output_string outchan "static char caml_sections[] = {\n"; + output_data_string outchan + (Marshal.to_string sections []); + output_string outchan "\n};\n\n"; + (* The table of primitives *) + Symtable.output_primitive_table outchan; + (* The entry point *) + output_string outchan "\n +void caml_startup(char ** argv) +{ + caml_startup_code(caml_code, sizeof(caml_code), + caml_data, sizeof(caml_data), + caml_sections, sizeof(caml_sections), + argv); +}\n"; + close_out outchan + with x -> + close_out outchan; + raise x + +(* Build a custom runtime *) + +let build_custom_runtime prim_name exec_name = + Ccomp.call_linker Ccomp.Exe exec_name + ([prim_name] @ List.rev !Clflags.ccobjs @ ["-lcamlrun"]) + Config.bytecomp_c_libraries + +let append_bytecode_and_cleanup bytecode_name exec_name prim_name = + let oc = open_out_gen [Open_wronly; Open_append; Open_binary] 0 exec_name in + let ic = open_in_bin bytecode_name in + copy_file ic oc; + close_in ic; + close_out oc; + remove_file bytecode_name; + remove_file prim_name + +(* Fix the name of the output file, if the C compiler changes it behind + our back. *) + +let fix_exec_name name = + match Sys.os_type with + "Win32" | "Cygwin" -> + if String.contains name '.' then name else name ^ ".exe" + | _ -> name + +(* Main entry point (build a custom runtime if needed) *) + +let link objfiles output_name = + let objfiles = + if !Clflags.nopervasives then objfiles + else if !Clflags.output_c_object then "stdlib.cma" :: objfiles + else "stdlib.cma" :: (objfiles @ ["std_exit.cmo"]) in + let tolink = List.fold_right scan_file objfiles [] in + Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs; (* put user's libs last *) + Clflags.ccopts := !lib_ccopts @ !Clflags.ccopts; (* put user's opts first *) + Clflags.dllibs := !lib_dllibs @ !Clflags.dllibs; (* put user's DLLs first *) + if not !Clflags.custom_runtime then + link_bytecode tolink output_name true + else if not !Clflags.output_c_object then begin + let bytecode_name = Filename.temp_file "camlcode" "" in + let prim_name = Filename.temp_file "camlprim" ".c" in + try + link_bytecode tolink bytecode_name false; + let poc = open_out prim_name in + Symtable.output_primitive_table poc; + close_out poc; + let exec_name = fix_exec_name output_name in + if not (build_custom_runtime prim_name exec_name) + then raise(Error Custom_runtime); + if !Clflags.make_runtime + then (remove_file bytecode_name; remove_file prim_name) + else append_bytecode_and_cleanup bytecode_name exec_name prim_name + with x -> + remove_file bytecode_name; + remove_file prim_name; + raise x + end else begin + let basename = Filename.chop_extension output_name in + let c_file = basename ^ ".c" + and obj_file = basename ^ Config.ext_obj in + if Sys.file_exists c_file then raise(Error(File_exists c_file)); + let temps = ref [] in + try + link_bytecode_as_c tolink c_file; + if not (Filename.check_suffix output_name ".c") then begin + temps := c_file :: !temps; + if Ccomp.compile_file c_file <> 0 then raise(Error Custom_runtime); + if not (Filename.check_suffix output_name Config.ext_obj) then begin + temps := obj_file :: !temps; + if not ( + Ccomp.call_linker Ccomp.MainDll output_name + ([obj_file] @ List.rev !Clflags.ccobjs @ ["-lcamlrun"]) + Config.bytecomp_c_libraries + ) then raise (Error Custom_runtime); + end + end; + List.iter remove_file !temps + with x -> + List.iter remove_file !temps; + raise x + end + +(* Error report *) + +open Format + +let report_error ppf = function + | File_not_found name -> + fprintf ppf "Cannot find file %s" name + | Not_an_object_file name -> + fprintf ppf "The file %s is not a bytecode object file" name + | Symbol_error(name, err) -> + fprintf ppf "Error while linking %s:@ %a" name + Symtable.report_error err + | Inconsistent_import(intf, file1, file2) -> + fprintf ppf + "@[Files %s@ and %s@ \ + make inconsistent assumptions over interface %s@]" + file1 file2 intf + | Custom_runtime -> + fprintf ppf "Error while building custom runtime system" + | File_exists file -> + fprintf ppf "Cannot overwrite existing file %s" file + | Cannot_open_dll file -> + fprintf ppf "Error on dynamically loaded library: %s" file diff --git a/bytecomp/bytelink.mli b/bytecomp/bytelink.mli new file mode 100644 index 0000000..dc5d55e --- /dev/null +++ b/bytecomp/bytelink.mli @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytelink.mli,v 1.12 2006-05-11 15:50:53 xleroy Exp $ *) + +(* Link .cmo files and produce a bytecode executable. *) + +val link: string list -> string -> unit + +val check_consistency: string -> Cmo_format.compilation_unit -> unit + +val extract_crc_interfaces: unit -> (string * Digest.t) list + +type error = + File_not_found of string + | Not_an_object_file of string + | Symbol_error of string * Symtable.error + | Inconsistent_import of string * string * string + | Custom_runtime + | File_exists of string + | Cannot_open_dll of string + +exception Error of error + +open Format + +val report_error: formatter -> error -> unit diff --git a/bytecomp/bytepackager.ml b/bytecomp/bytepackager.ml new file mode 100644 index 0000000..aefd6a0 --- /dev/null +++ b/bytecomp/bytepackager.ml @@ -0,0 +1,251 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytepackager.ml,v 1.6 2007-02-23 13:44:51 ertai Exp $ *) + +(* "Package" a set of .cmo files into one .cmo file having the + original compilation units as sub-modules. *) + +open Misc +open Instruct +open Cmo_format + +type error = + Forward_reference of string * Ident.t + | Multiple_definition of string * Ident.t + | Not_an_object_file of string + | Illegal_renaming of string * string + | File_not_found of string + +exception Error of error + +(* References accumulating informations on the .cmo files *) + +let relocs = ref ([] : (reloc_info * int) list) +let events = ref ([] : debug_event list) +let primitives = ref ([] : string list) +let force_link = ref false + +(* Record a relocation. Update its offset, and rename GETGLOBAL and + SETGLOBAL relocations that correspond to one of the units being + consolidated. *) + +let rename_relocation objfile mapping defined base (rel, ofs) = + let rel' = + match rel with + Reloc_getglobal id -> + begin try + let id' = List.assoc id mapping in + if List.mem id defined + then Reloc_getglobal id' + else raise(Error(Forward_reference(objfile, id))) + with Not_found -> + rel + end + | Reloc_setglobal id -> + begin try + let id' = List.assoc id mapping in + if List.mem id defined + then raise(Error(Multiple_definition(objfile, id))) + else Reloc_setglobal id' + with Not_found -> + rel + end + | _ -> + rel in + relocs := (rel', base + ofs) :: !relocs + +(* Record and relocate a debugging event *) + +let relocate_debug base ev = + ev.ev_pos <- base + ev.ev_pos; + events := ev :: !events + +(* Read the unit information from a .cmo file. *) + +type pack_member_kind = PM_intf | PM_impl of compilation_unit + +type pack_member = + { pm_file: string; + pm_name: string; + pm_kind: pack_member_kind } + +let read_member_info file = + let name = + String.capitalize(Filename.basename(chop_extensions file)) in + let kind = + if Filename.check_suffix file ".cmo" then begin + let ic = open_in_bin file in + try + let buffer = String.create (String.length Config.cmo_magic_number) in + really_input ic buffer 0 (String.length Config.cmo_magic_number); + if buffer <> Config.cmo_magic_number then + raise(Error(Not_an_object_file file)); + let compunit_pos = input_binary_int ic in + seek_in ic compunit_pos; + let compunit = (input_value ic : compilation_unit) in + if compunit.cu_name <> name + then raise(Error(Illegal_renaming(file, compunit.cu_name))); + close_in ic; + PM_impl compunit + with x -> + close_in ic; + raise x + end else + PM_intf in + { pm_file = file; pm_name = name; pm_kind = kind } + +(* Read the bytecode from a .cmo file. + Write bytecode to channel [oc]. + Rename globals as indicated by [mapping] in reloc info. + Accumulate relocs, debug info, etc. + Return size of bytecode. *) + +let rename_append_bytecode oc mapping defined ofs objfile compunit = + let ic = open_in_bin objfile in + try + Bytelink.check_consistency objfile compunit; + List.iter + (rename_relocation objfile mapping defined ofs) + compunit.cu_reloc; + primitives := compunit.cu_primitives @ !primitives; + if compunit.cu_force_link then force_link := true; + seek_in ic compunit.cu_pos; + Misc.copy_file_chunk ic oc compunit.cu_codesize; + if !Clflags.debug && compunit.cu_debug > 0 then begin + seek_in ic compunit.cu_debug; + List.iter (relocate_debug ofs) (input_value ic); + end; + close_in ic; + compunit.cu_codesize + with x -> + close_in ic; + raise x + +(* Same, for a list of .cmo and .cmi files. + Return total size of bytecode. *) + +let rec rename_append_bytecode_list oc mapping defined ofs = function + [] -> + ofs + | m :: rem -> + match m.pm_kind with + | PM_intf -> + rename_append_bytecode_list oc mapping defined ofs rem + | PM_impl compunit -> + let size = + rename_append_bytecode oc mapping defined ofs + m.pm_file compunit in + rename_append_bytecode_list + oc mapping (Ident.create_persistent m.pm_name :: defined) + (ofs + size) rem + +(* Generate the code that builds the tuple representing the package module *) + +let build_global_target oc target_name members mapping pos coercion = + let components = + List.map2 + (fun m (id1, id2) -> + match m.pm_kind with + | PM_intf -> None + | PM_impl _ -> Some id2) + members mapping in + let lam = + Translmod.transl_package + components (Ident.create_persistent target_name) coercion in + let instrs = + Bytegen.compile_implementation target_name lam in + let rel = + Emitcode.to_packed_file oc instrs in + relocs := List.map (fun (r, ofs) -> (r, pos + ofs)) rel @ !relocs + +(* Build the .cmo file obtained by packaging the given .cmo files. *) + +let package_object_files files targetfile targetname coercion = + let members = + map_left_right read_member_info files in + let unit_names = + List.map (fun m -> m.pm_name) members in + let mapping = + List.map + (fun name -> + (Ident.create_persistent name, + Ident.create_persistent(targetname ^ "." ^ name))) + unit_names in + let oc = open_out_bin targetfile in + try + output_string oc Config.cmo_magic_number; + let pos_depl = pos_out oc in + output_binary_int oc 0; + let pos_code = pos_out oc in + let ofs = rename_append_bytecode_list oc mapping [] 0 members in + build_global_target oc targetname members mapping ofs coercion; + let pos_debug = pos_out oc in + if !Clflags.debug && !events <> [] then + output_value oc (List.rev !events); + let pos_final = pos_out oc in + let imports = + List.filter + (fun (name, crc) -> not (List.mem name unit_names)) + (Bytelink.extract_crc_interfaces()) in + let compunit = + { cu_name = targetname; + cu_pos = pos_code; + cu_codesize = pos_debug - pos_code; + cu_reloc = List.rev !relocs; + cu_imports = (targetname, Env.crc_of_unit targetname) :: imports; + cu_primitives = !primitives; + cu_force_link = !force_link; + cu_debug = if pos_final > pos_debug then pos_debug else 0; + cu_debugsize = pos_final - pos_debug } in + output_value oc compunit; + seek_out oc pos_depl; + output_binary_int oc pos_final; + close_out oc + with x -> + close_out oc; + raise x + +(* The entry point *) + +let package_files files targetfile = + let files = + List.map + (fun f -> + try find_in_path !Config.load_path f + with Not_found -> raise(Error(File_not_found f))) + files in + let prefix = chop_extensions targetfile in + let targetcmi = prefix ^ ".cmi" in + let targetname = String.capitalize(Filename.basename prefix) in + try + let coercion = Typemod.package_units files targetcmi targetname in + package_object_files files targetfile targetname coercion + with x -> + remove_file targetfile; raise x + +(* Error report *) + +open Format + +let report_error ppf = function + Forward_reference(file, ident) -> + fprintf ppf "Forward reference to %s in file %s" (Ident.name ident) file + | Multiple_definition(file, ident) -> + fprintf ppf "File %s redefines %s" file (Ident.name ident) + | Not_an_object_file file -> + fprintf ppf "%s is not a bytecode object file" file + | Illegal_renaming(file, id) -> + fprintf ppf "Wrong file naming: %s@ contains the code for@ %s" + file id + | File_not_found file -> + fprintf ppf "File %s not found" file diff --git a/bytecomp/bytepackager.mli b/bytecomp/bytepackager.mli new file mode 100644 index 0000000..a18c152 --- /dev/null +++ b/bytecomp/bytepackager.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytepackager.mli,v 1.1 2002-02-08 16:55:42 xleroy Exp $ *) + +(* "Package" a set of .cmo files into one .cmo file having the + original compilation units as sub-modules. *) + +val package_files: string list -> string -> unit + +type error = + Forward_reference of string * Ident.t + | Multiple_definition of string * Ident.t + | Not_an_object_file of string + | Illegal_renaming of string * string + | File_not_found of string + +exception Error of error + +val report_error: Format.formatter -> error -> unit diff --git a/bytecomp/bytesections.ml b/bytecomp/bytesections.ml new file mode 100644 index 0000000..5d14bd0 --- /dev/null +++ b/bytecomp/bytesections.ml @@ -0,0 +1,99 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytesections.ml,v 1.3 2004-02-22 15:07:50 xleroy Exp $ *) + +(* Handling of sections in bytecode executable files *) + +(* List of all sections, in reverse order *) + +let section_table = ref ([] : (string * int) list) + +(* Recording sections *) + +let section_beginning = ref 0 + +let init_record outchan = + section_beginning := pos_out outchan; + section_table := [] + +let record outchan name = + let pos = pos_out outchan in + section_table := (name, pos - !section_beginning) :: !section_table; + section_beginning := pos + +let write_toc_and_trailer outchan = + List.iter + (fun (name, len) -> + output_string outchan name; output_binary_int outchan len) + (List.rev !section_table); + output_binary_int outchan (List.length !section_table); + output_string outchan Config.exec_magic_number; + section_table := []; + +(* Read the table of sections from a bytecode executable *) + +exception Bad_magic_number + +let read_toc ic = + let pos_trailer = in_channel_length ic - 16 in + seek_in ic pos_trailer; + let num_sections = input_binary_int ic in + let header = String.create(String.length Config.exec_magic_number) in + really_input ic header 0 (String.length Config.exec_magic_number); + if header <> Config.exec_magic_number then raise Bad_magic_number; + seek_in ic (pos_trailer - 8 * num_sections); + section_table := []; + for i = 1 to num_sections do + let name = String.create 4 in + really_input ic name 0 4; + let len = input_binary_int ic in + section_table := (name, len) :: !section_table + done + +(* Return the current table of contents *) + +let toc () = List.rev !section_table + +(* Position ic at the beginning of the section named "name", + and return the length of that section. Raise Not_found if no + such section exists. *) + +let seek_section ic name = + let rec seek_sec curr_ofs = function + [] -> raise Not_found + | (n, len) :: rem -> + if n = name + then begin seek_in ic (curr_ofs - len); len end + else seek_sec (curr_ofs - len) rem in + seek_sec (in_channel_length ic - 16 - 8 * List.length !section_table) + !section_table + +(* Return the contents of a section, as a string *) + +let read_section_string ic name = + let len = seek_section ic name in + let res = String.create len in + really_input ic res 0 len; + res + +(* Return the contents of a section, as marshalled data *) + +let read_section_struct ic name = + ignore (seek_section ic name); + input_value ic + +(* Return the position of the beginning of the first section *) + +let pos_first_section ic = + in_channel_length ic - 16 - 8 * List.length !section_table - + List.fold_left (fun total (name, len) -> total + len) 0 !section_table diff --git a/bytecomp/bytesections.mli b/bytecomp/bytesections.mli new file mode 100644 index 0000000..bc798be --- /dev/null +++ b/bytecomp/bytesections.mli @@ -0,0 +1,54 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bytesections.mli,v 1.3 2004-02-22 15:07:50 xleroy Exp $ *) + +(* Handling of sections in bytecode executable files *) + +(** Recording sections written to a bytecode executable file *) + +val init_record: out_channel -> unit + (* Start recording sections from the current position in out_channel *) + +val record: out_channel -> string -> unit + (* Record the current position in the out_channel as the end of + the section with the given name *) + +val write_toc_and_trailer: out_channel -> unit + (* Write the table of contents and the standard trailer for bytecode + executable files *) + +(** Reading sections from a bytecode executable file *) + +val read_toc: in_channel -> unit + (* Read the table of sections from a bytecode executable *) + +exception Bad_magic_number + (* Raised by [read_toc] if magic number doesn't match *) + +val toc: unit -> (string * int) list + (* Return the current table of contents as a list of + (section name, section length) pairs. *) + +val seek_section: in_channel -> string -> int + (* Position the input channel at the beginning of the section named "name", + and return the length of that section. Raise Not_found if no + such section exists. *) + +val read_section_string: in_channel -> string -> string + (* Return the contents of a section, as a string *) + +val read_section_struct: in_channel -> string -> 'a + (* Return the contents of a section, as marshalled data *) + +val pos_first_section: in_channel -> int + (* Return the position of the beginning of the first section *) diff --git a/bytecomp/cmo_format.mli b/bytecomp/cmo_format.mli new file mode 100644 index 0000000..1f08b78 --- /dev/null +++ b/bytecomp/cmo_format.mli @@ -0,0 +1,61 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cmo_format.mli,v 1.1 2006-05-11 15:50:53 xleroy Exp $ *) + +(* Symbol table information for .cmo and .cma files *) + +(* Relocation information *) + +type reloc_info = + Reloc_literal of Lambda.structured_constant (* structured constant *) + | Reloc_getglobal of Ident.t (* reference to a global *) + | Reloc_setglobal of Ident.t (* definition of a global *) + | Reloc_primitive of string (* C primitive number *) + +(* Descriptor for compilation units *) + +type compilation_unit = + { cu_name: string; (* Name of compilation unit *) + mutable cu_pos: int; (* Absolute position in file *) + cu_codesize: int; (* Size of code block *) + cu_reloc: (reloc_info * int) list; (* Relocation information *) + cu_imports: (string * Digest.t) list; (* Names and CRC of intfs imported *) + cu_primitives: string list; (* Primitives declared inside *) + mutable cu_force_link: bool; (* Must be linked even if unref'ed *) + mutable cu_debug: int; (* Position of debugging info, or 0 *) + cu_debugsize: int } (* Length of debugging info *) + +(* Format of a .cmo file: + magic number (Config.cmo_magic_number) + absolute offset of compilation unit descriptor + block of relocatable bytecode + debugging information if any + compilation unit descriptor *) + +(* Descriptor for libraries *) + +type library = + { lib_units: compilation_unit list; (* List of compilation units *) + lib_custom: bool; (* Requires custom mode linking? *) + lib_ccobjs: string list; (* C object files needed for -custom *) + lib_ccopts: string list; (* Extra opts to C compiler *) + lib_dllibs: string list } (* DLLs needed *) + +(* Format of a .cma file: + magic number (Config.cma_magic_number) + absolute offset of library descriptor + object code for first library member + ... + object code for last library member + library descriptor *) + diff --git a/bytecomp/dll.ml b/bytecomp/dll.ml new file mode 100644 index 0000000..0f4b0cf --- /dev/null +++ b/bytecomp/dll.ml @@ -0,0 +1,172 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: dll.ml,v 1.13 2006-09-28 21:36:38 xleroy Exp $ *) + +(* Handling of dynamically-linked libraries *) + +type dll_handle +type dll_address +type dll_mode = For_checking | For_execution + +external dll_open: dll_mode -> string -> dll_handle = "caml_dynlink_open_lib" +external dll_close: dll_handle -> unit = "caml_dynlink_close_lib" +external dll_sym: dll_handle -> string -> dll_address + = "caml_dynlink_lookup_symbol" + (* returned dll_address may be Val_unit *) +external add_primitive: dll_address -> int = "caml_dynlink_add_primitive" +external get_current_dlls: unit -> dll_handle array + = "caml_dynlink_get_current_libs" + +(* Current search path for DLLs *) +let search_path = ref ([] : string list) + +(* DLLs currently opened *) +let opened_dlls = ref ([] : dll_handle list) + +(* File names for those DLLs *) +let names_of_opened_dlls = ref ([] : string list) + +(* Add the given directories to the search path for DLLs. *) +let add_path dirs = + search_path := dirs @ !search_path + +(* Extract the name of a DLLs from its external name (xxx.so or -lxxx) *) + +let extract_dll_name file = + if Filename.check_suffix file Config.ext_dll then + Filename.chop_suffix file Config.ext_dll + else if String.length file >= 2 && String.sub file 0 2 = "-l" then + "dll" ^ String.sub file 2 (String.length file - 2) + else + file (* will cause error later *) + +(* Open a list of DLLs, adding them to opened_dlls. + Raise [Failure msg] in case of error. *) + +let open_dll mode name = + let name = name ^ Config.ext_dll in + let fullname = + try + let fullname = Misc.find_in_path !search_path name in + if Filename.is_implicit fullname then + Filename.concat Filename.current_dir_name fullname + else fullname + with Not_found -> name in + if not (List.mem fullname !names_of_opened_dlls) then begin + try + let dll = dll_open mode fullname in + names_of_opened_dlls := fullname :: !names_of_opened_dlls; + opened_dlls := dll :: !opened_dlls + with Failure msg -> + failwith (fullname ^ ": " ^ msg) + end + +let open_dlls mode names = + List.iter (open_dll mode) names + +(* Close all DLLs *) + +let close_all_dlls () = + List.iter dll_close !opened_dlls; + opened_dlls := []; + names_of_opened_dlls := [] + +(* Find a primitive in the currently opened DLLs. + Raise [Not_found] if not found. *) + +let find_primitive prim_name = + let rec find = function + [] -> + raise Not_found + | dll :: rem -> + let addr = dll_sym dll prim_name in + if addr == Obj.magic () then find rem else addr in + find !opened_dlls + +(* If linking in core (dynlink or toplevel), synchronize the VM + table of primitive with the linker's table of primitive + by storing the given primitive function at the given position + in the VM table of primitives. *) + +let linking_in_core = ref false + +let synchronize_primitive num symb = + if !linking_in_core then begin + let actual_num = add_primitive symb in + assert (actual_num = num) + end + +(* Read the [ld.conf] file and return the corresponding list of directories *) + +let ld_conf_contents () = + let path = ref [] in + begin try + let ic = open_in (Filename.concat Config.standard_library "ld.conf") in + begin try + while true do + path := input_line ic :: !path + done + with End_of_file -> () + end; + close_in ic + with Sys_error _ -> () + end; + List.rev !path + +(* Split the CAML_LD_LIBRARY_PATH environment variable and return + the corresponding list of directories. *) + +let split str sep = + let rec split_rec pos = + if pos >= String.length str then [] else begin + try + let newpos = String.index_from str pos sep in + String.sub str pos (newpos - pos) :: + split_rec (newpos + 1) + with Not_found -> + [String.sub str pos (String.length str - pos)] + end in + split_rec 0 + +let ld_library_path_contents () = + let path_separator = + match Sys.os_type with + | "Unix" | "Cygwin" -> ':' + | "Win32" -> ';' + | _ -> assert false in + try + split (Sys.getenv "CAML_LD_LIBRARY_PATH") path_separator + with Not_found -> + [] + +let split_dll_path path = + split path '\000' + +(* Initialization for separate compilation *) + +let init_compile nostdlib = + search_path := + ld_library_path_contents() @ + (if nostdlib then [] else ld_conf_contents()) + +(* Initialization for linking in core (dynlink or toplevel) *) + +let init_toplevel dllpath = + search_path := + ld_library_path_contents() @ + split_dll_path dllpath @ + ld_conf_contents(); + opened_dlls := Array.to_list (get_current_dlls()); + names_of_opened_dlls := []; + linking_in_core := true + diff --git a/bytecomp/dll.mli b/bytecomp/dll.mli new file mode 100644 index 0000000..8d39df6 --- /dev/null +++ b/bytecomp/dll.mli @@ -0,0 +1,61 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: dll.mli,v 1.6 2006-09-28 21:36:38 xleroy Exp $ *) + +(* Handling of dynamically-linked libraries *) + +(* Extract the name of a DLLs from its external name (xxx.so or -lxxx) *) +val extract_dll_name: string -> string + +type dll_mode = + | For_checking (* will just check existence of symbols; + no need to do full symbol resolution *) + | For_execution (* will call functions from this DLL; + must resolve symbols completely *) + +(* Open a list of DLLs. First argument indicates whether to perform + full symbol resolution. Raise [Failure msg] in case of error. *) +val open_dlls: dll_mode -> string list -> unit + +(* Close all DLLs *) +val close_all_dlls: unit -> unit + +(* The abstract type representing C function pointers *) +type dll_address + +(* Find a primitive in the currently opened DLLs and return its address. + Raise [Not_found] if not found. *) +val find_primitive: string -> dll_address + +(* If linking in core (dynlink or toplevel), synchronize the VM + table of primitive with the linker's table of primitive + by storing the given primitive function at the given position + in the VM table of primitives. *) +val synchronize_primitive: int -> dll_address -> unit + +(* Add the given directories at the head of the search path for DLLs *) +val add_path: string list -> unit + +(* Initialization for separate compilation. + Initialize the DLL search path to the directories given in the + environment variable CAML_LD_LIBRARY_PATH, plus contents of ld.conf file + if argument is [false]. If argument is [true], ignore ld.conf. *) +val init_compile: bool -> unit + +(* Initialization for linking in core (dynlink or toplevel). + Initialize the search path to the same path that was used to start + the running program (CAML_LD_LIBRARY_PATH + directories in executable + + contents of ld.conf file). Take note of the DLLs that were opened + when starting the running program. *) +val init_toplevel: string -> unit + diff --git a/bytecomp/emitcode.ml b/bytecomp/emitcode.ml new file mode 100644 index 0000000..1b55b6e --- /dev/null +++ b/bytecomp/emitcode.ml @@ -0,0 +1,409 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emitcode.ml,v 1.34 2008-07-24 05:35:22 frisch Exp $ *) + +(* Generation of bytecode + relocation information *) + +open Config +open Misc +open Asttypes +open Lambda +open Instruct +open Opcodes +open Cmo_format + +(* Buffering of bytecode *) + +let out_buffer = ref(String.create 1024) +and out_position = ref 0 + +let out_word b1 b2 b3 b4 = + let p = !out_position in + if p >= String.length !out_buffer then begin + let len = String.length !out_buffer in + let new_buffer = String.create (2 * len) in + String.blit !out_buffer 0 new_buffer 0 len; + out_buffer := new_buffer + end; + String.unsafe_set !out_buffer p (Char.unsafe_chr b1); + String.unsafe_set !out_buffer (p+1) (Char.unsafe_chr b2); + String.unsafe_set !out_buffer (p+2) (Char.unsafe_chr b3); + String.unsafe_set !out_buffer (p+3) (Char.unsafe_chr b4); + out_position := p + 4 + +let out opcode = + out_word opcode 0 0 0 + + +exception AsInt + +let const_as_int = function + | Const_base(Const_int i) -> i + | Const_base(Const_char c) -> Char.code c + | Const_pointer i -> i + | _ -> raise AsInt + +let is_immed i = immed_min <= i && i <= immed_max +let is_immed_const k = + try + is_immed (const_as_int k) + with + | AsInt -> false + + +let out_int n = + out_word n (n asr 8) (n asr 16) (n asr 24) + +let out_const c = + try + out_int (const_as_int c) + with + | AsInt -> Misc.fatal_error "Emitcode.const_as_int" + + +(* Handling of local labels and backpatching *) + +type label_definition = + Label_defined of int + | Label_undefined of (int * int) list + +let label_table = ref ([| |] : label_definition array) + +let extend_label_table needed = + let new_size = ref(Array.length !label_table) in + while needed >= !new_size do new_size := 2 * !new_size done; + let new_table = Array.create !new_size (Label_undefined []) in + Array.blit !label_table 0 new_table 0 (Array.length !label_table); + label_table := new_table + +let backpatch (pos, orig) = + let displ = (!out_position - orig) asr 2 in + !out_buffer.[pos] <- Char.unsafe_chr displ; + !out_buffer.[pos+1] <- Char.unsafe_chr (displ asr 8); + !out_buffer.[pos+2] <- Char.unsafe_chr (displ asr 16); + !out_buffer.[pos+3] <- Char.unsafe_chr (displ asr 24) + +let define_label lbl = + if lbl >= Array.length !label_table then extend_label_table lbl; + match (!label_table).(lbl) with + Label_defined _ -> + fatal_error "Emitcode.define_label" + | Label_undefined patchlist -> + List.iter backpatch patchlist; + (!label_table).(lbl) <- Label_defined !out_position + +let out_label_with_orig orig lbl = + if lbl >= Array.length !label_table then extend_label_table lbl; + match (!label_table).(lbl) with + Label_defined def -> + out_int((def - orig) asr 2) + | Label_undefined patchlist -> + (!label_table).(lbl) <- + Label_undefined((!out_position, orig) :: patchlist); + out_int 0 + +let out_label l = out_label_with_orig !out_position l + +(* Relocation information *) + +let reloc_info = ref ([] : (reloc_info * int) list) + +let enter info = + reloc_info := (info, !out_position) :: !reloc_info + +let slot_for_literal sc = + enter (Reloc_literal sc); + out_int 0 +and slot_for_getglobal id = + enter (Reloc_getglobal id); + out_int 0 +and slot_for_setglobal id = + enter (Reloc_setglobal id); + out_int 0 +and slot_for_c_prim name = + enter (Reloc_primitive name); + out_int 0 + +(* Debugging events *) + +let events = ref ([] : debug_event list) + +let record_event ev = + ev.ev_pos <- !out_position; + events := ev :: !events + +(* Initialization *) + +let init () = + out_position := 0; + label_table := Array.create 16 (Label_undefined []); + reloc_info := []; + events := [] + +(* Emission of one instruction *) + +let emit_comp = function +| Ceq -> out opEQ | Cneq -> out opNEQ +| Clt -> out opLTINT | Cle -> out opLEINT +| Cgt -> out opGTINT | Cge -> out opGEINT + +and emit_branch_comp = function +| Ceq -> out opBEQ | Cneq -> out opBNEQ +| Clt -> out opBLTINT | Cle -> out opBLEINT +| Cgt -> out opBGTINT | Cge -> out opBGEINT + +let emit_instr = function + Klabel lbl -> define_label lbl + | Kacc n -> + if n < 8 then out(opACC0 + n) else (out opACC; out_int n) + | Kenvacc n -> + if n >= 1 && n <= 4 + then out(opENVACC1 + n - 1) + else (out opENVACC; out_int n) + | Kpush -> + out opPUSH + | Kpop n -> + out opPOP; out_int n + | Kassign n -> + out opASSIGN; out_int n + | Kpush_retaddr lbl -> out opPUSH_RETADDR; out_label lbl + | Kapply n -> + if n < 4 then out(opAPPLY1 + n - 1) else (out opAPPLY; out_int n) + | Kappterm(n, sz) -> + if n < 4 then (out(opAPPTERM1 + n - 1); out_int sz) + else (out opAPPTERM; out_int n; out_int sz) + | Kreturn n -> out opRETURN; out_int n + | Krestart -> out opRESTART + | Kgrab n -> out opGRAB; out_int n + | Kclosure(lbl, n) -> out opCLOSURE; out_int n; out_label lbl + | Kclosurerec(lbls, n) -> + out opCLOSUREREC; out_int (List.length lbls); out_int n; + let org = !out_position in + List.iter (out_label_with_orig org) lbls + | Koffsetclosure ofs -> + if ofs = -2 || ofs = 0 || ofs = 2 + then out (opOFFSETCLOSURE0 + ofs / 2) + else (out opOFFSETCLOSURE; out_int ofs) + | Kgetglobal q -> out opGETGLOBAL; slot_for_getglobal q + | Ksetglobal q -> out opSETGLOBAL; slot_for_setglobal q + | Kconst sc -> + begin match sc with + Const_base(Const_int i) when is_immed i -> + if i >= 0 && i <= 3 + then out (opCONST0 + i) + else (out opCONSTINT; out_int i) + | Const_base(Const_char c) -> + out opCONSTINT; out_int (Char.code c) + | Const_pointer i -> + if i >= 0 && i <= 3 + then out (opCONST0 + i) + else (out opCONSTINT; out_int i) + | Const_block(t, []) -> + if t = 0 then out opATOM0 else (out opATOM; out_int t) + | _ -> + out opGETGLOBAL; slot_for_literal sc + end + | Kmakeblock(n, t) -> + if n = 0 then + if t = 0 then out opATOM0 else (out opATOM; out_int t) + else if n < 4 then (out(opMAKEBLOCK1 + n - 1); out_int t) + else (out opMAKEBLOCK; out_int n; out_int t) + | Kgetfield n -> + if n < 4 then out(opGETFIELD0 + n) else (out opGETFIELD; out_int n) + | Ksetfield n -> + if n < 4 then out(opSETFIELD0 + n) else (out opSETFIELD; out_int n) + | Kmakefloatblock(n) -> + if n = 0 then out opATOM0 else (out opMAKEFLOATBLOCK; out_int n) + | Kgetfloatfield n -> out opGETFLOATFIELD; out_int n + | Ksetfloatfield n -> out opSETFLOATFIELD; out_int n + | Kvectlength -> out opVECTLENGTH + | Kgetvectitem -> out opGETVECTITEM + | Ksetvectitem -> out opSETVECTITEM + | Kgetstringchar -> out opGETSTRINGCHAR + | Ksetstringchar -> out opSETSTRINGCHAR + | Kbranch lbl -> out opBRANCH; out_label lbl + | Kbranchif lbl -> out opBRANCHIF; out_label lbl + | Kbranchifnot lbl -> out opBRANCHIFNOT; out_label lbl + | Kstrictbranchif lbl -> out opBRANCHIF; out_label lbl + | Kstrictbranchifnot lbl -> out opBRANCHIFNOT; out_label lbl + | Kswitch(tbl_const, tbl_block) -> + out opSWITCH; + out_int (Array.length tbl_const + (Array.length tbl_block lsl 16)); + let org = !out_position in + Array.iter (out_label_with_orig org) tbl_const; + Array.iter (out_label_with_orig org) tbl_block + | Kboolnot -> out opBOOLNOT + | Kpushtrap lbl -> out opPUSHTRAP; out_label lbl + | Kpoptrap -> out opPOPTRAP + | Kraise -> out opRAISE + | Kcheck_signals -> out opCHECK_SIGNALS + | Kccall(name, n) -> + if n <= 5 + then (out (opC_CALL1 + n - 1); slot_for_c_prim name) + else (out opC_CALLN; out_int n; slot_for_c_prim name) + | Knegint -> out opNEGINT | Kaddint -> out opADDINT + | Ksubint -> out opSUBINT | Kmulint -> out opMULINT + | Kdivint -> out opDIVINT | Kmodint -> out opMODINT + | Kandint -> out opANDINT | Korint -> out opORINT + | Kxorint -> out opXORINT | Klslint -> out opLSLINT + | Klsrint -> out opLSRINT | Kasrint -> out opASRINT + | Kintcomp c -> emit_comp c + | Koffsetint n -> out opOFFSETINT; out_int n + | Koffsetref n -> out opOFFSETREF; out_int n + | Kisint -> out opISINT + | Kisout -> out opULTINT + | Kgetmethod -> out opGETMETHOD + | Kgetpubmet tag -> out opGETPUBMET; out_int tag; out_int 0 + | Kgetdynmet -> out opGETDYNMET + | Kevent ev -> record_event ev + | Kstop -> out opSTOP + +(* Emission of a list of instructions. Include some peephole optimization. *) + +let rec emit = function + [] -> () + (* Peephole optimizations *) +(* optimization of integer tests *) + | Kpush::Kconst k::Kintcomp c::Kbranchif lbl::rem + when is_immed_const k -> + emit_branch_comp c ; + out_const k ; + out_label lbl ; + emit rem + | Kpush::Kconst k::Kintcomp c::Kbranchifnot lbl::rem + when is_immed_const k -> + emit_branch_comp (negate_comparison c) ; + out_const k ; + out_label lbl ; + emit rem +(* same for range tests *) + | Kpush::Kconst k::Kisout::Kbranchif lbl::rem + when is_immed_const k -> + out opBULTINT ; + out_const k ; + out_label lbl ; + emit rem + | Kpush::Kconst k::Kisout::Kbranchifnot lbl::rem + when is_immed_const k -> + out opBUGEINT ; + out_const k ; + out_label lbl ; + emit rem +(* Some special case of push ; i ; ret generated by the match compiler *) + | Kpush :: Kacc 0 :: Kreturn m :: c -> + emit (Kreturn (m-1) :: c) +(* General push then access scheme *) + | Kpush :: Kacc n :: c -> + if n < 8 then out(opPUSHACC0 + n) else (out opPUSHACC; out_int n); + emit c + | Kpush :: Kenvacc n :: c -> + if n >= 1 && n < 4 + then out(opPUSHENVACC1 + n - 1) + else (out opPUSHENVACC; out_int n); + emit c + | Kpush :: Koffsetclosure ofs :: c -> + if ofs = -2 || ofs = 0 || ofs = 2 + then out(opPUSHOFFSETCLOSURE0 + ofs / 2) + else (out opPUSHOFFSETCLOSURE; out_int ofs); + emit c + | Kpush :: Kgetglobal id :: Kgetfield n :: c -> + out opPUSHGETGLOBALFIELD; slot_for_getglobal id; out_int n; emit c + | Kpush :: Kgetglobal id :: c -> + out opPUSHGETGLOBAL; slot_for_getglobal id; emit c + | Kpush :: Kconst sc :: c -> + begin match sc with + Const_base(Const_int i) when is_immed i -> + if i >= 0 && i <= 3 + then out (opPUSHCONST0 + i) + else (out opPUSHCONSTINT; out_int i) + | Const_base(Const_char c) -> + out opPUSHCONSTINT; out_int(Char.code c) + | Const_pointer i -> + if i >= 0 && i <= 3 + then out (opPUSHCONST0 + i) + else (out opPUSHCONSTINT; out_int i) + | Const_block(t, []) -> + if t = 0 then out opPUSHATOM0 else (out opPUSHATOM; out_int t) + | _ -> + out opPUSHGETGLOBAL; slot_for_literal sc + end; + emit c + | Kpush :: (Kevent {ev_kind = Event_before} as ev) :: + (Kgetglobal _ as instr1) :: (Kgetfield _ as instr2) :: c -> + emit (Kpush :: instr1 :: instr2 :: ev :: c) + | Kpush :: (Kevent {ev_kind = Event_before} as ev) :: + (Kacc _ | Kenvacc _ | Koffsetclosure _ | Kgetglobal _ | Kconst _ as instr) :: c -> + emit (Kpush :: instr :: ev :: c) + | Kgetglobal id :: Kgetfield n :: c -> + out opGETGLOBALFIELD; slot_for_getglobal id; out_int n; emit c + (* Default case *) + | instr :: c -> + emit_instr instr; emit c + +(* Emission to a file *) + +let to_file outchan unit_name code = + init(); + output_string outchan cmo_magic_number; + let pos_depl = pos_out outchan in + output_binary_int outchan 0; + let pos_code = pos_out outchan in + emit code; + output outchan !out_buffer 0 !out_position; + let (pos_debug, size_debug) = + if !Clflags.debug then begin + let p = pos_out outchan in + output_value outchan !events; + (p, pos_out outchan - p) + end else + (0, 0) in + let compunit = + { cu_name = unit_name; + cu_pos = pos_code; + cu_codesize = !out_position; + cu_reloc = List.rev !reloc_info; + cu_imports = Env.imported_units(); + cu_primitives = List.map Primitive.byte_name !Translmod.primitive_declarations; + cu_force_link = false; + cu_debug = pos_debug; + cu_debugsize = size_debug } in + init(); (* Free out_buffer and reloc_info *) + Btype.cleanup_abbrev (); (* Remove any cached abbreviation + expansion before saving *) + let pos_compunit = pos_out outchan in + output_value outchan compunit; + seek_out outchan pos_depl; + output_binary_int outchan pos_compunit + +(* Emission to a memory block *) + +let to_memory init_code fun_code = + init(); + emit init_code; + emit fun_code; + let code = Meta.static_alloc !out_position in + String.unsafe_blit !out_buffer 0 code 0 !out_position; + let reloc = List.rev !reloc_info + and code_size = !out_position in + init(); + (code, code_size, reloc) + +(* Emission to a file for a packed library *) + +let to_packed_file outchan code = + init(); + emit code; + output outchan !out_buffer 0 !out_position; + let reloc = !reloc_info in + init(); + reloc diff --git a/bytecomp/emitcode.mli b/bytecomp/emitcode.mli new file mode 100644 index 0000000..24e5a23 --- /dev/null +++ b/bytecomp/emitcode.mli @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: emitcode.mli,v 1.15 2006-05-11 15:50:53 xleroy Exp $ *) + +(* Generation of bytecode for .cmo files *) + +open Cmo_format +open Instruct + +val to_file: out_channel -> string -> instruction list -> unit + (* Arguments: + channel on output file + name of compilation unit implemented + list of instructions to emit *) +val to_memory: instruction list -> instruction list -> + string * int * (reloc_info * int) list + (* Arguments: + initialization code (terminated by STOP) + function code + Results: + block of relocatable bytecode + size of this block + relocation information *) +val to_packed_file: + out_channel -> instruction list -> (reloc_info * int) list + (* Arguments: + channel on output file + list of instructions to emit + Result: + relocation information (reversed) *) diff --git a/bytecomp/instruct.ml b/bytecomp/instruct.ml new file mode 100644 index 0000000..b14e529 --- /dev/null +++ b/bytecomp/instruct.ml @@ -0,0 +1,110 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: instruct.ml,v 1.22 2005-08-25 15:35:16 doligez Exp $ *) + +open Lambda + +type compilation_env = + { ce_stack: int Ident.tbl; + ce_heap: int Ident.tbl; + ce_rec: int Ident.tbl } + +type debug_event = + { mutable ev_pos: int; (* Position in bytecode *) + ev_module: string; (* Name of defining module *) + ev_loc: Location.t; (* Location in source file *) + ev_kind: debug_event_kind; (* Before/after event *) + ev_info: debug_event_info; (* Extra information *) + ev_typenv: Env.summary; (* Typing environment *) + ev_compenv: compilation_env; (* Compilation environment *) + ev_stacksize: int; (* Size of stack frame *) + ev_repr: debug_event_repr } (* Position of the representative *) + +and debug_event_kind = + Event_before + | Event_after of Types.type_expr + | Event_pseudo + +and debug_event_info = + Event_function + | Event_return of int + | Event_other + +and debug_event_repr = + Event_none + | Event_parent of int ref + | Event_child of int ref + +type label = int (* Symbolic code labels *) + +type instruction = + Klabel of label + | Kacc of int + | Kenvacc of int + | Kpush + | Kpop of int + | Kassign of int + | Kpush_retaddr of label + | Kapply of int (* number of arguments *) + | Kappterm of int * int (* number of arguments, slot size *) + | Kreturn of int (* slot size *) + | Krestart + | Kgrab of int (* number of arguments *) + | Kclosure of label * int + | Kclosurerec of label list * int + | Koffsetclosure of int + | Kgetglobal of Ident.t + | Ksetglobal of Ident.t + | Kconst of structured_constant + | Kmakeblock of int * int (* size, tag *) + | Kmakefloatblock of int + | Kgetfield of int + | Ksetfield of int + | Kgetfloatfield of int + | Ksetfloatfield of int + | Kvectlength + | Kgetvectitem + | Ksetvectitem + | Kgetstringchar + | Ksetstringchar + | Kbranch of label + | Kbranchif of label + | Kbranchifnot of label + | Kstrictbranchif of label + | Kstrictbranchifnot of label + | Kswitch of label array * label array + | Kboolnot + | Kpushtrap of label + | Kpoptrap + | Kraise + | Kcheck_signals + | Kccall of string * int + | Knegint | Kaddint | Ksubint | Kmulint | Kdivint | Kmodint + | Kandint | Korint | Kxorint | Klslint | Klsrint | Kasrint + | Kintcomp of comparison + | Koffsetint of int + | Koffsetref of int + | Kisint + | Kisout + | Kgetmethod + | Kgetpubmet of int + | Kgetdynmet + | Kevent of debug_event + | Kstop + +let immed_min = -0x40000000 +and immed_max = 0x3FFFFFFF + +(* Actually the abstract machine accomodates -0x80000000 to 0x7FFFFFFF, + but these numbers overflow the Caml type int if the compiler runs on + a 32-bit processor. *) diff --git a/bytecomp/instruct.mli b/bytecomp/instruct.mli new file mode 100644 index 0000000..5c47688 --- /dev/null +++ b/bytecomp/instruct.mli @@ -0,0 +1,126 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: instruct.mli,v 1.22 2005-10-25 15:56:45 doligez Exp $ *) + +(* The type of the instructions of the abstract machine *) + +open Lambda + +(* Structure of compilation environments *) + +type compilation_env = + { ce_stack: int Ident.tbl; (* Positions of variables in the stack *) + ce_heap: int Ident.tbl; (* Structure of the heap-allocated env *) + ce_rec: int Ident.tbl } (* Functions bound by the same let rec *) + +(* The ce_stack component gives locations of variables residing + in the stack. The locations are offsets w.r.t. the origin of the + stack frame. + The ce_heap component gives the positions of variables residing in the + heap-allocated environment. + The ce_rec component associate offsets to identifiers for functions + bound by the same let rec as the current function. The offsets + are used by the OFFSETCLOSURE instruction to recover the closure + pointer of the desired function from the env register (which + points to the closure for the current function). *) + +(* Debugging events *) + +(* Warning: when you change these types, check byterun/backtrace.c *) +type debug_event = + { mutable ev_pos: int; (* Position in bytecode *) + ev_module: string; (* Name of defining module *) + ev_loc: Location.t; (* Location in source file *) + ev_kind: debug_event_kind; (* Before/after event *) + ev_info: debug_event_info; (* Extra information *) + ev_typenv: Env.summary; (* Typing environment *) + ev_compenv: compilation_env; (* Compilation environment *) + ev_stacksize: int; (* Size of stack frame *) + ev_repr: debug_event_repr } (* Position of the representative *) + +and debug_event_kind = + Event_before + | Event_after of Types.type_expr + | Event_pseudo + +and debug_event_info = + Event_function + | Event_return of int + | Event_other + +and debug_event_repr = + Event_none + | Event_parent of int ref + | Event_child of int ref + +(* Abstract machine instructions *) + +type label = int (* Symbolic code labels *) + +type instruction = + Klabel of label + | Kacc of int + | Kenvacc of int + | Kpush + | Kpop of int + | Kassign of int + | Kpush_retaddr of label + | Kapply of int (* number of arguments *) + | Kappterm of int * int (* number of arguments, slot size *) + | Kreturn of int (* slot size *) + | Krestart + | Kgrab of int (* number of arguments *) + | Kclosure of label * int + | Kclosurerec of label list * int + | Koffsetclosure of int + | Kgetglobal of Ident.t + | Ksetglobal of Ident.t + | Kconst of structured_constant + | Kmakeblock of int * int (* size, tag *) + | Kmakefloatblock of int + | Kgetfield of int + | Ksetfield of int + | Kgetfloatfield of int + | Ksetfloatfield of int + | Kvectlength + | Kgetvectitem + | Ksetvectitem + | Kgetstringchar + | Ksetstringchar + | Kbranch of label + | Kbranchif of label + | Kbranchifnot of label + | Kstrictbranchif of label + | Kstrictbranchifnot of label + | Kswitch of label array * label array + | Kboolnot + | Kpushtrap of label + | Kpoptrap + | Kraise + | Kcheck_signals + | Kccall of string * int + | Knegint | Kaddint | Ksubint | Kmulint | Kdivint | Kmodint + | Kandint | Korint | Kxorint | Klslint | Klsrint | Kasrint + | Kintcomp of comparison + | Koffsetint of int + | Koffsetref of int + | Kisint + | Kisout + | Kgetmethod + | Kgetpubmet of int + | Kgetdynmet + | Kevent of debug_event + | Kstop + +val immed_min: int +val immed_max: int diff --git a/bytecomp/lambda.ml b/bytecomp/lambda.ml new file mode 100644 index 0000000..bcd6a19 --- /dev/null +++ b/bytecomp/lambda.ml @@ -0,0 +1,427 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lambda.ml,v 1.48 2008-08-01 16:57:10 mauny Exp $ *) + +open Misc +open Path +open Asttypes + +type primitive = + Pidentity + | Pignore + (* Globals *) + | Pgetglobal of Ident.t + | Psetglobal of Ident.t + (* Operations on heap blocks *) + | Pmakeblock of int * mutable_flag + | Pfield of int + | Psetfield of int * bool + | Pfloatfield of int + | Psetfloatfield of int + | Pduprecord of Types.record_representation * int + (* Force lazy values *) + | Plazyforce + (* External call *) + | Pccall of Primitive.description + (* Exceptions *) + | Praise + (* Boolean operations *) + | Psequand | Psequor | Pnot + (* Integer operations *) + | Pnegint | Paddint | Psubint | Pmulint | Pdivint | Pmodint + | Pandint | Porint | Pxorint + | Plslint | Plsrint | Pasrint + | Pintcomp of comparison + | Poffsetint of int + | Poffsetref of int + (* Float operations *) + | Pintoffloat | Pfloatofint + | Pnegfloat | Pabsfloat + | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat + | Pfloatcomp of comparison + (* String operations *) + | Pstringlength | Pstringrefu | Pstringsetu | Pstringrefs | Pstringsets + (* Array operations *) + | Pmakearray of array_kind + | Parraylength of array_kind + | Parrayrefu of array_kind + | Parraysetu of array_kind + | Parrayrefs of array_kind + | Parraysets of array_kind + (* Test if the argument is a block or an immediate integer *) + | Pisint + (* Test if the (integer) argument is outside an interval *) + | Pisout + (* Bitvect operations *) + | Pbittest + (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) + | Pbintofint of boxed_integer + | Pintofbint of boxed_integer + | Pcvtbint of boxed_integer (*source*) * boxed_integer (*destination*) + | Pnegbint of boxed_integer + | Paddbint of boxed_integer + | Psubbint of boxed_integer + | Pmulbint of boxed_integer + | Pdivbint of boxed_integer + | Pmodbint of boxed_integer + | Pandbint of boxed_integer + | Porbint of boxed_integer + | Pxorbint of boxed_integer + | Plslbint of boxed_integer + | Plsrbint of boxed_integer + | Pasrbint of boxed_integer + | Pbintcomp of boxed_integer * comparison + (* Operations on big arrays: (unsafe, #dimensions, kind, layout) *) + | Pbigarrayref of bool * int * bigarray_kind * bigarray_layout + | Pbigarrayset of bool * int * bigarray_kind * bigarray_layout + +and comparison = + Ceq | Cneq | Clt | Cgt | Cle | Cge + +and array_kind = + Pgenarray | Paddrarray | Pintarray | Pfloatarray + +and boxed_integer = + Pnativeint | Pint32 | Pint64 + +and bigarray_kind = + Pbigarray_unknown + | Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64 + +and bigarray_layout = + Pbigarray_unknown_layout + | Pbigarray_c_layout + | Pbigarray_fortran_layout + +type structured_constant = + Const_base of constant + | Const_pointer of int + | Const_block of int * structured_constant list + | Const_float_array of string list + | Const_immstring of string + +type function_kind = Curried | Tupled + +type let_kind = Strict | Alias | StrictOpt | Variable + +type meth_kind = Self | Public | Cached + +type shared_code = (int * int) list + +type lambda = + Lvar of Ident.t + | Lconst of structured_constant + | Lapply of lambda * lambda list * Location.t + | Lfunction of function_kind * Ident.t list * lambda + | Llet of let_kind * Ident.t * lambda * lambda + | Lletrec of (Ident.t * lambda) list * lambda + | Lprim of primitive * lambda list + | Lswitch of lambda * lambda_switch + | Lstaticraise of int * lambda list + | Lstaticcatch of lambda * (int * Ident.t list) * lambda + | Ltrywith of lambda * Ident.t * lambda + | Lifthenelse of lambda * lambda * lambda + | Lsequence of lambda * lambda + | Lwhile of lambda * lambda + | Lfor of Ident.t * lambda * lambda * direction_flag * lambda + | Lassign of Ident.t * lambda + | Lsend of meth_kind * lambda * lambda * lambda list + | Levent of lambda * lambda_event + | Lifused of Ident.t * lambda + +and lambda_switch = + { sw_numconsts: int; + sw_consts: (int * lambda) list; + sw_numblocks: int; + sw_blocks: (int * lambda) list; + sw_failaction : lambda option} + +and lambda_event = + { lev_loc: Location.t; + lev_kind: lambda_event_kind; + lev_repr: int ref option; + lev_env: Env.summary } + +and lambda_event_kind = + Lev_before + | Lev_after of Types.type_expr + | Lev_function + +let const_unit = Const_pointer 0 + +let lambda_unit = Lconst const_unit + +let rec same l1 l2 = + match (l1, l2) with + | Lvar v1, Lvar v2 -> + Ident.same v1 v2 + | Lconst c1, Lconst c2 -> + c1 = c2 + | Lapply(a1, bl1, _), Lapply(a2, bl2, _) -> + same a1 a2 && samelist same bl1 bl2 + | Lfunction(k1, idl1, a1), Lfunction(k2, idl2, a2) -> + k1 = k2 && samelist Ident.same idl1 idl2 && same a1 a2 + | Llet(k1, id1, a1, b1), Llet(k2, id2, a2, b2) -> + k1 = k2 && Ident.same id1 id2 && same a1 a2 && same b1 b2 + | Lletrec (bl1, a1), Lletrec (bl2, a2) -> + samelist samebinding bl1 bl2 && same a1 a2 + | Lprim(p1, al1), Lprim(p2, al2) -> + p1 = p2 && samelist same al1 al2 + | Lswitch(a1, s1), Lswitch(a2, s2) -> + same a1 a2 && sameswitch s1 s2 + | Lstaticraise(n1, al1), Lstaticraise(n2, al2) -> + n1 = n2 && samelist same al1 al2 + | Lstaticcatch(a1, (n1, idl1), b1), Lstaticcatch(a2, (n2, idl2), b2) -> + same a1 a2 && n1 = n2 && samelist Ident.same idl1 idl2 && same b1 b2 + | Ltrywith(a1, id1, b1), Ltrywith(a2, id2, b2) -> + same a1 a2 && Ident.same id1 id2 && same b1 b2 + | Lifthenelse(a1, b1, c1), Lifthenelse(a2, b2, c2) -> + same a1 a2 && same b1 b2 && same c1 c2 + | Lsequence(a1, b1), Lsequence(a2, b2) -> + same a1 a2 && same b1 b2 + | Lwhile(a1, b1), Lwhile(a2, b2) -> + same a1 a2 && same b1 b2 + | Lfor(id1, a1, b1, df1, c1), Lfor(id2, a2, b2, df2, c2) -> + Ident.same id1 id2 && same a1 a2 && + same b1 b2 && df1 = df2 && same c1 c2 + | Lassign(id1, a1), Lassign(id2, a2) -> + Ident.same id1 id2 && same a1 a2 + | Lsend(k1, a1, b1, cl1), Lsend(k2, a2, b2, cl2) -> + k1 = k2 && same a1 a2 && same b1 b2 && samelist same cl1 cl2 + | Levent(a1, ev1), Levent(a2, ev2) -> + same a1 a2 && ev1.lev_loc = ev2.lev_loc + | Lifused(id1, a1), Lifused(id2, a2) -> + Ident.same id1 id2 && same a1 a2 + | _, _ -> + false + +and samebinding (id1, c1) (id2, c2) = + Ident.same id1 id2 && same c1 c2 + +and sameswitch sw1 sw2 = + let samecase (n1, a1) (n2, a2) = n1 = n2 && same a1 a2 in + sw1.sw_numconsts = sw2.sw_numconsts && + sw1.sw_numblocks = sw2.sw_numblocks && + samelist samecase sw1.sw_consts sw2.sw_consts && + samelist samecase sw1.sw_blocks sw2.sw_blocks && + (match (sw1.sw_failaction, sw2.sw_failaction) with + | (None, None) -> true + | (Some a1, Some a2) -> same a1 a2 + | _ -> false) + +let name_lambda arg fn = + match arg with + Lvar id -> fn id + | _ -> let id = Ident.create "let" in Llet(Strict, id, arg, fn id) + +let name_lambda_list args fn = + let rec name_list names = function + [] -> fn (List.rev names) + | (Lvar id as arg) :: rem -> + name_list (arg :: names) rem + | arg :: rem -> + let id = Ident.create "let" in + Llet(Strict, id, arg, name_list (Lvar id :: names) rem) in + name_list [] args + +let rec iter f = function + Lvar _ + | Lconst _ -> () + | Lapply(fn, args, _) -> + f fn; List.iter f args + | Lfunction(kind, params, body) -> + f body + | Llet(str, id, arg, body) -> + f arg; f body + | Lletrec(decl, body) -> + f body; + List.iter (fun (id, exp) -> f exp) decl + | Lprim(p, args) -> + List.iter f args + | Lswitch(arg, sw) -> + f arg; + List.iter (fun (key, case) -> f case) sw.sw_consts; + List.iter (fun (key, case) -> f case) sw.sw_blocks; + begin match sw.sw_failaction with + | None -> () + | Some l -> f l + end + | Lstaticraise (_,args) -> + List.iter f args + | Lstaticcatch(e1, (_,vars), e2) -> + f e1; f e2 + | Ltrywith(e1, exn, e2) -> + f e1; f e2 + | Lifthenelse(e1, e2, e3) -> + f e1; f e2; f e3 + | Lsequence(e1, e2) -> + f e1; f e2 + | Lwhile(e1, e2) -> + f e1; f e2 + | Lfor(v, e1, e2, dir, e3) -> + f e1; f e2; f e3 + | Lassign(id, e) -> + f e + | Lsend (k, met, obj, args) -> + List.iter f (met::obj::args) + | Levent (lam, evt) -> + f lam + | Lifused (v, e) -> + f e + +module IdentSet = + Set.Make(struct + type t = Ident.t + let compare = compare + end) + +let free_ids get l = + let fv = ref IdentSet.empty in + let rec free l = + iter free l; + fv := List.fold_right IdentSet.add (get l) !fv; + match l with + Lfunction(kind, params, body) -> + List.iter (fun param -> fv := IdentSet.remove param !fv) params + | Llet(str, id, arg, body) -> + fv := IdentSet.remove id !fv + | Lletrec(decl, body) -> + List.iter (fun (id, exp) -> fv := IdentSet.remove id !fv) decl + | Lstaticcatch(e1, (_,vars), e2) -> + List.iter (fun id -> fv := IdentSet.remove id !fv) vars + | Ltrywith(e1, exn, e2) -> + fv := IdentSet.remove exn !fv + | Lfor(v, e1, e2, dir, e3) -> + fv := IdentSet.remove v !fv + | Lassign(id, e) -> + fv := IdentSet.add id !fv + | Lvar _ | Lconst _ | Lapply _ + | Lprim _ | Lswitch _ | Lstaticraise _ + | Lifthenelse _ | Lsequence _ | Lwhile _ + | Lsend _ | Levent _ | Lifused _ -> () + in free l; !fv + +let free_variables l = + free_ids (function Lvar id -> [id] | _ -> []) l + +let free_methods l = + free_ids (function Lsend(Self, Lvar meth, obj, _) -> [meth] | _ -> []) l + +(* Check if an action has a "when" guard *) +let raise_count = ref 0 + +let next_raise_count () = + incr raise_count ; + !raise_count + +(* Anticipated staticraise, for guards *) +let staticfail = Lstaticraise (0,[]) + +let rec is_guarded = function + | Lifthenelse( cond, body, Lstaticraise (0,[])) -> true + | Llet(str, id, lam, body) -> is_guarded body + | Levent(lam, ev) -> is_guarded lam + | _ -> false + +let rec patch_guarded patch = function + | Lifthenelse (cond, body, Lstaticraise (0,[])) -> + Lifthenelse (cond, body, patch) + | Llet(str, id, lam, body) -> + Llet (str, id, lam, patch_guarded patch body) + | Levent(lam, ev) -> + Levent (patch_guarded patch lam, ev) + | _ -> fatal_error "Lambda.patch_guarded" + +(* Translate an access path *) + +let rec transl_path = function + Pident id -> + if Ident.global id then Lprim(Pgetglobal id, []) else Lvar id + | Pdot(p, s, pos) -> + Lprim(Pfield pos, [transl_path p]) + | Papply(p1, p2) -> + fatal_error "Lambda.transl_path" + +(* Compile a sequence of expressions *) + +let rec make_sequence fn = function + [] -> lambda_unit + | [x] -> fn x + | x::rem -> + let lam = fn x in Lsequence(lam, make_sequence fn rem) + +(* Apply a substitution to a lambda-term. + Assumes that the bound variables of the lambda-term do not + belong to the domain of the substitution. + Assumes that the image of the substitution is out of reach + of the bound variables of the lambda-term (no capture). *) + +let subst_lambda s lam = + let rec subst = function + Lvar id as l -> + begin try Ident.find_same id s with Not_found -> l end + | Lconst sc as l -> l + | Lapply(fn, args, loc) -> Lapply(subst fn, List.map subst args, loc) + | Lfunction(kind, params, body) -> Lfunction(kind, params, subst body) + | Llet(str, id, arg, body) -> Llet(str, id, subst arg, subst body) + | Lletrec(decl, body) -> Lletrec(List.map subst_decl decl, subst body) + | Lprim(p, args) -> Lprim(p, List.map subst args) + | Lswitch(arg, sw) -> + Lswitch(subst arg, + {sw with sw_consts = List.map subst_case sw.sw_consts; + sw_blocks = List.map subst_case sw.sw_blocks; + sw_failaction = + match sw.sw_failaction with + | None -> None + | Some l -> Some (subst l)}) + + | Lstaticraise (i,args) -> Lstaticraise (i, List.map subst args) + | Lstaticcatch(e1, io, e2) -> Lstaticcatch(subst e1, io, subst e2) + | Ltrywith(e1, exn, e2) -> Ltrywith(subst e1, exn, subst e2) + | Lifthenelse(e1, e2, e3) -> Lifthenelse(subst e1, subst e2, subst e3) + | Lsequence(e1, e2) -> Lsequence(subst e1, subst e2) + | Lwhile(e1, e2) -> Lwhile(subst e1, subst e2) + | Lfor(v, e1, e2, dir, e3) -> Lfor(v, subst e1, subst e2, dir, subst e3) + | Lassign(id, e) -> Lassign(id, subst e) + | Lsend (k, met, obj, args) -> + Lsend (k, subst met, subst obj, List.map subst args) + | Levent (lam, evt) -> Levent (subst lam, evt) + | Lifused (v, e) -> Lifused (v, subst e) + and subst_decl (id, exp) = (id, subst exp) + and subst_case (key, case) = (key, subst case) + in subst lam + + +(* To let-bind expressions to variables *) + +let bind str var exp body = + match exp with + Lvar var' when Ident.same var var' -> body + | _ -> Llet(str, var, exp, body) + +and commute_comparison = function +| Ceq -> Ceq| Cneq -> Cneq +| Clt -> Cgt | Cle -> Cge +| Cgt -> Clt | Cge -> Cle + +and negate_comparison = function +| Ceq -> Cneq| Cneq -> Ceq +| Clt -> Cge | Cle -> Cgt +| Cgt -> Cle | Cge -> Clt + + diff --git a/bytecomp/lambda.mli b/bytecomp/lambda.mli new file mode 100644 index 0000000..fe9fe2b --- /dev/null +++ b/bytecomp/lambda.mli @@ -0,0 +1,208 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lambda.mli,v 1.46 2008-08-01 16:57:10 mauny Exp $ *) + +(* The "lambda" intermediate code *) + +open Asttypes + +type primitive = + Pidentity + | Pignore + (* Globals *) + | Pgetglobal of Ident.t + | Psetglobal of Ident.t + (* Operations on heap blocks *) + | Pmakeblock of int * mutable_flag + | Pfield of int + | Psetfield of int * bool + | Pfloatfield of int + | Psetfloatfield of int + | Pduprecord of Types.record_representation * int + (* Force lazy values *) + | Plazyforce + (* External call *) + | Pccall of Primitive.description + (* Exceptions *) + | Praise + (* Boolean operations *) + | Psequand | Psequor | Pnot + (* Integer operations *) + | Pnegint | Paddint | Psubint | Pmulint | Pdivint | Pmodint + | Pandint | Porint | Pxorint + | Plslint | Plsrint | Pasrint + | Pintcomp of comparison + | Poffsetint of int + | Poffsetref of int + (* Float operations *) + | Pintoffloat | Pfloatofint + | Pnegfloat | Pabsfloat + | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat + | Pfloatcomp of comparison + (* String operations *) + | Pstringlength | Pstringrefu | Pstringsetu | Pstringrefs | Pstringsets + (* Array operations *) + | Pmakearray of array_kind + | Parraylength of array_kind + | Parrayrefu of array_kind + | Parraysetu of array_kind + | Parrayrefs of array_kind + | Parraysets of array_kind + (* Test if the argument is a block or an immediate integer *) + | Pisint + (* Test if the (integer) argument is outside an interval *) + | Pisout + (* Bitvect operations *) + | Pbittest + (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) + | Pbintofint of boxed_integer + | Pintofbint of boxed_integer + | Pcvtbint of boxed_integer (*source*) * boxed_integer (*destination*) + | Pnegbint of boxed_integer + | Paddbint of boxed_integer + | Psubbint of boxed_integer + | Pmulbint of boxed_integer + | Pdivbint of boxed_integer + | Pmodbint of boxed_integer + | Pandbint of boxed_integer + | Porbint of boxed_integer + | Pxorbint of boxed_integer + | Plslbint of boxed_integer + | Plsrbint of boxed_integer + | Pasrbint of boxed_integer + | Pbintcomp of boxed_integer * comparison + (* Operations on big arrays: (unsafe, #dimensions, kind, layout) *) + | Pbigarrayref of bool * int * bigarray_kind * bigarray_layout + | Pbigarrayset of bool * int * bigarray_kind * bigarray_layout + +and comparison = + Ceq | Cneq | Clt | Cgt | Cle | Cge + +and array_kind = + Pgenarray | Paddrarray | Pintarray | Pfloatarray + +and boxed_integer = + Pnativeint | Pint32 | Pint64 + +and bigarray_kind = + Pbigarray_unknown + | Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64 + +and bigarray_layout = + Pbigarray_unknown_layout + | Pbigarray_c_layout + | Pbigarray_fortran_layout + +type structured_constant = + Const_base of constant + | Const_pointer of int + | Const_block of int * structured_constant list + | Const_float_array of string list + | Const_immstring of string + +type function_kind = Curried | Tupled + +type let_kind = Strict | Alias | StrictOpt | Variable +(* Meaning of kinds for let x = e in e': + Strict: e may have side-effets; always evaluate e first + (If e is a simple expression, e.g. a variable or constant, + we may still substitute e'[x/e].) + Alias: e is pure, we can substitute e'[x/e] if x has 0 or 1 occurrences + in e' + StrictOpt: e does not have side-effects, but depend on the store; + we can discard e if x does not appear in e' + Variable: the variable x is assigned later in e' *) + +type meth_kind = Self | Public | Cached + +type shared_code = (int * int) list (* stack size -> code label *) + +type lambda = + Lvar of Ident.t + | Lconst of structured_constant + | Lapply of lambda * lambda list * Location.t + | Lfunction of function_kind * Ident.t list * lambda + | Llet of let_kind * Ident.t * lambda * lambda + | Lletrec of (Ident.t * lambda) list * lambda + | Lprim of primitive * lambda list + | Lswitch of lambda * lambda_switch + | Lstaticraise of int * lambda list + | Lstaticcatch of lambda * (int * Ident.t list) * lambda + | Ltrywith of lambda * Ident.t * lambda + | Lifthenelse of lambda * lambda * lambda + | Lsequence of lambda * lambda + | Lwhile of lambda * lambda + | Lfor of Ident.t * lambda * lambda * direction_flag * lambda + | Lassign of Ident.t * lambda + | Lsend of meth_kind * lambda * lambda * lambda list + | Levent of lambda * lambda_event + | Lifused of Ident.t * lambda + +and lambda_switch = + { sw_numconsts: int; (* Number of integer cases *) + sw_consts: (int * lambda) list; (* Integer cases *) + sw_numblocks: int; (* Number of tag block cases *) + sw_blocks: (int * lambda) list; (* Tag block cases *) + sw_failaction : lambda option} (* Action to take if failure *) +and lambda_event = + { lev_loc: Location.t; + lev_kind: lambda_event_kind; + lev_repr: int ref option; + lev_env: Env.summary } + +and lambda_event_kind = + Lev_before + | Lev_after of Types.type_expr + | Lev_function + +val same: lambda -> lambda -> bool +val const_unit: structured_constant +val lambda_unit: lambda +val name_lambda: lambda -> (Ident.t -> lambda) -> lambda +val name_lambda_list: lambda list -> (lambda list -> lambda) -> lambda +val is_guarded: lambda -> bool +val patch_guarded : lambda -> lambda -> lambda + +val iter: (lambda -> unit) -> lambda -> unit +module IdentSet: Set.S with type elt = Ident.t +val free_variables: lambda -> IdentSet.t +val free_methods: lambda -> IdentSet.t + +val transl_path: Path.t -> lambda +val make_sequence: ('a -> lambda) -> 'a list -> lambda + +val subst_lambda: lambda Ident.tbl -> lambda -> lambda +val bind : let_kind -> Ident.t -> lambda -> lambda -> lambda + +val commute_comparison : comparison -> comparison +val negate_comparison : comparison -> comparison + +(***********************) +(* For static failures *) +(***********************) + +(* Get a new static failure ident *) +val next_raise_count : unit -> int + + +val staticfail : lambda (* Anticipated static failure *) + +(* Check anticipated failure, substitute its final value *) +val is_guarded: lambda -> bool +val patch_guarded : lambda -> lambda -> lambda + diff --git a/bytecomp/matching.ml b/bytecomp/matching.ml new file mode 100644 index 0000000..d331d7b --- /dev/null +++ b/bytecomp/matching.ml @@ -0,0 +1,2706 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: matching.ml,v 1.71 2008-08-01 16:57:10 mauny Exp $ *) + +(* Compilation of pattern matching *) + +open Misc +open Asttypes +open Primitive +open Types +open Typedtree +open Lambda +open Parmatch +open Printf + +(* See Peyton-Jones, ``The Implementation of functional programming + languages'', chapter 5. *) +(* + Bon, au commencement du monde c'etait vrai. + Now, see Lefessant-Maranget ``Optimizing Pattern-Matching'' ICFP'2001 +*) + + +(* + Many functions on the various data structures ofthe algorithm : + - Pattern matrices. + - Default environments: mapping from matrices to exit numbers. + - Contexts: matrices whose column are partitioned into + left and right. + - Jump sumaries: mapping from exit numbers to contexts +*) + +type matrix = pattern list list + +let add_omega_column pss = List.map (fun ps -> omega::ps) pss + +type ctx = {left:pattern list ; right:pattern list} + +let pretty_ctx ctx = + List.iter + (fun {left=left ; right=right} -> + prerr_string "LEFT:" ; + pretty_line left ; + prerr_string " RIGHT:" ; + pretty_line right ; + prerr_endline "") + ctx + +let le_ctx c1 c2 = + le_pats c1.left c2.left && + le_pats c1.right c2.right + +let lshift {left=left ; right=right} = match right with +| x::xs -> {left=x::left ; right=xs} +| _ -> assert false + +let lforget {left=left ; right=right} = match right with +| x::xs -> {left=omega::left ; right=xs} +| _ -> assert false + +let rec small_enough n = function + | [] -> true + | _::rem -> + if n <= 0 then false + else small_enough (n-1) rem + +let ctx_lshift ctx = + if small_enough 31 ctx then + List.map lshift ctx + else (* Context pruning *) begin + get_mins le_ctx (List.map lforget ctx) + end + +let rshift {left=left ; right=right} = match left with +| p::ps -> {left=ps ; right=p::right} +| _ -> assert false + +let ctx_rshift ctx = List.map rshift ctx + +let rec nchars n ps = + if n <= 0 then [],ps + else match ps with + | p::rem -> + let chars, cdrs = nchars (n-1) rem in + p::chars,cdrs + | _ -> assert false + +let rshift_num n {left=left ; right=right} = + let shifted,left = nchars n left in + {left=left ; right = shifted@right} + +let ctx_rshift_num n ctx = List.map (rshift_num n) ctx + +(* Recombination of contexts (eg: (_,_)::p1::p2::rem -> (p1,p2)::rem) + All mutable fields are replaced by '_', since side-effects in + guards can alter these fields *) + +let combine {left=left ; right=right} = match left with +| p::ps -> {left=ps ; right=set_args_erase_mutable p right} +| _ -> assert false + +let ctx_combine ctx = List.map combine ctx + +let ncols = function + | [] -> 0 + | ps::_ -> List.length ps + + +exception NoMatch +exception OrPat + +let filter_matrix matcher pss = + + let rec filter_rec = function + | (p::ps)::rem -> + begin match p.pat_desc with + | Tpat_alias (p,_) -> + filter_rec ((p::ps)::rem) + | Tpat_var _ -> + filter_rec ((omega::ps)::rem) + | _ -> + begin + let rem = filter_rec rem in + try + matcher p ps::rem + with + | NoMatch -> rem + | OrPat -> + match p.pat_desc with + | Tpat_or (p1,p2,_) -> filter_rec [(p1::ps) ;(p2::ps)]@rem + | _ -> assert false + end + end + | [] -> [] + | _ -> + pretty_matrix pss ; + fatal_error "Matching.filter_matrix" in + filter_rec pss + +let make_default matcher env = + let rec make_rec = function + | [] -> [] + | ([[]],i)::_ -> [[[]],i] + | (pss,i)::rem -> + let rem = make_rec rem in + match filter_matrix matcher pss with + | [] -> rem + | ([]::_) -> ([[]],i)::rem + | pss -> (pss,i)::rem in + make_rec env + +let ctx_matcher p = + let p = normalize_pat p in + match p.pat_desc with + | Tpat_construct (cstr,omegas) -> + (fun q rem -> match q.pat_desc with + | Tpat_construct (cstr',args) when cstr.cstr_tag=cstr'.cstr_tag -> + p,args @ rem + | Tpat_any -> p,omegas @ rem + | _ -> raise NoMatch) + | Tpat_constant cst -> + (fun q rem -> match q.pat_desc with + | Tpat_constant cst' when cst=cst' -> + p,rem + | Tpat_any -> p,rem + | _ -> raise NoMatch) + | Tpat_variant (lab,Some omega,_) -> + (fun q rem -> match q.pat_desc with + | Tpat_variant (lab',Some arg,_) when lab=lab' -> + p,arg::rem + | Tpat_any -> p,omega::rem + | _ -> raise NoMatch) + | Tpat_variant (lab,None,_) -> + (fun q rem -> match q.pat_desc with + | Tpat_variant (lab',None,_) when lab=lab' -> + p,rem + | Tpat_any -> p,rem + | _ -> raise NoMatch) + | Tpat_array omegas -> + let len = List.length omegas in + (fun q rem -> match q.pat_desc with + | Tpat_array args when List.length args=len -> + p,args @ rem + | Tpat_any -> p, omegas @ rem + | _ -> raise NoMatch) + | Tpat_tuple omegas -> + (fun q rem -> match q.pat_desc with + | Tpat_tuple args -> p,args @ rem + | _ -> p, omegas @ rem) + | Tpat_record l -> (* Records are normalized *) + (fun q rem -> match q.pat_desc with + | Tpat_record l' -> + let l' = all_record_args l' in + p, List.fold_right (fun (_,p) r -> p::r) l' rem + | _ -> p,List.fold_right (fun (_,p) r -> p::r) l rem) + | Tpat_lazy omega -> + (fun q rem -> match q.pat_desc with + | Tpat_lazy arg -> p, (arg::rem) + | _ -> p, (omega::rem)) + | _ -> fatal_error "Matching.ctx_matcher" + + + + +let filter_ctx q ctx = + + let matcher = ctx_matcher q in + + let rec filter_rec = function + | ({right=p::ps} as l)::rem -> + begin match p.pat_desc with + | Tpat_or (p1,p2,_) -> + filter_rec ({l with right=p1::ps}::{l with right=p2::ps}::rem) + | Tpat_alias (p,_) -> + filter_rec ({l with right=p::ps}::rem) + | Tpat_var _ -> + filter_rec ({l with right=omega::ps}::rem) + | _ -> + begin let rem = filter_rec rem in + try + let to_left, right = matcher p ps in + {left=to_left::l.left ; right=right}::rem + with + | NoMatch -> rem + end + end + | [] -> [] + | _ -> fatal_error "Matching.filter_ctx" in + + filter_rec ctx + +let select_columns pss ctx = + let n = ncols pss in + List.fold_right + (fun ps r -> + List.fold_right + (fun {left=left ; right=right} r -> + let transfert, right = nchars n right in + try + {left = lubs transfert ps @ left ; right=right}::r + with + | Empty -> r) + ctx r) + pss [] + +let ctx_lub p ctx = + List.fold_right + (fun {left=left ; right=right} r -> + match right with + | q::rem -> + begin try + {left=left ; right = lub p q::rem}::r + with + | Empty -> r + end + | _ -> fatal_error "Matching.ctx_lub") + ctx [] + +let ctx_match ctx pss = + List.exists + (fun {right=qs} -> + List.exists + (fun ps -> compats qs ps) + pss) + ctx + +type jumps = (int * ctx ) list + +let pretty_jumps env = match env with +| [] -> () +| _ -> + List.iter + (fun (i,ctx) -> + Printf.fprintf stderr "jump for %d\n" i ; + pretty_ctx ctx) + env + + +let rec jumps_extract i = function + | [] -> [],[] + | (j,pss) as x::rem as all -> + if i=j then pss,rem + else if j < i then [],all + else + let r,rem = jumps_extract i rem in + r,(x::rem) + +let rec jumps_remove i = function + | [] -> [] + | (j,_)::rem when i=j -> rem + | x::rem -> x::jumps_remove i rem + +let jumps_empty = [] +and jumps_is_empty = function + | [] -> true + | _ -> false + +let jumps_singleton i = function + | [] -> [] + | ctx -> [i,ctx] + +let jumps_add i pss jumps = match pss with +| [] -> jumps +| _ -> + let rec add = function + | [] -> [i,pss] + | (j,qss) as x::rem as all -> + if j > i then x::add rem + else if j < i then (i,pss)::all + else (i,(get_mins le_ctx (pss@qss)))::rem in + add jumps + + +let rec jumps_union env1 env2 = match env1,env2 with +| [],_ -> env2 +| _,[] -> env1 +| ((i1,pss1) as x1::rem1), ((i2,pss2) as x2::rem2) -> + if i1=i2 then + (i1,get_mins le_ctx (pss1@pss2))::jumps_union rem1 rem2 + else if i1 > i2 then + x1::jumps_union rem1 env2 + else + x2::jumps_union env1 rem2 + + +let rec merge = function + | env1::env2::rem -> jumps_union env1 env2::merge rem + | envs -> envs + +let rec jumps_unions envs = match envs with + | [] -> [] + | [env] -> env + | _ -> jumps_unions (merge envs) + +let rec jumps_map f env = + List.map + (fun (i,pss) -> i,f pss) + env + +(* Pattern matching before any compilation *) + +type pattern_matching = + { mutable cases : (pattern list * lambda) list; + args : (lambda * let_kind) list ; + default : (matrix * int) list} + +(* Pattern matching after application of both the or-pat rule and the + mixture rule *) + +type pm_or_compiled = + {body : pattern_matching ; + handlers : (matrix * int * Ident.t list * pattern_matching) list ; + or_matrix : matrix ; } + +type pm_half_compiled = + | PmOr of pm_or_compiled + | PmVar of pm_var_compiled + | Pm of pattern_matching + +and pm_var_compiled = + {inside : pm_half_compiled ; var_arg : lambda ; } + +type pm_half_compiled_info = + {me : pm_half_compiled ; + matrix : matrix ; + top_default : (matrix * int) list ; } + +let pretty_cases cases = + List.iter + (fun ((ps),l) -> + List.iter + (fun p -> + Parmatch.top_pretty Format.str_formatter p ; + prerr_string " " ; + prerr_string (Format.flush_str_formatter ())) + ps ; +(* + prerr_string " -> " ; + Printlambda.lambda Format.str_formatter l ; + prerr_string (Format.flush_str_formatter ()) ; +*) + prerr_endline "") + cases + +let pretty_def def = + prerr_endline "+++++ Defaults +++++" ; + List.iter + (fun (pss,i) -> + Printf.fprintf stderr "Matrix for %d\n" i ; + pretty_matrix pss) + def ; + prerr_endline "+++++++++++++++++++++" + +let pretty_pm pm = pretty_cases pm.cases + + +let rec pretty_precompiled = function + | Pm pm -> + prerr_endline "++++ PM ++++" ; + pretty_pm pm + | PmVar x -> + prerr_endline "++++ VAR ++++" ; + pretty_precompiled x.inside + | PmOr x -> + prerr_endline "++++ OR ++++" ; + pretty_pm x.body ; + List.iter + (fun (_,i,_,pm) -> + eprintf "++ Handler %d ++\n" i ; + pretty_pm pm) + x.handlers + +let pretty_precompiled_res first nexts = + pretty_precompiled first ; + List.iter + (fun (e, pmh) -> + eprintf "** DEFAULT %d **\n" e ; + pretty_precompiled pmh) + nexts + + + +(* A slight attempt to identify semantically equivalent lambda-expressions *) +exception Not_simple + +let rec raw_rec env = function + | Llet(Alias,x,ex, body) -> raw_rec ((x,raw_rec env ex)::env) body + | Lvar id as l -> + begin try List.assoc id env with + | Not_found -> l + end + | Lprim (Pfield i,args) -> + Lprim (Pfield i, List.map (raw_rec env) args) + | Lconst _ as l -> l + | Lstaticraise (i,args) -> + Lstaticraise (i, List.map (raw_rec env) args) + | _ -> raise Not_simple + +let raw_action l = try raw_rec [] l with Not_simple -> l + +let same_actions = function + | [] -> None + | [_,act] -> Some act + | (_,act0) :: rem -> + try + let raw_act0 = raw_rec [] act0 in + let rec s_rec = function + | [] -> Some act0 + | (_,act)::rem -> + if raw_act0 = raw_rec [] act then + s_rec rem + else + None in + s_rec rem + with + | Not_simple -> None + +let equal_action act1 act2 = + try + let raw1 = raw_rec [] act1 + and raw2 = raw_rec [] act2 in + raw1 = raw2 + with + | Not_simple -> false + +(* Test for swapping two clauses *) + +let up_ok_action act1 act2 = + try + let raw1 = raw_rec [] act1 + and raw2 = raw_rec [] act2 in + match raw1, raw2 with + | Lstaticraise (i1,[]), Lstaticraise (i2,[]) -> i1=i2 + | _,_ -> raw1 = raw2 + with + | Not_simple -> false + +let up_ok (ps,act_p) l = + List.for_all + (fun (qs,act_q) -> + up_ok_action act_p act_q || + not (Parmatch.compats ps qs)) + l + + +(* + Simplify fonction normalize the first column of the match + - records are expanded so that they posses all fields + - aliases are removed and replaced by bindings in actions. + However or-patterns are simplified differently, + - aliases are not removed + - or patterns (_|p) are changed into _ +*) + +exception Var of pattern + +let simplify_or p = + let rec simpl_rec p = match p with + | {pat_desc = Tpat_any|Tpat_var _} -> raise (Var p) + | {pat_desc = Tpat_alias (q,id)} -> + begin try + {p with pat_desc = Tpat_alias (simpl_rec q,id)} + with + | Var q -> raise (Var {p with pat_desc = Tpat_alias (q,id)}) + end + | {pat_desc = Tpat_or (p1,p2,o)} -> + let q1 = simpl_rec p1 in + begin try + let q2 = simpl_rec p2 in + {p with pat_desc = Tpat_or (q1, q2, o)} + with + | Var q2 -> raise (Var {p with pat_desc = Tpat_or (q1, q2, o)}) + end + | {pat_desc = Tpat_record lbls} -> + let all_lbls = all_record_args lbls in + {p with pat_desc=Tpat_record all_lbls} + | _ -> p in + try + simpl_rec p + with + | Var p -> p + +let rec simplify_cases args cls = match args with +| [] -> assert false +| (arg,_)::_ -> + let rec simplify = function + | [] -> [] + | ((pat :: patl, action) as cl) :: rem -> + begin match pat.pat_desc with + | Tpat_var id -> + (omega :: patl, bind Alias id arg action) :: + simplify rem + | Tpat_any -> + cl :: simplify rem + | Tpat_alias(p, id) -> + simplify ((p :: patl, bind Alias id arg action) :: rem) + | Tpat_record [] -> + (omega :: patl, action):: + simplify rem + | Tpat_record lbls -> + let all_lbls = all_record_args lbls in + let full_pat = {pat with pat_desc=Tpat_record all_lbls} in + (full_pat::patl,action):: + simplify rem + | Tpat_or _ -> + let pat_simple = simplify_or pat in + begin match pat_simple.pat_desc with + | Tpat_or _ -> + (pat_simple :: patl, action) :: + simplify rem + | _ -> + simplify ((pat_simple::patl,action) :: rem) + end + | _ -> cl :: simplify rem + end + | _ -> assert false in + + simplify cls + + + +(* Once matchings are simplified one easily finds + their nature *) + +let rec what_is_cases cases = match cases with +| ({pat_desc=Tpat_any} :: _, _) :: rem -> what_is_cases rem +| (({pat_desc=(Tpat_var _|Tpat_or (_,_,_)|Tpat_alias (_,_))}::_),_)::_ + -> assert false (* applies to simplified matchings only *) +| (p::_,_)::_ -> p +| [] -> omega +| _ -> assert false + + + +(* A few operation on default environments *) +let as_matrix cases = get_mins le_pats (List.map (fun (ps,_) -> ps) cases) + +let cons_default matrix raise_num default = + match matrix with + | [] -> default + | _ -> (matrix,raise_num)::default + +let default_compat p def = + List.fold_right + (fun (pss,i) r -> + let qss = + List.fold_right + (fun qs r -> match qs with + | q::rem when Parmatch.compat p q -> rem::r + | _ -> r) + pss [] in + match qss with + | [] -> r + | _ -> (qss,i)::r) + def [] + +(* Or-pattern expansion, variables are a complication w.r.t. the article *) +let rec extract_vars r p = match p.pat_desc with +| Tpat_var id -> IdentSet.add id r +| Tpat_alias (p, id) -> + extract_vars (IdentSet.add id r) p +| Tpat_tuple pats -> + List.fold_left extract_vars r pats +| Tpat_record lpats -> + List.fold_left + (fun r (_,p) -> extract_vars r p) + r lpats +| Tpat_construct (_,pats) -> + List.fold_left extract_vars r pats +| Tpat_array pats -> + List.fold_left extract_vars r pats +| Tpat_variant (_,Some p, _) -> extract_vars r p +| Tpat_lazy p -> extract_vars r p +| Tpat_or (p,_,_) -> extract_vars r p +| Tpat_constant _|Tpat_any|Tpat_variant (_,None,_) -> r + +exception Cannot_flatten + +let mk_alpha_env arg aliases ids = + List.map + (fun id -> id, + if List.mem id aliases then + match arg with + | Some v -> v + | _ -> raise Cannot_flatten + else + Ident.create (Ident.name id)) + ids + +let rec explode_or_pat arg patl mk_action rem vars aliases = function + | {pat_desc = Tpat_or (p1,p2,_)} -> + explode_or_pat + arg patl mk_action + (explode_or_pat arg patl mk_action rem vars aliases p2) + vars aliases p1 + | {pat_desc = Tpat_alias (p,id)} -> + explode_or_pat arg patl mk_action rem vars (id::aliases) p + | {pat_desc = Tpat_var x} -> + let env = mk_alpha_env arg (x::aliases) vars in + (omega::patl,mk_action (List.map snd env))::rem + | p -> + let env = mk_alpha_env arg aliases vars in + (alpha_pat env p::patl,mk_action (List.map snd env))::rem + +let pm_free_variables {cases=cases} = + List.fold_right + (fun (_,act) r -> IdentSet.union (free_variables act) r) + cases IdentSet.empty + + +(* Basic grouping predicates *) + +let group_constant = function + | {pat_desc= Tpat_constant _} -> true + | _ -> false + +and group_constructor = function + | {pat_desc = Tpat_construct (_, _)} -> true + | _ -> false + +and group_variant = function + | {pat_desc = Tpat_variant (_, _, _)} -> true + | _ -> false + +and group_var = function + | {pat_desc=Tpat_any} -> true + | _ -> false + +and group_tuple = function + | {pat_desc = (Tpat_tuple _|Tpat_any)} -> true + | _ -> false + +and group_record = function + | {pat_desc = (Tpat_record _|Tpat_any)} -> true + | _ -> false + +and group_array = function + | {pat_desc=Tpat_array _} -> true + | _ -> false + +and group_lazy = function + | {pat_desc = Tpat_lazy _} -> true + | _ -> false + +let get_group p = match p.pat_desc with +| Tpat_any -> group_var +| Tpat_constant _ -> group_constant +| Tpat_construct (_, _) -> group_constructor +| Tpat_tuple _ -> group_tuple +| Tpat_record _ -> group_record +| Tpat_array _ -> group_array +| Tpat_variant (_,_,_) -> group_variant +| Tpat_lazy _ -> group_lazy +| _ -> fatal_error "Matching.get_group" + + + +let is_or p = match p.pat_desc with +| Tpat_or _ -> true +| _ -> false + +(* Conditions for appending to the Or matrix *) +let conda p q = not (compat p q) +and condb act ps qs = not (is_guarded act) && Parmatch.le_pats qs ps + +let or_ok p ps l = + List.for_all + (function + | ({pat_desc=Tpat_or _} as q::qs,act) -> + conda p q || condb act ps qs + | _ -> true) + l + +(* Insert or append a pattern in the Or matrix *) + +let equiv_pat p q = le_pat p q && le_pat q p + +let rec get_equiv p l = match l with + | (q::_,_) as cl::rem -> + if equiv_pat p q then + let others,rem = get_equiv p rem in + cl::others,rem + else + [],l + | _ -> [],l + + +let insert_or_append p ps act ors no = + let rec attempt seen = function + | (q::qs,act_q) as cl::rem -> + if is_or q then begin + if compat p q then + if + IdentSet.is_empty (extract_vars IdentSet.empty p) && + IdentSet.is_empty (extract_vars IdentSet.empty q) && + equiv_pat p q + then (* attempt insert, for equivalent orpats with no variables *) + let _, not_e = get_equiv q rem in + if + or_ok p ps not_e && (* check append condition for head of O *) + List.for_all (* check insert condition for tail of O *) + (fun cl -> match cl with + | (q::_,_) -> not (compat p q) + | _ -> assert false) + seen + then (* insert *) + List.rev_append seen ((p::ps,act)::cl::rem), no + else (* fail to insert or append *) + ors,(p::ps,act)::no + else if condb act_q ps qs then (* check condition (b) for append *) + attempt (cl::seen) rem + else + ors,(p::ps,act)::no + else (* p # q, go on with append/insert *) + attempt (cl::seen) rem + end else (* q is not a or-pat, go on with append/insert *) + attempt (cl::seen) rem + | _ -> (* [] in fact *) + (p::ps,act)::ors,no in (* success in appending *) + attempt [] ors + +(* Reconstruct default information from half_compiled pm list *) + +let rec rebuild_matrix pmh = match pmh with + | Pm pm -> as_matrix pm.cases + | PmOr {or_matrix=m} -> m + | PmVar x -> add_omega_column (rebuild_matrix x.inside) + +let rec rebuild_default nexts def = match nexts with +| [] -> def +| (e, pmh)::rem -> + (add_omega_column (rebuild_matrix pmh), e):: + rebuild_default rem def + +let rebuild_nexts arg nexts k = + List.fold_right + (fun (e, pm) k -> (e, PmVar {inside=pm ; var_arg=arg})::k) + nexts k + + +(* + Split a matching. + Splitting is first directed by or-patterns, then by + tests (e.g. constructors)/variable transitions. + + The approach is greedy, every split function attempt to + raise rows as much as possible in the top matrix, + then splitting applies again to the remaining rows. + + Some precompilation of or-patterns and + variable pattern occurs. Mostly this means that bindings + are performed now, being replaced by let-bindings + in actions (cf. simplify_cases). + + Additionally, if the match argument is a variable, matchings whose + first column is made of variables only are splitted further + (cf. precompile_var). + +*) + + +let rec split_or argo cls args def = + + let cls = simplify_cases args cls in + + let rec do_split before ors no = function + | [] -> + cons_next + (List.rev before) (List.rev ors) (List.rev no) + | ((p::ps,act) as cl)::rem -> + if up_ok cl no then + if is_or p then + let ors, no = insert_or_append p ps act ors no in + do_split before ors no rem + else begin + if up_ok cl ors then + do_split (cl::before) ors no rem + else if or_ok p ps ors then + do_split before (cl::ors) no rem + else + do_split before ors (cl::no) rem + end + else + do_split before ors (cl::no) rem + | _ -> assert false + + and cons_next yes yesor = function + | [] -> + precompile_or argo yes yesor args def [] + | rem -> + let {me=next ; matrix=matrix ; top_default=def},nexts = + do_split [] [] [] rem in + let idef = next_raise_count () in + precompile_or + argo yes yesor args + (cons_default matrix idef def) + ((idef,next)::nexts) in + + do_split [] [] [] cls + +and split_constr cls args def k = + let ex_pat = what_is_cases cls in + match ex_pat.pat_desc with + | Tpat_any -> precompile_var args cls def k + | _ -> + + let group = get_group ex_pat in + + let rec split_ex yes no = function + | [] -> + let yes = List.rev yes and no = List.rev no in + begin match no with + | [] -> + {me = Pm {cases=yes ; args=args ; default=def} ; + matrix = as_matrix yes ; + top_default = def}, + k + | cl::rem -> + begin match yes with + | [] -> + (* Could not success in raising up a constr matching up *) + split_noex [cl] [] rem + | _ -> + let {me=next ; matrix=matrix ; top_default=def}, nexts = + split_noex [cl] [] rem in + let idef = next_raise_count () in + let def = cons_default matrix idef def in + {me = Pm {cases=yes ; args=args ; default=def} ; + matrix = as_matrix yes ; + top_default = def }, + (idef, next)::nexts + end + end + | (p::_,_) as cl::rem -> + if group p && up_ok cl no then + split_ex (cl::yes) no rem + else + split_ex yes (cl::no) rem + | _ -> assert false + + and split_noex yes no = function + | [] -> + let yes = List.rev yes and no = List.rev no in + begin match no with + | [] -> precompile_var args yes def k + | cl::rem -> + let {me=next ; matrix=matrix ; top_default=def}, nexts = + split_ex [cl] [] rem in + let idef = next_raise_count () in + precompile_var + args yes + (cons_default matrix idef def) + ((idef,next)::nexts) + end + | [ps,_ as cl] + when List.for_all group_var ps && yes <> [] -> + (* This enables an extra division in some frequent case : + last row is made of variables only *) + split_noex yes (cl::no) [] + | (p::_,_) as cl::rem -> + if not (group p) && up_ok cl no then + split_noex (cl::yes) no rem + else + split_noex yes (cl::no) rem + | _ -> assert false in + + match cls with + | ((p::_,_) as cl)::rem -> + if group p then split_ex [cl] [] rem + else split_noex [cl] [] rem + | _ -> assert false + +and precompile_var args cls def k = match args with +| [] -> assert false +| _::((Lvar v as av,_) as arg)::rargs -> + begin match cls with + | [ps,_] -> (* as splitted as it can *) + dont_precompile_var args cls def k + | _ -> +(* Precompile *) + let var_cls = + List.map + (fun (ps,act) -> match ps with + | _::ps -> ps,act | _ -> assert false) + cls + and var_def = make_default (fun _ rem -> rem) def in + let {me=first ; matrix=matrix}, nexts = + split_or (Some v) var_cls (arg::rargs) var_def in + +(* Compute top information *) + match nexts with + | [] -> (* If you need *) + dont_precompile_var args cls def k + | _ -> + let rfirst = + {me = PmVar {inside=first ; var_arg = av} ; + matrix = add_omega_column matrix ; + top_default = rebuild_default nexts def ; } + and rnexts = rebuild_nexts av nexts k in + rfirst, rnexts + end +| _ -> + dont_precompile_var args cls def k + +and dont_precompile_var args cls def k = + {me = Pm {cases = cls ; args = args ; default = def } ; + matrix=as_matrix cls ; + top_default=def},k + +and precompile_or argo cls ors args def k = match ors with +| [] -> split_constr cls args def k +| _ -> + let rec do_cases = function + | ({pat_desc=Tpat_or _} as orp::patl, action)::rem -> + let others,rem = get_equiv orp rem in + let orpm = + {cases = + (patl, action):: + List.map + (function + | (_::ps,action) -> ps,action + | _ -> assert false) + others ; + args = (match args with _::r -> r | _ -> assert false) ; + default = default_compat orp def} in + let vars = + IdentSet.elements + (IdentSet.inter + (extract_vars IdentSet.empty orp) + (pm_free_variables orpm)) in + let or_num = next_raise_count () in + let new_patl = Parmatch.omega_list patl in + + let mk_new_action vs = + Lstaticraise + (or_num, List.map (fun v -> Lvar v) vs) in + + let body,handlers = do_cases rem in + explode_or_pat + argo new_patl mk_new_action body vars [] orp, + (([[orp]], or_num, vars , orpm):: handlers) + | cl::rem -> + let new_ord,new_to_catch = do_cases rem in + cl::new_ord,new_to_catch + | [] -> [],[] in + + let end_body, handlers = do_cases ors in + let matrix = as_matrix (cls@ors) + and body = {cases=cls@end_body ; args=args ; default=def} in + {me = PmOr {body=body ; handlers=handlers ; or_matrix=matrix} ; + matrix=matrix ; + top_default=def}, + k + +let split_precompile argo pm = + let {me=next}, nexts = split_or argo pm.cases pm.args pm.default in +(* + if nexts <> [] || (match next with PmOr _ -> true | _ -> false) then begin + prerr_endline "** SPLIT **" ; + pretty_pm pm ; + pretty_precompiled_res next nexts + end ; +*) + next, nexts + + +(* General divide functions *) + +let add_line patl_action pm = pm.cases <- patl_action :: pm.cases; pm + +type cell = + {pm : pattern_matching ; + ctx : ctx list ; + pat : pattern} + +let add make_matching_fun division key patl_action args = + try + let cell = List.assoc key division in + cell.pm.cases <- patl_action :: cell.pm.cases; + division + with Not_found -> + let cell = make_matching_fun args in + cell.pm.cases <- [patl_action] ; + (key, cell) :: division + + +let divide make get_key get_args ctx pm = + + let rec divide_rec = function + | (p::patl,action) :: rem -> + let this_match = divide_rec rem in + add + (make p pm.default ctx) + this_match (get_key p) (get_args p patl,action) pm.args + | _ -> [] in + + divide_rec pm.cases + + +let divide_line make_ctx make get_args pat ctx pm = + let rec divide_rec = function + | (p::patl,action) :: rem -> + let this_match = divide_rec rem in + add_line (get_args p patl, action) this_match + | _ -> make pm.default pm.args in + + {pm = divide_rec pm.cases ; + ctx=make_ctx ctx ; + pat=pat} + + + +(* Then come various functions, + There is one set of functions per matching style + (constants, constructors etc.) + + - matcher function are arguments to make_default (for defaukt handlers) + They may raise NoMatch or OrPat and perform the full + matching (selection + arguments). + + + - get_args and get_key are for the compiled matrices, note that + selection and geting arguments are separed. + + - make_ _matching combines the previous functions for produicing + new ``pattern_matching'' records. +*) + + + +let rec matcher_const cst p rem = match p.pat_desc with +| Tpat_or (p1,p2,_) -> + begin try + matcher_const cst p1 rem with + | NoMatch -> matcher_const cst p2 rem + end +| Tpat_constant c1 when c1=cst -> rem +| Tpat_any -> rem +| _ -> raise NoMatch + +let get_key_constant caller = function + | {pat_desc= Tpat_constant cst} -> cst + | p -> + prerr_endline ("BAD: "^caller) ; + pretty_pat p ; + assert false + +let get_args_constant _ rem = rem + +let make_constant_matching p def ctx = function + [] -> fatal_error "Matching.make_constant_matching" + | (_ :: argl) -> + let def = + make_default + (matcher_const (get_key_constant "make" p)) def + and ctx = + filter_ctx p ctx in + {pm = {cases = []; args = argl ; default = def} ; + ctx = ctx ; + pat = normalize_pat p} + + + + +let divide_constant ctx m = + divide + make_constant_matching (get_key_constant "divide") + get_args_constant + ctx m + +(* Matching against a constructor *) + + +let make_field_args binding_kind arg first_pos last_pos argl = + let rec make_args pos = + if pos > last_pos + then argl + else (Lprim(Pfield pos, [arg]), binding_kind) :: make_args (pos + 1) + in make_args first_pos + +let get_key_constr = function + | {pat_desc=Tpat_construct (cstr,_)} -> cstr.cstr_tag + | _ -> assert false + +let get_args_constr p rem = match p with +| {pat_desc=Tpat_construct (_,args)} -> args @ rem +| _ -> assert false + +let pat_as_constr = function + | {pat_desc=Tpat_construct (cstr,_)} -> cstr + | _ -> fatal_error "Matching.pat_as_constr" + + +let matcher_constr cstr = match cstr.cstr_arity with +| 0 -> + let rec matcher_rec q rem = match q.pat_desc with + | Tpat_or (p1,p2,_) -> + begin + try + matcher_rec p1 rem + with + | NoMatch -> matcher_rec p2 rem + end + | Tpat_construct (cstr1, []) when cstr.cstr_tag = cstr1.cstr_tag -> + rem + | Tpat_any -> rem + | _ -> raise NoMatch in + matcher_rec +| 1 -> + let rec matcher_rec q rem = match q.pat_desc with + | Tpat_or (p1,p2,_) -> + let r1 = try Some (matcher_rec p1 rem) with NoMatch -> None + and r2 = try Some (matcher_rec p2 rem) with NoMatch -> None in + begin match r1,r2 with + | None, None -> raise NoMatch + | Some r1, None -> r1 + | None, Some r2 -> r2 + | Some (a1::rem1), Some (a2::_) -> + {a1 with +pat_loc = Location.none ; +pat_desc = Tpat_or (a1, a2, None)}:: + rem + | _, _ -> assert false + end + | Tpat_construct (cstr1, [arg]) when cstr.cstr_tag = cstr1.cstr_tag -> + arg::rem + | Tpat_any -> omega::rem + | _ -> raise NoMatch in + matcher_rec +| _ -> + fun q rem -> match q.pat_desc with + | Tpat_or (_,_,_) -> raise OrPat + | Tpat_construct (cstr1, args) + when cstr.cstr_tag = cstr1.cstr_tag -> args @ rem + | Tpat_any -> Parmatch.omegas cstr.cstr_arity @ rem + | _ -> raise NoMatch + +let make_constr_matching p def ctx = function + [] -> fatal_error "Matching.make_constr_matching" + | ((arg, mut) :: argl) -> + let cstr = pat_as_constr p in + let newargs = + match cstr.cstr_tag with + Cstr_constant _ | Cstr_block _ -> + make_field_args Alias arg 0 (cstr.cstr_arity - 1) argl + | Cstr_exception _ -> + make_field_args Alias arg 1 cstr.cstr_arity argl in + {pm= + {cases = []; args = newargs; + default = make_default (matcher_constr cstr) def} ; + ctx = filter_ctx p ctx ; + pat=normalize_pat p} + + +let divide_constructor ctx pm = + divide + make_constr_matching + get_key_constr get_args_constr + ctx pm + +(* Matching against a variant *) + +let rec matcher_variant_const lab p rem = match p.pat_desc with +| Tpat_or (p1, p2, _) -> + begin + try + matcher_variant_const lab p1 rem + with + | NoMatch -> matcher_variant_const lab p2 rem + end +| Tpat_variant (lab1,_,_) when lab1=lab -> rem +| Tpat_any -> rem +| _ -> raise NoMatch + + +let make_variant_matching_constant p lab def ctx = function + [] -> fatal_error "Matching.make_variant_matching_constant" + | ((arg, mut) :: argl) -> + let def = make_default (matcher_variant_const lab) def + and ctx = filter_ctx p ctx in + {pm={ cases = []; args = argl ; default=def} ; + ctx=ctx ; + pat = normalize_pat p} + +let matcher_variant_nonconst lab p rem = match p.pat_desc with +| Tpat_or (_,_,_) -> raise OrPat +| Tpat_variant (lab1,Some arg,_) when lab1=lab -> arg::rem +| Tpat_any -> omega::rem +| _ -> raise NoMatch + + +let make_variant_matching_nonconst p lab def ctx = function + [] -> fatal_error "Matching.make_variant_matching_nonconst" + | ((arg, mut) :: argl) -> + let def = make_default (matcher_variant_nonconst lab) def + and ctx = filter_ctx p ctx in + {pm= + {cases = []; args = (Lprim(Pfield 1, [arg]), Alias) :: argl; + default=def} ; + ctx=ctx ; + pat = normalize_pat p} + +let get_key_variant p = match p.pat_desc with +| Tpat_variant(lab, Some _ , _) -> Cstr_block (Btype.hash_variant lab) +| Tpat_variant(lab, None , _) -> Cstr_constant (Btype.hash_variant lab) +| _ -> assert false + +let divide_variant row ctx {cases = cl; args = al; default=def} = + let row = Btype.row_repr row in + let rec divide = function + ({pat_desc = Tpat_variant(lab, pato, _)} as p:: patl, action) :: rem -> + let variants = divide rem in + if try Btype.row_field_repr (List.assoc lab row.row_fields) = Rabsent + with Not_found -> true + then + variants + else begin + let tag = Btype.hash_variant lab in + match pato with + None -> + add (make_variant_matching_constant p lab def ctx) variants + (Cstr_constant tag) (patl, action) al + | Some pat -> + add (make_variant_matching_nonconst p lab def ctx) variants + (Cstr_block tag) (pat :: patl, action) al + end + | cl -> [] + in + divide cl + +(* + Three ``no-test'' cases + *) + +(* Matching against a variable *) + +let get_args_var _ rem = rem + + +let make_var_matching def = function + | [] -> fatal_error "Matching.make_var_matching" + | _::argl -> + {cases=[] ; + args = argl ; + default= make_default get_args_var def} + +let divide_var ctx pm = + divide_line ctx_lshift make_var_matching get_args_var omega ctx pm + +(* Matching and forcing a lazy value *) + +let get_arg_lazy p rem = match p with +| {pat_desc = Tpat_any} -> omega :: rem +| {pat_desc = Tpat_lazy arg} -> arg :: rem +| _ -> assert false + +let matcher_lazy p rem = match p.pat_desc with +| Tpat_or (_,_,_) -> raise OrPat +| Tpat_var _ -> get_arg_lazy omega rem +| _ -> get_arg_lazy p rem + +(* Inlining the tag tests before calling the primitive that works on + lazy blocks. This is alse used in translcore.ml. + No call other than Obj.tag when the value has been forced before. +*) + +let prim_obj_tag = + {prim_name = "caml_obj_tag"; + prim_arity = 1; prim_alloc = false; + prim_native_name = ""; + prim_native_float = false} + +let get_mod_field modname field = + lazy ( + try + let mod_ident = Ident.create_persistent modname in + let env = Env.open_pers_signature modname Env.initial in + let p = try + match Env.lookup_value (Longident.Lident field) env with + | (Path.Pdot(_,_,i), _) -> i + | _ -> fatal_error ("Primitive "^modname^"."^field^" not found.") + with Not_found -> fatal_error ("Primitive "^modname^"."^field^" not found.") + in + Lprim(Pfield p, [Lprim(Pgetglobal mod_ident, [])]) + with Not_found -> fatal_error ("Module "^modname^" unavailable.") + ) + +let code_force_lazy_block = + get_mod_field "CamlinternalLazy" "force_lazy_block" +;; + +(* inline_lazy_force inlines the beginning of the code of Lazy.force. When + the value argument is tagged as: + - forward, take field 0 + - lazy, call the primitive that forces (without testing again the tag) + - anything else, return it + + Using Lswitch below relies on the fact that the GC does not shortcut + Forward(val_out_of_heap). +*) + +let inline_lazy_force_cond arg loc = + let idarg = Ident.create "lzarg" in + let varg = Lvar idarg in + let tag = Ident.create "tag" in + let force_fun = Lazy.force code_force_lazy_block in + Llet(Strict, idarg, arg, + Llet(Alias, tag, Lprim(Pccall prim_obj_tag, [varg]), + Lifthenelse( + (* if (tag == Obj.forward_tag) then varg.(0) else ... *) + Lprim(Pintcomp Ceq, + [Lvar tag; Lconst(Const_base(Const_int Obj.forward_tag))]), + Lprim(Pfield 0, [varg]), + Lifthenelse( + (* ... if (tag == Obj.lazy_tag) then Lazy.force varg else ... *) + Lprim(Pintcomp Ceq, + [Lvar tag; Lconst(Const_base(Const_int Obj.lazy_tag))]), + Lapply(force_fun, [varg], loc), + (* ... arg *) + varg)))) + +let inline_lazy_force_switch arg loc = + let idarg = Ident.create "lzarg" in + let varg = Lvar idarg in + let force_fun = Lazy.force code_force_lazy_block in + Llet(Strict, idarg, arg, + Lifthenelse( + Lprim(Pisint, [varg]), varg, + (Lswitch + (varg, + { sw_numconsts = 0; sw_consts = []; + sw_numblocks = (max Obj.lazy_tag Obj.forward_tag) + 1; + sw_blocks = + [ (Obj.forward_tag, Lprim(Pfield 0, [varg])); + (Obj.lazy_tag, + Lapply(force_fun, [varg], loc)) ]; + sw_failaction = Some varg } )))) + +let inline_lazy_force = + if !Clflags.native_code then + (* Lswitch generates compact and efficient native code *) + inline_lazy_force_switch + else + (* generating bytecode: Lswitch would generate too many rather big + tables (~ 250 elts); conditionals are better *) + inline_lazy_force_cond + +let make_lazy_matching def = function + [] -> fatal_error "Matching.make_lazy_matching" + | (arg,mut) :: argl -> + { cases = []; + args = + (inline_lazy_force arg Location.none, Strict) :: argl; + default = make_default matcher_lazy def } + +let divide_lazy p ctx pm = + divide_line + (filter_ctx p) + make_lazy_matching + get_arg_lazy + p ctx pm + +(* Matching against a tuple pattern *) + + +let get_args_tuple arity p rem = match p with +| {pat_desc = Tpat_any} -> omegas arity @ rem +| {pat_desc = Tpat_tuple args} -> + args @ rem +| _ -> assert false + +let matcher_tuple arity p rem = match p.pat_desc with +| Tpat_or (_,_,_) -> raise OrPat +| Tpat_var _ -> get_args_tuple arity omega rem +| _ -> get_args_tuple arity p rem + +let make_tuple_matching arity def = function + [] -> fatal_error "Matching.make_tuple_matching" + | (arg, mut) :: argl -> + let rec make_args pos = + if pos >= arity + then argl + else (Lprim(Pfield pos, [arg]), Alias) :: make_args (pos + 1) in + {cases = []; args = make_args 0 ; + default=make_default (matcher_tuple arity) def} + + +let divide_tuple arity p ctx pm = + divide_line + (filter_ctx p) + (make_tuple_matching arity) + (get_args_tuple arity) p ctx pm + +(* Matching against a record pattern *) + + +let record_matching_line num_fields lbl_pat_list = + let patv = Array.create num_fields omega in + List.iter (fun (lbl, pat) -> patv.(lbl.lbl_pos) <- pat) lbl_pat_list; + Array.to_list patv + +let get_args_record num_fields p rem = match p with +| {pat_desc=Tpat_any} -> + record_matching_line num_fields [] @ rem +| {pat_desc=Tpat_record lbl_pat_list} -> + record_matching_line num_fields lbl_pat_list @ rem +| _ -> assert false + +let matcher_record num_fields p rem = match p.pat_desc with +| Tpat_or (_,_,_) -> raise OrPat +| Tpat_var _ -> get_args_record num_fields omega rem +| _ -> get_args_record num_fields p rem + +let make_record_matching all_labels def = function + [] -> fatal_error "Matching.make_record_matching" + | ((arg, mut) :: argl) -> + let rec make_args pos = + if pos >= Array.length all_labels then argl else begin + let lbl = all_labels.(pos) in + let access = + match lbl.lbl_repres with + Record_regular -> Pfield lbl.lbl_pos + | Record_float -> Pfloatfield lbl.lbl_pos in + let str = + match lbl.lbl_mut with + Immutable -> Alias + | Mutable -> StrictOpt in + (Lprim(access, [arg]), str) :: make_args(pos + 1) + end in + let nfields = Array.length all_labels in + let def= make_default (matcher_record nfields) def in + {cases = []; args = make_args 0 ; default = def} + + +let divide_record all_labels p ctx pm = + let get_args = get_args_record (Array.length all_labels) in + divide_line + (filter_ctx p) + (make_record_matching all_labels) + get_args + p ctx pm + +(* Matching against an array pattern *) + +let get_key_array = function + | {pat_desc=Tpat_array patl} -> List.length patl + | _ -> assert false + +let get_args_array p rem = match p with +| {pat_desc=Tpat_array patl} -> patl@rem +| _ -> assert false + +let matcher_array len p rem = match p.pat_desc with +| Tpat_or (_,_,_) -> raise OrPat +| Tpat_array args when List.length args=len -> args @ rem +| Tpat_any -> Parmatch.omegas len @ rem +| _ -> raise NoMatch + +let make_array_matching kind p def ctx = function + | [] -> fatal_error "Matching.make_array_matching" + | ((arg, mut) :: argl) -> + let len = get_key_array p in + let rec make_args pos = + if pos >= len + then argl + else (Lprim(Parrayrefu kind, [arg; Lconst(Const_base(Const_int pos))]), + StrictOpt) :: make_args (pos + 1) in + let def = make_default (matcher_array len) def + and ctx = filter_ctx p ctx in + {pm={cases = []; args = make_args 0 ; default = def} ; + ctx=ctx ; + pat = normalize_pat p} + +let divide_array kind ctx pm = + divide + (make_array_matching kind) + get_key_array get_args_array ctx pm + +(* To combine sub-matchings together *) + +let float_compare s1 s2 = + let f1 = float_of_string s1 and f2 = float_of_string s2 in + Pervasives.compare f1 f2 + +let sort_lambda_list l = + List.sort + (fun (x,_) (y,_) -> match x,y with + | Const_float f1, Const_float f2 -> float_compare f1 f2 + | _, _ -> Pervasives.compare x y) + l + +let rec cut n l = + if n = 0 then [],l + else match l with + [] -> raise (Invalid_argument "cut") + | a::l -> let l1,l2 = cut (n-1) l in a::l1, l2 + +let rec do_tests_fail fail tst arg = function + | [] -> fail + | (c, act)::rem -> + Lifthenelse + (Lprim (tst, [arg ; Lconst (Const_base c)]), + do_tests_fail fail tst arg rem, + act) + +let rec do_tests_nofail tst arg = function + | [] -> fatal_error "Matching.do_tests_nofail" + | [_,act] -> act + | (c,act)::rem -> + Lifthenelse + (Lprim (tst, [arg ; Lconst (Const_base c)]), + do_tests_nofail tst arg rem, + act) + +let make_test_sequence fail tst lt_tst arg const_lambda_list = + let rec make_test_sequence const_lambda_list = + if List.length const_lambda_list >= 4 && lt_tst <> Praise then + split_sequence const_lambda_list + else match fail with + | None -> do_tests_nofail tst arg const_lambda_list + | Some fail -> do_tests_fail fail tst arg const_lambda_list + + and split_sequence const_lambda_list = + let list1, list2 = + cut (List.length const_lambda_list / 2) const_lambda_list in + Lifthenelse(Lprim(lt_tst,[arg; Lconst(Const_base (fst(List.hd list2)))]), + make_test_sequence list1, make_test_sequence list2) + in make_test_sequence (sort_lambda_list const_lambda_list) + + +let make_offset x arg = if x=0 then arg else Lprim(Poffsetint(x), [arg]) + + + +let prim_string_notequal = + Pccall{prim_name = "caml_string_notequal"; + prim_arity = 2; prim_alloc = false; + prim_native_name = ""; prim_native_float = false} + +let rec explode_inter offset i j act k = + if i <= j then + explode_inter offset i (j-1) act ((j-offset,act)::k) + else + k + +let max_vals cases acts = + let vals = Array.create (Array.length acts) 0 in + for i=Array.length cases-1 downto 0 do + let l,h,act = cases.(i) in + vals.(act) <- h - l + 1 + vals.(act) + done ; + let max = ref 0 in + for i = Array.length vals-1 downto 0 do + if vals.(i) >= vals.(!max) then + max := i + done ; + if vals.(!max) > 1 then + !max + else + -1 + +let as_int_list cases acts = + let default = max_vals cases acts in + let min_key,_,_ = cases.(0) + and _,max_key,_ = cases.(Array.length cases-1) in + + let rec do_rec i k = + if i >= 0 then + let low, high, act = cases.(i) in + if act = default then + do_rec (i-1) k + else + do_rec (i-1) (explode_inter min_key low high acts.(act) k) + else + k in + min_key, max_key,do_rec (Array.length cases-1) [], + (if default >= 0 then Some acts.(default) else None) + + +let make_switch_offset arg min_key max_key int_lambda_list default = + let numcases = max_key - min_key + 1 in + let cases = + List.map (fun (key, l) -> (key - min_key, l)) int_lambda_list in + let offsetarg = make_offset (-min_key) arg in + Lswitch(offsetarg, + {sw_numconsts = numcases; sw_consts = cases; + sw_numblocks = 0; sw_blocks = []; + sw_failaction = default}) + +let make_switch_switcher arg cases acts = + let l = ref [] in + for i = Array.length cases-1 downto 0 do + l := (i,acts.(cases.(i))) :: !l + done ; + Lswitch(arg, + {sw_numconsts = Array.length cases ; sw_consts = !l ; + sw_numblocks = 0 ; sw_blocks = [] ; + sw_failaction = None}) + +let full sw = + List.length sw.sw_consts = sw.sw_numconsts && + List.length sw.sw_blocks = sw.sw_numblocks + +let make_switch (arg,sw) = match sw.sw_failaction with +| None -> + let t = Hashtbl.create 17 in + let seen l = match l with + | Lstaticraise (i,[]) -> + let old = try Hashtbl.find t i with Not_found -> 0 in + Hashtbl.replace t i (old+1) + | _ -> () in + List.iter (fun (_,lam) -> seen lam) sw.sw_consts ; + List.iter (fun (_,lam) -> seen lam) sw.sw_blocks ; + let i_max = ref (-1) + and max = ref (-1) in + Hashtbl.iter + (fun i c -> + if c > !max then begin + i_max := i ; + max := c + end) t ; + if !i_max >= 0 then + let default = !i_max in + let rec remove = function + | [] -> [] + | (_,Lstaticraise (j,[]))::rem when j=default -> + remove rem + | x::rem -> x::remove rem in + Lswitch + (arg, + {sw with +sw_consts = remove sw.sw_consts ; +sw_blocks = remove sw.sw_blocks ; +sw_failaction = Some (Lstaticraise (default,[]))}) + else + Lswitch (arg,sw) +| _ -> Lswitch (arg,sw) + +module SArg = struct + type primitive = Lambda.primitive + + let eqint = Pintcomp Ceq + let neint = Pintcomp Cneq + let leint = Pintcomp Cle + let ltint = Pintcomp Clt + let geint = Pintcomp Cge + let gtint = Pintcomp Cgt + + type act = Lambda.lambda + + let make_prim p args = Lprim (p,args) + let make_offset arg n = match n with + | 0 -> arg + | _ -> Lprim (Poffsetint n,[arg]) + let bind arg body = + let newvar,newarg = match arg with + | Lvar v -> v,arg + | _ -> + let newvar = Ident.create "switcher" in + newvar,Lvar newvar in + bind Alias newvar arg (body newarg) + + let make_isout h arg = Lprim (Pisout, [h ; arg]) + let make_isin h arg = Lprim (Pnot,[make_isout h arg]) + let make_if cond ifso ifnot = Lifthenelse (cond, ifso, ifnot) + let make_switch = make_switch_switcher +end + +module Switcher = Switch.Make(SArg) +open Switch + +let lambda_of_int i = Lconst (Const_base (Const_int i)) + +let rec last def = function + | [] -> def + | [x,_] -> x + | _::rem -> last def rem + +let get_edges low high l = match l with +| [] -> low, high +| (x,_)::_ -> x, last high l + + +let as_interval_canfail fail low high l = + let store = mk_store equal_action in + let rec nofail_rec cur_low cur_high cur_act = function + | [] -> + if cur_high = high then + [cur_low,cur_high,cur_act] + else + [(cur_low,cur_high,cur_act) ; (cur_high+1,high, 0)] + | ((i,act_i)::rem) as all -> + let act_index = store.act_store act_i in + if cur_high+1= i then + if act_index=cur_act then + nofail_rec cur_low i cur_act rem + else if act_index=0 then + (cur_low,i-1, cur_act)::fail_rec i i rem + else + (cur_low, i-1, cur_act)::nofail_rec i i act_index rem + else + (cur_low, cur_high, cur_act):: + fail_rec ((cur_high+1)) (cur_high+1) all + + and fail_rec cur_low cur_high = function + | [] -> [(cur_low, cur_high, 0)] + | (i,act_i)::rem -> + let index = store.act_store act_i in + if index=0 then fail_rec cur_low i rem + else + (cur_low,i-1,0):: + nofail_rec i i index rem in + + let rec init_rec = function + | [] -> [] + | (i,act_i)::rem -> + let index = store.act_store act_i in + if index=0 then + fail_rec low i rem + else + if low < i then + (low,i-1,0)::nofail_rec i i index rem + else + nofail_rec i i index rem in + + ignore (store.act_store fail) ; (* fail has action index 0 *) + let r = init_rec l in + Array.of_list r, store.act_get () + +let as_interval_nofail l = + let store = mk_store equal_action in + + let rec i_rec cur_low cur_high cur_act = function + | [] -> + [cur_low, cur_high, cur_act] + | (i,act)::rem -> + let act_index = store.act_store act in + if act_index = cur_act then + i_rec cur_low i cur_act rem + else + (cur_low, cur_high, cur_act):: + i_rec i i act_index rem in + let inters = match l with + | (i,act)::rem -> + let act_index = store.act_store act in + i_rec i i act_index rem + | _ -> assert false in + + Array.of_list inters, store.act_get () + + +let sort_int_lambda_list l = + List.sort + (fun (i1,_) (i2,_) -> + if i1 < i2 then -1 + else if i2 < i1 then 1 + else 0) + l + +let as_interval fail low high l = + let l = sort_int_lambda_list l in + get_edges low high l, + (match fail with + | None -> as_interval_nofail l + | Some act -> as_interval_canfail act low high l) + +let call_switcher konst fail arg low high int_lambda_list = + let edges, (cases, actions) = + as_interval fail low high int_lambda_list in + Switcher.zyva edges konst arg cases actions + + +let exists_ctx ok ctx = + List.exists + (function + | {right=p::_} -> ok p + | _ -> assert false) + ctx + +let rec list_as_pat = function + | [] -> fatal_error "Matching.list_as_pat" + | [pat] -> pat + | pat::rem -> + {pat with pat_desc = Tpat_or (pat,list_as_pat rem,None)} + + +let rec pat_as_list k = function + | {pat_desc=Tpat_or (p1,p2,_)} -> + pat_as_list (pat_as_list k p2) p1 + | p -> p::k + +(* Extracting interesting patterns *) +exception All + +let rec extract_pat seen k p = match p.pat_desc with +| Tpat_or (p1,p2,_) -> + let k1,seen1 = extract_pat seen k p1 in + extract_pat seen1 k1 p2 +| Tpat_alias (p,_) -> + extract_pat seen k p +| Tpat_var _|Tpat_any -> + raise All +| _ -> + let q = normalize_pat p in + if List.exists (compat q) seen then + k, seen + else + q::k, q::seen + +let extract_mat seen pss = + let r,_ = + List.fold_left + (fun (k,seen) ps -> match ps with + | p::_ -> extract_pat seen k p + | _ -> assert false) + ([],seen) + pss in + r + + + +let complete_pats_constrs = function + | p::_ as pats -> + List.map + (pat_of_constr p) + (complete_constrs p (List.map get_key_constr pats)) + | _ -> assert false + + +let mk_res get_key env last_choice idef cant_fail ctx = + + let env,fail,jumps_fail = match last_choice with + | [] -> + env, None, jumps_empty + | [p] when group_var p -> + env, + Some (Lstaticraise (idef,[])), + jumps_singleton idef ctx + | _ -> + (idef,cant_fail,last_choice)::env, + None, jumps_empty in + let klist,jumps = + List.fold_right + (fun (i,cant_fail,pats) (klist,jumps) -> + let act = Lstaticraise (i,[]) + and pat = list_as_pat pats in + let klist = + List.fold_right + (fun pat klist -> (get_key pat,act)::klist) + pats klist + and ctx = if cant_fail then ctx else ctx_lub pat ctx in + klist,jumps_add i ctx jumps) + env ([],jumps_fail) in + fail, klist, jumps + + +(* + Following two ``failaction'' function compute n, the trap handler + to jump to in case of failure of elementary tests +*) + +let mk_failaction_neg partial ctx def = match partial with +| Partial -> + begin match def with + | (_,idef)::_ -> + Some (Lstaticraise (idef,[])),[],jumps_singleton idef ctx + | _ -> + (* Act as Total, this means + If no appropriate default matrix exists, + then this switch cannot fail *) + None, [], jumps_empty + end +| Total -> + None, [], jumps_empty + + + +(* Conforme a l'article et plus simple qu'avant *) +and mk_failaction_pos partial seen ctx defs = + let rec scan_def env to_test defs = match to_test,defs with + | ([],_)|(_,[]) -> + List.fold_left + (fun (klist,jumps) (pats,i)-> + let action = Lstaticraise (i,[]) in + let klist = + List.fold_right + (fun pat r -> (get_key_constr pat,action)::r) + pats klist + and jumps = + jumps_add i (ctx_lub (list_as_pat pats) ctx) jumps in + klist,jumps) + ([],jumps_empty) env + | _,(pss,idef)::rem -> + let now, later = + List.partition + (fun (p,p_ctx) -> ctx_match p_ctx pss) to_test in + match now with + | [] -> scan_def env to_test rem + | _ -> scan_def ((List.map fst now,idef)::env) later rem in + + scan_def + [] + (List.map + (fun pat -> pat, ctx_lub pat ctx) + (complete_pats_constrs seen)) + defs + + +let combine_constant arg cst partial ctx def + (const_lambda_list, total, pats) = + let fail, to_add, local_jumps = + mk_failaction_neg partial ctx def in + let const_lambda_list = to_add@const_lambda_list in + let lambda1 = + match cst with + | Const_int _ -> + let int_lambda_list = + List.map (function Const_int n, l -> n,l | _ -> assert false) + const_lambda_list in + call_switcher + lambda_of_int fail arg min_int max_int int_lambda_list + | Const_char _ -> + let int_lambda_list = + List.map (function Const_char c, l -> (Char.code c, l) + | _ -> assert false) + const_lambda_list in + call_switcher + (fun i -> Lconst (Const_base (Const_int i))) + fail arg 0 255 int_lambda_list + | Const_string _ -> + make_test_sequence + fail prim_string_notequal Praise arg const_lambda_list + | Const_float _ -> + make_test_sequence + fail + (Pfloatcomp Cneq) (Pfloatcomp Clt) + arg const_lambda_list + | Const_int32 _ -> + make_test_sequence + fail + (Pbintcomp(Pint32, Cneq)) (Pbintcomp(Pint32, Clt)) + arg const_lambda_list + | Const_int64 _ -> + make_test_sequence + fail + (Pbintcomp(Pint64, Cneq)) (Pbintcomp(Pint64, Clt)) + arg const_lambda_list + | Const_nativeint _ -> + make_test_sequence + fail + (Pbintcomp(Pnativeint, Cneq)) (Pbintcomp(Pnativeint, Clt)) + arg const_lambda_list + in lambda1,jumps_union local_jumps total + + + +let split_cases tag_lambda_list = + let rec split_rec = function + [] -> ([], []) + | (cstr, act) :: rem -> + let (consts, nonconsts) = split_rec rem in + match cstr with + Cstr_constant n -> ((n, act) :: consts, nonconsts) + | Cstr_block n -> (consts, (n, act) :: nonconsts) + | _ -> assert false in + let const, nonconst = split_rec tag_lambda_list in + sort_int_lambda_list const, + sort_int_lambda_list nonconst + + +let combine_constructor arg ex_pat cstr partial ctx def + (tag_lambda_list, total1, pats) = + if cstr.cstr_consts < 0 then begin + (* Special cases for exceptions *) + let fail, to_add, local_jumps = + mk_failaction_neg partial ctx def in + let tag_lambda_list = to_add@tag_lambda_list in + let lambda1 = + let default, tests = + match fail with + | None -> + begin match tag_lambda_list with + | (_, act)::rem -> act,rem + | _ -> assert false + end + | Some fail -> fail, tag_lambda_list in + List.fold_right + (fun (ex, act) rem -> + match ex with + | Cstr_exception path -> + Lifthenelse(Lprim(Pintcomp Ceq, + [Lprim(Pfield 0, [arg]); transl_path path]), + act, rem) + | _ -> assert false) + tests default in + lambda1, jumps_union local_jumps total1 + end else begin + (* Regular concrete type *) + let ncases = List.length tag_lambda_list + and nconstrs = cstr.cstr_consts + cstr.cstr_nonconsts in + let sig_complete = ncases = nconstrs in + let fails,local_jumps = + if sig_complete then [],jumps_empty + else + mk_failaction_pos partial pats ctx def in + + let tag_lambda_list = fails @ tag_lambda_list in + let (consts, nonconsts) = split_cases tag_lambda_list in + let lambda1 = + match same_actions tag_lambda_list with + | Some act -> act + | _ -> + match + (cstr.cstr_consts, cstr.cstr_nonconsts, consts, nonconsts) + with + | (1, 1, [0, act1], [0, act2]) -> + Lifthenelse(arg, act2, act1) + | (n,_,_,[]) -> + call_switcher + (fun i -> Lconst (Const_base (Const_int i))) + None arg 0 (n-1) consts + | (n, _, _, _) -> + match same_actions nonconsts with + | None -> + make_switch(arg, {sw_numconsts = cstr.cstr_consts; + sw_consts = consts; + sw_numblocks = cstr.cstr_nonconsts; + sw_blocks = nonconsts; + sw_failaction = None}) + | Some act -> + Lifthenelse + (Lprim (Pisint, [arg]), + call_switcher + (fun i -> Lconst (Const_base (Const_int i))) + None arg + 0 (n-1) consts, + act) in + lambda1, jumps_union local_jumps total1 + end + +let make_test_sequence_variant_constant fail arg int_lambda_list = + let _, (cases, actions) = + as_interval fail min_int max_int int_lambda_list in + Switcher.test_sequence + (fun i -> Lconst (Const_base (Const_int i))) arg cases actions + +let call_switcher_variant_constant fail arg int_lambda_list = + call_switcher + (fun i -> Lconst (Const_base (Const_int i))) + fail arg min_int max_int int_lambda_list + + +let call_switcher_variant_constr fail arg int_lambda_list = + let v = Ident.create "variant" in + Llet(Alias, v, Lprim(Pfield 0, [arg]), + call_switcher + (fun i -> Lconst (Const_base (Const_int i))) + fail (Lvar v) min_int max_int int_lambda_list) + +let combine_variant row arg partial ctx def (tag_lambda_list, total1, pats) = + let row = Btype.row_repr row in + let num_constr = ref 0 in + if row.row_closed then + List.iter + (fun (_, f) -> + match Btype.row_field_repr f with + Rabsent | Reither(true, _::_, _, _) -> () + | _ -> incr num_constr) + row.row_fields + else + num_constr := max_int; + let test_int_or_block arg if_int if_block = + Lifthenelse(Lprim (Pisint, [arg]), if_int, if_block) in + let sig_complete = List.length tag_lambda_list = !num_constr + and one_action = same_actions tag_lambda_list in + let fail, to_add, local_jumps = + if + sig_complete || (match partial with Total -> true | _ -> false) + then + None, [], jumps_empty + else + mk_failaction_neg partial ctx def in + let tag_lambda_list = to_add@tag_lambda_list in + let (consts, nonconsts) = split_cases tag_lambda_list in + let lambda1 = match fail, one_action with + | None, Some act -> act + | _,_ -> + match (consts, nonconsts) with + | ([n, act1], [m, act2]) when fail=None -> + test_int_or_block arg act1 act2 + | (_, []) -> (* One can compare integers and pointers *) + make_test_sequence_variant_constant fail arg consts + | ([], _) -> + let lam = call_switcher_variant_constr + fail arg nonconsts in + (* One must not dereference integers *) + begin match fail with + | None -> lam + | Some fail -> test_int_or_block arg fail lam + end + | (_, _) -> + let lam_const = + call_switcher_variant_constant + fail arg consts + and lam_nonconst = + call_switcher_variant_constr + fail arg nonconsts in + test_int_or_block arg lam_const lam_nonconst + in + lambda1, jumps_union local_jumps total1 + + +let combine_array arg kind partial ctx def + (len_lambda_list, total1, pats) = + let fail, to_add, local_jumps = mk_failaction_neg partial ctx def in + let len_lambda_list = to_add @ len_lambda_list in + let lambda1 = + let newvar = Ident.create "len" in + let switch = + call_switcher + lambda_of_int + fail (Lvar newvar) + 0 max_int len_lambda_list in + bind + Alias newvar (Lprim(Parraylength kind, [arg])) switch in + lambda1, jumps_union local_jumps total1 + +(* Insertion of debugging events *) + +let rec event_branch repr lam = + begin match lam, repr with + (_, None) -> + lam + | (Levent(lam', ev), Some r) -> + incr r; + Levent(lam', {lev_loc = ev.lev_loc; + lev_kind = ev.lev_kind; + lev_repr = repr; + lev_env = ev.lev_env}) + | (Llet(str, id, lam, body), _) -> + Llet(str, id, lam, event_branch repr body) + | Lstaticraise _,_ -> lam + | (_, Some r) -> + Printlambda.lambda Format.str_formatter lam ; + fatal_error + ("Matching.event_branch: "^Format.flush_str_formatter ()) + end + + +(* + This exception is raised when the compiler cannot produce code + because control cannot reach the compiled clause, + + Unused is raised initialy in compile_test. + + compile_list (for compiling switch results) catch Unused + + comp_match_handlers (for compililing splitted matches) + may reraise Unused + + +*) + +exception Unused + +let compile_list compile_fun division = + + let rec c_rec totals = function + | [] -> [], jumps_unions totals, [] + | (key, cell) :: rem -> + begin match cell.ctx with + | [] -> c_rec totals rem + | _ -> + try + let (lambda1, total1) = compile_fun cell.ctx cell.pm in + let c_rem, total, new_pats = + c_rec + (jumps_map ctx_combine total1::totals) rem in + ((key,lambda1)::c_rem), total, (cell.pat::new_pats) + with + | Unused -> c_rec totals rem + end in + c_rec [] division + + +let compile_orhandlers compile_fun lambda1 total1 ctx to_catch = + let rec do_rec r total_r = function + | [] -> r,total_r + | (mat,i,vars,pm)::rem -> + begin try + let ctx = select_columns mat ctx in + let handler_i, total_i = compile_fun ctx pm in + match raw_action r with + | Lstaticraise (j,args) -> + if i=j then + List.fold_right2 (bind Alias) vars args handler_i, + jumps_map (ctx_rshift_num (ncols mat)) total_i + else + do_rec r total_r rem + | _ -> + do_rec + (Lstaticcatch (r,(i,vars), handler_i)) + (jumps_union + (jumps_remove i total_r) + (jumps_map (ctx_rshift_num (ncols mat)) total_i)) + rem + with + | Unused -> + do_rec (Lstaticcatch (r, (i,vars), lambda_unit)) total_r rem + end in + do_rec lambda1 total1 to_catch + + +let compile_test compile_fun partial divide combine ctx to_match = + let division = divide ctx to_match in + let c_div = compile_list compile_fun division in + match c_div with + | [],_,_ -> + begin match mk_failaction_neg partial ctx to_match.default with + | None,_,_ -> raise Unused + | Some l,_,total -> l,total + end + | _ -> + combine ctx to_match.default c_div + +(* Attempt to avoid some useless bindings by lowering them *) + +(* Approximation of v present in lam *) +let rec approx_present v = function + | Lconst _ -> false + | Lstaticraise (_,args) -> + List.exists (fun lam -> approx_present v lam) args + | Lprim (_,args) -> + List.exists (fun lam -> approx_present v lam) args + | Llet (Alias, _, l1, l2) -> + approx_present v l1 || approx_present v l2 + | Lvar vv -> Ident.same v vv + | _ -> true + +let string_of_lam lam = + Printlambda.lambda Format.str_formatter lam ; + Format.flush_str_formatter () + +let rec lower_bind v arg lam = match lam with +| Lifthenelse (cond, ifso, ifnot) -> + let pcond = approx_present v cond + and pso = approx_present v ifso + and pnot = approx_present v ifnot in + begin match pcond, pso, pnot with + | false, false, false -> lam + | false, true, false -> + Lifthenelse (cond, lower_bind v arg ifso, ifnot) + | false, false, true -> + Lifthenelse (cond, ifso, lower_bind v arg ifnot) + | _,_,_ -> bind Alias v arg lam + end +| Lswitch (ls,({sw_consts=[i,act] ; sw_blocks = []} as sw)) + when not (approx_present v ls) -> + Lswitch (ls, {sw with sw_consts = [i,lower_bind v arg act]}) +| Lswitch (ls,({sw_consts=[] ; sw_blocks = [i,act]} as sw)) + when not (approx_present v ls) -> + Lswitch (ls, {sw with sw_blocks = [i,lower_bind v arg act]}) +| Llet (Alias, vv, lv, l) -> + if approx_present v lv then + bind Alias v arg lam + else + Llet (Alias, vv, lv, lower_bind v arg l) +| _ -> + bind Alias v arg lam + +let bind_check str v arg lam = match str,arg with +| _, Lvar _ ->bind str v arg lam +| Alias,_ -> lower_bind v arg lam +| _,_ -> bind str v arg lam + +let rec comp_exit ctx m = match m.default with +| (_,i)::_ -> Lstaticraise (i,[]), jumps_singleton i ctx +| _ -> fatal_error "Matching.comp_exit" + + + +let rec comp_match_handlers comp_fun partial ctx arg first_match next_matchs = match next_matchs with + | [] -> comp_fun partial ctx arg first_match + | rem -> + let rec c_rec body total_body = function + | [] -> body, total_body + (* Hum, -1 meant never taken + | (-1,pm)::rem -> c_rec body total_body rem *) + | (i,pm)::rem -> + let ctx_i,total_rem = jumps_extract i total_body in + begin match ctx_i with + | [] -> c_rec body total_body rem + | _ -> + try + let li,total_i = + comp_fun + (match rem with [] -> partial | _ -> Partial) + ctx_i arg pm in + c_rec + (Lstaticcatch (body,(i,[]),li)) + (jumps_union total_i total_rem) + rem + with + | Unused -> + c_rec (Lstaticcatch (body,(i,[]),lambda_unit)) + total_rem rem + end in + try + let first_lam,total = comp_fun Partial ctx arg first_match in + c_rec first_lam total rem + with Unused -> match next_matchs with + | [] -> raise Unused + | (_,x)::xs -> comp_match_handlers comp_fun partial ctx arg x xs + +(* To find reasonable names for variables *) + +let rec name_pattern default = function + (pat :: patl, action) :: rem -> + begin match pat.pat_desc with + Tpat_var id -> id + | Tpat_alias(p, id) -> id + | _ -> name_pattern default rem + end + | _ -> Ident.create default + +let arg_to_var arg cls = match arg with +| Lvar v -> v,arg +| _ -> + let v = name_pattern "match" cls in + v,Lvar v + + +(* + The main compilation function. + Input: + repr=used for inserting debug events + partial=exhaustiveness information from Parmatch + ctx=a context + m=a pattern matching + + Output: a lambda term, a jump summary {..., exit number -> context, .. } +*) + + +let rec compile_match repr partial ctx m = match m with +| { cases = [] } -> comp_exit ctx m +| { cases = ([], action) :: rem } -> + if is_guarded action then begin + let (lambda, total) = + compile_match None partial ctx { m with cases = rem } in + event_branch repr (patch_guarded lambda action), total + end else + (event_branch repr action, jumps_empty) +| { args = (arg, str)::argl } -> + let v,newarg = arg_to_var arg m.cases in + let first_match,rem = + split_precompile (Some v) + { m with args = (newarg, Alias) :: argl } in + let (lam, total) = + comp_match_handlers + (do_compile_matching repr) partial ctx newarg first_match rem in + bind_check str v arg lam, total +| _ -> assert false + + +(* verbose version of do_compile_matching, for debug *) +(* +and do_compile_matching_pr repr partial ctx arg x = + prerr_string "COMPILE: " ; + prerr_endline (match partial with Partial -> "Partial" | Total -> "Total") ; + prerr_endline "MATCH" ; + pretty_precompiled x ; + prerr_endline "CTX" ; + pretty_ctx ctx ; + let (_, jumps) as r = do_compile_matching repr partial ctx arg x in + prerr_endline "JUMPS" ; + pretty_jumps jumps ; + r +*) +and do_compile_matching repr partial ctx arg pmh = match pmh with +| Pm pm -> + let pat = what_is_cases pm.cases in + begin match pat.pat_desc with + | Tpat_any -> + compile_no_test + divide_var ctx_rshift repr partial ctx pm + | Tpat_tuple patl -> + compile_no_test + (divide_tuple (List.length patl) (normalize_pat pat)) ctx_combine + repr partial ctx pm + | Tpat_record ((lbl,_)::_) -> + compile_no_test + (divide_record lbl.lbl_all (normalize_pat pat)) + ctx_combine repr partial ctx pm + | Tpat_constant cst -> + compile_test + (compile_match repr partial) partial + divide_constant + (combine_constant arg cst partial) + ctx pm + | Tpat_construct (cstr, _) -> + compile_test + (compile_match repr partial) partial + divide_constructor (combine_constructor arg pat cstr partial) + ctx pm + | Tpat_array _ -> + let kind = Typeopt.array_pattern_kind pat in + compile_test (compile_match repr partial) partial + (divide_array kind) (combine_array arg kind partial) + ctx pm + | Tpat_lazy _ -> + compile_no_test + (divide_lazy (normalize_pat pat)) + ctx_combine repr partial ctx pm + | Tpat_variant(lab, _, row) -> + compile_test (compile_match repr partial) partial + (divide_variant !row) + (combine_variant !row arg partial) + ctx pm + | _ -> assert false + end +| PmVar {inside=pmh ; var_arg=arg} -> + let lam, total = + do_compile_matching repr partial (ctx_lshift ctx) arg pmh in + lam, jumps_map ctx_rshift total +| PmOr {body=body ; handlers=handlers} -> + let lam, total = compile_match repr partial ctx body in + compile_orhandlers (compile_match repr partial) lam total ctx handlers + +and compile_no_test divide up_ctx repr partial ctx to_match = + let {pm=this_match ; ctx=this_ctx } = divide ctx to_match in + let lambda,total = compile_match repr partial this_ctx this_match in + lambda, jumps_map up_ctx total + + + + +(* The entry points *) + +(* + If there is a guard in a matching, then + set exhaustiveness info to Partial. + (because of side effects in guards, assume the worst) +*) + +let check_partial pat_act_list partial = + if + List.exists + (fun (_,lam) -> is_guarded lam) + pat_act_list + then begin + Partial + end else + partial + + +(* have toplevel handler when appropriate *) + +let start_ctx n = [{left=[] ; right = omegas n}] + +let check_total total lambda i handler_fun = + if jumps_is_empty total then + lambda + else begin + Lstaticcatch(lambda, (i,[]), handler_fun()) + end + +let compile_matching loc repr handler_fun arg pat_act_list partial = + let partial = check_partial pat_act_list partial in + match partial with + | Partial -> + let raise_num = next_raise_count () in + let pm = + { cases = List.map (fun (pat, act) -> ([pat], act)) pat_act_list; + args = [arg, Strict] ; + default = [[[omega]],raise_num]} in + begin try + let (lambda, total) = compile_match repr partial (start_ctx 1) pm in + check_total total lambda raise_num handler_fun + with + | Unused -> assert false (* ; handler_fun() *) + end + | Total -> + let pm = + { cases = List.map (fun (pat, act) -> ([pat], act)) pat_act_list; + args = [arg, Strict] ; + default = []} in + let (lambda, total) = compile_match repr partial (start_ctx 1) pm in + assert (jumps_is_empty total) ; + lambda + + +let partial_function loc () = + (* [Location.get_pos_info] is too expensive *) + let fname = match loc.Location.loc_start.Lexing.pos_fname with + | "" -> !Location.input_name + | x -> x + in + let pos = loc.Location.loc_start in + let line = pos.Lexing.pos_lnum in + let char = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in + Lprim(Praise, [Lprim(Pmakeblock(0, Immutable), + [transl_path Predef.path_match_failure; + Lconst(Const_block(0, + [Const_base(Const_string fname); + Const_base(Const_int line); + Const_base(Const_int char)]))])]) + +let for_function loc repr param pat_act_list partial = + compile_matching loc repr (partial_function loc) param pat_act_list partial + +(* In the following two cases, exhaustiveness info is not available! *) +let for_trywith param pat_act_list = + compile_matching Location.none None (fun () -> Lprim(Praise, [param])) + param pat_act_list Partial + +let for_let loc param pat body = + compile_matching loc None (partial_function loc) param [pat, body] Partial + +(* Handling of tupled functions and matchings *) + +(* Easy case since variables are available *) +let for_tupled_function loc paraml pats_act_list partial = + let partial = check_partial pats_act_list partial in + let raise_num = next_raise_count () in + let omegas = [List.map (fun _ -> omega) paraml] in + let pm = + { cases = pats_act_list; + args = List.map (fun id -> (Lvar id, Strict)) paraml ; + default = [omegas,raise_num] + } in + try + let (lambda, total) = compile_match None partial + (start_ctx (List.length paraml)) pm in + check_total total lambda raise_num (partial_function loc) + with + | Unused -> partial_function loc () + + + +let flatten_pattern size p = match p.pat_desc with +| Tpat_tuple args -> args +| Tpat_any -> omegas size +| _ -> raise Cannot_flatten + +let rec flatten_pat_line size p k = match p.pat_desc with +| Tpat_any -> omegas size::k +| Tpat_tuple args -> args::k +| Tpat_or (p1,p2,_) -> flatten_pat_line size p1 (flatten_pat_line size p2 k) +| Tpat_alias (p,_) -> (* Note: if this 'as' pat is here, then this is a useless + binding, solves PR #3780 *) + flatten_pat_line size p k +| _ -> fatal_error "Matching.flatten_pat_line" + +let flatten_cases size cases = + List.map + (fun (ps,action) -> match ps with + | [p] -> flatten_pattern size p,action + | _ -> fatal_error "Matching.flatten_case") + cases + +let flatten_matrix size pss = + List.fold_right + (fun ps r -> match ps with + | [p] -> flatten_pat_line size p r + | _ -> fatal_error "Matching.flatten_matrix") + pss [] + +let flatten_def size def = + List.map + (fun (pss,i) -> flatten_matrix size pss,i) + def + +let flatten_pm size args pm = + {args = args ; cases = flatten_cases size pm.cases ; + default = flatten_def size pm.default} + + +let rec flatten_precompiled size args pmh = match pmh with +| Pm pm -> Pm (flatten_pm size args pm) +| PmOr {body=b ; handlers=hs ; or_matrix=m} -> + PmOr + {body=flatten_pm size args b ; + handlers= + List.map + (fun (mat,i,vars,pm) -> flatten_matrix size mat,i,vars,pm) + hs ; + or_matrix=flatten_matrix size m ;} +| PmVar _ -> assert false + +(* + compiled_flattened is a ``comp_fun'' argument to comp_match_handlers. + Hence it needs a fourth argument, which it ignores +*) + +let compile_flattened repr partial ctx _ pmh = match pmh with +| Pm pm -> compile_match repr partial ctx pm +| PmOr {body=b ; handlers=hs} -> + let lam, total = compile_match repr partial ctx b in + compile_orhandlers (compile_match repr partial) lam total ctx hs +| PmVar _ -> assert false + +let for_multiple_match loc paraml pat_act_list partial = + let repr = None in + let partial = check_partial pat_act_list partial in + let raise_num,pm1 = + match partial with + | Partial -> + let raise_num = next_raise_count () in + raise_num, + { cases = List.map (fun (pat, act) -> ([pat], act)) pat_act_list; + args = [Lprim(Pmakeblock(0, Immutable), paraml), Strict] ; + default = [[[omega]],raise_num] } + | _ -> + -1, + { cases = List.map (fun (pat, act) -> ([pat], act)) pat_act_list; + args = [Lprim(Pmakeblock(0, Immutable), paraml), Strict] ; + default = [] } in + + try + try +(* Once for checking that compilation is possible *) + let next, nexts = split_precompile None pm1 in + + let size = List.length paraml + and idl = List.map (fun _ -> Ident.create "match") paraml in + let args = List.map (fun id -> Lvar id, Alias) idl in + + let flat_next = flatten_precompiled size args next + and flat_nexts = + List.map + (fun (e,pm) -> e,flatten_precompiled size args pm) + nexts in + + let lam, total = + comp_match_handlers + (compile_flattened repr) + partial (start_ctx size) () flat_next flat_nexts in + List.fold_right2 (bind Strict) idl paraml + (match partial with + | Partial -> + check_total total lam raise_num (partial_function loc) + | Total -> + assert (jumps_is_empty total) ; + lam) + with Cannot_flatten -> + let (lambda, total) = compile_match None partial (start_ctx 1) pm1 in + begin match partial with + | Partial -> + check_total total lambda raise_num (partial_function loc) + | Total -> + assert (jumps_is_empty total) ; + lambda + end + with Unused -> + assert false (* ; partial_function loc () *) diff --git a/bytecomp/matching.mli b/bytecomp/matching.mli new file mode 100644 index 0000000..183f900 --- /dev/null +++ b/bytecomp/matching.mli @@ -0,0 +1,43 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: matching.mli,v 1.13 2008-08-01 16:57:10 mauny Exp $ *) + +(* Compilation of pattern-matching *) + +open Typedtree +open Lambda + +val for_function: + Location.t -> int ref option -> lambda -> (pattern * lambda) list -> + partial -> lambda +val for_trywith: + lambda -> (pattern * lambda) list -> lambda +val for_let: + Location.t -> lambda -> pattern -> lambda -> lambda +val for_multiple_match: + Location.t -> lambda list -> (pattern * lambda) list -> partial -> + lambda + +val for_tupled_function: + Location.t -> Ident.t list -> (pattern list * lambda) list -> + partial -> lambda + +exception Cannot_flatten + +val flatten_pattern: int -> pattern -> pattern list + +val make_test_sequence: + lambda option -> primitive -> primitive -> lambda -> + (Asttypes.constant * lambda) list -> lambda + +val inline_lazy_force : lambda -> Location.t -> lambda diff --git a/bytecomp/meta.ml b/bytecomp/meta.ml new file mode 100644 index 0000000..6fc1796 --- /dev/null +++ b/bytecomp/meta.ml @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: meta.ml,v 1.13 2004-04-16 13:46:20 starynke Exp $ *) + +external global_data : unit -> Obj.t array = "caml_get_global_data" +external realloc_global_data : int -> unit = "caml_realloc_global" +external static_alloc : int -> string = "caml_static_alloc" +external static_free : string -> unit = "caml_static_free" +external static_resize : string -> int -> string = "caml_static_resize" +external static_release_bytecode : string -> int -> unit = "caml_static_release_bytecode" +type closure = unit -> Obj.t +external reify_bytecode : string -> int -> closure = "caml_reify_bytecode" +external invoke_traced_function : Obj.t -> Obj.t -> Obj.t -> Obj.t + = "caml_invoke_traced_function" +external get_section_table : unit -> (string * Obj.t) list + = "caml_get_section_table" diff --git a/bytecomp/meta.mli b/bytecomp/meta.mli new file mode 100644 index 0000000..3886605 --- /dev/null +++ b/bytecomp/meta.mli @@ -0,0 +1,28 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: meta.mli,v 1.13 2004-04-16 13:46:27 starynke Exp $ *) + +(* To control the runtime system and bytecode interpreter *) + +external global_data : unit -> Obj.t array = "caml_get_global_data" +external realloc_global_data : int -> unit = "caml_realloc_global" +external static_alloc : int -> string = "caml_static_alloc" +external static_free : string -> unit = "caml_static_free" +external static_release_bytecode : string -> int -> unit = "caml_static_release_bytecode" +external static_resize : string -> int -> string = "caml_static_resize" +type closure = unit -> Obj.t +external reify_bytecode : string -> int -> closure = "caml_reify_bytecode" +external invoke_traced_function : Obj.t -> Obj.t -> Obj.t -> Obj.t + = "caml_invoke_traced_function" +external get_section_table : unit -> (string * Obj.t) list + = "caml_get_section_table" diff --git a/bytecomp/printinstr.ml b/bytecomp/printinstr.ml new file mode 100644 index 0000000..ad22354 --- /dev/null +++ b/bytecomp/printinstr.ml @@ -0,0 +1,115 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printinstr.ml,v 1.23 2005-08-25 15:35:16 doligez Exp $ *) + +(* Pretty-print lists of instructions *) + +open Format +open Lambda +open Instruct + +let instruction ppf = function + | Klabel lbl -> fprintf ppf "L%i:" lbl + | Kacc n -> fprintf ppf "\tacc %i" n + | Kenvacc n -> fprintf ppf "\tenvacc %i" n + | Kpush -> fprintf ppf "\tpush" + | Kpop n -> fprintf ppf "\tpop %i" n + | Kassign n -> fprintf ppf "\tassign %i" n + | Kpush_retaddr lbl -> fprintf ppf "\tpush_retaddr L%i" lbl + | Kapply n -> fprintf ppf "\tapply %i" n + | Kappterm(n, m) -> + fprintf ppf "\tappterm %i, %i" n m + | Kreturn n -> fprintf ppf "\treturn %i" n + | Krestart -> fprintf ppf "\trestart" + | Kgrab n -> fprintf ppf "\tgrab %i" n + | Kclosure(lbl, n) -> + fprintf ppf "\tclosure L%i, %i" lbl n + | Kclosurerec(lbls, n) -> + fprintf ppf "\tclosurerec"; + List.iter (fun lbl -> fprintf ppf " %i" lbl) lbls; + fprintf ppf ", %i" n + | Koffsetclosure n -> fprintf ppf "\toffsetclosure %i" n + | Kgetglobal id -> fprintf ppf "\tgetglobal %a" Ident.print id + | Ksetglobal id -> fprintf ppf "\tsetglobal %a" Ident.print id + | Kconst cst -> + fprintf ppf "@[<10>\tconst@ %a@]" Printlambda.structured_constant cst + | Kmakeblock(n, m) -> + fprintf ppf "\tmakeblock %i, %i" n m + | Kmakefloatblock(n) -> + fprintf ppf "\tmakefloatblock %i" n + | Kgetfield n -> fprintf ppf "\tgetfield %i" n + | Ksetfield n -> fprintf ppf "\tsetfield %i" n + | Kgetfloatfield n -> fprintf ppf "\tgetfloatfield %i" n + | Ksetfloatfield n -> fprintf ppf "\tsetfloatfield %i" n + | Kvectlength -> fprintf ppf "\tvectlength" + | Kgetvectitem -> fprintf ppf "\tgetvectitem" + | Ksetvectitem -> fprintf ppf "\tsetvectitem" + | Kgetstringchar -> fprintf ppf "\tgetstringchar" + | Ksetstringchar -> fprintf ppf "\tsetstringchar" + | Kbranch lbl -> fprintf ppf "\tbranch L%i" lbl + | Kbranchif lbl -> fprintf ppf "\tbranchif L%i" lbl + | Kbranchifnot lbl -> fprintf ppf "\tbranchifnot L%i" lbl + | Kstrictbranchif lbl -> fprintf ppf "\tstrictbranchif L%i" lbl + | Kstrictbranchifnot lbl -> + fprintf ppf "\tstrictbranchifnot L%i" lbl + | Kswitch(consts, blocks) -> + let labels ppf labs = + Array.iter (fun lbl -> fprintf ppf "@ %i" lbl) labs in + fprintf ppf "@[<10>\tswitch%a/%a@]" labels consts labels blocks + | Kboolnot -> fprintf ppf "\tboolnot" + | Kpushtrap lbl -> fprintf ppf "\tpushtrap L%i" lbl + | Kpoptrap -> fprintf ppf "\tpoptrap" + | Kraise -> fprintf ppf "\traise" + | Kcheck_signals -> fprintf ppf "\tcheck_signals" + | Kccall(s, n) -> + fprintf ppf "\tccall %s, %i" s n + | Knegint -> fprintf ppf "\tnegint" + | Kaddint -> fprintf ppf "\taddint" + | Ksubint -> fprintf ppf "\tsubint" + | Kmulint -> fprintf ppf "\tmulint" + | Kdivint -> fprintf ppf "\tdivint" + | Kmodint -> fprintf ppf "\tmodint" + | Kandint -> fprintf ppf "\tandint" + | Korint -> fprintf ppf "\torint" + | Kxorint -> fprintf ppf "\txorint" + | Klslint -> fprintf ppf "\tlslint" + | Klsrint -> fprintf ppf "\tlsrint" + | Kasrint -> fprintf ppf "\tasrint" + | Kintcomp Ceq -> fprintf ppf "\teqint" + | Kintcomp Cneq -> fprintf ppf "\tneqint" + | Kintcomp Clt -> fprintf ppf "\tltint" + | Kintcomp Cgt -> fprintf ppf "\tgtint" + | Kintcomp Cle -> fprintf ppf "\tleint" + | Kintcomp Cge -> fprintf ppf "\tgeint" + | Koffsetint n -> fprintf ppf "\toffsetint %i" n + | Koffsetref n -> fprintf ppf "\toffsetref %i" n + | Kisint -> fprintf ppf "\tisint" + | Kisout -> fprintf ppf "\tisout" + | Kgetmethod -> fprintf ppf "\tgetmethod" + | Kgetpubmet n -> fprintf ppf "\tgetpubmet %i" n + | Kgetdynmet -> fprintf ppf "\tgetdynmet" + | Kstop -> fprintf ppf "\tstop" + | Kevent ev -> fprintf ppf "\tevent \"%s\" %i-%i" + ev.ev_loc.Location.loc_start.Lexing.pos_fname + ev.ev_loc.Location.loc_start.Lexing.pos_cnum + ev.ev_loc.Location.loc_end.Lexing.pos_cnum + +let rec instruction_list ppf = function + [] -> () + | Klabel lbl :: il -> + fprintf ppf "L%i:%a" lbl instruction_list il + | instr :: il -> + fprintf ppf "%a@ %a" instruction instr instruction_list il + +let instrlist ppf il = + fprintf ppf "@[%a@]" instruction_list il diff --git a/bytecomp/printinstr.mli b/bytecomp/printinstr.mli new file mode 100644 index 0000000..8f9f343 --- /dev/null +++ b/bytecomp/printinstr.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printinstr.mli,v 1.5 2000-03-06 22:11:08 weis Exp $ *) + +(* Pretty-print lists of instructions *) + +open Instruct + +open Format + +val instruction: formatter -> instruction -> unit +val instrlist: formatter -> instruction list -> unit diff --git a/bytecomp/printlambda.ml b/bytecomp/printlambda.ml new file mode 100644 index 0000000..0445480 --- /dev/null +++ b/bytecomp/printlambda.ml @@ -0,0 +1,315 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printlambda.ml,v 1.55 2008-08-01 16:57:10 mauny Exp $ *) + +open Format +open Asttypes +open Primitive +open Types +open Lambda + + +let rec struct_const ppf = function + | Const_base(Const_int n) -> fprintf ppf "%i" n + | Const_base(Const_char c) -> fprintf ppf "%C" c + | Const_base(Const_string s) -> fprintf ppf "%S" s + | Const_immstring s -> fprintf ppf "#%S" s + | Const_base(Const_float f) -> fprintf ppf "%s" f + | Const_base(Const_int32 n) -> fprintf ppf "%lil" n + | Const_base(Const_int64 n) -> fprintf ppf "%LiL" n + | Const_base(Const_nativeint n) -> fprintf ppf "%nin" n + | Const_pointer n -> fprintf ppf "%ia" n + | Const_block(tag, []) -> + fprintf ppf "[%i]" tag + | Const_block(tag, sc1::scl) -> + let sconsts ppf scl = + List.iter (fun sc -> fprintf ppf "@ %a" struct_const sc) scl in + fprintf ppf "@[<1>[%i:@ @[%a%a@]]@]" tag struct_const sc1 sconsts scl + | Const_float_array [] -> + fprintf ppf "[| |]" + | Const_float_array (f1 :: fl) -> + let floats ppf fl = + List.iter (fun f -> fprintf ppf "@ %s" f) fl in + fprintf ppf "@[<1>[|@[%s%a@]|]@]" f1 floats fl + +let boxed_integer_name = function + | Pnativeint -> "nativeint" + | Pint32 -> "int32" + | Pint64 -> "int64" + +let print_boxed_integer name ppf bi = + fprintf ppf "%s_%s" (boxed_integer_name bi) name + +let print_boxed_integer_conversion ppf bi1 bi2 = + fprintf ppf "%s_of_%s" (boxed_integer_name bi2) (boxed_integer_name bi1) + +let boxed_integer_mark name = function + | Pnativeint -> Printf.sprintf "Nativeint.%s" name + | Pint32 -> Printf.sprintf "Int32.%s" name + | Pint64 -> Printf.sprintf "Int64.%s" name + +let print_boxed_integer name ppf bi = + fprintf ppf "%s" (boxed_integer_mark name bi);; + +let print_bigarray name unsafe kind ppf layout = + fprintf ppf "Bigarray.%s[%s,%s]" + (if unsafe then "unsafe_"^ name else name) + (match kind with + | Pbigarray_unknown -> "generic" + | Pbigarray_float32 -> "float32" + | Pbigarray_float64 -> "float64" + | Pbigarray_sint8 -> "sint8" + | Pbigarray_uint8 -> "uint8" + | Pbigarray_sint16 -> "sint16" + | Pbigarray_uint16 -> "uint16" + | Pbigarray_int32 -> "int32" + | Pbigarray_int64 -> "int64" + | Pbigarray_caml_int -> "camlint" + | Pbigarray_native_int -> "nativeint" + | Pbigarray_complex32 -> "complex32" + | Pbigarray_complex64 -> "complex64") + (match layout with + | Pbigarray_unknown_layout -> "unknown" + | Pbigarray_c_layout -> "C" + | Pbigarray_fortran_layout -> "Fortran") + +let record_rep ppf r = + match r with + | Record_regular -> fprintf ppf "regular" + | Record_float -> fprintf ppf "float" +;; + +let primitive ppf = function + | Pidentity -> fprintf ppf "id" + | Pignore -> fprintf ppf "ignore" + | Pgetglobal id -> fprintf ppf "global %a" Ident.print id + | Psetglobal id -> fprintf ppf "setglobal %a" Ident.print id + | Pmakeblock(tag, Immutable) -> fprintf ppf "makeblock %i" tag + | Pmakeblock(tag, Mutable) -> fprintf ppf "makemutable %i" tag + | Pfield n -> fprintf ppf "field %i" n + | Psetfield(n, ptr) -> + let instr = if ptr then "setfield_ptr " else "setfield_imm " in + fprintf ppf "%s%i" instr n + | Pfloatfield n -> fprintf ppf "floatfield %i" n + | Psetfloatfield n -> fprintf ppf "setfloatfield %i" n + | Pduprecord (rep, size) -> fprintf ppf "duprecord %a %i" record_rep rep size + | Plazyforce -> fprintf ppf "force" + | Pccall p -> fprintf ppf "%s" p.prim_name + | Praise -> fprintf ppf "raise" + | Psequand -> fprintf ppf "&&" + | Psequor -> fprintf ppf "||" + | Pnot -> fprintf ppf "not" + | Pnegint -> fprintf ppf "~" + | Paddint -> fprintf ppf "+" + | Psubint -> fprintf ppf "-" + | Pmulint -> fprintf ppf "*" + | Pdivint -> fprintf ppf "/" + | Pmodint -> fprintf ppf "mod" + | Pandint -> fprintf ppf "and" + | Porint -> fprintf ppf "or" + | Pxorint -> fprintf ppf "xor" + | Plslint -> fprintf ppf "lsl" + | Plsrint -> fprintf ppf "lsr" + | Pasrint -> fprintf ppf "asr" + | Pintcomp(Ceq) -> fprintf ppf "==" + | Pintcomp(Cneq) -> fprintf ppf "!=" + | Pintcomp(Clt) -> fprintf ppf "<" + | Pintcomp(Cle) -> fprintf ppf "<=" + | Pintcomp(Cgt) -> fprintf ppf ">" + | Pintcomp(Cge) -> fprintf ppf ">=" + | Poffsetint n -> fprintf ppf "%i+" n + | Poffsetref n -> fprintf ppf "+:=%i"n + | Pintoffloat -> fprintf ppf "int_of_float" + | Pfloatofint -> fprintf ppf "float_of_int" + | Pnegfloat -> fprintf ppf "~." + | Pabsfloat -> fprintf ppf "abs." + | Paddfloat -> fprintf ppf "+." + | Psubfloat -> fprintf ppf "-." + | Pmulfloat -> fprintf ppf "*." + | Pdivfloat -> fprintf ppf "/." + | Pfloatcomp(Ceq) -> fprintf ppf "==." + | Pfloatcomp(Cneq) -> fprintf ppf "!=." + | Pfloatcomp(Clt) -> fprintf ppf "<." + | Pfloatcomp(Cle) -> fprintf ppf "<=." + | Pfloatcomp(Cgt) -> fprintf ppf ">." + | Pfloatcomp(Cge) -> fprintf ppf ">=." + | Pstringlength -> fprintf ppf "string.length" + | Pstringrefu -> fprintf ppf "string.unsafe_get" + | Pstringsetu -> fprintf ppf "string.unsafe_set" + | Pstringrefs -> fprintf ppf "string.get" + | Pstringsets -> fprintf ppf "string.set" + | Parraylength _ -> fprintf ppf "array.length" + | Pmakearray _ -> fprintf ppf "makearray " + | Parrayrefu _ -> fprintf ppf "array.unsafe_get" + | Parraysetu _ -> fprintf ppf "array.unsafe_set" + | Parrayrefs _ -> fprintf ppf "array.get" + | Parraysets _ -> fprintf ppf "array.set" + | Pisint -> fprintf ppf "isint" + | Pisout -> fprintf ppf "isout" + | Pbittest -> fprintf ppf "testbit" + | Pbintofint bi -> print_boxed_integer "of_int" ppf bi + | Pintofbint bi -> print_boxed_integer "to_int" ppf bi + | Pcvtbint (bi1, bi2) -> print_boxed_integer_conversion ppf bi1 bi2 + | Pnegbint bi -> print_boxed_integer "neg" ppf bi + | Paddbint bi -> print_boxed_integer "add" ppf bi + | Psubbint bi -> print_boxed_integer "sub" ppf bi + | Pmulbint bi -> print_boxed_integer "mul" ppf bi + | Pdivbint bi -> print_boxed_integer "div" ppf bi + | Pmodbint bi -> print_boxed_integer "mod" ppf bi + | Pandbint bi -> print_boxed_integer "and" ppf bi + | Porbint bi -> print_boxed_integer "or" ppf bi + | Pxorbint bi -> print_boxed_integer "xor" ppf bi + | Plslbint bi -> print_boxed_integer "lsl" ppf bi + | Plsrbint bi -> print_boxed_integer "lsr" ppf bi + | Pasrbint bi -> print_boxed_integer "asr" ppf bi + | Pbintcomp(bi, Ceq) -> print_boxed_integer "==" ppf bi + | Pbintcomp(bi, Cneq) -> print_boxed_integer "!=" ppf bi + | Pbintcomp(bi, Clt) -> print_boxed_integer "<" ppf bi + | Pbintcomp(bi, Cgt) -> print_boxed_integer ">" ppf bi + | Pbintcomp(bi, Cle) -> print_boxed_integer "<=" ppf bi + | Pbintcomp(bi, Cge) -> print_boxed_integer ">=" ppf bi + | Pbigarrayref(unsafe, n, kind, layout) -> + print_bigarray "get" unsafe kind ppf layout + | Pbigarrayset(unsafe, n, kind, layout) -> + print_bigarray "set" unsafe kind ppf layout + +let rec lam ppf = function + | Lvar id -> + Ident.print ppf id + | Lconst cst -> + struct_const ppf cst + | Lapply(lfun, largs, _) -> + let lams ppf largs = + List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in + fprintf ppf "@[<2>(apply@ %a%a)@]" lam lfun lams largs + | Lfunction(kind, params, body) -> + let pr_params ppf params = + match kind with + | Curried -> + List.iter (fun param -> fprintf ppf "@ %a" Ident.print param) params + | Tupled -> + fprintf ppf " ("; + let first = ref true in + List.iter + (fun param -> + if !first then first := false else fprintf ppf ",@ "; + Ident.print ppf param) + params; + fprintf ppf ")" in + fprintf ppf "@[<2>(function%a@ %a)@]" pr_params params lam body + | Llet(str, id, arg, body) -> + let rec letbody = function + | Llet(str, id, arg, body) -> + fprintf ppf "@ @[<2>%a@ %a@]" Ident.print id lam arg; + letbody body + | expr -> expr in + fprintf ppf "@[<2>(let@ @[(@[<2>%a@ %a@]" Ident.print id lam arg; + let expr = letbody body in + fprintf ppf ")@]@ %a)@]" lam expr + | Lletrec(id_arg_list, body) -> + let bindings ppf id_arg_list = + let spc = ref false in + List.iter + (fun (id, l) -> + if !spc then fprintf ppf "@ " else spc := true; + fprintf ppf "@[<2>%a@ %a@]" Ident.print id lam l) + id_arg_list in + fprintf ppf + "@[<2>(letrec@ (@[%a@])@ %a)@]" bindings id_arg_list lam body + | Lprim(prim, largs) -> + let lams ppf largs = + List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in + fprintf ppf "@[<2>(%a%a)@]" primitive prim lams largs + | Lswitch(larg, sw) -> + let switch ppf sw = + let spc = ref false in + List.iter + (fun (n, l) -> + if !spc then fprintf ppf "@ " else spc := true; + fprintf ppf "@[case int %i:@ %a@]" n lam l) + sw.sw_consts; + List.iter + (fun (n, l) -> + if !spc then fprintf ppf "@ " else spc := true; + fprintf ppf "@[case tag %i:@ %a@]" n lam l) + sw.sw_blocks ; + begin match sw.sw_failaction with + | None -> () + | Some l -> + if !spc then fprintf ppf "@ " else spc := true; + fprintf ppf "@[default:@ %a@]" lam l + end in + + fprintf ppf + "@[<1>(%s %a@ @[%a@])@]" + (match sw.sw_failaction with None -> "switch*" | _ -> "switch") + lam larg switch sw + | Lstaticraise (i, ls) -> + let lams ppf largs = + List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in + fprintf ppf "@[<2>(exit@ %d%a)@]" i lams ls; + | Lstaticcatch(lbody, (i, vars), lhandler) -> + fprintf ppf "@[<2>(catch@ %a@;<1 -1>with (%d%a)@ %a)@]" + lam lbody i + (fun ppf vars -> match vars with + | [] -> () + | _ -> + List.iter + (fun x -> fprintf ppf " %a" Ident.print x) + vars) + vars + lam lhandler + | Ltrywith(lbody, param, lhandler) -> + fprintf ppf "@[<2>(try@ %a@;<1 -1>with %a@ %a)@]" + lam lbody Ident.print param lam lhandler + | Lifthenelse(lcond, lif, lelse) -> + fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" lam lcond lam lif lam lelse + | Lsequence(l1, l2) -> + fprintf ppf "@[<2>(seq@ %a@ %a)@]" lam l1 sequence l2 + | Lwhile(lcond, lbody) -> + fprintf ppf "@[<2>(while@ %a@ %a)@]" lam lcond lam lbody + | Lfor(param, lo, hi, dir, body) -> + fprintf ppf "@[<2>(for %a@ %a@ %s@ %a@ %a)@]" + Ident.print param lam lo + (match dir with Upto -> "to" | Downto -> "downto") + lam hi lam body + | Lassign(id, expr) -> + fprintf ppf "@[<2>(assign@ %a@ %a)@]" Ident.print id lam expr + | Lsend (k, met, obj, largs) -> + let args ppf largs = + List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in + let kind = + if k = Self then "self" else if k = Cached then "cache" else "" in + fprintf ppf "@[<2>(send%s@ %a@ %a%a)@]" kind lam obj lam met args largs + | Levent(expr, ev) -> + let kind = + match ev.lev_kind with + | Lev_before -> "before" + | Lev_after _ -> "after" + | Lev_function -> "funct-body" in + fprintf ppf "@[<2>(%s %i-%i@ %a)@]" kind + ev.lev_loc.Location.loc_start.Lexing.pos_cnum + ev.lev_loc.Location.loc_end.Lexing.pos_cnum + lam expr + | Lifused(id, expr) -> + fprintf ppf "@[<2>(ifused@ %a@ %a)@]" Ident.print id lam expr + +and sequence ppf = function + | Lsequence(l1, l2) -> + fprintf ppf "%a@ %a" sequence l1 sequence l2 + | l -> + lam ppf l + +let structured_constant = struct_const + +let lambda = lam diff --git a/bytecomp/printlambda.mli b/bytecomp/printlambda.mli new file mode 100644 index 0000000..22ef844 --- /dev/null +++ b/bytecomp/printlambda.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printlambda.mli,v 1.5 2000-03-06 22:11:10 weis Exp $ *) + +open Lambda + +open Format + +val structured_constant: formatter -> structured_constant -> unit +val lambda: formatter -> lambda -> unit diff --git a/bytecomp/runtimedef.mli b/bytecomp/runtimedef.mli new file mode 100644 index 0000000..893e328 --- /dev/null +++ b/bytecomp/runtimedef.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: runtimedef.mli,v 1.4 1999-11-17 18:57:01 xleroy Exp $ *) + +(* Values and functions known and/or provided by the runtime system *) + +val builtin_exceptions: string array +val builtin_primitives: string array diff --git a/bytecomp/simplif.ml b/bytecomp/simplif.ml new file mode 100644 index 0000000..abe7007 --- /dev/null +++ b/bytecomp/simplif.ml @@ -0,0 +1,412 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: simplif.ml,v 1.25 2008-03-19 10:26:56 maranget Exp $ *) + +(* Elimination of useless Llet(Alias) bindings. + Also transform let-bound references into variables. *) + +open Asttypes +open Lambda + +(* To transform let-bound references into variables *) + +exception Real_reference + +let rec eliminate_ref id = function + Lvar v as lam -> + if Ident.same v id then raise Real_reference else lam + | Lconst cst as lam -> lam + | Lapply(e1, el, loc) -> + Lapply(eliminate_ref id e1, List.map (eliminate_ref id) el, loc) + | Lfunction(kind, params, body) as lam -> + if IdentSet.mem id (free_variables lam) + then raise Real_reference + else lam + | Llet(str, v, e1, e2) -> + Llet(str, v, eliminate_ref id e1, eliminate_ref id e2) + | Lletrec(idel, e2) -> + Lletrec(List.map (fun (v, e) -> (v, eliminate_ref id e)) idel, + eliminate_ref id e2) + | Lprim(Pfield 0, [Lvar v]) when Ident.same v id -> + Lvar id + | Lprim(Psetfield(0, _), [Lvar v; e]) when Ident.same v id -> + Lassign(id, eliminate_ref id e) + | Lprim(Poffsetref delta, [Lvar v]) when Ident.same v id -> + Lassign(id, Lprim(Poffsetint delta, [Lvar id])) + | Lprim(p, el) -> + Lprim(p, List.map (eliminate_ref id) el) + | Lswitch(e, sw) -> + Lswitch(eliminate_ref id e, + {sw_numconsts = sw.sw_numconsts; + sw_consts = + List.map (fun (n, e) -> (n, eliminate_ref id e)) sw.sw_consts; + sw_numblocks = sw.sw_numblocks; + sw_blocks = + List.map (fun (n, e) -> (n, eliminate_ref id e)) sw.sw_blocks; + sw_failaction = match sw.sw_failaction with + | None -> None + | Some l -> Some (eliminate_ref id l)}) + | Lstaticraise (i,args) -> + Lstaticraise (i,List.map (eliminate_ref id) args) + | Lstaticcatch(e1, i, e2) -> + Lstaticcatch(eliminate_ref id e1, i, eliminate_ref id e2) + | Ltrywith(e1, v, e2) -> + Ltrywith(eliminate_ref id e1, v, eliminate_ref id e2) + | Lifthenelse(e1, e2, e3) -> + Lifthenelse(eliminate_ref id e1, + eliminate_ref id e2, + eliminate_ref id e3) + | Lsequence(e1, e2) -> + Lsequence(eliminate_ref id e1, eliminate_ref id e2) + | Lwhile(e1, e2) -> + Lwhile(eliminate_ref id e1, eliminate_ref id e2) + | Lfor(v, e1, e2, dir, e3) -> + Lfor(v, eliminate_ref id e1, eliminate_ref id e2, + dir, eliminate_ref id e3) + | Lassign(v, e) -> + Lassign(v, eliminate_ref id e) + | Lsend(k, m, o, el) -> + Lsend(k, eliminate_ref id m, eliminate_ref id o, + List.map (eliminate_ref id) el) + | Levent(l, ev) -> + Levent(eliminate_ref id l, ev) + | Lifused(v, e) -> + Lifused(v, eliminate_ref id e) + +(* Simplification of exits *) + +let simplify_exits lam = + + (* Count occurrences of (exit n ...) statements *) + let exits = Hashtbl.create 17 in + + let count_exit i = + try + !(Hashtbl.find exits i) + with + | Not_found -> 0 + + and incr_exit i = + try + incr (Hashtbl.find exits i) + with + | Not_found -> Hashtbl.add exits i (ref 1) in + + let rec count = function + | (Lvar _| Lconst _) -> () + | Lapply(l1, ll, _) -> count l1; List.iter count ll + | Lfunction(kind, params, l) -> count l + | Llet(str, v, l1, l2) -> + count l2; count l1 + | Lletrec(bindings, body) -> + List.iter (fun (v, l) -> count l) bindings; + count body + | Lprim(p, ll) -> List.iter count ll + | Lswitch(l, sw) -> + count_default sw ; + count l; + List.iter (fun (_, l) -> count l) sw.sw_consts; + List.iter (fun (_, l) -> count l) sw.sw_blocks + | Lstaticraise (i,ls) -> incr_exit i ; List.iter count ls + | Lstaticcatch (l1,(i,[]),Lstaticraise (j,[])) -> + (* i will be replaced by j in l1, so each occurence of i in l1 + increases j's ref count *) + count l1 ; + let ic = count_exit i in + begin try + let r = Hashtbl.find exits j in r := !r + ic + with + | Not_found -> + Hashtbl.add exits j (ref ic) + end + | Lstaticcatch(l1, (i,_), l2) -> + count l1; + (* If l1 does not contain (exit i), + l2 will be removed, so don't count its exits *) + if count_exit i > 0 then + count l2 + | Ltrywith(l1, v, l2) -> count l1; count l2 + | Lifthenelse(l1, l2, l3) -> count l1; count l2; count l3 + | Lsequence(l1, l2) -> count l1; count l2 + | Lwhile(l1, l2) -> count l1; count l2 + | Lfor(_, l1, l2, dir, l3) -> count l1; count l2; count l3 + | Lassign(v, l) -> + (* Lalias-bound variables are never assigned, so don't increase + v's refcount *) + count l + | Lsend(k, m, o, ll) -> List.iter count (m::o::ll) + | Levent(l, _) -> count l + | Lifused(v, l) -> count l + + and count_default sw = match sw.sw_failaction with + | None -> () + | Some al -> + let nconsts = List.length sw.sw_consts + and nblocks = List.length sw.sw_blocks in + if + nconsts < sw.sw_numconsts && nblocks < sw.sw_numblocks + then begin (* default action will occur twice in native code *) + count al ; count al + end else begin (* default action will occur once *) + assert (nconsts < sw.sw_numconsts || nblocks < sw.sw_numblocks) ; + count al + end + in + count lam; + + (* + Second pass simplify ``catch body with (i ...) handler'' + - if (exit i ...) does not occur in body, suppress catch + - if (exit i ...) occurs exactly once in body, + substitute it with handler + - If handler is a single variable, replace (exit i ..) with it + Note: + In ``catch body with (i x1 .. xn) handler'' + Substituted expression is + let y1 = x1 and ... yn = xn in + handler[x1 <- y1 ; ... ; xn <- yn] + For the sake of preserving the uniqueness of bound variables. + (No alpha conversion of ``handler'' is presently needed, since + substitution of several ``(exit i ...)'' + occurs only when ``handler'' is a variable.) + *) + + let subst = Hashtbl.create 17 in + + let rec simplif = function + | (Lvar _|Lconst _) as l -> l + | Lapply(l1, ll, loc) -> Lapply(simplif l1, List.map simplif ll, loc) + | Lfunction(kind, params, l) -> Lfunction(kind, params, simplif l) + | Llet(kind, v, l1, l2) -> Llet(kind, v, simplif l1, simplif l2) + | Lletrec(bindings, body) -> + Lletrec(List.map (fun (v, l) -> (v, simplif l)) bindings, simplif body) + | Lprim(p, ll) -> Lprim(p, List.map simplif ll) + | Lswitch(l, sw) -> + let new_l = simplif l + and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts + and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks + and new_fail = match sw.sw_failaction with + | None -> None + | Some l -> Some (simplif l) in + Lswitch + (new_l, + {sw with sw_consts = new_consts ; sw_blocks = new_blocks; + sw_failaction = new_fail}) + | Lstaticraise (i,[]) as l -> + begin try + let _,handler = Hashtbl.find subst i in + handler + with + | Not_found -> l + end + | Lstaticraise (i,ls) -> + let ls = List.map simplif ls in + begin try + let xs,handler = Hashtbl.find subst i in + let ys = List.map Ident.rename xs in + let env = + List.fold_right2 + (fun x y t -> Ident.add x (Lvar y) t) + xs ys Ident.empty in + List.fold_right2 + (fun y l r -> Llet (Alias, y, l, r)) + ys ls (Lambda.subst_lambda env handler) + with + | Not_found -> Lstaticraise (i,ls) + end + | Lstaticcatch (l1,(i,[]),(Lstaticraise (j,[]) as l2)) -> + Hashtbl.add subst i ([],simplif l2) ; + simplif l1 + | Lstaticcatch (l1,(i,xs), (Lvar _ as l2)) -> + begin match count_exit i with + | 0 -> simplif l1 + | _ -> + Hashtbl.add subst i (xs,l2) ; + simplif l1 + end + | Lstaticcatch (l1,(i,xs),l2) -> + begin match count_exit i with + | 0 -> simplif l1 + | 1 -> + Hashtbl.add subst i (xs,simplif l2) ; + simplif l1 + | _ -> + Lstaticcatch (simplif l1, (i,xs), simplif l2) + end + | Ltrywith(l1, v, l2) -> Ltrywith(simplif l1, v, simplif l2) + | Lifthenelse(l1, l2, l3) -> Lifthenelse(simplif l1, simplif l2, simplif l3) + | Lsequence(l1, l2) -> Lsequence(simplif l1, simplif l2) + | Lwhile(l1, l2) -> Lwhile(simplif l1, simplif l2) + | Lfor(v, l1, l2, dir, l3) -> + Lfor(v, simplif l1, simplif l2, dir, simplif l3) + | Lassign(v, l) -> Lassign(v, simplif l) + | Lsend(k, m, o, ll) -> Lsend(k, simplif m, simplif o, List.map simplif ll) + | Levent(l, ev) -> Levent(simplif l, ev) + | Lifused(v, l) -> Lifused (v,simplif l) + in + simplif lam + +(* Simplification of lets *) + +let simplify_lets lam = + + (* First pass: count the occurrences of all identifiers *) + let occ = Hashtbl.create 83 in + let count_var v = + try + !(Hashtbl.find occ v) + with Not_found -> + 0 + and incr_var v = + try + incr(Hashtbl.find occ v) + with Not_found -> + Hashtbl.add occ v (ref 1) in + + let rec count = function + | Lvar v -> incr_var v + | Lconst cst -> () + | Lapply(l1, ll, _) -> count l1; List.iter count ll + | Lfunction(kind, params, l) -> count l + | Llet(str, v, Lvar w, l2) when not !Clflags.debug -> + (* v will be replaced by w in l2, so each occurrence of v in l2 + increases w's refcount *) + count l2; + let vc = count_var v in + begin try + let r = Hashtbl.find occ w in r := !r + vc + with Not_found -> + Hashtbl.add occ w (ref vc) + end + | Llet(str, v, l1, l2) -> + count l2; + (* If v is unused, l1 will be removed, so don't count its variables *) + if str = Strict || count_var v > 0 then count l1 + | Lletrec(bindings, body) -> + List.iter (fun (v, l) -> count l) bindings; + count body + | Lprim(p, ll) -> List.iter count ll + | Lswitch(l, sw) -> + count_default sw ; + count l; + List.iter (fun (_, l) -> count l) sw.sw_consts; + List.iter (fun (_, l) -> count l) sw.sw_blocks + | Lstaticraise (i,ls) -> List.iter count ls + | Lstaticcatch(l1, (i,_), l2) -> + count l1; count l2 + | Ltrywith(l1, v, l2) -> count l1; count l2 + | Lifthenelse(l1, l2, l3) -> count l1; count l2; count l3 + | Lsequence(l1, l2) -> count l1; count l2 + | Lwhile(l1, l2) -> count l1; count l2 + | Lfor(_, l1, l2, dir, l3) -> count l1; count l2; count l3 + | Lassign(v, l) -> + (* Lalias-bound variables are never assigned, so don't increase + v's refcount *) + count l + | Lsend(_, m, o, ll) -> List.iter count (m::o::ll) + | Levent(l, _) -> count l + | Lifused(v, l) -> + if count_var v > 0 then count l + + and count_default sw = match sw.sw_failaction with + | None -> () + | Some al -> + let nconsts = List.length sw.sw_consts + and nblocks = List.length sw.sw_blocks in + if + nconsts < sw.sw_numconsts && nblocks < sw.sw_numblocks + then begin (* default action will occur twice in native code *) + count al ; count al + end else begin (* default action will occur once *) + assert (nconsts < sw.sw_numconsts || nblocks < sw.sw_numblocks) ; + count al + end + in + count lam; + (* Second pass: remove Lalias bindings of unused variables, + and substitute the bindings of variables used exactly once. *) + + let subst = Hashtbl.create 83 in + + let rec simplif = function + Lvar v as l -> + begin try + Hashtbl.find subst v + with Not_found -> + l + end + | Lconst cst as l -> l + | Lapply(l1, ll, loc) -> Lapply(simplif l1, List.map simplif ll, loc) + | Lfunction(kind, params, l) -> Lfunction(kind, params, simplif l) + | Llet(str, v, Lvar w, l2) when not !Clflags.debug -> + Hashtbl.add subst v (simplif (Lvar w)); + simplif l2 + | Llet(Strict, v, Lprim(Pmakeblock(0, Mutable), [linit]), lbody) + when not !Clflags.debug -> + let slinit = simplif linit in + let slbody = simplif lbody in + begin try + Llet(Variable, v, slinit, eliminate_ref v slbody) + with Real_reference -> + Llet(Strict, v, Lprim(Pmakeblock(0, Mutable), [slinit]), slbody) + end + | Llet(Alias, v, l1, l2) -> + begin match count_var v with + 0 -> simplif l2 + | 1 when not !Clflags.debug -> + Hashtbl.add subst v (simplif l1); simplif l2 + | n -> Llet(Alias, v, simplif l1, simplif l2) + end + | Llet(StrictOpt, v, l1, l2) -> + begin match count_var v with + 0 -> simplif l2 + | n -> Llet(Alias, v, simplif l1, simplif l2) + end + | Llet(kind, v, l1, l2) -> Llet(kind, v, simplif l1, simplif l2) + | Lletrec(bindings, body) -> + Lletrec(List.map (fun (v, l) -> (v, simplif l)) bindings, simplif body) + | Lprim(p, ll) -> Lprim(p, List.map simplif ll) + | Lswitch(l, sw) -> + let new_l = simplif l + and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts + and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks + and new_fail = match sw.sw_failaction with + | None -> None + | Some l -> Some (simplif l) in + Lswitch + (new_l, + {sw with sw_consts = new_consts ; sw_blocks = new_blocks; + sw_failaction = new_fail}) + | Lstaticraise (i,ls) -> + Lstaticraise (i, List.map simplif ls) + | Lstaticcatch(l1, (i,args), l2) -> + Lstaticcatch (simplif l1, (i,args), simplif l2) + | Ltrywith(l1, v, l2) -> Ltrywith(simplif l1, v, simplif l2) + | Lifthenelse(l1, l2, l3) -> Lifthenelse(simplif l1, simplif l2, simplif l3) + | Lsequence(Lifused(v, l1), l2) -> + if count_var v > 0 + then Lsequence(simplif l1, simplif l2) + else simplif l2 + | Lsequence(l1, l2) -> Lsequence(simplif l1, simplif l2) + | Lwhile(l1, l2) -> Lwhile(simplif l1, simplif l2) + | Lfor(v, l1, l2, dir, l3) -> + Lfor(v, simplif l1, simplif l2, dir, simplif l3) + | Lassign(v, l) -> Lassign(v, simplif l) + | Lsend(k, m, o, ll) -> Lsend(k, simplif m, simplif o, List.map simplif ll) + | Levent(l, ev) -> Levent(simplif l, ev) + | Lifused(v, l) -> + if count_var v > 0 then simplif l else lambda_unit + in + simplif lam + +let simplify_lambda lam = simplify_lets (simplify_exits lam) diff --git a/bytecomp/simplif.mli b/bytecomp/simplif.mli new file mode 100644 index 0000000..8e3c924 --- /dev/null +++ b/bytecomp/simplif.mli @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: simplif.mli,v 1.3 1999-11-17 18:57:01 xleroy Exp $ *) + +(* Elimination of useless Llet(Alias) bindings *) + +open Lambda + +val simplify_lambda: lambda -> lambda diff --git a/bytecomp/switch.ml b/bytecomp/switch.ml new file mode 100644 index 0000000..ff58af7 --- /dev/null +++ b/bytecomp/switch.ml @@ -0,0 +1,811 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* Store for actions in object style *) +exception Found of int + +type 'a t_store = + {act_get : unit -> 'a array ; act_store : 'a -> int} + +let mk_store same = + let r_acts = ref [] in + let store act = + let rec store_rec i = function + | [] -> i,[act] + | act0::rem -> + if same act0 act then raise (Found i) + else + let i,rem = store_rec (i+1) rem in + i,act0::rem in + try + let i,acts = store_rec 0 !r_acts in + r_acts := acts ; + i + with + | Found i -> i + + and get () = Array.of_list !r_acts in + {act_store=store ; act_get=get} + + + +module type S = + sig + type primitive + val eqint : primitive + val neint : primitive + val leint : primitive + val ltint : primitive + val geint : primitive + val gtint : primitive + type act + + val bind : act -> (act -> act) -> act + val make_offset : act -> int -> act + val make_prim : primitive -> act list -> act + val make_isout : act -> act -> act + val make_isin : act -> act -> act + val make_if : act -> act -> act -> act + val make_switch : + act -> int array -> act array -> act + end + +(* The module will ``produce good code for the case statement'' *) +(* + Adaptation of + R.L. Berstein + ``Producing good code for the case statement'' + Sofware Practice and Experience, 15(10) (1985) + and + D.L. Spuler + ``Two-Way Comparison Search Trees, a Generalisation of Binary Search Trees + and Split Trees'' + ``Compiler Code Generation for Multiway Branch Statement as + a Static Search Problem'' + Technical Reports, James Cook University +*) +(* + Main adaptation is considering interval tests + (implemented as one addition + one unsigned test and branch) + which leads to exhaustive search for finding the optimal + test sequence in small cases and heuristics otherwise. +*) +module Make (Arg : S) = + struct + + type 'a inter = + {cases : (int * int * int) array ; + actions : 'a array} + +type 'a t_ctx = {off : int ; arg : 'a} + +let cut = ref 8 +and more_cut = ref 16 + +let pint chan i = + if i = min_int then Printf.fprintf chan "-oo" + else if i=max_int then Printf.fprintf chan "oo" + else Printf.fprintf chan "%d" i + +let pcases chan cases = + for i =0 to Array.length cases-1 do + let l,h,act = cases.(i) in + if l=h then + Printf.fprintf chan "%d:%d " l act + else + Printf.fprintf chan "%a..%a:%d " pint l pint h act + done + + let prerr_inter i = Printf.fprintf stderr + "cases=%a" pcases i.cases + +let get_act cases i = + let _,_,r = cases.(i) in + r +and get_low cases i = + let r,_,_ = cases.(i) in + r + +type ctests = { + mutable n : int ; + mutable ni : int ; + } + +let too_much = {n=max_int ; ni=max_int} + +let ptests chan {n=n ; ni=ni} = + Printf.fprintf chan "{n=%d ; ni=%d}" n ni + +let pta chan t = + for i =0 to Array.length t-1 do + Printf.fprintf chan "%d: %a\n" i ptests t.(i) + done + +let count_tests s = + let r = + Array.init + (Array.length s.actions) + (fun _ -> {n=0 ; ni=0 }) in + let c = s.cases in + let imax = Array.length c-1 in + for i=0 to imax do + let l,h,act = c.(i) in + let x = r.(act) in + x.n <- x.n+1 ; + if l < h && i<> 0 && i<>imax then + x.ni <- x.ni+1 ; + done ; + r + + +let less_tests c1 c2 = + if c1.n < c2.n then + true + else if c1.n = c2.n then begin + if c1.ni < c2.ni then + true + else + false + end else + false + +and eq_tests c1 c2 = c1.n = c2.n && c1.ni=c2.ni + +let min_tests c1 c2 = if less_tests c1 c2 then c1 else c2 + +let less2tests (c1,d1) (c2,d2) = + if eq_tests c1 c2 then + less_tests d1 d2 + else + less_tests c1 c2 + +let add_test t1 t2 = + t1.n <- t1.n + t2.n ; + t1.ni <- t1.ni + t2.ni ; + +type t_ret = Inter of int * int | Sep of int | No + +let pret chan = function + | Inter (i,j)-> Printf.fprintf chan "Inter %d %d" i j + | Sep i -> Printf.fprintf chan "Sep %d" i + | No -> Printf.fprintf chan "No" + +let coupe cases i = + let l,_,_ = cases.(i) in + l, + Array.sub cases 0 i, + Array.sub cases i (Array.length cases-i) + + +let case_append c1 c2 = + let len1 = Array.length c1 + and len2 = Array.length c2 in + match len1,len2 with + | 0,_ -> c2 + | _,0 -> c1 + | _,_ -> + let l1,h1,act1 = c1.(Array.length c1-1) + and l2,h2,act2 = c2.(0) in + if act1 = act2 then + let r = Array.create (len1+len2-1) c1.(0) in + for i = 0 to len1-2 do + r.(i) <- c1.(i) + done ; + + let l = + if len1-2 >= 0 then begin + let _,h,_ = r.(len1-2) in + if h+1 < l1 then + h+1 + else + l1 + end else + l1 + and h = + if 1 < len2-1 then begin + let l,_,_ = c2.(1) in + if h2+1 < l then + l-1 + else + h2 + end else + h2 in + r.(len1-1) <- (l,h,act1) ; + for i=1 to len2-1 do + r.(len1-1+i) <- c2.(i) + done ; + r + else if h1 > l1 then + let r = Array.create (len1+len2) c1.(0) in + for i = 0 to len1-2 do + r.(i) <- c1.(i) + done ; + r.(len1-1) <- (l1,l2-1,act1) ; + for i=0 to len2-1 do + r.(len1+i) <- c2.(i) + done ; + r + else if h2 > l2 then + let r = Array.create (len1+len2) c1.(0) in + for i = 0 to len1-1 do + r.(i) <- c1.(i) + done ; + r.(len1) <- (h1+1,h2,act2) ; + for i=1 to len2-1 do + r.(len1+i) <- c2.(i) + done ; + r + else + Array.append c1 c2 + + +let coupe_inter i j cases = + let lcases = Array.length cases in + let low,_,_ = cases.(i) + and _,high,_ = cases.(j) in + low,high, + Array.sub cases i (j-i+1), + case_append (Array.sub cases 0 i) (Array.sub cases (j+1) (lcases-(j+1))) + +type kind = Kvalue of int | Kinter of int | Kempty + +let pkind chan = function + | Kvalue i ->Printf.fprintf chan "V%d" i + | Kinter i -> Printf.fprintf chan "I%d" i + | Kempty -> Printf.fprintf chan "E" + +let rec pkey chan = function + | [] -> () + | [k] -> pkind chan k + | k::rem -> + Printf.fprintf chan "%a %a" pkey rem pkind k + +let t = Hashtbl.create 17 + +let make_key cases = + let seen = ref [] + and count = ref 0 in + let rec got_it act = function + | [] -> + seen := (act,!count):: !seen ; + let r = !count in + incr count ; + r + | (act0,index) :: rem -> + if act0 = act then + index + else + got_it act rem in + + let make_one l h act = + if l=h then + Kvalue (got_it act !seen) + else + Kinter (got_it act !seen) in + + let rec make_rec i pl = + if i < 0 then + [] + else + let l,h,act = cases.(i) in + if pl = h+1 then + make_one l h act::make_rec (i-1) l + else + Kempty::make_one l h act::make_rec (i-1) l in + + let l,h,act = cases.(Array.length cases-1) in + make_one l h act::make_rec (Array.length cases-2) l + + + let same_act t = + let len = Array.length t in + let a = get_act t (len-1) in + let rec do_rec i = + if i < 0 then true + else + let b = get_act t i in + b=a && do_rec (i-1) in + do_rec (len-2) + + +(* + Intervall test x in [l,h] works by checking x-l in [0,h-l] + * This may be false for arithmetic modulo 2^31 + * Subtracting l may change the relative ordering of values + and invalid the invariant that matched values are given in + increasing order + + To avoid this, interval check is allowed only when the + integers indeed present in the whole case interval are + in [-2^16 ; 2^16] + + This condition is checked by zyva +*) + +let inter_limit = 1 lsl 16 + +let ok_inter = ref false + +let rec opt_count top cases = + let key = make_key cases in + try + let r = Hashtbl.find t key in + r + with + | Not_found -> + let r = + let lcases = Array.length cases in + match lcases with + | 0 -> assert false + | _ when same_act cases -> No, ({n=0; ni=0},{n=0; ni=0}) + | _ -> + if lcases < !cut then + enum top cases + else if lcases < !more_cut then + heuristic top cases + else + divide top cases in + Hashtbl.add t key r ; + r + +and divide top cases = + let lcases = Array.length cases in + let m = lcases/2 in + let _,left,right = coupe cases m in + let ci = {n=1 ; ni=0} + and cm = {n=1 ; ni=0} + and _,(cml,cleft) = opt_count false left + and _,(cmr,cright) = opt_count false right in + add_test ci cleft ; + add_test ci cright ; + if less_tests cml cmr then + add_test cm cmr + else + add_test cm cml ; + Sep m,(cm, ci) + +and heuristic top cases = + let lcases = Array.length cases in + + let sep,csep = divide false cases + + and inter,cinter = + if !ok_inter then begin + let _,_,act0 = cases.(0) + and _,_,act1 = cases.(lcases-1) in + if act0 = act1 then begin + let low, high, inside, outside = coupe_inter 1 (lcases-2) cases in + let _,(cmi,cinside) = opt_count false inside + and _,(cmo,coutside) = opt_count false outside + and cmij = {n=1 ; ni=(if low=high then 0 else 1)} + and cij = {n=1 ; ni=(if low=high then 0 else 1)} in + add_test cij cinside ; + add_test cij coutside ; + if less_tests cmi cmo then + add_test cmij cmo + else + add_test cmij cmi ; + Inter (1,lcases-2),(cmij,cij) + end else + Inter (-1,-1),(too_much, too_much) + end else + Inter (-1,-1),(too_much, too_much) in + if less2tests csep cinter then + sep,csep + else + inter,cinter + + +and enum top cases = + let lcases = Array.length cases in + let lim, with_sep = + let best = ref (-1) and best_cost = ref (too_much,too_much) in + + for i = 1 to lcases-(1) do + let _,left,right = coupe cases i in + let ci = {n=1 ; ni=0} + and cm = {n=1 ; ni=0} + and _,(cml,cleft) = opt_count false left + and _,(cmr,cright) = opt_count false right in + add_test ci cleft ; + add_test ci cright ; + if less_tests cml cmr then + add_test cm cmr + else + add_test cm cml ; + + if + less2tests (cm,ci) !best_cost + then begin + if top then + Printf.fprintf stderr "Get it: %d\n" i ; + best := i ; + best_cost := (cm,ci) + end + done ; + !best, !best_cost in + + let ilow, ihigh, with_inter = + if not !ok_inter then + let rlow = ref (-1) and rhigh = ref (-1) + and best_cost= ref (too_much,too_much) in + for i=1 to lcases-2 do + let low, high, inside, outside = coupe_inter i i cases in + if low=high then begin + let _,(cmi,cinside) = opt_count false inside + and _,(cmo,coutside) = opt_count false outside + and cmij = {n=1 ; ni=0} + and cij = {n=1 ; ni=0} in + add_test cij cinside ; + add_test cij coutside ; + if less_tests cmi cmo then + add_test cmij cmo + else + add_test cmij cmi ; + if less2tests (cmij,cij) !best_cost then begin + rlow := i ; + rhigh := i ; + best_cost := (cmij,cij) + end + end + done ; + !rlow, !rhigh, !best_cost + else + let rlow = ref (-1) and rhigh = ref (-1) + and best_cost= ref (too_much,too_much) in + for i=1 to lcases-2 do + for j=i to lcases-2 do + let low, high, inside, outside = coupe_inter i j cases in + let _,(cmi,cinside) = opt_count false inside + and _,(cmo,coutside) = opt_count false outside + and cmij = {n=1 ; ni=(if low=high then 0 else 1)} + and cij = {n=1 ; ni=(if low=high then 0 else 1)} in + add_test cij cinside ; + add_test cij coutside ; + if less_tests cmi cmo then + add_test cmij cmo + else + add_test cmij cmi ; + if less2tests (cmij,cij) !best_cost then begin + rlow := i ; + rhigh := j ; + best_cost := (cmij,cij) + end + done + done ; + !rlow, !rhigh, !best_cost in + let r = ref (Inter (ilow,ihigh)) and rc = ref with_inter in + if less2tests with_sep !rc then begin + r := Sep lim ; rc := with_sep + end ; + !r, !rc + + let make_if_test konst test arg i ifso ifnot = + Arg.make_if + (Arg.make_prim test [arg ; konst i]) + ifso ifnot + + let make_if_lt konst arg i ifso ifnot = match i with + | 1 -> + make_if_test konst Arg.leint arg 0 ifso ifnot + | _ -> + make_if_test konst Arg.ltint arg i ifso ifnot + + and make_if_le konst arg i ifso ifnot = match i with + | -1 -> + make_if_test konst Arg.ltint arg 0 ifso ifnot + | _ -> + make_if_test konst Arg.leint arg i ifso ifnot + + and make_if_gt konst arg i ifso ifnot = match i with + | -1 -> + make_if_test konst Arg.geint arg 0 ifso ifnot + | _ -> + make_if_test konst Arg.gtint arg i ifso ifnot + + and make_if_ge konst arg i ifso ifnot = match i with + | 1 -> + make_if_test konst Arg.gtint arg 0 ifso ifnot + | _ -> + make_if_test konst Arg.geint arg i ifso ifnot + + and make_if_eq konst arg i ifso ifnot = + make_if_test konst Arg.eqint arg i ifso ifnot + + and make_if_ne konst arg i ifso ifnot = + make_if_test konst Arg.neint arg i ifso ifnot + + let do_make_if_out h arg ifso ifno = + Arg.make_if (Arg.make_isout h arg) ifso ifno + + let make_if_out konst ctx l d mk_ifso mk_ifno = match l with + | 0 -> + do_make_if_out + (konst d) ctx.arg (mk_ifso ctx) (mk_ifno ctx) + | _ -> + Arg.bind + (Arg.make_offset ctx.arg (-l)) + (fun arg -> + let ctx = {off= (-l+ctx.off) ; arg=arg} in + do_make_if_out + (konst d) arg (mk_ifso ctx) (mk_ifno ctx)) + + let do_make_if_in h arg ifso ifno = + Arg.make_if (Arg.make_isin h arg) ifso ifno + + let make_if_in konst ctx l d mk_ifso mk_ifno = match l with + | 0 -> + do_make_if_in + (konst d) ctx.arg (mk_ifso ctx) (mk_ifno ctx) + | _ -> + Arg.bind + (Arg.make_offset ctx.arg (-l)) + (fun arg -> + let ctx = {off= (-l+ctx.off) ; arg=arg} in + do_make_if_in + (konst d) arg (mk_ifso ctx) (mk_ifno ctx)) + + + let rec c_test konst ctx ({cases=cases ; actions=actions} as s) = + let lcases = Array.length cases in + assert(lcases > 0) ; + if lcases = 1 then + actions.(get_act cases 0) ctx + else begin + + let w,c = opt_count false cases in +(* + Printf.fprintf stderr + "off=%d tactic=%a for %a\n" + ctx.off pret w pcases cases ; + *) + match w with + | No -> actions.(get_act cases 0) ctx + | Inter (i,j) -> + let low,high,inside, outside = coupe_inter i j cases in + let _,(cinside,_) = opt_count false inside + and _,(coutside,_) = opt_count false outside in +(* Costs are retrieved to put the code with more remaining tests + in the privileged (positive) branch of ``if'' *) + if low=high then begin + if less_tests coutside cinside then + make_if_eq + konst ctx.arg + (low+ctx.off) + (c_test konst ctx {s with cases=inside}) + (c_test konst ctx {s with cases=outside}) + else + make_if_ne + konst ctx.arg + (low+ctx.off) + (c_test konst ctx {s with cases=outside}) + (c_test konst ctx {s with cases=inside}) + end else begin + if less_tests coutside cinside then + make_if_in + konst ctx + (low+ctx.off) + (high-low) + (fun ctx -> c_test konst ctx {s with cases=inside}) + (fun ctx -> c_test konst ctx {s with cases=outside}) + else + make_if_out + konst ctx + (low+ctx.off) + (high-low) + (fun ctx -> c_test konst ctx {s with cases=outside}) + (fun ctx -> c_test konst ctx {s with cases=inside}) + end + | Sep i -> + let lim,left,right = coupe cases i in + let _,(cleft,_) = opt_count false left + and _,(cright,_) = opt_count false right in + let left = {s with cases=left} + and right = {s with cases=right} in + + if i=1 && (lim+ctx.off)=1 && get_low cases 0+ctx.off=0 then + make_if_ne konst + ctx.arg 0 + (c_test konst ctx right) (c_test konst ctx left) + else if less_tests cright cleft then + make_if_lt konst + ctx.arg (lim+ctx.off) + (c_test konst ctx left) (c_test konst ctx right) + else + make_if_ge konst + ctx.arg (lim+ctx.off) + (c_test konst ctx right) (c_test konst ctx left) + + end + + +(* Minimal density of switches *) +let theta = ref 0.33333 + +(* Minmal number of tests to make a switch *) +let switch_min = ref 3 + +(* Particular case 0, 1, 2 *) +let particular_case cases i j = + j-i = 2 && + (let l1,h1,act1 = cases.(i) + and l2,h2,act2 = cases.(i+1) + and l3,h3,act3 = cases.(i+2) in + l1+1=l2 && l2+1=l3 && l3=h3 && + act1 <> act3) + +let approx_count cases i j n_actions = + let l = j-i+1 in + if l < !cut then + let _,(_,{n=ntests}) = opt_count false (Array.sub cases i l) in + ntests + else + l-1 + +(* Sends back a boolean that says whether is switch is worth or not *) + +let dense {cases=cases ; actions=actions} i j = + if i=j then true + else + let l,_,_ = cases.(i) + and _,h,_ = cases.(j) in + let ntests = approx_count cases i j (Array.length actions) in +(* + (ntests+1) >= theta * (h-l+1) +*) + particular_case cases i j || + (ntests >= !switch_min && + float_of_int ntests +. 1.0 >= + !theta *. (float_of_int h -. float_of_int l +. 1.0)) + +(* Compute clusters by dynamic programming + Adaptation of the correction to Bernstein + ``Correction to `Producing Good Code for the Case Statement' '' + S.K. Kannan and T.A. Proebsting + Software Practice and Exprience Vol. 24(2) 233 (Feb 1994) +*) + +let comp_clusters ({cases=cases ; actions=actions} as s) = + let len = Array.length cases in + let min_clusters = Array.create len max_int + and k = Array.create len 0 in + let get_min i = if i < 0 then 0 else min_clusters.(i) in + + for i = 0 to len-1 do + for j = 0 to i do + if + dense s j i && + get_min (j-1) + 1 < min_clusters.(i) + then begin + k.(i) <- j ; + min_clusters.(i) <- get_min (j-1) + 1 + end + done ; + done ; + min_clusters.(len-1),k + +(* Assume j > i *) +let make_switch {cases=cases ; actions=actions} i j = + let ll,_,_ = cases.(i) + and _,hh,_ = cases.(j) in + let tbl = Array.create (hh-ll+1) 0 + and t = Hashtbl.create 17 + and index = ref 0 in + let get_index act = + try + Hashtbl.find t act + with + | Not_found -> + let i = !index in + incr index ; + Hashtbl.add t act i ; + i in + + for k=i to j do + let l,h,act = cases.(k) in + let index = get_index act in + for kk=l-ll to h-ll do + tbl.(kk) <- index + done + done ; + let acts = Array.create !index actions.(0) in + Hashtbl.iter + (fun act i -> acts.(i) <- actions.(act)) + t ; + (fun ctx -> + match -ll-ctx.off with + | 0 -> Arg.make_switch ctx.arg tbl acts + | _ -> + Arg.bind + (Arg.make_offset ctx.arg (-ll-ctx.off)) + (fun arg -> Arg.make_switch arg tbl acts)) + + +let make_clusters ({cases=cases ; actions=actions} as s) n_clusters k = + let len = Array.length cases in + let r = Array.create n_clusters (0,0,0) + and t = Hashtbl.create 17 + and index = ref 0 + and bidon = ref (Array.length actions) in + let get_index act = + try + let i,_ = Hashtbl.find t act in + i + with + | Not_found -> + let i = !index in + incr index ; + Hashtbl.add + t act + (i,(fun _ -> actions.(act))) ; + i + and add_index act = + let i = !index in + incr index ; + incr bidon ; + Hashtbl.add t !bidon (i,act) ; + i in + + let rec zyva j ir = + let i = k.(j) in + begin if i=j then + let l,h,act = cases.(i) in + r.(ir) <- (l,h,get_index act) + else (* assert i < j *) + let l,_,_ = cases.(i) + and _,h,_ = cases.(j) in + r.(ir) <- (l,h,add_index (make_switch s i j)) + end ; + if i > 0 then zyva (i-1) (ir-1) in + + zyva (len-1) (n_clusters-1) ; + let acts = Array.create !index (fun _ -> assert false) in + Hashtbl.iter (fun _ (i,act) -> acts.(i) <- act) t ; + {cases = r ; actions = acts} +;; + + +let zyva (low,high) konst arg cases actions = + let old_ok = !ok_inter in + ok_inter := (abs low <= inter_limit && abs high <= inter_limit) ; + if !ok_inter <> old_ok then Hashtbl.clear t ; + + let s = {cases=cases ; actions=actions} in +(* + Printf.eprintf "ZYVA: %b\n" !ok_inter ; + pcases stderr cases ; + prerr_endline "" ; +*) + let n_clusters,k = comp_clusters s in + let clusters = make_clusters s n_clusters k in + let r = c_test konst {arg=arg ; off=0} clusters in + r + + + +and test_sequence konst arg cases actions = + let old_ok = !ok_inter in + ok_inter := false ; + if !ok_inter <> old_ok then Hashtbl.clear t ; + let s = + {cases=cases ; + actions=Array.map (fun act -> (fun _ -> act)) actions} in +(* + Printf.eprintf "SEQUENCE: %b\n" !ok_inter ; + pcases stderr cases ; + prerr_endline "" ; +*) + let r = c_test konst {arg=arg ; off=0} s in + r +;; + +end diff --git a/bytecomp/switch.mli b/bytecomp/switch.mli new file mode 100644 index 0000000..73799da --- /dev/null +++ b/bytecomp/switch.mli @@ -0,0 +1,82 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* + This module transforms generic switches in combinations + of if tests and switches. +*) + +(* For detecting action sharing, object style *) + +type 'a t_store = + {act_get : unit -> 'a array ; act_store : 'a -> int} +val mk_store : ('a -> 'a -> bool) -> 'a t_store + +(* Arguments to the Make functor *) +module type S = + sig + (* type of basic tests *) + type primitive + (* basic tests themselves *) + val eqint : primitive + val neint : primitive + val leint : primitive + val ltint : primitive + val geint : primitive + val gtint : primitive + (* type of actions *) + type act + + (* Various constructors, for making a binder, + adding one integer, etc. *) + val bind : act -> (act -> act) -> act + val make_offset : act -> int -> act + val make_prim : primitive -> act list -> act + val make_isout : act -> act -> act + val make_isin : act -> act -> act + val make_if : act -> act -> act -> act + (* construct an actual switch : + make_switch arg cases acts + NB: cases is in the value form *) + val make_switch : + act -> int array -> act array -> act + end + + +(* + Make.zyva mk_const arg low high cases actions where + - mk_const takes an integer sends a constant action. + - arg is the argument of the switch. + - low, high are the interval limits. + - cases is a list of sub-interval and action indices + - actions is an array of actions. + + All these arguments specify a switch construct and zyva + returns an action that performs the switch, +*) +module Make : + functor (Arg : S) -> + sig + val zyva : + (int * int) -> + (int -> Arg.act) -> + Arg.act -> + (int * int * int) array -> + Arg.act array -> + Arg.act + val test_sequence : + (int -> Arg.act) -> + Arg.act -> + (int * int * int) array -> + Arg.act array -> + Arg.act + end diff --git a/bytecomp/symtable.ml b/bytecomp/symtable.ml new file mode 100644 index 0000000..188d7f6 --- /dev/null +++ b/bytecomp/symtable.ml @@ -0,0 +1,378 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: symtable.ml,v 1.39 2006-05-11 15:50:53 xleroy Exp $ *) + +(* To assign numbers to globals and primitives *) + +open Misc +open Asttypes +open Lambda +open Cmo_format + +(* Functions for batch linking *) + +type error = + Undefined_global of string + | Unavailable_primitive of string + | Wrong_vm of string + | Uninitialized_global of string + +exception Error of error + +(* Tables for numbering objects *) + +type 'a numtable = + { num_cnt: int; (* The next number *) + num_tbl: ('a, int) Tbl.t } (* The table of already numbered objects *) + +let empty_numtable = { num_cnt = 0; num_tbl = Tbl.empty } + +let find_numtable nt key = + Tbl.find key nt.num_tbl + +let enter_numtable nt key = + let n = !nt.num_cnt in + nt := { num_cnt = n + 1; num_tbl = Tbl.add key n !nt.num_tbl }; + n + +let incr_numtable nt = + let n = !nt.num_cnt in + nt := { num_cnt = n + 1; num_tbl = !nt.num_tbl }; + n + +(* Global variables *) + +let global_table = ref(empty_numtable : Ident.t numtable) +and literal_table = ref([] : (int * structured_constant) list) + +let slot_for_getglobal id = + try + find_numtable !global_table id + with Not_found -> + raise(Error(Undefined_global(Ident.name id))) + +let slot_for_setglobal id = + enter_numtable global_table id + +let slot_for_literal cst = + let n = incr_numtable global_table in + literal_table := (n, cst) :: !literal_table; + n + +(* The C primitives *) + +let c_prim_table = ref(empty_numtable : string numtable) + +let set_prim_table name = + ignore(enter_numtable c_prim_table name) + +let num_of_prim name = + try + find_numtable !c_prim_table name + with Not_found -> + if !Clflags.custom_runtime then + enter_numtable c_prim_table name + else begin + let symb = + try Dll.find_primitive name + with Not_found -> raise(Error(Unavailable_primitive name)) in + let num = enter_numtable c_prim_table name in + Dll.synchronize_primitive num symb; + num + end + +let require_primitive name = + if name.[0] <> '%' then ignore(num_of_prim name) + +let all_primitives () = + let prim = Array.create !c_prim_table.num_cnt "" in + Tbl.iter (fun name number -> prim.(number) <- name) !c_prim_table.num_tbl; + prim + +let data_primitive_names () = + let prim = all_primitives() in + let b = Buffer.create 512 in + for i = 0 to Array.length prim - 1 do + Buffer.add_string b prim.(i); Buffer.add_char b '\000' + done; + Buffer.contents b + +let output_primitive_names outchan = + output_string outchan (data_primitive_names()) + +open Printf + +let output_primitive_table outchan = + let prim = all_primitives() in + fprintf outchan "\ + #ifdef __cplusplus\n\ + extern \"C\" {\n\ + #endif\n"; + for i = 0 to Array.length prim - 1 do + fprintf outchan "extern long %s();\n" prim.(i) + done; + fprintf outchan "typedef long (*primitive)();\n"; + fprintf outchan "primitive caml_builtin_cprim[] = {\n"; + for i = 0 to Array.length prim - 1 do + fprintf outchan " %s,\n" prim.(i) + done; + fprintf outchan " (primitive) 0 };\n"; + fprintf outchan "char * caml_names_of_builtin_cprim[] = {\n"; + for i = 0 to Array.length prim - 1 do + fprintf outchan " \"%s\",\n" prim.(i) + done; + fprintf outchan " (char *) 0 };\n"; + fprintf outchan "\ + #ifdef __cplusplus\n\ + }\n\ + #endif\n" + +(* Initialization for batch linking *) + +let init () = + (* Enter the predefined exceptions *) + Array.iter + (fun name -> + let id = + try List.assoc name Predef.builtin_values + with Not_found -> fatal_error "Symtable.init" in + let c = slot_for_setglobal id in + let cst = Const_block(0, [Const_base(Const_string name)]) in + literal_table := (c, cst) :: !literal_table) + Runtimedef.builtin_exceptions; + (* Initialize the known C primitives *) + if String.length !Clflags.use_prims > 0 then begin + let ic = open_in !Clflags.use_prims in + try + while true do + set_prim_table (input_line ic) + done + with End_of_file -> close_in ic + | x -> close_in ic; raise x + end else if String.length !Clflags.use_runtime > 0 then begin + let primfile = Filename.temp_file "camlprims" "" in + try + if Sys.command(Printf.sprintf "%s -p > %s" + !Clflags.use_runtime primfile) <> 0 + then raise(Error(Wrong_vm !Clflags.use_runtime)); + let ic = open_in primfile in + try + while true do + set_prim_table (input_line ic) + done + with End_of_file -> close_in ic; remove_file primfile + | x -> close_in ic; raise x + with x -> remove_file primfile; raise x + end else begin + Array.iter set_prim_table Runtimedef.builtin_primitives + end + +(* Relocate a block of object bytecode *) + +(* Must use the unsafe String.set here because the block may be + a "fake" string as returned by Meta.static_alloc. *) + +let patch_int buff pos n = + String.unsafe_set buff pos (Char.unsafe_chr n); + String.unsafe_set buff (pos + 1) (Char.unsafe_chr (n asr 8)); + String.unsafe_set buff (pos + 2) (Char.unsafe_chr (n asr 16)); + String.unsafe_set buff (pos + 3) (Char.unsafe_chr (n asr 24)) + +let patch_object buff patchlist = + List.iter + (function + (Reloc_literal sc, pos) -> + patch_int buff pos (slot_for_literal sc) + | (Reloc_getglobal id, pos) -> + patch_int buff pos (slot_for_getglobal id) + | (Reloc_setglobal id, pos) -> + patch_int buff pos (slot_for_setglobal id) + | (Reloc_primitive name, pos) -> + patch_int buff pos (num_of_prim name)) + patchlist + +(* Translate structured constants *) + +let rec transl_const = function + Const_base(Const_int i) -> Obj.repr i + | Const_base(Const_char c) -> Obj.repr c + | Const_base(Const_string s) -> Obj.repr s + | Const_base(Const_float f) -> Obj.repr (float_of_string f) + | Const_base(Const_int32 i) -> Obj.repr i + | Const_base(Const_int64 i) -> Obj.repr i + | Const_base(Const_nativeint i) -> Obj.repr i + | Const_pointer i -> Obj.repr i + | Const_immstring s -> Obj.repr s + | Const_block(tag, fields) -> + let block = Obj.new_block tag (List.length fields) in + let pos = ref 0 in + List.iter + (fun c -> Obj.set_field block !pos (transl_const c); incr pos) + fields; + block + | Const_float_array fields -> + Obj.repr(Array.of_list(List.map (fun f -> float_of_string f) fields)) + +(* Build the initial table of globals *) + +let initial_global_table () = + let glob = Array.create !global_table.num_cnt (Obj.repr 0) in + List.iter + (fun (slot, cst) -> glob.(slot) <- transl_const cst) + !literal_table; + literal_table := []; + glob + +(* Save the table of globals *) + +let output_global_map oc = + output_value oc !global_table + +let data_global_map () = + Obj.repr !global_table + +(* Functions for toplevel use *) + +(* Update the in-core table of globals *) + +let update_global_table () = + let ng = !global_table.num_cnt in + if ng > Array.length(Meta.global_data()) then Meta.realloc_global_data ng; + let glob = Meta.global_data() in + List.iter + (fun (slot, cst) -> glob.(slot) <- transl_const cst) + !literal_table; + literal_table := [] + +(* Recover data for toplevel initialization. Data can come either from + executable file (normal case) or from linked-in data (-output-obj). *) + +type section_reader = { + read_string: string -> string; + read_struct: string -> Obj.t; + close_reader: unit -> unit +} + +let read_sections () = + try + let sections = Meta.get_section_table () in + { read_string = + (fun name -> (Obj.magic(List.assoc name sections) : string)); + read_struct = + (fun name -> List.assoc name sections); + close_reader = + (fun () -> ()) } + with Not_found -> + let ic = open_in_bin Sys.executable_name in + Bytesections.read_toc ic; + { read_string = Bytesections.read_section_string ic; + read_struct = Bytesections.read_section_struct ic; + close_reader = fun () -> close_in ic } + +(* Initialize the linker for toplevel use *) + +let init_toplevel () = + try + let sect = read_sections () in + (* Locations of globals *) + global_table := (Obj.magic (sect.read_struct "SYMB") : Ident.t numtable); + (* Primitives *) + let prims = sect.read_string "PRIM" in + c_prim_table := empty_numtable; + let pos = ref 0 in + while !pos < String.length prims do + let i = String.index_from prims !pos '\000' in + set_prim_table (String.sub prims !pos (i - !pos)); + pos := i + 1 + done; + (* DLL initialization *) + let dllpath = try sect.read_string "DLPT" with Not_found -> "" in + Dll.init_toplevel dllpath; + (* Recover CRC infos for interfaces *) + let crcintfs = + try (Obj.magic (sect.read_struct "CRCS") : (string * Digest.t) list) + with Not_found -> [] in + (* Done *) + sect.close_reader(); + crcintfs + with Bytesections.Bad_magic_number | Not_found | Failure _ -> + fatal_error "Toplevel bytecode executable is corrupted" + +(* Find the value of a global identifier *) + +let get_global_position id = slot_for_getglobal id + +let get_global_value id = + (Meta.global_data()).(slot_for_getglobal id) +let assign_global_value id v = + (Meta.global_data()).(slot_for_getglobal id) <- v + +(* Check that all globals referenced in the given patch list + have been initialized already *) + +let check_global_initialized patchlist = + (* First determine the globals we will define *) + let defined_globals = + List.fold_left + (fun accu rel -> + match rel with + (Reloc_setglobal id, pos) -> id :: accu + | _ -> accu) + [] patchlist in + (* Then check that all referenced, not defined globals have a value *) + let check_reference = function + (Reloc_getglobal id, pos) -> + if not (List.mem id defined_globals) + && Obj.is_int (get_global_value id) + then raise (Error(Uninitialized_global(Ident.name id))) + | _ -> () in + List.iter check_reference patchlist + +(* Save and restore the current state *) + +type global_map = Ident.t numtable + +let current_state () = !global_table + +let restore_state st = global_table := st + +let hide_additions st = + if st.num_cnt > !global_table.num_cnt then + fatal_error "Symtable.hide_additions"; + global_table := + { num_cnt = !global_table.num_cnt; + num_tbl = st.num_tbl } + +(* "Filter" the global map according to some predicate. + Used to expunge the global map for the toplevel. *) + +let filter_global_map p gmap = + let newtbl = ref Tbl.empty in + Tbl.iter + (fun id num -> if p id then newtbl := Tbl.add id num !newtbl) + gmap.num_tbl; + {num_cnt = gmap.num_cnt; num_tbl = !newtbl} + +(* Error report *) + +open Format + +let report_error ppf = function + | Undefined_global s -> + fprintf ppf "Reference to undefined global `%s'" s + | Unavailable_primitive s -> + fprintf ppf "The external function `%s' is not available" s + | Wrong_vm s -> + fprintf ppf "Cannot find or execute the runtime system %s" s + | Uninitialized_global s -> + fprintf ppf "The value of the global `%s' is not yet computed" s diff --git a/bytecomp/symtable.mli b/bytecomp/symtable.mli new file mode 100644 index 0000000..d90b34b --- /dev/null +++ b/bytecomp/symtable.mli @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: symtable.mli,v 1.15 2006-05-11 15:50:53 xleroy Exp $ *) + +(* Assign locations and numbers to globals and primitives *) + +open Cmo_format + +(* Functions for batch linking *) + +val init: unit -> unit +val patch_object: string -> (reloc_info * int) list -> unit +val require_primitive: string -> unit +val initial_global_table: unit -> Obj.t array +val output_global_map: out_channel -> unit +val output_primitive_names: out_channel -> unit +val output_primitive_table: out_channel -> unit +val data_global_map: unit -> Obj.t +val data_primitive_names: unit -> string + +(* Functions for the toplevel *) + +val init_toplevel: unit -> (string * Digest.t) list +val update_global_table: unit -> unit +val get_global_value: Ident.t -> Obj.t +val assign_global_value: Ident.t -> Obj.t -> unit +val get_global_position: Ident.t -> int +val check_global_initialized: (reloc_info * int) list -> unit + +type global_map + +val current_state: unit -> global_map +val restore_state: global_map -> unit +val hide_additions: global_map -> unit +val filter_global_map: (Ident.t -> bool) -> global_map -> global_map + +(* Error report *) + +type error = + Undefined_global of string + | Unavailable_primitive of string + | Wrong_vm of string + | Uninitialized_global of string + +exception Error of error + +open Format + +val report_error: formatter -> error -> unit diff --git a/bytecomp/translclass.ml b/bytecomp/translclass.ml new file mode 100644 index 0000000..c1b169b --- /dev/null +++ b/bytecomp/translclass.ml @@ -0,0 +1,821 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translclass.ml,v 1.45 2008-12-03 18:09:09 doligez Exp $ *) + +open Misc +open Asttypes +open Types +open Typedtree +open Lambda +open Translobj +open Translcore + +(* XXX Rajouter des evenements... *) + +type error = Illegal_class_expr | Tags of label * label + +exception Error of Location.t * error + +let lfunction params body = + if params = [] then body else + match body with + Lfunction (Curried, params', body') -> + Lfunction (Curried, params @ params', body') + | _ -> + Lfunction (Curried, params, body) + +let lapply func args loc = + match func with + Lapply(func', args', _) -> + Lapply(func', args' @ args, loc) + | _ -> + Lapply(func, args, loc) + +let mkappl (func, args) = Lapply (func, args, Location.none);; + +let lsequence l1 l2 = + if l2 = lambda_unit then l1 else Lsequence(l1, l2) + +let lfield v i = Lprim(Pfield i, [Lvar v]) + +let transl_label l = share (Const_immstring l) + +let rec transl_meth_list lst = + if lst = [] then Lconst (Const_pointer 0) else + share (Const_block + (0, List.map (fun lab -> Const_immstring lab) lst)) + +let set_inst_var obj id expr = + let kind = if Typeopt.maybe_pointer expr then Paddrarray else Pintarray in + Lprim(Parraysetu kind, [Lvar obj; Lvar id; transl_exp expr]) + +let copy_inst_var obj id expr templ offset = + let kind = if Typeopt.maybe_pointer expr then Paddrarray else Pintarray in + let id' = Ident.create (Ident.name id) in + Llet(Strict, id', Lprim (Pidentity, [Lvar id]), + Lprim(Parraysetu kind, + [Lvar obj; Lvar id'; + Lprim(Parrayrefu kind, [Lvar templ; Lprim(Paddint, + [Lvar id'; + Lvar offset])])])) + +let transl_val tbl create name = + mkappl (oo_prim (if create then "new_variable" else "get_variable"), + [Lvar tbl; transl_label name]) + +let transl_vals tbl create strict vals rem = + List.fold_right + (fun (name, id) rem -> + Llet(strict, id, transl_val tbl create name, rem)) + vals rem + +let meths_super tbl meths inh_meths = + List.fold_right + (fun (nm, id) rem -> + try + (nm, id, + mkappl(oo_prim "get_method", [Lvar tbl; Lvar (Meths.find nm meths)])) + :: rem + with Not_found -> rem) + inh_meths [] + +let bind_super tbl (vals, meths) cl_init = + transl_vals tbl false StrictOpt vals + (List.fold_right (fun (nm, id, def) rem -> Llet(StrictOpt, id, def, rem)) + meths cl_init) + +let create_object cl obj init = + let obj' = Ident.create "self" in + let (inh_init, obj_init, has_init) = init obj' in + if obj_init = lambda_unit then + (inh_init, + mkappl (oo_prim (if has_init then "create_object_and_run_initializers" + else"create_object_opt"), + [obj; Lvar cl])) + else begin + (inh_init, + Llet(Strict, obj', + mkappl (oo_prim "create_object_opt", [obj; Lvar cl]), + Lsequence(obj_init, + if not has_init then Lvar obj' else + mkappl (oo_prim "run_initializers_opt", + [obj; Lvar obj'; Lvar cl])))) + end + +let rec build_object_init cl_table obj params inh_init obj_init cl = + match cl.cl_desc with + Tclass_ident path -> + let obj_init = Ident.create "obj_init" in + let envs, inh_init = inh_init in + let env = + match envs with None -> [] + | Some envs -> [Lprim(Pfield (List.length inh_init + 1), [Lvar envs])] + in + ((envs, (obj_init, path)::inh_init), + mkappl(Lvar obj_init, env @ [obj])) + | Tclass_structure str -> + create_object cl_table obj (fun obj -> + let (inh_init, obj_init, has_init) = + List.fold_right + (fun field (inh_init, obj_init, has_init) -> + match field with + Cf_inher (cl, _, _) -> + let (inh_init, obj_init') = + build_object_init cl_table (Lvar obj) [] inh_init + (fun _ -> lambda_unit) cl + in + (inh_init, lsequence obj_init' obj_init, true) + | Cf_val (_, id, Some exp, _) -> + (inh_init, lsequence (set_inst_var obj id exp) obj_init, + has_init) + | Cf_meth _ | Cf_val _ -> + (inh_init, obj_init, has_init) + | Cf_init _ -> + (inh_init, obj_init, true) + | Cf_let (rec_flag, defs, vals) -> + (inh_init, + Translcore.transl_let rec_flag defs + (List.fold_right + (fun (id, expr) rem -> + lsequence (Lifused(id, set_inst_var obj id expr)) + rem) + vals obj_init), + has_init)) + str.cl_field + (inh_init, obj_init obj, false) + in + (inh_init, + List.fold_right + (fun (id, expr) rem -> + lsequence (Lifused (id, set_inst_var obj id expr)) rem) + params obj_init, + has_init)) + | Tclass_fun (pat, vals, cl, partial) -> + let (inh_init, obj_init) = + build_object_init cl_table obj (vals @ params) inh_init obj_init cl + in + (inh_init, + let build params rem = + let param = name_pattern "param" [pat, ()] in + Lfunction (Curried, param::params, + Matching.for_function + pat.pat_loc None (Lvar param) [pat, rem] partial) + in + begin match obj_init with + Lfunction (Curried, params, rem) -> build params rem + | rem -> build [] rem + end) + | Tclass_apply (cl, oexprs) -> + let (inh_init, obj_init) = + build_object_init cl_table obj params inh_init obj_init cl + in + (inh_init, transl_apply obj_init oexprs Location.none) + | Tclass_let (rec_flag, defs, vals, cl) -> + let (inh_init, obj_init) = + build_object_init cl_table obj (vals @ params) inh_init obj_init cl + in + (inh_init, Translcore.transl_let rec_flag defs obj_init) + | Tclass_constraint (cl, vals, pub_meths, concr_meths) -> + build_object_init cl_table obj params inh_init obj_init cl + +let rec build_object_init_0 cl_table params cl copy_env subst_env top ids = + match cl.cl_desc with + Tclass_let (rec_flag, defs, vals, cl) -> + build_object_init_0 cl_table (vals@params) cl copy_env subst_env top ids + | _ -> + let self = Ident.create "self" in + let env = Ident.create "env" in + let obj = if ids = [] then lambda_unit else Lvar self in + let envs = if top then None else Some env in + let ((_,inh_init), obj_init) = + build_object_init cl_table obj params (envs,[]) (copy_env env) cl in + let obj_init = + if ids = [] then obj_init else lfunction [self] obj_init in + (inh_init, lfunction [env] (subst_env env inh_init obj_init)) + + +let bind_method tbl lab id cl_init = + Llet(Strict, id, mkappl (oo_prim "get_method_label", + [Lvar tbl; transl_label lab]), + cl_init) + +let bind_methods tbl meths vals cl_init = + let methl = Meths.fold (fun lab id tl -> (lab,id) :: tl) meths [] in + let len = List.length methl and nvals = List.length vals in + if len < 2 && nvals = 0 then Meths.fold (bind_method tbl) meths cl_init else + if len = 0 && nvals < 2 then transl_vals tbl true Strict vals cl_init else + let ids = Ident.create "ids" in + let i = ref (len + nvals) in + let getter, names = + if nvals = 0 then "get_method_labels", [] else + "new_methods_variables", [transl_meth_list (List.map fst vals)] + in + Llet(Strict, ids, + mkappl (oo_prim getter, + [Lvar tbl; transl_meth_list (List.map fst methl)] @ names), + List.fold_right + (fun (lab,id) lam -> decr i; Llet(StrictOpt, id, lfield ids !i, lam)) + (methl @ vals) cl_init) + +let output_methods tbl methods lam = + match methods with + [] -> lam + | [lab; code] -> + lsequence (mkappl(oo_prim "set_method", [Lvar tbl; lab; code])) lam + | _ -> + lsequence (mkappl(oo_prim "set_methods", + [Lvar tbl; Lprim(Pmakeblock(0,Immutable), methods)])) + lam + +let rec ignore_cstrs cl = + match cl.cl_desc with + Tclass_constraint (cl, _, _, _) -> ignore_cstrs cl + | Tclass_apply (cl, _) -> ignore_cstrs cl + | _ -> cl + +let rec index a = function + [] -> raise Not_found + | b :: l -> + if b = a then 0 else 1 + index a l + +let bind_id_as_val (id, _) = ("", id) + +let rec build_class_init cla cstr super inh_init cl_init msubst top cl = + match cl.cl_desc with + Tclass_ident path -> + begin match inh_init with + (obj_init, path')::inh_init -> + let lpath = transl_path path in + (inh_init, + Llet (Strict, obj_init, + mkappl(Lprim(Pfield 1, [lpath]), Lvar cla :: + if top then [Lprim(Pfield 3, [lpath])] else []), + bind_super cla super cl_init)) + | _ -> + assert false + end + | Tclass_structure str -> + let cl_init = bind_super cla super cl_init in + let (inh_init, cl_init, methods, values) = + List.fold_right + (fun field (inh_init, cl_init, methods, values) -> + match field with + Cf_inher (cl, vals, meths) -> + let cl_init = output_methods cla methods cl_init in + let inh_init, cl_init = + build_class_init cla false + (vals, meths_super cla str.cl_meths meths) + inh_init cl_init msubst top cl in + (inh_init, cl_init, [], values) + | Cf_val (name, id, exp, over) -> + let values = if over then values else (name, id) :: values in + (inh_init, cl_init, methods, values) + | Cf_meth (name, exp) -> + let met_code = msubst true (transl_exp exp) in + let met_code = + if !Clflags.native_code && List.length met_code = 1 then + (* Force correct naming of method for profiles *) + let met = Ident.create ("method_" ^ name) in + [Llet(Strict, met, List.hd met_code, Lvar met)] + else met_code + in + (inh_init, cl_init, + Lvar (Meths.find name str.cl_meths) :: met_code @ methods, + values) + | Cf_let (rec_flag, defs, vals) -> + let vals = + List.map (function (id, _) -> (Ident.name id, id)) vals + in + (inh_init, cl_init, methods, vals @ values) + | Cf_init exp -> + (inh_init, + Lsequence(mkappl (oo_prim "add_initializer", + Lvar cla :: msubst false (transl_exp exp)), + cl_init), + methods, values)) + str.cl_field + (inh_init, cl_init, [], []) + in + let cl_init = output_methods cla methods cl_init in + (inh_init, bind_methods cla str.cl_meths values cl_init) + | Tclass_fun (pat, vals, cl, _) -> + let (inh_init, cl_init) = + build_class_init cla cstr super inh_init cl_init msubst top cl + in + let vals = List.map bind_id_as_val vals in + (inh_init, transl_vals cla true StrictOpt vals cl_init) + | Tclass_apply (cl, exprs) -> + build_class_init cla cstr super inh_init cl_init msubst top cl + | Tclass_let (rec_flag, defs, vals, cl) -> + let (inh_init, cl_init) = + build_class_init cla cstr super inh_init cl_init msubst top cl + in + let vals = List.map bind_id_as_val vals in + (inh_init, transl_vals cla true StrictOpt vals cl_init) + | Tclass_constraint (cl, vals, meths, concr_meths) -> + let virt_meths = + List.filter (fun lab -> not (Concr.mem lab concr_meths)) meths in + let concr_meths = Concr.elements concr_meths in + let narrow_args = + [Lvar cla; + transl_meth_list vals; + transl_meth_list virt_meths; + transl_meth_list concr_meths] in + let cl = ignore_cstrs cl in + begin match cl.cl_desc, inh_init with + Tclass_ident path, (obj_init, path')::inh_init -> + assert (Path.same path path'); + let lpath = transl_path path in + let inh = Ident.create "inh" + and ofs = List.length vals + 1 + and valids, methids = super in + let cl_init = + List.fold_left + (fun init (nm, id, _) -> + Llet(StrictOpt, id, lfield inh (index nm concr_meths + ofs), + init)) + cl_init methids in + let cl_init = + List.fold_left + (fun init (nm, id) -> + Llet(StrictOpt, id, lfield inh (index nm vals + 1), init)) + cl_init valids in + (inh_init, + Llet (Strict, inh, + mkappl(oo_prim "inherits", narrow_args @ + [lpath; Lconst(Const_pointer(if top then 1 else 0))]), + Llet(StrictOpt, obj_init, lfield inh 0, cl_init))) + | _ -> + let core cl_init = + build_class_init cla true super inh_init cl_init msubst top cl + in + if cstr then core cl_init else + let (inh_init, cl_init) = + core (Lsequence (mkappl (oo_prim "widen", [Lvar cla]), cl_init)) + in + (inh_init, + Lsequence(mkappl (oo_prim "narrow", narrow_args), + cl_init)) + end + +let rec build_class_lets cl = + match cl.cl_desc with + Tclass_let (rec_flag, defs, vals, cl) -> + let env, wrap = build_class_lets cl in + (env, fun x -> Translcore.transl_let rec_flag defs (wrap x)) + | _ -> + (cl.cl_env, fun x -> x) + +let rec get_class_meths cl = + match cl.cl_desc with + Tclass_structure cl -> + Meths.fold (fun _ -> IdentSet.add) cl.cl_meths IdentSet.empty + | Tclass_ident _ -> IdentSet.empty + | Tclass_fun (_, _, cl, _) + | Tclass_let (_, _, _, cl) + | Tclass_apply (cl, _) + | Tclass_constraint (cl, _, _, _) -> get_class_meths cl + +(* + XXX Il devrait etre peu couteux d'ecrire des classes : + class c x y = d e f +*) +let rec transl_class_rebind obj_init cl vf = + match cl.cl_desc with + Tclass_ident path -> + if vf = Concrete then begin + try if (Env.find_class path cl.cl_env).cty_new = None then raise Exit + with Not_found -> raise Exit + end; + (path, obj_init) + | Tclass_fun (pat, _, cl, partial) -> + let path, obj_init = transl_class_rebind obj_init cl vf in + let build params rem = + let param = name_pattern "param" [pat, ()] in + Lfunction (Curried, param::params, + Matching.for_function + pat.pat_loc None (Lvar param) [pat, rem] partial) + in + (path, + match obj_init with + Lfunction (Curried, params, rem) -> build params rem + | rem -> build [] rem) + | Tclass_apply (cl, oexprs) -> + let path, obj_init = transl_class_rebind obj_init cl vf in + (path, transl_apply obj_init oexprs Location.none) + | Tclass_let (rec_flag, defs, vals, cl) -> + let path, obj_init = transl_class_rebind obj_init cl vf in + (path, Translcore.transl_let rec_flag defs obj_init) + | Tclass_structure _ -> raise Exit + | Tclass_constraint (cl', _, _, _) -> + let path, obj_init = transl_class_rebind obj_init cl' vf in + let rec check_constraint = function + Tcty_constr(path', _, _) when Path.same path path' -> () + | Tcty_fun (_, _, cty) -> check_constraint cty + | _ -> raise Exit + in + check_constraint cl.cl_type; + (path, obj_init) + +let rec transl_class_rebind_0 self obj_init cl vf = + match cl.cl_desc with + Tclass_let (rec_flag, defs, vals, cl) -> + let path, obj_init = transl_class_rebind_0 self obj_init cl vf in + (path, Translcore.transl_let rec_flag defs obj_init) + | _ -> + let path, obj_init = transl_class_rebind obj_init cl vf in + (path, lfunction [self] obj_init) + +let transl_class_rebind ids cl vf = + try + let obj_init = Ident.create "obj_init" + and self = Ident.create "self" in + let obj_init0 = lapply (Lvar obj_init) [Lvar self] Location.none in + let path, obj_init' = transl_class_rebind_0 self obj_init0 cl vf in + if not (Translcore.check_recursive_lambda ids obj_init') then + raise(Error(cl.cl_loc, Illegal_class_expr)); + let id = (obj_init' = lfunction [self] obj_init0) in + if id then transl_path path else + + let cla = Ident.create "class" + and new_init = Ident.create "new_init" + and env_init = Ident.create "env_init" + and table = Ident.create "table" + and envs = Ident.create "envs" in + Llet( + Strict, new_init, lfunction [obj_init] obj_init', + Llet( + Alias, cla, transl_path path, + Lprim(Pmakeblock(0, Immutable), + [mkappl(Lvar new_init, [lfield cla 0]); + lfunction [table] + (Llet(Strict, env_init, + mkappl(lfield cla 1, [Lvar table]), + lfunction [envs] + (mkappl(Lvar new_init, + [mkappl(Lvar env_init, [Lvar envs])])))); + lfield cla 2; + lfield cla 3]))) + with Exit -> + lambda_unit + +(* Rewrite a closure using builtins. Improves native code size. *) + +let rec module_path = function + Lvar id -> + let s = Ident.name id in s <> "" && s.[0] >= 'A' && s.[0] <= 'Z' + | Lprim(Pfield _, [p]) -> module_path p + | Lprim(Pgetglobal _, []) -> true + | _ -> false + +let const_path local = function + Lvar id -> not (List.mem id local) + | Lconst _ -> true + | Lfunction (Curried, _, body) -> + let fv = free_variables body in + List.for_all (fun x -> not (IdentSet.mem x fv)) local + | p -> module_path p + +let rec builtin_meths self env env2 body = + let const_path = const_path (env::self) in + let conv = function + (* Lvar s when List.mem s self -> "_self", [] *) + | p when const_path p -> "const", [p] + | Lprim(Parrayrefu _, [Lvar s; Lvar n]) when List.mem s self -> + "var", [Lvar n] + | Lprim(Pfield n, [Lvar e]) when Ident.same e env -> + "env", [Lvar env2; Lconst(Const_pointer n)] + | Lsend(Self, met, Lvar s, []) when List.mem s self -> + "meth", [met] + | _ -> raise Not_found + in + match body with + | Llet(_, s', Lvar s, body) when List.mem s self -> + builtin_meths (s'::self) env env2 body + | Lapply(f, [arg], _) when const_path f -> + let s, args = conv arg in ("app_"^s, f :: args) + | Lapply(f, [arg; p], _) when const_path f && const_path p -> + let s, args = conv arg in + ("app_"^s^"_const", f :: args @ [p]) + | Lapply(f, [p; arg], _) when const_path f && const_path p -> + let s, args = conv arg in + ("app_const_"^s, f :: p :: args) + | Lsend(Self, Lvar n, Lvar s, [arg]) when List.mem s self -> + let s, args = conv arg in + ("meth_app_"^s, Lvar n :: args) + | Lsend(Self, met, Lvar s, []) when List.mem s self -> + ("get_meth", [met]) + | Lsend(Public, met, arg, []) -> + let s, args = conv arg in + ("send_"^s, met :: args) + | Lsend(Cached, met, arg, [_;_]) -> + let s, args = conv arg in + ("send_"^s, met :: args) + | Lfunction (Curried, [x], body) -> + let rec enter self = function + | Lprim(Parraysetu _, [Lvar s; Lvar n; Lvar x']) + when Ident.same x x' && List.mem s self -> + ("set_var", [Lvar n]) + | Llet(_, s', Lvar s, body) when List.mem s self -> + enter (s'::self) body + | _ -> raise Not_found + in enter self body + | Lfunction _ -> raise Not_found + | _ -> + let s, args = conv body in ("get_"^s, args) + +module M = struct + open CamlinternalOO + let builtin_meths self env env2 body = + let builtin, args = builtin_meths self env env2 body in + (* if not arr then [mkappl(oo_prim builtin, args)] else *) + let tag = match builtin with + "get_const" -> GetConst + | "get_var" -> GetVar + | "get_env" -> GetEnv + | "get_meth" -> GetMeth + | "set_var" -> SetVar + | "app_const" -> AppConst + | "app_var" -> AppVar + | "app_env" -> AppEnv + | "app_meth" -> AppMeth + | "app_const_const" -> AppConstConst + | "app_const_var" -> AppConstVar + | "app_const_env" -> AppConstEnv + | "app_const_meth" -> AppConstMeth + | "app_var_const" -> AppVarConst + | "app_env_const" -> AppEnvConst + | "app_meth_const" -> AppMethConst + | "meth_app_const" -> MethAppConst + | "meth_app_var" -> MethAppVar + | "meth_app_env" -> MethAppEnv + | "meth_app_meth" -> MethAppMeth + | "send_const" -> SendConst + | "send_var" -> SendVar + | "send_env" -> SendEnv + | "send_meth" -> SendMeth + | _ -> assert false + in Lconst(Const_pointer(Obj.magic tag)) :: args +end +open M + + +(* + Traduction d'une classe. + Plusieurs cas: + * reapplication d'une classe connue -> transl_class_rebind + * classe sans dependances locales -> traduction directe + * avec dependances locale -> creation d'un arbre de stubs, + avec un noeud pour chaque classe locale heritee + Une classe est un 4-uplet: + (obj_init, class_init, env_init, env) + obj_init: fonction de creation d'objet (unit -> obj) + class_init: fonction d'heritage (table -> env_init) + (une seule par code source) + env_init: parametrage par l'environnement local (env -> params -> obj_init) + (une par combinaison de class_init herites) + env: environnement local + Si ids=0 (objet immediat), alors on ne conserve que env_init. +*) + +let prerr_ids msg ids = + let names = List.map Ident.unique_toplevel_name ids in + prerr_endline (String.concat " " (msg :: names)) + +let transl_class ids cl_id arity pub_meths cl vflag = + (* First check if it is not only a rebind *) + let rebind = transl_class_rebind ids cl vflag in + if rebind <> lambda_unit then rebind else + + (* Prepare for heavy environment handling *) + let tables = Ident.create (Ident.name cl_id ^ "_tables") in + let (top_env, req) = oo_add_class tables in + let top = not req in + let cl_env, llets = build_class_lets cl in + let new_ids = if top then [] else Env.diff top_env cl_env in + let env2 = Ident.create "env" in + let meth_ids = get_class_meths cl in + let subst env lam i0 new_ids' = + let fv = free_variables lam in + (* prerr_ids "cl_id =" [cl_id]; prerr_ids "fv =" (IdentSet.elements fv); *) + let fv = List.fold_right IdentSet.remove !new_ids' fv in + (* We need to handle method ids specially, as they do not appear + in the typing environment (PR#3576, PR#4560) *) + (* very hacky: we add and remove free method ids on the fly, + depending on the visit order... *) + method_ids := + IdentSet.diff (IdentSet.union (free_methods lam) !method_ids) meth_ids; + (* prerr_ids "meth_ids =" (IdentSet.elements meth_ids); + prerr_ids "method_ids =" (IdentSet.elements !method_ids); *) + let new_ids = List.fold_right IdentSet.add new_ids !method_ids in + let fv = IdentSet.inter fv new_ids in + new_ids' := !new_ids' @ IdentSet.elements fv; + (* prerr_ids "new_ids' =" !new_ids'; *) + let i = ref (i0-1) in + List.fold_left + (fun subst id -> + incr i; Ident.add id (lfield env !i) subst) + Ident.empty !new_ids' + in + let new_ids_meths = ref [] in + let msubst arr = function + Lfunction (Curried, self :: args, body) -> + let env = Ident.create "env" in + let body' = + if new_ids = [] then body else + subst_lambda (subst env body 0 new_ids_meths) body in + begin try + (* Doesn't seem to improve size for bytecode *) + (* if not !Clflags.native_code then raise Not_found; *) + if not arr || !Clflags.debug then raise Not_found; + builtin_meths [self] env env2 (lfunction args body') + with Not_found -> + [lfunction (self :: args) + (if not (IdentSet.mem env (free_variables body')) then body' else + Llet(Alias, env, + Lprim(Parrayrefu Paddrarray, + [Lvar self; Lvar env2]), body'))] + end + | _ -> assert false + in + let new_ids_init = ref [] in + let env1 = Ident.create "env" and env1' = Ident.create "env'" in + let copy_env envs self = + if top then lambda_unit else + Lifused(env2, Lprim(Parraysetu Paddrarray, + [Lvar self; Lvar env2; Lvar env1'])) + and subst_env envs l lam = + if top then lam else + (* must be called only once! *) + let lam = subst_lambda (subst env1 lam 1 new_ids_init) lam in + Llet(Alias, env1, (if l = [] then Lvar envs else lfield envs 0), + Llet(Alias, env1', + (if !new_ids_init = [] then Lvar env1 else lfield env1 0), + lam)) + in + + (* Now we start compiling the class *) + let cla = Ident.create "class" in + let (inh_init, obj_init) = + build_object_init_0 cla [] cl copy_env subst_env top ids in + if not (Translcore.check_recursive_lambda ids obj_init) then + raise(Error(cl.cl_loc, Illegal_class_expr)); + let inh_init' = List.rev inh_init in + let (inh_init', cl_init) = + build_class_init cla true ([],[]) inh_init' obj_init msubst top cl + in + assert (inh_init' = []); + let table = Ident.create "table" + and class_init = Ident.create (Ident.name cl_id ^ "_init") + and env_init = Ident.create "env_init" + and obj_init = Ident.create "obj_init" in + let pub_meths = + List.sort + (fun s s' -> compare (Btype.hash_variant s) (Btype.hash_variant s')) + pub_meths in + let tags = List.map Btype.hash_variant pub_meths in + let rev_map = List.combine tags pub_meths in + List.iter2 + (fun tag name -> + let name' = List.assoc tag rev_map in + if name' <> name then raise(Error(cl.cl_loc, Tags(name, name')))) + tags pub_meths; + let ltable table lam = + Llet(Strict, table, + mkappl (oo_prim "create_table", [transl_meth_list pub_meths]), lam) + and ldirect obj_init = + Llet(Strict, obj_init, cl_init, + Lsequence(mkappl (oo_prim "init_class", [Lvar cla]), + mkappl (Lvar obj_init, [lambda_unit]))) + in + (* Simplest case: an object defined at toplevel (ids=[]) *) + if top && ids = [] then llets (ltable cla (ldirect obj_init)) else + + let concrete = (vflag = Concrete) + and lclass lam = + let cl_init = llets (Lfunction(Curried, [cla], cl_init)) in + Llet(Strict, class_init, cl_init, lam (free_variables cl_init)) + and lbody fv = + if List.for_all (fun id -> not (IdentSet.mem id fv)) ids then + mkappl (oo_prim "make_class",[transl_meth_list pub_meths; + Lvar class_init]) + else + ltable table ( + Llet( + Strict, env_init, mkappl (Lvar class_init, [Lvar table]), + Lsequence( + mkappl (oo_prim "init_class", [Lvar table]), + Lprim(Pmakeblock(0, Immutable), + [mkappl (Lvar env_init, [lambda_unit]); + Lvar class_init; Lvar env_init; lambda_unit])))) + and lbody_virt lenvs = + Lprim(Pmakeblock(0, Immutable), + [lambda_unit; Lfunction(Curried,[cla], cl_init); lambda_unit; lenvs]) + in + (* Still easy: a class defined at toplevel *) + if top && concrete then lclass lbody else + if top then llets (lbody_virt lambda_unit) else + + (* Now for the hard stuff: prepare for table cacheing *) + let envs = Ident.create "envs" + and cached = Ident.create "cached" in + let lenvs = + if !new_ids_meths = [] && !new_ids_init = [] && inh_init = [] + then lambda_unit + else Lvar envs in + let lenv = + let menv = + if !new_ids_meths = [] then lambda_unit else + Lprim(Pmakeblock(0, Immutable), + List.map (fun id -> Lvar id) !new_ids_meths) in + if !new_ids_init = [] then menv else + Lprim(Pmakeblock(0, Immutable), + menv :: List.map (fun id -> Lvar id) !new_ids_init) + and linh_envs = + List.map (fun (_, p) -> Lprim(Pfield 3, [transl_path p])) + (List.rev inh_init) + in + let make_envs lam = + Llet(StrictOpt, envs, + (if linh_envs = [] then lenv else + Lprim(Pmakeblock(0, Immutable), lenv :: linh_envs)), + lam) + and def_ids cla lam = + Llet(StrictOpt, env2, + mkappl (oo_prim "new_variable", [Lvar cla; transl_label ""]), + lam) + in + let inh_paths = + List.filter + (fun (_,path) -> List.mem (Path.head path) new_ids) inh_init in + let inh_keys = + List.map (fun (_,p) -> Lprim(Pfield 1, [transl_path p])) inh_paths in + let lclass lam = + Llet(Strict, class_init, + Lfunction(Curried, [cla], def_ids cla cl_init), lam) + and lcache lam = + if inh_keys = [] then Llet(Alias, cached, Lvar tables, lam) else + Llet(Strict, cached, + mkappl (oo_prim "lookup_tables", + [Lvar tables; Lprim(Pmakeblock(0, Immutable), inh_keys)]), + lam) + and lset cached i lam = + Lprim(Psetfield(i, true), [Lvar cached; lam]) + in + let ldirect () = + ltable cla + (Llet(Strict, env_init, def_ids cla cl_init, + Lsequence(mkappl (oo_prim "init_class", [Lvar cla]), + lset cached 0 (Lvar env_init)))) + and lclass_virt () = + lset cached 0 (Lfunction(Curried, [cla], def_ids cla cl_init)) + in + llets ( + lcache ( + Lsequence( + Lifthenelse(lfield cached 0, lambda_unit, + if ids = [] then ldirect () else + if not concrete then lclass_virt () else + lclass ( + mkappl (oo_prim "make_class_store", + [transl_meth_list pub_meths; + Lvar class_init; Lvar cached]))), + make_envs ( + if ids = [] then mkappl (lfield cached 0, [lenvs]) else + Lprim(Pmakeblock(0, Immutable), + if concrete then + [mkappl (lfield cached 0, [lenvs]); + lfield cached 1; + lfield cached 0; + lenvs] + else [lambda_unit; lfield cached 0; lambda_unit; lenvs] + ))))) + +(* Wrapper for class compilation *) + +let transl_class ids cl_id arity pub_meths cl vf = + oo_wrap cl.cl_env false (transl_class ids cl_id arity pub_meths cl) vf + +let () = + transl_object := (fun id meths cl -> transl_class [] id 0 meths cl Concrete) + +(* Error report *) + +open Format + +let report_error ppf = function + | Illegal_class_expr -> + fprintf ppf "This kind of class expression is not allowed" + | Tags (lab1, lab2) -> + fprintf ppf "Method labels `%s' and `%s' are incompatible.@ %s" + lab1 lab2 "Change one of them." diff --git a/bytecomp/translclass.mli b/bytecomp/translclass.mli new file mode 100644 index 0000000..de63ee5 --- /dev/null +++ b/bytecomp/translclass.mli @@ -0,0 +1,28 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translclass.mli,v 1.12 2006-04-05 02:28:12 garrigue Exp $ *) + +open Typedtree +open Lambda + +val transl_class : + Ident.t list -> Ident.t -> + int -> string list -> class_expr -> Asttypes.virtual_flag -> lambda;; + +type error = Illegal_class_expr | Tags of string * string + +exception Error of Location.t * error + +open Format + +val report_error: formatter -> error -> unit diff --git a/bytecomp/translcore.ml b/bytecomp/translcore.ml new file mode 100644 index 0000000..50a2f8b --- /dev/null +++ b/bytecomp/translcore.ml @@ -0,0 +1,1048 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translcore.ml,v 1.110 2008-08-27 10:23:21 garrigue Exp $ *) + +(* Translation from typed abstract syntax to lambda terms, + for the core language *) + +open Misc +open Asttypes +open Primitive +open Path +open Types +open Typedtree +open Typeopt +open Lambda + +type error = + Illegal_letrec_pat + | Illegal_letrec_expr + | Free_super_var + +exception Error of Location.t * error + +(* Forward declaration -- to be filled in by Translmod.transl_module *) +let transl_module = + ref((fun cc rootpath modl -> assert false) : + module_coercion -> Path.t option -> module_expr -> lambda) + +let transl_object = + ref (fun id s cl -> assert false : + Ident.t -> string list -> class_expr -> lambda) + +(* Translation of primitives *) + +let comparisons_table = create_hashtable 11 [ + "%equal", + (Pccall{prim_name = "caml_equal"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Ceq, + Pfloatcomp Ceq, + Pccall{prim_name = "caml_string_equal"; prim_arity = 2; + prim_alloc = false; + prim_native_name = ""; prim_native_float = false}, + Pbintcomp(Pnativeint, Ceq), + Pbintcomp(Pint32, Ceq), + Pbintcomp(Pint64, Ceq), + true); + "%notequal", + (Pccall{prim_name = "caml_notequal"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Cneq, + Pfloatcomp Cneq, + Pccall{prim_name = "caml_string_notequal"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pbintcomp(Pnativeint, Cneq), + Pbintcomp(Pint32, Cneq), + Pbintcomp(Pint64, Cneq), + true); + "%lessthan", + (Pccall{prim_name = "caml_lessthan"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Clt, + Pfloatcomp Clt, + Pccall{prim_name = "caml_string_lessthan"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pbintcomp(Pnativeint, Clt), + Pbintcomp(Pint32, Clt), + Pbintcomp(Pint64, Clt), + false); + "%greaterthan", + (Pccall{prim_name = "caml_greaterthan"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Cgt, + Pfloatcomp Cgt, + Pccall{prim_name = "caml_string_greaterthan"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pbintcomp(Pnativeint, Cgt), + Pbintcomp(Pint32, Cgt), + Pbintcomp(Pint64, Cgt), + false); + "%lessequal", + (Pccall{prim_name = "caml_lessequal"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Cle, + Pfloatcomp Cle, + Pccall{prim_name = "caml_string_lessequal"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pbintcomp(Pnativeint, Cle), + Pbintcomp(Pint32, Cle), + Pbintcomp(Pint64, Cle), + false); + "%greaterequal", + (Pccall{prim_name = "caml_greaterequal"; prim_arity = 2; + prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pintcomp Cge, + Pfloatcomp Cge, + Pccall{prim_name = "caml_string_greaterequal"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pbintcomp(Pnativeint, Cge), + Pbintcomp(Pint32, Cge), + Pbintcomp(Pint64, Cge), + false); + "%compare", + (Pccall{prim_name = "caml_compare"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false}, + Pccall{prim_name = "caml_int_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pccall{prim_name = "caml_float_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pccall{prim_name = "caml_string_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pccall{prim_name = "caml_nativeint_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pccall{prim_name = "caml_int32_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + Pccall{prim_name = "caml_int64_compare"; prim_arity = 2; + prim_alloc = false; prim_native_name = ""; + prim_native_float = false}, + false) +] + +let primitives_table = create_hashtable 57 [ + "%identity", Pidentity; + "%ignore", Pignore; + "%field0", Pfield 0; + "%field1", Pfield 1; + "%setfield0", Psetfield(0, true); + "%makeblock", Pmakeblock(0, Immutable); + "%makemutable", Pmakeblock(0, Mutable); + "%raise", Praise; + "%sequand", Psequand; + "%sequor", Psequor; + "%boolnot", Pnot; + "%negint", Pnegint; + "%succint", Poffsetint 1; + "%predint", Poffsetint(-1); + "%addint", Paddint; + "%subint", Psubint; + "%mulint", Pmulint; + "%divint", Pdivint; + "%modint", Pmodint; + "%andint", Pandint; + "%orint", Porint; + "%xorint", Pxorint; + "%lslint", Plslint; + "%lsrint", Plsrint; + "%asrint", Pasrint; + "%eq", Pintcomp Ceq; + "%noteq", Pintcomp Cneq; + "%ltint", Pintcomp Clt; + "%leint", Pintcomp Cle; + "%gtint", Pintcomp Cgt; + "%geint", Pintcomp Cge; + "%incr", Poffsetref(1); + "%decr", Poffsetref(-1); + "%intoffloat", Pintoffloat; + "%floatofint", Pfloatofint; + "%negfloat", Pnegfloat; + "%absfloat", Pabsfloat; + "%addfloat", Paddfloat; + "%subfloat", Psubfloat; + "%mulfloat", Pmulfloat; + "%divfloat", Pdivfloat; + "%eqfloat", Pfloatcomp Ceq; + "%noteqfloat", Pfloatcomp Cneq; + "%ltfloat", Pfloatcomp Clt; + "%lefloat", Pfloatcomp Cle; + "%gtfloat", Pfloatcomp Cgt; + "%gefloat", Pfloatcomp Cge; + "%string_length", Pstringlength; + "%string_safe_get", Pstringrefs; + "%string_safe_set", Pstringsets; + "%string_unsafe_get", Pstringrefu; + "%string_unsafe_set", Pstringsetu; + "%array_length", Parraylength Pgenarray; + "%array_safe_get", Parrayrefs Pgenarray; + "%array_safe_set", Parraysets Pgenarray; + "%array_unsafe_get", Parrayrefu Pgenarray; + "%array_unsafe_set", Parraysetu Pgenarray; + "%obj_size", Parraylength Pgenarray; + "%obj_field", Parrayrefu Pgenarray; + "%obj_set_field", Parraysetu Pgenarray; + "%obj_is_int", Pisint; + "%lazy_force", Plazyforce; + "%nativeint_of_int", Pbintofint Pnativeint; + "%nativeint_to_int", Pintofbint Pnativeint; + "%nativeint_neg", Pnegbint Pnativeint; + "%nativeint_add", Paddbint Pnativeint; + "%nativeint_sub", Psubbint Pnativeint; + "%nativeint_mul", Pmulbint Pnativeint; + "%nativeint_div", Pdivbint Pnativeint; + "%nativeint_mod", Pmodbint Pnativeint; + "%nativeint_and", Pandbint Pnativeint; + "%nativeint_or", Porbint Pnativeint; + "%nativeint_xor", Pxorbint Pnativeint; + "%nativeint_lsl", Plslbint Pnativeint; + "%nativeint_lsr", Plsrbint Pnativeint; + "%nativeint_asr", Pasrbint Pnativeint; + "%int32_of_int", Pbintofint Pint32; + "%int32_to_int", Pintofbint Pint32; + "%int32_neg", Pnegbint Pint32; + "%int32_add", Paddbint Pint32; + "%int32_sub", Psubbint Pint32; + "%int32_mul", Pmulbint Pint32; + "%int32_div", Pdivbint Pint32; + "%int32_mod", Pmodbint Pint32; + "%int32_and", Pandbint Pint32; + "%int32_or", Porbint Pint32; + "%int32_xor", Pxorbint Pint32; + "%int32_lsl", Plslbint Pint32; + "%int32_lsr", Plsrbint Pint32; + "%int32_asr", Pasrbint Pint32; + "%int64_of_int", Pbintofint Pint64; + "%int64_to_int", Pintofbint Pint64; + "%int64_neg", Pnegbint Pint64; + "%int64_add", Paddbint Pint64; + "%int64_sub", Psubbint Pint64; + "%int64_mul", Pmulbint Pint64; + "%int64_div", Pdivbint Pint64; + "%int64_mod", Pmodbint Pint64; + "%int64_and", Pandbint Pint64; + "%int64_or", Porbint Pint64; + "%int64_xor", Pxorbint Pint64; + "%int64_lsl", Plslbint Pint64; + "%int64_lsr", Plsrbint Pint64; + "%int64_asr", Pasrbint Pint64; + "%nativeint_of_int32", Pcvtbint(Pint32, Pnativeint); + "%nativeint_to_int32", Pcvtbint(Pnativeint, Pint32); + "%int64_of_int32", Pcvtbint(Pint32, Pint64); + "%int64_to_int32", Pcvtbint(Pint64, Pint32); + "%int64_of_nativeint", Pcvtbint(Pnativeint, Pint64); + "%int64_to_nativeint", Pcvtbint(Pint64, Pnativeint); + "%caml_ba_ref_1", + Pbigarrayref(false, 1, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_ref_2", + Pbigarrayref(false, 2, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_ref_3", + Pbigarrayref(false, 3, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_set_1", + Pbigarrayset(false, 1, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_set_2", + Pbigarrayset(false, 2, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_set_3", + Pbigarrayset(false, 3, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_ref_1", + Pbigarrayref(true, 1, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_ref_2", + Pbigarrayref(true, 2, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_ref_3", + Pbigarrayref(true, 3, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_set_1", + Pbigarrayset(true, 1, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_set_2", + Pbigarrayset(true, 2, Pbigarray_unknown, Pbigarray_unknown_layout); + "%caml_ba_unsafe_set_3", + Pbigarrayset(true, 3, Pbigarray_unknown, Pbigarray_unknown_layout) +] + +let prim_makearray = + { prim_name = "caml_make_vect"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false } + +let prim_obj_dup = + { prim_name = "caml_obj_dup"; prim_arity = 1; prim_alloc = true; + prim_native_name = ""; prim_native_float = false } + +let transl_prim prim args = + try + let (gencomp, intcomp, floatcomp, stringcomp, + nativeintcomp, int32comp, int64comp, + simplify_constant_constructor) = + Hashtbl.find comparisons_table prim.prim_name in + begin match args with + [arg1; {exp_desc = Texp_construct({cstr_tag = Cstr_constant _}, _)}] + when simplify_constant_constructor -> + intcomp + | [{exp_desc = Texp_construct({cstr_tag = Cstr_constant _}, _)}; arg2] + when simplify_constant_constructor -> + intcomp + | [arg1; {exp_desc = Texp_variant(_, None)}] + when simplify_constant_constructor -> + intcomp + | [{exp_desc = Texp_variant(_, None)}; exp2] + when simplify_constant_constructor -> + intcomp + | [arg1; arg2] when has_base_type arg1 Predef.path_int + || has_base_type arg1 Predef.path_char -> + intcomp + | [arg1; arg2] when has_base_type arg1 Predef.path_float -> + floatcomp + | [arg1; arg2] when has_base_type arg1 Predef.path_string -> + stringcomp + | [arg1; arg2] when has_base_type arg1 Predef.path_nativeint -> + nativeintcomp + | [arg1; arg2] when has_base_type arg1 Predef.path_int32 -> + int32comp + | [arg1; arg2] when has_base_type arg1 Predef.path_int64 -> + int64comp + | _ -> + gencomp + end + with Not_found -> + try + let p = Hashtbl.find primitives_table prim.prim_name in + (* Try strength reduction based on the type of the argument *) + begin match (p, args) with + (Psetfield(n, _), [arg1; arg2]) -> Psetfield(n, maybe_pointer arg2) + | (Parraylength Pgenarray, [arg]) -> Parraylength(array_kind arg) + | (Parrayrefu Pgenarray, arg1 :: _) -> Parrayrefu(array_kind arg1) + | (Parraysetu Pgenarray, arg1 :: _) -> Parraysetu(array_kind arg1) + | (Parrayrefs Pgenarray, arg1 :: _) -> Parrayrefs(array_kind arg1) + | (Parraysets Pgenarray, arg1 :: _) -> Parraysets(array_kind arg1) + | (Pbigarrayref(unsafe, n, Pbigarray_unknown, Pbigarray_unknown_layout), + arg1 :: _) -> + let (k, l) = bigarray_kind_and_layout arg1 in + Pbigarrayref(unsafe, n, k, l) + | (Pbigarrayset(unsafe, n, Pbigarray_unknown, Pbigarray_unknown_layout), + arg1 :: _) -> + let (k, l) = bigarray_kind_and_layout arg1 in + Pbigarrayset(unsafe, n, k, l) + | _ -> p + end + with Not_found -> + Pccall prim + + +(* Eta-expand a primitive without knowing the types of its arguments *) + +let transl_primitive p = + let prim = + try + let (gencomp, _, _, _, _, _, _, _) = + Hashtbl.find comparisons_table p.prim_name in + gencomp + with Not_found -> + try + Hashtbl.find primitives_table p.prim_name + with Not_found -> + Pccall p in + match prim with + Plazyforce -> + let parm = Ident.create "prim" in + Lfunction(Curried, [parm], Matching.inline_lazy_force (Lvar parm) Location.none) + | _ -> + let rec make_params n = + if n <= 0 then [] else Ident.create "prim" :: make_params (n-1) in + let params = make_params p.prim_arity in + Lfunction(Curried, params, Lprim(prim, List.map (fun id -> Lvar id) params)) + +(* To check the well-formedness of r.h.s. of "let rec" definitions *) + +let check_recursive_lambda idlist lam = + let rec check_top idlist = function + | Lvar v -> not (List.mem v idlist) + | Llet (_, _, _, _) as lam when check_recursive_recordwith idlist lam -> + true + | Llet(str, id, arg, body) -> + check idlist arg && check_top (add_let id arg idlist) body + | Lletrec(bindings, body) -> + let idlist' = add_letrec bindings idlist in + List.for_all (fun (id, arg) -> check idlist' arg) bindings && + check_top idlist' body + | Lsequence (lam1, lam2) -> check idlist lam1 && check_top idlist lam2 + | Levent (lam, _) -> check_top idlist lam + | lam -> check idlist lam + + and check idlist = function + | Lvar _ -> true + | Lfunction(kind, params, body) -> true + | Llet (_, _, _, _) as lam when check_recursive_recordwith idlist lam -> + true + | Llet(str, id, arg, body) -> + check idlist arg && check (add_let id arg idlist) body + | Lletrec(bindings, body) -> + let idlist' = add_letrec bindings idlist in + List.for_all (fun (id, arg) -> check idlist' arg) bindings && + check idlist' body + | Lprim(Pmakeblock(tag, mut), args) -> + List.for_all (check idlist) args + | Lprim(Pmakearray(Paddrarray|Pintarray), args) -> + List.for_all (check idlist) args + | Lprim (Pmakearray (Pgenarray), args) -> false + | Lsequence (lam1, lam2) -> check idlist lam1 && check idlist lam2 + | Levent (lam, _) -> check idlist lam + | lam -> + let fv = free_variables lam in + not (List.exists (fun id -> IdentSet.mem id fv) idlist) + + and add_let id arg idlist = + let fv = free_variables arg in + if List.exists (fun id -> IdentSet.mem id fv) idlist + then id :: idlist + else idlist + + and add_letrec bindings idlist = + List.fold_right (fun (id, arg) idl -> add_let id arg idl) + bindings idlist + + (* reverse-engineering the code generated by transl_record case 2 *) + (* If you change this, you probably need to change Bytegen.size_of_lambda. *) + and check_recursive_recordwith idlist = function + | Llet (Strict, id1, Lprim (Pduprecord _, [e1]), body) -> + check_top idlist e1 + && check_recordwith_updates idlist id1 body + | _ -> false + + and check_recordwith_updates idlist id1 = function + | Lsequence (Lprim ((Psetfield _ | Psetfloatfield _), [Lvar id2; e1]), cont) + -> id2 = id1 && check idlist e1 + && check_recordwith_updates idlist id1 cont + | Lvar id2 -> id2 = id1 + | _ -> false + + in check_top idlist lam + +(* To propagate structured constants *) + +exception Not_constant + +let extract_constant = function + Lconst sc -> sc + | _ -> raise Not_constant + +let extract_float = function + Const_base(Const_float f) -> f + | _ -> fatal_error "Translcore.extract_float" + +(* To find reasonable names for let-bound and lambda-bound idents *) + +let rec name_pattern default = function + [] -> Ident.create default + | (p, e) :: rem -> + match p.pat_desc with + Tpat_var id -> id + | Tpat_alias(p, id) -> id + | _ -> name_pattern default rem + +(* Push the default values under the functional abstractions *) + +let rec push_defaults loc bindings pat_expr_list partial = + match pat_expr_list with + [pat, ({exp_desc = Texp_function(pl,partial)} as exp)] -> + let pl = push_defaults exp.exp_loc bindings pl partial in + [pat, {exp with exp_desc = Texp_function(pl, partial)}] + | [pat, {exp_desc = Texp_let + (Default, cases, ({exp_desc = Texp_function _} as e2))}] -> + push_defaults loc (cases :: bindings) [pat, e2] partial + | [pat, exp] -> + let exp = + List.fold_left + (fun exp cases -> + {exp with exp_desc = Texp_let(Nonrecursive, cases, exp)}) + exp bindings + in + [pat, exp] + | (pat, exp) :: _ when bindings <> [] -> + let param = name_pattern "param" pat_expr_list in + let exp = + { exp with exp_loc = loc; exp_desc = + Texp_match + ({exp with exp_type = pat.pat_type; exp_desc = + Texp_ident (Path.Pident param, + {val_type = pat.pat_type; val_kind = Val_reg})}, + pat_expr_list, partial) } + in + push_defaults loc bindings + [{pat with pat_desc = Tpat_var param}, exp] Total + | _ -> + pat_expr_list + +(* Insertion of debugging events *) + +let event_before exp lam = match lam with +| Lstaticraise (_,_) -> lam +| _ -> + if !Clflags.debug + then Levent(lam, {lev_loc = exp.exp_loc; + lev_kind = Lev_before; + lev_repr = None; + lev_env = Env.summary exp.exp_env}) + else lam + +let event_after exp lam = + if !Clflags.debug + then Levent(lam, {lev_loc = exp.exp_loc; + lev_kind = Lev_after exp.exp_type; + lev_repr = None; + lev_env = Env.summary exp.exp_env}) + else lam + +let event_function exp lam = + if !Clflags.debug then + let repr = Some (ref 0) in + let (info, body) = lam repr in + (info, + Levent(body, {lev_loc = exp.exp_loc; + lev_kind = Lev_function; + lev_repr = repr; + lev_env = Env.summary exp.exp_env})) + else + lam None + +let primitive_is_ccall = function + (* Determine if a primitive is a Pccall or will be turned later into + a C function call that may raise an exception *) + | Pccall _ | Pstringrefs | Pstringsets | Parrayrefs _ | Parraysets _ | + Pbigarrayref _ | Pbigarrayset _ | Pduprecord _ -> true + | _ -> false + +(* Assertions *) + +let assert_failed loc = + (* [Location.get_pos_info] is too expensive *) + let fname = match loc.Location.loc_start.Lexing.pos_fname with + | "" -> !Location.input_name + | x -> x + in + let pos = loc.Location.loc_start in + let line = pos.Lexing.pos_lnum in + let char = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in + Lprim(Praise, [Lprim(Pmakeblock(0, Immutable), + [transl_path Predef.path_assert_failure; + Lconst(Const_block(0, + [Const_base(Const_string fname); + Const_base(Const_int line); + Const_base(Const_int char)]))])]) +;; + +let rec cut n l = + if n = 0 then ([],l) else + match l with [] -> failwith "Translcore.cut" + | a::l -> let (l1,l2) = cut (n-1) l in (a::l1,l2) + +(* Translation of expressions *) + +let rec transl_exp e = + let eval_once = + (* Whether classes for immediate objects must be cached *) + match e.exp_desc with + Texp_function _ | Texp_for _ | Texp_while _ -> false + | _ -> true + in + if eval_once then transl_exp0 e else + Translobj.oo_wrap e.exp_env true transl_exp0 e + +and transl_exp0 e = + match e.exp_desc with + Texp_ident(path, {val_kind = Val_prim p}) -> + let public_send = p.prim_name = "%send" in + if public_send || p.prim_name = "%sendself" then + let kind = if public_send then Public else Self in + let obj = Ident.create "obj" and meth = Ident.create "meth" in + Lfunction(Curried, [obj; meth], Lsend(kind, Lvar meth, Lvar obj, [])) + else if p.prim_name = "%sendcache" then + let obj = Ident.create "obj" and meth = Ident.create "meth" in + let cache = Ident.create "cache" and pos = Ident.create "pos" in + Lfunction(Curried, [obj; meth; cache; pos], + Lsend(Cached, Lvar meth, Lvar obj, [Lvar cache; Lvar pos])) + else + transl_primitive p + | Texp_ident(path, {val_kind = Val_anc _}) -> + raise(Error(e.exp_loc, Free_super_var)) + | Texp_ident(path, {val_kind = Val_reg | Val_self _}) -> + transl_path path + | Texp_ident _ -> fatal_error "Translcore.transl_exp: bad Texp_ident" + | Texp_constant cst -> + Lconst(Const_base cst) + | Texp_let(rec_flag, pat_expr_list, body) -> + transl_let rec_flag pat_expr_list (event_before body (transl_exp body)) + | Texp_function (pat_expr_list, partial) -> + let ((kind, params), body) = + event_function e + (function repr -> + let pl = push_defaults e.exp_loc [] pat_expr_list partial in + transl_function e.exp_loc !Clflags.native_code repr partial pl) + in + Lfunction(kind, params, body) + | Texp_apply({exp_desc = Texp_ident(path, {val_kind = Val_prim p})}, oargs) + when List.length oargs >= p.prim_arity + && List.for_all (fun (arg,_) -> arg <> None) oargs -> + let args, args' = cut p.prim_arity oargs in + let wrap f = + if args' = [] + then event_after e f + else event_after e (transl_apply f args' e.exp_loc) + in + let wrap0 f = + if args' = [] then f else wrap f in + let args = List.map (function Some x, _ -> x | _ -> assert false) args in + let argl = transl_list args in + let public_send = p.prim_name = "%send" + || not !Clflags.native_code && p.prim_name = "%sendcache"in + if public_send || p.prim_name = "%sendself" then + let kind = if public_send then Public else Self in + let obj = List.hd argl in + wrap (Lsend (kind, List.nth argl 1, obj, [])) + else if p.prim_name = "%sendcache" then + match argl with [obj; meth; cache; pos] -> + wrap (Lsend(Cached, meth, obj, [cache; pos])) + | _ -> assert false + else begin + let prim = transl_prim p args in + match (prim, args) with + (Praise, [arg1]) -> + wrap0 (Lprim(Praise, [event_after arg1 (List.hd argl)])) + | (_, _) -> + begin match (prim, argl) with + | (Plazyforce, [a]) -> + wrap (Matching.inline_lazy_force a e.exp_loc) + | (Plazyforce, _) -> assert false + |_ -> let p = Lprim(prim, argl) in + if primitive_is_ccall prim then wrap p else wrap0 p + end + end + | Texp_apply(funct, oargs) -> + event_after e (transl_apply (transl_exp funct) oargs e.exp_loc) + | Texp_match({exp_desc = Texp_tuple argl}, pat_expr_list, partial) -> + Matching.for_multiple_match e.exp_loc + (transl_list argl) (transl_cases pat_expr_list) partial + | Texp_match(arg, pat_expr_list, partial) -> + Matching.for_function e.exp_loc None + (transl_exp arg) (transl_cases pat_expr_list) partial + | Texp_try(body, pat_expr_list) -> + let id = name_pattern "exn" pat_expr_list in + Ltrywith(transl_exp body, id, + Matching.for_trywith (Lvar id) (transl_cases pat_expr_list)) + | Texp_tuple el -> + let ll = transl_list el in + begin try + Lconst(Const_block(0, List.map extract_constant ll)) + with Not_constant -> + Lprim(Pmakeblock(0, Immutable), ll) + end + | Texp_construct(cstr, args) -> + let ll = transl_list args in + begin match cstr.cstr_tag with + Cstr_constant n -> + Lconst(Const_pointer n) + | Cstr_block n -> + begin try + Lconst(Const_block(n, List.map extract_constant ll)) + with Not_constant -> + Lprim(Pmakeblock(n, Immutable), ll) + end + | Cstr_exception path -> + Lprim(Pmakeblock(0, Immutable), transl_path path :: ll) + end + | Texp_variant(l, arg) -> + let tag = Btype.hash_variant l in + begin match arg with + None -> Lconst(Const_pointer tag) + | Some arg -> + let lam = transl_exp arg in + try + Lconst(Const_block(0, [Const_base(Const_int tag); + extract_constant lam])) + with Not_constant -> + Lprim(Pmakeblock(0, Immutable), + [Lconst(Const_base(Const_int tag)); lam]) + end + | Texp_record ((lbl1, _) :: _ as lbl_expr_list, opt_init_expr) -> + transl_record lbl1.lbl_all lbl1.lbl_repres lbl_expr_list opt_init_expr + | Texp_record ([], _) -> + fatal_error "Translcore.transl_exp: bad Texp_record" + | Texp_field(arg, lbl) -> + let access = + match lbl.lbl_repres with + Record_regular -> Pfield lbl.lbl_pos + | Record_float -> Pfloatfield lbl.lbl_pos in + Lprim(access, [transl_exp arg]) + | Texp_setfield(arg, lbl, newval) -> + let access = + match lbl.lbl_repres with + Record_regular -> Psetfield(lbl.lbl_pos, maybe_pointer newval) + | Record_float -> Psetfloatfield lbl.lbl_pos in + Lprim(access, [transl_exp arg; transl_exp newval]) + | Texp_array expr_list -> + let kind = array_kind e in + let ll = transl_list expr_list in + begin try + (* Deactivate constant optimization if array is small enough *) + if List.length ll <= 4 then raise Not_constant; + let cl = List.map extract_constant ll in + let master = + match kind with + | Paddrarray | Pintarray -> + Lconst(Const_block(0, cl)) + | Pfloatarray -> + Lconst(Const_float_array(List.map extract_float cl)) + | Pgenarray -> + raise Not_constant in (* can this really happen? *) + Lprim(Pccall prim_obj_dup, [master]) + with Not_constant -> + Lprim(Pmakearray kind, ll) + end + | Texp_ifthenelse(cond, ifso, Some ifnot) -> + Lifthenelse(transl_exp cond, + event_before ifso (transl_exp ifso), + event_before ifnot (transl_exp ifnot)) + | Texp_ifthenelse(cond, ifso, None) -> + Lifthenelse(transl_exp cond, + event_before ifso (transl_exp ifso), + lambda_unit) + | Texp_sequence(expr1, expr2) -> + Lsequence(transl_exp expr1, event_before expr2 (transl_exp expr2)) + | Texp_while(cond, body) -> + Lwhile(transl_exp cond, event_before body (transl_exp body)) + | Texp_for(param, low, high, dir, body) -> + Lfor(param, transl_exp low, transl_exp high, dir, + event_before body (transl_exp body)) + | Texp_when(cond, body) -> + event_before cond + (Lifthenelse(transl_exp cond, event_before body (transl_exp body), + staticfail)) + | Texp_send(expr, met) -> + let obj = transl_exp expr in + let lam = + match met with + Tmeth_val id -> Lsend (Self, Lvar id, obj, []) + | Tmeth_name nm -> + let (tag, cache) = Translobj.meth obj nm in + let kind = if cache = [] then Public else Cached in + Lsend (kind, tag, obj, cache) + in + event_after e lam + | Texp_new (cl, _) -> + Lapply(Lprim(Pfield 0, [transl_path cl]), [lambda_unit], Location.none) + | Texp_instvar(path_self, path) -> + Lprim(Parrayrefu Paddrarray, [transl_path path_self; transl_path path]) + | Texp_setinstvar(path_self, path, expr) -> + transl_setinstvar (transl_path path_self) path expr + | Texp_override(path_self, modifs) -> + let cpy = Ident.create "copy" in + Llet(Strict, cpy, + Lapply(Translobj.oo_prim "copy", [transl_path path_self], + Location.none), + List.fold_right + (fun (path, expr) rem -> + Lsequence(transl_setinstvar (Lvar cpy) path expr, rem)) + modifs + (Lvar cpy)) + | Texp_letmodule(id, modl, body) -> + Llet(Strict, id, !transl_module Tcoerce_none None modl, transl_exp body) + | Texp_assert (cond) -> + if !Clflags.noassert + then lambda_unit + else Lifthenelse (transl_exp cond, lambda_unit, assert_failed e.exp_loc) + | Texp_assertfalse -> assert_failed e.exp_loc + | Texp_lazy e -> + (* when e needs no computation (constants, identifiers, ...), we + optimize the translation just as Lazy.lazy_from_val would + do *) + begin match e.exp_desc with + (* a constant expr of type <> float gets compiled as itself *) + | Texp_constant + ( Const_int _ | Const_char _ | Const_string _ + | Const_int32 _ | Const_int64 _ | Const_nativeint _ ) + | Texp_function(_, _) + | Texp_construct ({cstr_arity = 0}, _) + -> transl_exp e + | Texp_constant(Const_float _) -> + Lprim(Pmakeblock(Obj.forward_tag, Immutable), [transl_exp e]) + | Texp_ident(_, _) -> (* according to the type *) + begin match e.exp_type.desc with + (* the following may represent a float/forward/lazy: need a + forward_tag *) + | Tvar | Tlink _ | Tsubst _ | Tunivar + | Tpoly(_,_) | Tfield(_,_,_,_) -> + Lprim(Pmakeblock(Obj.forward_tag, Immutable), [transl_exp e]) + (* the following cannot be represented as float/forward/lazy: + optimize *) + | Tarrow(_,_,_,_) | Ttuple _ | Tobject(_,_) | Tnil | Tvariant _ + -> transl_exp e + (* optimize predefined types (excepted float) *) + | Tconstr(_,_,_) -> + if has_base_type e Predef.path_int + || has_base_type e Predef.path_char + || has_base_type e Predef.path_string + || has_base_type e Predef.path_bool + || has_base_type e Predef.path_unit + || has_base_type e Predef.path_exn + || has_base_type e Predef.path_array + || has_base_type e Predef.path_list + || has_base_type e Predef.path_format6 + || has_base_type e Predef.path_option + || has_base_type e Predef.path_nativeint + || has_base_type e Predef.path_int32 + || has_base_type e Predef.path_int64 + then transl_exp e + else + Lprim(Pmakeblock(Obj.forward_tag, Immutable), [transl_exp e]) + end + (* other cases compile to a lazy block holding a function *) + | _ -> + let fn = Lfunction (Curried, [Ident.create "param"], transl_exp e) in + Lprim(Pmakeblock(Config.lazy_tag, Immutable), [fn]) + end + | Texp_object (cs, cty, meths) -> + let cl = Ident.create "class" in + !transl_object cl meths + { cl_desc = Tclass_structure cs; + cl_loc = e.exp_loc; + cl_type = Tcty_signature cty; + cl_env = e.exp_env } + +and transl_list expr_list = + List.map transl_exp expr_list + +and transl_cases pat_expr_list = + List.map + (fun (pat, expr) -> (pat, event_before expr (transl_exp expr))) + pat_expr_list + +and transl_tupled_cases patl_expr_list = + List.map (fun (patl, expr) -> (patl, transl_exp expr)) patl_expr_list + +and transl_apply lam sargs loc = + let lapply funct args = + match funct with + Lsend(k, lmet, lobj, largs) -> + Lsend(k, lmet, lobj, largs @ args) + | Levent(Lsend(k, lmet, lobj, largs), _) -> + Lsend(k, lmet, lobj, largs @ args) + | Lapply(lexp, largs, _) -> + Lapply(lexp, largs @ args, loc) + | lexp -> + Lapply(lexp, args, loc) + in + let rec build_apply lam args = function + (None, optional) :: l -> + let defs = ref [] in + let protect name lam = + match lam with + Lvar _ | Lconst _ -> lam + | _ -> + let id = Ident.create name in + defs := (id, lam) :: !defs; + Lvar id + in + let args, args' = + if List.for_all (fun (_,opt) -> opt = Optional) args then [], args + else args, [] in + let lam = + if args = [] then lam else lapply lam (List.rev_map fst args) in + let handle = protect "func" lam + and l = List.map (fun (arg, opt) -> may_map (protect "arg") arg, opt) l + and id_arg = Ident.create "param" in + let body = + match build_apply handle ((Lvar id_arg, optional)::args') l with + Lfunction(Curried, ids, lam) -> + Lfunction(Curried, id_arg::ids, lam) + | Levent(Lfunction(Curried, ids, lam), _) -> + Lfunction(Curried, id_arg::ids, lam) + | lam -> + Lfunction(Curried, [id_arg], lam) + in + List.fold_left + (fun body (id, lam) -> Llet(Strict, id, lam, body)) + body !defs + | (Some arg, optional) :: l -> + build_apply lam ((arg, optional) :: args) l + | [] -> + lapply lam (List.rev_map fst args) + in + build_apply lam [] (List.map (fun (x,o) -> may_map transl_exp x, o) sargs) + +and transl_function loc untuplify_fn repr partial pat_expr_list = + match pat_expr_list with + [pat, ({exp_desc = Texp_function(pl,partial')} as exp)] + when Parmatch.fluid pat -> + let param = name_pattern "param" pat_expr_list in + let ((_, params), body) = + transl_function exp.exp_loc false repr partial' pl in + ((Curried, param :: params), + Matching.for_function loc None (Lvar param) [pat, body] partial) + | ({pat_desc = Tpat_tuple pl}, _) :: _ when untuplify_fn -> + begin try + let size = List.length pl in + let pats_expr_list = + List.map + (fun (pat, expr) -> (Matching.flatten_pattern size pat, expr)) + pat_expr_list in + let params = List.map (fun p -> Ident.create "param") pl in + ((Tupled, params), + Matching.for_tupled_function loc params + (transl_tupled_cases pats_expr_list) partial) + with Matching.Cannot_flatten -> + let param = name_pattern "param" pat_expr_list in + ((Curried, [param]), + Matching.for_function loc repr (Lvar param) + (transl_cases pat_expr_list) partial) + end + | _ -> + let param = name_pattern "param" pat_expr_list in + ((Curried, [param]), + Matching.for_function loc repr (Lvar param) + (transl_cases pat_expr_list) partial) + +and transl_let rec_flag pat_expr_list body = + match rec_flag with + Nonrecursive | Default -> + let rec transl = function + [] -> + body + | (pat, expr) :: rem -> + Matching.for_let pat.pat_loc (transl_exp expr) pat (transl rem) + in transl pat_expr_list + | Recursive -> + let idlist = + List.map + (fun (pat, expr) -> + match pat.pat_desc with + Tpat_var id -> id + | _ -> raise(Error(pat.pat_loc, Illegal_letrec_pat))) + pat_expr_list in + let transl_case (pat, expr) id = + let lam = transl_exp expr in + if not (check_recursive_lambda idlist lam) then + raise(Error(expr.exp_loc, Illegal_letrec_expr)); + (id, lam) in + Lletrec(List.map2 transl_case pat_expr_list idlist, body) + +and transl_setinstvar self var expr = + Lprim(Parraysetu (if maybe_pointer expr then Paddrarray else Pintarray), + [self; transl_path var; transl_exp expr]) + +and transl_record all_labels repres lbl_expr_list opt_init_expr = + let size = Array.length all_labels in + (* Determine if there are "enough" new fields *) + if 3 + 2 * List.length lbl_expr_list >= size + then begin + (* Allocate new record with given fields (and remaining fields + taken from init_expr if any *) + let lv = Array.create (Array.length all_labels) staticfail in + let init_id = Ident.create "init" in + begin match opt_init_expr with + None -> () + | Some init_expr -> + for i = 0 to Array.length all_labels - 1 do + let access = + match all_labels.(i).lbl_repres with + Record_regular -> Pfield i + | Record_float -> Pfloatfield i in + lv.(i) <- Lprim(access, [Lvar init_id]) + done + end; + List.iter + (fun (lbl, expr) -> lv.(lbl.lbl_pos) <- transl_exp expr) + lbl_expr_list; + let ll = Array.to_list lv in + let mut = + if List.exists (fun (lbl, expr) -> lbl.lbl_mut = Mutable) lbl_expr_list + then Mutable + else Immutable in + let lam = + try + if mut = Mutable then raise Not_constant; + let cl = List.map extract_constant ll in + match repres with + Record_regular -> Lconst(Const_block(0, cl)) + | Record_float -> + Lconst(Const_float_array(List.map extract_float cl)) + with Not_constant -> + match repres with + Record_regular -> Lprim(Pmakeblock(0, mut), ll) + | Record_float -> Lprim(Pmakearray Pfloatarray, ll) in + begin match opt_init_expr with + None -> lam + | Some init_expr -> Llet(Strict, init_id, transl_exp init_expr, lam) + end + end else begin + (* Take a shallow copy of the init record, then mutate the fields + of the copy *) + (* If you change anything here, you will likely have to change + [check_recursive_recordwith] in this file. *) + let copy_id = Ident.create "newrecord" in + let rec update_field (lbl, expr) cont = + let upd = + match lbl.lbl_repres with + Record_regular -> Psetfield(lbl.lbl_pos, maybe_pointer expr) + | Record_float -> Psetfloatfield lbl.lbl_pos in + Lsequence(Lprim(upd, [Lvar copy_id; transl_exp expr]), cont) in + begin match opt_init_expr with + None -> assert false + | Some init_expr -> + Llet(Strict, copy_id, + Lprim(Pduprecord (repres, size), [transl_exp init_expr]), + List.fold_right update_field lbl_expr_list (Lvar copy_id)) + end + end + +(* Wrapper for class compilation *) + +(* +let transl_exp = transl_exp_wrap + +let transl_let rec_flag pat_expr_list body = + match pat_expr_list with + [] -> body + | (_, expr) :: _ -> + Translobj.oo_wrap expr.exp_env false + (transl_let rec_flag pat_expr_list) body +*) + +(* Compile an exception definition *) + +let transl_exception id path decl = + let name = + match path with + None -> Ident.name id + | Some p -> Path.name p in + Lprim(Pmakeblock(0, Immutable), [Lconst(Const_base(Const_string name))]) + +(* Error report *) + +open Format + +let report_error ppf = function + | Illegal_letrec_pat -> + fprintf ppf + "Only variables are allowed as left-hand side of `let rec'" + | Illegal_letrec_expr -> + fprintf ppf + "This kind of expression is not allowed as right-hand side of `let rec'" + | Free_super_var -> + fprintf ppf + "Ancestor names can only be used to select inherited methods" diff --git a/bytecomp/translcore.mli b/bytecomp/translcore.mli new file mode 100644 index 0000000..c50bda4 --- /dev/null +++ b/bytecomp/translcore.mli @@ -0,0 +1,51 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translcore.mli,v 1.19 2007-05-16 08:21:40 doligez Exp $ *) + +(* Translation from typed abstract syntax to lambda terms, + for the core language *) + +open Asttypes +open Types +open Typedtree +open Lambda + +val name_pattern: string -> (pattern * 'a) list -> Ident.t + +val transl_exp: expression -> lambda +val transl_apply: lambda -> (expression option * optional) list + -> Location.t -> lambda +val transl_let: + rec_flag -> (pattern * expression) list -> lambda -> lambda +val transl_primitive: Primitive.description -> lambda +val transl_exception: + Ident.t -> Path.t option -> exception_declaration -> lambda + +val check_recursive_lambda: Ident.t list -> lambda -> bool + +type error = + Illegal_letrec_pat + | Illegal_letrec_expr + | Free_super_var + +exception Error of Location.t * error + +open Format + +val report_error: formatter -> error -> unit + +(* Forward declaration -- to be filled in by Translmod.transl_module *) +val transl_module : + (module_coercion -> Path.t option -> module_expr -> lambda) ref +val transl_object : + (Ident.t -> string list -> class_expr -> lambda) ref diff --git a/bytecomp/translmod.ml b/bytecomp/translmod.ml new file mode 100644 index 0000000..94d9362 --- /dev/null +++ b/bytecomp/translmod.ml @@ -0,0 +1,712 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translmod.ml,v 1.56 2008-07-24 05:35:22 frisch Exp $ *) + +(* Translation from typed abstract syntax to lambda terms, + for the module language *) + +open Misc +open Asttypes +open Longident +open Path +open Types +open Typedtree +open Primitive +open Lambda +open Translobj +open Translcore +open Translclass + +type error = + Circular_dependency of Ident.t + +exception Error of Location.t * error + +(* Compile a coercion *) + +let rec apply_coercion restr arg = + match restr with + Tcoerce_none -> + arg + | Tcoerce_structure pos_cc_list -> + name_lambda arg (fun id -> + Lprim(Pmakeblock(0, Immutable), + List.map (apply_coercion_field id) pos_cc_list)) + | Tcoerce_functor(cc_arg, cc_res) -> + let param = Ident.create "funarg" in + name_lambda arg (fun id -> + Lfunction(Curried, [param], + apply_coercion cc_res + (Lapply(Lvar id, [apply_coercion cc_arg (Lvar param)], + Location.none)))) + | Tcoerce_primitive p -> + transl_primitive p + +and apply_coercion_field id (pos, cc) = + apply_coercion cc (Lprim(Pfield pos, [Lvar id])) + +(* Compose two coercions + apply_coercion c1 (apply_coercion c2 e) behaves like + apply_coercion (compose_coercions c1 c2) e. *) + +let rec compose_coercions c1 c2 = + match (c1, c2) with + (Tcoerce_none, c2) -> c2 + | (c1, Tcoerce_none) -> c1 + | (Tcoerce_structure pc1, Tcoerce_structure pc2) -> + let v2 = Array.of_list pc2 in + Tcoerce_structure + (List.map + (function (p1, Tcoerce_primitive p) -> + (p1, Tcoerce_primitive p) + | (p1, c1) -> + let (p2, c2) = v2.(p1) in (p2, compose_coercions c1 c2)) + pc1) + | (Tcoerce_functor(arg1, res1), Tcoerce_functor(arg2, res2)) -> + Tcoerce_functor(compose_coercions arg2 arg1, + compose_coercions res1 res2) + | (_, _) -> + fatal_error "Translmod.compose_coercions" + +(* Record the primitive declarations occuring in the module compiled *) + +let primitive_declarations = ref ([] : Primitive.description list) +let record_primitive = function + | {val_kind=Val_prim p} -> primitive_declarations := p :: !primitive_declarations + | _ -> () + +(* Keep track of the root path (from the root of the namespace to the + currently compiled module expression). Useful for naming exceptions. *) + +let global_path glob = Some(Pident glob) +let functor_path path param = + match path with + None -> None + | Some p -> Some(Papply(p, Pident param)) +let field_path path field = + match path with + None -> None + | Some p -> Some(Pdot(p, Ident.name field, Path.nopos)) + +(* Utilities for compiling "module rec" definitions *) + +let mod_prim name = + try + transl_path + (fst (Env.lookup_value (Ldot (Lident "CamlinternalMod", name)) + Env.empty)) + with Not_found -> + fatal_error ("Primitive " ^ name ^ " not found.") + +let undefined_location loc = + (* Confer Translcore.assert_failed *) + let fname = match loc.Location.loc_start.Lexing.pos_fname with + | "" -> !Location.input_name + | x -> x in + let pos = loc.Location.loc_start in + let line = pos.Lexing.pos_lnum in + let char = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in + Lconst(Const_block(0, + [Const_base(Const_string fname); + Const_base(Const_int line); + Const_base(Const_int char)])) + +let init_shape modl = + let rec init_shape_mod env mty = + match Mtype.scrape env mty with + Tmty_ident _ -> + raise Not_found + | Tmty_signature sg -> + Const_block(0, [Const_block(0, init_shape_struct env sg)]) + | Tmty_functor(id, arg, res) -> + raise Not_found (* can we do better? *) + and init_shape_struct env sg = + match sg with + [] -> [] + | Tsig_value(id, vdesc) :: rem -> + let init_v = + match Ctype.expand_head env vdesc.val_type with + {desc = Tarrow(_,_,_,_)} -> + Const_pointer 0 (* camlinternalMod.Function *) + | {desc = Tconstr(p, _, _)} when Path.same p Predef.path_lazy_t -> + Const_pointer 1 (* camlinternalMod.Lazy *) + | _ -> raise Not_found in + init_v :: init_shape_struct env rem + | Tsig_type(id, tdecl, _) :: rem -> + init_shape_struct (Env.add_type id tdecl env) rem + | Tsig_exception(id, edecl) :: rem -> + raise Not_found + | Tsig_module(id, mty, _) :: rem -> + init_shape_mod env mty :: + init_shape_struct (Env.add_module id mty env) rem + | Tsig_modtype(id, minfo) :: rem -> + init_shape_struct (Env.add_modtype id minfo env) rem + | Tsig_class(id, cdecl, _) :: rem -> + Const_pointer 2 (* camlinternalMod.Class *) + :: init_shape_struct env rem + | Tsig_cltype(id, ctyp, _) :: rem -> + init_shape_struct env rem + in + try + Some(undefined_location modl.mod_loc, + Lconst(init_shape_mod modl.mod_env modl.mod_type)) + with Not_found -> + None + +(* Reorder bindings to honor dependencies. *) + +type binding_status = Undefined | Inprogress | Defined + +let reorder_rec_bindings bindings = + let id = Array.of_list (List.map (fun (id,_,_,_) -> id) bindings) + and loc = Array.of_list (List.map (fun (_,loc,_,_) -> loc) bindings) + and init = Array.of_list (List.map (fun (_,_,init,_) -> init) bindings) + and rhs = Array.of_list (List.map (fun (_,_,_,rhs) -> rhs) bindings) in + let fv = Array.map Lambda.free_variables rhs in + let num_bindings = Array.length id in + let status = Array.create num_bindings Undefined in + let res = ref [] in + let rec emit_binding i = + match status.(i) with + Defined -> () + | Inprogress -> raise(Error(loc.(i), Circular_dependency id.(i))) + | Undefined -> + if init.(i) = None then begin + status.(i) <- Inprogress; + for j = 0 to num_bindings - 1 do + if IdentSet.mem id.(j) fv.(i) then emit_binding j + done + end; + res := (id.(i), init.(i), rhs.(i)) :: !res; + status.(i) <- Defined in + for i = 0 to num_bindings - 1 do + match status.(i) with + Undefined -> emit_binding i + | Inprogress -> assert false + | Defined -> () + done; + List.rev !res + +(* Generate lambda-code for a reordered list of bindings *) + +let eval_rec_bindings bindings cont = + let rec bind_inits = function + [] -> + bind_strict bindings + | (id, None, rhs) :: rem -> + bind_inits rem + | (id, Some(loc, shape), rhs) :: rem -> + Llet(Strict, id, Lapply(mod_prim "init_mod", [loc; shape], Location.none), + bind_inits rem) + and bind_strict = function + [] -> + patch_forwards bindings + | (id, None, rhs) :: rem -> + Llet(Strict, id, rhs, bind_strict rem) + | (id, Some(loc, shape), rhs) :: rem -> + bind_strict rem + and patch_forwards = function + [] -> + cont + | (id, None, rhs) :: rem -> + patch_forwards rem + | (id, Some(loc, shape), rhs) :: rem -> + Lsequence(Lapply(mod_prim "update_mod", [shape; Lvar id; rhs], + Location.none), + patch_forwards rem) + in + bind_inits bindings + +let compile_recmodule compile_rhs bindings cont = + eval_rec_bindings + (reorder_rec_bindings + (List.map + (fun (id, modl) -> + (id, modl.mod_loc, init_shape modl, compile_rhs id modl)) + bindings)) + cont + +(* Compile a module expression *) + +let rec transl_module cc rootpath mexp = + match mexp.mod_desc with + Tmod_ident path -> + apply_coercion cc (transl_path path) + | Tmod_structure str -> + transl_structure [] cc rootpath str + | Tmod_functor(param, mty, body) -> + let bodypath = functor_path rootpath param in + oo_wrap mexp.mod_env true + (function + | Tcoerce_none -> + Lfunction(Curried, [param], + transl_module Tcoerce_none bodypath body) + | Tcoerce_functor(ccarg, ccres) -> + let param' = Ident.create "funarg" in + Lfunction(Curried, [param'], + Llet(Alias, param, apply_coercion ccarg (Lvar param'), + transl_module ccres bodypath body)) + | _ -> + fatal_error "Translmod.transl_module") + cc + | Tmod_apply(funct, arg, ccarg) -> + oo_wrap mexp.mod_env true + (apply_coercion cc) + (Lapply(transl_module Tcoerce_none None funct, + [transl_module ccarg None arg], mexp.mod_loc)) + | Tmod_constraint(arg, mty, ccarg) -> + transl_module (compose_coercions cc ccarg) rootpath arg + +and transl_structure fields cc rootpath = function + [] -> + begin match cc with + Tcoerce_none -> + Lprim(Pmakeblock(0, Immutable), + List.map (fun id -> Lvar id) (List.rev fields)) + | Tcoerce_structure pos_cc_list -> + let v = Array.of_list (List.rev fields) in + Lprim(Pmakeblock(0, Immutable), + List.map + (fun (pos, cc) -> + match cc with + Tcoerce_primitive p -> transl_primitive p + | _ -> apply_coercion cc (Lvar v.(pos))) + pos_cc_list) + | _ -> + fatal_error "Translmod.transl_structure" + end + | Tstr_eval expr :: rem -> + Lsequence(transl_exp expr, transl_structure fields cc rootpath rem) + | Tstr_value(rec_flag, pat_expr_list) :: rem -> + let ext_fields = rev_let_bound_idents pat_expr_list @ fields in + transl_let rec_flag pat_expr_list + (transl_structure ext_fields cc rootpath rem) + | Tstr_primitive(id, descr) :: rem -> + record_primitive descr; + transl_structure fields cc rootpath rem + | Tstr_type(decls) :: rem -> + transl_structure fields cc rootpath rem + | Tstr_exception(id, decl) :: rem -> + Llet(Strict, id, transl_exception id (field_path rootpath id) decl, + transl_structure (id :: fields) cc rootpath rem) + | Tstr_exn_rebind(id, path) :: rem -> + Llet(Strict, id, transl_path path, + transl_structure (id :: fields) cc rootpath rem) + | Tstr_module(id, modl) :: rem -> + Llet(Strict, id, + transl_module Tcoerce_none (field_path rootpath id) modl, + transl_structure (id :: fields) cc rootpath rem) + | Tstr_recmodule bindings :: rem -> + let ext_fields = List.rev_append (List.map fst bindings) fields in + compile_recmodule + (fun id modl -> + transl_module Tcoerce_none (field_path rootpath id) modl) + bindings + (transl_structure ext_fields cc rootpath rem) + | Tstr_modtype(id, decl) :: rem -> + transl_structure fields cc rootpath rem + | Tstr_open path :: rem -> + transl_structure fields cc rootpath rem + | Tstr_class cl_list :: rem -> + let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + Lletrec(List.map + (fun (id, arity, meths, cl, vf) -> + (id, transl_class ids id arity meths cl vf)) + cl_list, + transl_structure (List.rev ids @ fields) cc rootpath rem) + | Tstr_cltype cl_list :: rem -> + transl_structure fields cc rootpath rem + | Tstr_include(modl, ids) :: rem -> + let mid = Ident.create "include" in + let rec rebind_idents pos newfields = function + [] -> + transl_structure newfields cc rootpath rem + | id :: ids -> + Llet(Alias, id, Lprim(Pfield pos, [Lvar mid]), + rebind_idents (pos + 1) (id :: newfields) ids) in + Llet(Strict, mid, transl_module Tcoerce_none None modl, + rebind_idents 0 fields ids) + +(* Update forward declaration in Translcore *) +let _ = + Translcore.transl_module := transl_module + +(* Compile an implementation *) + +let transl_implementation module_name (str, cc) = + reset_labels (); + primitive_declarations := []; + let module_id = Ident.create_persistent module_name in + Lprim(Psetglobal module_id, + [transl_label_init + (transl_structure [] cc (global_path module_id) str)]) + +(* A variant of transl_structure used to compile toplevel structure definitions + for the native-code compiler. Store the defined values in the fields + of the global as soon as they are defined, in order to reduce register + pressure. Also rewrites the defining expressions so that they + refer to earlier fields of the structure through the fields of + the global, not by their names. + "map" is a table from defined idents to (pos in global block, coercion). + "prim" is a list of (pos in global block, primitive declaration). *) + +let transl_store_subst = ref Ident.empty + (** In the native toplevel, this reference is threaded through successive + calls of transl_store_structure *) + +let nat_toplevel_name id = + try match Ident.find_same id !transl_store_subst with + | Lprim(Pfield pos, [Lprim(Pgetglobal glob, [])]) -> (glob,pos) + | _ -> raise Not_found + with Not_found -> + fatal_error("Translmod.nat_toplevel_name: " ^ Ident.unique_name id) + +let transl_store_structure glob map prims str = + let rec transl_store subst = function + [] -> + transl_store_subst := subst; + lambda_unit + | Tstr_eval expr :: rem -> + Lsequence(subst_lambda subst (transl_exp expr), + transl_store subst rem) + | Tstr_value(rec_flag, pat_expr_list) :: rem -> + let ids = let_bound_idents pat_expr_list in + let lam = transl_let rec_flag pat_expr_list (store_idents ids) in + Lsequence(subst_lambda subst lam, + transl_store (add_idents false ids subst) rem) + | Tstr_primitive(id, descr) :: rem -> + record_primitive descr; + transl_store subst rem + | Tstr_type(decls) :: rem -> + transl_store subst rem + | Tstr_exception(id, decl) :: rem -> + let lam = transl_exception id (field_path (global_path glob) id) decl in + Lsequence(Llet(Strict, id, lam, store_ident id), + transl_store (add_ident false id subst) rem) + | Tstr_exn_rebind(id, path) :: rem -> + let lam = subst_lambda subst (transl_path path) in + Lsequence(Llet(Strict, id, lam, store_ident id), + transl_store (add_ident false id subst) rem) + | Tstr_module(id, modl) :: rem -> + let lam = + transl_module Tcoerce_none (field_path (global_path glob) id) modl in + (* Careful: the module value stored in the global may be different + from the local module value, in case a coercion is applied. + If so, keep using the local module value (id) in the remainder of + the compilation unit (add_ident true returns subst unchanged). + If not, we can use the value from the global + (add_ident true adds id -> Pgetglobal... to subst). *) + Llet(Strict, id, subst_lambda subst lam, + Lsequence(store_ident id, transl_store(add_ident true id subst) rem)) + | Tstr_recmodule bindings :: rem -> + let ids = List.map fst bindings in + compile_recmodule + (fun id modl -> + subst_lambda subst + (transl_module Tcoerce_none + (field_path (global_path glob) id) modl)) + bindings + (Lsequence(store_idents ids, + transl_store (add_idents true ids subst) rem)) + | Tstr_modtype(id, decl) :: rem -> + transl_store subst rem + | Tstr_open path :: rem -> + transl_store subst rem + | Tstr_class cl_list :: rem -> + let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + let lam = + Lletrec(List.map + (fun (id, arity, meths, cl, vf) -> + (id, transl_class ids id arity meths cl vf)) + cl_list, + store_idents ids) in + Lsequence(subst_lambda subst lam, + transl_store (add_idents false ids subst) rem) + | Tstr_cltype cl_list :: rem -> + transl_store subst rem + | Tstr_include(modl, ids) :: rem -> + let mid = Ident.create "include" in + let rec store_idents pos = function + [] -> transl_store (add_idents true ids subst) rem + | id :: idl -> + Llet(Alias, id, Lprim(Pfield pos, [Lvar mid]), + Lsequence(store_ident id, store_idents (pos + 1) idl)) in + Llet(Strict, mid, + subst_lambda subst (transl_module Tcoerce_none None modl), + store_idents 0 ids) + + and store_ident id = + try + let (pos, cc) = Ident.find_same id map in + let init_val = apply_coercion cc (Lvar id) in + Lprim(Psetfield(pos, false), [Lprim(Pgetglobal glob, []); init_val]) + with Not_found -> + fatal_error("Translmod.store_ident: " ^ Ident.unique_name id) + + and store_idents idlist = + make_sequence store_ident idlist + + and add_ident may_coerce id subst = + try + let (pos, cc) = Ident.find_same id map in + match cc with + Tcoerce_none -> + Ident.add id (Lprim(Pfield pos, [Lprim(Pgetglobal glob, [])])) subst + | _ -> + if may_coerce then subst else assert false + with Not_found -> + assert false + + and add_idents may_coerce idlist subst = + List.fold_right (add_ident may_coerce) idlist subst + + and store_primitive (pos, prim) cont = + Lsequence(Lprim(Psetfield(pos, false), + [Lprim(Pgetglobal glob, []); transl_primitive prim]), + cont) + + in List.fold_right store_primitive prims (transl_store !transl_store_subst str) + +(* Build the list of value identifiers defined by a toplevel structure + (excluding primitive declarations). *) + +let rec defined_idents = function + [] -> [] + | Tstr_eval expr :: rem -> defined_idents rem + | Tstr_value(rec_flag, pat_expr_list) :: rem -> + let_bound_idents pat_expr_list @ defined_idents rem + | Tstr_primitive(id, descr) :: rem -> defined_idents rem + | Tstr_type decls :: rem -> defined_idents rem + | Tstr_exception(id, decl) :: rem -> id :: defined_idents rem + | Tstr_exn_rebind(id, path) :: rem -> id :: defined_idents rem + | Tstr_module(id, modl) :: rem -> id :: defined_idents rem + | Tstr_recmodule decls :: rem -> List.map fst decls @ defined_idents rem + | Tstr_modtype(id, decl) :: rem -> defined_idents rem + | Tstr_open path :: rem -> defined_idents rem + | Tstr_class cl_list :: rem -> + List.map (fun (i, _, _, _, _) -> i) cl_list @ defined_idents rem + | Tstr_cltype cl_list :: rem -> defined_idents rem + | Tstr_include(modl, ids) :: rem -> ids @ defined_idents rem + +(* Transform a coercion and the list of value identifiers defined by + a toplevel structure into a table [id -> (pos, coercion)], + with [pos] being the position in the global block where the value of + [id] must be stored, and [coercion] the coercion to be applied to it. + A given identifier may appear several times + in the coercion (if it occurs several times in the signature); remember + to assign it the position of its last occurrence. + Identifiers that are not exported are assigned positions at the + end of the block (beyond the positions of all exported idents). + Also compute the total size of the global block, + and the list of all primitives exported as values. *) + +let build_ident_map restr idlist = + let rec natural_map pos map prims = function + [] -> + (map, prims, pos) + | id :: rem -> + natural_map (pos+1) (Ident.add id (pos, Tcoerce_none) map) prims rem in + match restr with + Tcoerce_none -> + natural_map 0 Ident.empty [] idlist + | Tcoerce_structure pos_cc_list -> + let idarray = Array.of_list idlist in + let rec export_map pos map prims undef = function + [] -> + natural_map pos map prims undef + | (source_pos, Tcoerce_primitive p) :: rem -> + export_map (pos + 1) map ((pos, p) :: prims) undef rem + | (source_pos, cc) :: rem -> + let id = idarray.(source_pos) in + export_map (pos + 1) (Ident.add id (pos, cc) map) + prims (list_remove id undef) rem + in export_map 0 Ident.empty [] idlist pos_cc_list + | _ -> + fatal_error "Translmod.build_ident_map" + +(* Compile an implementation using transl_store_structure + (for the native-code compiler). *) + +let transl_store_gen module_name (str, restr) topl = + reset_labels (); + primitive_declarations := []; + let module_id = Ident.create_persistent module_name in + let (map, prims, size) = build_ident_map restr (defined_idents str) in + let f = function + | [ Tstr_eval expr ] when topl -> + assert (size = 0); + subst_lambda !transl_store_subst (transl_exp expr) + | str -> transl_store_structure module_id map prims str in + transl_store_label_init module_id size f str + (*size, transl_label_init (transl_store_structure module_id map prims str)*) + +let transl_store_phrases module_name str = + transl_store_gen module_name (str,Tcoerce_none) true + +let transl_store_implementation module_name (str, restr) = + let s = !transl_store_subst in + transl_store_subst := Ident.empty; + let r = transl_store_gen module_name (str, restr) false in + transl_store_subst := s; + r + +(* Compile a toplevel phrase *) + +let toploop_ident = Ident.create_persistent "Toploop" +let toploop_getvalue_pos = 0 (* position of getvalue in module Toploop *) +let toploop_setvalue_pos = 1 (* position of setvalue in module Toploop *) + +let aliased_idents = ref Ident.empty + +let set_toplevel_unique_name id = + aliased_idents := + Ident.add id (Ident.unique_toplevel_name id) !aliased_idents + +let toplevel_name id = + try Ident.find_same id !aliased_idents + with Not_found -> Ident.name id + +let toploop_getvalue id = + Lapply(Lprim(Pfield toploop_getvalue_pos, + [Lprim(Pgetglobal toploop_ident, [])]), + [Lconst(Const_base(Const_string (toplevel_name id)))], + Location.none) + +let toploop_setvalue id lam = + Lapply(Lprim(Pfield toploop_setvalue_pos, + [Lprim(Pgetglobal toploop_ident, [])]), + [Lconst(Const_base(Const_string (toplevel_name id))); lam], + Location.none) + +let toploop_setvalue_id id = toploop_setvalue id (Lvar id) + +let close_toplevel_term lam = + IdentSet.fold (fun id l -> Llet(Strict, id, toploop_getvalue id, l)) + (free_variables lam) lam + +let transl_toplevel_item = function + Tstr_eval expr -> + transl_exp expr + | Tstr_value(rec_flag, pat_expr_list) -> + let idents = let_bound_idents pat_expr_list in + transl_let rec_flag pat_expr_list + (make_sequence toploop_setvalue_id idents) + | Tstr_primitive(id, descr) -> + lambda_unit + | Tstr_type(decls) -> + lambda_unit + | Tstr_exception(id, decl) -> + toploop_setvalue id (transl_exception id None decl) + | Tstr_exn_rebind(id, path) -> + toploop_setvalue id (transl_path path) + | Tstr_module(id, modl) -> + (* we need to use the unique name for the module because of issues + with "open" (PR#1672) *) + set_toplevel_unique_name id; + toploop_setvalue id + (transl_module Tcoerce_none (Some(Pident id)) modl) + | Tstr_recmodule bindings -> + let idents = List.map fst bindings in + compile_recmodule + (fun id modl -> transl_module Tcoerce_none (Some(Pident id)) modl) + bindings + (make_sequence toploop_setvalue_id idents) + | Tstr_modtype(id, decl) -> + lambda_unit + | Tstr_open path -> + lambda_unit + | Tstr_class cl_list -> + (* we need to use unique names for the classes because there might + be a value named identically *) + let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + List.iter set_toplevel_unique_name ids; + Lletrec(List.map + (fun (id, arity, meths, cl, vf) -> + (id, transl_class ids id arity meths cl vf)) + cl_list, + make_sequence + (fun (id, _, _, _, _) -> toploop_setvalue_id id) + cl_list) + | Tstr_cltype cl_list -> + lambda_unit + | Tstr_include(modl, ids) -> + let mid = Ident.create "include" in + let rec set_idents pos = function + [] -> + lambda_unit + | id :: ids -> + Lsequence(toploop_setvalue id (Lprim(Pfield pos, [Lvar mid])), + set_idents (pos + 1) ids) in + Llet(Strict, mid, transl_module Tcoerce_none None modl, set_idents 0 ids) + +let transl_toplevel_item_and_close itm = + close_toplevel_term (transl_label_init (transl_toplevel_item itm)) + +let transl_toplevel_definition str = + reset_labels (); + make_sequence transl_toplevel_item_and_close str + +(* Compile the initialization code for a packed library *) + +let get_component = function + None -> Lconst const_unit + | Some id -> Lprim(Pgetglobal id, []) + +let transl_package component_names target_name coercion = + let components = + match coercion with + Tcoerce_none -> + List.map get_component component_names + | Tcoerce_structure pos_cc_list -> + let g = Array.of_list component_names in + List.map + (fun (pos, cc) -> apply_coercion cc (get_component g.(pos))) + pos_cc_list + | _ -> + assert false in + Lprim(Psetglobal target_name, [Lprim(Pmakeblock(0, Immutable), components)]) + +let transl_store_package component_names target_name coercion = + let rec make_sequence fn pos arg = + match arg with + [] -> lambda_unit + | hd :: tl -> Lsequence(fn pos hd, make_sequence fn (pos + 1) tl) in + match coercion with + Tcoerce_none -> + (List.length component_names, + make_sequence + (fun pos id -> + Lprim(Psetfield(pos, false), + [Lprim(Pgetglobal target_name, []); + get_component id])) + 0 component_names) + | Tcoerce_structure pos_cc_list -> + let id = Array.of_list component_names in + (List.length pos_cc_list, + make_sequence + (fun dst (src, cc) -> + Lprim(Psetfield(dst, false), + [Lprim(Pgetglobal target_name, []); + apply_coercion cc (get_component id.(src))])) + 0 pos_cc_list) + | _ -> assert false + +(* Error report *) + +open Format + +let report_error ppf = function + Circular_dependency id -> + fprintf ppf + "@[Cannot safely evaluate the definition@ of the recursively-defined module %a@]" + Printtyp.ident id diff --git a/bytecomp/translmod.mli b/bytecomp/translmod.mli new file mode 100644 index 0000000..5c8ed33 --- /dev/null +++ b/bytecomp/translmod.mli @@ -0,0 +1,41 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translmod.mli,v 1.14 2008-07-24 05:35:22 frisch Exp $ *) + +(* Translation from typed abstract syntax to lambda terms, + for the module language *) + +open Typedtree +open Lambda + +val transl_implementation: string -> structure * module_coercion -> lambda +val transl_store_phrases: string -> structure -> int * lambda +val transl_store_implementation: + string -> structure * module_coercion -> int * lambda +val transl_toplevel_definition: structure -> lambda +val transl_package: + Ident.t option list -> Ident.t -> module_coercion -> lambda +val transl_store_package: + Ident.t option list -> Ident.t -> module_coercion -> int * lambda + +val toplevel_name: Ident.t -> string +val nat_toplevel_name: Ident.t -> Ident.t * int + +val primitive_declarations: Primitive.description list ref + +type error = + Circular_dependency of Ident.t + +exception Error of Location.t * error + +val report_error: Format.formatter -> error -> unit diff --git a/bytecomp/translobj.ml b/bytecomp/translobj.ml new file mode 100644 index 0000000..a71b1f6 --- /dev/null +++ b/bytecomp/translobj.ml @@ -0,0 +1,160 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translobj.ml,v 1.11 2008-12-03 18:09:09 doligez Exp $ *) + +open Misc +open Primitive +open Asttypes +open Longident +open Lambda + +(* Get oo primitives identifiers *) + +let oo_prim name = + try + transl_path + (fst (Env.lookup_value (Ldot (Lident "CamlinternalOO", name)) Env.empty)) + with Not_found -> + fatal_error ("Primitive " ^ name ^ " not found.") + +(* Share blocks *) + +let consts : (structured_constant, Ident.t) Hashtbl.t = Hashtbl.create 17 + +let share c = + match c with + Const_block (n, l) when l <> [] -> + begin try + Lvar (Hashtbl.find consts c) + with Not_found -> + let id = Ident.create "shared" in + Hashtbl.add consts c id; + Lvar id + end + | _ -> Lconst c + +(* Collect labels *) + +let cache_required = ref false +let method_cache = ref lambda_unit +let method_count = ref 0 +let method_table = ref [] + +let meth_tag s = Lconst(Const_base(Const_int(Btype.hash_variant s))) + +let next_cache tag = + let n = !method_count in + incr method_count; + (tag, [!method_cache; Lconst(Const_base(Const_int n))]) + +let rec is_path = function + Lvar _ | Lprim (Pgetglobal _, []) | Lconst _ -> true + | Lprim (Pfield _, [lam]) -> is_path lam + | Lprim ((Parrayrefu _ | Parrayrefs _), [lam1; lam2]) -> + is_path lam1 && is_path lam2 + | _ -> false + +let meth obj lab = + let tag = meth_tag lab in + if not (!cache_required && !Clflags.native_code) then (tag, []) else + if not (is_path obj) then next_cache tag else + try + let r = List.assoc obj !method_table in + try + (tag, List.assoc tag !r) + with Not_found -> + let p = next_cache tag in + r := p :: !r; + p + with Not_found -> + let p = next_cache tag in + method_table := (obj, ref [p]) :: !method_table; + p + +let reset_labels () = + Hashtbl.clear consts; + method_count := 0; + method_table := [] + +(* Insert labels *) + +let string s = Lconst (Const_base (Const_string s)) +let int n = Lconst (Const_base (Const_int n)) + +let prim_makearray = + { prim_name = "caml_make_vect"; prim_arity = 2; prim_alloc = true; + prim_native_name = ""; prim_native_float = false } + +let transl_label_init expr = + let expr = + Hashtbl.fold + (fun c id expr -> Llet(Alias, id, Lconst c, expr)) + consts expr + in + reset_labels (); + expr + +let transl_store_label_init glob size f arg = + method_cache := Lprim(Pfield size, [Lprim(Pgetglobal glob, [])]); + let expr = f arg in + let (size, expr) = + if !method_count = 0 then (size, expr) else + (size+1, + Lsequence( + Lprim(Psetfield(size, false), + [Lprim(Pgetglobal glob, []); + Lprim (Pccall prim_makearray, [int !method_count; int 0])]), + expr)) + in + (size, transl_label_init expr) + +(* Share classes *) + +let wrapping = ref false +let top_env = ref Env.empty +let classes = ref [] +let method_ids = ref IdentSet.empty + +let oo_add_class id = + classes := id :: !classes; + (!top_env, !cache_required) + +let oo_wrap env req f x = + if !wrapping then + if !cache_required then f x else + try cache_required := true; let lam = f x in cache_required := false; lam + with exn -> cache_required := false; raise exn + else try + wrapping := true; + cache_required := req; + top_env := env; + classes := []; + method_ids := IdentSet.empty; + let lambda = f x in + let lambda = + List.fold_left + (fun lambda id -> + Llet(StrictOpt, id, + Lprim(Pmakeblock(0, Mutable), + [lambda_unit; lambda_unit; lambda_unit]), + lambda)) + lambda !classes + in + wrapping := false; + top_env := Env.empty; + lambda + with exn -> + wrapping := false; + top_env := Env.empty; + raise exn + diff --git a/bytecomp/translobj.mli b/bytecomp/translobj.mli new file mode 100644 index 0000000..6f4661b --- /dev/null +++ b/bytecomp/translobj.mli @@ -0,0 +1,30 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: translobj.mli,v 1.8 2008-12-03 18:09:09 doligez Exp $ *) + +open Lambda + +val oo_prim: string -> lambda + +val share: structured_constant -> lambda +val meth: lambda -> string -> lambda * lambda list + +val reset_labels: unit -> unit +val transl_label_init: lambda -> lambda +val transl_store_label_init: + Ident.t -> int -> ('a -> lambda) -> 'a -> int * lambda + +val method_ids: IdentSet.t ref (* reset when starting a new wrapper *) + +val oo_wrap: Env.t -> bool -> ('a -> lambda) -> 'a -> lambda +val oo_add_class: Ident.t -> Env.t * bool diff --git a/bytecomp/typeopt.ml b/bytecomp/typeopt.ml new file mode 100644 index 0000000..c8e587a --- /dev/null +++ b/bytecomp/typeopt.ml @@ -0,0 +1,134 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typeopt.ml,v 1.13 2008-02-29 14:21:22 doligez Exp $ *) + +(* Auxiliaries for type-based optimizations, e.g. array kinds *) + +open Misc +open Asttypes +open Primitive +open Path +open Types +open Typedtree +open Lambda + +let has_base_type exp base_ty_path = + let exp_ty = + Ctype.expand_head_opt exp.exp_env (Ctype.correct_levels exp.exp_type) in + match Ctype.repr exp_ty with + {desc = Tconstr(p, _, _)} -> Path.same p base_ty_path + | _ -> false + +let maybe_pointer exp = + let exp_ty = + Ctype.expand_head_opt exp.exp_env (Ctype.correct_levels exp.exp_type) in + match (Ctype.repr exp_ty).desc with + Tconstr(p, args, abbrev) -> + not (Path.same p Predef.path_int) && + not (Path.same p Predef.path_char) && + begin try + match Env.find_type p exp.exp_env with + {type_kind = Type_variant []} -> true (* type exn *) + | {type_kind = Type_variant cstrs} -> + List.exists (fun (name, args) -> args <> []) cstrs + | _ -> true + with Not_found -> true + (* This can happen due to e.g. missing -I options, + causing some .cmi files to be unavailable. + Maybe we should emit a warning. *) + end + | _ -> true + +let array_element_kind env ty = + let ty = Ctype.repr (Ctype.expand_head_opt env ty) in + match ty.desc with + Tvar | Tunivar -> + Pgenarray + | Tconstr(p, args, abbrev) -> + if Path.same p Predef.path_int || Path.same p Predef.path_char then + Pintarray + else if Path.same p Predef.path_float then + Pfloatarray + else if Path.same p Predef.path_string + || Path.same p Predef.path_array + || Path.same p Predef.path_nativeint + || Path.same p Predef.path_int32 + || Path.same p Predef.path_int64 then + Paddrarray + else begin + try + match Env.find_type p env with + {type_kind = Type_abstract} -> + Pgenarray + | {type_kind = Type_variant cstrs} + when List.for_all (fun (name, args) -> args = []) cstrs -> + Pintarray + | {type_kind = _} -> + Paddrarray + with Not_found -> + (* This can happen due to e.g. missing -I options, + causing some .cmi files to be unavailable. + Maybe we should emit a warning. *) + Pgenarray + end + | _ -> + Paddrarray + +let array_kind_gen ty env = + let array_ty = Ctype.expand_head_opt env (Ctype.correct_levels ty) in + match (Ctype.repr array_ty).desc with + Tconstr(p, [elt_ty], _) | Tpoly({desc = Tconstr(p, [elt_ty], _)}, _) + when Path.same p Predef.path_array -> + array_element_kind env elt_ty + | _ -> + (* This can happen with e.g. Obj.field *) + Pgenarray + +let array_kind exp = array_kind_gen exp.exp_type exp.exp_env + +let array_pattern_kind pat = array_kind_gen pat.pat_type pat.pat_env + +let bigarray_decode_type ty tbl dfl = + match (Ctype.repr ty).desc with + Tconstr(Pdot(Pident mod_id, type_name, _), [], _) + when Ident.name mod_id = "Bigarray" -> + begin try List.assoc type_name tbl with Not_found -> dfl end + | _ -> + dfl + +let kind_table = + ["float32_elt", Pbigarray_float32; + "float64_elt", Pbigarray_float64; + "int8_signed_elt", Pbigarray_sint8; + "int8_unsigned_elt", Pbigarray_uint8; + "int16_signed_elt", Pbigarray_sint16; + "int16_unsigned_elt", Pbigarray_uint16; + "int32_elt", Pbigarray_int32; + "int64_elt", Pbigarray_int64; + "int_elt", Pbigarray_caml_int; + "nativeint_elt", Pbigarray_native_int; + "complex32_elt", Pbigarray_complex32; + "complex64_elt", Pbigarray_complex64] + +let layout_table = + ["c_layout", Pbigarray_c_layout; + "fortran_layout", Pbigarray_fortran_layout] + +let bigarray_kind_and_layout exp = + let ty = Ctype.repr (Ctype.expand_head_opt exp.exp_env exp.exp_type) in + match ty.desc with + Tconstr(p, [caml_type; elt_type; layout_type], abbrev) -> + (bigarray_decode_type elt_type kind_table Pbigarray_unknown, + bigarray_decode_type layout_type layout_table Pbigarray_unknown_layout) + | _ -> + (Pbigarray_unknown, Pbigarray_unknown_layout) diff --git a/bytecomp/typeopt.mli b/bytecomp/typeopt.mli new file mode 100644 index 0000000..133a3b0 --- /dev/null +++ b/bytecomp/typeopt.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typeopt.mli,v 1.4 2000-02-28 15:45:50 xleroy Exp $ *) + +(* Auxiliaries for type-based optimizations, e.g. array kinds *) + +val has_base_type : Typedtree.expression -> Path.t -> bool +val maybe_pointer : Typedtree.expression -> bool +val array_kind : Typedtree.expression -> Lambda.array_kind +val array_pattern_kind : Typedtree.pattern -> Lambda.array_kind +val bigarray_kind_and_layout : + Typedtree.expression -> Lambda.bigarray_kind * Lambda.bigarray_layout diff --git a/byterun/.cvsignore b/byterun/.cvsignore new file mode 100644 index 0000000..9020f40 --- /dev/null +++ b/byterun/.cvsignore @@ -0,0 +1,17 @@ +jumptbl.h +primitives +prims.c +opnames.h +version.h +ocamlrun +ocamlrund +ld.conf +libcamlrun.x +libcamlrun-gui.x +*.c.x +ocamlrun.xcoff +ocamlrun.dbg +interp.a.lst +*.[sd]obj +*.lib +.gdb_history diff --git a/byterun/.depend b/byterun/.depend new file mode 100644 index 0000000..6366bde --- /dev/null +++ b/byterun/.depend @@ -0,0 +1,410 @@ +alloc.o: alloc.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h stacks.h +array.o: array.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +backtrace.o: backtrace.c config.h ../config/m.h ../config/s.h \ + compatibility.h mlvalues.h misc.h alloc.h io.h instruct.h intext.h \ + fix_code.h exec.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + startup.h stacks.h sys.h backtrace.h +callback.o: callback.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h interp.h instruct.h fix_code.h stacks.h +compact.o: compact.c config.h ../config/m.h ../config/s.h compatibility.h \ + finalise.h roots.h misc.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h gc_ctrl.h weak.h +compare.o: compare.c custom.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +custom.o: custom.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +debugger.o: debugger.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fail.h fix_code.h \ + instruct.h intext.h io.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h sys.h +dynlink.o: dynlink.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h dynlink.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h osdeps.h prims.h +extern.o: extern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +fail.o: fail.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h io.h gc.h memory.h major_gc.h \ + freelist.h minor_gc.h printexc.h signals.h stacks.h +finalise.o: finalise.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h roots.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h signals.h +fix_code.o: fix_code.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fix_code.h instruct.h \ + md5.h io.h memory.h gc.h major_gc.h freelist.h minor_gc.h reverse.h +floats.o: floats.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h reverse.h stacks.h +freelist.o: freelist.c config.h ../config/m.h ../config/s.h \ + compatibility.h freelist.h misc.h mlvalues.h gc.h gc_ctrl.h memory.h \ + major_gc.h minor_gc.h +gc_ctrl.o: gc_ctrl.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h compact.h custom.h finalise.h \ + roots.h memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h \ + stacks.h +globroots.o: globroots.c memory.h compatibility.h config.h ../config/m.h \ + ../config/s.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + roots.h globroots.h +hash.o: hash.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h custom.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +instrtrace.o: instrtrace.c +intern.o: intern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +interp.o: interp.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h backtrace.h callback.h debugger.h fail.h \ + fix_code.h instrtrace.h instruct.h interp.h major_gc.h freelist.h \ + memory.h gc.h minor_gc.h prims.h signals.h stacks.h jumptbl.h +ints.o: ints.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h intext.h io.h fix_code.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h int64_native.h +io.o: io.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h custom.h fail.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h signals.h sys.h +lexing.o: lexing.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +main.o: main.c misc.h compatibility.h config.h ../config/m.h \ + ../config/s.h mlvalues.h sys.h +major_gc.o: major_gc.c compact.h config.h ../config/m.h ../config/s.h \ + compatibility.h misc.h custom.h mlvalues.h fail.h finalise.h roots.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h weak.h +md5.o: md5.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h md5.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h reverse.h +memory.o: memory.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h freelist.h gc.h gc_ctrl.h major_gc.h memory.h \ + minor_gc.h signals.h +meta.o: meta.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h fix_code.h interp.h intext.h io.h \ + major_gc.h freelist.h memory.h gc.h minor_gc.h prims.h stacks.h +minor_gc.o: minor_gc.c config.h ../config/m.h ../config/s.h \ + compatibility.h fail.h misc.h mlvalues.h finalise.h roots.h memory.h \ + gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h signals.h weak.h +misc.o: misc.c config.h ../config/m.h ../config/s.h compatibility.h \ + misc.h memory.h gc.h mlvalues.h major_gc.h freelist.h minor_gc.h +obj.o: obj.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h gc.h interp.h major_gc.h freelist.h \ + memory.h minor_gc.h prims.h +parsing.o: parsing.c config.h ../config/m.h ../config/s.h compatibility.h \ + mlvalues.h misc.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + alloc.h +prims.o: prims.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h prims.h +printexc.o: printexc.c backtrace.h mlvalues.h compatibility.h config.h \ + ../config/m.h ../config/s.h misc.h callback.h debugger.h fail.h \ + printexc.h +roots.o: roots.c finalise.h roots.h misc.h compatibility.h config.h \ + ../config/m.h ../config/s.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h globroots.h stacks.h +signals_byt.o: signals_byt.c config.h ../config/m.h ../config/s.h \ + compatibility.h memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h \ + minor_gc.h osdeps.h signals.h signals_machdep.h +signals.o: signals.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h callback.h fail.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h roots.h signals.h signals_machdep.h \ + sys.h +stacks.o: stacks.c config.h ../config/m.h ../config/s.h compatibility.h \ + fail.h misc.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +startup.o: startup.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h backtrace.h callback.h custom.h debugger.h \ + dynlink.h exec.h fail.h fix_code.h freelist.h gc_ctrl.h instrtrace.h \ + interp.h intext.h io.h memory.h gc.h major_gc.h minor_gc.h osdeps.h \ + prims.h printexc.h reverse.h signals.h stacks.h sys.h startup.h \ + version.h +str.o: str.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h +sys.o: sys.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h debugger.h fail.h instruct.h osdeps.h signals.h \ + stacks.h memory.h gc.h major_gc.h freelist.h minor_gc.h sys.h +terminfo.o: terminfo.c config.h ../config/m.h ../config/s.h \ + compatibility.h alloc.h misc.h mlvalues.h fail.h io.h +unix.o: unix.c config.h ../config/m.h ../config/s.h compatibility.h \ + memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + osdeps.h +weak.o: weak.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h +alloc.d.o: alloc.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h stacks.h +array.d.o: array.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +backtrace.d.o: backtrace.c config.h ../config/m.h ../config/s.h \ + compatibility.h mlvalues.h misc.h alloc.h io.h instruct.h intext.h \ + fix_code.h exec.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + startup.h stacks.h sys.h backtrace.h +callback.d.o: callback.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h interp.h instruct.h fix_code.h stacks.h +compact.d.o: compact.c config.h ../config/m.h ../config/s.h compatibility.h \ + finalise.h roots.h misc.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h gc_ctrl.h weak.h +compare.d.o: compare.c custom.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +custom.d.o: custom.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +debugger.d.o: debugger.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fail.h fix_code.h \ + instruct.h intext.h io.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h sys.h +dynlink.d.o: dynlink.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h dynlink.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h osdeps.h prims.h +extern.d.o: extern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +fail.d.o: fail.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h io.h gc.h memory.h major_gc.h \ + freelist.h minor_gc.h printexc.h signals.h stacks.h +finalise.d.o: finalise.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h roots.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h signals.h +fix_code.d.o: fix_code.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fix_code.h instruct.h \ + md5.h io.h memory.h gc.h major_gc.h freelist.h minor_gc.h reverse.h +floats.d.o: floats.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h reverse.h stacks.h +freelist.d.o: freelist.c config.h ../config/m.h ../config/s.h \ + compatibility.h freelist.h misc.h mlvalues.h gc.h gc_ctrl.h memory.h \ + major_gc.h minor_gc.h +gc_ctrl.d.o: gc_ctrl.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h compact.h custom.h finalise.h \ + roots.h memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h \ + stacks.h +globroots.d.o: globroots.c memory.h compatibility.h config.h ../config/m.h \ + ../config/s.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + roots.h globroots.h +hash.d.o: hash.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h custom.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +instrtrace.d.o: instrtrace.c instruct.h misc.h compatibility.h config.h \ + ../config/m.h ../config/s.h mlvalues.h opnames.h prims.h stacks.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h +intern.d.o: intern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +interp.d.o: interp.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h backtrace.h callback.h debugger.h fail.h \ + fix_code.h instrtrace.h instruct.h interp.h major_gc.h freelist.h \ + memory.h gc.h minor_gc.h prims.h signals.h stacks.h +ints.d.o: ints.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h intext.h io.h fix_code.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h int64_native.h +io.d.o: io.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h custom.h fail.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h signals.h sys.h +lexing.d.o: lexing.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +main.d.o: main.c misc.h compatibility.h config.h ../config/m.h \ + ../config/s.h mlvalues.h sys.h +major_gc.d.o: major_gc.c compact.h config.h ../config/m.h ../config/s.h \ + compatibility.h misc.h custom.h mlvalues.h fail.h finalise.h roots.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h weak.h +md5.d.o: md5.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h md5.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h reverse.h +memory.d.o: memory.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h freelist.h gc.h gc_ctrl.h major_gc.h memory.h \ + minor_gc.h signals.h +meta.d.o: meta.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h fix_code.h interp.h intext.h io.h \ + major_gc.h freelist.h memory.h gc.h minor_gc.h prims.h stacks.h +minor_gc.d.o: minor_gc.c config.h ../config/m.h ../config/s.h \ + compatibility.h fail.h misc.h mlvalues.h finalise.h roots.h memory.h \ + gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h signals.h weak.h +misc.d.o: misc.c config.h ../config/m.h ../config/s.h compatibility.h \ + misc.h memory.h gc.h mlvalues.h major_gc.h freelist.h minor_gc.h +obj.d.o: obj.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h gc.h interp.h major_gc.h freelist.h \ + memory.h minor_gc.h prims.h +parsing.d.o: parsing.c config.h ../config/m.h ../config/s.h compatibility.h \ + mlvalues.h misc.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + alloc.h +prims.d.o: prims.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h prims.h +printexc.d.o: printexc.c backtrace.h mlvalues.h compatibility.h config.h \ + ../config/m.h ../config/s.h misc.h callback.h debugger.h fail.h \ + printexc.h +roots.d.o: roots.c finalise.h roots.h misc.h compatibility.h config.h \ + ../config/m.h ../config/s.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h globroots.h stacks.h +signals_byt.d.o: signals_byt.c config.h ../config/m.h ../config/s.h \ + compatibility.h memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h \ + minor_gc.h osdeps.h signals.h signals_machdep.h +signals.d.o: signals.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h callback.h fail.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h roots.h signals.h signals_machdep.h \ + sys.h +stacks.d.o: stacks.c config.h ../config/m.h ../config/s.h compatibility.h \ + fail.h misc.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +startup.d.o: startup.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h backtrace.h callback.h custom.h debugger.h \ + dynlink.h exec.h fail.h fix_code.h freelist.h gc_ctrl.h instrtrace.h \ + interp.h intext.h io.h memory.h gc.h major_gc.h minor_gc.h osdeps.h \ + prims.h printexc.h reverse.h signals.h stacks.h sys.h startup.h \ + version.h +str.d.o: str.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h +sys.d.o: sys.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h debugger.h fail.h instruct.h osdeps.h signals.h \ + stacks.h memory.h gc.h major_gc.h freelist.h minor_gc.h sys.h +terminfo.d.o: terminfo.c config.h ../config/m.h ../config/s.h \ + compatibility.h alloc.h misc.h mlvalues.h fail.h io.h +unix.d.o: unix.c config.h ../config/m.h ../config/s.h compatibility.h \ + memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + osdeps.h +weak.d.o: weak.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h +alloc.pic.o: alloc.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h stacks.h +array.pic.o: array.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +backtrace.pic.o: backtrace.c config.h ../config/m.h ../config/s.h \ + compatibility.h mlvalues.h misc.h alloc.h io.h instruct.h intext.h \ + fix_code.h exec.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + startup.h stacks.h sys.h backtrace.h +callback.pic.o: callback.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h interp.h instruct.h fix_code.h stacks.h +compact.pic.o: compact.c config.h ../config/m.h ../config/s.h compatibility.h \ + finalise.h roots.h misc.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h gc_ctrl.h weak.h +compare.pic.o: compare.c custom.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +custom.pic.o: custom.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h +debugger.pic.o: debugger.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fail.h fix_code.h \ + instruct.h intext.h io.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h sys.h +dynlink.pic.o: dynlink.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h dynlink.h fail.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h osdeps.h prims.h +extern.pic.o: extern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +fail.pic.o: fail.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h io.h gc.h memory.h major_gc.h \ + freelist.h minor_gc.h printexc.h signals.h stacks.h +finalise.pic.o: finalise.c callback.h compatibility.h mlvalues.h config.h \ + ../config/m.h ../config/s.h misc.h fail.h roots.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h signals.h +fix_code.pic.o: fix_code.c config.h ../config/m.h ../config/s.h \ + compatibility.h debugger.h misc.h mlvalues.h fix_code.h instruct.h \ + md5.h io.h memory.h gc.h major_gc.h freelist.h minor_gc.h reverse.h +floats.pic.o: floats.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h reverse.h stacks.h +freelist.pic.o: freelist.c config.h ../config/m.h ../config/s.h \ + compatibility.h freelist.h misc.h mlvalues.h gc.h gc_ctrl.h memory.h \ + major_gc.h minor_gc.h +gc_ctrl.pic.o: gc_ctrl.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h compact.h custom.h finalise.h \ + roots.h memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h \ + stacks.h +globroots.pic.o: globroots.c memory.h compatibility.h config.h ../config/m.h \ + ../config/s.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + roots.h globroots.h +hash.pic.o: hash.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h custom.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +instrtrace.pic.o: instrtrace.c +intern.pic.o: intern.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h gc.h intext.h io.h fix_code.h \ + memory.h major_gc.h freelist.h minor_gc.h reverse.h +interp.pic.o: interp.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h backtrace.h callback.h debugger.h fail.h \ + fix_code.h instrtrace.h instruct.h interp.h major_gc.h freelist.h \ + memory.h gc.h minor_gc.h prims.h signals.h stacks.h jumptbl.h +ints.pic.o: ints.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h custom.h fail.h intext.h io.h fix_code.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h int64_native.h +io.pic.o: io.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h custom.h fail.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h signals.h sys.h +lexing.pic.o: lexing.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +main.pic.o: main.c misc.h compatibility.h config.h ../config/m.h \ + ../config/s.h mlvalues.h sys.h +major_gc.pic.o: major_gc.c compact.h config.h ../config/m.h ../config/s.h \ + compatibility.h misc.h custom.h mlvalues.h fail.h finalise.h roots.h \ + memory.h gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h weak.h +md5.pic.o: md5.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h md5.h io.h memory.h gc.h major_gc.h \ + freelist.h minor_gc.h reverse.h +memory.pic.o: memory.c fail.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h freelist.h gc.h gc_ctrl.h major_gc.h memory.h \ + minor_gc.h signals.h +meta.pic.o: meta.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h fix_code.h interp.h intext.h io.h \ + major_gc.h freelist.h memory.h gc.h minor_gc.h prims.h stacks.h +minor_gc.pic.o: minor_gc.c config.h ../config/m.h ../config/s.h \ + compatibility.h fail.h misc.h mlvalues.h finalise.h roots.h memory.h \ + gc.h major_gc.h freelist.h minor_gc.h gc_ctrl.h signals.h weak.h +misc.pic.o: misc.c config.h ../config/m.h ../config/s.h compatibility.h \ + misc.h memory.h gc.h mlvalues.h major_gc.h freelist.h minor_gc.h +obj.pic.o: obj.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h gc.h interp.h major_gc.h freelist.h \ + memory.h minor_gc.h prims.h +parsing.pic.o: parsing.c config.h ../config/m.h ../config/s.h compatibility.h \ + mlvalues.h misc.h memory.h gc.h major_gc.h freelist.h minor_gc.h \ + alloc.h +prims.pic.o: prims.c mlvalues.h compatibility.h config.h ../config/m.h \ + ../config/s.h misc.h prims.h +printexc.pic.o: printexc.c backtrace.h mlvalues.h compatibility.h config.h \ + ../config/m.h ../config/s.h misc.h callback.h debugger.h fail.h \ + printexc.h +roots.pic.o: roots.c finalise.h roots.h misc.h compatibility.h config.h \ + ../config/m.h ../config/s.h memory.h gc.h mlvalues.h major_gc.h \ + freelist.h minor_gc.h globroots.h stacks.h +signals.pic.o: signals.c alloc.h compatibility.h misc.h config.h \ + ../config/m.h ../config/s.h mlvalues.h callback.h fail.h memory.h gc.h \ + major_gc.h freelist.h minor_gc.h roots.h signals.h signals_machdep.h \ + sys.h +signals_byt.pic.o: signals_byt.c config.h ../config/m.h ../config/s.h \ + compatibility.h memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h \ + minor_gc.h osdeps.h signals.h signals_machdep.h +stacks.pic.o: stacks.c config.h ../config/m.h ../config/s.h compatibility.h \ + fail.h misc.h mlvalues.h stacks.h memory.h gc.h major_gc.h freelist.h \ + minor_gc.h +startup.pic.o: startup.c config.h ../config/m.h ../config/s.h compatibility.h \ + alloc.h misc.h mlvalues.h backtrace.h callback.h custom.h debugger.h \ + dynlink.h exec.h fail.h fix_code.h freelist.h gc_ctrl.h instrtrace.h \ + interp.h intext.h io.h memory.h gc.h major_gc.h minor_gc.h osdeps.h \ + prims.h printexc.h reverse.h signals.h stacks.h sys.h startup.h \ + version.h +str.pic.o: str.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h +sys.pic.o: sys.c config.h ../config/m.h ../config/s.h compatibility.h alloc.h \ + misc.h mlvalues.h debugger.h fail.h instruct.h osdeps.h signals.h \ + stacks.h memory.h gc.h major_gc.h freelist.h minor_gc.h sys.h +terminfo.pic.o: terminfo.c config.h ../config/m.h ../config/s.h \ + compatibility.h alloc.h misc.h mlvalues.h fail.h io.h +unix.pic.o: unix.c config.h ../config/m.h ../config/s.h compatibility.h \ + memory.h gc.h mlvalues.h misc.h major_gc.h freelist.h minor_gc.h \ + osdeps.h +weak.pic.o: weak.c alloc.h compatibility.h misc.h config.h ../config/m.h \ + ../config/s.h mlvalues.h fail.h major_gc.h freelist.h memory.h gc.h \ + minor_gc.h diff --git a/byterun/Makefile b/byterun/Makefile new file mode 100644 index 0000000..16a9d1f --- /dev/null +++ b/byterun/Makefile @@ -0,0 +1,73 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.65 2008-12-03 18:09:09 doligez Exp $ + +include Makefile.common + +CFLAGS=-DCAML_NAME_SPACE -O $(BYTECCCOMPOPTS) $(IFLEXDIR) +DFLAGS=-DCAML_NAME_SPACE -g -DDEBUG $(BYTECCCOMPOPTS) + +OBJS=$(COMMONOBJS) unix.o main.o +DOBJS=$(OBJS:.o=.d.o) instrtrace.d.o +PICOBJS=$(OBJS:.o=.pic.o) + +#ifeq ($(SUPPORTS_SHARED_LIBRARIES),true) + +all:: libcamlrun_shared.so + +install:: + cp libcamlrun_shared.so $(LIBDIR)/libcamlrun_shared.so + +#endif + +ocamlrun$(EXE): libcamlrun.a prims.o + $(MKEXE) $(BYTECCLINKOPTS) -o ocamlrun$(EXE) \ + prims.o libcamlrun.a $(BYTECCLIBS) + +ocamlrund$(EXE): libcamlrund.a prims.o + $(MKEXE) -g $(BYTECCLINKOPTS) -o ocamlrund$(EXE) \ + prims.o libcamlrund.a $(BYTECCLIBS) + +libcamlrun.a: $(OBJS) + ar rc libcamlrun.a $(OBJS) + $(RANLIB) libcamlrun.a + +libcamlrund.a: $(DOBJS) + ar rc libcamlrund.a $(DOBJS) + $(RANLIB) libcamlrund.a + +libcamlrun_shared.so: $(PICOBJS) + $(MKDLL) -o libcamlrun_shared.so $(PICOBJS) $(BYTECCLIBS) + +.SUFFIXES: .d.o .pic.o + +.c.d.o: + @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi + $(CC) -c $(DFLAGS) $< + mv $*.o $*.d.o + @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi + +.c.pic.o: + @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi + $(CC) -c $(CFLAGS) $(SHAREDCCCOMPOPTS) $< + mv $*.o $*.pic.o + @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi + +depend : prims.c opnames.h jumptbl.h version.h + -gcc -MM $(BYTECCCOMPOPTS) *.c > .depend + -gcc -MM $(BYTECCCOMPOPTS) -DDEBUG *.c | sed -e 's/\.o/.d.o/' >> .depend + -gcc -MM $(BYTECCCOMPOPTS) *.c | sed -e 's/\.o/.pic.o/' >> .depend +.PHONY: depend + +include .depend diff --git a/byterun/Makefile.common b/byterun/Makefile.common new file mode 100755 index 0000000..41b4480 --- /dev/null +++ b/byterun/Makefile.common @@ -0,0 +1,93 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.common,v 1.6 2008-09-10 05:51:11 weis Exp $ + +include ../config/Makefile + +CC=$(BYTECC) + +COMMONOBJS=\ + interp.o misc.o stacks.o fix_code.o startup.o \ + freelist.o major_gc.o minor_gc.o memory.o alloc.o roots.o globroots.o \ + fail.o signals.o signals_byt.o printexc.o backtrace.o \ + compare.o ints.o floats.o str.o array.o io.o extern.o intern.o \ + hash.o sys.o meta.o parsing.o gc_ctrl.o terminfo.o md5.o obj.o \ + lexing.o callback.o debugger.o weak.o compact.o finalise.o custom.o \ + dynlink.o + +PRIMS=\ + alloc.c array.c compare.c extern.c floats.c gc_ctrl.c hash.c \ + intern.c interp.c ints.c io.c lexing.c md5.c meta.c obj.c parsing.c \ + signals.c str.c sys.c terminfo.c callback.c weak.c finalise.c stacks.c \ + dynlink.c backtrace.c + +PUBLIC_INCLUDES=\ + alloc.h callback.h config.h custom.h fail.h intext.h \ + memory.h misc.h mlvalues.h printexc.h signals.h compatibility.h + + +all:: ocamlrun$(EXE) ld.conf libcamlrun.$(A) +.PHONY: all + +ld.conf: ../config/Makefile + echo "$(STUBLIBDIR)" > ld.conf + echo "$(LIBDIR)" >> ld.conf + +install:: + cp ocamlrun$(EXE) $(BINDIR)/ocamlrun$(EXE) + cp libcamlrun.$(A) $(LIBDIR)/libcamlrun.$(A) + cd $(LIBDIR); $(RANLIB) libcamlrun.$(A) + if test -d $(LIBDIR)/caml; then : ; else mkdir $(LIBDIR)/caml; fi + for i in $(PUBLIC_INCLUDES); do \ + sed -f ../tools/cleanup-header $$i > $(LIBDIR)/caml/$$i; \ + done + cp ld.conf $(LIBDIR)/ld.conf +.PHONY: install + + +primitives : $(PRIMS) + sed -n -e "s/CAMLprim value \([a-z0-9_][a-z0-9_]*\).*/\1/p" \ + $(PRIMS) > primitives + +prims.c : primitives + (echo '#include "mlvalues.h"'; \ + echo '#include "prims.h"'; \ + sed -e 's/.*/extern value &();/' primitives; \ + echo 'c_primitive caml_builtin_cprim[] = {'; \ + sed -e 's/.*/ &,/' primitives; \ + echo ' 0 };'; \ + echo 'char * caml_names_of_builtin_cprim[] = {'; \ + sed -e 's/.*/ "&",/' primitives; \ + echo ' 0 };') > prims.c + +opnames.h : instruct.h + sed -e '/\/\*/d' \ + -e '/^#/d' \ + -e 's/enum /char * names_of_/' \ + -e 's/{$$/[] = {/' \ + -e 's/\([[:upper:]][[:upper:]_0-9]*\)/"\1"/g' instruct.h > opnames.h + +# jumptbl.h is required only if you have GCC 2.0 or later +jumptbl.h : instruct.h + sed -n -e '/^ /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \ + -e '/^}/q' instruct.h > jumptbl.h + +version.h : ../VERSION + echo "#define OCAML_VERSION \"`head -1 ../VERSION`\"" > version.h + +clean: + rm -f ocamlrun$(EXE) ocamlrund$(EXE) *.$(O) *.$(A) *.$(SO) + rm -f primitives prims.c opnames.h jumptbl.h ld.conf + rm -f version.h +.PHONY: clean diff --git a/byterun/Makefile.nt b/byterun/Makefile.nt new file mode 100644 index 0000000..1ccae92 --- /dev/null +++ b/byterun/Makefile.nt @@ -0,0 +1,54 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.49 2008-12-03 18:09:09 doligez Exp $ + +include Makefile.common + +CFLAGS=-DOCAML_STDLIB_DIR='"$(LIBDIR)"' $(IFLEXDIR) + +DBGO=d.$(O) +OBJS=$(COMMONOBJS:.o=.$(O)) win32.$(O) main.$(O) +DOBJS=$(OBJS:.$(O)=.$(DBGO)) instrtrace.$(DBGO) + +ocamlrun$(EXE): libcamlrun.$(A) prims.$(O) + $(MKEXE) -o ocamlrun$(EXE) prims.$(O) $(call SYSLIB,ws2_32) $(EXTRALIBS) libcamlrun.$(A) + +ocamlrund$(EXE): libcamlrund.$(A) prims.$(O) main.$(O) + $(MKEXE) -o ocamlrun$(EXE) $(BYTECCDBGCOMPOPTS) prims.$(O) $(call SYSLIB,ws2_32) $(EXTRALIBS) libcamlrund.$(A) + +libcamlrun.$(A): $(OBJS) + $(call MKLIB,libcamlrun.$(A),$(OBJS)) + +libcamlrund.$(A): $(DOBJS) + $(call MKLIB,libcamlrund.$(A),$(DOBJS)) + +.SUFFIXES: .$(O) .$(DBGO) + +.c.$(O): + $(CC) $(CFLAGS) $(BYTECCCOMPOPTS) -c $< + +.c.$(DBGO): + $(CC) $(CFLAGS) $(BYTECCDBGCOMPOPTS) -c $< + mv $*.$(O) $*.$(DBGO) + +.depend.nt: .depend + rm -f .depend.win32 + echo "win32.o: win32.c fail.h compatibility.h misc.h config.h \\" >> .depend.win32 + echo " ../config/m.h ../config/s.h mlvalues.h memory.h gc.h \\" >> .depend.win32 + echo " major_gc.h freelist.h minor_gc.h osdeps.h signals.h" >> .depend.win32 + cat .depend >> .depend.win32 + sed -e '/\.d\.o/q' -e 's/^\(.*\)\.o:/\1.$$(O) \1.$$(DBGO):/' .depend.win32 > .depend.nt + rm -f .depend.win32 + +include .depend.nt diff --git a/byterun/alloc.c b/byterun/alloc.c new file mode 100644 index 0000000..eeff9a5 --- /dev/null +++ b/byterun/alloc.c @@ -0,0 +1,186 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: alloc.c,v 1.29 2007-02-09 13:31:15 doligez Exp $ */ + +/* 1. Allocation functions doing the same work as the macros in the + case where [Setup_for_gc] and [Restore_after_gc] are no-ops. + 2. Convenience functions related to allocation. +*/ + +#include +#include "alloc.h" +#include "custom.h" +#include "major_gc.h" +#include "memory.h" +#include "mlvalues.h" +#include "stacks.h" + +#define Setup_for_gc +#define Restore_after_gc + +CAMLexport value caml_alloc (mlsize_t wosize, tag_t tag) +{ + value result; + mlsize_t i; + + Assert (tag < 256); + Assert (tag != Infix_tag); + if (wosize == 0){ + result = Atom (tag); + }else if (wosize <= Max_young_wosize){ + Alloc_small (result, wosize, tag); + if (tag < No_scan_tag){ + for (i = 0; i < wosize; i++) Field (result, i) = 0; + } + }else{ + result = caml_alloc_shr (wosize, tag); + if (tag < No_scan_tag) memset (Bp_val (result), 0, Bsize_wsize (wosize)); + result = caml_check_urgent_gc (result); + } + return result; +} + +CAMLexport value caml_alloc_small (mlsize_t wosize, tag_t tag) +{ + value result; + + Assert (wosize > 0); + Assert (wosize <= Max_young_wosize); + Assert (tag < 256); + Alloc_small (result, wosize, tag); + return result; +} + +CAMLexport value caml_alloc_tuple(mlsize_t n) +{ + return caml_alloc(n, 0); +} + +CAMLexport value caml_alloc_string (mlsize_t len) +{ + value result; + mlsize_t offset_index; + mlsize_t wosize = (len + sizeof (value)) / sizeof (value); + + if (wosize <= Max_young_wosize) { + Alloc_small (result, wosize, String_tag); + }else{ + result = caml_alloc_shr (wosize, String_tag); + result = caml_check_urgent_gc (result); + } + Field (result, wosize - 1) = 0; + offset_index = Bsize_wsize (wosize) - 1; + Byte (result, offset_index) = offset_index - len; + return result; +} + +CAMLexport value caml_alloc_final (mlsize_t len, final_fun fun, + mlsize_t mem, mlsize_t max) +{ + return caml_alloc_custom(caml_final_custom_operations(fun), + len * sizeof(value), mem, max); +} + +CAMLexport value caml_copy_string(char const *s) +{ + int len; + value res; + + len = strlen(s); + res = caml_alloc_string(len); + memmove(String_val(res), s, len); + return res; +} + +CAMLexport value caml_alloc_array(value (*funct)(char const *), + char const ** arr) +{ + CAMLparam0 (); + mlsize_t nbr, n; + CAMLlocal2 (v, result); + + nbr = 0; + while (arr[nbr] != 0) nbr++; + if (nbr == 0) { + CAMLreturn (Atom(0)); + } else { + result = caml_alloc (nbr, 0); + for (n = 0; n < nbr; n++) { + /* The two statements below must be separate because of evaluation + order (don't take the address &Field(result, n) before + calling funct, which may cause a GC and move result). */ + v = funct(arr[n]); + caml_modify(&Field(result, n), v); + } + CAMLreturn (result); + } +} + +CAMLexport value caml_copy_string_array(char const ** arr) +{ + return caml_alloc_array(caml_copy_string, arr); +} + +CAMLexport int caml_convert_flag_list(value list, int *flags) +{ + int res; + res = 0; + while (list != Val_int(0)) { + res |= flags[Int_val(Field(list, 0))]; + list = Field(list, 1); + } + return res; +} + +/* For compiling let rec over values */ + +CAMLprim value caml_alloc_dummy(value size) +{ + mlsize_t wosize = Int_val(size); + + if (wosize == 0) return Atom(0); + return caml_alloc (wosize, 0); +} + +CAMLprim value caml_alloc_dummy_float (value size) +{ + mlsize_t wosize = Int_val(size) * Double_wosize; + + if (wosize == 0) return Atom(0); + return caml_alloc (wosize, 0); +} + +CAMLprim value caml_update_dummy(value dummy, value newval) +{ + mlsize_t size, i; + tag_t tag; + + size = Wosize_val(newval); + tag = Tag_val (newval); + Assert (size == Wosize_val(dummy)); + Assert (tag < No_scan_tag || tag == Double_array_tag); + + Tag_val(dummy) = tag; + if (tag == Double_array_tag){ + size = Wosize_val (newval) / Double_wosize; + for (i = 0; i < size; i++){ + Store_double_field (dummy, i, Double_field (newval, i)); + } + }else{ + for (i = 0; i < size; i++){ + caml_modify (&Field(dummy, i), Field(newval, i)); + } + } + return Val_unit; +} diff --git a/byterun/alloc.h b/byterun/alloc.h new file mode 100644 index 0000000..9db0ef8 --- /dev/null +++ b/byterun/alloc.h @@ -0,0 +1,47 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: alloc.h,v 1.18 2005-09-22 14:21:50 xleroy Exp $ */ + +#ifndef CAML_ALLOC_H +#define CAML_ALLOC_H + + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "misc.h" +#include "mlvalues.h" + +CAMLextern value caml_alloc (mlsize_t, tag_t); +CAMLextern value caml_alloc_small (mlsize_t, tag_t); +CAMLextern value caml_alloc_tuple (mlsize_t); +CAMLextern value caml_alloc_string (mlsize_t); /* size in bytes */ +CAMLextern value caml_copy_string (char const *); +CAMLextern value caml_copy_string_array (char const **); +CAMLextern value caml_copy_double (double); +CAMLextern value caml_copy_int32 (int32); /* defined in [ints.c] */ +CAMLextern value caml_copy_int64 (int64); /* defined in [ints.c] */ +CAMLextern value caml_copy_nativeint (intnat); /* defined in [ints.c] */ +CAMLextern value caml_alloc_array (value (*funct) (char const *), + char const ** array); + +typedef void (*final_fun)(value); +CAMLextern value caml_alloc_final (mlsize_t, /*size in words*/ + final_fun, /*finalization function*/ + mlsize_t, /*resources consumed*/ + mlsize_t /*max resources*/); + +CAMLextern int caml_convert_flag_list (value, int *); + +#endif /* CAML_ALLOC_H */ diff --git a/byterun/array.c b/byterun/array.c new file mode 100644 index 0000000..bd010aa --- /dev/null +++ b/byterun/array.c @@ -0,0 +1,193 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: array.c,v 1.26 2008-09-08 09:43:28 frisch Exp $ */ + +/* Operations on arrays */ + +#include "alloc.h" +#include "fail.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" + +CAMLprim value caml_array_get_addr(value array, value index) +{ + intnat idx = Long_val(index); + if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error(); + return Field(array, idx); +} + +CAMLprim value caml_array_get_float(value array, value index) +{ + intnat idx = Long_val(index); + double d; + value res; + + if (idx < 0 || idx >= Wosize_val(array) / Double_wosize) + caml_array_bound_error(); + d = Double_field(array, idx); +#define Setup_for_gc +#define Restore_after_gc + Alloc_small(res, Double_wosize, Double_tag); +#undef Setup_for_gc +#undef Restore_after_gc + Store_double_val(res, d); + return res; +} + +CAMLprim value caml_array_get(value array, value index) +{ + if (Tag_val(array) == Double_array_tag) + return caml_array_get_float(array, index); + else + return caml_array_get_addr(array, index); +} + +CAMLprim value caml_array_set_addr(value array, value index, value newval) +{ + intnat idx = Long_val(index); + if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error(); + Modify(&Field(array, idx), newval); + return Val_unit; +} + +CAMLprim value caml_array_set_float(value array, value index, value newval) +{ + intnat idx = Long_val(index); + if (idx < 0 || idx >= Wosize_val(array) / Double_wosize) + caml_array_bound_error(); + Store_double_field(array, idx, Double_val(newval)); + return Val_unit; +} + +CAMLprim value caml_array_set(value array, value index, value newval) +{ + if (Tag_val(array) == Double_array_tag) + return caml_array_set_float(array, index, newval); + else + return caml_array_set_addr(array, index, newval); +} + +CAMLprim value caml_array_unsafe_get_float(value array, value index) +{ + double d; + value res; + + d = Double_field(array, Long_val(index)); +#define Setup_for_gc +#define Restore_after_gc + Alloc_small(res, Double_wosize, Double_tag); +#undef Setup_for_gc +#undef Restore_after_gc + Store_double_val(res, d); + return res; +} + +CAMLprim value caml_array_unsafe_get(value array, value index) +{ + if (Tag_val(array) == Double_array_tag) + return caml_array_unsafe_get_float(array, index); + else + return Field(array, Long_val(index)); +} + +CAMLprim value caml_array_unsafe_set_addr(value array, value index,value newval) +{ + intnat idx = Long_val(index); + Modify(&Field(array, idx), newval); + return Val_unit; +} + +CAMLprim value caml_array_unsafe_set_float(value array,value index,value newval) +{ + Store_double_field(array, Long_val(index), Double_val(newval)); + return Val_unit; +} + +CAMLprim value caml_array_unsafe_set(value array, value index, value newval) +{ + if (Tag_val(array) == Double_array_tag) + return caml_array_unsafe_set_float(array, index, newval); + else + return caml_array_unsafe_set_addr(array, index, newval); +} + +CAMLprim value caml_make_vect(value len, value init) +{ + CAMLparam2 (len, init); + CAMLlocal1 (res); + mlsize_t size, wsize, i; + double d; + + size = Long_val(len); + if (size == 0) { + res = Atom(0); + } + else if (Is_block(init) + && Is_in_value_area(init) + && Tag_val(init) == Double_tag) { + d = Double_val(init); + wsize = size * Double_wosize; + if (wsize > Max_wosize) caml_invalid_argument("Array.make"); + res = caml_alloc(wsize, Double_array_tag); + for (i = 0; i < size; i++) { + Store_double_field(res, i, d); + } + } else { + if (size > Max_wosize) caml_invalid_argument("Array.make"); + if (size < Max_young_wosize) { + res = caml_alloc_small(size, 0); + for (i = 0; i < size; i++) Field(res, i) = init; + } + else if (Is_block(init) && Is_young(init)) { + caml_minor_collection(); + res = caml_alloc_shr(size, 0); + for (i = 0; i < size; i++) Field(res, i) = init; + res = caml_check_urgent_gc (res); + } + else { + res = caml_alloc_shr(size, 0); + for (i = 0; i < size; i++) caml_initialize(&Field(res, i), init); + res = caml_check_urgent_gc (res); + } + } + CAMLreturn (res); +} + +CAMLprim value caml_make_array(value init) +{ + CAMLparam1 (init); + mlsize_t wsize, size, i; + CAMLlocal2 (v, res); + + size = Wosize_val(init); + if (size == 0) { + CAMLreturn (init); + } else { + v = Field(init, 0); + if (Is_long(v) + || ! Is_in_value_area(v) + || Tag_val(v) != Double_tag) { + CAMLreturn (init); + } else { + Assert(size < Max_young_wosize); + wsize = size * Double_wosize; + res = caml_alloc_small(wsize, Double_array_tag); + for (i = 0; i < size; i++) { + Store_double_field(res, i, Double_val(Field(init, i))); + } + CAMLreturn (res); + } + } +} diff --git a/byterun/backtrace.c b/byterun/backtrace.c new file mode 100644 index 0000000..7874999 --- /dev/null +++ b/byterun/backtrace.c @@ -0,0 +1,306 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: backtrace.c,v 1.25 2008-03-14 13:47:24 xleroy Exp $ */ + +/* Stack backtrace for uncaught exceptions */ + +#include +#include +#include +#include "config.h" +#ifdef HAS_UNISTD +#include +#endif +#include "mlvalues.h" +#include "alloc.h" +#include "io.h" +#include "instruct.h" +#include "intext.h" +#include "exec.h" +#include "fix_code.h" +#include "memory.h" +#include "startup.h" +#include "stacks.h" +#include "sys.h" +#include "backtrace.h" + +CAMLexport int caml_backtrace_active = 0; +CAMLexport int caml_backtrace_pos = 0; +CAMLexport code_t * caml_backtrace_buffer = NULL; +CAMLexport value caml_backtrace_last_exn = Val_unit; +#define BACKTRACE_BUFFER_SIZE 1024 + +/* Location of fields in the Instruct.debug_event record */ +enum { EV_POS = 0, + EV_MODULE = 1, + EV_LOC = 2, + EV_KIND = 3 }; + +/* Location of fields in the Location.t record. */ +enum { LOC_START = 0, + LOC_END = 1, + LOC_GHOST = 2 }; + +/* Location of fields in the Lexing.position record. */ +enum { + POS_FNAME = 0, + POS_LNUM = 1, + POS_BOL = 2, + POS_CNUM = 3 +}; + +/* Start or stop the backtrace machinery */ + +CAMLprim value caml_record_backtrace(value vflag) +{ + int flag = Int_val(vflag); + + if (flag != caml_backtrace_active) { + caml_backtrace_active = flag; + caml_backtrace_pos = 0; + if (flag) { + caml_register_global_root(&caml_backtrace_last_exn); + } else { + caml_remove_global_root(&caml_backtrace_last_exn); + } + /* Note: lazy initialization of caml_backtrace_buffer in + caml_stash_backtrace to simplify the interface with the thread + libraries */ + } + return Val_unit; +} + +/* Return the status of the backtrace machinery */ + +CAMLprim value caml_backtrace_status(value vunit) +{ + return Val_bool(caml_backtrace_active); +} + +/* Store the return addresses contained in the given stack fragment + into the backtrace array */ + +void caml_stash_backtrace(value exn, code_t pc, value * sp) +{ + code_t end_code = (code_t) ((char *) caml_start_code + caml_code_size); + if (pc != NULL) pc = pc - 1; + if (exn != caml_backtrace_last_exn) { + caml_backtrace_pos = 0; + caml_backtrace_last_exn = exn; + } + if (caml_backtrace_buffer == NULL) { + caml_backtrace_buffer = malloc(BACKTRACE_BUFFER_SIZE * sizeof(code_t)); + if (caml_backtrace_buffer == NULL) return; + } + if (caml_backtrace_pos >= BACKTRACE_BUFFER_SIZE) return; + if (pc >= caml_start_code && pc < end_code){ + caml_backtrace_buffer[caml_backtrace_pos++] = pc; + } + for (/*nothing*/; sp < caml_trapsp; sp++) { + code_t p = (code_t) *sp; + if (p >= caml_start_code && p < end_code) { + if (caml_backtrace_pos >= BACKTRACE_BUFFER_SIZE) break; + caml_backtrace_buffer[caml_backtrace_pos++] = p; + } + } +} + +/* Read the debugging info contained in the current bytecode executable. + Return a Caml array of Caml lists of debug_event records in "events", + or Val_false on failure. */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +static value read_debug_info(void) +{ + CAMLparam0(); + CAMLlocal1(events); + char * exec_name; + int fd; + struct exec_trailer trail; + struct channel * chan; + uint32 num_events, orig, i; + value evl, l; + + exec_name = caml_exe_name; + fd = caml_attempt_open(&exec_name, &trail, 1); + if (fd < 0) CAMLreturn(Val_false); + caml_read_section_descriptors(fd, &trail); + if (caml_seek_optional_section(fd, &trail, "DBUG") == -1) { + close(fd); + CAMLreturn(Val_false); + } + chan = caml_open_descriptor_in(fd); + num_events = caml_getword(chan); + events = caml_alloc(num_events, 0); + for (i = 0; i < num_events; i++) { + orig = caml_getword(chan); + evl = caml_input_val(chan); + /* Relocate events in event list */ + for (l = evl; l != Val_int(0); l = Field(l, 1)) { + value ev = Field(l, 0); + Field(ev, EV_POS) = Val_long(Long_val(Field(ev, EV_POS)) + orig); + } + /* Record event list */ + Store_field(events, i, evl); + } + caml_close_channel(chan); + CAMLreturn(events); +} + +/* Search the event for the given PC. Return Val_false if not found. */ + +static value event_for_location(value events, code_t pc) +{ + mlsize_t i; + value pos, l, ev, ev_pos, best_ev; + + best_ev = 0; + Assert(pc >= caml_start_code && pc < caml_start_code + caml_code_size); + pos = Val_long((char *) pc - (char *) caml_start_code); + for (i = 0; i < Wosize_val(events); i++) { + for (l = Field(events, i); l != Val_int(0); l = Field(l, 1)) { + ev = Field(l, 0); + ev_pos = Field(ev, EV_POS); + if (ev_pos == pos) return ev; + /* ocamlc sometimes moves an event past a following PUSH instruction; + allow mismatch by 1 instruction. */ + if (ev_pos == pos + 8) best_ev = ev; + } + } + if (best_ev != 0) return best_ev; + return Val_false; +} + +/* Extract location information for the given PC */ + +struct loc_info { + int loc_valid; + int loc_is_raise; + char * loc_filename; + int loc_lnum; + int loc_startchr; + int loc_endchr; +}; + +static void extract_location_info(value events, code_t pc, + /*out*/ struct loc_info * li) +{ + value ev, ev_start; + + ev = event_for_location(events, pc); + li->loc_is_raise = caml_is_instruction(*pc, RAISE); + if (ev == Val_false) { + li->loc_valid = 0; + return; + } + li->loc_valid = 1; + ev_start = Field (Field (ev, EV_LOC), LOC_START); + li->loc_filename = String_val (Field (ev_start, POS_FNAME)); + li->loc_lnum = Int_val (Field (ev_start, POS_LNUM)); + li->loc_startchr = + Int_val (Field (ev_start, POS_CNUM)) + - Int_val (Field (ev_start, POS_BOL)); + li->loc_endchr = + Int_val (Field (Field (Field (ev, EV_LOC), LOC_END), POS_CNUM)) + - Int_val (Field (ev_start, POS_BOL)); +} + +/* Print location information */ + +static void print_location(struct loc_info * li, int index) +{ + char * info; + + /* Ignore compiler-inserted raise */ + if (!li->loc_valid && li->loc_is_raise) return; + + if (li->loc_is_raise) { + /* Initial raise if index == 0, re-raise otherwise */ + if (index == 0) + info = "Raised at"; + else + info = "Re-raised at"; + } else { + if (index == 0) + info = "Raised by primitive operation at"; + else + info = "Called from"; + } + if (! li->loc_valid) { + fprintf(stderr, "%s unknown location\n", info); + } else { + fprintf (stderr, "%s file \"%s\", line %d, characters %d-%d\n", + info, li->loc_filename, li->loc_lnum, + li->loc_startchr, li->loc_endchr); + } +} + +/* Print a backtrace */ + +CAMLexport void caml_print_exception_backtrace(void) +{ + value events; + int i; + struct loc_info li; + + events = read_debug_info(); + if (events == Val_false) { + fprintf(stderr, + "(Program not linked with -g, cannot print stack backtrace)\n"); + return; + } + for (i = 0; i < caml_backtrace_pos; i++) { + extract_location_info(events, caml_backtrace_buffer[i], &li); + print_location(&li, i); + } +} + +/* Convert the backtrace to a data structure usable from Caml */ + +CAMLprim value caml_get_exception_backtrace(value unit) +{ + CAMLparam0(); + CAMLlocal5(events, res, arr, p, fname); + int i; + struct loc_info li; + + events = read_debug_info(); + if (events == Val_false) { + res = Val_int(0); /* None */ + } else { + arr = caml_alloc(caml_backtrace_pos, 0); + for (i = 0; i < caml_backtrace_pos; i++) { + extract_location_info(events, caml_backtrace_buffer[i], &li); + if (li.loc_valid) { + fname = caml_copy_string(li.loc_filename); + p = caml_alloc_small(5, 0); + Field(p, 0) = Val_bool(li.loc_is_raise); + Field(p, 1) = fname; + Field(p, 2) = Val_int(li.loc_lnum); + Field(p, 3) = Val_int(li.loc_startchr); + Field(p, 4) = Val_int(li.loc_endchr); + } else { + p = caml_alloc_small(1, 1); + Field(p, 0) = Val_bool(li.loc_is_raise); + } + caml_modify(&Field(arr, i), p); + } + res = caml_alloc_small(1, 0); Field(res, 0) = arr; /* Some */ + } + CAMLreturn(res); +} + diff --git a/byterun/backtrace.h b/byterun/backtrace.h new file mode 100644 index 0000000..a93051e --- /dev/null +++ b/byterun/backtrace.h @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: backtrace.h,v 1.8 2008-03-14 13:47:24 xleroy Exp $ */ + +#ifndef CAML_BACKTRACE_H +#define CAML_BACKTRACE_H + +#include "mlvalues.h" + +CAMLextern int caml_backtrace_active; +CAMLextern int caml_backtrace_pos; +CAMLextern code_t * caml_backtrace_buffer; +CAMLextern value caml_backtrace_last_exn; + +CAMLprim value caml_record_backtrace(value vflag); +#ifndef NATIVE_CODE +extern void caml_stash_backtrace(value exn, code_t pc, value * sp); +#endif +CAMLextern void caml_print_exception_backtrace(void); + +#endif /* CAML_BACKTRACE_H */ diff --git a/byterun/callback.c b/byterun/callback.c new file mode 100644 index 0000000..6a91019 --- /dev/null +++ b/byterun/callback.c @@ -0,0 +1,248 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: callback.c,v 1.24 2006-09-11 12:12:24 doligez Exp $ */ + +/* Callbacks from C to Caml */ + +#include +#include "callback.h" +#include "fail.h" +#include "memory.h" +#include "mlvalues.h" + +#ifndef NATIVE_CODE + +/* Bytecode callbacks */ + +#include "interp.h" +#include "instruct.h" +#include "fix_code.h" +#include "stacks.h" + +CAMLexport int caml_callback_depth = 0; + +#ifndef LOCAL_CALLBACK_BYTECODE +static opcode_t callback_code[] = { ACC, 0, APPLY, 0, POP, 1, STOP }; +#endif + + +#ifdef THREADED_CODE + +static int callback_code_threaded = 0; + +static void thread_callback(void) +{ + caml_thread_code(callback_code, sizeof(callback_code)); + callback_code_threaded = 1; +} + +#define Init_callback() if (!callback_code_threaded) thread_callback() + +#else + +#define Init_callback() + +#endif + +CAMLexport value caml_callbackN_exn(value closure, int narg, value args[]) +{ + int i; + value res; + + /* some alternate bytecode implementations (e.g. a JIT translator) + might require that the bytecode is kept in a local variable on + the C stack */ +#ifdef LOCAL_CALLBACK_BYTECODE + opcode_t local_callback_code[7]; +#endif + + Assert(narg + 4 <= 256); + + caml_extern_sp -= narg + 4; + for (i = 0; i < narg; i++) caml_extern_sp[i] = args[i]; /* arguments */ +#ifndef LOCAL_CALLBACK_BYTECODE + caml_extern_sp[narg] = (value) (callback_code + 4); /* return address */ + caml_extern_sp[narg + 1] = Val_unit; /* environment */ + caml_extern_sp[narg + 2] = Val_long(0); /* extra args */ + caml_extern_sp[narg + 3] = closure; + Init_callback(); + callback_code[1] = narg + 3; + callback_code[3] = narg; + res = caml_interprete(callback_code, sizeof(callback_code)); +#else /*have LOCAL_CALLBACK_BYTECODE*/ + caml_extern_sp[narg] = (value) (local_callback_code + 4); /* return address */ + caml_extern_sp[narg + 1] = Val_unit; /* environment */ + caml_extern_sp[narg + 2] = Val_long(0); /* extra args */ + caml_extern_sp[narg + 3] = closure; + local_callback_code[0] = ACC; + local_callback_code[1] = narg + 3; + local_callback_code[2] = APPLY; + local_callback_code[3] = narg; + local_callback_code[4] = POP; + local_callback_code[5] = 1; + local_callback_code[6] = STOP; +#ifdef THREADED_CODE + caml_thread_code(local_callback_code, sizeof(local_callback_code)); +#endif /*THREADED_CODE*/ + res = caml_interprete(local_callback_code, sizeof(local_callback_code)); + caml_release_bytecode(local_callback_code, sizeof(local_callback_code)); +#endif /*LOCAL_CALLBACK_BYTECODE*/ + if (Is_exception_result(res)) caml_extern_sp += narg + 4; /* PR#1228 */ + return res; +} + +CAMLexport value caml_callback_exn(value closure, value arg1) +{ + value arg[1]; + arg[0] = arg1; + return caml_callbackN_exn(closure, 1, arg); +} + +CAMLexport value caml_callback2_exn(value closure, value arg1, value arg2) +{ + value arg[2]; + arg[0] = arg1; + arg[1] = arg2; + return caml_callbackN_exn(closure, 2, arg); +} + +CAMLexport value caml_callback3_exn(value closure, + value arg1, value arg2, value arg3) +{ + value arg[3]; + arg[0] = arg1; + arg[1] = arg2; + arg[2] = arg3; + return caml_callbackN_exn(closure, 3, arg); +} + +#else + +/* Native-code callbacks. caml_callback[123]_exn are implemented in asm. */ + +CAMLexport value caml_callbackN_exn(value closure, int narg, value args[]) +{ + CAMLparam1 (closure); + CAMLxparamN (args, narg); + CAMLlocal1 (res); + int i; + + res = closure; + for (i = 0; i < narg; /*nothing*/) { + /* Pass as many arguments as possible */ + switch (narg - i) { + case 1: + res = caml_callback_exn(res, args[i]); + if (Is_exception_result(res)) CAMLreturn (res); + i += 1; + break; + case 2: + res = caml_callback2_exn(res, args[i], args[i + 1]); + if (Is_exception_result(res)) CAMLreturn (res); + i += 2; + break; + default: + res = caml_callback3_exn(res, args[i], args[i + 1], args[i + 2]); + if (Is_exception_result(res)) CAMLreturn (res); + i += 3; + break; + } + } + CAMLreturn (res); +} + +#endif + +/* Exception-propagating variants of the above */ + +CAMLexport value caml_callback (value closure, value arg) +{ + value res = caml_callback_exn(closure, arg); + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + +CAMLexport value caml_callback2 (value closure, value arg1, value arg2) +{ + value res = caml_callback2_exn(closure, arg1, arg2); + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + +CAMLexport value caml_callback3 (value closure, value arg1, value arg2, + value arg3) +{ + value res = caml_callback3_exn(closure, arg1, arg2, arg3); + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + +CAMLexport value caml_callbackN (value closure, int narg, value args[]) +{ + value res = caml_callbackN_exn(closure, narg, args); + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); + return res; +} + +/* Naming of Caml values */ + +struct named_value { + value val; + struct named_value * next; + char name[1]; +}; + +#define Named_value_size 13 + +static struct named_value * named_value_table[Named_value_size] = { NULL, }; + +static unsigned int hash_value_name(char const *name) +{ + unsigned int h; + for (h = 0; *name != 0; name++) h = h * 19 + *name; + return h % Named_value_size; +} + +CAMLprim value caml_register_named_value(value vname, value val) +{ + struct named_value * nv; + char * name = String_val(vname); + unsigned int h = hash_value_name(name); + + for (nv = named_value_table[h]; nv != NULL; nv = nv->next) { + if (strcmp(name, nv->name) == 0) { + nv->val = val; + return Val_unit; + } + } + nv = (struct named_value *) + caml_stat_alloc(sizeof(struct named_value) + strlen(name)); + strcpy(nv->name, name); + nv->val = val; + nv->next = named_value_table[h]; + named_value_table[h] = nv; + caml_register_global_root(&nv->val); + return Val_unit; +} + +CAMLexport value * caml_named_value(char const *name) +{ + struct named_value * nv; + for (nv = named_value_table[hash_value_name(name)]; + nv != NULL; + nv = nv->next) { + if (strcmp(name, nv->name) == 0) return &nv->val; + } + return NULL; +} diff --git a/byterun/callback.h b/byterun/callback.h new file mode 100644 index 0000000..0464a68 --- /dev/null +++ b/byterun/callback.h @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: callback.h,v 1.14 2006-09-11 12:12:24 doligez Exp $ */ + +/* Callbacks from C to Caml */ + +#ifndef CAML_CALLBACK_H +#define CAML_CALLBACK_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "mlvalues.h" + +CAMLextern value caml_callback (value closure, value arg); +CAMLextern value caml_callback2 (value closure, value arg1, value arg2); +CAMLextern value caml_callback3 (value closure, value arg1, value arg2, + value arg3); +CAMLextern value caml_callbackN (value closure, int narg, value args[]); + +CAMLextern value caml_callback_exn (value closure, value arg); +CAMLextern value caml_callback2_exn (value closure, value arg1, value arg2); +CAMLextern value caml_callback3_exn (value closure, + value arg1, value arg2, value arg3); +CAMLextern value caml_callbackN_exn (value closure, int narg, value args[]); + +#define Make_exception_result(v) ((v) | 2) +#define Is_exception_result(v) (((v) & 3) == 2) +#define Extract_exception(v) ((v) & ~3) + +CAMLextern value * caml_named_value (char const * name); + +CAMLextern void caml_main (char ** argv); +CAMLextern void caml_startup (char ** argv); + +CAMLextern int caml_callback_depth; + +#endif diff --git a/byterun/compact.c b/byterun/compact.c new file mode 100644 index 0000000..800de14 --- /dev/null +++ b/byterun/compact.c @@ -0,0 +1,441 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: compact.c,v 1.26 2008-02-29 12:56:15 doligez Exp $ */ + +#include + +#include "config.h" +#include "finalise.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "major_gc.h" +#include "memory.h" +#include "mlvalues.h" +#include "roots.h" +#include "weak.h" + +extern uintnat caml_percent_free; /* major_gc.c */ +extern void caml_shrink_heap (char *); /* memory.c */ + +/* Encoded headers: the color is stored in the 2 least significant bits. + (For pointer inversion, we need to distinguish headers from pointers.) + s is a Wosize, t is a tag, and c is a color (a two-bit number) + + For the purpose of compaction, "colors" are: + 0: pointers (direct or inverted) + 1: integer or (unencoded) infix header + 2: inverted pointer for infix header + 3: integer or encoded (noninfix) header + + XXX Should be fixed: + XXX The above assumes that all roots are aligned on a 4-byte boundary, + XXX which is not always guaranteed by C. + XXX (see [caml_register_global_roots] and [caml_init_exceptions]) + XXX Should be able to fix it to only assume 2-byte alignment. +*/ +#define Make_ehd(s,t,c) (((s) << 10) | (t) << 2 | (c)) +#define Whsize_ehd(h) Whsize_hd (h) +#define Wosize_ehd(h) Wosize_hd (h) +#define Tag_ehd(h) (((h) >> 2) & 0xFF) +#define Ecolor(w) ((w) & 3) + +typedef uintnat word; + +static void invert_pointer_at (word *p) +{ + word q = *p; + Assert (Ecolor ((intnat) p) == 0); + + /* Use Ecolor (q) == 0 instead of Is_block (q) because q could be an + inverted pointer for an infix header (with Ecolor == 2). */ + if (Ecolor (q) == 0 && (Classify_addr (q) & In_heap)){ + switch (Ecolor (Hd_val (q))){ + case 0: + case 3: /* Pointer or header: insert in inverted list. */ + *p = Hd_val (q); + Hd_val (q) = (header_t) p; + break; + case 1: /* Infix header: make inverted infix list. */ + /* Double inversion: the last of the inverted infix list points to + the next infix header in this block. The last of the last list + contains the original block header. */ + { + /* This block as a value. */ + value val = (value) q - Infix_offset_val (q); + /* Get the block header. */ + word *hp = (word *) Hp_val (val); + + while (Ecolor (*hp) == 0) hp = (word *) *hp; + Assert (Ecolor (*hp) == 3); + if (Tag_ehd (*hp) == Closure_tag){ + /* This is the first infix found in this block. */ + /* Save original header. */ + *p = *hp; + /* Link inverted infix list. */ + Hd_val (q) = (header_t) ((word) p | 2); + /* Change block header's tag to Infix_tag, and change its size + to point to the infix list. */ + *hp = Make_ehd (Wosize_bhsize (q - val), Infix_tag, 3); + }else{ Assert (Tag_ehd (*hp) == Infix_tag); + /* Point the last of this infix list to the current first infix + list of the block. */ + *p = (word) &Field (val, Wosize_ehd (*hp)) | 1; + /* Point the head of this infix list to the above. */ + Hd_val (q) = (header_t) ((word) p | 2); + /* Change block header's size to point to this infix list. */ + *hp = Make_ehd (Wosize_bhsize (q - val), Infix_tag, 3); + } + } + break; + case 2: /* Inverted infix list: insert. */ + *p = Hd_val (q); + Hd_val (q) = (header_t) ((word) p | 2); + break; + } + } +} + +static void invert_root (value v, value *p) +{ + invert_pointer_at ((word *) p); +} + +static char *compact_fl; + +static void init_compact_allocate (void) +{ + char *ch = caml_heap_start; + while (ch != NULL){ + Chunk_alloc (ch) = 0; + ch = Chunk_next (ch); + } + compact_fl = caml_heap_start; +} + +static char *compact_allocate (mlsize_t size) + /* in bytes, including header */ +{ + char *chunk, *adr; + + while (Chunk_size (compact_fl) - Chunk_alloc (compact_fl) <= Bhsize_wosize (3) + && Chunk_size (Chunk_next (compact_fl)) + - Chunk_alloc (Chunk_next (compact_fl)) + <= Bhsize_wosize (3)){ + compact_fl = Chunk_next (compact_fl); + } + chunk = compact_fl; + while (Chunk_size (chunk) - Chunk_alloc (chunk) < size){ + chunk = Chunk_next (chunk); Assert (chunk != NULL); + } + adr = chunk + Chunk_alloc (chunk); + Chunk_alloc (chunk) += size; + return adr; +} + +void caml_compact_heap (void) +{ + char *ch, *chend; + Assert (caml_gc_phase == Phase_idle); + caml_gc_message (0x10, "Compacting heap...\n", 0); + +#ifdef DEBUG + caml_heap_check (); +#endif + + /* First pass: encode all noninfix headers. */ + { + ch = caml_heap_start; + while (ch != NULL){ + header_t *p = (header_t *) ch; + + chend = ch + Chunk_size (ch); + while ((char *) p < chend){ + header_t hd = Hd_hp (p); + mlsize_t sz = Wosize_hd (hd); + + if (Is_blue_hd (hd)){ + /* Free object. Give it a string tag. */ + Hd_hp (p) = Make_ehd (sz, String_tag, 3); + }else{ Assert (Is_white_hd (hd)); + /* Live object. Keep its tag. */ + Hd_hp (p) = Make_ehd (sz, Tag_hd (hd), 3); + } + p += Whsize_wosize (sz); + } + ch = Chunk_next (ch); + } + } + + + /* Second pass: invert pointers. + Link infix headers in each block in an inverted list of inverted lists. + Don't forget roots and weak pointers. */ + { + /* Invert roots first because the threads library needs some heap + data structures to find its roots. Fortunately, it doesn't need + the headers (see above). */ + caml_do_roots (invert_root); + caml_final_do_weak_roots (invert_root); + + ch = caml_heap_start; + while (ch != NULL){ + word *p = (word *) ch; + chend = ch + Chunk_size (ch); + + while ((char *) p < chend){ + word q = *p; + size_t sz, i; + tag_t t; + word *infixes; + + while (Ecolor (q) == 0) q = * (word *) q; + sz = Whsize_ehd (q); + t = Tag_ehd (q); + + if (t == Infix_tag){ + /* Get the original header of this block. */ + infixes = p + sz; + q = *infixes; + while (Ecolor (q) != 3) q = * (word *) (q & ~(uintnat)3); + sz = Whsize_ehd (q); + t = Tag_ehd (q); + } + + if (t < No_scan_tag){ + for (i = 1; i < sz; i++) invert_pointer_at (&(p[i])); + } + p += sz; + } + ch = Chunk_next (ch); + } + /* Invert weak pointers. */ + { + value *pp = &caml_weak_list_head; + value p; + word q; + size_t sz, i; + + while (1){ + p = *pp; + if (p == (value) NULL) break; + q = Hd_val (p); + while (Ecolor (q) == 0) q = * (word *) q; + sz = Wosize_ehd (q); + for (i = 1; i < sz; i++){ + if (Field (p,i) != caml_weak_none){ + invert_pointer_at ((word *) &(Field (p,i))); + } + } + invert_pointer_at ((word *) pp); + pp = &Field (p, 0); + } + } + } + + + /* Third pass: reallocate virtually; revert pointers; decode headers. + Rebuild infix headers. */ + { + init_compact_allocate (); + ch = caml_heap_start; + while (ch != NULL){ + word *p = (word *) ch; + + chend = ch + Chunk_size (ch); + while ((char *) p < chend){ + word q = *p; + + if (Ecolor (q) == 0 || Tag_ehd (q) == Infix_tag){ + /* There were (normal or infix) pointers to this block. */ + size_t sz; + tag_t t; + char *newadr; + word *infixes = NULL; + + while (Ecolor (q) == 0) q = * (word *) q; + sz = Whsize_ehd (q); + t = Tag_ehd (q); + + if (t == Infix_tag){ + /* Get the original header of this block. */ + infixes = p + sz; + q = *infixes; Assert (Ecolor (q) == 2); + while (Ecolor (q) != 3) q = * (word *) (q & ~(uintnat)3); + sz = Whsize_ehd (q); + t = Tag_ehd (q); + } + + newadr = compact_allocate (Bsize_wsize (sz)); + q = *p; + while (Ecolor (q) == 0){ + word next = * (word *) q; + * (word *) q = (word) Val_hp (newadr); + q = next; + } + *p = Make_header (Wosize_whsize (sz), t, Caml_white); + + if (infixes != NULL){ + /* Rebuild the infix headers and revert the infix pointers. */ + while (Ecolor ((word) infixes) != 3){ + infixes = (word *) ((word) infixes & ~(uintnat) 3); + q = *infixes; + while (Ecolor (q) == 2){ + word next; + q = (word) q & ~(uintnat) 3; + next = * (word *) q; + * (word *) q = (word) Val_hp ((word *) newadr + (infixes - p)); + q = next; + } Assert (Ecolor (q) == 1 || Ecolor (q) == 3); + *infixes = Make_header (infixes - p, Infix_tag, Caml_white); + infixes = (word *) q; + } + } + p += sz; + }else{ Assert (Ecolor (q) == 3); + /* This is guaranteed only if caml_compact_heap was called after a + nonincremental major GC: Assert (Tag_ehd (q) == String_tag); + */ + /* No pointers to the header and no infix header: + the object was free. */ + *p = Make_header (Wosize_ehd (q), Tag_ehd (q), Caml_blue); + p += Whsize_ehd (q); + } + } + ch = Chunk_next (ch); + } + } + + + /* Fourth pass: reallocate and move objects. + Use the exact same allocation algorithm as pass 3. */ + { + init_compact_allocate (); + ch = caml_heap_start; + while (ch != NULL){ + word *p = (word *) ch; + + chend = ch + Chunk_size (ch); + while ((char *) p < chend){ + word q = *p; + if (Color_hd (q) == Caml_white){ + size_t sz = Bhsize_hd (q); + char *newadr = compact_allocate (sz); Assert (newadr <= (char *)p); + memmove (newadr, p, sz); + p += Wsize_bsize (sz); + }else{ + Assert (Color_hd (q) == Caml_blue); + p += Whsize_hd (q); + } + } + ch = Chunk_next (ch); + } + } + + /* Shrink the heap if needed. */ + { + /* Find the amount of live data and the unshrinkable free space. */ + asize_t live = 0; + asize_t free = 0; + asize_t wanted; + + ch = caml_heap_start; + while (ch != NULL){ + if (Chunk_alloc (ch) != 0){ + live += Wsize_bsize (Chunk_alloc (ch)); + free += Wsize_bsize (Chunk_size (ch) - Chunk_alloc (ch)); + } + ch = Chunk_next (ch); + } + + /* Add up the empty chunks until there are enough, then remove the + other empty chunks. */ + wanted = caml_percent_free * (live / 100 + 1); + ch = caml_heap_start; + while (ch != NULL){ + char *next_chunk = Chunk_next (ch); /* Chunk_next (ch) will be erased */ + + if (Chunk_alloc (ch) == 0){ + if (free < wanted){ + free += Wsize_bsize (Chunk_size (ch)); + }else{ + caml_shrink_heap (ch); + } + } + ch = next_chunk; + } + } + + /* Rebuild the free list. */ + { + ch = caml_heap_start; + caml_fl_reset (); + while (ch != NULL){ + if (Chunk_size (ch) > Chunk_alloc (ch)){ + caml_make_free_blocks ((value *) (ch + Chunk_alloc (ch)), + Wsize_bsize (Chunk_size(ch)-Chunk_alloc(ch)), 1); + } + ch = Chunk_next (ch); + } + } + ++ caml_stat_compactions; + caml_gc_message (0x10, "done.\n", 0); +} + +uintnat caml_percent_max; /* used in gc_ctrl.c and memory.c */ + +void caml_compact_heap_maybe (void) +{ + /* Estimated free words in the heap: + FW = fl_size_at_change + 3 * (caml_fl_cur_size + - caml_fl_size_at_phase_change) + FW = 3 * caml_fl_cur_size - 2 * caml_fl_size_at_phase_change + Estimated live words: LW = caml_stat_heap_size - FW + Estimated free percentage: FP = 100 * FW / LW + We compact the heap if FP > caml_percent_max + */ + float fw, fp; + Assert (caml_gc_phase == Phase_idle); + if (caml_percent_max >= 1000000) return; + if (caml_stat_major_collections < 3 || caml_stat_heap_chunks < 3) return; + + fw = 3.0 * caml_fl_cur_size - 2.0 * caml_fl_size_at_phase_change; + if (fw < 0) fw = caml_fl_cur_size; + + if (fw >= Wsize_bsize (caml_stat_heap_size)){ + fp = 1000000.0; + }else{ + fp = 100.0 * fw / (Wsize_bsize (caml_stat_heap_size) - fw); + if (fp > 1000000.0) fp = 1000000.0; + } + caml_gc_message (0x200, "FL size at phase change = %" + ARCH_INTNAT_PRINTF_FORMAT "u\n", + (uintnat) caml_fl_size_at_phase_change); + caml_gc_message (0x200, "Estimated overhead = %" + ARCH_INTNAT_PRINTF_FORMAT "u%%\n", + (uintnat) fp); + if (fp >= caml_percent_max){ + caml_gc_message (0x200, "Automatic compaction triggered.\n", 0); + caml_finish_major_cycle (); + + /* We just did a complete GC, so we can measure the overhead exactly. */ + fw = caml_fl_cur_size; + fp = 100.0 * fw / (Wsize_bsize (caml_stat_heap_size) - fw); + caml_gc_message (0x200, "Measured overhead: %" + ARCH_INTNAT_PRINTF_FORMAT "u%%\n", + (uintnat) fp); + + caml_compact_heap (); + } +} diff --git a/byterun/compact.h b/byterun/compact.h new file mode 100644 index 0000000..3150da2 --- /dev/null +++ b/byterun/compact.h @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: compact.h,v 1.7 2003-12-31 14:20:35 doligez Exp $ */ + +#ifndef CAML_COMPACT_H +#define CAML_COMPACT_H + + +#include "config.h" +#include "misc.h" + +extern void caml_compact_heap (void); +extern void caml_compact_heap_maybe (void); + + +#endif /* CAML_COMPACT_H */ diff --git a/byterun/compare.c b/byterun/compare.c new file mode 100644 index 0000000..72a7b66 --- /dev/null +++ b/byterun/compare.c @@ -0,0 +1,293 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: compare.c,v 1.39 2008-01-11 16:13:16 doligez Exp $ */ + +#include +#include +#include "custom.h" +#include "fail.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" + +/* Structural comparison on trees. */ + +struct compare_item { value * v1, * v2; mlsize_t count; }; + +#define COMPARE_STACK_INIT_SIZE 256 +#define COMPARE_STACK_MAX_SIZE (1024*1024) + +static struct compare_item compare_stack_init[COMPARE_STACK_INIT_SIZE]; + +static struct compare_item * compare_stack = compare_stack_init; +static struct compare_item * compare_stack_limit = compare_stack_init + + COMPARE_STACK_INIT_SIZE; + +CAMLexport int caml_compare_unordered; + +/* Free the compare stack if needed */ +static void compare_free_stack(void) +{ + if (compare_stack != compare_stack_init) { + free(compare_stack); + /* Reinitialize the globals for next time around */ + compare_stack = compare_stack_init; + compare_stack_limit = compare_stack + COMPARE_STACK_INIT_SIZE; + } +} + +/* Same, then raise Out_of_memory */ +static void compare_stack_overflow(void) +{ + caml_gc_message (0x04, "Stack overflow in structural comparison\n", 0); + compare_free_stack(); + caml_raise_out_of_memory(); +} + +/* Grow the compare stack */ +static struct compare_item * compare_resize_stack(struct compare_item * sp) +{ + asize_t newsize = 2 * (compare_stack_limit - compare_stack); + asize_t sp_offset = sp - compare_stack; + struct compare_item * newstack; + + if (newsize >= COMPARE_STACK_MAX_SIZE) compare_stack_overflow(); + if (compare_stack == compare_stack_init) { + newstack = malloc(sizeof(struct compare_item) * newsize); + if (newstack == NULL) compare_stack_overflow(); + memcpy(newstack, compare_stack_init, + sizeof(struct compare_item) * COMPARE_STACK_INIT_SIZE); + } else { + newstack = + realloc(compare_stack, sizeof(struct compare_item) * newsize); + if (newstack == NULL) compare_stack_overflow(); + } + compare_stack = newstack; + compare_stack_limit = newstack + newsize; + return newstack + sp_offset; +} + +/* Structural comparison */ + +#define LESS -1 +#define EQUAL 0 +#define GREATER 1 +#define UNORDERED ((intnat)1 << (8 * sizeof(value) - 1)) + +/* The return value of compare_val is as follows: + > 0 v1 is greater than v2 + 0 v1 is equal to v2 + < 0 and > UNORDERED v1 is less than v2 + UNORDERED v1 and v2 cannot be compared */ + +static intnat compare_val(value v1, value v2, int total) +{ + struct compare_item * sp; + tag_t t1, t2; + + sp = compare_stack; + while (1) { + if (v1 == v2 && total) goto next_item; + if (Is_long(v1)) { + if (v1 == v2) goto next_item; + if (Is_long(v2)) + return Long_val(v1) - Long_val(v2); + /* Subtraction above cannot overflow and cannot result in UNORDERED */ + if (Is_in_value_area(v2) && + Tag_val(v2) == Forward_tag) { + v2 = Forward_val(v2); + continue; + } + return LESS; /* v1 long < v2 block */ + } + if (Is_long(v2)) { + if (Is_in_value_area(v1) && + Tag_val(v1) == Forward_tag) { + v1 = Forward_val(v1); + continue; + } + return GREATER; /* v1 block > v2 long */ + } + /* If one of the objects is outside the heap (but is not an atom), + use address comparison. Since both addresses are 2-aligned, + shift lsb off to avoid overflow in subtraction. */ + if (! Is_in_value_area(v1) || ! Is_in_value_area(v2)) { + if (v1 == v2) goto next_item; + return (v1 >> 1) - (v2 >> 1); + /* Subtraction above cannot result in UNORDERED */ + } + t1 = Tag_val(v1); + t2 = Tag_val(v2); + if (t1 == Forward_tag) { v1 = Forward_val (v1); continue; } + if (t2 == Forward_tag) { v2 = Forward_val (v2); continue; } + if (t1 != t2) return (intnat)t1 - (intnat)t2; + switch(t1) { + case String_tag: { + mlsize_t len1, len2, len; + unsigned char * p1, * p2; + if (v1 == v2) break; + len1 = caml_string_length(v1); + len2 = caml_string_length(v2); + for (len = (len1 <= len2 ? len1 : len2), + p1 = (unsigned char *) String_val(v1), + p2 = (unsigned char *) String_val(v2); + len > 0; + len--, p1++, p2++) + if (*p1 != *p2) return (intnat)*p1 - (intnat)*p2; + if (len1 != len2) return len1 - len2; + break; + } + case Double_tag: { + double d1 = Double_val(v1); + double d2 = Double_val(v2); + if (d1 < d2) return LESS; + if (d1 > d2) return GREATER; + if (d1 != d2) { + if (! total) return UNORDERED; + /* One or both of d1 and d2 is NaN. Order according to the + convention NaN = NaN and NaN < f for all other floats f. */ + if (d1 == d1) return GREATER; /* d1 is not NaN, d2 is NaN */ + if (d2 == d2) return LESS; /* d2 is not NaN, d1 is NaN */ + /* d1 and d2 are both NaN, thus equal: continue comparison */ + } + break; + } + case Double_array_tag: { + mlsize_t sz1 = Wosize_val(v1) / Double_wosize; + mlsize_t sz2 = Wosize_val(v2) / Double_wosize; + mlsize_t i; + if (sz1 != sz2) return sz1 - sz2; + for (i = 0; i < sz1; i++) { + double d1 = Double_field(v1, i); + double d2 = Double_field(v2, i); + if (d1 < d2) return LESS; + if (d1 > d2) return GREATER; + if (d1 != d2) { + if (! total) return UNORDERED; + /* See comment for Double_tag case */ + if (d1 == d1) return GREATER; + if (d2 == d2) return LESS; + } + } + break; + } + case Abstract_tag: + compare_free_stack(); + caml_invalid_argument("equal: abstract value"); + case Closure_tag: + case Infix_tag: + compare_free_stack(); + caml_invalid_argument("equal: functional value"); + case Object_tag: { + intnat oid1 = Oid_val(v1); + intnat oid2 = Oid_val(v2); + if (oid1 != oid2) return oid1 - oid2; + break; + } + case Custom_tag: { + int res; + int (*compare)(value v1, value v2) = Custom_ops_val(v1)->compare; + if (compare == NULL) { + compare_free_stack(); + caml_invalid_argument("equal: abstract value"); + } + caml_compare_unordered = 0; + res = Custom_ops_val(v1)->compare(v1, v2); + if (caml_compare_unordered && !total) return UNORDERED; + if (res != 0) return res; + break; + } + default: { + mlsize_t sz1 = Wosize_val(v1); + mlsize_t sz2 = Wosize_val(v2); + /* Compare sizes first for speed */ + if (sz1 != sz2) return sz1 - sz2; + if (sz1 == 0) break; + /* Remember that we still have to compare fields 1 ... sz - 1 */ + if (sz1 > 1) { + sp++; + if (sp >= compare_stack_limit) sp = compare_resize_stack(sp); + sp->v1 = &Field(v1, 1); + sp->v2 = &Field(v2, 1); + sp->count = sz1 - 1; + } + /* Continue comparison with first field */ + v1 = Field(v1, 0); + v2 = Field(v2, 0); + continue; + } + } + next_item: + /* Pop one more item to compare, if any */ + if (sp == compare_stack) return EQUAL; /* we're done */ + v1 = *((sp->v1)++); + v2 = *((sp->v2)++); + if (--(sp->count) == 0) sp--; + } +} + +CAMLprim value caml_compare(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 1); + /* Free stack if needed */ + if (compare_stack != compare_stack_init) compare_free_stack(); + if (res < 0) + return Val_int(LESS); + else if (res > 0) + return Val_int(GREATER); + else + return Val_int(EQUAL); +} + +CAMLprim value caml_equal(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res == 0); +} + +CAMLprim value caml_notequal(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res != 0); +} + +CAMLprim value caml_lessthan(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res < 0 && res != UNORDERED); +} + +CAMLprim value caml_lessequal(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res <= 0 && res != UNORDERED); +} + +CAMLprim value caml_greaterthan(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res > 0); +} + +CAMLprim value caml_greaterequal(value v1, value v2) +{ + intnat res = compare_val(v1, v2, 0); + if (compare_stack != compare_stack_init) compare_free_stack(); + return Val_int(res >= 0); +} diff --git a/byterun/compare.h b/byterun/compare.h new file mode 100644 index 0000000..5297a4c --- /dev/null +++ b/byterun/compare.h @@ -0,0 +1,21 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, Projet Moscova, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: compare.h,v 1.2 2003-12-31 14:20:35 doligez Exp $ */ + +#ifndef CAML_COMPARE_H +#define CAML_COMPARE_H + +CAMLextern int caml_compare_unordered; + +#endif /* CAML_COMPARE_H */ diff --git a/byterun/compatibility.h b/byterun/compatibility.h new file mode 100644 index 0000000..a8bee9b --- /dev/null +++ b/byterun/compatibility.h @@ -0,0 +1,372 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Moscova, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: compatibility.h,v 1.17 2008-07-28 11:59:55 doligez Exp $ */ + +/* definitions for compatibility with old identifiers */ + +#ifndef CAML_COMPATIBILITY_H +#define CAML_COMPATIBILITY_H + +#ifndef CAML_NAME_SPACE + +/* + #define --> CAMLextern (defined with CAMLexport or CAMLprim) + (rien) --> CAMLprim + g --> global C identifier + x --> special case + + SP* signals the special cases: + - when the identifier was not simply prefixed with [caml_] + - when the [caml_] version was already used for something else, and + was renamed out of the way (watch out for [caml_alloc] and + [caml_array_bound_error] in *.s) +*/ + +/* a faire: + - ui_* (reverifier que win32.c n'en depend pas) +*/ + + +/* **** alloc.c */ +#define alloc caml_alloc /*SP*/ +#define alloc_small caml_alloc_small +#define alloc_tuple caml_alloc_tuple +#define alloc_string caml_alloc_string +#define alloc_final caml_alloc_final +#define copy_string caml_copy_string +#define alloc_array caml_alloc_array +#define copy_string_array caml_copy_string_array +#define convert_flag_list caml_convert_flag_list + +/* **** array.c */ + +/* **** backtrace.c */ +#define backtrace_active caml_backtrace_active +#define backtrace_pos caml_backtrace_pos +#define backtrace_buffer caml_backtrace_buffer +#define backtrace_last_exn caml_backtrace_last_exn +#define print_exception_backtrace caml_print_exception_backtrace + +/* **** callback.c */ +#define callback_depth caml_callback_depth +#define callbackN_exn caml_callbackN_exn +#define callback_exn caml_callback_exn +#define callback2_exn caml_callback2_exn +#define callback3_exn caml_callback3_exn +#define callback caml_callback +#define callback2 caml_callback2 +#define callback3 caml_callback3 +#define callbackN caml_callbackN + +/* **** compact.c */ + +/* **** compare.c */ +#define compare_unordered caml_compare_unordered + +/* **** custom.c */ +#define alloc_custom caml_alloc_custom +#define register_custom_operations caml_register_custom_operations + +/* **** debugger.c */ + +/* **** dynlink.c */ + +/* **** extern.c */ +#define output_val caml_output_val +#define output_value_to_malloc caml_output_value_to_malloc +#define output_value_to_block caml_output_value_to_block +#define serialize_int_1 caml_serialize_int_1 +#define serialize_int_2 caml_serialize_int_2 +#define serialize_int_4 caml_serialize_int_4 +#define serialize_int_8 caml_serialize_int_8 +#define serialize_float_4 caml_serialize_float_4 +#define serialize_float_8 caml_serialize_float_8 +#define serialize_block_1 caml_serialize_block_1 +#define serialize_block_2 caml_serialize_block_2 +#define serialize_block_4 caml_serialize_block_4 +#define serialize_block_8 caml_serialize_block_8 +#define serialize_block_float_8 caml_serialize_block_float_8 + +/* **** fail.c */ +#define external_raise caml_external_raise +#define mlraise caml_raise /*SP*/ +#define raise_constant caml_raise_constant +#define raise_with_arg caml_raise_with_arg +#define raise_with_string caml_raise_with_string +#define failwith caml_failwith +#define invalid_argument caml_invalid_argument +#define array_bound_error caml_array_bound_error /*SP*/ +#define raise_out_of_memory caml_raise_out_of_memory +#define raise_stack_overflow caml_raise_stack_overflow +#define raise_sys_error caml_raise_sys_error +#define raise_end_of_file caml_raise_end_of_file +#define raise_zero_divide caml_raise_zero_divide +#define raise_not_found caml_raise_not_found +#define raise_sys_blocked_io caml_raise_sys_blocked_io +#define init_exceptions caml_init_exceptions +/* **** asmrun/fail.c */ +/* **** asmrun/.s */ + +/* **** finalise.c */ + +/* **** fix_code.c */ + +/* **** floats.c */ +/*#define Double_val caml_Double_val done in mlvalues.h as needed */ +/*#define Store_double_val caml_Store_double_val done in mlvalues.h as needed */ +#define copy_double caml_copy_double + +/* **** freelist.c */ + +/* **** gc_ctrl.c */ + +/* **** globroots.c */ +#define register_global_root caml_register_global_root +#define remove_global_root caml_remove_global_root + +/* **** hash.c */ +#define hash_variant caml_hash_variant + +/* **** instrtrace.c */ + +/* **** intern.c */ +#define input_val caml_input_val +#define input_val_from_string caml_input_val_from_string +#define input_value_from_malloc caml_input_value_from_malloc +#define input_value_from_block caml_input_value_from_block +#define deserialize_uint_1 caml_deserialize_uint_1 +#define deserialize_sint_1 caml_deserialize_sint_1 +#define deserialize_uint_2 caml_deserialize_uint_2 +#define deserialize_sint_2 caml_deserialize_sint_2 +#define deserialize_uint_4 caml_deserialize_uint_4 +#define deserialize_sint_4 caml_deserialize_sint_4 +#define deserialize_uint_8 caml_deserialize_uint_8 +#define deserialize_sint_8 caml_deserialize_sint_8 +#define deserialize_float_4 caml_deserialize_float_4 +#define deserialize_float_8 caml_deserialize_float_8 +#define deserialize_block_1 caml_deserialize_block_1 +#define deserialize_block_2 caml_deserialize_block_2 +#define deserialize_block_4 caml_deserialize_block_4 +#define deserialize_block_8 caml_deserialize_block_8 +#define deserialize_block_float_8 caml_deserialize_block_float_8 +#define deserialize_error caml_deserialize_error + +/* **** interp.c */ + +/* **** ints.c */ +#define int32_ops caml_int32_ops +#define copy_int32 caml_copy_int32 +/*#define Int64_val caml_Int64_val *** done in mlvalues.h as needed */ +#define int64_ops caml_int64_ops +#define copy_int64 caml_copy_int64 +#define nativeint_ops caml_nativeint_ops +#define copy_nativeint caml_copy_nativeint + +/* **** io.c */ +#define channel_mutex_free caml_channel_mutex_free +#define channel_mutex_lock caml_channel_mutex_lock +#define channel_mutex_unlock caml_channel_mutex_unlock +#define channel_mutex_unlock_exn caml_channel_mutex_unlock_exn +#define all_opened_channels caml_all_opened_channels +#define open_descriptor_in caml_open_descriptor_in /*SP*/ +#define open_descriptor_out caml_open_descriptor_out /*SP*/ +#define close_channel caml_close_channel /*SP*/ +#define channel_size caml_channel_size /*SP*/ +#define channel_binary_mode caml_channel_binary_mode +#define flush_partial caml_flush_partial /*SP*/ +#define flush caml_flush /*SP*/ +#define putword caml_putword +#define putblock caml_putblock +#define really_putblock caml_really_putblock +#define seek_out caml_seek_out /*SP*/ +#define pos_out caml_pos_out /*SP*/ +#define do_read caml_do_read +#define refill caml_refill +#define getword caml_getword +#define getblock caml_getblock +#define really_getblock caml_really_getblock +#define seek_in caml_seek_in /*SP*/ +#define pos_in caml_pos_in /*SP*/ +#define input_scan_line caml_input_scan_line /*SP*/ +#define finalize_channel caml_finalize_channel +#define alloc_channel caml_alloc_channel +/*#define Val_file_offset caml_Val_file_offset *** done in io.h as needed */ +/*#define File_offset_val caml_File_offset_val *** done in io.h as needed */ + +/* **** lexing.c */ + +/* **** main.c */ +/* *** no change */ + +/* **** major_gc.c */ +#define heap_start caml_heap_start +#define page_table caml_page_table + +/* **** md5.c */ +#define md5_string caml_md5_string +#define md5_chan caml_md5_chan +#define MD5Init caml_MD5Init +#define MD5Update caml_MD5Update +#define MD5Final caml_MD5Final +#define MD5Transform caml_MD5Transform + +/* **** memory.c */ +#define alloc_shr caml_alloc_shr +#define initialize caml_initialize +#define modify caml_modify +#define stat_alloc caml_stat_alloc +#define stat_free caml_stat_free +#define stat_resize caml_stat_resize + +/* **** meta.c */ + +/* **** minor_gc.c */ +#define young_start caml_young_start +#define young_end caml_young_end +#define young_ptr caml_young_ptr +#define young_limit caml_young_limit +#define ref_table caml_ref_table +#define minor_collection caml_minor_collection +#define check_urgent_gc caml_check_urgent_gc + +/* **** misc.c */ + +/* **** obj.c */ + +/* **** parsing.c */ + +/* **** prims.c */ + +/* **** printexc.c */ +#define format_caml_exception caml_format_exception /*SP*/ + +/* **** roots.c */ +#define local_roots caml_local_roots +#define scan_roots_hook caml_scan_roots_hook +#define do_local_roots caml_do_local_roots + +/* **** signals.c */ +#define pending_signals caml_pending_signals +#define something_to_do caml_something_to_do +#define enter_blocking_section_hook caml_enter_blocking_section_hook +#define leave_blocking_section_hook caml_leave_blocking_section_hook +#define try_leave_blocking_section_hook caml_try_leave_blocking_section_hook +#define async_action_hook caml_async_action_hook +#define enter_blocking_section caml_enter_blocking_section +#define leave_blocking_section caml_leave_blocking_section +#define convert_signal_number caml_convert_signal_number +/* **** asmrun/signals.c */ +#define garbage_collection caml_garbage_collection + +/* **** stacks.c */ +#define stack_low caml_stack_low +#define stack_high caml_stack_high +#define stack_threshold caml_stack_threshold +#define extern_sp caml_extern_sp +#define trapsp caml_trapsp +#define trap_barrier caml_trap_barrier + +/* **** startup.c */ +#define atom_table caml_atom_table +/* **** asmrun/startup.c */ +#define static_data_start caml_static_data_start +#define static_data_end caml_static_data_end + +/* **** str.c */ +#define string_length caml_string_length + +/* **** sys.c */ +#define sys_error caml_sys_error +#define sys_exit caml_sys_exit + +/* **** terminfo.c */ + +/* **** unix.c & win32.c */ +#define search_exe_in_path caml_search_exe_in_path + +/* **** weak.c */ + +/* **** asmcomp/asmlink.ml */ + +/* **** asmcomp/cmmgen.ml */ + +/* **** asmcomp/asmlink.ml, asmcomp/cmmgen.ml, asmcomp/compilenv.ml */ + +/* ************************************************************* */ + +/* **** otherlibs/bigarray */ +#define int8 caml_ba_int8 +#define uint8 caml_ba_uint8 +#define int16 caml_ba_int16 +#define uint16 caml_ba_uint16 +#define MAX_NUM_DIMS CAML_BA_MAX_NUM_DIMS +#define caml_bigarray_kind caml_ba_kind +#define BIGARRAY_FLOAT32 CAML_BA_FLOAT32 +#define BIGARRAY_FLOAT64 CAML_BA_FLOAT64 +#define BIGARRAY_SINT8 CAML_BA_SINT8 +#define BIGARRAY_UINT8 CAML_BA_UINT8 +#define BIGARRAY_SINT16 CAML_BA_SINT16 +#define BIGARRAY_UINT16 CAML_BA_UINT16 +#define BIGARRAY_INT32 CAML_BA_INT32 +#define BIGARRAY_INT64 CAML_BA_INT64 +#define BIGARRAY_CAML_INT CAML_BA_CAML_INT +#define BIGARRAY_NATIVE_INT CAML_BA_NATIVE_INT +#define BIGARRAY_COMPLEX32 CAML_BA_COMPLEX32 +#define BIGARRAY_COMPLEX64 CAML_BA_COMPLEX64 +#define BIGARRAY_KIND_MASK CAML_BA_KIND_MASK +#define caml_bigarray_layout caml_ba_layout +#define BIGARRAY_C_LAYOUT CAML_BA_C_LAYOUT +#define BIGARRAY_FORTRAN_LAYOUT CAML_BA_FORTRAN_LAYOUT +#define BIGARRAY_LAYOUT_MASK CAML_BA_LAYOUT_MASK +#define caml_bigarray_managed caml_ba_managed +#define BIGARRAY_EXTERNAL CAML_BA_EXTERNAL +#define BIGARRAY_MANAGED CAML_BA_MANAGED +#define BIGARRAY_MAPPED_FILE CAML_BA_MAPPED_FILE +#define BIGARRAY_MANAGED_MASK CAML_BA_MANAGED_MASK +#define caml_bigarray_proxy caml_ba_proxy +#define caml_bigarray caml_ba_array +#define Bigarray_val Caml_ba_array_val +#define Data_bigarray_val Caml_ba_data_val +#define alloc_bigarray caml_ba_alloc +#define alloc_bigarray_dims caml_ba_alloc_dims +#define bigarray_map_file caml_ba_map_file +#define bigarray_unmap_file caml_ba_unmap_file +#define bigarray_element_size caml_ba_element_size +#define bigarray_byte_size caml_ba_byte_size +#define bigarray_deserialize caml_ba_deserialize +#define MAX_BIGARRAY_MEMORY CAML_BA_MAX_MEMORY +#define bigarray_create caml_ba_create +#define bigarray_get_N caml_ba_get_N +#define bigarray_get_1 caml_ba_get_1 +#define bigarray_get_2 caml_ba_get_2 +#define bigarray_get_3 caml_ba_get_3 +#define bigarray_get_generic caml_ba_get_generic +#define bigarray_set_1 caml_ba_set_1 +#define bigarray_set_2 caml_ba_set_2 +#define bigarray_set_3 caml_ba_set_3 +#define bigarray_set_N caml_ba_set_N +#define bigarray_set_generic caml_ba_set_generic +#define bigarray_num_dims caml_ba_num_dims +#define bigarray_dim caml_ba_dim +#define bigarray_kind caml_ba_kind +#define bigarray_layout caml_ba_layout +#define bigarray_slice caml_ba_slice +#define bigarray_sub caml_ba_sub +#define bigarray_blit caml_ba_blit +#define bigarray_fill caml_ba_fill +#define bigarray_reshape caml_ba_reshape +#define bigarray_init caml_ba_init + +#endif /* CAML_NAME_SPACE */ +#endif /* CAML_COMPATIBILITY_H */ diff --git a/byterun/config.h b/byterun/config.h new file mode 100644 index 0000000..a8bbfc9 --- /dev/null +++ b/byterun/config.h @@ -0,0 +1,168 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: config.h,v 1.43 2008-12-03 18:09:09 doligez Exp $ */ + +#ifndef CAML_CONFIG_H +#define CAML_CONFIG_H + +/* */ +/* */ +/* */ +#include "../config/m.h" +#include "../config/s.h" +/* */ + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif + +/* Types for signed chars, 32-bit integers, 64-bit integers, + native integers (as wide as a pointer type) */ + +typedef signed char schar; + +#if SIZEOF_PTR == SIZEOF_LONG +/* Standard models: ILP32 or I32LP64 */ +typedef long intnat; +typedef unsigned long uintnat; +#define ARCH_INTNAT_PRINTF_FORMAT "l" +#elif SIZEOF_PTR == SIZEOF_INT +/* Hypothetical IP32L64 model */ +typedef int intnat; +typedef unsigned int uintnat; +#define ARCH_INTNAT_PRINTF_FORMAT "" +#elif SIZEOF_PTR == 8 && defined(ARCH_INT64_TYPE) +/* Win64 model: IL32LLP64 */ +typedef ARCH_INT64_TYPE intnat; +typedef ARCH_UINT64_TYPE uintnat; +#define ARCH_INTNAT_PRINTF_FORMAT ARCH_INT64_PRINTF_FORMAT +#else +#error "No integer type available to represent pointers" +#endif + +#if SIZEOF_INT == 4 +typedef int int32; +typedef unsigned int uint32; +#define ARCH_INT32_PRINTF_FORMAT "" +#elif SIZEOF_LONG == 4 +typedef long int32; +typedef unsigned long uint32; +#define ARCH_INT32_PRINTF_FORMAT "l" +#elif SIZEOF_SHORT == 4 +typedef short int32; +typedef unsigned short uint32; +#define ARCH_INT32_PRINTF_FORMAT "" +#else +#error "No 32-bit integer type available" +#endif + +#if defined(ARCH_INT64_TYPE) +typedef ARCH_INT64_TYPE int64; +typedef ARCH_UINT64_TYPE uint64; +#else +# ifdef ARCH_BIG_ENDIAN +typedef struct { uint32 h, l; } uint64, int64; +# else +typedef struct { uint32 l, h; } uint64, int64; +# endif +#endif + +/* Endianness of floats */ + +/* ARCH_FLOAT_ENDIANNESS encodes the byte order of doubles as follows: + the value [0xabcdefgh] means that the least significant byte of the + float is at byte offset [a], the next lsb at [b], ..., and the + most significant byte at [h]. */ + +#if defined(__arm__) && !defined(__ARM_EABI__) +#define ARCH_FLOAT_ENDIANNESS 0x45670123 +#elif defined(ARCH_BIG_ENDIAN) +#define ARCH_FLOAT_ENDIANNESS 0x76543210 +#else +#define ARCH_FLOAT_ENDIANNESS 0x01234567 +#endif + +/* We use threaded code interpretation if the compiler provides labels + as first-class values (GCC 2.x). */ + +#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(DEBUG) && !defined (SHRINKED_GNUC) && !defined(CAML_JIT) +#define THREADED_CODE +#endif + + +/* Do not change this definition. */ +#define Page_size (1 << Page_log) + +/* Memory model parameters */ + +/* The size of a page for memory management (in bytes) is [1 << Page_log]. + It must be a multiple of [sizeof (value)] and >= 8 and <= 20. */ +#define Page_log 12 /* A page is 4 kilobytes. */ + +/* Initial size of stack (bytes). */ +#define Stack_size (4096 * sizeof(value)) + +/* Minimum free size of stack (bytes); below that, it is reallocated. */ +#define Stack_threshold (256 * sizeof(value)) + +/* Default maximum size of the stack (words). */ +#define Max_stack_def (1024 * 1024) + + +/* Maximum size of a block allocated in the young generation (words). */ +/* Must be > 4 */ +#define Max_young_wosize 256 + + +/* Minimum size of the minor zone (words). + This must be at least [Max_young_wosize + 1]. */ +#define Minor_heap_min 4096 + +/* Maximum size of the minor zone (words). + Must be greater than or equal to [Minor_heap_min]. +*/ +#define Minor_heap_max (1 << 28) + +/* Default size of the minor zone. (words) */ +#define Minor_heap_def 32768 + + +/* Minimum size increment when growing the heap (words). + Must be a multiple of [Page_size / sizeof (value)]. */ +#define Heap_chunk_min (2 * Page_size / sizeof (value)) + +/* Default size increment when growing the heap. (words) + Must be a multiple of [Page_size / sizeof (value)]. + (Approx 512 Kb for a 32-bit platform, 1 Mb for a 64-bit platform.) */ +#define Heap_chunk_def (31 * Page_size) + +/* Default initial size of the major heap (words); + same constraints as for Heap_chunk_def. */ +#define Init_heap_def (31 * Page_size) + + +/* Default speed setting for the major GC. The heap will grow until + the dead objects and the free list represent this percentage of the + total size of live objects. */ +#define Percent_free_def 80 + +/* Default setting for the compacter: 500% + (i.e. trigger the compacter when 5/6 of the heap is free or garbage) + This can be set quite high because the overhead is over-estimated + when fragmentation occurs. + */ +#define Max_percent_free_def 500 + + +#endif /* CAML_CONFIG_H */ diff --git a/byterun/custom.c b/byterun/custom.c new file mode 100644 index 0000000..b47a5c4 --- /dev/null +++ b/byterun/custom.c @@ -0,0 +1,102 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: custom.c,v 1.15 2005-09-22 14:21:50 xleroy Exp $ */ + +#include + +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "memory.h" +#include "mlvalues.h" + +CAMLexport value caml_alloc_custom(struct custom_operations * ops, + uintnat size, + mlsize_t mem, + mlsize_t max) +{ + mlsize_t wosize; + value result; + + wosize = 1 + (size + sizeof(value) - 1) / sizeof(value); + if (ops->finalize == NULL && wosize <= Max_young_wosize) { + result = caml_alloc_small(wosize, Custom_tag); + Custom_ops_val(result) = ops; + } else { + result = caml_alloc_shr(wosize, Custom_tag); + Custom_ops_val(result) = ops; + caml_adjust_gc_speed(mem, max); + result = caml_check_urgent_gc(result); + } + return result; +} + +struct custom_operations_list { + struct custom_operations * ops; + struct custom_operations_list * next; +}; + +static struct custom_operations_list * custom_ops_table = NULL; + +CAMLexport void caml_register_custom_operations(struct custom_operations * ops) +{ + struct custom_operations_list * l = + caml_stat_alloc(sizeof(struct custom_operations_list)); + Assert(ops->identifier != NULL); + Assert(ops->deserialize != NULL); + l->ops = ops; + l->next = custom_ops_table; + custom_ops_table = l; +} + +struct custom_operations * caml_find_custom_operations(char * ident) +{ + struct custom_operations_list * l; + for (l = custom_ops_table; l != NULL; l = l->next) + if (strcmp(l->ops->identifier, ident) == 0) return l->ops; + return NULL; +} + +static struct custom_operations_list * custom_ops_final_table = NULL; + +struct custom_operations * caml_final_custom_operations(final_fun fn) +{ + struct custom_operations_list * l; + struct custom_operations * ops; + for (l = custom_ops_final_table; l != NULL; l = l->next) + if (l->ops->finalize == fn) return l->ops; + ops = caml_stat_alloc(sizeof(struct custom_operations)); + ops->identifier = "_final"; + ops->finalize = fn; + ops->compare = custom_compare_default; + ops->hash = custom_hash_default; + ops->serialize = custom_serialize_default; + ops->deserialize = custom_deserialize_default; + l = caml_stat_alloc(sizeof(struct custom_operations_list)); + l->ops = ops; + l->next = custom_ops_final_table; + custom_ops_final_table = l; + return ops; +} + +extern struct custom_operations caml_int32_ops, + caml_nativeint_ops, + caml_int64_ops; + +void caml_init_custom_operations(void) +{ + caml_register_custom_operations(&caml_int32_ops); + caml_register_custom_operations(&caml_nativeint_ops); + caml_register_custom_operations(&caml_int64_ops); +} diff --git a/byterun/custom.h b/byterun/custom.h new file mode 100644 index 0000000..204dd06 --- /dev/null +++ b/byterun/custom.h @@ -0,0 +1,62 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: custom.h,v 1.13 2005-09-22 14:21:50 xleroy Exp $ */ + +#ifndef CAML_CUSTOM_H +#define CAML_CUSTOM_H + + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "mlvalues.h" + +struct custom_operations { + char *identifier; + void (*finalize)(value v); + int (*compare)(value v1, value v2); + intnat (*hash)(value v); + void (*serialize)(value v, + /*out*/ uintnat * wsize_32 /*size in bytes*/, + /*out*/ uintnat * wsize_64 /*size in bytes*/); + uintnat (*deserialize)(void * dst); +}; + +#define custom_finalize_default NULL +#define custom_compare_default NULL +#define custom_hash_default NULL +#define custom_serialize_default NULL +#define custom_deserialize_default NULL + +#define Custom_ops_val(v) (*((struct custom_operations **) (v))) + +CAMLextern value caml_alloc_custom(struct custom_operations * ops, + uintnat size, /*size in bytes*/ + mlsize_t mem, /*resources consumed*/ + mlsize_t max /*max resources*/); + +CAMLextern void caml_register_custom_operations(struct custom_operations * ops); + +CAMLextern int caml_compare_unordered; + /* Used by custom comparison to report unordered NaN-like cases. */ + +/* */ +extern struct custom_operations * caml_find_custom_operations(char * ident); +extern struct custom_operations * + caml_final_custom_operations(void (*fn)(value)); + +extern void caml_init_custom_operations(void); +/* */ + +#endif /* CAML_CUSTOM_H */ diff --git a/byterun/debugger.c b/byterun/debugger.c new file mode 100644 index 0000000..bb11891 --- /dev/null +++ b/byterun/debugger.c @@ -0,0 +1,419 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: debugger.c,v 1.31 2008-07-29 08:31:41 xleroy Exp $ */ + +/* Interface with the debugger */ + +#ifdef _WIN32 +#include +#endif /* _WIN32 */ + +#include + +#include "config.h" +#include "debugger.h" +#include "fail.h" +#include "fix_code.h" +#include "instruct.h" +#include "intext.h" +#include "io.h" +#include "misc.h" +#include "mlvalues.h" +#include "stacks.h" +#include "sys.h" + +int caml_debugger_in_use = 0; +uintnat caml_event_count; + +#if !defined(HAS_SOCKETS) + +void caml_debugger_init(void) +{ +} + +void caml_debugger(enum event_kind event) +{ +} + +#else + +#ifdef HAS_UNISTD +#include +#endif +#include +#include +#ifndef _WIN32 +#include +#include +#include +#include +#include +#include +#else +#define ATOM ATOM_WS +#include +#undef ATOM +#include +#endif + +static int sock_domain; /* Socket domain for the debugger */ +static union { /* Socket address for the debugger */ + struct sockaddr s_gen; +#ifndef _WIN32 + struct sockaddr_un s_unix; +#endif + struct sockaddr_in s_inet; +} sock_addr; +static int sock_addr_len; /* Length of sock_addr */ + +static int dbg_socket = -1; /* The socket connected to the debugger */ +static struct channel * dbg_in; /* Input channel on the socket */ +static struct channel * dbg_out;/* Output channel on the socket */ + +static char *dbg_addr = "(none)"; + +static void open_connection(void) +{ +#ifdef _WIN32 + /* Set socket to synchronous mode so that file descriptor-oriented + functions (read()/write() etc.) can be used */ + + int oldvalue, oldvaluelen, newvalue, retcode; + oldvaluelen = sizeof(oldvalue); + retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, &oldvaluelen); + if (retcode == 0) { + newvalue = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &newvalue, sizeof(newvalue)); + } +#endif + dbg_socket = socket(sock_domain, SOCK_STREAM, 0); +#ifdef _WIN32 + if (retcode == 0) { + /* Restore initial mode */ + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, oldvaluelen); + } +#endif + if (dbg_socket == -1 || + connect(dbg_socket, &sock_addr.s_gen, sock_addr_len) == -1){ + caml_fatal_error_arg2 ("cannot connect to debugger at %s", dbg_addr, + "error: %s\n", strerror (errno)); + } +#ifdef _WIN32 + dbg_socket = _open_osfhandle(dbg_socket, 0); + if (dbg_socket == -1) + caml_fatal_error("_open_osfhandle failed"); +#endif + dbg_in = caml_open_descriptor_in(dbg_socket); + dbg_out = caml_open_descriptor_out(dbg_socket); + if (!caml_debugger_in_use) caml_putword(dbg_out, -1); /* first connection */ +#ifdef _WIN32 + caml_putword(dbg_out, _getpid()); +#else + caml_putword(dbg_out, getpid()); +#endif + caml_flush(dbg_out); +} + +static void close_connection(void) +{ + caml_close_channel(dbg_in); + caml_close_channel(dbg_out); + dbg_socket = -1; /* was closed by caml_close_channel */ +} + +#ifdef _WIN32 +static void winsock_startup(void) +{ + WSADATA wsaData; + int err = WSAStartup(MAKEWORD(2, 0), &wsaData); + if (err) caml_fatal_error("WSAStartup failed"); +} + +static void winsock_cleanup(void) +{ + WSACleanup(); +} +#endif + +void caml_debugger_init(void) +{ + char * address; + char * port, * p; + struct hostent * host; + int n; + + address = getenv("CAML_DEBUG_SOCKET"); + if (address == NULL) return; + dbg_addr = address; + +#ifdef _WIN32 + winsock_startup(); + (void)atexit(winsock_cleanup); +#endif + /* Parse the address */ + port = NULL; + for (p = address; *p != 0; p++) { + if (*p == ':') { *p = 0; port = p+1; break; } + } + if (port == NULL) { +#ifndef _WIN32 + /* Unix domain */ + sock_domain = PF_UNIX; + sock_addr.s_unix.sun_family = AF_UNIX; + strncpy(sock_addr.s_unix.sun_path, address, + sizeof(sock_addr.s_unix.sun_path)); + sock_addr_len = + ((char *)&(sock_addr.s_unix.sun_path) - (char *)&(sock_addr.s_unix)) + + strlen(address); +#else + caml_fatal_error("Unix sockets not supported"); +#endif + } else { + /* Internet domain */ + sock_domain = PF_INET; + for (p = (char *) &sock_addr.s_inet, n = sizeof(sock_addr.s_inet); + n > 0; n--) *p++ = 0; + sock_addr.s_inet.sin_family = AF_INET; + sock_addr.s_inet.sin_addr.s_addr = inet_addr(address); + if (sock_addr.s_inet.sin_addr.s_addr == -1) { + host = gethostbyname(address); + if (host == NULL) + caml_fatal_error_arg("Unknown debugging host %s\n", address); + memmove(&sock_addr.s_inet.sin_addr, host->h_addr, host->h_length); + } + sock_addr.s_inet.sin_port = htons(atoi(port)); + sock_addr_len = sizeof(sock_addr.s_inet); + } + open_connection(); + caml_debugger_in_use = 1; + caml_trap_barrier = caml_stack_high; +} + +static value getval(struct channel *chan) +{ + value res; + if (caml_really_getblock(chan, (char *) &res, sizeof(res)) == 0) + caml_raise_end_of_file(); /* Bad, but consistent with caml_getword */ + return res; +} + +static void putval(struct channel *chan, value val) +{ + caml_really_putblock(chan, (char *) &val, sizeof(val)); +} + +static void safe_output_value(struct channel *chan, value val) +{ + struct longjmp_buffer raise_buf, * saved_external_raise; + + /* Catch exceptions raised by [caml_output_val] */ + saved_external_raise = caml_external_raise; + if (sigsetjmp(raise_buf.buf, 0) == 0) { + caml_external_raise = &raise_buf; + caml_output_val(chan, val, Val_unit); + } else { + /* Send wrong magic number, will cause [caml_input_value] to fail */ + caml_really_putblock(chan, "\000\000\000\000", 4); + } + caml_external_raise = saved_external_raise; +} + +#define Pc(sp) ((code_t)((sp)[0])) +#define Env(sp) ((sp)[1]) +#define Extra_args(sp) (Long_val(((sp)[2]))) +#define Locals(sp) ((sp) + 3) + +void caml_debugger(enum event_kind event) +{ + int frame_number; + value * frame; + intnat i, pos; + value val; + + if (dbg_socket == -1) return; /* Not connected to a debugger. */ + + /* Reset current frame */ + frame_number = 0; + frame = caml_extern_sp + 1; + + /* Report the event to the debugger */ + switch(event) { + case PROGRAM_START: /* Nothing to report */ + goto command_loop; + case EVENT_COUNT: + putch(dbg_out, REP_EVENT); + break; + case BREAKPOINT: + putch(dbg_out, REP_BREAKPOINT); + break; + case PROGRAM_EXIT: + putch(dbg_out, REP_EXITED); + break; + case TRAP_BARRIER: + putch(dbg_out, REP_TRAP); + break; + case UNCAUGHT_EXC: + putch(dbg_out, REP_UNCAUGHT_EXC); + break; + } + caml_putword(dbg_out, caml_event_count); + if (event == EVENT_COUNT || event == BREAKPOINT) { + caml_putword(dbg_out, caml_stack_high - frame); + caml_putword(dbg_out, (Pc(frame) - caml_start_code) * sizeof(opcode_t)); + } else { + /* No PC and no stack frame associated with other events */ + caml_putword(dbg_out, 0); + caml_putword(dbg_out, 0); + } + caml_flush(dbg_out); + + command_loop: + + /* Read and execute the commands sent by the debugger */ + while(1) { + switch(getch(dbg_in)) { + case REQ_SET_EVENT: + pos = caml_getword(dbg_in); + Assert (pos >= 0); + Assert (pos < caml_code_size); + caml_set_instruction(caml_start_code + pos / sizeof(opcode_t), EVENT); + break; + case REQ_SET_BREAKPOINT: + pos = caml_getword(dbg_in); + Assert (pos >= 0); + Assert (pos < caml_code_size); + caml_set_instruction(caml_start_code + pos / sizeof(opcode_t), BREAK); + break; + case REQ_RESET_INSTR: + pos = caml_getword(dbg_in); + Assert (pos >= 0); + Assert (pos < caml_code_size); + pos = pos / sizeof(opcode_t); + caml_set_instruction(caml_start_code + pos, caml_saved_code[pos]); + break; + case REQ_CHECKPOINT: +#ifndef _WIN32 + i = fork(); + if (i == 0) { + close_connection(); /* Close parent connection. */ + open_connection(); /* Open new connection with debugger */ + } else { + caml_putword(dbg_out, i); + caml_flush(dbg_out); + } +#else + caml_fatal_error("error: REQ_CHECKPOINT command"); + exit(-1); +#endif + break; + case REQ_GO: + caml_event_count = caml_getword(dbg_in); + return; + case REQ_STOP: + exit(0); + break; + case REQ_WAIT: +#ifndef _WIN32 + wait(NULL); +#else + caml_fatal_error("Fatal error: REQ_WAIT command"); + exit(-1); +#endif + break; + case REQ_INITIAL_FRAME: + frame = caml_extern_sp + 1; + /* Fall through */ + case REQ_GET_FRAME: + caml_putword(dbg_out, caml_stack_high - frame); + if (frame < caml_stack_high){ + caml_putword(dbg_out, (Pc(frame) - caml_start_code) * sizeof(opcode_t)); + }else{ + caml_putword (dbg_out, 0); + } + caml_flush(dbg_out); + break; + case REQ_SET_FRAME: + i = caml_getword(dbg_in); + frame = caml_stack_high - i; + break; + case REQ_UP_FRAME: + i = caml_getword(dbg_in); + if (frame + Extra_args(frame) + i + 3 >= caml_stack_high) { + caml_putword(dbg_out, -1); + } else { + frame += Extra_args(frame) + i + 3; + caml_putword(dbg_out, caml_stack_high - frame); + caml_putword(dbg_out, (Pc(frame) - caml_start_code) * sizeof(opcode_t)); + } + caml_flush(dbg_out); + break; + case REQ_SET_TRAP_BARRIER: + i = caml_getword(dbg_in); + caml_trap_barrier = caml_stack_high - i; + break; + case REQ_GET_LOCAL: + i = caml_getword(dbg_in); + putval(dbg_out, Locals(frame)[i]); + caml_flush(dbg_out); + break; + case REQ_GET_ENVIRONMENT: + i = caml_getword(dbg_in); + putval(dbg_out, Field(Env(frame), i)); + caml_flush(dbg_out); + break; + case REQ_GET_GLOBAL: + i = caml_getword(dbg_in); + putval(dbg_out, Field(caml_global_data, i)); + caml_flush(dbg_out); + break; + case REQ_GET_ACCU: + putval(dbg_out, *caml_extern_sp); + caml_flush(dbg_out); + break; + case REQ_GET_HEADER: + val = getval(dbg_in); + caml_putword(dbg_out, Hd_val(val)); + caml_flush(dbg_out); + break; + case REQ_GET_FIELD: + val = getval(dbg_in); + i = caml_getword(dbg_in); + if (Tag_val(val) != Double_array_tag) { + putch(dbg_out, 0); + putval(dbg_out, Field(val, i)); + } else { + double d = Double_field(val, i); + putch(dbg_out, 1); + caml_really_putblock(dbg_out, (char *) &d, 8); + } + caml_flush(dbg_out); + break; + case REQ_MARSHAL_OBJ: + val = getval(dbg_in); + safe_output_value(dbg_out, val); + caml_flush(dbg_out); + break; + case REQ_GET_CLOSURE_CODE: + val = getval(dbg_in); + caml_putword(dbg_out, (Code_val(val)-caml_start_code) * sizeof(opcode_t)); + caml_flush(dbg_out); + break; + } + } +} + +#endif diff --git a/byterun/debugger.h b/byterun/debugger.h new file mode 100644 index 0000000..ffefc44 --- /dev/null +++ b/byterun/debugger.h @@ -0,0 +1,110 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: debugger.h,v 1.10 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Interface with the debugger */ + +#ifndef CAML_DEBUGGER_H +#define CAML_DEBUGGER_H + +#include "misc.h" +#include "mlvalues.h" + +extern int caml_debugger_in_use; +extern int running; +extern uintnat caml_event_count; + +enum event_kind { + EVENT_COUNT, BREAKPOINT, PROGRAM_START, PROGRAM_EXIT, + TRAP_BARRIER, UNCAUGHT_EXC +}; + +void caml_debugger_init (void); +void caml_debugger (enum event_kind event); + +/* Communication protocol */ + +/* Requests from the debugger to the runtime system */ + +enum debugger_request { + REQ_SET_EVENT = 'e', /* uint32 pos */ + /* Set an event on the instruction at position pos */ + REQ_SET_BREAKPOINT = 'B', /* uint32 pos, (char k) */ + /* Set a breakpoint at position pos */ + /* In profiling mode, the breakpoint kind is set to k */ + REQ_RESET_INSTR = 'i', /* uint32 pos */ + /* Clear an event or breapoint at position pos, restores initial instr. */ + REQ_CHECKPOINT = 'c', /* no args */ + /* Checkpoint the runtime system by forking a child process. + Reply is pid of child process or -1 if checkpoint failed. */ + REQ_GO = 'g', /* uint32 n */ + /* Run the program for n events. + Reply is one of debugger_reply described below. */ + REQ_STOP = 's', /* no args */ + /* Terminate the runtime system */ + REQ_WAIT = 'w', /* no args */ + /* Reap one dead child (a discarded checkpoint). */ + REQ_INITIAL_FRAME = '0', /* no args */ + /* Set current frame to bottom frame (the one currently executing). + Reply is stack offset and current pc. */ + REQ_GET_FRAME = 'f', /* no args */ + /* Return current frame location (stack offset + current pc). */ + REQ_SET_FRAME = 'S', /* uint32 stack_offset */ + /* Set current frame to given stack offset. No reply. */ + REQ_UP_FRAME = 'U', /* uint32 n */ + /* Move one frame up. Argument n is size of current frame (in words). + Reply is stack offset and current pc, or -1 if top of stack reached. */ + REQ_SET_TRAP_BARRIER = 'b', /* uint32 offset */ + /* Set the trap barrier at the given offset. */ + REQ_GET_LOCAL = 'L', /* uint32 slot_number */ + /* Return the local variable at the given slot in the current frame. + Reply is one value. */ + REQ_GET_ENVIRONMENT = 'E', /* uint32 slot_number */ + /* Return the local variable at the given slot in the heap environment + of the current frame. Reply is one value. */ + REQ_GET_GLOBAL = 'G', /* uint32 global_number */ + /* Return the specified global variable. Reply is one value. */ + REQ_GET_ACCU = 'A', /* no args */ + /* Return the current contents of the accumulator. Reply is one value. */ + REQ_GET_HEADER = 'H', /* mlvalue v */ + /* As REQ_GET_OBJ, but sends only the header. */ + REQ_GET_FIELD = 'F', /* mlvalue v, uint32 fieldnum */ + /* As REQ_GET_OBJ, but sends only one field. */ + REQ_MARSHAL_OBJ = 'M', /* mlvalue v */ + /* Send a copy of the data structure rooted at v, using the same + format as [caml_output_value]. */ + REQ_GET_CLOSURE_CODE = 'C' /* mlvalue v */ + /* Send the code address of the given closure. + Reply is one uint32. */ +}; + +/* Replies to a REQ_GO request. All replies are followed by three uint32: + - the value of the event counter + - the position of the stack + - the current pc. */ + +enum debugger_reply { + REP_EVENT = 'e', + /* Event counter reached 0. */ + REP_BREAKPOINT = 'b', + /* Breakpoint hit. */ + REP_EXITED = 'x', + /* Program exited by calling exit or reaching the end of the source. */ + REP_TRAP = 's', + /* Trap barrier crossed. */ + REP_UNCAUGHT_EXC = 'u' + /* Program exited due to a stray exception. */ +}; + +#endif /* CAML_DEBUGGER_H */ diff --git a/byterun/dynlink.c b/byterun/dynlink.c new file mode 100644 index 0000000..9bbfaa5 --- /dev/null +++ b/byterun/dynlink.c @@ -0,0 +1,267 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dynlink.c,v 1.18 2008-04-22 12:24:10 frisch Exp $ */ + +/* Dynamic loading of C primitives. */ + +#include +#include +#include +#include +#include +#include "config.h" +#ifdef HAS_UNISTD +#include +#endif +#include "alloc.h" +#include "dynlink.h" +#include "fail.h" +#include "mlvalues.h" +#include "memory.h" +#include "misc.h" +#include "osdeps.h" +#include "prims.h" + +#ifndef NATIVE_CODE + +/* The table of primitives */ +struct ext_table caml_prim_table; + +#ifdef DEBUG +/* The names of primitives (for instrtrace.c) */ +struct ext_table caml_prim_name_table; +#endif + +/* The table of shared libraries currently opened */ +static struct ext_table shared_libs; + +/* The search path for shared libraries */ +struct ext_table caml_shared_libs_path; + +/* Look up the given primitive name in the built-in primitive table, + then in the opened shared libraries (shared_libs) */ +static c_primitive lookup_primitive(char * name) +{ + int i; + void * res; + + for (i = 0; caml_names_of_builtin_cprim[i] != NULL; i++) { + if (strcmp(name, caml_names_of_builtin_cprim[i]) == 0) + return caml_builtin_cprim[i]; + } + for (i = 0; i < shared_libs.size; i++) { + res = caml_dlsym(shared_libs.contents[i], name); + if (res != NULL) return (c_primitive) res; + } + return NULL; +} + +/* Parse the OCAML_STDLIB_DIR/ld.conf file and add the directories + listed there to the search path */ + +#define LD_CONF_NAME "ld.conf" + +static char * parse_ld_conf(void) +{ + char * stdlib, * ldconfname, * config, * p, * q; + struct stat st; + int ldconf, nread; + + stdlib = getenv("OCAMLLIB"); + if (stdlib == NULL) stdlib = getenv("CAMLLIB"); + if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR; + ldconfname = caml_stat_alloc(strlen(stdlib) + 2 + sizeof(LD_CONF_NAME)); + strcpy(ldconfname, stdlib); + strcat(ldconfname, "/" LD_CONF_NAME); + if (stat(ldconfname, &st) == -1) { + caml_stat_free(ldconfname); + return NULL; + } + ldconf = open(ldconfname, O_RDONLY, 0); + if (ldconf == -1) + caml_fatal_error_arg("Fatal error: cannot read loader config file %s\n", + ldconfname); + config = caml_stat_alloc(st.st_size + 1); + nread = read(ldconf, config, st.st_size); + if (nread == -1) + caml_fatal_error_arg + ("Fatal error: error while reading loader config file %s\n", + ldconfname); + config[nread] = 0; + q = config; + for (p = config; *p != 0; p++) { + if (*p == '\n') { + *p = 0; + caml_ext_table_add(&caml_shared_libs_path, q); + q = p + 1; + } + } + if (q < p) caml_ext_table_add(&caml_shared_libs_path, q); + close(ldconf); + caml_stat_free(ldconfname); + return config; +} + +/* Open the given shared library and add it to shared_libs. + Abort on error. */ +static void open_shared_lib(char * name) +{ + char * realname; + void * handle; + + realname = caml_search_dll_in_path(&caml_shared_libs_path, name); + caml_gc_message(0x100, "Loading shared library %s\n", + (uintnat) realname); + handle = caml_dlopen(realname, 1, 1); + if (handle == NULL) + caml_fatal_error_arg2("Fatal error: cannot load shared library %s\n", name, + "Reason: %s\n", caml_dlerror()); + caml_ext_table_add(&shared_libs, handle); + caml_stat_free(realname); +} + +/* Build the table of primitives, given a search path and a list + of shared libraries (both 0-separated in a char array). + Abort the runtime system on error. */ +void caml_build_primitive_table(char * lib_path, + char * libs, + char * req_prims) +{ + char * tofree1, * tofree2; + char * p; + + /* Initialize the search path for dynamic libraries: + - directories specified on the command line with the -I option + - directories specified in the CAML_LD_LIBRARY_PATH + - directories specified in the executable + - directories specified in the file /ld.conf */ + tofree1 = caml_decompose_path(&caml_shared_libs_path, + getenv("CAML_LD_LIBRARY_PATH")); + if (lib_path != NULL) + for (p = lib_path; *p != 0; p += strlen(p) + 1) + caml_ext_table_add(&caml_shared_libs_path, p); + tofree2 = parse_ld_conf(); + /* Open the shared libraries */ + caml_ext_table_init(&shared_libs, 8); + if (libs != NULL) + for (p = libs; *p != 0; p += strlen(p) + 1) + open_shared_lib(p); + /* Build the primitive table */ + caml_ext_table_init(&caml_prim_table, 0x180); +#ifdef DEBUG + caml_ext_table_init(&caml_prim_name_table, 0x180); +#endif + for (p = req_prims; *p != 0; p += strlen(p) + 1) { + c_primitive prim = lookup_primitive(p); + if (prim == NULL) + caml_fatal_error_arg("Fatal error: unknown C primitive `%s'\n", p); + caml_ext_table_add(&caml_prim_table, (void *) prim); +#ifdef DEBUG + caml_ext_table_add(&caml_prim_name_table, strdup(p)); +#endif + } + /* Clean up */ + caml_stat_free(tofree1); + caml_stat_free(tofree2); + caml_ext_table_free(&caml_shared_libs_path, 0); +} + +/* Build the table of primitives as a copy of the builtin primitive table. + Used for executables generated by ocamlc -output-obj. */ + +void caml_build_primitive_table_builtin(void) +{ + int i; + caml_ext_table_init(&caml_prim_table, 0x180); + for (i = 0; caml_builtin_cprim[i] != 0; i++) + caml_ext_table_add(&caml_prim_table, (void *) caml_builtin_cprim[i]); +} + +#endif /* NATIVE_CODE */ + +/** dlopen interface for the bytecode linker **/ + +#define Handle_val(v) (*((void **) (v))) + +CAMLprim value caml_dynlink_open_lib(value mode, value filename) +{ + void * handle; + value result; + + caml_gc_message(0x100, "Opening shared library %s\n", + (uintnat) String_val(filename)); + handle = caml_dlopen(String_val(filename), Int_val(mode), 1); + if (handle == NULL) caml_failwith(caml_dlerror()); + result = caml_alloc_small(1, Abstract_tag); + Handle_val(result) = handle; + return result; +} + +CAMLprim value caml_dynlink_close_lib(value handle) +{ + caml_dlclose(Handle_val(handle)); + return Val_unit; +} + +/*#include */ +CAMLprim value caml_dynlink_lookup_symbol(value handle, value symbolname) +{ + void * symb; + value result; + symb = caml_dlsym(Handle_val(handle), String_val(symbolname)); + /* printf("%s = 0x%lx\n", String_val(symbolname), symb); + fflush(stdout); */ + if (symb == NULL) return Val_unit /*caml_failwith(caml_dlerror())*/; + result = caml_alloc_small(1, Abstract_tag); + Handle_val(result) = symb; + return result; +} + +#ifndef NATIVE_CODE + +CAMLprim value caml_dynlink_add_primitive(value handle) +{ + return Val_int(caml_ext_table_add(&caml_prim_table, Handle_val(handle))); +} + +CAMLprim value caml_dynlink_get_current_libs(value unit) +{ + CAMLparam0(); + CAMLlocal1(res); + int i; + + res = caml_alloc_tuple(shared_libs.size); + for (i = 0; i < shared_libs.size; i++) { + value v = caml_alloc_small(1, Abstract_tag); + Handle_val(v) = shared_libs.contents[i]; + Store_field(res, i, v); + } + CAMLreturn(res); +} + +#else + +value caml_dynlink_add_primitive(value handle) +{ + caml_invalid_argument("dynlink_add_primitive"); + return Val_unit; /* not reached */ +} + +value caml_dynlink_get_current_libs(value unit) +{ + caml_invalid_argument("dynlink_get_current_libs"); + return Val_unit; /* not reached */ +} + +#endif /* NATIVE_CODE */ diff --git a/byterun/dynlink.h b/byterun/dynlink.h new file mode 100644 index 0000000..cf7fefc --- /dev/null +++ b/byterun/dynlink.h @@ -0,0 +1,38 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dynlink.h,v 1.8 2004-02-22 15:07:51 xleroy Exp $ */ + +/* Dynamic loading of C primitives. */ + +#ifndef CAML_DYNLINK_H +#define CAML_DYNLINK_H + +#include "misc.h" + +/* Build the table of primitives, given a search path, a list + of shared libraries, and a list of primitive names + (all three 0-separated in char arrays). + Abort the runtime system on error. */ +extern void caml_build_primitive_table(char * lib_path, + char * libs, + char * req_prims); + +/* The search path for shared libraries */ +extern struct ext_table caml_shared_libs_path; + +/* Build the table of primitives as a copy of the builtin primitive table. + Used for executables generated by ocamlc -output-obj. */ +extern void caml_build_primitive_table_builtin(void); + +#endif /* CAML_DYNLINK_H */ diff --git a/byterun/exec.h b/byterun/exec.h new file mode 100644 index 0000000..6e87d21 --- /dev/null +++ b/byterun/exec.h @@ -0,0 +1,62 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: exec.h,v 1.14 2004-06-01 12:36:34 xleroy Exp $ */ + +/* exec.h : format of executable bytecode files */ + +#ifndef CAML_EXEC_H +#define CAML_EXEC_H + +/* Executable bytecode files are composed of a number of sections, + identified by 4-character names. A table of contents at the + end of the file lists the section names along with their sizes, + in the order in which they appear in the file: + + offset 0 ---> initial junk + data for section 1 + data for section 2 + ... + data for section N + table of contents: + descriptor for section 1 + ... + descriptor for section N + trailer + end of file ---> +*/ + +/* Structure of t.o.c. entries + Numerical quantities are 32-bit unsigned integers, big endian */ + +struct section_descriptor { + char name[4]; /* Section name */ + uint32 len; /* Length of data in bytes */ +}; + +/* Structure of the trailer. */ + +struct exec_trailer { + uint32 num_sections; /* Number of sections */ + char magic[12]; /* The magic number */ + struct section_descriptor * section; /* Not part of file */ +}; + +#define TRAILER_SIZE (4+12) + +/* Magic number for this release */ + +#define EXEC_MAGIC "Caml1999X008" + + +#endif /* CAML_EXEC_H */ diff --git a/byterun/extern.c b/byterun/extern.c new file mode 100644 index 0000000..4550eaa --- /dev/null +++ b/byterun/extern.c @@ -0,0 +1,726 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: extern.c,v 1.64 2008-08-04 11:45:58 xleroy Exp $ */ + +/* Structured output */ + +/* The interface of this file is "intext.h" */ + +#include +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "gc.h" +#include "intext.h" +#include "io.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "reverse.h" + +static uintnat obj_counter; /* Number of objects emitted so far */ +static uintnat size_32; /* Size in words of 32-bit block for struct. */ +static uintnat size_64; /* Size in words of 64-bit block for struct. */ + +static int extern_ignore_sharing; /* Flag to ignore sharing */ +static int extern_closures; /* Flag to allow externing code pointers */ + +/* Trail mechanism to undo forwarding pointers put inside objects */ + +struct trail_entry { + value obj; /* address of object + initial color in low 2 bits */ + value field0; /* initial contents of field 0 */ +}; + +struct trail_block { + struct trail_block * previous; + struct trail_entry entries[ENTRIES_PER_TRAIL_BLOCK]; +}; + +static struct trail_block extern_trail_first; +static struct trail_block * extern_trail_block; +static struct trail_entry * extern_trail_cur, * extern_trail_limit; + +/* Forward declarations */ + +static void extern_out_of_memory(void); +static void extern_invalid_argument(char *msg); + +/* Initialize the trail */ + +static void init_extern_trail(void) +{ + extern_trail_block = &extern_trail_first; + extern_trail_cur = extern_trail_block->entries; + extern_trail_limit = extern_trail_block->entries + ENTRIES_PER_TRAIL_BLOCK; +} + +/* Replay the trail, undoing the in-place modifications + performed on objects */ + +static void extern_replay_trail(void) +{ + struct trail_block * blk, * prevblk; + struct trail_entry * ent, * lim; + + blk = extern_trail_block; + lim = extern_trail_cur; + while (1) { + for (ent = &(blk->entries[0]); ent < lim; ent++) { + value obj = ent->obj; + color_t colornum = obj & 3; + obj = obj & ~3; + Hd_val(obj) = Coloredhd_hd(Hd_val(obj), colornum); + Field(obj, 0) = ent->field0; + } + if (blk == &extern_trail_first) break; + prevblk = blk->previous; + free(blk); + blk = prevblk; + lim = &(blk->entries[ENTRIES_PER_TRAIL_BLOCK]); + } + /* Protect against a second call to extern_replay_trail */ + extern_trail_block = &extern_trail_first; + extern_trail_cur = extern_trail_block->entries; +} + +/* Set forwarding pointer on an object and add corresponding entry + to the trail. */ + +static void extern_record_location(value obj) +{ + header_t hdr; + + if (extern_ignore_sharing) return; + if (extern_trail_cur == extern_trail_limit) { + struct trail_block * new_block = malloc(sizeof(struct trail_block)); + if (new_block == NULL) extern_out_of_memory(); + new_block->previous = extern_trail_block; + extern_trail_block = new_block; + extern_trail_cur = extern_trail_block->entries; + extern_trail_limit = extern_trail_block->entries + ENTRIES_PER_TRAIL_BLOCK; + } + hdr = Hd_val(obj); + extern_trail_cur->obj = obj | Colornum_hd(hdr); + extern_trail_cur->field0 = Field(obj, 0); + extern_trail_cur++; + Hd_val(obj) = Bluehd_hd(hdr); + Field(obj, 0) = (value) obj_counter; + obj_counter++; +} + +/* To buffer the output */ + +static char * extern_userprovided_output; +static char * extern_ptr, * extern_limit; + +struct output_block { + struct output_block * next; + char * end; + char data[SIZE_EXTERN_OUTPUT_BLOCK]; +}; + +static struct output_block * extern_output_first, * extern_output_block; + +static void init_extern_output(void) +{ + extern_userprovided_output = NULL; + extern_output_first = malloc(sizeof(struct output_block)); + if (extern_output_first == NULL) caml_raise_out_of_memory(); + extern_output_block = extern_output_first; + extern_output_block->next = NULL; + extern_ptr = extern_output_block->data; + extern_limit = extern_output_block->data + SIZE_EXTERN_OUTPUT_BLOCK; +} + +static void close_extern_output(void) +{ + if (extern_userprovided_output == NULL){ + extern_output_block->end = extern_ptr; + } +} + +static void free_extern_output(void) +{ + struct output_block * blk, * nextblk; + + if (extern_userprovided_output != NULL) return; + for (blk = extern_output_first; blk != NULL; blk = nextblk) { + nextblk = blk->next; + free(blk); + } + extern_output_first = NULL; +} + +static void grow_extern_output(intnat required) +{ + struct output_block * blk; + intnat extra; + + if (extern_userprovided_output != NULL) { + extern_replay_trail(); + caml_failwith("Marshal.to_buffer: buffer overflow"); + } + extern_output_block->end = extern_ptr; + if (required <= SIZE_EXTERN_OUTPUT_BLOCK / 2) + extra = 0; + else + extra = required; + blk = malloc(sizeof(struct output_block) + extra); + if (blk == NULL) extern_out_of_memory(); + extern_output_block->next = blk; + extern_output_block = blk; + extern_output_block->next = NULL; + extern_ptr = extern_output_block->data; + extern_limit = extern_output_block->data + SIZE_EXTERN_OUTPUT_BLOCK + extra; +} + +static intnat extern_output_length(void) +{ + struct output_block * blk; + intnat len; + + if (extern_userprovided_output != NULL) { + return extern_ptr - extern_userprovided_output; + } else { + for (len = 0, blk = extern_output_first; blk != NULL; blk = blk->next) + len += blk->end - blk->data; + return len; + } +} + +/* Exception raising, with cleanup */ + +static void extern_out_of_memory(void) +{ + extern_replay_trail(); + free_extern_output(); + caml_raise_out_of_memory(); +} + +static void extern_invalid_argument(char *msg) +{ + extern_replay_trail(); + free_extern_output(); + caml_invalid_argument(msg); +} + +/* Write characters, integers, and blocks in the output buffer */ + +#define Write(c) \ + if (extern_ptr >= extern_limit) grow_extern_output(1); \ + *extern_ptr++ = (c) + +static void writeblock(char *data, intnat len) +{ + if (extern_ptr + len > extern_limit) grow_extern_output(len); + memmove(extern_ptr, data, len); + extern_ptr += len; +} + +#if ARCH_FLOAT_ENDIANNESS == 0x01234567 || ARCH_FLOAT_ENDIANNESS == 0x76543210 +#define writeblock_float8(data,ndoubles) \ + writeblock((char *)(data), (ndoubles) * 8) +#else +#define writeblock_float8(data,ndoubles) \ + caml_serialize_block_float_8((data), (ndoubles)) +#endif + +static void writecode8(int code, intnat val) +{ + if (extern_ptr + 2 > extern_limit) grow_extern_output(2); + extern_ptr[0] = code; + extern_ptr[1] = val; + extern_ptr += 2; +} + +static void writecode16(int code, intnat val) +{ + if (extern_ptr + 3 > extern_limit) grow_extern_output(3); + extern_ptr[0] = code; + extern_ptr[1] = val >> 8; + extern_ptr[2] = val; + extern_ptr += 3; +} + +static void write32(intnat val) +{ + if (extern_ptr + 4 > extern_limit) grow_extern_output(4); + extern_ptr[0] = val >> 24; + extern_ptr[1] = val >> 16; + extern_ptr[2] = val >> 8; + extern_ptr[3] = val; + extern_ptr += 4; +} + +static void writecode32(int code, intnat val) +{ + if (extern_ptr + 5 > extern_limit) grow_extern_output(5); + extern_ptr[0] = code; + extern_ptr[1] = val >> 24; + extern_ptr[2] = val >> 16; + extern_ptr[3] = val >> 8; + extern_ptr[4] = val; + extern_ptr += 5; +} + +#ifdef ARCH_SIXTYFOUR +static void writecode64(int code, intnat val) +{ + int i; + if (extern_ptr + 9 > extern_limit) grow_extern_output(9); + *extern_ptr ++ = code; + for (i = 64 - 8; i >= 0; i -= 8) *extern_ptr++ = val >> i; +} +#endif + +/* Marshal the given value in the output buffer */ + +static void extern_rec(value v) +{ + tailcall: + if (Is_long(v)) { + intnat n = Long_val(v); + if (n >= 0 && n < 0x40) { + Write(PREFIX_SMALL_INT + n); + } else if (n >= -(1 << 7) && n < (1 << 7)) { + writecode8(CODE_INT8, n); + } else if (n >= -(1 << 15) && n < (1 << 15)) { + writecode16(CODE_INT16, n); +#ifdef ARCH_SIXTYFOUR + } else if (n < -((intnat)1 << 31) || n >= ((intnat)1 << 31)) { + writecode64(CODE_INT64, n); +#endif + } else + writecode32(CODE_INT32, n); + return; + } + if (Is_in_value_area(v)) { + header_t hd = Hd_val(v); + tag_t tag = Tag_hd(hd); + mlsize_t sz = Wosize_hd(hd); + + if (tag == Forward_tag) { + value f = Forward_val (v); + if (Is_block (f) + && (!Is_in_value_area(f) || Tag_val (f) == Forward_tag + || Tag_val (f) == Lazy_tag || Tag_val (f) == Double_tag)){ + /* Do not short-circuit the pointer. */ + }else{ + v = f; + goto tailcall; + } + } + /* Atoms are treated specially for two reasons: they are not allocated + in the externed block, and they are automatically shared. */ + if (sz == 0) { + if (tag < 16) { + Write(PREFIX_SMALL_BLOCK + tag); + } else { + writecode32(CODE_BLOCK32, hd); + } + return; + } + /* Check if already seen */ + if (Color_hd(hd) == Caml_blue) { + uintnat d = obj_counter - (uintnat) Field(v, 0); + if (d < 0x100) { + writecode8(CODE_SHARED8, d); + } else if (d < 0x10000) { + writecode16(CODE_SHARED16, d); + } else { + writecode32(CODE_SHARED32, d); + } + return; + } + + /* Output the contents of the object */ + switch(tag) { + case String_tag: { + mlsize_t len = caml_string_length(v); + if (len < 0x20) { + Write(PREFIX_SMALL_STRING + len); + } else if (len < 0x100) { + writecode8(CODE_STRING8, len); + } else { + writecode32(CODE_STRING32, len); + } + writeblock(String_val(v), len); + size_32 += 1 + (len + 4) / 4; + size_64 += 1 + (len + 8) / 8; + extern_record_location(v); + break; + } + case Double_tag: { + if (sizeof(double) != 8) + extern_invalid_argument("output_value: non-standard floats"); + Write(CODE_DOUBLE_NATIVE); + writeblock_float8((double *) v, 1); + size_32 += 1 + 2; + size_64 += 1 + 1; + extern_record_location(v); + break; + } + case Double_array_tag: { + mlsize_t nfloats; + if (sizeof(double) != 8) + extern_invalid_argument("output_value: non-standard floats"); + nfloats = Wosize_val(v) / Double_wosize; + if (nfloats < 0x100) { + writecode8(CODE_DOUBLE_ARRAY8_NATIVE, nfloats); + } else { + writecode32(CODE_DOUBLE_ARRAY32_NATIVE, nfloats); + } + writeblock_float8((double *) v, nfloats); + size_32 += 1 + nfloats * 2; + size_64 += 1 + nfloats; + extern_record_location(v); + break; + } + case Abstract_tag: + extern_invalid_argument("output_value: abstract value (Abstract)"); + break; + case Infix_tag: + writecode32(CODE_INFIXPOINTER, Infix_offset_hd(hd)); + extern_rec(v - Infix_offset_hd(hd)); + break; + case Custom_tag: { + uintnat sz_32, sz_64; + char * ident = Custom_ops_val(v)->identifier; + void (*serialize)(value v, uintnat * wsize_32, + uintnat * wsize_64) + = Custom_ops_val(v)->serialize; + if (serialize == NULL) + extern_invalid_argument("output_value: abstract value (Custom)"); + Write(CODE_CUSTOM); + writeblock(ident, strlen(ident) + 1); + Custom_ops_val(v)->serialize(v, &sz_32, &sz_64); + size_32 += 2 + ((sz_32 + 3) >> 2); /* header + ops + data */ + size_64 += 2 + ((sz_64 + 7) >> 3); + extern_record_location(v); + break; + } + default: { + value field0; + mlsize_t i; + if (tag < 16 && sz < 8) { + Write(PREFIX_SMALL_BLOCK + tag + (sz << 4)); +#ifdef ARCH_SIXTYFOUR + } else if (hd >= ((uintnat)1 << 32)) { + writecode64(CODE_BLOCK64, Whitehd_hd (hd)); +#endif + } else { + writecode32(CODE_BLOCK32, Whitehd_hd (hd)); + } + size_32 += 1 + sz; + size_64 += 1 + sz; + field0 = Field(v, 0); + extern_record_location(v); + if (sz == 1) { + v = field0; + } else { + extern_rec(field0); + for (i = 1; i < sz - 1; i++) extern_rec(Field(v, i)); + v = Field(v, i); + } + goto tailcall; + } + } + } + else if ((char *) v >= caml_code_area_start && + (char *) v < caml_code_area_end) { + if (!extern_closures) + extern_invalid_argument("output_value: functional value"); + writecode32(CODE_CODEPOINTER, (char *) v - caml_code_area_start); + writeblock((char *) caml_code_checksum(), 16); + } else { + extern_invalid_argument("output_value: abstract value (outside heap)"); + } +} + +enum { NO_SHARING = 1, CLOSURES = 2 }; +static int extern_flags[] = { NO_SHARING, CLOSURES }; + +static intnat extern_value(value v, value flags) +{ + intnat res_len; + int fl; + /* Parse flag list */ + fl = caml_convert_flag_list(flags, extern_flags); + extern_ignore_sharing = fl & NO_SHARING; + extern_closures = fl & CLOSURES; + /* Initializations */ + init_extern_trail(); + obj_counter = 0; + size_32 = 0; + size_64 = 0; + /* Write magic number */ + write32(Intext_magic_number); + /* Set aside space for the sizes */ + extern_ptr += 4*4; + /* Marshal the object */ + extern_rec(v); + /* Record end of output */ + close_extern_output(); + /* Undo the modifications done on externed blocks */ + extern_replay_trail(); + /* Write the sizes */ + res_len = extern_output_length(); +#ifdef ARCH_SIXTYFOUR + if (res_len >= ((intnat)1 << 32) || + size_32 >= ((intnat)1 << 32) || size_64 >= ((intnat)1 << 32)) { + /* The object is so big its size cannot be written in the header. + Besides, some of the array lengths or string lengths or shared offsets + it contains may have overflowed the 32 bits used to write them. */ + free_extern_output(); + caml_failwith("output_value: object too big"); + } +#endif + if (extern_userprovided_output != NULL) + extern_ptr = extern_userprovided_output + 4; + else { + extern_ptr = extern_output_first->data + 4; + extern_limit = extern_output_first->data + SIZE_EXTERN_OUTPUT_BLOCK; + } + write32(res_len - 5*4); + write32(obj_counter); + write32(size_32); + write32(size_64); + return res_len; +} + +void caml_output_val(struct channel *chan, value v, value flags) +{ + intnat len; + struct output_block * blk, * nextblk; + + if (! caml_channel_binary_mode(chan)) + caml_failwith("output_value: not a binary channel"); + init_extern_output(); + len = extern_value(v, flags); + /* During [caml_really_putblock], concurrent [caml_output_val] operations + can take place (via signal handlers or context switching in systhreads), + and [extern_output_first] may change. So, save it in a local variable. */ + blk = extern_output_first; + while (blk != NULL) { + caml_really_putblock(chan, blk->data, blk->end - blk->data); + nextblk = blk->next; + free(blk); + blk = nextblk; + } +} + +CAMLprim value caml_output_value(value vchan, value v, value flags) +{ + CAMLparam3 (vchan, v, flags); + struct channel * channel = Channel(vchan); + + Lock(channel); + caml_output_val(channel, v, flags); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_output_value_to_string(value v, value flags) +{ + intnat len, ofs; + value res; + struct output_block * blk, * nextblk; + + init_extern_output(); + len = extern_value(v, flags); + /* PR#4030: it is prudent to save extern_output_first before allocating + the result, as in caml_output_val */ + blk = extern_output_first; + res = caml_alloc_string(len); + ofs = 0; + while (blk != NULL) { + int n = blk->end - blk->data; + memmove(&Byte(res, ofs), blk->data, n); + ofs += n; + nextblk = blk->next; + free(blk); + blk = nextblk; + } + return res; +} + +CAMLprim value caml_output_value_to_buffer(value buf, value ofs, value len, + value v, value flags) +{ + intnat len_res; + extern_userprovided_output = &Byte(buf, Long_val(ofs)); + extern_ptr = extern_userprovided_output; + extern_limit = extern_userprovided_output + Long_val(len); + len_res = extern_value(v, flags); + return Val_long(len_res); +} + +CAMLexport void caml_output_value_to_malloc(value v, value flags, + /*out*/ char ** buf, + /*out*/ intnat * len) +{ + intnat len_res; + char * res; + struct output_block * blk; + + init_extern_output(); + len_res = extern_value(v, flags); + res = malloc(len_res); + if (res == NULL) extern_out_of_memory(); + *buf = res; + *len = len_res; + for (blk = extern_output_first; blk != NULL; blk = blk->next) { + int n = blk->end - blk->data; + memmove(res, blk->data, n); + res += n; + } + free_extern_output(); +} + +CAMLexport intnat caml_output_value_to_block(value v, value flags, + char * buf, intnat len) +{ + intnat len_res; + extern_userprovided_output = buf; + extern_ptr = extern_userprovided_output; + extern_limit = extern_userprovided_output + len; + len_res = extern_value(v, flags); + return len_res; +} + +/* Functions for writing user-defined marshallers */ + +CAMLexport void caml_serialize_int_1(int i) +{ + if (extern_ptr + 1 > extern_limit) grow_extern_output(1); + extern_ptr[0] = i; + extern_ptr += 1; +} + +CAMLexport void caml_serialize_int_2(int i) +{ + if (extern_ptr + 2 > extern_limit) grow_extern_output(2); + extern_ptr[0] = i >> 8; + extern_ptr[1] = i; + extern_ptr += 2; +} + +CAMLexport void caml_serialize_int_4(int32 i) +{ + if (extern_ptr + 4 > extern_limit) grow_extern_output(4); + extern_ptr[0] = i >> 24; + extern_ptr[1] = i >> 16; + extern_ptr[2] = i >> 8; + extern_ptr[3] = i; + extern_ptr += 4; +} + +CAMLexport void caml_serialize_int_8(int64 i) +{ + caml_serialize_block_8(&i, 1); +} + +CAMLexport void caml_serialize_float_4(float f) +{ + caml_serialize_block_4(&f, 1); +} + +CAMLexport void caml_serialize_float_8(double f) +{ + caml_serialize_block_float_8(&f, 1); +} + +CAMLexport void caml_serialize_block_1(void * data, intnat len) +{ + if (extern_ptr + len > extern_limit) grow_extern_output(len); + memmove(extern_ptr, data, len); + extern_ptr += len; +} + +CAMLexport void caml_serialize_block_2(void * data, intnat len) +{ + if (extern_ptr + 2 * len > extern_limit) grow_extern_output(2 * len); +#ifndef ARCH_BIG_ENDIAN + { + unsigned char * p; + char * q; + for (p = data, q = extern_ptr; len > 0; len--, p += 2, q += 2) + Reverse_16(q, p); + extern_ptr = q; + } +#else + memmove(extern_ptr, data, len * 2); + extern_ptr += len * 2; +#endif +} + +CAMLexport void caml_serialize_block_4(void * data, intnat len) +{ + if (extern_ptr + 4 * len > extern_limit) grow_extern_output(4 * len); +#ifndef ARCH_BIG_ENDIAN + { + unsigned char * p; + char * q; + for (p = data, q = extern_ptr; len > 0; len--, p += 4, q += 4) + Reverse_32(q, p); + extern_ptr = q; + } +#else + memmove(extern_ptr, data, len * 4); + extern_ptr += len * 4; +#endif +} + +CAMLexport void caml_serialize_block_8(void * data, intnat len) +{ + if (extern_ptr + 8 * len > extern_limit) grow_extern_output(8 * len); +#ifndef ARCH_BIG_ENDIAN + { + unsigned char * p; + char * q; + for (p = data, q = extern_ptr; len > 0; len--, p += 8, q += 8) + Reverse_64(q, p); + extern_ptr = q; + } +#else + memmove(extern_ptr, data, len * 8); + extern_ptr += len * 8; +#endif +} + +CAMLexport void caml_serialize_block_float_8(void * data, intnat len) +{ + if (extern_ptr + 8 * len > extern_limit) grow_extern_output(8 * len); +#if ARCH_FLOAT_ENDIANNESS == 0x01234567 + memmove(extern_ptr, data, len * 8); + extern_ptr += len * 8; +#elif ARCH_FLOAT_ENDIANNESS == 0x76543210 + { + unsigned char * p; + char * q; + for (p = data, q = extern_ptr; len > 0; len--, p += 8, q += 8) + Reverse_64(q, p); + extern_ptr = q; + } +#else + { + unsigned char * p; + char * q; + for (p = data, q = extern_ptr; len > 0; len--, p += 8, q += 8) + Permute_64(q, 0x01234567, p, ARCH_FLOAT_ENDIANNESS); + extern_ptr = q; + } +#endif +} diff --git a/byterun/fail.c b/byterun/fail.c new file mode 100644 index 0000000..8148c2c --- /dev/null +++ b/byterun/fail.c @@ -0,0 +1,157 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fail.c,v 1.32 2008-09-18 11:23:28 xleroy Exp $ */ + +/* Raising exceptions from C. */ + +#include "alloc.h" +#include "fail.h" +#include "io.h" +#include "gc.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "printexc.h" +#include "signals.h" +#include "stacks.h" + +CAMLexport struct longjmp_buffer * caml_external_raise = NULL; +value caml_exn_bucket; + +CAMLexport void caml_raise(value v) +{ + Unlock_exn(); + caml_exn_bucket = v; + if (caml_external_raise == NULL) caml_fatal_uncaught_exception(v); + siglongjmp(caml_external_raise->buf, 1); +} + +CAMLexport void caml_raise_constant(value tag) +{ + CAMLparam1 (tag); + CAMLlocal1 (bucket); + + bucket = caml_alloc_small (1, 0); + Field(bucket, 0) = tag; + caml_raise(bucket); + CAMLnoreturn; +} + +CAMLexport void caml_raise_with_arg(value tag, value arg) +{ + CAMLparam2 (tag, arg); + CAMLlocal1 (bucket); + + bucket = caml_alloc_small (2, 0); + Field(bucket, 0) = tag; + Field(bucket, 1) = arg; + caml_raise(bucket); + CAMLnoreturn; +} + +CAMLexport void caml_raise_with_args(value tag, int nargs, value args[]) +{ + CAMLparam1 (tag); + CAMLxparamN (args, nargs); + value bucket; + int i; + + Assert(1 + nargs <= Max_young_wosize); + bucket = caml_alloc_small (1 + nargs, 0); + Field(bucket, 0) = tag; + for (i = 0; i < nargs; i++) Field(bucket, 1 + i) = args[i]; + caml_raise(bucket); + CAMLnoreturn; +} + +CAMLexport void caml_raise_with_string(value tag, char const *msg) +{ + CAMLparam1 (tag); + CAMLlocal1 (vmsg); + + vmsg = caml_copy_string(msg); + caml_raise_with_arg(tag, vmsg); + CAMLnoreturn; +} + +CAMLexport void caml_failwith (char const *msg) +{ + caml_raise_with_string(Field(caml_global_data, FAILURE_EXN), msg); +} + +CAMLexport void caml_invalid_argument (char const *msg) +{ + caml_raise_with_string(Field(caml_global_data, INVALID_EXN), msg); +} + +CAMLexport void caml_array_bound_error(void) +{ + caml_invalid_argument("index out of bounds"); +} + +/* Problem: we can't use [caml_raise_constant], because it allocates and + we're out of memory... Here, we allocate statically the exn bucket + for [Out_of_memory]. */ + +static struct { + header_t hdr; + value exn; +} out_of_memory_bucket = { 0, 0 }; + +CAMLexport void caml_raise_out_of_memory(void) +{ + if (out_of_memory_bucket.exn == 0) + caml_fatal_error + ("Fatal error: out of memory while raising Out_of_memory\n"); + caml_raise((value) &(out_of_memory_bucket.exn)); +} + +CAMLexport void caml_raise_stack_overflow(void) +{ + caml_raise_constant(Field(caml_global_data, STACK_OVERFLOW_EXN)); +} + +CAMLexport void caml_raise_sys_error(value msg) +{ + caml_raise_with_arg(Field(caml_global_data, SYS_ERROR_EXN), msg); +} + +CAMLexport void caml_raise_end_of_file(void) +{ + caml_raise_constant(Field(caml_global_data, END_OF_FILE_EXN)); +} + +CAMLexport void caml_raise_zero_divide(void) +{ + caml_raise_constant(Field(caml_global_data, ZERO_DIVIDE_EXN)); +} + +CAMLexport void caml_raise_not_found(void) +{ + caml_raise_constant(Field(caml_global_data, NOT_FOUND_EXN)); +} + +CAMLexport void caml_raise_sys_blocked_io(void) +{ + caml_raise_constant(Field(caml_global_data, SYS_BLOCKED_IO)); +} + +/* Initialization of statically-allocated exception buckets */ + +void caml_init_exceptions(void) +{ + out_of_memory_bucket.hdr = Make_header(1, 0, Caml_white); + out_of_memory_bucket.exn = Field(caml_global_data, OUT_OF_MEMORY_EXN); + caml_register_global_root(&out_of_memory_bucket.exn); +} diff --git a/byterun/fail.h b/byterun/fail.h new file mode 100644 index 0000000..afcefad --- /dev/null +++ b/byterun/fail.h @@ -0,0 +1,77 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fail.h,v 1.27 2008-09-18 11:23:28 xleroy Exp $ */ + +#ifndef CAML_FAIL_H +#define CAML_FAIL_H + +/* */ +#include +/* */ + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "misc.h" +#include "mlvalues.h" + +/* */ +#define OUT_OF_MEMORY_EXN 0 /* "Out_of_memory" */ +#define SYS_ERROR_EXN 1 /* "Sys_error" */ +#define FAILURE_EXN 2 /* "Failure" */ +#define INVALID_EXN 3 /* "Invalid_argument" */ +#define END_OF_FILE_EXN 4 /* "End_of_file" */ +#define ZERO_DIVIDE_EXN 5 /* "Division_by_zero" */ +#define NOT_FOUND_EXN 6 /* "Not_found" */ +#define MATCH_FAILURE_EXN 7 /* "Match_failure" */ +#define STACK_OVERFLOW_EXN 8 /* "Stack_overflow" */ +#define SYS_BLOCKED_IO 9 /* "Sys_blocked_io" */ +#define ASSERT_FAILURE_EXN 10 /* "Assert_failure" */ +#define UNDEFINED_RECURSIVE_MODULE_EXN 11 /* "Undefined_recursive_module" */ + +#ifdef POSIX_SIGNALS +struct longjmp_buffer { + sigjmp_buf buf; +}; +#else +struct longjmp_buffer { + jmp_buf buf; +}; +#define sigsetjmp(buf,save) setjmp(buf) +#define siglongjmp(buf,val) longjmp(buf,val) +#endif + +CAMLextern struct longjmp_buffer * caml_external_raise; +extern value caml_exn_bucket; + +/* */ + +CAMLextern void caml_raise (value bucket) Noreturn; +CAMLextern void caml_raise_constant (value tag) Noreturn; +CAMLextern void caml_raise_with_arg (value tag, value arg) Noreturn; +CAMLextern void caml_raise_with_args (value tag, int nargs, value arg[]) Noreturn; +CAMLextern void caml_raise_with_string (value tag, char const * msg) Noreturn; +CAMLextern void caml_failwith (char const *) Noreturn; +CAMLextern void caml_invalid_argument (char const *) Noreturn; +CAMLextern void caml_raise_out_of_memory (void) Noreturn; +CAMLextern void caml_raise_stack_overflow (void) Noreturn; +CAMLextern void caml_raise_sys_error (value) Noreturn; +CAMLextern void caml_raise_end_of_file (void) Noreturn; +CAMLextern void caml_raise_zero_divide (void) Noreturn; +CAMLextern void caml_raise_not_found (void) Noreturn; +CAMLextern void caml_init_exceptions (void); +CAMLextern void caml_array_bound_error (void) Noreturn; +CAMLextern void caml_raise_sys_blocked_io (void) Noreturn; + +#endif /* CAML_FAIL_H */ diff --git a/byterun/finalise.c b/byterun/finalise.c new file mode 100644 index 0000000..a25ee07 --- /dev/null +++ b/byterun/finalise.c @@ -0,0 +1,249 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Moscova, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: finalise.c,v 1.23 2008-07-28 12:03:55 doligez Exp $ */ + +/* Handling of finalised values. */ + +#include "callback.h" +#include "fail.h" +#include "mlvalues.h" +#include "roots.h" +#include "signals.h" + +struct final { + value fun; + value val; + int offset; +}; + +static struct final *final_table = NULL; +static uintnat old = 0, young = 0, size = 0; +/* [0..old) : finalisable set + [old..young) : recent set + [young..size) : free space +*/ + +struct to_do { + struct to_do *next; + int size; + struct final item[1]; /* variable size */ +}; + +static struct to_do *to_do_hd = NULL; +static struct to_do *to_do_tl = NULL; + +static void alloc_to_do (int size) +{ + struct to_do *result = malloc (sizeof (struct to_do) + + size * sizeof (struct final)); + if (result == NULL) caml_fatal_error ("out of memory"); + result->next = NULL; + result->size = size; + if (to_do_tl == NULL){ + to_do_hd = result; + to_do_tl = result; + }else{ + Assert (to_do_tl->next == NULL); + to_do_tl->next = result; + to_do_tl = result; + } +} + +/* Find white finalisable values, put them in the finalising set, and + darken them. + The recent set is empty. +*/ +void caml_final_update (void) +{ + uintnat i, j, k; + uintnat todo_count = 0; + + Assert (young == old); + for (i = 0; i < old; i++){ + Assert (Is_block (final_table[i].val)); + Assert (Is_in_heap (final_table[i].val)); + if (Is_white_val (final_table[i].val)) ++ todo_count; + } + + if (todo_count > 0){ + alloc_to_do (todo_count); + j = k = 0; + for (i = 0; i < old; i++){ + again: + Assert (Is_block (final_table[i].val)); + Assert (Is_in_heap (final_table[i].val)); + if (Is_white_val (final_table[i].val)){ + if (Tag_val (final_table[i].val) == Forward_tag){ + value fv; + Assert (final_table[i].offset == 0); + fv = Forward_val (final_table[i].val); + if (Is_block (fv) + && (!Is_in_value_area(fv) || Tag_val (fv) == Forward_tag + || Tag_val (fv) == Lazy_tag || Tag_val (fv) == Double_tag)){ + /* Do not short-circuit the pointer. */ + }else{ + final_table[i].val = fv; + if (Is_block (final_table[i].val) + && Is_in_heap (final_table[i].val)){ + goto again; + } + } + } + to_do_tl->item[k++] = final_table[i]; + }else{ + final_table[j++] = final_table[i]; + } + } + young = old = j; + to_do_tl->size = k; + for (i = 0; i < k; i++){ + CAMLassert (Is_white_val (to_do_tl->item[i].val)); + caml_darken (to_do_tl->item[i].val, NULL); + } + } +} + +static int running_finalisation_function = 0; + +/* Call the finalisation functions for the finalising set. + Note that this function must be reentrant. +*/ +void caml_final_do_calls (void) +{ + struct final f; + + if (running_finalisation_function) return; + + if (to_do_hd != NULL){ + caml_gc_message (0x80, "Calling finalisation functions.\n", 0); + while (1){ + while (to_do_hd != NULL && to_do_hd->size == 0){ + struct to_do *next_hd = to_do_hd->next; + free (to_do_hd); + to_do_hd = next_hd; + if (to_do_hd == NULL) to_do_tl = NULL; + } + if (to_do_hd == NULL) break; + Assert (to_do_hd->size > 0); + -- to_do_hd->size; + f = to_do_hd->item[to_do_hd->size]; + running_finalisation_function = 1; + caml_callback (f.fun, f.val + f.offset); + running_finalisation_function = 0; + } + caml_gc_message (0x80, "Done calling finalisation functions.\n", 0); + } +} + +/* Call a scanning_action [f] on [x]. */ +#define Call_action(f,x) (*(f)) ((x), &(x)) + +/* Call [*f] on the closures of the finalisable set and + the closures and values of the finalising set. + The recent set is empty. + This is called by the major GC and the compactor + through [caml_darken_all_roots]. +*/ +void caml_final_do_strong_roots (scanning_action f) +{ + uintnat i; + struct to_do *todo; + + Assert (old == young); + for (i = 0; i < old; i++) Call_action (f, final_table[i].fun); + + for (todo = to_do_hd; todo != NULL; todo = todo->next){ + for (i = 0; i < todo->size; i++){ + Call_action (f, todo->item[i].fun); + Call_action (f, todo->item[i].val); + } + } +} + +/* Call [*f] on the values of the finalisable set. + The recent set is empty. + This is called directly by the compactor. +*/ +void caml_final_do_weak_roots (scanning_action f) +{ + uintnat i; + + Assert (old == young); + for (i = 0; i < old; i++) Call_action (f, final_table[i].val); +} + +/* Call [*f] on the closures and values of the recent set. + This is called by the minor GC through [caml_oldify_local_roots]. +*/ +void caml_final_do_young_roots (scanning_action f) +{ + uintnat i; + + Assert (old <= young); + for (i = old; i < young; i++){ + Call_action (f, final_table[i].fun); + Call_action (f, final_table[i].val); + } +} + +/* Empty the recent set into the finalisable set. + This is called at the end of each minor collection. + The minor heap must be empty when this is called. +*/ +void caml_final_empty_young (void) +{ + old = young; +} + +/* Put (f,v) in the recent set. */ +CAMLprim value caml_final_register (value f, value v) +{ + if (!(Is_block (v) && Is_in_heap_or_young(v))) { + caml_invalid_argument ("Gc.finalise"); + } + Assert (old <= young); + + if (young >= size){ + if (final_table == NULL){ + uintnat new_size = 30; + final_table = caml_stat_alloc (new_size * sizeof (struct final)); + Assert (old == 0); + Assert (young == 0); + size = new_size; + }else{ + uintnat new_size = size * 2; + final_table = caml_stat_resize (final_table, + new_size * sizeof (struct final)); + size = new_size; + } + } + Assert (young < size); + final_table[young].fun = f; + if (Tag_val (v) == Infix_tag){ + final_table[young].offset = Infix_offset_val (v); + final_table[young].val = v - Infix_offset_val (v); + }else{ + final_table[young].offset = 0; + final_table[young].val = v; + } + ++ young; + + return Val_unit; +} + +CAMLprim value caml_final_release (value unit) +{ + running_finalisation_function = 0; + return Val_unit; +} diff --git a/byterun/finalise.h b/byterun/finalise.h new file mode 100644 index 0000000..5fb7f30 --- /dev/null +++ b/byterun/finalise.h @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Moscova, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: finalise.h,v 1.5 2004-01-02 19:23:21 doligez Exp $ */ + +#ifndef CAML_FINALISE_H +#define CAML_FINALISE_H + +#include "roots.h" + +void caml_final_update (void); +void caml_final_do_calls (void); +void caml_final_do_strong_roots (scanning_action f); +void caml_final_do_weak_roots (scanning_action f); +void caml_final_do_young_roots (scanning_action f); +void caml_final_empty_young (void); +value caml_final_register (value f, value v); + +#endif /* CAML_FINALISE_H */ diff --git a/byterun/fix_code.c b/byterun/fix_code.c new file mode 100644 index 0000000..d239600 --- /dev/null +++ b/byterun/fix_code.c @@ -0,0 +1,162 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fix_code.c,v 1.31 2004-05-26 11:10:51 garrigue Exp $ */ + +/* Handling of blocks of bytecode (endianness switch, threading). */ + +#include "config.h" + +#ifdef HAS_UNISTD +#include +#endif + +#include "debugger.h" +#include "fix_code.h" +#include "instruct.h" +#include "md5.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "reverse.h" + +code_t caml_start_code; +asize_t caml_code_size; +unsigned char * caml_saved_code; +unsigned char caml_code_md5[16]; + +/* Read the main bytecode block from a file */ + +void caml_load_code(int fd, asize_t len) +{ + int i; + struct MD5Context ctx; + + caml_code_size = len; + caml_start_code = (code_t) caml_stat_alloc(caml_code_size); + if (read(fd, (char *) caml_start_code, caml_code_size) != caml_code_size) + caml_fatal_error("Fatal error: truncated bytecode file.\n"); + caml_MD5Init(&ctx); + caml_MD5Update(&ctx, (unsigned char *) caml_start_code, caml_code_size); + caml_MD5Final(caml_code_md5, &ctx); +#ifdef ARCH_BIG_ENDIAN + caml_fixup_endianness(caml_start_code, caml_code_size); +#endif + if (caml_debugger_in_use) { + len /= sizeof(opcode_t); + caml_saved_code = (unsigned char *) caml_stat_alloc(len); + for (i = 0; i < len; i++) caml_saved_code[i] = caml_start_code[i]; + } +#ifdef THREADED_CODE + /* Better to thread now than at the beginning of [caml_interprete], + since the debugger interface needs to perform SET_EVENT requests + on the code. */ + caml_thread_code(caml_start_code, caml_code_size); +#endif +} + +/* This code is needed only if the processor is big endian */ + +#ifdef ARCH_BIG_ENDIAN + +void caml_fixup_endianness(code_t code, asize_t len) +{ + code_t p; + len /= sizeof(opcode_t); + for (p = code; p < code + len; p++) { + Reverse_32(p, p); + } +} + +#endif + +/* This code is needed only if we're using threaded code */ + +#ifdef THREADED_CODE + +char ** caml_instr_table; +char * caml_instr_base; + +void caml_thread_code (code_t code, asize_t len) +{ + code_t p; + int l [STOP + 1]; + int i; + + for (i = 0; i <= STOP; i++) { + l [i] = 0; + } + /* Instructions with one operand */ + l[PUSHACC] = l[ACC] = l[POP] = l[ASSIGN] = + l[PUSHENVACC] = l[ENVACC] = l[PUSH_RETADDR] = l[APPLY] = + l[APPTERM1] = l[APPTERM2] = l[APPTERM3] = l[RETURN] = + l[GRAB] = l[PUSHGETGLOBAL] = l[GETGLOBAL] = l[SETGLOBAL] = + l[PUSHATOM] = l[ATOM] = l[MAKEBLOCK1] = l[MAKEBLOCK2] = + l[MAKEBLOCK3] = l[MAKEFLOATBLOCK] = l[GETFIELD] = + l[GETFLOATFIELD] = l[SETFIELD] = l[SETFLOATFIELD] = + l[BRANCH] = l[BRANCHIF] = l[BRANCHIFNOT] = l[PUSHTRAP] = + l[C_CALL1] = l[C_CALL2] = l[C_CALL3] = l[C_CALL4] = l[C_CALL5] = + l[CONSTINT] = l[PUSHCONSTINT] = l[OFFSETINT] = + l[OFFSETREF] = l[OFFSETCLOSURE] = l[PUSHOFFSETCLOSURE] = 1; + + /* Instructions with two operands */ + l[APPTERM] = l[CLOSURE] = l[PUSHGETGLOBALFIELD] = + l[GETGLOBALFIELD] = l[MAKEBLOCK] = l[C_CALLN] = + l[BEQ] = l[BNEQ] = l[BLTINT] = l[BLEINT] = l[BGTINT] = l[BGEINT] = + l[BULTINT] = l[BUGEINT] = l[GETPUBMET] = 2; + len /= sizeof(opcode_t); + for (p = code; p < code + len; /*nothing*/) { + opcode_t instr = *p; + if (instr < 0 || instr > STOP){ + /* FIXME -- should Assert(false) ? + caml_fatal_error_arg ("Fatal error in fix_code: bad opcode (%lx)\n", + (char *)(long)instr); + */ + instr = STOP; + } + *p++ = (opcode_t)(caml_instr_table[instr] - caml_instr_base); + if (instr == SWITCH) { + uint32 sizes = *p++; + uint32 const_size = sizes & 0xFFFF; + uint32 block_size = sizes >> 16; + p += const_size + block_size; + } else if (instr == CLOSUREREC) { + uint32 nfuncs = *p++; + p++; /* skip nvars */ + p += nfuncs; + } else { + p += l[instr]; + } + } + Assert(p == code + len); +} + +#endif /* THREADED_CODE */ + +void caml_set_instruction(code_t pos, opcode_t instr) +{ +#ifdef THREADED_CODE + *pos = (opcode_t)(caml_instr_table[instr] - caml_instr_base); +#else + *pos = instr; +#endif +} + +int caml_is_instruction(opcode_t instr1, opcode_t instr2) +{ +#ifdef THREADED_CODE + return instr1 == (opcode_t)(caml_instr_table[instr2] - caml_instr_base); +#else + return instr1 == instr2; +#endif +} diff --git a/byterun/fix_code.h b/byterun/fix_code.h new file mode 100644 index 0000000..e58f349 --- /dev/null +++ b/byterun/fix_code.h @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fix_code.h,v 1.17 2004-01-02 19:23:21 doligez Exp $ */ + +/* Handling of blocks of bytecode (endianness switch, threading). */ + +#ifndef CAML_FIX_CODE_H +#define CAML_FIX_CODE_H + + +#include "config.h" +#include "misc.h" +#include "mlvalues.h" + +extern code_t caml_start_code; +extern asize_t caml_code_size; +extern unsigned char * caml_saved_code; +extern unsigned char caml_code_md5[16]; + +void caml_load_code (int fd, asize_t len); +void caml_fixup_endianness (code_t code, asize_t len); +void caml_set_instruction (code_t pos, opcode_t instr); +int caml_is_instruction (opcode_t instr1, opcode_t instr2); + +#ifdef THREADED_CODE +extern char ** caml_instr_table; +extern char * caml_instr_base; +void caml_thread_code (code_t code, asize_t len); +#endif + +#endif /* CAML_FIX_CODE_H */ diff --git a/byterun/floats.c b/byterun/floats.c new file mode 100644 index 0000000..572f493 --- /dev/null +++ b/byterun/floats.c @@ -0,0 +1,441 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: floats.c,v 1.50 2008-08-02 11:02:28 xleroy Exp $ */ + +/* The interface of this file is in "mlvalues.h" and "alloc.h" */ + +#include +#include +#include +#include + +#include "alloc.h" +#include "fail.h" +#include "memory.h" +#include "mlvalues.h" +#include "misc.h" +#include "reverse.h" +#include "stacks.h" + +#ifdef ARCH_ALIGN_DOUBLE + +CAMLexport double caml_Double_val(value val) +{ + union { value v[2]; double d; } buffer; + + Assert(sizeof(double) == 2 * sizeof(value)); + buffer.v[0] = Field(val, 0); + buffer.v[1] = Field(val, 1); + return buffer.d; +} + +CAMLexport void caml_Store_double_val(value val, double dbl) +{ + union { value v[2]; double d; } buffer; + + Assert(sizeof(double) == 2 * sizeof(value)); + buffer.d = dbl; + Field(val, 0) = buffer.v[0]; + Field(val, 1) = buffer.v[1]; +} + +#endif + +CAMLexport value caml_copy_double(double d) +{ + value res; + +#define Setup_for_gc +#define Restore_after_gc + Alloc_small(res, Double_wosize, Double_tag); +#undef Setup_for_gc +#undef Restore_after_gc + Store_double_val(res, d); + return res; +} + +CAMLprim value caml_format_float(value fmt, value arg) +{ +#define MAX_DIGITS 350 +/* Max number of decimal digits in a "natural" (not artificially padded) + representation of a float. Can be quite big for %f format. + Max exponent for IEEE format is 308 decimal digits. + Rounded up for good measure. */ + char format_buffer[MAX_DIGITS + 20]; + int prec, i; + char * p; + char * dest; + value res; + + prec = MAX_DIGITS; + for (p = String_val(fmt); *p != 0; p++) { + if (*p >= '0' && *p <= '9') { + i = atoi(p) + MAX_DIGITS; + if (i > prec) prec = i; + break; + } + } + for( ; *p != 0; p++) { + if (*p == '.') { + i = atoi(p+1) + MAX_DIGITS; + if (i > prec) prec = i; + break; + } + } + if (prec < sizeof(format_buffer)) { + dest = format_buffer; + } else { + dest = caml_stat_alloc(prec); + } + sprintf(dest, String_val(fmt), Double_val(arg)); + res = caml_copy_string(dest); + if (dest != format_buffer) { + caml_stat_free(dest); + } + return res; +} + +/*CAMLprim*/ value caml_float_of_substring(value vs, value idx, value l) +{ + char parse_buffer[64]; + char * buf, * src, * dst, * end; + mlsize_t len, lenvs; + double d; + intnat flen = Long_val(l); + intnat fidx = Long_val(idx); + + lenvs = caml_string_length(vs); + len = + fidx >= 0 && fidx < lenvs && flen > 0 && flen <= lenvs - fidx + ? flen : 0; + buf = len < sizeof(parse_buffer) ? parse_buffer : caml_stat_alloc(len + 1); + src = String_val(vs) + fidx; + dst = buf; + while (len--) { + char c = *src++; + if (c != '_') *dst++ = c; + } + *dst = 0; + if (dst == buf) goto error; + d = strtod((const char *) buf, &end); + if (end != dst) goto error; + if (buf != parse_buffer) caml_stat_free(buf); + return caml_copy_double(d); + error: + if (buf != parse_buffer) caml_stat_free(buf); + caml_failwith("float_of_string"); +} + +CAMLprim value caml_float_of_string(value vs) +{ + char parse_buffer[64]; + char * buf, * src, * dst, * end; + mlsize_t len; + double d; + + len = caml_string_length(vs); + buf = len < sizeof(parse_buffer) ? parse_buffer : caml_stat_alloc(len + 1); + src = String_val(vs); + dst = buf; + while (len--) { + char c = *src++; + if (c != '_') *dst++ = c; + } + *dst = 0; + if (dst == buf) goto error; + d = strtod((const char *) buf, &end); + if (end != dst) goto error; + if (buf != parse_buffer) caml_stat_free(buf); + return caml_copy_double(d); + error: + if (buf != parse_buffer) caml_stat_free(buf); + caml_failwith("float_of_string"); +} + +CAMLprim value caml_int_of_float(value f) +{ + return Val_long((intnat) Double_val(f)); +} + +CAMLprim value caml_float_of_int(value n) +{ + return caml_copy_double((double) Long_val(n)); +} + +CAMLprim value caml_neg_float(value f) +{ + return caml_copy_double(- Double_val(f)); +} + +CAMLprim value caml_abs_float(value f) +{ + return caml_copy_double(fabs(Double_val(f))); +} + +CAMLprim value caml_add_float(value f, value g) +{ + return caml_copy_double(Double_val(f) + Double_val(g)); +} + +CAMLprim value caml_sub_float(value f, value g) +{ + return caml_copy_double(Double_val(f) - Double_val(g)); +} + +CAMLprim value caml_mul_float(value f, value g) +{ + return caml_copy_double(Double_val(f) * Double_val(g)); +} + +CAMLprim value caml_div_float(value f, value g) +{ + return caml_copy_double(Double_val(f) / Double_val(g)); +} + +CAMLprim value caml_exp_float(value f) +{ + return caml_copy_double(exp(Double_val(f))); +} + +CAMLprim value caml_floor_float(value f) +{ + return caml_copy_double(floor(Double_val(f))); +} + +CAMLprim value caml_fmod_float(value f1, value f2) +{ + return caml_copy_double(fmod(Double_val(f1), Double_val(f2))); +} + +CAMLprim value caml_frexp_float(value f) +{ + CAMLparam1 (f); + CAMLlocal2 (res, mantissa); + int exponent; + + mantissa = caml_copy_double(frexp (Double_val(f), &exponent)); + res = caml_alloc_tuple(2); + Field(res, 0) = mantissa; + Field(res, 1) = Val_int(exponent); + CAMLreturn (res); +} + +CAMLprim value caml_ldexp_float(value f, value i) +{ + return caml_copy_double(ldexp(Double_val(f), Int_val(i))); +} + +CAMLprim value caml_log_float(value f) +{ + return caml_copy_double(log(Double_val(f))); +} + +CAMLprim value caml_log10_float(value f) +{ + return caml_copy_double(log10(Double_val(f))); +} + +CAMLprim value caml_modf_float(value f) +{ +#if __SC__ + _float_eval frem; /* Problem with Apple's */ +#else + double frem; +#endif + CAMLparam1 (f); + CAMLlocal3 (res, quo, rem); + + quo = caml_copy_double(modf (Double_val(f), &frem)); + rem = caml_copy_double(frem); + res = caml_alloc_tuple(2); + Field(res, 0) = quo; + Field(res, 1) = rem; + CAMLreturn (res); +} + +CAMLprim value caml_sqrt_float(value f) +{ + return caml_copy_double(sqrt(Double_val(f))); +} + +CAMLprim value caml_power_float(value f, value g) +{ + return caml_copy_double(pow(Double_val(f), Double_val(g))); +} + +CAMLprim value caml_sin_float(value f) +{ + return caml_copy_double(sin(Double_val(f))); +} + +CAMLprim value caml_sinh_float(value f) +{ + return caml_copy_double(sinh(Double_val(f))); +} + +CAMLprim value caml_cos_float(value f) +{ + return caml_copy_double(cos(Double_val(f))); +} + +CAMLprim value caml_cosh_float(value f) +{ + return caml_copy_double(cosh(Double_val(f))); +} + +CAMLprim value caml_tan_float(value f) +{ + return caml_copy_double(tan(Double_val(f))); +} + +CAMLprim value caml_tanh_float(value f) +{ + return caml_copy_double(tanh(Double_val(f))); +} + +CAMLprim value caml_asin_float(value f) +{ + return caml_copy_double(asin(Double_val(f))); +} + +CAMLprim value caml_acos_float(value f) +{ + return caml_copy_double(acos(Double_val(f))); +} + +CAMLprim value caml_atan_float(value f) +{ + return caml_copy_double(atan(Double_val(f))); +} + +CAMLprim value caml_atan2_float(value f, value g) +{ + return caml_copy_double(atan2(Double_val(f), Double_val(g))); +} + +CAMLprim value caml_ceil_float(value f) +{ + return caml_copy_double(ceil(Double_val(f))); +} + +CAMLprim value caml_eq_float(value f, value g) +{ + return Val_bool(Double_val(f) == Double_val(g)); +} + +CAMLprim value caml_neq_float(value f, value g) +{ + return Val_bool(Double_val(f) != Double_val(g)); +} + +CAMLprim value caml_le_float(value f, value g) +{ + return Val_bool(Double_val(f) <= Double_val(g)); +} + +CAMLprim value caml_lt_float(value f, value g) +{ + return Val_bool(Double_val(f) < Double_val(g)); +} + +CAMLprim value caml_ge_float(value f, value g) +{ + return Val_bool(Double_val(f) >= Double_val(g)); +} + +CAMLprim value caml_gt_float(value f, value g) +{ + return Val_bool(Double_val(f) > Double_val(g)); +} + +CAMLprim value caml_float_compare(value vf, value vg) +{ + double f = Double_val(vf); + double g = Double_val(vg); + if (f == g) return Val_int(0); + if (f < g) return Val_int(-1); + if (f > g) return Val_int(1); + /* One or both of f and g is NaN. Order according to the + convention NaN = NaN and NaN < x for all other floats x. */ + if (f == f) return Val_int(1); /* f is not NaN, g is NaN */ + if (g == g) return Val_int(-1); /* g is not NaN, f is NaN */ + return Val_int(0); /* both f and g are NaN */ +} + +enum { FP_normal, FP_subnormal, FP_zero, FP_infinite, FP_nan }; + +CAMLprim value caml_classify_float(value vd) +{ + /* Cygwin 1.3 has problems with fpclassify (PR#1293), so don't use it */ +#if defined(fpclassify) && !defined(__CYGWIN32__) && !defined(__MINGW32__) + switch (fpclassify(Double_val(vd))) { + case FP_NAN: + return Val_int(FP_nan); + case FP_INFINITE: + return Val_int(FP_infinite); + case FP_ZERO: + return Val_int(FP_zero); + case FP_SUBNORMAL: + return Val_int(FP_subnormal); + default: /* case FP_NORMAL */ + return Val_int(FP_normal); + } +#else + union { + double d; +#if defined(ARCH_BIG_ENDIAN) || (defined(__arm__) && !defined(__ARM_EABI__)) + struct { uint32 h; uint32 l; } i; +#else + struct { uint32 l; uint32 h; } i; +#endif + } u; + uint32 h, l; + + u.d = Double_val(vd); + h = u.i.h; l = u.i.l; + l = l | (h & 0xFFFFF); + h = h & 0x7FF00000; + if ((h | l) == 0) + return Val_int(FP_zero); + if (h == 0) + return Val_int(FP_subnormal); + if (h == 0x7FF00000) { + if (l == 0) + return Val_int(FP_infinite); + else + return Val_int(FP_nan); + } + return Val_int(FP_normal); +#endif +} + +/* The [caml_init_ieee_float] function should initialize floating-point hardware + so that it behaves as much as possible like the IEEE standard. + In particular, return special numbers like Infinity and NaN instead + of signalling exceptions. Currently, everyone is in IEEE mode + at program startup, except FreeBSD prior to 4.0R. */ + +#ifdef __FreeBSD__ +#include +#if (__FreeBSD_version < 400017) +#include +#endif +#endif + +void caml_init_ieee_floats(void) +{ +#if defined(__FreeBSD__) && (__FreeBSD_version < 400017) + fpsetmask(0); +#endif +} diff --git a/byterun/freelist.c b/byterun/freelist.c new file mode 100644 index 0000000..e7e3546 --- /dev/null +++ b/byterun/freelist.c @@ -0,0 +1,545 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: freelist.c,v 1.21 2008-12-03 18:09:09 doligez Exp $ */ + +#define FREELIST_DEBUG 0 +#if FREELIST_DEBUG +#include +#endif + +#include + +#include "config.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "memory.h" +#include "major_gc.h" +#include "misc.h" +#include "mlvalues.h" + +/* The free-list is kept sorted by increasing addresses. + This makes the merging of adjacent free blocks possible. + (See [caml_fl_merge_block].) +*/ + +typedef struct { + char *next_bp; /* Pointer to the first byte of the next block. */ +} block; + +/* The sentinel can be located anywhere in memory, but it must not be + adjacent to any heap object. */ +static struct { + value filler1; /* Make sure the sentinel is never adjacent to any block. */ + header_t h; + value first_bp; + value filler2; /* Make sure the sentinel is never adjacent to any block. */ +} sentinel = {0, Make_header (0, 0, Caml_blue), 0, 0}; + +#define Fl_head ((char *) (&(sentinel.first_bp))) +static char *fl_prev = Fl_head; /* Current allocation pointer. */ +static char *fl_last = NULL; /* Last block in the list. Only valid + just after [caml_fl_allocate] returns NULL. */ +char *caml_fl_merge = Fl_head; /* Current insertion pointer. Managed + jointly with [sweep_slice]. */ +asize_t caml_fl_cur_size = 0; /* Number of words in the free list, + including headers but not fragments. */ + +#define FLP_MAX 1000 +static char *flp [FLP_MAX]; +static int flp_size = 0; +static char *beyond = NULL; + +#define Next(b) (((block *) (b))->next_bp) + +#define Policy_next_fit 0 +#define Policy_first_fit 1 +uintnat caml_allocation_policy = Policy_next_fit; +#define policy caml_allocation_policy + +#ifdef DEBUG +static void fl_check (void) +{ + char *cur, *prev; + int prev_found = 0, flp_found = 0, merge_found = 0; + uintnat size_found = 0; + int sz = 0; + + prev = Fl_head; + cur = Next (prev); + while (cur != NULL){ + size_found += Whsize_bp (cur); + Assert (Is_in_heap (cur)); + if (cur == fl_prev) prev_found = 1; + if (policy == Policy_first_fit && Wosize_bp (cur) > sz){ + sz = Wosize_bp (cur); + if (flp_found < flp_size){ + Assert (Next (flp[flp_found]) == cur); + ++ flp_found; + }else{ + Assert (beyond == NULL || cur >= Next (beyond)); + } + } + if (cur == caml_fl_merge) merge_found = 1; + prev = cur; + cur = Next (prev); + } + if (policy == Policy_next_fit) Assert (prev_found || fl_prev == Fl_head); + if (policy == Policy_first_fit) Assert (flp_found == flp_size); + Assert (merge_found || caml_fl_merge == Fl_head); + Assert (size_found == caml_fl_cur_size); +} + +#endif + +/* [allocate_block] is called by [caml_fl_allocate]. Given a suitable free + block and the desired size, it allocates a new block from the free + block. There are three cases: + 0. The free block has the desired size. Detach the block from the + free-list and return it. + 1. The free block is 1 word longer than the desired size. Detach + the block from the free list. The remaining word cannot be linked: + turn it into an empty block (header only), and return the rest. + 2. The free block is big enough. Split it in two and return the right + block. + In all cases, the allocated block is right-justified in the free block: + it is located in the high-address words of the free block. This way, + the linking of the free-list does not change in case 2. +*/ +static char *allocate_block (mlsize_t wh_sz, int flpi, char *prev, char *cur) +{ + header_t h = Hd_bp (cur); + Assert (Whsize_hd (h) >= wh_sz); + if (Wosize_hd (h) < wh_sz + 1){ /* Cases 0 and 1. */ + caml_fl_cur_size -= Whsize_hd (h); + Next (prev) = Next (cur); + Assert (Is_in_heap (Next (prev)) || Next (prev) == NULL); + if (caml_fl_merge == cur) caml_fl_merge = prev; +#ifdef DEBUG + fl_last = NULL; +#endif + /* In case 1, the following creates the empty block correctly. + In case 0, it gives an invalid header to the block. The function + calling [caml_fl_allocate] will overwrite it. */ + Hd_op (cur) = Make_header (0, 0, Caml_white); + if (policy == Policy_first_fit){ + if (flpi + 1 < flp_size && flp[flpi + 1] == cur){ + flp[flpi + 1] = prev; + }else if (flpi == flp_size - 1){ + beyond = (prev == Fl_head) ? NULL : prev; + -- flp_size; + } + } + }else{ /* Case 2. */ + caml_fl_cur_size -= wh_sz; + Hd_op (cur) = Make_header (Wosize_hd (h) - wh_sz, 0, Caml_blue); + } + if (policy == Policy_next_fit) fl_prev = prev; + return cur + Bosize_hd (h) - Bsize_wsize (wh_sz); +} + +/* [caml_fl_allocate] does not set the header of the newly allocated block. + The calling function must do it before any GC function gets called. + [caml_fl_allocate] returns a head pointer. +*/ +char *caml_fl_allocate (mlsize_t wo_sz) +{ + char *cur = NULL, *prev, *result; + int i; + mlsize_t sz, prevsz; + Assert (sizeof (char *) == sizeof (value)); + Assert (wo_sz >= 1); + switch (policy){ + case Policy_next_fit: + Assert (fl_prev != NULL); + /* Search from [fl_prev] to the end of the list. */ + prev = fl_prev; + cur = Next (prev); + while (cur != NULL){ Assert (Is_in_heap (cur)); + if (Wosize_bp (cur) >= wo_sz){ + return allocate_block (Whsize_wosize (wo_sz), 0, prev, cur); + } + prev = cur; + cur = Next (prev); + } + fl_last = prev; + /* Search from the start of the list to [fl_prev]. */ + prev = Fl_head; + cur = Next (prev); + while (prev != fl_prev){ + if (Wosize_bp (cur) >= wo_sz){ + return allocate_block (Whsize_wosize (wo_sz), 0, prev, cur); + } + prev = cur; + cur = Next (prev); + } + /* No suitable block was found. */ + return NULL; + break; + + case Policy_first_fit: { + /* Search in the flp array. */ + for (i = 0; i < flp_size; i++){ + sz = Wosize_bp (Next (flp[i])); + if (sz >= wo_sz){ +#if FREELIST_DEBUG + if (i > 5) fprintf (stderr, "FLP: found at %d size=%d\n", i, wo_sz); +#endif + result = allocate_block (Whsize_wosize (wo_sz), i, flp[i], Next(flp[i])); + goto update_flp; + } + } + /* Extend the flp array. */ + if (flp_size == 0){ + prev = Fl_head; + prevsz = 0; + }else{ + prev = Next (flp[flp_size - 1]); + prevsz = Wosize_bp (prev); + if (beyond != NULL) prev = beyond; + } + while (flp_size < FLP_MAX){ + cur = Next (prev); + if (cur == NULL){ + fl_last = prev; + beyond = (prev == Fl_head) ? NULL : prev; + return NULL; + }else{ + sz = Wosize_bp (cur); + if (sz > prevsz){ + flp[flp_size] = prev; + ++ flp_size; + if (sz >= wo_sz){ + beyond = cur; + i = flp_size - 1; +#if FREELIST_DEBUG + if (flp_size > 5){ + fprintf (stderr, "FLP: extended to %d\n", flp_size); + } +#endif + result = allocate_block (Whsize_wosize (wo_sz), flp_size - 1, prev, + cur); + goto update_flp; + } + prevsz = sz; + } + } + prev = cur; + } + beyond = cur; + + /* The flp table is full. Do a slow first-fit search. */ +#if FREELIST_DEBUG + fprintf (stderr, "FLP: table is full -- slow first-fit\n"); +#endif + if (beyond != NULL){ + prev = beyond; + }else{ + prev = flp[flp_size - 1]; + } + prevsz = Wosize_bp (Next (flp[FLP_MAX-1])); + Assert (prevsz < wo_sz); + cur = Next (prev); + while (cur != NULL){ + Assert (Is_in_heap (cur)); + sz = Wosize_bp (cur); + if (sz < prevsz){ + beyond = cur; + }else if (sz >= wo_sz){ + return allocate_block (Whsize_wosize (wo_sz), flp_size, prev, cur); + } + prev = cur; + cur = Next (prev); + } + fl_last = prev; + return NULL; + + update_flp: /* (i, sz) */ + /* The block at [i] was removed or reduced. Update the table. */ + Assert (0 <= i && i < flp_size + 1); + if (i < flp_size){ + if (i > 0){ + prevsz = Wosize_bp (Next (flp[i-1])); + }else{ + prevsz = 0; + } + if (i == flp_size - 1){ + if (Wosize_bp (Next (flp[i])) <= prevsz){ + beyond = Next (flp[i]); + -- flp_size; + }else{ + beyond = NULL; + } + }else{ + char *buf [FLP_MAX]; + int j = 0; + mlsize_t oldsz = sz; + + prev = flp[i]; + while (prev != flp[i+1]){ + cur = Next (prev); + sz = Wosize_bp (cur); + if (sz > prevsz){ + buf[j++] = prev; + prevsz = sz; + if (sz >= oldsz){ + Assert (sz == oldsz); + break; + } + } + prev = cur; + } +#if FREELIST_DEBUG + if (j > 2) fprintf (stderr, "FLP: update; buf size = %d\n", j); +#endif + if (FLP_MAX >= flp_size + j - 1){ + if (j != 1){ + memmove (&flp[i+j], &flp[i+1], sizeof (block *) * (flp_size-i-1)); + } + if (j > 0) memmove (&flp[i], &buf[0], sizeof (block *) * j); + flp_size += j - 1; + }else{ + if (FLP_MAX > i + j){ + if (j != 1){ + memmove (&flp[i+j], &flp[i+1], sizeof (block *) * (FLP_MAX-i-j)); + } + if (j > 0) memmove (&flp[i], &buf[0], sizeof (block *) * j); + }else{ + if (i != FLP_MAX){ + memmove (&flp[i], &buf[0], sizeof (block *) * (FLP_MAX - i)); + } + } + flp_size = FLP_MAX - 1; + beyond = Next (flp[FLP_MAX - 1]); + } + } + } + return result; + } + break; + + default: + Assert (0); /* unknown policy */ + break; + } + return NULL; /* NOT REACHED */ +} + +static char *last_fragment; + +void caml_fl_init_merge (void) +{ + last_fragment = NULL; + caml_fl_merge = Fl_head; +#ifdef DEBUG + fl_check (); +#endif +} + +static void truncate_flp (char *changed) +{ + if (changed == Fl_head){ + flp_size = 0; + beyond = NULL; + }else{ + while (flp_size > 0 && Next (flp[flp_size - 1]) >= changed) -- flp_size; + if (beyond >= changed) beyond = NULL; + } +} + +/* This is called by caml_compact_heap. */ +void caml_fl_reset (void) +{ + Next (Fl_head) = NULL; + switch (policy){ + case Policy_next_fit: + fl_prev = Fl_head; + break; + case Policy_first_fit: + truncate_flp (Fl_head); + break; + default: + Assert (0); + break; + } + caml_fl_cur_size = 0; + caml_fl_init_merge (); +} + +/* [caml_fl_merge_block] returns the head pointer of the next block after [bp], + because merging blocks may change the size of [bp]. */ +char *caml_fl_merge_block (char *bp) +{ + char *prev, *cur, *adj; + header_t hd = Hd_bp (bp); + mlsize_t prev_wosz; + + caml_fl_cur_size += Whsize_hd (hd); + +#ifdef DEBUG + caml_set_fields (bp, 0, Debug_free_major); +#endif + prev = caml_fl_merge; + cur = Next (prev); + /* The sweep code makes sure that this is the right place to insert + this block: */ + Assert (prev < bp || prev == Fl_head); + Assert (cur > bp || cur == NULL); + + if (policy == Policy_first_fit) truncate_flp (prev); + + /* If [last_fragment] and [bp] are adjacent, merge them. */ + if (last_fragment == Hp_bp (bp)){ + mlsize_t bp_whsz = Whsize_bp (bp); + if (bp_whsz <= Max_wosize){ + hd = Make_header (bp_whsz, 0, Caml_white); + bp = last_fragment; + Hd_bp (bp) = hd; + caml_fl_cur_size += Whsize_wosize (0); + } + } + + /* If [bp] and [cur] are adjacent, remove [cur] from the free-list + and merge them. */ + adj = bp + Bosize_hd (hd); + if (adj == Hp_bp (cur)){ + char *next_cur = Next (cur); + mlsize_t cur_whsz = Whsize_bp (cur); + + if (Wosize_hd (hd) + cur_whsz <= Max_wosize){ + Next (prev) = next_cur; + if (policy == Policy_next_fit && fl_prev == cur) fl_prev = prev; + hd = Make_header (Wosize_hd (hd) + cur_whsz, 0, Caml_blue); + Hd_bp (bp) = hd; + adj = bp + Bosize_hd (hd); +#ifdef DEBUG + fl_last = NULL; + Next (cur) = (char *) Debug_free_major; + Hd_bp (cur) = Debug_free_major; +#endif + cur = next_cur; + } + } + /* If [prev] and [bp] are adjacent merge them, else insert [bp] into + the free-list if it is big enough. */ + prev_wosz = Wosize_bp (prev); + if (prev + Bsize_wsize (prev_wosz) == Hp_bp (bp) + && prev_wosz + Whsize_hd (hd) < Max_wosize){ + Hd_bp (prev) = Make_header (prev_wosz + Whsize_hd (hd), 0,Caml_blue); +#ifdef DEBUG + Hd_bp (bp) = Debug_free_major; +#endif + Assert (caml_fl_merge == prev); + }else if (Wosize_hd (hd) != 0){ + Hd_bp (bp) = Bluehd_hd (hd); + Next (bp) = cur; + Next (prev) = bp; + caml_fl_merge = bp; + }else{ + /* This is a fragment. Leave it in white but remember it for eventual + merging with the next block. */ + last_fragment = bp; + caml_fl_cur_size -= Whsize_wosize (0); + } + return adj; +} + +/* This is a heap extension. We have to insert it in the right place + in the free-list. + [caml_fl_add_blocks] can only be called right after a call to + [caml_fl_allocate] that returned NULL. + Most of the heap extensions are expected to be at the end of the + free list. (This depends on the implementation of [malloc].) + + [bp] must point to a list of blocks chained by their field 0, + terminated by NULL, and field 1 of the first block must point to + the last block. +*/ +void caml_fl_add_blocks (char *bp) +{ + Assert (fl_last != NULL); + Assert (Next (fl_last) == NULL); + caml_fl_cur_size += Whsize_bp (bp); + + if (bp > fl_last){ + Next (fl_last) = bp; + if (fl_last == caml_fl_merge && bp < caml_gc_sweep_hp){ + caml_fl_merge = (char *) Field (bp, 1); + } + if (policy == Policy_first_fit && flp_size < FLP_MAX){ + flp [flp_size++] = fl_last; + } + }else{ + char *cur, *prev; + + prev = Fl_head; + cur = Next (prev); + while (cur != NULL && cur < bp){ Assert (prev < bp || prev == Fl_head); + /* XXX TODO: extend flp on the fly */ + prev = cur; + cur = Next (prev); + } Assert (prev < bp || prev == Fl_head); + Assert (cur > bp || cur == NULL); + Next (Field (bp, 1)) = cur; + Next (prev) = bp; + /* When inserting blocks between [caml_fl_merge] and [caml_gc_sweep_hp], + we must advance [caml_fl_merge] to the new block, so that [caml_fl_merge] + is always the last free-list block before [caml_gc_sweep_hp]. */ + if (prev == caml_fl_merge && bp < caml_gc_sweep_hp){ + caml_fl_merge = (char *) Field (bp, 1); + } + if (policy == Policy_first_fit) truncate_flp (bp); + } +} + +/* Cut a block of memory into Max_wosize pieces, give them headers, + and optionally merge them into the free list. + arguments: + p: pointer to the first word of the block + size: size of the block (in words) + do_merge: 1 -> do merge; 0 -> do not merge +*/ +void caml_make_free_blocks (value *p, mlsize_t size, int do_merge) +{ + mlsize_t sz; + + while (size > 0){ + if (size > Whsize_wosize (Max_wosize)){ + sz = Whsize_wosize (Max_wosize); + }else{ + sz = size; + } + *(header_t *)p = Make_header (Wosize_whsize (sz), 0, Caml_white); + if (do_merge) caml_fl_merge_block (Bp_hp (p)); + size -= sz; + p += sz; + } +} + +void caml_set_allocation_policy (uintnat p) +{ + switch (p){ + case Policy_next_fit: + fl_prev = Fl_head; + break; + case Policy_first_fit: + flp_size = 0; + beyond = NULL; + break; + default: + Assert (0); + break; + } + policy = p; +} diff --git a/byterun/freelist.h b/byterun/freelist.h new file mode 100644 index 0000000..f52b1a0 --- /dev/null +++ b/byterun/freelist.h @@ -0,0 +1,36 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: freelist.h,v 1.14 2008-12-03 18:09:09 doligez Exp $ */ + +/* Free lists of heap blocks. */ + +#ifndef CAML_FREELIST_H +#define CAML_FREELIST_H + + +#include "misc.h" +#include "mlvalues.h" + +extern asize_t caml_fl_cur_size; /* size in words */ + +char *caml_fl_allocate (mlsize_t); +void caml_fl_init_merge (void); +void caml_fl_reset (void); +char *caml_fl_merge_block (char *); +void caml_fl_add_blocks (char *); +void caml_make_free_blocks (value *, mlsize_t, int); +void caml_set_allocation_policy (uintnat); + + +#endif /* CAML_FREELIST_H */ diff --git a/byterun/gc.h b/byterun/gc.h new file mode 100644 index 0000000..99af14c --- /dev/null +++ b/byterun/gc.h @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gc.h,v 1.15 2004-07-19 13:20:06 xleroy Exp $ */ + +#ifndef CAML_GC_H +#define CAML_GC_H + + +#include "mlvalues.h" + +#define Caml_white (0 << 8) +#define Caml_gray (1 << 8) +#define Caml_blue (2 << 8) +#define Caml_black (3 << 8) + +#define Color_hd(hd) ((color_t) ((hd) & Caml_black)) +#define Color_hp(hp) (Color_hd (Hd_hp (hp))) +#define Color_val(val) (Color_hd (Hd_val (val))) + +#define Is_white_hd(hd) (Color_hd (hd) == Caml_white) +#define Is_gray_hd(hd) (Color_hd (hd) == Caml_gray) +#define Is_blue_hd(hd) (Color_hd (hd) == Caml_blue) +#define Is_black_hd(hd) (Color_hd (hd) == Caml_black) + +#define Whitehd_hd(hd) (((hd) & ~Caml_black)/*| Caml_white*/) +#define Grayhd_hd(hd) (((hd) & ~Caml_black) | Caml_gray) +#define Blackhd_hd(hd) (((hd)/*& ~Caml_black*/)| Caml_black) +#define Bluehd_hd(hd) (((hd) & ~Caml_black) | Caml_blue) + +/* This depends on the layout of the header. See [mlvalues.h]. */ +#define Make_header(wosize, tag, color) \ + (/*Assert ((wosize) <= Max_wosize),*/ \ + ((header_t) (((header_t) (wosize) << 10) \ + + (color) \ + + (tag_t) (tag))) \ + ) + +#define Is_white_val(val) (Color_val(val) == Caml_white) +#define Is_gray_val(val) (Color_val(val) == Caml_gray) +#define Is_blue_val(val) (Color_val(val) == Caml_blue) +#define Is_black_val(val) (Color_val(val) == Caml_black) + +/* For extern.c */ +#define Colornum_hd(hd) ((color_t) (((hd) >> 8) & 3)) +#define Coloredhd_hd(hd,colnum) (((hd) & ~Caml_black) | ((colnum) << 8)) + +#endif /* CAML_GC_H */ diff --git a/byterun/gc_ctrl.c b/byterun/gc_ctrl.c new file mode 100644 index 0000000..c5d34ac --- /dev/null +++ b/byterun/gc_ctrl.c @@ -0,0 +1,494 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gc_ctrl.c,v 1.54 2008-12-03 18:09:09 doligez Exp $ */ + +#include "alloc.h" +#include "compact.h" +#include "custom.h" +#include "finalise.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "major_gc.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "stacks.h" + +#ifndef NATIVE_CODE +extern uintnat caml_max_stack_size; /* defined in stacks.c */ +#endif + +double caml_stat_minor_words = 0.0, + caml_stat_promoted_words = 0.0, + caml_stat_major_words = 0.0; + +intnat caml_stat_minor_collections = 0, + caml_stat_major_collections = 0, + caml_stat_heap_size = 0, /* bytes */ + caml_stat_top_heap_size = 0, /* bytes */ + caml_stat_compactions = 0, + caml_stat_heap_chunks = 0; + +extern asize_t caml_major_heap_increment; /* bytes; see major_gc.c */ +extern uintnat caml_percent_free; /* see major_gc.c */ +extern uintnat caml_percent_max; /* see compact.c */ +extern uintnat caml_allocation_policy; /* see freelist.c */ + +#define Next(hp) ((hp) + Bhsize_hp (hp)) + +#ifdef DEBUG + +/* Check that [v]'s header looks good. [v] must be a block in the heap. */ +static void check_head (value v) +{ + Assert (Is_block (v)); + Assert (Is_in_heap (v)); + + Assert (Wosize_val (v) != 0); + Assert (Color_hd (Hd_val (v)) != Caml_blue); + Assert (Is_in_heap (v)); + if (Tag_val (v) == Infix_tag){ + int offset = Wsize_bsize (Infix_offset_val (v)); + value trueval = Val_op (&Field (v, -offset)); + Assert (Tag_val (trueval) == Closure_tag); + Assert (Wosize_val (trueval) > offset); + Assert (Is_in_heap (&Field (trueval, Wosize_val (trueval) - 1))); + }else{ + Assert (Is_in_heap (&Field (v, Wosize_val (v) - 1))); + } + if (Tag_val (v) == Double_tag){ + Assert (Wosize_val (v) == Double_wosize); + }else if (Tag_val (v) == Double_array_tag){ + Assert (Wosize_val (v) % Double_wosize == 0); + } +} + +static void check_block (char *hp) +{ + mlsize_t i; + value v = Val_hp (hp); + value f; + + check_head (v); + switch (Tag_hp (hp)){ + case Abstract_tag: break; + case String_tag: + break; + case Double_tag: + Assert (Wosize_val (v) == Double_wosize); + break; + case Double_array_tag: + Assert (Wosize_val (v) % Double_wosize == 0); + break; + case Custom_tag: + Assert (!Is_in_heap (Custom_ops_val (v))); + break; + + case Infix_tag: + Assert (0); + break; + + default: + Assert (Tag_hp (hp) < No_scan_tag); + for (i = 0; i < Wosize_hp (hp); i++){ + f = Field (v, i); + if (Is_block (f) && Is_in_heap (f)){ + check_head (f); + Assert (Color_val (f) != Caml_blue); + } + } + } +} + +#endif /* DEBUG */ + +/* Check the heap structure (if compiled in debug mode) and + gather statistics; return the stats if [returnstats] is true, + otherwise return [Val_unit]. +*/ +static value heap_stats (int returnstats) +{ + CAMLparam0 (); + intnat live_words = 0, live_blocks = 0, + free_words = 0, free_blocks = 0, largest_free = 0, + fragments = 0, heap_chunks = 0; + char *chunk = caml_heap_start, *chunk_end; + char *cur_hp, *prev_hp; + header_t cur_hd; + +#ifdef DEBUG + caml_gc_message (-1, "### O'Caml runtime: heap check ###\n", 0); +#endif + + while (chunk != NULL){ + ++ heap_chunks; + chunk_end = chunk + Chunk_size (chunk); + prev_hp = NULL; + cur_hp = chunk; + while (cur_hp < chunk_end){ + cur_hd = Hd_hp (cur_hp); + Assert (Next (cur_hp) <= chunk_end); + switch (Color_hd (cur_hd)){ + case Caml_white: + if (Wosize_hd (cur_hd) == 0){ + ++ fragments; + Assert (prev_hp == NULL + || Color_hp (prev_hp) != Caml_blue + || cur_hp == caml_gc_sweep_hp); + }else{ + if (caml_gc_phase == Phase_sweep && cur_hp >= caml_gc_sweep_hp){ + ++ free_blocks; + free_words += Whsize_hd (cur_hd); + if (Whsize_hd (cur_hd) > largest_free){ + largest_free = Whsize_hd (cur_hd); + } + }else{ + ++ live_blocks; + live_words += Whsize_hd (cur_hd); +#ifdef DEBUG + check_block (cur_hp); +#endif + } + } + break; + case Caml_gray: case Caml_black: + Assert (Wosize_hd (cur_hd) > 0); + ++ live_blocks; + live_words += Whsize_hd (cur_hd); +#ifdef DEBUG + check_block (cur_hp); +#endif + break; + case Caml_blue: + Assert (Wosize_hd (cur_hd) > 0); + ++ free_blocks; + free_words += Whsize_hd (cur_hd); + if (Whsize_hd (cur_hd) > largest_free){ + largest_free = Whsize_hd (cur_hd); + } + /* not true any more with big heap chunks + Assert (prev_hp == NULL + || (Color_hp (prev_hp) != Caml_blue && Wosize_hp (prev_hp) > 0) + || cur_hp == caml_gc_sweep_hp); + Assert (Next (cur_hp) == chunk_end + || (Color_hp (Next (cur_hp)) != Caml_blue + && Wosize_hp (Next (cur_hp)) > 0) + || (Whsize_hd (cur_hd) + Wosize_hp (Next (cur_hp)) > Max_wosize) + || Next (cur_hp) == caml_gc_sweep_hp); + */ + break; + } + prev_hp = cur_hp; + cur_hp = Next (cur_hp); + } Assert (cur_hp == chunk_end); + chunk = Chunk_next (chunk); + } + + Assert (heap_chunks == caml_stat_heap_chunks); + Assert (live_words + free_words + fragments + == Wsize_bsize (caml_stat_heap_size)); + + if (returnstats){ + CAMLlocal1 (res); + + /* get a copy of these before allocating anything... */ + double minwords = caml_stat_minor_words + + (double) Wsize_bsize (caml_young_end - caml_young_ptr); + double prowords = caml_stat_promoted_words; + double majwords = caml_stat_major_words + (double) caml_allocated_words; + intnat mincoll = caml_stat_minor_collections; + intnat majcoll = caml_stat_major_collections; + intnat heap_words = Wsize_bsize (caml_stat_heap_size); + intnat cpct = caml_stat_compactions; + intnat top_heap_words = Wsize_bsize (caml_stat_top_heap_size); + + res = caml_alloc_tuple (15); + Store_field (res, 0, caml_copy_double (minwords)); + Store_field (res, 1, caml_copy_double (prowords)); + Store_field (res, 2, caml_copy_double (majwords)); + Store_field (res, 3, Val_long (mincoll)); + Store_field (res, 4, Val_long (majcoll)); + Store_field (res, 5, Val_long (heap_words)); + Store_field (res, 6, Val_long (heap_chunks)); + Store_field (res, 7, Val_long (live_words)); + Store_field (res, 8, Val_long (live_blocks)); + Store_field (res, 9, Val_long (free_words)); + Store_field (res, 10, Val_long (free_blocks)); + Store_field (res, 11, Val_long (largest_free)); + Store_field (res, 12, Val_long (fragments)); + Store_field (res, 13, Val_long (cpct)); + Store_field (res, 14, Val_long (top_heap_words)); + CAMLreturn (res); + }else{ + CAMLreturn (Val_unit); + } +} + +#ifdef DEBUG +void caml_heap_check (void) +{ + heap_stats (0); +} +#endif + +CAMLprim value caml_gc_stat(value v) +{ + Assert (v == Val_unit); + return heap_stats (1); +} + +CAMLprim value caml_gc_quick_stat(value v) +{ + CAMLparam0 (); + CAMLlocal1 (res); + + /* get a copy of these before allocating anything... */ + double minwords = caml_stat_minor_words + + (double) Wsize_bsize (caml_young_end - caml_young_ptr); + double prowords = caml_stat_promoted_words; + double majwords = caml_stat_major_words + (double) caml_allocated_words; + intnat mincoll = caml_stat_minor_collections; + intnat majcoll = caml_stat_major_collections; + intnat heap_words = caml_stat_heap_size / sizeof (value); + intnat top_heap_words = caml_stat_top_heap_size / sizeof (value); + intnat cpct = caml_stat_compactions; + intnat heap_chunks = caml_stat_heap_chunks; + + res = caml_alloc_tuple (15); + Store_field (res, 0, caml_copy_double (minwords)); + Store_field (res, 1, caml_copy_double (prowords)); + Store_field (res, 2, caml_copy_double (majwords)); + Store_field (res, 3, Val_long (mincoll)); + Store_field (res, 4, Val_long (majcoll)); + Store_field (res, 5, Val_long (heap_words)); + Store_field (res, 6, Val_long (heap_chunks)); + Store_field (res, 7, Val_long (0)); + Store_field (res, 8, Val_long (0)); + Store_field (res, 9, Val_long (0)); + Store_field (res, 10, Val_long (0)); + Store_field (res, 11, Val_long (0)); + Store_field (res, 12, Val_long (0)); + Store_field (res, 13, Val_long (cpct)); + Store_field (res, 14, Val_long (top_heap_words)); + CAMLreturn (res); +} + +CAMLprim value caml_gc_counters(value v) +{ + CAMLparam0 (); /* v is ignored */ + CAMLlocal1 (res); + + /* get a copy of these before allocating anything... */ + double minwords = caml_stat_minor_words + + (double) Wsize_bsize (caml_young_end - caml_young_ptr); + double prowords = caml_stat_promoted_words; + double majwords = caml_stat_major_words + (double) caml_allocated_words; + + res = caml_alloc_tuple (3); + Store_field (res, 0, caml_copy_double (minwords)); + Store_field (res, 1, caml_copy_double (prowords)); + Store_field (res, 2, caml_copy_double (majwords)); + CAMLreturn (res); +} + +CAMLprim value caml_gc_get(value v) +{ + CAMLparam0 (); /* v is ignored */ + CAMLlocal1 (res); + + res = caml_alloc_tuple (7); + Store_field (res, 0, Val_long (Wsize_bsize (caml_minor_heap_size))); /* s */ + Store_field (res, 1,Val_long(Wsize_bsize(caml_major_heap_increment)));/* i */ + Store_field (res, 2, Val_long (caml_percent_free)); /* o */ + Store_field (res, 3, Val_long (caml_verb_gc)); /* v */ + Store_field (res, 4, Val_long (caml_percent_max)); /* O */ +#ifndef NATIVE_CODE + Store_field (res, 5, Val_long (caml_max_stack_size)); /* l */ +#else + Store_field (res, 5, Val_long (0)); +#endif + Store_field (res, 6, Val_long (caml_allocation_policy)); /* a */ + CAMLreturn (res); +} + +#define Max(x,y) ((x) < (y) ? (y) : (x)) + +static uintnat norm_pfree (uintnat p) +{ + return Max (p, 1); +} + +static uintnat norm_pmax (uintnat p) +{ + return p; +} + +static intnat norm_heapincr (uintnat i) +{ +#define Psv (Wsize_bsize (Page_size)) + i = ((i + Psv - 1) / Psv) * Psv; + if (i < Heap_chunk_min) i = Heap_chunk_min; + return i; +} + +static intnat norm_minsize (intnat s) +{ + if (s < Minor_heap_min) s = Minor_heap_min; + if (s > Minor_heap_max) s = Minor_heap_max; + return s; +} + +static intnat norm_policy (intnat p) +{ + if (p >= 0 && p <= 1){ + return p; + }else{ + return 1; + } +} + +CAMLprim value caml_gc_set(value v) +{ + uintnat newpf, newpm; + asize_t newheapincr; + asize_t newminsize; + uintnat newpolicy; + + caml_verb_gc = Long_val (Field (v, 3)); + +#ifndef NATIVE_CODE + caml_change_max_stack_size (Long_val (Field (v, 5))); +#endif + + newpf = norm_pfree (Long_val (Field (v, 2))); + if (newpf != caml_percent_free){ + caml_percent_free = newpf; + caml_gc_message (0x20, "New space overhead: %d%%\n", caml_percent_free); + } + + newpm = norm_pmax (Long_val (Field (v, 4))); + if (newpm != caml_percent_max){ + caml_percent_max = newpm; + caml_gc_message (0x20, "New max overhead: %d%%\n", caml_percent_max); + } + + newheapincr = Bsize_wsize (norm_heapincr (Long_val (Field (v, 1)))); + if (newheapincr != caml_major_heap_increment){ + caml_major_heap_increment = newheapincr; + caml_gc_message (0x20, "New heap increment size: %luk bytes\n", + caml_major_heap_increment/1024); + } + newpolicy = norm_policy (Long_val (Field (v, 6))); + if (newpolicy != caml_allocation_policy){ + caml_gc_message (0x20, "New allocation policy: %d\n", newpolicy); + caml_set_allocation_policy (newpolicy); + } + + /* Minor heap size comes last because it will trigger a minor collection + (thus invalidating [v]) and it can raise [Out_of_memory]. */ + newminsize = norm_minsize (Bsize_wsize (Long_val (Field (v, 0)))); + if (newminsize != caml_minor_heap_size){ + caml_gc_message (0x20, "New minor heap size: %luk bytes\n", + newminsize/1024); + caml_set_minor_heap_size (newminsize); + } + return Val_unit; +} + +CAMLprim value caml_gc_minor(value v) +{ Assert (v == Val_unit); + caml_minor_collection (); + return Val_unit; +} + +static void test_and_compact (void) +{ + float fp; + + fp = 100.0 * caml_fl_cur_size + / (Wsize_bsize (caml_stat_heap_size) - caml_fl_cur_size); + if (fp > 1000000.0) fp = 1000000.0; + caml_gc_message (0x200, "Estimated overhead (lower bound) = %" + ARCH_INTNAT_PRINTF_FORMAT "u%%\n", + (uintnat) fp); + if (fp >= caml_percent_max && caml_stat_heap_chunks > 1){ + caml_gc_message (0x200, "Automatic compaction triggered.\n", 0); + caml_compact_heap (); + } +} + +CAMLprim value caml_gc_major(value v) +{ Assert (v == Val_unit); + caml_gc_message (0x1, "Major GC cycle requested\n", 0); + caml_empty_minor_heap (); + caml_finish_major_cycle (); + test_and_compact (); + caml_final_do_calls (); + return Val_unit; +} + +CAMLprim value caml_gc_full_major(value v) +{ Assert (v == Val_unit); + caml_gc_message (0x1, "Full major GC cycle requested\n", 0); + caml_empty_minor_heap (); + caml_finish_major_cycle (); + caml_final_do_calls (); + caml_empty_minor_heap (); + caml_finish_major_cycle (); + test_and_compact (); + caml_final_do_calls (); + return Val_unit; +} + +CAMLprim value caml_gc_major_slice (value v) +{ + Assert (Is_long (v)); + caml_empty_minor_heap (); + return Val_long (caml_major_collection_slice (Long_val (v))); +} + +CAMLprim value caml_gc_compaction(value v) +{ Assert (v == Val_unit); + caml_empty_minor_heap (); + caml_finish_major_cycle (); + caml_finish_major_cycle (); + caml_compact_heap (); + caml_final_do_calls (); + return Val_unit; +} + +void caml_init_gc (uintnat minor_size, uintnat major_size, + uintnat major_incr, uintnat percent_fr, + uintnat percent_m) +{ + uintnat major_heap_size = Bsize_wsize (norm_heapincr (major_size)); + + caml_page_table_initialize(Bsize_wsize(minor_size) + major_heap_size); + caml_set_minor_heap_size (Bsize_wsize (norm_minsize (minor_size))); + caml_major_heap_increment = Bsize_wsize (norm_heapincr (major_incr)); + caml_percent_free = norm_pfree (percent_fr); + caml_percent_max = norm_pmax (percent_m); + caml_init_major_heap (major_heap_size); + caml_gc_message (0x20, "Initial minor heap size: %luk bytes\n", + caml_minor_heap_size / 1024); + caml_gc_message (0x20, "Initial major heap size: %luk bytes\n", + major_heap_size / 1024); + caml_gc_message (0x20, "Initial space overhead: %lu%%\n", caml_percent_free); + caml_gc_message (0x20, "Initial max overhead: %lu%%\n", caml_percent_max); + caml_gc_message (0x20, "Initial heap increment: %luk bytes\n", + caml_major_heap_increment / 1024); + caml_gc_message (0x20, "Initial allocation policy: %d\n", + caml_allocation_policy); +} diff --git a/byterun/gc_ctrl.h b/byterun/gc_ctrl.h new file mode 100644 index 0000000..062e920 --- /dev/null +++ b/byterun/gc_ctrl.h @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gc_ctrl.h,v 1.16 2005-09-22 14:21:50 xleroy Exp $ */ + +#ifndef CAML_GC_CTRL_H +#define CAML_GC_CTRL_H + +#include "misc.h" + +extern double + caml_stat_minor_words, + caml_stat_promoted_words, + caml_stat_major_words; + +extern intnat + caml_stat_minor_collections, + caml_stat_major_collections, + caml_stat_heap_size, + caml_stat_top_heap_size, + caml_stat_compactions, + caml_stat_heap_chunks; + +void caml_init_gc (uintnat, uintnat, uintnat, + uintnat, uintnat); + + +#ifdef DEBUG +void caml_heap_check (void); +#endif + +#endif /* CAML_GC_CTRL_H */ diff --git a/byterun/globroots.c b/byterun/globroots.c new file mode 100644 index 0000000..a9dddb9 --- /dev/null +++ b/byterun/globroots.c @@ -0,0 +1,261 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: globroots.c,v 1.11 2008-07-14 06:28:27 xleroy Exp $ */ + +/* Registration of global memory roots */ + +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "roots.h" +#include "globroots.h" + +/* The sets of global memory roots are represented as skip lists + (see William Pugh, "Skip lists: a probabilistic alternative to + balanced binary trees", Comm. ACM 33(6), 1990). */ + +struct global_root { + value * root; /* the address of the root */ + struct global_root * forward[1]; /* variable-length array */ +}; + +#define NUM_LEVELS 17 + +struct global_root_list { + value * root; /* dummy value for layout compatibility */ + struct global_root * forward[NUM_LEVELS]; /* forward chaining */ + int level; /* max used level */ +}; + +/* Generate a random level for a new node: 0 with probability 3/4, + 1 with probability 3/16, 2 with probability 3/64, etc. + We use a simple linear congruential PRNG (see Knuth vol 2) instead + of random(), because we need exactly 32 bits of pseudo-random data + (i.e. 2 * (NUM_LEVELS - 1)). Moreover, the congruential PRNG + is faster and guaranteed to be deterministic (to reproduce bugs). */ + +static uint32 random_seed = 0; + +static int random_level(void) +{ + uint32 r; + int level = 0; + + /* Linear congruence with modulus = 2^32, multiplier = 69069 + (Knuth vol 2 p. 106, line 15 of table 1), additive = 25173. */ + r = random_seed = random_seed * 69069 + 25173; + /* Knuth (vol 2 p. 13) shows that the least significant bits are + "less random" than the most significant bits with a modulus of 2^m, + so consume most significant bits first */ + while ((r & 0xC0000000U) == 0xC0000000U) { level++; r = r << 2; } + Assert(level < NUM_LEVELS); + return level; +} + +/* Insertion in a global root list */ + +static void caml_insert_global_root(struct global_root_list * rootlist, + value * r) +{ + struct global_root * update[NUM_LEVELS]; + struct global_root * e, * f; + int i, new_level; + + /* Init "cursor" to list head */ + e = (struct global_root *) rootlist; + /* Find place to insert new node */ + for (i = rootlist->level; i >= 0; i--) { + while (1) { + f = e->forward[i]; + if (f == NULL || f->root >= r) break; + e = f; + } + update[i] = e; + } + e = e->forward[0]; + /* If already present, don't do anything */ + if (e != NULL && e->root == r) return; + /* Insert additional element, updating list level if necessary */ + new_level = random_level(); + if (new_level > rootlist->level) { + for (i = rootlist->level + 1; i <= new_level; i++) + update[i] = (struct global_root *) rootlist; + rootlist->level = new_level; + } + e = caml_stat_alloc(sizeof(struct global_root) + + new_level * sizeof(struct global_root *)); + e->root = r; + for (i = 0; i <= new_level; i++) { + e->forward[i] = update[i]->forward[i]; + update[i]->forward[i] = e; + } +} + +/* Deletion in a global root list */ + +static void caml_delete_global_root(struct global_root_list * rootlist, + value * r) +{ + struct global_root * update[NUM_LEVELS]; + struct global_root * e, * f; + int i; + + /* Init "cursor" to list head */ + e = (struct global_root *) rootlist; + /* Find element in list */ + for (i = rootlist->level; i >= 0; i--) { + while (1) { + f = e->forward[i]; + if (f == NULL || f->root >= r) break; + e = f; + } + update[i] = e; + } + e = e->forward[0]; + /* If not found, nothing to do */ + if (e == NULL || e->root != r) return; + /* Rebuild list without node */ + for (i = 0; i <= rootlist->level; i++) { + if (update[i]->forward[i] == e) + update[i]->forward[i] = e->forward[i]; + } + /* Reclaim list element */ + caml_stat_free(e); + /* Down-correct list level */ + while (rootlist->level > 0 && + rootlist->forward[rootlist->level] == NULL) + rootlist->level--; +} + +/* Iterate over a global root list */ + +static void caml_iterate_global_roots(scanning_action f, + struct global_root_list * rootlist) +{ + struct global_root * gr; + + for (gr = rootlist->forward[0]; gr != NULL; gr = gr->forward[0]) { + f(*(gr->root), gr->root); + } +} + +/* Empty a global root list */ + +static void caml_empty_global_roots(struct global_root_list * rootlist) +{ + struct global_root * gr, * next; + int i; + + for (gr = rootlist->forward[0]; gr != NULL; /**/) { + next = gr->forward[0]; + caml_stat_free(gr); + gr = next; + } + for (i = 0; i <= rootlist->level; i++) rootlist->forward[i] = NULL; + rootlist->level = 0; +} + +/* The three global root lists */ + +struct global_root_list caml_global_roots = { NULL, { NULL, }, 0 }; + /* mutable roots, don't know whether old or young */ +struct global_root_list caml_global_roots_young = { NULL, { NULL, }, 0 }; + /* generational roots pointing to minor or major heap */ +struct global_root_list caml_global_roots_old = { NULL, { NULL, }, 0 }; + /* generational roots pointing to major heap */ + +/* Register a global C root of the mutable kind */ + +CAMLexport void caml_register_global_root(value *r) +{ + Assert (((intnat) r & 3) == 0); /* compact.c demands this (for now) */ + caml_insert_global_root(&caml_global_roots, r); +} + +/* Un-register a global C root of the mutable kind */ + +CAMLexport void caml_remove_global_root(value *r) +{ + caml_delete_global_root(&caml_global_roots, r); +} + +/* Register a global C root of the generational kind */ + +CAMLexport void caml_register_generational_global_root(value *r) +{ + value v = *r; + Assert (((intnat) r & 3) == 0); /* compact.c demands this (for now) */ + if (Is_block(v)) { + if (Is_young(v)) + caml_insert_global_root(&caml_global_roots_young, r); + else if (Is_in_heap(v)) + caml_insert_global_root(&caml_global_roots_old, r); + } +} + +/* Un-register a global C root of the generational kind */ + +CAMLexport void caml_remove_generational_global_root(value *r) +{ + value v = *r; + if (Is_block(v)) { + if (Is_young(v)) + caml_delete_global_root(&caml_global_roots_young, r); + else if (Is_in_heap(v)) + caml_delete_global_root(&caml_global_roots_old, r); + } +} + +/* Modify the value of a global C root of the generational kind */ + +CAMLexport void caml_modify_generational_global_root(value *r, value newval) +{ + value oldval = *r; + + /* It is OK to have a root in roots_young that suddenly points to + the old generation -- the next minor GC will take care of that. + What needs corrective action is a root in roots_old that suddenly + points to the young generation. */ + if (Is_block(newval) && Is_young(newval) && + Is_block(oldval) && Is_in_heap(oldval)) { + caml_delete_global_root(&caml_global_roots_old, r); + caml_insert_global_root(&caml_global_roots_young, r); + } + *r = newval; +} + +/* Scan all global roots */ + +void caml_scan_global_roots(scanning_action f) +{ + caml_iterate_global_roots(f, &caml_global_roots); + caml_iterate_global_roots(f, &caml_global_roots_young); + caml_iterate_global_roots(f, &caml_global_roots_old); +} + +/* Scan global roots for a minor collection */ + +void caml_scan_global_young_roots(scanning_action f) +{ + struct global_root * gr; + + caml_iterate_global_roots(f, &caml_global_roots); + caml_iterate_global_roots(f, &caml_global_roots_young); + /* Move young roots to old roots */ + for (gr = caml_global_roots_young.forward[0]; + gr != NULL; gr = gr->forward[0]) { + caml_insert_global_root(&caml_global_roots_old, gr->root); + } + caml_empty_global_roots(&caml_global_roots_young); +} diff --git a/byterun/globroots.h b/byterun/globroots.h new file mode 100644 index 0000000..2d7a4d9 --- /dev/null +++ b/byterun/globroots.h @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: globroots.h,v 1.5 2008-03-10 19:56:39 xleroy Exp $ */ + +/* Registration of global memory roots */ + +#ifndef CAML_GLOBROOTS_H +#define CAML_GLOBROOTS_H + +#include "mlvalues.h" +#include "roots.h" + +void caml_scan_global_roots(scanning_action f); +void caml_scan_global_young_roots(scanning_action f); + +#endif /* CAML_GLOBROOTS_H */ diff --git a/byterun/hash.c b/byterun/hash.c new file mode 100644 index 0000000..0bd9b90 --- /dev/null +++ b/byterun/hash.c @@ -0,0 +1,157 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: hash.c,v 1.26 2008-08-01 14:10:36 xleroy Exp $ */ + +/* The generic hashing primitive */ + +/* The interface of this file is in "mlvalues.h" */ + +#include "mlvalues.h" +#include "custom.h" +#include "memory.h" + +static uintnat hash_accu; +static intnat hash_univ_limit, hash_univ_count; + +static void hash_aux(value obj); + +CAMLprim value caml_hash_univ_param(value count, value limit, value obj) +{ + hash_univ_limit = Long_val(limit); + hash_univ_count = Long_val(count); + hash_accu = 0; + hash_aux(obj); + return Val_long(hash_accu & 0x3FFFFFFF); + /* The & has two purposes: ensure that the return value is positive + and give the same result on 32 bit and 64 bit architectures. */ +} + +#define Alpha 65599 +#define Beta 19 +#define Combine(new) (hash_accu = hash_accu * Alpha + (new)) +#define Combine_small(new) (hash_accu = hash_accu * Beta + (new)) + +static void hash_aux(value obj) +{ + unsigned char * p; + mlsize_t i, j; + tag_t tag; + + hash_univ_limit--; + if (hash_univ_count < 0 || hash_univ_limit < 0) return; + + again: + if (Is_long(obj)) { + hash_univ_count--; + Combine(Long_val(obj)); + return; + } + + /* Pointers into the heap are well-structured blocks. So are atoms. + We can inspect the block contents. */ + + Assert (Is_block (obj)); + if (Is_in_value_area(obj)) { + tag = Tag_val(obj); + switch (tag) { + case String_tag: + hash_univ_count--; + i = caml_string_length(obj); + for (p = &Byte_u(obj, 0); i > 0; i--, p++) + Combine_small(*p); + break; + case Double_tag: + /* For doubles, we inspect their binary representation, LSB first. + The results are consistent among all platforms with IEEE floats. */ + hash_univ_count--; +#ifdef ARCH_BIG_ENDIAN + for (p = &Byte_u(obj, sizeof(double) - 1), i = sizeof(double); + i > 0; + p--, i--) +#else + for (p = &Byte_u(obj, 0), i = sizeof(double); + i > 0; + p++, i--) +#endif + Combine_small(*p); + break; + case Double_array_tag: + hash_univ_count--; + for (j = 0; j < Bosize_val(obj); j += sizeof(double)) { +#ifdef ARCH_BIG_ENDIAN + for (p = &Byte_u(obj, j + sizeof(double) - 1), i = sizeof(double); + i > 0; + p--, i--) +#else + for (p = &Byte_u(obj, j), i = sizeof(double); + i > 0; + p++, i--) +#endif + Combine_small(*p); + } + break; + case Abstract_tag: + /* We don't know anything about the contents of the block. + Better do nothing. */ + break; + case Infix_tag: + hash_aux(obj - Infix_offset_val(obj)); + break; + case Forward_tag: + obj = Forward_val (obj); + goto again; + case Object_tag: + hash_univ_count--; + Combine(Oid_val(obj)); + break; + case Custom_tag: + /* If no hashing function provided, do nothing */ + if (Custom_ops_val(obj)->hash != NULL) { + hash_univ_count--; + Combine(Custom_ops_val(obj)->hash(obj)); + } + break; + default: + hash_univ_count--; + Combine_small(tag); + i = Wosize_val(obj); + while (i != 0) { + i--; + hash_aux(Field(obj, i)); + } + break; + } + return; + } + + /* Otherwise, obj is a pointer outside the heap, to an object with + a priori unknown structure. Use its physical address as hash key. */ + Combine((intnat) obj); +} + +/* Hashing variant tags */ + +CAMLexport value caml_hash_variant(char const * tag) +{ + value accu; + /* Same hashing algorithm as in ../typing/btype.ml, function hash_variant */ + for (accu = Val_int(0); *tag != 0; tag++) + accu = Val_int(223 * Int_val(accu) + *((unsigned char *) tag)); +#ifdef ARCH_SIXTYFOUR + accu = accu & Val_long(0x7FFFFFFFL); +#endif + /* Force sign extension of bit 31 for compatibility between 32 and 64-bit + platforms */ + return (int32) accu; +} diff --git a/byterun/instrtrace.c b/byterun/instrtrace.c new file mode 100644 index 0000000..539e8f6 --- /dev/null +++ b/byterun/instrtrace.c @@ -0,0 +1,265 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: instrtrace.c,v 1.22 2008-01-03 09:37:09 xleroy Exp $ */ + +/* Trace the instructions executed */ + +#ifdef DEBUG + +#include +#include +#include + +#include "instruct.h" +#include "misc.h" +#include "mlvalues.h" +#include "opnames.h" +#include "prims.h" +#include "stacks.h" + +extern code_t caml_start_code; + +intnat caml_icount = 0; + +void caml_stop_here () {} + +int caml_trace_flag = 0; + +void caml_disasm_instr(pc) + code_t pc; +{ + int instr = *pc; + printf("%6ld %s", (long) (pc - caml_start_code), + instr < 0 || instr > STOP ? "???" : names_of_instructions[instr]); + pc++; + switch(instr) { + /* Instructions with one integer operand */ + case PUSHACC: case ACC: case POP: case ASSIGN: + case PUSHENVACC: case ENVACC: case PUSH_RETADDR: case APPLY: + case APPTERM1: case APPTERM2: case APPTERM3: case RETURN: + case GRAB: case PUSHGETGLOBAL: case GETGLOBAL: case SETGLOBAL: + case PUSHATOM: case ATOM: case MAKEBLOCK1: case MAKEBLOCK2: + case MAKEBLOCK3: case MAKEFLOATBLOCK: + case GETFIELD: case SETFIELD: case GETFLOATFIELD: case SETFLOATFIELD: + case BRANCH: case BRANCHIF: case BRANCHIFNOT: case PUSHTRAP: + case CONSTINT: case PUSHCONSTINT: case OFFSETINT: case OFFSETREF: + case OFFSETCLOSURE: case PUSHOFFSETCLOSURE: + printf(" %d\n", pc[0]); break; + /* Instructions with two operands */ + case APPTERM: case CLOSURE: case CLOSUREREC: case PUSHGETGLOBALFIELD: + case GETGLOBALFIELD: case MAKEBLOCK: + case BEQ: case BNEQ: case BLTINT: case BLEINT: case BGTINT: case BGEINT: + case BULTINT: case BUGEINT: + printf(" %d, %d\n", pc[0], pc[1]); break; + /* Instructions with a C primitive as operand */ + case C_CALLN: + printf(" %d,", pc[0]); pc++; + /* fallthrough */ + case C_CALL1: case C_CALL2: case C_CALL3: case C_CALL4: case C_CALL5: + if (pc[0] < 0 || pc[0] >= caml_prim_name_table.size) + printf(" unknown primitive %d\n", pc[0]); + else + printf(" %s\n", (char *) caml_prim_name_table.contents[pc[0]]); + break; + default: + printf("\n"); + } + fflush (stdout); +} + +char * caml_instr_string (code_t pc) +{ + static char buf[256]; + char nambuf[128]; + int instr = *pc; + char *nam; + + nam = (instr < 0 || instr > STOP) + ? (sprintf (nambuf, "???%d", instr), nambuf) + : names_of_instructions[instr]; + pc++; + switch (instr) { + /* Instructions with one integer operand */ + case PUSHACC: + case ACC: + case POP: + case ASSIGN: + case PUSHENVACC: + case ENVACC: + case PUSH_RETADDR: + case APPLY: + case APPTERM1: + case APPTERM2: + case APPTERM3: + case RETURN: + case GRAB: + case PUSHGETGLOBAL: + case GETGLOBAL: + case SETGLOBAL: + case PUSHATOM: + case ATOM: + case MAKEBLOCK1: + case MAKEBLOCK2: + case MAKEBLOCK3: + case MAKEFLOATBLOCK: + case GETFIELD: + case SETFIELD: + case GETFLOATFIELD: + case SETFLOATFIELD: + case BRANCH: + case BRANCHIF: + case BRANCHIFNOT: + case PUSHTRAP: + case CONSTINT: + case PUSHCONSTINT: + case OFFSETINT: + case OFFSETREF: + case OFFSETCLOSURE: + case PUSHOFFSETCLOSURE: + sprintf(buf, "%s %d", nam, pc[0]); + break; + /* Instructions with two operands */ + case APPTERM: + case CLOSURE: + case CLOSUREREC: + case PUSHGETGLOBALFIELD: + case GETGLOBALFIELD: + case MAKEBLOCK: + case BEQ: + case BNEQ: + case BLTINT: + case BLEINT: + case BGTINT: + case BGEINT: + case BULTINT: + case BUGEINT: + sprintf(buf, "%s %d, %d", nam, pc[0], pc[1]); + break; + case SWITCH: + sprintf(buf, "SWITCH sz%#lx=%ld::ntag%ld nint%ld", + (long) pc[0], (long) pc[0], (unsigned long) pc[0] >> 16, + (unsigned long) pc[0] & 0xffff); + break; + /* Instructions with a C primitive as operand */ + case C_CALLN: + sprintf(buf, "%s %d,", nam, pc[0]); + pc++; + /* fallthrough */ + case C_CALL1: + case C_CALL2: + case C_CALL3: + case C_CALL4: + case C_CALL5: + if (pc[0] < 0 || pc[0] >= caml_prim_name_table.size) + sprintf(buf, "%s unknown primitive %d", nam, pc[0]); + else + sprintf(buf, "%s %s", nam, (char *) caml_prim_name_table.contents[pc[0]]); + break; + default: + sprintf(buf, "%s", nam); + break; + }; + return buf; +} + + +void +caml_trace_value_file (value v, code_t prog, int proglen, FILE * f) +{ + int i; + fprintf (f, "%#lx", v); + if (!v) + return; + if (prog && v % sizeof (int) == 0 + && (code_t) v >= prog + && (code_t) v < (code_t) ((char *) prog + proglen)) + fprintf (f, "=code@%d", (code_t) v - prog); + else if (Is_long (v)) + fprintf (f, "=long%" ARCH_INTNAT_PRINTF_FORMAT "d", Long_val (v)); + else if ((void*)v >= (void*)caml_stack_low + && (void*)v < (void*)caml_stack_high) + fprintf (f, "=stack_%d", (intnat*)caml_stack_high - (intnat*)v); + else if (Is_block (v)) { + int s = Wosize_val (v); + int tg = Tag_val (v); + int l = 0; + switch (tg) { + case Closure_tag: + fprintf (f, "=closure[s%d,cod%d]", s, (code_t) (Code_val (v)) - prog); + goto displayfields; + case String_tag: + l = caml_string_length (v); + fprintf (f, "=string[s%dL%d]'", s, l); + for (i = 0; i < ((l>0x1f)?0x1f:l) ; i++) { + if (isprint (Byte (v, i))) + putc (Byte (v, i), f); + else + putc ('?', f); + }; + fprintf (f, "'"); + goto displayfields; + case Double_tag: + fprintf (f, "=float[s%d]=%g", s, Double_val (v)); + goto displayfields; + case Double_array_tag: + fprintf (f, "=floatarray[s%d]", s); + for (i = 0; i < ((s>0xf)?0xf:s); i++) + fprintf (f, " %g", Double_field (v, i)); + goto displayfields; + case Abstract_tag: + fprintf (f, "=abstract[s%d]", s); + goto displayfields; + case Custom_tag: + fprintf (f, "=custom[s%d]", s); + goto displayfields; + default: + fprintf (f, "=block", tg, s); + displayfields: + if (s > 0) + fputs ("=(", f); + for (i = 0; i < s; i++) { + if (i > 20) { + fputs ("....", f); + break; + }; + if (i > 0) + putc (' ', f); + fprintf (f, "%#lx", Field (v, i)); + }; + if (s > 0) + putc (')', f); + }; + } +} + +void +caml_trace_accu_sp_file (value accu, value * sp, code_t prog, int proglen, + FILE * f) +{ + int i; + value *p; + fprintf (f, "accu="); + caml_trace_value_file (accu, prog, proglen, f); + fprintf (f, "\n sp=%#" ARCH_INTNAT_PRINTF_FORMAT "x @%d:", + (intnat) sp, caml_stack_high - sp); + for (p = sp, i = 0; i < 12 + (1 << caml_trace_flag) && p < caml_stack_high; + p++, i++) { + fprintf (f, "\n[%d] ", caml_stack_high - p); + caml_trace_value_file (*p, prog, proglen, f); + }; + putc ('\n', f); + fflush (f); +} + +#endif /* DEBUG */ diff --git a/byterun/instrtrace.h b/byterun/instrtrace.h new file mode 100644 index 0000000..83cb52b --- /dev/null +++ b/byterun/instrtrace.h @@ -0,0 +1,31 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: instrtrace.h,v 1.9 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Trace the instructions executed */ + +#ifndef _instrtrace_ +#define _instrtrace_ + + +#include "mlvalues.h" +#include "misc.h" + +extern int caml_trace_flag; +extern intnat caml_icount; +void caml_stop_here (void); +void caml_disasm_instr (code_t pc); +void caml_trace_value_file (value v, code_t prog, int proglen, FILE * f); +void caml_trace_accu_sp_file(value accu, value * sp, code_t prog, int proglen, FILE * f); +#endif diff --git a/byterun/instruct.h b/byterun/instruct.h new file mode 100644 index 0000000..abdfad1 --- /dev/null +++ b/byterun/instruct.h @@ -0,0 +1,61 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: instruct.h,v 1.20 2004-05-26 11:10:51 garrigue Exp $ */ + +/* The instruction set. */ + +#ifndef CAML_INSTRUCT_H +#define CAML_INSTRUCT_H + +enum instructions { + ACC0, ACC1, ACC2, ACC3, ACC4, ACC5, ACC6, ACC7, + ACC, PUSH, + PUSHACC0, PUSHACC1, PUSHACC2, PUSHACC3, + PUSHACC4, PUSHACC5, PUSHACC6, PUSHACC7, + PUSHACC, POP, ASSIGN, + ENVACC1, ENVACC2, ENVACC3, ENVACC4, ENVACC, + PUSHENVACC1, PUSHENVACC2, PUSHENVACC3, PUSHENVACC4, PUSHENVACC, + PUSH_RETADDR, APPLY, APPLY1, APPLY2, APPLY3, + APPTERM, APPTERM1, APPTERM2, APPTERM3, + RETURN, RESTART, GRAB, + CLOSURE, CLOSUREREC, + OFFSETCLOSUREM2, OFFSETCLOSURE0, OFFSETCLOSURE2, OFFSETCLOSURE, + PUSHOFFSETCLOSUREM2, PUSHOFFSETCLOSURE0, + PUSHOFFSETCLOSURE2, PUSHOFFSETCLOSURE, + GETGLOBAL, PUSHGETGLOBAL, GETGLOBALFIELD, PUSHGETGLOBALFIELD, SETGLOBAL, + ATOM0, ATOM, PUSHATOM0, PUSHATOM, + MAKEBLOCK, MAKEBLOCK1, MAKEBLOCK2, MAKEBLOCK3, MAKEFLOATBLOCK, + GETFIELD0, GETFIELD1, GETFIELD2, GETFIELD3, GETFIELD, GETFLOATFIELD, + SETFIELD0, SETFIELD1, SETFIELD2, SETFIELD3, SETFIELD, SETFLOATFIELD, + VECTLENGTH, GETVECTITEM, SETVECTITEM, + GETSTRINGCHAR, SETSTRINGCHAR, + BRANCH, BRANCHIF, BRANCHIFNOT, SWITCH, BOOLNOT, + PUSHTRAP, POPTRAP, RAISE, CHECK_SIGNALS, + C_CALL1, C_CALL2, C_CALL3, C_CALL4, C_CALL5, C_CALLN, + CONST0, CONST1, CONST2, CONST3, CONSTINT, + PUSHCONST0, PUSHCONST1, PUSHCONST2, PUSHCONST3, PUSHCONSTINT, + NEGINT, ADDINT, SUBINT, MULINT, DIVINT, MODINT, + ANDINT, ORINT, XORINT, LSLINT, LSRINT, ASRINT, + EQ, NEQ, LTINT, LEINT, GTINT, GEINT, + OFFSETINT, OFFSETREF, ISINT, + GETMETHOD, + BEQ, BNEQ, BLTINT, BLEINT, BGTINT, BGEINT, + ULTINT, UGEINT, + BULTINT, BUGEINT, + GETPUBMET, GETDYNMET, + STOP, + EVENT, BREAK +}; + +#endif /* CAML_INSTRUCT_H */ diff --git a/byterun/int64_emul.h b/byterun/int64_emul.h new file mode 100644 index 0000000..fa0603e --- /dev/null +++ b/byterun/int64_emul.h @@ -0,0 +1,272 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: int64_emul.h,v 1.5 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Software emulation of 64-bit integer arithmetic, for C compilers + that do not support it. */ + +#ifndef CAML_INT64_EMUL_H +#define CAML_INT64_EMUL_H + +#include + +#ifdef ARCH_BIG_ENDIAN +#define I64_literal(hi,lo) { hi, lo } +#else +#define I64_literal(hi,lo) { lo, hi } +#endif + +/* Unsigned comparison */ +static int I64_ucompare(uint64 x, uint64 y) +{ + if (x.h > y.h) return 1; + if (x.h < y.h) return -1; + if (x.l > y.l) return 1; + if (x.l < y.l) return -1; + return 0; +} + +#define I64_ult(x, y) (I64_ucompare(x, y) < 0) + +/* Signed comparison */ +static int I64_compare(int64 x, int64 y) +{ + if ((int32)x.h > (int32)y.h) return 1; + if ((int32)x.h < (int32)y.h) return -1; + if (x.l > y.l) return 1; + if (x.l < y.l) return -1; + return 0; +} + +/* Negation */ +static int64 I64_neg(int64 x) +{ + int64 res; + res.l = -x.l; + res.h = ~x.h; + if (res.l == 0) res.h++; + return res; +} + +/* Addition */ +static int64 I64_add(int64 x, int64 y) +{ + int64 res; + res.l = x.l + y.l; + res.h = x.h + y.h; + if (res.l < x.l) res.h++; + return res; +} + +/* Subtraction */ +static int64 I64_sub(int64 x, int64 y) +{ + int64 res; + res.l = x.l - y.l; + res.h = x.h - y.h; + if (x.l < y.l) res.h--; + return res; +} + +/* Multiplication */ +static int64 I64_mul(int64 x, int64 y) +{ + int64 res; + uint32 prod00 = (x.l & 0xFFFF) * (y.l & 0xFFFF); + uint32 prod10 = (x.l >> 16) * (y.l & 0xFFFF); + uint32 prod01 = (x.l & 0xFFFF) * (y.l >> 16); + uint32 prod11 = (x.l >> 16) * (y.l >> 16); + res.l = prod00; + res.h = prod11 + (prod01 >> 16) + (prod10 >> 16); + prod01 = prod01 << 16; res.l += prod01; if (res.l < prod01) res.h++; + prod10 = prod10 << 16; res.l += prod10; if (res.l < prod10) res.h++; + res.h += x.l * y.h + x.h * y.l; + return res; +} + +#define I64_is_zero(x) (((x).l | (x).h) == 0) + +#define I64_is_negative(x) ((int32) (x).h < 0) + +/* Bitwise operations */ +static int64 I64_and(int64 x, int64 y) +{ + int64 res; + res.l = x.l & y.l; + res.h = x.h & y.h; + return res; +} + +static int64 I64_or(int64 x, int64 y) +{ + int64 res; + res.l = x.l | y.l; + res.h = x.h | y.h; + return res; +} + +static int64 I64_xor(int64 x, int64 y) +{ + int64 res; + res.l = x.l ^ y.l; + res.h = x.h ^ y.h; + return res; +} + +/* Shifts */ +static int64 I64_lsl(int64 x, int s) +{ + int64 res; + s = s & 63; + if (s == 0) return x; + if (s < 32) { + res.l = x.l << s; + res.h = (x.h << s) | (x.l >> (32 - s)); + } else { + res.l = 0; + res.h = x.l << (s - 32); + } + return res; +} + +static int64 I64_lsr(int64 x, int s) +{ + int64 res; + s = s & 63; + if (s == 0) return x; + if (s < 32) { + res.l = (x.l >> s) | (x.h << (32 - s)); + res.h = x.h >> s; + } else { + res.l = x.h >> (s - 32); + res.h = 0; + } + return res; +} + +static int64 I64_asr(int64 x, int s) +{ + int64 res; + s = s & 63; + if (s == 0) return x; + if (s < 32) { + res.l = (x.l >> s) | (x.h << (32 - s)); + res.h = (int32) x.h >> s; + } else { + res.l = (int32) x.h >> (s - 32); + res.h = (int32) x.h >> 31; + } + return res; +} + +/* Division and modulus */ + +#define I64_SHL1(x) x.h = (x.h << 1) | (x.l >> 31); x.l <<= 1 +#define I64_SHR1(x) x.l = (x.l >> 1) | (x.h << 31); x.h >>= 1 + +static void I64_udivmod(uint64 modulus, uint64 divisor, + uint64 * quo, uint64 * mod) +{ + int64 quotient, mask; + int cmp; + + quotient.h = 0; quotient.l = 0; + mask.h = 0; mask.l = 1; + while ((int32) divisor.h >= 0) { + cmp = I64_ucompare(divisor, modulus); + I64_SHL1(divisor); + I64_SHL1(mask); + if (cmp >= 0) break; + } + while (mask.l | mask.h) { + if (I64_ucompare(modulus, divisor) >= 0) { + quotient.h |= mask.h; quotient.l |= mask.l; + modulus = I64_sub(modulus, divisor); + } + I64_SHR1(mask); + I64_SHR1(divisor); + } + *quo = quotient; + *mod = modulus; +} + +static int64 I64_div(int64 x, int64 y) +{ + int64 q, r; + int32 sign; + + sign = x.h ^ y.h; + if ((int32) x.h < 0) x = I64_neg(x); + if ((int32) y.h < 0) y = I64_neg(y); + I64_udivmod(x, y, &q, &r); + if (sign < 0) q = I64_neg(q); + return q; +} + +static int64 I64_mod(int64 x, int64 y) +{ + int64 q, r; + int32 sign; + + sign = x.h; + if ((int32) x.h < 0) x = I64_neg(x); + if ((int32) y.h < 0) y = I64_neg(y); + I64_udivmod(x, y, &q, &r); + if (sign < 0) r = I64_neg(r); + return r; +} + +/* Coercions */ + +static int64 I64_of_int32(int32 x) +{ + int64 res; + res.l = x; + res.h = x >> 31; + return res; +} + +#define I64_to_int32(x) ((int32) (x).l) + +/* Note: we assume sizeof(intnat) = 4 here, which is true otherwise + autoconfiguration would have selected native 64-bit integers */ +#define I64_of_intnat I64_of_int32 +#define I64_to_intnat I64_to_int32 + +static double I64_to_double(int64 x) +{ + double res; + int32 sign = x.h; + if (sign < 0) x = I64_neg(x); + res = ldexp((double) x.h, 32) + x.l; + if (sign < 0) res = -res; + return res; +} + +static int64 I64_of_double(double f) +{ + int64 res; + double frac, integ; + int neg; + + neg = (f < 0); + f = fabs(f); + frac = modf(ldexp(f, -32), &integ); + res.h = (uint32) integ; + res.l = (uint32) ldexp(frac, 32); + if (neg) res = I64_neg(res); + return res; +} + +#endif /* CAML_INT64_EMUL_H */ diff --git a/byterun/int64_format.h b/byterun/int64_format.h new file mode 100644 index 0000000..0850dca --- /dev/null +++ b/byterun/int64_format.h @@ -0,0 +1,107 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: int64_format.h,v 1.2 2003-12-15 18:10:47 doligez Exp $ */ + +/* printf-like formatting of 64-bit integers, in case the C library + printf() function does not support them. */ + +#ifndef CAML_INT64_FORMAT_H +#define CAML_INT64_FORMAT_H + +static void I64_format(char * buffer, char * fmt, int64 x) +{ + static char conv_lower[] = "0123456789abcdef"; + static char conv_upper[] = "0123456789ABCDEF"; + char rawbuffer[24]; + char justify, signstyle, filler, alternate, signedconv; + int base, width, sign, i, rawlen; + char * cvtbl; + char * p, * r; + int64 wbase, digit; + + /* Parsing of format */ + justify = '+'; + signstyle = '-'; + filler = ' '; + alternate = 0; + base = 0; + signedconv = 0; + width = 0; + cvtbl = conv_lower; + for (p = fmt; *p != 0; p++) { + switch (*p) { + case '-': + justify = '-'; break; + case '+': case ' ': + signstyle = *p; break; + case '0': + filler = '0'; break; + case '#': + alternate = 1; break; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + width = atoi(p); + while (*p >= '0' && *p <= '9') p++; + break; + case 'd': case 'i': + signedconv = 1; /* fallthrough */ + case 'u': + base = 10; break; + case 'x': + base = 16; break; + case 'X': + base = 16; cvtbl = conv_upper; break; + case 'o': + base = 8; break; + } + } + if (base == 0) { buffer[0] = 0; return; } + /* Do the conversion */ + sign = 1; + if (signedconv && I64_is_negative(x)) { sign = -1; x = I64_neg(x); } + r = rawbuffer + sizeof(rawbuffer); + wbase = I64_of_int32(base); + do { + I64_udivmod(x, wbase, &x, &digit); + *--r = cvtbl[I64_to_int32(digit)]; + } while (! I64_is_zero(x)); + rawlen = rawbuffer + sizeof(rawbuffer) - r; + /* Adjust rawlen to reflect additional chars (sign, etc) */ + if (signedconv && (sign < 0 || signstyle != '-')) rawlen++; + if (alternate) { + if (base == 8) rawlen += 1; + if (base == 16) rawlen += 2; + } + /* Do the formatting */ + p = buffer; + if (justify == '+' && filler == ' ') { + for (i = rawlen; i < width; i++) *p++ = ' '; + } + if (signedconv) { + if (sign < 0) *p++ = '-'; + else if (signstyle != '-') *p++ = signstyle; + } + if (alternate && base == 8) *p++ = '0'; + if (alternate && base == 16) { *p++ = '0'; *p++ = 'x'; } + if (justify == '+' && filler == '0') { + for (i = rawlen; i < width; i++) *p++ = '0'; + } + while (r < rawbuffer + sizeof(rawbuffer)) *p++ = *r++; + if (justify == '-') { + for (i = rawlen; i < width; i++) *p++ = ' '; + } + *p = 0; +} + +#endif /* CAML_INT64_FORMAT_H */ diff --git a/byterun/int64_native.h b/byterun/int64_native.h new file mode 100644 index 0000000..daacdb6 --- /dev/null +++ b/byterun/int64_native.h @@ -0,0 +1,50 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: int64_native.h,v 1.5 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Wrapper macros around native 64-bit integer arithmetic, + so that it has the same interface as the software emulation + provided in int64_emul.h */ + +#ifndef CAML_INT64_NATIVE_H +#define CAML_INT64_NATIVE_H + +#define I64_literal(hi,lo) ((int64)(hi) << 32 | (lo)) +#define I64_compare(x,y) (((x) > (y)) - ((x) < (y))) +#define I64_ult(x,y) ((uint64)(x) < (uint64)(y)) +#define I64_neg(x) (-(x)) +#define I64_add(x,y) ((x) + (y)) +#define I64_sub(x,y) ((x) - (y)) +#define I64_mul(x,y) ((x) * (y)) +#define I64_is_zero(x) ((x) == 0) +#define I64_is_negative(x) ((x) < 0) +#define I64_div(x,y) ((x) / (y)) +#define I64_mod(x,y) ((x) % (y)) +#define I64_udivmod(x,y,quo,rem) \ + (*(rem) = (uint64)(x) % (uint64)(y), \ + *(quo) = (uint64)(x) / (uint64)(y)) +#define I64_and(x,y) ((x) & (y)) +#define I64_or(x,y) ((x) | (y)) +#define I64_xor(x,y) ((x) ^ (y)) +#define I64_lsl(x,y) ((x) << (y)) +#define I64_asr(x,y) ((x) >> (y)) +#define I64_lsr(x,y) ((uint64)(x) >> (y)) +#define I64_to_intnat(x) ((intnat) (x)) +#define I64_of_intnat(x) ((intnat) (x)) +#define I64_to_int32(x) ((int32) (x)) +#define I64_of_int32(x) ((int64) (x)) +#define I64_to_double(x) ((double)(x)) +#define I64_of_double(x) ((int64)(x)) + +#endif /* CAML_INT64_NATIVE_H */ diff --git a/byterun/intern.c b/byterun/intern.c new file mode 100644 index 0000000..a0794cb --- /dev/null +++ b/byterun/intern.c @@ -0,0 +1,715 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: intern.c,v 1.61 2008-01-11 16:13:16 doligez Exp $ */ + +/* Structured input, compact format */ + +/* The interface of this file is "intext.h" */ + +#include +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "gc.h" +#include "intext.h" +#include "io.h" +#include "memory.h" +#include "mlvalues.h" +#include "misc.h" +#include "reverse.h" + +static unsigned char * intern_src; +/* Reading pointer in block holding input data. */ + +static unsigned char * intern_input; +/* Pointer to beginning of block holding input data. + Meaningful only if intern_input_malloced = 1. */ + +static int intern_input_malloced; +/* 1 if intern_input was allocated by caml_stat_alloc() + and needs caml_stat_free() on error, 0 otherwise. */ + +static header_t * intern_dest; +/* Writing pointer in destination block */ + +static char * intern_extra_block; +/* If non-NULL, point to new heap chunk allocated with caml_alloc_for_heap. */ + +static asize_t obj_counter; +/* Count how many objects seen so far */ + +static value * intern_obj_table; +/* The pointers to objects already seen */ + +static unsigned int intern_color; +/* Color to assign to newly created headers */ + +static header_t intern_header; +/* Original header of the destination block. + Meaningful only if intern_extra_block is NULL. */ + +static value intern_block; +/* Point to the heap block allocated as destination block. + Meaningful only if intern_extra_block is NULL. */ + +#define Sign_extend_shift ((sizeof(intnat) - 1) * 8) +#define Sign_extend(x) (((intnat)(x) << Sign_extend_shift) >> Sign_extend_shift) + +#define read8u() (*intern_src++) +#define read8s() Sign_extend(*intern_src++) +#define read16u() \ + (intern_src += 2, \ + (intern_src[-2] << 8) + intern_src[-1]) +#define read16s() \ + (intern_src += 2, \ + (Sign_extend(intern_src[-2]) << 8) + intern_src[-1]) +#define read32u() \ + (intern_src += 4, \ + ((uintnat)(intern_src[-4]) << 24) + (intern_src[-3] << 16) + \ + (intern_src[-2] << 8) + intern_src[-1]) +#define read32s() \ + (intern_src += 4, \ + (Sign_extend(intern_src[-4]) << 24) + (intern_src[-3] << 16) + \ + (intern_src[-2] << 8) + intern_src[-1]) + +#ifdef ARCH_SIXTYFOUR +static intnat read64s(void) +{ + intnat res; + int i; + res = 0; + for (i = 0; i < 8; i++) res = (res << 8) + intern_src[i]; + intern_src += 8; + return res; +} +#endif + +#define readblock(dest,len) \ + (memmove((dest), intern_src, (len)), intern_src += (len)) + +static void intern_cleanup(void) +{ + if (intern_input_malloced) caml_stat_free(intern_input); + if (intern_obj_table != NULL) caml_stat_free(intern_obj_table); + if (intern_extra_block != NULL) { + /* free newly allocated heap chunk */ + caml_free_for_heap(intern_extra_block); + } else if (intern_block != 0) { + /* restore original header for heap block, otherwise GC is confused */ + Hd_val(intern_block) = intern_header; + } +} + +static void intern_rec(value *dest) +{ + unsigned int code; + tag_t tag; + mlsize_t size, len, ofs_ind; + value v, clos; + asize_t ofs; + header_t header; + char cksum[16]; + struct custom_operations * ops; + + tailcall: + code = read8u(); + if (code >= PREFIX_SMALL_INT) { + if (code >= PREFIX_SMALL_BLOCK) { + /* Small block */ + tag = code & 0xF; + size = (code >> 4) & 0x7; + read_block: + if (size == 0) { + v = Atom(tag); + } else { + v = Val_hp(intern_dest); + *dest = v; + if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; + dest = (value *) (intern_dest + 1); + *intern_dest = Make_header(size, tag, intern_color); + intern_dest += 1 + size; + for(/*nothing*/; size > 1; size--, dest++) + intern_rec(dest); + goto tailcall; + } + } else { + /* Small integer */ + v = Val_int(code & 0x3F); + } + } else { + if (code >= PREFIX_SMALL_STRING) { + /* Small string */ + len = (code & 0x1F); + read_string: + size = (len + sizeof(value)) / sizeof(value); + v = Val_hp(intern_dest); + if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; + *intern_dest = Make_header(size, String_tag, intern_color); + intern_dest += 1 + size; + Field(v, size - 1) = 0; + ofs_ind = Bsize_wsize(size) - 1; + Byte(v, ofs_ind) = ofs_ind - len; + readblock(String_val(v), len); + } else { + switch(code) { + case CODE_INT8: + v = Val_long(read8s()); + break; + case CODE_INT16: + v = Val_long(read16s()); + break; + case CODE_INT32: + v = Val_long(read32s()); + break; + case CODE_INT64: +#ifdef ARCH_SIXTYFOUR + v = Val_long(read64s()); + break; +#else + intern_cleanup(); + caml_failwith("input_value: integer too large"); + break; +#endif + case CODE_SHARED8: + ofs = read8u(); + read_shared: + Assert (ofs > 0); + Assert (ofs <= obj_counter); + Assert (intern_obj_table != NULL); + v = intern_obj_table[obj_counter - ofs]; + break; + case CODE_SHARED16: + ofs = read16u(); + goto read_shared; + case CODE_SHARED32: + ofs = read32u(); + goto read_shared; + case CODE_BLOCK32: + header = (header_t) read32u(); + tag = Tag_hd(header); + size = Wosize_hd(header); + goto read_block; + case CODE_BLOCK64: +#ifdef ARCH_SIXTYFOUR + header = (header_t) read64s(); + tag = Tag_hd(header); + size = Wosize_hd(header); + goto read_block; +#else + intern_cleanup(); + caml_failwith("input_value: data block too large"); + break; +#endif + case CODE_STRING8: + len = read8u(); + goto read_string; + case CODE_STRING32: + len = read32u(); + goto read_string; + case CODE_DOUBLE_LITTLE: + case CODE_DOUBLE_BIG: + if (sizeof(double) != 8) { + intern_cleanup(); + caml_invalid_argument("input_value: non-standard floats"); + } + v = Val_hp(intern_dest); + if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; + *intern_dest = Make_header(Double_wosize, Double_tag, intern_color); + intern_dest += 1 + Double_wosize; + readblock((char *) v, 8); +#if ARCH_FLOAT_ENDIANNESS == 0x76543210 + if (code != CODE_DOUBLE_BIG) Reverse_64(v, v); +#elif ARCH_FLOAT_ENDIANNESS == 0x01234567 + if (code != CODE_DOUBLE_LITTLE) Reverse_64(v, v); +#else + if (code == CODE_DOUBLE_LITTLE) + Permute_64(v, ARCH_FLOAT_ENDIANNESS, v, 0x01234567) + else + Permute_64(v, ARCH_FLOAT_ENDIANNESS, v, 0x76543210); +#endif + break; + case CODE_DOUBLE_ARRAY8_LITTLE: + case CODE_DOUBLE_ARRAY8_BIG: + len = read8u(); + read_double_array: + if (sizeof(double) != 8) { + intern_cleanup(); + caml_invalid_argument("input_value: non-standard floats"); + } + size = len * Double_wosize; + v = Val_hp(intern_dest); + if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; + *intern_dest = Make_header(size, Double_array_tag, intern_color); + intern_dest += 1 + size; + readblock((char *) v, len * 8); +#if ARCH_FLOAT_ENDIANNESS == 0x76543210 + if (code != CODE_DOUBLE_ARRAY8_BIG && + code != CODE_DOUBLE_ARRAY32_BIG) { + mlsize_t i; + for (i = 0; i < len; i++) Reverse_64((value)((double *)v + i), + (value)((double *)v + i)); + } +#elif ARCH_FLOAT_ENDIANNESS == 0x01234567 + if (code != CODE_DOUBLE_ARRAY8_LITTLE && + code != CODE_DOUBLE_ARRAY32_LITTLE) { + mlsize_t i; + for (i = 0; i < len; i++) Reverse_64((value)((double *)v + i), + (value)((double *)v + i)); + } +#else + if (code == CODE_DOUBLE_ARRAY8_LITTLE || + code == CODE_DOUBLE_ARRAY32_LITTLE) { + mlsize_t i; + for (i = 0; i < len; i++) + Permute_64((value)((double *)v + i), ARCH_FLOAT_ENDIANNESS, + (value)((double *)v + i), 0x01234567); + } else { + mlsize_t i; + for (i = 0; i < len; i++) + Permute_64((value)((double *)v + i), ARCH_FLOAT_ENDIANNESS, + (value)((double *)v + i), 0x76543210); + } +#endif + break; + case CODE_DOUBLE_ARRAY32_LITTLE: + case CODE_DOUBLE_ARRAY32_BIG: + len = read32u(); + goto read_double_array; + case CODE_CODEPOINTER: + ofs = read32u(); + readblock(cksum, 16); + if (memcmp(cksum, caml_code_checksum(), 16) != 0) { + intern_cleanup(); + caml_failwith("input_value: code mismatch"); + } + v = (value) (caml_code_area_start + ofs); + break; + case CODE_INFIXPOINTER: + ofs = read32u(); + intern_rec(&clos); + v = clos + ofs; + break; + case CODE_CUSTOM: + ops = caml_find_custom_operations((char *) intern_src); + if (ops == NULL) { + intern_cleanup(); + caml_failwith("input_value: unknown custom block identifier"); + } + while (*intern_src++ != 0) /*nothing*/; /*skip identifier*/ + size = ops->deserialize((void *) (intern_dest + 2)); + size = 1 + (size + sizeof(value) - 1) / sizeof(value); + v = Val_hp(intern_dest); + if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; + *intern_dest = Make_header(size, Custom_tag, intern_color); + Custom_ops_val(v) = ops; + intern_dest += 1 + size; + break; + default: + intern_cleanup(); + caml_failwith("input_value: ill-formed message"); + } + } + } + *dest = v; +} + +static void intern_alloc(mlsize_t whsize, mlsize_t num_objects) +{ + mlsize_t wosize; + + if (whsize == 0) { + intern_obj_table = NULL; + intern_extra_block = NULL; + intern_block = 0; + return; + } + wosize = Wosize_whsize(whsize); + if (wosize > Max_wosize) { + /* Round desired size up to next page */ + asize_t request = + ((Bsize_wsize(whsize) + Page_size - 1) >> Page_log) << Page_log; + intern_extra_block = caml_alloc_for_heap(request); + if (intern_extra_block == NULL) caml_raise_out_of_memory(); + intern_color = caml_allocation_color(intern_extra_block); + intern_dest = (header_t *) intern_extra_block; + } else { + /* this is a specialised version of caml_alloc from alloc.c */ + if (wosize == 0){ + intern_block = Atom (String_tag); + }else if (wosize <= Max_young_wosize){ + intern_block = caml_alloc_small (wosize, String_tag); + }else{ + intern_block = caml_alloc_shr (wosize, String_tag); + /* do not do the urgent_gc check here because it might darken + intern_block into gray and break the Assert 3 lines down */ + } + intern_header = Hd_val(intern_block); + intern_color = Color_hd(intern_header); + Assert (intern_color == Caml_white || intern_color == Caml_black); + intern_dest = (header_t *) Hp_val(intern_block); + intern_extra_block = NULL; + } + obj_counter = 0; + if (num_objects > 0) + intern_obj_table = (value *) caml_stat_alloc(num_objects * sizeof(value)); + else + intern_obj_table = NULL; +} + +static void intern_add_to_heap(mlsize_t whsize) +{ + /* Add new heap chunk to heap if needed */ + if (intern_extra_block != NULL) { + /* If heap chunk not filled totally, build free block at end */ + asize_t request = + ((Bsize_wsize(whsize) + Page_size - 1) >> Page_log) << Page_log; + header_t * end_extra_block = + (header_t *) intern_extra_block + Wsize_bsize(request); + Assert(intern_dest <= end_extra_block); + if (intern_dest < end_extra_block){ + caml_make_free_blocks ((value *) intern_dest, + end_extra_block - intern_dest, 0); + } + caml_allocated_words += + Wsize_bsize ((char *) intern_dest - intern_extra_block); + caml_add_to_heap(intern_extra_block); + } +} + +value caml_input_val(struct channel *chan) +{ + uint32 magic; + mlsize_t block_len, num_objects, size_32, size_64, whsize; + char * block; + value res; + + if (! caml_channel_binary_mode(chan)) + caml_failwith("input_value: not a binary channel"); + magic = caml_getword(chan); + if (magic != Intext_magic_number) caml_failwith("input_value: bad object"); + block_len = caml_getword(chan); + num_objects = caml_getword(chan); + size_32 = caml_getword(chan); + size_64 = caml_getword(chan); + /* Read block from channel */ + block = caml_stat_alloc(block_len); + /* During [caml_really_getblock], concurrent [caml_input_val] operations + can take place (via signal handlers or context switching in systhreads), + and [intern_input] may change. So, wait until [caml_really_getblock] + is over before using [intern_input] and the other global vars. */ + if (caml_really_getblock(chan, block, block_len) == 0) { + caml_stat_free(block); + caml_failwith("input_value: truncated object"); + } + intern_input = (unsigned char *) block; + intern_input_malloced = 1; + intern_src = intern_input; + /* Allocate result */ +#ifdef ARCH_SIXTYFOUR + whsize = size_64; +#else + whsize = size_32; +#endif + intern_alloc(whsize, num_objects); + /* Fill it in */ + intern_rec(&res); + intern_add_to_heap(whsize); + /* Free everything */ + caml_stat_free(intern_input); + if (intern_obj_table != NULL) caml_stat_free(intern_obj_table); + return res; +} + +CAMLprim value caml_input_value(value vchan) +{ + CAMLparam1 (vchan); + struct channel * chan = Channel(vchan); + CAMLlocal1 (res); + + Lock(chan); + res = caml_input_val(chan); + Unlock(chan); + CAMLreturn (res); +} + +CAMLexport value caml_input_val_from_string(value str, intnat ofs) +{ + CAMLparam1 (str); + mlsize_t num_objects, size_32, size_64, whsize; + CAMLlocal1 (obj); + + intern_src = &Byte_u(str, ofs + 2*4); + intern_input_malloced = 0; + num_objects = read32u(); + size_32 = read32u(); + size_64 = read32u(); + /* Allocate result */ +#ifdef ARCH_SIXTYFOUR + whsize = size_64; +#else + whsize = size_32; +#endif + intern_alloc(whsize, num_objects); + intern_src = &Byte_u(str, ofs + 5*4); /* If a GC occurred */ + /* Fill it in */ + intern_rec(&obj); + intern_add_to_heap(whsize); + /* Free everything */ + if (intern_obj_table != NULL) caml_stat_free(intern_obj_table); + CAMLreturn (obj); +} + +CAMLprim value caml_input_value_from_string(value str, value ofs) +{ + return caml_input_val_from_string(str, Long_val(ofs)); +} + +static value input_val_from_block(void) +{ + mlsize_t num_objects, size_32, size_64, whsize; + value obj; + + num_objects = read32u(); + size_32 = read32u(); + size_64 = read32u(); + /* Allocate result */ +#ifdef ARCH_SIXTYFOUR + whsize = size_64; +#else + whsize = size_32; +#endif + intern_alloc(whsize, num_objects); + /* Fill it in */ + intern_rec(&obj); + intern_add_to_heap(whsize); + /* Free internal data structures */ + if (intern_obj_table != NULL) caml_stat_free(intern_obj_table); + return obj; +} + +CAMLexport value caml_input_value_from_malloc(char * data, intnat ofs) +{ + uint32 magic; + mlsize_t block_len; + value obj; + + intern_input = (unsigned char *) data; + intern_src = intern_input + ofs; + intern_input_malloced = 1; + magic = read32u(); + if (magic != Intext_magic_number) + caml_failwith("input_value_from_malloc: bad object"); + block_len = read32u(); + obj = input_val_from_block(); + /* Free the input */ + caml_stat_free(intern_input); + return obj; +} + +CAMLexport value caml_input_value_from_block(char * data, intnat len) +{ + uint32 magic; + mlsize_t block_len; + value obj; + + intern_input = (unsigned char *) data; + intern_src = intern_input; + intern_input_malloced = 0; + magic = read32u(); + if (magic != Intext_magic_number) + caml_failwith("input_value_from_block: bad object"); + block_len = read32u(); + if (5*4 + block_len > len) + caml_failwith("input_value_from_block: bad block length"); + obj = input_val_from_block(); + return obj; +} + +CAMLprim value caml_marshal_data_size(value buff, value ofs) +{ + uint32 magic; + mlsize_t block_len; + + intern_src = &Byte_u(buff, Long_val(ofs)); + intern_input_malloced = 0; + magic = read32u(); + if (magic != Intext_magic_number){ + caml_failwith("Marshal.data_size: bad object"); + } + block_len = read32u(); + return Val_long(block_len); +} + +/* Return an MD5 checksum of the code area */ + +#ifdef NATIVE_CODE + +#include "md5.h" + +unsigned char * caml_code_checksum(void) +{ + static unsigned char checksum[16]; + static int checksum_computed = 0; + + if (! checksum_computed) { + struct MD5Context ctx; + caml_MD5Init(&ctx); + caml_MD5Update(&ctx, + (unsigned char *) caml_code_area_start, + caml_code_area_end - caml_code_area_start); + caml_MD5Final(checksum, &ctx); + checksum_computed = 1; + } + return checksum; +} + +#else + +#include "fix_code.h" + +unsigned char * caml_code_checksum(void) +{ + return caml_code_md5; +} + +#endif + +/* Functions for writing user-defined marshallers */ + +CAMLexport int caml_deserialize_uint_1(void) +{ + return read8u(); +} + +CAMLexport int caml_deserialize_sint_1(void) +{ + return read8s(); +} + +CAMLexport int caml_deserialize_uint_2(void) +{ + return read16u(); +} + +CAMLexport int caml_deserialize_sint_2(void) +{ + return read16s(); +} + +CAMLexport uint32 caml_deserialize_uint_4(void) +{ + return read32u(); +} + +CAMLexport int32 caml_deserialize_sint_4(void) +{ + return read32s(); +} + +CAMLexport uint64 caml_deserialize_uint_8(void) +{ + uint64 i; + caml_deserialize_block_8(&i, 1); + return i; +} + +CAMLexport int64 caml_deserialize_sint_8(void) +{ + int64 i; + caml_deserialize_block_8(&i, 1); + return i; +} + +CAMLexport float caml_deserialize_float_4(void) +{ + float f; + caml_deserialize_block_4(&f, 1); + return f; +} + +CAMLexport double caml_deserialize_float_8(void) +{ + double f; + caml_deserialize_block_float_8(&f, 1); + return f; +} + +CAMLexport void caml_deserialize_block_1(void * data, intnat len) +{ + memmove(data, intern_src, len); + intern_src += len; +} + +CAMLexport void caml_deserialize_block_2(void * data, intnat len) +{ +#ifndef ARCH_BIG_ENDIAN + unsigned char * p, * q; + for (p = intern_src, q = data; len > 0; len--, p += 2, q += 2) + Reverse_16(q, p); + intern_src = p; +#else + memmove(data, intern_src, len * 2); + intern_src += len * 2; +#endif +} + +CAMLexport void caml_deserialize_block_4(void * data, intnat len) +{ +#ifndef ARCH_BIG_ENDIAN + unsigned char * p, * q; + for (p = intern_src, q = data; len > 0; len--, p += 4, q += 4) + Reverse_32(q, p); + intern_src = p; +#else + memmove(data, intern_src, len * 4); + intern_src += len * 4; +#endif +} + +CAMLexport void caml_deserialize_block_8(void * data, intnat len) +{ +#ifndef ARCH_BIG_ENDIAN + unsigned char * p, * q; + for (p = intern_src, q = data; len > 0; len--, p += 8, q += 8) + Reverse_64(q, p); + intern_src = p; +#else + memmove(data, intern_src, len * 8); + intern_src += len * 8; +#endif +} + +CAMLexport void caml_deserialize_block_float_8(void * data, intnat len) +{ +#if ARCH_FLOAT_ENDIANNESS == 0x01234567 + memmove(data, intern_src, len * 8); + intern_src += len * 8; +#elif ARCH_FLOAT_ENDIANNESS == 0x76543210 + unsigned char * p, * q; + for (p = intern_src, q = data; len > 0; len--, p += 8, q += 8) + Reverse_64(q, p); + intern_src = p; +#else + unsigned char * p, * q; + for (p = intern_src, q = data; len > 0; len--, p += 8, q += 8) + Permute_64(q, ARCH_FLOAT_ENDIANNESS, p, 0x01234567); + intern_src = p; +#endif +} + +CAMLexport void caml_deserialize_error(char * msg) +{ + intern_cleanup(); + caml_failwith(msg); +} diff --git a/byterun/interp.c b/byterun/interp.c new file mode 100644 index 0000000..a01bce8 --- /dev/null +++ b/byterun/interp.c @@ -0,0 +1,1147 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: interp.c,v 1.97 2008-08-01 11:52:31 xleroy Exp $ */ + +/* The bytecode interpreter */ +#include +#include "alloc.h" +#include "backtrace.h" +#include "callback.h" +#include "debugger.h" +#include "fail.h" +#include "fix_code.h" +#include "instrtrace.h" +#include "instruct.h" +#include "interp.h" +#include "major_gc.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "prims.h" +#include "signals.h" +#include "stacks.h" + +/* Registers for the abstract machine: + pc the code pointer + sp the stack pointer (grows downward) + accu the accumulator + env heap-allocated environment + caml_trapsp pointer to the current trap frame + extra_args number of extra arguments provided by the caller + +sp is a local copy of the global variable caml_extern_sp. */ + +/* Instruction decoding */ + +#ifdef THREADED_CODE +# define Instruct(name) lbl_##name +# if defined(ARCH_SIXTYFOUR) && !defined(ARCH_CODE32) +# define Jumptbl_base ((char *) &&lbl_ACC0) +# else +# define Jumptbl_base ((char *) 0) +# define jumptbl_base ((char *) 0) +# endif +# ifdef DEBUG +# define Next goto next_instr +# else +# define Next goto *(void *)(jumptbl_base + *pc++) +# endif +#else +# define Instruct(name) case name +# define Next break +#endif + +/* GC interface */ + +#define Setup_for_gc \ + { sp -= 2; sp[0] = accu; sp[1] = env; caml_extern_sp = sp; } +#define Restore_after_gc \ + { accu = sp[0]; env = sp[1]; sp += 2; } +#define Setup_for_c_call \ + { saved_pc = pc; *--sp = env; caml_extern_sp = sp; } +#define Restore_after_c_call \ + { sp = caml_extern_sp; env = *sp++; saved_pc = NULL; } + +/* An event frame must look like accu + a C_CALL frame + a RETURN 1 frame */ +#define Setup_for_event \ + { sp -= 6; \ + sp[0] = accu; /* accu */ \ + sp[1] = Val_unit; /* C_CALL frame: dummy environment */ \ + sp[2] = Val_unit; /* RETURN frame: dummy local 0 */ \ + sp[3] = (value) pc; /* RETURN frame: saved return address */ \ + sp[4] = env; /* RETURN frame: saved environment */ \ + sp[5] = Val_long(extra_args); /* RETURN frame: saved extra args */ \ + caml_extern_sp = sp; } +#define Restore_after_event \ + { sp = caml_extern_sp; accu = sp[0]; \ + pc = (code_t) sp[3]; env = sp[4]; extra_args = Long_val(sp[5]); \ + sp += 6; } + +/* Debugger interface */ + +#define Setup_for_debugger \ + { sp -= 4; \ + sp[0] = accu; sp[1] = (value)(pc - 1); \ + sp[2] = env; sp[3] = Val_long(extra_args); \ + caml_extern_sp = sp; } +#define Restore_after_debugger { sp += 4; } + +#ifdef THREADED_CODE +#define Restart_curr_instr \ + goto *(jumptable[caml_saved_code[pc - 1 - caml_start_code]]) +#else +#define Restart_curr_instr \ + curr_instr = caml_saved_code[pc - 1 - caml_start_code]; \ + goto dispatch_instr +#endif + +/* Register optimization. + Some compilers underestimate the use of the local variables representing + the abstract machine registers, and don't put them in hardware registers, + which slows down the interpreter considerably. + For GCC, I have hand-assigned hardware registers for several architectures. +*/ + +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(DEBUG) +#ifdef __mips__ +#define PC_REG asm("$16") +#define SP_REG asm("$17") +#define ACCU_REG asm("$18") +#endif +#ifdef __sparc__ +#define PC_REG asm("%l0") +#define SP_REG asm("%l1") +#define ACCU_REG asm("%l2") +#endif +#ifdef __alpha__ +#ifdef __CRAY__ +#define PC_REG asm("r9") +#define SP_REG asm("r10") +#define ACCU_REG asm("r11") +#define JUMPTBL_BASE_REG asm("r12") +#else +#define PC_REG asm("$9") +#define SP_REG asm("$10") +#define ACCU_REG asm("$11") +#define JUMPTBL_BASE_REG asm("$12") +#endif +#endif +#ifdef __i386__ +#define PC_REG asm("%esi") +#define SP_REG asm("%edi") +#define ACCU_REG +#endif +#if defined(__ppc__) || defined(__ppc64__) +#define PC_REG asm("26") +#define SP_REG asm("27") +#define ACCU_REG asm("28") +#endif +#ifdef __hppa__ +#define PC_REG asm("%r18") +#define SP_REG asm("%r17") +#define ACCU_REG asm("%r16") +#endif +#ifdef __mc68000__ +#define PC_REG asm("a5") +#define SP_REG asm("a4") +#define ACCU_REG asm("d7") +#endif +#ifdef __arm__ +#define PC_REG asm("r9") +#define SP_REG asm("r8") +#define ACCU_REG asm("r7") +#endif +#ifdef __ia64__ +#define PC_REG asm("36") +#define SP_REG asm("37") +#define ACCU_REG asm("38") +#define JUMPTBL_BASE_REG asm("39") +#endif +#ifdef __x86_64__ +#define PC_REG asm("%r15") +#define SP_REG asm("%r14") +#define ACCU_REG asm("%r13") +#endif +#endif + +/* Division and modulus madness */ + +#ifdef NONSTANDARD_DIV_MOD +extern intnat caml_safe_div(intnat p, intnat q); +extern intnat caml_safe_mod(intnat p, intnat q); +#endif + + +#ifdef DEBUG +static intnat caml_bcodcount; +#endif + +/* The interpreter itself */ + +value caml_interprete(code_t prog, asize_t prog_size) +{ +#ifdef PC_REG + register code_t pc PC_REG; + register value * sp SP_REG; + register value accu ACCU_REG; +#else + register code_t pc; + register value * sp; + register value accu; +#endif +#if defined(THREADED_CODE) && defined(ARCH_SIXTYFOUR) && !defined(ARCH_CODE32) +#ifdef JUMPTBL_BASE_REG + register char * jumptbl_base JUMPTBL_BASE_REG; +#else + register char * jumptbl_base; +#endif +#endif + value env; + intnat extra_args; + struct longjmp_buffer * initial_external_raise; + int initial_sp_offset; + /* volatile ensures that initial_local_roots and saved_pc + will keep correct value across longjmp */ + struct caml__roots_block * volatile initial_local_roots; + volatile code_t saved_pc = NULL; + struct longjmp_buffer raise_buf; + value * modify_dest, modify_newval; +#ifndef THREADED_CODE + opcode_t curr_instr; +#endif + +#ifdef THREADED_CODE + static void * jumptable[] = { +# include "jumptbl.h" + }; +#endif + + if (prog == NULL) { /* Interpreter is initializing */ +#ifdef THREADED_CODE + caml_instr_table = (char **) jumptable; + caml_instr_base = Jumptbl_base; +#endif + return Val_unit; + } + +#if defined(THREADED_CODE) && defined(ARCH_SIXTYFOUR) && !defined(ARCH_CODE32) + jumptbl_base = Jumptbl_base; +#endif + initial_local_roots = caml_local_roots; + initial_sp_offset = (char *) caml_stack_high - (char *) caml_extern_sp; + initial_external_raise = caml_external_raise; + caml_callback_depth++; + saved_pc = NULL; + + if (sigsetjmp(raise_buf.buf, 0)) { + caml_local_roots = initial_local_roots; + sp = caml_extern_sp; + accu = caml_exn_bucket; + pc = saved_pc; saved_pc = NULL; + if (pc != NULL) pc += 2; + /* +2 adjustement for the sole purpose of backtraces */ + goto raise_exception; + } + caml_external_raise = &raise_buf; + + sp = caml_extern_sp; + pc = prog; + extra_args = 0; + env = Atom(0); + accu = Val_int(0); + +#ifdef THREADED_CODE +#ifdef DEBUG + next_instr: + if (caml_icount-- == 0) caml_stop_here (); + Assert(sp >= caml_stack_low); + Assert(sp <= caml_stack_high); +#endif + goto *(void *)(jumptbl_base + *pc++); /* Jump to the first instruction */ +#else + while(1) { +#ifdef DEBUG + caml_bcodcount++; + if (caml_icount-- == 0) caml_stop_here (); + if (caml_trace_flag>1) printf("\n##%ld\n", caml_bcodcount); + if (caml_trace_flag) caml_disasm_instr(pc); + if (caml_trace_flag>1) { + printf("env="); + caml_trace_value_file(env,prog,prog_size,stdout); + putchar('\n'); + caml_trace_accu_sp_file(accu,sp,prog,prog_size,stdout); + fflush(stdout); + }; + Assert(sp >= caml_stack_low); + Assert(sp <= caml_stack_high); +#endif + curr_instr = *pc++; + + dispatch_instr: + switch(curr_instr) { +#endif + +/* Basic stack operations */ + + Instruct(ACC0): + accu = sp[0]; Next; + Instruct(ACC1): + accu = sp[1]; Next; + Instruct(ACC2): + accu = sp[2]; Next; + Instruct(ACC3): + accu = sp[3]; Next; + Instruct(ACC4): + accu = sp[4]; Next; + Instruct(ACC5): + accu = sp[5]; Next; + Instruct(ACC6): + accu = sp[6]; Next; + Instruct(ACC7): + accu = sp[7]; Next; + + Instruct(PUSH): Instruct(PUSHACC0): + *--sp = accu; Next; + Instruct(PUSHACC1): + *--sp = accu; accu = sp[1]; Next; + Instruct(PUSHACC2): + *--sp = accu; accu = sp[2]; Next; + Instruct(PUSHACC3): + *--sp = accu; accu = sp[3]; Next; + Instruct(PUSHACC4): + *--sp = accu; accu = sp[4]; Next; + Instruct(PUSHACC5): + *--sp = accu; accu = sp[5]; Next; + Instruct(PUSHACC6): + *--sp = accu; accu = sp[6]; Next; + Instruct(PUSHACC7): + *--sp = accu; accu = sp[7]; Next; + + Instruct(PUSHACC): + *--sp = accu; + /* Fallthrough */ + Instruct(ACC): + accu = sp[*pc++]; + Next; + + Instruct(POP): + sp += *pc++; + Next; + Instruct(ASSIGN): + sp[*pc++] = accu; + accu = Val_unit; + Next; + +/* Access in heap-allocated environment */ + + Instruct(ENVACC1): + accu = Field(env, 1); Next; + Instruct(ENVACC2): + accu = Field(env, 2); Next; + Instruct(ENVACC3): + accu = Field(env, 3); Next; + Instruct(ENVACC4): + accu = Field(env, 4); Next; + + Instruct(PUSHENVACC1): + *--sp = accu; accu = Field(env, 1); Next; + Instruct(PUSHENVACC2): + *--sp = accu; accu = Field(env, 2); Next; + Instruct(PUSHENVACC3): + *--sp = accu; accu = Field(env, 3); Next; + Instruct(PUSHENVACC4): + *--sp = accu; accu = Field(env, 4); Next; + + Instruct(PUSHENVACC): + *--sp = accu; + /* Fallthrough */ + Instruct(ENVACC): + accu = Field(env, *pc++); + Next; + +/* Function application */ + + Instruct(PUSH_RETADDR): { + sp -= 3; + sp[0] = (value) (pc + *pc); + sp[1] = env; + sp[2] = Val_long(extra_args); + pc++; + Next; + } + Instruct(APPLY): { + extra_args = *pc - 1; + pc = Code_val(accu); + env = accu; + goto check_stacks; + } + Instruct(APPLY1): { + value arg1 = sp[0]; + sp -= 3; + sp[0] = arg1; + sp[1] = (value)pc; + sp[2] = env; + sp[3] = Val_long(extra_args); + pc = Code_val(accu); + env = accu; + extra_args = 0; + goto check_stacks; + } + Instruct(APPLY2): { + value arg1 = sp[0]; + value arg2 = sp[1]; + sp -= 3; + sp[0] = arg1; + sp[1] = arg2; + sp[2] = (value)pc; + sp[3] = env; + sp[4] = Val_long(extra_args); + pc = Code_val(accu); + env = accu; + extra_args = 1; + goto check_stacks; + } + Instruct(APPLY3): { + value arg1 = sp[0]; + value arg2 = sp[1]; + value arg3 = sp[2]; + sp -= 3; + sp[0] = arg1; + sp[1] = arg2; + sp[2] = arg3; + sp[3] = (value)pc; + sp[4] = env; + sp[5] = Val_long(extra_args); + pc = Code_val(accu); + env = accu; + extra_args = 2; + goto check_stacks; + } + + Instruct(APPTERM): { + int nargs = *pc++; + int slotsize = *pc; + value * newsp; + int i; + /* Slide the nargs bottom words of the current frame to the top + of the frame, and discard the remainder of the frame */ + newsp = sp + slotsize - nargs; + for (i = nargs - 1; i >= 0; i--) newsp[i] = sp[i]; + sp = newsp; + pc = Code_val(accu); + env = accu; + extra_args += nargs - 1; + goto check_stacks; + } + Instruct(APPTERM1): { + value arg1 = sp[0]; + sp = sp + *pc - 1; + sp[0] = arg1; + pc = Code_val(accu); + env = accu; + goto check_stacks; + } + Instruct(APPTERM2): { + value arg1 = sp[0]; + value arg2 = sp[1]; + sp = sp + *pc - 2; + sp[0] = arg1; + sp[1] = arg2; + pc = Code_val(accu); + env = accu; + extra_args += 1; + goto check_stacks; + } + Instruct(APPTERM3): { + value arg1 = sp[0]; + value arg2 = sp[1]; + value arg3 = sp[2]; + sp = sp + *pc - 3; + sp[0] = arg1; + sp[1] = arg2; + sp[2] = arg3; + pc = Code_val(accu); + env = accu; + extra_args += 2; + goto check_stacks; + } + + Instruct(RETURN): { + sp += *pc++; + if (extra_args > 0) { + extra_args--; + pc = Code_val(accu); + env = accu; + } else { + pc = (code_t)(sp[0]); + env = sp[1]; + extra_args = Long_val(sp[2]); + sp += 3; + } + Next; + } + + Instruct(RESTART): { + int num_args = Wosize_val(env) - 2; + int i; + sp -= num_args; + for (i = 0; i < num_args; i++) sp[i] = Field(env, i + 2); + env = Field(env, 1); + extra_args += num_args; + Next; + } + + Instruct(GRAB): { + int required = *pc++; + if (extra_args >= required) { + extra_args -= required; + } else { + mlsize_t num_args, i; + num_args = 1 + extra_args; /* arg1 + extra args */ + Alloc_small(accu, num_args + 2, Closure_tag); + Field(accu, 1) = env; + for (i = 0; i < num_args; i++) Field(accu, i + 2) = sp[i]; + Code_val(accu) = pc - 3; /* Point to the preceding RESTART instr. */ + sp += num_args; + pc = (code_t)(sp[0]); + env = sp[1]; + extra_args = Long_val(sp[2]); + sp += 3; + } + Next; + } + + Instruct(CLOSURE): { + int nvars = *pc++; + int i; + if (nvars > 0) *--sp = accu; + Alloc_small(accu, 1 + nvars, Closure_tag); + Code_val(accu) = pc + *pc; + pc++; + for (i = 0; i < nvars; i++) Field(accu, i + 1) = sp[i]; + sp += nvars; + Next; + } + + Instruct(CLOSUREREC): { + int nfuncs = *pc++; + int nvars = *pc++; + int i; + value * p; + if (nvars > 0) *--sp = accu; + Alloc_small(accu, nfuncs * 2 - 1 + nvars, Closure_tag); + p = &Field(accu, nfuncs * 2 - 1); + for (i = 0; i < nvars; i++) { + *p++ = sp[i]; + } + sp += nvars; + p = &Field(accu, 0); + *p = (value) (pc + pc[0]); + *--sp = accu; + p++; + for (i = 1; i < nfuncs; i++) { + *p = Make_header(i * 2, Infix_tag, Caml_white); /* color irrelevant. */ + p++; + *p = (value) (pc + pc[i]); + *--sp = (value) p; + p++; + } + pc += nfuncs; + Next; + } + + Instruct(PUSHOFFSETCLOSURE): + *--sp = accu; /* fallthrough */ + Instruct(OFFSETCLOSURE): + accu = env + *pc++ * sizeof(value); Next; + + Instruct(PUSHOFFSETCLOSUREM2): + *--sp = accu; /* fallthrough */ + Instruct(OFFSETCLOSUREM2): + accu = env - 2 * sizeof(value); Next; + Instruct(PUSHOFFSETCLOSURE0): + *--sp = accu; /* fallthrough */ + Instruct(OFFSETCLOSURE0): + accu = env; Next; + Instruct(PUSHOFFSETCLOSURE2): + *--sp = accu; /* fallthrough */ + Instruct(OFFSETCLOSURE2): + accu = env + 2 * sizeof(value); Next; + + +/* Access to global variables */ + + Instruct(PUSHGETGLOBAL): + *--sp = accu; + /* Fallthrough */ + Instruct(GETGLOBAL): + accu = Field(caml_global_data, *pc); + pc++; + Next; + + Instruct(PUSHGETGLOBALFIELD): + *--sp = accu; + /* Fallthrough */ + Instruct(GETGLOBALFIELD): { + accu = Field(caml_global_data, *pc); + pc++; + accu = Field(accu, *pc); + pc++; + Next; + } + + Instruct(SETGLOBAL): + caml_modify(&Field(caml_global_data, *pc), accu); + accu = Val_unit; + pc++; + Next; + +/* Allocation of blocks */ + + Instruct(PUSHATOM0): + *--sp = accu; + /* Fallthrough */ + Instruct(ATOM0): + accu = Atom(0); Next; + + Instruct(PUSHATOM): + *--sp = accu; + /* Fallthrough */ + Instruct(ATOM): + accu = Atom(*pc++); Next; + + Instruct(MAKEBLOCK): { + mlsize_t wosize = *pc++; + tag_t tag = *pc++; + mlsize_t i; + value block; + if (wosize <= Max_young_wosize) { + Alloc_small(block, wosize, tag); + Field(block, 0) = accu; + for (i = 1; i < wosize; i++) Field(block, i) = *sp++; + } else { + block = caml_alloc_shr(wosize, tag); + caml_initialize(&Field(block, 0), accu); + for (i = 1; i < wosize; i++) caml_initialize(&Field(block, i), *sp++); + } + accu = block; + Next; + } + Instruct(MAKEBLOCK1): { + tag_t tag = *pc++; + value block; + Alloc_small(block, 1, tag); + Field(block, 0) = accu; + accu = block; + Next; + } + Instruct(MAKEBLOCK2): { + tag_t tag = *pc++; + value block; + Alloc_small(block, 2, tag); + Field(block, 0) = accu; + Field(block, 1) = sp[0]; + sp += 1; + accu = block; + Next; + } + Instruct(MAKEBLOCK3): { + tag_t tag = *pc++; + value block; + Alloc_small(block, 3, tag); + Field(block, 0) = accu; + Field(block, 1) = sp[0]; + Field(block, 2) = sp[1]; + sp += 2; + accu = block; + Next; + } + Instruct(MAKEFLOATBLOCK): { + mlsize_t size = *pc++; + mlsize_t i; + value block; + if (size <= Max_young_wosize / Double_wosize) { + Alloc_small(block, size * Double_wosize, Double_array_tag); + } else { + block = caml_alloc_shr(size * Double_wosize, Double_array_tag); + } + Store_double_field(block, 0, Double_val(accu)); + for (i = 1; i < size; i++){ + Store_double_field(block, i, Double_val(*sp)); + ++ sp; + } + accu = block; + Next; + } + +/* Access to components of blocks */ + + Instruct(GETFIELD0): + accu = Field(accu, 0); Next; + Instruct(GETFIELD1): + accu = Field(accu, 1); Next; + Instruct(GETFIELD2): + accu = Field(accu, 2); Next; + Instruct(GETFIELD3): + accu = Field(accu, 3); Next; + Instruct(GETFIELD): + accu = Field(accu, *pc); pc++; Next; + Instruct(GETFLOATFIELD): { + double d = Double_field(accu, *pc); + Alloc_small(accu, Double_wosize, Double_tag); + Store_double_val(accu, d); + pc++; + Next; + } + + Instruct(SETFIELD0): + modify_dest = &Field(accu, 0); + modify_newval = *sp++; + modify: + Modify(modify_dest, modify_newval); + accu = Val_unit; + Next; + Instruct(SETFIELD1): + modify_dest = &Field(accu, 1); + modify_newval = *sp++; + goto modify; + Instruct(SETFIELD2): + modify_dest = &Field(accu, 2); + modify_newval = *sp++; + goto modify; + Instruct(SETFIELD3): + modify_dest = &Field(accu, 3); + modify_newval = *sp++; + goto modify; + Instruct(SETFIELD): + modify_dest = &Field(accu, *pc); + pc++; + modify_newval = *sp++; + goto modify; + Instruct(SETFLOATFIELD): + Store_double_field(accu, *pc, Double_val(*sp)); + accu = Val_unit; + sp++; + pc++; + Next; + +/* Array operations */ + + Instruct(VECTLENGTH): { + mlsize_t size = Wosize_val(accu); + if (Tag_val(accu) == Double_array_tag) size = size / Double_wosize; + accu = Val_long(size); + Next; + } + Instruct(GETVECTITEM): + accu = Field(accu, Long_val(sp[0])); + sp += 1; + Next; + Instruct(SETVECTITEM): + modify_dest = &Field(accu, Long_val(sp[0])); + modify_newval = sp[1]; + sp += 2; + goto modify; + +/* String operations */ + + Instruct(GETSTRINGCHAR): + accu = Val_int(Byte_u(accu, Long_val(sp[0]))); + sp += 1; + Next; + Instruct(SETSTRINGCHAR): + Byte_u(accu, Long_val(sp[0])) = Int_val(sp[1]); + sp += 2; + accu = Val_unit; + Next; + +/* Branches and conditional branches */ + + Instruct(BRANCH): + pc += *pc; + Next; + Instruct(BRANCHIF): + if (accu != Val_false) pc += *pc; else pc++; + Next; + Instruct(BRANCHIFNOT): + if (accu == Val_false) pc += *pc; else pc++; + Next; + Instruct(SWITCH): { + uint32 sizes = *pc++; + if (Is_block(accu)) { + intnat index = Tag_val(accu); + Assert ((uintnat) index < (sizes >> 16)); + pc += pc[(sizes & 0xFFFF) + index]; + } else { + intnat index = Long_val(accu); + Assert ((uintnat) index < (sizes & 0xFFFF)) ; + pc += pc[index]; + } + Next; + } + Instruct(BOOLNOT): + accu = Val_not(accu); + Next; + +/* Exceptions */ + + Instruct(PUSHTRAP): + sp -= 4; + Trap_pc(sp) = pc + *pc; + Trap_link(sp) = caml_trapsp; + sp[2] = env; + sp[3] = Val_long(extra_args); + caml_trapsp = sp; + pc++; + Next; + + Instruct(POPTRAP): + if (caml_something_to_do) { + /* We must check here so that if a signal is pending and its + handler triggers an exception, the exception is trapped + by the current try...with, not the enclosing one. */ + pc--; /* restart the POPTRAP after processing the signal */ + goto process_signal; + } + caml_trapsp = Trap_link(sp); + sp += 4; + Next; + + Instruct(RAISE): + raise_exception: + if (caml_trapsp >= caml_trap_barrier) caml_debugger(TRAP_BARRIER); + if (caml_backtrace_active) caml_stash_backtrace(accu, pc, sp); + if ((char *) caml_trapsp + >= (char *) caml_stack_high - initial_sp_offset) { + caml_external_raise = initial_external_raise; + caml_extern_sp = (value *) ((char *) caml_stack_high + - initial_sp_offset); + caml_callback_depth--; + return Make_exception_result(accu); + } + sp = caml_trapsp; + pc = Trap_pc(sp); + caml_trapsp = Trap_link(sp); + env = sp[2]; + extra_args = Long_val(sp[3]); + sp += 4; + Next; + +/* Stack checks */ + + check_stacks: + if (sp < caml_stack_threshold) { + caml_extern_sp = sp; + caml_realloc_stack(Stack_threshold / sizeof(value)); + sp = caml_extern_sp; + } + /* Fall through CHECK_SIGNALS */ + +/* Signal handling */ + + Instruct(CHECK_SIGNALS): /* accu not preserved */ + if (caml_something_to_do) goto process_signal; + Next; + + process_signal: + caml_something_to_do = 0; + Setup_for_event; + caml_process_event(); + Restore_after_event; + Next; + +/* Calling C functions */ + + Instruct(C_CALL1): + Setup_for_c_call; + accu = Primitive(*pc)(accu); + Restore_after_c_call; + pc++; + Next; + Instruct(C_CALL2): + Setup_for_c_call; + accu = Primitive(*pc)(accu, sp[1]); + Restore_after_c_call; + sp += 1; + pc++; + Next; + Instruct(C_CALL3): + Setup_for_c_call; + accu = Primitive(*pc)(accu, sp[1], sp[2]); + Restore_after_c_call; + sp += 2; + pc++; + Next; + Instruct(C_CALL4): + Setup_for_c_call; + accu = Primitive(*pc)(accu, sp[1], sp[2], sp[3]); + Restore_after_c_call; + sp += 3; + pc++; + Next; + Instruct(C_CALL5): + Setup_for_c_call; + accu = Primitive(*pc)(accu, sp[1], sp[2], sp[3], sp[4]); + Restore_after_c_call; + sp += 4; + pc++; + Next; + Instruct(C_CALLN): { + int nargs = *pc++; + *--sp = accu; + Setup_for_c_call; + accu = Primitive(*pc)(sp + 1, nargs); + Restore_after_c_call; + sp += nargs; + pc++; + Next; + } + +/* Integer constants */ + + Instruct(CONST0): + accu = Val_int(0); Next; + Instruct(CONST1): + accu = Val_int(1); Next; + Instruct(CONST2): + accu = Val_int(2); Next; + Instruct(CONST3): + accu = Val_int(3); Next; + + Instruct(PUSHCONST0): + *--sp = accu; accu = Val_int(0); Next; + Instruct(PUSHCONST1): + *--sp = accu; accu = Val_int(1); Next; + Instruct(PUSHCONST2): + *--sp = accu; accu = Val_int(2); Next; + Instruct(PUSHCONST3): + *--sp = accu; accu = Val_int(3); Next; + + Instruct(PUSHCONSTINT): + *--sp = accu; + /* Fallthrough */ + Instruct(CONSTINT): + accu = Val_int(*pc); + pc++; + Next; + +/* Integer arithmetic */ + + Instruct(NEGINT): + accu = (value)(2 - (intnat)accu); Next; + Instruct(ADDINT): + accu = (value)((intnat) accu + (intnat) *sp++ - 1); Next; + Instruct(SUBINT): + accu = (value)((intnat) accu - (intnat) *sp++ + 1); Next; + Instruct(MULINT): + accu = Val_long(Long_val(accu) * Long_val(*sp++)); Next; + + Instruct(DIVINT): { + intnat divisor = Long_val(*sp++); + if (divisor == 0) { Setup_for_c_call; caml_raise_zero_divide(); } +#ifdef NONSTANDARD_DIV_MOD + accu = Val_long(caml_safe_div(Long_val(accu), divisor)); +#else + accu = Val_long(Long_val(accu) / divisor); +#endif + Next; + } + Instruct(MODINT): { + intnat divisor = Long_val(*sp++); + if (divisor == 0) { Setup_for_c_call; caml_raise_zero_divide(); } +#ifdef NONSTANDARD_DIV_MOD + accu = Val_long(caml_safe_mod(Long_val(accu), divisor)); +#else + accu = Val_long(Long_val(accu) % divisor); +#endif + Next; + } + Instruct(ANDINT): + accu = (value)((intnat) accu & (intnat) *sp++); Next; + Instruct(ORINT): + accu = (value)((intnat) accu | (intnat) *sp++); Next; + Instruct(XORINT): + accu = (value)(((intnat) accu ^ (intnat) *sp++) | 1); Next; + Instruct(LSLINT): + accu = (value)((((intnat) accu - 1) << Long_val(*sp++)) + 1); Next; + Instruct(LSRINT): + accu = (value)((((uintnat) accu - 1) >> Long_val(*sp++)) | 1); + Next; + Instruct(ASRINT): + accu = (value)((((intnat) accu - 1) >> Long_val(*sp++)) | 1); Next; + +#define Integer_comparison(typ,opname,tst) \ + Instruct(opname): \ + accu = Val_int((typ) accu tst (typ) *sp++); Next; + + Integer_comparison(intnat,EQ, ==) + Integer_comparison(intnat,NEQ, !=) + Integer_comparison(intnat,LTINT, <) + Integer_comparison(intnat,LEINT, <=) + Integer_comparison(intnat,GTINT, >) + Integer_comparison(intnat,GEINT, >=) + Integer_comparison(uintnat,ULTINT, <) + Integer_comparison(uintnat,UGEINT, >=) + +#define Integer_branch_comparison(typ,opname,tst,debug) \ + Instruct(opname): \ + if ( *pc++ tst (typ) Long_val(accu)) { \ + pc += *pc ; \ + } else { \ + pc++ ; \ + } ; Next; + + Integer_branch_comparison(intnat,BEQ, ==, "==") + Integer_branch_comparison(intnat,BNEQ, !=, "!=") + Integer_branch_comparison(intnat,BLTINT, <, "<") + Integer_branch_comparison(intnat,BLEINT, <=, "<=") + Integer_branch_comparison(intnat,BGTINT, >, ">") + Integer_branch_comparison(intnat,BGEINT, >=, ">=") + Integer_branch_comparison(uintnat,BULTINT, <, "<") + Integer_branch_comparison(uintnat,BUGEINT, >=, ">=") + + Instruct(OFFSETINT): + accu += *pc << 1; + pc++; + Next; + Instruct(OFFSETREF): + Field(accu, 0) += *pc << 1; + accu = Val_unit; + pc++; + Next; + Instruct(ISINT): + accu = Val_long(accu & 1); + Next; + +/* Object-oriented operations */ + +#define Lookup(obj, lab) Field (Field (obj, 0), Int_val(lab)) + + /* please don't forget to keep below code in sync with the + functions caml_cache_public_method and + caml_cache_public_method2 in obj.c */ + + Instruct(GETMETHOD): + accu = Lookup(sp[0], accu); + Next; + +#define CAML_METHOD_CACHE +#ifdef CAML_METHOD_CACHE + Instruct(GETPUBMET): { + /* accu == object, pc[0] == tag, pc[1] == cache */ + value meths = Field (accu, 0); + value ofs; +#ifdef CAML_TEST_CACHE + static int calls = 0, hits = 0; + if (calls >= 10000000) { + fprintf(stderr, "cache hit = %d%%\n", hits / 100000); + calls = 0; hits = 0; + } + calls++; +#endif + *--sp = accu; + accu = Val_int(*pc++); + ofs = *pc & Field(meths,1); + if (*(value*)(((char*)&Field(meths,3)) + ofs) == accu) { +#ifdef CAML_TEST_CACHE + hits++; +#endif + accu = *(value*)(((char*)&Field(meths,2)) + ofs); + } + else + { + int li = 3, hi = Field(meths,0), mi; + while (li < hi) { + mi = ((li+hi) >> 1) | 1; + if (accu < Field(meths,mi)) hi = mi-2; + else li = mi; + } + *pc = (li-3)*sizeof(value); + accu = Field (meths, li-1); + } + pc++; + Next; + } +#else + Instruct(GETPUBMET): + *--sp = accu; + accu = Val_int(*pc); + pc += 2; + /* Fallthrough */ +#endif + Instruct(GETDYNMET): { + /* accu == tag, sp[0] == object, *pc == cache */ + value meths = Field (sp[0], 0); + int li = 3, hi = Field(meths,0), mi; + while (li < hi) { + mi = ((li+hi) >> 1) | 1; + if (accu < Field(meths,mi)) hi = mi-2; + else li = mi; + } + accu = Field (meths, li-1); + Next; + } + +/* Debugging and machine control */ + + Instruct(STOP): + caml_external_raise = initial_external_raise; + caml_extern_sp = sp; + caml_callback_depth--; + return accu; + + Instruct(EVENT): + if (--caml_event_count == 0) { + Setup_for_debugger; + caml_debugger(EVENT_COUNT); + Restore_after_debugger; + } + Restart_curr_instr; + + Instruct(BREAK): + Setup_for_debugger; + caml_debugger(BREAKPOINT); + Restore_after_debugger; + Restart_curr_instr; + +#ifndef THREADED_CODE + default: +#if _MSC_VER >= 1200 + __assume(0); +#else + caml_fatal_error_arg("Fatal error: bad opcode (%" + ARCH_INTNAT_PRINTF_FORMAT "x)\n", + (char *)(*(pc-1))); +#endif + } + } +#endif +} + +void caml_prepare_bytecode(code_t prog, asize_t prog_size) { + /* other implementations of the interpreter (such as an hypothetical + JIT translator) might want to do something with a bytecode before + running it */ + Assert(prog); + Assert(prog_size>0); + /* actually, the threading of the bytecode might be done here */ +} + +void caml_release_bytecode(code_t prog, asize_t prog_size) { + /* other implementations of the interpreter (such as an hypothetical + JIT translator) might want to know when a bytecode is removed */ + /* check that we have a program */ + Assert(prog); + Assert(prog_size>0); +} diff --git a/byterun/interp.h b/byterun/interp.h new file mode 100644 index 0000000..159b337 --- /dev/null +++ b/byterun/interp.h @@ -0,0 +1,33 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: interp.h,v 1.13 2004-04-26 14:08:22 basile Exp $ */ + +/* The bytecode interpreter */ + +#ifndef CAML_INTERP_H +#define CAML_INTERP_H + +#include "misc.h" +#include "mlvalues.h" + +/* interpret a bytecode */ +value caml_interprete (code_t prog, asize_t prog_size); + +/* tell the runtime that a bytecode program might be needed */ +void caml_prepare_bytecode(code_t prog, asize_t prog_size); + +/* tell the runtime that a bytecode program is no more needed */ +void caml_release_bytecode(code_t prog, asize_t prog_size); + +#endif /* CAML_INTERP_H */ diff --git a/byterun/intext.h b/byterun/intext.h new file mode 100644 index 0000000..8ecdf3a --- /dev/null +++ b/byterun/intext.h @@ -0,0 +1,162 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: intext.h,v 1.32 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Structured input/output */ + +#ifndef CAML_INTEXT_H +#define CAML_INTEXT_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "misc.h" +#include "mlvalues.h" + +/* */ +#include "io.h" + +/* Magic number */ + +#define Intext_magic_number 0x8495A6BE + +/* Codes for the compact format */ + +#define PREFIX_SMALL_BLOCK 0x80 +#define PREFIX_SMALL_INT 0x40 +#define PREFIX_SMALL_STRING 0x20 +#define CODE_INT8 0x0 +#define CODE_INT16 0x1 +#define CODE_INT32 0x2 +#define CODE_INT64 0x3 +#define CODE_SHARED8 0x4 +#define CODE_SHARED16 0x5 +#define CODE_SHARED32 0x6 +#define CODE_BLOCK32 0x8 +#define CODE_BLOCK64 0x13 +#define CODE_STRING8 0x9 +#define CODE_STRING32 0xA +#define CODE_DOUBLE_BIG 0xB +#define CODE_DOUBLE_LITTLE 0xC +#define CODE_DOUBLE_ARRAY8_BIG 0xD +#define CODE_DOUBLE_ARRAY8_LITTLE 0xE +#define CODE_DOUBLE_ARRAY32_BIG 0xF +#define CODE_DOUBLE_ARRAY32_LITTLE 0x7 +#define CODE_CODEPOINTER 0x10 +#define CODE_INFIXPOINTER 0x11 +#define CODE_CUSTOM 0x12 + +#if ARCH_FLOAT_ENDIANNESS == 0x76543210 +#define CODE_DOUBLE_NATIVE CODE_DOUBLE_BIG +#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_BIG +#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_BIG +#else +#define CODE_DOUBLE_NATIVE CODE_DOUBLE_LITTLE +#define CODE_DOUBLE_ARRAY8_NATIVE CODE_DOUBLE_ARRAY8_LITTLE +#define CODE_DOUBLE_ARRAY32_NATIVE CODE_DOUBLE_ARRAY32_LITTLE +#endif + +/* Size-ing data structures for extern. Chosen so that + sizeof(struct trail_block) and sizeof(struct output_block) + are slightly below 8Kb. */ + +#define ENTRIES_PER_TRAIL_BLOCK 1025 +#define SIZE_EXTERN_OUTPUT_BLOCK 8100 + +/* The entry points */ + +void caml_output_val (struct channel * chan, value v, value flags); + /* Output [v] with flags [flags] on the channel [chan]. */ + +/* */ + +CAMLextern void caml_output_value_to_malloc(value v, value flags, + /*out*/ char ** buf, + /*out*/ intnat * len); + /* Output [v] with flags [flags] to a memory buffer allocated with + malloc. On return, [*buf] points to the buffer and [*len] + contains the number of bytes in buffer. */ +CAMLextern intnat caml_output_value_to_block(value v, value flags, + char * data, intnat len); + /* Output [v] with flags [flags] to a user-provided memory buffer. + [data] points to the start of this buffer, and [len] is its size + in bytes. Return the number of bytes actually written in buffer. + Raise [Failure] if buffer is too short. */ + +/* */ +value caml_input_val (struct channel * chan); + /* Read a structured value from the channel [chan]. */ +/* */ + +CAMLextern value caml_input_val_from_string (value str, intnat ofs); + /* Read a structured value from the Caml string [str], starting + at offset [ofs]. */ +CAMLextern value caml_input_value_from_malloc(char * data, intnat ofs); + /* Read a structured value from a malloced buffer. [data] points + to the beginning of the buffer, and [ofs] is the offset of the + beginning of the externed data in this buffer. The buffer is + deallocated with [free] on return, or if an exception is raised. */ +CAMLextern value caml_input_value_from_block(char * data, intnat len); + /* Read a structured value from a user-provided buffer. [data] points + to the beginning of the externed data in this buffer, + and [len] is the length in bytes of valid data in this buffer. + The buffer is never deallocated by this routine. */ + +/* Functions for writing user-defined marshallers */ + +CAMLextern void caml_serialize_int_1(int i); +CAMLextern void caml_serialize_int_2(int i); +CAMLextern void caml_serialize_int_4(int32 i); +CAMLextern void caml_serialize_int_8(int64 i); +CAMLextern void caml_serialize_float_4(float f); +CAMLextern void caml_serialize_float_8(double f); +CAMLextern void caml_serialize_block_1(void * data, intnat len); +CAMLextern void caml_serialize_block_2(void * data, intnat len); +CAMLextern void caml_serialize_block_4(void * data, intnat len); +CAMLextern void caml_serialize_block_8(void * data, intnat len); +CAMLextern void caml_serialize_block_float_8(void * data, intnat len); + +CAMLextern int caml_deserialize_uint_1(void); +CAMLextern int caml_deserialize_sint_1(void); +CAMLextern int caml_deserialize_uint_2(void); +CAMLextern int caml_deserialize_sint_2(void); +CAMLextern uint32 caml_deserialize_uint_4(void); +CAMLextern int32 caml_deserialize_sint_4(void); +CAMLextern uint64 caml_deserialize_uint_8(void); +CAMLextern int64 caml_deserialize_sint_8(void); +CAMLextern float caml_deserialize_float_4(void); +CAMLextern double caml_deserialize_float_8(void); +CAMLextern void caml_deserialize_block_1(void * data, intnat len); +CAMLextern void caml_deserialize_block_2(void * data, intnat len); +CAMLextern void caml_deserialize_block_4(void * data, intnat len); +CAMLextern void caml_deserialize_block_8(void * data, intnat len); +CAMLextern void caml_deserialize_block_float_8(void * data, intnat len); +CAMLextern void caml_deserialize_error(char * msg); + +/* */ + +/* Auxiliary stuff for sending code pointers */ +unsigned char * caml_code_checksum (void); + +#ifndef NATIVE_CODE +#include "fix_code.h" +#define caml_code_area_start ((char *) caml_start_code) +#define caml_code_area_end ((char *) caml_start_code + caml_code_size) +#else +extern char * caml_code_area_start, * caml_code_area_end; +#endif + +/* */ + +#endif /* CAML_INTEXT_H */ diff --git a/byterun/ints.c b/byterun/ints.c new file mode 100644 index 0000000..58a56c2 --- /dev/null +++ b/byterun/ints.c @@ -0,0 +1,738 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: ints.c,v 1.51 2008-01-11 16:13:16 doligez Exp $ */ + +#include +#include +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "intext.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" + +static char * parse_sign_and_base(char * p, + /*out*/ int * base, + /*out*/ int * sign) +{ + *sign = 1; + if (*p == '-') { + *sign = -1; + p++; + } + *base = 10; + if (*p == '0') { + switch (p[1]) { + case 'x': case 'X': + *base = 16; p += 2; break; + case 'o': case 'O': + *base = 8; p += 2; break; + case 'b': case 'B': + *base = 2; p += 2; break; + } + } + return p; +} + +static int parse_digit(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + else if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + else + return -1; +} + +static intnat parse_intnat(value s, int nbits) +{ + char * p; + uintnat res, threshold; + int sign, base, d; + + p = parse_sign_and_base(String_val(s), &base, &sign); + threshold = ((uintnat) -1) / base; + d = parse_digit(*p); + if (d < 0 || d >= base) caml_failwith("int_of_string"); + for (p++, res = d; /*nothing*/; p++) { + char c = *p; + if (c == '_') continue; + d = parse_digit(c); + if (d < 0 || d >= base) break; + /* Detect overflow in multiplication base * res */ + if (res > threshold) caml_failwith("int_of_string"); + res = base * res + d; + /* Detect overflow in addition (base * res) + d */ + if (res < (uintnat) d) caml_failwith("int_of_string"); + } + if (p != String_val(s) + caml_string_length(s)){ + caml_failwith("int_of_string"); + } + if (base == 10) { + /* Signed representation expected, allow -2^(nbits-1) to 2^(nbits - 1) */ + if (res > (uintnat)1 << (nbits - 1)) + caml_failwith("int_of_string"); + } else { + /* Unsigned representation expected, allow 0 to 2^nbits - 1 + and tolerate -(2^nbits - 1) to 0 */ + if (nbits < sizeof(uintnat) * 8 && res >= (uintnat)1 << nbits) + caml_failwith("int_of_string"); + } + return sign < 0 ? -((intnat) res) : (intnat) res; +} + +#ifdef NONSTANDARD_DIV_MOD +intnat caml_safe_div(intnat p, intnat q) +{ + uintnat ap = p >= 0 ? p : -p; + uintnat aq = q >= 0 ? q : -q; + uintnat ar = ap / aq; + return (p ^ q) >= 0 ? ar : -ar; +} + +intnat caml_safe_mod(intnat p, intnat q) +{ + uintnat ap = p >= 0 ? p : -p; + uintnat aq = q >= 0 ? q : -q; + uintnat ar = ap % aq; + return p >= 0 ? ar : -ar; +} +#endif + +/* Tagged integers */ + +CAMLprim value caml_int_compare(value v1, value v2) +{ + int res = (v1 > v2) - (v1 < v2); + return Val_int(res); +} + +CAMLprim value caml_int_of_string(value s) +{ + return Val_long(parse_intnat(s, 8 * sizeof(value) - 1)); +} + +#define FORMAT_BUFFER_SIZE 32 + +static char * parse_format(value fmt, + char * suffix, + char format_string[], + char default_format_buffer[], + char *conv) +{ + int prec; + char * p; + char lastletter; + mlsize_t len, len_suffix; + + /* Copy Caml format fmt to format_string, + adding the suffix before the last letter of the format */ + len = caml_string_length(fmt); + len_suffix = strlen(suffix); + if (len + len_suffix + 1 >= FORMAT_BUFFER_SIZE) + caml_invalid_argument("format_int: format too long"); + memmove(format_string, String_val(fmt), len); + p = format_string + len - 1; + lastletter = *p; + /* Compress two-letter formats, ignoring the [lnL] annotation */ + if (p[-1] == 'l' || p[-1] == 'n' || p[-1] == 'L') p--; + memmove(p, suffix, len_suffix); p += len_suffix; + *p++ = lastletter; + *p = 0; + /* Determine space needed for result and allocate it dynamically if needed */ + prec = 22 + 5; /* 22 digits for 64-bit number in octal + 5 extra */ + for (p = String_val(fmt); *p != 0; p++) { + if (*p >= '0' && *p <= '9') { + prec = atoi(p) + 5; + break; + } + } + *conv = lastletter; + if (prec < FORMAT_BUFFER_SIZE) + return default_format_buffer; + else + return caml_stat_alloc(prec + 1); +} + +CAMLprim value caml_format_int(value fmt, value arg) +{ + char format_string[FORMAT_BUFFER_SIZE]; + char default_format_buffer[FORMAT_BUFFER_SIZE]; + char * buffer; + char conv; + value res; + + buffer = parse_format(fmt, ARCH_INTNAT_PRINTF_FORMAT, + format_string, default_format_buffer, &conv); + switch (conv) { + case 'u': case 'x': case 'X': case 'o': + sprintf(buffer, format_string, Unsigned_long_val(arg)); + break; + default: + sprintf(buffer, format_string, Long_val(arg)); + break; + } + res = caml_copy_string(buffer); + if (buffer != default_format_buffer) caml_stat_free(buffer); + return res; +} + +/* 32-bit integers */ + +static int int32_cmp(value v1, value v2) +{ + int32 i1 = Int32_val(v1); + int32 i2 = Int32_val(v2); + return (i1 > i2) - (i1 < i2); +} + +static intnat int32_hash(value v) +{ + return Int32_val(v); +} + +static void int32_serialize(value v, uintnat * wsize_32, + uintnat * wsize_64) +{ + caml_serialize_int_4(Int32_val(v)); + *wsize_32 = *wsize_64 = 4; +} + +static uintnat int32_deserialize(void * dst) +{ + *((int32 *) dst) = caml_deserialize_sint_4(); + return 4; +} + +CAMLexport struct custom_operations caml_int32_ops = { + "_i", + custom_finalize_default, + int32_cmp, + int32_hash, + int32_serialize, + int32_deserialize +}; + +CAMLexport value caml_copy_int32(int32 i) +{ + value res = caml_alloc_custom(&caml_int32_ops, 4, 0, 1); + Int32_val(res) = i; + return res; +} + +CAMLprim value caml_int32_neg(value v) +{ return caml_copy_int32(- Int32_val(v)); } + +CAMLprim value caml_int32_add(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) + Int32_val(v2)); } + +CAMLprim value caml_int32_sub(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) - Int32_val(v2)); } + +CAMLprim value caml_int32_mul(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) * Int32_val(v2)); } + +CAMLprim value caml_int32_div(value v1, value v2) +{ + int32 divisor = Int32_val(v2); + if (divisor == 0) caml_raise_zero_divide(); +#ifdef NONSTANDARD_DIV_MOD + return caml_copy_int32(caml_safe_div(Int32_val(v1), divisor)); +#else + return caml_copy_int32(Int32_val(v1) / divisor); +#endif +} + +CAMLprim value caml_int32_mod(value v1, value v2) +{ + int32 divisor = Int32_val(v2); + if (divisor == 0) caml_raise_zero_divide(); +#ifdef NONSTANDARD_DIV_MOD + return caml_copy_int32(caml_safe_mod(Int32_val(v1), divisor)); +#else + return caml_copy_int32(Int32_val(v1) % divisor); +#endif +} + +CAMLprim value caml_int32_and(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) & Int32_val(v2)); } + +CAMLprim value caml_int32_or(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) | Int32_val(v2)); } + +CAMLprim value caml_int32_xor(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) ^ Int32_val(v2)); } + +CAMLprim value caml_int32_shift_left(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) << Int_val(v2)); } + +CAMLprim value caml_int32_shift_right(value v1, value v2) +{ return caml_copy_int32(Int32_val(v1) >> Int_val(v2)); } + +CAMLprim value caml_int32_shift_right_unsigned(value v1, value v2) +{ return caml_copy_int32((uint32)Int32_val(v1) >> Int_val(v2)); } + +CAMLprim value caml_int32_of_int(value v) +{ return caml_copy_int32(Long_val(v)); } + +CAMLprim value caml_int32_to_int(value v) +{ return Val_long(Int32_val(v)); } + +CAMLprim value caml_int32_of_float(value v) +{ return caml_copy_int32((int32)(Double_val(v))); } + +CAMLprim value caml_int32_to_float(value v) +{ return caml_copy_double((double)(Int32_val(v))); } + +CAMLprim value caml_int32_compare(value v1, value v2) +{ + int32 i1 = Int32_val(v1); + int32 i2 = Int32_val(v2); + int res = (i1 > i2) - (i1 < i2); + return Val_int(res); +} + +CAMLprim value caml_int32_format(value fmt, value arg) +{ + char format_string[FORMAT_BUFFER_SIZE]; + char default_format_buffer[FORMAT_BUFFER_SIZE]; + char * buffer; + char conv; + value res; + + buffer = parse_format(fmt, ARCH_INT32_PRINTF_FORMAT, + format_string, default_format_buffer, &conv); + sprintf(buffer, format_string, Int32_val(arg)); + res = caml_copy_string(buffer); + if (buffer != default_format_buffer) caml_stat_free(buffer); + return res; +} + +CAMLprim value caml_int32_of_string(value s) +{ + return caml_copy_int32(parse_intnat(s, 32)); +} + +CAMLprim value caml_int32_bits_of_float(value vd) +{ + union { float d; int32 i; } u; + u.d = Double_val(vd); + return caml_copy_int32(u.i); +} + +CAMLprim value caml_int32_float_of_bits(value vi) +{ + union { float d; int32 i; } u; + u.i = Int32_val(vi); + return caml_copy_double(u.d); +} + +/* 64-bit integers */ + +#ifdef ARCH_INT64_TYPE +#include "int64_native.h" +#else +#include "int64_emul.h" +#endif + +#ifdef ARCH_ALIGN_INT64 + +CAMLexport int64 caml_Int64_val(value v) +{ + union { int32 i[2]; int64 j; } buffer; + buffer.i[0] = ((int32 *) Data_custom_val(v))[0]; + buffer.i[1] = ((int32 *) Data_custom_val(v))[1]; + return buffer.j; +} + +#endif + +static int int64_cmp(value v1, value v2) +{ + int64 i1 = Int64_val(v1); + int64 i2 = Int64_val(v2); + return I64_compare(i1, i2); +} + +static intnat int64_hash(value v) +{ + return I64_to_intnat(Int64_val(v)); +} + +static void int64_serialize(value v, uintnat * wsize_32, + uintnat * wsize_64) +{ + caml_serialize_int_8(Int64_val(v)); + *wsize_32 = *wsize_64 = 8; +} + +static uintnat int64_deserialize(void * dst) +{ +#ifndef ARCH_ALIGN_INT64 + *((int64 *) dst) = caml_deserialize_sint_8(); +#else + union { int32 i[2]; int64 j; } buffer; + buffer.j = caml_deserialize_sint_8(); + ((int32 *) dst)[0] = buffer.i[0]; + ((int32 *) dst)[1] = buffer.i[1]; +#endif + return 8; +} + +CAMLexport struct custom_operations caml_int64_ops = { + "_j", + custom_finalize_default, + int64_cmp, + int64_hash, + int64_serialize, + int64_deserialize +}; + +CAMLexport value caml_copy_int64(int64 i) +{ + value res = caml_alloc_custom(&caml_int64_ops, 8, 0, 1); +#ifndef ARCH_ALIGN_INT64 + Int64_val(res) = i; +#else + union { int32 i[2]; int64 j; } buffer; + buffer.j = i; + ((int32 *) Data_custom_val(res))[0] = buffer.i[0]; + ((int32 *) Data_custom_val(res))[1] = buffer.i[1]; +#endif + return res; +} + +CAMLprim value caml_int64_neg(value v) +{ return caml_copy_int64(I64_neg(Int64_val(v))); } + +CAMLprim value caml_int64_add(value v1, value v2) +{ return caml_copy_int64(I64_add(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_sub(value v1, value v2) +{ return caml_copy_int64(I64_sub(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_mul(value v1, value v2) +{ return caml_copy_int64(I64_mul(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_div(value v1, value v2) +{ + int64 divisor = Int64_val(v2); + if (I64_is_zero(divisor)) caml_raise_zero_divide(); + return caml_copy_int64(I64_div(Int64_val(v1), divisor)); +} + +CAMLprim value caml_int64_mod(value v1, value v2) +{ + int64 divisor = Int64_val(v2); + if (I64_is_zero(divisor)) caml_raise_zero_divide(); + return caml_copy_int64(I64_mod(Int64_val(v1), divisor)); +} + +CAMLprim value caml_int64_and(value v1, value v2) +{ return caml_copy_int64(I64_and(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_or(value v1, value v2) +{ return caml_copy_int64(I64_or(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_xor(value v1, value v2) +{ return caml_copy_int64(I64_xor(Int64_val(v1), Int64_val(v2))); } + +CAMLprim value caml_int64_shift_left(value v1, value v2) +{ return caml_copy_int64(I64_lsl(Int64_val(v1), Int_val(v2))); } + +CAMLprim value caml_int64_shift_right(value v1, value v2) +{ return caml_copy_int64(I64_asr(Int64_val(v1), Int_val(v2))); } + +CAMLprim value caml_int64_shift_right_unsigned(value v1, value v2) +{ return caml_copy_int64(I64_lsr(Int64_val(v1), Int_val(v2))); } + +CAMLprim value caml_int64_of_int(value v) +{ return caml_copy_int64(I64_of_intnat(Long_val(v))); } + +CAMLprim value caml_int64_to_int(value v) +{ return Val_long(I64_to_intnat(Int64_val(v))); } + +CAMLprim value caml_int64_of_float(value v) +{ return caml_copy_int64(I64_of_double(Double_val(v))); } + +CAMLprim value caml_int64_to_float(value v) +{ + int64 i = Int64_val(v); + return caml_copy_double(I64_to_double(i)); +} + +CAMLprim value caml_int64_of_int32(value v) +{ return caml_copy_int64(I64_of_int32(Int32_val(v))); } + +CAMLprim value caml_int64_to_int32(value v) +{ return caml_copy_int32(I64_to_int32(Int64_val(v))); } + +CAMLprim value caml_int64_of_nativeint(value v) +{ return caml_copy_int64(I64_of_intnat(Nativeint_val(v))); } + +CAMLprim value caml_int64_to_nativeint(value v) +{ return caml_copy_nativeint(I64_to_intnat(Int64_val(v))); } + +CAMLprim value caml_int64_compare(value v1, value v2) +{ + int64 i1 = Int64_val(v1); + int64 i2 = Int64_val(v2); + return Val_int(I64_compare(i1, i2)); +} + +#ifdef ARCH_INT64_PRINTF_FORMAT +#define I64_format(buf,fmt,x) sprintf(buf,fmt,x) +#else +#include "int64_format.h" +#define ARCH_INT64_PRINTF_FORMAT "" +#endif + +CAMLprim value caml_int64_format(value fmt, value arg) +{ + char format_string[FORMAT_BUFFER_SIZE]; + char default_format_buffer[FORMAT_BUFFER_SIZE]; + char * buffer; + char conv; + value res; + + buffer = parse_format(fmt, ARCH_INT64_PRINTF_FORMAT, + format_string, default_format_buffer, &conv); + I64_format(buffer, format_string, Int64_val(arg)); + res = caml_copy_string(buffer); + if (buffer != default_format_buffer) caml_stat_free(buffer); + return res; +} + +CAMLprim value caml_int64_of_string(value s) +{ + char * p; + uint64 max_uint64 = I64_literal(0xFFFFFFFF, 0xFFFFFFFF); + uint64 max_int64 = I64_literal(0x80000000, 0x00000000); + uint64 res, threshold; + int sign, base, d; + + p = parse_sign_and_base(String_val(s), &base, &sign); + I64_udivmod(max_uint64, I64_of_int32(base), &threshold, &res); + d = parse_digit(*p); + if (d < 0 || d >= base) caml_failwith("int_of_string"); + res = I64_of_int32(d); + for (p++; /*nothing*/; p++) { + char c = *p; + if (c == '_') continue; + d = parse_digit(c); + if (d < 0 || d >= base) break; + /* Detect overflow in multiplication base * res */ + if (I64_ult(threshold, res)) caml_failwith("int_of_string"); + res = I64_add(I64_mul(I64_of_int32(base), res), I64_of_int32(d)); + /* Detect overflow in addition (base * res) + d */ + if (I64_ult(res, I64_of_int32(d))) caml_failwith("int_of_string"); + } + if (p != String_val(s) + caml_string_length(s)){ + caml_failwith("int_of_string"); + } + if (base == 10 && I64_ult(max_int64, res)) caml_failwith("int_of_string"); + if (sign < 0) res = I64_neg(res); + return caml_copy_int64(res); +} + +CAMLprim value caml_int64_bits_of_float(value vd) +{ + union { double d; int64 i; int32 h[2]; } u; + u.d = Double_val(vd); +#if defined(__arm__) && !defined(__ARM_EABI__) + { int32 t = u.h[0]; u.h[0] = u.h[1]; u.h[1] = t; } +#endif + return caml_copy_int64(u.i); +} + +CAMLprim value caml_int64_float_of_bits(value vi) +{ + union { double d; int64 i; int32 h[2]; } u; + u.i = Int64_val(vi); +#if defined(__arm__) && !defined(__ARM_EABI__) + { int32 t = u.h[0]; u.h[0] = u.h[1]; u.h[1] = t; } +#endif + return caml_copy_double(u.d); +} + +/* Native integers */ + +static int nativeint_cmp(value v1, value v2) +{ + intnat i1 = Nativeint_val(v1); + intnat i2 = Nativeint_val(v2); + return (i1 > i2) - (i1 < i2); +} + +static intnat nativeint_hash(value v) +{ + return Nativeint_val(v); +} + +static void nativeint_serialize(value v, uintnat * wsize_32, + uintnat * wsize_64) +{ + intnat l = Nativeint_val(v); +#ifdef ARCH_SIXTYFOUR + if (l <= 0x7FFFFFFFL && l >= -0x80000000L) { + caml_serialize_int_1(1); + caml_serialize_int_4((int32) l); + } else { + caml_serialize_int_1(2); + caml_serialize_int_8(l); + } +#else + caml_serialize_int_1(1); + caml_serialize_int_4(l); +#endif + *wsize_32 = 4; + *wsize_64 = 8; +} + +static uintnat nativeint_deserialize(void * dst) +{ + switch (caml_deserialize_uint_1()) { + case 1: + *((intnat *) dst) = caml_deserialize_sint_4(); + break; + case 2: +#ifdef ARCH_SIXTYFOUR + *((intnat *) dst) = caml_deserialize_sint_8(); +#else + caml_deserialize_error("input_value: native integer value too large"); +#endif + break; + default: + caml_deserialize_error("input_value: ill-formed native integer"); + } + return sizeof(long); +} + +CAMLexport struct custom_operations caml_nativeint_ops = { + "_n", + custom_finalize_default, + nativeint_cmp, + nativeint_hash, + nativeint_serialize, + nativeint_deserialize +}; + +CAMLexport value caml_copy_nativeint(intnat i) +{ + value res = caml_alloc_custom(&caml_nativeint_ops, sizeof(intnat), 0, 1); + Nativeint_val(res) = i; + return res; +} + +CAMLprim value caml_nativeint_neg(value v) +{ return caml_copy_nativeint(- Nativeint_val(v)); } + +CAMLprim value caml_nativeint_add(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) + Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_sub(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) - Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_mul(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) * Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_div(value v1, value v2) +{ + intnat divisor = Nativeint_val(v2); + if (divisor == 0) caml_raise_zero_divide(); +#ifdef NONSTANDARD_DIV_MOD + return caml_copy_nativeint(caml_safe_div(Nativeint_val(v1), divisor)); +#else + return caml_copy_nativeint(Nativeint_val(v1) / divisor); +#endif +} + +CAMLprim value caml_nativeint_mod(value v1, value v2) +{ + intnat divisor = Nativeint_val(v2); + if (divisor == 0) caml_raise_zero_divide(); +#ifdef NONSTANDARD_DIV_MOD + return caml_copy_nativeint(caml_safe_mod(Nativeint_val(v1), divisor)); +#else + return caml_copy_nativeint(Nativeint_val(v1) % divisor); +#endif +} + +CAMLprim value caml_nativeint_and(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) & Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_or(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) | Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_xor(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) ^ Nativeint_val(v2)); } + +CAMLprim value caml_nativeint_shift_left(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) << Int_val(v2)); } + +CAMLprim value caml_nativeint_shift_right(value v1, value v2) +{ return caml_copy_nativeint(Nativeint_val(v1) >> Int_val(v2)); } + +CAMLprim value caml_nativeint_shift_right_unsigned(value v1, value v2) +{ return caml_copy_nativeint((uintnat)Nativeint_val(v1) >> Int_val(v2)); } + +CAMLprim value caml_nativeint_of_int(value v) +{ return caml_copy_nativeint(Long_val(v)); } + +CAMLprim value caml_nativeint_to_int(value v) +{ return Val_long(Nativeint_val(v)); } + +CAMLprim value caml_nativeint_of_float(value v) +{ return caml_copy_nativeint((intnat)(Double_val(v))); } + +CAMLprim value caml_nativeint_to_float(value v) +{ return caml_copy_double((double)(Nativeint_val(v))); } + +CAMLprim value caml_nativeint_of_int32(value v) +{ return caml_copy_nativeint(Int32_val(v)); } + +CAMLprim value caml_nativeint_to_int32(value v) +{ return caml_copy_int32(Nativeint_val(v)); } + +CAMLprim value caml_nativeint_compare(value v1, value v2) +{ + intnat i1 = Nativeint_val(v1); + intnat i2 = Nativeint_val(v2); + int res = (i1 > i2) - (i1 < i2); + return Val_int(res); +} + +CAMLprim value caml_nativeint_format(value fmt, value arg) +{ + char format_string[FORMAT_BUFFER_SIZE]; + char default_format_buffer[FORMAT_BUFFER_SIZE]; + char * buffer; + char conv; + value res; + + buffer = parse_format(fmt, ARCH_INTNAT_PRINTF_FORMAT, + format_string, default_format_buffer, &conv); + sprintf(buffer, format_string, Nativeint_val(arg)); + res = caml_copy_string(buffer); + if (buffer != default_format_buffer) caml_stat_free(buffer); + return res; +} + +CAMLprim value caml_nativeint_of_string(value s) +{ + return caml_copy_nativeint(parse_intnat(s, 8 * sizeof(value))); +} diff --git a/byterun/io.c b/byterun/io.c new file mode 100644 index 0000000..d895c2e --- /dev/null +++ b/byterun/io.c @@ -0,0 +1,768 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: io.c,v 1.77 2007-02-25 12:38:36 xleroy Exp $ */ + +/* Buffered input/output. */ + +#include +#include +#include +#include +#include +#include "config.h" +#ifdef HAS_UNISTD +#include +#endif +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "io.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "signals.h" +#include "sys.h" + +#ifndef SEEK_SET +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 +#endif + +/* Hooks for locking channels */ + +CAMLexport void (*caml_channel_mutex_free) (struct channel *) = NULL; +CAMLexport void (*caml_channel_mutex_lock) (struct channel *) = NULL; +CAMLexport void (*caml_channel_mutex_unlock) (struct channel *) = NULL; +CAMLexport void (*caml_channel_mutex_unlock_exn) (void) = NULL; + +/* List of opened channels */ +CAMLexport struct channel * caml_all_opened_channels = NULL; + +/* Basic functions over type struct channel *. + These functions can be called directly from C. + No locking is performed. */ + +/* Functions shared between input and output */ + +CAMLexport struct channel * caml_open_descriptor_in(int fd) +{ + struct channel * channel; + + channel = (struct channel *) caml_stat_alloc(sizeof(struct channel)); + channel->fd = fd; + channel->offset = lseek (fd, 0, SEEK_CUR); + channel->curr = channel->max = channel->buff; + channel->end = channel->buff + IO_BUFFER_SIZE; + channel->mutex = NULL; + channel->revealed = 0; + channel->old_revealed = 0; + channel->refcount = 0; + channel->flags = 0; + channel->next = caml_all_opened_channels; + channel->prev = NULL; + if (caml_all_opened_channels != NULL) + caml_all_opened_channels->prev = channel; + caml_all_opened_channels = channel; + return channel; +} + +CAMLexport struct channel * caml_open_descriptor_out(int fd) +{ + struct channel * channel; + + channel = caml_open_descriptor_in(fd); + channel->max = NULL; + return channel; +} + +static void unlink_channel(struct channel *channel) +{ + if (channel->prev == NULL) { + Assert (channel == caml_all_opened_channels); + caml_all_opened_channels = caml_all_opened_channels->next; + if (caml_all_opened_channels != NULL) + caml_all_opened_channels->prev = NULL; + } else { + channel->prev->next = channel->next; + if (channel->next != NULL) channel->next->prev = channel->prev; + } +} + +CAMLexport void caml_close_channel(struct channel *channel) +{ + close(channel->fd); + if (channel->refcount > 0) return; + if (caml_channel_mutex_free != NULL) (*caml_channel_mutex_free)(channel); + unlink_channel(channel); + caml_stat_free(channel); +} + +CAMLexport file_offset caml_channel_size(struct channel *channel) +{ + file_offset end; + + end = lseek(channel->fd, 0, SEEK_END); + if (end == -1 || + lseek(channel->fd, channel->offset, SEEK_SET) != channel->offset) { + caml_sys_error(NO_ARG); + } + return end; +} + +CAMLexport int caml_channel_binary_mode(struct channel *channel) +{ +#if defined(_WIN32) || defined(__CYGWIN__) + int oldmode = setmode(channel->fd, O_BINARY); + if (oldmode == O_TEXT) setmode(channel->fd, O_TEXT); + return oldmode == O_BINARY; +#else + return 1; +#endif +} + +/* Output */ + +#ifndef EINTR +#define EINTR (-1) +#endif +#ifndef EAGAIN +#define EAGAIN (-1) +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK (-1) +#endif + +static int do_write(int fd, char *p, int n) +{ + int retcode; + +again: + caml_enter_blocking_section(); + retcode = write(fd, p, n); + caml_leave_blocking_section(); + if (retcode == -1) { + if (errno == EINTR) goto again; + if ((errno == EAGAIN || errno == EWOULDBLOCK) && n > 1) { + /* We couldn't do a partial write here, probably because + n <= PIPE_BUF and POSIX says that writes of less than + PIPE_BUF characters must be atomic. + We first try again with a partial write of 1 character. + If that fails too, we'll raise Sys_blocked_io below. */ + n = 1; goto again; + } + } + if (retcode == -1) caml_sys_io_error(NO_ARG); + return retcode; +} + +/* Attempt to flush the buffer. This will make room in the buffer for + at least one character. Returns true if the buffer is empty at the + end of the flush, or false if some data remains in the buffer. + */ + +CAMLexport int caml_flush_partial(struct channel *channel) +{ + int towrite, written; + + towrite = channel->curr - channel->buff; + if (towrite > 0) { + written = do_write(channel->fd, channel->buff, towrite); + channel->offset += written; + if (written < towrite) + memmove(channel->buff, channel->buff + written, towrite - written); + channel->curr -= written; + } + return (channel->curr == channel->buff); +} + +/* Flush completely the buffer. */ + +CAMLexport void caml_flush(struct channel *channel) +{ + while (! caml_flush_partial(channel)) /*nothing*/; +} + +/* Output data */ + +CAMLexport void caml_putword(struct channel *channel, uint32 w) +{ + if (! caml_channel_binary_mode(channel)) + caml_failwith("output_binary_int: not a binary channel"); + putch(channel, w >> 24); + putch(channel, w >> 16); + putch(channel, w >> 8); + putch(channel, w); +} + +CAMLexport int caml_putblock(struct channel *channel, char *p, intnat len) +{ + int n, free, towrite, written; + + n = len >= INT_MAX ? INT_MAX : (int) len; + free = channel->end - channel->curr; + if (n < free) { + /* Write request small enough to fit in buffer: transfer to buffer. */ + memmove(channel->curr, p, n); + channel->curr += n; + return n; + } else { + /* Write request overflows buffer (or just fills it up): transfer whatever + fits to buffer and write the buffer */ + memmove(channel->curr, p, free); + towrite = channel->end - channel->buff; + written = do_write(channel->fd, channel->buff, towrite); + if (written < towrite) + memmove(channel->buff, channel->buff + written, towrite - written); + channel->offset += written; + channel->curr = channel->end - written; + return free; + } +} + +CAMLexport void caml_really_putblock(struct channel *channel, + char *p, intnat len) +{ + int written; + while (len > 0) { + written = caml_putblock(channel, p, len); + p += written; + len -= written; + } +} + +CAMLexport void caml_seek_out(struct channel *channel, file_offset dest) +{ + caml_flush(channel); + if (lseek(channel->fd, dest, SEEK_SET) != dest) caml_sys_error(NO_ARG); + channel->offset = dest; +} + +CAMLexport file_offset caml_pos_out(struct channel *channel) +{ + return channel->offset + (file_offset)(channel->curr - channel->buff); +} + +/* Input */ + +/* caml_do_read is exported for Cash */ +CAMLexport int caml_do_read(int fd, char *p, unsigned int n) +{ + int retcode; + + do { + caml_enter_blocking_section(); + retcode = read(fd, p, n); + caml_leave_blocking_section(); + } while (retcode == -1 && errno == EINTR); + if (retcode == -1) caml_sys_io_error(NO_ARG); + return retcode; +} + +CAMLexport unsigned char caml_refill(struct channel *channel) +{ + int n; + + n = caml_do_read(channel->fd, channel->buff, channel->end - channel->buff); + if (n == 0) caml_raise_end_of_file(); + channel->offset += n; + channel->max = channel->buff + n; + channel->curr = channel->buff + 1; + return (unsigned char)(channel->buff[0]); +} + +CAMLexport uint32 caml_getword(struct channel *channel) +{ + int i; + uint32 res; + + if (! caml_channel_binary_mode(channel)) + caml_failwith("input_binary_int: not a binary channel"); + res = 0; + for(i = 0; i < 4; i++) { + res = (res << 8) + getch(channel); + } + return res; +} + +CAMLexport int caml_getblock(struct channel *channel, char *p, intnat len) +{ + int n, avail, nread; + + n = len >= INT_MAX ? INT_MAX : (int) len; + avail = channel->max - channel->curr; + if (n <= avail) { + memmove(p, channel->curr, n); + channel->curr += n; + return n; + } else if (avail > 0) { + memmove(p, channel->curr, avail); + channel->curr += avail; + return avail; + } else { + nread = caml_do_read(channel->fd, channel->buff, + channel->end - channel->buff); + channel->offset += nread; + channel->max = channel->buff + nread; + if (n > nread) n = nread; + memmove(p, channel->buff, n); + channel->curr = channel->buff + n; + return n; + } +} + +CAMLexport int caml_really_getblock(struct channel *chan, char *p, intnat n) +{ + int r; + while (n > 0) { + r = caml_getblock(chan, p, n); + if (r == 0) break; + p += r; + n -= r; + } + return (n == 0); +} + +CAMLexport void caml_seek_in(struct channel *channel, file_offset dest) +{ + if (dest >= channel->offset - (channel->max - channel->buff) && + dest <= channel->offset) { + channel->curr = channel->max - (channel->offset - dest); + } else { + if (lseek(channel->fd, dest, SEEK_SET) != dest) caml_sys_error(NO_ARG); + channel->offset = dest; + channel->curr = channel->max = channel->buff; + } +} + +CAMLexport file_offset caml_pos_in(struct channel *channel) +{ + return channel->offset - (file_offset)(channel->max - channel->curr); +} + +CAMLexport intnat caml_input_scan_line(struct channel *channel) +{ + char * p; + int n; + + p = channel->curr; + do { + if (p >= channel->max) { + /* No more characters available in the buffer */ + if (channel->curr > channel->buff) { + /* Try to make some room in the buffer by shifting the unread + portion at the beginning */ + memmove(channel->buff, channel->curr, channel->max - channel->curr); + n = channel->curr - channel->buff; + channel->curr -= n; + channel->max -= n; + p -= n; + } + if (channel->max >= channel->end) { + /* Buffer is full, no room to read more characters from the input. + Return the number of characters in the buffer, with negative + sign to indicate that no newline was encountered. */ + return -(channel->max - channel->curr); + } + /* Fill the buffer as much as possible */ + n = caml_do_read(channel->fd, channel->max, channel->end - channel->max); + if (n == 0) { + /* End-of-file encountered. Return the number of characters in the + buffer, with negative sign since we haven't encountered + a newline. */ + return -(channel->max - channel->curr); + } + channel->offset += n; + channel->max += n; + } + } while (*p++ != '\n'); + /* Found a newline. Return the length of the line, newline included. */ + return (p - channel->curr); +} + +/* Caml entry points for the I/O functions. Wrap struct channel * + objects into a heap-allocated object. Perform locking + and unlocking around the I/O operations. */ +/* FIXME CAMLexport, but not in io.h exported for Cash ? */ +CAMLexport void caml_finalize_channel(value vchan) +{ + struct channel * chan = Channel(vchan); + if (--chan->refcount > 0) return; + if (caml_channel_mutex_free != NULL) (*caml_channel_mutex_free)(chan); + unlink_channel(chan); + caml_stat_free(chan); +} + +static int compare_channel(value vchan1, value vchan2) +{ + struct channel * chan1 = Channel(vchan1); + struct channel * chan2 = Channel(vchan2); + return (chan1 == chan2) ? 0 : (chan1 < chan2) ? -1 : 1; +} + +static struct custom_operations channel_operations = { + "_chan", + caml_finalize_channel, + compare_channel, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +CAMLexport value caml_alloc_channel(struct channel *chan) +{ + value res; + chan->refcount++; /* prevent finalization during next alloc */ + res = caml_alloc_custom(&channel_operations, sizeof(struct channel *), + 1, 1000); + Channel(res) = chan; + return res; +} + +CAMLprim value caml_ml_open_descriptor_in(value fd) +{ + return caml_alloc_channel(caml_open_descriptor_in(Int_val(fd))); +} + +CAMLprim value caml_ml_open_descriptor_out(value fd) +{ + return caml_alloc_channel(caml_open_descriptor_out(Int_val(fd))); +} + +#define Pair_tag 0 + +CAMLprim value caml_ml_out_channels_list (value unit) +{ + CAMLparam0 (); + CAMLlocal3 (res, tail, chan); + struct channel * channel; + + res = Val_emptylist; + for (channel = caml_all_opened_channels; + channel != NULL; + channel = channel->next) + /* Testing channel->fd >= 0 looks unnecessary, as + caml_ml_close_channel changes max when setting fd to -1. */ + if (channel->max == NULL) { + chan = caml_alloc_channel (channel); + tail = res; + res = caml_alloc_small (2, Pair_tag); + Field (res, 0) = chan; + Field (res, 1) = tail; + } + CAMLreturn (res); +} + +CAMLprim value caml_channel_descriptor(value vchannel) +{ + int fd = Channel(vchannel)->fd; + if (fd == -1) { errno = EBADF; caml_sys_error(NO_ARG); } + return Val_int(fd); +} + +CAMLprim value caml_ml_close_channel(value vchannel) +{ + int result; + + /* For output channels, must have flushed before */ + struct channel * channel = Channel(vchannel); + if (channel->fd != -1){ + result = close(channel->fd); + channel->fd = -1; + }else{ + result = 0; + } + /* Ensure that every read or write on the channel will cause an + immediate caml_flush_partial or caml_refill, thus raising a Sys_error + exception */ + channel->curr = channel->max = channel->end; + if (result == -1) caml_sys_error (NO_ARG); + return Val_unit; +} + +/* EOVERFLOW is the Unix98 error indicating that a file position or file + size is not representable. + ERANGE is the ANSI C error indicating that some argument to some + function is out of range. This is less precise than EOVERFLOW, + but guaranteed to be defined on all ANSI C environments. */ +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif + +CAMLprim value caml_ml_channel_size(value vchannel) +{ + file_offset size = caml_channel_size(Channel(vchannel)); + if (size > Max_long) { errno = EOVERFLOW; caml_sys_error(NO_ARG); } + return Val_long(size); +} + +CAMLprim value caml_ml_channel_size_64(value vchannel) +{ + return Val_file_offset(caml_channel_size(Channel(vchannel))); +} + +CAMLprim value caml_ml_set_binary_mode(value vchannel, value mode) +{ +#if defined(_WIN32) || defined(__CYGWIN__) + struct channel * channel = Channel(vchannel); + if (setmode(channel->fd, Bool_val(mode) ? O_BINARY : O_TEXT) == -1) + caml_sys_error(NO_ARG); +#endif + return Val_unit; +} + +/* + If the channel is closed, DO NOT raise a "bad file descriptor" + exception, but do nothing (the buffer is already empty). + This is because some libraries will flush at exit, even on + file descriptors that may be closed. +*/ + +CAMLprim value caml_ml_flush_partial(value vchannel) +{ + CAMLparam1 (vchannel); + struct channel * channel = Channel(vchannel); + int res; + + if (channel->fd == -1) CAMLreturn(Val_true); + Lock(channel); + res = caml_flush_partial(channel); + Unlock(channel); + CAMLreturn (Val_bool(res)); +} + +CAMLprim value caml_ml_flush(value vchannel) +{ + CAMLparam1 (vchannel); + struct channel * channel = Channel(vchannel); + + if (channel->fd == -1) CAMLreturn(Val_unit); + Lock(channel); + caml_flush(channel); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_output_char(value vchannel, value ch) +{ + CAMLparam2 (vchannel, ch); + struct channel * channel = Channel(vchannel); + + Lock(channel); + putch(channel, Long_val(ch)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_output_int(value vchannel, value w) +{ + CAMLparam2 (vchannel, w); + struct channel * channel = Channel(vchannel); + + Lock(channel); + caml_putword(channel, Long_val(w)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_output_partial(value vchannel, value buff, value start, + value length) +{ + CAMLparam4 (vchannel, buff, start, length); + struct channel * channel = Channel(vchannel); + int res; + + Lock(channel); + res = caml_putblock(channel, &Byte(buff, Long_val(start)), Long_val(length)); + Unlock(channel); + CAMLreturn (Val_int(res)); +} + +CAMLprim value caml_ml_output(value vchannel, value buff, value start, + value length) +{ + CAMLparam4 (vchannel, buff, start, length); + struct channel * channel = Channel(vchannel); + intnat pos = Long_val(start); + intnat len = Long_val(length); + + Lock(channel); + while (len > 0) { + int written = caml_putblock(channel, &Byte(buff, pos), len); + pos += written; + len -= written; + } + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_seek_out(value vchannel, value pos) +{ + CAMLparam2 (vchannel, pos); + struct channel * channel = Channel(vchannel); + + Lock(channel); + caml_seek_out(channel, Long_val(pos)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_seek_out_64(value vchannel, value pos) +{ + CAMLparam2 (vchannel, pos); + struct channel * channel = Channel(vchannel); + + Lock(channel); + caml_seek_out(channel, File_offset_val(pos)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_pos_out(value vchannel) +{ + file_offset pos = caml_pos_out(Channel(vchannel)); + if (pos > Max_long) { errno = EOVERFLOW; caml_sys_error(NO_ARG); } + return Val_long(pos); +} + +CAMLprim value caml_ml_pos_out_64(value vchannel) +{ + return Val_file_offset(caml_pos_out(Channel(vchannel))); +} + +CAMLprim value caml_ml_input_char(value vchannel) +{ + CAMLparam1 (vchannel); + struct channel * channel = Channel(vchannel); + unsigned char c; + + Lock(channel); + c = getch(channel); + Unlock(channel); + CAMLreturn (Val_long(c)); +} + +CAMLprim value caml_ml_input_int(value vchannel) +{ + CAMLparam1 (vchannel); + struct channel * channel = Channel(vchannel); + intnat i; + + Lock(channel); + i = caml_getword(channel); + Unlock(channel); +#ifdef ARCH_SIXTYFOUR + i = (i << 32) >> 32; /* Force sign extension */ +#endif + CAMLreturn (Val_long(i)); +} + +CAMLprim value caml_ml_input(value vchannel, value buff, value vstart, + value vlength) +{ + CAMLparam4 (vchannel, buff, vstart, vlength); + struct channel * channel = Channel(vchannel); + intnat start, len; + int n, avail, nread; + + Lock(channel); + /* We cannot call caml_getblock here because buff may move during + caml_do_read */ + start = Long_val(vstart); + len = Long_val(vlength); + n = len >= INT_MAX ? INT_MAX : (int) len; + avail = channel->max - channel->curr; + if (n <= avail) { + memmove(&Byte(buff, start), channel->curr, n); + channel->curr += n; + } else if (avail > 0) { + memmove(&Byte(buff, start), channel->curr, avail); + channel->curr += avail; + n = avail; + } else { + nread = caml_do_read(channel->fd, channel->buff, + channel->end - channel->buff); + channel->offset += nread; + channel->max = channel->buff + nread; + if (n > nread) n = nread; + memmove(&Byte(buff, start), channel->buff, n); + channel->curr = channel->buff + n; + } + Unlock(channel); + CAMLreturn (Val_long(n)); +} + +CAMLprim value caml_ml_seek_in(value vchannel, value pos) +{ + CAMLparam2 (vchannel, pos); + struct channel * channel = Channel(vchannel); + + Lock(channel); + caml_seek_in(channel, Long_val(pos)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_seek_in_64(value vchannel, value pos) +{ + CAMLparam2 (vchannel, pos); + struct channel * channel = Channel(vchannel); + + Lock(channel); + caml_seek_in(channel, File_offset_val(pos)); + Unlock(channel); + CAMLreturn (Val_unit); +} + +CAMLprim value caml_ml_pos_in(value vchannel) +{ + file_offset pos = caml_pos_in(Channel(vchannel)); + if (pos > Max_long) { errno = EOVERFLOW; caml_sys_error(NO_ARG); } + return Val_long(pos); +} + +CAMLprim value caml_ml_pos_in_64(value vchannel) +{ + return Val_file_offset(caml_pos_in(Channel(vchannel))); +} + +CAMLprim value caml_ml_input_scan_line(value vchannel) +{ + CAMLparam1 (vchannel); + struct channel * channel = Channel(vchannel); + intnat res; + + Lock(channel); + res = caml_input_scan_line(channel); + Unlock(channel); + CAMLreturn (Val_long(res)); +} + +/* Conversion between file_offset and int64 */ + +#ifndef ARCH_INT64_TYPE +CAMLexport value caml_Val_file_offset(file_offset fofs) +{ + int64 ofs; + ofs.l = fofs; + ofs.h = 0; + return caml_copy_int64(ofs); +} + +CAMLexport file_offset caml_File_offset_val(value v) +{ + int64 ofs = Int64_val(v); + return (file_offset) ofs.l; +} +#endif diff --git a/byterun/io.h b/byterun/io.h new file mode 100644 index 0000000..81ac391 --- /dev/null +++ b/byterun/io.h @@ -0,0 +1,126 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: io.h,v 1.32 2008-09-27 21:16:29 weis Exp $ */ + +/* Buffered input/output */ + +#ifndef CAML_IO_H +#define CAML_IO_H + +#include "misc.h" +#include "mlvalues.h" + +#ifndef IO_BUFFER_SIZE +#define IO_BUFFER_SIZE 4096 +#endif + +#if defined(_WIN32) +typedef __int64 file_offset; +extern __int64 _lseeki64(int, __int64, int); +#define lseek(fd,d,m) _lseeki64(fd,d,m) +#elif defined(HAS_OFF_T) +#include +typedef off_t file_offset; +#else +typedef long file_offset; +#endif + +struct channel { + int fd; /* Unix file descriptor */ + file_offset offset; /* Absolute position of fd in the file */ + char * end; /* Physical end of the buffer */ + char * curr; /* Current position in the buffer */ + char * max; /* Logical end of the buffer (for input) */ + void * mutex; /* Placeholder for mutex (for systhreads) */ + struct channel * next, * prev;/* Double chaining of channels (flush_all) */ + int revealed; /* For Cash only */ + int old_revealed; /* For Cash only */ + int refcount; /* For flush_all and for Cash */ + int flags; /* Bitfield */ + char buff[IO_BUFFER_SIZE]; /* The buffer itself */ +}; + +enum { + CHANNEL_FLAG_FROM_SOCKET = 1 /* For Windows */ +}; + +/* For an output channel: + [offset] is the absolute position of the beginning of the buffer [buff]. + For an input channel: + [offset] is the absolute position of the logical end of the buffer, [max]. +*/ + +/* Functions and macros that can be called from C. Take arguments of + type struct channel *. No locking is performed. */ + +#define putch(channel, ch) do{ \ + if ((channel)->curr >= (channel)->end) caml_flush_partial(channel); \ + *((channel)->curr)++ = (ch); \ +}while(0) + +#define getch(channel) \ + ((channel)->curr >= (channel)->max \ + ? caml_refill(channel) \ + : (unsigned char) *((channel)->curr)++) + +CAMLextern struct channel * caml_open_descriptor_in (int); +CAMLextern struct channel * caml_open_descriptor_out (int); +CAMLextern void caml_close_channel (struct channel *); +CAMLextern int caml_channel_binary_mode (struct channel *); +CAMLextern value caml_alloc_channel(struct channel *chan); + +CAMLextern int caml_flush_partial (struct channel *); +CAMLextern void caml_flush (struct channel *); +CAMLextern void caml_putword (struct channel *, uint32); +CAMLextern int caml_putblock (struct channel *, char *, intnat); +CAMLextern void caml_really_putblock (struct channel *, char *, intnat); + +CAMLextern unsigned char caml_refill (struct channel *); +CAMLextern uint32 caml_getword (struct channel *); +CAMLextern int caml_getblock (struct channel *, char *, intnat); +CAMLextern int caml_really_getblock (struct channel *, char *, intnat); + +/* Extract a struct channel * from the heap object representing it */ + +#define Channel(v) (*((struct channel **) (Data_custom_val(v)))) + +/* The locking machinery */ + +CAMLextern void (*caml_channel_mutex_free) (struct channel *); +CAMLextern void (*caml_channel_mutex_lock) (struct channel *); +CAMLextern void (*caml_channel_mutex_unlock) (struct channel *); +CAMLextern void (*caml_channel_mutex_unlock_exn) (void); + +CAMLextern struct channel * caml_all_opened_channels; + +#define Lock(channel) \ + if (caml_channel_mutex_lock != NULL) (*caml_channel_mutex_lock)(channel) +#define Unlock(channel) \ + if (caml_channel_mutex_unlock != NULL) (*caml_channel_mutex_unlock)(channel) +#define Unlock_exn() \ + if (caml_channel_mutex_unlock_exn != NULL) (*caml_channel_mutex_unlock_exn)() + +/* Conversion between file_offset and int64 */ + +#ifdef ARCH_INT64_TYPE +#define Val_file_offset(fofs) caml_copy_int64(fofs) +#define File_offset_val(v) ((file_offset) Int64_val(v)) +#else +CAMLextern value caml_Val_file_offset(file_offset fofs); +CAMLextern file_offset caml_File_offset_val(value v); +#define Val_file_offset caml_Val_file_offset +#define File_offset_val caml_File_offset_val +#endif + +#endif /* CAML_IO_H */ diff --git a/byterun/lexing.c b/byterun/lexing.c new file mode 100644 index 0000000..4012a28 --- /dev/null +++ b/byterun/lexing.c @@ -0,0 +1,231 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: lexing.c,v 1.27 2004-01-01 16:42:36 doligez Exp $ */ + +/* The table-driven automaton for lexers generated by camllex. */ + +#include "fail.h" +#include "mlvalues.h" +#include "stacks.h" + +struct lexer_buffer { + value refill_buff; + value lex_buffer; + value lex_buffer_len; + value lex_abs_pos; + value lex_start_pos; + value lex_curr_pos; + value lex_last_pos; + value lex_last_action; + value lex_eof_reached; + value lex_mem; + value lex_start_p; + value lex_curr_p; +}; + +struct lexing_table { + value lex_base; + value lex_backtrk; + value lex_default; + value lex_trans; + value lex_check; + value lex_base_code; + value lex_backtrk_code; + value lex_default_code; + value lex_trans_code; + value lex_check_code; + value lex_code; +}; + +#if defined(ARCH_BIG_ENDIAN) || SIZEOF_SHORT != 2 +#define Short(tbl,n) \ + (*((unsigned char *)((tbl) + (n) * 2)) + \ + (*((schar *)((tbl) + (n) * 2 + 1)) << 8)) +#else +#define Short(tbl,n) (((short *)(tbl))[(n)]) +#endif + +CAMLprim value caml_lex_engine(struct lexing_table *tbl, value start_state, + struct lexer_buffer *lexbuf) +{ + int state, base, backtrk, c; + + state = Int_val(start_state); + if (state >= 0) { + /* First entry */ + lexbuf->lex_last_pos = lexbuf->lex_start_pos = lexbuf->lex_curr_pos; + lexbuf->lex_last_action = Val_int(-1); + } else { + /* Reentry after refill */ + state = -state - 1; + } + while(1) { + /* Lookup base address or action number for current state */ + base = Short(tbl->lex_base, state); + if (base < 0) return Val_int(-base-1); + /* See if it's a backtrack point */ + backtrk = Short(tbl->lex_backtrk, state); + if (backtrk >= 0) { + lexbuf->lex_last_pos = lexbuf->lex_curr_pos; + lexbuf->lex_last_action = Val_int(backtrk); + } + /* See if we need a refill */ + if (lexbuf->lex_curr_pos >= lexbuf->lex_buffer_len){ + if (lexbuf->lex_eof_reached == Val_bool (0)){ + return Val_int(-state - 1); + }else{ + c = 256; + } + }else{ + /* Read next input char */ + c = Byte_u(lexbuf->lex_buffer, Long_val(lexbuf->lex_curr_pos)); + lexbuf->lex_curr_pos += 2; + } + /* Determine next state */ + if (Short(tbl->lex_check, base + c) == state) + state = Short(tbl->lex_trans, base + c); + else + state = Short(tbl->lex_default, state); + /* If no transition on this char, return to last backtrack point */ + if (state < 0) { + lexbuf->lex_curr_pos = lexbuf->lex_last_pos; + if (lexbuf->lex_last_action == Val_int(-1)) { + caml_failwith("lexing: empty token"); + } else { + return lexbuf->lex_last_action; + } + }else{ + /* Erase the EOF condition only if the EOF pseudo-character was + consumed by the automaton (i.e. there was no backtrack above) + */ + if (c == 256) lexbuf->lex_eof_reached = Val_bool (0); + } + } +} + +/***********************************************/ +/* New lexer engine, with memory of positions */ +/***********************************************/ + +static void run_mem(char *pc, value mem, value curr_pos) { + for (;;) { + unsigned char dst, src ; + + dst = *pc++ ; + if (dst == 0xff) + return ; + src = *pc++ ; + if (src == 0xff) { + /* fprintf(stderr,"[%hhu] <- %d\n",dst,Int_val(curr_pos)) ;*/ + Field(mem,dst) = curr_pos ; + } else { + /* fprintf(stderr,"[%hhu] <- [%hhu]\n",dst,src) ; */ + Field(mem,dst) = Field(mem,src) ; + } + } +} + +static void run_tag(char *pc, value mem) { + for (;;) { + unsigned char dst, src ; + + dst = *pc++ ; + if (dst == 0xff) + return ; + src = *pc++ ; + if (src == 0xff) { + /* fprintf(stderr,"[%hhu] <- -1\n",dst) ; */ + Field(mem,dst) = Val_int(-1) ; + } else { + /* fprintf(stderr,"[%hhu] <- [%hhu]\n",dst,src) ; */ + Field(mem,dst) = Field(mem,src) ; + } + } +} + +CAMLprim value caml_new_lex_engine(struct lexing_table *tbl, value start_state, + struct lexer_buffer *lexbuf) +{ + int state, base, backtrk, c, pstate ; + state = Int_val(start_state); + if (state >= 0) { + /* First entry */ + lexbuf->lex_last_pos = lexbuf->lex_start_pos = lexbuf->lex_curr_pos; + lexbuf->lex_last_action = Val_int(-1); + } else { + /* Reentry after refill */ + state = -state - 1; + } + while(1) { + /* Lookup base address or action number for current state */ + base = Short(tbl->lex_base, state); + if (base < 0) { + int pc_off = Short(tbl->lex_base_code, state) ; + run_tag(Bp_val(tbl->lex_code) + pc_off, lexbuf->lex_mem); + /* fprintf(stderr,"Perform: %d\n",-base-1) ; */ + return Val_int(-base-1); + } + /* See if it's a backtrack point */ + backtrk = Short(tbl->lex_backtrk, state); + if (backtrk >= 0) { + int pc_off = Short(tbl->lex_backtrk_code, state); + run_tag(Bp_val(tbl->lex_code) + pc_off, lexbuf->lex_mem); + lexbuf->lex_last_pos = lexbuf->lex_curr_pos; + lexbuf->lex_last_action = Val_int(backtrk); + + } + /* See if we need a refill */ + if (lexbuf->lex_curr_pos >= lexbuf->lex_buffer_len){ + if (lexbuf->lex_eof_reached == Val_bool (0)){ + return Val_int(-state - 1); + }else{ + c = 256; + } + }else{ + /* Read next input char */ + c = Byte_u(lexbuf->lex_buffer, Long_val(lexbuf->lex_curr_pos)); + lexbuf->lex_curr_pos += 2; + } + /* Determine next state */ + pstate=state ; + if (Short(tbl->lex_check, base + c) == state) + state = Short(tbl->lex_trans, base + c); + else + state = Short(tbl->lex_default, state); + /* If no transition on this char, return to last backtrack point */ + if (state < 0) { + lexbuf->lex_curr_pos = lexbuf->lex_last_pos; + if (lexbuf->lex_last_action == Val_int(-1)) { + caml_failwith("lexing: empty token"); + } else { + return lexbuf->lex_last_action; + } + }else{ + /* If some transition, get and perform memory moves */ + int base_code = Short(tbl->lex_base_code, pstate) ; + int pc_off ; + if (Short(tbl->lex_check_code, base_code + c) == pstate) + pc_off = Short(tbl->lex_trans_code, base_code + c) ; + else + pc_off = Short(tbl->lex_default_code, pstate) ; + if (pc_off > 0) + run_mem(Bp_val(tbl->lex_code) + pc_off, lexbuf->lex_mem, lexbuf->lex_curr_pos) ; + /* Erase the EOF condition only if the EOF pseudo-character was + consumed by the automaton (i.e. there was no backtrack above) + */ + if (c == 256) lexbuf->lex_eof_reached = Val_bool (0); + } + } +} + diff --git a/byterun/main.c b/byterun/main.c new file mode 100644 index 0000000..a48abc5 --- /dev/null +++ b/byterun/main.c @@ -0,0 +1,59 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: main.c,v 1.37 2008-02-29 12:56:15 doligez Exp $ */ + +/* Main entry point (can be overridden by a user-provided main() + function that calls caml_main() later). */ + +#include "misc.h" +#include "mlvalues.h" +#include "sys.h" + +CAMLextern void caml_main (char **); + +#ifdef _WIN32 +CAMLextern void caml_expand_command_line (int *, char ***); +#endif + +int main(int argc, char **argv) +{ +#ifdef DEBUG + { + char *ocp; + char *cp; + int i; + + caml_gc_message (-1, "### OCaml runtime: debug mode ###\n", 0); +#if 0 + caml_gc_message (-1, "### command line:", 0); + for (i = 0; i < argc; i++){ + caml_gc_message (-1, " %s", argv[i]); + } + caml_gc_message (-1, "\n", 0); + ocp = getenv ("OCAMLRUNPARAM"); + caml_gc_message (-1, "### OCAMLRUNPARAM=%s\n", ocp == NULL ? "" : ocp); + cp = getenv ("CAMLRUNPARAM"); + caml_gc_message (-1, "### CAMLRUNPARAM=%s\n", cp == NULL ? "" : cp); + caml_gc_message (-1, "### working dir: %s\n", getcwd (NULL, 0)); +#endif + } +#endif +#ifdef _WIN32 + /* Expand wildcards and diversions in command line */ + caml_expand_command_line(&argc, &argv); +#endif + caml_main(argv); + caml_sys_exit(Val_int(0)); + return 0; /* not reached */ +} diff --git a/byterun/major_gc.c b/byterun/major_gc.c new file mode 100644 index 0000000..e3c573e --- /dev/null +++ b/byterun/major_gc.c @@ -0,0 +1,509 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: major_gc.c,v 1.63 2008-12-03 18:09:09 doligez Exp $ */ + +#include + +#include "compact.h" +#include "custom.h" +#include "config.h" +#include "fail.h" +#include "finalise.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "major_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "roots.h" +#include "weak.h" + +uintnat caml_percent_free; +intnat caml_major_heap_increment; +CAMLexport char *caml_heap_start; +char *caml_gc_sweep_hp; +int caml_gc_phase; /* always Phase_mark, Phase_sweep, or Phase_idle */ +static value *gray_vals; +static value *gray_vals_cur, *gray_vals_end; +static asize_t gray_vals_size; +static int heap_is_pure; /* The heap is pure if the only gray objects + below [markhp] are also in [gray_vals]. */ +uintnat caml_allocated_words; +uintnat caml_dependent_size, caml_dependent_allocated; +double caml_extra_heap_resources; +uintnat caml_fl_size_at_phase_change = 0; + +extern char *caml_fl_merge; /* Defined in freelist.c. */ + +static char *markhp, *chunk, *limit; + +int caml_gc_subphase; /* Subphase_{main,weak1,weak2,final} */ +static value *weak_prev; + +#ifdef DEBUG +static unsigned long major_gc_counter = 0; +#endif + +static void realloc_gray_vals (void) +{ + value *new; + + Assert (gray_vals_cur == gray_vals_end); + if (gray_vals_size < caml_stat_heap_size / 128){ + caml_gc_message (0x08, "Growing gray_vals to %" + ARCH_INTNAT_PRINTF_FORMAT "uk bytes\n", + (intnat) gray_vals_size * sizeof (value) / 512); + new = (value *) realloc ((char *) gray_vals, + 2 * gray_vals_size * sizeof (value)); + if (new == NULL){ + caml_gc_message (0x08, "No room for growing gray_vals\n", 0); + gray_vals_cur = gray_vals; + heap_is_pure = 0; + }else{ + gray_vals = new; + gray_vals_cur = gray_vals + gray_vals_size; + gray_vals_size *= 2; + gray_vals_end = gray_vals + gray_vals_size; + } + }else{ + gray_vals_cur = gray_vals + gray_vals_size / 2; + heap_is_pure = 0; + } +} + +void caml_darken (value v, value *p /* not used */) +{ + if (Is_block (v) && Is_in_heap (v)) { + header_t h = Hd_val (v); + tag_t t = Tag_hd (h); + if (t == Infix_tag){ + v -= Infix_offset_val(v); + h = Hd_val (v); + t = Tag_hd (h); + } + CAMLassert (!Is_blue_hd (h)); + if (Is_white_hd (h)){ + if (t < No_scan_tag){ + Hd_val (v) = Grayhd_hd (h); + *gray_vals_cur++ = v; + if (gray_vals_cur >= gray_vals_end) realloc_gray_vals (); + }else{ + Hd_val (v) = Blackhd_hd (h); + } + } + } +} + +static void start_cycle (void) +{ + Assert (caml_gc_phase == Phase_idle); + Assert (gray_vals_cur == gray_vals); + caml_gc_message (0x01, "Starting new major GC cycle\n", 0); + caml_darken_all_roots(); + caml_gc_phase = Phase_mark; + caml_gc_subphase = Subphase_main; + markhp = NULL; +#ifdef DEBUG + ++ major_gc_counter; + caml_heap_check (); +#endif +} + +static void mark_slice (intnat work) +{ + value *gray_vals_ptr; /* Local copy of gray_vals_cur */ + value v, child; + header_t hd; + mlsize_t size, i; + + caml_gc_message (0x40, "Marking %ld words\n", work); + caml_gc_message (0x40, "Subphase = %ld\n", caml_gc_subphase); + gray_vals_ptr = gray_vals_cur; + while (work > 0){ + if (gray_vals_ptr > gray_vals){ + v = *--gray_vals_ptr; + hd = Hd_val(v); + Assert (Is_gray_hd (hd)); + Hd_val (v) = Blackhd_hd (hd); + size = Wosize_hd (hd); + if (Tag_hd (hd) < No_scan_tag){ + for (i = 0; i < size; i++){ + child = Field (v, i); + if (Is_block (child) && Is_in_heap (child)) { + hd = Hd_val (child); + if (Tag_hd (hd) == Forward_tag){ + value f = Forward_val (child); + if (Is_block (f) + && (!Is_in_value_area(f) || Tag_val (f) == Forward_tag + || Tag_val (f) == Lazy_tag || Tag_val (f) == Double_tag)){ + /* Do not short-circuit the pointer. */ + }else{ + Field (v, i) = f; + } + } + else if (Tag_hd(hd) == Infix_tag) { + child -= Infix_offset_val(child); + hd = Hd_val(child); + } + if (Is_white_hd (hd)){ + Hd_val (child) = Grayhd_hd (hd); + *gray_vals_ptr++ = child; + if (gray_vals_ptr >= gray_vals_end) { + gray_vals_cur = gray_vals_ptr; + realloc_gray_vals (); + gray_vals_ptr = gray_vals_cur; + } + } + } + } + } + work -= Whsize_wosize(size); + }else if (markhp != NULL){ + if (markhp == limit){ + chunk = Chunk_next (chunk); + if (chunk == NULL){ + markhp = NULL; + }else{ + markhp = chunk; + limit = chunk + Chunk_size (chunk); + } + }else{ + if (Is_gray_val (Val_hp (markhp))){ + Assert (gray_vals_ptr == gray_vals); + *gray_vals_ptr++ = Val_hp (markhp); + } + markhp += Bhsize_hp (markhp); + } + }else if (!heap_is_pure){ + heap_is_pure = 1; + chunk = caml_heap_start; + markhp = chunk; + limit = chunk + Chunk_size (chunk); + }else{ + switch (caml_gc_subphase){ + case Subphase_main: { + /* The main marking phase is over. Start removing weak pointers to + dead values. */ + caml_gc_subphase = Subphase_weak1; + weak_prev = &caml_weak_list_head; + } + break; + case Subphase_weak1: { + value cur, curfield; + mlsize_t sz, i; + header_t hd; + + cur = *weak_prev; + if (cur != (value) NULL){ + hd = Hd_val (cur); + sz = Wosize_hd (hd); + for (i = 1; i < sz; i++){ + curfield = Field (cur, i); + weak_again: + if (curfield != caml_weak_none + && Is_block (curfield) && Is_in_heap (curfield)){ + if (Tag_val (curfield) == Forward_tag){ + value f = Forward_val (curfield); + if (Is_block (f)) { + if (!Is_in_value_area(f) || Tag_val (f) == Forward_tag + || Tag_val (f) == Lazy_tag || Tag_val (f) == Double_tag){ + /* Do not short-circuit the pointer. */ + }else{ + Field (cur, i) = curfield = f; + goto weak_again; + } + } + } + if (Is_white_val (curfield)){ + Field (cur, i) = caml_weak_none; + } + } + } + weak_prev = &Field (cur, 0); + work -= Whsize_hd (hd); + }else{ + /* Subphase_weak1 is done. Start removing dead weak arrays. */ + caml_gc_subphase = Subphase_weak2; + weak_prev = &caml_weak_list_head; + } + } + break; + case Subphase_weak2: { + value cur; + header_t hd; + + cur = *weak_prev; + if (cur != (value) NULL){ + hd = Hd_val (cur); + if (Color_hd (hd) == Caml_white){ + /* The whole array is dead, remove it from the list. */ + *weak_prev = Field (cur, 0); + }else{ + weak_prev = &Field (cur, 0); + } + work -= 1; + }else{ + /* Subphase_weak2 is done. Handle finalised values. */ + gray_vals_cur = gray_vals_ptr; + caml_final_update (); + gray_vals_ptr = gray_vals_cur; + caml_gc_subphase = Subphase_final; + } + } + break; + case Subphase_final: { + /* Initialise the sweep phase. */ + gray_vals_cur = gray_vals_ptr; + caml_gc_sweep_hp = caml_heap_start; + caml_fl_init_merge (); + caml_gc_phase = Phase_sweep; + chunk = caml_heap_start; + caml_gc_sweep_hp = chunk; + limit = chunk + Chunk_size (chunk); + work = 0; + caml_fl_size_at_phase_change = caml_fl_cur_size; + } + break; + default: Assert (0); + } + } + } + gray_vals_cur = gray_vals_ptr; +} + +static void sweep_slice (intnat work) +{ + char *hp; + header_t hd; + + caml_gc_message (0x40, "Sweeping %ld words\n", work); + while (work > 0){ + if (caml_gc_sweep_hp < limit){ + hp = caml_gc_sweep_hp; + hd = Hd_hp (hp); + work -= Whsize_hd (hd); + caml_gc_sweep_hp += Bhsize_hd (hd); + switch (Color_hd (hd)){ + case Caml_white: + if (Tag_hd (hd) == Custom_tag){ + void (*final_fun)(value) = Custom_ops_val(Val_hp(hp))->finalize; + if (final_fun != NULL) final_fun(Val_hp(hp)); + } + caml_gc_sweep_hp = caml_fl_merge_block (Bp_hp (hp)); + break; + case Caml_blue: + /* Only the blocks of the free-list are blue. See [freelist.c]. */ + caml_fl_merge = Bp_hp (hp); + break; + default: /* gray or black */ + Assert (Color_hd (hd) == Caml_black); + Hd_hp (hp) = Whitehd_hd (hd); + break; + } + Assert (caml_gc_sweep_hp <= limit); + }else{ + chunk = Chunk_next (chunk); + if (chunk == NULL){ + /* Sweeping is done. */ + ++ caml_stat_major_collections; + work = 0; + caml_gc_phase = Phase_idle; + }else{ + caml_gc_sweep_hp = chunk; + limit = chunk + Chunk_size (chunk); + } + } + } +} + +/* The main entry point for the GC. Called after each minor GC. + [howmuch] is the amount of work to do, 0 to let the GC compute it. + Return the computed amount of work to do. + */ +intnat caml_major_collection_slice (intnat howmuch) +{ + double p, dp; + intnat computed_work; + /* + Free memory at the start of the GC cycle (garbage + free list) (assumed): + FM = caml_stat_heap_size * caml_percent_free + / (100 + caml_percent_free) + + Assuming steady state and enforcing a constant allocation rate, then + FM is divided in 2/3 for garbage and 1/3 for free list. + G = 2 * FM / 3 + G is also the amount of memory that will be used during this cycle + (still assuming steady state). + + Proportion of G consumed since the previous slice: + PH = caml_allocated_words / G + = caml_allocated_words * 3 * (100 + caml_percent_free) + / (2 * caml_stat_heap_size * caml_percent_free) + Proportion of extra-heap resources consumed since the previous slice: + PE = caml_extra_heap_resources + Proportion of total work to do in this slice: + P = max (PH, PE) + Amount of marking work for the GC cycle: + MW = caml_stat_heap_size * 100 / (100 + caml_percent_free) + Amount of sweeping work for the GC cycle: + SW = caml_stat_heap_size + + In order to finish marking with a non-empty free list, we will + use 40% of the time for marking, and 60% for sweeping. + + If TW is the total work for this cycle, + MW = 40/100 * TW + SW = 60/100 * TW + + Amount of work to do for this slice: + W = P * TW + + Amount of marking work for a marking slice: + MS = P * MW / (40/100) + MS = P * caml_stat_heap_size * 250 / (100 + caml_percent_free) + Amount of sweeping work for a sweeping slice: + SS = P * SW / (60/100) + SS = P * caml_stat_heap_size * 5 / 3 + + This slice will either mark MS words or sweep SS words. + */ + + if (caml_gc_phase == Phase_idle) start_cycle (); + + p = (double) caml_allocated_words * 3.0 * (100 + caml_percent_free) + / Wsize_bsize (caml_stat_heap_size) / caml_percent_free / 2.0; + if (caml_dependent_size > 0){ + dp = (double) caml_dependent_allocated * (100 + caml_percent_free) + / caml_dependent_size / caml_percent_free; + }else{ + dp = 0.0; + } + if (p < dp) p = dp; + if (p < caml_extra_heap_resources) p = caml_extra_heap_resources; + + caml_gc_message (0x40, "allocated_words = %" + ARCH_INTNAT_PRINTF_FORMAT "u\n", + caml_allocated_words); + caml_gc_message (0x40, "extra_heap_resources = %" + ARCH_INTNAT_PRINTF_FORMAT "uu\n", + (uintnat) (caml_extra_heap_resources * 1000000)); + caml_gc_message (0x40, "amount of work to do = %" + ARCH_INTNAT_PRINTF_FORMAT "uu\n", + (uintnat) (p * 1000000)); + + if (caml_gc_phase == Phase_mark){ + computed_work = (intnat) (p * Wsize_bsize (caml_stat_heap_size) * 250 + / (100 + caml_percent_free)); + }else{ + computed_work = (intnat) (p * Wsize_bsize (caml_stat_heap_size) * 5 / 3); + } + caml_gc_message (0x40, "ordered work = %ld words\n", howmuch); + caml_gc_message (0x40, "computed work = %ld words\n", computed_work); + if (howmuch == 0) howmuch = computed_work; + if (caml_gc_phase == Phase_mark){ + mark_slice (howmuch); + caml_gc_message (0x02, "!", 0); + }else{ + Assert (caml_gc_phase == Phase_sweep); + sweep_slice (howmuch); + caml_gc_message (0x02, "$", 0); + } + + if (caml_gc_phase == Phase_idle) caml_compact_heap_maybe (); + + caml_stat_major_words += caml_allocated_words; + caml_allocated_words = 0; + caml_dependent_allocated = 0; + caml_extra_heap_resources = 0.0; + return computed_work; +} + +/* The minor heap must be empty when this function is called; + the minor heap is empty when this function returns. +*/ +/* This does not call caml_compact_heap_maybe because the estimations of + free and live memory are only valid for a cycle done incrementally. + Besides, this function is called by caml_compact_heap_maybe. +*/ +void caml_finish_major_cycle (void) +{ + if (caml_gc_phase == Phase_idle) start_cycle (); + while (caml_gc_phase == Phase_mark) mark_slice (LONG_MAX); + Assert (caml_gc_phase == Phase_sweep); + while (caml_gc_phase == Phase_sweep) sweep_slice (LONG_MAX); + Assert (caml_gc_phase == Phase_idle); + caml_stat_major_words += caml_allocated_words; + caml_allocated_words = 0; +} + +/* Make sure the request is at least Heap_chunk_min and round it up + to a multiple of the page size. +*/ +static asize_t clip_heap_chunk_size (asize_t request) +{ + if (request < Bsize_wsize (Heap_chunk_min)){ + request = Bsize_wsize (Heap_chunk_min); + } + return ((request + Page_size - 1) >> Page_log) << Page_log; +} + +/* Make sure the request is >= caml_major_heap_increment, then call + clip_heap_chunk_size, then make sure the result is >= request. +*/ +asize_t caml_round_heap_chunk_size (asize_t request) +{ + asize_t result = request; + + if (result < caml_major_heap_increment){ + result = caml_major_heap_increment; + } + result = clip_heap_chunk_size (result); + + if (result < request){ + caml_raise_out_of_memory (); + return 0; /* not reached */ + } + return result; +} + +void caml_init_major_heap (asize_t heap_size) +{ + caml_stat_heap_size = clip_heap_chunk_size (heap_size); + caml_stat_top_heap_size = caml_stat_heap_size; + Assert (caml_stat_heap_size % Page_size == 0); + caml_heap_start = (char *) caml_alloc_for_heap (caml_stat_heap_size); + if (caml_heap_start == NULL) + caml_fatal_error ("Fatal error: not enough memory for the initial heap.\n"); + Chunk_next (caml_heap_start) = NULL; + caml_stat_heap_chunks = 1; + + if (caml_page_table_add(In_heap, caml_heap_start, + caml_heap_start + caml_stat_heap_size) != 0) { + caml_fatal_error ("Fatal error: not enough memory for the initial page table.\n"); + } + + caml_fl_init_merge (); + caml_make_free_blocks ((value *) caml_heap_start, + Wsize_bsize (caml_stat_heap_size), 1); + caml_gc_phase = Phase_idle; + gray_vals_size = 2048; + gray_vals = (value *) malloc (gray_vals_size * sizeof (value)); + if (gray_vals == NULL) + caml_fatal_error ("Fatal error: not enough memory for the gray cache.\n"); + gray_vals_cur = gray_vals; + gray_vals_end = gray_vals + gray_vals_size; + heap_is_pure = 1; + caml_allocated_words = 0; + caml_extra_heap_resources = 0.0; +} diff --git a/byterun/major_gc.h b/byterun/major_gc.h new file mode 100644 index 0000000..ed16a09 --- /dev/null +++ b/byterun/major_gc.h @@ -0,0 +1,62 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: major_gc.h,v 1.23 2008-01-11 11:55:36 doligez Exp $ */ + +#ifndef CAML_MAJOR_GC_H +#define CAML_MAJOR_GC_H + + +#include "freelist.h" +#include "misc.h" + +typedef struct { + void *block; /* address of the malloced block this chunk live in */ + asize_t alloc; /* in bytes, used for compaction */ + asize_t size; /* in bytes */ + char *next; +} heap_chunk_head; + +#define Chunk_size(c) (((heap_chunk_head *) (c)) [-1]).size +#define Chunk_alloc(c) (((heap_chunk_head *) (c)) [-1]).alloc +#define Chunk_next(c) (((heap_chunk_head *) (c)) [-1]).next +#define Chunk_block(c) (((heap_chunk_head *) (c)) [-1]).block + +extern int caml_gc_phase; +extern int caml_gc_subphase; +extern uintnat caml_allocated_words; +extern double caml_extra_heap_resources; +extern uintnat caml_dependent_size, caml_dependent_allocated; +extern uintnat caml_fl_size_at_phase_change; + +#define Phase_mark 0 +#define Phase_sweep 1 +#define Phase_idle 2 +#define Subphase_main 10 +#define Subphase_weak1 11 +#define Subphase_weak2 12 +#define Subphase_final 13 + +CAMLextern char *caml_heap_start; +extern uintnat total_heap_size; +extern char *caml_gc_sweep_hp; + +void caml_init_major_heap (asize_t); /* size in bytes */ +asize_t caml_round_heap_chunk_size (asize_t); /* size in bytes */ +void caml_darken (value, value *); +intnat caml_major_collection_slice (long); +void major_collection (void); +void caml_finish_major_cycle (void); + + +#endif /* CAML_MAJOR_GC_H */ diff --git a/byterun/md5.c b/byterun/md5.c new file mode 100644 index 0000000..cd09540 --- /dev/null +++ b/byterun/md5.c @@ -0,0 +1,311 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: md5.c,v 1.20 2006-04-16 23:28:21 doligez Exp $ */ + +#include +#include "alloc.h" +#include "fail.h" +#include "md5.h" +#include "memory.h" +#include "mlvalues.h" +#include "io.h" +#include "reverse.h" + +/* MD5 message digest */ + +CAMLprim value caml_md5_string(value str, value ofs, value len) +{ + struct MD5Context ctx; + value res; + caml_MD5Init(&ctx); + caml_MD5Update(&ctx, &Byte_u(str, Long_val(ofs)), Long_val(len)); + res = caml_alloc_string(16); + caml_MD5Final(&Byte_u(res, 0), &ctx); + return res; +} + +CAMLprim value caml_md5_chan(value vchan, value len) +{ + CAMLparam2 (vchan, len); + struct channel * chan = Channel(vchan); + struct MD5Context ctx; + value res; + intnat toread, read; + char buffer[4096]; + + Lock(chan); + caml_MD5Init(&ctx); + toread = Long_val(len); + if (toread < 0){ + while (1){ + read = caml_getblock (chan, buffer, sizeof(buffer)); + if (read == 0) break; + caml_MD5Update (&ctx, (unsigned char *) buffer, read); + } + }else{ + while (toread > 0) { + read = caml_getblock(chan, buffer, + toread > sizeof(buffer) ? sizeof(buffer) : toread); + if (read == 0) caml_raise_end_of_file(); + caml_MD5Update(&ctx, (unsigned char *) buffer, read); + toread -= read; + } + } + res = caml_alloc_string(16); + caml_MD5Final(&Byte_u(res, 0), &ctx); + Unlock(chan); + CAMLreturn (res); +} + +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to caml_MD5Init, call caml_MD5Update as + * needed on buffers full of bytes, and then call caml_MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#ifndef ARCH_BIG_ENDIAN +#define byteReverse(buf, len) /* Nothing */ +#else +static void byteReverse(unsigned char * buf, unsigned longs) +{ + uint32 t; + do { + t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(uint32 *) buf = t; + buf += 4; + } while (--longs); +} +#endif + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +CAMLexport void caml_MD5Init(struct MD5Context *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +CAMLexport void caml_MD5Update(struct MD5Context *ctx, unsigned char *buf, + uintnat len) +{ + uint32 t; + + /* Update bitcount */ + + t = ctx->bits[0]; + if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + + /* Handle any leading odd-sized chunks */ + + if (t) { + unsigned char *p = (unsigned char *) ctx->in + t; + + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + caml_MD5Transform(ctx->buf, (uint32 *) ctx->in); + buf += t; + len -= t; + } + /* Process data in 64-byte chunks */ + + while (len >= 64) { + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + caml_MD5Transform(ctx->buf, (uint32 *) ctx->in); + buf += 64; + len -= 64; + } + + /* Handle any remaining bytes of data. */ + + memcpy(ctx->in, buf, len); +} + +/* + * Final wrapup - pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +CAMLexport void caml_MD5Final(unsigned char *digest, struct MD5Context *ctx) +{ + unsigned count; + unsigned char *p; + + /* Compute number of bytes mod 64 */ + count = (ctx->bits[0] >> 3) & 0x3F; + + /* Set the first char of padding to 0x80. This is safe since there is + always at least one byte free */ + p = ctx->in + count; + *p++ = 0x80; + + /* Bytes of padding needed to make 64 bytes */ + count = 64 - 1 - count; + + /* Pad out to 56 mod 64 */ + if (count < 8) { + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + caml_MD5Transform(ctx->buf, (uint32 *) ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); + } + byteReverse(ctx->in, 14); + + /* Append length in bits and transform */ + ((uint32 *) ctx->in)[14] = ctx->bits[0]; + ((uint32 *) ctx->in)[15] = ctx->bits[1]; + + caml_MD5Transform(ctx->buf, (uint32 *) ctx->in); + byteReverse((unsigned char *) ctx->buf, 4); + memcpy(digest, ctx->buf, 16); + memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ +} + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. caml_MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +CAMLexport void caml_MD5Transform(uint32 *buf, uint32 *in) +{ + register uint32 a, b, c, d; + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + diff --git a/byterun/md5.h b/byterun/md5.h new file mode 100644 index 0000000..4280c60 --- /dev/null +++ b/byterun/md5.h @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1999 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: md5.h,v 1.13 2005-09-22 14:21:50 xleroy Exp $ */ + +/* MD5 message digest */ + +#ifndef CAML_MD5_H +#define CAML_MD5_H + + +#include "mlvalues.h" +#include "io.h" + +CAMLextern value caml_md5_string (value str, value ofs, value len); +CAMLextern value caml_md5_chan (value vchan, value len); + +struct MD5Context { + uint32 buf[4]; + uint32 bits[2]; + unsigned char in[64]; +}; + +CAMLextern void caml_MD5Init (struct MD5Context *context); +CAMLextern void caml_MD5Update (struct MD5Context *context, unsigned char *buf, + uintnat len); +CAMLextern void caml_MD5Final (unsigned char *digest, struct MD5Context *ctx); +CAMLextern void caml_MD5Transform (uint32 *buf, uint32 *in); + + +#endif /* CAML_MD5_H */ diff --git a/byterun/memory.c b/byterun/memory.c new file mode 100644 index 0000000..e25636c --- /dev/null +++ b/byterun/memory.c @@ -0,0 +1,548 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: memory.c,v 1.47 2008-12-03 18:09:09 doligez Exp $ */ + +#include +#include +#include "fail.h" +#include "freelist.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "major_gc.h" +#include "memory.h" +#include "major_gc.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "signals.h" + +extern uintnat caml_percent_free; /* major_gc.c */ + +/* Page table management */ + +#define Page(p) ((uintnat) (p) >> Page_log) +#define Page_mask ((uintnat) -1 << Page_log) + +#ifdef ARCH_SIXTYFOUR + +/* 64-bit implementation: + The page table is represented sparsely as a hash table + with linear probing */ + +struct page_table { + mlsize_t size; /* size == 1 << (wordsize - shift) */ + int shift; + mlsize_t mask; /* mask == size - 1 */ + mlsize_t occupancy; + uintnat * entries; /* [size] */ +}; + +static struct page_table caml_page_table; + +/* Page table entries are the logical 'or' of + - the key: address of a page (low Page_log bits = 0) + - the data: a 8-bit integer */ + +#define Page_entry_matches(entry,addr) \ + ((((entry) ^ (addr)) & Page_mask) == 0) + +/* Multiplicative Fibonacci hashing + (Knuth, TAOCP vol 3, section 6.4, page 518). + HASH_FACTOR is (sqrt(5) - 1) / 2 * 2^wordsize. */ +#ifdef ARCH_SIXTYFOUR +#define HASH_FACTOR 11400714819323198486UL +#else +#define HASH_FACTOR 2654435769UL +#endif +#define Hash(v) (((v) * HASH_FACTOR) >> caml_page_table.shift) + +int caml_page_table_lookup(void * addr) +{ + uintnat h, e; + + h = Hash(Page(addr)); + /* The first hit is almost always successful, so optimize for this case */ + e = caml_page_table.entries[h]; + if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF; + while(1) { + if (e == 0) return 0; + h = (h + 1) & caml_page_table.mask; + e = caml_page_table.entries[h]; + if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF; + } +} + +int caml_page_table_initialize(mlsize_t bytesize) +{ + uintnat pagesize = Page(bytesize); + + caml_page_table.size = 1; + caml_page_table.shift = 8 * sizeof(uintnat); + /* Aim for initial load factor between 1/4 and 1/2 */ + while (caml_page_table.size < 2 * pagesize) { + caml_page_table.size <<= 1; + caml_page_table.shift -= 1; + } + caml_page_table.mask = caml_page_table.size - 1; + caml_page_table.occupancy = 0; + caml_page_table.entries = calloc(caml_page_table.size, sizeof(uintnat)); + if (caml_page_table.entries == NULL) + return -1; + else + return 0; +} + +static int caml_page_table_resize(void) +{ + struct page_table old = caml_page_table; + uintnat * new_entries; + uintnat i, h; + + caml_gc_message (0x08, "Growing page table to %lu entries\n", + caml_page_table.size); + + new_entries = calloc(2 * old.size, sizeof(uintnat)); + if (new_entries == NULL) { + caml_gc_message (0x08, "No room for growing page table\n", 0); + return -1; + } + + caml_page_table.size = 2 * old.size; + caml_page_table.shift = old.shift - 1; + caml_page_table.mask = caml_page_table.size - 1; + caml_page_table.occupancy = old.occupancy; + caml_page_table.entries = new_entries; + + for (i = 0; i < old.size; i++) { + uintnat e = old.entries[i]; + if (e == 0) continue; + h = Hash(Page(e)); + while (caml_page_table.entries[h] != 0) + h = (h + 1) & caml_page_table.mask; + caml_page_table.entries[h] = e; + } + + free(old.entries); + return 0; +} + +static int caml_page_table_modify(uintnat page, int toclear, int toset) +{ + uintnat h; + + Assert ((page & ~Page_mask) == 0); + + /* Resize to keep load factor below 1/2 */ + if (caml_page_table.occupancy * 2 >= caml_page_table.size) { + if (caml_page_table_resize() != 0) return -1; + } + h = Hash(Page(page)); + while (1) { + if (caml_page_table.entries[h] == 0) { + caml_page_table.entries[h] = page | toset; + caml_page_table.occupancy++; + break; + } + if (Page_entry_matches(caml_page_table.entries[h], page)) { + caml_page_table.entries[h] = + (caml_page_table.entries[h] & ~toclear) | toset; + break; + } + h = (h + 1) & caml_page_table.mask; + } + return 0; +} + +#else + +/* 32-bit implementation: + The page table is represented as a 2-level array of unsigned char */ + +CAMLexport unsigned char * caml_page_table[Pagetable1_size]; +static unsigned char caml_page_table_empty[Pagetable2_size] = { 0, }; + +int caml_page_table_initialize(mlsize_t bytesize) +{ + int i; + for (i = 0; i < Pagetable1_size; i++) + caml_page_table[i] = caml_page_table_empty; + return 0; +} + +static int caml_page_table_modify(uintnat page, int toclear, int toset) +{ + uintnat i = Pagetable_index1(page); + uintnat j = Pagetable_index2(page); + + if (caml_page_table[i] == caml_page_table_empty) { + unsigned char * new_tbl = calloc(Pagetable2_size, 1); + if (new_tbl == 0) return -1; + caml_page_table[i] = new_tbl; + } + caml_page_table[i][j] = (caml_page_table[i][j] & ~toclear) | toset; + return 0; +} + +#endif + +int caml_page_table_add(int kind, void * start, void * end) +{ + uintnat pstart = (uintnat) start & Page_mask; + uintnat pend = ((uintnat) end - 1) & Page_mask; + uintnat p; + + for (p = pstart; p <= pend; p += Page_size) + if (caml_page_table_modify(p, 0, kind) != 0) return -1; + return 0; +} + +int caml_page_table_remove(int kind, void * start, void * end) +{ + uintnat pstart = (uintnat) start & Page_mask; + uintnat pend = ((uintnat) end - 1) & Page_mask; + uintnat p; + + for (p = pstart; p <= pend; p += Page_size) + if (caml_page_table_modify(p, kind, 0) != 0) return -1; + return 0; +} + +/* Allocate a block of the requested size, to be passed to + [caml_add_to_heap] later. + [request] must be a multiple of [Page_size]. + [caml_alloc_for_heap] returns NULL if the request cannot be satisfied. + The returned pointer is a hp, but the header must be initialized by + the caller. +*/ +char *caml_alloc_for_heap (asize_t request) +{ + char *mem; + void *block; + Assert (request % Page_size == 0); + mem = caml_aligned_malloc (request + sizeof (heap_chunk_head), + sizeof (heap_chunk_head), &block); + if (mem == NULL) return NULL; + mem += sizeof (heap_chunk_head); + Chunk_size (mem) = request; + Chunk_block (mem) = block; + return mem; +} + +/* Use this function to free a block allocated with [caml_alloc_for_heap] + if you don't add it with [caml_add_to_heap]. +*/ +void caml_free_for_heap (char *mem) +{ + free (Chunk_block (mem)); +} + +/* Take a chunk of memory as argument, which must be the result of a + call to [caml_alloc_for_heap], and insert it into the heap chaining. + The contents of the chunk must be a sequence of valid blocks and + fragments: no space between blocks and no trailing garbage. If + some blocks are blue, they must be added to the free list by the + caller. All other blocks must have the color [caml_allocation_color(m)]. + The caller must update [caml_allocated_words] if applicable. + Return value: 0 if no error; -1 in case of error. +*/ +int caml_add_to_heap (char *m) +{ + Assert (Chunk_size (m) % Page_size == 0); +#ifdef DEBUG + /* Should check the contents of the block. */ +#endif /* debug */ + + caml_gc_message (0x04, "Growing heap to %luk bytes\n", + (caml_stat_heap_size + Chunk_size (m)) / 1024); + + /* Register block in page table */ + if (caml_page_table_add(In_heap, m, m + Chunk_size(m)) != 0) + return -1; + + /* Chain this heap chunk. */ + { + char **last = &caml_heap_start; + char *cur = *last; + + while (cur != NULL && cur < m){ + last = &(Chunk_next (cur)); + cur = *last; + } + Chunk_next (m) = cur; + *last = m; + + ++ caml_stat_heap_chunks; + } + + caml_stat_heap_size += Chunk_size (m); + if (caml_stat_heap_size > caml_stat_top_heap_size){ + caml_stat_top_heap_size = caml_stat_heap_size; + } + return 0; +} + +/* Allocate more memory from malloc for the heap. + Return a blue block of at least the requested size. + The blue block is chained to a sequence of blue blocks (through their + field 0); the last block of the chain is pointed by field 1 of the + first. There may be a fragment after the last block. + The caller must insert the blocks into the free list. + The request must be less than or equal to Max_wosize. + Return NULL when out of memory. +*/ +static char *expand_heap (mlsize_t request) +{ + char *mem, *hp, *prev; + asize_t over_request, malloc_request, remain; + + Assert (request <= Max_wosize); + over_request = request + request / 100 * caml_percent_free; + malloc_request = caml_round_heap_chunk_size (Bhsize_wosize (over_request)); + mem = caml_alloc_for_heap (malloc_request); + if (mem == NULL){ + caml_gc_message (0x04, "No room for growing heap\n", 0); + return NULL; + } + remain = malloc_request; + prev = hp = mem; + /* XXX find a way to do this with a call to caml_make_free_blocks */ + while (Wosize_bhsize (remain) > Max_wosize){ + Hd_hp (hp) = Make_header (Max_wosize, 0, Caml_blue); +#ifdef DEBUG + caml_set_fields (Bp_hp (hp), 0, Debug_free_major); +#endif + hp += Bhsize_wosize (Max_wosize); + remain -= Bhsize_wosize (Max_wosize); + Field (Op_hp (mem), 1) = Field (Op_hp (prev), 0) = (value) Op_hp (hp); + prev = hp; + } + if (remain > 1){ + Hd_hp (hp) = Make_header (Wosize_bhsize (remain), 0, Caml_blue); +#ifdef DEBUG + caml_set_fields (Bp_hp (hp), 0, Debug_free_major); +#endif + Field (Op_hp (mem), 1) = Field (Op_hp (prev), 0) = (value) Op_hp (hp); + Field (Op_hp (hp), 0) = (value) NULL; + }else{ + Field (Op_hp (prev), 0) = (value) NULL; + if (remain == 1) Hd_hp (hp) = Make_header (0, 0, Caml_white); + } + Assert (Wosize_hp (mem) >= request); + if (caml_add_to_heap (mem) != 0){ + caml_free_for_heap (mem); + return NULL; + } + return Bp_hp (mem); +} + +/* Remove the heap chunk [chunk] from the heap and give the memory back + to [free]. +*/ +void caml_shrink_heap (char *chunk) +{ + char **cp; + + /* Never deallocate the first block, because caml_heap_start is both the + first block and the base address for page numbers, and we don't + want to shift the page table, it's too messy (see above). + It will never happen anyway, because of the way compaction works. + (see compact.c) + */ + if (chunk == caml_heap_start) return; + + caml_stat_heap_size -= Chunk_size (chunk); + caml_gc_message (0x04, "Shrinking heap to %luk bytes\n", + (unsigned long) caml_stat_heap_size / 1024); + +#ifdef DEBUG + { + mlsize_t i; + for (i = 0; i < Wsize_bsize (Chunk_size (chunk)); i++){ + ((value *) chunk) [i] = Debug_free_shrink; + } + } +#endif + + -- caml_stat_heap_chunks; + + /* Remove [chunk] from the list of chunks. */ + cp = &caml_heap_start; + while (*cp != chunk) cp = &(Chunk_next (*cp)); + *cp = Chunk_next (chunk); + + /* Remove the pages of [chunk] from the page table. */ + caml_page_table_remove(In_heap, chunk, chunk + Chunk_size (chunk)); + + /* Free the [malloc] block that contains [chunk]. */ + caml_free_for_heap (chunk); +} + +color_t caml_allocation_color (void *hp) +{ + if (caml_gc_phase == Phase_mark + || (caml_gc_phase == Phase_sweep && (addr)hp >= (addr)caml_gc_sweep_hp)){ + return Caml_black; + }else{ + Assert (caml_gc_phase == Phase_idle + || (caml_gc_phase == Phase_sweep + && (addr)hp < (addr)caml_gc_sweep_hp)); + return Caml_white; + } +} + +CAMLexport value caml_alloc_shr (mlsize_t wosize, tag_t tag) +{ + char *hp, *new_block; + + if (wosize > Max_wosize) caml_raise_out_of_memory (); + hp = caml_fl_allocate (wosize); + if (hp == NULL){ + new_block = expand_heap (wosize); + if (new_block == NULL) { + if (caml_in_minor_collection) + caml_fatal_error ("Fatal error: out of memory.\n"); + else + caml_raise_out_of_memory (); + } + caml_fl_add_blocks (new_block); + hp = caml_fl_allocate (wosize); + } + + Assert (Is_in_heap (Val_hp (hp))); + + /* Inline expansion of caml_allocation_color. */ + if (caml_gc_phase == Phase_mark + || (caml_gc_phase == Phase_sweep && (addr)hp >= (addr)caml_gc_sweep_hp)){ + Hd_hp (hp) = Make_header (wosize, tag, Caml_black); + }else{ + Assert (caml_gc_phase == Phase_idle + || (caml_gc_phase == Phase_sweep + && (addr)hp < (addr)caml_gc_sweep_hp)); + Hd_hp (hp) = Make_header (wosize, tag, Caml_white); + } + Assert (Hd_hp (hp) == Make_header (wosize, tag, caml_allocation_color (hp))); + caml_allocated_words += Whsize_wosize (wosize); + if (caml_allocated_words > Wsize_bsize (caml_minor_heap_size)){ + caml_urge_major_slice (); + } +#ifdef DEBUG + { + uintnat i; + for (i = 0; i < wosize; i++){ + Field (Val_hp (hp), i) = Debug_uninit_major; + } + } +#endif + return Val_hp (hp); +} + +/* Dependent memory is all memory blocks allocated out of the heap + that depend on the GC (and finalizers) for deallocation. + For the GC to take dependent memory into account when computing + its automatic speed setting, + you must call [caml_alloc_dependent_memory] when you alloate some + dependent memory, and [caml_free_dependent_memory] when you + free it. In both cases, you pass as argument the size (in bytes) + of the block being allocated or freed. +*/ +CAMLexport void caml_alloc_dependent_memory (mlsize_t nbytes) +{ + caml_dependent_size += nbytes / sizeof (value); + caml_dependent_allocated += nbytes / sizeof (value); +} + +CAMLexport void caml_free_dependent_memory (mlsize_t nbytes) +{ + if (caml_dependent_size < nbytes / sizeof (value)){ + caml_dependent_size = 0; + }else{ + caml_dependent_size -= nbytes / sizeof (value); + } +} + +/* Use this function to tell the major GC to speed up when you use + finalized blocks to automatically deallocate resources (other + than memory). The GC will do at least one cycle every [max] + allocated resources; [res] is the number of resources allocated + this time. + Note that only [res/max] is relevant. The units (and kind of + resource) can change between calls to [caml_adjust_gc_speed]. +*/ +CAMLexport void caml_adjust_gc_speed (mlsize_t res, mlsize_t max) +{ + if (max == 0) max = 1; + if (res > max) res = max; + caml_extra_heap_resources += (double) res / (double) max; + if (caml_extra_heap_resources > 1.0){ + caml_extra_heap_resources = 1.0; + caml_urge_major_slice (); + } + if (caml_extra_heap_resources + > (double) Wsize_bsize (caml_minor_heap_size) / 2.0 + / (double) Wsize_bsize (caml_stat_heap_size)) { + caml_urge_major_slice (); + } +} + +/* You must use [caml_initialize] to store the initial value in a field of + a shared block, unless you are sure the value is not a young block. + A block value [v] is a shared block if and only if [Is_in_heap (v)] + is true. +*/ +/* [caml_initialize] never calls the GC, so you may call it while an block is + unfinished (i.e. just after a call to [caml_alloc_shr].) */ +void caml_initialize (value *fp, value val) +{ + *fp = val; + if (Is_block (val) && Is_young (val) && Is_in_heap (fp)){ + if (caml_ref_table.ptr >= caml_ref_table.limit){ + caml_realloc_ref_table (&caml_ref_table); + } + *caml_ref_table.ptr++ = fp; + } +} + +/* You must use [caml_modify] to change a field of an existing shared block, + unless you are sure the value being overwritten is not a shared block and + the value being written is not a young block. */ +/* [caml_modify] never calls the GC. */ +void caml_modify (value *fp, value val) +{ + Modify (fp, val); +} + +CAMLexport void * caml_stat_alloc (asize_t sz) +{ + void * result = malloc (sz); + + /* malloc() may return NULL if size is 0 */ + if (result == NULL && sz != 0) caml_raise_out_of_memory (); +#ifdef DEBUG + memset (result, Debug_uninit_stat, sz); +#endif + return result; +} + +CAMLexport void caml_stat_free (void * blk) +{ + free (blk); +} + +CAMLexport void * caml_stat_resize (void * blk, asize_t sz) +{ + void * result = realloc (blk, sz); + + if (result == NULL) caml_raise_out_of_memory (); + return result; +} diff --git a/byterun/memory.h b/byterun/memory.h new file mode 100644 index 0000000..42777bb --- /dev/null +++ b/byterun/memory.h @@ -0,0 +1,459 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: memory.h,v 1.60 2008-12-03 18:09:09 doligez Exp $ */ + +/* Allocation macros and functions */ + +#ifndef CAML_MEMORY_H +#define CAML_MEMORY_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "config.h" +/* */ +#include "gc.h" +#include "major_gc.h" +#include "minor_gc.h" +/* */ +#include "misc.h" +#include "mlvalues.h" + +CAMLextern value caml_alloc_shr (mlsize_t, tag_t); +CAMLextern void caml_adjust_gc_speed (mlsize_t, mlsize_t); +CAMLextern void caml_alloc_dependent_memory (mlsize_t); +CAMLextern void caml_free_dependent_memory (mlsize_t); +CAMLextern void caml_modify (value *, value); +CAMLextern void caml_initialize (value *, value); +CAMLextern value caml_check_urgent_gc (value); +CAMLextern void * caml_stat_alloc (asize_t); /* Size in bytes. */ +CAMLextern void caml_stat_free (void *); +CAMLextern void * caml_stat_resize (void *, asize_t); /* Size in bytes. */ +char *caml_alloc_for_heap (asize_t request); /* Size in bytes. */ +void caml_free_for_heap (char *mem); +int caml_add_to_heap (char *mem); +color_t caml_allocation_color (void *hp); + +/* void caml_shrink_heap (char *); Only used in compact.c */ + +/* */ + +#define Not_in_heap 0 +#define In_heap 1 +#define In_young 2 +#define In_static_data 4 +#define In_code_area 8 + +#ifdef ARCH_SIXTYFOUR + +/* 64 bits: Represent page table as a sparse hash table */ +int caml_page_table_lookup(void * addr); +#define Classify_addr(a) (caml_page_table_lookup((void *)(a))) + +#else + +/* 32 bits: Represent page table as a 2-level array */ +#define Pagetable2_log 11 +#define Pagetable2_size (1 << Pagetable2_log) +#define Pagetable1_log (Page_log + Pagetable2_log) +#define Pagetable1_size (1 << (32 - Pagetable1_log)) +CAMLextern unsigned char * caml_page_table[Pagetable1_size]; + +#define Pagetable_index1(a) (((uintnat)(a)) >> Pagetable1_log) +#define Pagetable_index2(a) \ + ((((uintnat)(a)) >> Page_log) & (Pagetable2_size - 1)) +#define Classify_addr(a) \ + caml_page_table[Pagetable_index1(a)][Pagetable_index2(a)] + +#endif + +#define Is_in_value_area(a) \ + (Classify_addr(a) & (In_heap | In_young | In_static_data)) +#define Is_in_heap(a) (Classify_addr(a) & In_heap) +#define Is_in_heap_or_young(a) (Classify_addr(a) & (In_heap | In_young)) + +int caml_page_table_add(int kind, void * start, void * end); +int caml_page_table_remove(int kind, void * start, void * end); +int caml_page_table_initialize(mlsize_t bytesize); + +#ifdef DEBUG +#define DEBUG_clear(result, wosize) do{ \ + uintnat caml__DEBUG_i; \ + for (caml__DEBUG_i = 0; caml__DEBUG_i < (wosize); ++ caml__DEBUG_i){ \ + Field ((result), caml__DEBUG_i) = Debug_uninit_minor; \ + } \ +}while(0) +#else +#define DEBUG_clear(result, wosize) +#endif + +#define Alloc_small(result, wosize, tag) do{ CAMLassert ((wosize) >= 1); \ + CAMLassert ((tag_t) (tag) < 256); \ + CAMLassert ((wosize) <= Max_young_wosize); \ + caml_young_ptr -= Bhsize_wosize (wosize); \ + if (caml_young_ptr < caml_young_limit){ \ + caml_young_ptr += Bhsize_wosize (wosize); \ + Setup_for_gc; \ + caml_minor_collection (); \ + Restore_after_gc; \ + caml_young_ptr -= Bhsize_wosize (wosize); \ + } \ + Hd_hp (caml_young_ptr) = Make_header ((wosize), (tag), Caml_black); \ + (result) = Val_hp (caml_young_ptr); \ + DEBUG_clear ((result), (wosize)); \ +}while(0) + +/* You must use [Modify] to change a field of an existing shared block, + unless you are sure the value being overwritten is not a shared block and + the value being written is not a young block. */ +/* [Modify] never calls the GC. */ +/* [Modify] can also be used to do assignment on data structures that are + not in the (major) heap. In this case, it is a bit slower than + simple assignment. + In particular, you can use [Modify] when you don't know whether the + block being changed is in the minor heap or the major heap. +*/ + +#define Modify(fp, val) do{ \ + value _old_ = *(fp); \ + *(fp) = (val); \ + if (Is_in_heap (fp)){ \ + if (caml_gc_phase == Phase_mark) caml_darken (_old_, NULL); \ + if (Is_block (val) && Is_young (val) \ + && ! (Is_block (_old_) && Is_young (_old_))){ \ + if (caml_ref_table.ptr >= caml_ref_table.limit){ \ + CAMLassert (caml_ref_table.ptr == caml_ref_table.limit); \ + caml_realloc_ref_table (&caml_ref_table); \ + } \ + *caml_ref_table.ptr++ = (fp); \ + } \ + } \ +}while(0) + +/* */ + +struct caml__roots_block { + struct caml__roots_block *next; + intnat ntables; + intnat nitems; + value *tables [5]; +}; + +CAMLextern struct caml__roots_block *caml_local_roots; /* defined in roots.c */ + +/* The following macros are used to declare C local variables and + function parameters of type [value]. + + The function body must start with one of the [CAMLparam] macros. + If the function has no parameter of type [value], use [CAMLparam0]. + If the function has 1 to 5 [value] parameters, use the corresponding + [CAMLparam] with the parameters as arguments. + If the function has more than 5 [value] parameters, use [CAMLparam5] + for the first 5 parameters, and one or more calls to the [CAMLxparam] + macros for the others. + If the function takes an array of [value]s as argument, use + [CAMLparamN] to declare it (or [CAMLxparamN] if you already have a + call to [CAMLparam] for some other arguments). + + If you need local variables of type [value], declare them with one + or more calls to the [CAMLlocal] macros at the beginning of the + function. Use [CAMLlocalN] (at the beginning of the function) to + declare an array of [value]s. + + Your function may raise an exception or return a [value] with the + [CAMLreturn] macro. Its argument is simply the [value] returned by + your function. Do NOT directly return a [value] with the [return] + keyword. If your function returns void, use [CAMLreturn0]. + + All the identifiers beginning with "caml__" are reserved by Caml. + Do not use them for anything (local or global variables, struct or + union tags, macros, etc.) +*/ + +#define CAMLparam0() \ + struct caml__roots_block *caml__frame = caml_local_roots + +#define CAMLparam1(x) \ + CAMLparam0 (); \ + CAMLxparam1 (x) + +#define CAMLparam2(x, y) \ + CAMLparam0 (); \ + CAMLxparam2 (x, y) + +#define CAMLparam3(x, y, z) \ + CAMLparam0 (); \ + CAMLxparam3 (x, y, z) + +#define CAMLparam4(x, y, z, t) \ + CAMLparam0 (); \ + CAMLxparam4 (x, y, z, t) + +#define CAMLparam5(x, y, z, t, u) \ + CAMLparam0 (); \ + CAMLxparam5 (x, y, z, t, u) + +#define CAMLparamN(x, size) \ + CAMLparam0 (); \ + CAMLxparamN (x, (size)) + + +#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 7)) + #define CAMLunused __attribute__ ((unused)) +#else + #define CAMLunused +#endif + +#define CAMLxparam1(x) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 1), \ + (caml__roots_##x.tables [0] = &x), \ + 0) + +#define CAMLxparam2(x, y) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 2), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + 0) + +#define CAMLxparam3(x, y, z) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 3), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + 0) + +#define CAMLxparam4(x, y, z, t) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 4), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + (caml__roots_##x.tables [3] = &t), \ + 0) + +#define CAMLxparam5(x, y, z, t, u) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 5), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + (caml__roots_##x.tables [3] = &t), \ + (caml__roots_##x.tables [4] = &u), \ + 0) + +#define CAMLxparamN(x, size) \ + struct caml__roots_block caml__roots_##x; \ + CAMLunused int caml__dummy_##x = ( \ + (caml__roots_##x.next = caml_local_roots), \ + (caml_local_roots = &caml__roots_##x), \ + (caml__roots_##x.nitems = (size)), \ + (caml__roots_##x.ntables = 1), \ + (caml__roots_##x.tables[0] = &(x[0])), \ + 0) + +#define CAMLlocal1(x) \ + value x = 0; \ + CAMLxparam1 (x) + +#define CAMLlocal2(x, y) \ + value x = 0, y = 0; \ + CAMLxparam2 (x, y) + +#define CAMLlocal3(x, y, z) \ + value x = 0, y = 0, z = 0; \ + CAMLxparam3 (x, y, z) + +#define CAMLlocal4(x, y, z, t) \ + value x = 0, y = 0, z = 0, t = 0; \ + CAMLxparam4 (x, y, z, t) + +#define CAMLlocal5(x, y, z, t, u) \ + value x = 0, y = 0, z = 0, t = 0, u = 0; \ + CAMLxparam5 (x, y, z, t, u) + +#define CAMLlocalN(x, size) \ + value x [(size)] = { 0, /* 0, 0, ... */ }; \ + CAMLxparamN (x, (size)) + + +#define CAMLreturn0 do{ \ + caml_local_roots = caml__frame; \ + return; \ +}while (0) + +#define CAMLreturnT(type, result) do{ \ + type caml__temp_result = (result); \ + caml_local_roots = caml__frame; \ + return (caml__temp_result); \ +}while(0) + +#define CAMLreturn(result) CAMLreturnT(value, result) + +#define CAMLnoreturn ((void) caml__frame) + + +/* convenience macro */ +#define Store_field(block, offset, val) do{ \ + mlsize_t caml__temp_offset = (offset); \ + value caml__temp_val = (val); \ + caml_modify (&Field ((block), caml__temp_offset), caml__temp_val); \ +}while(0) + +/* + NOTE: [Begin_roots] and [End_roots] are superseded by [CAMLparam]*, + [CAMLxparam]*, [CAMLlocal]*, [CAMLreturn]. + + [Begin_roots] and [End_roots] are used for C variables that are GC roots. + It must contain all values in C local variables and function parameters + at the time the minor GC is called. + Usage: + After initialising your local variables to legal Caml values, but before + calling allocation functions, insert [Begin_roots_n(v1, ... vn)], where + v1 ... vn are your variables of type [value] that you want to be updated + across allocations. + At the end, insert [End_roots()]. + + Note that [Begin_roots] opens a new block, and [End_roots] closes it. + Thus they must occur in matching pairs at the same brace nesting level. + + You can use [Val_unit] as a dummy initial value for your variables. +*/ + +#define Begin_root Begin_roots1 + +#define Begin_roots1(r0) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = 1; \ + caml__roots_block.ntables = 1; \ + caml__roots_block.tables[0] = &(r0); + +#define Begin_roots2(r0, r1) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = 1; \ + caml__roots_block.ntables = 2; \ + caml__roots_block.tables[0] = &(r0); \ + caml__roots_block.tables[1] = &(r1); + +#define Begin_roots3(r0, r1, r2) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = 1; \ + caml__roots_block.ntables = 3; \ + caml__roots_block.tables[0] = &(r0); \ + caml__roots_block.tables[1] = &(r1); \ + caml__roots_block.tables[2] = &(r2); + +#define Begin_roots4(r0, r1, r2, r3) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = 1; \ + caml__roots_block.ntables = 4; \ + caml__roots_block.tables[0] = &(r0); \ + caml__roots_block.tables[1] = &(r1); \ + caml__roots_block.tables[2] = &(r2); \ + caml__roots_block.tables[3] = &(r3); + +#define Begin_roots5(r0, r1, r2, r3, r4) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = 1; \ + caml__roots_block.ntables = 5; \ + caml__roots_block.tables[0] = &(r0); \ + caml__roots_block.tables[1] = &(r1); \ + caml__roots_block.tables[2] = &(r2); \ + caml__roots_block.tables[3] = &(r3); \ + caml__roots_block.tables[4] = &(r4); + +#define Begin_roots_block(table, size) { \ + struct caml__roots_block caml__roots_block; \ + caml__roots_block.next = caml_local_roots; \ + caml_local_roots = &caml__roots_block; \ + caml__roots_block.nitems = (size); \ + caml__roots_block.ntables = 1; \ + caml__roots_block.tables[0] = (table); + +#define End_roots() caml_local_roots = caml__roots_block.next; } + + +/* [caml_register_global_root] registers a global C variable as a memory root + for the duration of the program, or until [caml_remove_global_root] is + called. */ + +CAMLextern void caml_register_global_root (value *); + +/* [caml_remove_global_root] removes a memory root registered on a global C + variable with [caml_register_global_root]. */ + +CAMLextern void caml_remove_global_root (value *); + +/* [caml_register_generational_global_root] registers a global C + variable as a memory root for the duration of the program, or until + [caml_remove_generational_global_root] is called. + The program guarantees that the value contained in this variable + will not be assigned directly. If the program needs to change + the value of this variable, it must do so by calling + [caml_modify_generational_global_root]. The [value *] pointer + passed to [caml_register_generational_global_root] must contain + a valid Caml value before the call. + In return for these constraints, scanning of memory roots during + minor collection is made more efficient. */ + +CAMLextern void caml_register_generational_global_root (value *); + +/* [caml_remove_generational_global_root] removes a memory root + registered on a global C variable with + [caml_register_generational_global_root]. */ + +CAMLextern void caml_remove_generational_global_root (value *); + +/* [caml_modify_generational_global_root(r, newval)] + modifies the value contained in [r], storing [newval] inside. + In other words, the assignment [*r = newval] is performed, + but in a way that is compatible with the optimized scanning of + generational global roots. [r] must be a global memory root + previously registered with [caml_register_generational_global_root]. */ + +CAMLextern void caml_modify_generational_global_root(value *r, value newval); + +#endif /* CAML_MEMORY_H */ diff --git a/byterun/meta.c b/byterun/meta.c new file mode 100644 index 0000000..d09fab5 --- /dev/null +++ b/byterun/meta.c @@ -0,0 +1,174 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: meta.c,v 1.33 2008-01-31 09:13:19 frisch Exp $ */ + +/* Primitives for the toplevel */ + +#include "alloc.h" +#include "config.h" +#include "fail.h" +#include "fix_code.h" +#include "interp.h" +#include "intext.h" +#include "major_gc.h" +#include "memory.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "prims.h" +#include "stacks.h" + +#ifndef NATIVE_CODE + +CAMLprim value caml_get_global_data(value unit) +{ + return caml_global_data; +} + +char * caml_section_table = NULL; +asize_t caml_section_table_size; + +CAMLprim value caml_get_section_table(value unit) +{ + if (caml_section_table == NULL) caml_raise_not_found(); + return caml_input_value_from_block(caml_section_table, + caml_section_table_size); +} + +CAMLprim value caml_reify_bytecode(value prog, value len) +{ + value clos; +#ifdef ARCH_BIG_ENDIAN + caml_fixup_endianness((code_t) prog, (asize_t) Long_val(len)); +#endif +#ifdef THREADED_CODE + caml_thread_code((code_t) prog, (asize_t) Long_val(len)); +#endif + caml_prepare_bytecode((code_t) prog, (asize_t) Long_val(len)); + clos = caml_alloc_small (1, Closure_tag); + Code_val(clos) = (code_t) prog; + return clos; +} + +CAMLprim value caml_realloc_global(value size) +{ + mlsize_t requested_size, actual_size, i; + value new_global_data; + + requested_size = Long_val(size); + actual_size = Wosize_val(caml_global_data); + if (requested_size >= actual_size) { + requested_size = (requested_size + 0x100) & 0xFFFFFF00; + caml_gc_message (0x08, "Growing global data to %lu entries\n", + requested_size); + new_global_data = caml_alloc_shr(requested_size, 0); + for (i = 0; i < actual_size; i++) + caml_initialize(&Field(new_global_data, i), Field(caml_global_data, i)); + for (i = actual_size; i < requested_size; i++){ + Field (new_global_data, i) = Val_long (0); + } + caml_global_data = new_global_data; + } + return Val_unit; +} + +CAMLprim value caml_get_current_environment(value unit) +{ + return *caml_extern_sp; +} + +CAMLprim value caml_invoke_traced_function(value codeptr, value env, value arg) +{ + /* Stack layout on entry: + return frame into instrument_closure function + arg3 to call_original_code (arg) + arg2 to call_original_code (env) + arg1 to call_original_code (codeptr) + arg3 to call_original_code (arg) + arg2 to call_original_code (env) + saved env */ + + /* Stack layout on exit: + return frame into instrument_closure function + actual arg to code (arg) + pseudo return frame into codeptr: + extra_args = 0 + environment = env + PC = codeptr + arg3 to call_original_code (arg) same 6 bottom words as + arg2 to call_original_code (env) on entrance, but + arg1 to call_original_code (codeptr) shifted down 4 words + arg3 to call_original_code (arg) + arg2 to call_original_code (env) + saved env */ + + value * osp, * nsp; + int i; + + osp = caml_extern_sp; + caml_extern_sp -= 4; + nsp = caml_extern_sp; + for (i = 0; i < 6; i++) nsp[i] = osp[i]; + nsp[6] = codeptr; + nsp[7] = env; + nsp[8] = Val_int(0); + nsp[9] = arg; + return Val_unit; +} + +#else + +/* Dummy definitions to support compilation of ocamlc.opt */ + +value caml_get_global_data(value unit) +{ + caml_invalid_argument("Meta.get_global_data"); + return Val_unit; /* not reached */ +} + +value caml_get_section_table(value unit) +{ + caml_invalid_argument("Meta.get_section_table"); + return Val_unit; /* not reached */ +} + +value caml_realloc_global(value size) +{ + caml_invalid_argument("Meta.realloc_global"); + return Val_unit; /* not reached */ +} + +value caml_invoke_traced_function(value codeptr, value env, value arg) +{ + caml_invalid_argument("Meta.invoke_traced_function"); + return Val_unit; /* not reached */ +} + +value caml_reify_bytecode(value prog, value len) +{ + caml_invalid_argument("Meta.reify_bytecode"); + return Val_unit; /* not reached */ +} + +value * caml_stack_low; +value * caml_stack_high; +value * caml_stack_threshold; +value * caml_extern_sp; +value * caml_trapsp; +int caml_callback_depth; +int volatile caml_something_to_do; +void (* volatile caml_async_action_hook)(void); +struct longjmp_buffer * caml_external_raise; + +#endif diff --git a/byterun/minor_gc.c b/byterun/minor_gc.c new file mode 100644 index 0000000..1b871eb --- /dev/null +++ b/byterun/minor_gc.c @@ -0,0 +1,321 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: minor_gc.c,v 1.47 2008-07-28 12:03:55 doligez Exp $ */ + +#include +#include "config.h" +#include "fail.h" +#include "finalise.h" +#include "gc.h" +#include "gc_ctrl.h" +#include "major_gc.h" +#include "memory.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "roots.h" +#include "signals.h" +#include "weak.h" + +asize_t caml_minor_heap_size; +static void *caml_young_base = NULL; +CAMLexport char *caml_young_start = NULL, *caml_young_end = NULL; +CAMLexport char *caml_young_ptr = NULL, *caml_young_limit = NULL; + +CAMLexport struct caml_ref_table + caml_ref_table = { NULL, NULL, NULL, NULL, NULL, 0, 0}, + caml_weak_ref_table = { NULL, NULL, NULL, NULL, NULL, 0, 0}; + +int caml_in_minor_collection = 0; + +#ifdef DEBUG +static unsigned long minor_gc_counter = 0; +#endif + +void caml_alloc_table (struct caml_ref_table *tbl, asize_t sz, asize_t rsv) +{ + value **new_table; + + tbl->size = sz; + tbl->reserve = rsv; + new_table = (value **) caml_stat_alloc ((tbl->size + tbl->reserve) + * sizeof (value *)); + if (tbl->base != NULL) caml_stat_free (tbl->base); + tbl->base = new_table; + tbl->ptr = tbl->base; + tbl->threshold = tbl->base + tbl->size; + tbl->limit = tbl->threshold; + tbl->end = tbl->base + tbl->size + tbl->reserve; +} + +static void reset_table (struct caml_ref_table *tbl) +{ + tbl->size = 0; + tbl->reserve = 0; + if (tbl->base != NULL) caml_stat_free (tbl->base); + tbl->base = tbl->ptr = tbl->threshold = tbl->limit = tbl->end = NULL; +} + +static void clear_table (struct caml_ref_table *tbl) +{ + tbl->ptr = tbl->base; + tbl->limit = tbl->threshold; +} + +void caml_set_minor_heap_size (asize_t size) +{ + char *new_heap; + void *new_heap_base; + + Assert (size >= Minor_heap_min); + Assert (size <= Minor_heap_max); + Assert (size % sizeof (value) == 0); + if (caml_young_ptr != caml_young_end) caml_minor_collection (); + Assert (caml_young_ptr == caml_young_end); + new_heap = caml_aligned_malloc(size, 0, &new_heap_base); + if (new_heap == NULL) caml_raise_out_of_memory(); + if (caml_page_table_add(In_young, new_heap, new_heap + size) != 0) + caml_raise_out_of_memory(); + + if (caml_young_start != NULL){ + caml_page_table_remove(In_young, caml_young_start, caml_young_end); + free (caml_young_base); + } + caml_young_base = new_heap_base; + caml_young_start = new_heap; + caml_young_end = new_heap + size; + caml_young_limit = caml_young_start; + caml_young_ptr = caml_young_end; + caml_minor_heap_size = size; + + reset_table (&caml_ref_table); + reset_table (&caml_weak_ref_table); +} + +static value oldify_todo_list = 0; + +/* Note that the tests on the tag depend on the fact that Infix_tag, + Forward_tag, and No_scan_tag are contiguous. */ + +void caml_oldify_one (value v, value *p) +{ + value result; + header_t hd; + mlsize_t sz, i; + tag_t tag; + + tail_call: + if (Is_block (v) && Is_young (v)){ + Assert (Hp_val (v) >= caml_young_ptr); + hd = Hd_val (v); + if (hd == 0){ /* If already forwarded */ + *p = Field (v, 0); /* then forward pointer is first field. */ + }else{ + tag = Tag_hd (hd); + if (tag < Infix_tag){ + value field0; + + sz = Wosize_hd (hd); + result = caml_alloc_shr (sz, tag); + *p = result; + field0 = Field (v, 0); + Hd_val (v) = 0; /* Set forward flag */ + Field (v, 0) = result; /* and forward pointer. */ + if (sz > 1){ + Field (result, 0) = field0; + Field (result, 1) = oldify_todo_list; /* Add this block */ + oldify_todo_list = v; /* to the "to do" list. */ + }else{ + Assert (sz == 1); + p = &Field (result, 0); + v = field0; + goto tail_call; + } + }else if (tag >= No_scan_tag){ + sz = Wosize_hd (hd); + result = caml_alloc_shr (sz, tag); + for (i = 0; i < sz; i++) Field (result, i) = Field (v, i); + Hd_val (v) = 0; /* Set forward flag */ + Field (v, 0) = result; /* and forward pointer. */ + *p = result; + }else if (tag == Infix_tag){ + mlsize_t offset = Infix_offset_hd (hd); + caml_oldify_one (v - offset, p); /* Cannot recurse deeper than 1. */ + *p += offset; + }else{ + value f = Forward_val (v); + tag_t ft = 0; + int vv = 1; + + Assert (tag == Forward_tag); + if (Is_block (f)){ + vv = Is_in_value_area(f); + if (vv) { + ft = Tag_val (Hd_val (f) == 0 ? Field (f, 0) : f); + } + } + if (!vv || ft == Forward_tag || ft == Lazy_tag || ft == Double_tag){ + /* Do not short-circuit the pointer. Copy as a normal block. */ + Assert (Wosize_hd (hd) == 1); + result = caml_alloc_shr (1, Forward_tag); + *p = result; + Hd_val (v) = 0; /* Set (GC) forward flag */ + Field (v, 0) = result; /* and forward pointer. */ + p = &Field (result, 0); + v = f; + goto tail_call; + }else{ + v = f; /* Follow the forwarding */ + goto tail_call; /* then oldify. */ + } + } + } + }else{ + *p = v; + } +} + +/* Finish the work that was put off by [caml_oldify_one]. + Note that [caml_oldify_one] itself is called by oldify_mopup, so we + have to be careful to remove the first entry from the list before + oldifying its fields. */ +void caml_oldify_mopup (void) +{ + value v, new_v, f; + mlsize_t i; + + while (oldify_todo_list != 0){ + v = oldify_todo_list; /* Get the head. */ + Assert (Hd_val (v) == 0); /* It must be forwarded. */ + new_v = Field (v, 0); /* Follow forward pointer. */ + oldify_todo_list = Field (new_v, 1); /* Remove from list. */ + + f = Field (new_v, 0); + if (Is_block (f) && Is_young (f)){ + caml_oldify_one (f, &Field (new_v, 0)); + } + for (i = 1; i < Wosize_val (new_v); i++){ + f = Field (v, i); + if (Is_block (f) && Is_young (f)){ + caml_oldify_one (f, &Field (new_v, i)); + }else{ + Field (new_v, i) = f; + } + } + } +} + +/* Make sure the minor heap is empty by performing a minor collection + if needed. +*/ +void caml_empty_minor_heap (void) +{ + value **r; + + if (caml_young_ptr != caml_young_end){ + caml_in_minor_collection = 1; + caml_gc_message (0x02, "<", 0); + caml_oldify_local_roots(); + for (r = caml_ref_table.base; r < caml_ref_table.ptr; r++){ + caml_oldify_one (**r, *r); + } + caml_oldify_mopup (); + for (r = caml_weak_ref_table.base; r < caml_weak_ref_table.ptr; r++){ + if (Is_block (**r) && Is_young (**r)){ + if (Hd_val (**r) == 0){ + **r = Field (**r, 0); + }else{ + **r = caml_weak_none; + } + } + } + if (caml_young_ptr < caml_young_start) caml_young_ptr = caml_young_start; + caml_stat_minor_words += Wsize_bsize (caml_young_end - caml_young_ptr); + caml_young_ptr = caml_young_end; + caml_young_limit = caml_young_start; + clear_table (&caml_ref_table); + clear_table (&caml_weak_ref_table); + caml_gc_message (0x02, ">", 0); + caml_in_minor_collection = 0; + } + caml_final_empty_young (); +#ifdef DEBUG + { + value *p; + for (p = (value *) caml_young_start; p < (value *) caml_young_end; ++p){ + *p = Debug_free_minor; + } + ++ minor_gc_counter; + } +#endif +} + +/* Do a minor collection and a slice of major collection, call finalisation + functions, etc. + Leave the minor heap empty. +*/ +CAMLexport void caml_minor_collection (void) +{ + intnat prev_alloc_words = caml_allocated_words; + + caml_empty_minor_heap (); + + caml_stat_promoted_words += caml_allocated_words - prev_alloc_words; + ++ caml_stat_minor_collections; + caml_major_collection_slice (0); + caml_force_major_slice = 0; + + caml_final_do_calls (); + + caml_empty_minor_heap (); +} + +CAMLexport value caml_check_urgent_gc (value extra_root) +{ + CAMLparam1 (extra_root); + if (caml_force_major_slice) caml_minor_collection(); + CAMLreturn (extra_root); +} + +void caml_realloc_ref_table (struct caml_ref_table *tbl) +{ Assert (tbl->ptr == tbl->limit); + Assert (tbl->limit <= tbl->end); + Assert (tbl->limit >= tbl->threshold); + + if (tbl->base == NULL){ + caml_alloc_table (tbl, caml_minor_heap_size / sizeof (value) / 8, 256); + }else if (tbl->limit == tbl->threshold){ + caml_gc_message (0x08, "ref_table threshold crossed\n", 0); + tbl->limit = tbl->end; + caml_urge_major_slice (); + }else{ /* This will almost never happen with the bytecode interpreter. */ + asize_t sz; + asize_t cur_ptr = tbl->ptr - tbl->base; + Assert (caml_force_major_slice); + + tbl->size *= 2; + sz = (tbl->size + tbl->reserve) * sizeof (value *); + caml_gc_message (0x08, "Growing ref_table to %" + ARCH_INTNAT_PRINTF_FORMAT "dk bytes\n", + (intnat) sz/1024); + tbl->base = (value **) realloc ((char *) tbl->base, sz); + if (tbl->base == NULL){ + caml_fatal_error ("Fatal error: ref_table overflow\n"); + } + tbl->end = tbl->base + tbl->size + tbl->reserve; + tbl->threshold = tbl->base + tbl->size; + tbl->ptr = tbl->base + cur_ptr; + tbl->limit = tbl->end; + } +} diff --git a/byterun/minor_gc.h b/byterun/minor_gc.h new file mode 100644 index 0000000..0ef99cc --- /dev/null +++ b/byterun/minor_gc.h @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: minor_gc.h,v 1.18 2007-05-04 14:05:13 doligez Exp $ */ + +#ifndef CAML_MINOR_GC_H +#define CAML_MINOR_GC_H + + +#include "misc.h" + +CAMLextern char *caml_young_start, *caml_young_ptr; +CAMLextern char *caml_young_end, *caml_young_limit; +extern asize_t caml_minor_heap_size; +extern int caml_in_minor_collection; + +struct caml_ref_table { + value **base; + value **end; + value **threshold; + value **ptr; + value **limit; + asize_t size; + asize_t reserve; +}; +CAMLextern struct caml_ref_table caml_ref_table, caml_weak_ref_table; + +#define Is_young(val) \ + (Assert (Is_block (val)), \ + (addr)(val) < (addr)caml_young_end && (addr)(val) > (addr)caml_young_start) + +extern void caml_set_minor_heap_size (asize_t); +extern void caml_empty_minor_heap (void); +CAMLextern void caml_minor_collection (void); +CAMLextern void garbage_collection (void); /* def in asmrun/signals.c */ +extern void caml_realloc_ref_table (struct caml_ref_table *); +extern void caml_alloc_table (struct caml_ref_table *, asize_t, asize_t); +extern void caml_oldify_one (value, value *); +extern void caml_oldify_mopup (void); + +#define Oldify(p) do{ \ + value __oldify__v__ = *p; \ + if (Is_block (__oldify__v__) && Is_young (__oldify__v__)){ \ + caml_oldify_one (__oldify__v__, (p)); \ + } \ + }while(0) + +#endif /* CAML_MINOR_GC_H */ diff --git a/byterun/misc.c b/byterun/misc.c new file mode 100644 index 0000000..05c4955 --- /dev/null +++ b/byterun/misc.c @@ -0,0 +1,125 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: misc.c,v 1.29 2008-02-29 12:56:15 doligez Exp $ */ + +#include +#include "config.h" +#include "misc.h" +#include "memory.h" + +#ifdef DEBUG + +int caml_failed_assert (char * expr, char * file, int line) +{ + fprintf (stderr, "file %s; line %d ### Assertion failed: %s\n", + file, line, expr); + fflush (stderr); + exit (100); + return 1; /* not reached */ +} + +void caml_set_fields (char *bp, unsigned long start, unsigned long filler) +{ + mlsize_t i; + for (i = start; i < Wosize_bp (bp); i++){ + Field (Val_bp (bp), i) = (value) filler; + } +} + +#endif /* DEBUG */ + +uintnat caml_verb_gc = 0; + +void caml_gc_message (int level, char *msg, uintnat arg) +{ + if (level < 0 || (caml_verb_gc & level) != 0){ + fprintf (stderr, msg, arg); + fflush (stderr); + } +} + +CAMLexport void caml_fatal_error (char *msg) +{ + fprintf (stderr, "%s", msg); + exit(2); +} + +CAMLexport void caml_fatal_error_arg (char *fmt, char *arg) +{ + fprintf (stderr, fmt, arg); + exit(2); +} + +CAMLexport void caml_fatal_error_arg2 (char *fmt1, char *arg1, + char *fmt2, char *arg2) +{ + fprintf (stderr, fmt1, arg1); + fprintf (stderr, fmt2, arg2); + exit(2); +} + +char *caml_aligned_malloc (asize_t size, int modulo, void **block) +{ + char *raw_mem; + uintnat aligned_mem; + Assert (modulo < Page_size); + raw_mem = (char *) malloc (size + Page_size); + if (raw_mem == NULL) return NULL; + *block = raw_mem; + raw_mem += modulo; /* Address to be aligned */ + aligned_mem = (((uintnat) raw_mem / Page_size + 1) * Page_size); +#ifdef DEBUG + { + uintnat *p; + uintnat *p0 = (void *) *block, + *p1 = (void *) (aligned_mem - modulo), + *p2 = (void *) (aligned_mem - modulo + size), + *p3 = (void *) ((char *) *block + size + Page_size); + + for (p = p0; p < p1; p++) *p = Debug_filler_align; + for (p = p1; p < p2; p++) *p = Debug_uninit_align; + for (p = p2; p < p3; p++) *p = Debug_filler_align; + } +#endif + return (char *) (aligned_mem - modulo); +} + +void caml_ext_table_init(struct ext_table * tbl, int init_capa) +{ + tbl->size = 0; + tbl->capacity = init_capa; + tbl->contents = caml_stat_alloc(sizeof(void *) * init_capa); +} + +int caml_ext_table_add(struct ext_table * tbl, void * data) +{ + int res; + if (tbl->size >= tbl->capacity) { + tbl->capacity *= 2; + tbl->contents = + caml_stat_resize(tbl->contents, sizeof(void *) * tbl->capacity); + } + res = tbl->size; + tbl->contents[res] = data; + tbl->size++; + return res; +} + +void caml_ext_table_free(struct ext_table * tbl, int free_entries) +{ + int i; + if (free_entries) + for (i = 0; i < tbl->size; i++) caml_stat_free(tbl->contents[i]); + caml_stat_free(tbl->contents); +} diff --git a/byterun/misc.h b/byterun/misc.h new file mode 100644 index 0000000..3b104a6 --- /dev/null +++ b/byterun/misc.h @@ -0,0 +1,136 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: misc.h,v 1.33 2008-02-29 12:56:15 doligez Exp $ */ + +/* Miscellaneous macros and variables. */ + +#ifndef CAML_MISC_H +#define CAML_MISC_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "config.h" + +/* Standard definitions */ + +#include +#include + +/* Basic types and constants */ + +typedef size_t asize_t; + +#ifndef NULL +#define NULL 0 +#endif + +/* */ +typedef char * addr; +/* */ + +#ifdef __GNUC__ + /* Works only in GCC 2.5 and later */ + #define Noreturn __attribute__ ((noreturn)) +#else + #define Noreturn +#endif + +/* Export control (to mark primitives and to handle Windows DLL) */ + +#define CAMLexport +#define CAMLprim +#define CAMLextern extern + +/* Assertions */ + +/* */ + +#ifdef DEBUG +#define CAMLassert(x) ((x) ? 0 : caml_failed_assert ( #x , __FILE__, __LINE__)) +CAMLextern int caml_failed_assert (char *, char *, int); +#else +#define CAMLassert(x) ((void) 0) +#endif + +CAMLextern void caml_fatal_error (char *msg) Noreturn; +CAMLextern void caml_fatal_error_arg (char *fmt, char *arg) Noreturn; +CAMLextern void caml_fatal_error_arg2 (char *fmt1, char *arg1, + char *fmt2, char *arg2) Noreturn; + +/* Data structures */ + +struct ext_table { + int size; + int capacity; + void ** contents; +}; + +extern void caml_ext_table_init(struct ext_table * tbl, int init_capa); +extern int caml_ext_table_add(struct ext_table * tbl, void * data); +extern void caml_ext_table_free(struct ext_table * tbl, int free_entries); + +/* GC flags and messages */ + +extern uintnat caml_verb_gc; +void caml_gc_message (int, char *, uintnat); + +/* Memory routines */ + +char *caml_aligned_malloc (asize_t, int, void **); + +#ifdef DEBUG +#ifdef ARCH_SIXTYFOUR +#define Debug_tag(x) (0xD700D7D7D700D6D7ul \ + | ((uintnat) (x) << 16) \ + | ((uintnat) (x) << 48)) +#else +#define Debug_tag(x) (0xD700D6D7ul | ((uintnat) (x) << 16)) +#endif /* ARCH_SIXTYFOUR */ + +/* + 00 -> free words in minor heap + 01 -> fields of free list blocks in major heap + 03 -> heap chunks deallocated by heap shrinking + 04 -> fields deallocated by [caml_obj_truncate] + 10 -> uninitialised fields of minor objects + 11 -> uninitialised fields of major objects + 15 -> uninitialised words of [caml_aligned_malloc] blocks + 85 -> filler bytes of [caml_aligned_malloc] + + special case (byte by byte): + D7 -> uninitialised words of [caml_stat_alloc] blocks +*/ +#define Debug_free_minor Debug_tag (0x00) +#define Debug_free_major Debug_tag (0x01) +#define Debug_free_shrink Debug_tag (0x03) +#define Debug_free_truncate Debug_tag (0x04) +#define Debug_uninit_minor Debug_tag (0x10) +#define Debug_uninit_major Debug_tag (0x11) +#define Debug_uninit_align Debug_tag (0x15) +#define Debug_filler_align Debug_tag (0x85) + +#define Debug_uninit_stat 0xD7 + +extern void caml_set_fields (char *, unsigned long, unsigned long); +#endif /* DEBUG */ + + +#ifndef CAML_AVOID_CONFLICTS +#define Assert CAMLassert +#endif + +/* */ + +#endif /* CAML_MISC_H */ diff --git a/byterun/mlvalues.h b/byterun/mlvalues.h new file mode 100644 index 0000000..bd42c0b --- /dev/null +++ b/byterun/mlvalues.h @@ -0,0 +1,295 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mlvalues.h,v 1.58 2008-08-01 14:10:36 xleroy Exp $ */ + +#ifndef CAML_MLVALUES_H +#define CAML_MLVALUES_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "config.h" +#include "misc.h" + +/* Definitions + + word: Four bytes on 32 and 16 bit architectures, + eight bytes on 64 bit architectures. + long: A C integer having the same number of bytes as a word. + val: The ML representation of something. A long or a block or a pointer + outside the heap. If it is a block, it is the (encoded) address + of an object. If it is a long, it is encoded as well. + block: Something allocated. It always has a header and some + fields or some number of bytes (a multiple of the word size). + field: A word-sized val which is part of a block. + bp: Pointer to the first byte of a block. (a char *) + op: Pointer to the first field of a block. (a value *) + hp: Pointer to the header of a block. (a char *) + int32: Four bytes on all architectures. + int64: Eight bytes on all architectures. + + Remark: A block size is always a multiple of the word size, and at least + one word plus the header. + + bosize: Size (in bytes) of the "bytes" part. + wosize: Size (in words) of the "fields" part. + bhsize: Size (in bytes) of the block with its header. + whsize: Size (in words) of the block with its header. + + hd: A header. + tag: The value of the tag field of the header. + color: The value of the color field of the header. + This is for use only by the GC. +*/ + +typedef intnat value; +typedef uintnat header_t; +typedef uintnat mlsize_t; +typedef unsigned int tag_t; /* Actually, an unsigned char */ +typedef uintnat color_t; +typedef uintnat mark_t; + +/* Longs vs blocks. */ +#define Is_long(x) (((x) & 1) != 0) +#define Is_block(x) (((x) & 1) == 0) + +/* Conversion macro names are always of the form "to_from". */ +/* Example: Val_long as in "Val from long" or "Val of long". */ +#define Val_long(x) (((intnat)(x) << 1) + 1) +#define Long_val(x) ((x) >> 1) +#define Max_long (((intnat)1 << (8 * sizeof(value) - 2)) - 1) +#define Min_long (-((intnat)1 << (8 * sizeof(value) - 2))) +#define Val_int(x) Val_long(x) +#define Int_val(x) ((int) Long_val(x)) +#define Unsigned_long_val(x) ((uintnat)(x) >> 1) +#define Unsigned_int_val(x) ((int) Unsigned_long_val(x)) + +/* Structure of the header: + +For 16-bit and 32-bit architectures: + +--------+-------+-----+ + | wosize | color | tag | + +--------+-------+-----+ +bits 31 10 9 8 7 0 + +For 64-bit architectures: + + +--------+-------+-----+ + | wosize | color | tag | + +--------+-------+-----+ +bits 63 10 9 8 7 0 + +*/ + +#define Tag_hd(hd) ((tag_t) ((hd) & 0xFF)) +#define Wosize_hd(hd) ((mlsize_t) ((hd) >> 10)) + +#define Hd_val(val) (((header_t *) (val)) [-1]) /* Also an l-value. */ +#define Hd_op(op) (Hd_val (op)) /* Also an l-value. */ +#define Hd_bp(bp) (Hd_val (bp)) /* Also an l-value. */ +#define Hd_hp(hp) (* ((header_t *) (hp))) /* Also an l-value. */ +#define Hp_val(val) ((char *) (((header_t *) (val)) - 1)) +#define Hp_op(op) (Hp_val (op)) +#define Hp_bp(bp) (Hp_val (bp)) +#define Val_op(op) ((value) (op)) +#define Val_hp(hp) ((value) (((header_t *) (hp)) + 1)) +#define Op_hp(hp) ((value *) Val_hp (hp)) +#define Bp_hp(hp) ((char *) Val_hp (hp)) + +#define Num_tags (1 << 8) +#ifdef ARCH_SIXTYFOUR +#define Max_wosize (((intnat)1 << 54) - 1) +#else +#define Max_wosize ((1 << 22) - 1) +#endif + +#define Wosize_val(val) (Wosize_hd (Hd_val (val))) +#define Wosize_op(op) (Wosize_val (op)) +#define Wosize_bp(bp) (Wosize_val (bp)) +#define Wosize_hp(hp) (Wosize_hd (Hd_hp (hp))) +#define Whsize_wosize(sz) ((sz) + 1) +#define Wosize_whsize(sz) ((sz) - 1) +#define Wosize_bhsize(sz) ((sz) / sizeof (value) - 1) +#define Bsize_wsize(sz) ((sz) * sizeof (value)) +#define Wsize_bsize(sz) ((sz) / sizeof (value)) +#define Bhsize_wosize(sz) (Bsize_wsize (Whsize_wosize (sz))) +#define Bhsize_bosize(sz) ((sz) + sizeof (header_t)) +#define Bosize_val(val) (Bsize_wsize (Wosize_val (val))) +#define Bosize_op(op) (Bosize_val (Val_op (op))) +#define Bosize_bp(bp) (Bosize_val (Val_bp (bp))) +#define Bosize_hd(hd) (Bsize_wsize (Wosize_hd (hd))) +#define Whsize_hp(hp) (Whsize_wosize (Wosize_hp (hp))) +#define Whsize_val(val) (Whsize_hp (Hp_val (val))) +#define Whsize_bp(bp) (Whsize_val (Val_bp (bp))) +#define Whsize_hd(hd) (Whsize_wosize (Wosize_hd (hd))) +#define Bhsize_hp(hp) (Bsize_wsize (Whsize_hp (hp))) +#define Bhsize_hd(hd) (Bsize_wsize (Whsize_hd (hd))) + +#ifdef ARCH_BIG_ENDIAN +#define Tag_val(val) (((unsigned char *) (val)) [-1]) + /* Also an l-value. */ +#define Tag_hp(hp) (((unsigned char *) (hp)) [sizeof(value)-1]) + /* Also an l-value. */ +#else +#define Tag_val(val) (((unsigned char *) (val)) [-sizeof(value)]) + /* Also an l-value. */ +#define Tag_hp(hp) (((unsigned char *) (hp)) [0]) + /* Also an l-value. */ +#endif + +/* The lowest tag for blocks containing no value. */ +#define No_scan_tag 251 + + +/* 1- If tag < No_scan_tag : a tuple of fields. */ + +/* Pointer to the first field. */ +#define Op_val(x) ((value *) (x)) +/* Fields are numbered from 0. */ +#define Field(x, i) (((value *)(x)) [i]) /* Also an l-value. */ + +typedef int32 opcode_t; +typedef opcode_t * code_t; + +/* NOTE: [Forward_tag] and [Infix_tag] must be just under + [No_scan_tag], with [Infix_tag] the lower one. + See [caml_oldify_one] in minor_gc.c for more details. + + NOTE: Update stdlib/obj.ml whenever you change the tags. + */ + +/* Forward_tag: forwarding pointer that the GC may silently shortcut. + See stdlib/lazy.ml. */ +#define Forward_tag 250 +#define Forward_val(v) Field(v, 0) + +/* If tag == Infix_tag : an infix header inside a closure */ +/* Infix_tag must be odd so that the infix header is scanned as an integer */ +/* Infix_tag must be 1 modulo 4 and infix headers can only occur in blocks + with tag Closure_tag (see compact.c). */ + +#define Infix_tag 249 +#define Infix_offset_hd(hd) (Bosize_hd(hd)) +#define Infix_offset_val(v) Infix_offset_hd(Hd_val(v)) + +/* Another special case: objects */ +#define Object_tag 248 +#define Class_val(val) Field((val), 0) +#define Oid_val(val) Long_val(Field((val), 1)) +CAMLextern value caml_get_public_method (value obj, value tag); +/* Called as: + caml_callback(caml_get_public_method(obj, caml_hash_variant(name)), obj) */ +/* caml_get_public_method returns 0 if tag not in the table. + Note however that tags being hashed, same tag does not necessarily mean + same method name. */ + +/* Special case of tuples of fields: closures */ +#define Closure_tag 247 +#define Code_val(val) (((code_t *) (val)) [0]) /* Also an l-value. */ + +/* This tag is used (with Forward_tag) to implement lazy values. + See major_gc.c and stdlib/lazy.ml. */ +#define Lazy_tag 246 + +/* Another special case: variants */ +CAMLextern value caml_hash_variant(char const * tag); + +/* 2- If tag >= No_scan_tag : a sequence of bytes. */ + +/* Pointer to the first byte */ +#define Bp_val(v) ((char *) (v)) +#define Val_bp(p) ((value) (p)) +/* Bytes are numbered from 0. */ +#define Byte(x, i) (((char *) (x)) [i]) /* Also an l-value. */ +#define Byte_u(x, i) (((unsigned char *) (x)) [i]) /* Also an l-value. */ + +/* Abstract things. Their contents is not traced by the GC; therefore they + must not contain any [value]. +*/ +#define Abstract_tag 251 + +/* Strings. */ +#define String_tag 252 +#define String_val(x) ((char *) Bp_val(x)) +CAMLextern mlsize_t caml_string_length (value); /* size in bytes */ + +/* Floating-point numbers. */ +#define Double_tag 253 +#define Double_wosize ((sizeof(double) / sizeof(value))) +#ifndef ARCH_ALIGN_DOUBLE +#define Double_val(v) (* (double *)(v)) +#define Store_double_val(v,d) (* (double *)(v) = (d)) +#else +CAMLextern double caml_Double_val (value); +CAMLextern void caml_Store_double_val (value,double); +#define Double_val(v) caml_Double_val(v) +#define Store_double_val(v,d) caml_Store_double_val(v,d) +#endif + +/* Arrays of floating-point numbers. */ +#define Double_array_tag 254 +#define Double_field(v,i) Double_val((value)((double *)(v) + (i))) +#define Store_double_field(v,i,d) do{ \ + mlsize_t caml__temp_i = (i); \ + double caml__temp_d = (d); \ + Store_double_val((value)((double *) (v) + caml__temp_i), caml__temp_d); \ +}while(0) + +/* Custom blocks. They contain a pointer to a "method suite" + of functions (for finalization, comparison, hashing, etc) + followed by raw data. The contents of custom blocks is not traced by + the GC; therefore, they must not contain any [value]. + See [custom.h] for operations on method suites. */ +#define Custom_tag 255 +#define Data_custom_val(v) ((void *) &Field((v), 1)) +struct custom_operations; /* defined in [custom.h] */ + +/* Int32.t, Int64.t and Nativeint.t are represented as custom blocks. */ + +#define Int32_val(v) (*((int32 *) Data_custom_val(v))) +#define Nativeint_val(v) (*((intnat *) Data_custom_val(v))) +#ifndef ARCH_ALIGN_INT64 +#define Int64_val(v) (*((int64 *) Data_custom_val(v))) +#else +CAMLextern int64 caml_Int64_val(value v); +#define Int64_val(v) caml_Int64_val(v) +#endif + +/* 3- Atoms are 0-tuples. They are statically allocated once and for all. */ + +CAMLextern header_t caml_atom_table[]; +#define Atom(tag) (Val_hp (&(caml_atom_table [(tag)]))) + +/* Booleans are integers 0 or 1 */ + +#define Val_bool(x) Val_int((x) != 0) +#define Bool_val(x) Int_val(x) +#define Val_false Val_int(0) +#define Val_true Val_int(1) +#define Val_not(x) (Val_false + Val_true - (x)) + +/* The unit value is 0 (tagged) */ + +#define Val_unit Val_int(0) + +/* List constructors */ +#define Val_emptylist Val_int(0) +#define Tag_cons 0 + +/* The table of global identifiers */ + +extern value caml_global_data; + + +#endif /* CAML_MLVALUES_H */ diff --git a/byterun/obj.c b/byterun/obj.c new file mode 100644 index 0000000..a9cd97e --- /dev/null +++ b/byterun/obj.c @@ -0,0 +1,247 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: obj.c,v 1.42 2008-01-29 13:11:15 doligez Exp $ */ + +/* Operations on objects */ + +#include +#include "alloc.h" +#include "fail.h" +#include "gc.h" +#include "interp.h" +#include "major_gc.h" +#include "memory.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "prims.h" + +CAMLprim value caml_static_alloc(value size) +{ + return (value) caml_stat_alloc((asize_t) Long_val(size)); +} + +CAMLprim value caml_static_free(value blk) +{ + caml_stat_free((void *) blk); + return Val_unit; +} + +/* signal to the interpreter machinery that a bytecode is no more + needed (before freeing it) - this might be useful for a JIT + implementation */ + +CAMLprim value caml_static_release_bytecode(value blk, value size) +{ +#ifndef NATIVE_CODE + caml_release_bytecode((code_t) blk, (asize_t) Long_val(size)); +#else + caml_failwith("Meta.static_release_bytecode impossible with native code"); +#endif + return Val_unit; +} + + +CAMLprim value caml_static_resize(value blk, value new_size) +{ + return (value) caml_stat_resize((char *) blk, (asize_t) Long_val(new_size)); +} + +CAMLprim value caml_obj_is_block(value arg) +{ + return Val_bool(Is_block(arg)); +} + +CAMLprim value caml_obj_tag(value arg) +{ + if (Is_long (arg)){ + return Val_int (1000); /* int_tag */ + }else if ((long) arg & (sizeof (value) - 1)){ + return Val_int (1002); /* unaligned_tag */ + }else if (Is_in_value_area (arg)){ + return Val_int(Tag_val(arg)); + }else{ + return Val_int (1001); /* out_of_heap_tag */ + } +} + +CAMLprim value caml_obj_set_tag (value arg, value new_tag) +{ + Tag_val (arg) = Int_val (new_tag); + return Val_unit; +} + +CAMLprim value caml_obj_block(value tag, value size) +{ + value res; + mlsize_t sz, i; + tag_t tg; + + sz = Long_val(size); + tg = Long_val(tag); + if (sz == 0) return Atom(tg); + res = caml_alloc(sz, tg); + for (i = 0; i < sz; i++) + Field(res, i) = Val_long(0); + + return res; +} + +CAMLprim value caml_obj_dup(value arg) +{ + CAMLparam1 (arg); + CAMLlocal1 (res); + mlsize_t sz, i; + tag_t tg; + + sz = Wosize_val(arg); + if (sz == 0) CAMLreturn (arg); + tg = Tag_val(arg); + if (tg >= No_scan_tag) { + res = caml_alloc(sz, tg); + memcpy(Bp_val(res), Bp_val(arg), sz * sizeof(value)); + } else if (sz <= Max_young_wosize) { + res = caml_alloc_small(sz, tg); + for (i = 0; i < sz; i++) Field(res, i) = Field(arg, i); + } else { + res = caml_alloc_shr(sz, tg); + for (i = 0; i < sz; i++) caml_initialize(&Field(res, i), Field(arg, i)); + } + CAMLreturn (res); +} + +/* Shorten the given block to the given size and return void. + Raise Invalid_argument if the given size is less than or equal + to 0 or greater than the current size. + + algorithm: + Change the length field of the header. Make up a white object + with the leftover part of the object: this is needed in the major + heap and harmless in the minor heap. +*/ +CAMLprim value caml_obj_truncate (value v, value newsize) +{ + mlsize_t new_wosize = Long_val (newsize); + header_t hd = Hd_val (v); + tag_t tag = Tag_hd (hd); + color_t color = Color_hd (hd); + mlsize_t wosize = Wosize_hd (hd); + mlsize_t i; + + if (tag == Double_array_tag) new_wosize *= Double_wosize; /* PR#156 */ + + if (new_wosize <= 0 || new_wosize > wosize){ + caml_invalid_argument ("Obj.truncate"); + } + if (new_wosize == wosize) return Val_unit; + /* PR#61: since we're about to lose our references to the elements + beyond new_wosize in v, erase them explicitly so that the GC + can darken them as appropriate. */ + if (tag < No_scan_tag) { + for (i = new_wosize; i < wosize; i++){ + caml_modify(&Field(v, i), Val_unit); +#ifdef DEBUG + Field (v, i) = Debug_free_truncate; +#endif + } + } + /* We must use an odd tag for the header of the leftovers so it does not + look like a pointer because there may be some references to it in + ref_table. */ + Field (v, new_wosize) = + Make_header (Wosize_whsize (wosize-new_wosize), 1, Caml_white); + Hd_val (v) = Make_header (new_wosize, tag, color); + return Val_unit; +} + + +/* The following functions are used in stdlib/lazy.ml. + They are not written in O'Caml because they must be atomic with respect + to the GC. + */ + +CAMLprim value caml_lazy_follow_forward (value v) +{ + if (Is_block (v) && Is_in_value_area(v) + && Tag_val (v) == Forward_tag){ + return Forward_val (v); + }else{ + return v; + } +} + +CAMLprim value caml_lazy_make_forward (value v) +{ + CAMLparam1 (v); + CAMLlocal1 (res); + + res = caml_alloc_small (1, Forward_tag); + Modify (&Field (res, 0), v); + CAMLreturn (res); +} + +/* For mlvalues.h and camlinternalOO.ml + See also GETPUBMET in interp.c + */ + +CAMLprim value caml_get_public_method (value obj, value tag) +{ + value meths = Field (obj, 0); + int li = 3, hi = Field(meths,0), mi; + while (li < hi) { + mi = ((li+hi) >> 1) | 1; + if (tag < Field(meths,mi)) hi = mi-2; + else li = mi; + } + /* return 0 if tag is not there */ + return (tag == Field(meths,li) ? Field (meths, li-1) : 0); +} + +/* these two functions might be useful to an hypothetical JIT */ + +#ifdef CAML_JIT +#ifdef NATIVE_CODE +#define MARK 1 +#else +#define MARK 0 +#endif +value caml_cache_public_method (value meths, value tag, value *cache) +{ + int li = 3, hi = Field(meths,0), mi; + while (li < hi) { + mi = ((li+hi) >> 1) | 1; + if (tag < Field(meths,mi)) hi = mi-2; + else li = mi; + } + *cache = (li-3)*sizeof(value) + MARK; + return Field (meths, li-1); +} + +value caml_cache_public_method2 (value *meths, value tag, value *cache) +{ + value ofs = *cache & meths[1]; + if (*(value*)(((char*)(meths+3)) + ofs - MARK) == tag) + return *(value*)(((char*)(meths+2)) + ofs - MARK); + { + int li = 3, hi = meths[0], mi; + while (li < hi) { + mi = ((li+hi) >> 1) | 1; + if (tag < meths[mi]) hi = mi-2; + else li = mi; + } + *cache = (li-3)*sizeof(value) + MARK; + return meths[li-1]; + } +} +#endif /*CAML_JIT*/ diff --git a/byterun/osdeps.h b/byterun/osdeps.h new file mode 100644 index 0000000..80a8041 --- /dev/null +++ b/byterun/osdeps.h @@ -0,0 +1,72 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: osdeps.h,v 1.12 2008-04-22 12:24:10 frisch Exp $ */ + +/* Operating system - specific stuff */ + +#ifndef CAML_OSDEPS_H +#define CAML_OSDEPS_H + +#include "misc.h" + +/* Decompose the given path into a list of directories, and add them + to the given table. Return the block to be freed later. */ +extern char * caml_decompose_path(struct ext_table * tbl, char * path); + +/* Search the given file in the given list of directories. + If not found, return a copy of [name]. Result is allocated with + [caml_stat_alloc]. */ +extern char * caml_search_in_path(struct ext_table * path, char * name); + +/* Same, but search an executable name in the system path for executables. */ +CAMLextern char * caml_search_exe_in_path(char * name); + +/* Same, but search a shared library in the given path. */ +extern char * caml_search_dll_in_path(struct ext_table * path, char * name); + +/* Open a shared library and return a handle on it. + If [for_execution] is true, perform full symbol resolution and + execute initialization code so that functions from the shared library + can be called. If [for_execution] is false, functions from this + shared library will not be called, but just checked for presence, + so symbol resolution can be skipped. + If [global] is true, symbols from the shared library can be used + to resolve for other libraries to be opened later on. + Return [NULL] on error. */ +extern void * caml_dlopen(char * libname, int for_execution, int global); + +/* Close a shared library handle */ +extern void caml_dlclose(void * handle); + +/* Look up the given symbol in the given shared library. + Return [NULL] if not found, or symbol value if found. */ +extern void * caml_dlsym(void * handle, char * name); + +extern void * caml_globalsym(char * name); + +/* Return an error message describing the most recent dynlink failure. */ +extern char * caml_dlerror(void); + +/* Add to [contents] the (short) names of the files contained in + the directory named [dirname]. No entries are added for [.] and [..]. + Return 0 on success, -1 on error; set errno in the case of error. */ +extern int caml_read_directory(char * dirname, struct ext_table * contents); + +#ifdef __linux__ +/* Recover executable name from /proc/self/exe if possible */ +extern int caml_executable_name(char * name, int name_len); +#endif + +#endif /* CAML_OSDEPS_H */ + diff --git a/byterun/parsing.c b/byterun/parsing.c new file mode 100644 index 0000000..569231e --- /dev/null +++ b/byterun/parsing.c @@ -0,0 +1,302 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: parsing.c,v 1.21 2008-08-06 09:38:25 xleroy Exp $ */ + +/* The PDA automaton for parsers generated by camlyacc */ + +#include +#include +#include "config.h" +#include "mlvalues.h" +#include "memory.h" +#include "alloc.h" + +#define ERRCODE 256 + +struct parser_tables { /* Mirrors parse_tables in ../stdlib/parsing.mli */ + value actions; + value transl_const; + value transl_block; + char * lhs; + char * len; + char * defred; + char * dgoto; + char * sindex; + char * rindex; + char * gindex; + value tablesize; + char * table; + char * check; + value error_function; + char * names_const; + char * names_block; +}; + +struct parser_env { /* Mirrors parser_env in ../stdlib/parsing.ml */ + value s_stack; + value v_stack; + value symb_start_stack; + value symb_end_stack; + value stacksize; + value stackbase; + value curr_char; + value lval; + value symb_start; + value symb_end; + value asp; + value rule_len; + value rule_number; + value sp; + value state; + value errflag; +}; + +#if defined(ARCH_BIG_ENDIAN) || SIZEOF_SHORT != 2 +#define Short(tbl,n) \ + (*((unsigned char *)((tbl) + (n) * 2)) + \ + (*((schar *)((tbl) + (n) * 2 + 1)) << 8)) +#else +#define Short(tbl,n) (((short *)(tbl))[n]) +#endif + +int caml_parser_trace = 0; + +/* Input codes */ +/* Mirrors parser_input in ../stdlib/parsing.ml */ +#define START 0 +#define TOKEN_READ 1 +#define STACKS_GROWN_1 2 +#define STACKS_GROWN_2 3 +#define SEMANTIC_ACTION_COMPUTED 4 +#define ERROR_DETECTED 5 + +/* Output codes */ +/* Mirrors parser_output in ../stdlib/parsing.ml */ +#define READ_TOKEN Val_int(0) +#define RAISE_PARSE_ERROR Val_int(1) +#define GROW_STACKS_1 Val_int(2) +#define GROW_STACKS_2 Val_int(3) +#define COMPUTE_SEMANTIC_ACTION Val_int(4) +#define CALL_ERROR_FUNCTION Val_int(5) + +/* To preserve local variables when communicating with the ML code */ + +#define SAVE \ + env->sp = Val_int(sp), \ + env->state = Val_int(state), \ + env->errflag = Val_int(errflag) + +#define RESTORE \ + sp = Int_val(env->sp), \ + state = Int_val(env->state), \ + errflag = Int_val(env->errflag) + +/* Auxiliary for printing token just read */ + +static char * token_name(char * names, int number) +{ + for (/*nothing*/; number > 0; number--) { + if (names[0] == 0) return ""; + names += strlen(names) + 1; + } + return names; +} + +static void print_token(struct parser_tables *tables, int state, value tok) +{ + value v; + + if (Is_long(tok)) { + fprintf(stderr, "State %d: read token %s\n", + state, token_name(tables->names_const, Int_val(tok))); + } else { + fprintf(stderr, "State %d: read token %s(", + state, token_name(tables->names_block, Tag_val(tok))); + v = Field(tok, 0); + if (Is_long(v)) + fprintf(stderr, "%ld", Long_val(v)); + else if (Tag_val(v) == String_tag) + fprintf(stderr, "%s", String_val(v)); + else if (Tag_val(v) == Double_tag) + fprintf(stderr, "%g", Double_val(v)); + else + fprintf(stderr, "_"); + fprintf(stderr, ")\n"); + } +} + +/* The pushdown automata */ + +CAMLprim value caml_parse_engine(struct parser_tables *tables, + struct parser_env *env, value cmd, value arg) +{ + int state; + mlsize_t sp, asp; + int errflag; + int n, n1, n2, m, state1; + + switch(Int_val(cmd)) { + + case START: + state = 0; + sp = Int_val(env->sp); + errflag = 0; + + loop: + n = Short(tables->defred, state); + if (n != 0) goto reduce; + if (Int_val(env->curr_char) >= 0) goto testshift; + SAVE; + return READ_TOKEN; + /* The ML code calls the lexer and updates */ + /* symb_start and symb_end */ + case TOKEN_READ: + RESTORE; + if (Is_block(arg)) { + env->curr_char = Field(tables->transl_block, Tag_val(arg)); + caml_modify(&env->lval, Field(arg, 0)); + } else { + env->curr_char = Field(tables->transl_const, Int_val(arg)); + caml_modify(&env->lval, Val_long(0)); + } + if (caml_parser_trace) print_token(tables, state, arg); + + testshift: + n1 = Short(tables->sindex, state); + n2 = n1 + Int_val(env->curr_char); + if (n1 != 0 && n2 >= 0 && n2 <= Int_val(tables->tablesize) && + Short(tables->check, n2) == Int_val(env->curr_char)) goto shift; + n1 = Short(tables->rindex, state); + n2 = n1 + Int_val(env->curr_char); + if (n1 != 0 && n2 >= 0 && n2 <= Int_val(tables->tablesize) && + Short(tables->check, n2) == Int_val(env->curr_char)) { + n = Short(tables->table, n2); + goto reduce; + } + if (errflag > 0) goto recover; + SAVE; + return CALL_ERROR_FUNCTION; + /* The ML code calls the error function */ + case ERROR_DETECTED: + RESTORE; + recover: + if (errflag < 3) { + errflag = 3; + while (1) { + state1 = Int_val(Field(env->s_stack, sp)); + n1 = Short(tables->sindex, state1); + n2 = n1 + ERRCODE; + if (n1 != 0 && n2 >= 0 && n2 <= Int_val(tables->tablesize) && + Short(tables->check, n2) == ERRCODE) { + if (caml_parser_trace) + fprintf(stderr, "Recovering in state %d\n", state1); + goto shift_recover; + } else { + if (caml_parser_trace){ + fprintf(stderr, "Discarding state %d\n", state1); + } + if (sp <= Int_val(env->stackbase)) { + if (caml_parser_trace){ + fprintf(stderr, "No more states to discard\n"); + } + return RAISE_PARSE_ERROR; /* The ML code raises Parse_error */ + } + sp--; + } + } + } else { + if (Int_val(env->curr_char) == 0) + return RAISE_PARSE_ERROR; /* The ML code raises Parse_error */ + if (caml_parser_trace) fprintf(stderr, "Discarding last token read\n"); + env->curr_char = Val_int(-1); + goto loop; + } + + shift: + env->curr_char = Val_int(-1); + if (errflag > 0) errflag--; + shift_recover: + if (caml_parser_trace) + fprintf(stderr, "State %d: shift to state %d\n", + state, Short(tables->table, n2)); + state = Short(tables->table, n2); + sp++; + if (sp < Long_val(env->stacksize)) goto push; + SAVE; + return GROW_STACKS_1; + /* The ML code resizes the stacks */ + case STACKS_GROWN_1: + RESTORE; + push: + Field(env->s_stack, sp) = Val_int(state); + caml_modify(&Field(env->v_stack, sp), env->lval); + Store_field (env->symb_start_stack, sp, env->symb_start); + Store_field (env->symb_end_stack, sp, env->symb_end); + goto loop; + + reduce: + if (caml_parser_trace) + fprintf(stderr, "State %d: reduce by rule %d\n", state, n); + m = Short(tables->len, n); + env->asp = Val_int(sp); + env->rule_number = Val_int(n); + env->rule_len = Val_int(m); + sp = sp - m + 1; + m = Short(tables->lhs, n); + state1 = Int_val(Field(env->s_stack, sp - 1)); + n1 = Short(tables->gindex, m); + n2 = n1 + state1; + if (n1 != 0 && n2 >= 0 && n2 <= Int_val(tables->tablesize) && + Short(tables->check, n2) == state1) { + state = Short(tables->table, n2); + } else { + state = Short(tables->dgoto, m); + } + if (sp < Long_val(env->stacksize)) goto semantic_action; + SAVE; + return GROW_STACKS_2; + /* The ML code resizes the stacks */ + case STACKS_GROWN_2: + RESTORE; + semantic_action: + SAVE; + return COMPUTE_SEMANTIC_ACTION; + /* The ML code calls the semantic action */ + case SEMANTIC_ACTION_COMPUTED: + RESTORE; + Field(env->s_stack, sp) = Val_int(state); + caml_modify(&Field(env->v_stack, sp), arg); + asp = Int_val(env->asp); + Store_field (env->symb_end_stack, sp, Field(env->symb_end_stack, asp)); + if (sp > asp) { + /* This is an epsilon production. Take symb_start equal to symb_end. */ + Store_field (env->symb_start_stack, sp, Field(env->symb_end_stack, asp)); + } + goto loop; + + default: /* Should not happen */ + Assert(0); + return RAISE_PARSE_ERROR; /* Keeps gcc -Wall happy */ + } + +} + +/* Control printing of debugging info */ + +CAMLprim value caml_set_parser_trace(value flag) +{ + value oldflag = Val_bool(caml_parser_trace); + caml_parser_trace = Bool_val(flag); + return oldflag; +} diff --git a/byterun/prims.h b/byterun/prims.h new file mode 100644 index 0000000..10bdeaa --- /dev/null +++ b/byterun/prims.h @@ -0,0 +1,36 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: prims.h,v 1.10 2004-02-22 15:07:51 xleroy Exp $ */ + +/* Interface with C primitives. */ + +#ifndef CAML_PRIMS_H +#define CAML_PRIMS_H + +typedef value (*c_primitive)(); + +extern c_primitive caml_builtin_cprim[]; +extern char * caml_names_of_builtin_cprim[]; + +extern struct ext_table caml_prim_table; +#ifdef DEBUG +extern struct ext_table caml_prim_name_table; +#endif + +#define Primitive(n) ((c_primitive)(caml_prim_table.contents[n])) + +extern char * caml_section_table; +extern asize_t caml_section_table_size; + +#endif /* CAML_PRIMS_H */ diff --git a/byterun/printexc.c b/byterun/printexc.c new file mode 100644 index 0000000..8bdcb3d --- /dev/null +++ b/byterun/printexc.c @@ -0,0 +1,126 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: printexc.c,v 1.17 2007-01-29 12:11:15 xleroy Exp $ */ + +/* Print an uncaught exception and abort */ + +#include +#include +#include +#include "backtrace.h" +#include "callback.h" +#include "debugger.h" +#include "fail.h" +#include "misc.h" +#include "mlvalues.h" +#include "printexc.h" + +struct stringbuf { + char * ptr; + char * end; + char data[256]; +}; + +static void add_char(struct stringbuf *buf, char c) +{ + if (buf->ptr < buf->end) *(buf->ptr++) = c; +} + +static void add_string(struct stringbuf *buf, char *s) +{ + int len = strlen(s); + if (buf->ptr + len > buf->end) len = buf->end - buf->ptr; + if (len > 0) memmove(buf->ptr, s, len); + buf->ptr += len; +} + +CAMLexport char * caml_format_exception(value exn) +{ + mlsize_t start, i; + value bucket, v; + struct stringbuf buf; + char intbuf[64]; + char * res; + + buf.ptr = buf.data; + buf.end = buf.data + sizeof(buf.data) - 1; + add_string(&buf, String_val(Field(Field(exn, 0), 0))); + if (Wosize_val(exn) >= 2) { + /* Check for exceptions in the style of Match_failure and Assert_failure */ + if (Wosize_val(exn) == 2 && + Is_block(Field(exn, 1)) && + Tag_val(Field(exn, 1)) == 0) { + bucket = Field(exn, 1); + start = 0; + } else { + bucket = exn; + start = 1; + } + add_char(&buf, '('); + for (i = start; i < Wosize_val(bucket); i++) { + if (i > start) add_string(&buf, ", "); + v = Field(bucket, i); + if (Is_long(v)) { + sprintf(intbuf, "%ld", Long_val(v)); + add_string(&buf, intbuf); + } else if (Tag_val(v) == String_tag) { + add_char(&buf, '"'); + add_string(&buf, String_val(v)); + add_char(&buf, '"'); + } else { + add_char(&buf, '_'); + } + } + add_char(&buf, ')'); + } + *buf.ptr = 0; /* Terminate string */ + i = buf.ptr - buf.data + 1; + res = malloc(i); + if (res == NULL) return NULL; + memmove(res, buf.data, i); + return res; +} + + +void caml_fatal_uncaught_exception(value exn) +{ + char * msg; + value * at_exit; + int saved_backtrace_active, saved_backtrace_pos; + + /* Build a string representation of the exception */ + msg = caml_format_exception(exn); + /* Perform "at_exit" processing, ignoring all exceptions that may + be triggered by this */ + saved_backtrace_active = caml_backtrace_active; + saved_backtrace_pos = caml_backtrace_pos; + caml_backtrace_active = 0; + at_exit = caml_named_value("Pervasives.do_at_exit"); + if (at_exit != NULL) caml_callback_exn(*at_exit, Val_unit); + caml_backtrace_active = saved_backtrace_active; + caml_backtrace_pos = saved_backtrace_pos; + /* Display the uncaught exception */ + fprintf(stderr, "Fatal error: exception %s\n", msg); + free(msg); + /* Display the backtrace if available */ + if (caml_backtrace_active +#ifndef NATIVE_CODE + && !caml_debugger_in_use +#endif + ) { + caml_print_exception_backtrace(); + } + /* Terminate the process */ + exit(2); +} diff --git a/byterun/printexc.h b/byterun/printexc.h new file mode 100644 index 0000000..db55e52 --- /dev/null +++ b/byterun/printexc.h @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: printexc.h,v 1.5 2004-01-01 16:42:37 doligez Exp $ */ + +#ifndef CAML_PRINTEXC_H +#define CAML_PRINTEXC_H + + +#include "misc.h" +#include "mlvalues.h" + +CAMLextern char * caml_format_exception (value); +void caml_fatal_uncaught_exception (value) Noreturn; + + +#endif /* CAML_PRINTEXC_H */ diff --git a/byterun/reverse.h b/byterun/reverse.h new file mode 100644 index 0000000..4b75c1f --- /dev/null +++ b/byterun/reverse.h @@ -0,0 +1,88 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: reverse.h,v 1.12 2003-12-15 18:10:48 doligez Exp $ */ + +/* Swap byte-order in 16, 32, and 64-bit integers or floats */ + +#ifndef CAML_REVERSE_H +#define CAML_REVERSE_H + +#define Reverse_16(dst,src) { \ + char * _p, * _q; \ + char _a; \ + _p = (char *) (src); \ + _q = (char *) (dst); \ + _a = _p[0]; \ + _q[0] = _p[1]; \ + _q[1] = _a; \ +} + +#define Reverse_32(dst,src) { \ + char * _p, * _q; \ + char _a, _b; \ + _p = (char *) (src); \ + _q = (char *) (dst); \ + _a = _p[0]; \ + _b = _p[1]; \ + _q[0] = _p[3]; \ + _q[1] = _p[2]; \ + _q[3] = _a; \ + _q[2] = _b; \ +} + +#define Reverse_64(dst,src) { \ + char * _p, * _q; \ + char _a, _b; \ + _p = (char *) (src); \ + _q = (char *) (dst); \ + _a = _p[0]; \ + _b = _p[1]; \ + _q[0] = _p[7]; \ + _q[1] = _p[6]; \ + _q[7] = _a; \ + _q[6] = _b; \ + _a = _p[2]; \ + _b = _p[3]; \ + _q[2] = _p[5]; \ + _q[3] = _p[4]; \ + _q[5] = _a; \ + _q[4] = _b; \ +} + +#define Perm_index(perm,i) ((perm >> (i * 4)) & 0xF) + +#define Permute_64(dst,perm_dst,src,perm_src) { \ + char * _p; \ + char _a, _b, _c, _d, _e, _f, _g, _h; \ + _p = (char *) (src); \ + _a = _p[Perm_index(perm_src, 0)]; \ + _b = _p[Perm_index(perm_src, 1)]; \ + _c = _p[Perm_index(perm_src, 2)]; \ + _d = _p[Perm_index(perm_src, 3)]; \ + _e = _p[Perm_index(perm_src, 4)]; \ + _f = _p[Perm_index(perm_src, 5)]; \ + _g = _p[Perm_index(perm_src, 6)]; \ + _h = _p[Perm_index(perm_src, 7)]; \ + _p = (char *) (dst); \ + _p[Perm_index(perm_dst, 0)] = _a; \ + _p[Perm_index(perm_dst, 1)] = _b; \ + _p[Perm_index(perm_dst, 2)] = _c; \ + _p[Perm_index(perm_dst, 3)] = _d; \ + _p[Perm_index(perm_dst, 4)] = _e; \ + _p[Perm_index(perm_dst, 5)] = _f; \ + _p[Perm_index(perm_dst, 6)] = _g; \ + _p[Perm_index(perm_dst, 7)] = _h; \ +} + +#endif /* CAML_REVERSE_H */ diff --git a/byterun/roots.c b/byterun/roots.c new file mode 100644 index 0000000..1c8f5ee --- /dev/null +++ b/byterun/roots.c @@ -0,0 +1,104 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: roots.c,v 1.30 2008-03-10 19:56:39 xleroy Exp $ */ + +/* To walk the memory roots for garbage collection */ + +#include "finalise.h" +#include "globroots.h" +#include "major_gc.h" +#include "memory.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "roots.h" +#include "stacks.h" + +CAMLexport struct caml__roots_block *caml_local_roots = NULL; + +CAMLexport void (*caml_scan_roots_hook) (scanning_action f) = NULL; + +/* FIXME should rename to [caml_oldify_young_roots] and synchronise with + asmrun/roots.c */ +/* Call [caml_oldify_one] on (at least) all the roots that point to the minor + heap. */ +void caml_oldify_local_roots (void) +{ + register value * sp; + struct caml__roots_block *lr; + intnat i, j; + + /* The stack */ + for (sp = caml_extern_sp; sp < caml_stack_high; sp++) { + caml_oldify_one (*sp, sp); + } + /* Local C roots */ /* FIXME do the old-frame trick ? */ + for (lr = caml_local_roots; lr != NULL; lr = lr->next) { + for (i = 0; i < lr->ntables; i++){ + for (j = 0; j < lr->nitems; j++){ + sp = &(lr->tables[i][j]); + caml_oldify_one (*sp, sp); + } + } + } + /* Global C roots */ + caml_scan_global_young_roots(&caml_oldify_one); + /* Finalised values */ + caml_final_do_young_roots (&caml_oldify_one); + /* Hook */ + if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(&caml_oldify_one); +} + +/* Call [caml_darken] on all roots */ + +void caml_darken_all_roots (void) +{ + caml_do_roots (caml_darken); +} + +void caml_do_roots (scanning_action f) +{ + /* Global variables */ + f(caml_global_data, &caml_global_data); + /* The stack and the local C roots */ + caml_do_local_roots(f, caml_extern_sp, caml_stack_high, caml_local_roots); + /* Global C roots */ + caml_scan_global_roots(f); + /* Finalised values */ + caml_final_do_strong_roots (f); + /* Hook */ + if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(f); +} + +CAMLexport void caml_do_local_roots (scanning_action f, value *stack_low, + value *stack_high, + struct caml__roots_block *local_roots) +{ + register value * sp; + struct caml__roots_block *lr; + int i, j; + + for (sp = stack_low; sp < stack_high; sp++) { + f (*sp, sp); + } + for (lr = local_roots; lr != NULL; lr = lr->next) { + for (i = 0; i < lr->ntables; i++){ + for (j = 0; j < lr->nitems; j++){ + sp = &(lr->tables[i][j]); + f (*sp, sp); + } + } + } +} + diff --git a/byterun/roots.h b/byterun/roots.h new file mode 100644 index 0000000..b368066 --- /dev/null +++ b/byterun/roots.h @@ -0,0 +1,38 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: roots.h,v 1.19 2005-09-22 14:21:50 xleroy Exp $ */ + +#ifndef CAML_ROOTS_H +#define CAML_ROOTS_H + +#include "misc.h" +#include "memory.h" + +typedef void (*scanning_action) (value, value *); + +void caml_oldify_local_roots (void); +void caml_darken_all_roots (void); +void caml_do_roots (scanning_action); +#ifndef NATIVE_CODE +CAMLextern void caml_do_local_roots (scanning_action, value *, value *, + struct caml__roots_block *); +#else +CAMLextern void caml_do_local_roots(scanning_action f, char * bottom_of_stack, + uintnat last_retaddr, value * gc_regs, + struct caml__roots_block * local_roots); +#endif + +CAMLextern void (*caml_scan_roots_hook) (scanning_action); + +#endif /* CAML_ROOTS_H */ diff --git a/byterun/signals.c b/byterun/signals.c new file mode 100644 index 0000000..845cf3d --- /dev/null +++ b/byterun/signals.c @@ -0,0 +1,307 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals.c,v 1.53 2007-02-23 09:29:45 xleroy Exp $ */ + +/* Signal handling, code common to the bytecode and native systems */ + +#include +#include "alloc.h" +#include "callback.h" +#include "config.h" +#include "fail.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "roots.h" +#include "signals.h" +#include "signals_machdep.h" +#include "sys.h" + +#ifndef NSIG +#define NSIG 64 +#endif + +/* The set of pending signals (received but not yet processed) */ + +CAMLexport intnat volatile caml_signals_are_pending = 0; +CAMLexport intnat volatile caml_pending_signals[NSIG]; + +/* Execute all pending signals */ + +void caml_process_pending_signals(void) +{ + int i; + + if (caml_signals_are_pending) { + caml_signals_are_pending = 0; + for (i = 0; i < NSIG; i++) { + if (caml_pending_signals[i]) { + caml_pending_signals[i] = 0; + caml_execute_signal(i, 0); + } + } + } +} + +/* Record the delivery of a signal, and arrange for it to be processed + as soon as possible: + - in bytecode: via caml_something_to_do, processed in caml_process_event + - in native-code: by playing with the allocation limit, processed + in caml_garbage_collection +*/ + +void caml_record_signal(int signal_number) +{ + caml_pending_signals[signal_number] = 1; + caml_signals_are_pending = 1; +#ifndef NATIVE_CODE + caml_something_to_do = 1; +#else + caml_young_limit = caml_young_end; +#endif +} + +/* Management of blocking sections. */ + +static intnat volatile caml_async_signal_mode = 0; + +static void caml_enter_blocking_section_default(void) +{ + Assert (caml_async_signal_mode == 0); + caml_async_signal_mode = 1; +} + +static void caml_leave_blocking_section_default(void) +{ + Assert (caml_async_signal_mode == 1); + caml_async_signal_mode = 0; +} + +static int caml_try_leave_blocking_section_default(void) +{ + intnat res; + Read_and_clear(res, caml_async_signal_mode); + return res; +} + +CAMLexport void (*caml_enter_blocking_section_hook)(void) = + caml_enter_blocking_section_default; +CAMLexport void (*caml_leave_blocking_section_hook)(void) = + caml_leave_blocking_section_default; +CAMLexport int (*caml_try_leave_blocking_section_hook)(void) = + caml_try_leave_blocking_section_default; + +CAMLexport void caml_enter_blocking_section(void) +{ + while (1){ + /* Process all pending signals now */ + caml_process_pending_signals(); + caml_enter_blocking_section_hook (); + /* Check again for pending signals. + If none, done; otherwise, try again */ + if (! caml_signals_are_pending) break; + caml_leave_blocking_section_hook (); + } +} + +CAMLexport void caml_leave_blocking_section(void) +{ + caml_leave_blocking_section_hook (); + caml_process_pending_signals(); +} + +/* Execute a signal handler immediately */ + +static value caml_signal_handlers = 0; + +void caml_execute_signal(int signal_number, int in_signal_handler) +{ + value res; +#ifdef POSIX_SIGNALS + sigset_t sigs; + /* Block the signal before executing the handler, and record in sigs + the original signal mask */ + sigemptyset(&sigs); + sigaddset(&sigs, signal_number); + sigprocmask(SIG_BLOCK, &sigs, &sigs); +#endif + res = caml_callback_exn( + Field(caml_signal_handlers, signal_number), + Val_int(caml_rev_convert_signal_number(signal_number))); +#ifdef POSIX_SIGNALS + if (! in_signal_handler) { + /* Restore the original signal mask */ + sigprocmask(SIG_SETMASK, &sigs, NULL); + } else if (Is_exception_result(res)) { + /* Restore the original signal mask and unblock the signal itself */ + sigdelset(&sigs, signal_number); + sigprocmask(SIG_SETMASK, &sigs, NULL); + } +#endif + if (Is_exception_result(res)) caml_raise(Extract_exception(res)); +} + +/* Arrange for a garbage collection to be performed as soon as possible */ + +int volatile caml_force_major_slice = 0; + +void caml_urge_major_slice (void) +{ + caml_force_major_slice = 1; +#ifndef NATIVE_CODE + caml_something_to_do = 1; +#else + caml_young_limit = caml_young_end; + /* This is only moderately effective on ports that cache [caml_young_limit] + in a register, since [caml_modify] is called directly, not through + [caml_c_call], so it may take a while before the register is reloaded + from [caml_young_limit]. */ +#endif +} + +/* OS-independent numbering of signals */ + +#ifndef SIGABRT +#define SIGABRT -1 +#endif +#ifndef SIGALRM +#define SIGALRM -1 +#endif +#ifndef SIGFPE +#define SIGFPE -1 +#endif +#ifndef SIGHUP +#define SIGHUP -1 +#endif +#ifndef SIGILL +#define SIGILL -1 +#endif +#ifndef SIGINT +#define SIGINT -1 +#endif +#ifndef SIGKILL +#define SIGKILL -1 +#endif +#ifndef SIGPIPE +#define SIGPIPE -1 +#endif +#ifndef SIGQUIT +#define SIGQUIT -1 +#endif +#ifndef SIGSEGV +#define SIGSEGV -1 +#endif +#ifndef SIGTERM +#define SIGTERM -1 +#endif +#ifndef SIGUSR1 +#define SIGUSR1 -1 +#endif +#ifndef SIGUSR2 +#define SIGUSR2 -1 +#endif +#ifndef SIGCHLD +#define SIGCHLD -1 +#endif +#ifndef SIGCONT +#define SIGCONT -1 +#endif +#ifndef SIGSTOP +#define SIGSTOP -1 +#endif +#ifndef SIGTSTP +#define SIGTSTP -1 +#endif +#ifndef SIGTTIN +#define SIGTTIN -1 +#endif +#ifndef SIGTTOU +#define SIGTTOU -1 +#endif +#ifndef SIGVTALRM +#define SIGVTALRM -1 +#endif +#ifndef SIGPROF +#define SIGPROF -1 +#endif + +static int posix_signals[] = { + SIGABRT, SIGALRM, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, + SIGQUIT, SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2, SIGCHLD, SIGCONT, + SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGVTALRM, SIGPROF +}; + +CAMLexport int caml_convert_signal_number(int signo) +{ + if (signo < 0 && signo >= -(sizeof(posix_signals) / sizeof(int))) + return posix_signals[-signo-1]; + else + return signo; +} + +CAMLexport int caml_rev_convert_signal_number(int signo) +{ + int i; + for (i = 0; i < sizeof(posix_signals) / sizeof(int); i++) + if (signo == posix_signals[i]) return -i - 1; + return signo; +} + +/* Installation of a signal handler (as per [Sys.signal]) */ + +CAMLprim value caml_install_signal_handler(value signal_number, value action) +{ + CAMLparam2 (signal_number, action); + CAMLlocal1 (res); + int sig, act, oldact; + + sig = caml_convert_signal_number(Int_val(signal_number)); + if (sig < 0 || sig >= NSIG) + caml_invalid_argument("Sys.signal: unavailable signal"); + switch(action) { + case Val_int(0): /* Signal_default */ + act = 0; + break; + case Val_int(1): /* Signal_ignore */ + act = 1; + break; + default: /* Signal_handle */ + act = 2; + break; + } + oldact = caml_set_signal_action(sig, act); + switch (oldact) { + case 0: /* was Signal_default */ + res = Val_int(0); + break; + case 1: /* was Signal_ignore */ + res = Val_int(1); + break; + case 2: /* was Signal_handle */ + res = caml_alloc_small (1, 0); + Field(res, 0) = Field(caml_signal_handlers, sig); + break; + default: /* error in caml_set_signal_action */ + caml_sys_error(NO_ARG); + } + if (Is_block(action)) { + if (caml_signal_handlers == 0) { + caml_signal_handlers = caml_alloc(NSIG, 0); + caml_register_global_root(&caml_signal_handlers); + } + caml_modify(&Field(caml_signal_handlers, sig), Field(action, 0)); + } + caml_process_pending_signals(); + CAMLreturn (res); +} diff --git a/byterun/signals.h b/byterun/signals.h new file mode 100644 index 0000000..d91ccfc --- /dev/null +++ b/byterun/signals.h @@ -0,0 +1,51 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals.h,v 1.27 2007-02-23 09:29:45 xleroy Exp $ */ + +#ifndef CAML_SIGNALS_H +#define CAML_SIGNALS_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "misc.h" +#include "mlvalues.h" + +/* */ +CAMLextern intnat volatile caml_signals_are_pending; +CAMLextern intnat volatile caml_pending_signals[]; +CAMLextern int volatile caml_something_to_do; +extern int volatile caml_force_major_slice; +/* */ + +CAMLextern void caml_enter_blocking_section (void); +CAMLextern void caml_leave_blocking_section (void); + +/* */ +void caml_urge_major_slice (void); +CAMLextern int caml_convert_signal_number (int); +CAMLextern int caml_rev_convert_signal_number (int); +void caml_execute_signal(int signal_number, int in_signal_handler); +void caml_record_signal(int signal_number); +void caml_process_pending_signals(void); +void caml_process_event(void); +int caml_set_signal_action(int signo, int action); + +CAMLextern void (*caml_enter_blocking_section_hook)(void); +CAMLextern void (*caml_leave_blocking_section_hook)(void); +CAMLextern int (*caml_try_leave_blocking_section_hook)(void); +CAMLextern void (* volatile caml_async_action_hook)(void); +/* */ + +#endif /* CAML_SIGNALS_H */ diff --git a/byterun/signals_byt.c b/byterun/signals_byt.c new file mode 100644 index 0000000..b698598 --- /dev/null +++ b/byterun/signals_byt.c @@ -0,0 +1,95 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 2007 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals_byt.c,v 1.1 2007-02-23 09:29:45 xleroy Exp $ */ + +/* Signal handling, code specific to the bytecode interpreter */ + +#include +#include "config.h" +#include "memory.h" +#include "osdeps.h" +#include "signals.h" +#include "signals_machdep.h" + +#ifndef NSIG +#define NSIG 64 +#endif + +#ifdef _WIN32 +typedef void (*sighandler)(int sig); +extern sighandler caml_win32_signal(int sig, sighandler action); +#define signal(sig,act) caml_win32_signal(sig,act) +#endif + +CAMLexport int volatile caml_something_to_do = 0; +CAMLexport void (* volatile caml_async_action_hook)(void) = NULL; + +void caml_process_event(void) +{ + void (*async_action)(void); + + if (caml_force_major_slice) caml_minor_collection (); + /* FIXME should be [caml_check_urgent_gc] */ + caml_process_pending_signals(); + async_action = caml_async_action_hook; + if (async_action != NULL) { + caml_async_action_hook = NULL; + (*async_action)(); + } +} + +static void handle_signal(int signal_number) +{ +#if !defined(POSIX_SIGNALS) && !defined(BSD_SIGNALS) + signal(signal_number, handle_signal); +#endif + if (signal_number < 0 || signal_number >= NSIG) return; + if (caml_try_leave_blocking_section_hook()) { + caml_execute_signal(signal_number, 1); + caml_enter_blocking_section_hook(); + }else{ + caml_record_signal(signal_number); + } +} + +int caml_set_signal_action(int signo, int action) +{ + void (*act)(int signo), (*oldact)(int signo); +#ifdef POSIX_SIGNALS + struct sigaction sigact, oldsigact; +#endif + + switch (action) { + case 0: act = SIG_DFL; break; + case 1: act = SIG_IGN; break; + default: act = handle_signal; break; + } + +#ifdef POSIX_SIGNALS + sigact.sa_handler = act; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + if (sigaction(signo, &sigact, &oldsigact) == -1) return -1; + oldact = oldsigact.sa_handler; +#else + oldact = signal(signo, act); + if (oldact == SIG_ERR) return -1; +#endif + if (oldact == handle_signal) + return 2; + else if (oldact == SIG_IGN) + return 1; + else + return 0; +} diff --git a/byterun/signals_machdep.h b/byterun/signals_machdep.h new file mode 100644 index 0000000..8fee7f2 --- /dev/null +++ b/byterun/signals_machdep.h @@ -0,0 +1,62 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals_machdep.h,v 1.3 2007-02-23 09:43:14 xleroy Exp $ */ + +/* Processor-specific operation: atomic "read and clear" */ + +#ifndef CAML_SIGNALS_MACHDEP_H +#define CAML_SIGNALS_MACHDEP_H + +#if defined(__GNUC__) && defined(__i386__) + +#define Read_and_clear(dst,src) \ + asm("xorl %0, %0; xchgl %0, %1" \ + : "=r" (dst), "=m" (src) \ + : "m" (src)) + +#elif defined(__GNUC__) && defined(__x86_64__) + +#define Read_and_clear(dst,src) \ + asm("xorq %0, %0; xchgq %0, %1" \ + : "=r" (dst), "=m" (src) \ + : "m" (src)) + +#elif defined(__GNUC__) && defined(__ppc__) + +#define Read_and_clear(dst,src) \ + asm("0: lwarx %0, 0, %1\n\t" \ + "stwcx. %2, 0, %1\n\t" \ + "bne- 0b" \ + : "=&r" (dst) \ + : "r" (&(src)), "r" (0) \ + : "cr0", "memory") + +#elif defined(__GNUC__) && defined(__ppc64__) + +#define Read_and_clear(dst,src) \ + asm("0: ldarx %0, 0, %1\n\t" \ + "stdcx. %2, 0, %1\n\t" \ + "bne- 0b" \ + : "=&r" (dst) \ + : "r" (&(src)), "r" (0) \ + : "cr0", "memory") + +#else + +/* Default, non-atomic implementation */ +#define Read_and_clear(dst,src) ((dst) = (src), (src) = 0) + +#endif + +#endif /* CAML_SIGNALS_MACHDEP_H */ diff --git a/byterun/stacks.c b/byterun/stacks.c new file mode 100644 index 0000000..44c43c4 --- /dev/null +++ b/byterun/stacks.c @@ -0,0 +1,104 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stacks.c,v 1.22 2005-09-22 14:21:50 xleroy Exp $ */ + +/* To initialize and resize the stacks */ + +#include +#include "config.h" +#include "fail.h" +#include "misc.h" +#include "mlvalues.h" +#include "stacks.h" + +CAMLexport value * caml_stack_low; +CAMLexport value * caml_stack_high; +CAMLexport value * caml_stack_threshold; +CAMLexport value * caml_extern_sp; +CAMLexport value * caml_trapsp; +CAMLexport value * caml_trap_barrier; +value caml_global_data; + +uintnat caml_max_stack_size; /* also used in gc_ctrl.c */ + +void caml_init_stack (uintnat initial_max_size) +{ + caml_stack_low = (value *) caml_stat_alloc(Stack_size); + caml_stack_high = caml_stack_low + Stack_size / sizeof (value); + caml_stack_threshold = caml_stack_low + Stack_threshold / sizeof (value); + caml_extern_sp = caml_stack_high; + caml_trapsp = caml_stack_high; + caml_trap_barrier = caml_stack_high + 1; + caml_max_stack_size = initial_max_size; + caml_gc_message (0x08, "Initial stack limit: %luk bytes\n", + caml_max_stack_size / 1024 * sizeof (value)); +} + +void caml_realloc_stack(asize_t required_space) +{ + asize_t size; + value * new_low, * new_high, * new_sp; + value * p; + + Assert(caml_extern_sp >= caml_stack_low); + size = caml_stack_high - caml_stack_low; + do { + if (size >= caml_max_stack_size) caml_raise_stack_overflow(); + size *= 2; + } while (size < caml_stack_high - caml_extern_sp + required_space); + caml_gc_message (0x08, "Growing stack to %" + ARCH_INTNAT_PRINTF_FORMAT "uk bytes\n", + (uintnat) size * sizeof(value) / 1024); + new_low = (value *) caml_stat_alloc(size * sizeof(value)); + new_high = new_low + size; + +#define shift(ptr) \ + ((char *) new_high - ((char *) caml_stack_high - (char *) (ptr))) + + new_sp = (value *) shift(caml_extern_sp); + memmove((char *) new_sp, + (char *) caml_extern_sp, + (caml_stack_high - caml_extern_sp) * sizeof(value)); + caml_stat_free(caml_stack_low); + caml_trapsp = (value *) shift(caml_trapsp); + caml_trap_barrier = (value *) shift(caml_trap_barrier); + for (p = caml_trapsp; p < new_high; p = Trap_link(p)) + Trap_link(p) = (value *) shift(Trap_link(p)); + caml_stack_low = new_low; + caml_stack_high = new_high; + caml_stack_threshold = caml_stack_low + Stack_threshold / sizeof (value); + caml_extern_sp = new_sp; + +#undef shift +} + +CAMLprim value caml_ensure_stack_capacity(value required_space) +{ + asize_t req = Long_val(required_space); + if (caml_extern_sp - req < caml_stack_low) caml_realloc_stack(req); + return Val_unit; +} + +void caml_change_max_stack_size (uintnat new_max_size) +{ + asize_t size = caml_stack_high - caml_extern_sp + + Stack_threshold / sizeof (value); + + if (new_max_size < size) new_max_size = size; + if (new_max_size != caml_max_stack_size){ + caml_gc_message (0x08, "Changing stack limit to %luk bytes\n", + new_max_size * sizeof (value) / 1024); + } + caml_max_stack_size = new_max_size; +} diff --git a/byterun/stacks.h b/byterun/stacks.h new file mode 100644 index 0000000..5979f72 --- /dev/null +++ b/byterun/stacks.h @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stacks.h,v 1.14 2005-09-22 14:21:50 xleroy Exp $ */ + +/* structure of the stacks */ + +#ifndef CAML_STACKS_H +#define CAML_STACKS_H + + +#include "misc.h" +#include "mlvalues.h" +#include "memory.h" + +CAMLextern value * caml_stack_low; +CAMLextern value * caml_stack_high; +CAMLextern value * caml_stack_threshold; +CAMLextern value * caml_extern_sp; +CAMLextern value * caml_trapsp; +CAMLextern value * caml_trap_barrier; + +#define Trap_pc(tp) (((code_t *)(tp))[0]) +#define Trap_link(tp) (((value **)(tp))[1]) + +void caml_init_stack (uintnat init_max_size); +void caml_realloc_stack (asize_t required_size); +void caml_change_max_stack_size (uintnat new_max_size); + + +#endif /* CAML_STACKS_H */ diff --git a/byterun/startup.c b/byterun/startup.c new file mode 100644 index 0000000..0ddfcb7 --- /dev/null +++ b/byterun/startup.c @@ -0,0 +1,478 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: startup.c,v 1.71 2008-12-03 18:09:09 doligez Exp $ */ + +/* Start-up code */ + +#include +#include +#include +#include +#include "config.h" +#ifdef HAS_UNISTD +#include +#endif +#ifdef _WIN32 +#include +#endif +#include "alloc.h" +#include "backtrace.h" +#include "callback.h" +#include "custom.h" +#include "debugger.h" +#include "dynlink.h" +#include "exec.h" +#include "fail.h" +#include "fix_code.h" +#include "freelist.h" +#include "gc_ctrl.h" +#include "instrtrace.h" +#include "interp.h" +#include "intext.h" +#include "io.h" +#include "memory.h" +#include "minor_gc.h" +#include "misc.h" +#include "mlvalues.h" +#include "osdeps.h" +#include "prims.h" +#include "printexc.h" +#include "reverse.h" +#include "signals.h" +#include "stacks.h" +#include "sys.h" +#include "startup.h" +#include "version.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +extern int caml_parser_trace; + +CAMLexport header_t caml_atom_table[256]; + +/* Initialize the atom table */ + +static void init_atoms(void) +{ + int i; + for(i = 0; i < 256; i++) caml_atom_table[i] = Make_header(0, i, Caml_white); + if (caml_page_table_add(In_static_data, + caml_atom_table, caml_atom_table + 256) != 0) { + caml_fatal_error("Fatal error: not enough memory for the initial page table"); + } +} + +/* Read the trailer of a bytecode file */ + +static void fixup_endianness_trailer(uint32 * p) +{ +#ifndef ARCH_BIG_ENDIAN + Reverse_32(p, p); +#endif +} + +static int read_trailer(int fd, struct exec_trailer *trail) +{ + lseek(fd, (long) -TRAILER_SIZE, SEEK_END); + if (read(fd, (char *) trail, TRAILER_SIZE) < TRAILER_SIZE) + return BAD_BYTECODE; + fixup_endianness_trailer(&trail->num_sections); + if (strncmp(trail->magic, EXEC_MAGIC, 12) == 0) + return 0; + else + return BAD_BYTECODE; +} + +int caml_attempt_open(char **name, struct exec_trailer *trail, + int do_open_script) +{ + char * truename; + int fd; + int err; + char buf [2]; + + truename = caml_search_exe_in_path(*name); + *name = truename; + caml_gc_message(0x100, "Opening bytecode executable %s\n", + (uintnat) truename); + fd = open(truename, O_RDONLY | O_BINARY); + if (fd == -1) { + caml_gc_message(0x100, "Cannot open file\n", 0); + return FILE_NOT_FOUND; + } + if (!do_open_script) { + err = read (fd, buf, 2); + if (err < 2 || (buf [0] == '#' && buf [1] == '!')) { + close(fd); + caml_gc_message(0x100, "Rejected #! script\n", 0); + return BAD_BYTECODE; + } + } + err = read_trailer(fd, trail); + if (err != 0) { + close(fd); + caml_gc_message(0x100, "Not a bytecode executable\n", 0); + return err; + } + return fd; +} + +/* Read the section descriptors */ + +void caml_read_section_descriptors(int fd, struct exec_trailer *trail) +{ + int toc_size, i; + + toc_size = trail->num_sections * 8; + trail->section = caml_stat_alloc(toc_size); + lseek(fd, - (long) (TRAILER_SIZE + toc_size), SEEK_END); + if (read(fd, (char *) trail->section, toc_size) != toc_size) + caml_fatal_error("Fatal error: cannot read section table\n"); + /* Fixup endianness of lengths */ + for (i = 0; i < trail->num_sections; i++) + fixup_endianness_trailer(&(trail->section[i].len)); +} + +/* Position fd at the beginning of the section having the given name. + Return the length of the section data in bytes, or -1 if no section + found with that name. */ + +int32 caml_seek_optional_section(int fd, struct exec_trailer *trail, char *name) +{ + long ofs; + int i; + + ofs = TRAILER_SIZE + trail->num_sections * 8; + for (i = trail->num_sections - 1; i >= 0; i--) { + ofs += trail->section[i].len; + if (strncmp(trail->section[i].name, name, 4) == 0) { + lseek(fd, -ofs, SEEK_END); + return trail->section[i].len; + } + } + return -1; +} + +/* Position fd at the beginning of the section having the given name. + Return the length of the section data in bytes. */ + +int32 caml_seek_section(int fd, struct exec_trailer *trail, char *name) +{ + int32 len = caml_seek_optional_section(fd, trail, name); + if (len == -1) + caml_fatal_error_arg("Fatal_error: section `%s' is missing\n", name); + return len; +} + +/* Read and return the contents of the section having the given name. + Add a terminating 0. Return NULL if no such section. */ + +static char * read_section(int fd, struct exec_trailer *trail, char *name) +{ + int32 len; + char * data; + + len = caml_seek_optional_section(fd, trail, name); + if (len == -1) return NULL; + data = caml_stat_alloc(len + 1); + if (read(fd, data, len) != len) + caml_fatal_error_arg("Fatal error: error reading section %s\n", name); + data[len] = 0; + return data; +} + +/* Invocation of ocamlrun: 4 cases. + + 1. runtime + bytecode + user types: ocamlrun [options] bytecode args... + arguments: ocamlrun [options] bytecode args... + + 2. bytecode script + user types: bytecode args... + 2a (kernel 1) arguments: ocamlrun ./bytecode args... + 2b (kernel 2) arguments: bytecode bytecode args... + + 3. concatenated runtime and bytecode + user types: composite args... + arguments: composite args... + +Algorithm: + 1- If argument 0 is a valid byte-code file that does not start with #!, + then we are in case 3 and we pass the same command line to the + Objective Caml program. + 2- In all other cases, we parse the command line as: + (whatever) [options] bytecode args... + and we strip "(whatever) [options]" from the command line. + +*/ + +/* Configuration parameters and flags */ + +static uintnat percent_free_init = Percent_free_def; +static uintnat max_percent_free_init = Max_percent_free_def; +static uintnat minor_heap_init = Minor_heap_def; +static uintnat heap_chunk_init = Heap_chunk_def; +static uintnat heap_size_init = Init_heap_def; +static uintnat max_stack_init = Max_stack_def; + +/* Parse options on the command line */ + +static int parse_command_line(char **argv) +{ + int i, j; + + for(i = 1; argv[i] != NULL && argv[i][0] == '-'; i++) { + switch(argv[i][1]) { +#ifdef DEBUG + case 't': + caml_trace_flag++; + break; +#endif + case 'v': + if (!strcmp (argv[i], "-version")){ + printf ("The Objective Caml runtime, version " OCAML_VERSION "\n"); + exit (0); + }else{ + caml_verb_gc = 0x001+0x004+0x008+0x010+0x020; + } + break; + case 'p': + for (j = 0; caml_names_of_builtin_cprim[j] != NULL; j++) + printf("%s\n", caml_names_of_builtin_cprim[j]); + exit(0); + break; + case 'b': + caml_record_backtrace(Val_true); + break; + case 'I': + if (argv[i + 1] != NULL) { + caml_ext_table_add(&caml_shared_libs_path, argv[i + 1]); + i++; + } + break; + default: + caml_fatal_error_arg("Unknown option %s.\n", argv[i]); + } + } + return i; +} + +/* Parse the OCAMLRUNPARAM variable */ +/* The option letter for each runtime option is the first letter of the + last word of the ML name of the option (see [stdlib/gc.mli]). + Except for l (maximum stack size) and h (initial heap size). +*/ + +/* If you change these functions, see also their copy in asmrun/startup.c */ + +static void scanmult (char *opt, uintnat *var) +{ + char mult = ' '; + int val; + sscanf (opt, "=%u%c", &val, &mult); + sscanf (opt, "=0x%x%c", &val, &mult); + switch (mult) { + case 'k': *var = (uintnat) val * 1024; break; + case 'M': *var = (uintnat) val * 1024 * 1024; break; + case 'G': *var = (uintnat) val * 1024 * 1024 * 1024; break; + default: *var = (uintnat) val; break; + } +} + +static void parse_camlrunparam(void) +{ + char *opt = getenv ("OCAMLRUNPARAM"); + uintnat p; + + if (opt == NULL) opt = getenv ("CAMLRUNPARAM"); + + if (opt != NULL){ + while (*opt != '\0'){ + switch (*opt++){ + case 's': scanmult (opt, &minor_heap_init); break; + case 'i': scanmult (opt, &heap_chunk_init); break; + case 'h': scanmult (opt, &heap_size_init); break; + case 'l': scanmult (opt, &max_stack_init); break; + case 'o': scanmult (opt, &percent_free_init); break; + case 'O': scanmult (opt, &max_percent_free_init); break; + case 'v': scanmult (opt, &caml_verb_gc); break; + case 'b': caml_record_backtrace(Val_true); break; + case 'p': caml_parser_trace = 1; break; + case 'a': scanmult (opt, &p); caml_set_allocation_policy (p); break; + } + } + } +} + +extern void caml_init_ieee_floats (void); + +#ifdef _WIN32 +extern void caml_signal_thread(void * lpParam); +#endif + +/* Main entry point when loading code from a file */ + +CAMLexport void caml_main(char **argv) +{ + int fd, pos; + struct exec_trailer trail; + struct channel * chan; + value res; + char * shared_lib_path, * shared_libs, * req_prims; + char * exe_name; +#ifdef __linux__ + static char proc_self_exe[256]; +#endif + + /* Machine-dependent initialization of the floating-point hardware + so that it behaves as much as possible as specified in IEEE */ + caml_init_ieee_floats(); + caml_init_custom_operations(); + caml_ext_table_init(&caml_shared_libs_path, 8); + caml_external_raise = NULL; + /* Determine options and position of bytecode file */ +#ifdef DEBUG + caml_verb_gc = 0xBF; +#endif + parse_camlrunparam(); + pos = 0; + exe_name = argv[0]; +#ifdef __linux__ + if (caml_executable_name(proc_self_exe, sizeof(proc_self_exe)) == 0) + exe_name = proc_self_exe; +#endif + fd = caml_attempt_open(&exe_name, &trail, 0); + if (fd < 0) { + pos = parse_command_line(argv); + if (argv[pos] == 0) + caml_fatal_error("No bytecode file specified.\n"); + exe_name = argv[pos]; + fd = caml_attempt_open(&exe_name, &trail, 1); + switch(fd) { + case FILE_NOT_FOUND: + caml_fatal_error_arg("Fatal error: cannot find file %s\n", argv[pos]); + break; + case BAD_BYTECODE: + caml_fatal_error_arg( + "Fatal error: the file %s is not a bytecode executable file\n", + argv[pos]); + break; + } + } + /* Read the table of contents (section descriptors) */ + caml_read_section_descriptors(fd, &trail); + /* Initialize the abstract machine */ + caml_init_gc (minor_heap_init, heap_size_init, heap_chunk_init, + percent_free_init, max_percent_free_init); + caml_init_stack (max_stack_init); + init_atoms(); + /* Initialize the interpreter */ + caml_interprete(NULL, 0); + /* Initialize the debugger, if needed */ + caml_debugger_init(); + /* Load the code */ + caml_code_size = caml_seek_section(fd, &trail, "CODE"); + caml_load_code(fd, caml_code_size); + /* Build the table of primitives */ + shared_lib_path = read_section(fd, &trail, "DLPT"); + shared_libs = read_section(fd, &trail, "DLLS"); + req_prims = read_section(fd, &trail, "PRIM"); + if (req_prims == NULL) caml_fatal_error("Fatal error: no PRIM section\n"); + caml_build_primitive_table(shared_lib_path, shared_libs, req_prims); + caml_stat_free(shared_lib_path); + caml_stat_free(shared_libs); + caml_stat_free(req_prims); + /* Load the globals */ + caml_seek_section(fd, &trail, "DATA"); + chan = caml_open_descriptor_in(fd); + caml_global_data = caml_input_val(chan); + caml_close_channel(chan); /* this also closes fd */ + caml_stat_free(trail.section); + /* Ensure that the globals are in the major heap. */ + caml_oldify_one (caml_global_data, &caml_global_data); + caml_oldify_mopup (); + /* Initialize system libraries */ + caml_init_exceptions(); + caml_sys_init(exe_name, argv + pos); +#ifdef _WIN32 + /* Start a thread to handle signals */ + if (getenv("CAMLSIGPIPE")) + _beginthread(caml_signal_thread, 4096, NULL); +#endif + /* Execute the program */ + caml_debugger(PROGRAM_START); + res = caml_interprete(caml_start_code, caml_code_size); + if (Is_exception_result(res)) { + caml_exn_bucket = Extract_exception(res); + if (caml_debugger_in_use) { + caml_extern_sp = &caml_exn_bucket; /* The debugger needs the + exception value.*/ + caml_debugger(UNCAUGHT_EXC); + } + caml_fatal_uncaught_exception(caml_exn_bucket); + } +} + +/* Main entry point when code is linked in as initialized data */ + +CAMLexport void caml_startup_code( + code_t code, asize_t code_size, + char *data, asize_t data_size, + char *section_table, asize_t section_table_size, + char **argv) +{ + value res; + + caml_init_ieee_floats(); + caml_init_custom_operations(); +#ifdef DEBUG + caml_verb_gc = 63; +#endif + parse_camlrunparam(); + caml_external_raise = NULL; + /* Initialize the abstract machine */ + caml_init_gc (minor_heap_init, heap_size_init, heap_chunk_init, + percent_free_init, max_percent_free_init); + caml_init_stack (max_stack_init); + init_atoms(); + /* Initialize the interpreter */ + caml_interprete(NULL, 0); + /* Load the code */ + caml_start_code = code; +#ifdef THREADED_CODE + caml_thread_code(caml_start_code, code_size); +#endif + /* Use the builtin table of primitives */ + caml_build_primitive_table_builtin(); + /* Load the globals */ + caml_global_data = caml_input_value_from_block(data, data_size); + /* Ensure that the globals are in the major heap. */ + caml_oldify_one (caml_global_data, &caml_global_data); + caml_oldify_mopup (); + /* Record the sections (for caml_get_section_table in meta.c) */ + caml_section_table = section_table; + caml_section_table_size = section_table_size; + /* Run the code */ + caml_init_exceptions(); + caml_sys_init("", argv); + res = caml_interprete(caml_start_code, code_size); + if (Is_exception_result(res)) + caml_fatal_uncaught_exception(Extract_exception(res)); +} diff --git a/byterun/startup.h b/byterun/startup.h new file mode 100644 index 0000000..cfc649f --- /dev/null +++ b/byterun/startup.h @@ -0,0 +1,40 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: startup.h,v 1.5 2004-02-22 15:07:51 xleroy Exp $ */ + +#ifndef CAML_STARTUP_H +#define CAML_STARTUP_H + +#include "mlvalues.h" +#include "exec.h" + +CAMLextern void caml_main(char **argv); + +CAMLextern void caml_startup_code( + code_t code, asize_t code_size, + char *data, asize_t data_size, + char *section_table, asize_t section_table_size, + char **argv); + +enum { FILE_NOT_FOUND = -1, BAD_BYTECODE = -2 }; + +extern int caml_attempt_open(char **name, struct exec_trailer *trail, + int do_open_script); +extern void caml_read_section_descriptors(int fd, struct exec_trailer *trail); +extern int32 caml_seek_optional_section(int fd, struct exec_trailer *trail, + char *name); +extern int32 caml_seek_section(int fd, struct exec_trailer *trail, char *name); + + +#endif /* CAML_STARTUP_H */ diff --git a/byterun/str.c b/byterun/str.c new file mode 100644 index 0000000..1d8506b --- /dev/null +++ b/byterun/str.c @@ -0,0 +1,156 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: str.c,v 1.28 2007-01-30 09:52:08 xleroy Exp $ */ + +/* Operations on strings */ + +#include +#include +#include "alloc.h" +#include "fail.h" +#include "mlvalues.h" +#include "misc.h" +#ifdef HAS_LOCALE +#include +#endif + +CAMLexport mlsize_t caml_string_length(value s) +{ + mlsize_t temp; + temp = Bosize_val(s) - 1; + Assert (Byte (s, temp - Byte (s, temp)) == 0); + return temp - Byte (s, temp); +} + +CAMLprim value caml_ml_string_length(value s) +{ + mlsize_t temp; + temp = Bosize_val(s) - 1; + Assert (Byte (s, temp - Byte (s, temp)) == 0); + return Val_long(temp - Byte (s, temp)); +} + +CAMLprim value caml_create_string(value len) +{ + mlsize_t size = Long_val(len); + if (size > Bsize_wsize (Max_wosize) - 1){ + caml_invalid_argument("String.create"); + } + return caml_alloc_string(size); +} + +CAMLprim value caml_string_get(value str, value index) +{ + intnat idx = Long_val(index); + if (idx < 0 || idx >= caml_string_length(str)) caml_array_bound_error(); + return Val_int(Byte_u(str, idx)); +} + +CAMLprim value caml_string_set(value str, value index, value newval) +{ + intnat idx = Long_val(index); + if (idx < 0 || idx >= caml_string_length(str)) caml_array_bound_error(); + Byte_u(str, idx) = Int_val(newval); + return Val_unit; +} + +CAMLprim value caml_string_equal(value s1, value s2) +{ + mlsize_t sz1, sz2; + value * p1, * p2; + + if (s1 == s2) return Val_true; + sz1 = Wosize_val(s1); + sz2 = Wosize_val(s2); + if (sz1 != sz2) return Val_false; + for(p1 = Op_val(s1), p2 = Op_val(s2); sz1 > 0; sz1--, p1++, p2++) + if (*p1 != *p2) return Val_false; + return Val_true; +} + +CAMLprim value caml_string_notequal(value s1, value s2) +{ + return Val_not(caml_string_equal(s1, s2)); +} + +CAMLprim value caml_string_compare(value s1, value s2) +{ + mlsize_t len1, len2; + int res; + + if (s1 == s2) return Val_int(0); + len1 = caml_string_length(s1); + len2 = caml_string_length(s2); + res = memcmp(String_val(s1), String_val(s2), len1 <= len2 ? len1 : len2); + if (res < 0) return Val_int(-1); + if (res > 0) return Val_int(1); + if (len1 < len2) return Val_int(-1); + if (len1 > len2) return Val_int(1); + return Val_int(0); +} + +CAMLprim value caml_string_lessthan(value s1, value s2) +{ + return caml_string_compare(s1, s2) < Val_int(0) ? Val_true : Val_false; +} + +CAMLprim value caml_string_lessequal(value s1, value s2) +{ + return caml_string_compare(s1, s2) <= Val_int(0) ? Val_true : Val_false; +} + +CAMLprim value caml_string_greaterthan(value s1, value s2) +{ + return caml_string_compare(s1, s2) > Val_int(0) ? Val_true : Val_false; +} + +CAMLprim value caml_string_greaterequal(value s1, value s2) +{ + return caml_string_compare(s1, s2) >= Val_int(0) ? Val_true : Val_false; +} + +CAMLprim value caml_blit_string(value s1, value ofs1, value s2, value ofs2, + value n) +{ + memmove(&Byte(s2, Long_val(ofs2)), &Byte(s1, Long_val(ofs1)), Int_val(n)); + return Val_unit; +} + +CAMLprim value caml_fill_string(value s, value offset, value len, value init) +{ + memset(&Byte(s, Long_val(offset)), Int_val(init), Long_val(len)); + return Val_unit; +} + +CAMLprim value caml_is_printable(value chr) +{ + int c; + +#ifdef HAS_LOCALE + static int locale_is_set = 0; + if (! locale_is_set) { + setlocale(LC_CTYPE, ""); + locale_is_set = 1; + } +#endif + c = Int_val(chr); + return Val_bool(isprint(c)); +} + +CAMLprim value caml_bitvect_test(value bv, value n) +{ + int pos = Int_val(n); + return Val_int(Byte_u(bv, pos >> 3) & (1 << (pos & 7))); +} + diff --git a/byterun/sys.c b/byterun/sys.c new file mode 100644 index 0000000..7aa0664 --- /dev/null +++ b/byterun/sys.c @@ -0,0 +1,346 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sys.c,v 1.83 2007-03-01 13:37:39 xleroy Exp $ */ + +/* Basic system calls */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if !_WIN32 +#include +#endif +#include "config.h" +#ifdef HAS_UNISTD +#include +#endif +#ifdef HAS_TIMES +#include +#endif +#ifdef HAS_GETRUSAGE +#include +#include +#endif +#ifdef HAS_GETTIMEOFDAY +#include +#endif +#include "alloc.h" +#include "debugger.h" +#include "fail.h" +#include "instruct.h" +#include "mlvalues.h" +#include "osdeps.h" +#include "signals.h" +#include "stacks.h" +#include "sys.h" + +#ifndef _WIN32 +extern int errno; +#endif + +static char * error_message(void) +{ + return strerror(errno); +} + +#ifndef EAGAIN +#define EAGAIN (-1) +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK (-1) +#endif + +CAMLexport void caml_sys_error(value arg) +{ + CAMLparam1 (arg); + char * err; + CAMLlocal1 (str); + + err = error_message(); + if (arg == NO_ARG) { + str = caml_copy_string(err); + } else { + int err_len = strlen(err); + int arg_len = caml_string_length(arg); + str = caml_alloc_string(arg_len + 2 + err_len); + memmove(&Byte(str, 0), String_val(arg), arg_len); + memmove(&Byte(str, arg_len), ": ", 2); + memmove(&Byte(str, arg_len + 2), err, err_len); + } + caml_raise_sys_error(str); + CAMLnoreturn; +} + +CAMLexport void caml_sys_io_error(value arg) +{ + if (errno == EAGAIN || errno == EWOULDBLOCK) { + caml_raise_sys_blocked_io(); + } else { + caml_sys_error(arg); + } +} + +CAMLprim value caml_sys_exit(value retcode) +{ +#ifndef NATIVE_CODE + caml_debugger(PROGRAM_EXIT); +#endif + exit(Int_val(retcode)); + return Val_unit; +} + +#ifndef O_BINARY +#define O_BINARY 0 +#endif +#ifndef O_TEXT +#define O_TEXT 0 +#endif +#ifndef O_NONBLOCK +#ifdef O_NDELAY +#define O_NONBLOCK O_NDELAY +#else +#define O_NONBLOCK 0 +#endif +#endif + +static int sys_open_flags[] = { + O_RDONLY, O_WRONLY, O_APPEND | O_WRONLY, O_CREAT, O_TRUNC, O_EXCL, + O_BINARY, O_TEXT, O_NONBLOCK +}; + +CAMLprim value caml_sys_open(value path, value vflags, value vperm) +{ + CAMLparam3(path, vflags, vperm); + int fd, flags, perm; + char * p; + + p = caml_stat_alloc(caml_string_length(path) + 1); + strcpy(p, String_val(path)); + flags = caml_convert_flag_list(vflags, sys_open_flags); + perm = Int_val(vperm); + /* open on a named FIFO can block (PR#1533) */ + caml_enter_blocking_section(); + fd = open(p, flags, perm); + caml_leave_blocking_section(); + caml_stat_free(p); + if (fd == -1) caml_sys_error(path); +#if defined(F_SETFD) && defined(FD_CLOEXEC) + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif + CAMLreturn(Val_long(fd)); +} + +CAMLprim value caml_sys_close(value fd) +{ + close(Int_val(fd)); + return Val_unit; +} + +CAMLprim value caml_sys_file_exists(value name) +{ + struct stat st; + return Val_bool(stat(String_val(name), &st) == 0); +} + +CAMLprim value caml_sys_is_directory(value name) +{ + struct stat st; + if (stat(String_val(name), &st) == -1) caml_sys_error(name); +#ifdef S_ISDIR + return Val_bool(S_ISDIR(st.st_mode)); +#else + return Val_bool(st.st_mode & S_IFDIR); +#endif +} + +CAMLprim value caml_sys_remove(value name) +{ + int ret; + ret = unlink(String_val(name)); + if (ret != 0) caml_sys_error(name); + return Val_unit; +} + +CAMLprim value caml_sys_rename(value oldname, value newname) +{ + if (rename(String_val(oldname), String_val(newname)) != 0) + caml_sys_error(NO_ARG); + return Val_unit; +} + +CAMLprim value caml_sys_chdir(value dirname) +{ + if (chdir(String_val(dirname)) != 0) caml_sys_error(dirname); + return Val_unit; +} + +CAMLprim value caml_sys_getcwd(value unit) +{ + char buff[4096]; +#ifdef HAS_GETCWD + if (getcwd(buff, sizeof(buff)) == 0) caml_sys_error(NO_ARG); +#else + if (getwd(buff) == 0) caml_sys_error(NO_ARG); +#endif /* HAS_GETCWD */ + return caml_copy_string(buff); +} + +CAMLprim value caml_sys_getenv(value var) +{ + char * res; + + res = getenv(String_val(var)); + if (res == 0) caml_raise_not_found(); + return caml_copy_string(res); +} + +char * caml_exe_name; +static char ** caml_main_argv; + +CAMLprim value caml_sys_get_argv(value unit) +{ + CAMLparam0 (); /* unit is unused */ + CAMLlocal3 (exe_name, argv, res); + exe_name = caml_copy_string(caml_exe_name); + argv = caml_copy_string_array((char const **) caml_main_argv); + res = caml_alloc_small(2, 0); + Field(res, 0) = exe_name; + Field(res, 1) = argv; + CAMLreturn(res); +} + +void caml_sys_init(char * exe_name, char **argv) +{ + caml_exe_name = exe_name; + caml_main_argv = argv; +} + +#ifdef _WIN32 +#define WIFEXITED(status) 1 +#define WEXITSTATUS(status) (status) +#else +#if !(defined(WIFEXITED) && defined(WEXITSTATUS)) +/* Assume old-style V7 status word */ +#define WIFEXITED(status) (((status) & 0xFF) == 0) +#define WEXITSTATUS(status) (((status) >> 8) & 0xFF) +#endif +#endif + +CAMLprim value caml_sys_system_command(value command) +{ + CAMLparam1 (command); + int status, retcode; + char *buf; + intnat len; + + len = caml_string_length (command); + buf = caml_stat_alloc (len + 1); + memmove (buf, String_val (command), len + 1); + caml_enter_blocking_section (); + status = system(buf); + caml_leave_blocking_section (); + caml_stat_free(buf); + if (status == -1) caml_sys_error(command); + if (WIFEXITED(status)) + retcode = WEXITSTATUS(status); + else + retcode = 255; + CAMLreturn (Val_int(retcode)); +} + +CAMLprim value caml_sys_time(value unit) +{ +#ifdef HAS_GETRUSAGE + struct rusage ru; + + getrusage (RUSAGE_SELF, &ru); + return caml_copy_double (ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1e6 + + ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1e6); +#else + #ifdef HAS_TIMES + #ifndef CLK_TCK + #ifdef HZ + #define CLK_TCK HZ + #else + #define CLK_TCK 60 + #endif + #endif + struct tms t; + times(&t); + return caml_copy_double((double)(t.tms_utime + t.tms_stime) / CLK_TCK); + #else + /* clock() is standard ANSI C */ + return caml_copy_double((double)clock() / CLOCKS_PER_SEC); + #endif +#endif +} + +#ifdef _WIN32 +extern intnat caml_win32_random_seed (void); +#endif + +CAMLprim value caml_sys_random_seed (value unit) +{ +#ifdef _WIN32 + return Val_long(caml_win32_random_seed()); +#else + intnat seed; +#ifdef HAS_GETTIMEOFDAY + struct timeval tv; + gettimeofday(&tv, NULL); + seed = tv.tv_sec ^ tv.tv_usec; +#else + seed = time (NULL); +#endif +#ifdef HAS_UNISTD + seed ^= (getppid() << 16) ^ getpid(); +#endif + return Val_long(seed); +#endif +} + +CAMLprim value caml_sys_get_config(value unit) +{ + CAMLparam0 (); /* unit is unused */ + CAMLlocal2 (result, ostype); + + ostype = caml_copy_string(OCAML_OS_TYPE); + result = caml_alloc_small (2, 0); + Field(result, 0) = ostype; + Field(result, 1) = Val_long (8 * sizeof(value)); + CAMLreturn (result); +} + +CAMLprim value caml_sys_read_directory(value path) +{ + CAMLparam1(path); + CAMLlocal1(result); + struct ext_table tbl; + + caml_ext_table_init(&tbl, 50); + if (caml_read_directory(String_val(path), &tbl) == -1){ + caml_ext_table_free(&tbl, 1); + caml_sys_error(path); + } + caml_ext_table_add(&tbl, NULL); + result = caml_copy_string_array((char const **) tbl.contents); + caml_ext_table_free(&tbl, 1); + CAMLreturn(result); +} diff --git a/byterun/sys.h b/byterun/sys.h new file mode 100644 index 0000000..f7de9a5 --- /dev/null +++ b/byterun/sys.h @@ -0,0 +1,30 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sys.h,v 1.16 2007-02-25 12:38:36 xleroy Exp $ */ + +#ifndef CAML_SYS_H +#define CAML_SYS_H + +#include "misc.h" + +#define NO_ARG Val_int(0) + +CAMLextern void caml_sys_error (value); +CAMLextern void caml_sys_io_error (value); +extern void caml_sys_init (char * exe_name, char ** argv); +CAMLextern value caml_sys_exit (value); + +extern char * caml_exe_name; + +#endif /* CAML_SYS_H */ diff --git a/byterun/terminfo.c b/byterun/terminfo.c new file mode 100644 index 0000000..e5f4d57 --- /dev/null +++ b/byterun/terminfo.c @@ -0,0 +1,132 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: terminfo.c,v 1.23 2004-01-01 16:42:38 doligez Exp $ */ + +/* Read and output terminal commands */ + +#include "config.h" +#include "alloc.h" +#include "fail.h" +#include "io.h" +#include "mlvalues.h" + +#define Uninitialised (Val_int(0)) +#define Bad_term (Val_int(1)) +#define Good_term_tag 0 + +#if defined (HAS_TERMCAP) && !defined (NATIVE_CODE) + +extern int tgetent (char * buffer, char * name); +extern char * tgetstr (char * id, char ** area); +extern int tgetnum (char * id); +extern int tputs (char * str, int count, int (*outchar)(int c)); + +static struct channel *chan; +static char area [1024]; +static char *area_p = area; +static int num_lines; +static char *up = NULL; +static char *down = NULL; +static char *standout = NULL; +static char *standend = NULL; + +CAMLprim value caml_terminfo_setup (value vchan) +{ + value result; + static char buffer[1024]; + char *term; + + chan = Channel (vchan); + + term = getenv ("TERM"); + if (term == NULL) return Bad_term; + if (tgetent(buffer, term) != 1) return Bad_term; + + num_lines = tgetnum ("li"); + up = tgetstr ("up", &area_p); + down = tgetstr ("do", &area_p); + standout = tgetstr ("us", &area_p); + standend = tgetstr ("ue", &area_p); + if (standout == NULL || standend == NULL){ + standout = tgetstr ("so", &area_p); + standend = tgetstr ("se", &area_p); + } + Assert (area_p <= area + 1024); + if (num_lines == -1 || up == NULL || down == NULL + || standout == NULL || standend == NULL){ + return Bad_term; + } + result = caml_alloc_small (1, Good_term_tag); + Field (result, 0) = Val_int (num_lines); + return result; +} + +static int terminfo_putc (int c) +{ + putch (chan, c); + return c; +} + +CAMLprim value caml_terminfo_backup (value lines) +{ + int i; + + for (i = 0; i < Int_val (lines); i++){ + tputs (up, 1, terminfo_putc); + } + return Val_unit; +} + +CAMLprim value caml_terminfo_standout (value start) +{ + tputs (Bool_val (start) ? standout : standend, 1, terminfo_putc); + return Val_unit; +} + +CAMLprim value caml_terminfo_resume (value lines) +{ + int i; + + for (i = 0; i < Int_val (lines); i++){ + tputs (down, 1, terminfo_putc); + } + return Val_unit; +} + +#else /* defined (HAS_TERMCAP) && !defined (NATIVE_CODE) */ + +CAMLexport value caml_terminfo_setup (value vchan) +{ + return Bad_term; +} + +CAMLexport value caml_terminfo_backup (value lines) +{ + caml_invalid_argument("Terminfo.backup"); + return Val_unit; +} + +CAMLexport value caml_terminfo_standout (value start) +{ + caml_invalid_argument("Terminfo.standout"); + return Val_unit; +} + +CAMLexport value caml_terminfo_resume (value lines) +{ + caml_invalid_argument("Terminfo.resume"); + return Val_unit; +} + +#endif /* defined (HAS_TERMCAP) && !defined (NATIVE_CODE) */ diff --git a/byterun/ui.h b/byterun/ui.h new file mode 100644 index 0000000..9ce054d --- /dev/null +++ b/byterun/ui.h @@ -0,0 +1,28 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: ui.h,v 1.5 2003-12-15 18:10:49 doligez Exp $ */ + +/* Function declarations for non-Unix user interfaces */ + +#ifndef CAML_UI_H +#define CAML_UI_H + +#include "config.h" + +void ui_exit (int return_code); +int ui_read (int file_desc, char *buf, unsigned int length); +int ui_write (int file_desc, char *buf, unsigned int length); +void ui_print_stderr (char *format, void *arg); + +#endif /* CAML_UI_H */ diff --git a/byterun/unix.c b/byterun/unix.c new file mode 100644 index 0000000..773c31c --- /dev/null +++ b/byterun/unix.c @@ -0,0 +1,322 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unix.c,v 1.37 2008-12-03 18:09:09 doligez Exp $ */ + +/* Unix-specific stuff */ + +#define _GNU_SOURCE + /* Helps finding RTLD_DEFAULT in glibc */ + +#include +#include +#include +#include +#include +#include +#include "config.h" +#ifdef SUPPORT_DYNAMIC_LINKING +#ifdef __CYGWIN32__ +#include "flexdll.h" +#else +#include +#endif +#endif +#ifdef HAS_UNISTD +#include +#endif +#ifdef HAS_DIRENT +#include +#else +#include +#endif +#include "memory.h" +#include "misc.h" +#include "osdeps.h" + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif + +char * caml_decompose_path(struct ext_table * tbl, char * path) +{ + char * p, * q; + int n; + + if (path == NULL) return NULL; + p = caml_stat_alloc(strlen(path) + 1); + strcpy(p, path); + q = p; + while (1) { + for (n = 0; q[n] != 0 && q[n] != ':'; n++) /*nothing*/; + caml_ext_table_add(tbl, q); + q = q + n; + if (*q == 0) break; + *q = 0; + q += 1; + } + return p; +} + +char * caml_search_in_path(struct ext_table * path, char * name) +{ + char * p, * fullname; + int i; + struct stat st; + + for (p = name; *p != 0; p++) { + if (*p == '/') goto not_found; + } + for (i = 0; i < path->size; i++) { + fullname = caml_stat_alloc(strlen((char *)(path->contents[i])) + + strlen(name) + 2); + strcpy(fullname, (char *)(path->contents[i])); + if (fullname[0] != 0) strcat(fullname, "/"); + strcat(fullname, name); + if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) return fullname; + caml_stat_free(fullname); + } + not_found: + fullname = caml_stat_alloc(strlen(name) + 1); + strcpy(fullname, name); + return fullname; +} + +#ifdef __CYGWIN32__ + +/* Cygwin needs special treatment because of the implicit ".exe" at the + end of executable file names */ + +static int cygwin_file_exists(char * name) +{ + int fd; + /* Cannot use stat() here because it adds ".exe" implicitly */ + fd = open(name, O_RDONLY); + if (fd == -1) return 0; + close(fd); + return 1; +} + +static char * cygwin_search_exe_in_path(struct ext_table * path, char * name) +{ + char * p, * fullname; + int i; + + for (p = name; *p != 0; p++) { + if (*p == '/' || *p == '\\') goto not_found; + } + for (i = 0; i < path->size; i++) { + fullname = caml_stat_alloc(strlen((char *)(path->contents[i])) + + strlen(name) + 6); + strcpy(fullname, (char *)(path->contents[i])); + strcat(fullname, "/"); + strcat(fullname, name); + if (cygwin_file_exists(fullname)) return fullname; + strcat(fullname, ".exe"); + if (cygwin_file_exists(fullname)) return fullname; + caml_stat_free(fullname); + } + not_found: + fullname = caml_stat_alloc(strlen(name) + 5); + strcpy(fullname, name); + if (cygwin_file_exists(fullname)) return fullname; + strcat(fullname, ".exe"); + if (cygwin_file_exists(fullname)) return fullname; + strcpy(fullname, name); + return fullname; +} + +#endif + +char * caml_search_exe_in_path(char * name) +{ + struct ext_table path; + char * tofree; + char * res; + + caml_ext_table_init(&path, 8); + tofree = caml_decompose_path(&path, getenv("PATH")); +#ifndef __CYGWIN32__ + res = caml_search_in_path(&path, name); +#else + res = cygwin_search_exe_in_path(&path, name); +#endif + caml_stat_free(tofree); + caml_ext_table_free(&path, 0); + return res; +} + +char * caml_search_dll_in_path(struct ext_table * path, char * name) +{ + char * dllname = caml_stat_alloc(strlen(name) + 4); + char * res; + strcpy(dllname, name); + strcat(dllname, ".so"); + res = caml_search_in_path(path, dllname); + caml_stat_free(dllname); + return res; +} + +#ifdef SUPPORT_DYNAMIC_LINKING +#ifdef __CYGWIN32__ +/* Use flexdll */ + +void * caml_dlopen(char * libname, int for_execution, int global) +{ + int flags = (global ? FLEXDLL_RTLD_GLOBAL : 0); + if (!for_execution) flags |= FLEXDLL_RTLD_NOEXEC; + return flexdll_dlopen(libname, flags); +} + +void caml_dlclose(void * handle) +{ + flexdll_dlclose(handle); +} + +void * caml_dlsym(void * handle, char * name) +{ + return flexdll_dlsym(handle, name); +} + +void * caml_globalsym(char * name) +{ + return flexdll_dlsym(flexdll_dlopen(NULL,0), name); +} + +char * caml_dlerror(void) +{ + return flexdll_dlerror(); +} + +#else +/* Use normal dlopen */ + +#ifndef RTLD_GLOBAL +#define RTLD_GLOBAL 0 +#endif +#ifndef RTLD_NODELETE +#define RTLD_NODELETE 0 +#endif + +void * caml_dlopen(char * libname, int for_execution, int global) +{ + return dlopen(libname, RTLD_NOW | (global ? RTLD_GLOBAL : 0) | RTLD_NODELETE); + /* Could use RTLD_LAZY if for_execution == 0, but needs testing */ +} + +void caml_dlclose(void * handle) +{ + dlclose(handle); +} + +void * caml_dlsym(void * handle, char * name) +{ +#ifdef DL_NEEDS_UNDERSCORE + char _name[1000] = "_"; + strncat (_name, name, 998); + name = _name; +#endif + return dlsym(handle, name); +} + +void * caml_globalsym(char * name) +{ +#ifdef RTLD_DEFAULT + return caml_dlsym(RTLD_DEFAULT, name); +#else + return NULL; +#endif +} + +char * caml_dlerror(void) +{ + return (char*) dlerror(); +} + +#endif +#else + +void * caml_dlopen(char * libname, int for_execution, int global) +{ + return NULL; +} + +void caml_dlclose(void * handle) +{ +} + +void * caml_dlsym(void * handle, char * name) +{ + return NULL; +} + +void * caml_globalsym(char * name) +{ + return NULL; +} + +char * caml_dlerror(void) +{ + return "dynamic loading not supported on this platform"; +} + +#endif + +/* Add to [contents] the (short) names of the files contained in + the directory named [dirname]. No entries are added for [.] and [..]. + Return 0 on success, -1 on error; set errno in the case of error. */ + +int caml_read_directory(char * dirname, struct ext_table * contents) +{ + DIR * d; +#ifdef HAS_DIRENT + struct dirent * e; +#else + struct direct * e; +#endif + char * p; + + d = opendir(dirname); + if (d == NULL) return -1; + while (1) { + e = readdir(d); + if (e == NULL) break; + if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0) continue; + p = caml_stat_alloc(strlen(e->d_name) + 1); + strcpy(p, e->d_name); + caml_ext_table_add(contents, p); + } + closedir(d); + return 0; +} + +/* Recover executable name from /proc/self/exe if possible */ + +#ifdef __linux__ + +int caml_executable_name(char * name, int name_len) +{ + int retcode; + struct stat st; + + retcode = readlink("/proc/self/exe", name, name_len); + if (retcode == -1 || retcode >= name_len) return -1; + name[retcode] = 0; + /* Make sure that the contents of /proc/self/exe is a regular file. + (Old Linux kernels return an inode number instead.) */ + if (stat(name, &st) != 0) return -1; + if (! S_ISREG(st.st_mode)) return -1; + return 0; +} + +#endif diff --git a/byterun/weak.c b/byterun/weak.c new file mode 100644 index 0000000..cdf32dc --- /dev/null +++ b/byterun/weak.c @@ -0,0 +1,193 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1997 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: weak.c,v 1.29 2008-09-17 14:55:30 doligez Exp $ */ + +/* Operations on weak arrays */ + +#include + +#include "alloc.h" +#include "fail.h" +#include "major_gc.h" +#include "memory.h" +#include "mlvalues.h" + +value caml_weak_list_head = 0; + +static value weak_dummy = 0; +value caml_weak_none = (value) &weak_dummy; + +CAMLprim value caml_weak_create (value len) +{ + mlsize_t size, i; + value res; + + size = Long_val (len) + 1; + if (size <= 0 || size > Max_wosize) caml_invalid_argument ("Weak.create"); + res = caml_alloc_shr (size, Abstract_tag); + for (i = 1; i < size; i++) Field (res, i) = caml_weak_none; + Field (res, 0) = caml_weak_list_head; + caml_weak_list_head = res; + return res; +} + +#define None_val (Val_int(0)) +#define Some_tag 0 + +static void do_set (value ar, mlsize_t offset, value v) +{ + if (Is_block (v) && Is_young (v)){ + /* modified version of Modify */ + value old = Field (ar, offset); + Field (ar, offset) = v; + if (!(Is_block (old) && Is_young (old))){ + if (caml_weak_ref_table.ptr >= caml_weak_ref_table.limit){ + CAMLassert (caml_weak_ref_table.ptr == caml_weak_ref_table.limit); + caml_realloc_ref_table (&caml_weak_ref_table); + } + *caml_weak_ref_table.ptr++ = &Field (ar, offset); + } + }else{ + Field (ar, offset) = v; + } +} + +CAMLprim value caml_weak_set (value ar, value n, value el) +{ + mlsize_t offset = Long_val (n) + 1; + Assert (Is_in_heap (ar)); + if (offset < 1 || offset >= Wosize_val (ar)){ + caml_invalid_argument ("Weak.set"); + } + if (el != None_val && Is_block (el)){ + Assert (Wosize_val (el) == 1); + do_set (ar, offset, Field (el, 0)); + }else{ + Field (ar, offset) = caml_weak_none; + } + return Val_unit; +} + +#define Setup_for_gc +#define Restore_after_gc + +CAMLprim value caml_weak_get (value ar, value n) +{ + CAMLparam2 (ar, n); + mlsize_t offset = Long_val (n) + 1; + CAMLlocal2 (res, elt); + Assert (Is_in_heap (ar)); + if (offset < 1 || offset >= Wosize_val (ar)){ + caml_invalid_argument ("Weak.get"); + } + if (Field (ar, offset) == caml_weak_none){ + res = None_val; + }else{ + elt = Field (ar, offset); + if (caml_gc_phase == Phase_mark && Is_block (elt) && Is_in_heap (elt)){ + caml_darken (elt, NULL); + } + res = caml_alloc_small (1, Some_tag); + Field (res, 0) = elt; + } + CAMLreturn (res); +} + +#undef Setup_for_gc +#undef Restore_after_gc + +CAMLprim value caml_weak_get_copy (value ar, value n) +{ + CAMLparam2 (ar, n); + mlsize_t offset = Long_val (n) + 1; + CAMLlocal2 (res, elt); + value v; /* Caution: this is NOT a local root. */ + Assert (Is_in_heap (ar)); + if (offset < 1 || offset >= Wosize_val (ar)){ + caml_invalid_argument ("Weak.get"); + } + + v = Field (ar, offset); + if (v == caml_weak_none) CAMLreturn (None_val); + if (Is_block (v) && Is_in_heap_or_young(v)) { + elt = caml_alloc (Wosize_val (v), Tag_val (v)); + /* The GC may erase or move v during this call to caml_alloc. */ + v = Field (ar, offset); + if (v == caml_weak_none) CAMLreturn (None_val); + if (Tag_val (v) < No_scan_tag){ + mlsize_t i; + for (i = 0; i < Wosize_val (v); i++){ + value f = Field (v, i); + if (caml_gc_phase == Phase_mark && Is_block (f) && Is_in_heap (f)){ + caml_darken (f, NULL); + } + Modify (&Field (elt, i), f); + } + }else{ + memmove (Bp_val (elt), Bp_val (v), Bosize_val (v)); + } + }else{ + elt = v; + } + res = caml_alloc_small (1, Some_tag); + Field (res, 0) = elt; + + CAMLreturn (res); +} + +CAMLprim value caml_weak_check (value ar, value n) +{ + mlsize_t offset = Long_val (n) + 1; + Assert (Is_in_heap (ar)); + if (offset < 1 || offset >= Wosize_val (ar)){ + caml_invalid_argument ("Weak.get"); + } + return Val_bool (Field (ar, offset) != caml_weak_none); +} + +CAMLprim value caml_weak_blit (value ars, value ofs, + value ard, value ofd, value len) +{ + mlsize_t offset_s = Long_val (ofs) + 1; + mlsize_t offset_d = Long_val (ofd) + 1; + mlsize_t length = Long_val (len); + long i; + Assert (Is_in_heap (ars)); + Assert (Is_in_heap (ard)); + if (offset_s < 1 || offset_s + length > Wosize_val (ars)){ + caml_invalid_argument ("Weak.blit"); + } + if (offset_d < 1 || offset_d + length > Wosize_val (ard)){ + caml_invalid_argument ("Weak.blit"); + } + if (caml_gc_phase == Phase_mark && caml_gc_subphase == Subphase_weak1){ + for (i = 0; i < length; i++){ + value v = Field (ars, offset_s + i); + if (v != caml_weak_none && Is_block (v) && Is_in_heap (v) + && Is_white_val (v)){ + Field (ars, offset_s + i) = caml_weak_none; + } + } + } + if (offset_d < offset_s){ + for (i = 0; i < length; i++){ + do_set (ard, offset_d + i, Field (ars, offset_s + i)); + } + }else{ + for (i = length - 1; i >= 0; i--){ + do_set (ard, offset_d + i, Field (ars, offset_s + i)); + } + } + return Val_unit; +} diff --git a/byterun/weak.h b/byterun/weak.h new file mode 100644 index 0000000..e0ef035 --- /dev/null +++ b/byterun/weak.h @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1997 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: weak.h,v 1.7 2004-01-01 16:42:38 doligez Exp $ */ + +/* Operations on weak arrays */ + +#ifndef CAML_WEAK_H +#define CAML_WEAK_H + +#include "mlvalues.h" + +extern value caml_weak_list_head; +extern value caml_weak_none; + +#endif /* CAML_WEAK_H */ diff --git a/byterun/win32.c b/byterun/win32.c new file mode 100644 index 0000000..d8c3951 --- /dev/null +++ b/byterun/win32.c @@ -0,0 +1,545 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: win32.c,v 1.36 2008-04-22 12:24:10 frisch Exp $ */ + +/* Win32-specific stuff */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fail.h" +#include "memory.h" +#include "misc.h" +#include "osdeps.h" +#include "signals.h" +#include "sys.h" + +#include "flexdll.h" + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif + +char * caml_decompose_path(struct ext_table * tbl, char * path) +{ + char * p, * q; + int n; + + if (path == NULL) return NULL; + p = caml_stat_alloc(strlen(path) + 1); + strcpy(p, path); + q = p; + while (1) { + for (n = 0; q[n] != 0 && q[n] != ';'; n++) /*nothing*/; + caml_ext_table_add(tbl, q); + q = q + n; + if (*q == 0) break; + *q = 0; + q += 1; + } + return p; +} + +char * caml_search_in_path(struct ext_table * path, char * name) +{ + char * p, * fullname; + int i; + struct stat st; + + for (p = name; *p != 0; p++) { + if (*p == '/' || *p == '\\') goto not_found; + } + for (i = 0; i < path->size; i++) { + fullname = caml_stat_alloc(strlen((char *)(path->contents[i])) + + strlen(name) + 2); + strcpy(fullname, (char *)(path->contents[i])); + strcat(fullname, "\\"); + strcat(fullname, name); + caml_gc_message(0x100, "Searching %s\n", (uintnat) fullname); + if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) return fullname; + caml_stat_free(fullname); + } + not_found: + caml_gc_message(0x100, "%s not found in search path\n", (uintnat) name); + fullname = caml_stat_alloc(strlen(name) + 1); + strcpy(fullname, name); + return fullname; +} + +CAMLexport char * caml_search_exe_in_path(char * name) +{ + char * fullname, * filepart; + DWORD pathlen, retcode; + + pathlen = strlen(name) + 1; + if (pathlen < 256) pathlen = 256; + while (1) { + fullname = stat_alloc(pathlen); + retcode = SearchPath(NULL, /* use system search path */ + name, + ".exe", /* add .exe extension if needed */ + pathlen, + fullname, + &filepart); + if (retcode == 0) { + caml_gc_message(0x100, "%s not found in search path\n", + (uintnat) name); + strcpy(fullname, name); + break; + } + if (retcode < pathlen) break; + stat_free(fullname); + pathlen = retcode + 1; + } + return fullname; +} + +char * caml_search_dll_in_path(struct ext_table * path, char * name) +{ + char * dllname = caml_stat_alloc(strlen(name) + 5); + char * res; + strcpy(dllname, name); + strcat(dllname, ".dll"); + res = caml_search_in_path(path, dllname); + caml_stat_free(dllname); + return res; +} + +void * caml_dlopen(char * libname, int for_execution, int global) +{ + void *handle; + int flags = (global ? FLEXDLL_RTLD_GLOBAL : 0); + if (!for_execution) flags |= FLEXDLL_RTLD_NOEXEC; + handle = flexdll_dlopen(libname, flags); + if ((handle != NULL) && ((caml_verb_gc & 0x100) != 0)) { + flexdll_dump_exports(handle); + fflush(stdout); + } + return handle; +} + +void caml_dlclose(void * handle) +{ + flexdll_dlclose(handle); +} + +void * caml_dlsym(void * handle, char * name) +{ + return flexdll_dlsym(handle, name); +} + +void * caml_globalsym(char * name) +{ + return flexdll_dlsym(flexdll_dlopen(NULL,0), name); +} + +char * caml_dlerror(void) +{ + return flexdll_dlerror(); +} + +/* Proper emulation of signal(), including ctrl-C and ctrl-break */ + +typedef void (*sighandler)(int sig); +static int ctrl_handler_installed = 0; +static volatile sighandler ctrl_handler_action = SIG_DFL; + +static BOOL WINAPI ctrl_handler(DWORD event) +{ + int saved_mode; + + /* Only ctrl-C and ctrl-Break are handled */ + if (event != CTRL_C_EVENT && event != CTRL_BREAK_EVENT) return FALSE; + /* Default behavior is to exit, which we get by not handling the event */ + if (ctrl_handler_action == SIG_DFL) return FALSE; + /* Ignore behavior is to do nothing, which we get by claiming that we + have handled the event */ + if (ctrl_handler_action == SIG_IGN) return TRUE; + /* Win32 doesn't like it when we do a longjmp() at this point + (it looks like we're running in a different thread than + the main program!). So, just record the signal. */ + caml_record_signal(SIGINT); + /* We have handled the event */ + return TRUE; +} + +sighandler caml_win32_signal(int sig, sighandler action) +{ + sighandler oldaction; + + if (sig != SIGINT) return signal(sig, action); + if (! ctrl_handler_installed) { + SetConsoleCtrlHandler(ctrl_handler, TRUE); + ctrl_handler_installed = 1; + } + oldaction = ctrl_handler_action; + ctrl_handler_action = action; + return oldaction; +} + +/* Expansion of @responsefile and *? file patterns in the command line */ + +static int argc; +static char ** argv; +static int argvsize; + +static void store_argument(char * arg); +static void expand_argument(char * arg); +static void expand_pattern(char * arg); +static void expand_diversion(char * filename); + +static void out_of_memory(void) +{ + fprintf(stderr, "Out of memory while expanding command line\n"); + exit(2); +} + +static void store_argument(char * arg) +{ + if (argc + 1 >= argvsize) { + argvsize *= 2; + argv = (char **) realloc(argv, argvsize * sizeof(char *)); + if (argv == NULL) out_of_memory(); + } + argv[argc++] = arg; +} + +static void expand_argument(char * arg) +{ + char * p; + + if (arg[0] == '@') { + expand_diversion(arg + 1); + return; + } + for (p = arg; *p != 0; p++) { + if (*p == '*' || *p == '?') { + expand_pattern(arg); + return; + } + } + store_argument(arg); +} + +static void expand_pattern(char * pat) +{ + int handle; + struct _finddata_t ffblk; + int preflen; + + handle = _findfirst(pat, &ffblk); + if (handle == -1) { + store_argument(pat); /* a la Bourne shell */ + return; + } + for (preflen = strlen(pat); preflen > 0; preflen--) { + char c = pat[preflen - 1]; + if (c == '\\' || c == '/' || c == ':') break; + } + do { + char * name = malloc(preflen + strlen(ffblk.name) + 1); + if (name == NULL) out_of_memory(); + memcpy(name, pat, preflen); + strcpy(name + preflen, ffblk.name); + store_argument(name); + } while (_findnext(handle, &ffblk) != -1); + _findclose(handle); +} + +static void expand_diversion(char * filename) +{ + struct _stat stat; + int fd; + char * buf, * endbuf, * p, * q, * s; + int inquote; + + if (_stat(filename, &stat) == -1 || + (fd = _open(filename, O_RDONLY | O_BINARY, 0)) == -1) { + fprintf(stderr, "Cannot open file %s\n", filename); + exit(2); + } + buf = (char *) malloc(stat.st_size + 1); + if (buf == NULL) out_of_memory(); + _read(fd, buf, stat.st_size); + endbuf = buf + stat.st_size; + _close(fd); + for (p = buf; p < endbuf; /*nothing*/) { + /* Skip leading blanks */ + while (p < endbuf && isspace(*p)) p++; + if (p >= endbuf) break; + s = p; + /* Skip to end of argument, taking quotes into account */ + q = s; + inquote = 0; + while (p < endbuf) { + if (! inquote) { + if (isspace(*p)) break; + if (*p == '"') { inquote = 1; p++; continue; } + *q++ = *p++; + } else { + switch (*p) { + case '"': + inquote = 0; p++; continue; + case '\\': + if (p + 4 <= endbuf && strncmp(p, "\\\\\\\"", 4) == 0) { + p += 4; *q++ = '\\'; *q++ = '"'; continue; + } + if (p + 3 <= endbuf && strncmp(p, "\\\\\"", 3) == 0) { + p += 3; *q++ = '\\'; inquote = 0; continue; + } + if (p + 2 <= endbuf && p[1] == '"') { + p += 2; *q++ = '"'; continue; + } + /* fallthrough */ + default: + *q++ = *p++; + } + } + } + /* Delimit argument and expand it */ + *q++ = 0; + expand_argument(s); + p++; + } +} + +CAMLexport void caml_expand_command_line(int * argcp, char *** argvp) +{ + int i; + argc = 0; + argvsize = 16; + argv = (char **) malloc(argvsize * sizeof(char *)); + if (argv == NULL) out_of_memory(); + for (i = 0; i < *argcp; i++) expand_argument((*argvp)[i]); + argv[argc] = NULL; + *argcp = argc; + *argvp = argv; +} + +/* Add to [contents] the (short) names of the files contained in + the directory named [dirname]. No entries are added for [.] and [..]. + Return 0 on success, -1 on error; set errno in the case of error. */ + +int caml_read_directory(char * dirname, struct ext_table * contents) +{ + int dirnamelen; + char * template; +#if _MSC_VER <= 1200 + int h; +#else + intptr_t h; +#endif + struct _finddata_t fileinfo; + char * p; + + dirnamelen = strlen(dirname); + template = caml_stat_alloc(dirnamelen + 5); + strcpy(template, dirname); + switch (dirname[dirnamelen - 1]) { + case '/': case '\\': case ':': + strcat(template, "*.*"); break; + default: + strcat(template, "\\*.*"); + } + h = _findfirst(template, &fileinfo); + caml_stat_free(template); + if (h == -1) return errno == ENOENT ? 0 : -1; + do { + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { + p = caml_stat_alloc(strlen(fileinfo.name) + 1); + strcpy(p, fileinfo.name); + caml_ext_table_add(contents, p); + } + } while (_findnext(h, &fileinfo) == 0); + _findclose(h); + return 0; +} + +#ifndef NATIVE_CODE + +/* Set up a new thread for control-C emulation and termination */ + +void caml_signal_thread(void * lpParam) +{ + char *endptr; + HANDLE h; + /* Get an hexa-code raw handle through the environment */ + h = (HANDLE) strtol(getenv("CAMLSIGPIPE"), &endptr, 16); + while (1) { + DWORD numread; + BOOL ret; + char iobuf[2]; + /* This shall always return a single character */ + ret = ReadFile(h, iobuf, 1, &numread, NULL); + if (!ret || numread != 1) caml_sys_exit(Val_int(2)); + switch (iobuf[0]) { + case 'C': + caml_record_signal(SIGINT); + break; + case 'T': + raise(SIGTERM); + return; + } + } +} + +#endif /* NATIVE_CODE */ + +#if defined(NATIVE_CODE) && !defined(_WIN64) + +/* Handling of system stack overflow. + * Based on code provided by Olivier Andrieu. + + * An EXCEPTION_STACK_OVERFLOW is signaled when the guard page at the + * end of the stack has been accessed. Windows clears the PAGE_GUARD + * protection (making it a regular PAGE_READWRITE) and then calls our + * exception handler. This means that although we're handling an "out + * of stack" condition, there is a bit of stack available to call + * functions and allocate temporaries. + * + * PAGE_GUARD is a one-shot access protection mechanism: we need to + * restore the PAGE_GUARD protection on this page otherwise the next + * stack overflow won't be detected and the program will abruptly exit + * with STATUS_ACCESS_VIOLATION. + * + * Visual Studio 2003 and later (_MSC_VER >= 1300) have a + * _resetstkoflw() function that resets this protection. + * Unfortunately, it cannot work when called directly from the + * exception handler because at this point we are using the page that + * is to be protected. + * + * A solution is to used an alternate stack when restoring the + * protection. However it's not possible to use _resetstkoflw() then + * since it determines the stack pointer by calling alloca(): it would + * try to protect the alternate stack. + * + * Finally, we call caml_raise_stack_overflow; it will either call + * caml_raise_exception which switches back to the normal stack, or + * call caml_fatal_uncaught_exception which terminates the program + * quickly. + * + * NB: The PAGE_GUARD protection is only available on WinNT, not + * Win9x. There is an equivalent mechanism on Win9x with + * PAGE_NOACCESS. + * + * Currently, does not work under Win64. + */ + +static uintnat win32_alt_stack[0x80]; + +static void caml_reset_stack (void *faulting_address) +{ + OSVERSIONINFO osi; + SYSTEM_INFO si; + DWORD page_size; + MEMORY_BASIC_INFORMATION mbi; + DWORD oldprot; + + /* get the os version (Win9x or WinNT ?) */ + osi.dwOSVersionInfoSize = sizeof osi; + if (! GetVersionEx (&osi)) + goto failed; + + /* get the system's page size. */ + GetSystemInfo (&si); + page_size = si.dwPageSize; + + /* get some information on the page the fault occurred */ + if (! VirtualQuery (faulting_address, &mbi, sizeof mbi)) + goto failed; + + /* restore the PAGE_GUARD protection on this page */ + switch (osi.dwPlatformId) { + case VER_PLATFORM_WIN32_NT: + VirtualProtect (mbi.BaseAddress, page_size, + mbi.Protect | PAGE_GUARD, &oldprot); + break; + case VER_PLATFORM_WIN32_WINDOWS: + VirtualProtect (mbi.BaseAddress, page_size, + PAGE_NOACCESS, &oldprot); + break; + } + + failed: + caml_raise_stack_overflow(); +} + +extern char * caml_code_area_start, * caml_code_area_end; +CAMLextern int caml_is_in_code(void *); + +#define Is_in_code_area(pc) \ + ( ((char *)(pc) >= caml_code_area_start && \ + (char *)(pc) <= caml_code_area_end) \ + || (Classify_addr(pc) & In_code_area) ) + +static LONG CALLBACK + caml_UnhandledExceptionFilter (EXCEPTION_POINTERS* exn_info) +{ + DWORD code = exn_info->ExceptionRecord->ExceptionCode; + CONTEXT *ctx = exn_info->ContextRecord; + DWORD *ctx_ip = &(ctx->Eip); + DWORD *ctx_sp = &(ctx->Esp); + + if (code == EXCEPTION_STACK_OVERFLOW && Is_in_code_area (*ctx_ip)) + { + uintnat faulting_address; + uintnat * alt_esp; + + /* grab the address that caused the fault */ + faulting_address = exn_info->ExceptionRecord->ExceptionInformation[1]; + + /* call caml_reset_stack(faulting_address) using the alternate stack */ + alt_esp = win32_alt_stack + sizeof(win32_alt_stack) / sizeof(uintnat); + *--alt_esp = faulting_address; + *ctx_sp = (uintnat) (alt_esp - 1); + *ctx_ip = (uintnat) &caml_reset_stack; + + return EXCEPTION_CONTINUE_EXECUTION; + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +void caml_win32_overflow_detection() +{ + SetUnhandledExceptionFilter (caml_UnhandledExceptionFilter); +} + +#endif + +/* Seeding of pseudo-random number generators */ + +intnat caml_win32_random_seed (void) +{ + intnat seed; + SYSTEMTIME t; + + GetLocalTime(&t); + seed = t.wMonth; + seed = (seed << 5) ^ t.wDay; + seed = (seed << 4) ^ t.wHour; + seed = (seed << 5) ^ t.wMinute; + seed = (seed << 5) ^ t.wSecond; + seed = (seed << 9) ^ t.wMilliseconds; + seed ^= GetCurrentProcessId(); + return seed; +} diff --git a/camlp4/.cvsignore b/camlp4/.cvsignore new file mode 100644 index 0000000..493096e --- /dev/null +++ b/camlp4/.cvsignore @@ -0,0 +1,3 @@ +*.cm* +.cache-status +*.tmp.ml diff --git a/camlp4/.vcs b/camlp4/.vcs new file mode 100644 index 0000000..70f4211 --- /dev/null +++ b/camlp4/.vcs @@ -0,0 +1,4 @@ +--- +exclude: + - !re boot/camlp4boot\.save\..* + - build/camlp4_config.ml diff --git a/camlp4/CHANGES b/camlp4/CHANGES new file mode 100644 index 0000000..571894b --- /dev/null +++ b/camlp4/CHANGES @@ -0,0 +1,898 @@ +- [...] + In the revised syntax of parsers the "?" is now a "??" like in the orignal + syntax to not conflict with optional labels. + +- [29 Jun 05] Add private row types. Make "private" a type constructor + "TyPrv" rather than a flag. (Jacques) + +- [09 Jun 04] Moved "-no_quot" option from pa_o to camlp4, enabling to + use it indepently fom pa_o.cmo. + +- [17 Nov 04] Renamed "loc" into "_loc", introducing an incompatibility + with existing code (3.08.x and before). Such code can generally run + unmodified using the -loc option (camlp4 -loc "loc"). + +Camlp4 Version 3.08.2 +------------------------ +- [07 Oct 04] Changes in the interfaces plexer.mli and pcaml.mli: + - plexer.mli: introduced a new lexer building function `make_lexer', + similar to `gmake', but returning a triple of references in addition + (holding respectively the character number of the beginning of the + current line, the current line number and the name of the file being + parsed). + - pcaml.mli: a new value `position'. A global reference to a triple like + the one mentioned above. +- [07 Sep 04] Camlp4 grammars `error recovery mode' now issues a warning + when used (but this warning is disabled by default). + +Camlp4 Version 3.08.[01] +------------------------ +- [05 Jul 04] creation of the `unmaintained' directory: + pa_format, pa_lefteval, pa_ocamllex, pa_olabl, pa_scheme and pa_sml + go there, each in its own subdir. Currently, they compile fine. +- [05 Jul 04] pa_ifdef, subsumed by pa_macro since 3.07, prints a warning + when loaded, encouraging use of pa_macro. +- [01 July 04] profiled versions of Camlp4 libs are *NOT* installed + by default (not even built). To build and install them, uncomment + the line PROFILING=prof in camlp4/config/Makefile.tpl, and then + make opt.opt && make install +- [22-23 June 04] `make install' now installs also pa_[or].cmx, pa_[or]p.cmx, + pa_[or]_fast.cmx, and odyl.cmx +- [12 may 04] Added to the camlp4 tools the -version option that prints + the version number, in the same way as the other ocaml tools. +- [12 may 04] Locations are now handled as in OCaml. The main benefit + is that line numbers are now correct in error messages. However, this + slightly changes the interface of a few Camlp4 modules (see ICHANGES). + ** Warning: Some contribs of the camlp4 distribution are broken because + of this change. In particular the scheme/lisp syntaxes. +- [20 nov 03] Illegal escape sequences in strings now issue a warning. + +Camlp4 Version 3.07 +___________________ + +- [29 Sep 03] Camlp4 code now licensed under the LGPL minus clause 6. +- [09 Sep 03] Added tokens LABEL and OPTLABEL in plexer, and use them in + both parsers (ocaml and revised). There was, afaik, no other way to fix + ambiguities (bugs) in parsing labels and type constraints. + +Camlp4 Version 3.07 beta1 +________________________ + +- [July 03] Updated the ocaml/camlp4 CVS tree with the camlp4 + "parallel" CVS tree, which becomes obsolete from now on. + Added support for recursive modules, private data constructors, and + new syntaxes for integers (int32, nativeint, ...). + +Camlp4 Version 3.06++ +----------------------- + +- [02 Dec 02] In AST predefined quotation, changed antiquotations for + "rec", "mutable": now all are with coercion "opt": $opt:...$ (instead + of "rec" and "mut"). Added antiquotation for "private". Cleaned up + the entries for "methods" and for labelled and optional parameters. +- [29 Nov 02] Removed all "extract_crc" stuff no more necessary with + the new interface of Dynlink. +- [26 Nov 02] Added ability to use "#use" directives in compiled files. +- [21 Nov 02] Changed Scheme syntax for directives: now, e.g. #load "file" + is written: # (load "file"). Added directives in "implem", "interf" and + "use" directive. +- [20 Nov 02] Added Grammar.glexer returning the lexer used by a + grammar. Also added a field in Token.glexer type to ask lexers to + record the locations of the comments. +- [04 Nov 02] Added option -no_quot with normal syntax (pa_o.cmo): + don't parse quotations (it allows to use e.g. <:> as a valid token). +- [31 Oct 02] Added pa_macro.cmo (to replace pa_ifdef.cmo which is + kept for compatibility, but deprecated). The extended statements + allow de definitions of macros and conditional compilation like + in C. +- [29 Oct 02] Changed pretty printers of the three main syntaxes: if + the locations of input are not correct, do no more raise End_of_file + when displaying the inter-phrases (return: the input found up to eof + if not empty, otherwise the value of the -sep parameter if not empty, + otherwise the string "\n"). +- [25 Oct 02] Added option -records in pa_sml.cmo: generates normal + OCaml records instead of objects (the user must be sure that there + are no names conflicts). +- [22 Oct 02] Added Plexer.specific_space_dot: when set to "true", the + next call to Plexer.gmake returns a lexer where the dot preceded by + spaces (space, tab, newline, etc.) return a different token than when + not preceded by spaces. +- [19 Oct 02] Added printer in Scheme syntax: pr_scheme.cmo and the + extension pr_schemep.cmo which rebuilts parsers. +- [15 Oct 02] Now, in case of syntax error, the real input file name is + displayed (can be different from the input file, because of the possibility + of line directives, typically generated by /lib/cpp). + Changed interface of Stdpp.line_of_loc: now return also a string: the name + of the real input file name. +- [14 Oct 02] Fixed bug in normal syntax (pa_o.cmo): the constructors + with currification of parameters (C x y) were accepted. +- [14 Oct 02] Fixed many problems of make under Windows (in particular if + installations directories contain spaces). +- [11 Oct 02] In ocaml syntax (pa_o.cmo), fixed 3 bugs (or incompatibilities + with the ocaml yacc version of the compiler): 1/ "ref new foo" was + interpreted as "ref;; new foo" instead of "ref (new foo)" 2/ unary + minuses did not work correctly (nor in quotation of syntax trees), in + particular "-0.0" 3/ "begin end" was a syntax error, instead of being "()". +- [Sep-Oct 02] Many changes and improvements in Scheme syntax. +- [07 Oct 02] Added definition of Pcaml.type_declaration which is + now visible in the interface, allowing to change the type declarations. +- [07 Oct 02] Added Pcaml.syntax_name to allow syntax extensions to test + it and take different decision. In revised syntax, its value is "Revised", + in normal syntax "OCaml" and in Scheme syntax "Scheme". +- [03 Oct 02] Added lexing of '\xHH' where HH is hexadecimal number. +- [01 Oct 02] In normal syntax (camlp4o), fixed problem of lexing + comment: (* bleble'''*) +- [23 Sep 02] Fixed bug: input "0x" raised Failure "int_of_string" + without location (syntaxes pa_o and pa_r). +- [14 Sep 02] Added functions Grammar.iter_entry and Grammar.fold_entry + to iterate a grammar entry and transitively all the entries it calls. +- [12 Sep 02] Added "Pcaml.rename_id", a hook to allow parsers to give + ability to rename their identifiers. Called in Scheme syntax (pa_scheme.ml) + when generating its identifiers. +- [09 Sep 02] Fixed bug under toplevel, the command: + !Toploop.parse_toplevel_phrase (Lexing.from_buff "1;;");; + failed "End_of_file". +- [06 Sep 02] Added "Pcaml.string_of". Combined with Pcaml.pr_expr, + Pcaml.pr_patt, and so on, allow to pretty print syntax trees in string. + E.g. in the toplevel: + # #load "pr_o.cmo"; + # Pcaml.string_of Pcaml.pr_expr <:expr< let x = 3 in x + 2 >>;; + - : string = "let x = 3 in x + 2" + +Camlp4 Version 3.06 +-------------------- + +- [24 Jul 02] Added Scheme syntax: pa_scheme.ml, camlp4sch.cma (toplevel), + camlp4sch (command). + +Camlp4 Version 3.05 +----------------------- + +- [12 Jul 02] Better treatment of comments in option -cip (add comments + in phrases) for both printers pr_o.cmo (normal syntax) and pr_r.cmo + (revised syntax); added comments before let binding and class + structure items; treat comments inside sum and record type definitions; + the option -tc is now deprecated and equivalent to -cip. +- [13 Jun 02] Added pa_lefteval.cmo: add let..in expressions to guarantee + left evaluation of functions parameters, t-uples, and so on (instead of + the default non-specified-but-in-fact-right-to-left evaluation). +- [06 Jun 02] Changed revised syntax (pa_r) of variants types definition; + (Jacques Garrigue's idea): + old syntax new syntax + [| ... |] [ = ... ] + [| < ... |] [ < ... ] + [| > ... |] [ > ... ] + This applies also in predefined quotations of syntax tree for types + <:ctyp< ... >> +- [05 Jun 02] Added option -ss in pr_o.cmo: print with double semicolons; + and the option -no_ss is now by default. +- [30 May 02] Improved SML syntax (pa_sml). +- [30 May 02] Changed the AST for the "with module" construct (was with + type "module_type"; changed into type "module_expr"). +- [26 May 02] Added missing abstract module types. +- [21 Apr 02] Added polymorphic types for polymorphic methods: + revised syntax (example): ! 'a 'b . type + ctyp quotation: <:ctyp< ! $list:pl$ . $t$ >> +- [17 Apr 02] Fixed bug: in normal syntax (pa_o.cmo) made a parse error on + the "dot" on (in interface file file): + class c : a * B.c -> object val x : int end +- [03 Apr 02] Fixed bug: (* "(*" *) resulted in "comment not terminated". +- [03 Apr 02] Fixed incompatibility with ocaml: ''' and '"' must be + displayed as '\'' and '\"' in normal syntax printer (pr_o.cmo). +- [03 Apr 02] When there are several tokens parsed together (locally LL(n)), + the location error now highlights all tokens, resulting in a more clear + error message (e.g. "for i let" would display "illegal begin of expr" + and highlight the 3 tokens, not just "for"). +- [30 Mar 02] Added pa_extfold.cmo extending pa_extend.cmo by grammar + symbols FOLD0 and FOLD1. Work like LIST0 and LIST1 but have two initial + parameters: a function of type 'a -> 'b -> 'b doing the fold and an + initial value of type 'b. Actually, LIST0 now is like + FOLD0 (fun x y -> x :: y) [] + with an reverse of the resulting list. +- [20 Mar 02] Fixed problem: when running a toplevel linked with camlp4 + as a script, the camlp4 welcome message was displayed. +- [14 Mar 02] The configure shell and the program now test the consistency + of OCaml and Camlp4. Therefore 1/ if trying to compile this version with + an incompatible OCaml version or 2/ trying to run an installed Camlp4 with + a incompatible OCaml version: in both cases, camlp4 fails. +- [14 Mar 02] When make opt.opt is done, the very fast version is made for + the normal syntax ("compiled" version). The installed camlp4o.opt is that + version. +- [05 Mar 02] Changed the conversion to OCaml syntax tree for <:expr< x.val >> + and <:expr< x.val := e >> which generates now the tree of !x and x := e, + no more x.contents and x.contents <- e. This change was necessary because + of a problem if a record has been defined with a field named "contents". + +- [16 Feb 02] Changed interface of grammars: the token type is now + customizable, using a new lexer type Token.glexer, parametrized by + the token type, and a new functor GMake. This was accompanied by + some cleanup. Become deprecated: the type Token.lexer (use Token.glexer), + Grammar.create (use Grammar.gcreate), Unsafe.reinit_gram (use + Unsafe.gram_reinit), the functor Grammar.Make (use Grammar.GMake). + Deprecated means that they are kept during some versions and removed + afterwards. +- [06 Feb 02] Added missing infix "%" in pa_o (normal syntax). +- [06 Feb 02] Added Grammar.print_entry printing any kind of (obj) entry + and having the Format.formatter as first parameter (Grammar.Entry.print + and its equivalent in functorial interface call it). +- [05 Feb 02] Added a flag Plexer.no_quotations. When set to True, the + quotations are no more lexed in all lexers built by Plexer.make () +- [05 Feb 02] Changed the printing of options so that the option -help + aligns correctly their documentation. One can use now Pcaml.add_option + without having to calculate that. +- [05 Feb 02] pr_r.cmo: now the option -ncip (no comments in phrases) is + by default, because its behaviour is not 100% sure. An option -cip has + been added to set it. +- [03 Feb 02] Added function Stdpp.line_of_loc returning the line and + columns positions from a character location and a file. +- [01 Feb 02] Fixed bug in token.ml: the location function provided by + lexer_func_of_parser, lexer_func_of_ocamllex and make_stream_and_location + could raise Invalid_argument "Array.make" for big files if the number + of read tokens overflows the maximum arrays size (Sys.max_array_length). + The bug is not really fixed: in case of this overflow, the returned + location is (0, 0) (but the program does not fail). +- [28 Jan 02] Fixed bug in pa_o when parsing class_types. A horrible hack + had to be programmed to be able to treat them correctly. +- [28 Jan 02] Fixed bug in OCaml toplevel when loading camlp4: the directives + were not applied in the good order. +- [26 Jan 02] The printer pr_extend.cmo try now also to rebuild GEXTEND + statements (before it tried only the EXTEND). +- [23 Jan 02] The empty functional stream "fstream [: :]" is now of type + 'a Fstream.t thanks to the new implementation of lazies allowing to + create polymorphic lazy values. +- [11 Jan 02] Added a test in grammars using Plexer that a keyword is not + used also as parameter of a LIDENT or a UIDENT. +- [04 Jan 02] Fixed bug in pa_sml (SML syntax): the function definitions + with several currified parameters did not work. It works now, but the + previous code was supposed to treat let ("fun" in SML syntax) definitions + of infix operators, what does not work any more now. +- [04 Jan 02] Alain Frisch's contribution: + Added pa_ocamllex.cma, syntax for ocamllex files. The command: + camlp4 pa_ocamllex.cmo pr_o.cmo -ocamllex -impl foo.mll > foo.ml + does the same thing as: + ocamllex foo.mll + Allow to compile directly mll files. Without option -ocamllex, allow + to insert lex rules in a ml file. +- [29 Dec 01] Added variable "inter_phrases" in Pcaml, of type ref (option + string) to specify the string to print between phrases in pretty printers. + The default is None, meaning to copy the inter phrases from the source + file. + +Camlp4 Version 3.04 +------------------- + +- [07 Dec 01] Added Pcaml.parse_interf and Pcaml.parse_implem, hooks to + specify the parsers tof use, i.e. now can use other parsing technics + than the Camlp4 grammar system. +- [27 Nov 01] Fixed functions Token.eval_char and Token.eval_string which + returned bad values, resulting lexing of backslash sequences incompatible + with OCaml (e.g. "\1" returned "\001" (one character) but OCaml returns + the string of the two characters \ and 1). +- [15 Nov 01] In revised syntax, in let binding in sequences, the "in" + can be replaced by a semicolon; the revised syntax printer pr_r.cmo + now rather prints a semicolon there. +- [07 Nov 01] Added the ability to use $ as token: was impossible so far, + because of AST quotation uses it for its antiquotation. The fix is just + a little (invisible) change in Plexer. +- [05 Nov 01] Added option -tc (types comment) when using pr_o or pr_r + try to print comments inside sum and record types like they are in + the source (not by default, because may work incorrectly). +- [05 Nov 01] Added option -ca (comment after) when using pr_o or pr_r: + print ocamldoc comments after the declarations, when they are before. +- [04 Nov 01] Added locations for variants and labels declarations in AST + (file MLast.mli). +- [03 Nov 01] In pretty printers pr_o and pr_r, skip to next begin of line + when displaying the sources between phrase, to prevent e.g. the displaying + of the possible last comment of a sum type declaration (the other comment + being not displayed anyway). +- [24 Oct 01] Fixed incorrect locations in sequences. +- [24 Oct 01] Was erroneously compiled by the OCaml boot compiler instead + of the generated ocamlc. Fixed. +- [15 Oct 01] Fixed some parsing differences between pa_o and ocamlyacc: + in parsers, in labels. +- [12 Oct 01] Added missing bigarray syntax a.{b} (and Cie) in standard + syntax (pa_o). + +Camlp4 Version 3.03 +------------------- + +- [09 Oct 01] Fixed bug: the token !$ did not work. Fixed and completed + some syntaxes of labels patterns. Added missing case in exception + declaration (exception rebinding). +- [05 Oct 01] Fixed bug in normal syntax: when defining a constructor + named "True" of "False" (capitalized, i.e. not like the booleans), it + did not work. +- [04 Oct 01] Fixed some revised and quotation syntaxes in objects classes + and types (cleaner). Cleaned up also several parts of the parsers. +- [02 Oct 01] In revised syntax, the warning for using old syntax for + sequences is now by default. To remove it, the option -no-warn-seq + of camlp4r has been added. Option -warn-seq has been removed. +- [07 Sep 01] Included Camlp4 in OCaml distribution. +- [06 Sep 01] Added missing pattern construction #t +- [05 Sep 01] Fixed bug in pa_o: {A.B.c = d} was refused. +- [26 Aug 01] Fixed bug: in normal and revised syntaxes, refused -1.0 + (minus float) as pattern. +- [24 Aug 01] Fixed bug: (a : b :> c) and ((a : b) :> c) were parsed + identically. +- [20 Aug 01] Fixed configure script for Windows configuration. +- [10 Aug 01] Fixed bug: <:expr< 'a' >> did not work because of a typing + problem. +- [10 Aug 01] Fixed bug in compilation process under Windows: the use of + the extension .exe was missing in several parts in Makefiles and shell + scripts. +- [09 Aug 01] Changed message error in grammar: in the case when the rule + is: ....; tok1; tok2; .. tokn; ... (n terminal tokens following each other), + where the grammar is locally LL(n), it displays now: + tok1 tok2 .. tokn expected + instead of just + tok1 expected + because "tok1" can be correct in the input, and in this case, the message + underscored the tok1 and said "tok1 expected". +- [07 Aug 01] When camlp4r.cma is loaded in the toplevel, the results are + now displayed in revised syntax. +- [04 Aug 01] Added syntax "declare..end" in quotations class_str_item and + class_sig_item to be able to generate several items from one only item + (like in str_item and sig_item). + +Camlp4 Version 3.02 +------------------- + +- [21 Jul 01] Fixed bug: <:expr< { l = x } >> was badly built and resulted + in a typing error. +- [13 Jul 01] Fixed bug: did not accept floats in patterns. +- [11 Jul 01] Added function Pcaml.top_printer to be able to use the + printers Pcaml.pr_expr, Pcaml.pr_patt, and so on for the #install_printer + of OCaml toplevel. Ex: + let f = Pcaml.top_printer Pcaml.pr_expr;; + #install_printer f;; + #load "pr_o.cmo";; +- [24 Jun 01] In grammars, added symbol ANY, returning the current token, + whichever it is. +- [24 Jun 01] In grammars, a rule list of the form [ s1 | s2 | .. | sn ] + is interpreted as [ x = s1 -> x | x = s2 -> x | .. x = sn -> x ] + instead of [ _ = s1 -> () | _ = s2 -> () .. ] +- [24 Jun 01] Moved the functions [Plexer.char_of_char_token] and + [Plexer.string_of_string_token] into module [Token] with names + [Token.eval_char] and [Token.eval_string]. +- [22 Jun 01] Added warning when using old syntax for sequences, while + and do (do..return, do..done) in predefined quotation expr. +- [22 Jun 01] Changed message for unbound quotations (more clear). + +Camlp4 Version 3.01.6: +---------------------- + +- [22 Jun 01] Changed the module Pretty into Spretty. +- [21 Jun 01] Camlp4 can now be compiled even if OCaml is not installed: + in the directory "config", the file "configure_batch" is a possibility + to configure the compilation (alternative of "configure" of the top + directory) and has a parameter "-ocaml-top" to specify the OCaml top + directory (relative to the camlp4/config directory). +- [21 Jun 01] The interactive "configure" now tests if the native-code + compilers ocamlc.opt and ocamlopt.opt are accessible and tell the + Makefile to preferably use them if they are. +- [16 Jun 01] The syntax tree for strings and characters now represent their + exact input representation (the node for characters is now of type string, + no more char). For example, the string "a\098c" remains "a\098c" and is + *not* converted into (the equivalent) "abc" in the syntax tree. The + convertion takes place when converting into OCaml tree representation. + This has the advantage that the pretty print now display them as they + are in the input file. To convert from input to real representation + (if needed), two functions have been added: Plexer.string_of_string_token + and Plexer.char_of_char_token. +- [10 Jun 01] In revised syntax, added ability to write {foo x = y} as short + form for {foo = fun x -> y}. +- [08 Jun 01] Completed missing cases in pa_extfun.cmo for variants. +- [06 Jun 01] Completed missing cases in abstract syntax tree and in normal + syntax parser pa_o.ml (about classes). +- [06 Jun 01] Fixed bug in pa_o.cmo (parser of normal syntax): (~~) did not + work, and actually all prefix operators between parentheses. + +Camlp4 Version 3.01.5: +---------------------- + +- [04 Jun 01] Fixed bug: when using "include" in a structure item the rest + of the structure was lost. +- [31 May 01] Added ability to user #load and #directory inside ml or mli + files to specify a cmo file to be loaded (for syntax extension) or the + directory path (like option -I). Same semantics than in toplevel. +- [29 May 01] The name of the location variable used in grammars (action + parts of the rules) and in the predefined quotations for OCaml syntax + trees is now configurable in Stdpp.loc_name (string reference). Added also + option -loc to set this variable. Default: loc. +- [26 May 01] Added functional streams: a library module Fstream and a syntax + kit: pa_fstream.cmo. Syntax: + streams: fstream [: ... :] + parsers: fparser [ [: ... :] -> ... | ... ] +- [25 May 01] Added function Token.lexer_func_of a little bit more general + than Token.lexer_func_of_parser. + +Camlp4 Version 3.01.4: +---------------------- + +- [20 May 01] Fixed bug: pr_rp and pr_op could generate bound variables + resulting incorrect program: + (e.g. fun s -> parser [: `_; x :] -> s x was printed: + fun s -> parser [: `_; s :] -> s s) +- [19 May 01] Small improvement in pretty.ml resulting a faster print (no + more stacked HOVboxes which printers pr_r and pr_o usually generate in + expr, patt, ctyp, etc.) +- [18 May 01] Added [lexer_func_of_parser] and [lexer_func_of_ocamllex] + in module [Token] to create lexers functions from char stream parsers + or from [ocamllex] lexers. +- [16 May 01] Pretty printing with pr_r.cmo (revised syntax) now keep + comments inside phrases. +- [15 May 01] Changed pretty printing system, using now new extensible + functions of Camlp4. +- [15 May 01] Added library module Extfun for extensible functions, + syntax pa_extfun, and a printer pr_extfun. +- [12 May 01] Fixed bug: missing cases in pr_o and pr_r for in cases of + "for", "while", and some other expressions, when between parentheses. + +Camlp4 Version 3.01.3: +---------------------- + +- [04 May 01] Put back the syntax "do ... return ..." in predefined + quotation "expr", to be able to compile previous programs. Work + only if the quotation is in position of expression, not in pattern. +- [04 May 01] Added lisp syntax pa_lisp.cmo (not terminated). +- [01 May 01] Fixed bug: in toplevel, in case of syntax error in #use, + the display was incorrect: it displayed the input, instead of the + file location. + +Camlp4 Version 3.01.2: +---------------------- + +- [27 Apr 01] Added variable Grammar.error_verbose and option -verbose of + command camlp4 to display more information in case of parsing error. +- [27 Apr 01] Fixed bug: the locations in sequences was not what expected + by OCaml, resulting on bad locations displaying in case of typing error. +- [27 Apr 01] Fixed bug: in normal syntax, the sequence was parsed + of left associative instead of right associative, resulting bad pretty + printing. + +Camlp4 Version 3.01.1: +---------------------- + +- [19 Apr 01] Added missing new feature "include" (structure item). +- [17 Apr 01] Changed revised syntax of sequences. Now: + do { expr1; expr2 ..... ; exprn } + for patt = expr to/downto expr do { expr1; expr2 ..... ; exprn } + while expr do { expr1; expr2 ..... ; exprn } + * If holding a "let ... in", the scope applies up to the end of the sequence. + * The old syntax "do .... return ..." is still accepted. + * In expr quotation, it is *not* accepted. To ensure backward + compatibility, use ifdef NEWSEQ, which answers True from this version. + * The printer pr_r.cmo by default prints with this new syntax. + * To print with old syntax, use option -old_seq. + * To get a warning when using old syntax, use option -warn_seq. + +Camlp4 Version 3.01: +-------------------- + +- [5 Mar 01] In pa_o.ml fixed problem, did not parse: + class ['a, 'b] cl a b : ['a, 'b] classtype +- [9 Oct 00] Raise now Stream.Error when parsing with an empty entry (meaning + that the user probably forgot to initialize it). +- [21 Jul 00] Fixed (pr_o.cmo) pb of bad printing of + let (f : unit -> int) = fun () -> 1 +- [10 Jun, 21 Jul 00] Added Pcaml.sync to synchronize after syntax error in + toplevel. +- [24 May 00] Changed the "make opt", returning to what was done in the + previous releases, i.e. just the compilation of the library (6 files). + The native code compilation of "camlp4o" and "camlp4r" are not absolutely + necessary and can create problems in some systems because of too long code. + The drawbacks are more important than the advantages. +- [19 May 00] Changed option -split_gext (when pa_extend.cmo is loaded) into + -split_ext: it applies now also for non functorial grammars (extended by + EXTEND instead of GEXTEND). +- [12 May 00] Fixed problem in pr_rp.cmo and pr_op.cmo: the pretty printing + of the construction "match x with parser" did not work (because of the + type constraint "Stream.t _" added some versions ago). + +Camlp4 Version 3.00: +-------------------- + +- [Apr 19, 00] Added "pa_olabl" for labels with old Olabl syntax. +- [Apr 18, 00] Make opt now builds camlp4o.opt and camlp4r.opt +- [Apr 17, 00] Added support for labels and variants. +- [Mar 28, 00] Improved the grammars: now the rules starting with n + terminals are locally LL(n), i.e. if any of the terminal fails, it is + not Error but just Failure. Allows to write the Ocaml syntax case: + ( operator ) + ( expr ) + with the problem of "( - )" as: + "("; "-"; ")" + "("; operator; ")" + "("; expr; ")" + after factorization of the "(", the rule "-"; ")" is locally LL(2): it + works for this reason. In the previous implementation, a hack had to be + added for this case. + + To allow this, the interface of "Token" changed. The field "tparse" is + now of type "pattern -> option (Stream.t t -> string)" instead of + "pattern -> Stream.t t -> string". Set it to "None" for standard pattern + parsing (or if you don't know). + +Camlp4 Version 2.04: +-------------------- + +- [Nov 23, 99] Changed the module name Config into Oconfig, because of + conflict problem when applications want to link with the module Config of + Ocaml. + +Camlp4 Version 2.03: +-------------------- + +* pr_depend: + - [Jun 25, 99] Added missing case in "pr_depend.cmo": pattern A.B.C. + - [Jun 5, 99] Fixed in "pr_depend.ml" case expression "Foo.Bar" displaying a + bad dependency with file "bar.ml" if existed. And changed "pa_r.ml" + (revised syntax parsing) to generate a more logical ast for case + "var.Mod.lab". + - [Apr 29, 99] Added missing cases in "pr_o.cmo" and in "pr_depend.cmo". + - [Mar 11, 99] Added missing cases in "pr_depend.cmo". + - [Mar 9, 99] Added missing case in pr_depend.ml. + +* Other: + - [Sep 10, 99] Updated from current Ocaml new interfaces. + - [Jul 9, 99] Added stream type constraint in pa_oop.ml to reflect the same + change in Ocaml. + - [Jun 24, 99] Added missing "constraint" construction in types + - [Jun 15, 99] Added option -I for command "mkcamlp4". + - [May 14, 99] Added man pages (links) for camlp4o, camlp4r, mkcamlp4, ocpp + - [May 10, 99] Added shell script "configure_batch" in directory "config". + - [May 10, 99] Changed LICENSE to BSD. + - [Apr 29, 99] Added "ifdef" for mli files. + - [Apr 11, 99] Changed option "-no_cp" into "-sep" in pr_r.cmo and pr_o.cmo. + - [Apr 11, 99] Fixed (old) bug: too long strings where bad pretty printed. + - [Mar 24, 99] Added missing stream type constraint for parsers. + - [Mar 17, 99] Changed template Makefile to use ocamlc.opt and ocamlopt.opt + by default, instead of ocamlc and ocamlopt. + - [Mar 9, 99] Added ifndef in pa_ifdef.ml. + - [Mar 7, 99] Completed and fixed some cases in pr_extend.ml. + +Camlp4 Version 2.02: +-------------------- + +* Parsing: + - [Feb 27, 99] Fixed 2 bugs, resulting of incorrect Ocaml parsing of the + program example: "type t = F(B).t" + - [Jan 30, 99] Fixed bug "pa_op.ml", could not parse "parser | [<>] -> ()". + - [Jan 16, 99] Added "define" and "undef" in "pa_ifdef.cmo". + - [Dec 22, 98] Fixed precedence of "!=" in Ocaml syntax + +* Printing: + - [Mar 4, 99] Added pr_depend.cmo for printing file dependencies. + - [Dec 28, 98] Fixed pretty printing of long strings starting with spaces; + used to display "\\n..." instead of "\\n...". + +* Camlp4: + - [Feb 19, 99] Sort command line argument list in reverse order to + avoid argument names conflicts when adding arguments. + +* Olabl: + - [Feb 26, 99] Started extensions for Olabl: directory "lablp4" and some + changes in MLast. Olabl programs can be preprocessed by: + camlp4 pa_labl.cma pr_ldump.cmo + +* Internal: + - Use of pr_depend.cmo instead of ocamldep for dependencies. + +Camlp4 Version 2.01: +-------------------- + +Token interface +* Big change: the type for tokens and tokens patterns is now (string * string) + the first string being the constructor name and the second its possible + parameters. No change in EXTEND statements using Plexer. But lexers + have: + - a supplementary parameter "tparse" to specify how to parse token + from token patterns. + - fields "using" and "removing" replacing "add_keyword" and + "remove_keyword". + See the file README-2.01 for how to update your programs and the interface + of Token. + +Grammar interface +* The function "keywords" have been replaced by "tokens". The equivalent + of the old statement: + Grammar.keywords g + is now: + Grammar.tokens g "" + +Missing features added +* Added "lazy" statement (pa_r.cmo, pa_o.cmo, pr_r.cmo, pr_o.cmo) +* Added print "assert" statement (pr_o.cmo, pr_r.cmo) +* Added parsing of infix operators like in Ocaml (e.g. |||) in pa_o.cmo + +Compilation +* Added "make scratch" +* Changed Makefile. No more "make T=../", working bad in some systems. +* Some changes to make compilation in Windows 95/98 working better (thanks + to Patricia Peratto). + +Classes and objects +* Added quotations for classes and objects (q_MLast.ml) +* Added accessible entries in module Pcaml (class_type, class_expr, etc.) +* Changed classes and objects types in definition (module MLast) + +Miscelleneous +* Some adds in pa_sml.cmo. Thanks to Franklin Chen. +* Added option "-no_cp" when "pr_o.cmo" or "pr_r.cmo" is loaded: do + not print comments between phrases. +* Added option "-split_gext" when "pa_extend.cmo" is loaded: split GEXTEND + by functions to turn around a PowerPC problem. + +Bug fixes +* Fixed pa_r.cmo, pa_o.cmo to parse, and pr_r.cmo, pr_o.cmo to print "(x:#M.c)" +* Fixed printing pr_o.cmo of "(a.b <- 1)::1" +* Extended options with parameters worked only when the parameter was sticked. + Ex: + camlp4o pr_o.cmo -l120 foo.ml + worked, but not: + camlp4o pr_o.cmo -l 120 foo.ml + +Camlp4 Version 2.00: +-------------------- + +* Designation "righteous" has been renamed "revised". +* Added class and objects in Ocaml printing (pr_o.cmo), revised parsing + (pa_r.cmo) and printing (pr_r.cmo). +* Fixed bug in Ocaml syntax: let _, x = 1, 2;; was refused. + +Camlp4 Version 2.00--1: +----------------------- + +* Added classes and objects in Ocaml syntax (pa_o.cmo) +* Fixed pr_r.cmo et pr_r.cmo which wrote on stdout, even when option -o + +Camlp4 Version 2.00--: +---------------------- + +* Adapted for Ocaml 2.00. +* No objects and classes in this version. + +* Added "let module" parsing and printing. +* Added arrays patterns parsing and printing. +* Added records with "with" "{... with ...}" parsing and printing + +* Added # num "string" in plexer (was missing). +* Fixed bug in pr_o.cmo: module A = B (C);; was printed module A = B C;; +* Added "pa_sml.cmo", SML syntax + "lib.sml" +* Fixed bug in pa_r.ml and pa_o.ml: forgot to clear let_binding +* Changed Plexer: unknown keywords do not raise error but return Tterm +* q_MLast.cmo: suppressed <:expr< [$list:el$] >> (cannot work) +* Added option "-no_ss" (no ;;) when "pr_o.cmo" loaded +* Many changes and bug fixing in pretty printing pr_o.cmo and pr_r.cmo +* Command ocpp works now without having to explicitely load + "/usr/local/lib/ocaml/stdlib.cma" and + "/usr/local/lib/camlp4/gramlib.cma" + +* Fixed problem of pretty print "&" and "or" in normal and righteous syntaxes +* Added missing statement "include" in signature item in normal and righteous + syntaxes +* Changed precedence of ":=" and "<-" in normal syntax (pa_o et pr_o): + now before "or", like in Ocaml compiler. +* Same change in righteous syntax, by symmetry. + +Camlp4 Version 1.07.2: +---------------------- + +Errors and missings in normal and righteous syntaxes. + +* Added forgotten syntax (righteous): type constraints in class type fields. +* Added missing syntax (normal): type foo = bar = {......} +* Added missing syntax (normal): did not accept separators before ending + constructions (many of them). +* Fixed bug: "assert false" is now of type 'a, like in Ocaml. +* Fixed to match Ocaml feature: "\^" is "\^" in Ocaml, but just "^" in Camlp4. +* Fixed bug in Windows NT/95: problem in backslash before newlines in strings + +Grammars, EXTEND, DELETE_RULE + +* Added functorial version for grammars (started in version 1.07.1, + completed in this version). +* Added statements GEXTEND and GDELETE_RULE in pa_extend.cmo for functorial + version. +* EXTEND statement is added AFTER "top" instead of LEVEL "top" (because + of problems parsing "a; EXTEND...") +* Added ability to have expressions (in antiquotation form) of type string in + EXTEND after keywords "LIDENT", "UIDENT", "IDENT", "ANTIQUOT", "INT" as + in others constructions inside EXTEND. +* A grammar rule hidden by another is not deleted but just masked. DELETE_RULE + will restore the old version. +* DELETE_RULE now raises Not_found if no rule matched. +* Fixed bug: DELETE_RULE did not work when deleting a rule which is a prefix of + another rule. +* Some functions for "system use" in [Grammar] become "official": + [Entry.obj], [extend], [delete_rule]. + +Command line, man page + +* Added option -o: output on file instead of standard output, necessary + to allow compilation in Windows NT/95 (in fact, this option exists since + 1.07.1 but forgotten in its "changes" list). +* Command line option -help more complete. +* Updated man page: camlp4 options are better explained. +* Fixed bug: "camlp4 [other-options] foo.ml" worked but not + "camlp4 foo.ml [other-options]". +* Fixed bug: "camlp4 foo" did not display a understandable error message. + +Camlp4's compilation + +* Changes in compilation process in order to try to make it work better for + Windows NT under Cygnus. + +Miscellaneous + +* Added [Pcaml.add_option] for adding command line options. + +Camlp4 Version 1.07.1: +---------------------- + +* Added forgotten syntax in pr_o: type x = y = A | B +* Fixed bug negative floats parsing in pa_o => error while pretty printing +* Added assert statement and option -noassert. +* Environment variable CAMLP4LIB to change camlp4 library directory +* Grammar: empty rules have a correct location instead of (-1, -1) +* Compilation possible in Windows NT/95 +* String constants no more shared while parsing Ocaml +* Fixed bug in antiquotations in q_MLast.cmo (bad errors locations) +* Fixed bug in antiquotations in q_MLast.cmo (EOI not checked) +* Fixed bug in Plexer: could not create keywords with iso 8859 characters + +Camlp4 Version 1.07: +-------------------- + +* Changed version number + configuration script +* Added iso 8859 uppercase characters for uidents in plexer.ml +* Fixed bug factorization IDENT in grammars +* Fixed bug pr_o.cmo was printing "declare" +* Fixed bug constructor arity in Ocaml syntax (pa_o.cmo). +* Changed "lazy" into "slazy". +* Completed pa_ifdef.cmo. + +Camlp4 Version 1.06: +-------------------- + +* Adapted to Ocaml 1.06. +* Changed version number to match Ocaml's => 1.06 too. +* Deleted module Gstream, using Ocaml's Stream. +* Generate different AST for C(x,y) and C x y (change done in Ocaml's compiler) +* No more message "Interrupted" in toplevel in case of syntax error. +* Added flag to suppress warnings while extending grammars. +* Completed some missing statements and declarations (objects) +* Modified odyl implementation; works better +* Added ability to extend command line specification +* Added "let_binding" as predefined (accessible) entry in Pcaml. +* Added construction FUNCTION in EXTEND statement to call another function. +* Added some ISO-8859-1 characters in lexer identifiers. +* Fixed bug "value x = {val = 1};" (righteous syntax) +* Fixed bug "open A.B.C" was interpreted as "open B.A.C" +* Modified behavior of "DELETE_RULE": the complete rule must be provided +* Completed quotations MLast ("expr", "patt", etc) to accept whole language +* Renamed "LIKE" into "LEVEL" in grammar EXTEND +* Added "NEXT" as grammar symbol in grammar EXTEND +* Added command "mkcamlp4" to make camlp4 executables linked with C code +* Added "pr_extend.cmo" to reconstitute EXTEND instructions + +Camlp4 Version 0.6: +------------------- + +--- Installing + +* To compile camlp4, it is no more necessary to have the sources of the + Objective Caml compiler available. It can be compiled like any other + Objective Caml program. + +--- Options of "camlp4" + +* Added option -where: "camlp4 -where" prints the name of the standard + library directory of Camlp4 and exit. So, the ocaml toplevel and the + compiler can use the option: + -I `camlp4 -where` + +* Added option -nolib to not search for objects files in the installed + library directory of Camlp4. + +--- Interface of grammar library modules + +* The function Grammar.keywords returns now a list of pairs. The pair is + composed of a keyword and the number of times it is used in entries. + +* Changed interface of Token and Grammar for lexers, so user lexers have + to be changed. + +--- New features in grammars + +* New instruction "DELETE_RULE" provided by pa_extend.cmo to delete rules. + Ex: + DELETE_RULE Pcaml.expr: "if" END; + deletes the "if" instruction of the language. + +* Added the ability to parse some specific integer in grammars: a possible + parameter to INT, like the ones for LIDENT and UIDENT. + +* In instruction EXTEND, ability to omit "-> action", default is "-> ()" + +* Ability to add antiquotation (between $'s) as symbol rule, of type string, + interpreted as a keyword, in instruction EXTEND. + +* Ability to put entries with qualified names (Foo.bar) in instruction EXTEND. + +--- Quotations + +* The module Ast has been renamed MLast. The quotation expander "q_ast.cmo" + has been renamed "q_MLast.cmo". + +* Quotation expanders are now of two kinds: + - The "classical" type for expanders returning a string. These expanders + have now a supplementary parameter: a boolean value set to "True" + when the quotation is in a context of an expression an to "False" + when the quotation is in a context of a pattern. These expanders, + returning strings which are parsed afterwards, may work for some + language syntax and/or language extensions used (e.g. may work for + Righteous syntax and not for Ocaml syntax). + - A new type of expander returning directly syntax trees. A pair + of functions, for expressions and for patterns must be provided. + These expanders are independant from the language syntax and/or + extensions used. + +* The predefined quotation expanders "ctyp_", "patt_" and "expr_" has + been deleted; one can use "ctyp", "patt", and "expr" in position of + pattern or expression. + +--- Ocaml and Righteous syntaxes + +* Fixed bug: "open Foo.Bar" was converted (pr_dump.cmo) into "open Bar.Foo" + +* Corrected behavior different from Ocaml's: "^" and "@" were at the same + level than "=": now, like Ocaml, they have a separated right associative + level. + +--- Grammars behavior + +* While extending entries: default position is now "extension of the + first level", instead of "adding a new level at the end". + +* Another Change: in each precedence level, terminals are inserted before + other symbols (non terminals, lists, options, etc), LIDENT "foo" before + LIDENT (alone) and UIDENT "foo" before UIDENT (alone). New rules not + factorizable are now inserted before the other rules. + +* Changed algorithm of entries parsing: each precedence level is tested + against the stream *before* its next precedences levels (instead of + *after*): + EXTEND e: [[ LIDENT "a" -> "xxx" ] | [ i = LIDENT -> i ]]; END; + Now, parsing the entry e with the string "a" returns "xxx" instead of "a" + +* Less keywords in instruction EXTEND (LEFTA, LIDENT, etc), which can be + used now as normal identifiers. + +* When inserting a new rule, a warning appears if a rule with the + same production already existed (it is deleted). + +* Parse error messages (Gstream.Error) are formatted => spaces trigger + Format.print_space and newlines trigger Format.force_newline. + + +Camlp4 Version 0.5: +------------------- + +* Possible creation of native code library (make opt) + +* Ocaml and Righteous Syntax more complete + +* Added pa_ru.cmo for compiling sequences of type unit (Righteous) + +* Quotations AST + - No more quotation long_id + - Antiquotations for identifiers more simple + +* Lot of small changes + + +Camlp4 Version 0.4: +------------------- + +* First distributed version diff --git a/camlp4/Camlp4.mlpack b/camlp4/Camlp4.mlpack new file mode 100644 index 0000000..cc38b11 --- /dev/null +++ b/camlp4/Camlp4.mlpack @@ -0,0 +1,9 @@ +Debug +ErrorHandler +OCamlInitSyntax +Options +PreCast +Printers +Register +Sig +Struct diff --git a/camlp4/Camlp4/.cvsignore b/camlp4/Camlp4/.cvsignore new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/Camlp4/Camlp4Ast.partial.ml b/camlp4/Camlp4/Camlp4Ast.partial.ml new file mode 100644 index 0000000..ba941d7 --- /dev/null +++ b/camlp4/Camlp4/Camlp4Ast.partial.ml @@ -0,0 +1,346 @@ + type loc = Loc.t + and meta_bool = + [ BTrue + | BFalse + | BAnt of string ] + and meta_option 'a = + [ ONone + | OSome of 'a + | OAnt of string ] + and meta_list 'a = + [ LNil + | LCons of 'a and meta_list 'a + | LAnt of string ] + and ident = + [ IdAcc of loc and ident and ident (* i . i *) + | IdApp of loc and ident and ident (* i i *) + | IdLid of loc and string (* foo *) + | IdUid of loc and string (* Bar *) + | IdAnt of loc and string (* $s$ *) ] + and ctyp = + [ TyNil of loc + | TyAli of loc and ctyp and ctyp (* t as t *) (* list 'a as 'a *) + | TyAny of loc (* _ *) + | TyApp of loc and ctyp and ctyp (* t t *) (* list 'a *) + | TyArr of loc and ctyp and ctyp (* t -> t *) (* int -> string *) + | TyCls of loc and ident (* #i *) (* #point *) + | TyLab of loc and string and ctyp (* ~s:t *) + | TyId of loc and ident (* i *) (* Lazy.t *) + | TyMan of loc and ctyp and ctyp (* t == t *) (* type t = [ A | B ] == Foo.t *) + (* type t 'a 'b 'c = t constraint t = t constraint t = t *) + | TyDcl of loc and string and list ctyp and ctyp and list (ctyp * ctyp) + (* < (t)? (..)? > *) (* < move : int -> 'a .. > as 'a *) + | TyObj of loc and ctyp and meta_bool + | TyOlb of loc and string and ctyp (* ?s:t *) + | TyPol of loc and ctyp and ctyp (* ! t . t *) (* ! 'a . list 'a -> 'a *) + | TyQuo of loc and string (* 's *) + | TyQuP of loc and string (* +'s *) + | TyQuM of loc and string (* -'s *) + | TyVrn of loc and string (* `s *) + | TyRec of loc and ctyp (* { t } *) (* { foo : int ; bar : mutable string } *) + | TyCol of loc and ctyp and ctyp (* t : t *) + | TySem of loc and ctyp and ctyp (* t; t *) + | TyCom of loc and ctyp and ctyp (* t, t *) + | TySum of loc and ctyp (* [ t ] *) (* [ A of int and string | B ] *) + | TyOf of loc and ctyp and ctyp (* t of t *) (* A of int *) + | TyAnd of loc and ctyp and ctyp (* t and t *) + | TyOr of loc and ctyp and ctyp (* t | t *) + | TyPrv of loc and ctyp (* private t *) + | TyMut of loc and ctyp (* mutable t *) + | TyTup of loc and ctyp (* ( t ) *) (* (int * string) *) + | TySta of loc and ctyp and ctyp (* t * t *) + | TyVrnEq of loc and ctyp (* [ = t ] *) + | TyVrnSup of loc and ctyp (* [ > t ] *) + | TyVrnInf of loc and ctyp (* [ < t ] *) + | TyVrnInfSup of loc and ctyp and ctyp (* [ < t > t ] *) + | TyAmp of loc and ctyp and ctyp (* t & t *) + | TyOfAmp of loc and ctyp and ctyp (* t of & t *) + | TyAnt of loc and string (* $s$ *) + ] + and patt = + [ PaNil of loc + | PaId of loc and ident (* i *) + | PaAli of loc and patt and patt (* p as p *) (* (Node x y as n) *) + | PaAnt of loc and string (* $s$ *) + | PaAny of loc (* _ *) + | PaApp of loc and patt and patt (* p p *) (* fun x y -> *) + | PaArr of loc and patt (* [| p |] *) + | PaCom of loc and patt and patt (* p, p *) + | PaSem of loc and patt and patt (* p; p *) + | PaChr of loc and string (* c *) (* 'x' *) + | PaInt of loc and string + | PaInt32 of loc and string + | PaInt64 of loc and string + | PaNativeInt of loc and string + | PaFlo of loc and string + | PaLab of loc and string and patt (* ~s or ~s:(p) *) + (* ?s or ?s:(p) *) + | PaOlb of loc and string and patt + (* ?s:(p = e) or ?(p = e) *) + | PaOlbi of loc and string and patt and expr + | PaOrp of loc and patt and patt (* p | p *) + | PaRng of loc and patt and patt (* p .. p *) + | PaRec of loc and patt (* { p } *) + | PaEq of loc and ident and patt (* i = p *) + | PaStr of loc and string (* s *) + | PaTup of loc and patt (* ( p ) *) + | PaTyc of loc and patt and ctyp (* (p : t) *) + | PaTyp of loc and ident (* #i *) + | PaVrn of loc and string (* `s *) + | PaLaz of loc and patt (* lazy p *) ] + and expr = + [ ExNil of loc + | ExId of loc and ident (* i *) + | ExAcc of loc and expr and expr (* e.e *) + | ExAnt of loc and string (* $s$ *) + | ExApp of loc and expr and expr (* e e *) + | ExAre of loc and expr and expr (* e.(e) *) + | ExArr of loc and expr (* [| e |] *) + | ExSem of loc and expr and expr (* e; e *) + | ExAsf of loc (* assert False *) + | ExAsr of loc and expr (* assert e *) + | ExAss of loc and expr and expr (* e := e *) + | ExChr of loc and string (* 'c' *) + | ExCoe of loc and expr and ctyp and ctyp (* (e : t) or (e : t :> t) *) + | ExFlo of loc and string (* 3.14 *) + (* for s = e to/downto e do { e } *) + | ExFor of loc and string and expr and expr and meta_bool and expr + | ExFun of loc and match_case (* fun [ mc ] *) + | ExIfe of loc and expr and expr and expr (* if e then e else e *) + | ExInt of loc and string (* 42 *) + | ExInt32 of loc and string + | ExInt64 of loc and string + | ExNativeInt of loc and string + | ExLab of loc and string and expr (* ~s or ~s:e *) + | ExLaz of loc and expr (* lazy e *) + (* let b in e or let rec b in e *) + | ExLet of loc and meta_bool and binding and expr + (* let module s = me in e *) + | ExLmd of loc and string and module_expr and expr + (* match e with [ mc ] *) + | ExMat of loc and expr and match_case + (* new i *) + | ExNew of loc and ident + (* object ((p))? (cst)? end *) + | ExObj of loc and patt and class_str_item + (* ?s or ?s:e *) + | ExOlb of loc and string and expr + (* {< rb >} *) + | ExOvr of loc and rec_binding + (* { rb } or { (e) with rb } *) + | ExRec of loc and rec_binding and expr + (* do { e } *) + | ExSeq of loc and expr + (* e#s *) + | ExSnd of loc and expr and string + (* e.[e] *) + | ExSte of loc and expr and expr + (* s *) (* "foo" *) + | ExStr of loc and string + (* try e with [ mc ] *) + | ExTry of loc and expr and match_case + (* (e) *) + | ExTup of loc and expr + (* e, e *) + | ExCom of loc and expr and expr + (* (e : t) *) + | ExTyc of loc and expr and ctyp + (* `s *) + | ExVrn of loc and string + (* while e do { e } *) + | ExWhi of loc and expr and expr ] + and module_type = + [ MtNil of loc + (* i *) (* A.B.C *) + | MtId of loc and ident + (* functor (s : mt) -> mt *) + | MtFun of loc and string and module_type and module_type + (* 's *) + | MtQuo of loc and string + (* sig sg end *) + | MtSig of loc and sig_item + (* mt with wc *) + | MtWit of loc and module_type and with_constr + | MtAnt of loc and string (* $s$ *) ] + and sig_item = + [ SgNil of loc + (* class cict *) + | SgCls of loc and class_type + (* class type cict *) + | SgClt of loc and class_type + (* sg ; sg *) + | SgSem of loc and sig_item and sig_item + (* # s or # s e *) + | SgDir of loc and string and expr + (* exception t *) + | SgExc of loc and ctyp + (* external s : t = s ... s *) + | SgExt of loc and string and ctyp and meta_list string + (* include mt *) + | SgInc of loc and module_type + (* module s : mt *) + | SgMod of loc and string and module_type + (* module rec mb *) + | SgRecMod of loc and module_binding + (* module type s = mt *) + | SgMty of loc and string and module_type + (* open i *) + | SgOpn of loc and ident + (* type t *) + | SgTyp of loc and ctyp + (* value s : t *) + | SgVal of loc and string and ctyp + | SgAnt of loc and string (* $s$ *) ] + and with_constr = + [ WcNil of loc + (* type t = t *) + | WcTyp of loc and ctyp and ctyp + (* module i = i *) + | WcMod of loc and ident and ident + (* wc and wc *) + | WcAnd of loc and with_constr and with_constr + | WcAnt of loc and string (* $s$ *) ] + and binding = + [ BiNil of loc + (* bi and bi *) (* let a = 42 and c = 43 *) + | BiAnd of loc and binding and binding + (* p = e *) (* let patt = expr *) + | BiEq of loc and patt and expr + | BiAnt of loc and string (* $s$ *) ] + and rec_binding = + [ RbNil of loc + (* rb ; rb *) + | RbSem of loc and rec_binding and rec_binding + (* i = e *) + | RbEq of loc and ident and expr + | RbAnt of loc and string (* $s$ *) ] + and module_binding = + [ MbNil of loc + (* mb and mb *) (* module rec (s : mt) = me and (s : mt) = me *) + | MbAnd of loc and module_binding and module_binding + (* s : mt = me *) + | MbColEq of loc and string and module_type and module_expr + (* s : mt *) + | MbCol of loc and string and module_type + | MbAnt of loc and string (* $s$ *) ] + and match_case = + [ McNil of loc + (* a | a *) + | McOr of loc and match_case and match_case + (* p (when e)? -> e *) + | McArr of loc and patt and expr and expr + | McAnt of loc and string (* $s$ *) ] + and module_expr = + [ MeNil of loc + (* i *) + | MeId of loc and ident + (* me me *) + | MeApp of loc and module_expr and module_expr + (* functor (s : mt) -> me *) + | MeFun of loc and string and module_type and module_expr + (* struct st end *) + | MeStr of loc and str_item + (* (me : mt) *) + | MeTyc of loc and module_expr and module_type + | MeAnt of loc and string (* $s$ *) ] + and str_item = + [ StNil of loc + (* class cice *) + | StCls of loc and class_expr + (* class type cict *) + | StClt of loc and class_type + (* st ; st *) + | StSem of loc and str_item and str_item + (* # s or # s e *) + | StDir of loc and string and expr + (* exception t or exception t = i *) + | StExc of loc and ctyp and meta_option(*FIXME*) ident + (* e *) + | StExp of loc and expr + (* external s : t = s ... s *) + | StExt of loc and string and ctyp and meta_list string + (* include me *) + | StInc of loc and module_expr + (* module s = me *) + | StMod of loc and string and module_expr + (* module rec mb *) + | StRecMod of loc and module_binding + (* module type s = mt *) + | StMty of loc and string and module_type + (* open i *) + | StOpn of loc and ident + (* type t *) + | StTyp of loc and ctyp + (* value (rec)? bi *) + | StVal of loc and meta_bool and binding + | StAnt of loc and string (* $s$ *) ] + and class_type = + [ CtNil of loc + (* (virtual)? i ([ t ])? *) + | CtCon of loc and meta_bool and ident and ctyp + (* [t] -> ct *) + | CtFun of loc and ctyp and class_type + (* object ((t))? (csg)? end *) + | CtSig of loc and ctyp and class_sig_item + (* ct and ct *) + | CtAnd of loc and class_type and class_type + (* ct : ct *) + | CtCol of loc and class_type and class_type + (* ct = ct *) + | CtEq of loc and class_type and class_type + (* $s$ *) + | CtAnt of loc and string ] + and class_sig_item = + [ CgNil of loc + (* type t = t *) + | CgCtr of loc and ctyp and ctyp + (* csg ; csg *) + | CgSem of loc and class_sig_item and class_sig_item + (* inherit ct *) + | CgInh of loc and class_type + (* method s : t or method private s : t *) + | CgMth of loc and string and meta_bool and ctyp + (* value (virtual)? (mutable)? s : t *) + | CgVal of loc and string and meta_bool and meta_bool and ctyp + (* method virtual (mutable)? s : t *) + | CgVir of loc and string and meta_bool and ctyp + | CgAnt of loc and string (* $s$ *) ] + and class_expr = + [ CeNil of loc + (* ce e *) + | CeApp of loc and class_expr and expr + (* (virtual)? i ([ t ])? *) + | CeCon of loc and meta_bool and ident and ctyp + (* fun p -> ce *) + | CeFun of loc and patt and class_expr + (* let (rec)? bi in ce *) + | CeLet of loc and meta_bool and binding and class_expr + (* object ((p))? (cst)? end *) + | CeStr of loc and patt and class_str_item + (* ce : ct *) + | CeTyc of loc and class_expr and class_type + (* ce and ce *) + | CeAnd of loc and class_expr and class_expr + (* ce = ce *) + | CeEq of loc and class_expr and class_expr + (* $s$ *) + | CeAnt of loc and string ] + and class_str_item = + [ CrNil of loc + (* cst ; cst *) + | CrSem of loc and class_str_item and class_str_item + (* type t = t *) + | CrCtr of loc and ctyp and ctyp + (* inherit ce or inherit ce as s *) + | CrInh of loc and class_expr and string + (* initializer e *) + | CrIni of loc and expr + (* method (private)? s : t = e or method (private)? s = e *) + | CrMth of loc and string and meta_bool and expr and ctyp + (* value (mutable)? s = e *) + | CrVal of loc and string and meta_bool and expr + (* method virtual (private)? s : t *) + | CrVir of loc and string and meta_bool and ctyp + (* value virtual (private)? s : t *) + | CrVvr of loc and string and meta_bool and ctyp + | CrAnt of loc and string (* $s$ *) ]; diff --git a/camlp4/Camlp4/Debug.ml b/camlp4/Camlp4/Debug.ml new file mode 100644 index 0000000..e99ec9e --- /dev/null +++ b/camlp4/Camlp4/Debug.ml @@ -0,0 +1,73 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +(* camlp4r *) +open Format; + +module Debug = struct value mode _ = False; end; + +type section = string; + +value out_channel = + try + let f = Sys.getenv "CAMLP4_DEBUG_FILE" in + open_out_gen [Open_wronly; Open_creat; Open_append; Open_text] + 0o666 f + with + [ Not_found -> stderr ]; + +module StringSet = Set.Make String; + +value mode = + try + let str = Sys.getenv "CAMLP4_DEBUG" in + let rec loop acc i = + try + let pos = String.index_from str i ':' in + loop (StringSet.add (String.sub str i (pos - i)) acc) (pos + 1) + with + [ Not_found -> + StringSet.add (String.sub str i (String.length str - i)) acc ] in + let sections = loop StringSet.empty 0 in + if StringSet.mem "*" sections then fun _ -> True + else fun x -> StringSet.mem x sections + with [ Not_found -> fun _ -> False ]; + +value formatter = + let header = "camlp4-debug: " in + let normal s = + let rec self from accu = + try + let i = String.index_from s from '\n' + in self (i + 1) [String.sub s from (i - from + 1) :: accu] + with + [ Not_found -> [ String.sub s from (String.length s - from) :: accu ] ] + in String.concat header (List.rev (self 0 [])) in + let after_new_line str = header ^ normal str in + let f = ref after_new_line in + let output str chr = do { + output_string out_channel (f.val str); + output_char out_channel chr; + f.val := if chr = '\n' then after_new_line else normal; + } in + (make_formatter + (fun buf pos len -> + let p = pred len in output (String.sub buf pos p) buf.[pos + p]) + (fun () -> flush out_channel)); + +value printf section fmt = fprintf formatter ("%s: " ^^ fmt) section; diff --git a/camlp4/Camlp4/Debug.mli b/camlp4/Camlp4/Debug.mli new file mode 100644 index 0000000..13af773 --- /dev/null +++ b/camlp4/Camlp4/Debug.mli @@ -0,0 +1,22 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +(* camlp4r *) +type section = string; +value mode : section -> bool; +value printf : section -> format 'a Format.formatter unit -> 'a; diff --git a/camlp4/Camlp4/ErrorHandler.ml b/camlp4/Camlp4/ErrorHandler.ml new file mode 100644 index 0000000..231efed --- /dev/null +++ b/camlp4/Camlp4/ErrorHandler.ml @@ -0,0 +1,171 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +(* camlp4r *) + +open Format; + +module ObjTools = struct + + value desc obj = + if Obj.is_block obj then + "tag = " ^ string_of_int (Obj.tag obj) + else "int_val = " ^ string_of_int (Obj.obj obj); + + (*Imported from the extlib*) + value rec to_string r = + if Obj.is_int r then + let i = (Obj.magic r : int) + in string_of_int i ^ " | CstTag" ^ string_of_int (i + 1) + else (* Block. *) + let rec get_fields acc = + fun + [ 0 -> acc + | n -> let n = n-1 in get_fields [Obj.field r n :: acc] n ] + in + let rec is_list r = + if Obj.is_int r then + r = Obj.repr 0 (* [] *) + else + let s = Obj.size r and t = Obj.tag r in + t = 0 && s = 2 && is_list (Obj.field r 1) (* h :: t *) + in + let rec get_list r = + if Obj.is_int r then [] + else let h = Obj.field r 0 and t = get_list (Obj.field r 1) in [h :: t] + in + let opaque name = + (* XXX In future, print the address of value 'r'. Not possible in + * pure OCaml at the moment. + *) + "<" ^ name ^ ">" + in + let s = Obj.size r and t = Obj.tag r in + (* From the tag, determine the type of block. *) + match t with + [ _ when is_list r -> + let fields = get_list r in + "[" ^ String.concat "; " (List.map to_string fields) ^ "]" + | 0 -> + let fields = get_fields [] s in + "(" ^ String.concat ", " (List.map to_string fields) ^ ")" + | x when x = Obj.lazy_tag -> + (* Note that [lazy_tag .. forward_tag] are < no_scan_tag. Not + * clear if very large constructed values could have the same + * tag. XXX *) + opaque "lazy" + | x when x = Obj.closure_tag -> + opaque "closure" + | x when x = Obj.object_tag -> + let fields = get_fields [] s in + let (_class, id, slots) = + match fields with + [ [h; h'::t] -> (h, h', t) + | _ -> assert False ] + in + (* No information on decoding the class (first field). So just print + * out the ID and the slots. *) + "Object #" ^ to_string id ^ " (" ^ String.concat ", " (List.map to_string slots) ^ ")" + | x when x = Obj.infix_tag -> + opaque "infix" + | x when x = Obj.forward_tag -> + opaque "forward" + | x when x < Obj.no_scan_tag -> + let fields = get_fields [] s in + "Tag" ^ string_of_int t ^ + " (" ^ String.concat ", " (List.map to_string fields) ^ ")" + | x when x = Obj.string_tag -> + "\"" ^ String.escaped (Obj.magic r : string) ^ "\"" + | x when x = Obj.double_tag -> + string_of_float (Obj.magic r : float) + | x when x = Obj.abstract_tag -> + opaque "abstract" + | x when x = Obj.custom_tag -> + opaque "custom" + | x when x = Obj.final_tag -> + opaque "final" + | _ -> + failwith ("ObjTools.to_string: unknown tag (" ^ string_of_int t ^ ")") ]; + + value print ppf x = fprintf ppf "%s" (to_string x); + value print_desc ppf x = fprintf ppf "%s" (desc x); + +end; + +value default_handler ppf x = do { + let x = Obj.repr x; + fprintf ppf "Camlp4: Uncaught exception: %s" + (Obj.obj (Obj.field (Obj.field x 0) 0) : string); + if Obj.size x > 1 then do { + pp_print_string ppf " ("; + for i = 1 to Obj.size x - 1 do + if i > 1 then pp_print_string ppf ", " else (); + ObjTools.print ppf (Obj.field x i); + done; + pp_print_char ppf ')' + } + else (); + fprintf ppf "@." +}; + +value handler = ref (fun ppf default_handler exn -> default_handler ppf exn); + +value register f = + let current_handler = handler.val in + handler.val := + fun ppf default_handler exn -> + try f ppf exn with exn -> current_handler ppf default_handler exn; + +module Register (Error : Sig.Error) = struct + let current_handler = handler.val in + handler.val := + fun ppf default_handler -> + fun [ Error.E x -> Error.print ppf x + | x -> current_handler ppf default_handler x ]; +end; + + +value gen_print ppf default_handler = + fun + [ Out_of_memory -> fprintf ppf "Out of memory" + | Assert_failure (file, line, char) -> + fprintf ppf "Assertion failed, file %S, line %d, char %d" + file line char + | Match_failure (file, line, char) -> + fprintf ppf "Pattern matching failed, file %S, line %d, char %d" + file line char + | Failure str -> fprintf ppf "Failure: %S" str + | Invalid_argument str -> fprintf ppf "Invalid argument: %S" str + | Sys_error str -> fprintf ppf "I/O error: %S" str + | Stream.Failure -> fprintf ppf "Parse failure" + | Stream.Error str -> fprintf ppf "Parse error: %s" str + | x -> handler.val ppf default_handler x ]; + +value print ppf = gen_print ppf default_handler; + +value try_print ppf = gen_print ppf (fun _ -> raise); + +value to_string exn = + let buf = Buffer.create 128 in + let () = bprintf buf "%a" print exn in + Buffer.contents buf; + +value try_to_string exn = + let buf = Buffer.create 128 in + let () = bprintf buf "%a" try_print exn in + Buffer.contents buf; diff --git a/camlp4/Camlp4/ErrorHandler.mli b/camlp4/Camlp4/ErrorHandler.mli new file mode 100644 index 0000000..6748114 --- /dev/null +++ b/camlp4/Camlp4/ErrorHandler.mli @@ -0,0 +1,36 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) +value print : Format.formatter -> exn -> unit; + +value try_print : Format.formatter -> exn -> unit; + +value to_string : exn -> string; + +value try_to_string : exn -> string; + +value register : (Format.formatter -> exn -> unit) -> unit; + +module Register (Error : Sig.Error) : sig end; + +module ObjTools : sig + value print : Format.formatter -> Obj.t -> unit; + value print_desc : Format.formatter -> Obj.t -> unit; + (*Imported from the extlib*) + value to_string : Obj.t -> string; + value desc : Obj.t -> string; +end; diff --git a/camlp4/Camlp4/OCamlInitSyntax.ml b/camlp4/Camlp4/OCamlInitSyntax.ml new file mode 100644 index 0000000..8a70d71 --- /dev/null +++ b/camlp4/Camlp4/OCamlInitSyntax.ml @@ -0,0 +1,256 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Camlp4Ast) + (Gram : Sig.Grammar.Static with module Loc = Ast.Loc + with type Token.t = Sig.camlp4_token) + (Quotation : Sig.Quotation with module Ast = Sig.Camlp4AstToAst Ast) +: Sig.Camlp4Syntax with module Loc = Ast.Loc + and module Ast = Ast + and module Token = Gram.Token + and module Gram = Gram + and module Quotation = Quotation += struct + + module Loc = Ast.Loc; + module Ast = Ast; + module Gram = Gram; + module Token = Gram.Token; + open Sig; + + (* Warnings *) + type warning = Loc.t -> string -> unit; + value default_warning loc txt = Format.eprintf " %a: %s@." Loc.print loc txt; + value current_warning = ref default_warning; + value print_warning loc txt = current_warning.val loc txt; + + value a_CHAR = Gram.Entry.mk "a_CHAR"; + value a_FLOAT = Gram.Entry.mk "a_FLOAT"; + value a_INT = Gram.Entry.mk "a_INT"; + value a_INT32 = Gram.Entry.mk "a_INT32"; + value a_INT64 = Gram.Entry.mk "a_INT64"; + value a_LABEL = Gram.Entry.mk "a_LABEL"; + value a_LIDENT = Gram.Entry.mk "a_LIDENT"; + value a_NATIVEINT = Gram.Entry.mk "a_NATIVEINT"; + value a_OPTLABEL = Gram.Entry.mk "a_OPTLABEL"; + value a_STRING = Gram.Entry.mk "a_STRING"; + value a_UIDENT = Gram.Entry.mk "a_UIDENT"; + value a_ident = Gram.Entry.mk "a_ident"; + value amp_ctyp = Gram.Entry.mk "amp_ctyp"; + value and_ctyp = Gram.Entry.mk "and_ctyp"; + value match_case = Gram.Entry.mk "match_case"; + value match_case0 = Gram.Entry.mk "match_case0"; + value binding = Gram.Entry.mk "binding"; + value class_declaration = Gram.Entry.mk "class_declaration"; + value class_description = Gram.Entry.mk "class_description"; + value class_expr = Gram.Entry.mk "class_expr"; + value class_fun_binding = Gram.Entry.mk "class_fun_binding"; + value class_fun_def = Gram.Entry.mk "class_fun_def"; + value class_info_for_class_expr = Gram.Entry.mk "class_info_for_class_expr"; + value class_info_for_class_type = Gram.Entry.mk "class_info_for_class_type"; + value class_longident = Gram.Entry.mk "class_longident"; + value class_longident_and_param = Gram.Entry.mk "class_longident_and_param"; + value class_name_and_param = Gram.Entry.mk "class_name_and_param"; + value class_sig_item = Gram.Entry.mk "class_sig_item"; + value class_signature = Gram.Entry.mk "class_signature"; + value class_str_item = Gram.Entry.mk "class_str_item"; + value class_structure = Gram.Entry.mk "class_structure"; + value class_type = Gram.Entry.mk "class_type"; + value class_type_declaration = Gram.Entry.mk "class_type_declaration"; + value class_type_longident = Gram.Entry.mk "class_type_longident"; + value class_type_longident_and_param = Gram.Entry.mk "class_type_longident_and_param"; + value class_type_plus = Gram.Entry.mk "class_type_plus"; + value comma_ctyp = Gram.Entry.mk "comma_ctyp"; + value comma_expr = Gram.Entry.mk "comma_expr"; + value comma_ipatt = Gram.Entry.mk "comma_ipatt"; + value comma_patt = Gram.Entry.mk "comma_patt"; + value comma_type_parameter = Gram.Entry.mk "comma_type_parameter"; + value constrain = Gram.Entry.mk "constrain"; + value constructor_arg_list = Gram.Entry.mk "constructor_arg_list"; + value constructor_declaration = Gram.Entry.mk "constructor_declaration"; + value constructor_declarations = Gram.Entry.mk "constructor_declarations"; + value ctyp = Gram.Entry.mk "ctyp"; + value cvalue_binding = Gram.Entry.mk "cvalue_binding"; + value direction_flag = Gram.Entry.mk "direction_flag"; + value dummy = Gram.Entry.mk "dummy"; + value entry_eoi = Gram.Entry.mk "entry_eoi"; + value eq_expr = Gram.Entry.mk "eq_expr"; + value expr = Gram.Entry.mk "expr"; + value expr_eoi = Gram.Entry.mk "expr_eoi"; + value field_expr = Gram.Entry.mk "field_expr"; + value field_expr_list = Gram.Entry.mk "field_expr_list"; + value fun_binding = Gram.Entry.mk "fun_binding"; + value fun_def = Gram.Entry.mk "fun_def"; + value ident = Gram.Entry.mk "ident"; + value implem = Gram.Entry.mk "implem"; + value interf = Gram.Entry.mk "interf"; + value ipatt = Gram.Entry.mk "ipatt"; + value ipatt_tcon = Gram.Entry.mk "ipatt_tcon"; + value label = Gram.Entry.mk "label"; + value label_declaration = Gram.Entry.mk "label_declaration"; + value label_declaration_list = Gram.Entry.mk "label_declaration_list"; + value label_expr = Gram.Entry.mk "label_expr"; + value label_expr_list = Gram.Entry.mk "label_expr_list"; + value label_ipatt = Gram.Entry.mk "label_ipatt"; + value label_ipatt_list = Gram.Entry.mk "label_ipatt_list"; + value label_longident = Gram.Entry.mk "label_longident"; + value label_patt = Gram.Entry.mk "label_patt"; + value label_patt_list = Gram.Entry.mk "label_patt_list"; + value labeled_ipatt = Gram.Entry.mk "labeled_ipatt"; + value let_binding = Gram.Entry.mk "let_binding"; + value meth_list = Gram.Entry.mk "meth_list"; + value meth_decl = Gram.Entry.mk "meth_decl"; + value module_binding = Gram.Entry.mk "module_binding"; + value module_binding0 = Gram.Entry.mk "module_binding0"; + value module_declaration = Gram.Entry.mk "module_declaration"; + value module_expr = Gram.Entry.mk "module_expr"; + value module_longident = Gram.Entry.mk "module_longident"; + value module_longident_with_app = Gram.Entry.mk "module_longident_with_app"; + value module_rec_declaration = Gram.Entry.mk "module_rec_declaration"; + value module_type = Gram.Entry.mk "module_type"; + value more_ctyp = Gram.Entry.mk "more_ctyp"; + value name_tags = Gram.Entry.mk "name_tags"; + value opt_as_lident = Gram.Entry.mk "opt_as_lident"; + value opt_class_self_patt = Gram.Entry.mk "opt_class_self_patt"; + value opt_class_self_type = Gram.Entry.mk "opt_class_self_type"; + value opt_class_signature = Gram.Entry.mk "opt_class_signature"; + value opt_class_structure = Gram.Entry.mk "opt_class_structure"; + value opt_comma_ctyp = Gram.Entry.mk "opt_comma_ctyp"; + value opt_dot_dot = Gram.Entry.mk "opt_dot_dot"; + value opt_eq_ctyp = Gram.Entry.mk "opt_eq_ctyp"; + value opt_expr = Gram.Entry.mk "opt_expr"; + value opt_meth_list = Gram.Entry.mk "opt_meth_list"; + value opt_mutable = Gram.Entry.mk "opt_mutable"; + value opt_polyt = Gram.Entry.mk "opt_polyt"; + value opt_private = Gram.Entry.mk "opt_private"; + value opt_rec = Gram.Entry.mk "opt_rec"; + value opt_sig_items = Gram.Entry.mk "opt_sig_items"; + value opt_str_items = Gram.Entry.mk "opt_str_items"; + value opt_virtual = Gram.Entry.mk "opt_virtual"; + value opt_when_expr = Gram.Entry.mk "opt_when_expr"; + value patt = Gram.Entry.mk "patt"; + value patt_as_patt_opt = Gram.Entry.mk "patt_as_patt_opt"; + value patt_eoi = Gram.Entry.mk "patt_eoi"; + value patt_tcon = Gram.Entry.mk "patt_tcon"; + value phrase = Gram.Entry.mk "phrase"; + value poly_type = Gram.Entry.mk "poly_type"; + value row_field = Gram.Entry.mk "row_field"; + value sem_expr = Gram.Entry.mk "sem_expr"; + value sem_expr_for_list = Gram.Entry.mk "sem_expr_for_list"; + value sem_patt = Gram.Entry.mk "sem_patt"; + value sem_patt_for_list = Gram.Entry.mk "sem_patt_for_list"; + value semi = Gram.Entry.mk "semi"; + value sequence = Gram.Entry.mk "sequence"; + value do_sequence = Gram.Entry.mk "do_sequence"; + value sig_item = Gram.Entry.mk "sig_item"; + value sig_items = Gram.Entry.mk "sig_items"; + value star_ctyp = Gram.Entry.mk "star_ctyp"; + value str_item = Gram.Entry.mk "str_item"; + value str_items = Gram.Entry.mk "str_items"; + value top_phrase = Gram.Entry.mk "top_phrase"; + value type_constraint = Gram.Entry.mk "type_constraint"; + value type_declaration = Gram.Entry.mk "type_declaration"; + value type_ident_and_parameters = Gram.Entry.mk "type_ident_and_parameters"; + value type_kind = Gram.Entry.mk "type_kind"; + value type_longident = Gram.Entry.mk "type_longident"; + value type_longident_and_parameters = Gram.Entry.mk "type_longident_and_parameters"; + value type_parameter = Gram.Entry.mk "type_parameter"; + value type_parameters = Gram.Entry.mk "type_parameters"; + value typevars = Gram.Entry.mk "typevars"; + value use_file = Gram.Entry.mk "use_file"; + value val_longident = Gram.Entry.mk "val_longident"; + value value_let = Gram.Entry.mk "value_let"; + value value_val = Gram.Entry.mk "value_val"; + value with_constr = Gram.Entry.mk "with_constr"; + value expr_quot = Gram.Entry.mk "quotation of expression"; + value patt_quot = Gram.Entry.mk "quotation of pattern"; + value ctyp_quot = Gram.Entry.mk "quotation of type"; + value str_item_quot = Gram.Entry.mk "quotation of structure item"; + value sig_item_quot = Gram.Entry.mk "quotation of signature item"; + value class_str_item_quot = Gram.Entry.mk "quotation of class structure item"; + value class_sig_item_quot = Gram.Entry.mk "quotation of class signature item"; + value module_expr_quot = Gram.Entry.mk "quotation of module expression"; + value module_type_quot = Gram.Entry.mk "quotation of module type"; + value class_type_quot = Gram.Entry.mk "quotation of class type"; + value class_expr_quot = Gram.Entry.mk "quotation of class expression"; + value with_constr_quot = Gram.Entry.mk "quotation of with constraint"; + value binding_quot = Gram.Entry.mk "quotation of binding"; + value rec_binding_quot = Gram.Entry.mk "quotation of record binding"; + value match_case_quot = Gram.Entry.mk "quotation of match_case (try/match/function case)"; + value module_binding_quot = Gram.Entry.mk "quotation of module rec binding"; + value ident_quot = Gram.Entry.mk "quotation of identifier"; + value prefixop = Gram.Entry.mk "prefix operator (start with '!', '?', '~')"; + value infixop0 = Gram.Entry.mk "infix operator (level 0) (comparison operators, and some others)"; + value infixop1 = Gram.Entry.mk "infix operator (level 1) (start with '^', '@')"; + value infixop2 = Gram.Entry.mk "infix operator (level 2) (start with '+', '-')"; + value infixop3 = Gram.Entry.mk "infix operator (level 3) (start with '*', '/', '%')"; + value infixop4 = Gram.Entry.mk "infix operator (level 4) (start with \"**\") (right assoc)"; + + EXTEND Gram + top_phrase: + [ [ `EOI -> None ] ] + ; + END; + + module AntiquotSyntax = struct + module Loc = Ast.Loc; + module Ast = Sig.Camlp4AstToAst Ast; + module Gram = Gram; + value antiquot_expr = Gram.Entry.mk "antiquot_expr"; + value antiquot_patt = Gram.Entry.mk "antiquot_patt"; + EXTEND Gram + antiquot_expr: + [ [ x = expr; `EOI -> x ] ] + ; + antiquot_patt: + [ [ x = patt; `EOI -> x ] ] + ; + END; + value parse_expr loc str = Gram.parse_string antiquot_expr loc str; + value parse_patt loc str = Gram.parse_string antiquot_patt loc str; + end; + + module Quotation = Quotation; + + value wrap directive_handler pa init_loc cs = + let rec loop loc = + let (pl, stopped_at_directive) = pa loc cs in + match stopped_at_directive with + [ Some new_loc -> + let pl = + match List.rev pl with + [ [] -> assert False + | [x :: xs] -> + match directive_handler x with + [ None -> xs + | Some x -> [x :: xs] ] ] + in (List.rev pl) @ (loop new_loc) + | None -> pl ] + in loop init_loc; + + value parse_implem ?(directive_handler = fun _ -> None) _loc cs = + let l = wrap directive_handler (Gram.parse implem) _loc cs in + <:str_item< $list:l$ >>; + + value parse_interf ?(directive_handler = fun _ -> None) _loc cs = + let l = wrap directive_handler (Gram.parse interf) _loc cs in + <:sig_item< $list:l$ >>; + + value print_interf ?input_file:(_) ?output_file:(_) _ = failwith "No interface printer"; + value print_implem ?input_file:(_) ?output_file:(_) _ = failwith "No implementation printer"; +end; diff --git a/camlp4/Camlp4/Options.ml b/camlp4/Camlp4/Options.ml new file mode 100644 index 0000000..e9979be --- /dev/null +++ b/camlp4/Camlp4/Options.ml @@ -0,0 +1,191 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +type spec_list = list (string * Arg.spec * string); +open Format; + +value rec action_arg s sl = + fun + [ Arg.Unit f -> if s = "" then do { f (); Some sl } else None + | Arg.Bool f -> + if s = "" then + match sl with + [ [s :: sl] -> + try do { f (bool_of_string s); Some sl } with + [ Invalid_argument "bool_of_string" -> None ] + | [] -> None ] + else + try do { f (bool_of_string s); Some sl } with + [ Invalid_argument "bool_of_string" -> None ] + | Arg.Set r -> if s = "" then do { r.val := True; Some sl } else None + | Arg.Clear r -> if s = "" then do { r.val := False; Some sl } else None + | Arg.Rest f -> do { List.iter f [s :: sl]; Some [] } + | Arg.String f -> + if s = "" then + match sl with + [ [s :: sl] -> do { f s; Some sl } + | [] -> None ] + else do { f s; Some sl } + | Arg.Set_string r -> + if s = "" then + match sl with + [ [s :: sl] -> do { r.val := s; Some sl } + | [] -> None ] + else do { r.val := s; Some sl } + | Arg.Int f -> + if s = "" then + match sl with + [ [s :: sl] -> + try do { f (int_of_string s); Some sl } with + [ Failure "int_of_string" -> None ] + | [] -> None ] + else + try do { f (int_of_string s); Some sl } with + [ Failure "int_of_string" -> None ] + | Arg.Set_int r -> + if s = "" then + match sl with + [ [s :: sl] -> + try do { r.val := (int_of_string s); Some sl } with + [ Failure "int_of_string" -> None ] + | [] -> None ] + else + try do { r.val := (int_of_string s); Some sl } with + [ Failure "int_of_string" -> None ] + | Arg.Float f -> + if s = "" then + match sl with + [ [s :: sl] -> do { f (float_of_string s); Some sl } + | [] -> None ] + else do { f (float_of_string s); Some sl } + | Arg.Set_float r -> + if s = "" then + match sl with + [ [s :: sl] -> do { r.val := (float_of_string s); Some sl } + | [] -> None ] + else do { r.val := (float_of_string s); Some sl } + | Arg.Tuple specs -> + let rec action_args s sl = + fun + [ [] -> Some sl + | [spec :: spec_list] -> + match action_arg s sl spec with + [ None -> action_args "" [] spec_list + | Some [s :: sl] -> action_args s sl spec_list + | Some sl -> action_args "" sl spec_list + ] + ] in + action_args s sl specs + | Arg.Symbol syms f -> + match (if s = "" then sl else [s :: sl]) with + [ [s :: sl] when List.mem s syms -> do { f s; Some sl } + | _ -> None ] + ]; + +value common_start s1 s2 = + loop 0 where rec loop i = + if i == String.length s1 || i == String.length s2 then i + else if s1.[i] == s2.[i] then loop (i + 1) + else i; + +value parse_arg fold s sl = + fold + (fun (name, action, _) acu -> + let i = common_start s name in + if i == String.length name then + try action_arg (String.sub s i (String.length s - i)) sl action with + [ Arg.Bad _ -> acu ] + else acu) None; + +value rec parse_aux fold anon_fun = + fun + [ [] -> [] + | [s :: sl] -> + if String.length s > 1 && s.[0] = '-' then + match parse_arg fold s sl with + [ Some sl -> parse_aux fold anon_fun sl + | None -> [s :: parse_aux fold anon_fun sl] ] + else do { (anon_fun s : unit); parse_aux fold anon_fun sl } ]; + +value align_doc key s = + let s = + loop 0 where rec loop i = + if i = String.length s then "" + else if s.[i] = ' ' then loop (i + 1) + else String.sub s i (String.length s - i) + in + let (p, s) = + if String.length s > 0 then + if s.[0] = '<' then + loop 0 where rec loop i = + if i = String.length s then ("", s) + else if s.[i] <> '>' then loop (i + 1) + else + let p = String.sub s 0 (i + 1) in + loop (i + 1) where rec loop i = + if i >= String.length s then (p, "") + else if s.[i] = ' ' then loop (i + 1) + else (p, String.sub s i (String.length s - i)) + else ("", s) + else ("", "") + in + let tab = + String.make (max 1 (16 - String.length key - String.length p)) ' ' + in + p ^ tab ^ s; + +value make_symlist l = + match l with + [ [] -> "" + | [h::t] -> (List.fold_left (fun x y -> x ^ "|" ^ y) ("{" ^ h) t) ^ "}" ]; + +value print_usage_list l = + List.iter + (fun (key, spec, doc) -> + match spec with + [ Arg.Symbol symbs _ -> + let s = make_symlist symbs in + let synt = key ^ " " ^ s in + eprintf " %s %s\n" synt (align_doc synt doc) + | _ -> eprintf " %s %s\n" key (align_doc key doc) ] ) + l; + +value remaining_args argv = + let rec loop l i = + if i == Array.length argv then l else loop [argv.(i) :: l] (i + 1) + in + List.rev (loop [] (Arg.current.val + 1)); + +value init_spec_list = ref []; +value ext_spec_list = ref []; + +value init spec_list = init_spec_list.val := spec_list; + +value add name spec descr = + ext_spec_list.val := [(name, spec, descr) :: ext_spec_list.val]; + +value fold f init = + let spec_list = init_spec_list.val @ ext_spec_list.val in + let specs = Sort.list (fun (k1, _, _) (k2, _, _) -> k1 >= k2) spec_list in + List.fold_right f specs init; + +value parse anon_fun argv = + let remaining_args = remaining_args argv in + parse_aux fold anon_fun remaining_args; + +value ext_spec_list () = ext_spec_list.val; diff --git a/camlp4/Camlp4/Options.mli b/camlp4/Camlp4/Options.mli new file mode 100644 index 0000000..caffd8c --- /dev/null +++ b/camlp4/Camlp4/Options.mli @@ -0,0 +1,26 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +type spec_list = list (string * Arg.spec * string); +value init : spec_list -> unit; +value add : string -> Arg.spec -> string -> unit; + (** Add an option to the command line options. *) +value print_usage_list : spec_list -> unit; +value ext_spec_list : unit -> spec_list; +value parse : (string -> unit) -> array string -> list string; diff --git a/camlp4/Camlp4/PreCast.ml b/camlp4/Camlp4/PreCast.ml new file mode 100644 index 0000000..527c0c4 --- /dev/null +++ b/camlp4/Camlp4/PreCast.ml @@ -0,0 +1,68 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id = struct + value name = "Camlp4.PreCast"; + value version = Sys.ocaml_version; +end; + +type camlp4_token = Sig.camlp4_token == + [ KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int and string + | INT32 of int32 and string + | INT64 of int64 and string + | NATIVEINT of nativeint and string + | FLOAT of float and string + | CHAR of char and string + | STRING of string and string + | LABEL of string + | OPTLABEL of string + | QUOTATION of Sig.quotation + | ANTIQUOT of string and string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int and option string + | EOI ]; + +module Loc = Struct.Loc; +module Ast = Struct.Camlp4Ast.Make Loc; +module Token = Struct.Token.Make Loc; +module Lexer = Struct.Lexer.Make Token; +module Gram = Struct.Grammar.Static.Make Lexer; +module DynLoader = Struct.DynLoader; +module Quotation = Struct.Quotation.Make Ast; +module MakeSyntax (U : sig end) = OCamlInitSyntax.Make Ast Gram Quotation; +module Syntax = MakeSyntax (struct end); +module AstFilters = Struct.AstFilters.Make Ast; +module MakeGram = Struct.Grammar.Static.Make; + +module Printers = struct + module OCaml = Printers.OCaml.Make Syntax; + module OCamlr = Printers.OCamlr.Make Syntax; + (* module OCamlrr = Printers.OCamlrr.Make Syntax; *) + module DumpOCamlAst = Printers.DumpOCamlAst.Make Syntax; + module DumpCamlp4Ast = Printers.DumpCamlp4Ast.Make Syntax; + module Null = Printers.Null.Make Syntax; +end; + diff --git a/camlp4/Camlp4/PreCast.mli b/camlp4/Camlp4/PreCast.mli new file mode 100644 index 0000000..1c6eb2e --- /dev/null +++ b/camlp4/Camlp4/PreCast.mli @@ -0,0 +1,76 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +type camlp4_token = Sig.camlp4_token == + [ KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int and string + | INT32 of int32 and string + | INT64 of int64 and string + | NATIVEINT of nativeint and string + | FLOAT of float and string + | CHAR of char and string + | STRING of string and string + | LABEL of string + | OPTLABEL of string + | QUOTATION of Sig.quotation + | ANTIQUOT of string and string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int and option string + | EOI ]; + +module Id : Sig.Id; +module Loc : Sig.Loc; +module Ast : Sig.Camlp4Ast with module Loc = Loc; +module Token : Sig.Token + with module Loc = Loc + and type t = camlp4_token; +module Lexer : Sig.Lexer + with module Loc = Loc + and module Token = Token; +module Gram : Sig.Grammar.Static + with module Loc = Loc + and module Token = Token; +module Quotation : Sig.Quotation with module Ast = Sig.Camlp4AstToAst Ast; +module DynLoader : Sig.DynLoader; +module AstFilters : Sig.AstFilters with module Ast = Ast; +module Syntax : Sig.Camlp4Syntax + with module Loc = Loc + and module Token = Token + and module Ast = Ast + and module Gram = Gram + and module Quotation = Quotation; + +module Printers : sig + module OCaml : (Sig.Printer Ast).S; + module OCamlr : (Sig.Printer Ast).S; + module DumpOCamlAst : (Sig.Printer Ast).S; + module DumpCamlp4Ast : (Sig.Printer Ast).S; + module Null : (Sig.Printer Ast).S; +end; + +module MakeGram (Lexer : Sig.Lexer with module Loc = Loc) + : Sig.Grammar.Static with module Loc = Loc and module Token = Lexer.Token; + +module MakeSyntax (U : sig end) : Sig.Syntax; diff --git a/camlp4/Camlp4/Printers.mlpack b/camlp4/Camlp4/Printers.mlpack new file mode 100644 index 0000000..9e593a7 --- /dev/null +++ b/camlp4/Camlp4/Printers.mlpack @@ -0,0 +1,5 @@ +DumpCamlp4Ast +DumpOCamlAst +Null +OCaml +OCamlr diff --git a/camlp4/Camlp4/Printers/DumpCamlp4Ast.ml b/camlp4/Camlp4/Printers/DumpCamlp4Ast.ml new file mode 100644 index 0000000..bd220c1 --- /dev/null +++ b/camlp4/Camlp4/Printers/DumpCamlp4Ast.ml @@ -0,0 +1,51 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id = struct + value name = "Camlp4Printers.DumpCamlp4Ast"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Syntax) +: (Sig.Printer Syntax.Ast).S += struct + include Syntax; + + value with_open_out_file x f = + match x with + [ Some file -> do { let oc = open_out_bin file; + f oc; + flush oc; + close_out oc } + | None -> do { set_binary_mode_out stdout True; f stdout; flush stdout } ]; + + value dump_ast magic ast oc = do { + output_string oc magic; + output_value oc ast; + }; + + value print_interf ?input_file:(_) ?output_file ast = + with_open_out_file output_file + (dump_ast Camlp4_config.camlp4_ast_intf_magic_number ast); + + value print_implem ?input_file:(_) ?output_file ast = + with_open_out_file output_file + (dump_ast Camlp4_config.camlp4_ast_impl_magic_number ast); + +end; diff --git a/camlp4/Camlp4/Printers/DumpCamlp4Ast.mli b/camlp4/Camlp4/Printers/DumpCamlp4Ast.mli new file mode 100644 index 0000000..d35642a --- /dev/null +++ b/camlp4/Camlp4/Printers/DumpCamlp4Ast.mli @@ -0,0 +1,21 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Id : Sig.Id; + +module Make (Syntax : Sig.Syntax) : (Sig.Printer Syntax.Ast).S; diff --git a/camlp4/Camlp4/Printers/DumpOCamlAst.ml b/camlp4/Camlp4/Printers/DumpOCamlAst.ml new file mode 100644 index 0000000..dd6c60f --- /dev/null +++ b/camlp4/Camlp4/Printers/DumpOCamlAst.ml @@ -0,0 +1,53 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id : Sig.Id = struct + value name = "Camlp4Printers.DumpOCamlAst"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) +: (Sig.Printer Syntax.Ast).S += struct + include Syntax; + module Ast2pt = Struct.Camlp4Ast2OCamlAst.Make Ast; + + value with_open_out_file x f = + match x with + [ Some file -> do { let oc = open_out_bin file; + f oc; + flush oc; + close_out oc } + | None -> do { set_binary_mode_out stdout True; f stdout; flush stdout } ]; + + value dump_pt magic fname pt oc = do { + output_string oc magic; + output_value oc (if fname = "-" then "" else fname); + output_value oc pt; + }; + + value print_interf ?(input_file = "-") ?output_file ast = + let pt = Ast2pt.sig_item ast in + with_open_out_file output_file (dump_pt Camlp4_config.ocaml_ast_intf_magic_number input_file pt); + + value print_implem ?(input_file = "-") ?output_file ast = + let pt = Ast2pt.str_item ast in + with_open_out_file output_file (dump_pt Camlp4_config.ocaml_ast_impl_magic_number input_file pt); + +end; diff --git a/camlp4/Camlp4/Printers/DumpOCamlAst.mli b/camlp4/Camlp4/Printers/DumpOCamlAst.mli new file mode 100644 index 0000000..3233557 --- /dev/null +++ b/camlp4/Camlp4/Printers/DumpOCamlAst.mli @@ -0,0 +1,21 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Id : Sig.Id; + +module Make (Syntax : Sig.Camlp4Syntax) : (Sig.Printer Syntax.Ast).S; diff --git a/camlp4/Camlp4/Printers/Null.ml b/camlp4/Camlp4/Printers/Null.ml new file mode 100644 index 0000000..d593f9e --- /dev/null +++ b/camlp4/Camlp4/Printers/Null.ml @@ -0,0 +1,30 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id = struct + value name = "Camlp4.Printers.Null"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Syntax) = struct + include Syntax; + + value print_interf ?input_file:(_) ?output_file:(_) _ = (); + value print_implem ?input_file:(_) ?output_file:(_) _ = (); +end; diff --git a/camlp4/Camlp4/Printers/Null.mli b/camlp4/Camlp4/Printers/Null.mli new file mode 100644 index 0000000..d771511 --- /dev/null +++ b/camlp4/Camlp4/Printers/Null.mli @@ -0,0 +1,22 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id : Sig.Id; + +module Make (Syntax : Sig.Syntax) : (Sig.Printer Syntax.Ast).S; diff --git a/camlp4/Camlp4/Printers/OCaml.ml b/camlp4/Camlp4/Printers/OCaml.ml new file mode 100644 index 0000000..b364171 --- /dev/null +++ b/camlp4/Camlp4/Printers/OCaml.ml @@ -0,0 +1,1092 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open Format; + +module Id = struct + value name = "Camlp4.Printers.OCaml"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + include Syntax; + + type sep = format unit formatter unit; + + value pp = fprintf; + value cut f = fprintf f "@ "; + + value list' elt sep sep' f = + let rec loop = + fun + [ [] -> () + | [x::xs] -> do { pp f sep ; elt f x; pp f sep'; loop xs } ] in + fun + [ [] -> () + | [x] -> do { elt f x; pp f sep' } + | [x::xs] -> do { elt f x; pp f sep'; loop xs } ]; + + value list elt sep f = + let rec loop = + fun + [ [] -> () + | [x::xs] -> do { pp f sep ; elt f x; loop xs } ] in + fun + [ [] -> () + | [x] -> elt f x + | [x::xs] -> do { elt f x; loop xs } ]; + + value rec list_of_meta_list = + fun + [ Ast.LNil -> [] + | Ast.LCons x xs -> [x :: list_of_meta_list xs] + | Ast.LAnt x -> assert False ]; + + value meta_list elt sep f mxs = + let xs = list_of_meta_list mxs in + list elt sep f xs; + + module CommentFilter = Struct.CommentFilter.Make Token; + value comment_filter = CommentFilter.mk (); + CommentFilter.define (Gram.get_filter ()) comment_filter; + + module StringSet = Set.Make String; + + value infix_lidents = ["asr"; "land"; "lor"; "lsl"; "lsr"; "lxor"; "mod"; "or"]; + + value is_infix = + let first_chars = ['='; '<'; '>'; '|'; '&'; '$'; '@'; '^'; '+'; '-'; '*'; '/'; '%'; '\\'] + and infixes = + List.fold_right StringSet.add infix_lidents StringSet.empty + in fun s -> (StringSet.mem s infixes + || (s <> "" && List.mem s.[0] first_chars)); + + value is_keyword = + let keywords = (* without infix_lidents *) + List.fold_right StringSet.add + ["and"; "as"; "assert"; "begin"; "class"; "constraint"; "do"; + "done"; "downto"; "else"; "end"; "exception"; "external"; "false"; + "for"; "fun"; "function"; "functor"; "if"; "in"; "include"; + "inherit"; "initializer"; "lazy"; "let"; "match"; "method"; "module"; + "mutable"; "new"; "object"; "of"; "open"; "parser"; "private"; "rec"; "sig"; + "struct"; "then"; "to"; "true"; "try"; "type"; "val"; "virtual"; + "when"; "while"; "with"] StringSet.empty + in fun s -> StringSet.mem s keywords; + + module Lexer = Struct.Lexer.Make Token; + let module M = ErrorHandler.Register Lexer.Error in (); + open Sig; + value lexer s = + Lexer.from_string ~quotations:Camlp4_config.quotations.val Loc.ghost s; + value lex_string str = + try match lexer str with parser + [: `(tok, _); `(EOI, _) :] -> tok + with + [ Stream.Failure | Stream.Error _ -> + failwith (sprintf + "Cannot print %S this string contains more than one token" str) + | Lexer.Error.E exn -> + failwith (sprintf + "Cannot print %S this identifier does not respect OCaml lexing rules (%s)" + str (Lexer.Error.to_string exn)) ]; + + value ocaml_char = + fun + [ "'" -> "\\'" + | c -> c ]; + + value rec get_expr_args a al = + match a with + [ <:expr< $a1$ $a2$ >> -> get_expr_args a1 [a2 :: al] + | _ -> (a, al) ]; + + value rec get_patt_args a al = + match a with + [ <:patt< $a1$ $a2$ >> -> get_patt_args a1 [a2 :: al] + | _ -> (a, al) ]; + + value rec get_ctyp_args a al = + match a with + [ <:ctyp< $a1$ $a2$ >> -> get_ctyp_args a1 [a2 :: al] + | _ -> (a, al) ]; + + value is_irrefut_patt = Ast.is_irrefut_patt; + + value rec expr_fun_args = + fun + [ <:expr< fun $p$ -> $e$ >> as ge -> + if is_irrefut_patt p then + let (pl, e) = expr_fun_args e in + ([p :: pl], e) + else ([], ge) + | ge -> ([], ge) ]; + + value rec class_expr_fun_args = + fun + [ <:class_expr< fun $p$ -> $ce$ >> as ge -> + if is_irrefut_patt p then + let (pl, ce) = class_expr_fun_args ce in + ([p :: pl], ce) + else ([], ge) + | ge -> ([], ge) ]; + + value rec do_print_comments_before loc f = + parser + [ [: ` (comm, comm_loc) when Loc.strictly_before comm_loc loc; s :] -> + let () = f comm comm_loc in + do_print_comments_before loc f s + | [: :] -> () ]; + + class printer ?curry_constr:(init_curry_constr = False) ?(comments = True) () = + object (o) + + (** pipe means we are under a match case (try, function) *) + value pipe = False; + value semi = False; + + method under_pipe = {< pipe = True >}; + method under_semi = {< semi = True >}; + method reset_semi = {< semi = False >}; + method reset = {< pipe = False; semi = False >}; + + value semisep : sep = ";;"; + value andsep : sep = "@]@ @[<2>and@ "; + value value_val = "val"; + value value_let = "let"; + value mode = if comments then `comments else `no_comments; + value curry_constr = init_curry_constr; + value var_conversion = False; + + method semisep = semisep; + method set_semisep s = {< semisep = s >}; + method set_comments b = {< mode = if b then `comments else `no_comments >}; + method set_loc_and_comments = {< mode = `loc_and_comments >}; + method set_curry_constr b = {< curry_constr = b >}; + + method print_comments_before loc f = + match mode with + [ `comments -> + do_print_comments_before loc (fun c _ -> pp f "%s@ " c) + (CommentFilter.take_stream comment_filter) + | `loc_and_comments -> + let () = pp f "(*loc: %a*)@ " Loc.dump loc in + do_print_comments_before loc + (fun s -> pp f "%s(*comm_loc: %a*)@ " s Loc.dump) + (CommentFilter.take_stream comment_filter) + | _ -> () ]; + + method var f = + fun + [ "" -> pp f "$lid:\"\"$" + | "[]" -> pp f "[]" + | "()" -> pp f "()" + | " True" -> pp f "True" + | " False" -> pp f "False" + | v -> + match (var_conversion, v) with + [ (True, "val") -> pp f "contents" + | (True, "True") -> pp f "true" + | (True, "False") -> pp f "false" + | _ -> + match lex_string v with + [ (LIDENT s | UIDENT s | ESCAPED_IDENT s) when is_keyword s -> + pp f "%s__" s + | (LIDENT s | ESCAPED_IDENT s) when List.mem s infix_lidents -> + pp f "( %s )" s + | SYMBOL s -> + pp f "( %s )" s + | LIDENT s | UIDENT s | ESCAPED_IDENT s -> + pp_print_string f s + | tok -> failwith (sprintf + "Bad token used as an identifier: %s" + (Token.to_string tok)) ] ] ]; + + method type_params f = + fun + [ [] -> () + | [x] -> pp f "%a@ " o#ctyp x + | l -> pp f "@[<1>(%a)@]@ " (list o#ctyp ",@ ") l ]; + + method class_params f = + fun + [ <:ctyp< $t1$, $t2$ >> -> + pp f "@[<1>%a,@ %a@]" o#class_params t1 o#class_params t2 + | x -> o#ctyp f x ]; + + method mutable_flag f b = o#flag f b "mutable"; + method rec_flag f b = o#flag f b "rec"; + method virtual_flag f b = o#flag f b "virtual"; + method private_flag f b = o#flag f b "private"; + method flag f b n = + match b with + [ Ast.BTrue -> do { pp_print_string f n; pp f "@ " } + | Ast.BFalse -> () + | Ast.BAnt s -> o#anti f s ]; + + method anti f s = pp f "$%s$" s; + + method seq f = + fun + [ <:expr< $e1$; $e2$ >> -> + pp f "%a;@ %a" o#under_semi#seq e1 o#seq e2 + | <:expr< do { $e$ } >> -> + o#seq f e + | e -> o#expr f e ]; + + (* FIXME when the Format module will fixed. + pp_print_if_newline f (); + pp_print_string f "| "; *) + method match_case f = + fun + [ <:match_case@_loc<>> -> + pp f "@[<2>@ _ ->@ %a@]" o#raise_match_failure _loc + | a -> o#match_case_aux f a ]; + + method match_case_aux f = + fun + [ <:match_case<>> -> () + | <:match_case< $anti:s$ >> -> o#anti f s + | <:match_case< $a1$ | $a2$ >> -> + pp f "%a%a" o#match_case_aux a1 o#match_case_aux a2 + | <:match_case< $p$ -> $e$ >> -> + pp f "@ | @[<2>%a@ ->@ %a@]" o#patt p o#under_pipe#expr e + | <:match_case< $p$ when $w$ -> $e$ >> -> + pp f "@ | @[<2>%a@ when@ %a@ ->@ %a@]" + o#patt p o#under_pipe#expr w o#under_pipe#expr e ]; + + method binding f bi = + let () = o#node f bi Ast.loc_of_binding in + match bi with + [ <:binding<>> -> () + | <:binding< $b1$ and $b2$ >> -> + do { o#binding f b1; pp f andsep; o#binding f b2 } + | <:binding< $p$ = $e$ >> -> + let (pl, e) = + match p with + [ <:patt< ($_$ : $_$) >> -> ([], e) + | _ -> expr_fun_args e ] in + match (p, e) with + [ (<:patt< $lid:_$ >>, <:expr< ($e$ : $t$) >>) -> + pp f "%a :@ %a =@ %a" + (list o#simple_patt "@ ") [p::pl] o#ctyp t o#expr e + | _ -> pp f "%a @[<0>%a=@]@ %a" o#simple_patt + p (list' o#simple_patt "" "@ ") pl o#expr e ] + | <:binding< $anti:s$ >> -> o#anti f s ]; + + method record_binding f bi = + let () = o#node f bi Ast.loc_of_rec_binding in + match bi with + [ <:rec_binding<>> -> () + | <:rec_binding< $i$ = $e$ >> -> + pp f "@ @[<2>%a =@ %a@];" o#var_ident i o#expr e + | <:rec_binding< $b1$ ; $b2$ >> -> + do { o#under_semi#record_binding f b1; + o#under_semi#record_binding f b2 } + | <:rec_binding< $anti:s$ >> -> o#anti f s ]; + + method mk_patt_list = + fun + [ <:patt< [$p1$ :: $p2$] >> -> + let (pl, c) = o#mk_patt_list p2 in + ([p1 :: pl], c) + | <:patt< [] >> -> ([], None) + | p -> ([], Some p) ]; + + method mk_expr_list = + fun + [ <:expr< [$e1$ :: $e2$] >> -> + let (el, c) = o#mk_expr_list e2 in + ([e1 :: el], c) + | <:expr< [] >> -> ([], None) + | e -> ([], Some e) ]; + + method expr_list f = + fun + [ [] -> pp f "[]" + | [e] -> pp f "[ %a ]" o#under_semi#expr e + | el -> pp f "@[<2>[ %a@] ]" (list o#under_semi#expr ";@ ") el ]; + + method expr_list_cons simple f e = + let (el, c) = o#mk_expr_list e in + match c with + [ None -> o#expr_list f el + | Some x -> + (if simple then pp f "@[<2>(%a)@]" else pp f "@[<2>%a@]") + (list o#under_semi#dot_expr " ::@ ") (el @ [x]) ]; + + method patt_expr_fun_args f (p, e) = + let (pl, e) = expr_fun_args e + in pp f "%a@ ->@ %a" (list o#simple_patt "@ ") [p::pl] o#expr e; + + method patt_class_expr_fun_args f (p, ce) = + let (pl, ce) = class_expr_fun_args ce + in pp f "%a =@]@ %a" (list o#simple_patt "@ ") [p::pl] o#class_expr ce; + + method constrain f (t1, t2) = + pp f "@[<2>constraint@ %a =@ %a@]" o#ctyp t1 o#ctyp t2; + + method sum_type f t = + match Ast.list_of_ctyp t [] with + [ [] -> () + | ts -> + pp f "@[| %a@]" (list o#ctyp "@ | ") ts ]; + + method string f = pp f "%s"; + method quoted_string f = pp f "%S"; + + method numeric f num suff = + if num.[0] = '-' then pp f "(%s%s)" num suff else pp f "%s%s" num suff; + + method module_expr_get_functor_args accu = + fun + [ <:module_expr< functor ($s$ : $mt$) -> $me$ >> -> + o#module_expr_get_functor_args [(s, mt)::accu] me + | <:module_expr< ($me$ : $mt$) >> -> (List.rev accu, me, Some mt) + | me -> (List.rev accu, me, None) ]; + + method functor_args f = list o#functor_arg "@ " f; + + method functor_arg f (s, mt) = + pp f "@[<2>(%a :@ %a)@]" o#var s o#module_type mt; + + method module_rec_binding f = + fun + [ <:module_binding<>> -> () + | <:module_binding< $s$ : $mt$ = $me$ >> -> + pp f "@[<2>%a :@ %a =@ %a@]" + o#var s o#module_type mt o#module_expr me + | <:module_binding< $s$ : $mt$ >> -> + pp f "@[<2>%a :@ %a@]" o#var s o#module_type mt + | <:module_binding< $mb1$ and $mb2$ >> -> + do { o#module_rec_binding f mb1; + pp f andsep; + o#module_rec_binding f mb2 } + | <:module_binding< $anti:s$ >> -> o#anti f s ]; + + method class_declaration f = + fun + [ <:class_expr< ( $ce$ : $ct$ ) >> -> + pp f "%a :@ %a" o#class_expr ce o#class_type ct + | ce -> o#class_expr f ce ]; + + method raise_match_failure f _loc = + let n = Loc.file_name _loc in + let l = Loc.start_line _loc in + let c = Loc.start_off _loc - Loc.start_bol _loc in + o#expr f <:expr< raise (Match_failure $`str:n$ $`int:l$ $`int:c$) >>; + + method node : ! 'a . formatter -> 'a -> ('a -> Loc.t) -> unit = + fun f node loc_of_node -> + o#print_comments_before (loc_of_node node) f; + + method ident f i = + let () = o#node f i Ast.loc_of_ident in + match i with + [ <:ident< $i1$.$i2$ >> -> pp f "%a.@,%a" o#ident i1 o#ident i2 + | <:ident< $i1$ $i2$ >> -> pp f "%a@,(%a)" o#ident i1 o#ident i2 + | <:ident< $anti:s$ >> -> o#anti f s + | <:ident< $lid:s$ >> | <:ident< $uid:s$ >> -> o#var f s ]; + + method private var_ident = {< var_conversion = True >}#ident; + + method expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ ((<:expr< let $rec:_$ $_$ in $_$ >> | + <:expr< let module $_$ = $_$ in $_$ >>) as e) when semi -> + pp f "(%a)" o#reset#expr e + | ((<:expr< match $_$ with [ $_$ ] >> | + <:expr< try $_$ with [ $_$ ] >> | + <:expr< fun [ $_$ ] >>) as e) when pipe || semi -> + pp f "(%a)" o#reset#expr e + + | <:expr< - $x$ >> -> + (* If you want to remove the space take care of - !r *) + pp f "@[<2>-@ %a@]" o#dot_expr x + | <:expr< -. $x$ >> -> + pp f "@[<2>-.@ %a@]" o#dot_expr x (* same note as above *) + | <:expr< [$_$ :: $_$] >> -> o#expr_list_cons False f e + | <:expr@_loc< $lid:n$ $x$ $y$ >> when is_infix n -> + pp f "@[<2>%a@ %s@ %a@]" o#apply_expr x n o#apply_expr y + | <:expr< $x$ $y$ >> -> + let (a, al) = get_expr_args x [y] in + if (not curry_constr) && Ast.is_expr_constructor a then + match al with + [ [ <:expr< ($tup:_$) >> ] -> + pp f "@[<2>%a@ (%a)@]" o#apply_expr x o#expr y + | [_] -> pp f "@[<2>%a@ %a@]" o#apply_expr x o#apply_expr y + | al -> + pp f "@[<2>%a@ (%a)@]" o#apply_expr a + (list o#under_pipe#expr ",@ ") al ] + else pp f "@[<2>%a@]" (list o#apply_expr "@ ") [a::al] + | <:expr< $e1$.val := $e2$ >> -> + pp f "@[<2>%a :=@ %a@]" o#dot_expr e1 o#expr e2 + | <:expr< $e1$ := $e2$ >> -> + pp f "@[<2>%a@ <-@ %a@]" o#dot_expr e1 o#expr e2 + | <:expr@loc< fun [] >> -> + pp f "@[<2>fun@ _@ ->@ %a@]" o#raise_match_failure loc + | <:expr< fun $p$ -> $e$ >> when is_irrefut_patt p -> + pp f "@[<2>fun@ %a@]" o#patt_expr_fun_args (p, e) + | <:expr< fun [ $a$ ] >> -> + pp f "@[function%a@]" o#match_case a + | <:expr< if $e1$ then $e2$ else $e3$ >> -> + pp f "@[@[<2>if@ %a@]@ @[<2>then@ %a@]@ @[<2>else@ %a@]@]" + o#expr e1 o#under_semi#expr e2 o#under_semi#expr e3 + | <:expr< lazy $e$ >> -> pp f "@[<2>lazy@ %a@]" o#simple_expr e + | <:expr< let $rec:r$ $bi$ in $e$ >> -> + match e with + [ <:expr< let $rec:_$ $_$ in $_$ >> -> + pp f "@[<0>@[<2>let %a%a in@]@ %a@]" + o#rec_flag r o#binding bi o#reset_semi#expr e + | _ -> + pp f "@[@[<2>let %a%a@]@ @[in@ %a@]@]" + o#rec_flag r o#binding bi o#reset_semi#expr e ] + | <:expr< match $e$ with [ $a$ ] >> -> + pp f "@[@[@[<2>match %a@]@ with@]%a@]" + o#expr e o#match_case a + | <:expr< try $e$ with [ $a$ ] >> -> + pp f "@[<0>@[try@ %a@]@ @[<0>with%a@]@]" + o#expr e o#match_case a + | <:expr< assert False >> -> pp f "@[<2>assert@ false@]" + | <:expr< assert $e$ >> -> pp f "@[<2>assert@ %a@]" o#dot_expr e + | <:expr< let module $s$ = $me$ in $e$ >> -> + pp f "@[<2>let module %a =@ %a@]@ @[<2>in@ %a@]" o#var s o#module_expr me o#reset_semi#expr e + | <:expr< object $cst$ end >> -> + pp f "@[@[object@ %a@]@ end@]" o#class_str_item cst + | <:expr< object ($p$ : $t$) $cst$ end >> -> + pp f "@[@[object @[<1>(%a :@ %a)@]@ %a@]@ end@]" + o#patt p o#ctyp t o#class_str_item cst + | <:expr< object ($p$) $cst$ end >> -> + pp f "@[@[object @[<2>(%a)@]@ %a@]@ end@]" + o#patt p o#class_str_item cst + | e -> o#apply_expr f e ]; + + method apply_expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ <:expr< new $i$ >> -> pp f "@[<2>new@ %a@]" o#ident i + | e -> o#dot_expr f e ]; + + method dot_expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ <:expr< $e$.val >> -> pp f "@[<2>!@,%a@]" o#simple_expr e + | <:expr< $e1$ . $e2$ >> -> pp f "@[<2>%a.@,%a@]" o#dot_expr e1 o#dot_expr e2 + | <:expr< $e1$ .( $e2$ ) >> -> + pp f "@[<2>%a.@,(%a)@]" o#dot_expr e1 o#expr e2 + | <:expr< $e1$ .[ $e2$ ] >> -> + pp f "%a.@[<1>[@,%a@]@,]" o#dot_expr e1 o#expr e2 + | <:expr< $e$ # $s$ >> -> pp f "@[<2>%a#@,%s@]" o#dot_expr e s + | e -> o#simple_expr f e ]; + + method simple_expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ <:expr<>> -> () + | <:expr< do { $e$ } >> -> + pp f "@[(%a)@]" o#seq e + | <:expr< [$_$ :: $_$] >> -> o#expr_list_cons True f e + | <:expr< ( $tup:e$ ) >> -> + pp f "@[<1>(%a)@]" o#expr e + | <:expr< [| $e$ |] >> -> + pp f "@[<0>@[<2>[|@ %a@]@ |]@]" o#under_semi#expr e + | <:expr< ($e$ :> $t$) >> -> + pp f "@[<2>(%a :>@ %a)@]" o#expr e o#ctyp t + | <:expr< ($e$ : $t1$ :> $t2$) >> -> + pp f "@[<2>(%a :@ %a :>@ %a)@]" o#expr e o#ctyp t1 o#ctyp t2 + | <:expr< ($e$ : $t$) >> -> + pp f "@[<2>(%a :@ %a)@]" o#expr e o#ctyp t + | <:expr< $anti:s$ >> -> o#anti f s + | <:expr< for $s$ = $e1$ $to:df$ $e2$ do { $e3$ } >> -> + pp f "@[@[@[<2>for %a =@ %a@ %a@ %a@ do@]@ %a@]@ done@]" + o#var s o#expr e1 o#direction_flag df o#expr e2 o#seq e3 + | <:expr< $int:s$ >> -> o#numeric f s "" + | <:expr< $nativeint:s$ >> -> o#numeric f s "n" + | <:expr< $int64:s$ >> -> o#numeric f s "L" + | <:expr< $int32:s$ >> -> o#numeric f s "l" + | <:expr< $flo:s$ >> -> o#numeric f s "" + | <:expr< $chr:s$ >> -> pp f "'%s'" (ocaml_char s) + | <:expr< $id:i$ >> -> o#var_ident f i + | <:expr< { $b$ } >> -> + pp f "@[@[{%a@]@ }@]" o#record_binding b + | <:expr< { ($e$) with $b$ } >> -> + pp f "@[@[{@ (%a)@ with%a@]@ }@]" + o#expr e o#record_binding b + | <:expr< $str:s$ >> -> pp f "\"%s\"" s + | <:expr< while $e1$ do { $e2$ } >> -> + pp f "@[<2>while@ %a@ do@ %a@ done@]" o#expr e1 o#seq e2 + | <:expr< ~ $s$ >> -> pp f "~%s" s + | <:expr< ~ $s$ : $e$ >> -> pp f "@[<2>~%s:@ %a@]" s o#dot_expr e + | <:expr< ? $s$ >> -> pp f "?%s" s + | <:expr< ? $s$ : $e$ >> -> pp f "@[<2>?%s:@ %a@]" s o#dot_expr e + | <:expr< ` $lid:s$ >> -> pp f "`%a" o#var s + | <:expr< {< $b$ >} >> -> + pp f "@[@[{<%a@]@ >}@]" o#record_binding b + | <:expr< $e1$, $e2$ >> -> + pp f "%a,@ %a" o#simple_expr e1 o#simple_expr e2 + | <:expr< $e1$; $e2$ >> -> + pp f "%a;@ %a" o#under_semi#expr e1 o#expr e2 + | <:expr< $_$ $_$ >> | <:expr< $_$ . $_$ >> | <:expr< $_$ . ( $_$ ) >> | + <:expr< $_$ . [ $_$ ] >> | <:expr< $_$ := $_$ >> | + <:expr< $_$ # $_$ >> | + <:expr< fun [ $_$ ] >> | <:expr< match $_$ with [ $_$ ] >> | + <:expr< try $_$ with [ $_$ ] >> | + <:expr< if $_$ then $_$ else $_$ >> | + <:expr< let $rec:_$ $_$ in $_$ >> | + <:expr< let module $_$ = $_$ in $_$ >> | + <:expr< assert $_$ >> | <:expr< assert False >> | + <:expr< lazy $_$ >> | <:expr< new $_$ >> | + <:expr< object ($_$) $_$ end >> -> + pp f "(%a)" o#reset#expr e ]; + + method direction_flag f b = + match b with + [ Ast.BTrue -> pp_print_string f "to" + | Ast.BFalse -> pp_print_string f "downto" + | Ast.BAnt s -> o#anti f s ]; + + method patt f p = + let () = o#node f p Ast.loc_of_patt in match p with + [ <:patt< ( $p1$ as $p2$ ) >> -> pp f "@[<1>(%a@ as@ %a)@]" o#patt p1 o#patt p2 + | <:patt< $i$ = $p$ >> -> pp f "@[<2>%a =@ %a@]" o#var_ident i o#patt p + | <:patt< $p1$; $p2$ >> -> pp f "%a;@ %a" o#patt p1 o#patt p2 + | p -> o#patt1 f p ]; + + method patt1 f = fun + [ <:patt< $p1$ | $p2$ >> -> pp f "@[<2>%a@ |@ %a@]" o#patt1 p1 o#patt2 p2 + | p -> o#patt2 f p ]; + + method patt2 f = fun + [ (* <:patt< ( $tup:p$ ) >> -> pp f "@[<1>(%a)@]" o#patt3 p + | *) p -> o#patt3 f p ]; + + method patt3 f = fun + [ <:patt< $p1$ .. $p2$ >> -> pp f "@[<2>%a@ ..@ %a@]" o#patt3 p1 o#patt4 p2 + | <:patt< $p1$, $p2$ >> -> pp f "%a,@ %a" o#patt3 p1 o#patt3 p2 + | p -> o#patt4 f p ]; + + method patt4 f = fun + [ <:patt< [$_$ :: $_$] >> as p -> + let (pl, c) = o#mk_patt_list p in + match c with + [ None -> pp f "@[<2>[@ %a@]@ ]" (list o#patt ";@ ") pl + | Some x -> pp f "@[<2>%a@]" (list o#patt5 " ::@ ") (pl @ [x]) ] + | p -> o#patt5 f p ]; + + method patt5 f = fun + [ <:patt< [$_$ :: $_$] >> as p -> o#simple_patt f p + | <:patt< lazy $p$ >> -> + pp f "@[<2>lazy %a@]" o#simple_patt p + | <:patt< $x$ $y$ >> -> + let (a, al) = get_patt_args x [y] in + if not (Ast.is_patt_constructor a) then + Format.eprintf "WARNING: strange pattern application of a non constructor@." + else if curry_constr then + pp f "@[<2>%a@]" (list o#simple_patt "@ ") [a::al] + else + match al with + [ [ <:patt< ($tup:_$) >> ] -> + pp f "@[<2>%a@ (%a)@]" o#simple_patt x o#patt y + | [_] -> pp f "@[<2>%a@ %a@]" o#patt5 x o#simple_patt y + | al -> pp f "@[<2>%a@ (%a)@]" o#patt5 a + (list o#simple_patt ",@ ") al ] + | p -> o#simple_patt f p ]; + + method simple_patt f p = + let () = o#node f p Ast.loc_of_patt in + match p with + [ <:patt<>> -> () + | <:patt< $id:i$ >> -> o#var_ident f i + | <:patt< $anti:s$ >> -> o#anti f s + | <:patt< _ >> -> pp f "_" + | <:patt< ( $tup:p$ ) >> -> pp f "@[<1>(%a)@]" o#patt3 p + | <:patt< { $p$ } >> -> pp f "@[{@ %a@]@ }" o#patt p + | <:patt< $str:s$ >> -> pp f "\"%s\"" s + | <:patt< ( $p$ : $t$ ) >> -> pp f "@[<1>(%a :@ %a)@]" o#patt p o#ctyp t + | <:patt< $nativeint:s$ >> -> o#numeric f s "n" + | <:patt< $int64:s$ >> -> o#numeric f s "L" + | <:patt< $int32:s$ >> -> o#numeric f s "l" + | <:patt< $int:s$ >> -> o#numeric f s "" + | <:patt< $flo:s$ >> -> o#numeric f s "" + | <:patt< $chr:s$ >> -> pp f "'%s'" (ocaml_char s) + | <:patt< ~ $s$ >> -> pp f "~%s" s + | <:patt< ` $uid:s$ >> -> pp f "`%a" o#var s + | <:patt< # $i$ >> -> pp f "@[<2>#%a@]" o#ident i + | <:patt< [| $p$ |] >> -> pp f "@[<2>[|@ %a@]@ |]" o#patt p + | <:patt< ~ $s$ : ($p$) >> -> pp f "@[<2>~%s:@ (%a)@]" s o#patt p + | <:patt< ? $s$ >> -> pp f "?%s" s + | <:patt< ?($p$) >> -> + pp f "@[<2>?(%a)@]" o#patt_tycon p + | <:patt< ? $s$ : ($p$) >> -> + pp f "@[<2>?%s:@,@[<1>(%a)@]@]" s o#patt_tycon p + | <:patt< ?($p$ = $e$) >> -> + pp f "@[<2>?(%a =@ %a)@]" o#patt_tycon p o#expr e + | <:patt< ? $s$ : ($p$ = $e$) >> -> + pp f "@[<2>?%s:@,@[<1>(%a =@ %a)@]@]" s o#patt_tycon p o#expr e + | <:patt< $_$ $_$ >> | <:patt< ($_$ as $_$) >> | <:patt< $_$ | $_$ >> | + <:patt< $_$ .. $_$ >> | <:patt< $_$, $_$ >> | + <:patt< $_$; $_$ >> | <:patt< $_$ = $_$ >> | <:patt< lazy $_$ >> as p -> + pp f "@[<1>(%a)@]" o#patt p + ]; + + method patt_tycon f = + fun + [ <:patt< ( $p$ : $t$ ) >> -> pp f "%a :@ %a" o#patt p o#ctyp t + | p -> o#patt f p ]; + + method simple_ctyp f t = + let () = o#node f t Ast.loc_of_ctyp in + match t with + [ <:ctyp< $id:i$ >> -> o#ident f i + | <:ctyp< $anti:s$ >> -> o#anti f s + | <:ctyp< _ >> -> pp f "_" + | <:ctyp< ~ $s$ : $t$ >> -> pp f "@[<2>%s:@ %a@]" s o#simple_ctyp t + | <:ctyp< ? $s$ : $t$ >> -> pp f "@[<2>?%s:@ %a@]" s o#simple_ctyp t + | <:ctyp< < > >> -> pp f "< >" + | <:ctyp< < .. > >> -> pp f "< .. >" + | <:ctyp< < $t$ .. > >> -> pp f "@[<0>@[<2><@ %a;@ ..@]@ >@]" o#ctyp t + | <:ctyp< < $t$ > >> -> pp f "@[<0>@[<2><@ %a@]@ >@]" o#ctyp t + | <:ctyp< '$s$ >> -> pp f "'%a" o#var s + | <:ctyp< { $t$ } >> -> pp f "@[<2>{@ %a@]@ }" o#ctyp t + | <:ctyp< [ $t$ ] >> -> pp f "@[<0>%a@]" o#sum_type t + | <:ctyp< ( $tup:t$ ) >> -> pp f "@[<1>(%a)@]" o#ctyp t + | <:ctyp< [ = $t$ ] >> -> pp f "@[<2>[@ %a@]@ ]" o#sum_type t + | <:ctyp< [ < $t$ ] >> -> pp f "@[<2>[<@ %a@]@,]" o#sum_type t + | <:ctyp< [ < $t1$ > $t2$ ] >> -> + let (a, al) = get_ctyp_args t2 [] in + pp f "@[<2>[<@ %a@ >@ %a@]@ ]" o#sum_type t1 + (list o#simple_ctyp "@ ") [a::al] + | <:ctyp< [ > $t$ ] >> -> pp f "@[<2>[>@ %a@]@,]" o#sum_type t + | <:ctyp< # $i$ >> -> pp f "@[<2>#%a@]" o#ident i + | <:ctyp< $t1$ == $t2$ >> -> + pp f "@[<2>%a =@ %a@]" o#simple_ctyp t1 o#simple_ctyp t2 + | <:ctyp< `$s$ >> -> pp f "`%a" o#var s + | <:ctyp< $t1$ * $t2$ >> -> pp f "%a *@ %a" o#simple_ctyp t1 o#simple_ctyp t2 + | <:ctyp<>> -> assert False + | t -> pp f "@[<1>(%a)@]" o#ctyp t ]; + + method ctyp f t = + let () = o#node f t Ast.loc_of_ctyp in + match t with + [ <:ctyp< $t1$ as $t2$ >> -> pp f "@[<2>%a@ as@ %a@]" o#simple_ctyp t1 o#simple_ctyp t2 + | <:ctyp< $t1$ -> $t2$ >> -> pp f "@[<2>%a@ ->@ %a@]" o#ctyp1 t1 o#ctyp t2 + | <:ctyp< +'$s$ >> -> pp f "+'%a" o#var s + | <:ctyp< -'$s$ >> -> pp f "-'%a" o#var s + | <:ctyp< $t1$ | $t2$ >> -> pp f "%a@ | %a" o#ctyp t1 o#ctyp t2 + | <:ctyp< $t1$ : mutable $t2$ >> -> + pp f "@[mutable@ %a :@ %a@]" o#ctyp t1 o#ctyp t2 + | <:ctyp< $t1$ : $t2$ >> -> pp f "@[<2>%a :@ %a@]" o#ctyp t1 o#ctyp t2 + | <:ctyp< $t1$; $t2$ >> -> pp f "%a;@ %a" o#ctyp t1 o#ctyp t2 + | <:ctyp< $t$ of $<:ctyp<>>$ >> -> o#ctyp f t + | <:ctyp< $t1$ of $t2$ >> -> + pp f "@[%a@ @[<3>of@ %a@]@]" o#ctyp t1 o#constructor_type t2 + | <:ctyp< $t1$ of & $t2$ >> -> + pp f "@[%a@ @[<3>of &@ %a@]@]" o#ctyp t1 o#constructor_type t2 + | <:ctyp< $t1$ and $t2$ >> -> pp f "%a@ and %a" o#ctyp t1 o#ctyp t2 + | <:ctyp< mutable $t$ >> -> pp f "@[<2>mutable@ %a@]" o#ctyp t + | <:ctyp< $t1$ & $t2$ >> -> pp f "%a@ &@ %a" o#ctyp t1 o#ctyp t2 + | Ast.TyDcl _ tn tp te cl -> do { + pp f "@[<2>%a%a@]" o#type_params tp o#var tn; + match te with + [ <:ctyp<>> -> () + | _ -> pp f " =@ %a" o#ctyp te ]; + if cl <> [] then pp f "@ %a" (list o#constrain "@ ") cl else (); + } + | t -> o#ctyp1 f t ]; + + method ctyp1 f = fun + [ <:ctyp< $t1$ $t2$ >> -> + match get_ctyp_args t1 [t2] with + [ (_, [_]) -> pp f "@[<2>%a@ %a@]" o#simple_ctyp t2 o#simple_ctyp t1 + | (a, al) -> pp f "@[<2>(%a)@ %a@]" (list o#ctyp ",@ ") al o#simple_ctyp a ] + | <:ctyp< ! $t1$ . $t2$ >> -> + let (a, al) = get_ctyp_args t1 [] in + pp f "@[<2>%a.@ %a@]" (list o#ctyp "@ ") [a::al] o#ctyp t2 + | <:ctyp< private $t$ >> -> pp f "@[private@ %a@]" o#simple_ctyp t + | t -> o#simple_ctyp f t ]; + + method constructor_type f t = + match t with + [ <:ctyp@loc< $t1$ and $t2$ >> -> + let () = o#node f t (fun _ -> loc) in + pp f "%a@ * %a" o#constructor_type t1 o#constructor_type t2 + | <:ctyp< $_$ -> $_$ >> -> pp f "(%a)" o#ctyp t + | t -> o#ctyp f t ]; + + + method sig_item f sg = + let () = o#node f sg Ast.loc_of_sig_item in + match sg with + [ <:sig_item<>> -> () + | <:sig_item< $sg$; $<:sig_item<>>$ >> | + <:sig_item< $<:sig_item<>>$; $sg$ >> -> + o#sig_item f sg + | <:sig_item< $sg1$; $sg2$ >> -> + do { o#sig_item f sg1; cut f; o#sig_item f sg2 } + | <:sig_item< exception $t$ >> -> + pp f "@[<2>exception@ %a%(%)@]" o#ctyp t semisep + | <:sig_item< external $s$ : $t$ = $sl$ >> -> + pp f "@[<2>external@ %a :@ %a =@ %a%(%)@]" + o#var s o#ctyp t (meta_list o#quoted_string "@ ") sl semisep + | <:sig_item< module $s1$ ($s2$ : $mt1$) : $mt2$ >> -> + let rec loop accu = + fun + [ <:module_type< functor ($s$ : $mt1$) -> $mt2$ >> -> + loop [(s, mt1)::accu] mt2 + | mt -> (List.rev accu, mt) ] in + let (al, mt) = loop [(s2, mt1)] mt2 in + pp f "@[<2>module %a@ @[<0>%a@] :@ %a%(%)@]" + o#var s1 o#functor_args al o#module_type mt semisep + | <:sig_item< module $s$ : $mt$ >> -> + pp f "@[<2>module %a :@ %a%(%)@]" + o#var s o#module_type mt semisep + | <:sig_item< module type $s$ = $ <:module_type<>> $ >> -> + pp f "@[<2>module type %a%(%)@]" o#var s semisep + | <:sig_item< module type $s$ = $mt$ >> -> + pp f "@[<2>module type %a =@ %a%(%)@]" + o#var s o#module_type mt semisep + | <:sig_item< open $sl$ >> -> + pp f "@[<2>open@ %a%(%)@]" o#ident sl semisep + | <:sig_item< type $t$ >> -> + pp f "@[@[type %a@]%(%)@]" o#ctyp t semisep + | <:sig_item< value $s$ : $t$ >> -> + pp f "@[<2>%s %a :@ %a%(%)@]" + value_val o#var s o#ctyp t semisep + | <:sig_item< include $mt$ >> -> + pp f "@[<2>include@ %a%(%)@]" o#module_type mt semisep + | <:sig_item< class type $ct$ >> -> + pp f "@[<2>class type %a%(%)@]" o#class_type ct semisep + | <:sig_item< class $ce$ >> -> + pp f "@[<2>class %a%(%)@]" o#class_type ce semisep + | <:sig_item< module rec $mb$ >> -> + pp f "@[<2>module rec %a%(%)@]" + o#module_rec_binding mb semisep + | <:sig_item< # $_$ $_$ >> -> () + | <:sig_item< $anti:s$ >> -> + pp f "%a%(%)" o#anti s semisep ]; + + method str_item f st = + let () = o#node f st Ast.loc_of_str_item in + match st with + [ <:str_item<>> -> () + | <:str_item< $st$; $<:str_item<>>$ >> | + <:str_item< $<:str_item<>>$; $st$ >> -> + o#str_item f st + | <:str_item< $st1$; $st2$ >> -> + do { o#str_item f st1; cut f; o#str_item f st2 } + | <:str_item< exception $t$ >> -> + pp f "@[<2>exception@ %a%(%)@]" o#ctyp t semisep + | <:str_item< exception $t$ = $sl$ >> -> + pp f "@[<2>exception@ %a =@ %a%(%)@]" o#ctyp t o#ident sl semisep + | <:str_item< external $s$ : $t$ = $sl$ >> -> + pp f "@[<2>external@ %a :@ %a =@ %a%(%)@]" + o#var s o#ctyp t (meta_list o#quoted_string "@ ") sl semisep + | <:str_item< module $s1$ ($s2$ : $mt1$) = $me$ >> -> + match o#module_expr_get_functor_args [(s2, mt1)] me with + [ (al, me, Some mt2) -> + pp f "@[<2>module %a@ @[<0>%a@] :@ %a =@ %a%(%)@]" + o#var s1 o#functor_args al o#module_type mt2 + o#module_expr me semisep + | (al, me, _) -> + pp f "@[<2>module %a@ @[<0>%a@] =@ %a%(%)@]" + o#var s1 o#functor_args al o#module_expr me semisep ] + | <:str_item< module $s$ : $mt$ = $me$ >> -> + pp f "@[<2>module %a :@ %a =@ %a%(%)@]" + o#var s o#module_type mt o#module_expr me semisep + | <:str_item< module $s$ = $me$ >> -> + pp f "@[<2>module %a =@ %a%(%)@]" o#var s o#module_expr me semisep + | <:str_item< module type $s$ = $mt$ >> -> + pp f "@[<2>module type %a =@ %a%(%)@]" + o#var s o#module_type mt semisep + | <:str_item< open $sl$ >> -> + pp f "@[<2>open@ %a%(%)@]" o#ident sl semisep + | <:str_item< type $t$ >> -> + pp f "@[@[type %a@]%(%)@]" o#ctyp t semisep + | <:str_item< value $rec:r$ $bi$ >> -> + pp f "@[<2>%s %a%a%(%)@]" value_let o#rec_flag r o#binding bi semisep + | <:str_item< $exp:e$ >> -> + pp f "@[<2>let _ =@ %a%(%)@]" o#expr e semisep + | <:str_item< include $me$ >> -> + pp f "@[<2>include@ %a%(%)@]" o#simple_module_expr me semisep + | <:str_item< class type $ct$ >> -> + pp f "@[<2>class type %a%(%)@]" o#class_type ct semisep + | <:str_item< class $ce$ >> -> + pp f "@[class %a%(%)@]" o#class_declaration ce semisep + | <:str_item< module rec $mb$ >> -> + pp f "@[<2>module rec %a%(%)@]" o#module_rec_binding mb semisep + | <:str_item< # $_$ $_$ >> -> () + | <:str_item< $anti:s$ >> -> pp f "%a%(%)" o#anti s semisep + | Ast.StExc _ _ (Ast.OAnt _) -> assert False ]; + + method module_type f mt = + let () = o#node f mt Ast.loc_of_module_type in + match mt with + [ <:module_type<>> -> assert False + | <:module_type< $id:i$ >> -> o#ident f i + | <:module_type< $anti:s$ >> -> o#anti f s + | <:module_type< functor ( $s$ : $mt1$ ) -> $mt2$ >> -> + pp f "@[<2>functor@ @[<1>(%a :@ %a)@]@ ->@ %a@]" + o#var s o#module_type mt1 o#module_type mt2 + | <:module_type< '$s$ >> -> pp f "'%a" o#var s + | <:module_type< sig $sg$ end >> -> + pp f "@[@[sig@ %a@]@ end@]" o#sig_item sg + | <:module_type< $mt$ with $wc$ >> -> + pp f "@[<2>%a@ with@ %a@]" o#module_type mt o#with_constraint wc ]; + + method with_constraint f wc = + let () = o#node f wc Ast.loc_of_with_constr in + match wc with + [ <:with_constr<>> -> () + | <:with_constr< type $t1$ = $t2$ >> -> + pp f "@[<2>type@ %a =@ %a@]" o#ctyp t1 o#ctyp t2 + | <:with_constr< module $i1$ = $i2$ >> -> + pp f "@[<2>module@ %a =@ %a@]" o#ident i1 o#ident i2 + | <:with_constr< $wc1$ and $wc2$ >> -> + do { o#with_constraint f wc1; pp f andsep; o#with_constraint f wc2 } + | <:with_constr< $anti:s$ >> -> o#anti f s ]; + + method module_expr f me = + let () = o#node f me Ast.loc_of_module_expr in + match me with + [ <:module_expr<>> -> assert False + | <:module_expr< ( struct $st$ end : sig $sg$ end ) >> -> + pp f "@[<2>@[struct@ %a@]@ end :@ @[sig@ %a@]@ end@]" + o#str_item st o#sig_item sg + | _ -> o#simple_module_expr f me ]; + + method simple_module_expr f me = + let () = o#node f me Ast.loc_of_module_expr in + match me with + [ <:module_expr<>> -> assert False + | <:module_expr< $id:i$ >> -> o#ident f i + | <:module_expr< $anti:s$ >> -> o#anti f s + | <:module_expr< $me1$ $me2$ >> -> + pp f "@[<2>%a@,(%a)@]" o#module_expr me1 o#module_expr me2 + | <:module_expr< functor ( $s$ : $mt$ ) -> $me$ >> -> + pp f "@[<2>functor@ @[<1>(%a :@ %a)@]@ ->@ %a@]" o#var s o#module_type mt o#module_expr me + | <:module_expr< struct $st$ end >> -> + pp f "@[@[struct@ %a@]@ end@]" o#str_item st + | <:module_expr< ( $me$ : $mt$ ) >> -> + pp f "@[<1>(%a :@ %a)@]" o#module_expr me o#module_type mt ]; + + method class_expr f ce = + let () = o#node f ce Ast.loc_of_class_expr in + match ce with + [ <:class_expr< $ce$ $e$ >> -> + pp f "@[<2>%a@ %a@]" o#class_expr ce o#expr e + | <:class_expr< $id:i$ >> -> + pp f "@[<2>%a@]" o#ident i + | <:class_expr< $id:i$ [ $t$ ] >> -> + pp f "@[<2>@[<1>[%a]@]@ %a@]" o#class_params t o#ident i + | <:class_expr< virtual $lid:i$ >> -> + pp f "@[<2>virtual@ %a@]" o#var i + | <:class_expr< virtual $lid:i$ [ $t$ ] >> -> + pp f "@[<2>virtual@ @[<1>[%a]@]@ %a@]" o#class_params t o#var i + | <:class_expr< fun $p$ -> $ce$ >> -> + pp f "@[<2>fun@ %a@ ->@ %a@]" o#simple_patt p o#class_expr ce + | <:class_expr< let $rec:r$ $bi$ in $ce$ >> -> + pp f "@[<2>let %a%a@]@ @[<2>in@ %a@]" + o#rec_flag r o#binding bi o#class_expr ce + | <:class_expr< object $cst$ end >> -> + pp f "@[@[object %a@]@ end@]" o#class_str_item cst + | <:class_expr< object ($p$) $cst$ end >> -> + pp f "@[@[object @[<1>(%a)@]@ %a@]@ end@]" + o#patt p o#class_str_item cst + | <:class_expr< ( $ce$ : $ct$ ) >> -> + pp f "@[<1>(%a :@ %a)@]" o#class_expr ce o#class_type ct + | <:class_expr< $anti:s$ >> -> o#anti f s + | <:class_expr< $ce1$ and $ce2$ >> -> + do { o#class_expr f ce1; pp f andsep; o#class_expr f ce2 } + | <:class_expr< $ce1$ = fun $p$ -> $ce2$ >> when is_irrefut_patt p -> + pp f "@[<2>%a@ %a" o#class_expr ce1 + o#patt_class_expr_fun_args (p, ce2) + | <:class_expr< $ce1$ = $ce2$ >> -> + pp f "@[<2>%a =@]@ %a" o#class_expr ce1 o#class_expr ce2 + | _ -> assert False ]; + + method class_type f ct = + let () = o#node f ct Ast.loc_of_class_type in + match ct with + [ <:class_type< $id:i$ >> -> + pp f "@[<2>%a@]" o#ident i + | <:class_type< $id:i$ [ $t$ ] >> -> + pp f "@[<2>[@,%a@]@,]@ %a" o#class_params t o#ident i + | <:class_type< virtual $lid:i$ >> -> + pp f "@[<2>virtual@ %a@]" o#var i + | <:class_type< virtual $lid:i$ [ $t$ ] >> -> + pp f "@[<2>virtual@ [@,%a@]@,]@ %a" o#class_params t o#var i + | <:class_type< [ $t$ ] -> $ct$ >> -> + pp f "@[<2>%a@ ->@ %a@]" o#simple_ctyp t o#class_type ct + | <:class_type< object $csg$ end >> -> + pp f "@[@[object@ %a@]@ end@]" o#class_sig_item csg + | <:class_type< object ($t$) $csg$ end >> -> + pp f "@[@[object @[<1>(%a)@]@ %a@]@ end@]" + o#ctyp t o#class_sig_item csg + | <:class_type< $anti:s$ >> -> o#anti f s + | <:class_type< $ct1$ and $ct2$ >> -> + do { o#class_type f ct1; pp f andsep; o#class_type f ct2 } + | <:class_type< $ct1$ : $ct2$ >> -> + pp f "%a :@ %a" o#class_type ct1 o#class_type ct2 + | <:class_type< $ct1$ = $ct2$ >> -> + pp f "%a =@ %a" o#class_type ct1 o#class_type ct2 + | _ -> assert False ]; + + method class_sig_item f csg = + let () = o#node f csg Ast.loc_of_class_sig_item in + match csg with + [ <:class_sig_item<>> -> () + | <:class_sig_item< $csg$; $<:class_sig_item<>>$ >> | + <:class_sig_item< $<:class_sig_item<>>$; $csg$ >> -> + o#class_sig_item f csg + | <:class_sig_item< $csg1$; $csg2$ >> -> + do { o#class_sig_item f csg1; cut f; o#class_sig_item f csg2 } + | <:class_sig_item< constraint $t1$ = $t2$ >> -> + pp f "@[<2>constraint@ %a =@ %a%(%)@]" o#ctyp t1 o#ctyp t2 semisep + | <:class_sig_item< inherit $ct$ >> -> + pp f "@[<2>inherit@ %a%(%)@]" o#class_type ct semisep + | <:class_sig_item< method $private:pr$ $s$ : $t$ >> -> + pp f "@[<2>method %a%a :@ %a%(%)@]" o#private_flag pr o#var s + o#ctyp t semisep + | <:class_sig_item< method virtual $private:pr$ $s$ : $t$ >> -> + pp f "@[<2>method virtual %a%a :@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t semisep + | <:class_sig_item< value $mutable:mu$ $virtual:vi$ $s$ : $t$ >> -> + pp f "@[<2>%s %a%a%a :@ %a%(%)@]" + value_val o#mutable_flag mu o#virtual_flag vi o#var s o#ctyp t + semisep + | <:class_sig_item< $anti:s$ >> -> + pp f "%a%(%)" o#anti s semisep ]; + + method class_str_item f cst = + let () = o#node f cst Ast.loc_of_class_str_item in + match cst with + [ <:class_str_item<>> -> () + | <:class_str_item< $cst$; $<:class_str_item<>>$ >> | + <:class_str_item< $<:class_str_item<>>$; $cst$ >> -> + o#class_str_item f cst + | <:class_str_item< $cst1$; $cst2$ >> -> + do { o#class_str_item f cst1; cut f; o#class_str_item f cst2 } + | <:class_str_item< constraint $t1$ = $t2$ >> -> + pp f "@[<2>constraint %a =@ %a%(%)@]" o#ctyp t1 o#ctyp t2 semisep + | <:class_str_item< inherit $ce$ >> -> + pp f "@[<2>inherit@ %a%(%)@]" o#class_expr ce semisep + | <:class_str_item< inherit $ce$ as $lid:s$ >> -> + pp f "@[<2>inherit@ %a as@ %a%(%)@]" o#class_expr ce o#var s semisep + | <:class_str_item< initializer $e$ >> -> + pp f "@[<2>initializer@ %a%(%)@]" o#expr e semisep + | <:class_str_item< method $private:pr$ $s$ = $e$ >> -> + pp f "@[<2>method %a%a =@ %a%(%)@]" + o#private_flag pr o#var s o#expr e semisep + | <:class_str_item< method $private:pr$ $s$ : $t$ = $e$ >> -> + pp f "@[<2>method %a%a :@ %a =@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t o#expr e semisep + | <:class_str_item< method virtual $private:pr$ $s$ : $t$ >> -> + pp f "@[<2>method virtual@ %a%a :@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t semisep + | <:class_str_item< value virtual $mutable:mu$ $s$ : $t$ >> -> + pp f "@[<2>%s virtual %a%a :@ %a%(%)@]" + value_val o#mutable_flag mu o#var s o#ctyp t semisep + | <:class_str_item< value $mutable:mu$ $s$ = $e$ >> -> + pp f "@[<2>%s %a%a =@ %a%(%)@]" + value_val o#mutable_flag mu o#var s o#expr e semisep + | <:class_str_item< $anti:s$ >> -> + pp f "%a%(%)" o#anti s semisep ]; + + method implem f st = + match st with + [ <:str_item< $exp:e$ >> -> pp f "@[<0>%a%(%)@]@." o#expr e semisep + | st -> pp f "@[%a@]@." o#str_item st ]; + + method interf f sg = pp f "@[%a@]@." o#sig_item sg; + end; + + value with_outfile output_file fct arg = + let call close f = do { + try fct f arg with [ exn -> do { close (); raise exn } ]; + close () + } in + match output_file with + [ None -> call (fun () -> ()) std_formatter + | Some s -> + let oc = open_out s in + let f = formatter_of_out_channel oc in + call (fun () -> close_out oc) f ]; + + value print output_file fct = + let o = new printer () in + with_outfile output_file (fct o); + + value print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg; + + value print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st; + +end; + +module MakeMore (Syntax : Sig.Camlp4Syntax) +: (Sig.Printer Syntax.Ast).S += struct + + include Make Syntax; + + value semisep : ref sep = ref ("@\n" : sep); + value margin = ref 78; + value comments = ref True; + value locations = ref False; + value curry_constr = ref False; + + value print output_file fct = + let o = new printer ~comments:comments.val + ~curry_constr:curry_constr.val () in + let o = o#set_semisep semisep.val in + let o = if locations.val then o#set_loc_and_comments else o in + with_outfile output_file + (fun f -> + let () = Format.pp_set_margin f margin.val in + Format.fprintf f "@[%a@]@." (fct o)); + + value print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg; + + value print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st; + + value check_sep s = + if String.contains s '%' then failwith "-sep Format error, % found in string" + else (Obj.magic (Struct.Token.Eval.string s : string) : sep); + + Options.add "-l" (Arg.Int (fun i -> margin.val := i)) + " line length for pretty printing."; + + Options.add "-ss" (Arg.Unit (fun () -> semisep.val := ";;")) + " Print double semicolons."; + + Options.add "-no_ss" (Arg.Unit (fun () -> semisep.val := "")) + " Do not print double semicolons (default)."; + + Options.add "-sep" (Arg.String (fun s -> semisep.val := check_sep s)) + " Use this string between phrases."; + + Options.add "-curry-constr" (Arg.Set curry_constr) "Use currified constructors."; + + Options.add "-no_comments" (Arg.Clear comments) "Do not add comments."; + + Options.add "-add_locations" (Arg.Set locations) "Add locations as comment."; + +end; diff --git a/camlp4/Camlp4/Printers/OCaml.mli b/camlp4/Camlp4/Printers/OCaml.mli new file mode 100644 index 0000000..6bc573b --- /dev/null +++ b/camlp4/Camlp4/Printers/OCaml.mli @@ -0,0 +1,163 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Id : Sig.Id; + +module Make (Syntax : Sig.Camlp4Syntax) : sig + open Format; + include Sig.Camlp4Syntax + with module Loc = Syntax.Loc + and module Token = Syntax.Token + and module Ast = Syntax.Ast + and module Gram = Syntax.Gram; + + type sep = format unit formatter unit; + + value list' : + (formatter -> 'a -> unit) -> + format 'b formatter unit -> + format unit formatter unit -> + formatter -> list 'a -> unit; + + value list : + (formatter -> 'a -> unit) -> + format 'b formatter unit -> + formatter -> list 'a -> unit; + + value lex_string : string -> Token.t; + value is_infix : string -> bool; + value is_keyword : string -> bool; + value ocaml_char : string -> string; + value get_expr_args : + Ast.expr -> list Ast.expr -> (Ast.expr * list Ast.expr); + value get_patt_args : + Ast.patt -> list Ast.patt -> (Ast.patt * list Ast.patt); + value get_ctyp_args : + Ast.ctyp -> list Ast.ctyp -> (Ast.ctyp * list Ast.ctyp); + value expr_fun_args : Ast.expr -> (list Ast.patt * Ast.expr); + + (** + [new printer ~curry_constr:True ~comments:False] + Default values: curry_constr = False + comments = True + *) + class printer : + [?curry_constr: bool] -> [?comments: bool] -> [unit] -> + object ('a) + method interf : formatter -> Ast.sig_item -> unit; + method implem : formatter -> Ast.str_item -> unit; + method sig_item : formatter -> Ast.sig_item -> unit; + method str_item : formatter -> Ast.str_item -> unit; + + value pipe : bool; + value semi : bool; + value semisep : sep; + value value_val : string; + value value_let : string; + method anti : formatter -> string -> unit; + method class_declaration : + formatter -> Ast.class_expr -> unit; + method class_expr : formatter -> Ast.class_expr -> unit; + method class_sig_item : + formatter -> Ast.class_sig_item -> unit; + method class_str_item : + formatter -> Ast.class_str_item -> unit; + method class_type : formatter -> Ast.class_type -> unit; + method constrain : + formatter -> (Ast.ctyp * Ast.ctyp) -> unit; + method ctyp : formatter -> Ast.ctyp -> unit; + method ctyp1 : formatter -> Ast.ctyp -> unit; + method constructor_type : formatter -> Ast.ctyp -> unit; + method dot_expr : formatter -> Ast.expr -> unit; + method apply_expr : formatter -> Ast.expr -> unit; + method expr : formatter -> Ast.expr -> unit; + method expr_list : formatter -> list Ast.expr -> unit; + method expr_list_cons : bool -> formatter -> Ast.expr -> unit; + method functor_arg : + formatter -> (string * Ast.module_type) -> unit; + method functor_args : + formatter -> + list (string * Ast.module_type) -> unit; + method ident : formatter -> Ast.ident -> unit; + method numeric : formatter -> string -> string -> unit; + method binding : formatter -> Ast.binding -> unit; + method record_binding : formatter -> Ast.rec_binding -> unit; + method match_case : formatter -> Ast.match_case -> unit; + method match_case_aux : formatter -> Ast.match_case -> unit; + method mk_expr_list : Ast.expr -> (list Ast.expr * option Ast.expr); + method mk_patt_list : Ast.patt -> (list Ast.patt * option Ast.patt); + method simple_module_expr : formatter -> Ast.module_expr -> unit; + method module_expr : formatter -> Ast.module_expr -> unit; + method module_expr_get_functor_args : + list (string * Ast.module_type) -> + Ast.module_expr -> + (list (string * Ast.module_type) * + Ast.module_expr * + option Ast.module_type); + method module_rec_binding : formatter -> Ast.module_binding -> unit; + method module_type : formatter -> Ast.module_type -> unit; + method mutable_flag : formatter -> Ast.meta_bool -> unit; + method direction_flag : formatter -> Ast.meta_bool -> unit; + method rec_flag : formatter -> Ast.meta_bool -> unit; + method flag : formatter -> Ast.meta_bool -> string -> unit; + method node : formatter -> 'b -> ('b -> Loc.t) -> unit; + method patt : formatter -> Ast.patt -> unit; + method patt1 : formatter -> Ast.patt -> unit; + method patt2 : formatter -> Ast.patt -> unit; + method patt3 : formatter -> Ast.patt -> unit; + method patt4 : formatter -> Ast.patt -> unit; + method patt5 : formatter -> Ast.patt -> unit; + method patt_tycon : formatter -> Ast.patt -> unit; + method patt_expr_fun_args : + formatter -> (Ast.patt * Ast.expr) -> unit; + method patt_class_expr_fun_args : + formatter -> (Ast.patt * Ast.class_expr) -> unit; + method print_comments_before : Loc.t -> formatter -> unit; + method private_flag : formatter -> Ast.meta_bool -> unit; + method virtual_flag : formatter -> Ast.meta_bool -> unit; + method quoted_string : formatter -> string -> unit; + method raise_match_failure : formatter -> Loc.t -> unit; + method reset : 'a; + method reset_semi : 'a; + method semisep : sep; + method set_comments : bool -> 'a; + method set_curry_constr : bool -> 'a; + method set_loc_and_comments : 'a; + method set_semisep : sep -> 'a; + method simple_ctyp : formatter -> Ast.ctyp -> unit; + method simple_expr : formatter -> Ast.expr -> unit; + method simple_patt : formatter -> Ast.patt -> unit; + method seq : formatter -> Ast.expr -> unit; + method string : formatter -> string -> unit; + method sum_type : formatter -> Ast.ctyp -> unit; + method type_params : formatter -> list Ast.ctyp -> unit; + method class_params : formatter -> Ast.ctyp -> unit; + method under_pipe : 'a; + method under_semi : 'a; + method var : formatter -> string -> unit; + method with_constraint : formatter -> Ast.with_constr -> unit; + end; + + value with_outfile : + option string -> (formatter -> 'a -> unit) -> 'a -> unit; + + value print : + option string -> (printer -> formatter -> 'a -> unit) -> 'a -> unit; +end; + +module MakeMore (Syntax : Sig.Camlp4Syntax) : (Sig.Printer Syntax.Ast).S; diff --git a/camlp4/Camlp4/Printers/OCamlr.ml b/camlp4/Camlp4/Printers/OCamlr.ml new file mode 100644 index 0000000..a1aa40c --- /dev/null +++ b/camlp4/Camlp4/Printers/OCamlr.ml @@ -0,0 +1,308 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open Format; + +module Id = struct + value name = "Camlp4.Printers.OCamlr"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + include Syntax; + open Sig; + + module PP_o = OCaml.Make Syntax; + + open PP_o; + + value pp = fprintf; + + value is_keyword = + let keywords = ["where"] + and not_keywords = ["false"; "function"; "true"; "val"] + in fun s -> not (List.mem s not_keywords) + && (is_keyword s || List.mem s keywords); + + class printer ?curry_constr:(init_curry_constr = True) ?(comments = True) () = + object (o) + inherit PP_o.printer ~curry_constr:init_curry_constr ~comments () as super; + + value semisep : sep = ";"; + value andsep : sep = "@]@ @[<2>and@ "; + value value_val = "value"; + value value_let = "value"; + value mode = if comments then `comments else `no_comments; + value curry_constr = init_curry_constr; + value first_match_case = True; + + method under_pipe = o; + method under_semi = o; + method reset_semi = o; + method reset = o; + method private unset_first_match_case = {< first_match_case = False >}; + method private set_first_match_case = {< first_match_case = True >}; + + method seq f e = + let rec self right f e = + let go_right = self right and go_left = self False in + match e with + [ <:expr< let $rec:r$ $bi$ in $e1$ >> -> + if right then + pp f "@[<2>let %a%a@];@ %a" + o#rec_flag r o#binding bi go_right e1 + else + pp f "(%a)" o#expr e + | <:expr< do { $e$ } >> -> go_right f e + | <:expr< $e1$; $e2$ >> -> do { + pp f "%a;@ " go_left e1; + match (right, e2) with + [ (True, <:expr< let $rec:r$ $bi$ in $e3$ >>) -> + pp f "@[<2>let %a%a@];@ %a" + o#rec_flag r o#binding bi go_right e3 + | _ -> go_right f e2 ] } + | e -> o#expr f e ] + in self True f e; + + method var f = + fun + [ "" -> pp f "$lid:\"\"$" + | "[]" -> pp f "[]" + | "()" -> pp f "()" + | " True" -> pp f "True" + | " False" -> pp f "False" + | v -> + match lex_string v with + [ (LIDENT s | UIDENT s | ESCAPED_IDENT s) when is_keyword s -> + pp f "%s__" s + | SYMBOL s -> + pp f "( %s )" s + | LIDENT s | UIDENT s | ESCAPED_IDENT s -> + pp_print_string f s + | tok -> failwith (sprintf + "Bad token used as an identifier: %s" + (Token.to_string tok)) ] ]; + + method type_params f = + fun + [ [] -> () + | [x] -> pp f "@ %a" o#ctyp x + | l -> pp f "@ @[<1>%a@]" (list o#ctyp "@ ") l ]; + + method match_case f = + fun + [ <:match_case<>> -> pp f "@ []" + | m -> pp f "@ [ %a ]" o#set_first_match_case#match_case_aux m ]; + + method match_case_aux f = + fun + [ <:match_case<>> -> () + | <:match_case< $anti:s$ >> -> o#anti f s + | <:match_case< $a1$ | $a2$ >> -> + pp f "%a%a" o#match_case_aux a1 o#unset_first_match_case#match_case_aux a2 + | <:match_case< $p$ -> $e$ >> -> + let () = if first_match_case then () else pp f "@ | " in + pp f "@[<2>%a@ ->@ %a@]" o#patt p o#under_pipe#expr e + | <:match_case< $p$ when $w$ -> $e$ >> -> + let () = if first_match_case then () else pp f "@ | " in + pp f "@[<2>%a@ when@ %a@ ->@ %a@]" + o#patt p o#under_pipe#expr w o#under_pipe#expr e ]; + + method sum_type f t = pp f "@[[ %a ]@]" o#ctyp t; + + method ident f i = + let () = o#node f i Ast.loc_of_ident in + match i with + [ <:ident< $i1$ $i2$ >> -> pp f "%a@ %a" o#dot_ident i1 o#dot_ident i2 + | i -> o#dot_ident f i ]; + + method private dot_ident f i = + let () = o#node f i Ast.loc_of_ident in + match i with + [ <:ident< $i1$.$i2$ >> -> pp f "%a.@,%a" o#dot_ident i1 o#dot_ident i2 + | <:ident< $anti:s$ >> -> o#anti f s + | <:ident< $lid:s$ >> | <:ident< $uid:s$ >> -> o#var f s + | i -> pp f "(%a)" o#ident i ]; + + method patt4 f = fun + [ <:patt< [$_$ :: $_$] >> as p -> + let (pl, c) = o#mk_patt_list p in + match c with + [ None -> pp f "@[<2>[@ %a@]@ ]" (list o#patt ";@ ") pl + | Some x -> pp f "@[<2>[ %a ::@ %a ]@]" (list o#patt ";@ ") pl o#patt x ] + | p -> super#patt4 f p ]; + + method expr_list_cons _ f e = + let (el, c) = o#mk_expr_list e in + match c with + [ None -> o#expr_list f el + | Some x -> pp f "@[<2>[ %a ::@ %a ]@]" (list o#expr ";@ ") el o#expr x ]; + + method expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ <:expr< $e1$ := $e2$ >> -> + pp f "@[<2>%a@ :=@ %a@]" o#dot_expr e1 o#expr e2 + | <:expr< fun $p$ -> $e$ >> when Ast.is_irrefut_patt p -> + pp f "@[<2>fun@ %a@]" o#patt_expr_fun_args (p, e) + | <:expr< fun [ $a$ ] >> -> + pp f "@[fun%a@]" o#match_case a + | <:expr< assert False >> -> pp f "@[<2>assert@ False@]" + | e -> super#expr f e ]; + + method dot_expr f e = + let () = o#node f e Ast.loc_of_expr in + match e with + [ <:expr< $e$.val >> -> pp f "@[<2>%a.@,val@]" o#simple_expr e + | e -> super#dot_expr f e ]; + + method ctyp f t = + let () = o#node f t Ast.loc_of_ctyp in + match t with + [ Ast.TyDcl _ tn tp te cl -> do { + pp f "@[<2>%a%a@]" o#var tn o#type_params tp; + match te with + [ <:ctyp<>> -> () + | _ -> pp f " =@ %a" o#ctyp te ]; + if cl <> [] then pp f "@ %a" (list o#constrain "@ ") cl else (); + } + | <:ctyp< $t1$ : mutable $t2$ >> -> + pp f "@[%a :@ mutable %a@]" o#ctyp t1 o#ctyp t2 + | t -> super#ctyp f t ]; + + method simple_ctyp f t = + let () = o#node f t Ast.loc_of_ctyp in + match t with + [ <:ctyp< [ = $t$ ] >> -> pp f "@[<2>[ =@ %a@]@ ]" o#ctyp t + | <:ctyp< [ < $t$ ] >> -> pp f "@[<2>[ <@ %a@]@,]" o#ctyp t + | <:ctyp< [ < $t1$ > $t2$ ] >> -> + pp f "@[<2>[ <@ %a@ >@ %a@]@ ]" o#ctyp t1 o#ctyp t2 + | <:ctyp< [ > $t$ ] >> -> pp f "@[<2>[ >@ %a@]@,]" o#ctyp t + | <:ctyp< $t1$ == $t2$ >> -> + pp f "@[<2>%a@ ==@ %a@]" o#simple_ctyp t1 o#simple_ctyp t2 + | <:ctyp< ~ $s$ : $t$ >> -> pp f "@[<2>~%s:@ %a@]" s o#simple_ctyp t + | t -> super#simple_ctyp f t ]; + + method ctyp1 f = fun + [ <:ctyp< $t1$ $t2$ >> -> + match get_ctyp_args t1 [t2] with + [ (_, [_]) -> pp f "@[<2>%a@ %a@]" o#simple_ctyp t1 o#simple_ctyp t2 + | (a, al) -> pp f "@[<2>%a@]" (list o#simple_ctyp "@ ") [a::al] ] + | <:ctyp< ! $t1$ . $t2$ >> -> + let (a, al) = get_ctyp_args t1 [] in + pp f "@[<2>! %a.@ %a@]" (list o#ctyp "@ ") [a::al] o#ctyp t2 + | t -> super#ctyp1 f t ]; + + method constructor_type f t = + match t with + [ <:ctyp@loc< $t1$ and $t2$ >> -> + let () = o#node f t (fun _ -> loc) in + pp f "%a@ and %a" o#constructor_type t1 o#constructor_type t2 + | t -> o#ctyp f t ]; + + method str_item f st = + match st with + [ <:str_item< $exp:e$ >> -> pp f "@[<2>%a%(%)@]" o#expr e semisep + | st -> super#str_item f st ]; + + method module_expr f me = + let () = o#node f me Ast.loc_of_module_expr in + match me with + [ <:module_expr< $me1$ $me2$ >> -> + pp f "@[<2>%a@ %a@]" o#module_expr me1 o#simple_module_expr me2 + | me -> super#module_expr f me ]; + + method simple_module_expr f me = + let () = o#node f me Ast.loc_of_module_expr in + match me with + [ <:module_expr< $_$ $_$ >> -> + pp f "(%a)" o#module_expr me + | _ -> super#simple_module_expr f me ]; + + method implem f st = pp f "@[%a@]@." o#str_item st; + + method class_type f ct = + let () = o#node f ct Ast.loc_of_class_type in + match ct with + [ <:class_type< [ $t$ ] -> $ct$ >> -> + pp f "@[<2>[ %a ] ->@ %a@]" o#simple_ctyp t o#class_type ct + | <:class_type< $id:i$ >> -> + pp f "@[<2>%a@]" o#ident i + | <:class_type< $id:i$ [ $t$ ] >> -> + pp f "@[<2>%a [@,%a@]@,]" o#ident i o#class_params t + | <:class_type< virtual $lid:i$ >> -> + pp f "@[<2>virtual@ %a@]" o#var i + | <:class_type< virtual $lid:i$ [ $t$ ] >> -> + pp f "@[<2>virtual@ %a@ [@,%a@]@,]" o#var i o#class_params t + | ct -> super#class_type f ct ]; + + method class_expr f ce = + let () = o#node f ce Ast.loc_of_class_expr in + match ce with + [ <:class_expr< $id:i$ >> -> + pp f "@[<2>%a@]" o#ident i + | <:class_expr< $id:i$ [ $t$ ] >> -> + pp f "@[<2>%a@ @[<1>[%a]@]@]" o#ident i o#class_params t + | <:class_expr< virtual $lid:i$ >> -> + pp f "@[<2>virtual@ %a@]" o#var i + | <:class_expr< virtual $lid:i$ [ $t$ ] >> -> + pp f "@[<2>virtual@ %a@ @[<1>[%a]@]@]" o#var i o#ctyp t + | ce -> super#class_expr f ce ]; + end; + + value with_outfile = with_outfile; + value print = print; + value print_interf = print_interf; + value print_implem = print_implem; + +end; + +module MakeMore (Syntax : Sig.Camlp4Syntax) +: (Sig.Printer Syntax.Ast).S += struct + + include Make Syntax; + + value margin = ref 78; + value comments = ref True; + value locations = ref False; + value curry_constr = ref True; + + value print output_file fct = + let o = new printer ~comments:comments.val + ~curry_constr:curry_constr.val () in + let o = if locations.val then o#set_loc_and_comments else o in + with_outfile output_file + (fun f -> + let () = Format.pp_set_margin f margin.val in + Format.fprintf f "@[%a@]@." (fct o)); + + value print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg; + + value print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st; + + Options.add "-l" (Arg.Int (fun i -> margin.val := i)) + " line length for pretty printing."; + + Options.add "-no_comments" (Arg.Clear comments) "Do not add comments."; + + Options.add "-add_locations" (Arg.Set locations) "Add locations as comment."; + +end; diff --git a/camlp4/Camlp4/Printers/OCamlr.mli b/camlp4/Camlp4/Printers/OCamlr.mli new file mode 100644 index 0000000..f1db176 --- /dev/null +++ b/camlp4/Camlp4/Printers/OCamlr.mli @@ -0,0 +1,47 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Id : Sig.Id; + +module Make (Syntax : Sig.Camlp4Syntax) : sig + open Format; + include Sig.Camlp4Syntax + with module Loc = Syntax.Loc + and module Token = Syntax.Token + and module Ast = Syntax.Ast + and module Gram = Syntax.Gram; + + (** + [new printer ~curry_constr:c ~comments:False] + Default values: curry_constr = True + comments = True + *) + class printer : + [?curry_constr: bool] -> [?comments: bool] -> [unit] -> + object ('a) + inherit (OCaml.Make Syntax).printer; + end; + + value with_outfile : + option string -> (formatter -> 'a -> unit) -> 'a -> unit; + + value print : + option string -> (printer -> formatter -> 'a -> unit) -> 'a -> unit; +end; + +module MakeMore (Syntax : Sig.Camlp4Syntax) : (Sig.Printer Syntax.Ast).S; diff --git a/camlp4/Camlp4/Register.ml b/camlp4/Camlp4/Register.ml new file mode 100644 index 0000000..6044b0d --- /dev/null +++ b/camlp4/Camlp4/Register.ml @@ -0,0 +1,170 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module PP = Printers; +open PreCast; + +type parser_fun 'a = + ?directive_handler:('a -> option 'a) -> PreCast.Loc.t -> Stream.t char -> 'a; + +type printer_fun 'a = + ?input_file:string -> ?output_file:string -> 'a -> unit; + +value sig_item_parser = ref (fun ?directive_handler:(_) _ _ -> failwith "No interface parser"); +value str_item_parser = ref (fun ?directive_handler:(_) _ _ -> failwith "No implementation parser"); + +value sig_item_printer = ref (fun ?input_file:(_) ?output_file:(_) _ -> failwith "No interface printer"); +value str_item_printer = ref (fun ?input_file:(_) ?output_file:(_) _ -> failwith "No implementation printer"); + +value callbacks = Queue.create (); + +value loaded_modules = ref []; + +value iter_and_take_callbacks f = + let rec loop () = loop (f (Queue.take callbacks)) in + try loop () with [ Queue.Empty -> () ]; + +value declare_dyn_module m f = + begin + (* let () = Format.eprintf "declare_dyn_module: %s@." m in *) + loaded_modules.val := [ m :: loaded_modules.val ]; + Queue.add (m, f) callbacks; + end; + +value register_str_item_parser f = str_item_parser.val := f; +value register_sig_item_parser f = sig_item_parser.val := f; +value register_parser f g = + do { str_item_parser.val := f; sig_item_parser.val := g }; + +value register_str_item_printer f = str_item_printer.val := f; +value register_sig_item_printer f = sig_item_printer.val := f; +value register_printer f g = + do { str_item_printer.val := f; sig_item_printer.val := g }; + +module Plugin (Id : Sig.Id) (Maker : functor (Unit : sig end) -> sig end) = struct + declare_dyn_module Id.name (fun _ -> let module M = Maker (struct end) in ()); +end; + +module SyntaxExtension (Id : Sig.Id) (Maker : Sig.SyntaxExtension) = struct + declare_dyn_module Id.name (fun _ -> let module M = Maker Syntax in ()); +end; + +module OCamlSyntaxExtension + (Id : Sig.Id) (Maker : functor (Syn : Sig.Camlp4Syntax) -> Sig.Camlp4Syntax) = +struct + declare_dyn_module Id.name (fun _ -> let module M = Maker Syntax in ()); +end; + +module SyntaxPlugin (Id : Sig.Id) (Maker : functor (Syn : Sig.Syntax) -> sig end) = struct + declare_dyn_module Id.name (fun _ -> let module M = Maker Syntax in ()); +end; + +module Printer + (Id : Sig.Id) (Maker : functor (Syn : Sig.Syntax) + -> (Sig.Printer Syn.Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + let module M = Maker Syntax in + register_printer M.print_implem M.print_interf); +end; + +module OCamlPrinter + (Id : Sig.Id) (Maker : functor (Syn : Sig.Camlp4Syntax) + -> (Sig.Printer Syn.Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + let module M = Maker Syntax in + register_printer M.print_implem M.print_interf); +end; + +module OCamlPreCastPrinter + (Id : Sig.Id) (P : (Sig.Printer PreCast.Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + register_printer P.print_implem P.print_interf); +end; + +module Parser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast) + -> (Sig.Parser Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + let module M = Maker PreCast.Ast in + register_parser M.parse_implem M.parse_interf); +end; + +module OCamlParser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Camlp4Ast) + -> (Sig.Parser Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + let module M = Maker PreCast.Ast in + register_parser M.parse_implem M.parse_interf); +end; + +module OCamlPreCastParser + (Id : Sig.Id) (P : (Sig.Parser PreCast.Ast).S) = +struct + declare_dyn_module Id.name (fun _ -> + register_parser P.parse_implem P.parse_interf); +end; + +module AstFilter + (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) = +struct + declare_dyn_module Id.name (fun _ -> let module M = Maker AstFilters in ()); +end; + +sig_item_parser.val := Syntax.parse_interf; +str_item_parser.val := Syntax.parse_implem; + +module CurrentParser = struct + module Ast = Ast; + value parse_interf ?directive_handler loc strm = + sig_item_parser.val ?directive_handler loc strm; + value parse_implem ?directive_handler loc strm = + str_item_parser.val ?directive_handler loc strm; +end; + +module CurrentPrinter = struct + module Ast = Ast; + value print_interf ?input_file ?output_file ast = + sig_item_printer.val ?input_file ?output_file ast; + value print_implem ?input_file ?output_file ast = + str_item_printer.val ?input_file ?output_file ast; +end; + +value enable_ocaml_printer () = + let module M = OCamlPrinter PP.OCaml.Id PP.OCaml.MakeMore in (); + +value enable_ocamlr_printer () = + let module M = OCamlPrinter PP.OCamlr.Id PP.OCamlr.MakeMore in (); + +(* value enable_ocamlrr_printer () = + let module M = OCamlPrinter PP.OCamlrr.Id PP.OCamlrr.MakeMore in (); *) + +value enable_dump_ocaml_ast_printer () = + let module M = OCamlPrinter PP.DumpOCamlAst.Id PP.DumpOCamlAst.Make in (); + +value enable_dump_camlp4_ast_printer () = + let module M = Printer PP.DumpCamlp4Ast.Id PP.DumpCamlp4Ast.Make in (); + +value enable_null_printer () = + let module M = Printer PP.Null.Id PP.Null.Make in (); + diff --git a/camlp4/Camlp4/Register.mli b/camlp4/Camlp4/Register.mli new file mode 100644 index 0000000..df1180f --- /dev/null +++ b/camlp4/Camlp4/Register.mli @@ -0,0 +1,94 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Plugin + (Id : Sig.Id) (Plugin : functor (Unit : sig end) -> sig end) : sig end; + +module SyntaxPlugin + (Id : Sig.Id) (SyntaxPlugin : functor (Syn : Sig.Syntax) -> sig end) : + sig end; + +module SyntaxExtension + (Id : Sig.Id) (SyntaxExtension : Sig.SyntaxExtension) : sig end; + +module OCamlSyntaxExtension + (Id : Sig.Id) + (SyntaxExtension : functor (Syntax : Sig.Camlp4Syntax) -> Sig.Camlp4Syntax) + : sig end; + +(** {6 Registering Parsers} *) + +type parser_fun 'a = + ?directive_handler:('a -> option 'a) -> PreCast.Loc.t -> Stream.t char -> 'a; + +value register_str_item_parser : parser_fun PreCast.Ast.str_item -> unit; +value register_sig_item_parser : parser_fun PreCast.Ast.sig_item -> unit; +value register_parser : parser_fun PreCast.Ast.str_item -> parser_fun PreCast.Ast.sig_item -> unit; + +module Parser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast) -> (Sig.Parser Ast).S) : sig end; + +module OCamlParser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Camlp4Ast) -> (Sig.Parser Ast).S) : sig end; + +module OCamlPreCastParser + (Id : Sig.Id) (Parser : (Sig.Parser PreCast.Ast).S) : sig end; + +(** {6 Registering Printers} *) + +type printer_fun 'a = + ?input_file:string -> ?output_file:string -> 'a -> unit; + +value register_str_item_printer : printer_fun PreCast.Ast.str_item -> unit; +value register_sig_item_printer : printer_fun PreCast.Ast.sig_item -> unit; +value register_printer : printer_fun PreCast.Ast.str_item -> printer_fun PreCast.Ast.sig_item -> unit; + +module Printer + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Syntax) -> (Sig.Printer Syn.Ast).S) : + sig end; + +module OCamlPrinter + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Camlp4Syntax) -> (Sig.Printer Syn.Ast).S) : + sig end; + +module OCamlPreCastPrinter + (Id : Sig.Id) (Printer : (Sig.Printer PreCast.Ast).S) : + sig end; + +(** {6 Registering Filters} *) + +module AstFilter + (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) : sig end; + +value declare_dyn_module : string -> (unit -> unit) -> unit; +value iter_and_take_callbacks : ((string * (unit -> unit)) -> unit) -> unit; +value loaded_modules : ref (list string); + +module CurrentParser : (Sig.Parser PreCast.Ast).S; +module CurrentPrinter : (Sig.Printer PreCast.Ast).S; + +value enable_ocaml_printer : unit -> unit; +value enable_ocamlr_printer : unit -> unit; +(* value enable_ocamlrr_printer : unit -> unit; *) +value enable_null_printer : unit -> unit; +value enable_dump_ocaml_ast_printer : unit -> unit; +value enable_dump_camlp4_ast_printer : unit -> unit; + diff --git a/camlp4/Camlp4/Sig.ml b/camlp4/Camlp4/Sig.ml new file mode 100644 index 0000000..3e7106e --- /dev/null +++ b/camlp4/Camlp4/Sig.ml @@ -0,0 +1,1370 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +(** Camlp4 signature repository *) + +(** {6 Basic signatures} *) + +(** Signature with just a type. *) +module type Type = sig + type t; +end; + +(** Signature for errors modules, an Error modules can be registred with + the {!ErrorHandler.Register} functor in order to be well printed. *) +module type Error = sig + type t; + exception E of t; + value to_string : t -> string; + value print : Format.formatter -> t -> unit; +end; + +(** A signature for extensions identifiers. *) +module type Id = sig + + (** The name of the extension, typically the module name. *) + value name : string; + + (** The version of the extension, typically $ Id$ with a versionning system. *) + value version : string; + +end; + +(** A signature for warnings abstract from locations. *) +module Warning (Loc : Type) = struct + module type S = sig + type warning = Loc.t -> string -> unit; + value default_warning : warning; + value current_warning : ref warning; + value print_warning : warning; + end; +end; + +(** {6 Advanced signatures} *) + +(** A signature for locations. *) +module type Loc = sig + + type t; + + (** Return a start location for the given file name. + This location starts at the begining of the file. *) + value mk : string -> t; + + (** The [ghost] location can be used when no location + information is available. *) + value ghost : t; + + (** {6 Conversion functions} *) + + (** Return a location where both positions are set the given position. *) + value of_lexing_position : Lexing.position -> t; + + (** Return an OCaml location. *) + value to_ocaml_location : t -> Camlp4_import.Location.t; + + (** Return a location from an OCaml location. *) + value of_ocaml_location : Camlp4_import.Location.t -> t; + + (** Return a location from ocamllex buffer. *) + value of_lexbuf : Lexing.lexbuf -> t; + + (** Return a location from [(file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost)]. *) + value of_tuple : (string * int * int * int * int * int * int * bool) -> t; + + (** Return [(file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost)]. *) + value to_tuple : t -> (string * int * int * int * int * int * int * bool); + + (** [merge loc1 loc2] Return a location that starts at [loc1] and end at [loc2]. *) + value merge : t -> t -> t; + + (** The stop pos becomes equal to the start pos. *) + value join : t -> t; + + (** [move selector n loc] + Return the location where positions are moved. + Affected positions are chosen with [selector]. + Returned positions have their character offset plus [n]. *) + value move : [= `start | `stop | `both ] -> int -> t -> t; + + (** [shift n loc] Return the location where the new start position is the old + stop position, and where the new stop position character offset is the + old one plus [n]. *) + value shift : int -> t -> t; + + (** [move_line n loc] Return the location with the old line count plus [n]. + The "begin of line" of both positions become the current offset. *) + value move_line : int -> t -> t; + + (** {6 Accessors} *) + + (** Return the file name *) + value file_name : t -> string; + + (** Return the line number of the begining of this location. *) + value start_line : t -> int; + + (** Return the line number of the ending of this location. *) + value stop_line : t -> int; + + (** Returns the number of characters from the begining of the file + to the begining of the line of location's begining. *) + value start_bol : t -> int; + + (** Returns the number of characters from the begining of the file + to the begining of the line of location's ending. *) + value stop_bol : t -> int; + + (** Returns the number of characters from the begining of the file + of the begining of this location. *) + value start_off : t -> int; + + (** Return the number of characters from the begining of the file + of the ending of this location. *) + value stop_off : t -> int; + + (** Return the start position as a Lexing.position. *) + value start_pos : t -> Lexing.position; + + (** Return the stop position as a Lexing.position. *) + value stop_pos : t -> Lexing.position; + + (** Generally, return true if this location does not come + from an input stream. *) + value is_ghost : t -> bool; + + (** Return the associated ghost location. *) + value ghostify : t -> t; + + (** Return the location with the give file name *) + value set_file_name : string -> t -> t; + + (** [strictly_before loc1 loc2] True if the stop position of [loc1] is + strictly_before the start position of [loc2]. *) + value strictly_before : t -> t -> bool; + + (** Return the location with an absolute file name. *) + value make_absolute : t -> t; + + (** Print the location into the formatter in a format suitable for error + reporting. *) + value print : Format.formatter -> t -> unit; + + (** Print the location in a short format useful for debugging. *) + value dump : Format.formatter -> t -> unit; + + (** Same as {!print} but return a string instead of printting it. *) + value to_string : t -> string; + + (** [Exc_located loc e] is an encapsulation of the exception [e] with + the input location [loc]. To be used in quotation expanders + and in grammars to specify some input location for an error. + Do not raise this exception directly: rather use the following + function [Loc.raise]. *) + exception Exc_located of t and exn; + + (** [raise loc e], if [e] is already an [Exc_located] exception, + re-raise it, else raise the exception [Exc_located loc e]. *) + value raise : t -> exn -> 'a; + + (** The name of the location variable used in grammars and in + the predefined quotations for OCaml syntax trees. Default: [_loc]. *) + value name : ref string; + +end; + +(** Abstract syntax tree minimal signature. + Types of this signature are abstract. + See the {!Camlp4Ast} signature for a concrete definition. *) +module type Ast = sig + + (** {6 Syntactic categories as abstract types} *) + + type loc; + type meta_bool; + type meta_option 'a; + type meta_list 'a; + type ctyp; + type patt; + type expr; + type module_type; + type sig_item; + type with_constr; + type module_expr; + type str_item; + type class_type; + type class_sig_item; + type class_expr; + type class_str_item; + type match_case; + type ident; + type binding; + type rec_binding; + type module_binding; + + (** {6 Location accessors} *) + + value loc_of_ctyp : ctyp -> loc; + value loc_of_patt : patt -> loc; + value loc_of_expr : expr -> loc; + value loc_of_module_type : module_type -> loc; + value loc_of_module_expr : module_expr -> loc; + value loc_of_sig_item : sig_item -> loc; + value loc_of_str_item : str_item -> loc; + value loc_of_class_type : class_type -> loc; + value loc_of_class_sig_item : class_sig_item -> loc; + value loc_of_class_expr : class_expr -> loc; + value loc_of_class_str_item : class_str_item -> loc; + value loc_of_with_constr : with_constr -> loc; + value loc_of_binding : binding -> loc; + value loc_of_rec_binding : rec_binding -> loc; + value loc_of_module_binding : module_binding -> loc; + value loc_of_match_case : match_case -> loc; + value loc_of_ident : ident -> loc; + + (** {6 Traversals} *) + + (** This class is the base class for map traversal on the Ast. + To make a custom traversal class one just extend it like that: + + This example swap pairs expression contents: + open Camlp4.PreCast; + [class swap = object + inherit Ast.map as super; + method expr e = + match super#expr e with + \[ <:expr\@_loc< ($e1$, $e2$) >> -> <:expr< ($e2$, $e1$) >> + | e -> e \]; + end; + value _loc = Loc.ghost; + value map = (new swap)#expr; + assert (map <:expr< fun x -> (x, 42) >> = <:expr< fun x -> (42, x) >>);] + *) + class map : object ('self_type) + method string : string -> string; + method list : ! 'a 'b . ('self_type -> 'a -> 'b) -> list 'a -> list 'b; + method meta_bool : meta_bool -> meta_bool; + method meta_option : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_option 'a -> meta_option 'b; + method meta_list : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_list 'a -> meta_list 'b; + method loc : loc -> loc; + method expr : expr -> expr; + method patt : patt -> patt; + method ctyp : ctyp -> ctyp; + method str_item : str_item -> str_item; + method sig_item : sig_item -> sig_item; + + method module_expr : module_expr -> module_expr; + method module_type : module_type -> module_type; + method class_expr : class_expr -> class_expr; + method class_type : class_type -> class_type; + method class_sig_item : class_sig_item -> class_sig_item; + method class_str_item : class_str_item -> class_str_item; + method with_constr : with_constr -> with_constr; + method binding : binding -> binding; + method rec_binding : rec_binding -> rec_binding; + method module_binding : module_binding -> module_binding; + method match_case : match_case -> match_case; + method ident : ident -> ident; + + method unknown : ! 'a. 'a -> 'a; + end; + + (** Fold style traversal *) + class fold : object ('self_type) + method string : string -> 'self_type; + method list : ! 'a . ('self_type -> 'a -> 'self_type) -> list 'a -> 'self_type; + method meta_bool : meta_bool -> 'self_type; + method meta_option : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_option 'a -> 'self_type; + method meta_list : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_list 'a -> 'self_type; + method loc : loc -> 'self_type; + method expr : expr -> 'self_type; + method patt : patt -> 'self_type; + method ctyp : ctyp -> 'self_type; + method str_item : str_item -> 'self_type; + method sig_item : sig_item -> 'self_type; + method module_expr : module_expr -> 'self_type; + method module_type : module_type -> 'self_type; + method class_expr : class_expr -> 'self_type; + method class_type : class_type -> 'self_type; + method class_sig_item : class_sig_item -> 'self_type; + method class_str_item : class_str_item -> 'self_type; + method with_constr : with_constr -> 'self_type; + method binding : binding -> 'self_type; + method rec_binding : rec_binding -> 'self_type; + method module_binding : module_binding -> 'self_type; + method match_case : match_case -> 'self_type; + method ident : ident -> 'self_type; + + method unknown : ! 'a. 'a -> 'self_type; + end; + +end; + + +(** Signature for OCaml syntax trees. *) (* + This signature is an extension of {!Ast} + It provides: + - Types for all kinds of structure. + - Map: A base class for map traversals. + - Map classes and functions for common kinds. + + == Core language == + ctyp :: Representaion of types + patt :: The type of patterns + expr :: The type of expressions + match_case :: The type of cases for match/function/try constructions + ident :: The type of identifiers (including path like Foo(X).Bar.y) + binding :: The type of let bindings + rec_binding :: The type of record definitions + + == Modules == + module_type :: The type of module types + sig_item :: The type of signature items + str_item :: The type of structure items + module_expr :: The type of module expressions + module_binding :: The type of recursive module definitions + with_constr :: The type of `with' constraints + + == Classes == + class_type :: The type of class types + class_sig_item :: The type of class signature items + class_expr :: The type of class expressions + class_str_item :: The type of class structure items + *) +module type Camlp4Ast = sig + + (** The inner module for locations *) + module Loc : Loc; + + INCLUDE "camlp4/Camlp4/Camlp4Ast.partial.ml"; + + value loc_of_ctyp : ctyp -> loc; + value loc_of_patt : patt -> loc; + value loc_of_expr : expr -> loc; + value loc_of_module_type : module_type -> loc; + value loc_of_module_expr : module_expr -> loc; + value loc_of_sig_item : sig_item -> loc; + value loc_of_str_item : str_item -> loc; + value loc_of_class_type : class_type -> loc; + value loc_of_class_sig_item : class_sig_item -> loc; + value loc_of_class_expr : class_expr -> loc; + value loc_of_class_str_item : class_str_item -> loc; + value loc_of_with_constr : with_constr -> loc; + value loc_of_binding : binding -> loc; + value loc_of_rec_binding : rec_binding -> loc; + value loc_of_module_binding : module_binding -> loc; + value loc_of_match_case : match_case -> loc; + value loc_of_ident : ident -> loc; + + module Meta : sig + module type META_LOC = sig + (* The first location is where to put the returned pattern. + Generally it's _loc to match with <:patt< ... >> quotations. + The second location is the one to treat. *) + value meta_loc_patt : loc -> loc -> patt; + (* The first location is where to put the returned expression. + Generally it's _loc to match with <:expr< ... >> quotations. + The second location is the one to treat. *) + value meta_loc_expr : loc -> loc -> expr; + end; + module MetaLoc : sig + value meta_loc_patt : loc -> loc -> patt; + value meta_loc_expr : loc -> loc -> expr; + end; + module MetaGhostLoc : sig + value meta_loc_patt : loc -> 'a -> patt; + value meta_loc_expr : loc -> 'a -> expr; + end; + module MetaLocVar : sig + value meta_loc_patt : loc -> 'a -> patt; + value meta_loc_expr : loc -> 'a -> expr; + end; + module Make (MetaLoc : META_LOC) : sig + module Expr : sig + value meta_string : loc -> string -> expr; + value meta_int : loc -> string -> expr; + value meta_float : loc -> string -> expr; + value meta_char : loc -> string -> expr; + value meta_bool : loc -> bool -> expr; + value meta_list : (loc -> 'a -> expr) -> loc -> list 'a -> expr; + value meta_binding : loc -> binding -> expr; + value meta_rec_binding : loc -> rec_binding -> expr; + value meta_class_expr : loc -> class_expr -> expr; + value meta_class_sig_item : loc -> class_sig_item -> expr; + value meta_class_str_item : loc -> class_str_item -> expr; + value meta_class_type : loc -> class_type -> expr; + value meta_ctyp : loc -> ctyp -> expr; + value meta_expr : loc -> expr -> expr; + value meta_ident : loc -> ident -> expr; + value meta_match_case : loc -> match_case -> expr; + value meta_module_binding : loc -> module_binding -> expr; + value meta_module_expr : loc -> module_expr -> expr; + value meta_module_type : loc -> module_type -> expr; + value meta_patt : loc -> patt -> expr; + value meta_sig_item : loc -> sig_item -> expr; + value meta_str_item : loc -> str_item -> expr; + value meta_with_constr : loc -> with_constr -> expr; + end; + module Patt : sig + value meta_string : loc -> string -> patt; + value meta_int : loc -> string -> patt; + value meta_float : loc -> string -> patt; + value meta_char : loc -> string -> patt; + value meta_bool : loc -> bool -> patt; + value meta_list : (loc -> 'a -> patt) -> loc -> list 'a -> patt; + value meta_binding : loc -> binding -> patt; + value meta_rec_binding : loc -> rec_binding -> patt; + value meta_class_expr : loc -> class_expr -> patt; + value meta_class_sig_item : loc -> class_sig_item -> patt; + value meta_class_str_item : loc -> class_str_item -> patt; + value meta_class_type : loc -> class_type -> patt; + value meta_ctyp : loc -> ctyp -> patt; + value meta_expr : loc -> expr -> patt; + value meta_ident : loc -> ident -> patt; + value meta_match_case : loc -> match_case -> patt; + value meta_module_binding : loc -> module_binding -> patt; + value meta_module_expr : loc -> module_expr -> patt; + value meta_module_type : loc -> module_type -> patt; + value meta_patt : loc -> patt -> patt; + value meta_sig_item : loc -> sig_item -> patt; + value meta_str_item : loc -> str_item -> patt; + value meta_with_constr : loc -> with_constr -> patt; + end; + end; + end; + + (** See {!Ast.map}. *) + class map : object ('self_type) + method string : string -> string; + method list : ! 'a 'b . ('self_type -> 'a -> 'b) -> list 'a -> list 'b; + method meta_bool : meta_bool -> meta_bool; + method meta_option : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_option 'a -> meta_option 'b; + method meta_list : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_list 'a -> meta_list 'b; + method loc : loc -> loc; + method expr : expr -> expr; + method patt : patt -> patt; + method ctyp : ctyp -> ctyp; + method str_item : str_item -> str_item; + method sig_item : sig_item -> sig_item; + + method module_expr : module_expr -> module_expr; + method module_type : module_type -> module_type; + method class_expr : class_expr -> class_expr; + method class_type : class_type -> class_type; + method class_sig_item : class_sig_item -> class_sig_item; + method class_str_item : class_str_item -> class_str_item; + method with_constr : with_constr -> with_constr; + method binding : binding -> binding; + method rec_binding : rec_binding -> rec_binding; + method module_binding : module_binding -> module_binding; + method match_case : match_case -> match_case; + method ident : ident -> ident; + + method unknown : ! 'a. 'a -> 'a; + end; + + (** See {!Ast.fold}. *) + class fold : object ('self_type) + method string : string -> 'self_type; + method list : ! 'a . ('self_type -> 'a -> 'self_type) -> list 'a -> 'self_type; + method meta_bool : meta_bool -> 'self_type; + method meta_option : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_option 'a -> 'self_type; + method meta_list : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_list 'a -> 'self_type; + method loc : loc -> 'self_type; + method expr : expr -> 'self_type; + method patt : patt -> 'self_type; + method ctyp : ctyp -> 'self_type; + method str_item : str_item -> 'self_type; + method sig_item : sig_item -> 'self_type; + method module_expr : module_expr -> 'self_type; + method module_type : module_type -> 'self_type; + method class_expr : class_expr -> 'self_type; + method class_type : class_type -> 'self_type; + method class_sig_item : class_sig_item -> 'self_type; + method class_str_item : class_str_item -> 'self_type; + method with_constr : with_constr -> 'self_type; + method binding : binding -> 'self_type; + method rec_binding : rec_binding -> 'self_type; + method module_binding : module_binding -> 'self_type; + method match_case : match_case -> 'self_type; + method ident : ident -> 'self_type; + + method unknown : ! 'a. 'a -> 'self_type; + end; + + value map_expr : (expr -> expr) -> map; + value map_patt : (patt -> patt) -> map; + value map_ctyp : (ctyp -> ctyp) -> map; + value map_str_item : (str_item -> str_item) -> map; + value map_sig_item : (sig_item -> sig_item) -> map; + value map_loc : (loc -> loc) -> map; + + value ident_of_expr : expr -> ident; + value ident_of_patt : patt -> ident; + value ident_of_ctyp : ctyp -> ident; + + value biAnd_of_list : list binding -> binding; + value rbSem_of_list : list rec_binding -> rec_binding; + value paSem_of_list : list patt -> patt; + value paCom_of_list : list patt -> patt; + value tyOr_of_list : list ctyp -> ctyp; + value tyAnd_of_list : list ctyp -> ctyp; + value tyAmp_of_list : list ctyp -> ctyp; + value tySem_of_list : list ctyp -> ctyp; + value tyCom_of_list : list ctyp -> ctyp; + value tySta_of_list : list ctyp -> ctyp; + value stSem_of_list : list str_item -> str_item; + value sgSem_of_list : list sig_item -> sig_item; + value crSem_of_list : list class_str_item -> class_str_item; + value cgSem_of_list : list class_sig_item -> class_sig_item; + value ctAnd_of_list : list class_type -> class_type; + value ceAnd_of_list : list class_expr -> class_expr; + value wcAnd_of_list : list with_constr -> with_constr; + value meApp_of_list : list module_expr -> module_expr; + value mbAnd_of_list : list module_binding -> module_binding; + value mcOr_of_list : list match_case -> match_case; + value idAcc_of_list : list ident -> ident; + value idApp_of_list : list ident -> ident; + value exSem_of_list : list expr -> expr; + value exCom_of_list : list expr -> expr; + + value list_of_ctyp : ctyp -> list ctyp -> list ctyp; + value list_of_binding : binding -> list binding -> list binding; + value list_of_rec_binding : rec_binding -> list rec_binding -> list rec_binding; + value list_of_with_constr : with_constr -> list with_constr -> list with_constr; + value list_of_patt : patt -> list patt -> list patt; + value list_of_expr : expr -> list expr -> list expr; + value list_of_str_item : str_item -> list str_item -> list str_item; + value list_of_sig_item : sig_item -> list sig_item -> list sig_item; + value list_of_class_sig_item : class_sig_item -> list class_sig_item -> list class_sig_item; + value list_of_class_str_item : class_str_item -> list class_str_item -> list class_str_item; + value list_of_class_type : class_type -> list class_type -> list class_type; + value list_of_class_expr : class_expr -> list class_expr -> list class_expr; + value list_of_module_expr : module_expr -> list module_expr -> list module_expr; + value list_of_module_binding : module_binding -> list module_binding -> list module_binding; + value list_of_match_case : match_case -> list match_case -> list match_case; + value list_of_ident : ident -> list ident -> list ident; + + (** Like [String.escape] but takes care to not + escape antiquotations strings. *) + value safe_string_escaped : string -> string; + + (** Returns True if the given pattern is irrefutable. *) + value is_irrefut_patt : patt -> bool; + + value is_constructor : ident -> bool; + value is_patt_constructor : patt -> bool; + value is_expr_constructor : expr -> bool; + + value ty_of_stl : (Loc.t * string * list ctyp) -> ctyp; + value ty_of_sbt : (Loc.t * string * bool * ctyp) -> ctyp; + value bi_of_pe : (patt * expr) -> binding; + value pel_of_binding : binding -> list (patt * expr); + value binding_of_pel : list (patt * expr) -> binding; + value sum_type_of_list : list (Loc.t * string * list ctyp) -> ctyp; + value record_type_of_list : list (Loc.t * string * bool * ctyp) -> ctyp; +end; + +(** This functor is a restriction functor. + It takes a Camlp4Ast module and gives the Ast one. + Typical use is for [with] constraints. + Example: ... with module Ast = Camlp4.Sig.Camlp4AstToAst Camlp4Ast *) +module Camlp4AstToAst (M : Camlp4Ast) : Ast + with type loc = M.loc + and type meta_bool = M.meta_bool + and type meta_option 'a = M.meta_option 'a + and type meta_list 'a = M.meta_list 'a + and type ctyp = M.ctyp + and type patt = M.patt + and type expr = M.expr + and type module_type = M.module_type + and type sig_item = M.sig_item + and type with_constr = M.with_constr + and type module_expr = M.module_expr + and type str_item = M.str_item + and type class_type = M.class_type + and type class_sig_item = M.class_sig_item + and type class_expr = M.class_expr + and type class_str_item = M.class_str_item + and type binding = M.binding + and type rec_binding = M.rec_binding + and type module_binding = M.module_binding + and type match_case = M.match_case + and type ident = M.ident += M; + +(** Concrete definition of Camlp4 ASTs abstracted from locations. + Since the Ast contains locations, this functor produces Ast types + for a given location type. *) +module MakeCamlp4Ast (Loc : Type) = struct + + INCLUDE "camlp4/Camlp4/Camlp4Ast.partial.ml"; + +end; + +(** {6 Filters} *) + +(** A type for stream filters. *) +type stream_filter 'a 'loc = Stream.t ('a * 'loc) -> Stream.t ('a * 'loc); + +(** Registerinng and folding of Ast filters. + Two kinds of filters must be handled: + - Implementation filters: str_item -> str_item. + - Interface filters: sig_item -> sig_item. *) +module type AstFilters = sig + + module Ast : Camlp4Ast; + + type filter 'a = 'a -> 'a; + + value register_sig_item_filter : (filter Ast.sig_item) -> unit; + value register_str_item_filter : (filter Ast.str_item) -> unit; + value register_topphrase_filter : (filter Ast.str_item) -> unit; + + value fold_interf_filters : ('a -> filter Ast.sig_item -> 'a) -> 'a -> 'a; + value fold_implem_filters : ('a -> filter Ast.str_item -> 'a) -> 'a -> 'a; + value fold_topphrase_filters : ('a -> filter Ast.str_item -> 'a) -> 'a -> 'a; + +end; + +(** ASTs as one single dynamic type *) +module type DynAst = sig + module Ast : Ast; + type tag 'a; + + value ctyp_tag : tag Ast.ctyp; + value patt_tag : tag Ast.patt; + value expr_tag : tag Ast.expr; + value module_type_tag : tag Ast.module_type; + value sig_item_tag : tag Ast.sig_item; + value with_constr_tag : tag Ast.with_constr; + value module_expr_tag : tag Ast.module_expr; + value str_item_tag : tag Ast.str_item; + value class_type_tag : tag Ast.class_type; + value class_sig_item_tag : tag Ast.class_sig_item; + value class_expr_tag : tag Ast.class_expr; + value class_str_item_tag : tag Ast.class_str_item; + value match_case_tag : tag Ast.match_case; + value ident_tag : tag Ast.ident; + value binding_tag : tag Ast.binding; + value rec_binding_tag : tag Ast.rec_binding; + value module_binding_tag : tag Ast.module_binding; + + value string_of_tag : tag 'a -> string; + + module Pack (X : sig type t 'a; end) : sig + type pack; + value pack : tag 'a -> X.t 'a -> pack; + value unpack : tag 'a -> pack -> X.t 'a; + value print_tag : Format.formatter -> pack -> unit; + end; +end; + + +(** {6 Quotation operations} *) + +(** The generic quotation type. + To see how fields are used here is an example: + <:q_name@q_loc> + The last one, q_shift is equal to the length of "<:q_name@q_loc<". *) +type quotation = + { q_name : string ; + q_loc : string ; + q_shift : int ; + q_contents : string }; + +(** The signature for a quotation expander registery. *) +module type Quotation = sig + module Ast : Ast; + module DynAst : DynAst with module Ast = Ast; + open Ast; + + (** The [loc] is the initial location. The option string is the optional name + for the location variable. The string is the quotation contents. *) + type expand_fun 'a = loc -> option string -> string -> 'a; + + (** [add name exp] adds the quotation [name] associated with the + expander [exp]. *) + value add : string -> DynAst.tag 'a -> expand_fun 'a -> unit; + + (** [find name] returns the expander of the given quotation name. *) + value find : string -> DynAst.tag 'a -> expand_fun 'a; + + (** [default] holds the default quotation name. *) + value default : ref string; + + (** [parse_quotation_result parse_function loc position_tag quotation quotation_result] + It's a parser wrapper, this function handles the error reporting for you. *) + value parse_quotation_result : + (loc -> string -> 'a) -> loc -> quotation -> string -> string -> 'a; + + (** function translating quotation names; default = identity *) + value translate : ref (string -> string); + + value expand : loc -> quotation -> DynAst.tag 'a -> 'a; + + (** [dump_file] optionally tells Camlp4 to dump the + result of an expander if this result is syntactically incorrect. + If [None] (default), this result is not dumped. If [Some fname], the + result is dumped in the file [fname]. *) + value dump_file : ref (option string); + + module Error : Error; + +end; + +(** {6 Tokens} *) + +(** A signature for tokens. *) +module type Token = sig + + module Loc : Loc; + + type t; + + value to_string : t -> string; + + value print : Format.formatter -> t -> unit; + + value match_keyword : string -> t -> bool; + + value extract_string : t -> string; + + module Filter : sig + + type token_filter = stream_filter t Loc.t; + + (** The type for this filter chain. + A basic implementation just store the [is_keyword] function given + by [mk] and use it in the [filter] function. *) + type t; + + (** The given predicate function returns true if the given string + is a keyword. This function can be used in filters to translate + identifier tokens to keyword tokens. *) + value mk : (string -> bool) -> t; + + (** This function allows to register a new filter to the token filter chain. + You can choose to not support these and raise an exception. *) + value define_filter : t -> (token_filter -> token_filter) -> unit; + + (** This function filter the given stream and return a filtered stream. + A basic implementation just match identifiers against the [is_keyword] + function to produce token keywords instead. *) + value filter : t -> token_filter; + + (** Called by the grammar system when a keyword is used. + The boolean argument is True when it's the first time that keyword + is used. If you do not care about this information just return [()]. *) + value keyword_added : t -> string -> bool -> unit; + + (** Called by the grammar system when a keyword is no longer used. + If you do not care about this information just return [()]. *) + value keyword_removed : t -> string -> unit; + end; + + module Error : Error; +end; + +(** This signature describes tokens for the Objective Caml and the Revised + syntax lexing rules. For some tokens the data constructor holds two + representations with the evaluated one and the source one. For example + the INT data constructor holds an integer and a string, this string can + contains more information that's needed for a good pretty-printing + ("42", "4_2", "0000042", "0b0101010"...). + + The meaning of the tokens are: +- [KEYWORD s] is the keyword [s]. +- [LIDENT s] is the ident [s] starting with a lowercase letter. +- [UIDENT s] is the ident [s] starting with an uppercase letter. +- [INT i s] (resp. [INT32 i s], [INT64 i s] and [NATIVEINT i s]) + the integer constant [i] whose string source is [s]. +- [FLOAT f s] is the float constant [f] whose string source is [s]. +- [STRING s s'] is the string constant [s] whose string source is [s']. +- [CHAR c s] is the character constant [c] whose string source is [s]. +- [QUOTATION q] is a quotation [q], see {!Quotation.t} for more information. +- [ANTIQUOT n s] is an antiquotation [n] holding the string [s]. +- [EOI] is the end of input. + + Warning: the second string associated with the constructor [STRING] is + the string found in the source without any interpretation. In particular, + the backslashes are not interpreted. For example, if the input is ["\n"] + the string is *not* a string with one element containing the character + "return", but a string of two elements: the backslash and the character + ["n"]. To interpret a string use the first string of the [STRING] + constructor (or if you need to compute it use the module + {!Camlp4.Struct.Token.Eval}. Same thing for the constructor [CHAR]. *) +type camlp4_token = + [ KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int and string + | INT32 of int32 and string + | INT64 of int64 and string + | NATIVEINT of nativeint and string + | FLOAT of float and string + | CHAR of char and string + | STRING of string and string + | LABEL of string + | OPTLABEL of string + | QUOTATION of quotation + | ANTIQUOT of string and string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int and option string + | EOI ]; + +(** A signature for specialized tokens. *) +module type Camlp4Token = Token with type t = camlp4_token; + +(** {6 Dynamic loaders} *) + +(** A signature for dynamic loaders. *) +module type DynLoader = sig + type t; + exception Error of string and string; + + (** [mk ?ocaml_stdlib ?camlp4_stdlib] + The stdlib flag is true by default. + To disable it use: [mk ~ocaml_stdlib:False] *) + value mk : ?ocaml_stdlib: bool -> ?camlp4_stdlib: bool -> unit -> t; + + (** Fold over the current load path list. *) + value fold_load_path : t -> (string -> 'a -> 'a) -> 'a -> 'a; + + (** [load f] Load the file [f]. If [f] is not an absolute path name, + the load path list used to find the directory of [f]. *) + value load : t -> string -> unit; + + (** [include_dir d] Add the directory [d] in the current load path + list (like the common -I option). *) + value include_dir : t -> string -> unit; + + (** [find_in_path f] Returns the full path of the file [f] if + [f] is in the current load path, raises [Not_found] otherwise. *) + value find_in_path : t -> string -> string; + + (** [is_native] [True] if we are in native code, [False] for bytecode. *) + value is_native : bool; +end; + +(** A signature for grammars. *) +module Grammar = struct + + (** Internal signature for sematantic actions of grammars, + not for the casual user. These functions are unsafe. *) + module type Action = sig + type t ; + + value mk : 'a -> t; + value get : t -> 'a; + value getf : t -> ('a -> 'b); + value getf2 : t -> ('a -> 'b -> 'c); + end; + + type assoc = + [ NonA + | RightA + | LeftA ]; + + type position = + [ First + | Last + | Before of string + | After of string + | Level of string ]; + + (** Common signature for {!Sig.Grammar.Static} and {!Sig.Grammar.Dynamic}. *) + module type Structure = sig + module Loc : Loc; + module Action : Action; + module Token : Token with module Loc = Loc; + + type gram; + type internal_entry; + type tree; + + type token_pattern = ((Token.t -> bool) * string); + + type symbol = + [ Smeta of string and list symbol and Action.t + | Snterm of internal_entry + | Snterml of internal_entry and string + | Slist0 of symbol + | Slist0sep of symbol and symbol + | Slist1 of symbol + | Slist1sep of symbol and symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree ]; + + type production_rule = (list symbol * Action.t); + type single_extend_statment = + (option string * option assoc * list production_rule); + type extend_statment = + (option position * list single_extend_statment); + type delete_statment = list symbol; + + type fold 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> Stream.t 'a -> 'c; + + type foldsep 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> (Stream.t 'a -> unit) -> Stream.t 'a -> 'c; + + end; + + (** Signature for Camlp4 grammars. Here the dynamic means that you can produce as + many grammar values as needed with a single grammar module. + If you do not need many grammar values it's preferable to use a static one. *) + module type Dynamic = sig + include Structure; + + (** Make a new grammar. *) + value mk : unit -> gram; + + module Entry : sig + (** The abstract type of grammar entries. The type parameter is the type + of the semantic actions that are associated with this entry. *) + type t 'a; + + (** Make a new entry from the given name. *) + value mk : gram -> string -> t 'a; + + (** Make a new entry from a name and an hand made token parser. *) + value of_parser : + gram -> string -> (Stream.t (Token.t * Loc.t) -> 'a) -> t 'a; + + (** Clear the entry and setup this parser instead. *) + value setup_parser : + t 'a -> (Stream.t (Token.t * Loc.t) -> 'a) -> unit; + + (** Get the entry name. *) + value name : t 'a -> string; + + (** Print the given entry into the given formatter. *) + value print : Format.formatter -> t 'a -> unit; + + (** Same as {!print} but show the left-factorization. *) + value dump : Format.formatter -> t 'a -> unit; + + (**/**) + value obj : t 'a -> internal_entry; + value clear : t 'a -> unit; + (**/**) + end; + + (** [get_filter g] Get the {!Token.Filter} associated to the [g]. *) + value get_filter : gram -> Token.Filter.t; + + type not_filtered 'a; + + (** This function is called by the EXTEND ... END syntax. *) + value extend : Entry.t 'a -> extend_statment -> unit; + + (** The delete rule. *) + value delete_rule : Entry.t 'a -> delete_statment -> unit; + + value srules : Entry.t 'a -> list (list symbol * Action.t) -> symbol; + value sfold0 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold1 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold0sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; + (* value sfold1sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; *) + + (** Use the lexer to produce a non filtered token stream from a char stream. *) + value lex : gram -> Loc.t -> Stream.t char + -> not_filtered (Stream.t (Token.t * Loc.t)); + + (** Token stream from string. *) + value lex_string : gram -> Loc.t -> string + -> not_filtered (Stream.t (Token.t * Loc.t)); + + (** Filter a token stream using the {!Token.Filter} module *) + value filter : gram -> not_filtered (Stream.t (Token.t * Loc.t)) + -> Stream.t (Token.t * Loc.t); + + (** Lex, filter and parse a stream of character. *) + value parse : Entry.t 'a -> Loc.t -> Stream.t char -> 'a; + + (** Same as {!parse} but from a string. *) + value parse_string : Entry.t 'a -> Loc.t -> string -> 'a; + + (** Parse a token stream that is not filtered yet. *) + value parse_tokens_before_filter : + Entry.t 'a -> not_filtered (Stream.t (Token.t * Loc.t)) -> 'a; + + (** Parse a token stream that is already filtered. *) + value parse_tokens_after_filter : + Entry.t 'a -> Stream.t (Token.t * Loc.t) -> 'a; + + end; + + (** Signature for Camlp4 grammars. Here the static means that there is only + one grammar value by grammar module. If you do not need to store the grammar + value it's preferable to use a static one. *) + module type Static = sig + include Structure; + + module Entry : sig + (** The abstract type of grammar entries. The type parameter is the type + of the semantic actions that are associated with this entry. *) + type t 'a; + + (** Make a new entry from the given name. *) + value mk : string -> t 'a; + + (** Make a new entry from a name and an hand made token parser. *) + value of_parser : + string -> (Stream.t (Token.t * Loc.t) -> 'a) -> t 'a; + + (** Clear the entry and setup this parser instead. *) + value setup_parser : + t 'a -> (Stream.t (Token.t * Loc.t) -> 'a) -> unit; + + (** Get the entry name. *) + value name : t 'a -> string; + + (** Print the given entry into the given formatter. *) + value print : Format.formatter -> t 'a -> unit; + + (** Same as {!print} but show the left-factorization. *) + value dump : Format.formatter -> t 'a -> unit; + + (**/**) + value obj : t 'a -> internal_entry; + value clear : t 'a -> unit; + (**/**) + end; + + (** Get the {!Token.Filter} associated to the grammar module. *) + value get_filter : unit -> Token.Filter.t; + + type not_filtered 'a; + + (** This function is called by the EXTEND ... END syntax. *) + value extend : Entry.t 'a -> extend_statment -> unit; + + (** The delete rule. *) + value delete_rule : Entry.t 'a -> delete_statment -> unit; + value srules : Entry.t 'a -> list (list symbol * Action.t) -> symbol; + value sfold0 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold1 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold0sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; + (* value sfold1sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; *) + + (** Use the lexer to produce a non filtered token stream from a char stream. *) + value lex : Loc.t -> Stream.t char + -> not_filtered (Stream.t (Token.t * Loc.t)); + (** Token stream from string. *) + value lex_string : Loc.t -> string + -> not_filtered (Stream.t (Token.t * Loc.t)); + + (** Filter a token stream using the {!Token.Filter} module *) + value filter : not_filtered (Stream.t (Token.t * Loc.t)) + -> Stream.t (Token.t * Loc.t); + + (** Lex, filter and parse a stream of character. *) + value parse : Entry.t 'a -> Loc.t -> Stream.t char -> 'a; + + (** Same as {!parse} but from a string. *) + value parse_string : Entry.t 'a -> Loc.t -> string -> 'a; + + (** Parse a token stream that is not filtered yet. *) + value parse_tokens_before_filter : + Entry.t 'a -> not_filtered (Stream.t (Token.t * Loc.t)) -> 'a; + + (** Parse a token stream that is already filtered. *) + value parse_tokens_after_filter : + Entry.t 'a -> Stream.t (Token.t * Loc.t) -> 'a; + + end; + +end; + +(** A signature for lexers. *) +module type Lexer = sig + module Loc : Loc; + module Token : Token with module Loc = Loc; + module Error : Error; + + (** The constructor for a lexing function. The character stream is the input + stream to be lexed. The result is a stream of pairs of a token and + a location. + The lexer do not use global (mutable) variables: instantiations + of [Lexer.mk ()] do not perturb each other. *) + value mk : unit -> (Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t)); +end; + + +(** A signature for parsers abstract from ASTs. *) +module Parser (Ast : Ast) = struct + module type SIMPLE = sig + (** The parse function for expressions. + The underlying expression grammar entry is generally "expr; EOI". *) + value parse_expr : Ast.loc -> string -> Ast.expr; + + (** The parse function for patterns. + The underlying pattern grammar entry is generally "patt; EOI". *) + value parse_patt : Ast.loc -> string -> Ast.patt; + end; + + module type S = sig + + (** Called when parsing an implementation (ml file) to build the syntax + tree; the returned list contains the phrases (structure items) as a + single "declare" node (a list of structure items); if the parser + encounter a directive it stops (since the directive may change the + syntax), the given [directive_handler] function evaluates it and + the parsing starts again. *) + value parse_implem : ?directive_handler:(Ast.str_item -> option Ast.str_item) -> + Ast.loc -> Stream.t char -> Ast.str_item; + + (** Same as {!parse_implem} but for interface (mli file). *) + value parse_interf : ?directive_handler:(Ast.sig_item -> option Ast.sig_item) -> + Ast.loc -> Stream.t char -> Ast.sig_item; + end; +end; + +(** A signature for printers abstract from ASTs. *) +module Printer (Ast : Ast) = struct + module type S = sig + + value print_interf : ?input_file:string -> ?output_file:string -> + Ast.sig_item -> unit; + value print_implem : ?input_file:string -> ?output_file:string -> + Ast.str_item -> unit; + + end; +end; + +(** A syntax module is a sort of constistent bunch of modules and values. + In such a module you have a parser, a printer, and also modules for + locations, syntax trees, tokens, grammars, quotations, anti-quotations. + There is also the main grammar entries. *) +module type Syntax = sig + module Loc : Loc; + module Ast : Ast with type loc = Loc.t; + module Token : Token with module Loc = Loc; + module Gram : Grammar.Static with module Loc = Loc and module Token = Token; + module Quotation : Quotation with module Ast = Ast; + + module AntiquotSyntax : (Parser Ast).SIMPLE; + + include (Warning Loc).S; + include (Parser Ast).S; + include (Printer Ast).S; +end; + +(** A syntax module is a sort of constistent bunch of modules and values. + In such a module you have a parser, a printer, and also modules for + locations, syntax trees, tokens, grammars, quotations, anti-quotations. + There is also the main grammar entries. *) +module type Camlp4Syntax = sig + module Loc : Loc; + + module Ast : Camlp4Ast with module Loc = Loc; + module Token : Camlp4Token with module Loc = Loc; + + module Gram : Grammar.Static with module Loc = Loc and module Token = Token; + module Quotation : Quotation with module Ast = Camlp4AstToAst Ast; + + module AntiquotSyntax : (Parser Ast).SIMPLE; + + include (Warning Loc).S; + include (Parser Ast).S; + include (Printer Ast).S; + + value interf : Gram.Entry.t (list Ast.sig_item * option Loc.t); + value implem : Gram.Entry.t (list Ast.str_item * option Loc.t); + value top_phrase : Gram.Entry.t (option Ast.str_item); + value use_file : Gram.Entry.t (list Ast.str_item * option Loc.t); + value a_CHAR : Gram.Entry.t string; + value a_FLOAT : Gram.Entry.t string; + value a_INT : Gram.Entry.t string; + value a_INT32 : Gram.Entry.t string; + value a_INT64 : Gram.Entry.t string; + value a_LABEL : Gram.Entry.t string; + value a_LIDENT : Gram.Entry.t string; + value a_NATIVEINT : Gram.Entry.t string; + value a_OPTLABEL : Gram.Entry.t string; + value a_STRING : Gram.Entry.t string; + value a_UIDENT : Gram.Entry.t string; + value a_ident : Gram.Entry.t string; + value amp_ctyp : Gram.Entry.t Ast.ctyp; + value and_ctyp : Gram.Entry.t Ast.ctyp; + value match_case : Gram.Entry.t Ast.match_case; + value match_case0 : Gram.Entry.t Ast.match_case; + value match_case_quot : Gram.Entry.t Ast.match_case; + value binding : Gram.Entry.t Ast.binding; + value binding_quot : Gram.Entry.t Ast.binding; + value rec_binding_quot : Gram.Entry.t Ast.rec_binding; + value class_declaration : Gram.Entry.t Ast.class_expr; + value class_description : Gram.Entry.t Ast.class_type; + value class_expr : Gram.Entry.t Ast.class_expr; + value class_expr_quot : Gram.Entry.t Ast.class_expr; + value class_fun_binding : Gram.Entry.t Ast.class_expr; + value class_fun_def : Gram.Entry.t Ast.class_expr; + value class_info_for_class_expr : Gram.Entry.t Ast.class_expr; + value class_info_for_class_type : Gram.Entry.t Ast.class_type; + value class_longident : Gram.Entry.t Ast.ident; + value class_longident_and_param : Gram.Entry.t Ast.class_expr; + value class_name_and_param : Gram.Entry.t (string * Ast.ctyp); + value class_sig_item : Gram.Entry.t Ast.class_sig_item; + value class_sig_item_quot : Gram.Entry.t Ast.class_sig_item; + value class_signature : Gram.Entry.t Ast.class_sig_item; + value class_str_item : Gram.Entry.t Ast.class_str_item; + value class_str_item_quot : Gram.Entry.t Ast.class_str_item; + value class_structure : Gram.Entry.t Ast.class_str_item; + value class_type : Gram.Entry.t Ast.class_type; + value class_type_declaration : Gram.Entry.t Ast.class_type; + value class_type_longident : Gram.Entry.t Ast.ident; + value class_type_longident_and_param : Gram.Entry.t Ast.class_type; + value class_type_plus : Gram.Entry.t Ast.class_type; + value class_type_quot : Gram.Entry.t Ast.class_type; + value comma_ctyp : Gram.Entry.t Ast.ctyp; + value comma_expr : Gram.Entry.t Ast.expr; + value comma_ipatt : Gram.Entry.t Ast.patt; + value comma_patt : Gram.Entry.t Ast.patt; + value comma_type_parameter : Gram.Entry.t Ast.ctyp; + value constrain : Gram.Entry.t (Ast.ctyp * Ast.ctyp); + value constructor_arg_list : Gram.Entry.t Ast.ctyp; + value constructor_declaration : Gram.Entry.t Ast.ctyp; + value constructor_declarations : Gram.Entry.t Ast.ctyp; + value ctyp : Gram.Entry.t Ast.ctyp; + value ctyp_quot : Gram.Entry.t Ast.ctyp; + value cvalue_binding : Gram.Entry.t Ast.expr; + value direction_flag : Gram.Entry.t Ast.meta_bool; + value dummy : Gram.Entry.t unit; + value eq_expr : Gram.Entry.t (string -> Ast.patt -> Ast.patt); + value expr : Gram.Entry.t Ast.expr; + value expr_eoi : Gram.Entry.t Ast.expr; + value expr_quot : Gram.Entry.t Ast.expr; + value field_expr : Gram.Entry.t Ast.rec_binding; + value field_expr_list : Gram.Entry.t Ast.rec_binding; + value fun_binding : Gram.Entry.t Ast.expr; + value fun_def : Gram.Entry.t Ast.expr; + value ident : Gram.Entry.t Ast.ident; + value ident_quot : Gram.Entry.t Ast.ident; + value ipatt : Gram.Entry.t Ast.patt; + value ipatt_tcon : Gram.Entry.t Ast.patt; + value label : Gram.Entry.t string; + value label_declaration : Gram.Entry.t Ast.ctyp; + value label_declaration_list : Gram.Entry.t Ast.ctyp; + value label_expr : Gram.Entry.t Ast.rec_binding; + value label_expr_list : Gram.Entry.t Ast.rec_binding; + value label_ipatt : Gram.Entry.t Ast.patt; + value label_ipatt_list : Gram.Entry.t Ast.patt; + value label_longident : Gram.Entry.t Ast.ident; + value label_patt : Gram.Entry.t Ast.patt; + value label_patt_list : Gram.Entry.t Ast.patt; + value labeled_ipatt : Gram.Entry.t Ast.patt; + value let_binding : Gram.Entry.t Ast.binding; + value meth_list : Gram.Entry.t (Ast.ctyp * Ast.meta_bool); + value meth_decl : Gram.Entry.t Ast.ctyp; + value module_binding : Gram.Entry.t Ast.module_binding; + value module_binding0 : Gram.Entry.t Ast.module_expr; + value module_binding_quot : Gram.Entry.t Ast.module_binding; + value module_declaration : Gram.Entry.t Ast.module_type; + value module_expr : Gram.Entry.t Ast.module_expr; + value module_expr_quot : Gram.Entry.t Ast.module_expr; + value module_longident : Gram.Entry.t Ast.ident; + value module_longident_with_app : Gram.Entry.t Ast.ident; + value module_rec_declaration : Gram.Entry.t Ast.module_binding; + value module_type : Gram.Entry.t Ast.module_type; + value module_type_quot : Gram.Entry.t Ast.module_type; + value more_ctyp : Gram.Entry.t Ast.ctyp; + value name_tags : Gram.Entry.t Ast.ctyp; + value opt_as_lident : Gram.Entry.t string; + value opt_class_self_patt : Gram.Entry.t Ast.patt; + value opt_class_self_type : Gram.Entry.t Ast.ctyp; + value opt_comma_ctyp : Gram.Entry.t Ast.ctyp; + value opt_dot_dot : Gram.Entry.t Ast.meta_bool; + value opt_eq_ctyp : Gram.Entry.t Ast.ctyp; + value opt_expr : Gram.Entry.t Ast.expr; + value opt_meth_list : Gram.Entry.t Ast.ctyp; + value opt_mutable : Gram.Entry.t Ast.meta_bool; + value opt_polyt : Gram.Entry.t Ast.ctyp; + value opt_private : Gram.Entry.t Ast.meta_bool; + value opt_rec : Gram.Entry.t Ast.meta_bool; + value opt_virtual : Gram.Entry.t Ast.meta_bool; + value opt_when_expr : Gram.Entry.t Ast.expr; + value patt : Gram.Entry.t Ast.patt; + value patt_as_patt_opt : Gram.Entry.t Ast.patt; + value patt_eoi : Gram.Entry.t Ast.patt; + value patt_quot : Gram.Entry.t Ast.patt; + value patt_tcon : Gram.Entry.t Ast.patt; + value phrase : Gram.Entry.t Ast.str_item; + value poly_type : Gram.Entry.t Ast.ctyp; + value row_field : Gram.Entry.t Ast.ctyp; + value sem_expr : Gram.Entry.t Ast.expr; + value sem_expr_for_list : Gram.Entry.t (Ast.expr -> Ast.expr); + value sem_patt : Gram.Entry.t Ast.patt; + value sem_patt_for_list : Gram.Entry.t (Ast.patt -> Ast.patt); + value semi : Gram.Entry.t unit; + value sequence : Gram.Entry.t Ast.expr; + value do_sequence : Gram.Entry.t Ast.expr; + value sig_item : Gram.Entry.t Ast.sig_item; + value sig_item_quot : Gram.Entry.t Ast.sig_item; + value sig_items : Gram.Entry.t Ast.sig_item; + value star_ctyp : Gram.Entry.t Ast.ctyp; + value str_item : Gram.Entry.t Ast.str_item; + value str_item_quot : Gram.Entry.t Ast.str_item; + value str_items : Gram.Entry.t Ast.str_item; + value type_constraint : Gram.Entry.t unit; + value type_declaration : Gram.Entry.t Ast.ctyp; + value type_ident_and_parameters : Gram.Entry.t (string * list Ast.ctyp); + value type_kind : Gram.Entry.t Ast.ctyp; + value type_longident : Gram.Entry.t Ast.ident; + value type_longident_and_parameters : Gram.Entry.t Ast.ctyp; + value type_parameter : Gram.Entry.t Ast.ctyp; + value type_parameters : Gram.Entry.t (Ast.ctyp -> Ast.ctyp); + value typevars : Gram.Entry.t Ast.ctyp; + value val_longident : Gram.Entry.t Ast.ident; + value value_let : Gram.Entry.t unit; + value value_val : Gram.Entry.t unit; + value with_constr : Gram.Entry.t Ast.with_constr; + value with_constr_quot : Gram.Entry.t Ast.with_constr; + value prefixop : Gram.Entry.t Ast.expr; + value infixop0 : Gram.Entry.t Ast.expr; + value infixop1 : Gram.Entry.t Ast.expr; + value infixop2 : Gram.Entry.t Ast.expr; + value infixop3 : Gram.Entry.t Ast.expr; + value infixop4 : Gram.Entry.t Ast.expr; +end; + +(** A signature for syntax extension (syntax -> syntax functors). *) +module type SyntaxExtension = functor (Syn : Syntax) + -> (Syntax with module Loc = Syn.Loc + and module Ast = Syn.Ast + and module Token = Syn.Token + and module Gram = Syn.Gram + and module Quotation = Syn.Quotation); + diff --git a/camlp4/Camlp4/Struct.mlpack b/camlp4/Camlp4/Struct.mlpack new file mode 100644 index 0000000..a939fe7 --- /dev/null +++ b/camlp4/Camlp4/Struct.mlpack @@ -0,0 +1,15 @@ +AstFilters +Camlp4Ast +Camlp4Ast2OCamlAst +CleanAst +CommentFilter +DynLoader +EmptyError +EmptyPrinter +FreeVars +Lexer +Loc +Quotation +Token +Grammar +DynAst diff --git a/camlp4/Camlp4/Struct/.cvsignore b/camlp4/Camlp4/Struct/.cvsignore new file mode 100644 index 0000000..262784d --- /dev/null +++ b/camlp4/Camlp4/Struct/.cvsignore @@ -0,0 +1,2 @@ +Lexer.ml +Camlp4Ast.tmp.ml diff --git a/camlp4/Camlp4/Struct/AstFilters.ml b/camlp4/Camlp4/Struct/AstFilters.ml new file mode 100644 index 0000000..665e610 --- /dev/null +++ b/camlp4/Camlp4/Struct/AstFilters.ml @@ -0,0 +1,37 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Ast : Sig.Camlp4Ast) +: Sig.AstFilters with module Ast = Ast += struct + + module Ast = Ast; + + type filter 'a = 'a -> 'a; + + value interf_filters = Queue.create (); + value fold_interf_filters f i = Queue.fold f i interf_filters; + value implem_filters = Queue.create (); + value fold_implem_filters f i = Queue.fold f i implem_filters; + value topphrase_filters = Queue.create (); + value fold_topphrase_filters f i = Queue.fold f i topphrase_filters; + + value register_sig_item_filter f = Queue.add f interf_filters; + value register_str_item_filter f = Queue.add f implem_filters; + value register_topphrase_filter f = Queue.add f topphrase_filters; +end; diff --git a/camlp4/Camlp4/Struct/Camlp4Ast.mlast b/camlp4/Camlp4/Struct/Camlp4Ast.mlast new file mode 100644 index 0000000..6c4ea3b --- /dev/null +++ b/camlp4/Camlp4/Struct/Camlp4Ast.mlast @@ -0,0 +1,543 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Loc : Sig.Loc) +: Sig.Camlp4Ast with module Loc = Loc += struct + module Loc = Loc; + + module Ast = struct + include Sig.MakeCamlp4Ast Loc; + + value safe_string_escaped s = + if String.length s > 2 && s.[0] = '\\' && s.[1] = '$' then s + else String.escaped s; + end; + + include Ast; + + external loc_of_ctyp : ctyp -> Loc.t = "%field0"; + external loc_of_patt : patt -> Loc.t = "%field0"; + external loc_of_expr : expr -> Loc.t = "%field0"; + external loc_of_module_type : module_type -> Loc.t = "%field0"; + external loc_of_module_expr : module_expr -> Loc.t = "%field0"; + external loc_of_sig_item : sig_item -> Loc.t = "%field0"; + external loc_of_str_item : str_item -> Loc.t = "%field0"; + external loc_of_class_type : class_type -> Loc.t = "%field0"; + external loc_of_class_sig_item : class_sig_item -> Loc.t = "%field0"; + external loc_of_class_expr : class_expr -> Loc.t = "%field0"; + external loc_of_class_str_item : class_str_item -> Loc.t = "%field0"; + external loc_of_with_constr : with_constr -> Loc.t = "%field0"; + external loc_of_binding : binding -> Loc.t = "%field0"; + external loc_of_rec_binding : rec_binding -> Loc.t = "%field0"; + external loc_of_module_binding : module_binding -> Loc.t = "%field0"; + external loc_of_match_case : match_case -> Loc.t = "%field0"; + external loc_of_ident : ident -> Loc.t = "%field0"; + + value ghost = Loc.ghost; + + value rec is_module_longident = + fun + [ <:ident< $_$.$i$ >> -> is_module_longident i + | <:ident< $i1$ $i2$ >> -> + is_module_longident i1 && is_module_longident i2 + | <:ident< $uid:_$ >> -> True + | _ -> False ]; + + value ident_of_expr = + let error () = + invalid_arg "ident_of_expr: this expression is not an identifier" in + let rec self = + fun + [ <:expr@_loc< $e1$ $e2$ >> -> <:ident< $self e1$ $self e2$ >> + | <:expr@_loc< $e1$.$e2$ >> -> <:ident< $self e1$.$self e2$ >> + | <:expr< $lid:_$ >> -> error () + | <:expr< $id:i$ >> -> if is_module_longident i then i else error () + | _ -> error () ] in + fun + [ <:expr< $id:i$ >> -> i + | <:expr< $_$ $_$ >> -> error () + | t -> self t ]; + + value ident_of_ctyp = + let error () = + invalid_arg "ident_of_ctyp: this type is not an identifier" in + let rec self = + fun + [ <:ctyp@_loc< $t1$ $t2$ >> -> <:ident< $self t1$ $self t2$ >> + | <:ctyp< $lid:_$ >> -> error () + | <:ctyp< $id:i$ >> -> if is_module_longident i then i else error () + | _ -> error () ] in + fun + [ <:ctyp< $id:i$ >> -> i + | t -> self t ]; + + value ident_of_patt = + let error () = + invalid_arg "ident_of_patt: this pattern is not an identifier" in + let rec self = + fun + [ <:patt@_loc< $p1$ $p2$ >> -> <:ident< $self p1$ $self p2$ >> + | <:patt< $lid:_$ >> -> error () + | <:patt< $id:i$ >> -> if is_module_longident i then i else error () + | _ -> error () ] in + fun + [ <:patt< $id:i$ >> -> i + | p -> self p ]; + + value rec is_irrefut_patt = + fun + [ <:patt< $lid:_$ >> -> True + | <:patt< () >> -> True + | <:patt< _ >> -> True + | <:patt<>> -> True (* why not *) + | <:patt< ($x$ as $y$) >> -> is_irrefut_patt x && is_irrefut_patt y + | <:patt< { $p$ } >> -> is_irrefut_patt p + | <:patt< $_$ = $p$ >> -> is_irrefut_patt p + | <:patt< $p1$; $p2$ >> -> is_irrefut_patt p1 && is_irrefut_patt p2 + | <:patt< $p1$, $p2$ >> -> is_irrefut_patt p1 && is_irrefut_patt p2 + | <:patt< $p1$ | $p2$ >> -> is_irrefut_patt p1 && is_irrefut_patt p2 (* could be more fine grained *) + | <:patt< $p1$ $p2$ >> -> is_irrefut_patt p1 && is_irrefut_patt p2 + | <:patt< ($p$ : $_$) >> -> is_irrefut_patt p + | <:patt< ($tup:pl$) >> -> is_irrefut_patt pl + | <:patt< ? $_$ >> -> True + | <:patt< ? $_$ : ($p$) >> -> is_irrefut_patt p + | <:patt< ? $_$ : ($p$ = $_$) >> -> is_irrefut_patt p + | <:patt< ~ $_$ >> -> True + | <:patt< ~ $_$ : $p$ >> -> is_irrefut_patt p + | <:patt< lazy $p$ >> -> is_irrefut_patt p + | <:patt< $id:_$ >> -> False (* here one need to know the arity of constructors *) + | <:patt< `$_$ >> | <:patt< $str:_$ >> | <:patt< $_$ .. $_$ >> | + <:patt< $flo:_$ >> | <:patt< $nativeint:_$ >> | <:patt< $int64:_$ >> | + <:patt< $int32:_$ >> | <:patt< $int:_$ >> | <:patt< $chr:_$ >> | + <:patt< #$_$ >> | <:patt< [| $_$ |] >> | <:patt< $anti:_$ >> -> False + ]; + + value rec is_constructor = + fun + [ <:ident< $_$.$i$ >> -> is_constructor i + | <:ident< $uid:_$ >> -> True + | <:ident< $lid:_$ >> | <:ident< $_$ $_$ >> -> False + | <:ident< $anti:_$ >> -> assert False ]; + + value is_patt_constructor = + fun + [ <:patt< $id:i$ >> -> is_constructor i + | <:patt< `$_$ >> -> True + | _ -> False ]; + + value rec is_expr_constructor = + fun + [ <:expr< $id:i$ >> -> is_constructor i + | <:expr< $e1$.$e2$ >> -> is_expr_constructor e1 && is_expr_constructor e2 + | <:expr< `$_$ >> -> True + | _ -> False ]; + + value rec tyOr_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$ | $tyOr_of_list ts$ >> ]; + + value rec tyAnd_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$ and $tyAnd_of_list ts$ >> ]; + + value rec tySem_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$ ; $tySem_of_list ts$ >> ]; + + value rec tyCom_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$, $tyCom_of_list ts$ >> ]; + + value rec tyAmp_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$ & $tyAmp_of_list ts$ >> ]; + + value rec tySta_of_list = + fun + [ [] -> <:ctyp@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_ctyp t in <:ctyp< $t$ * $tySta_of_list ts$ >> ]; + + value rec stSem_of_list = + fun + [ [] -> <:str_item@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_str_item t in <:str_item< $t$ ; $stSem_of_list ts$ >> ]; + + value rec sgSem_of_list = + fun + [ [] -> <:sig_item@ghost<>> + | [t] -> t + | [t::ts] -> + let _loc = loc_of_sig_item t in <:sig_item< $t$ ; $sgSem_of_list ts$ >> ]; + + value rec biAnd_of_list = + fun + [ [] -> <:binding@ghost<>> + | [b] -> b + | [b::bs] -> + let _loc = loc_of_binding b in <:binding< $b$ and $biAnd_of_list bs$ >> ]; + + value rec rbSem_of_list = + fun + [ [] -> <:rec_binding@ghost<>> + | [b] -> b + | [b::bs] -> + let _loc = loc_of_rec_binding b in + <:rec_binding< $b$; $rbSem_of_list bs$ >> ]; + + value rec wcAnd_of_list = + fun + [ [] -> <:with_constr@ghost<>> + | [w] -> w + | [w::ws] -> + let _loc = loc_of_with_constr w in + <:with_constr< $w$ and $wcAnd_of_list ws$ >> ]; + + value rec idAcc_of_list = + fun + [ [] -> assert False + | [i] -> i + | [i::is] -> + let _loc = loc_of_ident i in + <:ident< $i$ . $idAcc_of_list is$ >> ]; + + value rec idApp_of_list = + fun + [ [] -> assert False + | [i] -> i + | [i::is] -> + let _loc = loc_of_ident i in + <:ident< $i$ $idApp_of_list is$ >> ]; + + value rec mcOr_of_list = + fun + [ [] -> <:match_case@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_match_case x in + <:match_case< $x$ | $mcOr_of_list xs$ >> ]; + + value rec mbAnd_of_list = + fun + [ [] -> <:module_binding@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_module_binding x in + <:module_binding< $x$ and $mbAnd_of_list xs$ >> ]; + + value rec meApp_of_list = + fun + [ [] -> assert False + | [x] -> x + | [x::xs] -> + let _loc = loc_of_module_expr x in + <:module_expr< $x$ $meApp_of_list xs$ >> ]; + + value rec ceAnd_of_list = + fun + [ [] -> <:class_expr@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_class_expr x in + <:class_expr< $x$ and $ceAnd_of_list xs$ >> ]; + + value rec ctAnd_of_list = + fun + [ [] -> <:class_type@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_class_type x in + <:class_type< $x$ and $ctAnd_of_list xs$ >> ]; + + value rec cgSem_of_list = + fun + [ [] -> <:class_sig_item@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_class_sig_item x in + <:class_sig_item< $x$; $cgSem_of_list xs$ >> ]; + + value rec crSem_of_list = + fun + [ [] -> <:class_str_item@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_class_str_item x in + <:class_str_item< $x$; $crSem_of_list xs$ >> ]; + + value rec paSem_of_list = + fun + [ [] -> <:patt@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_patt x in + <:patt< $x$; $paSem_of_list xs$ >> ]; + + value rec paCom_of_list = + fun + [ [] -> <:patt@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_patt x in + <:patt< $x$, $paCom_of_list xs$ >> ]; + + value rec exSem_of_list = + fun + [ [] -> <:expr@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_expr x in + <:expr< $x$; $exSem_of_list xs$ >> ]; + + value rec exCom_of_list = + fun + [ [] -> <:expr@ghost<>> + | [x] -> x + | [x::xs] -> + let _loc = loc_of_expr x in + <:expr< $x$, $exCom_of_list xs$ >> ]; + + value ty_of_stl = + fun + [ (_loc, s, []) -> <:ctyp< $uid:s$ >> + | (_loc, s, tl) -> <:ctyp< $uid:s$ of $tyAnd_of_list tl$ >> ]; + + value ty_of_sbt = + fun + [ (_loc, s, True, t) -> <:ctyp< $lid:s$ : mutable $t$ >> + | (_loc, s, False, t) -> <:ctyp< $lid:s$ : $t$ >> ]; + + value bi_of_pe (p, e) = let _loc = loc_of_patt p in <:binding< $p$ = $e$ >>; + value sum_type_of_list l = tyOr_of_list (List.map ty_of_stl l); + value record_type_of_list l = tySem_of_list (List.map ty_of_sbt l); + value binding_of_pel l = biAnd_of_list (List.map bi_of_pe l); + + value rec pel_of_binding = + fun + [ <:binding< $b1$ and $b2$ >> -> pel_of_binding b1 @ pel_of_binding b2 + | <:binding< $p$ = $e$ >> -> [(p, e)] + | _ -> assert False ]; + + value rec list_of_binding x acc = + match x with + [ <:binding< $b1$ and $b2$ >> -> + list_of_binding b1 (list_of_binding b2 acc) + | t -> [t :: acc] ]; + + value rec list_of_rec_binding x acc = + match x with + [ <:rec_binding< $b1$; $b2$ >> -> + list_of_rec_binding b1 (list_of_rec_binding b2 acc) + | t -> [t :: acc] ]; + + value rec list_of_with_constr x acc = + match x with + [ <:with_constr< $w1$ and $w2$ >> -> + list_of_with_constr w1 (list_of_with_constr w2 acc) + | t -> [t :: acc] ]; + + value rec list_of_ctyp x acc = + match x with + [ <:ctyp<>> -> acc + | <:ctyp< $x$ & $y$ >> | <:ctyp< $x$, $y$ >> | + <:ctyp< $x$ * $y$ >> | <:ctyp< $x$; $y$ >> | + <:ctyp< $x$ and $y$ >> | <:ctyp< $x$ | $y$ >> -> + list_of_ctyp x (list_of_ctyp y acc) + | x -> [x :: acc] ]; + + value rec list_of_patt x acc = + match x with + [ <:patt<>> -> acc + | <:patt< $x$, $y$ >> | <:patt< $x$; $y$ >> -> + list_of_patt x (list_of_patt y acc) + | x -> [x :: acc] ]; + + value rec list_of_expr x acc = + match x with + [ <:expr<>> -> acc + | <:expr< $x$, $y$ >> | <:expr< $x$; $y$ >> -> + list_of_expr x (list_of_expr y acc) + | x -> [x :: acc] ]; + + value rec list_of_str_item x acc = + match x with + [ <:str_item<>> -> acc + | <:str_item< $x$; $y$ >> -> + list_of_str_item x (list_of_str_item y acc) + | x -> [x :: acc] ]; + + value rec list_of_sig_item x acc = + match x with + [ <:sig_item<>> -> acc + | <:sig_item< $x$; $y$ >> -> + list_of_sig_item x (list_of_sig_item y acc) + | x -> [x :: acc] ]; + + value rec list_of_class_sig_item x acc = + match x with + [ <:class_sig_item<>> -> acc + | <:class_sig_item< $x$; $y$ >> -> + list_of_class_sig_item x (list_of_class_sig_item y acc) + | x -> [x :: acc] ]; + + value rec list_of_class_str_item x acc = + match x with + [ <:class_str_item<>> -> acc + | <:class_str_item< $x$; $y$ >> -> + list_of_class_str_item x (list_of_class_str_item y acc) + | x -> [x :: acc] ]; + + value rec list_of_class_type x acc = + match x with + [ <:class_type< $x$ and $y$ >> -> + list_of_class_type x (list_of_class_type y acc) + | x -> [x :: acc] ]; + + value rec list_of_class_expr x acc = + match x with + [ <:class_expr< $x$ and $y$ >> -> + list_of_class_expr x (list_of_class_expr y acc) + | x -> [x :: acc] ]; + + value rec list_of_module_expr x acc = + match x with + [ <:module_expr< $x$ $y$ >> -> + list_of_module_expr x (list_of_module_expr y acc) + | x -> [x :: acc] ]; + + value rec list_of_match_case x acc = + match x with + [ <:match_case<>> -> acc + | <:match_case< $x$ | $y$ >> -> + list_of_match_case x (list_of_match_case y acc) + | x -> [x :: acc] ]; + + value rec list_of_ident x acc = + match x with + [ <:ident< $x$ . $y$ >> | <:ident< $x$ $y$ >> -> + list_of_ident x (list_of_ident y acc) + | x -> [x :: acc] ]; + + value rec list_of_module_binding x acc = + match x with + [ <:module_binding< $x$ and $y$ >> -> + list_of_module_binding x (list_of_module_binding y acc) + | x -> [x :: acc] ]; + + module Camlp4Trash = struct + INCLUDE "camlp4/Camlp4/Camlp4Ast.partial.ml"; + end; + + module Meta = struct + + module type META_LOC = sig + (** The first location is where to put the returned pattern. + Generally it's _loc to match with <:patt< ... >> quotations. + The second location is the one to treat. *) + value meta_loc_patt : Loc.t -> Loc.t -> Ast.patt; + (** The first location is where to put the returned expression. + Generally it's _loc to match with <:expr< ... >> quotations. + The second location is the one to treat. *) + value meta_loc_expr : Loc.t -> Loc.t -> Ast.expr; + end; + + module MetaLoc = struct + value meta_loc_patt _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location in + <:patt< Loc.of_tuple + ($`str:a$, $`int:b$, $`int:c$, $`int:d$, + $`int:e$, $`int:f$, $`int:g$, + $if h then <:patt< True >> else <:patt< False >> $) >>; + value meta_loc_expr _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location in + <:expr< Loc.of_tuple + ($`str:a$, $`int:b$, $`int:c$, $`int:d$, + $`int:e$, $`int:f$, $`int:g$, + $if h then <:expr< True >> else <:expr< False >> $) >>; + end; + + module MetaGhostLoc = struct + value meta_loc_patt _loc _ = <:patt< Loc.ghost >>; + value meta_loc_expr _loc _ = <:expr< Loc.ghost >>; + end; + + module MetaLocVar = struct + value meta_loc_patt _loc _ = <:patt< $lid:Loc.name.val$ >>; + value meta_loc_expr _loc _ = <:expr< $lid:Loc.name.val$ >>; + end; + + module Make (MetaLoc : META_LOC) = struct + open MetaLoc; + + value meta_loc = meta_loc_expr; + module Expr = Camlp4Filters.MetaGeneratorExpr Ast; + value meta_loc = meta_loc_patt; + module Patt = Camlp4Filters.MetaGeneratorPatt Ast; + end; + + end; + + class map = Camlp4MapGenerator.generated; + + class fold = Camlp4FoldGenerator.generated; + + value map_expr f = object + inherit map as super; + method expr x = f (super#expr x); + end; + value map_patt f = object + inherit map as super; + method patt x = f (super#patt x); + end; + value map_ctyp f = object + inherit map as super; + method ctyp x = f (super#ctyp x); + end; + value map_str_item f = object + inherit map as super; + method str_item x = f (super#str_item x); + end; + value map_sig_item f = object + inherit map as super; + method sig_item x = f (super#sig_item x); + end; + value map_loc f = object + inherit map as super; + method loc x = f (super#loc x); + end; +end; diff --git a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml new file mode 100644 index 0000000..fa6deaa --- /dev/null +++ b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml @@ -0,0 +1,1047 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +module Make (Ast : Sig.Camlp4Ast) = struct + open Format; + open Camlp4_import.Parsetree; + open Camlp4_import.Longident; + open Camlp4_import.Asttypes; + open Ast; + + value constructors_arity () = + debug ast2pt "constructors_arity: %b@." Camlp4_config.constructors_arity.val in + Camlp4_config.constructors_arity.val; + + value error loc str = Loc.raise loc (Failure str); + + value char_of_char_token loc s = + try Token.Eval.char s with [ Failure _ as exn -> Loc.raise loc exn ] + ; + + value string_of_string_token loc s = + try Token.Eval.string s + with [ Failure _ as exn -> Loc.raise loc exn ] + ; + + value remove_underscores s = + let l = String.length s in + let rec remove src dst = + if src >= l then + if dst >= l then s else String.sub s 0 dst + else + match s.[src] with + [ '_' -> remove (src + 1) dst + | c -> do { s.[dst] := c; remove (src + 1) (dst + 1) } ] + in remove 0 0 + ; + + value mkloc = Loc.to_ocaml_location; + value mkghloc loc = Loc.to_ocaml_location (Loc.ghostify loc); + + value mktyp loc d = {ptyp_desc = d; ptyp_loc = mkloc loc}; + value mkpat loc d = {ppat_desc = d; ppat_loc = mkloc loc}; + value mkghpat loc d = {ppat_desc = d; ppat_loc = mkghloc loc}; + value mkexp loc d = {pexp_desc = d; pexp_loc = mkloc loc}; + value mkmty loc d = {pmty_desc = d; pmty_loc = mkloc loc}; + value mksig loc d = {psig_desc = d; psig_loc = mkloc loc}; + value mkmod loc d = {pmod_desc = d; pmod_loc = mkloc loc}; + value mkstr loc d = {pstr_desc = d; pstr_loc = mkloc loc}; + value mkfield loc d = {pfield_desc = d; pfield_loc = mkloc loc}; + value mkcty loc d = {pcty_desc = d; pcty_loc = mkloc loc}; + value mkpcl loc d = {pcl_desc = d; pcl_loc = mkloc loc}; + value mkpolytype t = + match t.ptyp_desc with + [ Ptyp_poly _ _ -> t + | _ -> { (t) with ptyp_desc = Ptyp_poly [] t } ] + ; + + value mb2b = + fun + [ Ast.BTrue -> True + | Ast.BFalse -> False + | Ast.BAnt _ -> assert False ]; + + value mkvirtual m = if mb2b m then Virtual else Concrete; + + value lident s = Lident s; + value ldot l s = Ldot l s; + value lapply l s = Lapply l s; + + value conv_con = + let t = Hashtbl.create 73 in + do { + List.iter (fun (s, s') -> Hashtbl.add t s s') + [("True", "true"); ("False", "false"); (" True", "True"); + (" False", "False")]; + fun s -> try Hashtbl.find t s with [ Not_found -> s ] + } + ; + + value conv_lab = + let t = Hashtbl.create 73 in + do { + List.iter (fun (s, s') -> Hashtbl.add t s s') [("val", "contents")]; + fun s -> try Hashtbl.find t s with [ Not_found -> s ] + } + ; + + value array_function str name = + ldot (lident str) (if Camlp4_config.unsafe.val then "unsafe_" ^ name else name) + ; + + value mkrf = + fun + [ Ast.BTrue -> Recursive + | Ast.BFalse -> Nonrecursive + | Ast.BAnt _ -> assert False ]; + + value mkli s = loop lident + where rec loop f = + fun + [ [i :: il] -> loop (ldot (f i)) il + | [] -> f s ] + ; + + value rec ctyp_fa al = + fun + [ TyApp _ f a -> ctyp_fa [a :: al] f + | f -> (f, al) ] + ; + + value ident_tag ?(conv_lid = fun x -> x) i = + + let rec self i acc = + match i with + [ <:ident< $i1$.$i2$ >> -> + self i2 (Some (self i1 acc)) + | <:ident< $i1$ $i2$ >> -> + let i' = Lapply (fst (self i1 None)) (fst (self i2 None)) in + let x = + match acc with + [ None -> i' + | _ -> error (loc_of_ident i) "invalid long identifier" ] + in (x, `app) + | <:ident< $uid:s$ >> -> + let x = + match acc with + [ None -> lident s + | Some (acc, `uident | `app) -> ldot acc s + | _ -> error (loc_of_ident i) "invalid long identifier" ] + in (x, `uident) + | <:ident< $lid:s$ >> -> + let x = + match acc with + [ None -> lident (conv_lid s) + | Some (acc, `uident | `app) -> ldot acc (conv_lid s) + | _ -> error (loc_of_ident i) "invalid long identifier" ] + in (x, `lident) + | _ -> error (loc_of_ident i) "invalid long identifier" ] + in self i None; + + value ident ?conv_lid i = fst (ident_tag ?conv_lid i); + + value long_lident msg i = + match ident_tag i with + [ (i, `lident) -> i + | _ -> error (loc_of_ident i) msg ] + ; + + value long_type_ident = long_lident "invalid long identifier type"; + value long_class_ident = long_lident "invalid class name"; + + value long_uident ?(conv_con = fun x -> x) i = + match ident_tag i with + [ (Ldot i s, `uident) -> ldot i (conv_con s) + | (Lident s, `uident) -> lident (conv_con s) + | (i, `app) -> i + | _ -> error (loc_of_ident i) "uppercase identifier expected" ] + ; + + value rec ctyp_long_id_prefix t = + match t with + [ <:ctyp< $id:i$ >> -> ident i + | <:ctyp< $m1$ $m2$ >> -> + let li1 = ctyp_long_id_prefix m1 in + let li2 = ctyp_long_id_prefix m2 in + Lapply li1 li2 + | t -> error (loc_of_ctyp t) "invalid module expression" ] + ; + + value ctyp_long_id t = + match t with + [ <:ctyp< $id:i$ >> -> + (False, long_type_ident i) + | TyApp loc _ _ -> + error loc "invalid type name" + | TyCls _ i -> (True, ident i) + | t -> error (loc_of_ctyp t) "invalid type" ] + ; + + value rec ty_var_list_of_ctyp = + fun + [ <:ctyp< $t1$ $t2$ >> -> ty_var_list_of_ctyp t1 @ ty_var_list_of_ctyp t2 + | <:ctyp< '$s$ >> -> [s] + | _ -> assert False ]; + + value rec ctyp = + fun + [ TyId loc i -> + let li = long_type_ident i in + mktyp loc (Ptyp_constr li []) + | TyAli loc t1 t2 -> + let (t, i) = + match (t1, t2) with + [ (t, TyQuo _ s) -> (t, s) + | (TyQuo _ s, t) -> (t, s) + | _ -> error loc "invalid alias type" ] + in + mktyp loc (Ptyp_alias (ctyp t) i) + | TyAny loc -> mktyp loc Ptyp_any + | TyApp loc _ _ as f -> + let (f, al) = ctyp_fa [] f in + let (is_cls, li) = ctyp_long_id f in + if is_cls then mktyp loc (Ptyp_class li (List.map ctyp al) []) + else mktyp loc (Ptyp_constr li (List.map ctyp al)) + | TyArr loc (TyLab _ lab t1) t2 -> + mktyp loc (Ptyp_arrow lab (ctyp t1) (ctyp t2)) + | TyArr loc (TyOlb loc1 lab t1) t2 -> + let t1 = TyApp loc1 <:ctyp@loc1< option >> t1 in + mktyp loc (Ptyp_arrow ("?" ^ lab) (ctyp t1) (ctyp t2)) + | TyArr loc t1 t2 -> mktyp loc (Ptyp_arrow "" (ctyp t1) (ctyp t2)) + | <:ctyp@loc< < $fl$ > >> -> mktyp loc (Ptyp_object (meth_list fl [])) + | <:ctyp@loc< < $fl$ .. > >> -> + mktyp loc (Ptyp_object (meth_list fl [mkfield loc Pfield_var])) + | TyCls loc id -> + mktyp loc (Ptyp_class (ident id) [] []) + | TyLab loc _ _ -> error loc "labelled type not allowed here" + | TyMan loc _ _ -> error loc "manifest type not allowed here" + | TyOlb loc _ _ -> error loc "labelled type not allowed here" + | TyPol loc t1 t2 -> mktyp loc (Ptyp_poly (ty_var_list_of_ctyp t1) (ctyp t2)) + | TyQuo loc s -> mktyp loc (Ptyp_var s) + | TyRec loc _ -> error loc "record type not allowed here" + | TySum loc _ -> error loc "sum type not allowed here" + | TyPrv loc _ -> error loc "private type not allowed here" + | TyMut loc _ -> error loc "mutable type not allowed here" + | TyOr loc _ _ -> error loc "type1 | type2 not allowed here" + | TyAnd loc _ _ -> error loc "type1 and type2 not allowed here" + | TyOf loc _ _ -> error loc "type1 of type2 not allowed here" + | TyCol loc _ _ -> error loc "type1 : type2 not allowed here" + | TySem loc _ _ -> error loc "type1 ; type2 not allowed here" + | <:ctyp@loc< ($t1$ * $t2$) >> -> + mktyp loc (Ptyp_tuple (List.map ctyp (list_of_ctyp t1 (list_of_ctyp t2 [])))) + | <:ctyp@loc< [ = $t$ ] >> -> mktyp loc (Ptyp_variant (row_field t) True None) + | <:ctyp@loc< [ > $t$ ] >> -> mktyp loc (Ptyp_variant (row_field t) False None) + | <:ctyp@loc< [ < $t$ ] >> -> mktyp loc (Ptyp_variant (row_field t) True (Some [])) + | <:ctyp@loc< [ < $t$ > $t'$ ] >> -> + mktyp loc (Ptyp_variant (row_field t) True (Some (name_tags t'))) + | TyAnt loc _ -> error loc "antiquotation not allowed here" + | TyOfAmp _ _ _ |TyAmp _ _ _ |TySta _ _ _ | + TyCom _ _ _ |TyVrn _ _ |TyQuM _ _ |TyQuP _ _ |TyDcl _ _ _ _ _ | + TyObj _ _ (BAnt _) | TyNil _ | TyTup _ _ -> + assert False ] + and row_field = fun + [ <:ctyp<>> -> [] + | <:ctyp< `$i$ >> -> [Rtag i True []] + | <:ctyp< `$i$ of & $t$ >> -> [Rtag i True (List.map ctyp (list_of_ctyp t []))] + | <:ctyp< `$i$ of $t$ >> -> [Rtag i False (List.map ctyp (list_of_ctyp t []))] + | <:ctyp< $t1$ | $t2$ >> -> row_field t1 @ row_field t2 + | t -> [Rinherit (ctyp t)] ] + and name_tags = fun + [ <:ctyp< $t1$ $t2$ >> -> name_tags t1 @ name_tags t2 + | <:ctyp< `$s$ >> -> [s] + | _ -> assert False ] + and meth_list fl acc = + match fl with + [ <:ctyp<>> -> acc + | <:ctyp< $t1$; $t2$ >> -> meth_list t1 (meth_list t2 acc) + | <:ctyp@loc< $lid:lab$ : $t$ >> -> + [mkfield loc (Pfield lab (mkpolytype (ctyp t))) :: acc] + | _ -> assert False ] + ; + + value mktype loc tl cl tk tp tm = + let (params, variance) = List.split tl in + {ptype_params = params; ptype_cstrs = cl; ptype_kind = tk; + ptype_private = tp; ptype_manifest = tm; ptype_loc = mkloc loc; + ptype_variance = variance} + ; + value mkprivate' m = if m then Private else Public; + value mkprivate m = mkprivate' (mb2b m); + value mktrecord = + fun + [ <:ctyp@loc< $lid:s$ : mutable $t$ >> -> + (s, Mutable, mkpolytype (ctyp t), mkloc loc) + | <:ctyp@loc< $lid:s$ : $t$ >> -> + (s, Immutable, mkpolytype (ctyp t), mkloc loc) + | _ -> assert False (*FIXME*) ]; + value mkvariant = + fun + [ <:ctyp@loc< $uid:s$ >> -> (conv_con s, [], mkloc loc) + | <:ctyp@loc< $uid:s$ of $t$ >> -> + (conv_con s, List.map ctyp (list_of_ctyp t []), mkloc loc) + | _ -> assert False (*FIXME*) ]; + value rec type_decl tl cl loc m pflag = + fun + [ <:ctyp< $t1$ == $t2$ >> -> + type_decl tl cl loc (Some (ctyp t1)) pflag t2 + | <:ctyp< private $t$ >> -> + type_decl tl cl loc m True t + | <:ctyp< { $t$ } >> -> + mktype loc tl cl + (Ptype_record (List.map mktrecord (list_of_ctyp t []))) (mkprivate' pflag) m + | <:ctyp< [ $t$ ] >> -> + mktype loc tl cl + (Ptype_variant (List.map mkvariant (list_of_ctyp t []))) (mkprivate' pflag) m + | t -> + if m <> None then + error loc "only one manifest type allowed by definition" else + let m = + match t with + [ <:ctyp<>> -> None + | _ -> Some (ctyp t) ] + in + mktype loc tl cl Ptype_abstract (mkprivate' pflag) m ] + ; + + value type_decl tl cl t = type_decl tl cl (loc_of_ctyp t) None False t; + + value mkvalue_desc t p = {pval_type = ctyp t; pval_prim = p}; + + value rec list_of_meta_list = + fun + [ Ast.LNil -> [] + | Ast.LCons x xs -> [x :: list_of_meta_list xs] + | Ast.LAnt _ -> assert False ]; + + value mkmutable m = if mb2b m then Mutable else Immutable; + + value paolab lab p = + match (lab, p) with + [ ("", <:patt< $lid:i$ >> | <:patt< ($lid:i$ : $_$) >>) -> i + | ("", p) -> error (loc_of_patt p) "bad ast in label" + | _ -> lab ] + ; + + value opt_private_ctyp = + fun + [ <:ctyp< private $t$ >> -> (Ptype_abstract, Private, ctyp t) + | t -> (Ptype_abstract, Public, ctyp t) ]; + + value rec type_parameters t acc = + match t with + [ <:ctyp< $t1$ $t2$ >> -> type_parameters t1 (type_parameters t2 acc) + | <:ctyp< +'$s$ >> -> [(s, (True, False)) :: acc] + | <:ctyp< -'$s$ >> -> [(s, (False, True)) :: acc] + | <:ctyp< '$s$ >> -> [(s, (False, False)) :: acc] + | _ -> assert False ]; + + value rec class_parameters t acc = + match t with + [ <:ctyp< $t1$, $t2$ >> -> class_parameters t1 (class_parameters t2 acc) + | <:ctyp< +'$s$ >> -> [(s, (True, False)) :: acc] + | <:ctyp< -'$s$ >> -> [(s, (False, True)) :: acc] + | <:ctyp< '$s$ >> -> [(s, (False, False)) :: acc] + | _ -> assert False ]; + + value rec type_parameters_and_type_name t acc = + match t with + [ <:ctyp< $t1$ $t2$ >> -> + type_parameters_and_type_name t1 + (type_parameters t2 acc) + | <:ctyp< $id:i$ >> -> (ident i, acc) + | _ -> assert False ]; + + value rec mkwithc wc acc = + match wc with + [ WcNil _ -> acc + | WcTyp loc id_tpl ct -> + let (id, tpl) = type_parameters_and_type_name id_tpl [] in + let (params, variance) = List.split tpl in + let (kind, priv, ct) = opt_private_ctyp ct in + [(id, + Pwith_type + {ptype_params = params; ptype_cstrs = []; + ptype_kind = kind; + ptype_private = priv; + ptype_manifest = Some ct; + ptype_loc = mkloc loc; ptype_variance = variance}) :: acc] + | WcMod _ i1 i2 -> + [(long_uident i1, Pwith_module (long_uident i2)) :: acc] + | <:with_constr< $wc1$ and $wc2$ >> -> mkwithc wc1 (mkwithc wc2 acc) + | <:with_constr@loc< $anti:_$ >> -> + error loc "bad with constraint (antiquotation)" ]; + + value rec patt_fa al = + fun + [ PaApp _ f a -> patt_fa [a :: al] f + | f -> (f, al) ] + ; + + value rec deep_mkrangepat loc c1 c2 = + if c1 = c2 then mkghpat loc (Ppat_constant (Const_char c1)) + else + mkghpat loc + (Ppat_or (mkghpat loc (Ppat_constant (Const_char c1))) + (deep_mkrangepat loc (Char.chr (Char.code c1 + 1)) c2)) + ; + + value rec mkrangepat loc c1 c2 = + if c1 > c2 then mkrangepat loc c2 c1 + else if c1 = c2 then mkpat loc (Ppat_constant (Const_char c1)) + else + mkpat loc + (Ppat_or (mkghpat loc (Ppat_constant (Const_char c1))) + (deep_mkrangepat loc (Char.chr (Char.code c1 + 1)) c2)) + ; + + value rec patt = + fun + [ <:patt@loc< $lid:s$ >> -> mkpat loc (Ppat_var s) + | <:patt@loc< $id:i$ >> -> + let p = Ppat_construct (long_uident ~conv_con i) + None (constructors_arity ()) + in mkpat loc p + | PaAli loc p1 p2 -> + let (p, i) = + match (p1, p2) with + [ (p, <:patt< $lid:s$ >>) -> (p, s) + | (<:patt< $lid:s$ >>, p) -> (p, s) + | _ -> error loc "invalid alias pattern" ] + in + mkpat loc (Ppat_alias (patt p) i) + | PaAnt loc _ -> error loc "antiquotation not allowed here" + | PaAny loc -> mkpat loc Ppat_any + | <:patt@loc< $uid:s$ ($tup:<:patt@loc_any< _ >>$) >> -> + mkpat loc (Ppat_construct (lident (conv_con s)) + (Some (mkpat loc_any Ppat_any)) False) + | PaApp loc _ _ as f -> + let (f, al) = patt_fa [] f in + let al = List.map patt al in + match (patt f).ppat_desc with + [ Ppat_construct li None _ -> + if constructors_arity () then + mkpat loc (Ppat_construct li (Some (mkpat loc (Ppat_tuple al))) True) + else + let a = + match al with + [ [a] -> a + | _ -> mkpat loc (Ppat_tuple al) ] + in + mkpat loc (Ppat_construct li (Some a) False) + | Ppat_variant s None -> + let a = + if constructors_arity () then + mkpat loc (Ppat_tuple al) + else + match al with + [ [a] -> a + | _ -> mkpat loc (Ppat_tuple al) ] + in mkpat loc (Ppat_variant s (Some a)) + | _ -> + error (loc_of_patt f) + "this is not a constructor, it cannot be applied in a pattern" ] + | PaArr loc p -> mkpat loc (Ppat_array (List.map patt (list_of_patt p []))) + | PaChr loc s -> + mkpat loc (Ppat_constant (Const_char (char_of_char_token loc s))) + | PaInt loc s -> + let i = try int_of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int" + ] in mkpat loc (Ppat_constant (Const_int i)) + | PaInt32 loc s -> + let i32 = try Int32.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int32" + ] in mkpat loc (Ppat_constant (Const_int32 i32)) + | PaInt64 loc s -> + let i64 = try Int64.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int64" + ] in mkpat loc (Ppat_constant (Const_int64 i64)) + | PaNativeInt loc s -> + let nati = try Nativeint.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type nativeint" + ] in mkpat loc (Ppat_constant (Const_nativeint nati)) + | PaFlo loc s -> mkpat loc (Ppat_constant (Const_float (remove_underscores s))) + | PaLab loc _ _ -> error loc "labeled pattern not allowed here" + | PaOlb loc _ _ | PaOlbi loc _ _ _ -> error loc "labeled pattern not allowed here" + | PaOrp loc p1 p2 -> mkpat loc (Ppat_or (patt p1) (patt p2)) + | PaRng loc p1 p2 -> + match (p1, p2) with + [ (PaChr loc1 c1, PaChr loc2 c2) -> + let c1 = char_of_char_token loc1 c1 in + let c2 = char_of_char_token loc2 c2 in + mkrangepat loc c1 c2 + | _ -> error loc "range pattern allowed only for characters" ] + | PaRec loc p -> + mkpat loc (Ppat_record (List.map mklabpat (list_of_patt p []))) + | PaStr loc s -> + mkpat loc (Ppat_constant (Const_string (string_of_string_token loc s))) + | <:patt@loc< ($p1$, $p2$) >> -> + mkpat loc (Ppat_tuple + (List.map patt (list_of_patt p1 (list_of_patt p2 [])))) + | <:patt@loc< ($tup:_$) >> -> error loc "singleton tuple pattern" + | PaTyc loc p t -> mkpat loc (Ppat_constraint (patt p) (ctyp t)) + | PaTyp loc i -> mkpat loc (Ppat_type (long_type_ident i)) + | PaVrn loc s -> mkpat loc (Ppat_variant s None) + | PaLaz loc p -> mkpat loc (Ppat_lazy (patt p)) + | PaEq _ _ _ | PaSem _ _ _ | PaCom _ _ _ | PaNil _ as p -> + error (loc_of_patt p) "invalid pattern" ] + and mklabpat = + fun + [ <:patt< $i$ = $p$ >> -> (ident ~conv_lid:conv_lab i, patt p) + | p -> error (loc_of_patt p) "invalid pattern" ]; + + value rec expr_fa al = + fun + [ ExApp _ f a -> expr_fa [a :: al] f + | f -> (f, al) ] + ; + + value rec class_expr_fa al = + fun + [ CeApp _ ce a -> class_expr_fa [a :: al] ce + | ce -> (ce, al) ] + ; + + + value rec sep_expr_acc l = + fun + [ ExAcc _ e1 e2 -> sep_expr_acc (sep_expr_acc l e2) e1 + | <:expr@loc< $uid:s$ >> as e -> + match l with + [ [] -> [(loc, [], e)] + | [(loc', sl, e) :: l] -> [(Loc.merge loc loc', [s :: sl], e) :: l] ] + | <:expr< $id:(<:ident< $_$.$_$ >> as i)$ >> -> + let rec normalize_acc = + fun + [ <:ident@_loc< $i1$.$i2$ >> -> + <:expr< $normalize_acc i1$.$normalize_acc i2$ >> + | <:ident@_loc< $i1$ $i2$ >> -> + <:expr< $normalize_acc i1$ $normalize_acc i2$ >> + | <:ident@_loc< $anti:_$ >> | <:ident@_loc< $uid:_$ >> | + <:ident@_loc< $lid:_$ >> as i -> <:expr< $id:i$ >> ] + in sep_expr_acc l (normalize_acc i) + | e -> [(loc_of_expr e, [], e) :: l] ] + ; + + value list_of_opt_ctyp ot acc = + match ot with + [ <:ctyp<>> -> acc + | t -> list_of_ctyp t acc ]; + + value rec expr = + fun + [ <:expr@loc< $x$.val >> -> + mkexp loc + (Pexp_apply (mkexp loc (Pexp_ident (Lident "!"))) [("", expr x)]) + | ExAcc loc _ _ | <:expr@loc< $id:<:ident< $_$ . $_$ >>$ >> as e -> + let (e, l) = + match sep_expr_acc [] e with + [ [(loc, ml, <:expr< $uid:s$ >>) :: l] -> + let ca = constructors_arity () in + (mkexp loc (Pexp_construct (mkli (conv_con s) ml) None ca), l) + | [(loc, ml, <:expr< $lid:s$ >>) :: l] -> + (mkexp loc (Pexp_ident (mkli s ml)), l) + | [(_, [], e) :: l] -> (expr e, l) + | _ -> error loc "bad ast in expression" ] + in + let (_, e) = + List.fold_left + (fun (loc_bp, e1) (loc_ep, ml, e2) -> + match e2 with + [ <:expr< $lid:s$ >> -> + let loc = Loc.merge loc_bp loc_ep + in (loc, mkexp loc (Pexp_field e1 (mkli (conv_lab s) ml))) + | _ -> error (loc_of_expr e2) "lowercase identifier expected" ]) + (loc, e) l + in + e + | ExAnt loc _ -> error loc "antiquotation not allowed here" + | ExApp loc _ _ as f -> + let (f, al) = expr_fa [] f in + let al = List.map label_expr al in + match (expr f).pexp_desc with + [ Pexp_construct li None _ -> + let al = List.map snd al in + if constructors_arity () then + mkexp loc (Pexp_construct li (Some (mkexp loc (Pexp_tuple al))) True) + else + let a = + match al with + [ [a] -> a + | _ -> mkexp loc (Pexp_tuple al) ] + in + mkexp loc (Pexp_construct li (Some a) False) + | Pexp_variant s None -> + let al = List.map snd al in + let a = + if constructors_arity () then + mkexp loc (Pexp_tuple al) + else + match al with + [ [a] -> a + | _ -> mkexp loc (Pexp_tuple al) ] + in mkexp loc (Pexp_variant s (Some a)) + | _ -> mkexp loc (Pexp_apply (expr f) al) ] + | ExAre loc e1 e2 -> + mkexp loc + (Pexp_apply (mkexp loc (Pexp_ident (array_function "Array" "get"))) + [("", expr e1); ("", expr e2)]) + | ExArr loc e -> mkexp loc (Pexp_array (List.map expr (list_of_expr e []))) + | ExAsf loc -> mkexp loc Pexp_assertfalse + | ExAss loc e v -> + let e = + match e with + [ <:expr@loc< $x$.val >> -> + Pexp_apply (mkexp loc (Pexp_ident (Lident ":="))) + [("", expr x); ("", expr v)] + | ExAcc loc _ _ -> + match (expr e).pexp_desc with + [ Pexp_field e lab -> Pexp_setfield e lab (expr v) + | _ -> error loc "bad record access" ] + | ExAre _ e1 e2 -> + Pexp_apply (mkexp loc (Pexp_ident (array_function "Array" "set"))) + [("", expr e1); ("", expr e2); ("", expr v)] + | <:expr< $lid:lab$ >> -> Pexp_setinstvar lab (expr v) + | ExSte _ e1 e2 -> + Pexp_apply + (mkexp loc (Pexp_ident (array_function "String" "set"))) + [("", expr e1); ("", expr e2); ("", expr v)] + | _ -> error loc "bad left part of assignment" ] + in + mkexp loc e + | ExAsr loc e -> mkexp loc (Pexp_assert (expr e)) + | ExChr loc s -> + mkexp loc (Pexp_constant (Const_char (char_of_char_token loc s))) + | ExCoe loc e t1 t2 -> + let t1 = + match t1 with + [ <:ctyp<>> -> None + | t -> Some (ctyp t) ] in + mkexp loc (Pexp_constraint (expr e) t1 (Some (ctyp t2))) + | ExFlo loc s -> mkexp loc (Pexp_constant (Const_float (remove_underscores s))) + | ExFor loc i e1 e2 df el -> + let e3 = ExSeq loc el in + let df = if mb2b df then Upto else Downto in + mkexp loc (Pexp_for i (expr e1) (expr e2) df (expr e3)) + | <:expr@loc< fun [ $PaLab _ lab po$ when $w$ -> $e$ ] >> -> + mkexp loc + (Pexp_function lab None + [(patt_of_lab loc lab po, when_expr e w)]) + | <:expr@loc< fun [ $PaOlbi _ lab p e1$ when $w$ -> $e2$ ] >> -> + let lab = paolab lab p in + mkexp loc + (Pexp_function ("?" ^ lab) (Some (expr e1)) [(patt p, when_expr e2 w)]) + | <:expr@loc< fun [ $PaOlb _ lab p$ when $w$ -> $e$ ] >> -> + let lab = paolab lab p in + mkexp loc + (Pexp_function ("?" ^ lab) None [(patt_of_lab loc lab p, when_expr e w)]) + | ExFun loc a -> mkexp loc (Pexp_function "" None (match_case a [])) + | ExIfe loc e1 e2 e3 -> + mkexp loc (Pexp_ifthenelse (expr e1) (expr e2) (Some (expr e3))) + | ExInt loc s -> + let i = try int_of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int" + ] in mkexp loc (Pexp_constant (Const_int i)) + | ExInt32 loc s -> + let i32 = try Int32.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int32" + ] in mkexp loc (Pexp_constant (Const_int32 i32)) + | ExInt64 loc s -> + let i64 = try Int64.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type int64" + ] in mkexp loc (Pexp_constant (Const_int64 i64)) + | ExNativeInt loc s -> + let nati = try Nativeint.of_string s with [ + Failure _ -> error loc "Integer literal exceeds the range of representable integers of type nativeint" + ] in mkexp loc (Pexp_constant (Const_nativeint nati)) + | ExLab loc _ _ -> error loc "labeled expression not allowed here" + | ExLaz loc e -> mkexp loc (Pexp_lazy (expr e)) + | ExLet loc rf bi e -> + mkexp loc (Pexp_let (mkrf rf) (binding bi []) (expr e)) + | ExLmd loc i me e -> mkexp loc (Pexp_letmodule i (module_expr me) (expr e)) + | ExMat loc e a -> mkexp loc (Pexp_match (expr e) (match_case a [])) + | ExNew loc id -> mkexp loc (Pexp_new (long_type_ident id)) + | ExObj loc po cfl -> + let p = + match po with + [ <:patt<>> -> <:patt@loc< _ >> + | p -> p ] + in + let cil = class_str_item cfl [] in + mkexp loc (Pexp_object (patt p, cil)) + | ExOlb loc _ _ -> error loc "labeled expression not allowed here" + | ExOvr loc iel -> mkexp loc (Pexp_override (mkideexp iel [])) + | ExRec loc lel eo -> + match lel with + [ <:rec_binding<>> -> error loc "empty record" + | _ -> + let eo = + match eo with + [ <:expr<>> -> None + | e -> Some (expr e) ] in + mkexp loc (Pexp_record (mklabexp lel []) eo) ] + | ExSeq _loc e -> + let rec loop = + fun + [ [] -> expr <:expr< () >> + | [e] -> expr e + | [e :: el] -> + let _loc = Loc.merge (loc_of_expr e) _loc in + mkexp _loc (Pexp_sequence (expr e) (loop el)) ] + in + loop (list_of_expr e []) + | ExSnd loc e s -> mkexp loc (Pexp_send (expr e) s) + | ExSte loc e1 e2 -> + mkexp loc + (Pexp_apply (mkexp loc (Pexp_ident (array_function "String" "get"))) + [("", expr e1); ("", expr e2)]) + | ExStr loc s -> + mkexp loc (Pexp_constant (Const_string (string_of_string_token loc s))) + | ExTry loc e a -> mkexp loc (Pexp_try (expr e) (match_case a [])) + | <:expr@loc< ($e1$, $e2$) >> -> + mkexp loc (Pexp_tuple (List.map expr (list_of_expr e1 (list_of_expr e2 [])))) + | <:expr@loc< ($tup:_$) >> -> error loc "singleton tuple" + | ExTyc loc e t -> mkexp loc (Pexp_constraint (expr e) (Some (ctyp t)) None) + | <:expr@loc< () >> -> + mkexp loc (Pexp_construct (lident "()") None True) + | <:expr@loc< $lid:s$ >> -> + mkexp loc (Pexp_ident (lident s)) + | <:expr@loc< $uid:s$ >> -> + (* let ca = constructors_arity () in *) + mkexp loc (Pexp_construct (lident (conv_con s)) None True) + | ExVrn loc s -> mkexp loc (Pexp_variant s None) + | ExWhi loc e1 el -> + let e2 = ExSeq loc el in + mkexp loc (Pexp_while (expr e1) (expr e2)) + | <:expr@loc< $_$,$_$ >> -> error loc "expr, expr: not allowed here" + | <:expr@loc< $_$;$_$ >> -> + error loc "expr; expr: not allowed here, use do {...} or [|...|] to surround them" + | ExId _ _ | ExNil _ as e -> error (loc_of_expr e) "invalid expr" ] + and patt_of_lab _loc lab = + fun + [ <:patt<>> -> patt <:patt< $lid:lab$ >> + | p -> patt p ] + and expr_of_lab _loc lab = + fun + [ <:expr<>> -> expr <:expr< $lid:lab$ >> + | e -> expr e ] + and label_expr = + fun + [ ExLab loc lab eo -> (lab, expr_of_lab loc lab eo) + | ExOlb loc lab eo -> ("?" ^ lab, expr_of_lab loc lab eo) + | e -> ("", expr e) ] + and binding x acc = + match x with + [ <:binding< $x$ and $y$ >> -> + binding x (binding y acc) + | <:binding< $p$ = $e$ >> -> [(patt p, expr e) :: acc] + | <:binding<>> -> acc + | _ -> assert False ] + and match_case x acc = + match x with + [ <:match_case< $x$ | $y$ >> -> match_case x (match_case y acc) + | <:match_case< $pat:p$ when $w$ -> $e$ >> -> + [(patt p, when_expr e w) :: acc] + | <:match_case<>> -> acc + | _ -> assert False ] + and when_expr e w = + match w with + [ <:expr<>> -> expr e + | w -> mkexp (loc_of_expr w) (Pexp_when (expr w) (expr e)) ] + and mklabexp x acc = + match x with + [ <:rec_binding< $x$; $y$ >> -> + mklabexp x (mklabexp y acc) + | <:rec_binding< $i$ = $e$ >> -> [(ident ~conv_lid:conv_lab i, expr e) :: acc] + | _ -> assert False ] + and mkideexp x acc = + match x with + [ <:rec_binding<>> -> acc + | <:rec_binding< $x$; $y$ >> -> + mkideexp x (mkideexp y acc) + | <:rec_binding< $lid:s$ = $e$ >> -> [(s, expr e) :: acc] + | _ -> assert False ] + and mktype_decl x acc = + match x with + [ <:ctyp< $x$ and $y$ >> -> + mktype_decl x (mktype_decl y acc) + | Ast.TyDcl _ c tl td cl -> + let cl = + List.map + (fun (t1, t2) -> + let loc = Loc.merge (loc_of_ctyp t1) (loc_of_ctyp t2) in + (ctyp t1, ctyp t2, mkloc loc)) + cl + in + [(c, type_decl (List.fold_right type_parameters tl []) cl td) :: acc] + | _ -> assert False ] + and module_type = + fun + [ <:module_type@loc<>> -> error loc "abstract/nil module type not allowed here" + | <:module_type@loc< $id:i$ >> -> mkmty loc (Pmty_ident (long_uident i)) + | <:module_type@loc< functor ($n$ : $nt$) -> $mt$ >> -> + mkmty loc (Pmty_functor n (module_type nt) (module_type mt)) + | <:module_type@loc< '$_$ >> -> error loc "module type variable not allowed here" + | <:module_type@loc< sig $sl$ end >> -> + mkmty loc (Pmty_signature (sig_item sl [])) + | <:module_type@loc< $mt$ with $wc$ >> -> + mkmty loc (Pmty_with (module_type mt) (mkwithc wc [])) + | <:module_type< $anti:_$ >> -> assert False ] + and sig_item s l = + match s with + [ <:sig_item<>> -> l + | SgCls loc cd -> + [mksig loc (Psig_class + (List.map class_info_class_type (list_of_class_type cd []))) :: l] + | SgClt loc ctd -> + [mksig loc (Psig_class_type + (List.map class_info_class_type (list_of_class_type ctd []))) :: l] + | <:sig_item< $sg1$; $sg2$ >> -> sig_item sg1 (sig_item sg2 l) + | SgDir _ _ _ -> l + | <:sig_item@loc< exception $uid:s$ >> -> + [mksig loc (Psig_exception (conv_con s) []) :: l] + | <:sig_item@loc< exception $uid:s$ of $t$ >> -> + [mksig loc (Psig_exception (conv_con s) + (List.map ctyp (list_of_ctyp t []))) :: l] + | SgExc _ _ -> assert False (*FIXME*) + | SgExt loc n t sl -> [mksig loc (Psig_value n (mkvalue_desc t (list_of_meta_list sl))) :: l] + | SgInc loc mt -> [mksig loc (Psig_include (module_type mt)) :: l] + | SgMod loc n mt -> [mksig loc (Psig_module n (module_type mt)) :: l] + | SgRecMod loc mb -> + [mksig loc (Psig_recmodule (module_sig_binding mb [])) :: l] + | SgMty loc n mt -> + let si = + match mt with + [ MtQuo _ _ -> Pmodtype_abstract + | _ -> Pmodtype_manifest (module_type mt) ] + in + [mksig loc (Psig_modtype n si) :: l] + | SgOpn loc id -> + [mksig loc (Psig_open (long_uident id)) :: l] + | SgTyp loc tdl -> [mksig loc (Psig_type (mktype_decl tdl [])) :: l] + | SgVal loc n t -> [mksig loc (Psig_value n (mkvalue_desc t [])) :: l] + | <:sig_item@loc< $anti:_$ >> -> error loc "antiquotation in sig_item" ] + and module_sig_binding x acc = + match x with + [ <:module_binding< $x$ and $y$ >> -> + module_sig_binding x (module_sig_binding y acc) + | <:module_binding< $s$ : $mt$ >> -> + [(s, module_type mt) :: acc] + | _ -> assert False ] + and module_str_binding x acc = + match x with + [ <:module_binding< $x$ and $y$ >> -> + module_str_binding x (module_str_binding y acc) + | <:module_binding< $s$ : $mt$ = $me$ >> -> + [(s, module_type mt, module_expr me) :: acc] + | _ -> assert False ] + and module_expr = + fun + [ <:module_expr@loc<>> -> error loc "nil module expression" + | <:module_expr@loc< $id:i$ >> -> mkmod loc (Pmod_ident (long_uident i)) + | <:module_expr@loc< $me1$ $me2$ >> -> + mkmod loc (Pmod_apply (module_expr me1) (module_expr me2)) + | <:module_expr@loc< functor ($n$ : $mt$) -> $me$ >> -> + mkmod loc (Pmod_functor n (module_type mt) (module_expr me)) + | <:module_expr@loc< struct $sl$ end >> -> + mkmod loc (Pmod_structure (str_item sl [])) + | <:module_expr@loc< ($me$ : $mt$) >> -> + mkmod loc (Pmod_constraint (module_expr me) (module_type mt)) + | <:module_expr@loc< $anti:_$ >> -> error loc "antiquotation in module_expr" ] + and str_item s l = + match s with + [ <:str_item<>> -> l + | StCls loc cd -> + [mkstr loc (Pstr_class + (List.map class_info_class_expr (list_of_class_expr cd []))) :: l] + | StClt loc ctd -> + [mkstr loc (Pstr_class_type + (List.map class_info_class_type (list_of_class_type ctd []))) :: l] + | <:str_item< $st1$; $st2$ >> -> str_item st1 (str_item st2 l) + | StDir _ _ _ -> l + | <:str_item@loc< exception $uid:s$ >> -> + [mkstr loc (Pstr_exception (conv_con s) []) :: l ] + | <:str_item@loc< exception $uid:s$ of $t$ >> -> + [mkstr loc (Pstr_exception (conv_con s) + (List.map ctyp (list_of_ctyp t []))) :: l ] + | <:str_item@loc< exception $uid:s$ = $i$ >> -> + [mkstr loc (Pstr_exn_rebind (conv_con s) (ident i)) :: l ] + | StExc _ _ _ -> assert False (*FIXME*) + | StExp loc e -> [mkstr loc (Pstr_eval (expr e)) :: l] + | StExt loc n t sl -> [mkstr loc (Pstr_primitive n (mkvalue_desc t (list_of_meta_list sl))) :: l] + | StInc loc me -> [mkstr loc (Pstr_include (module_expr me)) :: l] + | StMod loc n me -> [mkstr loc (Pstr_module n (module_expr me)) :: l] + | StRecMod loc mb -> + [mkstr loc (Pstr_recmodule (module_str_binding mb [])) :: l] + | StMty loc n mt -> [mkstr loc (Pstr_modtype n (module_type mt)) :: l] + | StOpn loc id -> + [mkstr loc (Pstr_open (long_uident id)) :: l] + | StTyp loc tdl -> [mkstr loc (Pstr_type (mktype_decl tdl [])) :: l] + | StVal loc rf bi -> + [mkstr loc (Pstr_value (mkrf rf) (binding bi [])) :: l] + | <:str_item@loc< $anti:_$ >> -> error loc "antiquotation in str_item" ] + and class_type = + fun + [ CtCon loc Ast.BFalse id tl -> + mkcty loc + (Pcty_constr (long_class_ident id) (List.map ctyp (list_of_opt_ctyp tl []))) + | CtFun loc (TyLab _ lab t) ct -> + mkcty loc (Pcty_fun lab (ctyp t) (class_type ct)) + | CtFun loc (TyOlb loc1 lab t) ct -> + let t = TyApp loc1 <:ctyp@loc1< option >> t in + mkcty loc (Pcty_fun ("?" ^ lab) (ctyp t) (class_type ct)) + | CtFun loc t ct -> mkcty loc (Pcty_fun "" (ctyp t) (class_type ct)) + | CtSig loc t_o ctfl -> + let t = + match t_o with + [ <:ctyp<>> -> <:ctyp@loc< _ >> + | t -> t ] + in + let cil = class_sig_item ctfl [] in + mkcty loc (Pcty_signature (ctyp t, cil)) + | CtCon loc _ _ _ -> + error loc "invalid virtual class inside a class type" + | CtAnt _ _ | CtEq _ _ _ | CtCol _ _ _ | CtAnd _ _ _ | CtNil _ -> + assert False ] + + and class_info_class_expr ci = + match ci with + [ CeEq _ (CeCon loc vir (IdLid _ name) params) ce -> + let (loc_params, (params, variance)) = + match params with + [ <:ctyp<>> -> (loc, ([], [])) + | t -> (loc_of_ctyp t, List.split (class_parameters t [])) ] + in + {pci_virt = if mb2b vir then Virtual else Concrete; + pci_params = (params, mkloc loc_params); + pci_name = name; + pci_expr = class_expr ce; + pci_loc = mkloc loc; + pci_variance = variance} + | ce -> error (loc_of_class_expr ce) "bad class definition" ] + and class_info_class_type ci = + match ci with + [ CtEq _ (CtCon loc vir (IdLid _ name) params) ct | + CtCol _ (CtCon loc vir (IdLid _ name) params) ct -> + let (loc_params, (params, variance)) = + match params with + [ <:ctyp<>> -> (loc, ([], [])) + | t -> (loc_of_ctyp t, List.split (class_parameters t [])) ] + in + {pci_virt = if mb2b vir then Virtual else Concrete; + pci_params = (params, mkloc loc_params); + pci_name = name; + pci_expr = class_type ct; + pci_loc = mkloc loc; + pci_variance = variance} + | ct -> error (loc_of_class_type ct) + "bad class/class type declaration/definition" ] + and class_sig_item c l = + match c with + [ <:class_sig_item<>> -> l + | CgCtr loc t1 t2 -> [Pctf_cstr (ctyp t1, ctyp t2, mkloc loc) :: l] + | <:class_sig_item< $csg1$; $csg2$ >> -> + class_sig_item csg1 (class_sig_item csg2 l) + | CgInh _ ct -> [Pctf_inher (class_type ct) :: l] + | CgMth loc s pf t -> + [Pctf_meth (s, mkprivate pf, mkpolytype (ctyp t), mkloc loc) :: l] + | CgVal loc s b v t -> + [Pctf_val (s, mkmutable b, mkvirtual v, ctyp t, mkloc loc) :: l] + | CgVir loc s b t -> + [Pctf_virt (s, mkprivate b, mkpolytype (ctyp t), mkloc loc) :: l] + | CgAnt _ _ -> assert False ] + and class_expr = + fun + [ CeApp loc _ _ as c -> + let (ce, el) = class_expr_fa [] c in + let el = List.map label_expr el in + mkpcl loc (Pcl_apply (class_expr ce) el) + | CeCon loc Ast.BFalse id tl -> + mkpcl loc + (Pcl_constr (long_class_ident id) (List.map ctyp (list_of_opt_ctyp tl []))) + | CeFun loc (PaLab _ lab po) ce -> + mkpcl loc + (Pcl_fun lab None (patt_of_lab loc lab po) (class_expr ce)) + | CeFun loc (PaOlbi _ lab p e) ce -> + let lab = paolab lab p in + mkpcl loc (Pcl_fun ("?" ^ lab) (Some (expr e)) (patt p) (class_expr ce)) + | CeFun loc (PaOlb _ lab p) ce -> + let lab = paolab lab p in + mkpcl loc + (Pcl_fun ("?" ^ lab) None (patt_of_lab loc lab p) (class_expr ce)) + | CeFun loc p ce -> mkpcl loc (Pcl_fun "" None (patt p) (class_expr ce)) + | CeLet loc rf bi ce -> + mkpcl loc (Pcl_let (mkrf rf) (binding bi []) (class_expr ce)) + | CeStr loc po cfl -> + let p = + match po with + [ <:patt<>> -> <:patt@loc< _ >> + | p -> p ] + in + let cil = class_str_item cfl [] in + mkpcl loc (Pcl_structure (patt p, cil)) + | CeTyc loc ce ct -> + mkpcl loc (Pcl_constraint (class_expr ce) (class_type ct)) + | CeCon loc _ _ _ -> + error loc "invalid virtual class inside a class expression" + | CeAnt _ _ | CeEq _ _ _ | CeAnd _ _ _ | CeNil _ -> assert False ] + and class_str_item c l = + match c with + [ CrNil _ -> l + | CrCtr loc t1 t2 -> [Pcf_cstr (ctyp t1, ctyp t2, mkloc loc) :: l] + | <:class_str_item< $cst1$; $cst2$ >> -> + class_str_item cst1 (class_str_item cst2 l) + | CrInh _ ce "" -> [Pcf_inher (class_expr ce) None :: l] + | CrInh _ ce pb -> [Pcf_inher (class_expr ce) (Some pb) :: l] + | CrIni _ e -> [Pcf_init (expr e) :: l] + | CrMth loc s b e t -> + let t = + match t with + [ <:ctyp<>> -> None + | t -> Some (mkpolytype (ctyp t)) ] in + let e = mkexp loc (Pexp_poly (expr e) t) in + [Pcf_meth (s, mkprivate b, e, mkloc loc) :: l] + | CrVal loc s b e -> [Pcf_val (s, mkmutable b, expr e, mkloc loc) :: l] + | CrVir loc s b t -> + [Pcf_virt (s, mkprivate b, mkpolytype (ctyp t), mkloc loc) :: l] + | CrVvr loc s b t -> + [Pcf_valvirt (s, mkmutable b, ctyp t, mkloc loc) :: l] + | CrAnt _ _ -> assert False ]; + + value sig_item ast = sig_item ast []; + value str_item ast = str_item ast []; + + value directive = + fun + [ <:expr<>> -> Pdir_none + | ExStr _ s -> Pdir_string s + | ExInt _ i -> Pdir_int (int_of_string i) + | <:expr< True >> -> Pdir_bool True + | <:expr< False >> -> Pdir_bool False + | e -> Pdir_ident (ident (ident_of_expr e)) ] + ; + + value phrase = + fun + [ StDir _ d dp -> Ptop_dir d (directive dp) + | si -> Ptop_def (str_item si) ] + ; +end; diff --git a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli new file mode 100644 index 0000000..6c28483 --- /dev/null +++ b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli @@ -0,0 +1,32 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +module Make (Camlp4Ast : Sig.Camlp4Ast) : sig + open Camlp4Ast; + + (** {6 Useful functions} *) + + value sig_item : sig_item -> Camlp4_import.Parsetree.signature; + value str_item : str_item -> Camlp4_import.Parsetree.structure; + value phrase : str_item -> Camlp4_import.Parsetree.toplevel_phrase; + +end; diff --git a/camlp4/Camlp4/Struct/CleanAst.ml b/camlp4/Camlp4/Struct/CleanAst.ml new file mode 100644 index 0000000..ab92505 --- /dev/null +++ b/camlp4/Camlp4/Struct/CleanAst.ml @@ -0,0 +1,145 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +(** This module is suppose to contain nils elimination. *) +module Make (Ast : Sig.Camlp4Ast) = struct + + class clean_ast = object + + inherit Ast.map as super; + + method with_constr wc = + match super#with_constr wc with + [ <:with_constr< $ <:with_constr<>> $ and $wc$ >> | + <:with_constr< $wc$ and $ <:with_constr<>> $ >> -> wc + | wc -> wc ]; + + method expr e = + match super#expr e with + [ <:expr< let $rec:_$ $ <:binding<>> $ in $e$ >> | + <:expr< { ($e$) with $ <:rec_binding<>> $ } >> | + <:expr< $ <:expr<>> $, $e$ >> | + <:expr< $e$, $ <:expr<>> $ >> | + <:expr< $ <:expr<>> $; $e$ >> | + <:expr< $e$; $ <:expr<>> $ >> -> e + | e -> e ]; + + method patt p = + match super#patt p with + [ <:patt< ( $p$ as $ <:patt<>> $ ) >> | + <:patt< $ <:patt<>> $ | $p$ >> | + <:patt< $p$ | $ <:patt<>> $ >> | + <:patt< $ <:patt<>> $, $p$ >> | + <:patt< $p$, $ <:patt<>> $ >> | + <:patt< $ <:patt<>> $; $p$ >> | + <:patt< $p$; $ <:patt<>> $ >> -> p + | p -> p ]; + + method match_case mc = + match super#match_case mc with + [ <:match_case< $ <:match_case<>> $ | $mc$ >> | + <:match_case< $mc$ | $ <:match_case<>> $ >> -> mc + | mc -> mc ]; + + method binding bi = + match super#binding bi with + [ <:binding< $ <:binding<>> $ and $bi$ >> | + <:binding< $bi$ and $ <:binding<>> $ >> -> bi + | bi -> bi ]; + + method rec_binding rb = + match super#rec_binding rb with + [ <:rec_binding< $ <:rec_binding<>> $ ; $bi$ >> | + <:rec_binding< $bi$ ; $ <:rec_binding<>> $ >> -> bi + | bi -> bi ]; + + method module_binding mb = + match super#module_binding mb with + [ <:module_binding< $ <:module_binding<>> $ and $mb$ >> | + <:module_binding< $mb$ and $ <:module_binding<>> $ >> -> mb + | mb -> mb ]; + + method ctyp t = + match super#ctyp t with + [ <:ctyp< ! $ <:ctyp<>> $ . $t$ >> | + <:ctyp< $ <:ctyp<>> $ as $t$ >> | + <:ctyp< $t$ as $ <:ctyp<>> $ >> | + <:ctyp< $t$ -> $ <:ctyp<>> $ >> | + <:ctyp< $ <:ctyp<>> $ -> $t$ >> | + <:ctyp< $ <:ctyp<>> $ | $t$ >> | + <:ctyp< $t$ | $ <:ctyp<>> $ >> | + <:ctyp< $t$ of $ <:ctyp<>> $ >> | + <:ctyp< $ <:ctyp<>> $ and $t$ >> | + <:ctyp< $t$ and $ <:ctyp<>> $ >> | + <:ctyp< $t$; $ <:ctyp<>> $ >> | + <:ctyp< $ <:ctyp<>> $; $t$ >> | + <:ctyp< $ <:ctyp<>> $, $t$ >> | + <:ctyp< $t$, $ <:ctyp<>> $ >> | + <:ctyp< $t$ & $ <:ctyp<>> $ >> | + <:ctyp< $ <:ctyp<>> $ & $t$ >> | + <:ctyp< $ <:ctyp<>> $ * $t$ >> | + <:ctyp< $t$ * $ <:ctyp<>> $ >> -> t + | t -> t ]; + + method sig_item sg = + match super#sig_item sg with + [ <:sig_item< $ <:sig_item<>> $; $sg$ >> | + <:sig_item< $sg$; $ <:sig_item<>> $ >> -> sg + | <:sig_item@loc< type $ <:ctyp<>> $ >> -> <:sig_item@loc<>> + | sg -> sg ]; + + method str_item st = + match super#str_item st with + [ <:str_item< $ <:str_item<>> $; $st$ >> | + <:str_item< $st$; $ <:str_item<>> $ >> -> st + | <:str_item@loc< type $ <:ctyp<>> $ >> -> <:str_item@loc<>> + | <:str_item@loc< value $rec:_$ $ <:binding<>> $ >> -> <:str_item@loc<>> + | st -> st ]; + + method module_type mt = + match super#module_type mt with + [ <:module_type< $mt$ with $ <:with_constr<>> $ >> -> mt + | mt -> mt ]; + + method class_expr ce = + match super#class_expr ce with + [ <:class_expr< $ <:class_expr<>> $ and $ce$ >> | + <:class_expr< $ce$ and $ <:class_expr<>> $ >> -> ce + | ce -> ce ]; + + method class_type ct = + match super#class_type ct with + [ <:class_type< $ <:class_type<>> $ and $ct$ >> | + <:class_type< $ct$ and $ <:class_type<>> $ >> -> ct + | ct -> ct ]; + + method class_sig_item csg = + match super#class_sig_item csg with + [ <:class_sig_item< $ <:class_sig_item<>> $; $csg$ >> | + <:class_sig_item< $csg$; $ <:class_sig_item<>> $ >> -> csg + | csg -> csg ]; + + method class_str_item cst = + match super#class_str_item cst with + [ <:class_str_item< $ <:class_str_item<>> $; $cst$ >> | + <:class_str_item< $cst$; $ <:class_str_item<>> $ >> -> cst + | cst -> cst ]; + + end; + +end; diff --git a/camlp4/Camlp4/Struct/CommentFilter.ml b/camlp4/Camlp4/Struct/CommentFilter.ml new file mode 100644 index 0000000..5867df4 --- /dev/null +++ b/camlp4/Camlp4/Struct/CommentFilter.ml @@ -0,0 +1,56 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Token : Sig.Camlp4Token) = struct + open Token; + + type t = (Stream.t (string * Loc.t) * Queue.t (string * Loc.t)); + + value mk () = + let q = Queue.create () in + let f _ = + debug comments "take...@\n" in + try Some (Queue.take q) with [ Queue.Empty -> None ] + in (Stream.from f, q); + + value filter (_, q) = + let rec self = + parser + [ [: ` (Sig.COMMENT x, loc); xs :] -> + do { Queue.add (x, loc) q; + debug comments "add: %S at %a@\n" x Loc.dump loc in + self xs } + | [: ` x; xs :] -> + (* debug comments "Found %a at %a@." Token.print x Loc.dump loc in *) + [: ` x; self xs :] + | [: :] -> [: :] ] + in self; + + value take_list (_, q) = + let rec self accu = + if Queue.is_empty q then accu else self [Queue.take q :: accu] + in self []; + + value take_stream = fst; + + value define token_fiter comments_strm = + debug comments "Define a comment filter@\n" in + Token.Filter.define_filter token_fiter + (fun previous strm -> previous (filter comments_strm strm)); + +end; diff --git a/camlp4/Camlp4/Struct/CommentFilter.mli b/camlp4/Camlp4/Struct/CommentFilter.mli new file mode 100644 index 0000000..79ece6a --- /dev/null +++ b/camlp4/Camlp4/Struct/CommentFilter.mli @@ -0,0 +1,33 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Token : Sig.Camlp4Token) : sig + open Token; + + type t; + + value mk : unit -> t; + + value define : Token.Filter.t -> t -> unit; + + value filter : t -> Stream.t (Token.t * Loc.t) -> Stream.t (Token.t * Loc.t); + + value take_list : t -> list (string * Loc.t); + + value take_stream : t -> Stream.t (string * Loc.t); +end; diff --git a/camlp4/Camlp4/Struct/DynAst.ml b/camlp4/Camlp4/Struct/DynAst.ml new file mode 100644 index 0000000..2161e1c --- /dev/null +++ b/camlp4/Camlp4/Struct/DynAst.ml @@ -0,0 +1,91 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2007 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Ast) : Sig.DynAst with module Ast = Ast = struct + module Ast = Ast; + type tag 'a = + [ Tag_ctyp + | Tag_patt + | Tag_expr + | Tag_module_type + | Tag_sig_item + | Tag_with_constr + | Tag_module_expr + | Tag_str_item + | Tag_class_type + | Tag_class_sig_item + | Tag_class_expr + | Tag_class_str_item + | Tag_match_case + | Tag_ident + | Tag_binding + | Tag_rec_binding + | Tag_module_binding ]; + + value string_of_tag = + fun + [ Tag_ctyp -> "ctyp" + | Tag_patt -> "patt" + | Tag_expr -> "expr" + | Tag_module_type -> "module_type" + | Tag_sig_item -> "sig_item" + | Tag_with_constr -> "with_constr" + | Tag_module_expr -> "module_expr" + | Tag_str_item -> "str_item" + | Tag_class_type -> "class_type" + | Tag_class_sig_item -> "class_sig_item" + | Tag_class_expr -> "class_expr" + | Tag_class_str_item -> "class_str_item" + | Tag_match_case -> "match_case" + | Tag_ident -> "ident" + | Tag_binding -> "binding" + | Tag_rec_binding -> "rec_binding" + | Tag_module_binding -> "module_binding" ]; + + value ctyp_tag = Tag_ctyp; + value patt_tag = Tag_patt; + value expr_tag = Tag_expr; + value module_type_tag = Tag_module_type; + value sig_item_tag = Tag_sig_item; + value with_constr_tag = Tag_with_constr; + value module_expr_tag = Tag_module_expr; + value str_item_tag = Tag_str_item; + value class_type_tag = Tag_class_type; + value class_sig_item_tag = Tag_class_sig_item; + value class_expr_tag = Tag_class_expr; + value class_str_item_tag = Tag_class_str_item; + value match_case_tag = Tag_match_case; + value ident_tag = Tag_ident; + value binding_tag = Tag_binding; + value rec_binding_tag = Tag_rec_binding; + value module_binding_tag = Tag_module_binding; + + type dyn; + external dyn_tag : tag 'a -> tag dyn = "%identity"; + + module Pack(X : sig type t 'a; end) = struct + (* These Obj.* hacks should be avoided with GADTs *) + type pack = (tag dyn * Obj.t); + exception Pack_error; + value pack tag v = (dyn_tag tag, Obj.repr v); + value unpack (tag : tag 'a) (tag', obj) = + if dyn_tag tag = tag' then (Obj.obj obj : X.t 'a) else raise Pack_error; + value print_tag f (tag, _) = Format.pp_print_string f (string_of_tag tag); + end; +end; diff --git a/camlp4/Camlp4/Struct/DynLoader.ml b/camlp4/Camlp4/Struct/DynLoader.ml new file mode 100644 index 0000000..f8e8c22 --- /dev/null +++ b/camlp4/Camlp4/Struct/DynLoader.ml @@ -0,0 +1,84 @@ +(* camlp4r pa_macro.cmo *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2001-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + + +type t = Queue.t string; + +exception Error of string and string; + +value include_dir x y = Queue.add y x; + +value fold_load_path x f acc = Queue.fold (fun x y -> f y x) acc x; + +value mk ?(ocaml_stdlib = True) ?(camlp4_stdlib = True) () = + let q = Queue.create () in do { + if ocaml_stdlib then include_dir q Camlp4_config.ocaml_standard_library else (); + if camlp4_stdlib then do { + include_dir q Camlp4_config.camlp4_standard_library; + include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Parsers"); + include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Printers"); + include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Filters"); + } else (); + include_dir q "."; + q +}; + +(* Load files in core *) + +value find_in_path x name = + if not (Filename.is_implicit name) then + if Sys.file_exists name then name else raise Not_found + else + let res = + fold_load_path x + (fun dir -> + fun + [ None -> + let fullname = Filename.concat dir name in + if Sys.file_exists fullname then Some fullname else None + | x -> x ]) None + in match res with [ None -> raise Not_found | Some x -> x ]; + +value load = + let _initialized = ref False in + fun _path file -> + do { + if not _initialized.val then + try do { + Dynlink.init (); + Dynlink.allow_unsafe_modules True; + _initialized.val := True + } + with + [ Dynlink.Error e -> + raise (Error "Camlp4's dynamic loader initialization" (Dynlink.error_message e)) ] + else (); + let fname = + try find_in_path _path file with + [ Not_found -> raise (Error file "file not found in path") ] + in + try Dynlink.loadfile fname with + [ Dynlink.Error e -> raise (Error fname (Dynlink.error_message e)) ] + }; + + +value is_native = Dynlink.is_native; diff --git a/camlp4/Camlp4/Struct/DynLoader.mli b/camlp4/Camlp4/Struct/DynLoader.mli new file mode 100644 index 0000000..292b705 --- /dev/null +++ b/camlp4/Camlp4/Struct/DynLoader.mli @@ -0,0 +1,20 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +include Sig.DynLoader; diff --git a/camlp4/Camlp4/Struct/EmptyError.ml b/camlp4/Camlp4/Struct/EmptyError.ml new file mode 100644 index 0000000..1acb225 --- /dev/null +++ b/camlp4/Camlp4/Struct/EmptyError.ml @@ -0,0 +1,22 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +type t = unit; +exception E of t; +value print _ = assert False; +value to_string _ = assert False; \ No newline at end of file diff --git a/camlp4/Camlp4/Struct/EmptyError.mli b/camlp4/Camlp4/Struct/EmptyError.mli new file mode 100644 index 0000000..9d21662 --- /dev/null +++ b/camlp4/Camlp4/Struct/EmptyError.mli @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +include Sig.Error; \ No newline at end of file diff --git a/camlp4/Camlp4/Struct/EmptyPrinter.ml b/camlp4/Camlp4/Struct/EmptyPrinter.ml new file mode 100644 index 0000000..5886809 --- /dev/null +++ b/camlp4/Camlp4/Struct/EmptyPrinter.ml @@ -0,0 +1,22 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Ast) = struct + value print_interf ?input_file:(_) ?output_file:(_) _ = failwith "No interface printer"; + value print_implem ?input_file:(_) ?output_file:(_) _ = failwith "No implementation printer"; +end; diff --git a/camlp4/Camlp4/Struct/EmptyPrinter.mli b/camlp4/Camlp4/Struct/EmptyPrinter.mli new file mode 100644 index 0000000..f8bf907 --- /dev/null +++ b/camlp4/Camlp4/Struct/EmptyPrinter.mli @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Ast) : (Sig.Printer Ast).S; diff --git a/camlp4/Camlp4/Struct/FreeVars.ml b/camlp4/Camlp4/Struct/FreeVars.ml new file mode 100644 index 0000000..66a9a8b --- /dev/null +++ b/camlp4/Camlp4/Struct/FreeVars.ml @@ -0,0 +1,128 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Camlp4Ast) = struct + + module S = Set.Make String; + + class c_fold_pattern_vars ['accu] f init = + object + inherit Ast.fold as super; + value acc = init; + method acc : 'accu = acc; + method patt = + fun + [ <:patt< $lid:s$ >> | <:patt< ~ $s$ >> | <:patt< ? $s$ >> -> + {< acc = f s acc >} + | p -> super#patt p ]; + end; + + value fold_pattern_vars f p init = ((new c_fold_pattern_vars f init)#patt p)#acc; + + value rec fold_binding_vars f bi acc = + match bi with + [ <:binding< $bi1$ and $bi2$ >> -> + fold_binding_vars f bi1 (fold_binding_vars f bi2 acc) + | <:binding< $p$ = $_$ >> -> fold_pattern_vars f p acc + | <:binding<>> -> acc + | <:binding< $anti:_$ >> -> assert False ]; + + class fold_free_vars ['accu] (f : string -> 'accu -> 'accu) ?(env_init = S.empty) free_init = + object (o) + inherit Ast.fold as super; + value free : 'accu = free_init; + value env : S.t = env_init; + + method free = free; + method set_env env = {< env = env >}; + method add_atom s = {< env = S.add s env >}; + method add_patt p = {< env = fold_pattern_vars S.add p env >}; + method add_binding bi = {< env = fold_binding_vars S.add bi env >}; + + method expr = + fun + [ <:expr< $lid:s$ >> | <:expr< ~ $s$ >> | <:expr< ? $s$ >> -> + if S.mem s env then o else {< free = f s free >} + + | <:expr< let $bi$ in $e$ >> -> + (((o#add_binding bi)#expr e)#set_env env)#binding bi + + | <:expr< let rec $bi$ in $e$ >> -> + (((o#add_binding bi)#expr e)#binding bi)#set_env env + + | <:expr< for $s$ = $e1$ $to:_$ $e2$ do { $e3$ } >> -> + ((((o#expr e1)#expr e2)#add_atom s)#expr e3)#set_env env + + | <:expr< $id:_$ >> | <:expr< new $_$ >> -> o + + | <:expr< object ($p$) $cst$ end >> -> + ((o#add_patt p)#class_str_item cst)#set_env env + + | e -> super#expr e ]; + + method match_case = + fun + [ <:match_case< $p$ when $e1$ -> $e2$ >> -> + (((o#add_patt p)#expr e1)#expr e2)#set_env env + | m -> super#match_case m ]; + + method str_item = + fun + [ <:str_item< external $s$ : $t$ = $_$ >> -> + (o#ctyp t)#add_atom s + | <:str_item< value $bi$ >> -> + (o#binding bi)#add_binding bi + | <:str_item< value rec $bi$ >> -> + (o#add_binding bi)#binding bi + | st -> super#str_item st ]; + + method class_expr = + fun + [ <:class_expr< fun $p$ -> $ce$ >> -> + ((o#add_patt p)#class_expr ce)#set_env env + | <:class_expr< let $bi$ in $ce$ >> -> + (((o#binding bi)#add_binding bi)#class_expr ce)#set_env env + | <:class_expr< let rec $bi$ in $ce$ >> -> + (((o#add_binding bi)#binding bi)#class_expr ce)#set_env env + | <:class_expr< object ($p$) $cst$ end >> -> + ((o#add_patt p)#class_str_item cst)#set_env env + | ce -> super#class_expr ce ]; + + method class_str_item = + fun + [ <:class_str_item< inherit $_$ >> as cst -> super#class_str_item cst + | <:class_str_item< inherit $ce$ as $s$ >> -> + (o#class_expr ce)#add_atom s + | <:class_str_item< value $mutable:_$ $s$ = $e$ >> -> + (o#expr e)#add_atom s + | <:class_str_item< value virtual $mutable:_$ $s$ : $t$ >> -> + (o#ctyp t)#add_atom s + | cst -> super#class_str_item cst ]; + + method module_expr = fun + [ <:module_expr< struct $st$ end >> -> + (o#str_item st)#set_env env + | me -> super#module_expr me ]; + + end; + + value free_vars env_init e = + let fold = new fold_free_vars S.add ~env_init S.empty in (fold#expr e)#free; +end; + diff --git a/camlp4/Camlp4/Struct/FreeVars.mli b/camlp4/Camlp4/Struct/FreeVars.mli new file mode 100644 index 0000000..aac72db --- /dev/null +++ b/camlp4/Camlp4/Struct/FreeVars.mli @@ -0,0 +1,48 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Make (Ast : Sig.Camlp4Ast) : sig + module S : Set.S with type elt = string; + + value fold_binding_vars : (string -> 'accu -> 'accu) -> Ast.binding -> 'accu -> 'accu; + + class c_fold_pattern_vars ['accu] : [string -> 'accu -> 'accu] -> ['accu] -> + object + inherit Ast.fold; + value acc : 'accu; + method acc : 'accu; + end; + + value fold_pattern_vars : (string -> 'accu -> 'accu) -> Ast.patt -> 'accu -> 'accu; + + class fold_free_vars ['accu] : [string -> 'accu -> 'accu] -> [?env_init:S.t] -> ['accu] -> + object ('self_type) + inherit Ast.fold; + value free : 'accu; + value env : S.t; + method free : 'accu; + method set_env : S.t -> 'self_type; + method add_atom : string -> 'self_type; + method add_patt : Ast.patt -> 'self_type; + method add_binding : Ast.binding -> 'self_type; + end; + + value free_vars : S.t -> Ast.expr -> S.t; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar.mlpack b/camlp4/Camlp4/Struct/Grammar.mlpack new file mode 100644 index 0000000..23c3429 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar.mlpack @@ -0,0 +1,14 @@ +Context +Delete +Dynamic +Entry +Failed +Find +Fold +Insert +Parser +Print +Search +Static +Structure +Tools diff --git a/camlp4/Camlp4/Struct/Grammar/Context.ml b/camlp4/Camlp4/Struct/Grammar/Context.ml new file mode 100644 index 0000000..75d731c --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Context.ml @@ -0,0 +1,90 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module type S = sig + module Token : Sig.Token; + open Token; + type t; + value call_with_ctx : Stream.t (Token.t * Loc.t) -> (t -> 'a) -> 'a; + value loc_bp : t -> Loc.t; + value loc_ep : t -> Loc.t; + value stream : t -> Stream.t (Token.t * Loc.t); + value peek_nth : t -> int -> option (Token.t * Loc.t); + value njunk : t -> int -> unit; + value junk : Stream.t (Token.t * Loc.t) -> unit; + value bp : Stream.t (Token.t * Loc.t) -> Loc.t; +end; + +module Make (Token : Sig.Token) : S with module Token = Token = struct + module Token = Token; + open Token; + + type t = { strm : mutable Stream.t (Token.t * Loc.t); + loc : mutable Loc.t }; + + value loc_bp c = + match Stream.peek c.strm with + [ None -> Loc.ghost + | Some (_, loc) -> loc ]; + + value loc_ep c = c.loc; + + value set_loc c = + match Stream.peek c.strm with + [ Some (_, loc) -> c.loc := loc + | None -> () ]; + + value mk strm = + match Stream.peek strm with + [ Some (_, loc) -> { strm = strm; loc = loc } + | None -> { strm = strm ; loc = Loc.ghost } ]; + + value stream c = c.strm; + + value peek_nth c n = + let list = Stream.npeek n c.strm in + let rec loop list n = + match (list, n) with + [ ([((_, loc) as x) :: _], 1) -> do { c.loc := loc; Some x } + | ([_ :: l], n) -> loop l (n - 1) + | ([], _) -> None ] + in + loop list n; + + value njunk c n = + (for i = 1 to n do Stream.junk c.strm done; + set_loc c); + + value streams = ref []; + value mk strm = + let c = mk strm in + let () = streams.val := [(strm, c) :: streams.val] in c; + value junk strm = + do { set_loc (List.assq strm streams.val); Stream.junk strm }; + value bp strm = loc_bp (List.assq strm streams.val); + + value call_with_ctx strm f = + let streams_v = streams.val in + let r = + try f (mk strm) with exc -> do { streams.val := streams_v; raise exc } + in + do { streams.val := streams_v; r } + ; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Delete.ml b/camlp4/Camlp4/Struct/Grammar/Delete.ml new file mode 100644 index 0000000..49a4500 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Delete.ml @@ -0,0 +1,163 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + module Tools = Tools.Make Structure; + module Parser = Parser.Make Structure; + open Structure; + +(* Deleting a rule *) + +(* [delete_rule_in_tree] returns + [Some (dsl, t)] if success + [dsl] = + Some (list of deleted nodes) if branch deleted + None if action replaced by previous version of action + [t] = remaining tree + [None] if failure *) + +value delete_rule_in_tree entry = + let rec delete_in_tree symbols tree = + match (symbols, tree) with + [ ([s :: sl], Node n) -> + if Tools.logically_eq_symbols entry s n.node then delete_son sl n + else + match delete_in_tree symbols n.brother with + [ Some (dsl, t) -> + Some (dsl, Node {node = n.node; son = n.son; brother = t}) + | None -> None ] + | ([_ :: _], _) -> None + | ([], Node n) -> + match delete_in_tree [] n.brother with + [ Some (dsl, t) -> + Some (dsl, Node {node = n.node; son = n.son; brother = t}) + | None -> None ] + | ([], DeadEnd) -> None + | ([], LocAct _ []) -> Some (Some [], DeadEnd) + | ([], LocAct _ [action :: list]) -> Some (None, LocAct action list) ] + and delete_son sl n = + match delete_in_tree sl n.son with + [ Some (Some dsl, DeadEnd) -> Some (Some [n.node :: dsl], n.brother) + | Some (Some dsl, t) -> + let t = Node {node = n.node; son = t; brother = n.brother} in + Some (Some [n.node :: dsl], t) + | Some (None, t) -> + let t = Node {node = n.node; son = t; brother = n.brother} in + Some (None, t) + | None -> None ] + in + delete_in_tree +; +value rec decr_keyw_use gram = + fun + [ Skeyword kwd -> removing gram kwd + | Smeta _ sl _ -> List.iter (decr_keyw_use gram) sl + | Slist0 s -> decr_keyw_use gram s + | Slist1 s -> decr_keyw_use gram s + | Slist0sep s1 s2 -> do { decr_keyw_use gram s1; decr_keyw_use gram s2 } + | Slist1sep s1 s2 -> do { decr_keyw_use gram s1; decr_keyw_use gram s2 } + | Sopt s -> decr_keyw_use gram s + | Stree t -> decr_keyw_use_in_tree gram t + | Sself | Snext | Snterm _ | Snterml _ _ | Stoken _ -> () ] +and decr_keyw_use_in_tree gram = + fun + [ DeadEnd | LocAct _ _ -> () + | Node n -> + do { + decr_keyw_use gram n.node; + decr_keyw_use_in_tree gram n.son; + decr_keyw_use_in_tree gram n.brother + } ] +; +value rec delete_rule_in_suffix entry symbols = + fun + [ [lev :: levs] -> + match delete_rule_in_tree entry symbols lev.lsuffix with + [ Some (dsl, t) -> + do { + match dsl with + [ Some dsl -> List.iter (decr_keyw_use entry.egram) dsl + | None -> () ]; + match t with + [ DeadEnd when lev.lprefix == DeadEnd -> levs + | _ -> + let lev = + {assoc = lev.assoc; lname = lev.lname; lsuffix = t; + lprefix = lev.lprefix} + in + [lev :: levs] ] + } + | None -> + let levs = delete_rule_in_suffix entry symbols levs in + [lev :: levs] ] + | [] -> raise Not_found ] +; + +value rec delete_rule_in_prefix entry symbols = + fun + [ [lev :: levs] -> + match delete_rule_in_tree entry symbols lev.lprefix with + [ Some (dsl, t) -> + do { + match dsl with + [ Some dsl -> List.iter (decr_keyw_use entry.egram) dsl + | None -> () ]; + match t with + [ DeadEnd when lev.lsuffix == DeadEnd -> levs + | _ -> + let lev = + {assoc = lev.assoc; lname = lev.lname; + lsuffix = lev.lsuffix; lprefix = t} + in + [lev :: levs] ] + } + | None -> + let levs = delete_rule_in_prefix entry symbols levs in + [lev :: levs] ] + | [] -> raise Not_found ] +; + +value rec delete_rule_in_level_list entry symbols levs = + match symbols with + [ [Sself :: symbols] -> delete_rule_in_suffix entry symbols levs + | [Snterm e :: symbols] when e == entry -> + delete_rule_in_suffix entry symbols levs + | _ -> delete_rule_in_prefix entry symbols levs ] +; + + +value delete_rule entry sl = + match entry.edesc with + [ Dlevels levs -> + let levs = delete_rule_in_level_list entry sl levs in + do { + entry.edesc := Dlevels levs; + entry.estart := + fun lev c strm -> + let f = Parser.start_parser_of_entry entry in + do { entry.estart := f; f lev c strm }; + entry.econtinue := + fun lev bp a c strm -> + let f = Parser.continue_parser_of_entry entry in + do { entry.econtinue := f; f lev bp a c strm } + } + | Dparser _ -> () ] +; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Dynamic.ml b/camlp4/Camlp4/Struct/Grammar/Dynamic.ml new file mode 100644 index 0000000..09b4397 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Dynamic.ml @@ -0,0 +1,72 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Lexer : Sig.Lexer) +: Sig.Grammar.Dynamic with module Loc = Lexer.Loc + and module Token = Lexer.Token += struct + module Structure = Structure.Make Lexer; + module Delete = Delete.Make Structure; + module Insert = Insert.Make Structure; + module Entry = Entry.Make Structure; + module Fold = Fold.Make Structure; + include Structure; + + value mk () = + let gkeywords = Hashtbl.create 301 in + { + gkeywords = gkeywords; + gfilter = Token.Filter.mk (Hashtbl.mem gkeywords); + glexer = Lexer.mk (); + warning_verbose = ref True; (* FIXME *) + error_verbose = Camlp4_config.verbose + }; + + value get_filter g = g.gfilter; + + value lex g loc cs = g.glexer loc cs; + + value lex_string g loc str = lex g loc (Stream.of_string str); + + value filter g ts = Token.Filter.filter g.gfilter ts; + + value parse_tokens_after_filter entry ts = Entry.parse_tokens_after_filter entry ts; + + value parse_tokens_before_filter entry ts = parse_tokens_after_filter entry (filter entry.egram ts); + + value parse entry loc cs = parse_tokens_before_filter entry (lex entry.egram loc cs); + + value parse_string entry loc str = + parse_tokens_before_filter entry (lex_string entry.egram loc str); + + value delete_rule = Delete.delete_rule; + + value srules e rl = + let t = + List.fold_left + (fun tree (symbols, action) -> Insert.insert_tree e symbols action tree) + DeadEnd rl + in + Stree t; + value sfold0 = Fold.sfold0; + value sfold1 = Fold.sfold1; + value sfold0sep = Fold.sfold0sep; + (* value sfold1sep = Fold.sfold1sep; *) + + value extend = Insert.extend; +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Entry.ml b/camlp4/Camlp4/Struct/Grammar/Entry.ml new file mode 100644 index 0000000..8402672 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Entry.ml @@ -0,0 +1,91 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + module Dump = Print.MakeDump Structure; + module Print = Print.Make Structure; + module Tools = Tools.Make Structure; + open Format; + open Structure; + + type t 'a = internal_entry; + + value name e = e.ename; + + value print ppf e = fprintf ppf "%a@\n" Print.entry e; + value dump ppf e = fprintf ppf "%a@\n" Dump.entry e; + + (* value find e s = Find.entry e s; *) + + value mk g n = + { egram = g; + ename = n; + estart = Tools.empty_entry n; + econtinue _ _ _ _ = parser []; + edesc = Dlevels [] }; + + value action_parse entry ts : Action.t = + Context.call_with_ctx ts + (fun c -> + try entry.estart 0 c (Context.stream c) with + [ Stream.Failure -> + Loc.raise (Context.loc_ep c) + (Stream.Error ("illegal begin of " ^ entry.ename)) + | Loc.Exc_located _ _ as exc -> raise exc + | exc -> Loc.raise (Context.loc_ep c) exc ]); + + value lex entry loc cs = entry.egram.glexer loc cs; + + value lex_string entry loc str = lex entry loc (Stream.of_string str); + + value filter entry ts = Token.Filter.filter (get_filter entry.egram) ts; + + value parse_tokens_after_filter entry ts = Action.get (action_parse entry ts); + + value parse_tokens_before_filter entry ts = parse_tokens_after_filter entry (filter entry ts); + + value parse entry loc cs = parse_tokens_before_filter entry (lex entry loc cs); + + value parse_string entry loc str = + parse_tokens_before_filter entry (lex_string entry loc str); + + value of_parser g n (p : Stream.t (Token.t * Loc.t) -> 'a) : t 'a = + { egram = g; + ename = n; + estart _ _ ts = Action.mk (p ts); + econtinue _ _ _ _ = parser []; + edesc = Dparser (fun ts -> Action.mk (p ts)) }; + + value setup_parser e (p : Stream.t (Token.t * Loc.t) -> 'a) = + let f ts = Action.mk (p ts) in do { + e.estart := fun _ _ -> f; + e.econtinue := fun _ _ _ _ -> parser []; + e.edesc := Dparser f + }; + + value clear e = + do { + e.estart := fun _ _ -> parser []; + e.econtinue := fun _ _ _ _ -> parser []; + e.edesc := Dlevels [] + }; + + value obj x = x; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Failed.ml b/camlp4/Camlp4/Struct/Grammar/Failed.ml new file mode 100644 index 0000000..ee3eff5 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Failed.ml @@ -0,0 +1,134 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + module Tools = Tools.Make Structure; + module Search = Search.Make Structure; + module Print = Print.Make Structure; + open Structure; + open Format; + +value rec name_of_symbol entry = + fun + [ Snterm e -> "[" ^ e.ename ^ "]" + | Snterml e l -> "[" ^ e.ename ^ " level " ^ l ^ "]" + | Sself | Snext -> "[" ^ entry.ename ^ "]" + | Stoken (_, descr) -> descr + | Skeyword kwd -> "\"" ^ kwd ^ "\"" + | _ -> "???" ] +; + + +value rec name_of_symbol_failed entry = + fun + [ Slist0 s -> name_of_symbol_failed entry s + | Slist0sep s _ -> name_of_symbol_failed entry s + | Slist1 s -> name_of_symbol_failed entry s + | Slist1sep s _ -> name_of_symbol_failed entry s + | Sopt s -> name_of_symbol_failed entry s + | Stree t -> name_of_tree_failed entry t + | s -> name_of_symbol entry s ] +and name_of_tree_failed entry = + fun + [ Node {node = s; brother = bro; son = son} -> + let tokl = + match s with + [ Stoken _ | Skeyword _ -> Tools.get_token_list entry [] s son + | _ -> None ] + in + match tokl with + [ None -> + let txt = name_of_symbol_failed entry s in + let txt = + match (s, son) with + [ (Sopt _, Node _) -> txt ^ " or " ^ name_of_tree_failed entry son + | _ -> txt ] + in + let txt = + match bro with + [ DeadEnd | LocAct _ _ -> txt + | Node _ -> txt ^ " or " ^ name_of_tree_failed entry bro ] + in + txt + | Some (tokl, _, _) -> + List.fold_left + (fun s tok -> + (if s = "" then "" else s ^ " then ") ^ + match tok with + [ Stoken (_, descr) -> descr + | Skeyword kwd -> kwd + | _ -> assert False ]) + "" tokl ] + | DeadEnd | LocAct _ _ -> "???" ] +; +value magic _s x = debug magic "Obj.magic: %s@." _s in Obj.magic x; +value tree_failed entry prev_symb_result prev_symb tree = + let txt = name_of_tree_failed entry tree in + let txt = + match prev_symb with + [ Slist0 s -> + let txt1 = name_of_symbol_failed entry s in + txt1 ^ " or " ^ txt ^ " expected" + | Slist1 s -> + let txt1 = name_of_symbol_failed entry s in + txt1 ^ " or " ^ txt ^ " expected" + | Slist0sep s sep -> + match magic "tree_failed: 'a -> list 'b" prev_symb_result with + [ [] -> + let txt1 = name_of_symbol_failed entry s in + txt1 ^ " or " ^ txt ^ " expected" + | _ -> + let txt1 = name_of_symbol_failed entry sep in + txt1 ^ " or " ^ txt ^ " expected" ] + | Slist1sep s sep -> + match magic "tree_failed: 'a -> list 'b" prev_symb_result with + [ [] -> + let txt1 = name_of_symbol_failed entry s in + txt1 ^ " or " ^ txt ^ " expected" + | _ -> + let txt1 = name_of_symbol_failed entry sep in + txt1 ^ " or " ^ txt ^ " expected" ] + | Sopt _ | Stree _ -> txt ^ " expected" + | _ -> txt ^ " expected after " ^ name_of_symbol entry prev_symb ] + in + do { + if entry.egram.error_verbose.val then do { + let tree = Search.tree_in_entry prev_symb tree entry.edesc; + let ppf = err_formatter; + fprintf ppf "@[@,"; + fprintf ppf "----------------------------------@,"; + fprintf ppf "Parse error in entry [%s], rule:@;<0 2>" entry.ename; + fprintf ppf "@["; + Print.print_level ppf pp_force_newline (Print.flatten_tree tree); + fprintf ppf "@]@,"; + fprintf ppf "----------------------------------@,"; + fprintf ppf "@]@." + } + else (); + txt ^ " (in [" ^ entry.ename ^ "])" + } +; +value symb_failed entry prev_symb_result prev_symb symb = + let tree = Node {node = symb; brother = DeadEnd; son = DeadEnd} in + tree_failed entry prev_symb_result prev_symb tree +; + +value symb_failed_txt e s1 s2 = symb_failed e 0 s1 s2; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Find.ml b/camlp4/Camlp4/Struct/Grammar/Find.ml new file mode 100644 index 0000000..9e7774d --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Find.ml @@ -0,0 +1,68 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +(* + value entry e s = + let rec find_levels = + fun + [ [] -> None + | [lev :: levs] -> + match find_tree lev.lsuffix with + [ None -> + match find_tree lev.lprefix with + [ None -> find_levels levs + | x -> x ] + | x -> x ] ] + and symbol = + fun + [ Snterm e -> if e.ename = s then Some e else None + | Snterml e _ -> if e.ename = s then Some e else None + | Smeta _ sl _ -> find_symbol_list sl + | Slist0 s -> find_symbol s + | Slist0sep s _ -> find_symbol s + | Slist1 s -> find_symbol s + | Slist1sep s _ -> find_symbol s + | Sopt s -> find_symbol s + | Stree t -> find_tree t + | Sself | Snext | Stoken _ | Stoken_fun _ -> None ] + and symbol_list = + fun + [ [s :: sl] -> + match find_symbol s with + [ None -> find_symbol_list sl + | x -> x ] + | [] -> None ] + and tree = + fun + [ Node {node = s; brother = bro; son = son} -> + match find_symbol s with + [ None -> + match find_tree bro with + [ None -> find_tree son + | x -> x ] + | x -> x ] + | LocAct _ _ | DeadEnd -> None ] + in + match e.edesc with + [ Dlevels levs -> + match find_levels levs with + [ Some e -> e + | None -> raise Not_found ] + | Dparser _ -> raise Not_found ] + ; +*) diff --git a/camlp4/Camlp4/Struct/Grammar/Fold.ml b/camlp4/Camlp4/Struct/Grammar/Fold.ml new file mode 100644 index 0000000..6da366f --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Fold.ml @@ -0,0 +1,94 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + + + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Structure : Structure.S) = struct + open Structure; + open Format; + module Parse = Parser.Make Structure; + module Fail = Failed.Make Structure; + open Sig.Grammar; + + module Stream = struct + include Stream; + value junk strm = Context.junk strm; + value count strm = Context.bp strm; + end; + + value sfold0 f e _entry _symbl psymb = + let rec fold accu = + parser + [ [: a = psymb; s :] -> fold (f a accu) s + | [: :] -> accu ] + in + parser [: a = fold e :] -> a + ; + + value sfold1 f e _entry _symbl psymb = + let rec fold accu = + parser + [ [: a = psymb; s :] -> fold (f a accu) s + | [: :] -> accu ] + in + parser [: a = psymb; a = fold (f a e) :] -> a + ; + + value sfold0sep f e entry symbl psymb psep = + let failed = + fun + [ [symb; sep] -> Fail.symb_failed_txt entry sep symb + | _ -> "failed" ] + in + let rec kont accu = + parser + [ [: () = psep; a = psymb ?? failed symbl; s :] -> kont (f a accu) s + | [: :] -> accu ] + in + parser + [ [: a = psymb; s :] -> kont (f a e) s + | [: :] -> e ] + ; + + value sfold1sep f e entry symbl psymb psep = + let failed = + fun + [ [symb; sep] -> Fail.symb_failed_txt entry sep symb + | _ -> "failed" ] + in + let parse_top = + fun + [ [symb; _] -> Parse.parse_top_symb entry symb (* FIXME context *) + | _ -> raise Stream.Failure ] + in + let rec kont accu = + parser + [ [: () = psep; + a = + parser + [ [: a = psymb :] -> a + | [: a = parse_top symbl :] -> Obj.magic a + | [: :] -> raise (Stream.Error (failed symbl)) ]; + s :] -> + kont (f a accu) s + | [: :] -> accu ] + in + parser [: a = psymb; s :] -> kont (f a e) s + ; +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Fold.mli b/camlp4/Camlp4/Struct/Grammar/Fold.mli new file mode 100644 index 0000000..0b9b22b --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Fold.mli @@ -0,0 +1,30 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + + + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) : sig + open Structure; + + value sfold0 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold1 : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b; + value sfold0sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; + (* value sfold1sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; *) +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Insert.ml b/camlp4/Camlp4/Struct/Grammar/Insert.ml new file mode 100644 index 0000000..fc506a7 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Insert.ml @@ -0,0 +1,328 @@ +(* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + module Tools = Tools.Make Structure; + module Parser = Parser.Make Structure; + open Structure; + open Format; + open Sig.Grammar; + + value is_before s1 s2 = + match (s1, s2) with + [ (Skeyword _ | Stoken _, Skeyword _ | Stoken _) -> False + | (Skeyword _ | Stoken _, _) -> True + | _ -> False ] + ; + value rec derive_eps = + fun + [ Slist0 _ -> True + | Slist0sep _ _ -> True + | Sopt _ -> True + | Stree t -> tree_derive_eps t + | Smeta _ _ _ | Slist1 _ | Slist1sep _ _ | Snterm _ | Snterml _ _ | Snext | + Sself | Stoken _ | Skeyword _ -> False ] + and tree_derive_eps = + fun + [ LocAct _ _ -> True + | Node {node = s; brother = bro; son = son} -> + derive_eps s && tree_derive_eps son || tree_derive_eps bro + | DeadEnd -> False ] + ; + + value empty_lev lname assoc = + let assoc = + match assoc with + [ Some a -> a + | None -> LeftA ] + in + {assoc = assoc; lname = lname; lsuffix = DeadEnd; lprefix = DeadEnd} + ; + value change_lev entry lev n lname assoc = + let a = + match assoc with + [ None -> lev.assoc + | Some a -> + do { + if a <> lev.assoc && entry.egram.warning_verbose.val then do { + eprintf " Changing associativity of level \"%s\"\n" n; + flush stderr + } + else (); + a + } ] + in + do { + match lname with + [ Some n -> + if lname <> lev.lname && entry.egram.warning_verbose.val then do { + eprintf " Level label \"%s\" ignored\n" n; flush stderr + } + else () + | None -> () ]; + {assoc = a; lname = lev.lname; lsuffix = lev.lsuffix; + lprefix = lev.lprefix} + } + ; + value change_to_self entry = + fun + [ Snterm e when e == entry -> Sself + | x -> x ] + ; + + + value get_level entry position levs = + match position with + [ Some First -> ([], empty_lev, levs) + | Some Last -> (levs, empty_lev, []) + | Some (Level n) -> + let rec get = + fun + [ [] -> + do { + eprintf "No level labelled \"%s\" in entry \"%s\"\n" n + entry.ename; + flush stderr; + failwith "Grammar.extend" + } + | [lev :: levs] -> + if Tools.is_level_labelled n lev then ([], change_lev entry lev n, levs) + else + let (levs1, rlev, levs2) = get levs in + ([lev :: levs1], rlev, levs2) ] + in + get levs + | Some (Before n) -> + let rec get = + fun + [ [] -> + do { + eprintf "No level labelled \"%s\" in entry \"%s\"\n" n + entry.ename; + flush stderr; + failwith "Grammar.extend" + } + | [lev :: levs] -> + if Tools.is_level_labelled n lev then ([], empty_lev, [lev :: levs]) + else + let (levs1, rlev, levs2) = get levs in + ([lev :: levs1], rlev, levs2) ] + in + get levs + | Some (After n) -> + let rec get = + fun + [ [] -> + do { + eprintf "No level labelled \"%s\" in entry \"%s\"\n" n + entry.ename; + flush stderr; + failwith "Grammar.extend" + } + | [lev :: levs] -> + if Tools.is_level_labelled n lev then ([lev], empty_lev, levs) + else + let (levs1, rlev, levs2) = get levs in + ([lev :: levs1], rlev, levs2) ] + in + get levs + | None -> + match levs with + [ [lev :: levs] -> ([], change_lev entry lev "", levs) + | [] -> ([], empty_lev, []) ] ] + ; + + value rec check_gram entry = + fun + [ Snterm e -> + if e.egram != entry.egram then do { + eprintf "\ + Error: entries \"%s\" and \"%s\" do not belong to the same grammar.\n" + entry.ename e.ename; + flush stderr; + failwith "Grammar.extend error" + } + else () + | Snterml e _ -> + if e.egram != entry.egram then do { + eprintf "\ + Error: entries \"%s\" and \"%s\" do not belong to the same grammar.\n" + entry.ename e.ename; + flush stderr; + failwith "Grammar.extend error" + } + else () + | Smeta _ sl _ -> List.iter (check_gram entry) sl + | Slist0sep s t -> do { check_gram entry t; check_gram entry s } + | Slist1sep s t -> do { check_gram entry t; check_gram entry s } + | Slist0 s -> check_gram entry s + | Slist1 s -> check_gram entry s + | Sopt s -> check_gram entry s + | Stree t -> tree_check_gram entry t + | Snext | Sself | Stoken _ | Skeyword _ -> () ] + and tree_check_gram entry = + fun + [ Node {node = n; brother = bro; son = son} -> + do { + check_gram entry n; + tree_check_gram entry bro; + tree_check_gram entry son + } + | LocAct _ _ | DeadEnd -> () ] + ; + value get_initial = + fun + [ [Sself :: symbols] -> (True, symbols) + | symbols -> (False, symbols) ] + ; + + + value insert_tokens gram symbols = + let rec insert = + fun + [ Smeta _ sl _ -> List.iter insert sl + | Slist0 s -> insert s + | Slist1 s -> insert s + | Slist0sep s t -> do { insert s; insert t } + | Slist1sep s t -> do { insert s; insert t } + | Sopt s -> insert s + | Stree t -> tinsert t + | Skeyword kwd -> using gram kwd + | Snterm _ | Snterml _ _ | Snext | Sself | Stoken _ -> () ] + and tinsert = + fun + [ Node {node = s; brother = bro; son = son} -> + do { insert s; tinsert bro; tinsert son } + | LocAct _ _ | DeadEnd -> () ] + in + List.iter insert symbols + ; + + value insert_tree entry gsymbols action tree = + let rec insert symbols tree = + match symbols with + [ [s :: sl] -> insert_in_tree s sl tree + | [] -> + match tree with + [ Node {node = s; son = son; brother = bro} -> + Node {node = s; son = son; brother = insert [] bro} + | LocAct old_action action_list -> + let () = + if entry.egram.warning_verbose.val then + eprintf " Grammar extension: in [%s] some rule has been masked@." + entry.ename + else () + in LocAct action [old_action :: action_list] + | DeadEnd -> LocAct action [] ] ] + and insert_in_tree s sl tree = + match try_insert s sl tree with + [ Some t -> t + | None -> Node {node = s; son = insert sl DeadEnd; brother = tree} ] + and try_insert s sl tree = + match tree with + [ Node {node = s1; son = son; brother = bro} -> + if Tools.eq_symbol s s1 then + let t = Node {node = s1; son = insert sl son; brother = bro} in + Some t + else if is_before s1 s || derive_eps s && not (derive_eps s1) then + let bro = + match try_insert s sl bro with + [ Some bro -> bro + | None -> + Node {node = s; son = insert sl DeadEnd; brother = bro} ] + in + let t = Node {node = s1; son = son; brother = bro} in + Some t + else + match try_insert s sl bro with + [ Some bro -> + let t = Node {node = s1; son = son; brother = bro} in + Some t + | None -> None ] + | LocAct _ _ | DeadEnd -> None ] + and insert_new = + fun + [ [s :: sl] -> Node {node = s; son = insert_new sl; brother = DeadEnd} + | [] -> LocAct action [] ] + in + insert gsymbols tree + ; + value insert_level entry e1 symbols action slev = + match e1 with + [ True -> + {assoc = slev.assoc; lname = slev.lname; + lsuffix = insert_tree entry symbols action slev.lsuffix; + lprefix = slev.lprefix} + | False -> + {assoc = slev.assoc; lname = slev.lname; lsuffix = slev.lsuffix; + lprefix = insert_tree entry symbols action slev.lprefix} ] + ; + + value levels_of_rules entry position rules = + let elev = + match entry.edesc with + [ Dlevels elev -> elev + | Dparser _ -> + do { + eprintf "Error: entry not extensible: \"%s\"\n" entry.ename; + flush stderr; + failwith "Grammar.extend" + } ] + in + if rules = [] then elev + else + let (levs1, make_lev, levs2) = get_level entry position elev in + let (levs, _) = + List.fold_left + (fun (levs, make_lev) (lname, assoc, level) -> + let lev = make_lev lname assoc in + let lev = + List.fold_left + (fun lev (symbols, action) -> + let symbols = List.map (change_to_self entry) symbols in + do { + List.iter (check_gram entry) symbols; + let (e1, symbols) = get_initial symbols; + insert_tokens entry.egram symbols; + insert_level entry e1 symbols action lev + }) + lev level + in + ([lev :: levs], empty_lev)) + ([], make_lev) rules + in + levs1 @ List.rev levs @ levs2 + ; + + value extend entry (position, rules) = + let elev = levels_of_rules entry position rules in + do { + entry.edesc := Dlevels elev; + entry.estart := + fun lev c strm -> + let f = Parser.start_parser_of_entry entry in + do { entry.estart := f; f lev c strm }; + entry.econtinue := + fun lev bp a c strm -> + let f = Parser.continue_parser_of_entry entry in + do { entry.econtinue := f; f lev bp a c strm } + }; + + end; diff --git a/camlp4/Camlp4/Struct/Grammar/Parser.ml b/camlp4/Camlp4/Struct/Grammar/Parser.ml new file mode 100644 index 0000000..715c48f --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Parser.ml @@ -0,0 +1,382 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + module Tools = Tools.Make Structure; + module Failed = Failed.Make Structure; + module Print = Print.Make Structure; + open Structure; + open Sig.Grammar; + + module Stream = struct + include Stream; + value junk strm = Context.junk strm; + value count strm = Context.bp strm; + end; + + value add_loc c bp parse_fun strm = + let x = parse_fun c strm in + let ep = Context.loc_ep c in + let loc = Loc.merge bp ep in + (x, loc); + + value level_number entry lab = + let rec lookup levn = + fun + [ [] -> failwith ("unknown level " ^ lab) + | [lev :: levs] -> + if Tools.is_level_labelled lab lev then levn else lookup (succ levn) levs ] + in + match entry.edesc with + [ Dlevels elev -> lookup 0 elev + | Dparser _ -> raise Not_found ] + ; + value strict_parsing = ref False; + value strict_parsing_warning = ref False; + + value rec top_symb entry = + fun + [ Sself | Snext -> Snterm entry + | Snterml e _ -> Snterm e + | Slist1sep s sep -> Slist1sep (top_symb entry s) sep + | _ -> raise Stream.Failure ] + ; + + value top_tree entry = + fun + [ Node {node = s; brother = bro; son = son} -> + Node {node = top_symb entry s; brother = bro; son = son} + | LocAct _ _ | DeadEnd -> raise Stream.Failure ] + ; + + value entry_of_symb entry = + fun + [ Sself | Snext -> entry + | Snterm e -> e + | Snterml e _ -> e + | _ -> raise Stream.Failure ] + ; + + value continue entry loc a s c son p1 = + parser + [: a = (entry_of_symb entry s).econtinue 0 loc a c; + act = p1 ?? Failed.tree_failed entry a s son :] -> + Action.mk (fun _ -> Action.getf act a) + ; + + (* PR#4603, PR#4330, PR#4551: + Here Context.loc_bp replaced Context.loc_ep to fix all these bugs. + If you do change it again look at these bugs. *) + value skip_if_empty c bp _ = + if Context.loc_bp c = bp then Action.mk (fun _ -> raise Stream.Failure) + else + raise Stream.Failure + ; + + value do_recover parser_of_tree entry nlevn alevn loc a s c son = + parser + [ [: a = parser_of_tree entry nlevn alevn (top_tree entry son) c :] -> a + | [: a = skip_if_empty c loc :] -> a + | [: a = + continue entry loc a s c son + (parser_of_tree entry nlevn alevn son c) :] -> + a ] + ; + + + value recover parser_of_tree entry nlevn alevn loc a s c son strm = + if strict_parsing.val then raise (Stream.Error (Failed.tree_failed entry a s son)) + else + let _ = + if strict_parsing_warning.val then + do { + let msg = Failed.tree_failed entry a s son; + Format.eprintf "Warning: trying to recover from syntax error"; + if entry.ename <> "" then Format.eprintf " in [%s]" entry.ename else (); + Format.eprintf "\n%s%a@." msg Loc.print loc; + } else () in + do_recover parser_of_tree entry nlevn alevn loc a s c son strm + ; + + value rec parser_of_tree entry nlevn alevn = + fun + [ DeadEnd -> fun _ -> parser [] + | LocAct act _ -> fun _ -> parser [: :] -> act + | Node {node = Sself; son = LocAct act _; brother = DeadEnd} -> + fun c -> + parser [: a = entry.estart alevn c :] -> Action.getf act a + | Node {node = Sself; son = LocAct act _; brother = bro} -> + let p2 = parser_of_tree entry nlevn alevn bro in + fun c -> + parser + [ [: a = entry.estart alevn c :] -> Action.getf act a + | [: a = p2 c :] -> a ] + | Node {node = s; son = son; brother = DeadEnd} -> + let tokl = + match s with + [ Stoken _ | Skeyword _ -> Tools.get_token_list entry [] s son + | _ -> None ] + in + match tokl with + [ None -> + let ps = parser_of_symbol entry nlevn s in + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = parser_cont p1 entry nlevn alevn s son in + fun c -> + parser bp [: a = ps c; act = p1 c bp a :] -> Action.getf act a + | Some (tokl, last_tok, son) -> + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = parser_cont p1 entry nlevn alevn last_tok son in + parser_of_token_list p1 tokl ] + | Node {node = s; son = son; brother = bro} -> + let tokl = + match s with + [ Stoken _ | Skeyword _ -> Tools.get_token_list entry [] s son + | _ -> None ] + in + match tokl with + [ None -> + let ps = parser_of_symbol entry nlevn s in + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = parser_cont p1 entry nlevn alevn s son in + let p2 = parser_of_tree entry nlevn alevn bro in + fun c -> + parser bp + [ [: a = ps c; act = p1 c bp a :] -> Action.getf act a + | [: a = p2 c :] -> a ] + | Some (tokl, last_tok, son) -> + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = parser_cont p1 entry nlevn alevn last_tok son in + let p1 = parser_of_token_list p1 tokl in + let p2 = parser_of_tree entry nlevn alevn bro in + fun c -> + parser + [ [: a = p1 c :] -> a + | [: a = p2 c :] -> a ] ] ] + and parser_cont p1 entry nlevn alevn s son c loc a = + parser + [ [: a = p1 c :] -> a + | [: a = recover parser_of_tree entry nlevn alevn loc a s c son :] -> a + | [: :] -> raise (Stream.Error (Failed.tree_failed entry a s son)) ] + and parser_of_token_list p1 tokl = + loop 1 tokl where rec loop n = + fun + [ [Stoken (tematch, _) :: tokl] -> + match tokl with + [ [] -> + let ps c _ = + match Context.peek_nth c n with + [ Some (tok, _) when tematch tok -> do { Context.njunk c n; Action.mk tok } + | _ -> raise Stream.Failure ] + in + fun c -> + parser bp [: a = ps c; act = p1 c bp a :] -> Action.getf act a + | _ -> + let ps c _ = + match Context.peek_nth c n with + [ Some (tok, _) when tematch tok -> tok + | _ -> raise Stream.Failure ] + in + let p1 = loop (n + 1) tokl in + fun c -> + parser [: tok = ps c; s :] -> + let act = p1 c s in Action.getf act tok ] + | [Skeyword kwd :: tokl] -> + match tokl with + [ [] -> + let ps c _ = + match Context.peek_nth c n with + [ Some (tok, _) when Token.match_keyword kwd tok -> + do { Context.njunk c n; Action.mk tok } + | _ -> raise Stream.Failure ] + in + fun c -> + parser bp [: a = ps c; act = p1 c bp a :] -> Action.getf act a + | _ -> + let ps c _ = + match Context.peek_nth c n with + [ Some (tok, _) when Token.match_keyword kwd tok -> tok + | _ -> raise Stream.Failure ] + in + let p1 = loop (n + 1) tokl in + fun c -> + parser [: tok = ps c; s :] -> + let act = p1 c s in Action.getf act tok ] + | _ -> invalid_arg "parser_of_token_list" ] + and parser_of_symbol entry nlevn = + fun + [ Smeta _ symbl act -> + let act = Obj.magic act entry symbl in + let pl = List.map (parser_of_symbol entry nlevn) symbl in + fun c -> + Obj.magic (List.fold_left (fun act p -> Obj.magic act (p c)) act pl) + | Slist0 s -> + let ps = parser_of_symbol entry nlevn s in + let rec loop c al = + parser + [ [: a = ps c; s :] -> loop c [a :: al] s + | [: :] -> al ] + in + fun c -> parser [: a = loop c [] :] -> Action.mk (List.rev a) + | Slist0sep symb sep -> + let ps = parser_of_symbol entry nlevn symb in + let pt = parser_of_symbol entry nlevn sep in + let rec kont c al = + parser + [ [: v = pt c; a = ps c ?? Failed.symb_failed entry v sep symb; + s :] -> + kont c [a :: al] s + | [: :] -> al ] + in + fun c -> + parser + [ [: a = ps c; s :] -> Action.mk (List.rev (kont c [a] s)) + | [: :] -> Action.mk [] ] + | Slist1 s -> + let ps = parser_of_symbol entry nlevn s in + let rec loop c al = + parser + [ [: a = ps c; s :] -> loop c [a :: al] s + | [: :] -> al ] + in + fun c -> + parser [: a = ps c; s :] -> Action.mk (List.rev (loop c [a] s)) + | Slist1sep symb sep -> + let ps = parser_of_symbol entry nlevn symb in + let pt = parser_of_symbol entry nlevn sep in + let rec kont c al = + parser + [ [: v = pt c; + a = + parser + [ [: a = ps c :] -> a + | [: a = parse_top_symb' entry symb c :] -> a + | [: :] -> + raise (Stream.Error (Failed.symb_failed entry v sep symb)) ]; + s :] -> + kont c [a :: al] s + | [: :] -> al ] + in + fun c -> + parser [: a = ps c; s :] -> Action.mk (List.rev (kont c [a] s)) + | Sopt s -> + let ps = parser_of_symbol entry nlevn s in + fun c -> + parser + [ [: a = ps c :] -> Action.mk (Some a) + | [: :] -> Action.mk None ] + | Stree t -> + let pt = parser_of_tree entry 1 0 t in + fun c -> + parser bp [: (act, loc) = add_loc c bp pt :] -> + Action.getf act loc + | Snterm e -> fun c -> parser [: a = e.estart 0 c :] -> a + | Snterml e l -> + fun c -> parser [: a = e.estart (level_number e l) c :] -> a + | Sself -> fun c -> parser [: a = entry.estart 0 c :] -> a + | Snext -> fun c -> parser [: a = entry.estart nlevn c :] -> a + | Skeyword kwd -> + fun _ -> + parser + [: `(tok, _) when Token.match_keyword kwd tok :] -> Action.mk tok + | Stoken (f, _) -> + fun _ -> parser [: `(tok, _) when f tok :] -> Action.mk tok ] + and parse_top_symb' entry symb c = + parser_of_symbol entry 0 (top_symb entry symb) c + and parse_top_symb entry symb = + fun strm -> + Context.call_with_ctx strm + (fun c -> parse_top_symb' entry symb c (Context.stream c)); + + value rec start_parser_of_levels entry clevn = + fun + [ [] -> fun _ _ -> parser [] + | [lev :: levs] -> + let p1 = start_parser_of_levels entry (succ clevn) levs in + match lev.lprefix with + [ DeadEnd -> p1 + | tree -> + let alevn = + match lev.assoc with + [ LeftA | NonA -> succ clevn + | RightA -> clevn ] + in + let p2 = parser_of_tree entry (succ clevn) alevn tree in + match levs with + [ [] -> + fun levn c -> + parser bp + [: (act, loc) = add_loc c bp p2; strm :] -> + let a = Action.getf act loc in + entry.econtinue levn loc a c strm + | _ -> + fun levn c strm -> + if levn > clevn then p1 levn c strm + else + match strm with parser bp + [ [: (act, loc) = add_loc c bp p2 :] -> + let a = Action.getf act loc in + entry.econtinue levn loc a c strm + | [: act = p1 levn c :] -> act ] ] ] ] + ; + + value start_parser_of_entry entry = + debug gram "start_parser_of_entry: @[<2>%a@]@." Print.entry entry in + match entry.edesc with + [ Dlevels [] -> Tools.empty_entry entry.ename + | Dlevels elev -> start_parser_of_levels entry 0 elev + | Dparser p -> fun _ _ strm -> p strm ] + ; + value rec continue_parser_of_levels entry clevn = + fun + [ [] -> fun _ _ _ _ -> parser [] + | [lev :: levs] -> + let p1 = continue_parser_of_levels entry (succ clevn) levs in + match lev.lsuffix with + [ DeadEnd -> p1 + | tree -> + let alevn = + match lev.assoc with + [ LeftA | NonA -> succ clevn + | RightA -> clevn ] + in + let p2 = parser_of_tree entry (succ clevn) alevn tree in + fun c levn bp a strm -> + if levn > clevn then p1 c levn bp a strm + else + match strm with parser + [ [: act = p1 c levn bp a :] -> act + | [: (act, loc) = add_loc c bp p2 :] -> + let a = Action.getf2 act a loc in + entry.econtinue levn loc a c strm ] ] ] + ; + + value continue_parser_of_entry entry = + debug gram "continue_parser_of_entry: @[<2>%a@]@." Print.entry entry in + match entry.edesc with + [ Dlevels elev -> + let p = continue_parser_of_levels entry 0 elev in + fun levn bp a c -> + parser + [ [: a = p c levn bp a :] -> a + | [: :] -> a ] + | Dparser _ -> fun _ _ _ _ -> parser [] ] + ; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Parser.mli b/camlp4/Camlp4/Struct/Grammar/Parser.mli new file mode 100644 index 0000000..695982a --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Parser.mli @@ -0,0 +1,68 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2007 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + + + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) : sig + open Structure; + open Context; + value add_loc : + Context.t -> Loc.t -> (Context.t -> 'a -> 'b) -> 'a -> ('b * Loc.t); + value level_number : internal_entry -> string -> int; + value strict_parsing : ref bool; + value strict_parsing_warning : ref bool; + value top_symb : + internal_entry -> symbol -> symbol; + value top_tree : + internal_entry -> tree -> tree; + value entry_of_symb : + internal_entry -> symbol -> internal_entry; + value continue : + internal_entry -> Loc.t -> Action.t -> symbol -> Context.t -> tree -> + (Stream.t (Token.t * Loc.t) -> Action.t) -> Stream.t (Token.t * Loc.t) -> Action.t; + value do_recover : + (internal_entry -> 'a -> 'b -> tree -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t) -> internal_entry -> + 'a -> 'b -> Loc.t -> Action.t -> symbol -> Context.t -> tree -> Stream.t (Token.t * Loc.t) -> Action.t; + value recover : + (internal_entry -> 'a -> 'b -> tree -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t) -> internal_entry -> + 'a -> 'b -> Loc.t -> Action.t -> symbol -> Context.t -> tree -> Stream.t (Token.t * Loc.t) -> Action.t; + value parser_of_tree : + internal_entry -> int -> int -> tree -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value parser_cont : + (Context.t -> Stream.t (Token.t * Loc.t) -> Action.t) -> internal_entry -> int -> int -> symbol -> tree -> + Context.t -> Loc.t -> Action.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value parser_of_token_list : + (Context.t -> Loc.t -> Action.t -> Stream.t (Token.t * Loc.t) -> Action.t) -> list symbol -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value parser_of_symbol : + internal_entry -> int -> symbol -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value parse_top_symb' : + internal_entry -> symbol -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value parse_top_symb : + internal_entry -> symbol -> Stream.t (Token.t * Loc.t) -> Action.t; + value start_parser_of_levels : + internal_entry -> int -> list level -> int -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value start_parser_of_entry : + internal_entry -> int -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + value continue_parser_of_levels : + internal_entry -> int -> list level -> Context.t -> int -> Loc.t -> 'a -> Stream.t (Token.t * Loc.t) -> Action.t; + value continue_parser_of_entry : + internal_entry -> int -> Loc.t -> Action.t -> Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; +end; + diff --git a/camlp4/Camlp4/Struct/Grammar/Print.ml b/camlp4/Camlp4/Struct/Grammar/Print.ml new file mode 100644 index 0000000..f5a9723 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Print.ml @@ -0,0 +1,268 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) = struct + open Structure; + open Format; + open Sig.Grammar; + + value rec flatten_tree = + fun + [ DeadEnd -> [] + | LocAct _ _ -> [[]] + | Node {node = n; brother = b; son = s} -> + [ [n :: l] | l <- flatten_tree s ] @ flatten_tree b ]; + + value rec print_symbol ppf = + fun + [ Smeta n sl _ -> print_meta ppf n sl + | Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s + | Slist0sep s t -> + fprintf ppf "LIST0 %a SEP %a" print_symbol1 s print_symbol1 t + | Slist1 s -> fprintf ppf "LIST1 %a" print_symbol1 s + | Slist1sep s t -> + fprintf ppf "LIST1 %a SEP %a" print_symbol1 s print_symbol1 t + | Sopt s -> fprintf ppf "OPT %a" print_symbol1 s + | Snterml e l -> fprintf ppf "%s@ LEVEL@ %S" e.ename l + | Snterm _ | Snext | Sself | Stree _ | Stoken _ | Skeyword _ as s -> + print_symbol1 ppf s ] + and print_meta ppf n sl = + loop 0 sl where rec loop i = + fun + [ [] -> () + | [s :: sl] -> + let j = + try String.index_from n i ' ' with [ Not_found -> String.length n ] + in + do { + fprintf ppf "%s %a" (String.sub n i (j - i)) print_symbol1 s; + if sl = [] then () + else do { fprintf ppf " "; loop (min (j + 1) (String.length n)) sl } + } ] + and print_symbol1 ppf = + fun + [ Snterm e -> pp_print_string ppf e.ename + | Sself -> pp_print_string ppf "SELF" + | Snext -> pp_print_string ppf "NEXT" + | Stoken (_, descr) -> pp_print_string ppf descr + | Skeyword s -> fprintf ppf "%S" s + | Stree t -> print_level ppf pp_print_space (flatten_tree t) + | Smeta _ _ _ | Snterml _ _ | Slist0 _ | Slist0sep _ _ | Slist1 _ | + Slist1sep _ _ | Sopt _ as s -> + fprintf ppf "(%a)" print_symbol s ] + and print_rule ppf symbols = + do { + fprintf ppf "@["; + let _ = + List.fold_left + (fun sep symbol -> + do { + fprintf ppf "%t%a" sep print_symbol symbol; + fun ppf -> fprintf ppf ";@ " + }) + (fun _ -> ()) symbols + in + fprintf ppf "@]" + } + and print_level ppf pp_print_space rules = + do { + fprintf ppf "@[[ "; + let _ = + List.fold_left + (fun sep rule -> + do { + fprintf ppf "%t%a" sep print_rule rule; + fun ppf -> fprintf ppf "%a| " pp_print_space () + }) + (fun _ -> ()) rules + in + fprintf ppf " ]@]" + } + ; + + value levels ppf elev = + let _ = + List.fold_left + (fun sep lev -> + let rules = + [ [Sself :: t] | t <- flatten_tree lev.lsuffix ] @ + flatten_tree lev.lprefix + in + do { + fprintf ppf "%t@[" sep; + match lev.lname with + [ Some n -> fprintf ppf "%S@;<1 2>" n + | None -> () ]; + match lev.assoc with + [ LeftA -> fprintf ppf "LEFTA" + | RightA -> fprintf ppf "RIGHTA" + | NonA -> fprintf ppf "NONA" ]; + fprintf ppf "@]@;<1 2>"; + print_level ppf pp_force_newline rules; + fun ppf -> fprintf ppf "@,| " + }) + (fun _ -> ()) elev + in + (); + + value entry ppf e = + do { + fprintf ppf "@[%s: [ " e.ename; + match e.edesc with + [ Dlevels elev -> levels ppf elev + | Dparser _ -> fprintf ppf "" ]; + fprintf ppf " ]@]" + }; + +end; + +module MakeDump (Structure : Structure.S) = struct + open Structure; + open Format; + open Sig.Grammar; + + type brothers = [ Bro of symbol and list brothers ]; + + value rec print_tree ppf tree = + let rec get_brothers acc = + fun + [ DeadEnd -> List.rev acc + | LocAct _ _ -> List.rev acc + | Node {node = n; brother = b; son = s} -> get_brothers [Bro n (get_brothers [] s) :: acc] b ] + and print_brothers ppf brothers = + if brothers = [] then fprintf ppf "@ []" + else + List.iter (fun [ Bro n xs -> do { + fprintf ppf "@ @[- %a" print_symbol n; + match xs with + [ [] -> () + | [_] -> try print_children ppf (get_children [] xs) + with [ Exit -> fprintf ppf ":%a" print_brothers xs ] + | _ -> fprintf ppf ":%a" print_brothers xs ]; + fprintf ppf "@]"; + }]) brothers + and print_children ppf = List.iter (fprintf ppf ";@ %a" print_symbol) + and get_children acc = + fun + [ [] -> List.rev acc + | [Bro n x] -> get_children [n::acc] x + | _ -> raise Exit ] + in print_brothers ppf (get_brothers [] tree) + and print_symbol ppf = + fun + [ Smeta n sl _ -> print_meta ppf n sl + | Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s + | Slist0sep s t -> + fprintf ppf "LIST0 %a SEP %a" print_symbol1 s print_symbol1 t + | Slist1 s -> fprintf ppf "LIST1 %a" print_symbol1 s + | Slist1sep s t -> + fprintf ppf "LIST1 %a SEP %a" print_symbol1 s print_symbol1 t + | Sopt s -> fprintf ppf "OPT %a" print_symbol1 s + | Snterml e l -> fprintf ppf "%s@ LEVEL@ %S" e.ename l + | Snterm _ | Snext | Sself | Stree _ | Stoken _ | Skeyword _ as s -> + print_symbol1 ppf s ] + and print_meta ppf n sl = + loop 0 sl where rec loop i = + fun + [ [] -> () + | [s :: sl] -> + let j = + try String.index_from n i ' ' with [ Not_found -> String.length n ] + in + do { + fprintf ppf "%s %a" (String.sub n i (j - i)) print_symbol1 s; + if sl = [] then () + else do { fprintf ppf " "; loop (min (j + 1) (String.length n)) sl } + } ] + and print_symbol1 ppf = + fun + [ Snterm e -> pp_print_string ppf e.ename + | Sself -> pp_print_string ppf "SELF" + | Snext -> pp_print_string ppf "NEXT" + | Stoken (_, descr) -> pp_print_string ppf descr + | Skeyword s -> fprintf ppf "%S" s + | Stree t -> print_tree ppf t + | Smeta _ _ _ | Snterml _ _ | Slist0 _ | Slist0sep _ _ | Slist1 _ | + Slist1sep _ _ | Sopt _ as s -> + fprintf ppf "(%a)" print_symbol s ] + and print_rule ppf symbols = + do { + fprintf ppf "@["; + let _ = + List.fold_left + (fun sep symbol -> + do { + fprintf ppf "%t%a" sep print_symbol symbol; + fun ppf -> fprintf ppf ";@ " + }) + (fun _ -> ()) symbols + in + fprintf ppf "@]" + } + and print_level ppf pp_print_space rules = + do { + fprintf ppf "@[[ "; + let _ = + List.fold_left + (fun sep rule -> + do { + fprintf ppf "%t%a" sep print_rule rule; + fun ppf -> fprintf ppf "%a| " pp_print_space () + }) + (fun _ -> ()) rules + in + fprintf ppf " ]@]" + } + ; + + value levels ppf elev = + let _ = + List.fold_left + (fun sep lev -> + do { + fprintf ppf "%t@[" sep; + match lev.lname with + [ Some n -> fprintf ppf "%S@;<1 2>" n + | None -> () ]; + match lev.assoc with + [ LeftA -> fprintf ppf "LEFTA" + | RightA -> fprintf ppf "RIGHTA" + | NonA -> fprintf ppf "NONA" ]; + fprintf ppf "@]@;<1 2>"; + fprintf ppf "@[suffix:@ "; + print_tree ppf lev.lsuffix; + fprintf ppf "@]@ @[prefix:@ "; + print_tree ppf lev.lprefix; + fprintf ppf "@]"; + fun ppf -> fprintf ppf "@,| " + }) + (fun _ -> ()) elev + in + (); + + value entry ppf e = + do { + fprintf ppf "@[%s: [ " e.ename; + match e.edesc with + [ Dlevels elev -> levels ppf elev + | Dparser _ -> fprintf ppf "" ]; + fprintf ppf " ]@]" + }; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Print.mli b/camlp4/Camlp4/Struct/Grammar/Print.mli new file mode 100644 index 0000000..9acc836 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Print.mli @@ -0,0 +1,47 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Structure : Structure.S) : sig + value flatten_tree : Structure.tree -> list (list Structure.symbol); + value print_symbol : Format.formatter -> Structure.symbol -> unit; + value print_meta : + Format.formatter -> string -> list Structure.symbol -> unit; + value print_symbol1 : Format.formatter -> Structure.symbol -> unit; + value print_rule : Format.formatter -> list Structure.symbol -> unit; + value print_level : + Format.formatter -> + (Format.formatter -> unit -> unit) -> + list (list Structure.symbol) -> unit; + value levels : Format.formatter -> list Structure.level -> unit; + value entry : Format.formatter -> Structure.internal_entry -> unit; +end; + +module MakeDump (Structure : Structure.S) : sig + value print_symbol : Format.formatter -> Structure.symbol -> unit; + value print_meta : + Format.formatter -> string -> list Structure.symbol -> unit; + value print_symbol1 : Format.formatter -> Structure.symbol -> unit; + value print_rule : Format.formatter -> list Structure.symbol -> unit; + value print_level : + Format.formatter -> + (Format.formatter -> unit -> unit) -> + list (list Structure.symbol) -> unit; + value levels : Format.formatter -> list Structure.level -> unit; + value entry : Format.formatter -> Structure.internal_entry -> unit; +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Search.ml b/camlp4/Camlp4/Struct/Grammar/Search.ml new file mode 100644 index 0000000..870a6f7 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Search.ml @@ -0,0 +1,91 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Structure : Structure.S) = struct + open Structure; +value tree_in_entry prev_symb tree = + fun + [ Dlevels levels -> + let rec search_levels = + fun + [ [] -> tree + | [level :: levels] -> + match search_level level with + [ Some tree -> tree + | None -> search_levels levels ] ] + and search_level level = + match search_tree level.lsuffix with + [ Some t -> Some (Node {node = Sself; son = t; brother = DeadEnd}) + | None -> search_tree level.lprefix ] + and search_tree t = + if tree <> DeadEnd && t == tree then Some t + else + match t with + [ Node n -> + match search_symbol n.node with + [ Some symb -> + Some (Node {node = symb; son = n.son; brother = DeadEnd}) + | None -> + match search_tree n.son with + [ Some t -> + Some (Node {node = n.node; son = t; brother = DeadEnd}) + | None -> search_tree n.brother ] ] + | LocAct _ _ | DeadEnd -> None ] + and search_symbol symb = + match symb with + [ Snterm _ | Snterml _ _ | Slist0 _ | Slist0sep _ _ | Slist1 _ | + Slist1sep _ _ | Sopt _ | Stoken _ | Stree _ | Skeyword _ + when symb == prev_symb -> + Some symb + | Slist0 symb -> + match search_symbol symb with + [ Some symb -> Some (Slist0 symb) + | None -> None ] + | Slist0sep symb sep -> + match search_symbol symb with + [ Some symb -> Some (Slist0sep symb sep) + | None -> + match search_symbol sep with + [ Some sep -> Some (Slist0sep symb sep) + | None -> None ] ] + | Slist1 symb -> + match search_symbol symb with + [ Some symb -> Some (Slist1 symb) + | None -> None ] + | Slist1sep symb sep -> + match search_symbol symb with + [ Some symb -> Some (Slist1sep symb sep) + | None -> + match search_symbol sep with + [ Some sep -> Some (Slist1sep symb sep) + | None -> None ] ] + | Sopt symb -> + match search_symbol symb with + [ Some symb -> Some (Sopt symb) + | None -> None ] + | Stree t -> + match search_tree t with + [ Some t -> Some (Stree t) + | None -> None ] + | _ -> None ] + in + search_levels levels + | Dparser _ -> tree ] +; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Static.ml b/camlp4/Camlp4/Struct/Grammar/Static.ml new file mode 100644 index 0000000..7d7b51e --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Static.ml @@ -0,0 +1,83 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring +*) + +value uncurry f (x,y) = f x y; +value flip f x y = f y x; + +module Make (Lexer : Sig.Lexer) +: Sig.Grammar.Static with module Loc = Lexer.Loc + and module Token = Lexer.Token += struct + module Structure = Structure.Make Lexer; + module Delete = Delete.Make Structure; + module Insert = Insert.Make Structure; + module Fold = Fold.Make Structure; + include Structure; + + value gram = + let gkeywords = Hashtbl.create 301 in + { + gkeywords = gkeywords; + gfilter = Token.Filter.mk (Hashtbl.mem gkeywords); + glexer = Lexer.mk (); + warning_verbose = ref True; (* FIXME *) + error_verbose = Camlp4_config.verbose + }; + + module Entry = struct + module E = Entry.Make Structure; + type t 'a = E.t 'a; + value mk = E.mk gram; + value of_parser name strm = E.of_parser gram name strm; + value setup_parser = E.setup_parser; + value name = E.name; + value print = E.print; + value clear = E.clear; + value dump = E.dump; + value obj x = x; + end; + + value get_filter () = gram.gfilter; + + value lex loc cs = gram.glexer loc cs; + + value lex_string loc str = lex loc (Stream.of_string str); + + value filter ts = Token.Filter.filter gram.gfilter ts; + + value parse_tokens_after_filter entry ts = Entry.E.parse_tokens_after_filter entry ts; + + value parse_tokens_before_filter entry ts = parse_tokens_after_filter entry (filter ts); + + value parse entry loc cs = parse_tokens_before_filter entry (lex loc cs); + + value parse_string entry loc str = parse_tokens_before_filter entry (lex_string loc str); + + value delete_rule = Delete.delete_rule; + + value srules e rl = + Stree (List.fold_left (flip (uncurry (Insert.insert_tree e))) DeadEnd rl); + value sfold0 = Fold.sfold0; + value sfold1 = Fold.sfold1; + value sfold0sep = Fold.sfold0sep; + (* value sfold1sep = Fold.sfold1sep; *) + + value extend = Insert.extend; + +end; diff --git a/camlp4/Camlp4/Struct/Grammar/Structure.ml b/camlp4/Camlp4/Struct/Grammar/Structure.ml new file mode 100644 index 0000000..12023b7 --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Structure.ml @@ -0,0 +1,280 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +open Sig.Grammar; + +module type S = sig + module Loc : Sig.Loc; + module Token : Sig.Token with module Loc = Loc; + module Lexer : Sig.Lexer + with module Loc = Loc + and module Token = Token; + module Context : Context.S with module Token = Token; + module Action : Sig.Grammar.Action; + + type gram = + { gfilter : Token.Filter.t; + gkeywords : Hashtbl.t string (ref int); + glexer : Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t); + warning_verbose : ref bool; + error_verbose : ref bool }; + + type efun = Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + + type token_pattern = ((Token.t -> bool) * string); + + type internal_entry = + { egram : gram; + ename : string; + estart : mutable int -> efun; + econtinue : mutable int -> Loc.t -> Action.t -> efun; + edesc : mutable desc } + and desc = + [ Dlevels of list level + | Dparser of Stream.t (Token.t * Loc.t) -> Action.t ] + and level = + { assoc : assoc ; + lname : option string ; + lsuffix : tree ; + lprefix : tree } + and symbol = + [ Smeta of string and list symbol and Action.t + | Snterm of internal_entry + | Snterml of internal_entry and string + | Slist0 of symbol + | Slist0sep of symbol and symbol + | Slist1 of symbol + | Slist1sep of symbol and symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree ] + and tree = + [ Node of node + | LocAct of Action.t and list Action.t + | DeadEnd ] + and node = + { node : symbol ; + son : tree ; + brother : tree }; + + type production_rule = (list symbol * Action.t); + type single_extend_statment = + (option string * option assoc * list production_rule); + type extend_statment = + (option position * list single_extend_statment); + type delete_statment = list symbol; + + type fold 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> Stream.t 'a -> 'c; + + type foldsep 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> (Stream.t 'a -> unit) -> Stream.t 'a -> 'c; + + (* Accessors *) + value get_filter : gram -> Token.Filter.t; + + (* Useful functions *) + value using : gram -> string -> unit; + value removing : gram -> string -> unit; +end; + +module Make (Lexer : Sig.Lexer) = struct + module Loc = Lexer.Loc; + module Token = Lexer.Token; + module Action : Sig.Grammar.Action = struct + type t = Obj.t ; + value mk = Obj.repr; + value get = Obj.obj ; + value getf = Obj.obj ; + value getf2 = Obj.obj ; + end; + module Lexer = Lexer; + + type gram = + { gfilter : Token.Filter.t; + gkeywords : Hashtbl.t string (ref int); + glexer : Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t); + warning_verbose : ref bool; + error_verbose : ref bool }; + + module Context = Context.Make Token; + + type efun = Context.t -> Stream.t (Token.t * Loc.t) -> Action.t; + + type token_pattern = ((Token.t -> bool) * string); + + type internal_entry = + { egram : gram; + ename : string; + estart : mutable int -> efun; + econtinue : mutable int -> Loc.t -> Action.t -> efun; + edesc : mutable desc } + and desc = + [ Dlevels of list level + | Dparser of Stream.t (Token.t * Loc.t) -> Action.t ] + and level = + { assoc : assoc ; + lname : option string ; + lsuffix : tree ; + lprefix : tree } + and symbol = + [ Smeta of string and list symbol and Action.t + | Snterm of internal_entry + | Snterml of internal_entry and string + | Slist0 of symbol + | Slist0sep of symbol and symbol + | Slist1 of symbol + | Slist1sep of symbol and symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree ] + and tree = + [ Node of node + | LocAct of Action.t and list Action.t + | DeadEnd ] + and node = + { node : symbol ; + son : tree ; + brother : tree }; + + type production_rule = (list symbol * Action.t); + type single_extend_statment = + (option string * option assoc * list production_rule); + type extend_statment = + (option position * list single_extend_statment); + type delete_statment = list symbol; + + type fold 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> Stream.t 'a -> 'c; + + type foldsep 'a 'b 'c = + internal_entry -> list symbol -> + (Stream.t 'a -> 'b) -> (Stream.t 'a -> unit) -> Stream.t 'a -> 'c; + + value get_filter g = g.gfilter; + + type not_filtered 'a = 'a; + value using { gkeywords = table; gfilter = filter } kwd = + let r = try Hashtbl.find table kwd with + [ Not_found -> + let r = ref 0 in do { Hashtbl.add table kwd r; r } ] + in do { Token.Filter.keyword_added filter kwd (r.val = 0); + incr r }; + + value removing { gkeywords = table; gfilter = filter } kwd = + let r = Hashtbl.find table kwd in + let () = decr r in + if r.val = 0 then do { + Token.Filter.keyword_removed filter kwd; + Hashtbl.remove table kwd + } else (); +end; + +(* +value iter_entry f e = + let treated = ref [] in + let rec do_entry e = + if List.memq e treated.val then () + else do { + treated.val := [e :: treated.val]; + f e; + match e.edesc with + [ Dlevels ll -> List.iter do_level ll + | Dparser _ -> () ] + } + and do_level lev = do { do_tree lev.lsuffix; do_tree lev.lprefix } + and do_tree = + fun + [ Node n -> do_node n + | LocAct _ _ | DeadEnd -> () ] + and do_node n = do { do_symbol n.node; do_tree n.son; do_tree n.brother } + and do_symbol = + fun + [ Smeta _ sl _ -> List.iter do_symbol sl + | Snterm e | Snterml e _ -> do_entry e + | Slist0 s | Slist1 s | Sopt s -> do_symbol s + | Slist0sep s1 s2 | Slist1sep s1 s2 -> do { do_symbol s1; do_symbol s2 } + | Stree t -> do_tree t + | Sself | Snext | Stoken _ | Stoken_fun _ -> () ] + in + do_entry e +; + +value fold_entry f e init = + let treated = ref [] in + let rec do_entry accu e = + if List.memq e treated.val then accu + else do { + treated.val := [e :: treated.val]; + let accu = f e accu in + match e.edesc with + [ Dlevels ll -> List.fold_left do_level accu ll + | Dparser _ -> accu ] + } + and do_level accu lev = + let accu = do_tree accu lev.lsuffix in + do_tree accu lev.lprefix + and do_tree accu = + fun + [ Node n -> do_node accu n + | LocAct _ _ | DeadEnd -> accu ] + and do_node accu n = + let accu = do_symbol accu n.node in + let accu = do_tree accu n.son in + do_tree accu n.brother + and do_symbol accu = + fun + [ Smeta _ sl _ -> List.fold_left do_symbol accu sl + | Snterm e | Snterml e _ -> do_entry accu e + | Slist0 s | Slist1 s | Sopt s -> do_symbol accu s + | Slist0sep s1 s2 | Slist1sep s1 s2 -> + let accu = do_symbol accu s1 in + do_symbol accu s2 + | Stree t -> do_tree accu t + | Sself | Snext | Stoken _ | Stoken_fun _ -> accu ] + in + do_entry init e +; + +value is_level_labelled n lev = + match lev.lname with + [ Some n1 -> n = n1 + | None -> False ] +; + +value tokens g con = + let list = ref [] in + do { + Hashtbl.iter + (fun (p_con, p_prm) c -> + if p_con = con then list.val := [(p_prm, c.val) :: list.val] else ()) + g.gtokens; + list.val + } +; +*) diff --git a/camlp4/Camlp4/Struct/Grammar/Tools.ml b/camlp4/Camlp4/Struct/Grammar/Tools.ml new file mode 100644 index 0000000..bcb933b --- /dev/null +++ b/camlp4/Camlp4/Struct/Grammar/Tools.ml @@ -0,0 +1,89 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Structure : Structure.S) = struct + open Structure; + + value empty_entry ename _ _ _ = + raise (Stream.Error ("entry [" ^ ename ^ "] is empty")); + + value is_level_labelled n lev = + match lev.lname with + [ Some n1 -> n = n1 + | None -> False ]; + + value warning_verbose = ref True; + + value rec get_token_list entry tokl last_tok tree = + match tree with + [ Node {node = (Stoken _ | Skeyword _ as tok); son = son; brother = DeadEnd} -> + get_token_list entry [last_tok :: tokl] tok son + | _ -> + if tokl = [] then None + else Some (List.rev [last_tok :: tokl], last_tok, tree) ]; + + value is_antiquot s = + let len = String.length s in + len > 1 && s.[0] = '$'; + + value eq_Stoken_ids s1 s2 = + not (is_antiquot s1) && not (is_antiquot s2) && s1 = s2; + + value logically_eq_symbols entry = + let rec eq_symbols s1 s2 = + match (s1, s2) with + [ (Snterm e1, Snterm e2) -> e1.ename = e2.ename + | (Snterm e1, Sself) -> e1.ename = entry.ename + | (Sself, Snterm e2) -> entry.ename = e2.ename + | (Snterml e1 l1, Snterml e2 l2) -> e1.ename = e2.ename && l1 = l2 + | (Slist0 s1, Slist0 s2) -> eq_symbols s1 s2 + | (Slist0sep s1 sep1, Slist0sep s2 sep2) -> + eq_symbols s1 s2 && eq_symbols sep1 sep2 + | (Slist1 s1, Slist1 s2) -> eq_symbols s1 s2 + | (Slist1sep s1 sep1, Slist1sep s2 sep2) -> + eq_symbols s1 s2 && eq_symbols sep1 sep2 + | (Sopt s1, Sopt s2) -> eq_symbols s1 s2 + | (Stree t1, Stree t2) -> eq_trees t1 t2 + | (Stoken (_, s1), Stoken (_, s2)) -> eq_Stoken_ids s1 s2 + | _ -> s1 = s2 ] + and eq_trees t1 t2 = + match (t1, t2) with + [ (Node n1, Node n2) -> + eq_symbols n1.node n2.node && eq_trees n1.son n2.son && + eq_trees n1.brother n2.brother + | (LocAct _ _ | DeadEnd, LocAct _ _ | DeadEnd) -> True + | _ -> False ] + in + eq_symbols; + + value rec eq_symbol s1 s2 = + match (s1, s2) with + [ (Snterm e1, Snterm e2) -> e1 == e2 + | (Snterml e1 l1, Snterml e2 l2) -> e1 == e2 && l1 = l2 + | (Slist0 s1, Slist0 s2) -> eq_symbol s1 s2 + | (Slist0sep s1 sep1, Slist0sep s2 sep2) -> + eq_symbol s1 s2 && eq_symbol sep1 sep2 + | (Slist1 s1, Slist1 s2) -> eq_symbol s1 s2 + | (Slist1sep s1 sep1, Slist1sep s2 sep2) -> + eq_symbol s1 s2 && eq_symbol sep1 sep2 + | (Sopt s1, Sopt s2) -> eq_symbol s1 s2 + | (Stree _, Stree _) -> False + | (Stoken (_, s1), Stoken (_, s2)) -> eq_Stoken_ids s1 s2 + | _ -> s1 = s2 ] + ; +end; diff --git a/camlp4/Camlp4/Struct/Lexer.mll b/camlp4/Camlp4/Struct/Lexer.mll new file mode 100644 index 0000000..f024fa4 --- /dev/null +++ b/camlp4/Camlp4/Struct/Lexer.mll @@ -0,0 +1,483 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +(* The lexer definition *) + + +{ + +(** A lexical analyzer. *) + +(* FIXME interface module Make (Token : Token) |+ Note that this Token sig is not in Sig +| *) +(* : Sig.Lexer. S with module Loc = Token.Loc and module Token = Token; *) + +(* type context = +{ loc : Loc.t ; + in_comment : bool ; + |+* FIXME When True, all lexers built by [Plexer.make ()] do not lex the + quotation syntax any more. Default is False (quotations are + lexed). +| + quotations : bool }; + +value default_context : context; + +value mk : Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t); + +value mk' : context -> Stream.t char -> Stream.t (Token.t * Loc.t); *) +(* FIXME Beware the context argument must be given like that: + * mk' { (default_context) with ... = ... } strm + *) + +module TokenEval = Token.Eval +module Make (Token : Sig.Camlp4Token) += struct + module Loc = Token.Loc + module Token = Token + + open Lexing + open Sig + + (* Error report *) + module Error = struct + + type t = + | Illegal_character of char + | Illegal_escape of string + | Unterminated_comment + | Unterminated_string + | Unterminated_quotation + | Unterminated_antiquot + | Unterminated_string_in_comment + | Comment_start + | Comment_not_end + | Literal_overflow of string + + exception E of t + + open Format + + let print ppf = + function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Illegal_escape s -> + fprintf ppf "Illegal backslash escape in string or character (%s)" s + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf "This comment contains an unterminated string literal" + | Unterminated_quotation -> + fprintf ppf "Quotation not terminated" + | Unterminated_antiquot -> + fprintf ppf "Antiquotation not terminated" + | Literal_overflow ty -> + fprintf ppf "Integer literal exceeds the range of representable integers of type %s" ty + | Comment_start -> + fprintf ppf "this is the start of a comment" + | Comment_not_end -> + fprintf ppf "this is not the end of a comment" + + let to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b + end;; + + let module M = ErrorHandler.Register(Error) in () + + open Error + + (* To store some context information: + * loc : position of the beginning of a string, quotation and comment + * in_comment: are we in a comment? + * quotations: shall we lex quotation? + * If quotations is false it's a SYMBOL token. + * antiquots : shall we lex antiquotations. + *) + + type context = + { loc : Loc.t ; + in_comment : bool ; + quotations : bool ; + antiquots : bool ; + lexbuf : lexbuf ; + buffer : Buffer.t } + + let default_context lb = + { loc = Loc.ghost ; + in_comment = false ; + quotations = true ; + antiquots = false ; + lexbuf = lb ; + buffer = Buffer.create 256 } + + (* To buffer string literals, quotations and antiquotations *) + + let store c = Buffer.add_string c.buffer (Lexing.lexeme c.lexbuf) + let istore_char c i = Buffer.add_char c.buffer (Lexing.lexeme_char c.lexbuf i) + let buff_contents c = + let contents = Buffer.contents c.buffer in + Buffer.reset c.buffer; contents + + let loc c = Loc.merge c.loc (Loc.of_lexbuf c.lexbuf) + let quotations c = c.quotations + let antiquots c = c.antiquots + let is_in_comment c = c.in_comment + let in_comment c = { (c) with in_comment = true } + let set_start_p c = c.lexbuf.lex_start_p <- Loc.start_pos c.loc + let move_start_p shift c = + let p = c.lexbuf.lex_start_p in + c.lexbuf.lex_start_p <- { (p) with pos_cnum = p.pos_cnum + shift } + + let update_loc c = { (c) with loc = Loc.of_lexbuf c.lexbuf } + let with_curr_loc f c = f (update_loc c) c.lexbuf + let parse_nested f c = + with_curr_loc f c; + set_start_p c; + buff_contents c + let shift n c = { (c) with loc = Loc.move `both n c.loc } + let store_parse f c = store c ; f c c.lexbuf + let parse f c = f c c.lexbuf + let mk_quotation quotation c name loc shift = + let s = parse_nested quotation (update_loc c) in + let contents = String.sub s 0 (String.length s - 2) in + QUOTATION { q_name = name ; + q_loc = loc ; + q_shift = shift ; + q_contents = contents } + + + (* Update the current location with file name and line number. *) + + let update_loc c file line absolute chars = + let lexbuf = c.lexbuf in + let pos = lexbuf.lex_curr_p in + let new_file = match file with + | None -> pos.pos_fname + | Some s -> s + in + lexbuf.lex_curr_p <- { pos with + pos_fname = new_file; + pos_lnum = if absolute then line else pos.pos_lnum + line; + pos_bol = pos.pos_cnum - chars; + } + + let err error loc = + raise(Loc.Exc_located(loc, Error.E error)) + + let warn error loc = + Format.eprintf "Warning: %a: %a@." Loc.print loc Error.print error + + } + + let newline = ('\010' | '\013' | "\013\010") + let blank = [' ' '\009' '\012'] + let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] + let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] + let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] + let ident = (lowercase|uppercase) identchar* + let locname = ident + let not_star_symbolchar = + ['$' '!' '%' '&' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~' '\\'] + let symbolchar = '*' | not_star_symbolchar + let quotchar = + ['!' '%' '&' '+' '-' '.' '/' ':' '=' '?' '@' '^' '|' '~' '\\' '*'] + let hexa_char = ['0'-'9' 'A'-'F' 'a'-'f'] + let decimal_literal = + ['0'-'9'] ['0'-'9' '_']* + let hex_literal = + '0' ['x' 'X'] hexa_char ['0'-'9' 'A'-'F' 'a'-'f' '_']* + let oct_literal = + '0' ['o' 'O'] ['0'-'7'] ['0'-'7' '_']* + let bin_literal = + '0' ['b' 'B'] ['0'-'1'] ['0'-'1' '_']* + let int_literal = + decimal_literal | hex_literal | oct_literal | bin_literal + let float_literal = + ['0'-'9'] ['0'-'9' '_']* + ('.' ['0'-'9' '_']* )? + (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)? + + (* Delimitors are extended (from 3.09) in a conservative way *) + + (* These chars that can't start an expression or a pattern: *) + let safe_delimchars = ['%' '&' '/' '@' '^'] + + (* These symbols are unsafe since "[<", "[|", etc. exsist. *) + let delimchars = safe_delimchars | ['|' '<' '>' ':' '=' '.'] + + let left_delims = ['(' '[' '{'] + let right_delims = [')' ']' '}'] + + let left_delimitor = + (* At least a safe_delimchars *) + left_delims delimchars* safe_delimchars (delimchars|left_delims)* + + (* A '(' or a new super '(' without "(<" *) + | '(' (['|' ':'] delimchars*)? + (* Old brackets, no new brackets starting with "[|" or "[:" *) + | '[' ['|' ':']? + (* Old "[<","{<" and new ones *) + | ['[' '{'] delimchars* '<' + (* Old brace and new ones *) + | '{' (['|' ':'] delimchars*)? + + let right_delimitor = + (* At least a safe_delimchars *) + (delimchars|right_delims)* safe_delimchars (delimchars|right_delims)* right_delims + (* A ')' or a new super ')' without ">)" *) + | (delimchars* ['|' ':'])? ')' + (* Old brackets, no new brackets ending with "|]" or ":]" *) + | ['|' ':']? ']' + (* Old ">]",">}" and new ones *) + | '>' delimchars* [']' '}'] + (* Old brace and new ones *) + | (delimchars* ['|' ':'])? '}' + + + rule token c = parse + | newline { update_loc c None 1 false 0; NEWLINE } + | blank + as x { BLANKS x } + | "~" (lowercase identchar * as x) ':' { LABEL x } + | "?" (lowercase identchar * as x) ':' { OPTLABEL x } + | lowercase identchar * as x { LIDENT x } + | uppercase identchar * as x { UIDENT x } + | int_literal as i + { try INT(int_of_string i, i) + with Failure _ -> err (Literal_overflow "int") (Loc.of_lexbuf lexbuf) } + | float_literal as f + { try FLOAT(float_of_string f, f) + with Failure _ -> err (Literal_overflow "float") (Loc.of_lexbuf lexbuf) } + | (int_literal as i) "l" + { try INT32(Int32.of_string i, i) + with Failure _ -> err (Literal_overflow "int32") (Loc.of_lexbuf lexbuf) } + | (int_literal as i) "L" + { try INT64(Int64.of_string i, i) + with Failure _ -> err (Literal_overflow "int64") (Loc.of_lexbuf lexbuf) } + | (int_literal as i) "n" + { try NATIVEINT(Nativeint.of_string i, i) + with Failure _ -> err (Literal_overflow "nativeint") (Loc.of_lexbuf lexbuf) } + | '"' + { with_curr_loc string c; + let s = buff_contents c in STRING (TokenEval.string s, s) } + | "'" (newline as x) "'" + { update_loc c None 1 false 1; CHAR (TokenEval.char x, x) } + | "'" ( [^ '\\' '\010' '\013'] + | '\\' (['\\' '"' 'n' 't' 'b' 'r' ' ' '\''] + |['0'-'9'] ['0'-'9'] ['0'-'9'] + |'x' hexa_char hexa_char) + as x) "'" { CHAR (TokenEval.char x, x) } + | "'\\" (_ as c) + { err (Illegal_escape (String.make 1 c)) (Loc.of_lexbuf lexbuf) } + | "(*" + { store c; COMMENT(parse_nested comment (in_comment c)) } + | "(*)" + { warn Comment_start (Loc.of_lexbuf lexbuf) ; + parse comment (in_comment c); COMMENT (buff_contents c) } + | "*)" + { warn Comment_not_end (Loc.of_lexbuf lexbuf) ; + move_start_p (-1) c; SYMBOL "*" } + | "<<" (quotchar* as beginning) + { if quotations c + then (move_start_p (-String.length beginning); + mk_quotation quotation c "" "" 2) + else parse (symbolchar_star ("<<" ^ beginning)) c } + | "<<>>" + { if quotations c + then QUOTATION { q_name = ""; q_loc = ""; q_shift = 2; q_contents = "" } + else parse (symbolchar_star "<<>>") c } + | "<@" + { if quotations c then with_curr_loc maybe_quotation_at c + else parse (symbolchar_star "<@") c } + | "<:" + { if quotations c then with_curr_loc maybe_quotation_colon c + else parse (symbolchar_star "<:") c } + | "#" [' ' '\t']* (['0'-'9']+ as num) [' ' '\t']* + ("\"" ([^ '\010' '\013' '"' ] * as name) "\"")? + [^ '\010' '\013'] * newline + { let inum = int_of_string num + in update_loc c name inum true 0; LINE_DIRECTIVE(inum, name) } + | '(' (not_star_symbolchar as op) ')' + { ESCAPED_IDENT (String.make 1 op) } + | '(' (not_star_symbolchar symbolchar* not_star_symbolchar as op) ')' + { ESCAPED_IDENT op } + | '(' (not_star_symbolchar symbolchar* as op) blank+ ')' + { ESCAPED_IDENT op } + | '(' blank+ (symbolchar* not_star_symbolchar as op) ')' + { ESCAPED_IDENT op } + | '(' blank+ (symbolchar+ as op) blank+ ')' + { ESCAPED_IDENT op } + | ( "#" | "`" | "'" | "," | "." | ".." | ":" | "::" + | ":=" | ":>" | ";" | ";;" | "_" + | left_delimitor | right_delimitor ) as x { SYMBOL x } + | '$' { if antiquots c + then with_curr_loc dollar (shift 1 c) + else parse (symbolchar_star "$") c } + | ['~' '?' '!' '=' '<' '>' '|' '&' '@' '^' '+' '-' '*' '/' '%' '\\'] symbolchar * + as x { SYMBOL x } + | eof + { let pos = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { pos with pos_bol = pos.pos_bol + 1 ; + pos_cnum = pos.pos_cnum + 1 }; EOI } + | _ as c { err (Illegal_character c) (Loc.of_lexbuf lexbuf) } + + and comment c = parse + "(*" + { store c; with_curr_loc comment c; parse comment c } + | "*)" { store c } + | '<' (':' ident)? ('@' locname)? '<' + { store c; + if quotations c then with_curr_loc quotation c; parse comment c } + | ident { store_parse comment c } + | "\"" + { store c; + begin try with_curr_loc string c + with Loc.Exc_located(_, Error.E Unterminated_string) -> + err Unterminated_string_in_comment (loc c) + end; + Buffer.add_char c.buffer '"'; + parse comment c } + | "''" { store_parse comment c } + | "'''" { store_parse comment c } + | "'" newline "'" + { update_loc c None 1 false 1; store_parse comment c } + | "'" [^ '\\' '\'' '\010' '\013' ] "'" { store_parse comment c } + | "'\\" ['\\' '"' '\'' 'n' 't' 'b' 'r' ' '] "'" { store_parse comment c } + | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" { store_parse comment c } + | "'\\" 'x' hexa_char hexa_char "'" { store_parse comment c } + | eof + { err Unterminated_comment (loc c) } + | newline + { update_loc c None 1 false 0; store_parse comment c } + | _ { store_parse comment c } + + and string c = parse + '"' { set_start_p c } + | '\\' newline ([' ' '\t'] * as space) + { update_loc c None 1 false (String.length space); + store_parse string c } + | '\\' ['\\' '"' 'n' 't' 'b' 'r' ' ' '\''] { store_parse string c } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] { store_parse string c } + | '\\' 'x' hexa_char hexa_char { store_parse string c } + | '\\' (_ as x) + { if is_in_comment c + then store_parse string c + else begin + warn (Illegal_escape (String.make 1 x)) (Loc.of_lexbuf lexbuf); + store_parse string c + end } + | newline + { update_loc c None 1 false 0; store_parse string c } + | eof { err Unterminated_string (loc c) } + | _ { store_parse string c } + + and symbolchar_star beginning c = parse + | symbolchar* as tok { move_start_p (-String.length beginning) c ; + SYMBOL(beginning ^ tok) } + + and maybe_quotation_at c = parse + | (ident as loc) '<' + { mk_quotation quotation c "" loc (1 + String.length loc) } + | symbolchar* as tok { SYMBOL("<@" ^ tok) } + + and maybe_quotation_colon c = parse + | (ident as name) '<' + { mk_quotation quotation c name "" (1 + String.length name) } + | (ident as name) '@' (locname as loc) '<' + { mk_quotation quotation c name loc + (2 + String.length loc + String.length name) } + | symbolchar* as tok { SYMBOL("<:" ^ tok) } + + and quotation c = parse + | '<' (':' ident)? ('@' locname)? '<' { store c ; + with_curr_loc quotation c ; + parse quotation c } + | ">>" { store c } + | eof { err Unterminated_quotation (loc c) } + | newline { update_loc c None 1 false 0 ; + store_parse quotation c } + | _ { store_parse quotation c } + + and dollar c = parse + | '$' { set_start_p c; ANTIQUOT("", "") } + | ('`'? (identchar*|'.'+) as name) ':' + { with_curr_loc (antiquot name) (shift (1 + String.length name) c) } + | _ { store_parse (antiquot "") c } + + and antiquot name c = parse + | '$' { set_start_p c; ANTIQUOT(name, buff_contents c) } + | eof { err Unterminated_antiquot (loc c) } + | newline + { update_loc c None 1 false 0; store_parse (antiquot name) c } + | '<' (':' ident)? ('@' locname)? '<' + { store c; with_curr_loc quotation c; parse (antiquot name) c } + | _ { store_parse (antiquot name) c } + + { + + let lexing_store s buff max = + let rec self n s = + if n >= max then n + else + match Stream.peek s with + | Some x -> + Stream.junk s; + buff.[n] <- x; + succ n + | _ -> n + in + self 0 s + + let from_context c = + let next _ = + let tok = with_curr_loc token c in + let loc = Loc.of_lexbuf c.lexbuf in + Some ((tok, loc)) + in Stream.from next + + let from_lexbuf ?(quotations = true) lb = + let c = { (default_context lb) with + loc = Loc.of_lexbuf lb; + antiquots = !Camlp4_config.antiquotations; + quotations = quotations } + in from_context c + + let setup_loc lb loc = + let start_pos = Loc.start_pos loc in + lb.lex_abs_pos <- start_pos.pos_cnum; + lb.lex_curr_p <- start_pos + + let from_string ?quotations loc str = + let lb = Lexing.from_string str in + setup_loc lb loc; + from_lexbuf ?quotations lb + + let from_stream ?quotations loc strm = + let lb = Lexing.from_function (lexing_store strm) in + setup_loc lb loc; + from_lexbuf ?quotations lb + + let mk () loc strm = + from_stream ~quotations:!Camlp4_config.quotations loc strm +end +} diff --git a/camlp4/Camlp4/Struct/Loc.ml b/camlp4/Camlp4/Struct/Loc.ml new file mode 100644 index 0000000..48974d8 --- /dev/null +++ b/camlp4/Camlp4/Struct/Loc.ml @@ -0,0 +1,307 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +(* camlp4r *) + +open Format; + +(* FIXME + Study these 2 others implementations which change the ghost + handling: + + type pos = ... the same ... + + 1/ + + type loc = { + file_name : string; + start : pos; + stop : pos + }; + + type t = + [ Nowhere + | Ghost of loc (* the closest non ghost loc *) + | Concrete of loc ]; + + 2/ + + type loc = { + file_name : string; + start : pos; + stop : pos + }; + + type t = option loc; + + 3/ + + type t = { + file_name : option string; + start : pos; + stop : pos + }; + +*) + +type pos = { + line : int; + bol : int; + off : int +}; + +type t = { + file_name : string; + start : pos; + stop : pos; + ghost : bool +}; + +(* Debug section *) +value dump_sel f x = + let s = + match x with + [ `start -> "`start" + | `stop -> "`stop" + | `both -> "`both" + | _ -> "" ] + in pp_print_string f s; +value dump_pos f x = + fprintf f "@[{ line = %d ;@ bol = %d ;@ off = %d } : pos@]" + x.line x.bol x.off; +value dump_long f x = + fprintf f + "@[{ file_name = %s ;@ start = %a (%d-%d);@ stop = %a (%d);@ ghost = %b@ } : Loc.t@]" + x.file_name dump_pos x.start (x.start.off - x.start.bol) + (x.stop.off - x.start.bol) dump_pos x.stop + (x.stop.off - x.stop.bol) x.ghost; +value dump f x = + fprintf f "[%S: %d:%d-%d %d:%d%t]" + x.file_name x.start.line (x.start.off - x.start.bol) + (x.stop.off - x.start.bol) x.stop.line (x.stop.off - x.stop.bol) + (fun o -> if x.ghost then fprintf o " (ghost)" else ()); + +value start_pos = { line = 1 ; bol = 0 ; off = 0 }; + +value ghost = + { file_name = "ghost-location"; + start = start_pos; + stop = start_pos; + ghost = True }; + +value mk file_name = + debug loc "mk %s@\n" file_name in + { file_name = file_name; + start = start_pos; + stop = start_pos; + ghost = False }; + +value of_tuple (file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost) = + { file_name = file_name; + start = { line = start_line ; bol = start_bol ; off = start_off }; + stop = { line = stop_line ; bol = stop_bol ; off = stop_off }; + ghost = ghost }; + +value to_tuple + { file_name = file_name; + start = { line = start_line ; bol = start_bol ; off = start_off }; + stop = { line = stop_line ; bol = stop_bol ; off = stop_off }; + ghost = ghost } = + (file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost); + +value pos_of_lexing_position p = + let pos = + { line = p.Lexing.pos_lnum ; + bol = p.Lexing.pos_bol ; + off = p.Lexing.pos_cnum } in + debug loc "pos_of_lexing_position: %a@\n" dump_pos pos in + pos; + +value pos_to_lexing_position p file_name = + (* debug loc "pos_to_lexing_position: %a@\n" dump_pos p in *) + { Lexing. + pos_fname = file_name; + pos_lnum = p.line ; + pos_bol = p.bol ; + pos_cnum = p.off }; + +value better_file_name a b = + match (a, b) with + [ ("", "") -> a + | ("", x) -> x + | (x, "") -> x + | ("-", x) -> x + | (x, "-") -> x + | (x, _) -> x ]; + +value of_lexbuf lb = + let start = Lexing.lexeme_start_p lb + and stop = Lexing.lexeme_end_p lb in + let loc = + { file_name = better_file_name start.Lexing.pos_fname stop.Lexing.pos_fname; + start = pos_of_lexing_position start; + stop = pos_of_lexing_position stop; + ghost = False } in + debug loc "of_lexbuf: %a@\n" dump loc in + loc; + +value of_lexing_position pos = + let loc = + { file_name = pos.Lexing.pos_fname; + start = pos_of_lexing_position pos; + stop = pos_of_lexing_position pos; + ghost = False } in + debug loc "of_lexing_position: %a@\n" dump loc in + loc; + +value to_ocaml_location x = + debug loc "to_ocaml_location: %a@\n" dump x in + { Camlp4_import.Location. + loc_start = pos_to_lexing_position x.start x.file_name; + loc_end = pos_to_lexing_position x.stop x.file_name; + loc_ghost = x.ghost }; + +value of_ocaml_location { Camlp4_import.Location.loc_start = a; loc_end = b; loc_ghost = g } = + let res = + { file_name = better_file_name a.Lexing.pos_fname b.Lexing.pos_fname; + start = pos_of_lexing_position a; + stop = pos_of_lexing_position b; + ghost = g } in + debug loc "of_ocaml_location: %a@\n" dump res in + res; + +value start_pos x = pos_to_lexing_position x.start x.file_name; +value stop_pos x = pos_to_lexing_position x.stop x.file_name; + +value merge a b = + if a == b then + debug loc "trivial merge@\n" in + a + else + let r = + match (a.ghost, b.ghost) with + [ (False, False) -> + (* FIXME if a.file_name <> b.file_name then + raise (Invalid_argument + (sprintf "Loc.merge: Filenames must be equal: %s <> %s" + a.file_name b.file_name)) *) + (* else *) + { (a) with stop = b.stop } + | (True, True) -> { (a) with stop = b.stop } + | (True, _) -> { (a) with stop = b.stop } + | (_, True) -> { (b) with start = a.start } ] + in debug loc "@[merge %a@ %a@ %a@]@\n" dump a dump b dump r in r; + +value join x = { (x) with stop = x.start }; + +value map f start_stop_both x = + match start_stop_both with + [ `start -> { (x) with start = f x.start } + | `stop -> { (x) with stop = f x.stop } + | `both -> { (x) with start = f x.start; stop = f x.stop } ]; + +value move_pos chars x = { (x) with off = x.off + chars }; + +value move s chars x = + debug loc "move %a %d %a@\n" dump_sel s chars dump x in + map (move_pos chars) s x; + +value move_line lines x = + debug loc "move_line %d %a@\n" lines dump x in + let move_line_pos x = + { (x) with line = x.line + lines ; bol = x.off } + in map move_line_pos `both x; + +value shift width x = + { (x) with start = x.stop ; stop = move_pos width x.stop }; + +value file_name x = x.file_name; +value start_line x = x.start.line; +value stop_line x = x.stop.line; +value start_bol x = x.start.bol; +value stop_bol x = x.stop.bol; +value start_off x = x.start.off; +value stop_off x = x.stop.off; +value is_ghost x = x.ghost; + +value set_file_name s x = + debug loc "set_file_name: %a@\n" dump x in + { (x) with file_name = s }; + +value ghostify x = + debug loc "ghostify: %a@\n" dump x in + { (x) with ghost = True }; + +value make_absolute x = + debug loc "make_absolute: %a@\n" dump x in + let pwd = Sys.getcwd () in + if Filename.is_relative x.file_name then + { (x) with file_name = Filename.concat pwd x.file_name } + else x; + +value strictly_before x y = + let b = x.stop.off < y.start.off && x.file_name = y.file_name in + debug loc "%a [strictly_before] %a => %b@\n" dump x dump y b in + b; + +value to_string x = do { + let (a, b) = (x.start, x.stop) in + let res = sprintf "File \"%s\", line %d, characters %d-%d" + x.file_name a.line (a.off - a.bol) (b.off - a.bol) in + if x.start.line <> x.stop.line then + sprintf "%s (end at line %d, character %d)" + res x.stop.line (b.off - b.bol) + else res +}; + +value print out x = pp_print_string out (to_string x); + +value check x msg = + if ((start_line x) > (stop_line x) || + (start_bol x) > (stop_bol x) || + (start_off x) > (stop_off x) || + (start_line x) < 0 || (stop_line x) < 0 || + (start_bol x) < 0 || (stop_bol x) < 0 || + (start_off x) < 0 || (stop_off x) < 0) + (* Here, we don't check + (start_off x) < (start_bol x) || (stop_off x) < (start_bol x) + since the lexer is called on antiquotations, with off=0, but line and bolpos + have "correct" values *) + then do { + eprintf "*** Warning: (%s) strange positions ***\n%a@\n" msg print x; + False + } + else True; + +exception Exc_located of t and exn; + +ErrorHandler.register + (fun ppf -> + fun [ Exc_located loc exn -> + fprintf ppf "%a:@\n%a" print loc ErrorHandler.print exn + | exn -> raise exn ]); + +value name = ref "_loc"; + +value raise loc exc = + match exc with + [ Exc_located _ _ -> raise exc + | _ -> raise (Exc_located loc exc) ] +; diff --git a/camlp4/Camlp4/Struct/Loc.mli b/camlp4/Camlp4/Struct/Loc.mli new file mode 100644 index 0000000..e901619 --- /dev/null +++ b/camlp4/Camlp4/Struct/Loc.mli @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +include Sig.Loc; diff --git a/camlp4/Camlp4/Struct/Quotation.ml b/camlp4/Camlp4/Struct/Quotation.ml new file mode 100644 index 0000000..65202c8 --- /dev/null +++ b/camlp4/Camlp4/Struct/Quotation.ml @@ -0,0 +1,167 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +module Make (Ast : Sig.Camlp4Ast) +: Sig.Quotation with module Ast = Ast += struct + module Ast = Ast; + module DynAst = DynAst.Make Ast; + module Loc = Ast.Loc; + open Format; + open Sig; + + type expand_fun 'a = Loc.t -> option string -> string -> 'a; + + module Exp_key = DynAst.Pack(struct + type t 'a = unit; + end); + + module Exp_fun = DynAst.Pack(struct + type t 'a = expand_fun 'a; + end); + + value expanders_table = + (ref [] : ref (list ((string * Exp_key.pack) * Exp_fun.pack))); + + value default = ref ""; + value translate = ref (fun x -> x); + + value expander_name name = + match translate.val name with + [ "" -> default.val + | name -> name ]; + + value find name tag = + let key = (expander_name name, Exp_key.pack tag ()) in + Exp_fun.unpack tag (List.assoc key expanders_table.val); + + value add name tag f = + let elt = ((name, Exp_key.pack tag ()), Exp_fun.pack tag f) in + expanders_table.val := [elt :: expanders_table.val]; + + value dump_file = ref None; + + module Error = struct + type error = + [ Finding + | Expanding + | ParsingResult of Loc.t and string + | Locating ]; + type t = (string * string * error * exn); + exception E of t; + + value print ppf (name, position, ctx, exn) = + let name = if name = "" then default.val else name in + let pp x = fprintf ppf "@?@[<2>While %s %S in a position of %S:" x name position in + let () = + match ctx with + [ Finding -> begin + pp "finding quotation"; + if expanders_table.val = [] then + fprintf ppf "@ There is no quotation expander available." + else + begin + fprintf ppf "@ @[Available quotation expanders are:@\n"; + List.iter begin fun ((s,t),_) -> + fprintf ppf "@[<2>%s@ (in@ a@ position@ of %a)@]@ " + s Exp_key.print_tag t + end expanders_table.val; + fprintf ppf "@]" + end + end + | Expanding -> pp "expanding quotation" + | Locating -> pp "parsing" + | ParsingResult loc str -> + let () = pp "parsing result of quotation" in + match dump_file.val with + [ Some dump_file -> + let () = fprintf ppf " dumping result...\n" in + try + let oc = open_out_bin dump_file in + begin + output_string oc str; + output_string oc "\n"; + flush oc; + close_out oc; + fprintf ppf "%a:" Loc.print (Loc.set_file_name dump_file loc); + end + with _ -> + fprintf ppf + "Error while dumping result in file %S; dump aborted" + dump_file + | None -> + fprintf ppf + "\n(consider setting variable Quotation.dump_file, or using the -QD option)" + ] + ] + in fprintf ppf "@\n%a@]@." ErrorHandler.print exn; + + value to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b; + end; + let module M = ErrorHandler.Register Error in (); + open Error; + + value expand_quotation loc expander pos_tag quot = + debug quot "expand_quotation: name: %s, str: %S@." quot.q_name quot.q_contents in + let loc_name_opt = if quot.q_loc = "" then None else Some quot.q_loc in + try expander loc loc_name_opt quot.q_contents with + [ Loc.Exc_located _ (Error.E _) as exc -> + raise exc + | Loc.Exc_located iloc exc -> + let exc1 = Error.E (quot.q_name, pos_tag, Expanding, exc) in + raise (Loc.Exc_located iloc exc1) + | exc -> + let exc1 = Error.E (quot.q_name, pos_tag, Expanding, exc) in + raise (Loc.Exc_located loc exc1) ]; + + value parse_quotation_result parse loc quot pos_tag str = + try parse loc str with + [ Loc.Exc_located iloc (Error.E (n, pos_tag, Expanding, exc)) -> + let ctx = ParsingResult iloc quot.q_contents in + let exc1 = Error.E (n, pos_tag, ctx, exc) in + raise (Loc.Exc_located iloc exc1) + | Loc.Exc_located iloc (Error.E _ as exc) -> + raise (Loc.Exc_located iloc exc) + | Loc.Exc_located iloc exc -> + let ctx = ParsingResult iloc quot.q_contents in + let exc1 = Error.E (quot.q_name, pos_tag, ctx, exc) in + raise (Loc.Exc_located iloc exc1) ]; + + value expand loc quotation tag = + let pos_tag = DynAst.string_of_tag tag in + let name = quotation.q_name in + debug quot "handle_quotation: name: %s, str: %S@." name quotation.q_contents in + let expander = + try find name tag + with + [ Loc.Exc_located _ (Error.E _) as exc -> raise exc + | Loc.Exc_located qloc exc -> + raise (Loc.Exc_located qloc (Error.E (name, pos_tag, Finding, exc))) + | exc -> + raise (Loc.Exc_located loc (Error.E (name, pos_tag, Finding, exc))) ] + in + let loc = Loc.join (Loc.move `start quotation.q_shift loc) in + expand_quotation loc expander pos_tag quotation; + +end; diff --git a/camlp4/Camlp4/Struct/Token.ml b/camlp4/Camlp4/Struct/Token.ml new file mode 100644 index 0000000..384bba9 --- /dev/null +++ b/camlp4/Camlp4/Struct/Token.ml @@ -0,0 +1,244 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open Format; + +module Make (Loc : Sig.Loc) +: Sig.Camlp4Token with module Loc = Loc += struct + module Loc = Loc; + open Sig; + type t = camlp4_token; + type token = t; + + value to_string = + fun + [ KEYWORD s -> sprintf "KEYWORD %S" s + | SYMBOL s -> sprintf "SYMBOL %S" s + | LIDENT s -> sprintf "LIDENT %S" s + | UIDENT s -> sprintf "UIDENT %S" s + | INT _ s -> sprintf "INT %s" s + | INT32 _ s -> sprintf "INT32 %sd" s + | INT64 _ s -> sprintf "INT64 %sd" s + | NATIVEINT _ s-> sprintf "NATIVEINT %sd" s + | FLOAT _ s -> sprintf "FLOAT %s" s + | CHAR _ s -> sprintf "CHAR '%s'" s + | STRING _ s -> sprintf "STRING \"%s\"" s + (* here it's not %S since the string is already escaped *) + | LABEL s -> sprintf "LABEL %S" s + | OPTLABEL s -> sprintf "OPTLABEL %S" s + | ANTIQUOT n s -> sprintf "ANTIQUOT %s: %S" n s + | QUOTATION x -> sprintf "QUOTATION { q_name=%S; q_loc=%S; q_shift=%d; q_contents=%S }" + x.q_name x.q_loc x.q_shift x.q_contents + | COMMENT s -> sprintf "COMMENT %S" s + | BLANKS s -> sprintf "BLANKS %S" s + | NEWLINE -> sprintf "NEWLINE" + | EOI -> sprintf "EOI" + | ESCAPED_IDENT s -> sprintf "ESCAPED_IDENT %S" s + | LINE_DIRECTIVE i None -> sprintf "LINE_DIRECTIVE %d" i + | LINE_DIRECTIVE i (Some s) -> sprintf "LINE_DIRECTIVE %d %S" i s ]; + + value print ppf x = pp_print_string ppf (to_string x); + + value match_keyword kwd = + fun + [ KEYWORD kwd' when kwd = kwd' -> True + | _ -> False ]; + + value extract_string = + fun + [ KEYWORD s | SYMBOL s | LIDENT s | UIDENT s | INT _ s | INT32 _ s | + INT64 _ s | NATIVEINT _ s | FLOAT _ s | CHAR _ s | STRING _ s | + LABEL s | OPTLABEL s | COMMENT s | BLANKS s | ESCAPED_IDENT s -> s + | tok -> + invalid_arg ("Cannot extract a string from this token: "^ + to_string tok) ]; + + module Error = struct + type t = + [ Illegal_token of string + | Keyword_as_label of string + | Illegal_token_pattern of string and string + | Illegal_constructor of string ]; + + exception E of t; + + value print ppf = + fun + [ Illegal_token s -> + fprintf ppf "Illegal token (%s)" s + | Keyword_as_label kwd -> + fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd + | Illegal_token_pattern p_con p_prm -> + fprintf ppf "Illegal token pattern: %s %S" p_con p_prm + | Illegal_constructor con -> + fprintf ppf "Illegal constructor %S" con ]; + + value to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b; + end; + let module M = ErrorHandler.Register Error in (); + + module Filter = struct + type token_filter = stream_filter t Loc.t; + + type t = + { is_kwd : string -> bool; + filter : mutable token_filter }; + + value err error loc = + raise (Loc.Exc_located loc (Error.E error)); + + value keyword_conversion tok is_kwd = + match tok with + [ SYMBOL s | LIDENT s | UIDENT s when is_kwd s -> KEYWORD s + | ESCAPED_IDENT s -> LIDENT s + | _ -> tok ]; + + value check_keyword_as_label tok loc is_kwd = + let s = + match tok with + [ LABEL s -> s + | OPTLABEL s -> s + | _ -> "" ] + in if s <> "" && is_kwd s then err (Error.Keyword_as_label s) loc else (); + + value check_unknown_keywords tok loc = + match tok with + [ SYMBOL s -> err (Error.Illegal_token s) loc + | _ -> () ]; + + value error_no_respect_rules p_con p_prm = + raise (Error.E (Error.Illegal_token_pattern p_con p_prm)); + + value check_keyword _ = True; + (* FIXME let lb = Lexing.from_string s in + let next () = token default_context lb in + try + match next () with + [ SYMBOL _ | UIDENT _ | LIDENT _ -> (next () = EOI) + | _ -> False ] + with [ Stream.Error _ -> False ]; *) + + value error_on_unknown_keywords = ref False; + + value rec ignore_layout = + parser + [ [: `(COMMENT _ | BLANKS _ | NEWLINE | LINE_DIRECTIVE _ _, _); s :] -> + ignore_layout s + | [: ` x; s :] -> [: ` x; ignore_layout s :] + | [: :] -> [: :] ]; + + value mk is_kwd = + { is_kwd = is_kwd; + filter = ignore_layout }; + + value filter x = + let f tok loc = do { + let tok = keyword_conversion tok x.is_kwd; + check_keyword_as_label tok loc x.is_kwd; + if error_on_unknown_keywords.val + then check_unknown_keywords tok loc else (); + debug token "@[Lexer before filter:@ %a@ at@ %a@]@." + print tok Loc.dump loc in + (tok, loc) + } in + let rec filter = + parser + [ [: `(tok, loc); s :] -> [: ` f tok loc; filter s :] + | [: :] -> [: :] ] + in + let rec tracer = (* FIXME add a debug block construct *) + parser + [ [: `((_tok, _loc) as x); xs :] -> + debug token "@[Lexer after filter:@ %a@ at@ %a@]@." + print _tok Loc.dump _loc in + [: ` x; tracer xs :] + | [: :] -> [: :] ] + in fun strm -> tracer (x.filter (filter strm)); + + value define_filter x f = x.filter := f x.filter; + + value keyword_added _ _ _ = (); + value keyword_removed _ _ = (); + end; + +end; + +(* Char and string tokens to real chars and string *) +module Eval = struct + + value valch x = Char.code x - Char.code '0'; + value valch_hex x = + let d = Char.code x in + if d >= 97 then d - 87 + else if d >= 65 then d - 55 + else d - 48; + + value rec skip_indent = parser + [ [: `' ' | '\t'; s :] -> skip_indent s + | [: :] -> () ]; + + value skip_opt_linefeed = parser + [ [: `'\010' :] -> () + | [: :] -> () ]; + + value chr c = + if c < 0 || c > 255 then failwith "invalid char token" else Char.chr c; + + value rec backslash = parser + [ [: `'\010' :] -> '\010' + | [: `'\013' :] -> '\013' + | [: `'n' :] -> '\n' + | [: `'r' :] -> '\r' + | [: `'t' :] -> '\t' + | [: `'b' :] -> '\b' + | [: `'\\' :] -> '\\' + | [: `'"' :] -> '"' + | [: `''' :] -> ''' + | [: `' ' :] -> ' ' + | [: `('0'..'9' as c1); `('0'..'9' as c2); `('0'..'9' as c3) :] -> + chr (100 * (valch c1) + 10 * (valch c2) + (valch c3)) + | [: `'x'; `('0'..'9' | 'a'..'f' | 'A'..'F' as c1) ; + `('0'..'9' | 'a'..'f' | 'A'..'F' as c2) :] -> + chr (16 * (valch_hex c1) + (valch_hex c2)) ]; + + value rec backslash_in_string strict store = parser + [ [: `'\010'; s :] -> skip_indent s + | [: `'\013'; s :] -> do { skip_opt_linefeed s; skip_indent s } + | [: x = backslash :] -> store x + | [: `c when not strict :] -> do { store '\\'; store c } + | [: :] -> failwith "invalid string token" ]; + + value char s = + if String.length s = 1 then s.[0] + else if String.length s = 0 then failwith "invalid char token" + else match Stream.of_string s with parser + [ [: `'\\'; x = backslash :] -> x + | [: :] -> failwith "invalid char token" ]; + + value string ?strict s = + let buf = Buffer.create 23 in + let store = Buffer.add_char buf in + let rec parse = parser + [ [: `'\\'; _ = backslash_in_string (strict <> None) store; s :] -> parse s + | [: `c; s :] -> do { store c; parse s } + | [: :] -> Buffer.contents buf ] + in parse (Stream.of_string s); +end; diff --git a/camlp4/Camlp4/Struct/Token.mli b/camlp4/Camlp4/Struct/Token.mli new file mode 100644 index 0000000..812df0e --- /dev/null +++ b/camlp4/Camlp4/Struct/Token.mli @@ -0,0 +1,35 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Make (Loc : Sig.Loc) : Sig.Camlp4Token with module Loc = Loc; + +module Eval : sig + value char : string -> char; + (** Convert a char token, where the escape sequences (backslashes) + remain to be interpreted; raise [Failure] if an + incorrect backslash sequence is found; [Token.Eval.char (Char.escaped c)] + returns [c] *) + + value string : ?strict:unit -> string -> string; + (** [Taken.Eval.string strict s] + Convert a string token, where the escape sequences (backslashes) + remain to be interpreted; raise [Failure] if [strict] and an + incorrect backslash sequence is found; + [Token.Eval.string strict (String.escaped s)] returns [s] *) +end; diff --git a/camlp4/Camlp4Bin.ml b/camlp4/Camlp4Bin.ml new file mode 100644 index 0000000..5a029b9 --- /dev/null +++ b/camlp4/Camlp4Bin.ml @@ -0,0 +1,323 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +open Camlp4; +open PreCast.Syntax; +open PreCast; +open Format; +module CleanAst = Camlp4.Struct.CleanAst.Make Ast; +module SSet = Set.Make String; + +value pa_r = "Camlp4OCamlRevisedParser"; +value pa_rr = "Camlp4OCamlReloadedParser"; +value pa_o = "Camlp4OCamlParser"; +value pa_rp = "Camlp4OCamlRevisedParserParser"; +value pa_op = "Camlp4OCamlParserParser"; +value pa_g = "Camlp4GrammarParser"; +value pa_m = "Camlp4MacroParser"; +value pa_qb = "Camlp4QuotationCommon"; +value pa_q = "Camlp4QuotationExpander"; +value pa_rq = "Camlp4OCamlRevisedQuotationExpander"; +value pa_oq = "Camlp4OCamlOriginalQuotationExpander"; +value pa_l = "Camlp4ListComprehension"; + +open Register; + +value dyn_loader = ref (fun []); +value rcall_callback = ref (fun () -> ()); +value loaded_modules = ref SSet.empty; +value add_to_loaded_modules name = + loaded_modules.val := SSet.add name loaded_modules.val; + +value (objext,libext) = + if DynLoader.is_native then (".cmxs",".cmxs") + else (".cmo",".cma"); + +value rewrite_and_load n x = + let dyn_loader = dyn_loader.val () in + let find_in_path = DynLoader.find_in_path dyn_loader in + let real_load name = do { + add_to_loaded_modules name; + DynLoader.load dyn_loader name + } in + let load = List.iter begin fun n -> + if SSet.mem n loaded_modules.val || List.mem n Register.loaded_modules.val then () + else begin + add_to_loaded_modules n; + DynLoader.load dyn_loader (n ^ objext); + end + end in + do { + match (n, String.lowercase x) with + [ ("Parsers"|"", "pa_r.cmo" | "r" | "ocamlr" | "ocamlrevised" | "camlp4ocamlrevisedparser.cmo") -> load [pa_r] + | ("Parsers"|"", "rr" | "reloaded" | "ocamlreloaded" | "camlp4ocamlreloadedparser.cmo") -> load [pa_rr] + | ("Parsers"|"", "pa_o.cmo" | "o" | "ocaml" | "camlp4ocamlparser.cmo") -> load [pa_r; pa_o] + | ("Parsers"|"", "pa_rp.cmo" | "rp" | "rparser" | "camlp4ocamlrevisedparserparser.cmo") -> load [pa_r; pa_o; pa_rp] + | ("Parsers"|"", "pa_op.cmo" | "op" | "parser" | "camlp4ocamlparserparser.cmo") -> load [pa_r; pa_o; pa_rp; pa_op] + | ("Parsers"|"", "pa_extend.cmo" | "pa_extend_m.cmo" | "g" | "grammar" | "camlp4grammarparser.cmo") -> load [pa_g] + | ("Parsers"|"", "pa_macro.cmo" | "m" | "macro" | "camlp4macroparser.cmo") -> load [pa_m] + | ("Parsers"|"", "q" | "camlp4quotationexpander.cmo") -> load [pa_qb; pa_q] + | ("Parsers"|"", "q_mlast.cmo" | "rq" | "camlp4ocamlrevisedquotationexpander.cmo") -> load [pa_qb; pa_rq] + | ("Parsers"|"", "oq" | "camlp4ocamloriginalquotationexpander.cmo") -> load [pa_r; pa_o; pa_qb; pa_oq] + | ("Parsers"|"", "rf") -> load [pa_r; pa_rp; pa_qb; pa_q; pa_g; pa_l; pa_m] + | ("Parsers"|"", "of") -> load [pa_r; pa_o; pa_rp; pa_op; pa_qb; pa_rq; pa_g; pa_l; pa_m] + | ("Parsers"|"", "comp" | "camlp4listcomprehension.cmo") -> load [pa_l] + | ("Filters"|"", "lift" | "camlp4astlifter.cmo") -> load ["Camlp4AstLifter"] + | ("Filters"|"", "exn" | "camlp4exceptiontracer.cmo") -> load ["Camlp4ExceptionTracer"] + | ("Filters"|"", "prof" | "camlp4profiler.cmo") -> load ["Camlp4Profiler"] + (* map is now an alias of fold since fold handles map too *) + | ("Filters"|"", "map" | "camlp4mapgenerator.cmo") -> load ["Camlp4FoldGenerator"] + | ("Filters"|"", "fold" | "camlp4foldgenerator.cmo") -> load ["Camlp4FoldGenerator"] + | ("Filters"|"", "meta" | "camlp4metagenerator.cmo") -> load ["Camlp4MetaGenerator"] + | ("Filters"|"", "trash" | "camlp4trashremover.cmo") -> load ["Camlp4TrashRemover"] + | ("Filters"|"", "striploc" | "camlp4locationstripper.cmo") -> load ["Camlp4LocationStripper"] + | ("Printers"|"", "pr_r.cmo" | "r" | "ocamlr" | "camlp4ocamlrevisedprinter.cmo") -> + Register.enable_ocamlr_printer () + | ("Printers"|"", "pr_o.cmo" | "o" | "ocaml" | "camlp4ocamlprinter.cmo") -> + Register.enable_ocaml_printer () + | ("Printers"|"", "pr_dump.cmo" | "p" | "dumpocaml" | "camlp4ocamlastdumper.cmo") -> + Register.enable_dump_ocaml_ast_printer () + | ("Printers"|"", "d" | "dumpcamlp4" | "camlp4astdumper.cmo") -> + Register.enable_dump_camlp4_ast_printer () + | ("Printers"|"", "a" | "auto" | "camlp4autoprinter.cmo") -> + load ["Camlp4AutoPrinter"] + | _ -> + let y = "Camlp4"^n^"/"^x^objext in + real_load (try find_in_path y with [ Not_found -> x ]) ]; + rcall_callback.val (); + }; + +value print_warning = eprintf "%a:\n%s@." Loc.print; + +value rec parse_file dyn_loader name pa getdir = + let directive_handler = Some (fun ast -> + match getdir ast with + [ Some x -> + match x with + [ (_, "load", s) -> do { rewrite_and_load "" s; None } + | (_, "directory", s) -> do { DynLoader.include_dir dyn_loader s; None } + | (_, "use", s) -> Some (parse_file dyn_loader s pa getdir) + | (_, "default_quotation", s) -> do { Quotation.default.val := s; None } + | (loc, _, _) -> Loc.raise loc (Stream.Error "bad directive") ] + | None -> None ]) in + let loc = Loc.mk name + in do { + current_warning.val := print_warning; + let ic = if name = "-" then stdin else open_in_bin name; + let cs = Stream.of_channel ic; + let clear () = if name = "-" then () else close_in ic; + let phr = + try pa ?directive_handler loc cs + with x -> do { clear (); raise x }; + clear (); + phr + }; + +value output_file = ref None; + +value process dyn_loader name pa pr clean fold_filters getdir = + let ast = parse_file dyn_loader name pa getdir in + let ast = fold_filters (fun t filter -> filter t) ast in + let ast = clean ast in + pr ?input_file:(Some name) ?output_file:output_file.val ast; + +value gind = + fun + [ <:sig_item@loc< # $n$ $str:s$ >> -> Some (loc, n, s) + | _ -> None ]; + +value gimd = + fun + [ <:str_item@loc< # $n$ $str:s$ >> -> Some (loc, n, s) + | _ -> None ]; + +value process_intf dyn_loader name = + process dyn_loader name CurrentParser.parse_interf CurrentPrinter.print_interf + (new CleanAst.clean_ast)#sig_item + AstFilters.fold_interf_filters gind; +value process_impl dyn_loader name = + process dyn_loader name CurrentParser.parse_implem CurrentPrinter.print_implem + (new CleanAst.clean_ast)#str_item + AstFilters.fold_implem_filters gimd; + +value just_print_the_version () = + do { printf "%s@." Camlp4_config.version; exit 0 }; + +value print_version () = + do { eprintf "Camlp4 version %s@." Camlp4_config.version; exit 0 }; + +value print_stdlib () = + do { printf "%s@." Camlp4_config.camlp4_standard_library; exit 0 }; + +value usage ini_sl ext_sl = + do { + eprintf "\ +Usage: camlp4 [load-options] [--] [other-options] +Options: +.ml Parse this implementation file +.mli Parse this interface file +.%s Load this module inside the Camlp4 core@." +(if DynLoader.is_native then "cmxs " else "(cmo|cma)") +; + Options.print_usage_list ini_sl; + (* loop (ini_sl @ ext_sl) where rec loop = + fun + [ [(y, _, _) :: _] when y = "-help" -> () + | [_ :: sl] -> loop sl + | [] -> eprintf " -help Display this list of options.@." ]; *) + if ext_sl <> [] then do { + eprintf "Options added by loaded object files:@."; + Options.print_usage_list ext_sl; + } + else (); + }; + +value warn_noassert () = + do { + eprintf "\ +camlp4 warning: option -noassert is obsolete +You should give the -noassert option to the ocaml compiler instead.@."; + }; + +type file_kind = + [ Intf of string + | Impl of string + | Str of string + | ModuleImpl of string + | IncludeDir of string ]; + +value search_stdlib = ref True; +value print_loaded_modules = ref False; +value (task, do_task) = + let t = ref None in + let task f x = + let () = Camlp4_config.current_input_file.val := x in + t.val := Some (if t.val = None then (fun _ -> f x) + else (fun usage -> usage ())) in + let do_task usage = match t.val with [ Some f -> f usage | None -> () ] in + (task, do_task); +value input_file x = + let dyn_loader = dyn_loader.val () in + do { + rcall_callback.val (); + match x with + [ Intf file_name -> task (process_intf dyn_loader) file_name + | Impl file_name -> task (process_impl dyn_loader) file_name + | Str s -> + begin + let (f, o) = Filename.open_temp_file "from_string" ".ml"; + output_string o s; + close_out o; + task (process_impl dyn_loader) f; + at_exit (fun () -> Sys.remove f); + end + | ModuleImpl file_name -> rewrite_and_load "" file_name + | IncludeDir dir -> DynLoader.include_dir dyn_loader dir ]; + rcall_callback.val (); + }; + +value initial_spec_list = + [("-I", Arg.String (fun x -> input_file (IncludeDir x)), + " Add directory in search patch for object files."); + ("-where", Arg.Unit print_stdlib, + "Print camlp4 library directory and exit."); + ("-nolib", Arg.Clear search_stdlib, + "No automatic search for object files in library directory."); + ("-intf", Arg.String (fun x -> input_file (Intf x)), + " Parse as an interface, whatever its extension."); + ("-impl", Arg.String (fun x -> input_file (Impl x)), + " Parse as an implementation, whatever its extension."); + ("-str", Arg.String (fun x -> input_file (Str x)), + " Parse as an implementation."); + ("-unsafe", Arg.Set Camlp4_config.unsafe, + "Generate unsafe accesses to array and strings."); + ("-noassert", Arg.Unit warn_noassert, + "Obsolete, do not use this option."); + ("-verbose", Arg.Set Camlp4_config.verbose, + "More verbose in parsing errors."); + ("-loc", Arg.Set_string Loc.name, + " Name of the location variable (default: " ^ Loc.name.val ^ ")."); + ("-QD", Arg.String (fun x -> Quotation.dump_file.val := Some x), + " Dump quotation expander result in case of syntax error."); + ("-o", Arg.String (fun x -> output_file.val := Some x), + " Output on instead of standard output."); + ("-v", Arg.Unit print_version, + "Print Camlp4 version and exit."); + ("-version", Arg.Unit just_print_the_version, + "Print Camlp4 version number and exit."); + ("-no_quot", Arg.Clear Camlp4_config.quotations, + "Don't parse quotations, allowing to use, e.g. \"<:>\" as token."); + ("-loaded-modules", Arg.Set print_loaded_modules, "Print the list of loaded modules."); + ("-parser", Arg.String (rewrite_and_load "Parsers"), + " Load the parser Camlp4Parsers/.cm(o|a|xs)"); + ("-printer", Arg.String (rewrite_and_load "Printers"), + " Load the printer Camlp4Printers/.cm(o|a|xs)"); + ("-filter", Arg.String (rewrite_and_load "Filters"), + " Load the filter Camlp4Filters/.cm(o|a|xs)"); + ("-ignore", Arg.String ignore, "ignore the next argument"); + ("--", Arg.Unit ignore, "Deprecated, does nothing") +]; + +Options.init initial_spec_list; + +value anon_fun name = + input_file + (if Filename.check_suffix name ".mli" then Intf name + else if Filename.check_suffix name ".ml" then Impl name + else if Filename.check_suffix name objext then ModuleImpl name + else if Filename.check_suffix name libext then ModuleImpl name + else raise (Arg.Bad ("don't know what to do with " ^ name))); + +value main argv = + let usage () = do { usage initial_spec_list (Options.ext_spec_list ()); exit 0 } in + try do { + let dynloader = DynLoader.mk ~ocaml_stdlib:search_stdlib.val + ~camlp4_stdlib:search_stdlib.val (); + dyn_loader.val := fun () -> dynloader; + let call_callback () = + Register.iter_and_take_callbacks + (fun (name, module_callback) -> + let () = add_to_loaded_modules name in + module_callback ()); + call_callback (); + rcall_callback.val := call_callback; + match Options.parse anon_fun argv with + [ [] -> () + | ["-help"|"--help"|"-h"|"-?" :: _] -> usage () + | [s :: _] -> + do { eprintf "%s: unknown or misused option\n" s; + eprintf "Use option -help for usage@."; + exit 2 } ]; + do_task usage; + call_callback (); + if print_loaded_modules.val then do { + SSet.iter (eprintf "%s@.") loaded_modules.val; + } else () + } + with + [ Arg.Bad s -> do { eprintf "Error: %s\n" s; + eprintf "Use option -help for usage@."; + exit 2 } + | Arg.Help _ -> usage () + | exc -> do { eprintf "@[%a@]@." ErrorHandler.print exc; exit 2 } ]; + +main Sys.argv; diff --git a/camlp4/Camlp4Filters/Camlp4AstLifter.ml b/camlp4/Camlp4Filters/Camlp4AstLifter.ml new file mode 100644 index 0000000..768e4da --- /dev/null +++ b/camlp4/Camlp4Filters/Camlp4AstLifter.ml @@ -0,0 +1,44 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + + +open Camlp4; + +module Id = struct + value name = "Camlp4AstLifter"; + value version = Sys.ocaml_version; +end; + +module Make (AstFilters : Camlp4.Sig.AstFilters) = struct + open AstFilters; + + module MetaLoc = struct + module Ast = Ast; + value meta_loc_patt _loc _ = <:patt< loc >>; + value meta_loc_expr _loc _ = <:expr< loc >>; + end; + module MetaAst = Ast.Meta.Make MetaLoc; + + register_str_item_filter (fun ast -> + let _loc = Ast.loc_of_str_item ast in + <:str_item< let loc = Loc.ghost in $exp:MetaAst.Expr.meta_str_item _loc ast$ >>); + +end; + +let module M = Camlp4.Register.AstFilter Id Make in (); diff --git a/camlp4/Camlp4Filters/Camlp4ExceptionTracer.ml b/camlp4/Camlp4Filters/Camlp4ExceptionTracer.ml new file mode 100644 index 0000000..3d338c4 --- /dev/null +++ b/camlp4/Camlp4Filters/Camlp4ExceptionTracer.ml @@ -0,0 +1,68 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + + +open Camlp4; + +module Id = struct + value name = "Camlp4ExceptionTracer"; + value version = Sys.ocaml_version; +end; + +module Make (AstFilters : Camlp4.Sig.AstFilters) = struct + open AstFilters; + open Ast; + + value add_debug_expr e = + (* let _loc = Loc.make_absolute (MLast.loc_of_expr e) in *) + let _loc = Ast.loc_of_expr e in + let msg = "camlp4-debug: exc: %s at " ^ Loc.to_string _loc ^ "@." in + <:expr< + try $e$ + with + [ Stream.Failure | Exit as exc -> raise exc + | exc -> do { + if Debug.mode "exc" then + Format.eprintf $`str:msg$ (Printexc.to_string exc) else (); + raise exc + } ] >>; + + value rec map_match_case = + fun + [ <:match_case@_loc< $m1$ | $m2$ >> -> + <:match_case< $map_match_case m1$ | $map_match_case m2$ >> + | <:match_case@_loc< $p$ when $w$ -> $e$ >> -> + <:match_case@_loc< $p$ when $w$ -> $add_debug_expr e$ >> + | m -> m ]; + + value filter = object + inherit Ast.map as super; + method expr = fun + [ <:expr@_loc< fun [ $m$ ] >> -> <:expr< fun [ $map_match_case m$ ] >> + | x -> super#expr x ]; + method str_item = fun + [ <:str_item< module Debug = $_$ >> as st -> st + | st -> super#str_item st ]; + end; + + register_str_item_filter filter#str_item; + +end; + +let module M = Camlp4.Register.AstFilter Id Make in (); diff --git a/camlp4/Camlp4Filters/Camlp4FoldGenerator.ml b/camlp4/Camlp4Filters/Camlp4FoldGenerator.ml new file mode 100644 index 0000000..f5efd2c --- /dev/null +++ b/camlp4/Camlp4Filters/Camlp4FoldGenerator.ml @@ -0,0 +1,609 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006,2007 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + + +open Camlp4; + +module Id = struct + value name = "Camlp4FoldGenerator"; + value version = Sys.ocaml_version; +end; + +module Make (AstFilters : Camlp4.Sig.AstFilters) = struct + open AstFilters; + module StringMap = Map.Make String; + open Ast; + + value _loc = Loc.ghost; + + value sf = Printf.sprintf; + + value xik i k = + let i = + if i < 0 then assert False + else if i = 0 then "" + else sf "_i%d" i + in + let k = + if k < 1 then assert False + else if k = 1 then "" + else sf "_k%d" k + in + sf "_x%s%s" i k; + value exik i k = <:expr< $lid:xik i k$ >>; + value pxik i k = <:patt< $lid:xik i k$ >>; + value elidk y k = <:expr< $lid:sf "%s_%d" y k$ >>; + value plidk y k = <:patt< $lid:sf "%s_%d" y k$ >>; + + value xs s = "_x_" ^ s; + value xsk = sf "_x_%s_%d"; + value exsk s k = <:expr< $lid:xsk s k$>>; + + value rec apply_expr accu = + fun + [ [] -> accu + | [x :: xs] -> + let _loc = Ast.loc_of_expr x + in apply_expr <:expr< $accu$ $x$ >> xs ]; + + value rec apply_patt accu = + fun + [ [] -> accu + | [x :: xs] -> + let _loc = Ast.loc_of_patt x + in apply_patt <:patt< $accu$ $x$ >> xs ]; + + value rec apply_ctyp accu = + fun + [ [] -> accu + | [x :: xs] -> + let _loc = Ast.loc_of_ctyp x + in apply_ctyp <:ctyp< $accu$ $x$ >> xs ]; + + value opt_map f = fun [ Some x -> Some (f x) | None -> None ]; + + value list_init f n = + let rec self m = + if m = n then [] + else [f m :: self (succ m)] + in self 0; + + value rec lid_of_ident sep = + fun + [ <:ident< $lid:s$ >> | <:ident< $uid:s$ >> -> s + | <:ident< $i1$.$i2$ >> -> lid_of_ident sep i1 ^ sep ^ lid_of_ident sep i2 + | _ -> assert False ]; + + type type_decl = (string * Ast.ident * list Ast.ctyp * Ast.ctyp * bool); + + value builtin_types = + let tyMap = StringMap.empty in + let tyMap = + let abstr = ["string"; "int"; "float"; "int32"; "int64"; "nativeint"; "char"] in + List.fold_right + (fun name -> StringMap.add name (name, <:ident< $lid:name$ >>, [], <:ctyp<>>, False)) + abstr tyMap + in + let tyMap = + let concr = + [("bool", <:ident>, [], <:ctyp< [ False | True ] >>, False); + ("list", <:ident>, [ <:ctyp< 'a >> ], <:ctyp< [ $uid:"[]"$ | $uid:"::"$ of 'a and list 'a ] >>, False); + ("option", <:ident

add to the search path for INCLUDE'd files + + After having used a DEFINE followed by "= ", you + can use it in expressions *and* in patterns. If the expression defining + the macro cannot be used as a pattern, there is an error message if + it is used in a pattern. + + You can also define a local macro in an expression usigng the DEFINE ... IN form. + Note that local macros have lowercase names and can not take parameters. + + If a macro is defined to = NOTHING, and then used as an argument to a function, + this will be equivalent to function taking one less argument. Similarly, + passing NOTHING as an argument to a macro is equivalent to "erasing" the + corresponding parameter from the macro body. + + The toplevel statement INCLUDE can be used to include a + file containing macro definitions and also any other toplevel items. + The included files are looked up in directories passed in via the -I + option, falling back to the current directory. + + The expression __FILE__ returns the current compiled file name. + The expression __LOCATION__ returns the current location of itself. + +*) + +open Camlp4; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + type item_or_def 'a = + [ SdStr of 'a + | SdDef of string and option (list string * Ast.expr) + | SdUnd of string + | SdITE of bool and list (item_or_def 'a) and list (item_or_def 'a) + | SdLazy of Lazy.t 'a ]; + + value rec list_remove x = + fun + [ [(y, _) :: l] when y = x -> l + | [d :: l] -> [d :: list_remove x l] + | [] -> [] ]; + + value defined = ref []; + + value is_defined i = List.mem_assoc i defined.val; + + value bad_patt _loc = + Loc.raise _loc + (Failure + "this macro cannot be used in a pattern (see its definition)"); + + value substp _loc env = + loop where rec loop = + fun + [ <:expr< $e1$ $e2$ >> -> <:patt< $loop e1$ $loop e2$ >> + | <:expr< >> -> <:patt< >> + | <:expr< $lid:x$ >> -> + try List.assoc x env with + [ Not_found -> <:patt< $lid:x$ >> ] + | <:expr< $uid:x$ >> -> + try List.assoc x env with + [ Not_found -> <:patt< $uid:x$ >> ] + | <:expr< $int:x$ >> -> <:patt< $int:x$ >> + | <:expr< $str:s$ >> -> <:patt< $str:s$ >> + | <:expr< ($tup:x$) >> -> <:patt< ($tup:loop x$) >> + | <:expr< $x1$, $x2$ >> -> <:patt< $loop x1$, $loop x2$ >> + | <:expr< { $bi$ } >> -> + let rec substbi = fun + [ <:rec_binding< $b1$; $b2$ >> -> <:patt< $substbi b1$; $substbi b2$ >> + | <:rec_binding< $i$ = $e$ >> -> <:patt< $i$ = $loop e$ >> + | _ -> bad_patt _loc ] + in <:patt< { $substbi bi$ } >> + | _ -> bad_patt _loc ]; + + class reloc _loc = object + inherit Ast.map as super; + method loc _ = _loc; + (* method _Loc_t _ = _loc; *) + end; + + class subst _loc env = object + inherit reloc _loc as super; + method expr = + fun + [ <:expr< $lid:x$ >> | <:expr< $uid:x$ >> as e -> + try List.assoc x env with + [ Not_found -> super#expr e ] + | e -> super#expr e ]; + + method patt = + fun + [ <:patt< $lid:x$ >> | <:patt< $uid:x$ >> as p -> + try substp _loc [] (List.assoc x env) with + [ Not_found -> super#patt p ] + | p -> super#patt p ]; + end; + + value incorrect_number loc l1 l2 = + Loc.raise loc + (Failure + (Printf.sprintf "expected %d parameters; found %d" + (List.length l2) (List.length l1))); + + value define eo x = + do { + match eo with + [ Some ([], e) -> + EXTEND Gram + expr: LEVEL "simple" + [ [ UIDENT $x$ -> (new reloc _loc)#expr e ]] + ; + patt: LEVEL "simple" + [ [ UIDENT $x$ -> + let p = substp _loc [] e + in (new reloc _loc)#patt p ]] + ; + END + | Some (sl, e) -> + EXTEND Gram + expr: LEVEL "apply" + [ [ UIDENT $x$; param = SELF -> + let el = + match param with + [ <:expr< ($tup:e$) >> -> Ast.list_of_expr e [] + | e -> [e] ] + in + if List.length el = List.length sl then + let env = List.combine sl el in + (new subst _loc env)#expr e + else + incorrect_number _loc el sl ] ] + ; + patt: LEVEL "simple" + [ [ UIDENT $x$; param = SELF -> + let pl = + match param with + [ <:patt< ($tup:p$) >> -> Ast.list_of_patt p [] + | p -> [p] ] + in + if List.length pl = List.length sl then + let env = List.combine sl pl in + let p = substp _loc env e in + (new reloc _loc)#patt p + else + incorrect_number _loc pl sl ] ] + ; + END + | None -> () ]; + defined.val := [(x, eo) :: defined.val]; + }; + + value undef x = + try + do { + let eo = List.assoc x defined.val in + match eo with + [ Some ([], _) -> + do { + DELETE_RULE Gram expr: UIDENT $x$ END; + DELETE_RULE Gram patt: UIDENT $x$ END; + } + | Some (_, _) -> + do { + DELETE_RULE Gram expr: UIDENT $x$; SELF END; + DELETE_RULE Gram patt: UIDENT $x$; SELF END; + } + | None -> () ]; + defined.val := list_remove x defined.val; + } + with + [ Not_found -> () ]; + + value parse_def s = + match Gram.parse_string expr (Loc.mk "") s with + [ <:expr< $uid:n$ >> -> define None n + | <:expr< $uid:n$ = $e$ >> -> define (Some ([],e)) n + | _ -> invalid_arg s ]; + + (* This is a list of directories to search for INCLUDE statements. *) + value include_dirs = ref []; + + (* Add something to the above, make sure it ends with a slash. *) + value add_include_dir str = + if str <> "" then + let str = + if String.get str ((String.length str)-1) = '/' + then str else str ^ "/" + in include_dirs.val := include_dirs.val @ [str] + else (); + + value parse_include_file rule = + let dir_ok file dir = Sys.file_exists (dir ^ file) in + fun file -> + let file = + try (List.find (dir_ok file) (include_dirs.val @ ["./"])) ^ file + with [ Not_found -> file ] + in + let ch = open_in file in + let st = Stream.of_channel ch in + Gram.parse rule (Loc.mk file) st; + + value rec execute_macro nil cons = + fun + [ SdStr i -> i + | SdDef x eo -> do { define eo x; nil } + | SdUnd x -> do { undef x; nil } + | SdITE b l1 l2 -> execute_macro_list nil cons (if b then l1 else l2) + | SdLazy l -> Lazy.force l ] + + and execute_macro_list nil cons = fun + [ [] -> nil + | [hd::tl] -> (* The evaluation order is important here *) + let il1 = execute_macro nil cons hd in + let il2 = execute_macro_list nil cons tl in + cons il1 il2 ] + ; + + (* Stack of conditionals. *) + value stack = Stack.create () ; + + (* Make an SdITE value by extracting the result of the test from the stack. *) + value make_SdITE_result st1 st2 = + let test = Stack.pop stack in + SdITE test st1 st2 ; + + type branch = [ Then | Else ]; + + (* Execute macro only if it belongs to the currently active branch. *) + value execute_macro_if_active_branch _loc nil cons branch macro_def = + let test = Stack.top stack in + let item = + if (test && branch=Then) || ((not test) && branch=Else) then + execute_macro nil cons macro_def + else (* ignore the macro *) + nil + in SdStr(item) + ; + + EXTEND Gram + GLOBAL: expr patt str_item sig_item; + str_item: FIRST + [ [ x = macro_def -> + execute_macro <:str_item<>> (fun a b -> <:str_item< $a$; $b$ >>) x ] ] + ; + sig_item: FIRST + [ [ x = macro_def_sig -> + execute_macro <:sig_item<>> (fun a b -> <:sig_item< $a$; $b$ >>) x ] ] + ; + macro_def: + [ [ "DEFINE"; i = uident; def = opt_macro_value -> SdDef i def + | "UNDEF"; i = uident -> SdUnd i + | "IFDEF"; uident_eval_ifdef; "THEN"; st1 = smlist_then; st2 = else_macro_def -> + make_SdITE_result st1 st2 + | "IFNDEF"; uident_eval_ifndef; "THEN"; st1 = smlist_then; st2 = else_macro_def -> + make_SdITE_result st1 st2 + | "INCLUDE"; fname = STRING -> + SdLazy (lazy (parse_include_file str_items fname)) ] ] + ; + macro_def_sig: + [ [ "DEFINE"; i = uident -> SdDef i None + | "UNDEF"; i = uident -> SdUnd i + | "IFDEF"; uident_eval_ifdef; "THEN"; sg1 = sglist_then; sg2 = else_macro_def_sig -> + make_SdITE_result sg1 sg2 + | "IFNDEF"; uident_eval_ifndef; "THEN"; sg1 = sglist_then; sg2 = else_macro_def_sig -> + make_SdITE_result sg1 sg2 + | "INCLUDE"; fname = STRING -> + SdLazy (lazy (parse_include_file sig_items fname)) ] ] + ; + uident_eval_ifdef: + [ [ i = uident -> Stack.push (is_defined i) stack ]] + ; + uident_eval_ifndef: + [ [ i = uident -> Stack.push (not (is_defined i)) stack ]] + ; + else_macro_def: + [ [ "ELSE"; st = smlist_else; endif -> st + | endif -> [] ] ] + ; + else_macro_def_sig: + [ [ "ELSE"; st = sglist_else; endif -> st + | endif -> [] ] ] + ; + else_expr: + [ [ "ELSE"; e = expr; endif -> e + | endif -> <:expr< () >> ] ] + ; + smlist_then: + [ [ sml = LIST1 [ d = macro_def; semi -> + execute_macro_if_active_branch _loc <:str_item<>> (fun a b -> <:str_item< $a$; $b$ >>) Then d + | si = str_item; semi -> SdStr si ] -> sml ] ] + ; + smlist_else: + [ [ sml = LIST1 [ d = macro_def; semi -> + execute_macro_if_active_branch _loc <:str_item<>> (fun a b -> <:str_item< $a$; $b$ >>) Else d + | si = str_item; semi -> SdStr si ] -> sml ] ] + ; + sglist_then: + [ [ sgl = LIST1 [ d = macro_def_sig; semi -> + execute_macro_if_active_branch _loc <:sig_item<>> (fun a b -> <:sig_item< $a$; $b$ >>) Then d + | si = sig_item; semi -> SdStr si ] -> sgl ] ] + ; + sglist_else: + [ [ sgl = LIST1 [ d = macro_def_sig; semi -> + execute_macro_if_active_branch _loc <:sig_item<>> (fun a b -> <:sig_item< $a$; $b$ >>) Else d + | si = sig_item; semi -> SdStr si ] -> sgl ] ] + ; + endif: + [ [ "END" -> () + | "ENDIF" -> () ] ] + ; + opt_macro_value: + [ [ "("; pl = LIST1 [ x = LIDENT -> x ] SEP ","; ")"; "="; e = expr -> Some (pl, e) + | "="; e = expr -> Some ([], e) + | -> None ] ] + ; + expr: LEVEL "top" + [ [ "IFDEF"; i = uident; "THEN"; e1 = expr; e2 = else_expr -> + if is_defined i then e1 else e2 + | "IFNDEF"; i = uident; "THEN"; e1 = expr; e2 = else_expr -> + if is_defined i then e2 else e1 + | "DEFINE"; i = LIDENT; "="; def = expr; "IN"; body = expr -> + (new subst _loc [(i, def)])#expr body ] ] + ; + expr: LEVEL "simple" + [ [ LIDENT "__FILE__" -> <:expr< $`str:Loc.file_name _loc$ >> + | LIDENT "__LOCATION__" -> + let (a, b, c, d, e, f, g, h) = Loc.to_tuple _loc in + <:expr< Loc.of_tuple + ($`str:a$, $`int:b$, $`int:c$, $`int:d$, + $`int:e$, $`int:f$, $`int:g$, + $if h then <:expr< True >> else <:expr< False >> $) >> ] ] + ; + patt: + [ [ "IFDEF"; i = uident; "THEN"; p1 = patt; "ELSE"; p2 = patt; endif -> + if is_defined i then p1 else p2 + | "IFNDEF"; i = uident; "THEN"; p1 = patt; "ELSE"; p2 = patt; endif -> + if is_defined i then p2 else p1 ] ] + ; + uident: + [ [ i = UIDENT -> i ] ] + ; + END; + + Options.add "-D" (Arg.String parse_def) + " Define for IFDEF instruction."; + Options.add "-U" (Arg.String undef) + " Undefine for IFDEF instruction."; + Options.add "-I" (Arg.String add_include_dir) + " Add a directory to INCLUDE search path."; + +end; + +let module M = Register.OCamlSyntaxExtension Id Make in (); + +module MakeNothing (AstFilters : Camlp4.Sig.AstFilters) = struct + open AstFilters; + open Ast; + + value remove_nothings = + fun + [ <:expr< $e$ NOTHING >> | <:expr< fun $ <:patt< NOTHING >> $ -> $e$ >> -> e + | e -> e]; + + register_str_item_filter (Ast.map_expr remove_nothings)#str_item; + +end; + +let module M = Camlp4.Register.AstFilter Id MakeNothing in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander.ml b/camlp4/Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander.ml new file mode 100644 index 0000000..c033a22 --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander.ml @@ -0,0 +1,25 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open PreCast; +let module Gram = MakeGram Lexer in +let module M1 = OCamlInitSyntax.Make Ast Gram Quotation in +let module M2 = Camlp4OCamlRevisedParser.Make M1 in +let module M3 = Camlp4OCamlParser.Make M2 in +let module M3 = Camlp4QuotationCommon.Make M3 Syntax.AntiquotSyntax in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml new file mode 100644 index 0000000..8a1b53c --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlParser.ml @@ -0,0 +1,682 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + +module Id : Sig.Id = struct + value name = "Camlp4OCamlParser"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + Camlp4_config.constructors_arity.val := False; + + (*FIXME remove this and use OCaml ones *) + value bigarray_set _loc var newval = + match var with + [ <:expr< Bigarray.Array1.get $arr$ $c1$ >> -> + Some <:expr< Bigarray.Array1.set $arr$ $c1$ $newval$ >> + | <:expr< Bigarray.Array2.get $arr$ $c1$ $c2$ >> -> + Some <:expr< Bigarray.Array2.set $arr$ $c1$ $c2$ $newval$ >> + | <:expr< Bigarray.Array3.get $arr$ $c1$ $c2$ $c3$ >> -> + Some <:expr< Bigarray.Array3.set $arr$ $c1$ $c2$ $c3$ $newval$ >> + | <:expr< Bigarray.Genarray.get $arr$ [| $coords$ |] >> -> + Some <:expr< Bigarray.Genarray.set $arr$ [| $coords$ |] $newval$ >> + | _ -> None ]; + value mk_anti ?(c = "") n s = "\\$"^n^c^":"^s; + (*FIXME*) + + value conc_seq e1 e2 = + match (e1, e2) with + [ (<:expr@_loc< do { $e1$ } >>, <:expr< do { $e2$ } >>) -> + <:expr< do { $e1$; $e2$ } >> + | (<:expr@_loc< do { $e1$ } >>, _) -> + <:expr< do { $e1$; $e2$ } >> + | (_, <:expr@_loc< do { $e2$ } >>) -> + <:expr< do { $e1$; $e2$ } >> + | _ -> + let _loc = + Loc.merge (Ast.loc_of_expr e1) + (Ast.loc_of_expr e2) in + <:expr< do { $e1$; $e2$ } >> ]; + + value test_constr_decl = + Gram.Entry.of_parser "test_constr_decl" + (fun strm -> + match Stream.npeek 1 strm with + [ [(UIDENT _, _)] -> + match Stream.npeek 2 strm with + [ [_; (KEYWORD ".", _)] -> raise Stream.Failure + | [_; (KEYWORD "(", _)] -> raise Stream.Failure + | [_ :: _] -> () + | _ -> raise Stream.Failure ] + | [(KEYWORD "|", _)] -> () + | _ -> raise Stream.Failure ]) + ; + + value stream_peek_nth n strm = + loop n (Stream.npeek n strm) where rec loop n = + fun + [ [] -> None + | [(x, _)] -> if n == 1 then Some x else None + | [_ :: l] -> loop (n - 1) l ] + ; + + (* horrible hacks to be able to parse class_types *) + + value test_ctyp_minusgreater = + Gram.Entry.of_parser "test_ctyp_minusgreater" + (fun strm -> + let rec skip_simple_ctyp n = + match stream_peek_nth n strm with + [ Some (KEYWORD "->") -> n + | Some (KEYWORD ("[" | "[<")) -> + skip_simple_ctyp (ignore_upto "]" (n + 1) + 1) + | Some (KEYWORD "(") -> skip_simple_ctyp (ignore_upto ")" (n + 1) + 1) + | Some + (KEYWORD + ("as" | "'" | ":" | "*" | "." | "#" | "<" | ">" | ".." | ";" | + "_" | "?")) -> + skip_simple_ctyp (n + 1) + | Some (LIDENT _ | UIDENT _) -> + skip_simple_ctyp (n + 1) + | Some _ | None -> raise Stream.Failure ] + and ignore_upto end_kwd n = + match stream_peek_nth n strm with + [ Some (KEYWORD prm) when prm = end_kwd -> n + | Some (KEYWORD ("[" | "[<")) -> + ignore_upto end_kwd (ignore_upto "]" (n + 1) + 1) + | Some (KEYWORD "(") -> ignore_upto end_kwd (ignore_upto ")" (n + 1) + 1) + | Some _ -> ignore_upto end_kwd (n + 1) + | None -> raise Stream.Failure ] + in + match Stream.peek strm with + [ Some ((KEYWORD "[" | LIDENT _ | UIDENT _), _) -> skip_simple_ctyp 1 + | Some (KEYWORD "object", _) -> raise Stream.Failure + | _ -> 1 ]) + ; + + value test_label_eq = + Gram.Entry.of_parser "test_label_eq" + (test 1 where rec test lev strm = + match stream_peek_nth lev strm with + [ Some (UIDENT _ | LIDENT _ | KEYWORD ".") -> + test (lev + 1) strm + | Some (KEYWORD "=") -> () + | _ -> raise Stream.Failure ]) + ; + + value test_typevar_list_dot = + Gram.Entry.of_parser "test_typevar_list_dot" + (let rec test lev strm = + match stream_peek_nth lev strm with + [ Some (KEYWORD "'") -> test2 (lev + 1) strm + | Some (KEYWORD ".") -> () + | _ -> raise Stream.Failure ] + and test2 lev strm = + match stream_peek_nth lev strm with + [ Some (UIDENT _ | LIDENT _) -> test (lev + 1) strm + | _ -> raise Stream.Failure ] + in + test 1) + ; + + value lident_colon = + Gram.Entry.of_parser "lident_colon" + (fun strm -> + match Stream.npeek 2 strm with + [ [(LIDENT i, _); (KEYWORD ":", _)] -> + do { Stream.junk strm; Stream.junk strm; i } + | _ -> raise Stream.Failure ]) + ; + + value rec is_ident_constr_call = + fun + [ <:ident< $uid:_$ >> -> True + | <:ident< $_$.$i$ >> -> is_ident_constr_call i + | _ -> False ]; + + value rec is_expr_constr_call = + fun + [ <:expr< $id:i$ >> -> is_ident_constr_call i + | <:expr< `$_$ >> -> True + | <:expr< $_$.$e$ >> -> is_expr_constr_call e + | <:expr@_loc< $e$ $_$ >> -> + let res = is_expr_constr_call e in + if (not Camlp4_config.constructors_arity.val) && res then + Loc.raise _loc (Stream.Error "currified constructor") + else res + | _ -> False ]; + + DELETE_RULE Gram expr: SELF; "where"; opt_rec; let_binding END; + DELETE_RULE Gram value_let: "value" END; + DELETE_RULE Gram value_val: "value" END; + DELETE_RULE Gram str_item: value_let; opt_rec; binding END; + DELETE_RULE Gram module_type: "'"; a_ident END; + DELETE_RULE Gram module_type: SELF; SELF; dummy END; + DELETE_RULE Gram module_type: SELF; "."; SELF END; + DELETE_RULE Gram label_expr: label_longident; fun_binding END; + DELETE_RULE Gram meth_list: meth_decl; opt_dot_dot END; + DELETE_RULE Gram expr: "let"; opt_rec; binding; "in"; SELF END; + DELETE_RULE Gram expr: "let"; "module"; a_UIDENT; module_binding0; "in"; SELF END; + DELETE_RULE Gram expr: "fun"; "["; LIST0 match_case0 SEP "|"; "]" END; + DELETE_RULE Gram expr: "if"; SELF; "then"; SELF; "else"; SELF END; + DELETE_RULE Gram expr: "do"; do_sequence END; + DELETE_RULE Gram expr: SELF; SELF END; + DELETE_RULE Gram expr: "new"; class_longident END; + DELETE_RULE Gram expr: "["; sem_expr_for_list; "::"; expr; "]" END; + DELETE_RULE Gram expr: "{"; label_expr_list; "}" END; + DELETE_RULE Gram expr: "{"; "("; SELF; ")"; "with"; label_expr_list; "}" END; + DELETE_RULE Gram expr: "("; SELF; ","; comma_expr; ")" END; + DELETE_RULE Gram expr: SELF; ":="; SELF; dummy END; + DELETE_RULE Gram expr: "~"; a_LIDENT; ":"; SELF END; + DELETE_RULE Gram expr: "?"; a_LIDENT; ":"; SELF END; + (* Some other DELETE_RULE are after the grammar *) + + value clear = Gram.Entry.clear; + clear ctyp; + clear patt; + clear a_UIDENT; + clear type_longident_and_parameters; + clear type_parameters; + clear ipatt; + clear labeled_ipatt; + clear semi; + clear do_sequence; + clear type_kind; + clear constructor_arg_list; + clear poly_type; + clear class_name_and_param; + clear class_longident_and_param; + clear class_type_longident_and_param; + clear class_type_plus; + clear type_constraint; + clear comma_patt; + clear sequence; + clear sem_expr_for_list; + clear sem_expr; + clear label_declaration; + clear star_ctyp; + clear match_case; + clear with_constr; + clear top_phrase; + + EXTEND Gram + GLOBAL: + a_CHAR a_FLOAT a_INT a_INT32 a_INT64 a_LABEL a_LIDENT + a_NATIVEINT a_OPTLABEL a_STRING a_UIDENT a_ident + amp_ctyp and_ctyp match_case match_case0 match_case_quot binding binding_quot + class_declaration class_description class_expr class_expr_quot + class_fun_binding class_fun_def class_info_for_class_expr + class_info_for_class_type class_longident class_longident_and_param + class_name_and_param class_sig_item class_sig_item_quot class_signature + class_str_item class_str_item_quot class_structure class_type + class_type_declaration class_type_longident + class_type_longident_and_param class_type_plus class_type_quot + comma_ctyp comma_expr comma_ipatt comma_patt comma_type_parameter + constrain constructor_arg_list constructor_declaration + constructor_declarations ctyp ctyp_quot cvalue_binding direction_flag + dummy eq_expr expr expr_eoi expr_quot fun_binding + fun_def ident ident_quot implem interf ipatt ipatt_tcon label + label_declaration label_declaration_list label_expr label_expr_list + label_longident label_patt_list meth_list + labeled_ipatt let_binding module_binding module_binding0 + module_binding_quot module_declaration module_expr module_expr_quot + module_longident module_longident_with_app module_rec_declaration + module_type module_type_quot more_ctyp name_tags opt_as_lident + opt_class_self_patt opt_class_self_type + opt_comma_ctyp opt_dot_dot opt_eq_ctyp opt_expr + opt_meth_list opt_mutable opt_polyt opt_private opt_rec + opt_virtual opt_when_expr patt patt_as_patt_opt patt_eoi + patt_quot patt_tcon phrase poly_type row_field + sem_expr sem_expr_for_list sem_patt sem_patt_for_list semi sequence + sig_item sig_item_quot sig_items star_ctyp str_item str_item_quot + str_items top_phrase type_constraint type_declaration + type_ident_and_parameters type_kind type_longident + type_longident_and_parameters type_parameter type_parameters typevars + use_file val_longident value_let value_val with_constr with_constr_quot + infixop0 infixop1 infixop2 infixop3 infixop4 do_sequence + ; + sem_expr: + [ [ e1 = expr LEVEL "top"; ";"; e2 = SELF -> <:expr< $e1$; $e2$ >> + | e = expr LEVEL "top"; ";" -> e + | e = expr LEVEL "top" -> e ] ] + ; + sequence: + [ [ e = sem_expr -> e ] ] + ; + do_sequence: + [ [ seq = sequence; "done" -> seq + ] ] + ; + sem_expr_for_list: + [ [ e = expr LEVEL "top"; ";"; el = SELF -> fun acc -> <:expr< [ $e$ :: $el acc$ ] >> + | e = expr LEVEL "top"; ";" -> fun acc -> <:expr< [ $e$ :: $acc$ ] >> + | e = expr LEVEL "top" -> fun acc -> <:expr< [ $e$ :: $acc$ ] >> + ] ] + ; + str_item: + [ "top" + [ "let"; r = opt_rec; bi = binding; "in"; x = expr -> + <:str_item< let $rec:r$ $bi$ in $x$ >> + | "let"; r = opt_rec; bi = binding -> + match bi with + [ <:binding< _ = $e$ >> -> <:str_item< $exp:e$ >> + | _ -> <:str_item< value $rec:r$ $bi$ >> ] + | "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; e = expr -> + <:str_item< let module $m$ = $mb$ in $e$ >> + ] ] + ; + seq_expr: + [ [ e1 = expr LEVEL "top"; ";"; e2 = SELF -> + conc_seq e1 e2 + | e1 = expr LEVEL "top"; ";" -> e1 + | e1 = expr LEVEL "top" -> e1 ] ]; + expr: BEFORE "top" + [ ";" [ e = seq_expr -> e ] ]; + expr: LEVEL "top" + [ [ "let"; r = opt_rec; bi = binding; "in"; + x = expr LEVEL ";" -> + <:expr< let $rec:r$ $bi$ in $x$ >> + | "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; + e = expr LEVEL ";" -> + <:expr< let module $m$ = $mb$ in $e$ >> + | "function"; a = match_case -> + <:expr< fun [ $a$ ] >> + | "if"; e1 = SELF; "then"; e2 = expr LEVEL "top"; + "else"; e3 = expr LEVEL "top" -> + <:expr< if $e1$ then $e2$ else $e3$ >> + | "if"; e1 = SELF; "then"; e2 = expr LEVEL "top" -> + <:expr< if $e1$ then $e2$ else () >> + ] ]; + expr: BEFORE "||" + [ "," + [ e1 = SELF; ","; e2 = comma_expr -> + <:expr< ( $e1$, $e2$ ) >> ] + | ":=" NONA + [ e1 = SELF; ":="; e2 = expr LEVEL "top" -> + <:expr< $e1$.val := $e2$ >> + | e1 = SELF; "<-"; e2 = expr LEVEL "top" -> + match bigarray_set _loc e1 e2 with + [ Some e -> e + | None -> <:expr< $e1$ := $e2$ >> ] + ] ]; + expr: AFTER "^" + [ "::" RIGHTA + [ e1 = SELF; "::"; e2 = SELF -> <:expr< [$e1$ :: $e2$] >> ] + ]; + expr: LEVEL "apply" (* LEFTA *) + [ [ e1 = SELF; e2 = SELF -> + match (is_expr_constr_call e1, e2) with + [ (True, <:expr< ( $tup:e$ ) >>) -> + List.fold_left (fun e1 e2 -> <:expr< $e1$ $e2$ >>) e1 + (Ast.list_of_expr e []) + | _ -> <:expr< $e1$ $e2$ >> ] + ] ]; + expr: LEVEL "simple" (* LEFTA *) + [ [ "false" -> <:expr< False >> + | "true" -> <:expr< True >> + | "{"; test_label_eq; lel = label_expr_list; "}" -> + <:expr< { $lel$ } >> + | "{"; e = expr LEVEL "."; "with"; lel = label_expr_list; "}" -> + <:expr< { ($e$) with $lel$ } >> + | "new"; i = class_longident -> <:expr< new $i$ >> + ] ] + ; + val_longident: + [ [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> + | i = a_LIDENT -> <:ident< $lid:i$ >> + | `ANTIQUOT (""|"id"|"anti"|"list" as n) s; "."; i = SELF -> + <:ident< $anti:mk_anti ~c:"ident" n s$.$i$ >> + | i = a_UIDENT; "."; j = SELF -> <:ident< $uid:i$.$j$ >> ] ] + ; + match_case: + [ [ OPT "|"; l = LIST1 match_case0 SEP "|" -> Ast.mcOr_of_list l ] ] + ; + patt_constr: + [ [ i = module_longident -> <:patt< $id:i$ >> + | "`"; s = a_ident -> <:patt< `$s$ >> ] ] + ; + (* Patterns *) + patt: + [ "as" LEFTA + [ p1 = SELF; "as"; i = a_LIDENT -> <:patt< ($p1$ as $lid:i$) >> ] + | "|" LEFTA + [ p1 = SELF; "|"; p2 = SELF -> <:patt< $p1$ | $p2$ >> ] + | "," + [ p = SELF; ","; pl = (*FIXME comma_patt*) LIST1 NEXT SEP "," -> + <:patt< ( $p$, $Ast.paCom_of_list pl$ ) >> ] + | "::" RIGHTA + [ p1 = SELF; "::"; p2 = SELF -> <:patt< [$p1$ :: $p2$] >> ] + | "apply" RIGHTA + [ p1 = patt_constr; p2 = SELF -> + match p2 with + [ <:patt< ( $tup:p$ ) >> -> + List.fold_left (fun p1 p2 -> <:patt< $p1$ $p2$ >>) p1 + (Ast.list_of_patt p []) + | _ -> <:patt< $p1$ $p2$ >> ] + | "lazy"; p = SELF -> <:patt< lazy $p$ >> + | `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | p = patt_constr -> p ] + | "simple" + [ `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | `ANTIQUOT ("tup" as n) s -> <:patt< ($tup:<:patt< $anti:mk_anti ~c:"patt" n s$ >>$) >> + | `ANTIQUOT ("`bool" as n) s -> <:patt< $anti:mk_anti n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag + | i = ident -> <:patt< $id:i$ >> + | s = a_INT -> <:patt< $int:s$ >> + | s = a_INT32 -> <:patt< $int32:s$ >> + | s = a_INT64 -> <:patt< $int64:s$ >> + | s = a_NATIVEINT -> <:patt< $nativeint:s$ >> + | "-"; s = a_INT -> <:patt< $int:"-" ^ s$ >> + | "-"; s = a_INT32 -> <:patt< $int32:"-" ^ s$ >> + | "-"; s = a_INT64 -> <:patt< $int64:"-" ^ s$ >> + | "-"; s = a_NATIVEINT -> <:patt< $nativeint:"-" ^ s$ >> + | "-"; s = a_FLOAT -> <:patt< $flo:"-" ^ s$ >> + | s = a_FLOAT -> <:patt< $flo:s$ >> + | s = a_STRING -> <:patt< $str:s$ >> + | s1 = a_CHAR; ".."; s2 = a_CHAR -> <:patt< $chr:s1$ .. $chr:s2$ >> + | s = a_CHAR -> <:patt< $chr:s$ >> + | "false" -> <:patt< False >> + | "true" -> <:patt< True >> + | "["; "]" -> <:patt< [] >> + | "["; mk_list = sem_patt_for_list; "::"; last = patt; "]" -> + mk_list last + | "["; mk_list = sem_patt_for_list; "]" -> + mk_list <:patt< [] >> + | "[|"; "|]" -> <:patt< [||] >> + | "[|"; pl = sem_patt; "|]" -> <:patt< [| $pl$ |] >> + | "{"; pl = label_patt_list; "}" -> <:patt< { $pl$ } >> + | "("; ")" -> <:patt< () >> + | "("; p = patt; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> + | "("; p = patt; ")" -> <:patt< $p$ >> + | "_" -> <:patt< _ >> + | "`"; s = a_ident -> <:patt< ` $s$ >> + | "#"; i = type_longident -> <:patt< # $i$ >> ] ] + ; + comma_expr: + [ [ e1 = expr LEVEL ":="; ","; e2 = SELF -> <:expr< $e1$, $e2$ >> + | e1 = expr LEVEL ":=" -> e1 ] ] + ; + (* comma_patt: + [ [ p1 = SELF; ","; p2 = SELF -> <:patt< $p1$, $p2$ >> + | p = patt LEVEL ".." -> p ] ] + ; *) + type_constraint: + [ [ "constraint" -> () ] ] + ; + with_constr: + [ LEFTA + [ wc1 = SELF; "and"; wc2 = SELF -> <:with_constr< $wc1$ and $wc2$ >> + | `ANTIQUOT (""|"with_constr"|"anti"|"list" as n) s -> + <:with_constr< $anti:mk_anti ~c:"with_constr" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.with_constr_tag + | "type"; `ANTIQUOT (""|"typ"|"anti" as n) s; "="; t = opt_private_ctyp -> + <:with_constr< type $anti:mk_anti ~c:"ctyp" n s$ = $t$ >> + | "type"; t1 = type_longident_and_parameters; "="; t2 = opt_private_ctyp -> + <:with_constr< type $t1$ = $t2$ >> + | "module"; i1 = module_longident; "="; i2 = module_longident_with_app -> + <:with_constr< module $i1$ = $i2$ >> ] ] + ; + opt_private_ctyp: + [ [ "private"; t = ctyp -> <:ctyp< private $t$ >> + | t = ctyp -> t ] ] + ; + class_type_plus: + [ [ i = lident_colon; t = ctyp LEVEL "star"; "->"; ct = SELF -> + <:class_type< [ ~ $i$ : $t$ ] -> $ct$ >> + | "?"; i = a_LIDENT; ":"; t = ctyp LEVEL "star"; "->"; ct = SELF -> + <:class_type< [ ? $i$ : $t$ ] -> $ct$ >> + | i = OPTLABEL (* FIXME inline a_OPTLABEL *); t = ctyp LEVEL "star"; "->"; ct = SELF -> + <:class_type< [ ? $i$ : $t$ ] -> $ct$ >> + | test_ctyp_minusgreater; t = ctyp LEVEL "star"; "->"; ct = SELF -> + <:class_type< [ $t$ ] -> $ct$ >> + | ct = class_type -> ct ] ] + ; + class_type_longident_and_param: + [ [ "["; t = comma_ctyp; "]"; i = class_type_longident -> + <:class_type< $id:i$ [ $t$ ] >> + | i = class_type_longident -> <:class_type< $id:i$ >> ] ] + ; + class_longident_and_param: + [ [ "["; t = comma_ctyp; "]"; ci = class_longident -> + <:class_expr< $id:ci$ [ $t$ ] >> + | ci = class_longident -> <:class_expr< $id:ci$ >> + ] ] + ; + class_name_and_param: + [ [ "["; x = comma_type_parameter; "]"; i = a_LIDENT -> (i, x) + | i = a_LIDENT -> (i, <:ctyp<>>) + ] ] + ; + ctyp: + [ [ t1 = SELF; "as"; "'"; i = a_ident -> <:ctyp< $t1$ as '$i$ >> ] + | "arrow" RIGHTA + [ t1 = SELF; "->"; t2 = SELF -> <:ctyp< $t1$ -> $t2$ >> + | i = lident_colon; t1 = ctyp LEVEL "star"; "->"; t2 = SELF -> + <:ctyp< ( ~ $i$ : $t1$ ) -> $t2$ >> + | i = a_OPTLABEL; t1 = ctyp LEVEL "star"; "->"; t2 = SELF -> + <:ctyp< ( ? $i$ : $t1$ ) -> $t2$ >> + | "?"; i = a_LIDENT; ":"; t1 = ctyp LEVEL "star"; "->"; t2 = SELF -> + <:ctyp< ( ? $i$ : $t1$ ) -> $t2$ >> ] + | "star" + [ t = SELF; "*"; tl = star_ctyp -> + <:ctyp< ( $t$ * $tl$ ) >> ] + | "ctyp1" + [ t1 = SELF; t2 = SELF -> <:ctyp< $t2$ $t1$ >> ] + | "ctyp2" + [ t1 = SELF; "."; t2 = SELF -> + try <:ctyp< $id:Ast.ident_of_ctyp t1$.$id:Ast.ident_of_ctyp t2$ >> + with [ Invalid_argument s -> raise (Stream.Error s) ] + | t1 = SELF; "("; t2 = SELF; ")" -> + let t = <:ctyp< $t1$ $t2$ >> in + try <:ctyp< $id:Ast.ident_of_ctyp t$ >> + with [ Invalid_argument s -> raise (Stream.Error s) ] ] + | "simple" + [ "'"; i = a_ident -> <:ctyp< '$i$ >> + | "_" -> <:ctyp< _ >> + | i = a_LIDENT -> <:ctyp< $lid:i$ >> + | i = a_UIDENT -> <:ctyp< $uid:i$ >> + | `ANTIQUOT (""|"typ"|"anti" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("tup" as n) s -> + <:ctyp< ($tup:<:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >>$) >> + | `ANTIQUOT ("id" as n) s -> + <:ctyp< $id:<:ident< $anti:mk_anti ~c:"ident" n s$ >>$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | "("; t = SELF; ","; mk = comma_ctyp_app; ")"; + i = ctyp LEVEL "ctyp2" -> + mk <:ctyp< $i$ $t$ >> + | "("; t = SELF; ")" -> <:ctyp< $t$ >> + | "#"; i = class_longident -> <:ctyp< # $i$ >> + | "<"; t = opt_meth_list; ">" -> t + | "["; OPT "|"; rfl = row_field; "]" -> + <:ctyp< [ = $rfl$ ] >> + | "["; ">"; "]" -> <:ctyp< [ > $<:ctyp<>>$ ] >> + | "["; ">"; OPT "|"; rfl = row_field; "]" -> + <:ctyp< [ > $rfl$ ] >> + | "[<"; OPT "|"; rfl = row_field; "]" -> + <:ctyp< [ < $rfl$ ] >> + | "[<"; OPT "|"; rfl = row_field; ">"; ntl = name_tags; "]" -> + <:ctyp< [ < $rfl$ > $ntl$ ] >> + ] ] + ; + meth_list: + [ [ m = meth_decl -> (m, Ast.BFalse) ] ]; + comma_ctyp_app: + [ [ t1 = ctyp; ","; t2 = SELF -> fun acc -> t2 <:ctyp< $acc$ $t1$ >> + | t = ctyp -> fun acc -> <:ctyp< $acc$ $t$ >> + ] ] + ; + star_ctyp: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp*" n s$ >> + | t1 = ctyp LEVEL "ctyp1"; "*"; t2 = SELF -> + <:ctyp< $t1$ * $t2$ >> + | t = ctyp LEVEL "ctyp1" -> t + ] ] + ; + semi: + [ [ ";;" -> () | -> () ] ] + ; + ipatt: + [ [ p = patt -> p ] ] + ; + type_longident_and_parameters: + [ [ "("; tpl = type_parameters; ")"; i = type_longident -> + tpl <:ctyp< $id:i$ >> + | tp = type_parameter; i = type_longident -> + <:ctyp< $id:i$ $tp$ >> + | i = type_longident -> + <:ctyp< $id:i$ >> + ] ] + ; + type_parameters: + [ [ t1 = type_parameter; ","; t2 = SELF -> + fun acc -> t2 <:ctyp< $acc$ $t1$ >> + | t = type_parameter -> fun acc -> <:ctyp< $acc$ $t$ >> + ] ] + ; + type_ident_and_parameters: + [ [ "("; tpl = LIST1 type_parameter SEP ","; ")"; i = a_LIDENT -> (i, tpl) + | t = type_parameter; i = a_LIDENT -> (i, [t]) + | i = a_LIDENT -> (i, []) + ] ] + ; + type_kind: + [ [ "private"; tk = type_kind -> <:ctyp< private $tk$ >> + | test_constr_decl; OPT "|"; + t = constructor_declarations -> <:ctyp< [ $t$ ] >> + | t = ctyp -> <:ctyp< $t$ >> + | t = ctyp; "="; "private"; tk = type_kind -> + <:ctyp< $t$ == private $tk$ >> + | t1 = ctyp; "="; "{"; t2 = label_declaration_list; "}" -> + <:ctyp< $t1$ == { $t2$ } >> + | t1 = ctyp; "="; OPT "|"; t2 = constructor_declarations -> + <:ctyp< $t1$ == [ $t2$ ] >> + | "{"; t = label_declaration_list; "}" -> + <:ctyp< { $t$ } >> ] ] + ; + module_expr: LEVEL "apply" + [ [ i = SELF; "("; j = SELF; ")" -> <:module_expr< $i$ $j$ >> ] ] + ; + ident_quot: LEVEL "apply" + [ [ i = SELF; "("; j = SELF; ")" -> <:ident< $i$ $j$ >> ] ] + ; + module_longident_with_app: LEVEL "apply" + [ [ i = SELF; "("; j = SELF; ")" -> <:ident< $i$ $j$ >> ] ] + ; + type_longident: LEVEL "apply" + [ [ i = SELF; "("; j = SELF; ")" -> <:ident< $i$ $j$ >> ] ] + ; + constructor_arg_list: + [ [ t1 = SELF; "*"; t2 = SELF -> <:ctyp< $t1$ and $t2$ >> + | t = ctyp LEVEL "ctyp1" -> t + ] ] + ; + value_let: + [ [ "let" -> () ] ] + ; + value_val: + [ [ "val" -> () ] ] + ; + label_declaration: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | s = a_LIDENT; ":"; t = poly_type -> <:ctyp< $lid:s$ : $t$ >> + | "mutable"; s = a_LIDENT; ":"; t = poly_type -> + <:ctyp< $lid:s$ : mutable $t$ >> + ] ] + ; + poly_type: + [ [ test_typevar_list_dot; t1 = typevars; "."; t2 = ctyp -> + <:ctyp< ! $t1$ . $t2$ >> + | t = ctyp -> t ] ] + ; + labeled_ipatt: + [ [ i = a_LABEL; p = patt LEVEL "simple" -> + <:patt< ~ $i$ : $p$ >> + | "~"; i = a_LIDENT -> <:patt< ~ $i$ >> + | "~"; "("; i = a_LIDENT; ")" -> + <:patt< ~ $i$ >> + | "~"; "("; i = a_LIDENT; ":"; t = ctyp; ")" -> + <:patt< ~ $i$ : ($lid:i$ : $t$) >> + | i = a_OPTLABEL; j = a_LIDENT -> (* ?a:b <> ?a : b *) + <:patt< ? $i$ : ($lid:j$) >> + | i = a_OPTLABEL; "("; p = patt; ")" -> + <:patt< ? $i$ : ($p$) >> + | i = a_OPTLABEL; "("; p = patt; "="; e = expr; ")" -> + <:patt< ? $i$ : ( $p$ = $e$ ) >> + | i = a_OPTLABEL; "("; p = patt; ":"; t = ctyp; ")" -> + <:patt< ? $i$ : ( $p$ : $t$ ) >> + | i = a_OPTLABEL; "("; p = patt; ":"; t = ctyp; "="; + e = expr; ")" -> + <:patt< ? $i$ : ( $p$ : $t$ = $e$ ) >> + | "?"; i = a_LIDENT -> <:patt< ? $i$ >> + | "?"; "("; i = a_LIDENT; "="; e = expr; ")" -> + <:patt< ? ( $lid:i$ = $e$ ) >> + | "?"; "("; i = a_LIDENT; ":"; t = ctyp; "="; e = expr; ")" -> + <:patt< ? ( $lid:i$ : $t$ = $e$ ) >> + | "?"; "("; i = a_LIDENT; ")" -> + <:patt< ? $i$ >> + | "?"; "("; i = a_LIDENT; ":"; t = ctyp; ")" -> + <:patt< ? ( $lid:i$ : $t$ ) >> + | p = patt LEVEL "simple" -> p + ] ] + ; + label_expr: + [ [ i = label_longident; "="; e = expr LEVEL "top" -> + <:rec_binding< $i$ = $e$ >> ] ] + ; + a_UIDENT: + [ [ `ANTIQUOT (""|"uid" as n) s -> mk_anti n s + | `UIDENT "True" -> " True" + | `UIDENT "False" -> " False" + | `UIDENT s -> s + ] ] + ; + top_phrase: + [ [ "#"; n = a_LIDENT; dp = opt_expr; ";;" -> + Some <:str_item< # $n$ $dp$ >> + | l = LIST1 str_item; ";;" -> Some (Ast.stSem_of_list l) + | `EOI -> None + ] ] + ; + END; + + (* Some other DELETE_RULE are before the grammar *) + DELETE_RULE Gram module_longident_with_app: "("; SELF; ")" END; + DELETE_RULE Gram type_longident: "("; SELF; ")" END; + DELETE_RULE Gram ident_quot: "("; SELF; ")" END; + DELETE_RULE Gram module_longident_with_app: SELF; SELF END; + DELETE_RULE Gram type_longident: SELF; SELF END; + DELETE_RULE Gram ident_quot: SELF; SELF END; + DELETE_RULE Gram module_expr: SELF; SELF END; +end; +let module M = Register.OCamlSyntaxExtension Id Make in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlParserParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlParserParser.ml new file mode 100644 index 0000000..94a2bdb --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlParserParser.ml @@ -0,0 +1,60 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 1998-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + +open Camlp4; + +module Id : Sig.Id = struct + value name = "Camlp4OCamlParserParser"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + module M = Camlp4OCamlRevisedParserParser.Make Syntax; + open M; + + Gram.Entry.clear stream_expr; + Gram.Entry.clear stream_begin; + Gram.Entry.clear stream_end; + Gram.Entry.clear stream_quot; + Gram.Entry.clear parser_case_list; + + EXTEND Gram + stream_expr: + [ [ e = expr LEVEL "top" -> e ] ] + ; + stream_begin: + [ [ "[<" -> () ] ] + ; + stream_end: + [ [ ">]" -> () ] ] + ; + stream_quot: + [ [ "'" -> () ] ] + ; + parser_case_list: + [ [ OPT "|"; pcl = LIST1 parser_case SEP "|" -> pcl ] ] + ; + END; +end; + +let module M = Register.OCamlSyntaxExtension Id Make in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml new file mode 100644 index 0000000..e56ab36 --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml @@ -0,0 +1,94 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2007 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: Original version + *) + +module Id = struct + value name = "Camlp4Reloaded"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + Gram.Entry.clear match_case; + Gram.Entry.clear semi; + + value mkseq _loc = + fun + [ <:expr< $_$; $_$ >> as e -> <:expr< do { $e$ } >> + | e -> e ] + ; + + DELETE_RULE Gram match_case0: patt_as_patt_opt; opt_when_expr; "->"; expr END; + + value revised = + try + (DELETE_RULE Gram expr: "if"; SELF; "then"; SELF; "else"; SELF END; True) + with [ Not_found -> begin + DELETE_RULE Gram expr: "if"; SELF; "then"; expr LEVEL "top"; "else"; expr LEVEL "top" END; + DELETE_RULE Gram expr: "if"; SELF; "then"; expr LEVEL "top" END; False + end ]; + + if revised then begin + DELETE_RULE Gram expr: "fun"; "["; LIST0 match_case0 SEP "|"; "]" END; + EXTEND Gram + expr: LEVEL "top" + [ [ "function"; a = match_case -> <:expr< fun [ $a$ ] >> ] ]; + END; + DELETE_RULE Gram value_let: "value" END; + DELETE_RULE Gram value_val: "value" END; + end else begin + DELETE_RULE Gram value_let: "let" END; + DELETE_RULE Gram value_val: "val" END; + end; + + EXTEND Gram + GLOBAL: match_case match_case0 expr value_let value_val semi; + + match_case: + [ [ OPT "|"; l = LIST1 match_case0 SEP "|"; "end" -> Ast.mcOr_of_list l + | "end" -> <:match_case<>> ] ] + ; + + match_case0: + [ [ p = patt_as_patt_opt; w = opt_when_expr; "->"; e = sequence -> + <:match_case< $p$ when $w$ -> $mkseq _loc e$ >> ] ] + ; + + expr: LEVEL "top" + [ [ "if"; e1 = sequence; "then"; e2 = sequence; "else"; e3 = sequence; "end" -> + <:expr< if $mkseq _loc e1$ then $mkseq _loc e2$ else $mkseq _loc e3$ >> + | "if"; e1 = sequence; "then"; e2 = sequence; "end" -> + <:expr< if $mkseq _loc e1$ then $mkseq _loc e2$ else () >> ] ] + ; + + value_let: + [ [ "val" -> () ] ] + ; + value_val: + [ [ "val" -> () ] ] + ; + semi: + [ [ ";;" -> () | ";" -> () | -> () ] ] + ; + END; + +end; + +let module M = Register.OCamlSyntaxExtension Id Make in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml new file mode 100644 index 0000000..f3beee6 --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml @@ -0,0 +1,1786 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +module Id = struct + value name = "Camlp4OCamlRevisedParser"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + (* Camlp4_config.constructors_arity.val := True; *) + Camlp4_config.constructors_arity.val := False; + + value help_sequences () = + do { + Printf.eprintf "\ +New syntax: + (e1; e2; ... ; en) OR begin e1; e2; ... ; en end + while e do e1; e2; ... ; en done + for v = v1 to/downto v2 do e1; e2; ... ; en done +Old syntax (still supported): + do {e1; e2; ... ; en} + while e do {e1; e2; ... ; en} + for v = v1 to/downto v2 do {e1; e2; ... ; en} +Very old (no more supported) syntax: + do e1; e2; ... ; en-1; return en + while e do e1; e2; ... ; en; done + for v = v1 to/downto v2 do e1; e2; ... ; en; done + "; + flush stderr; + exit 1 + } + ; + Options.add "-help_seq" (Arg.Unit help_sequences) + "Print explanations about new sequences and exit."; + + Gram.Entry.clear a_CHAR; + Gram.Entry.clear a_FLOAT; + Gram.Entry.clear a_INT; + Gram.Entry.clear a_INT32; + Gram.Entry.clear a_INT64; + Gram.Entry.clear a_LABEL; + Gram.Entry.clear a_LIDENT; + Gram.Entry.clear a_NATIVEINT; + Gram.Entry.clear a_OPTLABEL; + Gram.Entry.clear a_STRING; + Gram.Entry.clear a_UIDENT; + Gram.Entry.clear a_ident; + Gram.Entry.clear amp_ctyp; + Gram.Entry.clear and_ctyp; + Gram.Entry.clear match_case; + Gram.Entry.clear match_case0; + Gram.Entry.clear match_case_quot; + Gram.Entry.clear binding; + Gram.Entry.clear binding_quot; + Gram.Entry.clear rec_binding_quot; + Gram.Entry.clear class_declaration; + Gram.Entry.clear class_description; + Gram.Entry.clear class_expr; + Gram.Entry.clear class_expr_quot; + Gram.Entry.clear class_fun_binding; + Gram.Entry.clear class_fun_def; + Gram.Entry.clear class_info_for_class_expr; + Gram.Entry.clear class_info_for_class_type; + Gram.Entry.clear class_longident; + Gram.Entry.clear class_longident_and_param; + Gram.Entry.clear class_name_and_param; + Gram.Entry.clear class_sig_item; + Gram.Entry.clear class_sig_item_quot; + Gram.Entry.clear class_signature; + Gram.Entry.clear class_str_item; + Gram.Entry.clear class_str_item_quot; + Gram.Entry.clear class_structure; + Gram.Entry.clear class_type; + Gram.Entry.clear class_type_declaration; + Gram.Entry.clear class_type_longident; + Gram.Entry.clear class_type_longident_and_param; + Gram.Entry.clear class_type_plus; + Gram.Entry.clear class_type_quot; + Gram.Entry.clear comma_ctyp; + Gram.Entry.clear comma_expr; + Gram.Entry.clear comma_ipatt; + Gram.Entry.clear comma_patt; + Gram.Entry.clear comma_type_parameter; + Gram.Entry.clear constrain; + Gram.Entry.clear constructor_arg_list; + Gram.Entry.clear constructor_declaration; + Gram.Entry.clear constructor_declarations; + Gram.Entry.clear ctyp; + Gram.Entry.clear ctyp_quot; + Gram.Entry.clear cvalue_binding; + Gram.Entry.clear direction_flag; + Gram.Entry.clear dummy; + Gram.Entry.clear eq_expr; + Gram.Entry.clear expr; + Gram.Entry.clear expr_eoi; + Gram.Entry.clear expr_quot; + Gram.Entry.clear field_expr; + Gram.Entry.clear field_expr_list; + Gram.Entry.clear fun_binding; + Gram.Entry.clear fun_def; + Gram.Entry.clear ident; + Gram.Entry.clear ident_quot; + Gram.Entry.clear implem; + Gram.Entry.clear interf; + Gram.Entry.clear ipatt; + Gram.Entry.clear ipatt_tcon; + Gram.Entry.clear label; + Gram.Entry.clear label_declaration; + Gram.Entry.clear label_declaration_list; + Gram.Entry.clear label_expr_list; + Gram.Entry.clear label_expr; + Gram.Entry.clear label_ipatt; + Gram.Entry.clear label_ipatt_list; + Gram.Entry.clear label_longident; + Gram.Entry.clear label_patt; + Gram.Entry.clear label_patt_list; + Gram.Entry.clear labeled_ipatt; + Gram.Entry.clear let_binding; + Gram.Entry.clear meth_list; + Gram.Entry.clear meth_decl; + Gram.Entry.clear module_binding; + Gram.Entry.clear module_binding0; + Gram.Entry.clear module_binding_quot; + Gram.Entry.clear module_declaration; + Gram.Entry.clear module_expr; + Gram.Entry.clear module_expr_quot; + Gram.Entry.clear module_longident; + Gram.Entry.clear module_longident_with_app; + Gram.Entry.clear module_rec_declaration; + Gram.Entry.clear module_type; + Gram.Entry.clear module_type_quot; + Gram.Entry.clear more_ctyp; + Gram.Entry.clear name_tags; + Gram.Entry.clear opt_as_lident; + Gram.Entry.clear opt_class_self_patt; + Gram.Entry.clear opt_class_self_type; + Gram.Entry.clear opt_comma_ctyp; + Gram.Entry.clear opt_dot_dot; + Gram.Entry.clear opt_eq_ctyp; + Gram.Entry.clear opt_expr; + Gram.Entry.clear opt_meth_list; + Gram.Entry.clear opt_mutable; + Gram.Entry.clear opt_polyt; + Gram.Entry.clear opt_private; + Gram.Entry.clear opt_rec; + Gram.Entry.clear opt_virtual; + Gram.Entry.clear opt_when_expr; + Gram.Entry.clear patt; + Gram.Entry.clear patt_as_patt_opt; + Gram.Entry.clear patt_eoi; + Gram.Entry.clear patt_quot; + Gram.Entry.clear patt_tcon; + Gram.Entry.clear phrase; + Gram.Entry.clear poly_type; + Gram.Entry.clear row_field; + Gram.Entry.clear sem_expr; + Gram.Entry.clear sem_expr_for_list; + Gram.Entry.clear sem_patt; + Gram.Entry.clear sem_patt_for_list; + Gram.Entry.clear semi; + Gram.Entry.clear sequence; + Gram.Entry.clear sig_item; + Gram.Entry.clear sig_item_quot; + Gram.Entry.clear sig_items; + Gram.Entry.clear star_ctyp; + Gram.Entry.clear str_item; + Gram.Entry.clear str_item_quot; + Gram.Entry.clear str_items; + Gram.Entry.clear top_phrase; + Gram.Entry.clear type_constraint; + Gram.Entry.clear type_declaration; + Gram.Entry.clear type_ident_and_parameters; + Gram.Entry.clear type_kind; + Gram.Entry.clear type_longident; + Gram.Entry.clear type_longident_and_parameters; + Gram.Entry.clear type_parameter; + Gram.Entry.clear type_parameters; + Gram.Entry.clear typevars; + Gram.Entry.clear use_file; + Gram.Entry.clear val_longident; + Gram.Entry.clear value_let; + Gram.Entry.clear value_val; + Gram.Entry.clear with_constr; + Gram.Entry.clear with_constr_quot; + + value neg_string n = + let len = String.length n in + if len > 0 && n.[0] = '-' then String.sub n 1 (len - 1) + else "-" ^ n + ; + + value mkumin _loc f arg = + match arg with + [ <:expr< $int:n$ >> -> <:expr< $int:neg_string n$ >> + | <:expr< $int32:n$ >> -> <:expr< $int32:neg_string n$ >> + | <:expr< $int64:n$ >> -> <:expr< $int64:neg_string n$ >> + | <:expr< $nativeint:n$ >> -> <:expr< $nativeint:neg_string n$ >> + | <:expr< $flo:n$ >> -> <:expr< $flo:neg_string n$ >> + | _ -> <:expr< $lid:"~" ^ f$ $arg$ >> ]; + + value mklistexp _loc last = + loop True where rec loop top = + fun + [ [] -> + match last with + [ Some e -> e + | None -> <:expr< [] >> ] + | [e1 :: el] -> + let _loc = + if top then _loc else Loc.merge (Ast.loc_of_expr e1) _loc + in + <:expr< [$e1$ :: $loop False el$] >> ] + ; + + value mkassert _loc = + fun + [ <:expr< False >> -> + <:expr< assert False >> (* this case takes care about + the special assert false node *) + | e -> <:expr< assert $e$ >> ] + ; + + value append_eLem el e = el @ [e]; + value mk_anti ?(c = "") n s = "\\$"^n^c^":"^s; + + value mksequence _loc = + fun + [ <:expr< $_$; $_$ >> | <:expr< $anti:_$ >> as e -> <:expr< do { $e$ } >> + | e -> e ] + ; + + value mksequence' _loc = + fun + [ <:expr< $_$; $_$ >> as e -> <:expr< do { $e$ } >> + | e -> e ] + ; + + value module_type_app mt1 mt2 = + match (mt1, mt2) with + [ (<:module_type@_loc< $id:i1$ >>, <:module_type< $id:i2$ >>) -> + <:module_type< $id:<:ident< $i1$ $i2$ >>$ >> + | _ -> raise Stream.Failure ]; + + value module_type_acc mt1 mt2 = + match (mt1, mt2) with + [ (<:module_type@_loc< $id:i1$ >>, <:module_type< $id:i2$ >>) -> + <:module_type< $id:<:ident< $i1$.$i2$ >>$ >> + | _ -> raise Stream.Failure ]; + + value bigarray_get _loc arr arg = + let coords = + match arg with + [ <:expr< ($e1$, $e2$) >> | <:expr< $e1$, $e2$ >> -> + Ast.list_of_expr e1 (Ast.list_of_expr e2 []) + | _ -> [arg] ] + in + match coords with + [ [c1] -> <:expr< Bigarray.Array1.get $arr$ $c1$ >> + | [c1; c2] -> <:expr< Bigarray.Array2.get $arr$ $c1$ $c2$ >> + | [c1; c2; c3] -> <:expr< Bigarray.Array3.get $arr$ $c1$ $c2$ $c3$ >> + (* | coords -> <:expr< Bigarray.Genarray.get $arr$ [| $list:coords$ |] >> ] *) + | coords -> + <:expr< Bigarray.Genarray.get $arr$ [| $Ast.exSem_of_list coords$ |] >> ]; + + value bigarray_set _loc var newval = + match var with + [ <:expr< Bigarray.Array1.get $arr$ $c1$ >> -> + Some <:expr< Bigarray.Array1.set $arr$ $c1$ $newval$ >> + | <:expr< Bigarray.Array2.get $arr$ $c1$ $c2$ >> -> + Some <:expr< Bigarray.Array2.set $arr$ $c1$ $c2$ $newval$ >> + | <:expr< Bigarray.Array3.get $arr$ $c1$ $c2$ $c3$ >> -> + Some <:expr< Bigarray.Array3.set $arr$ $c1$ $c2$ $c3$ $newval$ >> + | <:expr< Bigarray.Genarray.get $arr$ [| $coords$ |] >> -> + Some <:expr< Bigarray.Genarray.set $arr$ [| $coords$ |] $newval$ >> + | _ -> None ]; + + value test_not_left_brace_nor_do = + Gram.Entry.of_parser "test_not_left_brace_nor_do" + (fun strm -> + match Stream.peek strm with + [ Some(KEYWORD "{" | KEYWORD "do", _) -> raise Stream.Failure + | _ -> () ]); + + value stopped_at _loc = + Some (Loc.move_line 1 _loc) (* FIXME be more precise *); + + value symbolchar = + let list = + ['$'; '!'; '%'; '&'; '*'; '+'; '-'; '.'; '/'; ':'; '<'; '='; '>'; '?'; + '@'; '^'; '|'; '~'; '\\'] + in + let rec loop s i = + if i == String.length s then True + else if List.mem s.[i] list then loop s (i + 1) + else False + in + loop + ; + + let list = ['!'; '?'; '~'] in + let excl = ["!="; "??"] in + Gram.Entry.setup_parser prefixop + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + not (List.mem x excl) && String.length x >= 2 && + List.mem x.[0] list && symbolchar x 1 :] -> + <:expr< $lid:x$ >>) + ; + + let list_ok = ["<"; ">"; "<="; ">="; "="; "<>"; "=="; "!="; "$"] in + let list_first_char_ok = ['='; '<'; '>'; '|'; '&'; '$'; '!'] in + let excl = ["<-"; "||"; "&&"] in + Gram.Entry.setup_parser infixop0 + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + (List.mem x list_ok) || + (not (List.mem x excl) && String.length x >= 2 && + List.mem x.[0] list_first_char_ok && symbolchar x 1) :] -> + <:expr< $lid:x$ >>) + ; + + let list = ['@'; '^'] in + Gram.Entry.setup_parser infixop1 + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + String.length x >= 1 && List.mem x.[0] list && + symbolchar x 1 :] -> + <:expr< $lid:x$ >>) + ; + + let list = ['+'; '-'] in + Gram.Entry.setup_parser infixop2 + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + x <> "->" && String.length x >= 1 && List.mem x.[0] list && + symbolchar x 1 :] -> + <:expr< $lid:x$ >>) + ; + + let list = ['*'; '/'; '%'; '\\'] in + Gram.Entry.setup_parser infixop3 + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + String.length x >= 1 && List.mem x.[0] list && + (x.[0] <> '*' || String.length x < 2 || x.[1] <> '*') && + symbolchar x 1 :] -> + <:expr< $lid:x$ >>) + ; + + Gram.Entry.setup_parser infixop4 + (parser + [: `(KEYWORD x | SYMBOL x, _loc) + when + String.length x >= 2 && x.[0] == '*' && x.[1] == '*' && + symbolchar x 2 :] -> + <:expr< $lid:x$ >>) + ; + + value rec infix_kwds_filter = + parser + [ [: `((KEYWORD "(", _) as tok); xs :] -> + match xs with parser + [ [: `(KEYWORD ("mod"|"land"|"lor"|"lxor"|"lsl"|"lsr"|"asr" as i), _loc); + `(KEYWORD ")", _); xs :] -> + [: `(LIDENT i, _loc); infix_kwds_filter xs :] + | [: xs :] -> + [: `tok; infix_kwds_filter xs :] ] + | [: `x; xs :] -> [: `x; infix_kwds_filter xs :] ]; + + Token.Filter.define_filter (Gram.get_filter ()) + (fun f strm -> infix_kwds_filter (f strm)); + + (* transmit the context *) + Gram.Entry.setup_parser sem_expr begin + let symb1 = Gram.parse_tokens_after_filter expr in + let symb = + parser + [ [: `(ANTIQUOT ("list" as n) s, _loc) :] -> <:expr< $anti:mk_anti ~c:"expr;" n s$ >> + | [: a = symb1 :] -> a ] + in + let rec kont al = + parser + [ [: `(KEYWORD ";", _loc); a = symb; s :] -> kont <:expr< $al$; $a$ >> s + | [: :] -> al ] + in + parser [: a = symb; s :] -> kont a s + end; + + EXTEND Gram + GLOBAL: + a_CHAR a_FLOAT a_INT a_INT32 a_INT64 a_LABEL a_LIDENT rec_binding_quot + a_NATIVEINT a_OPTLABEL a_STRING a_UIDENT a_ident + amp_ctyp and_ctyp match_case match_case0 match_case_quot binding binding_quot + class_declaration class_description class_expr class_expr_quot + class_fun_binding class_fun_def class_info_for_class_expr + class_info_for_class_type class_longident class_longident_and_param + class_name_and_param class_sig_item class_sig_item_quot class_signature + class_str_item class_str_item_quot class_structure class_type + class_type_declaration class_type_longident + class_type_longident_and_param class_type_plus class_type_quot + comma_ctyp comma_expr comma_ipatt comma_patt comma_type_parameter + constrain constructor_arg_list constructor_declaration + constructor_declarations ctyp ctyp_quot cvalue_binding direction_flag + dummy eq_expr expr expr_eoi expr_quot field_expr field_expr_list fun_binding + fun_def ident ident_quot implem interf ipatt ipatt_tcon label + label_declaration label_declaration_list label_expr label_expr_list + label_ipatt label_ipatt_list label_longident label_patt label_patt_list + labeled_ipatt let_binding meth_list meth_decl module_binding module_binding0 + module_binding_quot module_declaration module_expr module_expr_quot + module_longident module_longident_with_app module_rec_declaration + module_type module_type_quot more_ctyp name_tags opt_as_lident + opt_class_self_patt opt_class_self_type opt_comma_ctyp opt_dot_dot opt_eq_ctyp opt_expr + opt_meth_list opt_mutable opt_polyt opt_private opt_rec + opt_virtual opt_when_expr patt patt_as_patt_opt patt_eoi + patt_quot patt_tcon phrase poly_type row_field + sem_expr sem_expr_for_list sem_patt sem_patt_for_list semi sequence + sig_item sig_item_quot sig_items star_ctyp str_item str_item_quot + str_items top_phrase type_constraint type_declaration + type_ident_and_parameters type_kind type_longident + type_longident_and_parameters type_parameter type_parameters typevars + use_file val_longident value_let value_val with_constr with_constr_quot + infixop0 infixop1 infixop2 infixop3 infixop4 do_sequence; + module_expr: + [ "top" + [ "functor"; "("; i = a_UIDENT; ":"; t = module_type; ")"; "->"; + me = SELF -> + <:module_expr< functor ( $i$ : $t$ ) -> $me$ >> + | "struct"; st = str_items; "end" -> + <:module_expr< struct $st$ end >> ] + | "apply" + [ me1 = SELF; me2 = SELF -> <:module_expr< $me1$ $me2$ >> ] + | "simple" + [ `ANTIQUOT (""|"mexp"|"anti"|"list" as n) s -> + <:module_expr< $anti:mk_anti ~c:"module_expr" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.module_expr_tag + | i = module_longident -> <:module_expr< $id:i$ >> + | "("; me = SELF; ":"; mt = module_type; ")" -> + <:module_expr< ( $me$ : $mt$ ) >> + | "("; me = SELF; ")" -> <:module_expr< $me$ >> ] ] + ; + str_item: + [ "top" + [ "exception"; t = constructor_declaration -> + <:str_item< exception $t$ >> + | "exception"; t = constructor_declaration; "="; i = type_longident -> + <:str_item< exception $t$ = $i$ >> + | "external"; i = a_LIDENT; ":"; t = ctyp; "="; sl = string_list -> + <:str_item< external $i$ : $t$ = $sl$ >> + | "include"; me = module_expr -> <:str_item< include $me$ >> + | "module"; i = a_UIDENT; mb = module_binding0 -> + <:str_item< module $i$ = $mb$ >> + | "module"; "rec"; mb = module_binding -> + <:str_item< module rec $mb$ >> + | "module"; "type"; i = a_UIDENT; "="; mt = module_type -> + <:str_item< module type $i$ = $mt$ >> + | "open"; i = module_longident -> <:str_item< open $i$ >> + | "type"; td = type_declaration -> + <:str_item< type $td$ >> + | value_let; r = opt_rec; bi = binding -> + <:str_item< value $rec:r$ $bi$ >> + | "class"; cd = class_declaration -> + <:str_item< class $cd$ >> + | "class"; "type"; ctd = class_type_declaration -> + <:str_item< class type $ctd$ >> + | `ANTIQUOT (""|"stri"|"anti"|"list" as n) s -> + <:str_item< $anti:mk_anti ~c:"str_item" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.str_item_tag + | e = expr -> <:str_item< $exp:e$ >> ] ] + ; + module_binding0: + [ RIGHTA + [ "("; m = a_UIDENT; ":"; mt = module_type; ")"; mb = SELF -> + <:module_expr< functor ( $m$ : $mt$ ) -> $mb$ >> + | ":"; mt = module_type; "="; me = module_expr -> + <:module_expr< ( $me$ : $mt$ ) >> + | "="; me = module_expr -> <:module_expr< $me$ >> ] ] + ; + module_binding: + [ LEFTA + [ b1 = SELF; "and"; b2 = SELF -> + <:module_binding< $b1$ and $b2$ >> + | `ANTIQUOT ("module_binding"|"anti"|"list" as n) s -> + <:module_binding< $anti:mk_anti ~c:"module_binding" n s$ >> + | `ANTIQUOT ("" as n) s -> + <:module_binding< $anti:mk_anti ~c:"module_binding" n s$ >> + | `ANTIQUOT ("" as n) m; ":"; mt = module_type; "="; me = module_expr -> + <:module_binding< $mk_anti n m$ : $mt$ = $me$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.module_binding_tag + | m = a_UIDENT; ":"; mt = module_type; "="; me = module_expr -> + <:module_binding< $m$ : $mt$ = $me$ >> ] ] + ; + module_type: + [ "top" + [ "functor"; "("; i = a_UIDENT; ":"; t = SELF; ")"; "->"; mt = SELF -> + <:module_type< functor ( $i$ : $t$ ) -> $mt$ >> ] + | "with" + [ mt = SELF; "with"; wc = with_constr -> + <:module_type< $mt$ with $wc$ >> ] + | "apply" + [ mt1 = SELF; mt2 = SELF; dummy -> module_type_app mt1 mt2 ] + | "." + [ mt1 = SELF; "."; mt2 = SELF -> module_type_acc mt1 mt2 ] + | "sig" + [ "sig"; sg = sig_items; "end" -> + <:module_type< sig $sg$ end >> ] + | "simple" + [ `ANTIQUOT (""|"mtyp"|"anti"|"list" as n) s -> + <:module_type< $anti:mk_anti ~c:"module_type" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.module_type_tag + | i = module_longident_with_app -> <:module_type< $id:i$ >> + | "'"; i = a_ident -> <:module_type< ' $i$ >> + | "("; mt = SELF; ")" -> <:module_type< $mt$ >> ] ] + ; + sig_item: + [ "top" + [ `ANTIQUOT (""|"sigi"|"anti"|"list" as n) s -> + <:sig_item< $anti:mk_anti ~c:"sig_item" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.sig_item_tag + | "exception"; t = constructor_declaration -> + <:sig_item< exception $t$ >> + | "external"; i = a_LIDENT; ":"; t = ctyp; "="; sl = string_list -> + <:sig_item< external $i$ : $t$ = $sl$ >> + | "include"; mt = module_type -> <:sig_item< include $mt$ >> + | "module"; i = a_UIDENT; mt = module_declaration -> + <:sig_item< module $i$ : $mt$ >> + | "module"; "rec"; mb = module_rec_declaration -> + <:sig_item< module rec $mb$ >> + | "module"; "type"; i = a_UIDENT; "="; mt = module_type -> + <:sig_item< module type $i$ = $mt$ >> + | "module"; "type"; i = a_UIDENT -> + <:sig_item< module type $i$ >> + | "open"; i = module_longident -> <:sig_item< open $i$ >> + | "type"; t = type_declaration -> + <:sig_item< type $t$ >> + | value_val; i = a_LIDENT; ":"; t = ctyp -> + <:sig_item< value $i$ : $t$ >> + | "class"; cd = class_description -> + <:sig_item< class $cd$ >> + | "class"; "type"; ctd = class_type_declaration -> + <:sig_item< class type $ctd$ >> ] ] + ; + module_declaration: + [ RIGHTA + [ ":"; mt = module_type -> <:module_type< $mt$ >> + | "("; i = a_UIDENT; ":"; t = module_type; ")"; mt = SELF -> + <:module_type< functor ( $i$ : $t$ ) -> $mt$ >> ] ] + ; + module_rec_declaration: + [ LEFTA + [ m1 = SELF; "and"; m2 = SELF -> <:module_binding< $m1$ and $m2$ >> + | `ANTIQUOT (""|"module_binding"|"anti"|"list" as n) s -> + <:module_binding< $anti:mk_anti ~c:"module_binding" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.module_binding_tag + | m = a_UIDENT; ":"; mt = module_type -> <:module_binding< $m$ : $mt$ >> + ] ] + ; + with_constr: + [ LEFTA + [ wc1 = SELF; "and"; wc2 = SELF -> <:with_constr< $wc1$ and $wc2$ >> + | `ANTIQUOT (""|"with_constr"|"anti"|"list" as n) s -> + <:with_constr< $anti:mk_anti ~c:"with_constr" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.with_constr_tag + | "type"; `ANTIQUOT (""|"typ"|"anti" as n) s; "="; t = ctyp -> + <:with_constr< type $anti:mk_anti ~c:"ctyp" n s$ = $t$ >> + | "type"; t1 = type_longident_and_parameters; "="; t2 = ctyp -> + <:with_constr< type $t1$ = $t2$ >> + | "module"; i1 = module_longident; "="; i2 = module_longident_with_app -> + <:with_constr< module $i1$ = $i2$ >> ] ] + ; + expr: + [ "top" RIGHTA + [ "let"; r = opt_rec; bi = binding; "in"; x = SELF -> + <:expr< let $rec:r$ $bi$ in $x$ >> + | "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; e = SELF -> + <:expr< let module $m$ = $mb$ in $e$ >> + | "fun"; "["; a = LIST0 match_case0 SEP "|"; "]" -> + <:expr< fun [ $list:a$ ] >> + | "fun"; e = fun_def -> e + | "match"; e = sequence; "with"; a = match_case -> + <:expr< match $mksequence' _loc e$ with [ $a$ ] >> + | "try"; e = sequence; "with"; a = match_case -> + <:expr< try $mksequence' _loc e$ with [ $a$ ] >> + | "if"; e1 = SELF; "then"; e2 = SELF; "else"; e3 = SELF -> + <:expr< if $e1$ then $e2$ else $e3$ >> + | "do"; seq = do_sequence -> mksequence _loc seq + | "for"; i = a_LIDENT; "="; e1 = sequence; df = direction_flag; + e2 = sequence; "do"; seq = do_sequence -> + <:expr< for $i$ = $mksequence' _loc e1$ $to:df$ $mksequence' _loc e2$ do { $seq$ } >> + | "while"; e = sequence; "do"; seq = do_sequence -> + <:expr< while $mksequence' _loc e$ do { $seq$ } >> + | "object"; csp = opt_class_self_patt; cst = class_structure; "end" -> + <:expr< object ($csp$) $cst$ end >> ] + | "where" + [ e = SELF; "where"; rf = opt_rec; lb = let_binding -> + <:expr< let $rec:rf$ $lb$ in $e$ >> ] + | ":=" NONA + [ e1 = SELF; ":="; e2 = SELF; dummy -> + match bigarray_set _loc e1 e2 with + [ Some e -> e + | None -> <:expr< $e1$ := $e2$ >> ] ] + | "||" RIGHTA + [ e1 = SELF; op = infixop6; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "&&" RIGHTA + [ e1 = SELF; op = infixop5; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "<" LEFTA + [ e1 = SELF; op = infixop0; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "^" RIGHTA + [ e1 = SELF; op = infixop1; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "+" LEFTA + [ e1 = SELF; op = infixop2; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "*" LEFTA + [ e1 = SELF; "land"; e2 = SELF -> <:expr< $e1$ land $e2$ >> + | e1 = SELF; "lor"; e2 = SELF -> <:expr< $e1$ lor $e2$ >> + | e1 = SELF; "lxor"; e2 = SELF -> <:expr< $e1$ lxor $e2$ >> + | e1 = SELF; "mod"; e2 = SELF -> <:expr< $e1$ mod $e2$ >> + | e1 = SELF; op = infixop3; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "**" RIGHTA + [ e1 = SELF; "asr"; e2 = SELF -> <:expr< $e1$ asr $e2$ >> + | e1 = SELF; "lsl"; e2 = SELF -> <:expr< $e1$ lsl $e2$ >> + | e1 = SELF; "lsr"; e2 = SELF -> <:expr< $e1$ lsr $e2$ >> + | e1 = SELF; op = infixop4; e2 = SELF -> <:expr< $op$ $e1$ $e2$ >> ] + | "unary minus" NONA + [ "-"; e = SELF -> mkumin _loc "-" e + | "-."; e = SELF -> mkumin _loc "-." e ] + | "apply" LEFTA + [ e1 = SELF; e2 = SELF -> <:expr< $e1$ $e2$ >> + | "assert"; e = SELF -> mkassert _loc e + | "new"; i = class_longident -> <:expr< new $i$ >> + | "lazy"; e = SELF -> <:expr< lazy $e$ >> ] + | "label" NONA + [ "~"; i = a_LIDENT; ":"; e = SELF -> <:expr< ~ $i$ : $e$ >> + | "~"; i = a_LIDENT -> <:expr< ~ $i$ >> + + (* Here it's LABEL and not tilde_label since ~a:b is different than ~a : b *) + | `LABEL i; e = SELF -> <:expr< ~ $i$ : $e$ >> + + (* Same remark for ?a:b *) + | `OPTLABEL i; e = SELF -> <:expr< ? $i$ : $e$ >> + + | "?"; i = a_LIDENT; ":"; e = SELF -> <:expr< ? $i$ : $e$ >> + | "?"; i = a_LIDENT -> <:expr< ? $i$ >> ] + | "." LEFTA + [ e1 = SELF; "."; "("; e2 = SELF; ")" -> <:expr< $e1$ .( $e2$ ) >> + | e1 = SELF; "."; "["; e2 = SELF; "]" -> <:expr< $e1$ .[ $e2$ ] >> + | e1 = SELF; "."; "{"; e2 = comma_expr; "}" -> bigarray_get _loc e1 e2 + | e1 = SELF; "."; e2 = SELF -> <:expr< $e1$ . $e2$ >> + | e = SELF; "#"; lab = label -> <:expr< $e$ # $lab$ >> ] + | "~-" NONA + [ "!"; e = SELF -> <:expr< $e$.val >> + | f = prefixop; e = SELF -> <:expr< $f$ $e$ >> ] + | "simple" + [ `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.expr_tag + | `ANTIQUOT ("exp"|""|"anti" as n) s -> + <:expr< $anti:mk_anti ~c:"expr" n s$ >> + | `ANTIQUOT ("`bool" as n) s -> + <:expr< $id:<:ident< $anti:mk_anti n s$ >>$ >> + | `ANTIQUOT ("tup" as n) s -> + <:expr< $tup: <:expr< $anti:mk_anti ~c:"expr" n s$ >>$ >> + | `ANTIQUOT ("seq" as n) s -> + <:expr< do $anti:mk_anti ~c:"expr" n s$ done >> + | s = a_INT -> <:expr< $int:s$ >> + | s = a_INT32 -> <:expr< $int32:s$ >> + | s = a_INT64 -> <:expr< $int64:s$ >> + | s = a_NATIVEINT -> <:expr< $nativeint:s$ >> + | s = a_FLOAT -> <:expr< $flo:s$ >> + | s = a_STRING -> <:expr< $str:s$ >> + | s = a_CHAR -> <:expr< $chr:s$ >> + | i = val_longident -> <:expr< $id:i$ >> + | "`"; s = a_ident -> <:expr< ` $s$ >> + | "["; "]" -> <:expr< [] >> + | "["; mk_list = sem_expr_for_list; "::"; last = expr; "]" -> + mk_list last + | "["; mk_list = sem_expr_for_list; "]" -> + mk_list <:expr< [] >> + | "[|"; "|]" -> <:expr< [| $<:expr<>>$ |] >> + | "[|"; el = sem_expr; "|]" -> <:expr< [| $el$ |] >> + | "{"; el = label_expr_list; "}" -> <:expr< { $el$ } >> + | "{"; "("; e = SELF; ")"; "with"; el = label_expr_list; "}" -> + <:expr< { ($e$) with $el$ } >> + | "{<"; ">}" -> <:expr< {<>} >> + | "{<"; fel = field_expr_list; ">}" -> <:expr< {< $fel$ >} >> + | "("; ")" -> <:expr< () >> + | "("; e = SELF; ":"; t = ctyp; ")" -> <:expr< ($e$ : $t$) >> + | "("; e = SELF; ","; el = comma_expr; ")" -> <:expr< ( $e$, $el$ ) >> + | "("; e = SELF; ";"; seq = sequence; ")" -> mksequence _loc <:expr< $e$; $seq$ >> + | "("; e = SELF; ";"; ")" -> mksequence _loc e + | "("; e = SELF; ":"; t = ctyp; ":>"; t2 = ctyp; ")" -> + <:expr< ($e$ : $t$ :> $t2$ ) >> + | "("; e = SELF; ":>"; t = ctyp; ")" -> <:expr< ($e$ :> $t$) >> + | "("; e = SELF; ")" -> e + | "begin"; seq = sequence; "end" -> mksequence _loc seq + | "begin"; "end" -> <:expr< () >> ] ] + ; + do_sequence: + [ [ "{"; seq = sequence; "}" -> seq + | test_not_left_brace_nor_do; seq = sequence; "done" -> seq + ] ] + ; + infixop5: + [ [ x = [ "&" | "&&" ] -> <:expr< $lid:x$ >> ] ] + ; + infixop6: + [ [ x = [ "or" | "||" ] -> <:expr< $lid:x$ >> ] ] + ; + sem_expr_for_list: + [ [ e = expr; ";"; el = SELF -> fun acc -> <:expr< [ $e$ :: $el acc$ ] >> + | e = expr -> fun acc -> <:expr< [ $e$ :: $acc$ ] >> + ] ] + ; + comma_expr: + [ [ e1 = SELF; ","; e2 = SELF -> <:expr< $e1$, $e2$ >> + | `ANTIQUOT ("list" as n) s -> <:expr< $anti:mk_anti ~c:"expr," n s$ >> + | e = expr LEVEL "top" -> e ] ] + ; + dummy: + [ [ -> () ] ] + ; + sequence': + [ [ -> fun e -> e + | ";" -> fun e -> e + | ";"; el = sequence -> fun e -> <:expr< $e$; $el$ >> ] ] + ; + sequence: + [ [ "let"; rf = opt_rec; bi = binding; "in"; e = expr; k = sequence' -> + k <:expr< let $rec:rf$ $bi$ in $e$ >> + | "let"; rf = opt_rec; bi = binding; ";"; el = SELF -> + <:expr< let $rec:rf$ $bi$ in $mksequence _loc el$ >> + | "let"; "module"; m = a_UIDENT; mb = module_binding0; "in"; e = expr; k = sequence' -> + k <:expr< let module $m$ = $mb$ in $e$ >> + | "let"; "module"; m = a_UIDENT; mb = module_binding0; ";"; el = SELF -> + <:expr< let module $m$ = $mb$ in $mksequence _loc el$ >> + | `ANTIQUOT ("list" as n) s -> <:expr< $anti:mk_anti ~c:"expr;" n s$ >> + | e = expr; k = sequence' -> k e ] ] + ; + binding: + [ LEFTA + [ `ANTIQUOT ("binding"|"list" as n) s -> + <:binding< $anti:mk_anti ~c:"binding" n s$ >> + | `ANTIQUOT (""|"anti" as n) s; "="; e = expr -> + <:binding< $anti:mk_anti ~c:"patt" n s$ = $e$ >> + | `ANTIQUOT (""|"anti" as n) s -> <:binding< $anti:mk_anti ~c:"binding" n s$ >> + | b1 = SELF; "and"; b2 = SELF -> <:binding< $b1$ and $b2$ >> + | b = let_binding -> b + ] ] + ; + let_binding: + [ [ p = ipatt; e = fun_binding -> <:binding< $p$ = $e$ >> ] ] + ; + fun_binding: + [ RIGHTA + [ p = labeled_ipatt; e = SELF -> + <:expr< fun $p$ -> $e$ >> + | "="; e = expr -> <:expr< $e$ >> + | ":"; t = ctyp; "="; e = expr -> <:expr< ($e$ : $t$) >> + | ":>"; t = ctyp; "="; e = expr -> <:expr< ($e$ :> $t$) >> ] ] + ; + match_case: + [ [ "["; l = LIST0 match_case0 SEP "|"; "]" -> Ast.mcOr_of_list l + | p = ipatt; "->"; e = expr -> <:match_case< $p$ -> $e$ >> ] ] + ; + match_case0: + [ [ `ANTIQUOT ("match_case"|"list" as n) s -> + <:match_case< $anti:mk_anti ~c:"match_case" n s$ >> + | `ANTIQUOT (""|"anti" as n) s -> + <:match_case< $anti:mk_anti ~c:"match_case" n s$ >> + | `ANTIQUOT (""|"anti" as n) s; "->"; e = expr -> + <:match_case< $anti:mk_anti ~c:"patt" n s$ -> $e$ >> + | `ANTIQUOT (""|"anti" as n) s; "when"; w = expr; "->"; e = expr -> + <:match_case< $anti:mk_anti ~c:"patt" n s$ when $w$ -> $e$ >> + | p = patt_as_patt_opt; w = opt_when_expr; "->"; e = expr -> <:match_case< $p$ when $w$ -> $e$ >> + ] ] + ; + opt_when_expr: + [ [ "when"; w = expr -> w + | -> <:expr<>> + ] ] + ; + patt_as_patt_opt: + [ [ p1 = patt; "as"; p2 = patt -> <:patt< ($p1$ as $p2$) >> + | p = patt -> p + ] ] + ; + label_expr_list: + [ [ b1 = label_expr; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >> + | b1 = label_expr; ";" -> b1 + | b1 = label_expr -> b1 + ] ]; + label_expr: + [ [ `ANTIQUOT ("rec_binding" as n) s -> + <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >> + | `ANTIQUOT (""|"anti" as n) s -> + <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >> + | `ANTIQUOT (""|"anti" as n) s; "="; e = expr -> + <:rec_binding< $anti:mk_anti ~c:"ident" n s$ = $e$ >> + | `ANTIQUOT ("list" as n) s -> + <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >> + | i = label_longident; e = fun_binding -> <:rec_binding< $i$ = $e$ >> ] ] + ; + fun_def: + [ [ p = labeled_ipatt; (w, e) = fun_def_cont -> + <:expr< fun [ $p$ when $w$ -> $e$ ] >> ] ] + ; + fun_def_cont: + [ RIGHTA + [ p = labeled_ipatt; (w,e) = SELF -> (<:expr<>>, <:expr< fun [ $p$ when $w$ -> $e$ ] >>) + | "when"; w = expr; "->"; e = expr -> (w, e) + | "->"; e = expr -> (<:expr<>>, e) ] ] + ; + patt: + [ "|" LEFTA + [ p1 = SELF; "|"; p2 = SELF -> <:patt< $p1$ | $p2$ >> ] + | ".." NONA + [ p1 = SELF; ".."; p2 = SELF -> <:patt< $p1$ .. $p2$ >> ] + | "apply" LEFTA + [ p1 = SELF; p2 = SELF -> <:patt< $p1$ $p2$ >> + | "lazy"; p = SELF -> <:patt< lazy $p$ >> ] + | "simple" + [ `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | `ANTIQUOT ("tup" as n) s -> <:patt< ($tup:<:patt< $anti:mk_anti ~c:"patt" n s$ >>$) >> + | `ANTIQUOT ("`bool" as n) s -> <:patt< $id:<:ident< $anti:mk_anti n s$ >>$ >> + | i = ident -> <:patt< $id:i$ >> + | s = a_INT -> <:patt< $int:s$ >> + | s = a_INT32 -> <:patt< $int32:s$ >> + | s = a_INT64 -> <:patt< $int64:s$ >> + | s = a_NATIVEINT -> <:patt< $nativeint:s$ >> + | s = a_FLOAT -> <:patt< $flo:s$ >> + | s = a_STRING -> <:patt< $str:s$ >> + | s = a_CHAR -> <:patt< $chr:s$ >> + | "-"; s = a_INT -> <:patt< $int:neg_string s$ >> + | "-"; s = a_INT32 -> <:patt< $int32:neg_string s$ >> + | "-"; s = a_INT64 -> <:patt< $int64:neg_string s$ >> + | "-"; s = a_NATIVEINT -> <:patt< $nativeint:neg_string s$ >> + | "-"; s = a_FLOAT -> <:patt< $flo:neg_string s$ >> + | "["; "]" -> <:patt< [] >> + | "["; mk_list = sem_patt_for_list; "::"; last = patt; "]" -> + mk_list last + | "["; mk_list = sem_patt_for_list; "]" -> + mk_list <:patt< [] >> + | "[|"; "|]" -> <:patt< [| $<:patt<>>$ |] >> + | "[|"; pl = sem_patt; "|]" -> <:patt< [| $pl$ |] >> + | "{"; pl = label_patt_list; "}" -> <:patt< { $pl$ } >> + | "("; ")" -> <:patt< () >> + | "("; p = SELF; ")" -> p + | "("; p = SELF; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> + | "("; p = SELF; "as"; p2 = SELF; ")" -> <:patt< ($p$ as $p2$) >> + | "("; p = SELF; ","; pl = comma_patt; ")" -> <:patt< ($p$, $pl$) >> + | "_" -> <:patt< _ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag + | "`"; s = a_ident -> <:patt< ` $s$ >> + | "#"; i = type_longident -> <:patt< # $i$ >> + | `LABEL i; p = SELF -> <:patt< ~ $i$ : $p$ >> + | "~"; `ANTIQUOT (""|"lid" as n) i; ":"; p = SELF -> + <:patt< ~ $mk_anti n i$ : $p$ >> + | "~"; `ANTIQUOT (""|"lid" as n) i -> <:patt< ~ $mk_anti n i$ >> + | "~"; `LIDENT i -> <:patt< ~ $i$ >> + (* | i = opt_label; "("; p = patt_tcon; ")" -> *) + (* <:patt< ? $i$ : ($p$) >> *) + | `OPTLABEL i; "("; p = patt_tcon; f = eq_expr; ")" -> f i p + | "?"; `ANTIQUOT (""|"lid" as n) i; ":"; "("; p = patt_tcon; f = eq_expr; ")" -> + f (mk_anti n i) p + | "?"; `LIDENT i -> <:patt< ? $i$ >> + | "?"; `ANTIQUOT (""|"lid" as n) i -> <:patt< ? $mk_anti n i$ >> + | "?"; "("; p = patt_tcon; ")" -> + <:patt< ? ($p$) >> + | "?"; "("; p = patt_tcon; "="; e = expr; ")" -> + <:patt< ? ($p$ = $e$) >> ] ] + ; + comma_patt: + [ [ p1 = SELF; ","; p2 = SELF -> <:patt< $p1$, $p2$ >> + | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt," n s$ >> + | p = patt -> p ] ] + ; + sem_patt: + [ LEFTA + [ p1 = SELF; ";"; p2 = SELF -> <:patt< $p1$; $p2$ >> + | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt;" n s$ >> + | p = patt -> p ] ] + ; + sem_patt_for_list: + [ [ p = patt; ";"; pl = SELF -> fun acc -> <:patt< [ $p$ :: $pl acc$ ] >> + | p = patt -> fun acc -> <:patt< [ $p$ :: $acc$ ] >> + ] ] + ; + label_patt_list: + [ [ p1 = label_patt; ";"; p2 = SELF -> <:patt< $p1$ ; $p2$ >> + | p1 = label_patt; ";" -> p1 + | p1 = label_patt -> p1 + ] ]; + label_patt: + [ [ `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag + | `ANTIQUOT ("list" as n) s -> + <:patt< $anti:mk_anti ~c:"patt;" n s$ >> + | i = label_longident; "="; p = patt -> <:patt< $i$ = $p$ >> + ] ] + ; + ipatt: + [ [ "{"; pl = label_ipatt_list; "}" -> <:patt< { $pl$ } >> + | `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | `ANTIQUOT ("tup" as n) s -> + <:patt< ($tup:<:patt< $anti:mk_anti ~c:"patt" n s$ >>$) >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag + | "("; ")" -> <:patt< () >> + | "("; p = SELF; ")" -> p + | "("; p = SELF; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> + | "("; p = SELF; "as"; p2 = SELF; ")" -> <:patt< ($p$ as $p2$) >> + | "("; p = SELF; ","; pl = comma_ipatt; ")" -> <:patt< ($p$, $pl$) >> + | s = a_LIDENT -> <:patt< $lid:s$ >> + | "_" -> <:patt< _ >> ] ] + ; + labeled_ipatt: + [ [ p = ipatt -> p ] ] + ; + comma_ipatt: + [ LEFTA + [ p1 = SELF; ","; p2 = SELF -> <:patt< $p1$, $p2$ >> + | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt," n s$ >> + | p = ipatt -> p ] ] + ; + label_ipatt_list: + [ [ p1 = label_ipatt; ";"; p2 = SELF -> <:patt< $p1$ ; $p2$ >> + | p1 = label_ipatt; ";" -> p1 + | p1 = label_ipatt -> p1 + ] ]; + label_ipatt: + [ [ `ANTIQUOT (""|"pat"|"anti" as n) s -> + <:patt< $anti:mk_anti ~c:"patt" n s$ >> + | `ANTIQUOT ("list" as n) s -> <:patt< $anti:mk_anti ~c:"patt;" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.patt_tag + | i = label_longident; "="; p = ipatt -> <:patt< $i$ = $p$ >> + ] ] + ; + type_declaration: + [ LEFTA + [ `ANTIQUOT (""|"typ"|"anti" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctypand" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | t1 = SELF; "and"; t2 = SELF -> <:ctyp< $t1$ and $t2$ >> + | (n, tpl) = type_ident_and_parameters; tk = opt_eq_ctyp; + cl = LIST0 constrain -> Ast.TyDcl _loc n tpl tk cl ] ] + ; + constrain: + [ [ "constraint"; t1 = ctyp; "="; t2 = ctyp -> (t1, t2) ] ] + ; + opt_eq_ctyp: + [ [ "="; tk = type_kind -> tk + | -> <:ctyp<>> ] ] + ; + type_kind: + [ [ t = ctyp -> t ] ] + ; + type_ident_and_parameters: + [ [ i = a_LIDENT; tpl = LIST0 type_parameter -> (i, tpl) ] ] + ; + type_longident_and_parameters: + [ [ i = type_longident; tpl = type_parameters -> tpl <:ctyp< $id:i$ >> + ] ] + ; + type_parameters: + [ [ t1 = type_parameter; t2 = SELF -> + fun acc -> t2 <:ctyp< $acc$ $t1$ >> + | t = type_parameter -> fun acc -> <:ctyp< $acc$ $t$ >> + | -> fun t -> t + ] ] + ; + type_parameter: + [ [ `ANTIQUOT (""|"typ"|"anti" as n) s -> <:ctyp< $anti:mk_anti n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | "'"; i = a_ident -> <:ctyp< '$lid:i$ >> + | "+"; "'"; i = a_ident -> <:ctyp< +'$lid:i$ >> + | "-"; "'"; i = a_ident -> <:ctyp< -'$lid:i$ >> ] ] + ; + ctyp: + [ "==" LEFTA + [ t1 = SELF; "=="; t2 = SELF -> <:ctyp< $t1$ == $t2$ >> ] + | "private" NONA + [ "private"; t = ctyp LEVEL "alias" -> <:ctyp< private $t$ >> ] + | "alias" LEFTA + [ t1 = SELF; "as"; t2 = SELF -> <:ctyp< $t1$ as $t2$ >> ] + | "forall" LEFTA + [ "!"; t1 = typevars; "."; t2 = ctyp -> <:ctyp< ! $t1$ . $t2$ >> ] + | "arrow" RIGHTA + [ t1 = SELF; "->"; t2 = SELF -> <:ctyp< $t1$ -> $t2$ >> ] + | "label" NONA + [ "~"; i = a_LIDENT; ":"; t = SELF -> <:ctyp< ~ $i$ : $t$ >> + | i = a_LABEL; t = SELF -> <:ctyp< ~ $i$ : $t$ >> + | "?"; i = a_LIDENT; ":"; t = SELF -> <:ctyp< ? $i$ : $t$ >> + | i = a_OPTLABEL; t = SELF -> <:ctyp< ? $i$ : $t$ >> ] + | "apply" LEFTA + [ t1 = SELF; t2 = SELF -> + let t = <:ctyp< $t1$ $t2$ >> in + try <:ctyp< $id:Ast.ident_of_ctyp t$ >> + with [ Invalid_argument _ -> t ] ] + | "." LEFTA + [ t1 = SELF; "."; t2 = SELF -> + try <:ctyp< $id:Ast.ident_of_ctyp t1$.$id:Ast.ident_of_ctyp t2$ >> + with [ Invalid_argument s -> raise (Stream.Error s) ] ] + | "simple" + [ "'"; i = a_ident -> <:ctyp< '$i$ >> + | "_" -> <:ctyp< _ >> + | `ANTIQUOT (""|"typ"|"anti" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("tup" as n) s -> + <:ctyp< ($tup:<:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >>$) >> + | `ANTIQUOT ("id" as n) s -> + <:ctyp< $id:<:ident< $anti:mk_anti ~c:"ident" n s$ >>$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | i = a_LIDENT -> <:ctyp< $lid:i$ >> + | i = a_UIDENT -> <:ctyp< $uid:i$ >> + | "("; t = SELF; "*"; tl = star_ctyp; ")" -> + <:ctyp< ( $t$ * $tl$ ) >> + | "("; t = SELF; ")" -> t + | "["; t = constructor_declarations; "]" -> <:ctyp< [ $t$ ] >> + | "["; "="; rfl = row_field; "]" -> + <:ctyp< [ = $rfl$ ] >> + | "["; ">"; "]" -> <:ctyp< [ > $<:ctyp<>>$ ] >> + | "["; ">"; rfl = row_field; "]" -> + <:ctyp< [ > $rfl$ ] >> + | "["; "<"; rfl = row_field; "]" -> + <:ctyp< [ < $rfl$ ] >> + | "["; "<"; rfl = row_field; ">"; ntl = name_tags; "]" -> + <:ctyp< [ < $rfl$ > $ntl$ ] >> + | "[<"; rfl = row_field; "]" -> + <:ctyp< [ < $rfl$ ] >> + | "[<"; rfl = row_field; ">"; ntl = name_tags; "]" -> + <:ctyp< [ < $rfl$ > $ntl$ ] >> + | "{"; t = label_declaration_list; "}" -> <:ctyp< { $t$ } >> + | "#"; i = class_longident -> <:ctyp< # $i$ >> + | "<"; t = opt_meth_list; ">" -> t + ] ] + ; + star_ctyp: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp*" n s$ >> + | t1 = SELF; "*"; t2 = SELF -> + <:ctyp< $t1$ * $t2$ >> + | t = ctyp -> t + ] ] + ; + constructor_declarations: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp|" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | t1 = SELF; "|"; t2 = SELF -> + <:ctyp< $t1$ | $t2$ >> + | s = a_UIDENT; "of"; t = constructor_arg_list -> + <:ctyp< $uid:s$ of $t$ >> + | s = a_UIDENT -> + <:ctyp< $uid:s$ >> + ] ] + ; + constructor_declaration: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | s = a_UIDENT; "of"; t = constructor_arg_list -> + <:ctyp< $uid:s$ of $t$ >> + | s = a_UIDENT -> + <:ctyp< $uid:s$ >> + ] ] + ; + constructor_arg_list: + [ [ `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctypand" n s$ >> + | t1 = SELF; "and"; t2 = SELF -> <:ctyp< $t1$ and $t2$ >> + | t = ctyp -> t + ] ] + ; + label_declaration_list: + [ [ t1 = label_declaration; ";"; t2 = SELF -> <:ctyp< $t1$; $t2$ >> + | t1 = label_declaration; ";" -> t1 + | t1 = label_declaration -> t1 + ] ] + ; + label_declaration: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp;" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | s = a_LIDENT; ":"; t = poly_type -> <:ctyp< $lid:s$ : $t$ >> + | s = a_LIDENT; ":"; "mutable"; t = poly_type -> + <:ctyp< $lid:s$ : mutable $t$ >> + ] ] + ; + a_ident: + [ [ i = a_LIDENT -> i + | i = a_UIDENT -> i ] ] + ; + ident: + [ [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> + | i = a_LIDENT -> <:ident< $lid:i$ >> + | `ANTIQUOT (""|"id"|"anti"|"list" as n) s; "."; i = SELF -> + <:ident< $anti:mk_anti ~c:"ident" n s$.$i$ >> + | i = a_UIDENT; "."; j = SELF -> <:ident< $uid:i$.$j$ >> ] ] + ; + module_longident: + [ [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | m = a_UIDENT; "."; l = SELF -> <:ident< $uid:m$.$l$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> ] ] + ; + module_longident_with_app: + [ "apply" + [ i = SELF; j = SELF -> <:ident< $i$ $j$ >> ] + | "." + [ i = SELF; "."; j = SELF -> <:ident< $i$.$j$ >> ] + | "simple" + [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> + | "("; i = SELF; ")" -> i ] ] + ; + type_longident: + [ "apply" + [ i = SELF; j = SELF -> <:ident< $i$ $j$ >> ] + | "." + [ i = SELF; "."; j = SELF -> <:ident< $i$.$j$ >> ] + | "simple" + [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | i = a_LIDENT -> <:ident< $lid:i$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> + | "("; i = SELF; ")" -> i ] ] + ; + label_longident: + [ [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | m = a_UIDENT; "."; l = SELF -> <:ident< $uid:m$.$l$ >> + | i = a_LIDENT -> <:ident< $lid:i$ >> ] ] + ; + class_type_longident: + [ [ x = type_longident -> x ] ] + ; + val_longident: + [ [ x = ident -> x ] ] + ; + class_longident: + [ [ x = label_longident -> x ] ] + ; + class_declaration: + [ LEFTA + [ c1 = SELF; "and"; c2 = SELF -> + <:class_expr< $c1$ and $c2$ >> + | `ANTIQUOT (""|"cdcl"|"anti"|"list" as n) s -> + <:class_expr< $anti:mk_anti ~c:"class_expr" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_expr_tag + | ci = class_info_for_class_expr; ce = class_fun_binding -> + <:class_expr< $ci$ = $ce$ >> + ] ] + ; + class_fun_binding: + [ [ "="; ce = class_expr -> ce + | ":"; ct = class_type_plus; "="; ce = class_expr -> + <:class_expr< ($ce$ : $ct$) >> + | p = labeled_ipatt; cfb = SELF -> + <:class_expr< fun $p$ -> $cfb$ >> + ] ] + ; + class_info_for_class_type: + [ [ mv = opt_virtual; (i, ot) = class_name_and_param -> + <:class_type< $virtual:mv$ $lid:i$ [ $ot$ ] >> + ] ] + ; + class_info_for_class_expr: + [ [ mv = opt_virtual; (i, ot) = class_name_and_param -> + <:class_expr< $virtual:mv$ $lid:i$ [ $ot$ ] >> + ] ] + ; + class_name_and_param: + [ [ i = a_LIDENT; "["; x = comma_type_parameter; "]" -> (i, x) + | i = a_LIDENT -> (i, <:ctyp<>>) + ] ] + ; + comma_type_parameter: + [ [ t1 = SELF; ","; t2 = SELF -> <:ctyp< $t1$, $t2$ >> + | `ANTIQUOT ("list" as n) s -> <:ctyp< $anti:mk_anti ~c:"ctyp," n s$ >> + | t = type_parameter -> t + ] ] + ; + opt_comma_ctyp: + [ [ "["; x = comma_ctyp; "]" -> x + | -> <:ctyp<>> + ] ] + ; + comma_ctyp: + [ [ t1 = SELF; ","; t2 = SELF -> <:ctyp< $t1$, $t2$ >> + | `ANTIQUOT ("list" as n) s -> <:ctyp< $anti:mk_anti ~c:"ctyp," n s$ >> + | t = ctyp -> t + ] ] + ; + class_fun_def: + [ [ p = labeled_ipatt; ce = SELF -> <:class_expr< fun $p$ -> $ce$ >> + | "->"; ce = class_expr -> ce ] ] + ; + class_expr: + [ "top" + [ "fun"; p = labeled_ipatt; ce = class_fun_def -> + <:class_expr< fun $p$ -> $ce$ >> + | "let"; rf = opt_rec; bi = binding; "in"; ce = SELF -> + <:class_expr< let $rec:rf$ $bi$ in $ce$ >> ] + | "apply" NONA + [ ce = SELF; e = expr LEVEL "label" -> + <:class_expr< $ce$ $e$ >> ] + | "simple" + [ `ANTIQUOT (""|"cexp"|"anti" as n) s -> + <:class_expr< $anti:mk_anti ~c:"class_expr" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_expr_tag + | ce = class_longident_and_param -> ce + | "object"; csp = opt_class_self_patt; cst = class_structure; "end" -> + <:class_expr< object ($csp$) $cst$ end >> + | "("; ce = SELF; ":"; ct = class_type; ")" -> + <:class_expr< ($ce$ : $ct$) >> + | "("; ce = SELF; ")" -> ce ] ] + ; + class_longident_and_param: + [ [ ci = class_longident; "["; t = comma_ctyp; "]" -> + <:class_expr< $id:ci$ [ $t$ ] >> + | ci = class_longident -> <:class_expr< $id:ci$ >> + ] ] + ; + class_structure: + [ [ `ANTIQUOT (""|"cst"|"anti"|"list" as n) s -> + <:class_str_item< $anti:mk_anti ~c:"class_str_item" n s$ >> + | `ANTIQUOT (""|"cst"|"anti"|"list" as n) s; semi; cst = SELF -> + <:class_str_item< $anti:mk_anti ~c:"class_str_item" n s$; $cst$ >> + | l = LIST0 [ cst = class_str_item; semi -> cst ] -> Ast.crSem_of_list l + ] ] + ; + opt_class_self_patt: + [ [ "("; p = patt; ")" -> p + | "("; p = patt; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> + | -> <:patt<>> ] ] + ; + class_str_item: + [ LEFTA + [ `ANTIQUOT (""|"cst"|"anti"|"list" as n) s -> + <:class_str_item< $anti:mk_anti ~c:"class_str_item" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_str_item_tag + | "inherit"; ce = class_expr; pb = opt_as_lident -> + <:class_str_item< inherit $ce$ as $pb$ >> + | value_val; mf = opt_mutable; lab = label; e = cvalue_binding -> + <:class_str_item< value $mutable:mf$ $lab$ = $e$ >> + | value_val; mf = opt_mutable; "virtual"; l = label; ":"; t = poly_type -> + <:class_str_item< value virtual $mutable:mf$ $l$ : $t$ >> + | value_val; "virtual"; mf = opt_mutable; l = label; ":"; t = poly_type -> + <:class_str_item< value virtual $mutable:mf$ $l$ : $t$ >> + | "method"; "virtual"; pf = opt_private; l = label; ":"; t = poly_type -> + <:class_str_item< method virtual $private:pf$ $l$ : $t$ >> + | "method"; pf = opt_private; "virtual"; l = label; ":"; t = poly_type -> + <:class_str_item< method virtual $private:pf$ $l$ : $t$ >> + | "method"; pf = opt_private; l = label; topt = opt_polyt; + e = fun_binding -> + <:class_str_item< method $private:pf$ $l$ : $topt$ = $e$ >> + | type_constraint; t1 = ctyp; "="; t2 = ctyp -> + <:class_str_item< type $t1$ = $t2$ >> + | "initializer"; se = expr -> <:class_str_item< initializer $se$ >> ] ] + ; + opt_as_lident: + [ [ "as"; i = a_LIDENT -> i + | -> "" + ] ] + ; + opt_polyt: + [ [ ":"; t = poly_type -> t + | -> <:ctyp<>> ] ] + ; + cvalue_binding: + [ [ "="; e = expr -> e + | ":"; t = ctyp; "="; e = expr -> <:expr< ($e$ : $t$) >> + | ":"; t = ctyp; ":>"; t2 = ctyp; "="; e = expr -> + <:expr< ($e$ : $t$ :> $t2$) >> + | ":>"; t = ctyp; "="; e = expr -> <:expr< ($e$ :> $t$) >> ] ] + ; + label: + [ [ i = a_LIDENT -> i ] ] + ; + class_type: + [ [ `ANTIQUOT (""|"ctyp"|"anti" as n) s -> + <:class_type< $anti:mk_anti ~c:"class_type" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_type_tag + | ct = class_type_longident_and_param -> ct + | "object"; cst = opt_class_self_type; csg = class_signature; "end" -> + <:class_type< object ($cst$) $csg$ end >> ] ] + ; + class_type_longident_and_param: + [ [ i = class_type_longident; "["; t = comma_ctyp; "]" -> + <:class_type< $id:i$ [ $t$ ] >> + | i = class_type_longident -> <:class_type< $id:i$ >> ] ] + ; + class_type_plus: + [ [ "["; t = ctyp; "]"; "->"; ct = SELF -> <:class_type< [ $t$ ] -> $ct$ >> + | ct = class_type -> ct ] ] + ; + opt_class_self_type: + [ [ "("; t = ctyp; ")" -> t + | -> <:ctyp<>> ] ] + ; + class_signature: + [ [ `ANTIQUOT (""|"csg"|"anti"|"list" as n) s -> + <:class_sig_item< $anti:mk_anti ~c:"class_sig_item" n s$ >> + | `ANTIQUOT (""|"csg"|"anti"|"list" as n) s; semi; csg = SELF -> + <:class_sig_item< $anti:mk_anti ~c:"class_sig_item" n s$; $csg$ >> + | l = LIST0 [ csg = class_sig_item; semi -> csg ] -> Ast.cgSem_of_list l + ] ] + ; + class_sig_item: + [ [ `ANTIQUOT (""|"csg"|"anti"|"list" as n) s -> + <:class_sig_item< $anti:mk_anti ~c:"class_sig_item" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_sig_item_tag + | "inherit"; cs = class_type -> <:class_sig_item< inherit $cs$ >> + | value_val; mf = opt_mutable; mv = opt_virtual; + l = label; ":"; t = ctyp -> + <:class_sig_item< value $mutable:mf$ $virtual:mv$ $l$ : $t$ >> + | "method"; "virtual"; pf = opt_private; l = label; ":"; t = poly_type -> + <:class_sig_item< method virtual $private:pf$ $l$ : $t$ >> + | "method"; pf = opt_private; l = label; ":"; t = poly_type -> + <:class_sig_item< method $private:pf$ $l$ : $t$ >> + | "method"; pf = opt_private; "virtual"; l = label; ":"; t = poly_type -> + <:class_sig_item< method virtual $private:pf$ $l$ : $t$ >> + | type_constraint; t1 = ctyp; "="; t2 = ctyp -> + <:class_sig_item< type $t1$ = $t2$ >> ] ] + ; + type_constraint: + [ [ "type" | "constraint" -> () ] ] + ; + class_description: + [ [ cd1 = SELF; "and"; cd2 = SELF -> <:class_type< $cd1$ and $cd2$ >> + | `ANTIQUOT (""|"typ"|"anti"|"list" as n) s -> + <:class_type< $anti:mk_anti ~c:"class_type" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_type_tag + | ci = class_info_for_class_type; ":"; ct = class_type_plus -> <:class_type< $ci$ : $ct$ >> + ] ] + ; + class_type_declaration: + [ LEFTA + [ cd1 = SELF; "and"; cd2 = SELF -> <:class_type< $cd1$ and $cd2$ >> + | `ANTIQUOT (""|"typ"|"anti"|"list" as n) s -> + <:class_type< $anti:mk_anti ~c:"class_type" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.class_type_tag + | ci = class_info_for_class_type; "="; ct = class_type -> <:class_type< $ci$ = $ct$ >> + ] ] + ; + field_expr_list: + [ [ b1 = field_expr; ";"; b2 = SELF -> <:rec_binding< $b1$ ; $b2$ >> + | b1 = field_expr; ";" -> b1 + | b1 = field_expr -> b1 + ] ]; + field_expr: + [ [ `ANTIQUOT (""|"bi"|"anti" as n) s -> + <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:rec_binding< $anti:mk_anti ~c:"rec_binding" n s$ >> + | l = label; "="; e = expr -> <:rec_binding< $lid:l$ = $e$ >> ] ] + ; + meth_list: + [ [ m = meth_decl; ";"; (ml, v) = SELF -> (<:ctyp< $m$; $ml$ >>, v) + | m = meth_decl; ";"; v = opt_dot_dot -> (m, v) + | m = meth_decl; v = opt_dot_dot -> (m, v) + ] ] + ; + meth_decl: + [ [ `ANTIQUOT (""|"typ" as n) s -> <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> <:ctyp< $anti:mk_anti ~c:"ctyp;" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | lab = a_LIDENT; ":"; t = poly_type -> <:ctyp< $lid:lab$ : $t$ >> ] ] + ; + opt_meth_list: + [ [ (ml, v) = meth_list -> <:ctyp< < $ml$ $..:v$ > >> + | v = opt_dot_dot -> <:ctyp< < $..:v$ > >> + ] ] + ; + poly_type: + [ [ t = ctyp -> t ] ] + ; + typevars: + [ LEFTA + [ t1 = SELF; t2 = SELF -> <:ctyp< $t1$ $t2$ >> + | `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `QUOTATION x -> Quotation.expand _loc x Quotation.DynAst.ctyp_tag + | "'"; i = a_ident -> <:ctyp< '$lid:i$ >> + ] ] + ; + row_field: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | `ANTIQUOT ("list" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp|" n s$ >> + | t1 = SELF; "|"; t2 = SELF -> <:ctyp< $t1$ | $t2$ >> + | "`"; i = a_ident -> <:ctyp< `$i$ >> + | "`"; i = a_ident; "of"; "&"; t = amp_ctyp -> <:ctyp< `$i$ of & $t$ >> + | "`"; i = a_ident; "of"; t = amp_ctyp -> <:ctyp< `$i$ of $t$ >> + | t = ctyp -> t ] ] + ; + amp_ctyp: + [ [ t1 = SELF; "&"; t2 = SELF -> <:ctyp< $t1$ & $t2$ >> + | `ANTIQUOT ("list" as n) s -> <:ctyp< $anti:mk_anti ~c:"ctyp&" n s$ >> + | t = ctyp -> t + ] ] + ; + name_tags: + [ [ `ANTIQUOT (""|"typ" as n) s -> + <:ctyp< $anti:mk_anti ~c:"ctyp" n s$ >> + | t1 = SELF; t2 = SELF -> <:ctyp< $t1$ $t2$ >> + | "`"; i = a_ident -> <:ctyp< `$i$ >> + ] ] + ; + eq_expr: + [ [ "="; e = expr -> fun i p -> <:patt< ? $i$ : ($p$ = $e$) >> + | -> fun i p -> <:patt< ? $i$ : ($p$) >> ] ] + ; + patt_tcon: + [ [ p = patt; ":"; t = ctyp -> <:patt< ($p$ : $t$) >> + | p = patt -> p ] ] + ; + ipatt: + [ [ `LABEL i; p = SELF -> <:patt< ~ $i$ : $p$ >> + | "~"; `ANTIQUOT (""|"lid" as n) i; ":"; p = SELF -> + <:patt< ~ $mk_anti n i$ : $p$ >> + | "~"; `ANTIQUOT (""|"lid" as n) i -> <:patt< ~ $mk_anti n i$ >> + | "~"; `LIDENT i -> <:patt< ~ $i$ >> + (* | i = opt_label; "("; p = ipatt_tcon; ")" -> + <:patt< ? $i$ : ($p$) >> + | i = opt_label; "("; p = ipatt_tcon; "="; e = expr; ")" -> + <:patt< ? $i$ : ($p$ = $e$) >> *) + | `OPTLABEL i; "("; p = ipatt_tcon; f = eq_expr; ")" -> f i p + | "?"; `ANTIQUOT (""|"lid" as n) i; ":"; "("; p = ipatt_tcon; + f = eq_expr; ")" -> f (mk_anti n i) p + | "?"; `LIDENT i -> <:patt< ? $i$ >> + | "?"; `ANTIQUOT (""|"lid" as n) i -> <:patt< ? $mk_anti n i$ >> + | "?"; "("; p = ipatt_tcon; ")" -> + <:patt< ? ($p$) >> + | "?"; "("; p = ipatt_tcon; "="; e = expr; ")" -> + <:patt< ? ($p$ = $e$) >> ] ] + ; + ipatt_tcon: + [ [ p = ipatt; ":"; t = ctyp -> <:patt< ($p$ : $t$) >> + | p = ipatt -> p ] ] + ; + direction_flag: + [ [ "to" -> Ast.BTrue + | "downto" -> Ast.BFalse + | `ANTIQUOT ("to" as n) s -> Ast.BAnt (mk_anti n s) ] ] + ; + opt_private: + [ [ "private" -> Ast.BTrue + | `ANTIQUOT ("private" as n) s -> Ast.BAnt (mk_anti n s) + | -> Ast.BFalse + ] ] + ; + opt_mutable: + [ [ "mutable" -> Ast.BTrue + | `ANTIQUOT ("mutable" as n) s -> Ast.BAnt (mk_anti n s) + | -> Ast.BFalse + ] ] + ; + opt_virtual: + [ [ "virtual" -> Ast.BTrue + | `ANTIQUOT ("virtual" as n) s -> Ast.BAnt (mk_anti n s) + | -> Ast.BFalse + ] ] + ; + opt_dot_dot: + [ [ ".." -> Ast.BTrue + | `ANTIQUOT (".." as n) s -> Ast.BAnt (mk_anti n s) + | -> Ast.BFalse + ] ] + ; + opt_rec: + [ [ "rec" -> Ast.BTrue + | `ANTIQUOT ("rec" as n) s -> Ast.BAnt (mk_anti n s) + | -> Ast.BFalse + ] ] + ; + opt_expr: + [ [ e = expr -> e + | -> <:expr<>> + ] ] + ; + interf: + [ [ "#"; n = a_LIDENT; dp = opt_expr; semi -> + ([ <:sig_item< # $n$ $dp$ >> ], stopped_at _loc) + | si = sig_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped) + | `EOI -> ([], None) ] ] + ; + sig_items: + [ [ `ANTIQUOT (""|"sigi"|"anti"|"list" as n) s -> + <:sig_item< $anti:mk_anti n ~c:"sig_item" s$ >> + | `ANTIQUOT (""|"sigi"|"anti"|"list" as n) s; semi; sg = SELF -> + <:sig_item< $anti:mk_anti n ~c:"sig_item" s$; $sg$ >> + | l = LIST0 [ sg = sig_item; semi -> sg ] -> Ast.sgSem_of_list l + ] ] + ; + implem: + [ [ "#"; n = a_LIDENT; dp = opt_expr; semi -> + ([ <:str_item< # $n$ $dp$ >> ], stopped_at _loc) + | si = str_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped) + | `EOI -> ([], None) + ] ] + ; + str_items: + [ [ `ANTIQUOT (""|"stri"|"anti"|"list" as n) s -> + <:str_item< $anti:mk_anti n ~c:"str_item" s$ >> + | `ANTIQUOT (""|"stri"|"anti"|"list" as n) s; semi; st = SELF -> + <:str_item< $anti:mk_anti n ~c:"str_item" s$; $st$ >> + | l = LIST0 [ st = str_item; semi -> st ] -> Ast.stSem_of_list l + ] ] + ; + top_phrase: + [ [ ph = phrase -> Some ph + | `EOI -> None + ] ] + ; + use_file: + [ [ "#"; n = a_LIDENT; dp = opt_expr; semi -> + ([ <:str_item< # $n$ $dp$ >> ], stopped_at _loc) + | si = str_item; semi; (sil, stopped) = SELF -> ([si :: sil], stopped) + | `EOI -> ([], None) + ] ] + ; + phrase: + [ [ "#"; n = a_LIDENT; dp = opt_expr; semi -> + <:str_item< # $n$ $dp$ >> + | st = str_item; semi -> st + ] ] + ; + a_INT: + [ [ `ANTIQUOT (""|"int"|"`int" as n) s -> mk_anti n s + | `INT _ s -> s ] ] + ; + a_INT32: + [ [ `ANTIQUOT (""|"int32"|"`int32" as n) s -> mk_anti n s + | `INT32 _ s -> s ] ] + ; + a_INT64: + [ [ `ANTIQUOT (""|"int64"|"`int64" as n) s -> mk_anti n s + | `INT64 _ s -> s ] ] + ; + a_NATIVEINT: + [ [ `ANTIQUOT (""|"nativeint"|"`nativeint" as n) s -> mk_anti n s + | `NATIVEINT _ s -> s ] ] + ; + a_FLOAT: + [ [ `ANTIQUOT (""|"flo"|"`flo" as n) s -> mk_anti n s + | `FLOAT _ s -> s ] ] + ; + a_CHAR: + [ [ `ANTIQUOT (""|"chr"|"`chr" as n) s -> mk_anti n s + | `CHAR _ s -> s ] ] + ; + a_UIDENT: + [ [ `ANTIQUOT (""|"uid" as n) s -> mk_anti n s + | `UIDENT s -> s ] ] + ; + a_LIDENT: + [ [ `ANTIQUOT (""|"lid" as n) s -> mk_anti n s + | `LIDENT s -> s ] ] + ; + a_LABEL: + [ [ "~"; `ANTIQUOT ("" as n) s; ":" -> mk_anti n s + | `LABEL s -> s ] ] + ; + a_OPTLABEL: + [ [ "?"; `ANTIQUOT ("" as n) s; ":" -> mk_anti n s + | `OPTLABEL s -> s ] ] + ; + a_STRING: + [ [ `ANTIQUOT (""|"str"|"`str" as n) s -> mk_anti n s + | `STRING _ s -> s ] ] + ; + string_list: + [ [ `ANTIQUOT (""|"str_list") s -> Ast.LAnt (mk_anti "str_list" s) + | `STRING _ x; xs = string_list -> Ast.LCons x xs + | `STRING _ x -> Ast.LCons x Ast.LNil ] ] + ; + value_let: + [ [ "value" -> () ] ] + ; + value_val: + [ [ "value" -> () ] ] + ; + semi: + [ [ ";" -> () ] ] + ; + expr_quot: + [ [ e1 = expr; ","; e2 = comma_expr -> <:expr< $e1$, $e2$ >> + | e1 = expr; ";"; e2 = sem_expr -> <:expr< $e1$; $e2$ >> + | e = expr -> e + | -> <:expr<>> + ] ] + ; + patt_quot: + [ [ x = patt; ","; y = comma_patt -> <:patt< $x$, $y$ >> + | x = patt; ";"; y = sem_patt -> <:patt< $x$; $y$ >> + | x = patt; "="; y = patt -> + let i = + match x with + [ <:patt@loc< $anti:s$ >> -> <:ident@loc< $anti:s$ >> + | p -> Ast.ident_of_patt p ] + in + <:patt< $i$ = $y$ >> + | x = patt -> x + | -> <:patt<>> + ] ] + ; + ctyp_quot: + [ [ x = more_ctyp; ","; y = comma_ctyp -> <:ctyp< $x$, $y$ >> + | x = more_ctyp; ";"; y = label_declaration_list -> <:ctyp< $x$; $y$ >> + | x = more_ctyp; "|"; y = constructor_declarations -> <:ctyp< $x$ | $y$ >> + | x = more_ctyp; "of"; y = constructor_arg_list -> <:ctyp< $x$ of $y$ >> + | x = more_ctyp; "of"; y = constructor_arg_list; "|"; z = constructor_declarations -> + <:ctyp< $ <:ctyp< $x$ of $y$ >> $ | $z$ >> + | x = more_ctyp; "of"; "&"; y = amp_ctyp -> <:ctyp< $x$ of & $y$ >> + | x = more_ctyp; "of"; "&"; y = amp_ctyp; "|"; z = row_field -> + <:ctyp< $ <:ctyp< $x$ of & $y$ >> $ | $z$ >> + | x = more_ctyp; ":"; y = more_ctyp -> <:ctyp< $x$ : $y$ >> + | x = more_ctyp; ":"; y = more_ctyp; ";"; z = label_declaration_list -> + <:ctyp< $ <:ctyp< $x$ : $y$ >> $ ; $z$ >> + | x = more_ctyp; "*"; y = star_ctyp -> <:ctyp< $x$ * $y$ >> + | x = more_ctyp; "&"; y = amp_ctyp -> <:ctyp< $x$ & $y$ >> + | x = more_ctyp; "and"; y = constructor_arg_list -> <:ctyp< $x$ and $y$ >> + | x = more_ctyp -> x + | -> <:ctyp<>> + ] ] + ; + more_ctyp: + [ [ "mutable"; x = SELF -> <:ctyp< mutable $x$ >> + | "`"; x = a_ident -> <:ctyp< `$x$ >> + | x = type_kind -> x + | x = type_parameter -> x + ] ] + ; + str_item_quot: + [ [ "#"; n = a_LIDENT; dp = opt_expr -> <:str_item< # $n$ $dp$ >> + | st1 = str_item; semi; st2 = SELF -> <:str_item< $st1$; $st2$ >> + | st = str_item -> st + | -> <:str_item<>> ] ] + ; + sig_item_quot: + [ [ "#"; n = a_LIDENT; dp = opt_expr -> <:sig_item< # $n$ $dp$ >> + | sg1 = sig_item; semi; sg2 = SELF -> <:sig_item< $sg1$; $sg2$ >> + | sg = sig_item -> sg + | -> <:sig_item<>> ] ] + ; + module_type_quot: + [ [ x = module_type -> x + | -> <:module_type<>> + ] ] + ; + module_expr_quot: + [ [ x = module_expr -> x + | -> <:module_expr<>> + ] ] + ; + match_case_quot: + [ [ x = LIST0 match_case0 SEP "|" -> <:match_case< $list:x$ >> + | -> <:match_case<>> ] ] + ; + binding_quot: + [ [ x = binding -> x + | -> <:binding<>> + ] ] + ; + rec_binding_quot: + [ [ x = label_expr_list -> x + | -> <:rec_binding<>> ] ] + ; + module_binding_quot: + [ [ b1 = SELF; "and"; b2 = SELF -> + <:module_binding< $b1$ and $b2$ >> + | `ANTIQUOT ("module_binding"|"anti" as n) s -> + <:module_binding< $anti:mk_anti ~c:"module_binding" n s$ >> + | `ANTIQUOT ("" as n) s -> <:module_binding< $anti:mk_anti ~c:"module_binding" n s$ >> + | `ANTIQUOT ("" as n) m; ":"; mt = module_type -> + <:module_binding< $mk_anti n m$ : $mt$ >> + | `ANTIQUOT ("" as n) m; ":"; mt = module_type; "="; me = module_expr -> + <:module_binding< $mk_anti n m$ : $mt$ = $me$ >> + | m = a_UIDENT; ":"; mt = module_type -> <:module_binding< $m$ : $mt$ >> + | m = a_UIDENT; ":"; mt = module_type; "="; me = module_expr -> + <:module_binding< $m$ : $mt$ = $me$ >> + | -> <:module_binding<>> + ] ] + ; + ident_quot: + [ "apply" + [ i = SELF; j = SELF -> <:ident< $i$ $j$ >> ] + | "." + [ i = SELF; "."; j = SELF -> <:ident< $i$.$j$ >> ] + | "simple" + [ `ANTIQUOT (""|"id"|"anti"|"list" as n) s -> + <:ident< $anti:mk_anti ~c:"ident" n s$ >> + | i = a_UIDENT -> <:ident< $uid:i$ >> + | i = a_LIDENT -> <:ident< $lid:i$ >> + | `ANTIQUOT (""|"id"|"anti"|"list" as n) s; "."; i = SELF -> + <:ident< $anti:mk_anti ~c:"ident" n s$.$i$ >> + | "("; i = SELF; ")" -> i + ] ] + ; + class_expr_quot: + [ [ ce1 = SELF; "and"; ce2 = SELF -> <:class_expr< $ce1$ and $ce2$ >> + | ce1 = SELF; "="; ce2 = SELF -> <:class_expr< $ce1$ = $ce2$ >> + | "virtual"; (i, ot) = class_name_and_param -> + <:class_expr< virtual $lid:i$ [ $ot$ ] >> + | `ANTIQUOT ("virtual" as n) s; i = ident; ot = opt_comma_ctyp -> + let anti = Ast.BAnt (mk_anti ~c:"class_expr" n s) in + <:class_expr< $virtual:anti$ $id:i$ [ $ot$ ] >> + | x = class_expr -> x + | -> <:class_expr<>> + ] ] + ; + class_type_quot: + [ [ ct1 = SELF; "and"; ct2 = SELF -> <:class_type< $ct1$ and $ct2$ >> + | ct1 = SELF; "="; ct2 = SELF -> <:class_type< $ct1$ = $ct2$ >> + | ct1 = SELF; ":"; ct2 = SELF -> <:class_type< $ct1$ : $ct2$ >> + | "virtual"; (i, ot) = class_name_and_param -> + <:class_type< virtual $lid:i$ [ $ot$ ] >> + | `ANTIQUOT ("virtual" as n) s; i = ident; ot = opt_comma_ctyp -> + let anti = Ast.BAnt (mk_anti ~c:"class_type" n s) in + <:class_type< $virtual:anti$ $id:i$ [ $ot$ ] >> + | x = class_type_plus -> x + | -> <:class_type<>> + ] ] + ; + class_str_item_quot: + [ [ x1 = class_str_item; semi; x2 = SELF -> + <:class_str_item< $x1$; $x2$ >> + | x = class_str_item -> x + | -> <:class_str_item<>> ] ] + ; + class_sig_item_quot: + [ [ x1 = class_sig_item; semi; x2 = SELF -> <:class_sig_item< $x1$; $x2$ >> + | x = class_sig_item -> x + | -> <:class_sig_item<>> ] ] + ; + with_constr_quot: + [ [ x = with_constr -> x + | -> <:with_constr<>> ] ] + ; + patt_eoi: + [ [ x = patt; `EOI -> x ] ] + ; + expr_eoi: + [ [ x = expr; `EOI -> x ] ] + ; + END; + +end; + +let module M = Register.OCamlSyntaxExtension Id Make in (); diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParserParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParserParser.ml new file mode 100644 index 0000000..4e4d35d --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParserParser.ml @@ -0,0 +1,394 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 1998-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + +module Id : Sig.Id = struct + value name = "Camlp4OCamlRevisedParserParser"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) = struct + open Sig; + include Syntax; + + type spat_comp = + [ SpTrm of Loc.t and Ast.patt and option Ast.expr + | SpNtr of Loc.t and Ast.patt and Ast.expr + | SpStr of Loc.t and Ast.patt ] + ; + type sexp_comp = + [ SeTrm of Loc.t and Ast.expr | SeNtr of Loc.t and Ast.expr ] + ; + + value stream_expr = Gram.Entry.mk "stream_expr"; + value stream_begin = Gram.Entry.mk "stream_begin"; + value stream_end = Gram.Entry.mk "stream_end"; + value stream_quot = Gram.Entry.mk "stream_quot"; + value parser_case = Gram.Entry.mk "parser_case"; + value parser_case_list = Gram.Entry.mk "parser_case_list"; + + value strm_n = "__strm"; + value peek_fun _loc = <:expr< Stream.peek >>; + value junk_fun _loc = <:expr< Stream.junk >>; + + (* Parsers. *) + (* In syntax generated, many cases are optimisations. *) + + value rec pattern_eq_expression p e = + match (p, e) with + [ (<:patt< $lid:a$ >>, <:expr< $lid:b$ >>) -> a = b + | (<:patt< $uid:a$ >>, <:expr< $uid:b$ >>) -> a = b + | (<:patt< $p1$ $p2$ >>, <:expr< $e1$ $e2$ >>) -> + pattern_eq_expression p1 e1 && pattern_eq_expression p2 e2 + | _ -> False ] + ; + + value is_raise e = + match e with + [ <:expr< raise $_$ >> -> True + | _ -> False ] + ; + + value is_raise_failure e = + match e with + [ <:expr< raise Stream.Failure >> -> True + | _ -> False ] + ; + + value rec handle_failure e = + match e with + [ <:expr< try $_$ with [ Stream.Failure -> $e$] >> -> + handle_failure e + | <:expr< match $me$ with [ $a$ ] >> -> + let rec match_case_handle_failure = + fun + [ <:match_case< $a1$ | $a2$ >> -> + match_case_handle_failure a1 && match_case_handle_failure a2 + | <:match_case< $pat:_$ -> $e$ >> -> handle_failure e + | _ -> False ] + in handle_failure me && match_case_handle_failure a + | <:expr< let $bi$ in $e$ >> -> + let rec binding_handle_failure = + fun + [ <:binding< $b1$ and $b2$ >> -> + binding_handle_failure b1 && binding_handle_failure b2 + | <:binding< $_$ = $e$ >> -> handle_failure e + | _ -> False ] + in binding_handle_failure bi && handle_failure e + | <:expr< $lid:_$ >> | <:expr< $int:_$ >> | <:expr< $str:_$ >> | + <:expr< $chr:_$ >> | <:expr< fun [ $_$ ] >> | <:expr< $uid:_$ >> -> + True + | <:expr< raise $e$ >> -> + match e with + [ <:expr< Stream.Failure >> -> False + | _ -> True ] + | <:expr< $f$ $x$ >> -> + is_constr_apply f && handle_failure f && handle_failure x + | _ -> False ] + and is_constr_apply = + fun + [ <:expr< $uid:_$ >> -> True + | <:expr< $lid:_$ >> -> False + | <:expr< $x$ $_$ >> -> is_constr_apply x + | _ -> False ] + ; + + value rec subst v e = + let _loc = Ast.loc_of_expr e in + match e with + [ <:expr< $lid:x$ >> -> + let x = if x = v then strm_n else x in + <:expr< $lid:x$ >> + | <:expr< $uid:_$ >> -> e + | <:expr< $int:_$ >> -> e + | <:expr< $chr:_$ >> -> e + | <:expr< $str:_$ >> -> e + | <:expr< $_$ . $_$ >> -> e + | <:expr< let $rec:rf$ $bi$ in $e$ >> -> + <:expr< let $rec:rf$ $subst_binding v bi$ in $subst v e$ >> + | <:expr< $e1$ $e2$ >> -> <:expr< $subst v e1$ $subst v e2$ >> + | <:expr< ( $tup:e$ ) >> -> <:expr< ( $tup:subst v e$ ) >> + | <:expr< $e1$, $e2$ >> -> <:expr< $subst v e1$, $subst v e2$ >> + | _ -> raise Not_found ] + and subst_binding v = + fun + [ <:binding@_loc< $b1$ and $b2$ >> -> + <:binding< $subst_binding v b1$ and $subst_binding v b2$ >> + | <:binding@_loc< $lid:v'$ = $e$ >> -> + <:binding< $lid:v'$ = $if v = v' then e else subst v e$ >> + | _ -> raise Not_found ]; + + value stream_pattern_component skont ckont = + fun + [ SpTrm _loc p None -> + <:expr< match $peek_fun _loc$ $lid:strm_n$ with + [ Some $p$ -> + do { $junk_fun _loc$ $lid:strm_n$; $skont$ } + | _ -> $ckont$ ] >> + | SpTrm _loc p (Some w) -> + <:expr< match $peek_fun _loc$ $lid:strm_n$ with + [ Some $p$ when $w$ -> + do { $junk_fun _loc$ $lid:strm_n$; $skont$ } + | _ -> $ckont$ ] >> + | SpNtr _loc p e -> + let e = + match e with + [ <:expr< fun [ ($lid:v$ : Stream.t _) -> $e$ ] >> when v = strm_n -> e + | _ -> <:expr< $e$ $lid:strm_n$ >> ] + in + if pattern_eq_expression p skont then + if is_raise_failure ckont then e + else if handle_failure e then e + else <:expr< try $e$ with [ Stream.Failure -> $ckont$ ] >> + else if is_raise_failure ckont then + <:expr< let $p$ = $e$ in $skont$ >> + else if pattern_eq_expression <:patt< Some $p$ >> skont then + <:expr< try Some $e$ with [ Stream.Failure -> $ckont$ ] >> + else if is_raise ckont then + let tst = + if handle_failure e then e + else <:expr< try $e$ with [ Stream.Failure -> $ckont$ ] >> + in + <:expr< let $p$ = $tst$ in $skont$ >> + else + <:expr< match try Some $e$ with [ Stream.Failure -> None ] with + [ Some $p$ -> $skont$ + | _ -> $ckont$ ] >> + | SpStr _loc p -> + try + match p with + [ <:patt< $lid:v$ >> -> subst v skont + | _ -> raise Not_found ] + with + [ Not_found -> <:expr< let $p$ = $lid:strm_n$ in $skont$ >> ] ] + ; + + value rec stream_pattern _loc epo e ekont = + fun + [ [] -> + match epo with + [ Some ep -> <:expr< let $ep$ = Stream.count $lid:strm_n$ in $e$ >> + | _ -> e ] + | [(spc, err) :: spcl] -> + let skont = + let ekont err = + let str = + match err with + [ Some estr -> estr + | _ -> <:expr< "" >> ] + in + <:expr< raise (Stream.Error $str$) >> + in + stream_pattern _loc epo e ekont spcl + in + let ckont = ekont err in stream_pattern_component skont ckont spc ] + ; + + value stream_patterns_term _loc ekont tspel = + let pel = + List.fold_right + (fun (p, w, _loc, spcl, epo, e) acc -> + let p = <:patt< Some $p$ >> in + let e = + let ekont err = + let str = + match err with + [ Some estr -> estr + | _ -> <:expr< "" >> ] + in + <:expr< raise (Stream.Error $str$) >> + in + let skont = stream_pattern _loc epo e ekont spcl in + <:expr< do { $junk_fun _loc$ $lid:strm_n$; $skont$ } >> + in + match w with + [ Some w -> <:match_case< $pat:p$ when $w$ -> $e$ | $acc$ >> + | None -> <:match_case< $pat:p$ -> $e$ | $acc$ >> ]) + tspel <:match_case<>> + in + <:expr< match $peek_fun _loc$ $lid:strm_n$ with [ $pel$ | _ -> $ekont ()$ ] >> + ; + + value rec group_terms = + fun + [ [([(SpTrm _loc p w, None) :: spcl], epo, e) :: spel] -> + let (tspel, spel) = group_terms spel in + ([(p, w, _loc, spcl, epo, e) :: tspel], spel) + | spel -> ([], spel) ] + ; + + value rec parser_cases _loc = + fun + [ [] -> <:expr< raise Stream.Failure >> + | spel -> + match group_terms spel with + [ ([], [(spcl, epo, e) :: spel]) -> + stream_pattern _loc epo e (fun _ -> parser_cases _loc spel) spcl + | (tspel, spel) -> + stream_patterns_term _loc (fun _ -> parser_cases _loc spel) tspel ] ] + ; + + value cparser _loc bpo pc = + let e = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $e$ >> + | None -> e ] + in + let p = <:patt< ($lid:strm_n$ : Stream.t _) >> in + <:expr< fun $p$ -> $e$ >> + ; + + value cparser_match _loc me bpo pc = + let pc = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >> + | None -> pc ] + in + let me = + match me with + [ <:expr@_loc< $_$; $_$ >> as e -> <:expr< do { $e$ } >> + | e -> e ] + in + match me with + [ <:expr< $lid:x$ >> when x = strm_n -> e + | _ -> <:expr< let ($lid:strm_n$ : Stream.t _) = $me$ in $e$ >> ] + ; + + (* streams *) + + value rec not_computing = + fun + [ <:expr< $lid:_$ >> | <:expr< $uid:_$ >> | <:expr< $int:_$ >> | + <:expr< $flo:_$ >> | <:expr< $chr:_$ >> | <:expr< $str:_$ >> -> True + | <:expr< $x$ $y$ >> -> is_cons_apply_not_computing x && not_computing y + | _ -> False ] + and is_cons_apply_not_computing = + fun + [ <:expr< $uid:_$ >> -> True + | <:expr< $lid:_$ >> -> False + | <:expr< $x$ $y$ >> -> is_cons_apply_not_computing x && not_computing y + | _ -> False ] + ; + + value slazy _loc e = + match e with + [ <:expr< $f$ () >> -> + match f with + [ <:expr< $lid:_$ >> -> f + | _ -> <:expr< fun _ -> $e$ >> ] + | _ -> <:expr< fun _ -> $e$ >> ] + ; + + value rec cstream gloc = + fun + [ [] -> let _loc = gloc in <:expr< Stream.sempty >> + | [SeTrm _loc e] -> + if not_computing e then <:expr< Stream.ising $e$ >> + else <:expr< Stream.lsing $slazy _loc e$ >> + | [SeTrm _loc e :: secl] -> + if not_computing e then <:expr< Stream.icons $e$ $cstream gloc secl$ >> + else <:expr< Stream.lcons $slazy _loc e$ $cstream gloc secl$ >> + | [SeNtr _loc e] -> + if not_computing e then e else <:expr< Stream.slazy $slazy _loc e$ >> + | [SeNtr _loc e :: secl] -> + if not_computing e then <:expr< Stream.iapp $e$ $cstream gloc secl$ >> + else <:expr< Stream.lapp $slazy _loc e$ $cstream gloc secl$ >> ] + ; + (* Syntax extensions in Revised Syntax grammar *) + + EXTEND Gram + GLOBAL: expr stream_expr stream_begin stream_end stream_quot + parser_case parser_case_list; + expr: LEVEL "top" + [ [ "parser"; po = OPT parser_ipatt; pcl = parser_case_list -> + <:expr< $cparser _loc po pcl$ >> + | "match"; e = sequence; "with"; "parser"; po = OPT parser_ipatt; + pcl = parser_case_list -> + <:expr< $cparser_match _loc e po pcl$ >> + ] ] + ; + parser_case_list: + [ [ "["; pcl = LIST0 parser_case SEP "|"; "]" -> pcl + | pc = parser_case -> [pc] + ] ] + ; + parser_case: + [ [ stream_begin; sp = stream_patt; stream_end; po = OPT parser_ipatt; "->"; e = expr -> + (sp, po, e) ] ] + ; + stream_begin: + [ [ "[:" -> () ] ] + ; + stream_end: + [ [ ":]" -> () ] ] + ; + stream_quot: + [ [ "`" -> () ] ] + ; + stream_expr: + [ [ e = expr -> e ] ] + ; + stream_patt: + [ [ spc = stream_patt_comp -> [(spc, None)] + | spc = stream_patt_comp; ";"; sp = stream_patt_comp_err_list -> + [(spc, None) :: sp] + | -> [] ] ] + ; + stream_patt_comp_err: + [ [ spc = stream_patt_comp; eo = OPT [ "??"; e = stream_expr -> e ] -> + (spc, eo) ] ] + ; + stream_patt_comp_err_list: + [ [ spc = stream_patt_comp_err -> [spc] + | spc = stream_patt_comp_err; ";" -> [spc] + | spc = stream_patt_comp_err; ";"; sp = stream_patt_comp_err_list -> + [spc :: sp] ] ] + ; + stream_patt_comp: + [ [ stream_quot; p = patt; eo = OPT [ "when"; e = stream_expr -> e ] -> SpTrm _loc p eo + | p = patt; "="; e = stream_expr -> SpNtr _loc p e + | p = patt -> SpStr _loc p ] ] + ; + parser_ipatt: + [ [ i = a_LIDENT -> <:patt< $lid:i$ >> + | "_" -> <:patt< _ >> + ] ] + ; + expr: LEVEL "simple" + [ [ stream_begin; stream_end -> <:expr< $cstream _loc []$ >> + | stream_begin; sel = stream_expr_comp_list; stream_end -> + <:expr< $cstream _loc sel$ >> ] ] + ; + stream_expr_comp_list: + [ [ se = stream_expr_comp; ";"; sel = stream_expr_comp_list -> [se :: sel] + | se = stream_expr_comp; ";" -> [se] + | se = stream_expr_comp -> [se] ] ] + ; + stream_expr_comp: + [ [ stream_quot; e = stream_expr -> SeTrm _loc e + | e = stream_expr -> SeNtr _loc e ] ] + ; + END; + +end; + +module M = Register.OCamlSyntaxExtension Id Make; diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedQuotationExpander.ml b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedQuotationExpander.ml new file mode 100644 index 0000000..07d2a01 --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedQuotationExpander.ml @@ -0,0 +1,24 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open PreCast; +let module Gram = MakeGram Lexer in +let module M1 = OCamlInitSyntax.Make Ast Gram Quotation in +let module M2 = Camlp4OCamlRevisedParser.Make M1 in +let module M3 = Camlp4QuotationCommon.Make M2 Syntax.AntiquotSyntax in (); diff --git a/camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml b/camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml new file mode 100644 index 0000000..50e57fa --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml @@ -0,0 +1,205 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +module Id = struct + value name = "Camlp4QuotationCommon"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) + (TheAntiquotSyntax : (Sig.Parser Syntax.Ast).SIMPLE) += struct + open Sig; + include Syntax; (* Be careful an AntiquotSyntax module appears here *) + + module MetaLocHere = Ast.Meta.MetaLoc; + module MetaLoc = struct + module Ast = Ast; + value loc_name = ref None; + value meta_loc_expr _loc loc = + match loc_name.val with + [ None -> <:expr< $lid:Loc.name.val$ >> + | Some "here" -> MetaLocHere.meta_loc_expr _loc loc + | Some x -> <:expr< $lid:x$ >> ]; + value meta_loc_patt _loc _ = <:patt< _ >>; + end; + module MetaAst = Ast.Meta.Make MetaLoc; + module ME = MetaAst.Expr; + module MP = MetaAst.Patt; + + value is_antiquot s = + let len = String.length s in + len > 2 && s.[0] = '\\' && s.[1] = '$'; + + value handle_antiquot_in_string s term parse loc decorate = + if is_antiquot s then + let pos = String.index s ':' in + let name = String.sub s 2 (pos - 2) + and code = String.sub s (pos + 1) (String.length s - pos - 1) in + decorate name (parse loc code) + else term; + + value antiquot_expander = object + inherit Ast.map as super; + method patt = fun + [ <:patt@_loc< $anti:s$ >> | <:patt@_loc< $str:s$ >> as p -> + let mloc _loc = MetaLoc.meta_loc_patt _loc _loc in + handle_antiquot_in_string s p TheAntiquotSyntax.parse_patt _loc (fun n p -> + match n with + [ "antisig_item" -> <:patt< Ast.SgAnt $mloc _loc$ $p$ >> + | "antistr_item" -> <:patt< Ast.StAnt $mloc _loc$ $p$ >> + | "antictyp" -> <:patt< Ast.TyAnt $mloc _loc$ $p$ >> + | "antipatt" -> <:patt< Ast.PaAnt $mloc _loc$ $p$ >> + | "antiexpr" -> <:patt< Ast.ExAnt $mloc _loc$ $p$ >> + | "antimodule_type" -> <:patt< Ast.MtAnt $mloc _loc$ $p$ >> + | "antimodule_expr" -> <:patt< Ast.MeAnt $mloc _loc$ $p$ >> + | "anticlass_type" -> <:patt< Ast.CtAnt $mloc _loc$ $p$ >> + | "anticlass_expr" -> <:patt< Ast.CeAnt $mloc _loc$ $p$ >> + | "anticlass_sig_item" -> <:patt< Ast.CgAnt $mloc _loc$ $p$ >> + | "anticlass_str_item" -> <:patt< Ast.CrAnt $mloc _loc$ $p$ >> + | "antiwith_constr" -> <:patt< Ast.WcAnt $mloc _loc$ $p$ >> + | "antibinding" -> <:patt< Ast.BiAnt $mloc _loc$ $p$ >> + | "antirec_binding" -> <:patt< Ast.RbAnt $mloc _loc$ $p$ >> + | "antimatch_case" -> <:patt< Ast.McAnt $mloc _loc$ $p$ >> + | "antimodule_binding" -> <:patt< Ast.MbAnt $mloc _loc$ $p$ >> + | "antiident" -> <:patt< Ast.IdAnt $mloc _loc$ $p$ >> + | _ -> p ]) + | p -> super#patt p ]; + method expr = fun + [ <:expr@_loc< $anti:s$ >> | <:expr@_loc< $str:s$ >> as e -> + let mloc _loc = MetaLoc.meta_loc_expr _loc _loc in + handle_antiquot_in_string s e TheAntiquotSyntax.parse_expr _loc (fun n e -> + match n with + [ "`int" -> <:expr< string_of_int $e$ >> + | "`int32" -> <:expr< Int32.to_string $e$ >> + | "`int64" -> <:expr< Int64.to_string $e$ >> + | "`nativeint" -> <:expr< Nativeint.to_string $e$ >> + | "`flo" -> <:expr< string_of_float $e$ >> + | "`str" -> <:expr< Ast.safe_string_escaped $e$ >> + | "`chr" -> <:expr< Char.escaped $e$ >> + | "`bool" -> <:expr< Ast.IdUid $mloc _loc$ (if $e$ then "True" else "False") >> + | "liststr_item" -> <:expr< Ast.stSem_of_list $e$ >> + | "listsig_item" -> <:expr< Ast.sgSem_of_list $e$ >> + | "listclass_sig_item" -> <:expr< Ast.cgSem_of_list $e$ >> + | "listclass_str_item" -> <:expr< Ast.crSem_of_list $e$ >> + | "listmodule_expr" -> <:expr< Ast.meApp_of_list $e$ >> + | "listmodule_type" -> <:expr< Ast.mtApp_of_list $e$ >> + | "listmodule_binding" -> <:expr< Ast.mbAnd_of_list $e$ >> + | "listbinding" -> <:expr< Ast.biAnd_of_list $e$ >> + | "listbinding;" -> <:expr< Ast.biSem_of_list $e$ >> + | "listrec_binding" -> <:expr< Ast.rbSem_of_list $e$ >> + | "listclass_type" -> <:expr< Ast.ctAnd_of_list $e$ >> + | "listclass_expr" -> <:expr< Ast.ceAnd_of_list $e$ >> + | "listident" -> <:expr< Ast.idAcc_of_list $e$ >> + | "listctypand" -> <:expr< Ast.tyAnd_of_list $e$ >> + | "listctyp;" -> <:expr< Ast.tySem_of_list $e$ >> + | "listctyp*" -> <:expr< Ast.tySta_of_list $e$ >> + | "listctyp|" -> <:expr< Ast.tyOr_of_list $e$ >> + | "listctyp," -> <:expr< Ast.tyCom_of_list $e$ >> + | "listctyp&" -> <:expr< Ast.tyAmp_of_list $e$ >> + | "listwith_constr" -> <:expr< Ast.wcAnd_of_list $e$ >> + | "listmatch_case" -> <:expr< Ast.mcOr_of_list $e$ >> + | "listpatt," -> <:expr< Ast.paCom_of_list $e$ >> + | "listpatt;" -> <:expr< Ast.paSem_of_list $e$ >> + | "listexpr," -> <:expr< Ast.exCom_of_list $e$ >> + | "listexpr;" -> <:expr< Ast.exSem_of_list $e$ >> + | "antisig_item" -> <:expr< Ast.SgAnt $mloc _loc$ $e$ >> + | "antistr_item" -> <:expr< Ast.StAnt $mloc _loc$ $e$ >> + | "antictyp" -> <:expr< Ast.TyAnt $mloc _loc$ $e$ >> + | "antipatt" -> <:expr< Ast.PaAnt $mloc _loc$ $e$ >> + | "antiexpr" -> <:expr< Ast.ExAnt $mloc _loc$ $e$ >> + | "antimodule_type" -> <:expr< Ast.MtAnt $mloc _loc$ $e$ >> + | "antimodule_expr" -> <:expr< Ast.MeAnt $mloc _loc$ $e$ >> + | "anticlass_type" -> <:expr< Ast.CtAnt $mloc _loc$ $e$ >> + | "anticlass_expr" -> <:expr< Ast.CeAnt $mloc _loc$ $e$ >> + | "anticlass_sig_item" -> <:expr< Ast.CgAnt $mloc _loc$ $e$ >> + | "anticlass_str_item" -> <:expr< Ast.CrAnt $mloc _loc$ $e$ >> + | "antiwith_constr" -> <:expr< Ast.WcAnt $mloc _loc$ $e$ >> + | "antibinding" -> <:expr< Ast.BiAnt $mloc _loc$ $e$ >> + | "antirec_binding" -> <:expr< Ast.RbAnt $mloc _loc$ $e$ >> + | "antimatch_case" -> <:expr< Ast.McAnt $mloc _loc$ $e$ >> + | "antimodule_binding" -> <:expr< Ast.MbAnt $mloc _loc$ $e$ >> + | "antiident" -> <:expr< Ast.IdAnt $mloc _loc$ $e$ >> + | _ -> e ]) + | e -> super#expr e ]; + end; + + value add_quotation name entry mexpr mpatt = + let entry_eoi = Gram.Entry.mk (Gram.Entry.name entry) in + let parse_quot_string entry loc s = + let q = Camlp4_config.antiquotations.val in + let () = Camlp4_config.antiquotations.val := True in + let res = Gram.parse_string entry loc s in + let () = Camlp4_config.antiquotations.val := q in + res in + let expand_expr loc loc_name_opt s = + let ast = parse_quot_string entry_eoi loc s in + let () = MetaLoc.loc_name.val := loc_name_opt in + let meta_ast = mexpr loc ast in + let exp_ast = antiquot_expander#expr meta_ast in + exp_ast in + let expand_str_item loc loc_name_opt s = + let exp_ast = expand_expr loc loc_name_opt s in + <:str_item@loc< $exp:exp_ast$ >> in + let expand_patt _loc loc_name_opt s = + let ast = parse_quot_string entry_eoi _loc s in + let meta_ast = mpatt _loc ast in + let exp_ast = antiquot_expander#patt meta_ast in + match loc_name_opt with + [ None -> exp_ast + | Some name -> + let rec subst_first_loc = + fun + [ <:patt@_loc< Ast.$uid:u$ $_$ >> -> <:patt< Ast.$uid:u$ $lid:name$ >> + | <:patt@_loc< $a$ $b$ >> -> <:patt< $subst_first_loc a$ $b$ >> + | p -> p ] in + subst_first_loc exp_ast ] in + do { + EXTEND Gram + entry_eoi: + [ [ x = entry; `EOI -> x ] ] + ; + END; + Quotation.add name Quotation.DynAst.expr_tag expand_expr; + Quotation.add name Quotation.DynAst.patt_tag expand_patt; + Quotation.add name Quotation.DynAst.str_item_tag expand_str_item; + }; + + add_quotation "sig_item" sig_item_quot ME.meta_sig_item MP.meta_sig_item; + add_quotation "str_item" str_item_quot ME.meta_str_item MP.meta_str_item; + add_quotation "ctyp" ctyp_quot ME.meta_ctyp MP.meta_ctyp; + add_quotation "patt" patt_quot ME.meta_patt MP.meta_patt; + add_quotation "expr" expr_quot ME.meta_expr MP.meta_expr; + add_quotation "module_type" module_type_quot ME.meta_module_type MP.meta_module_type; + add_quotation "module_expr" module_expr_quot ME.meta_module_expr MP.meta_module_expr; + add_quotation "class_type" class_type_quot ME.meta_class_type MP.meta_class_type; + add_quotation "class_expr" class_expr_quot ME.meta_class_expr MP.meta_class_expr; + add_quotation "class_sig_item" + class_sig_item_quot ME.meta_class_sig_item MP.meta_class_sig_item; + add_quotation "class_str_item" + class_str_item_quot ME.meta_class_str_item MP.meta_class_str_item; + add_quotation "with_constr" with_constr_quot ME.meta_with_constr MP.meta_with_constr; + add_quotation "binding" binding_quot ME.meta_binding MP.meta_binding; + add_quotation "rec_binding" rec_binding_quot ME.meta_rec_binding MP.meta_rec_binding; + add_quotation "match_case" match_case_quot ME.meta_match_case MP.meta_match_case; + add_quotation "module_binding" + module_binding_quot ME.meta_module_binding MP.meta_module_binding; + add_quotation "ident" ident_quot ME.meta_ident MP.meta_ident; + +end; diff --git a/camlp4/Camlp4Parsers/Camlp4QuotationExpander.ml b/camlp4/Camlp4Parsers/Camlp4QuotationExpander.ml new file mode 100644 index 0000000..fb225a5 --- /dev/null +++ b/camlp4/Camlp4Parsers/Camlp4QuotationExpander.ml @@ -0,0 +1,33 @@ +open Camlp4; (* -*- camlp4r -*- *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + +module Id = struct + value name = "Camlp4QuotationExpander"; + value version = Sys.ocaml_version; +end; + +module Make (Syntax : Sig.Camlp4Syntax) += struct + module M = Camlp4QuotationCommon.Make Syntax Syntax.AntiquotSyntax; + include M; +end; + +let module M = Register.OCamlSyntaxExtension Id Make in (); diff --git a/camlp4/Camlp4Printers/Camlp4AstDumper.ml b/camlp4/Camlp4Printers/Camlp4AstDumper.ml new file mode 100644 index 0000000..f89fed4 --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4AstDumper.ml @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +Camlp4.Register.enable_dump_camlp4_ast_printer (); diff --git a/camlp4/Camlp4Printers/Camlp4AutoPrinter.ml b/camlp4/Camlp4Printers/Camlp4AutoPrinter.ml new file mode 100644 index 0000000..eb6b9a2 --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4AutoPrinter.ml @@ -0,0 +1,24 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +open Camlp4.Register; + +if Unix.isatty Unix.stdout then + enable_ocaml_printer () +else + enable_dump_ocaml_ast_printer (); diff --git a/camlp4/Camlp4Printers/Camlp4NullDumper.ml b/camlp4/Camlp4Printers/Camlp4NullDumper.ml new file mode 100644 index 0000000..0e02b66 --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4NullDumper.ml @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +Camlp4.Register.enable_null_printer (); diff --git a/camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml b/camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml new file mode 100644 index 0000000..174e5ad --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +Camlp4.Register.enable_dump_ocaml_ast_printer (); diff --git a/camlp4/Camlp4Printers/Camlp4OCamlPrinter.ml b/camlp4/Camlp4Printers/Camlp4OCamlPrinter.ml new file mode 100644 index 0000000..487b862 --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4OCamlPrinter.ml @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +Camlp4.Register.enable_ocaml_printer (); diff --git a/camlp4/Camlp4Printers/Camlp4OCamlRevisedPrinter.ml b/camlp4/Camlp4Printers/Camlp4OCamlRevisedPrinter.ml new file mode 100644 index 0000000..bd5af1f --- /dev/null +++ b/camlp4/Camlp4Printers/Camlp4OCamlRevisedPrinter.ml @@ -0,0 +1,19 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) + +Camlp4.Register.enable_ocamlr_printer (); diff --git a/camlp4/Camlp4Top.mlpack b/camlp4/Camlp4Top.mlpack new file mode 100644 index 0000000..d3560fb --- /dev/null +++ b/camlp4/Camlp4Top.mlpack @@ -0,0 +1,2 @@ +Top +Rprint diff --git a/camlp4/Camlp4Top/Rprint.ml b/camlp4/Camlp4Top/Rprint.ml new file mode 100644 index 0000000..ff2a7e5 --- /dev/null +++ b/camlp4/Camlp4Top/Rprint.ml @@ -0,0 +1,472 @@ +(* camlp4r *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +(* There is a few Obj.magic due to the fact that we no longer have compiler + files like Parsetree, Location, Longident but Camlp4_import that wrap them to + avoid name clashing. *) +module Toploop : sig + open Format; + open Camlp4_import; + value print_out_value : + ref (formatter -> Outcometree.out_value -> unit); + value print_out_type : + ref (formatter -> Outcometree.out_type -> unit); + value print_out_class_type : + ref (formatter -> Outcometree.out_class_type -> unit); + value print_out_module_type : + ref (formatter -> Outcometree.out_module_type -> unit); + value print_out_sig_item : + ref (formatter -> Outcometree.out_sig_item -> unit); + value print_out_signature : + ref (formatter -> list Outcometree.out_sig_item -> unit); + value print_out_phrase : + ref (formatter -> Outcometree.out_phrase -> unit); +end = struct + open Toploop; + value print_out_value = Obj.magic print_out_value; + value print_out_type = Obj.magic print_out_type; + value print_out_class_type = Obj.magic print_out_class_type; + value print_out_module_type = Obj.magic print_out_module_type; + value print_out_sig_item = Obj.magic print_out_sig_item; + value print_out_signature = Obj.magic print_out_signature; + value print_out_phrase = Obj.magic print_out_phrase; +end; + +(* This file originally come from typing/oprint.ml *) + +open Format; +open Camlp4_import.Outcometree; +open Camlp4; + +exception Ellipsis; +value cautious f ppf arg = + try f ppf arg with [ Ellipsis -> fprintf ppf "..." ] +; + +value rec print_ident ppf = + fun + [ Oide_ident s -> fprintf ppf "%s" s + | Oide_dot id s -> fprintf ppf "%a.%s" print_ident id s + | Oide_apply id1 id2 -> + fprintf ppf "%a(%a)" print_ident id1 print_ident id2 ] +; + +value value_ident ppf name = + if List.mem name ["or"; "mod"; "land"; "lor"; "lxor"; "lsl"; "lsr"; "asr"] + then + fprintf ppf "( %s )" name + else + match name.[0] with + [ 'a'..'z' | '\223'..'\246' | '\248'..'\255' | '_' -> + fprintf ppf "%s" name + | _ -> fprintf ppf "( %s )" name ] +; + +(* Values *) + +value print_out_value ppf tree = + let rec print_tree ppf = + fun + [ Oval_constr name ([_ :: _] as params) -> + fprintf ppf "@[<1>%a@ %a@]" print_ident name + (print_tree_list print_simple_tree "") params + | Oval_variant name (Some param) -> + fprintf ppf "@[<2>`%s@ %a@]" name print_simple_tree param + | tree -> print_simple_tree ppf tree ] + and print_simple_tree ppf = + fun + [ Oval_int i -> fprintf ppf "%i" i + | Oval_int32 i -> fprintf ppf "%ldl" i + | Oval_int64 i -> fprintf ppf "%LdL" i + | Oval_nativeint i -> fprintf ppf "%ndn" i + | Oval_float f -> fprintf ppf "%.12g" f + | Oval_char c -> fprintf ppf "'%s'" (Char.escaped c) + | Oval_string s -> + try fprintf ppf "\"%s\"" (String.escaped s) with + [ Invalid_argument "String.create" -> fprintf ppf "" ] + | Oval_list tl -> + fprintf ppf "@[<1>[%a]@]" (print_tree_list print_tree ";") tl + | Oval_array tl -> + fprintf ppf "@[<2>[|%a|]@]" (print_tree_list print_tree ";") tl + | Oval_constr (Oide_ident "true") [] -> fprintf ppf "True" + | Oval_constr (Oide_ident "false") [] -> fprintf ppf "False" + | Oval_constr name [] -> print_ident ppf name + | Oval_variant name None -> fprintf ppf "`%s" name + | Oval_stuff s -> fprintf ppf "%s" s + | Oval_record fel -> + fprintf ppf "@[<1>{%a}@]" (cautious (print_fields True)) fel + | Oval_tuple tree_list -> + fprintf ppf "@[(%a)@]" (print_tree_list print_tree ",") tree_list + | Oval_ellipsis -> raise Ellipsis + | Oval_printer f -> f ppf + | tree -> fprintf ppf "@[<1>(%a)@]" (cautious print_tree) tree ] + and print_fields first ppf = + fun + [ [] -> () + | [(name, tree) :: fields] -> + let name = + match name with + [ Oide_ident "contents" -> Oide_ident "val" + | x -> x ] + in + do { + if not first then fprintf ppf ";@ " else (); + fprintf ppf "@[<1>%a=@,%a@]" print_ident name (cautious print_tree) + tree; + print_fields False ppf fields + } ] + and print_tree_list print_item sep ppf tree_list = + let rec print_list first ppf = + fun + [ [] -> () + | [tree :: tree_list] -> + do { + if not first then fprintf ppf "%s@ " sep else (); + print_item ppf tree; + print_list False ppf tree_list + } ] + in + cautious (print_list True) ppf tree_list + in + cautious print_tree ppf tree +; + +value rec print_list pr sep ppf = + fun + [ [] -> () + | [a] -> pr ppf a + | [a :: l] -> do { pr ppf a; sep ppf; print_list pr sep ppf l } ] +; + +value pr_vars = + print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ") +; + +value pr_present = + print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ") +; + +(* Types *) + +value rec print_out_type ppf = + fun + [ Otyp_alias ty s -> fprintf ppf "@[%a as '%s@]" print_out_type ty s + | ty -> print_out_type_1 ppf ty ] +and print_out_type_1 ppf = + fun + [ Otyp_arrow lab ty1 ty2 -> + fprintf ppf "@[%a%a ->@ %a@]" print_ty_label lab + print_out_type_2 ty1 print_out_type_1 ty2 + | Otyp_poly sl ty -> + fprintf ppf "@[!%a.@ %a@]" + pr_vars sl + print_out_type ty + | ty -> print_out_type_2 ppf ty ] +and print_out_type_2 ppf = + fun + [ Otyp_constr id ([_ :: _] as tyl) -> + fprintf ppf "@[%a@;<1 2>%a@]" print_ident id + (print_typlist print_simple_out_type "") tyl + | ty -> print_simple_out_type ppf ty ] +and print_simple_out_type ppf = + let rec print_tkind ppf = + fun + [ Otyp_var ng s -> fprintf ppf "'%s%s" (if ng then "_" else "") s + | Otyp_constr id [] -> fprintf ppf "@[%a@]" print_ident id + | Otyp_tuple tyl -> + fprintf ppf "@[<1>(%a)@]" (print_typlist print_out_type " *") tyl + | Otyp_stuff s -> fprintf ppf "%s" s + | Otyp_variant non_gen row_fields closed tags -> + let print_present ppf = + fun + [ None | Some [] -> () + | Some l -> fprintf ppf "@;<1 -2>> @[%a@]" pr_present l ] + in + let print_fields ppf = + fun + [ Ovar_fields fields -> + print_list print_row_field (fun ppf -> fprintf ppf "@;<1 -2>| ") + ppf fields + | Ovar_name id tyl -> + fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id ] + in + fprintf ppf "%s[%s@[@[%a@]%a ]@]" (if non_gen then "_" else "") + (if closed then if tags = None then "= " else "< " + else if tags = None then "> " + else "? ") + print_fields row_fields + print_present tags + | Otyp_object fields rest -> + fprintf ppf "@[<2>< %a >@]" (print_fields rest) fields + | Otyp_class ng id tyl -> + fprintf ppf "@[%a%s#%a@]" print_typargs tyl (if ng then "_" else "") + print_ident id + | Otyp_manifest ty1 ty2 -> + fprintf ppf "@[<2>%a ==@ %a@]" print_out_type ty1 print_out_type ty2 + | Otyp_sum constrs -> + fprintf ppf "@[[ %a ]@]" + (print_list print_out_constr (fun ppf -> fprintf ppf "@ | ")) constrs + | Otyp_record lbls -> + fprintf ppf "@[{ %a }@]" + (print_list print_out_label (fun ppf -> fprintf ppf ";@ ")) lbls + | Otyp_abstract -> fprintf ppf "" + | Otyp_alias _ _ | Otyp_poly _ _ + | Otyp_arrow _ _ _ | Otyp_constr _ [_ :: _] as ty -> + fprintf ppf "@[<1>(%a)@]" print_out_type ty ] + in + print_tkind ppf +and print_out_constr ppf (name, tyl) = + match tyl with + [ [] -> fprintf ppf "%s" name + | _ -> + fprintf ppf "@[<2>%s of@ %a@]" name + (print_typlist print_out_type " and") tyl ] +and print_out_label ppf (name, mut, arg) = + fprintf ppf "@[<2>%s :@ %s%a@]" name (if mut then "mutable " else "") + print_out_type arg +and print_fields rest ppf = + fun + [ [] -> + match rest with + [ Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "") + | None -> () ] + | [(s, t)] -> + do { + fprintf ppf "%s : %a" s print_out_type t; + match rest with + [ Some _ -> fprintf ppf ";@ " + | None -> () ]; + print_fields rest ppf [] + } + | [(s, t) :: l] -> + fprintf ppf "%s : %a;@ %a" s print_out_type t (print_fields rest) l ] +and print_row_field ppf (l, opt_amp, tyl) = + let pr_of ppf = + if opt_amp then fprintf ppf " of@ &@ " + else if tyl <> [] then fprintf ppf " of@ " + else fprintf ppf "" + in + fprintf ppf "@[`%s%t%a@]" l pr_of (print_typlist print_out_type " &") + tyl +and print_typlist print_elem sep ppf = + fun + [ [] -> () + | [ty] -> print_elem ppf ty + | [ty :: tyl] -> + fprintf ppf "%a%s@ %a" print_elem ty sep (print_typlist print_elem sep) + tyl ] +and print_typargs ppf = + fun + [ [] -> () + | [ty1] -> fprintf ppf "%a@ " print_simple_out_type ty1 + | tyl -> + fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_out_type ",") tyl ] +and print_ty_label ppf lab = + if lab <> "" then fprintf ppf "~%s:" lab else () +; + +value type_parameter ppf (ty, (co, cn)) = + fprintf ppf "%s'%s" (if not cn then "+" else if not co then "-" else "") + ty +; + +value print_out_class_params ppf = + fun + [ [] -> () + | tyl -> + fprintf ppf "@[<1>[%a]@]@ " + (print_list type_parameter (fun ppf -> fprintf ppf ", ")) + tyl ] +; + +(* Signature items *) + +value rec print_out_class_type ppf = + fun + [ Octy_constr id tyl -> + let pr_tyl ppf = + fun + [ [] -> () + | tyl -> + fprintf ppf "@[<1>[%a]@]@ " + (print_typlist Toploop.print_out_type.val ",") tyl ] + in + fprintf ppf "@[%a%a@]" pr_tyl tyl print_ident id + | Octy_fun lab ty cty -> + fprintf ppf "@[%a[ %a ] ->@ %a@]" print_ty_label lab + Toploop.print_out_type.val ty print_out_class_type cty + | Octy_signature self_ty csil -> + let pr_param ppf = + fun + [ Some ty -> fprintf ppf "@ @[(%a)@]" Toploop.print_out_type.val ty + | None -> () ] + in + fprintf ppf "@[@[<2>object%a@]@ %a@;<1 -2>end@]" pr_param self_ty + (print_list print_out_class_sig_item (fun ppf -> fprintf ppf "@ ")) + csil ] +and print_out_class_sig_item ppf = + fun + [ Ocsg_constraint ty1 ty2 -> + fprintf ppf "@[<2>type %a =@ %a;@]" Toploop.print_out_type.val ty1 + Toploop.print_out_type.val ty2 + | Ocsg_method name priv virt ty -> + fprintf ppf "@[<2>method %s%s%s :@ %a;@]" + (if priv then "private " else "") (if virt then "virtual " else "") + name Toploop.print_out_type.val ty + | Ocsg_value name mut virt ty -> + fprintf ppf "@[<2>value %s%s%s :@ %a;@]" + (if mut then "mutable " else "") (if virt then "virtual " else "") + name Toploop.print_out_type.val ty ] +; + +value rec print_out_module_type ppf = + fun + [ Omty_ident id -> fprintf ppf "%a" print_ident id + | Omty_signature sg -> + fprintf ppf "@[sig@ %a@;<1 -2>end@]" + Toploop.print_out_signature.val sg + | Omty_functor name mty_arg mty_res -> + fprintf ppf "@[<2>functor@ (%s : %a) ->@ %a@]" name + print_out_module_type mty_arg print_out_module_type mty_res + | Omty_abstract -> () ] +and print_out_signature ppf = + fun + [ [] -> () + | [item] -> fprintf ppf "%a;" Toploop.print_out_sig_item.val item + | [item :: items] -> + fprintf ppf "%a;@ %a" Toploop.print_out_sig_item.val item + print_out_signature items ] +and print_out_sig_item ppf = + fun + [ Osig_class vir_flag name params clt rs -> + fprintf ppf "@[<2>%s%s@ %a%s@ :@ %a@]" + (if rs = Orec_next then "and" else "class") + (if vir_flag then " virtual" else "") print_out_class_params params + name Toploop.print_out_class_type.val clt + | Osig_class_type vir_flag name params clt rs -> + fprintf ppf "@[<2>%s%s@ %a%s@ =@ %a@]" + (if rs = Orec_next then "and" else "class type") + (if vir_flag then " virtual" else "") print_out_class_params params + name Toploop.print_out_class_type.val clt + | Osig_exception id tyl -> + fprintf ppf "@[<2>exception %a@]" print_out_constr (id, tyl) + | Osig_modtype name Omty_abstract -> + fprintf ppf "@[<2>module type %s@]" name + | Osig_modtype name mty -> + fprintf ppf "@[<2>module type %s =@ %a@]" name + Toploop.print_out_module_type.val mty + | Osig_module name mty rs -> + fprintf ppf "@[<2>%s %s :@ %a@]" + (match rs with [ Orec_not -> "module" + | Orec_first -> "module rec" + | Orec_next -> "and" ]) name + Toploop.print_out_module_type.val mty + | Osig_type td rs -> + print_out_type_decl + (if rs = Orec_next then "and" else "type") + ppf td + | Osig_value name ty prims -> + let kwd = if prims = [] then "value" else "external" in + let pr_prims ppf = + fun + [ [] -> () + | [s :: sl] -> + do { + fprintf ppf "@ = \"%s\"" s; + List.iter (fun s -> fprintf ppf "@ \"%s\"" s) sl + } ] + in + fprintf ppf "@[<2>%s %a :@ %a%a@]" kwd value_ident name + Toploop.print_out_type.val ty pr_prims prims ] + +and print_out_type_decl kwd ppf (name, args, ty, priv, constraints) = + let constrain ppf (ty, ty') = + fprintf ppf "@ @[<2>constraint %a =@ %a@]" Toploop.print_out_type.val ty + Toploop.print_out_type.val ty' + in + let print_constraints ppf params = List.iter (constrain ppf) params in + let type_defined ppf = + match args with + [ [] -> fprintf ppf "%s" name + | [arg] -> fprintf ppf "%s %a" name type_parameter arg + | _ -> + fprintf ppf "%s@ %a" name + (print_list type_parameter (fun ppf -> fprintf ppf "@ ")) args ] + and print_kind ppf ty = + fprintf ppf "%s@ %a" + (if priv = Obj.magic Camlp4_import.Asttypes.Private then " private" else "") + Toploop.print_out_type.val ty + in + let print_types ppf = fun + [ Otyp_manifest ty1 ty2 -> + fprintf ppf "@ @[<2>%a ==%a@]" + Toploop.print_out_type.val ty1 + print_kind ty2 + | ty -> print_kind ppf ty ] + in + fprintf ppf "@[<2>@[@[%s %t@] =%a@]%a@]" kwd type_defined + print_types ty print_constraints constraints +; + +(* Phrases *) + +value print_out_exception ppf exn outv = + match exn with + [ Sys.Break -> fprintf ppf "Interrupted.@." + | Out_of_memory -> fprintf ppf "Out of memory during evaluation.@." + | Stack_overflow -> + fprintf ppf "Stack overflow during evaluation (looping recursion?).@." + | _ -> + fprintf ppf "@[Exception:@ %a.@]@." Toploop.print_out_value.val outv ] +; + +value rec print_items ppf = + fun + [ [] -> () + | [(tree, valopt) :: items] -> + do { + match valopt with + [ Some v -> + fprintf ppf "@[<2>%a =@ %a@]" Toploop.print_out_sig_item.val tree + Toploop.print_out_value.val v + | None -> fprintf ppf "@[%a@]" Toploop.print_out_sig_item.val tree ]; + if items <> [] then fprintf ppf "@ %a" print_items items else () + } ] +; + +value print_out_phrase ppf = + fun + [ Ophr_eval outv ty -> + fprintf ppf "@[- : %a@ =@ %a@]@." Toploop.print_out_type.val ty + Toploop.print_out_value.val outv + | Ophr_signature [] -> () + | Ophr_signature items -> fprintf ppf "@[%a@]@." print_items items + | Ophr_exception (exn, outv) -> print_out_exception ppf exn outv ] +; + +Toploop.print_out_value.val := print_out_value; +Toploop.print_out_type.val := print_out_type; +Toploop.print_out_class_type.val := print_out_class_type; +Toploop.print_out_module_type.val := print_out_module_type; +Toploop.print_out_sig_item.val := print_out_sig_item; +Toploop.print_out_signature.val := print_out_signature; +Toploop.print_out_phrase.val := print_out_phrase; diff --git a/camlp4/Camlp4Top/Top.ml b/camlp4/Camlp4Top/Top.ml new file mode 100644 index 0000000..4bb92bd --- /dev/null +++ b/camlp4/Camlp4Top/Top.ml @@ -0,0 +1,147 @@ +(* camlp4r q_MLast.cmo *) +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002-2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + + +(* There is a few Obj.magic due to the fact that we no longer have compiler + files like Parsetree, Location, Longident but Camlp4_import that wrap them to + avoid name clashing. *) +module Toploop : sig + value print_location : + Format.formatter -> Camlp4_import.Location.t -> unit; + value print_warning : + Camlp4_import.Location.t -> Format.formatter -> Camlp4_import.Warnings.t -> unit; + value parse_toplevel_phrase : + ref (Lexing.lexbuf -> Camlp4_import.Parsetree.toplevel_phrase); + value parse_use_file : + ref (Lexing.lexbuf -> list Camlp4_import.Parsetree.toplevel_phrase); +end = struct + value print_location fmt loc = + Toploop.print_location fmt (Obj.magic loc); + value parse_toplevel_phrase = + Obj.magic Toploop.parse_toplevel_phrase; + value parse_use_file = + Obj.magic Toploop.parse_use_file; + value print_warning loc fmt w = + Toploop.print_warning (Obj.magic loc) fmt (Obj.magic w); +end; + +open Camlp4_import.Parsetree; +open Lexing; +open Camlp4; +open PreCast; +open Syntax; +open Camlp4.Sig; +module Ast2pt = Camlp4.Struct.Camlp4Ast2OCamlAst.Make Ast; +module Lexer = Camlp4.Struct.Lexer.Make Token; + +external not_filtered : 'a -> Gram.not_filtered 'a = "%identity"; + +value initialization = lazy begin + if Sys.interactive.val + then Format.printf "\tCamlp4 Parsing version %s\n@." Camlp4_config.version + else () +end; + +value lookup x xs = try Some (List.assq x xs) with [ Not_found -> None ]; + +value wrap parse_fun = + let token_streams = ref [] in + let cleanup lb = + try token_streams.val := List.remove_assq lb token_streams.val + with [ Not_found -> () ] + in + fun lb -> + let () = Lazy.force initialization in + let () = Register.iter_and_take_callbacks (fun (_, f) -> f ()) in + let token_stream = + match lookup lb token_streams.val with + [ None -> + let not_filtered_token_stream = Lexer.from_lexbuf lb in + let token_stream = Gram.filter (not_filtered not_filtered_token_stream) in + do { token_streams.val := [ (lb,token_stream) :: token_streams.val ]; token_stream } + | Some token_stream -> token_stream ] + in try + match token_stream with parser + [ [: `(EOI, _) :] -> raise End_of_file + | [: :] -> parse_fun token_stream ] + with + [ End_of_file | Sys.Break | (Loc.Exc_located _ (End_of_file | Sys.Break)) + as x -> (cleanup lb; raise x) + | x -> + let x = + match x with + [ Loc.Exc_located loc x -> do { + Toploop.print_location Format.err_formatter + (Loc.to_ocaml_location loc); + x } + | x -> x ] + in + do { + cleanup lb; + Format.eprintf "@[<0>%a@]@." Camlp4.ErrorHandler.print x; + raise Exit + } ]; + +value toplevel_phrase token_stream = + match Gram.parse_tokens_after_filter Syntax.top_phrase token_stream with + [ Some str_item -> + let str_item = + AstFilters.fold_topphrase_filters (fun t filter -> filter t) str_item + in + Ast2pt.phrase str_item + + | None -> raise End_of_file ]; + +value use_file token_stream = + let (pl0, eoi) = + loop () where rec loop () = + let (pl, stopped_at_directive) = + Gram.parse_tokens_after_filter Syntax.use_file token_stream + in + if stopped_at_directive <> None then + match pl with + [ [ <:str_item< #load $str:s$ >> ] -> + do { Topdirs.dir_load Format.std_formatter s; loop () } + | [ <:str_item< #directory $str:s$ >> ] -> + do { Topdirs.dir_directory s; loop () } + | _ -> (pl, False) ] + else (pl, True) + in + let pl = + if eoi then [] + else + loop () where rec loop () = + let (pl, stopped_at_directive) = + Gram.parse_tokens_after_filter Syntax.use_file token_stream + in + if stopped_at_directive <> None then pl @ loop () else pl + in List.map Ast2pt.phrase (pl0 @ pl); + +Toploop.parse_toplevel_phrase.val := wrap toplevel_phrase; + +Toploop.parse_use_file.val := wrap use_file; + +current_warning.val := + fun loc txt -> + Toploop.print_warning (Loc.to_ocaml_location loc) Format.err_formatter + (Camlp4_import.Warnings.Camlp4 txt); + +Register.iter_and_take_callbacks (fun (_, f) -> f ()); diff --git a/camlp4/Camlp4_config.ml b/camlp4/Camlp4_config.ml new file mode 100644 index 0000000..8eb1915 --- /dev/null +++ b/camlp4/Camlp4_config.ml @@ -0,0 +1,39 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +let ocaml_standard_library = Camlp4_import.Config.standard_library;; + +let camlp4_standard_library = + try Sys.getenv "CAMLP4LIB" + with Not_found -> + Filename.concat ocaml_standard_library "camlp4";; + +let version = Sys.ocaml_version;; +let program_name = ref "camlp4";; +let constructors_arity = ref true;; +let unsafe = ref false;; +let verbose = ref false;; +let antiquotations = ref false;; +let quotations = ref true;; +let inter_phrases = ref None;; +let camlp4_ast_impl_magic_number = "Camlp42006M001";; +let camlp4_ast_intf_magic_number = "Camlp42006N001";; +let ocaml_ast_intf_magic_number = Camlp4_import.Config.ast_intf_magic_number;; +let ocaml_ast_impl_magic_number = Camlp4_import.Config.ast_impl_magic_number;; +let current_input_file = ref "";; diff --git a/camlp4/Camlp4_config.mli b/camlp4/Camlp4_config.mli new file mode 100644 index 0000000..1759208 --- /dev/null +++ b/camlp4/Camlp4_config.mli @@ -0,0 +1,34 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + +val version : string;; +val ocaml_standard_library : string;; +val camlp4_standard_library : string;; +val ocaml_ast_impl_magic_number : string;; +val ocaml_ast_intf_magic_number : string;; +val camlp4_ast_impl_magic_number : string;; +val camlp4_ast_intf_magic_number : string;; +val program_name : string ref;; +val unsafe : bool ref;; +val verbose : bool ref;; +val quotations : bool ref;; +val antiquotations : bool ref;; +val constructors_arity : bool ref;; +val inter_phrases : (string option) ref;; +val current_input_file : string ref;; diff --git a/camlp4/ICHANGES b/camlp4/ICHANGES new file mode 100644 index 0000000..809a65a --- /dev/null +++ b/camlp4/ICHANGES @@ -0,0 +1,27 @@ +Internal, very small, undocumented, or invisible changes +******************************************************** + +- [april-may 04] the following interface files changed in order to + implement OCaml style locations: + camlp4/camlp4/{ast2pt.mli,pcaml.mli,reloc.mli,grammar.mli} + camlp4/lib/{stdpp.mli,token.mli} + The main changes are occurrences of "int" changed into + "Lexing.position" and "int * int" changed into + "Lexing.position * Lexing.position" (or an equivalent type). +- [20 nov 03], token.mli: eval_string takes a location as a extra + argument (needed to issue a warning). + +Camlp4s Version 3.06+19 +----------------------- + +- [28 Oct 02] Changed and simplified local entry of pa_o.ml from "cvalue" + to "cvalue_binding". +- [18 Oct 02] The standard syntax for antiquotations in object class_types + and object class_expr are now: <:class_type< $opt:x$ $list:y$ >> and + <:class_expr< $opt:x$ $list:y$ >>: the syntax without the "opt" is + accepted but deprecated (a warning is displayed). +- [15 Oct 02] Changed Plexer which now manages better the line directives + (applied only on begin of lines, no error if parsing error in the + directive). +- [14 Sep 02] Grammar.print_entry does not end any more with + Format.print_flush. The "flush" is done by Grammar.Entry.print. diff --git a/camlp4/Makefile b/camlp4/Makefile new file mode 100644 index 0000000..8686e25 --- /dev/null +++ b/camlp4/Makefile @@ -0,0 +1,99 @@ +######################################################################### +# # +# Objective Caml # +# # +# Nicolas Pouillard, projet Gallium, INRIA Rocquencourt # +# # +# Copyright 2006 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + + + +# RELEASE NOTE: +# Do not forget to call make genclean to update Makefile.clean before a +# release. + +OCAMLC=../boot/ocamlrun ../ocamlc -nostdlib \ + -I ../stdlib -I ../otherlibs/unix -I ../otherlibs/win32unix -I build -g +OCAMLRUN=../boot/ocamlrun -I ../otherlibs/unix -I ../otherlibs/win32unix +YAM=$(OCAMLRUN) ./yam +YAM_OPTIONS=-verbosity '$(VERBOSE)' + +default: all + +opt install doc all pack just_doc: yam + @echo 'YAM $@ (use "make $@ VERBOSE=1" for a verbose make)' + @$(YAM) $(YAM_OPTIONS) $@ + +smartclean:: + if test -x ../boot/ocamlrun; then \ + if test -x ../ocaml; then \ + $(OCAML) build/build.ml -clean; \ + else \ + if test -x ./yam; then \ + $(YAM) $(YAM_OPTIONS) -clean; \ + else \ + $(MAKE) staticclean; \ + fi; \ + fi; \ + else \ + rm -f $(CLEANFILES); \ + fi + +genclean: yam + $(YAM) -genclean Makefile.clean + (echo /Camlp4Ast.ml/d; echo w; echo q) | ed Makefile.clean + +clean:: + rm -f yam .cache-status + rm -f $(CLEANFILES) + rm -f *.cm[io] build/*.cm[io] + +YAM_OBJS=build/YaM.cmo build/camlp4_config.cmo Makefile.cmo + +yam: $(YAM_OBJS) + $(OCAMLC) -o yam unix.cma $(YAM_OBJS) + +.SUFFIXES: .mli .ml .cmi .cmo + +.mli.cmi: + $(OCAMLC) -c $*.mli +.ml.cmo: + $(OCAMLC) -c $*.ml + +build/YaM.cmo: build/YaM.cmi +Makefile.cmo: build/YaM.cmi build/camlp4_config.cmo + +uninstall: + rm -rf "$(LIBDIR)/camlp4" + cd "$(BINDIR)"; rm -f *camlp4* + +depend: + +# Normal bootstrap + +bootstrap: backup promote clean all compare +bootstrap-debug: backup promote-debug clean all compare + +backup restore boot-clean:: + cd boot && $(MAKE) $@ + +promote-debug: + cp camlp4boot-debug.run boot/camlp4boot + +promote: + cp camlp4boot.run boot/camlp4boot + +compare: + @if (cmp camlp4boot.run boot/camlp4boot); \ + then echo "Fixpoint reached, bootstrap succeeded."; \ + else echo "Fixpoint not reached, try one more bootstrapping cycle."; \ + fi + +.PHONY: clean install all uninstall backup restore boot-clean promote-debug \ + promote compare opt doc smartclean depend + +include Makefile.clean diff --git a/camlp4/Makefile.ml b/camlp4/Makefile.ml new file mode 100644 index 0000000..543c9f1 --- /dev/null +++ b/camlp4/Makefile.ml @@ -0,0 +1,359 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Nicolas Pouillard: initial version + *) +open YaM +open Format + +let getenv var default = + try Sys.getenv var + with Not_found -> + default + +let libdir_camlp4 = (getenv "LIBDIR" Camlp4_config.libdir) ^ "/camlp4/." + +let bindir = (getenv "BINDIR" Camlp4_config.bindir) ^ "/." + +(** +let unixlib = + match Sys.os_type with + | "Win32" -> "../otherlibs/win32unix" + | _ -> "../otherlibs/unix" +**) +let ocamlrun = "../boot/ocamlrun" (* " -I " ^ unixlib *) +let ocamlrun_os = + Filename.concat Filename.parent_dir_name + (Filename.concat "boot" "ocamlrun") +(* ^ " -I " ^ unixlib *) + +let ocaml = ocamlrun ^ " ../ocaml -I ../stdlib" (* "-I " ^ unixlib *) + +let debug_mode = + (* true *) + false + +let camlp4_modules = + [ + ocamlrun_os; + "./boot/camlp4boot"; + ] +let camlp4_modules = + if debug_mode then "env STATIC_CAMLP4_DEBUG=\\*" :: camlp4_modules + else camlp4_modules + +let debug_opt x = if debug_mode && Sys.file_exists x then [x] else [] +let filter_opt x = if Sys.file_exists x then [x] else [] + +let camlp4boot = "'" ^ String.concat " " camlp4_modules ^ "'" +let camlp4boot_may_debug mods = + let camlp4_modules = camlp4_modules @ + debug_opt "./boot/ExceptionTracer.cmo" @ + filter_opt "./boot/Profiler.cmo" @ mods + in "'" ^ String.concat " " camlp4_modules ^ "'" + +let ocamlc = + best ["../ocamlc.opt", "../ocamlc.opt"; + "../ocamlc", ocamlrun ^^ "../ocamlc"; + "", "echo no byte compiler available && false"] +let ocamlopt = + best ["../ocamlopt.opt", "../ocamlopt.opt"; + "../ocamlopt", ocamlrun ^^ "../ocamlopt"; + "", "echo no native compiler available && false"] + +let () = + !options.ocamlc := ocamlc ^^ " -nostdlib -I ../stdlib"; + !options.ocamlopt := ocamlopt ^^ " -nostdlib -I ../stdlib"; + !options.ocamldoc := ocamlrun ^^ "../ocamldoc/ocamldoc"; + !options.ocamlyacc := ocamlrun ^^ "../boot/ocamlyacc"; + !options.ocamllex := ocamlrun ^^ "../boot/ocamllex"; + !options.ocamldep := ocamlrun ^^ "../tools/ocamldep"; + () + +let options_without_camlp4 = new_scope (lazy !options) + +let windows = Sys.os_type = "Win32" + +let may_define_unix = if windows then [] else ["-D UNIX"] + +let () = + !options.ocaml_Flags ^= "-w Ale -warn-error Ale"^^ + (if getenv "DTYPES" "" <> "" then "-dtypes" + else ""); + !options.ocaml_P4 := camlp4boot_may_debug may_define_unix; + !options.ocaml_P4_opt := camlp4boot_may_debug ("-D OPT" :: may_define_unix); + () + +let options_without_debug () = { (!options) with ocaml_P4 = ref camlp4boot + ; ocaml_P4_opt = ref camlp4boot } + +let parsing = "../parsing" +and typing = "../typing" +and toplevel = "../toplevel" +and utils = "../utils" +and dynlink = "../otherlibs/dynlink" +and unix = + match Sys.os_type with + | "Win32" -> "../otherlibs/win32unix" + | _ -> "../otherlibs/unix" +and build = "build" + +let ocaml_Module_with_genmap = + generic_ocaml_Module_extension ".genmap.ml" + (fun _ i o -> + "if test ! -e"^^o^^ + "|| ( test -e ./camlp4boot.run"^^ + "&& test -e Camlp4Filters/GenerateMap.cmo"^^ + "&& test -e Camlp4Filters/GenerateFold.cmo"^^ + "&& test -e Camlp4Filters/MetaGenerator.cmo"^^ + "&& test -e Camlp4Filters/RemoveTrashModule.cmo ) ;"^^ + "then ( echo 'module Camlp4FiltersTrash = struct' ;"^^ + "cat Camlp4/Sig/Camlp4Ast.ml ; echo 'end;' ) > Camlp4/Struct/Camlp4Ast.tmp.ml ;"^^ + "( echo '(* Generated file! Do not edit by hand *)' ;"^^ + "../boot/ocamlrun ./camlp4boot.run"^^ + "./Camlp4Filters/GenerateMap.cmo"^^ + "./Camlp4Filters/GenerateFold.cmo"^^ + "./Camlp4Filters/MetaGenerator.cmo"^^ + "./Camlp4Filters/RemoveTrashModule.cmo -printer OCamlr"^^ + i^^" -no_comments ) >"^^o^^"; else : ; fi") + +let camlp4_package_as_one_dir = + ocaml_PackageDir "Camlp4" (lazy [ + ocaml_IModule ~includes:[build] "Config"; + ocaml_IModule ~o:(options_without_debug ()) "Debug"; + ocaml_IModule "Options"; + ocaml_PackageDir "Sig" (lazy [ + ocaml_Interface "Id"; + ocaml_Interface ~ext_includes:[parsing] "Loc"; + ocaml_Interface "Error"; + ocaml_Interface "Warning"; + ocaml_Interface "Type"; + ocaml_Interface "Token"; + ocaml_Interface "Lexer"; + ocaml_PackageDir "Grammar" (lazy [ + ocaml_Interface "Action"; + ocaml_Interface "Structure"; + ocaml_Interface "Dynamic"; + ocaml_Interface "Static" + ]); + ocaml_IModule "Mapper"; + ocaml_Interface "Ast"; + ocaml_Module "Camlp4Ast"; + ocaml_Interface "Quotation"; + ocaml_Interface "Camlp4Token"; + ocaml_Interface "DynLoader"; + ocaml_Interface "AntiquotSyntax"; + ocaml_Interface "Parser"; + ocaml_Interface "Printer"; + ocaml_Interface "Syntax"; + ocaml_Interface "Camlp4Syntax"; + ocaml_Interface "AstFilters"; + ocaml_Interface "SyntaxExtension"; + ]); + ocaml_IModule "ErrorHandler"; + ocaml_PackageDir "Struct" (lazy [ + ocaml_IModule ~ext_includes:[parsing] "Loc"; + ocaml_Module "Warning"; + ocaml_IModule "EmptyError"; + ocaml_IModule "EmptyPrinter"; + ocaml_IModule "Token"; + ocaml_Lexer ~includes:[utils] ~ext_includes:[parsing] ~pp:"" "Lexer"; + ocaml_PackageDir "Grammar" (lazy [ + ocaml_Module "Context"; + ocaml_Module "Structure"; + ocaml_Module "Search"; + ocaml_Module "Tools"; + ocaml_IModule "Print"; + ocaml_Module "Failed"; + ocaml_Module "Parser"; + ocaml_IModule "Fold"; + ocaml_Module "Insert"; + ocaml_Module "Delete"; + ocaml_Module "Entry"; + ocaml_Module "Find"; + ocaml_Module "Dynamic"; + ocaml_Module "Static" + ]); + ocaml_Module "Quotation"; + ocaml_IModule ~ext_includes:[dynlink] "DynLoader"; + ocaml_Module_with_genmap ~flags:"-w z -warn-error z" "Camlp4Ast"; + ocaml_IModule "FreeVars"; + ocaml_Module "AstFilters"; + ocaml_IModule ~ext_includes:[parsing] "Camlp4Ast2OCamlAst"; + ocaml_Module "CleanAst"; + ocaml_IModule "CommentFilter"; + ]); + ocaml_Module "OCamlInitSyntax"; + ocaml_PackageDir "Printers" (lazy [ + ocaml_IModule "Null"; + ocaml_IModule "DumpOCamlAst"; + ocaml_IModule "DumpCamlp4Ast"; + ocaml_IModule "OCaml"; + ocaml_IModule "OCamlr" ~flags:"-w v -warn-error v"; + (* ocaml_IModule "OCamlrr"; *) + ]); + ocaml_IModule "PreCast"; + ocaml_IModule "Register" + ]) + +let camlp4_parsers = + ocaml_PackageDir "Camlp4Parsers" (lazy [ + ocaml_Module "OCamlr"; + ocaml_Module "OCaml"; + (* ocaml_Module "OCamlrr"; *) + ocaml_Module "OCamlQuotationBase"; + ocaml_Module "OCamlQuotation"; + ocaml_Module "OCamlRevisedQuotation"; + ocaml_Module "OCamlOriginalQuotation"; + ocaml_Module "OCamlRevisedParser"; + ocaml_Module "OCamlParser"; + ocaml_Module "Grammar"; + ocaml_Module "Macro"; + ocaml_Module ~o:(options_without_debug ()) "Debug"; + ocaml_Module "LoadCamlp4Ast"; + ]) + +let camlp4_printers = + ocaml_PackageDir "Camlp4Printers" (lazy [ + ocaml_Module "DumpOCamlAst"; + ocaml_Module "DumpCamlp4Ast"; + ocaml_Module "OCaml"; + ocaml_Module "OCamlr"; + (* ocaml_Module "OCamlrr"; *) + ocaml_Module "Null"; + ocaml_Module ~ext_includes:[unix] "Auto"; + ]) + +let camlp4_filters = + ocaml_PackageDir "Camlp4Filters" (lazy [ + ocaml_Module "ExceptionTracer"; + ocaml_Module "Tracer"; + ocaml_Module "StripLocations"; + ocaml_Module "LiftCamlp4Ast"; + ocaml_Module "GenerateMap"; + ocaml_Module "GenerateFold"; + ocaml_Module "MetaGenerator"; + ocaml_Module "RemoveTrashModule"; + ocaml_Module "Profiler"; + ]) + +let camlp4_top = + ocaml_PackageDir "Camlp4Top" (lazy [ + ocaml_Module ~ext_includes:[toplevel; typing; parsing] "Rprint"; + ocaml_Module ~ext_includes:[toplevel; parsing; utils] "Camlp4Top"; + ]) + +let split c s = + let rec self acc s = + try + let pos = String.rindex s c in + let x = String.sub s 0 pos + and y = String.sub s (pos + 1) (String.length s - pos - 1) + in self (y :: acc) x + with Not_found -> s :: acc + in self [] s +let chop_end c s = + let pos = String.rindex s c in + String.sub s (pos + 1) (String.length s - pos - 1) +let file ppf f = + let cin = open_in f in + let rec loop () = + pp_print_string ppf (input_line cin); + fprintf ppf "@\n"; + loop () + in try loop () with End_of_file -> () +let ext_split f = split '.' f + + +let print_packed_sources ppf ?(skip = fun _ -> false) package_dir = + let _ = + fold_units_sources [package_dir] (fun name sources k (skip, inside) -> + eprintf "%s: [%s] (%b)@." name (String.concat "; " sources) inside; + let name = try chop_end '/' name with Not_found -> name in + let k () = ignore (k (skip, true)) in + if not inside then k () else ( + if skip name then fprintf ppf "(**/**)@\n" else fprintf ppf "(** *)@\n"; + fprintf ppf "@[<2>module %s " name; + let (mli, ml, mll, k) = + List.fold_right + (fun x (mli, ml, mll, k) -> + match ext_split x with + | [_; "mli"] -> (Some x, ml, mll, k) + | [_; "ml"] -> (mli, Some x, mll, k) + | [_; "mll"] -> (mli, ml, Some x, k) + | [x; "meta"; "ml"] -> (mli, Some (x^".ml"), mll, fun () -> ()) + | [x; "genmap"; "ml"] -> (mli, Some (x^".ml"), mll, fun () -> ()) + | [_; ext] -> failwith ("unknown extension " ^ ext) + | _ -> failwith ("bad file "^x)) + sources (None, None, None, k) in + (match (ml, mll, mli) with + | (None, None, Some mli) -> fprintf ppf "=@ @[<2>struct@\n" + | (_, _, Some mli) -> fprintf ppf ":@,@[<2>sig@\n%a@]@\nend@\n" file mli; + fprintf ppf "=@ @[<2>struct@\n" + | _ -> fprintf ppf "=@ @[<2>struct@\n"); + (match (ml, mll, mli) with + | (_, Some mll, _) -> + fprintf ppf "(*___CAMLP4_LEXER___ %a ___CAMLP4_LEXER___*)@\n();" + file (String.sub mll 0 (String.length mll - 1)) + | (Some ml, _, _) -> k (); fprintf ppf "%a" file ml + | (None, _, Some mli) -> k (); fprintf ppf "%a" file mli + | _ -> if sources <> [] then () else k ()); + fprintf ppf "@]@\nend;@]@\n"; + if skip name then fprintf ppf "(**/**)@\n"; + ); + (skip, inside) + ) (skip, false) in fprintf ppf "@." + +let run l = + let cmd = String.concat " " l in + let () = Format.printf "%s@." cmd in + let st = YaM.call cmd in + if st <> 0 then failwith ("Exit: " ^ string_of_int st) + +let sed re str file = + run ["sed"; "-i"; "-e"; "'s/"^re^"/"^str^"/'"; file] + +let pack () = + let revised_to_ocaml f = + run ["./boot/camlp4boot -printer OCaml -o "^f^".ml -impl "^f^".ml4"] in + let ppf_of_file f = formatter_of_out_channel (open_out f) in + let skip_struct = function "Struct" -> true | _ -> false in + print_packed_sources (ppf_of_file "Camlp4.ml4") + ~skip:skip_struct camlp4_package_as_one_dir; + print_packed_sources (ppf_of_file "Camlp4Parsers.ml4") camlp4_parsers; + print_packed_sources (ppf_of_file "Camlp4Printers.ml4") camlp4_printers; + print_packed_sources (ppf_of_file "Camlp4Filters.ml4") camlp4_filters; + print_packed_sources (ppf_of_file "Camlp4Top.ml4") camlp4_top; + revised_to_ocaml "Camlp4"; + sed "(\\*___CAMLP4_LEXER___" "" "Camlp4.ml"; + sed "___CAMLP4_LEXER___\\*)" "" "Camlp4.ml"; + sed "^ *# [0-9]\\+.*$" "" "Camlp4.ml"; + revised_to_ocaml "Camlp4Parsers"; + revised_to_ocaml "Camlp4Printers"; + revised_to_ocaml "Camlp4Filters"; + revised_to_ocaml "Camlp4Top" + +let just_doc () = + run ["cd doc && ../../ocamldoc/ocamldoc"; + "-v -short-functors -html"; + "-I ../../parsing -I ../build -I ../../utils -I .."; + "-dump ocamldoc.out"; + "-t 'Camlp4 a Pre-Processor-Pretty-Printer for Objective Caml'"; + "../Camlp4.ml"; "../Camlp4Parsers.ml"; "../Camlp4Printers.ml"; + "../Camlp4Filters.ml"; "../Camlp4Top.ml"] + +let doc () = + pack (); just_doc () + diff --git a/camlp4/boot/.cvsignore b/camlp4/boot/.cvsignore new file mode 100644 index 0000000..85599a4 --- /dev/null +++ b/camlp4/boot/.cvsignore @@ -0,0 +1,5 @@ +*.cm[oia] +camlp4 +camlp4o +camlp4r +SAVED diff --git a/camlp4/boot/Camlp4.ml b/camlp4/boot/Camlp4.ml new file mode 100644 index 0000000..ea3f335 --- /dev/null +++ b/camlp4/boot/Camlp4.ml @@ -0,0 +1,20570 @@ +module Debug : + sig + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + (* camlp4r *) + type section = string + + val mode : section -> bool + + val printf : section -> ('a, Format.formatter, unit) format -> 'a + + end = + struct + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + (* camlp4r *) + open Format + + module Debug = struct let mode _ = false + end + + type section = string + + let out_channel = + try + let f = Sys.getenv "CAMLP4_DEBUG_FILE" + in + open_out_gen [ Open_wronly; Open_creat; Open_append; Open_text ] + 0o666 f + with | Not_found -> stderr + + module StringSet = Set.Make(String) + + let mode = + try + let str = Sys.getenv "CAMLP4_DEBUG" in + let rec loop acc i = + try + let pos = String.index_from str i ':' + in + loop (StringSet.add (String.sub str i (pos - i)) acc) (pos + 1) + with + | Not_found -> + StringSet.add (String.sub str i ((String.length str) - i)) acc in + let sections = loop StringSet.empty 0 + in + if StringSet.mem "*" sections + then (fun _ -> true) + else (fun x -> StringSet.mem x sections) + with | Not_found -> (fun _ -> false) + + let formatter = + let header = "camlp4-debug: " in + let normal s = + let rec self from accu = + try + let i = String.index_from s from '\n' + in self (i + 1) ((String.sub s from ((i - from) + 1)) :: accu) + with + | Not_found -> + (String.sub s from ((String.length s) - from)) :: accu + in String.concat header (List.rev (self 0 [])) in + let after_new_line str = header ^ (normal str) in + let f = ref after_new_line in + let output str chr = + (output_string out_channel (!f str); + output_char out_channel chr; + f := if chr = '\n' then after_new_line else normal) + in + make_formatter + (fun buf pos len -> + let p = pred len in output (String.sub buf pos p) buf.[pos + p]) + (fun () -> flush out_channel) + + let printf section fmt = fprintf formatter ("%s: " ^^ fmt) section + + end + +module Options : + sig + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + type spec_list = (string * Arg.spec * string) list + + val init : spec_list -> unit + + val add : string -> Arg.spec -> string -> unit + + (** Add an option to the command line options. *) + val print_usage_list : spec_list -> unit + + val ext_spec_list : unit -> spec_list + + val parse : (string -> unit) -> string array -> string list + + end = + struct + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + type spec_list = (string * Arg.spec * string) list + + open Format + + let rec action_arg s sl = + function + | Arg.Unit f -> if s = "" then (f (); Some sl) else None + | Arg.Bool f -> + if s = "" + then + (match sl with + | s :: sl -> + (try (f (bool_of_string s); Some sl) + with | Invalid_argument "bool_of_string" -> None) + | [] -> None) + else + (try (f (bool_of_string s); Some sl) + with | Invalid_argument "bool_of_string" -> None) + | Arg.Set r -> if s = "" then (r := true; Some sl) else None + | Arg.Clear r -> if s = "" then (r := false; Some sl) else None + | Arg.Rest f -> (List.iter f (s :: sl); Some []) + | Arg.String f -> + if s = "" + then (match sl with | s :: sl -> (f s; Some sl) | [] -> None) + else (f s; Some sl) + | Arg.Set_string r -> + if s = "" + then (match sl with | s :: sl -> (r := s; Some sl) | [] -> None) + else (r := s; Some sl) + | Arg.Int f -> + if s = "" + then + (match sl with + | s :: sl -> + (try (f (int_of_string s); Some sl) + with | Failure "int_of_string" -> None) + | [] -> None) + else + (try (f (int_of_string s); Some sl) + with | Failure "int_of_string" -> None) + | Arg.Set_int r -> + if s = "" + then + (match sl with + | s :: sl -> + (try (r := int_of_string s; Some sl) + with | Failure "int_of_string" -> None) + | [] -> None) + else + (try (r := int_of_string s; Some sl) + with | Failure "int_of_string" -> None) + | Arg.Float f -> + if s = "" + then + (match sl with + | s :: sl -> (f (float_of_string s); Some sl) + | [] -> None) + else (f (float_of_string s); Some sl) + | Arg.Set_float r -> + if s = "" + then + (match sl with + | s :: sl -> (r := float_of_string s; Some sl) + | [] -> None) + else (r := float_of_string s; Some sl) + | Arg.Tuple specs -> + let rec action_args s sl = + (function + | [] -> Some sl + | spec :: spec_list -> + (match action_arg s sl spec with + | None -> action_args "" [] spec_list + | Some (s :: sl) -> action_args s sl spec_list + | Some sl -> action_args "" sl spec_list)) + in action_args s sl specs + | Arg.Symbol (syms, f) -> + (match if s = "" then sl else s :: sl with + | s :: sl when List.mem s syms -> (f s; Some sl) + | _ -> None) + + let common_start s1 s2 = + let rec loop i = + if (i == (String.length s1)) || (i == (String.length s2)) + then i + else if s1.[i] == s2.[i] then loop (i + 1) else i + in loop 0 + + let parse_arg fold s sl = + fold + (fun (name, action, _) acu -> + let i = common_start s name + in + if i == (String.length name) + then + (try + action_arg (String.sub s i ((String.length s) - i)) sl + action + with | Arg.Bad _ -> acu) + else acu) + None + + let rec parse_aux fold anon_fun = + function + | [] -> [] + | s :: sl -> + if ((String.length s) > 1) && (s.[0] = '-') + then + (match parse_arg fold s sl with + | Some sl -> parse_aux fold anon_fun sl + | None -> s :: (parse_aux fold anon_fun sl)) + else ((anon_fun s : unit); parse_aux fold anon_fun sl) + + let align_doc key s = + let s = + let rec loop i = + if i = (String.length s) + then "" + else + if s.[i] = ' ' + then loop (i + 1) + else String.sub s i ((String.length s) - i) + in loop 0 in + let (p, s) = + if (String.length s) > 0 + then + if s.[0] = '<' + then + (let rec loop i = + if i = (String.length s) + then ("", s) + else + if s.[i] <> '>' + then loop (i + 1) + else + (let p = String.sub s 0 (i + 1) in + let rec loop i = + if i >= (String.length s) + then (p, "") + else + if s.[i] = ' ' + then loop (i + 1) + else (p, (String.sub s i ((String.length s) - i))) + in loop (i + 1)) + in loop 0) + else ("", s) + else ("", "") in + let tab = + String.make (max 1 ((16 - (String.length key)) - (String.length p))) + ' ' + in p ^ (tab ^ s) + + let make_symlist l = + match l with + | [] -> "" + | h :: t -> + (List.fold_left (fun x y -> x ^ ("|" ^ y)) ("{" ^ h) t) ^ "}" + + let print_usage_list l = + List.iter + (fun (key, spec, doc) -> + match spec with + | Arg.Symbol (symbs, _) -> + let s = make_symlist symbs in + let synt = key ^ (" " ^ s) + in eprintf " %s %s\n" synt (align_doc synt doc) + | _ -> eprintf " %s %s\n" key (align_doc key doc)) + l + + let remaining_args argv = + let rec loop l i = + if i == (Array.length argv) then l else loop (argv.(i) :: l) (i + 1) + in List.rev (loop [] (!Arg.current + 1)) + + let init_spec_list = ref [] + + let ext_spec_list = ref [] + + let init spec_list = init_spec_list := spec_list + + let add name spec descr = + ext_spec_list := (name, spec, descr) :: !ext_spec_list + + let fold f init = + let spec_list = !init_spec_list @ !ext_spec_list in + let specs = Sort.list (fun (k1, _, _) (k2, _, _) -> k1 >= k2) spec_list + in List.fold_right f specs init + + let parse anon_fun argv = + let remaining_args = remaining_args argv + in parse_aux fold anon_fun remaining_args + + let ext_spec_list () = !ext_spec_list + + end + +module Sig = + struct + (* camlp4r *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + (** Camlp4 signature repository *) + (** {6 Basic signatures} *) + (** Signature with just a type. *) + module type Type = sig type t + end + + (** Signature for errors modules, an Error modules can be registred with + the {!ErrorHandler.Register} functor in order to be well printed. *) + module type Error = + sig + type t + + exception E of t + + val to_string : t -> string + + val print : Format.formatter -> t -> unit + + end + + (** A signature for extensions identifiers. *) + module type Id = + sig + (** The name of the extension, typically the module name. *) + val name : string + + (** The version of the extension, typically $ Id$ with a versionning system. *) + val version : string + + end + + (** A signature for warnings abstract from locations. *) + module Warning (Loc : Type) = + struct + module type S = + sig + type warning = Loc.t -> string -> unit + + val default_warning : warning + + val current_warning : warning ref + + val print_warning : warning + + end + + end + + (** {6 Advanced signatures} *) + (** A signature for locations. *) + module type Loc = + sig + type t + + (** Return a start location for the given file name. + This location starts at the begining of the file. *) + val mk : string -> t + + (** The [ghost] location can be used when no location + information is available. *) + val ghost : t + + (** {6 Conversion functions} *) + (** Return a location where both positions are set the given position. *) + val of_lexing_position : Lexing.position -> t + + (** Return an OCaml location. *) + val to_ocaml_location : t -> Camlp4_import.Location.t + + (** Return a location from an OCaml location. *) + val of_ocaml_location : Camlp4_import.Location.t -> t + + (** Return a location from ocamllex buffer. *) + val of_lexbuf : Lexing.lexbuf -> t + + (** Return a location from [(file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost)]. *) + val of_tuple : + (string * int * int * int * int * int * int * bool) -> t + + (** Return [(file_name, start_line, start_bol, start_off, + stop_line, stop_bol, stop_off, ghost)]. *) + val to_tuple : + t -> (string * int * int * int * int * int * int * bool) + + (** [merge loc1 loc2] Return a location that starts at [loc1] and end at [loc2]. *) + val merge : t -> t -> t + + (** The stop pos becomes equal to the start pos. *) + val join : t -> t + + (** [move selector n loc] + Return the location where positions are moved. + Affected positions are chosen with [selector]. + Returned positions have their character offset plus [n]. *) + val move : [ | `start | `stop | `both ] -> int -> t -> t + + (** [shift n loc] Return the location where the new start position is the old + stop position, and where the new stop position character offset is the + old one plus [n]. *) + val shift : int -> t -> t + + (** [move_line n loc] Return the location with the old line count plus [n]. + The "begin of line" of both positions become the current offset. *) + val move_line : int -> t -> t + + (** {6 Accessors} *) + (** Return the file name *) + val file_name : t -> string + + (** Return the line number of the begining of this location. *) + val start_line : t -> int + + (** Return the line number of the ending of this location. *) + val stop_line : t -> int + + (** Returns the number of characters from the begining of the file + to the begining of the line of location's begining. *) + val start_bol : t -> int + + (** Returns the number of characters from the begining of the file + to the begining of the line of location's ending. *) + val stop_bol : t -> int + + (** Returns the number of characters from the begining of the file + of the begining of this location. *) + val start_off : t -> int + + (** Return the number of characters from the begining of the file + of the ending of this location. *) + val stop_off : t -> int + + (** Return the start position as a Lexing.position. *) + val start_pos : t -> Lexing.position + + (** Return the stop position as a Lexing.position. *) + val stop_pos : t -> Lexing.position + + (** Generally, return true if this location does not come + from an input stream. *) + val is_ghost : t -> bool + + (** Return the associated ghost location. *) + val ghostify : t -> t + + (** Return the location with the give file name *) + val set_file_name : string -> t -> t + + (** [strictly_before loc1 loc2] True if the stop position of [loc1] is + strictly_before the start position of [loc2]. *) + val strictly_before : t -> t -> bool + + (** Return the location with an absolute file name. *) + val make_absolute : t -> t + + (** Print the location into the formatter in a format suitable for error + reporting. *) + val print : Format.formatter -> t -> unit + + (** Print the location in a short format useful for debugging. *) + val dump : Format.formatter -> t -> unit + + (** Same as {!print} but return a string instead of printting it. *) + val to_string : t -> string + + (** [Exc_located loc e] is an encapsulation of the exception [e] with + the input location [loc]. To be used in quotation expanders + and in grammars to specify some input location for an error. + Do not raise this exception directly: rather use the following + function [Loc.raise]. *) + exception Exc_located of t * exn + + (** [raise loc e], if [e] is already an [Exc_located] exception, + re-raise it, else raise the exception [Exc_located loc e]. *) + val raise : t -> exn -> 'a + + (** The name of the location variable used in grammars and in + the predefined quotations for OCaml syntax trees. Default: [_loc]. *) + val name : string ref + + end + + (** Abstract syntax tree minimal signature. + Types of this signature are abstract. + See the {!Camlp4Ast} signature for a concrete definition. *) + module type Ast = + sig + (** {6 Syntactic categories as abstract types} *) + type loc + + type meta_bool + + type 'a meta_option + + type 'a meta_list + + type ctyp + + type patt + + type expr + + type module_type + + type sig_item + + type with_constr + + type module_expr + + type str_item + + type class_type + + type class_sig_item + + type class_expr + + type class_str_item + + type match_case + + type ident + + type binding + + type rec_binding + + type module_binding + + (** {6 Location accessors} *) + val loc_of_ctyp : ctyp -> loc + + val loc_of_patt : patt -> loc + + val loc_of_expr : expr -> loc + + val loc_of_module_type : module_type -> loc + + val loc_of_module_expr : module_expr -> loc + + val loc_of_sig_item : sig_item -> loc + + val loc_of_str_item : str_item -> loc + + val loc_of_class_type : class_type -> loc + + val loc_of_class_sig_item : class_sig_item -> loc + + val loc_of_class_expr : class_expr -> loc + + val loc_of_class_str_item : class_str_item -> loc + + val loc_of_with_constr : with_constr -> loc + + val loc_of_binding : binding -> loc + + val loc_of_rec_binding : rec_binding -> loc + + val loc_of_module_binding : module_binding -> loc + + val loc_of_match_case : match_case -> loc + + val loc_of_ident : ident -> loc + + (** {6 Traversals} *) + (** This class is the base class for map traversal on the Ast. + To make a custom traversal class one just extend it like that: + + This example swap pairs expression contents: + open Camlp4.PreCast; + [class swap = object + inherit Ast.map as super; + method expr e = + match super#expr e with + \[ <:expr\@_loc< ($e1$, $e2$) >> -> <:expr< ($e2$, $e1$) >> + | e -> e \]; + end; + value _loc = Loc.ghost; + value map = (new swap)#expr; + assert (map <:expr< fun x -> (x, 42) >> = <:expr< fun x -> (42, x) >>);] + *) + class map : + object ('self_type) + method string : string -> string + + method list : + 'a 'b. ('self_type -> 'a -> 'b) -> 'a list -> 'b list + + method meta_bool : meta_bool -> meta_bool + + method meta_option : + 'a 'b. + ('self_type -> 'a -> 'b) -> 'a meta_option -> 'b meta_option + + method meta_list : + 'a 'b. ('self_type -> 'a -> 'b) -> 'a meta_list -> 'b meta_list + + method loc : loc -> loc + + method expr : expr -> expr + + method patt : patt -> patt + + method ctyp : ctyp -> ctyp + + method str_item : str_item -> str_item + + method sig_item : sig_item -> sig_item + + method module_expr : module_expr -> module_expr + + method module_type : module_type -> module_type + + method class_expr : class_expr -> class_expr + + method class_type : class_type -> class_type + + method class_sig_item : class_sig_item -> class_sig_item + + method class_str_item : class_str_item -> class_str_item + + method with_constr : with_constr -> with_constr + + method binding : binding -> binding + + method rec_binding : rec_binding -> rec_binding + + method module_binding : module_binding -> module_binding + + method match_case : match_case -> match_case + + method ident : ident -> ident + + method unknown : 'a. 'a -> 'a + + end + + (** Fold style traversal *) + class fold : + object ('self_type) + method string : string -> 'self_type + + method list : + 'a. ('self_type -> 'a -> 'self_type) -> 'a list -> 'self_type + + method meta_bool : meta_bool -> 'self_type + + method meta_option : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_option -> 'self_type + + method meta_list : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_list -> 'self_type + + method loc : loc -> 'self_type + + method expr : expr -> 'self_type + + method patt : patt -> 'self_type + + method ctyp : ctyp -> 'self_type + + method str_item : str_item -> 'self_type + + method sig_item : sig_item -> 'self_type + + method module_expr : module_expr -> 'self_type + + method module_type : module_type -> 'self_type + + method class_expr : class_expr -> 'self_type + + method class_type : class_type -> 'self_type + + method class_sig_item : class_sig_item -> 'self_type + + method class_str_item : class_str_item -> 'self_type + + method with_constr : with_constr -> 'self_type + + method binding : binding -> 'self_type + + method rec_binding : rec_binding -> 'self_type + + method module_binding : module_binding -> 'self_type + + method match_case : match_case -> 'self_type + + method ident : ident -> 'self_type + + method unknown : 'a. 'a -> 'self_type + + end + + end + + (** Signature for OCaml syntax trees. *) + (* + This signature is an extension of {!Ast} + It provides: + - Types for all kinds of structure. + - Map: A base class for map traversals. + - Map classes and functions for common kinds. + + == Core language == + ctyp :: Representaion of types + patt :: The type of patterns + expr :: The type of expressions + match_case :: The type of cases for match/function/try constructions + ident :: The type of identifiers (including path like Foo(X).Bar.y) + binding :: The type of let bindings + rec_binding :: The type of record definitions + + == Modules == + module_type :: The type of module types + sig_item :: The type of signature items + str_item :: The type of structure items + module_expr :: The type of module expressions + module_binding :: The type of recursive module definitions + with_constr :: The type of `with' constraints + + == Classes == + class_type :: The type of class types + class_sig_item :: The type of class signature items + class_expr :: The type of class expressions + class_str_item :: The type of class structure items + *) + module type Camlp4Ast = + sig + (** The inner module for locations *) + module Loc : Loc + + type loc = + Loc. + t + and meta_bool = + | BTrue | BFalse | BAnt of string + and 'a meta_option = + | ONone | OSome of 'a | OAnt of string + and 'a meta_list = + | LNil | LCons of 'a * 'a meta_list | LAnt of string + and ident = + | IdAcc of loc * ident * ident + | (* i . i *) + IdApp of loc * ident * ident + | (* i i *) + IdLid of loc * string + | (* foo *) + IdUid of loc * string + | (* Bar *) + IdAnt of loc * string + and (* $s$ *) + ctyp = + | TyNil of loc + | TyAli of loc * ctyp * ctyp + | (* t as t *) + (* list 'a as 'a *) + TyAny of loc + | (* _ *) + TyApp of loc * ctyp * ctyp + | (* t t *) + (* list 'a *) + TyArr of loc * ctyp * ctyp + | (* t -> t *) + (* int -> string *) + TyCls of loc * ident + | (* #i *) + (* #point *) + TyLab of loc * string * ctyp + | (* ~s:t *) + TyId of loc * ident + | (* i *) + (* Lazy.t *) + TyMan of loc * ctyp * ctyp + | (* t == t *) + (* type t = [ A | B ] == Foo.t *) + (* type t 'a 'b 'c = t constraint t = t constraint t = t *) + TyDcl of loc * string * ctyp list * ctyp * (ctyp * ctyp) list + | (* < (t)? (..)? > *) + (* < move : int -> 'a .. > as 'a *) + TyObj of loc * ctyp * meta_bool + | TyOlb of loc * string * ctyp + | (* ?s:t *) + TyPol of loc * ctyp * ctyp + | (* ! t . t *) + (* ! 'a . list 'a -> 'a *) + TyQuo of loc * string + | (* 's *) + TyQuP of loc * string + | (* +'s *) + TyQuM of loc * string + | (* -'s *) + TyVrn of loc * string + | (* `s *) + TyRec of loc * ctyp + | (* { t } *) + (* { foo : int ; bar : mutable string } *) + TyCol of loc * ctyp * ctyp + | (* t : t *) + TySem of loc * ctyp * ctyp + | (* t; t *) + TyCom of loc * ctyp * ctyp + | (* t, t *) + TySum of loc * ctyp + | (* [ t ] *) + (* [ A of int and string | B ] *) + TyOf of loc * ctyp * ctyp + | (* t of t *) + (* A of int *) + TyAnd of loc * ctyp * ctyp + | (* t and t *) + TyOr of loc * ctyp * ctyp + | (* t | t *) + TyPrv of loc * ctyp + | (* private t *) + TyMut of loc * ctyp + | (* mutable t *) + TyTup of loc * ctyp + | (* ( t ) *) + (* (int * string) *) + TySta of loc * ctyp * ctyp + | (* t * t *) + TyVrnEq of loc * ctyp + | (* [ = t ] *) + TyVrnSup of loc * ctyp + | (* [ > t ] *) + TyVrnInf of loc * ctyp + | (* [ < t ] *) + TyVrnInfSup of loc * ctyp * ctyp + | (* [ < t > t ] *) + TyAmp of loc * ctyp * ctyp + | (* t & t *) + TyOfAmp of loc * ctyp * ctyp + | (* t of & t *) + TyAnt of loc * string + and (* $s$ *) + patt = + | PaNil of loc + | PaId of loc * ident + | (* i *) + PaAli of loc * patt * patt + | (* p as p *) + (* (Node x y as n) *) + PaAnt of loc * string + | (* $s$ *) + PaAny of loc + | (* _ *) + PaApp of loc * patt * patt + | (* p p *) + (* fun x y -> *) + PaArr of loc * patt + | (* [| p |] *) + PaCom of loc * patt * patt + | (* p, p *) + PaSem of loc * patt * patt + | (* p; p *) + PaChr of loc * string + | (* c *) + (* 'x' *) + PaInt of loc * string + | PaInt32 of loc * string + | PaInt64 of loc * string + | PaNativeInt of loc * string + | PaFlo of loc * string + | PaLab of loc * string * patt + | (* ~s or ~s:(p) *) + (* ?s or ?s:(p) *) + PaOlb of loc * string * patt + | (* ?s:(p = e) or ?(p = e) *) + PaOlbi of loc * string * patt * expr + | PaOrp of loc * patt * patt + | (* p | p *) + PaRng of loc * patt * patt + | (* p .. p *) + PaRec of loc * patt + | (* { p } *) + PaEq of loc * ident * patt + | (* i = p *) + PaStr of loc * string + | (* s *) + PaTup of loc * patt + | (* ( p ) *) + PaTyc of loc * patt * ctyp + | (* (p : t) *) + PaTyp of loc * ident + | (* #i *) + PaVrn of loc * string + | (* `s *) + PaLaz of loc * patt + and (* lazy p *) + expr = + | ExNil of loc + | ExId of loc * ident + | (* i *) + ExAcc of loc * expr * expr + | (* e.e *) + ExAnt of loc * string + | (* $s$ *) + ExApp of loc * expr * expr + | (* e e *) + ExAre of loc * expr * expr + | (* e.(e) *) + ExArr of loc * expr + | (* [| e |] *) + ExSem of loc * expr * expr + | (* e; e *) + ExAsf of loc + | (* assert False *) + ExAsr of loc * expr + | (* assert e *) + ExAss of loc * expr * expr + | (* e := e *) + ExChr of loc * string + | (* 'c' *) + ExCoe of loc * expr * ctyp * ctyp + | (* (e : t) or (e : t :> t) *) + ExFlo of loc * string + | (* 3.14 *) + (* for s = e to/downto e do { e } *) + ExFor of loc * string * expr * expr * meta_bool * expr + | ExFun of loc * match_case + | (* fun [ mc ] *) + ExIfe of loc * expr * expr * expr + | (* if e then e else e *) + ExInt of loc * string + | (* 42 *) + ExInt32 of loc * string + | ExInt64 of loc * string + | ExNativeInt of loc * string + | ExLab of loc * string * expr + | (* ~s or ~s:e *) + ExLaz of loc * expr + | (* lazy e *) + (* let b in e or let rec b in e *) + ExLet of loc * meta_bool * binding * expr + | (* let module s = me in e *) + ExLmd of loc * string * module_expr * expr + | (* match e with [ mc ] *) + ExMat of loc * expr * match_case + | (* new i *) + ExNew of loc * ident + | (* object ((p))? (cst)? end *) + ExObj of loc * patt * class_str_item + | (* ?s or ?s:e *) + ExOlb of loc * string * expr + | (* {< rb >} *) + ExOvr of loc * rec_binding + | (* { rb } or { (e) with rb } *) + ExRec of loc * rec_binding * expr + | (* do { e } *) + ExSeq of loc * expr + | (* e#s *) + ExSnd of loc * expr * string + | (* e.[e] *) + ExSte of loc * expr * expr + | (* s *) + (* "foo" *) + ExStr of loc * string + | (* try e with [ mc ] *) + ExTry of loc * expr * match_case + | (* (e) *) + ExTup of loc * expr + | (* e, e *) + ExCom of loc * expr * expr + | (* (e : t) *) + ExTyc of loc * expr * ctyp + | (* `s *) + ExVrn of loc * string + | (* while e do { e } *) + ExWhi of loc * expr * expr + and module_type = + | MtNil of loc + | (* i *) + (* A.B.C *) + MtId of loc * ident + | (* functor (s : mt) -> mt *) + MtFun of loc * string * module_type * module_type + | (* 's *) + MtQuo of loc * string + | (* sig sg end *) + MtSig of loc * sig_item + | (* mt with wc *) + MtWit of loc * module_type * with_constr + | MtAnt of loc * string + and (* $s$ *) + sig_item = + | SgNil of loc + | (* class cict *) + SgCls of loc * class_type + | (* class type cict *) + SgClt of loc * class_type + | (* sg ; sg *) + SgSem of loc * sig_item * sig_item + | (* # s or # s e *) + SgDir of loc * string * expr + | (* exception t *) + SgExc of loc * ctyp + | (* external s : t = s ... s *) + SgExt of loc * string * ctyp * string meta_list + | (* include mt *) + SgInc of loc * module_type + | (* module s : mt *) + SgMod of loc * string * module_type + | (* module rec mb *) + SgRecMod of loc * module_binding + | (* module type s = mt *) + SgMty of loc * string * module_type + | (* open i *) + SgOpn of loc * ident + | (* type t *) + SgTyp of loc * ctyp + | (* value s : t *) + SgVal of loc * string * ctyp + | SgAnt of loc * string + and (* $s$ *) + with_constr = + | WcNil of loc + | (* type t = t *) + WcTyp of loc * ctyp * ctyp + | (* module i = i *) + WcMod of loc * ident * ident + | (* wc and wc *) + WcAnd of loc * with_constr * with_constr + | WcAnt of loc * string + and (* $s$ *) + binding = + | BiNil of loc + | (* bi and bi *) + (* let a = 42 and c = 43 *) + BiAnd of loc * binding * binding + | (* p = e *) + (* let patt = expr *) + BiEq of loc * patt * expr + | BiAnt of loc * string + and (* $s$ *) + rec_binding = + | RbNil of loc + | (* rb ; rb *) + RbSem of loc * rec_binding * rec_binding + | (* i = e *) + RbEq of loc * ident * expr + | RbAnt of loc * string + and (* $s$ *) + module_binding = + | MbNil of loc + | (* mb and mb *) + (* module rec (s : mt) = me and (s : mt) = me *) + MbAnd of loc * module_binding * module_binding + | (* s : mt = me *) + MbColEq of loc * string * module_type * module_expr + | (* s : mt *) + MbCol of loc * string * module_type + | MbAnt of loc * string + and (* $s$ *) + match_case = + | McNil of loc + | (* a | a *) + McOr of loc * match_case * match_case + | (* p (when e)? -> e *) + McArr of loc * patt * expr * expr + | McAnt of loc * string + and (* $s$ *) + module_expr = + | MeNil of loc + | (* i *) + MeId of loc * ident + | (* me me *) + MeApp of loc * module_expr * module_expr + | (* functor (s : mt) -> me *) + MeFun of loc * string * module_type * module_expr + | (* struct st end *) + MeStr of loc * str_item + | (* (me : mt) *) + MeTyc of loc * module_expr * module_type + | MeAnt of loc * string + and (* $s$ *) + str_item = + | StNil of loc + | (* class cice *) + StCls of loc * class_expr + | (* class type cict *) + StClt of loc * class_type + | (* st ; st *) + StSem of loc * str_item * str_item + | (* # s or # s e *) + StDir of loc * string * expr + | (* exception t or exception t = i *) + StExc of loc * ctyp * (*FIXME*) ident meta_option + | (* e *) + StExp of loc * expr + | (* external s : t = s ... s *) + StExt of loc * string * ctyp * string meta_list + | (* include me *) + StInc of loc * module_expr + | (* module s = me *) + StMod of loc * string * module_expr + | (* module rec mb *) + StRecMod of loc * module_binding + | (* module type s = mt *) + StMty of loc * string * module_type + | (* open i *) + StOpn of loc * ident + | (* type t *) + StTyp of loc * ctyp + | (* value (rec)? bi *) + StVal of loc * meta_bool * binding + | StAnt of loc * string + and (* $s$ *) + class_type = + | CtNil of loc + | (* (virtual)? i ([ t ])? *) + CtCon of loc * meta_bool * ident * ctyp + | (* [t] -> ct *) + CtFun of loc * ctyp * class_type + | (* object ((t))? (csg)? end *) + CtSig of loc * ctyp * class_sig_item + | (* ct and ct *) + CtAnd of loc * class_type * class_type + | (* ct : ct *) + CtCol of loc * class_type * class_type + | (* ct = ct *) + CtEq of loc * class_type * class_type + | (* $s$ *) + CtAnt of loc * string + and class_sig_item = + | CgNil of loc + | (* type t = t *) + CgCtr of loc * ctyp * ctyp + | (* csg ; csg *) + CgSem of loc * class_sig_item * class_sig_item + | (* inherit ct *) + CgInh of loc * class_type + | (* method s : t or method private s : t *) + CgMth of loc * string * meta_bool * ctyp + | (* value (virtual)? (mutable)? s : t *) + CgVal of loc * string * meta_bool * meta_bool * ctyp + | (* method virtual (mutable)? s : t *) + CgVir of loc * string * meta_bool * ctyp + | CgAnt of loc * string + and (* $s$ *) + class_expr = + | CeNil of loc + | (* ce e *) + CeApp of loc * class_expr * expr + | (* (virtual)? i ([ t ])? *) + CeCon of loc * meta_bool * ident * ctyp + | (* fun p -> ce *) + CeFun of loc * patt * class_expr + | (* let (rec)? bi in ce *) + CeLet of loc * meta_bool * binding * class_expr + | (* object ((p))? (cst)? end *) + CeStr of loc * patt * class_str_item + | (* ce : ct *) + CeTyc of loc * class_expr * class_type + | (* ce and ce *) + CeAnd of loc * class_expr * class_expr + | (* ce = ce *) + CeEq of loc * class_expr * class_expr + | (* $s$ *) + CeAnt of loc * string + and class_str_item = + | CrNil of loc + | (* cst ; cst *) + CrSem of loc * class_str_item * class_str_item + | (* type t = t *) + CrCtr of loc * ctyp * ctyp + | (* inherit ce or inherit ce as s *) + CrInh of loc * class_expr * string + | (* initializer e *) + CrIni of loc * expr + | (* method (private)? s : t = e or method (private)? s = e *) + CrMth of loc * string * meta_bool * expr * ctyp + | (* value (mutable)? s = e *) + CrVal of loc * string * meta_bool * expr + | (* method virtual (private)? s : t *) + CrVir of loc * string * meta_bool * ctyp + | (* value virtual (private)? s : t *) + CrVvr of loc * string * meta_bool * ctyp + | CrAnt of loc * string + + val loc_of_ctyp : ctyp -> loc + + val loc_of_patt : patt -> loc + + val loc_of_expr : expr -> loc + + val loc_of_module_type : module_type -> loc + + val loc_of_module_expr : module_expr -> loc + + val loc_of_sig_item : sig_item -> loc + + val loc_of_str_item : str_item -> loc + + val loc_of_class_type : class_type -> loc + + val loc_of_class_sig_item : class_sig_item -> loc + + val loc_of_class_expr : class_expr -> loc + + val loc_of_class_str_item : class_str_item -> loc + + val loc_of_with_constr : with_constr -> loc + + val loc_of_binding : binding -> loc + + val loc_of_rec_binding : rec_binding -> loc + + val loc_of_module_binding : module_binding -> loc + + val loc_of_match_case : match_case -> loc + + val loc_of_ident : ident -> loc + + module Meta : + sig + module type META_LOC = + sig + val meta_loc_patt : loc -> loc -> patt + + val meta_loc_expr : loc -> loc -> expr + + end + + module MetaLoc : + sig + val meta_loc_patt : loc -> loc -> patt + + val meta_loc_expr : loc -> loc -> expr + + end + + module MetaGhostLoc : + sig + val meta_loc_patt : loc -> 'a -> patt + + val meta_loc_expr : loc -> 'a -> expr + + end + + module MetaLocVar : + sig + val meta_loc_patt : loc -> 'a -> patt + + val meta_loc_expr : loc -> 'a -> expr + + end + + module Make (MetaLoc : META_LOC) : + sig + module Expr : + sig + val meta_string : loc -> string -> expr + + val meta_int : loc -> string -> expr + + val meta_float : loc -> string -> expr + + val meta_char : loc -> string -> expr + + val meta_bool : loc -> bool -> expr + + val meta_list : + (loc -> 'a -> expr) -> loc -> 'a list -> expr + + val meta_binding : loc -> binding -> expr + + val meta_rec_binding : loc -> rec_binding -> expr + + val meta_class_expr : loc -> class_expr -> expr + + val meta_class_sig_item : loc -> class_sig_item -> expr + + val meta_class_str_item : loc -> class_str_item -> expr + + val meta_class_type : loc -> class_type -> expr + + val meta_ctyp : loc -> ctyp -> expr + + val meta_expr : loc -> expr -> expr + + val meta_ident : loc -> ident -> expr + + val meta_match_case : loc -> match_case -> expr + + val meta_module_binding : loc -> module_binding -> expr + + val meta_module_expr : loc -> module_expr -> expr + + val meta_module_type : loc -> module_type -> expr + + val meta_patt : loc -> patt -> expr + + val meta_sig_item : loc -> sig_item -> expr + + val meta_str_item : loc -> str_item -> expr + + val meta_with_constr : loc -> with_constr -> expr + + end + + module Patt : + sig + val meta_string : loc -> string -> patt + + val meta_int : loc -> string -> patt + + val meta_float : loc -> string -> patt + + val meta_char : loc -> string -> patt + + val meta_bool : loc -> bool -> patt + + val meta_list : + (loc -> 'a -> patt) -> loc -> 'a list -> patt + + val meta_binding : loc -> binding -> patt + + val meta_rec_binding : loc -> rec_binding -> patt + + val meta_class_expr : loc -> class_expr -> patt + + val meta_class_sig_item : loc -> class_sig_item -> patt + + val meta_class_str_item : loc -> class_str_item -> patt + + val meta_class_type : loc -> class_type -> patt + + val meta_ctyp : loc -> ctyp -> patt + + val meta_expr : loc -> expr -> patt + + val meta_ident : loc -> ident -> patt + + val meta_match_case : loc -> match_case -> patt + + val meta_module_binding : loc -> module_binding -> patt + + val meta_module_expr : loc -> module_expr -> patt + + val meta_module_type : loc -> module_type -> patt + + val meta_patt : loc -> patt -> patt + + val meta_sig_item : loc -> sig_item -> patt + + val meta_str_item : loc -> str_item -> patt + + val meta_with_constr : loc -> with_constr -> patt + + end + + end + + end + + class map : + object ('self_type) + method string : string -> string + + method list : + 'a 'b. ('self_type -> 'a -> 'b) -> 'a list -> 'b list + + method meta_bool : meta_bool -> meta_bool + + method meta_option : + 'a 'b. + ('self_type -> 'a -> 'b) -> 'a meta_option -> 'b meta_option + + method meta_list : + 'a 'b. ('self_type -> 'a -> 'b) -> 'a meta_list -> 'b meta_list + + method loc : loc -> loc + + method expr : expr -> expr + + method patt : patt -> patt + + method ctyp : ctyp -> ctyp + + method str_item : str_item -> str_item + + method sig_item : sig_item -> sig_item + + method module_expr : module_expr -> module_expr + + method module_type : module_type -> module_type + + method class_expr : class_expr -> class_expr + + method class_type : class_type -> class_type + + method class_sig_item : class_sig_item -> class_sig_item + + method class_str_item : class_str_item -> class_str_item + + method with_constr : with_constr -> with_constr + + method binding : binding -> binding + + method rec_binding : rec_binding -> rec_binding + + method module_binding : module_binding -> module_binding + + method match_case : match_case -> match_case + + method ident : ident -> ident + + method unknown : 'a. 'a -> 'a + + end + + class fold : + object ('self_type) + method string : string -> 'self_type + + method list : + 'a. ('self_type -> 'a -> 'self_type) -> 'a list -> 'self_type + + method meta_bool : meta_bool -> 'self_type + + method meta_option : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_option -> 'self_type + + method meta_list : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_list -> 'self_type + + method loc : loc -> 'self_type + + method expr : expr -> 'self_type + + method patt : patt -> 'self_type + + method ctyp : ctyp -> 'self_type + + method str_item : str_item -> 'self_type + + method sig_item : sig_item -> 'self_type + + method module_expr : module_expr -> 'self_type + + method module_type : module_type -> 'self_type + + method class_expr : class_expr -> 'self_type + + method class_type : class_type -> 'self_type + + method class_sig_item : class_sig_item -> 'self_type + + method class_str_item : class_str_item -> 'self_type + + method with_constr : with_constr -> 'self_type + + method binding : binding -> 'self_type + + method rec_binding : rec_binding -> 'self_type + + method module_binding : module_binding -> 'self_type + + method match_case : match_case -> 'self_type + + method ident : ident -> 'self_type + + method unknown : 'a. 'a -> 'self_type + + end + + val map_expr : (expr -> expr) -> map + + val map_patt : (patt -> patt) -> map + + val map_ctyp : (ctyp -> ctyp) -> map + + val map_str_item : (str_item -> str_item) -> map + + val map_sig_item : (sig_item -> sig_item) -> map + + val map_loc : (loc -> loc) -> map + + val ident_of_expr : expr -> ident + + val ident_of_patt : patt -> ident + + val ident_of_ctyp : ctyp -> ident + + val biAnd_of_list : binding list -> binding + + val rbSem_of_list : rec_binding list -> rec_binding + + val paSem_of_list : patt list -> patt + + val paCom_of_list : patt list -> patt + + val tyOr_of_list : ctyp list -> ctyp + + val tyAnd_of_list : ctyp list -> ctyp + + val tyAmp_of_list : ctyp list -> ctyp + + val tySem_of_list : ctyp list -> ctyp + + val tyCom_of_list : ctyp list -> ctyp + + val tySta_of_list : ctyp list -> ctyp + + val stSem_of_list : str_item list -> str_item + + val sgSem_of_list : sig_item list -> sig_item + + val crSem_of_list : class_str_item list -> class_str_item + + val cgSem_of_list : class_sig_item list -> class_sig_item + + val ctAnd_of_list : class_type list -> class_type + + val ceAnd_of_list : class_expr list -> class_expr + + val wcAnd_of_list : with_constr list -> with_constr + + val meApp_of_list : module_expr list -> module_expr + + val mbAnd_of_list : module_binding list -> module_binding + + val mcOr_of_list : match_case list -> match_case + + val idAcc_of_list : ident list -> ident + + val idApp_of_list : ident list -> ident + + val exSem_of_list : expr list -> expr + + val exCom_of_list : expr list -> expr + + val list_of_ctyp : ctyp -> ctyp list -> ctyp list + + val list_of_binding : binding -> binding list -> binding list + + val list_of_rec_binding : + rec_binding -> rec_binding list -> rec_binding list + + val list_of_with_constr : + with_constr -> with_constr list -> with_constr list + + val list_of_patt : patt -> patt list -> patt list + + val list_of_expr : expr -> expr list -> expr list + + val list_of_str_item : str_item -> str_item list -> str_item list + + val list_of_sig_item : sig_item -> sig_item list -> sig_item list + + val list_of_class_sig_item : + class_sig_item -> class_sig_item list -> class_sig_item list + + val list_of_class_str_item : + class_str_item -> class_str_item list -> class_str_item list + + val list_of_class_type : + class_type -> class_type list -> class_type list + + val list_of_class_expr : + class_expr -> class_expr list -> class_expr list + + val list_of_module_expr : + module_expr -> module_expr list -> module_expr list + + val list_of_module_binding : + module_binding -> module_binding list -> module_binding list + + val list_of_match_case : + match_case -> match_case list -> match_case list + + val list_of_ident : ident -> ident list -> ident list + + val safe_string_escaped : string -> string + + val is_irrefut_patt : patt -> bool + + val is_constructor : ident -> bool + + val is_patt_constructor : patt -> bool + + val is_expr_constructor : expr -> bool + + val ty_of_stl : (Loc.t * string * (ctyp list)) -> ctyp + + val ty_of_sbt : (Loc.t * string * bool * ctyp) -> ctyp + + val bi_of_pe : (patt * expr) -> binding + + val pel_of_binding : binding -> (patt * expr) list + + val binding_of_pel : (patt * expr) list -> binding + + val sum_type_of_list : (Loc.t * string * (ctyp list)) list -> ctyp + + val record_type_of_list : (Loc.t * string * bool * ctyp) list -> ctyp + + end + + module Camlp4AstToAst (M : Camlp4Ast) : Ast with type loc = M.loc + and type meta_bool = M.meta_bool + and type 'a meta_option = 'a M.meta_option + and type 'a meta_list = 'a M.meta_list and type ctyp = M.ctyp + and type patt = M.patt and type expr = M.expr + and type module_type = M.module_type and type sig_item = M.sig_item + and type with_constr = M.with_constr + and type module_expr = M.module_expr and type str_item = M.str_item + and type class_type = M.class_type + and type class_sig_item = M.class_sig_item + and type class_expr = M.class_expr + and type class_str_item = M.class_str_item and type binding = M.binding + and type rec_binding = M.rec_binding + and type module_binding = M.module_binding + and type match_case = M.match_case and type ident = M.ident = M + + module MakeCamlp4Ast (Loc : Type) = + struct + type loc = + Loc. + t + and meta_bool = + | BTrue | BFalse | BAnt of string + and 'a meta_option = + | ONone | OSome of 'a | OAnt of string + and 'a meta_list = + | LNil | LCons of 'a * 'a meta_list | LAnt of string + and ident = + | IdAcc of loc * ident * ident + | IdApp of loc * ident * ident + | IdLid of loc * string + | IdUid of loc * string + | IdAnt of loc * string + and ctyp = + | TyNil of loc + | TyAli of loc * ctyp * ctyp + | TyAny of loc + | TyApp of loc * ctyp * ctyp + | TyArr of loc * ctyp * ctyp + | TyCls of loc * ident + | TyLab of loc * string * ctyp + | TyId of loc * ident + | TyMan of loc * ctyp * ctyp + | TyDcl of loc * string * ctyp list * ctyp * (ctyp * ctyp) list + | TyObj of loc * ctyp * meta_bool + | TyOlb of loc * string * ctyp + | TyPol of loc * ctyp * ctyp + | TyQuo of loc * string + | TyQuP of loc * string + | TyQuM of loc * string + | TyVrn of loc * string + | TyRec of loc * ctyp + | TyCol of loc * ctyp * ctyp + | TySem of loc * ctyp * ctyp + | TyCom of loc * ctyp * ctyp + | TySum of loc * ctyp + | TyOf of loc * ctyp * ctyp + | TyAnd of loc * ctyp * ctyp + | TyOr of loc * ctyp * ctyp + | TyPrv of loc * ctyp + | TyMut of loc * ctyp + | TyTup of loc * ctyp + | TySta of loc * ctyp * ctyp + | TyVrnEq of loc * ctyp + | TyVrnSup of loc * ctyp + | TyVrnInf of loc * ctyp + | TyVrnInfSup of loc * ctyp * ctyp + | TyAmp of loc * ctyp * ctyp + | TyOfAmp of loc * ctyp * ctyp + | TyAnt of loc * string + and patt = + | PaNil of loc + | PaId of loc * ident + | PaAli of loc * patt * patt + | PaAnt of loc * string + | PaAny of loc + | PaApp of loc * patt * patt + | PaArr of loc * patt + | PaCom of loc * patt * patt + | PaSem of loc * patt * patt + | PaChr of loc * string + | PaInt of loc * string + | PaInt32 of loc * string + | PaInt64 of loc * string + | PaNativeInt of loc * string + | PaFlo of loc * string + | PaLab of loc * string * patt + | PaOlb of loc * string * patt + | PaOlbi of loc * string * patt * expr + | PaOrp of loc * patt * patt + | PaRng of loc * patt * patt + | PaRec of loc * patt + | PaEq of loc * ident * patt + | PaStr of loc * string + | PaTup of loc * patt + | PaTyc of loc * patt * ctyp + | PaTyp of loc * ident + | PaVrn of loc * string + | PaLaz of loc * patt + and expr = + | ExNil of loc + | ExId of loc * ident + | ExAcc of loc * expr * expr + | ExAnt of loc * string + | ExApp of loc * expr * expr + | ExAre of loc * expr * expr + | ExArr of loc * expr + | ExSem of loc * expr * expr + | ExAsf of loc + | ExAsr of loc * expr + | ExAss of loc * expr * expr + | ExChr of loc * string + | ExCoe of loc * expr * ctyp * ctyp + | ExFlo of loc * string + | ExFor of loc * string * expr * expr * meta_bool * expr + | ExFun of loc * match_case + | ExIfe of loc * expr * expr * expr + | ExInt of loc * string + | ExInt32 of loc * string + | ExInt64 of loc * string + | ExNativeInt of loc * string + | ExLab of loc * string * expr + | ExLaz of loc * expr + | ExLet of loc * meta_bool * binding * expr + | ExLmd of loc * string * module_expr * expr + | ExMat of loc * expr * match_case + | ExNew of loc * ident + | ExObj of loc * patt * class_str_item + | ExOlb of loc * string * expr + | ExOvr of loc * rec_binding + | ExRec of loc * rec_binding * expr + | ExSeq of loc * expr + | ExSnd of loc * expr * string + | ExSte of loc * expr * expr + | ExStr of loc * string + | ExTry of loc * expr * match_case + | ExTup of loc * expr + | ExCom of loc * expr * expr + | ExTyc of loc * expr * ctyp + | ExVrn of loc * string + | ExWhi of loc * expr * expr + and module_type = + | MtNil of loc + | MtId of loc * ident + | MtFun of loc * string * module_type * module_type + | MtQuo of loc * string + | MtSig of loc * sig_item + | MtWit of loc * module_type * with_constr + | MtAnt of loc * string + and sig_item = + | SgNil of loc + | SgCls of loc * class_type + | SgClt of loc * class_type + | SgSem of loc * sig_item * sig_item + | SgDir of loc * string * expr + | SgExc of loc * ctyp + | SgExt of loc * string * ctyp * string meta_list + | SgInc of loc * module_type + | SgMod of loc * string * module_type + | SgRecMod of loc * module_binding + | SgMty of loc * string * module_type + | SgOpn of loc * ident + | SgTyp of loc * ctyp + | SgVal of loc * string * ctyp + | SgAnt of loc * string + and with_constr = + | WcNil of loc + | WcTyp of loc * ctyp * ctyp + | WcMod of loc * ident * ident + | WcAnd of loc * with_constr * with_constr + | WcAnt of loc * string + and binding = + | BiNil of loc + | BiAnd of loc * binding * binding + | BiEq of loc * patt * expr + | BiAnt of loc * string + and rec_binding = + | RbNil of loc + | RbSem of loc * rec_binding * rec_binding + | RbEq of loc * ident * expr + | RbAnt of loc * string + and module_binding = + | MbNil of loc + | MbAnd of loc * module_binding * module_binding + | MbColEq of loc * string * module_type * module_expr + | MbCol of loc * string * module_type + | MbAnt of loc * string + and match_case = + | McNil of loc + | McOr of loc * match_case * match_case + | McArr of loc * patt * expr * expr + | McAnt of loc * string + and module_expr = + | MeNil of loc + | MeId of loc * ident + | MeApp of loc * module_expr * module_expr + | MeFun of loc * string * module_type * module_expr + | MeStr of loc * str_item + | MeTyc of loc * module_expr * module_type + | MeAnt of loc * string + and str_item = + | StNil of loc + | StCls of loc * class_expr + | StClt of loc * class_type + | StSem of loc * str_item * str_item + | StDir of loc * string * expr + | StExc of loc * ctyp * ident meta_option + | StExp of loc * expr + | StExt of loc * string * ctyp * string meta_list + | StInc of loc * module_expr + | StMod of loc * string * module_expr + | StRecMod of loc * module_binding + | StMty of loc * string * module_type + | StOpn of loc * ident + | StTyp of loc * ctyp + | StVal of loc * meta_bool * binding + | StAnt of loc * string + and class_type = + | CtNil of loc + | CtCon of loc * meta_bool * ident * ctyp + | CtFun of loc * ctyp * class_type + | CtSig of loc * ctyp * class_sig_item + | CtAnd of loc * class_type * class_type + | CtCol of loc * class_type * class_type + | CtEq of loc * class_type * class_type + | CtAnt of loc * string + and class_sig_item = + | CgNil of loc + | CgCtr of loc * ctyp * ctyp + | CgSem of loc * class_sig_item * class_sig_item + | CgInh of loc * class_type + | CgMth of loc * string * meta_bool * ctyp + | CgVal of loc * string * meta_bool * meta_bool * ctyp + | CgVir of loc * string * meta_bool * ctyp + | CgAnt of loc * string + and class_expr = + | CeNil of loc + | CeApp of loc * class_expr * expr + | CeCon of loc * meta_bool * ident * ctyp + | CeFun of loc * patt * class_expr + | CeLet of loc * meta_bool * binding * class_expr + | CeStr of loc * patt * class_str_item + | CeTyc of loc * class_expr * class_type + | CeAnd of loc * class_expr * class_expr + | CeEq of loc * class_expr * class_expr + | CeAnt of loc * string + and class_str_item = + | CrNil of loc + | CrSem of loc * class_str_item * class_str_item + | CrCtr of loc * ctyp * ctyp + | CrInh of loc * class_expr * string + | CrIni of loc * expr + | CrMth of loc * string * meta_bool * expr * ctyp + | CrVal of loc * string * meta_bool * expr + | CrVir of loc * string * meta_bool * ctyp + | CrVvr of loc * string * meta_bool * ctyp + | CrAnt of loc * string + + end + + type ('a, 'loc) stream_filter = + ('a * 'loc) Stream.t -> ('a * 'loc) Stream.t + + module type AstFilters = + sig + module Ast : Camlp4Ast + + type 'a filter = 'a -> 'a + + val register_sig_item_filter : Ast.sig_item filter -> unit + + val register_str_item_filter : Ast.str_item filter -> unit + + val fold_interf_filters : + ('a -> Ast.sig_item filter -> 'a) -> 'a -> 'a + + val fold_implem_filters : + ('a -> Ast.str_item filter -> 'a) -> 'a -> 'a + + end + + module type DynAst = + sig + module Ast : Ast + + type 'a tag + + val ctyp_tag : Ast.ctyp tag + + val patt_tag : Ast.patt tag + + val expr_tag : Ast.expr tag + + val module_type_tag : Ast.module_type tag + + val sig_item_tag : Ast.sig_item tag + + val with_constr_tag : Ast.with_constr tag + + val module_expr_tag : Ast.module_expr tag + + val str_item_tag : Ast.str_item tag + + val class_type_tag : Ast.class_type tag + + val class_sig_item_tag : Ast.class_sig_item tag + + val class_expr_tag : Ast.class_expr tag + + val class_str_item_tag : Ast.class_str_item tag + + val match_case_tag : Ast.match_case tag + + val ident_tag : Ast.ident tag + + val binding_tag : Ast.binding tag + + val rec_binding_tag : Ast.rec_binding tag + + val module_binding_tag : Ast.module_binding tag + + val string_of_tag : 'a tag -> string + + module Pack (X : sig type 'a t + end) : + sig + type pack + + val pack : 'a tag -> 'a X.t -> pack + + val unpack : 'a tag -> pack -> 'a X.t + + val print_tag : Format.formatter -> pack -> unit + + end + + end + + type quotation = + { q_name : string; q_loc : string; q_shift : int; q_contents : string + } + + module type Quotation = + sig + module Ast : Ast + + module DynAst : DynAst with module Ast = Ast + + open Ast + + type 'a expand_fun = loc -> string option -> string -> 'a + + val add : string -> 'a DynAst.tag -> 'a expand_fun -> unit + + val find : string -> 'a DynAst.tag -> 'a expand_fun + + val default : string ref + + val parse_quotation_result : + (loc -> string -> 'a) -> loc -> quotation -> string -> string -> 'a + + val translate : (string -> string) ref + + val expand : loc -> quotation -> 'a DynAst.tag -> 'a + + val dump_file : (string option) ref + + module Error : Error + + end + + module type Token = + sig + module Loc : Loc + + type t + + val to_string : t -> string + + val print : Format.formatter -> t -> unit + + val match_keyword : string -> t -> bool + + val extract_string : t -> string + + module Filter : + sig + type token_filter = (t, Loc.t) stream_filter + + type t + + val mk : (string -> bool) -> t + + val define_filter : t -> (token_filter -> token_filter) -> unit + + val filter : t -> token_filter + + val keyword_added : t -> string -> bool -> unit + + val keyword_removed : t -> string -> unit + + end + + module Error : Error + + end + + type camlp4_token = + | KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int * string + | INT32 of int32 * string + | INT64 of int64 * string + | NATIVEINT of nativeint * string + | FLOAT of float * string + | CHAR of char * string + | STRING of string * string + | LABEL of string + | OPTLABEL of string + | QUOTATION of quotation + | ANTIQUOT of string * string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int * string option + | EOI + + module type Camlp4Token = Token with type t = camlp4_token + + module type DynLoader = + sig + type t + + exception Error of string * string + + val mk : ?ocaml_stdlib: bool -> ?camlp4_stdlib: bool -> unit -> t + + val fold_load_path : t -> (string -> 'a -> 'a) -> 'a -> 'a + + val load : t -> string -> unit + + val include_dir : t -> string -> unit + + val find_in_path : t -> string -> string + + val is_native : bool + + end + + module Grammar = + struct + module type Action = + sig + type t + + val mk : 'a -> t + + val get : t -> 'a + + val getf : t -> 'a -> 'b + + val getf2 : t -> 'a -> 'b -> 'c + + end + + type assoc = | NonA | RightA | LeftA + + type position = + | First + | Last + | Before of string + | After of string + | Level of string + + module type Structure = + sig + module Loc : Loc + + module Action : Action + + module Token : Token with module Loc = Loc + + type gram + + type internal_entry + + type tree + + type token_pattern = ((Token.t -> bool) * string) + + type symbol = + | Smeta of string * symbol list * Action.t + | Snterm of internal_entry + | Snterml of internal_entry * string + | Slist0 of symbol + | Slist0sep of symbol * symbol + | Slist1 of symbol + | Slist1sep of symbol * symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree + + type production_rule = ((symbol list) * Action.t) + + type single_extend_statment = + ((string option) * (assoc option) * (production_rule list)) + + type extend_statment = + ((position option) * (single_extend_statment list)) + + type delete_statment = symbol list + + type ('a, 'b, 'c) fold = + internal_entry -> + symbol list -> ('a Stream.t -> 'b) -> 'a Stream.t -> 'c + + type ('a, 'b, 'c) foldsep = + internal_entry -> + symbol list -> + ('a Stream.t -> 'b) -> + ('a Stream.t -> unit) -> 'a Stream.t -> 'c + + end + + module type Dynamic = + sig + include Structure + + val mk : unit -> gram + + module Entry : + sig + type 'a t + + val mk : gram -> string -> 'a t + + val of_parser : + gram -> + string -> ((Token.t * Loc.t) Stream.t -> 'a) -> 'a t + + val setup_parser : + 'a t -> ((Token.t * Loc.t) Stream.t -> 'a) -> unit + + val name : 'a t -> string + + val print : Format.formatter -> 'a t -> unit + + val dump : Format.formatter -> 'a t -> unit + + val obj : 'a t -> internal_entry + + val clear : 'a t -> unit + + end + + val get_filter : gram -> Token.Filter.t + + type 'a not_filtered + + val extend : 'a Entry.t -> extend_statment -> unit + + val delete_rule : 'a Entry.t -> delete_statment -> unit + + val srules : + 'a Entry.t -> ((symbol list) * Action.t) list -> symbol + + val sfold0 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold1 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold0sep : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) foldsep + + val lex : + gram -> + Loc.t -> + char Stream.t -> ((Token.t * Loc.t) Stream.t) not_filtered + + val lex_string : + gram -> + Loc.t -> string -> ((Token.t * Loc.t) Stream.t) not_filtered + + val filter : + gram -> + ((Token.t * Loc.t) Stream.t) not_filtered -> + (Token.t * Loc.t) Stream.t + + val parse : 'a Entry.t -> Loc.t -> char Stream.t -> 'a + + val parse_string : 'a Entry.t -> Loc.t -> string -> 'a + + val parse_tokens_before_filter : + 'a Entry.t -> ((Token.t * Loc.t) Stream.t) not_filtered -> 'a + + val parse_tokens_after_filter : + 'a Entry.t -> (Token.t * Loc.t) Stream.t -> 'a + + end + + module type Static = + sig + include Structure + + module Entry : + sig + type 'a t + + val mk : string -> 'a t + + val of_parser : + string -> ((Token.t * Loc.t) Stream.t -> 'a) -> 'a t + + val setup_parser : + 'a t -> ((Token.t * Loc.t) Stream.t -> 'a) -> unit + + val name : 'a t -> string + + val print : Format.formatter -> 'a t -> unit + + val dump : Format.formatter -> 'a t -> unit + + val obj : 'a t -> internal_entry + + val clear : 'a t -> unit + + end + + val get_filter : unit -> Token.Filter.t + + type 'a not_filtered + + val extend : 'a Entry.t -> extend_statment -> unit + + val delete_rule : 'a Entry.t -> delete_statment -> unit + + val srules : + 'a Entry.t -> ((symbol list) * Action.t) list -> symbol + + val sfold0 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold1 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold0sep : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) foldsep + + val lex : + Loc.t -> + char Stream.t -> ((Token.t * Loc.t) Stream.t) not_filtered + + val lex_string : + Loc.t -> string -> ((Token.t * Loc.t) Stream.t) not_filtered + + val filter : + ((Token.t * Loc.t) Stream.t) not_filtered -> + (Token.t * Loc.t) Stream.t + + val parse : 'a Entry.t -> Loc.t -> char Stream.t -> 'a + + val parse_string : 'a Entry.t -> Loc.t -> string -> 'a + + val parse_tokens_before_filter : + 'a Entry.t -> ((Token.t * Loc.t) Stream.t) not_filtered -> 'a + + val parse_tokens_after_filter : + 'a Entry.t -> (Token.t * Loc.t) Stream.t -> 'a + + end + + end + + module type Lexer = + sig + module Loc : Loc + + module Token : Token with module Loc = Loc + + module Error : Error + + val mk : unit -> Loc.t -> char Stream.t -> (Token.t * Loc.t) Stream.t + + end + + module Parser (Ast : Ast) = + struct + module type SIMPLE = + sig + val parse_expr : Ast.loc -> string -> Ast.expr + + val parse_patt : Ast.loc -> string -> Ast.patt + + end + + module type S = + sig + val parse_implem : + ?directive_handler: (Ast.str_item -> Ast.str_item option) -> + Ast.loc -> char Stream.t -> Ast.str_item + + val parse_interf : + ?directive_handler: (Ast.sig_item -> Ast.sig_item option) -> + Ast.loc -> char Stream.t -> Ast.sig_item + + end + + end + + module Printer (Ast : Ast) = + struct + module type S = + sig + val print_interf : + ?input_file: string -> + ?output_file: string -> Ast.sig_item -> unit + + val print_implem : + ?input_file: string -> + ?output_file: string -> Ast.str_item -> unit + + end + + end + + module type Syntax = + sig + module Loc : Loc + + module Ast : Ast with type loc = Loc.t + + module Token : Token with module Loc = Loc + + module Gram : Grammar.Static with module Loc = Loc + and module Token = Token + + module Quotation : Quotation with module Ast = Ast + + module AntiquotSyntax : Parser(Ast).SIMPLE + + include Warning(Loc).S + + include Parser(Ast).S + + include Printer(Ast).S + + end + + module type Camlp4Syntax = + sig + module Loc : Loc + + module Ast : Camlp4Ast with module Loc = Loc + + module Token : Camlp4Token with module Loc = Loc + + module Gram : Grammar.Static with module Loc = Loc + and module Token = Token + + module Quotation : Quotation with module Ast = Camlp4AstToAst(Ast) + + module AntiquotSyntax : Parser(Ast).SIMPLE + + include Warning(Loc).S + + include Parser(Ast).S + + include Printer(Ast).S + + val interf : ((Ast.sig_item list) * (Loc.t option)) Gram.Entry.t + + val implem : ((Ast.str_item list) * (Loc.t option)) Gram.Entry.t + + val top_phrase : (Ast.str_item option) Gram.Entry.t + + val use_file : ((Ast.str_item list) * (Loc.t option)) Gram.Entry.t + + val a_CHAR : string Gram.Entry.t + + val a_FLOAT : string Gram.Entry.t + + val a_INT : string Gram.Entry.t + + val a_INT32 : string Gram.Entry.t + + val a_INT64 : string Gram.Entry.t + + val a_LABEL : string Gram.Entry.t + + val a_LIDENT : string Gram.Entry.t + + val a_NATIVEINT : string Gram.Entry.t + + val a_OPTLABEL : string Gram.Entry.t + + val a_STRING : string Gram.Entry.t + + val a_UIDENT : string Gram.Entry.t + + val a_ident : string Gram.Entry.t + + val amp_ctyp : Ast.ctyp Gram.Entry.t + + val and_ctyp : Ast.ctyp Gram.Entry.t + + val match_case : Ast.match_case Gram.Entry.t + + val match_case0 : Ast.match_case Gram.Entry.t + + val match_case_quot : Ast.match_case Gram.Entry.t + + val binding : Ast.binding Gram.Entry.t + + val binding_quot : Ast.binding Gram.Entry.t + + val rec_binding_quot : Ast.rec_binding Gram.Entry.t + + val class_declaration : Ast.class_expr Gram.Entry.t + + val class_description : Ast.class_type Gram.Entry.t + + val class_expr : Ast.class_expr Gram.Entry.t + + val class_expr_quot : Ast.class_expr Gram.Entry.t + + val class_fun_binding : Ast.class_expr Gram.Entry.t + + val class_fun_def : Ast.class_expr Gram.Entry.t + + val class_info_for_class_expr : Ast.class_expr Gram.Entry.t + + val class_info_for_class_type : Ast.class_type Gram.Entry.t + + val class_longident : Ast.ident Gram.Entry.t + + val class_longident_and_param : Ast.class_expr Gram.Entry.t + + val class_name_and_param : (string * Ast.ctyp) Gram.Entry.t + + val class_sig_item : Ast.class_sig_item Gram.Entry.t + + val class_sig_item_quot : Ast.class_sig_item Gram.Entry.t + + val class_signature : Ast.class_sig_item Gram.Entry.t + + val class_str_item : Ast.class_str_item Gram.Entry.t + + val class_str_item_quot : Ast.class_str_item Gram.Entry.t + + val class_structure : Ast.class_str_item Gram.Entry.t + + val class_type : Ast.class_type Gram.Entry.t + + val class_type_declaration : Ast.class_type Gram.Entry.t + + val class_type_longident : Ast.ident Gram.Entry.t + + val class_type_longident_and_param : Ast.class_type Gram.Entry.t + + val class_type_plus : Ast.class_type Gram.Entry.t + + val class_type_quot : Ast.class_type Gram.Entry.t + + val comma_ctyp : Ast.ctyp Gram.Entry.t + + val comma_expr : Ast.expr Gram.Entry.t + + val comma_ipatt : Ast.patt Gram.Entry.t + + val comma_patt : Ast.patt Gram.Entry.t + + val comma_type_parameter : Ast.ctyp Gram.Entry.t + + val constrain : (Ast.ctyp * Ast.ctyp) Gram.Entry.t + + val constructor_arg_list : Ast.ctyp Gram.Entry.t + + val constructor_declaration : Ast.ctyp Gram.Entry.t + + val constructor_declarations : Ast.ctyp Gram.Entry.t + + val ctyp : Ast.ctyp Gram.Entry.t + + val ctyp_quot : Ast.ctyp Gram.Entry.t + + val cvalue_binding : Ast.expr Gram.Entry.t + + val direction_flag : Ast.meta_bool Gram.Entry.t + + val dummy : unit Gram.Entry.t + + val eq_expr : (string -> Ast.patt -> Ast.patt) Gram.Entry.t + + val expr : Ast.expr Gram.Entry.t + + val expr_eoi : Ast.expr Gram.Entry.t + + val expr_quot : Ast.expr Gram.Entry.t + + val field_expr : Ast.rec_binding Gram.Entry.t + + val field_expr_list : Ast.rec_binding Gram.Entry.t + + val fun_binding : Ast.expr Gram.Entry.t + + val fun_def : Ast.expr Gram.Entry.t + + val ident : Ast.ident Gram.Entry.t + + val ident_quot : Ast.ident Gram.Entry.t + + val ipatt : Ast.patt Gram.Entry.t + + val ipatt_tcon : Ast.patt Gram.Entry.t + + val label : string Gram.Entry.t + + val label_declaration : Ast.ctyp Gram.Entry.t + + val label_declaration_list : Ast.ctyp Gram.Entry.t + + val label_expr : Ast.rec_binding Gram.Entry.t + + val label_expr_list : Ast.rec_binding Gram.Entry.t + + val label_ipatt : Ast.patt Gram.Entry.t + + val label_ipatt_list : Ast.patt Gram.Entry.t + + val label_longident : Ast.ident Gram.Entry.t + + val label_patt : Ast.patt Gram.Entry.t + + val label_patt_list : Ast.patt Gram.Entry.t + + val labeled_ipatt : Ast.patt Gram.Entry.t + + val let_binding : Ast.binding Gram.Entry.t + + val meth_list : (Ast.ctyp * Ast.meta_bool) Gram.Entry.t + + val meth_decl : Ast.ctyp Gram.Entry.t + + val module_binding : Ast.module_binding Gram.Entry.t + + val module_binding0 : Ast.module_expr Gram.Entry.t + + val module_binding_quot : Ast.module_binding Gram.Entry.t + + val module_declaration : Ast.module_type Gram.Entry.t + + val module_expr : Ast.module_expr Gram.Entry.t + + val module_expr_quot : Ast.module_expr Gram.Entry.t + + val module_longident : Ast.ident Gram.Entry.t + + val module_longident_with_app : Ast.ident Gram.Entry.t + + val module_rec_declaration : Ast.module_binding Gram.Entry.t + + val module_type : Ast.module_type Gram.Entry.t + + val module_type_quot : Ast.module_type Gram.Entry.t + + val more_ctyp : Ast.ctyp Gram.Entry.t + + val name_tags : Ast.ctyp Gram.Entry.t + + val opt_as_lident : string Gram.Entry.t + + val opt_class_self_patt : Ast.patt Gram.Entry.t + + val opt_class_self_type : Ast.ctyp Gram.Entry.t + + val opt_comma_ctyp : Ast.ctyp Gram.Entry.t + + val opt_dot_dot : Ast.meta_bool Gram.Entry.t + + val opt_eq_ctyp : Ast.ctyp Gram.Entry.t + + val opt_expr : Ast.expr Gram.Entry.t + + val opt_meth_list : Ast.ctyp Gram.Entry.t + + val opt_mutable : Ast.meta_bool Gram.Entry.t + + val opt_polyt : Ast.ctyp Gram.Entry.t + + val opt_private : Ast.meta_bool Gram.Entry.t + + val opt_rec : Ast.meta_bool Gram.Entry.t + + val opt_virtual : Ast.meta_bool Gram.Entry.t + + val opt_when_expr : Ast.expr Gram.Entry.t + + val patt : Ast.patt Gram.Entry.t + + val patt_as_patt_opt : Ast.patt Gram.Entry.t + + val patt_eoi : Ast.patt Gram.Entry.t + + val patt_quot : Ast.patt Gram.Entry.t + + val patt_tcon : Ast.patt Gram.Entry.t + + val phrase : Ast.str_item Gram.Entry.t + + val poly_type : Ast.ctyp Gram.Entry.t + + val row_field : Ast.ctyp Gram.Entry.t + + val sem_expr : Ast.expr Gram.Entry.t + + val sem_expr_for_list : (Ast.expr -> Ast.expr) Gram.Entry.t + + val sem_patt : Ast.patt Gram.Entry.t + + val sem_patt_for_list : (Ast.patt -> Ast.patt) Gram.Entry.t + + val semi : unit Gram.Entry.t + + val sequence : Ast.expr Gram.Entry.t + + val do_sequence : Ast.expr Gram.Entry.t + + val sig_item : Ast.sig_item Gram.Entry.t + + val sig_item_quot : Ast.sig_item Gram.Entry.t + + val sig_items : Ast.sig_item Gram.Entry.t + + val star_ctyp : Ast.ctyp Gram.Entry.t + + val str_item : Ast.str_item Gram.Entry.t + + val str_item_quot : Ast.str_item Gram.Entry.t + + val str_items : Ast.str_item Gram.Entry.t + + val type_constraint : unit Gram.Entry.t + + val type_declaration : Ast.ctyp Gram.Entry.t + + val type_ident_and_parameters : + (string * (Ast.ctyp list)) Gram.Entry.t + + val type_kind : Ast.ctyp Gram.Entry.t + + val type_longident : Ast.ident Gram.Entry.t + + val type_longident_and_parameters : Ast.ctyp Gram.Entry.t + + val type_parameter : Ast.ctyp Gram.Entry.t + + val type_parameters : (Ast.ctyp -> Ast.ctyp) Gram.Entry.t + + val typevars : Ast.ctyp Gram.Entry.t + + val val_longident : Ast.ident Gram.Entry.t + + val value_let : unit Gram.Entry.t + + val value_val : unit Gram.Entry.t + + val with_constr : Ast.with_constr Gram.Entry.t + + val with_constr_quot : Ast.with_constr Gram.Entry.t + + val prefixop : Ast.expr Gram.Entry.t + + val infixop0 : Ast.expr Gram.Entry.t + + val infixop1 : Ast.expr Gram.Entry.t + + val infixop2 : Ast.expr Gram.Entry.t + + val infixop3 : Ast.expr Gram.Entry.t + + val infixop4 : Ast.expr Gram.Entry.t + + end + + module type SyntaxExtension = + functor (Syn : Syntax) -> Syntax with module Loc = Syn.Loc + and module Ast = Syn.Ast and module Token = Syn.Token + and module Gram = Syn.Gram and module Quotation = Syn.Quotation + + end + +module ErrorHandler : + sig + val print : Format.formatter -> exn -> unit + + val try_print : Format.formatter -> exn -> unit + + val to_string : exn -> string + + val try_to_string : exn -> string + + val register : (Format.formatter -> exn -> unit) -> unit + + module Register (Error : Sig.Error) : sig end + + module ObjTools : + sig + val print : Format.formatter -> Obj.t -> unit + + val print_desc : Format.formatter -> Obj.t -> unit + + val to_string : Obj.t -> string + + val desc : Obj.t -> string + + end + + end = + struct + open Format + + module ObjTools = + struct + let desc obj = + if Obj.is_block obj + then "tag = " ^ (string_of_int (Obj.tag obj)) + else "int_val = " ^ (string_of_int (Obj.obj obj)) + + let rec to_string r = + if Obj.is_int r + then + (let i : int = Obj.magic r + in (string_of_int i) ^ (" | CstTag" ^ (string_of_int (i + 1)))) + else + (let rec get_fields acc = + function + | 0 -> acc + | n -> let n = n - 1 in get_fields ((Obj.field r n) :: acc) n in + let rec is_list r = + if Obj.is_int r + then r = (Obj.repr 0) + else + (let s = Obj.size r + and t = Obj.tag r + in (t = 0) && ((s = 2) && (is_list (Obj.field r 1)))) in + let rec get_list r = + if Obj.is_int r + then [] + else + (let h = Obj.field r 0 + and t = get_list (Obj.field r 1) + in h :: t) in + let opaque name = "<" ^ (name ^ ">") in + let s = Obj.size r + and t = Obj.tag r + in + match t with + | _ when is_list r -> + let fields = get_list r + in + "[" ^ + ((String.concat "; " (List.map to_string fields)) ^ + "]") + | 0 -> + let fields = get_fields [] s + in + "(" ^ + ((String.concat ", " (List.map to_string fields)) ^ + ")") + | x when x = Obj.lazy_tag -> opaque "lazy" + | x when x = Obj.closure_tag -> opaque "closure" + | x when x = Obj.object_tag -> + let fields = get_fields [] s in + let (_class, id, slots) = + (match fields with + | h :: h' :: t -> (h, h', t) + | _ -> assert false) + in + "Object #" ^ + ((to_string id) ^ + (" (" ^ + ((String.concat ", " (List.map to_string slots)) + ^ ")"))) + | x when x = Obj.infix_tag -> opaque "infix" + | x when x = Obj.forward_tag -> opaque "forward" + | x when x < Obj.no_scan_tag -> + let fields = get_fields [] s + in + "Tag" ^ + ((string_of_int t) ^ + (" (" ^ + ((String.concat ", " (List.map to_string fields)) + ^ ")"))) + | x when x = Obj.string_tag -> + "\"" ^ ((String.escaped (Obj.magic r : string)) ^ "\"") + | x when x = Obj.double_tag -> + string_of_float (Obj.magic r : float) + | x when x = Obj.abstract_tag -> opaque "abstract" + | x when x = Obj.custom_tag -> opaque "custom" + | x when x = Obj.final_tag -> opaque "final" + | _ -> + failwith + ("ObjTools.to_string: unknown tag (" ^ + ((string_of_int t) ^ ")"))) + + let print ppf x = fprintf ppf "%s" (to_string x) + + let print_desc ppf x = fprintf ppf "%s" (desc x) + + end + + let default_handler ppf x = + let x = Obj.repr x + in + (fprintf ppf "Camlp4: Uncaught exception: %s" + (Obj.obj (Obj.field (Obj.field x 0) 0) : string); + if (Obj.size x) > 1 + then + (pp_print_string ppf " ("; + for i = 1 to (Obj.size x) - 1 do + if i > 1 then pp_print_string ppf ", " else (); + ObjTools.print ppf (Obj.field x i) + done; + pp_print_char ppf ')') + else (); + fprintf ppf "@.") + + let handler = + ref (fun ppf default_handler exn -> default_handler ppf exn) + + let register f = + let current_handler = !handler + in + handler := + fun ppf default_handler exn -> + try f ppf exn + with | exn -> current_handler ppf default_handler exn + + module Register (Error : Sig.Error) = + struct + let _ = + let current_handler = !handler + in + handler := + fun ppf default_handler -> + function + | Error.E x -> Error.print ppf x + | x -> current_handler ppf default_handler x + + end + + let gen_print ppf default_handler = + function + | Out_of_memory -> fprintf ppf "Out of memory" + | Assert_failure ((file, line, char)) -> + fprintf ppf "Assertion failed, file %S, line %d, char %d" file line + char + | Match_failure ((file, line, char)) -> + fprintf ppf "Pattern matching failed, file %S, line %d, char %d" + file line char + | Failure str -> fprintf ppf "Failure: %S" str + | Invalid_argument str -> fprintf ppf "Invalid argument: %S" str + | Sys_error str -> fprintf ppf "I/O error: %S" str + | Stream.Failure -> fprintf ppf "Parse failure" + | Stream.Error str -> fprintf ppf "Parse error: %s" str + | x -> !handler ppf default_handler x + + let print ppf = gen_print ppf default_handler + + let try_print ppf = gen_print ppf (fun _ -> raise) + + let to_string exn = + let buf = Buffer.create 128 in + let () = bprintf buf "%a" print exn in Buffer.contents buf + + let try_to_string exn = + let buf = Buffer.create 128 in + let () = bprintf buf "%a" try_print exn in Buffer.contents buf + + end + +module Struct = + struct + module Loc : sig include Sig.Loc + end = + struct + open Format + + type pos = { line : int; bol : int; off : int } + + type t = + { file_name : string; start : pos; stop : pos; ghost : bool + } + + let dump_sel f x = + let s = + match x with + | `start -> "`start" + | `stop -> "`stop" + | `both -> "`both" + | _ -> "" + in pp_print_string f s + + let dump_pos f x = + fprintf f "@[{ line = %d ;@ bol = %d ;@ off = %d } : pos@]" + x.line x.bol x.off + + let dump_long f x = + fprintf f + "@[{ file_name = %s ;@ start = %a (%d-%d);@ stop = %a (%d);@ ghost = %b@ } : Loc.t@]" + x.file_name dump_pos x.start (x.start.off - x.start.bol) + (x.stop.off - x.start.bol) dump_pos x.stop + (x.stop.off - x.stop.bol) x.ghost + + let dump f x = + fprintf f "[%S: %d:%d-%d %d:%d%t]" x.file_name x.start.line + (x.start.off - x.start.bol) (x.stop.off - x.start.bol) + x.stop.line (x.stop.off - x.stop.bol) + (fun o -> if x.ghost then fprintf o " (ghost)" else ()) + + let start_pos = { line = 1; bol = 0; off = 0; } + + let ghost = + { + file_name = "ghost-location"; + start = start_pos; + stop = start_pos; + ghost = true; + } + + let mk file_name = + { + file_name = file_name; + start = start_pos; + stop = start_pos; + ghost = false; + } + + let of_tuple (file_name, start_line, start_bol, start_off, stop_line, + stop_bol, stop_off, ghost) + = + { + file_name = file_name; + start = { line = start_line; bol = start_bol; off = start_off; }; + stop = { line = stop_line; bol = stop_bol; off = stop_off; }; + ghost = ghost; + } + + let to_tuple { + file_name = file_name; + start = + { + line = start_line; + bol = start_bol; + off = start_off + }; + stop = + { line = stop_line; bol = stop_bol; off = stop_off }; + ghost = ghost + } = + (file_name, start_line, start_bol, start_off, stop_line, stop_bol, + stop_off, ghost) + + let pos_of_lexing_position p = + let pos = + { + line = p.Lexing.pos_lnum; + bol = p.Lexing.pos_bol; + off = p.Lexing.pos_cnum; + } + in pos + + let pos_to_lexing_position p file_name = + { + Lexing.pos_fname = file_name; + pos_lnum = p.line; + pos_bol = p.bol; + pos_cnum = p.off; + } + + let better_file_name a b = + match (a, b) with + | ("", "") -> a + | ("", x) -> x + | (x, "") -> x + | ("-", x) -> x + | (x, "-") -> x + | (x, _) -> x + + let of_lexbuf lb = + let start = Lexing.lexeme_start_p lb + and stop = Lexing.lexeme_end_p lb in + let loc = + { + file_name = + better_file_name start.Lexing.pos_fname stop.Lexing.pos_fname; + start = pos_of_lexing_position start; + stop = pos_of_lexing_position stop; + ghost = false; + } + in loc + + let of_lexing_position pos = + let loc = + { + file_name = pos.Lexing.pos_fname; + start = pos_of_lexing_position pos; + stop = pos_of_lexing_position pos; + ghost = false; + } + in loc + + let to_ocaml_location x = + { + Camlp4_import.Location.loc_start = + pos_to_lexing_position x.start x.file_name; + loc_end = pos_to_lexing_position x.stop x.file_name; + loc_ghost = x.ghost; + } + + let of_ocaml_location { + Camlp4_import.Location.loc_start = a; + loc_end = b; + loc_ghost = g + } = + let res = + { + file_name = + better_file_name a.Lexing.pos_fname b.Lexing.pos_fname; + start = pos_of_lexing_position a; + stop = pos_of_lexing_position b; + ghost = g; + } + in res + + let start_pos x = pos_to_lexing_position x.start x.file_name + + let stop_pos x = pos_to_lexing_position x.stop x.file_name + + let merge a b = + if a == b + then a + else + (let r = + match ((a.ghost), (b.ghost)) with + | (false, false) -> { (a) with stop = b.stop; } + | (true, true) -> { (a) with stop = b.stop; } + | (true, _) -> { (a) with stop = b.stop; } + | (_, true) -> { (b) with start = a.start; } + in r) + + let join x = { (x) with stop = x.start; } + + let map f start_stop_both x = + match start_stop_both with + | `start -> { (x) with start = f x.start; } + | `stop -> { (x) with stop = f x.stop; } + | `both -> { (x) with start = f x.start; stop = f x.stop; } + + let move_pos chars x = { (x) with off = x.off + chars; } + + let move s chars x = map (move_pos chars) s x + + let move_line lines x = + let move_line_pos x = + { (x) with line = x.line + lines; bol = x.off; } + in map move_line_pos `both x + + let shift width x = + { (x) with start = x.stop; stop = move_pos width x.stop; } + + let file_name x = x.file_name + + let start_line x = x.start.line + + let stop_line x = x.stop.line + + let start_bol x = x.start.bol + + let stop_bol x = x.stop.bol + + let start_off x = x.start.off + + let stop_off x = x.stop.off + + let is_ghost x = x.ghost + + let set_file_name s x = { (x) with file_name = s; } + + let ghostify x = { (x) with ghost = true; } + + let make_absolute x = + let pwd = Sys.getcwd () + in + if Filename.is_relative x.file_name + then { (x) with file_name = Filename.concat pwd x.file_name; } + else x + + let strictly_before x y = + let b = (x.stop.off < y.start.off) && (x.file_name = y.file_name) + in b + + let to_string x = + let (a, b) = ((x.start), (x.stop)) in + let res = + sprintf "File \"%s\", line %d, characters %d-%d" x.file_name + a.line (a.off - a.bol) (b.off - a.bol) + in + if x.start.line <> x.stop.line + then + sprintf "%s (end at line %d, character %d)" res x.stop.line + (b.off - b.bol) + else res + + let print out x = pp_print_string out (to_string x) + + let check x msg = + if + ((start_line x) > (stop_line x)) || + (((start_bol x) > (stop_bol x)) || + (((start_off x) > (stop_off x)) || + (((start_line x) < 0) || + (((stop_line x) < 0) || + (((start_bol x) < 0) || + (((stop_bol x) < 0) || + (((start_off x) < 0) || ((stop_off x) < 0)))))))) + then + (eprintf "*** Warning: (%s) strange positions ***\n%a@\n" msg + print x; + false) + else true + + exception Exc_located of t * exn + + let _ = + ErrorHandler.register + (fun ppf -> + function + | Exc_located (loc, exn) -> + fprintf ppf "%a:@\n%a" print loc ErrorHandler.print exn + | exn -> raise exn) + + let name = ref "_loc" + + let raise loc exc = + match exc with + | Exc_located (_, _) -> raise exc + | _ -> raise (Exc_located (loc, exc)) + + end + + module Token : + sig + module Make (Loc : Sig.Loc) : Sig.Camlp4Token with module Loc = Loc + + module Eval : + sig + val char : string -> char + + val string : ?strict: unit -> string -> string + + end + + end = + struct + open Format + + module Make (Loc : Sig.Loc) : Sig.Camlp4Token with module Loc = Loc = + struct + module Loc = Loc + + open Sig + + type t = camlp4_token + + type token = t + + let to_string = + function + | KEYWORD s -> sprintf "KEYWORD %S" s + | SYMBOL s -> sprintf "SYMBOL %S" s + | LIDENT s -> sprintf "LIDENT %S" s + | UIDENT s -> sprintf "UIDENT %S" s + | INT (_, s) -> sprintf "INT %s" s + | INT32 (_, s) -> sprintf "INT32 %sd" s + | INT64 (_, s) -> sprintf "INT64 %sd" s + | NATIVEINT (_, s) -> sprintf "NATIVEINT %sd" s + | FLOAT (_, s) -> sprintf "FLOAT %s" s + | CHAR (_, s) -> sprintf "CHAR '%s'" s + | STRING (_, s) -> sprintf "STRING \"%s\"" s + | LABEL s -> sprintf "LABEL %S" s + | OPTLABEL s -> sprintf "OPTLABEL %S" s + | ANTIQUOT (n, s) -> sprintf "ANTIQUOT %s: %S" n s + | QUOTATION x -> + sprintf + "QUOTATION { q_name=%S; q_loc=%S; q_shift=%d; q_contents=%S }" + x.q_name x.q_loc x.q_shift x.q_contents + | COMMENT s -> sprintf "COMMENT %S" s + | BLANKS s -> sprintf "BLANKS %S" s + | NEWLINE -> sprintf "NEWLINE" + | EOI -> sprintf "EOI" + | ESCAPED_IDENT s -> sprintf "ESCAPED_IDENT %S" s + | LINE_DIRECTIVE (i, None) -> sprintf "LINE_DIRECTIVE %d" i + | LINE_DIRECTIVE (i, (Some s)) -> + sprintf "LINE_DIRECTIVE %d %S" i s + + let print ppf x = pp_print_string ppf (to_string x) + + let match_keyword kwd = + function | KEYWORD kwd' when kwd = kwd' -> true | _ -> false + + let extract_string = + function + | KEYWORD s | SYMBOL s | LIDENT s | UIDENT s | INT (_, s) | + INT32 (_, s) | INT64 (_, s) | NATIVEINT (_, s) | + FLOAT (_, s) | CHAR (_, s) | STRING (_, s) | LABEL s | + OPTLABEL s | COMMENT s | BLANKS s | ESCAPED_IDENT s -> s + | tok -> + invalid_arg + ("Cannot extract a string from this token: " ^ + (to_string tok)) + + module Error = + struct + type t = + | Illegal_token of string + | Keyword_as_label of string + | Illegal_token_pattern of string * string + | Illegal_constructor of string + + exception E of t + + let print ppf = + function + | Illegal_token s -> fprintf ppf "Illegal token (%s)" s + | Keyword_as_label kwd -> + fprintf ppf + "`%s' is a keyword, it cannot be used as label name" + kwd + | Illegal_token_pattern (p_con, p_prm) -> + fprintf ppf "Illegal token pattern: %s %S" p_con p_prm + | Illegal_constructor con -> + fprintf ppf "Illegal constructor %S" con + + let to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b + + end + + let _ = let module M = ErrorHandler.Register(Error) in () + + module Filter = + struct + type token_filter = (t, Loc.t) stream_filter + + type t = + { is_kwd : string -> bool; mutable filter : token_filter + } + + let err error loc = + raise (Loc.Exc_located (loc, Error.E error)) + + let keyword_conversion tok is_kwd = + match tok with + | SYMBOL s | LIDENT s | UIDENT s when is_kwd s -> KEYWORD s + | ESCAPED_IDENT s -> LIDENT s + | _ -> tok + + let check_keyword_as_label tok loc is_kwd = + let s = + match tok with | LABEL s -> s | OPTLABEL s -> s | _ -> "" + in + if (s <> "") && (is_kwd s) + then err (Error.Keyword_as_label s) loc + else () + + let check_unknown_keywords tok loc = + match tok with + | SYMBOL s -> err (Error.Illegal_token s) loc + | _ -> () + + let error_no_respect_rules p_con p_prm = + raise + (Error.E (Error.Illegal_token_pattern (p_con, p_prm))) + + let check_keyword _ = true + + let error_on_unknown_keywords = ref false + + let rec ignore_layout (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some + (((COMMENT _ | BLANKS _ | NEWLINE | + LINE_DIRECTIVE (_, _)), + _)) + -> (Stream.junk __strm; ignore_layout __strm) + | Some x -> + (Stream.junk __strm; + let s = __strm + in + Stream.icons x + (Stream.slazy (fun _ -> ignore_layout s))) + | _ -> Stream.sempty + + let mk is_kwd = { is_kwd = is_kwd; filter = ignore_layout; } + + let filter x = + let f tok loc = + let tok = keyword_conversion tok x.is_kwd + in + (check_keyword_as_label tok loc x.is_kwd; + if !error_on_unknown_keywords + then check_unknown_keywords tok loc + else (); + (tok, loc)) in + let rec filter (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some ((tok, loc)) -> + (Stream.junk __strm; + let s = __strm + in + Stream.lcons (fun _ -> f tok loc) + (Stream.slazy (fun _ -> filter s))) + | _ -> Stream.sempty in + let rec tracer (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some (((_tok, _loc) as x)) -> + (Stream.junk __strm; + let xs = __strm + in + Stream.icons x (Stream.slazy (fun _ -> tracer xs))) + | _ -> Stream.sempty + in fun strm -> tracer (x.filter (filter strm)) + + let define_filter x f = x.filter <- f x.filter + + let keyword_added _ _ _ = () + + let keyword_removed _ _ = () + + end + + end + + module Eval = + struct + let valch x = (Char.code x) - (Char.code '0') + + let valch_hex x = + let d = Char.code x + in + if d >= 97 + then d - 87 + else if d >= 65 then d - 55 else d - 48 + + let rec skip_indent (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some (' ' | '\t') -> (Stream.junk __strm; skip_indent __strm) + | _ -> () + + let skip_opt_linefeed (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some '\010' -> (Stream.junk __strm; ()) + | _ -> () + + let chr c = + if (c < 0) || (c > 255) + then failwith "invalid char token" + else Char.chr c + + let rec backslash (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some '\010' -> (Stream.junk __strm; '\010') + | Some '\013' -> (Stream.junk __strm; '\013') + | Some 'n' -> (Stream.junk __strm; '\n') + | Some 'r' -> (Stream.junk __strm; '\r') + | Some 't' -> (Stream.junk __strm; '\t') + | Some 'b' -> (Stream.junk __strm; '\b') + | Some '\\' -> (Stream.junk __strm; '\\') + | Some '"' -> (Stream.junk __strm; '"') + | Some '\'' -> (Stream.junk __strm; '\'') + | Some ' ' -> (Stream.junk __strm; ' ') + | Some (('0' .. '9' as c1)) -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some (('0' .. '9' as c2)) -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some (('0' .. '9' as c3)) -> + (Stream.junk __strm; + chr + (((100 * (valch c1)) + (10 * (valch c2))) + + (valch c3))) + | _ -> raise (Stream.Error ""))) + | _ -> raise (Stream.Error ""))) + | Some 'x' -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some (('0' .. '9' | 'a' .. 'f' | 'A' .. 'F' as c1)) -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some + (('0' .. '9' | 'a' .. 'f' | 'A' .. 'F' as c2)) + -> + (Stream.junk __strm; + chr ((16 * (valch_hex c1)) + (valch_hex c2))) + | _ -> raise (Stream.Error ""))) + | _ -> raise (Stream.Error ""))) + | _ -> raise Stream.Failure + + let rec backslash_in_string strict store (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some '\010' -> (Stream.junk __strm; skip_indent __strm) + | Some '\013' -> + (Stream.junk __strm; + let s = __strm in (skip_opt_linefeed s; skip_indent s)) + | _ -> + (match try Some (backslash __strm) + with | Stream.Failure -> None + with + | Some x -> store x + | _ -> + (match Stream.peek __strm with + | Some c when not strict -> + (Stream.junk __strm; store '\\'; store c) + | _ -> failwith "invalid string token")) + + let char s = + if (String.length s) = 1 + then s.[0] + else + if (String.length s) = 0 + then failwith "invalid char token" + else + (let (__strm : _ Stream.t) = Stream.of_string s + in + match Stream.peek __strm with + | Some '\\' -> + (Stream.junk __strm; + (try backslash __strm + with | Stream.Failure -> raise (Stream.Error ""))) + | _ -> failwith "invalid char token") + + let string ?strict s = + let buf = Buffer.create 23 in + let store = Buffer.add_char buf in + let rec parse (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some '\\' -> + (Stream.junk __strm; + let _ = + (try backslash_in_string (strict <> None) store __strm + with | Stream.Failure -> raise (Stream.Error "")) + in parse __strm) + | Some c -> + (Stream.junk __strm; + let s = __strm in (store c; parse s)) + | _ -> Buffer.contents buf + in parse (Stream.of_string s) + + end + + end + + module Lexer = + struct + module TokenEval = Token.Eval + + module Make (Token : Sig.Camlp4Token) = + struct + module Loc = Token.Loc + + module Token = Token + + open Lexing + + open Sig + + module Error = + struct + type t = + | Illegal_character of char + | Illegal_escape of string + | Unterminated_comment + | Unterminated_string + | Unterminated_quotation + | Unterminated_antiquot + | Unterminated_string_in_comment + | Comment_start + | Comment_not_end + | Literal_overflow of string + + exception E of t + + open Format + + let print ppf = + function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Illegal_escape s -> + fprintf ppf + "Illegal backslash escape in string or character (%s)" + s + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf + "This comment contains an unterminated string literal" + | Unterminated_quotation -> + fprintf ppf "Quotation not terminated" + | Unterminated_antiquot -> + fprintf ppf "Antiquotation not terminated" + | Literal_overflow ty -> + fprintf ppf + "Integer literal exceeds the range of representable integers of type %s" + ty + | Comment_start -> + fprintf ppf "this is the start of a comment" + | Comment_not_end -> + fprintf ppf "this is not the end of a comment" + + let to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b + + end + + let _ = let module M = ErrorHandler.Register(Error) in () + + open Error + + type context = + { loc : Loc.t; in_comment : bool; quotations : bool; + antiquots : bool; lexbuf : lexbuf; buffer : Buffer.t + } + + let default_context lb = + { + loc = Loc.ghost; + in_comment = false; + quotations = true; + antiquots = false; + lexbuf = lb; + buffer = Buffer.create 256; + } + + let store c = Buffer.add_string c.buffer (Lexing.lexeme c.lexbuf) + + let istore_char c i = + Buffer.add_char c.buffer (Lexing.lexeme_char c.lexbuf i) + + let buff_contents c = + let contents = Buffer.contents c.buffer + in (Buffer.reset c.buffer; contents) + + let loc c = Loc.merge c.loc (Loc.of_lexbuf c.lexbuf) + + let quotations c = c.quotations + + let antiquots c = c.antiquots + + let is_in_comment c = c.in_comment + + let in_comment c = { (c) with in_comment = true; } + + let set_start_p c = c.lexbuf.lex_start_p <- Loc.start_pos c.loc + + let move_start_p shift c = + let p = c.lexbuf.lex_start_p + in + c.lexbuf.lex_start_p <- + { (p) with pos_cnum = p.pos_cnum + shift; } + + let update_loc c = { (c) with loc = Loc.of_lexbuf c.lexbuf; } + + let with_curr_loc f c = f (update_loc c) c.lexbuf + + let parse_nested f c = + (with_curr_loc f c; set_start_p c; buff_contents c) + + let shift n c = { (c) with loc = Loc.move `both n c.loc; } + + let store_parse f c = (store c; f c c.lexbuf) + + let parse f c = f c c.lexbuf + + let mk_quotation quotation c name loc shift = + let s = parse_nested quotation (update_loc c) in + let contents = String.sub s 0 ((String.length s) - 2) + in + QUOTATION + { + q_name = name; + q_loc = loc; + q_shift = shift; + q_contents = contents; + } + + let update_loc c file line absolute chars = + let lexbuf = c.lexbuf in + let pos = lexbuf.lex_curr_p in + let new_file = + match file with | None -> pos.pos_fname | Some s -> s + in + lexbuf.lex_curr_p <- + { + (pos) + with + pos_fname = new_file; + pos_lnum = if absolute then line else pos.pos_lnum + line; + pos_bol = pos.pos_cnum - chars; + } + + let err error loc = raise (Loc.Exc_located (loc, Error.E error)) + + let warn error loc = + Format.eprintf "Warning: %a: %a@." Loc.print loc Error.print + error + + let __ocaml_lex_tables = + { + Lexing.lex_base = + "\000\000\223\255\224\255\224\000\226\255\253\000\035\001\072\001\ + \109\001\146\001\091\000\183\001\068\000\190\001\218\001\227\255\ + \122\000\002\002\071\002\110\002\176\000\244\255\129\002\162\002\ + \235\002\187\003\154\004\246\004\124\000\001\000\255\255\198\005\ + \253\255\150\006\252\255\245\255\246\255\247\255\253\000\224\000\ + \086\000\091\000\054\003\006\004\029\002\237\001\182\004\109\000\ + \118\007\091\000\253\000\093\000\243\255\242\255\241\255\106\005\ + \077\003\108\000\087\003\017\006\151\007\218\007\001\008\068\008\ + \107\008\107\000\239\255\126\008\075\001\210\008\249\008\060\009\ + \232\255\231\255\230\255\099\009\166\009\205\009\016\010\055\010\ + \249\001\228\255\229\255\238\255\090\010\127\010\164\010\201\010\ + \238\010\019\011\056\011\091\011\128\011\165\011\202\011\239\011\ + \020\012\057\012\094\012\011\007\136\005\004\000\233\255\008\000\ + \054\001\245\002\009\000\005\000\233\255\131\012\138\012\175\012\ + \212\012\249\012\000\013\037\013\068\013\096\013\133\013\138\013\ + \205\013\242\013\023\014\085\014\241\255\006\000\242\255\243\255\ + \148\002\251\255\047\015\123\000\109\000\125\000\255\255\254\255\ + \253\255\111\015\046\016\254\016\206\017\174\018\129\000\017\001\ + \130\000\141\000\249\255\248\255\247\255\237\006\109\003\143\000\ + \246\255\035\004\145\000\245\255\160\014\149\000\244\255\086\004\ + \247\255\248\255\007\000\249\255\201\018\255\255\250\255\121\016\ + \154\004\253\255\091\001\057\001\171\004\252\255\073\017\251\255\ + \240\018\051\019\018\020\048\020\255\255\015\021\238\021\015\022\ + \079\022\255\255\031\023\254\255\164\001\251\255\010\000\252\255\ + \253\255\128\000\079\001\255\255\095\023\030\024\238\024\190\025\ + \254\255\154\026\253\255\254\255\201\000\116\027\077\028\255\255\ + \028\001\029\029\206\001\251\255\080\001\013\000\253\255\254\255\ + \255\255\252\255\093\029\028\030\236\030\188\031"; + Lexing.lex_backtrk = + "\255\255\255\255\255\255\030\000\255\255\028\000\030\000\030\000\ + \030\000\030\000\028\000\028\000\028\000\028\000\028\000\255\255\ + \028\000\030\000\030\000\028\000\028\000\255\255\006\000\006\000\ + \005\000\004\000\030\000\030\000\001\000\000\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\007\000\ + \255\255\255\255\255\255\006\000\006\000\006\000\007\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\014\000\ + \014\000\014\000\255\255\255\255\255\255\255\255\255\255\028\000\ + \028\000\015\000\255\255\028\000\255\255\255\255\028\000\255\255\ + \255\255\255\255\255\255\028\000\028\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\030\000\021\000\020\000\ + \018\000\030\000\018\000\018\000\018\000\018\000\028\000\018\000\ + \255\255\019\000\030\000\255\255\255\255\022\000\255\255\255\255\ + \255\255\255\255\255\255\022\000\255\255\255\255\255\255\255\255\ + \028\000\255\255\028\000\255\255\028\000\028\000\028\000\028\000\ + \030\000\030\000\030\000\255\255\255\255\013\000\255\255\255\255\ + \014\000\255\255\003\000\014\000\014\000\014\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\005\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\006\000\255\255\008\000\255\255\255\255\005\000\ + \005\000\255\255\001\000\001\000\255\255\255\255\255\255\255\255\ + \000\000\001\000\001\000\255\255\255\255\002\000\002\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\003\000\255\255\ + \255\255\004\000\004\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\002\000\002\000\002\000\255\255\ + \255\255\255\255\255\255\255\255\004\000\002\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255"; + Lexing.lex_default = + "\001\000\000\000\000\000\255\255\000\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\000\ + \255\255\255\255\255\255\255\255\049\000\000\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\000\000\255\255\ + \000\000\255\255\000\000\000\000\000\000\000\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \054\000\255\255\255\255\255\255\000\000\000\000\000\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\000\000\255\255\255\255\255\255\255\255\255\255\ + \000\000\000\000\000\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\000\000\000\000\000\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\103\000\255\255\255\255\000\000\103\000\ + \104\000\103\000\106\000\255\255\000\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\124\000\000\000\255\255\000\000\000\000\ + \142\000\000\000\255\255\255\255\255\255\255\255\000\000\000\000\ + \000\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\000\000\000\000\000\000\255\255\255\255\255\255\ + \000\000\255\255\255\255\000\000\255\255\255\255\000\000\160\000\ + \000\000\000\000\255\255\000\000\166\000\000\000\000\000\255\255\ + \255\255\000\000\255\255\255\255\255\255\000\000\255\255\000\000\ + \255\255\255\255\255\255\255\255\000\000\255\255\255\255\255\255\ + \255\255\000\000\255\255\000\000\189\000\000\000\255\255\000\000\ + \000\000\255\255\255\255\000\000\255\255\255\255\255\255\255\255\ + \000\000\202\000\000\000\000\000\255\255\255\255\255\255\000\000\ + \255\255\255\255\211\000\000\000\255\255\255\255\000\000\000\000\ + \000\000\000\000\255\255\255\255\255\255\255\255"; + Lexing.lex_trans = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\028\000\030\000\030\000\028\000\029\000\102\000\108\000\ + \126\000\163\000\102\000\108\000\191\000\101\000\107\000\214\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \028\000\003\000\021\000\016\000\004\000\009\000\009\000\020\000\ + \019\000\005\000\018\000\003\000\015\000\003\000\014\000\009\000\ + \023\000\022\000\022\000\022\000\022\000\022\000\022\000\022\000\ + \022\000\022\000\013\000\012\000\017\000\006\000\007\000\026\000\ + \009\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\011\000\003\000\005\000\009\000\025\000\ + \015\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\010\000\008\000\005\000\027\000\015\000\ + \117\000\117\000\053\000\100\000\052\000\028\000\045\000\045\000\ + \028\000\115\000\117\000\044\000\044\000\044\000\044\000\044\000\ + \044\000\044\000\044\000\053\000\066\000\118\000\135\000\116\000\ + \115\000\115\000\100\000\117\000\028\000\046\000\046\000\046\000\ + \046\000\046\000\046\000\046\000\046\000\046\000\046\000\134\000\ + \148\000\147\000\099\000\099\000\099\000\099\000\099\000\099\000\ + \099\000\099\000\099\000\099\000\146\000\138\000\152\000\136\000\ + \155\000\117\000\051\000\137\000\158\000\050\000\200\000\000\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\118\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\208\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \002\000\003\000\000\000\203\000\003\000\003\000\003\000\051\000\ + \255\255\255\255\003\000\003\000\048\000\003\000\003\000\003\000\ + \039\000\039\000\039\000\039\000\039\000\039\000\039\000\039\000\ + \039\000\039\000\003\000\144\000\003\000\003\000\003\000\003\000\ + \003\000\000\000\096\000\096\000\052\000\038\000\084\000\000\000\ + \047\000\000\000\047\000\084\000\096\000\046\000\046\000\046\000\ + \046\000\046\000\046\000\046\000\046\000\046\000\046\000\084\000\ + \147\000\084\000\084\000\084\000\003\000\096\000\003\000\039\000\ + \102\000\000\000\171\000\101\000\003\000\038\000\000\000\003\000\ + \009\000\009\000\208\000\000\000\084\000\003\000\003\000\000\000\ + \003\000\006\000\009\000\000\000\068\000\000\000\203\000\068\000\ + \106\000\171\000\084\000\096\000\003\000\085\000\003\000\006\000\ + \006\000\006\000\003\000\009\000\171\000\171\000\000\000\000\000\ + \000\000\003\000\000\000\068\000\003\000\121\000\121\000\000\000\ + \000\000\084\000\003\000\003\000\074\000\003\000\007\000\121\000\ + \000\000\084\000\084\000\171\000\000\000\000\000\000\000\003\000\ + \084\000\009\000\120\000\000\000\007\000\007\000\007\000\003\000\ + \121\000\197\000\219\000\195\000\217\000\000\000\003\000\196\000\ + \218\000\003\000\009\000\009\000\000\000\000\000\005\000\003\000\ + \003\000\000\000\003\000\006\000\009\000\000\000\000\000\085\000\ + \084\000\003\000\000\000\000\000\003\000\005\000\121\000\085\000\ + \000\000\006\000\006\000\006\000\003\000\009\000\191\000\000\000\ + \255\255\190\000\000\000\003\000\000\000\000\000\003\000\009\000\ + \009\000\000\000\000\000\094\000\003\000\003\000\000\000\003\000\ + \009\000\009\000\000\000\000\000\120\000\005\000\003\000\000\000\ + \000\000\003\000\005\000\009\000\098\000\000\000\009\000\009\000\ + \009\000\003\000\009\000\000\000\000\000\000\000\000\000\000\000\ + \214\000\000\000\000\000\213\000\117\000\117\000\000\000\000\000\ + \194\000\000\000\193\000\111\000\111\000\115\000\117\000\005\000\ + \000\000\085\000\005\000\003\000\109\000\111\000\003\000\094\000\ + \009\000\116\000\216\000\116\000\115\000\115\000\000\000\117\000\ + \114\000\000\000\109\000\112\000\112\000\000\000\111\000\111\000\ + \111\000\000\000\080\000\084\000\000\000\080\000\000\000\000\000\ + \112\000\111\000\212\000\000\000\000\000\000\000\098\000\094\000\ + \003\000\000\000\000\000\000\000\110\000\117\000\109\000\109\000\ + \109\000\080\000\111\000\005\000\111\000\045\000\045\000\000\000\ + \000\000\000\000\081\000\003\000\000\000\000\000\003\000\009\000\ + \009\000\000\000\000\000\084\000\003\000\003\000\000\000\003\000\ + \006\000\009\000\000\000\116\000\000\000\000\000\255\255\084\000\ + \111\000\036\000\110\000\005\000\086\000\000\000\088\000\006\000\ + \006\000\003\000\087\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\045\000\044\000\044\000\044\000\ + \044\000\044\000\044\000\044\000\044\000\000\000\110\000\084\000\ + \000\000\037\000\000\000\035\000\000\000\000\000\003\000\084\000\ + \009\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \003\000\036\000\000\000\003\000\003\000\003\000\000\000\000\000\ + \083\000\003\000\003\000\000\000\003\000\003\000\003\000\060\000\ + \000\000\000\000\060\000\000\000\044\000\000\000\085\000\084\000\ + \003\000\003\000\000\000\003\000\003\000\003\000\003\000\003\000\ + \000\000\037\000\000\000\035\000\000\000\000\000\060\000\061\000\ + \000\000\000\000\061\000\064\000\064\000\000\000\000\000\000\000\ + \065\000\061\000\000\000\061\000\062\000\064\000\144\000\000\000\ + \000\000\143\000\000\000\003\000\192\000\003\000\000\000\000\000\ + \063\000\000\000\062\000\062\000\062\000\061\000\064\000\039\000\ + \000\000\022\000\022\000\022\000\022\000\022\000\022\000\022\000\ + \022\000\022\000\022\000\145\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\003\000\000\000\003\000\038\000\000\000\ + \000\000\000\000\061\000\000\000\064\000\036\000\215\000\000\000\ + \039\000\000\000\022\000\022\000\022\000\022\000\022\000\022\000\ + \022\000\022\000\022\000\022\000\000\000\000\000\000\000\000\000\ + \022\000\000\000\000\000\000\000\040\000\000\000\038\000\038\000\ + \000\000\000\000\063\000\000\000\061\000\037\000\036\000\035\000\ + \141\000\041\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\042\000\000\000\000\000\000\000\105\000\102\000\ + \000\000\022\000\101\000\000\000\040\000\000\000\000\000\038\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\037\000\000\000\ + \035\000\041\000\024\000\000\000\000\000\105\000\000\000\104\000\ + \000\000\000\000\042\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\000\000\000\000\ + \000\000\000\000\024\000\000\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\043\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\049\000\ + \049\000\049\000\049\000\049\000\049\000\049\000\049\000\049\000\ + \049\000\000\000\000\000\000\000\255\255\000\000\000\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\153\000\153\000\153\000\ + \153\000\153\000\153\000\153\000\153\000\153\000\153\000\000\000\ + \000\000\000\000\000\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\000\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\025\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\255\255\000\000\000\000\ + \000\000\000\000\000\000\000\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\000\000\000\000\ + \000\000\000\000\025\000\000\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\043\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\000\000\000\000\000\000\ + \000\000\000\000\036\000\154\000\154\000\154\000\154\000\154\000\ + \154\000\154\000\154\000\154\000\154\000\000\000\000\000\000\000\ + \163\000\000\000\000\000\162\000\000\000\043\000\000\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\000\000\000\000\000\000\ + \000\000\000\000\037\000\000\000\035\000\000\000\000\000\000\000\ + \165\000\000\000\000\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\000\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\164\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\003\000\000\000\000\000\003\000\003\000\ + \003\000\000\000\000\000\000\000\003\000\003\000\000\000\003\000\ + \003\000\003\000\172\000\172\000\172\000\172\000\172\000\172\000\ + \172\000\172\000\172\000\172\000\003\000\000\000\003\000\003\000\ + \003\000\003\000\003\000\173\000\173\000\173\000\173\000\173\000\ + \173\000\173\000\173\000\173\000\173\000\000\000\046\000\046\000\ + \046\000\046\000\046\000\046\000\046\000\046\000\046\000\046\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\003\000\000\000\ + \003\000\033\000\000\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\046\000\003\000\003\000\ + \003\000\000\000\003\000\003\000\003\000\000\000\000\000\000\000\ + \003\000\003\000\000\000\003\000\003\000\003\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \003\000\000\000\003\000\003\000\003\000\003\000\003\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\003\000\000\000\003\000\031\000\161\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\000\000\003\000\000\000\003\000\000\000\000\000\000\000\ + \000\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\100\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\059\000\059\000\059\000\059\000\059\000\059\000\ + \059\000\059\000\059\000\059\000\000\000\000\000\000\000\000\000\ + \100\000\000\000\000\000\059\000\059\000\059\000\059\000\059\000\ + \059\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \099\000\099\000\099\000\099\000\099\000\099\000\099\000\099\000\ + \099\000\099\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\059\000\059\000\059\000\059\000\059\000\ + \059\000\000\000\000\000\000\000\000\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \032\000\000\000\000\000\000\000\000\000\000\000\000\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\000\000\000\000\000\000\000\000\031\000\000\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\049\000\049\000\049\000\049\000\049\000\049\000\049\000\ + \049\000\049\000\049\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\049\000\049\000\049\000\049\000\049\000\049\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\049\000\049\000\049\000\049\000\049\000\049\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\000\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\033\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \034\000\000\000\000\000\000\000\000\000\000\000\000\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\000\000\000\000\000\000\000\000\033\000\000\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\000\000\000\000\000\000\105\000\102\000\000\000\000\000\ + \101\000\000\000\000\000\000\000\000\000\156\000\156\000\156\000\ + \156\000\156\000\156\000\156\000\156\000\156\000\156\000\000\000\ + \000\000\000\000\000\000\105\000\000\000\104\000\156\000\156\000\ + \156\000\156\000\156\000\156\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\099\000\099\000\099\000\099\000\099\000\ + \099\000\099\000\099\000\099\000\099\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\156\000\156\000\ + \156\000\156\000\156\000\156\000\000\000\000\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\000\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\000\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\057\000\000\000\ + \057\000\000\000\000\000\000\000\000\000\057\000\000\000\000\000\ + \060\000\000\000\000\000\060\000\000\000\000\000\056\000\056\000\ + \056\000\056\000\056\000\056\000\056\000\056\000\056\000\056\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\060\000\ + \078\000\000\000\000\000\078\000\078\000\078\000\000\000\000\000\ + \000\000\079\000\078\000\000\000\078\000\078\000\078\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\078\000\057\000\078\000\078\000\078\000\078\000\078\000\ + \057\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\068\000\057\000\000\000\068\000\000\000\ + \057\000\000\000\057\000\000\000\000\000\000\000\055\000\000\000\ + \000\000\000\000\000\000\078\000\000\000\078\000\000\000\000\000\ + \000\000\000\000\068\000\069\000\000\000\000\000\069\000\069\000\ + \069\000\000\000\000\000\072\000\071\000\069\000\000\000\069\000\ + \069\000\069\000\068\000\255\255\000\000\068\000\000\000\000\000\ + \000\000\000\000\000\000\078\000\069\000\078\000\069\000\069\000\ + \069\000\069\000\069\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\068\000\069\000\000\000\000\000\069\000\070\000\070\000\ + \000\000\000\000\072\000\071\000\069\000\000\000\069\000\077\000\ + \070\000\000\000\000\000\000\000\000\000\000\000\069\000\000\000\ + \069\000\000\000\000\000\077\000\000\000\077\000\077\000\077\000\ + \069\000\070\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\068\000\000\000\000\000\ + \068\000\000\000\000\000\000\000\000\000\000\000\069\000\000\000\ + \069\000\000\000\000\000\000\000\000\000\069\000\000\000\070\000\ + \000\000\000\000\000\000\000\000\068\000\069\000\000\000\000\000\ + \069\000\076\000\076\000\000\000\000\000\072\000\071\000\069\000\ + \000\000\069\000\075\000\076\000\068\000\000\000\255\255\068\000\ + \000\000\000\000\000\000\000\000\000\000\077\000\075\000\069\000\ + \075\000\075\000\075\000\069\000\076\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\068\000\069\000\000\000\000\000\069\000\ + \070\000\070\000\000\000\067\000\072\000\071\000\069\000\000\000\ + \069\000\070\000\070\000\000\000\000\000\000\000\000\000\000\000\ + \069\000\000\000\076\000\067\000\067\000\070\000\067\000\070\000\ + \070\000\070\000\069\000\070\000\067\000\067\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \067\000\000\000\067\000\067\000\067\000\000\000\067\000\000\000\ + \075\000\000\000\069\000\000\000\000\000\000\000\067\000\069\000\ + \000\000\070\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\067\000\000\000\068\000\067\000\000\000\068\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\067\000\070\000\ + \000\000\069\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\068\000\069\000\000\000\000\000\069\000\069\000\ + \069\000\067\000\067\000\073\000\071\000\069\000\000\000\069\000\ + \069\000\069\000\068\000\000\000\000\000\068\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\069\000\000\000\069\000\069\000\ + \069\000\069\000\069\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\068\000\069\000\000\000\000\000\069\000\070\000\070\000\ + \000\000\067\000\073\000\071\000\069\000\000\000\069\000\070\000\ + \070\000\000\000\000\000\000\000\000\000\000\000\069\000\000\000\ + \069\000\000\000\000\000\070\000\000\000\070\000\070\000\070\000\ + \069\000\070\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\068\000\000\000\000\000\ + \068\000\000\000\000\000\000\000\000\000\000\000\069\000\000\000\ + \069\000\000\000\000\000\000\000\067\000\069\000\000\000\070\000\ + \000\000\000\000\000\000\000\000\068\000\069\000\000\000\000\000\ + \069\000\069\000\069\000\000\000\000\000\000\000\071\000\069\000\ + \000\000\069\000\069\000\069\000\068\000\000\000\000\000\068\000\ + \000\000\000\000\000\000\000\000\067\000\070\000\069\000\069\000\ + \069\000\069\000\069\000\069\000\069\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\068\000\069\000\000\000\000\000\069\000\ + \076\000\076\000\000\000\000\000\073\000\071\000\069\000\000\000\ + \069\000\075\000\076\000\000\000\000\000\000\000\000\000\000\000\ + \069\000\000\000\069\000\000\000\000\000\075\000\000\000\075\000\ + \075\000\075\000\069\000\076\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\068\000\ + \000\000\000\000\068\000\000\000\000\000\000\000\000\000\000\000\ + \069\000\000\000\069\000\000\000\000\000\000\000\000\000\069\000\ + \000\000\076\000\000\000\000\000\000\000\000\000\068\000\069\000\ + \000\000\000\000\069\000\076\000\076\000\000\000\067\000\073\000\ + \071\000\069\000\000\000\069\000\076\000\076\000\068\000\000\000\ + \000\000\068\000\000\000\000\000\000\000\000\000\000\000\075\000\ + \076\000\069\000\076\000\076\000\076\000\069\000\076\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\068\000\069\000\000\000\ + \000\000\069\000\070\000\070\000\000\000\000\000\073\000\071\000\ + \069\000\000\000\069\000\077\000\070\000\000\000\000\000\000\000\ + \000\000\067\000\069\000\000\000\076\000\000\000\000\000\077\000\ + \000\000\077\000\077\000\077\000\069\000\070\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\080\000\000\000\000\000\080\000\000\000\000\000\000\000\ + \000\000\067\000\076\000\000\000\069\000\000\000\000\000\000\000\ + \000\000\069\000\000\000\070\000\000\000\000\000\000\000\000\000\ + \080\000\078\000\000\000\000\000\078\000\078\000\078\000\000\000\ + \000\000\082\000\079\000\078\000\000\000\078\000\078\000\078\000\ + \080\000\000\000\000\000\080\000\000\000\000\000\000\000\000\000\ + \000\000\077\000\078\000\069\000\078\000\078\000\078\000\078\000\ + \078\000\000\000\000\000\000\000\000\000\000\000\000\000\080\000\ + \078\000\000\000\000\000\078\000\078\000\078\000\000\000\000\000\ + \000\000\079\000\078\000\000\000\078\000\078\000\078\000\000\000\ + \000\000\000\000\000\000\000\000\078\000\000\000\078\000\000\000\ + \000\000\078\000\000\000\078\000\078\000\078\000\078\000\078\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\096\000\ + \096\000\000\000\000\000\084\000\000\000\000\000\000\000\000\000\ + \084\000\096\000\000\000\000\000\078\000\000\000\078\000\000\000\ + \000\000\000\000\000\000\078\000\084\000\078\000\084\000\084\000\ + \084\000\000\000\096\000\000\000\000\000\000\000\000\000\000\000\ + \003\000\000\000\000\000\003\000\009\000\009\000\000\000\000\000\ + \005\000\003\000\003\000\000\000\003\000\006\000\009\000\000\000\ + \000\000\000\000\000\000\078\000\000\000\078\000\000\000\084\000\ + \096\000\085\000\000\000\006\000\006\000\006\000\003\000\009\000\ + \000\000\000\000\000\000\000\000\000\000\003\000\000\000\000\000\ + \003\000\009\000\009\000\000\000\000\000\005\000\003\000\003\000\ + \000\000\003\000\006\000\009\000\000\000\000\000\084\000\084\000\ + \000\000\000\000\000\000\003\000\084\000\009\000\085\000\000\000\ + \006\000\006\000\006\000\003\000\009\000\000\000\000\000\000\000\ + \000\000\000\000\003\000\000\000\000\000\003\000\009\000\009\000\ + \000\000\000\000\094\000\003\000\003\000\000\000\003\000\009\000\ + \009\000\000\000\000\000\085\000\005\000\003\000\000\000\000\000\ + \003\000\084\000\009\000\098\000\000\000\009\000\009\000\009\000\ + \003\000\009\000\000\000\000\000\000\000\000\000\000\000\090\000\ + \000\000\000\000\003\000\093\000\093\000\000\000\000\000\084\000\ + \090\000\090\000\000\000\090\000\091\000\093\000\000\000\000\000\ + \085\000\005\000\003\000\000\000\000\000\003\000\094\000\009\000\ + \092\000\000\000\006\000\091\000\089\000\090\000\093\000\000\000\ + \000\000\000\000\000\000\000\000\003\000\000\000\000\000\003\000\ + \009\000\009\000\000\000\000\000\084\000\003\000\003\000\000\000\ + \003\000\006\000\009\000\000\000\000\000\098\000\094\000\003\000\ + \000\000\000\000\090\000\084\000\093\000\085\000\000\000\006\000\ + \006\000\097\000\003\000\009\000\000\000\000\000\000\000\000\000\ + \000\000\090\000\000\000\000\000\003\000\090\000\090\000\000\000\ + \000\000\000\000\090\000\090\000\000\000\090\000\090\000\090\000\ + \000\000\000\000\092\000\084\000\090\000\000\000\000\000\003\000\ + \084\000\009\000\090\000\000\000\003\000\090\000\003\000\090\000\ + \090\000\000\000\000\000\000\000\090\000\000\000\000\000\003\000\ + \093\000\093\000\000\000\000\000\084\000\090\000\090\000\000\000\ + \090\000\091\000\093\000\000\000\000\000\000\000\000\000\085\000\ + \084\000\003\000\000\000\000\000\090\000\092\000\090\000\006\000\ + \091\000\006\000\090\000\093\000\000\000\000\000\000\000\000\000\ + \000\000\090\000\000\000\000\000\003\000\093\000\093\000\000\000\ + \000\000\005\000\090\000\090\000\000\000\090\000\091\000\093\000\ + \000\000\000\000\000\000\000\000\090\000\000\000\090\000\090\000\ + \084\000\093\000\092\000\000\000\006\000\091\000\006\000\090\000\ + \093\000\000\000\000\000\000\000\000\000\000\000\090\000\000\000\ + \000\000\003\000\093\000\093\000\000\000\000\000\094\000\090\000\ + \090\000\000\000\090\000\093\000\093\000\000\000\000\000\092\000\ + \084\000\090\000\000\000\000\000\090\000\084\000\093\000\095\000\ + \000\000\009\000\093\000\009\000\090\000\093\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\096\000\ + \096\000\000\000\000\000\094\000\000\000\000\000\000\000\000\000\ + \096\000\096\000\000\000\000\000\092\000\005\000\090\000\000\000\ + \000\000\090\000\094\000\093\000\096\000\000\000\096\000\096\000\ + \096\000\000\000\096\000\000\000\000\000\000\000\000\000\000\000\ + \090\000\000\000\000\000\003\000\093\000\093\000\000\000\000\000\ + \094\000\090\000\090\000\000\000\090\000\093\000\093\000\000\000\ + \000\000\095\000\094\000\090\000\000\000\000\000\000\000\094\000\ + \096\000\095\000\000\000\009\000\093\000\009\000\090\000\093\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\096\000\096\000\000\000\000\000\094\000\000\000\000\000\ + \000\000\000\000\096\000\096\000\000\000\000\000\096\000\094\000\ + \000\000\000\000\000\000\090\000\094\000\093\000\096\000\000\000\ + \096\000\096\000\096\000\000\000\096\000\000\000\000\000\000\000\ + \000\000\000\000\003\000\000\000\000\000\003\000\009\000\009\000\ + \000\000\000\000\084\000\003\000\003\000\000\000\003\000\006\000\ + \009\000\000\000\000\000\095\000\094\000\090\000\000\000\000\000\ + \000\000\094\000\096\000\085\000\000\000\006\000\006\000\006\000\ + \003\000\009\000\000\000\000\000\000\000\000\000\000\000\003\000\ + \000\000\000\000\003\000\009\000\009\000\000\000\000\000\094\000\ + \003\000\003\000\000\000\003\000\009\000\009\000\000\000\000\000\ + \096\000\094\000\000\000\000\000\000\000\003\000\084\000\009\000\ + \098\000\000\000\009\000\009\000\009\000\003\000\009\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \111\000\111\000\000\000\000\000\084\000\000\000\000\000\111\000\ + \111\000\109\000\111\000\005\000\000\000\085\000\084\000\003\000\ + \109\000\111\000\003\000\094\000\009\000\110\000\000\000\109\000\ + \109\000\109\000\000\000\111\000\110\000\000\000\109\000\109\000\ + \109\000\000\000\111\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\111\000\111\000\000\000\000\000\ + \094\000\000\000\098\000\094\000\003\000\111\000\111\000\000\000\ + \084\000\111\000\000\000\000\000\000\000\000\000\000\000\084\000\ + \111\000\113\000\000\000\111\000\111\000\111\000\000\000\111\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\111\000\111\000\000\000\000\000\084\000\000\000\110\000\ + \084\000\000\000\109\000\111\000\000\000\000\000\110\000\005\000\ + \000\000\000\000\000\000\000\000\094\000\111\000\110\000\000\000\ + \109\000\109\000\109\000\000\000\111\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\111\000\111\000\ + \000\000\000\000\094\000\000\000\000\000\111\000\111\000\111\000\ + \111\000\005\000\000\000\113\000\094\000\000\000\109\000\111\000\ + \000\000\084\000\111\000\113\000\000\000\111\000\111\000\111\000\ + \000\000\111\000\110\000\000\000\109\000\109\000\109\000\000\000\ + \111\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\117\000\117\000\000\000\000\000\000\000\000\000\ + \110\000\084\000\000\000\115\000\117\000\000\000\094\000\111\000\ + \000\000\000\000\000\000\000\000\000\000\084\000\111\000\115\000\ + \000\000\116\000\115\000\115\000\000\000\117\000\000\000\000\000\ + \000\000\117\000\117\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\115\000\117\000\000\000\113\000\094\000\000\000\ + \000\000\000\000\000\000\000\000\110\000\005\000\115\000\000\000\ + \116\000\115\000\115\000\117\000\117\000\117\000\117\000\000\000\ + \067\000\000\000\000\000\000\000\000\000\000\000\117\000\117\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\117\000\000\000\117\000\117\000\117\000\000\000\ + \117\000\115\000\117\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\119\000\119\000\000\000\000\000\000\000\119\000\ + \119\000\000\000\067\000\118\000\119\000\000\000\000\000\000\000\ + \119\000\119\000\000\000\067\000\000\000\000\000\117\000\118\000\ + \115\000\118\000\118\000\118\000\119\000\119\000\119\000\119\000\ + \119\000\000\000\119\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\067\000\117\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\119\000\000\000\067\000\000\000\000\000\ + \119\000\000\000\000\000\000\000\000\000\000\000\003\000\000\000\ + \000\000\003\000\121\000\121\000\000\000\000\000\005\000\003\000\ + \003\000\000\000\003\000\007\000\121\000\000\000\000\000\000\000\ + \000\000\118\000\000\000\000\000\000\000\067\000\119\000\120\000\ + \000\000\007\000\007\000\007\000\003\000\121\000\000\000\000\000\ + \000\000\000\000\000\000\003\000\000\000\000\000\003\000\121\000\ + \121\000\000\000\000\000\094\000\003\000\003\000\000\000\003\000\ + \121\000\121\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\003\000\005\000\121\000\122\000\000\000\121\000\121\000\ + \121\000\003\000\121\000\000\000\000\000\000\000\000\000\000\000\ + \003\000\000\000\000\000\003\000\121\000\121\000\000\000\000\000\ + \094\000\003\000\003\000\000\000\003\000\121\000\121\000\000\000\ + \000\000\120\000\005\000\003\000\000\000\000\000\003\000\094\000\ + \121\000\122\000\000\000\121\000\121\000\121\000\003\000\121\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\126\000\ + \000\000\000\000\125\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\122\000\094\000\ + \003\000\000\000\000\000\003\000\094\000\121\000\000\000\129\000\ + \000\000\000\000\000\000\000\000\128\000\133\000\000\000\132\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\131\000\000\000\122\000\094\000\003\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \000\000\000\000\000\000\000\000\130\000\000\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \157\000\157\000\157\000\157\000\157\000\157\000\157\000\157\000\ + \157\000\157\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\157\000\157\000\157\000\157\000\157\000\157\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\157\000\157\000\157\000\157\000\157\000\157\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\000\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\000\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\127\000\130\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\000\000\000\000\000\000\000\000\130\000\000\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\000\000\000\000\000\000\000\000\140\000\000\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\000\000\000\000\000\000\000\000\000\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\000\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\000\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\000\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\000\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\000\000\000\000\000\000\000\000\139\000\000\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\174\000\174\000\174\000\174\000\174\000\174\000\174\000\ + \174\000\174\000\174\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\174\000\174\000\174\000\174\000\174\000\174\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\174\000\174\000\174\000\174\000\174\000\174\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\000\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \000\000\000\000\136\000\000\000\000\000\000\000\137\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\000\000\000\000\000\000\000\000\139\000\000\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\175\000\175\000\175\000\175\000\175\000\175\000\175\000\ + \175\000\175\000\175\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\175\000\175\000\175\000\175\000\175\000\175\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\175\000\175\000\175\000\175\000\175\000\175\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\000\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\140\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \000\000\000\000\136\000\000\000\000\000\000\000\000\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\000\000\000\000\000\000\000\000\140\000\000\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\000\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\000\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\151\000\000\000\ + \151\000\000\000\000\000\171\000\000\000\151\000\170\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\150\000\150\000\ + \150\000\150\000\150\000\150\000\150\000\150\000\150\000\150\000\ + \000\000\169\000\000\000\169\000\000\000\000\000\000\000\000\000\ + \169\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\168\000\168\000\168\000\168\000\168\000\168\000\168\000\ + \168\000\168\000\168\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\151\000\000\000\000\000\000\000\000\000\000\000\ + \151\000\176\000\000\000\000\000\176\000\176\000\176\000\000\000\ + \000\000\000\000\176\000\176\000\151\000\176\000\176\000\176\000\ + \151\000\000\000\151\000\000\000\000\000\169\000\149\000\000\000\ + \000\000\000\000\176\000\169\000\176\000\176\000\176\000\176\000\ + \176\000\000\000\000\000\000\000\000\000\000\000\000\000\169\000\ + \000\000\000\000\000\000\169\000\000\000\169\000\000\000\000\000\ + \000\000\167\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\176\000\000\000\176\000\000\000\ + \000\000\000\000\000\000\000\000\178\000\000\000\000\000\178\000\ + \178\000\178\000\000\000\000\000\000\000\178\000\178\000\000\000\ + \178\000\178\000\178\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\176\000\178\000\176\000\178\000\ + \178\000\178\000\178\000\178\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\000\000\178\000\ + \000\000\178\000\179\000\000\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\000\000\178\000\ + \000\000\178\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\255\255\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\000\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\000\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\178\000\000\000\000\000\178\000\178\000\ + \178\000\000\000\000\000\000\000\178\000\178\000\000\000\178\000\ + \178\000\178\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\178\000\000\000\178\000\178\000\ + \178\000\178\000\178\000\000\000\000\000\000\000\000\000\179\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\000\000\000\000\180\000\000\000\178\000\000\000\ + \178\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\000\000\000\000\000\000\178\000\179\000\ + \178\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\000\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\000\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \182\000\000\000\000\000\182\000\182\000\182\000\000\000\000\000\ + \000\000\182\000\182\000\000\000\182\000\182\000\182\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\182\000\000\000\182\000\182\000\182\000\182\000\182\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\000\000\182\000\000\000\182\000\183\000\000\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\000\000\182\000\000\000\182\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\182\000\ + \000\000\000\000\182\000\182\000\182\000\000\000\000\000\000\000\ + \182\000\182\000\000\000\182\000\182\000\182\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \182\000\000\000\182\000\182\000\182\000\182\000\182\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\183\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\000\000\182\000\185\000\182\000\000\000\000\000\184\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\182\000\000\000\182\000\000\000\183\000\000\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\000\000\000\000\000\000\000\000\186\000\000\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\000\000\000\000\000\000\000\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\000\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\000\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\000\000\000\000\187\000\000\000\000\000\000\000\000\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\000\000\000\000\000\000\000\000\186\000\000\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\000\000\000\000\000\000\000\000\199\000\000\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\000\000\000\000\000\000\000\000\000\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\000\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\000\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\000\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\000\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\000\000\000\000\000\000\000\000\198\000\000\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\000\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \000\000\000\000\195\000\000\000\000\000\000\000\196\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\000\000\000\000\000\000\000\000\198\000\000\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\000\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\199\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \000\000\000\000\195\000\000\000\000\000\000\000\000\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\000\000\000\000\000\000\000\000\199\000\000\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\000\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\000\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\207\000\000\000\ + \000\000\205\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \204\000\000\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\203\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\000\000\000\000\000\000\ + \000\000\205\000\206\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\000\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\000\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\255\255\209\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\203\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\000\000\ + \000\000\000\000\000\000\209\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\000\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\000\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\208\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\203\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \000\000\000\000\000\000\000\000\209\000\000\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\203\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \000\000\000\000\000\000\000\000\209\000\000\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \000\000\000\000\000\000\000\000\221\000\000\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \000\000\000\000\000\000\000\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\000\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\000\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\000\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\000\000\ + \000\000\000\000\000\000\220\000\000\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\000\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\000\000\000\000\ + \217\000\000\000\000\000\000\000\218\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\000\000\ + \000\000\000\000\000\000\220\000\000\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\000\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\221\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\000\000\000\000\ + \217\000\000\000\000\000\000\000\000\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\000\000\ + \000\000\000\000\000\000\221\000\000\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\000\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\000\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\000\000"; + Lexing.lex_check = + "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\000\000\000\000\029\000\000\000\000\000\101\000\107\000\ + \125\000\162\000\103\000\106\000\190\000\103\000\106\000\213\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\012\000\ + \010\000\010\000\049\000\016\000\051\000\028\000\040\000\040\000\ + \028\000\010\000\010\000\041\000\041\000\041\000\041\000\041\000\ + \041\000\041\000\041\000\057\000\065\000\010\000\132\000\010\000\ + \010\000\010\000\016\000\010\000\028\000\047\000\047\000\047\000\ + \047\000\047\000\047\000\047\000\047\000\047\000\047\000\133\000\ + \142\000\144\000\016\000\016\000\016\000\016\000\016\000\016\000\ + \016\000\016\000\016\000\016\000\145\000\131\000\151\000\131\000\ + \154\000\010\000\020\000\131\000\157\000\020\000\193\000\255\255\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\010\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\204\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\003\000\255\255\204\000\003\000\003\000\003\000\050\000\ + \103\000\106\000\003\000\003\000\020\000\003\000\003\000\003\000\ + \039\000\039\000\039\000\039\000\039\000\039\000\039\000\039\000\ + \039\000\039\000\003\000\143\000\003\000\003\000\003\000\003\000\ + \003\000\255\255\005\000\005\000\050\000\039\000\005\000\255\255\ + \038\000\255\255\038\000\005\000\005\000\038\000\038\000\038\000\ + \038\000\038\000\038\000\038\000\038\000\038\000\038\000\005\000\ + \143\000\005\000\005\000\005\000\003\000\005\000\003\000\039\000\ + \104\000\255\255\171\000\104\000\006\000\039\000\255\255\006\000\ + \006\000\006\000\208\000\255\255\006\000\006\000\006\000\255\255\ + \006\000\006\000\006\000\255\255\068\000\255\255\208\000\068\000\ + \104\000\171\000\005\000\005\000\003\000\006\000\003\000\006\000\ + \006\000\006\000\006\000\006\000\170\000\170\000\255\255\255\255\ + \255\255\007\000\255\255\068\000\007\000\007\000\007\000\255\255\ + \255\255\007\000\007\000\007\000\068\000\007\000\007\000\007\000\ + \255\255\005\000\005\000\170\000\255\255\255\255\255\255\006\000\ + \006\000\006\000\007\000\255\255\007\000\007\000\007\000\007\000\ + \007\000\194\000\212\000\194\000\212\000\255\255\008\000\194\000\ + \212\000\008\000\008\000\008\000\255\255\255\255\008\000\008\000\ + \008\000\255\255\008\000\008\000\008\000\255\255\255\255\006\000\ + \006\000\006\000\255\255\255\255\007\000\007\000\007\000\008\000\ + \255\255\008\000\008\000\008\000\008\000\008\000\188\000\255\255\ + \020\000\188\000\255\255\009\000\255\255\255\255\009\000\009\000\ + \009\000\255\255\255\255\009\000\009\000\009\000\255\255\009\000\ + \009\000\009\000\255\255\255\255\007\000\007\000\007\000\255\255\ + \255\255\008\000\008\000\008\000\009\000\255\255\009\000\009\000\ + \009\000\009\000\009\000\255\255\255\255\255\255\255\255\255\255\ + \210\000\255\255\255\255\210\000\011\000\011\000\255\255\255\255\ + \188\000\255\255\188\000\013\000\013\000\011\000\011\000\013\000\ + \255\255\008\000\008\000\008\000\013\000\013\000\009\000\009\000\ + \009\000\011\000\210\000\011\000\011\000\011\000\255\255\011\000\ + \013\000\255\255\013\000\013\000\013\000\255\255\013\000\014\000\ + \014\000\255\255\080\000\014\000\255\255\080\000\255\255\255\255\ + \014\000\014\000\210\000\255\255\255\255\255\255\009\000\009\000\ + \009\000\255\255\255\255\255\255\014\000\011\000\014\000\014\000\ + \014\000\080\000\014\000\013\000\013\000\045\000\045\000\255\255\ + \255\255\255\255\080\000\017\000\255\255\255\255\017\000\017\000\ + \017\000\255\255\255\255\017\000\017\000\017\000\255\255\017\000\ + \017\000\017\000\255\255\011\000\255\255\255\255\104\000\014\000\ + \014\000\045\000\013\000\013\000\017\000\255\255\017\000\017\000\ + \017\000\017\000\017\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\045\000\044\000\044\000\044\000\ + \044\000\044\000\044\000\044\000\044\000\255\255\014\000\014\000\ + \255\255\045\000\255\255\045\000\255\255\255\255\017\000\017\000\ + \017\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \018\000\044\000\255\255\018\000\018\000\018\000\255\255\255\255\ + \018\000\018\000\018\000\255\255\018\000\018\000\018\000\019\000\ + \255\255\255\255\019\000\255\255\044\000\255\255\017\000\017\000\ + \017\000\018\000\255\255\018\000\018\000\018\000\018\000\018\000\ + \255\255\044\000\255\255\044\000\255\255\255\255\019\000\019\000\ + \255\255\255\255\019\000\019\000\019\000\255\255\255\255\255\255\ + \019\000\019\000\255\255\019\000\019\000\019\000\128\000\255\255\ + \255\255\128\000\255\255\018\000\188\000\018\000\255\255\255\255\ + \019\000\255\255\019\000\019\000\019\000\019\000\019\000\022\000\ + \255\255\022\000\022\000\022\000\022\000\022\000\022\000\022\000\ + \022\000\022\000\022\000\128\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\018\000\255\255\018\000\022\000\255\255\ + \255\255\255\255\019\000\255\255\019\000\022\000\210\000\255\255\ + \023\000\255\255\023\000\023\000\023\000\023\000\023\000\023\000\ + \023\000\023\000\023\000\023\000\255\255\255\255\255\255\255\255\ + \022\000\255\255\255\255\255\255\023\000\255\255\022\000\023\000\ + \255\255\255\255\019\000\255\255\019\000\022\000\023\000\022\000\ + \128\000\023\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\023\000\255\255\255\255\255\255\105\000\105\000\ + \255\255\023\000\105\000\255\255\023\000\255\255\255\255\023\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\023\000\255\255\ + \023\000\023\000\024\000\255\255\255\255\105\000\255\255\105\000\ + \255\255\255\255\023\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\255\255\255\255\ + \255\255\255\255\024\000\255\255\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\042\000\042\000\ + \042\000\042\000\042\000\042\000\042\000\042\000\042\000\042\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\042\000\ + \042\000\042\000\042\000\042\000\042\000\056\000\056\000\056\000\ + \056\000\056\000\056\000\056\000\056\000\056\000\056\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\255\255\255\255\255\255\128\000\255\255\255\255\042\000\ + \042\000\042\000\042\000\042\000\042\000\150\000\150\000\150\000\ + \150\000\150\000\150\000\150\000\150\000\150\000\150\000\255\255\ + \255\255\255\255\255\255\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\255\255\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\025\000\024\000\024\000\024\000\024\000\024\000\ + \024\000\024\000\024\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\105\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\255\255\255\255\ + \255\255\255\255\025\000\255\255\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\043\000\043\000\ + \043\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\043\000\ + \043\000\043\000\043\000\043\000\043\000\255\255\255\255\255\255\ + \255\255\255\255\043\000\153\000\153\000\153\000\153\000\153\000\ + \153\000\153\000\153\000\153\000\153\000\255\255\255\255\255\255\ + \159\000\255\255\255\255\159\000\255\255\043\000\255\255\043\000\ + \043\000\043\000\043\000\043\000\043\000\255\255\255\255\255\255\ + \255\255\255\255\043\000\255\255\043\000\255\255\255\255\255\255\ + \159\000\255\255\255\255\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\255\255\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\159\000\025\000\025\000\025\000\025\000\025\000\ + \025\000\025\000\025\000\026\000\255\255\255\255\026\000\026\000\ + \026\000\255\255\255\255\255\255\026\000\026\000\255\255\026\000\ + \026\000\026\000\168\000\168\000\168\000\168\000\168\000\168\000\ + \168\000\168\000\168\000\168\000\026\000\255\255\026\000\026\000\ + \026\000\026\000\026\000\172\000\172\000\172\000\172\000\172\000\ + \172\000\172\000\172\000\172\000\172\000\255\255\046\000\046\000\ + \046\000\046\000\046\000\046\000\046\000\046\000\046\000\046\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\026\000\255\255\ + \026\000\026\000\255\255\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\026\000\026\000\026\000\046\000\026\000\027\000\ + \026\000\255\255\027\000\027\000\027\000\255\255\255\255\255\255\ + \027\000\027\000\255\255\027\000\027\000\027\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \027\000\255\255\027\000\027\000\027\000\027\000\027\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\027\000\255\255\027\000\027\000\159\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\ + \027\000\255\255\027\000\255\255\027\000\255\255\255\255\255\255\ + \255\255\026\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\100\000\026\000\026\000\026\000\026\000\026\000\026\000\ + \026\000\026\000\055\000\055\000\055\000\055\000\055\000\055\000\ + \055\000\055\000\055\000\055\000\255\255\255\255\255\255\255\255\ + \100\000\255\255\255\255\055\000\055\000\055\000\055\000\055\000\ + \055\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \100\000\100\000\100\000\100\000\100\000\100\000\100\000\100\000\ + \100\000\100\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\055\000\055\000\055\000\055\000\055\000\ + \055\000\255\255\255\255\255\255\255\255\027\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\031\000\027\000\027\000\ + \027\000\027\000\027\000\027\000\027\000\027\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\255\255\255\255\255\255\255\255\255\255\255\255\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\255\255\255\255\255\255\255\255\031\000\255\255\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\059\000\059\000\059\000\059\000\059\000\059\000\059\000\ + \059\000\059\000\059\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\059\000\059\000\059\000\059\000\059\000\059\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\059\000\059\000\059\000\059\000\059\000\059\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\255\255\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\033\000\031\000\031\000\ + \031\000\031\000\031\000\031\000\031\000\031\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\255\255\255\255\255\255\255\255\255\255\255\255\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\255\255\255\255\255\255\255\255\033\000\255\255\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\255\255\255\255\255\255\099\000\099\000\255\255\255\255\ + \099\000\255\255\255\255\255\255\255\255\149\000\149\000\149\000\ + \149\000\149\000\149\000\149\000\149\000\149\000\149\000\255\255\ + \255\255\255\255\255\255\099\000\255\255\099\000\149\000\149\000\ + \149\000\149\000\149\000\149\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\099\000\099\000\099\000\099\000\099\000\ + \099\000\099\000\099\000\099\000\099\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\149\000\149\000\ + \149\000\149\000\149\000\149\000\255\255\255\255\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\255\255\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\255\255\033\000\033\000\ + \033\000\033\000\033\000\033\000\033\000\033\000\048\000\255\255\ + \048\000\255\255\255\255\255\255\255\255\048\000\255\255\255\255\ + \060\000\255\255\255\255\060\000\255\255\255\255\048\000\048\000\ + \048\000\048\000\048\000\048\000\048\000\048\000\048\000\048\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\060\000\ + \060\000\255\255\255\255\060\000\060\000\060\000\255\255\255\255\ + \255\255\060\000\060\000\255\255\060\000\060\000\060\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\060\000\048\000\060\000\060\000\060\000\060\000\060\000\ + \048\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\061\000\048\000\255\255\061\000\255\255\ + \048\000\255\255\048\000\255\255\255\255\255\255\048\000\255\255\ + \255\255\255\255\255\255\060\000\255\255\060\000\255\255\255\255\ + \255\255\255\255\061\000\061\000\255\255\255\255\061\000\061\000\ + \061\000\255\255\255\255\061\000\061\000\061\000\255\255\061\000\ + \061\000\061\000\062\000\099\000\255\255\062\000\255\255\255\255\ + \255\255\255\255\255\255\060\000\061\000\060\000\061\000\061\000\ + \061\000\061\000\061\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\062\000\062\000\255\255\255\255\062\000\062\000\062\000\ + \255\255\255\255\062\000\062\000\062\000\255\255\062\000\062\000\ + \062\000\255\255\255\255\255\255\255\255\255\255\061\000\255\255\ + \061\000\255\255\255\255\062\000\255\255\062\000\062\000\062\000\ + \062\000\062\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\063\000\255\255\255\255\ + \063\000\255\255\255\255\255\255\255\255\255\255\061\000\255\255\ + \061\000\255\255\255\255\255\255\255\255\062\000\255\255\062\000\ + \255\255\255\255\255\255\255\255\063\000\063\000\255\255\255\255\ + \063\000\063\000\063\000\255\255\255\255\063\000\063\000\063\000\ + \255\255\063\000\063\000\063\000\064\000\255\255\048\000\064\000\ + \255\255\255\255\255\255\255\255\255\255\062\000\063\000\062\000\ + \063\000\063\000\063\000\063\000\063\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\064\000\064\000\255\255\255\255\064\000\ + \064\000\064\000\255\255\064\000\064\000\064\000\064\000\255\255\ + \064\000\064\000\064\000\255\255\255\255\255\255\255\255\255\255\ + \063\000\255\255\063\000\067\000\067\000\064\000\067\000\064\000\ + \064\000\064\000\064\000\064\000\067\000\067\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \067\000\255\255\067\000\067\000\067\000\255\255\067\000\255\255\ + \063\000\255\255\063\000\255\255\255\255\255\255\064\000\064\000\ + \255\255\064\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\067\000\255\255\069\000\067\000\255\255\069\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\064\000\064\000\ + \255\255\064\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\069\000\069\000\255\255\255\255\069\000\069\000\ + \069\000\067\000\067\000\069\000\069\000\069\000\255\255\069\000\ + \069\000\069\000\070\000\255\255\255\255\070\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\069\000\255\255\069\000\069\000\ + \069\000\069\000\069\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\070\000\070\000\255\255\255\255\070\000\070\000\070\000\ + \255\255\070\000\070\000\070\000\070\000\255\255\070\000\070\000\ + \070\000\255\255\255\255\255\255\255\255\255\255\069\000\255\255\ + \069\000\255\255\255\255\070\000\255\255\070\000\070\000\070\000\ + \070\000\070\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\071\000\255\255\255\255\ + \071\000\255\255\255\255\255\255\255\255\255\255\069\000\255\255\ + \069\000\255\255\255\255\255\255\070\000\070\000\255\255\070\000\ + \255\255\255\255\255\255\255\255\071\000\071\000\255\255\255\255\ + \071\000\071\000\071\000\255\255\255\255\255\255\071\000\071\000\ + \255\255\071\000\071\000\071\000\075\000\255\255\255\255\075\000\ + \255\255\255\255\255\255\255\255\070\000\070\000\071\000\070\000\ + \071\000\071\000\071\000\071\000\071\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\075\000\075\000\255\255\255\255\075\000\ + \075\000\075\000\255\255\255\255\075\000\075\000\075\000\255\255\ + \075\000\075\000\075\000\255\255\255\255\255\255\255\255\255\255\ + \071\000\255\255\071\000\255\255\255\255\075\000\255\255\075\000\ + \075\000\075\000\075\000\075\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\076\000\ + \255\255\255\255\076\000\255\255\255\255\255\255\255\255\255\255\ + \071\000\255\255\071\000\255\255\255\255\255\255\255\255\075\000\ + \255\255\075\000\255\255\255\255\255\255\255\255\076\000\076\000\ + \255\255\255\255\076\000\076\000\076\000\255\255\076\000\076\000\ + \076\000\076\000\255\255\076\000\076\000\076\000\077\000\255\255\ + \255\255\077\000\255\255\255\255\255\255\255\255\255\255\075\000\ + \076\000\075\000\076\000\076\000\076\000\076\000\076\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\077\000\077\000\255\255\ + \255\255\077\000\077\000\077\000\255\255\255\255\077\000\077\000\ + \077\000\255\255\077\000\077\000\077\000\255\255\255\255\255\255\ + \255\255\076\000\076\000\255\255\076\000\255\255\255\255\077\000\ + \255\255\077\000\077\000\077\000\077\000\077\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\078\000\255\255\255\255\078\000\255\255\255\255\255\255\ + \255\255\076\000\076\000\255\255\076\000\255\255\255\255\255\255\ + \255\255\077\000\255\255\077\000\255\255\255\255\255\255\255\255\ + \078\000\078\000\255\255\255\255\078\000\078\000\078\000\255\255\ + \255\255\078\000\078\000\078\000\255\255\078\000\078\000\078\000\ + \079\000\255\255\255\255\079\000\255\255\255\255\255\255\255\255\ + \255\255\077\000\078\000\077\000\078\000\078\000\078\000\078\000\ + \078\000\255\255\255\255\255\255\255\255\255\255\255\255\079\000\ + \079\000\255\255\255\255\079\000\079\000\079\000\255\255\255\255\ + \255\255\079\000\079\000\255\255\079\000\079\000\079\000\255\255\ + \255\255\255\255\255\255\255\255\078\000\255\255\078\000\255\255\ + \255\255\079\000\255\255\079\000\079\000\079\000\079\000\079\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\084\000\ + \084\000\255\255\255\255\084\000\255\255\255\255\255\255\255\255\ + \084\000\084\000\255\255\255\255\078\000\255\255\078\000\255\255\ + \255\255\255\255\255\255\079\000\084\000\079\000\084\000\084\000\ + \084\000\255\255\084\000\255\255\255\255\255\255\255\255\255\255\ + \085\000\255\255\255\255\085\000\085\000\085\000\255\255\255\255\ + \085\000\085\000\085\000\255\255\085\000\085\000\085\000\255\255\ + \255\255\255\255\255\255\079\000\255\255\079\000\255\255\084\000\ + \084\000\085\000\255\255\085\000\085\000\085\000\085\000\085\000\ + \255\255\255\255\255\255\255\255\255\255\086\000\255\255\255\255\ + \086\000\086\000\086\000\255\255\255\255\086\000\086\000\086\000\ + \255\255\086\000\086\000\086\000\255\255\255\255\084\000\084\000\ + \255\255\255\255\255\255\085\000\085\000\085\000\086\000\255\255\ + \086\000\086\000\086\000\086\000\086\000\255\255\255\255\255\255\ + \255\255\255\255\087\000\255\255\255\255\087\000\087\000\087\000\ + \255\255\255\255\087\000\087\000\087\000\255\255\087\000\087\000\ + \087\000\255\255\255\255\085\000\085\000\085\000\255\255\255\255\ + \086\000\086\000\086\000\087\000\255\255\087\000\087\000\087\000\ + \087\000\087\000\255\255\255\255\255\255\255\255\255\255\088\000\ + \255\255\255\255\088\000\088\000\088\000\255\255\255\255\088\000\ + \088\000\088\000\255\255\088\000\088\000\088\000\255\255\255\255\ + \086\000\086\000\086\000\255\255\255\255\087\000\087\000\087\000\ + \088\000\255\255\088\000\088\000\088\000\088\000\088\000\255\255\ + \255\255\255\255\255\255\255\255\089\000\255\255\255\255\089\000\ + \089\000\089\000\255\255\255\255\089\000\089\000\089\000\255\255\ + \089\000\089\000\089\000\255\255\255\255\087\000\087\000\087\000\ + \255\255\255\255\088\000\088\000\088\000\089\000\255\255\089\000\ + \089\000\089\000\089\000\089\000\255\255\255\255\255\255\255\255\ + \255\255\090\000\255\255\255\255\090\000\090\000\090\000\255\255\ + \255\255\255\255\090\000\090\000\255\255\090\000\090\000\090\000\ + \255\255\255\255\088\000\088\000\088\000\255\255\255\255\089\000\ + \089\000\089\000\090\000\255\255\090\000\090\000\090\000\090\000\ + \090\000\255\255\255\255\255\255\091\000\255\255\255\255\091\000\ + \091\000\091\000\255\255\255\255\091\000\091\000\091\000\255\255\ + \091\000\091\000\091\000\255\255\255\255\255\255\255\255\089\000\ + \089\000\089\000\255\255\255\255\090\000\091\000\090\000\091\000\ + \091\000\091\000\091\000\091\000\255\255\255\255\255\255\255\255\ + \255\255\092\000\255\255\255\255\092\000\092\000\092\000\255\255\ + \255\255\092\000\092\000\092\000\255\255\092\000\092\000\092\000\ + \255\255\255\255\255\255\255\255\090\000\255\255\090\000\091\000\ + \091\000\091\000\092\000\255\255\092\000\092\000\092\000\092\000\ + \092\000\255\255\255\255\255\255\255\255\255\255\093\000\255\255\ + \255\255\093\000\093\000\093\000\255\255\255\255\093\000\093\000\ + \093\000\255\255\093\000\093\000\093\000\255\255\255\255\091\000\ + \091\000\091\000\255\255\255\255\092\000\092\000\092\000\093\000\ + \255\255\093\000\093\000\093\000\093\000\093\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\094\000\ + \094\000\255\255\255\255\094\000\255\255\255\255\255\255\255\255\ + \094\000\094\000\255\255\255\255\092\000\092\000\092\000\255\255\ + \255\255\093\000\093\000\093\000\094\000\255\255\094\000\094\000\ + \094\000\255\255\094\000\255\255\255\255\255\255\255\255\255\255\ + \095\000\255\255\255\255\095\000\095\000\095\000\255\255\255\255\ + \095\000\095\000\095\000\255\255\095\000\095\000\095\000\255\255\ + \255\255\093\000\093\000\093\000\255\255\255\255\255\255\094\000\ + \094\000\095\000\255\255\095\000\095\000\095\000\095\000\095\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\096\000\096\000\255\255\255\255\096\000\255\255\255\255\ + \255\255\255\255\096\000\096\000\255\255\255\255\094\000\094\000\ + \255\255\255\255\255\255\095\000\095\000\095\000\096\000\255\255\ + \096\000\096\000\096\000\255\255\096\000\255\255\255\255\255\255\ + \255\255\255\255\097\000\255\255\255\255\097\000\097\000\097\000\ + \255\255\255\255\097\000\097\000\097\000\255\255\097\000\097\000\ + \097\000\255\255\255\255\095\000\095\000\095\000\255\255\255\255\ + \255\255\096\000\096\000\097\000\255\255\097\000\097\000\097\000\ + \097\000\097\000\255\255\255\255\255\255\255\255\255\255\098\000\ + \255\255\255\255\098\000\098\000\098\000\255\255\255\255\098\000\ + \098\000\098\000\255\255\098\000\098\000\098\000\255\255\255\255\ + \096\000\096\000\255\255\255\255\255\255\097\000\097\000\097\000\ + \098\000\255\255\098\000\098\000\098\000\098\000\098\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \109\000\109\000\255\255\255\255\109\000\255\255\255\255\110\000\ + \110\000\109\000\109\000\110\000\255\255\097\000\097\000\097\000\ + \110\000\110\000\098\000\098\000\098\000\109\000\255\255\109\000\ + \109\000\109\000\255\255\109\000\110\000\255\255\110\000\110\000\ + \110\000\255\255\110\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\111\000\111\000\255\255\255\255\ + \111\000\255\255\098\000\098\000\098\000\111\000\111\000\255\255\ + \109\000\109\000\255\255\255\255\255\255\255\255\255\255\110\000\ + \110\000\111\000\255\255\111\000\111\000\111\000\255\255\111\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\112\000\112\000\255\255\255\255\112\000\255\255\109\000\ + \109\000\255\255\112\000\112\000\255\255\255\255\110\000\110\000\ + \255\255\255\255\255\255\255\255\111\000\111\000\112\000\255\255\ + \112\000\112\000\112\000\255\255\112\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\113\000\113\000\ + \255\255\255\255\113\000\255\255\255\255\114\000\114\000\113\000\ + \113\000\114\000\255\255\111\000\111\000\255\255\114\000\114\000\ + \255\255\112\000\112\000\113\000\255\255\113\000\113\000\113\000\ + \255\255\113\000\114\000\255\255\114\000\114\000\114\000\255\255\ + \114\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\115\000\115\000\255\255\255\255\255\255\255\255\ + \112\000\112\000\255\255\115\000\115\000\255\255\113\000\113\000\ + \255\255\255\255\255\255\255\255\255\255\114\000\114\000\115\000\ + \255\255\115\000\115\000\115\000\255\255\115\000\255\255\255\255\ + \255\255\116\000\116\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\116\000\116\000\255\255\113\000\113\000\255\255\ + \255\255\255\255\255\255\255\255\114\000\114\000\116\000\255\255\ + \116\000\116\000\116\000\115\000\116\000\117\000\117\000\255\255\ + \117\000\255\255\255\255\255\255\255\255\255\255\117\000\117\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\117\000\255\255\117\000\117\000\117\000\255\255\ + \117\000\115\000\116\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\118\000\118\000\255\255\255\255\255\255\119\000\ + \119\000\255\255\119\000\118\000\118\000\255\255\255\255\255\255\ + \119\000\119\000\255\255\117\000\255\255\255\255\117\000\118\000\ + \116\000\118\000\118\000\118\000\119\000\118\000\119\000\119\000\ + \119\000\255\255\119\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\117\000\117\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\118\000\255\255\119\000\255\255\255\255\ + \119\000\255\255\255\255\255\255\255\255\255\255\120\000\255\255\ + \255\255\120\000\120\000\120\000\255\255\255\255\120\000\120\000\ + \120\000\255\255\120\000\120\000\120\000\255\255\255\255\255\255\ + \255\255\118\000\255\255\255\255\255\255\119\000\119\000\120\000\ + \255\255\120\000\120\000\120\000\120\000\120\000\255\255\255\255\ + \255\255\255\255\255\255\121\000\255\255\255\255\121\000\121\000\ + \121\000\255\255\255\255\121\000\121\000\121\000\255\255\121\000\ + \121\000\121\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\120\000\120\000\120\000\121\000\255\255\121\000\121\000\ + \121\000\121\000\121\000\255\255\255\255\255\255\255\255\255\255\ + \122\000\255\255\255\255\122\000\122\000\122\000\255\255\255\255\ + \122\000\122\000\122\000\255\255\122\000\122\000\122\000\255\255\ + \255\255\120\000\120\000\120\000\255\255\255\255\121\000\121\000\ + \121\000\122\000\255\255\122\000\122\000\122\000\122\000\122\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\123\000\ + \255\255\255\255\123\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\121\000\121\000\ + \121\000\255\255\255\255\122\000\122\000\122\000\255\255\123\000\ + \255\255\255\255\255\255\255\255\123\000\123\000\255\255\123\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\123\000\255\255\122\000\122\000\122\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \255\255\255\255\255\255\255\255\123\000\255\255\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \156\000\156\000\156\000\156\000\156\000\156\000\156\000\156\000\ + \156\000\156\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\156\000\156\000\156\000\156\000\156\000\156\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\156\000\156\000\156\000\156\000\156\000\156\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\255\255\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\255\255\123\000\123\000\123\000\ + \123\000\123\000\123\000\123\000\123\000\123\000\130\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\255\255\255\255\255\255\255\255\130\000\255\255\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\255\255\255\255\255\255\255\255\137\000\255\255\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\255\255\255\255\255\255\255\255\255\255\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\255\255\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\255\255\130\000\ + \130\000\130\000\130\000\130\000\130\000\130\000\130\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\255\255\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\255\255\137\000\ + \137\000\137\000\137\000\137\000\137\000\137\000\137\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\255\255\255\255\255\255\255\255\138\000\255\255\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\167\000\167\000\167\000\167\000\167\000\167\000\167\000\ + \167\000\167\000\167\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\167\000\167\000\167\000\167\000\167\000\167\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\167\000\167\000\167\000\167\000\167\000\167\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\255\255\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\139\000\138\000\138\000\ + \138\000\138\000\138\000\138\000\138\000\138\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \255\255\255\255\139\000\255\255\255\255\255\255\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\255\255\255\255\255\255\255\255\139\000\255\255\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\174\000\174\000\174\000\174\000\174\000\174\000\174\000\ + \174\000\174\000\174\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\174\000\174\000\174\000\174\000\174\000\174\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\174\000\174\000\174\000\174\000\174\000\174\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\255\255\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\140\000\139\000\139\000\ + \139\000\139\000\139\000\139\000\139\000\139\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \255\255\255\255\140\000\255\255\255\255\255\255\255\255\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\255\255\255\255\255\255\255\255\140\000\255\255\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\255\255\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\255\255\140\000\140\000\ + \140\000\140\000\140\000\140\000\140\000\140\000\141\000\255\255\ + \141\000\255\255\255\255\164\000\255\255\141\000\164\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\141\000\141\000\ + \141\000\141\000\141\000\141\000\141\000\141\000\141\000\141\000\ + \255\255\164\000\255\255\164\000\255\255\255\255\255\255\255\255\ + \164\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\164\000\164\000\164\000\164\000\164\000\164\000\164\000\ + \164\000\164\000\164\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\141\000\255\255\255\255\255\255\255\255\255\255\ + \141\000\176\000\255\255\255\255\176\000\176\000\176\000\255\255\ + \255\255\255\255\176\000\176\000\141\000\176\000\176\000\176\000\ + \141\000\255\255\141\000\255\255\255\255\164\000\141\000\255\255\ + \255\255\255\255\176\000\164\000\176\000\176\000\176\000\176\000\ + \176\000\255\255\255\255\255\255\255\255\255\255\255\255\164\000\ + \255\255\255\255\255\255\164\000\255\255\164\000\255\255\255\255\ + \255\255\164\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\176\000\255\255\176\000\255\255\ + \255\255\255\255\255\255\255\255\177\000\255\255\255\255\177\000\ + \177\000\177\000\255\255\255\255\255\255\177\000\177\000\255\255\ + \177\000\177\000\177\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\176\000\177\000\176\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\255\255\177\000\ + \255\255\177\000\177\000\255\255\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\255\255\177\000\ + \255\255\177\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\164\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\255\255\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\255\255\177\000\177\000\177\000\177\000\177\000\ + \177\000\177\000\177\000\178\000\255\255\255\255\178\000\178\000\ + \178\000\255\255\255\255\255\255\178\000\178\000\255\255\178\000\ + \178\000\178\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\178\000\255\255\178\000\178\000\ + \178\000\178\000\178\000\255\255\255\255\255\255\255\255\179\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\255\255\255\255\179\000\255\255\178\000\255\255\ + \178\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\255\255\255\255\255\255\178\000\179\000\ + \178\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\255\255\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\255\255\ + \179\000\179\000\179\000\179\000\179\000\179\000\179\000\179\000\ + \181\000\255\255\255\255\181\000\181\000\181\000\255\255\255\255\ + \255\255\181\000\181\000\255\255\181\000\181\000\181\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\181\000\255\255\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\255\255\181\000\255\255\181\000\181\000\255\255\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\255\255\181\000\255\255\181\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\255\255\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\255\255\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\182\000\ + \255\255\255\255\182\000\182\000\182\000\255\255\255\255\255\255\ + \182\000\182\000\255\255\182\000\182\000\182\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \182\000\255\255\182\000\182\000\182\000\182\000\182\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\183\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\255\255\182\000\183\000\182\000\255\255\255\255\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\182\000\255\255\182\000\255\255\183\000\255\255\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\255\255\255\255\255\255\255\255\184\000\255\255\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\255\255\255\255\255\255\255\255\255\255\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\255\255\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\255\255\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\255\255\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\186\000\184\000\ + \184\000\184\000\184\000\184\000\184\000\184\000\184\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\255\255\255\255\186\000\255\255\255\255\255\255\255\255\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\255\255\255\255\255\255\255\255\186\000\255\255\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\255\255\255\255\255\255\255\255\196\000\255\255\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\255\255\255\255\255\255\255\255\255\255\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\255\255\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\255\255\186\000\ + \186\000\186\000\186\000\186\000\186\000\186\000\186\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\255\255\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\255\255\196\000\ + \196\000\196\000\196\000\196\000\196\000\196\000\196\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\255\255\255\255\255\255\255\255\197\000\255\255\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\255\255\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\198\000\197\000\197\000\ + \197\000\197\000\197\000\197\000\197\000\197\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \255\255\255\255\198\000\255\255\255\255\255\255\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\255\255\255\255\255\255\255\255\198\000\255\255\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\255\255\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\199\000\198\000\198\000\ + \198\000\198\000\198\000\198\000\198\000\198\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \255\255\255\255\199\000\255\255\255\255\255\255\255\255\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\255\255\255\255\255\255\255\255\199\000\255\255\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\255\255\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\255\255\199\000\199\000\ + \199\000\199\000\199\000\199\000\199\000\199\000\201\000\255\255\ + \255\255\201\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \201\000\255\255\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\255\255\255\255\255\255\ + \255\255\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\255\255\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\255\255\201\000\201\000\201\000\201\000\201\000\201\000\ + \201\000\201\000\201\000\205\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\255\255\ + \255\255\255\255\255\255\205\000\255\255\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\255\255\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\255\255\205\000\205\000\205\000\205\000\ + \205\000\205\000\205\000\205\000\206\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\206\000\255\255\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \255\255\255\255\255\255\255\255\206\000\255\255\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\255\255\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\209\000\206\000\206\000\206\000\ + \206\000\206\000\206\000\206\000\206\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \255\255\255\255\255\255\255\255\209\000\255\255\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \255\255\255\255\255\255\255\255\218\000\255\255\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \255\255\255\255\255\255\255\255\255\255\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\255\255\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\255\255\209\000\209\000\209\000\ + \209\000\209\000\209\000\209\000\209\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\255\255\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\255\255\218\000\218\000\218\000\ + \218\000\218\000\218\000\218\000\218\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\255\255\ + \255\255\255\255\255\255\219\000\255\255\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\255\255\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\220\000\219\000\219\000\219\000\219\000\ + \219\000\219\000\219\000\219\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\255\255\255\255\ + \220\000\255\255\255\255\255\255\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\255\255\ + \255\255\255\255\255\255\220\000\255\255\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\255\255\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\221\000\220\000\220\000\220\000\220\000\ + \220\000\220\000\220\000\220\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\255\255\255\255\ + \221\000\255\255\255\255\255\255\255\255\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\255\255\ + \255\255\255\255\255\255\221\000\255\255\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\255\255\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\255\255\221\000\221\000\221\000\221\000\ + \221\000\221\000\221\000\221\000\255\255"; + Lexing.lex_base_code = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\027\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\066\000\101\000\136\000\171\000\ + \206\000\000\000\000\000\000\000\000\000\241\000\020\001\055\001\ + \000\000\000\000\018\000\090\001\125\001\160\001\195\001\230\001\ + \000\000\021\000\026\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\247\001\040\002\000\000\034\000\000\000\ + \000\000\003\000\000\000\000\000\049\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\ + \000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\036\002\000\000\244\002\ + \000\000\000\000\000\000\061\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000"; + Lexing.lex_backtrk_code = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\034\000\000\000\000\000\ + \000\000\000\000\000\000\049\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\061\000\061\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000"; + Lexing.lex_default_code = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \041\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000"; + Lexing.lex_trans_code = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\001\000\000\000\058\000\058\000\000\000\058\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \001\000\000\000\000\000\001\000\007\000\044\000\000\000\007\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ + \004\000\004\000\000\000\007\000\012\000\000\000\000\000\012\000\ + \012\000\012\000\000\000\000\000\000\000\000\000\012\000\000\000\ + \012\000\012\000\012\000\007\000\000\000\000\000\007\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\ + \012\000\012\000\012\000\012\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\007\000\015\000\000\000\000\000\015\000\015\000\ + \015\000\000\000\000\000\000\000\015\000\015\000\000\000\015\000\ + \015\000\015\000\000\000\000\000\000\000\000\000\000\000\012\000\ + \000\000\012\000\000\000\000\000\015\000\000\000\015\000\015\000\ + \015\000\015\000\015\000\000\000\000\000\000\000\012\000\000\000\ + \000\000\012\000\012\000\012\000\000\000\000\000\000\000\012\000\ + \012\000\000\000\012\000\012\000\012\000\000\000\000\000\012\000\ + \000\000\012\000\000\000\000\000\000\000\000\000\015\000\012\000\ + \015\000\012\000\012\000\012\000\012\000\012\000\000\000\000\000\ + \000\000\012\000\000\000\000\000\012\000\012\000\012\000\000\000\ + \000\000\000\000\012\000\012\000\000\000\012\000\012\000\012\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\015\000\000\000\ + \015\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\ + \012\000\000\000\000\000\000\000\012\000\000\000\000\000\012\000\ + \012\000\012\000\000\000\000\000\000\000\012\000\012\000\000\000\ + \012\000\012\000\012\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\012\000\000\000\012\000\012\000\012\000\012\000\012\000\ + \012\000\012\000\012\000\012\000\000\000\000\000\000\000\012\000\ + \000\000\000\000\012\000\012\000\012\000\000\000\000\000\000\000\ + \012\000\012\000\000\000\012\000\012\000\012\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\012\000\000\000\012\000\012\000\ + \012\000\012\000\012\000\012\000\012\000\012\000\012\000\000\000\ + \000\000\000\000\012\000\000\000\000\000\012\000\012\000\012\000\ + \000\000\000\000\000\000\012\000\012\000\000\000\012\000\012\000\ + \012\000\000\000\000\000\000\000\000\000\000\000\000\000\012\000\ + \000\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\ + \012\000\012\000\000\000\000\000\000\000\012\000\000\000\000\000\ + \012\000\012\000\012\000\000\000\000\000\000\000\012\000\012\000\ + \000\000\012\000\012\000\012\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\012\000\000\000\012\000\012\000\012\000\012\000\ + \012\000\012\000\012\000\012\000\012\000\000\000\000\000\000\000\ + \012\000\000\000\000\000\012\000\012\000\012\000\000\000\000\000\ + \000\000\012\000\012\000\000\000\012\000\012\000\012\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\ + \012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\ + \000\000\000\000\000\000\012\000\000\000\000\000\012\000\012\000\ + \012\000\000\000\000\000\000\000\012\000\012\000\000\000\012\000\ + \012\000\012\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \012\000\000\000\012\000\012\000\012\000\012\000\012\000\012\000\ + \012\000\012\000\012\000\000\000\000\000\000\000\012\000\000\000\ + \000\000\012\000\012\000\012\000\000\000\000\000\000\000\012\000\ + \012\000\000\000\012\000\012\000\012\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\012\000\000\000\012\000\012\000\012\000\ + \012\000\012\000\012\000\012\000\012\000\012\000\000\000\000\000\ + \000\000\012\000\000\000\000\000\012\000\012\000\012\000\000\000\ + \000\000\000\000\012\000\012\000\000\000\012\000\012\000\012\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\012\000\000\000\ + \012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\ + \012\000\000\000\000\000\000\000\015\000\000\000\000\000\015\000\ + \015\000\015\000\000\000\000\000\000\000\015\000\015\000\000\000\ + \015\000\015\000\015\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\012\000\000\000\012\000\012\000\015\000\012\000\015\000\ + \015\000\015\000\015\000\015\000\000\000\000\000\000\000\015\000\ + \000\000\000\000\015\000\015\000\015\000\000\000\000\000\000\000\ + \015\000\015\000\000\000\015\000\015\000\015\000\000\000\000\000\ + \000\000\029\000\000\000\000\000\012\000\000\000\012\000\015\000\ + \015\000\015\000\015\000\015\000\015\000\015\000\015\000\004\000\ + \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ + \004\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\015\000\ + \000\000\015\000\015\000\000\000\015\000\000\000\000\000\000\000\ + \001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \004\000\004\000\004\000\004\000\004\000\004\000\004\000\004\000\ + \004\000\004\000\015\000\000\000\015\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\000\000\ + \000\000\000\000\000\000\058\000\000\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\000\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\000\000\ + \000\000\000\000\000\000\058\000\000\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\ + \000\000\000\000\000\000\000\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\000\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\000\000\058\000\058\000\058\000\058\000\ + \058\000\058\000\058\000\058\000\000\000"; + Lexing.lex_check_code = + "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\016\000\104\000\164\000\170\000\104\000\164\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \016\000\255\255\104\000\000\000\019\000\105\000\255\255\019\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \016\000\016\000\016\000\016\000\016\000\016\000\016\000\016\000\ + \016\000\016\000\255\255\019\000\019\000\255\255\255\255\019\000\ + \019\000\019\000\255\255\255\255\255\255\255\255\019\000\255\255\ + \019\000\019\000\019\000\060\000\255\255\255\255\060\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\019\000\255\255\019\000\ + \019\000\019\000\019\000\019\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\060\000\060\000\255\255\255\255\060\000\060\000\ + \060\000\255\255\255\255\255\255\060\000\060\000\255\255\060\000\ + \060\000\060\000\255\255\255\255\255\255\255\255\255\255\019\000\ + \255\255\019\000\255\255\255\255\060\000\255\255\060\000\060\000\ + \060\000\060\000\060\000\255\255\255\255\255\255\061\000\255\255\ + \255\255\061\000\061\000\061\000\255\255\255\255\255\255\061\000\ + \061\000\255\255\061\000\061\000\061\000\255\255\255\255\019\000\ + \255\255\019\000\255\255\255\255\255\255\255\255\060\000\061\000\ + \060\000\061\000\061\000\061\000\061\000\061\000\255\255\255\255\ + \255\255\062\000\255\255\255\255\062\000\062\000\062\000\255\255\ + \255\255\255\255\062\000\062\000\255\255\062\000\062\000\062\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\060\000\255\255\ + \060\000\061\000\062\000\061\000\062\000\062\000\062\000\062\000\ + \062\000\255\255\255\255\255\255\063\000\255\255\255\255\063\000\ + \063\000\063\000\255\255\255\255\255\255\063\000\063\000\255\255\ + \063\000\063\000\063\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\061\000\255\255\061\000\062\000\063\000\062\000\063\000\ + \063\000\063\000\063\000\063\000\255\255\255\255\255\255\064\000\ + \255\255\255\255\064\000\064\000\064\000\255\255\255\255\255\255\ + \064\000\064\000\255\255\064\000\064\000\064\000\255\255\255\255\ + \104\000\255\255\255\255\255\255\062\000\255\255\062\000\063\000\ + \064\000\063\000\064\000\064\000\064\000\064\000\064\000\255\255\ + \255\255\255\255\069\000\255\255\255\255\069\000\069\000\069\000\ + \255\255\255\255\255\255\069\000\069\000\255\255\069\000\069\000\ + \069\000\255\255\255\255\255\255\255\255\255\255\255\255\063\000\ + \255\255\063\000\064\000\069\000\064\000\069\000\069\000\069\000\ + \069\000\069\000\255\255\255\255\255\255\070\000\255\255\255\255\ + \070\000\070\000\070\000\255\255\255\255\255\255\070\000\070\000\ + \255\255\070\000\070\000\070\000\255\255\255\255\255\255\255\255\ + \255\255\255\255\064\000\255\255\064\000\069\000\070\000\069\000\ + \070\000\070\000\070\000\070\000\070\000\255\255\255\255\255\255\ + \071\000\255\255\255\255\071\000\071\000\071\000\255\255\255\255\ + \255\255\071\000\071\000\255\255\071\000\071\000\071\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\069\000\255\255\069\000\ + \070\000\071\000\070\000\071\000\071\000\071\000\071\000\071\000\ + \255\255\255\255\255\255\075\000\255\255\255\255\075\000\075\000\ + \075\000\255\255\255\255\255\255\075\000\075\000\255\255\075\000\ + \075\000\075\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \070\000\255\255\070\000\071\000\075\000\071\000\075\000\075\000\ + \075\000\075\000\075\000\255\255\255\255\255\255\076\000\255\255\ + \255\255\076\000\076\000\076\000\255\255\255\255\255\255\076\000\ + \076\000\255\255\076\000\076\000\076\000\255\255\255\255\255\255\ + \255\255\255\255\255\255\071\000\255\255\071\000\075\000\076\000\ + \075\000\076\000\076\000\076\000\076\000\076\000\255\255\255\255\ + \255\255\077\000\255\255\255\255\077\000\077\000\077\000\255\255\ + \255\255\255\255\077\000\077\000\255\255\077\000\077\000\077\000\ + \255\255\255\255\255\255\255\255\255\255\255\255\075\000\255\255\ + \075\000\076\000\077\000\076\000\077\000\077\000\077\000\077\000\ + \077\000\255\255\255\255\255\255\078\000\255\255\255\255\078\000\ + \078\000\078\000\255\255\255\255\255\255\078\000\078\000\255\255\ + \078\000\078\000\078\000\255\255\255\255\255\255\255\255\255\255\ + \255\255\076\000\255\255\076\000\077\000\078\000\077\000\078\000\ + \078\000\078\000\078\000\078\000\255\255\255\255\255\255\079\000\ + \255\255\255\255\079\000\079\000\079\000\255\255\255\255\255\255\ + \079\000\079\000\255\255\079\000\079\000\079\000\255\255\255\255\ + \255\255\099\000\255\255\255\255\077\000\255\255\077\000\078\000\ + \079\000\078\000\079\000\079\000\079\000\079\000\079\000\099\000\ + \099\000\099\000\099\000\099\000\099\000\099\000\099\000\099\000\ + \099\000\100\000\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\078\000\ + \255\255\078\000\079\000\255\255\079\000\255\255\255\255\255\255\ + \100\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \100\000\100\000\100\000\100\000\100\000\100\000\100\000\100\000\ + \100\000\100\000\079\000\255\255\079\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\255\255\ + \255\255\255\255\255\255\181\000\255\255\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\255\255\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\183\000\181\000\181\000\181\000\181\000\ + \181\000\181\000\181\000\181\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\255\255\ + \255\255\255\255\255\255\183\000\255\255\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\ + \255\255\255\255\255\255\255\255\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\255\255\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\255\255\183\000\183\000\183\000\183\000\ + \183\000\183\000\183\000\183\000\255\255"; + Lexing.lex_code = + "\255\004\255\255\009\255\255\006\255\005\255\255\007\255\255\008\ + \255\255\000\007\255\000\006\001\008\255\000\005\255\011\255\010\ + \255\255\003\255\000\004\001\009\255\011\255\255\010\255\011\255\ + \255\000\004\001\009\003\010\002\011\255\001\255\255\000\001\255\ + "; + } + + let rec token c lexbuf = + (lexbuf.Lexing.lex_mem <- Array.create 12 (-1); + __ocaml_lex_token_rec c lexbuf 0) + and __ocaml_lex_token_rec c lexbuf __ocaml_lex_state = + match Lexing.new_engine __ocaml_lex_tables __ocaml_lex_state + lexbuf + with + | 0 -> (update_loc c None 1 false 0; NEWLINE) + | 1 -> + let x = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in BLANKS x + | 2 -> + let x = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in LABEL x + | 3 -> + let x = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in OPTLABEL x + | 4 -> + let x = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in LIDENT x + | 5 -> + let x = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in UIDENT x + | 6 -> + let i = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in + (try INT (int_of_string i, i) + with + | Failure _ -> + err (Literal_overflow "int") (Loc.of_lexbuf lexbuf)) + | 7 -> + let f = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in + (try FLOAT (float_of_string f, f) + with + | Failure _ -> + err (Literal_overflow "float") + (Loc.of_lexbuf lexbuf)) + | 8 -> + let i = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + (try INT32 (Int32.of_string i, i) + with + | Failure _ -> + err (Literal_overflow "int32") + (Loc.of_lexbuf lexbuf)) + | 9 -> + let i = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + (try INT64 (Int64.of_string i, i) + with + | Failure _ -> + err (Literal_overflow "int64") + (Loc.of_lexbuf lexbuf)) + | 10 -> + let i = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + (try NATIVEINT (Nativeint.of_string i, i) + with + | Failure _ -> + err (Literal_overflow "nativeint") + (Loc.of_lexbuf lexbuf)) + | 11 -> + (with_curr_loc string c; + let s = buff_contents c in STRING (TokenEval.string s, s)) + | 12 -> + let x = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + (update_loc c None 1 false 1; CHAR (TokenEval.char x, x)) + | 13 -> + let x = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in CHAR (TokenEval.char x, x) + | 14 -> + let c = + Lexing.sub_lexeme_char lexbuf + (lexbuf.Lexing.lex_start_pos + 2) + in + err (Illegal_escape (String.make 1 c)) + (Loc.of_lexbuf lexbuf) + | 15 -> + (store c; COMMENT (parse_nested comment (in_comment c))) + | 16 -> + (warn Comment_start (Loc.of_lexbuf lexbuf); + parse comment (in_comment c); + COMMENT (buff_contents c)) + | 17 -> + (warn Comment_not_end (Loc.of_lexbuf lexbuf); + move_start_p (-1) c; + SYMBOL "*") + | 18 -> + let beginning = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 2) + lexbuf.Lexing.lex_curr_pos + in + if quotations c + then + (move_start_p (- (String.length beginning)); + mk_quotation quotation c "" "" 2) + else parse (symbolchar_star ("<<" ^ beginning)) c + | 19 -> + if quotations c + then + QUOTATION + { + q_name = ""; + q_loc = ""; + q_shift = 2; + q_contents = ""; + } + else parse (symbolchar_star "<<>>") c + | 20 -> + if quotations c + then with_curr_loc maybe_quotation_at c + else parse (symbolchar_star "<@") c + | 21 -> + if quotations c + then with_curr_loc maybe_quotation_colon c + else parse (symbolchar_star "<:") c + | 22 -> + let num = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_mem.(0) + lexbuf.Lexing.lex_mem.(1) + and name = + Lexing.sub_lexeme_opt lexbuf lexbuf.Lexing.lex_mem.(3) + lexbuf.Lexing.lex_mem.(2) in + let inum = int_of_string num + in + (update_loc c name inum true 0; + LINE_DIRECTIVE (inum, name)) + | 23 -> + let op = + Lexing.sub_lexeme_char lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + in ESCAPED_IDENT (String.make 1 op) + | 24 -> + let op = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in ESCAPED_IDENT op + | 25 -> + let op = + Lexing.sub_lexeme lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + lexbuf.Lexing.lex_mem.(0) + in ESCAPED_IDENT op + | 26 -> + let op = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_mem.(0) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in ESCAPED_IDENT op + | 27 -> + let op = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_mem.(0) + lexbuf.Lexing.lex_mem.(1) + in ESCAPED_IDENT op + | 28 -> + let x = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in SYMBOL x + | 29 -> + if antiquots c + then with_curr_loc dollar (shift 1 c) + else parse (symbolchar_star "$") c + | 30 -> + let x = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in SYMBOL x + | 31 -> + let pos = lexbuf.lex_curr_p + in + (lexbuf.lex_curr_p <- + { + (pos) + with + pos_bol = pos.pos_bol + 1; + pos_cnum = pos.pos_cnum + 1; + }; + EOI) + | 32 -> + let c = + Lexing.sub_lexeme_char lexbuf lexbuf.Lexing.lex_start_pos + in err (Illegal_character c) (Loc.of_lexbuf lexbuf) + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_token_rec c lexbuf __ocaml_lex_state) + and comment c lexbuf = __ocaml_lex_comment_rec c lexbuf 123 + and __ocaml_lex_comment_rec c lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> (store c; with_curr_loc comment c; parse comment c) + | 1 -> store c + | 2 -> + (store c; + if quotations c then with_curr_loc quotation c else (); + parse comment c) + | 3 -> store_parse comment c + | 4 -> + (store c; + (try with_curr_loc string c + with + | Loc.Exc_located (_, (Error.E Unterminated_string)) -> + err Unterminated_string_in_comment (loc c)); + Buffer.add_char c.buffer '"'; + parse comment c) + | 5 -> store_parse comment c + | 6 -> store_parse comment c + | 7 -> (update_loc c None 1 false 1; store_parse comment c) + | 8 -> store_parse comment c + | 9 -> store_parse comment c + | 10 -> store_parse comment c + | 11 -> store_parse comment c + | 12 -> err Unterminated_comment (loc c) + | 13 -> (update_loc c None 1 false 0; store_parse comment c) + | 14 -> store_parse comment c + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_comment_rec c lexbuf __ocaml_lex_state) + and string c lexbuf = + (lexbuf.Lexing.lex_mem <- Array.create 2 (-1); + __ocaml_lex_string_rec c lexbuf 159) + and __ocaml_lex_string_rec c lexbuf __ocaml_lex_state = + match Lexing.new_engine __ocaml_lex_tables __ocaml_lex_state + lexbuf + with + | 0 -> set_start_p c + | 1 -> + let space = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_mem.(0) + lexbuf.Lexing.lex_curr_pos + in + (update_loc c None 1 false (String.length space); + store_parse string c) + | 2 -> store_parse string c + | 3 -> store_parse string c + | 4 -> store_parse string c + | 5 -> + let x = + Lexing.sub_lexeme_char lexbuf + (lexbuf.Lexing.lex_start_pos + 1) + in + if is_in_comment c + then store_parse string c + else + (warn (Illegal_escape (String.make 1 x)) + (Loc.of_lexbuf lexbuf); + store_parse string c) + | 6 -> (update_loc c None 1 false 0; store_parse string c) + | 7 -> err Unterminated_string (loc c) + | 8 -> store_parse string c + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_string_rec c lexbuf __ocaml_lex_state) + and symbolchar_star beginning c lexbuf = + __ocaml_lex_symbolchar_star_rec beginning c lexbuf 176 + and + __ocaml_lex_symbolchar_star_rec beginning c lexbuf + __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> + let tok = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in + (move_start_p (- (String.length beginning)) c; + SYMBOL (beginning ^ tok)) + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_symbolchar_star_rec beginning c lexbuf + __ocaml_lex_state) + and maybe_quotation_at c lexbuf = + __ocaml_lex_maybe_quotation_at_rec c lexbuf 177 + and + __ocaml_lex_maybe_quotation_at_rec c lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> + let loc = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + mk_quotation quotation c "" loc (1 + (String.length loc)) + | 1 -> + let tok = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in SYMBOL ("<@" ^ tok) + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_maybe_quotation_at_rec c lexbuf + __ocaml_lex_state) + and maybe_quotation_colon c lexbuf = + (lexbuf.Lexing.lex_mem <- Array.create 2 (-1); + __ocaml_lex_maybe_quotation_colon_rec c lexbuf 181) + and + __ocaml_lex_maybe_quotation_colon_rec c lexbuf + __ocaml_lex_state = + match Lexing.new_engine __ocaml_lex_tables __ocaml_lex_state + lexbuf + with + | 0 -> + let name = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + mk_quotation quotation c name "" + (1 + (String.length name)) + | 1 -> + let name = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_mem.(0) + and loc = + Lexing.sub_lexeme lexbuf (lexbuf.Lexing.lex_mem.(0) + 1) + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + mk_quotation quotation c name loc + ((2 + (String.length loc)) + (String.length name)) + | 2 -> + let tok = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + lexbuf.Lexing.lex_curr_pos + in SYMBOL ("<:" ^ tok) + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_maybe_quotation_colon_rec c lexbuf + __ocaml_lex_state) + and quotation c lexbuf = __ocaml_lex_quotation_rec c lexbuf 188 + and __ocaml_lex_quotation_rec c lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> (store c; with_curr_loc quotation c; parse quotation c) + | 1 -> store c + | 2 -> err Unterminated_quotation (loc c) + | 3 -> (update_loc c None 1 false 0; store_parse quotation c) + | 4 -> store_parse quotation c + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_quotation_rec c lexbuf __ocaml_lex_state) + and dollar c lexbuf = __ocaml_lex_dollar_rec c lexbuf 201 + and __ocaml_lex_dollar_rec c lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> (set_start_p c; ANTIQUOT ("", "")) + | 1 -> + let name = + Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos + (lexbuf.Lexing.lex_curr_pos + (-1)) + in + with_curr_loc (antiquot name) + (shift (1 + (String.length name)) c) + | 2 -> store_parse (antiquot "") c + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_dollar_rec c lexbuf __ocaml_lex_state) + and antiquot name c lexbuf = + __ocaml_lex_antiquot_rec name c lexbuf 210 + and __ocaml_lex_antiquot_rec name c lexbuf __ocaml_lex_state = + match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf + with + | 0 -> (set_start_p c; ANTIQUOT (name, buff_contents c)) + | 1 -> err Unterminated_antiquot (loc c) + | 2 -> + (update_loc c None 1 false 0; + store_parse (antiquot name) c) + | 3 -> + (store c; + with_curr_loc quotation c; + parse (antiquot name) c) + | 4 -> store_parse (antiquot name) c + | __ocaml_lex_state -> + (lexbuf.Lexing.refill_buff lexbuf; + __ocaml_lex_antiquot_rec name c lexbuf __ocaml_lex_state) + + let lexing_store s buff max = + let rec self n s = + if n >= max + then n + else + (match Stream.peek s with + | Some x -> (Stream.junk s; buff.[n] <- x; succ n) + | _ -> n) + in self 0 s + + let from_context c = + let next _ = + let tok = with_curr_loc token c in + let loc = Loc.of_lexbuf c.lexbuf in Some (tok, loc) + in Stream.from next + + let from_lexbuf ?(quotations = true) lb = + let c = + { + (default_context lb) + with + loc = Loc.of_lexbuf lb; + antiquots = !Camlp4_config.antiquotations; + quotations = quotations; + } + in from_context c + + let setup_loc lb loc = + let start_pos = Loc.start_pos loc + in + (lb.lex_abs_pos <- start_pos.pos_cnum; + lb.lex_curr_p <- start_pos) + + let from_string ?quotations loc str = + let lb = Lexing.from_string str + in (setup_loc lb loc; from_lexbuf ?quotations lb) + + let from_stream ?quotations loc strm = + let lb = Lexing.from_function (lexing_store strm) + in (setup_loc lb loc; from_lexbuf ?quotations lb) + + let mk () loc strm = + from_stream ~quotations: !Camlp4_config.quotations loc strm + + end + + end + + module Camlp4Ast = + struct + module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc = + struct + module Loc = Loc + + module Ast = + struct + include Sig.MakeCamlp4Ast(Loc) + + let safe_string_escaped s = + if + ((String.length s) > 2) && + ((s.[0] = '\\') && (s.[1] = '$')) + then s + else String.escaped s + + end + + include Ast + + external loc_of_ctyp : ctyp -> Loc.t = "%field0" + + external loc_of_patt : patt -> Loc.t = "%field0" + + external loc_of_expr : expr -> Loc.t = "%field0" + + external loc_of_module_type : module_type -> Loc.t = "%field0" + + external loc_of_module_expr : module_expr -> Loc.t = "%field0" + + external loc_of_sig_item : sig_item -> Loc.t = "%field0" + + external loc_of_str_item : str_item -> Loc.t = "%field0" + + external loc_of_class_type : class_type -> Loc.t = "%field0" + + external loc_of_class_sig_item : class_sig_item -> Loc.t = + "%field0" + + external loc_of_class_expr : class_expr -> Loc.t = "%field0" + + external loc_of_class_str_item : class_str_item -> Loc.t = + "%field0" + + external loc_of_with_constr : with_constr -> Loc.t = "%field0" + + external loc_of_binding : binding -> Loc.t = "%field0" + + external loc_of_rec_binding : rec_binding -> Loc.t = "%field0" + + external loc_of_module_binding : module_binding -> Loc.t = + "%field0" + + external loc_of_match_case : match_case -> Loc.t = "%field0" + + external loc_of_ident : ident -> Loc.t = "%field0" + + let ghost = Loc.ghost + + let rec is_module_longident = + function + | Ast.IdAcc (_, _, i) -> is_module_longident i + | Ast.IdApp (_, i1, i2) -> + (is_module_longident i1) && (is_module_longident i2) + | Ast.IdUid (_, _) -> true + | _ -> false + + let ident_of_expr = + let error () = + invalid_arg + "ident_of_expr: this expression is not an identifier" in + let rec self = + function + | Ast.ExApp (_loc, e1, e2) -> + Ast.IdApp (_loc, self e1, self e2) + | Ast.ExAcc (_loc, e1, e2) -> + Ast.IdAcc (_loc, self e1, self e2) + | Ast.ExId (_, (Ast.IdLid (_, _))) -> error () + | Ast.ExId (_, i) -> + if is_module_longident i then i else error () + | _ -> error () + in + function + | Ast.ExId (_, i) -> i + | Ast.ExApp (_, _, _) -> error () + | t -> self t + + let ident_of_ctyp = + let error () = + invalid_arg "ident_of_ctyp: this type is not an identifier" in + let rec self = + function + | Ast.TyApp (_loc, t1, t2) -> + Ast.IdApp (_loc, self t1, self t2) + | Ast.TyId (_, (Ast.IdLid (_, _))) -> error () + | Ast.TyId (_, i) -> + if is_module_longident i then i else error () + | _ -> error () + in function | Ast.TyId (_, i) -> i | t -> self t + + let ident_of_patt = + let error () = + invalid_arg + "ident_of_patt: this pattern is not an identifier" in + let rec self = + function + | Ast.PaApp (_loc, p1, p2) -> + Ast.IdApp (_loc, self p1, self p2) + | Ast.PaId (_, (Ast.IdLid (_, _))) -> error () + | Ast.PaId (_, i) -> + if is_module_longident i then i else error () + | _ -> error () + in function | Ast.PaId (_, i) -> i | p -> self p + + let rec is_irrefut_patt = + function + | Ast.PaId (_, (Ast.IdLid (_, _))) -> true + | Ast.PaId (_, (Ast.IdUid (_, "()"))) -> true + | Ast.PaAny _ -> true + | Ast.PaNil _ -> true + | Ast.PaAli (_, x, y) -> + (is_irrefut_patt x) && (is_irrefut_patt y) + | Ast.PaRec (_, p) -> is_irrefut_patt p + | Ast.PaEq (_, _, p) -> is_irrefut_patt p + | Ast.PaSem (_, p1, p2) -> + (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaCom (_, p1, p2) -> + (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaOrp (_, p1, p2) -> + (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaApp (_, p1, p2) -> + (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaTyc (_, p, _) -> is_irrefut_patt p + | Ast.PaTup (_, pl) -> is_irrefut_patt pl + | Ast.PaOlb (_, _, (Ast.PaNil _)) -> true + | Ast.PaOlb (_, _, p) -> is_irrefut_patt p + | Ast.PaOlbi (_, _, p, _) -> is_irrefut_patt p + | Ast.PaLab (_, _, (Ast.PaNil _)) -> true + | Ast.PaLab (_, _, p) -> is_irrefut_patt p + | Ast.PaLaz (_, p) -> is_irrefut_patt p + | Ast.PaId (_, _) -> false + | Ast.PaVrn (_, _) | Ast.PaStr (_, _) | Ast.PaRng (_, _, _) | + Ast.PaFlo (_, _) | Ast.PaNativeInt (_, _) | + Ast.PaInt64 (_, _) | Ast.PaInt32 (_, _) | Ast.PaInt (_, _) + | Ast.PaChr (_, _) | Ast.PaTyp (_, _) | Ast.PaArr (_, _) | + Ast.PaAnt (_, _) -> false + + let rec is_constructor = + function + | Ast.IdAcc (_, _, i) -> is_constructor i + | Ast.IdUid (_, _) -> true + | Ast.IdLid (_, _) | Ast.IdApp (_, _, _) -> false + | Ast.IdAnt (_, _) -> assert false + + let is_patt_constructor = + function + | Ast.PaId (_, i) -> is_constructor i + | Ast.PaVrn (_, _) -> true + | _ -> false + + let rec is_expr_constructor = + function + | Ast.ExId (_, i) -> is_constructor i + | Ast.ExAcc (_, e1, e2) -> + (is_expr_constructor e1) && (is_expr_constructor e2) + | Ast.ExVrn (_, _) -> true + | _ -> false + + let rec tyOr_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TyOr (_loc, t, tyOr_of_list ts) + + let rec tyAnd_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TyAnd (_loc, t, tyAnd_of_list ts) + + let rec tySem_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TySem (_loc, t, tySem_of_list ts) + + let rec tyCom_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TyCom (_loc, t, tyCom_of_list ts) + + let rec tyAmp_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TyAmp (_loc, t, tyAmp_of_list ts) + + let rec tySta_of_list = + function + | [] -> Ast.TyNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_ctyp t + in Ast.TySta (_loc, t, tySta_of_list ts) + + let rec stSem_of_list = + function + | [] -> Ast.StNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_str_item t + in Ast.StSem (_loc, t, stSem_of_list ts) + + let rec sgSem_of_list = + function + | [] -> Ast.SgNil ghost + | [ t ] -> t + | t :: ts -> + let _loc = loc_of_sig_item t + in Ast.SgSem (_loc, t, sgSem_of_list ts) + + let rec biAnd_of_list = + function + | [] -> Ast.BiNil ghost + | [ b ] -> b + | b :: bs -> + let _loc = loc_of_binding b + in Ast.BiAnd (_loc, b, biAnd_of_list bs) + + let rec rbSem_of_list = + function + | [] -> Ast.RbNil ghost + | [ b ] -> b + | b :: bs -> + let _loc = loc_of_rec_binding b + in Ast.RbSem (_loc, b, rbSem_of_list bs) + + let rec wcAnd_of_list = + function + | [] -> Ast.WcNil ghost + | [ w ] -> w + | w :: ws -> + let _loc = loc_of_with_constr w + in Ast.WcAnd (_loc, w, wcAnd_of_list ws) + + let rec idAcc_of_list = + function + | [] -> assert false + | [ i ] -> i + | i :: is -> + let _loc = loc_of_ident i + in Ast.IdAcc (_loc, i, idAcc_of_list is) + + let rec idApp_of_list = + function + | [] -> assert false + | [ i ] -> i + | i :: is -> + let _loc = loc_of_ident i + in Ast.IdApp (_loc, i, idApp_of_list is) + + let rec mcOr_of_list = + function + | [] -> Ast.McNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_match_case x + in Ast.McOr (_loc, x, mcOr_of_list xs) + + let rec mbAnd_of_list = + function + | [] -> Ast.MbNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_module_binding x + in Ast.MbAnd (_loc, x, mbAnd_of_list xs) + + let rec meApp_of_list = + function + | [] -> assert false + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_module_expr x + in Ast.MeApp (_loc, x, meApp_of_list xs) + + let rec ceAnd_of_list = + function + | [] -> Ast.CeNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_class_expr x + in Ast.CeAnd (_loc, x, ceAnd_of_list xs) + + let rec ctAnd_of_list = + function + | [] -> Ast.CtNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_class_type x + in Ast.CtAnd (_loc, x, ctAnd_of_list xs) + + let rec cgSem_of_list = + function + | [] -> Ast.CgNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_class_sig_item x + in Ast.CgSem (_loc, x, cgSem_of_list xs) + + let rec crSem_of_list = + function + | [] -> Ast.CrNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_class_str_item x + in Ast.CrSem (_loc, x, crSem_of_list xs) + + let rec paSem_of_list = + function + | [] -> Ast.PaNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_patt x + in Ast.PaSem (_loc, x, paSem_of_list xs) + + let rec paCom_of_list = + function + | [] -> Ast.PaNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_patt x + in Ast.PaCom (_loc, x, paCom_of_list xs) + + let rec exSem_of_list = + function + | [] -> Ast.ExNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_expr x + in Ast.ExSem (_loc, x, exSem_of_list xs) + + let rec exCom_of_list = + function + | [] -> Ast.ExNil ghost + | [ x ] -> x + | x :: xs -> + let _loc = loc_of_expr x + in Ast.ExCom (_loc, x, exCom_of_list xs) + + let ty_of_stl = + function + | (_loc, s, []) -> Ast.TyId (_loc, Ast.IdUid (_loc, s)) + | (_loc, s, tl) -> + Ast.TyOf (_loc, Ast.TyId (_loc, Ast.IdUid (_loc, s)), + tyAnd_of_list tl) + + let ty_of_sbt = + function + | (_loc, s, true, t) -> + Ast.TyCol (_loc, Ast.TyId (_loc, Ast.IdLid (_loc, s)), + Ast.TyMut (_loc, t)) + | (_loc, s, false, t) -> + Ast.TyCol (_loc, Ast.TyId (_loc, Ast.IdLid (_loc, s)), t) + + let bi_of_pe (p, e) = + let _loc = loc_of_patt p in Ast.BiEq (_loc, p, e) + + let sum_type_of_list l = tyOr_of_list (List.map ty_of_stl l) + + let record_type_of_list l = tySem_of_list (List.map ty_of_sbt l) + + let binding_of_pel l = biAnd_of_list (List.map bi_of_pe l) + + let rec pel_of_binding = + function + | Ast.BiAnd (_, b1, b2) -> + (pel_of_binding b1) @ (pel_of_binding b2) + | Ast.BiEq (_, p, e) -> [ (p, e) ] + | _ -> assert false + + let rec list_of_binding x acc = + match x with + | Ast.BiAnd (_, b1, b2) -> + list_of_binding b1 (list_of_binding b2 acc) + | t -> t :: acc + + let rec list_of_rec_binding x acc = + match x with + | Ast.RbSem (_, b1, b2) -> + list_of_rec_binding b1 (list_of_rec_binding b2 acc) + | t -> t :: acc + + let rec list_of_with_constr x acc = + match x with + | Ast.WcAnd (_, w1, w2) -> + list_of_with_constr w1 (list_of_with_constr w2 acc) + | t -> t :: acc + + let rec list_of_ctyp x acc = + match x with + | Ast.TyNil _ -> acc + | Ast.TyAmp (_, x, y) | Ast.TyCom (_, x, y) | + Ast.TySta (_, x, y) | Ast.TySem (_, x, y) | + Ast.TyAnd (_, x, y) | Ast.TyOr (_, x, y) -> + list_of_ctyp x (list_of_ctyp y acc) + | x -> x :: acc + + let rec list_of_patt x acc = + match x with + | Ast.PaNil _ -> acc + | Ast.PaCom (_, x, y) | Ast.PaSem (_, x, y) -> + list_of_patt x (list_of_patt y acc) + | x -> x :: acc + + let rec list_of_expr x acc = + match x with + | Ast.ExNil _ -> acc + | Ast.ExCom (_, x, y) | Ast.ExSem (_, x, y) -> + list_of_expr x (list_of_expr y acc) + | x -> x :: acc + + let rec list_of_str_item x acc = + match x with + | Ast.StNil _ -> acc + | Ast.StSem (_, x, y) -> + list_of_str_item x (list_of_str_item y acc) + | x -> x :: acc + + let rec list_of_sig_item x acc = + match x with + | Ast.SgNil _ -> acc + | Ast.SgSem (_, x, y) -> + list_of_sig_item x (list_of_sig_item y acc) + | x -> x :: acc + + let rec list_of_class_sig_item x acc = + match x with + | Ast.CgNil _ -> acc + | Ast.CgSem (_, x, y) -> + list_of_class_sig_item x (list_of_class_sig_item y acc) + | x -> x :: acc + + let rec list_of_class_str_item x acc = + match x with + | Ast.CrNil _ -> acc + | Ast.CrSem (_, x, y) -> + list_of_class_str_item x (list_of_class_str_item y acc) + | x -> x :: acc + + let rec list_of_class_type x acc = + match x with + | Ast.CtAnd (_, x, y) -> + list_of_class_type x (list_of_class_type y acc) + | x -> x :: acc + + let rec list_of_class_expr x acc = + match x with + | Ast.CeAnd (_, x, y) -> + list_of_class_expr x (list_of_class_expr y acc) + | x -> x :: acc + + let rec list_of_module_expr x acc = + match x with + | Ast.MeApp (_, x, y) -> + list_of_module_expr x (list_of_module_expr y acc) + | x -> x :: acc + + let rec list_of_match_case x acc = + match x with + | Ast.McNil _ -> acc + | Ast.McOr (_, x, y) -> + list_of_match_case x (list_of_match_case y acc) + | x -> x :: acc + + let rec list_of_ident x acc = + match x with + | Ast.IdAcc (_, x, y) | Ast.IdApp (_, x, y) -> + list_of_ident x (list_of_ident y acc) + | x -> x :: acc + + let rec list_of_module_binding x acc = + match x with + | Ast.MbAnd (_, x, y) -> + list_of_module_binding x (list_of_module_binding y acc) + | x -> x :: acc + + module Meta = + struct + module type META_LOC = + sig + val meta_loc_patt : Loc.t -> Loc.t -> Ast.patt + + val meta_loc_expr : Loc.t -> Loc.t -> Ast.expr + + end + + module MetaLoc = + struct + let meta_loc_patt _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location + in + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "of_tuple"))), + Ast.PaTup (_loc, + Ast.PaCom (_loc, + Ast.PaStr (_loc, Ast.safe_string_escaped a), + Ast.PaCom (_loc, + Ast.PaCom (_loc, + Ast.PaCom (_loc, + Ast.PaCom (_loc, + Ast.PaCom (_loc, + Ast.PaCom (_loc, + Ast.PaInt (_loc, string_of_int b), + Ast.PaInt (_loc, string_of_int c)), + Ast.PaInt (_loc, string_of_int d)), + Ast.PaInt (_loc, string_of_int e)), + Ast.PaInt (_loc, string_of_int f)), + Ast.PaInt (_loc, string_of_int g)), + if h + then + Ast.PaId (_loc, Ast.IdUid (_loc, "True")) + else + Ast.PaId (_loc, Ast.IdUid (_loc, "False")))))) + + let meta_loc_expr _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location + in + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "of_tuple"))), + Ast.ExTup (_loc, + Ast.ExCom (_loc, + Ast.ExStr (_loc, Ast.safe_string_escaped a), + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExInt (_loc, string_of_int b), + Ast.ExInt (_loc, string_of_int c)), + Ast.ExInt (_loc, string_of_int d)), + Ast.ExInt (_loc, string_of_int e)), + Ast.ExInt (_loc, string_of_int f)), + Ast.ExInt (_loc, string_of_int g)), + if h + then + Ast.ExId (_loc, Ast.IdUid (_loc, "True")) + else + Ast.ExId (_loc, Ast.IdUid (_loc, "False")))))) + + end + + module MetaGhostLoc = + struct + let meta_loc_patt _loc _ = + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "ghost"))) + + let meta_loc_expr _loc _ = + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "ghost"))) + + end + + module MetaLocVar = + struct + let meta_loc_patt _loc _ = + Ast.PaId (_loc, Ast.IdLid (_loc, !Loc.name)) + + let meta_loc_expr _loc _ = + Ast.ExId (_loc, Ast.IdLid (_loc, !Loc.name)) + + end + + module Make (MetaLoc : META_LOC) = + struct + open MetaLoc + + let meta_loc = meta_loc_expr + + module Expr = + struct + let meta_string _loc s = Ast.ExStr (_loc, s) + + let meta_int _loc s = Ast.ExInt (_loc, s) + + let meta_float _loc s = Ast.ExFlo (_loc, s) + + let meta_char _loc s = Ast.ExChr (_loc, s) + + let meta_bool _loc = + function + | false -> + Ast.ExId (_loc, Ast.IdUid (_loc, "False")) + | true -> Ast.ExId (_loc, Ast.IdUid (_loc, "True")) + + let rec meta_list mf_a _loc = + function + | [] -> Ast.ExId (_loc, Ast.IdUid (_loc, "[]")) + | x :: xs -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + mf_a _loc x), + meta_list mf_a _loc xs) + + let rec meta_binding _loc = + function + | Ast.BiAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.BiEq (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiEq"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_expr _loc x2) + | Ast.BiAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiAnd"))), + meta_loc _loc x0), + meta_binding _loc x1), + meta_binding _loc x2) + | Ast.BiNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiNil"))), + meta_loc _loc x0) + and meta_class_expr _loc = + function + | Ast.CeAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.CeEq (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeEq"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_expr _loc x2) + | Ast.CeAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeAnd"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_expr _loc x2) + | Ast.CeTyc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeTyc"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_type _loc x2) + | Ast.CeStr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeStr"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_str_item _loc x2) + | Ast.CeLet (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeLet"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2), + meta_class_expr _loc x3) + | Ast.CeFun (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeFun"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_expr _loc x2) + | Ast.CeCon (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeCon"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_ident _loc x2), + meta_ctyp _loc x3) + | Ast.CeApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeApp"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_expr _loc x2) + | Ast.CeNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeNil"))), + meta_loc _loc x0) + and meta_class_sig_item _loc = + function + | Ast.CgAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.CgVir (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgVir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CgVal (x0, x1, x2, x3, x4) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_meta_bool _loc x3), + meta_ctyp _loc x4) + | Ast.CgMth (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgMth"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CgInh (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgInh"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.CgSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgSem"))), + meta_loc _loc x0), + meta_class_sig_item _loc x1), + meta_class_sig_item _loc x2) + | Ast.CgCtr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgCtr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.CgNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgNil"))), + meta_loc _loc x0) + and meta_class_str_item _loc = + function + | Ast.CrAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.CrVvr (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVvr"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CrVir (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CrVal (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_expr _loc x3) + | Ast.CrMth (x0, x1, x2, x3, x4) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrMth"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_expr _loc x3), + meta_ctyp _loc x4) + | Ast.CrIni (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrIni"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.CrInh (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrInh"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_string _loc x2) + | Ast.CrCtr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrCtr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.CrSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrSem"))), + meta_loc _loc x0), + meta_class_str_item _loc x1), + meta_class_str_item _loc x2) + | Ast.CrNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrNil"))), + meta_loc _loc x0) + and meta_class_type _loc = + function + | Ast.CtAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.CtEq (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtEq"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtCol (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtCol"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtAnd"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtSig (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtSig"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_class_sig_item _loc x2) + | Ast.CtFun (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtFun"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_class_type _loc x2) + | Ast.CtCon (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtCon"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_ident _loc x2), + meta_ctyp _loc x3) + | Ast.CtNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtNil"))), + meta_loc _loc x0) + and meta_ctyp _loc = + function + | Ast.TyAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.TyOfAmp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOfAmp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAmp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAmp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyVrnInfSup (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnInfSup"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyVrnInf (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnInf"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrnSup (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnSup"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrnEq (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnEq"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TySta (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySta"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyTup (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyTup"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyMut (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyMut"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyPrv (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyPrv"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyOr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAnd"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyOf (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOf"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TySum (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySum"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyCom (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCom"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TySem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySem"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyCol (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCol"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyRec (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyRec"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrn (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuM (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuM"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuP (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuP"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuo (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyPol (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyPol"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyOlb (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.TyObj (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyObj"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_meta_bool _loc x2) + | Ast.TyDcl (x0, x1, x2, x3, x4) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyDcl"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_list meta_ctyp _loc x2), + meta_ctyp _loc x3), + meta_list + (fun _loc (x1, x2) -> + Ast.ExTup (_loc, + Ast.ExCom (_loc, meta_ctyp _loc x1, + meta_ctyp _loc x2))) + _loc x4) + | Ast.TyMan (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyMan"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyId (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.TyLab (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.TyCls (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCls"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.TyArr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyArr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyApp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAny x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAny"))), + meta_loc _loc x0) + | Ast.TyAli (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAli"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyNil"))), + meta_loc _loc x0) + and meta_expr _loc = + function + | Ast.ExWhi (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExWhi"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExVrn (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExTyc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTyc"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_ctyp _loc x2) + | Ast.ExCom (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExCom"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExTup (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTup"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExTry (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTry"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_match_case _loc x2) + | Ast.ExStr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExStr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExSte (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSte"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExSnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSnd"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_string _loc x2) + | Ast.ExSeq (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSeq"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExRec (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExRec"))), + meta_loc _loc x0), + meta_rec_binding _loc x1), + meta_expr _loc x2) + | Ast.ExOvr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExOvr"))), + meta_loc _loc x0), + meta_rec_binding _loc x1) + | Ast.ExOlb (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.ExObj (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExObj"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_str_item _loc x2) + | Ast.ExNew (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNew"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.ExMat (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExMat"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_match_case _loc x2) + | Ast.ExLmd (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLmd"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_expr _loc x2), + meta_expr _loc x3) + | Ast.ExLet (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLet"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2), + meta_expr _loc x3) + | Ast.ExLaz (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLaz"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExLab (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.ExNativeInt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNativeInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt64 (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt64"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt32 (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt32"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExIfe (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExIfe"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2), + meta_expr _loc x3) + | Ast.ExFun (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFun"))), + meta_loc _loc x0), + meta_match_case _loc x1) + | Ast.ExFor (x0, x1, x2, x3, x4, x5) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFor"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2), + meta_expr _loc x3), + meta_meta_bool _loc x4), + meta_expr _loc x5) + | Ast.ExFlo (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFlo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExCoe (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExCoe"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_ctyp _loc x2), + meta_ctyp _loc x3) + | Ast.ExChr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExChr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExAss (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAss"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExAsr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAsr"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExAsf x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAsf"))), + meta_loc _loc x0) + | Ast.ExSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSem"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExArr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExArr"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExAre (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAre"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExApp"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.ExAcc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAcc"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExId (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.ExNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNil"))), + meta_loc _loc x0) + and meta_ident _loc = + function + | Ast.IdAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.IdUid (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdUid"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.IdLid (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdLid"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.IdApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdApp"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + | Ast.IdAcc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdAcc"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + and meta_match_case _loc = + function + | Ast.McAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.McArr (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McArr"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_expr _loc x2), + meta_expr _loc x3) + | Ast.McOr (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McOr"))), + meta_loc _loc x0), + meta_match_case _loc x1), + meta_match_case _loc x2) + | Ast.McNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McNil"))), + meta_loc _loc x0) + and meta_meta_bool _loc = + function + | Ast.BAnt x0 -> Ast.ExAnt (_loc, x0) + | Ast.BFalse -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BFalse"))) + | Ast.BTrue -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BTrue"))) + and meta_meta_list mf_a _loc = + function + | Ast.LAnt x0 -> Ast.ExAnt (_loc, x0) + | Ast.LCons (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "LCons"))), + mf_a _loc x0), + meta_meta_list mf_a _loc x1) + | Ast.LNil -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "LNil"))) + and meta_meta_option mf_a _loc = + function + | Ast.OAnt x0 -> Ast.ExAnt (_loc, x0) + | Ast.OSome x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "OSome"))), + mf_a _loc x0) + | Ast.ONone -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ONone"))) + and meta_module_binding _loc = + function + | Ast.MbAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.MbCol (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbCol"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.MbColEq (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbColEq"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_expr _loc x3) + | Ast.MbAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbAnd"))), + meta_loc _loc x0), + meta_module_binding _loc x1), + meta_module_binding _loc x2) + | Ast.MbNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbNil"))), + meta_loc _loc x0) + and meta_module_expr _loc = + function + | Ast.MeAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.MeTyc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeTyc"))), + meta_loc _loc x0), + meta_module_expr _loc x1), + meta_module_type _loc x2) + | Ast.MeStr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeStr"))), + meta_loc _loc x0), + meta_str_item _loc x1) + | Ast.MeFun (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeFun"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_expr _loc x3) + | Ast.MeApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeApp"))), + meta_loc _loc x0), + meta_module_expr _loc x1), + meta_module_expr _loc x2) + | Ast.MeId (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.MeNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeNil"))), + meta_loc _loc x0) + and meta_module_type _loc = + function + | Ast.MtAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.MtWit (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtWit"))), + meta_loc _loc x0), + meta_module_type _loc x1), + meta_with_constr _loc x2) + | Ast.MtSig (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtSig"))), + meta_loc _loc x0), + meta_sig_item _loc x1) + | Ast.MtQuo (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtQuo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.MtFun (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtFun"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_type _loc x3) + | Ast.MtId (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.MtNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtNil"))), + meta_loc _loc x0) + and meta_patt _loc = + function + | Ast.PaLaz (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaLaz"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaVrn (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaTyp (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTyp"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.PaTyc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTyc"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_ctyp _loc x2) + | Ast.PaTup (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTup"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaStr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaStr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaEq (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaEq"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_patt _loc x2) + | Ast.PaRec (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaRec"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaRng (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaRng"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaOrp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOrp"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaOlbi (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOlbi"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2), + meta_expr _loc x3) + | Ast.PaOlb (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2) + | Ast.PaLab (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2) + | Ast.PaFlo (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaFlo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaNativeInt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaNativeInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt64 (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt64"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt32 (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt32"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaChr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaChr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaSem"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaCom (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaCom"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaArr (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaArr"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaApp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaApp"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaAny x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAny"))), + meta_loc _loc x0) + | Ast.PaAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.PaAli (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAli"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaId (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.PaNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaNil"))), + meta_loc _loc x0) + and meta_rec_binding _loc = + function + | Ast.RbAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.RbEq (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbEq"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_expr _loc x2) + | Ast.RbSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbSem"))), + meta_loc _loc x0), + meta_rec_binding _loc x1), + meta_rec_binding _loc x2) + | Ast.RbNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbNil"))), + meta_loc _loc x0) + and meta_sig_item _loc = + function + | Ast.SgAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.SgVal (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.SgTyp (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.SgOpn (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgOpn"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.SgMty (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgMty"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.SgRecMod (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgRecMod"))), + meta_loc _loc x0), + meta_module_binding _loc x1) + | Ast.SgMod (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgMod"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.SgInc (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgInc"))), + meta_loc _loc x0), + meta_module_type _loc x1) + | Ast.SgExt (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgExt"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2), + meta_meta_list meta_string _loc x3) + | Ast.SgExc (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgExc"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.SgDir (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgDir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.SgSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgSem"))), + meta_loc _loc x0), + meta_sig_item _loc x1), + meta_sig_item _loc x2) + | Ast.SgClt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgClt"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.SgCls (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgCls"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.SgNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgNil"))), + meta_loc _loc x0) + and meta_str_item _loc = + function + | Ast.StAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.StVal (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StVal"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2) + | Ast.StTyp (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.StOpn (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StOpn"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.StMty (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StMty"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.StRecMod (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StRecMod"))), + meta_loc _loc x0), + meta_module_binding _loc x1) + | Ast.StMod (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StMod"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_expr _loc x2) + | Ast.StInc (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StInc"))), + meta_loc _loc x0), + meta_module_expr _loc x1) + | Ast.StExt (x0, x1, x2, x3) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExt"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2), + meta_meta_list meta_string _loc x3) + | Ast.StExp (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExp"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.StExc (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExc"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_meta_option meta_ident _loc x2) + | Ast.StDir (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StDir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.StSem (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StSem"))), + meta_loc _loc x0), + meta_str_item _loc x1), + meta_str_item _loc x2) + | Ast.StClt (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StClt"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.StCls (x0, x1) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StCls"))), + meta_loc _loc x0), + meta_class_expr _loc x1) + | Ast.StNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StNil"))), + meta_loc _loc x0) + and meta_with_constr _loc = + function + | Ast.WcAnt (x0, x1) -> Ast.ExAnt (x0, x1) + | Ast.WcAnd (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcAnd"))), + meta_loc _loc x0), + meta_with_constr _loc x1), + meta_with_constr _loc x2) + | Ast.WcMod (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcMod"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + | Ast.WcTyp (x0, x1, x2) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.WcNil x0 -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcNil"))), + meta_loc _loc x0) + + end + + let meta_loc = meta_loc_patt + + module Patt = + struct + let meta_string _loc s = Ast.PaStr (_loc, s) + + let meta_int _loc s = Ast.PaInt (_loc, s) + + let meta_float _loc s = Ast.PaFlo (_loc, s) + + let meta_char _loc s = Ast.PaChr (_loc, s) + + let meta_bool _loc = + function + | false -> + Ast.PaId (_loc, Ast.IdUid (_loc, "False")) + | true -> Ast.PaId (_loc, Ast.IdUid (_loc, "True")) + + let rec meta_list mf_a _loc = + function + | [] -> Ast.PaId (_loc, Ast.IdUid (_loc, "[]")) + | x :: xs -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "::")), + mf_a _loc x), + meta_list mf_a _loc xs) + + let rec meta_binding _loc = + function + | Ast.BiAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.BiEq (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiEq"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_expr _loc x2) + | Ast.BiAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiAnd"))), + meta_loc _loc x0), + meta_binding _loc x1), + meta_binding _loc x2) + | Ast.BiNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiNil"))), + meta_loc _loc x0) + and meta_class_expr _loc = + function + | Ast.CeAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.CeEq (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeEq"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_expr _loc x2) + | Ast.CeAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeAnd"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_expr _loc x2) + | Ast.CeTyc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeTyc"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_class_type _loc x2) + | Ast.CeStr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeStr"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_str_item _loc x2) + | Ast.CeLet (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeLet"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2), + meta_class_expr _loc x3) + | Ast.CeFun (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeFun"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_expr _loc x2) + | Ast.CeCon (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeCon"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_ident _loc x2), + meta_ctyp _loc x3) + | Ast.CeApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeApp"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_expr _loc x2) + | Ast.CeNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeNil"))), + meta_loc _loc x0) + and meta_class_sig_item _loc = + function + | Ast.CgAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.CgVir (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgVir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CgVal (x0, x1, x2, x3, x4) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_meta_bool _loc x3), + meta_ctyp _loc x4) + | Ast.CgMth (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgMth"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CgInh (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgInh"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.CgSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgSem"))), + meta_loc _loc x0), + meta_class_sig_item _loc x1), + meta_class_sig_item _loc x2) + | Ast.CgCtr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgCtr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.CgNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgNil"))), + meta_loc _loc x0) + and meta_class_str_item _loc = + function + | Ast.CrAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.CrVvr (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVvr"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CrVir (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_ctyp _loc x3) + | Ast.CrVal (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_expr _loc x3) + | Ast.CrMth (x0, x1, x2, x3, x4) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrMth"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_meta_bool _loc x2), + meta_expr _loc x3), + meta_ctyp _loc x4) + | Ast.CrIni (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrIni"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.CrInh (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrInh"))), + meta_loc _loc x0), + meta_class_expr _loc x1), + meta_string _loc x2) + | Ast.CrCtr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrCtr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.CrSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrSem"))), + meta_loc _loc x0), + meta_class_str_item _loc x1), + meta_class_str_item _loc x2) + | Ast.CrNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrNil"))), + meta_loc _loc x0) + and meta_class_type _loc = + function + | Ast.CtAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.CtEq (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtEq"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtCol (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtCol"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtAnd"))), + meta_loc _loc x0), + meta_class_type _loc x1), + meta_class_type _loc x2) + | Ast.CtSig (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtSig"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_class_sig_item _loc x2) + | Ast.CtFun (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtFun"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_class_type _loc x2) + | Ast.CtCon (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtCon"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_ident _loc x2), + meta_ctyp _loc x3) + | Ast.CtNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtNil"))), + meta_loc _loc x0) + and meta_ctyp _loc = + function + | Ast.TyAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.TyOfAmp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOfAmp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAmp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAmp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyVrnInfSup (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnInfSup"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyVrnInf (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnInf"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrnSup (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnSup"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrnEq (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrnEq"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TySta (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySta"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyTup (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyTup"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyMut (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyMut"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyPrv (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyPrv"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyOr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAnd"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyOf (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOf"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TySum (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySum"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyCom (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCom"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TySem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TySem"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyCol (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCol"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyRec (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyRec"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.TyVrn (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuM (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuM"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuP (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuP"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyQuo (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyQuo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.TyPol (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyPol"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyOlb (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.TyObj (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyObj"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_meta_bool _loc x2) + | Ast.TyDcl (x0, x1, x2, x3, x4) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyDcl"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_list meta_ctyp _loc x2), + meta_ctyp _loc x3), + meta_list + (fun _loc (x1, x2) -> + Ast.PaTup (_loc, + Ast.PaCom (_loc, meta_ctyp _loc x1, + meta_ctyp _loc x2))) + _loc x4) + | Ast.TyMan (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyMan"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyId (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.TyLab (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.TyCls (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyCls"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.TyArr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyArr"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyApp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyAny x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAny"))), + meta_loc _loc x0) + | Ast.TyAli (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAli"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.TyNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyNil"))), + meta_loc _loc x0) + and meta_expr _loc = + function + | Ast.ExWhi (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExWhi"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExVrn (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExTyc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTyc"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_ctyp _loc x2) + | Ast.ExCom (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExCom"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExTup (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTup"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExTry (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExTry"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_match_case _loc x2) + | Ast.ExStr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExStr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExSte (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSte"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExSnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSnd"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_string _loc x2) + | Ast.ExSeq (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSeq"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExRec (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExRec"))), + meta_loc _loc x0), + meta_rec_binding _loc x1), + meta_expr _loc x2) + | Ast.ExOvr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExOvr"))), + meta_loc _loc x0), + meta_rec_binding _loc x1) + | Ast.ExOlb (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.ExObj (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExObj"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_class_str_item _loc x2) + | Ast.ExNew (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNew"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.ExMat (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExMat"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_match_case _loc x2) + | Ast.ExLmd (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLmd"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_expr _loc x2), + meta_expr _loc x3) + | Ast.ExLet (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLet"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2), + meta_expr _loc x3) + | Ast.ExLaz (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLaz"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExLab (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.ExNativeInt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNativeInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt64 (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt64"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt32 (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt32"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExInt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExIfe (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExIfe"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2), + meta_expr _loc x3) + | Ast.ExFun (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFun"))), + meta_loc _loc x0), + meta_match_case _loc x1) + | Ast.ExFor (x0, x1, x2, x3, x4, x5) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFor"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2), + meta_expr _loc x3), + meta_meta_bool _loc x4), + meta_expr _loc x5) + | Ast.ExFlo (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExFlo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExCoe (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExCoe"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_ctyp _loc x2), + meta_ctyp _loc x3) + | Ast.ExChr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExChr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.ExAss (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAss"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExAsr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAsr"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExAsf x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAsf"))), + meta_loc _loc x0) + | Ast.ExSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExSem"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExArr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExArr"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.ExAre (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAre"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExApp"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.ExAcc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAcc"))), + meta_loc _loc x0), + meta_expr _loc x1), + meta_expr _loc x2) + | Ast.ExId (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.ExNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExNil"))), + meta_loc _loc x0) + and meta_ident _loc = + function + | Ast.IdAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.IdUid (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdUid"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.IdLid (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdLid"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.IdApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdApp"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + | Ast.IdAcc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdAcc"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + and meta_match_case _loc = + function + | Ast.McAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.McArr (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McArr"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_expr _loc x2), + meta_expr _loc x3) + | Ast.McOr (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McOr"))), + meta_loc _loc x0), + meta_match_case _loc x1), + meta_match_case _loc x2) + | Ast.McNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McNil"))), + meta_loc _loc x0) + and meta_meta_bool _loc = + function + | Ast.BAnt x0 -> Ast.PaAnt (_loc, x0) + | Ast.BFalse -> + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BFalse"))) + | Ast.BTrue -> + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BTrue"))) + and meta_meta_list mf_a _loc = + function + | Ast.LAnt x0 -> Ast.PaAnt (_loc, x0) + | Ast.LCons (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "LCons"))), + mf_a _loc x0), + meta_meta_list mf_a _loc x1) + | Ast.LNil -> + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "LNil"))) + and meta_meta_option mf_a _loc = + function + | Ast.OAnt x0 -> Ast.PaAnt (_loc, x0) + | Ast.OSome x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "OSome"))), + mf_a _loc x0) + | Ast.ONone -> + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ONone"))) + and meta_module_binding _loc = + function + | Ast.MbAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.MbCol (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbCol"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.MbColEq (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbColEq"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_expr _loc x3) + | Ast.MbAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbAnd"))), + meta_loc _loc x0), + meta_module_binding _loc x1), + meta_module_binding _loc x2) + | Ast.MbNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbNil"))), + meta_loc _loc x0) + and meta_module_expr _loc = + function + | Ast.MeAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.MeTyc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeTyc"))), + meta_loc _loc x0), + meta_module_expr _loc x1), + meta_module_type _loc x2) + | Ast.MeStr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeStr"))), + meta_loc _loc x0), + meta_str_item _loc x1) + | Ast.MeFun (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeFun"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_expr _loc x3) + | Ast.MeApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeApp"))), + meta_loc _loc x0), + meta_module_expr _loc x1), + meta_module_expr _loc x2) + | Ast.MeId (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.MeNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeNil"))), + meta_loc _loc x0) + and meta_module_type _loc = + function + | Ast.MtAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.MtWit (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtWit"))), + meta_loc _loc x0), + meta_module_type _loc x1), + meta_with_constr _loc x2) + | Ast.MtSig (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtSig"))), + meta_loc _loc x0), + meta_sig_item _loc x1) + | Ast.MtQuo (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtQuo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.MtFun (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtFun"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2), + meta_module_type _loc x3) + | Ast.MtId (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.MtNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtNil"))), + meta_loc _loc x0) + and meta_patt _loc = + function + | Ast.PaLaz (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaLaz"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaVrn (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaVrn"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaTyp (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTyp"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.PaTyc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTyc"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_ctyp _loc x2) + | Ast.PaTup (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaTup"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaStr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaStr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaEq (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaEq"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_patt _loc x2) + | Ast.PaRec (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaRec"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaRng (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaRng"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaOrp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOrp"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaOlbi (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOlbi"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2), + meta_expr _loc x3) + | Ast.PaOlb (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaOlb"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2) + | Ast.PaLab (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaLab"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_patt _loc x2) + | Ast.PaFlo (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaFlo"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaNativeInt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaNativeInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt64 (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt64"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt32 (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt32"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaInt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaInt"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaChr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaChr"))), + meta_loc _loc x0), + meta_string _loc x1) + | Ast.PaSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaSem"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaCom (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaCom"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaArr (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaArr"))), + meta_loc _loc x0), + meta_patt _loc x1) + | Ast.PaApp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaApp"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaAny x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAny"))), + meta_loc _loc x0) + | Ast.PaAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.PaAli (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAli"))), + meta_loc _loc x0), + meta_patt _loc x1), + meta_patt _loc x2) + | Ast.PaId (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaId"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.PaNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaNil"))), + meta_loc _loc x0) + and meta_rec_binding _loc = + function + | Ast.RbAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.RbEq (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbEq"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_expr _loc x2) + | Ast.RbSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbSem"))), + meta_loc _loc x0), + meta_rec_binding _loc x1), + meta_rec_binding _loc x2) + | Ast.RbNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbNil"))), + meta_loc _loc x0) + and meta_sig_item _loc = + function + | Ast.SgAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.SgVal (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgVal"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2) + | Ast.SgTyp (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.SgOpn (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgOpn"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.SgMty (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgMty"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.SgRecMod (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgRecMod"))), + meta_loc _loc x0), + meta_module_binding _loc x1) + | Ast.SgMod (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgMod"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.SgInc (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgInc"))), + meta_loc _loc x0), + meta_module_type _loc x1) + | Ast.SgExt (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgExt"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2), + meta_meta_list meta_string _loc x3) + | Ast.SgExc (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgExc"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.SgDir (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgDir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.SgSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgSem"))), + meta_loc _loc x0), + meta_sig_item _loc x1), + meta_sig_item _loc x2) + | Ast.SgClt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgClt"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.SgCls (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgCls"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.SgNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgNil"))), + meta_loc _loc x0) + and meta_str_item _loc = + function + | Ast.StAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.StVal (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StVal"))), + meta_loc _loc x0), + meta_meta_bool _loc x1), + meta_binding _loc x2) + | Ast.StTyp (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1) + | Ast.StOpn (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StOpn"))), + meta_loc _loc x0), + meta_ident _loc x1) + | Ast.StMty (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StMty"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_type _loc x2) + | Ast.StRecMod (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StRecMod"))), + meta_loc _loc x0), + meta_module_binding _loc x1) + | Ast.StMod (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StMod"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_module_expr _loc x2) + | Ast.StInc (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StInc"))), + meta_loc _loc x0), + meta_module_expr _loc x1) + | Ast.StExt (x0, x1, x2, x3) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExt"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_ctyp _loc x2), + meta_meta_list meta_string _loc x3) + | Ast.StExp (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExp"))), + meta_loc _loc x0), + meta_expr _loc x1) + | Ast.StExc (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StExc"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_meta_option meta_ident _loc x2) + | Ast.StDir (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StDir"))), + meta_loc _loc x0), + meta_string _loc x1), + meta_expr _loc x2) + | Ast.StSem (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StSem"))), + meta_loc _loc x0), + meta_str_item _loc x1), + meta_str_item _loc x2) + | Ast.StClt (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StClt"))), + meta_loc _loc x0), + meta_class_type _loc x1) + | Ast.StCls (x0, x1) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StCls"))), + meta_loc _loc x0), + meta_class_expr _loc x1) + | Ast.StNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StNil"))), + meta_loc _loc x0) + and meta_with_constr _loc = + function + | Ast.WcAnt (x0, x1) -> Ast.PaAnt (x0, x1) + | Ast.WcAnd (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcAnd"))), + meta_loc _loc x0), + meta_with_constr _loc x1), + meta_with_constr _loc x2) + | Ast.WcMod (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcMod"))), + meta_loc _loc x0), + meta_ident _loc x1), + meta_ident _loc x2) + | Ast.WcTyp (x0, x1, x2) -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcTyp"))), + meta_loc _loc x0), + meta_ctyp _loc x1), + meta_ctyp _loc x2) + | Ast.WcNil x0 -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcNil"))), + meta_loc _loc x0) + + end + + end + + end + + class map = + object ((o : 'self_type)) + method string : string -> string = o#unknown + + method list : + 'a 'a_out. + ('self_type -> 'a -> 'a_out) -> 'a list -> 'a_out list = + fun _f_a -> + function + | [] -> [] + | _x :: _x_i1 -> + let _x = _f_a o _x in + let _x_i1 = o#list _f_a _x_i1 in _x :: _x_i1 + + method with_constr : with_constr -> with_constr = + function + | WcNil _x -> let _x = o#loc _x in WcNil _x + | WcTyp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in WcTyp (_x, _x_i1, _x_i2) + | WcMod (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in WcMod (_x, _x_i1, _x_i2) + | WcAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#with_constr _x_i1 in + let _x_i2 = o#with_constr _x_i2 + in WcAnd (_x, _x_i1, _x_i2) + | WcAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in WcAnt (_x, _x_i1) + + method str_item : str_item -> str_item = + function + | StNil _x -> let _x = o#loc _x in StNil _x + | StCls (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in StCls (_x, _x_i1) + | StClt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in StClt (_x, _x_i1) + | StSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#str_item _x_i1 in + let _x_i2 = o#str_item _x_i2 + in StSem (_x, _x_i1, _x_i2) + | StDir (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in StDir (_x, _x_i1, _x_i2) + | StExc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#meta_option (fun o -> o#ident) _x_i2 + in StExc (_x, _x_i1, _x_i2) + | StExp (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in StExp (_x, _x_i1) + | StExt (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#meta_list (fun o -> o#string) _x_i3 + in StExt (_x, _x_i1, _x_i2, _x_i3) + | StInc (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in StInc (_x, _x_i1) + | StMod (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_expr _x_i2 + in StMod (_x, _x_i1, _x_i2) + | StRecMod (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 + in StRecMod (_x, _x_i1) + | StMty (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 + in StMty (_x, _x_i1, _x_i2) + | StOpn (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in StOpn (_x, _x_i1) + | StTyp (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in StTyp (_x, _x_i1) + | StVal (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in StVal (_x, _x_i1, _x_i2) + | StAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in StAnt (_x, _x_i1) + + method sig_item : sig_item -> sig_item = + function + | SgNil _x -> let _x = o#loc _x in SgNil _x + | SgCls (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in SgCls (_x, _x_i1) + | SgClt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in SgClt (_x, _x_i1) + | SgSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#sig_item _x_i1 in + let _x_i2 = o#sig_item _x_i2 + in SgSem (_x, _x_i1, _x_i2) + | SgDir (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in SgDir (_x, _x_i1, _x_i2) + | SgExc (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in SgExc (_x, _x_i1) + | SgExt (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#meta_list (fun o -> o#string) _x_i3 + in SgExt (_x, _x_i1, _x_i2, _x_i3) + | SgInc (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#module_type _x_i1 in SgInc (_x, _x_i1) + | SgMod (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 + in SgMod (_x, _x_i1, _x_i2) + | SgRecMod (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 + in SgRecMod (_x, _x_i1) + | SgMty (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 + in SgMty (_x, _x_i1, _x_i2) + | SgOpn (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in SgOpn (_x, _x_i1) + | SgTyp (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in SgTyp (_x, _x_i1) + | SgVal (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in SgVal (_x, _x_i1, _x_i2) + | SgAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in SgAnt (_x, _x_i1) + + method rec_binding : rec_binding -> rec_binding = + function + | RbNil _x -> let _x = o#loc _x in RbNil _x + | RbSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in + let _x_i2 = o#rec_binding _x_i2 + in RbSem (_x, _x_i1, _x_i2) + | RbEq (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#expr _x_i2 in RbEq (_x, _x_i1, _x_i2) + | RbAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in RbAnt (_x, _x_i1) + + method patt : patt -> patt = + function + | PaNil _x -> let _x = o#loc _x in PaNil _x + | PaId (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in PaId (_x, _x_i1) + | PaAli (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaAli (_x, _x_i1, _x_i2) + | PaAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaAnt (_x, _x_i1) + | PaAny _x -> let _x = o#loc _x in PaAny _x + | PaApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaApp (_x, _x_i1, _x_i2) + | PaArr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in PaArr (_x, _x_i1) + | PaCom (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaCom (_x, _x_i1, _x_i2) + | PaSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaSem (_x, _x_i1, _x_i2) + | PaChr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaChr (_x, _x_i1) + | PaInt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt (_x, _x_i1) + | PaInt32 (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt32 (_x, _x_i1) + | PaInt64 (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt64 (_x, _x_i1) + | PaNativeInt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaNativeInt (_x, _x_i1) + | PaFlo (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaFlo (_x, _x_i1) + | PaLab (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in PaLab (_x, _x_i1, _x_i2) + | PaOlb (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in PaOlb (_x, _x_i1, _x_i2) + | PaOlbi (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in + let _x_i3 = o#expr _x_i3 + in PaOlbi (_x, _x_i1, _x_i2, _x_i3) + | PaOrp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaOrp (_x, _x_i1, _x_i2) + | PaRng (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaRng (_x, _x_i1, _x_i2) + | PaRec (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in PaRec (_x, _x_i1) + | PaEq (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#patt _x_i2 in PaEq (_x, _x_i1, _x_i2) + | PaStr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaStr (_x, _x_i1) + | PaTup (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in PaTup (_x, _x_i1) + | PaTyc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#ctyp _x_i2 in PaTyc (_x, _x_i1, _x_i2) + | PaTyp (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in PaTyp (_x, _x_i1) + | PaVrn (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaVrn (_x, _x_i1) + | PaLaz (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in PaLaz (_x, _x_i1) + + method module_type : module_type -> module_type = + function + | MtNil _x -> let _x = o#loc _x in MtNil _x + | MtId (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in MtId (_x, _x_i1) + | MtFun (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_type _x_i3 + in MtFun (_x, _x_i1, _x_i2, _x_i3) + | MtQuo (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MtQuo (_x, _x_i1) + | MtSig (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#sig_item _x_i1 in MtSig (_x, _x_i1) + | MtWit (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#module_type _x_i1 in + let _x_i2 = o#with_constr _x_i2 + in MtWit (_x, _x_i1, _x_i2) + | MtAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MtAnt (_x, _x_i1) + + method module_expr : module_expr -> module_expr = + function + | MeNil _x -> let _x = o#loc _x in MeNil _x + | MeId (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in MeId (_x, _x_i1) + | MeApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in + let _x_i2 = o#module_expr _x_i2 + in MeApp (_x, _x_i1, _x_i2) + | MeFun (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_expr _x_i3 + in MeFun (_x, _x_i1, _x_i2, _x_i3) + | MeStr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#str_item _x_i1 in MeStr (_x, _x_i1) + | MeTyc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in + let _x_i2 = o#module_type _x_i2 + in MeTyc (_x, _x_i1, _x_i2) + | MeAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MeAnt (_x, _x_i1) + + method module_binding : module_binding -> module_binding = + function + | MbNil _x -> let _x = o#loc _x in MbNil _x + | MbAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 in + let _x_i2 = o#module_binding _x_i2 + in MbAnd (_x, _x_i1, _x_i2) + | MbColEq (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_expr _x_i3 + in MbColEq (_x, _x_i1, _x_i2, _x_i3) + | MbCol (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 + in MbCol (_x, _x_i1, _x_i2) + | MbAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MbAnt (_x, _x_i1) + + method meta_option : + 'a 'a_out. + ('self_type -> 'a -> 'a_out) -> + 'a meta_option -> 'a_out meta_option = + fun _f_a -> + function + | ONone -> ONone + | OSome _x -> let _x = _f_a o _x in OSome _x + | OAnt _x -> let _x = o#string _x in OAnt _x + + method meta_list : + 'a 'a_out. + ('self_type -> 'a -> 'a_out) -> + 'a meta_list -> 'a_out meta_list = + fun _f_a -> + function + | LNil -> LNil + | LCons (_x, _x_i1) -> + let _x = _f_a o _x in + let _x_i1 = o#meta_list _f_a _x_i1 + in LCons (_x, _x_i1) + | LAnt _x -> let _x = o#string _x in LAnt _x + + method meta_bool : meta_bool -> meta_bool = + function + | BTrue -> BTrue + | BFalse -> BFalse + | BAnt _x -> let _x = o#string _x in BAnt _x + + method match_case : match_case -> match_case = + function + | McNil _x -> let _x = o#loc _x in McNil _x + | McOr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#match_case _x_i1 in + let _x_i2 = o#match_case _x_i2 + in McOr (_x, _x_i1, _x_i2) + | McArr (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 + in McArr (_x, _x_i1, _x_i2, _x_i3) + | McAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in McAnt (_x, _x_i1) + + method loc : loc -> loc = o#unknown + + method ident : ident -> ident = + function + | IdAcc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in IdAcc (_x, _x_i1, _x_i2) + | IdApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in IdApp (_x, _x_i1, _x_i2) + | IdLid (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdLid (_x, _x_i1) + | IdUid (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdUid (_x, _x_i1) + | IdAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdAnt (_x, _x_i1) + + method expr : expr -> expr = + function + | ExNil _x -> let _x = o#loc _x in ExNil _x + | ExId (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in ExId (_x, _x_i1) + | ExAcc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAcc (_x, _x_i1, _x_i2) + | ExAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExAnt (_x, _x_i1) + | ExApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExApp (_x, _x_i1, _x_i2) + | ExAre (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAre (_x, _x_i1, _x_i2) + | ExArr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in ExArr (_x, _x_i1) + | ExSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExSem (_x, _x_i1, _x_i2) + | ExAsf _x -> let _x = o#loc _x in ExAsf _x + | ExAsr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in ExAsr (_x, _x_i1) + | ExAss (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAss (_x, _x_i1, _x_i2) + | ExChr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExChr (_x, _x_i1) + | ExCoe (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in ExCoe (_x, _x_i1, _x_i2, _x_i3) + | ExFlo (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExFlo (_x, _x_i1) + | ExFor (_x, _x_i1, _x_i2, _x_i3, _x_i4, _x_i5) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 in + let _x_i4 = o#meta_bool _x_i4 in + let _x_i5 = o#expr _x_i5 + in ExFor (_x, _x_i1, _x_i2, _x_i3, _x_i4, _x_i5) + | ExFun (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#match_case _x_i1 in ExFun (_x, _x_i1) + | ExIfe (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 + in ExIfe (_x, _x_i1, _x_i2, _x_i3) + | ExInt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt (_x, _x_i1) + | ExInt32 (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt32 (_x, _x_i1) + | ExInt64 (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt64 (_x, _x_i1) + | ExNativeInt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExNativeInt (_x, _x_i1) + | ExLab (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in ExLab (_x, _x_i1, _x_i2) + | ExLaz (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in ExLaz (_x, _x_i1) + | ExLet (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in + let _x_i3 = o#expr _x_i3 + in ExLet (_x, _x_i1, _x_i2, _x_i3) + | ExLmd (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_expr _x_i2 in + let _x_i3 = o#expr _x_i3 + in ExLmd (_x, _x_i1, _x_i2, _x_i3) + | ExMat (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#match_case _x_i2 + in ExMat (_x, _x_i1, _x_i2) + | ExNew (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in ExNew (_x, _x_i1) + | ExObj (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_str_item _x_i2 + in ExObj (_x, _x_i1, _x_i2) + | ExOlb (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in ExOlb (_x, _x_i1, _x_i2) + | ExOvr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in ExOvr (_x, _x_i1) + | ExRec (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in + let _x_i2 = o#expr _x_i2 in ExRec (_x, _x_i1, _x_i2) + | ExSeq (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in ExSeq (_x, _x_i1) + | ExSnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#string _x_i2 in ExSnd (_x, _x_i1, _x_i2) + | ExSte (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExSte (_x, _x_i1, _x_i2) + | ExStr (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExStr (_x, _x_i1) + | ExTry (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#match_case _x_i2 + in ExTry (_x, _x_i1, _x_i2) + | ExTup (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in ExTup (_x, _x_i1) + | ExCom (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExCom (_x, _x_i1, _x_i2) + | ExTyc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#ctyp _x_i2 in ExTyc (_x, _x_i1, _x_i2) + | ExVrn (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExVrn (_x, _x_i1) + | ExWhi (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExWhi (_x, _x_i1, _x_i2) + + method ctyp : ctyp -> ctyp = + function + | TyNil _x -> let _x = o#loc _x in TyNil _x + | TyAli (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAli (_x, _x_i1, _x_i2) + | TyAny _x -> let _x = o#loc _x in TyAny _x + | TyApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyApp (_x, _x_i1, _x_i2) + | TyArr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyArr (_x, _x_i1, _x_i2) + | TyCls (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in TyCls (_x, _x_i1) + | TyLab (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyLab (_x, _x_i1, _x_i2) + | TyId (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in TyId (_x, _x_i1) + | TyMan (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyMan (_x, _x_i1, _x_i2) + | TyDcl (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#list (fun o -> o#ctyp) _x_i2 in + let _x_i3 = o#ctyp _x_i3 in + let _x_i4 = + o#list + (fun o (_x, _x_i1) -> + let _x = o#ctyp _x in + let _x_i1 = o#ctyp _x_i1 in (_x, _x_i1)) + _x_i4 + in TyDcl (_x, _x_i1, _x_i2, _x_i3, _x_i4) + | TyObj (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#meta_bool _x_i2 + in TyObj (_x, _x_i1, _x_i2) + | TyOlb (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOlb (_x, _x_i1, _x_i2) + | TyPol (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyPol (_x, _x_i1, _x_i2) + | TyQuo (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuo (_x, _x_i1) + | TyQuP (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuP (_x, _x_i1) + | TyQuM (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuM (_x, _x_i1) + | TyVrn (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyVrn (_x, _x_i1) + | TyRec (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyRec (_x, _x_i1) + | TyCol (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyCol (_x, _x_i1, _x_i2) + | TySem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TySem (_x, _x_i1, _x_i2) + | TyCom (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyCom (_x, _x_i1, _x_i2) + | TySum (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TySum (_x, _x_i1) + | TyOf (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOf (_x, _x_i1, _x_i2) + | TyAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAnd (_x, _x_i1, _x_i2) + | TyOr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOr (_x, _x_i1, _x_i2) + | TyPrv (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyPrv (_x, _x_i1) + | TyMut (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyMut (_x, _x_i1) + | TyTup (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyTup (_x, _x_i1) + | TySta (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TySta (_x, _x_i1, _x_i2) + | TyVrnEq (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnEq (_x, _x_i1) + | TyVrnSup (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnSup (_x, _x_i1) + | TyVrnInf (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnInf (_x, _x_i1) + | TyVrnInfSup (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 + in TyVrnInfSup (_x, _x_i1, _x_i2) + | TyAmp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAmp (_x, _x_i1, _x_i2) + | TyOfAmp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOfAmp (_x, _x_i1, _x_i2) + | TyAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyAnt (_x, _x_i1) + + method class_type : class_type -> class_type = + function + | CtNil _x -> let _x = o#loc _x in CtNil _x + | CtCon (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#ident _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CtCon (_x, _x_i1, _x_i2, _x_i3) + | CtFun (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#class_type _x_i2 + in CtFun (_x, _x_i1, _x_i2) + | CtSig (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#class_sig_item _x_i2 + in CtSig (_x, _x_i1, _x_i2) + | CtAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 + in CtAnd (_x, _x_i1, _x_i2) + | CtCol (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 + in CtCol (_x, _x_i1, _x_i2) + | CtEq (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 + in CtEq (_x, _x_i1, _x_i2) + | CtAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CtAnt (_x, _x_i1) + + method class_str_item : class_str_item -> class_str_item = + function + | CrNil _x -> let _x = o#loc _x in CrNil _x + | CrSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_str_item _x_i1 in + let _x_i2 = o#class_str_item _x_i2 + in CrSem (_x, _x_i1, _x_i2) + | CrCtr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in CrCtr (_x, _x_i1, _x_i2) + | CrInh (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#string _x_i2 in CrInh (_x, _x_i1, _x_i2) + | CrIni (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in CrIni (_x, _x_i1) + | CrMth (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#expr _x_i3 in + let _x_i4 = o#ctyp _x_i4 + in CrMth (_x, _x_i1, _x_i2, _x_i3, _x_i4) + | CrVal (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#expr _x_i3 + in CrVal (_x, _x_i1, _x_i2, _x_i3) + | CrVir (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CrVir (_x, _x_i1, _x_i2, _x_i3) + | CrVvr (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CrVvr (_x, _x_i1, _x_i2, _x_i3) + | CrAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CrAnt (_x, _x_i1) + + method class_sig_item : class_sig_item -> class_sig_item = + function + | CgNil _x -> let _x = o#loc _x in CgNil _x + | CgCtr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in CgCtr (_x, _x_i1, _x_i2) + | CgSem (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_sig_item _x_i1 in + let _x_i2 = o#class_sig_item _x_i2 + in CgSem (_x, _x_i1, _x_i2) + | CgInh (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in CgInh (_x, _x_i1) + | CgMth (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CgMth (_x, _x_i1, _x_i2, _x_i3) + | CgVal (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#meta_bool _x_i3 in + let _x_i4 = o#ctyp _x_i4 + in CgVal (_x, _x_i1, _x_i2, _x_i3, _x_i4) + | CgVir (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CgVir (_x, _x_i1, _x_i2, _x_i3) + | CgAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CgAnt (_x, _x_i1) + + method class_expr : class_expr -> class_expr = + function + | CeNil _x -> let _x = o#loc _x in CeNil _x + | CeApp (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#expr _x_i2 in CeApp (_x, _x_i1, _x_i2) + | CeCon (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#ident _x_i2 in + let _x_i3 = o#ctyp _x_i3 + in CeCon (_x, _x_i1, _x_i2, _x_i3) + | CeFun (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_expr _x_i2 + in CeFun (_x, _x_i1, _x_i2) + | CeLet (_x, _x_i1, _x_i2, _x_i3) -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in + let _x_i3 = o#class_expr _x_i3 + in CeLet (_x, _x_i1, _x_i2, _x_i3) + | CeStr (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_str_item _x_i2 + in CeStr (_x, _x_i1, _x_i2) + | CeTyc (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_type _x_i2 + in CeTyc (_x, _x_i1, _x_i2) + | CeAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_expr _x_i2 + in CeAnd (_x, _x_i1, _x_i2) + | CeEq (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_expr _x_i2 + in CeEq (_x, _x_i1, _x_i2) + | CeAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CeAnt (_x, _x_i1) + + method binding : binding -> binding = + function + | BiNil _x -> let _x = o#loc _x in BiNil _x + | BiAnd (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#binding _x_i1 in + let _x_i2 = o#binding _x_i2 in BiAnd (_x, _x_i1, _x_i2) + | BiEq (_x, _x_i1, _x_i2) -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#expr _x_i2 in BiEq (_x, _x_i1, _x_i2) + | BiAnt (_x, _x_i1) -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in BiAnt (_x, _x_i1) + + method unknown : 'a. 'a -> 'a = fun x -> x + + end + + class fold = + object ((o : 'self_type)) + method string : string -> 'self_type = o#unknown + + method list : + 'a. + ('self_type -> 'a -> 'self_type) -> 'a list -> 'self_type = + fun _f_a -> + function + | [] -> o + | _x :: _x_i1 -> + let o = _f_a o _x in let o = o#list _f_a _x_i1 in o + + method with_constr : with_constr -> 'self_type = + function + | WcNil _x -> let o = o#loc _x in o + | WcTyp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | WcMod (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | WcAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#with_constr _x_i1 in + let o = o#with_constr _x_i2 in o + | WcAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method str_item : str_item -> 'self_type = + function + | StNil _x -> let o = o#loc _x in o + | StCls (_x, _x_i1) -> + let o = o#loc _x in let o = o#class_expr _x_i1 in o + | StClt (_x, _x_i1) -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | StSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#str_item _x_i1 in + let o = o#str_item _x_i2 in o + | StDir (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | StExc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in + let o = o#meta_option (fun o -> o#ident) _x_i2 in o + | StExp (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | StExt (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#ctyp _x_i2 in + let o = o#meta_list (fun o -> o#string) _x_i3 in o + | StInc (_x, _x_i1) -> + let o = o#loc _x in let o = o#module_expr _x_i1 in o + | StMod (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_expr _x_i2 in o + | StRecMod (_x, _x_i1) -> + let o = o#loc _x in let o = o#module_binding _x_i1 in o + | StMty (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in o + | StOpn (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | StTyp (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | StVal (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#binding _x_i2 in o + | StAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method sig_item : sig_item -> 'self_type = + function + | SgNil _x -> let o = o#loc _x in o + | SgCls (_x, _x_i1) -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | SgClt (_x, _x_i1) -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | SgSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#sig_item _x_i1 in + let o = o#sig_item _x_i2 in o + | SgDir (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | SgExc (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | SgExt (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#ctyp _x_i2 in + let o = o#meta_list (fun o -> o#string) _x_i3 in o + | SgInc (_x, _x_i1) -> + let o = o#loc _x in let o = o#module_type _x_i1 in o + | SgMod (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in o + | SgRecMod (_x, _x_i1) -> + let o = o#loc _x in let o = o#module_binding _x_i1 in o + | SgMty (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in o + | SgOpn (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | SgTyp (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | SgVal (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | SgAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method rec_binding : rec_binding -> 'self_type = + function + | RbNil _x -> let o = o#loc _x in o + | RbSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#rec_binding _x_i1 in + let o = o#rec_binding _x_i2 in o + | RbEq (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#expr _x_i2 in o + | RbAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method patt : patt -> 'self_type = + function + | PaNil _x -> let o = o#loc _x in o + | PaId (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | PaAli (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaAny _x -> let o = o#loc _x in o + | PaApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaArr (_x, _x_i1) -> + let o = o#loc _x in let o = o#patt _x_i1 in o + | PaCom (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaChr (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt32 (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt64 (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaNativeInt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaFlo (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaLab (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#patt _x_i2 in o + | PaOlb (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#patt _x_i2 in o + | PaOlbi (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#patt _x_i2 in let o = o#expr _x_i3 in o + | PaOrp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaRng (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaRec (_x, _x_i1) -> + let o = o#loc _x in let o = o#patt _x_i1 in o + | PaEq (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#patt _x_i2 in o + | PaStr (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaTup (_x, _x_i1) -> + let o = o#loc _x in let o = o#patt _x_i1 in o + | PaTyc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#ctyp _x_i2 in o + | PaTyp (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | PaVrn (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaLaz (_x, _x_i1) -> + let o = o#loc _x in let o = o#patt _x_i1 in o + + method module_type : module_type -> 'self_type = + function + | MtNil _x -> let o = o#loc _x in o + | MtId (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | MtFun (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in + let o = o#module_type _x_i3 in o + | MtQuo (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | MtSig (_x, _x_i1) -> + let o = o#loc _x in let o = o#sig_item _x_i1 in o + | MtWit (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#module_type _x_i1 in + let o = o#with_constr _x_i2 in o + | MtAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method module_expr : module_expr -> 'self_type = + function + | MeNil _x -> let o = o#loc _x in o + | MeId (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | MeApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#module_expr _x_i1 in + let o = o#module_expr _x_i2 in o + | MeFun (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in + let o = o#module_expr _x_i3 in o + | MeStr (_x, _x_i1) -> + let o = o#loc _x in let o = o#str_item _x_i1 in o + | MeTyc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#module_expr _x_i1 in + let o = o#module_type _x_i2 in o + | MeAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method module_binding : module_binding -> 'self_type = + function + | MbNil _x -> let o = o#loc _x in o + | MbAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#module_binding _x_i1 in + let o = o#module_binding _x_i2 in o + | MbColEq (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in + let o = o#module_expr _x_i3 in o + | MbCol (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in o + | MbAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method meta_option : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_option -> 'self_type = + fun _f_a -> + function + | ONone -> o + | OSome _x -> let o = _f_a o _x in o + | OAnt _x -> let o = o#string _x in o + + method meta_list : + 'a. + ('self_type -> 'a -> 'self_type) -> + 'a meta_list -> 'self_type = + fun _f_a -> + function + | LNil -> o + | LCons (_x, _x_i1) -> + let o = _f_a o _x in + let o = o#meta_list _f_a _x_i1 in o + | LAnt _x -> let o = o#string _x in o + + method meta_bool : meta_bool -> 'self_type = + function + | BTrue -> o + | BFalse -> o + | BAnt _x -> let o = o#string _x in o + + method match_case : match_case -> 'self_type = + function + | McNil _x -> let o = o#loc _x in o + | McOr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#match_case _x_i1 in + let o = o#match_case _x_i2 in o + | McArr (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#patt _x_i1 in + let o = o#expr _x_i2 in let o = o#expr _x_i3 in o + | McAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method loc : loc -> 'self_type = o#unknown + + method ident : ident -> 'self_type = + function + | IdAcc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | IdApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | IdLid (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | IdUid (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | IdAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method expr : expr -> 'self_type = + function + | ExNil _x -> let o = o#loc _x in o + | ExId (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | ExAcc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAre (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExArr (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | ExSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAsf _x -> let o = o#loc _x in o + | ExAsr (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | ExAss (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExChr (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExCoe (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#expr _x_i1 in + let o = o#ctyp _x_i2 in let o = o#ctyp _x_i3 in o + | ExFlo (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExFor (_x, _x_i1, _x_i2, _x_i3, _x_i4, _x_i5) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#expr _x_i2 in + let o = o#expr _x_i3 in + let o = o#meta_bool _x_i4 in let o = o#expr _x_i5 in o + | ExFun (_x, _x_i1) -> + let o = o#loc _x in let o = o#match_case _x_i1 in o + | ExIfe (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#expr _x_i1 in + let o = o#expr _x_i2 in let o = o#expr _x_i3 in o + | ExInt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExInt32 (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExInt64 (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExNativeInt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExLab (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | ExLaz (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | ExLet (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#binding _x_i2 in let o = o#expr _x_i3 in o + | ExLmd (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_expr _x_i2 in + let o = o#expr _x_i3 in o + | ExMat (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#match_case _x_i2 in o + | ExNew (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | ExObj (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in + let o = o#class_str_item _x_i2 in o + | ExOlb (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | ExOvr (_x, _x_i1) -> + let o = o#loc _x in let o = o#rec_binding _x_i1 in o + | ExRec (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#rec_binding _x_i1 in + let o = o#expr _x_i2 in o + | ExSeq (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | ExSnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#string _x_i2 in o + | ExSte (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExStr (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExTry (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#match_case _x_i2 in o + | ExTup (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | ExCom (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExTyc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#ctyp _x_i2 in o + | ExVrn (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExWhi (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + + method ctyp : ctyp -> 'self_type = + function + | TyNil _x -> let o = o#loc _x in o + | TyAli (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAny _x -> let o = o#loc _x in o + | TyApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyArr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyCls (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | TyLab (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | TyId (_x, _x_i1) -> + let o = o#loc _x in let o = o#ident _x_i1 in o + | TyMan (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyDcl (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#list (fun o -> o#ctyp) _x_i2 in + let o = o#ctyp _x_i3 in + let o = + o#list + (fun o (_x, _x_i1) -> + let o = o#ctyp _x in let o = o#ctyp _x_i1 in o) + _x_i4 + in o + | TyObj (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#meta_bool _x_i2 in o + | TyOlb (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | TyPol (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyQuo (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | TyQuP (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | TyQuM (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | TyVrn (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + | TyRec (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyCol (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TySem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyCom (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TySum (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyOf (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyOr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyPrv (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyMut (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyTup (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TySta (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyVrnEq (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnSup (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnInf (_x, _x_i1) -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnInfSup (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAmp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyOfAmp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method class_type : class_type -> 'self_type = + function + | CtNil _x -> let o = o#loc _x in o + | CtCon (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#ident _x_i2 in let o = o#ctyp _x_i3 in o + | CtFun (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#class_type _x_i2 in o + | CtSig (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in + let o = o#class_sig_item _x_i2 in o + | CtAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_type _x_i1 in + let o = o#class_type _x_i2 in o + | CtCol (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_type _x_i1 in + let o = o#class_type _x_i2 in o + | CtEq (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_type _x_i1 in + let o = o#class_type _x_i2 in o + | CtAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method class_str_item : class_str_item -> 'self_type = + function + | CrNil _x -> let o = o#loc _x in o + | CrSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_str_item _x_i1 in + let o = o#class_str_item _x_i2 in o + | CrCtr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | CrInh (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in + let o = o#string _x_i2 in o + | CrIni (_x, _x_i1) -> + let o = o#loc _x in let o = o#expr _x_i1 in o + | CrMth (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in + let o = o#expr _x_i3 in let o = o#ctyp _x_i4 in o + | CrVal (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#expr _x_i3 in o + | CrVir (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CrVvr (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CrAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method class_sig_item : class_sig_item -> 'self_type = + function + | CgNil _x -> let o = o#loc _x in o + | CgCtr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | CgSem (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_sig_item _x_i1 in + let o = o#class_sig_item _x_i2 in o + | CgInh (_x, _x_i1) -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | CgMth (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CgVal (_x, _x_i1, _x_i2, _x_i3, _x_i4) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in + let o = o#meta_bool _x_i3 in let o = o#ctyp _x_i4 in o + | CgVir (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CgAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method class_expr : class_expr -> 'self_type = + function + | CeNil _x -> let o = o#loc _x in o + | CeApp (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#expr _x_i2 in o + | CeCon (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#ident _x_i2 in let o = o#ctyp _x_i3 in o + | CeFun (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#class_expr _x_i2 in o + | CeLet (_x, _x_i1, _x_i2, _x_i3) -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#binding _x_i2 in + let o = o#class_expr _x_i3 in o + | CeStr (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in + let o = o#class_str_item _x_i2 in o + | CeTyc (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in + let o = o#class_type _x_i2 in o + | CeAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in + let o = o#class_expr _x_i2 in o + | CeEq (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in + let o = o#class_expr _x_i2 in o + | CeAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method binding : binding -> 'self_type = + function + | BiNil _x -> let o = o#loc _x in o + | BiAnd (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#binding _x_i1 in let o = o#binding _x_i2 in o + | BiEq (_x, _x_i1, _x_i2) -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#expr _x_i2 in o + | BiAnt (_x, _x_i1) -> + let o = o#loc _x in let o = o#string _x_i1 in o + + method unknown : 'a. 'a -> 'self_type = fun _ -> o + + end + + let map_expr f = + object + inherit map as super + + method expr = fun x -> f (super#expr x) + + end + + let map_patt f = + object + inherit map as super + + method patt = fun x -> f (super#patt x) + + end + + let map_ctyp f = + object + inherit map as super + + method ctyp = fun x -> f (super#ctyp x) + + end + + let map_str_item f = + object + inherit map as super + + method str_item = fun x -> f (super#str_item x) + + end + + let map_sig_item f = + object + inherit map as super + + method sig_item = fun x -> f (super#sig_item x) + + end + + let map_loc f = + object + inherit map as super + + method loc = fun x -> f (super#loc x) + + end + + end + + end + + module DynAst = + struct + module Make (Ast : Sig.Ast) : Sig.DynAst with module Ast = Ast = + struct + module Ast = Ast + + type 'a tag = + | Tag_ctyp + | Tag_patt + | Tag_expr + | Tag_module_type + | Tag_sig_item + | Tag_with_constr + | Tag_module_expr + | Tag_str_item + | Tag_class_type + | Tag_class_sig_item + | Tag_class_expr + | Tag_class_str_item + | Tag_match_case + | Tag_ident + | Tag_binding + | Tag_rec_binding + | Tag_module_binding + + let string_of_tag = + function + | Tag_ctyp -> "ctyp" + | Tag_patt -> "patt" + | Tag_expr -> "expr" + | Tag_module_type -> "module_type" + | Tag_sig_item -> "sig_item" + | Tag_with_constr -> "with_constr" + | Tag_module_expr -> "module_expr" + | Tag_str_item -> "str_item" + | Tag_class_type -> "class_type" + | Tag_class_sig_item -> "class_sig_item" + | Tag_class_expr -> "class_expr" + | Tag_class_str_item -> "class_str_item" + | Tag_match_case -> "match_case" + | Tag_ident -> "ident" + | Tag_binding -> "binding" + | Tag_rec_binding -> "rec_binding" + | Tag_module_binding -> "module_binding" + + let ctyp_tag = Tag_ctyp + + let patt_tag = Tag_patt + + let expr_tag = Tag_expr + + let module_type_tag = Tag_module_type + + let sig_item_tag = Tag_sig_item + + let with_constr_tag = Tag_with_constr + + let module_expr_tag = Tag_module_expr + + let str_item_tag = Tag_str_item + + let class_type_tag = Tag_class_type + + let class_sig_item_tag = Tag_class_sig_item + + let class_expr_tag = Tag_class_expr + + let class_str_item_tag = Tag_class_str_item + + let match_case_tag = Tag_match_case + + let ident_tag = Tag_ident + + let binding_tag = Tag_binding + + let rec_binding_tag = Tag_rec_binding + + let module_binding_tag = Tag_module_binding + + type dyn + + external dyn_tag : 'a tag -> dyn tag = "%identity" + + module Pack (X : sig type 'a t + end) = + struct + type pack = ((dyn tag) * Obj.t) + + exception Pack_error + + let pack tag v = ((dyn_tag tag), (Obj.repr v)) + + let unpack (tag : 'a tag) (tag', obj) = + if (dyn_tag tag) = tag' + then (Obj.obj obj : 'a X.t) + else raise Pack_error + + let print_tag f (tag, _) = + Format.pp_print_string f (string_of_tag tag) + + end + + end + + end + + module Quotation = + struct + module Make (Ast : Sig.Camlp4Ast) : + Sig.Quotation with module Ast = Ast = + struct + module Ast = Ast + + module DynAst = DynAst.Make(Ast) + + module Loc = Ast.Loc + + open Format + + open Sig + + type 'a expand_fun = Loc.t -> string option -> string -> 'a + + module Exp_key = DynAst.Pack(struct type 'a t = unit + end) + + module Exp_fun = + DynAst.Pack(struct type 'a t = 'a expand_fun + end) + + let expanders_table : + (((string * Exp_key.pack) * Exp_fun.pack) list) ref = ref [] + + let default = ref "" + + let translate = ref (fun x -> x) + + let expander_name name = + match !translate name with | "" -> !default | name -> name + + let find name tag = + let key = ((expander_name name), (Exp_key.pack tag ())) + in Exp_fun.unpack tag (List.assoc key !expanders_table) + + let add name tag f = + let elt = ((name, (Exp_key.pack tag ())), (Exp_fun.pack tag f)) + in expanders_table := elt :: !expanders_table + + let dump_file = ref None + + module Error = + struct + type error = + | Finding + | Expanding + | ParsingResult of Loc.t * string + | Locating + + type t = (string * string * error * exn) + + exception E of t + + let print ppf (name, position, ctx, exn) = + let name = if name = "" then !default else name in + let pp x = + fprintf ppf "@?@[<2>While %s %S in a position of %S:" x + name position in + let () = + match ctx with + | Finding -> + (pp "finding quotation"; + if !expanders_table = [] + then + fprintf ppf + "@ There is no quotation expander available." + else + (fprintf ppf + "@ @[Available quotation expanders are:@\n"; + List.iter + (fun ((s, t), _) -> + fprintf ppf + "@[<2>%s@ (in@ a@ position@ of %a)@]@ " s + Exp_key.print_tag t) + !expanders_table; + fprintf ppf "@]")) + | Expanding -> pp "expanding quotation" + | Locating -> pp "parsing" + | ParsingResult (loc, str) -> + let () = pp "parsing result of quotation" + in + (match !dump_file with + | Some dump_file -> + let () = fprintf ppf " dumping result...\n" + in + (try + let oc = open_out_bin dump_file + in + (output_string oc str; + output_string oc "\n"; + flush oc; + close_out oc; + fprintf ppf "%a:" Loc.print + (Loc.set_file_name dump_file loc)) + with + | _ -> + fprintf ppf + "Error while dumping result in file %S; dump aborted" + dump_file) + | None -> + fprintf ppf + "\n(consider setting variable Quotation.dump_file, or using the -QD option)") + in fprintf ppf "@\n%a@]@." ErrorHandler.print exn + + let to_string x = + let b = Buffer.create 50 in + let () = bprintf b "%a" print x in Buffer.contents b + + end + + let _ = let module M = ErrorHandler.Register(Error) in () + + open Error + + let expand_quotation loc expander pos_tag quot = + let loc_name_opt = + if quot.q_loc = "" then None else Some quot.q_loc + in + try expander loc loc_name_opt quot.q_contents + with | (Loc.Exc_located (_, (Error.E _)) as exc) -> raise exc + | Loc.Exc_located (iloc, exc) -> + let exc1 = + Error.E (((quot.q_name), pos_tag, Expanding, exc)) + in raise (Loc.Exc_located (iloc, exc1)) + | exc -> + let exc1 = + Error.E (((quot.q_name), pos_tag, Expanding, exc)) + in raise (Loc.Exc_located (loc, exc1)) + + let parse_quotation_result parse loc quot pos_tag str = + try parse loc str + with + | Loc.Exc_located (iloc, + (Error.E ((n, pos_tag, Expanding, exc)))) -> + let ctx = ParsingResult (iloc, quot.q_contents) in + let exc1 = Error.E ((n, pos_tag, ctx, exc)) + in raise (Loc.Exc_located (iloc, exc1)) + | Loc.Exc_located (iloc, ((Error.E _ as exc))) -> + raise (Loc.Exc_located (iloc, exc)) + | Loc.Exc_located (iloc, exc) -> + let ctx = ParsingResult (iloc, quot.q_contents) in + let exc1 = Error.E (((quot.q_name), pos_tag, ctx, exc)) + in raise (Loc.Exc_located (iloc, exc1)) + + let expand loc quotation tag = + let pos_tag = DynAst.string_of_tag tag in + let name = quotation.q_name in + let expander = + try find name tag + with | (Loc.Exc_located (_, (Error.E _)) as exc) -> raise exc + | Loc.Exc_located (qloc, exc) -> + raise + (Loc.Exc_located (qloc, + Error.E ((name, pos_tag, Finding, exc)))) + | exc -> + raise + (Loc.Exc_located (loc, + Error.E ((name, pos_tag, Finding, exc)))) in + let loc = Loc.join (Loc.move `start quotation.q_shift loc) + in expand_quotation loc expander pos_tag quotation + + end + + end + + module AstFilters = + struct + module Make (Ast : Sig.Camlp4Ast) : + Sig.AstFilters with module Ast = Ast = + struct + module Ast = Ast + + type 'a filter = 'a -> 'a + + let interf_filters = Queue.create () + + let fold_interf_filters f i = Queue.fold f i interf_filters + + let implem_filters = Queue.create () + + let fold_implem_filters f i = Queue.fold f i implem_filters + + let register_sig_item_filter f = Queue.add f interf_filters + + let register_str_item_filter f = Queue.add f implem_filters + + end + + end + + module Camlp4Ast2OCamlAst : + sig + module Make (Camlp4Ast : Sig.Camlp4Ast) : + sig + open Camlp4Ast + + val sig_item : sig_item -> Camlp4_import.Parsetree.signature + + val str_item : str_item -> Camlp4_import.Parsetree.structure + + val phrase : str_item -> Camlp4_import.Parsetree.toplevel_phrase + + end + + end = + struct + module Make (Ast : Sig.Camlp4Ast) = + struct + open Format + + open Camlp4_import.Parsetree + + open Camlp4_import.Longident + + open Camlp4_import.Asttypes + + open Ast + + let constructors_arity () = !Camlp4_config.constructors_arity + + let error loc str = Loc.raise loc (Failure str) + + let char_of_char_token loc s = + try Token.Eval.char s + with | (Failure _ as exn) -> Loc.raise loc exn + + let string_of_string_token loc s = + try Token.Eval.string s + with | (Failure _ as exn) -> Loc.raise loc exn + + let remove_underscores s = + let l = String.length s in + let rec remove src dst = + if src >= l + then if dst >= l then s else String.sub s 0 dst + else + (match s.[src] with + | '_' -> remove (src + 1) dst + | c -> (s.[dst] <- c; remove (src + 1) (dst + 1))) + in remove 0 0 + + let mkloc = Loc.to_ocaml_location + + let mkghloc loc = Loc.to_ocaml_location (Loc.ghostify loc) + + let mktyp loc d = { ptyp_desc = d; ptyp_loc = mkloc loc; } + + let mkpat loc d = { ppat_desc = d; ppat_loc = mkloc loc; } + + let mkghpat loc d = { ppat_desc = d; ppat_loc = mkghloc loc; } + + let mkexp loc d = { pexp_desc = d; pexp_loc = mkloc loc; } + + let mkmty loc d = { pmty_desc = d; pmty_loc = mkloc loc; } + + let mksig loc d = { psig_desc = d; psig_loc = mkloc loc; } + + let mkmod loc d = { pmod_desc = d; pmod_loc = mkloc loc; } + + let mkstr loc d = { pstr_desc = d; pstr_loc = mkloc loc; } + + let mkfield loc d = { pfield_desc = d; pfield_loc = mkloc loc; } + + let mkcty loc d = { pcty_desc = d; pcty_loc = mkloc loc; } + + let mkpcl loc d = { pcl_desc = d; pcl_loc = mkloc loc; } + + let mkpolytype t = + match t.ptyp_desc with + | Ptyp_poly (_, _) -> t + | _ -> { (t) with ptyp_desc = Ptyp_poly ([], t); } + + let mb2b = + function + | Ast.BTrue -> true + | Ast.BFalse -> false + | Ast.BAnt _ -> assert false + + let mkvirtual m = if mb2b m then Virtual else Concrete + + let lident s = Lident s + + let ldot l s = Ldot (l, s) + + let lapply l s = Lapply (l, s) + + let conv_con = + let t = Hashtbl.create 73 + in + (List.iter (fun (s, s') -> Hashtbl.add t s s') + [ ("True", "true"); ("False", "false"); (" True", "True"); + (" False", "False") ]; + fun s -> try Hashtbl.find t s with | Not_found -> s) + + let conv_lab = + let t = Hashtbl.create 73 + in + (List.iter (fun (s, s') -> Hashtbl.add t s s') + [ ("val", "contents") ]; + fun s -> try Hashtbl.find t s with | Not_found -> s) + + let array_function str name = + ldot (lident str) + (if !Camlp4_config.unsafe then "unsafe_" ^ name else name) + + let mkrf = + function + | Ast.BTrue -> Recursive + | Ast.BFalse -> Nonrecursive + | Ast.BAnt _ -> assert false + + let mkli s = + let rec loop f = + function | i :: il -> loop (ldot (f i)) il | [] -> f s + in loop lident + + let rec ctyp_fa al = + function + | TyApp (_, f, a) -> ctyp_fa (a :: al) f + | f -> (f, al) + + let ident_tag ?(conv_lid = fun x -> x) i = + let rec self i acc = + match i with + | Ast.IdAcc (_, i1, i2) -> self i2 (Some (self i1 acc)) + | Ast.IdApp (_, i1, i2) -> + let i' = + Lapply (fst (self i1 None), fst (self i2 None)) in + let x = + (match acc with + | None -> i' + | _ -> + error (loc_of_ident i) "invalid long identifier") + in (x, `app) + | Ast.IdUid (_, s) -> + let x = + (match acc with + | None -> lident s + | Some ((acc, (`uident | `app))) -> ldot acc s + | _ -> + error (loc_of_ident i) "invalid long identifier") + in (x, `uident) + | Ast.IdLid (_, s) -> + let x = + (match acc with + | None -> lident (conv_lid s) + | Some ((acc, (`uident | `app))) -> + ldot acc (conv_lid s) + | _ -> + error (loc_of_ident i) "invalid long identifier") + in (x, `lident) + | _ -> error (loc_of_ident i) "invalid long identifier" + in self i None + + let ident ?conv_lid i = fst (ident_tag ?conv_lid i) + + let long_lident msg i = + match ident_tag i with + | (i, `lident) -> i + | _ -> error (loc_of_ident i) msg + + let long_type_ident = long_lident "invalid long identifier type" + + let long_class_ident = long_lident "invalid class name" + + let long_uident ?(conv_con = fun x -> x) i = + match ident_tag i with + | (Ldot (i, s), `uident) -> ldot i (conv_con s) + | (Lident s, `uident) -> lident (conv_con s) + | (i, `app) -> i + | _ -> error (loc_of_ident i) "uppercase identifier expected" + + let rec ctyp_long_id_prefix t = + match t with + | Ast.TyId (_, i) -> ident i + | Ast.TyApp (_, m1, m2) -> + let li1 = ctyp_long_id_prefix m1 in + let li2 = ctyp_long_id_prefix m2 in Lapply (li1, li2) + | t -> error (loc_of_ctyp t) "invalid module expression" + + let ctyp_long_id t = + match t with + | Ast.TyId (_, i) -> (false, (long_type_ident i)) + | TyApp (loc, _, _) -> error loc "invalid type name" + | TyCls (_, i) -> (true, (ident i)) + | t -> error (loc_of_ctyp t) "invalid type" + + let rec ty_var_list_of_ctyp = + function + | Ast.TyApp (_, t1, t2) -> + (ty_var_list_of_ctyp t1) @ (ty_var_list_of_ctyp t2) + | Ast.TyQuo (_, s) -> [ s ] + | _ -> assert false + + let rec ctyp = + function + | TyId (loc, i) -> + let li = long_type_ident i + in mktyp loc (Ptyp_constr (li, [])) + | TyAli (loc, t1, t2) -> + let (t, i) = + (match (t1, t2) with + | (t, TyQuo (_, s)) -> (t, s) + | (TyQuo (_, s), t) -> (t, s) + | _ -> error loc "invalid alias type") + in mktyp loc (Ptyp_alias (ctyp t, i)) + | TyAny loc -> mktyp loc Ptyp_any + | (TyApp (loc, _, _) as f) -> + let (f, al) = ctyp_fa [] f in + let (is_cls, li) = ctyp_long_id f + in + if is_cls + then mktyp loc (Ptyp_class (li, List.map ctyp al, [])) + else mktyp loc (Ptyp_constr (li, List.map ctyp al)) + | TyArr (loc, (TyLab (_, lab, t1)), t2) -> + mktyp loc (Ptyp_arrow (lab, ctyp t1, ctyp t2)) + | TyArr (loc, (TyOlb (loc1, lab, t1)), t2) -> + let t1 = + TyApp (loc1, Ast.TyId (loc1, Ast.IdLid (loc1, "option")), + t1) + in mktyp loc (Ptyp_arrow ("?" ^ lab, ctyp t1, ctyp t2)) + | TyArr (loc, t1, t2) -> + mktyp loc (Ptyp_arrow ("", ctyp t1, ctyp t2)) + | Ast.TyObj (loc, fl, Ast.BFalse) -> + mktyp loc (Ptyp_object (meth_list fl [])) + | Ast.TyObj (loc, fl, Ast.BTrue) -> + mktyp loc + (Ptyp_object (meth_list fl [ mkfield loc Pfield_var ])) + | TyCls (loc, id) -> mktyp loc (Ptyp_class (ident id, [], [])) + | TyLab (loc, _, _) -> + error loc "labelled type not allowed here" + | TyMan (loc, _, _) -> + error loc "manifest type not allowed here" + | TyOlb (loc, _, _) -> + error loc "labelled type not allowed here" + | TyPol (loc, t1, t2) -> + mktyp loc (Ptyp_poly (ty_var_list_of_ctyp t1, ctyp t2)) + | TyQuo (loc, s) -> mktyp loc (Ptyp_var s) + | TyRec (loc, _) -> error loc "record type not allowed here" + | TySum (loc, _) -> error loc "sum type not allowed here" + | TyPrv (loc, _) -> error loc "private type not allowed here" + | TyMut (loc, _) -> error loc "mutable type not allowed here" + | TyOr (loc, _, _) -> + error loc "type1 | type2 not allowed here" + | TyAnd (loc, _, _) -> + error loc "type1 and type2 not allowed here" + | TyOf (loc, _, _) -> + error loc "type1 of type2 not allowed here" + | TyCol (loc, _, _) -> + error loc "type1 : type2 not allowed here" + | TySem (loc, _, _) -> + error loc "type1 ; type2 not allowed here" + | Ast.TyTup (loc, (Ast.TySta (_, t1, t2))) -> + mktyp loc + (Ptyp_tuple + (List.map ctyp (list_of_ctyp t1 (list_of_ctyp t2 [])))) + | Ast.TyVrnEq (loc, t) -> + mktyp loc (Ptyp_variant (row_field t, true, None)) + | Ast.TyVrnSup (loc, t) -> + mktyp loc (Ptyp_variant (row_field t, false, None)) + | Ast.TyVrnInf (loc, t) -> + mktyp loc (Ptyp_variant (row_field t, true, Some [])) + | Ast.TyVrnInfSup (loc, t, t') -> + mktyp loc + (Ptyp_variant (row_field t, true, Some (name_tags t'))) + | TyAnt (loc, _) -> error loc "antiquotation not allowed here" + | TyOfAmp (_, _, _) | TyAmp (_, _, _) | TySta (_, _, _) | + TyCom (_, _, _) | TyVrn (_, _) | TyQuM (_, _) | + TyQuP (_, _) | TyDcl (_, _, _, _, _) | + TyObj (_, _, (BAnt _)) | TyNil _ | TyTup (_, _) -> + assert false + and row_field = + function + | Ast.TyNil _ -> [] + | Ast.TyVrn (_, i) -> [ Rtag (i, true, []) ] + | Ast.TyOfAmp (_, (Ast.TyVrn (_, i)), t) -> + [ Rtag (i, true, List.map ctyp (list_of_ctyp t [])) ] + | Ast.TyOf (_, (Ast.TyVrn (_, i)), t) -> + [ Rtag (i, false, List.map ctyp (list_of_ctyp t [])) ] + | Ast.TyOr (_, t1, t2) -> (row_field t1) @ (row_field t2) + | t -> [ Rinherit (ctyp t) ] + and name_tags = + function + | Ast.TyApp (_, t1, t2) -> (name_tags t1) @ (name_tags t2) + | Ast.TyVrn (_, s) -> [ s ] + | _ -> assert false + and meth_list fl acc = + match fl with + | Ast.TyNil _ -> acc + | Ast.TySem (_, t1, t2) -> meth_list t1 (meth_list t2 acc) + | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (_, lab)))), t) -> + (mkfield loc (Pfield (lab, mkpolytype (ctyp t)))) :: acc + | _ -> assert false + + let mktype loc tl cl tk tp tm = + let (params, variance) = List.split tl + in + { + ptype_params = params; + ptype_cstrs = cl; + ptype_kind = tk; + ptype_private = tp; + ptype_manifest = tm; + ptype_loc = mkloc loc; + ptype_variance = variance; + } + + let mkprivate' m = if m then Private else Public + + let mkprivate m = mkprivate' (mb2b m) + + let mktrecord = + function + | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (_, s)))), + (Ast.TyMut (_, t))) -> + (s, Mutable, (mkpolytype (ctyp t)), (mkloc loc)) + | Ast.TyCol (loc, (Ast.TyId (_, (Ast.IdLid (_, s)))), t) -> + (s, Immutable, (mkpolytype (ctyp t)), (mkloc loc)) + | _ -> assert false + + let mkvariant = + function + | Ast.TyId (loc, (Ast.IdUid (_, s))) -> + ((conv_con s), [], (mkloc loc)) + | Ast.TyOf (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), t) -> + ((conv_con s), (List.map ctyp (list_of_ctyp t [])), + (mkloc loc)) + | _ -> assert false + + let rec type_decl tl cl loc m pflag = + function + | Ast.TyMan (_, t1, t2) -> + type_decl tl cl loc (Some (ctyp t1)) pflag t2 + | Ast.TyPrv (_, t) -> type_decl tl cl loc m true t + | Ast.TyRec (_, t) -> + mktype loc tl cl + (Ptype_record (List.map mktrecord (list_of_ctyp t []))) + (mkprivate' pflag) m + | Ast.TySum (_, t) -> + mktype loc tl cl + (Ptype_variant (List.map mkvariant (list_of_ctyp t []))) + (mkprivate' pflag) m + | t -> + if m <> None + then + error loc "only one manifest type allowed by definition" + else + (let m = + match t with + | Ast.TyNil _ -> None + | _ -> Some (ctyp t) + in mktype loc tl cl Ptype_abstract (mkprivate' pflag) m) + + let type_decl tl cl t = + type_decl tl cl (loc_of_ctyp t) None false t + + let mkvalue_desc t p = { pval_type = ctyp t; pval_prim = p; } + + let rec list_of_meta_list = + function + | Ast.LNil -> [] + | Ast.LCons (x, xs) -> x :: (list_of_meta_list xs) + | Ast.LAnt _ -> assert false + + let mkmutable m = if mb2b m then Mutable else Immutable + + let paolab lab p = + match (lab, p) with + | ("", + (Ast.PaId (_, (Ast.IdLid (_, i))) | + Ast.PaTyc (_, (Ast.PaId (_, (Ast.IdLid (_, i)))), _))) + -> i + | ("", p) -> error (loc_of_patt p) "bad ast in label" + | _ -> lab + + let opt_private_ctyp = + function + | Ast.TyPrv (_, t) -> (Ptype_abstract, Private, (ctyp t)) + | t -> (Ptype_abstract, Public, (ctyp t)) + + let rec type_parameters t acc = + match t with + | Ast.TyApp (_, t1, t2) -> + type_parameters t1 (type_parameters t2 acc) + | Ast.TyQuP (_, s) -> (s, (true, false)) :: acc + | Ast.TyQuM (_, s) -> (s, (false, true)) :: acc + | Ast.TyQuo (_, s) -> (s, (false, false)) :: acc + | _ -> assert false + + let rec class_parameters t acc = + match t with + | Ast.TyCom (_, t1, t2) -> + class_parameters t1 (class_parameters t2 acc) + | Ast.TyQuP (_, s) -> (s, (true, false)) :: acc + | Ast.TyQuM (_, s) -> (s, (false, true)) :: acc + | Ast.TyQuo (_, s) -> (s, (false, false)) :: acc + | _ -> assert false + + let rec type_parameters_and_type_name t acc = + match t with + | Ast.TyApp (_, t1, t2) -> + type_parameters_and_type_name t1 (type_parameters t2 acc) + | Ast.TyId (_, i) -> ((ident i), acc) + | _ -> assert false + + let rec mkwithc wc acc = + match wc with + | WcNil _ -> acc + | WcTyp (loc, id_tpl, ct) -> + let (id, tpl) = type_parameters_and_type_name id_tpl [] in + let (params, variance) = List.split tpl in + let (kind, priv, ct) = opt_private_ctyp ct + in + (id, + (Pwith_type + { + ptype_params = params; + ptype_cstrs = []; + ptype_kind = kind; + ptype_private = priv; + ptype_manifest = Some ct; + ptype_loc = mkloc loc; + ptype_variance = variance; + })) :: + acc + | WcMod (_, i1, i2) -> + ((long_uident i1), (Pwith_module (long_uident i2))) :: acc + | Ast.WcAnd (_, wc1, wc2) -> mkwithc wc1 (mkwithc wc2 acc) + | Ast.WcAnt (loc, _) -> + error loc "bad with constraint (antiquotation)" + + let rec patt_fa al = + function + | PaApp (_, f, a) -> patt_fa (a :: al) f + | f -> (f, al) + + let rec deep_mkrangepat loc c1 c2 = + if c1 = c2 + then mkghpat loc (Ppat_constant (Const_char c1)) + else + mkghpat loc + (Ppat_or (mkghpat loc (Ppat_constant (Const_char c1)), + deep_mkrangepat loc (Char.chr ((Char.code c1) + 1)) c2)) + + let rec mkrangepat loc c1 c2 = + if c1 > c2 + then mkrangepat loc c2 c1 + else + if c1 = c2 + then mkpat loc (Ppat_constant (Const_char c1)) + else + mkpat loc + (Ppat_or (mkghpat loc (Ppat_constant (Const_char c1)), + deep_mkrangepat loc (Char.chr ((Char.code c1) + 1)) c2)) + + let rec patt = + function + | Ast.PaId (loc, (Ast.IdLid (_, s))) -> mkpat loc (Ppat_var s) + | Ast.PaId (loc, i) -> + let p = + Ppat_construct (long_uident ~conv_con i, None, + constructors_arity ()) + in mkpat loc p + | PaAli (loc, p1, p2) -> + let (p, i) = + (match (p1, p2) with + | (p, Ast.PaId (_, (Ast.IdLid (_, s)))) -> (p, s) + | (Ast.PaId (_, (Ast.IdLid (_, s))), p) -> (p, s) + | _ -> error loc "invalid alias pattern") + in mkpat loc (Ppat_alias (patt p, i)) + | PaAnt (loc, _) -> error loc "antiquotation not allowed here" + | PaAny loc -> mkpat loc Ppat_any + | Ast.PaApp (loc, (Ast.PaId (_, (Ast.IdUid (_, s)))), + (Ast.PaTup (_, (Ast.PaAny loc_any)))) -> + mkpat loc + (Ppat_construct (lident (conv_con s), + Some (mkpat loc_any Ppat_any), false)) + | (PaApp (loc, _, _) as f) -> + let (f, al) = patt_fa [] f in + let al = List.map patt al + in + (match (patt f).ppat_desc with + | Ppat_construct (li, None, _) -> + if constructors_arity () + then + mkpat loc + (Ppat_construct (li, + Some (mkpat loc (Ppat_tuple al)), true)) + else + (let a = + match al with + | [ a ] -> a + | _ -> mkpat loc (Ppat_tuple al) + in mkpat loc (Ppat_construct (li, Some a, false))) + | Ppat_variant (s, None) -> + let a = + if constructors_arity () + then mkpat loc (Ppat_tuple al) + else + (match al with + | [ a ] -> a + | _ -> mkpat loc (Ppat_tuple al)) + in mkpat loc (Ppat_variant (s, Some a)) + | _ -> + error (loc_of_patt f) + "this is not a constructor, it cannot be applied in a pattern") + | PaArr (loc, p) -> + mkpat loc (Ppat_array (List.map patt (list_of_patt p []))) + | PaChr (loc, s) -> + mkpat loc + (Ppat_constant (Const_char (char_of_char_token loc s))) + | PaInt (loc, s) -> + let i = + (try int_of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int") + in mkpat loc (Ppat_constant (Const_int i)) + | PaInt32 (loc, s) -> + let i32 = + (try Int32.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int32") + in mkpat loc (Ppat_constant (Const_int32 i32)) + | PaInt64 (loc, s) -> + let i64 = + (try Int64.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int64") + in mkpat loc (Ppat_constant (Const_int64 i64)) + | PaNativeInt (loc, s) -> + let nati = + (try Nativeint.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type nativeint") + in mkpat loc (Ppat_constant (Const_nativeint nati)) + | PaFlo (loc, s) -> + mkpat loc + (Ppat_constant (Const_float (remove_underscores s))) + | PaLab (loc, _, _) -> + error loc "labeled pattern not allowed here" + | PaOlb (loc, _, _) | PaOlbi (loc, _, _, _) -> + error loc "labeled pattern not allowed here" + | PaOrp (loc, p1, p2) -> mkpat loc (Ppat_or (patt p1, patt p2)) + | PaRng (loc, p1, p2) -> + (match (p1, p2) with + | (PaChr (loc1, c1), PaChr (loc2, c2)) -> + let c1 = char_of_char_token loc1 c1 in + let c2 = char_of_char_token loc2 c2 + in mkrangepat loc c1 c2 + | _ -> + error loc "range pattern allowed only for characters") + | PaRec (loc, p) -> + mkpat loc + (Ppat_record (List.map mklabpat (list_of_patt p []))) + | PaStr (loc, s) -> + mkpat loc + (Ppat_constant + (Const_string (string_of_string_token loc s))) + | Ast.PaTup (loc, (Ast.PaCom (_, p1, p2))) -> + mkpat loc + (Ppat_tuple + (List.map patt (list_of_patt p1 (list_of_patt p2 [])))) + | Ast.PaTup (loc, _) -> error loc "singleton tuple pattern" + | PaTyc (loc, p, t) -> + mkpat loc (Ppat_constraint (patt p, ctyp t)) + | PaTyp (loc, i) -> mkpat loc (Ppat_type (long_type_ident i)) + | PaVrn (loc, s) -> mkpat loc (Ppat_variant (s, None)) + | PaLaz (loc, p) -> mkpat loc (Ppat_lazy (patt p)) + | (PaEq (_, _, _) | PaSem (_, _, _) | PaCom (_, _, _) | PaNil _ + as p) -> error (loc_of_patt p) "invalid pattern" + and mklabpat = + function + | Ast.PaEq (_, i, p) -> + ((ident ~conv_lid: conv_lab i), (patt p)) + | p -> error (loc_of_patt p) "invalid pattern" + + let rec expr_fa al = + function + | ExApp (_, f, a) -> expr_fa (a :: al) f + | f -> (f, al) + + let rec class_expr_fa al = + function + | CeApp (_, ce, a) -> class_expr_fa (a :: al) ce + | ce -> (ce, al) + + let rec sep_expr_acc l = + function + | ExAcc (_, e1, e2) -> sep_expr_acc (sep_expr_acc l e2) e1 + | (Ast.ExId (loc, (Ast.IdUid (_, s))) as e) -> + (match l with + | [] -> [ (loc, [], e) ] + | (loc', sl, e) :: l -> + ((Loc.merge loc loc'), (s :: sl), e) :: l) + | Ast.ExId (_, ((Ast.IdAcc (_, _, _) as i))) -> + let rec normalize_acc = + (function + | Ast.IdAcc (_loc, i1, i2) -> + Ast.ExAcc (_loc, normalize_acc i1, normalize_acc i2) + | Ast.IdApp (_loc, i1, i2) -> + Ast.ExApp (_loc, normalize_acc i1, normalize_acc i2) + | (Ast.IdAnt (_loc, _) | Ast.IdUid (_loc, _) | + Ast.IdLid (_loc, _) + as i) -> Ast.ExId (_loc, i)) + in sep_expr_acc l (normalize_acc i) + | e -> ((loc_of_expr e), [], e) :: l + + let list_of_opt_ctyp ot acc = + match ot with | Ast.TyNil _ -> acc | t -> list_of_ctyp t acc + + let rec expr = + function + | Ast.ExAcc (loc, x, (Ast.ExId (_, (Ast.IdLid (_, "val"))))) -> + mkexp loc + (Pexp_apply (mkexp loc (Pexp_ident (Lident "!")), + [ ("", (expr x)) ])) + | (ExAcc (loc, _, _) | Ast.ExId (loc, (Ast.IdAcc (_, _, _))) as + e) -> + let (e, l) = + (match sep_expr_acc [] e with + | (loc, ml, Ast.ExId (_, (Ast.IdUid (_, s)))) :: l -> + let ca = constructors_arity () + in + ((mkexp loc + (Pexp_construct (mkli (conv_con s) ml, None, + ca))), + l) + | (loc, ml, Ast.ExId (_, (Ast.IdLid (_, s)))) :: l -> + ((mkexp loc (Pexp_ident (mkli s ml))), l) + | (_, [], e) :: l -> ((expr e), l) + | _ -> error loc "bad ast in expression") in + let (_, e) = + List.fold_left + (fun (loc_bp, e1) (loc_ep, ml, e2) -> + match e2 with + | Ast.ExId (_, (Ast.IdLid (_, s))) -> + let loc = Loc.merge loc_bp loc_ep + in + (loc, + (mkexp loc + (Pexp_field (e1, mkli (conv_lab s) ml)))) + | _ -> + error (loc_of_expr e2) + "lowercase identifier expected") + (loc, e) l + in e + | ExAnt (loc, _) -> error loc "antiquotation not allowed here" + | (ExApp (loc, _, _) as f) -> + let (f, al) = expr_fa [] f in + let al = List.map label_expr al + in + (match (expr f).pexp_desc with + | Pexp_construct (li, None, _) -> + let al = List.map snd al + in + if constructors_arity () + then + mkexp loc + (Pexp_construct (li, + Some (mkexp loc (Pexp_tuple al)), true)) + else + (let a = + match al with + | [ a ] -> a + | _ -> mkexp loc (Pexp_tuple al) + in + mkexp loc + (Pexp_construct (li, Some a, false))) + | Pexp_variant (s, None) -> + let al = List.map snd al in + let a = + if constructors_arity () + then mkexp loc (Pexp_tuple al) + else + (match al with + | [ a ] -> a + | _ -> mkexp loc (Pexp_tuple al)) + in mkexp loc (Pexp_variant (s, Some a)) + | _ -> mkexp loc (Pexp_apply (expr f, al))) + | ExAre (loc, e1, e2) -> + mkexp loc + (Pexp_apply + (mkexp loc (Pexp_ident (array_function "Array" "get")), + [ ("", (expr e1)); ("", (expr e2)) ])) + | ExArr (loc, e) -> + mkexp loc (Pexp_array (List.map expr (list_of_expr e []))) + | ExAsf loc -> mkexp loc Pexp_assertfalse + | ExAss (loc, e, v) -> + let e = + (match e with + | Ast.ExAcc (loc, x, + (Ast.ExId (_, (Ast.IdLid (_, "val"))))) -> + Pexp_apply (mkexp loc (Pexp_ident (Lident ":=")), + [ ("", (expr x)); ("", (expr v)) ]) + | ExAcc (loc, _, _) -> + (match (expr e).pexp_desc with + | Pexp_field (e, lab) -> + Pexp_setfield (e, lab, expr v) + | _ -> error loc "bad record access") + | ExAre (_, e1, e2) -> + Pexp_apply + (mkexp loc + (Pexp_ident (array_function "Array" "set")), + [ ("", (expr e1)); ("", (expr e2)); ("", (expr v)) ]) + | Ast.ExId (_, (Ast.IdLid (_, lab))) -> + Pexp_setinstvar (lab, expr v) + | ExSte (_, e1, e2) -> + Pexp_apply + (mkexp loc + (Pexp_ident (array_function "String" "set")), + [ ("", (expr e1)); ("", (expr e2)); ("", (expr v)) ]) + | _ -> error loc "bad left part of assignment") + in mkexp loc e + | ExAsr (loc, e) -> mkexp loc (Pexp_assert (expr e)) + | ExChr (loc, s) -> + mkexp loc + (Pexp_constant (Const_char (char_of_char_token loc s))) + | ExCoe (loc, e, t1, t2) -> + let t1 = + (match t1 with | Ast.TyNil _ -> None | t -> Some (ctyp t)) + in mkexp loc (Pexp_constraint (expr e, t1, Some (ctyp t2))) + | ExFlo (loc, s) -> + mkexp loc + (Pexp_constant (Const_float (remove_underscores s))) + | ExFor (loc, i, e1, e2, df, el) -> + let e3 = ExSeq (loc, el) in + let df = if mb2b df then Upto else Downto + in mkexp loc (Pexp_for (i, expr e1, expr e2, df, expr e3)) + | Ast.ExFun (loc, (Ast.McArr (_, (PaLab (_, lab, po)), w, e))) + -> + mkexp loc + (Pexp_function (lab, None, + [ ((patt_of_lab loc lab po), (when_expr e w)) ])) + | Ast.ExFun (loc, + (Ast.McArr (_, (PaOlbi (_, lab, p, e1)), w, e2))) -> + let lab = paolab lab p + in + mkexp loc + (Pexp_function ("?" ^ lab, Some (expr e1), + [ ((patt p), (when_expr e2 w)) ])) + | Ast.ExFun (loc, (Ast.McArr (_, (PaOlb (_, lab, p)), w, e))) + -> + let lab = paolab lab p + in + mkexp loc + (Pexp_function ("?" ^ lab, None, + [ ((patt_of_lab loc lab p), (when_expr e w)) ])) + | ExFun (loc, a) -> + mkexp loc (Pexp_function ("", None, match_case a [])) + | ExIfe (loc, e1, e2, e3) -> + mkexp loc + (Pexp_ifthenelse (expr e1, expr e2, Some (expr e3))) + | ExInt (loc, s) -> + let i = + (try int_of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int") + in mkexp loc (Pexp_constant (Const_int i)) + | ExInt32 (loc, s) -> + let i32 = + (try Int32.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int32") + in mkexp loc (Pexp_constant (Const_int32 i32)) + | ExInt64 (loc, s) -> + let i64 = + (try Int64.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type int64") + in mkexp loc (Pexp_constant (Const_int64 i64)) + | ExNativeInt (loc, s) -> + let nati = + (try Nativeint.of_string s + with + | Failure _ -> + error loc + "Integer literal exceeds the range of representable integers of type nativeint") + in mkexp loc (Pexp_constant (Const_nativeint nati)) + | ExLab (loc, _, _) -> + error loc "labeled expression not allowed here" + | ExLaz (loc, e) -> mkexp loc (Pexp_lazy (expr e)) + | ExLet (loc, rf, bi, e) -> + mkexp loc (Pexp_let (mkrf rf, binding bi [], expr e)) + | ExLmd (loc, i, me, e) -> + mkexp loc (Pexp_letmodule (i, module_expr me, expr e)) + | ExMat (loc, e, a) -> + mkexp loc (Pexp_match (expr e, match_case a [])) + | ExNew (loc, id) -> mkexp loc (Pexp_new (long_type_ident id)) + | ExObj (loc, po, cfl) -> + let p = + (match po with | Ast.PaNil _ -> Ast.PaAny loc | p -> p) in + let cil = class_str_item cfl [] + in mkexp loc (Pexp_object (((patt p), cil))) + | ExOlb (loc, _, _) -> + error loc "labeled expression not allowed here" + | ExOvr (loc, iel) -> + mkexp loc (Pexp_override (mkideexp iel [])) + | ExRec (loc, lel, eo) -> + (match lel with + | Ast.RbNil _ -> error loc "empty record" + | _ -> + let eo = + (match eo with + | Ast.ExNil _ -> None + | e -> Some (expr e)) + in mkexp loc (Pexp_record (mklabexp lel [], eo))) + | ExSeq (_loc, e) -> + let rec loop = + (function + | [] -> expr (Ast.ExId (_loc, Ast.IdUid (_loc, "()"))) + | [ e ] -> expr e + | e :: el -> + let _loc = Loc.merge (loc_of_expr e) _loc + in mkexp _loc (Pexp_sequence (expr e, loop el))) + in loop (list_of_expr e []) + | ExSnd (loc, e, s) -> mkexp loc (Pexp_send (expr e, s)) + | ExSte (loc, e1, e2) -> + mkexp loc + (Pexp_apply + (mkexp loc + (Pexp_ident (array_function "String" "get")), + [ ("", (expr e1)); ("", (expr e2)) ])) + | ExStr (loc, s) -> + mkexp loc + (Pexp_constant + (Const_string (string_of_string_token loc s))) + | ExTry (loc, e, a) -> + mkexp loc (Pexp_try (expr e, match_case a [])) + | Ast.ExTup (loc, (Ast.ExCom (_, e1, e2))) -> + mkexp loc + (Pexp_tuple + (List.map expr (list_of_expr e1 (list_of_expr e2 [])))) + | Ast.ExTup (loc, _) -> error loc "singleton tuple" + | ExTyc (loc, e, t) -> + mkexp loc (Pexp_constraint (expr e, Some (ctyp t), None)) + | Ast.ExId (loc, (Ast.IdUid (_, "()"))) -> + mkexp loc (Pexp_construct (lident "()", None, true)) + | Ast.ExId (loc, (Ast.IdLid (_, s))) -> + mkexp loc (Pexp_ident (lident s)) + | Ast.ExId (loc, (Ast.IdUid (_, s))) -> + mkexp loc + (Pexp_construct (lident (conv_con s), None, true)) + | ExVrn (loc, s) -> mkexp loc (Pexp_variant (s, None)) + | ExWhi (loc, e1, el) -> + let e2 = ExSeq (loc, el) + in mkexp loc (Pexp_while (expr e1, expr e2)) + | Ast.ExCom (loc, _, _) -> + error loc "expr, expr: not allowed here" + | Ast.ExSem (loc, _, _) -> + error loc + "expr; expr: not allowed here, use do {...} or [|...|] to surround them" + | (ExId (_, _) | ExNil _ as e) -> + error (loc_of_expr e) "invalid expr" + and patt_of_lab _loc lab = + function + | Ast.PaNil _ -> patt (Ast.PaId (_loc, Ast.IdLid (_loc, lab))) + | p -> patt p + and expr_of_lab _loc lab = + function + | Ast.ExNil _ -> expr (Ast.ExId (_loc, Ast.IdLid (_loc, lab))) + | e -> expr e + and label_expr = + function + | ExLab (loc, lab, eo) -> (lab, (expr_of_lab loc lab eo)) + | ExOlb (loc, lab, eo) -> + (("?" ^ lab), (expr_of_lab loc lab eo)) + | e -> ("", (expr e)) + and binding x acc = + match x with + | Ast.BiAnd (_, x, y) -> binding x (binding y acc) + | Ast.BiEq (_, p, e) -> ((patt p), (expr e)) :: acc + | Ast.BiNil _ -> acc + | _ -> assert false + and match_case x acc = + match x with + | Ast.McOr (_, x, y) -> match_case x (match_case y acc) + | Ast.McArr (_, p, w, e) -> ((patt p), (when_expr e w)) :: acc + | Ast.McNil _ -> acc + | _ -> assert false + and when_expr e w = + match w with + | Ast.ExNil _ -> expr e + | w -> mkexp (loc_of_expr w) (Pexp_when (expr w, expr e)) + and mklabexp x acc = + match x with + | Ast.RbSem (_, x, y) -> mklabexp x (mklabexp y acc) + | Ast.RbEq (_, i, e) -> + ((ident ~conv_lid: conv_lab i), (expr e)) :: acc + | _ -> assert false + and mkideexp x acc = + match x with + | Ast.RbNil _ -> acc + | Ast.RbSem (_, x, y) -> mkideexp x (mkideexp y acc) + | Ast.RbEq (_, (Ast.IdLid (_, s)), e) -> (s, (expr e)) :: acc + | _ -> assert false + and mktype_decl x acc = + match x with + | Ast.TyAnd (_, x, y) -> mktype_decl x (mktype_decl y acc) + | Ast.TyDcl (_, c, tl, td, cl) -> + let cl = + List.map + (fun (t1, t2) -> + let loc = + Loc.merge (loc_of_ctyp t1) (loc_of_ctyp t2) + in ((ctyp t1), (ctyp t2), (mkloc loc))) + cl + in + (c, + (type_decl (List.fold_right type_parameters tl []) cl td)) :: + acc + | _ -> assert false + and module_type = + function + | Ast.MtNil loc -> + error loc "abstract/nil module type not allowed here" + | Ast.MtId (loc, i) -> mkmty loc (Pmty_ident (long_uident i)) + | Ast.MtFun (loc, n, nt, mt) -> + mkmty loc + (Pmty_functor (n, module_type nt, module_type mt)) + | Ast.MtQuo (loc, _) -> + error loc "module type variable not allowed here" + | Ast.MtSig (loc, sl) -> + mkmty loc (Pmty_signature (sig_item sl [])) + | Ast.MtWit (loc, mt, wc) -> + mkmty loc (Pmty_with (module_type mt, mkwithc wc [])) + | Ast.MtAnt (_, _) -> assert false + and sig_item s l = + match s with + | Ast.SgNil _ -> l + | SgCls (loc, cd) -> + (mksig loc + (Psig_class + (List.map class_info_class_type + (list_of_class_type cd [])))) :: + l + | SgClt (loc, ctd) -> + (mksig loc + (Psig_class_type + (List.map class_info_class_type + (list_of_class_type ctd [])))) :: + l + | Ast.SgSem (_, sg1, sg2) -> sig_item sg1 (sig_item sg2 l) + | SgDir (_, _, _) -> l + | Ast.SgExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s))))) -> + (mksig loc (Psig_exception (conv_con s, []))) :: l + | Ast.SgExc (loc, + (Ast.TyOf (_, (Ast.TyId (_, (Ast.IdUid (_, s)))), t))) -> + (mksig loc + (Psig_exception (conv_con s, + List.map ctyp (list_of_ctyp t [])))) :: + l + | SgExc (_, _) -> assert false + | SgExt (loc, n, t, sl) -> + (mksig loc + (Psig_value (n, mkvalue_desc t (list_of_meta_list sl)))) :: + l + | SgInc (loc, mt) -> + (mksig loc (Psig_include (module_type mt))) :: l + | SgMod (loc, n, mt) -> + (mksig loc (Psig_module (n, module_type mt))) :: l + | SgRecMod (loc, mb) -> + (mksig loc (Psig_recmodule (module_sig_binding mb []))) :: + l + | SgMty (loc, n, mt) -> + let si = + (match mt with + | MtQuo (_, _) -> Pmodtype_abstract + | _ -> Pmodtype_manifest (module_type mt)) + in (mksig loc (Psig_modtype (n, si))) :: l + | SgOpn (loc, id) -> + (mksig loc (Psig_open (long_uident id))) :: l + | SgTyp (loc, tdl) -> + (mksig loc (Psig_type (mktype_decl tdl []))) :: l + | SgVal (loc, n, t) -> + (mksig loc (Psig_value (n, mkvalue_desc t []))) :: l + | Ast.SgAnt (loc, _) -> error loc "antiquotation in sig_item" + and module_sig_binding x acc = + match x with + | Ast.MbAnd (_, x, y) -> + module_sig_binding x (module_sig_binding y acc) + | Ast.MbCol (_, s, mt) -> (s, (module_type mt)) :: acc + | _ -> assert false + and module_str_binding x acc = + match x with + | Ast.MbAnd (_, x, y) -> + module_str_binding x (module_str_binding y acc) + | Ast.MbColEq (_, s, mt, me) -> + (s, (module_type mt), (module_expr me)) :: acc + | _ -> assert false + and module_expr = + function + | Ast.MeNil loc -> error loc "nil module expression" + | Ast.MeId (loc, i) -> mkmod loc (Pmod_ident (long_uident i)) + | Ast.MeApp (loc, me1, me2) -> + mkmod loc (Pmod_apply (module_expr me1, module_expr me2)) + | Ast.MeFun (loc, n, mt, me) -> + mkmod loc + (Pmod_functor (n, module_type mt, module_expr me)) + | Ast.MeStr (loc, sl) -> + mkmod loc (Pmod_structure (str_item sl [])) + | Ast.MeTyc (loc, me, mt) -> + mkmod loc + (Pmod_constraint (module_expr me, module_type mt)) + | Ast.MeAnt (loc, _) -> + error loc "antiquotation in module_expr" + and str_item s l = + match s with + | Ast.StNil _ -> l + | StCls (loc, cd) -> + (mkstr loc + (Pstr_class + (List.map class_info_class_expr + (list_of_class_expr cd [])))) :: + l + | StClt (loc, ctd) -> + (mkstr loc + (Pstr_class_type + (List.map class_info_class_type + (list_of_class_type ctd [])))) :: + l + | Ast.StSem (_, st1, st2) -> str_item st1 (str_item st2 l) + | StDir (_, _, _) -> l + | Ast.StExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), Ast. + ONone) -> + (mkstr loc (Pstr_exception (conv_con s, []))) :: l + | Ast.StExc (loc, + (Ast.TyOf (_, (Ast.TyId (_, (Ast.IdUid (_, s)))), t)), Ast. + ONone) -> + (mkstr loc + (Pstr_exception (conv_con s, + List.map ctyp (list_of_ctyp t [])))) :: + l + | Ast.StExc (loc, (Ast.TyId (_, (Ast.IdUid (_, s)))), + (Ast.OSome i)) -> + (mkstr loc (Pstr_exn_rebind (conv_con s, ident i))) :: l + | StExc (_, _, _) -> assert false + | StExp (loc, e) -> (mkstr loc (Pstr_eval (expr e))) :: l + | StExt (loc, n, t, sl) -> + (mkstr loc + (Pstr_primitive (n, + mkvalue_desc t (list_of_meta_list sl)))) :: + l + | StInc (loc, me) -> + (mkstr loc (Pstr_include (module_expr me))) :: l + | StMod (loc, n, me) -> + (mkstr loc (Pstr_module (n, module_expr me))) :: l + | StRecMod (loc, mb) -> + (mkstr loc (Pstr_recmodule (module_str_binding mb []))) :: + l + | StMty (loc, n, mt) -> + (mkstr loc (Pstr_modtype (n, module_type mt))) :: l + | StOpn (loc, id) -> + (mkstr loc (Pstr_open (long_uident id))) :: l + | StTyp (loc, tdl) -> + (mkstr loc (Pstr_type (mktype_decl tdl []))) :: l + | StVal (loc, rf, bi) -> + (mkstr loc (Pstr_value (mkrf rf, binding bi []))) :: l + | Ast.StAnt (loc, _) -> error loc "antiquotation in str_item" + and class_type = + function + | CtCon (loc, Ast.BFalse, id, tl) -> + mkcty loc + (Pcty_constr (long_class_ident id, + List.map ctyp (list_of_opt_ctyp tl []))) + | CtFun (loc, (TyLab (_, lab, t)), ct) -> + mkcty loc (Pcty_fun (lab, ctyp t, class_type ct)) + | CtFun (loc, (TyOlb (loc1, lab, t)), ct) -> + let t = + TyApp (loc1, Ast.TyId (loc1, Ast.IdLid (loc1, "option")), + t) + in mkcty loc (Pcty_fun ("?" ^ lab, ctyp t, class_type ct)) + | CtFun (loc, t, ct) -> + mkcty loc (Pcty_fun ("", ctyp t, class_type ct)) + | CtSig (loc, t_o, ctfl) -> + let t = + (match t_o with | Ast.TyNil _ -> Ast.TyAny loc | t -> t) in + let cil = class_sig_item ctfl [] + in mkcty loc (Pcty_signature (((ctyp t), cil))) + | CtCon (loc, _, _, _) -> + error loc "invalid virtual class inside a class type" + | CtAnt (_, _) | CtEq (_, _, _) | CtCol (_, _, _) | + CtAnd (_, _, _) | CtNil _ -> assert false + and class_info_class_expr ci = + match ci with + | CeEq (_, (CeCon (loc, vir, (IdLid (_, name)), params)), ce) + -> + let (loc_params, (params, variance)) = + (match params with + | Ast.TyNil _ -> (loc, ([], [])) + | t -> + ((loc_of_ctyp t), + (List.split (class_parameters t [])))) + in + { + pci_virt = if mb2b vir then Virtual else Concrete; + pci_params = (params, (mkloc loc_params)); + pci_name = name; + pci_expr = class_expr ce; + pci_loc = mkloc loc; + pci_variance = variance; + } + | ce -> error (loc_of_class_expr ce) "bad class definition" + and class_info_class_type ci = + match ci with + | CtEq (_, (CtCon (loc, vir, (IdLid (_, name)), params)), ct) | + CtCol (_, (CtCon (loc, vir, (IdLid (_, name)), params)), + ct) + -> + let (loc_params, (params, variance)) = + (match params with + | Ast.TyNil _ -> (loc, ([], [])) + | t -> + ((loc_of_ctyp t), + (List.split (class_parameters t [])))) + in + { + pci_virt = if mb2b vir then Virtual else Concrete; + pci_params = (params, (mkloc loc_params)); + pci_name = name; + pci_expr = class_type ct; + pci_loc = mkloc loc; + pci_variance = variance; + } + | ct -> + error (loc_of_class_type ct) + "bad class/class type declaration/definition" + and class_sig_item c l = + match c with + | Ast.CgNil _ -> l + | CgCtr (loc, t1, t2) -> + (Pctf_cstr (((ctyp t1), (ctyp t2), (mkloc loc)))) :: l + | Ast.CgSem (_, csg1, csg2) -> + class_sig_item csg1 (class_sig_item csg2 l) + | CgInh (_, ct) -> (Pctf_inher (class_type ct)) :: l + | CgMth (loc, s, pf, t) -> + (Pctf_meth + ((s, (mkprivate pf), (mkpolytype (ctyp t)), (mkloc loc)))) :: + l + | CgVal (loc, s, b, v, t) -> + (Pctf_val + ((s, (mkmutable b), (mkvirtual v), (ctyp t), + (mkloc loc)))) :: + l + | CgVir (loc, s, b, t) -> + (Pctf_virt + ((s, (mkprivate b), (mkpolytype (ctyp t)), (mkloc loc)))) :: + l + | CgAnt (_, _) -> assert false + and class_expr = + function + | (CeApp (loc, _, _) as c) -> + let (ce, el) = class_expr_fa [] c in + let el = List.map label_expr el + in mkpcl loc (Pcl_apply (class_expr ce, el)) + | CeCon (loc, Ast.BFalse, id, tl) -> + mkpcl loc + (Pcl_constr (long_class_ident id, + List.map ctyp (list_of_opt_ctyp tl []))) + | CeFun (loc, (PaLab (_, lab, po)), ce) -> + mkpcl loc + (Pcl_fun (lab, None, patt_of_lab loc lab po, + class_expr ce)) + | CeFun (loc, (PaOlbi (_, lab, p, e)), ce) -> + let lab = paolab lab p + in + mkpcl loc + (Pcl_fun ("?" ^ lab, Some (expr e), patt p, + class_expr ce)) + | CeFun (loc, (PaOlb (_, lab, p)), ce) -> + let lab = paolab lab p + in + mkpcl loc + (Pcl_fun ("?" ^ lab, None, patt_of_lab loc lab p, + class_expr ce)) + | CeFun (loc, p, ce) -> + mkpcl loc (Pcl_fun ("", None, patt p, class_expr ce)) + | CeLet (loc, rf, bi, ce) -> + mkpcl loc (Pcl_let (mkrf rf, binding bi [], class_expr ce)) + | CeStr (loc, po, cfl) -> + let p = + (match po with | Ast.PaNil _ -> Ast.PaAny loc | p -> p) in + let cil = class_str_item cfl [] + in mkpcl loc (Pcl_structure (((patt p), cil))) + | CeTyc (loc, ce, ct) -> + mkpcl loc (Pcl_constraint (class_expr ce, class_type ct)) + | CeCon (loc, _, _, _) -> + error loc "invalid virtual class inside a class expression" + | CeAnt (_, _) | CeEq (_, _, _) | CeAnd (_, _, _) | CeNil _ -> + assert false + and class_str_item c l = + match c with + | CrNil _ -> l + | CrCtr (loc, t1, t2) -> + (Pcf_cstr (((ctyp t1), (ctyp t2), (mkloc loc)))) :: l + | Ast.CrSem (_, cst1, cst2) -> + class_str_item cst1 (class_str_item cst2 l) + | CrInh (_, ce, "") -> (Pcf_inher (class_expr ce, None)) :: l + | CrInh (_, ce, pb) -> + (Pcf_inher (class_expr ce, Some pb)) :: l + | CrIni (_, e) -> (Pcf_init (expr e)) :: l + | CrMth (loc, s, b, e, t) -> + let t = + (match t with + | Ast.TyNil _ -> None + | t -> Some (mkpolytype (ctyp t))) in + let e = mkexp loc (Pexp_poly (expr e, t)) + in (Pcf_meth ((s, (mkprivate b), e, (mkloc loc)))) :: l + | CrVal (loc, s, b, e) -> + (Pcf_val ((s, (mkmutable b), (expr e), (mkloc loc)))) :: l + | CrVir (loc, s, b, t) -> + (Pcf_virt + ((s, (mkprivate b), (mkpolytype (ctyp t)), (mkloc loc)))) :: + l + | CrVvr (loc, s, b, t) -> + (Pcf_valvirt ((s, (mkmutable b), (ctyp t), (mkloc loc)))) :: + l + | CrAnt (_, _) -> assert false + + let sig_item ast = sig_item ast [] + + let str_item ast = str_item ast [] + + let directive = + function + | Ast.ExNil _ -> Pdir_none + | ExStr (_, s) -> Pdir_string s + | ExInt (_, i) -> Pdir_int (int_of_string i) + | Ast.ExId (_, (Ast.IdUid (_, "True"))) -> Pdir_bool true + | Ast.ExId (_, (Ast.IdUid (_, "False"))) -> Pdir_bool false + | e -> Pdir_ident (ident (ident_of_expr e)) + + let phrase = + function + | StDir (_, d, dp) -> Ptop_dir (d, directive dp) + | si -> Ptop_def (str_item si) + + end + + end + + module CleanAst = + struct + module Make (Ast : Sig.Camlp4Ast) = + struct + class clean_ast = + object inherit Ast.map as super + + method with_constr = + fun wc -> + match super#with_constr wc with + | Ast.WcAnd (_, (Ast.WcNil _), wc) | + Ast.WcAnd (_, wc, (Ast.WcNil _)) -> wc + | wc -> wc + + method expr = + fun e -> + match super#expr e with + | Ast.ExLet (_, _, (Ast.BiNil _), e) | + Ast.ExRec (_, (Ast.RbNil _), e) | + Ast.ExCom (_, (Ast.ExNil _), e) | + Ast.ExCom (_, e, (Ast.ExNil _)) | + Ast.ExSem (_, (Ast.ExNil _), e) | + Ast.ExSem (_, e, (Ast.ExNil _)) -> e + | e -> e + + method patt = + fun p -> + match super#patt p with + | Ast.PaAli (_, p, (Ast.PaNil _)) | + Ast.PaOrp (_, (Ast.PaNil _), p) | + Ast.PaOrp (_, p, (Ast.PaNil _)) | + Ast.PaCom (_, (Ast.PaNil _), p) | + Ast.PaCom (_, p, (Ast.PaNil _)) | + Ast.PaSem (_, (Ast.PaNil _), p) | + Ast.PaSem (_, p, (Ast.PaNil _)) -> p + | p -> p + + method match_case = + fun mc -> + match super#match_case mc with + | Ast.McOr (_, (Ast.McNil _), mc) | + Ast.McOr (_, mc, (Ast.McNil _)) -> mc + | mc -> mc + + method binding = + fun bi -> + match super#binding bi with + | Ast.BiAnd (_, (Ast.BiNil _), bi) | + Ast.BiAnd (_, bi, (Ast.BiNil _)) -> bi + | bi -> bi + + method rec_binding = + fun rb -> + match super#rec_binding rb with + | Ast.RbSem (_, (Ast.RbNil _), bi) | + Ast.RbSem (_, bi, (Ast.RbNil _)) -> bi + | bi -> bi + + method module_binding = + fun mb -> + match super#module_binding mb with + | Ast.MbAnd (_, (Ast.MbNil _), mb) | + Ast.MbAnd (_, mb, (Ast.MbNil _)) -> mb + | mb -> mb + + method ctyp = + fun t -> + match super#ctyp t with + | Ast.TyPol (_, (Ast.TyNil _), t) | + Ast.TyAli (_, (Ast.TyNil _), t) | + Ast.TyAli (_, t, (Ast.TyNil _)) | + Ast.TyArr (_, t, (Ast.TyNil _)) | + Ast.TyArr (_, (Ast.TyNil _), t) | + Ast.TyOr (_, (Ast.TyNil _), t) | + Ast.TyOr (_, t, (Ast.TyNil _)) | + Ast.TyOf (_, t, (Ast.TyNil _)) | + Ast.TyAnd (_, (Ast.TyNil _), t) | + Ast.TyAnd (_, t, (Ast.TyNil _)) | + Ast.TySem (_, t, (Ast.TyNil _)) | + Ast.TySem (_, (Ast.TyNil _), t) | + Ast.TyCom (_, (Ast.TyNil _), t) | + Ast.TyCom (_, t, (Ast.TyNil _)) | + Ast.TyAmp (_, t, (Ast.TyNil _)) | + Ast.TyAmp (_, (Ast.TyNil _), t) | + Ast.TySta (_, (Ast.TyNil _), t) | + Ast.TySta (_, t, (Ast.TyNil _)) -> t + | t -> t + + method sig_item = + fun sg -> + match super#sig_item sg with + | Ast.SgSem (_, (Ast.SgNil _), sg) | + Ast.SgSem (_, sg, (Ast.SgNil _)) -> sg + | Ast.SgTyp (loc, (Ast.TyNil _)) -> Ast.SgNil loc + | sg -> sg + + method str_item = + fun st -> + match super#str_item st with + | Ast.StSem (_, (Ast.StNil _), st) | + Ast.StSem (_, st, (Ast.StNil _)) -> st + | Ast.StTyp (loc, (Ast.TyNil _)) -> Ast.StNil loc + | Ast.StVal (loc, _, (Ast.BiNil _)) -> Ast.StNil loc + | st -> st + + method module_type = + fun mt -> + match super#module_type mt with + | Ast.MtWit (_, mt, (Ast.WcNil _)) -> mt + | mt -> mt + + method class_expr = + fun ce -> + match super#class_expr ce with + | Ast.CeAnd (_, (Ast.CeNil _), ce) | + Ast.CeAnd (_, ce, (Ast.CeNil _)) -> ce + | ce -> ce + + method class_type = + fun ct -> + match super#class_type ct with + | Ast.CtAnd (_, (Ast.CtNil _), ct) | + Ast.CtAnd (_, ct, (Ast.CtNil _)) -> ct + | ct -> ct + + method class_sig_item = + fun csg -> + match super#class_sig_item csg with + | Ast.CgSem (_, (Ast.CgNil _), csg) | + Ast.CgSem (_, csg, (Ast.CgNil _)) -> csg + | csg -> csg + + method class_str_item = + fun cst -> + match super#class_str_item cst with + | Ast.CrSem (_, (Ast.CrNil _), cst) | + Ast.CrSem (_, cst, (Ast.CrNil _)) -> cst + | cst -> cst + + end + + end + + end + + module CommentFilter : + sig + module Make (Token : Sig.Camlp4Token) : + sig + open Token + + type t + + val mk : unit -> t + + val define : Token.Filter.t -> t -> unit + + val filter : + t -> (Token.t * Loc.t) Stream.t -> (Token.t * Loc.t) Stream.t + + val take_list : t -> (string * Loc.t) list + + val take_stream : t -> (string * Loc.t) Stream.t + + end + + end = + struct + module Make (Token : Sig.Camlp4Token) = + struct + open Token + + type t = + (((string * Loc.t) Stream.t) * ((string * Loc.t) Queue.t)) + + let mk () = + let q = Queue.create () in + let f _ = try Some (Queue.take q) with | Queue.Empty -> None + in ((Stream.from f), q) + + let filter (_, q) = + let rec self (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some ((Sig.COMMENT x, loc)) -> + (Stream.junk __strm; + let xs = __strm in (Queue.add (x, loc) q; self xs)) + | Some x -> + (Stream.junk __strm; + let xs = __strm + in Stream.icons x (Stream.slazy (fun _ -> self xs))) + | _ -> Stream.sempty + in self + + let take_list (_, q) = + let rec self accu = + if Queue.is_empty q + then accu + else self ((Queue.take q) :: accu) + in self [] + + let take_stream = fst + + let define token_fiter comments_strm = + Token.Filter.define_filter token_fiter + (fun previous strm -> previous (filter comments_strm strm)) + + end + + end + + module DynLoader : sig include Sig.DynLoader + end = + struct + type t = string Queue.t + + exception Error of string * string + + let include_dir x y = Queue.add y x + + let fold_load_path x f acc = Queue.fold (fun x y -> f y x) acc x + + let mk ?(ocaml_stdlib = true) ?(camlp4_stdlib = true) () = + let q = Queue.create () + in + (if ocaml_stdlib + then include_dir q Camlp4_config.ocaml_standard_library + else (); + if camlp4_stdlib + then + (include_dir q Camlp4_config.camlp4_standard_library; + include_dir q + (Filename.concat Camlp4_config.camlp4_standard_library + "Camlp4Parsers"); + include_dir q + (Filename.concat Camlp4_config.camlp4_standard_library + "Camlp4Printers"); + include_dir q + (Filename.concat Camlp4_config.camlp4_standard_library + "Camlp4Filters")) + else (); + include_dir q "."; + q) + + let find_in_path x name = + if not (Filename.is_implicit name) + then if Sys.file_exists name then name else raise Not_found + else + (let res = + fold_load_path x + (fun dir -> + function + | None -> + let fullname = Filename.concat dir name + in + if Sys.file_exists fullname + then Some fullname + else None + | x -> x) + None + in match res with | None -> raise Not_found | Some x -> x) + + let load = + let _initialized = ref false + in + fun _path file -> + (if not !_initialized + then + (try + (Dynlink.init (); + Dynlink.allow_unsafe_modules true; + _initialized := true) + with + | Dynlink.Error e -> + raise + (Error ("Camlp4's dynamic loader initialization", + Dynlink.error_message e))) + else (); + let fname = + try find_in_path _path file + with + | Not_found -> + raise (Error (file, "file not found in path")) + in + try Dynlink.loadfile fname + with + | Dynlink.Error e -> + raise (Error (fname, Dynlink.error_message e))) + + let is_native = Dynlink.is_native + + end + + module EmptyError : sig include Sig.Error + end = + struct + type t = unit + + exception E of t + + let print _ = assert false + + let to_string _ = assert false + + end + + module EmptyPrinter : + sig module Make (Ast : Sig.Ast) : Sig.Printer(Ast).S + end = + struct + module Make (Ast : Sig.Ast) = + struct + let print_interf ?input_file:(_) ?output_file:(_) _ = + failwith "No interface printer" + + let print_implem ?input_file:(_) ?output_file:(_) _ = + failwith "No implementation printer" + + end + + end + + module FreeVars : + sig + module Make (Ast : Sig.Camlp4Ast) : + sig + module S : Set.S with type elt = string + + val fold_binding_vars : + (string -> 'accu -> 'accu) -> Ast.binding -> 'accu -> 'accu + + class ['accu] c_fold_pattern_vars : + (string -> 'accu -> 'accu) -> + 'accu -> + object inherit Ast.fold + val acc : 'accu + method acc : 'accu + + end + + val fold_pattern_vars : + (string -> 'accu -> 'accu) -> Ast.patt -> 'accu -> 'accu + + class ['accu] fold_free_vars : + (string -> 'accu -> 'accu) -> + ?env_init: S.t -> + 'accu -> + object ('self_type) + inherit Ast.fold + + val free : 'accu + + val env : S.t + + method free : 'accu + + method set_env : S.t -> 'self_type + + method add_atom : string -> 'self_type + + method add_patt : Ast.patt -> 'self_type + + method add_binding : Ast.binding -> 'self_type + + end + + val free_vars : S.t -> Ast.expr -> S.t + + end + + end = + struct + module Make (Ast : Sig.Camlp4Ast) = + struct + module S = Set.Make(String) + + class ['accu] c_fold_pattern_vars f init = + object inherit Ast.fold as super + + val acc = init + + method acc : 'accu = acc + + method patt = + function + | Ast.PaId (_, (Ast.IdLid (_, s))) | + Ast.PaLab (_, s, (Ast.PaNil _)) | + Ast.PaOlb (_, s, (Ast.PaNil _)) -> {< acc = f s acc; >} + | p -> super#patt p + + end + + let fold_pattern_vars f p init = + ((new c_fold_pattern_vars f init)#patt p)#acc + + let rec fold_binding_vars f bi acc = + match bi with + | Ast.BiAnd (_, bi1, bi2) -> + fold_binding_vars f bi1 (fold_binding_vars f bi2 acc) + | Ast.BiEq (_, p, _) -> fold_pattern_vars f p acc + | Ast.BiNil _ -> acc + | Ast.BiAnt (_, _) -> assert false + + class ['accu] fold_free_vars (f : string -> 'accu -> 'accu) + ?(env_init = S.empty) free_init = + object (o) + inherit Ast.fold as super + + val free = (free_init : 'accu) + + val env = (env_init : S.t) + + method free = free + + method set_env = fun env -> {< env = env; >} + + method add_atom = fun s -> {< env = S.add s env; >} + + method add_patt = + fun p -> {< env = fold_pattern_vars S.add p env; >} + + method add_binding = + fun bi -> {< env = fold_binding_vars S.add bi env; >} + + method expr = + function + | Ast.ExId (_, (Ast.IdLid (_, s))) | + Ast.ExLab (_, s, (Ast.ExNil _)) | + Ast.ExOlb (_, s, (Ast.ExNil _)) -> + if S.mem s env then o else {< free = f s free; >} + | Ast.ExLet (_, Ast.BFalse, bi, e) -> + (((o#add_binding bi)#expr e)#set_env env)#binding bi + | Ast.ExLet (_, Ast.BTrue, bi, e) -> + (((o#add_binding bi)#expr e)#binding bi)#set_env env + | Ast.ExFor (_, s, e1, e2, _, e3) -> + ((((o#expr e1)#expr e2)#add_atom s)#expr e3)#set_env + env + | Ast.ExId (_, _) | Ast.ExNew (_, _) -> o + | Ast.ExObj (_, p, cst) -> + ((o#add_patt p)#class_str_item cst)#set_env env + | e -> super#expr e + + method match_case = + function + | Ast.McArr (_, p, e1, e2) -> + (((o#add_patt p)#expr e1)#expr e2)#set_env env + | m -> super#match_case m + + method str_item = + function + | Ast.StExt (_, s, t, _) -> (o#ctyp t)#add_atom s + | Ast.StVal (_, Ast.BFalse, bi) -> + (o#binding bi)#add_binding bi + | Ast.StVal (_, Ast.BTrue, bi) -> + (o#add_binding bi)#binding bi + | st -> super#str_item st + + method class_expr = + function + | Ast.CeFun (_, p, ce) -> + ((o#add_patt p)#class_expr ce)#set_env env + | Ast.CeLet (_, Ast.BFalse, bi, ce) -> + (((o#binding bi)#add_binding bi)#class_expr ce)#set_env + env + | Ast.CeLet (_, Ast.BTrue, bi, ce) -> + (((o#add_binding bi)#binding bi)#class_expr ce)#set_env + env + | Ast.CeStr (_, p, cst) -> + ((o#add_patt p)#class_str_item cst)#set_env env + | ce -> super#class_expr ce + + method class_str_item = + function + | (Ast.CrInh (_, _, "") as cst) -> super#class_str_item cst + | Ast.CrInh (_, ce, s) -> (o#class_expr ce)#add_atom s + | Ast.CrVal (_, s, _, e) -> (o#expr e)#add_atom s + | Ast.CrVvr (_, s, _, t) -> (o#ctyp t)#add_atom s + | cst -> super#class_str_item cst + + method module_expr = + function + | Ast.MeStr (_, st) -> (o#str_item st)#set_env env + | me -> super#module_expr me + + end + + let free_vars env_init e = + let fold = new fold_free_vars S.add ~env_init S.empty + in (fold#expr e)#free + + end + + end + + module Grammar = + struct + module Context = + struct + module type S = + sig + module Token : Sig.Token + + open Token + + type t + + val call_with_ctx : + (Token.t * Loc.t) Stream.t -> (t -> 'a) -> 'a + + val loc_bp : t -> Loc.t + + val loc_ep : t -> Loc.t + + val stream : t -> (Token.t * Loc.t) Stream.t + + val peek_nth : t -> int -> (Token.t * Loc.t) option + + val njunk : t -> int -> unit + + val junk : (Token.t * Loc.t) Stream.t -> unit + + val bp : (Token.t * Loc.t) Stream.t -> Loc.t + + end + + module Make (Token : Sig.Token) : S with module Token = Token = + struct + module Token = Token + + open Token + + type t = + { mutable strm : (Token.t * Loc.t) Stream.t; + mutable loc : Loc.t + } + + let loc_bp c = + match Stream.peek c.strm with + | None -> Loc.ghost + | Some ((_, loc)) -> loc + + let loc_ep c = c.loc + + let set_loc c = + match Stream.peek c.strm with + | Some ((_, loc)) -> c.loc <- loc + | None -> () + + let mk strm = + match Stream.peek strm with + | Some ((_, loc)) -> { strm = strm; loc = loc; } + | None -> { strm = strm; loc = Loc.ghost; } + + let stream c = c.strm + + let peek_nth c n = + let list = Stream.npeek n c.strm in + let rec loop list n = + match (list, n) with + | ((((_, loc) as x)) :: _, 1) -> (c.loc <- loc; Some x) + | (_ :: l, n) -> loop l (n - 1) + | ([], _) -> None + in loop list n + + let njunk c n = + (for i = 1 to n do Stream.junk c.strm done; set_loc c) + + let streams = ref [] + + let mk strm = + let c = mk strm in + let () = streams := (strm, c) :: !streams in c + + let junk strm = + (set_loc (List.assq strm !streams); Stream.junk strm) + + let bp strm = loc_bp (List.assq strm !streams) + + let call_with_ctx strm f = + let streams_v = !streams in + let r = + try f (mk strm) + with | exc -> (streams := streams_v; raise exc) + in (streams := streams_v; r) + + end + + end + + module Structure = + struct + open Sig.Grammar + + module type S = + sig + module Loc : Sig.Loc + + module Token : Sig.Token with module Loc = Loc + + module Lexer : Sig.Lexer with module Loc = Loc + and module Token = Token + + module Context : Context.S with module Token = Token + + module Action : Sig.Grammar.Action + + type gram = + { gfilter : Token.Filter.t; + gkeywords : (string, int ref) Hashtbl.t; + glexer : + Loc.t -> char Stream.t -> (Token.t * Loc.t) Stream.t; + warning_verbose : bool ref; error_verbose : bool ref + } + + type efun = + Context.t -> (Token.t * Loc.t) Stream.t -> Action.t + + type token_pattern = ((Token.t -> bool) * string) + + type internal_entry = + { egram : gram; ename : string; + mutable estart : int -> efun; + mutable econtinue : int -> Loc.t -> Action.t -> efun; + mutable edesc : desc + } + and desc = + | Dlevels of level list + | Dparser of ((Token.t * Loc.t) Stream.t -> Action.t) + and level = + { assoc : assoc; lname : string option; lsuffix : tree; + lprefix : tree + } + and symbol = + | Smeta of string * symbol list * Action.t + | Snterm of internal_entry + | Snterml of internal_entry * string + | Slist0 of symbol + | Slist0sep of symbol * symbol + | Slist1 of symbol + | Slist1sep of symbol * symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree + and tree = + | Node of node + | LocAct of Action.t * Action.t list + | DeadEnd + and node = + { node : symbol; son : tree; brother : tree + } + + type production_rule = ((symbol list) * Action.t) + + type single_extend_statment = + ((string option) * (assoc option) * (production_rule list)) + + type extend_statment = + ((position option) * (single_extend_statment list)) + + type delete_statment = symbol list + + type ('a, 'b, 'c) fold = + internal_entry -> + symbol list -> ('a Stream.t -> 'b) -> 'a Stream.t -> 'c + + type ('a, 'b, 'c) foldsep = + internal_entry -> + symbol list -> + ('a Stream.t -> 'b) -> + ('a Stream.t -> unit) -> 'a Stream.t -> 'c + + val get_filter : gram -> Token.Filter.t + + val using : gram -> string -> unit + + val removing : gram -> string -> unit + + end + + module Make (Lexer : Sig.Lexer) = + struct + module Loc = Lexer.Loc + + module Token = Lexer.Token + + module Action : Sig.Grammar.Action = + struct + type t = Obj.t + + let mk = Obj.repr + + let get = Obj.obj + + let getf = Obj.obj + + let getf2 = Obj.obj + + end + + module Lexer = Lexer + + type gram = + { gfilter : Token.Filter.t; + gkeywords : (string, int ref) Hashtbl.t; + glexer : + Loc.t -> char Stream.t -> (Token.t * Loc.t) Stream.t; + warning_verbose : bool ref; error_verbose : bool ref + } + + module Context = Context.Make(Token) + + type efun = + Context.t -> (Token.t * Loc.t) Stream.t -> Action.t + + type token_pattern = ((Token.t -> bool) * string) + + type internal_entry = + { egram : gram; ename : string; + mutable estart : int -> efun; + mutable econtinue : int -> Loc.t -> Action.t -> efun; + mutable edesc : desc + } + and desc = + | Dlevels of level list + | Dparser of ((Token.t * Loc.t) Stream.t -> Action.t) + and level = + { assoc : assoc; lname : string option; lsuffix : tree; + lprefix : tree + } + and symbol = + | Smeta of string * symbol list * Action.t + | Snterm of internal_entry + | Snterml of internal_entry * string + | Slist0 of symbol + | Slist0sep of symbol * symbol + | Slist1 of symbol + | Slist1sep of symbol * symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of token_pattern + | Skeyword of string + | Stree of tree + and tree = + | Node of node + | LocAct of Action.t * Action.t list + | DeadEnd + and node = + { node : symbol; son : tree; brother : tree + } + + type production_rule = ((symbol list) * Action.t) + + type single_extend_statment = + ((string option) * (assoc option) * (production_rule list)) + + type extend_statment = + ((position option) * (single_extend_statment list)) + + type delete_statment = symbol list + + type ('a, 'b, 'c) fold = + internal_entry -> + symbol list -> ('a Stream.t -> 'b) -> 'a Stream.t -> 'c + + type ('a, 'b, 'c) foldsep = + internal_entry -> + symbol list -> + ('a Stream.t -> 'b) -> + ('a Stream.t -> unit) -> 'a Stream.t -> 'c + + let get_filter g = g.gfilter + + type 'a not_filtered = 'a + + let using { gkeywords = table; gfilter = filter } kwd = + let r = + try Hashtbl.find table kwd + with + | Not_found -> + let r = ref 0 in (Hashtbl.add table kwd r; r) + in (Token.Filter.keyword_added filter kwd (!r = 0); incr r) + + let removing { gkeywords = table; gfilter = filter } kwd = + let r = Hashtbl.find table kwd in + let () = decr r + in + if !r = 0 + then + (Token.Filter.keyword_removed filter kwd; + Hashtbl.remove table kwd) + else () + + end + + end + + module Search = + struct + module Make (Structure : Structure.S) = + struct + open Structure + + let tree_in_entry prev_symb tree = + function + | Dlevels levels -> + let rec search_levels = + (function + | [] -> tree + | level :: levels -> + (match search_level level with + | Some tree -> tree + | None -> search_levels levels)) + and search_level level = + (match search_tree level.lsuffix with + | Some t -> + Some + (Node + { node = Sself; son = t; brother = DeadEnd; + }) + | None -> search_tree level.lprefix) + and search_tree t = + if (tree <> DeadEnd) && (t == tree) + then Some t + else + (match t with + | Node n -> + (match search_symbol n.node with + | Some symb -> + Some + (Node + { + node = symb; + son = n.son; + brother = DeadEnd; + }) + | None -> + (match search_tree n.son with + | Some t -> + Some + (Node + { + node = n.node; + son = t; + brother = DeadEnd; + }) + | None -> search_tree n.brother)) + | LocAct (_, _) | DeadEnd -> None) + and search_symbol symb = + (match symb with + | Snterm _ | Snterml (_, _) | Slist0 _ | + Slist0sep (_, _) | Slist1 _ | Slist1sep (_, _) | + Sopt _ | Stoken _ | Stree _ | Skeyword _ when + symb == prev_symb -> Some symb + | Slist0 symb -> + (match search_symbol symb with + | Some symb -> Some (Slist0 symb) + | None -> None) + | Slist0sep (symb, sep) -> + (match search_symbol symb with + | Some symb -> Some (Slist0sep (symb, sep)) + | None -> + (match search_symbol sep with + | Some sep -> Some (Slist0sep (symb, sep)) + | None -> None)) + | Slist1 symb -> + (match search_symbol symb with + | Some symb -> Some (Slist1 symb) + | None -> None) + | Slist1sep (symb, sep) -> + (match search_symbol symb with + | Some symb -> Some (Slist1sep (symb, sep)) + | None -> + (match search_symbol sep with + | Some sep -> Some (Slist1sep (symb, sep)) + | None -> None)) + | Sopt symb -> + (match search_symbol symb with + | Some symb -> Some (Sopt symb) + | None -> None) + | Stree t -> + (match search_tree t with + | Some t -> Some (Stree t) + | None -> None) + | _ -> None) + in search_levels levels + | Dparser _ -> tree + + end + + end + + module Tools = + struct + module Make (Structure : Structure.S) = + struct + open Structure + + let empty_entry ename _ _ _ = + raise (Stream.Error ("entry [" ^ (ename ^ "] is empty"))) + + let is_level_labelled n lev = + match lev.lname with | Some n1 -> n = n1 | None -> false + + let warning_verbose = ref true + + let rec get_token_list entry tokl last_tok tree = + match tree with + | Node + { + node = (Stoken _ | Skeyword _ as tok); + son = son; + brother = DeadEnd + } -> get_token_list entry (last_tok :: tokl) tok son + | _ -> + if tokl = [] + then None + else + Some + (((List.rev (last_tok :: tokl)), last_tok, tree)) + + let is_antiquot s = + let len = String.length s in (len > 1) && (s.[0] = '$') + + let eq_Stoken_ids s1 s2 = + (not (is_antiquot s1)) && + ((not (is_antiquot s2)) && (s1 = s2)) + + let logically_eq_symbols entry = + let rec eq_symbols s1 s2 = + match (s1, s2) with + | (Snterm e1, Snterm e2) -> e1.ename = e2.ename + | (Snterm e1, Sself) -> e1.ename = entry.ename + | (Sself, Snterm e2) -> entry.ename = e2.ename + | (Snterml (e1, l1), Snterml (e2, l2)) -> + (e1.ename = e2.ename) && (l1 = l2) + | (Slist0 s1, Slist0 s2) -> eq_symbols s1 s2 + | (Slist0sep (s1, sep1), Slist0sep (s2, sep2)) -> + (eq_symbols s1 s2) && (eq_symbols sep1 sep2) + | (Slist1 s1, Slist1 s2) -> eq_symbols s1 s2 + | (Slist1sep (s1, sep1), Slist1sep (s2, sep2)) -> + (eq_symbols s1 s2) && (eq_symbols sep1 sep2) + | (Sopt s1, Sopt s2) -> eq_symbols s1 s2 + | (Stree t1, Stree t2) -> eq_trees t1 t2 + | (Stoken ((_, s1)), Stoken ((_, s2))) -> + eq_Stoken_ids s1 s2 + | _ -> s1 = s2 + and eq_trees t1 t2 = + match (t1, t2) with + | (Node n1, Node n2) -> + (eq_symbols n1.node n2.node) && + ((eq_trees n1.son n2.son) && + (eq_trees n1.brother n2.brother)) + | ((LocAct (_, _) | DeadEnd), (LocAct (_, _) | DeadEnd)) + -> true + | _ -> false + in eq_symbols + + let rec eq_symbol s1 s2 = + match (s1, s2) with + | (Snterm e1, Snterm e2) -> e1 == e2 + | (Snterml (e1, l1), Snterml (e2, l2)) -> + (e1 == e2) && (l1 = l2) + | (Slist0 s1, Slist0 s2) -> eq_symbol s1 s2 + | (Slist0sep (s1, sep1), Slist0sep (s2, sep2)) -> + (eq_symbol s1 s2) && (eq_symbol sep1 sep2) + | (Slist1 s1, Slist1 s2) -> eq_symbol s1 s2 + | (Slist1sep (s1, sep1), Slist1sep (s2, sep2)) -> + (eq_symbol s1 s2) && (eq_symbol sep1 sep2) + | (Sopt s1, Sopt s2) -> eq_symbol s1 s2 + | (Stree _, Stree _) -> false + | (Stoken ((_, s1)), Stoken ((_, s2))) -> + eq_Stoken_ids s1 s2 + | _ -> s1 = s2 + + end + + end + + module Print : + sig + module Make (Structure : Structure.S) : + sig + val flatten_tree : + Structure.tree -> (Structure.symbol list) list + + val print_symbol : + Format.formatter -> Structure.symbol -> unit + + val print_meta : + Format.formatter -> string -> Structure.symbol list -> unit + + val print_symbol1 : + Format.formatter -> Structure.symbol -> unit + + val print_rule : + Format.formatter -> Structure.symbol list -> unit + + val print_level : + Format.formatter -> + (Format.formatter -> unit -> unit) -> + (Structure.symbol list) list -> unit + + val levels : Format.formatter -> Structure.level list -> unit + + val entry : + Format.formatter -> Structure.internal_entry -> unit + + end + + module MakeDump (Structure : Structure.S) : + sig + val print_symbol : + Format.formatter -> Structure.symbol -> unit + + val print_meta : + Format.formatter -> string -> Structure.symbol list -> unit + + val print_symbol1 : + Format.formatter -> Structure.symbol -> unit + + val print_rule : + Format.formatter -> Structure.symbol list -> unit + + val print_level : + Format.formatter -> + (Format.formatter -> unit -> unit) -> + (Structure.symbol list) list -> unit + + val levels : Format.formatter -> Structure.level list -> unit + + val entry : + Format.formatter -> Structure.internal_entry -> unit + + end + + end = + struct + module Make (Structure : Structure.S) = + struct + open Structure + + open Format + + open Sig.Grammar + + let rec flatten_tree = + function + | DeadEnd -> [] + | LocAct (_, _) -> [ [] ] + | Node { node = n; brother = b; son = s } -> + (List.map (fun l -> n :: l) (flatten_tree s)) @ + (flatten_tree b) + + let rec print_symbol ppf = + function + | Smeta (n, sl, _) -> print_meta ppf n sl + | Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s + | Slist0sep (s, t) -> + fprintf ppf "LIST0 %a SEP %a" print_symbol1 s + print_symbol1 t + | Slist1 s -> fprintf ppf "LIST1 %a" print_symbol1 s + | Slist1sep (s, t) -> + fprintf ppf "LIST1 %a SEP %a" print_symbol1 s + print_symbol1 t + | Sopt s -> fprintf ppf "OPT %a" print_symbol1 s + | Snterml (e, l) -> fprintf ppf "%s@ LEVEL@ %S" e.ename l + | (Snterm _ | Snext | Sself | Stree _ | Stoken _ | + Skeyword _ + as s) -> print_symbol1 ppf s + and print_meta ppf n sl = + let rec loop i = + function + | [] -> () + | s :: sl -> + let j = + (try String.index_from n i ' ' + with | Not_found -> String.length n) + in + (fprintf ppf "%s %a" (String.sub n i (j - i)) + print_symbol1 s; + if sl = [] + then () + else + (fprintf ppf " "; + loop (min (j + 1) (String.length n)) sl)) + in loop 0 sl + and print_symbol1 ppf = + function + | Snterm e -> pp_print_string ppf e.ename + | Sself -> pp_print_string ppf "SELF" + | Snext -> pp_print_string ppf "NEXT" + | Stoken ((_, descr)) -> pp_print_string ppf descr + | Skeyword s -> fprintf ppf "%S" s + | Stree t -> + print_level ppf pp_print_space (flatten_tree t) + | (Smeta (_, _, _) | Snterml (_, _) | Slist0 _ | + Slist0sep (_, _) | Slist1 _ | Slist1sep (_, _) | + Sopt _ + as s) -> fprintf ppf "(%a)" print_symbol s + and print_rule ppf symbols = + (fprintf ppf "@["; + let _ = + List.fold_left + (fun sep symbol -> + (fprintf ppf "%t%a" sep print_symbol symbol; + fun ppf -> fprintf ppf ";@ ")) + (fun _ -> ()) symbols + in fprintf ppf "@]") + and print_level ppf pp_print_space rules = + (fprintf ppf "@[[ "; + let _ = + List.fold_left + (fun sep rule -> + (fprintf ppf "%t%a" sep print_rule rule; + fun ppf -> fprintf ppf "%a| " pp_print_space ())) + (fun _ -> ()) rules + in fprintf ppf " ]@]") + + let levels ppf elev = + let _ = + List.fold_left + (fun sep lev -> + let rules = + (List.map (fun t -> Sself :: t) + (flatten_tree lev.lsuffix)) + @ (flatten_tree lev.lprefix) + in + (fprintf ppf "%t@[" sep; + (match lev.lname with + | Some n -> fprintf ppf "%S@;<1 2>" n + | None -> ()); + (match lev.assoc with + | LeftA -> fprintf ppf "LEFTA" + | RightA -> fprintf ppf "RIGHTA" + | NonA -> fprintf ppf "NONA"); + fprintf ppf "@]@;<1 2>"; + print_level ppf pp_force_newline rules; + fun ppf -> fprintf ppf "@,| ")) + (fun _ -> ()) elev + in () + + let entry ppf e = + (fprintf ppf "@[%s: [ " e.ename; + (match e.edesc with + | Dlevels elev -> levels ppf elev + | Dparser _ -> fprintf ppf ""); + fprintf ppf " ]@]") + + end + + module MakeDump (Structure : Structure.S) = + struct + open Structure + + open Format + + open Sig.Grammar + + type brothers = | Bro of symbol * brothers list + + let rec print_tree ppf tree = + let rec get_brothers acc = + function + | DeadEnd -> List.rev acc + | LocAct (_, _) -> List.rev acc + | Node { node = n; brother = b; son = s } -> + get_brothers ((Bro (n, get_brothers [] s)) :: acc) b + and print_brothers ppf brothers = + if brothers = [] + then fprintf ppf "@ []" + else + List.iter + (function + | Bro (n, xs) -> + (fprintf ppf "@ @[- %a" print_symbol n; + (match xs with + | [] -> () + | [ _ ] -> + (try + print_children ppf (get_children [] xs) + with + | Exit -> + fprintf ppf ":%a" print_brothers xs) + | _ -> fprintf ppf ":%a" print_brothers xs); + fprintf ppf "@]")) + brothers + and print_children ppf = + List.iter (fprintf ppf ";@ %a" print_symbol) + and get_children acc = + function + | [] -> List.rev acc + | [ Bro (n, x) ] -> get_children (n :: acc) x + | _ -> raise Exit + in print_brothers ppf (get_brothers [] tree) + and print_symbol ppf = + function + | Smeta (n, sl, _) -> print_meta ppf n sl + | Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s + | Slist0sep (s, t) -> + fprintf ppf "LIST0 %a SEP %a" print_symbol1 s + print_symbol1 t + | Slist1 s -> fprintf ppf "LIST1 %a" print_symbol1 s + | Slist1sep (s, t) -> + fprintf ppf "LIST1 %a SEP %a" print_symbol1 s + print_symbol1 t + | Sopt s -> fprintf ppf "OPT %a" print_symbol1 s + | Snterml (e, l) -> fprintf ppf "%s@ LEVEL@ %S" e.ename l + | (Snterm _ | Snext | Sself | Stree _ | Stoken _ | + Skeyword _ + as s) -> print_symbol1 ppf s + and print_meta ppf n sl = + let rec loop i = + function + | [] -> () + | s :: sl -> + let j = + (try String.index_from n i ' ' + with | Not_found -> String.length n) + in + (fprintf ppf "%s %a" (String.sub n i (j - i)) + print_symbol1 s; + if sl = [] + then () + else + (fprintf ppf " "; + loop (min (j + 1) (String.length n)) sl)) + in loop 0 sl + and print_symbol1 ppf = + function + | Snterm e -> pp_print_string ppf e.ename + | Sself -> pp_print_string ppf "SELF" + | Snext -> pp_print_string ppf "NEXT" + | Stoken ((_, descr)) -> pp_print_string ppf descr + | Skeyword s -> fprintf ppf "%S" s + | Stree t -> print_tree ppf t + | (Smeta (_, _, _) | Snterml (_, _) | Slist0 _ | + Slist0sep (_, _) | Slist1 _ | Slist1sep (_, _) | + Sopt _ + as s) -> fprintf ppf "(%a)" print_symbol s + and print_rule ppf symbols = + (fprintf ppf "@["; + let _ = + List.fold_left + (fun sep symbol -> + (fprintf ppf "%t%a" sep print_symbol symbol; + fun ppf -> fprintf ppf ";@ ")) + (fun _ -> ()) symbols + in fprintf ppf "@]") + and print_level ppf pp_print_space rules = + (fprintf ppf "@[[ "; + let _ = + List.fold_left + (fun sep rule -> + (fprintf ppf "%t%a" sep print_rule rule; + fun ppf -> fprintf ppf "%a| " pp_print_space ())) + (fun _ -> ()) rules + in fprintf ppf " ]@]") + + let levels ppf elev = + let _ = + List.fold_left + (fun sep lev -> + (fprintf ppf "%t@[" sep; + (match lev.lname with + | Some n -> fprintf ppf "%S@;<1 2>" n + | None -> ()); + (match lev.assoc with + | LeftA -> fprintf ppf "LEFTA" + | RightA -> fprintf ppf "RIGHTA" + | NonA -> fprintf ppf "NONA"); + fprintf ppf "@]@;<1 2>"; + fprintf ppf "@[suffix:@ "; + print_tree ppf lev.lsuffix; + fprintf ppf "@]@ @[prefix:@ "; + print_tree ppf lev.lprefix; + fprintf ppf "@]"; + fun ppf -> fprintf ppf "@,| ")) + (fun _ -> ()) elev + in () + + let entry ppf e = + (fprintf ppf "@[%s: [ " e.ename; + (match e.edesc with + | Dlevels elev -> levels ppf elev + | Dparser _ -> fprintf ppf ""); + fprintf ppf " ]@]") + + end + + end + + module Failed = + struct + module Make (Structure : Structure.S) = + struct + module Tools = Tools.Make(Structure) + + module Search = Search.Make(Structure) + + module Print = Print.Make(Structure) + + open Structure + + open Format + + let rec name_of_symbol entry = + function + | Snterm e -> "[" ^ (e.ename ^ "]") + | Snterml (e, l) -> + "[" ^ (e.ename ^ (" level " ^ (l ^ "]"))) + | Sself | Snext -> "[" ^ (entry.ename ^ "]") + | Stoken ((_, descr)) -> descr + | Skeyword kwd -> "\"" ^ (kwd ^ "\"") + | _ -> "???" + + let rec name_of_symbol_failed entry = + function + | Slist0 s -> name_of_symbol_failed entry s + | Slist0sep (s, _) -> name_of_symbol_failed entry s + | Slist1 s -> name_of_symbol_failed entry s + | Slist1sep (s, _) -> name_of_symbol_failed entry s + | Sopt s -> name_of_symbol_failed entry s + | Stree t -> name_of_tree_failed entry t + | s -> name_of_symbol entry s + and name_of_tree_failed entry = + function + | Node { node = s; brother = bro; son = son } -> + let tokl = + (match s with + | Stoken _ | Skeyword _ -> + Tools.get_token_list entry [] s son + | _ -> None) + in + (match tokl with + | None -> + let txt = name_of_symbol_failed entry s in + let txt = + (match (s, son) with + | (Sopt _, Node _) -> + txt ^ + (" or " ^ + (name_of_tree_failed entry son)) + | _ -> txt) in + let txt = + (match bro with + | DeadEnd | LocAct (_, _) -> txt + | Node _ -> + txt ^ + (" or " ^ + (name_of_tree_failed entry bro))) + in txt + | Some ((tokl, _, _)) -> + List.fold_left + (fun s tok -> + (if s = "" then "" else s ^ " then ") ^ + (match tok with + | Stoken ((_, descr)) -> descr + | Skeyword kwd -> kwd + | _ -> assert false)) + "" tokl) + | DeadEnd | LocAct (_, _) -> "???" + + let magic _s x = Obj.magic x + + let tree_failed entry prev_symb_result prev_symb tree = + let txt = name_of_tree_failed entry tree in + let txt = + match prev_symb with + | Slist0 s -> + let txt1 = name_of_symbol_failed entry s + in txt1 ^ (" or " ^ (txt ^ " expected")) + | Slist1 s -> + let txt1 = name_of_symbol_failed entry s + in txt1 ^ (" or " ^ (txt ^ " expected")) + | Slist0sep (s, sep) -> + (match magic "tree_failed: 'a -> list 'b" + prev_symb_result + with + | [] -> + let txt1 = name_of_symbol_failed entry s + in txt1 ^ (" or " ^ (txt ^ " expected")) + | _ -> + let txt1 = name_of_symbol_failed entry sep + in txt1 ^ (" or " ^ (txt ^ " expected"))) + | Slist1sep (s, sep) -> + (match magic "tree_failed: 'a -> list 'b" + prev_symb_result + with + | [] -> + let txt1 = name_of_symbol_failed entry s + in txt1 ^ (" or " ^ (txt ^ " expected")) + | _ -> + let txt1 = name_of_symbol_failed entry sep + in txt1 ^ (" or " ^ (txt ^ " expected"))) + | Sopt _ | Stree _ -> txt ^ " expected" + | _ -> + txt ^ + (" expected after " ^ + (name_of_symbol entry prev_symb)) + in + (if !(entry.egram.error_verbose) + then + (let tree = + Search.tree_in_entry prev_symb tree entry.edesc in + let ppf = err_formatter + in + (fprintf ppf "@[@,"; + fprintf ppf "----------------------------------@,"; + fprintf ppf + "Parse error in entry [%s], rule:@;<0 2>" + entry.ename; + fprintf ppf "@["; + Print.print_level ppf pp_force_newline + (Print.flatten_tree tree); + fprintf ppf "@]@,"; + fprintf ppf "----------------------------------@,"; + fprintf ppf "@]@.")) + else (); + txt ^ (" (in [" ^ (entry.ename ^ "])"))) + + let symb_failed entry prev_symb_result prev_symb symb = + let tree = + Node { node = symb; brother = DeadEnd; son = DeadEnd; } + in tree_failed entry prev_symb_result prev_symb tree + + let symb_failed_txt e s1 s2 = symb_failed e 0 s1 s2 + + end + + end + + module Parser = + struct + module Make (Structure : Structure.S) = + struct + module Tools = Tools.Make(Structure) + + module Failed = Failed.Make(Structure) + + module Print = Print.Make(Structure) + + open Structure + + open Sig.Grammar + + module Stream = + struct + include Stream + + let junk strm = Context.junk strm + + let count strm = Context.bp strm + + end + + let add_loc c bp parse_fun strm = + let x = parse_fun c strm in + let ep = Context.loc_ep c in + let loc = Loc.merge bp ep in (x, loc) + + let level_number entry lab = + let rec lookup levn = + function + | [] -> failwith ("unknown level " ^ lab) + | lev :: levs -> + if Tools.is_level_labelled lab lev + then levn + else lookup (succ levn) levs + in + match entry.edesc with + | Dlevels elev -> lookup 0 elev + | Dparser _ -> raise Not_found + + let strict_parsing = ref false + + let strict_parsing_warning = ref false + + let rec top_symb entry = + function + | Sself | Snext -> Snterm entry + | Snterml (e, _) -> Snterm e + | Slist1sep (s, sep) -> Slist1sep (top_symb entry s, sep) + | _ -> raise Stream.Failure + + let top_tree entry = + function + | Node { node = s; brother = bro; son = son } -> + Node + { node = top_symb entry s; brother = bro; son = son; + } + | LocAct (_, _) | DeadEnd -> raise Stream.Failure + + let entry_of_symb entry = + function + | Sself | Snext -> entry + | Snterm e -> e + | Snterml (e, _) -> e + | _ -> raise Stream.Failure + + let continue entry loc a s c son p1 (__strm : _ Stream.t) = + let a = + (entry_of_symb entry s).econtinue 0 loc a c __strm in + let act = + try p1 __strm + with + | Stream.Failure -> + raise + (Stream.Error (Failed.tree_failed entry a s son)) + in Action.mk (fun _ -> Action.getf act a) + + let skip_if_empty c bp _ = + if (Context.loc_bp c) = bp + then Action.mk (fun _ -> raise Stream.Failure) + else raise Stream.Failure + + let do_recover parser_of_tree entry nlevn alevn loc a s c son + (__strm : _ Stream.t) = + try + parser_of_tree entry nlevn alevn (top_tree entry son) c + __strm + with + | Stream.Failure -> + (try skip_if_empty c loc __strm + with + | Stream.Failure -> + continue entry loc a s c son + (parser_of_tree entry nlevn alevn son c) __strm) + + let recover parser_of_tree entry nlevn alevn loc a s c son + strm = + if !strict_parsing + then + raise (Stream.Error (Failed.tree_failed entry a s son)) + else + (let _ = + if !strict_parsing_warning + then + (let msg = Failed.tree_failed entry a s son + in + (Format.eprintf + "Warning: trying to recover from syntax error"; + if entry.ename <> "" + then Format.eprintf " in [%s]" entry.ename + else (); + Format.eprintf "\n%s%a@." msg Loc.print loc)) + else () + in + do_recover parser_of_tree entry nlevn alevn loc a s c + son strm) + + let rec parser_of_tree entry nlevn alevn = + function + | DeadEnd -> + (fun _ (__strm : _ Stream.t) -> raise Stream.Failure) + | LocAct (act, _) -> (fun _ (__strm : _ Stream.t) -> act) + | Node + { + node = Sself; + son = LocAct (act, _); + brother = DeadEnd + } -> + (fun c (__strm : _ Stream.t) -> + let a = entry.estart alevn c __strm + in Action.getf act a) + | Node { node = Sself; son = LocAct (act, _); brother = bro + } -> + let p2 = parser_of_tree entry nlevn alevn bro + in + (fun c (__strm : _ Stream.t) -> + match try Some (entry.estart alevn c __strm) + with | Stream.Failure -> None + with + | Some a -> Action.getf act a + | _ -> p2 c __strm) + | Node { node = s; son = son; brother = DeadEnd } -> + let tokl = + (match s with + | Stoken _ | Skeyword _ -> + Tools.get_token_list entry [] s son + | _ -> None) + in + (match tokl with + | None -> + let ps = parser_of_symbol entry nlevn s in + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = parser_cont p1 entry nlevn alevn s son + in + (fun c (__strm : _ Stream.t) -> + let bp = Stream.count __strm in + let a = ps c __strm in + let act = + try p1 c bp a __strm + with + | Stream.Failure -> + raise (Stream.Error "") + in Action.getf act a) + | Some ((tokl, last_tok, son)) -> + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = + parser_cont p1 entry nlevn alevn last_tok son + in parser_of_token_list p1 tokl) + | Node { node = s; son = son; brother = bro } -> + let tokl = + (match s with + | Stoken _ | Skeyword _ -> + Tools.get_token_list entry [] s son + | _ -> None) + in + (match tokl with + | None -> + let ps = parser_of_symbol entry nlevn s in + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = + parser_cont p1 entry nlevn alevn s son in + let p2 = parser_of_tree entry nlevn alevn bro + in + (fun c (__strm : _ Stream.t) -> + let bp = Stream.count __strm + in + match try Some (ps c __strm) + with | Stream.Failure -> None + with + | Some a -> + let act = + (try p1 c bp a __strm + with + | Stream.Failure -> + raise (Stream.Error "")) + in Action.getf act a + | _ -> p2 c __strm) + | Some ((tokl, last_tok, son)) -> + let p1 = parser_of_tree entry nlevn alevn son in + let p1 = + parser_cont p1 entry nlevn alevn last_tok son in + let p1 = parser_of_token_list p1 tokl in + let p2 = parser_of_tree entry nlevn alevn bro + in + (fun c (__strm : _ Stream.t) -> + try p1 c __strm + with | Stream.Failure -> p2 c __strm)) + and + parser_cont p1 entry nlevn alevn s son c loc a + (__strm : _ Stream.t) = + try p1 c __strm + with + | Stream.Failure -> + (try + recover parser_of_tree entry nlevn alevn loc a s c + son __strm + with + | Stream.Failure -> + raise + (Stream.Error (Failed.tree_failed entry a s son))) + and parser_of_token_list p1 tokl = + let rec loop n = + function + | Stoken ((tematch, _)) :: tokl -> + (match tokl with + | [] -> + let ps c _ = + (match Context.peek_nth c n with + | Some ((tok, _)) when tematch tok -> + (Context.njunk c n; Action.mk tok) + | _ -> raise Stream.Failure) + in + (fun c (__strm : _ Stream.t) -> + let bp = Stream.count __strm in + let a = ps c __strm in + let act = + try p1 c bp a __strm + with + | Stream.Failure -> + raise (Stream.Error "") + in Action.getf act a) + | _ -> + let ps c _ = + (match Context.peek_nth c n with + | Some ((tok, _)) when tematch tok -> tok + | _ -> raise Stream.Failure) in + let p1 = loop (n + 1) tokl + in + (fun c (__strm : _ Stream.t) -> + let tok = ps c __strm in + let s = __strm in + let act = p1 c s in Action.getf act tok)) + | Skeyword kwd :: tokl -> + (match tokl with + | [] -> + let ps c _ = + (match Context.peek_nth c n with + | Some ((tok, _)) when + Token.match_keyword kwd tok -> + (Context.njunk c n; Action.mk tok) + | _ -> raise Stream.Failure) + in + (fun c (__strm : _ Stream.t) -> + let bp = Stream.count __strm in + let a = ps c __strm in + let act = + try p1 c bp a __strm + with + | Stream.Failure -> + raise (Stream.Error "") + in Action.getf act a) + | _ -> + let ps c _ = + (match Context.peek_nth c n with + | Some ((tok, _)) when + Token.match_keyword kwd tok -> tok + | _ -> raise Stream.Failure) in + let p1 = loop (n + 1) tokl + in + (fun c (__strm : _ Stream.t) -> + let tok = ps c __strm in + let s = __strm in + let act = p1 c s in Action.getf act tok)) + | _ -> invalid_arg "parser_of_token_list" + in loop 1 tokl + and parser_of_symbol entry nlevn = + function + | Smeta (_, symbl, act) -> + let act = Obj.magic act entry symbl in + let pl = List.map (parser_of_symbol entry nlevn) symbl + in + (fun c -> + Obj.magic + (List.fold_left + (fun act p -> Obj.magic act (p c)) act pl)) + | Slist0 s -> + let ps = parser_of_symbol entry nlevn s in + let rec loop c al (__strm : _ Stream.t) = + (match try Some (ps c __strm) + with | Stream.Failure -> None + with + | Some a -> loop c (a :: al) __strm + | _ -> al) + in + (fun c (__strm : _ Stream.t) -> + let a = loop c [] __strm in Action.mk (List.rev a)) + | Slist0sep (symb, sep) -> + let ps = parser_of_symbol entry nlevn symb in + let pt = parser_of_symbol entry nlevn sep in + let rec kont c al (__strm : _ Stream.t) = + (match try Some (pt c __strm) + with | Stream.Failure -> None + with + | Some v -> + let a = + (try ps c __strm + with + | Stream.Failure -> + raise + (Stream.Error + (Failed.symb_failed entry v sep symb))) + in kont c (a :: al) __strm + | _ -> al) + in + (fun c (__strm : _ Stream.t) -> + match try Some (ps c __strm) + with | Stream.Failure -> None + with + | Some a -> + let s = __strm + in Action.mk (List.rev (kont c [ a ] s)) + | _ -> Action.mk []) + | Slist1 s -> + let ps = parser_of_symbol entry nlevn s in + let rec loop c al (__strm : _ Stream.t) = + (match try Some (ps c __strm) + with | Stream.Failure -> None + with + | Some a -> loop c (a :: al) __strm + | _ -> al) + in + (fun c (__strm : _ Stream.t) -> + let a = ps c __strm in + let s = __strm + in Action.mk (List.rev (loop c [ a ] s))) + | Slist1sep (symb, sep) -> + let ps = parser_of_symbol entry nlevn symb in + let pt = parser_of_symbol entry nlevn sep in + let rec kont c al (__strm : _ Stream.t) = + (match try Some (pt c __strm) + with | Stream.Failure -> None + with + | Some v -> + let a = + (try ps c __strm + with + | Stream.Failure -> + (try parse_top_symb' entry symb c __strm + with + | Stream.Failure -> + raise + (Stream.Error + (Failed.symb_failed entry v sep + symb)))) + in kont c (a :: al) __strm + | _ -> al) + in + (fun c (__strm : _ Stream.t) -> + let a = ps c __strm in + let s = __strm + in Action.mk (List.rev (kont c [ a ] s))) + | Sopt s -> + let ps = parser_of_symbol entry nlevn s + in + (fun c (__strm : _ Stream.t) -> + match try Some (ps c __strm) + with | Stream.Failure -> None + with + | Some a -> Action.mk (Some a) + | _ -> Action.mk None) + | Stree t -> + let pt = parser_of_tree entry 1 0 t + in + (fun c (__strm : _ Stream.t) -> + let bp = Stream.count __strm in + let (act, loc) = add_loc c bp pt __strm + in Action.getf act loc) + | Snterm e -> + (fun c (__strm : _ Stream.t) -> e.estart 0 c __strm) + | Snterml (e, l) -> + (fun c (__strm : _ Stream.t) -> + e.estart (level_number e l) c __strm) + | Sself -> + (fun c (__strm : _ Stream.t) -> entry.estart 0 c __strm) + | Snext -> + (fun c (__strm : _ Stream.t) -> + entry.estart nlevn c __strm) + | Skeyword kwd -> + (fun _ (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some ((tok, _)) when Token.match_keyword kwd tok + -> (Stream.junk __strm; Action.mk tok) + | _ -> raise Stream.Failure) + | Stoken ((f, _)) -> + (fun _ (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some ((tok, _)) when f tok -> + (Stream.junk __strm; Action.mk tok) + | _ -> raise Stream.Failure) + and parse_top_symb' entry symb c = + parser_of_symbol entry 0 (top_symb entry symb) c + and parse_top_symb entry symb strm = + Context.call_with_ctx strm + (fun c -> parse_top_symb' entry symb c (Context.stream c)) + + let rec start_parser_of_levels entry clevn = + function + | [] -> + (fun _ _ (__strm : _ Stream.t) -> raise Stream.Failure) + | lev :: levs -> + let p1 = start_parser_of_levels entry (succ clevn) levs + in + (match lev.lprefix with + | DeadEnd -> p1 + | tree -> + let alevn = + (match lev.assoc with + | LeftA | NonA -> succ clevn + | RightA -> clevn) in + let p2 = + parser_of_tree entry (succ clevn) alevn tree + in + (match levs with + | [] -> + (fun levn c (__strm : _ Stream.t) -> + let bp = Stream.count __strm in + let (act, loc) = + add_loc c bp p2 __strm in + let strm = __strm in + let a = Action.getf act loc + in entry.econtinue levn loc a c strm) + | _ -> + (fun levn c strm -> + if levn > clevn + then p1 levn c strm + else + (let (__strm : _ Stream.t) = strm in + let bp = Stream.count __strm + in + match try + Some + (add_loc c bp p2 __strm) + with + | Stream.Failure -> None + with + | Some ((act, loc)) -> + let a = Action.getf act loc + in + entry.econtinue levn loc a + c strm + | _ -> p1 levn c __strm)))) + + let start_parser_of_entry entry = + match entry.edesc with + | Dlevels [] -> Tools.empty_entry entry.ename + | Dlevels elev -> start_parser_of_levels entry 0 elev + | Dparser p -> (fun _ _ strm -> p strm) + + let rec continue_parser_of_levels entry clevn = + function + | [] -> + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure) + | lev :: levs -> + let p1 = + continue_parser_of_levels entry (succ clevn) levs + in + (match lev.lsuffix with + | DeadEnd -> p1 + | tree -> + let alevn = + (match lev.assoc with + | LeftA | NonA -> succ clevn + | RightA -> clevn) in + let p2 = + parser_of_tree entry (succ clevn) alevn tree + in + (fun c levn bp a strm -> + if levn > clevn + then p1 c levn bp a strm + else + (let (__strm : _ Stream.t) = strm + in + try p1 c levn bp a __strm + with + | Stream.Failure -> + let (act, loc) = + add_loc c bp p2 __strm in + let a = Action.getf2 act a loc + in + entry.econtinue levn loc a c + strm))) + + let continue_parser_of_entry entry = + match entry.edesc with + | Dlevels elev -> + let p = continue_parser_of_levels entry 0 elev + in + (fun levn bp a c (__strm : _ Stream.t) -> + try p c levn bp a __strm + with | Stream.Failure -> a) + | Dparser _ -> + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure) + + end + + end + + module Insert = + struct + module Make (Structure : Structure.S) = + struct + module Tools = Tools.Make(Structure) + + module Parser = Parser.Make(Structure) + + open Structure + + open Format + + open Sig.Grammar + + let is_before s1 s2 = + match (s1, s2) with + | ((Skeyword _ | Stoken _), (Skeyword _ | Stoken _)) -> + false + | ((Skeyword _ | Stoken _), _) -> true + | _ -> false + + let rec derive_eps = + function + | Slist0 _ -> true + | Slist0sep (_, _) -> true + | Sopt _ -> true + | Stree t -> tree_derive_eps t + | Smeta (_, _, _) | Slist1 _ | Slist1sep (_, _) | Snterm _ + | Snterml (_, _) | Snext | Sself | Stoken _ | + Skeyword _ -> false + and tree_derive_eps = + function + | LocAct (_, _) -> true + | Node { node = s; brother = bro; son = son } -> + ((derive_eps s) && (tree_derive_eps son)) || + (tree_derive_eps bro) + | DeadEnd -> false + + let empty_lev lname assoc = + let assoc = match assoc with | Some a -> a | None -> LeftA + in + { + assoc = assoc; + lname = lname; + lsuffix = DeadEnd; + lprefix = DeadEnd; + } + + let change_lev entry lev n lname assoc = + let a = + match assoc with + | None -> lev.assoc + | Some a -> + (if + (a <> lev.assoc) && !(entry.egram.warning_verbose) + then + (eprintf + " Changing associativity of level \"%s\"\n" + n; + flush stderr) + else (); + a) + in + ((match lname with + | Some n -> + if + (lname <> lev.lname) && + !(entry.egram.warning_verbose) + then + (eprintf " Level label \"%s\" ignored\n" n; + flush stderr) + else () + | None -> ()); + { + assoc = a; + lname = lev.lname; + lsuffix = lev.lsuffix; + lprefix = lev.lprefix; + }) + + let change_to_self entry = + function | Snterm e when e == entry -> Sself | x -> x + + let get_level entry position levs = + match position with + | Some First -> ([], empty_lev, levs) + | Some Last -> (levs, empty_lev, []) + | Some (Level n) -> + let rec get = + (function + | [] -> + (eprintf + "No level labelled \"%s\" in entry \"%s\"\n" + n entry.ename; + flush stderr; + failwith "Grammar.extend") + | lev :: levs -> + if Tools.is_level_labelled n lev + then ([], (change_lev entry lev n), levs) + else + (let (levs1, rlev, levs2) = get levs + in ((lev :: levs1), rlev, levs2))) + in get levs + | Some (Before n) -> + let rec get = + (function + | [] -> + (eprintf + "No level labelled \"%s\" in entry \"%s\"\n" + n entry.ename; + flush stderr; + failwith "Grammar.extend") + | lev :: levs -> + if Tools.is_level_labelled n lev + then ([], empty_lev, (lev :: levs)) + else + (let (levs1, rlev, levs2) = get levs + in ((lev :: levs1), rlev, levs2))) + in get levs + | Some (After n) -> + let rec get = + (function + | [] -> + (eprintf + "No level labelled \"%s\" in entry \"%s\"\n" + n entry.ename; + flush stderr; + failwith "Grammar.extend") + | lev :: levs -> + if Tools.is_level_labelled n lev + then ([ lev ], empty_lev, levs) + else + (let (levs1, rlev, levs2) = get levs + in ((lev :: levs1), rlev, levs2))) + in get levs + | None -> + (match levs with + | lev :: levs -> + ([], (change_lev entry lev ""), levs) + | [] -> ([], empty_lev, [])) + + let rec check_gram entry = + function + | Snterm e -> + if ( != ) e.egram entry.egram + then + (eprintf + "\ + Error: entries \"%s\" and \"%s\" do not belong to the same grammar.\n" + entry.ename e.ename; + flush stderr; + failwith "Grammar.extend error") + else () + | Snterml (e, _) -> + if ( != ) e.egram entry.egram + then + (eprintf + "\ + Error: entries \"%s\" and \"%s\" do not belong to the same grammar.\n" + entry.ename e.ename; + flush stderr; + failwith "Grammar.extend error") + else () + | Smeta (_, sl, _) -> List.iter (check_gram entry) sl + | Slist0sep (s, t) -> + (check_gram entry t; check_gram entry s) + | Slist1sep (s, t) -> + (check_gram entry t; check_gram entry s) + | Slist0 s -> check_gram entry s + | Slist1 s -> check_gram entry s + | Sopt s -> check_gram entry s + | Stree t -> tree_check_gram entry t + | Snext | Sself | Stoken _ | Skeyword _ -> () + and tree_check_gram entry = + function + | Node { node = n; brother = bro; son = son } -> + (check_gram entry n; + tree_check_gram entry bro; + tree_check_gram entry son) + | LocAct (_, _) | DeadEnd -> () + + let get_initial = + function + | Sself :: symbols -> (true, symbols) + | symbols -> (false, symbols) + + let insert_tokens gram symbols = + let rec insert = + function + | Smeta (_, sl, _) -> List.iter insert sl + | Slist0 s -> insert s + | Slist1 s -> insert s + | Slist0sep (s, t) -> (insert s; insert t) + | Slist1sep (s, t) -> (insert s; insert t) + | Sopt s -> insert s + | Stree t -> tinsert t + | Skeyword kwd -> using gram kwd + | Snterm _ | Snterml (_, _) | Snext | Sself | Stoken _ -> + () + and tinsert = + function + | Node { node = s; brother = bro; son = son } -> + (insert s; tinsert bro; tinsert son) + | LocAct (_, _) | DeadEnd -> () + in List.iter insert symbols + + let insert_tree entry gsymbols action tree = + let rec insert symbols tree = + match symbols with + | s :: sl -> insert_in_tree s sl tree + | [] -> + (match tree with + | Node { node = s; son = son; brother = bro } -> + Node + { + node = s; + son = son; + brother = insert [] bro; + } + | LocAct (old_action, action_list) -> + let () = + if !(entry.egram.warning_verbose) + then + eprintf + " Grammar extension: in [%s] some rule has been masked@." + entry.ename + else () + in LocAct (action, old_action :: action_list) + | DeadEnd -> LocAct (action, [])) + and insert_in_tree s sl tree = + match try_insert s sl tree with + | Some t -> t + | None -> + Node + { + node = s; + son = insert sl DeadEnd; + brother = tree; + } + and try_insert s sl tree = + match tree with + | Node { node = s1; son = son; brother = bro } -> + if Tools.eq_symbol s s1 + then + (let t = + Node + { + node = s1; + son = insert sl son; + brother = bro; + } + in Some t) + else + if + (is_before s1 s) || + ((derive_eps s) && (not (derive_eps s1))) + then + (let bro = + match try_insert s sl bro with + | Some bro -> bro + | None -> + Node + { + node = s; + son = insert sl DeadEnd; + brother = bro; + } in + let t = + Node { node = s1; son = son; brother = bro; } + in Some t) + else + (match try_insert s sl bro with + | Some bro -> + let t = + Node + { node = s1; son = son; brother = bro; } + in Some t + | None -> None) + | LocAct (_, _) | DeadEnd -> None + and insert_new = + function + | s :: sl -> + Node + { node = s; son = insert_new sl; brother = DeadEnd; + } + | [] -> LocAct (action, []) + in insert gsymbols tree + + let insert_level entry e1 symbols action slev = + match e1 with + | true -> + { + assoc = slev.assoc; + lname = slev.lname; + lsuffix = + insert_tree entry symbols action slev.lsuffix; + lprefix = slev.lprefix; + } + | false -> + { + assoc = slev.assoc; + lname = slev.lname; + lsuffix = slev.lsuffix; + lprefix = + insert_tree entry symbols action slev.lprefix; + } + + let levels_of_rules entry position rules = + let elev = + match entry.edesc with + | Dlevels elev -> elev + | Dparser _ -> + (eprintf "Error: entry not extensible: \"%s\"\n" + entry.ename; + flush stderr; + failwith "Grammar.extend") + in + if rules = [] + then elev + else + (let (levs1, make_lev, levs2) = + get_level entry position elev in + let (levs, _) = + List.fold_left + (fun (levs, make_lev) (lname, assoc, level) -> + let lev = make_lev lname assoc in + let lev = + List.fold_left + (fun lev (symbols, action) -> + let symbols = + List.map (change_to_self entry) + symbols + in + (List.iter (check_gram entry) symbols; + let (e1, symbols) = + get_initial symbols + in + (insert_tokens entry.egram symbols; + insert_level entry e1 symbols + action lev))) + lev level + in ((lev :: levs), empty_lev)) + ([], make_lev) rules + in levs1 @ ((List.rev levs) @ levs2)) + + let extend entry (position, rules) = + let elev = levels_of_rules entry position rules + in + (entry.edesc <- Dlevels elev; + entry.estart <- + (fun lev c strm -> + let f = Parser.start_parser_of_entry entry + in (entry.estart <- f; f lev c strm)); + entry.econtinue <- + fun lev bp a c strm -> + let f = Parser.continue_parser_of_entry entry + in (entry.econtinue <- f; f lev bp a c strm)) + + end + + end + + module Delete = + struct + module Make (Structure : Structure.S) = + struct + module Tools = Tools.Make(Structure) + + module Parser = Parser.Make(Structure) + + open Structure + + let delete_rule_in_tree entry = + let rec delete_in_tree symbols tree = + match (symbols, tree) with + | (s :: sl, Node n) -> + if Tools.logically_eq_symbols entry s n.node + then delete_son sl n + else + (match delete_in_tree symbols n.brother with + | Some ((dsl, t)) -> + Some + ((dsl, + (Node + { + node = n.node; + son = n.son; + brother = t; + }))) + | None -> None) + | (_ :: _, _) -> None + | ([], Node n) -> + (match delete_in_tree [] n.brother with + | Some ((dsl, t)) -> + Some + ((dsl, + (Node + { + node = n.node; + son = n.son; + brother = t; + }))) + | None -> None) + | ([], DeadEnd) -> None + | ([], LocAct (_, [])) -> Some (((Some []), DeadEnd)) + | ([], LocAct (_, (action :: list))) -> + Some ((None, (LocAct (action, list)))) + and delete_son sl n = + match delete_in_tree sl n.son with + | Some ((Some dsl, DeadEnd)) -> + Some (((Some (n.node :: dsl)), (n.brother))) + | Some ((Some dsl, t)) -> + let t = + Node + { node = n.node; son = t; brother = n.brother; } + in Some (((Some (n.node :: dsl)), t)) + | Some ((None, t)) -> + let t = + Node + { node = n.node; son = t; brother = n.brother; } + in Some ((None, t)) + | None -> None + in delete_in_tree + + let rec decr_keyw_use gram = + function + | Skeyword kwd -> removing gram kwd + | Smeta (_, sl, _) -> List.iter (decr_keyw_use gram) sl + | Slist0 s -> decr_keyw_use gram s + | Slist1 s -> decr_keyw_use gram s + | Slist0sep (s1, s2) -> + (decr_keyw_use gram s1; decr_keyw_use gram s2) + | Slist1sep (s1, s2) -> + (decr_keyw_use gram s1; decr_keyw_use gram s2) + | Sopt s -> decr_keyw_use gram s + | Stree t -> decr_keyw_use_in_tree gram t + | Sself | Snext | Snterm _ | Snterml (_, _) | Stoken _ -> + () + and decr_keyw_use_in_tree gram = + function + | DeadEnd | LocAct (_, _) -> () + | Node n -> + (decr_keyw_use gram n.node; + decr_keyw_use_in_tree gram n.son; + decr_keyw_use_in_tree gram n.brother) + + let rec delete_rule_in_suffix entry symbols = + function + | lev :: levs -> + (match delete_rule_in_tree entry symbols lev.lsuffix + with + | Some ((dsl, t)) -> + ((match dsl with + | Some dsl -> + List.iter (decr_keyw_use entry.egram) dsl + | None -> ()); + (match t with + | DeadEnd when lev.lprefix == DeadEnd -> levs + | _ -> + let lev = + { + assoc = lev.assoc; + lname = lev.lname; + lsuffix = t; + lprefix = lev.lprefix; + } + in lev :: levs)) + | None -> + let levs = + delete_rule_in_suffix entry symbols levs + in lev :: levs) + | [] -> raise Not_found + + let rec delete_rule_in_prefix entry symbols = + function + | lev :: levs -> + (match delete_rule_in_tree entry symbols lev.lprefix + with + | Some ((dsl, t)) -> + ((match dsl with + | Some dsl -> + List.iter (decr_keyw_use entry.egram) dsl + | None -> ()); + (match t with + | DeadEnd when lev.lsuffix == DeadEnd -> levs + | _ -> + let lev = + { + assoc = lev.assoc; + lname = lev.lname; + lsuffix = lev.lsuffix; + lprefix = t; + } + in lev :: levs)) + | None -> + let levs = + delete_rule_in_prefix entry symbols levs + in lev :: levs) + | [] -> raise Not_found + + let rec delete_rule_in_level_list entry symbols levs = + match symbols with + | Sself :: symbols -> + delete_rule_in_suffix entry symbols levs + | Snterm e :: symbols when e == entry -> + delete_rule_in_suffix entry symbols levs + | _ -> delete_rule_in_prefix entry symbols levs + + let delete_rule entry sl = + match entry.edesc with + | Dlevels levs -> + let levs = delete_rule_in_level_list entry sl levs + in + (entry.edesc <- Dlevels levs; + entry.estart <- + (fun lev c strm -> + let f = Parser.start_parser_of_entry entry + in (entry.estart <- f; f lev c strm)); + entry.econtinue <- + (fun lev bp a c strm -> + let f = Parser.continue_parser_of_entry entry + in (entry.econtinue <- f; f lev bp a c strm))) + | Dparser _ -> () + + end + + end + + module Fold : + sig + module Make (Structure : Structure.S) : + sig + open Structure + + val sfold0 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold1 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) fold + + val sfold0sep : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) foldsep + + end + + end = + struct + module Make (Structure : Structure.S) = + struct + open Structure + + open Format + + module Parse = Parser.Make(Structure) + + module Fail = Failed.Make(Structure) + + open Sig.Grammar + + module Stream = + struct + include Stream + + let junk strm = Context.junk strm + + let count strm = Context.bp strm + + end + + let sfold0 f e _entry _symbl psymb = + let rec fold accu (__strm : _ Stream.t) = + match try Some (psymb __strm) + with | Stream.Failure -> None + with + | Some a -> fold (f a accu) __strm + | _ -> accu + in fun (__strm : _ Stream.t) -> fold e __strm + + let sfold1 f e _entry _symbl psymb = + let rec fold accu (__strm : _ Stream.t) = + match try Some (psymb __strm) + with | Stream.Failure -> None + with + | Some a -> fold (f a accu) __strm + | _ -> accu + in + fun (__strm : _ Stream.t) -> + let a = psymb __strm + in + try fold (f a e) __strm + with | Stream.Failure -> raise (Stream.Error "") + + let sfold0sep f e entry symbl psymb psep = + let failed = + function + | [ symb; sep ] -> Fail.symb_failed_txt entry sep symb + | _ -> "failed" in + let rec kont accu (__strm : _ Stream.t) = + match try Some (psep __strm) + with | Stream.Failure -> None + with + | Some () -> + let a = + (try psymb __strm + with + | Stream.Failure -> + raise (Stream.Error (failed symbl))) + in kont (f a accu) __strm + | _ -> accu + in + fun (__strm : _ Stream.t) -> + match try Some (psymb __strm) + with | Stream.Failure -> None + with + | Some a -> kont (f a e) __strm + | _ -> e + + let sfold1sep f e entry symbl psymb psep = + let failed = + function + | [ symb; sep ] -> Fail.symb_failed_txt entry sep symb + | _ -> "failed" in + let parse_top = + function + | [ symb; _ ] -> Parse.parse_top_symb entry symb + | _ -> raise Stream.Failure in + let rec kont accu (__strm : _ Stream.t) = + match try Some (psep __strm) + with | Stream.Failure -> None + with + | Some () -> + let a = + (try + try psymb __strm + with + | Stream.Failure -> + let a = + (try parse_top symbl __strm + with + | Stream.Failure -> + raise (Stream.Error (failed symbl))) + in Obj.magic a + with | Stream.Failure -> raise (Stream.Error "")) + in kont (f a accu) __strm + | _ -> accu + in + fun (__strm : _ Stream.t) -> + let a = psymb __strm in kont (f a e) __strm + + end + + end + + module Entry = + struct + module Make (Structure : Structure.S) = + struct + module Dump = Print.MakeDump(Structure) + + module Print = Print.Make(Structure) + + module Tools = Tools.Make(Structure) + + open Format + + open Structure + + type 'a t = internal_entry + + let name e = e.ename + + let print ppf e = fprintf ppf "%a@\n" Print.entry e + + let dump ppf e = fprintf ppf "%a@\n" Dump.entry e + + let mk g n = + { + egram = g; + ename = n; + estart = Tools.empty_entry n; + econtinue = + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure); + edesc = Dlevels []; + } + + let action_parse entry ts : Action.t = + Context.call_with_ctx ts + (fun c -> + try entry.estart 0 c (Context.stream c) + with + | Stream.Failure -> + Loc.raise (Context.loc_ep c) + (Stream.Error + ("illegal begin of " ^ entry.ename)) + | (Loc.Exc_located (_, _) as exc) -> raise exc + | exc -> Loc.raise (Context.loc_ep c) exc) + + let lex entry loc cs = entry.egram.glexer loc cs + + let lex_string entry loc str = + lex entry loc (Stream.of_string str) + + let filter entry ts = + Token.Filter.filter (get_filter entry.egram) ts + + let parse_tokens_after_filter entry ts = + Action.get (action_parse entry ts) + + let parse_tokens_before_filter entry ts = + parse_tokens_after_filter entry (filter entry ts) + + let parse entry loc cs = + parse_tokens_before_filter entry (lex entry loc cs) + + let parse_string entry loc str = + parse_tokens_before_filter entry (lex_string entry loc str) + + let of_parser g n (p : (Token.t * Loc.t) Stream.t -> 'a) : + 'a t = + { + egram = g; + ename = n; + estart = (fun _ _ ts -> Action.mk (p ts)); + econtinue = + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure); + edesc = Dparser (fun ts -> Action.mk (p ts)); + } + + let setup_parser e (p : (Token.t * Loc.t) Stream.t -> 'a) = + let f ts = Action.mk (p ts) + in + (e.estart <- (fun _ _ -> f); + e.econtinue <- + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure); + e.edesc <- Dparser f) + + let clear e = + (e.estart <- + (fun _ _ (__strm : _ Stream.t) -> raise Stream.Failure); + e.econtinue <- + (fun _ _ _ _ (__strm : _ Stream.t) -> + raise Stream.Failure); + e.edesc <- Dlevels []) + + let obj x = x + + end + + end + + module Static = + struct + let uncurry f (x, y) = f x y + + let flip f x y = f y x + + module Make (Lexer : Sig.Lexer) : + Sig.Grammar.Static with module Loc = Lexer.Loc + and module Token = Lexer.Token = + struct + module Structure = Structure.Make(Lexer) + + module Delete = Delete.Make(Structure) + + module Insert = Insert.Make(Structure) + + module Fold = Fold.Make(Structure) + + include Structure + + let gram = + let gkeywords = Hashtbl.create 301 + in + { + gkeywords = gkeywords; + gfilter = Token.Filter.mk (Hashtbl.mem gkeywords); + glexer = Lexer.mk (); + warning_verbose = ref true; + error_verbose = Camlp4_config.verbose; + } + + module Entry = + struct + module E = Entry.Make(Structure) + + type 'a t = 'a E.t + + let mk = E.mk gram + + let of_parser name strm = E.of_parser gram name strm + + let setup_parser = E.setup_parser + + let name = E.name + + let print = E.print + + let clear = E.clear + + let dump = E.dump + + let obj x = x + + end + + let get_filter () = gram.gfilter + + let lex loc cs = gram.glexer loc cs + + let lex_string loc str = lex loc (Stream.of_string str) + + let filter ts = Token.Filter.filter gram.gfilter ts + + let parse_tokens_after_filter entry ts = + Entry.E.parse_tokens_after_filter entry ts + + let parse_tokens_before_filter entry ts = + parse_tokens_after_filter entry (filter ts) + + let parse entry loc cs = + parse_tokens_before_filter entry (lex loc cs) + + let parse_string entry loc str = + parse_tokens_before_filter entry (lex_string loc str) + + let delete_rule = Delete.delete_rule + + let srules e rl = + Stree + (List.fold_left (flip (uncurry (Insert.insert_tree e))) + DeadEnd rl) + + let sfold0 = Fold.sfold0 + + let sfold1 = Fold.sfold1 + + let sfold0sep = Fold.sfold0sep + + let extend = Insert.extend + + end + + end + + module Dynamic = + struct + module Make (Lexer : Sig.Lexer) : + Sig.Grammar.Dynamic with module Loc = Lexer.Loc + and module Token = Lexer.Token = + struct + module Structure = Structure.Make(Lexer) + + module Delete = Delete.Make(Structure) + + module Insert = Insert.Make(Structure) + + module Entry = Entry.Make(Structure) + + module Fold = Fold.Make(Structure) + + include Structure + + let mk () = + let gkeywords = Hashtbl.create 301 + in + { + gkeywords = gkeywords; + gfilter = Token.Filter.mk (Hashtbl.mem gkeywords); + glexer = Lexer.mk (); + warning_verbose = ref true; + error_verbose = Camlp4_config.verbose; + } + + let get_filter g = g.gfilter + + let lex g loc cs = g.glexer loc cs + + let lex_string g loc str = lex g loc (Stream.of_string str) + + let filter g ts = Token.Filter.filter g.gfilter ts + + let parse_tokens_after_filter entry ts = + Entry.parse_tokens_after_filter entry ts + + let parse_tokens_before_filter entry ts = + parse_tokens_after_filter entry (filter entry.egram ts) + + let parse entry loc cs = + parse_tokens_before_filter entry (lex entry.egram loc cs) + + let parse_string entry loc str = + parse_tokens_before_filter entry + (lex_string entry.egram loc str) + + let delete_rule = Delete.delete_rule + + let srules e rl = + let t = + List.fold_left + (fun tree (symbols, action) -> + Insert.insert_tree e symbols action tree) + DeadEnd rl + in Stree t + + let sfold0 = Fold.sfold0 + + let sfold1 = Fold.sfold1 + + let sfold0sep = Fold.sfold0sep + + let extend = Insert.extend + + end + + end + + end + + end + +module Printers = + struct + module DumpCamlp4Ast : + sig + module Id : Sig.Id + + module Make (Syntax : Sig.Syntax) : Sig.Printer(Syntax.Ast).S + + end = + struct + module Id = + struct + let name = "Camlp4Printers.DumpCamlp4Ast" + + let version = Sys.ocaml_version + + end + + module Make (Syntax : Sig.Syntax) : Sig.Printer(Syntax.Ast).S = + struct + include Syntax + + let with_open_out_file x f = + match x with + | Some file -> + let oc = open_out_bin file + in (f oc; flush oc; close_out oc) + | None -> + (set_binary_mode_out stdout true; f stdout; flush stdout) + + let dump_ast magic ast oc = + (output_string oc magic; output_value oc ast) + + let print_interf ?input_file:(_) ?output_file ast = + with_open_out_file output_file + (dump_ast Camlp4_config.camlp4_ast_intf_magic_number ast) + + let print_implem ?input_file:(_) ?output_file ast = + with_open_out_file output_file + (dump_ast Camlp4_config.camlp4_ast_impl_magic_number ast) + + end + + end + + module DumpOCamlAst : + sig + module Id : Sig.Id + + module Make (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax.Ast).S + + end = + struct + module Id : Sig.Id = + struct + let name = "Camlp4Printers.DumpOCamlAst" + + let version = Sys.ocaml_version + + end + + module Make (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax.Ast).S = + struct + include Syntax + + module Ast2pt = Struct.Camlp4Ast2OCamlAst.Make(Ast) + + let with_open_out_file x f = + match x with + | Some file -> + let oc = open_out_bin file + in (f oc; flush oc; close_out oc) + | None -> + (set_binary_mode_out stdout true; f stdout; flush stdout) + + let dump_pt magic fname pt oc = + (output_string oc magic; + output_value oc (if fname = "-" then "" else fname); + output_value oc pt) + + let print_interf ?(input_file = "-") ?output_file ast = + let pt = Ast2pt.sig_item ast + in + with_open_out_file output_file + (dump_pt Camlp4_config.ocaml_ast_intf_magic_number + input_file pt) + + let print_implem ?(input_file = "-") ?output_file ast = + let pt = Ast2pt.str_item ast + in + with_open_out_file output_file + (dump_pt Camlp4_config.ocaml_ast_impl_magic_number + input_file pt) + + end + + end + + module Null : + sig + module Id : Sig.Id + + module Make (Syntax : Sig.Syntax) : Sig.Printer(Syntax.Ast).S + + end = + struct + module Id = + struct let name = "Camlp4.Printers.Null" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Syntax) = + struct + include Syntax + + let print_interf ?input_file:(_) ?output_file:(_) _ = () + + let print_implem ?input_file:(_) ?output_file:(_) _ = () + + end + + end + + module OCaml : + sig + module Id : Sig.Id + + module Make (Syntax : Sig.Camlp4Syntax) : + sig + open Format + + include Sig.Camlp4Syntax with module Loc = Syntax.Loc + and module Token = Syntax.Token and module Ast = Syntax.Ast + and module Gram = Syntax.Gram + + type sep = (unit, formatter, unit) format + + val list' : + (formatter -> 'a -> unit) -> + ('b, formatter, unit) format -> + (unit, formatter, unit) format -> + formatter -> 'a list -> unit + + val list : + (formatter -> 'a -> unit) -> + ('b, formatter, unit) format -> formatter -> 'a list -> unit + + val lex_string : string -> Token.t + + val is_infix : string -> bool + + val is_keyword : string -> bool + + val ocaml_char : string -> string + + val get_expr_args : + Ast.expr -> Ast.expr list -> (Ast.expr * (Ast.expr list)) + + val get_patt_args : + Ast.patt -> Ast.patt list -> (Ast.patt * (Ast.patt list)) + + val get_ctyp_args : + Ast.ctyp -> Ast.ctyp list -> (Ast.ctyp * (Ast.ctyp list)) + + val expr_fun_args : Ast.expr -> ((Ast.patt list) * Ast.expr) + + class printer : + ?curry_constr: bool -> + ?comments: bool -> + unit -> + object ('a) + method interf : formatter -> Ast.sig_item -> unit + + method implem : formatter -> Ast.str_item -> unit + + method sig_item : formatter -> Ast.sig_item -> unit + + method str_item : formatter -> Ast.str_item -> unit + + val pipe : bool + + val semi : bool + + val semisep : sep + + val value_val : string + + val value_let : string + + method anti : formatter -> string -> unit + + method class_declaration : + formatter -> Ast.class_expr -> unit + + method class_expr : formatter -> Ast.class_expr -> unit + + method class_sig_item : + formatter -> Ast.class_sig_item -> unit + + method class_str_item : + formatter -> Ast.class_str_item -> unit + + method class_type : formatter -> Ast.class_type -> unit + + method constrain : + formatter -> (Ast.ctyp * Ast.ctyp) -> unit + + method ctyp : formatter -> Ast.ctyp -> unit + + method ctyp1 : formatter -> Ast.ctyp -> unit + + method constructor_type : formatter -> Ast.ctyp -> unit + + method dot_expr : formatter -> Ast.expr -> unit + + method apply_expr : formatter -> Ast.expr -> unit + + method expr : formatter -> Ast.expr -> unit + + method expr_list : formatter -> Ast.expr list -> unit + + method expr_list_cons : + bool -> formatter -> Ast.expr -> unit + + method functor_arg : + formatter -> (string * Ast.module_type) -> unit + + method functor_args : + formatter -> (string * Ast.module_type) list -> unit + + method ident : formatter -> Ast.ident -> unit + + method numeric : formatter -> string -> string -> unit + + method binding : formatter -> Ast.binding -> unit + + method record_binding : + formatter -> Ast.rec_binding -> unit + + method match_case : formatter -> Ast.match_case -> unit + + method match_case_aux : + formatter -> Ast.match_case -> unit + + method mk_expr_list : + Ast.expr -> ((Ast.expr list) * (Ast.expr option)) + + method mk_patt_list : + Ast.patt -> ((Ast.patt list) * (Ast.patt option)) + + method simple_module_expr : + formatter -> Ast.module_expr -> unit + + method module_expr : + formatter -> Ast.module_expr -> unit + + method module_expr_get_functor_args : + (string * Ast.module_type) list -> + Ast.module_expr -> + (((string * Ast.module_type) list) * Ast. + module_expr * (Ast.module_type option)) + + method module_rec_binding : + formatter -> Ast.module_binding -> unit + + method module_type : + formatter -> Ast.module_type -> unit + + method mutable_flag : + formatter -> Ast.meta_bool -> unit + + method direction_flag : + formatter -> Ast.meta_bool -> unit + + method rec_flag : formatter -> Ast.meta_bool -> unit + + method flag : + formatter -> Ast.meta_bool -> string -> unit + + method node : formatter -> 'b -> ('b -> Loc.t) -> unit + + method patt : formatter -> Ast.patt -> unit + + method patt1 : formatter -> Ast.patt -> unit + + method patt2 : formatter -> Ast.patt -> unit + + method patt3 : formatter -> Ast.patt -> unit + + method patt4 : formatter -> Ast.patt -> unit + + method patt5 : formatter -> Ast.patt -> unit + + method patt_tycon : formatter -> Ast.patt -> unit + + method patt_expr_fun_args : + formatter -> (Ast.patt * Ast.expr) -> unit + + method patt_class_expr_fun_args : + formatter -> (Ast.patt * Ast.class_expr) -> unit + + method print_comments_before : + Loc.t -> formatter -> unit + + method private_flag : + formatter -> Ast.meta_bool -> unit + + method virtual_flag : + formatter -> Ast.meta_bool -> unit + + method quoted_string : formatter -> string -> unit + + method raise_match_failure : formatter -> Loc.t -> unit + + method reset : 'a + + method reset_semi : 'a + + method semisep : sep + + method set_comments : bool -> 'a + + method set_curry_constr : bool -> 'a + + method set_loc_and_comments : 'a + + method set_semisep : sep -> 'a + + method simple_ctyp : formatter -> Ast.ctyp -> unit + + method simple_expr : formatter -> Ast.expr -> unit + + method simple_patt : formatter -> Ast.patt -> unit + + method seq : formatter -> Ast.expr -> unit + + method string : formatter -> string -> unit + + method sum_type : formatter -> Ast.ctyp -> unit + + method type_params : formatter -> Ast.ctyp list -> unit + + method class_params : formatter -> Ast.ctyp -> unit + + method under_pipe : 'a + + method under_semi : 'a + + method var : formatter -> string -> unit + + method with_constraint : + formatter -> Ast.with_constr -> unit + + end + + val with_outfile : + string option -> (formatter -> 'a -> unit) -> 'a -> unit + + val print : + string option -> + (printer -> formatter -> 'a -> unit) -> 'a -> unit + + end + + module MakeMore (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax. + Ast).S + + end = + struct + open Format + + module Id = + struct let name = "Camlp4.Printers.OCaml" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + include Syntax + + type sep = (unit, formatter, unit) format + + let pp = fprintf + + let cut f = fprintf f "@ " + + let list' elt sep sep' f = + let rec loop = + function + | [] -> () + | x :: xs -> (pp f sep; elt f x; pp f sep'; loop xs) + in + function + | [] -> () + | [ x ] -> (elt f x; pp f sep') + | x :: xs -> (elt f x; pp f sep'; loop xs) + + let list elt sep f = + let rec loop = + function | [] -> () | x :: xs -> (pp f sep; elt f x; loop xs) + in + function + | [] -> () + | [ x ] -> elt f x + | x :: xs -> (elt f x; loop xs) + + let rec list_of_meta_list = + function + | Ast.LNil -> [] + | Ast.LCons (x, xs) -> x :: (list_of_meta_list xs) + | Ast.LAnt x -> assert false + + let meta_list elt sep f mxs = + let xs = list_of_meta_list mxs in list elt sep f xs + + module CommentFilter = Struct.CommentFilter.Make(Token) + + let comment_filter = CommentFilter.mk () + + let _ = CommentFilter.define (Gram.get_filter ()) comment_filter + + module StringSet = Set.Make(String) + + let infix_lidents = + [ "asr"; "land"; "lor"; "lsl"; "lsr"; "lxor"; "mod"; "or" ] + + let is_infix = + let first_chars = + [ '='; '<'; '>'; '|'; '&'; '$'; '@'; '^'; '+'; '-'; '*'; '/'; + '%'; '\\' ] + and infixes = + List.fold_right StringSet.add infix_lidents StringSet.empty + in + fun s -> + (StringSet.mem s infixes) || + ((s <> "") && (List.mem s.[0] first_chars)) + + let is_keyword = + let keywords = + List.fold_right StringSet.add + [ "and"; "as"; "assert"; "begin"; "class"; "constraint"; + "do"; "done"; "downto"; "else"; "end"; "exception"; + "external"; "false"; "for"; "fun"; "function"; "functor"; + "if"; "in"; "include"; "inherit"; "initializer"; "lazy"; + "let"; "match"; "method"; "module"; "mutable"; "new"; + "object"; "of"; "open"; "parser"; "private"; "rec"; + "sig"; "struct"; "then"; "to"; "true"; "try"; "type"; + "val"; "virtual"; "when"; "while"; "with" ] + StringSet.empty + in fun s -> StringSet.mem s keywords + + module Lexer = Struct.Lexer.Make(Token) + + let _ = let module M = ErrorHandler.Register(Lexer.Error) in () + + open Sig + + let lexer s = + Lexer.from_string ~quotations: !Camlp4_config.quotations Loc. + ghost s + + let lex_string str = + try + let (__strm : _ Stream.t) = lexer str + in + match Stream.peek __strm with + | Some ((tok, _)) -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some ((EOI, _)) -> (Stream.junk __strm; tok) + | _ -> raise (Stream.Error ""))) + | _ -> raise Stream.Failure + with + | Stream.Failure | Stream.Error _ -> + failwith + (sprintf + "Cannot print %S this string contains more than one token" + str) + | Lexer.Error.E exn -> + failwith + (sprintf + "Cannot print %S this identifier does not respect OCaml lexing rules (%s)" + str (Lexer.Error.to_string exn)) + + let ocaml_char = function | "'" -> "\\'" | c -> c + + let rec get_expr_args a al = + match a with + | Ast.ExApp (_, a1, a2) -> get_expr_args a1 (a2 :: al) + | _ -> (a, al) + + let rec get_patt_args a al = + match a with + | Ast.PaApp (_, a1, a2) -> get_patt_args a1 (a2 :: al) + | _ -> (a, al) + + let rec get_ctyp_args a al = + match a with + | Ast.TyApp (_, a1, a2) -> get_ctyp_args a1 (a2 :: al) + | _ -> (a, al) + + let is_irrefut_patt = Ast.is_irrefut_patt + + let rec expr_fun_args = + function + | (Ast.ExFun (_, (Ast.McArr (_, p, (Ast.ExNil _), e))) as ge) + -> + if is_irrefut_patt p + then (let (pl, e) = expr_fun_args e in ((p :: pl), e)) + else ([], ge) + | ge -> ([], ge) + + let rec class_expr_fun_args = + function + | (Ast.CeFun (_, p, ce) as ge) -> + if is_irrefut_patt p + then + (let (pl, ce) = class_expr_fun_args ce in ((p :: pl), ce)) + else ([], ge) + | ge -> ([], ge) + + let rec do_print_comments_before loc f (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some ((comm, comm_loc)) when Loc.strictly_before comm_loc loc + -> + (Stream.junk __strm; + let s = __strm in + let () = f comm comm_loc + in do_print_comments_before loc f s) + | _ -> () + + class printer ?curry_constr:(init_curry_constr = false) + ?(comments = true) () = + object (o) + val pipe = false + + val semi = false + + method under_pipe = {< pipe = true; >} + + method under_semi = {< semi = true; >} + + method reset_semi = {< semi = false; >} + + method reset = {< pipe = false; semi = false; >} + + val semisep = (";;" : sep) + + val andsep = ("@]@ @[<2>and@ " : sep) + + val value_val = "val" + + val value_let = "let" + + val mode = if comments then `comments else `no_comments + + val curry_constr = init_curry_constr + + val var_conversion = false + + method semisep = semisep + + method set_semisep = fun s -> {< semisep = s; >} + + method set_comments = + fun b -> + {< mode = if b then `comments else `no_comments; >} + + method set_loc_and_comments = {< mode = `loc_and_comments; >} + + method set_curry_constr = fun b -> {< curry_constr = b; >} + + method print_comments_before = + fun loc f -> + match mode with + | `comments -> + do_print_comments_before loc + (fun c _ -> pp f "%s@ " c) + (CommentFilter.take_stream comment_filter) + | `loc_and_comments -> + let () = pp f "(*loc: %a*)@ " Loc.dump loc + in + do_print_comments_before loc + (fun s -> pp f "%s(*comm_loc: %a*)@ " s Loc.dump) + (CommentFilter.take_stream comment_filter) + | _ -> () + + method var = + fun f -> + function + | "" -> pp f "$lid:\"\"$" + | "[]" -> pp f "[]" + | "()" -> pp f "()" + | " True" -> pp f "True" + | " False" -> pp f "False" + | v -> + (match (var_conversion, v) with + | (true, "val") -> pp f "contents" + | (true, "True") -> pp f "true" + | (true, "False") -> pp f "false" + | _ -> + (match lex_string v with + | LIDENT s | UIDENT s | ESCAPED_IDENT s when + is_keyword s -> pp f "%s__" s + | LIDENT s | ESCAPED_IDENT s when + List.mem s infix_lidents -> pp f "( %s )" s + | SYMBOL s -> pp f "( %s )" s + | LIDENT s | UIDENT s | ESCAPED_IDENT s -> + pp_print_string f s + | tok -> + failwith + (sprintf + "Bad token used as an identifier: %s" + (Token.to_string tok)))) + + method type_params = + fun f -> + function + | [] -> () + | [ x ] -> pp f "%a@ " o#ctyp x + | l -> pp f "@[<1>(%a)@]@ " (list o#ctyp ",@ ") l + + method class_params = + fun f -> + function + | Ast.TyCom (_, t1, t2) -> + pp f "@[<1>%a,@ %a@]" o#class_params t1 + o#class_params t2 + | x -> o#ctyp f x + + method mutable_flag = fun f b -> o#flag f b "mutable" + + method rec_flag = fun f b -> o#flag f b "rec" + + method virtual_flag = fun f b -> o#flag f b "virtual" + + method private_flag = fun f b -> o#flag f b "private" + + method flag = + fun f b n -> + match b with + | Ast.BTrue -> (pp_print_string f n; pp f "@ ") + | Ast.BFalse -> () + | Ast.BAnt s -> o#anti f s + + method anti = fun f s -> pp f "$%s$" s + + method seq = + fun f -> + function + | Ast.ExSem (_, e1, e2) -> + pp f "%a;@ %a" o#under_semi#seq e1 o#seq e2 + | Ast.ExSeq (_, e) -> o#seq f e + | e -> o#expr f e + + method match_case = + fun f -> + function + | Ast.McNil _loc -> + pp f "@[<2>@ _ ->@ %a@]" o#raise_match_failure _loc + | a -> o#match_case_aux f a + + method match_case_aux = + fun f -> + function + | Ast.McNil _ -> () + | Ast.McAnt (_, s) -> o#anti f s + | Ast.McOr (_, a1, a2) -> + pp f "%a%a" o#match_case_aux a1 o#match_case_aux a2 + | Ast.McArr (_, p, (Ast.ExNil _), e) -> + pp f "@ | @[<2>%a@ ->@ %a@]" o#patt p + o#under_pipe#expr e + | Ast.McArr (_, p, w, e) -> + pp f "@ | @[<2>%a@ when@ %a@ ->@ %a@]" o#patt p + o#under_pipe#expr w o#under_pipe#expr e + + method binding = + fun f bi -> + let () = o#node f bi Ast.loc_of_binding + in + match bi with + | Ast.BiNil _ -> () + | Ast.BiAnd (_, b1, b2) -> + (o#binding f b1; pp f andsep; o#binding f b2) + | Ast.BiEq (_, p, e) -> + let (pl, e) = + (match p with + | Ast.PaTyc (_, _, _) -> ([], e) + | _ -> expr_fun_args e) + in + (match (p, e) with + | (Ast.PaId (_, (Ast.IdLid (_, _))), + Ast.ExTyc (_, e, t)) -> + pp f "%a :@ %a =@ %a" + (list o#simple_patt "@ ") (p :: pl) + o#ctyp t o#expr e + | _ -> + pp f "%a @[<0>%a=@]@ %a" o#simple_patt p + (list' o#simple_patt "" "@ ") pl o#expr e) + | Ast.BiAnt (_, s) -> o#anti f s + + method record_binding = + fun f bi -> + let () = o#node f bi Ast.loc_of_rec_binding + in + match bi with + | Ast.RbNil _ -> () + | Ast.RbEq (_, i, e) -> + pp f "@ @[<2>%a =@ %a@];" o#var_ident i o#expr e + | Ast.RbSem (_, b1, b2) -> + (o#under_semi#record_binding f b1; + o#under_semi#record_binding f b2) + | Ast.RbAnt (_, s) -> o#anti f s + + method mk_patt_list = + function + | Ast.PaApp (_, + (Ast.PaApp (_, (Ast.PaId (_, (Ast.IdUid (_, "::")))), + p1)), + p2) -> + let (pl, c) = o#mk_patt_list p2 in ((p1 :: pl), c) + | Ast.PaId (_, (Ast.IdUid (_, "[]"))) -> ([], None) + | p -> ([], (Some p)) + + method mk_expr_list = + function + | Ast.ExApp (_, + (Ast.ExApp (_, (Ast.ExId (_, (Ast.IdUid (_, "::")))), + e1)), + e2) -> + let (el, c) = o#mk_expr_list e2 in ((e1 :: el), c) + | Ast.ExId (_, (Ast.IdUid (_, "[]"))) -> ([], None) + | e -> ([], (Some e)) + + method expr_list = + fun f -> + function + | [] -> pp f "[]" + | [ e ] -> pp f "[ %a ]" o#under_semi#expr e + | el -> + pp f "@[<2>[ %a@] ]" (list o#under_semi#expr ";@ ") + el + + method expr_list_cons = + fun simple f e -> + let (el, c) = o#mk_expr_list e + in + match c with + | None -> o#expr_list f el + | Some x -> + (if simple + then pp f "@[<2>(%a)@]" + else pp f "@[<2>%a@]") + (list o#under_semi#dot_expr " ::@ ") (el @ [ x ]) + + method patt_expr_fun_args = + fun f (p, e) -> + let (pl, e) = expr_fun_args e + in + pp f "%a@ ->@ %a" (list o#simple_patt "@ ") (p :: pl) + o#expr e + + method patt_class_expr_fun_args = + fun f (p, ce) -> + let (pl, ce) = class_expr_fun_args ce + in + pp f "%a =@]@ %a" (list o#simple_patt "@ ") (p :: pl) + o#class_expr ce + + method constrain = + fun f (t1, t2) -> + pp f "@[<2>constraint@ %a =@ %a@]" o#ctyp t1 o#ctyp t2 + + method sum_type = + fun f t -> + match Ast.list_of_ctyp t [] with + | [] -> () + | ts -> pp f "@[| %a@]" (list o#ctyp "@ | ") ts + + method string = fun f -> pp f "%s" + + method quoted_string = fun f -> pp f "%S" + + method numeric = + fun f num suff -> + if num.[0] = '-' + then pp f "(%s%s)" num suff + else pp f "%s%s" num suff + + method module_expr_get_functor_args = + fun accu -> + function + | Ast.MeFun (_, s, mt, me) -> + o#module_expr_get_functor_args ((s, mt) :: accu) me + | Ast.MeTyc (_, me, mt) -> + ((List.rev accu), me, (Some mt)) + | me -> ((List.rev accu), me, None) + + method functor_args = fun f -> list o#functor_arg "@ " f + + method functor_arg = + fun f (s, mt) -> + pp f "@[<2>(%a :@ %a)@]" o#var s o#module_type mt + + method module_rec_binding = + fun f -> + function + | Ast.MbNil _ -> () + | Ast.MbColEq (_, s, mt, me) -> + pp f "@[<2>%a :@ %a =@ %a@]" o#var s o#module_type mt + o#module_expr me + | Ast.MbCol (_, s, mt) -> + pp f "@[<2>%a :@ %a@]" o#var s o#module_type mt + | Ast.MbAnd (_, mb1, mb2) -> + (o#module_rec_binding f mb1; + pp f andsep; + o#module_rec_binding f mb2) + | Ast.MbAnt (_, s) -> o#anti f s + + method class_declaration = + fun f -> + function + | Ast.CeTyc (_, ce, ct) -> + pp f "%a :@ %a" o#class_expr ce o#class_type ct + | ce -> o#class_expr f ce + + method raise_match_failure = + fun f _loc -> + let n = Loc.file_name _loc in + let l = Loc.start_line _loc in + let c = (Loc.start_off _loc) - (Loc.start_bol _loc) + in + o#expr f + (Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "raise")), + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "Match_failure")), + Ast.ExStr (_loc, Ast.safe_string_escaped n)), + Ast.ExInt (_loc, string_of_int l)), + Ast.ExInt (_loc, string_of_int c)))) + + method node : 'a. formatter -> 'a -> ('a -> Loc.t) -> unit = + fun f node loc_of_node -> + o#print_comments_before (loc_of_node node) f + + method ident = + fun f i -> + let () = o#node f i Ast.loc_of_ident + in + match i with + | Ast.IdAcc (_, i1, i2) -> + pp f "%a.@,%a" o#ident i1 o#ident i2 + | Ast.IdApp (_, i1, i2) -> + pp f "%a@,(%a)" o#ident i1 o#ident i2 + | Ast.IdAnt (_, s) -> o#anti f s + | Ast.IdLid (_, s) | Ast.IdUid (_, s) -> o#var f s + + method private var_ident = {< var_conversion = true; >}#ident + + method expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | (Ast.ExLet (_, _, _, _) | Ast.ExLmd (_, _, _, _) as + e) when semi -> pp f "(%a)" o#reset#expr e + | (Ast.ExMat (_, _, _) | Ast.ExTry (_, _, _) | + Ast.ExFun (_, _) + as e) when pipe || semi -> + pp f "(%a)" o#reset#expr e + | Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "~-")))), + x) -> pp f "@[<2>-@ %a@]" o#dot_expr x + | Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "~-.")))), + x) -> pp f "@[<2>-.@ %a@]" o#dot_expr x + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, (Ast.IdUid (_, "::")))), _)), + _) -> o#expr_list_cons false f e + | Ast.ExApp (_loc, + (Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, n)))), + x)), + y) when is_infix n -> + pp f "@[<2>%a@ %s@ %a@]" o#apply_expr x n + o#apply_expr y + | Ast.ExApp (_, x, y) -> + let (a, al) = get_expr_args x [ y ] + in + if + (not curry_constr) && + (Ast.is_expr_constructor a) + then + (match al with + | [ Ast.ExTup (_, _) ] -> + pp f "@[<2>%a@ (%a)@]" o#apply_expr x + o#expr y + | [ _ ] -> + pp f "@[<2>%a@ %a@]" o#apply_expr x + o#apply_expr y + | al -> + pp f "@[<2>%a@ (%a)@]" o#apply_expr a + (list o#under_pipe#expr ",@ ") al) + else + pp f "@[<2>%a@]" (list o#apply_expr "@ ") + (a :: al) + | Ast.ExAss (_, + (Ast.ExAcc (_, e1, + (Ast.ExId (_, (Ast.IdLid (_, "val")))))), + e2) -> + pp f "@[<2>%a :=@ %a@]" o#dot_expr e1 o#expr e2 + | Ast.ExAss (_, e1, e2) -> + pp f "@[<2>%a@ <-@ %a@]" o#dot_expr e1 o#expr e2 + | Ast.ExFun (loc, (Ast.McNil _)) -> + pp f "@[<2>fun@ _@ ->@ %a@]" o#raise_match_failure + loc + | Ast.ExFun (_, (Ast.McArr (_, p, (Ast.ExNil _), e))) + when is_irrefut_patt p -> + pp f "@[<2>fun@ %a@]" o#patt_expr_fun_args (p, e) + | Ast.ExFun (_, a) -> + pp f "@[function%a@]" o#match_case a + | Ast.ExIfe (_, e1, e2, e3) -> + pp f + "@[@[<2>if@ %a@]@ @[<2>then@ %a@]@ @[<2>else@ %a@]@]" + o#expr e1 o#under_semi#expr e2 o#under_semi#expr + e3 + | Ast.ExLaz (_, e) -> + pp f "@[<2>lazy@ %a@]" o#simple_expr e + | Ast.ExLet (_, r, bi, e) -> + (match e with + | Ast.ExLet (_, _, _, _) -> + pp f "@[<0>@[<2>let %a%a in@]@ %a@]" + o#rec_flag r o#binding bi o#reset_semi#expr + e + | _ -> + pp f + "@[@[<2>let %a%a@]@ @[in@ %a@]@]" + o#rec_flag r o#binding bi o#reset_semi#expr + e) + | Ast.ExMat (_, e, a) -> + pp f "@[@[@[<2>match %a@]@ with@]%a@]" + o#expr e o#match_case a + | Ast.ExTry (_, e, a) -> + pp f "@[<0>@[try@ %a@]@ @[<0>with%a@]@]" + o#expr e o#match_case a + | Ast.ExAsf _ -> pp f "@[<2>assert@ false@]" + | Ast.ExAsr (_, e) -> + pp f "@[<2>assert@ %a@]" o#dot_expr e + | Ast.ExLmd (_, s, me, e) -> + pp f "@[<2>let module %a =@ %a@]@ @[<2>in@ %a@]" + o#var s o#module_expr me o#reset_semi#expr e + | Ast.ExObj (_, (Ast.PaNil _), cst) -> + pp f "@[@[object@ %a@]@ end@]" + o#class_str_item cst + | Ast.ExObj (_, (Ast.PaTyc (_, p, t)), cst) -> + pp f + "@[@[object @[<1>(%a :@ %a)@]@ %a@]@ end@]" + o#patt p o#ctyp t o#class_str_item cst + | Ast.ExObj (_, p, cst) -> + pp f + "@[@[object @[<2>(%a)@]@ %a@]@ end@]" + o#patt p o#class_str_item cst + | e -> o#apply_expr f e + + method apply_expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | Ast.ExNew (_, i) -> pp f "@[<2>new@ %a@]" o#ident i + | e -> o#dot_expr f e + + method dot_expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | Ast.ExAcc (_, e, + (Ast.ExId (_, (Ast.IdLid (_, "val"))))) -> + pp f "@[<2>!@,%a@]" o#simple_expr e + | Ast.ExAcc (_, e1, e2) -> + pp f "@[<2>%a.@,%a@]" o#dot_expr e1 o#dot_expr e2 + | Ast.ExAre (_, e1, e2) -> + pp f "@[<2>%a.@,(%a)@]" o#dot_expr e1 o#expr e2 + | Ast.ExSte (_, e1, e2) -> + pp f "%a.@[<1>[@,%a@]@,]" o#dot_expr e1 o#expr e2 + | Ast.ExSnd (_, e, s) -> + pp f "@[<2>%a#@,%s@]" o#dot_expr e s + | e -> o#simple_expr f e + + method simple_expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | Ast.ExNil _ -> () + | Ast.ExSeq (_, e) -> pp f "@[(%a)@]" o#seq e + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, (Ast.IdUid (_, "::")))), _)), + _) -> o#expr_list_cons true f e + | Ast.ExTup (_, e) -> pp f "@[<1>(%a)@]" o#expr e + | Ast.ExArr (_, e) -> + pp f "@[<0>@[<2>[|@ %a@]@ |]@]" o#under_semi#expr e + | Ast.ExCoe (_, e, (Ast.TyNil _), t) -> + pp f "@[<2>(%a :>@ %a)@]" o#expr e o#ctyp t + | Ast.ExCoe (_, e, t1, t2) -> + pp f "@[<2>(%a :@ %a :>@ %a)@]" o#expr e o#ctyp t1 + o#ctyp t2 + | Ast.ExTyc (_, e, t) -> + pp f "@[<2>(%a :@ %a)@]" o#expr e o#ctyp t + | Ast.ExAnt (_, s) -> o#anti f s + | Ast.ExFor (_, s, e1, e2, df, e3) -> + pp f + "@[@[@[<2>for %a =@ %a@ %a@ %a@ do@]@ %a@]@ done@]" + o#var s o#expr e1 o#direction_flag df o#expr e2 + o#seq e3 + | Ast.ExInt (_, s) -> o#numeric f s "" + | Ast.ExNativeInt (_, s) -> o#numeric f s "n" + | Ast.ExInt64 (_, s) -> o#numeric f s "L" + | Ast.ExInt32 (_, s) -> o#numeric f s "l" + | Ast.ExFlo (_, s) -> o#numeric f s "" + | Ast.ExChr (_, s) -> pp f "'%s'" (ocaml_char s) + | Ast.ExId (_, i) -> o#var_ident f i + | Ast.ExRec (_, b, (Ast.ExNil _)) -> + pp f "@[@[{%a@]@ }@]" o#record_binding b + | Ast.ExRec (_, b, e) -> + pp f "@[@[{@ (%a)@ with%a@]@ }@]" + o#expr e o#record_binding b + | Ast.ExStr (_, s) -> pp f "\"%s\"" s + | Ast.ExWhi (_, e1, e2) -> + pp f "@[<2>while@ %a@ do@ %a@ done@]" o#expr e1 + o#seq e2 + | Ast.ExLab (_, s, (Ast.ExNil _)) -> pp f "~%s" s + | Ast.ExLab (_, s, e) -> + pp f "@[<2>~%s:@ %a@]" s o#dot_expr e + | Ast.ExOlb (_, s, (Ast.ExNil _)) -> pp f "?%s" s + | Ast.ExOlb (_, s, e) -> + pp f "@[<2>?%s:@ %a@]" s o#dot_expr e + | Ast.ExVrn (_, s) -> pp f "`%a" o#var s + | Ast.ExOvr (_, b) -> + pp f "@[@[{<%a@]@ >}@]" o#record_binding + b + | Ast.ExCom (_, e1, e2) -> + pp f "%a,@ %a" o#simple_expr e1 o#simple_expr e2 + | Ast.ExSem (_, e1, e2) -> + pp f "%a;@ %a" o#under_semi#expr e1 o#expr e2 + | Ast.ExApp (_, _, _) | Ast.ExAcc (_, _, _) | + Ast.ExAre (_, _, _) | Ast.ExSte (_, _, _) | + Ast.ExAss (_, _, _) | Ast.ExSnd (_, _, _) | + Ast.ExFun (_, _) | Ast.ExMat (_, _, _) | + Ast.ExTry (_, _, _) | Ast.ExIfe (_, _, _, _) | + Ast.ExLet (_, _, _, _) | Ast.ExLmd (_, _, _, _) | + Ast.ExAsr (_, _) | Ast.ExAsf _ | Ast.ExLaz (_, _) | + Ast.ExNew (_, _) | Ast.ExObj (_, _, _) -> + pp f "(%a)" o#reset#expr e + + method direction_flag = + fun f b -> + match b with + | Ast.BTrue -> pp_print_string f "to" + | Ast.BFalse -> pp_print_string f "downto" + | Ast.BAnt s -> o#anti f s + + method patt = + fun f p -> + let () = o#node f p Ast.loc_of_patt + in + match p with + | Ast.PaAli (_, p1, p2) -> + pp f "@[<1>(%a@ as@ %a)@]" o#patt p1 o#patt p2 + | Ast.PaEq (_, i, p) -> + pp f "@[<2>%a =@ %a@]" o#var_ident i o#patt p + | Ast.PaSem (_, p1, p2) -> + pp f "%a;@ %a" o#patt p1 o#patt p2 + | p -> o#patt1 f p + + method patt1 = + fun f -> + function + | Ast.PaOrp (_, p1, p2) -> + pp f "@[<2>%a@ |@ %a@]" o#patt1 p1 o#patt2 p2 + | p -> o#patt2 f p + + method patt2 = fun f p -> o#patt3 f p + + method patt3 = + fun f -> + function + | Ast.PaRng (_, p1, p2) -> + pp f "@[<2>%a@ ..@ %a@]" o#patt3 p1 o#patt4 p2 + | Ast.PaCom (_, p1, p2) -> + pp f "%a,@ %a" o#patt3 p1 o#patt3 p2 + | p -> o#patt4 f p + + method patt4 = + fun f -> + function + | (Ast.PaApp (_, + (Ast.PaApp (_, + (Ast.PaId (_, (Ast.IdUid (_, "::")))), _)), + _) + as p) -> + let (pl, c) = o#mk_patt_list p + in + (match c with + | None -> + pp f "@[<2>[@ %a@]@ ]" (list o#patt ";@ ") pl + | Some x -> + pp f "@[<2>%a@]" (list o#patt5 " ::@ ") + (pl @ [ x ])) + | p -> o#patt5 f p + + method patt5 = + fun f -> + function + | (Ast.PaApp (_, + (Ast.PaApp (_, + (Ast.PaId (_, (Ast.IdUid (_, "::")))), _)), + _) + as p) -> o#simple_patt f p + | Ast.PaLaz (_, p) -> + pp f "@[<2>lazy %a@]" o#simple_patt p + | Ast.PaApp (_, x, y) -> + let (a, al) = get_patt_args x [ y ] + in + if not (Ast.is_patt_constructor a) + then + Format.eprintf + "WARNING: strange pattern application of a non constructor@." + else + if curry_constr + then + pp f "@[<2>%a@]" (list o#simple_patt "@ ") + (a :: al) + else + (match al with + | [ Ast.PaTup (_, _) ] -> + pp f "@[<2>%a@ (%a)@]" o#simple_patt x + o#patt y + | [ _ ] -> + pp f "@[<2>%a@ %a@]" o#patt5 x + o#simple_patt y + | al -> + pp f "@[<2>%a@ (%a)@]" o#patt5 a + (list o#simple_patt ",@ ") al) + | p -> o#simple_patt f p + + method simple_patt = + fun f p -> + let () = o#node f p Ast.loc_of_patt + in + match p with + | Ast.PaNil _ -> () + | Ast.PaId (_, i) -> o#var_ident f i + | Ast.PaAnt (_, s) -> o#anti f s + | Ast.PaAny _ -> pp f "_" + | Ast.PaTup (_, p) -> pp f "@[<1>(%a)@]" o#patt3 p + | Ast.PaRec (_, p) -> pp f "@[{@ %a@]@ }" o#patt p + | Ast.PaStr (_, s) -> pp f "\"%s\"" s + | Ast.PaTyc (_, p, t) -> + pp f "@[<1>(%a :@ %a)@]" o#patt p o#ctyp t + | Ast.PaNativeInt (_, s) -> o#numeric f s "n" + | Ast.PaInt64 (_, s) -> o#numeric f s "L" + | Ast.PaInt32 (_, s) -> o#numeric f s "l" + | Ast.PaInt (_, s) -> o#numeric f s "" + | Ast.PaFlo (_, s) -> o#numeric f s "" + | Ast.PaChr (_, s) -> pp f "'%s'" (ocaml_char s) + | Ast.PaLab (_, s, (Ast.PaNil _)) -> pp f "~%s" s + | Ast.PaVrn (_, s) -> pp f "`%a" o#var s + | Ast.PaTyp (_, i) -> pp f "@[<2>#%a@]" o#ident i + | Ast.PaArr (_, p) -> pp f "@[<2>[|@ %a@]@ |]" o#patt p + | Ast.PaLab (_, s, p) -> + pp f "@[<2>~%s:@ (%a)@]" s o#patt p + | Ast.PaOlb (_, s, (Ast.PaNil _)) -> pp f "?%s" s + | Ast.PaOlb (_, "", p) -> + pp f "@[<2>?(%a)@]" o#patt_tycon p + | Ast.PaOlb (_, s, p) -> + pp f "@[<2>?%s:@,@[<1>(%a)@]@]" s o#patt_tycon p + | Ast.PaOlbi (_, "", p, e) -> + pp f "@[<2>?(%a =@ %a)@]" o#patt_tycon p o#expr e + | Ast.PaOlbi (_, s, p, e) -> + pp f "@[<2>?%s:@,@[<1>(%a =@ %a)@]@]" s + o#patt_tycon p o#expr e + | (Ast.PaApp (_, _, _) | Ast.PaAli (_, _, _) | + Ast.PaOrp (_, _, _) | Ast.PaRng (_, _, _) | + Ast.PaCom (_, _, _) | Ast.PaSem (_, _, _) | + Ast.PaEq (_, _, _) | Ast.PaLaz (_, _) + as p) -> pp f "@[<1>(%a)@]" o#patt p + + method patt_tycon = + fun f -> + function + | Ast.PaTyc (_, p, t) -> + pp f "%a :@ %a" o#patt p o#ctyp t + | p -> o#patt f p + + method simple_ctyp = + fun f t -> + let () = o#node f t Ast.loc_of_ctyp + in + match t with + | Ast.TyId (_, i) -> o#ident f i + | Ast.TyAnt (_, s) -> o#anti f s + | Ast.TyAny _ -> pp f "_" + | Ast.TyLab (_, s, t) -> + pp f "@[<2>%s:@ %a@]" s o#simple_ctyp t + | Ast.TyOlb (_, s, t) -> + pp f "@[<2>?%s:@ %a@]" s o#simple_ctyp t + | Ast.TyObj (_, (Ast.TyNil _), Ast.BFalse) -> + pp f "< >" + | Ast.TyObj (_, (Ast.TyNil _), Ast.BTrue) -> + pp f "< .. >" + | Ast.TyObj (_, t, Ast.BTrue) -> + pp f "@[<0>@[<2><@ %a;@ ..@]@ >@]" o#ctyp t + | Ast.TyObj (_, t, Ast.BFalse) -> + pp f "@[<0>@[<2><@ %a@]@ >@]" o#ctyp t + | Ast.TyQuo (_, s) -> pp f "'%a" o#var s + | Ast.TyRec (_, t) -> pp f "@[<2>{@ %a@]@ }" o#ctyp t + | Ast.TySum (_, t) -> pp f "@[<0>%a@]" o#sum_type t + | Ast.TyTup (_, t) -> pp f "@[<1>(%a)@]" o#ctyp t + | Ast.TyVrnEq (_, t) -> + pp f "@[<2>[@ %a@]@ ]" o#sum_type t + | Ast.TyVrnInf (_, t) -> + pp f "@[<2>[<@ %a@]@,]" o#sum_type t + | Ast.TyVrnInfSup (_, t1, t2) -> + let (a, al) = get_ctyp_args t2 [] + in + pp f "@[<2>[<@ %a@ >@ %a@]@ ]" o#sum_type t1 + (list o#simple_ctyp "@ ") (a :: al) + | Ast.TyVrnSup (_, t) -> + pp f "@[<2>[>@ %a@]@,]" o#sum_type t + | Ast.TyCls (_, i) -> pp f "@[<2>#%a@]" o#ident i + | Ast.TyMan (_, t1, t2) -> + pp f "@[<2>%a =@ %a@]" o#simple_ctyp t1 + o#simple_ctyp t2 + | Ast.TyVrn (_, s) -> pp f "`%a" o#var s + | Ast.TySta (_, t1, t2) -> + pp f "%a *@ %a" o#simple_ctyp t1 o#simple_ctyp t2 + | Ast.TyNil _ -> assert false + | t -> pp f "@[<1>(%a)@]" o#ctyp t + + method ctyp = + fun f t -> + let () = o#node f t Ast.loc_of_ctyp + in + match t with + | Ast.TyAli (_, t1, t2) -> + pp f "@[<2>%a@ as@ %a@]" o#simple_ctyp t1 + o#simple_ctyp t2 + | Ast.TyArr (_, t1, t2) -> + pp f "@[<2>%a@ ->@ %a@]" o#ctyp1 t1 o#ctyp t2 + | Ast.TyQuP (_, s) -> pp f "+'%a" o#var s + | Ast.TyQuM (_, s) -> pp f "-'%a" o#var s + | Ast.TyOr (_, t1, t2) -> + pp f "%a@ | %a" o#ctyp t1 o#ctyp t2 + | Ast.TyCol (_, t1, (Ast.TyMut (_, t2))) -> + pp f "@[mutable@ %a :@ %a@]" o#ctyp t1 o#ctyp t2 + | Ast.TyCol (_, t1, t2) -> + pp f "@[<2>%a :@ %a@]" o#ctyp t1 o#ctyp t2 + | Ast.TySem (_, t1, t2) -> + pp f "%a;@ %a" o#ctyp t1 o#ctyp t2 + | Ast.TyOf (_, t, (Ast.TyNil _)) -> o#ctyp f t + | Ast.TyOf (_, t1, t2) -> + pp f "@[%a@ @[<3>of@ %a@]@]" o#ctyp t1 + o#constructor_type t2 + | Ast.TyOfAmp (_, t1, t2) -> + pp f "@[%a@ @[<3>of &@ %a@]@]" o#ctyp t1 + o#constructor_type t2 + | Ast.TyAnd (_, t1, t2) -> + pp f "%a@ and %a" o#ctyp t1 o#ctyp t2 + | Ast.TyMut (_, t) -> + pp f "@[<2>mutable@ %a@]" o#ctyp t + | Ast.TyAmp (_, t1, t2) -> + pp f "%a@ &@ %a" o#ctyp t1 o#ctyp t2 + | Ast.TyDcl (_, tn, tp, te, cl) -> + (pp f "@[<2>%a%a@]" o#type_params tp o#var tn; + (match te with + | Ast.TyNil _ -> () + | _ -> pp f " =@ %a" o#ctyp te); + if cl <> [] + then pp f "@ %a" (list o#constrain "@ ") cl + else ()) + | t -> o#ctyp1 f t + + method ctyp1 = + fun f -> + function + | Ast.TyApp (_, t1, t2) -> + (match get_ctyp_args t1 [ t2 ] with + | (_, [ _ ]) -> + pp f "@[<2>%a@ %a@]" o#simple_ctyp t2 + o#simple_ctyp t1 + | (a, al) -> + pp f "@[<2>(%a)@ %a@]" (list o#ctyp ",@ ") al + o#simple_ctyp a) + | Ast.TyPol (_, t1, t2) -> + let (a, al) = get_ctyp_args t1 [] + in + pp f "@[<2>%a.@ %a@]" (list o#ctyp "@ ") (a :: al) + o#ctyp t2 + | Ast.TyPrv (_, t) -> + pp f "@[private@ %a@]" o#simple_ctyp t + | t -> o#simple_ctyp f t + + method constructor_type = + fun f t -> + match t with + | Ast.TyAnd (loc, t1, t2) -> + let () = o#node f t (fun _ -> loc) + in + pp f "%a@ * %a" o#constructor_type t1 + o#constructor_type t2 + | Ast.TyArr (_, _, _) -> pp f "(%a)" o#ctyp t + | t -> o#ctyp f t + + method sig_item = + fun f sg -> + let () = o#node f sg Ast.loc_of_sig_item + in + match sg with + | Ast.SgNil _ -> () + | Ast.SgSem (_, sg, (Ast.SgNil _)) | + Ast.SgSem (_, (Ast.SgNil _), sg) -> o#sig_item f sg + | Ast.SgSem (_, sg1, sg2) -> + (o#sig_item f sg1; cut f; o#sig_item f sg2) + | Ast.SgExc (_, t) -> + pp f "@[<2>exception@ %a%(%)@]" o#ctyp t semisep + | Ast.SgExt (_, s, t, sl) -> + pp f "@[<2>external@ %a :@ %a =@ %a%(%)@]" + o#var s o#ctyp t (meta_list o#quoted_string "@ ") + sl semisep + | Ast.SgMod (_, s1, (Ast.MtFun (_, s2, mt1, mt2))) -> + let rec loop accu = + (function + | Ast.MtFun (_, s, mt1, mt2) -> + loop ((s, mt1) :: accu) mt2 + | mt -> ((List.rev accu), mt)) in + let (al, mt) = loop [ (s2, mt1) ] mt2 + in + pp f "@[<2>module %a@ @[<0>%a@] :@ %a%(%)@]" + o#var s1 o#functor_args al o#module_type mt + semisep + | Ast.SgMod (_, s, mt) -> + pp f "@[<2>module %a :@ %a%(%)@]" o#var s + o#module_type mt semisep + | Ast.SgMty (_, s, (Ast.MtNil _)) -> + pp f "@[<2>module type %a%(%)@]" o#var s semisep + | Ast.SgMty (_, s, mt) -> + pp f "@[<2>module type %a =@ %a%(%)@]" o#var s + o#module_type mt semisep + | Ast.SgOpn (_, sl) -> + pp f "@[<2>open@ %a%(%)@]" o#ident sl semisep + | Ast.SgTyp (_, t) -> + pp f "@[@[type %a@]%(%)@]" o#ctyp t + semisep + | Ast.SgVal (_, s, t) -> + pp f "@[<2>%s %a :@ %a%(%)@]" value_val o#var s + o#ctyp t semisep + | Ast.SgInc (_, mt) -> + pp f "@[<2>include@ %a%(%)@]" o#module_type mt + semisep + | Ast.SgClt (_, ct) -> + pp f "@[<2>class type %a%(%)@]" o#class_type ct + semisep + | Ast.SgCls (_, ce) -> + pp f "@[<2>class %a%(%)@]" o#class_type ce semisep + | Ast.SgRecMod (_, mb) -> + pp f "@[<2>module rec %a%(%)@]" + o#module_rec_binding mb semisep + | Ast.SgDir (_, _, _) -> () + | Ast.SgAnt (_, s) -> pp f "%a%(%)" o#anti s semisep + + method str_item = + fun f st -> + let () = o#node f st Ast.loc_of_str_item + in + match st with + | Ast.StNil _ -> () + | Ast.StSem (_, st, (Ast.StNil _)) | + Ast.StSem (_, (Ast.StNil _), st) -> o#str_item f st + | Ast.StSem (_, st1, st2) -> + (o#str_item f st1; cut f; o#str_item f st2) + | Ast.StExc (_, t, Ast.ONone) -> + pp f "@[<2>exception@ %a%(%)@]" o#ctyp t semisep + | Ast.StExc (_, t, (Ast.OSome sl)) -> + pp f "@[<2>exception@ %a =@ %a%(%)@]" o#ctyp t + o#ident sl semisep + | Ast.StExt (_, s, t, sl) -> + pp f "@[<2>external@ %a :@ %a =@ %a%(%)@]" + o#var s o#ctyp t (meta_list o#quoted_string "@ ") + sl semisep + | Ast.StMod (_, s1, (Ast.MeFun (_, s2, mt1, me))) -> + (match o#module_expr_get_functor_args [ (s2, mt1) ] + me + with + | (al, me, Some mt2) -> + pp f + "@[<2>module %a@ @[<0>%a@] :@ %a =@ %a%(%)@]" + o#var s1 o#functor_args al o#module_type mt2 + o#module_expr me semisep + | (al, me, _) -> + pp f "@[<2>module %a@ @[<0>%a@] =@ %a%(%)@]" + o#var s1 o#functor_args al o#module_expr me + semisep) + | Ast.StMod (_, s, (Ast.MeTyc (_, me, mt))) -> + pp f "@[<2>module %a :@ %a =@ %a%(%)@]" o#var s + o#module_type mt o#module_expr me semisep + | Ast.StMod (_, s, me) -> + pp f "@[<2>module %a =@ %a%(%)@]" o#var s + o#module_expr me semisep + | Ast.StMty (_, s, mt) -> + pp f "@[<2>module type %a =@ %a%(%)@]" o#var s + o#module_type mt semisep + | Ast.StOpn (_, sl) -> + pp f "@[<2>open@ %a%(%)@]" o#ident sl semisep + | Ast.StTyp (_, t) -> + pp f "@[@[type %a@]%(%)@]" o#ctyp t + semisep + | Ast.StVal (_, r, bi) -> + pp f "@[<2>%s %a%a%(%)@]" value_let o#rec_flag r + o#binding bi semisep + | Ast.StExp (_, e) -> + pp f "@[<2>let _ =@ %a%(%)@]" o#expr e semisep + | Ast.StInc (_, me) -> + pp f "@[<2>include@ %a%(%)@]" o#simple_module_expr + me semisep + | Ast.StClt (_, ct) -> + pp f "@[<2>class type %a%(%)@]" o#class_type ct + semisep + | Ast.StCls (_, ce) -> + pp f "@[class %a%(%)@]" o#class_declaration ce + semisep + | Ast.StRecMod (_, mb) -> + pp f "@[<2>module rec %a%(%)@]" + o#module_rec_binding mb semisep + | Ast.StDir (_, _, _) -> () + | Ast.StAnt (_, s) -> pp f "%a%(%)" o#anti s semisep + | Ast.StExc (_, _, (Ast.OAnt _)) -> assert false + + method module_type = + fun f mt -> + let () = o#node f mt Ast.loc_of_module_type + in + match mt with + | Ast.MtNil _ -> assert false + | Ast.MtId (_, i) -> o#ident f i + | Ast.MtAnt (_, s) -> o#anti f s + | Ast.MtFun (_, s, mt1, mt2) -> + pp f "@[<2>functor@ @[<1>(%a :@ %a)@]@ ->@ %a@]" + o#var s o#module_type mt1 o#module_type mt2 + | Ast.MtQuo (_, s) -> pp f "'%a" o#var s + | Ast.MtSig (_, sg) -> + pp f "@[@[sig@ %a@]@ end@]" o#sig_item sg + | Ast.MtWit (_, mt, wc) -> + pp f "@[<2>%a@ with@ %a@]" o#module_type mt + o#with_constraint wc + + method with_constraint = + fun f wc -> + let () = o#node f wc Ast.loc_of_with_constr + in + match wc with + | Ast.WcNil _ -> () + | Ast.WcTyp (_, t1, t2) -> + pp f "@[<2>type@ %a =@ %a@]" o#ctyp t1 o#ctyp t2 + | Ast.WcMod (_, i1, i2) -> + pp f "@[<2>module@ %a =@ %a@]" o#ident i1 o#ident + i2 + | Ast.WcAnd (_, wc1, wc2) -> + (o#with_constraint f wc1; + pp f andsep; + o#with_constraint f wc2) + | Ast.WcAnt (_, s) -> o#anti f s + + method module_expr = + fun f me -> + let () = o#node f me Ast.loc_of_module_expr + in + match me with + | Ast.MeNil _ -> assert false + | Ast.MeTyc (_, (Ast.MeStr (_, st)), + (Ast.MtSig (_, sg))) -> + pp f + "@[<2>@[struct@ %a@]@ end :@ @[sig@ %a@]@ end@]" + o#str_item st o#sig_item sg + | _ -> o#simple_module_expr f me + + method simple_module_expr = + fun f me -> + let () = o#node f me Ast.loc_of_module_expr + in + match me with + | Ast.MeNil _ -> assert false + | Ast.MeId (_, i) -> o#ident f i + | Ast.MeAnt (_, s) -> o#anti f s + | Ast.MeApp (_, me1, me2) -> + pp f "@[<2>%a@,(%a)@]" o#module_expr me1 + o#module_expr me2 + | Ast.MeFun (_, s, mt, me) -> + pp f "@[<2>functor@ @[<1>(%a :@ %a)@]@ ->@ %a@]" + o#var s o#module_type mt o#module_expr me + | Ast.MeStr (_, st) -> + pp f "@[@[struct@ %a@]@ end@]" o#str_item + st + | Ast.MeTyc (_, me, mt) -> + pp f "@[<1>(%a :@ %a)@]" o#module_expr me + o#module_type mt + + method class_expr = + fun f ce -> + let () = o#node f ce Ast.loc_of_class_expr + in + match ce with + | Ast.CeApp (_, ce, e) -> + pp f "@[<2>%a@ %a@]" o#class_expr ce o#expr e + | Ast.CeCon (_, Ast.BFalse, i, (Ast.TyNil _)) -> + pp f "@[<2>%a@]" o#ident i + | Ast.CeCon (_, Ast.BFalse, i, t) -> + pp f "@[<2>@[<1>[%a]@]@ %a@]" o#class_params t + o#ident i + | Ast.CeCon (_, Ast.BTrue, (Ast.IdLid (_, i)), + (Ast.TyNil _)) -> pp f "@[<2>virtual@ %a@]" o#var i + | Ast.CeCon (_, Ast.BTrue, (Ast.IdLid (_, i)), t) -> + pp f "@[<2>virtual@ @[<1>[%a]@]@ %a@]" + o#class_params t o#var i + | Ast.CeFun (_, p, ce) -> + pp f "@[<2>fun@ %a@ ->@ %a@]" o#simple_patt p + o#class_expr ce + | Ast.CeLet (_, r, bi, ce) -> + pp f "@[<2>let %a%a@]@ @[<2>in@ %a@]" o#rec_flag r + o#binding bi o#class_expr ce + | Ast.CeStr (_, (Ast.PaNil _), cst) -> + pp f "@[@[object %a@]@ end@]" + o#class_str_item cst + | Ast.CeStr (_, p, cst) -> + pp f + "@[@[object @[<1>(%a)@]@ %a@]@ end@]" + o#patt p o#class_str_item cst + | Ast.CeTyc (_, ce, ct) -> + pp f "@[<1>(%a :@ %a)@]" o#class_expr ce + o#class_type ct + | Ast.CeAnt (_, s) -> o#anti f s + | Ast.CeAnd (_, ce1, ce2) -> + (o#class_expr f ce1; + pp f andsep; + o#class_expr f ce2) + | Ast.CeEq (_, ce1, (Ast.CeFun (_, p, ce2))) when + is_irrefut_patt p -> + pp f "@[<2>%a@ %a" o#class_expr ce1 + o#patt_class_expr_fun_args (p, ce2) + | Ast.CeEq (_, ce1, ce2) -> + pp f "@[<2>%a =@]@ %a" o#class_expr ce1 + o#class_expr ce2 + | _ -> assert false + + method class_type = + fun f ct -> + let () = o#node f ct Ast.loc_of_class_type + in + match ct with + | Ast.CtCon (_, Ast.BFalse, i, (Ast.TyNil _)) -> + pp f "@[<2>%a@]" o#ident i + | Ast.CtCon (_, Ast.BFalse, i, t) -> + pp f "@[<2>[@,%a@]@,]@ %a" o#class_params t + o#ident i + | Ast.CtCon (_, Ast.BTrue, (Ast.IdLid (_, i)), + (Ast.TyNil _)) -> pp f "@[<2>virtual@ %a@]" o#var i + | Ast.CtCon (_, Ast.BTrue, (Ast.IdLid (_, i)), t) -> + pp f "@[<2>virtual@ [@,%a@]@,]@ %a" o#class_params + t o#var i + | Ast.CtFun (_, t, ct) -> + pp f "@[<2>%a@ ->@ %a@]" o#simple_ctyp t + o#class_type ct + | Ast.CtSig (_, (Ast.TyNil _), csg) -> + pp f "@[@[object@ %a@]@ end@]" + o#class_sig_item csg + | Ast.CtSig (_, t, csg) -> + pp f + "@[@[object @[<1>(%a)@]@ %a@]@ end@]" + o#ctyp t o#class_sig_item csg + | Ast.CtAnt (_, s) -> o#anti f s + | Ast.CtAnd (_, ct1, ct2) -> + (o#class_type f ct1; + pp f andsep; + o#class_type f ct2) + | Ast.CtCol (_, ct1, ct2) -> + pp f "%a :@ %a" o#class_type ct1 o#class_type ct2 + | Ast.CtEq (_, ct1, ct2) -> + pp f "%a =@ %a" o#class_type ct1 o#class_type ct2 + | _ -> assert false + + method class_sig_item = + fun f csg -> + let () = o#node f csg Ast.loc_of_class_sig_item + in + match csg with + | Ast.CgNil _ -> () + | Ast.CgSem (_, csg, (Ast.CgNil _)) | + Ast.CgSem (_, (Ast.CgNil _), csg) -> + o#class_sig_item f csg + | Ast.CgSem (_, csg1, csg2) -> + (o#class_sig_item f csg1; + cut f; + o#class_sig_item f csg2) + | Ast.CgCtr (_, t1, t2) -> + pp f "@[<2>constraint@ %a =@ %a%(%)@]" o#ctyp t1 + o#ctyp t2 semisep + | Ast.CgInh (_, ct) -> + pp f "@[<2>inherit@ %a%(%)@]" o#class_type ct + semisep + | Ast.CgMth (_, s, pr, t) -> + pp f "@[<2>method %a%a :@ %a%(%)@]" o#private_flag + pr o#var s o#ctyp t semisep + | Ast.CgVir (_, s, pr, t) -> + pp f "@[<2>method virtual %a%a :@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t semisep + | Ast.CgVal (_, s, mu, vi, t) -> + pp f "@[<2>%s %a%a%a :@ %a%(%)@]" value_val + o#mutable_flag mu o#virtual_flag vi o#var s + o#ctyp t semisep + | Ast.CgAnt (_, s) -> pp f "%a%(%)" o#anti s semisep + + method class_str_item = + fun f cst -> + let () = o#node f cst Ast.loc_of_class_str_item + in + match cst with + | Ast.CrNil _ -> () + | Ast.CrSem (_, cst, (Ast.CrNil _)) | + Ast.CrSem (_, (Ast.CrNil _), cst) -> + o#class_str_item f cst + | Ast.CrSem (_, cst1, cst2) -> + (o#class_str_item f cst1; + cut f; + o#class_str_item f cst2) + | Ast.CrCtr (_, t1, t2) -> + pp f "@[<2>constraint %a =@ %a%(%)@]" o#ctyp t1 + o#ctyp t2 semisep + | Ast.CrInh (_, ce, "") -> + pp f "@[<2>inherit@ %a%(%)@]" o#class_expr ce + semisep + | Ast.CrInh (_, ce, s) -> + pp f "@[<2>inherit@ %a as@ %a%(%)@]" o#class_expr + ce o#var s semisep + | Ast.CrIni (_, e) -> + pp f "@[<2>initializer@ %a%(%)@]" o#expr e semisep + | Ast.CrMth (_, s, pr, e, (Ast.TyNil _)) -> + pp f "@[<2>method %a%a =@ %a%(%)@]" o#private_flag + pr o#var s o#expr e semisep + | Ast.CrMth (_, s, pr, e, t) -> + pp f "@[<2>method %a%a :@ %a =@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t o#expr e + semisep + | Ast.CrVir (_, s, pr, t) -> + pp f "@[<2>method virtual@ %a%a :@ %a%(%)@]" + o#private_flag pr o#var s o#ctyp t semisep + | Ast.CrVvr (_, s, mu, t) -> + pp f "@[<2>%s virtual %a%a :@ %a%(%)@]" value_val + o#mutable_flag mu o#var s o#ctyp t semisep + | Ast.CrVal (_, s, mu, e) -> + pp f "@[<2>%s %a%a =@ %a%(%)@]" value_val + o#mutable_flag mu o#var s o#expr e semisep + | Ast.CrAnt (_, s) -> pp f "%a%(%)" o#anti s semisep + + method implem = + fun f st -> + match st with + | Ast.StExp (_, e) -> + pp f "@[<0>%a%(%)@]@." o#expr e semisep + | st -> pp f "@[%a@]@." o#str_item st + + method interf = fun f sg -> pp f "@[%a@]@." o#sig_item sg + + end + + let with_outfile output_file fct arg = + let call close f = + ((try fct f arg with | exn -> (close (); raise exn)); + close ()) + in + match output_file with + | None -> call (fun () -> ()) std_formatter + | Some s -> + let oc = open_out s in + let f = formatter_of_out_channel oc + in call (fun () -> close_out oc) f + + let print output_file fct = + let o = new printer () in with_outfile output_file (fct o) + + let print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg + + let print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st + + end + + module MakeMore (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax. + Ast).S = + struct + include Make(Syntax) + + let semisep : sep ref = ref ("@\n" : sep) + + let margin = ref 78 + + let comments = ref true + + let locations = ref false + + let curry_constr = ref false + + let print output_file fct = + let o = + new printer ~comments: !comments ~curry_constr: !curry_constr + () in + let o = o#set_semisep !semisep in + let o = if !locations then o#set_loc_and_comments else o + in + with_outfile output_file + (fun f -> + let () = Format.pp_set_margin f !margin + in Format.fprintf f "@[%a@]@." (fct o)) + + let print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg + + let print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st + + let check_sep s = + if String.contains s '%' + then failwith "-sep Format error, % found in string" + else (Obj.magic (Struct.Token.Eval.string s : string) : sep) + + let _ = + Options.add "-l" (Arg.Int (fun i -> margin := i)) + " line length for pretty printing." + + let _ = + Options.add "-ss" (Arg.Unit (fun () -> semisep := ";;")) + " Print double semicolons." + + let _ = + Options.add "-no_ss" (Arg.Unit (fun () -> semisep := "")) + " Do not print double semicolons (default)." + + let _ = + Options.add "-sep" + (Arg.String (fun s -> semisep := check_sep s)) + " Use this string between phrases." + + let _ = + Options.add "-curry-constr" (Arg.Set curry_constr) + "Use currified constructors." + + let _ = + Options.add "-no_comments" (Arg.Clear comments) + "Do not add comments." + + let _ = + Options.add "-add_locations" (Arg.Set locations) + "Add locations as comment." + + end + + end + + module OCamlr : + sig + module Id : Sig.Id + + module Make (Syntax : Sig.Camlp4Syntax) : + sig + open Format + + include Sig.Camlp4Syntax with module Loc = Syntax.Loc + and module Token = Syntax.Token and module Ast = Syntax.Ast + and module Gram = Syntax.Gram + + class printer : + ?curry_constr: bool -> + ?comments: bool -> + unit -> object ('a) inherit OCaml.Make(Syntax).printer + end + + val with_outfile : + string option -> (formatter -> 'a -> unit) -> 'a -> unit + + val print : + string option -> + (printer -> formatter -> 'a -> unit) -> 'a -> unit + + end + + module MakeMore (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax. + Ast).S + + end = + struct + open Format + + module Id = + struct let name = "Camlp4.Printers.OCamlr" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + include Syntax + + open Sig + + module PP_o = OCaml.Make(Syntax) + + open PP_o + + let pp = fprintf + + let is_keyword = + let keywords = [ "where" ] + and not_keywords = [ "false"; "function"; "true"; "val" ] + in + fun s -> + (not (List.mem s not_keywords)) && + ((is_keyword s) || (List.mem s keywords)) + + class printer ?curry_constr:(init_curry_constr = true) + ?(comments = true) () = + object (o) + inherit + PP_o.printer ~curry_constr: init_curry_constr ~comments () as + super + + val semisep = (";" : sep) + + val andsep = ("@]@ @[<2>and@ " : sep) + + val value_val = "value" + + val value_let = "value" + + val mode = if comments then `comments else `no_comments + + val curry_constr = init_curry_constr + + val first_match_case = true + + method under_pipe = o + + method under_semi = o + + method reset_semi = o + + method reset = o + + method private unset_first_match_case = + {< first_match_case = false; >} + + method private set_first_match_case = + {< first_match_case = true; >} + + method seq = + fun f e -> + let rec self right f e = + let go_right = self right + and go_left = self false + in + match e with + | Ast.ExLet (_, r, bi, e1) -> + if right + then + pp f "@[<2>let %a%a@];@ %a" o#rec_flag r + o#binding bi go_right e1 + else pp f "(%a)" o#expr e + | Ast.ExSeq (_, e) -> go_right f e + | Ast.ExSem (_, e1, e2) -> + (pp f "%a;@ " go_left e1; + (match (right, e2) with + | (true, Ast.ExLet (_, r, bi, e3)) -> + pp f "@[<2>let %a%a@];@ %a" o#rec_flag r + o#binding bi go_right e3 + | _ -> go_right f e2)) + | e -> o#expr f e + in self true f e + + method var = + fun f -> + function + | "" -> pp f "$lid:\"\"$" + | "[]" -> pp f "[]" + | "()" -> pp f "()" + | " True" -> pp f "True" + | " False" -> pp f "False" + | v -> + (match lex_string v with + | LIDENT s | UIDENT s | ESCAPED_IDENT s when + is_keyword s -> pp f "%s__" s + | SYMBOL s -> pp f "( %s )" s + | LIDENT s | UIDENT s | ESCAPED_IDENT s -> + pp_print_string f s + | tok -> + failwith + (sprintf "Bad token used as an identifier: %s" + (Token.to_string tok))) + + method type_params = + fun f -> + function + | [] -> () + | [ x ] -> pp f "@ %a" o#ctyp x + | l -> pp f "@ @[<1>%a@]" (list o#ctyp "@ ") l + + method match_case = + fun f -> + function + | Ast.McNil _ -> pp f "@ []" + | m -> + pp f "@ [ %a ]" o#set_first_match_case#match_case_aux + m + + method match_case_aux = + fun f -> + function + | Ast.McNil _ -> () + | Ast.McAnt (_, s) -> o#anti f s + | Ast.McOr (_, a1, a2) -> + pp f "%a%a" o#match_case_aux a1 + o#unset_first_match_case#match_case_aux a2 + | Ast.McArr (_, p, (Ast.ExNil _), e) -> + let () = if first_match_case then () else pp f "@ | " + in + pp f "@[<2>%a@ ->@ %a@]" o#patt p o#under_pipe#expr + e + | Ast.McArr (_, p, w, e) -> + let () = if first_match_case then () else pp f "@ | " + in + pp f "@[<2>%a@ when@ %a@ ->@ %a@]" o#patt p + o#under_pipe#expr w o#under_pipe#expr e + + method sum_type = fun f t -> pp f "@[[ %a ]@]" o#ctyp t + + method ident = + fun f i -> + let () = o#node f i Ast.loc_of_ident + in + match i with + | Ast.IdApp (_, i1, i2) -> + pp f "%a@ %a" o#dot_ident i1 o#dot_ident i2 + | i -> o#dot_ident f i + + method private dot_ident = + fun f i -> + let () = o#node f i Ast.loc_of_ident + in + match i with + | Ast.IdAcc (_, i1, i2) -> + pp f "%a.@,%a" o#dot_ident i1 o#dot_ident i2 + | Ast.IdAnt (_, s) -> o#anti f s + | Ast.IdLid (_, s) | Ast.IdUid (_, s) -> o#var f s + | i -> pp f "(%a)" o#ident i + + method patt4 = + fun f -> + function + | (Ast.PaApp (_, + (Ast.PaApp (_, + (Ast.PaId (_, (Ast.IdUid (_, "::")))), _)), + _) + as p) -> + let (pl, c) = o#mk_patt_list p + in + (match c with + | None -> + pp f "@[<2>[@ %a@]@ ]" (list o#patt ";@ ") pl + | Some x -> + pp f "@[<2>[ %a ::@ %a ]@]" + (list o#patt ";@ ") pl o#patt x) + | p -> super#patt4 f p + + method expr_list_cons = + fun _ f e -> + let (el, c) = o#mk_expr_list e + in + match c with + | None -> o#expr_list f el + | Some x -> + pp f "@[<2>[ %a ::@ %a ]@]" (list o#expr ";@ ") el + o#expr x + + method expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | Ast.ExAss (_, e1, e2) -> + pp f "@[<2>%a@ :=@ %a@]" o#dot_expr e1 o#expr e2 + | Ast.ExFun (_, (Ast.McArr (_, p, (Ast.ExNil _), e))) + when Ast.is_irrefut_patt p -> + pp f "@[<2>fun@ %a@]" o#patt_expr_fun_args (p, e) + | Ast.ExFun (_, a) -> + pp f "@[fun%a@]" o#match_case a + | Ast.ExAsf _ -> pp f "@[<2>assert@ False@]" + | e -> super#expr f e + + method dot_expr = + fun f e -> + let () = o#node f e Ast.loc_of_expr + in + match e with + | Ast.ExAcc (_, e, + (Ast.ExId (_, (Ast.IdLid (_, "val"))))) -> + pp f "@[<2>%a.@,val@]" o#simple_expr e + | e -> super#dot_expr f e + + method ctyp = + fun f t -> + let () = o#node f t Ast.loc_of_ctyp + in + match t with + | Ast.TyDcl (_, tn, tp, te, cl) -> + (pp f "@[<2>%a%a@]" o#var tn o#type_params tp; + (match te with + | Ast.TyNil _ -> () + | _ -> pp f " =@ %a" o#ctyp te); + if cl <> [] + then pp f "@ %a" (list o#constrain "@ ") cl + else ()) + | Ast.TyCol (_, t1, (Ast.TyMut (_, t2))) -> + pp f "@[%a :@ mutable %a@]" o#ctyp t1 o#ctyp t2 + | t -> super#ctyp f t + + method simple_ctyp = + fun f t -> + let () = o#node f t Ast.loc_of_ctyp + in + match t with + | Ast.TyVrnEq (_, t) -> + pp f "@[<2>[ =@ %a@]@ ]" o#ctyp t + | Ast.TyVrnInf (_, t) -> + pp f "@[<2>[ <@ %a@]@,]" o#ctyp t + | Ast.TyVrnInfSup (_, t1, t2) -> + pp f "@[<2>[ <@ %a@ >@ %a@]@ ]" o#ctyp t1 o#ctyp t2 + | Ast.TyVrnSup (_, t) -> + pp f "@[<2>[ >@ %a@]@,]" o#ctyp t + | Ast.TyMan (_, t1, t2) -> + pp f "@[<2>%a@ ==@ %a@]" o#simple_ctyp t1 + o#simple_ctyp t2 + | Ast.TyLab (_, s, t) -> + pp f "@[<2>~%s:@ %a@]" s o#simple_ctyp t + | t -> super#simple_ctyp f t + + method ctyp1 = + fun f -> + function + | Ast.TyApp (_, t1, t2) -> + (match get_ctyp_args t1 [ t2 ] with + | (_, [ _ ]) -> + pp f "@[<2>%a@ %a@]" o#simple_ctyp t1 + o#simple_ctyp t2 + | (a, al) -> + pp f "@[<2>%a@]" (list o#simple_ctyp "@ ") + (a :: al)) + | Ast.TyPol (_, t1, t2) -> + let (a, al) = get_ctyp_args t1 [] + in + pp f "@[<2>! %a.@ %a@]" (list o#ctyp "@ ") + (a :: al) o#ctyp t2 + | t -> super#ctyp1 f t + + method constructor_type = + fun f t -> + match t with + | Ast.TyAnd (loc, t1, t2) -> + let () = o#node f t (fun _ -> loc) + in + pp f "%a@ and %a" o#constructor_type t1 + o#constructor_type t2 + | t -> o#ctyp f t + + method str_item = + fun f st -> + match st with + | Ast.StExp (_, e) -> + pp f "@[<2>%a%(%)@]" o#expr e semisep + | st -> super#str_item f st + + method module_expr = + fun f me -> + let () = o#node f me Ast.loc_of_module_expr + in + match me with + | Ast.MeApp (_, me1, me2) -> + pp f "@[<2>%a@ %a@]" o#module_expr me1 + o#simple_module_expr me2 + | me -> super#module_expr f me + + method simple_module_expr = + fun f me -> + let () = o#node f me Ast.loc_of_module_expr + in + match me with + | Ast.MeApp (_, _, _) -> pp f "(%a)" o#module_expr me + | _ -> super#simple_module_expr f me + + method implem = fun f st -> pp f "@[%a@]@." o#str_item st + + method class_type = + fun f ct -> + let () = o#node f ct Ast.loc_of_class_type + in + match ct with + | Ast.CtFun (_, t, ct) -> + pp f "@[<2>[ %a ] ->@ %a@]" o#simple_ctyp t + o#class_type ct + | Ast.CtCon (_, Ast.BFalse, i, (Ast.TyNil _)) -> + pp f "@[<2>%a@]" o#ident i + | Ast.CtCon (_, Ast.BFalse, i, t) -> + pp f "@[<2>%a [@,%a@]@,]" o#ident i o#class_params + t + | Ast.CtCon (_, Ast.BTrue, (Ast.IdLid (_, i)), + (Ast.TyNil _)) -> pp f "@[<2>virtual@ %a@]" o#var i + | Ast.CtCon (_, Ast.BTrue, (Ast.IdLid (_, i)), t) -> + pp f "@[<2>virtual@ %a@ [@,%a@]@,]" o#var i + o#class_params t + | ct -> super#class_type f ct + + method class_expr = + fun f ce -> + let () = o#node f ce Ast.loc_of_class_expr + in + match ce with + | Ast.CeCon (_, Ast.BFalse, i, (Ast.TyNil _)) -> + pp f "@[<2>%a@]" o#ident i + | Ast.CeCon (_, Ast.BFalse, i, t) -> + pp f "@[<2>%a@ @[<1>[%a]@]@]" o#ident i + o#class_params t + | Ast.CeCon (_, Ast.BTrue, (Ast.IdLid (_, i)), + (Ast.TyNil _)) -> pp f "@[<2>virtual@ %a@]" o#var i + | Ast.CeCon (_, Ast.BTrue, (Ast.IdLid (_, i)), t) -> + pp f "@[<2>virtual@ %a@ @[<1>[%a]@]@]" o#var i + o#ctyp t + | ce -> super#class_expr f ce + + end + + let with_outfile = with_outfile + + let print = print + + let print_interf = print_interf + + let print_implem = print_implem + + end + + module MakeMore (Syntax : Sig.Camlp4Syntax) : Sig.Printer(Syntax. + Ast).S = + struct + include Make(Syntax) + + let margin = ref 78 + + let comments = ref true + + let locations = ref false + + let curry_constr = ref true + + let print output_file fct = + let o = + new printer ~comments: !comments ~curry_constr: !curry_constr + () in + let o = if !locations then o#set_loc_and_comments else o + in + with_outfile output_file + (fun f -> + let () = Format.pp_set_margin f !margin + in Format.fprintf f "@[%a@]@." (fct o)) + + let print_interf ?input_file:(_) ?output_file sg = + print output_file (fun o -> o#interf) sg + + let print_implem ?input_file:(_) ?output_file st = + print output_file (fun o -> o#implem) st + + let _ = + Options.add "-l" (Arg.Int (fun i -> margin := i)) + " line length for pretty printing." + + let _ = + Options.add "-no_comments" (Arg.Clear comments) + "Do not add comments." + + let _ = + Options.add "-add_locations" (Arg.Set locations) + "Add locations as comment." + + end + + end + + end + +module OCamlInitSyntax = + struct + module Make + (Ast : Sig.Camlp4Ast) + (Gram : + Sig.Grammar.Static with module Loc = Ast.Loc with + type Token.t = Sig.camlp4_token) + (Quotation : Sig.Quotation with module Ast = Sig.Camlp4AstToAst(Ast)) : + Sig.Camlp4Syntax with module Loc = Ast.Loc and module Ast = Ast + and module Token = Gram.Token and module Gram = Gram + and module Quotation = Quotation = + struct + module Loc = Ast.Loc + + module Ast = Ast + + module Gram = Gram + + module Token = Gram.Token + + open Sig + + type warning = Loc.t -> string -> unit + + let default_warning loc txt = + Format.eprintf " %a: %s@." Loc.print loc txt + + let current_warning = ref default_warning + + let print_warning loc txt = !current_warning loc txt + + let a_CHAR = Gram.Entry.mk "a_CHAR" + + let a_FLOAT = Gram.Entry.mk "a_FLOAT" + + let a_INT = Gram.Entry.mk "a_INT" + + let a_INT32 = Gram.Entry.mk "a_INT32" + + let a_INT64 = Gram.Entry.mk "a_INT64" + + let a_LABEL = Gram.Entry.mk "a_LABEL" + + let a_LIDENT = Gram.Entry.mk "a_LIDENT" + + let a_NATIVEINT = Gram.Entry.mk "a_NATIVEINT" + + let a_OPTLABEL = Gram.Entry.mk "a_OPTLABEL" + + let a_STRING = Gram.Entry.mk "a_STRING" + + let a_UIDENT = Gram.Entry.mk "a_UIDENT" + + let a_ident = Gram.Entry.mk "a_ident" + + let amp_ctyp = Gram.Entry.mk "amp_ctyp" + + let and_ctyp = Gram.Entry.mk "and_ctyp" + + let match_case = Gram.Entry.mk "match_case" + + let match_case0 = Gram.Entry.mk "match_case0" + + let binding = Gram.Entry.mk "binding" + + let class_declaration = Gram.Entry.mk "class_declaration" + + let class_description = Gram.Entry.mk "class_description" + + let class_expr = Gram.Entry.mk "class_expr" + + let class_fun_binding = Gram.Entry.mk "class_fun_binding" + + let class_fun_def = Gram.Entry.mk "class_fun_def" + + let class_info_for_class_expr = + Gram.Entry.mk "class_info_for_class_expr" + + let class_info_for_class_type = + Gram.Entry.mk "class_info_for_class_type" + + let class_longident = Gram.Entry.mk "class_longident" + + let class_longident_and_param = + Gram.Entry.mk "class_longident_and_param" + + let class_name_and_param = Gram.Entry.mk "class_name_and_param" + + let class_sig_item = Gram.Entry.mk "class_sig_item" + + let class_signature = Gram.Entry.mk "class_signature" + + let class_str_item = Gram.Entry.mk "class_str_item" + + let class_structure = Gram.Entry.mk "class_structure" + + let class_type = Gram.Entry.mk "class_type" + + let class_type_declaration = Gram.Entry.mk "class_type_declaration" + + let class_type_longident = Gram.Entry.mk "class_type_longident" + + let class_type_longident_and_param = + Gram.Entry.mk "class_type_longident_and_param" + + let class_type_plus = Gram.Entry.mk "class_type_plus" + + let comma_ctyp = Gram.Entry.mk "comma_ctyp" + + let comma_expr = Gram.Entry.mk "comma_expr" + + let comma_ipatt = Gram.Entry.mk "comma_ipatt" + + let comma_patt = Gram.Entry.mk "comma_patt" + + let comma_type_parameter = Gram.Entry.mk "comma_type_parameter" + + let constrain = Gram.Entry.mk "constrain" + + let constructor_arg_list = Gram.Entry.mk "constructor_arg_list" + + let constructor_declaration = Gram.Entry.mk "constructor_declaration" + + let constructor_declarations = + Gram.Entry.mk "constructor_declarations" + + let ctyp = Gram.Entry.mk "ctyp" + + let cvalue_binding = Gram.Entry.mk "cvalue_binding" + + let direction_flag = Gram.Entry.mk "direction_flag" + + let dummy = Gram.Entry.mk "dummy" + + let entry_eoi = Gram.Entry.mk "entry_eoi" + + let eq_expr = Gram.Entry.mk "eq_expr" + + let expr = Gram.Entry.mk "expr" + + let expr_eoi = Gram.Entry.mk "expr_eoi" + + let field_expr = Gram.Entry.mk "field_expr" + + let field_expr_list = Gram.Entry.mk "field_expr_list" + + let fun_binding = Gram.Entry.mk "fun_binding" + + let fun_def = Gram.Entry.mk "fun_def" + + let ident = Gram.Entry.mk "ident" + + let implem = Gram.Entry.mk "implem" + + let interf = Gram.Entry.mk "interf" + + let ipatt = Gram.Entry.mk "ipatt" + + let ipatt_tcon = Gram.Entry.mk "ipatt_tcon" + + let label = Gram.Entry.mk "label" + + let label_declaration = Gram.Entry.mk "label_declaration" + + let label_declaration_list = Gram.Entry.mk "label_declaration_list" + + let label_expr = Gram.Entry.mk "label_expr" + + let label_expr_list = Gram.Entry.mk "label_expr_list" + + let label_ipatt = Gram.Entry.mk "label_ipatt" + + let label_ipatt_list = Gram.Entry.mk "label_ipatt_list" + + let label_longident = Gram.Entry.mk "label_longident" + + let label_patt = Gram.Entry.mk "label_patt" + + let label_patt_list = Gram.Entry.mk "label_patt_list" + + let labeled_ipatt = Gram.Entry.mk "labeled_ipatt" + + let let_binding = Gram.Entry.mk "let_binding" + + let meth_list = Gram.Entry.mk "meth_list" + + let meth_decl = Gram.Entry.mk "meth_decl" + + let module_binding = Gram.Entry.mk "module_binding" + + let module_binding0 = Gram.Entry.mk "module_binding0" + + let module_declaration = Gram.Entry.mk "module_declaration" + + let module_expr = Gram.Entry.mk "module_expr" + + let module_longident = Gram.Entry.mk "module_longident" + + let module_longident_with_app = + Gram.Entry.mk "module_longident_with_app" + + let module_rec_declaration = Gram.Entry.mk "module_rec_declaration" + + let module_type = Gram.Entry.mk "module_type" + + let more_ctyp = Gram.Entry.mk "more_ctyp" + + let name_tags = Gram.Entry.mk "name_tags" + + let opt_as_lident = Gram.Entry.mk "opt_as_lident" + + let opt_class_self_patt = Gram.Entry.mk "opt_class_self_patt" + + let opt_class_self_type = Gram.Entry.mk "opt_class_self_type" + + let opt_class_signature = Gram.Entry.mk "opt_class_signature" + + let opt_class_structure = Gram.Entry.mk "opt_class_structure" + + let opt_comma_ctyp = Gram.Entry.mk "opt_comma_ctyp" + + let opt_dot_dot = Gram.Entry.mk "opt_dot_dot" + + let opt_eq_ctyp = Gram.Entry.mk "opt_eq_ctyp" + + let opt_expr = Gram.Entry.mk "opt_expr" + + let opt_meth_list = Gram.Entry.mk "opt_meth_list" + + let opt_mutable = Gram.Entry.mk "opt_mutable" + + let opt_polyt = Gram.Entry.mk "opt_polyt" + + let opt_private = Gram.Entry.mk "opt_private" + + let opt_rec = Gram.Entry.mk "opt_rec" + + let opt_sig_items = Gram.Entry.mk "opt_sig_items" + + let opt_str_items = Gram.Entry.mk "opt_str_items" + + let opt_virtual = Gram.Entry.mk "opt_virtual" + + let opt_when_expr = Gram.Entry.mk "opt_when_expr" + + let patt = Gram.Entry.mk "patt" + + let patt_as_patt_opt = Gram.Entry.mk "patt_as_patt_opt" + + let patt_eoi = Gram.Entry.mk "patt_eoi" + + let patt_tcon = Gram.Entry.mk "patt_tcon" + + let phrase = Gram.Entry.mk "phrase" + + let poly_type = Gram.Entry.mk "poly_type" + + let row_field = Gram.Entry.mk "row_field" + + let sem_expr = Gram.Entry.mk "sem_expr" + + let sem_expr_for_list = Gram.Entry.mk "sem_expr_for_list" + + let sem_patt = Gram.Entry.mk "sem_patt" + + let sem_patt_for_list = Gram.Entry.mk "sem_patt_for_list" + + let semi = Gram.Entry.mk "semi" + + let sequence = Gram.Entry.mk "sequence" + + let do_sequence = Gram.Entry.mk "do_sequence" + + let sig_item = Gram.Entry.mk "sig_item" + + let sig_items = Gram.Entry.mk "sig_items" + + let star_ctyp = Gram.Entry.mk "star_ctyp" + + let str_item = Gram.Entry.mk "str_item" + + let str_items = Gram.Entry.mk "str_items" + + let top_phrase = Gram.Entry.mk "top_phrase" + + let type_constraint = Gram.Entry.mk "type_constraint" + + let type_declaration = Gram.Entry.mk "type_declaration" + + let type_ident_and_parameters = + Gram.Entry.mk "type_ident_and_parameters" + + let type_kind = Gram.Entry.mk "type_kind" + + let type_longident = Gram.Entry.mk "type_longident" + + let type_longident_and_parameters = + Gram.Entry.mk "type_longident_and_parameters" + + let type_parameter = Gram.Entry.mk "type_parameter" + + let type_parameters = Gram.Entry.mk "type_parameters" + + let typevars = Gram.Entry.mk "typevars" + + let use_file = Gram.Entry.mk "use_file" + + let val_longident = Gram.Entry.mk "val_longident" + + let value_let = Gram.Entry.mk "value_let" + + let value_val = Gram.Entry.mk "value_val" + + let with_constr = Gram.Entry.mk "with_constr" + + let expr_quot = Gram.Entry.mk "quotation of expression" + + let patt_quot = Gram.Entry.mk "quotation of pattern" + + let ctyp_quot = Gram.Entry.mk "quotation of type" + + let str_item_quot = Gram.Entry.mk "quotation of structure item" + + let sig_item_quot = Gram.Entry.mk "quotation of signature item" + + let class_str_item_quot = + Gram.Entry.mk "quotation of class structure item" + + let class_sig_item_quot = + Gram.Entry.mk "quotation of class signature item" + + let module_expr_quot = Gram.Entry.mk "quotation of module expression" + + let module_type_quot = Gram.Entry.mk "quotation of module type" + + let class_type_quot = Gram.Entry.mk "quotation of class type" + + let class_expr_quot = Gram.Entry.mk "quotation of class expression" + + let with_constr_quot = Gram.Entry.mk "quotation of with constraint" + + let binding_quot = Gram.Entry.mk "quotation of binding" + + let rec_binding_quot = Gram.Entry.mk "quotation of record binding" + + let match_case_quot = + Gram.Entry.mk "quotation of match_case (try/match/function case)" + + let module_binding_quot = + Gram.Entry.mk "quotation of module rec binding" + + let ident_quot = Gram.Entry.mk "quotation of identifier" + + let prefixop = + Gram.Entry.mk "prefix operator (start with '!', '?', '~')" + + let infixop0 = + Gram.Entry.mk + "infix operator (level 0) (comparison operators, and some others)" + + let infixop1 = + Gram.Entry.mk "infix operator (level 1) (start with '^', '@')" + + let infixop2 = + Gram.Entry.mk "infix operator (level 2) (start with '+', '-')" + + let infixop3 = + Gram.Entry.mk "infix operator (level 3) (start with '*', '/', '%')" + + let infixop4 = + Gram.Entry.mk + "infix operator (level 4) (start with \"**\") (right assoc)" + + let _ = + Gram.extend (top_phrase : 'top_phrase Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (None : 'top_phrase) + | _ -> assert false))) ]) ])) + ()) + + module AntiquotSyntax = + struct + module Loc = Ast.Loc + + module Ast = Sig.Camlp4AstToAst(Ast) + + module Gram = Gram + + let antiquot_expr = Gram.Entry.mk "antiquot_expr" + + let antiquot_patt = Gram.Entry.mk "antiquot_patt" + + let _ = + (Gram.extend (antiquot_expr : 'antiquot_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Stoken + (((function | EOI -> true | _ -> false), + "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) (x : 'expr) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (x : 'antiquot_expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (antiquot_patt : 'antiquot_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Stoken + (((function | EOI -> true | _ -> false), + "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) (x : 'patt) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (x : 'antiquot_patt) + | _ -> assert false))) ]) ])) + ())) + + let parse_expr loc str = Gram.parse_string antiquot_expr loc str + + let parse_patt loc str = Gram.parse_string antiquot_patt loc str + + end + + module Quotation = Quotation + + let wrap directive_handler pa init_loc cs = + let rec loop loc = + let (pl, stopped_at_directive) = pa loc cs + in + match stopped_at_directive with + | Some new_loc -> + let pl = + (match List.rev pl with + | [] -> assert false + | x :: xs -> + (match directive_handler x with + | None -> xs + | Some x -> x :: xs)) + in (List.rev pl) @ (loop new_loc) + | None -> pl + in loop init_loc + + let parse_implem ?(directive_handler = fun _ -> None) _loc cs = + let l = wrap directive_handler (Gram.parse implem) _loc cs + in Ast.stSem_of_list l + + let parse_interf ?(directive_handler = fun _ -> None) _loc cs = + let l = wrap directive_handler (Gram.parse interf) _loc cs + in Ast.sgSem_of_list l + + let print_interf ?input_file:(_) ?output_file:(_) _ = + failwith "No interface printer" + + let print_implem ?input_file:(_) ?output_file:(_) _ = + failwith "No implementation printer" + + end + + end + +module PreCast : + sig + type camlp4_token = + Sig.camlp4_token = + | KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int * string + | INT32 of int32 * string + | INT64 of int64 * string + | NATIVEINT of nativeint * string + | FLOAT of float * string + | CHAR of char * string + | STRING of string * string + | LABEL of string + | OPTLABEL of string + | QUOTATION of Sig.quotation + | ANTIQUOT of string * string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int * string option + | EOI + + module Id : Sig.Id + + module Loc : Sig.Loc + + module Ast : Sig.Camlp4Ast with module Loc = Loc + + module Token : Sig.Token with module Loc = Loc and type t = camlp4_token + + module Lexer : Sig.Lexer with module Loc = Loc and module Token = Token + + module Gram : Sig.Grammar.Static with module Loc = Loc + and module Token = Token + + module Quotation : + Sig.Quotation with module Ast = Sig.Camlp4AstToAst(Ast) + + module DynLoader : Sig.DynLoader + + module AstFilters : Sig.AstFilters with module Ast = Ast + + module Syntax : Sig.Camlp4Syntax with module Loc = Loc + and module Token = Token and module Ast = Ast and module Gram = Gram + and module Quotation = Quotation + + module Printers : + sig + module OCaml : Sig.Printer(Ast).S + + module OCamlr : Sig.Printer(Ast).S + + module DumpOCamlAst : Sig.Printer(Ast).S + + module DumpCamlp4Ast : Sig.Printer(Ast).S + + module Null : Sig.Printer(Ast).S + + end + + module MakeGram (Lexer : Sig.Lexer with module Loc = Loc) : + Sig.Grammar.Static with module Loc = Loc and module Token = Lexer.Token + + module MakeSyntax (U : sig end) : Sig.Syntax + + end = + struct + module Id = struct let name = "Camlp4.PreCast" + let version = Sys.ocaml_version + end + + type camlp4_token = + Sig.camlp4_token = + | KEYWORD of string + | SYMBOL of string + | LIDENT of string + | UIDENT of string + | ESCAPED_IDENT of string + | INT of int * string + | INT32 of int32 * string + | INT64 of int64 * string + | NATIVEINT of nativeint * string + | FLOAT of float * string + | CHAR of char * string + | STRING of string * string + | LABEL of string + | OPTLABEL of string + | QUOTATION of Sig.quotation + | ANTIQUOT of string * string + | COMMENT of string + | BLANKS of string + | NEWLINE + | LINE_DIRECTIVE of int * string option + | EOI + + module Loc = Struct.Loc + + module Ast = Struct.Camlp4Ast.Make(Loc) + + module Token = Struct.Token.Make(Loc) + + module Lexer = Struct.Lexer.Make(Token) + + module Gram = Struct.Grammar.Static.Make(Lexer) + + module DynLoader = Struct.DynLoader + + module Quotation = Struct.Quotation.Make(Ast) + + module MakeSyntax (U : sig end) = + OCamlInitSyntax.Make(Ast)(Gram)(Quotation) + + module Syntax = MakeSyntax(struct end) + + module AstFilters = Struct.AstFilters.Make(Ast) + + module MakeGram = Struct.Grammar.Static.Make + + module Printers = + struct + module OCaml = Printers.OCaml.Make(Syntax) + + module OCamlr = Printers.OCamlr.Make(Syntax) + + module DumpOCamlAst = Printers.DumpOCamlAst.Make(Syntax) + + module DumpCamlp4Ast = Printers.DumpCamlp4Ast.Make(Syntax) + + module Null = Printers.Null.Make(Syntax) + + end + + end + +module Register : + sig + module Plugin + (Id : Sig.Id) (Plugin : functor (Unit : sig end) -> sig end) : + sig end + + module SyntaxPlugin + (Id : Sig.Id) (SyntaxPlugin : functor (Syn : Sig.Syntax) -> sig end) : + sig end + + module SyntaxExtension + (Id : Sig.Id) (SyntaxExtension : Sig.SyntaxExtension) : sig end + + module OCamlSyntaxExtension + (Id : Sig.Id) + (SyntaxExtension : + functor (Syntax : Sig.Camlp4Syntax) -> Sig.Camlp4Syntax) : + sig end + + type 'a parser_fun = + ?directive_handler: ('a -> 'a option) -> + PreCast.Loc.t -> char Stream.t -> 'a + + val register_str_item_parser : PreCast.Ast.str_item parser_fun -> unit + + val register_sig_item_parser : PreCast.Ast.sig_item parser_fun -> unit + + val register_parser : + PreCast.Ast.str_item parser_fun -> + PreCast.Ast.sig_item parser_fun -> unit + + module Parser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast) -> Sig.Parser(Ast).S) : + sig end + + module OCamlParser + (Id : Sig.Id) + (Maker : functor (Ast : Sig.Camlp4Ast) -> Sig.Parser(Ast).S) : + sig end + + module OCamlPreCastParser + (Id : Sig.Id) (Parser : Sig.Parser(PreCast.Ast).S) : sig end + + type 'a printer_fun = + ?input_file: string -> ?output_file: string -> 'a -> unit + + val register_str_item_printer : PreCast.Ast.str_item printer_fun -> unit + + val register_sig_item_printer : PreCast.Ast.sig_item printer_fun -> unit + + val register_printer : + PreCast.Ast.str_item printer_fun -> + PreCast.Ast.sig_item printer_fun -> unit + + module Printer + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Syntax) -> Sig.Printer(Syn.Ast).S) : + sig end + + module OCamlPrinter + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Camlp4Syntax) -> Sig.Printer(Syn.Ast).S) : + sig end + + module OCamlPreCastPrinter + (Id : Sig.Id) (Printer : Sig.Printer(PreCast.Ast).S) : sig end + + module AstFilter + (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) : + sig end + + val declare_dyn_module : string -> (unit -> unit) -> unit + + val iter_and_take_callbacks : ((string * (unit -> unit)) -> unit) -> unit + + val loaded_modules : (string list) ref + + module CurrentParser : Sig.Parser(PreCast.Ast).S + + module CurrentPrinter : Sig.Printer(PreCast.Ast).S + + val enable_ocaml_printer : unit -> unit + + val enable_ocamlr_printer : unit -> unit + + val enable_null_printer : unit -> unit + + val enable_dump_ocaml_ast_printer : unit -> unit + + val enable_dump_camlp4_ast_printer : unit -> unit + + end = + struct + module PP = Printers + + open PreCast + + type 'a parser_fun = + ?directive_handler: ('a -> 'a option) -> + PreCast.Loc.t -> char Stream.t -> 'a + + type 'a printer_fun = + ?input_file: string -> ?output_file: string -> 'a -> unit + + let sig_item_parser = + ref (fun ?directive_handler:(_) _ _ -> failwith "No interface parser") + + let str_item_parser = + ref + (fun ?directive_handler:(_) _ _ -> + failwith "No implementation parser") + + let sig_item_printer = + ref + (fun ?input_file:(_) ?output_file:(_) _ -> + failwith "No interface printer") + + let str_item_printer = + ref + (fun ?input_file:(_) ?output_file:(_) _ -> + failwith "No implementation printer") + + let callbacks = Queue.create () + + let loaded_modules = ref [] + + let iter_and_take_callbacks f = + let rec loop () = loop (f (Queue.take callbacks)) + in try loop () with | Queue.Empty -> () + + let declare_dyn_module m f = + (loaded_modules := m :: !loaded_modules; Queue.add (m, f) callbacks) + + let register_str_item_parser f = str_item_parser := f + + let register_sig_item_parser f = sig_item_parser := f + + let register_parser f g = (str_item_parser := f; sig_item_parser := g) + + let register_str_item_printer f = str_item_printer := f + + let register_sig_item_printer f = sig_item_printer := f + + let register_printer f g = (str_item_printer := f; sig_item_printer := g) + + module Plugin + (Id : Sig.Id) (Maker : functor (Unit : sig end) -> sig end) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(struct end) in ()) + + end + + module SyntaxExtension (Id : Sig.Id) (Maker : Sig.SyntaxExtension) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(Syntax) in ()) + + end + + module OCamlSyntaxExtension + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Camlp4Syntax) -> Sig.Camlp4Syntax) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(Syntax) in ()) + + end + + module SyntaxPlugin + (Id : Sig.Id) (Maker : functor (Syn : Sig.Syntax) -> sig end) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(Syntax) in ()) + + end + + module Printer + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Syntax) -> Sig.Printer(Syn.Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(Syntax) + in register_printer M.print_implem M.print_interf) + + end + + module OCamlPrinter + (Id : Sig.Id) + (Maker : functor (Syn : Sig.Camlp4Syntax) -> Sig.Printer(Syn.Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(Syntax) + in register_printer M.print_implem M.print_interf) + + end + + module OCamlPreCastPrinter + (Id : Sig.Id) (P : Sig.Printer(PreCast.Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> register_printer P.print_implem P.print_interf) + + end + + module Parser + (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast) -> Sig.Parser(Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(PreCast.Ast) + in register_parser M.parse_implem M.parse_interf) + + end + + module OCamlParser + (Id : Sig.Id) + (Maker : functor (Ast : Sig.Camlp4Ast) -> Sig.Parser(Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(PreCast.Ast) + in register_parser M.parse_implem M.parse_interf) + + end + + module OCamlPreCastParser (Id : Sig.Id) (P : Sig.Parser(PreCast.Ast).S) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> register_parser P.parse_implem P.parse_interf) + + end + + module AstFilter + (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) = + struct + let _ = + declare_dyn_module Id.name + (fun _ -> let module M = Maker(AstFilters) in ()) + + end + + let _ = sig_item_parser := Syntax.parse_interf + + let _ = str_item_parser := Syntax.parse_implem + + module CurrentParser = + struct + module Ast = Ast + + let parse_interf ?directive_handler loc strm = + !sig_item_parser ?directive_handler loc strm + + let parse_implem ?directive_handler loc strm = + !str_item_parser ?directive_handler loc strm + + end + + module CurrentPrinter = + struct + module Ast = Ast + + let print_interf ?input_file ?output_file ast = + !sig_item_printer ?input_file ?output_file ast + + let print_implem ?input_file ?output_file ast = + !str_item_printer ?input_file ?output_file ast + + end + + let enable_ocaml_printer () = + let module M = OCamlPrinter(PP.OCaml.Id)(PP.OCaml.MakeMore) in () + + let enable_ocamlr_printer () = + let module M = OCamlPrinter(PP.OCamlr.Id)(PP.OCamlr.MakeMore) in () + + let enable_dump_ocaml_ast_printer () = + let module M = OCamlPrinter(PP.DumpOCamlAst.Id)(PP.DumpOCamlAst.Make) + in () + + let enable_dump_camlp4_ast_printer () = + let module M = Printer(PP.DumpCamlp4Ast.Id)(PP.DumpCamlp4Ast.Make) + in () + + let enable_null_printer () = + let module M = Printer(PP.Null.Id)(PP.Null.Make) in () + + end + + diff --git a/camlp4/boot/Camlp4.ml4 b/camlp4/boot/Camlp4.ml4 new file mode 100644 index 0000000..d3ea1c7 --- /dev/null +++ b/camlp4/boot/Camlp4.ml4 @@ -0,0 +1,79 @@ +module Debug : sig INCLUDE "camlp4/Camlp4/Debug.mli"; end = struct INCLUDE "camlp4/Camlp4/Debug.ml"; end; +module Options : sig INCLUDE "camlp4/Camlp4/Options.mli"; end = struct INCLUDE "camlp4/Camlp4/Options.ml"; end; +module Sig = struct INCLUDE "camlp4/Camlp4/Sig.ml"; end; +module ErrorHandler : sig INCLUDE "camlp4/Camlp4/ErrorHandler.mli"; end = struct INCLUDE "camlp4/Camlp4/ErrorHandler.ml"; end; + +module Struct = struct + module Loc : + sig INCLUDE "camlp4/Camlp4/Struct/Loc.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/Loc.ml"; end; + module Token : + sig INCLUDE "camlp4/Camlp4/Struct/Token.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/Token.ml"; end; + module Lexer = struct INCLUDE "camlp4/boot/Lexer.ml"; end; + module Camlp4Ast = struct INCLUDE "camlp4/Camlp4/Struct/Camlp4Ast.ml"; end; + module DynAst = struct INCLUDE "camlp4/Camlp4/Struct/DynAst.ml"; end; + module Quotation = struct INCLUDE "camlp4/Camlp4/Struct/Quotation.ml"; end; + module AstFilters = struct INCLUDE "camlp4/Camlp4/Struct/AstFilters.ml"; end; + module Camlp4Ast2OCamlAst : + sig INCLUDE "camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml"; end; + module CleanAst = struct INCLUDE "camlp4/Camlp4/Struct/CleanAst.ml"; end; + module CommentFilter : + sig INCLUDE "camlp4/Camlp4/Struct/CommentFilter.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/CommentFilter.ml"; end; + module DynLoader : + sig INCLUDE "camlp4/Camlp4/Struct/DynLoader.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/DynLoader.ml"; end; + module EmptyError : + sig INCLUDE "camlp4/Camlp4/Struct/EmptyError.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/EmptyError.ml"; end; + module EmptyPrinter : + sig INCLUDE "camlp4/Camlp4/Struct/EmptyPrinter.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/EmptyPrinter.ml"; end; + module FreeVars : + sig INCLUDE "camlp4/Camlp4/Struct/FreeVars.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/FreeVars.ml"; end; + module Grammar = struct + module Context = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Context.ml"; end; + module Structure = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Structure.ml"; end; + module Search = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Search.ml"; end; + (* module Find = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Find.ml"; end; *) + module Tools = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Tools.ml"; end; + module Print : + sig INCLUDE "camlp4/Camlp4/Struct/Grammar/Print.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Print.ml"; end; + module Failed = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Failed.ml"; end; + module Parser = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Parser.ml"; end; + module Insert = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Insert.ml"; end; + module Delete = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Delete.ml"; end; + module Fold : + sig INCLUDE "camlp4/Camlp4/Struct/Grammar/Fold.mli"; end = + struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Fold.ml"; end; + module Entry = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Entry.ml"; end; + module Static = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Static.ml"; end; + module Dynamic = struct INCLUDE "camlp4/Camlp4/Struct/Grammar/Dynamic.ml"; end; + end; +end; + +module Printers = struct + module DumpCamlp4Ast : + sig INCLUDE "camlp4/Camlp4/Printers/DumpCamlp4Ast.mli"; end = + struct INCLUDE "camlp4/Camlp4/Printers/DumpCamlp4Ast.ml"; end; + module DumpOCamlAst : + sig INCLUDE "camlp4/Camlp4/Printers/DumpOCamlAst.mli"; end = + struct INCLUDE "camlp4/Camlp4/Printers/DumpOCamlAst.ml"; end; + module Null : + sig INCLUDE "camlp4/Camlp4/Printers/Null.mli"; end = + struct INCLUDE "camlp4/Camlp4/Printers/Null.ml"; end; + module OCaml : + sig INCLUDE "camlp4/Camlp4/Printers/OCaml.mli"; end = + struct INCLUDE "camlp4/Camlp4/Printers/OCaml.ml"; end; + module OCamlr : + sig INCLUDE "camlp4/Camlp4/Printers/OCamlr.mli"; end = + struct INCLUDE "camlp4/Camlp4/Printers/OCamlr.ml"; end; +end; + +module OCamlInitSyntax = struct INCLUDE "camlp4/Camlp4/OCamlInitSyntax.ml"; end; +module PreCast : sig INCLUDE "camlp4/Camlp4/PreCast.mli"; end = struct INCLUDE "camlp4/Camlp4/PreCast.ml"; end; +module Register : sig INCLUDE "camlp4/Camlp4/Register.mli"; end = struct INCLUDE "camlp4/Camlp4/Register.ml"; end; diff --git a/camlp4/boot/Camlp4Ast.ml b/camlp4/boot/Camlp4Ast.ml new file mode 100644 index 0000000..68ce6da --- /dev/null +++ b/camlp4/boot/Camlp4Ast.ml @@ -0,0 +1,5692 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) +(* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) +module Make (Loc : Sig.Loc) : Sig.Camlp4Ast with module Loc = Loc = + struct + module Loc = Loc; + module Ast = + struct + include (Sig.MakeCamlp4Ast Loc); + value safe_string_escaped s = + if ((String.length s) > 2) && ((s.[0] = '\\') && (s.[1] = '$')) + then s + else String.escaped s; + end; + include Ast; + external loc_of_ctyp : ctyp -> Loc.t = "%field0"; + external loc_of_patt : patt -> Loc.t = "%field0"; + external loc_of_expr : expr -> Loc.t = "%field0"; + external loc_of_module_type : module_type -> Loc.t = "%field0"; + external loc_of_module_expr : module_expr -> Loc.t = "%field0"; + external loc_of_sig_item : sig_item -> Loc.t = "%field0"; + external loc_of_str_item : str_item -> Loc.t = "%field0"; + external loc_of_class_type : class_type -> Loc.t = "%field0"; + external loc_of_class_sig_item : class_sig_item -> Loc.t = "%field0"; + external loc_of_class_expr : class_expr -> Loc.t = "%field0"; + external loc_of_class_str_item : class_str_item -> Loc.t = "%field0"; + external loc_of_with_constr : with_constr -> Loc.t = "%field0"; + external loc_of_binding : binding -> Loc.t = "%field0"; + external loc_of_rec_binding : rec_binding -> Loc.t = "%field0"; + external loc_of_module_binding : module_binding -> Loc.t = "%field0"; + external loc_of_match_case : match_case -> Loc.t = "%field0"; + external loc_of_ident : ident -> Loc.t = "%field0"; + value ghost = Loc.ghost; + value rec is_module_longident = + fun + [ Ast.IdAcc _ _ i -> is_module_longident i + | Ast.IdApp _ i1 i2 -> + (is_module_longident i1) && (is_module_longident i2) + | Ast.IdUid _ _ -> True + | _ -> False ]; + value ident_of_expr = + let error () = + invalid_arg "ident_of_expr: this expression is not an identifier" in + let rec self = + fun + [ Ast.ExApp _loc e1 e2 -> Ast.IdApp _loc (self e1) (self e2) + | Ast.ExAcc _loc e1 e2 -> Ast.IdAcc _loc (self e1) (self e2) + | Ast.ExId _ (Ast.IdLid _ _) -> error () + | Ast.ExId _ i -> if is_module_longident i then i else error () + | _ -> error () ] + in + fun [ Ast.ExId _ i -> i | Ast.ExApp _ _ _ -> error () | t -> self t ]; + value ident_of_ctyp = + let error () = + invalid_arg "ident_of_ctyp: this type is not an identifier" in + let rec self = + fun + [ Ast.TyApp _loc t1 t2 -> Ast.IdApp _loc (self t1) (self t2) + | Ast.TyId _ (Ast.IdLid _ _) -> error () + | Ast.TyId _ i -> if is_module_longident i then i else error () + | _ -> error () ] + in fun [ Ast.TyId _ i -> i | t -> self t ]; + value ident_of_patt = + let error () = + invalid_arg "ident_of_patt: this pattern is not an identifier" in + let rec self = + fun + [ Ast.PaApp _loc p1 p2 -> Ast.IdApp _loc (self p1) (self p2) + | Ast.PaId _ (Ast.IdLid _ _) -> error () + | Ast.PaId _ i -> if is_module_longident i then i else error () + | _ -> error () ] + in fun [ Ast.PaId _ i -> i | p -> self p ]; + value rec is_irrefut_patt = + fun + [ Ast.PaId _ (Ast.IdLid _ _) -> True + | Ast.PaId _ (Ast.IdUid _ "()") -> True + | Ast.PaAny _ -> True + | Ast.PaNil _ -> True + | (* why not *) Ast.PaAli _ x y -> + (is_irrefut_patt x) && (is_irrefut_patt y) + | Ast.PaRec _ p -> is_irrefut_patt p + | Ast.PaEq _ _ p -> is_irrefut_patt p + | Ast.PaSem _ p1 p2 -> (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaCom _ p1 p2 -> (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaOrp _ p1 p2 -> (is_irrefut_patt p1) && (is_irrefut_patt p2) + | (* could be more fine grained *) Ast.PaApp _ p1 p2 -> + (is_irrefut_patt p1) && (is_irrefut_patt p2) + | Ast.PaTyc _ p _ -> is_irrefut_patt p + | Ast.PaTup _ pl -> is_irrefut_patt pl + | Ast.PaOlb _ _ (Ast.PaNil _) -> True + | Ast.PaOlb _ _ p -> is_irrefut_patt p + | Ast.PaOlbi _ _ p _ -> is_irrefut_patt p + | Ast.PaLab _ _ (Ast.PaNil _) -> True + | Ast.PaLab _ _ p -> is_irrefut_patt p + | Ast.PaLaz _ p -> is_irrefut_patt p + | Ast.PaId _ _ -> False + | (* here one need to know the arity of constructors *) + Ast.PaVrn _ _ | Ast.PaStr _ _ | Ast.PaRng _ _ _ | Ast.PaFlo _ _ | + Ast.PaNativeInt _ _ | Ast.PaInt64 _ _ | Ast.PaInt32 _ _ | + Ast.PaInt _ _ | Ast.PaChr _ _ | Ast.PaTyp _ _ | Ast.PaArr _ _ | + Ast.PaAnt _ _ + -> False ]; + value rec is_constructor = + fun + [ Ast.IdAcc _ _ i -> is_constructor i + | Ast.IdUid _ _ -> True + | Ast.IdLid _ _ | Ast.IdApp _ _ _ -> False + | Ast.IdAnt _ _ -> assert False ]; + value is_patt_constructor = + fun + [ Ast.PaId _ i -> is_constructor i + | Ast.PaVrn _ _ -> True + | _ -> False ]; + value rec is_expr_constructor = + fun + [ Ast.ExId _ i -> is_constructor i + | Ast.ExAcc _ e1 e2 -> + (is_expr_constructor e1) && (is_expr_constructor e2) + | Ast.ExVrn _ _ -> True + | _ -> False ]; + value rec tyOr_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TyOr _loc t (tyOr_of_list ts) ]; + value rec tyAnd_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TyAnd _loc t (tyAnd_of_list ts) ]; + value rec tySem_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TySem _loc t (tySem_of_list ts) ]; + value rec tyCom_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TyCom _loc t (tyCom_of_list ts) ]; + value rec tyAmp_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TyAmp _loc t (tyAmp_of_list ts) ]; + value rec tySta_of_list = + fun + [ [] -> Ast.TyNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_ctyp t in Ast.TySta _loc t (tySta_of_list ts) ]; + value rec stSem_of_list = + fun + [ [] -> Ast.StNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_str_item t in Ast.StSem _loc t (stSem_of_list ts) ]; + value rec sgSem_of_list = + fun + [ [] -> Ast.SgNil ghost + | [ t ] -> t + | [ t :: ts ] -> + let _loc = loc_of_sig_item t in Ast.SgSem _loc t (sgSem_of_list ts) ]; + value rec biAnd_of_list = + fun + [ [] -> Ast.BiNil ghost + | [ b ] -> b + | [ b :: bs ] -> + let _loc = loc_of_binding b in Ast.BiAnd _loc b (biAnd_of_list bs) ]; + value rec rbSem_of_list = + fun + [ [] -> Ast.RbNil ghost + | [ b ] -> b + | [ b :: bs ] -> + let _loc = loc_of_rec_binding b + in Ast.RbSem _loc b (rbSem_of_list bs) ]; + value rec wcAnd_of_list = + fun + [ [] -> Ast.WcNil ghost + | [ w ] -> w + | [ w :: ws ] -> + let _loc = loc_of_with_constr w + in Ast.WcAnd _loc w (wcAnd_of_list ws) ]; + value rec idAcc_of_list = + fun + [ [] -> assert False + | [ i ] -> i + | [ i :: is ] -> + let _loc = loc_of_ident i in Ast.IdAcc _loc i (idAcc_of_list is) ]; + value rec idApp_of_list = + fun + [ [] -> assert False + | [ i ] -> i + | [ i :: is ] -> + let _loc = loc_of_ident i in Ast.IdApp _loc i (idApp_of_list is) ]; + value rec mcOr_of_list = + fun + [ [] -> Ast.McNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_match_case x in Ast.McOr _loc x (mcOr_of_list xs) ]; + value rec mbAnd_of_list = + fun + [ [] -> Ast.MbNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_module_binding x + in Ast.MbAnd _loc x (mbAnd_of_list xs) ]; + value rec meApp_of_list = + fun + [ [] -> assert False + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_module_expr x + in Ast.MeApp _loc x (meApp_of_list xs) ]; + value rec ceAnd_of_list = + fun + [ [] -> Ast.CeNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_class_expr x + in Ast.CeAnd _loc x (ceAnd_of_list xs) ]; + value rec ctAnd_of_list = + fun + [ [] -> Ast.CtNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_class_type x + in Ast.CtAnd _loc x (ctAnd_of_list xs) ]; + value rec cgSem_of_list = + fun + [ [] -> Ast.CgNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_class_sig_item x + in Ast.CgSem _loc x (cgSem_of_list xs) ]; + value rec crSem_of_list = + fun + [ [] -> Ast.CrNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_class_str_item x + in Ast.CrSem _loc x (crSem_of_list xs) ]; + value rec paSem_of_list = + fun + [ [] -> Ast.PaNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_patt x in Ast.PaSem _loc x (paSem_of_list xs) ]; + value rec paCom_of_list = + fun + [ [] -> Ast.PaNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_patt x in Ast.PaCom _loc x (paCom_of_list xs) ]; + value rec exSem_of_list = + fun + [ [] -> Ast.ExNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_expr x in Ast.ExSem _loc x (exSem_of_list xs) ]; + value rec exCom_of_list = + fun + [ [] -> Ast.ExNil ghost + | [ x ] -> x + | [ x :: xs ] -> + let _loc = loc_of_expr x in Ast.ExCom _loc x (exCom_of_list xs) ]; + value ty_of_stl = + fun + [ (_loc, s, []) -> Ast.TyId _loc (Ast.IdUid _loc s) + | (_loc, s, tl) -> + Ast.TyOf _loc (Ast.TyId _loc (Ast.IdUid _loc s)) (tyAnd_of_list tl) ]; + value ty_of_sbt = + fun + [ (_loc, s, True, t) -> + Ast.TyCol _loc (Ast.TyId _loc (Ast.IdLid _loc s)) + (Ast.TyMut _loc t) + | (_loc, s, False, t) -> + Ast.TyCol _loc (Ast.TyId _loc (Ast.IdLid _loc s)) t ]; + value bi_of_pe (p, e) = let _loc = loc_of_patt p in Ast.BiEq _loc p e; + value sum_type_of_list l = tyOr_of_list (List.map ty_of_stl l); + value record_type_of_list l = tySem_of_list (List.map ty_of_sbt l); + value binding_of_pel l = biAnd_of_list (List.map bi_of_pe l); + value rec pel_of_binding = + fun + [ Ast.BiAnd _ b1 b2 -> (pel_of_binding b1) @ (pel_of_binding b2) + | Ast.BiEq _ p e -> [ (p, e) ] + | _ -> assert False ]; + value rec list_of_binding x acc = + match x with + [ Ast.BiAnd _ b1 b2 -> list_of_binding b1 (list_of_binding b2 acc) + | t -> [ t :: acc ] ]; + value rec list_of_rec_binding x acc = + match x with + [ Ast.RbSem _ b1 b2 -> + list_of_rec_binding b1 (list_of_rec_binding b2 acc) + | t -> [ t :: acc ] ]; + value rec list_of_with_constr x acc = + match x with + [ Ast.WcAnd _ w1 w2 -> + list_of_with_constr w1 (list_of_with_constr w2 acc) + | t -> [ t :: acc ] ]; + value rec list_of_ctyp x acc = + match x with + [ Ast.TyNil _ -> acc + | Ast.TyAmp _ x y | Ast.TyCom _ x y | Ast.TySta _ x y | Ast.TySem _ x y + | Ast.TyAnd _ x y | Ast.TyOr _ x y -> + list_of_ctyp x (list_of_ctyp y acc) + | x -> [ x :: acc ] ]; + value rec list_of_patt x acc = + match x with + [ Ast.PaNil _ -> acc + | Ast.PaCom _ x y | Ast.PaSem _ x y -> + list_of_patt x (list_of_patt y acc) + | x -> [ x :: acc ] ]; + value rec list_of_expr x acc = + match x with + [ Ast.ExNil _ -> acc + | Ast.ExCom _ x y | Ast.ExSem _ x y -> + list_of_expr x (list_of_expr y acc) + | x -> [ x :: acc ] ]; + value rec list_of_str_item x acc = + match x with + [ Ast.StNil _ -> acc + | Ast.StSem _ x y -> list_of_str_item x (list_of_str_item y acc) + | x -> [ x :: acc ] ]; + value rec list_of_sig_item x acc = + match x with + [ Ast.SgNil _ -> acc + | Ast.SgSem _ x y -> list_of_sig_item x (list_of_sig_item y acc) + | x -> [ x :: acc ] ]; + value rec list_of_class_sig_item x acc = + match x with + [ Ast.CgNil _ -> acc + | Ast.CgSem _ x y -> + list_of_class_sig_item x (list_of_class_sig_item y acc) + | x -> [ x :: acc ] ]; + value rec list_of_class_str_item x acc = + match x with + [ Ast.CrNil _ -> acc + | Ast.CrSem _ x y -> + list_of_class_str_item x (list_of_class_str_item y acc) + | x -> [ x :: acc ] ]; + value rec list_of_class_type x acc = + match x with + [ Ast.CtAnd _ x y -> list_of_class_type x (list_of_class_type y acc) + | x -> [ x :: acc ] ]; + value rec list_of_class_expr x acc = + match x with + [ Ast.CeAnd _ x y -> list_of_class_expr x (list_of_class_expr y acc) + | x -> [ x :: acc ] ]; + value rec list_of_module_expr x acc = + match x with + [ Ast.MeApp _ x y -> list_of_module_expr x (list_of_module_expr y acc) + | x -> [ x :: acc ] ]; + value rec list_of_match_case x acc = + match x with + [ Ast.McNil _ -> acc + | Ast.McOr _ x y -> list_of_match_case x (list_of_match_case y acc) + | x -> [ x :: acc ] ]; + value rec list_of_ident x acc = + match x with + [ Ast.IdAcc _ x y | Ast.IdApp _ x y -> + list_of_ident x (list_of_ident y acc) + | x -> [ x :: acc ] ]; + value rec list_of_module_binding x acc = + match x with + [ Ast.MbAnd _ x y -> + list_of_module_binding x (list_of_module_binding y acc) + | x -> [ x :: acc ] ]; + module Meta = + struct + module type META_LOC = + sig + value meta_loc_patt : Loc.t -> Loc.t -> Ast.patt; + value meta_loc_expr : Loc.t -> Loc.t -> Ast.expr; + end; + module MetaLoc = + struct + value meta_loc_patt _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location + in + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Loc") + (Ast.IdLid _loc "of_tuple"))) + (Ast.PaTup _loc + (Ast.PaCom _loc + (Ast.PaStr _loc (Ast.safe_string_escaped a)) + (Ast.PaCom _loc + (Ast.PaCom _loc + (Ast.PaCom _loc + (Ast.PaCom _loc + (Ast.PaCom _loc + (Ast.PaCom _loc + (Ast.PaInt _loc (string_of_int b)) + (Ast.PaInt _loc (string_of_int c))) + (Ast.PaInt _loc (string_of_int d))) + (Ast.PaInt _loc (string_of_int e))) + (Ast.PaInt _loc (string_of_int f))) + (Ast.PaInt _loc (string_of_int g))) + (if h + then Ast.PaId _loc (Ast.IdUid _loc "True") + else Ast.PaId _loc (Ast.IdUid _loc "False"))))); + value meta_loc_expr _loc location = + let (a, b, c, d, e, f, g, h) = Loc.to_tuple location + in + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Loc") + (Ast.IdLid _loc "of_tuple"))) + (Ast.ExTup _loc + (Ast.ExCom _loc + (Ast.ExStr _loc (Ast.safe_string_escaped a)) + (Ast.ExCom _loc + (Ast.ExCom _loc + (Ast.ExCom _loc + (Ast.ExCom _loc + (Ast.ExCom _loc + (Ast.ExCom _loc + (Ast.ExInt _loc (string_of_int b)) + (Ast.ExInt _loc (string_of_int c))) + (Ast.ExInt _loc (string_of_int d))) + (Ast.ExInt _loc (string_of_int e))) + (Ast.ExInt _loc (string_of_int f))) + (Ast.ExInt _loc (string_of_int g))) + (if h + then Ast.ExId _loc (Ast.IdUid _loc "True") + else Ast.ExId _loc (Ast.IdUid _loc "False"))))); + end; + module MetaGhostLoc = + struct + value meta_loc_patt _loc _ = + Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Loc") + (Ast.IdLid _loc "ghost")); + value meta_loc_expr _loc _ = + Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Loc") + (Ast.IdLid _loc "ghost")); + end; + module MetaLocVar = + struct + value meta_loc_patt _loc _ = + Ast.PaId _loc (Ast.IdLid _loc Loc.name.val); + value meta_loc_expr _loc _ = + Ast.ExId _loc (Ast.IdLid _loc Loc.name.val); + end; + module Make (MetaLoc : META_LOC) = + struct + open MetaLoc; + value meta_loc = meta_loc_expr; + module Expr = + struct + value meta_string _loc s = Ast.ExStr _loc s; + value meta_int _loc s = Ast.ExInt _loc s; + value meta_float _loc s = Ast.ExFlo _loc s; + value meta_char _loc s = Ast.ExChr _loc s; + value meta_bool _loc = + fun + [ False -> Ast.ExId _loc (Ast.IdUid _loc "False") + | True -> Ast.ExId _loc (Ast.IdUid _loc "True") ]; + value rec meta_list mf_a _loc = + fun + [ [] -> Ast.ExId _loc (Ast.IdUid _loc "[]") + | [ x :: xs ] -> + Ast.ExApp _loc + (Ast.ExApp _loc (Ast.ExId _loc (Ast.IdUid _loc "::")) + (mf_a _loc x)) + (meta_list mf_a _loc xs) ]; + value rec meta_binding _loc = + fun + [ Ast.BiAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.BiEq x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiEq"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_expr _loc x2) + | Ast.BiAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiAnd"))) + (meta_loc _loc x0)) + (meta_binding _loc x1)) + (meta_binding _loc x2) + | Ast.BiNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiNil"))) + (meta_loc _loc x0) ] + and meta_class_expr _loc = + fun + [ Ast.CeAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.CeEq x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeEq"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeAnd"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeTyc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeTyc"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_type _loc x2) + | Ast.CeStr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeStr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_str_item _loc x2) + | Ast.CeLet x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeLet"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2)) + (meta_class_expr _loc x3) + | Ast.CeFun x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeFun"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeCon x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeCon"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_ident _loc x2)) + (meta_ctyp _loc x3) + | Ast.CeApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeApp"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_expr _loc x2) + | Ast.CeNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeNil"))) + (meta_loc _loc x0) ] + and meta_class_sig_item _loc = + fun + [ Ast.CgAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.CgVir x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgVir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CgVal x0 x1 x2 x3 x4 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_meta_bool _loc x3)) + (meta_ctyp _loc x4) + | Ast.CgMth x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgMth"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CgInh x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgInh"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.CgSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgSem"))) + (meta_loc _loc x0)) + (meta_class_sig_item _loc x1)) + (meta_class_sig_item _loc x2) + | Ast.CgCtr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgCtr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.CgNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgNil"))) + (meta_loc _loc x0) ] + and meta_class_str_item _loc = + fun + [ Ast.CrAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.CrVvr x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVvr"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CrVir x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CrVal x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_expr _loc x3) + | Ast.CrMth x0 x1 x2 x3 x4 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrMth"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_expr _loc x3)) + (meta_ctyp _loc x4) + | Ast.CrIni x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrIni"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.CrInh x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrInh"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_string _loc x2) + | Ast.CrCtr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrCtr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.CrSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrSem"))) + (meta_loc _loc x0)) + (meta_class_str_item _loc x1)) + (meta_class_str_item _loc x2) + | Ast.CrNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrNil"))) + (meta_loc _loc x0) ] + and meta_class_type _loc = + fun + [ Ast.CtAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.CtEq x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtEq"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtCol x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtCol"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtAnd"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtSig x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtSig"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_class_sig_item _loc x2) + | Ast.CtFun x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtFun"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_class_type _loc x2) + | Ast.CtCon x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtCon"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_ident _loc x2)) + (meta_ctyp _loc x3) + | Ast.CtNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtNil"))) + (meta_loc _loc x0) ] + and meta_ctyp _loc = + fun + [ Ast.TyAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.TyOfAmp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOfAmp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAmp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAmp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyVrnInfSup x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnInfSup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyVrnInf x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnInf"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrnSup x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnSup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrnEq x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnEq"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TySta x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySta"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyTup x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyTup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyMut x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyMut"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyPrv x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyPrv"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyOr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAnd"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyOf x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOf"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TySum x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySum"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyCom x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCom"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TySem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySem"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyCol x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCol"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyRec x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyRec"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrn x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuM x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuM"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuP x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuP"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuo x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyPol x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyPol"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyOlb x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyObj x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyObj"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_meta_bool _loc x2) + | Ast.TyDcl x0 x1 x2 x3 x4 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyDcl"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_list meta_ctyp _loc x2)) + (meta_ctyp _loc x3)) + (meta_list + (fun _loc (x1, x2) -> + Ast.ExTup _loc + (Ast.ExCom _loc (meta_ctyp _loc x1) + (meta_ctyp _loc x2))) + _loc x4) + | Ast.TyMan x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyMan"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyId x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.TyLab x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyCls x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCls"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.TyArr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyArr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyApp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAny x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAny"))) + (meta_loc _loc x0) + | Ast.TyAli x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAli"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyNil"))) + (meta_loc _loc x0) ] + and meta_expr _loc = + fun + [ Ast.ExWhi x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExWhi"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExVrn x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExTyc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTyc"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_ctyp _loc x2) + | Ast.ExCom x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExCom"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExTup x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTup"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExTry x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTry"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_match_case _loc x2) + | Ast.ExStr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExStr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExSte x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSte"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExSnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSnd"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_string _loc x2) + | Ast.ExSeq x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSeq"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExRec x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExRec"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1)) + (meta_expr _loc x2) + | Ast.ExOvr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExOvr"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1) + | Ast.ExOlb x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.ExObj x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExObj"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_str_item _loc x2) + | Ast.ExNew x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNew"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.ExMat x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExMat"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_match_case _loc x2) + | Ast.ExLmd x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLmd"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_expr _loc x2)) + (meta_expr _loc x3) + | Ast.ExLet x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLet"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2)) + (meta_expr _loc x3) + | Ast.ExLaz x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLaz"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExLab x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.ExNativeInt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNativeInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt64 x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt64"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt32 x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt32"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExIfe x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExIfe"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3) + | Ast.ExFun x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFun"))) + (meta_loc _loc x0)) + (meta_match_case _loc x1) + | Ast.ExFor x0 x1 x2 x3 x4 x5 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc + (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFor"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3)) + (meta_meta_bool _loc x4)) + (meta_expr _loc x5) + | Ast.ExFlo x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFlo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExCoe x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExCoe"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_ctyp _loc x2)) + (meta_ctyp _loc x3) + | Ast.ExChr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExChr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExAss x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAss"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExAsr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAsr"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExAsf x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAsf"))) + (meta_loc _loc x0) + | Ast.ExSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSem"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExArr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExArr"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExAre x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAre"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExApp"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.ExAcc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAcc"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExId x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.ExNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNil"))) + (meta_loc _loc x0) ] + and meta_ident _loc = + fun + [ Ast.IdAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.IdUid x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdUid"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.IdLid x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdLid"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.IdApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdApp"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) + | Ast.IdAcc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdAcc"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) ] + and meta_match_case _loc = + fun + [ Ast.McAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.McArr x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McArr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3) + | Ast.McOr x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McOr"))) + (meta_loc _loc x0)) + (meta_match_case _loc x1)) + (meta_match_case _loc x2) + | Ast.McNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McNil"))) + (meta_loc _loc x0) ] + and meta_meta_bool _loc = + fun + [ Ast.BAnt x0 -> Ast.ExAnt _loc x0 + | Ast.BFalse -> + Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BFalse")) + | Ast.BTrue -> + Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BTrue")) ] + and meta_meta_list mf_a _loc = + fun + [ Ast.LAnt x0 -> Ast.ExAnt _loc x0 + | Ast.LCons x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "LCons"))) + (mf_a _loc x0)) + (meta_meta_list mf_a _loc x1) + | Ast.LNil -> + Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "LNil")) ] + and meta_meta_option mf_a _loc = + fun + [ Ast.OAnt x0 -> Ast.ExAnt _loc x0 + | Ast.OSome x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "OSome"))) + (mf_a _loc x0) + | Ast.ONone -> + Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ONone")) ] + and meta_module_binding _loc = + fun + [ Ast.MbAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.MbCol x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbCol"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.MbColEq x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbColEq"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_expr _loc x3) + | Ast.MbAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbAnd"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1)) + (meta_module_binding _loc x2) + | Ast.MbNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbNil"))) + (meta_loc _loc x0) ] + and meta_module_expr _loc = + fun + [ Ast.MeAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.MeTyc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeTyc"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1)) + (meta_module_type _loc x2) + | Ast.MeStr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeStr"))) + (meta_loc _loc x0)) + (meta_str_item _loc x1) + | Ast.MeFun x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeFun"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_expr _loc x3) + | Ast.MeApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeApp"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1)) + (meta_module_expr _loc x2) + | Ast.MeId x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.MeNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeNil"))) + (meta_loc _loc x0) ] + and meta_module_type _loc = + fun + [ Ast.MtAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.MtWit x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtWit"))) + (meta_loc _loc x0)) + (meta_module_type _loc x1)) + (meta_with_constr _loc x2) + | Ast.MtSig x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtSig"))) + (meta_loc _loc x0)) + (meta_sig_item _loc x1) + | Ast.MtQuo x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtQuo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.MtFun x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtFun"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_type _loc x3) + | Ast.MtId x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.MtNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtNil"))) + (meta_loc _loc x0) ] + and meta_patt _loc = + fun + [ Ast.PaLaz x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaLaz"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaVrn x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaTyp x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTyp"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.PaTyc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTyc"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_ctyp _loc x2) + | Ast.PaTup x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTup"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaStr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaStr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaEq x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaEq"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_patt _loc x2) + | Ast.PaRec x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaRec"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaRng x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaRng"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaOrp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOrp"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaOlbi x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOlbi"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2)) + (meta_expr _loc x3) + | Ast.PaOlb x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2) + | Ast.PaLab x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2) + | Ast.PaFlo x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaFlo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaNativeInt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaNativeInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt64 x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt64"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt32 x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt32"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaChr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaChr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaSem"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaCom x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaCom"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaArr x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaArr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaApp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaApp"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaAny x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaAny"))) + (meta_loc _loc x0) + | Ast.PaAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.PaAli x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaAli"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaId x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.PaNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaNil"))) + (meta_loc _loc x0) ] + and meta_rec_binding _loc = + fun + [ Ast.RbAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.RbEq x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbEq"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_expr _loc x2) + | Ast.RbSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbSem"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1)) + (meta_rec_binding _loc x2) + | Ast.RbNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbNil"))) + (meta_loc _loc x0) ] + and meta_sig_item _loc = + fun + [ Ast.SgAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.SgVal x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.SgTyp x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.SgOpn x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgOpn"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.SgMty x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgMty"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.SgRecMod x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgRecMod"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1) + | Ast.SgMod x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgMod"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.SgInc x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgInc"))) + (meta_loc _loc x0)) + (meta_module_type _loc x1) + | Ast.SgExt x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgExt"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2)) + (meta_meta_list meta_string _loc x3) + | Ast.SgExc x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgExc"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.SgDir x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgDir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.SgSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgSem"))) + (meta_loc _loc x0)) + (meta_sig_item _loc x1)) + (meta_sig_item _loc x2) + | Ast.SgClt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgClt"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.SgCls x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgCls"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.SgNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgNil"))) + (meta_loc _loc x0) ] + and meta_str_item _loc = + fun + [ Ast.StAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.StVal x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StVal"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2) + | Ast.StTyp x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.StOpn x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StOpn"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.StMty x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StMty"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.StRecMod x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StRecMod"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1) + | Ast.StMod x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StMod"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_expr _loc x2) + | Ast.StInc x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StInc"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1) + | Ast.StExt x0 x1 x2 x3 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExt"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2)) + (meta_meta_list meta_string _loc x3) + | Ast.StExp x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExp"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.StExc x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExc"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_meta_option meta_ident _loc x2) + | Ast.StDir x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StDir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.StSem x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StSem"))) + (meta_loc _loc x0)) + (meta_str_item _loc x1)) + (meta_str_item _loc x2) + | Ast.StClt x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StClt"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.StCls x0 x1 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StCls"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1) + | Ast.StNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StNil"))) + (meta_loc _loc x0) ] + and meta_with_constr _loc = + fun + [ Ast.WcAnt x0 x1 -> Ast.ExAnt x0 x1 + | Ast.WcAnd x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcAnd"))) + (meta_loc _loc x0)) + (meta_with_constr _loc x1)) + (meta_with_constr _loc x2) + | Ast.WcMod x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcMod"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) + | Ast.WcTyp x0 x1 x2 -> + Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.WcNil x0 -> + Ast.ExApp _loc + (Ast.ExId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcNil"))) + (meta_loc _loc x0) ]; + end; + value meta_loc = meta_loc_patt; + module Patt = + struct + value meta_string _loc s = Ast.PaStr _loc s; + value meta_int _loc s = Ast.PaInt _loc s; + value meta_float _loc s = Ast.PaFlo _loc s; + value meta_char _loc s = Ast.PaChr _loc s; + value meta_bool _loc = + fun + [ False -> Ast.PaId _loc (Ast.IdUid _loc "False") + | True -> Ast.PaId _loc (Ast.IdUid _loc "True") ]; + value rec meta_list mf_a _loc = + fun + [ [] -> Ast.PaId _loc (Ast.IdUid _loc "[]") + | [ x :: xs ] -> + Ast.PaApp _loc + (Ast.PaApp _loc (Ast.PaId _loc (Ast.IdUid _loc "::")) + (mf_a _loc x)) + (meta_list mf_a _loc xs) ]; + value rec meta_binding _loc = + fun + [ Ast.BiAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.BiEq x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiEq"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_expr _loc x2) + | Ast.BiAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiAnd"))) + (meta_loc _loc x0)) + (meta_binding _loc x1)) + (meta_binding _loc x2) + | Ast.BiNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BiNil"))) + (meta_loc _loc x0) ] + and meta_class_expr _loc = + fun + [ Ast.CeAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.CeEq x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeEq"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeAnd"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeTyc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeTyc"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_class_type _loc x2) + | Ast.CeStr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeStr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_str_item _loc x2) + | Ast.CeLet x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeLet"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2)) + (meta_class_expr _loc x3) + | Ast.CeFun x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeFun"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_expr _loc x2) + | Ast.CeCon x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeCon"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_ident _loc x2)) + (meta_ctyp _loc x3) + | Ast.CeApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeApp"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_expr _loc x2) + | Ast.CeNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CeNil"))) + (meta_loc _loc x0) ] + and meta_class_sig_item _loc = + fun + [ Ast.CgAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.CgVir x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgVir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CgVal x0 x1 x2 x3 x4 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_meta_bool _loc x3)) + (meta_ctyp _loc x4) + | Ast.CgMth x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgMth"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CgInh x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgInh"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.CgSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgSem"))) + (meta_loc _loc x0)) + (meta_class_sig_item _loc x1)) + (meta_class_sig_item _loc x2) + | Ast.CgCtr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgCtr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.CgNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CgNil"))) + (meta_loc _loc x0) ] + and meta_class_str_item _loc = + fun + [ Ast.CrAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.CrVvr x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVvr"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CrVir x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_ctyp _loc x3) + | Ast.CrVal x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_expr _loc x3) + | Ast.CrMth x0 x1 x2 x3 x4 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrMth"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_meta_bool _loc x2)) + (meta_expr _loc x3)) + (meta_ctyp _loc x4) + | Ast.CrIni x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrIni"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.CrInh x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrInh"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1)) + (meta_string _loc x2) + | Ast.CrCtr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrCtr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.CrSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrSem"))) + (meta_loc _loc x0)) + (meta_class_str_item _loc x1)) + (meta_class_str_item _loc x2) + | Ast.CrNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CrNil"))) + (meta_loc _loc x0) ] + and meta_class_type _loc = + fun + [ Ast.CtAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.CtEq x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtEq"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtCol x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtCol"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtAnd"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1)) + (meta_class_type _loc x2) + | Ast.CtSig x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtSig"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_class_sig_item _loc x2) + | Ast.CtFun x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtFun"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_class_type _loc x2) + | Ast.CtCon x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtCon"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_ident _loc x2)) + (meta_ctyp _loc x3) + | Ast.CtNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "CtNil"))) + (meta_loc _loc x0) ] + and meta_ctyp _loc = + fun + [ Ast.TyAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.TyOfAmp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOfAmp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAmp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAmp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyVrnInfSup x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnInfSup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyVrnInf x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnInf"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrnSup x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnSup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrnEq x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrnEq"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TySta x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySta"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyTup x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyTup"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyMut x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyMut"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyPrv x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyPrv"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyOr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAnd"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyOf x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOf"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TySum x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySum"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyCom x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCom"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TySem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TySem"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyCol x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCol"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyRec x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyRec"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.TyVrn x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuM x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuM"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuP x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuP"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyQuo x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyQuo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.TyPol x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyPol"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyOlb x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyObj x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyObj"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_meta_bool _loc x2) + | Ast.TyDcl x0 x1 x2 x3 x4 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyDcl"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_list meta_ctyp _loc x2)) + (meta_ctyp _loc x3)) + (meta_list + (fun _loc (x1, x2) -> + Ast.PaTup _loc + (Ast.PaCom _loc (meta_ctyp _loc x1) + (meta_ctyp _loc x2))) + _loc x4) + | Ast.TyMan x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyMan"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyId x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.TyLab x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyCls x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyCls"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.TyArr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyArr"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyApp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyAny x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAny"))) + (meta_loc _loc x0) + | Ast.TyAli x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyAli"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.TyNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "TyNil"))) + (meta_loc _loc x0) ] + and meta_expr _loc = + fun + [ Ast.ExWhi x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExWhi"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExVrn x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExTyc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTyc"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_ctyp _loc x2) + | Ast.ExCom x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExCom"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExTup x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTup"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExTry x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExTry"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_match_case _loc x2) + | Ast.ExStr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExStr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExSte x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSte"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExSnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSnd"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_string _loc x2) + | Ast.ExSeq x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSeq"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExRec x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExRec"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1)) + (meta_expr _loc x2) + | Ast.ExOvr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExOvr"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1) + | Ast.ExOlb x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.ExObj x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExObj"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_class_str_item _loc x2) + | Ast.ExNew x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNew"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.ExMat x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExMat"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_match_case _loc x2) + | Ast.ExLmd x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLmd"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_expr _loc x2)) + (meta_expr _loc x3) + | Ast.ExLet x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLet"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2)) + (meta_expr _loc x3) + | Ast.ExLaz x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLaz"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExLab x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.ExNativeInt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNativeInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt64 x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt64"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt32 x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt32"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExInt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExIfe x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExIfe"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3) + | Ast.ExFun x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFun"))) + (meta_loc _loc x0)) + (meta_match_case _loc x1) + | Ast.ExFor x0 x1 x2 x3 x4 x5 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc + (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFor"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3)) + (meta_meta_bool _loc x4)) + (meta_expr _loc x5) + | Ast.ExFlo x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExFlo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExCoe x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExCoe"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_ctyp _loc x2)) + (meta_ctyp _loc x3) + | Ast.ExChr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExChr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.ExAss x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAss"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExAsr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAsr"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExAsf x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAsf"))) + (meta_loc _loc x0) + | Ast.ExSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExSem"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExArr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExArr"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.ExAre x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAre"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExApp"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.ExAcc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExAcc"))) + (meta_loc _loc x0)) + (meta_expr _loc x1)) + (meta_expr _loc x2) + | Ast.ExId x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.ExNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ExNil"))) + (meta_loc _loc x0) ] + and meta_ident _loc = + fun + [ Ast.IdAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.IdUid x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdUid"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.IdLid x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdLid"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.IdApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdApp"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) + | Ast.IdAcc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "IdAcc"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) ] + and meta_match_case _loc = + fun + [ Ast.McAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.McArr x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McArr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_expr _loc x2)) + (meta_expr _loc x3) + | Ast.McOr x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McOr"))) + (meta_loc _loc x0)) + (meta_match_case _loc x1)) + (meta_match_case _loc x2) + | Ast.McNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "McNil"))) + (meta_loc _loc x0) ] + and meta_meta_bool _loc = + fun + [ Ast.BAnt x0 -> Ast.PaAnt _loc x0 + | Ast.BFalse -> + Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BFalse")) + | Ast.BTrue -> + Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "BTrue")) ] + and meta_meta_list mf_a _loc = + fun + [ Ast.LAnt x0 -> Ast.PaAnt _loc x0 + | Ast.LCons x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "LCons"))) + (mf_a _loc x0)) + (meta_meta_list mf_a _loc x1) + | Ast.LNil -> + Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "LNil")) ] + and meta_meta_option mf_a _loc = + fun + [ Ast.OAnt x0 -> Ast.PaAnt _loc x0 + | Ast.OSome x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "OSome"))) + (mf_a _loc x0) + | Ast.ONone -> + Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "ONone")) ] + and meta_module_binding _loc = + fun + [ Ast.MbAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.MbCol x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbCol"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.MbColEq x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbColEq"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_expr _loc x3) + | Ast.MbAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbAnd"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1)) + (meta_module_binding _loc x2) + | Ast.MbNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MbNil"))) + (meta_loc _loc x0) ] + and meta_module_expr _loc = + fun + [ Ast.MeAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.MeTyc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeTyc"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1)) + (meta_module_type _loc x2) + | Ast.MeStr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeStr"))) + (meta_loc _loc x0)) + (meta_str_item _loc x1) + | Ast.MeFun x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeFun"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_expr _loc x3) + | Ast.MeApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeApp"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1)) + (meta_module_expr _loc x2) + | Ast.MeId x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.MeNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MeNil"))) + (meta_loc _loc x0) ] + and meta_module_type _loc = + fun + [ Ast.MtAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.MtWit x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtWit"))) + (meta_loc _loc x0)) + (meta_module_type _loc x1)) + (meta_with_constr _loc x2) + | Ast.MtSig x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtSig"))) + (meta_loc _loc x0)) + (meta_sig_item _loc x1) + | Ast.MtQuo x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtQuo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.MtFun x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtFun"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2)) + (meta_module_type _loc x3) + | Ast.MtId x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.MtNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "MtNil"))) + (meta_loc _loc x0) ] + and meta_patt _loc = + fun + [ Ast.PaLaz x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaLaz"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaVrn x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaVrn"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaTyp x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTyp"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.PaTyc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTyc"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_ctyp _loc x2) + | Ast.PaTup x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaTup"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaStr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaStr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaEq x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaEq"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_patt _loc x2) + | Ast.PaRec x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaRec"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaRng x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaRng"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaOrp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOrp"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaOlbi x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOlbi"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2)) + (meta_expr _loc x3) + | Ast.PaOlb x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaOlb"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2) + | Ast.PaLab x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaLab"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_patt _loc x2) + | Ast.PaFlo x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaFlo"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaNativeInt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaNativeInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt64 x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt64"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt32 x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt32"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaInt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaInt"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaChr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaChr"))) + (meta_loc _loc x0)) + (meta_string _loc x1) + | Ast.PaSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaSem"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaCom x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaCom"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaArr x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaArr"))) + (meta_loc _loc x0)) + (meta_patt _loc x1) + | Ast.PaApp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaApp"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaAny x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaAny"))) + (meta_loc _loc x0) + | Ast.PaAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.PaAli x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaAli"))) + (meta_loc _loc x0)) + (meta_patt _loc x1)) + (meta_patt _loc x2) + | Ast.PaId x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaId"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.PaNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "PaNil"))) + (meta_loc _loc x0) ] + and meta_rec_binding _loc = + fun + [ Ast.RbAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.RbEq x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbEq"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_expr _loc x2) + | Ast.RbSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbSem"))) + (meta_loc _loc x0)) + (meta_rec_binding _loc x1)) + (meta_rec_binding _loc x2) + | Ast.RbNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "RbNil"))) + (meta_loc _loc x0) ] + and meta_sig_item _loc = + fun + [ Ast.SgAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.SgVal x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgVal"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2) + | Ast.SgTyp x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.SgOpn x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgOpn"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.SgMty x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgMty"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.SgRecMod x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgRecMod"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1) + | Ast.SgMod x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgMod"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.SgInc x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgInc"))) + (meta_loc _loc x0)) + (meta_module_type _loc x1) + | Ast.SgExt x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgExt"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2)) + (meta_meta_list meta_string _loc x3) + | Ast.SgExc x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgExc"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.SgDir x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgDir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.SgSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgSem"))) + (meta_loc _loc x0)) + (meta_sig_item _loc x1)) + (meta_sig_item _loc x2) + | Ast.SgClt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgClt"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.SgCls x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgCls"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.SgNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "SgNil"))) + (meta_loc _loc x0) ] + and meta_str_item _loc = + fun + [ Ast.StAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.StVal x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StVal"))) + (meta_loc _loc x0)) + (meta_meta_bool _loc x1)) + (meta_binding _loc x2) + | Ast.StTyp x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1) + | Ast.StOpn x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StOpn"))) + (meta_loc _loc x0)) + (meta_ident _loc x1) + | Ast.StMty x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StMty"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_type _loc x2) + | Ast.StRecMod x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StRecMod"))) + (meta_loc _loc x0)) + (meta_module_binding _loc x1) + | Ast.StMod x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StMod"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_module_expr _loc x2) + | Ast.StInc x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StInc"))) + (meta_loc _loc x0)) + (meta_module_expr _loc x1) + | Ast.StExt x0 x1 x2 x3 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExt"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_ctyp _loc x2)) + (meta_meta_list meta_string _loc x3) + | Ast.StExp x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExp"))) + (meta_loc _loc x0)) + (meta_expr _loc x1) + | Ast.StExc x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StExc"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_meta_option meta_ident _loc x2) + | Ast.StDir x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StDir"))) + (meta_loc _loc x0)) + (meta_string _loc x1)) + (meta_expr _loc x2) + | Ast.StSem x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StSem"))) + (meta_loc _loc x0)) + (meta_str_item _loc x1)) + (meta_str_item _loc x2) + | Ast.StClt x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StClt"))) + (meta_loc _loc x0)) + (meta_class_type _loc x1) + | Ast.StCls x0 x1 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StCls"))) + (meta_loc _loc x0)) + (meta_class_expr _loc x1) + | Ast.StNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "StNil"))) + (meta_loc _loc x0) ] + and meta_with_constr _loc = + fun + [ Ast.WcAnt x0 x1 -> Ast.PaAnt x0 x1 + | Ast.WcAnd x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcAnd"))) + (meta_loc _loc x0)) + (meta_with_constr _loc x1)) + (meta_with_constr _loc x2) + | Ast.WcMod x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcMod"))) + (meta_loc _loc x0)) + (meta_ident _loc x1)) + (meta_ident _loc x2) + | Ast.WcTyp x0 x1 x2 -> + Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcTyp"))) + (meta_loc _loc x0)) + (meta_ctyp _loc x1)) + (meta_ctyp _loc x2) + | Ast.WcNil x0 -> + Ast.PaApp _loc + (Ast.PaId _loc + (Ast.IdAcc _loc (Ast.IdUid _loc "Ast") + (Ast.IdUid _loc "WcNil"))) + (meta_loc _loc x0) ]; + end; + end; + end; + class map = + object ((o : 'self_type)) + method string : string -> string = o#unknown; + method list : + ! 'a 'a_out. ('self_type -> 'a -> 'a_out) -> list 'a -> list 'a_out = + fun _f_a -> + fun + [ [] -> [] + | [ _x :: _x_i1 ] -> + let _x = _f_a o _x in + let _x_i1 = o#list _f_a _x_i1 in [ _x :: _x_i1 ] ]; + method with_constr : with_constr -> with_constr = + fun + [ WcNil _x -> let _x = o#loc _x in WcNil _x + | WcTyp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in WcTyp _x _x_i1 _x_i2 + | WcMod _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in WcMod _x _x_i1 _x_i2 + | WcAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#with_constr _x_i1 in + let _x_i2 = o#with_constr _x_i2 in WcAnd _x _x_i1 _x_i2 + | WcAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in WcAnt _x _x_i1 ]; + method str_item : str_item -> str_item = + fun + [ StNil _x -> let _x = o#loc _x in StNil _x + | StCls _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in StCls _x _x_i1 + | StClt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in StClt _x _x_i1 + | StSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#str_item _x_i1 in + let _x_i2 = o#str_item _x_i2 in StSem _x _x_i1 _x_i2 + | StDir _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in StDir _x _x_i1 _x_i2 + | StExc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#meta_option (fun o -> o#ident) _x_i2 + in StExc _x _x_i1 _x_i2 + | StExp _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in StExp _x _x_i1 + | StExt _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#meta_list (fun o -> o#string) _x_i3 + in StExt _x _x_i1 _x_i2 _x_i3 + | StInc _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in StInc _x _x_i1 + | StMod _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_expr _x_i2 in StMod _x _x_i1 _x_i2 + | StRecMod _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 in StRecMod _x _x_i1 + | StMty _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in StMty _x _x_i1 _x_i2 + | StOpn _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in StOpn _x _x_i1 + | StTyp _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in StTyp _x _x_i1 + | StVal _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in StVal _x _x_i1 _x_i2 + | StAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in StAnt _x _x_i1 ]; + method sig_item : sig_item -> sig_item = + fun + [ SgNil _x -> let _x = o#loc _x in SgNil _x + | SgCls _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in SgCls _x _x_i1 + | SgClt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in SgClt _x _x_i1 + | SgSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#sig_item _x_i1 in + let _x_i2 = o#sig_item _x_i2 in SgSem _x _x_i1 _x_i2 + | SgDir _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in SgDir _x _x_i1 _x_i2 + | SgExc _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in SgExc _x _x_i1 + | SgExt _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#meta_list (fun o -> o#string) _x_i3 + in SgExt _x _x_i1 _x_i2 _x_i3 + | SgInc _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#module_type _x_i1 in SgInc _x _x_i1 + | SgMod _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in SgMod _x _x_i1 _x_i2 + | SgRecMod _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 in SgRecMod _x _x_i1 + | SgMty _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in SgMty _x _x_i1 _x_i2 + | SgOpn _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in SgOpn _x _x_i1 + | SgTyp _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in SgTyp _x _x_i1 + | SgVal _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in SgVal _x _x_i1 _x_i2 + | SgAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in SgAnt _x _x_i1 ]; + method rec_binding : rec_binding -> rec_binding = + fun + [ RbNil _x -> let _x = o#loc _x in RbNil _x + | RbSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in + let _x_i2 = o#rec_binding _x_i2 in RbSem _x _x_i1 _x_i2 + | RbEq _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#expr _x_i2 in RbEq _x _x_i1 _x_i2 + | RbAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in RbAnt _x _x_i1 ]; + method patt : patt -> patt = + fun + [ PaNil _x -> let _x = o#loc _x in PaNil _x + | PaId _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ident _x_i1 in PaId _x _x_i1 + | PaAli _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaAli _x _x_i1 _x_i2 + | PaAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaAnt _x _x_i1 + | PaAny _x -> let _x = o#loc _x in PaAny _x + | PaApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaApp _x _x_i1 _x_i2 + | PaArr _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#patt _x_i1 in PaArr _x _x_i1 + | PaCom _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaCom _x _x_i1 _x_i2 + | PaSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaSem _x _x_i1 _x_i2 + | PaChr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaChr _x _x_i1 + | PaInt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt _x _x_i1 + | PaInt32 _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt32 _x _x_i1 + | PaInt64 _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaInt64 _x _x_i1 + | PaNativeInt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaNativeInt _x _x_i1 + | PaFlo _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaFlo _x _x_i1 + | PaLab _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in PaLab _x _x_i1 _x_i2 + | PaOlb _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in PaOlb _x _x_i1 _x_i2 + | PaOlbi _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#patt _x_i2 in + let _x_i3 = o#expr _x_i3 in PaOlbi _x _x_i1 _x_i2 _x_i3 + | PaOrp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaOrp _x _x_i1 _x_i2 + | PaRng _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#patt _x_i2 in PaRng _x _x_i1 _x_i2 + | PaRec _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#patt _x_i1 in PaRec _x _x_i1 + | PaEq _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#patt _x_i2 in PaEq _x _x_i1 _x_i2 + | PaStr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaStr _x _x_i1 + | PaTup _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#patt _x_i1 in PaTup _x _x_i1 + | PaTyc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#ctyp _x_i2 in PaTyc _x _x_i1 _x_i2 + | PaTyp _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in PaTyp _x _x_i1 + | PaVrn _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in PaVrn _x _x_i1 + | PaLaz _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#patt _x_i1 in PaLaz _x _x_i1 ]; + method module_type : module_type -> module_type = + fun + [ MtNil _x -> let _x = o#loc _x in MtNil _x + | MtId _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ident _x_i1 in MtId _x _x_i1 + | MtFun _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_type _x_i3 in MtFun _x _x_i1 _x_i2 _x_i3 + | MtQuo _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MtQuo _x _x_i1 + | MtSig _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#sig_item _x_i1 in MtSig _x _x_i1 + | MtWit _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#module_type _x_i1 in + let _x_i2 = o#with_constr _x_i2 in MtWit _x _x_i1 _x_i2 + | MtAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MtAnt _x _x_i1 ]; + method module_expr : module_expr -> module_expr = + fun + [ MeNil _x -> let _x = o#loc _x in MeNil _x + | MeId _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ident _x_i1 in MeId _x _x_i1 + | MeApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in + let _x_i2 = o#module_expr _x_i2 in MeApp _x _x_i1 _x_i2 + | MeFun _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_expr _x_i3 in MeFun _x _x_i1 _x_i2 _x_i3 + | MeStr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#str_item _x_i1 in MeStr _x _x_i1 + | MeTyc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#module_expr _x_i1 in + let _x_i2 = o#module_type _x_i2 in MeTyc _x _x_i1 _x_i2 + | MeAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MeAnt _x _x_i1 ]; + method module_binding : module_binding -> module_binding = + fun + [ MbNil _x -> let _x = o#loc _x in MbNil _x + | MbAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#module_binding _x_i1 in + let _x_i2 = o#module_binding _x_i2 in MbAnd _x _x_i1 _x_i2 + | MbColEq _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in + let _x_i3 = o#module_expr _x_i3 in MbColEq _x _x_i1 _x_i2 _x_i3 + | MbCol _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_type _x_i2 in MbCol _x _x_i1 _x_i2 + | MbAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in MbAnt _x _x_i1 ]; + method meta_option : + ! 'a 'a_out. + ('self_type -> 'a -> 'a_out) -> + meta_option 'a -> meta_option 'a_out = + fun _f_a -> + fun + [ ONone -> ONone + | OSome _x -> let _x = _f_a o _x in OSome _x + | OAnt _x -> let _x = o#string _x in OAnt _x ]; + method meta_list : + ! 'a 'a_out. + ('self_type -> 'a -> 'a_out) -> meta_list 'a -> meta_list 'a_out = + fun _f_a -> + fun + [ LNil -> LNil + | LCons _x _x_i1 -> + let _x = _f_a o _x in + let _x_i1 = o#meta_list _f_a _x_i1 in LCons _x _x_i1 + | LAnt _x -> let _x = o#string _x in LAnt _x ]; + method meta_bool : meta_bool -> meta_bool = + fun + [ BTrue -> BTrue + | BFalse -> BFalse + | BAnt _x -> let _x = o#string _x in BAnt _x ]; + method match_case : match_case -> match_case = + fun + [ McNil _x -> let _x = o#loc _x in McNil _x + | McOr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#match_case _x_i1 in + let _x_i2 = o#match_case _x_i2 in McOr _x _x_i1 _x_i2 + | McArr _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 in McArr _x _x_i1 _x_i2 _x_i3 + | McAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in McAnt _x _x_i1 ]; + method loc : loc -> loc = o#unknown; + method ident : ident -> ident = + fun + [ IdAcc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in IdAcc _x _x_i1 _x_i2 + | IdApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in + let _x_i2 = o#ident _x_i2 in IdApp _x _x_i1 _x_i2 + | IdLid _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdLid _x _x_i1 + | IdUid _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdUid _x _x_i1 + | IdAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in IdAnt _x _x_i1 ]; + method expr : expr -> expr = + fun + [ ExNil _x -> let _x = o#loc _x in ExNil _x + | ExId _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ident _x_i1 in ExId _x _x_i1 + | ExAcc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAcc _x _x_i1 _x_i2 + | ExAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExAnt _x _x_i1 + | ExApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExApp _x _x_i1 _x_i2 + | ExAre _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAre _x _x_i1 _x_i2 + | ExArr _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in ExArr _x _x_i1 + | ExSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExSem _x _x_i1 _x_i2 + | ExAsf _x -> let _x = o#loc _x in ExAsf _x + | ExAsr _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in ExAsr _x _x_i1 + | ExAss _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExAss _x _x_i1 _x_i2 + | ExChr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExChr _x _x_i1 + | ExCoe _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#ctyp _x_i2 in + let _x_i3 = o#ctyp _x_i3 in ExCoe _x _x_i1 _x_i2 _x_i3 + | ExFlo _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExFlo _x _x_i1 + | ExFor _x _x_i1 _x_i2 _x_i3 _x_i4 _x_i5 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 in + let _x_i4 = o#meta_bool _x_i4 in + let _x_i5 = o#expr _x_i5 + in ExFor _x _x_i1 _x_i2 _x_i3 _x_i4 _x_i5 + | ExFun _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#match_case _x_i1 in ExFun _x _x_i1 + | ExIfe _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in + let _x_i3 = o#expr _x_i3 in ExIfe _x _x_i1 _x_i2 _x_i3 + | ExInt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt _x _x_i1 + | ExInt32 _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt32 _x _x_i1 + | ExInt64 _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExInt64 _x _x_i1 + | ExNativeInt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExNativeInt _x _x_i1 + | ExLab _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in ExLab _x _x_i1 _x_i2 + | ExLaz _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in ExLaz _x _x_i1 + | ExLet _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in + let _x_i3 = o#expr _x_i3 in ExLet _x _x_i1 _x_i2 _x_i3 + | ExLmd _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#module_expr _x_i2 in + let _x_i3 = o#expr _x_i3 in ExLmd _x _x_i1 _x_i2 _x_i3 + | ExMat _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#match_case _x_i2 in ExMat _x _x_i1 _x_i2 + | ExNew _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in ExNew _x _x_i1 + | ExObj _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_str_item _x_i2 in ExObj _x _x_i1 _x_i2 + | ExOlb _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#expr _x_i2 in ExOlb _x _x_i1 _x_i2 + | ExOvr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in ExOvr _x _x_i1 + | ExRec _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#rec_binding _x_i1 in + let _x_i2 = o#expr _x_i2 in ExRec _x _x_i1 _x_i2 + | ExSeq _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in ExSeq _x _x_i1 + | ExSnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#string _x_i2 in ExSnd _x _x_i1 _x_i2 + | ExSte _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExSte _x _x_i1 _x_i2 + | ExStr _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExStr _x _x_i1 + | ExTry _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#match_case _x_i2 in ExTry _x _x_i1 _x_i2 + | ExTup _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in ExTup _x _x_i1 + | ExCom _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExCom _x _x_i1 _x_i2 + | ExTyc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#ctyp _x_i2 in ExTyc _x _x_i1 _x_i2 + | ExVrn _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in ExVrn _x _x_i1 + | ExWhi _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#expr _x_i1 in + let _x_i2 = o#expr _x_i2 in ExWhi _x _x_i1 _x_i2 ]; + method ctyp : ctyp -> ctyp = + fun + [ TyNil _x -> let _x = o#loc _x in TyNil _x + | TyAli _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAli _x _x_i1 _x_i2 + | TyAny _x -> let _x = o#loc _x in TyAny _x + | TyApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyApp _x _x_i1 _x_i2 + | TyArr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyArr _x _x_i1 _x_i2 + | TyCls _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ident _x_i1 in TyCls _x _x_i1 + | TyLab _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyLab _x _x_i1 _x_i2 + | TyId _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ident _x_i1 in TyId _x _x_i1 + | TyMan _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyMan _x _x_i1 _x_i2 + | TyDcl _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#list (fun o -> o#ctyp) _x_i2 in + let _x_i3 = o#ctyp _x_i3 in + let _x_i4 = + o#list + (fun o (_x, _x_i1) -> + let _x = o#ctyp _x in + let _x_i1 = o#ctyp _x_i1 in (_x, _x_i1)) + _x_i4 + in TyDcl _x _x_i1 _x_i2 _x_i3 _x_i4 + | TyObj _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in TyObj _x _x_i1 _x_i2 + | TyOlb _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOlb _x _x_i1 _x_i2 + | TyPol _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyPol _x _x_i1 _x_i2 + | TyQuo _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuo _x _x_i1 + | TyQuP _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuP _x _x_i1 + | TyQuM _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyQuM _x _x_i1 + | TyVrn _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyVrn _x _x_i1 + | TyRec _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in TyRec _x _x_i1 + | TyCol _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyCol _x _x_i1 _x_i2 + | TySem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TySem _x _x_i1 _x_i2 + | TyCom _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyCom _x _x_i1 _x_i2 + | TySum _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in TySum _x _x_i1 + | TyOf _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOf _x _x_i1 _x_i2 + | TyAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAnd _x _x_i1 _x_i2 + | TyOr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOr _x _x_i1 _x_i2 + | TyPrv _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in TyPrv _x _x_i1 + | TyMut _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in TyMut _x _x_i1 + | TyTup _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#ctyp _x_i1 in TyTup _x _x_i1 + | TySta _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TySta _x _x_i1 _x_i2 + | TyVrnEq _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnEq _x _x_i1 + | TyVrnSup _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnSup _x _x_i1 + | TyVrnInf _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in TyVrnInf _x _x_i1 + | TyVrnInfSup _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyVrnInfSup _x _x_i1 _x_i2 + | TyAmp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyAmp _x _x_i1 _x_i2 + | TyOfAmp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in TyOfAmp _x _x_i1 _x_i2 + | TyAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in TyAnt _x _x_i1 ]; + method class_type : class_type -> class_type = + fun + [ CtNil _x -> let _x = o#loc _x in CtNil _x + | CtCon _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#ident _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CtCon _x _x_i1 _x_i2 _x_i3 + | CtFun _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#class_type _x_i2 in CtFun _x _x_i1 _x_i2 + | CtSig _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#class_sig_item _x_i2 in CtSig _x _x_i1 _x_i2 + | CtAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 in CtAnd _x _x_i1 _x_i2 + | CtCol _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 in CtCol _x _x_i1 _x_i2 + | CtEq _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in + let _x_i2 = o#class_type _x_i2 in CtEq _x _x_i1 _x_i2 + | CtAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CtAnt _x _x_i1 ]; + method class_str_item : class_str_item -> class_str_item = + fun + [ CrNil _x -> let _x = o#loc _x in CrNil _x + | CrSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_str_item _x_i1 in + let _x_i2 = o#class_str_item _x_i2 in CrSem _x _x_i1 _x_i2 + | CrCtr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in CrCtr _x _x_i1 _x_i2 + | CrInh _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#string _x_i2 in CrInh _x _x_i1 _x_i2 + | CrIni _x _x_i1 -> + let _x = o#loc _x in let _x_i1 = o#expr _x_i1 in CrIni _x _x_i1 + | CrMth _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#expr _x_i3 in + let _x_i4 = o#ctyp _x_i4 in CrMth _x _x_i1 _x_i2 _x_i3 _x_i4 + | CrVal _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#expr _x_i3 in CrVal _x _x_i1 _x_i2 _x_i3 + | CrVir _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CrVir _x _x_i1 _x_i2 _x_i3 + | CrVvr _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CrVvr _x _x_i1 _x_i2 _x_i3 + | CrAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CrAnt _x _x_i1 ]; + method class_sig_item : class_sig_item -> class_sig_item = + fun + [ CgNil _x -> let _x = o#loc _x in CgNil _x + | CgCtr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#ctyp _x_i1 in + let _x_i2 = o#ctyp _x_i2 in CgCtr _x _x_i1 _x_i2 + | CgSem _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_sig_item _x_i1 in + let _x_i2 = o#class_sig_item _x_i2 in CgSem _x _x_i1 _x_i2 + | CgInh _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#class_type _x_i1 in CgInh _x _x_i1 + | CgMth _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CgMth _x _x_i1 _x_i2 _x_i3 + | CgVal _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#meta_bool _x_i3 in + let _x_i4 = o#ctyp _x_i4 in CgVal _x _x_i1 _x_i2 _x_i3 _x_i4 + | CgVir _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in + let _x_i2 = o#meta_bool _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CgVir _x _x_i1 _x_i2 _x_i3 + | CgAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CgAnt _x _x_i1 ]; + method class_expr : class_expr -> class_expr = + fun + [ CeNil _x -> let _x = o#loc _x in CeNil _x + | CeApp _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#expr _x_i2 in CeApp _x _x_i1 _x_i2 + | CeCon _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#ident _x_i2 in + let _x_i3 = o#ctyp _x_i3 in CeCon _x _x_i1 _x_i2 _x_i3 + | CeFun _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_expr _x_i2 in CeFun _x _x_i1 _x_i2 + | CeLet _x _x_i1 _x_i2 _x_i3 -> + let _x = o#loc _x in + let _x_i1 = o#meta_bool _x_i1 in + let _x_i2 = o#binding _x_i2 in + let _x_i3 = o#class_expr _x_i3 in CeLet _x _x_i1 _x_i2 _x_i3 + | CeStr _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#class_str_item _x_i2 in CeStr _x _x_i1 _x_i2 + | CeTyc _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_type _x_i2 in CeTyc _x _x_i1 _x_i2 + | CeAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_expr _x_i2 in CeAnd _x _x_i1 _x_i2 + | CeEq _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#class_expr _x_i1 in + let _x_i2 = o#class_expr _x_i2 in CeEq _x _x_i1 _x_i2 + | CeAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in CeAnt _x _x_i1 ]; + method binding : binding -> binding = + fun + [ BiNil _x -> let _x = o#loc _x in BiNil _x + | BiAnd _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#binding _x_i1 in + let _x_i2 = o#binding _x_i2 in BiAnd _x _x_i1 _x_i2 + | BiEq _x _x_i1 _x_i2 -> + let _x = o#loc _x in + let _x_i1 = o#patt _x_i1 in + let _x_i2 = o#expr _x_i2 in BiEq _x _x_i1 _x_i2 + | BiAnt _x _x_i1 -> + let _x = o#loc _x in + let _x_i1 = o#string _x_i1 in BiAnt _x _x_i1 ]; + method unknown : ! 'a. 'a -> 'a = fun x -> x; + end; + class fold = + object ((o : 'self_type)) + method string : string -> 'self_type = o#unknown; + method list : + ! 'a. ('self_type -> 'a -> 'self_type) -> list 'a -> 'self_type = + fun _f_a -> + fun + [ [] -> o + | [ _x :: _x_i1 ] -> + let o = _f_a o _x in let o = o#list _f_a _x_i1 in o ]; + method with_constr : with_constr -> 'self_type = + fun + [ WcNil _x -> let o = o#loc _x in o + | WcTyp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | WcMod _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | WcAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#with_constr _x_i1 in let o = o#with_constr _x_i2 in o + | WcAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method str_item : str_item -> 'self_type = + fun + [ StNil _x -> let o = o#loc _x in o + | StCls _x _x_i1 -> + let o = o#loc _x in let o = o#class_expr _x_i1 in o + | StClt _x _x_i1 -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | StSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#str_item _x_i1 in let o = o#str_item _x_i2 in o + | StDir _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | StExc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in + let o = o#meta_option (fun o -> o#ident) _x_i2 in o + | StExp _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | StExt _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#ctyp _x_i2 in + let o = o#meta_list (fun o -> o#string) _x_i3 in o + | StInc _x _x_i1 -> + let o = o#loc _x in let o = o#module_expr _x_i1 in o + | StMod _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#module_expr _x_i2 in o + | StRecMod _x _x_i1 -> + let o = o#loc _x in let o = o#module_binding _x_i1 in o + | StMty _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#module_type _x_i2 in o + | StOpn _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | StTyp _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | StVal _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in let o = o#binding _x_i2 in o + | StAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method sig_item : sig_item -> 'self_type = + fun + [ SgNil _x -> let o = o#loc _x in o + | SgCls _x _x_i1 -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | SgClt _x _x_i1 -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | SgSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#sig_item _x_i1 in let o = o#sig_item _x_i2 in o + | SgDir _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | SgExc _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | SgExt _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#ctyp _x_i2 in + let o = o#meta_list (fun o -> o#string) _x_i3 in o + | SgInc _x _x_i1 -> + let o = o#loc _x in let o = o#module_type _x_i1 in o + | SgMod _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#module_type _x_i2 in o + | SgRecMod _x _x_i1 -> + let o = o#loc _x in let o = o#module_binding _x_i1 in o + | SgMty _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#module_type _x_i2 in o + | SgOpn _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | SgTyp _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | SgVal _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | SgAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method rec_binding : rec_binding -> 'self_type = + fun + [ RbNil _x -> let o = o#loc _x in o + | RbSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#rec_binding _x_i1 in let o = o#rec_binding _x_i2 in o + | RbEq _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#expr _x_i2 in o + | RbAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method patt : patt -> 'self_type = + fun + [ PaNil _x -> let o = o#loc _x in o + | PaId _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | PaAli _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaAny _x -> let o = o#loc _x in o + | PaApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaArr _x _x_i1 -> let o = o#loc _x in let o = o#patt _x_i1 in o + | PaCom _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaChr _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt32 _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaInt64 _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaNativeInt _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | PaFlo _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaLab _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#patt _x_i2 in o + | PaOlb _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#patt _x_i2 in o + | PaOlbi _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#patt _x_i2 in let o = o#expr _x_i3 in o + | PaOrp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaRng _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#patt _x_i2 in o + | PaRec _x _x_i1 -> let o = o#loc _x in let o = o#patt _x_i1 in o + | PaEq _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#patt _x_i2 in o + | PaStr _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaTup _x _x_i1 -> let o = o#loc _x in let o = o#patt _x_i1 in o + | PaTyc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#ctyp _x_i2 in o + | PaTyp _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | PaVrn _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | PaLaz _x _x_i1 -> let o = o#loc _x in let o = o#patt _x_i1 in o ]; + method module_type : module_type -> 'self_type = + fun + [ MtNil _x -> let o = o#loc _x in o + | MtId _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | MtFun _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in let o = o#module_type _x_i3 in o + | MtQuo _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | MtSig _x _x_i1 -> + let o = o#loc _x in let o = o#sig_item _x_i1 in o + | MtWit _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#module_type _x_i1 in let o = o#with_constr _x_i2 in o + | MtAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method module_expr : module_expr -> 'self_type = + fun + [ MeNil _x -> let o = o#loc _x in o + | MeId _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | MeApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#module_expr _x_i1 in let o = o#module_expr _x_i2 in o + | MeFun _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in let o = o#module_expr _x_i3 in o + | MeStr _x _x_i1 -> + let o = o#loc _x in let o = o#str_item _x_i1 in o + | MeTyc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#module_expr _x_i1 in let o = o#module_type _x_i2 in o + | MeAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method module_binding : module_binding -> 'self_type = + fun + [ MbNil _x -> let o = o#loc _x in o + | MbAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#module_binding _x_i1 in + let o = o#module_binding _x_i2 in o + | MbColEq _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_type _x_i2 in let o = o#module_expr _x_i3 in o + | MbCol _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#module_type _x_i2 in o + | MbAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method meta_option : + ! 'a. + ('self_type -> 'a -> 'self_type) -> meta_option 'a -> 'self_type = + fun _f_a -> + fun + [ ONone -> o + | OSome _x -> let o = _f_a o _x in o + | OAnt _x -> let o = o#string _x in o ]; + method meta_list : + ! 'a. + ('self_type -> 'a -> 'self_type) -> meta_list 'a -> 'self_type = + fun _f_a -> + fun + [ LNil -> o + | LCons _x _x_i1 -> + let o = _f_a o _x in let o = o#meta_list _f_a _x_i1 in o + | LAnt _x -> let o = o#string _x in o ]; + method meta_bool : meta_bool -> 'self_type = + fun + [ BTrue -> o + | BFalse -> o + | BAnt _x -> let o = o#string _x in o ]; + method match_case : match_case -> 'self_type = + fun + [ McNil _x -> let o = o#loc _x in o + | McOr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#match_case _x_i1 in let o = o#match_case _x_i2 in o + | McArr _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#patt _x_i1 in + let o = o#expr _x_i2 in let o = o#expr _x_i3 in o + | McAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method loc : loc -> 'self_type = o#unknown; + method ident : ident -> 'self_type = + fun + [ IdAcc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | IdApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ident _x_i1 in let o = o#ident _x_i2 in o + | IdLid _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | IdUid _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | IdAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method expr : expr -> 'self_type = + fun + [ ExNil _x -> let o = o#loc _x in o + | ExId _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | ExAcc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAre _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExArr _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | ExSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExAsf _x -> let o = o#loc _x in o + | ExAsr _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | ExAss _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExChr _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExCoe _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#expr _x_i1 in + let o = o#ctyp _x_i2 in let o = o#ctyp _x_i3 in o + | ExFlo _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExFor _x _x_i1 _x_i2 _x_i3 _x_i4 _x_i5 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#expr _x_i2 in + let o = o#expr _x_i3 in + let o = o#meta_bool _x_i4 in let o = o#expr _x_i5 in o + | ExFun _x _x_i1 -> + let o = o#loc _x in let o = o#match_case _x_i1 in o + | ExIfe _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#expr _x_i1 in + let o = o#expr _x_i2 in let o = o#expr _x_i3 in o + | ExInt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExInt32 _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExInt64 _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExNativeInt _x _x_i1 -> + let o = o#loc _x in let o = o#string _x_i1 in o + | ExLab _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | ExLaz _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | ExLet _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#binding _x_i2 in let o = o#expr _x_i3 in o + | ExLmd _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#module_expr _x_i2 in let o = o#expr _x_i3 in o + | ExMat _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#match_case _x_i2 in o + | ExNew _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | ExObj _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#class_str_item _x_i2 in o + | ExOlb _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#expr _x_i2 in o + | ExOvr _x _x_i1 -> + let o = o#loc _x in let o = o#rec_binding _x_i1 in o + | ExRec _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#rec_binding _x_i1 in let o = o#expr _x_i2 in o + | ExSeq _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | ExSnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#string _x_i2 in o + | ExSte _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExStr _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExTry _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#match_case _x_i2 in o + | ExTup _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | ExCom _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o + | ExTyc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#ctyp _x_i2 in o + | ExVrn _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | ExWhi _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#expr _x_i1 in let o = o#expr _x_i2 in o ]; + method ctyp : ctyp -> 'self_type = + fun + [ TyNil _x -> let o = o#loc _x in o + | TyAli _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAny _x -> let o = o#loc _x in o + | TyApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyArr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyCls _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | TyLab _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | TyId _x _x_i1 -> let o = o#loc _x in let o = o#ident _x_i1 in o + | TyMan _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyDcl _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#list (fun o -> o#ctyp) _x_i2 in + let o = o#ctyp _x_i3 in + let o = + o#list + (fun o (_x, _x_i1) -> + let o = o#ctyp _x in let o = o#ctyp _x_i1 in o) + _x_i4 + in o + | TyObj _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#meta_bool _x_i2 in o + | TyOlb _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#string _x_i1 in let o = o#ctyp _x_i2 in o + | TyPol _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyQuo _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | TyQuP _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | TyQuM _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | TyVrn _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o + | TyRec _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyCol _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TySem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyCom _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TySum _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyOf _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyOr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyPrv _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyMut _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyTup _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TySta _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyVrnEq _x _x_i1 -> let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnSup _x _x_i1 -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnInf _x _x_i1 -> + let o = o#loc _x in let o = o#ctyp _x_i1 in o + | TyVrnInfSup _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAmp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyOfAmp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | TyAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method class_type : class_type -> 'self_type = + fun + [ CtNil _x -> let o = o#loc _x in o + | CtCon _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#ident _x_i2 in let o = o#ctyp _x_i3 in o + | CtFun _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#class_type _x_i2 in o + | CtSig _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#class_sig_item _x_i2 in o + | CtAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_type _x_i1 in let o = o#class_type _x_i2 in o + | CtCol _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_type _x_i1 in let o = o#class_type _x_i2 in o + | CtEq _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_type _x_i1 in let o = o#class_type _x_i2 in o + | CtAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method class_str_item : class_str_item -> 'self_type = + fun + [ CrNil _x -> let o = o#loc _x in o + | CrSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_str_item _x_i1 in + let o = o#class_str_item _x_i2 in o + | CrCtr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | CrInh _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#string _x_i2 in o + | CrIni _x _x_i1 -> let o = o#loc _x in let o = o#expr _x_i1 in o + | CrMth _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in + let o = o#expr _x_i3 in let o = o#ctyp _x_i4 in o + | CrVal _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#expr _x_i3 in o + | CrVir _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CrVvr _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CrAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method class_sig_item : class_sig_item -> 'self_type = + fun + [ CgNil _x -> let o = o#loc _x in o + | CgCtr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#ctyp _x_i1 in let o = o#ctyp _x_i2 in o + | CgSem _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_sig_item _x_i1 in + let o = o#class_sig_item _x_i2 in o + | CgInh _x _x_i1 -> + let o = o#loc _x in let o = o#class_type _x_i1 in o + | CgMth _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CgVal _x _x_i1 _x_i2 _x_i3 _x_i4 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in + let o = o#meta_bool _x_i3 in let o = o#ctyp _x_i4 in o + | CgVir _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#string _x_i1 in + let o = o#meta_bool _x_i2 in let o = o#ctyp _x_i3 in o + | CgAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method class_expr : class_expr -> 'self_type = + fun + [ CeNil _x -> let o = o#loc _x in o + | CeApp _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#expr _x_i2 in o + | CeCon _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#ident _x_i2 in let o = o#ctyp _x_i3 in o + | CeFun _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#class_expr _x_i2 in o + | CeLet _x _x_i1 _x_i2 _x_i3 -> + let o = o#loc _x in + let o = o#meta_bool _x_i1 in + let o = o#binding _x_i2 in let o = o#class_expr _x_i3 in o + | CeStr _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#class_str_item _x_i2 in o + | CeTyc _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#class_type _x_i2 in o + | CeAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#class_expr _x_i2 in o + | CeEq _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#class_expr _x_i1 in let o = o#class_expr _x_i2 in o + | CeAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method binding : binding -> 'self_type = + fun + [ BiNil _x -> let o = o#loc _x in o + | BiAnd _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#binding _x_i1 in let o = o#binding _x_i2 in o + | BiEq _x _x_i1 _x_i2 -> + let o = o#loc _x in + let o = o#patt _x_i1 in let o = o#expr _x_i2 in o + | BiAnt _x _x_i1 -> let o = o#loc _x in let o = o#string _x_i1 in o ]; + method unknown : ! 'a. 'a -> 'self_type = fun _ -> o; + end; + value map_expr f = + object inherit map as super; method expr = fun x -> f (super#expr x); + end; + value map_patt f = + object inherit map as super; method patt = fun x -> f (super#patt x); + end; + value map_ctyp f = + object inherit map as super; method ctyp = fun x -> f (super#ctyp x); + end; + value map_str_item f = + object + inherit map as super; + method str_item = fun x -> f (super#str_item x); + end; + value map_sig_item f = + object + inherit map as super; + method sig_item = fun x -> f (super#sig_item x); + end; + value map_loc f = + object inherit map as super; method loc = fun x -> f (super#loc x); end; + end; + diff --git a/camlp4/boot/Makefile b/camlp4/boot/Makefile new file mode 100644 index 0000000..b6a1463 --- /dev/null +++ b/camlp4/boot/Makefile @@ -0,0 +1,24 @@ + + +MAX_SAVE = 10 + +backup: + cp camlp4boot camlp4boot.save.0 + set -e; for i in camlp4boot.save.*; do \ + mv $$i camlp4boot.evas.$$((`echo $$i | sed -e 's/.*\.save\.\([0-9][0-9]*\)/\1/'` + 1)); \ + done + set -e; for i in camlp4boot.evas.*; do mv $$i $${i/.evas./.save.}; done + rm -f camlp4boot.save.$(MAX_SAVE) + +restore: + set -e; for i in camlp4boot.save.*; do \ + mv $$i camlp4boot.evas.$$((`echo $$i | sed -e 's/.*\.save\.\([0-9][0-9]*\)/\1/'` - 1)); \ + done + set -e; for i in camlp4boot.evas.*; do mv $$i $${i/.evas./.save.}; done + mv camlp4boot.save.0 camlp4boot + +boot-clean: + rm -f camlp4boot.save.* camlp4boot.evas.* + +maintainer-clean: + rm -f camlp4boot diff --git a/camlp4/boot/camlp4boot.ml b/camlp4/boot/camlp4boot.ml new file mode 100644 index 0000000..0167cef --- /dev/null +++ b/camlp4/boot/camlp4boot.ml @@ -0,0 +1,14596 @@ +module R = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2002-2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + module Id = + struct let name = "Camlp4OCamlRevisedParser" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + (* Camlp4_config.constructors_arity.val := True; *) + let _ = Camlp4_config.constructors_arity := false + + let help_sequences () = + (Printf.eprintf + "\ +New syntax: + (e1; e2; ... ; en) OR begin e1; e2; ... ; en end + while e do e1; e2; ... ; en done + for v = v1 to/downto v2 do e1; e2; ... ; en done +Old syntax (still supported): + do {e1; e2; ... ; en} + while e do {e1; e2; ... ; en} + for v = v1 to/downto v2 do {e1; e2; ... ; en} +Very old (no more supported) syntax: + do e1; e2; ... ; en-1; return en + while e do e1; e2; ... ; en; done + for v = v1 to/downto v2 do e1; e2; ... ; en; done + "; + flush stderr; + exit 1) + + let _ = + Options.add "-help_seq" (Arg.Unit help_sequences) + "Print explanations about new sequences and exit." + + let _ = Gram.Entry.clear a_CHAR + + let _ = Gram.Entry.clear a_FLOAT + + let _ = Gram.Entry.clear a_INT + + let _ = Gram.Entry.clear a_INT32 + + let _ = Gram.Entry.clear a_INT64 + + let _ = Gram.Entry.clear a_LABEL + + let _ = Gram.Entry.clear a_LIDENT + + let _ = Gram.Entry.clear a_NATIVEINT + + let _ = Gram.Entry.clear a_OPTLABEL + + let _ = Gram.Entry.clear a_STRING + + let _ = Gram.Entry.clear a_UIDENT + + let _ = Gram.Entry.clear a_ident + + let _ = Gram.Entry.clear amp_ctyp + + let _ = Gram.Entry.clear and_ctyp + + let _ = Gram.Entry.clear match_case + + let _ = Gram.Entry.clear match_case0 + + let _ = Gram.Entry.clear match_case_quot + + let _ = Gram.Entry.clear binding + + let _ = Gram.Entry.clear binding_quot + + let _ = Gram.Entry.clear rec_binding_quot + + let _ = Gram.Entry.clear class_declaration + + let _ = Gram.Entry.clear class_description + + let _ = Gram.Entry.clear class_expr + + let _ = Gram.Entry.clear class_expr_quot + + let _ = Gram.Entry.clear class_fun_binding + + let _ = Gram.Entry.clear class_fun_def + + let _ = Gram.Entry.clear class_info_for_class_expr + + let _ = Gram.Entry.clear class_info_for_class_type + + let _ = Gram.Entry.clear class_longident + + let _ = Gram.Entry.clear class_longident_and_param + + let _ = Gram.Entry.clear class_name_and_param + + let _ = Gram.Entry.clear class_sig_item + + let _ = Gram.Entry.clear class_sig_item_quot + + let _ = Gram.Entry.clear class_signature + + let _ = Gram.Entry.clear class_str_item + + let _ = Gram.Entry.clear class_str_item_quot + + let _ = Gram.Entry.clear class_structure + + let _ = Gram.Entry.clear class_type + + let _ = Gram.Entry.clear class_type_declaration + + let _ = Gram.Entry.clear class_type_longident + + let _ = Gram.Entry.clear class_type_longident_and_param + + let _ = Gram.Entry.clear class_type_plus + + let _ = Gram.Entry.clear class_type_quot + + let _ = Gram.Entry.clear comma_ctyp + + let _ = Gram.Entry.clear comma_expr + + let _ = Gram.Entry.clear comma_ipatt + + let _ = Gram.Entry.clear comma_patt + + let _ = Gram.Entry.clear comma_type_parameter + + let _ = Gram.Entry.clear constrain + + let _ = Gram.Entry.clear constructor_arg_list + + let _ = Gram.Entry.clear constructor_declaration + + let _ = Gram.Entry.clear constructor_declarations + + let _ = Gram.Entry.clear ctyp + + let _ = Gram.Entry.clear ctyp_quot + + let _ = Gram.Entry.clear cvalue_binding + + let _ = Gram.Entry.clear direction_flag + + let _ = Gram.Entry.clear dummy + + let _ = Gram.Entry.clear eq_expr + + let _ = Gram.Entry.clear expr + + let _ = Gram.Entry.clear expr_eoi + + let _ = Gram.Entry.clear expr_quot + + let _ = Gram.Entry.clear field_expr + + let _ = Gram.Entry.clear field_expr_list + + let _ = Gram.Entry.clear fun_binding + + let _ = Gram.Entry.clear fun_def + + let _ = Gram.Entry.clear ident + + let _ = Gram.Entry.clear ident_quot + + let _ = Gram.Entry.clear implem + + let _ = Gram.Entry.clear interf + + let _ = Gram.Entry.clear ipatt + + let _ = Gram.Entry.clear ipatt_tcon + + let _ = Gram.Entry.clear label + + let _ = Gram.Entry.clear label_declaration + + let _ = Gram.Entry.clear label_declaration_list + + let _ = Gram.Entry.clear label_expr_list + + let _ = Gram.Entry.clear label_expr + + let _ = Gram.Entry.clear label_ipatt + + let _ = Gram.Entry.clear label_ipatt_list + + let _ = Gram.Entry.clear label_longident + + let _ = Gram.Entry.clear label_patt + + let _ = Gram.Entry.clear label_patt_list + + let _ = Gram.Entry.clear labeled_ipatt + + let _ = Gram.Entry.clear let_binding + + let _ = Gram.Entry.clear meth_list + + let _ = Gram.Entry.clear meth_decl + + let _ = Gram.Entry.clear module_binding + + let _ = Gram.Entry.clear module_binding0 + + let _ = Gram.Entry.clear module_binding_quot + + let _ = Gram.Entry.clear module_declaration + + let _ = Gram.Entry.clear module_expr + + let _ = Gram.Entry.clear module_expr_quot + + let _ = Gram.Entry.clear module_longident + + let _ = Gram.Entry.clear module_longident_with_app + + let _ = Gram.Entry.clear module_rec_declaration + + let _ = Gram.Entry.clear module_type + + let _ = Gram.Entry.clear module_type_quot + + let _ = Gram.Entry.clear more_ctyp + + let _ = Gram.Entry.clear name_tags + + let _ = Gram.Entry.clear opt_as_lident + + let _ = Gram.Entry.clear opt_class_self_patt + + let _ = Gram.Entry.clear opt_class_self_type + + let _ = Gram.Entry.clear opt_comma_ctyp + + let _ = Gram.Entry.clear opt_dot_dot + + let _ = Gram.Entry.clear opt_eq_ctyp + + let _ = Gram.Entry.clear opt_expr + + let _ = Gram.Entry.clear opt_meth_list + + let _ = Gram.Entry.clear opt_mutable + + let _ = Gram.Entry.clear opt_polyt + + let _ = Gram.Entry.clear opt_private + + let _ = Gram.Entry.clear opt_rec + + let _ = Gram.Entry.clear opt_virtual + + let _ = Gram.Entry.clear opt_when_expr + + let _ = Gram.Entry.clear patt + + let _ = Gram.Entry.clear patt_as_patt_opt + + let _ = Gram.Entry.clear patt_eoi + + let _ = Gram.Entry.clear patt_quot + + let _ = Gram.Entry.clear patt_tcon + + let _ = Gram.Entry.clear phrase + + let _ = Gram.Entry.clear poly_type + + let _ = Gram.Entry.clear row_field + + let _ = Gram.Entry.clear sem_expr + + let _ = Gram.Entry.clear sem_expr_for_list + + let _ = Gram.Entry.clear sem_patt + + let _ = Gram.Entry.clear sem_patt_for_list + + let _ = Gram.Entry.clear semi + + let _ = Gram.Entry.clear sequence + + let _ = Gram.Entry.clear sig_item + + let _ = Gram.Entry.clear sig_item_quot + + let _ = Gram.Entry.clear sig_items + + let _ = Gram.Entry.clear star_ctyp + + let _ = Gram.Entry.clear str_item + + let _ = Gram.Entry.clear str_item_quot + + let _ = Gram.Entry.clear str_items + + let _ = Gram.Entry.clear top_phrase + + let _ = Gram.Entry.clear type_constraint + + let _ = Gram.Entry.clear type_declaration + + let _ = Gram.Entry.clear type_ident_and_parameters + + let _ = Gram.Entry.clear type_kind + + let _ = Gram.Entry.clear type_longident + + let _ = Gram.Entry.clear type_longident_and_parameters + + let _ = Gram.Entry.clear type_parameter + + let _ = Gram.Entry.clear type_parameters + + let _ = Gram.Entry.clear typevars + + let _ = Gram.Entry.clear use_file + + let _ = Gram.Entry.clear val_longident + + let _ = Gram.Entry.clear value_let + + let _ = Gram.Entry.clear value_val + + let _ = Gram.Entry.clear with_constr + + let _ = Gram.Entry.clear with_constr_quot + + let neg_string n = + let len = String.length n + in + if (len > 0) && (n.[0] = '-') + then String.sub n 1 (len - 1) + else "-" ^ n + + let mkumin _loc f arg = + match arg with + | Ast.ExInt (_, n) -> Ast.ExInt (_loc, neg_string n) + | Ast.ExInt32 (_, n) -> Ast.ExInt32 (_loc, neg_string n) + | Ast.ExInt64 (_, n) -> Ast.ExInt64 (_loc, neg_string n) + | Ast.ExNativeInt (_, n) -> Ast.ExNativeInt (_loc, neg_string n) + | Ast.ExFlo (_, n) -> Ast.ExFlo (_loc, neg_string n) + | _ -> + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdLid (_loc, "~" ^ f)), + arg) + + let mklistexp _loc last = + let rec loop top = + function + | [] -> + (match last with + | Some e -> e + | None -> Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + | e1 :: el -> + let _loc = + if top then _loc else Loc.merge (Ast.loc_of_expr e1) _loc + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + e1), + loop false el) + in loop true + + let mkassert _loc = + function + | Ast.ExId (_, (Ast.IdUid (_, "False"))) -> Ast.ExAsf _loc + | (* this case takes care about + the special assert false node *) + e -> Ast.ExAsr (_loc, e) + + let append_eLem el e = el @ [ e ] + + let mk_anti ?(c = "") n s = "\\$" ^ (n ^ (c ^ (":" ^ s))) + + let mksequence _loc = + function + | (Ast.ExSem (_, _, _) | Ast.ExAnt (_, _) as e) -> + Ast.ExSeq (_loc, e) + | e -> e + + let mksequence' _loc = + function + | (Ast.ExSem (_, _, _) as e) -> Ast.ExSeq (_loc, e) + | e -> e + + let module_type_app mt1 mt2 = + match (mt1, mt2) with + | (Ast.MtId (_loc, i1), Ast.MtId (_, i2)) -> + Ast.MtId (_loc, Ast.IdApp (_loc, i1, i2)) + | _ -> raise Stream.Failure + + let module_type_acc mt1 mt2 = + match (mt1, mt2) with + | (Ast.MtId (_loc, i1), Ast.MtId (_, i2)) -> + Ast.MtId (_loc, Ast.IdAcc (_loc, i1, i2)) + | _ -> raise Stream.Failure + + let bigarray_get _loc arr arg = + let coords = + match arg with + | Ast.ExTup (_, (Ast.ExCom (_, e1, e2))) | Ast.ExCom (_, e1, e2) + -> Ast.list_of_expr e1 (Ast.list_of_expr e2 []) + | _ -> [ arg ] + in + match coords with + | [ c1 ] -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array1"), + Ast.IdLid (_loc, "get")))), + arr), + c1) + | [ c1; c2 ] -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array2"), + Ast.IdLid (_loc, "get")))), + arr), + c1), + c2) + | [ c1; c2; c3 ] -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array3"), + Ast.IdLid (_loc, "get")))), + arr), + c1), + c2), + c3) + | (* | coords -> <:expr< Bigarray.Genarray.get $arr$ [| $list:coords$ |] >> ] *) + coords -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Genarray"), + Ast.IdLid (_loc, "get")))), + arr), + Ast.ExArr (_loc, Ast.exSem_of_list coords)) + + let bigarray_set _loc var newval = + match var with + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")), + (Ast.IdAcc (_, (Ast.IdUid (_, "Array1")), + (Ast.IdLid (_, "get")))))))), + arr)), + c1) -> + Some + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array1"), + Ast.IdLid (_loc, "set")))), + arr), + c1), + newval)) + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")), + (Ast.IdAcc (_, (Ast.IdUid (_, "Array2")), + (Ast.IdLid (_, "get")))))))), + arr)), + c1)), + c2) -> + Some + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array2"), + Ast.IdLid (_loc, "set")))), + arr), + c1), + c2), + newval)) + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")), + (Ast.IdAcc (_, (Ast.IdUid (_, "Array3")), + (Ast.IdLid (_, "get")))))))), + arr)), + c1)), + c2)), + c3) -> + Some + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array3"), + Ast.IdLid (_loc, "set")))), + arr), + c1), + c2), + c3), + newval)) + | Ast.ExApp (_, + (Ast.ExApp (_, + (Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")), + (Ast.IdAcc (_, (Ast.IdUid (_, "Genarray")), + (Ast.IdLid (_, "get")))))))), + arr)), + (Ast.ExArr (_, coords))) -> + Some + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Genarray"), + Ast.IdLid (_loc, "set")))), + arr), + Ast.ExArr (_loc, coords)), + newval)) + | _ -> None + + let test_not_left_brace_nor_do = + Gram.Entry.of_parser "test_not_left_brace_nor_do" + (fun strm -> + match Stream.peek strm with + | Some (((KEYWORD "{" | KEYWORD "do"), _)) -> + raise Stream.Failure + | _ -> ()) + + let stopped_at _loc = Some (Loc.move_line 1 _loc) + + (* FIXME be more precise *) + let symbolchar = + let list = + [ '$'; '!'; '%'; '&'; '*'; '+'; '-'; '.'; '/'; ':'; '<'; '='; + '>'; '?'; '@'; '^'; '|'; '~'; '\\' ] in + let rec loop s i = + if i == (String.length s) + then true + else if List.mem s.[i] list then loop s (i + 1) else false + in loop + + let _ = + let list = [ '!'; '?'; '~' ] in + let excl = [ "!="; "??" ] + in + Gram.Entry.setup_parser prefixop + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + (not (List.mem x excl)) && + (((String.length x) >= 2) && + ((List.mem x.[0] list) && (symbolchar x 1))) + -> + (Stream.junk __strm; + Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let _ = + let list_ok = + [ "<"; ">"; "<="; ">="; "="; "<>"; "=="; "!="; "$" ] in + let list_first_char_ok = [ '='; '<'; '>'; '|'; '&'; '$'; '!' ] in + let excl = [ "<-"; "||"; "&&" ] + in + Gram.Entry.setup_parser infixop0 + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + (List.mem x list_ok) || + ((not (List.mem x excl)) && + (((String.length x) >= 2) && + ((List.mem x.[0] list_first_char_ok) && + (symbolchar x 1)))) + -> + (Stream.junk __strm; + Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let _ = + let list = [ '@'; '^' ] + in + Gram.Entry.setup_parser infixop1 + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + ((String.length x) >= 1) && + ((List.mem x.[0] list) && (symbolchar x 1)) + -> + (Stream.junk __strm; + Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let _ = + let list = [ '+'; '-' ] + in + Gram.Entry.setup_parser infixop2 + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + (x <> "->") && + (((String.length x) >= 1) && + ((List.mem x.[0] list) && (symbolchar x 1))) + -> + (Stream.junk __strm; + Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let _ = + let list = [ '*'; '/'; '%'; '\\' ] + in + Gram.Entry.setup_parser infixop3 + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + ((String.length x) >= 1) && + ((List.mem x.[0] list) && + (((x.[0] <> '*') || + (((String.length x) < 2) || (x.[1] <> '*'))) + && (symbolchar x 1))) + -> + (Stream.junk __strm; + Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let _ = + Gram.Entry.setup_parser infixop4 + (fun (__strm : _ Stream.t) -> + match Stream.peek __strm with + | Some (((KEYWORD x | SYMBOL x), _loc)) when + ((String.length x) >= 2) && + ((x.[0] == '*') && ((x.[1] == '*') && (symbolchar x 2))) + -> + (Stream.junk __strm; Ast.ExId (_loc, Ast.IdLid (_loc, x))) + | _ -> raise Stream.Failure) + + let rec infix_kwds_filter (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some (((KEYWORD "(", _) as tok)) -> + (Stream.junk __strm; + let xs = __strm in + let (__strm : _ Stream.t) = xs + in + (match Stream.peek __strm with + | Some + ((KEYWORD + (("mod" | "land" | "lor" | "lxor" | "lsl" | "lsr" | + "asr" + as i)), + _loc)) + -> + (Stream.junk __strm; + (match Stream.peek __strm with + | Some ((KEYWORD ")", _)) -> + (Stream.junk __strm; + let xs = __strm + in + Stream.lcons (fun _ -> ((LIDENT i), _loc)) + (Stream.slazy + (fun _ -> infix_kwds_filter xs))) + | _ -> raise (Stream.Error ""))) + | _ -> + let xs = __strm + in + Stream.icons tok + (Stream.slazy (fun _ -> infix_kwds_filter xs)))) + | Some x -> + (Stream.junk __strm; + let xs = __strm + in + Stream.icons x + (Stream.slazy (fun _ -> infix_kwds_filter xs))) + | _ -> raise Stream.Failure + + let _ = + Token.Filter.define_filter (Gram.get_filter ()) + (fun f strm -> infix_kwds_filter (f strm)) + + (* transmit the context *) + let _ = + Gram.Entry.setup_parser sem_expr + (let symb1 = Gram.parse_tokens_after_filter expr in + let symb (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some ((ANTIQUOT ((("list" as n)), s), _loc)) -> + (Stream.junk __strm; + Ast.ExAnt (_loc, mk_anti ~c: "expr;" n s)) + | _ -> symb1 __strm in + let rec kont al (__strm : _ Stream.t) = + match Stream.peek __strm with + | Some ((KEYWORD ";", _loc)) -> + (Stream.junk __strm; + let a = + (try symb __strm + with | Stream.Failure -> raise (Stream.Error "")) in + let s = __strm in kont (Ast.ExSem (_loc, al, a)) s) + | _ -> al + in + fun (__strm : _ Stream.t) -> + let a = symb __strm in kont a __strm) + + let _ = + let _ = (a_CHAR : 'a_CHAR Gram.Entry.t) + and _ = (do_sequence : 'do_sequence Gram.Entry.t) + and _ = (infixop4 : 'infixop4 Gram.Entry.t) + and _ = (infixop3 : 'infixop3 Gram.Entry.t) + and _ = (infixop2 : 'infixop2 Gram.Entry.t) + and _ = (infixop1 : 'infixop1 Gram.Entry.t) + and _ = (infixop0 : 'infixop0 Gram.Entry.t) + and _ = (with_constr_quot : 'with_constr_quot Gram.Entry.t) + and _ = (with_constr : 'with_constr Gram.Entry.t) + and _ = (value_val : 'value_val Gram.Entry.t) + and _ = (value_let : 'value_let Gram.Entry.t) + and _ = (val_longident : 'val_longident Gram.Entry.t) + and _ = (use_file : 'use_file Gram.Entry.t) + and _ = (typevars : 'typevars Gram.Entry.t) + and _ = (type_parameters : 'type_parameters Gram.Entry.t) + and _ = (type_parameter : 'type_parameter Gram.Entry.t) + and _ = + (type_longident_and_parameters : + 'type_longident_and_parameters Gram.Entry.t) + and _ = (type_longident : 'type_longident Gram.Entry.t) + and _ = (type_kind : 'type_kind Gram.Entry.t) + and _ = + (type_ident_and_parameters : + 'type_ident_and_parameters Gram.Entry.t) + and _ = (type_declaration : 'type_declaration Gram.Entry.t) + and _ = (type_constraint : 'type_constraint Gram.Entry.t) + and _ = (top_phrase : 'top_phrase Gram.Entry.t) + and _ = (str_items : 'str_items Gram.Entry.t) + and _ = (str_item_quot : 'str_item_quot Gram.Entry.t) + and _ = (str_item : 'str_item Gram.Entry.t) + and _ = (star_ctyp : 'star_ctyp Gram.Entry.t) + and _ = (sig_items : 'sig_items Gram.Entry.t) + and _ = (sig_item_quot : 'sig_item_quot Gram.Entry.t) + and _ = (sig_item : 'sig_item Gram.Entry.t) + and _ = (sequence : 'sequence Gram.Entry.t) + and _ = (semi : 'semi Gram.Entry.t) + and _ = (sem_patt_for_list : 'sem_patt_for_list Gram.Entry.t) + and _ = (sem_patt : 'sem_patt Gram.Entry.t) + and _ = (sem_expr_for_list : 'sem_expr_for_list Gram.Entry.t) + and _ = (sem_expr : 'sem_expr Gram.Entry.t) + and _ = (row_field : 'row_field Gram.Entry.t) + and _ = (poly_type : 'poly_type Gram.Entry.t) + and _ = (phrase : 'phrase Gram.Entry.t) + and _ = (patt_tcon : 'patt_tcon Gram.Entry.t) + and _ = (patt_quot : 'patt_quot Gram.Entry.t) + and _ = (patt_eoi : 'patt_eoi Gram.Entry.t) + and _ = (patt_as_patt_opt : 'patt_as_patt_opt Gram.Entry.t) + and _ = (patt : 'patt Gram.Entry.t) + and _ = (opt_when_expr : 'opt_when_expr Gram.Entry.t) + and _ = (opt_virtual : 'opt_virtual Gram.Entry.t) + and _ = (opt_rec : 'opt_rec Gram.Entry.t) + and _ = (opt_private : 'opt_private Gram.Entry.t) + and _ = (opt_polyt : 'opt_polyt Gram.Entry.t) + and _ = (opt_mutable : 'opt_mutable Gram.Entry.t) + and _ = (opt_meth_list : 'opt_meth_list Gram.Entry.t) + and _ = (opt_expr : 'opt_expr Gram.Entry.t) + and _ = (opt_eq_ctyp : 'opt_eq_ctyp Gram.Entry.t) + and _ = (opt_dot_dot : 'opt_dot_dot Gram.Entry.t) + and _ = (opt_comma_ctyp : 'opt_comma_ctyp Gram.Entry.t) + and _ = (opt_class_self_type : 'opt_class_self_type Gram.Entry.t) + and _ = (opt_class_self_patt : 'opt_class_self_patt Gram.Entry.t) + and _ = (opt_as_lident : 'opt_as_lident Gram.Entry.t) + and _ = (name_tags : 'name_tags Gram.Entry.t) + and _ = (more_ctyp : 'more_ctyp Gram.Entry.t) + and _ = (module_type_quot : 'module_type_quot Gram.Entry.t) + and _ = (module_type : 'module_type Gram.Entry.t) + and _ = + (module_rec_declaration : 'module_rec_declaration Gram.Entry.t) + and _ = + (module_longident_with_app : + 'module_longident_with_app Gram.Entry.t) + and _ = (module_longident : 'module_longident Gram.Entry.t) + and _ = (module_expr_quot : 'module_expr_quot Gram.Entry.t) + and _ = (module_expr : 'module_expr Gram.Entry.t) + and _ = (module_declaration : 'module_declaration Gram.Entry.t) + and _ = (module_binding_quot : 'module_binding_quot Gram.Entry.t) + and _ = (module_binding0 : 'module_binding0 Gram.Entry.t) + and _ = (module_binding : 'module_binding Gram.Entry.t) + and _ = (meth_decl : 'meth_decl Gram.Entry.t) + and _ = (meth_list : 'meth_list Gram.Entry.t) + and _ = (let_binding : 'let_binding Gram.Entry.t) + and _ = (labeled_ipatt : 'labeled_ipatt Gram.Entry.t) + and _ = (label_patt_list : 'label_patt_list Gram.Entry.t) + and _ = (label_patt : 'label_patt Gram.Entry.t) + and _ = (label_longident : 'label_longident Gram.Entry.t) + and _ = (label_ipatt_list : 'label_ipatt_list Gram.Entry.t) + and _ = (label_ipatt : 'label_ipatt Gram.Entry.t) + and _ = (label_expr_list : 'label_expr_list Gram.Entry.t) + and _ = (label_expr : 'label_expr Gram.Entry.t) + and _ = + (label_declaration_list : 'label_declaration_list Gram.Entry.t) + and _ = (label_declaration : 'label_declaration Gram.Entry.t) + and _ = (label : 'label Gram.Entry.t) + and _ = (ipatt_tcon : 'ipatt_tcon Gram.Entry.t) + and _ = (ipatt : 'ipatt Gram.Entry.t) + and _ = (interf : 'interf Gram.Entry.t) + and _ = (implem : 'implem Gram.Entry.t) + and _ = (ident_quot : 'ident_quot Gram.Entry.t) + and _ = (ident : 'ident Gram.Entry.t) + and _ = (fun_def : 'fun_def Gram.Entry.t) + and _ = (fun_binding : 'fun_binding Gram.Entry.t) + and _ = (field_expr_list : 'field_expr_list Gram.Entry.t) + and _ = (field_expr : 'field_expr Gram.Entry.t) + and _ = (expr_quot : 'expr_quot Gram.Entry.t) + and _ = (expr_eoi : 'expr_eoi Gram.Entry.t) + and _ = (expr : 'expr Gram.Entry.t) + and _ = (eq_expr : 'eq_expr Gram.Entry.t) + and _ = (dummy : 'dummy Gram.Entry.t) + and _ = (direction_flag : 'direction_flag Gram.Entry.t) + and _ = (cvalue_binding : 'cvalue_binding Gram.Entry.t) + and _ = (ctyp_quot : 'ctyp_quot Gram.Entry.t) + and _ = (ctyp : 'ctyp Gram.Entry.t) + and _ = + (constructor_declarations : + 'constructor_declarations Gram.Entry.t) + and _ = + (constructor_declaration : 'constructor_declaration Gram.Entry.t) + and _ = (constructor_arg_list : 'constructor_arg_list Gram.Entry.t) + and _ = (constrain : 'constrain Gram.Entry.t) + and _ = (comma_type_parameter : 'comma_type_parameter Gram.Entry.t) + and _ = (comma_patt : 'comma_patt Gram.Entry.t) + and _ = (comma_ipatt : 'comma_ipatt Gram.Entry.t) + and _ = (comma_expr : 'comma_expr Gram.Entry.t) + and _ = (comma_ctyp : 'comma_ctyp Gram.Entry.t) + and _ = (class_type_quot : 'class_type_quot Gram.Entry.t) + and _ = (class_type_plus : 'class_type_plus Gram.Entry.t) + and _ = + (class_type_longident_and_param : + 'class_type_longident_and_param Gram.Entry.t) + and _ = (class_type_longident : 'class_type_longident Gram.Entry.t) + and _ = + (class_type_declaration : 'class_type_declaration Gram.Entry.t) + and _ = (class_type : 'class_type Gram.Entry.t) + and _ = (class_structure : 'class_structure Gram.Entry.t) + and _ = (class_str_item_quot : 'class_str_item_quot Gram.Entry.t) + and _ = (class_str_item : 'class_str_item Gram.Entry.t) + and _ = (class_signature : 'class_signature Gram.Entry.t) + and _ = (class_sig_item_quot : 'class_sig_item_quot Gram.Entry.t) + and _ = (class_sig_item : 'class_sig_item Gram.Entry.t) + and _ = (class_name_and_param : 'class_name_and_param Gram.Entry.t) + and _ = + (class_longident_and_param : + 'class_longident_and_param Gram.Entry.t) + and _ = (class_longident : 'class_longident Gram.Entry.t) + and _ = + (class_info_for_class_type : + 'class_info_for_class_type Gram.Entry.t) + and _ = + (class_info_for_class_expr : + 'class_info_for_class_expr Gram.Entry.t) + and _ = (class_fun_def : 'class_fun_def Gram.Entry.t) + and _ = (class_fun_binding : 'class_fun_binding Gram.Entry.t) + and _ = (class_expr_quot : 'class_expr_quot Gram.Entry.t) + and _ = (class_expr : 'class_expr Gram.Entry.t) + and _ = (class_description : 'class_description Gram.Entry.t) + and _ = (class_declaration : 'class_declaration Gram.Entry.t) + and _ = (binding_quot : 'binding_quot Gram.Entry.t) + and _ = (binding : 'binding Gram.Entry.t) + and _ = (match_case_quot : 'match_case_quot Gram.Entry.t) + and _ = (match_case0 : 'match_case0 Gram.Entry.t) + and _ = (match_case : 'match_case Gram.Entry.t) + and _ = (and_ctyp : 'and_ctyp Gram.Entry.t) + and _ = (amp_ctyp : 'amp_ctyp Gram.Entry.t) + and _ = (a_ident : 'a_ident Gram.Entry.t) + and _ = (a_UIDENT : 'a_UIDENT Gram.Entry.t) + and _ = (a_STRING : 'a_STRING Gram.Entry.t) + and _ = (a_OPTLABEL : 'a_OPTLABEL Gram.Entry.t) + and _ = (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t) + and _ = (rec_binding_quot : 'rec_binding_quot Gram.Entry.t) + and _ = (a_LIDENT : 'a_LIDENT Gram.Entry.t) + and _ = (a_LABEL : 'a_LABEL Gram.Entry.t) + and _ = (a_INT64 : 'a_INT64 Gram.Entry.t) + and _ = (a_INT32 : 'a_INT32 Gram.Entry.t) + and _ = (a_INT : 'a_INT Gram.Entry.t) + and _ = (a_FLOAT : 'a_FLOAT Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let (* Here it's LABEL and not tilde_label since ~a:b is different than ~a : b *) + (* Same remark for ?a:b *) infixop5 : 'infixop5 Gram.Entry.t = + grammar_entry_create "infixop5" + and (* | i = opt_label; "("; p = patt_tcon; ")" -> *) + (* <:patt< ? $i$ : ($p$) >> *) + (* | i = opt_label; "("; p = ipatt_tcon; ")" -> + <:patt< ? $i$ : ($p$) >> + | i = opt_label; "("; p = ipatt_tcon; "="; e = expr; ")" -> + <:patt< ? $i$ : ($p$ = $e$) >> *) + string_list : 'string_list Gram.Entry.t = + grammar_entry_create "string_list" + and fun_def_cont : 'fun_def_cont Gram.Entry.t = + grammar_entry_create "fun_def_cont" + and sequence' : 'sequence' Gram.Entry.t = + grammar_entry_create "sequence'" + and infixop6 : 'infixop6 Gram.Entry.t = + grammar_entry_create "infixop6" + in + (Gram.extend (module_expr : 'module_expr Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), None, + [ ([ Gram.Skeyword "struct"; + Gram.Snterm + (Gram.Entry.obj + (str_items : 'str_items Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (st : 'str_items) _ (_loc : Gram.Loc.t) + -> (Ast.MeStr (_loc, st) : 'module_expr)))); + ([ Gram.Skeyword "functor"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword ")"; Gram.Skeyword "->"; Gram.Sself ], + (Gram.Action.mk + (fun (me : 'module_expr) _ _ (t : 'module_type) + _ (i : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) -> + (Ast.MeFun (_loc, i, t, me) : 'module_expr)))) ]); + ((Some "apply"), None, + [ ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (me2 : 'module_expr) (me1 : 'module_expr) + (_loc : Gram.Loc.t) -> + (Ast.MeApp (_loc, me1, me2) : 'module_expr)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (me : 'module_expr) _ (_loc : Gram.Loc.t) + -> (me : 'module_expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (mt : 'module_type) _ (me : 'module_expr) + _ (_loc : Gram.Loc.t) -> + (Ast.MeTyc (_loc, me, mt) : 'module_expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (module_longident : + 'module_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'module_longident) (_loc : Gram.Loc.t) + -> (Ast.MeId (_loc, i) : 'module_expr)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.module_expr_tag : + 'module_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "mexp" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"mexp\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "mexp" | "anti" | "list" as n)), + s) -> + (Ast.MeAnt (_loc, + mk_anti ~c: "module_expr" n s) : + 'module_expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (str_item : 'str_item Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (Ast.StExp (_loc, e) : 'str_item)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.str_item_tag : + 'str_item) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "stri" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"stri\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "stri" | "anti" | "list" as n)), + s) -> + (Ast.StAnt (_loc, + mk_anti ~c: "str_item" n s) : + 'str_item) + | _ -> assert false))); + ([ Gram.Skeyword "class"; Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (class_type_declaration : + 'class_type_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ctd : 'class_type_declaration) _ _ + (_loc : Gram.Loc.t) -> + (Ast.StClt (_loc, ctd) : 'str_item)))); + ([ Gram.Skeyword "class"; + Gram.Snterm + (Gram.Entry.obj + (class_declaration : + 'class_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (cd : 'class_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.StCls (_loc, cd) : 'str_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_let : 'value_let Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (bi : 'binding) (r : 'opt_rec) _ + (_loc : Gram.Loc.t) -> + (Ast.StVal (_loc, r, bi) : 'str_item)))); + ([ Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (type_declaration : + 'type_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (td : 'type_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.StTyp (_loc, td) : 'str_item)))); + ([ Gram.Skeyword "open"; + Gram.Snterm + (Gram.Entry.obj + (module_longident : + 'module_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'module_longident) _ + (_loc : Gram.Loc.t) -> + (Ast.StOpn (_loc, i) : 'str_item)))); + ([ Gram.Skeyword "module"; Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (i : 'a_UIDENT) _ _ + (_loc : Gram.Loc.t) -> + (Ast.StMty (_loc, i, mt) : 'str_item)))); + ([ Gram.Skeyword "module"; Gram.Skeyword "rec"; + Gram.Snterm + (Gram.Entry.obj + (module_binding : + 'module_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mb : 'module_binding) _ _ + (_loc : Gram.Loc.t) -> + (Ast.StRecMod (_loc, mb) : 'str_item)))); + ([ Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (module_binding0 : + 'module_binding0 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mb : 'module_binding0) (i : 'a_UIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.StMod (_loc, i, mb) : 'str_item)))); + ([ Gram.Skeyword "include"; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (_loc : Gram.Loc.t) + -> (Ast.StInc (_loc, me) : 'str_item)))); + ([ Gram.Skeyword "external"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (string_list : 'string_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sl : 'string_list) _ (t : 'ctyp) _ + (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (Ast.StExt (_loc, i, t, sl) : 'str_item)))); + ([ Gram.Skeyword "exception"; + Gram.Snterm + (Gram.Entry.obj + (constructor_declaration : + 'constructor_declaration Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (type_longident : + 'type_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'type_longident) _ + (t : 'constructor_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.StExc (_loc, t, Ast.OSome i) : + 'str_item)))); + ([ Gram.Skeyword "exception"; + Gram.Snterm + (Gram.Entry.obj + (constructor_declaration : + 'constructor_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'constructor_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.StExc (_loc, t, Ast.ONone) : 'str_item)))) ]) ])) + ()); + Gram.extend (module_binding0 : 'module_binding0 Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (_loc : Gram.Loc.t) + -> (me : 'module_binding0)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (mt : 'module_type) _ + (_loc : Gram.Loc.t) -> + (Ast.MeTyc (_loc, me, mt) : 'module_binding0)))); + ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword ")"; Gram.Sself ], + (Gram.Action.mk + (fun (mb : 'module_binding0) _ + (mt : 'module_type) _ (m : 'a_UIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.MeFun (_loc, m, mt, mb) : + 'module_binding0)))) ]) ])) + ()); + Gram.extend (module_binding : 'module_binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (mt : 'module_type) _ + (m : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.MbColEq (_loc, m, mt, me) : + 'module_binding)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.module_binding_tag : + 'module_binding) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (mt : 'module_type) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), m) -> + (Ast.MbColEq (_loc, mk_anti n m, mt, me) : + 'module_binding) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), s) -> + (Ast.MbAnt (_loc, + mk_anti ~c: "module_binding" n s) : + 'module_binding) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT + (("module_binding" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"module_binding\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("module_binding" | "anti" | "list" as + n)), + s) -> + (Ast.MbAnt (_loc, + mk_anti ~c: "module_binding" n s) : + 'module_binding) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (b2 : 'module_binding) _ + (b1 : 'module_binding) (_loc : Gram.Loc.t) -> + (Ast.MbAnd (_loc, b1, b2) : 'module_binding)))) ]) ])) + ()); + Gram.extend (module_type : 'module_type Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), None, + [ ([ Gram.Skeyword "functor"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Sself; Gram.Skeyword ")"; + Gram.Skeyword "->"; Gram.Sself ], + (Gram.Action.mk + (fun (mt : 'module_type) _ _ (t : 'module_type) + _ (i : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) -> + (Ast.MtFun (_loc, i, t, mt) : 'module_type)))) ]); + ((Some "with"), None, + [ ([ Gram.Sself; Gram.Skeyword "with"; + Gram.Snterm + (Gram.Entry.obj + (with_constr : 'with_constr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (wc : 'with_constr) _ (mt : 'module_type) + (_loc : Gram.Loc.t) -> + (Ast.MtWit (_loc, mt, wc) : 'module_type)))) ]); + ((Some "apply"), None, + [ ([ Gram.Sself; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj (dummy : 'dummy Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (mt2 : 'module_type) (mt1 : 'module_type) + (_loc : Gram.Loc.t) -> + (module_type_app mt1 mt2 : 'module_type)))) ]); + ((Some "."), None, + [ ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (mt2 : 'module_type) _ (mt1 : 'module_type) + (_loc : Gram.Loc.t) -> + (module_type_acc mt1 mt2 : 'module_type)))) ]); + ((Some "sig"), None, + [ ([ Gram.Skeyword "sig"; + Gram.Snterm + (Gram.Entry.obj + (sig_items : 'sig_items Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (sg : 'sig_items) _ (_loc : Gram.Loc.t) + -> (Ast.MtSig (_loc, sg) : 'module_type)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (mt : 'module_type) _ (_loc : Gram.Loc.t) + -> (mt : 'module_type)))); + ([ Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.MtQuo (_loc, i) : 'module_type)))); + ([ Gram.Snterm + (Gram.Entry.obj + (module_longident_with_app : + 'module_longident_with_app Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'module_longident_with_app) + (_loc : Gram.Loc.t) -> + (Ast.MtId (_loc, i) : 'module_type)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.module_type_tag : + 'module_type) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "mtyp" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"mtyp\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "mtyp" | "anti" | "list" as n)), + s) -> + (Ast.MtAnt (_loc, + mk_anti ~c: "module_type" n s) : + 'module_type) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (sig_item : 'sig_item Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), None, + [ ([ Gram.Skeyword "class"; Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (class_type_declaration : + 'class_type_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ctd : 'class_type_declaration) _ _ + (_loc : Gram.Loc.t) -> + (Ast.SgClt (_loc, ctd) : 'sig_item)))); + ([ Gram.Skeyword "class"; + Gram.Snterm + (Gram.Entry.obj + (class_description : + 'class_description Gram.Entry.t)) ], + (Gram.Action.mk + (fun (cd : 'class_description) _ + (_loc : Gram.Loc.t) -> + (Ast.SgCls (_loc, cd) : 'sig_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_val : 'value_val Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (i : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.SgVal (_loc, i, t) : 'sig_item)))); + ([ Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (type_declaration : + 'type_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'type_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.SgTyp (_loc, t) : 'sig_item)))); + ([ Gram.Skeyword "open"; + Gram.Snterm + (Gram.Entry.obj + (module_longident : + 'module_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'module_longident) _ + (_loc : Gram.Loc.t) -> + (Ast.SgOpn (_loc, i) : 'sig_item)))); + ([ Gram.Skeyword "module"; Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) -> + (Ast.SgMty (_loc, i, Ast.MtNil _loc) : + 'sig_item)))); + ([ Gram.Skeyword "module"; Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (i : 'a_UIDENT) _ _ + (_loc : Gram.Loc.t) -> + (Ast.SgMty (_loc, i, mt) : 'sig_item)))); + ([ Gram.Skeyword "module"; Gram.Skeyword "rec"; + Gram.Snterm + (Gram.Entry.obj + (module_rec_declaration : + 'module_rec_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mb : 'module_rec_declaration) _ _ + (_loc : Gram.Loc.t) -> + (Ast.SgRecMod (_loc, mb) : 'sig_item)))); + ([ Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (module_declaration : + 'module_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_declaration) (i : 'a_UIDENT) + _ (_loc : Gram.Loc.t) -> + (Ast.SgMod (_loc, i, mt) : 'sig_item)))); + ([ Gram.Skeyword "include"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (_loc : Gram.Loc.t) + -> (Ast.SgInc (_loc, mt) : 'sig_item)))); + ([ Gram.Skeyword "external"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (string_list : 'string_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sl : 'string_list) _ (t : 'ctyp) _ + (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (Ast.SgExt (_loc, i, t, sl) : 'sig_item)))); + ([ Gram.Skeyword "exception"; + Gram.Snterm + (Gram.Entry.obj + (constructor_declaration : + 'constructor_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'constructor_declaration) _ + (_loc : Gram.Loc.t) -> + (Ast.SgExc (_loc, t) : 'sig_item)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.sig_item_tag : + 'sig_item) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "sigi" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"sigi\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "sigi" | "anti" | "list" as n)), + s) -> + (Ast.SgAnt (_loc, + mk_anti ~c: "sig_item" n s) : + 'sig_item) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (module_declaration : 'module_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword ")"; Gram.Sself ], + (Gram.Action.mk + (fun (mt : 'module_declaration) _ + (t : 'module_type) _ (i : 'a_UIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.MtFun (_loc, i, t, mt) : + 'module_declaration)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (_loc : Gram.Loc.t) + -> (mt : 'module_declaration)))) ]) ])) + ()); + Gram.extend + (module_rec_declaration : + 'module_rec_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (m : 'a_UIDENT) + (_loc : Gram.Loc.t) -> + (Ast.MbCol (_loc, m, mt) : + 'module_rec_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.module_binding_tag : + 'module_rec_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT + (("" | "module_binding" | "anti" | + "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"module_binding\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "module_binding" | "anti" | + "list" + as n)), + s) -> + (Ast.MbAnt (_loc, + mk_anti ~c: "module_binding" n s) : + 'module_rec_declaration) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (m2 : 'module_rec_declaration) _ + (m1 : 'module_rec_declaration) + (_loc : Gram.Loc.t) -> + (Ast.MbAnd (_loc, m1, m2) : + 'module_rec_declaration)))) ]) ])) + ()); + Gram.extend (with_constr : 'with_constr Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (module_longident : + 'module_longident Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_longident_with_app : + 'module_longident_with_app Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i2 : 'module_longident_with_app) _ + (i1 : 'module_longident) _ + (_loc : Gram.Loc.t) -> + (Ast.WcMod (_loc, i1, i2) : 'with_constr)))); + ([ Gram.Skeyword "type"; + Gram.Snterm + (Gram.Entry.obj + (type_longident_and_parameters : + 'type_longident_and_parameters Gram.Entry. + t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ + (t1 : 'type_longident_and_parameters) _ + (_loc : Gram.Loc.t) -> + (Ast.WcTyp (_loc, t1, t2) : 'with_constr)))); + ([ Gram.Skeyword "type"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\"), _)")); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" | "anti" as n)), s) + -> + (Ast.WcTyp (_loc, + Ast.TyAnt (_loc, + mk_anti ~c: "ctyp" n s), + t) : + 'with_constr) + | _ -> assert false))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.with_constr_tag : + 'with_constr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT + (("" | "with_constr" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"with_constr\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "with_constr" | "anti" | "list" + as n)), + s) -> + (Ast.WcAnt (_loc, + mk_anti ~c: "with_constr" n s) : + 'with_constr) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (wc2 : 'with_constr) _ (wc1 : 'with_constr) + (_loc : Gram.Loc.t) -> + (Ast.WcAnd (_loc, wc1, wc2) : 'with_constr)))) ]) ])) + ()); + Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Skeyword "object"; + Gram.Snterm + (Gram.Entry.obj + (opt_class_self_patt : + 'opt_class_self_patt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_structure : + 'class_structure Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (cst : 'class_structure) + (csp : 'opt_class_self_patt) _ + (_loc : Gram.Loc.t) -> + (Ast.ExObj (_loc, csp, cst) : 'expr)))); + ([ Gram.Skeyword "while"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "do"; + Gram.Snterm + (Gram.Entry.obj + (do_sequence : 'do_sequence Gram.Entry.t)) ], + (Gram.Action.mk + (fun (seq : 'do_sequence) _ (e : 'sequence) _ + (_loc : Gram.Loc.t) -> + (Ast.ExWhi (_loc, mksequence' _loc e, seq) : + 'expr)))); + ([ Gram.Skeyword "for"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (direction_flag : + 'direction_flag Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "do"; + Gram.Snterm + (Gram.Entry.obj + (do_sequence : 'do_sequence Gram.Entry.t)) ], + (Gram.Action.mk + (fun (seq : 'do_sequence) _ (e2 : 'sequence) + (df : 'direction_flag) (e1 : 'sequence) _ + (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (Ast.ExFor (_loc, i, mksequence' _loc e1, + mksequence' _loc e2, df, seq) : + 'expr)))); + ([ Gram.Skeyword "do"; + Gram.Snterm + (Gram.Entry.obj + (do_sequence : 'do_sequence Gram.Entry.t)) ], + (Gram.Action.mk + (fun (seq : 'do_sequence) _ (_loc : Gram.Loc.t) + -> (mksequence _loc seq : 'expr)))); + ([ Gram.Skeyword "if"; Gram.Sself; + Gram.Skeyword "then"; Gram.Sself; + Gram.Skeyword "else"; Gram.Sself ], + (Gram.Action.mk + (fun (e3 : 'expr) _ (e2 : 'expr) _ (e1 : 'expr) + _ (_loc : Gram.Loc.t) -> + (Ast.ExIfe (_loc, e1, e2, e3) : 'expr)))); + ([ Gram.Skeyword "try"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "with"; + Gram.Snterm + (Gram.Entry.obj + (match_case : 'match_case Gram.Entry.t)) ], + (Gram.Action.mk + (fun (a : 'match_case) _ (e : 'sequence) _ + (_loc : Gram.Loc.t) -> + (Ast.ExTry (_loc, mksequence' _loc e, a) : + 'expr)))); + ([ Gram.Skeyword "match"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "with"; + Gram.Snterm + (Gram.Entry.obj + (match_case : 'match_case Gram.Entry.t)) ], + (Gram.Action.mk + (fun (a : 'match_case) _ (e : 'sequence) _ + (_loc : Gram.Loc.t) -> + (Ast.ExMat (_loc, mksequence' _loc e, a) : + 'expr)))); + ([ Gram.Skeyword "fun"; + Gram.Snterm + (Gram.Entry.obj + (fun_def : 'fun_def Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'fun_def) _ (_loc : Gram.Loc.t) -> + (e : 'expr)))); + ([ Gram.Skeyword "fun"; Gram.Skeyword "["; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (match_case0 : 'match_case0 Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (a : 'match_case0 list) _ _ + (_loc : Gram.Loc.t) -> + (Ast.ExFun (_loc, Ast.mcOr_of_list a) : + 'expr)))); + ([ Gram.Skeyword "let"; Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (module_binding0 : + 'module_binding0 Gram.Entry.t)); + Gram.Skeyword "in"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (mb : 'module_binding0) + (m : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) -> + (Ast.ExLmd (_loc, m, mb, e) : 'expr)))); + ([ Gram.Skeyword "let"; + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)); + Gram.Skeyword "in"; Gram.Sself ], + (Gram.Action.mk + (fun (x : 'expr) _ (bi : 'binding) + (r : 'opt_rec) _ (_loc : Gram.Loc.t) -> + (Ast.ExLet (_loc, r, bi, x) : 'expr)))) ]); + ((Some "where"), None, + [ ([ Gram.Sself; Gram.Skeyword "where"; + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (let_binding : 'let_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (lb : 'let_binding) (rf : 'opt_rec) _ + (e : 'expr) (_loc : Gram.Loc.t) -> + (Ast.ExLet (_loc, rf, lb, e) : 'expr)))) ]); + ((Some ":="), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Sself; Gram.Skeyword ":="; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj (dummy : 'dummy Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (match bigarray_set _loc e1 e2 with + | Some e -> e + | None -> Ast.ExAss (_loc, e1, e2) : 'expr)))) ]); + ((Some "||"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop6 : 'infixop6 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop6) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))) ]); + ((Some "&&"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop5 : 'infixop5 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop5) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))) ]); + ((Some "<"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop0 : 'infixop0 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop0) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))) ]); + ((Some "^"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop1 : 'infixop1 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop1) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))) ]); + ((Some "+"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop2 : 'infixop2 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop2) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))) ]); + ((Some "*"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop3 : 'infixop3 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop3) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "mod"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "mod")), + e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "lxor"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "lxor")), + e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "lor"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "lor")), + e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "land"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "land")), + e1), + e2) : + 'expr)))) ]); + ((Some "**"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (infixop4 : 'infixop4 Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (op : 'infixop4) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, Ast.ExApp (_loc, op, e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "lsr"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "lsr")), + e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "lsl"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "lsl")), + e1), + e2) : + 'expr)))); + ([ Gram.Sself; Gram.Skeyword "asr"; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "asr")), + e1), + e2) : + 'expr)))) ]); + ((Some "unary minus"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Skeyword "-."; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (mkumin _loc "-." e : 'expr)))); + ([ Gram.Skeyword "-"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (mkumin _loc "-" e : 'expr)))) ]); + ((Some "apply"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "lazy"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (Ast.ExLaz (_loc, e) : 'expr)))); + ([ Gram.Skeyword "new"; + Gram.Snterm + (Gram.Entry.obj + (class_longident : + 'class_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'class_longident) _ + (_loc : Gram.Loc.t) -> + (Ast.ExNew (_loc, i) : 'expr)))); + ([ Gram.Skeyword "assert"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (mkassert _loc e : 'expr)))); + ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, e1, e2) : 'expr)))) ]); + ((Some "label"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Skeyword "?"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (Ast.ExOlb (_loc, i, Ast.ExNil _loc) : 'expr)))); + ([ Gram.Skeyword "?"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (i : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.ExOlb (_loc, i, e) : 'expr)))); + ([ Gram.Stoken + (((function | OPTLABEL _ -> true | _ -> false), + "OPTLABEL _")); + Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | OPTLABEL i -> + (Ast.ExOlb (_loc, i, e) : 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function | LABEL _ -> true | _ -> false), + "LABEL _")); + Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LABEL i -> (Ast.ExLab (_loc, i, e) : 'expr) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (Ast.ExLab (_loc, i, Ast.ExNil _loc) : 'expr)))); + ([ Gram.Skeyword "~"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (i : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.ExLab (_loc, i, e) : 'expr)))) ]); + ((Some "."), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)) ], + (Gram.Action.mk + (fun (lab : 'label) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExSnd (_loc, e, lab) : 'expr)))); + ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExAcc (_loc, e1, e2) : 'expr)))); + ([ Gram.Sself; Gram.Skeyword "."; Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (comma_expr : 'comma_expr Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (e2 : 'comma_expr) _ _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (bigarray_get _loc e1 e2 : 'expr)))); + ([ Gram.Sself; Gram.Skeyword "."; Gram.Skeyword "["; + Gram.Sself; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (e2 : 'expr) _ _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExSte (_loc, e1, e2) : 'expr)))); + ([ Gram.Sself; Gram.Skeyword "."; Gram.Skeyword "("; + Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (e2 : 'expr) _ _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExAre (_loc, e1, e2) : 'expr)))) ]); + ((Some "~-"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (prefixop : 'prefixop Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) (f : 'prefixop) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, f, e) : 'expr)))); + ([ Gram.Skeyword "!"; Gram.Sself ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (Ast.ExAcc (_loc, e, + Ast.ExId (_loc, Ast.IdLid (_loc, "val"))) : + 'expr)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "begin"; Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdUid (_loc, "()")) : + 'expr)))); + ([ Gram.Skeyword "begin"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (seq : 'sequence) _ (_loc : Gram.Loc.t) + -> (mksequence _loc seq : 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (e : 'expr) _ (_loc : Gram.Loc.t) -> + (e : 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; + Gram.Skeyword ":>"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (e : 'expr) _ + (_loc : Gram.Loc.t) -> + (Ast.ExCoe (_loc, e, Ast.TyNil _loc, t) : + 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ":>"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t2 : 'ctyp) _ (t : 'ctyp) _ (e : 'expr) + _ (_loc : Gram.Loc.t) -> + (Ast.ExCoe (_loc, e, t, t2) : 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ";"; + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ _ (e : 'expr) _ (_loc : Gram.Loc.t) -> + (mksequence _loc e : 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (seq : 'sequence) _ (e : 'expr) _ + (_loc : Gram.Loc.t) -> + (mksequence _loc (Ast.ExSem (_loc, e, seq)) : + 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_expr : 'comma_expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (el : 'comma_expr) _ (e : 'expr) _ + (_loc : Gram.Loc.t) -> + (Ast.ExTup (_loc, Ast.ExCom (_loc, e, el)) : + 'expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (e : 'expr) _ + (_loc : Gram.Loc.t) -> + (Ast.ExTyc (_loc, e, t) : 'expr)))); + ([ Gram.Skeyword "("; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdUid (_loc, "()")) : + 'expr)))); + ([ Gram.Skeyword "{<"; + Gram.Snterm + (Gram.Entry.obj + (field_expr_list : + 'field_expr_list Gram.Entry.t)); + Gram.Skeyword ">}" ], + (Gram.Action.mk + (fun _ (fel : 'field_expr_list) _ + (_loc : Gram.Loc.t) -> + (Ast.ExOvr (_loc, fel) : 'expr)))); + ([ Gram.Skeyword "{<"; Gram.Skeyword ">}" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.ExOvr (_loc, Ast.RbNil _loc) : 'expr)))); + ([ Gram.Skeyword "{"; Gram.Skeyword "("; Gram.Sself; + Gram.Skeyword ")"; Gram.Skeyword "with"; + Gram.Snterm + (Gram.Entry.obj + (label_expr_list : + 'label_expr_list Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (el : 'label_expr_list) _ _ (e : 'expr) _ + _ (_loc : Gram.Loc.t) -> + (Ast.ExRec (_loc, el, e) : 'expr)))); + ([ Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (label_expr_list : + 'label_expr_list Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (el : 'label_expr_list) _ + (_loc : Gram.Loc.t) -> + (Ast.ExRec (_loc, el, Ast.ExNil _loc) : + 'expr)))); + ([ Gram.Skeyword "[|"; + Gram.Snterm + (Gram.Entry.obj + (sem_expr : 'sem_expr Gram.Entry.t)); + Gram.Skeyword "|]" ], + (Gram.Action.mk + (fun _ (el : 'sem_expr) _ (_loc : Gram.Loc.t) -> + (Ast.ExArr (_loc, el) : 'expr)))); + ([ Gram.Skeyword "[|"; Gram.Skeyword "|]" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.ExArr (_loc, Ast.ExNil _loc) : 'expr)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : + 'sem_expr_for_list Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (mk_list : 'sem_expr_for_list) _ + (_loc : Gram.Loc.t) -> + (mk_list + (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) : + 'expr)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : + 'sem_expr_for_list Gram.Entry.t)); + Gram.Skeyword "::"; Gram.Sself; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (last : 'expr) _ + (mk_list : 'sem_expr_for_list) _ + (_loc : Gram.Loc.t) -> (mk_list last : 'expr)))); + ([ Gram.Skeyword "["; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdUid (_loc, "[]")) : + 'expr)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.ExVrn (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (val_longident : + 'val_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'val_longident) (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, i) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj (a_CHAR : 'a_CHAR Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_CHAR) (_loc : Gram.Loc.t) -> + (Ast.ExChr (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_STRING : 'a_STRING Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_STRING) (_loc : Gram.Loc.t) -> + (Ast.ExStr (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_FLOAT : 'a_FLOAT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_FLOAT) (_loc : Gram.Loc.t) -> + (Ast.ExFlo (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_NATIVEINT) (_loc : Gram.Loc.t) -> + (Ast.ExNativeInt (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_INT64 : 'a_INT64 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT64) (_loc : Gram.Loc.t) -> + (Ast.ExInt64 (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_INT32 : 'a_INT32 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT32) (_loc : Gram.Loc.t) -> + (Ast.ExInt32 (_loc, s) : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj (a_INT : 'a_INT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT) (_loc : Gram.Loc.t) -> + (Ast.ExInt (_loc, s) : 'expr)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("seq", _) -> true + | _ -> false), + "ANTIQUOT (\"seq\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("seq" as n)), s) -> + (Ast.ExSeq (_loc, + Ast.ExAnt (_loc, + mk_anti ~c: "expr" n s)) : + 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("tup", _) -> true + | _ -> false), + "ANTIQUOT (\"tup\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("tup" as n)), s) -> + (Ast.ExTup (_loc, + Ast.ExAnt (_loc, + mk_anti ~c: "expr" n s)) : + 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("`bool", _) -> true + | _ -> false), + "ANTIQUOT (\"`bool\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("`bool" as n)), s) -> + (Ast.ExId (_loc, + Ast.IdAnt (_loc, mk_anti n s)) : + 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("exp" | "" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"exp\" | \"\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("exp" | "" | "anti" as n)), s) + -> + (Ast.ExAnt (_loc, mk_anti ~c: "expr" n s) : + 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.expr_tag : + 'expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (do_sequence : 'do_sequence Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (test_not_left_brace_nor_do : + 'test_not_left_brace_nor_do Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "done" ], + (Gram.Action.mk + (fun _ (seq : 'sequence) _ (_loc : Gram.Loc.t) + -> (seq : 'do_sequence)))); + ([ Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (seq : 'sequence) _ (_loc : Gram.Loc.t) + -> (seq : 'do_sequence)))) ]) ])) + ()); + Gram.extend (infixop5 : 'infixop5 Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.srules infixop5 + [ ([ Gram.Skeyword "&&" ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (Gram.Token.extract_string x : 'e__1)))); + ([ Gram.Skeyword "&" ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (Gram.Token.extract_string x : 'e__1)))) ] ], + (Gram.Action.mk + (fun (x : 'e__1) (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdLid (_loc, x)) : + 'infixop5)))) ]) ])) + ()); + Gram.extend (infixop6 : 'infixop6 Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.srules infixop6 + [ ([ Gram.Skeyword "||" ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (Gram.Token.extract_string x : 'e__2)))); + ([ Gram.Skeyword "or" ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (Gram.Token.extract_string x : 'e__2)))) ] ], + (Gram.Action.mk + (fun (x : 'e__2) (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdLid (_loc, x)) : + 'infixop6)))) ]) ])) + ()); + Gram.extend + (sem_expr_for_list : 'sem_expr_for_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (fun acc -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "::")), + e), + acc) : + 'sem_expr_for_list)))); + ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (el : 'sem_expr_for_list) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (fun acc -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "::")), + e), + el acc) : + 'sem_expr_for_list)))) ]) ])) + ()); + Gram.extend (comma_expr : 'comma_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top") ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (e : 'comma_expr)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.ExAnt (_loc, + mk_anti ~c: "expr," n s) : + 'comma_expr) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (e2 : 'comma_expr) _ (e1 : 'comma_expr) + (_loc : Gram.Loc.t) -> + (Ast.ExCom (_loc, e1, e2) : 'comma_expr)))) ]) ])) + ()); + Gram.extend (dummy : 'dummy Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> (() : 'dummy)))) ]) ])) + ()); + Gram.extend (sequence' : 'sequence' Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)) ], + (Gram.Action.mk + (fun (el : 'sequence) _ (_loc : Gram.Loc.t) -> + (fun e -> Ast.ExSem (_loc, e, el) : + 'sequence')))); + ([ Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (fun e -> e : 'sequence')))); + ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (fun e -> e : 'sequence')))) ]) ])) + ()); + Gram.extend (sequence : 'sequence Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (sequence' : 'sequence' Gram.Entry.t)) ], + (Gram.Action.mk + (fun (k : 'sequence') (e : 'expr) + (_loc : Gram.Loc.t) -> (k e : 'sequence)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.ExAnt (_loc, + mk_anti ~c: "expr;" n s) : + 'sequence) + | _ -> assert false))); + ([ Gram.Skeyword "let"; Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (module_binding0 : + 'module_binding0 Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (el : 'sequence) _ (mb : 'module_binding0) + (m : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) -> + (Ast.ExLmd (_loc, m, mb, mksequence _loc el) : + 'sequence)))); + ([ Gram.Skeyword "let"; Gram.Skeyword "module"; + Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (module_binding0 : + 'module_binding0 Gram.Entry.t)); + Gram.Skeyword "in"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (sequence' : 'sequence' Gram.Entry.t)) ], + (Gram.Action.mk + (fun (k : 'sequence') (e : 'expr) _ + (mb : 'module_binding0) (m : 'a_UIDENT) _ _ + (_loc : Gram.Loc.t) -> + (k (Ast.ExLmd (_loc, m, mb, e)) : 'sequence)))); + ([ Gram.Skeyword "let"; + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (el : 'sequence) _ (bi : 'binding) + (rf : 'opt_rec) _ (_loc : Gram.Loc.t) -> + (Ast.ExLet (_loc, rf, bi, mksequence _loc el) : + 'sequence)))); + ([ Gram.Skeyword "let"; + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)); + Gram.Skeyword "in"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (sequence' : 'sequence' Gram.Entry.t)) ], + (Gram.Action.mk + (fun (k : 'sequence') (e : 'expr) _ + (bi : 'binding) (rf : 'opt_rec) _ + (_loc : Gram.Loc.t) -> + (k (Ast.ExLet (_loc, rf, bi, e)) : 'sequence)))) ]) ])) + ()); + Gram.extend (binding : 'binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (let_binding : 'let_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (b : 'let_binding) (_loc : Gram.Loc.t) -> + (b : 'binding)))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (b2 : 'binding) _ (b1 : 'binding) + (_loc : Gram.Loc.t) -> + (Ast.BiAnd (_loc, b1, b2) : 'binding)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.BiAnt (_loc, + mk_anti ~c: "binding" n s) : + 'binding) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.BiEq (_loc, + Ast.PaAnt (_loc, + mk_anti ~c: "patt" n s), + e) : + 'binding) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("binding" | "list"), _) -> true + | _ -> false), + "ANTIQUOT ((\"binding\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("binding" | "list" as n)), s) + -> + (Ast.BiAnt (_loc, + mk_anti ~c: "binding" n s) : + 'binding) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (let_binding : 'let_binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (fun_binding : 'fun_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'fun_binding) (p : 'ipatt) + (_loc : Gram.Loc.t) -> + (Ast.BiEq (_loc, p, e) : 'let_binding)))) ]) ])) + ()); + Gram.extend (fun_binding : 'fun_binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Skeyword ":>"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.ExCoe (_loc, e, Ast.TyNil _loc, t) : + 'fun_binding)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.ExTyc (_loc, e, t) : 'fun_binding)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (e : 'fun_binding)))); + ([ Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (e : 'fun_binding) (p : 'labeled_ipatt) + (_loc : Gram.Loc.t) -> + (Ast.ExFun (_loc, + Ast.McArr (_loc, p, Ast.ExNil _loc, e)) : + 'fun_binding)))) ]) ])) + ()); + Gram.extend (match_case : 'match_case Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (p : 'ipatt) + (_loc : Gram.Loc.t) -> + (Ast.McArr (_loc, p, Ast.ExNil _loc, e) : + 'match_case)))); + ([ Gram.Skeyword "["; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (match_case0 : 'match_case0 Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (l : 'match_case0 list) _ + (_loc : Gram.Loc.t) -> + (Ast.mcOr_of_list l : 'match_case)))) ]) ])) + ()); + Gram.extend (match_case0 : 'match_case0 Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (patt_as_patt_opt : + 'patt_as_patt_opt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_when_expr : + 'opt_when_expr Gram.Entry.t)); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (w : 'opt_when_expr) + (p : 'patt_as_patt_opt) (_loc : Gram.Loc.t) + -> (Ast.McArr (_loc, p, w, e) : 'match_case0)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")); + Gram.Skeyword "when"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (w : 'expr) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.McArr (_loc, + Ast.PaAnt (_loc, + mk_anti ~c: "patt" n s), + w, e) : + 'match_case0) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.McArr (_loc, + Ast.PaAnt (_loc, + mk_anti ~c: "patt" n s), + Ast.ExNil _loc, e) : + 'match_case0) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.McAnt (_loc, + mk_anti ~c: "match_case" n s) : + 'match_case0) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("match_case" | "list"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"match_case\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("match_case" | "list" as n)), + s) -> + (Ast.McAnt (_loc, + mk_anti ~c: "match_case" n s) : + 'match_case0) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (opt_when_expr : 'opt_when_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.ExNil _loc : 'opt_when_expr)))); + ([ Gram.Skeyword "when"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (w : 'expr) _ (_loc : Gram.Loc.t) -> + (w : 'opt_when_expr)))) ]) ])) + ()); + Gram.extend (patt_as_patt_opt : 'patt_as_patt_opt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (p : 'patt_as_patt_opt)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword "as"; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p2 : 'patt) _ (p1 : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaAli (_loc, p1, p2) : + 'patt_as_patt_opt)))) ]) ])) + ()); + Gram.extend (label_expr_list : 'label_expr_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_expr : 'label_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (b1 : 'label_expr) (_loc : Gram.Loc.t) -> + (b1 : 'label_expr_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_expr : 'label_expr Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (b1 : 'label_expr) (_loc : Gram.Loc.t) -> + (b1 : 'label_expr_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_expr : 'label_expr Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (b2 : 'label_expr_list) _ + (b1 : 'label_expr) (_loc : Gram.Loc.t) -> + (Ast.RbSem (_loc, b1, b2) : 'label_expr_list)))) ]) ])) + ()); + Gram.extend (label_expr : 'label_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_longident : + 'label_longident Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (fun_binding : 'fun_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'fun_binding) (i : 'label_longident) + (_loc : Gram.Loc.t) -> + (Ast.RbEq (_loc, i, e) : 'label_expr)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.RbAnt (_loc, + mk_anti ~c: "rec_binding" n s) : + 'label_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.RbEq (_loc, + Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s), + e) : + 'label_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "anti" as n)), s) -> + (Ast.RbAnt (_loc, + mk_anti ~c: "rec_binding" n s) : + 'label_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("rec_binding", _) -> true + | _ -> false), + "ANTIQUOT (\"rec_binding\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("rec_binding" as n)), s) -> + (Ast.RbAnt (_loc, + mk_anti ~c: "rec_binding" n s) : + 'label_expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (fun_def : 'fun_def Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (fun_def_cont : 'fun_def_cont Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((w, e) : 'fun_def_cont) + (p : 'labeled_ipatt) (_loc : Gram.Loc.t) -> + (Ast.ExFun (_loc, Ast.McArr (_loc, p, w, e)) : + 'fun_def)))) ]) ])) + ()); + Gram.extend (fun_def_cont : 'fun_def_cont Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (((Ast.ExNil _loc), e) : 'fun_def_cont)))); + ([ Gram.Skeyword "when"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (w : 'expr) _ + (_loc : Gram.Loc.t) -> + ((w, e) : 'fun_def_cont)))); + ([ Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun ((w, e) : 'fun_def_cont) + (p : 'labeled_ipatt) (_loc : Gram.Loc.t) -> + (((Ast.ExNil _loc), + (Ast.ExFun (_loc, + Ast.McArr (_loc, p, w, e)))) : + 'fun_def_cont)))) ]) ])) + ()); + Gram.extend (patt : 'patt Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "|"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Skeyword "|"; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'patt) _ (p1 : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaOrp (_loc, p1, p2) : 'patt)))) ]); + ((Some ".."), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Sself; Gram.Skeyword ".."; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'patt) _ (p1 : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaRng (_loc, p1, p2) : 'patt)))) ]); + ((Some "apply"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "lazy"; Gram.Sself ], + (Gram.Action.mk + (fun (p : 'patt) _ (_loc : Gram.Loc.t) -> + (Ast.PaLaz (_loc, p) : 'patt)))); + ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'patt) (p1 : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaApp (_loc, p1, p2) : 'patt)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "?"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (patt_tcon : 'patt_tcon Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (e : 'expr) _ (p : 'patt_tcon) _ _ + (_loc : Gram.Loc.t) -> + (Ast.PaOlbi (_loc, "", p, e) : 'patt)))); + ([ Gram.Skeyword "?"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (patt_tcon : 'patt_tcon Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'patt_tcon) _ _ (_loc : Gram.Loc.t) + -> (Ast.PaOlb (_loc, "", p) : 'patt)))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaOlb (_loc, mk_anti n i, + Ast.PaNil _loc) : + 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function | LIDENT _ -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT i -> + (Ast.PaOlb (_loc, i, Ast.PaNil _loc) : + 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")); + Gram.Skeyword ":"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (patt_tcon : 'patt_tcon Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (eq_expr : 'eq_expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (f : 'eq_expr) (p : 'patt_tcon) _ _ + (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (f (mk_anti n i) p : 'patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function | OPTLABEL _ -> true | _ -> false), + "OPTLABEL _")); + Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (patt_tcon : 'patt_tcon Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (eq_expr : 'eq_expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (f : 'eq_expr) (p : 'patt_tcon) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | OPTLABEL i -> (f i p : 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function | LIDENT _ -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT i -> + (Ast.PaLab (_loc, i, Ast.PaNil _loc) : + 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaLab (_loc, mk_anti n i, + Ast.PaNil _loc) : + 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (p : 'patt) _ (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaLab (_loc, mk_anti n i, p) : + 'patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function | LABEL _ -> true | _ -> false), + "LABEL _")); + Gram.Sself ], + (Gram.Action.mk + (fun (p : 'patt) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LABEL i -> (Ast.PaLab (_loc, i, p) : 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (type_longident : + 'type_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'type_longident) _ (_loc : Gram.Loc.t) + -> (Ast.PaTyp (_loc, i) : 'patt)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.PaVrn (_loc, s) : 'patt)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.patt_tag : + 'patt) + | _ -> assert false))); + ([ Gram.Skeyword "_" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.PaAny _loc : 'patt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_patt : 'comma_patt Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (pl : 'comma_patt) _ (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTup (_loc, Ast.PaCom (_loc, p, pl)) : + 'patt)))); + ([ Gram.Skeyword "("; Gram.Sself; + Gram.Skeyword "as"; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p2 : 'patt) _ (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaAli (_loc, p, p2) : 'patt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTyc (_loc, p, t) : 'patt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'patt) _ (_loc : Gram.Loc.t) -> + (p : 'patt)))); + ([ Gram.Skeyword "("; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, Ast.IdUid (_loc, "()")) : + 'patt)))); + ([ Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (label_patt_list : + 'label_patt_list Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (pl : 'label_patt_list) _ + (_loc : Gram.Loc.t) -> + (Ast.PaRec (_loc, pl) : 'patt)))); + ([ Gram.Skeyword "[|"; + Gram.Snterm + (Gram.Entry.obj + (sem_patt : 'sem_patt Gram.Entry.t)); + Gram.Skeyword "|]" ], + (Gram.Action.mk + (fun _ (pl : 'sem_patt) _ (_loc : Gram.Loc.t) -> + (Ast.PaArr (_loc, pl) : 'patt)))); + ([ Gram.Skeyword "[|"; Gram.Skeyword "|]" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.PaArr (_loc, Ast.PaNil _loc) : 'patt)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_patt_for_list : + 'sem_patt_for_list Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (mk_list : 'sem_patt_for_list) _ + (_loc : Gram.Loc.t) -> + (mk_list + (Ast.PaId (_loc, Ast.IdUid (_loc, "[]"))) : + 'patt)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_patt_for_list : + 'sem_patt_for_list Gram.Entry.t)); + Gram.Skeyword "::"; Gram.Sself; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (last : 'patt) _ + (mk_list : 'sem_patt_for_list) _ + (_loc : Gram.Loc.t) -> (mk_list last : 'patt)))); + ([ Gram.Skeyword "["; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, Ast.IdUid (_loc, "[]")) : + 'patt)))); + ([ Gram.Skeyword "-"; + Gram.Snterm + (Gram.Entry.obj + (a_FLOAT : 'a_FLOAT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_FLOAT) _ (_loc : Gram.Loc.t) -> + (Ast.PaFlo (_loc, neg_string s) : 'patt)))); + ([ Gram.Skeyword "-"; + Gram.Snterm + (Gram.Entry.obj + (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_NATIVEINT) _ (_loc : Gram.Loc.t) -> + (Ast.PaNativeInt (_loc, neg_string s) : + 'patt)))); + ([ Gram.Skeyword "-"; + Gram.Snterm + (Gram.Entry.obj + (a_INT64 : 'a_INT64 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT64) _ (_loc : Gram.Loc.t) -> + (Ast.PaInt64 (_loc, neg_string s) : 'patt)))); + ([ Gram.Skeyword "-"; + Gram.Snterm + (Gram.Entry.obj + (a_INT32 : 'a_INT32 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT32) _ (_loc : Gram.Loc.t) -> + (Ast.PaInt32 (_loc, neg_string s) : 'patt)))); + ([ Gram.Skeyword "-"; + Gram.Snterm + (Gram.Entry.obj (a_INT : 'a_INT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT) _ (_loc : Gram.Loc.t) -> + (Ast.PaInt (_loc, neg_string s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj (a_CHAR : 'a_CHAR Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_CHAR) (_loc : Gram.Loc.t) -> + (Ast.PaChr (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_STRING : 'a_STRING Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_STRING) (_loc : Gram.Loc.t) -> + (Ast.PaStr (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_FLOAT : 'a_FLOAT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_FLOAT) (_loc : Gram.Loc.t) -> + (Ast.PaFlo (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_NATIVEINT) (_loc : Gram.Loc.t) -> + (Ast.PaNativeInt (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_INT64 : 'a_INT64 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT64) (_loc : Gram.Loc.t) -> + (Ast.PaInt64 (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_INT32 : 'a_INT32 Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT32) (_loc : Gram.Loc.t) -> + (Ast.PaInt32 (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj (a_INT : 'a_INT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_INT) (_loc : Gram.Loc.t) -> + (Ast.PaInt (_loc, s) : 'patt)))); + ([ Gram.Snterm + (Gram.Entry.obj (ident : 'ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'ident) (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, i) : 'patt)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("`bool", _) -> true + | _ -> false), + "ANTIQUOT (\"`bool\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("`bool" as n)), s) -> + (Ast.PaId (_loc, + Ast.IdAnt (_loc, mk_anti n s)) : + 'patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("tup", _) -> true + | _ -> false), + "ANTIQUOT (\"tup\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("tup" as n)), s) -> + (Ast.PaTup (_loc, + Ast.PaAnt (_loc, + mk_anti ~c: "patt" n s)) : + 'patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "pat" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"pat\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "pat" | "anti" as n)), s) + -> + (Ast.PaAnt (_loc, mk_anti ~c: "patt" n s) : + 'patt) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (comma_patt : 'comma_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (p : 'comma_patt)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.PaAnt (_loc, + mk_anti ~c: "patt," n s) : + 'comma_patt) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'comma_patt) _ (p1 : 'comma_patt) + (_loc : Gram.Loc.t) -> + (Ast.PaCom (_loc, p1, p2) : 'comma_patt)))) ]) ])) + ()); + Gram.extend (sem_patt : 'sem_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (p : 'sem_patt)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.PaAnt (_loc, + mk_anti ~c: "patt;" n s) : + 'sem_patt) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'sem_patt) _ (p1 : 'sem_patt) + (_loc : Gram.Loc.t) -> + (Ast.PaSem (_loc, p1, p2) : 'sem_patt)))) ]) ])) + ()); + Gram.extend + (sem_patt_for_list : 'sem_patt_for_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (fun acc -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdUid (_loc, "::")), + p), + acc) : + 'sem_patt_for_list)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (pl : 'sem_patt_for_list) _ (p : 'patt) + (_loc : Gram.Loc.t) -> + (fun acc -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdUid (_loc, "::")), + p), + pl acc) : + 'sem_patt_for_list)))) ]) ])) + ()); + Gram.extend (label_patt_list : 'label_patt_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_patt : 'label_patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p1 : 'label_patt) (_loc : Gram.Loc.t) -> + (p1 : 'label_patt_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_patt : 'label_patt Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (p1 : 'label_patt) (_loc : Gram.Loc.t) -> + (p1 : 'label_patt_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_patt : 'label_patt Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'label_patt_list) _ + (p1 : 'label_patt) (_loc : Gram.Loc.t) -> + (Ast.PaSem (_loc, p1, p2) : 'label_patt_list)))) ]) ])) + ()); + Gram.extend (label_patt : 'label_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_longident : + 'label_longident Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) _ (i : 'label_longident) + (_loc : Gram.Loc.t) -> + (Ast.PaEq (_loc, i, p) : 'label_patt)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.PaAnt (_loc, + mk_anti ~c: "patt;" n s) : + 'label_patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.patt_tag : + 'label_patt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "pat" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"pat\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "pat" | "anti" as n)), s) + -> + (Ast.PaAnt (_loc, mk_anti ~c: "patt" n s) : + 'label_patt) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (ipatt : 'ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "_" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.PaAny _loc : 'ipatt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, Ast.IdLid (_loc, s)) : + 'ipatt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_ipatt : 'comma_ipatt Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (pl : 'comma_ipatt) _ (p : 'ipatt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTup (_loc, Ast.PaCom (_loc, p, pl)) : + 'ipatt)))); + ([ Gram.Skeyword "("; Gram.Sself; + Gram.Skeyword "as"; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p2 : 'ipatt) _ (p : 'ipatt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaAli (_loc, p, p2) : 'ipatt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (p : 'ipatt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTyc (_loc, p, t) : 'ipatt)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'ipatt) _ (_loc : Gram.Loc.t) -> + (p : 'ipatt)))); + ([ Gram.Skeyword "("; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, Ast.IdUid (_loc, "()")) : + 'ipatt)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.patt_tag : + 'ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("tup", _) -> true + | _ -> false), + "ANTIQUOT (\"tup\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("tup" as n)), s) -> + (Ast.PaTup (_loc, + Ast.PaAnt (_loc, + mk_anti ~c: "patt" n s)) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "pat" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"pat\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "pat" | "anti" as n)), s) + -> + (Ast.PaAnt (_loc, mk_anti ~c: "patt" n s) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (label_ipatt_list : + 'label_ipatt_list Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (pl : 'label_ipatt_list) _ + (_loc : Gram.Loc.t) -> + (Ast.PaRec (_loc, pl) : 'ipatt)))) ]) ])) + ()); + Gram.extend (labeled_ipatt : 'labeled_ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'ipatt) (_loc : Gram.Loc.t) -> + (p : 'labeled_ipatt)))) ]) ])) + ()); + Gram.extend (comma_ipatt : 'comma_ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'ipatt) (_loc : Gram.Loc.t) -> + (p : 'comma_ipatt)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.PaAnt (_loc, + mk_anti ~c: "patt," n s) : + 'comma_ipatt) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'comma_ipatt) _ (p1 : 'comma_ipatt) + (_loc : Gram.Loc.t) -> + (Ast.PaCom (_loc, p1, p2) : 'comma_ipatt)))) ]) ])) + ()); + Gram.extend (label_ipatt_list : 'label_ipatt_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_ipatt : 'label_ipatt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p1 : 'label_ipatt) (_loc : Gram.Loc.t) -> + (p1 : 'label_ipatt_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_ipatt : 'label_ipatt Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (p1 : 'label_ipatt) (_loc : Gram.Loc.t) + -> (p1 : 'label_ipatt_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_ipatt : 'label_ipatt Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'label_ipatt_list) _ + (p1 : 'label_ipatt) (_loc : Gram.Loc.t) -> + (Ast.PaSem (_loc, p1, p2) : + 'label_ipatt_list)))) ]) ])) + ()); + Gram.extend (label_ipatt : 'label_ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_longident : + 'label_longident Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'ipatt) _ (i : 'label_longident) + (_loc : Gram.Loc.t) -> + (Ast.PaEq (_loc, i, p) : 'label_ipatt)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.patt_tag : + 'label_ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.PaAnt (_loc, + mk_anti ~c: "patt;" n s) : + 'label_ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "pat" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"pat\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "pat" | "anti" as n)), s) + -> + (Ast.PaAnt (_loc, mk_anti ~c: "patt" n s) : + 'label_ipatt) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (type_declaration : 'type_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_ident_and_parameters : + 'type_ident_and_parameters Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_eq_ctyp : 'opt_eq_ctyp Gram.Entry.t)); + Gram.Slist0 + (Gram.Snterm + (Gram.Entry.obj + (constrain : 'constrain Gram.Entry.t))) ], + (Gram.Action.mk + (fun (cl : 'constrain list) (tk : 'opt_eq_ctyp) + ((n, tpl) : 'type_ident_and_parameters) + (_loc : Gram.Loc.t) -> + (Ast.TyDcl (_loc, n, tpl, tk, cl) : + 'type_declaration)))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'type_declaration) _ + (t1 : 'type_declaration) (_loc : Gram.Loc.t) + -> + (Ast.TyAnd (_loc, t1, t2) : + 'type_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'type_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctypand" n s) : + 'type_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" | "anti" as n)), s) + -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'type_declaration) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (constrain : 'constrain Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "constraint"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) _ + (_loc : Gram.Loc.t) -> + ((t1, t2) : 'constrain)))) ]) ])) + ()); + Gram.extend (opt_eq_ctyp : 'opt_eq_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.TyNil _loc : 'opt_eq_ctyp)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (type_kind : 'type_kind Gram.Entry.t)) ], + (Gram.Action.mk + (fun (tk : 'type_kind) _ (_loc : Gram.Loc.t) -> + (tk : 'opt_eq_ctyp)))) ]) ])) + ()); + Gram.extend (type_kind : 'type_kind Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'type_kind)))) ]) ])) + ()); + Gram.extend + (type_ident_and_parameters : + 'type_ident_and_parameters Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Slist0 + (Gram.Snterm + (Gram.Entry.obj + (type_parameter : + 'type_parameter Gram.Entry.t))) ], + (Gram.Action.mk + (fun (tpl : 'type_parameter list) + (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + ((i, tpl) : 'type_ident_and_parameters)))) ]) ])) + ()); + Gram.extend + (type_longident_and_parameters : + 'type_longident_and_parameters Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_longident : + 'type_longident Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (type_parameters : + 'type_parameters Gram.Entry.t)) ], + (Gram.Action.mk + (fun (tpl : 'type_parameters) + (i : 'type_longident) (_loc : Gram.Loc.t) -> + (tpl (Ast.TyId (_loc, i)) : + 'type_longident_and_parameters)))) ]) ])) + ()); + Gram.extend (type_parameters : 'type_parameters Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (fun t -> t : 'type_parameters)))); + ([ Gram.Snterm + (Gram.Entry.obj + (type_parameter : + 'type_parameter Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'type_parameter) (_loc : Gram.Loc.t) + -> + (fun acc -> Ast.TyApp (_loc, acc, t) : + 'type_parameters)))); + ([ Gram.Snterm + (Gram.Entry.obj + (type_parameter : + 'type_parameter Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'type_parameters) + (t1 : 'type_parameter) (_loc : Gram.Loc.t) -> + (fun acc -> t2 (Ast.TyApp (_loc, acc, t1)) : + 'type_parameters)))) ]) ])) + ()); + Gram.extend (type_parameter : 'type_parameter Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "-"; Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ _ (_loc : Gram.Loc.t) -> + (Ast.TyQuM (_loc, i) : 'type_parameter)))); + ([ Gram.Skeyword "+"; Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ _ (_loc : Gram.Loc.t) -> + (Ast.TyQuP (_loc, i) : 'type_parameter)))); + ([ Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyQuo (_loc, i) : 'type_parameter)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'type_parameter) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" | "anti" as n)), s) + -> + (Ast.TyAnt (_loc, mk_anti n s) : + 'type_parameter) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (ctyp : 'ctyp Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "=="), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Skeyword "=="; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyMan (_loc, t1, t2) : 'ctyp)))) ]); + ((Some "private"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Skeyword "private"; + Gram.Snterml + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t), + "alias") ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (_loc : Gram.Loc.t) -> + (Ast.TyPrv (_loc, t) : 'ctyp)))) ]); + ((Some "alias"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Skeyword "as"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyAli (_loc, t1, t2) : 'ctyp)))) ]); + ((Some "forall"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "!"; + Gram.Snterm + (Gram.Entry.obj + (typevars : 'typevars Gram.Entry.t)); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'typevars) _ + (_loc : Gram.Loc.t) -> + (Ast.TyPol (_loc, t1, t2) : 'ctyp)))) ]); + ((Some "arrow"), (Some Camlp4.Sig.Grammar.RightA), + [ ([ Gram.Sself; Gram.Skeyword "->"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyArr (_loc, t1, t2) : 'ctyp)))) ]); + ((Some "label"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_OPTLABEL : 'a_OPTLABEL Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (t : 'ctyp) (i : 'a_OPTLABEL) + (_loc : Gram.Loc.t) -> + (Ast.TyOlb (_loc, i, t) : 'ctyp)))); + ([ Gram.Skeyword "?"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (i : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.TyOlb (_loc, i, t) : 'ctyp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LABEL : 'a_LABEL Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (t : 'ctyp) (i : 'a_LABEL) + (_loc : Gram.Loc.t) -> + (Ast.TyLab (_loc, i, t) : 'ctyp)))); + ([ Gram.Skeyword "~"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (i : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.TyLab (_loc, i, t) : 'ctyp)))) ]); + ((Some "apply"), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) (t1 : 'ctyp) + (_loc : Gram.Loc.t) -> + (let t = Ast.TyApp (_loc, t1, t2) + in + try Ast.TyId (_loc, Ast.ident_of_ctyp t) + with | Invalid_argument _ -> t : + 'ctyp)))) ]); + ((Some "."), (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) + (_loc : Gram.Loc.t) -> + (try + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.ident_of_ctyp t1, + Ast.ident_of_ctyp t2)) + with + | Invalid_argument s -> + raise (Stream.Error s) : + 'ctyp)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "<"; + Gram.Snterm + (Gram.Entry.obj + (opt_meth_list : + 'opt_meth_list Gram.Entry.t)); + Gram.Skeyword ">" ], + (Gram.Action.mk + (fun _ (t : 'opt_meth_list) _ + (_loc : Gram.Loc.t) -> (t : 'ctyp)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (class_longident : + 'class_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'class_longident) _ + (_loc : Gram.Loc.t) -> + (Ast.TyCls (_loc, i) : 'ctyp)))); + ([ Gram.Skeyword "{"; + Gram.Snterm + (Gram.Entry.obj + (label_declaration_list : + 'label_declaration_list Gram.Entry.t)); + Gram.Skeyword "}" ], + (Gram.Action.mk + (fun _ (t : 'label_declaration_list) _ + (_loc : Gram.Loc.t) -> + (Ast.TyRec (_loc, t) : 'ctyp)))); + ([ Gram.Skeyword "[<"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword ">"; + Gram.Snterm + (Gram.Entry.obj + (name_tags : 'name_tags Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (ntl : 'name_tags) _ (rfl : 'row_field) _ + (_loc : Gram.Loc.t) -> + (Ast.TyVrnInfSup (_loc, rfl, ntl) : 'ctyp)))); + ([ Gram.Skeyword "[<"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rfl : 'row_field) _ (_loc : Gram.Loc.t) + -> (Ast.TyVrnInf (_loc, rfl) : 'ctyp)))); + ([ Gram.Skeyword "["; Gram.Skeyword "<"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword ">"; + Gram.Snterm + (Gram.Entry.obj + (name_tags : 'name_tags Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (ntl : 'name_tags) _ (rfl : 'row_field) _ + _ (_loc : Gram.Loc.t) -> + (Ast.TyVrnInfSup (_loc, rfl, ntl) : 'ctyp)))); + ([ Gram.Skeyword "["; Gram.Skeyword "<"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rfl : 'row_field) _ _ + (_loc : Gram.Loc.t) -> + (Ast.TyVrnInf (_loc, rfl) : 'ctyp)))); + ([ Gram.Skeyword "["; Gram.Skeyword ">"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rfl : 'row_field) _ _ + (_loc : Gram.Loc.t) -> + (Ast.TyVrnSup (_loc, rfl) : 'ctyp)))); + ([ Gram.Skeyword "["; Gram.Skeyword ">"; + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ _ _ (_loc : Gram.Loc.t) -> + (Ast.TyVrnSup (_loc, Ast.TyNil _loc) : 'ctyp)))); + ([ Gram.Skeyword "["; Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rfl : 'row_field) _ _ + (_loc : Gram.Loc.t) -> + (Ast.TyVrnEq (_loc, rfl) : 'ctyp)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (constructor_declarations : + 'constructor_declarations Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (t : 'constructor_declarations) _ + (_loc : Gram.Loc.t) -> + (Ast.TySum (_loc, t) : 'ctyp)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (_loc : Gram.Loc.t) -> + (t : 'ctyp)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword "*"; + Gram.Snterm + (Gram.Entry.obj + (star_ctyp : 'star_ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (tl : 'star_ctyp) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.TyTup (_loc, Ast.TySta (_loc, t, tl)) : + 'ctyp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyId (_loc, Ast.IdUid (_loc, i)) : + 'ctyp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyId (_loc, Ast.IdLid (_loc, i)) : + 'ctyp)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'ctyp) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("id", _) -> true + | _ -> false), + "ANTIQUOT (\"id\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("id" as n)), s) -> + (Ast.TyId (_loc, + Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s)) : + 'ctyp) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("tup", _) -> true + | _ -> false), + "ANTIQUOT (\"tup\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("tup" as n)), s) -> + (Ast.TyTup (_loc, + Ast.TyAnt (_loc, + mk_anti ~c: "ctyp" n s)) : + 'ctyp) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" | "anti" as n)), s) + -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'ctyp) + | _ -> assert false))); + ([ Gram.Skeyword "_" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.TyAny _loc : 'ctyp)))); + ([ Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyQuo (_loc, i) : 'ctyp)))) ]) ])) + ()); + Gram.extend (star_ctyp : 'star_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'star_ctyp)))); + ([ Gram.Sself; Gram.Skeyword "*"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'star_ctyp) _ (t1 : 'star_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TySta (_loc, t1, t2) : 'star_ctyp)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp*" n s) : + 'star_ctyp) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'star_ctyp) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (constructor_declarations : + 'constructor_declarations Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyId (_loc, Ast.IdUid (_loc, s)) : + 'constructor_declarations)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "of"; + Gram.Snterm + (Gram.Entry.obj + (constructor_arg_list : + 'constructor_arg_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'constructor_arg_list) _ + (s : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyOf (_loc, + Ast.TyId (_loc, Ast.IdUid (_loc, s)), t) : + 'constructor_declarations)))); + ([ Gram.Sself; Gram.Skeyword "|"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'constructor_declarations) _ + (t1 : 'constructor_declarations) + (_loc : Gram.Loc.t) -> + (Ast.TyOr (_loc, t1, t2) : + 'constructor_declarations)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'constructor_declarations) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp|" n s) : + 'constructor_declarations) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'constructor_declarations) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (constructor_declaration : + 'constructor_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyId (_loc, Ast.IdUid (_loc, s)) : + 'constructor_declaration)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "of"; + Gram.Snterm + (Gram.Entry.obj + (constructor_arg_list : + 'constructor_arg_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'constructor_arg_list) _ + (s : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.TyOf (_loc, + Ast.TyId (_loc, Ast.IdUid (_loc, s)), t) : + 'constructor_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'constructor_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'constructor_declaration) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (constructor_arg_list : 'constructor_arg_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'constructor_arg_list)))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'constructor_arg_list) _ + (t1 : 'constructor_arg_list) + (_loc : Gram.Loc.t) -> + (Ast.TyAnd (_loc, t1, t2) : + 'constructor_arg_list)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctypand" n s) : + 'constructor_arg_list) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (label_declaration_list : + 'label_declaration_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_declaration : + 'label_declaration Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t1 : 'label_declaration) + (_loc : Gram.Loc.t) -> + (t1 : 'label_declaration_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_declaration : + 'label_declaration Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (t1 : 'label_declaration) + (_loc : Gram.Loc.t) -> + (t1 : 'label_declaration_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_declaration : + 'label_declaration Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'label_declaration_list) _ + (t1 : 'label_declaration) (_loc : Gram.Loc.t) + -> + (Ast.TySem (_loc, t1, t2) : + 'label_declaration_list)))) ]) ])) + ()); + Gram.extend + (label_declaration : 'label_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; Gram.Skeyword "mutable"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ _ (s : 'a_LIDENT) + (_loc : Gram.Loc.t) -> + (Ast.TyCol (_loc, + Ast.TyId (_loc, Ast.IdLid (_loc, s)), + Ast.TyMut (_loc, t)) : + 'label_declaration)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (s : 'a_LIDENT) + (_loc : Gram.Loc.t) -> + (Ast.TyCol (_loc, + Ast.TyId (_loc, Ast.IdLid (_loc, s)), t) : + 'label_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'label_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp;" n s) : + 'label_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'label_declaration) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_ident : 'a_ident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (i : 'a_ident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (i : 'a_ident)))) ]) ])) + ()); + Gram.extend (ident : 'ident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'ident) _ (i : 'a_UIDENT) + (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, Ast.IdUid (_loc, i), j) : + 'ident)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (i : 'ident) _ (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAcc (_loc, + Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s), + i) : + 'ident) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdLid (_loc, i) : 'ident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdUid (_loc, i) : 'ident)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'ident) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (module_longident : 'module_longident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdUid (_loc, i) : 'module_longident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (l : 'module_longident) _ (m : 'a_UIDENT) + (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, Ast.IdUid (_loc, m), l) : + 'module_longident)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'module_longident) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (module_longident_with_app : + 'module_longident_with_app Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "apply"), None, + [ ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'module_longident_with_app) + (i : 'module_longident_with_app) + (_loc : Gram.Loc.t) -> + (Ast.IdApp (_loc, i, j) : + 'module_longident_with_app)))) ]); + ((Some "."), None, + [ ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'module_longident_with_app) _ + (i : 'module_longident_with_app) + (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, i, j) : + 'module_longident_with_app)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (i : 'module_longident_with_app) _ + (_loc : Gram.Loc.t) -> + (i : 'module_longident_with_app)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdUid (_loc, i) : + 'module_longident_with_app)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'module_longident_with_app) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (type_longident : 'type_longident Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "apply"), None, + [ ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'type_longident) (i : 'type_longident) + (_loc : Gram.Loc.t) -> + (Ast.IdApp (_loc, i, j) : 'type_longident)))) ]); + ((Some "."), None, + [ ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'type_longident) _ + (i : 'type_longident) (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, i, j) : 'type_longident)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (i : 'type_longident) _ + (_loc : Gram.Loc.t) -> (i : 'type_longident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdUid (_loc, i) : 'type_longident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdLid (_loc, i) : 'type_longident)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'type_longident) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (label_longident : 'label_longident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdLid (_loc, i) : 'label_longident)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (l : 'label_longident) _ (m : 'a_UIDENT) + (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, Ast.IdUid (_loc, m), l) : + 'label_longident)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'label_longident) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (class_type_longident : 'class_type_longident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_longident : + 'type_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'type_longident) (_loc : Gram.Loc.t) + -> (x : 'class_type_longident)))) ]) ])) + ()); + Gram.extend (val_longident : 'val_longident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ident : 'ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'ident) (_loc : Gram.Loc.t) -> + (x : 'val_longident)))) ]) ])) + ()); + Gram.extend (class_longident : 'class_longident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (label_longident : + 'label_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'label_longident) (_loc : Gram.Loc.t) + -> (x : 'class_longident)))) ]) ])) + ()); + Gram.extend + (class_declaration : 'class_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_info_for_class_expr : + 'class_info_for_class_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_fun_binding : + 'class_fun_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_fun_binding) + (ci : 'class_info_for_class_expr) + (_loc : Gram.Loc.t) -> + (Ast.CeEq (_loc, ci, ce) : + 'class_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_expr_tag : + 'class_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "cdcl" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"cdcl\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "cdcl" | "anti" | "list" as n)), + s) -> + (Ast.CeAnt (_loc, + mk_anti ~c: "class_expr" n s) : + 'class_declaration) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (c2 : 'class_declaration) _ + (c1 : 'class_declaration) (_loc : Gram.Loc.t) + -> + (Ast.CeAnd (_loc, c1, c2) : + 'class_declaration)))) ]) ])) + ()); + Gram.extend + (class_fun_binding : 'class_fun_binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (cfb : 'class_fun_binding) + (p : 'labeled_ipatt) (_loc : Gram.Loc.t) -> + (Ast.CeFun (_loc, p, cfb) : + 'class_fun_binding)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (class_type_plus : + 'class_type_plus Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (class_expr : 'class_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_expr) _ + (ct : 'class_type_plus) _ (_loc : Gram.Loc.t) + -> + (Ast.CeTyc (_loc, ce, ct) : + 'class_fun_binding)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (class_expr : 'class_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_expr) _ (_loc : Gram.Loc.t) -> + (ce : 'class_fun_binding)))) ]) ])) + ()); + Gram.extend + (class_info_for_class_type : + 'class_info_for_class_type Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (opt_virtual : 'opt_virtual Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_name_and_param : + 'class_name_and_param Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((i, ot) : 'class_name_and_param) + (mv : 'opt_virtual) (_loc : Gram.Loc.t) -> + (Ast.CtCon (_loc, mv, Ast.IdLid (_loc, i), + ot) : + 'class_info_for_class_type)))) ]) ])) + ()); + Gram.extend + (class_info_for_class_expr : + 'class_info_for_class_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (opt_virtual : 'opt_virtual Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_name_and_param : + 'class_name_and_param Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((i, ot) : 'class_name_and_param) + (mv : 'opt_virtual) (_loc : Gram.Loc.t) -> + (Ast.CeCon (_loc, mv, Ast.IdLid (_loc, i), + ot) : + 'class_info_for_class_expr)))) ]) ])) + ()); + Gram.extend + (class_name_and_param : 'class_name_and_param Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + ((i, (Ast.TyNil _loc)) : + 'class_name_and_param)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (comma_type_parameter : + 'comma_type_parameter Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (x : 'comma_type_parameter) _ + (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + ((i, x) : 'class_name_and_param)))) ]) ])) + ()); + Gram.extend + (comma_type_parameter : 'comma_type_parameter Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_parameter : + 'type_parameter Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'type_parameter) (_loc : Gram.Loc.t) + -> (t : 'comma_type_parameter)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp," n s) : + 'comma_type_parameter) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'comma_type_parameter) _ + (t1 : 'comma_type_parameter) + (_loc : Gram.Loc.t) -> + (Ast.TyCom (_loc, t1, t2) : + 'comma_type_parameter)))) ]) ])) + ()); + Gram.extend (opt_comma_ctyp : 'opt_comma_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.TyNil _loc : 'opt_comma_ctyp)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (comma_ctyp : 'comma_ctyp Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (x : 'comma_ctyp) _ (_loc : Gram.Loc.t) + -> (x : 'opt_comma_ctyp)))) ]) ])) + ()); + Gram.extend (comma_ctyp : 'comma_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'comma_ctyp)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp," n s) : + 'comma_ctyp) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'comma_ctyp) _ (t1 : 'comma_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyCom (_loc, t1, t2) : 'comma_ctyp)))) ]) ])) + ()); + Gram.extend (class_fun_def : 'class_fun_def Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj + (class_expr : 'class_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_expr) _ (_loc : Gram.Loc.t) -> + (ce : 'class_fun_def)))); + ([ Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (ce : 'class_fun_def) (p : 'labeled_ipatt) + (_loc : Gram.Loc.t) -> + (Ast.CeFun (_loc, p, ce) : 'class_fun_def)))) ]) ])) + ()); + Gram.extend (class_expr : 'class_expr Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), None, + [ ([ Gram.Skeyword "let"; + Gram.Snterm + (Gram.Entry.obj + (opt_rec : 'opt_rec Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)); + Gram.Skeyword "in"; Gram.Sself ], + (Gram.Action.mk + (fun (ce : 'class_expr) _ (bi : 'binding) + (rf : 'opt_rec) _ (_loc : Gram.Loc.t) -> + (Ast.CeLet (_loc, rf, bi, ce) : 'class_expr)))); + ([ Gram.Skeyword "fun"; + Gram.Snterm + (Gram.Entry.obj + (labeled_ipatt : + 'labeled_ipatt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_fun_def : + 'class_fun_def Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_fun_def) (p : 'labeled_ipatt) + _ (_loc : Gram.Loc.t) -> + (Ast.CeFun (_loc, p, ce) : 'class_expr)))) ]); + ((Some "apply"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Sself; + Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "label") ], + (Gram.Action.mk + (fun (e : 'expr) (ce : 'class_expr) + (_loc : Gram.Loc.t) -> + (Ast.CeApp (_loc, ce, e) : 'class_expr)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (ce : 'class_expr) _ (_loc : Gram.Loc.t) + -> (ce : 'class_expr)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (class_type : 'class_type Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (ct : 'class_type) _ (ce : 'class_expr) _ + (_loc : Gram.Loc.t) -> + (Ast.CeTyc (_loc, ce, ct) : 'class_expr)))); + ([ Gram.Skeyword "object"; + Gram.Snterm + (Gram.Entry.obj + (opt_class_self_patt : + 'opt_class_self_patt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_structure : + 'class_structure Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (cst : 'class_structure) + (csp : 'opt_class_self_patt) _ + (_loc : Gram.Loc.t) -> + (Ast.CeStr (_loc, csp, cst) : 'class_expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_longident_and_param : + 'class_longident_and_param Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ce : 'class_longident_and_param) + (_loc : Gram.Loc.t) -> (ce : 'class_expr)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_expr_tag : + 'class_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "cexp" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"cexp\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "cexp" | "anti" as n)), s) + -> + (Ast.CeAnt (_loc, + mk_anti ~c: "class_expr" n s) : + 'class_expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (class_longident_and_param : + 'class_longident_and_param Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_longident : + 'class_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ci : 'class_longident) (_loc : Gram.Loc.t) + -> + (Ast.CeCon (_loc, Ast.BFalse, ci, + Ast.TyNil _loc) : + 'class_longident_and_param)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_longident : + 'class_longident Gram.Entry.t)); + Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (comma_ctyp : 'comma_ctyp Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (t : 'comma_ctyp) _ + (ci : 'class_longident) (_loc : Gram.Loc.t) + -> + (Ast.CeCon (_loc, Ast.BFalse, ci, t) : + 'class_longident_and_param)))) ]) ])) + ()); + Gram.extend (class_structure : 'class_structure Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist0 + (Gram.srules class_structure + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_str_item : + 'class_str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (cst : 'class_str_item) + (_loc : Gram.Loc.t) -> + (cst : 'e__3)))) ]) ], + (Gram.Action.mk + (fun (l : 'e__3 list) (_loc : Gram.Loc.t) -> + (Ast.crSem_of_list l : 'class_structure)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "cst" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"cst\" | \"anti\" | \"list\"), _)")); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (cst : 'class_structure) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "cst" | "anti" | "list" as n)), + s) -> + (Ast.CrSem (_loc, + Ast.CrAnt (_loc, + mk_anti ~c: "class_str_item" n s), + cst) : + 'class_structure) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "cst" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"cst\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "cst" | "anti" | "list" as n)), + s) -> + (Ast.CrAnt (_loc, + mk_anti ~c: "class_str_item" n s) : + 'class_structure) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (opt_class_self_patt : 'opt_class_self_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.PaNil _loc : 'opt_class_self_patt)))); + ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTyc (_loc, p, t) : + 'opt_class_self_patt)))); + ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'patt) _ (_loc : Gram.Loc.t) -> + (p : 'opt_class_self_patt)))) ]) ])) + ()); + Gram.extend (class_str_item : 'class_str_item Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "initializer"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (se : 'expr) _ (_loc : Gram.Loc.t) -> + (Ast.CrIni (_loc, se) : 'class_str_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (type_constraint : + 'type_constraint Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.CrCtr (_loc, t1, t2) : 'class_str_item)))); + ([ Gram.Skeyword "method"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_polyt : 'opt_polyt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (fun_binding : 'fun_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'fun_binding) (topt : 'opt_polyt) + (l : 'label) (pf : 'opt_private) _ + (_loc : Gram.Loc.t) -> + (Ast.CrMth (_loc, l, pf, e, topt) : + 'class_str_item)))); + ([ Gram.Skeyword "method"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) _ + (pf : 'opt_private) _ (_loc : Gram.Loc.t) -> + (Ast.CrVir (_loc, l, pf, t) : + 'class_str_item)))); + ([ Gram.Skeyword "method"; Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) + (pf : 'opt_private) _ _ (_loc : Gram.Loc.t) + -> + (Ast.CrVir (_loc, l, pf, t) : + 'class_str_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_val : 'value_val Gram.Entry.t)); + Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj + (opt_mutable : 'opt_mutable Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) + (mf : 'opt_mutable) _ _ (_loc : Gram.Loc.t) + -> + (Ast.CrVvr (_loc, l, mf, t) : + 'class_str_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_val : 'value_val Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_mutable : 'opt_mutable Gram.Entry.t)); + Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) _ + (mf : 'opt_mutable) _ (_loc : Gram.Loc.t) -> + (Ast.CrVvr (_loc, l, mf, t) : + 'class_str_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_val : 'value_val Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_mutable : 'opt_mutable Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (cvalue_binding : + 'cvalue_binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'cvalue_binding) (lab : 'label) + (mf : 'opt_mutable) _ (_loc : Gram.Loc.t) -> + (Ast.CrVal (_loc, lab, mf, e) : + 'class_str_item)))); + ([ Gram.Skeyword "inherit"; + Gram.Snterm + (Gram.Entry.obj + (class_expr : 'class_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_as_lident : + 'opt_as_lident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (pb : 'opt_as_lident) (ce : 'class_expr) _ + (_loc : Gram.Loc.t) -> + (Ast.CrInh (_loc, ce, pb) : 'class_str_item)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_str_item_tag : + 'class_str_item) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "cst" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"cst\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "cst" | "anti" | "list" as n)), + s) -> + (Ast.CrAnt (_loc, + mk_anti ~c: "class_str_item" n s) : + 'class_str_item) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (opt_as_lident : 'opt_as_lident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + ("" : 'opt_as_lident)))); + ([ Gram.Skeyword "as"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) _ (_loc : Gram.Loc.t) -> + (i : 'opt_as_lident)))) ]) ])) + ()); + Gram.extend (opt_polyt : 'opt_polyt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.TyNil _loc : 'opt_polyt)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (_loc : Gram.Loc.t) -> + (t : 'opt_polyt)))) ]) ])) + ()); + Gram.extend (cvalue_binding : 'cvalue_binding Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword ":>"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.ExCoe (_loc, e, Ast.TyNil _loc, t) : + 'cvalue_binding)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ":>"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (t2 : 'ctyp) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.ExCoe (_loc, e, t, t2) : + 'cvalue_binding)))); + ([ Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.ExTyc (_loc, e, t) : 'cvalue_binding)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (e : 'cvalue_binding)))) ]) ])) + ()); + Gram.extend (label : 'label Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (i : 'label)))) ]) ])) + ()); + Gram.extend (class_type : 'class_type Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "object"; + Gram.Snterm + (Gram.Entry.obj + (opt_class_self_type : + 'opt_class_self_type Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (class_signature : + 'class_signature Gram.Entry.t)); + Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (csg : 'class_signature) + (cst : 'opt_class_self_type) _ + (_loc : Gram.Loc.t) -> + (Ast.CtSig (_loc, cst, csg) : 'class_type)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_type_longident_and_param : + 'class_type_longident_and_param Gram. + Entry.t)) ], + (Gram.Action.mk + (fun (ct : 'class_type_longident_and_param) + (_loc : Gram.Loc.t) -> (ct : 'class_type)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_type_tag : + 'class_type) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "ctyp" | "anti"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"ctyp\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "ctyp" | "anti" as n)), s) + -> + (Ast.CtAnt (_loc, + mk_anti ~c: "class_type" n s) : + 'class_type) + | _ -> assert false))) ]) ])) + ()); + Gram.extend + (class_type_longident_and_param : + 'class_type_longident_and_param Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_type_longident : + 'class_type_longident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'class_type_longident) + (_loc : Gram.Loc.t) -> + (Ast.CtCon (_loc, Ast.BFalse, i, + Ast.TyNil _loc) : + 'class_type_longident_and_param)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_type_longident : + 'class_type_longident Gram.Entry.t)); + Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (comma_ctyp : 'comma_ctyp Gram.Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (t : 'comma_ctyp) _ + (i : 'class_type_longident) + (_loc : Gram.Loc.t) -> + (Ast.CtCon (_loc, Ast.BFalse, i, t) : + 'class_type_longident_and_param)))) ]) ])) + ()); + Gram.extend (class_type_plus : 'class_type_plus Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_type : 'class_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ct : 'class_type) (_loc : Gram.Loc.t) -> + (ct : 'class_type_plus)))); + ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "]"; Gram.Skeyword "->"; Gram.Sself ], + (Gram.Action.mk + (fun (ct : 'class_type_plus) _ _ (t : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.CtFun (_loc, t, ct) : 'class_type_plus)))) ]) ])) + ()); + Gram.extend + (opt_class_self_type : 'opt_class_self_type Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.TyNil _loc : 'opt_class_self_type)))); + ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 'ctyp) _ (_loc : Gram.Loc.t) -> + (t : 'opt_class_self_type)))) ]) ])) + ()); + Gram.extend (class_signature : 'class_signature Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist0 + (Gram.srules class_signature + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_sig_item : + 'class_sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (csg : 'class_sig_item) + (_loc : Gram.Loc.t) -> + (csg : 'e__4)))) ]) ], + (Gram.Action.mk + (fun (l : 'e__4 list) (_loc : Gram.Loc.t) -> + (Ast.cgSem_of_list l : 'class_signature)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "csg" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"csg\" | \"anti\" | \"list\"), _)")); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (csg : 'class_signature) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "csg" | "anti" | "list" as n)), + s) -> + (Ast.CgSem (_loc, + Ast.CgAnt (_loc, + mk_anti ~c: "class_sig_item" n s), + csg) : + 'class_signature) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "csg" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"csg\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "csg" | "anti" | "list" as n)), + s) -> + (Ast.CgAnt (_loc, + mk_anti ~c: "class_sig_item" n s) : + 'class_signature) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (class_sig_item : 'class_sig_item Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_constraint : + 'type_constraint Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t2 : 'ctyp) _ (t1 : 'ctyp) _ + (_loc : Gram.Loc.t) -> + (Ast.CgCtr (_loc, t1, t2) : 'class_sig_item)))); + ([ Gram.Skeyword "method"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) _ + (pf : 'opt_private) _ (_loc : Gram.Loc.t) -> + (Ast.CgVir (_loc, l, pf, t) : + 'class_sig_item)))); + ([ Gram.Skeyword "method"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) + (pf : 'opt_private) _ (_loc : Gram.Loc.t) -> + (Ast.CgMth (_loc, l, pf, t) : + 'class_sig_item)))); + ([ Gram.Skeyword "method"; Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj + (opt_private : 'opt_private Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (l : 'label) + (pf : 'opt_private) _ _ (_loc : Gram.Loc.t) + -> + (Ast.CgVir (_loc, l, pf, t) : + 'class_sig_item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (value_val : 'value_val Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_mutable : 'opt_mutable Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_virtual : 'opt_virtual Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (l : 'label) + (mv : 'opt_virtual) (mf : 'opt_mutable) _ + (_loc : Gram.Loc.t) -> + (Ast.CgVal (_loc, l, mf, mv, t) : + 'class_sig_item)))); + ([ Gram.Skeyword "inherit"; + Gram.Snterm + (Gram.Entry.obj + (class_type : 'class_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (cs : 'class_type) _ (_loc : Gram.Loc.t) -> + (Ast.CgInh (_loc, cs) : 'class_sig_item)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_sig_item_tag : + 'class_sig_item) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "csg" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"csg\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "csg" | "anti" | "list" as n)), + s) -> + (Ast.CgAnt (_loc, + mk_anti ~c: "class_sig_item" n s) : + 'class_sig_item) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (type_constraint : 'type_constraint Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "constraint" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (() : 'type_constraint)))); + ([ Gram.Skeyword "type" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (() : 'type_constraint)))) ]) ])) + ()); + Gram.extend + (class_description : 'class_description Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_info_for_class_type : + 'class_info_for_class_type Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (class_type_plus : + 'class_type_plus Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ct : 'class_type_plus) _ + (ci : 'class_info_for_class_type) + (_loc : Gram.Loc.t) -> + (Ast.CtCol (_loc, ci, ct) : + 'class_description)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_type_tag : + 'class_description) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "typ" | "anti" | "list" as n)), + s) -> + (Ast.CtAnt (_loc, + mk_anti ~c: "class_type" n s) : + 'class_description) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (cd2 : 'class_description) _ + (cd1 : 'class_description) + (_loc : Gram.Loc.t) -> + (Ast.CtAnd (_loc, cd1, cd2) : + 'class_description)))) ]) ])) + ()); + Gram.extend + (class_type_declaration : + 'class_type_declaration Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Snterm + (Gram.Entry.obj + (class_info_for_class_type : + 'class_info_for_class_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (class_type : 'class_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ct : 'class_type) _ + (ci : 'class_info_for_class_type) + (_loc : Gram.Loc.t) -> + (Ast.CtEq (_loc, ci, ct) : + 'class_type_declaration)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.class_type_tag : + 'class_type_declaration) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "typ" | "anti" | "list" as n)), + s) -> + (Ast.CtAnt (_loc, + mk_anti ~c: "class_type" n s) : + 'class_type_declaration) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (cd2 : 'class_type_declaration) _ + (cd1 : 'class_type_declaration) + (_loc : Gram.Loc.t) -> + (Ast.CtAnd (_loc, cd1, cd2) : + 'class_type_declaration)))) ]) ])) + ()); + Gram.extend (field_expr_list : 'field_expr_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (field_expr : 'field_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (b1 : 'field_expr) (_loc : Gram.Loc.t) -> + (b1 : 'field_expr_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (field_expr : 'field_expr Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (b1 : 'field_expr) (_loc : Gram.Loc.t) -> + (b1 : 'field_expr_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (field_expr : 'field_expr Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (b2 : 'field_expr_list) _ + (b1 : 'field_expr) (_loc : Gram.Loc.t) -> + (Ast.RbSem (_loc, b1, b2) : 'field_expr_list)))) ]) ])) + ()); + Gram.extend (field_expr : 'field_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (label : 'label Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (l : 'label) + (_loc : Gram.Loc.t) -> + (Ast.RbEq (_loc, Ast.IdLid (_loc, l), e) : + 'field_expr)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.RbAnt (_loc, + mk_anti ~c: "rec_binding" n s) : + 'field_expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "bi" | "anti"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"bi\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "bi" | "anti" as n)), s) + -> + (Ast.RbAnt (_loc, + mk_anti ~c: "rec_binding" n s) : + 'field_expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (meth_list : 'meth_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (meth_decl : 'meth_decl Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_dot_dot : 'opt_dot_dot Gram.Entry.t)) ], + (Gram.Action.mk + (fun (v : 'opt_dot_dot) (m : 'meth_decl) + (_loc : Gram.Loc.t) -> ((m, v) : 'meth_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (meth_decl : 'meth_decl Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (opt_dot_dot : 'opt_dot_dot Gram.Entry.t)) ], + (Gram.Action.mk + (fun (v : 'opt_dot_dot) _ (m : 'meth_decl) + (_loc : Gram.Loc.t) -> ((m, v) : 'meth_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (meth_decl : 'meth_decl Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun ((ml, v) : 'meth_list) _ (m : 'meth_decl) + (_loc : Gram.Loc.t) -> + (((Ast.TySem (_loc, m, ml)), v) : 'meth_list)))) ]) ])) + ()); + Gram.extend (meth_decl : 'meth_decl Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (poly_type : 'poly_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'poly_type) _ (lab : 'a_LIDENT) + (_loc : Gram.Loc.t) -> + (Ast.TyCol (_loc, + Ast.TyId (_loc, Ast.IdLid (_loc, lab)), t) : + 'meth_decl)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'meth_decl) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp;" n s) : + 'meth_decl) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'meth_decl) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (opt_meth_list : 'opt_meth_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (opt_dot_dot : 'opt_dot_dot Gram.Entry.t)) ], + (Gram.Action.mk + (fun (v : 'opt_dot_dot) (_loc : Gram.Loc.t) -> + (Ast.TyObj (_loc, Ast.TyNil _loc, v) : + 'opt_meth_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (meth_list : 'meth_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((ml, v) : 'meth_list) (_loc : Gram.Loc.t) + -> (Ast.TyObj (_loc, ml, v) : 'opt_meth_list)))) ]) ])) + ()); + Gram.extend (poly_type : 'poly_type Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'poly_type)))) ]) ])) + ()); + Gram.extend (typevars : 'typevars Gram.Entry.t) + ((fun () -> + (None, + [ (None, (Some Camlp4.Sig.Grammar.LeftA), + [ ([ Gram.Skeyword "'"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyQuo (_loc, i) : 'typevars)))); + ([ Gram.Stoken + (((function | QUOTATION _ -> true | _ -> false), + "QUOTATION _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | QUOTATION x -> + (Quotation.expand _loc x Quotation. + DynAst.ctyp_tag : + 'typevars) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'typevars) + | _ -> assert false))); + ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'typevars) (t1 : 'typevars) + (_loc : Gram.Loc.t) -> + (Ast.TyApp (_loc, t1, t2) : 'typevars)))) ]) ])) + ()); + Gram.extend (row_field : 'row_field Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'row_field)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)); + Gram.Skeyword "of"; + Gram.Snterm + (Gram.Entry.obj + (amp_ctyp : 'amp_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'amp_ctyp) _ (i : 'a_ident) _ + (_loc : Gram.Loc.t) -> + (Ast.TyOf (_loc, Ast.TyVrn (_loc, i), t) : + 'row_field)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)); + Gram.Skeyword "of"; Gram.Skeyword "&"; + Gram.Snterm + (Gram.Entry.obj + (amp_ctyp : 'amp_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'amp_ctyp) _ _ (i : 'a_ident) _ + (_loc : Gram.Loc.t) -> + (Ast.TyOfAmp (_loc, Ast.TyVrn (_loc, i), t) : + 'row_field)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyVrn (_loc, i) : 'row_field)))); + ([ Gram.Sself; Gram.Skeyword "|"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'row_field) _ (t1 : 'row_field) + (_loc : Gram.Loc.t) -> + (Ast.TyOr (_loc, t1, t2) : 'row_field)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp|" n s) : + 'row_field) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'row_field) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (amp_ctyp : 'amp_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) (_loc : Gram.Loc.t) -> + (t : 'amp_ctyp)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("list", _) -> true + | _ -> false), + "ANTIQUOT (\"list\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("list" as n)), s) -> + (Ast.TyAnt (_loc, + mk_anti ~c: "ctyp&" n s) : + 'amp_ctyp) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "&"; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'amp_ctyp) _ (t1 : 'amp_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyAmp (_loc, t1, t2) : 'amp_ctyp)))) ]) ])) + ()); + Gram.extend (name_tags : 'name_tags Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyVrn (_loc, i) : 'name_tags)))); + ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (t2 : 'name_tags) (t1 : 'name_tags) + (_loc : Gram.Loc.t) -> + (Ast.TyApp (_loc, t1, t2) : 'name_tags)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "typ"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"typ\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "typ" as n)), s) -> + (Ast.TyAnt (_loc, mk_anti ~c: "ctyp" n s) : + 'name_tags) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (eq_expr : 'eq_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (fun i p -> Ast.PaOlb (_loc, i, p) : + 'eq_expr)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (fun i p -> Ast.PaOlbi (_loc, i, p, e) : + 'eq_expr)))) ]) ])) + ()); + Gram.extend (patt_tcon : 'patt_tcon Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (p : 'patt_tcon)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (p : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaTyc (_loc, p, t) : 'patt_tcon)))) ]) ])) + ()); + Gram.extend (ipatt : 'ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "?"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (ipatt_tcon : 'ipatt_tcon Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (e : 'expr) _ (p : 'ipatt_tcon) _ _ + (_loc : Gram.Loc.t) -> + (Ast.PaOlbi (_loc, "", p, e) : 'ipatt)))); + ([ Gram.Skeyword "?"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (ipatt_tcon : 'ipatt_tcon Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'ipatt_tcon) _ _ (_loc : Gram.Loc.t) + -> (Ast.PaOlb (_loc, "", p) : 'ipatt)))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaOlb (_loc, mk_anti n i, + Ast.PaNil _loc) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function | LIDENT _ -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT i -> + (Ast.PaOlb (_loc, i, Ast.PaNil _loc) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")); + Gram.Skeyword ":"; Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (ipatt_tcon : 'ipatt_tcon Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (eq_expr : 'eq_expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (f : 'eq_expr) (p : 'ipatt_tcon) _ _ + (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (f (mk_anti n i) p : 'ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function | OPTLABEL _ -> true | _ -> false), + "OPTLABEL _")); + Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj + (ipatt_tcon : 'ipatt_tcon Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (eq_expr : 'eq_expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (f : 'eq_expr) (p : 'ipatt_tcon) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | OPTLABEL i -> (f i p : 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function | LIDENT _ -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT i -> + (Ast.PaLab (_loc, i, Ast.PaNil _loc) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaLab (_loc, mk_anti n i, + Ast.PaNil _loc) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")); + Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (p : 'ipatt) _ (__camlp4_0 : Gram.Token.t) + _ (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), i) -> + (Ast.PaLab (_loc, mk_anti n i, p) : + 'ipatt) + | _ -> assert false))); + ([ Gram.Stoken + (((function | LABEL _ -> true | _ -> false), + "LABEL _")); + Gram.Sself ], + (Gram.Action.mk + (fun (p : 'ipatt) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LABEL i -> + (Ast.PaLab (_loc, i, p) : 'ipatt) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (ipatt_tcon : 'ipatt_tcon Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'ipatt) (_loc : Gram.Loc.t) -> + (p : 'ipatt_tcon)))); + ([ Gram.Snterm + (Gram.Entry.obj (ipatt : 'ipatt Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj (ctyp : 'ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'ctyp) _ (p : 'ipatt) + (_loc : Gram.Loc.t) -> + (Ast.PaTyc (_loc, p, t) : 'ipatt_tcon)))) ]) ])) + ()); + Gram.extend (direction_flag : 'direction_flag Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | ANTIQUOT ("to", _) -> true + | _ -> false), + "ANTIQUOT (\"to\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("to" as n)), s) -> + (Ast.BAnt (mk_anti n s) : + 'direction_flag) + | _ -> assert false))); + ([ Gram.Skeyword "downto" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'direction_flag)))); + ([ Gram.Skeyword "to" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'direction_flag)))) ]) ])) + ()); + Gram.extend (opt_private : 'opt_private Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'opt_private)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("private", _) -> true + | _ -> false), + "ANTIQUOT (\"private\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("private" as n)), s) -> + (Ast.BAnt (mk_anti n s) : 'opt_private) + | _ -> assert false))); + ([ Gram.Skeyword "private" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'opt_private)))) ]) ])) + ()); + Gram.extend (opt_mutable : 'opt_mutable Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'opt_mutable)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("mutable", _) -> true + | _ -> false), + "ANTIQUOT (\"mutable\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("mutable" as n)), s) -> + (Ast.BAnt (mk_anti n s) : 'opt_mutable) + | _ -> assert false))); + ([ Gram.Skeyword "mutable" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'opt_mutable)))) ]) ])) + ()); + Gram.extend (opt_virtual : 'opt_virtual Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'opt_virtual)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("virtual", _) -> true + | _ -> false), + "ANTIQUOT (\"virtual\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("virtual" as n)), s) -> + (Ast.BAnt (mk_anti n s) : 'opt_virtual) + | _ -> assert false))); + ([ Gram.Skeyword "virtual" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'opt_virtual)))) ]) ])) + ()); + Gram.extend (opt_dot_dot : 'opt_dot_dot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'opt_dot_dot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("..", _) -> true + | _ -> false), + "ANTIQUOT (\"..\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT (((".." as n)), s) -> + (Ast.BAnt (mk_anti n s) : 'opt_dot_dot) + | _ -> assert false))); + ([ Gram.Skeyword ".." ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'opt_dot_dot)))) ]) ])) + ()); + Gram.extend (opt_rec : 'opt_rec Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BFalse : 'opt_rec)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("rec", _) -> true + | _ -> false), + "ANTIQUOT (\"rec\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("rec" as n)), s) -> + (Ast.BAnt (mk_anti n s) : 'opt_rec) + | _ -> assert false))); + ([ Gram.Skeyword "rec" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.BTrue : 'opt_rec)))) ]) ])) + ()); + Gram.extend (opt_expr : 'opt_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.ExNil _loc : 'opt_expr)))); + ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (e : 'opt_expr)))) ]) ])) + ()); + Gram.extend (interf : 'interf Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (([], None) : 'interf) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : 'sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun ((sil, stopped) : 'interf) _ + (si : 'sig_item) (_loc : Gram.Loc.t) -> + (((si :: sil), stopped) : 'interf)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (([ Ast.SgDir (_loc, n, dp) ], + (stopped_at _loc)) : 'interf)))) ]) ])) + ()); + Gram.extend (sig_items : 'sig_items Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist0 + (Gram.srules sig_items + [ ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : + 'sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (sg : 'sig_item) + (_loc : Gram.Loc.t) -> (sg : 'e__5)))) ]) ], + (Gram.Action.mk + (fun (l : 'e__5 list) (_loc : Gram.Loc.t) -> + (Ast.sgSem_of_list l : 'sig_items)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "sigi" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"sigi\" | \"anti\" | \"list\"), _)")); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (sg : 'sig_items) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "sigi" | "anti" | "list" as n)), + s) -> + (Ast.SgSem (_loc, + Ast.SgAnt (_loc, + mk_anti n ~c: "sig_item" s), + sg) : + 'sig_items) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "sigi" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"sigi\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "sigi" | "anti" | "list" as n)), + s) -> + (Ast.SgAnt (_loc, + mk_anti n ~c: "sig_item" s) : + 'sig_items) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (implem : 'implem Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (([], None) : 'implem) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj + (str_item : 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun ((sil, stopped) : 'implem) _ + (si : 'str_item) (_loc : Gram.Loc.t) -> + (((si :: sil), stopped) : 'implem)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (([ Ast.StDir (_loc, n, dp) ], + (stopped_at _loc)) : 'implem)))) ]) ])) + ()); + Gram.extend (str_items : 'str_items Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist0 + (Gram.srules str_items + [ ([ Gram.Snterm + (Gram.Entry.obj + (str_item : + 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (st : 'str_item) + (_loc : Gram.Loc.t) -> (st : 'e__6)))) ]) ], + (Gram.Action.mk + (fun (l : 'e__6 list) (_loc : Gram.Loc.t) -> + (Ast.stSem_of_list l : 'str_items)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "stri" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"stri\" | \"anti\" | \"list\"), _)")); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (st : 'str_items) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "stri" | "anti" | "list" as n)), + s) -> + (Ast.StSem (_loc, + Ast.StAnt (_loc, + mk_anti n ~c: "str_item" s), + st) : + 'str_items) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "stri" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"stri\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "stri" | "anti" | "list" as n)), + s) -> + (Ast.StAnt (_loc, + mk_anti n ~c: "str_item" s) : + 'str_items) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (top_phrase : 'top_phrase Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (None : 'top_phrase) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj (phrase : 'phrase Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ph : 'phrase) (_loc : Gram.Loc.t) -> + (Some ph : 'top_phrase)))) ]) ])) + ()); + Gram.extend (use_file : 'use_file Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (([], None) : 'use_file) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj + (str_item : 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun ((sil, stopped) : 'use_file) _ + (si : 'str_item) (_loc : Gram.Loc.t) -> + (((si :: sil), stopped) : 'use_file)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (([ Ast.StDir (_loc, n, dp) ], + (stopped_at _loc)) : 'use_file)))) ]) ])) + ()); + Gram.extend (phrase : 'phrase Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (str_item : 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (st : 'str_item) (_loc : Gram.Loc.t) -> + (st : 'phrase)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.StDir (_loc, n, dp) : 'phrase)))) ]) ])) + ()); + Gram.extend (a_INT : 'a_INT Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | INT (_, _) -> true | _ -> false), + "INT (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | INT (_, s) -> (s : 'a_INT) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "int" | "`int"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"int\" | \"`int\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "int" | "`int" as n)), s) + -> (mk_anti n s : 'a_INT) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_INT32 : 'a_INT32 Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | INT32 (_, _) -> true | _ -> false), + "INT32 (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | INT32 (_, s) -> (s : 'a_INT32) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "int32" | "`int32"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"int32\" | \"`int32\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "int32" | "`int32" as n)), + s) -> (mk_anti n s : 'a_INT32) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_INT64 : 'a_INT64 Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | INT64 (_, _) -> true | _ -> false), + "INT64 (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | INT64 (_, s) -> (s : 'a_INT64) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "int64" | "`int64"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"int64\" | \"`int64\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "int64" | "`int64" as n)), + s) -> (mk_anti n s : 'a_INT64) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | NATIVEINT (_, _) -> true + | _ -> false), + "NATIVEINT (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | NATIVEINT (_, s) -> (s : 'a_NATIVEINT) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT + (("" | "nativeint" | "`nativeint"), _) + -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"nativeint\" | \"`nativeint\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "nativeint" | "`nativeint" as n)), + s) -> (mk_anti n s : 'a_NATIVEINT) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_FLOAT : 'a_FLOAT Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | FLOAT (_, _) -> true | _ -> false), + "FLOAT (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | FLOAT (_, s) -> (s : 'a_FLOAT) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "flo" | "`flo"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"flo\" | \"`flo\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "flo" | "`flo" as n)), s) + -> (mk_anti n s : 'a_FLOAT) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_CHAR : 'a_CHAR Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | CHAR (_, _) -> true | _ -> false), + "CHAR (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | CHAR (_, s) -> (s : 'a_CHAR) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "chr" | "`chr"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"chr\" | \"`chr\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "chr" | "`chr" as n)), s) + -> (mk_anti n s : 'a_CHAR) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_UIDENT : 'a_UIDENT Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | UIDENT _ -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT s -> (s : 'a_UIDENT) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "uid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"uid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "uid" as n)), s) -> + (mk_anti n s : 'a_UIDENT) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_LIDENT : 'a_LIDENT Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | LIDENT _ -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT s -> (s : 'a_LIDENT) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "lid"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"lid\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "lid" as n)), s) -> + (mk_anti n s : 'a_LIDENT) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_LABEL : 'a_LABEL Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | LABEL _ -> true | _ -> false), + "LABEL _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LABEL s -> (s : 'a_LABEL) + | _ -> assert false))); + ([ Gram.Skeyword "~"; + Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")); + Gram.Skeyword ":" ], + (Gram.Action.mk + (fun _ (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), s) -> + (mk_anti n s : 'a_LABEL) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_OPTLABEL : 'a_OPTLABEL Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | OPTLABEL _ -> true | _ -> false), + "OPTLABEL _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | OPTLABEL s -> (s : 'a_OPTLABEL) + | _ -> assert false))); + ([ Gram.Skeyword "?"; + Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")); + Gram.Skeyword ":" ], + (Gram.Action.mk + (fun _ (__camlp4_0 : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), s) -> + (mk_anti n s : 'a_OPTLABEL) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (a_STRING : 'a_STRING Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | STRING (_, _) -> true + | _ -> false), + "STRING (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | STRING (_, s) -> (s : 'a_STRING) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "str" | "`str"), _) -> + true + | _ -> false), + "ANTIQUOT ((\"\" | \"str\" | \"`str\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" | "str" | "`str" as n)), s) + -> (mk_anti n s : 'a_STRING) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (string_list : 'string_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | STRING (_, _) -> true + | _ -> false), + "STRING (_, _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | STRING (_, x) -> + (Ast.LCons (x, Ast.LNil) : 'string_list) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | STRING (_, _) -> true + | _ -> false), + "STRING (_, _)")); + Gram.Sself ], + (Gram.Action.mk + (fun (xs : 'string_list) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | STRING (_, x) -> + (Ast.LCons (x, xs) : 'string_list) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "str_list"), _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"str_list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT (("" | "str_list"), s) -> + (Ast.LAnt (mk_anti "str_list" s) : + 'string_list) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (value_let : 'value_let Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "value" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'value_let)))) ]) ])) + ()); + Gram.extend (value_val : 'value_val Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "value" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'value_val)))) ]) ])) + ()); + Gram.extend (semi : 'semi Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'semi)))) ]) ])) + ()); + Gram.extend (expr_quot : 'expr_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.ExNil _loc : 'expr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (e : 'expr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sem_expr : 'sem_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e2 : 'sem_expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExSem (_loc, e1, e2) : 'expr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_expr : 'comma_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e2 : 'comma_expr) _ (e1 : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExCom (_loc, e1, e2) : 'expr_quot)))) ]) ])) + ()); + Gram.extend (patt_quot : 'patt_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.PaNil _loc : 'patt_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'patt) (_loc : Gram.Loc.t) -> + (x : 'patt_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'patt) _ (x : 'patt) + (_loc : Gram.Loc.t) -> + (let i = + match x with + | Ast.PaAnt (loc, s) -> Ast.IdAnt (loc, s) + | p -> Ast.ident_of_patt p + in Ast.PaEq (_loc, i, y) : 'patt_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sem_patt : 'sem_patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'sem_patt) _ (x : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaSem (_loc, x, y) : 'patt_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_patt : 'comma_patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'comma_patt) _ (x : 'patt) + (_loc : Gram.Loc.t) -> + (Ast.PaCom (_loc, x, y) : 'patt_quot)))) ]) ])) + ()); + Gram.extend (ctyp_quot : 'ctyp_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.TyNil _loc : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (x : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "and"; + Gram.Snterm + (Gram.Entry.obj + (constructor_arg_list : + 'constructor_arg_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'constructor_arg_list) _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TyAnd (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "&"; + Gram.Snterm + (Gram.Entry.obj + (amp_ctyp : 'amp_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'amp_ctyp) _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyAmp (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "*"; + Gram.Snterm + (Gram.Entry.obj + (star_ctyp : 'star_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'star_ctyp) _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TySta (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (label_declaration_list : + 'label_declaration_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (z : 'label_declaration_list) _ + (y : 'more_ctyp) _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TySem (_loc, Ast.TyCol (_loc, x, y), z) : + 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'more_ctyp) _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyCol (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "of"; Gram.Skeyword "&"; + Gram.Snterm + (Gram.Entry.obj + (amp_ctyp : 'amp_ctyp Gram.Entry.t)); + Gram.Skeyword "|"; + Gram.Snterm + (Gram.Entry.obj + (row_field : 'row_field Gram.Entry.t)) ], + (Gram.Action.mk + (fun (z : 'row_field) _ (y : 'amp_ctyp) _ _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TyOr (_loc, Ast.TyOfAmp (_loc, x, y), z) : + 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "of"; Gram.Skeyword "&"; + Gram.Snterm + (Gram.Entry.obj + (amp_ctyp : 'amp_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'amp_ctyp) _ _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyOfAmp (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "of"; + Gram.Snterm + (Gram.Entry.obj + (constructor_arg_list : + 'constructor_arg_list Gram.Entry.t)); + Gram.Skeyword "|"; + Gram.Snterm + (Gram.Entry.obj + (constructor_declarations : + 'constructor_declarations Gram.Entry.t)) ], + (Gram.Action.mk + (fun (z : 'constructor_declarations) _ + (y : 'constructor_arg_list) _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TyOr (_loc, Ast.TyOf (_loc, x, y), z) : + 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "of"; + Gram.Snterm + (Gram.Entry.obj + (constructor_arg_list : + 'constructor_arg_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'constructor_arg_list) _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TyOf (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword "|"; + Gram.Snterm + (Gram.Entry.obj + (constructor_declarations : + 'constructor_declarations Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'constructor_declarations) _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TyOr (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (label_declaration_list : + 'label_declaration_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'label_declaration_list) _ + (x : 'more_ctyp) (_loc : Gram.Loc.t) -> + (Ast.TySem (_loc, x, y) : 'ctyp_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (more_ctyp : 'more_ctyp Gram.Entry.t)); + Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_ctyp : 'comma_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (y : 'comma_ctyp) _ (x : 'more_ctyp) + (_loc : Gram.Loc.t) -> + (Ast.TyCom (_loc, x, y) : 'ctyp_quot)))) ]) ])) + ()); + Gram.extend (more_ctyp : 'more_ctyp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (type_parameter : + 'type_parameter Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'type_parameter) (_loc : Gram.Loc.t) + -> (x : 'more_ctyp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (type_kind : 'type_kind Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'type_kind) (_loc : Gram.Loc.t) -> + (x : 'more_ctyp)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj + (a_ident : 'a_ident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'a_ident) _ (_loc : Gram.Loc.t) -> + (Ast.TyVrn (_loc, x) : 'more_ctyp)))); + ([ Gram.Skeyword "mutable"; Gram.Sself ], + (Gram.Action.mk + (fun (x : 'more_ctyp) _ (_loc : Gram.Loc.t) -> + (Ast.TyMut (_loc, x) : 'more_ctyp)))) ]) ])) + ()); + Gram.extend (str_item_quot : 'str_item_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.StNil _loc : 'str_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (str_item : 'str_item Gram.Entry.t)) ], + (Gram.Action.mk + (fun (st : 'str_item) (_loc : Gram.Loc.t) -> + (st : 'str_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (str_item : 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (st2 : 'str_item_quot) _ (st1 : 'str_item) + (_loc : Gram.Loc.t) -> + (Ast.StSem (_loc, st1, st2) : 'str_item_quot)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.StDir (_loc, n, dp) : 'str_item_quot)))) ]) ])) + ()); + Gram.extend (sig_item_quot : 'sig_item_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.SgNil _loc : 'sig_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : 'sig_item Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sg : 'sig_item) (_loc : Gram.Loc.t) -> + (sg : 'sig_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : 'sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (sg2 : 'sig_item_quot) _ (sg1 : 'sig_item) + (_loc : Gram.Loc.t) -> + (Ast.SgSem (_loc, sg1, sg2) : 'sig_item_quot)))); + ([ Gram.Skeyword "#"; + Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_expr : 'opt_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (dp : 'opt_expr) (n : 'a_LIDENT) _ + (_loc : Gram.Loc.t) -> + (Ast.SgDir (_loc, n, dp) : 'sig_item_quot)))) ]) ])) + ()); + Gram.extend (module_type_quot : 'module_type_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.MtNil _loc : 'module_type_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'module_type) (_loc : Gram.Loc.t) -> + (x : 'module_type_quot)))) ]) ])) + ()); + Gram.extend (module_expr_quot : 'module_expr_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.MeNil _loc : 'module_expr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'module_expr) (_loc : Gram.Loc.t) -> + (x : 'module_expr_quot)))) ]) ])) + ()); + Gram.extend (match_case_quot : 'match_case_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.McNil _loc : 'match_case_quot)))); + ([ Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (match_case0 : 'match_case0 Gram.Entry.t)), + Gram.Skeyword "|") ], + (Gram.Action.mk + (fun (x : 'match_case0 list) (_loc : Gram.Loc.t) + -> (Ast.mcOr_of_list x : 'match_case_quot)))) ]) ])) + ()); + Gram.extend (binding_quot : 'binding_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.BiNil _loc : 'binding_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (binding : 'binding Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'binding) (_loc : Gram.Loc.t) -> + (x : 'binding_quot)))) ]) ])) + ()); + Gram.extend (rec_binding_quot : 'rec_binding_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.RbNil _loc : 'rec_binding_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (label_expr_list : + 'label_expr_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'label_expr_list) (_loc : Gram.Loc.t) + -> (x : 'rec_binding_quot)))) ]) ])) + ()); + Gram.extend + (module_binding_quot : 'module_binding_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.MbNil _loc : 'module_binding_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (mt : 'module_type) _ + (m : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.MbColEq (_loc, m, mt, me) : + 'module_binding_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ (m : 'a_UIDENT) + (_loc : Gram.Loc.t) -> + (Ast.MbCol (_loc, m, mt) : + 'module_binding_quot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (module_expr : 'module_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (me : 'module_expr) _ (mt : 'module_type) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), m) -> + (Ast.MbColEq (_loc, mk_anti n m, mt, me) : + 'module_binding_quot) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (module_type : 'module_type Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mt : 'module_type) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), m) -> + (Ast.MbCol (_loc, mk_anti n m, mt) : + 'module_binding_quot) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("" as n)), s) -> + (Ast.MbAnt (_loc, + mk_anti ~c: "module_binding" n s) : + 'module_binding_quot) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("module_binding" | "anti"), _) + -> true + | _ -> false), + "ANTIQUOT ((\"module_binding\" | \"anti\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("module_binding" | "anti" as n)), s) + -> + (Ast.MbAnt (_loc, + mk_anti ~c: "module_binding" n s) : + 'module_binding_quot) + | _ -> assert false))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (b2 : 'module_binding_quot) _ + (b1 : 'module_binding_quot) + (_loc : Gram.Loc.t) -> + (Ast.MbAnd (_loc, b1, b2) : + 'module_binding_quot)))) ]) ])) + ()); + Gram.extend (ident_quot : 'ident_quot Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "apply"), None, + [ ([ Gram.Sself; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'ident_quot) (i : 'ident_quot) + (_loc : Gram.Loc.t) -> + (Ast.IdApp (_loc, i, j) : 'ident_quot)))) ]); + ((Some "."), None, + [ ([ Gram.Sself; Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (j : 'ident_quot) _ (i : 'ident_quot) + (_loc : Gram.Loc.t) -> + (Ast.IdAcc (_loc, i, j) : 'ident_quot)))) ]); + ((Some "simple"), None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (i : 'ident_quot) _ (_loc : Gram.Loc.t) + -> (i : 'ident_quot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (i : 'ident_quot) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAcc (_loc, + Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s), + i) : + 'ident_quot) + | _ -> assert false))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdLid (_loc, i) : 'ident_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_UIDENT : 'a_UIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_UIDENT) (_loc : Gram.Loc.t) -> + (Ast.IdUid (_loc, i) : 'ident_quot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT (("" | "id" | "anti" | "list"), + _) -> true + | _ -> false), + "ANTIQUOT ((\"\" | \"id\" | \"anti\" | \"list\"), _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT + ((("" | "id" | "anti" | "list" as n)), s) + -> + (Ast.IdAnt (_loc, + mk_anti ~c: "ident" n s) : + 'ident_quot) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (class_expr_quot : 'class_expr_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.CeNil _loc : 'class_expr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_expr : 'class_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'class_expr) (_loc : Gram.Loc.t) -> + (x : 'class_expr_quot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("virtual", _) -> true + | _ -> false), + "ANTIQUOT (\"virtual\", _)")); + Gram.Snterm + (Gram.Entry.obj (ident : 'ident Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_comma_ctyp : + 'opt_comma_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ot : 'opt_comma_ctyp) (i : 'ident) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("virtual" as n)), s) -> + (let anti = + Ast.BAnt + (mk_anti ~c: "class_expr" n s) + in Ast.CeCon (_loc, anti, i, ot) : + 'class_expr_quot) + | _ -> assert false))); + ([ Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj + (class_name_and_param : + 'class_name_and_param Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((i, ot) : 'class_name_and_param) _ + (_loc : Gram.Loc.t) -> + (Ast.CeCon (_loc, Ast.BTrue, + Ast.IdLid (_loc, i), ot) : + 'class_expr_quot)))); + ([ Gram.Sself; Gram.Skeyword "="; Gram.Sself ], + (Gram.Action.mk + (fun (ce2 : 'class_expr_quot) _ + (ce1 : 'class_expr_quot) (_loc : Gram.Loc.t) + -> + (Ast.CeEq (_loc, ce1, ce2) : + 'class_expr_quot)))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (ce2 : 'class_expr_quot) _ + (ce1 : 'class_expr_quot) (_loc : Gram.Loc.t) + -> + (Ast.CeAnd (_loc, ce1, ce2) : + 'class_expr_quot)))) ]) ])) + ()); + Gram.extend (class_type_quot : 'class_type_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.CtNil _loc : 'class_type_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_type_plus : + 'class_type_plus Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'class_type_plus) (_loc : Gram.Loc.t) + -> (x : 'class_type_quot)))); + ([ Gram.Stoken + (((function + | ANTIQUOT ("virtual", _) -> true + | _ -> false), + "ANTIQUOT (\"virtual\", _)")); + Gram.Snterm + (Gram.Entry.obj (ident : 'ident Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_comma_ctyp : + 'opt_comma_ctyp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ot : 'opt_comma_ctyp) (i : 'ident) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ((("virtual" as n)), s) -> + (let anti = + Ast.BAnt + (mk_anti ~c: "class_type" n s) + in Ast.CtCon (_loc, anti, i, ot) : + 'class_type_quot) + | _ -> assert false))); + ([ Gram.Skeyword "virtual"; + Gram.Snterm + (Gram.Entry.obj + (class_name_and_param : + 'class_name_and_param Gram.Entry.t)) ], + (Gram.Action.mk + (fun ((i, ot) : 'class_name_and_param) _ + (_loc : Gram.Loc.t) -> + (Ast.CtCon (_loc, Ast.BTrue, + Ast.IdLid (_loc, i), ot) : + 'class_type_quot)))); + ([ Gram.Sself; Gram.Skeyword ":"; Gram.Sself ], + (Gram.Action.mk + (fun (ct2 : 'class_type_quot) _ + (ct1 : 'class_type_quot) (_loc : Gram.Loc.t) + -> + (Ast.CtCol (_loc, ct1, ct2) : + 'class_type_quot)))); + ([ Gram.Sself; Gram.Skeyword "="; Gram.Sself ], + (Gram.Action.mk + (fun (ct2 : 'class_type_quot) _ + (ct1 : 'class_type_quot) (_loc : Gram.Loc.t) + -> + (Ast.CtEq (_loc, ct1, ct2) : + 'class_type_quot)))); + ([ Gram.Sself; Gram.Skeyword "and"; Gram.Sself ], + (Gram.Action.mk + (fun (ct2 : 'class_type_quot) _ + (ct1 : 'class_type_quot) (_loc : Gram.Loc.t) + -> + (Ast.CtAnd (_loc, ct1, ct2) : + 'class_type_quot)))) ]) ])) + ()); + Gram.extend + (class_str_item_quot : 'class_str_item_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.CrNil _loc : 'class_str_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_str_item : + 'class_str_item Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'class_str_item) (_loc : Gram.Loc.t) + -> (x : 'class_str_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_str_item : + 'class_str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (x2 : 'class_str_item_quot) _ + (x1 : 'class_str_item) (_loc : Gram.Loc.t) -> + (Ast.CrSem (_loc, x1, x2) : + 'class_str_item_quot)))) ]) ])) + ()); + Gram.extend + (class_sig_item_quot : 'class_sig_item_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.CgNil _loc : 'class_sig_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_sig_item : + 'class_sig_item Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'class_sig_item) (_loc : Gram.Loc.t) + -> (x : 'class_sig_item_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (class_sig_item : + 'class_sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (semi : 'semi Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (x2 : 'class_sig_item_quot) _ + (x1 : 'class_sig_item) (_loc : Gram.Loc.t) -> + (Ast.CgSem (_loc, x1, x2) : + 'class_sig_item_quot)))) ]) ])) + ()); + Gram.extend (with_constr_quot : 'with_constr_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (Ast.WcNil _loc : 'with_constr_quot)))); + ([ Gram.Snterm + (Gram.Entry.obj + (with_constr : 'with_constr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'with_constr) (_loc : Gram.Loc.t) -> + (x : 'with_constr_quot)))) ]) ])) + ()); + Gram.extend (patt_eoi : 'patt_eoi Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) (x : 'patt) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (x : 'patt_eoi) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (expr_eoi : 'expr_eoi Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) (x : 'expr) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (x : 'expr_eoi) + | _ -> assert false))) ]) ])) + ())) + + end + + let _ = let module M = Register.OCamlSyntaxExtension(Id)(Make) in () + + end + +module Camlp4QuotationCommon = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2002-2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Nicolas Pouillard: initial version + *) + module Id = + struct let name = "Camlp4QuotationCommon" + let version = Sys.ocaml_version + end + + module Make + (Syntax : Sig.Camlp4Syntax) + (TheAntiquotSyntax : Sig.Parser(Syntax.Ast).SIMPLE) = + struct + open Sig + + include Syntax + + (* Be careful an AntiquotSyntax module appears here *) + module MetaLocHere = Ast.Meta.MetaLoc + + module MetaLoc = + struct + module Ast = Ast + + let loc_name = ref None + + let meta_loc_expr _loc loc = + match !loc_name with + | None -> Ast.ExId (_loc, Ast.IdLid (_loc, !Loc.name)) + | Some "here" -> MetaLocHere.meta_loc_expr _loc loc + | Some x -> Ast.ExId (_loc, Ast.IdLid (_loc, x)) + + let meta_loc_patt _loc _ = Ast.PaAny _loc + + end + + module MetaAst = Ast.Meta.Make(MetaLoc) + + module ME = MetaAst.Expr + + module MP = MetaAst.Patt + + let is_antiquot s = + let len = String.length s + in (len > 2) && ((s.[0] = '\\') && (s.[1] = '$')) + + let handle_antiquot_in_string s term parse loc decorate = + if is_antiquot s + then + (let pos = String.index s ':' in + let name = String.sub s 2 (pos - 2) + and code = + String.sub s (pos + 1) (((String.length s) - pos) - 1) + in decorate name (parse loc code)) + else term + + let antiquot_expander = + object + inherit Ast.map as super + + method patt = + function + | (Ast.PaAnt (_loc, s) | Ast.PaStr (_loc, s) as p) -> + let mloc _loc = MetaLoc.meta_loc_patt _loc _loc + in + handle_antiquot_in_string s p TheAntiquotSyntax. + parse_patt _loc + (fun n p -> + match n with + | "antisig_item" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgAnt"))), + mloc _loc), + p) + | "antistr_item" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StAnt"))), + mloc _loc), + p) + | "antictyp" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAnt"))), + mloc _loc), + p) + | "antipatt" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAnt"))), + mloc _loc), + p) + | "antiexpr" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAnt"))), + mloc _loc), + p) + | "antimodule_type" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtAnt"))), + mloc _loc), + p) + | "antimodule_expr" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeAnt"))), + mloc _loc), + p) + | "anticlass_type" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtAnt"))), + mloc _loc), + p) + | "anticlass_expr" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeAnt"))), + mloc _loc), + p) + | "anticlass_sig_item" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgAnt"))), + mloc _loc), + p) + | "anticlass_str_item" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrAnt"))), + mloc _loc), + p) + | "antiwith_constr" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcAnt"))), + mloc _loc), + p) + | "antibinding" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiAnt"))), + mloc _loc), + p) + | "antirec_binding" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbAnt"))), + mloc _loc), + p) + | "antimatch_case" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McAnt"))), + mloc _loc), + p) + | "antimodule_binding" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbAnt"))), + mloc _loc), + p) + | "antiident" -> + Ast.PaApp (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdAnt"))), + mloc _loc), + p) + | _ -> p) + | p -> super#patt p + + method expr = + function + | (Ast.ExAnt (_loc, s) | Ast.ExStr (_loc, s) as e) -> + let mloc _loc = MetaLoc.meta_loc_expr _loc _loc + in + handle_antiquot_in_string s e TheAntiquotSyntax. + parse_expr _loc + (fun n e -> + match n with + | "`int" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "string_of_int")), + e) + | "`int32" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Int32"), + Ast.IdLid (_loc, "to_string"))), + e) + | "`int64" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Int64"), + Ast.IdLid (_loc, "to_string"))), + e) + | "`nativeint" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Nativeint"), + Ast.IdLid (_loc, "to_string"))), + e) + | "`flo" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "string_of_float")), + e) + | "`str" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "safe_string_escaped"))), + e) + | "`chr" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Char"), + Ast.IdLid (_loc, "escaped"))), + e) + | "`bool" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdUid"))), + mloc _loc), + Ast.ExIfe (_loc, e, Ast.ExStr (_loc, "True"), + Ast.ExStr (_loc, "False"))) + | "liststr_item" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "stSem_of_list"))), + e) + | "listsig_item" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "sgSem_of_list"))), + e) + | "listclass_sig_item" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "cgSem_of_list"))), + e) + | "listclass_str_item" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "crSem_of_list"))), + e) + | "listmodule_expr" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "meApp_of_list"))), + e) + | "listmodule_type" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "mtApp_of_list"))), + e) + | "listmodule_binding" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "mbAnd_of_list"))), + e) + | "listbinding" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "biAnd_of_list"))), + e) + | "listbinding;" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "biSem_of_list"))), + e) + | "listrec_binding" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "rbSem_of_list"))), + e) + | "listclass_type" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "ctAnd_of_list"))), + e) + | "listclass_expr" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "ceAnd_of_list"))), + e) + | "listident" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "idAcc_of_list"))), + e) + | "listctypand" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tyAnd_of_list"))), + e) + | "listctyp;" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tySem_of_list"))), + e) + | "listctyp*" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tySta_of_list"))), + e) + | "listctyp|" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tyOr_of_list"))), + e) + | "listctyp," -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tyCom_of_list"))), + e) + | "listctyp&" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "tyAmp_of_list"))), + e) + | "listwith_constr" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "wcAnd_of_list"))), + e) + | "listmatch_case" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "mcOr_of_list"))), + e) + | "listpatt," -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "paCom_of_list"))), + e) + | "listpatt;" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "paSem_of_list"))), + e) + | "listexpr," -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "exCom_of_list"))), + e) + | "listexpr;" -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdLid (_loc, "exSem_of_list"))), + e) + | "antisig_item" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "SgAnt"))), + mloc _loc), + e) + | "antistr_item" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "StAnt"))), + mloc _loc), + e) + | "antictyp" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "TyAnt"))), + mloc _loc), + e) + | "antipatt" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "PaAnt"))), + mloc _loc), + e) + | "antiexpr" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExAnt"))), + mloc _loc), + e) + | "antimodule_type" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MtAnt"))), + mloc _loc), + e) + | "antimodule_expr" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MeAnt"))), + mloc _loc), + e) + | "anticlass_type" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CtAnt"))), + mloc _loc), + e) + | "anticlass_expr" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CeAnt"))), + mloc _loc), + e) + | "anticlass_sig_item" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CgAnt"))), + mloc _loc), + e) + | "anticlass_str_item" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "CrAnt"))), + mloc _loc), + e) + | "antiwith_constr" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "WcAnt"))), + mloc _loc), + e) + | "antibinding" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "BiAnt"))), + mloc _loc), + e) + | "antirec_binding" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "RbAnt"))), + mloc _loc), + e) + | "antimatch_case" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "McAnt"))), + mloc _loc), + e) + | "antimodule_binding" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "MbAnt"))), + mloc _loc), + e) + | "antiident" -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdAnt"))), + mloc _loc), + e) + | _ -> e) + | e -> super#expr e + + end + + let add_quotation name entry mexpr mpatt = + let entry_eoi = Gram.Entry.mk (Gram.Entry.name entry) in + let parse_quot_string entry loc s = + let q = !Camlp4_config.antiquotations in + let () = Camlp4_config.antiquotations := true in + let res = Gram.parse_string entry loc s in + let () = Camlp4_config.antiquotations := q in res in + let expand_expr loc loc_name_opt s = + let ast = parse_quot_string entry_eoi loc s in + let () = MetaLoc.loc_name := loc_name_opt in + let meta_ast = mexpr loc ast in + let exp_ast = antiquot_expander#expr meta_ast in exp_ast in + let expand_str_item loc loc_name_opt s = + let exp_ast = expand_expr loc loc_name_opt s + in Ast.StExp (loc, exp_ast) in + let expand_patt _loc loc_name_opt s = + let ast = parse_quot_string entry_eoi _loc s in + let meta_ast = mpatt _loc ast in + let exp_ast = antiquot_expander#patt meta_ast + in + match loc_name_opt with + | None -> exp_ast + | Some name -> + let rec subst_first_loc = + (function + | Ast.PaApp (_loc, + (Ast.PaId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Ast")), + (Ast.IdUid (_, u)))))), + _) -> + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, u))), + Ast.PaId (_loc, Ast.IdLid (_loc, name))) + | Ast.PaApp (_loc, a, b) -> + Ast.PaApp (_loc, subst_first_loc a, b) + | p -> p) + in subst_first_loc exp_ast + in + (Gram.extend (entry_eoi : 'entry_eoi Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (entry : 'entry Gram.Entry.t)); + Gram.Stoken + (((function | EOI -> true | _ -> false), "EOI")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) (x : 'entry) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | EOI -> (x : 'entry_eoi) + | _ -> assert false))) ]) ])) + ()); + Quotation.add name Quotation.DynAst.expr_tag expand_expr; + Quotation.add name Quotation.DynAst.patt_tag expand_patt; + Quotation.add name Quotation.DynAst.str_item_tag expand_str_item) + + let _ = + add_quotation "sig_item" sig_item_quot ME.meta_sig_item MP. + meta_sig_item + + let _ = + add_quotation "str_item" str_item_quot ME.meta_str_item MP. + meta_str_item + + let _ = add_quotation "ctyp" ctyp_quot ME.meta_ctyp MP.meta_ctyp + + let _ = add_quotation "patt" patt_quot ME.meta_patt MP.meta_patt + + let _ = add_quotation "expr" expr_quot ME.meta_expr MP.meta_expr + + let _ = + add_quotation "module_type" module_type_quot ME.meta_module_type + MP.meta_module_type + + let _ = + add_quotation "module_expr" module_expr_quot ME.meta_module_expr + MP.meta_module_expr + + let _ = + add_quotation "class_type" class_type_quot ME.meta_class_type MP. + meta_class_type + + let _ = + add_quotation "class_expr" class_expr_quot ME.meta_class_expr MP. + meta_class_expr + + let _ = + add_quotation "class_sig_item" class_sig_item_quot ME. + meta_class_sig_item MP.meta_class_sig_item + + let _ = + add_quotation "class_str_item" class_str_item_quot ME. + meta_class_str_item MP.meta_class_str_item + + let _ = + add_quotation "with_constr" with_constr_quot ME.meta_with_constr + MP.meta_with_constr + + let _ = + add_quotation "binding" binding_quot ME.meta_binding MP. + meta_binding + + let _ = + add_quotation "rec_binding" rec_binding_quot ME.meta_rec_binding + MP.meta_rec_binding + + let _ = + add_quotation "match_case" match_case_quot ME.meta_match_case MP. + meta_match_case + + let _ = + add_quotation "module_binding" module_binding_quot ME. + meta_module_binding MP.meta_module_binding + + let _ = add_quotation "ident" ident_quot ME.meta_ident MP.meta_ident + + end + + end + +module Q = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2002-2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + module Id = + struct let name = "Camlp4QuotationExpander" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + module M = Camlp4QuotationCommon.Make(Syntax)(Syntax.AntiquotSyntax) + + include M + + end + + let _ = let module M = Register.OCamlSyntaxExtension(Id)(Make) in () + + end + +module Rp = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 1998-2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + module Id : Sig.Id = + struct let name = "Camlp4OCamlRevisedParserParser" + let version = Sys.ocaml_version + + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + type spat_comp = + | SpTrm of Loc.t * Ast.patt * Ast.expr option + | SpNtr of Loc.t * Ast.patt * Ast.expr + | SpStr of Loc.t * Ast.patt + + type sexp_comp = + | SeTrm of Loc.t * Ast.expr | SeNtr of Loc.t * Ast.expr + + let stream_expr = Gram.Entry.mk "stream_expr" + + let stream_begin = Gram.Entry.mk "stream_begin" + + let stream_end = Gram.Entry.mk "stream_end" + + let stream_quot = Gram.Entry.mk "stream_quot" + + let parser_case = Gram.Entry.mk "parser_case" + + let parser_case_list = Gram.Entry.mk "parser_case_list" + + let strm_n = "__strm" + + let peek_fun _loc = + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "peek"))) + + let junk_fun _loc = + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "junk"))) + + (* Parsers. *) + (* In syntax generated, many cases are optimisations. *) + let rec pattern_eq_expression p e = + match (p, e) with + | (Ast.PaId (_, (Ast.IdLid (_, a))), + Ast.ExId (_, (Ast.IdLid (_, b)))) -> a = b + | (Ast.PaId (_, (Ast.IdUid (_, a))), + Ast.ExId (_, (Ast.IdUid (_, b)))) -> a = b + | (Ast.PaApp (_, p1, p2), Ast.ExApp (_, e1, e2)) -> + (pattern_eq_expression p1 e1) && (pattern_eq_expression p2 e2) + | _ -> false + + let is_raise e = + match e with + | Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "raise")))), _) -> + true + | _ -> false + + let is_raise_failure e = + match e with + | Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "raise")))), + (Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Stream")), + (Ast.IdUid (_, "Failure"))))))) + -> true + | _ -> false + + let rec handle_failure e = + match e with + | Ast.ExTry (_, _, + (Ast.McArr (_, + (Ast.PaId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Stream")), + (Ast.IdUid (_, "Failure")))))), + (Ast.ExNil _), e))) + -> handle_failure e + | Ast.ExMat (_, me, a) -> + let rec match_case_handle_failure = + (function + | Ast.McOr (_, a1, a2) -> + (match_case_handle_failure a1) && + (match_case_handle_failure a2) + | Ast.McArr (_, _, (Ast.ExNil _), e) -> handle_failure e + | _ -> false) + in (handle_failure me) && (match_case_handle_failure a) + | Ast.ExLet (_, Ast.BFalse, bi, e) -> + let rec binding_handle_failure = + (function + | Ast.BiAnd (_, b1, b2) -> + (binding_handle_failure b1) && + (binding_handle_failure b2) + | Ast.BiEq (_, _, e) -> handle_failure e + | _ -> false) + in (binding_handle_failure bi) && (handle_failure e) + | Ast.ExId (_, (Ast.IdLid (_, _))) | Ast.ExInt (_, _) | + Ast.ExStr (_, _) | Ast.ExChr (_, _) | Ast.ExFun (_, _) | + Ast.ExId (_, (Ast.IdUid (_, _))) -> true + | Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "raise")))), e) -> + (match e with + | Ast.ExId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Stream")), + (Ast.IdUid (_, "Failure"))))) + -> false + | _ -> true) + | Ast.ExApp (_, f, x) -> + (is_constr_apply f) && + ((handle_failure f) && (handle_failure x)) + | _ -> false + and is_constr_apply = + function + | Ast.ExId (_, (Ast.IdUid (_, _))) -> true + | Ast.ExId (_, (Ast.IdLid (_, _))) -> false + | Ast.ExApp (_, x, _) -> is_constr_apply x + | _ -> false + + let rec subst v e = + let _loc = Ast.loc_of_expr e + in + match e with + | Ast.ExId (_, (Ast.IdLid (_, x))) -> + let x = if x = v then strm_n else x + in Ast.ExId (_loc, Ast.IdLid (_loc, x)) + | Ast.ExId (_, (Ast.IdUid (_, _))) -> e + | Ast.ExInt (_, _) -> e + | Ast.ExChr (_, _) -> e + | Ast.ExStr (_, _) -> e + | Ast.ExAcc (_, _, _) -> e + | Ast.ExLet (_, rf, bi, e) -> + Ast.ExLet (_loc, rf, subst_binding v bi, subst v e) + | Ast.ExApp (_, e1, e2) -> + Ast.ExApp (_loc, subst v e1, subst v e2) + | Ast.ExTup (_, e) -> Ast.ExTup (_loc, subst v e) + | Ast.ExCom (_, e1, e2) -> + Ast.ExCom (_loc, subst v e1, subst v e2) + | _ -> raise Not_found + and subst_binding v = + function + | Ast.BiAnd (_loc, b1, b2) -> + Ast.BiAnd (_loc, subst_binding v b1, subst_binding v b2) + | Ast.BiEq (_loc, (Ast.PaId (_, (Ast.IdLid (_, v')))), e) -> + Ast.BiEq (_loc, Ast.PaId (_loc, Ast.IdLid (_loc, v')), + if v = v' then e else subst v e) + | _ -> raise Not_found + + let stream_pattern_component skont ckont = + function + | SpTrm (_loc, p, None) -> + Ast.ExMat (_loc, + Ast.ExApp (_loc, peek_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + Ast.McOr (_loc, + Ast.McArr (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "Some")), p), + Ast.ExNil _loc, + Ast.ExSeq (_loc, + Ast.ExSem (_loc, + Ast.ExApp (_loc, junk_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + skont))), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, ckont))) + | SpTrm (_loc, p, (Some w)) -> + Ast.ExMat (_loc, + Ast.ExApp (_loc, peek_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + Ast.McOr (_loc, + Ast.McArr (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "Some")), p), + w, + Ast.ExSeq (_loc, + Ast.ExSem (_loc, + Ast.ExApp (_loc, junk_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + skont))), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, ckont))) + | SpNtr (_loc, p, e) -> + let e = + (match e with + | Ast.ExFun (_, + (Ast.McArr (_, + (Ast.PaTyc (_, (Ast.PaId (_, (Ast.IdLid (_, v)))), + (Ast.TyApp (_, + (Ast.TyId (_, + (Ast.IdAcc (_, (Ast.IdUid (_, "Stream")), + (Ast.IdLid (_, "t")))))), + (Ast.TyAny _))))), + (Ast.ExNil _), e))) + when v = strm_n -> e + | _ -> + Ast.ExApp (_loc, e, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n)))) + in + if pattern_eq_expression p skont + then + if is_raise_failure ckont + then e + else + if handle_failure e + then e + else + Ast.ExTry (_loc, e, + Ast.McArr (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Failure"))), + Ast.ExNil _loc, ckont)) + else + if is_raise_failure ckont + then + Ast.ExLet (_loc, Ast.BFalse, Ast.BiEq (_loc, p, e), + skont) + else + if + pattern_eq_expression + (Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "Some")), p)) + skont + then + Ast.ExTry (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "Some")), e), + Ast.McArr (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Failure"))), + Ast.ExNil _loc, ckont)) + else + if is_raise ckont + then + (let tst = + if handle_failure e + then e + else + Ast.ExTry (_loc, e, + Ast.McArr (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Failure"))), + Ast.ExNil _loc, ckont)) + in + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, p, tst), skont)) + else + Ast.ExMat (_loc, + Ast.ExTry (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "Some")), e), + Ast.McArr (_loc, + Ast.PaId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Failure"))), + Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "None")))), + Ast.McOr (_loc, + Ast.McArr (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "Some")), p), + Ast.ExNil _loc, skont), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + ckont))) + | SpStr (_loc, p) -> + (try + match p with + | Ast.PaId (_, (Ast.IdLid (_, v))) -> subst v skont + | _ -> raise Not_found + with + | Not_found -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, p, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + skont)) + + let rec stream_pattern _loc epo e ekont = + function + | [] -> + (match epo with + | Some ep -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, ep, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "count"))), + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n)))), + e) + | _ -> e) + | (spc, err) :: spcl -> + let skont = + let ekont err = + let str = + (match err with + | Some estr -> estr + | _ -> Ast.ExStr (_loc, "")) + in + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "raise")), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Error"))), + str)) + in stream_pattern _loc epo e ekont spcl in + let ckont = ekont err + in stream_pattern_component skont ckont spc + + let stream_patterns_term _loc ekont tspel = + let pel = + List.fold_right + (fun (p, w, _loc, spcl, epo, e) acc -> + let p = + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "Some")), p) in + let e = + let ekont err = + let str = + match err with + | Some estr -> estr + | _ -> Ast.ExStr (_loc, "") + in + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "raise")), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Error"))), + str)) in + let skont = stream_pattern _loc epo e ekont spcl + in + Ast.ExSeq (_loc, + Ast.ExSem (_loc, + Ast.ExApp (_loc, junk_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + skont)) + in + match w with + | Some w -> + Ast.McOr (_loc, Ast.McArr (_loc, p, w, e), acc) + | None -> + Ast.McOr (_loc, + Ast.McArr (_loc, p, Ast.ExNil _loc, e), acc)) + tspel (Ast.McNil _loc) + in + Ast.ExMat (_loc, + Ast.ExApp (_loc, peek_fun _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n))), + Ast.McOr (_loc, pel, + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, ekont ()))) + + let rec group_terms = + function + | ((SpTrm (_loc, p, w), None) :: spcl, epo, e) :: spel -> + let (tspel, spel) = group_terms spel + in (((p, w, _loc, spcl, epo, e) :: tspel), spel) + | spel -> ([], spel) + + let rec parser_cases _loc = + function + | [] -> + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdLid (_loc, "raise")), + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdUid (_loc, "Failure")))) + | spel -> + (match group_terms spel with + | ([], (spcl, epo, e) :: spel) -> + stream_pattern _loc epo e + (fun _ -> parser_cases _loc spel) spcl + | (tspel, spel) -> + stream_patterns_term _loc + (fun _ -> parser_cases _loc spel) tspel) + + let cparser _loc bpo pc = + let e = parser_cases _loc pc in + let e = + match bpo with + | Some bp -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, bp, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "count"))), + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n)))), + e) + | None -> e in + let p = + Ast.PaTyc (_loc, Ast.PaId (_loc, Ast.IdLid (_loc, strm_n)), + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "t"))), + Ast.TyAny _loc)) + in Ast.ExFun (_loc, Ast.McArr (_loc, p, Ast.ExNil _loc, e)) + + let cparser_match _loc me bpo pc = + let pc = parser_cases _loc pc in + let e = + match bpo with + | Some bp -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, bp, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "count"))), + Ast.ExId (_loc, Ast.IdLid (_loc, strm_n)))), + pc) + | None -> pc in + let me = + match me with + | (Ast.ExSem (_loc, _, _) as e) -> Ast.ExSeq (_loc, e) + | e -> e + in + match me with + | Ast.ExId (_, (Ast.IdLid (_, x))) when x = strm_n -> e + | _ -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, + Ast.PaTyc (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, strm_n)), + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "t"))), + Ast.TyAny _loc)), + me), + e) + + (* streams *) + let rec not_computing = + function + | Ast.ExId (_, (Ast.IdLid (_, _))) | + Ast.ExId (_, (Ast.IdUid (_, _))) | Ast.ExInt (_, _) | + Ast.ExFlo (_, _) | Ast.ExChr (_, _) | Ast.ExStr (_, _) -> true + | Ast.ExApp (_, x, y) -> + (is_cons_apply_not_computing x) && (not_computing y) + | _ -> false + and is_cons_apply_not_computing = + function + | Ast.ExId (_, (Ast.IdUid (_, _))) -> true + | Ast.ExId (_, (Ast.IdLid (_, _))) -> false + | Ast.ExApp (_, x, y) -> + (is_cons_apply_not_computing x) && (not_computing y) + | _ -> false + + let slazy _loc e = + match e with + | Ast.ExApp (_, f, (Ast.ExId (_, (Ast.IdUid (_, "()"))))) -> + (match f with + | Ast.ExId (_, (Ast.IdLid (_, _))) -> f + | _ -> + Ast.ExFun (_loc, + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, e))) + | _ -> + Ast.ExFun (_loc, + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, e)) + + let rec cstream gloc = + function + | [] -> + let _loc = gloc + in + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "sempty"))) + | [ SeTrm (_loc, e) ] -> + if not_computing e + then + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "ising"))), + e) + else + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "lsing"))), + slazy _loc e) + | SeTrm (_loc, e) :: secl -> + if not_computing e + then + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "icons"))), + e), + cstream gloc secl) + else + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "lcons"))), + slazy _loc e), + cstream gloc secl) + | [ SeNtr (_loc, e) ] -> + if not_computing e + then e + else + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "slazy"))), + slazy _loc e) + | SeNtr (_loc, e) :: secl -> + if not_computing e + then + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "iapp"))), + e), + cstream gloc secl) + else + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Stream"), + Ast.IdLid (_loc, "lapp"))), + slazy _loc e), + cstream gloc secl) + + (* Syntax extensions in Revised Syntax grammar *) + let _ = + let _ = (expr : 'expr Gram.Entry.t) + and _ = (parser_case_list : 'parser_case_list Gram.Entry.t) + and _ = (parser_case : 'parser_case Gram.Entry.t) + and _ = (stream_quot : 'stream_quot Gram.Entry.t) + and _ = (stream_end : 'stream_end Gram.Entry.t) + and _ = (stream_begin : 'stream_begin Gram.Entry.t) + and _ = (stream_expr : 'stream_expr Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let stream_patt : 'stream_patt Gram.Entry.t = + grammar_entry_create "stream_patt" + and stream_expr_comp : 'stream_expr_comp Gram.Entry.t = + grammar_entry_create "stream_expr_comp" + and stream_expr_comp_list : 'stream_expr_comp_list Gram.Entry.t = + grammar_entry_create "stream_expr_comp_list" + and parser_ipatt : 'parser_ipatt Gram.Entry.t = + grammar_entry_create "parser_ipatt" + and stream_patt_comp : 'stream_patt_comp Gram.Entry.t = + grammar_entry_create "stream_patt_comp" + and stream_patt_comp_err_list : + 'stream_patt_comp_err_list Gram.Entry.t = + grammar_entry_create "stream_patt_comp_err_list" + and stream_patt_comp_err : 'stream_patt_comp_err Gram.Entry.t = + grammar_entry_create "stream_patt_comp_err" + in + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "top")), + [ (None, None, + [ ([ Gram.Skeyword "match"; + Gram.Snterm + (Gram.Entry.obj + (sequence : 'sequence Gram.Entry.t)); + Gram.Skeyword "with"; Gram.Skeyword "parser"; + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (parser_ipatt : + 'parser_ipatt Gram.Entry.t))); + Gram.Snterm + (Gram.Entry.obj + (parser_case_list : + 'parser_case_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (pcl : 'parser_case_list) + (po : 'parser_ipatt option) _ _ + (e : 'sequence) _ (_loc : Gram.Loc.t) -> + (cparser_match _loc e po pcl : 'expr)))); + ([ Gram.Skeyword "parser"; + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (parser_ipatt : + 'parser_ipatt Gram.Entry.t))); + Gram.Snterm + (Gram.Entry.obj + (parser_case_list : + 'parser_case_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (pcl : 'parser_case_list) + (po : 'parser_ipatt option) _ + (_loc : Gram.Loc.t) -> + (cparser _loc po pcl : 'expr)))) ]) ])) + ()); + Gram.extend (parser_case_list : 'parser_case_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (parser_case : 'parser_case Gram.Entry.t)) ], + (Gram.Action.mk + (fun (pc : 'parser_case) (_loc : Gram.Loc.t) -> + ([ pc ] : 'parser_case_list)))); + ([ Gram.Skeyword "["; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (parser_case : 'parser_case Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (pcl : 'parser_case list) _ + (_loc : Gram.Loc.t) -> + (pcl : 'parser_case_list)))) ]) ])) + ()); + Gram.extend (parser_case : 'parser_case Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_begin : 'stream_begin Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_patt : 'stream_patt Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_end : 'stream_end Gram.Entry.t)); + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (parser_ipatt : + 'parser_ipatt Gram.Entry.t))); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (po : 'parser_ipatt option) _ + (sp : 'stream_patt) _ (_loc : Gram.Loc.t) -> + ((sp, po, e) : 'parser_case)))) ]) ])) + ()); + Gram.extend (stream_begin : 'stream_begin Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "[:" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (() : 'stream_begin)))) ]) ])) + ()); + Gram.extend (stream_end : 'stream_end Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword ":]" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'stream_end)))) ]) ])) + ()); + Gram.extend (stream_quot : 'stream_quot Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "`" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (() : 'stream_quot)))) ]) ])) + ()); + Gram.extend (stream_expr : 'stream_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (e : 'stream_expr)))) ]) ])) + ()); + Gram.extend (stream_patt : 'stream_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> ([] : 'stream_patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp : + 'stream_patt_comp Gram.Entry.t)); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp_err_list : + 'stream_patt_comp_err_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sp : 'stream_patt_comp_err_list) _ + (spc : 'stream_patt_comp) (_loc : Gram.Loc.t) + -> ((spc, None) :: sp : 'stream_patt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp : + 'stream_patt_comp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (spc : 'stream_patt_comp) + (_loc : Gram.Loc.t) -> + ([ (spc, None) ] : 'stream_patt)))) ]) ])) + ()); + Gram.extend + (stream_patt_comp_err : 'stream_patt_comp_err Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp : + 'stream_patt_comp Gram.Entry.t)); + Gram.Sopt + (Gram.srules stream_patt_comp_err + [ ([ Gram.Skeyword "??"; + Gram.Snterm + (Gram.Entry.obj + (stream_expr : + 'stream_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'stream_expr) _ + (_loc : Gram.Loc.t) -> (e : 'e__7)))) ]) ], + (Gram.Action.mk + (fun (eo : 'e__7 option) + (spc : 'stream_patt_comp) (_loc : Gram.Loc.t) + -> ((spc, eo) : 'stream_patt_comp_err)))) ]) ])) + ()); + Gram.extend + (stream_patt_comp_err_list : + 'stream_patt_comp_err_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp_err : + 'stream_patt_comp_err Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (sp : 'stream_patt_comp_err_list) _ + (spc : 'stream_patt_comp_err) + (_loc : Gram.Loc.t) -> + (spc :: sp : 'stream_patt_comp_err_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp_err : + 'stream_patt_comp_err Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (spc : 'stream_patt_comp_err) + (_loc : Gram.Loc.t) -> + ([ spc ] : 'stream_patt_comp_err_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_patt_comp_err : + 'stream_patt_comp_err Gram.Entry.t)) ], + (Gram.Action.mk + (fun (spc : 'stream_patt_comp_err) + (_loc : Gram.Loc.t) -> + ([ spc ] : 'stream_patt_comp_err_list)))) ]) ])) + ()); + Gram.extend (stream_patt_comp : 'stream_patt_comp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) (_loc : Gram.Loc.t) -> + (SpStr (_loc, p) : 'stream_patt_comp)))); + ([ Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj + (stream_expr : 'stream_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'stream_expr) _ (p : 'patt) + (_loc : Gram.Loc.t) -> + (SpNtr (_loc, p, e) : 'stream_patt_comp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_quot : 'stream_quot Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Sopt + (Gram.srules stream_patt_comp + [ ([ Gram.Skeyword "when"; + Gram.Snterm + (Gram.Entry.obj + (stream_expr : + 'stream_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'stream_expr) _ + (_loc : Gram.Loc.t) -> (e : 'e__8)))) ]) ], + (Gram.Action.mk + (fun (eo : 'e__8 option) (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (SpTrm (_loc, p, eo) : 'stream_patt_comp)))) ]) ])) + ()); + Gram.extend (parser_ipatt : 'parser_ipatt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "_" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.PaAny _loc : 'parser_ipatt)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.PaId (_loc, Ast.IdLid (_loc, i)) : + 'parser_ipatt)))) ]) ])) + ()); + Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_begin : 'stream_begin Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_expr_comp_list : + 'stream_expr_comp_list Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_end : 'stream_end Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (sel : 'stream_expr_comp_list) _ + (_loc : Gram.Loc.t) -> + (cstream _loc sel : 'expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_begin : 'stream_begin Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_end : 'stream_end Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + (cstream _loc [] : 'expr)))) ]) ])) + ()); + Gram.extend + (stream_expr_comp_list : 'stream_expr_comp_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_expr_comp : + 'stream_expr_comp Gram.Entry.t)) ], + (Gram.Action.mk + (fun (se : 'stream_expr_comp) + (_loc : Gram.Loc.t) -> + ([ se ] : 'stream_expr_comp_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_expr_comp : + 'stream_expr_comp Gram.Entry.t)); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (se : 'stream_expr_comp) + (_loc : Gram.Loc.t) -> + ([ se ] : 'stream_expr_comp_list)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_expr_comp : + 'stream_expr_comp Gram.Entry.t)); + Gram.Skeyword ";"; Gram.Sself ], + (Gram.Action.mk + (fun (sel : 'stream_expr_comp_list) _ + (se : 'stream_expr_comp) (_loc : Gram.Loc.t) + -> (se :: sel : 'stream_expr_comp_list)))) ]) ])) + ()); + Gram.extend (stream_expr_comp : 'stream_expr_comp Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (stream_expr : 'stream_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'stream_expr) (_loc : Gram.Loc.t) -> + (SeNtr (_loc, e) : 'stream_expr_comp)))); + ([ Gram.Snterm + (Gram.Entry.obj + (stream_quot : 'stream_quot Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (stream_expr : 'stream_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'stream_expr) _ (_loc : Gram.Loc.t) -> + (SeTrm (_loc, e) : 'stream_expr_comp)))) ]) ])) + ())) + + end + + module M = Register.OCamlSyntaxExtension(Id)(Make) + + end + +module G = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2002-2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + module Id = + struct let name = "Camlp4GrammarParser" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + module MetaLoc = Ast.Meta.MetaGhostLoc + + module MetaAst = Ast.Meta.Make(MetaLoc) + + module PP = Camlp4.Printers.OCaml.Make(Syntax) + + let pp = new PP.printer ~comments: false () + + let string_of_patt patt = + let buf = Buffer.create 42 in + let () = Format.bprintf buf "%a@?" pp#patt patt in + let str = Buffer.contents buf + in if str = "" then assert false else str + + let split_ext = ref false + + type loc = Loc.t + + type 'e name = { expr : 'e; tvar : string; loc : loc } + + type styp = + | STlid of loc * string + | STapp of loc * styp * styp + | STquo of loc * string + | STself of loc * string + | STtok of loc + | STstring_tok of loc + | STtyp of Ast.ctyp + + type ('e, 'p) text = + | TXmeta of loc * string * (('e, 'p) text) list * 'e * styp + | TXlist of loc * bool * ('e, 'p) symbol * (('e, 'p) symbol) option + | TXnext of loc + | TXnterm of loc * 'e name * string option + | TXopt of loc * ('e, 'p) text + | TXrules of loc * (((('e, 'p) text) list) * 'e) list + | TXself of loc + | TXkwd of loc * string + | TXtok of loc * 'e * string + and (** The first is the match function expr, + the second is the string description. + The description string will be used for + grammar insertion and left factoring. + Keep this string normalized and well comparable. *) + ('e, 'p) entry = + { name : 'e name; pos : 'e option; levels : (('e, 'p) level) list + } + and ('e, 'p) level = + { label : string option; assoc : 'e option; + rules : (('e, 'p) rule) list + } + and ('e, 'p) rule = + { prod : (('e, 'p) symbol) list; action : 'e option + } + and ('e, 'p) symbol = + { used : string list; text : ('e, 'p) text; styp : styp; + pattern : 'p option + } + + type used = | Unused | UsedScanned | UsedNotScanned + + let _loc = Loc.ghost + + let gm = "Camlp4Grammar__" + + let mark_used modif ht n = + try + let rll = Hashtbl.find_all ht n + in + List.iter + (fun (r, _) -> + if !r == Unused + then (r := UsedNotScanned; modif := true) + else ()) + rll + with | Not_found -> () + + let rec mark_symbol modif ht symb = + List.iter (fun e -> mark_used modif ht e) symb.used + + let check_use nl el = + let ht = Hashtbl.create 301 in + let modif = ref false + in + (List.iter + (fun e -> + let u = + match e.name.expr with + | Ast.ExId (_, (Ast.IdLid (_, _))) -> Unused + | _ -> UsedNotScanned + in Hashtbl.add ht e.name.tvar ((ref u), e)) + el; + List.iter + (fun n -> + try + let rll = Hashtbl.find_all ht n.tvar + in List.iter (fun (r, _) -> r := UsedNotScanned) rll + with | _ -> ()) + nl; + modif := true; + while !modif do modif := false; + Hashtbl.iter + (fun _ (r, e) -> + if !r = UsedNotScanned + then + (r := UsedScanned; + List.iter + (fun level -> + let rules = level.rules + in + List.iter + (fun rule -> + List.iter + (fun s -> mark_symbol modif ht s) + rule.prod) + rules) + e.levels) + else ()) + ht + done; + Hashtbl.iter + (fun s (r, e) -> + if !r = Unused + then + print_warning e.name.loc + ("Unused local entry \"" ^ (s ^ "\"")) + else ()) + ht) + + let new_type_var = + let i = ref 0 in fun () -> (incr i; "e__" ^ (string_of_int !i)) + + let used_of_rule_list rl = + List.fold_left + (fun nl r -> List.fold_left (fun nl s -> s.used @ nl) nl r.prod) + [] rl + + let retype_rule_list_without_patterns _loc rl = + try + List.map + (function + | (* ...; [ "foo" ]; ... ==> ...; (x = [ "foo" ] -> Gram.Token.extract_string x); ... *) + { + prod = [ ({ pattern = None; styp = STtok _ } as s) ]; + action = None + } -> + { + prod = + [ { + (s) + with + pattern = + Some (Ast.PaId (_loc, Ast.IdLid (_loc, "x"))); + } ]; + action = + Some + (Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Token"), + Ast.IdLid (_loc, "extract_string")))), + Ast.ExId (_loc, Ast.IdLid (_loc, "x")))); + } + | (* ...; [ symb ]; ... ==> ...; (x = [ symb ] -> x); ... *) + { prod = [ ({ pattern = None } as s) ]; action = None } -> + { + prod = + [ { + (s) + with + pattern = + Some (Ast.PaId (_loc, Ast.IdLid (_loc, "x"))); + } ]; + action = Some (Ast.ExId (_loc, Ast.IdLid (_loc, "x"))); + } + | (* ...; ([] -> a); ... *) + ({ prod = []; action = Some _ } as r) -> r + | _ -> raise Exit) + rl + with | Exit -> rl + + let meta_action = ref false + + let mklistexp _loc = + let rec loop top = + function + | [] -> Ast.ExId (_loc, Ast.IdUid (_loc, "[]")) + | e1 :: el -> + let _loc = + if top then _loc else Loc.merge (Ast.loc_of_expr e1) _loc + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + e1), + loop false el) + in loop true + + let mklistpat _loc = + let rec loop top = + function + | [] -> Ast.PaId (_loc, Ast.IdUid (_loc, "[]")) + | p1 :: pl -> + let _loc = + if top then _loc else Loc.merge (Ast.loc_of_patt p1) _loc + in + Ast.PaApp (_loc, + Ast.PaApp (_loc, Ast.PaId (_loc, Ast.IdUid (_loc, "::")), + p1), + loop false pl) + in loop true + + let rec expr_fa al = + function + | Ast.ExApp (_, f, a) -> expr_fa (a :: al) f + | f -> (f, al) + + let rec make_ctyp styp tvar = + match styp with + | STlid (_loc, s) -> Ast.TyId (_loc, Ast.IdLid (_loc, s)) + | STapp (_loc, t1, t2) -> + Ast.TyApp (_loc, make_ctyp t1 tvar, make_ctyp t2 tvar) + | STquo (_loc, s) -> Ast.TyQuo (_loc, s) + | STself (_loc, x) -> + if tvar = "" + then + Loc.raise _loc + (Stream.Error + ("'" ^ (x ^ "' illegal in anonymous entry level"))) + else Ast.TyQuo (_loc, tvar) + | STtok _loc -> + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Token")), + Ast.IdLid (_loc, "t"))) + | STstring_tok _loc -> Ast.TyId (_loc, Ast.IdLid (_loc, "string")) + | STtyp t -> t + + let make_ctyp_patt styp tvar patt = + let styp = + match styp with | STstring_tok _loc -> STtok _loc | t -> t + in + match make_ctyp styp tvar with + | Ast.TyAny _ -> patt + | t -> + let _loc = Ast.loc_of_patt patt in Ast.PaTyc (_loc, patt, t) + + let make_ctyp_expr styp tvar expr = + match make_ctyp styp tvar with + | Ast.TyAny _ -> expr + | t -> let _loc = Ast.loc_of_expr expr in Ast.ExTyc (_loc, expr, t) + + let text_of_action _loc psl rtvar act tvar = + let locid = Ast.PaId (_loc, Ast.IdLid (_loc, !Loc.name)) in + let act = + match act with + | Some act -> act + | None -> Ast.ExId (_loc, Ast.IdUid (_loc, "()")) in + let (tok_match_pl, act, _) = + List.fold_left + (fun (((tok_match_pl, act, i) as accu)) -> + function + | { pattern = None } -> accu + | { pattern = Some p } when Ast.is_irrefut_patt p -> accu + | { + pattern = + Some + (Ast.PaAli (_, + (Ast.PaApp (_, _, (Ast.PaTup (_, (Ast.PaAny _))))), + (Ast.PaId (_, (Ast.IdLid (_, s)))))) + } -> + (tok_match_pl, + (Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, s)), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Token"), + Ast.IdLid (_loc, "extract_string")))), + Ast.ExId (_loc, Ast.IdLid (_loc, s)))), + act)), + i) + | { pattern = Some p; text = TXtok (_, _, _) } -> + let id = "__camlp4_" ^ (string_of_int i) + in + ((Some + (match tok_match_pl with + | None -> + ((Ast.ExId (_loc, Ast.IdLid (_loc, id))), p) + | Some ((tok_pl, match_pl)) -> + ((Ast.ExCom (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, id)), + tok_pl)), + (Ast.PaCom (_loc, p, match_pl))))), + act, (succ i)) + | _ -> accu) + (None, act, 0) psl in + let e = + let e1 = Ast.ExTyc (_loc, act, Ast.TyQuo (_loc, rtvar)) in + let e2 = + match tok_match_pl with + | None -> e1 + | Some ((Ast.ExCom (_, t1, t2), Ast.PaCom (_, p1, p2))) -> + Ast.ExMat (_loc, + Ast.ExTup (_loc, Ast.ExCom (_loc, t1, t2)), + Ast.McOr (_loc, + Ast.McArr (_loc, + Ast.PaTup (_loc, Ast.PaCom (_loc, p1, p2)), + Ast.ExNil _loc, e1), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + Ast.ExAsf _loc))) + | Some ((tok, match_)) -> + Ast.ExMat (_loc, tok, + Ast.McOr (_loc, + Ast.McArr (_loc, match_, Ast.ExNil _loc, e1), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + Ast.ExAsf _loc))) + in + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaTyc (_loc, locid, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Loc")), + Ast.IdLid (_loc, "t")))), + Ast.ExNil _loc, e2)) in + let (txt, _) = + List.fold_left + (fun (txt, i) s -> + match s.pattern with + | None | Some (Ast.PaAny _) -> + ((Ast.ExFun (_loc, + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + txt))), + i) + | Some + (Ast.PaAli (_, + (Ast.PaApp (_, _, (Ast.PaTup (_, (Ast.PaAny _))))), + p)) + -> + let p = make_ctyp_patt s.styp tvar p + in + ((Ast.ExFun (_loc, + Ast.McArr (_loc, p, Ast.ExNil _loc, txt))), + i) + | Some p when Ast.is_irrefut_patt p -> + let p = make_ctyp_patt s.styp tvar p + in + ((Ast.ExFun (_loc, + Ast.McArr (_loc, p, Ast.ExNil _loc, txt))), + i) + | Some _ -> + let p = + make_ctyp_patt s.styp tvar + (Ast.PaId (_loc, + Ast.IdLid (_loc, "__camlp4_" ^ (string_of_int i)))) + in + ((Ast.ExFun (_loc, + Ast.McArr (_loc, p, Ast.ExNil _loc, txt))), + (succ i))) + (e, 0) psl in + let txt = + if !meta_action + then + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Obj"), + Ast.IdLid (_loc, "magic"))), + MetaAst.Expr.meta_expr _loc txt) + else txt + in + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Action"), + Ast.IdLid (_loc, "mk")))), + txt) + + let srules loc t rl tvar = + List.map + (fun r -> + let sl = List.map (fun s -> s.text) r.prod in + let ac = text_of_action loc r.prod t r.action tvar in (sl, ac)) + rl + + let rec make_expr entry tvar = + function + | TXmeta (_loc, n, tl, e, t) -> + let el = + List.fold_right + (fun t el -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + make_expr entry "" t), + el)) + tl (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Smeta"))), + Ast.ExStr (_loc, n)), + el), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Action"), + Ast.IdLid (_loc, "mk")))), + make_ctyp_expr t tvar e)) + | TXlist (_loc, min, t, ts) -> + let txt = make_expr entry "" t.text + in + (match (min, ts) with + | (false, None) -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Slist0"))), + txt) + | (true, None) -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Slist1"))), + txt) + | (false, Some s) -> + let x = make_expr entry tvar s.text + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Slist0sep"))), + txt), + x) + | (true, Some s) -> + let x = make_expr entry tvar s.text + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Slist1sep"))), + txt), + x)) + | TXnext _loc -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Snext"))) + | TXnterm (_loc, n, lev) -> + (match lev with + | Some lab -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Snterml"))), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Entry"), + Ast.IdLid (_loc, "obj")))), + Ast.ExTyc (_loc, n.expr, + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Entry")), + Ast.IdLid (_loc, "t"))), + Ast.TyQuo (_loc, n.tvar))))), + Ast.ExStr (_loc, lab)) + | None -> + if n.tvar = tvar + then + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Sself"))) + else + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Snterm"))), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Entry"), + Ast.IdLid (_loc, "obj")))), + Ast.ExTyc (_loc, n.expr, + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Entry")), + Ast.IdLid (_loc, "t"))), + Ast.TyQuo (_loc, n.tvar)))))) + | TXopt (_loc, t) -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Sopt"))), + make_expr entry "" t) + | TXrules (_loc, rl) -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, "srules"))), + entry.expr), + make_expr_rules _loc entry rl "") + | TXself _loc -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Sself"))) + | TXkwd (_loc, kwd) -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Skeyword"))), + Ast.ExStr (_loc, kwd)) + | TXtok (_loc, match_fun, descr) -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Stoken"))), + Ast.ExTup (_loc, + Ast.ExCom (_loc, match_fun, + Ast.ExStr (_loc, Ast.safe_string_escaped descr)))) + and make_expr_rules _loc n rl tvar = + List.fold_left + (fun txt (sl, ac) -> + let sl = + List.fold_right + (fun t txt -> + let x = make_expr n tvar t + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), x), + txt)) + sl (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + Ast.ExTup (_loc, Ast.ExCom (_loc, sl, ac))), + txt)) + (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) rl + + let expr_of_delete_rule _loc n sl = + let sl = + List.fold_right + (fun s e -> + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + make_expr n "" s.text), + e)) + sl (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + in ((n.expr), sl) + + let rec tvar_of_ident = + function + | Ast.IdLid (_, x) | Ast.IdUid (_, x) -> x + | Ast.IdAcc (_, (Ast.IdUid (_, x)), xs) -> + x ^ ("__" ^ (tvar_of_ident xs)) + | _ -> failwith "internal error in the Grammar extension" + + let mk_name _loc i = + { expr = Ast.ExId (_loc, i); tvar = tvar_of_ident i; loc = _loc; } + + let slist loc min sep symb = TXlist (loc, min, symb, sep) + + (* + value sstoken _loc s = + let n = mk_name _loc <:ident< $lid:"a_" ^ s$ >> in + TXnterm _loc n None + ; + + value mk_symbol p s t = + {used = []; text = s; styp = t; pattern=Some p}; + + value sslist _loc min sep s = + let rl = + let r1 = + let prod = + let n = mk_name _loc <:ident< a_list >> in + [mk_symbol <:patt< a >> (TXnterm _loc n None) (STquo _loc "a_list")] + in + let act = <:expr< a >> in + {prod = prod; action = Some act} + in + let r2 = + let prod = + [mk_symbol <:patt< a >> (slist _loc min sep s) + (STapp _loc (STlid _loc "list") s.styp)] + in + let act = <:expr< Qast.List a >> in + {prod = prod; action = Some act} + in + [r1; r2] + in + let used = + match sep with + [ Some symb -> symb.used @ s.used + | None -> s.used ] + in + let used = ["a_list" :: used] in + let text = TXrules _loc (srules _loc "a_list" rl "") in + let styp = STquo _loc "a_list" in + {used = used; text = text; styp = styp; pattern = None} + ; + + value ssopt _loc s = + let rl = + let r1 = + let prod = + let n = mk_name _loc <:ident< a_opt >> in + [mk_symbol <:patt< a >> (TXnterm _loc n None) (STquo _loc "a_opt")] + in + let act = <:expr< a >> in + {prod = prod; action = Some act} + in + let r2 = + let s = + match s.text with + [ TXkwd _loc _ | TXtok _loc _ _ -> + let rl = + [{prod = [{ (s) with pattern = Some <:patt< x >> }]; + action = Some <:expr< Qast.Str (Token.extract_string x) >>}] + in + let t = new_type_var () in + {used = []; text = TXrules _loc (srules _loc t rl ""); + styp = STquo _loc t; pattern = None} + | _ -> s ] + in + let prod = + [mk_symbol <:patt< a >> (TXopt _loc s.text) + (STapp _loc (STlid _loc "option") s.styp)] + in + let act = <:expr< Qast.Option a >> in + {prod = prod; action = Some act} + in + [r1; r2] + in + let used = ["a_opt" :: s.used] in + let text = TXrules _loc (srules _loc "a_opt" rl "") in + let styp = STquo _loc "a_opt" in + {used = used; text = text; styp = styp; pattern = None} + ; + *) + let text_of_entry _loc e = + let ent = + let x = e.name in + let _loc = e.name.loc + in + Ast.ExTyc (_loc, x.expr, + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Entry")), + Ast.IdLid (_loc, "t"))), + Ast.TyQuo (_loc, x.tvar))) in + let pos = + match e.pos with + | Some pos -> + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "Some")), + pos) + | None -> Ast.ExId (_loc, Ast.IdUid (_loc, "None")) in + let txt = + List.fold_right + (fun level txt -> + let lab = + match level.label with + | Some lab -> + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "Some")), + Ast.ExStr (_loc, lab)) + | None -> Ast.ExId (_loc, Ast.IdUid (_loc, "None")) in + let ass = + match level.assoc with + | Some ass -> + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "Some")), ass) + | None -> Ast.ExId (_loc, Ast.IdUid (_loc, "None")) in + let txt = + let rl = + srules _loc e.name.tvar level.rules e.name.tvar in + let e = make_expr_rules _loc e.name rl e.name.tvar + in + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + Ast.ExTup (_loc, + Ast.ExCom (_loc, lab, Ast.ExCom (_loc, ass, e)))), + txt) + in txt) + e.levels (Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + in (ent, pos, txt) + + let let_in_of_extend _loc gram gl el args = + match gl with + | None -> args + | Some nl -> + (check_use nl el; + let ll = + let same_tvar e n = e.name.tvar = n.tvar + in + List.fold_right + (fun e ll -> + match e.name.expr with + | Ast.ExId (_, (Ast.IdLid (_, _))) -> + if List.exists (same_tvar e) nl + then ll + else + if List.exists (same_tvar e) ll + then ll + else e.name :: ll + | _ -> ll) + el [] in + let local_binding_of_name { expr = e; tvar = x; loc = _loc } = + let i = + (match e with + | Ast.ExId (_, (Ast.IdLid (_, i))) -> i + | _ -> failwith "internal error in the Grammar extension") + in + Ast.BiEq (_loc, Ast.PaId (_loc, Ast.IdLid (_loc, i)), + Ast.ExTyc (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "grammar_entry_create")), + Ast.ExStr (_loc, i)), + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Entry")), + Ast.IdLid (_loc, "t"))), + Ast.TyQuo (_loc, x)))) in + let expr_of_name { expr = e; tvar = x; loc = _loc } = + Ast.ExTyc (_loc, e, + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdUid (_loc, "Entry")), + Ast.IdLid (_loc, "t"))), + Ast.TyQuo (_loc, x))) in + let e = + (match ll with + | [] -> args + | x :: xs -> + let locals = + List.fold_right + (fun name acc -> + Ast.BiAnd (_loc, acc, + local_binding_of_name name)) + xs (local_binding_of_name x) in + let entry_mk = + (match gram with + | Some g -> + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Entry"), + Ast.IdLid (_loc, "mk")))), + Ast.ExId (_loc, g)) + | None -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Entry"), + Ast.IdLid (_loc, "mk"))))) + in + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, + Ast.PaId (_loc, + Ast.IdLid (_loc, "grammar_entry_create")), + entry_mk), + Ast.ExLet (_loc, Ast.BFalse, locals, args))) + in + (match nl with + | [] -> e + | x :: xs -> + let globals = + List.fold_right + (fun name acc -> + Ast.BiAnd (_loc, acc, + Ast.BiEq (_loc, Ast.PaAny _loc, + expr_of_name name))) + xs + (Ast.BiEq (_loc, Ast.PaAny _loc, expr_of_name x)) + in Ast.ExLet (_loc, Ast.BFalse, globals, e))) + + class subst gmod = + object inherit Ast.map as super + + method ident = + function + | Ast.IdUid (_, x) when x = gm -> gmod + | x -> super#ident x + + end + + let subst_gmod ast gmod = (new subst gmod)#expr ast + + let text_of_functorial_extend _loc gmod gram gl el = + let args = + let el = + List.map + (fun e -> + let (ent, pos, txt) = text_of_entry e.name.loc e in + let e = + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, "extend"))), + ent), + Ast.ExApp (_loc, + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "()")), + Ast.ExNil _loc, + Ast.ExTup (_loc, Ast.ExCom (_loc, pos, txt)))), + Ast.ExId (_loc, Ast.IdUid (_loc, "()")))) + in + if !split_ext + then + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, "aux")), + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, "()")), + Ast.ExNil _loc, e))), + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "aux")), + Ast.ExId (_loc, Ast.IdUid (_loc, "()")))) + else e) + el + in + match el with + | [] -> Ast.ExId (_loc, Ast.IdUid (_loc, "()")) + | [ e ] -> e + | e :: el -> + Ast.ExSeq (_loc, + List.fold_left (fun acc x -> Ast.ExSem (_loc, acc, x)) e + el) + in subst_gmod (let_in_of_extend _loc gram gl el args) gmod + + let wildcarder = + object (self) + inherit Ast.map as super + + method patt = + function + | Ast.PaId (_loc, (Ast.IdLid (_, _))) -> Ast.PaAny _loc + | Ast.PaAli (_, p, _) -> self#patt p + | p -> super#patt p + + end + + let mk_tok _loc p t = + let p' = wildcarder#patt p in + let match_fun = + if Ast.is_irrefut_patt p' + then + Ast.ExFun (_loc, + Ast.McArr (_loc, p', Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "True")))) + else + Ast.ExFun (_loc, + Ast.McOr (_loc, + Ast.McArr (_loc, p', Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "True"))), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "False"))))) in + let descr = string_of_patt p' in + let text = TXtok (_loc, match_fun, descr) + in { used = []; text = text; styp = t; pattern = Some p; } + + let symbol = Gram.Entry.mk "symbol" + + let check_not_tok s = + match s with + | { text = TXtok (_loc, _, _) } -> + Loc.raise _loc + (Stream.Error + ("Deprecated syntax, use a sub rule. " ^ + "LIST0 STRING becomes LIST0 [ x = STRING -> x ]")) + | _ -> () + + let _ = Camlp4_config.antiquotations := true + + let _ = + let _ = (expr : 'expr Gram.Entry.t) + and _ = (symbol : 'symbol Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let extend_header : 'extend_header Gram.Entry.t = + grammar_entry_create "extend_header" + and semi_sep : 'semi_sep Gram.Entry.t = + grammar_entry_create "semi_sep" + and string : 'string Gram.Entry.t = grammar_entry_create "string" + and name : 'name Gram.Entry.t = grammar_entry_create "name" + and comma_patt : 'comma_patt Gram.Entry.t = + grammar_entry_create "comma_patt" + and pattern : 'pattern Gram.Entry.t = + grammar_entry_create "pattern" + and psymbol : 'psymbol Gram.Entry.t = + grammar_entry_create "psymbol" + and rule : 'rule Gram.Entry.t = grammar_entry_create "rule" + and rule_list : 'rule_list Gram.Entry.t = + grammar_entry_create "rule_list" + and assoc : 'assoc Gram.Entry.t = grammar_entry_create "assoc" + and level : 'level Gram.Entry.t = grammar_entry_create "level" + and level_list : 'level_list Gram.Entry.t = + grammar_entry_create "level_list" + and position : 'position Gram.Entry.t = + grammar_entry_create "position" + and entry : 'entry Gram.Entry.t = grammar_entry_create "entry" + and global : 'global Gram.Entry.t = grammar_entry_create "global" + and t_qualid : 't_qualid Gram.Entry.t = + grammar_entry_create "t_qualid" + and qualid : 'qualid Gram.Entry.t = grammar_entry_create "qualid" + and qualuid : 'qualuid Gram.Entry.t = + grammar_entry_create "qualuid" + and delete_rule_body : 'delete_rule_body Gram.Entry.t = + grammar_entry_create "delete_rule_body" + and extend_body : 'extend_body Gram.Entry.t = + grammar_entry_create "extend_body" + in + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.After "top")), + [ (None, None, + [ ([ Gram.Skeyword "GEXTEND" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Loc.raise _loc + (Stream.Error + "Deprecated syntax, use EXTEND MyGramModule ... END instead") : + 'expr)))); + ([ Gram.Skeyword "GDELETE_RULE" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Loc.raise _loc + (Stream.Error + "Deprecated syntax, use DELETE_RULE MyGramModule ... END instead") : + 'expr)))); + ([ Gram.Skeyword "DELETE_RULE"; + Gram.Snterm + (Gram.Entry.obj + (delete_rule_body : + 'delete_rule_body Gram.Entry.t)); + Gram.Skeyword "END" ], + (Gram.Action.mk + (fun _ (e : 'delete_rule_body) _ + (_loc : Gram.Loc.t) -> (e : 'expr)))); + ([ Gram.Skeyword "EXTEND"; + Gram.Snterm + (Gram.Entry.obj + (extend_body : 'extend_body Gram.Entry.t)); + Gram.Skeyword "END" ], + (Gram.Action.mk + (fun _ (e : 'extend_body) _ (_loc : Gram.Loc.t) + -> (e : 'expr)))) ]) ])) + ()); + Gram.extend (extend_header : 'extend_header Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (qualuid : 'qualuid Gram.Entry.t)) ], + (Gram.Action.mk + (fun (g : 'qualuid) (_loc : Gram.Loc.t) -> + ((None, g) : 'extend_header)))); + ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj (qualid : 'qualid Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Snterm + (Gram.Entry.obj + (t_qualid : 't_qualid Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (t : 't_qualid) _ (i : 'qualid) _ + (_loc : Gram.Loc.t) -> + (((Some i), t) : 'extend_header)))) ]) ])) + ()); + Gram.extend (extend_body : 'extend_body Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (extend_header : + 'extend_header Gram.Entry.t)); + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (global : 'global Gram.Entry.t))); + Gram.Slist1 + (Gram.srules extend_body + [ ([ Gram.Snterm + (Gram.Entry.obj + (entry : 'entry Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi_sep : + 'semi_sep Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (e : 'entry) + (_loc : Gram.Loc.t) -> (e : 'e__9)))) ]) ], + (Gram.Action.mk + (fun (el : 'e__9 list) + (global_list : 'global option) + ((gram, g) : 'extend_header) + (_loc : Gram.Loc.t) -> + (text_of_functorial_extend _loc g gram + global_list el : + 'extend_body)))) ]) ])) + ()); + Gram.extend (delete_rule_body : 'delete_rule_body Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (qualuid : 'qualuid Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (name : 'name Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (symbol : 'symbol Gram.Entry.t)), + Gram.Snterm + (Gram.Entry.obj + (semi_sep : 'semi_sep Gram.Entry.t))) ], + (Gram.Action.mk + (fun (sl : 'symbol list) _ (n : 'name) + (g : 'qualuid) (_loc : Gram.Loc.t) -> + (let (e, b) = expr_of_delete_rule _loc n sl + in + subst_gmod + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, "delete_rule"))), + e), + b)) + g : + 'delete_rule_body)))) ]) ])) + ()); + Gram.extend (qualuid : 'qualuid Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.srules qualuid + [ ([ Gram.Stoken + (((function + | UIDENT "GLOBAL" -> true + | _ -> false), + "UIDENT \"GLOBAL\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "GLOBAL" -> (() : 'e__10) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | LIDENT ((_)) -> true + | _ -> false), + "LIDENT ((_))")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT ((_)) -> (() : 'e__10) + | _ -> assert false))) ] ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Loc.raise _loc + (Stream.Error + "Deprecated syntax, the grammar module is expected") : + 'qualuid)))) ]); + (None, None, + [ ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in Ast.IdUid (_loc, i) : 'qualuid)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (xs : 'qualuid) _ (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = Gram.Token.extract_string x + in Ast.IdAcc (_loc, Ast.IdUid (_loc, x), xs) : + 'qualuid)))) ]) ])) + ()); + Gram.extend (qualuid : 'qualuid Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.srules qualuid + [ ([ Gram.Stoken + (((function + | UIDENT "GLOBAL" -> true + | _ -> false), + "UIDENT \"GLOBAL\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "GLOBAL" -> (() : 'e__11) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | LIDENT ((_)) -> true + | _ -> false), + "LIDENT ((_))")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT ((_)) -> (() : 'e__11) + | _ -> assert false))) ] ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Loc.raise _loc + (Stream.Error + "Deprecated syntax, the grammar module is expected") : + 'qualuid)))) ]); + (None, None, + [ ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in Ast.IdUid (_loc, i) : 'qualuid)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (xs : 'qualuid) _ (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = Gram.Token.extract_string x + in Ast.IdAcc (_loc, Ast.IdUid (_loc, x), xs) : + 'qualuid)))) ]) ])) + ()); + Gram.extend (qualid : 'qualid Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in Ast.IdLid (_loc, i) : 'qualid)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in Ast.IdUid (_loc, i) : 'qualid)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (xs : 'qualid) _ (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = Gram.Token.extract_string x + in Ast.IdAcc (_loc, Ast.IdUid (_loc, x), xs) : + 'qualid)))) ]) ])) + ()); + Gram.extend (t_qualid : 't_qualid Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | LIDENT _ | UIDENT _ -> true + | _ -> false), + "LIDENT _ | UIDENT _")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT _ | UIDENT _ -> + (Loc.raise _loc + (Stream.Error + ("Wrong EXTEND header, the grammar type must finish by 't', " + ^ + "like in EXTEND (g : Gram.t) ... END")) : + 't_qualid) + | _ -> assert false))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; + Gram.Stoken + (((function | LIDENT "t" -> true | _ -> false), + "LIDENT \"t\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) _ + (x : Gram.Token.t) (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT "t" -> + (let x = Gram.Token.extract_string x + in Ast.IdUid (_loc, x) : 't_qualid) + | _ -> assert false))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; Gram.Sself ], + (Gram.Action.mk + (fun (xs : 't_qualid) _ (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = Gram.Token.extract_string x + in Ast.IdAcc (_loc, Ast.IdUid (_loc, x), xs) : + 't_qualid)))) ]) ])) + ()); + Gram.extend (global : 'global Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT "GLOBAL" -> true + | _ -> false), + "UIDENT \"GLOBAL\"")); + Gram.Skeyword ":"; + Gram.Slist1 + (Gram.Snterm + (Gram.Entry.obj (name : 'name Gram.Entry.t))); + Gram.Snterm + (Gram.Entry.obj + (semi_sep : 'semi_sep Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (sl : 'name list) _ + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "GLOBAL" -> (sl : 'global) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (entry : 'entry Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (name : 'name Gram.Entry.t)); + Gram.Skeyword ":"; + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (position : 'position Gram.Entry.t))); + Gram.Snterm + (Gram.Entry.obj + (level_list : 'level_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (ll : 'level_list) (pos : 'position option) + _ (n : 'name) (_loc : Gram.Loc.t) -> + ({ name = n; pos = pos; levels = ll; } : + 'entry)))) ]) ])) + ()); + Gram.extend (position : 'position Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT "LEVEL" -> true + | _ -> false), + "UIDENT \"LEVEL\"")); + Gram.Snterm + (Gram.Entry.obj (string : 'string Gram.Entry.t)) ], + (Gram.Action.mk + (fun (n : 'string) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LEVEL" -> + (Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "Level"))))), + n) : + 'position) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "AFTER" -> true + | _ -> false), + "UIDENT \"AFTER\"")); + Gram.Snterm + (Gram.Entry.obj (string : 'string Gram.Entry.t)) ], + (Gram.Action.mk + (fun (n : 'string) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "AFTER" -> + (Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "After"))))), + n) : + 'position) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "BEFORE" -> true + | _ -> false), + "UIDENT \"BEFORE\"")); + Gram.Snterm + (Gram.Entry.obj (string : 'string Gram.Entry.t)) ], + (Gram.Action.mk + (fun (n : 'string) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "BEFORE" -> + (Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "Before"))))), + n) : + 'position) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "LAST" -> true + | _ -> false), + "UIDENT \"LAST\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LAST" -> + (Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "Last"))))) : + 'position) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "FIRST" -> true + | _ -> false), + "UIDENT \"FIRST\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "FIRST" -> + (Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "First"))))) : + 'position) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (level_list : 'level_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "["; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (level : 'level Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (ll : 'level list) _ (_loc : Gram.Loc.t) + -> (ll : 'level_list)))) ]) ])) + ()); + Gram.extend (level : 'level Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Sopt + (Gram.srules level + [ ([ Gram.Stoken + (((function + | STRING ((_)) -> true + | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = + Gram.Token.extract_string x + in x : 'e__12)))) ]); + Gram.Sopt + (Gram.Snterm + (Gram.Entry.obj + (assoc : 'assoc Gram.Entry.t))); + Gram.Snterm + (Gram.Entry.obj + (rule_list : 'rule_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (rules : 'rule_list) (ass : 'assoc option) + (lab : 'e__12 option) (_loc : Gram.Loc.t) -> + ({ label = lab; assoc = ass; rules = rules; } : + 'level)))) ]) ])) + ()); + Gram.extend (assoc : 'assoc Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT "NONA" -> true + | _ -> false), + "UIDENT \"NONA\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "NONA" -> + (Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "NonA"))))) : + 'assoc) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "RIGHTA" -> true + | _ -> false), + "UIDENT \"RIGHTA\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "RIGHTA" -> + (Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "RightA"))))) : + 'assoc) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "LEFTA" -> true + | _ -> false), + "UIDENT \"LEFTA\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LEFTA" -> + (Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Camlp4"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Sig"), + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Grammar"), + Ast.IdUid (_loc, "LeftA"))))) : + 'assoc) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (rule_list : 'rule_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "["; + Gram.Slist1sep + (Gram.Snterm + (Gram.Entry.obj (rule : 'rule Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rules : 'rule list) _ + (_loc : Gram.Loc.t) -> + (retype_rule_list_without_patterns _loc rules : + 'rule_list)))); + ([ Gram.Skeyword "["; Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ _ (_loc : Gram.Loc.t) -> + ([] : 'rule_list)))) ]) ])) + ()); + Gram.extend (rule : 'rule Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (psymbol : 'psymbol Gram.Entry.t)), + Gram.Snterm + (Gram.Entry.obj + (semi_sep : 'semi_sep Gram.Entry.t))) ], + (Gram.Action.mk + (fun (psl : 'psymbol list) (_loc : Gram.Loc.t) + -> ({ prod = psl; action = None; } : 'rule)))); + ([ Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj + (psymbol : 'psymbol Gram.Entry.t)), + Gram.Snterm + (Gram.Entry.obj + (semi_sep : 'semi_sep Gram.Entry.t))); + Gram.Skeyword "->"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (act : 'expr) _ (psl : 'psymbol list) + (_loc : Gram.Loc.t) -> + ({ prod = psl; action = Some act; } : 'rule)))) ]) ])) + ()); + Gram.extend (psymbol : 'psymbol Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (symbol : 'symbol Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'symbol) (_loc : Gram.Loc.t) -> + (s : 'psymbol)))); + ([ Gram.Snterm + (Gram.Entry.obj + (pattern : 'pattern Gram.Entry.t)); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (symbol : 'symbol Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'symbol) _ (p : 'pattern) + (_loc : Gram.Loc.t) -> + (match s.pattern with + | Some + (Ast.PaApp (_, + (Ast.PaId (_, (Ast.IdUid (_, u)))), + (Ast.PaTup (_, (Ast.PaAny _))))) + -> + mk_tok _loc + (Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdUid (_loc, u)), + p)) + s.styp + | _ -> { (s) with pattern = Some p; } : + 'psymbol)))); + ([ Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")); + Gram.Sopt + (Gram.srules psymbol + [ ([ Gram.Stoken + (((function + | UIDENT "LEVEL" -> true + | _ -> false), + "UIDENT \"LEVEL\"")); + Gram.Stoken + (((function + | STRING ((_)) -> true + | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LEVEL" -> + (let s = + Gram.Token.extract_string s + in s : 'e__13) + | _ -> assert false))) ]) ], + (Gram.Action.mk + (fun (lev : 'e__13 option) (i : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i in + let name = + mk_name _loc (Ast.IdLid (_loc, i)) in + let text = TXnterm (_loc, name, lev) in + let styp = STquo (_loc, i) + in + { + used = [ i ]; + text = text; + styp = styp; + pattern = None; + } : + 'psymbol)))); + ([ Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")); + Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (symbol : 'symbol Gram.Entry.t)) ], + (Gram.Action.mk + (fun (s : 'symbol) _ (p : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let p = Gram.Token.extract_string p + in + match s.pattern with + | Some + ((Ast.PaApp (_, + (Ast.PaId (_, (Ast.IdUid (_, u)))), + (Ast.PaTup (_, (Ast.PaAny _)))) + as p')) + -> + let match_fun = + Ast.ExFun (_loc, + Ast.McOr (_loc, + Ast.McArr (_loc, p', + Ast.ExNil _loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "True"))), + Ast.McArr (_loc, Ast.PaAny _loc, + Ast.ExNil _loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "False"))))) in + let p' = + Ast.PaAli (_loc, p', + Ast.PaId (_loc, + Ast.IdLid (_loc, p))) in + let descr = u ^ " _" in + let text = + TXtok (_loc, match_fun, descr) + in + { + (s) + with + text = text; + pattern = Some p'; + } + | _ -> + { + (s) + with + pattern = + Some + (Ast.PaId (_loc, + Ast.IdLid (_loc, p))); + } : + 'psymbol)))) ]) ])) + ()); + Gram.extend (symbol : 'symbol Gram.Entry.t) + ((fun () -> + (None, + [ ((Some "top"), (Some Camlp4.Sig.Grammar.NonA), + [ ([ Gram.Stoken + (((function | UIDENT "OPT" -> true | _ -> false), + "UIDENT \"OPT\"")); + Gram.Sself ], + (Gram.Action.mk + (fun (s : 'symbol) (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "OPT" -> + (let () = check_not_tok s in + let styp = + STapp (_loc, STlid (_loc, "option"), + s.styp) in + let text = TXopt (_loc, s.text) + in + { + used = s.used; + text = text; + styp = styp; + pattern = None; + } : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "LIST1" -> true + | _ -> false), + "UIDENT \"LIST1\"")); + Gram.Sself; + Gram.Sopt + (Gram.srules symbol + [ ([ Gram.Stoken + (((function + | UIDENT "SEP" -> true + | _ -> false), + "UIDENT \"SEP\"")); + Gram.Snterm + (Gram.Entry.obj + (symbol : 'symbol Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'symbol) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "SEP" -> (t : 'e__15) + | _ -> assert false))) ]) ], + (Gram.Action.mk + (fun (sep : 'e__15 option) (s : 'symbol) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LIST1" -> + (let () = check_not_tok s in + let used = + (match sep with + | Some symb -> symb.used @ s.used + | None -> s.used) in + let styp = + STapp (_loc, STlid (_loc, "list"), + s.styp) in + let text = slist _loc true sep s + in + { + used = used; + text = text; + styp = styp; + pattern = None; + } : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "LIST0" -> true + | _ -> false), + "UIDENT \"LIST0\"")); + Gram.Sself; + Gram.Sopt + (Gram.srules symbol + [ ([ Gram.Stoken + (((function + | UIDENT "SEP" -> true + | _ -> false), + "UIDENT \"SEP\"")); + Gram.Snterm + (Gram.Entry.obj + (symbol : 'symbol Gram.Entry.t)) ], + (Gram.Action.mk + (fun (t : 'symbol) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "SEP" -> (t : 'e__14) + | _ -> assert false))) ]) ], + (Gram.Action.mk + (fun (sep : 'e__14 option) (s : 'symbol) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LIST0" -> + (let () = check_not_tok s in + let used = + (match sep with + | Some symb -> symb.used @ s.used + | None -> s.used) in + let styp = + STapp (_loc, STlid (_loc, "list"), + s.styp) in + let text = slist _loc false sep s + in + { + used = used; + text = text; + styp = styp; + pattern = None; + } : + 'symbol) + | _ -> assert false))) ]); + (None, None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (s_t : 'symbol) _ (_loc : Gram.Loc.t) -> + (s_t : 'symbol)))); + ([ Gram.Snterm + (Gram.Entry.obj (name : 'name Gram.Entry.t)); + Gram.Sopt + (Gram.srules symbol + [ ([ Gram.Stoken + (((function + | UIDENT "LEVEL" -> true + | _ -> false), + "UIDENT \"LEVEL\"")); + Gram.Stoken + (((function + | STRING ((_)) -> true + | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LEVEL" -> + (let s = + Gram.Token.extract_string s + in s : 'e__17) + | _ -> assert false))) ]) ], + (Gram.Action.mk + (fun (lev : 'e__17 option) (n : 'name) + (_loc : Gram.Loc.t) -> + ({ + used = [ n.tvar ]; + text = TXnterm (_loc, n, lev); + styp = STquo (_loc, n.tvar); + pattern = None; + } : 'symbol)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Skeyword "."; + Gram.Snterm + (Gram.Entry.obj (qualid : 'qualid Gram.Entry.t)); + Gram.Sopt + (Gram.srules symbol + [ ([ Gram.Stoken + (((function + | UIDENT "LEVEL" -> true + | _ -> false), + "UIDENT \"LEVEL\"")); + Gram.Stoken + (((function + | STRING ((_)) -> true + | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "LEVEL" -> + (let s = + Gram.Token.extract_string s + in s : 'e__16) + | _ -> assert false))) ]) ], + (Gram.Action.mk + (fun (lev : 'e__16 option) (il : 'qualid) _ + (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i in + let n = + mk_name _loc + (Ast.IdAcc (_loc, Ast.IdUid (_loc, i), + il)) + in + { + used = [ n.tvar ]; + text = TXnterm (_loc, n, lev); + styp = STquo (_loc, n.tvar); + pattern = None; + } : + 'symbol)))); + ([ Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let s = Gram.Token.extract_string s + in + { + used = []; + text = TXkwd (_loc, s); + styp = STtok _loc; + pattern = None; + } : + 'symbol)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (x : Gram.Token.t) (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ("", s) -> + (let x = Gram.Token.extract_string x in + let e = + AntiquotSyntax.parse_expr _loc s in + let match_fun = + Ast.ExFun (_loc, + Ast.McOr (_loc, + Ast.McArr (_loc, + Ast.PaApp (_loc, + Ast.PaId (_loc, + Ast.IdUid (_loc, x)), + Ast.PaId (_loc, + Ast.IdLid (_loc, "camlp4_x"))), + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdLid (_loc, "=")), + Ast.ExId (_loc, + Ast.IdLid (_loc, + "camlp4_x"))), + e), + Ast.ExId (_loc, + Ast.IdUid (_loc, "True"))), + Ast.McArr (_loc, Ast.PaAny _loc, + Ast.ExNil _loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "False"))))) in + let descr = "$" ^ (x ^ (" " ^ s)) in + let text = + TXtok (_loc, match_fun, descr) in + let p = + Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, x)), + Ast.PaTup (_loc, Ast.PaAny _loc)) + in + { + used = []; + text = text; + styp = STtok _loc; + pattern = Some p; + } : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")); + Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let s = Gram.Token.extract_string s in + let x = Gram.Token.extract_string x + in + mk_tok _loc + (Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, x)), + Ast.PaStr (_loc, s))) + (STtok _loc) : + 'symbol)))); + ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (x : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let x = Gram.Token.extract_string x + in + mk_tok _loc + (Ast.PaApp (_loc, + Ast.PaId (_loc, Ast.IdUid (_loc, x)), + Ast.PaTup (_loc, Ast.PaAny _loc))) + (STstring_tok _loc) : + 'symbol)))); + ([ Gram.Skeyword "`"; + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'patt) _ (_loc : Gram.Loc.t) -> + (mk_tok _loc p (STtok _loc) : 'symbol)))); + ([ Gram.Skeyword "["; + Gram.Slist0sep + (Gram.Snterm + (Gram.Entry.obj (rule : 'rule Gram.Entry.t)), + Gram.Skeyword "|"); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (rl : 'rule list) _ (_loc : Gram.Loc.t) + -> + (let rl = + retype_rule_list_without_patterns _loc rl in + let t = new_type_var () + in + { + used = used_of_rule_list rl; + text = + TXrules (_loc, srules _loc t rl ""); + styp = STquo (_loc, t); + pattern = None; + } : + 'symbol)))); + ([ Gram.Stoken + (((function + | UIDENT "NEXT" -> true + | _ -> false), + "UIDENT \"NEXT\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "NEXT" -> + ({ + used = []; + text = TXnext _loc; + styp = STself (_loc, "NEXT"); + pattern = None; + } : 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "SELF" -> true + | _ -> false), + "UIDENT \"SELF\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "SELF" -> + ({ + used = []; + text = TXself _loc; + styp = STself (_loc, "SELF"); + pattern = None; + } : 'symbol) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (pattern : 'pattern Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ","; + Gram.Snterm + (Gram.Entry.obj + (comma_patt : 'comma_patt Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p2 : 'comma_patt) _ (p1 : 'pattern) _ + (_loc : Gram.Loc.t) -> + (Ast.PaTup (_loc, Ast.PaCom (_loc, p1, p2)) : + 'pattern)))); + ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (p : 'pattern) _ (_loc : Gram.Loc.t) -> + (p : 'pattern)))); + ([ Gram.Skeyword "_" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.PaAny _loc : 'pattern)))); + ([ Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in Ast.PaId (_loc, Ast.IdLid (_loc, i)) : + 'pattern)))) ]) ])) + ()); + Gram.extend (comma_patt : 'comma_patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (pattern : 'pattern Gram.Entry.t)) ], + (Gram.Action.mk + (fun (p : 'pattern) (_loc : Gram.Loc.t) -> + (p : 'comma_patt)))); + ([ Gram.Sself; Gram.Skeyword ","; Gram.Sself ], + (Gram.Action.mk + (fun (p2 : 'comma_patt) _ (p1 : 'comma_patt) + (_loc : Gram.Loc.t) -> + (Ast.PaCom (_loc, p1, p2) : 'comma_patt)))) ]) ])) + ()); + Gram.extend (name : 'name Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (qualid : 'qualid Gram.Entry.t)) ], + (Gram.Action.mk + (fun (il : 'qualid) (_loc : Gram.Loc.t) -> + (mk_name _loc il : 'name)))) ]) ])) + ()); + Gram.extend (string : 'string Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | ANTIQUOT ("", _) -> true + | _ -> false), + "ANTIQUOT (\"\", _)")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | ANTIQUOT ("", s) -> + (AntiquotSyntax.parse_expr _loc s : + 'string) + | _ -> assert false))); + ([ Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (s : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let s = Gram.Token.extract_string s + in Ast.ExStr (_loc, s) : 'string)))) ]) ])) + ()); + Gram.extend (semi_sep : 'semi_sep Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'semi_sep)))) ]) ])) + ())) + + (* + EXTEND Gram + symbol: LEVEL "top" + [ NONA + [ min = [ UIDENT "SLIST0" -> False | UIDENT "SLIST1" -> True ]; + s = SELF; sep = OPT [ UIDENT "SEP"; t = symbol -> t ] -> + sslist _loc min sep s + | UIDENT "SOPT"; s = SELF -> + ssopt _loc s ] ] + ; + END; + *) + let sfold _loc n foldfun f e s = + let styp = STquo (_loc, new_type_var ()) in + let e = + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, foldfun))), + f), + e) in + let t = + STapp (_loc, + STapp (_loc, + STtyp + (Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, "fold"))), + Ast.TyAny _loc)), + s.styp), + styp) + in + { + used = s.used; + text = TXmeta (_loc, n, [ s.text ], e, t); + styp = styp; + pattern = None; + } + + let sfoldsep _loc n foldfun f e s sep = + let styp = STquo (_loc, new_type_var ()) in + let e = + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, foldfun))), + f), + e) in + let t = + STapp (_loc, + STapp (_loc, + STtyp + (Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, gm), + Ast.IdLid (_loc, "foldsep"))), + Ast.TyAny _loc)), + s.styp), + styp) + in + { + used = s.used @ sep.used; + text = TXmeta (_loc, n, [ s.text; sep.text ], e, t); + styp = styp; + pattern = None; + } + + let _ = + let _ = (symbol : 'symbol Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let simple_expr : 'simple_expr Gram.Entry.t = + grammar_entry_create "simple_expr" + in + (Gram.extend (symbol : 'symbol Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "top")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT "FOLD1" -> true + | _ -> false), + "UIDENT \"FOLD1\"")); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Sself; + Gram.Stoken + (((function | UIDENT "SEP" -> true | _ -> false), + "UIDENT \"SEP\"")); + Gram.Sself ], + (Gram.Action.mk + (fun (sep : 'symbol) (__camlp4_1 : Gram.Token.t) + (s : 'symbol) (e : 'simple_expr) + (f : 'simple_expr) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match (__camlp4_1, __camlp4_0) with + | (UIDENT "SEP", UIDENT "FOLD1") -> + (sfoldsep _loc "FOLD1 SEP" "sfold1sep" f + e s sep : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "FOLD0" -> true + | _ -> false), + "UIDENT \"FOLD0\"")); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Sself; + Gram.Stoken + (((function | UIDENT "SEP" -> true | _ -> false), + "UIDENT \"SEP\"")); + Gram.Sself ], + (Gram.Action.mk + (fun (sep : 'symbol) (__camlp4_1 : Gram.Token.t) + (s : 'symbol) (e : 'simple_expr) + (f : 'simple_expr) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match (__camlp4_1, __camlp4_0) with + | (UIDENT "SEP", UIDENT "FOLD0") -> + (sfoldsep _loc "FOLD0 SEP" "sfold0sep" f + e s sep : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "FOLD1" -> true + | _ -> false), + "UIDENT \"FOLD1\"")); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (s : 'symbol) (e : 'simple_expr) + (f : 'simple_expr) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "FOLD1" -> + (sfold _loc "FOLD1" "sfold1" f e s : + 'symbol) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | UIDENT "FOLD0" -> true + | _ -> false), + "UIDENT \"FOLD0\"")); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (simple_expr : 'simple_expr Gram.Entry.t)); + Gram.Sself ], + (Gram.Action.mk + (fun (s : 'symbol) (e : 'simple_expr) + (f : 'simple_expr) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT "FOLD0" -> + (sfold _loc "FOLD0" "sfold0" f e s : + 'symbol) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (simple_expr : 'simple_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "("; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword ")" ], + (Gram.Action.mk + (fun _ (e : 'expr) _ (_loc : Gram.Loc.t) -> + (e : 'simple_expr)))); + ([ Gram.Snterm + (Gram.Entry.obj + (a_LIDENT : 'a_LIDENT Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'a_LIDENT) (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdLid (_loc, i)) : + 'simple_expr)))) ]) ])) + ())) + + let _ = + Options.add "-split_ext" (Arg.Set split_ext) + "Split EXTEND by functions to turn around a PowerPC problem." + + let _ = + Options.add "-split_gext" (Arg.Set split_ext) + "Old name for the option -split_ext." + + let _ = + Options.add "-meta_action" (Arg.Set meta_action) "Undocumented" + + end + + (* FIXME *) + module M = Register.OCamlSyntaxExtension(Id)(Make) + + end + +module M = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + * - Aleksey Nogin: extra features and bug fixes. + * - Christopher Conway: extra feature (-D=) + * - Jean-vincent Loddo: definitions inside IFs. + *) + module Id = + struct let name = "Camlp4MacroParser" + let version = Sys.ocaml_version + end + + (* +Added statements: + + At toplevel (structure item): + + DEFINE + DEFINE = + DEFINE () = + IFDEF THEN [ ELSE ] (END | ENDIF) + IFNDEF THEN [ ELSE ] (END | ENDIF) + INCLUDE + + At toplevel (signature item): + + DEFINE + IFDEF THEN [ ELSE ] (END | ENDIF) + IFNDEF THEN [ ELSE ] (END | ENDIF) + INCLUDE + + In expressions: + + IFDEF THEN [ ELSE ] (END | ENDIF) + IFNDEF THEN [ ELSE ] (END | ENDIF) + DEFINE = IN + __FILE__ + __LOCATION__ + + In patterns: + + IFDEF THEN ELSE (END | ENDIF) + IFNDEF THEN ELSE (END | ENDIF) + + As Camlp4 options: + + -D or -D=expr define with optional value + -U undefine it + -I add to the search path for INCLUDE'd files + + After having used a DEFINE followed by "= ", you + can use it in expressions *and* in patterns. If the expression defining + the macro cannot be used as a pattern, there is an error message if + it is used in a pattern. + + You can also define a local macro in an expression usigng the DEFINE ... IN form. + Note that local macros have lowercase names and can not take parameters. + + If a macro is defined to = NOTHING, and then used as an argument to a function, + this will be equivalent to function taking one less argument. Similarly, + passing NOTHING as an argument to a macro is equivalent to "erasing" the + corresponding parameter from the macro body. + + The toplevel statement INCLUDE can be used to include a + file containing macro definitions and also any other toplevel items. + The included files are looked up in directories passed in via the -I + option, falling back to the current directory. + + The expression __FILE__ returns the current compiled file name. + The expression __LOCATION__ returns the current location of itself. + +*) + open Camlp4 + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + type 'a item_or_def = + | SdStr of 'a + | SdDef of string * ((string list) * Ast.expr) option + | SdUnd of string + | SdITE of bool * ('a item_or_def) list * ('a item_or_def) list + | SdLazy of 'a Lazy.t + + let rec list_remove x = + function + | (y, _) :: l when y = x -> l + | d :: l -> d :: (list_remove x l) + | [] -> [] + + let defined = ref [] + + let is_defined i = List.mem_assoc i !defined + + let bad_patt _loc = + Loc.raise _loc + (Failure + "this macro cannot be used in a pattern (see its definition)") + + let substp _loc env = + let rec loop = + function + | Ast.ExApp (_, e1, e2) -> Ast.PaApp (_loc, loop e1, loop e2) + | Ast.ExNil _ -> Ast.PaNil _loc + | Ast.ExId (_, (Ast.IdLid (_, x))) -> + (try List.assoc x env + with | Not_found -> Ast.PaId (_loc, Ast.IdLid (_loc, x))) + | Ast.ExId (_, (Ast.IdUid (_, x))) -> + (try List.assoc x env + with | Not_found -> Ast.PaId (_loc, Ast.IdUid (_loc, x))) + | Ast.ExInt (_, x) -> Ast.PaInt (_loc, x) + | Ast.ExStr (_, s) -> Ast.PaStr (_loc, s) + | Ast.ExTup (_, x) -> Ast.PaTup (_loc, loop x) + | Ast.ExCom (_, x1, x2) -> Ast.PaCom (_loc, loop x1, loop x2) + | Ast.ExRec (_, bi, (Ast.ExNil _)) -> + let rec substbi = + (function + | Ast.RbSem (_, b1, b2) -> + Ast.PaSem (_loc, substbi b1, substbi b2) + | Ast.RbEq (_, i, e) -> Ast.PaEq (_loc, i, loop e) + | _ -> bad_patt _loc) + in Ast.PaRec (_loc, substbi bi) + | _ -> bad_patt _loc + in loop + + class reloc _loc = + object inherit Ast.map as super + method loc = fun _ -> _loc + end + + (* method _Loc_t _ = _loc; *) + class subst _loc env = + object inherit reloc _loc as super + + method expr = + function + | (Ast.ExId (_, (Ast.IdLid (_, x))) | + Ast.ExId (_, (Ast.IdUid (_, x))) + as e) -> + (try List.assoc x env with | Not_found -> super#expr e) + | e -> super#expr e + + method patt = + function + | (Ast.PaId (_, (Ast.IdLid (_, x))) | + Ast.PaId (_, (Ast.IdUid (_, x))) + as p) -> + (try substp _loc [] (List.assoc x env) + with | Not_found -> super#patt p) + | p -> super#patt p + + end + + let incorrect_number loc l1 l2 = + Loc.raise loc + (Failure + (Printf.sprintf "expected %d parameters; found %d" + (List.length l2) (List.length l1))) + + let define eo x = + ((match eo with + | Some (([], e)) -> + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> + true + | _ -> false), + "$UIDENT x")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT ((_)) -> + ((new reloc _loc)#expr e : 'expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (patt : 'patt Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> + true + | _ -> false), + "$UIDENT x")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT ((_)) -> + (let p = substp _loc [] e + in (new reloc _loc)#patt p : 'patt) + | _ -> assert false))) ]) ])) + ())) + | Some ((sl, e)) -> + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "apply")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> + true + | _ -> false), + "$UIDENT x")); + Gram.Sself ], + (Gram.Action.mk + (fun (param : 'expr) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT ((_)) -> + (let el = + (match param with + | Ast.ExTup (_, e) -> + Ast.list_of_expr e [] + | e -> [ e ]) + in + if + (List.length el) = + (List.length sl) + then + (let env = List.combine sl el + in (new subst _loc env)#expr e) + else incorrect_number _loc el sl : + 'expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (patt : 'patt Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> + true + | _ -> false), + "$UIDENT x")); + Gram.Sself ], + (Gram.Action.mk + (fun (param : 'patt) + (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | UIDENT ((_)) -> + (let pl = + (match param with + | Ast.PaTup (_, p) -> + Ast.list_of_patt p [] + | p -> [ p ]) + in + if + (List.length pl) = + (List.length sl) + then + (let env = List.combine sl pl in + let p = substp _loc env e + in (new reloc _loc)#patt p) + else incorrect_number _loc pl sl : + 'patt) + | _ -> assert false))) ]) ])) + ())) + | None -> ()); + defined := (x, eo) :: !defined) + + let undef x = + try + ((let eo = List.assoc x !defined + in + match eo with + | Some (([], _)) -> + (Gram.delete_rule expr + [ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> true + | _ -> false), + "$UIDENT x")) ]; + Gram.delete_rule patt + [ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> true + | _ -> false), + "$UIDENT x")) ]) + | Some ((_, _)) -> + (Gram.delete_rule expr + [ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> true + | _ -> false), + "$UIDENT x")); + Gram.Sself ]; + Gram.delete_rule patt + [ Gram.Stoken + (((function + | UIDENT camlp4_x when camlp4_x = x -> true + | _ -> false), + "$UIDENT x")); + Gram.Sself ]) + | None -> ()); + defined := list_remove x !defined) + with | Not_found -> () + + let parse_def s = + match Gram.parse_string expr (Loc.mk "") s with + | Ast.ExId (_, (Ast.IdUid (_, n))) -> define None n + | Ast.ExApp (_, + (Ast.ExApp (_, (Ast.ExId (_, (Ast.IdLid (_, "=")))), + (Ast.ExId (_, (Ast.IdUid (_, n)))))), + e) -> define (Some (([], e))) n + | _ -> invalid_arg s + + (* This is a list of directories to search for INCLUDE statements. *) + let include_dirs = ref [] + + (* Add something to the above, make sure it ends with a slash. *) + let add_include_dir str = + if str <> "" + then + (let str = + if (String.get str ((String.length str) - 1)) = '/' + then str + else str ^ "/" + in include_dirs := !include_dirs @ [ str ]) + else () + + let parse_include_file rule = + let dir_ok file dir = Sys.file_exists (dir ^ file) + in + fun file -> + let file = + try + (List.find (dir_ok file) (!include_dirs @ [ "./" ])) ^ file + with | Not_found -> file in + let ch = open_in file in + let st = Stream.of_channel ch + in Gram.parse rule (Loc.mk file) st + + let rec execute_macro nil cons = + function + | SdStr i -> i + | SdDef (x, eo) -> (define eo x; nil) + | SdUnd x -> (undef x; nil) + | SdITE (b, l1, l2) -> + execute_macro_list nil cons (if b then l1 else l2) + | SdLazy l -> Lazy.force l + and execute_macro_list nil cons = + function + | [] -> nil + | hd :: tl -> (* The evaluation order is important here *) + let il1 = execute_macro nil cons hd in + let il2 = execute_macro_list nil cons tl in cons il1 il2 + + (* Stack of conditionals. *) + let stack = Stack.create () + + (* Make an SdITE value by extracting the result of the test from the stack. *) + let make_SdITE_result st1 st2 = + let test = Stack.pop stack in SdITE (test, st1, st2) + + type branch = | Then | Else + + (* Execute macro only if it belongs to the currently active branch. *) + let execute_macro_if_active_branch _loc nil cons branch macro_def = + let test = Stack.top stack in + let item = + if (test && (branch = Then)) || ((not test) && (branch = Else)) + then execute_macro nil cons macro_def + else (* ignore the macro *) nil + in SdStr item + + let _ = + let _ = (expr : 'expr Gram.Entry.t) + and _ = (sig_item : 'sig_item Gram.Entry.t) + and _ = (str_item : 'str_item Gram.Entry.t) + and _ = (patt : 'patt Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let macro_def : 'macro_def Gram.Entry.t = + grammar_entry_create "macro_def" + and uident : 'uident Gram.Entry.t = grammar_entry_create "uident" + and opt_macro_value : 'opt_macro_value Gram.Entry.t = + grammar_entry_create "opt_macro_value" + and endif : 'endif Gram.Entry.t = grammar_entry_create "endif" + and sglist_else : 'sglist_else Gram.Entry.t = + grammar_entry_create "sglist_else" + and sglist_then : 'sglist_then Gram.Entry.t = + grammar_entry_create "sglist_then" + and smlist_else : 'smlist_else Gram.Entry.t = + grammar_entry_create "smlist_else" + and smlist_then : 'smlist_then Gram.Entry.t = + grammar_entry_create "smlist_then" + and else_expr : 'else_expr Gram.Entry.t = + grammar_entry_create "else_expr" + and else_macro_def_sig : 'else_macro_def_sig Gram.Entry.t = + grammar_entry_create "else_macro_def_sig" + and else_macro_def : 'else_macro_def Gram.Entry.t = + grammar_entry_create "else_macro_def" + and uident_eval_ifndef : 'uident_eval_ifndef Gram.Entry.t = + grammar_entry_create "uident_eval_ifndef" + and uident_eval_ifdef : 'uident_eval_ifdef Gram.Entry.t = + grammar_entry_create "uident_eval_ifdef" + and macro_def_sig : 'macro_def_sig Gram.Entry.t = + grammar_entry_create "macro_def_sig" + in + (Gram.extend (str_item : 'str_item Gram.Entry.t) + ((fun () -> + ((Some Camlp4.Sig.Grammar.First), + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (macro_def : 'macro_def Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'macro_def) (_loc : Gram.Loc.t) -> + (execute_macro (Ast.StNil _loc) + (fun a b -> Ast.StSem (_loc, a, b)) x : + 'str_item)))) ]) ])) + ()); + Gram.extend (sig_item : 'sig_item Gram.Entry.t) + ((fun () -> + ((Some Camlp4.Sig.Grammar.First), + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (macro_def_sig : + 'macro_def_sig Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'macro_def_sig) (_loc : Gram.Loc.t) -> + (execute_macro (Ast.SgNil _loc) + (fun a b -> Ast.SgSem (_loc, a, b)) x : + 'sig_item)))) ]) ])) + ()); + Gram.extend (macro_def : 'macro_def Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "INCLUDE"; + Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (fname : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + (let fname = Gram.Token.extract_string fname + in + SdLazy + (lazy + (parse_include_file str_items fname)) : + 'macro_def)))); + ([ Gram.Skeyword "IFNDEF"; + Gram.Snterm + (Gram.Entry.obj + (uident_eval_ifndef : + 'uident_eval_ifndef Gram.Entry.t)); + Gram.Skeyword "THEN"; + Gram.Snterm + (Gram.Entry.obj + (smlist_then : 'smlist_then Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (else_macro_def : + 'else_macro_def Gram.Entry.t)) ], + (Gram.Action.mk + (fun (st2 : 'else_macro_def) + (st1 : 'smlist_then) _ _ _ + (_loc : Gram.Loc.t) -> + (make_SdITE_result st1 st2 : 'macro_def)))); + ([ Gram.Skeyword "IFDEF"; + Gram.Snterm + (Gram.Entry.obj + (uident_eval_ifdef : + 'uident_eval_ifdef Gram.Entry.t)); + Gram.Skeyword "THEN"; + Gram.Snterm + (Gram.Entry.obj + (smlist_then : 'smlist_then Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (else_macro_def : + 'else_macro_def Gram.Entry.t)) ], + (Gram.Action.mk + (fun (st2 : 'else_macro_def) + (st1 : 'smlist_then) _ _ _ + (_loc : Gram.Loc.t) -> + (make_SdITE_result st1 st2 : 'macro_def)))); + ([ Gram.Skeyword "UNDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'uident) _ (_loc : Gram.Loc.t) -> + (SdUnd i : 'macro_def)))); + ([ Gram.Skeyword "DEFINE"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (opt_macro_value : + 'opt_macro_value Gram.Entry.t)) ], + (Gram.Action.mk + (fun (def : 'opt_macro_value) (i : 'uident) _ + (_loc : Gram.Loc.t) -> + (SdDef (i, def) : 'macro_def)))) ]) ])) + ()); + Gram.extend (macro_def_sig : 'macro_def_sig Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "INCLUDE"; + Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")) ], + (Gram.Action.mk + (fun (fname : Gram.Token.t) _ + (_loc : Gram.Loc.t) -> + (let fname = Gram.Token.extract_string fname + in + SdLazy + (lazy + (parse_include_file sig_items fname)) : + 'macro_def_sig)))); + ([ Gram.Skeyword "IFNDEF"; + Gram.Snterm + (Gram.Entry.obj + (uident_eval_ifndef : + 'uident_eval_ifndef Gram.Entry.t)); + Gram.Skeyword "THEN"; + Gram.Snterm + (Gram.Entry.obj + (sglist_then : 'sglist_then Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (else_macro_def_sig : + 'else_macro_def_sig Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sg2 : 'else_macro_def_sig) + (sg1 : 'sglist_then) _ _ _ + (_loc : Gram.Loc.t) -> + (make_SdITE_result sg1 sg2 : 'macro_def_sig)))); + ([ Gram.Skeyword "IFDEF"; + Gram.Snterm + (Gram.Entry.obj + (uident_eval_ifdef : + 'uident_eval_ifdef Gram.Entry.t)); + Gram.Skeyword "THEN"; + Gram.Snterm + (Gram.Entry.obj + (sglist_then : 'sglist_then Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (else_macro_def_sig : + 'else_macro_def_sig Gram.Entry.t)) ], + (Gram.Action.mk + (fun (sg2 : 'else_macro_def_sig) + (sg1 : 'sglist_then) _ _ _ + (_loc : Gram.Loc.t) -> + (make_SdITE_result sg1 sg2 : 'macro_def_sig)))); + ([ Gram.Skeyword "UNDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'uident) _ (_loc : Gram.Loc.t) -> + (SdUnd i : 'macro_def_sig)))); + ([ Gram.Skeyword "DEFINE"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'uident) _ (_loc : Gram.Loc.t) -> + (SdDef (i, None) : 'macro_def_sig)))) ]) ])) + ()); + Gram.extend + (uident_eval_ifdef : 'uident_eval_ifdef Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'uident) (_loc : Gram.Loc.t) -> + (Stack.push (is_defined i) stack : + 'uident_eval_ifdef)))) ]) ])) + ()); + Gram.extend + (uident_eval_ifndef : 'uident_eval_ifndef Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)) ], + (Gram.Action.mk + (fun (i : 'uident) (_loc : Gram.Loc.t) -> + (Stack.push (not (is_defined i)) stack : + 'uident_eval_ifndef)))) ]) ])) + ()); + Gram.extend (else_macro_def : 'else_macro_def Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + ([] : 'else_macro_def)))); + ([ Gram.Skeyword "ELSE"; + Gram.Snterm + (Gram.Entry.obj + (smlist_else : 'smlist_else Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (st : 'smlist_else) _ (_loc : Gram.Loc.t) + -> (st : 'else_macro_def)))) ]) ])) + ()); + Gram.extend + (else_macro_def_sig : 'else_macro_def_sig Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + ([] : 'else_macro_def_sig)))); + ([ Gram.Skeyword "ELSE"; + Gram.Snterm + (Gram.Entry.obj + (sglist_else : 'sglist_else Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (st : 'sglist_else) _ (_loc : Gram.Loc.t) + -> (st : 'else_macro_def_sig)))) ]) ])) + ()); + Gram.extend (else_expr : 'else_expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (Ast.ExId (_loc, Ast.IdUid (_loc, "()")) : + 'else_expr)))); + ([ Gram.Skeyword "ELSE"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (e : 'expr) _ (_loc : Gram.Loc.t) -> + (e : 'else_expr)))) ]) ])) + ()); + Gram.extend (smlist_then : 'smlist_then Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist1 + (Gram.srules smlist_then + [ ([ Gram.Snterm + (Gram.Entry.obj + (str_item : + 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (si : 'str_item) + (_loc : Gram.Loc.t) -> + (SdStr si : 'e__18)))); + ([ Gram.Snterm + (Gram.Entry.obj + (macro_def : + 'macro_def Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (d : 'macro_def) + (_loc : Gram.Loc.t) -> + (execute_macro_if_active_branch + _loc (Ast.StNil _loc) + (fun a b -> + Ast.StSem (_loc, a, b)) + Then d : + 'e__18)))) ]) ], + (Gram.Action.mk + (fun (sml : 'e__18 list) (_loc : Gram.Loc.t) -> + (sml : 'smlist_then)))) ]) ])) + ()); + Gram.extend (smlist_else : 'smlist_else Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist1 + (Gram.srules smlist_else + [ ([ Gram.Snterm + (Gram.Entry.obj + (str_item : + 'str_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (si : 'str_item) + (_loc : Gram.Loc.t) -> + (SdStr si : 'e__19)))); + ([ Gram.Snterm + (Gram.Entry.obj + (macro_def : + 'macro_def Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (d : 'macro_def) + (_loc : Gram.Loc.t) -> + (execute_macro_if_active_branch + _loc (Ast.StNil _loc) + (fun a b -> + Ast.StSem (_loc, a, b)) + Else d : + 'e__19)))) ]) ], + (Gram.Action.mk + (fun (sml : 'e__19 list) (_loc : Gram.Loc.t) -> + (sml : 'smlist_else)))) ]) ])) + ()); + Gram.extend (sglist_then : 'sglist_then Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist1 + (Gram.srules sglist_then + [ ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : + 'sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (si : 'sig_item) + (_loc : Gram.Loc.t) -> + (SdStr si : 'e__20)))); + ([ Gram.Snterm + (Gram.Entry.obj + (macro_def_sig : + 'macro_def_sig Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (d : 'macro_def_sig) + (_loc : Gram.Loc.t) -> + (execute_macro_if_active_branch + _loc (Ast.SgNil _loc) + (fun a b -> + Ast.SgSem (_loc, a, b)) + Then d : + 'e__20)))) ]) ], + (Gram.Action.mk + (fun (sgl : 'e__20 list) (_loc : Gram.Loc.t) -> + (sgl : 'sglist_then)))) ]) ])) + ()); + Gram.extend (sglist_else : 'sglist_else Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Slist1 + (Gram.srules sglist_else + [ ([ Gram.Snterm + (Gram.Entry.obj + (sig_item : + 'sig_item Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (si : 'sig_item) + (_loc : Gram.Loc.t) -> + (SdStr si : 'e__21)))); + ([ Gram.Snterm + (Gram.Entry.obj + (macro_def_sig : + 'macro_def_sig Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj + (semi : 'semi Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (d : 'macro_def_sig) + (_loc : Gram.Loc.t) -> + (execute_macro_if_active_branch + _loc (Ast.SgNil _loc) + (fun a b -> + Ast.SgSem (_loc, a, b)) + Else d : + 'e__21)))) ]) ], + (Gram.Action.mk + (fun (sgl : 'e__21 list) (_loc : Gram.Loc.t) -> + (sgl : 'sglist_else)))) ]) ])) + ()); + Gram.extend (endif : 'endif Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "ENDIF" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'endif)))); + ([ Gram.Skeyword "END" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> (() : 'endif)))) ]) ])) + ()); + Gram.extend (opt_macro_value : 'opt_macro_value Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([], + (Gram.Action.mk + (fun (_loc : Gram.Loc.t) -> + (None : 'opt_macro_value)))); + ([ Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (Some (([], e)) : 'opt_macro_value)))); + ([ Gram.Skeyword "("; + Gram.Slist1sep + (Gram.srules opt_macro_value + [ ([ Gram.Stoken + (((function + | LIDENT ((_)) -> true + | _ -> false), + "LIDENT _")) ], + (Gram.Action.mk + (fun (x : Gram.Token.t) + (_loc : Gram.Loc.t) -> + (let x = + Gram.Token.extract_string x + in x : 'e__22)))) ], + Gram.Skeyword ","); + Gram.Skeyword ")"; Gram.Skeyword "="; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ _ (pl : 'e__22 list) _ + (_loc : Gram.Loc.t) -> + (Some ((pl, e)) : 'opt_macro_value)))) ]) ])) + ()); + Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "top")), + [ (None, None, + [ ([ Gram.Skeyword "DEFINE"; + Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")); + Gram.Skeyword "="; Gram.Sself; + Gram.Skeyword "IN"; Gram.Sself ], + (Gram.Action.mk + (fun (body : 'expr) _ (def : 'expr) _ + (i : Gram.Token.t) _ (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i + in (new subst _loc [ (i, def) ])#expr body : + 'expr)))); + ([ Gram.Skeyword "IFNDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)); + Gram.Skeyword "THEN"; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (else_expr : 'else_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e2 : 'else_expr) (e1 : 'expr) _ + (i : 'uident) _ (_loc : Gram.Loc.t) -> + (if is_defined i then e2 else e1 : 'expr)))); + ([ Gram.Skeyword "IFDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)); + Gram.Skeyword "THEN"; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj + (else_expr : 'else_expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e2 : 'else_expr) (e1 : 'expr) _ + (i : 'uident) _ (_loc : Gram.Loc.t) -> + (if is_defined i then e1 else e2 : 'expr)))) ]) ])) + ()); + Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Stoken + (((function + | LIDENT "__LOCATION__" -> true + | _ -> false), + "LIDENT \"__LOCATION__\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT "__LOCATION__" -> + (let (a, b, c, d, e, f, g, h) = + Loc.to_tuple _loc + in + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "of_tuple"))), + Ast.ExTup (_loc, + Ast.ExCom (_loc, + Ast.ExStr (_loc, + Ast.safe_string_escaped a), + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExCom (_loc, + Ast.ExInt (_loc, + string_of_int b), + Ast.ExInt (_loc, + string_of_int c)), + Ast.ExInt (_loc, + string_of_int d)), + Ast.ExInt (_loc, + string_of_int e)), + Ast.ExInt (_loc, + string_of_int f)), + Ast.ExInt (_loc, + string_of_int g)), + if h + then + Ast.ExId (_loc, + Ast.IdUid (_loc, "True")) + else + Ast.ExId (_loc, + Ast.IdUid (_loc, "False")))))) : + 'expr) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | LIDENT "__FILE__" -> true + | _ -> false), + "LIDENT \"__FILE__\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT "__FILE__" -> + (Ast.ExStr (_loc, + Ast.safe_string_escaped + (Loc.file_name _loc)) : + 'expr) + | _ -> assert false))) ]) ])) + ()); + Gram.extend (patt : 'patt Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "IFNDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)); + Gram.Skeyword "THEN"; Gram.Sself; + Gram.Skeyword "ELSE"; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (p2 : 'patt) _ (p1 : 'patt) _ + (i : 'uident) _ (_loc : Gram.Loc.t) -> + (if is_defined i then p2 else p1 : 'patt)))); + ([ Gram.Skeyword "IFDEF"; + Gram.Snterm + (Gram.Entry.obj (uident : 'uident Gram.Entry.t)); + Gram.Skeyword "THEN"; Gram.Sself; + Gram.Skeyword "ELSE"; Gram.Sself; + Gram.Snterm + (Gram.Entry.obj (endif : 'endif Gram.Entry.t)) ], + (Gram.Action.mk + (fun _ (p2 : 'patt) _ (p1 : 'patt) _ + (i : 'uident) _ (_loc : Gram.Loc.t) -> + (if is_defined i then p1 else p2 : 'patt)))) ]) ])) + ()); + Gram.extend (uident : 'uident Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function | UIDENT ((_)) -> true | _ -> false), + "UIDENT _")) ], + (Gram.Action.mk + (fun (i : Gram.Token.t) (_loc : Gram.Loc.t) -> + (let i = Gram.Token.extract_string i in i : + 'uident)))) ]) ])) + ())) + + let _ = + Options.add "-D" (Arg.String parse_def) + " Define for IFDEF instruction." + + let _ = + Options.add "-U" (Arg.String undef) + " Undefine for IFDEF instruction." + + let _ = + Options.add "-I" (Arg.String add_include_dir) + " Add a directory to INCLUDE search path." + + end + + let _ = let module M = Register.OCamlSyntaxExtension(Id)(Make) in () + + module MakeNothing (AstFilters : Camlp4.Sig.AstFilters) = + struct + open AstFilters + + open Ast + + let remove_nothings = + function + | Ast.ExApp (_, e, (Ast.ExId (_, (Ast.IdUid (_, "NOTHING"))))) | + Ast.ExFun (_, + (Ast.McArr (_, (Ast.PaId (_, (Ast.IdUid (_, "NOTHING")))), + (Ast.ExNil _), e))) + -> e + | e -> e + + let _ = + register_str_item_filter (Ast.map_expr remove_nothings)#str_item + + end + + let _ = let module M = Camlp4.Register.AstFilter(Id)(MakeNothing) in () + + end + +module D = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Nicolas Pouillard: initial version + *) + module Id = + struct let name = "Camlp4DebugParser" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + module StringSet = Set.Make(String) + + let debug_mode = + try + let str = Sys.getenv "STATIC_CAMLP4_DEBUG" in + let rec loop acc i = + try + let pos = String.index_from str i ':' + in + loop (StringSet.add (String.sub str i (pos - i)) acc) + (pos + 1) + with + | Not_found -> + StringSet.add (String.sub str i ((String.length str) - i)) + acc in + let sections = loop StringSet.empty 0 + in + if StringSet.mem "*" sections + then (fun _ -> true) + else (fun x -> StringSet.mem x sections) + with | Not_found -> (fun _ -> false) + + let rec apply accu = + function + | [] -> accu + | x :: xs -> + let _loc = Ast.loc_of_expr x + in apply (Ast.ExApp (_loc, accu, x)) xs + + let mk_debug_mode _loc = + function + | None -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Debug"), + Ast.IdLid (_loc, "mode"))) + | Some m -> + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, m), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Debug"), + Ast.IdLid (_loc, "mode")))) + + let mk_debug _loc m fmt section args = + let call = + apply + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Debug"), + Ast.IdLid (_loc, "printf"))), + Ast.ExStr (_loc, section)), + Ast.ExStr (_loc, fmt))) + args + in + Ast.ExIfe (_loc, + Ast.ExApp (_loc, mk_debug_mode _loc m, + Ast.ExStr (_loc, section)), + call, Ast.ExId (_loc, Ast.IdUid (_loc, "()"))) + + let _ = + let _ = (expr : 'expr Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let end_or_in : 'end_or_in Gram.Entry.t = + grammar_entry_create "end_or_in" + and start_debug : 'start_debug Gram.Entry.t = + grammar_entry_create "start_debug" + in + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterm + (Gram.Entry.obj + (start_debug : 'start_debug Gram.Entry.t)); + Gram.Stoken + (((function | LIDENT ((_)) -> true | _ -> false), + "LIDENT _")); + Gram.Stoken + (((function | STRING ((_)) -> true | _ -> false), + "STRING _")); + Gram.Slist0 + (Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + ".")); + Gram.Snterm + (Gram.Entry.obj + (end_or_in : 'end_or_in Gram.Entry.t)) ], + (Gram.Action.mk + (fun (x : 'end_or_in) (args : 'expr list) + (fmt : Gram.Token.t) (section : Gram.Token.t) + (m : 'start_debug) (_loc : Gram.Loc.t) -> + (let fmt = Gram.Token.extract_string fmt in + let section = + Gram.Token.extract_string section + in + match (x, (debug_mode section)) with + | (None, false) -> + Ast.ExId (_loc, + Ast.IdUid (_loc, "()")) + | (Some e, false) -> e + | (None, _) -> + mk_debug _loc m fmt section args + | (Some e, _) -> + Ast.ExLet (_loc, Ast.BFalse, + Ast.BiEq (_loc, + Ast.PaId (_loc, + Ast.IdUid (_loc, "()")), + mk_debug _loc m fmt section args), + e) : + 'expr)))) ]) ])) + ()); + Gram.extend (end_or_in : 'end_or_in Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Skeyword "in"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (e : 'expr) _ (_loc : Gram.Loc.t) -> + (Some e : 'end_or_in)))); + ([ Gram.Skeyword "end" ], + (Gram.Action.mk + (fun _ (_loc : Gram.Loc.t) -> + (None : 'end_or_in)))) ]) ])) + ()); + Gram.extend (start_debug : 'start_debug Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Stoken + (((function + | LIDENT "camlp4_debug" -> true + | _ -> false), + "LIDENT \"camlp4_debug\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT "camlp4_debug" -> + (Some "Camlp4" : 'start_debug) + | _ -> assert false))); + ([ Gram.Stoken + (((function + | LIDENT "debug" -> true + | _ -> false), + "LIDENT \"debug\"")) ], + (Gram.Action.mk + (fun (__camlp4_0 : Gram.Token.t) + (_loc : Gram.Loc.t) -> + match __camlp4_0 with + | LIDENT "debug" -> (None : 'start_debug) + | _ -> assert false))) ]) ])) + ())) + + end + + let _ = let module M = Register.OCamlSyntaxExtension(Id)(Make) in () + + end + +module L = + struct + open Camlp4 + + (* -*- camlp4r -*- *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2007 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Nao Hirokawa: initial version + * - Nicolas Pouillard: revised syntax version + *) + module Id = + struct let name = "Camlp4ListComprenhsion" + let version = Sys.ocaml_version + end + + module Make (Syntax : Sig.Camlp4Syntax) = + struct + open Sig + + include Syntax + + let rec loop n = + function + | [] -> None + | [ (x, _) ] -> if n = 1 then Some x else None + | _ :: l -> loop (n - 1) l + + let stream_peek_nth n strm = loop n (Stream.npeek n strm) + + (* usual trick *) + let test_patt_lessminus = + Gram.Entry.of_parser "test_patt_lessminus" + (fun strm -> + let rec skip_patt n = + match stream_peek_nth n strm with + | Some (KEYWORD "<-") -> n + | Some (KEYWORD ("[" | "[<")) -> + skip_patt ((ignore_upto "]" (n + 1)) + 1) + | Some (KEYWORD "(") -> + skip_patt ((ignore_upto ")" (n + 1)) + 1) + | Some (KEYWORD "{") -> + skip_patt ((ignore_upto "}" (n + 1)) + 1) + | Some (KEYWORD ("as" | "::" | "," | "_")) | + Some (LIDENT _ | UIDENT _) -> skip_patt (n + 1) + | Some _ | None -> raise Stream.Failure + and ignore_upto end_kwd n = + match stream_peek_nth n strm with + | Some (KEYWORD prm) when prm = end_kwd -> n + | Some (KEYWORD ("[" | "[<")) -> + ignore_upto end_kwd ((ignore_upto "]" (n + 1)) + 1) + | Some (KEYWORD "(") -> + ignore_upto end_kwd ((ignore_upto ")" (n + 1)) + 1) + | Some (KEYWORD "{") -> + ignore_upto end_kwd ((ignore_upto "}" (n + 1)) + 1) + | Some _ -> ignore_upto end_kwd (n + 1) + | None -> raise Stream.Failure + in skip_patt 1) + + let map _loc p e l = + match (p, e) with + | (Ast.PaId (_, (Ast.IdLid (_, x))), + Ast.ExId (_, (Ast.IdLid (_, y)))) when x = y -> l + | _ -> + if Ast.is_irrefut_patt p + then + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "List"), + Ast.IdLid (_loc, "map"))), + Ast.ExFun (_loc, Ast.McArr (_loc, p, Ast.ExNil _loc, e))), + l) + else + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "List"), + Ast.IdLid (_loc, "fold_right"))), + Ast.ExFun (_loc, + Ast.McOr (_loc, + Ast.McArr (_loc, p, + Ast.ExId (_loc, Ast.IdUid (_loc, "True")), + Ast.ExApp (_loc, + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, "x")), + Ast.ExNil _loc, + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, "xs")), + Ast.ExNil _loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "::")), + Ast.ExId (_loc, + Ast.IdLid (_loc, "x"))), + Ast.ExId (_loc, + Ast.IdLid (_loc, "xs"))))))), + e)), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + Ast.ExFun (_loc, + Ast.McArr (_loc, + Ast.PaId (_loc, Ast.IdLid (_loc, "l")), + Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdLid (_loc, "l")))))))), + l), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) + + let filter _loc p b l = + if Ast.is_irrefut_patt p + then + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "List"), + Ast.IdLid (_loc, "filter"))), + Ast.ExFun (_loc, Ast.McArr (_loc, p, Ast.ExNil _loc, b))), + l) + else + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "List"), + Ast.IdLid (_loc, "filter"))), + Ast.ExFun (_loc, + Ast.McOr (_loc, + Ast.McArr (_loc, p, + Ast.ExId (_loc, Ast.IdUid (_loc, "True")), b), + Ast.McArr (_loc, Ast.PaAny _loc, Ast.ExNil _loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "False")))))), + l) + + let concat _loc l = + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "List"), + Ast.IdLid (_loc, "concat"))), + l) + + let rec compr _loc e = + function + | [ `gen ((p, l)) ] -> map _loc p e l + | `gen ((p, l)) :: `cond b :: items -> + compr _loc e ((`gen ((p, (filter _loc p b l)))) :: items) + | `gen ((p, l)) :: ((`gen ((_, _)) :: _ as is)) -> + concat _loc (map _loc p (compr _loc e is) l) + | _ -> raise Stream.Failure + + let _ = + Gram.delete_rule expr + [ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : 'sem_expr_for_list Gram.Entry.t)); + Gram.Skeyword "]" ] + + let is_revised = + try + (Gram.delete_rule expr + [ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : 'sem_expr_for_list Gram.Entry.t)); + Gram.Skeyword "::"; + Gram.Snterm (Gram.Entry.obj (expr : 'expr Gram.Entry.t)); + Gram.Skeyword "]" ]; + true) + with | Not_found -> false + + let comprehension_or_sem_expr_for_list = + Gram.Entry.mk "comprehension_or_sem_expr_for_list" + + let _ = + let _ = (expr : 'expr Gram.Entry.t) + and _ = + (comprehension_or_sem_expr_for_list : + 'comprehension_or_sem_expr_for_list Gram.Entry.t) in + let grammar_entry_create = Gram.Entry.mk in + let item : 'item Gram.Entry.t = grammar_entry_create "item" + in + (Gram.extend (expr : 'expr Gram.Entry.t) + ((fun () -> + ((Some (Camlp4.Sig.Grammar.Level "simple")), + [ (None, None, + [ ([ Gram.Skeyword "["; + Gram.Snterm + (Gram.Entry.obj + (comprehension_or_sem_expr_for_list : + 'comprehension_or_sem_expr_for_list Gram. + Entry.t)); + Gram.Skeyword "]" ], + (Gram.Action.mk + (fun _ (e : 'comprehension_or_sem_expr_for_list) + _ (_loc : Gram.Loc.t) -> (e : 'expr)))) ]) ])) + ()); + Gram.extend + (comprehension_or_sem_expr_for_list : + 'comprehension_or_sem_expr_for_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top") ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + e), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) : + 'comprehension_or_sem_expr_for_list)))); + ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top"); + Gram.Skeyword "|"; + Gram.Slist1sep + (Gram.Snterm + (Gram.Entry.obj (item : 'item Gram.Entry.t)), + Gram.Skeyword ";") ], + (Gram.Action.mk + (fun (l : 'item list) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (compr _loc e l : + 'comprehension_or_sem_expr_for_list)))); + ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top"); + Gram.Skeyword ";" ], + (Gram.Action.mk + (fun _ (e : 'expr) (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + e), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))) : + 'comprehension_or_sem_expr_for_list)))); + ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top"); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : + 'sem_expr_for_list Gram.Entry.t)) ], + (Gram.Action.mk + (fun (mk : 'sem_expr_for_list) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + e), + mk + (Ast.ExId (_loc, Ast.IdUid (_loc, "[]")))) : + 'comprehension_or_sem_expr_for_list)))) ]) ])) + ()); + Gram.extend (item : 'item Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top") ], + (Gram.Action.mk + (fun (e : 'expr) (_loc : Gram.Loc.t) -> + (`cond e : 'item)))); + ([ Gram.Snterm + (Gram.Entry.obj + (test_patt_lessminus : + 'test_patt_lessminus Gram.Entry.t)); + Gram.Snterm + (Gram.Entry.obj (patt : 'patt Gram.Entry.t)); + Gram.Skeyword "<-"; + Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top") ], + (Gram.Action.mk + (fun (e : 'expr) _ (p : 'patt) _ + (_loc : Gram.Loc.t) -> + (`gen ((p, e)) : 'item)))) ]) ])) + ())) + + let _ = + if is_revised + then + (let _ = (expr : 'expr Gram.Entry.t) + and _ = + (comprehension_or_sem_expr_for_list : + 'comprehension_or_sem_expr_for_list Gram.Entry.t) + in + Gram.extend + (comprehension_or_sem_expr_for_list : + 'comprehension_or_sem_expr_for_list Gram.Entry.t) + ((fun () -> + (None, + [ (None, None, + [ ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top"); + Gram.Skeyword "::"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (last : 'expr) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "::")), + e), + last) : + 'comprehension_or_sem_expr_for_list)))); + ([ Gram.Snterml + (Gram.Entry.obj (expr : 'expr Gram.Entry.t), + "top"); + Gram.Skeyword ";"; + Gram.Snterm + (Gram.Entry.obj + (sem_expr_for_list : + 'sem_expr_for_list Gram.Entry.t)); + Gram.Skeyword "::"; + Gram.Snterm + (Gram.Entry.obj (expr : 'expr Gram.Entry.t)) ], + (Gram.Action.mk + (fun (last : 'expr) _ + (mk : 'sem_expr_for_list) _ (e : 'expr) + (_loc : Gram.Loc.t) -> + (Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdUid (_loc, "::")), + e), + mk last) : + 'comprehension_or_sem_expr_for_list)))) ]) ])) + ())) + else () + + end + + let _ = let module M = Register.OCamlSyntaxExtension(Id)(Make) in () + + end + +module P = + struct + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Nicolas Pouillard: initial version + *) + let _ = Camlp4.Register.enable_dump_ocaml_ast_printer () + + end + +module B = + struct + (* camlp4r *) + (****************************************************************************) + (* *) + (* Objective Caml *) + (* *) + (* INRIA Rocquencourt *) + (* *) + (* Copyright 2006 Institut National de Recherche en Informatique et *) + (* en Automatique. All rights reserved. This file is distributed under *) + (* the terms of the GNU Library General Public License, with the special *) + (* exception on linking described in LICENSE at the top of the Objective *) + (* Caml source tree. *) + (* *) + (****************************************************************************) + (* Authors: + * - Daniel de Rauglaudre: initial version + * - Nicolas Pouillard: refactoring + *) + + open Camlp4 + + open PreCast.Syntax + + open PreCast + + open Format + + module CleanAst = Camlp4.Struct.CleanAst.Make(Ast) + + module SSet = Set.Make(String) + + let pa_r = "Camlp4OCamlRevisedParser" + + let pa_rr = "Camlp4OCamlReloadedParser" + + let pa_o = "Camlp4OCamlParser" + + let pa_rp = "Camlp4OCamlRevisedParserParser" + + let pa_op = "Camlp4OCamlParserParser" + + let pa_g = "Camlp4GrammarParser" + + let pa_m = "Camlp4MacroParser" + + let pa_qb = "Camlp4QuotationCommon" + + let pa_q = "Camlp4QuotationExpander" + + let pa_rq = "Camlp4OCamlRevisedQuotationExpander" + + let pa_oq = "Camlp4OCamlOriginalQuotationExpander" + + let pa_l = "Camlp4ListComprehension" + + open Register + + let dyn_loader = + ref (fun _ -> raise (Match_failure ("./camlp4/Camlp4Bin.ml", 45, 24))) + + let rcall_callback = ref (fun () -> ()) + + let loaded_modules = ref SSet.empty + + let add_to_loaded_modules name = + loaded_modules := SSet.add name !loaded_modules + + let (objext, libext) = + if DynLoader.is_native then (".cmxs", ".cmxs") else (".cmo", ".cma") + + let rewrite_and_load n x = + let dyn_loader = !dyn_loader () in + let find_in_path = DynLoader.find_in_path dyn_loader in + let real_load name = + (add_to_loaded_modules name; DynLoader.load dyn_loader name) in + let load = + List.iter + (fun n -> + if + (SSet.mem n !loaded_modules) || + (List.mem n !Register.loaded_modules) + then () + else + (add_to_loaded_modules n; + DynLoader.load dyn_loader (n ^ objext))) + in + ((match (n, (String.lowercase x)) with + | (("Parsers" | ""), + ("pa_r.cmo" | "r" | "ocamlr" | "ocamlrevised" | + "camlp4ocamlrevisedparser.cmo")) + -> load [ pa_r ] + | (("Parsers" | ""), + ("rr" | "reloaded" | "ocamlreloaded" | + "camlp4ocamlreloadedparser.cmo")) + -> load [ pa_rr ] + | (("Parsers" | ""), + ("pa_o.cmo" | "o" | "ocaml" | "camlp4ocamlparser.cmo")) -> + load [ pa_r; pa_o ] + | (("Parsers" | ""), + ("pa_rp.cmo" | "rp" | "rparser" | + "camlp4ocamlrevisedparserparser.cmo")) + -> load [ pa_r; pa_o; pa_rp ] + | (("Parsers" | ""), + ("pa_op.cmo" | "op" | "parser" | "camlp4ocamlparserparser.cmo")) + -> load [ pa_r; pa_o; pa_rp; pa_op ] + | (("Parsers" | ""), + ("pa_extend.cmo" | "pa_extend_m.cmo" | "g" | "grammar" | + "camlp4grammarparser.cmo")) + -> load [ pa_g ] + | (("Parsers" | ""), + ("pa_macro.cmo" | "m" | "macro" | "camlp4macroparser.cmo")) -> + load [ pa_m ] + | (("Parsers" | ""), ("q" | "camlp4quotationexpander.cmo")) -> + load [ pa_qb; pa_q ] + | (("Parsers" | ""), + ("q_mlast.cmo" | "rq" | + "camlp4ocamlrevisedquotationexpander.cmo")) + -> load [ pa_qb; pa_rq ] + | (("Parsers" | ""), + ("oq" | "camlp4ocamloriginalquotationexpander.cmo")) -> + load [ pa_r; pa_o; pa_qb; pa_oq ] + | (("Parsers" | ""), "rf") -> + load [ pa_r; pa_rp; pa_qb; pa_q; pa_g; pa_l; pa_m ] + | (("Parsers" | ""), "of") -> + load + [ pa_r; pa_o; pa_rp; pa_op; pa_qb; pa_rq; pa_g; pa_l; pa_m ] + | (("Parsers" | ""), ("comp" | "camlp4listcomprehension.cmo")) -> + load [ pa_l ] + | (("Filters" | ""), ("lift" | "camlp4astlifter.cmo")) -> + load [ "Camlp4AstLifter" ] + | (("Filters" | ""), ("exn" | "camlp4exceptiontracer.cmo")) -> + load [ "Camlp4ExceptionTracer" ] + | (("Filters" | ""), ("prof" | "camlp4profiler.cmo")) -> + load [ "Camlp4Profiler" ] + | (* map is now an alias of fold since fold handles map too *) + (("Filters" | ""), ("map" | "camlp4mapgenerator.cmo")) -> + load [ "Camlp4FoldGenerator" ] + | (("Filters" | ""), ("fold" | "camlp4foldgenerator.cmo")) -> + load [ "Camlp4FoldGenerator" ] + | (("Filters" | ""), ("meta" | "camlp4metagenerator.cmo")) -> + load [ "Camlp4MetaGenerator" ] + | (("Filters" | ""), ("trash" | "camlp4trashremover.cmo")) -> + load [ "Camlp4TrashRemover" ] + | (("Filters" | ""), ("striploc" | "camlp4locationstripper.cmo")) + -> load [ "Camlp4LocationStripper" ] + | (("Printers" | ""), + ("pr_r.cmo" | "r" | "ocamlr" | "camlp4ocamlrevisedprinter.cmo")) + -> Register.enable_ocamlr_printer () + | (("Printers" | ""), + ("pr_o.cmo" | "o" | "ocaml" | "camlp4ocamlprinter.cmo")) -> + Register.enable_ocaml_printer () + | (("Printers" | ""), + ("pr_dump.cmo" | "p" | "dumpocaml" | "camlp4ocamlastdumper.cmo")) + -> Register.enable_dump_ocaml_ast_printer () + | (("Printers" | ""), ("d" | "dumpcamlp4" | "camlp4astdumper.cmo")) + -> Register.enable_dump_camlp4_ast_printer () + | (("Printers" | ""), ("a" | "auto" | "camlp4autoprinter.cmo")) -> + load [ "Camlp4AutoPrinter" ] + | _ -> + let y = "Camlp4" ^ (n ^ ("/" ^ (x ^ objext))) + in real_load (try find_in_path y with | Not_found -> x)); + !rcall_callback ()) + + let print_warning = eprintf "%a:\n%s@." Loc.print + + let rec parse_file dyn_loader name pa getdir = + let directive_handler = + Some + (fun ast -> + match getdir ast with + | Some x -> + (match x with + | (_, "load", s) -> (rewrite_and_load "" s; None) + | (_, "directory", s) -> + (DynLoader.include_dir dyn_loader s; None) + | (_, "use", s) -> Some (parse_file dyn_loader s pa getdir) + | (_, "default_quotation", s) -> + (Quotation.default := s; None) + | (loc, _, _) -> + Loc.raise loc (Stream.Error "bad directive")) + | None -> None) in + let loc = Loc.mk name + in + (current_warning := print_warning; + let ic = if name = "-" then stdin else open_in_bin name in + let cs = Stream.of_channel ic in + let clear () = if name = "-" then () else close_in ic in + let phr = + try pa ?directive_handler loc cs with | x -> (clear (); raise x) + in (clear (); phr)) + + let output_file = ref None + + let process dyn_loader name pa pr clean fold_filters getdir = + let ast = parse_file dyn_loader name pa getdir in + let ast = fold_filters (fun t filter -> filter t) ast in + let ast = clean ast + in pr ?input_file: (Some name) ?output_file: !output_file ast + + let gind = + function + | Ast.SgDir (loc, n, (Ast.ExStr (_, s))) -> Some ((loc, n, s)) + | _ -> None + + let gimd = + function + | Ast.StDir (loc, n, (Ast.ExStr (_, s))) -> Some ((loc, n, s)) + | _ -> None + + let process_intf dyn_loader name = + process dyn_loader name CurrentParser.parse_interf CurrentPrinter. + print_interf (new CleanAst.clean_ast)#sig_item AstFilters. + fold_interf_filters gind + + let process_impl dyn_loader name = + process dyn_loader name CurrentParser.parse_implem CurrentPrinter. + print_implem (new CleanAst.clean_ast)#str_item AstFilters. + fold_implem_filters gimd + + let just_print_the_version () = + (printf "%s@." Camlp4_config.version; exit 0) + + let print_version () = + (eprintf "Camlp4 version %s@." Camlp4_config.version; exit 0) + + let print_stdlib () = + (printf "%s@." Camlp4_config.camlp4_standard_library; exit 0) + + let usage ini_sl ext_sl = + (eprintf + "\ +Usage: camlp4 [load-options] [--] [other-options] +Options: +.ml Parse this implementation file +.mli Parse this interface file +.%s Load this module inside the Camlp4 core@." + (if DynLoader.is_native then "cmx " else "(cmo|cma)"); + Options.print_usage_list ini_sl; + (* loop (ini_sl @ ext_sl) where rec loop = + fun + [ [(y, _, _) :: _] when y = "-help" -> () + | [_ :: sl] -> loop sl + | [] -> eprintf " -help Display this list of options.@." ]; *) + if ext_sl <> [] + then + (eprintf "Options added by loaded object files:@."; + Options.print_usage_list ext_sl) + else ()) + + let warn_noassert () = + eprintf + "\ +camlp4 warning: option -noassert is obsolete +You should give the -noassert option to the ocaml compiler instead.@." + + type file_kind = + | Intf of string + | Impl of string + | Str of string + | ModuleImpl of string + | IncludeDir of string + + let search_stdlib = ref true + + let print_loaded_modules = ref false + + let (task, do_task) = + let t = ref None in + let task f x = + let () = Camlp4_config.current_input_file := x + in + t := + Some + (if !t = None then (fun _ -> f x) else (fun usage -> usage ())) in + let do_task usage = match !t with | Some f -> f usage | None -> () + in (task, do_task) + + let input_file x = + let dyn_loader = !dyn_loader () + in + (!rcall_callback (); + (match x with + | Intf file_name -> task (process_intf dyn_loader) file_name + | Impl file_name -> task (process_impl dyn_loader) file_name + | Str s -> + let (f, o) = Filename.open_temp_file "from_string" ".ml" + in + (output_string o s; + close_out o; + task (process_impl dyn_loader) f; + at_exit (fun () -> Sys.remove f)) + | ModuleImpl file_name -> rewrite_and_load "" file_name + | IncludeDir dir -> DynLoader.include_dir dyn_loader dir); + !rcall_callback ()) + + let initial_spec_list = + [ ("-I", (Arg.String (fun x -> input_file (IncludeDir x))), + " Add directory in search patch for object files."); + ("-where", (Arg.Unit print_stdlib), + "Print camlp4 library directory and exit."); + ("-nolib", (Arg.Clear search_stdlib), + "No automatic search for object files in library directory."); + ("-intf", (Arg.String (fun x -> input_file (Intf x))), + " Parse as an interface, whatever its extension."); + ("-impl", (Arg.String (fun x -> input_file (Impl x))), + " Parse as an implementation, whatever its extension."); + ("-str", (Arg.String (fun x -> input_file (Str x))), + " Parse as an implementation."); + ("-unsafe", (Arg.Set Camlp4_config.unsafe), + "Generate unsafe accesses to array and strings."); + ("-noassert", (Arg.Unit warn_noassert), + "Obsolete, do not use this option."); + ("-verbose", (Arg.Set Camlp4_config.verbose), + "More verbose in parsing errors."); + ("-loc", (Arg.Set_string Loc.name), + (" Name of the location variable (default: " ^ + (!Loc.name ^ ")."))); + ("-QD", (Arg.String (fun x -> Quotation.dump_file := Some x)), + " Dump quotation expander result in case of syntax error."); + ("-o", (Arg.String (fun x -> output_file := Some x)), + " Output on instead of standard output."); + ("-v", (Arg.Unit print_version), "Print Camlp4 version and exit."); + ("-version", (Arg.Unit just_print_the_version), + "Print Camlp4 version number and exit."); + ("-no_quot", (Arg.Clear Camlp4_config.quotations), + "Don't parse quotations, allowing to use, e.g. \"<:>\" as token."); + ("-loaded-modules", (Arg.Set print_loaded_modules), + "Print the list of loaded modules."); + ("-parser", (Arg.String (rewrite_and_load "Parsers")), + " Load the parser Camlp4Parsers/.cmo"); + ("-printer", (Arg.String (rewrite_and_load "Printers")), + " Load the printer Camlp4Printers/.cmo"); + ("-filter", (Arg.String (rewrite_and_load "Filters")), + " Load the filter Camlp4Filters/.cmo"); + ("-ignore", (Arg.String ignore), "ignore the next argument"); + ("--", (Arg.Unit ignore), "Deprecated, does nothing") ] + + let _ = Options.init initial_spec_list + + let anon_fun name = + input_file + (if Filename.check_suffix name ".mli" + then Intf name + else + if Filename.check_suffix name ".ml" + then Impl name + else + if Filename.check_suffix name objext + then ModuleImpl name + else + if Filename.check_suffix name libext + then ModuleImpl name + else raise (Arg.Bad ("don't know what to do with " ^ name))) + + let main argv = + let usage () = + (usage initial_spec_list (Options.ext_spec_list ()); exit 0) + in + try + let dynloader = + DynLoader.mk ~ocaml_stdlib: !search_stdlib + ~camlp4_stdlib: !search_stdlib () + in + (dyn_loader := (fun () -> dynloader); + let call_callback () = + Register.iter_and_take_callbacks + (fun (name, module_callback) -> + let () = add_to_loaded_modules name in module_callback ()) + in + (call_callback (); + rcall_callback := call_callback; + (match Options.parse anon_fun argv with + | [] -> () + | ("-help" | "--help" | "-h" | "-?") :: _ -> usage () + | s :: _ -> + (eprintf "%s: unknown or misused option\n" s; + eprintf "Use option -help for usage@."; + exit 2)); + do_task usage; + call_callback (); + if !print_loaded_modules + then SSet.iter (eprintf "%s@.") !loaded_modules + else ())) + with + | Arg.Bad s -> + (eprintf "Error: %s\n" s; + eprintf "Use option -help for usage@."; + exit 2) + | Arg.Help _ -> usage () + | exc -> (eprintf "@[%a@]@." ErrorHandler.print exc; exit 2) + + let _ = main Sys.argv + + end + + diff --git a/camlp4/boot/camlp4boot.ml4 b/camlp4/boot/camlp4boot.ml4 new file mode 100644 index 0000000..4c4c46d --- /dev/null +++ b/camlp4/boot/camlp4boot.ml4 @@ -0,0 +1,10 @@ +module R = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml"; end; +module Camlp4QuotationCommon = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4QuotationCommon.ml"; end; +module Q = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4QuotationExpander.ml"; end; +module Rp = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4OCamlRevisedParserParser.ml"; end; +module G = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4GrammarParser.ml"; end; +module M = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4MacroParser.ml"; end; +module D = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4DebugParser.ml"; end; +module L = struct INCLUDE "camlp4/Camlp4Parsers/Camlp4ListComprehension.ml"; end; +module P = struct INCLUDE "camlp4/Camlp4Printers/Camlp4OCamlAstDumper.ml"; end; +module B = struct INCLUDE "camlp4/Camlp4Bin.ml"; end; diff --git a/camlp4/build/.cvsignore b/camlp4/build/.cvsignore new file mode 100644 index 0000000..81edfb4 --- /dev/null +++ b/camlp4/build/.cvsignore @@ -0,0 +1,7 @@ +camlp4_config.ml +linenum.mli +linenum.mll +location.ml +location.mli +terminfo.ml +terminfo.mli diff --git a/camlp4/camlp4.odocl b/camlp4/camlp4.odocl new file mode 100644 index 0000000..715f15e --- /dev/null +++ b/camlp4/camlp4.odocl @@ -0,0 +1 @@ +Camlp4/Sig diff --git a/camlp4/camlp4fulllib.mllib b/camlp4/camlp4fulllib.mllib new file mode 100644 index 0000000..c7073c2 --- /dev/null +++ b/camlp4/camlp4fulllib.mllib @@ -0,0 +1,35 @@ +Camlp4 +Camlp4_import +Camlp4_config + +Camlp4Parsers/Camlp4AstLoader +Camlp4Parsers/Camlp4DebugParser +Camlp4Parsers/Camlp4GrammarParser +Camlp4Parsers/Camlp4ListComprehension +Camlp4Parsers/Camlp4MacroParser +Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander +Camlp4Parsers/Camlp4OCamlParser +Camlp4Parsers/Camlp4OCamlParserParser +Camlp4Parsers/Camlp4OCamlRevisedParser +Camlp4Parsers/Camlp4OCamlRevisedParserParser +Camlp4Parsers/Camlp4OCamlRevisedQuotationExpander +Camlp4Parsers/Camlp4QuotationCommon +Camlp4Parsers/Camlp4QuotationExpander + +Camlp4Printers/Camlp4AstDumper +Camlp4Printers/Camlp4AutoPrinter +Camlp4Printers/Camlp4NullDumper +Camlp4Printers/Camlp4OCamlAstDumper +Camlp4Printers/Camlp4OCamlPrinter +Camlp4Printers/Camlp4OCamlRevisedPrinter + +Camlp4Filters/Camlp4AstLifter +Camlp4Filters/Camlp4ExceptionTracer +Camlp4Filters/Camlp4FoldGenerator +Camlp4Filters/Camlp4LocationStripper +Camlp4Filters/Camlp4MapGenerator +Camlp4Filters/Camlp4MetaGenerator +Camlp4Filters/Camlp4Profiler +Camlp4Filters/Camlp4TrashRemover + +Camlp4Top diff --git a/camlp4/camlp4lib.mllib b/camlp4/camlp4lib.mllib new file mode 100644 index 0000000..08dc97f --- /dev/null +++ b/camlp4/camlp4lib.mllib @@ -0,0 +1,3 @@ +Camlp4 +Camlp4_import +Camlp4_config diff --git a/camlp4/camlp4prof.ml b/camlp4/camlp4prof.ml new file mode 100644 index 0000000..7e9df17 --- /dev/null +++ b/camlp4/camlp4prof.ml @@ -0,0 +1,24 @@ +module Debug = struct value mode _ = False; end; + +value count = + let h = Hashtbl.create 1007 in + let () = at_exit (fun () -> + let assoc = Hashtbl.fold (fun k v a -> [ (k, v.val) :: a ]) h [] in + let out = open_out "camlp4_profiler.out" in + let () = Marshal.to_channel out assoc [] in + close_out out) in + fun s -> + try incr (Hashtbl.find h s) + with [ Not_found -> Hashtbl.add h s (ref 1) ]; + +value load = Marshal.from_channel; + +value main () = + + let profile = List.sort (fun (_, v1) (_, v2) -> compare v1 v2) (load stdin) in + + List.iter + (fun (k, v) -> Format.printf "%-75s: %d@." k v) + profile; + +if Sys.argv.(0) = "camlp4prof" then main () else (); diff --git a/camlp4/camlp4prof.mli b/camlp4/camlp4prof.mli new file mode 100644 index 0000000..0703ac0 --- /dev/null +++ b/camlp4/camlp4prof.mli @@ -0,0 +1,3 @@ +value count : string -> unit; + +value load : in_channel -> list (string * int); diff --git a/camlp4/examples/_tags b/camlp4/examples/_tags new file mode 100644 index 0000000..19b2d70 --- /dev/null +++ b/camlp4/examples/_tags @@ -0,0 +1,19 @@ +true: warn_A, warn_e +<{apply_operator,type_quotation,global_handler,expression_closure{,_filter}}.ml> or : camlp4rf, use_camlp4 +"lambda_quot.ml": camlp4rf, use_camlp4_full +<{fancy_,}lambda_{quot,quot_{expr,patt},parser}.ml>: camlp4of, use_camlp4_full +"macros.ml" or or "gen_match_case.ml": camlp4of, use_camlp4 +"test_macros.ml": pp(camlp4of ./macros.cmo) +"lambda_test.ml": pp(camlp4of ./lambda_quot_o.cmo) +"fancy_lambda_quot_test.ml": use_camlp4, pp(camlp4of ./fancy_lambda_quot.cmo) +: camlp4of, use_camlp4_full, use_dynlink +"test_type_quotation.ml": pp(camlp4of ./type_quotation.cmo) +"apply_operator_test.ml": pp(camlp4o ./apply_operator.cmo) +"expression_closure_test.ml": pp(camlp4o ./expression_closure_filter.cmo) +"gen_type_N.ml": camlp4orf, use_camlp4 +"syb_fold.ml": pp(camlp4o -filter fold), use_camlp4 +"syb_map.ml": pp(camlp4o -filter map), use_camlp4 +"ex_str.ml": camlp4of, use_camlp4, use_camlp4_full +"ex_str_test.ml": pp(camlp4o ./ex_str.cmo) +"poly_by_default.ml": camlp4of, use_camlp4 +"poly_by_default_test.ml": pp(camlp4of ./poly_by_default.cmo) diff --git a/camlp4/examples/all.itarget b/camlp4/examples/all.itarget new file mode 100644 index 0000000..d8384ba --- /dev/null +++ b/camlp4/examples/all.itarget @@ -0,0 +1,11 @@ +apply_operator.cmo +type_quotation.cmo +lambda_quot.cmo +lambda_quot_o.cmo +macros.cmo +parse_files.byte +parse_files.native +arith.cmo +expression_closure.cmo +expression_closure_filter.cmo +global_handler.cmo diff --git a/camlp4/examples/apply_operator.ml b/camlp4/examples/apply_operator.ml new file mode 100644 index 0000000..35b17e5 --- /dev/null +++ b/camlp4/examples/apply_operator.ml @@ -0,0 +1,6 @@ +open Camlp4.PreCast; +AstFilters.register_str_item_filter + (Ast.map_expr + (fun + [ <:expr@loc< $e1$ & $e2$ >> -> <:expr@loc< $e1$ $e2$ >> + | e -> e ]))#str_item; diff --git a/camlp4/examples/apply_operator_test.ml b/camlp4/examples/apply_operator_test.ml new file mode 100644 index 0000000..07ca329 --- /dev/null +++ b/camlp4/examples/apply_operator_test.ml @@ -0,0 +1,3 @@ +let ( & ) = ();; (* To force it to be inlined. If not it's not well typed. *) + +fun f g h x -> f& g& h x diff --git a/camlp4/examples/arith.ml b/camlp4/examples/arith.ml new file mode 100644 index 0000000..ff7ab4f --- /dev/null +++ b/camlp4/examples/arith.ml @@ -0,0 +1,49 @@ +(* Please keep me in sync with brion.inria.fr/gallium/index.php/Arithmetic_Example *) + + open Camlp4.PreCast;; + module ArithGram = MakeGram(Lexer);; + + type t = Local of string * t * t + | Binop of t * (int -> int -> int) * t + | Int of int + | Var of string;; + + let expression = ArithGram.Entry.mk "expression";; + + EXTEND ArithGram + GLOBAL: expression; + + expression: (* A grammar entry for expressions *) + [ "top" + [ "let"; `LIDENT s; "="; e1 = SELF; "in"; e2 = SELF -> Local(s,e1,e2) ] + | "plus" + [ e1 = SELF; "+"; e2 = SELF -> Binop(e1, ( + ), e2) + | e1 = SELF; "-"; e2 = SELF -> Binop(e1, ( - ), e2) ] + | "times" + [ e1 = SELF; "*"; e2 = SELF -> Binop(e1, ( * ), e2) + | e1 = SELF; "/"; e2 = SELF -> Binop(e1, ( / ), e2) ] + | "simple" + [ `INT(i, _) -> Int(i) + | `LIDENT s -> Var(s) + | "("; e = expression; ")" -> e ] + ]; + + END;; + + let parse_arith s = + ArithGram.parse_string expression (Loc.mk "") s;; + + let rec eval env = + function + | Local(x, e1, e2) -> + let v1 = eval env e1 in + eval ((x, v1) :: env) e2 + | Binop(e1, op, e2) -> + op (eval env e1) (eval env e2) + | Int(i) -> i + | Var(x) -> List.assoc x env;; + + let calc s = + Format.printf "%s ==> %d@." s (eval [] (parse_arith s));; + + calc "42 * let x = 21 in x + x";; diff --git a/camlp4/examples/debug_extension.ml b/camlp4/examples/debug_extension.ml new file mode 100644 index 0000000..21696e4 --- /dev/null +++ b/camlp4/examples/debug_extension.ml @@ -0,0 +1,37 @@ +(* + * No debugging code at all: + * $ camlp4o -parser Camlp4DebugParser debug_extension.ml + * true + * Debugging code for lexing: + * $ STATIC_CAMLP4_DEBUG='lexing' camlp4o -parser Camlp4DebugParser debug_extension.ml + * let () = + * if Camlp4.Debug.mode "lexing" + * then Debug.printf "lexing" "TOKEN: Int %d" (2 * 21) + * else () + * in true + * + * Debugging code for lexing and parsing: + * $ STATIC_CAMLP4_DEBUG='lexing:parsing' camlp4o -parser Camlp4DebugParser debug_extension.ml + * let () = + * if Camlp4.Debug.mode "lexing" + * then Debug.printf "lexing" "TOKEN: Int %d" (2 * 21) + * else () in + * let () = + * if Camlp4.Debug.mode "parsing" + * then Debug.printf "parsing" "RULE: ..." + * else () + * in true + * + * Debugging code for any section: + * $ STATIC_CAMLP4_DEBUG='*' camlp4o -parser Camlp4DebugParser debug_extension.ml + * ... same output as above ... + * + * When you program is compiled you can use the CAMLP4_DEBUG variable to + * activate some debugging sections. + * + * CAMLP4_DEBUG_FILE manage where messages goes (default is stderr). + *) + +camlp4_debug lexing "TOKEN: Int %d" (2 * 21) in +camlp4_debug parsing "RULE: ..." in +true diff --git a/camlp4/examples/ex_str.ml b/camlp4/examples/ex_str.ml new file mode 100644 index 0000000..ac9513b --- /dev/null +++ b/camlp4/examples/ex_str.ml @@ -0,0 +1,22 @@ +open Camlp4.PreCast;; +module Caml = + Camlp4OCamlParser.Make + (Camlp4OCamlRevisedParser.Make + (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));; + +let quotexpander str = + "[1; 2; 3]" (* ... do some real code on str *) + +let patt_quotexpander loc _loc_name_opt str = + Gram.parse_string Caml.patt loc (quotexpander str) + +let expr_quotexpander loc _loc_name_opt str = + Gram.parse_string Caml.expr loc (quotexpander str) + +let str_item_quotexpander loc loc_name_opt str = + <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >> + +let () = + Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander; + Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag str_item_quotexpander; + Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander diff --git a/camlp4/examples/ex_str_test.ml b/camlp4/examples/ex_str_test.ml new file mode 100644 index 0000000..49a696f --- /dev/null +++ b/camlp4/examples/ex_str_test.ml @@ -0,0 +1 @@ +function <> -> <> diff --git a/camlp4/examples/expression_closure.ml b/camlp4/examples/expression_closure.ml new file mode 100644 index 0000000..58f1544 --- /dev/null +++ b/camlp4/examples/expression_closure.ml @@ -0,0 +1,24 @@ +#default_quotation "expr"; + +open Camlp4.PreCast; +open Format; + +module FV = Camlp4.Struct.FreeVars.Make Ast; +module PP = Camlp4.Printers.OCaml.Make Syntax; +module S = FV.S; + +value _loc = Loc.ghost; + +value pervasives = + let list = + [ "+"; "-"; "/"; "*" (* ... *) ] + in List.fold_right S.add list S.empty; + +value f e = + let fv = FV.free_vars pervasives e in + S.fold (fun x acc -> << fun ~ $x$ -> $acc$ >>) fv e; + +value print_expr = (new PP.printer ())#expr; + +printf "%a@." print_expr (f <>); + diff --git a/camlp4/examples/expression_closure_filter.ml b/camlp4/examples/expression_closure_filter.ml new file mode 100644 index 0000000..fb1fbe0 --- /dev/null +++ b/camlp4/examples/expression_closure_filter.ml @@ -0,0 +1,50 @@ +(* camlp4r *) +#default_quotation "expr"; + +open Camlp4.PreCast; +open Format; + +module FV = Camlp4.Struct.FreeVars.Make Ast; +module S = FV.S; + +value _loc = Loc.ghost; + +value pervasives = + let list = + [ "+"; "-"; "/"; "*" (* ... *) ] + in List.fold_right S.add list S.empty; + +value collect_free_vars_sets = + object (self) + inherit FV.fold_free_vars [S.t] S.add ~env_init:pervasives S.empty as super; + value free_sets = []; + method set_free free = {< free = free >}; + method expr = + fun + [ << close_expr $e$ >> -> (self#expr e)#add_current_free#set_free free + | e -> super#expr e ]; + method add_current_free = {< free_sets = [ free :: free_sets ] >}; + method free_sets = free_sets; + end; + +value apply_close_expr next_free_set = + object (self) + inherit Ast.map as super; + method expr = + fun + [ << close_expr $e$ >> -> + let e = self#expr e in + let fv = next_free_set () in + S.fold (fun x acc -> << fun ~ $x$ -> $acc$ >>) fv e + | e -> super#expr e ]; + end; + +value f st = + let fv_sets = ref (collect_free_vars_sets#str_item st)#free_sets in + let next_free_set () = + match fv_sets.val with + [ [] -> assert False + | [x::xs] -> let () = fv_sets.val := xs in x ] + in (apply_close_expr next_free_set)#str_item st; + +AstFilters.register_str_item_filter f; diff --git a/camlp4/examples/expression_closure_test.ml b/camlp4/examples/expression_closure_test.ml new file mode 100644 index 0000000..28747ce --- /dev/null +++ b/camlp4/examples/expression_closure_test.ml @@ -0,0 +1,14 @@ +(* x and y are free *) +close_expr(x y);; + +(* bind x *) +let x a = a + 42;; + +(* y is free *) +close_expr(x y);; + +(* bind y locally so the expr is closed *) +close_expr(let y = x 2 in x y);; + +(* bind y locally but outside, z is free *) +let y = x 2 in close_expr(x (z y));; diff --git a/camlp4/examples/fancy_lambda_quot.ml b/camlp4/examples/fancy_lambda_quot.ml new file mode 100644 index 0000000..be21fa2 --- /dev/null +++ b/camlp4/examples/fancy_lambda_quot.ml @@ -0,0 +1,159 @@ +(* module LambdaSyntax = struct + module Loc = Camlp4.PreCast.Loc + type 'a antiquotable = + | Val of Loc.t * 'a + | Ant of Loc.t * string + type term' = + | Lam of var * term + | App of term * term + | Var of var + | Int of int antiquotable + |+ Why you don't want an antiquotation case here: + * Basically it seems natural that since an antiquotation of expression + * can be at any expression place. One can be a + * .... in fact not I not against that... + | Anti of Loc.t * string + +| + and term = term' antiquotable + and var = string antiquotable +end *) +module Antiquotable = struct + module Loc = Camlp4.PreCast.Loc + type 'a t = + | Val of Loc.t * 'a + | Ant of Loc.t * string +end +module Identity_type_functor = struct + type 'a t = 'a +end +module MakeLambdaSyntax(Node : sig type 'a t end) = struct + type term' = + | Lam of var * term + | App of term * term + | Var of var + | Int of num + and term = term' Node.t + and num = int Node.t + and var = string Node.t +end +module AntiquotableLambdaSyntax = MakeLambdaSyntax(Antiquotable);; +module LambdaSyntax = MakeLambdaSyntax(Identity_type_functor);; +module LambdaParser = struct + open Antiquotable;; + open AntiquotableLambdaSyntax;; + open Camlp4.PreCast;; + + module LambdaGram = MakeGram(Lexer);; + + let term = LambdaGram.Entry.mk "term";; + let term_eoi = LambdaGram.Entry.mk "lambda term quotation";; + + Camlp4_config.antiquotations := true;; + + let mkLam _loc v t = Val(_loc, Lam(v, t));; + let mkApp _loc f x = Val(_loc, App(f, x));; + let mkVar _loc x = Val(_loc, Var(x));; + let mkInt _loc v = Val(_loc, Int(v));; + + EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> mkLam _loc v t ] + | "app" + [ t1 = SELF; t2 = SELF -> mkApp _loc t1 t2 ] + | "simple" + [ `ANTIQUOT((""|"term"), a) -> Ant(_loc, a) + | i = int -> mkInt _loc i + | v = var -> mkVar _loc v + | "("; t = term; ")" -> t ] + ]; + var: + [[ v = LIDENT -> Val(_loc, v) + | `ANTIQUOT((""|"var"), a) -> Ant(_loc, a) + ]]; + int: + [[ `INT(i, _) -> Val(_loc, i) + | `ANTIQUOT((""|"int"), a) -> Ant(_loc, a) + ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; + END;; + + let parse_string = LambdaGram.parse_string term_eoi +end +module LambdaLifter = struct + open Antiquotable;; + open AntiquotableLambdaSyntax;; + module CamlSyntax = + Camlp4OCamlParser.Make( + Camlp4OCamlRevisedParser.Make( + Camlp4.PreCast.Syntax + ) + );; + module Ast = Camlp4.PreCast.Ast + let expr_of_string = CamlSyntax.Gram.parse_string CamlSyntax.expr_eoi;; + let patt_of_string = CamlSyntax.Gram.parse_string CamlSyntax.patt_eoi;; + + (* + << fun x -> $3$ >> -> Lam(VAtom"x", 3) + + (* compilo.ml -pp lam.cmo *) + match t with + | << (fun $x$ -> $e1$) $e2$ >> -> << $subst ...$ >> + *) + + (* This part can be generated use SwitchValRepr *) + let rec term_to_expr = function + | Val(_loc, Lam(v, t)) -> <:expr< Lam($var_to_expr v$, $term_to_expr t$) >> + | Val(_loc, App(t1, t2)) -> <:expr< App($term_to_expr t1$, $term_to_expr t2$) >> + | Val(_loc, Var(v)) -> <:expr< Var($var_to_expr v$) >> + | Val(_loc, Int(i)) -> <:expr< Int($int_to_expr i$) >> + | Ant(_loc, a) -> expr_of_string _loc a + and var_to_expr = function + | Val(_loc, v) -> <:expr< $str:v$ >> + | Ant(_loc, s) -> expr_of_string _loc s + and int_to_expr = function + | Val(_loc, v) -> <:expr< $`int:v$ >> + | Ant(_loc, s) -> expr_of_string _loc s + ;; + + let rec term_to_patt = function + | Val(_loc, Lam(v, t)) -> <:patt< Lam($var_to_patt v$, $term_to_patt t$) >> + | Val(_loc, App(t1, t2)) -> <:patt< App($term_to_patt t1$, $term_to_patt t2$) >> + | Val(_loc, Var(v)) -> <:patt< Var($var_to_patt v$) >> + | Val(_loc, Int(i)) -> <:patt< Int($int_to_patt i$) >> + | Ant(_loc, a) -> patt_of_string _loc a + and var_to_patt = function + | Val(_loc, v) -> <:patt< $str:v$ >> + | Ant(_loc, s) -> patt_of_string _loc s + and int_to_patt = function + | Val(_loc, v) -> <:patt< $`int:v$ >> + | Ant(_loc, s) -> patt_of_string _loc s + ;; + + (* +Arrow(Var"a", Var"b") +<:typ< 'a -> 'b >> + + let a = ... + let b = ... + let ( ^-> ) t1 t2 = Arrow(t1, t2) + a ^-> b + *) +end +module LambadExpander = struct + module Q = Camlp4.PreCast.Syntax.Quotation;; + let expand_lambda_quot_expr loc _loc_name_opt quotation_contents = + LambdaLifter.term_to_expr + (LambdaParser.parse_string loc quotation_contents) + ;; + Q.add "lam" Q.DynAst.expr_tag expand_lambda_quot_expr;; + let expand_lambda_quot_patt loc _loc_name_opt quotation_contents = + LambdaLifter.term_to_patt + (LambdaParser.parse_string loc quotation_contents) + ;; + Q.add "lam" Q.DynAst.patt_tag expand_lambda_quot_patt;; + + Q.default := "lam";; +end diff --git a/camlp4/examples/fancy_lambda_quot_test.ml b/camlp4/examples/fancy_lambda_quot_test.ml new file mode 100644 index 0000000..3200982 --- /dev/null +++ b/camlp4/examples/fancy_lambda_quot_test.ml @@ -0,0 +1,22 @@ +open Fancy_lambda_quot.LambdaSyntax;; +let _loc = Camlp4.PreCast.Loc.ghost;; +let rec propagate = function + | << $f$ $x$ $y$ >> -> + begin match propagate f, propagate x, propagate y with + | f, << $int:i$ >>, << $int:j$ >> -> + begin match f with + | << plus >> -> << $int:i + j$ >> + | << minus >> -> << $int:i - j$ >> + | << times >> -> << $int:i * j$ >> + | << div >> -> << $int:i / j$ >> + | _ -> << $f$ $int:i$ $int:j$ >> + end + | f, x, y -> << $f$ $x$ $y$ >> + end + | << $f$ $x$ >> -> << $propagate f$ $propagate x$ >> + | << fun $x$ -> $e$ >> -> << fun $x$ -> $propagate e$ >> (* here x should not be a primitive like plus *) + | << $var:_$ >> | << $int:_$ >> as e -> e +;; + +let ex1 = propagate << f (fun x -> g (plus 3 (times 4 42)) (minus 1 (x 3))) >> +;; diff --git a/camlp4/examples/free_vars_test.ml b/camlp4/examples/free_vars_test.ml new file mode 100644 index 0000000..be01edc --- /dev/null +++ b/camlp4/examples/free_vars_test.ml @@ -0,0 +1,72 @@ +open Format; +open Camlp4.PreCast; + +module FV = Camlp4.Struct.FreeVars.Make Ast; + +#default_quotation "expr"; + +value print_set f s = do { + fprintf f "@[<2>{ "; + FV.S.iter (fprintf f "%s@ ") s; + fprintf f "}@]"; +}; + +module PP = Camlp4.Printers.OCamlr.Make Syntax; +value print_expr = (new PP.printer ())#expr; + +value print_status f st = pp_print_string f (if st then "PASS" else "FAIL"); + +value _loc = Loc.ghost; + +value atoms e = + let o = object + inherit Ast.fold as super; + value accu = FV.S.empty; + method accu = accu; + method expr = + fun + [ << $lid:s$ >> -> {< accu = FV.S.add s accu >} + | e -> super#expr e ]; + end in (o#expr e)#accu; + +value fv e ref = + let s = FV.free_vars FV.S.empty e in + let ref = atoms ref in + let st = FV.S.equal s ref in do { + printf "%a: @[fv << %a >> = %a" + print_status st + print_expr e print_set s; + if st then () else printf "@ ref = %a@ diff = %a" + print_set ref print_set (FV.S.diff ref s); + printf "@]@ "; +}; + +printf "@["; + +fv << x >> << x >>; +fv << x y >> << x y >>; +fv << fun x -> x y >> << y >>; +fv << fun y -> fun x -> x y >> <<>>; +fv << let x = 42 and y = 44 in x y z >> << z >>; +fv << let z = g in let x = 42 and y = 44 in x y z >> << g >>; +fv << let rec f x = g (x + 1) and g y = f (y - 1) in fun x -> g x * f x >> << (+) (-) ( * ) >>; +fv << let rec f x = g (x + 1) and g y = f (g (y - 1)) in fun x -> g x * f x >> << (+) (-) ( * ) >>; + +fv << let i = 42 in let module M = struct value f x = y x; end in M.h >> << y >>; + +fv << fun [ A x -> x y ] >> << y >>; + +fv << fun [ A x -> x y | _ -> x ] >> << x y >>; + +fv << fun [ { x = A z; y = y } as q -> x z y a q ] >> << x a >>; + +fv << let module M = struct value a = 42; value b = a + 1; end in () >> <<(+)>>; + +fv << let module M = struct value rec a = 42; value b = a + 1; end in () >> <<(+)>>; + +fv << let rec f x = x and g = x in y >> << x y >>; +fv << let f x = x in x >> << x >>; +fv << let f x = x and g x = x in x >> << x >>; +fv << let (x, y) = (42, 44) in x y z >> << z >>; + +printf "@]@."; diff --git a/camlp4/examples/gen_match_case.ml b/camlp4/examples/gen_match_case.ml new file mode 100644 index 0000000..c72a146 --- /dev/null +++ b/camlp4/examples/gen_match_case.ml @@ -0,0 +1,12 @@ +open Camlp4.PreCast;; + +let gen patts exprs = + let cases = + List.fold_right2 begin fun patt expr acc -> + let _loc = Loc.merge (Ast.loc_of_patt patt) (Ast.loc_of_expr expr) in + <:match_case< $patt$ -> $expr$ | $acc$ >> + end patts exprs <:match_case@here<>> + in + let _loc = Ast.loc_of_match_case cases in + <:expr< function $cases$ >> +;; diff --git a/camlp4/examples/gen_type_N.ml b/camlp4/examples/gen_type_N.ml new file mode 100644 index 0000000..276f682 --- /dev/null +++ b/camlp4/examples/gen_type_N.ml @@ -0,0 +1,33 @@ +open Camlp4.PreCast;; + +let data_constructor_arguments _loc n t = + let rec self n = + if n <= 0 then <:ctyp<>> else <:ctyp< $t$ and $self (n-1)$ >> + in self n +;; + +let data_constructor _loc n t = + <:ctyp< $uid:"C"^string_of_int n$ of $data_constructor_arguments _loc n t$ >> +;; + +let gen_type _loc n t = + let rec self n = + if n <= 0 then <:ctyp<>> + else <:ctyp< $self (n-1)$ | $data_constructor _loc n t$ >> + in <:ctyp< [ $self n$ ] >> +;; + +let filter = + function + | <:ctyp@_loc< gen_type $lid:x$ >> | <:ctyp@_loc< $lid:x$ gen_type >> -> + Scanf.sscanf x "%[^0-9]%d" begin fun _ n -> + gen_type _loc n <:ctyp< $lid:x$ >> + end + | t -> t +;; + +AstFilters.register_str_item_filter (Ast.map_ctyp filter)#str_item;; + +IFDEF TEST THEN + type t7 = gen_type t7;; +ENDIF;; diff --git a/camlp4/examples/gettext_test.ml b/camlp4/examples/gettext_test.ml new file mode 100644 index 0000000..27f6cee --- /dev/null +++ b/camlp4/examples/gettext_test.ml @@ -0,0 +1 @@ +f "test", f "foo", "bar" diff --git a/camlp4/examples/global_handler.ml b/camlp4/examples/global_handler.ml new file mode 100644 index 0000000..758e4f9 --- /dev/null +++ b/camlp4/examples/global_handler.ml @@ -0,0 +1,20 @@ +open Camlp4.PreCast; + +value ghost = Loc.ghost; + +value global_handler_ref = ref <:expr@ghost<>>; + +value find_global_handler = + Ast.map_str_item begin + fun + [ <:str_item@_loc< value global_handler = $f$ >> -> + (global_handler_ref.val := f; <:str_item<>>) + | st -> st ] + end; + +AstFilters.register_str_item_filter begin fun st -> + let _ = find_global_handler#str_item st in + <:str_item@ghost< try let module Main = struct $st$ end in () + with e -> $global_handler_ref.val$ e >> +end; + diff --git a/camlp4/examples/global_handler_test.ml b/camlp4/examples/global_handler_test.ml new file mode 100644 index 0000000..882af49 --- /dev/null +++ b/camlp4/examples/global_handler_test.ml @@ -0,0 +1,12 @@ +open Format;; +let f1 x = printf "f1 %d@." x;; +let f2 x = printf "f2 %f@." x;; +let f3 x = printf "f3 %s@." x;; +f1 1;; +f2 1.1;; +f3 "1.1.1";; +raise (Failure "test");; +let global_handler e = + (* Note that I need to give the complete name for eprintf since + Format is not opened in the new environment of global_handler. *) + Format.eprintf "global_handler: %s@." (Printexc.to_string e) diff --git a/camlp4/examples/lambda_parser.ml b/camlp4/examples/lambda_parser.ml new file mode 100644 index 0000000..9c70976 --- /dev/null +++ b/camlp4/examples/lambda_parser.ml @@ -0,0 +1,34 @@ +(* Please keep me in sync with brion.inria.fr/gallium/index.php/Lambda_calculus_quotations *) + +type term = + | Lam of var * term + | App of term * term + | Int of int + | Var of var +and var = string + +module LambdaGram = Camlp4.PreCast.MakeGram(Camlp4.PreCast.Lexer);; +module Loc = Camlp4.PreCast.Loc;; (* should not be necessary when camlp4 will be fixed *) +open Camlp4.Sig;; (* from tokens *) +let term = LambdaGram.Entry.mk "term";; +let term_eoi = LambdaGram.Entry.mk "lambda term quotation";; + +EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> Lam(v, t) ] + | "app" + [ t1 = SELF; t2 = SELF -> App(t1, t2) ] + | "simple" + [ v = var -> Var(v) + | `INT(i, _) -> Int(i) + | "("; t = term; ")" -> t ] + ]; + var: + [[ `LIDENT v -> v ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; +END;; + +let lambda_parser = LambdaGram.parse_string term_eoi;; diff --git a/camlp4/examples/lambda_quot.ml b/camlp4/examples/lambda_quot.ml new file mode 100644 index 0000000..654511a --- /dev/null +++ b/camlp4/examples/lambda_quot.ml @@ -0,0 +1,38 @@ +open Camlp4.PreCast; +module CamlSyntax = Camlp4OCamlParser.Make (Camlp4OCamlRevisedParser.Make Syntax); + +value expr_of_string = CamlSyntax.Gram.parse_string CamlSyntax.expr_eoi; + +module LambdaGram = MakeGram Lexer; + +value term = LambdaGram.Entry.mk "term"; +value term_eoi = LambdaGram.Entry.mk "lambda term quotation"; + +Camlp4_config.antiquotations.val := True; + +EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> <:expr< `Lam $v$ $t$ >> ] + | "app" + [ t1 = SELF; t2 = SELF -> <:expr< `App $t1$ $t2$ >> ] + | "simple" + [ `ANTIQUOT (""|"term") a -> expr_of_string _loc a + | v = var -> <:expr< `Var $v$ >> + | "("; t = term; ")" -> t ] + ]; + var: + [[ v = LIDENT -> <:expr< $str:v$ >> + | `ANTIQUOT (""|"var") a -> expr_of_string _loc a + ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; +END; + +value expand_lambda_quot_expr loc _loc_name_opt quotation_contents = + LambdaGram.parse_string term_eoi loc quotation_contents; + +Syntax.Quotation.add "lam" Syntax.Quotation.DynAst.expr_tag expand_lambda_quot_expr; + +Syntax.Quotation.default.val := "lam"; diff --git a/camlp4/examples/lambda_quot_expr.ml b/camlp4/examples/lambda_quot_expr.ml new file mode 100644 index 0000000..9892212 --- /dev/null +++ b/camlp4/examples/lambda_quot_expr.ml @@ -0,0 +1,41 @@ +(* Please keep me in sync with brion.inria.fr/gallium/index.php/Lambda_calculus_quotations *) + +open Camlp4.PreCast;; +module CamlSyntax = Camlp4OCamlParser.Make(Camlp4OCamlRevisedParser.Make(Syntax));; + +let expr_of_string = CamlSyntax.Gram.parse_string CamlSyntax.expr_eoi;; + +module LambdaGram = MakeGram(Lexer);; + +let term = LambdaGram.Entry.mk "term";; +let term_eoi = LambdaGram.Entry.mk "lambda term quotation";; + +Camlp4_config.antiquotations := true;; + +EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> <:expr< `Lam($v$, $t$) >> ] + | "app" + [ t1 = SELF; t2 = SELF -> <:expr< `App($t1$, $t2$) >> ] + | "simple" + [ `ANTIQUOT((""|"term"), a) -> expr_of_string _loc a + | v = var -> <:expr< `Var($v$) >> + | "("; t = term; ")" -> t ] + ]; + var: + [[ v = LIDENT -> <:expr< $str:v$ >> + | `ANTIQUOT((""|"var"), a) -> expr_of_string _loc a + ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; +END;; + +let expand_lambda_quot_expr loc _loc_name_opt quotation_contents = + LambdaGram.parse_string term_eoi loc quotation_contents;; + +(* to have this syntax <:lam< fun k -> k >> *) +Syntax.Quotation.add "lam" Syntax.Quotation.DynAst.expr_tag expand_lambda_quot_expr;; + +Syntax.Quotation.default := "lam";; diff --git a/camlp4/examples/lambda_quot_patt.ml b/camlp4/examples/lambda_quot_patt.ml new file mode 100644 index 0000000..e6732dd --- /dev/null +++ b/camlp4/examples/lambda_quot_patt.ml @@ -0,0 +1,41 @@ +(* Please keep me in sync with brion.inria.fr/gallium/index.php/Lambda_calculus_quotations *) + +open Camlp4.PreCast;; +module CamlSyntax = Camlp4OCamlParser.Make(Camlp4OCamlRevisedParser.Make(Syntax));; + +let patt_of_string = CamlSyntax.Gram.parse_string CamlSyntax.patt_eoi;; + +module LambdaGram = MakeGram(Lexer);; + +let term = LambdaGram.Entry.mk "term";; +let term_eoi = LambdaGram.Entry.mk "lambda term quotation";; + +Camlp4_config.antiquotations := true;; + +EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> <:patt< `Lam($v$, $t$) >> ] + | "app" + [ t1 = SELF; t2 = SELF -> <:patt< `App($t1$, $t2$) >> ] + | "simple" + [ `ANTIQUOT((""|"term"), a) -> patt_of_string _loc a + | v = var -> <:patt< `Var($v$) >> + | "("; t = term; ")" -> t ] + ]; + var: + [[ v = LIDENT -> <:patt< $str:v$ >> + | `ANTIQUOT((""|"var"), a) -> patt_of_string _loc a + ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; +END;; + +let expand_lambda_quot_patt loc _loc_name_opt quotation_contents = + LambdaGram.parse_string term_eoi loc quotation_contents;; + +(* function <:lam< fun x -> $(t|u)$ >> -> ... *) +Syntax.Quotation.add "lam" Syntax.Quotation.DynAst.patt_tag expand_lambda_quot_patt;; + +Syntax.Quotation.default := "lam";; diff --git a/camlp4/examples/lambda_test.ml b/camlp4/examples/lambda_test.ml new file mode 100644 index 0000000..408461a --- /dev/null +++ b/camlp4/examples/lambda_test.ml @@ -0,0 +1,13 @@ +let id = << fun x -> x >> +(* Imported and traduced from CCT *) +let zero = << fun s -> fun z -> z >> +let succ = << fun n -> fun s -> fun z -> s n >> +let one = << $succ$ $zero$ >> +let iota = << fun x -> z >> +let rho = << fun m -> fun r -> (s m (m r $iota$ r)) >> +let rec_nat = + << fun n -> fun s -> fun z -> n $rho$ $iota$ $rho$ >> +let plus = << fun n -> fun m -> $rec_nat$ n (fun n -> fun p -> $succ$ p) m >> +let times = << fun n -> fun m -> $rec_nat$ n (fun n -> fun p -> $plus$ m p) $zero$ >> +let fact = << fun n -> $rec_nat$ n (fun n -> fun p -> $times$ ($succ$ n) p) $one$ >> + diff --git a/camlp4/examples/macros.ml b/camlp4/examples/macros.ml new file mode 100644 index 0000000..fe7b739 --- /dev/null +++ b/camlp4/examples/macros.ml @@ -0,0 +1,67 @@ +open Camlp4.PreCast;; +let foldr_funs = ref [];; +let foldl_funs = ref [];; +AstFilters.register_str_item_filter begin + Ast.map_expr begin function + | <:expr@loc< def_foldr $lid:name$ $e$ >> -> + foldr_funs := (name, e) :: !foldr_funs; <:expr@loc<()>> + | <:expr@loc< def_foldl $lid:name$ $e$ >> -> + foldl_funs := (name, e) :: !foldl_funs; <:expr@loc<()>> + | e -> e + end +end#str_item;; +AstFilters.register_str_item_filter begin + Ast.map_expr begin function + | <:expr@loc< $lid:name$($tup:e$) >> when List.mem_assoc name !foldl_funs -> + let op = List.assoc name !foldl_funs in + let rec foldl = + function + | [] -> assert false + | [x] -> x + | x :: xs -> <:expr@loc< $op$ $foldl xs$ $x$ >> + in foldl (List.rev (Ast.list_of_expr e [])) + | <:expr@loc< $lid:name$($tup:e$) >> when List.mem_assoc name !foldr_funs -> + let op = List.assoc name !foldr_funs in + let rec foldr = + function + | [] -> assert false + | [x] -> x + | x :: xs -> <:expr@loc< $op$ $x$ $foldr xs$ >> + in foldr (Ast.list_of_expr e []) + | e -> e + end +end#str_item;; +(* + +AstFilters.register_str_item_filter begin + Ast.map_expr begin function + | <:expr@loc< foldl($lid:op$, $e$) >> -> + let rec foldl = + function + | [] -> assert false + | [x] -> x + | x :: xs -> <:expr@loc< $lid:op$ $foldl xs$ $x$ >> + in foldl (List.rev (Ast.list_of_expr e [])) + | <:expr@loc< foldr($lid:op$, $e$) >> -> + let rec foldr = + function + | [] -> assert false + | [x] -> x + | x :: xs -> <:expr@loc< $lid:op$ $x$ $foldr xs$ >> + in foldr (Ast.list_of_expr e []) + | e -> e + end +end#str_item;; + +AstFilters.register_str_item_filter begin + Ast.map_expr begin function + | <:expr@loc< \!+ ($tup:e$) >> -> + begin match Ast.list_of_expr e [] with + | [] | [_] -> assert false + | x :: xs -> List.fold_left (fun acc x -> <:expr@loc< $acc$ + $x$ >>) x xs + end + | <:expr< \!+ $e$ >> -> e + | e -> e + end +end#str_item;; +*) diff --git a/camlp4/examples/parse_files.ml b/camlp4/examples/parse_files.ml new file mode 100644 index 0000000..0df49c1 --- /dev/null +++ b/camlp4/examples/parse_files.ml @@ -0,0 +1,29 @@ +open Camlp4.PreCast;; + +module Caml = + Camlp4.Printers.OCaml.Make + (Camlp4OCamlParser.Make + (Camlp4OCamlRevisedParser.Make + (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation))));; + +let parse f = + let ic = open_in f in + let strm = Stream.of_channel ic in + let res = Caml.parse_implem (Loc.mk f) strm in + close_in ic; res;; + +let ghost = Loc.ghost;; + +let main () = + let a = parse "apply_operator_test.ml" in + let b = parse "global_handler_test.ml" in + Caml.print_implem + <:str_item@ghost< + module Apply_operator_test = struct $a$ end;; + module Global_handler_test = struct $b$ end >> +;; + +try main () +with e -> + Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; + exit 1;; diff --git a/camlp4/examples/syb_fold.ml b/camlp4/examples/syb_fold.ml new file mode 100644 index 0000000..3441c6b --- /dev/null +++ b/camlp4/examples/syb_fold.ml @@ -0,0 +1,90 @@ +type variable = string + and term = + | Var of variable + | Lam of variable * term + | App of term * term + | Const of constant + and constant = + | CInt of int + | CString of string +;; + +class fold = Camlp4Filters.GenerateFold.generated;; +(* class fold = Camlp4FoldGenerator.generated;; *) + +module VarSet = Set.Make(String);; + +(* Compute free variables with the fold class *) +let free_variables_v1 = + let o = + object (self) + inherit fold as super + val fv = VarSet.empty + method fv = fv + method empty_fv = {< fv = VarSet.empty >} + method term t = + match t with + | Var(v) -> {< fv = VarSet.add v fv >} + | Lam(v, t) -> + let fv1 = VarSet.remove v (self#empty_fv#term t)#fv in + {< fv = VarSet.union fv fv1 >} + | _ -> super#term t + end + in fun t -> VarSet.elements (o#term t)#fv +;; + +(* Let's try to abstract that a little *) + +let fold_term f t init = + let o = + object (self) + inherit fold as super + val acc = init + method get = acc + method reset = {< acc = init >} + method term t = + {< acc = f t acc (fun t -> (self#reset#term t)#get) + (fun t -> (super#term t)#get) >} + end + in + (o#term t)#get +;; + +(* A nicer version of free_variables *) +let free_variables_v2 t = + VarSet.elements begin + fold_term begin fun t fv self next -> + match t with + | Var(v) -> VarSet.add v fv + | Lam(v, t) -> VarSet.union fv (VarSet.remove v (self t)) + | _ -> next t + end t VarSet.empty + end +;; + +let term1 = + App( + App(Var"x1", + Lam("x", + App(Var"x", App(Var"y", (Lam("y", Lam("z", (App(Var"y", App(Var"x4",Var"z")))))))))), + Var"x3") + +;; + +let fv1 = free_variables_v1 term1;; +let fv2 = free_variables_v2 term1;; + +(* Low cost syntax *) +let ( ^-> ) v t = Lam(v, t) +let ( @ ) t1 t2 = App(t1, t2) +let ( ! ) s = Var s + +let term2 = + !"x1" @ + ("x" ^-> !"x" @ !"y" @ ("y" ^-> ("z" ^-> !"y" @ !"x4" @ !"z"))) @ + !"x3" + +;; + +let fv1' = free_variables_v1 term2;; +let fv2' = free_variables_v2 term2;; diff --git a/camlp4/examples/syb_map.ml b/camlp4/examples/syb_map.ml new file mode 100644 index 0000000..8ef923f --- /dev/null +++ b/camlp4/examples/syb_map.ml @@ -0,0 +1,51 @@ +type variable = string + and term = + | Var of variable + | Lam of variable * term + | App of term * term + | Const of constant + and constant = + | CInt of int + | CString of string + and program = + | Def of string * term + | Seq of program list +;; + +class map = Camlp4Filters.GenerateMap.generated;; +(* class map = Camlp4MapGenerator.generated;; *) + +let map_term f = object + inherit map as super + method term t = f (super#term t) +end;; + +let map_term' f = object (self) + inherit map as super + method term t = f t self#term super#term +end;; + +(* Suppress calls to the identity function... *) +let suppress_id = + map_term begin function + | App(Lam(v, Var(v')), t) when v = v' -> t + | x -> x + end;; + +(* Substitute blindly all occurences of v by t *) +let raw_subst v t = + map_term' begin fun t' _ next -> + match t' with + | Var(v') when v = v' -> t + | x -> next x + end;; + +let id = Lam("x", Var"x");; +let _42 = Const(CInt 42);; +let prog = + Seq[Def("foo", App(id, _42)); Def("bar", App(id, id))];; + +let prog2 = suppress_id#program prog;; +let term3 = suppress_id#term (App(id, _42));; + +let term4 = (raw_subst "x" _42)#term (App(Var"succ", Var"x"));; diff --git a/camlp4/examples/test.itarget b/camlp4/examples/test.itarget new file mode 100644 index 0000000..66c33d8 --- /dev/null +++ b/camlp4/examples/test.itarget @@ -0,0 +1,8 @@ +test_macros.cmo +lambda_test.cmo +free_vars_test.byte +free_vars_test.native +global_handler_test.cmo +apply_operator_test.cmo +test_type_quotation.cmo +expression_closure_test.cmo diff --git a/camlp4/examples/test_macros.ml b/camlp4/examples/test_macros.ml new file mode 100644 index 0000000..1e1b172 --- /dev/null +++ b/camlp4/examples/test_macros.ml @@ -0,0 +1,15 @@ +(* DEFINE F(x, y, z) = x + y * z;; *) +(* F(F(1, 2, 3), 4, 5);; *) + +(* !+ (1, 2, 3, 4);; *) + +(* foldl(( + ), 1, 2, 3, 4);; *) +(* foldr(cons, 1, 2, 3, []);; *) + +let cons x xs = x :: xs;; + +def_foldl ( !+ ) ( + );; +def_foldr ( !:: ) cons;; + +!+ (1, 2, 3, 4);; +!:: (1, 2, 3, []);; diff --git a/camlp4/examples/test_type_quotation.ml b/camlp4/examples/test_type_quotation.ml new file mode 100644 index 0000000..772dfcf --- /dev/null +++ b/camlp4/examples/test_type_quotation.ml @@ -0,0 +1,3 @@ +type t1 = <:power< 6 | int >> +type t2 = <:power< 3 | int -> int >> -> int +type t3 = <:power< 3 | int -> <:power< 2 | int >> >> -> int diff --git a/camlp4/examples/type_quotation.ml b/camlp4/examples/type_quotation.ml new file mode 100644 index 0000000..5dae046 --- /dev/null +++ b/camlp4/examples/type_quotation.ml @@ -0,0 +1,18 @@ +open Camlp4.PreCast; + +value rec mk_tuple _loc t n = + if n <= 1 then t else <:ctyp< $t$ * $mk_tuple _loc t (n - 1)$ >>; + +value ctyp_eoi = Gram.Entry.mk "ctyp eoi"; + +EXTEND Gram + ctyp_eoi: [[ t = Syntax.ctyp; `EOI -> t ]]; +END; + +value exp _loc _ s = + Scanf.sscanf s " %d | %[^!]" begin fun n s -> + let t = Syntax.Gram.parse_string ctyp_eoi _loc(* not accurate *) s in + <:ctyp< $tup:mk_tuple _loc t n$ >> + end; + +Quotation.add "power" Quotation.DynAst.ctyp_tag exp; diff --git a/camlp4/man/.cvsignore b/camlp4/man/.cvsignore new file mode 100644 index 0000000..2dc933c --- /dev/null +++ b/camlp4/man/.cvsignore @@ -0,0 +1,2 @@ +camlp4.1 +camlp4.help diff --git a/camlp4/man/Makefile b/camlp4/man/Makefile new file mode 100644 index 0000000..bf33c7a --- /dev/null +++ b/camlp4/man/Makefile @@ -0,0 +1,21 @@ + + +include ../config/Makefile.cnf + +TARGET=camlp4.1 +ALIASES=camlp4o.1 camlp4r.1 mkcamlp4.1 ocpp.1 camlp4o.opt.1 camlp4r.opt.1 + +include ../config/Makefile.base + +install-local: + if test -n '$(MANDIR)'; then \ + $(MKDIR) $(MANDIR)/man1 ; \ + cp $(TARGET) $(MANDIR)/man1/. ; \ + for i in $(ALIASES); do \ + rm -f $(MANDIR)/man1/$$i; \ + echo '.so man1/$(TARGET)' > $(MANDIR)/man1/$$i; \ + done; \ + fi + +camlp4.1: camlp4.1.tpl + sed -e "s'LIBDIR'$(LIBDIR)'g" camlp4.1.tpl > camlp4.1 diff --git a/camlp4/man/camlp4.1.tpl b/camlp4/man/camlp4.1.tpl new file mode 100644 index 0000000..ff8c650 --- /dev/null +++ b/camlp4/man/camlp4.1.tpl @@ -0,0 +1,279 @@ +.TH CAMLP4 1 "" "INRIA" +.SH NAME +camlp4 - Pre-Precessor-Pretty-Printer for OCaml +.br +mkcamlp4 - Create custom camlp4 +.br +ocpp - Universal preprocessor + +.SH SYNOPSIS +.B camlp4 +[ +load-options +] [--] [ +other-options +] +.br +.B camlp4o +[ +load-options +] [--] [ +other-options +] +.br +.B camlp4r +[ +load-options +] [--] [ +other-options +] +.br +.B camlp4o.cma +.br +.B camlp4r.cma +.br +.B mkcamlp4 +.br +.B ocpp +[ +load-options +] +file +.LP +.br +.B camlp4o.opt +[--] [ +other-options +] +.br +.B camlp4r.opt +[--] [ +other-options +] + +.SH DESCRIPTION +.B camlp4 +is a Pre-Processor-Pretty-Printer for OCaml, parsing a source +file and printing some result on standard output. +.LP +.B camlp4o +and +.B camlp4r +are versions of +.B camlp4 +with some files already loaded (see below). +.LP +.B camlp4o.cma +and +.B camlp4r.cma +are files to be loaded in ocaml toplevel to use the camlp4 machinery. +.LP +.B mkcamlp4 +creates camlp4 executables with almost the same options as ocamlmktop (see below). +.LP +.B ocpp +is an universal preprocessor, expanding quotations in any kind of text file. +.LP +.B camlp4o.opt +and +.B camlp4r.opt +are versions of camlp4o and camlp4r compiled by the native-code compiler +ocamlopt. They are faster but not extensible. And they are not available +in all installations of camlp4. + +.SH LOAD OPTIONS + +The load options select parsing and printing actions recorded in OCaml +object files (ending with .cmo or .cma). They must precede other +options. + +.LP +An optional +.B \-\- +may end the load options. + +.TP +.BI \-I\ directory +Add +.I directory +in the search path for files loaded. Unless the option \-nolib is used, +the camlp4 library directory is appended to the path. Note that there is +no automatic search in the current directory: add "\-I ." for this. +.TP +.B \-where +Print camlp4 library directory name and exit. +.TP +.B \-nolib +No automatic search for objects files in camlp4 library directory. +.TP +.I object-file +Load +.I object-file +in the camlp4 core. + +.SH OTHER OPTIONS + +.LP +The others options are: + +.TP +.I file +Treat +.I file +as an interface file if it ends with .mli and as an implementation file +if it ends with .ml. + +.TP +.BI \-intf\ file +Treat +.I file +as an interface file, whatever its extension is. +.TP +.BI \-impl\ file +Treat +.I file +as an implementation file, whatever its extension is. +.TP +.B \-unsafe +Generate unsafe accesses to arrays and strings. +.TP +.B \-noassert +Do not compile assertion checks. +.TP +.B \-verbose +More verbose in parsing errors. +.TP +.BI \-QD\ file +Dump in +.I file +in case of syntax error in the result of a quotation expansion. +.TP +.BI \-o\ out-file +Print the result in +.I out-file +instead of standard output. File is opened +with open_out_bin (see the documentation of the Pervasives OCaml library). +.TP +.B \-v +Print the version number and exit. +.TP +.B \-help +Print the available options and exit. The output includes the options +possibly added by the loaded object files. + +.LP +The others options can be extended by loaded object files. The provided +files add the following options: + +.TP +.BI \-l\ line-length +Added by pr_o.cmo and pr_r.cmo: set the line length (default 78). +.TP +.BI \-sep\ string +Added by pr_o.cmo and pr_r.cmo: print this string between phrases instead +of comments. +.TP +.BI \-no_ss +Added by pr_o.cmo: do not print double semicolons +.TP +.BI \-D\ ident +Added by pa_macro.cmo: define the ident. +.TP +.BI \-U\ ident +Added by pa_macro.cmo: undefine the ident. + +.SH "PROVIDED FILES" +These files are installed in LIBDIR/camlp4. + +.LP +Parsing files: +.nf +.ta 1c + pa_o.cmo: syntax of OCaml + pa_op.cmo: streams and parsers + pa_oop.cmo: streams and parsers (without code optimization) + pa_r.cmo: revised syntax + pa_rp.cmo: streams and parsers + pa_extend.cmo: syntax extension for grammars + pa_extfold.cmo: extension of pa_extend with FOLD0 and FOLD1 + pa_extfun.cmo: syntax extension for extensible functions + pa_fstream.cmo: syntax extension for functional streams + pa_macro.cmo: add macros (ifdef, define) like in C + pa_lefteval.cmo: left-to-right evaluation of parameters + pa_olabl.cmo: old syntax for labels +.fi +.LP +Printing files: +.nf +.ta 1c + pr_o.cmo: syntax of OCaml + pr_op.cmo: try to rebuild streams and parsers syntax + pr_r.cmo: revised syntax + pr_rp.cmo: try to rebuild streams and parsers syntax + pr_extend.cmo: try to rebuild EXTEND statements + pr_extfun.cmo: try to rebuild extfun statements + pr_dump.cmo: syntax tree + pr_depend.cmo: file dependencies + pr_null.cmo: no output +.fi +.LP +Quotation expanders: +.nf +.ta 1c + q_MLast.cmo: syntax tree nodes + q_phony.cmo: keeping quotations for pretty printing +.fi +.LP +The command +.B camlp4o +is a shortcut for: +.nf +.ta 1c + camlp4 pa_o.cmo pa_op.cmo pr_dump.cmo +.fi +.LP +The command +.B camlp4r +is a shortcut for: +.nf +.ta 1c + camlp4 pa_r.cmo pa_rp.cmo pr_dump.cmo +.fi +.LP +.LP +The file +.B camlp4o.cma +can be loaded in the toplevel to start camlp4 with OCaml syntax. +.LP +The file +.B camlp4r.cma +can be loaded in the toplevel to start camlp4 with revised syntax. + +.SH "MKCAMLP4" + +.B mkcamlp4 +creates camlp4 executables with almost the same options than ocamlmktop. +The only difference is that the interfaces to be visible must be explicitly +added in the command line as ".cmi" files. For example, how to add the +the OCaml module "str": + +.nf +.ta 1c 2c + mkcamlp4 -custom str.cmi str.cma -cclib -lstr \\ + -o camlp4str +.fi + +.SH "FILES" +Camlp4 library directory in the current installation: +.br +LIBDIR/camlp4 + +.SH "SEE ALSO" +Camlp4 - tutorial +.br +Camlp4 - reference manual +.br +ocamlc(1), ocaml(1). + +.SH AUTHOR +Daniel de Rauglaudre, INRIA Rocquencourt. diff --git a/camlp4/man/camlp4.help.tpl b/camlp4/man/camlp4.help.tpl new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/camlp4/man/camlp4.help.tpl @@ -0,0 +1 @@ + diff --git a/camlp4/mkcamlp4.ml b/camlp4/mkcamlp4.ml new file mode 100644 index 0000000..e585350 --- /dev/null +++ b/camlp4/mkcamlp4.ml @@ -0,0 +1,68 @@ +(****************************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed under *) +(* the terms of the GNU Library General Public License, with the special *) +(* exception on linking described in LICENSE at the top of the Objective *) +(* Caml source tree. *) +(* *) +(****************************************************************************) + +(* Authors: + * - Daniel de Rauglaudre: initial shell version + * - Nicolas Pouillard: rewriting in OCaml + *) + + + +open Camlp4; +open Camlp4_config; +open Filename; +open Format; + +value (interfaces, options, includes) = + let rec self (interf, opts, incl) = + fun + [ [] -> (List.rev interf, List.rev opts, List.rev incl) + | ["-I"; dir :: args] -> self (interf, opts, [dir; "-I" :: incl]) args + | ["-version" :: _] -> + do { printf "mkcamlp4, version %s@." version; exit 0 } + | [ arg :: args ] when check_suffix arg ".cmi" -> + let basename = String.capitalize (Filename.chop_suffix + (Filename.basename arg) ".cmi") in + self ([ basename :: interf ], opts, incl) args + | [ arg :: args ] -> + self (interf, [ arg :: opts ], incl) args ] + in self ([], [], ["."; "-I"]) (List.tl (Array.to_list Sys.argv)); + +value run l = + let cmd = String.concat " " l in + let () = Format.printf "%s@." cmd in + let st = + Sys.command cmd + (* 0 *) + in + if st <> 0 then failwith ("Exit: " ^ string_of_int st) else (); + +value crc_ml = Filename.temp_file "crc_" ".ml"; +value crc = Filename.chop_suffix crc_ml ".ml"; +value clean () = run ["rm"; "-f"; crc_ml; crc^".cmi"; crc^".cmo"]; + +try do { + run ([ocaml_standard_library^"/extract_crc"; "-I"; camlp4_standard_library] + @ includes @ interfaces @ [">"; crc_ml]); + + let cout = open_out_gen [Open_wronly; Open_append; Open_text] 0o666 crc_ml in do { + output_string cout "let _ = Dynlink.add_available_units crc_unit_list\n"; + close_out cout + }; + + run (["ocamlc"; "-I"; camlp4_standard_library; "camlp4lib.cma"; crc_ml] + @ includes @ options @ ["Camlp4Bin.cmo"; "-linkall"]); + clean(); +} +with exc -> do { clean (); raise exc }; diff --git a/camlp4/test/fixtures/assert.ml b/camlp4/test/fixtures/assert.ml new file mode 100644 index 0000000..8d9ea49 --- /dev/null +++ b/camlp4/test/fixtures/assert.ml @@ -0,0 +1,3 @@ +module MySet = Set.Make(String);; +let set = MySet.empty;; +assert (MySet.is_empty set);; diff --git a/camlp4/test/fixtures/backquoted_irrefutable_tuple.ml b/camlp4/test/fixtures/backquoted_irrefutable_tuple.ml new file mode 100644 index 0000000..f6764cb --- /dev/null +++ b/camlp4/test/fixtures/backquoted_irrefutable_tuple.ml @@ -0,0 +1,3 @@ +EXTEND Gram + abc: [ [ `(x,y) -> x + y ] ]; +END; diff --git a/camlp4/test/fixtures/backquoted_record.ml b/camlp4/test/fixtures/backquoted_record.ml new file mode 100644 index 0000000..e056f73 --- /dev/null +++ b/camlp4/test/fixtures/backquoted_record.ml @@ -0,0 +1,4 @@ +EXTEND Gram + raw_string: + [[ `QUOTATION { Sig.Quotation.q_contents = c; q_name = n } -> (c, n) ]]; +END; diff --git a/camlp4/test/fixtures/backquoted_tuple.ml b/camlp4/test/fixtures/backquoted_tuple.ml new file mode 100644 index 0000000..72ae1a6 --- /dev/null +++ b/camlp4/test/fixtures/backquoted_tuple.ml @@ -0,0 +1,3 @@ +EXTEND Gram + abc: [ [ `(A,y) -> y ] ]; +END; diff --git a/camlp4/test/fixtures/big-tab1.ml b/camlp4/test/fixtures/big-tab1.ml new file mode 100644 index 0000000..254da82 --- /dev/null +++ b/camlp4/test/fixtures/big-tab1.ml @@ -0,0 +1,704 @@ +[| +aaa; +aab; +aac; +aad; +aae; +aaf; +aag; +aah; +aai; +aaj; +aak; +aal; +aam; +aan; +aao; +aap; +aaq; +aar; +aas; +aat; +aau; +aav; +aaw; +aax; +aay; +aaz; +aba; +abb; +abc; +abd; +abe; +abf; +abg; +abh; +abi; +abj; +abk; +abl; +abm; +abn; +abo; +abp; +abq; +abr; +abs; +abt; +abu; +abv; +abw; +abx; +aby; +abz; +aca; +acb; +acc; +acd; +ace; +acf; +acg; +ach; +aci; +acj; +ack; +acl; +acm; +acn; +aco; +acp; +acq; +acr; +acs; +act; +acu; +acv; +acw; +acx; +acy; +acz; +ada; +adb; +adc; +add; +ade; +adf; +adg; +adh; +adi; +adj; +adk; +adl; +adm; +adn; +ado; +adp; +adq; +adr; +ads; +adt; +adu; +adv; +adw; +adx; +ady; +adz; +aea; +aeb; +aec; +aed; +aee; +aef; +aeg; +aeh; +aei; +aej; +aek; +ael; +aem; +aen; +aeo; +aep; +aeq; +aer; +aes; +aet; +aeu; +aev; +aew; +aex; +aey; +aez; +afa; +afb; +afc; +afd; +afe; +aff; +afg; +afh; +afi; +afj; +afk; +afl; +afm; +afn; +afo; +afp; +afq; +afr; +afs; +aft; +afu; +afv; +afw; +afx; +afy; +afz; +aga; +agb; +agc; +agd; +age; +agf; +agg; +agh; +agi; +agj; +agk; +agl; +agm; +agn; +ago; +agp; +agq; +agr; +ags; +agt; +agu; +agv; +agw; +agx; +agy; +agz; +aha; +ahb; +ahc; +ahd; +ahe; +ahf; +ahg; +ahh; +ahi; +ahj; +ahk; +ahl; +ahm; +ahn; +aho; +ahp; +ahq; +ahr; +ahs; +aht; +ahu; +ahv; +ahw; +ahx; +ahy; +ahz; +aia; +aib; +aic; +aid; +aie; +aif; +aig; +aih; +aii; +aij; +aik; +ail; +aim; +ain; +aio; +aip; +aiq; +air; +ais; +ait; +aiu; +aiv; +aiw; +aix; +aiy; +aiz; +aja; +ajb; +ajc; +ajd; +aje; +ajf; +ajg; +ajh; +aji; +ajj; +ajk; +ajl; +ajm; +ajn; +ajo; +ajp; +ajq; +ajr; +ajs; +ajt; +aju; +ajv; +ajw; +ajx; +ajy; +ajz; +aka; +akb; +akc; +akd; +ake; +akf; +akg; +akh; +aki; +akj; +akk; +akl; +akm; +akn; +ako; +akp; +akq; +akr; +aks; +akt; +aku; +akv; +akw; +akx; +aky; +akz; +ala; +alb; +alc; +ald; +ale; +alf; +alg; +alh; +ali; +alj; +alk; +all; +alm; +aln; +alo; +alp; +alq; +alr; +als; +alt; +alu; +alv; +alw; +alx; +aly; +alz; +ama; +amb; +amc; +amd; +ame; +amf; +amg; +amh; +ami; +amj; +amk; +aml; +amm; +amn; +amo; +amp; +amq; +amr; +ams; +amt; +amu; +amv; +amw; +amx; +amy; +amz; +ana; +anb; +anc; +ane; +anf; +ang; +anh; +ani; +anj; +ank; +anl; +anm; +ann; +ano; +anp; +anq; +anr; +ans; +ant; +anu; +anv; +anw; +anx; +any; +anz; +aoa; +aob; +aoc; +aod; +aoe; +aof; +aog; +aoh; +aoi; +aoj; +aok; +aol; +aom; +aon; +aoo; +aop; +aoq; +aor; +aos; +aot; +aou; +aov; +aow; +aox; +aoy; +aoz; +apa; +apb; +apc; +apd; +ape; +apf; +apg; +aph; +api; +apj; +apk; +apl; +apm; +apn; +apo; +app; +apq; +apr; +aps; +apt; +apu; +apv; +apw; +apx; +apy; +apz; +aqa; +aqb; +aqc; +aqd; +aqe; +aqf; +aqg; +aqh; +aqi; +aqj; +aqk; +aql; +aqm; +aqn; +aqo; +aqp; +aqq; +aqr; +aqs; +aqt; +aqu; +aqv; +aqw; +aqx; +aqy; +aqz; +ara; +arb; +arc; +ard; +are; +arf; +arg; +arh; +ari; +arj; +ark; +arl; +arm; +arn; +aro; +arp; +arq; +arr; +ars; +art; +aru; +arv; +arw; +arx; +ary; +arz; +asa; +asb; +asc; +asd; +ase; +asf; +asg; +ash; +asi; +asj; +ask; +asl; +asm; +asn; +aso; +asp; +asq; +ass; +ast; +asu; +asv; +asw; +asx; +asy; +asz; +ata; +atb; +atc; +atd; +ate; +atf; +atg; +ath; +ati; +atj; +atk; +atl; +atm; +atn; +ato; +atp; +atq; +atr; +ats; +att; +atu; +atv; +atw; +atx; +aty; +atz; +aua; +aub; +auc; +aud; +aue; +auf; +aug; +auh; +aui; +auj; +auk; +aul; +aum; +aun; +auo; +aup; +auq; +aur; +aus; +aut; +auu; +auv; +auw; +aux; +auy; +auz; +ava; +avb; +avc; +avd; +ave; +avf; +avg; +avh; +avi; +avj; +avk; +avl; +avm; +avn; +avo; +avp; +avq; +avr; +avs; +avt; +avu; +avv; +avw; +avx; +avy; +avz; +awa; +awb; +awc; +awd; +awe; +awf; +awg; +awh; +awi; +awj; +awk; +awl; +awm; +awn; +awo; +awp; +awq; +awr; +aws; +awt; +awu; +awv; +aww; +awx; +awy; +awz; +axa; +axb; +axc; +axd; +axe; +axf; +axg; +axh; +axi; +axj; +axk; +axl; +axm; +axn; +axo; +axp; +axq; +axr; +axs; +axt; +axu; +axv; +axw; +axx; +axy; +axz; +aya; +ayb; +ayc; +ayd; +aye; +ayf; +ayg; +ayh; +ayi; +ayj; +ayk; +ayl; +aym; +ayn; +ayo; +ayp; +ayq; +ayr; +ays; +ayt; +ayu; +ayv; +ayw; +ayx; +ayy; +ayz; +aza; +azb; +azc; +azd; +aze; +azf; +azg; +azh; +azi; +azj; +azk; +azl; +azm; +azn; +azo; +azp; +azq; +azr; +azs; +azt; +azu; +azv; +azw; +azx; +azy; +azz; +baa; +bab; +bac; +bad; +bae; +baf; +bag; +bah; +bai; +baj; +bak; +bal; +bam; +ban; +bao; +bap; +baq; +bar; +bas; +bat; +bau; +bav; +baw; +bax; +bay; +baz; +bba; +bbb +|]; diff --git a/camlp4/test/fixtures/big-tab2.ml b/camlp4/test/fixtures/big-tab2.ml new file mode 100644 index 0000000..e640f34 --- /dev/null +++ b/camlp4/test/fixtures/big-tab2.ml @@ -0,0 +1,18282 @@ +[| +aaaa; +aaab; +aaac; +aaad; +aaae; +aaaf; +aaag; +aaah; +aaai; +aaaj; +aaak; +aaal; +aaam; +aaan; +aaao; +aaap; +aaaq; +aaar; +aaas; +aaat; +aaau; +aaav; +aaaw; +aaax; +aaay; +aaaz; +aaba; +aabb; +aabc; +aabd; +aabe; +aabf; +aabg; +aabh; +aabi; +aabj; +aabk; +aabl; +aabm; +aabn; +aabo; +aabp; +aabq; +aabr; +aabs; +aabt; +aabu; +aabv; +aabw; +aabx; +aaby; +aabz; +aaca; +aacb; +aacc; +aacd; +aace; +aacf; +aacg; +aach; +aaci; +aacj; +aack; +aacl; +aacm; +aacn; +aaco; +aacp; +aacq; +aacr; +aacs; +aact; +aacu; +aacv; +aacw; +aacx; +aacy; +aacz; +aada; +aadb; +aadc; +aadd; +aade; +aadf; +aadg; +aadh; +aadi; +aadj; +aadk; +aadl; +aadm; +aadn; +aado; +aadp; +aadq; +aadr; +aads; +aadt; +aadu; +aadv; +aadw; +aadx; +aady; +aadz; +aaea; +aaeb; +aaec; +aaed; +aaee; +aaef; +aaeg; +aaeh; +aaei; +aaej; +aaek; +aael; +aaem; +aaen; +aaeo; +aaep; +aaeq; +aaer; +aaes; +aaet; +aaeu; +aaev; +aaew; +aaex; +aaey; +aaez; +aafa; +aafb; +aafc; +aafd; +aafe; +aaff; +aafg; +aafh; +aafi; +aafj; +aafk; +aafl; +aafm; +aafn; +aafo; +aafp; +aafq; +aafr; +aafs; +aaft; +aafu; +aafv; +aafw; +aafx; +aafy; +aafz; +aaga; +aagb; +aagc; +aagd; +aage; +aagf; +aagg; +aagh; +aagi; +aagj; +aagk; +aagl; +aagm; +aagn; +aago; +aagp; +aagq; +aagr; +aags; +aagt; +aagu; +aagv; +aagw; +aagx; +aagy; +aagz; +aaha; +aahb; +aahc; +aahd; +aahe; +aahf; +aahg; +aahh; +aahi; +aahj; +aahk; +aahl; +aahm; +aahn; +aaho; +aahp; +aahq; +aahr; +aahs; +aaht; +aahu; +aahv; +aahw; +aahx; +aahy; +aahz; +aaia; +aaib; +aaic; +aaid; +aaie; +aaif; +aaig; +aaih; +aaii; +aaij; +aaik; +aail; +aaim; +aain; +aaio; +aaip; +aaiq; +aair; +aais; +aait; +aaiu; +aaiv; +aaiw; +aaix; +aaiy; +aaiz; +aaja; +aajb; +aajc; +aajd; +aaje; +aajf; +aajg; +aajh; +aaji; +aajj; +aajk; +aajl; +aajm; +aajn; +aajo; +aajp; +aajq; +aajr; +aajs; +aajt; +aaju; +aajv; +aajw; +aajx; +aajy; +aajz; +aaka; +aakb; +aakc; +aakd; +aake; +aakf; +aakg; +aakh; +aaki; +aakj; +aakk; +aakl; +aakm; +aakn; +aako; +aakp; +aakq; +aakr; +aaks; +aakt; +aaku; +aakv; +aakw; +aakx; +aaky; +aakz; +aala; +aalb; +aalc; +aald; +aale; +aalf; +aalg; +aalh; +aali; +aalj; +aalk; +aall; +aalm; +aaln; +aalo; +aalp; +aalq; +aalr; +aals; +aalt; +aalu; +aalv; +aalw; +aalx; +aaly; +aalz; +aama; +aamb; +aamc; +aamd; +aame; +aamf; +aamg; +aamh; +aami; +aamj; +aamk; +aaml; +aamm; +aamn; +aamo; +aamp; +aamq; +aamr; +aams; +aamt; +aamu; +aamv; +aamw; +aamx; +aamy; +aamz; +aana; +aanb; +aanc; +aand; +aane; +aanf; +aang; +aanh; +aani; +aanj; +aank; +aanl; +aanm; +aann; +aano; +aanp; +aanq; +aanr; +aans; +aant; +aanu; +aanv; +aanw; +aanx; +aany; +aanz; +aaoa; +aaob; +aaoc; +aaod; +aaoe; +aaof; +aaog; +aaoh; +aaoi; +aaoj; +aaok; +aaol; +aaom; +aaon; +aaoo; +aaop; +aaoq; +aaor; +aaos; +aaot; +aaou; +aaov; +aaow; +aaox; +aaoy; +aaoz; +aapa; +aapb; +aapc; +aapd; +aape; +aapf; +aapg; +aaph; +aapi; +aapj; +aapk; +aapl; +aapm; +aapn; +aapo; +aapp; +aapq; +aapr; +aaps; +aapt; +aapu; +aapv; +aapw; +aapx; +aapy; +aapz; +aaqa; +aaqb; +aaqc; +aaqd; +aaqe; +aaqf; +aaqg; +aaqh; +aaqi; +aaqj; +aaqk; +aaql; +aaqm; +aaqn; +aaqo; +aaqp; +aaqq; +aaqr; +aaqs; +aaqt; +aaqu; +aaqv; +aaqw; +aaqx; +aaqy; +aaqz; +aara; +aarb; +aarc; +aard; +aare; +aarf; +aarg; +aarh; +aari; +aarj; +aark; +aarl; +aarm; +aarn; +aaro; +aarp; +aarq; +aarr; +aars; +aart; +aaru; +aarv; +aarw; +aarx; +aary; +aarz; +aasa; +aasb; +aasc; +aasd; +aase; +aasf; +aasg; +aash; +aasi; +aasj; +aask; +aasl; +aasm; +aasn; +aaso; +aasp; +aasq; +aasr; +aass; +aast; +aasu; +aasv; +aasw; +aasx; +aasy; +aasz; +aata; +aatb; +aatc; +aatd; +aate; +aatf; +aatg; +aath; +aati; +aatj; +aatk; +aatl; +aatm; +aatn; +aato; +aatp; +aatq; +aatr; +aats; +aatt; +aatu; +aatv; +aatw; +aatx; +aaty; +aatz; +aaua; +aaub; +aauc; +aaud; +aaue; +aauf; +aaug; +aauh; +aaui; +aauj; +aauk; +aaul; +aaum; +aaun; +aauo; +aaup; +aauq; +aaur; +aaus; +aaut; +aauu; +aauv; +aauw; +aaux; +aauy; +aauz; +aava; +aavb; +aavc; +aavd; +aave; +aavf; +aavg; +aavh; +aavi; +aavj; +aavk; +aavl; +aavm; +aavn; +aavo; +aavp; +aavq; +aavr; +aavs; +aavt; +aavu; +aavv; +aavw; +aavx; +aavy; +aavz; +aawa; +aawb; +aawc; +aawd; +aawe; +aawf; +aawg; +aawh; +aawi; +aawj; +aawk; +aawl; +aawm; +aawn; +aawo; +aawp; +aawq; +aawr; +aaws; +aawt; +aawu; +aawv; +aaww; +aawx; +aawy; +aawz; +aaxa; +aaxb; +aaxc; +aaxd; +aaxe; +aaxf; +aaxg; +aaxh; +aaxi; +aaxj; +aaxk; +aaxl; +aaxm; +aaxn; +aaxo; +aaxp; +aaxq; +aaxr; +aaxs; +aaxt; +aaxu; +aaxv; +aaxw; +aaxx; +aaxy; +aaxz; +aaya; +aayb; +aayc; +aayd; +aaye; +aayf; +aayg; +aayh; +aayi; +aayj; +aayk; +aayl; +aaym; +aayn; +aayo; +aayp; +aayq; +aayr; +aays; +aayt; +aayu; +aayv; +aayw; +aayx; +aayy; +aayz; +aaza; +aazb; +aazc; +aazd; +aaze; +aazf; +aazg; +aazh; +aazi; +aazj; +aazk; +aazl; +aazm; +aazn; +aazo; +aazp; +aazq; +aazr; +aazs; +aazt; +aazu; +aazv; +aazw; +aazx; +aazy; +aazz; +abaa; +abab; +abac; +abad; +abae; +abaf; +abag; +abah; +abai; +abaj; +abak; +abal; +abam; +aban; +abao; +abap; +abaq; +abar; +abas; +abat; +abau; +abav; +abaw; +abax; +abay; +abaz; +abba; +abbb; +abbc; +abbd; +abbe; +abbf; +abbg; +abbh; +abbi; +abbj; +abbk; +abbl; +abbm; +abbn; +abbo; +abbp; +abbq; +abbr; +abbs; +abbt; +abbu; +abbv; +abbw; +abbx; +abby; +abbz; +abca; +abcb; +abcc; +abcd; +abce; +abcf; +abcg; +abch; +abci; +abcj; +abck; +abcl; +abcm; +abcn; +abco; +abcp; +abcq; +abcr; +abcs; +abct; +abcu; +abcv; +abcw; +abcx; +abcy; +abcz; +abda; +abdb; +abdc; +abdd; +abde; +abdf; +abdg; +abdh; +abdi; +abdj; +abdk; +abdl; +abdm; +abdn; +abdo; +abdp; +abdq; +abdr; +abds; +abdt; +abdu; +abdv; +abdw; +abdx; +abdy; +abdz; +abea; +abeb; +abec; +abed; +abee; +abef; +abeg; +abeh; +abei; +abej; +abek; +abel; +abem; +aben; +abeo; +abep; +abeq; +aber; +abes; +abet; +abeu; +abev; +abew; +abex; +abey; +abez; +abfa; +abfb; +abfc; +abfd; +abfe; +abff; +abfg; +abfh; +abfi; +abfj; +abfk; +abfl; +abfm; +abfn; +abfo; +abfp; +abfq; +abfr; +abfs; +abft; +abfu; +abfv; +abfw; +abfx; +abfy; +abfz; +abga; +abgb; +abgc; +abgd; +abge; +abgf; +abgg; +abgh; +abgi; +abgj; +abgk; +abgl; +abgm; +abgn; +abgo; +abgp; +abgq; +abgr; +abgs; +abgt; +abgu; +abgv; +abgw; +abgx; +abgy; +abgz; +abha; +abhb; +abhc; +abhd; +abhe; +abhf; +abhg; +abhh; +abhi; +abhj; +abhk; +abhl; +abhm; +abhn; +abho; +abhp; +abhq; +abhr; +abhs; +abht; +abhu; +abhv; +abhw; +abhx; +abhy; +abhz; +abia; +abib; +abic; +abid; +abie; +abif; +abig; +abih; +abii; +abij; +abik; +abil; +abim; +abin; +abio; +abip; +abiq; +abir; +abis; +abit; +abiu; +abiv; +abiw; +abix; +abiy; +abiz; +abja; +abjb; +abjc; +abjd; +abje; +abjf; +abjg; +abjh; +abji; +abjj; +abjk; +abjl; +abjm; +abjn; +abjo; +abjp; +abjq; +abjr; +abjs; +abjt; +abju; +abjv; +abjw; +abjx; +abjy; +abjz; +abka; +abkb; +abkc; +abkd; +abke; +abkf; +abkg; +abkh; +abki; +abkj; +abkk; +abkl; +abkm; +abkn; +abko; +abkp; +abkq; +abkr; +abks; +abkt; +abku; +abkv; +abkw; +abkx; +abky; +abkz; +abla; +ablb; +ablc; +abld; +able; +ablf; +ablg; +ablh; +abli; +ablj; +ablk; +abll; +ablm; +abln; +ablo; +ablp; +ablq; +ablr; +abls; +ablt; +ablu; +ablv; +ablw; +ablx; +ably; +ablz; +abma; +abmb; +abmc; +abmd; +abme; +abmf; +abmg; +abmh; +abmi; +abmj; +abmk; +abml; +abmm; +abmn; +abmo; +abmp; +abmq; +abmr; +abms; +abmt; +abmu; +abmv; +abmw; +abmx; +abmy; +abmz; +abna; +abnb; +abnc; +abnd; +abne; +abnf; +abng; +abnh; +abni; +abnj; +abnk; +abnl; +abnm; +abnn; +abno; +abnp; +abnq; +abnr; +abns; +abnt; +abnu; +abnv; +abnw; +abnx; +abny; +abnz; +aboa; +abob; +aboc; +abod; +aboe; +abof; +abog; +aboh; +aboi; +aboj; +abok; +abol; +abom; +abon; +aboo; +abop; +aboq; +abor; +abos; +abot; +abou; +abov; +abow; +abox; +aboy; +aboz; +abpa; +abpb; +abpc; +abpd; +abpe; +abpf; +abpg; +abph; +abpi; +abpj; +abpk; +abpl; +abpm; +abpn; +abpo; +abpp; +abpq; +abpr; +abps; +abpt; +abpu; +abpv; +abpw; +abpx; +abpy; +abpz; +abqa; +abqb; +abqc; +abqd; +abqe; +abqf; +abqg; +abqh; +abqi; +abqj; +abqk; +abql; +abqm; +abqn; +abqo; +abqp; +abqq; +abqr; +abqs; +abqt; +abqu; +abqv; +abqw; +abqx; +abqy; +abqz; +abra; +abrb; +abrc; +abrd; +abre; +abrf; +abrg; +abrh; +abri; +abrj; +abrk; +abrl; +abrm; +abrn; +abro; +abrp; +abrq; +abrr; +abrs; +abrt; +abru; +abrv; +abrw; +abrx; +abry; +abrz; +absa; +absb; +absc; +absd; +abse; +absf; +absg; +absh; +absi; +absj; +absk; +absl; +absm; +absn; +abso; +absp; +absq; +absr; +abss; +abst; +absu; +absv; +absw; +absx; +absy; +absz; +abta; +abtb; +abtc; +abtd; +abte; +abtf; +abtg; +abth; +abti; +abtj; +abtk; +abtl; +abtm; +abtn; +abto; +abtp; +abtq; +abtr; +abts; +abtt; +abtu; +abtv; +abtw; +abtx; +abty; +abtz; +abua; +abub; +abuc; +abud; +abue; +abuf; +abug; +abuh; +abui; +abuj; +abuk; +abul; +abum; +abun; +abuo; +abup; +abuq; +abur; +abus; +abut; +abuu; +abuv; +abuw; +abux; +abuy; +abuz; +abva; +abvb; +abvc; +abvd; +abve; +abvf; +abvg; +abvh; +abvi; +abvj; +abvk; +abvl; +abvm; +abvn; +abvo; +abvp; +abvq; +abvr; +abvs; +abvt; +abvu; +abvv; +abvw; +abvx; +abvy; +abvz; +abwa; +abwb; +abwc; +abwd; +abwe; +abwf; +abwg; +abwh; +abwi; +abwj; +abwk; +abwl; +abwm; +abwn; +abwo; +abwp; +abwq; +abwr; +abws; +abwt; +abwu; +abwv; +abww; +abwx; +abwy; +abwz; +abxa; +abxb; +abxc; +abxd; +abxe; +abxf; +abxg; +abxh; +abxi; +abxj; +abxk; +abxl; +abxm; +abxn; +abxo; +abxp; +abxq; +abxr; +abxs; +abxt; +abxu; +abxv; +abxw; +abxx; +abxy; +abxz; +abya; +abyb; +abyc; +abyd; +abye; +abyf; +abyg; +abyh; +abyi; +abyj; +abyk; +abyl; +abym; +abyn; +abyo; +abyp; +abyq; +abyr; +abys; +abyt; +abyu; +abyv; +abyw; +abyx; +abyy; +abyz; +abza; +abzb; +abzc; +abzd; +abze; +abzf; +abzg; +abzh; +abzi; +abzj; +abzk; +abzl; +abzm; +abzn; +abzo; +abzp; +abzq; +abzr; +abzs; +abzt; +abzu; +abzv; +abzw; +abzx; +abzy; +abzz; +acaa; +acab; +acac; +acad; +acae; +acaf; +acag; +acah; +acai; +acaj; +acak; +acal; +acam; +acan; +acao; +acap; +acaq; +acar; +acas; +acat; +acau; +acav; +acaw; +acax; +acay; +acaz; +acba; +acbb; +acbc; +acbd; +acbe; +acbf; +acbg; +acbh; +acbi; +acbj; +acbk; +acbl; +acbm; +acbn; +acbo; +acbp; +acbq; +acbr; +acbs; +acbt; +acbu; +acbv; +acbw; +acbx; +acby; +acbz; +acca; +accb; +accc; +accd; +acce; +accf; +accg; +acch; +acci; +accj; +acck; +accl; +accm; +accn; +acco; +accp; +accq; +accr; +accs; +acct; +accu; +accv; +accw; +accx; +accy; +accz; +acda; +acdb; +acdc; +acdd; +acde; +acdf; +acdg; +acdh; +acdi; +acdj; +acdk; +acdl; +acdm; +acdn; +acdo; +acdp; +acdq; +acdr; +acds; +acdt; +acdu; +acdv; +acdw; +acdx; +acdy; +acdz; +acea; +aceb; +acec; +aced; +acee; +acef; +aceg; +aceh; +acei; +acej; +acek; +acel; +acem; +acen; +aceo; +acep; +aceq; +acer; +aces; +acet; +aceu; +acev; +acew; +acex; +acey; +acez; +acfa; +acfb; +acfc; +acfd; +acfe; +acff; +acfg; +acfh; +acfi; +acfj; +acfk; +acfl; +acfm; +acfn; +acfo; +acfp; +acfq; +acfr; +acfs; +acft; +acfu; +acfv; +acfw; +acfx; +acfy; +acfz; +acga; +acgb; +acgc; +acgd; +acge; +acgf; +acgg; +acgh; +acgi; +acgj; +acgk; +acgl; +acgm; +acgn; +acgo; +acgp; +acgq; +acgr; +acgs; +acgt; +acgu; +acgv; +acgw; +acgx; +acgy; +acgz; +acha; +achb; +achc; +achd; +ache; +achf; +achg; +achh; +achi; +achj; +achk; +achl; +achm; +achn; +acho; +achp; +achq; +achr; +achs; +acht; +achu; +achv; +achw; +achx; +achy; +achz; +acia; +acib; +acic; +acid; +acie; +acif; +acig; +acih; +acii; +acij; +acik; +acil; +acim; +acin; +acio; +acip; +aciq; +acir; +acis; +acit; +aciu; +aciv; +aciw; +acix; +aciy; +aciz; +acja; +acjb; +acjc; +acjd; +acje; +acjf; +acjg; +acjh; +acji; +acjj; +acjk; +acjl; +acjm; +acjn; +acjo; +acjp; +acjq; +acjr; +acjs; +acjt; +acju; +acjv; +acjw; +acjx; +acjy; +acjz; +acka; +ackb; +ackc; +ackd; +acke; +ackf; +ackg; +ackh; +acki; +ackj; +ackk; +ackl; +ackm; +ackn; +acko; +ackp; +ackq; +ackr; +acks; +ackt; +acku; +ackv; +ackw; +ackx; +acky; +ackz; +acla; +aclb; +aclc; +acld; +acle; +aclf; +aclg; +aclh; +acli; +aclj; +aclk; +acll; +aclm; +acln; +aclo; +aclp; +aclq; +aclr; +acls; +aclt; +aclu; +aclv; +aclw; +aclx; +acly; +aclz; +acma; +acmb; +acmc; +acmd; +acme; +acmf; +acmg; +acmh; +acmi; +acmj; +acmk; +acml; +acmm; +acmn; +acmo; +acmp; +acmq; +acmr; +acms; +acmt; +acmu; +acmv; +acmw; +acmx; +acmy; +acmz; +acna; +acnb; +acnc; +acnd; +acne; +acnf; +acng; +acnh; +acni; +acnj; +acnk; +acnl; +acnm; +acnn; +acno; +acnp; +acnq; +acnr; +acns; +acnt; +acnu; +acnv; +acnw; +acnx; +acny; +acnz; +acoa; +acob; +acoc; +acod; +acoe; +acof; +acog; +acoh; +acoi; +acoj; +acok; +acol; +acom; +acon; +acoo; +acop; +acoq; +acor; +acos; +acot; +acou; +acov; +acow; +acox; +acoy; +acoz; +acpa; +acpb; +acpc; +acpd; +acpe; +acpf; +acpg; +acph; +acpi; +acpj; +acpk; +acpl; +acpm; +acpn; +acpo; +acpp; +acpq; +acpr; +acps; +acpt; +acpu; +acpv; +acpw; +acpx; +acpy; +acpz; +acqa; +acqb; +acqc; +acqd; +acqe; +acqf; +acqg; +acqh; +acqi; +acqj; +acqk; +acql; +acqm; +acqn; +acqo; +acqp; +acqq; +acqr; +acqs; +acqt; +acqu; +acqv; +acqw; +acqx; +acqy; +acqz; +acra; +acrb; +acrc; +acrd; +acre; +acrf; +acrg; +acrh; +acri; +acrj; +acrk; +acrl; +acrm; +acrn; +acro; +acrp; +acrq; +acrr; +acrs; +acrt; +acru; +acrv; +acrw; +acrx; +acry; +acrz; +acsa; +acsb; +acsc; +acsd; +acse; +acsf; +acsg; +acsh; +acsi; +acsj; +acsk; +acsl; +acsm; +acsn; +acso; +acsp; +acsq; +acsr; +acss; +acst; +acsu; +acsv; +acsw; +acsx; +acsy; +acsz; +acta; +actb; +actc; +actd; +acte; +actf; +actg; +acth; +acti; +actj; +actk; +actl; +actm; +actn; +acto; +actp; +actq; +actr; +acts; +actt; +actu; +actv; +actw; +actx; +acty; +actz; +acua; +acub; +acuc; +acud; +acue; +acuf; +acug; +acuh; +acui; +acuj; +acuk; +acul; +acum; +acun; +acuo; +acup; +acuq; +acur; +acus; +acut; +acuu; +acuv; +acuw; +acux; +acuy; +acuz; +acva; +acvb; +acvc; +acvd; +acve; +acvf; +acvg; +acvh; +acvi; +acvj; +acvk; +acvl; +acvm; +acvn; +acvo; +acvp; +acvq; +acvr; +acvs; +acvt; +acvu; +acvv; +acvw; +acvx; +acvy; +acvz; +acwa; +acwb; +acwc; +acwd; +acwe; +acwf; +acwg; +acwh; +acwi; +acwj; +acwk; +acwl; +acwm; +acwn; +acwo; +acwp; +acwq; +acwr; +acws; +acwt; +acwu; +acwv; +acww; +acwx; +acwy; +acwz; +acxa; +acxb; +acxc; +acxd; +acxe; +acxf; +acxg; +acxh; +acxi; +acxj; +acxk; +acxl; +acxm; +acxn; +acxo; +acxp; +acxq; +acxr; +acxs; +acxt; +acxu; +acxv; +acxw; +acxx; +acxy; +acxz; +acya; +acyb; +acyc; +acyd; +acye; +acyf; +acyg; +acyh; +acyi; +acyj; +acyk; +acyl; +acym; +acyn; +acyo; +acyp; +acyq; +acyr; +acys; +acyt; +acyu; +acyv; +acyw; +acyx; +acyy; +acyz; +acza; +aczb; +aczc; +aczd; +acze; +aczf; +aczg; +aczh; +aczi; +aczj; +aczk; +aczl; +aczm; +aczn; +aczo; +aczp; +aczq; +aczr; +aczs; +aczt; +aczu; +aczv; +aczw; +aczx; +aczy; +aczz; +adaa; +adab; +adac; +adad; +adae; +adaf; +adag; +adah; +adai; +adaj; +adak; +adal; +adam; +adan; +adao; +adap; +adaq; +adar; +adas; +adat; +adau; +adav; +adaw; +adax; +aday; +adaz; +adba; +adbb; +adbc; +adbd; +adbe; +adbf; +adbg; +adbh; +adbi; +adbj; +adbk; +adbl; +adbm; +adbn; +adbo; +adbp; +adbq; +adbr; +adbs; +adbt; +adbu; +adbv; +adbw; +adbx; +adby; +adbz; +adca; +adcb; +adcc; +adcd; +adce; +adcf; +adcg; +adch; +adci; +adcj; +adck; +adcl; +adcm; +adcn; +adco; +adcp; +adcq; +adcr; +adcs; +adct; +adcu; +adcv; +adcw; +adcx; +adcy; +adcz; +adda; +addb; +addc; +addd; +adde; +addf; +addg; +addh; +addi; +addj; +addk; +addl; +addm; +addn; +addo; +addp; +addq; +addr; +adds; +addt; +addu; +addv; +addw; +addx; +addy; +addz; +adea; +adeb; +adec; +aded; +adee; +adef; +adeg; +adeh; +adei; +adej; +adek; +adel; +adem; +aden; +adeo; +adep; +adeq; +ader; +ades; +adet; +adeu; +adev; +adew; +adex; +adey; +adez; +adfa; +adfb; +adfc; +adfd; +adfe; +adff; +adfg; +adfh; +adfi; +adfj; +adfk; +adfl; +adfm; +adfn; +adfo; +adfp; +adfq; +adfr; +adfs; +adft; +adfu; +adfv; +adfw; +adfx; +adfy; +adfz; +adga; +adgb; +adgc; +adgd; +adge; +adgf; +adgg; +adgh; +adgi; +adgj; +adgk; +adgl; +adgm; +adgn; +adgo; +adgp; +adgq; +adgr; +adgs; +adgt; +adgu; +adgv; +adgw; +adgx; +adgy; +adgz; +adha; +adhb; +adhc; +adhd; +adhe; +adhf; +adhg; +adhh; +adhi; +adhj; +adhk; +adhl; +adhm; +adhn; +adho; +adhp; +adhq; +adhr; +adhs; +adht; +adhu; +adhv; +adhw; +adhx; +adhy; +adhz; +adia; +adib; +adic; +adid; +adie; +adif; +adig; +adih; +adii; +adij; +adik; +adil; +adim; +adin; +adio; +adip; +adiq; +adir; +adis; +adit; +adiu; +adiv; +adiw; +adix; +adiy; +adiz; +adja; +adjb; +adjc; +adjd; +adje; +adjf; +adjg; +adjh; +adji; +adjj; +adjk; +adjl; +adjm; +adjn; +adjo; +adjp; +adjq; +adjr; +adjs; +adjt; +adju; +adjv; +adjw; +adjx; +adjy; +adjz; +adka; +adkb; +adkc; +adkd; +adke; +adkf; +adkg; +adkh; +adki; +adkj; +adkk; +adkl; +adkm; +adkn; +adko; +adkp; +adkq; +adkr; +adks; +adkt; +adku; +adkv; +adkw; +adkx; +adky; +adkz; +adla; +adlb; +adlc; +adld; +adle; +adlf; +adlg; +adlh; +adli; +adlj; +adlk; +adll; +adlm; +adln; +adlo; +adlp; +adlq; +adlr; +adls; +adlt; +adlu; +adlv; +adlw; +adlx; +adly; +adlz; +adma; +admb; +admc; +admd; +adme; +admf; +admg; +admh; +admi; +admj; +admk; +adml; +admm; +admn; +admo; +admp; +admq; +admr; +adms; +admt; +admu; +admv; +admw; +admx; +admy; +admz; +adna; +adnb; +adnc; +adnd; +adne; +adnf; +adng; +adnh; +adni; +adnj; +adnk; +adnl; +adnm; +adnn; +adno; +adnp; +adnq; +adnr; +adns; +adnt; +adnu; +adnv; +adnw; +adnx; +adny; +adnz; +adoa; +adob; +adoc; +adod; +adoe; +adof; +adog; +adoh; +adoi; +adoj; +adok; +adol; +adom; +adon; +adoo; +adop; +adoq; +ador; +ados; +adot; +adou; +adov; +adow; +adox; +adoy; +adoz; +adpa; +adpb; +adpc; +adpd; +adpe; +adpf; +adpg; +adph; +adpi; +adpj; +adpk; +adpl; +adpm; +adpn; +adpo; +adpp; +adpq; +adpr; +adps; +adpt; +adpu; +adpv; +adpw; +adpx; +adpy; +adpz; +adqa; +adqb; +adqc; +adqd; +adqe; +adqf; +adqg; +adqh; +adqi; +adqj; +adqk; +adql; +adqm; +adqn; +adqo; +adqp; +adqq; +adqr; +adqs; +adqt; +adqu; +adqv; +adqw; +adqx; +adqy; +adqz; +adra; +adrb; +adrc; +adrd; +adre; +adrf; +adrg; +adrh; +adri; +adrj; +adrk; +adrl; +adrm; +adrn; +adro; +adrp; +adrq; +adrr; +adrs; +adrt; +adru; +adrv; +adrw; +adrx; +adry; +adrz; +adsa; +adsb; +adsc; +adsd; +adse; +adsf; +adsg; +adsh; +adsi; +adsj; +adsk; +adsl; +adsm; +adsn; +adso; +adsp; +adsq; +adsr; +adss; +adst; +adsu; +adsv; +adsw; +adsx; +adsy; +adsz; +adta; +adtb; +adtc; +adtd; +adte; +adtf; +adtg; +adth; +adti; +adtj; +adtk; +adtl; +adtm; +adtn; +adto; +adtp; +adtq; +adtr; +adts; +adtt; +adtu; +adtv; +adtw; +adtx; +adty; +adtz; +adua; +adub; +aduc; +adud; +adue; +aduf; +adug; +aduh; +adui; +aduj; +aduk; +adul; +adum; +adun; +aduo; +adup; +aduq; +adur; +adus; +adut; +aduu; +aduv; +aduw; +adux; +aduy; +aduz; +adva; +advb; +advc; +advd; +adve; +advf; +advg; +advh; +advi; +advj; +advk; +advl; +advm; +advn; +advo; +advp; +advq; +advr; +advs; +advt; +advu; +advv; +advw; +advx; +advy; +advz; +adwa; +adwb; +adwc; +adwd; +adwe; +adwf; +adwg; +adwh; +adwi; +adwj; +adwk; +adwl; +adwm; +adwn; +adwo; +adwp; +adwq; +adwr; +adws; +adwt; +adwu; +adwv; +adww; +adwx; +adwy; +adwz; +adxa; +adxb; +adxc; +adxd; +adxe; +adxf; +adxg; +adxh; +adxi; +adxj; +adxk; +adxl; +adxm; +adxn; +adxo; +adxp; +adxq; +adxr; +adxs; +adxt; +adxu; +adxv; +adxw; +adxx; +adxy; +adxz; +adya; +adyb; +adyc; +adyd; +adye; +adyf; +adyg; +adyh; +adyi; +adyj; +adyk; +adyl; +adym; +adyn; +adyo; +adyp; +adyq; +adyr; +adys; +adyt; +adyu; +adyv; +adyw; +adyx; +adyy; +adyz; +adza; +adzb; +adzc; +adzd; +adze; +adzf; +adzg; +adzh; +adzi; +adzj; +adzk; +adzl; +adzm; +adzn; +adzo; +adzp; +adzq; +adzr; +adzs; +adzt; +adzu; +adzv; +adzw; +adzx; +adzy; +adzz; +aeaa; +aeab; +aeac; +aead; +aeae; +aeaf; +aeag; +aeah; +aeai; +aeaj; +aeak; +aeal; +aeam; +aean; +aeao; +aeap; +aeaq; +aear; +aeas; +aeat; +aeau; +aeav; +aeaw; +aeax; +aeay; +aeaz; +aeba; +aebb; +aebc; +aebd; +aebe; +aebf; +aebg; +aebh; +aebi; +aebj; +aebk; +aebl; +aebm; +aebn; +aebo; +aebp; +aebq; +aebr; +aebs; +aebt; +aebu; +aebv; +aebw; +aebx; +aeby; +aebz; +aeca; +aecb; +aecc; +aecd; +aece; +aecf; +aecg; +aech; +aeci; +aecj; +aeck; +aecl; +aecm; +aecn; +aeco; +aecp; +aecq; +aecr; +aecs; +aect; +aecu; +aecv; +aecw; +aecx; +aecy; +aecz; +aeda; +aedb; +aedc; +aedd; +aede; +aedf; +aedg; +aedh; +aedi; +aedj; +aedk; +aedl; +aedm; +aedn; +aedo; +aedp; +aedq; +aedr; +aeds; +aedt; +aedu; +aedv; +aedw; +aedx; +aedy; +aedz; +aeea; +aeeb; +aeec; +aeed; +aeee; +aeef; +aeeg; +aeeh; +aeei; +aeej; +aeek; +aeel; +aeem; +aeen; +aeeo; +aeep; +aeeq; +aeer; +aees; +aeet; +aeeu; +aeev; +aeew; +aeex; +aeey; +aeez; +aefa; +aefb; +aefc; +aefd; +aefe; +aeff; +aefg; +aefh; +aefi; +aefj; +aefk; +aefl; +aefm; +aefn; +aefo; +aefp; +aefq; +aefr; +aefs; +aeft; +aefu; +aefv; +aefw; +aefx; +aefy; +aefz; +aega; +aegb; +aegc; +aegd; +aege; +aegf; +aegg; +aegh; +aegi; +aegj; +aegk; +aegl; +aegm; +aegn; +aego; +aegp; +aegq; +aegr; +aegs; +aegt; +aegu; +aegv; +aegw; +aegx; +aegy; +aegz; +aeha; +aehb; +aehc; +aehd; +aehe; +aehf; +aehg; +aehh; +aehi; +aehj; +aehk; +aehl; +aehm; +aehn; +aeho; +aehp; +aehq; +aehr; +aehs; +aeht; +aehu; +aehv; +aehw; +aehx; +aehy; +aehz; +aeia; +aeib; +aeic; +aeid; +aeie; +aeif; +aeig; +aeih; +aeii; +aeij; +aeik; +aeil; +aeim; +aein; +aeio; +aeip; +aeiq; +aeir; +aeis; +aeit; +aeiu; +aeiv; +aeiw; +aeix; +aeiy; +aeiz; +aeja; +aejb; +aejc; +aejd; +aeje; +aejf; +aejg; +aejh; +aeji; +aejj; +aejk; +aejl; +aejm; +aejn; +aejo; +aejp; +aejq; +aejr; +aejs; +aejt; +aeju; +aejv; +aejw; +aejx; +aejy; +aejz; +aeka; +aekb; +aekc; +aekd; +aeke; +aekf; +aekg; +aekh; +aeki; +aekj; +aekk; +aekl; +aekm; +aekn; +aeko; +aekp; +aekq; +aekr; +aeks; +aekt; +aeku; +aekv; +aekw; +aekx; +aeky; +aekz; +aela; +aelb; +aelc; +aeld; +aele; +aelf; +aelg; +aelh; +aeli; +aelj; +aelk; +aell; +aelm; +aeln; +aelo; +aelp; +aelq; +aelr; +aels; +aelt; +aelu; +aelv; +aelw; +aelx; +aely; +aelz; +aema; +aemb; +aemc; +aemd; +aeme; +aemf; +aemg; +aemh; +aemi; +aemj; +aemk; +aeml; +aemm; +aemn; +aemo; +aemp; +aemq; +aemr; +aems; +aemt; +aemu; +aemv; +aemw; +aemx; +aemy; +aemz; +aena; +aenb; +aenc; +aend; +aene; +aenf; +aeng; +aenh; +aeni; +aenj; +aenk; +aenl; +aenm; +aenn; +aeno; +aenp; +aenq; +aenr; +aens; +aent; +aenu; +aenv; +aenw; +aenx; +aeny; +aenz; +aeoa; +aeob; +aeoc; +aeod; +aeoe; +aeof; +aeog; +aeoh; +aeoi; +aeoj; +aeok; +aeol; +aeom; +aeon; +aeoo; +aeop; +aeoq; +aeor; +aeos; +aeot; +aeou; +aeov; +aeow; +aeox; +aeoy; +aeoz; +aepa; +aepb; +aepc; +aepd; +aepe; +aepf; +aepg; +aeph; +aepi; +aepj; +aepk; +aepl; +aepm; +aepn; +aepo; +aepp; +aepq; +aepr; +aeps; +aept; +aepu; +aepv; +aepw; +aepx; +aepy; +aepz; +aeqa; +aeqb; +aeqc; +aeqd; +aeqe; +aeqf; +aeqg; +aeqh; +aeqi; +aeqj; +aeqk; +aeql; +aeqm; +aeqn; +aeqo; +aeqp; +aeqq; +aeqr; +aeqs; +aeqt; +aequ; +aeqv; +aeqw; +aeqx; +aeqy; +aeqz; +aera; +aerb; +aerc; +aerd; +aere; +aerf; +aerg; +aerh; +aeri; +aerj; +aerk; +aerl; +aerm; +aern; +aero; +aerp; +aerq; +aerr; +aers; +aert; +aeru; +aerv; +aerw; +aerx; +aery; +aerz; +aesa; +aesb; +aesc; +aesd; +aese; +aesf; +aesg; +aesh; +aesi; +aesj; +aesk; +aesl; +aesm; +aesn; +aeso; +aesp; +aesq; +aesr; +aess; +aest; +aesu; +aesv; +aesw; +aesx; +aesy; +aesz; +aeta; +aetb; +aetc; +aetd; +aete; +aetf; +aetg; +aeth; +aeti; +aetj; +aetk; +aetl; +aetm; +aetn; +aeto; +aetp; +aetq; +aetr; +aets; +aett; +aetu; +aetv; +aetw; +aetx; +aety; +aetz; +aeua; +aeub; +aeuc; +aeud; +aeue; +aeuf; +aeug; +aeuh; +aeui; +aeuj; +aeuk; +aeul; +aeum; +aeun; +aeuo; +aeup; +aeuq; +aeur; +aeus; +aeut; +aeuu; +aeuv; +aeuw; +aeux; +aeuy; +aeuz; +aeva; +aevb; +aevc; +aevd; +aeve; +aevf; +aevg; +aevh; +aevi; +aevj; +aevk; +aevl; +aevm; +aevn; +aevo; +aevp; +aevq; +aevr; +aevs; +aevt; +aevu; +aevv; +aevw; +aevx; +aevy; +aevz; +aewa; +aewb; +aewc; +aewd; +aewe; +aewf; +aewg; +aewh; +aewi; +aewj; +aewk; +aewl; +aewm; +aewn; +aewo; +aewp; +aewq; +aewr; +aews; +aewt; +aewu; +aewv; +aeww; +aewx; +aewy; +aewz; +aexa; +aexb; +aexc; +aexd; +aexe; +aexf; +aexg; +aexh; +aexi; +aexj; +aexk; +aexl; +aexm; +aexn; +aexo; +aexp; +aexq; +aexr; +aexs; +aext; +aexu; +aexv; +aexw; +aexx; +aexy; +aexz; +aeya; +aeyb; +aeyc; +aeyd; +aeye; +aeyf; +aeyg; +aeyh; +aeyi; +aeyj; +aeyk; +aeyl; +aeym; +aeyn; +aeyo; +aeyp; +aeyq; +aeyr; +aeys; +aeyt; +aeyu; +aeyv; +aeyw; +aeyx; +aeyy; +aeyz; +aeza; +aezb; +aezc; +aezd; +aeze; +aezf; +aezg; +aezh; +aezi; +aezj; +aezk; +aezl; +aezm; +aezn; +aezo; +aezp; +aezq; +aezr; +aezs; +aezt; +aezu; +aezv; +aezw; +aezx; +aezy; +aezz; +afaa; +afab; +afac; +afad; +afae; +afaf; +afag; +afah; +afai; +afaj; +afak; +afal; +afam; +afan; +afao; +afap; +afaq; +afar; +afas; +afat; +afau; +afav; +afaw; +afax; +afay; +afaz; +afba; +afbb; +afbc; +afbd; +afbe; +afbf; +afbg; +afbh; +afbi; +afbj; +afbk; +afbl; +afbm; +afbn; +afbo; +afbp; +afbq; +afbr; +afbs; +afbt; +afbu; +afbv; +afbw; +afbx; +afby; +afbz; +afca; +afcb; +afcc; +afcd; +afce; +afcf; +afcg; +afch; +afci; +afcj; +afck; +afcl; +afcm; +afcn; +afco; +afcp; +afcq; +afcr; +afcs; +afct; +afcu; +afcv; +afcw; +afcx; +afcy; +afcz; +afda; +afdb; +afdc; +afdd; +afde; +afdf; +afdg; +afdh; +afdi; +afdj; +afdk; +afdl; +afdm; +afdn; +afdo; +afdp; +afdq; +afdr; +afds; +afdt; +afdu; +afdv; +afdw; +afdx; +afdy; +afdz; +afea; +afeb; +afec; +afed; +afee; +afef; +afeg; +afeh; +afei; +afej; +afek; +afel; +afem; +afen; +afeo; +afep; +afeq; +afer; +afes; +afet; +afeu; +afev; +afew; +afex; +afey; +afez; +affa; +affb; +affc; +affd; +affe; +afff; +affg; +affh; +affi; +affj; +affk; +affl; +affm; +affn; +affo; +affp; +affq; +affr; +affs; +afft; +affu; +affv; +affw; +affx; +affy; +affz; +afga; +afgb; +afgc; +afgd; +afge; +afgf; +afgg; +afgh; +afgi; +afgj; +afgk; +afgl; +afgm; +afgn; +afgo; +afgp; +afgq; +afgr; +afgs; +afgt; +afgu; +afgv; +afgw; +afgx; +afgy; +afgz; +afha; +afhb; +afhc; +afhd; +afhe; +afhf; +afhg; +afhh; +afhi; +afhj; +afhk; +afhl; +afhm; +afhn; +afho; +afhp; +afhq; +afhr; +afhs; +afht; +afhu; +afhv; +afhw; +afhx; +afhy; +afhz; +afia; +afib; +afic; +afid; +afie; +afif; +afig; +afih; +afii; +afij; +afik; +afil; +afim; +afin; +afio; +afip; +afiq; +afir; +afis; +afit; +afiu; +afiv; +afiw; +afix; +afiy; +afiz; +afja; +afjb; +afjc; +afjd; +afje; +afjf; +afjg; +afjh; +afji; +afjj; +afjk; +afjl; +afjm; +afjn; +afjo; +afjp; +afjq; +afjr; +afjs; +afjt; +afju; +afjv; +afjw; +afjx; +afjy; +afjz; +afka; +afkb; +afkc; +afkd; +afke; +afkf; +afkg; +afkh; +afki; +afkj; +afkk; +afkl; +afkm; +afkn; +afko; +afkp; +afkq; +afkr; +afks; +afkt; +afku; +afkv; +afkw; +afkx; +afky; +afkz; +afla; +aflb; +aflc; +afld; +afle; +aflf; +aflg; +aflh; +afli; +aflj; +aflk; +afll; +aflm; +afln; +aflo; +aflp; +aflq; +aflr; +afls; +aflt; +aflu; +aflv; +aflw; +aflx; +afly; +aflz; +afma; +afmb; +afmc; +afmd; +afme; +afmf; +afmg; +afmh; +afmi; +afmj; +afmk; +afml; +afmm; +afmn; +afmo; +afmp; +afmq; +afmr; +afms; +afmt; +afmu; +afmv; +afmw; +afmx; +afmy; +afmz; +afna; +afnb; +afnc; +afnd; +afne; +afnf; +afng; +afnh; +afni; +afnj; +afnk; +afnl; +afnm; +afnn; +afno; +afnp; +afnq; +afnr; +afns; +afnt; +afnu; +afnv; +afnw; +afnx; +afny; +afnz; +afoa; +afob; +afoc; +afod; +afoe; +afof; +afog; +afoh; +afoi; +afoj; +afok; +afol; +afom; +afon; +afoo; +afop; +afoq; +afor; +afos; +afot; +afou; +afov; +afow; +afox; +afoy; +afoz; +afpa; +afpb; +afpc; +afpd; +afpe; +afpf; +afpg; +afph; +afpi; +afpj; +afpk; +afpl; +afpm; +afpn; +afpo; +afpp; +afpq; +afpr; +afps; +afpt; +afpu; +afpv; +afpw; +afpx; +afpy; +afpz; +afqa; +afqb; +afqc; +afqd; +afqe; +afqf; +afqg; +afqh; +afqi; +afqj; +afqk; +afql; +afqm; +afqn; +afqo; +afqp; +afqq; +afqr; +afqs; +afqt; +afqu; +afqv; +afqw; +afqx; +afqy; +afqz; +afra; +afrb; +afrc; +afrd; +afre; +afrf; +afrg; +afrh; +afri; +afrj; +afrk; +afrl; +afrm; +afrn; +afro; +afrp; +afrq; +afrr; +afrs; +afrt; +afru; +afrv; +afrw; +afrx; +afry; +afrz; +afsa; +afsb; +afsc; +afsd; +afse; +afsf; +afsg; +afsh; +afsi; +afsj; +afsk; +afsl; +afsm; +afsn; +afso; +afsp; +afsq; +afsr; +afss; +afst; +afsu; +afsv; +afsw; +afsx; +afsy; +afsz; +afta; +aftb; +aftc; +aftd; +afte; +aftf; +aftg; +afth; +afti; +aftj; +aftk; +aftl; +aftm; +aftn; +afto; +aftp; +aftq; +aftr; +afts; +aftt; +aftu; +aftv; +aftw; +aftx; +afty; +aftz; +afua; +afub; +afuc; +afud; +afue; +afuf; +afug; +afuh; +afui; +afuj; +afuk; +aful; +afum; +afun; +afuo; +afup; +afuq; +afur; +afus; +afut; +afuu; +afuv; +afuw; +afux; +afuy; +afuz; +afva; +afvb; +afvc; +afvd; +afve; +afvf; +afvg; +afvh; +afvi; +afvj; +afvk; +afvl; +afvm; +afvn; +afvo; +afvp; +afvq; +afvr; +afvs; +afvt; +afvu; +afvv; +afvw; +afvx; +afvy; +afvz; +afwa; +afwb; +afwc; +afwd; +afwe; +afwf; +afwg; +afwh; +afwi; +afwj; +afwk; +afwl; +afwm; +afwn; +afwo; +afwp; +afwq; +afwr; +afws; +afwt; +afwu; +afwv; +afww; +afwx; +afwy; +afwz; +afxa; +afxb; +afxc; +afxd; +afxe; +afxf; +afxg; +afxh; +afxi; +afxj; +afxk; +afxl; +afxm; +afxn; +afxo; +afxp; +afxq; +afxr; +afxs; +afxt; +afxu; +afxv; +afxw; +afxx; +afxy; +afxz; +afya; +afyb; +afyc; +afyd; +afye; +afyf; +afyg; +afyh; +afyi; +afyj; +afyk; +afyl; +afym; +afyn; +afyo; +afyp; +afyq; +afyr; +afys; +afyt; +afyu; +afyv; +afyw; +afyx; +afyy; +afyz; +afza; +afzb; +afzc; +afzd; +afze; +afzf; +afzg; +afzh; +afzi; +afzj; +afzk; +afzl; +afzm; +afzn; +afzo; +afzp; +afzq; +afzr; +afzs; +afzt; +afzu; +afzv; +afzw; +afzx; +afzy; +afzz; +agaa; +agab; +agac; +agad; +agae; +agaf; +agag; +agah; +agai; +agaj; +agak; +agal; +agam; +agan; +agao; +agap; +agaq; +agar; +agas; +agat; +agau; +agav; +agaw; +agax; +agay; +agaz; +agba; +agbb; +agbc; +agbd; +agbe; +agbf; +agbg; +agbh; +agbi; +agbj; +agbk; +agbl; +agbm; +agbn; +agbo; +agbp; +agbq; +agbr; +agbs; +agbt; +agbu; +agbv; +agbw; +agbx; +agby; +agbz; +agca; +agcb; +agcc; +agcd; +agce; +agcf; +agcg; +agch; +agci; +agcj; +agck; +agcl; +agcm; +agcn; +agco; +agcp; +agcq; +agcr; +agcs; +agct; +agcu; +agcv; +agcw; +agcx; +agcy; +agcz; +agda; +agdb; +agdc; +agdd; +agde; +agdf; +agdg; +agdh; +agdi; +agdj; +agdk; +agdl; +agdm; +agdn; +agdo; +agdp; +agdq; +agdr; +agds; +agdt; +agdu; +agdv; +agdw; +agdx; +agdy; +agdz; +agea; +ageb; +agec; +aged; +agee; +agef; +ageg; +ageh; +agei; +agej; +agek; +agel; +agem; +agen; +ageo; +agep; +ageq; +ager; +ages; +aget; +ageu; +agev; +agew; +agex; +agey; +agez; +agfa; +agfb; +agfc; +agfd; +agfe; +agff; +agfg; +agfh; +agfi; +agfj; +agfk; +agfl; +agfm; +agfn; +agfo; +agfp; +agfq; +agfr; +agfs; +agft; +agfu; +agfv; +agfw; +agfx; +agfy; +agfz; +agga; +aggb; +aggc; +aggd; +agge; +aggf; +aggg; +aggh; +aggi; +aggj; +aggk; +aggl; +aggm; +aggn; +aggo; +aggp; +aggq; +aggr; +aggs; +aggt; +aggu; +aggv; +aggw; +aggx; +aggy; +aggz; +agha; +aghb; +aghc; +aghd; +aghe; +aghf; +aghg; +aghh; +aghi; +aghj; +aghk; +aghl; +aghm; +aghn; +agho; +aghp; +aghq; +aghr; +aghs; +aght; +aghu; +aghv; +aghw; +aghx; +aghy; +aghz; +agia; +agib; +agic; +agid; +agie; +agif; +agig; +agih; +agii; +agij; +agik; +agil; +agim; +agin; +agio; +agip; +agiq; +agir; +agis; +agit; +agiu; +agiv; +agiw; +agix; +agiy; +agiz; +agja; +agjb; +agjc; +agjd; +agje; +agjf; +agjg; +agjh; +agji; +agjj; +agjk; +agjl; +agjm; +agjn; +agjo; +agjp; +agjq; +agjr; +agjs; +agjt; +agju; +agjv; +agjw; +agjx; +agjy; +agjz; +agka; +agkb; +agkc; +agkd; +agke; +agkf; +agkg; +agkh; +agki; +agkj; +agkk; +agkl; +agkm; +agkn; +agko; +agkp; +agkq; +agkr; +agks; +agkt; +agku; +agkv; +agkw; +agkx; +agky; +agkz; +agla; +aglb; +aglc; +agld; +agle; +aglf; +aglg; +aglh; +agli; +aglj; +aglk; +agll; +aglm; +agln; +aglo; +aglp; +aglq; +aglr; +agls; +aglt; +aglu; +aglv; +aglw; +aglx; +agly; +aglz; +agma; +agmb; +agmc; +agmd; +agme; +agmf; +agmg; +agmh; +agmi; +agmj; +agmk; +agml; +agmm; +agmn; +agmo; +agmp; +agmq; +agmr; +agms; +agmt; +agmu; +agmv; +agmw; +agmx; +agmy; +agmz; +agna; +agnb; +agnc; +agnd; +agne; +agnf; +agng; +agnh; +agni; +agnj; +agnk; +agnl; +agnm; +agnn; +agno; +agnp; +agnq; +agnr; +agns; +agnt; +agnu; +agnv; +agnw; +agnx; +agny; +agnz; +agoa; +agob; +agoc; +agod; +agoe; +agof; +agog; +agoh; +agoi; +agoj; +agok; +agol; +agom; +agon; +agoo; +agop; +agoq; +agor; +agos; +agot; +agou; +agov; +agow; +agox; +agoy; +agoz; +agpa; +agpb; +agpc; +agpd; +agpe; +agpf; +agpg; +agph; +agpi; +agpj; +agpk; +agpl; +agpm; +agpn; +agpo; +agpp; +agpq; +agpr; +agps; +agpt; +agpu; +agpv; +agpw; +agpx; +agpy; +agpz; +agqa; +agqb; +agqc; +agqd; +agqe; +agqf; +agqg; +agqh; +agqi; +agqj; +agqk; +agql; +agqm; +agqn; +agqo; +agqp; +agqq; +agqr; +agqs; +agqt; +agqu; +agqv; +agqw; +agqx; +agqy; +agqz; +agra; +agrb; +agrc; +agrd; +agre; +agrf; +agrg; +agrh; +agri; +agrj; +agrk; +agrl; +agrm; +agrn; +agro; +agrp; +agrq; +agrr; +agrs; +agrt; +agru; +agrv; +agrw; +agrx; +agry; +agrz; +agsa; +agsb; +agsc; +agsd; +agse; +agsf; +agsg; +agsh; +agsi; +agsj; +agsk; +agsl; +agsm; +agsn; +agso; +agsp; +agsq; +agsr; +agss; +agst; +agsu; +agsv; +agsw; +agsx; +agsy; +agsz; +agta; +agtb; +agtc; +agtd; +agte; +agtf; +agtg; +agth; +agti; +agtj; +agtk; +agtl; +agtm; +agtn; +agto; +agtp; +agtq; +agtr; +agts; +agtt; +agtu; +agtv; +agtw; +agtx; +agty; +agtz; +agua; +agub; +aguc; +agud; +ague; +aguf; +agug; +aguh; +agui; +aguj; +aguk; +agul; +agum; +agun; +aguo; +agup; +aguq; +agur; +agus; +agut; +aguu; +aguv; +aguw; +agux; +aguy; +aguz; +agva; +agvb; +agvc; +agvd; +agve; +agvf; +agvg; +agvh; +agvi; +agvj; +agvk; +agvl; +agvm; +agvn; +agvo; +agvp; +agvq; +agvr; +agvs; +agvt; +agvu; +agvv; +agvw; +agvx; +agvy; +agvz; +agwa; +agwb; +agwc; +agwd; +agwe; +agwf; +agwg; +agwh; +agwi; +agwj; +agwk; +agwl; +agwm; +agwn; +agwo; +agwp; +agwq; +agwr; +agws; +agwt; +agwu; +agwv; +agww; +agwx; +agwy; +agwz; +agxa; +agxb; +agxc; +agxd; +agxe; +agxf; +agxg; +agxh; +agxi; +agxj; +agxk; +agxl; +agxm; +agxn; +agxo; +agxp; +agxq; +agxr; +agxs; +agxt; +agxu; +agxv; +agxw; +agxx; +agxy; +agxz; +agya; +agyb; +agyc; +agyd; +agye; +agyf; +agyg; +agyh; +agyi; +agyj; +agyk; +agyl; +agym; +agyn; +agyo; +agyp; +agyq; +agyr; +agys; +agyt; +agyu; +agyv; +agyw; +agyx; +agyy; +agyz; +agza; +agzb; +agzc; +agzd; +agze; +agzf; +agzg; +agzh; +agzi; +agzj; +agzk; +agzl; +agzm; +agzn; +agzo; +agzp; +agzq; +agzr; +agzs; +agzt; +agzu; +agzv; +agzw; +agzx; +agzy; +agzz; +ahaa; +ahab; +ahac; +ahad; +ahae; +ahaf; +ahag; +ahah; +ahai; +ahaj; +ahak; +ahal; +aham; +ahan; +ahao; +ahap; +ahaq; +ahar; +ahas; +ahat; +ahau; +ahav; +ahaw; +ahax; +ahay; +ahaz; +ahba; +ahbb; +ahbc; +ahbd; +ahbe; +ahbf; +ahbg; +ahbh; +ahbi; +ahbj; +ahbk; +ahbl; +ahbm; +ahbn; +ahbo; +ahbp; +ahbq; +ahbr; +ahbs; +ahbt; +ahbu; +ahbv; +ahbw; +ahbx; +ahby; +ahbz; +ahca; +ahcb; +ahcc; +ahcd; +ahce; +ahcf; +ahcg; +ahch; +ahci; +ahcj; +ahck; +ahcl; +ahcm; +ahcn; +ahco; +ahcp; +ahcq; +ahcr; +ahcs; +ahct; +ahcu; +ahcv; +ahcw; +ahcx; +ahcy; +ahcz; +ahda; +ahdb; +ahdc; +ahdd; +ahde; +ahdf; +ahdg; +ahdh; +ahdi; +ahdj; +ahdk; +ahdl; +ahdm; +ahdn; +ahdo; +ahdp; +ahdq; +ahdr; +ahds; +ahdt; +ahdu; +ahdv; +ahdw; +ahdx; +ahdy; +ahdz; +ahea; +aheb; +ahec; +ahed; +ahee; +ahef; +aheg; +aheh; +ahei; +ahej; +ahek; +ahel; +ahem; +ahen; +aheo; +ahep; +aheq; +aher; +ahes; +ahet; +aheu; +ahev; +ahew; +ahex; +ahey; +ahez; +ahfa; +ahfb; +ahfc; +ahfd; +ahfe; +ahff; +ahfg; +ahfh; +ahfi; +ahfj; +ahfk; +ahfl; +ahfm; +ahfn; +ahfo; +ahfp; +ahfq; +ahfr; +ahfs; +ahft; +ahfu; +ahfv; +ahfw; +ahfx; +ahfy; +ahfz; +ahga; +ahgb; +ahgc; +ahgd; +ahge; +ahgf; +ahgg; +ahgh; +ahgi; +ahgj; +ahgk; +ahgl; +ahgm; +ahgn; +ahgo; +ahgp; +ahgq; +ahgr; +ahgs; +ahgt; +ahgu; +ahgv; +ahgw; +ahgx; +ahgy; +ahgz; +ahha; +ahhb; +ahhc; +ahhd; +ahhe; +ahhf; +ahhg; +ahhh; +ahhi; +ahhj; +ahhk; +ahhl; +ahhm; +ahhn; +ahho; +ahhp; +ahhq; +ahhr; +ahhs; +ahht; +ahhu; +ahhv; +ahhw; +ahhx; +ahhy; +ahhz; +ahia; +ahib; +ahic; +ahid; +ahie; +ahif; +ahig; +ahih; +ahii; +ahij; +ahik; +ahil; +ahim; +ahin; +ahio; +ahip; +ahiq; +ahir; +ahis; +ahit; +ahiu; +ahiv; +ahiw; +ahix; +ahiy; +ahiz; +ahja; +ahjb; +ahjc; +ahjd; +ahje; +ahjf; +ahjg; +ahjh; +ahji; +ahjj; +ahjk; +ahjl; +ahjm; +ahjn; +ahjo; +ahjp; +ahjq; +ahjr; +ahjs; +ahjt; +ahju; +ahjv; +ahjw; +ahjx; +ahjy; +ahjz; +ahka; +ahkb; +ahkc; +ahkd; +ahke; +ahkf; +ahkg; +ahkh; +ahki; +ahkj; +ahkk; +ahkl; +ahkm; +ahkn; +ahko; +ahkp; +ahkq; +ahkr; +ahks; +ahkt; +ahku; +ahkv; +ahkw; +ahkx; +ahky; +ahkz; +ahla; +ahlb; +ahlc; +ahld; +ahle; +ahlf; +ahlg; +ahlh; +ahli; +ahlj; +ahlk; +ahll; +ahlm; +ahln; +ahlo; +ahlp; +ahlq; +ahlr; +ahls; +ahlt; +ahlu; +ahlv; +ahlw; +ahlx; +ahly; +ahlz; +ahma; +ahmb; +ahmc; +ahmd; +ahme; +ahmf; +ahmg; +ahmh; +ahmi; +ahmj; +ahmk; +ahml; +ahmm; +ahmn; +ahmo; +ahmp; +ahmq; +ahmr; +ahms; +ahmt; +ahmu; +ahmv; +ahmw; +ahmx; +ahmy; +ahmz; +ahna; +ahnb; +ahnc; +ahnd; +ahne; +ahnf; +ahng; +ahnh; +ahni; +ahnj; +ahnk; +ahnl; +ahnm; +ahnn; +ahno; +ahnp; +ahnq; +ahnr; +ahns; +ahnt; +ahnu; +ahnv; +ahnw; +ahnx; +ahny; +ahnz; +ahoa; +ahob; +ahoc; +ahod; +ahoe; +ahof; +ahog; +ahoh; +ahoi; +ahoj; +ahok; +ahol; +ahom; +ahon; +ahoo; +ahop; +ahoq; +ahor; +ahos; +ahot; +ahou; +ahov; +ahow; +ahox; +ahoy; +ahoz; +ahpa; +ahpb; +ahpc; +ahpd; +ahpe; +ahpf; +ahpg; +ahph; +ahpi; +ahpj; +ahpk; +ahpl; +ahpm; +ahpn; +ahpo; +ahpp; +ahpq; +ahpr; +ahps; +ahpt; +ahpu; +ahpv; +ahpw; +ahpx; +ahpy; +ahpz; +ahqa; +ahqb; +ahqc; +ahqd; +ahqe; +ahqf; +ahqg; +ahqh; +ahqi; +ahqj; +ahqk; +ahql; +ahqm; +ahqn; +ahqo; +ahqp; +ahqq; +ahqr; +ahqs; +ahqt; +ahqu; +ahqv; +ahqw; +ahqx; +ahqy; +ahqz; +ahra; +ahrb; +ahrc; +ahrd; +ahre; +ahrf; +ahrg; +ahrh; +ahri; +ahrj; +ahrk; +ahrl; +ahrm; +ahrn; +ahro; +ahrp; +ahrq; +ahrr; +ahrs; +ahrt; +ahru; +ahrv; +ahrw; +ahrx; +ahry; +ahrz; +ahsa; +ahsb; +ahsc; +ahsd; +ahse; +ahsf; +ahsg; +ahsh; +ahsi; +ahsj; +ahsk; +ahsl; +ahsm; +ahsn; +ahso; +ahsp; +ahsq; +ahsr; +ahss; +ahst; +ahsu; +ahsv; +ahsw; +ahsx; +ahsy; +ahsz; +ahta; +ahtb; +ahtc; +ahtd; +ahte; +ahtf; +ahtg; +ahth; +ahti; +ahtj; +ahtk; +ahtl; +ahtm; +ahtn; +ahto; +ahtp; +ahtq; +ahtr; +ahts; +ahtt; +ahtu; +ahtv; +ahtw; +ahtx; +ahty; +ahtz; +ahua; +ahub; +ahuc; +ahud; +ahue; +ahuf; +ahug; +ahuh; +ahui; +ahuj; +ahuk; +ahul; +ahum; +ahun; +ahuo; +ahup; +ahuq; +ahur; +ahus; +ahut; +ahuu; +ahuv; +ahuw; +ahux; +ahuy; +ahuz; +ahva; +ahvb; +ahvc; +ahvd; +ahve; +ahvf; +ahvg; +ahvh; +ahvi; +ahvj; +ahvk; +ahvl; +ahvm; +ahvn; +ahvo; +ahvp; +ahvq; +ahvr; +ahvs; +ahvt; +ahvu; +ahvv; +ahvw; +ahvx; +ahvy; +ahvz; +ahwa; +ahwb; +ahwc; +ahwd; +ahwe; +ahwf; +ahwg; +ahwh; +ahwi; +ahwj; +ahwk; +ahwl; +ahwm; +ahwn; +ahwo; +ahwp; +ahwq; +ahwr; +ahws; +ahwt; +ahwu; +ahwv; +ahww; +ahwx; +ahwy; +ahwz; +ahxa; +ahxb; +ahxc; +ahxd; +ahxe; +ahxf; +ahxg; +ahxh; +ahxi; +ahxj; +ahxk; +ahxl; +ahxm; +ahxn; +ahxo; +ahxp; +ahxq; +ahxr; +ahxs; +ahxt; +ahxu; +ahxv; +ahxw; +ahxx; +ahxy; +ahxz; +ahya; +ahyb; +ahyc; +ahyd; +ahye; +ahyf; +ahyg; +ahyh; +ahyi; +ahyj; +ahyk; +ahyl; +ahym; +ahyn; +ahyo; +ahyp; +ahyq; +ahyr; +ahys; +ahyt; +ahyu; +ahyv; +ahyw; +ahyx; +ahyy; +ahyz; +ahza; +ahzb; +ahzc; +ahzd; +ahze; +ahzf; +ahzg; +ahzh; +ahzi; +ahzj; +ahzk; +ahzl; +ahzm; +ahzn; +ahzo; +ahzp; +ahzq; +ahzr; +ahzs; +ahzt; +ahzu; +ahzv; +ahzw; +ahzx; +ahzy; +ahzz; +aiaa; +aiab; +aiac; +aiad; +aiae; +aiaf; +aiag; +aiah; +aiai; +aiaj; +aiak; +aial; +aiam; +aian; +aiao; +aiap; +aiaq; +aiar; +aias; +aiat; +aiau; +aiav; +aiaw; +aiax; +aiay; +aiaz; +aiba; +aibb; +aibc; +aibd; +aibe; +aibf; +aibg; +aibh; +aibi; +aibj; +aibk; +aibl; +aibm; +aibn; +aibo; +aibp; +aibq; +aibr; +aibs; +aibt; +aibu; +aibv; +aibw; +aibx; +aiby; +aibz; +aica; +aicb; +aicc; +aicd; +aice; +aicf; +aicg; +aich; +aici; +aicj; +aick; +aicl; +aicm; +aicn; +aico; +aicp; +aicq; +aicr; +aics; +aict; +aicu; +aicv; +aicw; +aicx; +aicy; +aicz; +aida; +aidb; +aidc; +aidd; +aide; +aidf; +aidg; +aidh; +aidi; +aidj; +aidk; +aidl; +aidm; +aidn; +aido; +aidp; +aidq; +aidr; +aids; +aidt; +aidu; +aidv; +aidw; +aidx; +aidy; +aidz; +aiea; +aieb; +aiec; +aied; +aiee; +aief; +aieg; +aieh; +aiei; +aiej; +aiek; +aiel; +aiem; +aien; +aieo; +aiep; +aieq; +aier; +aies; +aiet; +aieu; +aiev; +aiew; +aiex; +aiey; +aiez; +aifa; +aifb; +aifc; +aifd; +aife; +aiff; +aifg; +aifh; +aifi; +aifj; +aifk; +aifl; +aifm; +aifn; +aifo; +aifp; +aifq; +aifr; +aifs; +aift; +aifu; +aifv; +aifw; +aifx; +aify; +aifz; +aiga; +aigb; +aigc; +aigd; +aige; +aigf; +aigg; +aigh; +aigi; +aigj; +aigk; +aigl; +aigm; +aign; +aigo; +aigp; +aigq; +aigr; +aigs; +aigt; +aigu; +aigv; +aigw; +aigx; +aigy; +aigz; +aiha; +aihb; +aihc; +aihd; +aihe; +aihf; +aihg; +aihh; +aihi; +aihj; +aihk; +aihl; +aihm; +aihn; +aiho; +aihp; +aihq; +aihr; +aihs; +aiht; +aihu; +aihv; +aihw; +aihx; +aihy; +aihz; +aiia; +aiib; +aiic; +aiid; +aiie; +aiif; +aiig; +aiih; +aiii; +aiij; +aiik; +aiil; +aiim; +aiin; +aiio; +aiip; +aiiq; +aiir; +aiis; +aiit; +aiiu; +aiiv; +aiiw; +aiix; +aiiy; +aiiz; +aija; +aijb; +aijc; +aijd; +aije; +aijf; +aijg; +aijh; +aiji; +aijj; +aijk; +aijl; +aijm; +aijn; +aijo; +aijp; +aijq; +aijr; +aijs; +aijt; +aiju; +aijv; +aijw; +aijx; +aijy; +aijz; +aika; +aikb; +aikc; +aikd; +aike; +aikf; +aikg; +aikh; +aiki; +aikj; +aikk; +aikl; +aikm; +aikn; +aiko; +aikp; +aikq; +aikr; +aiks; +aikt; +aiku; +aikv; +aikw; +aikx; +aiky; +aikz; +aila; +ailb; +ailc; +aild; +aile; +ailf; +ailg; +ailh; +aili; +ailj; +ailk; +aill; +ailm; +ailn; +ailo; +ailp; +ailq; +ailr; +ails; +ailt; +ailu; +ailv; +ailw; +ailx; +aily; +ailz; +aima; +aimb; +aimc; +aimd; +aime; +aimf; +aimg; +aimh; +aimi; +aimj; +aimk; +aiml; +aimm; +aimn; +aimo; +aimp; +aimq; +aimr; +aims; +aimt; +aimu; +aimv; +aimw; +aimx; +aimy; +aimz; +aina; +ainb; +ainc; +aind; +aine; +ainf; +aing; +ainh; +aini; +ainj; +aink; +ainl; +ainm; +ainn; +aino; +ainp; +ainq; +ainr; +ains; +aint; +ainu; +ainv; +ainw; +ainx; +ainy; +ainz; +aioa; +aiob; +aioc; +aiod; +aioe; +aiof; +aiog; +aioh; +aioi; +aioj; +aiok; +aiol; +aiom; +aion; +aioo; +aiop; +aioq; +aior; +aios; +aiot; +aiou; +aiov; +aiow; +aiox; +aioy; +aioz; +aipa; +aipb; +aipc; +aipd; +aipe; +aipf; +aipg; +aiph; +aipi; +aipj; +aipk; +aipl; +aipm; +aipn; +aipo; +aipp; +aipq; +aipr; +aips; +aipt; +aipu; +aipv; +aipw; +aipx; +aipy; +aipz; +aiqa; +aiqb; +aiqc; +aiqd; +aiqe; +aiqf; +aiqg; +aiqh; +aiqi; +aiqj; +aiqk; +aiql; +aiqm; +aiqn; +aiqo; +aiqp; +aiqq; +aiqr; +aiqs; +aiqt; +aiqu; +aiqv; +aiqw; +aiqx; +aiqy; +aiqz; +aira; +airb; +airc; +aird; +aire; +airf; +airg; +airh; +airi; +airj; +airk; +airl; +airm; +airn; +airo; +airp; +airq; +airr; +airs; +airt; +airu; +airv; +airw; +airx; +airy; +airz; +aisa; +aisb; +aisc; +aisd; +aise; +aisf; +aisg; +aish; +aisi; +aisj; +aisk; +aisl; +aism; +aisn; +aiso; +aisp; +aisq; +aisr; +aiss; +aist; +aisu; +aisv; +aisw; +aisx; +aisy; +aisz; +aita; +aitb; +aitc; +aitd; +aite; +aitf; +aitg; +aith; +aiti; +aitj; +aitk; +aitl; +aitm; +aitn; +aito; +aitp; +aitq; +aitr; +aits; +aitt; +aitu; +aitv; +aitw; +aitx; +aity; +aitz; +aiua; +aiub; +aiuc; +aiud; +aiue; +aiuf; +aiug; +aiuh; +aiui; +aiuj; +aiuk; +aiul; +aium; +aiun; +aiuo; +aiup; +aiuq; +aiur; +aius; +aiut; +aiuu; +aiuv; +aiuw; +aiux; +aiuy; +aiuz; +aiva; +aivb; +aivc; +aivd; +aive; +aivf; +aivg; +aivh; +aivi; +aivj; +aivk; +aivl; +aivm; +aivn; +aivo; +aivp; +aivq; +aivr; +aivs; +aivt; +aivu; +aivv; +aivw; +aivx; +aivy; +aivz; +aiwa; +aiwb; +aiwc; +aiwd; +aiwe; +aiwf; +aiwg; +aiwh; +aiwi; +aiwj; +aiwk; +aiwl; +aiwm; +aiwn; +aiwo; +aiwp; +aiwq; +aiwr; +aiws; +aiwt; +aiwu; +aiwv; +aiww; +aiwx; +aiwy; +aiwz; +aixa; +aixb; +aixc; +aixd; +aixe; +aixf; +aixg; +aixh; +aixi; +aixj; +aixk; +aixl; +aixm; +aixn; +aixo; +aixp; +aixq; +aixr; +aixs; +aixt; +aixu; +aixv; +aixw; +aixx; +aixy; +aixz; +aiya; +aiyb; +aiyc; +aiyd; +aiye; +aiyf; +aiyg; +aiyh; +aiyi; +aiyj; +aiyk; +aiyl; +aiym; +aiyn; +aiyo; +aiyp; +aiyq; +aiyr; +aiys; +aiyt; +aiyu; +aiyv; +aiyw; +aiyx; +aiyy; +aiyz; +aiza; +aizb; +aizc; +aizd; +aize; +aizf; +aizg; +aizh; +aizi; +aizj; +aizk; +aizl; +aizm; +aizn; +aizo; +aizp; +aizq; +aizr; +aizs; +aizt; +aizu; +aizv; +aizw; +aizx; +aizy; +aizz; +ajaa; +ajab; +ajac; +ajad; +ajae; +ajaf; +ajag; +ajah; +ajai; +ajaj; +ajak; +ajal; +ajam; +ajan; +ajao; +ajap; +ajaq; +ajar; +ajas; +ajat; +ajau; +ajav; +ajaw; +ajax; +ajay; +ajaz; +ajba; +ajbb; +ajbc; +ajbd; +ajbe; +ajbf; +ajbg; +ajbh; +ajbi; +ajbj; +ajbk; +ajbl; +ajbm; +ajbn; +ajbo; +ajbp; +ajbq; +ajbr; +ajbs; +ajbt; +ajbu; +ajbv; +ajbw; +ajbx; +ajby; +ajbz; +ajca; +ajcb; +ajcc; +ajcd; +ajce; +ajcf; +ajcg; +ajch; +ajci; +ajcj; +ajck; +ajcl; +ajcm; +ajcn; +ajco; +ajcp; +ajcq; +ajcr; +ajcs; +ajct; +ajcu; +ajcv; +ajcw; +ajcx; +ajcy; +ajcz; +ajda; +ajdb; +ajdc; +ajdd; +ajde; +ajdf; +ajdg; +ajdh; +ajdi; +ajdj; +ajdk; +ajdl; +ajdm; +ajdn; +ajdo; +ajdp; +ajdq; +ajdr; +ajds; +ajdt; +ajdu; +ajdv; +ajdw; +ajdx; +ajdy; +ajdz; +ajea; +ajeb; +ajec; +ajed; +ajee; +ajef; +ajeg; +ajeh; +ajei; +ajej; +ajek; +ajel; +ajem; +ajen; +ajeo; +ajep; +ajeq; +ajer; +ajes; +ajet; +ajeu; +ajev; +ajew; +ajex; +ajey; +ajez; +ajfa; +ajfb; +ajfc; +ajfd; +ajfe; +ajff; +ajfg; +ajfh; +ajfi; +ajfj; +ajfk; +ajfl; +ajfm; +ajfn; +ajfo; +ajfp; +ajfq; +ajfr; +ajfs; +ajft; +ajfu; +ajfv; +ajfw; +ajfx; +ajfy; +ajfz; +ajga; +ajgb; +ajgc; +ajgd; +ajge; +ajgf; +ajgg; +ajgh; +ajgi; +ajgj; +ajgk; +ajgl; +ajgm; +ajgn; +ajgo; +ajgp; +ajgq; +ajgr; +ajgs; +ajgt; +ajgu; +ajgv; +ajgw; +ajgx; +ajgy; +ajgz; +ajha; +ajhb; +ajhc; +ajhd; +ajhe; +ajhf; +ajhg; +ajhh; +ajhi; +ajhj; +ajhk; +ajhl; +ajhm; +ajhn; +ajho; +ajhp; +ajhq; +ajhr; +ajhs; +ajht; +ajhu; +ajhv; +ajhw; +ajhx; +ajhy; +ajhz; +ajia; +ajib; +ajic; +ajid; +ajie; +ajif; +ajig; +ajih; +ajii; +ajij; +ajik; +ajil; +ajim; +ajin; +ajio; +ajip; +ajiq; +ajir; +ajis; +ajit; +ajiu; +ajiv; +ajiw; +ajix; +ajiy; +ajiz; +ajja; +ajjb; +ajjc; +ajjd; +ajje; +ajjf; +ajjg; +ajjh; +ajji; +ajjj; +ajjk; +ajjl; +ajjm; +ajjn; +ajjo; +ajjp; +ajjq; +ajjr; +ajjs; +ajjt; +ajju; +ajjv; +ajjw; +ajjx; +ajjy; +ajjz; +ajka; +ajkb; +ajkc; +ajkd; +ajke; +ajkf; +ajkg; +ajkh; +ajki; +ajkj; +ajkk; +ajkl; +ajkm; +ajkn; +ajko; +ajkp; +ajkq; +ajkr; +ajks; +ajkt; +ajku; +ajkv; +ajkw; +ajkx; +ajky; +ajkz; +ajla; +ajlb; +ajlc; +ajld; +ajle; +ajlf; +ajlg; +ajlh; +ajli; +ajlj; +ajlk; +ajll; +ajlm; +ajln; +ajlo; +ajlp; +ajlq; +ajlr; +ajls; +ajlt; +ajlu; +ajlv; +ajlw; +ajlx; +ajly; +ajlz; +ajma; +ajmb; +ajmc; +ajmd; +ajme; +ajmf; +ajmg; +ajmh; +ajmi; +ajmj; +ajmk; +ajml; +ajmm; +ajmn; +ajmo; +ajmp; +ajmq; +ajmr; +ajms; +ajmt; +ajmu; +ajmv; +ajmw; +ajmx; +ajmy; +ajmz; +ajna; +ajnb; +ajnc; +ajnd; +ajne; +ajnf; +ajng; +ajnh; +ajni; +ajnj; +ajnk; +ajnl; +ajnm; +ajnn; +ajno; +ajnp; +ajnq; +ajnr; +ajns; +ajnt; +ajnu; +ajnv; +ajnw; +ajnx; +ajny; +ajnz; +ajoa; +ajob; +ajoc; +ajod; +ajoe; +ajof; +ajog; +ajoh; +ajoi; +ajoj; +ajok; +ajol; +ajom; +ajon; +ajoo; +ajop; +ajoq; +ajor; +ajos; +ajot; +ajou; +ajov; +ajow; +ajox; +ajoy; +ajoz; +ajpa; +ajpb; +ajpc; +ajpd; +ajpe; +ajpf; +ajpg; +ajph; +ajpi; +ajpj; +ajpk; +ajpl; +ajpm; +ajpn; +ajpo; +ajpp; +ajpq; +ajpr; +ajps; +ajpt; +ajpu; +ajpv; +ajpw; +ajpx; +ajpy; +ajpz; +ajqa; +ajqb; +ajqc; +ajqd; +ajqe; +ajqf; +ajqg; +ajqh; +ajqi; +ajqj; +ajqk; +ajql; +ajqm; +ajqn; +ajqo; +ajqp; +ajqq; +ajqr; +ajqs; +ajqt; +ajqu; +ajqv; +ajqw; +ajqx; +ajqy; +ajqz; +ajra; +ajrb; +ajrc; +ajrd; +ajre; +ajrf; +ajrg; +ajrh; +ajri; +ajrj; +ajrk; +ajrl; +ajrm; +ajrn; +ajro; +ajrp; +ajrq; +ajrr; +ajrs; +ajrt; +ajru; +ajrv; +ajrw; +ajrx; +ajry; +ajrz; +ajsa; +ajsb; +ajsc; +ajsd; +ajse; +ajsf; +ajsg; +ajsh; +ajsi; +ajsj; +ajsk; +ajsl; +ajsm; +ajsn; +ajso; +ajsp; +ajsq; +ajsr; +ajss; +ajst; +ajsu; +ajsv; +ajsw; +ajsx; +ajsy; +ajsz; +ajta; +ajtb; +ajtc; +ajtd; +ajte; +ajtf; +ajtg; +ajth; +ajti; +ajtj; +ajtk; +ajtl; +ajtm; +ajtn; +ajto; +ajtp; +ajtq; +ajtr; +ajts; +ajtt; +ajtu; +ajtv; +ajtw; +ajtx; +ajty; +ajtz; +ajua; +ajub; +ajuc; +ajud; +ajue; +ajuf; +ajug; +ajuh; +ajui; +ajuj; +ajuk; +ajul; +ajum; +ajun; +ajuo; +ajup; +ajuq; +ajur; +ajus; +ajut; +ajuu; +ajuv; +ajuw; +ajux; +ajuy; +ajuz; +ajva; +ajvb; +ajvc; +ajvd; +ajve; +ajvf; +ajvg; +ajvh; +ajvi; +ajvj; +ajvk; +ajvl; +ajvm; +ajvn; +ajvo; +ajvp; +ajvq; +ajvr; +ajvs; +ajvt; +ajvu; +ajvv; +ajvw; +ajvx; +ajvy; +ajvz; +ajwa; +ajwb; +ajwc; +ajwd; +ajwe; +ajwf; +ajwg; +ajwh; +ajwi; +ajwj; +ajwk; +ajwl; +ajwm; +ajwn; +ajwo; +ajwp; +ajwq; +ajwr; +ajws; +ajwt; +ajwu; +ajwv; +ajww; +ajwx; +ajwy; +ajwz; +ajxa; +ajxb; +ajxc; +ajxd; +ajxe; +ajxf; +ajxg; +ajxh; +ajxi; +ajxj; +ajxk; +ajxl; +ajxm; +ajxn; +ajxo; +ajxp; +ajxq; +ajxr; +ajxs; +ajxt; +ajxu; +ajxv; +ajxw; +ajxx; +ajxy; +ajxz; +ajya; +ajyb; +ajyc; +ajyd; +ajye; +ajyf; +ajyg; +ajyh; +ajyi; +ajyj; +ajyk; +ajyl; +ajym; +ajyn; +ajyo; +ajyp; +ajyq; +ajyr; +ajys; +ajyt; +ajyu; +ajyv; +ajyw; +ajyx; +ajyy; +ajyz; +ajza; +ajzb; +ajzc; +ajzd; +ajze; +ajzf; +ajzg; +ajzh; +ajzi; +ajzj; +ajzk; +ajzl; +ajzm; +ajzn; +ajzo; +ajzp; +ajzq; +ajzr; +ajzs; +ajzt; +ajzu; +ajzv; +ajzw; +ajzx; +ajzy; +ajzz; +akaa; +akab; +akac; +akad; +akae; +akaf; +akag; +akah; +akai; +akaj; +akak; +akal; +akam; +akan; +akao; +akap; +akaq; +akar; +akas; +akat; +akau; +akav; +akaw; +akax; +akay; +akaz; +akba; +akbb; +akbc; +akbd; +akbe; +akbf; +akbg; +akbh; +akbi; +akbj; +akbk; +akbl; +akbm; +akbn; +akbo; +akbp; +akbq; +akbr; +akbs; +akbt; +akbu; +akbv; +akbw; +akbx; +akby; +akbz; +akca; +akcb; +akcc; +akcd; +akce; +akcf; +akcg; +akch; +akci; +akcj; +akck; +akcl; +akcm; +akcn; +akco; +akcp; +akcq; +akcr; +akcs; +akct; +akcu; +akcv; +akcw; +akcx; +akcy; +akcz; +akda; +akdb; +akdc; +akdd; +akde; +akdf; +akdg; +akdh; +akdi; +akdj; +akdk; +akdl; +akdm; +akdn; +akdo; +akdp; +akdq; +akdr; +akds; +akdt; +akdu; +akdv; +akdw; +akdx; +akdy; +akdz; +akea; +akeb; +akec; +aked; +akee; +akef; +akeg; +akeh; +akei; +akej; +akek; +akel; +akem; +aken; +akeo; +akep; +akeq; +aker; +akes; +aket; +akeu; +akev; +akew; +akex; +akey; +akez; +akfa; +akfb; +akfc; +akfd; +akfe; +akff; +akfg; +akfh; +akfi; +akfj; +akfk; +akfl; +akfm; +akfn; +akfo; +akfp; +akfq; +akfr; +akfs; +akft; +akfu; +akfv; +akfw; +akfx; +akfy; +akfz; +akga; +akgb; +akgc; +akgd; +akge; +akgf; +akgg; +akgh; +akgi; +akgj; +akgk; +akgl; +akgm; +akgn; +akgo; +akgp; +akgq; +akgr; +akgs; +akgt; +akgu; +akgv; +akgw; +akgx; +akgy; +akgz; +akha; +akhb; +akhc; +akhd; +akhe; +akhf; +akhg; +akhh; +akhi; +akhj; +akhk; +akhl; +akhm; +akhn; +akho; +akhp; +akhq; +akhr; +akhs; +akht; +akhu; +akhv; +akhw; +akhx; +akhy; +akhz; +akia; +akib; +akic; +akid; +akie; +akif; +akig; +akih; +akii; +akij; +akik; +akil; +akim; +akin; +akio; +akip; +akiq; +akir; +akis; +akit; +akiu; +akiv; +akiw; +akix; +akiy; +akiz; +akja; +akjb; +akjc; +akjd; +akje; +akjf; +akjg; +akjh; +akji; +akjj; +akjk; +akjl; +akjm; +akjn; +akjo; +akjp; +akjq; +akjr; +akjs; +akjt; +akju; +akjv; +akjw; +akjx; +akjy; +akjz; +akka; +akkb; +akkc; +akkd; +akke; +akkf; +akkg; +akkh; +akki; +akkj; +akkk; +akkl; +akkm; +akkn; +akko; +akkp; +akkq; +akkr; +akks; +akkt; +akku; +akkv; +akkw; +akkx; +akky; +akkz; +akla; +aklb; +aklc; +akld; +akle; +aklf; +aklg; +aklh; +akli; +aklj; +aklk; +akll; +aklm; +akln; +aklo; +aklp; +aklq; +aklr; +akls; +aklt; +aklu; +aklv; +aklw; +aklx; +akly; +aklz; +akma; +akmb; +akmc; +akmd; +akme; +akmf; +akmg; +akmh; +akmi; +akmj; +akmk; +akml; +akmm; +akmn; +akmo; +akmp; +akmq; +akmr; +akms; +akmt; +akmu; +akmv; +akmw; +akmx; +akmy; +akmz; +akna; +aknb; +aknc; +aknd; +akne; +aknf; +akng; +aknh; +akni; +aknj; +aknk; +aknl; +aknm; +aknn; +akno; +aknp; +aknq; +aknr; +akns; +aknt; +aknu; +aknv; +aknw; +aknx; +akny; +aknz; +akoa; +akob; +akoc; +akod; +akoe; +akof; +akog; +akoh; +akoi; +akoj; +akok; +akol; +akom; +akon; +akoo; +akop; +akoq; +akor; +akos; +akot; +akou; +akov; +akow; +akox; +akoy; +akoz; +akpa; +akpb; +akpc; +akpd; +akpe; +akpf; +akpg; +akph; +akpi; +akpj; +akpk; +akpl; +akpm; +akpn; +akpo; +akpp; +akpq; +akpr; +akps; +akpt; +akpu; +akpv; +akpw; +akpx; +akpy; +akpz; +akqa; +akqb; +akqc; +akqd; +akqe; +akqf; +akqg; +akqh; +akqi; +akqj; +akqk; +akql; +akqm; +akqn; +akqo; +akqp; +akqq; +akqr; +akqs; +akqt; +akqu; +akqv; +akqw; +akqx; +akqy; +akqz; +akra; +akrb; +akrc; +akrd; +akre; +akrf; +akrg; +akrh; +akri; +akrj; +akrk; +akrl; +akrm; +akrn; +akro; +akrp; +akrq; +akrr; +akrs; +akrt; +akru; +akrv; +akrw; +akrx; +akry; +akrz; +aksa; +aksb; +aksc; +aksd; +akse; +aksf; +aksg; +aksh; +aksi; +aksj; +aksk; +aksl; +aksm; +aksn; +akso; +aksp; +aksq; +aksr; +akss; +akst; +aksu; +aksv; +aksw; +aksx; +aksy; +aksz; +akta; +aktb; +aktc; +aktd; +akte; +aktf; +aktg; +akth; +akti; +aktj; +aktk; +aktl; +aktm; +aktn; +akto; +aktp; +aktq; +aktr; +akts; +aktt; +aktu; +aktv; +aktw; +aktx; +akty; +aktz; +akua; +akub; +akuc; +akud; +akue; +akuf; +akug; +akuh; +akui; +akuj; +akuk; +akul; +akum; +akun; +akuo; +akup; +akuq; +akur; +akus; +akut; +akuu; +akuv; +akuw; +akux; +akuy; +akuz; +akva; +akvb; +akvc; +akvd; +akve; +akvf; +akvg; +akvh; +akvi; +akvj; +akvk; +akvl; +akvm; +akvn; +akvo; +akvp; +akvq; +akvr; +akvs; +akvt; +akvu; +akvv; +akvw; +akvx; +akvy; +akvz; +akwa; +akwb; +akwc; +akwd; +akwe; +akwf; +akwg; +akwh; +akwi; +akwj; +akwk; +akwl; +akwm; +akwn; +akwo; +akwp; +akwq; +akwr; +akws; +akwt; +akwu; +akwv; +akww; +akwx; +akwy; +akwz; +akxa; +akxb; +akxc; +akxd; +akxe; +akxf; +akxg; +akxh; +akxi; +akxj; +akxk; +akxl; +akxm; +akxn; +akxo; +akxp; +akxq; +akxr; +akxs; +akxt; +akxu; +akxv; +akxw; +akxx; +akxy; +akxz; +akya; +akyb; +akyc; +akyd; +akye; +akyf; +akyg; +akyh; +akyi; +akyj; +akyk; +akyl; +akym; +akyn; +akyo; +akyp; +akyq; +akyr; +akys; +akyt; +akyu; +akyv; +akyw; +akyx; +akyy; +akyz; +akza; +akzb; +akzc; +akzd; +akze; +akzf; +akzg; +akzh; +akzi; +akzj; +akzk; +akzl; +akzm; +akzn; +akzo; +akzp; +akzq; +akzr; +akzs; +akzt; +akzu; +akzv; +akzw; +akzx; +akzy; +akzz; +alaa; +alab; +alac; +alad; +alae; +alaf; +alag; +alah; +alai; +alaj; +alak; +alal; +alam; +alan; +alao; +alap; +alaq; +alar; +alas; +alat; +alau; +alav; +alaw; +alax; +alay; +alaz; +alba; +albb; +albc; +albd; +albe; +albf; +albg; +albh; +albi; +albj; +albk; +albl; +albm; +albn; +albo; +albp; +albq; +albr; +albs; +albt; +albu; +albv; +albw; +albx; +alby; +albz; +alca; +alcb; +alcc; +alcd; +alce; +alcf; +alcg; +alch; +alci; +alcj; +alck; +alcl; +alcm; +alcn; +alco; +alcp; +alcq; +alcr; +alcs; +alct; +alcu; +alcv; +alcw; +alcx; +alcy; +alcz; +alda; +aldb; +aldc; +aldd; +alde; +aldf; +aldg; +aldh; +aldi; +aldj; +aldk; +aldl; +aldm; +aldn; +aldo; +aldp; +aldq; +aldr; +alds; +aldt; +aldu; +aldv; +aldw; +aldx; +aldy; +aldz; +alea; +aleb; +alec; +aled; +alee; +alef; +aleg; +aleh; +alei; +alej; +alek; +alel; +alem; +alen; +aleo; +alep; +aleq; +aler; +ales; +alet; +aleu; +alev; +alew; +alex; +aley; +alez; +alfa; +alfb; +alfc; +alfd; +alfe; +alff; +alfg; +alfh; +alfi; +alfj; +alfk; +alfl; +alfm; +alfn; +alfo; +alfp; +alfq; +alfr; +alfs; +alft; +alfu; +alfv; +alfw; +alfx; +alfy; +alfz; +alga; +algb; +algc; +algd; +alge; +algf; +algg; +algh; +algi; +algj; +algk; +algl; +algm; +algn; +algo; +algp; +algq; +algr; +algs; +algt; +algu; +algv; +algw; +algx; +algy; +algz; +alha; +alhb; +alhc; +alhd; +alhe; +alhf; +alhg; +alhh; +alhi; +alhj; +alhk; +alhl; +alhm; +alhn; +alho; +alhp; +alhq; +alhr; +alhs; +alht; +alhu; +alhv; +alhw; +alhx; +alhy; +alhz; +alia; +alib; +alic; +alid; +alie; +alif; +alig; +alih; +alii; +alij; +alik; +alil; +alim; +alin; +alio; +alip; +aliq; +alir; +alis; +alit; +aliu; +aliv; +aliw; +alix; +aliy; +aliz; +alja; +aljb; +aljc; +aljd; +alje; +aljf; +aljg; +aljh; +alji; +aljj; +aljk; +aljl; +aljm; +aljn; +aljo; +aljp; +aljq; +aljr; +aljs; +aljt; +alju; +aljv; +aljw; +aljx; +aljy; +aljz; +alka; +alkb; +alkc; +alkd; +alke; +alkf; +alkg; +alkh; +alki; +alkj; +alkk; +alkl; +alkm; +alkn; +alko; +alkp; +alkq; +alkr; +alks; +alkt; +alku; +alkv; +alkw; +alkx; +alky; +alkz; +alla; +allb; +allc; +alld; +alle; +allf; +allg; +allh; +alli; +allj; +allk; +alll; +allm; +alln; +allo; +allp; +allq; +allr; +alls; +allt; +allu; +allv; +allw; +allx; +ally; +allz; +alma; +almb; +almc; +almd; +alme; +almf; +almg; +almh; +almi; +almj; +almk; +alml; +almm; +almn; +almo; +almp; +almq; +almr; +alms; +almt; +almu; +almv; +almw; +almx; +almy; +almz; +alna; +alnb; +alnc; +alnd; +alne; +alnf; +alng; +alnh; +alni; +alnj; +alnk; +alnl; +alnm; +alnn; +alno; +alnp; +alnq; +alnr; +alns; +alnt; +alnu; +alnv; +alnw; +alnx; +alny; +alnz; +aloa; +alob; +aloc; +alod; +aloe; +alof; +alog; +aloh; +aloi; +aloj; +alok; +alol; +alom; +alon; +aloo; +alop; +aloq; +alor; +alos; +alot; +alou; +alov; +alow; +alox; +aloy; +aloz; +alpa; +alpb; +alpc; +alpd; +alpe; +alpf; +alpg; +alph; +alpi; +alpj; +alpk; +alpl; +alpm; +alpn; +alpo; +alpp; +alpq; +alpr; +alps; +alpt; +alpu; +alpv; +alpw; +alpx; +alpy; +alpz; +alqa; +alqb; +alqc; +alqd; +alqe; +alqf; +alqg; +alqh; +alqi; +alqj; +alqk; +alql; +alqm; +alqn; +alqo; +alqp; +alqq; +alqr; +alqs; +alqt; +alqu; +alqv; +alqw; +alqx; +alqy; +alqz; +alra; +alrb; +alrc; +alrd; +alre; +alrf; +alrg; +alrh; +alri; +alrj; +alrk; +alrl; +alrm; +alrn; +alro; +alrp; +alrq; +alrr; +alrs; +alrt; +alru; +alrv; +alrw; +alrx; +alry; +alrz; +alsa; +alsb; +alsc; +alsd; +alse; +alsf; +alsg; +alsh; +alsi; +alsj; +alsk; +alsl; +alsm; +alsn; +also; +alsp; +alsq; +alsr; +alss; +alst; +alsu; +alsv; +alsw; +alsx; +alsy; +alsz; +alta; +altb; +altc; +altd; +alte; +altf; +altg; +alth; +alti; +altj; +altk; +altl; +altm; +altn; +alto; +altp; +altq; +altr; +alts; +altt; +altu; +altv; +altw; +altx; +alty; +altz; +alua; +alub; +aluc; +alud; +alue; +aluf; +alug; +aluh; +alui; +aluj; +aluk; +alul; +alum; +alun; +aluo; +alup; +aluq; +alur; +alus; +alut; +aluu; +aluv; +aluw; +alux; +aluy; +aluz; +alva; +alvb; +alvc; +alvd; +alve; +alvf; +alvg; +alvh; +alvi; +alvj; +alvk; +alvl; +alvm; +alvn; +alvo; +alvp; +alvq; +alvr; +alvs; +alvt; +alvu; +alvv; +alvw; +alvx; +alvy; +alvz; +alwa; +alwb; +alwc; +alwd; +alwe; +alwf; +alwg; +alwh; +alwi; +alwj; +alwk; +alwl; +alwm; +alwn; +alwo; +alwp; +alwq; +alwr; +alws; +alwt; +alwu; +alwv; +alww; +alwx; +alwy; +alwz; +alxa; +alxb; +alxc; +alxd; +alxe; +alxf; +alxg; +alxh; +alxi; +alxj; +alxk; +alxl; +alxm; +alxn; +alxo; +alxp; +alxq; +alxr; +alxs; +alxt; +alxu; +alxv; +alxw; +alxx; +alxy; +alxz; +alya; +alyb; +alyc; +alyd; +alye; +alyf; +alyg; +alyh; +alyi; +alyj; +alyk; +alyl; +alym; +alyn; +alyo; +alyp; +alyq; +alyr; +alys; +alyt; +alyu; +alyv; +alyw; +alyx; +alyy; +alyz; +alza; +alzb; +alzc; +alzd; +alze; +alzf; +alzg; +alzh; +alzi; +alzj; +alzk; +alzl; +alzm; +alzn; +alzo; +alzp; +alzq; +alzr; +alzs; +alzt; +alzu; +alzv; +alzw; +alzx; +alzy; +alzz; +amaa; +amab; +amac; +amad; +amae; +amaf; +amag; +amah; +amai; +amaj; +amak; +amal; +amam; +aman; +amao; +amap; +amaq; +amar; +amas; +amat; +amau; +amav; +amaw; +amax; +amay; +amaz; +amba; +ambb; +ambc; +ambd; +ambe; +ambf; +ambg; +ambh; +ambi; +ambj; +ambk; +ambl; +ambm; +ambn; +ambo; +ambp; +ambq; +ambr; +ambs; +ambt; +ambu; +ambv; +ambw; +ambx; +amby; +ambz; +amca; +amcb; +amcc; +amcd; +amce; +amcf; +amcg; +amch; +amci; +amcj; +amck; +amcl; +amcm; +amcn; +amco; +amcp; +amcq; +amcr; +amcs; +amct; +amcu; +amcv; +amcw; +amcx; +amcy; +amcz; +amda; +amdb; +amdc; +amdd; +amde; +amdf; +amdg; +amdh; +amdi; +amdj; +amdk; +amdl; +amdm; +amdn; +amdo; +amdp; +amdq; +amdr; +amds; +amdt; +amdu; +amdv; +amdw; +amdx; +amdy; +amdz; +amea; +ameb; +amec; +amed; +amee; +amef; +ameg; +ameh; +amei; +amej; +amek; +amel; +amem; +amen; +ameo; +amep; +ameq; +amer; +ames; +amet; +ameu; +amev; +amew; +amex; +amey; +amez; +amfa; +amfb; +amfc; +amfd; +amfe; +amff; +amfg; +amfh; +amfi; +amfj; +amfk; +amfl; +amfm; +amfn; +amfo; +amfp; +amfq; +amfr; +amfs; +amft; +amfu; +amfv; +amfw; +amfx; +amfy; +amfz; +amga; +amgb; +amgc; +amgd; +amge; +amgf; +amgg; +amgh; +amgi; +amgj; +amgk; +amgl; +amgm; +amgn; +amgo; +amgp; +amgq; +amgr; +amgs; +amgt; +amgu; +amgv; +amgw; +amgx; +amgy; +amgz; +amha; +amhb; +amhc; +amhd; +amhe; +amhf; +amhg; +amhh; +amhi; +amhj; +amhk; +amhl; +amhm; +amhn; +amho; +amhp; +amhq; +amhr; +amhs; +amht; +amhu; +amhv; +amhw; +amhx; +amhy; +amhz; +amia; +amib; +amic; +amid; +amie; +amif; +amig; +amih; +amii; +amij; +amik; +amil; +amim; +amin; +amio; +amip; +amiq; +amir; +amis; +amit; +amiu; +amiv; +amiw; +amix; +amiy; +amiz; +amja; +amjb; +amjc; +amjd; +amje; +amjf; +amjg; +amjh; +amji; +amjj; +amjk; +amjl; +amjm; +amjn; +amjo; +amjp; +amjq; +amjr; +amjs; +amjt; +amju; +amjv; +amjw; +amjx; +amjy; +amjz; +amka; +amkb; +amkc; +amkd; +amke; +amkf; +amkg; +amkh; +amki; +amkj; +amkk; +amkl; +amkm; +amkn; +amko; +amkp; +amkq; +amkr; +amks; +amkt; +amku; +amkv; +amkw; +amkx; +amky; +amkz; +amla; +amlb; +amlc; +amld; +amle; +amlf; +amlg; +amlh; +amli; +amlj; +amlk; +amll; +amlm; +amln; +amlo; +amlp; +amlq; +amlr; +amls; +amlt; +amlu; +amlv; +amlw; +amlx; +amly; +amlz; +amma; +ammb; +ammc; +ammd; +amme; +ammf; +ammg; +ammh; +ammi; +ammj; +ammk; +amml; +ammm; +ammn; +ammo; +ammp; +ammq; +ammr; +amms; +ammt; +ammu; +ammv; +ammw; +ammx; +ammy; +ammz; +amna; +amnb; +amnc; +amnd; +amne; +amnf; +amng; +amnh; +amni; +amnj; +amnk; +amnl; +amnm; +amnn; +amno; +amnp; +amnq; +amnr; +amns; +amnt; +amnu; +amnv; +amnw; +amnx; +amny; +amnz; +amoa; +amob; +amoc; +amod; +amoe; +amof; +amog; +amoh; +amoi; +amoj; +amok; +amol; +amom; +amon; +amoo; +amop; +amoq; +amor; +amos; +amot; +amou; +amov; +amow; +amox; +amoy; +amoz; +ampa; +ampb; +ampc; +ampd; +ampe; +ampf; +ampg; +amph; +ampi; +ampj; +ampk; +ampl; +ampm; +ampn; +ampo; +ampp; +ampq; +ampr; +amps; +ampt; +ampu; +ampv; +ampw; +ampx; +ampy; +ampz; +amqa; +amqb; +amqc; +amqd; +amqe; +amqf; +amqg; +amqh; +amqi; +amqj; +amqk; +amql; +amqm; +amqn; +amqo; +amqp; +amqq; +amqr; +amqs; +amqt; +amqu; +amqv; +amqw; +amqx; +amqy; +amqz; +amra; +amrb; +amrc; +amrd; +amre; +amrf; +amrg; +amrh; +amri; +amrj; +amrk; +amrl; +amrm; +amrn; +amro; +amrp; +amrq; +amrr; +amrs; +amrt; +amru; +amrv; +amrw; +amrx; +amry; +amrz; +amsa; +amsb; +amsc; +amsd; +amse; +amsf; +amsg; +amsh; +amsi; +amsj; +amsk; +amsl; +amsm; +amsn; +amso; +amsp; +amsq; +amsr; +amss; +amst; +amsu; +amsv; +amsw; +amsx; +amsy; +amsz; +amta; +amtb; +amtc; +amtd; +amte; +amtf; +amtg; +amth; +amti; +amtj; +amtk; +amtl; +amtm; +amtn; +amto; +amtp; +amtq; +amtr; +amts; +amtt; +amtu; +amtv; +amtw; +amtx; +amty; +amtz; +amua; +amub; +amuc; +amud; +amue; +amuf; +amug; +amuh; +amui; +amuj; +amuk; +amul; +amum; +amun; +amuo; +amup; +amuq; +amur; +amus; +amut; +amuu; +amuv; +amuw; +amux; +amuy; +amuz; +amva; +amvb; +amvc; +amvd; +amve; +amvf; +amvg; +amvh; +amvi; +amvj; +amvk; +amvl; +amvm; +amvn; +amvo; +amvp; +amvq; +amvr; +amvs; +amvt; +amvu; +amvv; +amvw; +amvx; +amvy; +amvz; +amwa; +amwb; +amwc; +amwd; +amwe; +amwf; +amwg; +amwh; +amwi; +amwj; +amwk; +amwl; +amwm; +amwn; +amwo; +amwp; +amwq; +amwr; +amws; +amwt; +amwu; +amwv; +amww; +amwx; +amwy; +amwz; +amxa; +amxb; +amxc; +amxd; +amxe; +amxf; +amxg; +amxh; +amxi; +amxj; +amxk; +amxl; +amxm; +amxn; +amxo; +amxp; +amxq; +amxr; +amxs; +amxt; +amxu; +amxv; +amxw; +amxx; +amxy; +amxz; +amya; +amyb; +amyc; +amyd; +amye; +amyf; +amyg; +amyh; +amyi; +amyj; +amyk; +amyl; +amym; +amyn; +amyo; +amyp; +amyq; +amyr; +amys; +amyt; +amyu; +amyv; +amyw; +amyx; +amyy; +amyz; +amza; +amzb; +amzc; +amzd; +amze; +amzf; +amzg; +amzh; +amzi; +amzj; +amzk; +amzl; +amzm; +amzn; +amzo; +amzp; +amzq; +amzr; +amzs; +amzt; +amzu; +amzv; +amzw; +amzx; +amzy; +amzz; +anaa; +anab; +anac; +anad; +anae; +anaf; +anag; +anah; +anai; +anaj; +anak; +anal; +anam; +anan; +anao; +anap; +anaq; +anar; +anas; +anat; +anau; +anav; +anaw; +anax; +anay; +anaz; +anba; +anbb; +anbc; +anbd; +anbe; +anbf; +anbg; +anbh; +anbi; +anbj; +anbk; +anbl; +anbm; +anbn; +anbo; +anbp; +anbq; +anbr; +anbs; +anbt; +anbu; +anbv; +anbw; +anbx; +anby; +anbz; +anca; +ancb; +ancc; +ancd; +ance; +ancf; +ancg; +anch; +anci; +ancj; +anck; +ancl; +ancm; +ancn; +anco; +ancp; +ancq; +ancr; +ancs; +anct; +ancu; +ancv; +ancw; +ancx; +ancy; +ancz; +anda; +andb; +andc; +andd; +ande; +andf; +andg; +andh; +andi; +andj; +andk; +andl; +andm; +andn; +ando; +andp; +andq; +andr; +ands; +andt; +andu; +andv; +andw; +andx; +andy; +andz; +anea; +aneb; +anec; +aned; +anee; +anef; +aneg; +aneh; +anei; +anej; +anek; +anel; +anem; +anen; +aneo; +anep; +aneq; +aner; +anes; +anet; +aneu; +anev; +anew; +anex; +aney; +anez; +anfa; +anfb; +anfc; +anfd; +anfe; +anff; +anfg; +anfh; +anfi; +anfj; +anfk; +anfl; +anfm; +anfn; +anfo; +anfp; +anfq; +anfr; +anfs; +anft; +anfu; +anfv; +anfw; +anfx; +anfy; +anfz; +anga; +angb; +angc; +angd; +ange; +angf; +angg; +angh; +angi; +angj; +angk; +angl; +angm; +angn; +ango; +angp; +angq; +angr; +angs; +angt; +angu; +angv; +angw; +angx; +angy; +angz; +anha; +anhb; +anhc; +anhd; +anhe; +anhf; +anhg; +anhh; +anhi; +anhj; +anhk; +anhl; +anhm; +anhn; +anho; +anhp; +anhq; +anhr; +anhs; +anht; +anhu; +anhv; +anhw; +anhx; +anhy; +anhz; +ania; +anib; +anic; +anid; +anie; +anif; +anig; +anih; +anii; +anij; +anik; +anil; +anim; +anin; +anio; +anip; +aniq; +anir; +anis; +anit; +aniu; +aniv; +aniw; +anix; +aniy; +aniz; +anja; +anjb; +anjc; +anjd; +anje; +anjf; +anjg; +anjh; +anji; +anjj; +anjk; +anjl; +anjm; +anjn; +anjo; +anjp; +anjq; +anjr; +anjs; +anjt; +anju; +anjv; +anjw; +anjx; +anjy; +anjz; +anka; +ankb; +ankc; +ankd; +anke; +ankf; +ankg; +ankh; +anki; +ankj; +ankk; +ankl; +ankm; +ankn; +anko; +ankp; +ankq; +ankr; +anks; +ankt; +anku; +ankv; +ankw; +ankx; +anky; +ankz; +anla; +anlb; +anlc; +anld; +anle; +anlf; +anlg; +anlh; +anli; +anlj; +anlk; +anll; +anlm; +anln; +anlo; +anlp; +anlq; +anlr; +anls; +anlt; +anlu; +anlv; +anlw; +anlx; +anly; +anlz; +anma; +anmb; +anmc; +anmd; +anme; +anmf; +anmg; +anmh; +anmi; +anmj; +anmk; +anml; +anmm; +anmn; +anmo; +anmp; +anmq; +anmr; +anms; +anmt; +anmu; +anmv; +anmw; +anmx; +anmy; +anmz; +anna; +annb; +annc; +annd; +anne; +annf; +anng; +annh; +anni; +annj; +annk; +annl; +annm; +annn; +anno; +annp; +annq; +annr; +anns; +annt; +annu; +annv; +annw; +annx; +anny; +annz; +anoa; +anob; +anoc; +anod; +anoe; +anof; +anog; +anoh; +anoi; +anoj; +anok; +anol; +anom; +anon; +anoo; +anop; +anoq; +anor; +anos; +anot; +anou; +anov; +anow; +anox; +anoy; +anoz; +anpa; +anpb; +anpc; +anpd; +anpe; +anpf; +anpg; +anph; +anpi; +anpj; +anpk; +anpl; +anpm; +anpn; +anpo; +anpp; +anpq; +anpr; +anps; +anpt; +anpu; +anpv; +anpw; +anpx; +anpy; +anpz; +anqa; +anqb; +anqc; +anqd; +anqe; +anqf; +anqg; +anqh; +anqi; +anqj; +anqk; +anql; +anqm; +anqn; +anqo; +anqp; +anqq; +anqr; +anqs; +anqt; +anqu; +anqv; +anqw; +anqx; +anqy; +anqz; +anra; +anrb; +anrc; +anrd; +anre; +anrf; +anrg; +anrh; +anri; +anrj; +anrk; +anrl; +anrm; +anrn; +anro; +anrp; +anrq; +anrr; +anrs; +anrt; +anru; +anrv; +anrw; +anrx; +anry; +anrz; +ansa; +ansb; +ansc; +ansd; +anse; +ansf; +ansg; +ansh; +ansi; +ansj; +ansk; +ansl; +ansm; +ansn; +anso; +ansp; +ansq; +ansr; +anss; +anst; +ansu; +ansv; +answ; +ansx; +ansy; +ansz; +anta; +antb; +antc; +antd; +ante; +antf; +antg; +anth; +anti; +antj; +antk; +antl; +antm; +antn; +anto; +antp; +antq; +antr; +ants; +antt; +antu; +antv; +antw; +antx; +anty; +antz; +anua; +anub; +anuc; +anud; +anue; +anuf; +anug; +anuh; +anui; +anuj; +anuk; +anul; +anum; +anun; +anuo; +anup; +anuq; +anur; +anus; +anut; +anuu; +anuv; +anuw; +anux; +anuy; +anuz; +anva; +anvb; +anvc; +anvd; +anve; +anvf; +anvg; +anvh; +anvi; +anvj; +anvk; +anvl; +anvm; +anvn; +anvo; +anvp; +anvq; +anvr; +anvs; +anvt; +anvu; +anvv; +anvw; +anvx; +anvy; +anvz; +anwa; +anwb; +anwc; +anwd; +anwe; +anwf; +anwg; +anwh; +anwi; +anwj; +anwk; +anwl; +anwm; +anwn; +anwo; +anwp; +anwq; +anwr; +anws; +anwt; +anwu; +anwv; +anww; +anwx; +anwy; +anwz; +anxa; +anxb; +anxc; +anxd; +anxe; +anxf; +anxg; +anxh; +anxi; +anxj; +anxk; +anxl; +anxm; +anxn; +anxo; +anxp; +anxq; +anxr; +anxs; +anxt; +anxu; +anxv; +anxw; +anxx; +anxy; +anxz; +anya; +anyb; +anyc; +anyd; +anye; +anyf; +anyg; +anyh; +anyi; +anyj; +anyk; +anyl; +anym; +anyn; +anyo; +anyp; +anyq; +anyr; +anys; +anyt; +anyu; +anyv; +anyw; +anyx; +anyy; +anyz; +anza; +anzb; +anzc; +anzd; +anze; +anzf; +anzg; +anzh; +anzi; +anzj; +anzk; +anzl; +anzm; +anzn; +anzo; +anzp; +anzq; +anzr; +anzs; +anzt; +anzu; +anzv; +anzw; +anzx; +anzy; +anzz; +aoaa; +aoab; +aoac; +aoad; +aoae; +aoaf; +aoag; +aoah; +aoai; +aoaj; +aoak; +aoal; +aoam; +aoan; +aoao; +aoap; +aoaq; +aoar; +aoas; +aoat; +aoau; +aoav; +aoaw; +aoax; +aoay; +aoaz; +aoba; +aobb; +aobc; +aobd; +aobe; +aobf; +aobg; +aobh; +aobi; +aobj; +aobk; +aobl; +aobm; +aobn; +aobo; +aobp; +aobq; +aobr; +aobs; +aobt; +aobu; +aobv; +aobw; +aobx; +aoby; +aobz; +aoca; +aocb; +aocc; +aocd; +aoce; +aocf; +aocg; +aoch; +aoci; +aocj; +aock; +aocl; +aocm; +aocn; +aoco; +aocp; +aocq; +aocr; +aocs; +aoct; +aocu; +aocv; +aocw; +aocx; +aocy; +aocz; +aoda; +aodb; +aodc; +aodd; +aode; +aodf; +aodg; +aodh; +aodi; +aodj; +aodk; +aodl; +aodm; +aodn; +aodo; +aodp; +aodq; +aodr; +aods; +aodt; +aodu; +aodv; +aodw; +aodx; +aody; +aodz; +aoea; +aoeb; +aoec; +aoed; +aoee; +aoef; +aoeg; +aoeh; +aoei; +aoej; +aoek; +aoel; +aoem; +aoen; +aoeo; +aoep; +aoeq; +aoer; +aoes; +aoet; +aoeu; +aoev; +aoew; +aoex; +aoey; +aoez; +aofa; +aofb; +aofc; +aofd; +aofe; +aoff; +aofg; +aofh; +aofi; +aofj; +aofk; +aofl; +aofm; +aofn; +aofo; +aofp; +aofq; +aofr; +aofs; +aoft; +aofu; +aofv; +aofw; +aofx; +aofy; +aofz; +aoga; +aogb; +aogc; +aogd; +aoge; +aogf; +aogg; +aogh; +aogi; +aogj; +aogk; +aogl; +aogm; +aogn; +aogo; +aogp; +aogq; +aogr; +aogs; +aogt; +aogu; +aogv; +aogw; +aogx; +aogy; +aogz; +aoha; +aohb; +aohc; +aohd; +aohe; +aohf; +aohg; +aohh; +aohi; +aohj; +aohk; +aohl; +aohm; +aohn; +aoho; +aohp; +aohq; +aohr; +aohs; +aoht; +aohu; +aohv; +aohw; +aohx; +aohy; +aohz; +aoia; +aoib; +aoic; +aoid; +aoie; +aoif; +aoig; +aoih; +aoii; +aoij; +aoik; +aoil; +aoim; +aoin; +aoio; +aoip; +aoiq; +aoir; +aois; +aoit; +aoiu; +aoiv; +aoiw; +aoix; +aoiy; +aoiz; +aoja; +aojb; +aojc; +aojd; +aoje; +aojf; +aojg; +aojh; +aoji; +aojj; +aojk; +aojl; +aojm; +aojn; +aojo; +aojp; +aojq; +aojr; +aojs; +aojt; +aoju; +aojv; +aojw; +aojx; +aojy; +aojz; +aoka; +aokb; +aokc; +aokd; +aoke; +aokf; +aokg; +aokh; +aoki; +aokj; +aokk; +aokl; +aokm; +aokn; +aoko; +aokp; +aokq; +aokr; +aoks; +aokt; +aoku; +aokv; +aokw; +aokx; +aoky; +aokz; +aola; +aolb; +aolc; +aold; +aole; +aolf; +aolg; +aolh; +aoli; +aolj; +aolk; +aoll; +aolm; +aoln; +aolo; +aolp; +aolq; +aolr; +aols; +aolt; +aolu; +aolv; +aolw; +aolx; +aoly; +aolz; +aoma; +aomb; +aomc; +aomd; +aome; +aomf; +aomg; +aomh; +aomi; +aomj; +aomk; +aoml; +aomm; +aomn; +aomo; +aomp; +aomq; +aomr; +aoms; +aomt; +aomu; +aomv; +aomw; +aomx; +aomy; +aomz; +aona; +aonb; +aonc; +aond; +aone; +aonf; +aong; +aonh; +aoni; +aonj; +aonk; +aonl; +aonm; +aonn; +aono; +aonp; +aonq; +aonr; +aons; +aont; +aonu; +aonv; +aonw; +aonx; +aony; +aonz; +aooa; +aoob; +aooc; +aood; +aooe; +aoof; +aoog; +aooh; +aooi; +aooj; +aook; +aool; +aoom; +aoon; +aooo; +aoop; +aooq; +aoor; +aoos; +aoot; +aoou; +aoov; +aoow; +aoox; +aooy; +aooz; +aopa; +aopb; +aopc; +aopd; +aope; +aopf; +aopg; +aoph; +aopi; +aopj; +aopk; +aopl; +aopm; +aopn; +aopo; +aopp; +aopq; +aopr; +aops; +aopt; +aopu; +aopv; +aopw; +aopx; +aopy; +aopz; +aoqa; +aoqb; +aoqc; +aoqd; +aoqe; +aoqf; +aoqg; +aoqh; +aoqi; +aoqj; +aoqk; +aoql; +aoqm; +aoqn; +aoqo; +aoqp; +aoqq; +aoqr; +aoqs; +aoqt; +aoqu; +aoqv; +aoqw; +aoqx; +aoqy; +aoqz; +aora; +aorb; +aorc; +aord; +aore; +aorf; +aorg; +aorh; +aori; +aorj; +aork; +aorl; +aorm; +aorn; +aoro; +aorp; +aorq; +aorr; +aors; +aort; +aoru; +aorv; +aorw; +aorx; +aory; +aorz; +aosa; +aosb; +aosc; +aosd; +aose; +aosf; +aosg; +aosh; +aosi; +aosj; +aosk; +aosl; +aosm; +aosn; +aoso; +aosp; +aosq; +aosr; +aoss; +aost; +aosu; +aosv; +aosw; +aosx; +aosy; +aosz; +aota; +aotb; +aotc; +aotd; +aote; +aotf; +aotg; +aoth; +aoti; +aotj; +aotk; +aotl; +aotm; +aotn; +aoto; +aotp; +aotq; +aotr; +aots; +aott; +aotu; +aotv; +aotw; +aotx; +aoty; +aotz; +aoua; +aoub; +aouc; +aoud; +aoue; +aouf; +aoug; +aouh; +aoui; +aouj; +aouk; +aoul; +aoum; +aoun; +aouo; +aoup; +aouq; +aour; +aous; +aout; +aouu; +aouv; +aouw; +aoux; +aouy; +aouz; +aova; +aovb; +aovc; +aovd; +aove; +aovf; +aovg; +aovh; +aovi; +aovj; +aovk; +aovl; +aovm; +aovn; +aovo; +aovp; +aovq; +aovr; +aovs; +aovt; +aovu; +aovv; +aovw; +aovx; +aovy; +aovz; +aowa; +aowb; +aowc; +aowd; +aowe; +aowf; +aowg; +aowh; +aowi; +aowj; +aowk; +aowl; +aowm; +aown; +aowo; +aowp; +aowq; +aowr; +aows; +aowt; +aowu; +aowv; +aoww; +aowx; +aowy; +aowz; +aoxa; +aoxb; +aoxc; +aoxd; +aoxe; +aoxf; +aoxg; +aoxh; +aoxi; +aoxj; +aoxk; +aoxl; +aoxm; +aoxn; +aoxo; +aoxp; +aoxq; +aoxr; +aoxs; +aoxt; +aoxu; +aoxv; +aoxw; +aoxx; +aoxy; +aoxz; +aoya; +aoyb; +aoyc; +aoyd; +aoye; +aoyf; +aoyg; +aoyh; +aoyi; +aoyj; +aoyk; +aoyl; +aoym; +aoyn; +aoyo; +aoyp; +aoyq; +aoyr; +aoys; +aoyt; +aoyu; +aoyv; +aoyw; +aoyx; +aoyy; +aoyz; +aoza; +aozb; +aozc; +aozd; +aoze; +aozf; +aozg; +aozh; +aozi; +aozj; +aozk; +aozl; +aozm; +aozn; +aozo; +aozp; +aozq; +aozr; +aozs; +aozt; +aozu; +aozv; +aozw; +aozx; +aozy; +aozz; +apaa; +apab; +apac; +apad; +apae; +apaf; +apag; +apah; +apai; +apaj; +apak; +apal; +apam; +apan; +apao; +apap; +apaq; +apar; +apas; +apat; +apau; +apav; +apaw; +apax; +apay; +apaz; +apba; +apbb; +apbc; +apbd; +apbe; +apbf; +apbg; +apbh; +apbi; +apbj; +apbk; +apbl; +apbm; +apbn; +apbo; +apbp; +apbq; +apbr; +apbs; +apbt; +apbu; +apbv; +apbw; +apbx; +apby; +apbz; +apca; +apcb; +apcc; +apcd; +apce; +apcf; +apcg; +apch; +apci; +apcj; +apck; +apcl; +apcm; +apcn; +apco; +apcp; +apcq; +apcr; +apcs; +apct; +apcu; +apcv; +apcw; +apcx; +apcy; +apcz; +apda; +apdb; +apdc; +apdd; +apde; +apdf; +apdg; +apdh; +apdi; +apdj; +apdk; +apdl; +apdm; +apdn; +apdo; +apdp; +apdq; +apdr; +apds; +apdt; +apdu; +apdv; +apdw; +apdx; +apdy; +apdz; +apea; +apeb; +apec; +aped; +apee; +apef; +apeg; +apeh; +apei; +apej; +apek; +apel; +apem; +apen; +apeo; +apep; +apeq; +aper; +apes; +apet; +apeu; +apev; +apew; +apex; +apey; +apez; +apfa; +apfb; +apfc; +apfd; +apfe; +apff; +apfg; +apfh; +apfi; +apfj; +apfk; +apfl; +apfm; +apfn; +apfo; +apfp; +apfq; +apfr; +apfs; +apft; +apfu; +apfv; +apfw; +apfx; +apfy; +apfz; +apga; +apgb; +apgc; +apgd; +apge; +apgf; +apgg; +apgh; +apgi; +apgj; +apgk; +apgl; +apgm; +apgn; +apgo; +apgp; +apgq; +apgr; +apgs; +apgt; +apgu; +apgv; +apgw; +apgx; +apgy; +apgz; +apha; +aphb; +aphc; +aphd; +aphe; +aphf; +aphg; +aphh; +aphi; +aphj; +aphk; +aphl; +aphm; +aphn; +apho; +aphp; +aphq; +aphr; +aphs; +apht; +aphu; +aphv; +aphw; +aphx; +aphy; +aphz; +apia; +apib; +apic; +apid; +apie; +apif; +apig; +apih; +apii; +apij; +apik; +apil; +apim; +apin; +apio; +apip; +apiq; +apir; +apis; +apit; +apiu; +apiv; +apiw; +apix; +apiy; +apiz; +apja; +apjb; +apjc; +apjd; +apje; +apjf; +apjg; +apjh; +apji; +apjj; +apjk; +apjl; +apjm; +apjn; +apjo; +apjp; +apjq; +apjr; +apjs; +apjt; +apju; +apjv; +apjw; +apjx; +apjy; +apjz; +apka; +apkb; +apkc; +apkd; +apke; +apkf; +apkg; +apkh; +apki; +apkj; +apkk; +apkl; +apkm; +apkn; +apko; +apkp; +apkq; +apkr; +apks; +apkt; +apku; +apkv; +apkw; +apkx; +apky; +apkz; +apla; +aplb; +aplc; +apld; +aple; +aplf; +aplg; +aplh; +apli; +aplj; +aplk; +apll; +aplm; +apln; +aplo; +aplp; +aplq; +aplr; +apls; +aplt; +aplu; +aplv; +aplw; +aplx; +aply; +aplz; +apma; +apmb; +apmc; +apmd; +apme; +apmf; +apmg; +apmh; +apmi; +apmj; +apmk; +apml; +apmm; +apmn; +apmo; +apmp; +apmq; +apmr; +apms; +apmt; +apmu; +apmv; +apmw; +apmx; +apmy; +apmz; +apna; +apnb; +apnc; +apnd; +apne; +apnf; +apng; +apnh; +apni; +apnj; +apnk; +apnl; +apnm; +apnn; +apno; +apnp; +apnq; +apnr; +apns; +apnt; +apnu; +apnv; +apnw; +apnx; +apny; +apnz; +apoa; +apob; +apoc; +apod; +apoe; +apof; +apog; +apoh; +apoi; +apoj; +apok; +apol; +apom; +apon; +apoo; +apop; +apoq; +apor; +apos; +apot; +apou; +apov; +apow; +apox; +apoy; +apoz; +appa; +appb; +appc; +appd; +appe; +appf; +appg; +apph; +appi; +appj; +appk; +appl; +appm; +appn; +appo; +appp; +appq; +appr; +apps; +appt; +appu; +appv; +appw; +appx; +appy; +appz; +apqa; +apqb; +apqc; +apqd; +apqe; +apqf; +apqg; +apqh; +apqi; +apqj; +apqk; +apql; +apqm; +apqn; +apqo; +apqp; +apqq; +apqr; +apqs; +apqt; +apqu; +apqv; +apqw; +apqx; +apqy; +apqz; +apra; +aprb; +aprc; +aprd; +apre; +aprf; +aprg; +aprh; +apri; +aprj; +aprk; +aprl; +aprm; +aprn; +apro; +aprp; +aprq; +aprr; +aprs; +aprt; +apru; +aprv; +aprw; +aprx; +apry; +aprz; +apsa; +apsb; +apsc; +apsd; +apse; +apsf; +apsg; +apsh; +apsi; +apsj; +apsk; +apsl; +apsm; +apsn; +apso; +apsp; +apsq; +apsr; +apss; +apst; +apsu; +apsv; +apsw; +apsx; +apsy; +apsz; +apta; +aptb; +aptc; +aptd; +apte; +aptf; +aptg; +apth; +apti; +aptj; +aptk; +aptl; +aptm; +aptn; +apto; +aptp; +aptq; +aptr; +apts; +aptt; +aptu; +aptv; +aptw; +aptx; +apty; +aptz; +apua; +apub; +apuc; +apud; +apue; +apuf; +apug; +apuh; +apui; +apuj; +apuk; +apul; +apum; +apun; +apuo; +apup; +apuq; +apur; +apus; +aput; +apuu; +apuv; +apuw; +apux; +apuy; +apuz; +apva; +apvb; +apvc; +apvd; +apve; +apvf; +apvg; +apvh; +apvi; +apvj; +apvk; +apvl; +apvm; +apvn; +apvo; +apvp; +apvq; +apvr; +apvs; +apvt; +apvu; +apvv; +apvw; +apvx; +apvy; +apvz; +apwa; +apwb; +apwc; +apwd; +apwe; +apwf; +apwg; +apwh; +apwi; +apwj; +apwk; +apwl; +apwm; +apwn; +apwo; +apwp; +apwq; +apwr; +apws; +apwt; +apwu; +apwv; +apww; +apwx; +apwy; +apwz; +apxa; +apxb; +apxc; +apxd; +apxe; +apxf; +apxg; +apxh; +apxi; +apxj; +apxk; +apxl; +apxm; +apxn; +apxo; +apxp; +apxq; +apxr; +apxs; +apxt; +apxu; +apxv; +apxw; +apxx; +apxy; +apxz; +apya; +apyb; +apyc; +apyd; +apye; +apyf; +apyg; +apyh; +apyi; +apyj; +apyk; +apyl; +apym; +apyn; +apyo; +apyp; +apyq; +apyr; +apys; +apyt; +apyu; +apyv; +apyw; +apyx; +apyy; +apyz; +apza; +apzb; +apzc; +apzd; +apze; +apzf; +apzg; +apzh; +apzi; +apzj; +apzk; +apzl; +apzm; +apzn; +apzo; +apzp; +apzq; +apzr; +apzs; +apzt; +apzu; +apzv; +apzw; +apzx; +apzy; +apzz; +aqaa; +aqab; +aqac; +aqad; +aqae; +aqaf; +aqag; +aqah; +aqai; +aqaj; +aqak; +aqal; +aqam; +aqan; +aqao; +aqap; +aqaq; +aqar; +aqas; +aqat; +aqau; +aqav; +aqaw; +aqax; +aqay; +aqaz; +aqba; +aqbb; +aqbc; +aqbd; +aqbe; +aqbf; +aqbg; +aqbh; +aqbi; +aqbj; +aqbk; +aqbl; +aqbm; +aqbn; +aqbo; +aqbp; +aqbq; +aqbr; +aqbs; +aqbt; +aqbu; +aqbv; +aqbw; +aqbx; +aqby; +aqbz; +aqca; +aqcb; +aqcc; +aqcd; +aqce; +aqcf; +aqcg; +aqch; +aqci; +aqcj; +aqck; +aqcl; +aqcm; +aqcn; +aqco; +aqcp; +aqcq; +aqcr; +aqcs; +aqct; +aqcu; +aqcv; +aqcw; +aqcx; +aqcy; +aqcz; +aqda; +aqdb; +aqdc; +aqdd; +aqde; +aqdf; +aqdg; +aqdh; +aqdi; +aqdj; +aqdk; +aqdl; +aqdm; +aqdn; +aqdo; +aqdp; +aqdq; +aqdr; +aqds; +aqdt; +aqdu; +aqdv; +aqdw; +aqdx; +aqdy; +aqdz; +aqea; +aqeb; +aqec; +aqed; +aqee; +aqef; +aqeg; +aqeh; +aqei; +aqej; +aqek; +aqel; +aqem; +aqen; +aqeo; +aqep; +aqeq; +aqer; +aqes; +aqet; +aqeu; +aqev; +aqew; +aqex; +aqey; +aqez; +aqfa; +aqfb; +aqfc; +aqfd; +aqfe; +aqff; +aqfg; +aqfh; +aqfi; +aqfj; +aqfk; +aqfl; +aqfm; +aqfn; +aqfo; +aqfp; +aqfq; +aqfr; +aqfs; +aqft; +aqfu; +aqfv; +aqfw; +aqfx; +aqfy; +aqfz; +aqga; +aqgb; +aqgc; +aqgd; +aqge; +aqgf; +aqgg; +aqgh; +aqgi; +aqgj; +aqgk; +aqgl; +aqgm; +aqgn; +aqgo; +aqgp; +aqgq; +aqgr; +aqgs; +aqgt; +aqgu; +aqgv; +aqgw; +aqgx; +aqgy; +aqgz; +aqha; +aqhb; +aqhc; +aqhd; +aqhe; +aqhf; +aqhg; +aqhh; +aqhi; +aqhj; +aqhk; +aqhl; +aqhm; +aqhn; +aqho; +aqhp; +aqhq; +aqhr; +aqhs; +aqht; +aqhu; +aqhv; +aqhw; +aqhx; +aqhy; +aqhz; +aqia; +aqib; +aqic; +aqid; +aqie; +aqif; +aqig; +aqih; +aqii; +aqij; +aqik; +aqil; +aqim; +aqin; +aqio; +aqip; +aqiq; +aqir; +aqis; +aqit; +aqiu; +aqiv; +aqiw; +aqix; +aqiy; +aqiz; +aqja; +aqjb; +aqjc; +aqjd; +aqje; +aqjf; +aqjg; +aqjh; +aqji; +aqjj; +aqjk; +aqjl; +aqjm; +aqjn; +aqjo; +aqjp; +aqjq; +aqjr; +aqjs; +aqjt; +aqju; +aqjv; +aqjw; +aqjx; +aqjy; +aqjz; +aqka; +aqkb; +aqkc; +aqkd; +aqke; +aqkf; +aqkg; +aqkh; +aqki; +aqkj; +aqkk; +aqkl; +aqkm; +aqkn; +aqko; +aqkp; +aqkq; +aqkr; +aqks; +aqkt; +aqku; +aqkv; +aqkw; +aqkx; +aqky; +aqkz; +aqla; +aqlb; +aqlc; +aqld; +aqle; +aqlf; +aqlg; +aqlh; +aqli; +aqlj; +aqlk; +aqll; +aqlm; +aqln; +aqlo; +aqlp; +aqlq; +aqlr; +aqls; +aqlt; +aqlu; +aqlv; +aqlw; +aqlx; +aqly; +aqlz; +aqma; +aqmb; +aqmc; +aqmd; +aqme; +aqmf; +aqmg; +aqmh; +aqmi; +aqmj; +aqmk; +aqml; +aqmm; +aqmn; +aqmo; +aqmp; +aqmq; +aqmr; +aqms; +aqmt; +aqmu; +aqmv; +aqmw; +aqmx; +aqmy; +aqmz; +aqna; +aqnb; +aqnc; +aqnd; +aqne; +aqnf; +aqng; +aqnh; +aqni; +aqnj; +aqnk; +aqnl; +aqnm; +aqnn; +aqno; +aqnp; +aqnq; +aqnr; +aqns; +aqnt; +aqnu; +aqnv; +aqnw; +aqnx; +aqny; +aqnz; +aqoa; +aqob; +aqoc; +aqod; +aqoe; +aqof; +aqog; +aqoh; +aqoi; +aqoj; +aqok; +aqol; +aqom; +aqon; +aqoo; +aqop; +aqoq; +aqor; +aqos; +aqot; +aqou; +aqov; +aqow; +aqox; +aqoy; +aqoz; +aqpa; +aqpb; +aqpc; +aqpd; +aqpe; +aqpf; +aqpg; +aqph; +aqpi; +aqpj; +aqpk; +aqpl; +aqpm; +aqpn; +aqpo; +aqpp; +aqpq; +aqpr; +aqps; +aqpt; +aqpu; +aqpv; +aqpw; +aqpx; +aqpy; +aqpz; +aqqa; +aqqb; +aqqc; +aqqd; +aqqe; +aqqf; +aqqg; +aqqh; +aqqi; +aqqj; +aqqk; +aqql; +aqqm; +aqqn; +aqqo; +aqqp; +aqqq; +aqqr; +aqqs; +aqqt; +aqqu; +aqqv; +aqqw; +aqqx; +aqqy; +aqqz; +aqra; +aqrb; +aqrc; +aqrd; +aqre; +aqrf; +aqrg; +aqrh; +aqri; +aqrj; +aqrk; +aqrl; +aqrm; +aqrn; +aqro; +aqrp; +aqrq; +aqrr; +aqrs; +aqrt; +aqru; +aqrv; +aqrw; +aqrx; +aqry; +aqrz; +aqsa; +aqsb; +aqsc; +aqsd; +aqse; +aqsf; +aqsg; +aqsh; +aqsi; +aqsj; +aqsk; +aqsl; +aqsm; +aqsn; +aqso; +aqsp; +aqsq; +aqsr; +aqss; +aqst; +aqsu; +aqsv; +aqsw; +aqsx; +aqsy; +aqsz; +aqta; +aqtb; +aqtc; +aqtd; +aqte; +aqtf; +aqtg; +aqth; +aqti; +aqtj; +aqtk; +aqtl; +aqtm; +aqtn; +aqto; +aqtp; +aqtq; +aqtr; +aqts; +aqtt; +aqtu; +aqtv; +aqtw; +aqtx; +aqty; +aqtz; +aqua; +aqub; +aquc; +aqud; +aque; +aquf; +aqug; +aquh; +aqui; +aquj; +aquk; +aqul; +aqum; +aqun; +aquo; +aqup; +aquq; +aqur; +aqus; +aqut; +aquu; +aquv; +aquw; +aqux; +aquy; +aquz; +aqva; +aqvb; +aqvc; +aqvd; +aqve; +aqvf; +aqvg; +aqvh; +aqvi; +aqvj; +aqvk; +aqvl; +aqvm; +aqvn; +aqvo; +aqvp; +aqvq; +aqvr; +aqvs; +aqvt; +aqvu; +aqvv; +aqvw; +aqvx; +aqvy; +aqvz; +aqwa; +aqwb; +aqwc; +aqwd; +aqwe; +aqwf; +aqwg; +aqwh; +aqwi; +aqwj; +aqwk; +aqwl; +aqwm; +aqwn; +aqwo; +aqwp; +aqwq; +aqwr; +aqws; +aqwt; +aqwu; +aqwv; +aqww; +aqwx; +aqwy; +aqwz; +aqxa; +aqxb; +aqxc; +aqxd; +aqxe; +aqxf; +aqxg; +aqxh; +aqxi; +aqxj; +aqxk; +aqxl; +aqxm; +aqxn; +aqxo; +aqxp; +aqxq; +aqxr; +aqxs; +aqxt; +aqxu; +aqxv; +aqxw; +aqxx; +aqxy; +aqxz; +aqya; +aqyb; +aqyc; +aqyd; +aqye; +aqyf; +aqyg; +aqyh; +aqyi; +aqyj; +aqyk; +aqyl; +aqym; +aqyn; +aqyo; +aqyp; +aqyq; +aqyr; +aqys; +aqyt; +aqyu; +aqyv; +aqyw; +aqyx; +aqyy; +aqyz; +aqza; +aqzb; +aqzc; +aqzd; +aqze; +aqzf; +aqzg; +aqzh; +aqzi; +aqzj; +aqzk; +aqzl; +aqzm; +aqzn; +aqzo; +aqzp; +aqzq; +aqzr; +aqzs; +aqzt; +aqzu; +aqzv; +aqzw; +aqzx; +aqzy; +aqzz; +araa; +arab; +arac; +arad; +arae; +araf; +arag; +arah; +arai; +araj; +arak; +aral; +aram; +aran; +arao; +arap; +araq; +arar; +aras; +arat; +arau; +arav; +araw; +arax; +aray; +araz; +arba; +arbb; +arbc; +arbd; +arbe; +arbf; +arbg; +arbh; +arbi; +arbj; +arbk; +arbl; +arbm; +arbn; +arbo; +arbp; +arbq; +arbr; +arbs; +arbt; +arbu; +arbv; +arbw; +arbx; +arby; +arbz; +arca; +arcb; +arcc; +arcd; +arce; +arcf; +arcg; +arch; +arci; +arcj; +arck; +arcl; +arcm; +arcn; +arco; +arcp; +arcq; +arcr; +arcs; +arct; +arcu; +arcv; +arcw; +arcx; +arcy; +arcz; +arda; +ardb; +ardc; +ardd; +arde; +ardf; +ardg; +ardh; +ardi; +ardj; +ardk; +ardl; +ardm; +ardn; +ardo; +ardp; +ardq; +ardr; +ards; +ardt; +ardu; +ardv; +ardw; +ardx; +ardy; +ardz; +area; +areb; +arec; +ared; +aree; +aref; +areg; +areh; +arei; +arej; +arek; +arel; +arem; +aren; +areo; +arep; +areq; +arer; +ares; +aret; +areu; +arev; +arew; +arex; +arey; +arez; +arfa; +arfb; +arfc; +arfd; +arfe; +arff; +arfg; +arfh; +arfi; +arfj; +arfk; +arfl; +arfm; +arfn; +arfo; +arfp; +arfq; +arfr; +arfs; +arft; +arfu; +arfv; +arfw; +arfx; +arfy; +arfz; +arga; +argb; +argc; +argd; +arge; +argf; +argg; +argh; +argi; +argj; +argk; +argl; +argm; +argn; +argo; +argp; +argq; +argr; +args; +argt; +argu; +argv; +argw; +argx; +argy; +argz; +arha; +arhb; +arhc; +arhd; +arhe; +arhf; +arhg; +arhh; +arhi; +arhj; +arhk; +arhl; +arhm; +arhn; +arho; +arhp; +arhq; +arhr; +arhs; +arht; +arhu; +arhv; +arhw; +arhx; +arhy; +arhz; +aria; +arib; +aric; +arid; +arie; +arif; +arig; +arih; +arii; +arij; +arik; +aril; +arim; +arin; +ario; +arip; +ariq; +arir; +aris; +arit; +ariu; +ariv; +ariw; +arix; +ariy; +ariz; +arja; +arjb; +arjc; +arjd; +arje; +arjf; +arjg; +arjh; +arji; +arjj; +arjk; +arjl; +arjm; +arjn; +arjo; +arjp; +arjq; +arjr; +arjs; +arjt; +arju; +arjv; +arjw; +arjx; +arjy; +arjz; +arka; +arkb; +arkc; +arkd; +arke; +arkf; +arkg; +arkh; +arki; +arkj; +arkk; +arkl; +arkm; +arkn; +arko; +arkp; +arkq; +arkr; +arks; +arkt; +arku; +arkv; +arkw; +arkx; +arky; +arkz; +arla; +arlb; +arlc; +arld; +arle; +arlf; +arlg; +arlh; +arli; +arlj; +arlk; +arll; +arlm; +arln; +arlo; +arlp; +arlq; +arlr; +arls; +arlt; +arlu; +arlv; +arlw; +arlx; +arly; +arlz; +arma; +armb; +armc; +armd; +arme; +armf; +armg; +armh; +armi; +armj; +armk; +arml; +armm; +armn; +armo; +armp; +armq; +armr; +arms; +armt; +armu; +armv; +armw; +armx; +army; +armz; +arna; +arnb; +arnc; +arnd; +arne; +arnf; +arng; +arnh; +arni; +arnj; +arnk; +arnl; +arnm; +arnn; +arno; +arnp; +arnq; +arnr; +arns; +arnt; +arnu; +arnv; +arnw; +arnx; +arny; +arnz; +aroa; +arob; +aroc; +arod; +aroe; +arof; +arog; +aroh; +aroi; +aroj; +arok; +arol; +arom; +aron; +aroo; +arop; +aroq; +aror; +aros; +arot; +arou; +arov; +arow; +arox; +aroy; +aroz; +arpa; +arpb; +arpc; +arpd; +arpe; +arpf; +arpg; +arph; +arpi; +arpj; +arpk; +arpl; +arpm; +arpn; +arpo; +arpp; +arpq; +arpr; +arps; +arpt; +arpu; +arpv; +arpw; +arpx; +arpy; +arpz; +arqa; +arqb; +arqc; +arqd; +arqe; +arqf; +arqg; +arqh; +arqi; +arqj; +arqk; +arql; +arqm; +arqn; +arqo; +arqp; +arqq; +arqr; +arqs; +arqt; +arqu; +arqv; +arqw; +arqx; +arqy; +arqz; +arra; +arrb; +arrc; +arrd; +arre; +arrf; +arrg; +arrh; +arri; +arrj; +arrk; +arrl; +arrm; +arrn; +arro; +arrp; +arrq; +arrr; +arrs; +arrt; +arru; +arrv; +arrw; +arrx; +arry; +arrz; +arsa; +arsb; +arsc; +arsd; +arse; +arsf; +arsg; +arsh; +arsi; +arsj; +arsk; +arsl; +arsm; +arsn; +arso; +arsp; +arsq; +arsr; +arss; +arst; +arsu; +arsv; +arsw; +arsx; +arsy; +arsz; +arta; +artb; +artc; +artd; +arte; +artf; +artg; +arth; +arti; +artj; +artk; +artl; +artm; +artn; +arto; +artp; +artq; +artr; +arts; +artt; +artu; +artv; +artw; +artx; +arty; +artz; +arua; +arub; +aruc; +arud; +arue; +aruf; +arug; +aruh; +arui; +aruj; +aruk; +arul; +arum; +arun; +aruo; +arup; +aruq; +arur; +arus; +arut; +aruu; +aruv; +aruw; +arux; +aruy; +aruz; +arva; +arvb; +arvc; +arvd; +arve; +arvf; +arvg; +arvh; +arvi; +arvj; +arvk; +arvl; +arvm; +arvn; +arvo; +arvp; +arvq; +arvr; +arvs; +arvt; +arvu; +arvv; +arvw; +arvx; +arvy; +arvz; +arwa; +arwb; +arwc; +arwd; +arwe; +arwf; +arwg; +arwh; +arwi; +arwj; +arwk; +arwl; +arwm; +arwn; +arwo; +arwp; +arwq; +arwr; +arws; +arwt; +arwu; +arwv; +arww; +arwx; +arwy; +arwz; +arxa; +arxb; +arxc; +arxd; +arxe; +arxf; +arxg; +arxh; +arxi; +arxj; +arxk; +arxl; +arxm; +arxn; +arxo; +arxp; +arxq; +arxr; +arxs; +arxt; +arxu; +arxv; +arxw; +arxx; +arxy; +arxz; +arya; +aryb; +aryc; +aryd; +arye; +aryf; +aryg; +aryh; +aryi; +aryj; +aryk; +aryl; +arym; +aryn; +aryo; +aryp; +aryq; +aryr; +arys; +aryt; +aryu; +aryv; +aryw; +aryx; +aryy; +aryz; +arza; +arzb; +arzc; +arzd; +arze; +arzf; +arzg; +arzh; +arzi; +arzj; +arzk; +arzl; +arzm; +arzn; +arzo; +arzp; +arzq; +arzr; +arzs; +arzt; +arzu; +arzv; +arzw; +arzx; +arzy; +arzz; +asaa; +asab; +asac; +asad; +asae; +asaf; +asag; +asah; +asai; +asaj; +asak; +asal; +asam; +asan; +asao; +asap; +asaq; +asar; +asas; +asat; +asau; +asav; +asaw; +asax; +asay; +asaz; +asba; +asbb; +asbc; +asbd; +asbe; +asbf; +asbg; +asbh; +asbi; +asbj; +asbk; +asbl; +asbm; +asbn; +asbo; +asbp; +asbq; +asbr; +asbs; +asbt; +asbu; +asbv; +asbw; +asbx; +asby; +asbz; +asca; +ascb; +ascc; +ascd; +asce; +ascf; +ascg; +asch; +asci; +ascj; +asck; +ascl; +ascm; +ascn; +asco; +ascp; +ascq; +ascr; +ascs; +asct; +ascu; +ascv; +ascw; +ascx; +ascy; +ascz; +asda; +asdb; +asdc; +asdd; +asde; +asdf; +asdg; +asdh; +asdi; +asdj; +asdk; +asdl; +asdm; +asdn; +asdo; +asdp; +asdq; +asdr; +asds; +asdt; +asdu; +asdv; +asdw; +asdx; +asdy; +asdz; +asea; +aseb; +asec; +ased; +asee; +asef; +aseg; +aseh; +asei; +asej; +asek; +asel; +asem; +asen; +aseo; +asep; +aseq; +aser; +ases; +aset; +aseu; +asev; +asew; +asex; +asey; +asez; +asfa; +asfb; +asfc; +asfd; +asfe; +asff; +asfg; +asfh; +asfi; +asfj; +asfk; +asfl; +asfm; +asfn; +asfo; +asfp; +asfq; +asfr; +asfs; +asft; +asfu; +asfv; +asfw; +asfx; +asfy; +asfz; +asga; +asgb; +asgc; +asgd; +asge; +asgf; +asgg; +asgh; +asgi; +asgj; +asgk; +asgl; +asgm; +asgn; +asgo; +asgp; +asgq; +asgr; +asgs; +asgt; +asgu; +asgv; +asgw; +asgx; +asgy; +asgz; +asha; +ashb; +ashc; +ashd; +ashe; +ashf; +ashg; +ashh; +ashi; +ashj; +ashk; +ashl; +ashm; +ashn; +asho; +ashp; +ashq; +ashr; +ashs; +asht; +ashu; +ashv; +ashw; +ashx; +ashy; +ashz; +asia; +asib; +asic; +asid; +asie; +asif; +asig; +asih; +asii; +asij; +asik; +asil; +asim; +asin; +asio; +asip; +asiq; +asir; +asis; +asit; +asiu; +asiv; +asiw; +asix; +asiy; +asiz; +asja; +asjb; +asjc; +asjd; +asje; +asjf; +asjg; +asjh; +asji; +asjj; +asjk; +asjl; +asjm; +asjn; +asjo; +asjp; +asjq; +asjr; +asjs; +asjt; +asju; +asjv; +asjw; +asjx; +asjy; +asjz; +aska; +askb; +askc; +askd; +aske; +askf; +askg; +askh; +aski; +askj; +askk; +askl; +askm; +askn; +asko; +askp; +askq; +askr; +asks; +askt; +asku; +askv; +askw; +askx; +asky; +askz; +asla; +aslb; +aslc; +asld; +asle; +aslf; +aslg; +aslh; +asli; +aslj; +aslk; +asll; +aslm; +asln; +aslo; +aslp; +aslq; +aslr; +asls; +aslt; +aslu; +aslv; +aslw; +aslx; +asly; +aslz; +asma; +asmb; +asmc; +asmd; +asme; +asmf; +asmg; +asmh; +asmi; +asmj; +asmk; +asml; +asmm; +asmn; +asmo; +asmp; +asmq; +asmr; +asms; +asmt; +asmu; +asmv; +asmw; +asmx; +asmy; +asmz; +asna; +asnb; +asnc; +asnd; +asne; +asnf; +asng; +asnh; +asni; +asnj; +asnk; +asnl; +asnm; +asnn; +asno; +asnp; +asnq; +asnr; +asns; +asnt; +asnu; +asnv; +asnw; +asnx; +asny; +asnz; +asoa; +asob; +asoc; +asod; +asoe; +asof; +asog; +asoh; +asoi; +asoj; +asok; +asol; +asom; +ason; +asoo; +asop; +asoq; +asor; +asos; +asot; +asou; +asov; +asow; +asox; +asoy; +asoz; +aspa; +aspb; +aspc; +aspd; +aspe; +aspf; +aspg; +asph; +aspi; +aspj; +aspk; +aspl; +aspm; +aspn; +aspo; +aspp; +aspq; +aspr; +asps; +aspt; +aspu; +aspv; +aspw; +aspx; +aspy; +aspz; +asqa; +asqb; +asqc; +asqd; +asqe; +asqf; +asqg; +asqh; +asqi; +asqj; +asqk; +asql; +asqm; +asqn; +asqo; +asqp; +asqq; +asqr; +asqs; +asqt; +asqu; +asqv; +asqw; +asqx; +asqy; +asqz; +asra; +asrb; +asrc; +asrd; +asre; +asrf; +asrg; +asrh; +asri; +asrj; +asrk; +asrl; +asrm; +asrn; +asro; +asrp; +asrq; +asrr; +asrs; +asrt; +asru; +asrv; +asrw; +asrx; +asry; +asrz; +assa; +assb; +assc; +assd; +asse; +assf; +assg; +assh; +assi; +assj; +assk; +assl; +assm; +assn; +asso; +assp; +assq; +assr; +asss; +asst; +assu; +assv; +assw; +assx; +assy; +assz; +asta; +astb; +astc; +astd; +aste; +astf; +astg; +asth; +asti; +astj; +astk; +astl; +astm; +astn; +asto; +astp; +astq; +astr; +asts; +astt; +astu; +astv; +astw; +astx; +asty; +astz; +asua; +asub; +asuc; +asud; +asue; +asuf; +asug; +asuh; +asui; +asuj; +asuk; +asul; +asum; +asun; +asuo; +asup; +asuq; +asur; +asus; +asut; +asuu; +asuv; +asuw; +asux; +asuy; +asuz; +asva; +asvb; +asvc; +asvd; +asve; +asvf; +asvg; +asvh; +asvi; +asvj; +asvk; +asvl; +asvm; +asvn; +asvo; +asvp; +asvq; +asvr; +asvs; +asvt; +asvu; +asvv; +asvw; +asvx; +asvy; +asvz; +aswa; +aswb; +aswc; +aswd; +aswe; +aswf; +aswg; +aswh; +aswi; +aswj; +aswk; +aswl; +aswm; +aswn; +aswo; +aswp; +aswq; +aswr; +asws; +aswt; +aswu; +aswv; +asww; +aswx; +aswy; +aswz; +asxa; +asxb; +asxc; +asxd; +asxe; +asxf; +asxg; +asxh; +asxi; +asxj; +asxk; +asxl; +asxm; +asxn; +asxo; +asxp; +asxq; +asxr; +asxs; +asxt; +asxu; +asxv; +asxw; +asxx; +asxy; +asxz; +asya; +asyb; +asyc; +asyd; +asye; +asyf; +asyg; +asyh; +asyi; +asyj; +asyk; +asyl; +asym; +asyn; +asyo; +asyp; +asyq; +asyr; +asys; +asyt; +asyu; +asyv; +asyw; +asyx; +asyy; +asyz; +asza; +aszb; +aszc; +aszd; +asze; +aszf; +aszg; +aszh; +aszi; +aszj; +aszk; +aszl; +aszm; +aszn; +aszo; +aszp; +aszq; +aszr; +aszs; +aszt; +aszu; +aszv; +aszw; +aszx; +aszy; +aszz; +ataa; +atab; +atac; +atad; +atae; +ataf; +atag; +atah; +atai; +ataj; +atak; +atal; +atam; +atan; +atao; +atap; +ataq; +atar; +atas; +atat; +atau; +atav; +ataw; +atax; +atay; +ataz; +atba; +atbb; +atbc; +atbd; +atbe; +atbf; +atbg; +atbh; +atbi; +atbj; +atbk; +atbl; +atbm; +atbn; +atbo; +atbp; +atbq; +atbr; +atbs; +atbt; +atbu; +atbv; +atbw; +atbx; +atby; +atbz; +atca; +atcb; +atcc; +atcd; +atce; +atcf; +atcg; +atch; +atci; +atcj; +atck; +atcl; +atcm; +atcn; +atco; +atcp; +atcq; +atcr; +atcs; +atct; +atcu; +atcv; +atcw; +atcx; +atcy; +atcz; +atda; +atdb; +atdc; +atdd; +atde; +atdf; +atdg; +atdh; +atdi; +atdj; +atdk; +atdl; +atdm; +atdn; +atdo; +atdp; +atdq; +atdr; +atds; +atdt; +atdu; +atdv; +atdw; +atdx; +atdy; +atdz; +atea; +ateb; +atec; +ated; +atee; +atef; +ateg; +ateh; +atei; +atej; +atek; +atel; +atem; +aten; +ateo; +atep; +ateq; +ater; +ates; +atet; +ateu; +atev; +atew; +atex; +atey; +atez; +atfa; +atfb; +atfc; +atfd; +atfe; +atff; +atfg; +atfh; +atfi; +atfj; +atfk; +atfl; +atfm; +atfn; +atfo; +atfp; +atfq; +atfr; +atfs; +atft; +atfu; +atfv; +atfw; +atfx; +atfy; +atfz; +atga; +atgb; +atgc; +atgd; +atge; +atgf; +atgg; +atgh; +atgi; +atgj; +atgk; +atgl; +atgm; +atgn; +atgo; +atgp; +atgq; +atgr; +atgs; +atgt; +atgu; +atgv; +atgw; +atgx; +atgy; +atgz; +atha; +athb; +athc; +athd; +athe; +athf; +athg; +athh; +athi; +athj; +athk; +athl; +athm; +athn; +atho; +athp; +athq; +athr; +aths; +atht; +athu; +athv; +athw; +athx; +athy; +athz; +atia; +atib; +atic; +atid; +atie; +atif; +atig; +atih; +atii; +atij; +atik; +atil; +atim; +atin; +atio; +atip; +atiq; +atir; +atis; +atit; +atiu; +ativ; +atiw; +atix; +atiy; +atiz; +atja; +atjb; +atjc; +atjd; +atje; +atjf; +atjg; +atjh; +atji; +atjj; +atjk; +atjl; +atjm; +atjn; +atjo; +atjp; +atjq; +atjr; +atjs; +atjt; +atju; +atjv; +atjw; +atjx; +atjy; +atjz; +atka; +atkb; +atkc; +atkd; +atke; +atkf; +atkg; +atkh; +atki; +atkj; +atkk; +atkl; +atkm; +atkn; +atko; +atkp; +atkq; +atkr; +atks; +atkt; +atku; +atkv; +atkw; +atkx; +atky; +atkz; +atla; +atlb; +atlc; +atld; +atle; +atlf; +atlg; +atlh; +atli; +atlj; +atlk; +atll; +atlm; +atln; +atlo; +atlp; +atlq; +atlr; +atls; +atlt; +atlu; +atlv; +atlw; +atlx; +atly; +atlz; +atma; +atmb; +atmc; +atmd; +atme; +atmf; +atmg; +atmh; +atmi; +atmj; +atmk; +atml; +atmm; +atmn; +atmo; +atmp; +atmq; +atmr; +atms; +atmt; +atmu; +atmv; +atmw; +atmx; +atmy; +atmz; +atna; +atnb; +atnc; +atnd; +atne; +atnf; +atng; +atnh; +atni; +atnj; +atnk; +atnl; +atnm; +atnn; +atno; +atnp; +atnq; +atnr; +atns; +atnt; +atnu; +atnv; +atnw; +atnx; +atny; +atnz; +atoa; +atob; +atoc; +atod; +atoe; +atof; +atog; +atoh; +atoi; +atoj; +atok; +atol; +atom; +aton; +atoo; +atop; +atoq; +ator; +atos; +atot; +atou; +atov; +atow; +atox; +atoy; +atoz; +atpa; +atpb; +atpc; +atpd; +atpe; +atpf; +atpg; +atph; +atpi; +atpj; +atpk; +atpl; +atpm; +atpn; +atpo; +atpp; +atpq; +atpr; +atps; +atpt; +atpu; +atpv; +atpw; +atpx; +atpy; +atpz; +atqa; +atqb; +atqc; +atqd; +atqe; +atqf; +atqg; +atqh; +atqi; +atqj; +atqk; +atql; +atqm; +atqn; +atqo; +atqp; +atqq; +atqr; +atqs; +atqt; +atqu; +atqv; +atqw; +atqx; +atqy; +atqz; +atra; +atrb; +atrc; +atrd; +atre; +atrf; +atrg; +atrh; +atri; +atrj; +atrk; +atrl; +atrm; +atrn; +atro; +atrp; +atrq; +atrr; +atrs; +atrt; +atru; +atrv; +atrw; +atrx; +atry; +atrz; +atsa; +atsb; +atsc; +atsd; +atse; +atsf; +atsg; +atsh; +atsi; +atsj; +atsk; +atsl; +atsm; +atsn; +atso; +atsp; +atsq; +atsr; +atss; +atst; +atsu; +atsv; +atsw; +atsx; +atsy; +atsz; +atta; +attb; +attc; +attd; +atte; +attf; +attg; +atth; +atti; +attj; +attk; +attl; +attm; +attn; +atto; +attp; +attq; +attr; +atts; +attt; +attu; +attv; +attw; +attx; +atty; +attz; +atua; +atub; +atuc; +atud; +atue; +atuf; +atug; +atuh; +atui; +atuj; +atuk; +atul; +atum; +atun; +atuo; +atup; +atuq; +atur; +atus; +atut; +atuu; +atuv; +atuw; +atux; +atuy; +atuz; +atva; +atvb; +atvc; +atvd; +atve; +atvf; +atvg; +atvh; +atvi; +atvj; +atvk; +atvl; +atvm; +atvn; +atvo; +atvp; +atvq; +atvr; +atvs; +atvt; +atvu; +atvv; +atvw; +atvx; +atvy; +atvz; +atwa; +atwb; +atwc; +atwd; +atwe; +atwf; +atwg; +atwh; +atwi; +atwj; +atwk; +atwl; +atwm; +atwn; +atwo; +atwp; +atwq; +atwr; +atws; +atwt; +atwu; +atwv; +atww; +atwx; +atwy; +atwz; +atxa; +atxb; +atxc; +atxd; +atxe; +atxf; +atxg; +atxh; +atxi; +atxj; +atxk; +atxl; +atxm; +atxn; +atxo; +atxp; +atxq; +atxr; +atxs; +atxt; +atxu; +atxv; +atxw; +atxx; +atxy; +atxz; +atya; +atyb; +atyc; +atyd; +atye; +atyf; +atyg; +atyh; +atyi; +atyj; +atyk; +atyl; +atym; +atyn; +atyo; +atyp; +atyq; +atyr; +atys; +atyt; +atyu; +atyv; +atyw; +atyx; +atyy; +atyz; +atza; +atzb; +atzc; +atzd; +atze; +atzf; +atzg; +atzh; +atzi; +atzj; +atzk; +atzl; +atzm; +atzn; +atzo; +atzp; +atzq; +atzr; +atzs; +atzt; +atzu; +atzv; +atzw; +atzx; +atzy; +atzz; +auaa; +auab; +auac; +auad; +auae; +auaf; +auag; +auah; +auai; +auaj; +auak; +aual; +auam; +auan; +auao; +auap; +auaq; +auar; +auas; +auat; +auau; +auav; +auaw; +auax; +auay; +auaz; +auba; +aubb; +aubc; +aubd; +aube; +aubf; +aubg; +aubh; +aubi; +aubj; +aubk; +aubl; +aubm; +aubn; +aubo; +aubp; +aubq; +aubr; +aubs; +aubt; +aubu; +aubv; +aubw; +aubx; +auby; +aubz; +auca; +aucb; +aucc; +aucd; +auce; +aucf; +aucg; +auch; +auci; +aucj; +auck; +aucl; +aucm; +aucn; +auco; +aucp; +aucq; +aucr; +aucs; +auct; +aucu; +aucv; +aucw; +aucx; +aucy; +aucz; +auda; +audb; +audc; +audd; +aude; +audf; +audg; +audh; +audi; +audj; +audk; +audl; +audm; +audn; +audo; +audp; +audq; +audr; +auds; +audt; +audu; +audv; +audw; +audx; +audy; +audz; +auea; +aueb; +auec; +aued; +auee; +auef; +aueg; +aueh; +auei; +auej; +auek; +auel; +auem; +auen; +aueo; +auep; +aueq; +auer; +aues; +auet; +aueu; +auev; +auew; +auex; +auey; +auez; +aufa; +aufb; +aufc; +aufd; +aufe; +auff; +aufg; +aufh; +aufi; +aufj; +aufk; +aufl; +aufm; +aufn; +aufo; +aufp; +aufq; +aufr; +aufs; +auft; +aufu; +aufv; +aufw; +aufx; +aufy; +aufz; +auga; +augb; +augc; +augd; +auge; +augf; +augg; +augh; +augi; +augj; +augk; +augl; +augm; +augn; +augo; +augp; +augq; +augr; +augs; +augt; +augu; +augv; +augw; +augx; +augy; +augz; +auha; +auhb; +auhc; +auhd; +auhe; +auhf; +auhg; +auhh; +auhi; +auhj; +auhk; +auhl; +auhm; +auhn; +auho; +auhp; +auhq; +auhr; +auhs; +auht; +auhu; +auhv; +auhw; +auhx; +auhy; +auhz; +auia; +auib; +auic; +auid; +auie; +auif; +auig; +auih; +auii; +auij; +auik; +auil; +auim; +auin; +auio; +auip; +auiq; +auir; +auis; +auit; +auiu; +auiv; +auiw; +auix; +auiy; +auiz; +auja; +aujb; +aujc; +aujd; +auje; +aujf; +aujg; +aujh; +auji; +aujj; +aujk; +aujl; +aujm; +aujn; +aujo; +aujp; +aujq; +aujr; +aujs; +aujt; +auju; +aujv; +aujw; +aujx; +aujy; +aujz; +auka; +aukb; +aukc; +aukd; +auke; +aukf; +aukg; +aukh; +auki; +aukj; +aukk; +aukl; +aukm; +aukn; +auko; +aukp; +aukq; +aukr; +auks; +aukt; +auku; +aukv; +aukw; +aukx; +auky; +aukz; +aula; +aulb; +aulc; +auld; +aule; +aulf; +aulg; +aulh; +auli; +aulj; +aulk; +aull; +aulm; +auln; +aulo; +aulp; +aulq; +aulr; +auls; +ault; +aulu; +aulv; +aulw; +aulx; +auly; +aulz; +auma; +aumb; +aumc; +aumd; +aume; +aumf; +aumg; +aumh; +aumi; +aumj; +aumk; +auml; +aumm; +aumn; +aumo; +aump; +aumq; +aumr; +aums; +aumt; +aumu; +aumv; +aumw; +aumx; +aumy; +aumz; +auna; +aunb; +aunc; +aund; +aune; +aunf; +aung; +aunh; +auni; +aunj; +aunk; +aunl; +aunm; +aunn; +auno; +aunp; +aunq; +aunr; +auns; +aunt; +aunu; +aunv; +aunw; +aunx; +auny; +aunz; +auoa; +auob; +auoc; +auod; +auoe; +auof; +auog; +auoh; +auoi; +auoj; +auok; +auol; +auom; +auon; +auoo; +auop; +auoq; +auor; +auos; +auot; +auou; +auov; +auow; +auox; +auoy; +auoz; +aupa; +aupb; +aupc; +aupd; +aupe; +aupf; +aupg; +auph; +aupi; +aupj; +aupk; +aupl; +aupm; +aupn; +aupo; +aupp; +aupq; +aupr; +aups; +aupt; +aupu; +aupv; +aupw; +aupx; +aupy; +aupz; +auqa; +auqb; +auqc; +auqd; +auqe; +auqf; +auqg; +auqh; +auqi; +auqj; +auqk; +auql; +auqm; +auqn; +auqo; +auqp; +auqq; +auqr; +auqs; +auqt; +auqu; +auqv; +auqw; +auqx; +auqy; +auqz; +aura; +aurb; +aurc; +aurd; +aure; +aurf; +aurg; +aurh; +auri; +aurj; +aurk; +aurl; +aurm; +aurn; +auro; +aurp; +aurq; +aurr; +aurs; +aurt; +auru; +aurv; +aurw; +aurx; +aury; +aurz; +ausa; +ausb; +ausc; +ausd; +ause; +ausf; +ausg; +aush; +ausi; +ausj; +ausk; +ausl; +ausm; +ausn; +auso; +ausp; +ausq; +ausr; +auss; +aust; +ausu; +ausv; +ausw; +ausx; +ausy; +ausz; +auta; +autb; +autc; +autd; +aute; +autf; +autg; +auth; +auti; +autj; +autk; +autl; +autm; +autn; +auto; +autp; +autq; +autr; +auts; +autt; +autu; +autv; +autw; +autx; +auty; +autz; +auua; +auub; +auuc; +auud; +auue; +auuf; +auug; +auuh; +auui; +auuj; +auuk; +auul; +auum; +auun; +auuo; +auup; +auuq; +auur; +auus; +auut; +auuu; +auuv; +auuw; +auux; +auuy; +auuz; +auva; +auvb; +auvc; +auvd; +auve; +auvf; +auvg; +auvh; +auvi; +auvj; +auvk; +auvl; +auvm; +auvn; +auvo; +auvp; +auvq; +auvr; +auvs; +auvt; +auvu; +auvv; +auvw; +auvx; +auvy; +auvz; +auwa; +auwb; +auwc; +auwd; +auwe; +auwf; +auwg; +auwh; +auwi; +auwj; +auwk; +auwl; +auwm; +auwn; +auwo; +auwp; +auwq; +auwr; +auws; +auwt; +auwu; +auwv; +auww; +auwx; +auwy; +auwz; +auxa; +auxb; +auxc; +auxd; +auxe; +auxf; +auxg; +auxh; +auxi; +auxj; +auxk; +auxl; +auxm; +auxn; +auxo; +auxp; +auxq; +auxr; +auxs; +auxt; +auxu; +auxv; +auxw; +auxx; +auxy; +auxz; +auya; +auyb; +auyc; +auyd; +auye; +auyf; +auyg; +auyh; +auyi; +auyj; +auyk; +auyl; +auym; +auyn; +auyo; +auyp; +auyq; +auyr; +auys; +auyt; +auyu; +auyv; +auyw; +auyx; +auyy; +auyz; +auza; +auzb; +auzc; +auzd; +auze; +auzf; +auzg; +auzh; +auzi; +auzj; +auzk; +auzl; +auzm; +auzn; +auzo; +auzp; +auzq; +auzr; +auzs; +auzt; +auzu; +auzv; +auzw; +auzx; +auzy; +auzz; +avaa; +avab; +avac; +avad; +avae; +avaf; +avag; +avah; +avai; +avaj; +avak; +aval; +avam; +avan; +avao; +avap; +avaq; +avar; +avas; +avat; +avau; +avav; +avaw; +avax; +avay; +avaz; +avba; +avbb; +avbc; +avbd; +avbe; +avbf; +avbg; +avbh; +avbi; +avbj; +avbk; +avbl; +avbm; +avbn; +avbo; +avbp; +avbq; +avbr; +avbs; +avbt; +avbu; +avbv; +avbw; +avbx; +avby; +avbz; +avca; +avcb; +avcc; +avcd; +avce; +avcf; +avcg; +avch; +avci; +avcj; +avck; +avcl; +avcm; +avcn; +avco; +avcp; +avcq; +avcr; +avcs; +avct; +avcu; +avcv; +avcw; +avcx; +avcy; +avcz; +avda; +avdb; +avdc; +avdd; +avde; +avdf; +avdg; +avdh; +avdi; +avdj; +avdk; +avdl; +avdm; +avdn; +avdo; +avdp; +avdq; +avdr; +avds; +avdt; +avdu; +avdv; +avdw; +avdx; +avdy; +avdz; +avea; +aveb; +avec; +aved; +avee; +avef; +aveg; +aveh; +avei; +avej; +avek; +avel; +avem; +aven; +aveo; +avep; +aveq; +aver; +aves; +avet; +aveu; +avev; +avew; +avex; +avey; +avez; +avfa; +avfb; +avfc; +avfd; +avfe; +avff; +avfg; +avfh; +avfi; +avfj; +avfk; +avfl; +avfm; +avfn; +avfo; +avfp; +avfq; +avfr; +avfs; +avft; +avfu; +avfv; +avfw; +avfx; +avfy; +avfz; +avga; +avgb; +avgc; +avgd; +avge; +avgf; +avgg; +avgh; +avgi; +avgj; +avgk; +avgl; +avgm; +avgn; +avgo; +avgp; +avgq; +avgr; +avgs; +avgt; +avgu; +avgv; +avgw; +avgx; +avgy; +avgz; +avha; +avhb; +avhc; +avhd; +avhe; +avhf; +avhg; +avhh; +avhi; +avhj; +avhk; +avhl; +avhm; +avhn; +avho; +avhp; +avhq; +avhr; +avhs; +avht; +avhu; +avhv; +avhw; +avhx; +avhy; +avhz; +avia; +avib; +avic; +avid; +avie; +avif; +avig; +avih; +avii; +avij; +avik; +avil; +avim; +avin; +avio; +avip; +aviq; +avir; +avis; +avit; +aviu; +aviv; +aviw; +avix; +aviy; +aviz; +avja; +avjb; +avjc; +avjd; +avje; +avjf; +avjg; +avjh; +avji; +avjj; +avjk; +avjl; +avjm; +avjn; +avjo; +avjp; +avjq; +avjr; +avjs; +avjt; +avju; +avjv; +avjw; +avjx; +avjy; +avjz; +avka; +avkb; +avkc; +avkd; +avke; +avkf; +avkg; +avkh; +avki; +avkj; +avkk; +avkl; +avkm; +avkn; +avko; +avkp; +avkq; +avkr; +avks; +avkt; +avku; +avkv; +avkw; +avkx; +avky; +avkz; +avla; +avlb; +avlc; +avld; +avle; +avlf; +avlg; +avlh; +avli; +avlj; +avlk; +avll; +avlm; +avln; +avlo; +avlp; +avlq; +avlr; +avls; +avlt; +avlu; +avlv; +avlw; +avlx; +avly; +avlz; +avma; +avmb; +avmc; +avmd; +avme; +avmf; +avmg; +avmh; +avmi; +avmj; +avmk; +avml; +avmm; +avmn; +avmo; +avmp; +avmq; +avmr; +avms; +avmt; +avmu; +avmv; +avmw; +avmx; +avmy; +avmz; +avna; +avnb; +avnc; +avnd; +avne; +avnf; +avng; +avnh; +avni; +avnj; +avnk; +avnl; +avnm; +avnn; +avno; +avnp; +avnq; +avnr; +avns; +avnt; +avnu; +avnv; +avnw; +avnx; +avny; +avnz; +avoa; +avob; +avoc; +avod; +avoe; +avof; +avog; +avoh; +avoi; +avoj; +avok; +avol; +avom; +avon; +avoo; +avop; +avoq; +avor; +avos; +avot; +avou; +avov; +avow; +avox; +avoy; +avoz; +avpa; +avpb; +avpc; +avpd; +avpe; +avpf; +avpg; +avph; +avpi; +avpj; +avpk; +avpl; +avpm; +avpn; +avpo; +avpp; +avpq; +avpr; +avps; +avpt; +avpu; +avpv; +avpw; +avpx; +avpy; +avpz; +avqa; +avqb; +avqc; +avqd; +avqe; +avqf; +avqg; +avqh; +avqi; +avqj; +avqk; +avql; +avqm; +avqn; +avqo; +avqp; +avqq; +avqr; +avqs; +avqt; +avqu; +avqv; +avqw; +avqx; +avqy; +avqz; +avra; +avrb; +avrc; +avrd; +avre; +avrf; +avrg; +avrh; +avri; +avrj; +avrk; +avrl; +avrm; +avrn; +avro; +avrp; +avrq; +avrr; +avrs; +avrt; +avru; +avrv; +avrw; +avrx; +avry; +avrz; +avsa; +avsb; +avsc; +avsd; +avse; +avsf; +avsg; +avsh; +avsi; +avsj; +avsk; +avsl; +avsm; +avsn; +avso; +avsp; +avsq; +avsr; +avss; +avst; +avsu; +avsv; +avsw; +avsx; +avsy; +avsz; +avta; +avtb; +avtc; +avtd; +avte; +avtf; +avtg; +avth; +avti; +avtj; +avtk; +avtl; +avtm; +avtn; +avto; +avtp; +avtq; +avtr; +avts; +avtt; +avtu; +avtv; +avtw; +avtx; +avty; +avtz; +avua; +avub; +avuc; +avud; +avue; +avuf; +avug; +avuh; +avui; +avuj; +avuk; +avul; +avum; +avun; +avuo; +avup; +avuq; +avur; +avus; +avut; +avuu; +avuv; +avuw; +avux; +avuy; +avuz; +avva; +avvb; +avvc; +avvd; +avve; +avvf; +avvg; +avvh; +avvi; +avvj; +avvk; +avvl; +avvm; +avvn; +avvo; +avvp; +avvq; +avvr; +avvs; +avvt; +avvu; +avvv; +avvw; +avvx; +avvy; +avvz; +avwa; +avwb; +avwc; +avwd; +avwe; +avwf; +avwg; +avwh; +avwi; +avwj; +avwk; +avwl; +avwm; +avwn; +avwo; +avwp; +avwq; +avwr; +avws; +avwt; +avwu; +avwv; +avww; +avwx; +avwy; +avwz; +avxa; +avxb; +avxc; +avxd; +avxe; +avxf; +avxg; +avxh; +avxi; +avxj; +avxk; +avxl; +avxm; +avxn; +avxo; +avxp; +avxq; +avxr; +avxs; +avxt; +avxu; +avxv; +avxw; +avxx; +avxy; +avxz; +avya; +avyb; +avyc; +avyd; +avye; +avyf; +avyg; +avyh; +avyi; +avyj; +avyk; +avyl; +avym; +avyn; +avyo; +avyp; +avyq; +avyr; +avys; +avyt; +avyu; +avyv; +avyw; +avyx; +avyy; +avyz; +avza; +avzb; +avzc; +avzd; +avze; +avzf; +avzg; +avzh; +avzi; +avzj; +avzk; +avzl; +avzm; +avzn; +avzo; +avzp; +avzq; +avzr; +avzs; +avzt; +avzu; +avzv; +avzw; +avzx; +avzy; +avzz; +awaa; +awab; +awac; +awad; +awae; +awaf; +awag; +awah; +awai; +awaj; +awak; +awal; +awam; +awan; +awao; +awap; +awaq; +awar; +awas; +awat; +awau; +awav; +awaw; +awax; +away; +awaz; +awba; +awbb; +awbc; +awbd; +awbe; +awbf; +awbg; +awbh; +awbi; +awbj; +awbk; +awbl; +awbm; +awbn; +awbo; +awbp; +awbq; +awbr; +awbs; +awbt; +awbu; +awbv; +awbw; +awbx; +awby; +awbz; +awca; +awcb; +awcc; +awcd; +awce; +awcf; +awcg; +awch; +awci; +awcj; +awck; +awcl; +awcm; +awcn; +awco; +awcp; +awcq; +awcr; +awcs; +awct; +awcu; +awcv; +awcw; +awcx; +awcy; +awcz; +awda; +awdb; +awdc; +awdd; +awde; +awdf; +awdg; +awdh; +awdi; +awdj; +awdk; +awdl; +awdm; +awdn; +awdo; +awdp; +awdq; +awdr; +awds; +awdt; +awdu; +awdv; +awdw; +awdx; +awdy; +awdz; +awea; +aweb; +awec; +awed; +awee; +awef; +aweg; +aweh; +awei; +awej; +awek; +awel; +awem; +awen; +aweo; +awep; +aweq; +awer; +awes; +awet; +aweu; +awev; +awew; +awex; +awey; +awez; +awfa; +awfb; +awfc; +awfd; +awfe; +awff; +awfg; +awfh; +awfi; +awfj; +awfk; +awfl; +awfm; +awfn; +awfo; +awfp; +awfq; +awfr; +awfs; +awft; +awfu; +awfv; +awfw; +awfx; +awfy; +awfz; +awga; +awgb; +awgc; +awgd; +awge; +awgf; +awgg; +awgh; +awgi; +awgj; +awgk; +awgl; +awgm; +awgn; +awgo; +awgp; +awgq; +awgr; +awgs; +awgt; +awgu; +awgv; +awgw; +awgx; +awgy; +awgz; +awha; +awhb; +awhc; +awhd; +awhe; +awhf; +awhg; +awhh; +awhi; +awhj; +awhk; +awhl; +awhm; +awhn; +awho; +awhp; +awhq; +awhr; +awhs; +awht; +awhu; +awhv; +awhw; +awhx; +awhy; +awhz; +awia; +awib; +awic; +awid; +awie; +awif; +awig; +awih; +awii; +awij; +awik; +awil; +awim; +awin; +awio; +awip; +awiq; +awir; +awis; +awit; +awiu; +awiv; +awiw; +awix; +awiy; +awiz; +awja; +awjb; +awjc; +awjd; +awje; +awjf; +awjg; +awjh; +awji; +awjj; +awjk; +awjl; +awjm; +awjn; +awjo; +awjp; +awjq; +awjr; +awjs; +awjt; +awju; +awjv; +awjw; +awjx; +awjy; +awjz; +awka; +awkb; +awkc; +awkd; +awke; +awkf; +awkg; +awkh; +awki; +awkj; +awkk; +awkl; +awkm; +awkn; +awko; +awkp; +awkq; +awkr; +awks; +awkt; +awku; +awkv; +awkw; +awkx; +awky; +awkz; +awla; +awlb; +awlc; +awld; +awle; +awlf; +awlg; +awlh; +awli; +awlj; +awlk; +awll; +awlm; +awln; +awlo; +awlp; +awlq; +awlr; +awls; +awlt; +awlu; +awlv; +awlw; +awlx; +awly; +awlz; +awma; +awmb; +awmc; +awmd; +awme; +awmf; +awmg; +awmh; +awmi; +awmj; +awmk; +awml; +awmm; +awmn; +awmo; +awmp; +awmq; +awmr; +awms; +awmt; +awmu; +awmv; +awmw; +awmx; +awmy; +awmz; +awna; +awnb; +awnc; +awnd; +awne; +awnf; +awng; +awnh; +awni; +awnj; +awnk; +awnl; +awnm; +awnn; +awno; +awnp; +awnq; +awnr; +awns; +awnt; +awnu; +awnv; +awnw; +awnx; +awny; +awnz; +awoa; +awob; +awoc; +awod; +awoe; +awof; +awog; +awoh; +awoi; +awoj; +awok; +awol; +awom; +awon; +awoo; +awop; +awoq; +awor; +awos; +awot; +awou; +awov; +awow; +awox; +awoy; +awoz; +awpa; +awpb; +awpc; +awpd; +awpe; +awpf; +awpg; +awph; +awpi; +awpj; +awpk; +awpl; +awpm; +awpn; +awpo; +awpp; +awpq; +awpr; +awps; +awpt; +awpu; +awpv; +awpw; +awpx; +awpy; +awpz; +awqa; +awqb; +awqc; +awqd; +awqe; +awqf; +awqg; +awqh; +awqi; +awqj; +awqk; +awql; +awqm; +awqn; +awqo; +awqp; +awqq; +awqr; +awqs; +awqt; +awqu; +awqv; +awqw; +awqx; +awqy; +awqz; +awra; +awrb; +awrc; +awrd; +awre; +awrf; +awrg; +awrh; +awri; +awrj; +awrk; +awrl; +awrm; +awrn; +awro; +awrp; +awrq; +awrr; +awrs; +awrt; +awru; +awrv; +awrw; +awrx; +awry; +awrz; +awsa; +awsb; +awsc; +awsd; +awse; +awsf; +awsg; +awsh; +awsi; +awsj; +awsk; +awsl; +awsm; +awsn; +awso; +awsp; +awsq; +awsr; +awss; +awst; +awsu; +awsv; +awsw; +awsx; +awsy; +awsz; +awta; +awtb; +awtc; +awtd; +awte; +awtf; +awtg; +awth; +awti; +awtj; +awtk; +awtl; +awtm; +awtn; +awto; +awtp; +awtq; +awtr; +awts; +awtt; +awtu; +awtv; +awtw; +awtx; +awty; +awtz; +awua; +awub; +awuc; +awud; +awue; +awuf; +awug; +awuh; +awui; +awuj; +awuk; +awul; +awum; +awun; +awuo; +awup; +awuq; +awur; +awus; +awut; +awuu; +awuv; +awuw; +awux; +awuy; +awuz; +awva; +awvb; +awvc; +awvd; +awve; +awvf; +awvg; +awvh; +awvi; +awvj; +awvk; +awvl; +awvm; +awvn; +awvo; +awvp; +awvq; +awvr; +awvs; +awvt; +awvu; +awvv; +awvw; +awvx; +awvy; +awvz; +awwa; +awwb; +awwc; +awwd; +awwe; +awwf; +awwg; +awwh; +awwi; +awwj; +awwk; +awwl; +awwm; +awwn; +awwo; +awwp; +awwq; +awwr; +awws; +awwt; +awwu; +awwv; +awww; +awwx; +awwy; +awwz; +awxa; +awxb; +awxc; +awxd; +awxe; +awxf; +awxg; +awxh; +awxi; +awxj; +awxk; +awxl; +awxm; +awxn; +awxo; +awxp; +awxq; +awxr; +awxs; +awxt; +awxu; +awxv; +awxw; +awxx; +awxy; +awxz; +awya; +awyb; +awyc; +awyd; +awye; +awyf; +awyg; +awyh; +awyi; +awyj; +awyk; +awyl; +awym; +awyn; +awyo; +awyp; +awyq; +awyr; +awys; +awyt; +awyu; +awyv; +awyw; +awyx; +awyy; +awyz; +awza; +awzb; +awzc; +awzd; +awze; +awzf; +awzg; +awzh; +awzi; +awzj; +awzk; +awzl; +awzm; +awzn; +awzo; +awzp; +awzq; +awzr; +awzs; +awzt; +awzu; +awzv; +awzw; +awzx; +awzy; +awzz; +axaa; +axab; +axac; +axad; +axae; +axaf; +axag; +axah; +axai; +axaj; +axak; +axal; +axam; +axan; +axao; +axap; +axaq; +axar; +axas; +axat; +axau; +axav; +axaw; +axax; +axay; +axaz; +axba; +axbb; +axbc; +axbd; +axbe; +axbf; +axbg; +axbh; +axbi; +axbj; +axbk; +axbl; +axbm; +axbn; +axbo; +axbp; +axbq; +axbr; +axbs; +axbt; +axbu; +axbv; +axbw; +axbx; +axby; +axbz; +axca; +axcb; +axcc; +axcd; +axce; +axcf; +axcg; +axch; +axci; +axcj; +axck; +axcl; +axcm; +axcn; +axco; +axcp; +axcq; +axcr; +axcs; +axct; +axcu; +axcv; +axcw; +axcx; +axcy; +axcz; +axda; +axdb; +axdc; +axdd; +axde; +axdf; +axdg; +axdh; +axdi; +axdj; +axdk; +axdl; +axdm; +axdn; +axdo; +axdp; +axdq; +axdr; +axds; +axdt; +axdu; +axdv; +axdw; +axdx; +axdy; +axdz; +axea; +axeb; +axec; +axed; +axee; +axef; +axeg; +axeh; +axei; +axej; +axek; +axel; +axem; +axen; +axeo; +axep; +axeq; +axer; +axes; +axet; +axeu; +axev; +axew; +axex; +axey; +axez; +axfa; +axfb; +axfc; +axfd; +axfe; +axff; +axfg; +axfh; +axfi; +axfj; +axfk; +axfl; +axfm; +axfn; +axfo; +axfp; +axfq; +axfr; +axfs; +axft; +axfu; +axfv; +axfw; +axfx; +axfy; +axfz; +axga; +axgb; +axgc; +axgd; +axge; +axgf; +axgg; +axgh; +axgi; +axgj; +axgk; +axgl; +axgm; +axgn; +axgo; +axgp; +axgq; +axgr; +axgs; +axgt; +axgu; +axgv; +axgw; +axgx; +axgy; +axgz; +axha; +axhb; +axhc; +axhd; +axhe; +axhf; +axhg; +axhh; +axhi; +axhj; +axhk; +axhl; +axhm; +axhn; +axho; +axhp; +axhq; +axhr; +axhs; +axht; +axhu; +axhv; +axhw; +axhx; +axhy; +axhz; +axia; +axib; +axic; +axid; +axie; +axif; +axig; +axih; +axii; +axij; +axik; +axil; +axim; +axin; +axio; +axip; +axiq; +axir; +axis; +axit; +axiu; +axiv; +axiw; +axix; +axiy; +axiz; +axja; +axjb; +axjc; +axjd; +axje; +axjf; +axjg; +axjh; +axji; +axjj; +axjk; +axjl; +axjm; +axjn; +axjo; +axjp; +axjq; +axjr; +axjs; +axjt; +axju; +axjv; +axjw; +axjx; +axjy; +axjz; +axka; +axkb; +axkc; +axkd; +axke; +axkf; +axkg; +axkh; +axki; +axkj; +axkk; +axkl; +axkm; +axkn; +axko; +axkp; +axkq; +axkr; +axks; +axkt; +axku; +axkv; +axkw; +axkx; +axky; +axkz; +axla; +axlb; +axlc; +axld; +axle; +axlf; +axlg; +axlh; +axli; +axlj; +axlk; +axll; +axlm; +axln; +axlo; +axlp; +axlq; +axlr; +axls; +axlt; +axlu; +axlv; +axlw; +axlx; +axly; +axlz; +axma; +axmb; +axmc; +axmd; +axme; +axmf; +axmg; +axmh; +axmi; +axmj; +axmk; +axml; +axmm; +axmn; +axmo; +axmp; +axmq; +axmr; +axms; +axmt; +axmu; +axmv; +axmw; +axmx; +axmy; +axmz; +axna; +axnb; +axnc; +axnd; +axne; +axnf; +axng; +axnh; +axni; +axnj; +axnk; +axnl; +axnm; +axnn; +axno; +axnp; +axnq; +axnr; +axns; +axnt; +axnu; +axnv; +axnw; +axnx; +axny; +axnz; +axoa; +axob; +axoc; +axod; +axoe; +axof; +axog; +axoh; +axoi; +axoj; +axok; +axol; +axom; +axon; +axoo; +axop; +axoq; +axor; +axos; +axot; +axou; +axov; +axow; +axox; +axoy; +axoz; +axpa; +axpb; +axpc; +axpd; +axpe; +axpf; +axpg; +axph; +axpi; +axpj; +axpk; +axpl; +axpm; +axpn; +axpo; +axpp; +axpq; +axpr; +axps; +axpt; +axpu; +axpv; +axpw; +axpx; +axpy; +axpz; +axqa; +axqb; +axqc; +axqd; +axqe; +axqf; +axqg; +axqh; +axqi; +axqj; +axqk; +axql; +axqm; +axqn; +axqo; +axqp; +axqq; +axqr; +axqs; +axqt; +axqu; +axqv; +axqw; +axqx; +axqy; +axqz; +axra; +axrb; +axrc; +axrd; +axre; +axrf; +axrg; +axrh; +axri; +axrj; +axrk; +axrl; +axrm; +axrn; +axro; +axrp; +axrq; +axrr; +axrs; +axrt; +axru; +axrv; +axrw; +axrx; +axry; +axrz; +axsa; +axsb; +axsc; +axsd; +axse; +axsf; +axsg; +axsh; +axsi; +axsj; +axsk; +axsl; +axsm; +axsn; +axso; +axsp; +axsq; +axsr; +axss; +axst; +axsu; +axsv; +axsw; +axsx; +axsy; +axsz; +axta; +axtb; +axtc; +axtd; +axte; +axtf; +axtg; +axth; +axti; +axtj; +axtk; +axtl; +axtm; +axtn; +axto; +axtp; +axtq; +axtr; +axts; +axtt; +axtu; +axtv; +axtw; +axtx; +axty; +axtz; +axua; +axub; +axuc; +axud; +axue; +axuf; +axug; +axuh; +axui; +axuj; +axuk; +axul; +axum; +axun; +axuo; +axup; +axuq; +axur; +axus; +axut; +axuu; +axuv; +axuw; +axux; +axuy; +axuz; +axva; +axvb; +axvc; +axvd; +axve; +axvf; +axvg; +axvh; +axvi; +axvj; +axvk; +axvl; +axvm; +axvn; +axvo; +axvp; +axvq; +axvr; +axvs; +axvt; +axvu; +axvv; +axvw; +axvx; +axvy; +axvz; +axwa; +axwb; +axwc; +axwd; +axwe; +axwf; +axwg; +axwh; +axwi; +axwj; +axwk; +axwl; +axwm; +axwn; +axwo; +axwp; +axwq; +axwr; +axws; +axwt; +axwu; +axwv; +axww; +axwx; +axwy; +axwz; +axxa; +axxb; +axxc; +axxd; +axxe; +axxf; +axxg; +axxh; +axxi; +axxj; +axxk; +axxl; +axxm; +axxn; +axxo; +axxp; +axxq; +axxr; +axxs; +axxt; +axxu; +axxv; +axxw; +axxx; +axxy; +axxz; +axya; +axyb; +axyc; +axyd; +axye; +axyf; +axyg; +axyh; +axyi; +axyj; +axyk; +axyl; +axym; +axyn; +axyo; +axyp; +axyq; +axyr; +axys; +axyt; +axyu; +axyv; +axyw; +axyx; +axyy; +axyz; +axza; +axzb; +axzc; +axzd; +axze; +axzf; +axzg; +axzh; +axzi; +axzj; +axzk; +axzl; +axzm; +axzn; +axzo; +axzp; +axzq; +axzr; +axzs; +axzt; +axzu; +axzv; +axzw; +axzx; +axzy; +axzz; +ayaa; +ayab; +ayac; +ayad; +ayae; +ayaf; +ayag; +ayah; +ayai; +ayaj; +ayak; +ayal; +ayam; +ayan; +ayao; +ayap; +ayaq; +ayar; +ayas; +ayat; +ayau; +ayav; +ayaw; +ayax; +ayay; +ayaz; +ayba; +aybb; +aybc; +aybd; +aybe; +aybf; +aybg; +aybh; +aybi; +aybj; +aybk; +aybl; +aybm; +aybn; +aybo; +aybp; +aybq; +aybr; +aybs; +aybt; +aybu; +aybv; +aybw; +aybx; +ayby; +aybz; +ayca; +aycb; +aycc; +aycd; +ayce; +aycf; +aycg; +aych; +ayci; +aycj; +ayck; +aycl; +aycm; +aycn; +ayco; +aycp; +aycq; +aycr; +aycs; +ayct; +aycu; +aycv; +aycw; +aycx; +aycy; +aycz; +ayda; +aydb; +aydc; +aydd; +ayde; +aydf; +aydg; +aydh; +aydi; +aydj; +aydk; +aydl; +aydm; +aydn; +aydo; +aydp; +aydq; +aydr; +ayds; +aydt; +aydu; +aydv; +aydw; +aydx; +aydy; +aydz; +ayea; +ayeb; +ayec; +ayed; +ayee; +ayef; +ayeg; +ayeh; +ayei; +ayej; +ayek; +ayel; +ayem; +ayen; +ayeo; +ayep; +ayeq; +ayer; +ayes; +ayet; +ayeu; +ayev; +ayew; +ayex; +ayey; +ayez; +ayfa; +ayfb; +ayfc; +ayfd; +ayfe; +ayff; +ayfg; +ayfh; +ayfi; +ayfj; +ayfk; +ayfl; +ayfm; +ayfn; +ayfo; +ayfp; +ayfq; +ayfr; +ayfs; +ayft; +ayfu; +ayfv; +ayfw; +ayfx; +ayfy; +ayfz; +ayga; +aygb; +aygc; +aygd; +ayge; +aygf; +aygg; +aygh; +aygi; +aygj; +aygk; +aygl; +aygm; +aygn; +aygo; +aygp; +aygq; +aygr; +aygs; +aygt; +aygu; +aygv; +aygw; +aygx; +aygy; +aygz; +ayha; +ayhb; +ayhc; +ayhd; +ayhe; +ayhf; +ayhg; +ayhh; +ayhi; +ayhj; +ayhk; +ayhl; +ayhm; +ayhn; +ayho; +ayhp; +ayhq; +ayhr; +ayhs; +ayht; +ayhu; +ayhv; +ayhw; +ayhx; +ayhy; +ayhz; +ayia; +ayib; +ayic; +ayid; +ayie; +ayif; +ayig; +ayih; +ayii; +ayij; +ayik; +ayil; +ayim; +ayin; +ayio; +ayip; +ayiq; +ayir; +ayis; +ayit; +ayiu; +ayiv; +ayiw; +ayix; +ayiy; +ayiz; +ayja; +ayjb; +ayjc; +ayjd; +ayje; +ayjf; +ayjg; +ayjh; +ayji; +ayjj; +ayjk; +ayjl; +ayjm; +ayjn; +ayjo; +ayjp; +ayjq; +ayjr; +ayjs; +ayjt; +ayju; +ayjv; +ayjw; +ayjx; +ayjy; +ayjz; +ayka; +aykb; +aykc; +aykd; +ayke; +aykf; +aykg; +aykh; +ayki; +aykj; +aykk; +aykl; +aykm; +aykn; +ayko; +aykp; +aykq; +aykr; +ayks; +aykt; +ayku; +aykv; +aykw; +aykx; +ayky; +aykz; +ayla; +aylb; +aylc; +ayld; +ayle; +aylf; +aylg; +aylh; +ayli; +aylj; +aylk; +ayll; +aylm; +ayln; +aylo; +aylp; +aylq; +aylr; +ayls; +aylt; +aylu; +aylv; +aylw; +aylx; +ayly; +aylz; +ayma; +aymb; +aymc; +aymd; +ayme; +aymf; +aymg; +aymh; +aymi; +aymj; +aymk; +ayml; +aymm; +aymn; +aymo; +aymp; +aymq; +aymr; +ayms; +aymt; +aymu; +aymv; +aymw; +aymx; +aymy; +aymz; +ayna; +aynb; +aync; +aynd; +ayne; +aynf; +ayng; +aynh; +ayni; +aynj; +aynk; +aynl; +aynm; +aynn; +ayno; +aynp; +aynq; +aynr; +ayns; +aynt; +aynu; +aynv; +aynw; +aynx; +ayny; +aynz; +ayoa; +ayob; +ayoc; +ayod; +ayoe; +ayof; +ayog; +ayoh; +ayoi; +ayoj; +ayok; +ayol; +ayom; +ayon; +ayoo; +ayop; +ayoq; +ayor; +ayos; +ayot; +ayou; +ayov; +ayow; +ayox; +ayoy; +ayoz; +aypa; +aypb; +aypc; +aypd; +aype; +aypf; +aypg; +ayph; +aypi; +aypj; +aypk; +aypl; +aypm; +aypn; +aypo; +aypp; +aypq; +aypr; +ayps; +aypt; +aypu; +aypv; +aypw; +aypx; +aypy; +aypz; +ayqa; +ayqb; +ayqc; +ayqd; +ayqe; +ayqf; +ayqg; +ayqh; +ayqi; +ayqj; +ayqk; +ayql; +ayqm; +ayqn; +ayqo; +ayqp; +ayqq; +ayqr; +ayqs; +ayqt; +ayqu; +ayqv; +ayqw; +ayqx; +ayqy; +ayqz; +ayra; +ayrb; +ayrc; +ayrd; +ayre; +ayrf; +ayrg; +ayrh; +ayri; +ayrj; +ayrk; +ayrl; +ayrm; +ayrn; +ayro; +ayrp; +ayrq; +ayrr; +ayrs; +ayrt; +ayru; +ayrv; +ayrw; +ayrx; +ayry; +ayrz; +aysa; +aysb; +aysc; +aysd; +ayse; +aysf; +aysg; +aysh; +aysi; +aysj; +aysk; +aysl; +aysm; +aysn; +ayso; +aysp; +aysq; +aysr; +ayss; +ayst; +aysu; +aysv; +aysw; +aysx; +aysy; +aysz; +ayta; +aytb; +aytc; +aytd; +ayte; +aytf; +aytg; +ayth; +ayti; +aytj; +aytk; +aytl; +aytm; +aytn; +ayto; +aytp; +aytq; +aytr; +ayts; +aytt; +aytu; +aytv; +aytw; +aytx; +ayty; +aytz; +ayua; +ayub; +ayuc; +ayud; +ayue; +ayuf; +ayug; +ayuh; +ayui; +ayuj; +ayuk; +ayul; +ayum; +ayun; +ayuo; +ayup; +ayuq; +ayur; +ayus; +ayut; +ayuu; +ayuv; +ayuw; +ayux; +ayuy; +ayuz; +ayva; +ayvb; +ayvc; +ayvd; +ayve; +ayvf; +ayvg; +ayvh; +ayvi; +ayvj; +ayvk; +ayvl; +ayvm; +ayvn; +ayvo; +ayvp; +ayvq; +ayvr; +ayvs; +ayvt; +ayvu; +ayvv; +ayvw; +ayvx; +ayvy; +ayvz; +aywa; +aywb; +aywc; +aywd; +aywe; +aywf; +aywg; +aywh; +aywi; +aywj; +aywk; +aywl; +aywm; +aywn; +aywo; +aywp; +aywq; +aywr; +ayws; +aywt; +aywu; +aywv; +ayww; +aywx; +aywy; +aywz; +ayxa; +ayxb; +ayxc; +ayxd; +ayxe; +ayxf; +ayxg; +ayxh; +ayxi; +ayxj; +ayxk; +ayxl; +ayxm; +ayxn; +ayxo; +ayxp; +ayxq; +ayxr; +ayxs; +ayxt; +ayxu; +ayxv; +ayxw; +ayxx; +ayxy; +ayxz; +ayya; +ayyb; +ayyc; +ayyd; +ayye; +ayyf; +ayyg; +ayyh; +ayyi; +ayyj; +ayyk; +ayyl; +ayym; +ayyn; +ayyo; +ayyp; +ayyq; +ayyr; +ayys; +ayyt; +ayyu; +ayyv; +ayyw; +ayyx; +ayyy; +ayyz; +ayza; +ayzb; +ayzc; +ayzd; +ayze; +ayzf; +ayzg; +ayzh; +ayzi; +ayzj; +ayzk; +ayzl; +ayzm; +ayzn; +ayzo; +ayzp; +ayzq; +ayzr; +ayzs; +ayzt; +ayzu; +ayzv; +ayzw; +ayzx; +ayzy; +ayzz; +azaa; +azab; +azac; +azad; +azae; +azaf; +azag; +azah; +azai; +azaj; +azak; +azal; +azam; +azan; +azao; +azap; +azaq; +azar; +azas; +azat; +azau; +azav; +azaw; +azax; +azay; +azaz; +azba; +azbb; +azbc; +azbd; +azbe; +azbf; +azbg; +azbh; +azbi; +azbj; +azbk; +azbl; +azbm; +azbn; +azbo; +azbp; +azbq; +azbr; +azbs; +azbt; +azbu; +azbv; +azbw; +azbx; +azby; +azbz; +azca; +azcb; +azcc; +azcd; +azce; +azcf; +azcg; +azch; +azci; +azcj; +azck; +azcl; +azcm; +azcn; +azco; +azcp; +azcq; +azcr; +azcs; +azct; +azcu; +azcv; +azcw; +azcx; +azcy; +azcz; +azda; +azdb; +azdc; +azdd; +azde; +azdf; +azdg; +azdh; +azdi; +azdj; +azdk; +azdl; +azdm; +azdn; +azdo; +azdp; +azdq; +azdr; +azds; +azdt; +azdu; +azdv; +azdw; +azdx; +azdy; +azdz; +azea; +azeb; +azec; +azed; +azee; +azef; +azeg; +azeh; +azei; +azej; +azek; +azel; +azem; +azen; +azeo; +azep; +azeq; +azer; +azes; +azet; +azeu; +azev; +azew; +azex; +azey; +azez; +azfa; +azfb; +azfc; +azfd; +azfe; +azff; +azfg; +azfh; +azfi; +azfj; +azfk; +azfl; +azfm; +azfn; +azfo; +azfp; +azfq; +azfr; +azfs; +azft; +azfu; +azfv; +azfw; +azfx; +azfy; +azfz; +azga; +azgb; +azgc; +azgd; +azge; +azgf; +azgg; +azgh; +azgi; +azgj; +azgk; +azgl; +azgm; +azgn; +azgo; +azgp; +azgq; +azgr; +azgs; +azgt; +azgu; +azgv; +azgw; +azgx; +azgy; +azgz; +azha; +azhb; +azhc; +azhd; +azhe; +azhf; +azhg; +azhh; +azhi; +azhj; +azhk; +azhl; +azhm; +azhn; +azho; +azhp; +azhq; +azhr; +azhs; +azht; +azhu; +azhv; +azhw; +azhx; +azhy; +azhz; +azia; +azib; +azic; +azid; +azie; +azif; +azig; +azih; +azii; +azij; +azik; +azil; +azim; +azin; +azio; +azip; +aziq; +azir; +azis; +azit; +aziu; +aziv; +aziw; +azix; +aziy; +aziz; +azja; +azjb; +azjc; +azjd; +azje; +azjf; +azjg; +azjh; +azji; +azjj; +azjk; +azjl; +azjm; +azjn; +azjo; +azjp; +azjq; +azjr; +azjs; +azjt; +azju; +azjv; +azjw; +azjx; +azjy; +azjz; +azka; +azkb; +azkc; +azkd; +azke; +azkf; +azkg; +azkh; +azki; +azkj; +azkk; +azkl; +azkm; +azkn; +azko; +azkp; +azkq; +azkr; +azks; +azkt; +azku; +azkv; +azkw; +azkx; +azky; +azkz; +azla; +azlb; +azlc; +azld; +azle; +azlf; +azlg; +azlh; +azli; +azlj; +azlk; +azll; +azlm; +azln; +azlo; +azlp; +azlq; +azlr; +azls; +azlt; +azlu; +azlv; +azlw; +azlx; +azly; +azlz; +azma; +azmb; +azmc; +azmd; +azme; +azmf; +azmg; +azmh; +azmi; +azmj; +azmk; +azml; +azmm; +azmn; +azmo; +azmp; +azmq; +azmr; +azms; +azmt; +azmu; +azmv; +azmw; +azmx; +azmy; +azmz; +azna; +aznb; +aznc; +aznd; +azne; +aznf; +azng; +aznh; +azni; +aznj; +aznk; +aznl; +aznm; +aznn; +azno; +aznp; +aznq; +aznr; +azns; +aznt; +aznu; +aznv; +aznw; +aznx; +azny; +aznz; +azoa; +azob; +azoc; +azod; +azoe; +azof; +azog; +azoh; +azoi; +azoj; +azok; +azol; +azom; +azon; +azoo; +azop; +azoq; +azor; +azos; +azot; +azou; +azov; +azow; +azox; +azoy; +azoz; +azpa; +azpb; +azpc; +azpd; +azpe; +azpf; +azpg; +azph; +azpi; +azpj; +azpk; +azpl; +azpm; +azpn; +azpo; +azpp; +azpq; +azpr; +azps; +azpt; +azpu; +azpv; +azpw; +azpx; +azpy; +azpz; +azqa; +azqb; +azqc; +azqd; +azqe; +azqf; +azqg; +azqh; +azqi; +azqj; +azqk; +azql; +azqm; +azqn; +azqo; +azqp; +azqq; +azqr; +azqs; +azqt; +azqu; +azqv; +azqw; +azqx; +azqy; +azqz; +azra; +azrb; +azrc; +azrd; +azre; +azrf; +azrg; +azrh; +azri; +azrj; +azrk; +azrl; +azrm; +azrn; +azro; +azrp; +azrq; +azrr; +azrs; +azrt; +azru; +azrv; +azrw; +azrx; +azry; +azrz; +azsa; +azsb; +azsc; +azsd; +azse; +azsf; +azsg; +azsh; +azsi; +azsj; +azsk; +azsl; +azsm; +azsn; +azso; +azsp; +azsq; +azsr; +azss; +azst; +azsu; +azsv; +azsw; +azsx; +azsy; +azsz; +azta; +aztb; +aztc; +aztd; +azte; +aztf; +aztg; +azth; +azti; +aztj; +aztk; +aztl; +aztm; +aztn; +azto; +aztp; +aztq; +aztr; +azts; +aztt; +aztu; +aztv; +aztw; +aztx; +azty; +aztz; +azua; +azub; +azuc; +azud; +azue; +azuf; +azug; +azuh; +azui; +azuj; +azuk; +azul; +azum; +azun; +azuo; +azup; +azuq; +azur; +azus; +azut; +azuu; +azuv; +azuw; +azux; +azuy; +azuz; +azva; +azvb; +azvc; +azvd; +azve; +azvf; +azvg; +azvh; +azvi; +azvj; +azvk; +azvl; +azvm; +azvn; +azvo; +azvp; +azvq; +azvr; +azvs; +azvt; +azvu; +azvv; +azvw; +azvx; +azvy; +azvz; +azwa; +azwb; +azwc; +azwd; +azwe; +azwf; +azwg; +azwh; +azwi; +azwj; +azwk; +azwl; +azwm; +azwn; +azwo; +azwp; +azwq; +azwr; +azws; +azwt; +azwu; +azwv; +azww; +azwx; +azwy; +azwz; +azxa; +azxb; +azxc; +azxd; +azxe; +azxf; +azxg; +azxh; +azxi; +azxj; +azxk; +azxl; +azxm; +azxn; +azxo; +azxp; +azxq; +azxr; +azxs; +azxt; +azxu; +azxv; +azxw; +azxx; +azxy; +azxz; +azya; +azyb; +azyc; +azyd; +azye; +azyf; +azyg; +azyh; +azyi; +azyj; +azyk; +azyl; +azym; +azyn; +azyo; +azyp; +azyq; +azyr; +azys; +azyt; +azyu; +azyv; +azyw; +azyx; +azyy; +azyz; +azza; +azzb; +azzc; +azzd; +azze; +azzf; +azzg; +azzh; +azzi; +azzj; +azzk; +azzl; +azzm; +azzn; +azzo; +azzp; +azzq; +azzr; +azzs; +azzt; +azzu; +azzv; +azzw; +azzx; +azzy; +azzz; +baaa; +baab; +baac; +baad; +baae; +baaf; +baag; +baah; +baai; +baaj; +baak; +baal; +baam; +baan; +baao; +baap; +baaq; +baar; +baas; +baat; +baau; +baav; +baaw; +baax; +baay; +baaz; +baba; +babb; +babc; +babd; +babe; +babf; +babg; +babh; +babi; +babj; +babk; +babl; +babm; +babn; +babo; +babp; +babq; +babr; +babs; +babt; +babu; +babv; +babw; +babx; +baby; +babz; +baca; +bacb; +bacc; +bacd; +bace; +bacf; +bacg; +bach; +baci; +bacj; +back; +bacl; +bacm; +bacn; +baco; +bacp; +bacq; +bacr; +bacs; +bact; +bacu; +bacv; +bacw; +bacx; +bacy; +bacz; +bada; +badb; +badc; +badd; +bade; +badf; +badg; +badh; +badi; +badj; +badk; +badl; +badm; +badn; +bado; +badp; +badq; +badr; +bads; +badt; +badu; +badv; +badw; +badx; +bady; +badz; +baea; +baeb; +baec; +baed; +baee; +baef; +baeg; +baeh; +baei; +baej; +baek; +bael; +baem; +baen; +baeo; +baep; +baeq; +baer; +baes; +baet; +baeu; +baev; +baew; +baex; +baey; +baez; +bafa; +bafb; +bafc; +bafd; +bafe; +baff; +bafg; +bafh; +bafi; +bafj; +bafk; +bafl; +bafm; +bafn; +bafo; +bafp; +bafq; +bafr; +bafs; +baft; +bafu; +bafv; +bafw; +bafx; +bafy; +bafz; +baga; +bagb; +bagc; +bagd; +bage; +bagf; +bagg; +bagh; +bagi; +bagj; +bagk; +bagl; +bagm; +bagn; +bago; +bagp; +bagq; +bagr; +bags; +bagt; +bagu; +bagv; +bagw; +bagx; +bagy; +bagz; +baha; +bahb; +bahc; +bahd; +bahe; +bahf; +bahg; +bahh; +bahi; +bahj; +bahk; +bahl; +bahm; +bahn; +baho; +bahp; +bahq; +bahr; +bahs; +baht; +bahu; +bahv; +bahw; +bahx; +bahy; +bahz; +baia; +baib; +baic; +baid; +baie; +baif; +baig; +baih; +baii; +baij; +baik; +bail; +baim; +bain; +baio; +baip; +baiq; +bair; +bais; +bait; +baiu; +baiv; +baiw; +baix; +baiy; +baiz; +baja; +bajb; +bajc; +bajd; +baje; +bajf; +bajg; +bajh; +baji; +bajj; +bajk; +bajl; +bajm; +bajn; +bajo; +bajp; +bajq; +bajr; +bajs; +bajt; +baju; +bajv; +bajw; +bajx; +bajy; +bajz; +baka; +bakb; +bakc; +bakd; +bake; +bakf; +bakg; +bakh; +baki; +bakj; +bakk; +bakl; +bakm; +bakn; +bako; +bakp; +bakq; +bakr; +baks; +bakt; +baku; +bakv; +bakw; +bakx; +baky; +bakz; +bala; +balb; +balc; +bald; +bale; +balf; +balg; +balh; +bali; +balj; +balk; +ball; +balm; +baln; +balo; +balp; +balq; +balr; +bals; +balt; +balu; +balv; +balw; +balx; +baly; +balz; +bama; +bamb; +bamc; +bamd; +bame; +bamf; +bamg; +bamh; +bami; +bamj; +bamk; +baml; +bamm; +bamn; +bamo; +bamp; +bamq; +bamr; +bams; +bamt; +bamu; +bamv; +bamw; +bamx; +bamy; +bamz; +bana; +banb; +banc; +band; +bane; +banf; +bang; +banh; +bani; +banj; +bank; +banl; +banm; +bann; +bano; +banp; +banq; +banr; +bans; +bant; +banu; +banv; +banw; +banx; +bany; +banz; +baoa; +baob; +baoc; +baod; +baoe; +baof; +baog; +baoh; +baoi; +baoj; +baok; +baol; +baom; +baon; +baoo; +baop; +baoq; +baor; +baos; +baot; +baou; +baov; +baow; +baox; +baoy; +baoz; +bapa; +bapb; +bapc; +bapd; +bape; +bapf; +bapg; +baph; +bapi; +bapj; +bapk; +bapl; +bapm; +bapn; +bapo; +bapp; +bapq; +bapr; +baps; +bapt; +bapu; +bapv; +bapw; +bapx; +bapy; +bapz; +baqa; +baqb; +baqc; +baqd; +baqe; +baqf; +baqg; +baqh; +baqi; +baqj; +baqk; +baql; +baqm; +baqn; +baqo; +baqp; +baqq; +baqr; +baqs; +baqt; +baqu; +baqv; +baqw; +baqx; +baqy; +baqz; +bara; +barb; +barc; +bard; +bare; +barf; +barg; +barh; +bari; +barj; +bark; +barl; +barm; +barn; +baro; +barp; +barq; +barr; +bars; +bart; +baru; +barv; +barw; +barx; +bary; +barz; +basa; +basb; +basc; +basd; +base; +basf; +basg; +bash; +basi; +basj; +bask; +basl; +basm; +basn; +baso; +basp; +basq; +basr; +bass; +bast; +basu; +basv; +basw; +basx; +basy; +basz; +bata; +batb; +batc; +batd; +bate; +batf; +batg; +bath; +bati; +batj; +batk; +batl; +batm; +batn; +bato; +batp; +batq; +batr; +bats; +batt; +batu; +batv; +batw; +batx; +baty; +batz; +baua; +baub; +bauc; +baud; +baue; +bauf; +baug; +bauh; +baui; +bauj; +bauk; +baul; +baum; +baun; +bauo; +baup; +bauq; +baur; +baus; +baut; +bauu; +bauv; +bauw; +baux; +bauy; +bauz; +bava; +bavb; +bavc; +bavd; +bave; +bavf; +bavg; +bavh; +bavi; +bavj; +bavk; +bavl; +bavm; +bavn; +bavo; +bavp; +bavq; +bavr; +bavs; +bavt; +bavu; +bavv; +bavw; +bavx; +bavy; +bavz; +bawa; +bawb; +bawc; +bawd; +bawe; +bawf; +bawg; +bawh; +bawi; +bawj; +bawk; +bawl; +bawm; +bawn; +bawo; +bawp; +bawq; +bawr; +baws; +bawt; +bawu; +bawv; +baww; +bawx; +bawy; +bawz; +baxa; +baxb; +baxc; +baxd; +baxe; +baxf; +baxg; +baxh; +baxi; +baxj; +baxk; +baxl; +baxm; +baxn; +baxo; +baxp; +baxq; +baxr; +baxs; +baxt; +baxu; +baxv; +baxw; +baxx; +baxy; +baxz; +baya; +bayb; +bayc; +bayd; +baye; +bayf; +bayg; +bayh; +bayi; +bayj; +bayk; +bayl; +baym; +bayn; +bayo; +bayp; +bayq; +bayr; +bays; +bayt; +bayu; +bayv; +bayw; +bayx; +bayy; +bayz; +baza; +bazb; +bazc; +bazd; +baze; +bazf; +bazg; +bazh; +bazi; +bazj; +bazk; +bazl; +bazm; +bazn; +bazo; +bazp; +bazq; +bazr; +bazs; +bazt; +bazu; +bazv; +bazw; +bazx; +bazy; +bazz; +bbaa; +bbab; +bbac; +bbad; +bbae; +bbaf; +bbag; +bbah; +bbai; +bbaj; +bbak; +bbal; +bbam; +bban; +bbao; +bbap; +bbaq; +bbar; +bbas; +bbat; +bbau; +bbav; +bbaw; +bbax; +bbay; +bbaz; +bbba; +bbbb +|]; diff --git a/camlp4/test/fixtures/big-tab3.ml b/camlp4/test/fixtures/big-tab3.ml new file mode 100644 index 0000000..a597031 --- /dev/null +++ b/camlp4/test/fixtures/big-tab3.ml @@ -0,0 +1,20001 @@ +[| +aaaaa; +aaaab; +aaaac; +aaaad; +aaaae; +aaaaf; +aaaag; +aaaah; +aaaai; +aaaaj; +aaaak; +aaaal; +aaaam; +aaaan; +aaaao; +aaaap; +aaaaq; +aaaar; +aaaas; +aaaat; +aaaau; +aaaav; +aaaaw; +aaaax; +aaaay; +aaaaz; +aaaba; +aaabb; +aaabc; +aaabd; +aaabe; +aaabf; +aaabg; +aaabh; +aaabi; +aaabj; +aaabk; +aaabl; +aaabm; +aaabn; +aaabo; +aaabp; +aaabq; +aaabr; +aaabs; +aaabt; +aaabu; +aaabv; +aaabw; +aaabx; +aaaby; +aaabz; +aaaca; +aaacb; +aaacc; +aaacd; +aaace; +aaacf; +aaacg; +aaach; +aaaci; +aaacj; +aaack; +aaacl; +aaacm; +aaacn; +aaaco; +aaacp; +aaacq; +aaacr; +aaacs; +aaact; +aaacu; +aaacv; +aaacw; +aaacx; +aaacy; +aaacz; +aaada; +aaadb; +aaadc; +aaadd; +aaade; +aaadf; +aaadg; +aaadh; +aaadi; +aaadj; +aaadk; +aaadl; +aaadm; +aaadn; +aaado; +aaadp; +aaadq; +aaadr; +aaads; +aaadt; +aaadu; +aaadv; +aaadw; +aaadx; +aaady; +aaadz; +aaaea; +aaaeb; +aaaec; +aaaed; +aaaee; +aaaef; +aaaeg; +aaaeh; +aaaei; +aaaej; +aaaek; +aaael; +aaaem; +aaaen; +aaaeo; +aaaep; +aaaeq; +aaaer; +aaaes; +aaaet; +aaaeu; +aaaev; +aaaew; +aaaex; +aaaey; +aaaez; +aaafa; +aaafb; +aaafc; +aaafd; +aaafe; +aaaff; +aaafg; +aaafh; +aaafi; +aaafj; +aaafk; +aaafl; +aaafm; +aaafn; +aaafo; +aaafp; +aaafq; +aaafr; +aaafs; +aaaft; +aaafu; +aaafv; +aaafw; +aaafx; +aaafy; +aaafz; +aaaga; +aaagb; +aaagc; +aaagd; +aaage; +aaagf; +aaagg; +aaagh; +aaagi; +aaagj; +aaagk; +aaagl; +aaagm; +aaagn; +aaago; +aaagp; +aaagq; +aaagr; +aaags; +aaagt; +aaagu; +aaagv; +aaagw; +aaagx; +aaagy; +aaagz; +aaaha; +aaahb; +aaahc; +aaahd; +aaahe; +aaahf; +aaahg; +aaahh; +aaahi; +aaahj; +aaahk; +aaahl; +aaahm; +aaahn; +aaaho; +aaahp; +aaahq; +aaahr; +aaahs; +aaaht; +aaahu; +aaahv; +aaahw; +aaahx; +aaahy; +aaahz; +aaaia; +aaaib; +aaaic; +aaaid; +aaaie; +aaaif; +aaaig; +aaaih; +aaaii; +aaaij; +aaaik; +aaail; +aaaim; +aaain; +aaaio; +aaaip; +aaaiq; +aaair; +aaais; +aaait; +aaaiu; +aaaiv; +aaaiw; +aaaix; +aaaiy; +aaaiz; +aaaja; +aaajb; +aaajc; +aaajd; +aaaje; +aaajf; +aaajg; +aaajh; +aaaji; +aaajj; +aaajk; +aaajl; +aaajm; +aaajn; +aaajo; +aaajp; +aaajq; +aaajr; +aaajs; +aaajt; +aaaju; +aaajv; +aaajw; +aaajx; +aaajy; +aaajz; +aaaka; +aaakb; +aaakc; +aaakd; +aaake; +aaakf; +aaakg; +aaakh; +aaaki; +aaakj; +aaakk; +aaakl; +aaakm; +aaakn; +aaako; +aaakp; +aaakq; +aaakr; +aaaks; +aaakt; +aaaku; +aaakv; +aaakw; +aaakx; +aaaky; +aaakz; +aaala; +aaalb; +aaalc; +aaald; +aaale; +aaalf; +aaalg; +aaalh; +aaali; +aaalj; +aaalk; +aaall; +aaalm; +aaaln; +aaalo; +aaalp; +aaalq; +aaalr; +aaals; +aaalt; +aaalu; +aaalv; +aaalw; +aaalx; +aaaly; +aaalz; +aaama; +aaamb; +aaamc; +aaamd; +aaame; +aaamf; +aaamg; +aaamh; +aaami; +aaamj; +aaamk; +aaaml; +aaamm; +aaamn; +aaamo; +aaamp; +aaamq; +aaamr; +aaams; +aaamt; +aaamu; +aaamv; +aaamw; +aaamx; +aaamy; +aaamz; +aaana; +aaanb; +aaanc; +aaand; +aaane; +aaanf; +aaang; +aaanh; +aaani; +aaanj; +aaank; +aaanl; +aaanm; +aaann; +aaano; +aaanp; +aaanq; +aaanr; +aaans; +aaant; +aaanu; +aaanv; +aaanw; +aaanx; +aaany; +aaanz; +aaaoa; +aaaob; +aaaoc; +aaaod; +aaaoe; +aaaof; +aaaog; +aaaoh; +aaaoi; +aaaoj; +aaaok; +aaaol; +aaaom; +aaaon; +aaaoo; +aaaop; +aaaoq; +aaaor; +aaaos; +aaaot; +aaaou; +aaaov; +aaaow; +aaaox; +aaaoy; +aaaoz; +aaapa; +aaapb; +aaapc; +aaapd; +aaape; +aaapf; +aaapg; +aaaph; +aaapi; +aaapj; +aaapk; +aaapl; +aaapm; +aaapn; +aaapo; +aaapp; +aaapq; +aaapr; +aaaps; +aaapt; +aaapu; +aaapv; +aaapw; +aaapx; +aaapy; +aaapz; +aaaqa; +aaaqb; +aaaqc; +aaaqd; +aaaqe; +aaaqf; +aaaqg; +aaaqh; +aaaqi; +aaaqj; +aaaqk; +aaaql; +aaaqm; +aaaqn; +aaaqo; +aaaqp; +aaaqq; +aaaqr; +aaaqs; +aaaqt; +aaaqu; +aaaqv; +aaaqw; +aaaqx; +aaaqy; +aaaqz; +aaara; +aaarb; +aaarc; +aaard; +aaare; +aaarf; +aaarg; +aaarh; +aaari; +aaarj; +aaark; +aaarl; +aaarm; +aaarn; +aaaro; +aaarp; +aaarq; +aaarr; +aaars; +aaart; +aaaru; +aaarv; +aaarw; +aaarx; +aaary; +aaarz; +aaasa; +aaasb; +aaasc; +aaasd; +aaase; +aaasf; +aaasg; +aaash; +aaasi; +aaasj; +aaask; +aaasl; +aaasm; +aaasn; +aaaso; +aaasp; +aaasq; +aaasr; +aaass; +aaast; +aaasu; +aaasv; +aaasw; +aaasx; +aaasy; +aaasz; +aaata; +aaatb; +aaatc; +aaatd; +aaate; +aaatf; +aaatg; +aaath; +aaati; +aaatj; +aaatk; +aaatl; +aaatm; +aaatn; +aaato; +aaatp; +aaatq; +aaatr; +aaats; +aaatt; +aaatu; +aaatv; +aaatw; +aaatx; +aaaty; +aaatz; +aaaua; +aaaub; +aaauc; +aaaud; +aaaue; +aaauf; +aaaug; +aaauh; +aaaui; +aaauj; +aaauk; +aaaul; +aaaum; +aaaun; +aaauo; +aaaup; +aaauq; +aaaur; +aaaus; +aaaut; +aaauu; +aaauv; +aaauw; +aaaux; +aaauy; +aaauz; +aaava; +aaavb; +aaavc; +aaavd; +aaave; +aaavf; +aaavg; +aaavh; +aaavi; +aaavj; +aaavk; +aaavl; +aaavm; +aaavn; +aaavo; +aaavp; +aaavq; +aaavr; +aaavs; +aaavt; +aaavu; +aaavv; +aaavw; +aaavx; +aaavy; +aaavz; +aaawa; +aaawb; +aaawc; +aaawd; +aaawe; +aaawf; +aaawg; +aaawh; +aaawi; +aaawj; +aaawk; +aaawl; +aaawm; +aaawn; +aaawo; +aaawp; +aaawq; +aaawr; +aaaws; +aaawt; +aaawu; +aaawv; +aaaww; +aaawx; +aaawy; +aaawz; +aaaxa; +aaaxb; +aaaxc; +aaaxd; +aaaxe; +aaaxf; +aaaxg; +aaaxh; +aaaxi; +aaaxj; +aaaxk; +aaaxl; +aaaxm; +aaaxn; +aaaxo; +aaaxp; +aaaxq; +aaaxr; +aaaxs; +aaaxt; +aaaxu; +aaaxv; +aaaxw; +aaaxx; +aaaxy; +aaaxz; +aaaya; +aaayb; +aaayc; +aaayd; +aaaye; +aaayf; +aaayg; +aaayh; +aaayi; +aaayj; +aaayk; +aaayl; +aaaym; +aaayn; +aaayo; +aaayp; +aaayq; +aaayr; +aaays; +aaayt; +aaayu; +aaayv; +aaayw; +aaayx; +aaayy; +aaayz; +aaaza; +aaazb; +aaazc; +aaazd; +aaaze; +aaazf; +aaazg; +aaazh; +aaazi; +aaazj; +aaazk; +aaazl; +aaazm; +aaazn; +aaazo; +aaazp; +aaazq; +aaazr; +aaazs; +aaazt; +aaazu; +aaazv; +aaazw; +aaazx; +aaazy; +aaazz; +aabaa; +aabab; +aabac; +aabad; +aabae; +aabaf; +aabag; +aabah; +aabai; +aabaj; +aabak; +aabal; +aabam; +aaban; +aabao; +aabap; +aabaq; +aabar; +aabas; +aabat; +aabau; +aabav; +aabaw; +aabax; +aabay; +aabaz; +aabba; +aabbb; +aabbc; +aabbd; +aabbe; +aabbf; +aabbg; +aabbh; +aabbi; +aabbj; +aabbk; +aabbl; +aabbm; +aabbn; +aabbo; +aabbp; +aabbq; +aabbr; +aabbs; +aabbt; +aabbu; +aabbv; +aabbw; +aabbx; +aabby; +aabbz; +aabca; +aabcb; +aabcc; +aabcd; +aabce; +aabcf; +aabcg; +aabch; +aabci; +aabcj; +aabck; +aabcl; +aabcm; +aabcn; +aabco; +aabcp; +aabcq; +aabcr; +aabcs; +aabct; +aabcu; +aabcv; +aabcw; +aabcx; +aabcy; +aabcz; +aabda; +aabdb; +aabdc; +aabdd; +aabde; +aabdf; +aabdg; +aabdh; +aabdi; +aabdj; +aabdk; +aabdl; +aabdm; +aabdn; +aabdo; +aabdp; +aabdq; +aabdr; +aabds; +aabdt; +aabdu; +aabdv; +aabdw; +aabdx; +aabdy; +aabdz; +aabea; +aabeb; +aabec; +aabed; +aabee; +aabef; +aabeg; +aabeh; +aabei; +aabej; +aabek; +aabel; +aabem; +aaben; +aabeo; +aabep; +aabeq; +aaber; +aabes; +aabet; +aabeu; +aabev; +aabew; +aabex; +aabey; +aabez; +aabfa; +aabfb; +aabfc; +aabfd; +aabfe; +aabff; +aabfg; +aabfh; +aabfi; +aabfj; +aabfk; +aabfl; +aabfm; +aabfn; +aabfo; +aabfp; +aabfq; +aabfr; +aabfs; +aabft; +aabfu; +aabfv; +aabfw; +aabfx; +aabfy; +aabfz; +aabga; +aabgb; +aabgc; +aabgd; +aabge; +aabgf; +aabgg; +aabgh; +aabgi; +aabgj; +aabgk; +aabgl; +aabgm; +aabgn; +aabgo; +aabgp; +aabgq; +aabgr; +aabgs; +aabgt; +aabgu; +aabgv; +aabgw; +aabgx; +aabgy; +aabgz; +aabha; +aabhb; +aabhc; +aabhd; +aabhe; +aabhf; +aabhg; +aabhh; +aabhi; +aabhj; +aabhk; +aabhl; +aabhm; +aabhn; +aabho; +aabhp; +aabhq; +aabhr; +aabhs; +aabht; +aabhu; +aabhv; +aabhw; +aabhx; +aabhy; +aabhz; +aabia; +aabib; +aabic; +aabid; +aabie; +aabif; +aabig; +aabih; +aabii; +aabij; +aabik; +aabil; +aabim; +aabin; +aabio; +aabip; +aabiq; +aabir; +aabis; +aabit; +aabiu; +aabiv; +aabiw; +aabix; +aabiy; +aabiz; +aabja; +aabjb; +aabjc; +aabjd; +aabje; +aabjf; +aabjg; +aabjh; +aabji; +aabjj; +aabjk; +aabjl; +aabjm; +aabjn; +aabjo; +aabjp; +aabjq; +aabjr; +aabjs; +aabjt; +aabju; +aabjv; +aabjw; +aabjx; +aabjy; +aabjz; +aabka; +aabkb; +aabkc; +aabkd; +aabke; +aabkf; +aabkg; +aabkh; +aabki; +aabkj; +aabkk; +aabkl; +aabkm; +aabkn; +aabko; +aabkp; +aabkq; +aabkr; +aabks; +aabkt; +aabku; +aabkv; +aabkw; +aabkx; +aabky; +aabkz; +aabla; +aablb; +aablc; +aabld; +aable; +aablf; +aablg; +aablh; +aabli; +aablj; +aablk; +aabll; +aablm; +aabln; +aablo; +aablp; +aablq; +aablr; +aabls; +aablt; +aablu; +aablv; +aablw; +aablx; +aably; +aablz; +aabma; +aabmb; +aabmc; +aabmd; +aabme; +aabmf; +aabmg; +aabmh; +aabmi; +aabmj; +aabmk; +aabml; +aabmm; +aabmn; +aabmo; +aabmp; +aabmq; +aabmr; +aabms; +aabmt; +aabmu; +aabmv; +aabmw; +aabmx; +aabmy; +aabmz; +aabna; +aabnb; +aabnc; +aabnd; +aabne; +aabnf; +aabng; +aabnh; +aabni; +aabnj; +aabnk; +aabnl; +aabnm; +aabnn; +aabno; +aabnp; +aabnq; +aabnr; +aabns; +aabnt; +aabnu; +aabnv; +aabnw; +aabnx; +aabny; +aabnz; +aaboa; +aabob; +aaboc; +aabod; +aaboe; +aabof; +aabog; +aaboh; +aaboi; +aaboj; +aabok; +aabol; +aabom; +aabon; +aaboo; +aabop; +aaboq; +aabor; +aabos; +aabot; +aabou; +aabov; +aabow; +aabox; +aaboy; +aaboz; +aabpa; +aabpb; +aabpc; +aabpd; +aabpe; +aabpf; +aabpg; +aabph; +aabpi; +aabpj; +aabpk; +aabpl; +aabpm; +aabpn; +aabpo; +aabpp; +aabpq; +aabpr; +aabps; +aabpt; +aabpu; +aabpv; +aabpw; +aabpx; +aabpy; +aabpz; +aabqa; +aabqb; +aabqc; +aabqd; +aabqe; +aabqf; +aabqg; +aabqh; +aabqi; +aabqj; +aabqk; +aabql; +aabqm; +aabqn; +aabqo; +aabqp; +aabqq; +aabqr; +aabqs; +aabqt; +aabqu; +aabqv; +aabqw; +aabqx; +aabqy; +aabqz; +aabra; +aabrb; +aabrc; +aabrd; +aabre; +aabrf; +aabrg; +aabrh; +aabri; +aabrj; +aabrk; +aabrl; +aabrm; +aabrn; +aabro; +aabrp; +aabrq; +aabrr; +aabrs; +aabrt; +aabru; +aabrv; +aabrw; +aabrx; +aabry; +aabrz; +aabsa; +aabsb; +aabsc; +aabsd; +aabse; +aabsf; +aabsg; +aabsh; +aabsi; +aabsj; +aabsk; +aabsl; +aabsm; +aabsn; +aabso; +aabsp; +aabsq; +aabsr; +aabss; +aabst; +aabsu; +aabsv; +aabsw; +aabsx; +aabsy; +aabsz; +aabta; +aabtb; +aabtc; +aabtd; +aabte; +aabtf; +aabtg; +aabth; +aabti; +aabtj; +aabtk; +aabtl; +aabtm; +aabtn; +aabto; +aabtp; +aabtq; +aabtr; +aabts; +aabtt; +aabtu; +aabtv; +aabtw; +aabtx; +aabty; +aabtz; +aabua; +aabub; +aabuc; +aabud; +aabue; +aabuf; +aabug; +aabuh; +aabui; +aabuj; +aabuk; +aabul; +aabum; +aabun; +aabuo; +aabup; +aabuq; +aabur; +aabus; +aabut; +aabuu; +aabuv; +aabuw; +aabux; +aabuy; +aabuz; +aabva; +aabvb; +aabvc; +aabvd; +aabve; +aabvf; +aabvg; +aabvh; +aabvi; +aabvj; +aabvk; +aabvl; +aabvm; +aabvn; +aabvo; +aabvp; +aabvq; +aabvr; +aabvs; +aabvt; +aabvu; +aabvv; +aabvw; +aabvx; +aabvy; +aabvz; +aabwa; +aabwb; +aabwc; +aabwd; +aabwe; +aabwf; +aabwg; +aabwh; +aabwi; +aabwj; +aabwk; +aabwl; +aabwm; +aabwn; +aabwo; +aabwp; +aabwq; +aabwr; +aabws; +aabwt; +aabwu; +aabwv; +aabww; +aabwx; +aabwy; +aabwz; +aabxa; +aabxb; +aabxc; +aabxd; +aabxe; +aabxf; +aabxg; +aabxh; +aabxi; +aabxj; +aabxk; +aabxl; +aabxm; +aabxn; +aabxo; +aabxp; +aabxq; +aabxr; +aabxs; +aabxt; +aabxu; +aabxv; +aabxw; +aabxx; +aabxy; +aabxz; +aabya; +aabyb; +aabyc; +aabyd; +aabye; +aabyf; +aabyg; +aabyh; +aabyi; +aabyj; +aabyk; +aabyl; +aabym; +aabyn; +aabyo; +aabyp; +aabyq; +aabyr; +aabys; +aabyt; +aabyu; +aabyv; +aabyw; +aabyx; +aabyy; +aabyz; +aabza; +aabzb; +aabzc; +aabzd; +aabze; +aabzf; +aabzg; +aabzh; +aabzi; +aabzj; +aabzk; +aabzl; +aabzm; +aabzn; +aabzo; +aabzp; +aabzq; +aabzr; +aabzs; +aabzt; +aabzu; +aabzv; +aabzw; +aabzx; +aabzy; +aabzz; +aacaa; +aacab; +aacac; +aacad; +aacae; +aacaf; +aacag; +aacah; +aacai; +aacaj; +aacak; +aacal; +aacam; +aacan; +aacao; +aacap; +aacaq; +aacar; +aacas; +aacat; +aacau; +aacav; +aacaw; +aacax; +aacay; +aacaz; +aacba; +aacbb; +aacbc; +aacbd; +aacbe; +aacbf; +aacbg; +aacbh; +aacbi; +aacbj; +aacbk; +aacbl; +aacbm; +aacbn; +aacbo; +aacbp; +aacbq; +aacbr; +aacbs; +aacbt; +aacbu; +aacbv; +aacbw; +aacbx; +aacby; +aacbz; +aacca; +aaccb; +aaccc; +aaccd; +aacce; +aaccf; +aaccg; +aacch; +aacci; +aaccj; +aacck; +aaccl; +aaccm; +aaccn; +aacco; +aaccp; +aaccq; +aaccr; +aaccs; +aacct; +aaccu; +aaccv; +aaccw; +aaccx; +aaccy; +aaccz; +aacda; +aacdb; +aacdc; +aacdd; +aacde; +aacdf; +aacdg; +aacdh; +aacdi; +aacdj; +aacdk; +aacdl; +aacdm; +aacdn; +aacdo; +aacdp; +aacdq; +aacdr; +aacds; +aacdt; +aacdu; +aacdv; +aacdw; +aacdx; +aacdy; +aacdz; +aacea; +aaceb; +aacec; +aaced; +aacee; +aacef; +aaceg; +aaceh; +aacei; +aacej; +aacek; +aacel; +aacem; +aacen; +aaceo; +aacep; +aaceq; +aacer; +aaces; +aacet; +aaceu; +aacev; +aacew; +aacex; +aacey; +aacez; +aacfa; +aacfb; +aacfc; +aacfd; +aacfe; +aacff; +aacfg; +aacfh; +aacfi; +aacfj; +aacfk; +aacfl; +aacfm; +aacfn; +aacfo; +aacfp; +aacfq; +aacfr; +aacfs; +aacft; +aacfu; +aacfv; +aacfw; +aacfx; +aacfy; +aacfz; +aacga; +aacgb; +aacgc; +aacgd; +aacge; +aacgf; +aacgg; +aacgh; +aacgi; +aacgj; +aacgk; +aacgl; +aacgm; +aacgn; +aacgo; +aacgp; +aacgq; +aacgr; +aacgs; +aacgt; +aacgu; +aacgv; +aacgw; +aacgx; +aacgy; +aacgz; +aacha; +aachb; +aachc; +aachd; +aache; +aachf; +aachg; +aachh; +aachi; +aachj; +aachk; +aachl; +aachm; +aachn; +aacho; +aachp; +aachq; +aachr; +aachs; +aacht; +aachu; +aachv; +aachw; +aachx; +aachy; +aachz; +aacia; +aacib; +aacic; +aacid; +aacie; +aacif; +aacig; +aacih; +aacii; +aacij; +aacik; +aacil; +aacim; +aacin; +aacio; +aacip; +aaciq; +aacir; +aacis; +aacit; +aaciu; +aaciv; +aaciw; +aacix; +aaciy; +aaciz; +aacja; +aacjb; +aacjc; +aacjd; +aacje; +aacjf; +aacjg; +aacjh; +aacji; +aacjj; +aacjk; +aacjl; +aacjm; +aacjn; +aacjo; +aacjp; +aacjq; +aacjr; +aacjs; +aacjt; +aacju; +aacjv; +aacjw; +aacjx; +aacjy; +aacjz; +aacka; +aackb; +aackc; +aackd; +aacke; +aackf; +aackg; +aackh; +aacki; +aackj; +aackk; +aackl; +aackm; +aackn; +aacko; +aackp; +aackq; +aackr; +aacks; +aackt; +aacku; +aackv; +aackw; +aackx; +aacky; +aackz; +aacla; +aaclb; +aaclc; +aacld; +aacle; +aaclf; +aaclg; +aaclh; +aacli; +aaclj; +aaclk; +aacll; +aaclm; +aacln; +aaclo; +aaclp; +aaclq; +aaclr; +aacls; +aaclt; +aaclu; +aaclv; +aaclw; +aaclx; +aacly; +aaclz; +aacma; +aacmb; +aacmc; +aacmd; +aacme; +aacmf; +aacmg; +aacmh; +aacmi; +aacmj; +aacmk; +aacml; +aacmm; +aacmn; +aacmo; +aacmp; +aacmq; +aacmr; +aacms; +aacmt; +aacmu; +aacmv; +aacmw; +aacmx; +aacmy; +aacmz; +aacna; +aacnb; +aacnc; +aacnd; +aacne; +aacnf; +aacng; +aacnh; +aacni; +aacnj; +aacnk; +aacnl; +aacnm; +aacnn; +aacno; +aacnp; +aacnq; +aacnr; +aacns; +aacnt; +aacnu; +aacnv; +aacnw; +aacnx; +aacny; +aacnz; +aacoa; +aacob; +aacoc; +aacod; +aacoe; +aacof; +aacog; +aacoh; +aacoi; +aacoj; +aacok; +aacol; +aacom; +aacon; +aacoo; +aacop; +aacoq; +aacor; +aacos; +aacot; +aacou; +aacov; +aacow; +aacox; +aacoy; +aacoz; +aacpa; +aacpb; +aacpc; +aacpd; +aacpe; +aacpf; +aacpg; +aacph; +aacpi; +aacpj; +aacpk; +aacpl; +aacpm; +aacpn; +aacpo; +aacpp; +aacpq; +aacpr; +aacps; +aacpt; +aacpu; +aacpv; +aacpw; +aacpx; +aacpy; +aacpz; +aacqa; +aacqb; +aacqc; +aacqd; +aacqe; +aacqf; +aacqg; +aacqh; +aacqi; +aacqj; +aacqk; +aacql; +aacqm; +aacqn; +aacqo; +aacqp; +aacqq; +aacqr; +aacqs; +aacqt; +aacqu; +aacqv; +aacqw; +aacqx; +aacqy; +aacqz; +aacra; +aacrb; +aacrc; +aacrd; +aacre; +aacrf; +aacrg; +aacrh; +aacri; +aacrj; +aacrk; +aacrl; +aacrm; +aacrn; +aacro; +aacrp; +aacrq; +aacrr; +aacrs; +aacrt; +aacru; +aacrv; +aacrw; +aacrx; +aacry; +aacrz; +aacsa; +aacsb; +aacsc; +aacsd; +aacse; +aacsf; +aacsg; +aacsh; +aacsi; +aacsj; +aacsk; +aacsl; +aacsm; +aacsn; +aacso; +aacsp; +aacsq; +aacsr; +aacss; +aacst; +aacsu; +aacsv; +aacsw; +aacsx; +aacsy; +aacsz; +aacta; +aactb; +aactc; +aactd; +aacte; +aactf; +aactg; +aacth; +aacti; +aactj; +aactk; +aactl; +aactm; +aactn; +aacto; +aactp; +aactq; +aactr; +aacts; +aactt; +aactu; +aactv; +aactw; +aactx; +aacty; +aactz; +aacua; +aacub; +aacuc; +aacud; +aacue; +aacuf; +aacug; +aacuh; +aacui; +aacuj; +aacuk; +aacul; +aacum; +aacun; +aacuo; +aacup; +aacuq; +aacur; +aacus; +aacut; +aacuu; +aacuv; +aacuw; +aacux; +aacuy; +aacuz; +aacva; +aacvb; +aacvc; +aacvd; +aacve; +aacvf; +aacvg; +aacvh; +aacvi; +aacvj; +aacvk; +aacvl; +aacvm; +aacvn; +aacvo; +aacvp; +aacvq; +aacvr; +aacvs; +aacvt; +aacvu; +aacvv; +aacvw; +aacvx; +aacvy; +aacvz; +aacwa; +aacwb; +aacwc; +aacwd; +aacwe; +aacwf; +aacwg; +aacwh; +aacwi; +aacwj; +aacwk; +aacwl; +aacwm; +aacwn; +aacwo; +aacwp; +aacwq; +aacwr; +aacws; +aacwt; +aacwu; +aacwv; +aacww; +aacwx; +aacwy; +aacwz; +aacxa; +aacxb; +aacxc; +aacxd; +aacxe; +aacxf; +aacxg; +aacxh; +aacxi; +aacxj; +aacxk; +aacxl; +aacxm; +aacxn; +aacxo; +aacxp; +aacxq; +aacxr; +aacxs; +aacxt; +aacxu; +aacxv; +aacxw; +aacxx; +aacxy; +aacxz; +aacya; +aacyb; +aacyc; +aacyd; +aacye; +aacyf; +aacyg; +aacyh; +aacyi; +aacyj; +aacyk; +aacyl; +aacym; +aacyn; +aacyo; +aacyp; +aacyq; +aacyr; +aacys; +aacyt; +aacyu; +aacyv; +aacyw; +aacyx; +aacyy; +aacyz; +aacza; +aaczb; +aaczc; +aaczd; +aacze; +aaczf; +aaczg; +aaczh; +aaczi; +aaczj; +aaczk; +aaczl; +aaczm; +aaczn; +aaczo; +aaczp; +aaczq; +aaczr; +aaczs; +aaczt; +aaczu; +aaczv; +aaczw; +aaczx; +aaczy; +aaczz; +aadaa; +aadab; +aadac; +aadad; +aadae; +aadaf; +aadag; +aadah; +aadai; +aadaj; +aadak; +aadal; +aadam; +aadan; +aadao; +aadap; +aadaq; +aadar; +aadas; +aadat; +aadau; +aadav; +aadaw; +aadax; +aaday; +aadaz; +aadba; +aadbb; +aadbc; +aadbd; +aadbe; +aadbf; +aadbg; +aadbh; +aadbi; +aadbj; +aadbk; +aadbl; +aadbm; +aadbn; +aadbo; +aadbp; +aadbq; +aadbr; +aadbs; +aadbt; +aadbu; +aadbv; +aadbw; +aadbx; +aadby; +aadbz; +aadca; +aadcb; +aadcc; +aadcd; +aadce; +aadcf; +aadcg; +aadch; +aadci; +aadcj; +aadck; +aadcl; +aadcm; +aadcn; +aadco; +aadcp; +aadcq; +aadcr; +aadcs; +aadct; +aadcu; +aadcv; +aadcw; +aadcx; +aadcy; +aadcz; +aadda; +aaddb; +aaddc; +aaddd; +aadde; +aaddf; +aaddg; +aaddh; +aaddi; +aaddj; +aaddk; +aaddl; +aaddm; +aaddn; +aaddo; +aaddp; +aaddq; +aaddr; +aadds; +aaddt; +aaddu; +aaddv; +aaddw; +aaddx; +aaddy; +aaddz; +aadea; +aadeb; +aadec; +aaded; +aadee; +aadef; +aadeg; +aadeh; +aadei; +aadej; +aadek; +aadel; +aadem; +aaden; +aadeo; +aadep; +aadeq; +aader; +aades; +aadet; +aadeu; +aadev; +aadew; +aadex; +aadey; +aadez; +aadfa; +aadfb; +aadfc; +aadfd; +aadfe; +aadff; +aadfg; +aadfh; +aadfi; +aadfj; +aadfk; +aadfl; +aadfm; +aadfn; +aadfo; +aadfp; +aadfq; +aadfr; +aadfs; +aadft; +aadfu; +aadfv; +aadfw; +aadfx; +aadfy; +aadfz; +aadga; +aadgb; +aadgc; +aadgd; +aadge; +aadgf; +aadgg; +aadgh; +aadgi; +aadgj; +aadgk; +aadgl; +aadgm; +aadgn; +aadgo; +aadgp; +aadgq; +aadgr; +aadgs; +aadgt; +aadgu; +aadgv; +aadgw; +aadgx; +aadgy; +aadgz; +aadha; +aadhb; +aadhc; +aadhd; +aadhe; +aadhf; +aadhg; +aadhh; +aadhi; +aadhj; +aadhk; +aadhl; +aadhm; +aadhn; +aadho; +aadhp; +aadhq; +aadhr; +aadhs; +aadht; +aadhu; +aadhv; +aadhw; +aadhx; +aadhy; +aadhz; +aadia; +aadib; +aadic; +aadid; +aadie; +aadif; +aadig; +aadih; +aadii; +aadij; +aadik; +aadil; +aadim; +aadin; +aadio; +aadip; +aadiq; +aadir; +aadis; +aadit; +aadiu; +aadiv; +aadiw; +aadix; +aadiy; +aadiz; +aadja; +aadjb; +aadjc; +aadjd; +aadje; +aadjf; +aadjg; +aadjh; +aadji; +aadjj; +aadjk; +aadjl; +aadjm; +aadjn; +aadjo; +aadjp; +aadjq; +aadjr; +aadjs; +aadjt; +aadju; +aadjv; +aadjw; +aadjx; +aadjy; +aadjz; +aadka; +aadkb; +aadkc; +aadkd; +aadke; +aadkf; +aadkg; +aadkh; +aadki; +aadkj; +aadkk; +aadkl; +aadkm; +aadkn; +aadko; +aadkp; +aadkq; +aadkr; +aadks; +aadkt; +aadku; +aadkv; +aadkw; +aadkx; +aadky; +aadkz; +aadla; +aadlb; +aadlc; +aadld; +aadle; +aadlf; +aadlg; +aadlh; +aadli; +aadlj; +aadlk; +aadll; +aadlm; +aadln; +aadlo; +aadlp; +aadlq; +aadlr; +aadls; +aadlt; +aadlu; +aadlv; +aadlw; +aadlx; +aadly; +aadlz; +aadma; +aadmb; +aadmc; +aadmd; +aadme; +aadmf; +aadmg; +aadmh; +aadmi; +aadmj; +aadmk; +aadml; +aadmm; +aadmn; +aadmo; +aadmp; +aadmq; +aadmr; +aadms; +aadmt; +aadmu; +aadmv; +aadmw; +aadmx; +aadmy; +aadmz; +aadna; +aadnb; +aadnc; +aadnd; +aadne; +aadnf; +aadng; +aadnh; +aadni; +aadnj; +aadnk; +aadnl; +aadnm; +aadnn; +aadno; +aadnp; +aadnq; +aadnr; +aadns; +aadnt; +aadnu; +aadnv; +aadnw; +aadnx; +aadny; +aadnz; +aadoa; +aadob; +aadoc; +aadod; +aadoe; +aadof; +aadog; +aadoh; +aadoi; +aadoj; +aadok; +aadol; +aadom; +aadon; +aadoo; +aadop; +aadoq; +aador; +aados; +aadot; +aadou; +aadov; +aadow; +aadox; +aadoy; +aadoz; +aadpa; +aadpb; +aadpc; +aadpd; +aadpe; +aadpf; +aadpg; +aadph; +aadpi; +aadpj; +aadpk; +aadpl; +aadpm; +aadpn; +aadpo; +aadpp; +aadpq; +aadpr; +aadps; +aadpt; +aadpu; +aadpv; +aadpw; +aadpx; +aadpy; +aadpz; +aadqa; +aadqb; +aadqc; +aadqd; +aadqe; +aadqf; +aadqg; +aadqh; +aadqi; +aadqj; +aadqk; +aadql; +aadqm; +aadqn; +aadqo; +aadqp; +aadqq; +aadqr; +aadqs; +aadqt; +aadqu; +aadqv; +aadqw; +aadqx; +aadqy; +aadqz; +aadra; +aadrb; +aadrc; +aadrd; +aadre; +aadrf; +aadrg; +aadrh; +aadri; +aadrj; +aadrk; +aadrl; +aadrm; +aadrn; +aadro; +aadrp; +aadrq; +aadrr; +aadrs; +aadrt; +aadru; +aadrv; +aadrw; +aadrx; +aadry; +aadrz; +aadsa; +aadsb; +aadsc; +aadsd; +aadse; +aadsf; +aadsg; +aadsh; +aadsi; +aadsj; +aadsk; +aadsl; +aadsm; +aadsn; +aadso; +aadsp; +aadsq; +aadsr; +aadss; +aadst; +aadsu; +aadsv; +aadsw; +aadsx; +aadsy; +aadsz; +aadta; +aadtb; +aadtc; +aadtd; +aadte; +aadtf; +aadtg; +aadth; +aadti; +aadtj; +aadtk; +aadtl; +aadtm; +aadtn; +aadto; +aadtp; +aadtq; +aadtr; +aadts; +aadtt; +aadtu; +aadtv; +aadtw; +aadtx; +aadty; +aadtz; +aadua; +aadub; +aaduc; +aadud; +aadue; +aaduf; +aadug; +aaduh; +aadui; +aaduj; +aaduk; +aadul; +aadum; +aadun; +aaduo; +aadup; +aaduq; +aadur; +aadus; +aadut; +aaduu; +aaduv; +aaduw; +aadux; +aaduy; +aaduz; +aadva; +aadvb; +aadvc; +aadvd; +aadve; +aadvf; +aadvg; +aadvh; +aadvi; +aadvj; +aadvk; +aadvl; +aadvm; +aadvn; +aadvo; +aadvp; +aadvq; +aadvr; +aadvs; +aadvt; +aadvu; +aadvv; +aadvw; +aadvx; +aadvy; +aadvz; +aadwa; +aadwb; +aadwc; +aadwd; +aadwe; +aadwf; +aadwg; +aadwh; +aadwi; +aadwj; +aadwk; +aadwl; +aadwm; +aadwn; +aadwo; +aadwp; +aadwq; +aadwr; +aadws; +aadwt; +aadwu; +aadwv; +aadww; +aadwx; +aadwy; +aadwz; +aadxa; +aadxb; +aadxc; +aadxd; +aadxe; +aadxf; +aadxg; +aadxh; +aadxi; +aadxj; +aadxk; +aadxl; +aadxm; +aadxn; +aadxo; +aadxp; +aadxq; +aadxr; +aadxs; +aadxt; +aadxu; +aadxv; +aadxw; +aadxx; +aadxy; +aadxz; +aadya; +aadyb; +aadyc; +aadyd; +aadye; +aadyf; +aadyg; +aadyh; +aadyi; +aadyj; +aadyk; +aadyl; +aadym; +aadyn; +aadyo; +aadyp; +aadyq; +aadyr; +aadys; +aadyt; +aadyu; +aadyv; +aadyw; +aadyx; +aadyy; +aadyz; +aadza; +aadzb; +aadzc; +aadzd; +aadze; +aadzf; +aadzg; +aadzh; +aadzi; +aadzj; +aadzk; +aadzl; +aadzm; +aadzn; +aadzo; +aadzp; +aadzq; +aadzr; +aadzs; +aadzt; +aadzu; +aadzv; +aadzw; +aadzx; +aadzy; +aadzz; +aaeaa; +aaeab; +aaeac; +aaead; +aaeae; +aaeaf; +aaeag; +aaeah; +aaeai; +aaeaj; +aaeak; +aaeal; +aaeam; +aaean; +aaeao; +aaeap; +aaeaq; +aaear; +aaeas; +aaeat; +aaeau; +aaeav; +aaeaw; +aaeax; +aaeay; +aaeaz; +aaeba; +aaebb; +aaebc; +aaebd; +aaebe; +aaebf; +aaebg; +aaebh; +aaebi; +aaebj; +aaebk; +aaebl; +aaebm; +aaebn; +aaebo; +aaebp; +aaebq; +aaebr; +aaebs; +aaebt; +aaebu; +aaebv; +aaebw; +aaebx; +aaeby; +aaebz; +aaeca; +aaecb; +aaecc; +aaecd; +aaece; +aaecf; +aaecg; +aaech; +aaeci; +aaecj; +aaeck; +aaecl; +aaecm; +aaecn; +aaeco; +aaecp; +aaecq; +aaecr; +aaecs; +aaect; +aaecu; +aaecv; +aaecw; +aaecx; +aaecy; +aaecz; +aaeda; +aaedb; +aaedc; +aaedd; +aaede; +aaedf; +aaedg; +aaedh; +aaedi; +aaedj; +aaedk; +aaedl; +aaedm; +aaedn; +aaedo; +aaedp; +aaedq; +aaedr; +aaeds; +aaedt; +aaedu; +aaedv; +aaedw; +aaedx; +aaedy; +aaedz; +aaeea; +aaeeb; +aaeec; +aaeed; +aaeee; +aaeef; +aaeeg; +aaeeh; +aaeei; +aaeej; +aaeek; +aaeel; +aaeem; +aaeen; +aaeeo; +aaeep; +aaeeq; +aaeer; +aaees; +aaeet; +aaeeu; +aaeev; +aaeew; +aaeex; +aaeey; +aaeez; +aaefa; +aaefb; +aaefc; +aaefd; +aaefe; +aaeff; +aaefg; +aaefh; +aaefi; +aaefj; +aaefk; +aaefl; +aaefm; +aaefn; +aaefo; +aaefp; +aaefq; +aaefr; +aaefs; +aaeft; +aaefu; +aaefv; +aaefw; +aaefx; +aaefy; +aaefz; +aaega; +aaegb; +aaegc; +aaegd; +aaege; +aaegf; +aaegg; +aaegh; +aaegi; +aaegj; +aaegk; +aaegl; +aaegm; +aaegn; +aaego; +aaegp; +aaegq; +aaegr; +aaegs; +aaegt; +aaegu; +aaegv; +aaegw; +aaegx; +aaegy; +aaegz; +aaeha; +aaehb; +aaehc; +aaehd; +aaehe; +aaehf; +aaehg; +aaehh; +aaehi; +aaehj; +aaehk; +aaehl; +aaehm; +aaehn; +aaeho; +aaehp; +aaehq; +aaehr; +aaehs; +aaeht; +aaehu; +aaehv; +aaehw; +aaehx; +aaehy; +aaehz; +aaeia; +aaeib; +aaeic; +aaeid; +aaeie; +aaeif; +aaeig; +aaeih; +aaeii; +aaeij; +aaeik; +aaeil; +aaeim; +aaein; +aaeio; +aaeip; +aaeiq; +aaeir; +aaeis; +aaeit; +aaeiu; +aaeiv; +aaeiw; +aaeix; +aaeiy; +aaeiz; +aaeja; +aaejb; +aaejc; +aaejd; +aaeje; +aaejf; +aaejg; +aaejh; +aaeji; +aaejj; +aaejk; +aaejl; +aaejm; +aaejn; +aaejo; +aaejp; +aaejq; +aaejr; +aaejs; +aaejt; +aaeju; +aaejv; +aaejw; +aaejx; +aaejy; +aaejz; +aaeka; +aaekb; +aaekc; +aaekd; +aaeke; +aaekf; +aaekg; +aaekh; +aaeki; +aaekj; +aaekk; +aaekl; +aaekm; +aaekn; +aaeko; +aaekp; +aaekq; +aaekr; +aaeks; +aaekt; +aaeku; +aaekv; +aaekw; +aaekx; +aaeky; +aaekz; +aaela; +aaelb; +aaelc; +aaeld; +aaele; +aaelf; +aaelg; +aaelh; +aaeli; +aaelj; +aaelk; +aaell; +aaelm; +aaeln; +aaelo; +aaelp; +aaelq; +aaelr; +aaels; +aaelt; +aaelu; +aaelv; +aaelw; +aaelx; +aaely; +aaelz; +aaema; +aaemb; +aaemc; +aaemd; +aaeme; +aaemf; +aaemg; +aaemh; +aaemi; +aaemj; +aaemk; +aaeml; +aaemm; +aaemn; +aaemo; +aaemp; +aaemq; +aaemr; +aaems; +aaemt; +aaemu; +aaemv; +aaemw; +aaemx; +aaemy; +aaemz; +aaena; +aaenb; +aaenc; +aaend; +aaene; +aaenf; +aaeng; +aaenh; +aaeni; +aaenj; +aaenk; +aaenl; +aaenm; +aaenn; +aaeno; +aaenp; +aaenq; +aaenr; +aaens; +aaent; +aaenu; +aaenv; +aaenw; +aaenx; +aaeny; +aaenz; +aaeoa; +aaeob; +aaeoc; +aaeod; +aaeoe; +aaeof; +aaeog; +aaeoh; +aaeoi; +aaeoj; +aaeok; +aaeol; +aaeom; +aaeon; +aaeoo; +aaeop; +aaeoq; +aaeor; +aaeos; +aaeot; +aaeou; +aaeov; +aaeow; +aaeox; +aaeoy; +aaeoz; +aaepa; +aaepb; +aaepc; +aaepd; +aaepe; +aaepf; +aaepg; +aaeph; +aaepi; +aaepj; +aaepk; +aaepl; +aaepm; +aaepn; +aaepo; +aaepp; +aaepq; +aaepr; +aaeps; +aaept; +aaepu; +aaepv; +aaepw; +aaepx; +aaepy; +aaepz; +aaeqa; +aaeqb; +aaeqc; +aaeqd; +aaeqe; +aaeqf; +aaeqg; +aaeqh; +aaeqi; +aaeqj; +aaeqk; +aaeql; +aaeqm; +aaeqn; +aaeqo; +aaeqp; +aaeqq; +aaeqr; +aaeqs; +aaeqt; +aaequ; +aaeqv; +aaeqw; +aaeqx; +aaeqy; +aaeqz; +aaera; +aaerb; +aaerc; +aaerd; +aaere; +aaerf; +aaerg; +aaerh; +aaeri; +aaerj; +aaerk; +aaerl; +aaerm; +aaern; +aaero; +aaerp; +aaerq; +aaerr; +aaers; +aaert; +aaeru; +aaerv; +aaerw; +aaerx; +aaery; +aaerz; +aaesa; +aaesb; +aaesc; +aaesd; +aaese; +aaesf; +aaesg; +aaesh; +aaesi; +aaesj; +aaesk; +aaesl; +aaesm; +aaesn; +aaeso; +aaesp; +aaesq; +aaesr; +aaess; +aaest; +aaesu; +aaesv; +aaesw; +aaesx; +aaesy; +aaesz; +aaeta; +aaetb; +aaetc; +aaetd; +aaete; +aaetf; +aaetg; +aaeth; +aaeti; +aaetj; +aaetk; +aaetl; +aaetm; +aaetn; +aaeto; +aaetp; +aaetq; +aaetr; +aaets; +aaett; +aaetu; +aaetv; +aaetw; +aaetx; +aaety; +aaetz; +aaeua; +aaeub; +aaeuc; +aaeud; +aaeue; +aaeuf; +aaeug; +aaeuh; +aaeui; +aaeuj; +aaeuk; +aaeul; +aaeum; +aaeun; +aaeuo; +aaeup; +aaeuq; +aaeur; +aaeus; +aaeut; +aaeuu; +aaeuv; +aaeuw; +aaeux; +aaeuy; +aaeuz; +aaeva; +aaevb; +aaevc; +aaevd; +aaeve; +aaevf; +aaevg; +aaevh; +aaevi; +aaevj; +aaevk; +aaevl; +aaevm; +aaevn; +aaevo; +aaevp; +aaevq; +aaevr; +aaevs; +aaevt; +aaevu; +aaevv; +aaevw; +aaevx; +aaevy; +aaevz; +aaewa; +aaewb; +aaewc; +aaewd; +aaewe; +aaewf; +aaewg; +aaewh; +aaewi; +aaewj; +aaewk; +aaewl; +aaewm; +aaewn; +aaewo; +aaewp; +aaewq; +aaewr; +aaews; +aaewt; +aaewu; +aaewv; +aaeww; +aaewx; +aaewy; +aaewz; +aaexa; +aaexb; +aaexc; +aaexd; +aaexe; +aaexf; +aaexg; +aaexh; +aaexi; +aaexj; +aaexk; +aaexl; +aaexm; +aaexn; +aaexo; +aaexp; +aaexq; +aaexr; +aaexs; +aaext; +aaexu; +aaexv; +aaexw; +aaexx; +aaexy; +aaexz; +aaeya; +aaeyb; +aaeyc; +aaeyd; +aaeye; +aaeyf; +aaeyg; +aaeyh; +aaeyi; +aaeyj; +aaeyk; +aaeyl; +aaeym; +aaeyn; +aaeyo; +aaeyp; +aaeyq; +aaeyr; +aaeys; +aaeyt; +aaeyu; +aaeyv; +aaeyw; +aaeyx; +aaeyy; +aaeyz; +aaeza; +aaezb; +aaezc; +aaezd; +aaeze; +aaezf; +aaezg; +aaezh; +aaezi; +aaezj; +aaezk; +aaezl; +aaezm; +aaezn; +aaezo; +aaezp; +aaezq; +aaezr; +aaezs; +aaezt; +aaezu; +aaezv; +aaezw; +aaezx; +aaezy; +aaezz; +aafaa; +aafab; +aafac; +aafad; +aafae; +aafaf; +aafag; +aafah; +aafai; +aafaj; +aafak; +aafal; +aafam; +aafan; +aafao; +aafap; +aafaq; +aafar; +aafas; +aafat; +aafau; +aafav; +aafaw; +aafax; +aafay; +aafaz; +aafba; +aafbb; +aafbc; +aafbd; +aafbe; +aafbf; +aafbg; +aafbh; +aafbi; +aafbj; +aafbk; +aafbl; +aafbm; +aafbn; +aafbo; +aafbp; +aafbq; +aafbr; +aafbs; +aafbt; +aafbu; +aafbv; +aafbw; +aafbx; +aafby; +aafbz; +aafca; +aafcb; +aafcc; +aafcd; +aafce; +aafcf; +aafcg; +aafch; +aafci; +aafcj; +aafck; +aafcl; +aafcm; +aafcn; +aafco; +aafcp; +aafcq; +aafcr; +aafcs; +aafct; +aafcu; +aafcv; +aafcw; +aafcx; +aafcy; +aafcz; +aafda; +aafdb; +aafdc; +aafdd; +aafde; +aafdf; +aafdg; +aafdh; +aafdi; +aafdj; +aafdk; +aafdl; +aafdm; +aafdn; +aafdo; +aafdp; +aafdq; +aafdr; +aafds; +aafdt; +aafdu; +aafdv; +aafdw; +aafdx; +aafdy; +aafdz; +aafea; +aafeb; +aafec; +aafed; +aafee; +aafef; +aafeg; +aafeh; +aafei; +aafej; +aafek; +aafel; +aafem; +aafen; +aafeo; +aafep; +aafeq; +aafer; +aafes; +aafet; +aafeu; +aafev; +aafew; +aafex; +aafey; +aafez; +aaffa; +aaffb; +aaffc; +aaffd; +aaffe; +aafff; +aaffg; +aaffh; +aaffi; +aaffj; +aaffk; +aaffl; +aaffm; +aaffn; +aaffo; +aaffp; +aaffq; +aaffr; +aaffs; +aafft; +aaffu; +aaffv; +aaffw; +aaffx; +aaffy; +aaffz; +aafga; +aafgb; +aafgc; +aafgd; +aafge; +aafgf; +aafgg; +aafgh; +aafgi; +aafgj; +aafgk; +aafgl; +aafgm; +aafgn; +aafgo; +aafgp; +aafgq; +aafgr; +aafgs; +aafgt; +aafgu; +aafgv; +aafgw; +aafgx; +aafgy; +aafgz; +aafha; +aafhb; +aafhc; +aafhd; +aafhe; +aafhf; +aafhg; +aafhh; +aafhi; +aafhj; +aafhk; +aafhl; +aafhm; +aafhn; +aafho; +aafhp; +aafhq; +aafhr; +aafhs; +aafht; +aafhu; +aafhv; +aafhw; +aafhx; +aafhy; +aafhz; +aafia; +aafib; +aafic; +aafid; +aafie; +aafif; +aafig; +aafih; +aafii; +aafij; +aafik; +aafil; +aafim; +aafin; +aafio; +aafip; +aafiq; +aafir; +aafis; +aafit; +aafiu; +aafiv; +aafiw; +aafix; +aafiy; +aafiz; +aafja; +aafjb; +aafjc; +aafjd; +aafje; +aafjf; +aafjg; +aafjh; +aafji; +aafjj; +aafjk; +aafjl; +aafjm; +aafjn; +aafjo; +aafjp; +aafjq; +aafjr; +aafjs; +aafjt; +aafju; +aafjv; +aafjw; +aafjx; +aafjy; +aafjz; +aafka; +aafkb; +aafkc; +aafkd; +aafke; +aafkf; +aafkg; +aafkh; +aafki; +aafkj; +aafkk; +aafkl; +aafkm; +aafkn; +aafko; +aafkp; +aafkq; +aafkr; +aafks; +aafkt; +aafku; +aafkv; +aafkw; +aafkx; +aafky; +aafkz; +aafla; +aaflb; +aaflc; +aafld; +aafle; +aaflf; +aaflg; +aaflh; +aafli; +aaflj; +aaflk; +aafll; +aaflm; +aafln; +aaflo; +aaflp; +aaflq; +aaflr; +aafls; +aaflt; +aaflu; +aaflv; +aaflw; +aaflx; +aafly; +aaflz; +aafma; +aafmb; +aafmc; +aafmd; +aafme; +aafmf; +aafmg; +aafmh; +aafmi; +aafmj; +aafmk; +aafml; +aafmm; +aafmn; +aafmo; +aafmp; +aafmq; +aafmr; +aafms; +aafmt; +aafmu; +aafmv; +aafmw; +aafmx; +aafmy; +aafmz; +aafna; +aafnb; +aafnc; +aafnd; +aafne; +aafnf; +aafng; +aafnh; +aafni; +aafnj; +aafnk; +aafnl; +aafnm; +aafnn; +aafno; +aafnp; +aafnq; +aafnr; +aafns; +aafnt; +aafnu; +aafnv; +aafnw; +aafnx; +aafny; +aafnz; +aafoa; +aafob; +aafoc; +aafod; +aafoe; +aafof; +aafog; +aafoh; +aafoi; +aafoj; +aafok; +aafol; +aafom; +aafon; +aafoo; +aafop; +aafoq; +aafor; +aafos; +aafot; +aafou; +aafov; +aafow; +aafox; +aafoy; +aafoz; +aafpa; +aafpb; +aafpc; +aafpd; +aafpe; +aafpf; +aafpg; +aafph; +aafpi; +aafpj; +aafpk; +aafpl; +aafpm; +aafpn; +aafpo; +aafpp; +aafpq; +aafpr; +aafps; +aafpt; +aafpu; +aafpv; +aafpw; +aafpx; +aafpy; +aafpz; +aafqa; +aafqb; +aafqc; +aafqd; +aafqe; +aafqf; +aafqg; +aafqh; +aafqi; +aafqj; +aafqk; +aafql; +aafqm; +aafqn; +aafqo; +aafqp; +aafqq; +aafqr; +aafqs; +aafqt; +aafqu; +aafqv; +aafqw; +aafqx; +aafqy; +aafqz; +aafra; +aafrb; +aafrc; +aafrd; +aafre; +aafrf; +aafrg; +aafrh; +aafri; +aafrj; +aafrk; +aafrl; +aafrm; +aafrn; +aafro; +aafrp; +aafrq; +aafrr; +aafrs; +aafrt; +aafru; +aafrv; +aafrw; +aafrx; +aafry; +aafrz; +aafsa; +aafsb; +aafsc; +aafsd; +aafse; +aafsf; +aafsg; +aafsh; +aafsi; +aafsj; +aafsk; +aafsl; +aafsm; +aafsn; +aafso; +aafsp; +aafsq; +aafsr; +aafss; +aafst; +aafsu; +aafsv; +aafsw; +aafsx; +aafsy; +aafsz; +aafta; +aaftb; +aaftc; +aaftd; +aafte; +aaftf; +aaftg; +aafth; +aafti; +aaftj; +aaftk; +aaftl; +aaftm; +aaftn; +aafto; +aaftp; +aaftq; +aaftr; +aafts; +aaftt; +aaftu; +aaftv; +aaftw; +aaftx; +aafty; +aaftz; +aafua; +aafub; +aafuc; +aafud; +aafue; +aafuf; +aafug; +aafuh; +aafui; +aafuj; +aafuk; +aaful; +aafum; +aafun; +aafuo; +aafup; +aafuq; +aafur; +aafus; +aafut; +aafuu; +aafuv; +aafuw; +aafux; +aafuy; +aafuz; +aafva; +aafvb; +aafvc; +aafvd; +aafve; +aafvf; +aafvg; +aafvh; +aafvi; +aafvj; +aafvk; +aafvl; +aafvm; +aafvn; +aafvo; +aafvp; +aafvq; +aafvr; +aafvs; +aafvt; +aafvu; +aafvv; +aafvw; +aafvx; +aafvy; +aafvz; +aafwa; +aafwb; +aafwc; +aafwd; +aafwe; +aafwf; +aafwg; +aafwh; +aafwi; +aafwj; +aafwk; +aafwl; +aafwm; +aafwn; +aafwo; +aafwp; +aafwq; +aafwr; +aafws; +aafwt; +aafwu; +aafwv; +aafww; +aafwx; +aafwy; +aafwz; +aafxa; +aafxb; +aafxc; +aafxd; +aafxe; +aafxf; +aafxg; +aafxh; +aafxi; +aafxj; +aafxk; +aafxl; +aafxm; +aafxn; +aafxo; +aafxp; +aafxq; +aafxr; +aafxs; +aafxt; +aafxu; +aafxv; +aafxw; +aafxx; +aafxy; +aafxz; +aafya; +aafyb; +aafyc; +aafyd; +aafye; +aafyf; +aafyg; +aafyh; +aafyi; +aafyj; +aafyk; +aafyl; +aafym; +aafyn; +aafyo; +aafyp; +aafyq; +aafyr; +aafys; +aafyt; +aafyu; +aafyv; +aafyw; +aafyx; +aafyy; +aafyz; +aafza; +aafzb; +aafzc; +aafzd; +aafze; +aafzf; +aafzg; +aafzh; +aafzi; +aafzj; +aafzk; +aafzl; +aafzm; +aafzn; +aafzo; +aafzp; +aafzq; +aafzr; +aafzs; +aafzt; +aafzu; +aafzv; +aafzw; +aafzx; +aafzy; +aafzz; +aagaa; +aagab; +aagac; +aagad; +aagae; +aagaf; +aagag; +aagah; +aagai; +aagaj; +aagak; +aagal; +aagam; +aagan; +aagao; +aagap; +aagaq; +aagar; +aagas; +aagat; +aagau; +aagav; +aagaw; +aagax; +aagay; +aagaz; +aagba; +aagbb; +aagbc; +aagbd; +aagbe; +aagbf; +aagbg; +aagbh; +aagbi; +aagbj; +aagbk; +aagbl; +aagbm; +aagbn; +aagbo; +aagbp; +aagbq; +aagbr; +aagbs; +aagbt; +aagbu; +aagbv; +aagbw; +aagbx; +aagby; +aagbz; +aagca; +aagcb; +aagcc; +aagcd; +aagce; +aagcf; +aagcg; +aagch; +aagci; +aagcj; +aagck; +aagcl; +aagcm; +aagcn; +aagco; +aagcp; +aagcq; +aagcr; +aagcs; +aagct; +aagcu; +aagcv; +aagcw; +aagcx; +aagcy; +aagcz; +aagda; +aagdb; +aagdc; +aagdd; +aagde; +aagdf; +aagdg; +aagdh; +aagdi; +aagdj; +aagdk; +aagdl; +aagdm; +aagdn; +aagdo; +aagdp; +aagdq; +aagdr; +aagds; +aagdt; +aagdu; +aagdv; +aagdw; +aagdx; +aagdy; +aagdz; +aagea; +aageb; +aagec; +aaged; +aagee; +aagef; +aageg; +aageh; +aagei; +aagej; +aagek; +aagel; +aagem; +aagen; +aageo; +aagep; +aageq; +aager; +aages; +aaget; +aageu; +aagev; +aagew; +aagex; +aagey; +aagez; +aagfa; +aagfb; +aagfc; +aagfd; +aagfe; +aagff; +aagfg; +aagfh; +aagfi; +aagfj; +aagfk; +aagfl; +aagfm; +aagfn; +aagfo; +aagfp; +aagfq; +aagfr; +aagfs; +aagft; +aagfu; +aagfv; +aagfw; +aagfx; +aagfy; +aagfz; +aagga; +aaggb; +aaggc; +aaggd; +aagge; +aaggf; +aaggg; +aaggh; +aaggi; +aaggj; +aaggk; +aaggl; +aaggm; +aaggn; +aaggo; +aaggp; +aaggq; +aaggr; +aaggs; +aaggt; +aaggu; +aaggv; +aaggw; +aaggx; +aaggy; +aaggz; +aagha; +aaghb; +aaghc; +aaghd; +aaghe; +aaghf; +aaghg; +aaghh; +aaghi; +aaghj; +aaghk; +aaghl; +aaghm; +aaghn; +aagho; +aaghp; +aaghq; +aaghr; +aaghs; +aaght; +aaghu; +aaghv; +aaghw; +aaghx; +aaghy; +aaghz; +aagia; +aagib; +aagic; +aagid; +aagie; +aagif; +aagig; +aagih; +aagii; +aagij; +aagik; +aagil; +aagim; +aagin; +aagio; +aagip; +aagiq; +aagir; +aagis; +aagit; +aagiu; +aagiv; +aagiw; +aagix; +aagiy; +aagiz; +aagja; +aagjb; +aagjc; +aagjd; +aagje; +aagjf; +aagjg; +aagjh; +aagji; +aagjj; +aagjk; +aagjl; +aagjm; +aagjn; +aagjo; +aagjp; +aagjq; +aagjr; +aagjs; +aagjt; +aagju; +aagjv; +aagjw; +aagjx; +aagjy; +aagjz; +aagka; +aagkb; +aagkc; +aagkd; +aagke; +aagkf; +aagkg; +aagkh; +aagki; +aagkj; +aagkk; +aagkl; +aagkm; +aagkn; +aagko; +aagkp; +aagkq; +aagkr; +aagks; +aagkt; +aagku; +aagkv; +aagkw; +aagkx; +aagky; +aagkz; +aagla; +aaglb; +aaglc; +aagld; +aagle; +aaglf; +aaglg; +aaglh; +aagli; +aaglj; +aaglk; +aagll; +aaglm; +aagln; +aaglo; +aaglp; +aaglq; +aaglr; +aagls; +aaglt; +aaglu; +aaglv; +aaglw; +aaglx; +aagly; +aaglz; +aagma; +aagmb; +aagmc; +aagmd; +aagme; +aagmf; +aagmg; +aagmh; +aagmi; +aagmj; +aagmk; +aagml; +aagmm; +aagmn; +aagmo; +aagmp; +aagmq; +aagmr; +aagms; +aagmt; +aagmu; +aagmv; +aagmw; +aagmx; +aagmy; +aagmz; +aagna; +aagnb; +aagnc; +aagnd; +aagne; +aagnf; +aagng; +aagnh; +aagni; +aagnj; +aagnk; +aagnl; +aagnm; +aagnn; +aagno; +aagnp; +aagnq; +aagnr; +aagns; +aagnt; +aagnu; +aagnv; +aagnw; +aagnx; +aagny; +aagnz; +aagoa; +aagob; +aagoc; +aagod; +aagoe; +aagof; +aagog; +aagoh; +aagoi; +aagoj; +aagok; +aagol; +aagom; +aagon; +aagoo; +aagop; +aagoq; +aagor; +aagos; +aagot; +aagou; +aagov; +aagow; +aagox; +aagoy; +aagoz; +aagpa; +aagpb; +aagpc; +aagpd; +aagpe; +aagpf; +aagpg; +aagph; +aagpi; +aagpj; +aagpk; +aagpl; +aagpm; +aagpn; +aagpo; +aagpp; +aagpq; +aagpr; +aagps; +aagpt; +aagpu; +aagpv; +aagpw; +aagpx; +aagpy; +aagpz; +aagqa; +aagqb; +aagqc; +aagqd; +aagqe; +aagqf; +aagqg; +aagqh; +aagqi; +aagqj; +aagqk; +aagql; +aagqm; +aagqn; +aagqo; +aagqp; +aagqq; +aagqr; +aagqs; +aagqt; +aagqu; +aagqv; +aagqw; +aagqx; +aagqy; +aagqz; +aagra; +aagrb; +aagrc; +aagrd; +aagre; +aagrf; +aagrg; +aagrh; +aagri; +aagrj; +aagrk; +aagrl; +aagrm; +aagrn; +aagro; +aagrp; +aagrq; +aagrr; +aagrs; +aagrt; +aagru; +aagrv; +aagrw; +aagrx; +aagry; +aagrz; +aagsa; +aagsb; +aagsc; +aagsd; +aagse; +aagsf; +aagsg; +aagsh; +aagsi; +aagsj; +aagsk; +aagsl; +aagsm; +aagsn; +aagso; +aagsp; +aagsq; +aagsr; +aagss; +aagst; +aagsu; +aagsv; +aagsw; +aagsx; +aagsy; +aagsz; +aagta; +aagtb; +aagtc; +aagtd; +aagte; +aagtf; +aagtg; +aagth; +aagti; +aagtj; +aagtk; +aagtl; +aagtm; +aagtn; +aagto; +aagtp; +aagtq; +aagtr; +aagts; +aagtt; +aagtu; +aagtv; +aagtw; +aagtx; +aagty; +aagtz; +aagua; +aagub; +aaguc; +aagud; +aague; +aaguf; +aagug; +aaguh; +aagui; +aaguj; +aaguk; +aagul; +aagum; +aagun; +aaguo; +aagup; +aaguq; +aagur; +aagus; +aagut; +aaguu; +aaguv; +aaguw; +aagux; +aaguy; +aaguz; +aagva; +aagvb; +aagvc; +aagvd; +aagve; +aagvf; +aagvg; +aagvh; +aagvi; +aagvj; +aagvk; +aagvl; +aagvm; +aagvn; +aagvo; +aagvp; +aagvq; +aagvr; +aagvs; +aagvt; +aagvu; +aagvv; +aagvw; +aagvx; +aagvy; +aagvz; +aagwa; +aagwb; +aagwc; +aagwd; +aagwe; +aagwf; +aagwg; +aagwh; +aagwi; +aagwj; +aagwk; +aagwl; +aagwm; +aagwn; +aagwo; +aagwp; +aagwq; +aagwr; +aagws; +aagwt; +aagwu; +aagwv; +aagww; +aagwx; +aagwy; +aagwz; +aagxa; +aagxb; +aagxc; +aagxd; +aagxe; +aagxf; +aagxg; +aagxh; +aagxi; +aagxj; +aagxk; +aagxl; +aagxm; +aagxn; +aagxo; +aagxp; +aagxq; +aagxr; +aagxs; +aagxt; +aagxu; +aagxv; +aagxw; +aagxx; +aagxy; +aagxz; +aagya; +aagyb; +aagyc; +aagyd; +aagye; +aagyf; +aagyg; +aagyh; +aagyi; +aagyj; +aagyk; +aagyl; +aagym; +aagyn; +aagyo; +aagyp; +aagyq; +aagyr; +aagys; +aagyt; +aagyu; +aagyv; +aagyw; +aagyx; +aagyy; +aagyz; +aagza; +aagzb; +aagzc; +aagzd; +aagze; +aagzf; +aagzg; +aagzh; +aagzi; +aagzj; +aagzk; +aagzl; +aagzm; +aagzn; +aagzo; +aagzp; +aagzq; +aagzr; +aagzs; +aagzt; +aagzu; +aagzv; +aagzw; +aagzx; +aagzy; +aagzz; +aahaa; +aahab; +aahac; +aahad; +aahae; +aahaf; +aahag; +aahah; +aahai; +aahaj; +aahak; +aahal; +aaham; +aahan; +aahao; +aahap; +aahaq; +aahar; +aahas; +aahat; +aahau; +aahav; +aahaw; +aahax; +aahay; +aahaz; +aahba; +aahbb; +aahbc; +aahbd; +aahbe; +aahbf; +aahbg; +aahbh; +aahbi; +aahbj; +aahbk; +aahbl; +aahbm; +aahbn; +aahbo; +aahbp; +aahbq; +aahbr; +aahbs; +aahbt; +aahbu; +aahbv; +aahbw; +aahbx; +aahby; +aahbz; +aahca; +aahcb; +aahcc; +aahcd; +aahce; +aahcf; +aahcg; +aahch; +aahci; +aahcj; +aahck; +aahcl; +aahcm; +aahcn; +aahco; +aahcp; +aahcq; +aahcr; +aahcs; +aahct; +aahcu; +aahcv; +aahcw; +aahcx; +aahcy; +aahcz; +aahda; +aahdb; +aahdc; +aahdd; +aahde; +aahdf; +aahdg; +aahdh; +aahdi; +aahdj; +aahdk; +aahdl; +aahdm; +aahdn; +aahdo; +aahdp; +aahdq; +aahdr; +aahds; +aahdt; +aahdu; +aahdv; +aahdw; +aahdx; +aahdy; +aahdz; +aahea; +aaheb; +aahec; +aahed; +aahee; +aahef; +aaheg; +aaheh; +aahei; +aahej; +aahek; +aahel; +aahem; +aahen; +aaheo; +aahep; +aaheq; +aaher; +aahes; +aahet; +aaheu; +aahev; +aahew; +aahex; +aahey; +aahez; +aahfa; +aahfb; +aahfc; +aahfd; +aahfe; +aahff; +aahfg; +aahfh; +aahfi; +aahfj; +aahfk; +aahfl; +aahfm; +aahfn; +aahfo; +aahfp; +aahfq; +aahfr; +aahfs; +aahft; +aahfu; +aahfv; +aahfw; +aahfx; +aahfy; +aahfz; +aahga; +aahgb; +aahgc; +aahgd; +aahge; +aahgf; +aahgg; +aahgh; +aahgi; +aahgj; +aahgk; +aahgl; +aahgm; +aahgn; +aahgo; +aahgp; +aahgq; +aahgr; +aahgs; +aahgt; +aahgu; +aahgv; +aahgw; +aahgx; +aahgy; +aahgz; +aahha; +aahhb; +aahhc; +aahhd; +aahhe; +aahhf; +aahhg; +aahhh; +aahhi; +aahhj; +aahhk; +aahhl; +aahhm; +aahhn; +aahho; +aahhp; +aahhq; +aahhr; +aahhs; +aahht; +aahhu; +aahhv; +aahhw; +aahhx; +aahhy; +aahhz; +aahia; +aahib; +aahic; +aahid; +aahie; +aahif; +aahig; +aahih; +aahii; +aahij; +aahik; +aahil; +aahim; +aahin; +aahio; +aahip; +aahiq; +aahir; +aahis; +aahit; +aahiu; +aahiv; +aahiw; +aahix; +aahiy; +aahiz; +aahja; +aahjb; +aahjc; +aahjd; +aahje; +aahjf; +aahjg; +aahjh; +aahji; +aahjj; +aahjk; +aahjl; +aahjm; +aahjn; +aahjo; +aahjp; +aahjq; +aahjr; +aahjs; +aahjt; +aahju; +aahjv; +aahjw; +aahjx; +aahjy; +aahjz; +aahka; +aahkb; +aahkc; +aahkd; +aahke; +aahkf; +aahkg; +aahkh; +aahki; +aahkj; +aahkk; +aahkl; +aahkm; +aahkn; +aahko; +aahkp; +aahkq; +aahkr; +aahks; +aahkt; +aahku; +aahkv; +aahkw; +aahkx; +aahky; +aahkz; +aahla; +aahlb; +aahlc; +aahld; +aahle; +aahlf; +aahlg; +aahlh; +aahli; +aahlj; +aahlk; +aahll; +aahlm; +aahln; +aahlo; +aahlp; +aahlq; +aahlr; +aahls; +aahlt; +aahlu; +aahlv; +aahlw; +aahlx; +aahly; +aahlz; +aahma; +aahmb; +aahmc; +aahmd; +aahme; +aahmf; +aahmg; +aahmh; +aahmi; +aahmj; +aahmk; +aahml; +aahmm; +aahmn; +aahmo; +aahmp; +aahmq; +aahmr; +aahms; +aahmt; +aahmu; +aahmv; +aahmw; +aahmx; +aahmy; +aahmz; +aahna; +aahnb; +aahnc; +aahnd; +aahne; +aahnf; +aahng; +aahnh; +aahni; +aahnj; +aahnk; +aahnl; +aahnm; +aahnn; +aahno; +aahnp; +aahnq; +aahnr; +aahns; +aahnt; +aahnu; +aahnv; +aahnw; +aahnx; +aahny; +aahnz; +aahoa; +aahob; +aahoc; +aahod; +aahoe; +aahof; +aahog; +aahoh; +aahoi; +aahoj; +aahok; +aahol; +aahom; +aahon; +aahoo; +aahop; +aahoq; +aahor; +aahos; +aahot; +aahou; +aahov; +aahow; +aahox; +aahoy; +aahoz; +aahpa; +aahpb; +aahpc; +aahpd; +aahpe; +aahpf; +aahpg; +aahph; +aahpi; +aahpj; +aahpk; +aahpl; +aahpm; +aahpn; +aahpo; +aahpp; +aahpq; +aahpr; +aahps; +aahpt; +aahpu; +aahpv; +aahpw; +aahpx; +aahpy; +aahpz; +aahqa; +aahqb; +aahqc; +aahqd; +aahqe; +aahqf; +aahqg; +aahqh; +aahqi; +aahqj; +aahqk; +aahql; +aahqm; +aahqn; +aahqo; +aahqp; +aahqq; +aahqr; +aahqs; +aahqt; +aahqu; +aahqv; +aahqw; +aahqx; +aahqy; +aahqz; +aahra; +aahrb; +aahrc; +aahrd; +aahre; +aahrf; +aahrg; +aahrh; +aahri; +aahrj; +aahrk; +aahrl; +aahrm; +aahrn; +aahro; +aahrp; +aahrq; +aahrr; +aahrs; +aahrt; +aahru; +aahrv; +aahrw; +aahrx; +aahry; +aahrz; +aahsa; +aahsb; +aahsc; +aahsd; +aahse; +aahsf; +aahsg; +aahsh; +aahsi; +aahsj; +aahsk; +aahsl; +aahsm; +aahsn; +aahso; +aahsp; +aahsq; +aahsr; +aahss; +aahst; +aahsu; +aahsv; +aahsw; +aahsx; +aahsy; +aahsz; +aahta; +aahtb; +aahtc; +aahtd; +aahte; +aahtf; +aahtg; +aahth; +aahti; +aahtj; +aahtk; +aahtl; +aahtm; +aahtn; +aahto; +aahtp; +aahtq; +aahtr; +aahts; +aahtt; +aahtu; +aahtv; +aahtw; +aahtx; +aahty; +aahtz; +aahua; +aahub; +aahuc; +aahud; +aahue; +aahuf; +aahug; +aahuh; +aahui; +aahuj; +aahuk; +aahul; +aahum; +aahun; +aahuo; +aahup; +aahuq; +aahur; +aahus; +aahut; +aahuu; +aahuv; +aahuw; +aahux; +aahuy; +aahuz; +aahva; +aahvb; +aahvc; +aahvd; +aahve; +aahvf; +aahvg; +aahvh; +aahvi; +aahvj; +aahvk; +aahvl; +aahvm; +aahvn; +aahvo; +aahvp; +aahvq; +aahvr; +aahvs; +aahvt; +aahvu; +aahvv; +aahvw; +aahvx; +aahvy; +aahvz; +aahwa; +aahwb; +aahwc; +aahwd; +aahwe; +aahwf; +aahwg; +aahwh; +aahwi; +aahwj; +aahwk; +aahwl; +aahwm; +aahwn; +aahwo; +aahwp; +aahwq; +aahwr; +aahws; +aahwt; +aahwu; +aahwv; +aahww; +aahwx; +aahwy; +aahwz; +aahxa; +aahxb; +aahxc; +aahxd; +aahxe; +aahxf; +aahxg; +aahxh; +aahxi; +aahxj; +aahxk; +aahxl; +aahxm; +aahxn; +aahxo; +aahxp; +aahxq; +aahxr; +aahxs; +aahxt; +aahxu; +aahxv; +aahxw; +aahxx; +aahxy; +aahxz; +aahya; +aahyb; +aahyc; +aahyd; +aahye; +aahyf; +aahyg; +aahyh; +aahyi; +aahyj; +aahyk; +aahyl; +aahym; +aahyn; +aahyo; +aahyp; +aahyq; +aahyr; +aahys; +aahyt; +aahyu; +aahyv; +aahyw; +aahyx; +aahyy; +aahyz; +aahza; +aahzb; +aahzc; +aahzd; +aahze; +aahzf; +aahzg; +aahzh; +aahzi; +aahzj; +aahzk; +aahzl; +aahzm; +aahzn; +aahzo; +aahzp; +aahzq; +aahzr; +aahzs; +aahzt; +aahzu; +aahzv; +aahzw; +aahzx; +aahzy; +aahzz; +aaiaa; +aaiab; +aaiac; +aaiad; +aaiae; +aaiaf; +aaiag; +aaiah; +aaiai; +aaiaj; +aaiak; +aaial; +aaiam; +aaian; +aaiao; +aaiap; +aaiaq; +aaiar; +aaias; +aaiat; +aaiau; +aaiav; +aaiaw; +aaiax; +aaiay; +aaiaz; +aaiba; +aaibb; +aaibc; +aaibd; +aaibe; +aaibf; +aaibg; +aaibh; +aaibi; +aaibj; +aaibk; +aaibl; +aaibm; +aaibn; +aaibo; +aaibp; +aaibq; +aaibr; +aaibs; +aaibt; +aaibu; +aaibv; +aaibw; +aaibx; +aaiby; +aaibz; +aaica; +aaicb; +aaicc; +aaicd; +aaice; +aaicf; +aaicg; +aaich; +aaici; +aaicj; +aaick; +aaicl; +aaicm; +aaicn; +aaico; +aaicp; +aaicq; +aaicr; +aaics; +aaict; +aaicu; +aaicv; +aaicw; +aaicx; +aaicy; +aaicz; +aaida; +aaidb; +aaidc; +aaidd; +aaide; +aaidf; +aaidg; +aaidh; +aaidi; +aaidj; +aaidk; +aaidl; +aaidm; +aaidn; +aaido; +aaidp; +aaidq; +aaidr; +aaids; +aaidt; +aaidu; +aaidv; +aaidw; +aaidx; +aaidy; +aaidz; +aaiea; +aaieb; +aaiec; +aaied; +aaiee; +aaief; +aaieg; +aaieh; +aaiei; +aaiej; +aaiek; +aaiel; +aaiem; +aaien; +aaieo; +aaiep; +aaieq; +aaier; +aaies; +aaiet; +aaieu; +aaiev; +aaiew; +aaiex; +aaiey; +aaiez; +aaifa; +aaifb; +aaifc; +aaifd; +aaife; +aaiff; +aaifg; +aaifh; +aaifi; +aaifj; +aaifk; +aaifl; +aaifm; +aaifn; +aaifo; +aaifp; +aaifq; +aaifr; +aaifs; +aaift; +aaifu; +aaifv; +aaifw; +aaifx; +aaify; +aaifz; +aaiga; +aaigb; +aaigc; +aaigd; +aaige; +aaigf; +aaigg; +aaigh; +aaigi; +aaigj; +aaigk; +aaigl; +aaigm; +aaign; +aaigo; +aaigp; +aaigq; +aaigr; +aaigs; +aaigt; +aaigu; +aaigv; +aaigw; +aaigx; +aaigy; +aaigz; +aaiha; +aaihb; +aaihc; +aaihd; +aaihe; +aaihf; +aaihg; +aaihh; +aaihi; +aaihj; +aaihk; +aaihl; +aaihm; +aaihn; +aaiho; +aaihp; +aaihq; +aaihr; +aaihs; +aaiht; +aaihu; +aaihv; +aaihw; +aaihx; +aaihy; +aaihz; +aaiia; +aaiib; +aaiic; +aaiid; +aaiie; +aaiif; +aaiig; +aaiih; +aaiii; +aaiij; +aaiik; +aaiil; +aaiim; +aaiin; +aaiio; +aaiip; +aaiiq; +aaiir; +aaiis; +aaiit; +aaiiu; +aaiiv; +aaiiw; +aaiix; +aaiiy; +aaiiz; +aaija; +aaijb; +aaijc; +aaijd; +aaije; +aaijf; +aaijg; +aaijh; +aaiji; +aaijj; +aaijk; +aaijl; +aaijm; +aaijn; +aaijo; +aaijp; +aaijq; +aaijr; +aaijs; +aaijt; +aaiju; +aaijv; +aaijw; +aaijx; +aaijy; +aaijz; +aaika; +aaikb; +aaikc; +aaikd; +aaike; +aaikf; +aaikg; +aaikh; +aaiki; +aaikj; +aaikk; +aaikl; +aaikm; +aaikn; +aaiko; +aaikp; +aaikq; +aaikr; +aaiks; +aaikt; +aaiku; +aaikv; +aaikw; +aaikx; +aaiky; +aaikz; +aaila; +aailb; +aailc; +aaild; +aaile; +aailf; +aailg; +aailh; +aaili; +aailj; +aailk; +aaill; +aailm; +aailn; +aailo; +aailp; +aailq; +aailr; +aails; +aailt; +aailu; +aailv; +aailw; +aailx; +aaily; +aailz; +aaima; +aaimb; +aaimc; +aaimd; +aaime; +aaimf; +aaimg; +aaimh; +aaimi; +aaimj; +aaimk; +aaiml; +aaimm; +aaimn; +aaimo; +aaimp; +aaimq; +aaimr; +aaims; +aaimt; +aaimu; +aaimv; +aaimw; +aaimx; +aaimy; +aaimz; +aaina; +aainb; +aainc; +aaind; +aaine; +aainf; +aaing; +aainh; +aaini; +aainj; +aaink; +aainl; +aainm; +aainn; +aaino; +aainp; +aainq; +aainr; +aains; +aaint; +aainu; +aainv; +aainw; +aainx; +aainy; +aainz; +aaioa; +aaiob; +aaioc; +aaiod; +aaioe; +aaiof; +aaiog; +aaioh; +aaioi; +aaioj; +aaiok; +aaiol; +aaiom; +aaion; +aaioo; +aaiop; +aaioq; +aaior; +aaios; +aaiot; +aaiou; +aaiov; +aaiow; +aaiox; +aaioy; +aaioz; +aaipa; +aaipb; +aaipc; +aaipd; +aaipe; +aaipf; +aaipg; +aaiph; +aaipi; +aaipj; +aaipk; +aaipl; +aaipm; +aaipn; +aaipo; +aaipp; +aaipq; +aaipr; +aaips; +aaipt; +aaipu; +aaipv; +aaipw; +aaipx; +aaipy; +aaipz; +aaiqa; +aaiqb; +aaiqc; +aaiqd; +aaiqe; +aaiqf; +aaiqg; +aaiqh; +aaiqi; +aaiqj; +aaiqk; +aaiql; +aaiqm; +aaiqn; +aaiqo; +aaiqp; +aaiqq; +aaiqr; +aaiqs; +aaiqt; +aaiqu; +aaiqv; +aaiqw; +aaiqx; +aaiqy; +aaiqz; +aaira; +aairb; +aairc; +aaird; +aaire; +aairf; +aairg; +aairh; +aairi; +aairj; +aairk; +aairl; +aairm; +aairn; +aairo; +aairp; +aairq; +aairr; +aairs; +aairt; +aairu; +aairv; +aairw; +aairx; +aairy; +aairz; +aaisa; +aaisb; +aaisc; +aaisd; +aaise; +aaisf; +aaisg; +aaish; +aaisi; +aaisj; +aaisk; +aaisl; +aaism; +aaisn; +aaiso; +aaisp; +aaisq; +aaisr; +aaiss; +aaist; +aaisu; +aaisv; +aaisw; +aaisx; +aaisy; +aaisz; +aaita; +aaitb; +aaitc; +aaitd; +aaite; +aaitf; +aaitg; +aaith; +aaiti; +aaitj; +aaitk; +aaitl; +aaitm; +aaitn; +aaito; +aaitp; +aaitq; +aaitr; +aaits; +aaitt; +aaitu; +aaitv; +aaitw; +aaitx; +aaity; +aaitz; +aaiua; +aaiub; +aaiuc; +aaiud; +aaiue; +aaiuf; +aaiug; +aaiuh; +aaiui; +aaiuj; +aaiuk; +aaiul; +aaium; +aaiun; +aaiuo; +aaiup; +aaiuq; +aaiur; +aaius; +aaiut; +aaiuu; +aaiuv; +aaiuw; +aaiux; +aaiuy; +aaiuz; +aaiva; +aaivb; +aaivc; +aaivd; +aaive; +aaivf; +aaivg; +aaivh; +aaivi; +aaivj; +aaivk; +aaivl; +aaivm; +aaivn; +aaivo; +aaivp; +aaivq; +aaivr; +aaivs; +aaivt; +aaivu; +aaivv; +aaivw; +aaivx; +aaivy; +aaivz; +aaiwa; +aaiwb; +aaiwc; +aaiwd; +aaiwe; +aaiwf; +aaiwg; +aaiwh; +aaiwi; +aaiwj; +aaiwk; +aaiwl; +aaiwm; +aaiwn; +aaiwo; +aaiwp; +aaiwq; +aaiwr; +aaiws; +aaiwt; +aaiwu; +aaiwv; +aaiww; +aaiwx; +aaiwy; +aaiwz; +aaixa; +aaixb; +aaixc; +aaixd; +aaixe; +aaixf; +aaixg; +aaixh; +aaixi; +aaixj; +aaixk; +aaixl; +aaixm; +aaixn; +aaixo; +aaixp; +aaixq; +aaixr; +aaixs; +aaixt; +aaixu; +aaixv; +aaixw; +aaixx; +aaixy; +aaixz; +aaiya; +aaiyb; +aaiyc; +aaiyd; +aaiye; +aaiyf; +aaiyg; +aaiyh; +aaiyi; +aaiyj; +aaiyk; +aaiyl; +aaiym; +aaiyn; +aaiyo; +aaiyp; +aaiyq; +aaiyr; +aaiys; +aaiyt; +aaiyu; +aaiyv; +aaiyw; +aaiyx; +aaiyy; +aaiyz; +aaiza; +aaizb; +aaizc; +aaizd; +aaize; +aaizf; +aaizg; +aaizh; +aaizi; +aaizj; +aaizk; +aaizl; +aaizm; +aaizn; +aaizo; +aaizp; +aaizq; +aaizr; +aaizs; +aaizt; +aaizu; +aaizv; +aaizw; +aaizx; +aaizy; +aaizz; +aajaa; +aajab; +aajac; +aajad; +aajae; +aajaf; +aajag; +aajah; +aajai; +aajaj; +aajak; +aajal; +aajam; +aajan; +aajao; +aajap; +aajaq; +aajar; +aajas; +aajat; +aajau; +aajav; +aajaw; +aajax; +aajay; +aajaz; +aajba; +aajbb; +aajbc; +aajbd; +aajbe; +aajbf; +aajbg; +aajbh; +aajbi; +aajbj; +aajbk; +aajbl; +aajbm; +aajbn; +aajbo; +aajbp; +aajbq; +aajbr; +aajbs; +aajbt; +aajbu; +aajbv; +aajbw; +aajbx; +aajby; +aajbz; +aajca; +aajcb; +aajcc; +aajcd; +aajce; +aajcf; +aajcg; +aajch; +aajci; +aajcj; +aajck; +aajcl; +aajcm; +aajcn; +aajco; +aajcp; +aajcq; +aajcr; +aajcs; +aajct; +aajcu; +aajcv; +aajcw; +aajcx; +aajcy; +aajcz; +aajda; +aajdb; +aajdc; +aajdd; +aajde; +aajdf; +aajdg; +aajdh; +aajdi; +aajdj; +aajdk; +aajdl; +aajdm; +aajdn; +aajdo; +aajdp; +aajdq; +aajdr; +aajds; +aajdt; +aajdu; +aajdv; +aajdw; +aajdx; +aajdy; +aajdz; +aajea; +aajeb; +aajec; +aajed; +aajee; +aajef; +aajeg; +aajeh; +aajei; +aajej; +aajek; +aajel; +aajem; +aajen; +aajeo; +aajep; +aajeq; +aajer; +aajes; +aajet; +aajeu; +aajev; +aajew; +aajex; +aajey; +aajez; +aajfa; +aajfb; +aajfc; +aajfd; +aajfe; +aajff; +aajfg; +aajfh; +aajfi; +aajfj; +aajfk; +aajfl; +aajfm; +aajfn; +aajfo; +aajfp; +aajfq; +aajfr; +aajfs; +aajft; +aajfu; +aajfv; +aajfw; +aajfx; +aajfy; +aajfz; +aajga; +aajgb; +aajgc; +aajgd; +aajge; +aajgf; +aajgg; +aajgh; +aajgi; +aajgj; +aajgk; +aajgl; +aajgm; +aajgn; +aajgo; +aajgp; +aajgq; +aajgr; +aajgs; +aajgt; +aajgu; +aajgv; +aajgw; +aajgx; +aajgy; +aajgz; +aajha; +aajhb; +aajhc; +aajhd; +aajhe; +aajhf; +aajhg; +aajhh; +aajhi; +aajhj; +aajhk; +aajhl; +aajhm; +aajhn; +aajho; +aajhp; +aajhq; +aajhr; +aajhs; +aajht; +aajhu; +aajhv; +aajhw; +aajhx; +aajhy; +aajhz; +aajia; +aajib; +aajic; +aajid; +aajie; +aajif; +aajig; +aajih; +aajii; +aajij; +aajik; +aajil; +aajim; +aajin; +aajio; +aajip; +aajiq; +aajir; +aajis; +aajit; +aajiu; +aajiv; +aajiw; +aajix; +aajiy; +aajiz; +aajja; +aajjb; +aajjc; +aajjd; +aajje; +aajjf; +aajjg; +aajjh; +aajji; +aajjj; +aajjk; +aajjl; +aajjm; +aajjn; +aajjo; +aajjp; +aajjq; +aajjr; +aajjs; +aajjt; +aajju; +aajjv; +aajjw; +aajjx; +aajjy; +aajjz; +aajka; +aajkb; +aajkc; +aajkd; +aajke; +aajkf; +aajkg; +aajkh; +aajki; +aajkj; +aajkk; +aajkl; +aajkm; +aajkn; +aajko; +aajkp; +aajkq; +aajkr; +aajks; +aajkt; +aajku; +aajkv; +aajkw; +aajkx; +aajky; +aajkz; +aajla; +aajlb; +aajlc; +aajld; +aajle; +aajlf; +aajlg; +aajlh; +aajli; +aajlj; +aajlk; +aajll; +aajlm; +aajln; +aajlo; +aajlp; +aajlq; +aajlr; +aajls; +aajlt; +aajlu; +aajlv; +aajlw; +aajlx; +aajly; +aajlz; +aajma; +aajmb; +aajmc; +aajmd; +aajme; +aajmf; +aajmg; +aajmh; +aajmi; +aajmj; +aajmk; +aajml; +aajmm; +aajmn; +aajmo; +aajmp; +aajmq; +aajmr; +aajms; +aajmt; +aajmu; +aajmv; +aajmw; +aajmx; +aajmy; +aajmz; +aajna; +aajnb; +aajnc; +aajnd; +aajne; +aajnf; +aajng; +aajnh; +aajni; +aajnj; +aajnk; +aajnl; +aajnm; +aajnn; +aajno; +aajnp; +aajnq; +aajnr; +aajns; +aajnt; +aajnu; +aajnv; +aajnw; +aajnx; +aajny; +aajnz; +aajoa; +aajob; +aajoc; +aajod; +aajoe; +aajof; +aajog; +aajoh; +aajoi; +aajoj; +aajok; +aajol; +aajom; +aajon; +aajoo; +aajop; +aajoq; +aajor; +aajos; +aajot; +aajou; +aajov; +aajow; +aajox; +aajoy; +aajoz; +aajpa; +aajpb; +aajpc; +aajpd; +aajpe; +aajpf; +aajpg; +aajph; +aajpi; +aajpj; +aajpk; +aajpl; +aajpm; +aajpn; +aajpo; +aajpp; +aajpq; +aajpr; +aajps; +aajpt; +aajpu; +aajpv; +aajpw; +aajpx; +aajpy; +aajpz; +aajqa; +aajqb; +aajqc; +aajqd; +aajqe; +aajqf; +aajqg; +aajqh; +aajqi; +aajqj; +aajqk; +aajql; +aajqm; +aajqn; +aajqo; +aajqp; +aajqq; +aajqr; +aajqs; +aajqt; +aajqu; +aajqv; +aajqw; +aajqx; +aajqy; +aajqz; +aajra; +aajrb; +aajrc; +aajrd; +aajre; +aajrf; +aajrg; +aajrh; +aajri; +aajrj; +aajrk; +aajrl; +aajrm; +aajrn; +aajro; +aajrp; +aajrq; +aajrr; +aajrs; +aajrt; +aajru; +aajrv; +aajrw; +aajrx; +aajry; +aajrz; +aajsa; +aajsb; +aajsc; +aajsd; +aajse; +aajsf; +aajsg; +aajsh; +aajsi; +aajsj; +aajsk; +aajsl; +aajsm; +aajsn; +aajso; +aajsp; +aajsq; +aajsr; +aajss; +aajst; +aajsu; +aajsv; +aajsw; +aajsx; +aajsy; +aajsz; +aajta; +aajtb; +aajtc; +aajtd; +aajte; +aajtf; +aajtg; +aajth; +aajti; +aajtj; +aajtk; +aajtl; +aajtm; +aajtn; +aajto; +aajtp; +aajtq; +aajtr; +aajts; +aajtt; +aajtu; +aajtv; +aajtw; +aajtx; +aajty; +aajtz; +aajua; +aajub; +aajuc; +aajud; +aajue; +aajuf; +aajug; +aajuh; +aajui; +aajuj; +aajuk; +aajul; +aajum; +aajun; +aajuo; +aajup; +aajuq; +aajur; +aajus; +aajut; +aajuu; +aajuv; +aajuw; +aajux; +aajuy; +aajuz; +aajva; +aajvb; +aajvc; +aajvd; +aajve; +aajvf; +aajvg; +aajvh; +aajvi; +aajvj; +aajvk; +aajvl; +aajvm; +aajvn; +aajvo; +aajvp; +aajvq; +aajvr; +aajvs; +aajvt; +aajvu; +aajvv; +aajvw; +aajvx; +aajvy; +aajvz; +aajwa; +aajwb; +aajwc; +aajwd; +aajwe; +aajwf; +aajwg; +aajwh; +aajwi; +aajwj; +aajwk; +aajwl; +aajwm; +aajwn; +aajwo; +aajwp; +aajwq; +aajwr; +aajws; +aajwt; +aajwu; +aajwv; +aajww; +aajwx; +aajwy; +aajwz; +aajxa; +aajxb; +aajxc; +aajxd; +aajxe; +aajxf; +aajxg; +aajxh; +aajxi; +aajxj; +aajxk; +aajxl; +aajxm; +aajxn; +aajxo; +aajxp; +aajxq; +aajxr; +aajxs; +aajxt; +aajxu; +aajxv; +aajxw; +aajxx; +aajxy; +aajxz; +aajya; +aajyb; +aajyc; +aajyd; +aajye; +aajyf; +aajyg; +aajyh; +aajyi; +aajyj; +aajyk; +aajyl; +aajym; +aajyn; +aajyo; +aajyp; +aajyq; +aajyr; +aajys; +aajyt; +aajyu; +aajyv; +aajyw; +aajyx; +aajyy; +aajyz; +aajza; +aajzb; +aajzc; +aajzd; +aajze; +aajzf; +aajzg; +aajzh; +aajzi; +aajzj; +aajzk; +aajzl; +aajzm; +aajzn; +aajzo; +aajzp; +aajzq; +aajzr; +aajzs; +aajzt; +aajzu; +aajzv; +aajzw; +aajzx; +aajzy; +aajzz; +aakaa; +aakab; +aakac; +aakad; +aakae; +aakaf; +aakag; +aakah; +aakai; +aakaj; +aakak; +aakal; +aakam; +aakan; +aakao; +aakap; +aakaq; +aakar; +aakas; +aakat; +aakau; +aakav; +aakaw; +aakax; +aakay; +aakaz; +aakba; +aakbb; +aakbc; +aakbd; +aakbe; +aakbf; +aakbg; +aakbh; +aakbi; +aakbj; +aakbk; +aakbl; +aakbm; +aakbn; +aakbo; +aakbp; +aakbq; +aakbr; +aakbs; +aakbt; +aakbu; +aakbv; +aakbw; +aakbx; +aakby; +aakbz; +aakca; +aakcb; +aakcc; +aakcd; +aakce; +aakcf; +aakcg; +aakch; +aakci; +aakcj; +aakck; +aakcl; +aakcm; +aakcn; +aakco; +aakcp; +aakcq; +aakcr; +aakcs; +aakct; +aakcu; +aakcv; +aakcw; +aakcx; +aakcy; +aakcz; +aakda; +aakdb; +aakdc; +aakdd; +aakde; +aakdf; +aakdg; +aakdh; +aakdi; +aakdj; +aakdk; +aakdl; +aakdm; +aakdn; +aakdo; +aakdp; +aakdq; +aakdr; +aakds; +aakdt; +aakdu; +aakdv; +aakdw; +aakdx; +aakdy; +aakdz; +aakea; +aakeb; +aakec; +aaked; +aakee; +aakef; +aakeg; +aakeh; +aakei; +aakej; +aakek; +aakel; +aakem; +aaken; +aakeo; +aakep; +aakeq; +aaker; +aakes; +aaket; +aakeu; +aakev; +aakew; +aakex; +aakey; +aakez; +aakfa; +aakfb; +aakfc; +aakfd; +aakfe; +aakff; +aakfg; +aakfh; +aakfi; +aakfj; +aakfk; +aakfl; +aakfm; +aakfn; +aakfo; +aakfp; +aakfq; +aakfr; +aakfs; +aakft; +aakfu; +aakfv; +aakfw; +aakfx; +aakfy; +aakfz; +aakga; +aakgb; +aakgc; +aakgd; +aakge; +aakgf; +aakgg; +aakgh; +aakgi; +aakgj; +aakgk; +aakgl; +aakgm; +aakgn; +aakgo; +aakgp; +aakgq; +aakgr; +aakgs; +aakgt; +aakgu; +aakgv; +aakgw; +aakgx; +aakgy; +aakgz; +aakha; +aakhb; +aakhc; +aakhd; +aakhe; +aakhf; +aakhg; +aakhh; +aakhi; +aakhj; +aakhk; +aakhl; +aakhm; +aakhn; +aakho; +aakhp; +aakhq; +aakhr; +aakhs; +aakht; +aakhu; +aakhv; +aakhw; +aakhx; +aakhy; +aakhz; +aakia; +aakib; +aakic; +aakid; +aakie; +aakif; +aakig; +aakih; +aakii; +aakij; +aakik; +aakil; +aakim; +aakin; +aakio; +aakip; +aakiq; +aakir; +aakis; +aakit; +aakiu; +aakiv; +aakiw; +aakix; +aakiy; +aakiz; +aakja; +aakjb; +aakjc; +aakjd; +aakje; +aakjf; +aakjg; +aakjh; +aakji; +aakjj; +aakjk; +aakjl; +aakjm; +aakjn; +aakjo; +aakjp; +aakjq; +aakjr; +aakjs; +aakjt; +aakju; +aakjv; +aakjw; +aakjx; +aakjy; +aakjz; +aakka; +aakkb; +aakkc; +aakkd; +aakke; +aakkf; +aakkg; +aakkh; +aakki; +aakkj; +aakkk; +aakkl; +aakkm; +aakkn; +aakko; +aakkp; +aakkq; +aakkr; +aakks; +aakkt; +aakku; +aakkv; +aakkw; +aakkx; +aakky; +aakkz; +aakla; +aaklb; +aaklc; +aakld; +aakle; +aaklf; +aaklg; +aaklh; +aakli; +aaklj; +aaklk; +aakll; +aaklm; +aakln; +aaklo; +aaklp; +aaklq; +aaklr; +aakls; +aaklt; +aaklu; +aaklv; +aaklw; +aaklx; +aakly; +aaklz; +aakma; +aakmb; +aakmc; +aakmd; +aakme; +aakmf; +aakmg; +aakmh; +aakmi; +aakmj; +aakmk; +aakml; +aakmm; +aakmn; +aakmo; +aakmp; +aakmq; +aakmr; +aakms; +aakmt; +aakmu; +aakmv; +aakmw; +aakmx; +aakmy; +aakmz; +aakna; +aaknb; +aaknc; +aaknd; +aakne; +aaknf; +aakng; +aaknh; +aakni; +aaknj; +aaknk; +aaknl; +aaknm; +aaknn; +aakno; +aaknp; +aaknq; +aaknr; +aakns; +aaknt; +aaknu; +aaknv; +aaknw; +aaknx; +aakny; +aaknz; +aakoa; +aakob; +aakoc; +aakod; +aakoe; +aakof; +aakog; +aakoh; +aakoi; +aakoj; +aakok; +aakol; +aakom; +aakon; +aakoo; +aakop; +aakoq; +aakor; +aakos; +aakot; +aakou; +aakov; +aakow; +aakox; +aakoy; +aakoz; +aakpa; +aakpb; +aakpc; +aakpd; +aakpe; +aakpf; +aakpg; +aakph; +aakpi; +aakpj; +aakpk; +aakpl; +aakpm; +aakpn; +aakpo; +aakpp; +aakpq; +aakpr; +aakps; +aakpt; +aakpu; +aakpv; +aakpw; +aakpx; +aakpy; +aakpz; +aakqa; +aakqb; +aakqc; +aakqd; +aakqe; +aakqf; +aakqg; +aakqh; +aakqi; +aakqj; +aakqk; +aakql; +aakqm; +aakqn; +aakqo; +aakqp; +aakqq; +aakqr; +aakqs; +aakqt; +aakqu; +aakqv; +aakqw; +aakqx; +aakqy; +aakqz; +aakra; +aakrb; +aakrc; +aakrd; +aakre; +aakrf; +aakrg; +aakrh; +aakri; +aakrj; +aakrk; +aakrl; +aakrm; +aakrn; +aakro; +aakrp; +aakrq; +aakrr; +aakrs; +aakrt; +aakru; +aakrv; +aakrw; +aakrx; +aakry; +aakrz; +aaksa; +aaksb; +aaksc; +aaksd; +aakse; +aaksf; +aaksg; +aaksh; +aaksi; +aaksj; +aaksk; +aaksl; +aaksm; +aaksn; +aakso; +aaksp; +aaksq; +aaksr; +aakss; +aakst; +aaksu; +aaksv; +aaksw; +aaksx; +aaksy; +aaksz; +aakta; +aaktb; +aaktc; +aaktd; +aakte; +aaktf; +aaktg; +aakth; +aakti; +aaktj; +aaktk; +aaktl; +aaktm; +aaktn; +aakto; +aaktp; +aaktq; +aaktr; +aakts; +aaktt; +aaktu; +aaktv; +aaktw; +aaktx; +aakty; +aaktz; +aakua; +aakub; +aakuc; +aakud; +aakue; +aakuf; +aakug; +aakuh; +aakui; +aakuj; +aakuk; +aakul; +aakum; +aakun; +aakuo; +aakup; +aakuq; +aakur; +aakus; +aakut; +aakuu; +aakuv; +aakuw; +aakux; +aakuy; +aakuz; +aakva; +aakvb; +aakvc; +aakvd; +aakve; +aakvf; +aakvg; +aakvh; +aakvi; +aakvj; +aakvk; +aakvl; +aakvm; +aakvn; +aakvo; +aakvp; +aakvq; +aakvr; +aakvs; +aakvt; +aakvu; +aakvv; +aakvw; +aakvx; +aakvy; +aakvz; +aakwa; +aakwb; +aakwc; +aakwd; +aakwe; +aakwf; +aakwg; +aakwh; +aakwi; +aakwj; +aakwk; +aakwl; +aakwm; +aakwn; +aakwo; +aakwp; +aakwq; +aakwr; +aakws; +aakwt; +aakwu; +aakwv; +aakww; +aakwx; +aakwy; +aakwz; +aakxa; +aakxb; +aakxc; +aakxd; +aakxe; +aakxf; +aakxg; +aakxh; +aakxi; +aakxj; +aakxk; +aakxl; +aakxm; +aakxn; +aakxo; +aakxp; +aakxq; +aakxr; +aakxs; +aakxt; +aakxu; +aakxv; +aakxw; +aakxx; +aakxy; +aakxz; +aakya; +aakyb; +aakyc; +aakyd; +aakye; +aakyf; +aakyg; +aakyh; +aakyi; +aakyj; +aakyk; +aakyl; +aakym; +aakyn; +aakyo; +aakyp; +aakyq; +aakyr; +aakys; +aakyt; +aakyu; +aakyv; +aakyw; +aakyx; +aakyy; +aakyz; +aakza; +aakzb; +aakzc; +aakzd; +aakze; +aakzf; +aakzg; +aakzh; +aakzi; +aakzj; +aakzk; +aakzl; +aakzm; +aakzn; +aakzo; +aakzp; +aakzq; +aakzr; +aakzs; +aakzt; +aakzu; +aakzv; +aakzw; +aakzx; +aakzy; +aakzz; +aalaa; +aalab; +aalac; +aalad; +aalae; +aalaf; +aalag; +aalah; +aalai; +aalaj; +aalak; +aalal; +aalam; +aalan; +aalao; +aalap; +aalaq; +aalar; +aalas; +aalat; +aalau; +aalav; +aalaw; +aalax; +aalay; +aalaz; +aalba; +aalbb; +aalbc; +aalbd; +aalbe; +aalbf; +aalbg; +aalbh; +aalbi; +aalbj; +aalbk; +aalbl; +aalbm; +aalbn; +aalbo; +aalbp; +aalbq; +aalbr; +aalbs; +aalbt; +aalbu; +aalbv; +aalbw; +aalbx; +aalby; +aalbz; +aalca; +aalcb; +aalcc; +aalcd; +aalce; +aalcf; +aalcg; +aalch; +aalci; +aalcj; +aalck; +aalcl; +aalcm; +aalcn; +aalco; +aalcp; +aalcq; +aalcr; +aalcs; +aalct; +aalcu; +aalcv; +aalcw; +aalcx; +aalcy; +aalcz; +aalda; +aaldb; +aaldc; +aaldd; +aalde; +aaldf; +aaldg; +aaldh; +aaldi; +aaldj; +aaldk; +aaldl; +aaldm; +aaldn; +aaldo; +aaldp; +aaldq; +aaldr; +aalds; +aaldt; +aaldu; +aaldv; +aaldw; +aaldx; +aaldy; +aaldz; +aalea; +aaleb; +aalec; +aaled; +aalee; +aalef; +aaleg; +aaleh; +aalei; +aalej; +aalek; +aalel; +aalem; +aalen; +aaleo; +aalep; +aaleq; +aaler; +aales; +aalet; +aaleu; +aalev; +aalew; +aalex; +aaley; +aalez; +aalfa; +aalfb; +aalfc; +aalfd; +aalfe; +aalff; +aalfg; +aalfh; +aalfi; +aalfj; +aalfk; +aalfl; +aalfm; +aalfn; +aalfo; +aalfp; +aalfq; +aalfr; +aalfs; +aalft; +aalfu; +aalfv; +aalfw; +aalfx; +aalfy; +aalfz; +aalga; +aalgb; +aalgc; +aalgd; +aalge; +aalgf; +aalgg; +aalgh; +aalgi; +aalgj; +aalgk; +aalgl; +aalgm; +aalgn; +aalgo; +aalgp; +aalgq; +aalgr; +aalgs; +aalgt; +aalgu; +aalgv; +aalgw; +aalgx; +aalgy; +aalgz; +aalha; +aalhb; +aalhc; +aalhd; +aalhe; +aalhf; +aalhg; +aalhh; +aalhi; +aalhj; +aalhk; +aalhl; +aalhm; +aalhn; +aalho; +aalhp; +aalhq; +aalhr; +aalhs; +aalht; +aalhu; +aalhv; +aalhw; +aalhx; +aalhy; +aalhz; +aalia; +aalib; +aalic; +aalid; +aalie; +aalif; +aalig; +aalih; +aalii; +aalij; +aalik; +aalil; +aalim; +aalin; +aalio; +aalip; +aaliq; +aalir; +aalis; +aalit; +aaliu; +aaliv; +aaliw; +aalix; +aaliy; +aaliz; +aalja; +aaljb; +aaljc; +aaljd; +aalje; +aaljf; +aaljg; +aaljh; +aalji; +aaljj; +aaljk; +aaljl; +aaljm; +aaljn; +aaljo; +aaljp; +aaljq; +aaljr; +aaljs; +aaljt; +aalju; +aaljv; +aaljw; +aaljx; +aaljy; +aaljz; +aalka; +aalkb; +aalkc; +aalkd; +aalke; +aalkf; +aalkg; +aalkh; +aalki; +aalkj; +aalkk; +aalkl; +aalkm; +aalkn; +aalko; +aalkp; +aalkq; +aalkr; +aalks; +aalkt; +aalku; +aalkv; +aalkw; +aalkx; +aalky; +aalkz; +aalla; +aallb; +aallc; +aalld; +aalle; +aallf; +aallg; +aallh; +aalli; +aallj; +aallk; +aalll; +aallm; +aalln; +aallo; +aallp; +aallq; +aallr; +aalls; +aallt; +aallu; +aallv; +aallw; +aallx; +aally; +aallz; +aalma; +aalmb; +aalmc; +aalmd; +aalme; +aalmf; +aalmg; +aalmh; +aalmi; +aalmj; +aalmk; +aalml; +aalmm; +aalmn; +aalmo; +aalmp; +aalmq; +aalmr; +aalms; +aalmt; +aalmu; +aalmv; +aalmw; +aalmx; +aalmy; +aalmz; +aalna; +aalnb; +aalnc; +aalnd; +aalne; +aalnf; +aalng; +aalnh; +aalni; +aalnj; +aalnk; +aalnl; +aalnm; +aalnn; +aalno; +aalnp; +aalnq; +aalnr; +aalns; +aalnt; +aalnu; +aalnv; +aalnw; +aalnx; +aalny; +aalnz; +aaloa; +aalob; +aaloc; +aalod; +aaloe; +aalof; +aalog; +aaloh; +aaloi; +aaloj; +aalok; +aalol; +aalom; +aalon; +aaloo; +aalop; +aaloq; +aalor; +aalos; +aalot; +aalou; +aalov; +aalow; +aalox; +aaloy; +aaloz; +aalpa; +aalpb; +aalpc; +aalpd; +aalpe; +aalpf; +aalpg; +aalph; +aalpi; +aalpj; +aalpk; +aalpl; +aalpm; +aalpn; +aalpo; +aalpp; +aalpq; +aalpr; +aalps; +aalpt; +aalpu; +aalpv; +aalpw; +aalpx; +aalpy; +aalpz; +aalqa; +aalqb; +aalqc; +aalqd; +aalqe; +aalqf; +aalqg; +aalqh; +aalqi; +aalqj; +aalqk; +aalql; +aalqm; +aalqn; +aalqo; +aalqp; +aalqq; +aalqr; +aalqs; +aalqt; +aalqu; +aalqv; +aalqw; +aalqx; +aalqy; +aalqz; +aalra; +aalrb; +aalrc; +aalrd; +aalre; +aalrf; +aalrg; +aalrh; +aalri; +aalrj; +aalrk; +aalrl; +aalrm; +aalrn; +aalro; +aalrp; +aalrq; +aalrr; +aalrs; +aalrt; +aalru; +aalrv; +aalrw; +aalrx; +aalry; +aalrz; +aalsa; +aalsb; +aalsc; +aalsd; +aalse; +aalsf; +aalsg; +aalsh; +aalsi; +aalsj; +aalsk; +aalsl; +aalsm; +aalsn; +aalso; +aalsp; +aalsq; +aalsr; +aalss; +aalst; +aalsu; +aalsv; +aalsw; +aalsx; +aalsy; +aalsz; +aalta; +aaltb; +aaltc; +aaltd; +aalte; +aaltf; +aaltg; +aalth; +aalti; +aaltj; +aaltk; +aaltl; +aaltm; +aaltn; +aalto; +aaltp; +aaltq; +aaltr; +aalts; +aaltt; +aaltu; +aaltv; +aaltw; +aaltx; +aalty; +aaltz; +aalua; +aalub; +aaluc; +aalud; +aalue; +aaluf; +aalug; +aaluh; +aalui; +aaluj; +aaluk; +aalul; +aalum; +aalun; +aaluo; +aalup; +aaluq; +aalur; +aalus; +aalut; +aaluu; +aaluv; +aaluw; +aalux; +aaluy; +aaluz; +aalva; +aalvb; +aalvc; +aalvd; +aalve; +aalvf; +aalvg; +aalvh; +aalvi; +aalvj; +aalvk; +aalvl; +aalvm; +aalvn; +aalvo; +aalvp; +aalvq; +aalvr; +aalvs; +aalvt; +aalvu; +aalvv; +aalvw; +aalvx; +aalvy; +aalvz; +aalwa; +aalwb; +aalwc; +aalwd; +aalwe; +aalwf; +aalwg; +aalwh; +aalwi; +aalwj; +aalwk; +aalwl; +aalwm; +aalwn; +aalwo; +aalwp; +aalwq; +aalwr; +aalws; +aalwt; +aalwu; +aalwv; +aalww; +aalwx; +aalwy; +aalwz; +aalxa; +aalxb; +aalxc; +aalxd; +aalxe; +aalxf; +aalxg; +aalxh; +aalxi; +aalxj; +aalxk; +aalxl; +aalxm; +aalxn; +aalxo; +aalxp; +aalxq; +aalxr; +aalxs; +aalxt; +aalxu; +aalxv; +aalxw; +aalxx; +aalxy; +aalxz; +aalya; +aalyb; +aalyc; +aalyd; +aalye; +aalyf; +aalyg; +aalyh; +aalyi; +aalyj; +aalyk; +aalyl; +aalym; +aalyn; +aalyo; +aalyp; +aalyq; +aalyr; +aalys; +aalyt; +aalyu; +aalyv; +aalyw; +aalyx; +aalyy; +aalyz; +aalza; +aalzb; +aalzc; +aalzd; +aalze; +aalzf; +aalzg; +aalzh; +aalzi; +aalzj; +aalzk; +aalzl; +aalzm; +aalzn; +aalzo; +aalzp; +aalzq; +aalzr; +aalzs; +aalzt; +aalzu; +aalzv; +aalzw; +aalzx; +aalzy; +aalzz; +aamaa; +aamab; +aamac; +aamad; +aamae; +aamaf; +aamag; +aamah; +aamai; +aamaj; +aamak; +aamal; +aamam; +aaman; +aamao; +aamap; +aamaq; +aamar; +aamas; +aamat; +aamau; +aamav; +aamaw; +aamax; +aamay; +aamaz; +aamba; +aambb; +aambc; +aambd; +aambe; +aambf; +aambg; +aambh; +aambi; +aambj; +aambk; +aambl; +aambm; +aambn; +aambo; +aambp; +aambq; +aambr; +aambs; +aambt; +aambu; +aambv; +aambw; +aambx; +aamby; +aambz; +aamca; +aamcb; +aamcc; +aamcd; +aamce; +aamcf; +aamcg; +aamch; +aamci; +aamcj; +aamck; +aamcl; +aamcm; +aamcn; +aamco; +aamcp; +aamcq; +aamcr; +aamcs; +aamct; +aamcu; +aamcv; +aamcw; +aamcx; +aamcy; +aamcz; +aamda; +aamdb; +aamdc; +aamdd; +aamde; +aamdf; +aamdg; +aamdh; +aamdi; +aamdj; +aamdk; +aamdl; +aamdm; +aamdn; +aamdo; +aamdp; +aamdq; +aamdr; +aamds; +aamdt; +aamdu; +aamdv; +aamdw; +aamdx; +aamdy; +aamdz; +aamea; +aameb; +aamec; +aamed; +aamee; +aamef; +aameg; +aameh; +aamei; +aamej; +aamek; +aamel; +aamem; +aamen; +aameo; +aamep; +aameq; +aamer; +aames; +aamet; +aameu; +aamev; +aamew; +aamex; +aamey; +aamez; +aamfa; +aamfb; +aamfc; +aamfd; +aamfe; +aamff; +aamfg; +aamfh; +aamfi; +aamfj; +aamfk; +aamfl; +aamfm; +aamfn; +aamfo; +aamfp; +aamfq; +aamfr; +aamfs; +aamft; +aamfu; +aamfv; +aamfw; +aamfx; +aamfy; +aamfz; +aamga; +aamgb; +aamgc; +aamgd; +aamge; +aamgf; +aamgg; +aamgh; +aamgi; +aamgj; +aamgk; +aamgl; +aamgm; +aamgn; +aamgo; +aamgp; +aamgq; +aamgr; +aamgs; +aamgt; +aamgu; +aamgv; +aamgw; +aamgx; +aamgy; +aamgz; +aamha; +aamhb; +aamhc; +aamhd; +aamhe; +aamhf; +aamhg; +aamhh; +aamhi; +aamhj; +aamhk; +aamhl; +aamhm; +aamhn; +aamho; +aamhp; +aamhq; +aamhr; +aamhs; +aamht; +aamhu; +aamhv; +aamhw; +aamhx; +aamhy; +aamhz; +aamia; +aamib; +aamic; +aamid; +aamie; +aamif; +aamig; +aamih; +aamii; +aamij; +aamik; +aamil; +aamim; +aamin; +aamio; +aamip; +aamiq; +aamir; +aamis; +aamit; +aamiu; +aamiv; +aamiw; +aamix; +aamiy; +aamiz; +aamja; +aamjb; +aamjc; +aamjd; +aamje; +aamjf; +aamjg; +aamjh; +aamji; +aamjj; +aamjk; +aamjl; +aamjm; +aamjn; +aamjo; +aamjp; +aamjq; +aamjr; +aamjs; +aamjt; +aamju; +aamjv; +aamjw; +aamjx; +aamjy; +aamjz; +aamka; +aamkb; +aamkc; +aamkd; +aamke; +aamkf; +aamkg; +aamkh; +aamki; +aamkj; +aamkk; +aamkl; +aamkm; +aamkn; +aamko; +aamkp; +aamkq; +aamkr; +aamks; +aamkt; +aamku; +aamkv; +aamkw; +aamkx; +aamky; +aamkz; +aamla; +aamlb; +aamlc; +aamld; +aamle; +aamlf; +aamlg; +aamlh; +aamli; +aamlj; +aamlk; +aamll; +aamlm; +aamln; +aamlo; +aamlp; +aamlq; +aamlr; +aamls; +aamlt; +aamlu; +aamlv; +aamlw; +aamlx; +aamly; +aamlz; +aamma; +aammb; +aammc; +aammd; +aamme; +aammf; +aammg; +aammh; +aammi; +aammj; +aammk; +aamml; +aammm; +aammn; +aammo; +aammp; +aammq; +aammr; +aamms; +aammt; +aammu; +aammv; +aammw; +aammx; +aammy; +aammz; +aamna; +aamnb; +aamnc; +aamnd; +aamne; +aamnf; +aamng; +aamnh; +aamni; +aamnj; +aamnk; +aamnl; +aamnm; +aamnn; +aamno; +aamnp; +aamnq; +aamnr; +aamns; +aamnt; +aamnu; +aamnv; +aamnw; +aamnx; +aamny; +aamnz; +aamoa; +aamob; +aamoc; +aamod; +aamoe; +aamof; +aamog; +aamoh; +aamoi; +aamoj; +aamok; +aamol; +aamom; +aamon; +aamoo; +aamop; +aamoq; +aamor; +aamos; +aamot; +aamou; +aamov; +aamow; +aamox; +aamoy; +aamoz; +aampa; +aampb; +aampc; +aampd; +aampe; +aampf; +aampg; +aamph; +aampi; +aampj; +aampk; +aampl; +aampm; +aampn; +aampo; +aampp; +aampq; +aampr; +aamps; +aampt; +aampu; +aampv; +aampw; +aampx; +aampy; +aampz; +aamqa; +aamqb; +aamqc; +aamqd; +aamqe; +aamqf; +aamqg; +aamqh; +aamqi; +aamqj; +aamqk; +aamql; +aamqm; +aamqn; +aamqo; +aamqp; +aamqq; +aamqr; +aamqs; +aamqt; +aamqu; +aamqv; +aamqw; +aamqx; +aamqy; +aamqz; +aamra; +aamrb; +aamrc; +aamrd; +aamre; +aamrf; +aamrg; +aamrh; +aamri; +aamrj; +aamrk; +aamrl; +aamrm; +aamrn; +aamro; +aamrp; +aamrq; +aamrr; +aamrs; +aamrt; +aamru; +aamrv; +aamrw; +aamrx; +aamry; +aamrz; +aamsa; +aamsb; +aamsc; +aamsd; +aamse; +aamsf; +aamsg; +aamsh; +aamsi; +aamsj; +aamsk; +aamsl; +aamsm; +aamsn; +aamso; +aamsp; +aamsq; +aamsr; +aamss; +aamst; +aamsu; +aamsv; +aamsw; +aamsx; +aamsy; +aamsz; +aamta; +aamtb; +aamtc; +aamtd; +aamte; +aamtf; +aamtg; +aamth; +aamti; +aamtj; +aamtk; +aamtl; +aamtm; +aamtn; +aamto; +aamtp; +aamtq; +aamtr; +aamts; +aamtt; +aamtu; +aamtv; +aamtw; +aamtx; +aamty; +aamtz; +aamua; +aamub; +aamuc; +aamud; +aamue; +aamuf; +aamug; +aamuh; +aamui; +aamuj; +aamuk; +aamul; +aamum; +aamun; +aamuo; +aamup; +aamuq; +aamur; +aamus; +aamut; +aamuu; +aamuv; +aamuw; +aamux; +aamuy; +aamuz; +aamva; +aamvb; +aamvc; +aamvd; +aamve; +aamvf; +aamvg; +aamvh; +aamvi; +aamvj; +aamvk; +aamvl; +aamvm; +aamvn; +aamvo; +aamvp; +aamvq; +aamvr; +aamvs; +aamvt; +aamvu; +aamvv; +aamvw; +aamvx; +aamvy; +aamvz; +aamwa; +aamwb; +aamwc; +aamwd; +aamwe; +aamwf; +aamwg; +aamwh; +aamwi; +aamwj; +aamwk; +aamwl; +aamwm; +aamwn; +aamwo; +aamwp; +aamwq; +aamwr; +aamws; +aamwt; +aamwu; +aamwv; +aamww; +aamwx; +aamwy; +aamwz; +aamxa; +aamxb; +aamxc; +aamxd; +aamxe; +aamxf; +aamxg; +aamxh; +aamxi; +aamxj; +aamxk; +aamxl; +aamxm; +aamxn; +aamxo; +aamxp; +aamxq; +aamxr; +aamxs; +aamxt; +aamxu; +aamxv; +aamxw; +aamxx; +aamxy; +aamxz; +aamya; +aamyb; +aamyc; +aamyd; +aamye; +aamyf; +aamyg; +aamyh; +aamyi; +aamyj; +aamyk; +aamyl; +aamym; +aamyn; +aamyo; +aamyp; +aamyq; +aamyr; +aamys; +aamyt; +aamyu; +aamyv; +aamyw; +aamyx; +aamyy; +aamyz; +aamza; +aamzb; +aamzc; +aamzd; +aamze; +aamzf; +aamzg; +aamzh; +aamzi; +aamzj; +aamzk; +aamzl; +aamzm; +aamzn; +aamzo; +aamzp; +aamzq; +aamzr; +aamzs; +aamzt; +aamzu; +aamzv; +aamzw; +aamzx; +aamzy; +aamzz; +aanaa; +aanab; +aanac; +aanad; +aanae; +aanaf; +aanag; +aanah; +aanai; +aanaj; +aanak; +aanal; +aanam; +aanan; +aanao; +aanap; +aanaq; +aanar; +aanas; +aanat; +aanau; +aanav; +aanaw; +aanax; +aanay; +aanaz; +aanba; +aanbb; +aanbc; +aanbd; +aanbe; +aanbf; +aanbg; +aanbh; +aanbi; +aanbj; +aanbk; +aanbl; +aanbm; +aanbn; +aanbo; +aanbp; +aanbq; +aanbr; +aanbs; +aanbt; +aanbu; +aanbv; +aanbw; +aanbx; +aanby; +aanbz; +aanca; +aancb; +aancc; +aancd; +aance; +aancf; +aancg; +aanch; +aanci; +aancj; +aanck; +aancl; +aancm; +aancn; +aanco; +aancp; +aancq; +aancr; +aancs; +aanct; +aancu; +aancv; +aancw; +aancx; +aancy; +aancz; +aanda; +aandb; +aandc; +aandd; +aande; +aandf; +aandg; +aandh; +aandi; +aandj; +aandk; +aandl; +aandm; +aandn; +aando; +aandp; +aandq; +aandr; +aands; +aandt; +aandu; +aandv; +aandw; +aandx; +aandy; +aandz; +aanea; +aaneb; +aanec; +aaned; +aanee; +aanef; +aaneg; +aaneh; +aanei; +aanej; +aanek; +aanel; +aanem; +aanen; +aaneo; +aanep; +aaneq; +aaner; +aanes; +aanet; +aaneu; +aanev; +aanew; +aanex; +aaney; +aanez; +aanfa; +aanfb; +aanfc; +aanfd; +aanfe; +aanff; +aanfg; +aanfh; +aanfi; +aanfj; +aanfk; +aanfl; +aanfm; +aanfn; +aanfo; +aanfp; +aanfq; +aanfr; +aanfs; +aanft; +aanfu; +aanfv; +aanfw; +aanfx; +aanfy; +aanfz; +aanga; +aangb; +aangc; +aangd; +aange; +aangf; +aangg; +aangh; +aangi; +aangj; +aangk; +aangl; +aangm; +aangn; +aango; +aangp; +aangq; +aangr; +aangs; +aangt; +aangu; +aangv; +aangw; +aangx; +aangy; +aangz; +aanha; +aanhb; +aanhc; +aanhd; +aanhe; +aanhf; +aanhg; +aanhh; +aanhi; +aanhj; +aanhk; +aanhl; +aanhm; +aanhn; +aanho; +aanhp; +aanhq; +aanhr; +aanhs; +aanht; +aanhu; +aanhv; +aanhw; +aanhx; +aanhy; +aanhz; +aania; +aanib; +aanic; +aanid; +aanie; +aanif; +aanig; +aanih; +aanii; +aanij; +aanik; +aanil; +aanim; +aanin; +aanio; +aanip; +aaniq; +aanir; +aanis; +aanit; +aaniu; +aaniv; +aaniw; +aanix; +aaniy; +aaniz; +aanja; +aanjb; +aanjc; +aanjd; +aanje; +aanjf; +aanjg; +aanjh; +aanji; +aanjj; +aanjk; +aanjl; +aanjm; +aanjn; +aanjo; +aanjp; +aanjq; +aanjr; +aanjs; +aanjt; +aanju; +aanjv; +aanjw; +aanjx; +aanjy; +aanjz; +aanka; +aankb; +aankc; +aankd; +aanke; +aankf; +aankg; +aankh; +aanki; +aankj; +aankk; +aankl; +aankm; +aankn; +aanko; +aankp; +aankq; +aankr; +aanks; +aankt; +aanku; +aankv; +aankw; +aankx; +aanky; +aankz; +aanla; +aanlb; +aanlc; +aanld; +aanle; +aanlf; +aanlg; +aanlh; +aanli; +aanlj; +aanlk; +aanll; +aanlm; +aanln; +aanlo; +aanlp; +aanlq; +aanlr; +aanls; +aanlt; +aanlu; +aanlv; +aanlw; +aanlx; +aanly; +aanlz; +aanma; +aanmb; +aanmc; +aanmd; +aanme; +aanmf; +aanmg; +aanmh; +aanmi; +aanmj; +aanmk; +aanml; +aanmm; +aanmn; +aanmo; +aanmp; +aanmq; +aanmr; +aanms; +aanmt; +aanmu; +aanmv; +aanmw; +aanmx; +aanmy; +aanmz; +aanna; +aannb; +aannc; +aannd; +aanne; +aannf; +aanng; +aannh; +aanni; +aannj; +aannk; +aannl; +aannm; +aannn; +aanno; +aannp; +aannq; +aannr; +aanns; +aannt; +aannu; +aannv; +aannw; +aannx; +aanny; +aannz; +aanoa; +aanob; +aanoc; +aanod; +aanoe; +aanof; +aanog; +aanoh; +aanoi; +aanoj; +aanok; +aanol; +aanom; +aanon; +aanoo; +aanop; +aanoq; +aanor; +aanos; +aanot; +aanou; +aanov; +aanow; +aanox; +aanoy; +aanoz; +aanpa; +aanpb; +aanpc; +aanpd; +aanpe; +aanpf; +aanpg; +aanph; +aanpi; +aanpj; +aanpk; +aanpl; +aanpm; +aanpn; +aanpo; +aanpp; +aanpq; +aanpr; +aanps; +aanpt; +aanpu; +aanpv; +aanpw; +aanpx; +aanpy; +aanpz; +aanqa; +aanqb; +aanqc; +aanqd; +aanqe; +aanqf; +aanqg; +aanqh; +aanqi; +aanqj; +aanqk; +aanql; +aanqm; +aanqn; +aanqo; +aanqp; +aanqq; +aanqr; +aanqs; +aanqt; +aanqu; +aanqv; +aanqw; +aanqx; +aanqy; +aanqz; +aanra; +aanrb; +aanrc; +aanrd; +aanre; +aanrf; +aanrg; +aanrh; +aanri; +aanrj; +aanrk; +aanrl; +aanrm; +aanrn; +aanro; +aanrp; +aanrq; +aanrr; +aanrs; +aanrt; +aanru; +aanrv; +aanrw; +aanrx; +aanry; +aanrz; +aansa; +aansb; +aansc; +aansd; +aanse; +aansf; +aansg; +aansh; +aansi; +aansj; +aansk; +aansl; +aansm; +aansn; +aanso; +aansp; +aansq; +aansr; +aanss; +aanst; +aansu; +aansv; +aansw; +aansx; +aansy; +aansz; +aanta; +aantb; +aantc; +aantd; +aante; +aantf; +aantg; +aanth; +aanti; +aantj; +aantk; +aantl; +aantm; +aantn; +aanto; +aantp; +aantq; +aantr; +aants; +aantt; +aantu; +aantv; +aantw; +aantx; +aanty; +aantz; +aanua; +aanub; +aanuc; +aanud; +aanue; +aanuf; +aanug; +aanuh; +aanui; +aanuj; +aanuk; +aanul; +aanum; +aanun; +aanuo; +aanup; +aanuq; +aanur; +aanus; +aanut; +aanuu; +aanuv; +aanuw; +aanux; +aanuy; +aanuz; +aanva; +aanvb; +aanvc; +aanvd; +aanve; +aanvf; +aanvg; +aanvh; +aanvi; +aanvj; +aanvk; +aanvl; +aanvm; +aanvn; +aanvo; +aanvp; +aanvq; +aanvr; +aanvs; +aanvt; +aanvu; +aanvv; +aanvw; +aanvx; +aanvy; +aanvz; +aanwa; +aanwb; +aanwc; +aanwd; +aanwe; +aanwf; +aanwg; +aanwh; +aanwi; +aanwj; +aanwk; +aanwl; +aanwm; +aanwn; +aanwo; +aanwp; +aanwq; +aanwr; +aanws; +aanwt; +aanwu; +aanwv; +aanww; +aanwx; +aanwy; +aanwz; +aanxa; +aanxb; +aanxc; +aanxd; +aanxe; +aanxf; +aanxg; +aanxh; +aanxi; +aanxj; +aanxk; +aanxl; +aanxm; +aanxn; +aanxo; +aanxp; +aanxq; +aanxr; +aanxs; +aanxt; +aanxu; +aanxv; +aanxw; +aanxx; +aanxy; +aanxz; +aanya; +aanyb; +aanyc; +aanyd; +aanye; +aanyf; +aanyg; +aanyh; +aanyi; +aanyj; +aanyk; +aanyl; +aanym; +aanyn; +aanyo; +aanyp; +aanyq; +aanyr; +aanys; +aanyt; +aanyu; +aanyv; +aanyw; +aanyx; +aanyy; +aanyz; +aanza; +aanzb; +aanzc; +aanzd; +aanze; +aanzf; +aanzg; +aanzh; +aanzi; +aanzj; +aanzk; +aanzl; +aanzm; +aanzn; +aanzo; +aanzp; +aanzq; +aanzr; +aanzs; +aanzt; +aanzu; +aanzv; +aanzw; +aanzx; +aanzy; +aanzz; +aaoaa; +aaoab; +aaoac; +aaoad; +aaoae; +aaoaf; +aaoag; +aaoah; +aaoai; +aaoaj; +aaoak; +aaoal; +aaoam; +aaoan; +aaoao; +aaoap; +aaoaq; +aaoar; +aaoas; +aaoat; +aaoau; +aaoav; +aaoaw; +aaoax; +aaoay; +aaoaz; +aaoba; +aaobb; +aaobc; +aaobd; +aaobe; +aaobf; +aaobg; +aaobh; +aaobi; +aaobj; +aaobk; +aaobl; +aaobm; +aaobn; +aaobo; +aaobp; +aaobq; +aaobr; +aaobs; +aaobt; +aaobu; +aaobv; +aaobw; +aaobx; +aaoby; +aaobz; +aaoca; +aaocb; +aaocc; +aaocd; +aaoce; +aaocf; +aaocg; +aaoch; +aaoci; +aaocj; +aaock; +aaocl; +aaocm; +aaocn; +aaoco; +aaocp; +aaocq; +aaocr; +aaocs; +aaoct; +aaocu; +aaocv; +aaocw; +aaocx; +aaocy; +aaocz; +aaoda; +aaodb; +aaodc; +aaodd; +aaode; +aaodf; +aaodg; +aaodh; +aaodi; +aaodj; +aaodk; +aaodl; +aaodm; +aaodn; +aaodo; +aaodp; +aaodq; +aaodr; +aaods; +aaodt; +aaodu; +aaodv; +aaodw; +aaodx; +aaody; +aaodz; +aaoea; +aaoeb; +aaoec; +aaoed; +aaoee; +aaoef; +aaoeg; +aaoeh; +aaoei; +aaoej; +aaoek; +aaoel; +aaoem; +aaoen; +aaoeo; +aaoep; +aaoeq; +aaoer; +aaoes; +aaoet; +aaoeu; +aaoev; +aaoew; +aaoex; +aaoey; +aaoez; +aaofa; +aaofb; +aaofc; +aaofd; +aaofe; +aaoff; +aaofg; +aaofh; +aaofi; +aaofj; +aaofk; +aaofl; +aaofm; +aaofn; +aaofo; +aaofp; +aaofq; +aaofr; +aaofs; +aaoft; +aaofu; +aaofv; +aaofw; +aaofx; +aaofy; +aaofz; +aaoga; +aaogb; +aaogc; +aaogd; +aaoge; +aaogf; +aaogg; +aaogh; +aaogi; +aaogj; +aaogk; +aaogl; +aaogm; +aaogn; +aaogo; +aaogp; +aaogq; +aaogr; +aaogs; +aaogt; +aaogu; +aaogv; +aaogw; +aaogx; +aaogy; +aaogz; +aaoha; +aaohb; +aaohc; +aaohd; +aaohe; +aaohf; +aaohg; +aaohh; +aaohi; +aaohj; +aaohk; +aaohl; +aaohm; +aaohn; +aaoho; +aaohp; +aaohq; +aaohr; +aaohs; +aaoht; +aaohu; +aaohv; +aaohw; +aaohx; +aaohy; +aaohz; +aaoia; +aaoib; +aaoic; +aaoid; +aaoie; +aaoif; +aaoig; +aaoih; +aaoii; +aaoij; +aaoik; +aaoil; +aaoim; +aaoin; +aaoio; +aaoip; +aaoiq; +aaoir; +aaois; +aaoit; +aaoiu; +aaoiv; +aaoiw; +aaoix; +aaoiy; +aaoiz; +aaoja; +aaojb; +aaojc; +aaojd; +aaoje; +aaojf; +aaojg; +aaojh; +aaoji; +aaojj; +aaojk; +aaojl; +aaojm; +aaojn; +aaojo; +aaojp; +aaojq; +aaojr; +aaojs; +aaojt; +aaoju; +aaojv; +aaojw; +aaojx; +aaojy; +aaojz; +aaoka; +aaokb; +aaokc; +aaokd; +aaoke; +aaokf; +aaokg; +aaokh; +aaoki; +aaokj; +aaokk; +aaokl; +aaokm; +aaokn; +aaoko; +aaokp; +aaokq; +aaokr; +aaoks; +aaokt; +aaoku; +aaokv; +aaokw; +aaokx; +aaoky; +aaokz; +aaola; +aaolb; +aaolc; +aaold; +aaole; +aaolf; +aaolg; +aaolh; +aaoli; +aaolj; +aaolk; +aaoll; +aaolm; +aaoln; +aaolo; +aaolp; +aaolq; +aaolr; +aaols; +aaolt; +aaolu; +aaolv; +aaolw; +aaolx; +aaoly; +aaolz; +aaoma; +aaomb; +aaomc; +aaomd; +aaome; +aaomf; +aaomg; +aaomh; +aaomi; +aaomj; +aaomk; +aaoml; +aaomm; +aaomn; +aaomo; +aaomp; +aaomq; +aaomr; +aaoms; +aaomt; +aaomu; +aaomv; +aaomw; +aaomx; +aaomy; +aaomz; +aaona; +aaonb; +aaonc; +aaond; +aaone; +aaonf; +aaong; +aaonh; +aaoni; +aaonj; +aaonk; +aaonl; +aaonm; +aaonn; +aaono; +aaonp; +aaonq; +aaonr; +aaons; +aaont; +aaonu; +aaonv; +aaonw; +aaonx; +aaony; +aaonz; +aaooa; +aaoob; +aaooc; +aaood; +aaooe; +aaoof; +aaoog; +aaooh; +aaooi; +aaooj; +aaook; +aaool; +aaoom; +aaoon; +aaooo; +aaoop; +aaooq; +aaoor; +aaoos; +aaoot; +aaoou; +aaoov; +aaoow; +aaoox; +aaooy; +aaooz; +aaopa; +aaopb; +aaopc; +aaopd; +aaope; +aaopf; +aaopg; +aaoph; +aaopi; +aaopj; +aaopk; +aaopl; +aaopm; +aaopn; +aaopo; +aaopp; +aaopq; +aaopr; +aaops; +aaopt; +aaopu; +aaopv; +aaopw; +aaopx; +aaopy; +aaopz; +aaoqa; +aaoqb; +aaoqc; +aaoqd; +aaoqe; +aaoqf; +aaoqg; +aaoqh; +aaoqi; +aaoqj; +aaoqk; +aaoql; +aaoqm; +aaoqn; +aaoqo; +aaoqp; +aaoqq; +aaoqr; +aaoqs; +aaoqt; +aaoqu; +aaoqv; +aaoqw; +aaoqx; +aaoqy; +aaoqz; +aaora; +aaorb; +aaorc; +aaord; +aaore; +aaorf; +aaorg; +aaorh; +aaori; +aaorj; +aaork; +aaorl; +aaorm; +aaorn; +aaoro; +aaorp; +aaorq; +aaorr; +aaors; +aaort; +aaoru; +aaorv; +aaorw; +aaorx; +aaory; +aaorz; +aaosa; +aaosb; +aaosc; +aaosd; +aaose; +aaosf; +aaosg; +aaosh; +aaosi; +aaosj; +aaosk; +aaosl; +aaosm; +aaosn; +aaoso; +aaosp; +aaosq; +aaosr; +aaoss; +aaost; +aaosu; +aaosv; +aaosw; +aaosx; +aaosy; +aaosz; +aaota; +aaotb; +aaotc; +aaotd; +aaote; +aaotf; +aaotg; +aaoth; +aaoti; +aaotj; +aaotk; +aaotl; +aaotm; +aaotn; +aaoto; +aaotp; +aaotq; +aaotr; +aaots; +aaott; +aaotu; +aaotv; +aaotw; +aaotx; +aaoty; +aaotz; +aaoua; +aaoub; +aaouc; +aaoud; +aaoue; +aaouf; +aaoug; +aaouh; +aaoui; +aaouj; +aaouk; +aaoul; +aaoum; +aaoun; +aaouo; +aaoup; +aaouq; +aaour; +aaous; +aaout; +aaouu; +aaouv; +aaouw; +aaoux; +aaouy; +aaouz; +aaova; +aaovb; +aaovc; +aaovd; +aaove; +aaovf; +aaovg; +aaovh; +aaovi; +aaovj; +aaovk; +aaovl; +aaovm; +aaovn; +aaovo; +aaovp; +aaovq; +aaovr; +aaovs; +aaovt; +aaovu; +aaovv; +aaovw; +aaovx; +aaovy; +aaovz; +aaowa; +aaowb; +aaowc; +aaowd; +aaowe; +aaowf; +aaowg; +aaowh; +aaowi; +aaowj; +aaowk; +aaowl; +aaowm; +aaown; +aaowo; +aaowp; +aaowq; +aaowr; +aaows; +aaowt; +aaowu; +aaowv; +aaoww; +aaowx; +aaowy; +aaowz; +aaoxa; +aaoxb; +aaoxc; +aaoxd; +aaoxe; +aaoxf; +aaoxg; +aaoxh; +aaoxi; +aaoxj; +aaoxk; +aaoxl; +aaoxm; +aaoxn; +aaoxo; +aaoxp; +aaoxq; +aaoxr; +aaoxs; +aaoxt; +aaoxu; +aaoxv; +aaoxw; +aaoxx; +aaoxy; +aaoxz; +aaoya; +aaoyb; +aaoyc; +aaoyd; +aaoye; +aaoyf; +aaoyg; +aaoyh; +aaoyi; +aaoyj; +aaoyk; +aaoyl; +aaoym; +aaoyn; +aaoyo; +aaoyp; +aaoyq; +aaoyr; +aaoys; +aaoyt; +aaoyu; +aaoyv; +aaoyw; +aaoyx; +aaoyy; +aaoyz; +aaoza; +aaozb; +aaozc; +aaozd; +aaoze; +aaozf; +aaozg; +aaozh; +aaozi; +aaozj; +aaozk; +aaozl; +aaozm; +aaozn; +aaozo; +aaozp; +aaozq; +aaozr; +aaozs; +aaozt; +aaozu; +aaozv; +aaozw; +aaozx; +aaozy; +aaozz; +aapaa; +aapab; +aapac; +aapad; +aapae; +aapaf; +aapag; +aapah; +aapai; +aapaj; +aapak; +aapal; +aapam; +aapan; +aapao; +aapap; +aapaq; +aapar; +aapas; +aapat; +aapau; +aapav; +aapaw; +aapax; +aapay; +aapaz; +aapba; +aapbb; +aapbc; +aapbd; +aapbe; +aapbf; +aapbg; +aapbh; +aapbi; +aapbj; +aapbk; +aapbl; +aapbm; +aapbn; +aapbo; +aapbp; +aapbq; +aapbr; +aapbs; +aapbt; +aapbu; +aapbv; +aapbw; +aapbx; +aapby; +aapbz; +aapca; +aapcb; +aapcc; +aapcd; +aapce; +aapcf; +aapcg; +aapch; +aapci; +aapcj; +aapck; +aapcl; +aapcm; +aapcn; +aapco; +aapcp; +aapcq; +aapcr; +aapcs; +aapct; +aapcu; +aapcv; +aapcw; +aapcx; +aapcy; +aapcz; +aapda; +aapdb; +aapdc; +aapdd; +aapde; +aapdf; +aapdg; +aapdh; +aapdi; +aapdj; +aapdk; +aapdl; +aapdm; +aapdn; +aapdo; +aapdp; +aapdq; +aapdr; +aapds; +aapdt; +aapdu; +aapdv; +aapdw; +aapdx; +aapdy; +aapdz; +aapea; +aapeb; +aapec; +aaped; +aapee; +aapef; +aapeg; +aapeh; +aapei; +aapej; +aapek; +aapel; +aapem; +aapen; +aapeo; +aapep; +aapeq; +aaper; +aapes; +aapet; +aapeu; +aapev; +aapew; +aapex; +aapey; +aapez; +aapfa; +aapfb; +aapfc; +aapfd; +aapfe; +aapff; +aapfg; +aapfh; +aapfi; +aapfj; +aapfk; +aapfl; +aapfm; +aapfn; +aapfo; +aapfp; +aapfq; +aapfr; +aapfs; +aapft; +aapfu; +aapfv; +aapfw; +aapfx; +aapfy; +aapfz; +aapga; +aapgb; +aapgc; +aapgd; +aapge; +aapgf; +aapgg; +aapgh; +aapgi; +aapgj; +aapgk; +aapgl; +aapgm; +aapgn; +aapgo; +aapgp; +aapgq; +aapgr; +aapgs; +aapgt; +aapgu; +aapgv; +aapgw; +aapgx; +aapgy; +aapgz; +aapha; +aaphb; +aaphc; +aaphd; +aaphe; +aaphf; +aaphg; +aaphh; +aaphi; +aaphj; +aaphk; +aaphl; +aaphm; +aaphn; +aapho; +aaphp; +aaphq; +aaphr; +aaphs; +aapht; +aaphu; +aaphv; +aaphw; +aaphx; +aaphy; +aaphz; +aapia; +aapib; +aapic; +aapid; +aapie; +aapif; +aapig; +aapih; +aapii; +aapij; +aapik; +aapil; +aapim; +aapin; +aapio; +aapip; +aapiq; +aapir; +aapis; +aapit; +aapiu; +aapiv; +aapiw; +aapix; +aapiy; +aapiz; +aapja; +aapjb; +aapjc; +aapjd; +aapje; +aapjf; +aapjg; +aapjh; +aapji; +aapjj; +aapjk; +aapjl; +aapjm; +aapjn; +aapjo; +aapjp; +aapjq; +aapjr; +aapjs; +aapjt; +aapju; +aapjv; +aapjw; +aapjx; +aapjy; +aapjz; +aapka; +aapkb; +aapkc; +aapkd; +aapke; +aapkf; +aapkg; +aapkh; +aapki; +aapkj; +aapkk; +aapkl; +aapkm; +aapkn; +aapko; +aapkp; +aapkq; +aapkr; +aapks; +aapkt; +aapku; +aapkv; +aapkw; +aapkx; +aapky; +aapkz; +aapla; +aaplb; +aaplc; +aapld; +aaple; +aaplf; +aaplg; +aaplh; +aapli; +aaplj; +aaplk; +aapll; +aaplm; +aapln; +aaplo; +aaplp; +aaplq; +aaplr; +aapls; +aaplt; +aaplu; +aaplv; +aaplw; +aaplx; +aaply; +aaplz; +aapma; +aapmb; +aapmc; +aapmd; +aapme; +aapmf; +aapmg; +aapmh; +aapmi; +aapmj; +aapmk; +aapml; +aapmm; +aapmn; +aapmo; +aapmp; +aapmq; +aapmr; +aapms; +aapmt; +aapmu; +aapmv; +aapmw; +aapmx; +aapmy; +aapmz; +aapna; +aapnb; +aapnc; +aapnd; +aapne; +aapnf; +aapng; +aapnh; +aapni; +aapnj; +aapnk; +aapnl; +aapnm; +aapnn; +aapno; +aapnp; +aapnq; +aapnr; +aapns; +aapnt; +aapnu; +aapnv; +aapnw; +aapnx; +aapny; +aapnz; +aapoa; +aapob; +aapoc; +aapod; +aapoe; +aapof; +aapog; +aapoh; +aapoi; +aapoj; +aapok; +aapol; +aapom; +aapon; +aapoo; +aapop; +aapoq; +aapor; +aapos; +aapot; +aapou; +aapov; +aapow; +aapox; +aapoy; +aapoz; +aappa; +aappb; +aappc; +aappd; +aappe; +aappf; +aappg; +aapph; +aappi; +aappj; +aappk; +aappl; +aappm; +aappn; +aappo; +aappp; +aappq; +aappr; +aapps; +aappt; +aappu; +aappv; +aappw; +aappx; +aappy; +aappz; +aapqa; +aapqb; +aapqc; +aapqd; +aapqe; +aapqf; +aapqg; +aapqh; +aapqi; +aapqj; +aapqk; +aapql; +aapqm; +aapqn; +aapqo; +aapqp; +aapqq; +aapqr; +aapqs; +aapqt; +aapqu; +aapqv; +aapqw; +aapqx; +aapqy; +aapqz; +aapra; +aaprb; +aaprc; +aaprd; +aapre; +aaprf; +aaprg; +aaprh; +aapri; +aaprj; +aaprk; +aaprl; +aaprm; +aaprn; +aapro; +aaprp; +aaprq; +aaprr; +aaprs; +aaprt; +aapru; +aaprv; +aaprw; +aaprx; +aapry; +aaprz; +aapsa; +aapsb; +aapsc; +aapsd; +aapse; +aapsf; +aapsg; +aapsh; +aapsi; +aapsj; +aapsk; +aapsl; +aapsm; +aapsn; +aapso; +aapsp; +aapsq; +aapsr; +aapss; +aapst; +aapsu; +aapsv; +aapsw; +aapsx; +aapsy; +aapsz; +aapta; +aaptb; +aaptc; +aaptd; +aapte; +aaptf; +aaptg; +aapth; +aapti; +aaptj; +aaptk; +aaptl; +aaptm; +aaptn; +aapto; +aaptp; +aaptq; +aaptr; +aapts; +aaptt; +aaptu; +aaptv; +aaptw; +aaptx; +aapty; +aaptz; +aapua; +aapub; +aapuc; +aapud; +aapue; +aapuf; +aapug; +aapuh; +aapui; +aapuj; +aapuk; +aapul; +aapum; +aapun; +aapuo; +aapup; +aapuq; +aapur; +aapus; +aaput; +aapuu; +aapuv; +aapuw; +aapux; +aapuy; +aapuz; +aapva; +aapvb; +aapvc; +aapvd; +aapve; +aapvf; +aapvg; +aapvh; +aapvi; +aapvj; +aapvk; +aapvl; +aapvm; +aapvn; +aapvo; +aapvp; +aapvq; +aapvr; +aapvs; +aapvt; +aapvu; +aapvv; +aapvw; +aapvx; +aapvy; +aapvz; +aapwa; +aapwb; +aapwc; +aapwd; +aapwe; +aapwf; +aapwg; +aapwh; +aapwi; +aapwj; +aapwk; +aapwl; +aapwm; +aapwn; +aapwo; +aapwp; +aapwq; +aapwr; +aapws; +aapwt; +aapwu; +aapwv; +aapww; +aapwx; +aapwy; +aapwz; +aapxa; +aapxb; +aapxc; +aapxd; +aapxe; +aapxf; +aapxg; +aapxh; +aapxi; +aapxj; +aapxk; +aapxl; +aapxm; +aapxn; +aapxo; +aapxp; +aapxq; +aapxr; +aapxs; +aapxt; +aapxu; +aapxv; +aapxw; +aapxx; +aapxy; +aapxz; +aapya; +aapyb; +aapyc; +aapyd; +aapye; +aapyf; +aapyg; +aapyh; +aapyi; +aapyj; +aapyk; +aapyl; +aapym; +aapyn; +aapyo; +aapyp; +aapyq; +aapyr; +aapys; +aapyt; +aapyu; +aapyv; +aapyw; +aapyx; +aapyy; +aapyz; +aapza; +aapzb; +aapzc; +aapzd; +aapze; +aapzf; +aapzg; +aapzh; +aapzi; +aapzj; +aapzk; +aapzl; +aapzm; +aapzn; +aapzo; +aapzp; +aapzq; +aapzr; +aapzs; +aapzt; +aapzu; +aapzv; +aapzw; +aapzx; +aapzy; +aapzz; +aaqaa; +aaqab; +aaqac; +aaqad; +aaqae; +aaqaf; +aaqag; +aaqah; +aaqai; +aaqaj; +aaqak; +aaqal; +aaqam; +aaqan; +aaqao; +aaqap; +aaqaq; +aaqar; +aaqas; +aaqat; +aaqau; +aaqav; +aaqaw; +aaqax; +aaqay; +aaqaz; +aaqba; +aaqbb; +aaqbc; +aaqbd; +aaqbe; +aaqbf; +aaqbg; +aaqbh; +aaqbi; +aaqbj; +aaqbk; +aaqbl; +aaqbm; +aaqbn; +aaqbo; +aaqbp; +aaqbq; +aaqbr; +aaqbs; +aaqbt; +aaqbu; +aaqbv; +aaqbw; +aaqbx; +aaqby; +aaqbz; +aaqca; +aaqcb; +aaqcc; +aaqcd; +aaqce; +aaqcf; +aaqcg; +aaqch; +aaqci; +aaqcj; +aaqck; +aaqcl; +aaqcm; +aaqcn; +aaqco; +aaqcp; +aaqcq; +aaqcr; +aaqcs; +aaqct; +aaqcu; +aaqcv; +aaqcw; +aaqcx; +aaqcy; +aaqcz; +aaqda; +aaqdb; +aaqdc; +aaqdd; +aaqde; +aaqdf; +aaqdg; +aaqdh; +aaqdi; +aaqdj; +aaqdk; +aaqdl; +aaqdm; +aaqdn; +aaqdo; +aaqdp; +aaqdq; +aaqdr; +aaqds; +aaqdt; +aaqdu; +aaqdv; +aaqdw; +aaqdx; +aaqdy; +aaqdz; +aaqea; +aaqeb; +aaqec; +aaqed; +aaqee; +aaqef; +aaqeg; +aaqeh; +aaqei; +aaqej; +aaqek; +aaqel; +aaqem; +aaqen; +aaqeo; +aaqep; +aaqeq; +aaqer; +aaqes; +aaqet; +aaqeu; +aaqev; +aaqew; +aaqex; +aaqey; +aaqez; +aaqfa; +aaqfb; +aaqfc; +aaqfd; +aaqfe; +aaqff; +aaqfg; +aaqfh; +aaqfi; +aaqfj; +aaqfk; +aaqfl; +aaqfm; +aaqfn; +aaqfo; +aaqfp; +aaqfq; +aaqfr; +aaqfs; +aaqft; +aaqfu; +aaqfv; +aaqfw; +aaqfx; +aaqfy; +aaqfz; +aaqga; +aaqgb; +aaqgc; +aaqgd; +aaqge; +aaqgf; +aaqgg; +aaqgh; +aaqgi; +aaqgj; +aaqgk; +aaqgl; +aaqgm; +aaqgn; +aaqgo; +aaqgp; +aaqgq; +aaqgr; +aaqgs; +aaqgt; +aaqgu; +aaqgv; +aaqgw; +aaqgx; +aaqgy; +aaqgz; +aaqha; +aaqhb; +aaqhc; +aaqhd; +aaqhe; +aaqhf; +aaqhg; +aaqhh; +aaqhi; +aaqhj; +aaqhk; +aaqhl; +aaqhm; +aaqhn; +aaqho; +aaqhp; +aaqhq; +aaqhr; +aaqhs; +aaqht; +aaqhu; +aaqhv; +aaqhw; +aaqhx; +aaqhy; +aaqhz; +aaqia; +aaqib; +aaqic; +aaqid; +aaqie; +aaqif; +aaqig; +aaqih; +aaqii; +aaqij; +aaqik; +aaqil; +aaqim; +aaqin; +aaqio; +aaqip; +aaqiq; +aaqir; +aaqis; +aaqit; +aaqiu; +aaqiv; +aaqiw; +aaqix; +aaqiy; +aaqiz; +aaqja; +aaqjb; +aaqjc; +aaqjd; +aaqje; +aaqjf; +aaqjg; +aaqjh; +aaqji; +aaqjj; +aaqjk; +aaqjl; +aaqjm; +aaqjn; +aaqjo; +aaqjp; +aaqjq; +aaqjr; +aaqjs; +aaqjt; +aaqju; +aaqjv; +aaqjw; +aaqjx; +aaqjy; +aaqjz; +aaqka; +aaqkb; +aaqkc; +aaqkd; +aaqke; +aaqkf; +aaqkg; +aaqkh; +aaqki; +aaqkj; +aaqkk; +aaqkl; +aaqkm; +aaqkn; +aaqko; +aaqkp; +aaqkq; +aaqkr; +aaqks; +aaqkt; +aaqku; +aaqkv; +aaqkw; +aaqkx; +aaqky; +aaqkz; +aaqla; +aaqlb; +aaqlc; +aaqld; +aaqle; +aaqlf; +aaqlg; +aaqlh; +aaqli; +aaqlj; +aaqlk; +aaqll; +aaqlm; +aaqln; +aaqlo; +aaqlp; +aaqlq; +aaqlr; +aaqls; +aaqlt; +aaqlu; +aaqlv; +aaqlw; +aaqlx; +aaqly; +aaqlz; +aaqma; +aaqmb; +aaqmc; +aaqmd; +aaqme; +aaqmf; +aaqmg; +aaqmh; +aaqmi; +aaqmj; +aaqmk; +aaqml; +aaqmm; +aaqmn; +aaqmo; +aaqmp; +aaqmq; +aaqmr; +aaqms; +aaqmt; +aaqmu; +aaqmv; +aaqmw; +aaqmx; +aaqmy; +aaqmz; +aaqna; +aaqnb; +aaqnc; +aaqnd; +aaqne; +aaqnf; +aaqng; +aaqnh; +aaqni; +aaqnj; +aaqnk; +aaqnl; +aaqnm; +aaqnn; +aaqno; +aaqnp; +aaqnq; +aaqnr; +aaqns; +aaqnt; +aaqnu; +aaqnv; +aaqnw; +aaqnx; +aaqny; +aaqnz; +aaqoa; +aaqob; +aaqoc; +aaqod; +aaqoe; +aaqof; +aaqog; +aaqoh; +aaqoi; +aaqoj; +aaqok; +aaqol; +aaqom; +aaqon; +aaqoo; +aaqop; +aaqoq; +aaqor; +aaqos; +aaqot; +aaqou; +aaqov; +aaqow; +aaqox; +aaqoy; +aaqoz; +aaqpa; +aaqpb; +aaqpc; +aaqpd; +aaqpe; +aaqpf; +aaqpg; +aaqph; +aaqpi; +aaqpj; +aaqpk; +aaqpl; +aaqpm; +aaqpn; +aaqpo; +aaqpp; +aaqpq; +aaqpr; +aaqps; +aaqpt; +aaqpu; +aaqpv; +aaqpw; +aaqpx; +aaqpy; +aaqpz; +aaqqa; +aaqqb; +aaqqc; +aaqqd; +aaqqe; +aaqqf; +aaqqg; +aaqqh; +aaqqi; +aaqqj; +aaqqk; +aaqql; +aaqqm; +aaqqn; +aaqqo; +aaqqp; +aaqqq; +aaqqr; +aaqqs; +aaqqt; +aaqqu; +aaqqv; +aaqqw; +aaqqx; +aaqqy; +aaqqz; +aaqra; +aaqrb; +aaqrc; +aaqrd; +aaqre; +aaqrf; +aaqrg; +aaqrh; +aaqri; +aaqrj; +aaqrk; +aaqrl; +aaqrm; +aaqrn; +aaqro; +aaqrp; +aaqrq; +aaqrr; +aaqrs; +aaqrt; +aaqru; +aaqrv; +aaqrw; +aaqrx; +aaqry; +aaqrz; +aaqsa; +aaqsb; +aaqsc; +aaqsd; +aaqse; +aaqsf; +aaqsg; +aaqsh; +aaqsi; +aaqsj; +aaqsk; +aaqsl; +aaqsm; +aaqsn; +aaqso; +aaqsp; +aaqsq; +aaqsr; +aaqss; +aaqst; +aaqsu; +aaqsv; +aaqsw; +aaqsx; +aaqsy; +aaqsz; +aaqta; +aaqtb; +aaqtc; +aaqtd; +aaqte; +aaqtf; +aaqtg; +aaqth; +aaqti; +aaqtj; +aaqtk; +aaqtl; +aaqtm; +aaqtn; +aaqto; +aaqtp; +aaqtq; +aaqtr; +aaqts; +aaqtt; +aaqtu; +aaqtv; +aaqtw; +aaqtx; +aaqty; +aaqtz; +aaqua; +aaqub; +aaquc; +aaqud; +aaque; +aaquf; +aaqug; +aaquh; +aaqui; +aaquj; +aaquk; +aaqul; +aaqum; +aaqun; +aaquo; +aaqup; +aaquq; +aaqur; +aaqus; +aaqut; +aaquu; +aaquv; +aaquw; +aaqux; +aaquy; +aaquz; +aaqva; +aaqvb; +aaqvc; +aaqvd; +aaqve; +aaqvf; +aaqvg; +aaqvh; +aaqvi; +aaqvj; +aaqvk; +aaqvl; +aaqvm; +aaqvn; +aaqvo; +aaqvp; +aaqvq; +aaqvr; +aaqvs; +aaqvt; +aaqvu; +aaqvv; +aaqvw; +aaqvx; +aaqvy; +aaqvz; +aaqwa; +aaqwb; +aaqwc; +aaqwd; +aaqwe; +aaqwf; +aaqwg; +aaqwh; +aaqwi; +aaqwj; +aaqwk; +aaqwl; +aaqwm; +aaqwn; +aaqwo; +aaqwp; +aaqwq; +aaqwr; +aaqws; +aaqwt; +aaqwu; +aaqwv; +aaqww; +aaqwx; +aaqwy; +aaqwz; +aaqxa; +aaqxb; +aaqxc; +aaqxd; +aaqxe; +aaqxf; +aaqxg; +aaqxh; +aaqxi; +aaqxj; +aaqxk; +aaqxl; +aaqxm; +aaqxn; +aaqxo; +aaqxp; +aaqxq; +aaqxr; +aaqxs; +aaqxt; +aaqxu; +aaqxv; +aaqxw; +aaqxx; +aaqxy; +aaqxz; +aaqya; +aaqyb; +aaqyc; +aaqyd; +aaqye; +aaqyf; +aaqyg; +aaqyh; +aaqyi; +aaqyj; +aaqyk; +aaqyl; +aaqym; +aaqyn; +aaqyo; +aaqyp; +aaqyq; +aaqyr; +aaqys; +aaqyt; +aaqyu; +aaqyv; +aaqyw; +aaqyx; +aaqyy; +aaqyz; +aaqza; +aaqzb; +aaqzc; +aaqzd; +aaqze; +aaqzf; +aaqzg; +aaqzh; +aaqzi; +aaqzj; +aaqzk; +aaqzl; +aaqzm; +aaqzn; +aaqzo; +aaqzp; +aaqzq; +aaqzr; +aaqzs; +aaqzt; +aaqzu; +aaqzv; +aaqzw; +aaqzx; +aaqzy; +aaqzz; +aaraa; +aarab; +aarac; +aarad; +aarae; +aaraf; +aarag; +aarah; +aarai; +aaraj; +aarak; +aaral; +aaram; +aaran; +aarao; +aarap; +aaraq; +aarar; +aaras; +aarat; +aarau; +aarav; +aaraw; +aarax; +aaray; +aaraz; +aarba; +aarbb; +aarbc; +aarbd; +aarbe; +aarbf; +aarbg; +aarbh; +aarbi; +aarbj; +aarbk; +aarbl; +aarbm; +aarbn; +aarbo; +aarbp; +aarbq; +aarbr; +aarbs; +aarbt; +aarbu; +aarbv; +aarbw; +aarbx; +aarby; +aarbz; +aarca; +aarcb; +aarcc; +aarcd; +aarce; +aarcf; +aarcg; +aarch; +aarci; +aarcj; +aarck; +aarcl; +aarcm; +aarcn; +aarco; +aarcp; +aarcq; +aarcr; +aarcs; +aarct; +aarcu; +aarcv; +aarcw; +aarcx; +aarcy; +aarcz; +aarda; +aardb; +aardc; +aardd; +aarde; +aardf; +aardg; +aardh; +aardi; +aardj; +aardk; +aardl; +aardm; +aardn; +aardo; +aardp; +aardq; +aardr; +aards; +aardt; +aardu; +aardv; +aardw; +aardx; +aardy; +aardz; +aarea; +aareb; +aarec; +aared; +aaree; +aaref; +aareg; +aareh; +aarei; +aarej; +aarek; +aarel; +aarem; +aaren; +aareo; +aarep; +aareq; +aarer; +aares; +aaret; +aareu; +aarev; +aarew; +aarex; +aarey; +aarez; +aarfa; +aarfb; +aarfc; +aarfd; +aarfe; +aarff; +aarfg; +aarfh; +aarfi; +aarfj; +aarfk; +aarfl; +aarfm; +aarfn; +aarfo; +aarfp; +aarfq; +aarfr; +aarfs; +aarft; +aarfu; +aarfv; +aarfw; +aarfx; +aarfy; +aarfz; +aarga; +aargb; +aargc; +aargd; +aarge; +aargf; +aargg; +aargh; +aargi; +aargj; +aargk; +aargl; +aargm; +aargn; +aargo; +aargp; +aargq; +aargr; +aargs; +aargt; +aargu; +aargv; +aargw; +aargx; +aargy; +aargz; +aarha; +aarhb; +aarhc; +aarhd; +aarhe; +aarhf; +aarhg; +aarhh; +aarhi; +aarhj; +aarhk; +aarhl; +aarhm; +aarhn; +aarho; +aarhp; +aarhq; +aarhr; +aarhs; +aarht; +aarhu; +aarhv; +aarhw; +aarhx; +aarhy; +aarhz; +aaria; +aarib; +aaric; +aarid; +aarie; +aarif; +aarig; +aarih; +aarii; +aarij; +aarik; +aaril; +aarim; +aarin; +aario; +aarip; +aariq; +aarir; +aaris; +aarit; +aariu; +aariv; +aariw; +aarix; +aariy; +aariz; +aarja; +aarjb; +aarjc; +aarjd; +aarje; +aarjf; +aarjg; +aarjh; +aarji; +aarjj; +aarjk; +aarjl; +aarjm; +aarjn; +aarjo; +aarjp; +aarjq; +aarjr; +aarjs; +aarjt; +aarju; +aarjv; +aarjw; +aarjx; +aarjy; +aarjz; +aarka; +aarkb; +aarkc; +aarkd; +aarke; +aarkf; +aarkg; +aarkh; +aarki; +aarkj; +aarkk; +aarkl; +aarkm; +aarkn; +aarko; +aarkp; +aarkq; +aarkr; +aarks; +aarkt; +aarku; +aarkv; +aarkw; +aarkx; +aarky; +aarkz; +aarla; +aarlb; +aarlc; +aarld; +aarle; +aarlf; +aarlg; +aarlh; +aarli; +aarlj; +aarlk; +aarll; +aarlm; +aarln; +aarlo; +aarlp; +aarlq; +aarlr; +aarls; +aarlt; +aarlu; +aarlv; +aarlw; +aarlx; +aarly; +aarlz; +aarma; +aarmb; +aarmc; +aarmd; +aarme; +aarmf; +aarmg; +aarmh; +aarmi; +aarmj; +aarmk; +aarml; +aarmm; +aarmn; +aarmo; +aarmp; +aarmq; +aarmr; +aarms; +aarmt; +aarmu; +aarmv; +aarmw; +aarmx; +aarmy; +aarmz; +aarna; +aarnb; +aarnc; +aarnd; +aarne; +aarnf; +aarng; +aarnh; +aarni; +aarnj; +aarnk; +aarnl; +aarnm; +aarnn; +aarno; +aarnp; +aarnq; +aarnr; +aarns; +aarnt; +aarnu; +aarnv; +aarnw; +aarnx; +aarny; +aarnz; +aaroa; +aarob; +aaroc; +aarod; +aaroe; +aarof; +aarog; +aaroh; +aaroi; +aaroj; +aarok; +aarol; +aarom; +aaron; +aaroo; +aarop; +aaroq; +aaror; +aaros; +aarot; +aarou; +aarov; +aarow; +aarox; +aaroy; +aaroz; +aarpa; +aarpb; +aarpc; +aarpd; +aarpe; +aarpf; +aarpg; +aarph; +aarpi; +aarpj; +aarpk; +aarpl; +aarpm; +aarpn; +aarpo; +aarpp; +aarpq; +aarpr; +aarps; +aarpt; +aarpu; +aarpv; +aarpw; +aarpx; +aarpy; +aarpz; +aarqa; +aarqb; +aarqc; +aarqd; +aarqe; +aarqf; +aarqg; +aarqh; +aarqi; +aarqj; +aarqk; +aarql; +aarqm; +aarqn; +aarqo; +aarqp; +aarqq; +aarqr; +aarqs; +aarqt; +aarqu; +aarqv; +aarqw; +aarqx; +aarqy; +aarqz; +aarra; +aarrb; +aarrc; +aarrd; +aarre; +aarrf; +aarrg; +aarrh; +aarri; +aarrj; +aarrk; +aarrl; +aarrm; +aarrn; +aarro; +aarrp; +aarrq; +aarrr; +aarrs; +aarrt; +aarru; +aarrv; +aarrw; +aarrx; +aarry; +aarrz; +aarsa; +aarsb; +aarsc; +aarsd; +aarse; +aarsf; +aarsg; +aarsh; +aarsi; +aarsj; +aarsk; +aarsl; +aarsm; +aarsn; +aarso; +aarsp; +aarsq; +aarsr; +aarss; +aarst; +aarsu; +aarsv; +aarsw; +aarsx; +aarsy; +aarsz; +aarta; +aartb; +aartc; +aartd; +aarte; +aartf; +aartg; +aarth; +aarti; +aartj; +aartk; +aartl; +aartm; +aartn; +aarto; +aartp; +aartq; +aartr; +aarts; +aartt; +aartu; +aartv; +aartw; +aartx; +aarty; +aartz; +aarua; +aarub; +aaruc; +aarud; +aarue; +aaruf; +aarug; +aaruh; +aarui; +aaruj; +aaruk; +aarul; +aarum; +aarun; +aaruo; +aarup; +aaruq; +aarur; +aarus; +aarut; +aaruu; +aaruv; +aaruw; +aarux; +aaruy; +aaruz; +aarva; +aarvb; +aarvc; +aarvd; +aarve; +aarvf; +aarvg; +aarvh; +aarvi; +aarvj; +aarvk; +aarvl; +aarvm; +aarvn; +aarvo; +aarvp; +aarvq; +aarvr; +aarvs; +aarvt; +aarvu; +aarvv; +aarvw; +aarvx; +aarvy; +aarvz; +aarwa; +aarwb; +aarwc; +aarwd; +aarwe; +aarwf; +aarwg; +aarwh; +aarwi; +aarwj; +aarwk; +aarwl; +aarwm; +aarwn; +aarwo; +aarwp; +aarwq; +aarwr; +aarws; +aarwt; +aarwu; +aarwv; +aarww; +aarwx; +aarwy; +aarwz; +aarxa; +aarxb; +aarxc; +aarxd; +aarxe; +aarxf; +aarxg; +aarxh; +aarxi; +aarxj; +aarxk; +aarxl; +aarxm; +aarxn; +aarxo; +aarxp; +aarxq; +aarxr; +aarxs; +aarxt; +aarxu; +aarxv; +aarxw; +aarxx; +aarxy; +aarxz; +aarya; +aaryb; +aaryc; +aaryd; +aarye; +aaryf; +aaryg; +aaryh; +aaryi; +aaryj; +aaryk; +aaryl; +aarym; +aaryn; +aaryo; +aaryp; +aaryq; +aaryr; +aarys; +aaryt; +aaryu; +aaryv; +aaryw; +aaryx; +aaryy; +aaryz; +aarza; +aarzb; +aarzc; +aarzd; +aarze; +aarzf; +aarzg; +aarzh; +aarzi; +aarzj; +aarzk; +aarzl; +aarzm; +aarzn; +aarzo; +aarzp; +aarzq; +aarzr; +aarzs; +aarzt; +aarzu; +aarzv; +aarzw; +aarzx; +aarzy; +aarzz; +aasaa; +aasab; +aasac; +aasad; +aasae; +aasaf; +aasag; +aasah; +aasai; +aasaj; +aasak; +aasal; +aasam; +aasan; +aasao; +aasap; +aasaq; +aasar; +aasas; +aasat; +aasau; +aasav; +aasaw; +aasax; +aasay; +aasaz; +aasba; +aasbb; +aasbc; +aasbd; +aasbe; +aasbf; +aasbg; +aasbh; +aasbi; +aasbj; +aasbk; +aasbl; +aasbm; +aasbn; +aasbo; +aasbp; +aasbq; +aasbr; +aasbs; +aasbt; +aasbu; +aasbv; +aasbw; +aasbx; +aasby; +aasbz; +aasca; +aascb; +aascc; +aascd; +aasce; +aascf; +aascg; +aasch; +aasci; +aascj; +aasck; +aascl; +aascm; +aascn; +aasco; +aascp; +aascq; +aascr; +aascs; +aasct; +aascu; +aascv; +aascw; +aascx; +aascy; +aascz; +aasda; +aasdb; +aasdc; +aasdd; +aasde; +aasdf; +aasdg; +aasdh; +aasdi; +aasdj; +aasdk; +aasdl; +aasdm; +aasdn; +aasdo; +aasdp; +aasdq; +aasdr; +aasds; +aasdt; +aasdu; +aasdv; +aasdw; +aasdx; +aasdy; +aasdz; +aasea; +aaseb; +aasec; +aased; +aasee; +aasef; +aaseg; +aaseh; +aasei; +aasej; +aasek; +aasel; +aasem; +aasen; +aaseo; +aasep; +aaseq; +aaser; +aases; +aaset; +aaseu; +aasev; +aasew; +aasex; +aasey; +aasez; +aasfa; +aasfb; +aasfc; +aasfd; +aasfe; +aasff; +aasfg; +aasfh; +aasfi; +aasfj; +aasfk; +aasfl; +aasfm; +aasfn; +aasfo; +aasfp; +aasfq; +aasfr; +aasfs; +aasft; +aasfu; +aasfv; +aasfw; +aasfx; +aasfy; +aasfz; +aasga; +aasgb; +aasgc; +aasgd; +aasge; +aasgf; +aasgg; +aasgh; +aasgi; +aasgj; +aasgk; +aasgl; +aasgm; +aasgn; +aasgo; +aasgp; +aasgq; +aasgr; +aasgs; +aasgt; +aasgu; +aasgv; +aasgw; +aasgx; +aasgy; +aasgz; +aasha; +aashb; +aashc; +aashd; +aashe; +aashf; +aashg; +aashh; +aashi; +aashj; +aashk; +aashl; +aashm; +aashn; +aasho; +aashp; +aashq; +aashr; +aashs; +aasht; +aashu; +aashv; +aashw; +aashx; +aashy; +aashz; +aasia; +aasib; +aasic; +aasid; +aasie; +aasif; +aasig; +aasih; +aasii; +aasij; +aasik; +aasil; +aasim; +aasin; +aasio; +aasip; +aasiq; +aasir; +aasis; +aasit; +aasiu; +aasiv; +aasiw; +aasix; +aasiy; +aasiz; +aasja; +aasjb; +aasjc; +aasjd; +aasje; +aasjf; +aasjg; +aasjh; +aasji; +aasjj; +aasjk; +aasjl; +aasjm; +aasjn; +aasjo; +aasjp; +aasjq; +aasjr; +aasjs; +aasjt; +aasju; +aasjv; +aasjw; +aasjx; +aasjy; +aasjz; +aaska; +aaskb; +aaskc; +aaskd; +aaske; +aaskf; +aaskg; +aaskh; +aaski; +aaskj; +aaskk; +aaskl; +aaskm; +aaskn; +aasko; +aaskp; +aaskq; +aaskr; +aasks; +aaskt; +aasku; +aaskv; +aaskw; +aaskx; +aasky; +aaskz; +aasla; +aaslb; +aaslc; +aasld; +aasle; +aaslf; +aaslg; +aaslh; +aasli; +aaslj; +aaslk; +aasll; +aaslm; +aasln; +aaslo; +aaslp; +aaslq; +aaslr; +aasls; +aaslt; +aaslu; +aaslv; +aaslw; +aaslx; +aasly; +aaslz; +aasma; +aasmb; +aasmc; +aasmd; +aasme; +aasmf; +aasmg; +aasmh; +aasmi; +aasmj; +aasmk; +aasml; +aasmm; +aasmn; +aasmo; +aasmp; +aasmq; +aasmr; +aasms; +aasmt; +aasmu; +aasmv; +aasmw; +aasmx; +aasmy; +aasmz; +aasna; +aasnb; +aasnc; +aasnd; +aasne; +aasnf; +aasng; +aasnh; +aasni; +aasnj; +aasnk; +aasnl; +aasnm; +aasnn; +aasno; +aasnp; +aasnq; +aasnr; +aasns; +aasnt; +aasnu; +aasnv; +aasnw; +aasnx; +aasny; +aasnz; +aasoa; +aasob; +aasoc; +aasod; +aasoe; +aasof; +aasog; +aasoh; +aasoi; +aasoj; +aasok; +aasol; +aasom; +aason; +aasoo; +aasop; +aasoq; +aasor; +aasos; +aasot; +aasou; +aasov; +aasow; +aasox; +aasoy; +aasoz; +aaspa; +aaspb; +aaspc; +aaspd; +aaspe; +aaspf; +aaspg; +aasph; +aaspi; +aaspj; +aaspk; +aaspl; +aaspm; +aaspn; +aaspo; +aaspp; +aaspq; +aaspr; +aasps; +aaspt; +aaspu; +aaspv; +aaspw; +aaspx; +aaspy; +aaspz; +aasqa; +aasqb; +aasqc; +aasqd; +aasqe; +aasqf; +aasqg; +aasqh; +aasqi; +aasqj; +aasqk; +aasql; +aasqm; +aasqn; +aasqo; +aasqp; +aasqq; +aasqr; +aasqs; +aasqt; +aasqu; +aasqv; +aasqw; +aasqx; +aasqy; +aasqz; +aasra; +aasrb; +aasrc; +aasrd; +aasre; +aasrf; +aasrg; +aasrh; +aasri; +aasrj; +aasrk; +aasrl; +aasrm; +aasrn; +aasro; +aasrp; +aasrq; +aasrr; +aasrs; +aasrt; +aasru; +aasrv; +aasrw; +aasrx; +aasry; +aasrz; +aassa; +aassb; +aassc; +aassd; +aasse; +aassf; +aassg; +aassh; +aassi; +aassj; +aassk; +aassl; +aassm; +aassn; +aasso; +aassp; +aassq; +aassr; +aasss; +aasst; +aassu; +aassv; +aassw; +aassx; +aassy; +aassz; +aasta; +aastb; +aastc; +aastd; +aaste; +aastf; +aastg; +aasth; +aasti; +aastj; +aastk; +aastl; +aastm; +aastn; +aasto; +aastp; +aastq; +aastr; +aasts; +aastt; +aastu; +aastv; +aastw; +aastx; +aasty; +aastz; +aasua; +aasub; +aasuc; +aasud; +aasue; +aasuf; +aasug; +aasuh; +aasui; +aasuj; +aasuk; +aasul; +aasum; +aasun; +aasuo; +aasup; +aasuq; +aasur; +aasus; +aasut; +aasuu; +aasuv; +aasuw; +aasux; +aasuy; +aasuz; +aasva; +aasvb; +aasvc; +aasvd; +aasve; +aasvf; +aasvg; +aasvh; +aasvi; +aasvj; +aasvk; +aasvl; +aasvm; +aasvn; +aasvo; +aasvp; +aasvq; +aasvr; +aasvs; +aasvt; +aasvu; +aasvv; +aasvw; +aasvx; +aasvy; +aasvz; +aaswa; +aaswb; +aaswc; +aaswd; +aaswe; +aaswf; +aaswg; +aaswh; +aaswi; +aaswj; +aaswk; +aaswl; +aaswm; +aaswn; +aaswo; +aaswp; +aaswq; +aaswr; +aasws; +aaswt; +aaswu; +aaswv; +aasww; +aaswx; +aaswy; +aaswz; +aasxa; +aasxb; +aasxc; +aasxd; +aasxe; +aasxf; +aasxg; +aasxh; +aasxi; +aasxj; +aasxk; +aasxl; +aasxm; +aasxn; +aasxo; +aasxp; +aasxq; +aasxr; +aasxs; +aasxt; +aasxu; +aasxv; +aasxw; +aasxx; +aasxy; +aasxz; +aasya; +aasyb; +aasyc; +aasyd; +aasye; +aasyf; +aasyg; +aasyh; +aasyi; +aasyj; +aasyk; +aasyl; +aasym; +aasyn; +aasyo; +aasyp; +aasyq; +aasyr; +aasys; +aasyt; +aasyu; +aasyv; +aasyw; +aasyx; +aasyy; +aasyz; +aasza; +aaszb; +aaszc; +aaszd; +aasze; +aaszf; +aaszg; +aaszh; +aaszi; +aaszj; +aaszk; +aaszl; +aaszm; +aaszn; +aaszo; +aaszp; +aaszq; +aaszr; +aaszs; +aaszt; +aaszu; +aaszv; +aaszw; +aaszx; +aaszy; +aaszz; +aataa; +aatab; +aatac; +aatad; +aatae; +aataf; +aatag; +aatah; +aatai; +aataj; +aatak; +aatal; +aatam; +aatan; +aatao; +aatap; +aataq; +aatar; +aatas; +aatat; +aatau; +aatav; +aataw; +aatax; +aatay; +aataz; +aatba; +aatbb; +aatbc; +aatbd; +aatbe; +aatbf; +aatbg; +aatbh; +aatbi; +aatbj; +aatbk; +aatbl; +aatbm; +aatbn; +aatbo; +aatbp; +aatbq; +aatbr; +aatbs; +aatbt; +aatbu; +aatbv; +aatbw; +aatbx; +aatby; +aatbz; +aatca; +aatcb; +aatcc; +aatcd; +aatce; +aatcf; +aatcg; +aatch; +aatci; +aatcj; +aatck; +aatcl; +aatcm; +aatcn; +aatco; +aatcp; +aatcq; +aatcr; +aatcs; +aatct; +aatcu; +aatcv; +aatcw; +aatcx; +aatcy; +aatcz; +aatda; +aatdb; +aatdc; +aatdd; +aatde; +aatdf; +aatdg; +aatdh; +aatdi; +aatdj; +aatdk; +aatdl; +aatdm; +aatdn; +aatdo; +aatdp; +aatdq; +aatdr; +aatds; +aatdt; +aatdu; +aatdv; +aatdw; +aatdx; +aatdy; +aatdz; +aatea; +aateb; +aatec; +aated; +aatee; +aatef; +aateg; +aateh; +aatei; +aatej; +aatek; +aatel; +aatem; +aaten; +aateo; +aatep; +aateq; +aater; +aates; +aatet; +aateu; +aatev; +aatew; +aatex; +aatey; +aatez; +aatfa; +aatfb; +aatfc; +aatfd; +aatfe; +aatff; +aatfg; +aatfh; +aatfi; +aatfj; +aatfk; +aatfl; +aatfm; +aatfn; +aatfo; +aatfp; +aatfq; +aatfr; +aatfs; +aatft; +aatfu; +aatfv; +aatfw; +aatfx; +aatfy; +aatfz; +aatga; +aatgb; +aatgc; +aatgd; +aatge; +aatgf; +aatgg; +aatgh; +aatgi; +aatgj; +aatgk; +aatgl; +aatgm; +aatgn; +aatgo; +aatgp; +aatgq; +aatgr; +aatgs; +aatgt; +aatgu; +aatgv; +aatgw; +aatgx; +aatgy; +aatgz; +aatha; +aathb; +aathc; +aathd; +aathe; +aathf; +aathg; +aathh; +aathi; +aathj; +aathk; +aathl; +aathm; +aathn; +aatho; +aathp; +aathq; +aathr; +aaths; +aatht; +aathu; +aathv; +aathw; +aathx; +aathy; +aathz; +aatia; +aatib; +aatic; +aatid; +aatie; +aatif; +aatig; +aatih; +aatii; +aatij; +aatik; +aatil; +aatim; +aatin; +aatio; +aatip; +aatiq; +aatir; +aatis; +aatit; +aatiu; +aativ; +aatiw; +aatix; +aatiy; +aatiz; +aatja; +aatjb; +aatjc; +aatjd; +aatje; +aatjf; +aatjg; +aatjh; +aatji; +aatjj; +aatjk; +aatjl; +aatjm; +aatjn; +aatjo; +aatjp; +aatjq; +aatjr; +aatjs; +aatjt; +aatju; +aatjv; +aatjw; +aatjx; +aatjy; +aatjz; +aatka; +aatkb; +aatkc; +aatkd; +aatke; +aatkf; +aatkg; +aatkh; +aatki; +aatkj; +aatkk; +aatkl; +aatkm; +aatkn; +aatko; +aatkp; +aatkq; +aatkr; +aatks; +aatkt; +aatku; +aatkv; +aatkw; +aatkx; +aatky; +aatkz; +aatla; +aatlb; +aatlc; +aatld; +aatle; +aatlf; +aatlg; +aatlh; +aatli; +aatlj; +aatlk; +aatll; +aatlm; +aatln; +aatlo; +aatlp; +aatlq; +aatlr; +aatls; +aatlt; +aatlu; +aatlv; +aatlw; +aatlx; +aatly; +aatlz; +aatma; +aatmb; +aatmc; +aatmd; +aatme; +aatmf; +aatmg; +aatmh; +aatmi; +aatmj; +aatmk; +aatml; +aatmm; +aatmn; +aatmo; +aatmp; +aatmq; +aatmr; +aatms; +aatmt; +aatmu; +aatmv; +aatmw; +aatmx; +aatmy; +aatmz; +aatna; +aatnb; +aatnc; +aatnd; +aatne; +aatnf; +aatng; +aatnh; +aatni; +aatnj; +aatnk; +aatnl; +aatnm; +aatnn; +aatno; +aatnp; +aatnq; +aatnr; +aatns; +aatnt; +aatnu; +aatnv; +aatnw; +aatnx; +aatny; +aatnz; +aatoa; +aatob; +aatoc; +aatod; +aatoe; +aatof; +aatog; +aatoh; +aatoi; +aatoj; +aatok; +aatol; +aatom; +aaton; +aatoo; +aatop; +aatoq; +aator; +aatos; +aatot; +aatou; +aatov; +aatow; +aatox; +aatoy; +aatoz; +aatpa; +aatpb; +aatpc; +aatpd; +aatpe; +aatpf; +aatpg; +aatph; +aatpi; +aatpj; +aatpk; +aatpl; +aatpm; +aatpn; +aatpo; +aatpp; +aatpq; +aatpr; +aatps; +aatpt; +aatpu; +aatpv; +aatpw; +aatpx; +aatpy; +aatpz; +aatqa; +aatqb; +aatqc; +aatqd; +aatqe; +aatqf; +aatqg; +aatqh; +aatqi; +aatqj; +aatqk; +aatql; +aatqm; +aatqn; +aatqo; +aatqp; +aatqq; +aatqr; +aatqs; +aatqt; +aatqu; +aatqv; +aatqw; +aatqx; +aatqy; +aatqz; +aatra; +aatrb; +aatrc; +aatrd; +aatre; +aatrf; +aatrg; +aatrh; +aatri; +aatrj; +aatrk; +aatrl; +aatrm; +aatrn; +aatro; +aatrp; +aatrq; +aatrr; +aatrs; +aatrt; +aatru; +aatrv; +aatrw; +aatrx; +aatry; +aatrz; +aatsa; +aatsb; +aatsc; +aatsd; +aatse; +aatsf; +aatsg; +aatsh; +aatsi; +aatsj; +aatsk; +aatsl; +aatsm; +aatsn; +aatso; +aatsp; +aatsq; +aatsr; +aatss; +aatst; +aatsu; +aatsv; +aatsw; +aatsx; +aatsy; +aatsz; +aatta; +aattb; +aattc; +aattd; +aatte; +aattf; +aattg; +aatth; +aatti; +aattj; +aattk; +aattl; +aattm; +aattn; +aatto; +aattp; +aattq; +aattr; +aatts; +aattt; +aattu; +aattv; +aattw; +aattx; +aatty; +aattz; +aatua; +aatub; +aatuc; +aatud; +aatue; +aatuf; +aatug; +aatuh; +aatui; +aatuj; +aatuk; +aatul; +aatum; +aatun; +aatuo; +aatup; +aatuq; +aatur; +aatus; +aatut; +aatuu; +aatuv; +aatuw; +aatux; +aatuy; +aatuz; +aatva; +aatvb; +aatvc; +aatvd; +aatve; +aatvf; +aatvg; +aatvh; +aatvi; +aatvj; +aatvk; +aatvl; +aatvm; +aatvn; +aatvo; +aatvp; +aatvq; +aatvr; +aatvs; +aatvt; +aatvu; +aatvv; +aatvw; +aatvx; +aatvy; +aatvz; +aatwa; +aatwb; +aatwc; +aatwd; +aatwe; +aatwf; +aatwg; +aatwh; +aatwi; +aatwj; +aatwk; +aatwl; +aatwm; +aatwn; +aatwo; +aatwp; +aatwq; +aatwr; +aatws; +aatwt; +aatwu; +aatwv; +aatww; +aatwx; +aatwy; +aatwz; +aatxa; +aatxb; +aatxc; +aatxd; +aatxe; +aatxf; +aatxg; +aatxh; +aatxi; +aatxj; +aatxk; +aatxl; +aatxm; +aatxn; +aatxo; +aatxp; +aatxq; +aatxr; +aatxs; +aatxt; +aatxu; +aatxv; +aatxw; +aatxx; +aatxy; +aatxz; +aatya; +aatyb; +aatyc; +aatyd; +aatye; +aatyf; +aatyg; +aatyh; +aatyi; +aatyj; +aatyk; +aatyl; +aatym; +aatyn; +aatyo; +aatyp; +aatyq; +aatyr; +aatys; +aatyt; +aatyu; +aatyv; +aatyw; +aatyx; +aatyy; +aatyz; +aatza; +aatzb; +aatzc; +aatzd; +aatze; +aatzf; +aatzg; +aatzh; +aatzi; +aatzj; +aatzk; +aatzl; +aatzm; +aatzn; +aatzo; +aatzp; +aatzq; +aatzr; +aatzs; +aatzt; +aatzu; +aatzv; +aatzw; +aatzx; +aatzy; +aatzz; +aauaa; +aauab; +aauac; +aauad; +aauae; +aauaf; +aauag; +aauah; +aauai; +aauaj; +aauak; +aaual; +aauam; +aauan; +aauao; +aauap; +aauaq; +aauar; +aauas; +aauat; +aauau; +aauav; +aauaw; +aauax; +aauay; +aauaz; +aauba; +aaubb; +aaubc; +aaubd; +aaube; +aaubf; +aaubg; +aaubh; +aaubi; +aaubj; +aaubk; +aaubl; +aaubm; +aaubn; +aaubo; +aaubp; +aaubq; +aaubr; +aaubs; +aaubt; +aaubu; +aaubv; +aaubw; +aaubx; +aauby; +aaubz; +aauca; +aaucb; +aaucc; +aaucd; +aauce; +aaucf; +aaucg; +aauch; +aauci; +aaucj; +aauck; +aaucl; +aaucm; +aaucn; +aauco; +aaucp; +aaucq; +aaucr; +aaucs; +aauct; +aaucu; +aaucv; +aaucw; +aaucx; +aaucy; +aaucz; +aauda; +aaudb; +aaudc; +aaudd; +aaude; +aaudf; +aaudg; +aaudh; +aaudi; +aaudj; +aaudk; +aaudl; +aaudm; +aaudn; +aaudo; +aaudp; +aaudq; +aaudr; +aauds; +aaudt; +aaudu; +aaudv; +aaudw; +aaudx; +aaudy; +aaudz; +aauea; +aaueb; +aauec; +aaued; +aauee; +aauef; +aaueg; +aaueh; +aauei; +aauej; +aauek; +aauel; +aauem; +aauen; +aaueo; +aauep; +aaueq; +aauer; +aaues; +aauet; +aaueu; +aauev; +aauew; +aauex; +aauey; +aauez; +aaufa; +aaufb; +aaufc; +aaufd; +aaufe; +aauff; +aaufg; +aaufh; +aaufi; +aaufj; +aaufk; +aaufl; +aaufm; +aaufn; +aaufo; +aaufp; +aaufq; +aaufr; +aaufs; +aauft; +aaufu; +aaufv; +aaufw; +aaufx; +aaufy; +aaufz; +aauga; +aaugb; +aaugc; +aaugd; +aauge; +aaugf; +aaugg; +aaugh; +aaugi; +aaugj; +aaugk; +aaugl; +aaugm; +aaugn; +aaugo; +aaugp; +aaugq; +aaugr; +aaugs; +aaugt; +aaugu; +aaugv; +aaugw; +aaugx; +aaugy; +aaugz; +aauha; +aauhb; +aauhc; +aauhd; +aauhe; +aauhf; +aauhg; +aauhh; +aauhi; +aauhj; +aauhk; +aauhl; +aauhm; +aauhn; +aauho; +aauhp; +aauhq; +aauhr; +aauhs; +aauht; +aauhu; +aauhv; +aauhw; +aauhx; +aauhy; +aauhz; +aauia; +aauib; +aauic; +aauid; +aauie; +aauif; +aauig; +aauih; +aauii; +aauij; +aauik; +aauil; +aauim; +aauin; +aauio; +aauip; +aauiq; +aauir; +aauis; +aauit; +aauiu; +aauiv; +aauiw; +aauix; +aauiy; +aauiz; +aauja; +aaujb; +aaujc; +aaujd; +aauje; +aaujf; +aaujg; +aaujh; +aauji; +aaujj; +aaujk; +aaujl; +aaujm; +aaujn; +aaujo; +aaujp; +aaujq; +aaujr; +aaujs; +aaujt; +aauju; +aaujv; +aaujw; +aaujx; +aaujy; +aaujz; +aauka; +aaukb; +aaukc; +aaukd; +aauke; +aaukf; +aaukg; +aaukh; +aauki; +aaukj; +aaukk; +aaukl; +aaukm; +aaukn; +aauko; +aaukp; +aaukq; +aaukr; +aauks; +aaukt; +aauku; +aaukv; +aaukw; +aaukx; +aauky; +aaukz; +aaula; +aaulb; +aaulc; +aauld; +aaule; +aaulf; +aaulg; +aaulh; +aauli; +aaulj; +aaulk; +aaull; +aaulm; +aauln; +aaulo; +aaulp; +aaulq; +aaulr; +aauls; +aault; +aaulu; +aaulv; +aaulw; +aaulx; +aauly; +aaulz; +aauma; +aaumb; +aaumc; +aaumd; +aaume; +aaumf; +aaumg; +aaumh; +aaumi; +aaumj; +aaumk; +aauml; +aaumm; +aaumn; +aaumo; +aaump; +aaumq; +aaumr; +aaums; +aaumt; +aaumu; +aaumv; +aaumw; +aaumx; +aaumy; +aaumz; +aauna; +aaunb; +aaunc; +aaund; +aaune; +aaunf; +aaung; +aaunh; +aauni; +aaunj; +aaunk; +aaunl; +aaunm; +aaunn; +aauno; +aaunp; +aaunq; +aaunr; +aauns; +aaunt; +aaunu; +aaunv; +aaunw; +aaunx; +aauny; +aaunz; +aauoa; +aauob; +aauoc; +aauod; +aauoe; +aauof; +aauog; +aauoh; +aauoi; +aauoj; +aauok; +aauol; +aauom; +aauon; +aauoo; +aauop; +aauoq; +aauor; +aauos; +aauot; +aauou; +aauov; +aauow; +aauox; +aauoy; +aauoz; +aaupa; +aaupb; +aaupc; +aaupd; +aaupe; +aaupf; +aaupg; +aauph; +aaupi; +aaupj; +aaupk; +aaupl; +aaupm; +aaupn; +aaupo; +aaupp; +aaupq; +aaupr; +aaups; +aaupt; +aaupu; +aaupv; +aaupw; +aaupx; +aaupy; +aaupz; +aauqa; +aauqb; +aauqc; +aauqd; +aauqe; +aauqf; +aauqg; +aauqh; +aauqi; +aauqj; +aauqk; +aauql; +aauqm; +aauqn; +aauqo; +aauqp; +aauqq; +aauqr; +aauqs; +aauqt; +aauqu; +aauqv; +aauqw; +aauqx; +aauqy; +aauqz; +aaura; +aaurb; +aaurc; +aaurd; +aaure; +aaurf; +aaurg; +aaurh; +aauri; +aaurj; +aaurk; +aaurl; +aaurm; +aaurn; +aauro; +aaurp; +aaurq; +aaurr; +aaurs; +aaurt; +aauru; +aaurv; +aaurw; +aaurx; +aaury; +aaurz; +aausa; +aausb; +aausc; +aausd; +aause; +aausf; +aausg; +aaush; +aausi; +aausj; +aausk; +aausl; +aausm; +aausn; +aauso; +aausp; +aausq; +aausr; +aauss; +aaust; +aausu; +aausv; +aausw; +aausx; +aausy; +aausz; +aauta; +aautb; +aautc; +aautd; +aaute; +aautf; +aautg; +aauth; +aauti; +aautj; +aautk; +aautl; +aautm; +aautn; +aauto; +aautp; +aautq; +aautr; +aauts; +aautt; +aautu; +aautv; +aautw; +aautx; +aauty; +aautz; +aauua; +aauub; +aauuc; +aauud; +aauue; +aauuf; +aauug; +aauuh; +aauui; +aauuj; +aauuk; +aauul; +aauum; +aauun; +aauuo; +aauup; +aauuq; +aauur; +aauus; +aauut; +aauuu; +aauuv; +aauuw; +aauux; +aauuy; +aauuz; +aauva; +aauvb; +aauvc; +aauvd; +aauve; +aauvf; +aauvg; +aauvh; +aauvi; +aauvj; +aauvk; +aauvl; +aauvm; +aauvn; +aauvo; +aauvp; +aauvq; +aauvr; +aauvs; +aauvt; +aauvu; +aauvv; +aauvw; +aauvx; +aauvy; +aauvz; +aauwa; +aauwb; +aauwc; +aauwd; +aauwe; +aauwf; +aauwg; +aauwh; +aauwi; +aauwj; +aauwk; +aauwl; +aauwm; +aauwn; +aauwo; +aauwp; +aauwq; +aauwr; +aauws; +aauwt; +aauwu; +aauwv; +aauww; +aauwx; +aauwy; +aauwz; +aauxa; +aauxb; +aauxc; +aauxd; +aauxe; +aauxf; +aauxg; +aauxh; +aauxi; +aauxj; +aauxk; +aauxl; +aauxm; +aauxn; +aauxo; +aauxp; +aauxq; +aauxr; +aauxs; +aauxt; +aauxu; +aauxv; +aauxw; +aauxx; +aauxy; +aauxz; +aauya; +aauyb; +aauyc; +aauyd; +aauye; +aauyf; +aauyg; +aauyh; +aauyi; +aauyj; +aauyk; +aauyl; +aauym; +aauyn; +aauyo; +aauyp; +aauyq; +aauyr; +aauys; +aauyt; +aauyu; +aauyv; +aauyw; +aauyx; +aauyy; +aauyz; +aauza; +aauzb; +aauzc; +aauzd; +aauze; +aauzf; +aauzg; +aauzh; +aauzi; +aauzj; +aauzk; +aauzl; +aauzm; +aauzn; +aauzo; +aauzp; +aauzq; +aauzr; +aauzs; +aauzt; +aauzu; +aauzv; +aauzw; +aauzx; +aauzy; +aauzz; +aavaa; +aavab; +aavac; +aavad; +aavae; +aavaf; +aavag; +aavah; +aavai; +aavaj; +aavak; +aaval; +aavam; +aavan; +aavao; +aavap; +aavaq; +aavar; +aavas; +aavat; +aavau; +aavav; +aavaw; +aavax; +aavay; +aavaz; +aavba; +aavbb; +aavbc; +aavbd; +aavbe; +aavbf; +aavbg; +aavbh; +aavbi; +aavbj; +aavbk; +aavbl; +aavbm; +aavbn; +aavbo; +aavbp; +aavbq; +aavbr; +aavbs; +aavbt; +aavbu; +aavbv; +aavbw; +aavbx; +aavby; +aavbz; +aavca; +aavcb; +aavcc; +aavcd; +aavce; +aavcf; +aavcg; +aavch; +aavci; +aavcj; +aavck; +aavcl; +aavcm; +aavcn; +aavco; +aavcp; +aavcq; +aavcr; +aavcs; +aavct; +aavcu; +aavcv; +aavcw; +aavcx; +aavcy; +aavcz; +aavda; +aavdb; +aavdc; +aavdd; +aavde; +aavdf; +aavdg; +aavdh; +aavdi; +aavdj; +aavdk; +aavdl; +aavdm; +aavdn; +aavdo; +aavdp; +aavdq; +aavdr; +aavds; +aavdt; +aavdu; +aavdv; +aavdw; +aavdx; +aavdy; +aavdz; +aavea; +aaveb; +aavec; +aaved; +aavee; +aavef; +aaveg; +aaveh; +aavei; +aavej; +aavek; +aavel; +aavem; +aaven; +aaveo; +aavep; +aaveq; +aaver; +aaves; +aavet; +aaveu; +aavev; +aavew; +aavex; +aavey; +aavez; +aavfa; +aavfb; +aavfc; +aavfd; +aavfe; +aavff; +aavfg; +aavfh; +aavfi; +aavfj; +aavfk; +aavfl; +aavfm; +aavfn; +aavfo; +aavfp; +aavfq; +aavfr; +aavfs; +aavft; +aavfu; +aavfv; +aavfw; +aavfx; +aavfy; +aavfz; +aavga; +aavgb; +aavgc; +aavgd; +aavge; +aavgf; +aavgg; +aavgh; +aavgi; +aavgj; +aavgk; +aavgl; +aavgm; +aavgn; +aavgo; +aavgp; +aavgq; +aavgr; +aavgs; +aavgt; +aavgu; +aavgv; +aavgw; +aavgx; +aavgy; +aavgz; +aavha; +aavhb; +aavhc; +aavhd; +aavhe; +aavhf; +aavhg; +aavhh; +aavhi; +aavhj; +aavhk; +aavhl; +aavhm; +aavhn; +aavho; +aavhp; +aavhq; +aavhr; +aavhs; +aavht; +aavhu; +aavhv; +aavhw; +aavhx; +aavhy; +aavhz; +aavia; +aavib; +aavic; +aavid; +aavie; +aavif; +aavig; +aavih; +aavii; +aavij; +aavik; +aavil; +aavim; +aavin; +aavio; +aavip; +aaviq; +aavir; +aavis; +aavit; +aaviu; +aaviv; +aaviw; +aavix; +aaviy; +aaviz; +aavja; +aavjb; +aavjc; +aavjd; +aavje; +aavjf; +aavjg; +aavjh; +aavji; +aavjj; +aavjk; +aavjl; +aavjm; +aavjn; +aavjo; +aavjp; +aavjq; +aavjr; +aavjs; +aavjt; +aavju; +aavjv; +aavjw; +aavjx; +aavjy; +aavjz; +aavka; +aavkb; +aavkc; +aavkd; +aavke; +aavkf; +aavkg; +aavkh; +aavki; +aavkj; +aavkk; +aavkl; +aavkm; +aavkn; +aavko; +aavkp; +aavkq; +aavkr; +aavks; +aavkt; +aavku; +aavkv; +aavkw; +aavkx; +aavky; +aavkz; +aavla; +aavlb; +aavlc; +aavld; +aavle; +aavlf; +aavlg; +aavlh; +aavli; +aavlj; +aavlk; +aavll; +aavlm; +aavln; +aavlo; +aavlp; +aavlq; +aavlr; +aavls; +aavlt; +aavlu; +aavlv; +aavlw; +aavlx; +aavly; +aavlz; +aavma; +aavmb; +aavmc; +aavmd; +aavme; +aavmf; +aavmg; +aavmh; +aavmi; +aavmj; +aavmk; +aavml; +aavmm; +aavmn; +aavmo; +aavmp; +aavmq; +aavmr; +aavms; +aavmt; +aavmu; +aavmv; +aavmw; +aavmx; +aavmy; +aavmz; +aavna; +aavnb; +aavnc; +aavnd; +aavne; +aavnf; +aavng; +aavnh; +aavni; +aavnj; +aavnk; +aavnl; +aavnm; +aavnn; +aavno; +aavnp; +aavnq; +aavnr; +aavns; +aavnt; +aavnu; +aavnv; +aavnw; +aavnx; +aavny; +aavnz; +aavoa; +aavob; +aavoc; +aavod; +aavoe; +aavof; +aavog; +aavoh; +aavoi; +aavoj; +aavok; +aavol; +aavom; +aavon; +aavoo; +aavop; +aavoq; +aavor; +aavos; +aavot; +aavou; +aavov; +aavow; +aavox; +aavoy; +aavoz; +aavpa; +aavpb; +aavpc; +aavpd; +aavpe; +aavpf; +aavpg; +aavph; +aavpi; +aavpj; +aavpk; +aavpl; +aavpm; +aavpn; +aavpo; +aavpp; +aavpq; +aavpr; +aavps; +aavpt; +aavpu; +aavpv; +aavpw; +aavpx; +aavpy; +aavpz; +aavqa; +aavqb; +aavqc; +aavqd; +aavqe; +aavqf; +aavqg; +aavqh; +aavqi; +aavqj; +aavqk; +aavql; +aavqm; +aavqn; +aavqo; +aavqp; +aavqq; +aavqr; +aavqs; +aavqt; +aavqu; +aavqv; +aavqw; +aavqx; +aavqy; +aavqz; +aavra; +aavrb; +aavrc; +aavrd; +aavre; +aavrf; +aavrg; +aavrh; +aavri; +aavrj; +aavrk; +aavrl; +aavrm; +aavrn; +aavro; +aavrp; +aavrq; +aavrr; +aavrs; +aavrt; +aavru; +aavrv; +aavrw; +aavrx; +aavry; +aavrz; +aavsa; +aavsb; +aavsc; +aavsd; +aavse; +aavsf; +aavsg; +aavsh; +aavsi; +aavsj; +aavsk; +aavsl; +aavsm; +aavsn; +aavso; +aavsp; +aavsq; +aavsr; +aavss; +aavst; +aavsu; +aavsv; +aavsw; +aavsx; +aavsy; +aavsz; +aavta; +aavtb; +aavtc; +aavtd; +aavte; +aavtf; +aavtg; +aavth; +aavti; +aavtj; +aavtk; +aavtl; +aavtm; +aavtn; +aavto; +aavtp; +aavtq; +aavtr; +aavts; +aavtt; +aavtu; +aavtv; +aavtw; +aavtx; +aavty; +aavtz; +aavua; +aavub; +aavuc; +aavud; +aavue; +aavuf; +aavug; +aavuh; +aavui; +aavuj; +aavuk; +aavul; +aavum; +aavun; +aavuo; +aavup; +aavuq; +aavur; +aavus; +aavut; +aavuu; +aavuv; +aavuw; +aavux; +aavuy; +aavuz; +aavva; +aavvb; +aavvc; +aavvd; +aavve; +aavvf; +aavvg; +aavvh; +aavvi; +aavvj; +aavvk; +aavvl; +aavvm; +aavvn; +aavvo; +aavvp; +aavvq; +aavvr; +aavvs; +aavvt; +aavvu; +aavvv; +aavvw; +aavvx; +aavvy; +aavvz; +aavwa; +aavwb; +aavwc; +aavwd; +aavwe; +aavwf; +aavwg; +aavwh; +aavwi; +aavwj; +aavwk; +aavwl; +aavwm; +aavwn; +aavwo; +aavwp; +aavwq; +aavwr; +aavws; +aavwt; +aavwu; +aavwv; +aavww; +aavwx; +aavwy; +aavwz; +aavxa; +aavxb; +aavxc; +aavxd; +aavxe; +aavxf; +aavxg; +aavxh; +aavxi; +aavxj; +aavxk; +aavxl; +aavxm; +aavxn; +aavxo; +aavxp; +aavxq; +aavxr; +aavxs; +aavxt; +aavxu; +aavxv; +aavxw; +aavxx; +aavxy; +aavxz; +aavya; +aavyb; +aavyc; +aavyd; +aavye; +aavyf; +aavyg; +aavyh; +aavyi; +aavyj; +aavyk; +aavyl; +aavym; +aavyn; +aavyo; +aavyp; +aavyq; +aavyr; +aavys; +aavyt; +aavyu; +aavyv; +aavyw; +aavyx; +aavyy; +aavyz; +aavza; +aavzb; +aavzc; +aavzd; +aavze; +aavzf; +aavzg; +aavzh; +aavzi; +aavzj; +aavzk; +aavzl; +aavzm; +aavzn; +aavzo; +aavzp; +aavzq; +aavzr; +aavzs; +aavzt; +aavzu; +aavzv; +aavzw; +aavzx; +aavzy; +aavzz; +aawaa; +aawab; +aawac; +aawad; +aawae; +aawaf; +aawag; +aawah; +aawai; +aawaj; +aawak; +aawal; +aawam; +aawan; +aawao; +aawap; +aawaq; +aawar; +aawas; +aawat; +aawau; +aawav; +aawaw; +aawax; +aaway; +aawaz; +aawba; +aawbb; +aawbc; +aawbd; +aawbe; +aawbf; +aawbg; +aawbh; +aawbi; +aawbj; +aawbk; +aawbl; +aawbm; +aawbn; +aawbo; +aawbp; +aawbq; +aawbr; +aawbs; +aawbt; +aawbu; +aawbv; +aawbw; +aawbx; +aawby; +aawbz; +aawca; +aawcb; +aawcc; +aawcd; +aawce; +aawcf; +aawcg; +aawch; +aawci; +aawcj; +aawck; +aawcl; +aawcm; +aawcn; +aawco; +aawcp; +aawcq; +aawcr; +aawcs; +aawct; +aawcu; +aawcv; +aawcw; +aawcx; +aawcy; +aawcz; +aawda; +aawdb; +aawdc; +aawdd; +aawde; +aawdf; +aawdg; +aawdh; +aawdi; +aawdj; +aawdk; +aawdl; +aawdm; +aawdn; +aawdo; +aawdp; +aawdq; +aawdr; +aawds; +aawdt; +aawdu; +aawdv; +aawdw; +aawdx; +aawdy; +aawdz; +aawea; +aaweb; +aawec; +aawed; +aawee; +aawef; +aaweg; +aaweh; +aawei; +aawej; +aawek; +aawel; +aawem; +aawen; +aaweo; +aawep; +aaweq; +aawer; +aawes; +aawet; +aaweu; +aawev; +aawew; +aawex; +aawey; +aawez; +aawfa; +aawfb; +aawfc; +aawfd; +aawfe; +aawff; +aawfg; +aawfh; +aawfi; +aawfj; +aawfk; +aawfl; +aawfm; +aawfn; +aawfo; +aawfp; +aawfq; +aawfr; +aawfs; +aawft; +aawfu; +aawfv; +aawfw; +aawfx; +aawfy; +aawfz; +aawga; +aawgb; +aawgc; +aawgd; +aawge; +aawgf; +aawgg; +aawgh; +aawgi; +aawgj; +aawgk; +aawgl; +aawgm; +aawgn; +aawgo; +aawgp; +aawgq; +aawgr; +aawgs; +aawgt; +aawgu; +aawgv; +aawgw; +aawgx; +aawgy; +aawgz; +aawha; +aawhb; +aawhc; +aawhd; +aawhe; +aawhf; +aawhg; +aawhh; +aawhi; +aawhj; +aawhk; +aawhl; +aawhm; +aawhn; +aawho; +aawhp; +aawhq; +aawhr; +aawhs; +aawht; +aawhu; +aawhv; +aawhw; +aawhx; +aawhy; +aawhz; +aawia; +aawib; +aawic; +aawid; +aawie; +aawif; +aawig; +aawih; +aawii; +aawij; +aawik; +aawil; +aawim; +aawin; +aawio; +aawip; +aawiq; +aawir; +aawis; +aawit; +aawiu; +aawiv; +aawiw; +aawix; +aawiy; +aawiz; +aawja; +aawjb; +aawjc; +aawjd; +aawje; +aawjf; +aawjg; +aawjh; +aawji; +aawjj; +aawjk; +aawjl; +aawjm; +aawjn; +aawjo; +aawjp; +aawjq; +aawjr; +aawjs; +aawjt; +aawju; +aawjv; +aawjw; +aawjx; +aawjy; +aawjz; +aawka; +aawkb; +aawkc; +aawkd; +aawke; +aawkf; +aawkg; +aawkh; +aawki; +aawkj; +aawkk; +aawkl; +aawkm; +aawkn; +aawko; +aawkp; +aawkq; +aawkr; +aawks; +aawkt; +aawku; +aawkv; +aawkw; +aawkx; +aawky; +aawkz; +aawla; +aawlb; +aawlc; +aawld; +aawle; +aawlf; +aawlg; +aawlh; +aawli; +aawlj; +aawlk; +aawll; +aawlm; +aawln; +aawlo; +aawlp; +aawlq; +aawlr; +aawls; +aawlt; +aawlu; +aawlv; +aawlw; +aawlx; +aawly; +aawlz; +aawma; +aawmb; +aawmc; +aawmd; +aawme; +aawmf; +aawmg; +aawmh; +aawmi; +aawmj; +aawmk; +aawml; +aawmm; +aawmn; +aawmo; +aawmp; +aawmq; +aawmr; +aawms; +aawmt; +aawmu; +aawmv; +aawmw; +aawmx; +aawmy; +aawmz; +aawna; +aawnb; +aawnc; +aawnd; +aawne; +aawnf; +aawng; +aawnh; +aawni; +aawnj; +aawnk; +aawnl; +aawnm; +aawnn; +aawno; +aawnp; +aawnq; +aawnr; +aawns; +aawnt; +aawnu; +aawnv; +aawnw; +aawnx; +aawny; +aawnz; +aawoa; +aawob; +aawoc; +aawod; +aawoe; +aawof; +aawog; +aawoh; +aawoi; +aawoj; +aawok; +aawol; +aawom; +aawon; +aawoo; +aawop; +aawoq; +aawor; +aawos; +aawot; +aawou; +aawov; +aawow; +aawox; +aawoy; +aawoz; +aawpa; +aawpb; +aawpc; +aawpd; +aawpe; +aawpf; +aawpg; +aawph; +aawpi; +aawpj; +aawpk; +aawpl; +aawpm; +aawpn; +aawpo; +aawpp; +aawpq; +aawpr; +aawps; +aawpt; +aawpu; +aawpv; +aawpw; +aawpx; +aawpy; +aawpz; +aawqa; +aawqb; +aawqc; +aawqd; +aawqe; +aawqf; +aawqg; +aawqh; +aawqi; +aawqj; +aawqk; +aawql; +aawqm; +aawqn; +aawqo; +aawqp; +aawqq; +aawqr; +aawqs; +aawqt; +aawqu; +aawqv; +aawqw; +aawqx; +aawqy; +aawqz; +aawra; +aawrb; +aawrc; +aawrd; +aawre; +aawrf; +aawrg; +aawrh; +aawri; +aawrj; +aawrk; +aawrl; +aawrm; +aawrn; +aawro; +aawrp; +aawrq; +aawrr; +aawrs; +aawrt; +aawru; +aawrv; +aawrw; +aawrx; +aawry; +aawrz; +aawsa; +aawsb; +aawsc; +aawsd; +aawse; +aawsf; +aawsg; +aawsh; +aawsi; +aawsj; +aawsk; +aawsl; +aawsm; +aawsn; +aawso; +aawsp; +aawsq; +aawsr; +aawss; +aawst; +aawsu; +aawsv; +aawsw; +aawsx; +aawsy; +aawsz; +aawta; +aawtb; +aawtc; +aawtd; +aawte; +aawtf; +aawtg; +aawth; +aawti; +aawtj; +aawtk; +aawtl; +aawtm; +aawtn; +aawto; +aawtp; +aawtq; +aawtr; +aawts; +aawtt; +aawtu; +aawtv; +aawtw; +aawtx; +aawty; +aawtz; +aawua; +aawub; +aawuc; +aawud; +aawue; +aawuf; +aawug; +aawuh; +aawui; +aawuj; +aawuk; +aawul; +aawum; +aawun; +aawuo; +aawup; +aawuq; +aawur; +aawus; +aawut; +aawuu; +aawuv; +aawuw; +aawux; +aawuy; +aawuz; +aawva; +aawvb; +aawvc; +aawvd; +aawve; +aawvf; +aawvg; +aawvh; +aawvi; +aawvj; +aawvk; +aawvl; +aawvm; +aawvn; +aawvo; +aawvp; +aawvq; +aawvr; +aawvs; +aawvt; +aawvu; +aawvv; +aawvw; +aawvx; +aawvy; +aawvz; +aawwa; +aawwb; +aawwc; +aawwd; +aawwe; +aawwf; +aawwg; +aawwh; +aawwi; +aawwj; +aawwk; +aawwl; +aawwm; +aawwn; +aawwo; +aawwp; +aawwq; +aawwr; +aawws; +aawwt; +aawwu; +aawwv; +aawww; +aawwx; +aawwy; +aawwz; +aawxa; +aawxb; +aawxc; +aawxd; +aawxe; +aawxf; +aawxg; +aawxh; +aawxi; +aawxj; +aawxk; +aawxl; +aawxm; +aawxn; +aawxo; +aawxp; +aawxq; +aawxr; +aawxs; +aawxt; +aawxu; +aawxv; +aawxw; +aawxx; +aawxy; +aawxz; +aawya; +aawyb; +aawyc; +aawyd; +aawye; +aawyf; +aawyg; +aawyh; +aawyi; +aawyj; +aawyk; +aawyl; +aawym; +aawyn; +aawyo; +aawyp; +aawyq; +aawyr; +aawys; +aawyt; +aawyu; +aawyv; +aawyw; +aawyx; +aawyy; +aawyz; +aawza; +aawzb; +aawzc; +aawzd; +aawze; +aawzf; +aawzg; +aawzh; +aawzi; +aawzj; +aawzk; +aawzl; +aawzm; +aawzn; +aawzo; +aawzp; +aawzq; +aawzr; +aawzs; +aawzt; +aawzu; +aawzv; +aawzw; +aawzx; +aawzy; +aawzz; +aaxaa; +aaxab; +aaxac; +aaxad; +aaxae; +aaxaf; +aaxag; +aaxah; +aaxai; +aaxaj; +aaxak; +aaxal; +aaxam; +aaxan; +aaxao; +aaxap; +aaxaq; +aaxar; +aaxas; +aaxat; +aaxau; +aaxav; +aaxaw; +aaxax; +aaxay; +aaxaz; +aaxba; +aaxbb; +aaxbc; +aaxbd; +aaxbe; +aaxbf; +aaxbg; +aaxbh; +aaxbi; +aaxbj; +aaxbk; +aaxbl; +aaxbm; +aaxbn; +aaxbo; +aaxbp; +aaxbq; +aaxbr; +aaxbs; +aaxbt; +aaxbu; +aaxbv; +aaxbw; +aaxbx; +aaxby; +aaxbz; +aaxca; +aaxcb; +aaxcc; +aaxcd; +aaxce; +aaxcf; +aaxcg; +aaxch; +aaxci; +aaxcj; +aaxck; +aaxcl; +aaxcm; +aaxcn; +aaxco; +aaxcp; +aaxcq; +aaxcr; +aaxcs; +aaxct; +aaxcu; +aaxcv; +aaxcw; +aaxcx; +aaxcy; +aaxcz; +aaxda; +aaxdb; +aaxdc; +aaxdd; +aaxde; +aaxdf; +aaxdg; +aaxdh; +aaxdi; +aaxdj; +aaxdk; +aaxdl; +aaxdm; +aaxdn; +aaxdo; +aaxdp; +aaxdq; +aaxdr; +aaxds; +aaxdt; +aaxdu; +aaxdv; +aaxdw; +aaxdx; +aaxdy; +aaxdz; +aaxea; +aaxeb; +aaxec; +aaxed; +aaxee; +aaxef; +aaxeg; +aaxeh; +aaxei; +aaxej; +aaxek; +aaxel; +aaxem; +aaxen; +aaxeo; +aaxep; +aaxeq; +aaxer; +aaxes; +aaxet; +aaxeu; +aaxev; +aaxew; +aaxex; +aaxey; +aaxez; +aaxfa; +aaxfb; +aaxfc; +aaxfd; +aaxfe; +aaxff; +aaxfg; +aaxfh; +aaxfi; +aaxfj; +aaxfk; +aaxfl; +aaxfm; +aaxfn; +aaxfo; +aaxfp; +aaxfq; +aaxfr; +aaxfs; +aaxft; +aaxfu; +aaxfv; +aaxfw; +aaxfx; +aaxfy; +aaxfz; +aaxga; +aaxgb; +aaxgc; +aaxgd; +aaxge; +aaxgf; +aaxgg; +aaxgh; +aaxgi; +aaxgj; +aaxgk; +aaxgl; +aaxgm; +aaxgn; +aaxgo; +aaxgp; +aaxgq; +aaxgr; +aaxgs; +aaxgt; +aaxgu; +aaxgv; +aaxgw; +aaxgx; +aaxgy; +aaxgz; +aaxha; +aaxhb; +aaxhc; +aaxhd; +aaxhe; +aaxhf; +aaxhg; +aaxhh; +aaxhi; +aaxhj; +aaxhk; +aaxhl; +aaxhm; +aaxhn; +aaxho; +aaxhp; +aaxhq; +aaxhr; +aaxhs; +aaxht; +aaxhu; +aaxhv; +aaxhw; +aaxhx; +aaxhy; +aaxhz; +aaxia; +aaxib; +aaxic; +aaxid; +aaxie; +aaxif; +aaxig; +aaxih; +aaxii; +aaxij; +aaxik; +aaxil; +aaxim; +aaxin; +aaxio; +aaxip; +aaxiq; +aaxir; +aaxis; +aaxit; +aaxiu; +aaxiv; +aaxiw; +aaxix; +aaxiy; +aaxiz; +aaxja; +aaxjb; +aaxjc; +aaxjd; +aaxje; +aaxjf; +aaxjg; +aaxjh; +aaxji; +aaxjj; +aaxjk; +aaxjl; +aaxjm; +aaxjn; +aaxjo; +aaxjp; +aaxjq; +aaxjr; +aaxjs; +aaxjt; +aaxju; +aaxjv; +aaxjw; +aaxjx; +aaxjy; +aaxjz; +aaxka; +aaxkb; +aaxkc; +aaxkd; +aaxke; +aaxkf; +aaxkg; +aaxkh; +aaxki; +aaxkj; +aaxkk; +aaxkl; +aaxkm; +aaxkn; +aaxko; +aaxkp; +aaxkq; +aaxkr; +aaxks; +aaxkt; +aaxku; +aaxkv; +aaxkw; +aaxkx; +aaxky; +aaxkz; +aaxla; +aaxlb; +aaxlc; +aaxld; +aaxle; +aaxlf; +aaxlg; +aaxlh; +aaxli; +aaxlj; +aaxlk; +aaxll; +aaxlm; +aaxln; +aaxlo; +aaxlp; +aaxlq; +aaxlr; +aaxls; +aaxlt; +aaxlu; +aaxlv; +aaxlw; +aaxlx; +aaxly; +aaxlz; +aaxma; +aaxmb; +aaxmc; +aaxmd; +aaxme; +aaxmf; +aaxmg; +aaxmh; +aaxmi; +aaxmj; +aaxmk; +aaxml; +aaxmm; +aaxmn; +aaxmo; +aaxmp; +aaxmq; +aaxmr; +aaxms; +aaxmt; +aaxmu; +aaxmv; +aaxmw; +aaxmx; +aaxmy; +aaxmz; +aaxna; +aaxnb; +aaxnc; +aaxnd; +aaxne; +aaxnf; +aaxng; +aaxnh; +aaxni; +aaxnj; +aaxnk; +aaxnl; +aaxnm; +aaxnn; +aaxno; +aaxnp; +aaxnq; +aaxnr; +aaxns; +aaxnt; +aaxnu; +aaxnv; +aaxnw; +aaxnx; +aaxny; +aaxnz; +aaxoa; +aaxob; +aaxoc; +aaxod; +aaxoe; +aaxof; +aaxog; +aaxoh; +aaxoi; +aaxoj; +aaxok; +aaxol; +aaxom; +aaxon; +aaxoo; +aaxop; +aaxoq; +aaxor; +aaxos; +aaxot; +aaxou; +aaxov; +aaxow; +aaxox; +aaxoy; +aaxoz; +aaxpa; +aaxpb; +aaxpc; +aaxpd; +aaxpe; +aaxpf; +aaxpg; +aaxph; +aaxpi; +aaxpj; +aaxpk; +aaxpl; +aaxpm; +aaxpn; +aaxpo; +aaxpp; +aaxpq; +aaxpr; +aaxps; +aaxpt; +aaxpu; +aaxpv; +aaxpw; +aaxpx; +aaxpy; +aaxpz; +aaxqa; +aaxqb; +aaxqc; +aaxqd; +aaxqe; +aaxqf; +aaxqg; +aaxqh; +aaxqi; +aaxqj; +aaxqk; +aaxql; +aaxqm; +aaxqn; +aaxqo; +aaxqp; +aaxqq; +aaxqr; +aaxqs; +aaxqt; +aaxqu; +aaxqv; +aaxqw; +aaxqx; +aaxqy; +aaxqz; +aaxra; +aaxrb; +aaxrc; +aaxrd; +aaxre; +aaxrf; +aaxrg; +aaxrh; +aaxri; +aaxrj; +aaxrk; +aaxrl; +aaxrm; +aaxrn; +aaxro; +aaxrp; +aaxrq; +aaxrr; +aaxrs; +aaxrt; +aaxru; +aaxrv; +aaxrw; +aaxrx; +aaxry; +aaxrz; +aaxsa; +aaxsb; +aaxsc; +aaxsd; +aaxse; +aaxsf; +aaxsg; +aaxsh; +aaxsi; +aaxsj; +aaxsk; +aaxsl; +aaxsm; +aaxsn; +aaxso; +aaxsp; +aaxsq; +aaxsr; +aaxss; +aaxst; +aaxsu; +aaxsv; +aaxsw; +aaxsx; +aaxsy; +aaxsz; +aaxta; +aaxtb; +aaxtc; +aaxtd; +aaxte; +aaxtf; +aaxtg; +aaxth; +aaxti; +aaxtj; +aaxtk; +aaxtl; +aaxtm; +aaxtn; +aaxto; +aaxtp; +aaxtq; +aaxtr; +aaxts; +aaxtt; +aaxtu; +aaxtv; +aaxtw; +aaxtx; +aaxty; +aaxtz; +aaxua; +aaxub; +aaxuc; +aaxud; +aaxue; +aaxuf; +aaxug; +aaxuh; +aaxui; +aaxuj; +aaxuk; +aaxul; +aaxum; +aaxun; +aaxuo; +aaxup; +aaxuq; +aaxur; +aaxus; +aaxut; +aaxuu; +aaxuv; +aaxuw; +aaxux; +aaxuy; +aaxuz; +aaxva; +aaxvb; +aaxvc; +aaxvd; +aaxve; +aaxvf; +aaxvg; +aaxvh; +aaxvi; +aaxvj; +aaxvk; +aaxvl; +aaxvm; +aaxvn; +aaxvo; +aaxvp; +aaxvq; +aaxvr; +aaxvs; +aaxvt; +aaxvu; +aaxvv; +aaxvw; +aaxvx; +aaxvy; +aaxvz; +aaxwa; +aaxwb; +aaxwc; +aaxwd; +aaxwe; +aaxwf; +aaxwg; +aaxwh; +aaxwi; +aaxwj; +aaxwk; +aaxwl; +aaxwm; +aaxwn; +aaxwo; +aaxwp; +aaxwq; +aaxwr; +aaxws; +aaxwt; +aaxwu; +aaxwv; +aaxww; +aaxwx; +aaxwy; +aaxwz; +aaxxa; +aaxxb; +aaxxc; +aaxxd; +aaxxe; +aaxxf; +aaxxg; +aaxxh; +aaxxi; +aaxxj; +aaxxk; +aaxxl; +aaxxm; +aaxxn; +aaxxo; +aaxxp; +aaxxq; +aaxxr; +aaxxs; +aaxxt; +aaxxu; +aaxxv; +aaxxw; +aaxxx; +aaxxy; +aaxxz; +aaxya; +aaxyb; +aaxyc; +aaxyd; +aaxye; +aaxyf; +aaxyg; +aaxyh; +aaxyi; +aaxyj; +aaxyk; +aaxyl; +aaxym; +aaxyn; +aaxyo; +aaxyp; +aaxyq; +aaxyr; +aaxys; +aaxyt; +aaxyu; +aaxyv; +aaxyw; +aaxyx; +aaxyy; +aaxyz; +aaxza; +aaxzb; +aaxzc; +aaxzd; +aaxze; +aaxzf; +aaxzg; +aaxzh; +aaxzi; +aaxzj; +aaxzk; +aaxzl; +aaxzm; +aaxzn; +aaxzo; +aaxzp; +aaxzq; +aaxzr; +aaxzs; +aaxzt; +aaxzu; +aaxzv; +aaxzw; +aaxzx; +aaxzy; +aaxzz; +aayaa; +aayab; +aayac; +aayad; +aayae; +aayaf; +aayag; +aayah; +aayai; +aayaj; +aayak; +aayal; +aayam; +aayan; +aayao; +aayap; +aayaq; +aayar; +aayas; +aayat; +aayau; +aayav; +aayaw; +aayax; +aayay; +aayaz; +aayba; +aaybb; +aaybc; +aaybd; +aaybe; +aaybf; +aaybg; +aaybh; +aaybi; +aaybj; +aaybk; +aaybl; +aaybm; +aaybn; +aaybo; +aaybp; +aaybq; +aaybr; +aaybs; +aaybt; +aaybu; +aaybv; +aaybw; +aaybx; +aayby; +aaybz; +aayca; +aaycb; +aaycc; +aaycd; +aayce; +aaycf; +aaycg; +aaych; +aayci; +aaycj; +aayck; +aaycl; +aaycm; +aaycn; +aayco; +aaycp; +aaycq; +aaycr; +aaycs; +aayct; +aaycu; +aaycv; +aaycw; +aaycx; +aaycy; +aaycz; +aayda; +aaydb; +aaydc; +aaydd; +aayde; +aaydf; +aaydg; +aaydh; +aaydi; +aaydj; +aaydk; +aaydl; +aaydm; +aaydn; +aaydo; +aaydp; +aaydq; +aaydr; +aayds; +aaydt; +aaydu; +aaydv; +aaydw; +aaydx; +aaydy; +aaydz; +aayea; +aayeb; +aayec; +aayed; +aayee; +aayef; +aayeg; +aayeh; +aayei; +aayej; +aayek; +aayel; +aayem; +aayen; +aayeo; +aayep; +aayeq; +aayer; +aayes; +aayet; +aayeu; +aayev; +aayew; +aayex; +aayey; +aayez; +aayfa; +aayfb; +aayfc; +aayfd; +aayfe; +aayff; +aayfg; +aayfh; +aayfi; +aayfj; +aayfk; +aayfl; +aayfm; +aayfn; +aayfo; +aayfp; +aayfq; +aayfr; +aayfs; +aayft; +aayfu; +aayfv; +aayfw; +aayfx; +aayfy; +aayfz; +aayga; +aaygb; +aaygc; +aaygd; +aayge; +aaygf; +aaygg; +aaygh; +aaygi; +aaygj; +aaygk; +aaygl; +aaygm; +aaygn; +aaygo; +aaygp; +aaygq; +aaygr; +aaygs; +aaygt; +aaygu; +aaygv; +aaygw; +aaygx; +aaygy; +aaygz; +aayha; +aayhb; +aayhc; +aayhd; +aayhe; +aayhf; +aayhg; +aayhh; +aayhi; +aayhj; +aayhk; +aayhl; +aayhm; +aayhn; +aayho; +aayhp; +aayhq; +aayhr; +aayhs; +aayht; +aayhu; +aayhv; +aayhw; +aayhx; +aayhy; +aayhz; +aayia; +aayib; +aayic; +aayid; +aayie; +aayif; +aayig; +aayih; +aayii; +aayij; +aayik; +aayil; +aayim; +aayin; +aayio; +aayip; +aayiq; +aayir; +aayis; +aayit; +aayiu; +aayiv; +aayiw; +aayix; +aayiy; +aayiz; +aayja; +aayjb; +aayjc; +aayjd; +aayje; +aayjf; +aayjg; +aayjh; +aayji; +aayjj; +aayjk; +aayjl; +aayjm; +aayjn; +aayjo; +aayjp; +aayjq; +aayjr; +aayjs; +aayjt; +aayju; +aayjv; +aayjw; +aayjx; +aayjy; +aayjz; +aayka; +aaykb; +aaykc; +aaykd; +aayke; +aaykf; +aaykg; +aaykh; +aayki; +aaykj; +aaykk; +aaykl; +aaykm; +aaykn; +aayko; +aaykp; +aaykq; +aaykr; +aayks; +aaykt; +aayku; +aaykv; +aaykw; +aaykx; +aayky; +aaykz; +aayla; +aaylb; +aaylc; +aayld; +aayle; +aaylf; +aaylg; +aaylh; +aayli; +aaylj; +aaylk; +aayll; +aaylm; +aayln; +aaylo; +aaylp; +aaylq; +aaylr; +aayls; +aaylt; +aaylu; +aaylv; +aaylw; +aaylx; +aayly; +aaylz; +aayma; +aaymb; +aaymc; +aaymd; +aayme; +aaymf; +aaymg; +aaymh; +aaymi; +aaymj; +aaymk; +aayml; +aaymm; +aaymn; +aaymo; +aaymp; +aaymq; +aaymr; +aayms; +aaymt; +aaymu; +aaymv; +aaymw; +aaymx; +aaymy; +aaymz; +aayna; +aaynb; +aaync; +aaynd; +aayne; +aaynf; +aayng; +aaynh; +aayni; +aaynj; +aaynk; +aaynl; +aaynm; +aaynn; +aayno; +aaynp; +aaynq; +aaynr; +aayns; +aaynt; +aaynu; +aaynv; +aaynw; +aaynx; +aayny; +aaynz; +aayoa; +aayob; +aayoc; +aayod; +aayoe; +aayof; +aayog; +aayoh; +aayoi; +aayoj; +aayok; +aayol; +aayom; +aayon; +aayoo; +aayop; +aayoq; +aayor; +aayos; +aayot; +aayou; +aayov; +aayow; +aayox; +aayoy; +aayoz; +aaypa; +aaypb; +aaypc; +aaypd; +aaype; +aaypf; +aaypg; +aayph; +aaypi; +aaypj; +aaypk; +aaypl; +aaypm; +aaypn; +aaypo; +aaypp; +aaypq; +aaypr; +aayps; +aaypt; +aaypu; +aaypv; +aaypw; +aaypx; +aaypy; +aaypz; +aayqa; +aayqb; +aayqc; +aayqd; +aayqe; +aayqf; +aayqg; +aayqh; +aayqi; +aayqj; +aayqk; +aayql; +aayqm; +aayqn; +aayqo; +aayqp; +aayqq; +aayqr; +aayqs; +aayqt; +aayqu; +aayqv; +aayqw; +aayqx; +aayqy; +aayqz; +aayra; +aayrb; +aayrc; +aayrd; +aayre; +aayrf; +aayrg; +aayrh; +aayri; +aayrj; +aayrk; +aayrl; +aayrm; +aayrn; +aayro; +aayrp; +aayrq; +aayrr; +aayrs; +aayrt; +aayru; +aayrv; +aayrw; +aayrx; +aayry; +aayrz; +aaysa; +aaysb; +aaysc; +aaysd; +aayse; +aaysf; +aaysg; +aaysh; +aaysi; +aaysj; +aaysk; +aaysl; +aaysm; +aaysn; +aayso; +aaysp; +aaysq; +aaysr; +aayss; +aayst; +aaysu; +aaysv; +aaysw; +aaysx; +aaysy; +aaysz; +aayta; +aaytb; +aaytc; +aaytd; +aayte; +aaytf; +aaytg; +aayth; +aayti; +aaytj; +aaytk; +aaytl; +aaytm; +aaytn; +aayto; +aaytp; +aaytq; +aaytr; +aayts; +aaytt; +aaytu; +aaytv; +aaytw; +aaytx; +aayty; +aaytz; +aayua; +aayub; +aayuc; +aayud; +aayue; +aayuf; +aayug; +aayuh; +aayui; +aayuj; +aayuk; +aayul; +aayum; +aayun; +aayuo; +aayup; +aayuq; +aayur; +aayus; +aayut; +aayuu; +aayuv; +aayuw; +aayux; +aayuy; +aayuz; +aayva; +aayvb; +aayvc; +aayvd; +aayve; +aayvf; +aayvg; +aayvh; +aayvi; +aayvj; +aayvk; +aayvl; +aayvm; +aayvn; +aayvo; +aayvp; +aayvq; +aayvr; +aayvs; +aayvt; +aayvu; +aayvv; +aayvw; +aayvx; +aayvy; +aayvz; +aaywa; +aaywb; +aaywc; +aaywd; +aaywe; +aaywf; +aaywg; +aaywh; +aaywi; +aaywj; +aaywk; +aaywl; +aaywm; +aaywn; +aaywo; +aaywp; +aaywq; +aaywr; +aayws; +aaywt; +aaywu; +aaywv; +aayww; +aaywx; +aaywy; +aaywz; +aayxa; +aayxb; +aayxc; +aayxd; +aayxe; +aayxf; +aayxg; +aayxh; +aayxi; +aayxj; +aayxk; +aayxl; +aayxm; +aayxn; +aayxo; +aayxp; +aayxq; +aayxr; +aayxs; +aayxt; +aayxu; +aayxv; +aayxw; +aayxx; +aayxy; +aayxz; +aayya; +aayyb; +aayyc; +aayyd; +aayye; +aayyf; +aayyg; +aayyh; +aayyi; +aayyj; +aayyk; +aayyl; +aayym; +aayyn; +aayyo; +aayyp; +aayyq; +aayyr; +aayys; +aayyt; +aayyu; +aayyv; +aayyw; +aayyx; +aayyy; +aayyz; +aayza; +aayzb; +aayzc; +aayzd; +aayze; +aayzf; +aayzg; +aayzh; +aayzi; +aayzj; +aayzk; +aayzl; +aayzm; +aayzn; +aayzo; +aayzp; +aayzq; +aayzr; +aayzs; +aayzt; +aayzu; +aayzv; +aayzw; +aayzx; +aayzy; +aayzz; +aazaa; +aazab; +aazac; +aazad; +aazae; +aazaf; +aazag; +aazah; +aazai; +aazaj; +aazak; +aazal; +aazam; +aazan; +aazao; +aazap; +aazaq; +aazar; +aazas; +aazat; +aazau; +aazav; +aazaw; +aazax; +aazay; +aazaz; +aazba; +aazbb; +aazbc; +aazbd; +aazbe; +aazbf; +aazbg; +aazbh; +aazbi; +aazbj; +aazbk; +aazbl; +aazbm; +aazbn; +aazbo; +aazbp; +aazbq; +aazbr; +aazbs; +aazbt; +aazbu; +aazbv; +aazbw; +aazbx; +aazby; +aazbz; +aazca; +aazcb; +aazcc; +aazcd; +aazce; +aazcf; +aazcg; +aazch; +aazci; +aazcj; +aazck; +aazcl; +aazcm; +aazcn; +aazco; +aazcp; +aazcq; +aazcr; +aazcs; +aazct; +aazcu; +aazcv; +aazcw; +aazcx; +aazcy; +aazcz; +aazda; +aazdb; +aazdc; +aazdd; +aazde; +aazdf; +aazdg; +aazdh; +aazdi; +aazdj; +aazdk; +aazdl; +aazdm; +aazdn; +aazdo; +aazdp; +aazdq; +aazdr; +aazds; +aazdt; +aazdu; +aazdv; +aazdw; +aazdx; +aazdy; +aazdz; +aazea; +aazeb; +aazec; +aazed; +aazee; +aazef; +aazeg; +aazeh; +aazei; +aazej; +aazek; +aazel; +aazem; +aazen; +aazeo; +aazep; +aazeq; +aazer; +aazes; +aazet; +aazeu; +aazev; +aazew; +aazex; +aazey; +aazez; +aazfa; +aazfb; +aazfc; +aazfd; +aazfe; +aazff; +aazfg; +aazfh; +aazfi; +aazfj; +aazfk; +aazfl; +aazfm; +aazfn; +aazfo; +aazfp; +aazfq; +aazfr; +aazfs; +aazft; +aazfu; +aazfv; +aazfw; +aazfx; +aazfy; +aazfz; +aazga; +aazgb; +aazgc; +aazgd; +aazge; +aazgf; +aazgg; +aazgh; +aazgi; +aazgj; +aazgk; +aazgl; +aazgm; +aazgn; +aazgo; +aazgp; +aazgq; +aazgr; +aazgs; +aazgt; +aazgu; +aazgv; +aazgw; +aazgx; +aazgy; +aazgz; +aazha; +aazhb; +aazhc; +aazhd; +aazhe; +aazhf; +aazhg; +aazhh; +aazhi; +aazhj; +aazhk; +aazhl; +aazhm; +aazhn; +aazho; +aazhp; +aazhq; +aazhr; +aazhs; +aazht; +aazhu; +aazhv; +aazhw; +aazhx; +aazhy; +aazhz; +aazia; +aazib; +aazic; +aazid; +aazie; +aazif; +aazig; +aazih; +aazii; +aazij; +aazik; +aazil; +aazim; +aazin; +aazio; +aazip; +aaziq; +aazir; +aazis; +aazit; +aaziu; +aaziv; +aaziw; +aazix; +aaziy; +aaziz; +aazja; +aazjb; +aazjc; +aazjd; +aazje; +aazjf; +aazjg; +aazjh; +aazji; +aazjj; +aazjk; +aazjl; +aazjm; +aazjn; +aazjo; +aazjp; +aazjq; +aazjr; +aazjs; +aazjt; +aazju; +aazjv; +aazjw; +aazjx; +aazjy; +aazjz; +aazka; +aazkb; +aazkc; +aazkd; +aazke; +aazkf; +aazkg; +aazkh; +aazki; +aazkj; +aazkk; +aazkl; +aazkm; +aazkn; +aazko; +aazkp; +aazkq; +aazkr; +aazks; +aazkt; +aazku; +aazkv; +aazkw; +aazkx; +aazky; +aazkz; +aazla; +aazlb; +aazlc; +aazld; +aazle; +aazlf; +aazlg; +aazlh; +aazli; +aazlj; +aazlk; +aazll; +aazlm; +aazln; +aazlo; +aazlp; +aazlq; +aazlr; +aazls; +aazlt; +aazlu; +aazlv; +aazlw; +aazlx; +aazly; +aazlz; +aazma; +aazmb; +aazmc; +aazmd; +aazme; +aazmf; +aazmg; +aazmh; +aazmi; +aazmj; +aazmk; +aazml; +aazmm; +aazmn; +aazmo; +aazmp; +aazmq; +aazmr; +aazms; +aazmt; +aazmu; +aazmv; +aazmw; +aazmx; +aazmy; +aazmz; +aazna; +aaznb; +aaznc; +aaznd; +aazne; +aaznf; +aazng; +aaznh; +aazni; +aaznj; +aaznk; +aaznl; +aaznm; +aaznn; +aazno; +aaznp; +aaznq; +aaznr; +aazns; +aaznt; +aaznu; +aaznv; +aaznw; +aaznx; +aazny; +aaznz; +aazoa; +aazob; +aazoc; +aazod; +aazoe; +aazof; +aazog; +aazoh; +aazoi; +aazoj; +aazok; +aazol; +aazom; +aazon; +aazoo; +aazop; +aazoq; +aazor; +aazos; +aazot; +aazou; +aazov; +aazow; +aazox; +aazoy; +aazoz; +aazpa; +aazpb; +aazpc; +aazpd; +aazpe; +aazpf; +aazpg; +aazph; +aazpi; +aazpj; +aazpk; +aazpl; +aazpm; +aazpn; +aazpo; +aazpp; +aazpq; +aazpr; +aazps; +aazpt; +aazpu; +aazpv; +aazpw; +aazpx; +aazpy; +aazpz; +aazqa; +aazqb; +aazqc; +aazqd; +aazqe; +aazqf; +aazqg; +aazqh; +aazqi; +aazqj; +aazqk; +aazql; +aazqm; +aazqn; +aazqo; +aazqp; +aazqq; +aazqr; +aazqs; +aazqt; +aazqu; +aazqv; +aazqw; +aazqx; +aazqy; +aazqz; +aazra; +aazrb; +aazrc; +aazrd; +aazre; +aazrf; +aazrg; +aazrh; +aazri; +aazrj; +aazrk; +aazrl; +aazrm; +aazrn; +aazro; +aazrp; +aazrq; +aazrr; +aazrs; +aazrt; +aazru; +aazrv; +aazrw; +aazrx; +aazry; +aazrz; +aazsa; +aazsb; +aazsc; +aazsd; +aazse; +aazsf; +aazsg; +aazsh; +aazsi; +aazsj; +aazsk; +aazsl; +aazsm; +aazsn; +aazso; +aazsp; +aazsq; +aazsr; +aazss; +aazst; +aazsu; +aazsv; +aazsw; +aazsx; +aazsy; +aazsz; +aazta; +aaztb; +aaztc; +aaztd; +aazte; +aaztf; +aaztg; +aazth; +aazti; +aaztj; +aaztk; +aaztl; +aaztm; +aaztn; +aazto; +aaztp; +aaztq; +aaztr; +aazts; +aaztt; +aaztu; +aaztv; +aaztw; +aaztx; +aazty; +aaztz; +aazua; +aazub; +aazuc; +aazud; +aazue; +aazuf; +aazug; +aazuh; +aazui; +aazuj; +aazuk; +aazul; +aazum; +aazun; +aazuo; +aazup; +aazuq; +aazur; +aazus; +aazut; +aazuu; +aazuv; +aazuw; +aazux; +aazuy; +aazuz; +aazva; +aazvb; +aazvc; +aazvd; +aazve; +aazvf; +aazvg; +aazvh; +aazvi; +aazvj; +aazvk; +aazvl; +aazvm; +aazvn; +aazvo; +aazvp; +aazvq; +aazvr; +aazvs; +aazvt; +aazvu; +aazvv; +aazvw; +aazvx; +aazvy; +aazvz; +aazwa; +aazwb; +aazwc; +aazwd; +aazwe; +aazwf; +aazwg; +aazwh; +aazwi; +aazwj; +aazwk; +aazwl; +aazwm; +aazwn; +aazwo; +aazwp; +aazwq; +aazwr; +aazws; +aazwt; +aazwu; +aazwv; +aazww; +aazwx; +aazwy; +aazwz; +aazxa; +aazxb; +aazxc; +aazxd; +aazxe; +aazxf; +aazxg; +aazxh; +aazxi; +aazxj; +aazxk; +aazxl; +aazxm; +aazxn; +aazxo; +aazxp; +aazxq; +aazxr; +aazxs; +aazxt; +aazxu; +aazxv; +aazxw; +aazxx; +aazxy; +aazxz; +aazya; +aazyb; +aazyc; +aazyd; +aazye; +aazyf; +aazyg; +aazyh; +aazyi; +aazyj; +aazyk; +aazyl; +aazym; +aazyn; +aazyo; +aazyp; +aazyq; +aazyr; +aazys; +aazyt; +aazyu; +aazyv; +aazyw; +aazyx; +aazyy; +aazyz; +aazza; +aazzb; +aazzc; +aazzd; +aazze; +aazzf; +aazzg; +aazzh; +aazzi; +aazzj; +aazzk; +aazzl; +aazzm; +aazzn; +aazzo; +aazzp; +aazzq; +aazzr; +aazzs; +aazzt; +aazzu; +aazzv; +aazzw; +aazzx; +aazzy; +aazzz; +abaaa; +abaab; +abaac; +abaad; +abaae; +abaaf; +abaag; +abaah; +abaai; +abaaj; +abaak; +abaal; +abaam; +abaan; +abaao; +abaap; +abaaq; +abaar; +abaas; +abaat; +abaau; +abaav; +abaaw; +abaax; +abaay; +abaaz; +ababa; +ababb; +ababc; +ababd; +ababe; +ababf; +ababg; +ababh; +ababi; +ababj; +ababk; +ababl; +ababm; +ababn; +ababo; +ababp; +ababq; +ababr; +ababs; +ababt; +ababu; +ababv; +ababw; +ababx; +ababy; +ababz; +abaca; +abacb; +abacc; +abacd; +abace; +abacf; +abacg; +abach; +abaci; +abacj; +aback; +abacl; +abacm; +abacn; +abaco; +abacp; +abacq; +abacr; +abacs; +abact; +abacu; +abacv; +abacw; +abacx; +abacy; +abacz; +abada; +abadb; +abadc; +abadd; +abade; +abadf; +abadg; +abadh; +abadi; +abadj; +abadk; +abadl; +abadm; +abadn; +abado; +abadp; +abadq; +abadr; +abads; +abadt; +abadu; +abadv; +abadw; +abadx; +abady; +abadz; +abaea; +abaeb; +abaec; +abaed; +abaee; +abaef; +abaeg; +abaeh; +abaei; +abaej; +abaek; +abael; +abaem; +abaen; +abaeo; +abaep; +abaeq; +abaer; +abaes; +abaet; +abaeu; +abaev; +abaew; +abaex; +abaey; +abaez; +abafa; +abafb; +abafc; +abafd; +abafe; +abaff; +abafg; +abafh; +abafi; +abafj; +abafk; +abafl; +abafm; +abafn; +abafo; +abafp; +abafq; +abafr; +abafs; +abaft; +abafu; +abafv; +abafw; +abafx; +abafy; +abafz; +abaga; +abagb; +abagc; +abagd; +abage; +abagf; +abagg; +abagh; +abagi; +abagj; +abagk; +abagl; +abagm; +abagn; +abago; +abagp; +abagq; +abagr; +abags; +abagt; +abagu; +abagv; +abagw; +abagx; +abagy; +abagz; +abaha; +abahb; +abahc; +abahd; +abahe; +abahf; +abahg; +abahh; +abahi; +abahj; +abahk; +abahl; +abahm; +abahn; +abaho; +abahp; +abahq; +abahr; +abahs; +abaht; +abahu; +abahv; +abahw; +abahx; +abahy; +abahz; +abaia; +abaib; +abaic; +abaid; +abaie; +abaif; +abaig; +abaih; +abaii; +abaij; +abaik; +abail; +abaim; +abain; +abaio; +abaip; +abaiq; +abair; +abais; +abait; +abaiu; +abaiv; +abaiw; +abaix; +abaiy; +abaiz; +abaja; +abajb; +abajc; +abajd; +abaje; +abajf; +abajg; +abajh; +abaji; +abajj; +abajk; +abajl; +abajm; +abajn; +abajo; +abajp; +abajq; +abajr; +abajs; +abajt; +abaju; +abajv; +abajw; +abajx; +abajy; +abajz; +abaka; +abakb; +abakc; +abakd; +abake; +abakf; +abakg; +abakh; +abaki; +abakj; +abakk; +abakl; +abakm; +abakn; +abako; +abakp; +abakq; +abakr; +abaks; +abakt; +abaku; +abakv; +abakw; +abakx; +abaky; +abakz; +abala; +abalb; +abalc; +abald; +abale; +abalf; +abalg; +abalh; +abali; +abalj; +abalk; +aball; +abalm; +abaln; +abalo; +abalp; +abalq; +abalr; +abals; +abalt; +abalu; +abalv; +abalw; +abalx; +abaly; +abalz; +abama; +abamb; +abamc; +abamd; +abame; +abamf; +abamg; +abamh; +abami; +abamj; +abamk; +abaml; +abamm; +abamn; +abamo; +abamp; +abamq; +abamr; +abams; +abamt; +abamu; +abamv; +abamw; +abamx; +abamy; +abamz; +abana; +abanb; +abanc; +aband; +abane; +abanf; +abang; +abanh; +abani; +abanj; +abank; +abanl; +abanm; +abann; +abano; +abanp; +abanq; +abanr; +abans; +abant; +abanu; +abanv; +abanw; +abanx; +abany; +abanz; +abaoa; +abaob; +abaoc; +abaod; +abaoe; +abaof; +abaog; +abaoh; +abaoi; +abaoj; +abaok; +abaol; +abaom; +abaon; +abaoo; +abaop; +abaoq; +abaor; +abaos; +abaot; +abaou; +abaov; +abaow; +abaox; +abaoy; +abaoz; +abapa; +abapb; +abapc; +abapd; +abape; +abapf; +abapg; +abaph; +abapi; +abapj; +abapk; +abapl; +abapm; +abapn; +abapo; +abapp; +abapq; +abapr; +abaps; +abapt; +abapu; +abapv; +abapw; +abapx; +abapy; +abapz; +abaqa; +abaqb; +abaqc; +abaqd; +abaqe; +abaqf; +abaqg; +abaqh; +abaqi; +abaqj; +abaqk; +abaql; +abaqm; +abaqn; +abaqo; +abaqp; +abaqq; +abaqr; +abaqs; +abaqt; +abaqu; +abaqv; +abaqw; +abaqx; +abaqy; +abaqz; +abara; +abarb; +abarc; +abard; +abare; +abarf; +abarg; +abarh; +abari; +abarj; +abark; +abarl; +abarm; +abarn; +abaro; +abarp; +abarq; +abarr; +abars; +abart; +abaru; +abarv; +abarw; +abarx; +abary; +abarz; +abasa; +abasb; +abasc; +abasd; +abase; +abasf; +abasg; +abash; +abasi; +abasj; +abask; +abasl; +abasm; +abasn; +abaso; +abasp; +abasq; +abasr; +abass; +abast; +abasu; +abasv; +abasw; +abasx; +abasy; +abasz; +abata; +abatb; +abatc; +abatd; +abate; +abatf; +abatg; +abath; +abati; +abatj; +abatk; +abatl; +abatm; +abatn; +abato; +abatp; +abatq; +abatr; +abats; +abatt; +abatu; +abatv; +abatw; +abatx; +abaty; +abatz; +abaua; +abaub; +abauc; +abaud; +abaue; +abauf; +abaug; +abauh; +abaui; +abauj; +abauk; +abaul; +abaum; +abaun; +abauo; +abaup; +abauq; +abaur; +abaus; +abaut; +abauu; +abauv; +abauw; +abaux; +abauy; +abauz; +abava; +abavb; +abavc; +abavd; +abave; +abavf; +abavg; +abavh; +abavi; +abavj; +abavk; +abavl; +abavm; +abavn; +abavo; +abavp; +abavq; +abavr; +abavs; +abavt; +abavu; +abavv; +abavw; +abavx; +abavy; +abavz; +abawa; +abawb; +abawc; +abawd; +abawe; +abawf; +abawg; +abawh; +abawi; +abawj; +abawk; +abawl; +abawm; +abawn; +abawo; +abawp; +abawq; +abawr; +abaws; +abawt; +abawu; +abawv; +abaww; +abawx; +abawy; +abawz; +abaxa; +abaxb; +abaxc; +abaxd; +abaxe; +abaxf; +abaxg; +abaxh; +abaxi; +abaxj; +abaxk; +abaxl; +abaxm; +abaxn; +abaxo; +abaxp; +abaxq; +abaxr; +abaxs; +abaxt; +abaxu; +abaxv; +abaxw; +abaxx; +abaxy; +abaxz; +abaya; +abayb; +abayc; +abayd; +abaye; +abayf; +abayg; +abayh; +abayi; +abayj; +abayk; +abayl; +abaym; +abayn; +abayo; +abayp; +abayq; +abayr; +abays; +abayt; +abayu; +abayv; +abayw; +abayx; +abayy; +abayz; +abaza; +abazb; +abazc; +abazd; +abaze; +abazf; +abazg; +abazh; +abazi; +abazj; +abazk; +abazl; +abazm; +abazn; +abazo; +abazp; +abazq; +abazr; +abazs; +abazt; +abazu; +abazv; +abazw; +abazx; +abazy; +abazz; +abbaa; +abbab; +abbac; +abbad; +abbae; +abbaf; +abbag; +abbah; +abbai; +abbaj; +abbak; +abbal; +abbam; +abban; +abbao; +abbap; +abbaq; +abbar; +abbas; +abbat; +abbau; +abbav; +abbaw; +abbax; +abbay; +abbaz; +abbba; +abbbb; +abbbc; +abbbd; +abbbe; +abbbf; +abbbg; +abbbh; +abbbi; +abbbj; +abbbk; +abbbl; +abbbm; +abbbn; +abbbo; +abbbp; +abbbq; +abbbr; +abbbs; +abbbt; +abbbu; +abbbv; +abbbw; +abbbx; +abbby; +abbbz; +abbca; +abbcb; +abbcc; +abbcd; +abbce; +abbcf; +abbcg; +abbch; +abbci; +abbcj; +abbck; +abbcl; +abbcm; +abbcn; +abbco; +abbcp; +abbcq; +abbcr; +abbcs; +abbct; +abbcu; +abbcv; +abbcw; +abbcx; +abbcy; +abbcz; +abbda; +abbdb; +abbdc; +abbdd; +abbde; +abbdf; +abbdg; +abbdh; +abbdi; +abbdj; +abbdk; +abbdl; +abbdm; +abbdn; +abbdo; +abbdp; +abbdq; +abbdr; +abbds; +abbdt; +abbdu; +abbdv; +abbdw; +abbdx; +abbdy; +abbdz; +abbea; +abbeb; +abbec; +abbed; +abbee; +abbef; +abbeg; +abbeh; +abbei; +abbej; +abbek; +abbel; +abbem; +abben; +abbeo; +abbep; +abbeq; +abber; +abbes; +abbet; +abbeu; +abbev; +abbew; +abbex; +abbey; +abbez; +abbfa; +abbfb; +abbfc; +abbfd; +abbfe; +abbff; +abbfg; +abbfh; +abbfi; +abbfj; +abbfk; +abbfl; +abbfm; +abbfn; +abbfo; +abbfp; +abbfq; +abbfr; +abbfs; +abbft; +abbfu; +abbfv; +abbfw; +abbfx; +abbfy; +abbfz; +abbga; +abbgb; +abbgc; +abbgd; +abbge; +abbgf; +abbgg; +abbgh; +abbgi; +abbgj; +abbgk; +abbgl; +abbgm; +abbgn; +abbgo; +abbgp; +abbgq; +abbgr; +abbgs; +abbgt; +abbgu; +abbgv; +abbgw; +abbgx; +abbgy; +abbgz; +abbha; +abbhb; +abbhc; +abbhd; +abbhe; +abbhf; +abbhg; +abbhh; +abbhi; +abbhj; +abbhk; +abbhl; +abbhm; +abbhn; +abbho; +abbhp; +abbhq; +abbhr; +abbhs; +abbht; +abbhu; +abbhv; +abbhw; +abbhx; +abbhy; +abbhz; +abbia; +abbib; +abbic; +abbid; +abbie; +abbif; +abbig; +abbih; +abbii; +abbij; +abbik; +abbil; +abbim; +abbin; +abbio; +abbip; +abbiq; +abbir; +abbis; +abbit; +abbiu; +abbiv; +abbiw; +abbix; +abbiy; +abbiz; +abbja; +abbjb; +abbjc; +abbjd; +abbje; +abbjf; +abbjg; +abbjh; +abbji; +abbjj; +abbjk; +abbjl; +abbjm; +abbjn; +abbjo; +abbjp; +abbjq; +abbjr; +abbjs; +abbjt; +abbju; +abbjv; +abbjw; +abbjx; +abbjy; +abbjz; +abbka; +abbkb; +abbkc; +abbkd; +abbke; +abbkf; +abbkg; +abbkh; +abbki; +abbkj; +abbkk; +abbkl; +abbkm; +abbkn; +abbko; +abbkp; +abbkq; +abbkr; +abbks; +abbkt; +abbku; +abbkv; +abbkw; +abbkx; +abbky; +abbkz; +abbla; +abblb; +abblc; +abbld; +abble; +abblf; +abblg; +abblh; +abbli; +abblj; +abblk; +abbll; +abblm; +abbln; +abblo; +abblp; +abblq; +abblr; +abbls; +abblt; +abblu; +abblv; +abblw; +abblx; +abbly; +abblz; +abbma; +abbmb; +abbmc; +abbmd; +abbme; +abbmf; +abbmg; +abbmh; +abbmi; +abbmj; +abbmk; +abbml; +abbmm; +abbmn; +abbmo; +abbmp; +abbmq; +abbmr; +abbms; +abbmt; +abbmu; +abbmv; +abbmw; +abbmx; +abbmy; +abbmz; +abbna; +abbnb; +abbnc; +abbnd; +abbne; +abbnf; +abbng; +abbnh; +abbni; +abbnj; +abbnk; +abbnl; +abbnm; +abbnn; +abbno; +abbnp; +abbnq; +abbnr; +abbns; +abbnt; +abbnu; +abbnv; +abbnw; +abbnx; +abbny; +abbnz; +abboa; +abbob; +abboc; +abbod; +abboe; +abbof; +abbog; +abboh; +abboi; +abboj; +abbok; +abbol; +abbom; +abbon; +abboo; +abbop; +abboq; +abbor; +abbos; +abbot; +abbou; +abbov; +abbow; +abbox; +abboy; +abboz; +abbpa; +abbpb; +abbpc; +abbpd; +abbpe; +abbpf; +abbpg; +abbph; +abbpi; +abbpj; +abbpk; +abbpl; +abbpm; +abbpn; +abbpo; +abbpp; +abbpq; +abbpr; +abbps; +abbpt; +abbpu; +abbpv; +abbpw; +abbpx; +abbpy; +abbpz; +abbqa; +abbqb; +abbqc; +abbqd; +abbqe; +abbqf; +abbqg; +abbqh; +abbqi; +abbqj; +abbqk; +abbql; +abbqm; +abbqn; +abbqo; +abbqp; +abbqq; +abbqr; +abbqs; +abbqt; +abbqu; +abbqv; +abbqw; +abbqx; +abbqy; +abbqz; +abbra; +abbrb; +abbrc; +abbrd; +abbre; +abbrf; +abbrg; +abbrh; +abbri; +abbrj; +abbrk; +abbrl; +abbrm; +abbrn; +abbro; +abbrp; +abbrq; +abbrr; +abbrs; +abbrt; +abbru; +abbrv; +abbrw; +abbrx; +abbry; +abbrz; +abbsa; +abbsb; +abbsc; +abbsd; +abbse; +abbsf; +abbsg; +abbsh; +abbsi; +abbsj; +abbsk; +abbsl; +abbsm; +abbsn; +abbso; +abbsp; +abbsq; +abbsr; +abbss; +abbst; +abbsu; +abbsv; +abbsw; +abbsx; +abbsy; +abbsz; +abbta; +abbtb; +abbtc; +abbtd; +abbte; +abbtf; +abbtg; +abbth; +abbti; +abbtj; +abbtk; +abbtl; +abbtm; +abbtn; +abbto; +abbtp; +abbtq; +abbtr; +abbts; +abbtt; +abbtu; +abbtv; +abbtw; +abbtx; +abbty; +abbtz; +abbua; +abbub; +abbuc; +abbud; +abbue; +abbuf; +abbug; +abbuh; +abbui; +abbuj; +abbuk; +abbul; +abbum; +abbun; +abbuo; +abbup; +abbuq; +abbur; +abbus; +abbut; +abbuu; +abbuv; +abbuw; +abbux; +abbuy; +abbuz; +abbva; +abbvb; +abbvc; +abbvd; +abbve; +abbvf; +abbvg; +abbvh; +abbvi; +abbvj; +abbvk; +abbvl; +abbvm; +abbvn; +abbvo; +abbvp; +abbvq; +abbvr; +abbvs; +abbvt; +abbvu; +abbvv; +abbvw; +abbvx; +abbvy; +abbvz; +abbwa; +abbwb; +abbwc; +abbwd; +abbwe; +abbwf; +abbwg; +abbwh; +abbwi; +abbwj; +abbwk; +abbwl; +abbwm; +abbwn; +abbwo; +abbwp; +abbwq; +abbwr; +abbws; +abbwt; +abbwu; +abbwv; +abbww; +abbwx; +abbwy; +abbwz; +abbxa; +abbxb; +abbxc; +abbxd; +abbxe; +abbxf; +abbxg; +abbxh; +abbxi; +abbxj; +abbxk; +abbxl; +abbxm; +abbxn; +abbxo; +abbxp; +abbxq; +abbxr; +abbxs; +abbxt; +abbxu; +abbxv; +abbxw; +abbxx; +abbxy; +abbxz; +abbya; +abbyb; +abbyc; +abbyd; +abbye; +abbyf; +abbyg; +abbyh; +abbyi; +abbyj; +abbyk; +abbyl; +abbym; +abbyn; +abbyo; +abbyp; +abbyq; +abbyr; +abbys; +abbyt; +abbyu; +abbyv; +abbyw; +abbyx; +abbyy; +abbyz; +abbza; +abbzb; +abbzc; +abbzd; +abbze; +abbzf; +abbzg; +abbzh; +abbzi; +abbzj; +abbzk; +abbzl; +abbzm; +abbzn; +abbzo; +abbzp; +abbzq; +abbzr; +abbzs; +abbzt; +abbzu; +abbzv; +abbzw; +abbzx; +abbzy; +abbzz; +abcaa; +abcab; +abcac; +abcad; +abcae; +abcaf; +abcag; +abcah; +abcai; +abcaj; +abcak; +abcal; +abcam; +abcan; +abcao; +abcap; +abcaq; +abcar; +abcas; +abcat; +abcau; +abcav; +abcaw; +abcax; +abcay; +abcaz; +abcba; +abcbb; +abcbc; +abcbd; +abcbe; +abcbf; +abcbg; +abcbh; +abcbi; +abcbj; +abcbk; +abcbl; +abcbm; +abcbn; +abcbo; +abcbp; +abcbq; +abcbr; +abcbs; +abcbt; +abcbu; +abcbv; +abcbw; +abcbx; +abcby; +abcbz; +abcca; +abccb; +abccc; +abccd; +abcce; +abccf; +abccg; +abcch; +abcci; +abccj; +abcck; +abccl; +abccm; +abccn; +abcco; +abccp; +abccq; +abccr; +abccs; +abcct; +abccu; +abccv; +abccw; +abccx; +abccy; +abccz; +abcda; +abcdb; +abcdc; +abcdd; +abcde; +abcdf; +abcdg; +abcdh; +abcdi; +abcdj; +abcdk; +abcdl; +abcdm; +abcdn; +abcdo; +abcdp; +abcdq; +abcdr; +abcds; +abcdt; +abcdu; +abcdv; +abcdw; +abcdx; +abcdy; +abcdz; +abcea; +abceb; +abcec; +abced; +abcee; +abcef; +abceg; +abceh; +abcei; +abcej; +abcek; +abcel; +abcem; +abcen; +abceo; +abcep; +abceq; +abcer; +abces; +abcet; +abceu; +abcev; +abcew; +abcex; +abcey; +abcez; +abcfa; +abcfb; +abcfc; +abcfd; +abcfe; +abcff; +abcfg; +abcfh; +abcfi; +abcfj; +abcfk; +abcfl; +abcfm; +abcfn; +abcfo; +abcfp; +abcfq; +abcfr; +abcfs; +abcft; +abcfu; +abcfv; +abcfw; +abcfx; +abcfy; +abcfz; +abcga; +abcgb; +abcgc; +abcgd; +abcge; +abcgf; +abcgg; +abcgh; +abcgi; +abcgj; +abcgk; +abcgl; +abcgm; +abcgn; +abcgo; +abcgp; +abcgq; +abcgr; +abcgs; +abcgt; +abcgu; +abcgv; +abcgw; +abcgx; +abcgy; +abcgz; +abcha; +abchb; +abchc; +abchd; +abche; +abchf; +abchg; +abchh; +abchi; +abchj; +abchk; +abchl; +abchm; +abchn; +abcho; +abchp; +abchq; +abchr; +abchs; +abcht; +abchu; +abchv; +abchw; +abchx; +abchy; +abchz; +abcia; +abcib; +abcic; +abcid; +abcie; +abcif; +abcig; +abcih; +abcii; +abcij; +abcik; +abcil; +abcim; +abcin; +abcio; +abcip; +abciq; +abcir; +abcis; +abcit; +abciu; +abciv; +abciw; +abcix; +abciy; +abciz; +abcja; +abcjb; +abcjc; +abcjd; +abcje; +abcjf; +abcjg; +abcjh; +abcji; +abcjj; +abcjk; +abcjl; +abcjm; +abcjn; +abcjo; +abcjp; +abcjq; +abcjr; +abcjs; +abcjt; +abcju; +abcjv; +abcjw; +abcjx; +abcjy; +abcjz; +abcka; +abckb; +abckc; +abckd; +abcke; +abckf; +abckg; +abckh; +abcki; +abckj; +abckk; +abckl; +abckm; +abckn; +abcko; +abckp; +abckq; +abckr; +abcks; +abckt; +abcku; +abckv; +abckw; +abckx; +abcky; +abckz; +abcla; +abclb; +abclc; +abcld; +abcle; +abclf; +abclg; +abclh; +abcli; +abclj; +abclk; +abcll; +abclm; +abcln; +abclo; +abclp; +abclq; +abclr; +abcls; +abclt; +abclu; +abclv; +abclw; +abclx; +abcly; +abclz; +abcma; +abcmb; +abcmc; +abcmd; +abcme; +abcmf; +abcmg; +abcmh; +abcmi; +abcmj; +abcmk; +abcml; +abcmm; +abcmn; +abcmo; +abcmp; +abcmq; +abcmr; +abcms; +abcmt; +abcmu; +abcmv; +abcmw; +abcmx; +abcmy; +abcmz; +abcna; +abcnb; +abcnc; +abcnd; +abcne; +abcnf; +abcng; +abcnh; +abcni; +abcnj; +abcnk; +abcnl; +abcnm; +abcnn; +abcno; +abcnp; +abcnq; +abcnr; +abcns; +abcnt; +abcnu; +abcnv; +abcnw; +abcnx; +abcny; +abcnz; +abcoa; +abcob; +abcoc; +abcod; +abcoe; +abcof; +abcog; +abcoh; +abcoi; +abcoj; +abcok; +abcol; +abcom; +abcon; +abcoo; +abcop; +abcoq; +abcor; +abcos; +abcot; +abcou; +abcov; +abcow; +abcox; +abcoy; +abcoz; +abcpa; +abcpb; +abcpc; +abcpd; +abcpe; +abcpf; +abcpg; +abcph; +abcpi; +abcpj; +abcpk; +abcpl; +abcpm; +abcpn; +abcpo; +abcpp; +abcpq; +abcpr; +abcps; +abcpt; +abcpu; +abcpv; +abcpw; +abcpx; +abcpy; +abcpz; +abcqa; +abcqb; +abcqc; +abcqd; +abcqe; +abcqf; +abcqg; +abcqh; +abcqi; +abcqj; +abcqk; +abcql; +abcqm; +abcqn; +abcqo; +abcqp; +abcqq; +abcqr; +abcqs; +abcqt; +abcqu; +abcqv; +abcqw; +abcqx; +abcqy; +abcqz; +abcra; +abcrb; +abcrc; +abcrd; +abcre; +abcrf; +abcrg; +abcrh; +abcri; +abcrj; +abcrk; +abcrl; +abcrm; +abcrn; +abcro; +abcrp; +abcrq; +abcrr; +abcrs; +abcrt; +abcru; +abcrv; +abcrw; +abcrx; +abcry; +abcrz; +abcsa; +abcsb; +abcsc; +abcsd; +abcse; +abcsf; +abcsg; +abcsh; +abcsi; +abcsj; +abcsk; +abcsl; +abcsm; +abcsn; +abcso; +abcsp; +abcsq; +abcsr; +abcss; +abcst; +abcsu; +abcsv; +abcsw; +abcsx; +abcsy; +abcsz; +abcta; +abctb; +abctc; +abctd; +abcte; +abctf; +abctg; +abcth; +abcti; +abctj; +abctk; +abctl; +abctm; +abctn; +abcto; +abctp; +abctq; +abctr; +abcts; +abctt; +abctu; +abctv; +abctw; +abctx; +abcty; +abctz; +abcua; +abcub; +abcuc; +abcud; +abcue; +abcuf; +abcug; +abcuh; +abcui; +abcuj; +abcuk; +abcul; +abcum; +abcun; +abcuo; +abcup; +abcuq; +abcur; +abcus; +abcut; +abcuu; +abcuv; +abcuw; +abcux; +abcuy; +abcuz; +abcva; +abcvb; +abcvc; +abcvd; +abcve; +abcvf; +abcvg; +abcvh; +abcvi; +abcvj; +abcvk; +abcvl; +abcvm; +abcvn; +abcvo; +abcvp; +abcvq; +abcvr; +abcvs; +abcvt; +abcvu; +abcvv; +abcvw; +abcvx; +abcvy; +abcvz; +abcwa; +abcwb; +abcwc; +abcwd; +abcwe; +abcwf; +abcwg; +abcwh; +abcwi; +abcwj; +abcwk; +abcwl; +abcwm; +abcwn; +abcwo; +abcwp; +abcwq; +abcwr; +abcws; +abcwt; +abcwu; +abcwv; +abcww; +abcwx; +abcwy; +abcwz; +abcxa; +abcxb; +abcxc; +abcxd; +abcxe; +abcxf; +abcxg; +abcxh; +abcxi; +abcxj; +abcxk; +abcxl; +abcxm; +abcxn; +abcxo; +abcxp; +abcxq; +abcxr; +abcxs; +abcxt; +abcxu; +abcxv; +abcxw; +abcxx; +abcxy; +abcxz; +abcya; +abcyb; +abcyc; +abcyd; +abcye; +abcyf; +abcyg; +abcyh; +abcyi; +abcyj; +abcyk; +abcyl; +abcym; +abcyn; +abcyo; +abcyp; +abcyq; +abcyr; +abcys; +abcyt; +abcyu; +abcyv; +abcyw; +abcyx; +abcyy; +abcyz; +abcza; +abczb; +abczc; +abczd; +abcze; +abczf; +abczg; +abczh; +abczi; +abczj; +abczk; +abczl; +abczm; +abczn; +abczo; +abczp; +abczq; +abczr; +abczs; +abczt; +abczu; +abczv; +abczw; +abczx; +abczy; +abczz; +abdaa; +abdab; +abdac; +abdad; +abdae; +abdaf; +abdag; +abdah; +abdai; +abdaj; +abdak; +abdal; +abdam; +abdan; +abdao; +abdap; +abdaq; +abdar; +abdas; +abdat; +abdau; +abdav; +abdaw; +abdax; +abday; +abdaz; +abdba; +abdbb; +abdbc; +abdbd; +abdbe; +abdbf; +abdbg; +abdbh; +abdbi; +abdbj; +abdbk; +abdbl; +abdbm; +abdbn; +abdbo; +abdbp; +abdbq; +abdbr; +abdbs; +abdbt; +abdbu; +abdbv; +abdbw; +abdbx; +abdby; +abdbz; +abdca; +abdcb; +abdcc; +abdcd; +abdce; +abdcf; +abdcg; +abdch; +abdci; +abdcj; +abdck; +abdcl; +abdcm; +abdcn; +abdco; +abdcp; +abdcq; +abdcr; +abdcs; +abdct; +abdcu; +abdcv; +abdcw; +abdcx; +abdcy; +abdcz; +abdda; +abddb; +abddc; +abddd; +abdde; +abddf; +abddg; +abddh; +abddi; +abddj; +abddk; +abddl; +abddm; +abddn; +abddo; +abddp; +abddq; +abddr; +abdds; +abddt; +abddu; +abddv; +abddw; +abddx; +abddy; +abddz; +abdea; +abdeb; +abdec; +abded; +abdee; +abdef; +abdeg; +abdeh; +abdei; +abdej; +abdek; +abdel; +abdem; +abden; +abdeo; +abdep; +abdeq; +abder; +abdes; +abdet; +abdeu; +abdev; +abdew; +abdex; +abdey; +abdez; +abdfa; +abdfb; +abdfc; +abdfd; +abdfe; +abdff; +abdfg; +abdfh; +abdfi; +abdfj; +abdfk; +abdfl; +abdfm; +abdfn; +abdfo; +abdfp; +abdfq; +abdfr; +abdfs; +abdft; +abdfu; +abdfv; +abdfw; +abdfx; +abdfy; +abdfz; +abdga; +abdgb; +abdgc; +abdgd; +abdge; +abdgf; +abdgg; +abdgh; +abdgi; +abdgj; +abdgk; +abdgl; +abdgm; +abdgn; +abdgo; +abdgp; +abdgq; +abdgr; +abdgs; +abdgt; +abdgu; +abdgv; +abdgw; +abdgx; +abdgy; +abdgz; +abdha; +abdhb; +abdhc; +abdhd; +abdhe; +abdhf; +abdhg; +abdhh; +abdhi; +abdhj; +abdhk; +abdhl; +abdhm; +abdhn; +abdho; +abdhp; +abdhq; +abdhr; +abdhs; +abdht; +abdhu; +abdhv; +abdhw; +abdhx; +abdhy; +abdhz; +abdia; +abdib; +abdic; +abdid; +abdie; +abdif; +abdig; +abdih; +abdii; +abdij; +abdik; +abdil; +abdim; +abdin; +abdio; +abdip; +abdiq; +abdir; +abdis; +abdit; +abdiu; +abdiv; +abdiw; +abdix; +abdiy; +abdiz; +abdja; +abdjb; +abdjc; +abdjd; +abdje; +abdjf; +abdjg; +abdjh; +abdji; +abdjj; +abdjk; +abdjl; +abdjm; +abdjn; +abdjo; +abdjp; +abdjq; +abdjr; +abdjs; +abdjt; +abdju; +abdjv; +abdjw; +abdjx; +abdjy; +abdjz; +abdka; +abdkb; +abdkc; +abdkd; +abdke; +abdkf; +abdkg; +abdkh; +abdki; +abdkj; +abdkk; +abdkl; +abdkm; +abdkn; +abdko; +abdkp; +abdkq; +abdkr; +abdks; +abdkt; +abdku; +abdkv; +abdkw; +abdkx; +abdky; +abdkz; +abdla; +abdlb; +abdlc; +abdld; +abdle; +abdlf; +abdlg; +abdlh; +abdli; +abdlj; +abdlk; +abdll; +abdlm; +abdln; +abdlo; +abdlp; +abdlq; +abdlr; +abdls; +abdlt; +abdlu; +abdlv; +abdlw; +abdlx; +abdly; +abdlz; +abdma; +abdmb; +abdmc; +abdmd; +abdme; +abdmf; +abdmg; +abdmh; +abdmi; +abdmj; +abdmk; +abdml; +abdmm; +abdmn; +abdmo; +abdmp; +abdmq; +abdmr; +abdms; +abdmt; +abdmu; +abdmv; +abdmw; +abdmx; +abdmy; +abdmz; +abdna; +abdnb; +abdnc; +abdnd; +abdne; +abdnf; +abdng; +abdnh; +abdni; +abdnj; +abdnk; +abdnl; +abdnm; +abdnn; +abdno; +abdnp; +abdnq; +abdnr; +abdns; +abdnt; +abdnu; +abdnv; +abdnw; +abdnx; +abdny; +abdnz; +abdoa; +abdob; +abdoc; +abdod; +abdoe; +abdof; +abdog; +abdoh; +abdoi; +abdoj; +abdok; +abdol; +abdom; +abdon; +abdoo; +abdop; +abdoq; +abdor; +abdos; +abdot; +abdou; +abdov; +abdow; +abdox; +abdoy; +abdoz; +abdpa; +abdpb; +abdpc; +abdpd; +aljwf +|]; diff --git a/camlp4/test/fixtures/bug-4058.ml b/camlp4/test/fixtures/bug-4058.ml new file mode 100644 index 0000000..f83322b --- /dev/null +++ b/camlp4/test/fixtures/bug-4058.ml @@ -0,0 +1,4 @@ +let _ = (fun x -> x), 1 +let _ = (x := 1), 2 +let _ = (x <- 1), 2 +let _ = (if true then 1 else 2), 1 diff --git a/camlp4/test/fixtures/bug-4337.ml b/camlp4/test/fixtures/bug-4337.ml new file mode 100644 index 0000000..5a44ed0 --- /dev/null +++ b/camlp4/test/fixtures/bug-4337.ml @@ -0,0 +1 @@ +match [] with []°-> () | _ -> ();; diff --git a/camlp4/test/fixtures/bug-by-vincent-balat.ml b/camlp4/test/fixtures/bug-by-vincent-balat.ml new file mode 100644 index 0000000..ed75488 --- /dev/null +++ b/camlp4/test/fixtures/bug-by-vincent-balat.ml @@ -0,0 +1 @@ +fun a -> x <- !x + 1; x <- !x + 2 diff --git a/camlp4/test/fixtures/bug-camlp4o-benjamin-monate.ml b/camlp4/test/fixtures/bug-camlp4o-benjamin-monate.ml new file mode 100644 index 0000000..e7e583d --- /dev/null +++ b/camlp4/test/fixtures/bug-camlp4o-benjamin-monate.ml @@ -0,0 +1,15 @@ +type t = A of t | B ;; +let f = function A A B -> B | B | A B | A (A _) -> B ;; + +exception True +let qexists f q = + try + Queue.iter (fun v -> if f v then raise True) q; + false + with True -> true + +type u = True | False +let g x = function | True -> () | False -> () + +type v = [`True | `False] +let h x = function | `True -> () | `False -> () diff --git a/camlp4/test/fixtures/bug-camlp4o-constr-arity-expr.ml b/camlp4/test/fixtures/bug-camlp4o-constr-arity-expr.ml new file mode 100644 index 0000000..fc9b6ad --- /dev/null +++ b/camlp4/test/fixtures/bug-camlp4o-constr-arity-expr.ml @@ -0,0 +1,8 @@ +(* Some Some Some None;; *) +(* ((Some None) None) None;; *) +((Some) None);; +(* ((Some Some) Some) None;; *) +type t = A of int * int * int;; +A (1, 2, 3);; +(A) (1, 2, 3);; +(A (1, 2)) 3;; diff --git a/camlp4/test/fixtures/bug-camlp4o-constr-arity.ml b/camlp4/test/fixtures/bug-camlp4o-constr-arity.ml new file mode 100644 index 0000000..25efe04 --- /dev/null +++ b/camlp4/test/fixtures/bug-camlp4o-constr-arity.ml @@ -0,0 +1,75 @@ +type t = A of t * t | B;; +type t2 = C of (t2 * t2) | D;; +type 'a t3 = S of 'a | T;; + +fun B B B -> ();; + +fun B (A (B, B)) B -> ();; + +fun D (D, D) -> ();; + +fun (C (D, D)) -> ();; + +let A (b, B) = A (B, B);; + +let f (A (B, B)) = ();; + +let f B (A (B, B)) = ();; + +let (D, d) = (D, D);; + +let (C (D, d)) = (C (D, D));; + +function S S T -> ();; + +function Some (A (B, B)) -> ();; + +function S (A (B, B)) -> ();; + +function S (D, D) -> ();; + +function (C (D, D)) -> ();; + +function +| Some Some Some x -> x +(* | None None None x -> x *) +| _ -> assert false;; + +fun None None None -> ();; + +fun (Some None) None None -> ();; + +let Some a = Some 42;; +let Some a :: y = [Some 42];; +let Some a, b = Some 42, 43;; +let (Some a), b = Some 42, 43;; +let Some a as b = let _ = b = 42 in Some 42;; +(* let Some (a as b) = let _ = b = None in Some 42;; *) +(* let Some (a as b) = let _ = b = 42 in Some 42;; *) +(* let (Some a) as b = let _ = b = 42 in Some 42;; *) +(* let (Some a) as b = let _ = b = None in Some 42;; *) +let Some a | Some a = Some 42;; +let x,y as r = 1,2 ;; +let ((x, y) as r) = (1, 2);; + +type top = Top of (int * int);; + +match Top (1,2) with Top min as t -> ();; + +match Top (1,2) with Top (min,max) as t -> ();; + +(* let Some 'a' .. 'b' = Some 'b';; *) + +let rec f x y = ();; + +fun x y -> ();; + +fun (x, y) -> ();; + +function x, y -> ();; + +let rec next line pos0 = () in ();; + +(* fun Some None None None -> ();; *) +(* fun x, y -> ();; |+ syntax error +| *) + diff --git a/camlp4/test/fixtures/bug_escaping_quot.ml b/camlp4/test/fixtures/bug_escaping_quot.ml new file mode 100644 index 0000000..57e5ecd --- /dev/null +++ b/camlp4/test/fixtures/bug_escaping_quot.ml @@ -0,0 +1,7 @@ +open Camlp4.PreCast;; +Camlp4_config.antiquotations := true;; +let expand_my_quot_expr _loc _loc_name_opt quotation_contents = + Printf.eprintf "%S\n%!" quotation_contents; + <:expr< dummy >> +;; +Syntax.Quotation.add "my" Syntax.Quotation.DynAst.expr_tag expand_my_quot_expr;; diff --git a/camlp4/test/fixtures/chars.ml b/camlp4/test/fixtures/chars.ml new file mode 100644 index 0000000..3d307f0 --- /dev/null +++ b/camlp4/test/fixtures/chars.ml @@ -0,0 +1 @@ +'"' diff --git a/camlp4/test/fixtures/class_expr_quot.ml b/camlp4/test/fixtures/class_expr_quot.ml new file mode 100644 index 0000000..f37e976 --- /dev/null +++ b/camlp4/test/fixtures/class_expr_quot.ml @@ -0,0 +1,27 @@ +<:class_expr< a >>; +<:class_expr< A.a B.b >>; +<:class_expr< a [ t ] >>; +<:class_expr< virtual a >>; +<:class_expr< virtual $a$ >>; +<:class_expr< virtual $lid:a$ >>; +<:class_expr< virtual $lid:a$ [ 't ] >>; +(* <:class_expr< virtual a [ t ] >>; *) +<:class_expr< $opt:v$ a >>; +<:class_expr< $opt:v$ a [ t ] >>; +<:class_expr< $opt:v$ $a$ >>; +<:class_expr< $opt:v$ $id:a$ >>; +<:class_expr< $opt:v$ $a$ [ $t$ ] >>; +(* <:class_expr< $opt:v$ a [ $t$ ] >>; *) +(* <:class_expr< $opt:v$ a $opt:t$ >>; *) +(* <:class_expr< $opt:v$ $a$ $opt:t$ >>; *) + +<:class_type< a >>; +<:class_type< a [ t ] >>; +<:class_type< virtual a >>; +<:class_type< virtual $a$ >>; +<:class_type< virtual $lid:a$ >>; +<:class_type< virtual $lid:a$ [ 't ] >>; +<:class_type< $opt:v$ a >>; +<:class_type< $opt:v$ a [ t ] >>; +<:class_type< $opt:v$ $a$ >>; +<:class_type< $opt:v$ $a$ [ $t$ ] >>; diff --git a/camlp4/test/fixtures/comments.ml b/camlp4/test/fixtures/comments.ml new file mode 100644 index 0000000..5a64876 --- /dev/null +++ b/camlp4/test/fixtures/comments.ml @@ -0,0 +1,66 @@ +(** The first special comment of the file is the comment associated + to the whole module.*) + +(** The comment for function f *) +let f x y = x + y + +(** This comment is not attached to any element since there is another + special comment just before the next element. *) + +(** Comment for exception My_exception, even with a simple comment + between the special comment and the exception.*) +(* A simple comment. *) +exception My_exception of (int -> int) * int + +(** Comment for type weather *) +type weather = +| Rain of int (** The comment for constructor Rain *) +| Sun (** The comment for constructor Sun *) + +(** The comment for type my_record *) +type my_record = { + foo : int ; (** Comment for field foo *) + bar : string ; (** Comment for field bar *) + } + +(** The comment for class my_class *) +class my_class = + object + (** A comment to describe inheritance from cl *) + inherit cl + + (** The comment for the instance variable tutu *) + val mutable tutu = "tutu" + (** The comment for toto *) + val toto = 1 + val titi = "titi" + (** Comment for method toto *) + method toto = tutu ^ "!" + (** Comment for method m *) + method m (f : float) = 1 + end + +(** The comment for class type my_class_type *) +class type my_class_type = + object + (** The comment for the instance variable x. *) + val mutable x : int + (** The commend for method m. *) + method m : int -> int + end + +(** The comment for module Foo *) +module Foo = + struct + (** The comment for x *) + let x = 42 + (** A special comment in the class, but not associated to any element. *) + end + +(** The comment for module type my_module_type. *) +module type MY_MODULE_TYPE = + sig + (* Comment for value x. *) + val x : int + (* ... *) + end diff --git a/camlp4/test/fixtures/comments.mli b/camlp4/test/fixtures/comments.mli new file mode 100644 index 0000000..33e1434 --- /dev/null +++ b/camlp4/test/fixtures/comments.mli @@ -0,0 +1,106 @@ +(** The first special comment of the file is the comment associated + with the whole module.*) + + +(** Special comments can be placed between elements and are kept + by the OCamldoc tool, but are not associated to any element. + @-tags in these comments are ignored.*) + +(*******************************************************************) +(** Comments like the one above, with more than two asterisks, + are ignored. *) + +(** The comment for function f. *) +val f : int -> int -> int +(** The continuation of the comment for function f. *) + +(** Comment for exception My_exception, even with a simple comment + between the special comment and the exception.*) +(* Hello, I'm a simple comment :-) *) +exception My_exception of (int -> int) * int + +(** Comment for type weather *) +type weather = +| Rain of int (** The comment for construtor Rain *) +| Sun (** The comment for constructor Sun *) + +(** Comment for type weather2 *) +type weather2 = +| Rain of int (** The comment for construtor Rain *) +| Sun (** The comment for constructor Sun *) +(** I can continue the comment for type weather2 here + because there is already a comment associated to the last constructor.*) + +(** The comment for type my_record *) +type my_record = { + foo : int ; (** Comment for field foo *) + bar : string ; (** Comment for field bar *) + } + (** Continuation of comment for type my_record *) + +(** Comment for foo *) +val foo : string +(** This comment is associated to foo and not to bar. *) +val bar : string +(** This comment is assciated to bar. *) + +(** The comment for class my_class *) +class my_class : + object + (** A comment to describe inheritance from cl *) + inherit cl + + (** The comment for attribute tutu *) + val mutable tutu : string + + (** The comment for attribute toto. *) + val toto : int + + (** This comment is not attached to titi since + there is a blank line before titi, but is kept + as a comment in the class. *) + + val titi : string + + (** Comment for method toto *) + method toto : string + + (** Comment for method m *) + method m : float -> int + end + +(** The comment for the class type my_class_type *) +class type my_class_type = + object + (** The comment for variable x. *) + val mutable x : int + + (** The commend for method m. *) + method m : int -> int +end + +(** The comment for module Foo *) +module Foo : + sig + (** The comment for x *) + val x : int + + (** A special comment that is kept but not associated to any element *) + end + +(** The comment for module type my_module_type. *) +module type MY_MODULE_TYPE = + sig + (** The comment for value x. *) + val x : int + + (** The comment for module M. *) + module M : + sig + (** The comment for value y. *) + val y : int + + (* ... *) + end + + end diff --git a/camlp4/test/fixtures/comments2.ml b/camlp4/test/fixtures/comments2.ml new file mode 100644 index 0000000..d99e851 --- /dev/null +++ b/camlp4/test/fixtures/comments2.ml @@ -0,0 +1,70 @@ +(** The first special comment of the file is the comment associated + to the whole module.*) + +(** The comment for function f *) +let f x y = x + y + +(** This comment is not attached to any element since there is another + special comment just before the next element. *) + +(** Comment for exception My_exception, even with a simple comment + between the special comment and the exception.*) +(* A simple comment. *) +exception My_exception of (int -> int) * int + +(** Comment for type weather *) +type weather = + (** The comment for constructor Rain *) +| Rain of int + (** The comment for constructor Sun *) +| Sun + +(** The comment for type my_record *) +type my_record = { + (** Comment for field foo *) + foo : int ; + (** Comment for field bar *) + bar : string ; + } + +(** The comment for class my_class *) +class my_class = + object + (** A comment to describe inheritance from cl *) + inherit cl + + (** The comment for the instance variable tutu *) + val mutable tutu = "tutu" + (** The comment for toto *) + val toto = 1 + val titi = "titi" + (** Comment for method toto *) + method toto = tutu ^ "!" + (** Comment for method m *) + method m (f : float) = 1 + end + +(** The comment for class type my_class_type *) +class type my_class_type = + object + (** The comment for the instance variable x. *) + val mutable x : int + (** The commend for method m. *) + method m : int -> int + end + +(** The comment for module Foo *) +module Foo = + struct + (** The comment for x *) + let x = 42 + (** A special comment in the class, but not associated to any element. *) + end + +(** The comment for module type my_module_type. *) +module type MY_MODULE_TYPE = + sig + (* Comment for value x. *) + val x : int + (* ... *) + end diff --git a/camlp4/test/fixtures/constant-parser.ml b/camlp4/test/fixtures/constant-parser.ml new file mode 100644 index 0000000..a91f54b --- /dev/null +++ b/camlp4/test/fixtures/constant-parser.ml @@ -0,0 +1,90 @@ +open Camlp4 + +module Id = struct + let name = "Camlp4Parsers.LoadCamlp4Ast" + let version = Sys.ocaml_version +end + +module Make (Ast : Camlp4.Sig.Camlp4Ast.S) = struct + module Ast = Ast + open Ast + + let _loc = Loc.ghost + + let parse_implem ?directive_handler:(_) _ _ = + let e = + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "G"), Ast.IdLid (_loc, "extend"))), + Ast.ExTyc (_loc, Ast.ExId (_loc, Ast.IdLid (_loc, "expr")), + Ast.TyApp (_loc, + Ast.TyId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "G"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Entry"), + Ast.IdLid (_loc, "t")))), + Ast.TyQuo (_loc, "expr")))), + Ast.ExTup (_loc, + Ast.ExCom (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "None")), + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + Ast.ExTup (_loc, + Ast.ExCom (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "None")), + Ast.ExCom (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "None")), + Ast.ExApp (_loc, + Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + Ast.ExTup (_loc, + Ast.ExCom (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, Ast.IdUid (_loc, "::")), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "G"), + Ast.IdUid (_loc, "Skeyword"))), + Ast.ExStr (_loc, "foo"))), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))), + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, Ast.IdUid (_loc, "G"), + Ast.IdAcc (_loc, Ast.IdUid (_loc, "Action"), + Ast.IdLid (_loc, "mk")))), + Ast.ExFun (_loc, + Ast.AsArr (_loc, Ast.PaAny _loc, Ast.ONone, + Ast.ExFun (_loc, + Ast.AsArr (_loc, + Ast.PaTyc (_loc, + Ast.PaId (_loc, + Ast.IdLid (_loc, "_loc")), + Ast.TyId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Loc"), + Ast.IdLid (_loc, "t")))), + Ast.ONone, + Ast.ExTyc (_loc, + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "ExId"))), + Ast.ExId (_loc, + Ast.IdLid (_loc, "_loc"))), + Ast.ExApp (_loc, + Ast.ExApp (_loc, + Ast.ExId (_loc, + Ast.IdAcc (_loc, + Ast.IdUid (_loc, "Ast"), + Ast.IdUid (_loc, "IdLid"))), + Ast.ExId (_loc, + Ast.IdLid (_loc, "_loc"))), + Ast.ExStr (_loc, "foo"))), + Ast.TyQuo (_loc, "expr")))))))))), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]"))))))), + Ast.ExId (_loc, Ast.IdUid (_loc, "[]")))))) + in Ast.StExp (_loc, e) + let parse_interf ?directive_handler:(_) _ _ = assert false;; + +end;; + +let module M = Camlp4.Register.OCamlParser(Id)(Make) in () diff --git a/camlp4/test/fixtures/curry-constr.ml b/camlp4/test/fixtures/curry-constr.ml new file mode 100644 index 0000000..4443ece --- /dev/null +++ b/camlp4/test/fixtures/curry-constr.ml @@ -0,0 +1,3 @@ +type t = A of int +type u = B of t +let f = function B A x -> x diff --git a/camlp4/test/fixtures/default_quotation.ml b/camlp4/test/fixtures/default_quotation.ml new file mode 100644 index 0000000..c640507 --- /dev/null +++ b/camlp4/test/fixtures/default_quotation.ml @@ -0,0 +1,4 @@ +#default_quotation "expr"; +open Camlp4.PreCast; +fun [ << $x$ - $y$ >> when x = y -> << 0 >> + | e -> e ]; diff --git a/camlp4/test/fixtures/exception-with-eqn-bug.ml b/camlp4/test/fixtures/exception-with-eqn-bug.ml new file mode 100644 index 0000000..b93c202 --- /dev/null +++ b/camlp4/test/fixtures/exception-with-eqn-bug.ml @@ -0,0 +1 @@ +exception Foo of string = Bar diff --git a/camlp4/test/fixtures/external.ml b/camlp4/test/fixtures/external.ml new file mode 100644 index 0000000..9ee32bb --- /dev/null +++ b/camlp4/test/fixtures/external.ml @@ -0,0 +1 @@ +external f : 'a -> 'b = "%identity"; diff --git a/camlp4/test/fixtures/fun.ml b/camlp4/test/fixtures/fun.ml new file mode 100644 index 0000000..6c3264d --- /dev/null +++ b/camlp4/test/fixtures/fun.ml @@ -0,0 +1,7 @@ +value f = fun []; +value f = fun [ [] -> fun [ 4 -> () ] ]; +value f = fun []; +value f = fun []; +value f = fun []; +value f = g x y; +value f = (g x) y; diff --git a/camlp4/test/fixtures/functor-perf.ml b/camlp4/test/fixtures/functor-perf.ml new file mode 100644 index 0000000..3e55acb --- /dev/null +++ b/camlp4/test/fixtures/functor-perf.ml @@ -0,0 +1,2019 @@ +module type S = sig +(* <%- for i in 0 .. 1000 do -%> + val f<%= i %> : int -> int -> int +<%- end -%> *) + val f0 : int -> int -> int + val f1 : int -> int -> int + val f2 : int -> int -> int + val f3 : int -> int -> int + val f4 : int -> int -> int + val f5 : int -> int -> int + val f6 : int -> int -> int + val f7 : int -> int -> int + val f8 : int -> int -> int + val f9 : int -> int -> int + val f10 : int -> int -> int + val f11 : int -> int -> int + val f12 : int -> int -> int + val f13 : int -> int -> int + val f14 : int -> int -> int + val f15 : int -> int -> int + val f16 : int -> int -> int + val f17 : int -> int -> int + val f18 : int -> int -> int + val f19 : int -> int -> int + val f20 : int -> int -> int + val f21 : int -> int -> int + val f22 : int -> int -> int + val f23 : int -> int -> int + val f24 : int -> int -> int + val f25 : int -> int -> int + val f26 : int -> int -> int + val f27 : int -> int -> int + val f28 : int -> int -> int + val f29 : int -> int -> int + val f30 : int -> int -> int + val f31 : int -> int -> int + val f32 : int -> int -> int + val f33 : int -> int -> int + val f34 : int -> int -> int + val f35 : int -> int -> int + val f36 : int -> int -> int + val f37 : int -> int -> int + val f38 : int -> int -> int + val f39 : int -> int -> int + val f40 : int -> int -> int + val f41 : int -> int -> int + val f42 : int -> int -> int + val f43 : int -> int -> int + val f44 : int -> int -> int + val f45 : int -> int -> int + val f46 : int -> int -> int + val f47 : int -> int -> int + val f48 : int -> int -> int + val f49 : int -> int -> int + val f50 : int -> int -> int + val f51 : int -> int -> int + val f52 : int -> int -> int + val f53 : int -> int -> int + val f54 : int -> int -> int + val f55 : int -> int -> int + val f56 : int -> int -> int + val f57 : int -> int -> int + val f58 : int -> int -> int + val f59 : int -> int -> int + val f60 : int -> int -> int + val f61 : int -> int -> int + val f62 : int -> int -> int + val f63 : int -> int -> int + val f64 : int -> int -> int + val f65 : int -> int -> int + val f66 : int -> int -> int + val f67 : int -> int -> int + val f68 : int -> int -> int + val f69 : int -> int -> int + val f70 : int -> int -> int + val f71 : int -> int -> int + val f72 : int -> int -> int + val f73 : int -> int -> int + val f74 : int -> int -> int + val f75 : int -> int -> int + val f76 : int -> int -> int + val f77 : int -> int -> int + val f78 : int -> int -> int + val f79 : int -> int -> int + val f80 : int -> int -> int + val f81 : int -> int -> int + val f82 : int -> int -> int + val f83 : int -> int -> int + val f84 : int -> int -> int + val f85 : int -> int -> int + val f86 : int -> int -> int + val f87 : int -> int -> int + val f88 : int -> int -> int + val f89 : int -> int -> int + val f90 : int -> int -> int + val f91 : int -> int -> int + val f92 : int -> int -> int + val f93 : int -> int -> int + val f94 : int -> int -> int + val f95 : int -> int -> int + val f96 : int -> int -> int + val f97 : int -> int -> int + val f98 : int -> int -> int + val f99 : int -> int -> int + val f100 : int -> int -> int + val f101 : int -> int -> int + val f102 : int -> int -> int + val f103 : int -> int -> int + val f104 : int -> int -> int + val f105 : int -> int -> int + val f106 : int -> int -> int + val f107 : int -> int -> int + val f108 : int -> int -> int + val f109 : int -> int -> int + val f110 : int -> int -> int + val f111 : int -> int -> int + val f112 : int -> int -> int + val f113 : int -> int -> int + val f114 : int -> int -> int + val f115 : int -> int -> int + val f116 : int -> int -> int + val f117 : int -> int -> int + val f118 : int -> int -> int + val f119 : int -> int -> int + val f120 : int -> int -> int + val f121 : int -> int -> int + val f122 : int -> int -> int + val f123 : int -> int -> int + val f124 : int -> int -> int + val f125 : int -> int -> int + val f126 : int -> int -> int + val f127 : int -> int -> int + val f128 : int -> int -> int + val f129 : int -> int -> int + val f130 : int -> int -> int + val f131 : int -> int -> int + val f132 : int -> int -> int + val f133 : int -> int -> int + val f134 : int -> int -> int + val f135 : int -> int -> int + val f136 : int -> int -> int + val f137 : int -> int -> int + val f138 : int -> int -> int + val f139 : int -> int -> int + val f140 : int -> int -> int + val f141 : int -> int -> int + val f142 : int -> int -> int + val f143 : int -> int -> int + val f144 : int -> int -> int + val f145 : int -> int -> int + val f146 : int -> int -> int + val f147 : int -> int -> int + val f148 : int -> int -> int + val f149 : int -> int -> int + val f150 : int -> int -> int + val f151 : int -> int -> int + val f152 : int -> int -> int + val f153 : int -> int -> int + val f154 : int -> int -> int + val f155 : int -> int -> int + val f156 : int -> int -> int + val f157 : int -> int -> int + val f158 : int -> int -> int + val f159 : int -> int -> int + val f160 : int -> int -> int + val f161 : int -> int -> int + val f162 : int -> int -> int + val f163 : int -> int -> int + val f164 : int -> int -> int + val f165 : int -> int -> int + val f166 : int -> int -> int + val f167 : int -> int -> int + val f168 : int -> int -> int + val f169 : int -> int -> int + val f170 : int -> int -> int + val f171 : int -> int -> int + val f172 : int -> int -> int + val f173 : int -> int -> int + val f174 : int -> int -> int + val f175 : int -> int -> int + val f176 : int -> int -> int + val f177 : int -> int -> int + val f178 : int -> int -> int + val f179 : int -> int -> int + val f180 : int -> int -> int + val f181 : int -> int -> int + val f182 : int -> int -> int + val f183 : int -> int -> int + val f184 : int -> int -> int + val f185 : int -> int -> int + val f186 : int -> int -> int + val f187 : int -> int -> int + val f188 : int -> int -> int + val f189 : int -> int -> int + val f190 : int -> int -> int + val f191 : int -> int -> int + val f192 : int -> int -> int + val f193 : int -> int -> int + val f194 : int -> int -> int + val f195 : int -> int -> int + val f196 : int -> int -> int + val f197 : int -> int -> int + val f198 : int -> int -> int + val f199 : int -> int -> int + val f200 : int -> int -> int + val f201 : int -> int -> int + val f202 : int -> int -> int + val f203 : int -> int -> int + val f204 : int -> int -> int + val f205 : int -> int -> int + val f206 : int -> int -> int + val f207 : int -> int -> int + val f208 : int -> int -> int + val f209 : int -> int -> int + val f210 : int -> int -> int + val f211 : int -> int -> int + val f212 : int -> int -> int + val f213 : int -> int -> int + val f214 : int -> int -> int + val f215 : int -> int -> int + val f216 : int -> int -> int + val f217 : int -> int -> int + val f218 : int -> int -> int + val f219 : int -> int -> int + val f220 : int -> int -> int + val f221 : int -> int -> int + val f222 : int -> int -> int + val f223 : int -> int -> int + val f224 : int -> int -> int + val f225 : int -> int -> int + val f226 : int -> int -> int + val f227 : int -> int -> int + val f228 : int -> int -> int + val f229 : int -> int -> int + val f230 : int -> int -> int + val f231 : int -> int -> int + val f232 : int -> int -> int + val f233 : int -> int -> int + val f234 : int -> int -> int + val f235 : int -> int -> int + val f236 : int -> int -> int + val f237 : int -> int -> int + val f238 : int -> int -> int + val f239 : int -> int -> int + val f240 : int -> int -> int + val f241 : int -> int -> int + val f242 : int -> int -> int + val f243 : int -> int -> int + val f244 : int -> int -> int + val f245 : int -> int -> int + val f246 : int -> int -> int + val f247 : int -> int -> int + val f248 : int -> int -> int + val f249 : int -> int -> int + val f250 : int -> int -> int + val f251 : int -> int -> int + val f252 : int -> int -> int + val f253 : int -> int -> int + val f254 : int -> int -> int + val f255 : int -> int -> int + val f256 : int -> int -> int + val f257 : int -> int -> int + val f258 : int -> int -> int + val f259 : int -> int -> int + val f260 : int -> int -> int + val f261 : int -> int -> int + val f262 : int -> int -> int + val f263 : int -> int -> int + val f264 : int -> int -> int + val f265 : int -> int -> int + val f266 : int -> int -> int + val f267 : int -> int -> int + val f268 : int -> int -> int + val f269 : int -> int -> int + val f270 : int -> int -> int + val f271 : int -> int -> int + val f272 : int -> int -> int + val f273 : int -> int -> int + val f274 : int -> int -> int + val f275 : int -> int -> int + val f276 : int -> int -> int + val f277 : int -> int -> int + val f278 : int -> int -> int + val f279 : int -> int -> int + val f280 : int -> int -> int + val f281 : int -> int -> int + val f282 : int -> int -> int + val f283 : int -> int -> int + val f284 : int -> int -> int + val f285 : int -> int -> int + val f286 : int -> int -> int + val f287 : int -> int -> int + val f288 : int -> int -> int + val f289 : int -> int -> int + val f290 : int -> int -> int + val f291 : int -> int -> int + val f292 : int -> int -> int + val f293 : int -> int -> int + val f294 : int -> int -> int + val f295 : int -> int -> int + val f296 : int -> int -> int + val f297 : int -> int -> int + val f298 : int -> int -> int + val f299 : int -> int -> int + val f300 : int -> int -> int + val f301 : int -> int -> int + val f302 : int -> int -> int + val f303 : int -> int -> int + val f304 : int -> int -> int + val f305 : int -> int -> int + val f306 : int -> int -> int + val f307 : int -> int -> int + val f308 : int -> int -> int + val f309 : int -> int -> int + val f310 : int -> int -> int + val f311 : int -> int -> int + val f312 : int -> int -> int + val f313 : int -> int -> int + val f314 : int -> int -> int + val f315 : int -> int -> int + val f316 : int -> int -> int + val f317 : int -> int -> int + val f318 : int -> int -> int + val f319 : int -> int -> int + val f320 : int -> int -> int + val f321 : int -> int -> int + val f322 : int -> int -> int + val f323 : int -> int -> int + val f324 : int -> int -> int + val f325 : int -> int -> int + val f326 : int -> int -> int + val f327 : int -> int -> int + val f328 : int -> int -> int + val f329 : int -> int -> int + val f330 : int -> int -> int + val f331 : int -> int -> int + val f332 : int -> int -> int + val f333 : int -> int -> int + val f334 : int -> int -> int + val f335 : int -> int -> int + val f336 : int -> int -> int + val f337 : int -> int -> int + val f338 : int -> int -> int + val f339 : int -> int -> int + val f340 : int -> int -> int + val f341 : int -> int -> int + val f342 : int -> int -> int + val f343 : int -> int -> int + val f344 : int -> int -> int + val f345 : int -> int -> int + val f346 : int -> int -> int + val f347 : int -> int -> int + val f348 : int -> int -> int + val f349 : int -> int -> int + val f350 : int -> int -> int + val f351 : int -> int -> int + val f352 : int -> int -> int + val f353 : int -> int -> int + val f354 : int -> int -> int + val f355 : int -> int -> int + val f356 : int -> int -> int + val f357 : int -> int -> int + val f358 : int -> int -> int + val f359 : int -> int -> int + val f360 : int -> int -> int + val f361 : int -> int -> int + val f362 : int -> int -> int + val f363 : int -> int -> int + val f364 : int -> int -> int + val f365 : int -> int -> int + val f366 : int -> int -> int + val f367 : int -> int -> int + val f368 : int -> int -> int + val f369 : int -> int -> int + val f370 : int -> int -> int + val f371 : int -> int -> int + val f372 : int -> int -> int + val f373 : int -> int -> int + val f374 : int -> int -> int + val f375 : int -> int -> int + val f376 : int -> int -> int + val f377 : int -> int -> int + val f378 : int -> int -> int + val f379 : int -> int -> int + val f380 : int -> int -> int + val f381 : int -> int -> int + val f382 : int -> int -> int + val f383 : int -> int -> int + val f384 : int -> int -> int + val f385 : int -> int -> int + val f386 : int -> int -> int + val f387 : int -> int -> int + val f388 : int -> int -> int + val f389 : int -> int -> int + val f390 : int -> int -> int + val f391 : int -> int -> int + val f392 : int -> int -> int + val f393 : int -> int -> int + val f394 : int -> int -> int + val f395 : int -> int -> int + val f396 : int -> int -> int + val f397 : int -> int -> int + val f398 : int -> int -> int + val f399 : int -> int -> int + val f400 : int -> int -> int + val f401 : int -> int -> int + val f402 : int -> int -> int + val f403 : int -> int -> int + val f404 : int -> int -> int + val f405 : int -> int -> int + val f406 : int -> int -> int + val f407 : int -> int -> int + val f408 : int -> int -> int + val f409 : int -> int -> int + val f410 : int -> int -> int + val f411 : int -> int -> int + val f412 : int -> int -> int + val f413 : int -> int -> int + val f414 : int -> int -> int + val f415 : int -> int -> int + val f416 : int -> int -> int + val f417 : int -> int -> int + val f418 : int -> int -> int + val f419 : int -> int -> int + val f420 : int -> int -> int + val f421 : int -> int -> int + val f422 : int -> int -> int + val f423 : int -> int -> int + val f424 : int -> int -> int + val f425 : int -> int -> int + val f426 : int -> int -> int + val f427 : int -> int -> int + val f428 : int -> int -> int + val f429 : int -> int -> int + val f430 : int -> int -> int + val f431 : int -> int -> int + val f432 : int -> int -> int + val f433 : int -> int -> int + val f434 : int -> int -> int + val f435 : int -> int -> int + val f436 : int -> int -> int + val f437 : int -> int -> int + val f438 : int -> int -> int + val f439 : int -> int -> int + val f440 : int -> int -> int + val f441 : int -> int -> int + val f442 : int -> int -> int + val f443 : int -> int -> int + val f444 : int -> int -> int + val f445 : int -> int -> int + val f446 : int -> int -> int + val f447 : int -> int -> int + val f448 : int -> int -> int + val f449 : int -> int -> int + val f450 : int -> int -> int + val f451 : int -> int -> int + val f452 : int -> int -> int + val f453 : int -> int -> int + val f454 : int -> int -> int + val f455 : int -> int -> int + val f456 : int -> int -> int + val f457 : int -> int -> int + val f458 : int -> int -> int + val f459 : int -> int -> int + val f460 : int -> int -> int + val f461 : int -> int -> int + val f462 : int -> int -> int + val f463 : int -> int -> int + val f464 : int -> int -> int + val f465 : int -> int -> int + val f466 : int -> int -> int + val f467 : int -> int -> int + val f468 : int -> int -> int + val f469 : int -> int -> int + val f470 : int -> int -> int + val f471 : int -> int -> int + val f472 : int -> int -> int + val f473 : int -> int -> int + val f474 : int -> int -> int + val f475 : int -> int -> int + val f476 : int -> int -> int + val f477 : int -> int -> int + val f478 : int -> int -> int + val f479 : int -> int -> int + val f480 : int -> int -> int + val f481 : int -> int -> int + val f482 : int -> int -> int + val f483 : int -> int -> int + val f484 : int -> int -> int + val f485 : int -> int -> int + val f486 : int -> int -> int + val f487 : int -> int -> int + val f488 : int -> int -> int + val f489 : int -> int -> int + val f490 : int -> int -> int + val f491 : int -> int -> int + val f492 : int -> int -> int + val f493 : int -> int -> int + val f494 : int -> int -> int + val f495 : int -> int -> int + val f496 : int -> int -> int + val f497 : int -> int -> int + val f498 : int -> int -> int + val f499 : int -> int -> int + val f500 : int -> int -> int + val f501 : int -> int -> int + val f502 : int -> int -> int + val f503 : int -> int -> int + val f504 : int -> int -> int + val f505 : int -> int -> int + val f506 : int -> int -> int + val f507 : int -> int -> int + val f508 : int -> int -> int + val f509 : int -> int -> int + val f510 : int -> int -> int + val f511 : int -> int -> int + val f512 : int -> int -> int + val f513 : int -> int -> int + val f514 : int -> int -> int + val f515 : int -> int -> int + val f516 : int -> int -> int + val f517 : int -> int -> int + val f518 : int -> int -> int + val f519 : int -> int -> int + val f520 : int -> int -> int + val f521 : int -> int -> int + val f522 : int -> int -> int + val f523 : int -> int -> int + val f524 : int -> int -> int + val f525 : int -> int -> int + val f526 : int -> int -> int + val f527 : int -> int -> int + val f528 : int -> int -> int + val f529 : int -> int -> int + val f530 : int -> int -> int + val f531 : int -> int -> int + val f532 : int -> int -> int + val f533 : int -> int -> int + val f534 : int -> int -> int + val f535 : int -> int -> int + val f536 : int -> int -> int + val f537 : int -> int -> int + val f538 : int -> int -> int + val f539 : int -> int -> int + val f540 : int -> int -> int + val f541 : int -> int -> int + val f542 : int -> int -> int + val f543 : int -> int -> int + val f544 : int -> int -> int + val f545 : int -> int -> int + val f546 : int -> int -> int + val f547 : int -> int -> int + val f548 : int -> int -> int + val f549 : int -> int -> int + val f550 : int -> int -> int + val f551 : int -> int -> int + val f552 : int -> int -> int + val f553 : int -> int -> int + val f554 : int -> int -> int + val f555 : int -> int -> int + val f556 : int -> int -> int + val f557 : int -> int -> int + val f558 : int -> int -> int + val f559 : int -> int -> int + val f560 : int -> int -> int + val f561 : int -> int -> int + val f562 : int -> int -> int + val f563 : int -> int -> int + val f564 : int -> int -> int + val f565 : int -> int -> int + val f566 : int -> int -> int + val f567 : int -> int -> int + val f568 : int -> int -> int + val f569 : int -> int -> int + val f570 : int -> int -> int + val f571 : int -> int -> int + val f572 : int -> int -> int + val f573 : int -> int -> int + val f574 : int -> int -> int + val f575 : int -> int -> int + val f576 : int -> int -> int + val f577 : int -> int -> int + val f578 : int -> int -> int + val f579 : int -> int -> int + val f580 : int -> int -> int + val f581 : int -> int -> int + val f582 : int -> int -> int + val f583 : int -> int -> int + val f584 : int -> int -> int + val f585 : int -> int -> int + val f586 : int -> int -> int + val f587 : int -> int -> int + val f588 : int -> int -> int + val f589 : int -> int -> int + val f590 : int -> int -> int + val f591 : int -> int -> int + val f592 : int -> int -> int + val f593 : int -> int -> int + val f594 : int -> int -> int + val f595 : int -> int -> int + val f596 : int -> int -> int + val f597 : int -> int -> int + val f598 : int -> int -> int + val f599 : int -> int -> int + val f600 : int -> int -> int + val f601 : int -> int -> int + val f602 : int -> int -> int + val f603 : int -> int -> int + val f604 : int -> int -> int + val f605 : int -> int -> int + val f606 : int -> int -> int + val f607 : int -> int -> int + val f608 : int -> int -> int + val f609 : int -> int -> int + val f610 : int -> int -> int + val f611 : int -> int -> int + val f612 : int -> int -> int + val f613 : int -> int -> int + val f614 : int -> int -> int + val f615 : int -> int -> int + val f616 : int -> int -> int + val f617 : int -> int -> int + val f618 : int -> int -> int + val f619 : int -> int -> int + val f620 : int -> int -> int + val f621 : int -> int -> int + val f622 : int -> int -> int + val f623 : int -> int -> int + val f624 : int -> int -> int + val f625 : int -> int -> int + val f626 : int -> int -> int + val f627 : int -> int -> int + val f628 : int -> int -> int + val f629 : int -> int -> int + val f630 : int -> int -> int + val f631 : int -> int -> int + val f632 : int -> int -> int + val f633 : int -> int -> int + val f634 : int -> int -> int + val f635 : int -> int -> int + val f636 : int -> int -> int + val f637 : int -> int -> int + val f638 : int -> int -> int + val f639 : int -> int -> int + val f640 : int -> int -> int + val f641 : int -> int -> int + val f642 : int -> int -> int + val f643 : int -> int -> int + val f644 : int -> int -> int + val f645 : int -> int -> int + val f646 : int -> int -> int + val f647 : int -> int -> int + val f648 : int -> int -> int + val f649 : int -> int -> int + val f650 : int -> int -> int + val f651 : int -> int -> int + val f652 : int -> int -> int + val f653 : int -> int -> int + val f654 : int -> int -> int + val f655 : int -> int -> int + val f656 : int -> int -> int + val f657 : int -> int -> int + val f658 : int -> int -> int + val f659 : int -> int -> int + val f660 : int -> int -> int + val f661 : int -> int -> int + val f662 : int -> int -> int + val f663 : int -> int -> int + val f664 : int -> int -> int + val f665 : int -> int -> int + val f666 : int -> int -> int + val f667 : int -> int -> int + val f668 : int -> int -> int + val f669 : int -> int -> int + val f670 : int -> int -> int + val f671 : int -> int -> int + val f672 : int -> int -> int + val f673 : int -> int -> int + val f674 : int -> int -> int + val f675 : int -> int -> int + val f676 : int -> int -> int + val f677 : int -> int -> int + val f678 : int -> int -> int + val f679 : int -> int -> int + val f680 : int -> int -> int + val f681 : int -> int -> int + val f682 : int -> int -> int + val f683 : int -> int -> int + val f684 : int -> int -> int + val f685 : int -> int -> int + val f686 : int -> int -> int + val f687 : int -> int -> int + val f688 : int -> int -> int + val f689 : int -> int -> int + val f690 : int -> int -> int + val f691 : int -> int -> int + val f692 : int -> int -> int + val f693 : int -> int -> int + val f694 : int -> int -> int + val f695 : int -> int -> int + val f696 : int -> int -> int + val f697 : int -> int -> int + val f698 : int -> int -> int + val f699 : int -> int -> int + val f700 : int -> int -> int + val f701 : int -> int -> int + val f702 : int -> int -> int + val f703 : int -> int -> int + val f704 : int -> int -> int + val f705 : int -> int -> int + val f706 : int -> int -> int + val f707 : int -> int -> int + val f708 : int -> int -> int + val f709 : int -> int -> int + val f710 : int -> int -> int + val f711 : int -> int -> int + val f712 : int -> int -> int + val f713 : int -> int -> int + val f714 : int -> int -> int + val f715 : int -> int -> int + val f716 : int -> int -> int + val f717 : int -> int -> int + val f718 : int -> int -> int + val f719 : int -> int -> int + val f720 : int -> int -> int + val f721 : int -> int -> int + val f722 : int -> int -> int + val f723 : int -> int -> int + val f724 : int -> int -> int + val f725 : int -> int -> int + val f726 : int -> int -> int + val f727 : int -> int -> int + val f728 : int -> int -> int + val f729 : int -> int -> int + val f730 : int -> int -> int + val f731 : int -> int -> int + val f732 : int -> int -> int + val f733 : int -> int -> int + val f734 : int -> int -> int + val f735 : int -> int -> int + val f736 : int -> int -> int + val f737 : int -> int -> int + val f738 : int -> int -> int + val f739 : int -> int -> int + val f740 : int -> int -> int + val f741 : int -> int -> int + val f742 : int -> int -> int + val f743 : int -> int -> int + val f744 : int -> int -> int + val f745 : int -> int -> int + val f746 : int -> int -> int + val f747 : int -> int -> int + val f748 : int -> int -> int + val f749 : int -> int -> int + val f750 : int -> int -> int + val f751 : int -> int -> int + val f752 : int -> int -> int + val f753 : int -> int -> int + val f754 : int -> int -> int + val f755 : int -> int -> int + val f756 : int -> int -> int + val f757 : int -> int -> int + val f758 : int -> int -> int + val f759 : int -> int -> int + val f760 : int -> int -> int + val f761 : int -> int -> int + val f762 : int -> int -> int + val f763 : int -> int -> int + val f764 : int -> int -> int + val f765 : int -> int -> int + val f766 : int -> int -> int + val f767 : int -> int -> int + val f768 : int -> int -> int + val f769 : int -> int -> int + val f770 : int -> int -> int + val f771 : int -> int -> int + val f772 : int -> int -> int + val f773 : int -> int -> int + val f774 : int -> int -> int + val f775 : int -> int -> int + val f776 : int -> int -> int + val f777 : int -> int -> int + val f778 : int -> int -> int + val f779 : int -> int -> int + val f780 : int -> int -> int + val f781 : int -> int -> int + val f782 : int -> int -> int + val f783 : int -> int -> int + val f784 : int -> int -> int + val f785 : int -> int -> int + val f786 : int -> int -> int + val f787 : int -> int -> int + val f788 : int -> int -> int + val f789 : int -> int -> int + val f790 : int -> int -> int + val f791 : int -> int -> int + val f792 : int -> int -> int + val f793 : int -> int -> int + val f794 : int -> int -> int + val f795 : int -> int -> int + val f796 : int -> int -> int + val f797 : int -> int -> int + val f798 : int -> int -> int + val f799 : int -> int -> int + val f800 : int -> int -> int + val f801 : int -> int -> int + val f802 : int -> int -> int + val f803 : int -> int -> int + val f804 : int -> int -> int + val f805 : int -> int -> int + val f806 : int -> int -> int + val f807 : int -> int -> int + val f808 : int -> int -> int + val f809 : int -> int -> int + val f810 : int -> int -> int + val f811 : int -> int -> int + val f812 : int -> int -> int + val f813 : int -> int -> int + val f814 : int -> int -> int + val f815 : int -> int -> int + val f816 : int -> int -> int + val f817 : int -> int -> int + val f818 : int -> int -> int + val f819 : int -> int -> int + val f820 : int -> int -> int + val f821 : int -> int -> int + val f822 : int -> int -> int + val f823 : int -> int -> int + val f824 : int -> int -> int + val f825 : int -> int -> int + val f826 : int -> int -> int + val f827 : int -> int -> int + val f828 : int -> int -> int + val f829 : int -> int -> int + val f830 : int -> int -> int + val f831 : int -> int -> int + val f832 : int -> int -> int + val f833 : int -> int -> int + val f834 : int -> int -> int + val f835 : int -> int -> int + val f836 : int -> int -> int + val f837 : int -> int -> int + val f838 : int -> int -> int + val f839 : int -> int -> int + val f840 : int -> int -> int + val f841 : int -> int -> int + val f842 : int -> int -> int + val f843 : int -> int -> int + val f844 : int -> int -> int + val f845 : int -> int -> int + val f846 : int -> int -> int + val f847 : int -> int -> int + val f848 : int -> int -> int + val f849 : int -> int -> int + val f850 : int -> int -> int + val f851 : int -> int -> int + val f852 : int -> int -> int + val f853 : int -> int -> int + val f854 : int -> int -> int + val f855 : int -> int -> int + val f856 : int -> int -> int + val f857 : int -> int -> int + val f858 : int -> int -> int + val f859 : int -> int -> int + val f860 : int -> int -> int + val f861 : int -> int -> int + val f862 : int -> int -> int + val f863 : int -> int -> int + val f864 : int -> int -> int + val f865 : int -> int -> int + val f866 : int -> int -> int + val f867 : int -> int -> int + val f868 : int -> int -> int + val f869 : int -> int -> int + val f870 : int -> int -> int + val f871 : int -> int -> int + val f872 : int -> int -> int + val f873 : int -> int -> int + val f874 : int -> int -> int + val f875 : int -> int -> int + val f876 : int -> int -> int + val f877 : int -> int -> int + val f878 : int -> int -> int + val f879 : int -> int -> int + val f880 : int -> int -> int + val f881 : int -> int -> int + val f882 : int -> int -> int + val f883 : int -> int -> int + val f884 : int -> int -> int + val f885 : int -> int -> int + val f886 : int -> int -> int + val f887 : int -> int -> int + val f888 : int -> int -> int + val f889 : int -> int -> int + val f890 : int -> int -> int + val f891 : int -> int -> int + val f892 : int -> int -> int + val f893 : int -> int -> int + val f894 : int -> int -> int + val f895 : int -> int -> int + val f896 : int -> int -> int + val f897 : int -> int -> int + val f898 : int -> int -> int + val f899 : int -> int -> int + val f900 : int -> int -> int + val f901 : int -> int -> int + val f902 : int -> int -> int + val f903 : int -> int -> int + val f904 : int -> int -> int + val f905 : int -> int -> int + val f906 : int -> int -> int + val f907 : int -> int -> int + val f908 : int -> int -> int + val f909 : int -> int -> int + val f910 : int -> int -> int + val f911 : int -> int -> int + val f912 : int -> int -> int + val f913 : int -> int -> int + val f914 : int -> int -> int + val f915 : int -> int -> int + val f916 : int -> int -> int + val f917 : int -> int -> int + val f918 : int -> int -> int + val f919 : int -> int -> int + val f920 : int -> int -> int + val f921 : int -> int -> int + val f922 : int -> int -> int + val f923 : int -> int -> int + val f924 : int -> int -> int + val f925 : int -> int -> int + val f926 : int -> int -> int + val f927 : int -> int -> int + val f928 : int -> int -> int + val f929 : int -> int -> int + val f930 : int -> int -> int + val f931 : int -> int -> int + val f932 : int -> int -> int + val f933 : int -> int -> int + val f934 : int -> int -> int + val f935 : int -> int -> int + val f936 : int -> int -> int + val f937 : int -> int -> int + val f938 : int -> int -> int + val f939 : int -> int -> int + val f940 : int -> int -> int + val f941 : int -> int -> int + val f942 : int -> int -> int + val f943 : int -> int -> int + val f944 : int -> int -> int + val f945 : int -> int -> int + val f946 : int -> int -> int + val f947 : int -> int -> int + val f948 : int -> int -> int + val f949 : int -> int -> int + val f950 : int -> int -> int + val f951 : int -> int -> int + val f952 : int -> int -> int + val f953 : int -> int -> int + val f954 : int -> int -> int + val f955 : int -> int -> int + val f956 : int -> int -> int + val f957 : int -> int -> int + val f958 : int -> int -> int + val f959 : int -> int -> int + val f960 : int -> int -> int + val f961 : int -> int -> int + val f962 : int -> int -> int + val f963 : int -> int -> int + val f964 : int -> int -> int + val f965 : int -> int -> int + val f966 : int -> int -> int + val f967 : int -> int -> int + val f968 : int -> int -> int + val f969 : int -> int -> int + val f970 : int -> int -> int + val f971 : int -> int -> int + val f972 : int -> int -> int + val f973 : int -> int -> int + val f974 : int -> int -> int + val f975 : int -> int -> int + val f976 : int -> int -> int + val f977 : int -> int -> int + val f978 : int -> int -> int + val f979 : int -> int -> int + val f980 : int -> int -> int + val f981 : int -> int -> int + val f982 : int -> int -> int + val f983 : int -> int -> int + val f984 : int -> int -> int + val f985 : int -> int -> int + val f986 : int -> int -> int + val f987 : int -> int -> int + val f988 : int -> int -> int + val f989 : int -> int -> int + val f990 : int -> int -> int + val f991 : int -> int -> int + val f992 : int -> int -> int + val f993 : int -> int -> int + val f994 : int -> int -> int + val f995 : int -> int -> int + val f996 : int -> int -> int + val f997 : int -> int -> int + val f998 : int -> int -> int + val f999 : int -> int -> int + val f1000 : int -> int -> int +end + +module Make (M : S) = struct + include M +end + +module M = struct +(* <%- for i in 0 .. 1000 do -%> + let f<%= i %> = ( + ) +<%- end -%> *) + let f0 = ( + ) + let f1 = ( + ) + let f2 = ( + ) + let f3 = ( + ) + let f4 = ( + ) + let f5 = ( + ) + let f6 = ( + ) + let f7 = ( + ) + let f8 = ( + ) + let f9 = ( + ) + let f10 = ( + ) + let f11 = ( + ) + let f12 = ( + ) + let f13 = ( + ) + let f14 = ( + ) + let f15 = ( + ) + let f16 = ( + ) + let f17 = ( + ) + let f18 = ( + ) + let f19 = ( + ) + let f20 = ( + ) + let f21 = ( + ) + let f22 = ( + ) + let f23 = ( + ) + let f24 = ( + ) + let f25 = ( + ) + let f26 = ( + ) + let f27 = ( + ) + let f28 = ( + ) + let f29 = ( + ) + let f30 = ( + ) + let f31 = ( + ) + let f32 = ( + ) + let f33 = ( + ) + let f34 = ( + ) + let f35 = ( + ) + let f36 = ( + ) + let f37 = ( + ) + let f38 = ( + ) + let f39 = ( + ) + let f40 = ( + ) + let f41 = ( + ) + let f42 = ( + ) + let f43 = ( + ) + let f44 = ( + ) + let f45 = ( + ) + let f46 = ( + ) + let f47 = ( + ) + let f48 = ( + ) + let f49 = ( + ) + let f50 = ( + ) + let f51 = ( + ) + let f52 = ( + ) + let f53 = ( + ) + let f54 = ( + ) + let f55 = ( + ) + let f56 = ( + ) + let f57 = ( + ) + let f58 = ( + ) + let f59 = ( + ) + let f60 = ( + ) + let f61 = ( + ) + let f62 = ( + ) + let f63 = ( + ) + let f64 = ( + ) + let f65 = ( + ) + let f66 = ( + ) + let f67 = ( + ) + let f68 = ( + ) + let f69 = ( + ) + let f70 = ( + ) + let f71 = ( + ) + let f72 = ( + ) + let f73 = ( + ) + let f74 = ( + ) + let f75 = ( + ) + let f76 = ( + ) + let f77 = ( + ) + let f78 = ( + ) + let f79 = ( + ) + let f80 = ( + ) + let f81 = ( + ) + let f82 = ( + ) + let f83 = ( + ) + let f84 = ( + ) + let f85 = ( + ) + let f86 = ( + ) + let f87 = ( + ) + let f88 = ( + ) + let f89 = ( + ) + let f90 = ( + ) + let f91 = ( + ) + let f92 = ( + ) + let f93 = ( + ) + let f94 = ( + ) + let f95 = ( + ) + let f96 = ( + ) + let f97 = ( + ) + let f98 = ( + ) + let f99 = ( + ) + let f100 = ( + ) + let f101 = ( + ) + let f102 = ( + ) + let f103 = ( + ) + let f104 = ( + ) + let f105 = ( + ) + let f106 = ( + ) + let f107 = ( + ) + let f108 = ( + ) + let f109 = ( + ) + let f110 = ( + ) + let f111 = ( + ) + let f112 = ( + ) + let f113 = ( + ) + let f114 = ( + ) + let f115 = ( + ) + let f116 = ( + ) + let f117 = ( + ) + let f118 = ( + ) + let f119 = ( + ) + let f120 = ( + ) + let f121 = ( + ) + let f122 = ( + ) + let f123 = ( + ) + let f124 = ( + ) + let f125 = ( + ) + let f126 = ( + ) + let f127 = ( + ) + let f128 = ( + ) + let f129 = ( + ) + let f130 = ( + ) + let f131 = ( + ) + let f132 = ( + ) + let f133 = ( + ) + let f134 = ( + ) + let f135 = ( + ) + let f136 = ( + ) + let f137 = ( + ) + let f138 = ( + ) + let f139 = ( + ) + let f140 = ( + ) + let f141 = ( + ) + let f142 = ( + ) + let f143 = ( + ) + let f144 = ( + ) + let f145 = ( + ) + let f146 = ( + ) + let f147 = ( + ) + let f148 = ( + ) + let f149 = ( + ) + let f150 = ( + ) + let f151 = ( + ) + let f152 = ( + ) + let f153 = ( + ) + let f154 = ( + ) + let f155 = ( + ) + let f156 = ( + ) + let f157 = ( + ) + let f158 = ( + ) + let f159 = ( + ) + let f160 = ( + ) + let f161 = ( + ) + let f162 = ( + ) + let f163 = ( + ) + let f164 = ( + ) + let f165 = ( + ) + let f166 = ( + ) + let f167 = ( + ) + let f168 = ( + ) + let f169 = ( + ) + let f170 = ( + ) + let f171 = ( + ) + let f172 = ( + ) + let f173 = ( + ) + let f174 = ( + ) + let f175 = ( + ) + let f176 = ( + ) + let f177 = ( + ) + let f178 = ( + ) + let f179 = ( + ) + let f180 = ( + ) + let f181 = ( + ) + let f182 = ( + ) + let f183 = ( + ) + let f184 = ( + ) + let f185 = ( + ) + let f186 = ( + ) + let f187 = ( + ) + let f188 = ( + ) + let f189 = ( + ) + let f190 = ( + ) + let f191 = ( + ) + let f192 = ( + ) + let f193 = ( + ) + let f194 = ( + ) + let f195 = ( + ) + let f196 = ( + ) + let f197 = ( + ) + let f198 = ( + ) + let f199 = ( + ) + let f200 = ( + ) + let f201 = ( + ) + let f202 = ( + ) + let f203 = ( + ) + let f204 = ( + ) + let f205 = ( + ) + let f206 = ( + ) + let f207 = ( + ) + let f208 = ( + ) + let f209 = ( + ) + let f210 = ( + ) + let f211 = ( + ) + let f212 = ( + ) + let f213 = ( + ) + let f214 = ( + ) + let f215 = ( + ) + let f216 = ( + ) + let f217 = ( + ) + let f218 = ( + ) + let f219 = ( + ) + let f220 = ( + ) + let f221 = ( + ) + let f222 = ( + ) + let f223 = ( + ) + let f224 = ( + ) + let f225 = ( + ) + let f226 = ( + ) + let f227 = ( + ) + let f228 = ( + ) + let f229 = ( + ) + let f230 = ( + ) + let f231 = ( + ) + let f232 = ( + ) + let f233 = ( + ) + let f234 = ( + ) + let f235 = ( + ) + let f236 = ( + ) + let f237 = ( + ) + let f238 = ( + ) + let f239 = ( + ) + let f240 = ( + ) + let f241 = ( + ) + let f242 = ( + ) + let f243 = ( + ) + let f244 = ( + ) + let f245 = ( + ) + let f246 = ( + ) + let f247 = ( + ) + let f248 = ( + ) + let f249 = ( + ) + let f250 = ( + ) + let f251 = ( + ) + let f252 = ( + ) + let f253 = ( + ) + let f254 = ( + ) + let f255 = ( + ) + let f256 = ( + ) + let f257 = ( + ) + let f258 = ( + ) + let f259 = ( + ) + let f260 = ( + ) + let f261 = ( + ) + let f262 = ( + ) + let f263 = ( + ) + let f264 = ( + ) + let f265 = ( + ) + let f266 = ( + ) + let f267 = ( + ) + let f268 = ( + ) + let f269 = ( + ) + let f270 = ( + ) + let f271 = ( + ) + let f272 = ( + ) + let f273 = ( + ) + let f274 = ( + ) + let f275 = ( + ) + let f276 = ( + ) + let f277 = ( + ) + let f278 = ( + ) + let f279 = ( + ) + let f280 = ( + ) + let f281 = ( + ) + let f282 = ( + ) + let f283 = ( + ) + let f284 = ( + ) + let f285 = ( + ) + let f286 = ( + ) + let f287 = ( + ) + let f288 = ( + ) + let f289 = ( + ) + let f290 = ( + ) + let f291 = ( + ) + let f292 = ( + ) + let f293 = ( + ) + let f294 = ( + ) + let f295 = ( + ) + let f296 = ( + ) + let f297 = ( + ) + let f298 = ( + ) + let f299 = ( + ) + let f300 = ( + ) + let f301 = ( + ) + let f302 = ( + ) + let f303 = ( + ) + let f304 = ( + ) + let f305 = ( + ) + let f306 = ( + ) + let f307 = ( + ) + let f308 = ( + ) + let f309 = ( + ) + let f310 = ( + ) + let f311 = ( + ) + let f312 = ( + ) + let f313 = ( + ) + let f314 = ( + ) + let f315 = ( + ) + let f316 = ( + ) + let f317 = ( + ) + let f318 = ( + ) + let f319 = ( + ) + let f320 = ( + ) + let f321 = ( + ) + let f322 = ( + ) + let f323 = ( + ) + let f324 = ( + ) + let f325 = ( + ) + let f326 = ( + ) + let f327 = ( + ) + let f328 = ( + ) + let f329 = ( + ) + let f330 = ( + ) + let f331 = ( + ) + let f332 = ( + ) + let f333 = ( + ) + let f334 = ( + ) + let f335 = ( + ) + let f336 = ( + ) + let f337 = ( + ) + let f338 = ( + ) + let f339 = ( + ) + let f340 = ( + ) + let f341 = ( + ) + let f342 = ( + ) + let f343 = ( + ) + let f344 = ( + ) + let f345 = ( + ) + let f346 = ( + ) + let f347 = ( + ) + let f348 = ( + ) + let f349 = ( + ) + let f350 = ( + ) + let f351 = ( + ) + let f352 = ( + ) + let f353 = ( + ) + let f354 = ( + ) + let f355 = ( + ) + let f356 = ( + ) + let f357 = ( + ) + let f358 = ( + ) + let f359 = ( + ) + let f360 = ( + ) + let f361 = ( + ) + let f362 = ( + ) + let f363 = ( + ) + let f364 = ( + ) + let f365 = ( + ) + let f366 = ( + ) + let f367 = ( + ) + let f368 = ( + ) + let f369 = ( + ) + let f370 = ( + ) + let f371 = ( + ) + let f372 = ( + ) + let f373 = ( + ) + let f374 = ( + ) + let f375 = ( + ) + let f376 = ( + ) + let f377 = ( + ) + let f378 = ( + ) + let f379 = ( + ) + let f380 = ( + ) + let f381 = ( + ) + let f382 = ( + ) + let f383 = ( + ) + let f384 = ( + ) + let f385 = ( + ) + let f386 = ( + ) + let f387 = ( + ) + let f388 = ( + ) + let f389 = ( + ) + let f390 = ( + ) + let f391 = ( + ) + let f392 = ( + ) + let f393 = ( + ) + let f394 = ( + ) + let f395 = ( + ) + let f396 = ( + ) + let f397 = ( + ) + let f398 = ( + ) + let f399 = ( + ) + let f400 = ( + ) + let f401 = ( + ) + let f402 = ( + ) + let f403 = ( + ) + let f404 = ( + ) + let f405 = ( + ) + let f406 = ( + ) + let f407 = ( + ) + let f408 = ( + ) + let f409 = ( + ) + let f410 = ( + ) + let f411 = ( + ) + let f412 = ( + ) + let f413 = ( + ) + let f414 = ( + ) + let f415 = ( + ) + let f416 = ( + ) + let f417 = ( + ) + let f418 = ( + ) + let f419 = ( + ) + let f420 = ( + ) + let f421 = ( + ) + let f422 = ( + ) + let f423 = ( + ) + let f424 = ( + ) + let f425 = ( + ) + let f426 = ( + ) + let f427 = ( + ) + let f428 = ( + ) + let f429 = ( + ) + let f430 = ( + ) + let f431 = ( + ) + let f432 = ( + ) + let f433 = ( + ) + let f434 = ( + ) + let f435 = ( + ) + let f436 = ( + ) + let f437 = ( + ) + let f438 = ( + ) + let f439 = ( + ) + let f440 = ( + ) + let f441 = ( + ) + let f442 = ( + ) + let f443 = ( + ) + let f444 = ( + ) + let f445 = ( + ) + let f446 = ( + ) + let f447 = ( + ) + let f448 = ( + ) + let f449 = ( + ) + let f450 = ( + ) + let f451 = ( + ) + let f452 = ( + ) + let f453 = ( + ) + let f454 = ( + ) + let f455 = ( + ) + let f456 = ( + ) + let f457 = ( + ) + let f458 = ( + ) + let f459 = ( + ) + let f460 = ( + ) + let f461 = ( + ) + let f462 = ( + ) + let f463 = ( + ) + let f464 = ( + ) + let f465 = ( + ) + let f466 = ( + ) + let f467 = ( + ) + let f468 = ( + ) + let f469 = ( + ) + let f470 = ( + ) + let f471 = ( + ) + let f472 = ( + ) + let f473 = ( + ) + let f474 = ( + ) + let f475 = ( + ) + let f476 = ( + ) + let f477 = ( + ) + let f478 = ( + ) + let f479 = ( + ) + let f480 = ( + ) + let f481 = ( + ) + let f482 = ( + ) + let f483 = ( + ) + let f484 = ( + ) + let f485 = ( + ) + let f486 = ( + ) + let f487 = ( + ) + let f488 = ( + ) + let f489 = ( + ) + let f490 = ( + ) + let f491 = ( + ) + let f492 = ( + ) + let f493 = ( + ) + let f494 = ( + ) + let f495 = ( + ) + let f496 = ( + ) + let f497 = ( + ) + let f498 = ( + ) + let f499 = ( + ) + let f500 = ( + ) + let f501 = ( + ) + let f502 = ( + ) + let f503 = ( + ) + let f504 = ( + ) + let f505 = ( + ) + let f506 = ( + ) + let f507 = ( + ) + let f508 = ( + ) + let f509 = ( + ) + let f510 = ( + ) + let f511 = ( + ) + let f512 = ( + ) + let f513 = ( + ) + let f514 = ( + ) + let f515 = ( + ) + let f516 = ( + ) + let f517 = ( + ) + let f518 = ( + ) + let f519 = ( + ) + let f520 = ( + ) + let f521 = ( + ) + let f522 = ( + ) + let f523 = ( + ) + let f524 = ( + ) + let f525 = ( + ) + let f526 = ( + ) + let f527 = ( + ) + let f528 = ( + ) + let f529 = ( + ) + let f530 = ( + ) + let f531 = ( + ) + let f532 = ( + ) + let f533 = ( + ) + let f534 = ( + ) + let f535 = ( + ) + let f536 = ( + ) + let f537 = ( + ) + let f538 = ( + ) + let f539 = ( + ) + let f540 = ( + ) + let f541 = ( + ) + let f542 = ( + ) + let f543 = ( + ) + let f544 = ( + ) + let f545 = ( + ) + let f546 = ( + ) + let f547 = ( + ) + let f548 = ( + ) + let f549 = ( + ) + let f550 = ( + ) + let f551 = ( + ) + let f552 = ( + ) + let f553 = ( + ) + let f554 = ( + ) + let f555 = ( + ) + let f556 = ( + ) + let f557 = ( + ) + let f558 = ( + ) + let f559 = ( + ) + let f560 = ( + ) + let f561 = ( + ) + let f562 = ( + ) + let f563 = ( + ) + let f564 = ( + ) + let f565 = ( + ) + let f566 = ( + ) + let f567 = ( + ) + let f568 = ( + ) + let f569 = ( + ) + let f570 = ( + ) + let f571 = ( + ) + let f572 = ( + ) + let f573 = ( + ) + let f574 = ( + ) + let f575 = ( + ) + let f576 = ( + ) + let f577 = ( + ) + let f578 = ( + ) + let f579 = ( + ) + let f580 = ( + ) + let f581 = ( + ) + let f582 = ( + ) + let f583 = ( + ) + let f584 = ( + ) + let f585 = ( + ) + let f586 = ( + ) + let f587 = ( + ) + let f588 = ( + ) + let f589 = ( + ) + let f590 = ( + ) + let f591 = ( + ) + let f592 = ( + ) + let f593 = ( + ) + let f594 = ( + ) + let f595 = ( + ) + let f596 = ( + ) + let f597 = ( + ) + let f598 = ( + ) + let f599 = ( + ) + let f600 = ( + ) + let f601 = ( + ) + let f602 = ( + ) + let f603 = ( + ) + let f604 = ( + ) + let f605 = ( + ) + let f606 = ( + ) + let f607 = ( + ) + let f608 = ( + ) + let f609 = ( + ) + let f610 = ( + ) + let f611 = ( + ) + let f612 = ( + ) + let f613 = ( + ) + let f614 = ( + ) + let f615 = ( + ) + let f616 = ( + ) + let f617 = ( + ) + let f618 = ( + ) + let f619 = ( + ) + let f620 = ( + ) + let f621 = ( + ) + let f622 = ( + ) + let f623 = ( + ) + let f624 = ( + ) + let f625 = ( + ) + let f626 = ( + ) + let f627 = ( + ) + let f628 = ( + ) + let f629 = ( + ) + let f630 = ( + ) + let f631 = ( + ) + let f632 = ( + ) + let f633 = ( + ) + let f634 = ( + ) + let f635 = ( + ) + let f636 = ( + ) + let f637 = ( + ) + let f638 = ( + ) + let f639 = ( + ) + let f640 = ( + ) + let f641 = ( + ) + let f642 = ( + ) + let f643 = ( + ) + let f644 = ( + ) + let f645 = ( + ) + let f646 = ( + ) + let f647 = ( + ) + let f648 = ( + ) + let f649 = ( + ) + let f650 = ( + ) + let f651 = ( + ) + let f652 = ( + ) + let f653 = ( + ) + let f654 = ( + ) + let f655 = ( + ) + let f656 = ( + ) + let f657 = ( + ) + let f658 = ( + ) + let f659 = ( + ) + let f660 = ( + ) + let f661 = ( + ) + let f662 = ( + ) + let f663 = ( + ) + let f664 = ( + ) + let f665 = ( + ) + let f666 = ( + ) + let f667 = ( + ) + let f668 = ( + ) + let f669 = ( + ) + let f670 = ( + ) + let f671 = ( + ) + let f672 = ( + ) + let f673 = ( + ) + let f674 = ( + ) + let f675 = ( + ) + let f676 = ( + ) + let f677 = ( + ) + let f678 = ( + ) + let f679 = ( + ) + let f680 = ( + ) + let f681 = ( + ) + let f682 = ( + ) + let f683 = ( + ) + let f684 = ( + ) + let f685 = ( + ) + let f686 = ( + ) + let f687 = ( + ) + let f688 = ( + ) + let f689 = ( + ) + let f690 = ( + ) + let f691 = ( + ) + let f692 = ( + ) + let f693 = ( + ) + let f694 = ( + ) + let f695 = ( + ) + let f696 = ( + ) + let f697 = ( + ) + let f698 = ( + ) + let f699 = ( + ) + let f700 = ( + ) + let f701 = ( + ) + let f702 = ( + ) + let f703 = ( + ) + let f704 = ( + ) + let f705 = ( + ) + let f706 = ( + ) + let f707 = ( + ) + let f708 = ( + ) + let f709 = ( + ) + let f710 = ( + ) + let f711 = ( + ) + let f712 = ( + ) + let f713 = ( + ) + let f714 = ( + ) + let f715 = ( + ) + let f716 = ( + ) + let f717 = ( + ) + let f718 = ( + ) + let f719 = ( + ) + let f720 = ( + ) + let f721 = ( + ) + let f722 = ( + ) + let f723 = ( + ) + let f724 = ( + ) + let f725 = ( + ) + let f726 = ( + ) + let f727 = ( + ) + let f728 = ( + ) + let f729 = ( + ) + let f730 = ( + ) + let f731 = ( + ) + let f732 = ( + ) + let f733 = ( + ) + let f734 = ( + ) + let f735 = ( + ) + let f736 = ( + ) + let f737 = ( + ) + let f738 = ( + ) + let f739 = ( + ) + let f740 = ( + ) + let f741 = ( + ) + let f742 = ( + ) + let f743 = ( + ) + let f744 = ( + ) + let f745 = ( + ) + let f746 = ( + ) + let f747 = ( + ) + let f748 = ( + ) + let f749 = ( + ) + let f750 = ( + ) + let f751 = ( + ) + let f752 = ( + ) + let f753 = ( + ) + let f754 = ( + ) + let f755 = ( + ) + let f756 = ( + ) + let f757 = ( + ) + let f758 = ( + ) + let f759 = ( + ) + let f760 = ( + ) + let f761 = ( + ) + let f762 = ( + ) + let f763 = ( + ) + let f764 = ( + ) + let f765 = ( + ) + let f766 = ( + ) + let f767 = ( + ) + let f768 = ( + ) + let f769 = ( + ) + let f770 = ( + ) + let f771 = ( + ) + let f772 = ( + ) + let f773 = ( + ) + let f774 = ( + ) + let f775 = ( + ) + let f776 = ( + ) + let f777 = ( + ) + let f778 = ( + ) + let f779 = ( + ) + let f780 = ( + ) + let f781 = ( + ) + let f782 = ( + ) + let f783 = ( + ) + let f784 = ( + ) + let f785 = ( + ) + let f786 = ( + ) + let f787 = ( + ) + let f788 = ( + ) + let f789 = ( + ) + let f790 = ( + ) + let f791 = ( + ) + let f792 = ( + ) + let f793 = ( + ) + let f794 = ( + ) + let f795 = ( + ) + let f796 = ( + ) + let f797 = ( + ) + let f798 = ( + ) + let f799 = ( + ) + let f800 = ( + ) + let f801 = ( + ) + let f802 = ( + ) + let f803 = ( + ) + let f804 = ( + ) + let f805 = ( + ) + let f806 = ( + ) + let f807 = ( + ) + let f808 = ( + ) + let f809 = ( + ) + let f810 = ( + ) + let f811 = ( + ) + let f812 = ( + ) + let f813 = ( + ) + let f814 = ( + ) + let f815 = ( + ) + let f816 = ( + ) + let f817 = ( + ) + let f818 = ( + ) + let f819 = ( + ) + let f820 = ( + ) + let f821 = ( + ) + let f822 = ( + ) + let f823 = ( + ) + let f824 = ( + ) + let f825 = ( + ) + let f826 = ( + ) + let f827 = ( + ) + let f828 = ( + ) + let f829 = ( + ) + let f830 = ( + ) + let f831 = ( + ) + let f832 = ( + ) + let f833 = ( + ) + let f834 = ( + ) + let f835 = ( + ) + let f836 = ( + ) + let f837 = ( + ) + let f838 = ( + ) + let f839 = ( + ) + let f840 = ( + ) + let f841 = ( + ) + let f842 = ( + ) + let f843 = ( + ) + let f844 = ( + ) + let f845 = ( + ) + let f846 = ( + ) + let f847 = ( + ) + let f848 = ( + ) + let f849 = ( + ) + let f850 = ( + ) + let f851 = ( + ) + let f852 = ( + ) + let f853 = ( + ) + let f854 = ( + ) + let f855 = ( + ) + let f856 = ( + ) + let f857 = ( + ) + let f858 = ( + ) + let f859 = ( + ) + let f860 = ( + ) + let f861 = ( + ) + let f862 = ( + ) + let f863 = ( + ) + let f864 = ( + ) + let f865 = ( + ) + let f866 = ( + ) + let f867 = ( + ) + let f868 = ( + ) + let f869 = ( + ) + let f870 = ( + ) + let f871 = ( + ) + let f872 = ( + ) + let f873 = ( + ) + let f874 = ( + ) + let f875 = ( + ) + let f876 = ( + ) + let f877 = ( + ) + let f878 = ( + ) + let f879 = ( + ) + let f880 = ( + ) + let f881 = ( + ) + let f882 = ( + ) + let f883 = ( + ) + let f884 = ( + ) + let f885 = ( + ) + let f886 = ( + ) + let f887 = ( + ) + let f888 = ( + ) + let f889 = ( + ) + let f890 = ( + ) + let f891 = ( + ) + let f892 = ( + ) + let f893 = ( + ) + let f894 = ( + ) + let f895 = ( + ) + let f896 = ( + ) + let f897 = ( + ) + let f898 = ( + ) + let f899 = ( + ) + let f900 = ( + ) + let f901 = ( + ) + let f902 = ( + ) + let f903 = ( + ) + let f904 = ( + ) + let f905 = ( + ) + let f906 = ( + ) + let f907 = ( + ) + let f908 = ( + ) + let f909 = ( + ) + let f910 = ( + ) + let f911 = ( + ) + let f912 = ( + ) + let f913 = ( + ) + let f914 = ( + ) + let f915 = ( + ) + let f916 = ( + ) + let f917 = ( + ) + let f918 = ( + ) + let f919 = ( + ) + let f920 = ( + ) + let f921 = ( + ) + let f922 = ( + ) + let f923 = ( + ) + let f924 = ( + ) + let f925 = ( + ) + let f926 = ( + ) + let f927 = ( + ) + let f928 = ( + ) + let f929 = ( + ) + let f930 = ( + ) + let f931 = ( + ) + let f932 = ( + ) + let f933 = ( + ) + let f934 = ( + ) + let f935 = ( + ) + let f936 = ( + ) + let f937 = ( + ) + let f938 = ( + ) + let f939 = ( + ) + let f940 = ( + ) + let f941 = ( + ) + let f942 = ( + ) + let f943 = ( + ) + let f944 = ( + ) + let f945 = ( + ) + let f946 = ( + ) + let f947 = ( + ) + let f948 = ( + ) + let f949 = ( + ) + let f950 = ( + ) + let f951 = ( + ) + let f952 = ( + ) + let f953 = ( + ) + let f954 = ( + ) + let f955 = ( + ) + let f956 = ( + ) + let f957 = ( + ) + let f958 = ( + ) + let f959 = ( + ) + let f960 = ( + ) + let f961 = ( + ) + let f962 = ( + ) + let f963 = ( + ) + let f964 = ( + ) + let f965 = ( + ) + let f966 = ( + ) + let f967 = ( + ) + let f968 = ( + ) + let f969 = ( + ) + let f970 = ( + ) + let f971 = ( + ) + let f972 = ( + ) + let f973 = ( + ) + let f974 = ( + ) + let f975 = ( + ) + let f976 = ( + ) + let f977 = ( + ) + let f978 = ( + ) + let f979 = ( + ) + let f980 = ( + ) + let f981 = ( + ) + let f982 = ( + ) + let f983 = ( + ) + let f984 = ( + ) + let f985 = ( + ) + let f986 = ( + ) + let f987 = ( + ) + let f988 = ( + ) + let f989 = ( + ) + let f990 = ( + ) + let f991 = ( + ) + let f992 = ( + ) + let f993 = ( + ) + let f994 = ( + ) + let f995 = ( + ) + let f996 = ( + ) + let f997 = ( + ) + let f998 = ( + ) + let f999 = ( + ) + let f1000 = ( + ) +end + +module X = Make(Make(Make(M))) diff --git a/camlp4/test/fixtures/functor-perf2.gen.ml b/camlp4/test/fixtures/functor-perf2.gen.ml new file mode 100644 index 0000000..730a1bf --- /dev/null +++ b/camlp4/test/fixtures/functor-perf2.gen.ml @@ -0,0 +1,3029 @@ + + +module type S = sig + type t0 + type t1 + type t2 + type t3 + type t4 + type t5 + type t6 + type t7 + type t8 + type t9 + type t10 + type t11 + type t12 + type t13 + type t14 + type t15 + type t16 + type t17 + type t18 + type t19 + type t20 + type t21 + type t22 + type t23 + type t24 + type t25 + type t26 + type t27 + type t28 + type t29 + type t30 + type t31 + type t32 + type t33 + type t34 + type t35 + type t36 + type t37 + type t38 + type t39 + type t40 + type t41 + type t42 + type t43 + type t44 + type t45 + type t46 + type t47 + type t48 + type t49 + type t50 + type t51 + type t52 + type t53 + type t54 + type t55 + type t56 + type t57 + type t58 + type t59 + type t60 + type t61 + type t62 + type t63 + type t64 + type t65 + type t66 + type t67 + type t68 + type t69 + type t70 + type t71 + type t72 + type t73 + type t74 + type t75 + type t76 + type t77 + type t78 + type t79 + type t80 + type t81 + type t82 + type t83 + type t84 + type t85 + type t86 + type t87 + type t88 + type t89 + type t90 + type t91 + type t92 + type t93 + type t94 + type t95 + type t96 + type t97 + type t98 + type t99 + type t100 + type t101 + type t102 + type t103 + type t104 + type t105 + type t106 + type t107 + type t108 + type t109 + type t110 + type t111 + type t112 + type t113 + type t114 + type t115 + type t116 + type t117 + type t118 + type t119 + type t120 + type t121 + type t122 + type t123 + type t124 + type t125 + type t126 + type t127 + type t128 + type t129 + type t130 + type t131 + type t132 + type t133 + type t134 + type t135 + type t136 + type t137 + type t138 + type t139 + type t140 + type t141 + type t142 + type t143 + type t144 + type t145 + type t146 + type t147 + type t148 + type t149 + type t150 + type t151 + type t152 + type t153 + type t154 + type t155 + type t156 + type t157 + type t158 + type t159 + type t160 + type t161 + type t162 + type t163 + type t164 + type t165 + type t166 + type t167 + type t168 + type t169 + type t170 + type t171 + type t172 + type t173 + type t174 + type t175 + type t176 + type t177 + type t178 + type t179 + type t180 + type t181 + type t182 + type t183 + type t184 + type t185 + type t186 + type t187 + type t188 + type t189 + type t190 + type t191 + type t192 + type t193 + type t194 + type t195 + type t196 + type t197 + type t198 + type t199 + type t200 + type t201 + type t202 + type t203 + type t204 + type t205 + type t206 + type t207 + type t208 + type t209 + type t210 + type t211 + type t212 + type t213 + type t214 + type t215 + type t216 + type t217 + type t218 + type t219 + type t220 + type t221 + type t222 + type t223 + type t224 + type t225 + type t226 + type t227 + type t228 + type t229 + type t230 + type t231 + type t232 + type t233 + type t234 + type t235 + type t236 + type t237 + type t238 + type t239 + type t240 + type t241 + type t242 + type t243 + type t244 + type t245 + type t246 + type t247 + type t248 + type t249 + type t250 + type t251 + type t252 + type t253 + type t254 + type t255 + type t256 + type t257 + type t258 + type t259 + type t260 + type t261 + type t262 + type t263 + type t264 + type t265 + type t266 + type t267 + type t268 + type t269 + type t270 + type t271 + type t272 + type t273 + type t274 + type t275 + type t276 + type t277 + type t278 + type t279 + type t280 + type t281 + type t282 + type t283 + type t284 + type t285 + type t286 + type t287 + type t288 + type t289 + type t290 + type t291 + type t292 + type t293 + type t294 + type t295 + type t296 + type t297 + type t298 + type t299 + type t300 + type t301 + type t302 + type t303 + type t304 + type t305 + type t306 + type t307 + type t308 + type t309 + type t310 + type t311 + type t312 + type t313 + type t314 + type t315 + type t316 + type t317 + type t318 + type t319 + type t320 + type t321 + type t322 + type t323 + type t324 + type t325 + type t326 + type t327 + type t328 + type t329 + type t330 + type t331 + type t332 + type t333 + type t334 + type t335 + type t336 + type t337 + type t338 + type t339 + type t340 + type t341 + type t342 + type t343 + type t344 + type t345 + type t346 + type t347 + type t348 + type t349 + type t350 + type t351 + type t352 + type t353 + type t354 + type t355 + type t356 + type t357 + type t358 + type t359 + type t360 + type t361 + type t362 + type t363 + type t364 + type t365 + type t366 + type t367 + type t368 + type t369 + type t370 + type t371 + type t372 + type t373 + type t374 + type t375 + type t376 + type t377 + type t378 + type t379 + type t380 + type t381 + type t382 + type t383 + type t384 + type t385 + type t386 + type t387 + type t388 + type t389 + type t390 + type t391 + type t392 + type t393 + type t394 + type t395 + type t396 + type t397 + type t398 + type t399 + type t400 + type t401 + type t402 + type t403 + type t404 + type t405 + type t406 + type t407 + type t408 + type t409 + type t410 + type t411 + type t412 + type t413 + type t414 + type t415 + type t416 + type t417 + type t418 + type t419 + type t420 + type t421 + type t422 + type t423 + type t424 + type t425 + type t426 + type t427 + type t428 + type t429 + type t430 + type t431 + type t432 + type t433 + type t434 + type t435 + type t436 + type t437 + type t438 + type t439 + type t440 + type t441 + type t442 + type t443 + type t444 + type t445 + type t446 + type t447 + type t448 + type t449 + type t450 + type t451 + type t452 + type t453 + type t454 + type t455 + type t456 + type t457 + type t458 + type t459 + type t460 + type t461 + type t462 + type t463 + type t464 + type t465 + type t466 + type t467 + type t468 + type t469 + type t470 + type t471 + type t472 + type t473 + type t474 + type t475 + type t476 + type t477 + type t478 + type t479 + type t480 + type t481 + type t482 + type t483 + type t484 + type t485 + type t486 + type t487 + type t488 + type t489 + type t490 + type t491 + type t492 + type t493 + type t494 + type t495 + type t496 + type t497 + type t498 + type t499 + type t500 + type t501 + type t502 + type t503 + type t504 + type t505 + type t506 + type t507 + type t508 + type t509 + type t510 + type t511 + type t512 + type t513 + type t514 + type t515 + type t516 + type t517 + type t518 + type t519 + type t520 + type t521 + type t522 + type t523 + type t524 + type t525 + type t526 + type t527 + type t528 + type t529 + type t530 + type t531 + type t532 + type t533 + type t534 + type t535 + type t536 + type t537 + type t538 + type t539 + type t540 + type t541 + type t542 + type t543 + type t544 + type t545 + type t546 + type t547 + type t548 + type t549 + type t550 + type t551 + type t552 + type t553 + type t554 + type t555 + type t556 + type t557 + type t558 + type t559 + type t560 + type t561 + type t562 + type t563 + type t564 + type t565 + type t566 + type t567 + type t568 + type t569 + type t570 + type t571 + type t572 + type t573 + type t574 + type t575 + type t576 + type t577 + type t578 + type t579 + type t580 + type t581 + type t582 + type t583 + type t584 + type t585 + type t586 + type t587 + type t588 + type t589 + type t590 + type t591 + type t592 + type t593 + type t594 + type t595 + type t596 + type t597 + type t598 + type t599 + type t600 + type t601 + type t602 + type t603 + type t604 + type t605 + type t606 + type t607 + type t608 + type t609 + type t610 + type t611 + type t612 + type t613 + type t614 + type t615 + type t616 + type t617 + type t618 + type t619 + type t620 + type t621 + type t622 + type t623 + type t624 + type t625 + type t626 + type t627 + type t628 + type t629 + type t630 + type t631 + type t632 + type t633 + type t634 + type t635 + type t636 + type t637 + type t638 + type t639 + type t640 + type t641 + type t642 + type t643 + type t644 + type t645 + type t646 + type t647 + type t648 + type t649 + type t650 + type t651 + type t652 + type t653 + type t654 + type t655 + type t656 + type t657 + type t658 + type t659 + type t660 + type t661 + type t662 + type t663 + type t664 + type t665 + type t666 + type t667 + type t668 + type t669 + type t670 + type t671 + type t672 + type t673 + type t674 + type t675 + type t676 + type t677 + type t678 + type t679 + type t680 + type t681 + type t682 + type t683 + type t684 + type t685 + type t686 + type t687 + type t688 + type t689 + type t690 + type t691 + type t692 + type t693 + type t694 + type t695 + type t696 + type t697 + type t698 + type t699 + type t700 + type t701 + type t702 + type t703 + type t704 + type t705 + type t706 + type t707 + type t708 + type t709 + type t710 + type t711 + type t712 + type t713 + type t714 + type t715 + type t716 + type t717 + type t718 + type t719 + type t720 + type t721 + type t722 + type t723 + type t724 + type t725 + type t726 + type t727 + type t728 + type t729 + type t730 + type t731 + type t732 + type t733 + type t734 + type t735 + type t736 + type t737 + type t738 + type t739 + type t740 + type t741 + type t742 + type t743 + type t744 + type t745 + type t746 + type t747 + type t748 + type t749 + type t750 + type t751 + type t752 + type t753 + type t754 + type t755 + type t756 + type t757 + type t758 + type t759 + type t760 + type t761 + type t762 + type t763 + type t764 + type t765 + type t766 + type t767 + type t768 + type t769 + type t770 + type t771 + type t772 + type t773 + type t774 + type t775 + type t776 + type t777 + type t778 + type t779 + type t780 + type t781 + type t782 + type t783 + type t784 + type t785 + type t786 + type t787 + type t788 + type t789 + type t790 + type t791 + type t792 + type t793 + type t794 + type t795 + type t796 + type t797 + type t798 + type t799 + type t800 + type t801 + type t802 + type t803 + type t804 + type t805 + type t806 + type t807 + type t808 + type t809 + type t810 + type t811 + type t812 + type t813 + type t814 + type t815 + type t816 + type t817 + type t818 + type t819 + type t820 + type t821 + type t822 + type t823 + type t824 + type t825 + type t826 + type t827 + type t828 + type t829 + type t830 + type t831 + type t832 + type t833 + type t834 + type t835 + type t836 + type t837 + type t838 + type t839 + type t840 + type t841 + type t842 + type t843 + type t844 + type t845 + type t846 + type t847 + type t848 + type t849 + type t850 + type t851 + type t852 + type t853 + type t854 + type t855 + type t856 + type t857 + type t858 + type t859 + type t860 + type t861 + type t862 + type t863 + type t864 + type t865 + type t866 + type t867 + type t868 + type t869 + type t870 + type t871 + type t872 + type t873 + type t874 + type t875 + type t876 + type t877 + type t878 + type t879 + type t880 + type t881 + type t882 + type t883 + type t884 + type t885 + type t886 + type t887 + type t888 + type t889 + type t890 + type t891 + type t892 + type t893 + type t894 + type t895 + type t896 + type t897 + type t898 + type t899 + type t900 + type t901 + type t902 + type t903 + type t904 + type t905 + type t906 + type t907 + type t908 + type t909 + type t910 + type t911 + type t912 + type t913 + type t914 + type t915 + type t916 + type t917 + type t918 + type t919 + type t920 + type t921 + type t922 + type t923 + type t924 + type t925 + type t926 + type t927 + type t928 + type t929 + type t930 + type t931 + type t932 + type t933 + type t934 + type t935 + type t936 + type t937 + type t938 + type t939 + type t940 + type t941 + type t942 + type t943 + type t944 + type t945 + type t946 + type t947 + type t948 + type t949 + type t950 + type t951 + type t952 + type t953 + type t954 + type t955 + type t956 + type t957 + type t958 + type t959 + type t960 + type t961 + type t962 + type t963 + type t964 + type t965 + type t966 + type t967 + type t968 + type t969 + type t970 + type t971 + type t972 + type t973 + type t974 + type t975 + type t976 + type t977 + type t978 + type t979 + type t980 + type t981 + type t982 + type t983 + type t984 + type t985 + type t986 + type t987 + type t988 + type t989 + type t990 + type t991 + type t992 + type t993 + type t994 + type t995 + type t996 + type t997 + type t998 + type t999 + type t1000 +end + +module Make (M : S) +: S with type t0 = M.t0 + and type t1 = M.t1 + and type t2 = M.t2 + and type t3 = M.t3 + and type t4 = M.t4 + and type t5 = M.t5 + and type t6 = M.t6 + and type t7 = M.t7 + and type t8 = M.t8 + and type t9 = M.t9 + and type t10 = M.t10 + and type t11 = M.t11 + and type t12 = M.t12 + and type t13 = M.t13 + and type t14 = M.t14 + and type t15 = M.t15 + and type t16 = M.t16 + and type t17 = M.t17 + and type t18 = M.t18 + and type t19 = M.t19 + and type t20 = M.t20 + and type t21 = M.t21 + and type t22 = M.t22 + and type t23 = M.t23 + and type t24 = M.t24 + and type t25 = M.t25 + and type t26 = M.t26 + and type t27 = M.t27 + and type t28 = M.t28 + and type t29 = M.t29 + and type t30 = M.t30 + and type t31 = M.t31 + and type t32 = M.t32 + and type t33 = M.t33 + and type t34 = M.t34 + and type t35 = M.t35 + and type t36 = M.t36 + and type t37 = M.t37 + and type t38 = M.t38 + and type t39 = M.t39 + and type t40 = M.t40 + and type t41 = M.t41 + and type t42 = M.t42 + and type t43 = M.t43 + and type t44 = M.t44 + and type t45 = M.t45 + and type t46 = M.t46 + and type t47 = M.t47 + and type t48 = M.t48 + and type t49 = M.t49 + and type t50 = M.t50 + and type t51 = M.t51 + and type t52 = M.t52 + and type t53 = M.t53 + and type t54 = M.t54 + and type t55 = M.t55 + and type t56 = M.t56 + and type t57 = M.t57 + and type t58 = M.t58 + and type t59 = M.t59 + and type t60 = M.t60 + and type t61 = M.t61 + and type t62 = M.t62 + and type t63 = M.t63 + and type t64 = M.t64 + and type t65 = M.t65 + and type t66 = M.t66 + and type t67 = M.t67 + and type t68 = M.t68 + and type t69 = M.t69 + and type t70 = M.t70 + and type t71 = M.t71 + and type t72 = M.t72 + and type t73 = M.t73 + and type t74 = M.t74 + and type t75 = M.t75 + and type t76 = M.t76 + and type t77 = M.t77 + and type t78 = M.t78 + and type t79 = M.t79 + and type t80 = M.t80 + and type t81 = M.t81 + and type t82 = M.t82 + and type t83 = M.t83 + and type t84 = M.t84 + and type t85 = M.t85 + and type t86 = M.t86 + and type t87 = M.t87 + and type t88 = M.t88 + and type t89 = M.t89 + and type t90 = M.t90 + and type t91 = M.t91 + and type t92 = M.t92 + and type t93 = M.t93 + and type t94 = M.t94 + and type t95 = M.t95 + and type t96 = M.t96 + and type t97 = M.t97 + and type t98 = M.t98 + and type t99 = M.t99 + and type t100 = M.t100 + and type t101 = M.t101 + and type t102 = M.t102 + and type t103 = M.t103 + and type t104 = M.t104 + and type t105 = M.t105 + and type t106 = M.t106 + and type t107 = M.t107 + and type t108 = M.t108 + and type t109 = M.t109 + and type t110 = M.t110 + and type t111 = M.t111 + and type t112 = M.t112 + and type t113 = M.t113 + and type t114 = M.t114 + and type t115 = M.t115 + and type t116 = M.t116 + and type t117 = M.t117 + and type t118 = M.t118 + and type t119 = M.t119 + and type t120 = M.t120 + and type t121 = M.t121 + and type t122 = M.t122 + and type t123 = M.t123 + and type t124 = M.t124 + and type t125 = M.t125 + and type t126 = M.t126 + and type t127 = M.t127 + and type t128 = M.t128 + and type t129 = M.t129 + and type t130 = M.t130 + and type t131 = M.t131 + and type t132 = M.t132 + and type t133 = M.t133 + and type t134 = M.t134 + and type t135 = M.t135 + and type t136 = M.t136 + and type t137 = M.t137 + and type t138 = M.t138 + and type t139 = M.t139 + and type t140 = M.t140 + and type t141 = M.t141 + and type t142 = M.t142 + and type t143 = M.t143 + and type t144 = M.t144 + and type t145 = M.t145 + and type t146 = M.t146 + and type t147 = M.t147 + and type t148 = M.t148 + and type t149 = M.t149 + and type t150 = M.t150 + and type t151 = M.t151 + and type t152 = M.t152 + and type t153 = M.t153 + and type t154 = M.t154 + and type t155 = M.t155 + and type t156 = M.t156 + and type t157 = M.t157 + and type t158 = M.t158 + and type t159 = M.t159 + and type t160 = M.t160 + and type t161 = M.t161 + and type t162 = M.t162 + and type t163 = M.t163 + and type t164 = M.t164 + and type t165 = M.t165 + and type t166 = M.t166 + and type t167 = M.t167 + and type t168 = M.t168 + and type t169 = M.t169 + and type t170 = M.t170 + and type t171 = M.t171 + and type t172 = M.t172 + and type t173 = M.t173 + and type t174 = M.t174 + and type t175 = M.t175 + and type t176 = M.t176 + and type t177 = M.t177 + and type t178 = M.t178 + and type t179 = M.t179 + and type t180 = M.t180 + and type t181 = M.t181 + and type t182 = M.t182 + and type t183 = M.t183 + and type t184 = M.t184 + and type t185 = M.t185 + and type t186 = M.t186 + and type t187 = M.t187 + and type t188 = M.t188 + and type t189 = M.t189 + and type t190 = M.t190 + and type t191 = M.t191 + and type t192 = M.t192 + and type t193 = M.t193 + and type t194 = M.t194 + and type t195 = M.t195 + and type t196 = M.t196 + and type t197 = M.t197 + and type t198 = M.t198 + and type t199 = M.t199 + and type t200 = M.t200 + and type t201 = M.t201 + and type t202 = M.t202 + and type t203 = M.t203 + and type t204 = M.t204 + and type t205 = M.t205 + and type t206 = M.t206 + and type t207 = M.t207 + and type t208 = M.t208 + and type t209 = M.t209 + and type t210 = M.t210 + and type t211 = M.t211 + and type t212 = M.t212 + and type t213 = M.t213 + and type t214 = M.t214 + and type t215 = M.t215 + and type t216 = M.t216 + and type t217 = M.t217 + and type t218 = M.t218 + and type t219 = M.t219 + and type t220 = M.t220 + and type t221 = M.t221 + and type t222 = M.t222 + and type t223 = M.t223 + and type t224 = M.t224 + and type t225 = M.t225 + and type t226 = M.t226 + and type t227 = M.t227 + and type t228 = M.t228 + and type t229 = M.t229 + and type t230 = M.t230 + and type t231 = M.t231 + and type t232 = M.t232 + and type t233 = M.t233 + and type t234 = M.t234 + and type t235 = M.t235 + and type t236 = M.t236 + and type t237 = M.t237 + and type t238 = M.t238 + and type t239 = M.t239 + and type t240 = M.t240 + and type t241 = M.t241 + and type t242 = M.t242 + and type t243 = M.t243 + and type t244 = M.t244 + and type t245 = M.t245 + and type t246 = M.t246 + and type t247 = M.t247 + and type t248 = M.t248 + and type t249 = M.t249 + and type t250 = M.t250 + and type t251 = M.t251 + and type t252 = M.t252 + and type t253 = M.t253 + and type t254 = M.t254 + and type t255 = M.t255 + and type t256 = M.t256 + and type t257 = M.t257 + and type t258 = M.t258 + and type t259 = M.t259 + and type t260 = M.t260 + and type t261 = M.t261 + and type t262 = M.t262 + and type t263 = M.t263 + and type t264 = M.t264 + and type t265 = M.t265 + and type t266 = M.t266 + and type t267 = M.t267 + and type t268 = M.t268 + and type t269 = M.t269 + and type t270 = M.t270 + and type t271 = M.t271 + and type t272 = M.t272 + and type t273 = M.t273 + and type t274 = M.t274 + and type t275 = M.t275 + and type t276 = M.t276 + and type t277 = M.t277 + and type t278 = M.t278 + and type t279 = M.t279 + and type t280 = M.t280 + and type t281 = M.t281 + and type t282 = M.t282 + and type t283 = M.t283 + and type t284 = M.t284 + and type t285 = M.t285 + and type t286 = M.t286 + and type t287 = M.t287 + and type t288 = M.t288 + and type t289 = M.t289 + and type t290 = M.t290 + and type t291 = M.t291 + and type t292 = M.t292 + and type t293 = M.t293 + and type t294 = M.t294 + and type t295 = M.t295 + and type t296 = M.t296 + and type t297 = M.t297 + and type t298 = M.t298 + and type t299 = M.t299 + and type t300 = M.t300 + and type t301 = M.t301 + and type t302 = M.t302 + and type t303 = M.t303 + and type t304 = M.t304 + and type t305 = M.t305 + and type t306 = M.t306 + and type t307 = M.t307 + and type t308 = M.t308 + and type t309 = M.t309 + and type t310 = M.t310 + and type t311 = M.t311 + and type t312 = M.t312 + and type t313 = M.t313 + and type t314 = M.t314 + and type t315 = M.t315 + and type t316 = M.t316 + and type t317 = M.t317 + and type t318 = M.t318 + and type t319 = M.t319 + and type t320 = M.t320 + and type t321 = M.t321 + and type t322 = M.t322 + and type t323 = M.t323 + and type t324 = M.t324 + and type t325 = M.t325 + and type t326 = M.t326 + and type t327 = M.t327 + and type t328 = M.t328 + and type t329 = M.t329 + and type t330 = M.t330 + and type t331 = M.t331 + and type t332 = M.t332 + and type t333 = M.t333 + and type t334 = M.t334 + and type t335 = M.t335 + and type t336 = M.t336 + and type t337 = M.t337 + and type t338 = M.t338 + and type t339 = M.t339 + and type t340 = M.t340 + and type t341 = M.t341 + and type t342 = M.t342 + and type t343 = M.t343 + and type t344 = M.t344 + and type t345 = M.t345 + and type t346 = M.t346 + and type t347 = M.t347 + and type t348 = M.t348 + and type t349 = M.t349 + and type t350 = M.t350 + and type t351 = M.t351 + and type t352 = M.t352 + and type t353 = M.t353 + and type t354 = M.t354 + and type t355 = M.t355 + and type t356 = M.t356 + and type t357 = M.t357 + and type t358 = M.t358 + and type t359 = M.t359 + and type t360 = M.t360 + and type t361 = M.t361 + and type t362 = M.t362 + and type t363 = M.t363 + and type t364 = M.t364 + and type t365 = M.t365 + and type t366 = M.t366 + and type t367 = M.t367 + and type t368 = M.t368 + and type t369 = M.t369 + and type t370 = M.t370 + and type t371 = M.t371 + and type t372 = M.t372 + and type t373 = M.t373 + and type t374 = M.t374 + and type t375 = M.t375 + and type t376 = M.t376 + and type t377 = M.t377 + and type t378 = M.t378 + and type t379 = M.t379 + and type t380 = M.t380 + and type t381 = M.t381 + and type t382 = M.t382 + and type t383 = M.t383 + and type t384 = M.t384 + and type t385 = M.t385 + and type t386 = M.t386 + and type t387 = M.t387 + and type t388 = M.t388 + and type t389 = M.t389 + and type t390 = M.t390 + and type t391 = M.t391 + and type t392 = M.t392 + and type t393 = M.t393 + and type t394 = M.t394 + and type t395 = M.t395 + and type t396 = M.t396 + and type t397 = M.t397 + and type t398 = M.t398 + and type t399 = M.t399 + and type t400 = M.t400 + and type t401 = M.t401 + and type t402 = M.t402 + and type t403 = M.t403 + and type t404 = M.t404 + and type t405 = M.t405 + and type t406 = M.t406 + and type t407 = M.t407 + and type t408 = M.t408 + and type t409 = M.t409 + and type t410 = M.t410 + and type t411 = M.t411 + and type t412 = M.t412 + and type t413 = M.t413 + and type t414 = M.t414 + and type t415 = M.t415 + and type t416 = M.t416 + and type t417 = M.t417 + and type t418 = M.t418 + and type t419 = M.t419 + and type t420 = M.t420 + and type t421 = M.t421 + and type t422 = M.t422 + and type t423 = M.t423 + and type t424 = M.t424 + and type t425 = M.t425 + and type t426 = M.t426 + and type t427 = M.t427 + and type t428 = M.t428 + and type t429 = M.t429 + and type t430 = M.t430 + and type t431 = M.t431 + and type t432 = M.t432 + and type t433 = M.t433 + and type t434 = M.t434 + and type t435 = M.t435 + and type t436 = M.t436 + and type t437 = M.t437 + and type t438 = M.t438 + and type t439 = M.t439 + and type t440 = M.t440 + and type t441 = M.t441 + and type t442 = M.t442 + and type t443 = M.t443 + and type t444 = M.t444 + and type t445 = M.t445 + and type t446 = M.t446 + and type t447 = M.t447 + and type t448 = M.t448 + and type t449 = M.t449 + and type t450 = M.t450 + and type t451 = M.t451 + and type t452 = M.t452 + and type t453 = M.t453 + and type t454 = M.t454 + and type t455 = M.t455 + and type t456 = M.t456 + and type t457 = M.t457 + and type t458 = M.t458 + and type t459 = M.t459 + and type t460 = M.t460 + and type t461 = M.t461 + and type t462 = M.t462 + and type t463 = M.t463 + and type t464 = M.t464 + and type t465 = M.t465 + and type t466 = M.t466 + and type t467 = M.t467 + and type t468 = M.t468 + and type t469 = M.t469 + and type t470 = M.t470 + and type t471 = M.t471 + and type t472 = M.t472 + and type t473 = M.t473 + and type t474 = M.t474 + and type t475 = M.t475 + and type t476 = M.t476 + and type t477 = M.t477 + and type t478 = M.t478 + and type t479 = M.t479 + and type t480 = M.t480 + and type t481 = M.t481 + and type t482 = M.t482 + and type t483 = M.t483 + and type t484 = M.t484 + and type t485 = M.t485 + and type t486 = M.t486 + and type t487 = M.t487 + and type t488 = M.t488 + and type t489 = M.t489 + and type t490 = M.t490 + and type t491 = M.t491 + and type t492 = M.t492 + and type t493 = M.t493 + and type t494 = M.t494 + and type t495 = M.t495 + and type t496 = M.t496 + and type t497 = M.t497 + and type t498 = M.t498 + and type t499 = M.t499 + and type t500 = M.t500 + and type t501 = M.t501 + and type t502 = M.t502 + and type t503 = M.t503 + and type t504 = M.t504 + and type t505 = M.t505 + and type t506 = M.t506 + and type t507 = M.t507 + and type t508 = M.t508 + and type t509 = M.t509 + and type t510 = M.t510 + and type t511 = M.t511 + and type t512 = M.t512 + and type t513 = M.t513 + and type t514 = M.t514 + and type t515 = M.t515 + and type t516 = M.t516 + and type t517 = M.t517 + and type t518 = M.t518 + and type t519 = M.t519 + and type t520 = M.t520 + and type t521 = M.t521 + and type t522 = M.t522 + and type t523 = M.t523 + and type t524 = M.t524 + and type t525 = M.t525 + and type t526 = M.t526 + and type t527 = M.t527 + and type t528 = M.t528 + and type t529 = M.t529 + and type t530 = M.t530 + and type t531 = M.t531 + and type t532 = M.t532 + and type t533 = M.t533 + and type t534 = M.t534 + and type t535 = M.t535 + and type t536 = M.t536 + and type t537 = M.t537 + and type t538 = M.t538 + and type t539 = M.t539 + and type t540 = M.t540 + and type t541 = M.t541 + and type t542 = M.t542 + and type t543 = M.t543 + and type t544 = M.t544 + and type t545 = M.t545 + and type t546 = M.t546 + and type t547 = M.t547 + and type t548 = M.t548 + and type t549 = M.t549 + and type t550 = M.t550 + and type t551 = M.t551 + and type t552 = M.t552 + and type t553 = M.t553 + and type t554 = M.t554 + and type t555 = M.t555 + and type t556 = M.t556 + and type t557 = M.t557 + and type t558 = M.t558 + and type t559 = M.t559 + and type t560 = M.t560 + and type t561 = M.t561 + and type t562 = M.t562 + and type t563 = M.t563 + and type t564 = M.t564 + and type t565 = M.t565 + and type t566 = M.t566 + and type t567 = M.t567 + and type t568 = M.t568 + and type t569 = M.t569 + and type t570 = M.t570 + and type t571 = M.t571 + and type t572 = M.t572 + and type t573 = M.t573 + and type t574 = M.t574 + and type t575 = M.t575 + and type t576 = M.t576 + and type t577 = M.t577 + and type t578 = M.t578 + and type t579 = M.t579 + and type t580 = M.t580 + and type t581 = M.t581 + and type t582 = M.t582 + and type t583 = M.t583 + and type t584 = M.t584 + and type t585 = M.t585 + and type t586 = M.t586 + and type t587 = M.t587 + and type t588 = M.t588 + and type t589 = M.t589 + and type t590 = M.t590 + and type t591 = M.t591 + and type t592 = M.t592 + and type t593 = M.t593 + and type t594 = M.t594 + and type t595 = M.t595 + and type t596 = M.t596 + and type t597 = M.t597 + and type t598 = M.t598 + and type t599 = M.t599 + and type t600 = M.t600 + and type t601 = M.t601 + and type t602 = M.t602 + and type t603 = M.t603 + and type t604 = M.t604 + and type t605 = M.t605 + and type t606 = M.t606 + and type t607 = M.t607 + and type t608 = M.t608 + and type t609 = M.t609 + and type t610 = M.t610 + and type t611 = M.t611 + and type t612 = M.t612 + and type t613 = M.t613 + and type t614 = M.t614 + and type t615 = M.t615 + and type t616 = M.t616 + and type t617 = M.t617 + and type t618 = M.t618 + and type t619 = M.t619 + and type t620 = M.t620 + and type t621 = M.t621 + and type t622 = M.t622 + and type t623 = M.t623 + and type t624 = M.t624 + and type t625 = M.t625 + and type t626 = M.t626 + and type t627 = M.t627 + and type t628 = M.t628 + and type t629 = M.t629 + and type t630 = M.t630 + and type t631 = M.t631 + and type t632 = M.t632 + and type t633 = M.t633 + and type t634 = M.t634 + and type t635 = M.t635 + and type t636 = M.t636 + and type t637 = M.t637 + and type t638 = M.t638 + and type t639 = M.t639 + and type t640 = M.t640 + and type t641 = M.t641 + and type t642 = M.t642 + and type t643 = M.t643 + and type t644 = M.t644 + and type t645 = M.t645 + and type t646 = M.t646 + and type t647 = M.t647 + and type t648 = M.t648 + and type t649 = M.t649 + and type t650 = M.t650 + and type t651 = M.t651 + and type t652 = M.t652 + and type t653 = M.t653 + and type t654 = M.t654 + and type t655 = M.t655 + and type t656 = M.t656 + and type t657 = M.t657 + and type t658 = M.t658 + and type t659 = M.t659 + and type t660 = M.t660 + and type t661 = M.t661 + and type t662 = M.t662 + and type t663 = M.t663 + and type t664 = M.t664 + and type t665 = M.t665 + and type t666 = M.t666 + and type t667 = M.t667 + and type t668 = M.t668 + and type t669 = M.t669 + and type t670 = M.t670 + and type t671 = M.t671 + and type t672 = M.t672 + and type t673 = M.t673 + and type t674 = M.t674 + and type t675 = M.t675 + and type t676 = M.t676 + and type t677 = M.t677 + and type t678 = M.t678 + and type t679 = M.t679 + and type t680 = M.t680 + and type t681 = M.t681 + and type t682 = M.t682 + and type t683 = M.t683 + and type t684 = M.t684 + and type t685 = M.t685 + and type t686 = M.t686 + and type t687 = M.t687 + and type t688 = M.t688 + and type t689 = M.t689 + and type t690 = M.t690 + and type t691 = M.t691 + and type t692 = M.t692 + and type t693 = M.t693 + and type t694 = M.t694 + and type t695 = M.t695 + and type t696 = M.t696 + and type t697 = M.t697 + and type t698 = M.t698 + and type t699 = M.t699 + and type t700 = M.t700 + and type t701 = M.t701 + and type t702 = M.t702 + and type t703 = M.t703 + and type t704 = M.t704 + and type t705 = M.t705 + and type t706 = M.t706 + and type t707 = M.t707 + and type t708 = M.t708 + and type t709 = M.t709 + and type t710 = M.t710 + and type t711 = M.t711 + and type t712 = M.t712 + and type t713 = M.t713 + and type t714 = M.t714 + and type t715 = M.t715 + and type t716 = M.t716 + and type t717 = M.t717 + and type t718 = M.t718 + and type t719 = M.t719 + and type t720 = M.t720 + and type t721 = M.t721 + and type t722 = M.t722 + and type t723 = M.t723 + and type t724 = M.t724 + and type t725 = M.t725 + and type t726 = M.t726 + and type t727 = M.t727 + and type t728 = M.t728 + and type t729 = M.t729 + and type t730 = M.t730 + and type t731 = M.t731 + and type t732 = M.t732 + and type t733 = M.t733 + and type t734 = M.t734 + and type t735 = M.t735 + and type t736 = M.t736 + and type t737 = M.t737 + and type t738 = M.t738 + and type t739 = M.t739 + and type t740 = M.t740 + and type t741 = M.t741 + and type t742 = M.t742 + and type t743 = M.t743 + and type t744 = M.t744 + and type t745 = M.t745 + and type t746 = M.t746 + and type t747 = M.t747 + and type t748 = M.t748 + and type t749 = M.t749 + and type t750 = M.t750 + and type t751 = M.t751 + and type t752 = M.t752 + and type t753 = M.t753 + and type t754 = M.t754 + and type t755 = M.t755 + and type t756 = M.t756 + and type t757 = M.t757 + and type t758 = M.t758 + and type t759 = M.t759 + and type t760 = M.t760 + and type t761 = M.t761 + and type t762 = M.t762 + and type t763 = M.t763 + and type t764 = M.t764 + and type t765 = M.t765 + and type t766 = M.t766 + and type t767 = M.t767 + and type t768 = M.t768 + and type t769 = M.t769 + and type t770 = M.t770 + and type t771 = M.t771 + and type t772 = M.t772 + and type t773 = M.t773 + and type t774 = M.t774 + and type t775 = M.t775 + and type t776 = M.t776 + and type t777 = M.t777 + and type t778 = M.t778 + and type t779 = M.t779 + and type t780 = M.t780 + and type t781 = M.t781 + and type t782 = M.t782 + and type t783 = M.t783 + and type t784 = M.t784 + and type t785 = M.t785 + and type t786 = M.t786 + and type t787 = M.t787 + and type t788 = M.t788 + and type t789 = M.t789 + and type t790 = M.t790 + and type t791 = M.t791 + and type t792 = M.t792 + and type t793 = M.t793 + and type t794 = M.t794 + and type t795 = M.t795 + and type t796 = M.t796 + and type t797 = M.t797 + and type t798 = M.t798 + and type t799 = M.t799 + and type t800 = M.t800 + and type t801 = M.t801 + and type t802 = M.t802 + and type t803 = M.t803 + and type t804 = M.t804 + and type t805 = M.t805 + and type t806 = M.t806 + and type t807 = M.t807 + and type t808 = M.t808 + and type t809 = M.t809 + and type t810 = M.t810 + and type t811 = M.t811 + and type t812 = M.t812 + and type t813 = M.t813 + and type t814 = M.t814 + and type t815 = M.t815 + and type t816 = M.t816 + and type t817 = M.t817 + and type t818 = M.t818 + and type t819 = M.t819 + and type t820 = M.t820 + and type t821 = M.t821 + and type t822 = M.t822 + and type t823 = M.t823 + and type t824 = M.t824 + and type t825 = M.t825 + and type t826 = M.t826 + and type t827 = M.t827 + and type t828 = M.t828 + and type t829 = M.t829 + and type t830 = M.t830 + and type t831 = M.t831 + and type t832 = M.t832 + and type t833 = M.t833 + and type t834 = M.t834 + and type t835 = M.t835 + and type t836 = M.t836 + and type t837 = M.t837 + and type t838 = M.t838 + and type t839 = M.t839 + and type t840 = M.t840 + and type t841 = M.t841 + and type t842 = M.t842 + and type t843 = M.t843 + and type t844 = M.t844 + and type t845 = M.t845 + and type t846 = M.t846 + and type t847 = M.t847 + and type t848 = M.t848 + and type t849 = M.t849 + and type t850 = M.t850 + and type t851 = M.t851 + and type t852 = M.t852 + and type t853 = M.t853 + and type t854 = M.t854 + and type t855 = M.t855 + and type t856 = M.t856 + and type t857 = M.t857 + and type t858 = M.t858 + and type t859 = M.t859 + and type t860 = M.t860 + and type t861 = M.t861 + and type t862 = M.t862 + and type t863 = M.t863 + and type t864 = M.t864 + and type t865 = M.t865 + and type t866 = M.t866 + and type t867 = M.t867 + and type t868 = M.t868 + and type t869 = M.t869 + and type t870 = M.t870 + and type t871 = M.t871 + and type t872 = M.t872 + and type t873 = M.t873 + and type t874 = M.t874 + and type t875 = M.t875 + and type t876 = M.t876 + and type t877 = M.t877 + and type t878 = M.t878 + and type t879 = M.t879 + and type t880 = M.t880 + and type t881 = M.t881 + and type t882 = M.t882 + and type t883 = M.t883 + and type t884 = M.t884 + and type t885 = M.t885 + and type t886 = M.t886 + and type t887 = M.t887 + and type t888 = M.t888 + and type t889 = M.t889 + and type t890 = M.t890 + and type t891 = M.t891 + and type t892 = M.t892 + and type t893 = M.t893 + and type t894 = M.t894 + and type t895 = M.t895 + and type t896 = M.t896 + and type t897 = M.t897 + and type t898 = M.t898 + and type t899 = M.t899 + and type t900 = M.t900 + and type t901 = M.t901 + and type t902 = M.t902 + and type t903 = M.t903 + and type t904 = M.t904 + and type t905 = M.t905 + and type t906 = M.t906 + and type t907 = M.t907 + and type t908 = M.t908 + and type t909 = M.t909 + and type t910 = M.t910 + and type t911 = M.t911 + and type t912 = M.t912 + and type t913 = M.t913 + and type t914 = M.t914 + and type t915 = M.t915 + and type t916 = M.t916 + and type t917 = M.t917 + and type t918 = M.t918 + and type t919 = M.t919 + and type t920 = M.t920 + and type t921 = M.t921 + and type t922 = M.t922 + and type t923 = M.t923 + and type t924 = M.t924 + and type t925 = M.t925 + and type t926 = M.t926 + and type t927 = M.t927 + and type t928 = M.t928 + and type t929 = M.t929 + and type t930 = M.t930 + and type t931 = M.t931 + and type t932 = M.t932 + and type t933 = M.t933 + and type t934 = M.t934 + and type t935 = M.t935 + and type t936 = M.t936 + and type t937 = M.t937 + and type t938 = M.t938 + and type t939 = M.t939 + and type t940 = M.t940 + and type t941 = M.t941 + and type t942 = M.t942 + and type t943 = M.t943 + and type t944 = M.t944 + and type t945 = M.t945 + and type t946 = M.t946 + and type t947 = M.t947 + and type t948 = M.t948 + and type t949 = M.t949 + and type t950 = M.t950 + and type t951 = M.t951 + and type t952 = M.t952 + and type t953 = M.t953 + and type t954 = M.t954 + and type t955 = M.t955 + and type t956 = M.t956 + and type t957 = M.t957 + and type t958 = M.t958 + and type t959 = M.t959 + and type t960 = M.t960 + and type t961 = M.t961 + and type t962 = M.t962 + and type t963 = M.t963 + and type t964 = M.t964 + and type t965 = M.t965 + and type t966 = M.t966 + and type t967 = M.t967 + and type t968 = M.t968 + and type t969 = M.t969 + and type t970 = M.t970 + and type t971 = M.t971 + and type t972 = M.t972 + and type t973 = M.t973 + and type t974 = M.t974 + and type t975 = M.t975 + and type t976 = M.t976 + and type t977 = M.t977 + and type t978 = M.t978 + and type t979 = M.t979 + and type t980 = M.t980 + and type t981 = M.t981 + and type t982 = M.t982 + and type t983 = M.t983 + and type t984 = M.t984 + and type t985 = M.t985 + and type t986 = M.t986 + and type t987 = M.t987 + and type t988 = M.t988 + and type t989 = M.t989 + and type t990 = M.t990 + and type t991 = M.t991 + and type t992 = M.t992 + and type t993 = M.t993 + and type t994 = M.t994 + and type t995 = M.t995 + and type t996 = M.t996 + and type t997 = M.t997 + and type t998 = M.t998 + and type t999 = M.t999 + and type t1000 = M.t1000 += struct + include M +end + +module M = struct + type t0 = int -> int -> int + type t1 = int -> int -> int + type t2 = int -> int -> int + type t3 = int -> int -> int + type t4 = int -> int -> int + type t5 = int -> int -> int + type t6 = int -> int -> int + type t7 = int -> int -> int + type t8 = int -> int -> int + type t9 = int -> int -> int + type t10 = int -> int -> int + type t11 = int -> int -> int + type t12 = int -> int -> int + type t13 = int -> int -> int + type t14 = int -> int -> int + type t15 = int -> int -> int + type t16 = int -> int -> int + type t17 = int -> int -> int + type t18 = int -> int -> int + type t19 = int -> int -> int + type t20 = int -> int -> int + type t21 = int -> int -> int + type t22 = int -> int -> int + type t23 = int -> int -> int + type t24 = int -> int -> int + type t25 = int -> int -> int + type t26 = int -> int -> int + type t27 = int -> int -> int + type t28 = int -> int -> int + type t29 = int -> int -> int + type t30 = int -> int -> int + type t31 = int -> int -> int + type t32 = int -> int -> int + type t33 = int -> int -> int + type t34 = int -> int -> int + type t35 = int -> int -> int + type t36 = int -> int -> int + type t37 = int -> int -> int + type t38 = int -> int -> int + type t39 = int -> int -> int + type t40 = int -> int -> int + type t41 = int -> int -> int + type t42 = int -> int -> int + type t43 = int -> int -> int + type t44 = int -> int -> int + type t45 = int -> int -> int + type t46 = int -> int -> int + type t47 = int -> int -> int + type t48 = int -> int -> int + type t49 = int -> int -> int + type t50 = int -> int -> int + type t51 = int -> int -> int + type t52 = int -> int -> int + type t53 = int -> int -> int + type t54 = int -> int -> int + type t55 = int -> int -> int + type t56 = int -> int -> int + type t57 = int -> int -> int + type t58 = int -> int -> int + type t59 = int -> int -> int + type t60 = int -> int -> int + type t61 = int -> int -> int + type t62 = int -> int -> int + type t63 = int -> int -> int + type t64 = int -> int -> int + type t65 = int -> int -> int + type t66 = int -> int -> int + type t67 = int -> int -> int + type t68 = int -> int -> int + type t69 = int -> int -> int + type t70 = int -> int -> int + type t71 = int -> int -> int + type t72 = int -> int -> int + type t73 = int -> int -> int + type t74 = int -> int -> int + type t75 = int -> int -> int + type t76 = int -> int -> int + type t77 = int -> int -> int + type t78 = int -> int -> int + type t79 = int -> int -> int + type t80 = int -> int -> int + type t81 = int -> int -> int + type t82 = int -> int -> int + type t83 = int -> int -> int + type t84 = int -> int -> int + type t85 = int -> int -> int + type t86 = int -> int -> int + type t87 = int -> int -> int + type t88 = int -> int -> int + type t89 = int -> int -> int + type t90 = int -> int -> int + type t91 = int -> int -> int + type t92 = int -> int -> int + type t93 = int -> int -> int + type t94 = int -> int -> int + type t95 = int -> int -> int + type t96 = int -> int -> int + type t97 = int -> int -> int + type t98 = int -> int -> int + type t99 = int -> int -> int + type t100 = int -> int -> int + type t101 = int -> int -> int + type t102 = int -> int -> int + type t103 = int -> int -> int + type t104 = int -> int -> int + type t105 = int -> int -> int + type t106 = int -> int -> int + type t107 = int -> int -> int + type t108 = int -> int -> int + type t109 = int -> int -> int + type t110 = int -> int -> int + type t111 = int -> int -> int + type t112 = int -> int -> int + type t113 = int -> int -> int + type t114 = int -> int -> int + type t115 = int -> int -> int + type t116 = int -> int -> int + type t117 = int -> int -> int + type t118 = int -> int -> int + type t119 = int -> int -> int + type t120 = int -> int -> int + type t121 = int -> int -> int + type t122 = int -> int -> int + type t123 = int -> int -> int + type t124 = int -> int -> int + type t125 = int -> int -> int + type t126 = int -> int -> int + type t127 = int -> int -> int + type t128 = int -> int -> int + type t129 = int -> int -> int + type t130 = int -> int -> int + type t131 = int -> int -> int + type t132 = int -> int -> int + type t133 = int -> int -> int + type t134 = int -> int -> int + type t135 = int -> int -> int + type t136 = int -> int -> int + type t137 = int -> int -> int + type t138 = int -> int -> int + type t139 = int -> int -> int + type t140 = int -> int -> int + type t141 = int -> int -> int + type t142 = int -> int -> int + type t143 = int -> int -> int + type t144 = int -> int -> int + type t145 = int -> int -> int + type t146 = int -> int -> int + type t147 = int -> int -> int + type t148 = int -> int -> int + type t149 = int -> int -> int + type t150 = int -> int -> int + type t151 = int -> int -> int + type t152 = int -> int -> int + type t153 = int -> int -> int + type t154 = int -> int -> int + type t155 = int -> int -> int + type t156 = int -> int -> int + type t157 = int -> int -> int + type t158 = int -> int -> int + type t159 = int -> int -> int + type t160 = int -> int -> int + type t161 = int -> int -> int + type t162 = int -> int -> int + type t163 = int -> int -> int + type t164 = int -> int -> int + type t165 = int -> int -> int + type t166 = int -> int -> int + type t167 = int -> int -> int + type t168 = int -> int -> int + type t169 = int -> int -> int + type t170 = int -> int -> int + type t171 = int -> int -> int + type t172 = int -> int -> int + type t173 = int -> int -> int + type t174 = int -> int -> int + type t175 = int -> int -> int + type t176 = int -> int -> int + type t177 = int -> int -> int + type t178 = int -> int -> int + type t179 = int -> int -> int + type t180 = int -> int -> int + type t181 = int -> int -> int + type t182 = int -> int -> int + type t183 = int -> int -> int + type t184 = int -> int -> int + type t185 = int -> int -> int + type t186 = int -> int -> int + type t187 = int -> int -> int + type t188 = int -> int -> int + type t189 = int -> int -> int + type t190 = int -> int -> int + type t191 = int -> int -> int + type t192 = int -> int -> int + type t193 = int -> int -> int + type t194 = int -> int -> int + type t195 = int -> int -> int + type t196 = int -> int -> int + type t197 = int -> int -> int + type t198 = int -> int -> int + type t199 = int -> int -> int + type t200 = int -> int -> int + type t201 = int -> int -> int + type t202 = int -> int -> int + type t203 = int -> int -> int + type t204 = int -> int -> int + type t205 = int -> int -> int + type t206 = int -> int -> int + type t207 = int -> int -> int + type t208 = int -> int -> int + type t209 = int -> int -> int + type t210 = int -> int -> int + type t211 = int -> int -> int + type t212 = int -> int -> int + type t213 = int -> int -> int + type t214 = int -> int -> int + type t215 = int -> int -> int + type t216 = int -> int -> int + type t217 = int -> int -> int + type t218 = int -> int -> int + type t219 = int -> int -> int + type t220 = int -> int -> int + type t221 = int -> int -> int + type t222 = int -> int -> int + type t223 = int -> int -> int + type t224 = int -> int -> int + type t225 = int -> int -> int + type t226 = int -> int -> int + type t227 = int -> int -> int + type t228 = int -> int -> int + type t229 = int -> int -> int + type t230 = int -> int -> int + type t231 = int -> int -> int + type t232 = int -> int -> int + type t233 = int -> int -> int + type t234 = int -> int -> int + type t235 = int -> int -> int + type t236 = int -> int -> int + type t237 = int -> int -> int + type t238 = int -> int -> int + type t239 = int -> int -> int + type t240 = int -> int -> int + type t241 = int -> int -> int + type t242 = int -> int -> int + type t243 = int -> int -> int + type t244 = int -> int -> int + type t245 = int -> int -> int + type t246 = int -> int -> int + type t247 = int -> int -> int + type t248 = int -> int -> int + type t249 = int -> int -> int + type t250 = int -> int -> int + type t251 = int -> int -> int + type t252 = int -> int -> int + type t253 = int -> int -> int + type t254 = int -> int -> int + type t255 = int -> int -> int + type t256 = int -> int -> int + type t257 = int -> int -> int + type t258 = int -> int -> int + type t259 = int -> int -> int + type t260 = int -> int -> int + type t261 = int -> int -> int + type t262 = int -> int -> int + type t263 = int -> int -> int + type t264 = int -> int -> int + type t265 = int -> int -> int + type t266 = int -> int -> int + type t267 = int -> int -> int + type t268 = int -> int -> int + type t269 = int -> int -> int + type t270 = int -> int -> int + type t271 = int -> int -> int + type t272 = int -> int -> int + type t273 = int -> int -> int + type t274 = int -> int -> int + type t275 = int -> int -> int + type t276 = int -> int -> int + type t277 = int -> int -> int + type t278 = int -> int -> int + type t279 = int -> int -> int + type t280 = int -> int -> int + type t281 = int -> int -> int + type t282 = int -> int -> int + type t283 = int -> int -> int + type t284 = int -> int -> int + type t285 = int -> int -> int + type t286 = int -> int -> int + type t287 = int -> int -> int + type t288 = int -> int -> int + type t289 = int -> int -> int + type t290 = int -> int -> int + type t291 = int -> int -> int + type t292 = int -> int -> int + type t293 = int -> int -> int + type t294 = int -> int -> int + type t295 = int -> int -> int + type t296 = int -> int -> int + type t297 = int -> int -> int + type t298 = int -> int -> int + type t299 = int -> int -> int + type t300 = int -> int -> int + type t301 = int -> int -> int + type t302 = int -> int -> int + type t303 = int -> int -> int + type t304 = int -> int -> int + type t305 = int -> int -> int + type t306 = int -> int -> int + type t307 = int -> int -> int + type t308 = int -> int -> int + type t309 = int -> int -> int + type t310 = int -> int -> int + type t311 = int -> int -> int + type t312 = int -> int -> int + type t313 = int -> int -> int + type t314 = int -> int -> int + type t315 = int -> int -> int + type t316 = int -> int -> int + type t317 = int -> int -> int + type t318 = int -> int -> int + type t319 = int -> int -> int + type t320 = int -> int -> int + type t321 = int -> int -> int + type t322 = int -> int -> int + type t323 = int -> int -> int + type t324 = int -> int -> int + type t325 = int -> int -> int + type t326 = int -> int -> int + type t327 = int -> int -> int + type t328 = int -> int -> int + type t329 = int -> int -> int + type t330 = int -> int -> int + type t331 = int -> int -> int + type t332 = int -> int -> int + type t333 = int -> int -> int + type t334 = int -> int -> int + type t335 = int -> int -> int + type t336 = int -> int -> int + type t337 = int -> int -> int + type t338 = int -> int -> int + type t339 = int -> int -> int + type t340 = int -> int -> int + type t341 = int -> int -> int + type t342 = int -> int -> int + type t343 = int -> int -> int + type t344 = int -> int -> int + type t345 = int -> int -> int + type t346 = int -> int -> int + type t347 = int -> int -> int + type t348 = int -> int -> int + type t349 = int -> int -> int + type t350 = int -> int -> int + type t351 = int -> int -> int + type t352 = int -> int -> int + type t353 = int -> int -> int + type t354 = int -> int -> int + type t355 = int -> int -> int + type t356 = int -> int -> int + type t357 = int -> int -> int + type t358 = int -> int -> int + type t359 = int -> int -> int + type t360 = int -> int -> int + type t361 = int -> int -> int + type t362 = int -> int -> int + type t363 = int -> int -> int + type t364 = int -> int -> int + type t365 = int -> int -> int + type t366 = int -> int -> int + type t367 = int -> int -> int + type t368 = int -> int -> int + type t369 = int -> int -> int + type t370 = int -> int -> int + type t371 = int -> int -> int + type t372 = int -> int -> int + type t373 = int -> int -> int + type t374 = int -> int -> int + type t375 = int -> int -> int + type t376 = int -> int -> int + type t377 = int -> int -> int + type t378 = int -> int -> int + type t379 = int -> int -> int + type t380 = int -> int -> int + type t381 = int -> int -> int + type t382 = int -> int -> int + type t383 = int -> int -> int + type t384 = int -> int -> int + type t385 = int -> int -> int + type t386 = int -> int -> int + type t387 = int -> int -> int + type t388 = int -> int -> int + type t389 = int -> int -> int + type t390 = int -> int -> int + type t391 = int -> int -> int + type t392 = int -> int -> int + type t393 = int -> int -> int + type t394 = int -> int -> int + type t395 = int -> int -> int + type t396 = int -> int -> int + type t397 = int -> int -> int + type t398 = int -> int -> int + type t399 = int -> int -> int + type t400 = int -> int -> int + type t401 = int -> int -> int + type t402 = int -> int -> int + type t403 = int -> int -> int + type t404 = int -> int -> int + type t405 = int -> int -> int + type t406 = int -> int -> int + type t407 = int -> int -> int + type t408 = int -> int -> int + type t409 = int -> int -> int + type t410 = int -> int -> int + type t411 = int -> int -> int + type t412 = int -> int -> int + type t413 = int -> int -> int + type t414 = int -> int -> int + type t415 = int -> int -> int + type t416 = int -> int -> int + type t417 = int -> int -> int + type t418 = int -> int -> int + type t419 = int -> int -> int + type t420 = int -> int -> int + type t421 = int -> int -> int + type t422 = int -> int -> int + type t423 = int -> int -> int + type t424 = int -> int -> int + type t425 = int -> int -> int + type t426 = int -> int -> int + type t427 = int -> int -> int + type t428 = int -> int -> int + type t429 = int -> int -> int + type t430 = int -> int -> int + type t431 = int -> int -> int + type t432 = int -> int -> int + type t433 = int -> int -> int + type t434 = int -> int -> int + type t435 = int -> int -> int + type t436 = int -> int -> int + type t437 = int -> int -> int + type t438 = int -> int -> int + type t439 = int -> int -> int + type t440 = int -> int -> int + type t441 = int -> int -> int + type t442 = int -> int -> int + type t443 = int -> int -> int + type t444 = int -> int -> int + type t445 = int -> int -> int + type t446 = int -> int -> int + type t447 = int -> int -> int + type t448 = int -> int -> int + type t449 = int -> int -> int + type t450 = int -> int -> int + type t451 = int -> int -> int + type t452 = int -> int -> int + type t453 = int -> int -> int + type t454 = int -> int -> int + type t455 = int -> int -> int + type t456 = int -> int -> int + type t457 = int -> int -> int + type t458 = int -> int -> int + type t459 = int -> int -> int + type t460 = int -> int -> int + type t461 = int -> int -> int + type t462 = int -> int -> int + type t463 = int -> int -> int + type t464 = int -> int -> int + type t465 = int -> int -> int + type t466 = int -> int -> int + type t467 = int -> int -> int + type t468 = int -> int -> int + type t469 = int -> int -> int + type t470 = int -> int -> int + type t471 = int -> int -> int + type t472 = int -> int -> int + type t473 = int -> int -> int + type t474 = int -> int -> int + type t475 = int -> int -> int + type t476 = int -> int -> int + type t477 = int -> int -> int + type t478 = int -> int -> int + type t479 = int -> int -> int + type t480 = int -> int -> int + type t481 = int -> int -> int + type t482 = int -> int -> int + type t483 = int -> int -> int + type t484 = int -> int -> int + type t485 = int -> int -> int + type t486 = int -> int -> int + type t487 = int -> int -> int + type t488 = int -> int -> int + type t489 = int -> int -> int + type t490 = int -> int -> int + type t491 = int -> int -> int + type t492 = int -> int -> int + type t493 = int -> int -> int + type t494 = int -> int -> int + type t495 = int -> int -> int + type t496 = int -> int -> int + type t497 = int -> int -> int + type t498 = int -> int -> int + type t499 = int -> int -> int + type t500 = int -> int -> int + type t501 = int -> int -> int + type t502 = int -> int -> int + type t503 = int -> int -> int + type t504 = int -> int -> int + type t505 = int -> int -> int + type t506 = int -> int -> int + type t507 = int -> int -> int + type t508 = int -> int -> int + type t509 = int -> int -> int + type t510 = int -> int -> int + type t511 = int -> int -> int + type t512 = int -> int -> int + type t513 = int -> int -> int + type t514 = int -> int -> int + type t515 = int -> int -> int + type t516 = int -> int -> int + type t517 = int -> int -> int + type t518 = int -> int -> int + type t519 = int -> int -> int + type t520 = int -> int -> int + type t521 = int -> int -> int + type t522 = int -> int -> int + type t523 = int -> int -> int + type t524 = int -> int -> int + type t525 = int -> int -> int + type t526 = int -> int -> int + type t527 = int -> int -> int + type t528 = int -> int -> int + type t529 = int -> int -> int + type t530 = int -> int -> int + type t531 = int -> int -> int + type t532 = int -> int -> int + type t533 = int -> int -> int + type t534 = int -> int -> int + type t535 = int -> int -> int + type t536 = int -> int -> int + type t537 = int -> int -> int + type t538 = int -> int -> int + type t539 = int -> int -> int + type t540 = int -> int -> int + type t541 = int -> int -> int + type t542 = int -> int -> int + type t543 = int -> int -> int + type t544 = int -> int -> int + type t545 = int -> int -> int + type t546 = int -> int -> int + type t547 = int -> int -> int + type t548 = int -> int -> int + type t549 = int -> int -> int + type t550 = int -> int -> int + type t551 = int -> int -> int + type t552 = int -> int -> int + type t553 = int -> int -> int + type t554 = int -> int -> int + type t555 = int -> int -> int + type t556 = int -> int -> int + type t557 = int -> int -> int + type t558 = int -> int -> int + type t559 = int -> int -> int + type t560 = int -> int -> int + type t561 = int -> int -> int + type t562 = int -> int -> int + type t563 = int -> int -> int + type t564 = int -> int -> int + type t565 = int -> int -> int + type t566 = int -> int -> int + type t567 = int -> int -> int + type t568 = int -> int -> int + type t569 = int -> int -> int + type t570 = int -> int -> int + type t571 = int -> int -> int + type t572 = int -> int -> int + type t573 = int -> int -> int + type t574 = int -> int -> int + type t575 = int -> int -> int + type t576 = int -> int -> int + type t577 = int -> int -> int + type t578 = int -> int -> int + type t579 = int -> int -> int + type t580 = int -> int -> int + type t581 = int -> int -> int + type t582 = int -> int -> int + type t583 = int -> int -> int + type t584 = int -> int -> int + type t585 = int -> int -> int + type t586 = int -> int -> int + type t587 = int -> int -> int + type t588 = int -> int -> int + type t589 = int -> int -> int + type t590 = int -> int -> int + type t591 = int -> int -> int + type t592 = int -> int -> int + type t593 = int -> int -> int + type t594 = int -> int -> int + type t595 = int -> int -> int + type t596 = int -> int -> int + type t597 = int -> int -> int + type t598 = int -> int -> int + type t599 = int -> int -> int + type t600 = int -> int -> int + type t601 = int -> int -> int + type t602 = int -> int -> int + type t603 = int -> int -> int + type t604 = int -> int -> int + type t605 = int -> int -> int + type t606 = int -> int -> int + type t607 = int -> int -> int + type t608 = int -> int -> int + type t609 = int -> int -> int + type t610 = int -> int -> int + type t611 = int -> int -> int + type t612 = int -> int -> int + type t613 = int -> int -> int + type t614 = int -> int -> int + type t615 = int -> int -> int + type t616 = int -> int -> int + type t617 = int -> int -> int + type t618 = int -> int -> int + type t619 = int -> int -> int + type t620 = int -> int -> int + type t621 = int -> int -> int + type t622 = int -> int -> int + type t623 = int -> int -> int + type t624 = int -> int -> int + type t625 = int -> int -> int + type t626 = int -> int -> int + type t627 = int -> int -> int + type t628 = int -> int -> int + type t629 = int -> int -> int + type t630 = int -> int -> int + type t631 = int -> int -> int + type t632 = int -> int -> int + type t633 = int -> int -> int + type t634 = int -> int -> int + type t635 = int -> int -> int + type t636 = int -> int -> int + type t637 = int -> int -> int + type t638 = int -> int -> int + type t639 = int -> int -> int + type t640 = int -> int -> int + type t641 = int -> int -> int + type t642 = int -> int -> int + type t643 = int -> int -> int + type t644 = int -> int -> int + type t645 = int -> int -> int + type t646 = int -> int -> int + type t647 = int -> int -> int + type t648 = int -> int -> int + type t649 = int -> int -> int + type t650 = int -> int -> int + type t651 = int -> int -> int + type t652 = int -> int -> int + type t653 = int -> int -> int + type t654 = int -> int -> int + type t655 = int -> int -> int + type t656 = int -> int -> int + type t657 = int -> int -> int + type t658 = int -> int -> int + type t659 = int -> int -> int + type t660 = int -> int -> int + type t661 = int -> int -> int + type t662 = int -> int -> int + type t663 = int -> int -> int + type t664 = int -> int -> int + type t665 = int -> int -> int + type t666 = int -> int -> int + type t667 = int -> int -> int + type t668 = int -> int -> int + type t669 = int -> int -> int + type t670 = int -> int -> int + type t671 = int -> int -> int + type t672 = int -> int -> int + type t673 = int -> int -> int + type t674 = int -> int -> int + type t675 = int -> int -> int + type t676 = int -> int -> int + type t677 = int -> int -> int + type t678 = int -> int -> int + type t679 = int -> int -> int + type t680 = int -> int -> int + type t681 = int -> int -> int + type t682 = int -> int -> int + type t683 = int -> int -> int + type t684 = int -> int -> int + type t685 = int -> int -> int + type t686 = int -> int -> int + type t687 = int -> int -> int + type t688 = int -> int -> int + type t689 = int -> int -> int + type t690 = int -> int -> int + type t691 = int -> int -> int + type t692 = int -> int -> int + type t693 = int -> int -> int + type t694 = int -> int -> int + type t695 = int -> int -> int + type t696 = int -> int -> int + type t697 = int -> int -> int + type t698 = int -> int -> int + type t699 = int -> int -> int + type t700 = int -> int -> int + type t701 = int -> int -> int + type t702 = int -> int -> int + type t703 = int -> int -> int + type t704 = int -> int -> int + type t705 = int -> int -> int + type t706 = int -> int -> int + type t707 = int -> int -> int + type t708 = int -> int -> int + type t709 = int -> int -> int + type t710 = int -> int -> int + type t711 = int -> int -> int + type t712 = int -> int -> int + type t713 = int -> int -> int + type t714 = int -> int -> int + type t715 = int -> int -> int + type t716 = int -> int -> int + type t717 = int -> int -> int + type t718 = int -> int -> int + type t719 = int -> int -> int + type t720 = int -> int -> int + type t721 = int -> int -> int + type t722 = int -> int -> int + type t723 = int -> int -> int + type t724 = int -> int -> int + type t725 = int -> int -> int + type t726 = int -> int -> int + type t727 = int -> int -> int + type t728 = int -> int -> int + type t729 = int -> int -> int + type t730 = int -> int -> int + type t731 = int -> int -> int + type t732 = int -> int -> int + type t733 = int -> int -> int + type t734 = int -> int -> int + type t735 = int -> int -> int + type t736 = int -> int -> int + type t737 = int -> int -> int + type t738 = int -> int -> int + type t739 = int -> int -> int + type t740 = int -> int -> int + type t741 = int -> int -> int + type t742 = int -> int -> int + type t743 = int -> int -> int + type t744 = int -> int -> int + type t745 = int -> int -> int + type t746 = int -> int -> int + type t747 = int -> int -> int + type t748 = int -> int -> int + type t749 = int -> int -> int + type t750 = int -> int -> int + type t751 = int -> int -> int + type t752 = int -> int -> int + type t753 = int -> int -> int + type t754 = int -> int -> int + type t755 = int -> int -> int + type t756 = int -> int -> int + type t757 = int -> int -> int + type t758 = int -> int -> int + type t759 = int -> int -> int + type t760 = int -> int -> int + type t761 = int -> int -> int + type t762 = int -> int -> int + type t763 = int -> int -> int + type t764 = int -> int -> int + type t765 = int -> int -> int + type t766 = int -> int -> int + type t767 = int -> int -> int + type t768 = int -> int -> int + type t769 = int -> int -> int + type t770 = int -> int -> int + type t771 = int -> int -> int + type t772 = int -> int -> int + type t773 = int -> int -> int + type t774 = int -> int -> int + type t775 = int -> int -> int + type t776 = int -> int -> int + type t777 = int -> int -> int + type t778 = int -> int -> int + type t779 = int -> int -> int + type t780 = int -> int -> int + type t781 = int -> int -> int + type t782 = int -> int -> int + type t783 = int -> int -> int + type t784 = int -> int -> int + type t785 = int -> int -> int + type t786 = int -> int -> int + type t787 = int -> int -> int + type t788 = int -> int -> int + type t789 = int -> int -> int + type t790 = int -> int -> int + type t791 = int -> int -> int + type t792 = int -> int -> int + type t793 = int -> int -> int + type t794 = int -> int -> int + type t795 = int -> int -> int + type t796 = int -> int -> int + type t797 = int -> int -> int + type t798 = int -> int -> int + type t799 = int -> int -> int + type t800 = int -> int -> int + type t801 = int -> int -> int + type t802 = int -> int -> int + type t803 = int -> int -> int + type t804 = int -> int -> int + type t805 = int -> int -> int + type t806 = int -> int -> int + type t807 = int -> int -> int + type t808 = int -> int -> int + type t809 = int -> int -> int + type t810 = int -> int -> int + type t811 = int -> int -> int + type t812 = int -> int -> int + type t813 = int -> int -> int + type t814 = int -> int -> int + type t815 = int -> int -> int + type t816 = int -> int -> int + type t817 = int -> int -> int + type t818 = int -> int -> int + type t819 = int -> int -> int + type t820 = int -> int -> int + type t821 = int -> int -> int + type t822 = int -> int -> int + type t823 = int -> int -> int + type t824 = int -> int -> int + type t825 = int -> int -> int + type t826 = int -> int -> int + type t827 = int -> int -> int + type t828 = int -> int -> int + type t829 = int -> int -> int + type t830 = int -> int -> int + type t831 = int -> int -> int + type t832 = int -> int -> int + type t833 = int -> int -> int + type t834 = int -> int -> int + type t835 = int -> int -> int + type t836 = int -> int -> int + type t837 = int -> int -> int + type t838 = int -> int -> int + type t839 = int -> int -> int + type t840 = int -> int -> int + type t841 = int -> int -> int + type t842 = int -> int -> int + type t843 = int -> int -> int + type t844 = int -> int -> int + type t845 = int -> int -> int + type t846 = int -> int -> int + type t847 = int -> int -> int + type t848 = int -> int -> int + type t849 = int -> int -> int + type t850 = int -> int -> int + type t851 = int -> int -> int + type t852 = int -> int -> int + type t853 = int -> int -> int + type t854 = int -> int -> int + type t855 = int -> int -> int + type t856 = int -> int -> int + type t857 = int -> int -> int + type t858 = int -> int -> int + type t859 = int -> int -> int + type t860 = int -> int -> int + type t861 = int -> int -> int + type t862 = int -> int -> int + type t863 = int -> int -> int + type t864 = int -> int -> int + type t865 = int -> int -> int + type t866 = int -> int -> int + type t867 = int -> int -> int + type t868 = int -> int -> int + type t869 = int -> int -> int + type t870 = int -> int -> int + type t871 = int -> int -> int + type t872 = int -> int -> int + type t873 = int -> int -> int + type t874 = int -> int -> int + type t875 = int -> int -> int + type t876 = int -> int -> int + type t877 = int -> int -> int + type t878 = int -> int -> int + type t879 = int -> int -> int + type t880 = int -> int -> int + type t881 = int -> int -> int + type t882 = int -> int -> int + type t883 = int -> int -> int + type t884 = int -> int -> int + type t885 = int -> int -> int + type t886 = int -> int -> int + type t887 = int -> int -> int + type t888 = int -> int -> int + type t889 = int -> int -> int + type t890 = int -> int -> int + type t891 = int -> int -> int + type t892 = int -> int -> int + type t893 = int -> int -> int + type t894 = int -> int -> int + type t895 = int -> int -> int + type t896 = int -> int -> int + type t897 = int -> int -> int + type t898 = int -> int -> int + type t899 = int -> int -> int + type t900 = int -> int -> int + type t901 = int -> int -> int + type t902 = int -> int -> int + type t903 = int -> int -> int + type t904 = int -> int -> int + type t905 = int -> int -> int + type t906 = int -> int -> int + type t907 = int -> int -> int + type t908 = int -> int -> int + type t909 = int -> int -> int + type t910 = int -> int -> int + type t911 = int -> int -> int + type t912 = int -> int -> int + type t913 = int -> int -> int + type t914 = int -> int -> int + type t915 = int -> int -> int + type t916 = int -> int -> int + type t917 = int -> int -> int + type t918 = int -> int -> int + type t919 = int -> int -> int + type t920 = int -> int -> int + type t921 = int -> int -> int + type t922 = int -> int -> int + type t923 = int -> int -> int + type t924 = int -> int -> int + type t925 = int -> int -> int + type t926 = int -> int -> int + type t927 = int -> int -> int + type t928 = int -> int -> int + type t929 = int -> int -> int + type t930 = int -> int -> int + type t931 = int -> int -> int + type t932 = int -> int -> int + type t933 = int -> int -> int + type t934 = int -> int -> int + type t935 = int -> int -> int + type t936 = int -> int -> int + type t937 = int -> int -> int + type t938 = int -> int -> int + type t939 = int -> int -> int + type t940 = int -> int -> int + type t941 = int -> int -> int + type t942 = int -> int -> int + type t943 = int -> int -> int + type t944 = int -> int -> int + type t945 = int -> int -> int + type t946 = int -> int -> int + type t947 = int -> int -> int + type t948 = int -> int -> int + type t949 = int -> int -> int + type t950 = int -> int -> int + type t951 = int -> int -> int + type t952 = int -> int -> int + type t953 = int -> int -> int + type t954 = int -> int -> int + type t955 = int -> int -> int + type t956 = int -> int -> int + type t957 = int -> int -> int + type t958 = int -> int -> int + type t959 = int -> int -> int + type t960 = int -> int -> int + type t961 = int -> int -> int + type t962 = int -> int -> int + type t963 = int -> int -> int + type t964 = int -> int -> int + type t965 = int -> int -> int + type t966 = int -> int -> int + type t967 = int -> int -> int + type t968 = int -> int -> int + type t969 = int -> int -> int + type t970 = int -> int -> int + type t971 = int -> int -> int + type t972 = int -> int -> int + type t973 = int -> int -> int + type t974 = int -> int -> int + type t975 = int -> int -> int + type t976 = int -> int -> int + type t977 = int -> int -> int + type t978 = int -> int -> int + type t979 = int -> int -> int + type t980 = int -> int -> int + type t981 = int -> int -> int + type t982 = int -> int -> int + type t983 = int -> int -> int + type t984 = int -> int -> int + type t985 = int -> int -> int + type t986 = int -> int -> int + type t987 = int -> int -> int + type t988 = int -> int -> int + type t989 = int -> int -> int + type t990 = int -> int -> int + type t991 = int -> int -> int + type t992 = int -> int -> int + type t993 = int -> int -> int + type t994 = int -> int -> int + type t995 = int -> int -> int + type t996 = int -> int -> int + type t997 = int -> int -> int + type t998 = int -> int -> int + type t999 = int -> int -> int + type t1000 = int -> int -> int +end + +module X = + Make + (Make + (Make + (Make + (Make + (Make + (Make + (Make + (Make + (Make + (Make + (M))))))))))) diff --git a/camlp4/test/fixtures/functor-perf2.ml b/camlp4/test/fixtures/functor-perf2.ml new file mode 100644 index 0000000..57b8bba --- /dev/null +++ b/camlp4/test/fixtures/functor-perf2.ml @@ -0,0 +1,29 @@ +<% types, with_constrs, module_application = ARGV.map { |x| x.to_i } %> + +module type S = sig +<%- for i in 0 .. types do -%> + type t<%= i %> +<%- end -%> +end + +module Make (M : S) +: S with type t0 = M.t0 + <%- for i in 1 .. with_constrs do -%> + and type t<%= i %> = M.t<%= i %> + <%- end -%> += struct + include M +end + +module M = struct +<%- for i in 0 .. types do -%> + type t<%= i %> = int -> int -> int +<%- end -%> +end + +module X = + Make +<%- module_application.times do -%> + (Make +<%- end -%> + (M)<%= ')' * module_application %> diff --git a/camlp4/test/fixtures/functor-perf3.ml b/camlp4/test/fixtures/functor-perf3.ml new file mode 100644 index 0000000..5bf5359 --- /dev/null +++ b/camlp4/test/fixtures/functor-perf3.ml @@ -0,0 +1,50 @@ +<% types, with_constrs, make, make2 = ARGV.map { |x| x.to_i } %> + +module type S = sig +<%- for i in 0 .. types do -%> + type t<%= i %> +<%- end -%> +end + +module Make (M : S) +: S with type t0 = M.t0 + <%- for i in 1 .. with_constrs do -%> + and type t<%= i %> = M.t<%= i %> + <%- end -%> += struct + include M +end + +module type S2 = sig + module M : S +end + +module Make2 (M2 : S2) +: S2 with module M = M2.M += struct + include M2 +end + +module M = struct +<%- for i in 0 .. types do -%> + type t<%= i %> = int -> int -> int +<%- end -%> +end + +module M1 = + Make +<%- make.times do -%> + (Make +<%- end -%> + (M)<%= ')' * make %> + +module M2 = struct + module M = M1 +end + +module X = + Make2 +<%- make2.times do -%> + (Make2 +<%- end -%> + (M2)<%= ')' * make2 %> diff --git a/camlp4/test/fixtures/gen_map.ml b/camlp4/test/fixtures/gen_map.ml new file mode 100644 index 0000000..8655752 --- /dev/null +++ b/camlp4/test/fixtures/gen_map.ml @@ -0,0 +1,8 @@ +type t = + A of int * t * t +| B of int list +| C of option t + +module Map = struct + module T = Camlp4Filters.GenerateMap.Generated +end diff --git a/camlp4/test/fixtures/gram-fold.ml b/camlp4/test/fixtures/gram-fold.ml new file mode 100644 index 0000000..5cd53b1 --- /dev/null +++ b/camlp4/test/fixtures/gram-fold.ml @@ -0,0 +1,21 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +type t = [ A of t and t | B of string | C ]; +value main = G.Entry.mk "main"; +value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc + | C -> acc ]; +EXTEND G + GLOBAL: main; + main: + [ [ + l = FOLD1 (fun a b -> A (B a) b) (C) ident -> l + ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +let f = Sys.argv.(1) in +Format.printf "%d@." + (length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) 0); diff --git a/camlp4/test/fixtures/gram-list.ml b/camlp4/test/fixtures/gram-list.ml new file mode 100644 index 0000000..f3df766 --- /dev/null +++ b/camlp4/test/fixtures/gram-list.ml @@ -0,0 +1,13 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +value main = G.Entry.mk "main"; +EXTEND G + GLOBAL: main; + main: + [ [ l = LIST1 ident -> l ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +let f = Sys.argv.(1) in +Format.printf "%d@." + (List.length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f)))); diff --git a/camlp4/test/fixtures/gram-loc-lost.ml b/camlp4/test/fixtures/gram-loc-lost.ml new file mode 100644 index 0000000..38b164e --- /dev/null +++ b/camlp4/test/fixtures/gram-loc-lost.ml @@ -0,0 +1,30 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +(* type t = [ A of Loc.t and t and t | B of Loc.t and string ]; *) +value main = G.Entry.mk "main"; +(* value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc ]; +value length _ _ = -1; *) +EXTEND G + GLOBAL: main; + main: + [ RIGHTA + [ x = SELF; y = SELF -> + let l = Loc.merge x y in + if l = _loc then _loc + else do { + Format.eprintf "bad loc: %a <> %a + %a@." + Loc.dump _loc Loc.dump x Loc.dump y; + _loc + } + | i = ident -> i ] ]; + ident: + [ [ `LIDENT _ -> _loc ] ]; +END; +try + let f = Sys.argv.(1) in + Format.printf "%a@." + Loc.dump (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) +with e -> Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; diff --git a/camlp4/test/fixtures/gram-sub-rule.ml b/camlp4/test/fixtures/gram-sub-rule.ml new file mode 100644 index 0000000..4066cae --- /dev/null +++ b/camlp4/test/fixtures/gram-sub-rule.ml @@ -0,0 +1,33 @@ +open Camlp4.PreCast.Syntax; + +value mo _loc = + fun + [ None -> <:expr< None >> + | Some e -> <:expr< Some $e$ >> ]; + +EXTEND Gram +GLOBAL: expr; +expr: + [ [ "testbegin"; + lb = [ "("; l = LIST0 a_LIDENT SEP ","; ")" -> l | "()" -> [] ]; + b = bar; + "testend" -> + let e = + List.fold_right (fun i acc -> <:expr< [ $lid:i$ :: $acc$ ] >>) lb <:expr< [] >> + in <:expr< ($e$, $b$) >> + ] ]; +bar: + [ [ x = OPT [ o = OPT [ x = "testb" -> + <:expr< $str:Token.extract_string x$ >> ]; "testc"; b = baz -> + <:expr< ($mo _loc o$, $b$) >> ] -> mo _loc x + ] ]; +(* bar: + [ [ o = OPT [ o = OPT [ "bar" -> <:expr< bar >> ]; b = baz -> <:expr< ($mo _loc o$, $b$) >> ] -> + mo _loc o + ] ]; *) +(* bar: + [ [ o = OPT [ "bar" -> <:expr< bar >> ]; b = baz -> <:expr< ($mo _loc o$, $b$) >> + ] ]; *) +baz: + [ [ "baz" -> <:expr< baz >> ] ]; +END; diff --git a/camlp4/test/fixtures/gram-tree.ml b/camlp4/test/fixtures/gram-tree.ml new file mode 100644 index 0000000..ec1dd05 --- /dev/null +++ b/camlp4/test/fixtures/gram-tree.ml @@ -0,0 +1,22 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +type t = [ A of t and t | B of string ]; +value main = G.Entry.mk "main"; +(* value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc ]; *) +value length _ _ = -1; +EXTEND G + GLOBAL: main; + main: + [ [ x = SELF; y = SELF -> A x y + | i = ident -> B i ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +try + let f = Sys.argv.(1) in + Format.printf "%d@." + (length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) 0) +with e -> Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; diff --git a/camlp4/test/fixtures/gram-tree2.ml b/camlp4/test/fixtures/gram-tree2.ml new file mode 100644 index 0000000..68f8b0a --- /dev/null +++ b/camlp4/test/fixtures/gram-tree2.ml @@ -0,0 +1,22 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +type t = [ A of t and t | B of string ]; +value main = G.Entry.mk "main"; +(* value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc ]; *) +value length _ _ = -1; +EXTEND G + GLOBAL: main; + main: + [ [ i = ident; x = SELF -> A (B i) x + | i = ident -> B i ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +try + let f = Sys.argv.(1) in + Format.printf "%d@." + (length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) 0) +with e -> Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; diff --git a/camlp4/test/fixtures/gram-tree3.ml b/camlp4/test/fixtures/gram-tree3.ml new file mode 100644 index 0000000..06af8dd --- /dev/null +++ b/camlp4/test/fixtures/gram-tree3.ml @@ -0,0 +1,23 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +type t = [ A of t and t | B of string ]; +value main = G.Entry.mk "main"; +(* value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc ]; *) +value length _ _ = -1; +EXTEND G + GLOBAL: main; + main: + [ RIGHTA + [ x = SELF; y = SELF -> A x y + | i = ident -> B i ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +try + let f = Sys.argv.(1) in + Format.printf "%d@." + (length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) 0) +with e -> Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e; diff --git a/camlp4/test/fixtures/gram.ml b/camlp4/test/fixtures/gram.ml new file mode 100644 index 0000000..6a5f7e3 --- /dev/null +++ b/camlp4/test/fixtures/gram.ml @@ -0,0 +1,2 @@ +EXTEND G expr: [[ l = LIST0 STRING -> l ]]; END; +EXTEND G expr: [[ l = LIST0 [ x = STRING -> x ] -> l ]]; END; diff --git a/camlp4/test/fixtures/idents b/camlp4/test/fixtures/idents new file mode 100644 index 0000000..de41468 --- /dev/null +++ b/camlp4/test/fixtures/idents @@ -0,0 +1,38 @@ +aaa aab aac aad aae aaf aag aah aai aaj aak aal aam aan aao aap aaq aar aas +aat aau aav aaw aax aay aaz aba abb abc abd abe abf abg abh abi abj abk abl +abm abn abo abp abq abr abs abt abu abv abw abx aby abz aca acb acc acd ace +acf acg ach aci acj ack acl acm acn aco acp acq acr acs act acu acv acw acx +acy acz ada adb adc add ade adf adg adh adi adj adk adl adm adn ado adp adq +adr ads adt adu adv adw adx ady adz aea aeb aec aed aee aef aeg aeh aei aej +aek ael aem aen aeo aep aeq aer aes aet aeu aev aew aex aey aez afa afb afc +afd afe aff afg afh afi afj afk afl afm afn afo afp afq afr afs aft afu afv +afw afx afy afz aga agb agc agd age agf agg agh agi agj agk agl agm agn ago +agp agq agr ags agt agu agv agw agx agy agz aha ahb ahc ahd ahe ahf ahg ahh +ahi ahj ahk ahl ahm ahn aho ahp ahq ahr ahs aht ahu ahv ahw ahx ahy ahz aia +aib aic aid aie aif aig aih aii aij aik ail aim ain aio aip aiq air ais ait +aiu aiv aiw aix aiy aiz aja ajb ajc ajd aje ajf ajg ajh aji ajj ajk ajl ajm +ajn ajo ajp ajq ajr ajs ajt aju ajv ajw ajx ajy ajz aka akb akc akd ake akf +akg akh aki akj akk akl akm akn ako akp akq akr aks akt aku akv akw akx aky +akz ala alb alc ald ale alf alg alh ali alj alk all alm aln alo alp alq alr +als alt alu alv alw alx aly alz ama amb amc amd ame amf amg amh ami amj amk +aml amm amn amo amp amq amr ams amt amu amv amw amx amy amz ana anb anc and +ane anf ang anh ani anj ank anl anm ann ano anp anq anr ans ant anu anv anw +anx any anz aoa aob aoc aod aoe aof aog aoh aoi aoj aok aol aom aon aoo aop +aoq aor aos aot aou aov aow aox aoy aoz apa apb apc apd ape apf apg aph api +apj apk apl apm apn apo app apq apr aps apt apu apv apw apx apy apz aqa aqb +aqc aqd aqe aqf aqg aqh aqi aqj aqk aql aqm aqn aqo aqp aqq aqr aqs aqt aqu +aqv aqw aqx aqy aqz ara arb arc ard are arf arg arh ari arj ark arl arm arn +aro arp arq arr ars art aru arv arw arx ary arz asa asb asc asd ase asf asg +ash asi asj ask asl asm asn aso asp asq asr ass ast asu asv asw asx asy asz +ata atb atc atd ate atf atg ath ati atj atk atl atm atn ato atp atq atr ats +att atu atv atw atx aty atz aua aub auc aud aue auf aug auh aui auj auk aul +aum aun auo aup auq aur aus aut auu auv auw aux auy auz ava avb avc avd ave +avf avg avh avi avj avk avl avm avn avo avp avq avr avs avt avu avv avw avx +avy avz awa awb awc awd awe awf awg awh awi awj awk awl awm awn awo awp awq +awr aws awt awu awv aww awx awy awz axa axb axc axd axe axf axg axh axi axj +axk axl axm axn axo axp axq axr axs axt axu axv axw axx axy axz aya ayb ayc +ayd aye ayf ayg ayh ayi ayj ayk ayl aym ayn ayo ayp ayq ayr ays ayt ayu ayv +ayw ayx ayy ayz aza azb azc azd aze azf azg azh azi azj azk azl azm azn azo +azp azq azr azs azt azu azv azw azx azy azz baa bab bac bad bae baf bag bah +bai baj bak bal bam ban bao bap baq bar bas bat bau bav baw bax bay baz bba +bbb diff --git a/camlp4/test/fixtures/idents1 b/camlp4/test/fixtures/idents1 new file mode 100644 index 0000000..5da5440 --- /dev/null +++ b/camlp4/test/fixtures/idents1 @@ -0,0 +1,499 @@ +aaaa aaab aaac aaad aaae aaaf aaag aaah aaai aaaj aaak aaal aaam aaan aaao +aaap aaaq aaar aaas aaat aaau aaav aaaw aaax aaay aaaz aaba aabb aabc aabd +aabe aabf aabg aabh aabi aabj aabk aabl aabm aabn aabo aabp aabq aabr aabs +aabt aabu aabv aabw aabx aaby aabz aaca aacb aacc aacd aace aacf aacg aach +aaci aacj aack aacl aacm aacn aaco aacp aacq aacr aacs aact aacu aacv aacw +aacx aacy aacz aada aadb aadc aadd aade aadf aadg aadh aadi aadj aadk aadl +aadm aadn aado aadp aadq aadr aads aadt aadu aadv aadw aadx aady aadz aaea +aaeb aaec aaed aaee aaef aaeg aaeh aaei aaej aaek aael aaem aaen aaeo aaep +aaeq aaer aaes aaet aaeu aaev aaew aaex aaey aaez aafa aafb aafc aafd aafe +aaff aafg aafh aafi aafj aafk aafl aafm aafn aafo aafp aafq aafr aafs aaft +aafu aafv aafw aafx aafy aafz aaga aagb aagc aagd aage aagf aagg aagh aagi +aagj aagk aagl aagm aagn aago aagp aagq aagr aags aagt aagu aagv aagw aagx +aagy aagz aaha aahb aahc aahd aahe aahf aahg aahh aahi aahj aahk aahl aahm +aahn aaho aahp aahq aahr aahs aaht aahu aahv aahw aahx aahy aahz aaia aaib +aaic aaid aaie aaif aaig aaih aaii aaij aaik aail aaim aain aaio aaip aaiq +aair aais aait aaiu aaiv aaiw aaix aaiy aaiz aaja aajb aajc aajd aaje aajf +aajg aajh aaji aajj aajk aajl aajm aajn aajo aajp aajq aajr aajs aajt aaju +aajv aajw aajx aajy aajz aaka aakb aakc aakd aake aakf aakg aakh aaki aakj +aakk aakl aakm aakn aako aakp aakq aakr aaks aakt aaku aakv aakw aakx aaky +aakz aala aalb aalc aald aale aalf aalg aalh aali aalj aalk aall aalm aaln +aalo aalp aalq aalr aals aalt aalu aalv aalw aalx aaly aalz aama aamb aamc +aamd aame aamf aamg aamh aami aamj aamk aaml aamm aamn aamo aamp aamq aamr +aams aamt aamu aamv aamw aamx aamy aamz aana aanb aanc aand aane aanf aang +aanh aani aanj aank aanl aanm aann aano aanp aanq aanr aans aant aanu aanv +aanw aanx aany aanz aaoa aaob aaoc aaod aaoe aaof aaog aaoh aaoi aaoj aaok +aaol aaom aaon aaoo aaop aaoq aaor aaos aaot aaou aaov aaow aaox aaoy aaoz +aapa aapb aapc aapd aape aapf aapg aaph aapi aapj aapk aapl aapm aapn aapo +aapp aapq aapr aaps aapt aapu aapv aapw aapx aapy aapz aaqa aaqb aaqc aaqd +aaqe aaqf aaqg aaqh aaqi aaqj aaqk aaql aaqm aaqn aaqo aaqp aaqq aaqr aaqs +aaqt aaqu aaqv aaqw aaqx aaqy aaqz aara aarb aarc aard aare aarf aarg aarh +aari aarj aark aarl aarm aarn aaro aarp aarq aarr aars aart aaru aarv aarw +aarx aary aarz aasa aasb aasc aasd aase aasf aasg aash aasi aasj aask aasl +aasm aasn aaso aasp aasq aasr aass aast aasu aasv aasw aasx aasy aasz aata +aatb aatc aatd aate aatf aatg aath aati aatj aatk aatl aatm aatn aato aatp +aatq aatr aats aatt aatu aatv aatw aatx aaty aatz aaua aaub aauc aaud aaue +aauf aaug aauh aaui aauj aauk aaul aaum aaun aauo aaup aauq aaur aaus aaut +aauu aauv aauw aaux aauy aauz aava aavb aavc aavd aave aavf aavg aavh aavi +aavj aavk aavl aavm aavn aavo aavp aavq aavr aavs aavt aavu aavv aavw aavx +aavy aavz aawa aawb aawc aawd aawe aawf aawg aawh aawi aawj aawk aawl aawm +aawn aawo aawp aawq aawr aaws aawt aawu aawv aaww aawx aawy aawz aaxa aaxb +aaxc aaxd aaxe aaxf aaxg aaxh aaxi aaxj aaxk aaxl aaxm aaxn aaxo aaxp aaxq +aaxr aaxs aaxt aaxu aaxv aaxw aaxx aaxy aaxz aaya aayb aayc aayd aaye aayf +aayg aayh aayi aayj aayk aayl aaym aayn aayo aayp aayq aayr aays aayt aayu +aayv aayw aayx aayy aayz aaza aazb aazc aazd aaze aazf aazg aazh aazi aazj +aazk aazl aazm aazn aazo aazp aazq aazr aazs aazt aazu aazv aazw aazx aazy +aazz abaa abab abac abad abae abaf abag abah abai abaj abak abal abam aban +abao abap abaq abar abas abat abau abav abaw abax abay abaz abba abbb abbc +abbd abbe abbf abbg abbh abbi abbj abbk abbl abbm abbn abbo abbp abbq abbr +abbs abbt abbu abbv abbw abbx abby abbz abca abcb abcc abcd abce abcf abcg +abch abci abcj abck abcl abcm abcn abco abcp abcq abcr abcs abct abcu abcv +abcw abcx abcy abcz abda abdb abdc abdd abde abdf abdg abdh abdi abdj abdk +abdl abdm abdn abdo abdp abdq abdr abds abdt abdu abdv abdw abdx abdy abdz +abea abeb abec abed abee abef abeg abeh abei abej abek abel abem aben abeo +abep abeq aber abes abet abeu abev abew abex abey abez abfa abfb abfc abfd +abfe abff abfg abfh abfi abfj abfk abfl abfm abfn abfo abfp abfq abfr abfs +abft abfu abfv abfw abfx abfy abfz abga abgb abgc abgd abge abgf abgg abgh +abgi abgj abgk abgl abgm abgn abgo abgp abgq abgr abgs abgt abgu abgv abgw +abgx abgy abgz abha abhb abhc abhd abhe abhf abhg abhh abhi abhj abhk abhl +abhm abhn abho abhp abhq abhr abhs abht abhu abhv abhw abhx abhy abhz abia +abib abic abid abie abif abig abih abii abij abik abil abim abin abio abip +abiq abir abis abit abiu abiv abiw abix abiy abiz abja abjb abjc abjd abje +abjf abjg abjh abji abjj abjk abjl abjm abjn abjo abjp abjq abjr abjs abjt +abju abjv abjw abjx abjy abjz abka abkb abkc abkd abke abkf abkg abkh abki +abkj abkk abkl abkm abkn abko abkp abkq abkr abks abkt abku abkv abkw abkx +abky abkz abla ablb ablc abld able ablf ablg ablh abli ablj ablk abll ablm +abln ablo ablp ablq ablr abls ablt ablu ablv ablw ablx ably ablz abma abmb +abmc abmd abme abmf abmg abmh abmi abmj abmk abml abmm abmn abmo abmp abmq +abmr abms abmt abmu abmv abmw abmx abmy abmz abna abnb abnc abnd abne abnf +abng abnh abni abnj abnk abnl abnm abnn abno abnp abnq abnr abns abnt abnu +abnv abnw abnx abny abnz aboa abob aboc abod aboe abof abog aboh aboi aboj +abok abol abom abon aboo abop aboq abor abos abot abou abov abow abox aboy +aboz abpa abpb abpc abpd abpe abpf abpg abph abpi abpj abpk abpl abpm abpn +abpo abpp abpq abpr abps abpt abpu abpv abpw abpx abpy abpz abqa abqb abqc +abqd abqe abqf abqg abqh abqi abqj abqk abql abqm abqn abqo abqp abqq abqr +abqs abqt abqu abqv abqw abqx abqy abqz abra abrb abrc abrd abre abrf abrg +abrh abri abrj abrk abrl abrm abrn abro abrp abrq abrr abrs abrt abru abrv +abrw abrx abry abrz absa absb absc absd abse absf absg absh absi absj absk +absl absm absn abso absp absq absr abss abst absu absv absw absx absy absz +abta abtb abtc abtd abte abtf abtg abth abti abtj abtk abtl abtm abtn abto +abtp abtq abtr abts abtt abtu abtv abtw abtx abty abtz abua abub abuc abud +abue abuf abug abuh abui abuj abuk abul abum abun abuo abup abuq abur abus +abut abuu abuv abuw abux abuy abuz abva abvb abvc abvd abve abvf abvg abvh +abvi abvj abvk abvl abvm abvn abvo abvp abvq abvr abvs abvt abvu abvv abvw +abvx abvy abvz abwa abwb abwc abwd abwe abwf abwg abwh abwi abwj abwk abwl +abwm abwn abwo abwp abwq abwr abws abwt abwu abwv abww abwx abwy abwz abxa +abxb abxc abxd abxe abxf abxg abxh abxi abxj abxk abxl abxm abxn abxo abxp +abxq abxr abxs abxt abxu abxv abxw abxx abxy abxz abya abyb abyc abyd abye +abyf abyg abyh abyi abyj abyk abyl abym abyn abyo abyp abyq abyr abys abyt +abyu abyv abyw abyx abyy abyz abza abzb abzc abzd abze abzf abzg abzh abzi +abzj abzk abzl abzm abzn abzo abzp abzq abzr abzs abzt abzu abzv abzw abzx +abzy abzz acaa acab acac acad acae acaf acag acah acai acaj acak acal acam +acan acao acap acaq acar acas acat acau acav acaw acax acay acaz acba acbb +acbc acbd acbe acbf acbg acbh acbi acbj acbk acbl acbm acbn acbo acbp acbq +acbr acbs acbt acbu acbv acbw acbx acby acbz acca accb accc accd acce accf +accg acch acci accj acck accl accm accn acco accp accq accr accs acct accu +accv accw accx accy accz acda acdb acdc acdd acde acdf acdg acdh acdi acdj +acdk acdl acdm acdn acdo acdp acdq acdr acds acdt acdu acdv acdw acdx acdy +acdz acea aceb acec aced acee acef aceg aceh acei acej acek acel acem acen +aceo acep aceq acer aces acet aceu acev acew acex acey acez acfa acfb acfc +acfd acfe acff acfg acfh acfi acfj acfk acfl acfm acfn acfo acfp acfq acfr +acfs acft acfu acfv acfw acfx acfy acfz acga acgb acgc acgd acge acgf acgg +acgh acgi acgj acgk acgl acgm acgn acgo acgp acgq acgr acgs acgt acgu acgv +acgw acgx acgy acgz acha achb achc achd ache achf achg achh achi achj achk +achl achm achn acho achp achq achr achs acht achu achv achw achx achy achz +acia acib acic acid acie acif acig acih acii acij acik acil acim acin acio +acip aciq acir acis acit aciu aciv aciw acix aciy aciz acja acjb acjc acjd +acje acjf acjg acjh acji acjj acjk acjl acjm acjn acjo acjp acjq acjr acjs +acjt acju acjv acjw acjx acjy acjz acka ackb ackc ackd acke ackf ackg ackh +acki ackj ackk ackl ackm ackn acko ackp ackq ackr acks ackt acku ackv ackw +ackx acky ackz acla aclb aclc acld acle aclf aclg aclh acli aclj aclk acll +aclm acln aclo aclp aclq aclr acls aclt aclu aclv aclw aclx acly aclz acma +acmb acmc acmd acme acmf acmg acmh acmi acmj acmk acml acmm acmn acmo acmp +acmq acmr acms acmt acmu acmv acmw acmx acmy acmz acna acnb acnc acnd acne +acnf acng acnh acni acnj acnk acnl acnm acnn acno acnp acnq acnr acns acnt +acnu acnv acnw acnx acny acnz acoa acob acoc acod acoe acof acog acoh acoi +acoj acok acol acom acon acoo acop acoq acor acos acot acou acov acow acox +acoy acoz acpa acpb acpc acpd acpe acpf acpg acph acpi acpj acpk acpl acpm +acpn acpo acpp acpq acpr acps acpt acpu acpv acpw acpx acpy acpz acqa acqb +acqc acqd acqe acqf acqg acqh acqi acqj acqk acql acqm acqn acqo acqp acqq +acqr acqs acqt acqu acqv acqw acqx acqy acqz acra acrb acrc acrd acre acrf +acrg acrh acri acrj acrk acrl acrm acrn acro acrp acrq acrr acrs acrt acru +acrv acrw acrx acry acrz acsa acsb acsc acsd acse acsf acsg acsh acsi acsj +acsk acsl acsm acsn acso acsp acsq acsr acss acst acsu acsv acsw acsx acsy +acsz acta actb actc actd acte actf actg acth acti actj actk actl actm actn +acto actp actq actr acts actt actu actv actw actx acty actz acua acub acuc +acud acue acuf acug acuh acui acuj acuk acul acum acun acuo acup acuq acur +acus acut acuu acuv acuw acux acuy acuz acva acvb acvc acvd acve acvf acvg +acvh acvi acvj acvk acvl acvm acvn acvo acvp acvq acvr acvs acvt acvu acvv +acvw acvx acvy acvz acwa acwb acwc acwd acwe acwf acwg acwh acwi acwj acwk +acwl acwm acwn acwo acwp acwq acwr acws acwt acwu acwv acww acwx acwy acwz +acxa acxb acxc acxd acxe acxf acxg acxh acxi acxj acxk acxl acxm acxn acxo +acxp acxq acxr acxs acxt acxu acxv acxw acxx acxy acxz acya acyb acyc acyd +acye acyf acyg acyh acyi acyj acyk acyl acym acyn acyo acyp acyq acyr acys +acyt acyu acyv acyw acyx acyy acyz acza aczb aczc aczd acze aczf aczg aczh +aczi aczj aczk aczl aczm aczn aczo aczp aczq aczr aczs aczt aczu aczv aczw +aczx aczy aczz adaa adab adac adad adae adaf adag adah adai adaj adak adal +adam adan adao adap adaq adar adas adat adau adav adaw adax aday adaz adba +adbb adbc adbd adbe adbf adbg adbh adbi adbj adbk adbl adbm adbn adbo adbp +adbq adbr adbs adbt adbu adbv adbw adbx adby adbz adca adcb adcc adcd adce +adcf adcg adch adci adcj adck adcl adcm adcn adco adcp adcq adcr adcs adct +adcu adcv adcw adcx adcy adcz adda addb addc addd adde addf addg addh addi +addj addk addl addm addn addo addp addq addr adds addt addu addv addw addx +addy addz adea adeb adec aded adee adef adeg adeh adei adej adek adel adem +aden adeo adep adeq ader ades adet adeu adev adew adex adey adez adfa adfb +adfc adfd adfe adff adfg adfh adfi adfj adfk adfl adfm adfn adfo adfp adfq +adfr adfs adft adfu adfv adfw adfx adfy adfz adga adgb adgc adgd adge adgf +adgg adgh adgi adgj adgk adgl adgm adgn adgo adgp adgq adgr adgs adgt adgu +adgv adgw adgx adgy adgz adha adhb adhc adhd adhe adhf adhg adhh adhi adhj +adhk adhl adhm adhn adho adhp adhq adhr adhs adht adhu adhv adhw adhx adhy +adhz adia adib adic adid adie adif adig adih adii adij adik adil adim adin +adio adip adiq adir adis adit adiu adiv adiw adix adiy adiz adja adjb adjc +adjd adje adjf adjg adjh adji adjj adjk adjl adjm adjn adjo adjp adjq adjr +adjs adjt adju adjv adjw adjx adjy adjz adka adkb adkc adkd adke adkf adkg +adkh adki adkj adkk adkl adkm adkn adko adkp adkq adkr adks adkt adku adkv +adkw adkx adky adkz adla adlb adlc adld adle adlf adlg adlh adli adlj adlk +adll adlm adln adlo adlp adlq adlr adls adlt adlu adlv adlw adlx adly adlz +adma admb admc admd adme admf admg admh admi admj admk adml admm admn admo +admp admq admr adms admt admu admv admw admx admy admz adna adnb adnc adnd +adne adnf adng adnh adni adnj adnk adnl adnm adnn adno adnp adnq adnr adns +adnt adnu adnv adnw adnx adny adnz adoa adob adoc adod adoe adof adog adoh +adoi adoj adok adol adom adon adoo adop adoq ador ados adot adou adov adow +adox adoy adoz adpa adpb adpc adpd adpe adpf adpg adph adpi adpj adpk adpl +adpm adpn adpo adpp adpq adpr adps adpt adpu adpv adpw adpx adpy adpz adqa +adqb adqc adqd adqe adqf adqg adqh adqi adqj adqk adql adqm adqn adqo adqp +adqq adqr adqs adqt adqu adqv adqw adqx adqy adqz adra adrb adrc adrd adre +adrf adrg adrh adri adrj adrk adrl adrm adrn adro adrp adrq adrr adrs adrt +adru adrv adrw adrx adry adrz adsa adsb adsc adsd adse adsf adsg adsh adsi +adsj adsk adsl adsm adsn adso adsp adsq adsr adss adst adsu adsv adsw adsx +adsy adsz adta adtb adtc adtd adte adtf adtg adth adti adtj adtk adtl adtm +adtn adto adtp adtq adtr adts adtt adtu adtv adtw adtx adty adtz adua adub +aduc adud adue aduf adug aduh adui aduj aduk adul adum adun aduo adup aduq +adur adus adut aduu aduv aduw adux aduy aduz adva advb advc advd adve advf +advg advh advi advj advk advl advm advn advo advp advq advr advs advt advu +advv advw advx advy advz adwa adwb adwc adwd adwe adwf adwg adwh adwi adwj +adwk adwl adwm adwn adwo adwp adwq adwr adws adwt adwu adwv adww adwx adwy +adwz adxa adxb adxc adxd adxe adxf adxg adxh adxi adxj adxk adxl adxm adxn +adxo adxp adxq adxr adxs adxt adxu adxv adxw adxx adxy adxz adya adyb adyc +adyd adye adyf adyg adyh adyi adyj adyk adyl adym adyn adyo adyp adyq adyr +adys adyt adyu adyv adyw adyx adyy adyz adza adzb adzc adzd adze adzf adzg +adzh adzi adzj adzk adzl adzm adzn adzo adzp adzq adzr adzs adzt adzu adzv +adzw adzx adzy adzz aeaa aeab aeac aead aeae aeaf aeag aeah aeai aeaj aeak +aeal aeam aean aeao aeap aeaq aear aeas aeat aeau aeav aeaw aeax aeay aeaz +aeba aebb aebc aebd aebe aebf aebg aebh aebi aebj aebk aebl aebm aebn aebo +aebp aebq aebr aebs aebt aebu aebv aebw aebx aeby aebz aeca aecb aecc aecd +aece aecf aecg aech aeci aecj aeck aecl aecm aecn aeco aecp aecq aecr aecs +aect aecu aecv aecw aecx aecy aecz aeda aedb aedc aedd aede aedf aedg aedh +aedi aedj aedk aedl aedm aedn aedo aedp aedq aedr aeds aedt aedu aedv aedw +aedx aedy aedz aeea aeeb aeec aeed aeee aeef aeeg aeeh aeei aeej aeek aeel +aeem aeen aeeo aeep aeeq aeer aees aeet aeeu aeev aeew aeex aeey aeez aefa +aefb aefc aefd aefe aeff aefg aefh aefi aefj aefk aefl aefm aefn aefo aefp +aefq aefr aefs aeft aefu aefv aefw aefx aefy aefz aega aegb aegc aegd aege +aegf aegg aegh aegi aegj aegk aegl aegm aegn aego aegp aegq aegr aegs aegt +aegu aegv aegw aegx aegy aegz aeha aehb aehc aehd aehe aehf aehg aehh aehi +aehj aehk aehl aehm aehn aeho aehp aehq aehr aehs aeht aehu aehv aehw aehx +aehy aehz aeia aeib aeic aeid aeie aeif aeig aeih aeii aeij aeik aeil aeim +aein aeio aeip aeiq aeir aeis aeit aeiu aeiv aeiw aeix aeiy aeiz aeja aejb +aejc aejd aeje aejf aejg aejh aeji aejj aejk aejl aejm aejn aejo aejp aejq +aejr aejs aejt aeju aejv aejw aejx aejy aejz aeka aekb aekc aekd aeke aekf +aekg aekh aeki aekj aekk aekl aekm aekn aeko aekp aekq aekr aeks aekt aeku +aekv aekw aekx aeky aekz aela aelb aelc aeld aele aelf aelg aelh aeli aelj +aelk aell aelm aeln aelo aelp aelq aelr aels aelt aelu aelv aelw aelx aely +aelz aema aemb aemc aemd aeme aemf aemg aemh aemi aemj aemk aeml aemm aemn +aemo aemp aemq aemr aems aemt aemu aemv aemw aemx aemy aemz aena aenb aenc +aend aene aenf aeng aenh aeni aenj aenk aenl aenm aenn aeno aenp aenq aenr +aens aent aenu aenv aenw aenx aeny aenz aeoa aeob aeoc aeod aeoe aeof aeog +aeoh aeoi aeoj aeok aeol aeom aeon aeoo aeop aeoq aeor aeos aeot aeou aeov +aeow aeox aeoy aeoz aepa aepb aepc aepd aepe aepf aepg aeph aepi aepj aepk +aepl aepm aepn aepo aepp aepq aepr aeps aept aepu aepv aepw aepx aepy aepz +aeqa aeqb aeqc aeqd aeqe aeqf aeqg aeqh aeqi aeqj aeqk aeql aeqm aeqn aeqo +aeqp aeqq aeqr aeqs aeqt aequ aeqv aeqw aeqx aeqy aeqz aera aerb aerc aerd +aere aerf aerg aerh aeri aerj aerk aerl aerm aern aero aerp aerq aerr aers +aert aeru aerv aerw aerx aery aerz aesa aesb aesc aesd aese aesf aesg aesh +aesi aesj aesk aesl aesm aesn aeso aesp aesq aesr aess aest aesu aesv aesw +aesx aesy aesz aeta aetb aetc aetd aete aetf aetg aeth aeti aetj aetk aetl +aetm aetn aeto aetp aetq aetr aets aett aetu aetv aetw aetx aety aetz aeua +aeub aeuc aeud aeue aeuf aeug aeuh aeui aeuj aeuk aeul aeum aeun aeuo aeup +aeuq aeur aeus aeut aeuu aeuv aeuw aeux aeuy aeuz aeva aevb aevc aevd aeve +aevf aevg aevh aevi aevj aevk aevl aevm aevn aevo aevp aevq aevr aevs aevt +aevu aevv aevw aevx aevy aevz aewa aewb aewc aewd aewe aewf aewg aewh aewi +aewj aewk aewl aewm aewn aewo aewp aewq aewr aews aewt aewu aewv aeww aewx +aewy aewz aexa aexb aexc aexd aexe aexf aexg aexh aexi aexj aexk aexl aexm +aexn aexo aexp aexq aexr aexs aext aexu aexv aexw aexx aexy aexz aeya aeyb +aeyc aeyd aeye aeyf aeyg aeyh aeyi aeyj aeyk aeyl aeym aeyn aeyo aeyp aeyq +aeyr aeys aeyt aeyu aeyv aeyw aeyx aeyy aeyz aeza aezb aezc aezd aeze aezf +aezg aezh aezi aezj aezk aezl aezm aezn aezo aezp aezq aezr aezs aezt aezu +aezv aezw aezx aezy aezz afaa afab afac afad afae afaf afag afah afai afaj +afak afal afam afan afao afap afaq afar afas afat afau afav afaw afax afay +afaz afba afbb afbc afbd afbe afbf afbg afbh afbi afbj afbk afbl afbm afbn +afbo afbp afbq afbr afbs afbt afbu afbv afbw afbx afby afbz afca afcb afcc +afcd afce afcf afcg afch afci afcj afck afcl afcm afcn afco afcp afcq afcr +afcs afct afcu afcv afcw afcx afcy afcz afda afdb afdc afdd afde afdf afdg +afdh afdi afdj afdk afdl afdm afdn afdo afdp afdq afdr afds afdt afdu afdv +afdw afdx afdy afdz afea afeb afec afed afee afef afeg afeh afei afej afek +afel afem afen afeo afep afeq afer afes afet afeu afev afew afex afey afez +affa affb affc affd affe afff affg affh affi affj affk affl affm affn affo +affp affq affr affs afft affu affv affw affx affy affz afga afgb afgc afgd +afge afgf afgg afgh afgi afgj afgk afgl afgm afgn afgo afgp afgq afgr afgs +afgt afgu afgv afgw afgx afgy afgz afha afhb afhc afhd afhe afhf afhg afhh +afhi afhj afhk afhl afhm afhn afho afhp afhq afhr afhs afht afhu afhv afhw +afhx afhy afhz afia afib afic afid afie afif afig afih afii afij afik afil +afim afin afio afip afiq afir afis afit afiu afiv afiw afix afiy afiz afja +afjb afjc afjd afje afjf afjg afjh afji afjj afjk afjl afjm afjn afjo afjp +afjq afjr afjs afjt afju afjv afjw afjx afjy afjz afka afkb afkc afkd afke +afkf afkg afkh afki afkj afkk afkl afkm afkn afko afkp afkq afkr afks afkt +afku afkv afkw afkx afky afkz afla aflb aflc afld afle aflf aflg aflh afli +aflj aflk afll aflm afln aflo aflp aflq aflr afls aflt aflu aflv aflw aflx +afly aflz afma afmb afmc afmd afme afmf afmg afmh afmi afmj afmk afml afmm +afmn afmo afmp afmq afmr afms afmt afmu afmv afmw afmx afmy afmz afna afnb +afnc afnd afne afnf afng afnh afni afnj afnk afnl afnm afnn afno afnp afnq +afnr afns afnt afnu afnv afnw afnx afny afnz afoa afob afoc afod afoe afof +afog afoh afoi afoj afok afol afom afon afoo afop afoq afor afos afot afou +afov afow afox afoy afoz afpa afpb afpc afpd afpe afpf afpg afph afpi afpj +afpk afpl afpm afpn afpo afpp afpq afpr afps afpt afpu afpv afpw afpx afpy +afpz afqa afqb afqc afqd afqe afqf afqg afqh afqi afqj afqk afql afqm afqn +afqo afqp afqq afqr afqs afqt afqu afqv afqw afqx afqy afqz afra afrb afrc +afrd afre afrf afrg afrh afri afrj afrk afrl afrm afrn afro afrp afrq afrr +afrs afrt afru afrv afrw afrx afry afrz afsa afsb afsc afsd afse afsf afsg +afsh afsi afsj afsk afsl afsm afsn afso afsp afsq afsr afss afst afsu afsv +afsw afsx afsy afsz afta aftb aftc aftd afte aftf aftg afth afti aftj aftk +aftl aftm aftn afto aftp aftq aftr afts aftt aftu aftv aftw aftx afty aftz +afua afub afuc afud afue afuf afug afuh afui afuj afuk aful afum afun afuo +afup afuq afur afus afut afuu afuv afuw afux afuy afuz afva afvb afvc afvd +afve afvf afvg afvh afvi afvj afvk afvl afvm afvn afvo afvp afvq afvr afvs +afvt afvu afvv afvw afvx afvy afvz afwa afwb afwc afwd afwe afwf afwg afwh +afwi afwj afwk afwl afwm afwn afwo afwp afwq afwr afws afwt afwu afwv afww +afwx afwy afwz afxa afxb afxc afxd afxe afxf afxg afxh afxi afxj afxk afxl +afxm afxn afxo afxp afxq afxr afxs afxt afxu afxv afxw afxx afxy afxz afya +afyb afyc afyd afye afyf afyg afyh afyi afyj afyk afyl afym afyn afyo afyp +afyq afyr afys afyt afyu afyv afyw afyx afyy afyz afza afzb afzc afzd afze +afzf afzg afzh afzi afzj afzk afzl afzm afzn afzo afzp afzq afzr afzs afzt +afzu afzv afzw afzx afzy afzz agaa agab agac agad agae agaf agag agah agai +agaj agak agal agam agan agao agap agaq agar agas agat agau agav agaw agax +agay agaz agba agbb agbc agbd agbe agbf agbg agbh agbi agbj agbk agbl agbm +agbn agbo agbp agbq agbr agbs agbt agbu agbv agbw agbx agby agbz agca agcb +agcc agcd agce agcf agcg agch agci agcj agck agcl agcm agcn agco agcp agcq +agcr agcs agct agcu agcv agcw agcx agcy agcz agda agdb agdc agdd agde agdf +agdg agdh agdi agdj agdk agdl agdm agdn agdo agdp agdq agdr agds agdt agdu +agdv agdw agdx agdy agdz agea ageb agec aged agee agef ageg ageh agei agej +agek agel agem agen ageo agep ageq ager ages aget ageu agev agew agex agey +agez agfa agfb agfc agfd agfe agff agfg agfh agfi agfj agfk agfl agfm agfn +agfo agfp agfq agfr agfs agft agfu agfv agfw agfx agfy agfz agga aggb aggc +aggd agge aggf aggg aggh aggi aggj aggk aggl aggm aggn aggo aggp aggq aggr +aggs aggt aggu aggv aggw aggx aggy aggz agha aghb aghc aghd aghe aghf aghg +aghh aghi aghj aghk aghl aghm aghn agho aghp aghq aghr aghs aght aghu aghv +aghw aghx aghy aghz agia agib agic agid agie agif agig agih agii agij agik +agil agim agin agio agip agiq agir agis agit agiu agiv agiw agix agiy agiz +agja agjb agjc agjd agje agjf agjg agjh agji agjj agjk agjl agjm agjn agjo +agjp agjq agjr agjs agjt agju agjv agjw agjx agjy agjz agka agkb agkc agkd +agke agkf agkg agkh agki agkj agkk agkl agkm agkn agko agkp agkq agkr agks +agkt agku agkv agkw agkx agky agkz agla aglb aglc agld agle aglf aglg aglh +agli aglj aglk agll aglm agln aglo aglp aglq aglr agls aglt aglu aglv aglw +aglx agly aglz agma agmb agmc agmd agme agmf agmg agmh agmi agmj agmk agml +agmm agmn agmo agmp agmq agmr agms agmt agmu agmv agmw agmx agmy agmz agna +agnb agnc agnd agne agnf agng agnh agni agnj agnk agnl agnm agnn agno agnp +agnq agnr agns agnt agnu agnv agnw agnx agny agnz agoa agob agoc agod agoe +agof agog agoh agoi agoj agok agol agom agon agoo agop agoq agor agos agot +agou agov agow agox agoy agoz agpa agpb agpc agpd agpe agpf agpg agph agpi +agpj agpk agpl agpm agpn agpo agpp agpq agpr agps agpt agpu agpv agpw agpx +agpy agpz agqa agqb agqc agqd agqe agqf agqg agqh agqi agqj agqk agql agqm +agqn agqo agqp agqq agqr agqs agqt agqu agqv agqw agqx agqy agqz agra agrb +agrc agrd agre agrf agrg agrh agri agrj agrk agrl agrm agrn agro agrp agrq +agrr agrs agrt agru agrv agrw agrx agry agrz agsa agsb agsc agsd agse agsf +agsg agsh agsi agsj agsk agsl agsm agsn agso agsp agsq agsr agss agst agsu +agsv agsw agsx agsy agsz agta agtb agtc agtd agte agtf agtg agth agti agtj +agtk agtl agtm agtn agto agtp agtq agtr agts agtt agtu agtv agtw agtx agty +agtz agua agub aguc agud ague aguf agug aguh agui aguj aguk agul agum agun +aguo agup aguq agur agus agut aguu aguv aguw agux aguy aguz agva agvb agvc +agvd agve agvf agvg agvh agvi agvj agvk agvl agvm agvn agvo agvp agvq agvr +agvs agvt agvu agvv agvw agvx agvy agvz agwa agwb agwc agwd agwe agwf agwg +agwh agwi agwj agwk agwl agwm agwn agwo agwp agwq agwr agws agwt agwu agwv +agww agwx agwy agwz agxa agxb agxc agxd agxe agxf agxg agxh agxi agxj agxk +agxl agxm agxn agxo agxp agxq agxr agxs agxt agxu agxv agxw agxx agxy agxz +agya agyb agyc agyd agye agyf agyg agyh agyi agyj agyk agyl agym agyn agyo +agyp agyq agyr agys agyt agyu agyv agyw agyx agyy agyz agza agzb agzc agzd +agze agzf agzg agzh agzi agzj agzk agzl agzm agzn agzo agzp agzq agzr agzs +agzt agzu agzv agzw agzx agzy agzz ahaa ahab ahac ahad ahae ahaf ahag ahah +ahai ahaj ahak ahal aham ahan ahao ahap ahaq ahar ahas ahat ahau ahav ahaw +ahax ahay ahaz ahba ahbb ahbc ahbd ahbe ahbf ahbg ahbh ahbi ahbj ahbk ahbl +ahbm ahbn ahbo ahbp ahbq ahbr ahbs ahbt ahbu ahbv ahbw ahbx ahby ahbz ahca +ahcb ahcc ahcd ahce ahcf ahcg ahch ahci ahcj ahck ahcl ahcm ahcn ahco ahcp +ahcq ahcr ahcs ahct ahcu ahcv ahcw ahcx ahcy ahcz ahda ahdb ahdc ahdd ahde +ahdf ahdg ahdh ahdi ahdj ahdk ahdl ahdm ahdn ahdo ahdp ahdq ahdr ahds ahdt +ahdu ahdv ahdw ahdx ahdy ahdz ahea aheb ahec ahed ahee ahef aheg aheh ahei +ahej ahek ahel ahem ahen aheo ahep aheq aher ahes ahet aheu ahev ahew ahex +ahey ahez ahfa ahfb ahfc ahfd ahfe ahff ahfg ahfh ahfi ahfj ahfk ahfl ahfm +ahfn ahfo ahfp ahfq ahfr ahfs ahft ahfu ahfv ahfw ahfx ahfy ahfz ahga ahgb +ahgc ahgd ahge ahgf ahgg ahgh ahgi ahgj ahgk ahgl ahgm ahgn ahgo ahgp ahgq +ahgr ahgs ahgt ahgu ahgv ahgw ahgx ahgy ahgz ahha ahhb ahhc ahhd ahhe ahhf +ahhg ahhh ahhi ahhj ahhk ahhl ahhm ahhn ahho ahhp ahhq ahhr ahhs ahht ahhu +ahhv ahhw ahhx ahhy ahhz ahia ahib ahic ahid ahie ahif ahig ahih ahii ahij +ahik ahil ahim ahin ahio ahip ahiq ahir ahis ahit ahiu ahiv ahiw ahix ahiy +ahiz ahja ahjb ahjc ahjd ahje ahjf ahjg ahjh ahji ahjj ahjk ahjl ahjm ahjn +ahjo ahjp ahjq ahjr ahjs ahjt ahju ahjv ahjw ahjx ahjy ahjz ahka ahkb ahkc +ahkd ahke ahkf ahkg ahkh ahki ahkj ahkk ahkl ahkm ahkn ahko ahkp ahkq ahkr +ahks ahkt ahku ahkv ahkw ahkx ahky ahkz ahla ahlb ahlc ahld ahle ahlf ahlg +ahlh ahli ahlj ahlk ahll ahlm ahln ahlo ahlp ahlq ahlr ahls ahlt ahlu ahlv +ahlw ahlx ahly ahlz ahma ahmb ahmc ahmd ahme ahmf ahmg ahmh ahmi ahmj ahmk +ahml ahmm ahmn ahmo ahmp ahmq ahmr ahms ahmt ahmu ahmv ahmw ahmx ahmy ahmz +ahna ahnb ahnc ahnd ahne ahnf ahng ahnh ahni ahnj ahnk ahnl ahnm ahnn ahno +ahnp ahnq ahnr ahns ahnt ahnu ahnv ahnw ahnx ahny ahnz ahoa ahob ahoc ahod +ahoe ahof ahog ahoh ahoi ahoj ahok ahol ahom ahon ahoo ahop ahoq ahor ahos +ahot ahou ahov ahow ahox ahoy ahoz ahpa ahpb ahpc ahpd ahpe ahpf ahpg ahph +ahpi ahpj ahpk ahpl ahpm ahpn ahpo ahpp ahpq ahpr ahps ahpt ahpu ahpv ahpw +ahpx ahpy ahpz ahqa ahqb ahqc ahqd ahqe ahqf ahqg ahqh ahqi ahqj ahqk ahql +ahqm ahqn ahqo ahqp ahqq ahqr ahqs ahqt ahqu ahqv ahqw ahqx ahqy ahqz ahra +ahrb ahrc ahrd ahre ahrf ahrg ahrh ahri ahrj ahrk ahrl ahrm ahrn ahro ahrp +ahrq ahrr ahrs ahrt ahru ahrv ahrw ahrx ahry ahrz ahsa ahsb ahsc ahsd ahse +ahsf ahsg ahsh ahsi ahsj ahsk ahsl ahsm ahsn ahso ahsp ahsq ahsr ahss ahst +ahsu ahsv ahsw ahsx ahsy ahsz ahta ahtb ahtc ahtd ahte ahtf ahtg ahth ahti +ahtj ahtk ahtl ahtm ahtn ahto ahtp ahtq ahtr ahts ahtt ahtu ahtv ahtw ahtx +ahty ahtz ahua ahub ahuc ahud ahue ahuf ahug ahuh ahui ahuj ahuk ahul ahum +ahun ahuo ahup ahuq ahur ahus ahut ahuu ahuv ahuw ahux ahuy ahuz ahva ahvb +ahvc ahvd ahve ahvf ahvg ahvh ahvi ahvj ahvk ahvl ahvm ahvn ahvo ahvp ahvq +ahvr ahvs ahvt ahvu ahvv ahvw ahvx ahvy ahvz ahwa ahwb ahwc ahwd ahwe ahwf +ahwg ahwh ahwi ahwj ahwk ahwl ahwm ahwn ahwo ahwp ahwq ahwr ahws ahwt ahwu +ahwv ahww ahwx ahwy ahwz ahxa ahxb ahxc ahxd ahxe ahxf ahxg ahxh ahxi ahxj +ahxk ahxl ahxm ahxn ahxo ahxp ahxq ahxr ahxs ahxt ahxu ahxv ahxw ahxx ahxy +ahxz ahya ahyb ahyc ahyd ahye ahyf ahyg ahyh ahyi ahyj ahyk ahyl ahym ahyn +ahyo ahyp ahyq ahyr ahys ahyt ahyu ahyv ahyw ahyx ahyy ahyz ahza ahzb ahzc +ahzd ahze ahzf ahzg ahzh ahzi ahzj ahzk ahzl ahzm ahzn ahzo ahzp ahzq ahzr +ahzs ahzt ahzu ahzv ahzw ahzx ahzy ahzz aiaa aiab aiac aiad aiae aiaf aiag +aiah aiai aiaj aiak aial aiam aian aiao aiap aiaq aiar aias aiat aiau aiav +aiaw aiax aiay aiaz aiba aibb aibc aibd aibe aibf aibg aibh aibi aibj aibk +aibl aibm aibn aibo aibp aibq aibr aibs aibt aibu aibv aibw aibx aiby aibz +aica aicb aicc aicd aice aicf aicg aich aici aicj aick aicl aicm aicn aico +aicp aicq aicr aics aict aicu aicv aicw aicx aicy aicz aida aidb aidc aidd +aide aidf aidg aidh aidi aidj aidk aidl aidm aidn aido aidp aidq aidr aids +aidt aidu aidv aidw aidx aidy aidz aiea aieb aiec aied aiee aief aieg aieh +aiei aiej aiek aiel aiem aien aieo aiep aieq aier aies aiet aieu aiev aiew +aiex aiey aiez aifa aifb aifc aifd aife aiff aifg aifh aifi aifj aifk aifl +aifm aifn aifo aifp aifq aifr aifs aift aifu aifv aifw aifx aify aifz aiga +aigb aigc aigd aige aigf aigg aigh aigi aigj aigk aigl aigm aign aigo aigp +aigq aigr aigs aigt aigu aigv aigw aigx aigy aigz aiha aihb aihc aihd aihe +aihf aihg aihh aihi aihj aihk aihl aihm aihn aiho aihp aihq aihr aihs aiht +aihu aihv aihw aihx aihy aihz aiia aiib aiic aiid aiie aiif aiig aiih aiii +aiij aiik aiil aiim aiin aiio aiip aiiq aiir aiis aiit aiiu aiiv aiiw aiix +aiiy aiiz aija aijb aijc aijd aije aijf aijg aijh aiji aijj aijk aijl aijm +aijn aijo aijp aijq aijr aijs aijt aiju aijv aijw aijx aijy aijz aika aikb +aikc aikd aike aikf aikg aikh aiki aikj aikk aikl aikm aikn aiko aikp aikq +aikr aiks aikt aiku aikv aikw aikx aiky aikz aila ailb ailc aild aile ailf +ailg ailh aili ailj ailk aill ailm ailn ailo ailp ailq ailr ails ailt ailu +ailv ailw ailx aily ailz aima aimb aimc aimd aime aimf aimg aimh aimi aimj +aimk aiml aimm aimn aimo aimp aimq aimr aims aimt aimu aimv aimw aimx aimy +aimz aina ainb ainc aind aine ainf aing ainh aini ainj aink ainl ainm ainn +aino ainp ainq ainr ains aint ainu ainv ainw ainx ainy ainz aioa aiob aioc +aiod aioe aiof aiog aioh aioi aioj aiok aiol aiom aion aioo aiop aioq aior +aios aiot aiou aiov aiow aiox aioy aioz aipa aipb aipc aipd aipe aipf aipg +aiph aipi aipj aipk aipl aipm aipn aipo aipp aipq aipr aips aipt aipu aipv +aipw aipx aipy aipz aiqa aiqb aiqc aiqd aiqe aiqf aiqg aiqh aiqi aiqj aiqk +aiql aiqm aiqn aiqo aiqp aiqq aiqr aiqs aiqt aiqu aiqv aiqw aiqx aiqy aiqz +aira airb airc aird aire airf airg airh airi airj airk airl airm airn airo +airp airq airr airs airt airu airv airw airx airy airz aisa aisb aisc aisd +aise aisf aisg aish aisi aisj aisk aisl aism aisn aiso aisp aisq aisr aiss +aist aisu aisv aisw aisx aisy aisz aita aitb aitc aitd aite aitf aitg aith +aiti aitj aitk aitl aitm aitn aito aitp aitq aitr aits aitt aitu aitv aitw +aitx aity aitz aiua aiub aiuc aiud aiue aiuf aiug aiuh aiui aiuj aiuk aiul +aium aiun aiuo aiup aiuq aiur aius aiut aiuu aiuv aiuw aiux aiuy aiuz aiva +aivb aivc aivd aive aivf aivg aivh aivi aivj aivk aivl aivm aivn aivo aivp +aivq aivr aivs aivt aivu aivv aivw aivx aivy aivz aiwa aiwb aiwc aiwd aiwe +aiwf aiwg aiwh aiwi aiwj aiwk aiwl aiwm aiwn aiwo aiwp aiwq aiwr aiws aiwt +aiwu aiwv aiww aiwx aiwy aiwz aixa aixb aixc aixd aixe aixf aixg aixh aixi +aixj aixk aixl aixm aixn aixo aixp aixq aixr aixs aixt aixu aixv aixw aixx +aixy aixz aiya aiyb aiyc aiyd aiye aiyf aiyg aiyh aiyi aiyj aiyk aiyl aiym +aiyn aiyo aiyp aiyq aiyr aiys aiyt aiyu aiyv aiyw aiyx aiyy aiyz aiza aizb +aizc aizd aize aizf aizg aizh aizi aizj aizk aizl aizm aizn aizo aizp aizq +aizr aizs aizt aizu aizv aizw aizx aizy aizz ajaa ajab ajac ajad ajae ajaf +ajag ajah ajai ajaj ajak ajal ajam ajan ajao ajap ajaq ajar ajas ajat ajau +ajav ajaw ajax ajay ajaz ajba ajbb ajbc ajbd ajbe ajbf ajbg ajbh ajbi ajbj +ajbk ajbl ajbm ajbn ajbo ajbp ajbq ajbr ajbs ajbt ajbu ajbv ajbw ajbx ajby +ajbz ajca ajcb ajcc ajcd ajce ajcf ajcg ajch ajci ajcj ajck ajcl ajcm ajcn +ajco ajcp ajcq ajcr ajcs ajct ajcu ajcv ajcw ajcx ajcy ajcz ajda ajdb ajdc +ajdd ajde ajdf ajdg ajdh ajdi ajdj ajdk ajdl ajdm ajdn ajdo ajdp ajdq ajdr +ajds ajdt ajdu ajdv ajdw ajdx ajdy ajdz ajea ajeb ajec ajed ajee ajef ajeg +ajeh ajei ajej ajek ajel ajem ajen ajeo ajep ajeq ajer ajes ajet ajeu ajev +ajew ajex ajey ajez ajfa ajfb ajfc ajfd ajfe ajff ajfg ajfh ajfi ajfj ajfk +ajfl ajfm ajfn ajfo ajfp ajfq ajfr ajfs ajft ajfu ajfv ajfw ajfx ajfy ajfz +ajga ajgb ajgc ajgd ajge ajgf ajgg ajgh ajgi ajgj ajgk ajgl ajgm ajgn ajgo +ajgp ajgq ajgr ajgs ajgt ajgu ajgv ajgw ajgx ajgy ajgz ajha ajhb ajhc ajhd +ajhe ajhf ajhg ajhh ajhi ajhj ajhk ajhl ajhm ajhn ajho ajhp ajhq ajhr ajhs +ajht ajhu ajhv ajhw ajhx ajhy ajhz ajia ajib ajic ajid ajie ajif ajig ajih +ajii ajij ajik ajil ajim ajin ajio ajip ajiq ajir ajis ajit ajiu ajiv ajiw +ajix ajiy ajiz ajja ajjb ajjc ajjd ajje ajjf ajjg ajjh ajji ajjj ajjk ajjl +ajjm ajjn ajjo ajjp ajjq ajjr ajjs ajjt ajju ajjv ajjw ajjx ajjy ajjz ajka +ajkb ajkc ajkd ajke ajkf ajkg ajkh ajki ajkj ajkk ajkl ajkm ajkn ajko ajkp +ajkq ajkr ajks ajkt ajku ajkv ajkw ajkx ajky ajkz ajla ajlb ajlc ajld ajle +ajlf ajlg ajlh ajli ajlj ajlk ajll ajlm ajln ajlo ajlp ajlq ajlr ajls ajlt +ajlu ajlv ajlw ajlx ajly ajlz ajma ajmb ajmc ajmd ajme ajmf ajmg ajmh ajmi +ajmj ajmk ajml ajmm ajmn ajmo ajmp ajmq ajmr ajms ajmt ajmu ajmv ajmw ajmx +ajmy ajmz ajna ajnb ajnc ajnd ajne ajnf ajng ajnh ajni ajnj ajnk ajnl ajnm +ajnn ajno ajnp ajnq ajnr ajns ajnt ajnu ajnv ajnw ajnx ajny ajnz ajoa ajob +ajoc ajod ajoe ajof ajog ajoh ajoi ajoj ajok ajol ajom ajon ajoo ajop ajoq +ajor ajos ajot ajou ajov ajow ajox ajoy ajoz ajpa ajpb ajpc ajpd ajpe ajpf +ajpg ajph ajpi ajpj ajpk ajpl ajpm ajpn ajpo ajpp ajpq ajpr ajps ajpt ajpu +ajpv ajpw ajpx ajpy ajpz ajqa ajqb ajqc ajqd ajqe ajqf ajqg ajqh ajqi ajqj +ajqk ajql ajqm ajqn ajqo ajqp ajqq ajqr ajqs ajqt ajqu ajqv ajqw ajqx ajqy +ajqz ajra ajrb ajrc ajrd ajre ajrf ajrg ajrh ajri ajrj ajrk ajrl ajrm ajrn +ajro ajrp ajrq ajrr ajrs ajrt ajru ajrv ajrw ajrx ajry ajrz ajsa ajsb ajsc +ajsd ajse ajsf ajsg ajsh ajsi ajsj ajsk ajsl ajsm ajsn ajso ajsp ajsq ajsr +ajss ajst ajsu ajsv ajsw ajsx ajsy ajsz ajta ajtb ajtc ajtd ajte ajtf ajtg +ajth ajti ajtj ajtk ajtl ajtm ajtn ajto ajtp ajtq ajtr ajts ajtt ajtu ajtv +ajtw ajtx ajty ajtz ajua ajub ajuc ajud ajue ajuf ajug ajuh ajui ajuj ajuk +ajul ajum ajun ajuo ajup ajuq ajur ajus ajut ajuu ajuv ajuw ajux ajuy ajuz +ajva ajvb ajvc ajvd ajve ajvf ajvg ajvh ajvi ajvj ajvk ajvl ajvm ajvn ajvo +ajvp ajvq ajvr ajvs ajvt ajvu ajvv ajvw ajvx ajvy ajvz ajwa ajwb ajwc ajwd +ajwe ajwf ajwg ajwh ajwi ajwj ajwk ajwl ajwm ajwn ajwo ajwp ajwq ajwr ajws +ajwt ajwu ajwv ajww ajwx ajwy ajwz ajxa ajxb ajxc ajxd ajxe ajxf ajxg ajxh +ajxi ajxj ajxk ajxl ajxm ajxn ajxo ajxp ajxq ajxr ajxs ajxt ajxu ajxv ajxw +ajxx ajxy ajxz ajya ajyb ajyc ajyd ajye ajyf ajyg ajyh ajyi ajyj ajyk ajyl +ajym ajyn ajyo ajyp ajyq ajyr ajys ajyt ajyu ajyv ajyw ajyx ajyy ajyz ajza +ajzb ajzc ajzd ajze ajzf ajzg ajzh ajzi ajzj ajzk ajzl ajzm ajzn ajzo ajzp +ajzq ajzr ajzs ajzt ajzu ajzv ajzw ajzx ajzy ajzz akaa akab akac akad akae +akaf akag akah akai akaj akak akal akam akan akao akap akaq akar akas akat +akau akav akaw akax akay akaz akba akbb akbc akbd akbe akbf akbg akbh akbi +akbj akbk akbl akbm akbn akbo akbp akbq akbr akbs akbt akbu akbv akbw akbx +akby akbz akca akcb akcc akcd akce akcf akcg akch akci akcj akck akcl akcm +akcn akco akcp akcq akcr akcs akct akcu akcv akcw akcx akcy akcz akda akdb +akdc akdd akde akdf akdg akdh akdi akdj akdk akdl akdm akdn akdo akdp akdq +akdr akds akdt akdu akdv akdw akdx akdy akdz akea akeb akec aked akee akef +akeg akeh akei akej akek akel akem aken akeo akep akeq aker akes aket akeu +akev akew akex akey akez akfa akfb akfc akfd akfe akff akfg akfh akfi akfj +akfk akfl akfm akfn akfo akfp akfq akfr akfs akft akfu akfv akfw akfx akfy +akfz akga akgb akgc akgd akge akgf akgg akgh akgi akgj akgk akgl akgm akgn +akgo akgp akgq akgr akgs akgt akgu akgv akgw akgx akgy akgz akha akhb akhc +akhd akhe akhf akhg akhh akhi akhj akhk akhl akhm akhn akho akhp akhq akhr +akhs akht akhu akhv akhw akhx akhy akhz akia akib akic akid akie akif akig +akih akii akij akik akil akim akin akio akip akiq akir akis akit akiu akiv +akiw akix akiy akiz akja akjb akjc akjd akje akjf akjg akjh akji akjj akjk +akjl akjm akjn akjo akjp akjq akjr akjs akjt akju akjv akjw akjx akjy akjz +akka akkb akkc akkd akke akkf akkg akkh akki akkj akkk akkl akkm akkn akko +akkp akkq akkr akks akkt akku akkv akkw akkx akky akkz akla aklb aklc akld +akle aklf aklg aklh akli aklj aklk akll aklm akln aklo aklp aklq aklr akls +aklt aklu aklv aklw aklx akly aklz akma akmb akmc akmd akme akmf akmg akmh +akmi akmj akmk akml akmm akmn akmo akmp akmq akmr akms akmt akmu akmv akmw +akmx akmy akmz akna aknb aknc aknd akne aknf akng aknh akni aknj aknk aknl +aknm aknn akno aknp aknq aknr akns aknt aknu aknv aknw aknx akny aknz akoa +akob akoc akod akoe akof akog akoh akoi akoj akok akol akom akon akoo akop +akoq akor akos akot akou akov akow akox akoy akoz akpa akpb akpc akpd akpe +akpf akpg akph akpi akpj akpk akpl akpm akpn akpo akpp akpq akpr akps akpt +akpu akpv akpw akpx akpy akpz akqa akqb akqc akqd akqe akqf akqg akqh akqi +akqj akqk akql akqm akqn akqo akqp akqq akqr akqs akqt akqu akqv akqw akqx +akqy akqz akra akrb akrc akrd akre akrf akrg akrh akri akrj akrk akrl akrm +akrn akro akrp akrq akrr akrs akrt akru akrv akrw akrx akry akrz aksa aksb +aksc aksd akse aksf aksg aksh aksi aksj aksk aksl aksm aksn akso aksp aksq +aksr akss akst aksu aksv aksw aksx aksy aksz akta aktb aktc aktd akte aktf +aktg akth akti aktj aktk aktl aktm aktn akto aktp aktq aktr akts aktt aktu +aktv aktw aktx akty aktz akua akub akuc akud akue akuf akug akuh akui akuj +akuk akul akum akun akuo akup akuq akur akus akut akuu akuv akuw akux akuy +akuz akva akvb akvc akvd akve akvf akvg akvh akvi akvj akvk akvl akvm akvn +akvo akvp akvq akvr akvs akvt akvu akvv akvw akvx akvy akvz akwa akwb akwc +akwd akwe akwf akwg akwh akwi akwj akwk akwl akwm akwn akwo akwp akwq akwr +akws akwt akwu akwv akww akwx akwy akwz akxa akxb akxc akxd akxe akxf akxg +akxh akxi akxj akxk akxl akxm akxn akxo akxp akxq akxr akxs akxt akxu akxv +akxw akxx akxy akxz akya akyb akyc akyd akye akyf akyg akyh akyi akyj akyk +akyl akym akyn akyo akyp akyq akyr akys akyt akyu akyv akyw akyx akyy akyz +akza akzb akzc akzd akze akzf akzg akzh akzi akzj akzk akzl akzm akzn akzo +akzp akzq akzr akzs akzt akzu akzv akzw akzx akzy akzz alaa alab alac alad +alae alaf alag alah alai alaj alak alal alam alan alao alap alaq alar alas +alat alau alav alaw alax alay alaz alba albb albc albd albe albf albg albh +albi albj albk albl albm albn albo albp albq albr albs albt albu albv albw diff --git a/camlp4/test/fixtures/idents2 b/camlp4/test/fixtures/idents2 new file mode 100644 index 0000000..ef07f3e --- /dev/null +++ b/camlp4/test/fixtures/idents2 @@ -0,0 +1,1219 @@ +aaaa aaab aaac aaad aaae aaaf aaag aaah aaai aaaj aaak aaal aaam aaan aaao +aaap aaaq aaar aaas aaat aaau aaav aaaw aaax aaay aaaz aaba aabb aabc aabd +aabe aabf aabg aabh aabi aabj aabk aabl aabm aabn aabo aabp aabq aabr aabs +aabt aabu aabv aabw aabx aaby aabz aaca aacb aacc aacd aace aacf aacg aach +aaci aacj aack aacl aacm aacn aaco aacp aacq aacr aacs aact aacu aacv aacw +aacx aacy aacz aada aadb aadc aadd aade aadf aadg aadh aadi aadj aadk aadl +aadm aadn aado aadp aadq aadr aads aadt aadu aadv aadw aadx aady aadz aaea +aaeb aaec aaed aaee aaef aaeg aaeh aaei aaej aaek aael aaem aaen aaeo aaep +aaeq aaer aaes aaet aaeu aaev aaew aaex aaey aaez aafa aafb aafc aafd aafe +aaff aafg aafh aafi aafj aafk aafl aafm aafn aafo aafp aafq aafr aafs aaft +aafu aafv aafw aafx aafy aafz aaga aagb aagc aagd aage aagf aagg aagh aagi +aagj aagk aagl aagm aagn aago aagp aagq aagr aags aagt aagu aagv aagw aagx +aagy aagz aaha aahb aahc aahd aahe aahf aahg aahh aahi aahj aahk aahl aahm +aahn aaho aahp aahq aahr aahs aaht aahu aahv aahw aahx aahy aahz aaia aaib +aaic aaid aaie aaif aaig aaih aaii aaij aaik aail aaim aain aaio aaip aaiq +aair aais aait aaiu aaiv aaiw aaix aaiy aaiz aaja aajb aajc aajd aaje aajf +aajg aajh aaji aajj aajk aajl aajm aajn aajo aajp aajq aajr aajs aajt aaju +aajv aajw aajx aajy aajz aaka aakb aakc aakd aake aakf aakg aakh aaki aakj +aakk aakl aakm aakn aako aakp aakq aakr aaks aakt aaku aakv aakw aakx aaky +aakz aala aalb aalc aald aale aalf aalg aalh aali aalj aalk aall aalm aaln +aalo aalp aalq aalr aals aalt aalu aalv aalw aalx aaly aalz aama aamb aamc +aamd aame aamf aamg aamh aami aamj aamk aaml aamm aamn aamo aamp aamq aamr +aams aamt aamu aamv aamw aamx aamy aamz aana aanb aanc aand aane aanf aang +aanh aani aanj aank aanl aanm aann aano aanp aanq aanr aans aant aanu aanv +aanw aanx aany aanz aaoa aaob aaoc aaod aaoe aaof aaog aaoh aaoi aaoj aaok +aaol aaom aaon aaoo aaop aaoq aaor aaos aaot aaou aaov aaow aaox aaoy aaoz +aapa aapb aapc aapd aape aapf aapg aaph aapi aapj aapk aapl aapm aapn aapo +aapp aapq aapr aaps aapt aapu aapv aapw aapx aapy aapz aaqa aaqb aaqc aaqd +aaqe aaqf aaqg aaqh aaqi aaqj aaqk aaql aaqm aaqn aaqo aaqp aaqq aaqr aaqs +aaqt aaqu aaqv aaqw aaqx aaqy aaqz aara aarb aarc aard aare aarf aarg aarh +aari aarj aark aarl aarm aarn aaro aarp aarq aarr aars aart aaru aarv aarw +aarx aary aarz aasa aasb aasc aasd aase aasf aasg aash aasi aasj aask aasl +aasm aasn aaso aasp aasq aasr aass aast aasu aasv aasw aasx aasy aasz aata +aatb aatc aatd aate aatf aatg aath aati aatj aatk aatl aatm aatn aato aatp +aatq aatr aats aatt aatu aatv aatw aatx aaty aatz aaua aaub aauc aaud aaue +aauf aaug aauh aaui aauj aauk aaul aaum aaun aauo aaup aauq aaur aaus aaut +aauu aauv aauw aaux aauy aauz aava aavb aavc aavd aave aavf aavg aavh aavi +aavj aavk aavl aavm aavn aavo aavp aavq aavr aavs aavt aavu aavv aavw aavx +aavy aavz aawa aawb aawc aawd aawe aawf aawg aawh aawi aawj aawk aawl aawm +aawn aawo aawp aawq aawr aaws aawt aawu aawv aaww aawx aawy aawz aaxa aaxb +aaxc aaxd aaxe aaxf aaxg aaxh aaxi aaxj aaxk aaxl aaxm aaxn aaxo aaxp aaxq +aaxr aaxs aaxt aaxu aaxv aaxw aaxx aaxy aaxz aaya aayb aayc aayd aaye aayf +aayg aayh aayi aayj aayk aayl aaym aayn aayo aayp aayq aayr aays aayt aayu +aayv aayw aayx aayy aayz aaza aazb aazc aazd aaze aazf aazg aazh aazi aazj +aazk aazl aazm aazn aazo aazp aazq aazr aazs aazt aazu aazv aazw aazx aazy +aazz abaa abab abac abad abae abaf abag abah abai abaj abak abal abam aban +abao abap abaq abar abas abat abau abav abaw abax abay abaz abba abbb abbc +abbd abbe abbf abbg abbh abbi abbj abbk abbl abbm abbn abbo abbp abbq abbr +abbs abbt abbu abbv abbw abbx abby abbz abca abcb abcc abcd abce abcf abcg +abch abci abcj abck abcl abcm abcn abco abcp abcq abcr abcs abct abcu abcv +abcw abcx abcy abcz abda abdb abdc abdd abde abdf abdg abdh abdi abdj abdk +abdl abdm abdn abdo abdp abdq abdr abds abdt abdu abdv abdw abdx abdy abdz +abea abeb abec abed abee abef abeg abeh abei abej abek abel abem aben abeo +abep abeq aber abes abet abeu abev abew abex abey abez abfa abfb abfc abfd +abfe abff abfg abfh abfi abfj abfk abfl abfm abfn abfo abfp abfq abfr abfs +abft abfu abfv abfw abfx abfy abfz abga abgb abgc abgd abge abgf abgg abgh +abgi abgj abgk abgl abgm abgn abgo abgp abgq abgr abgs abgt abgu abgv abgw +abgx abgy abgz abha abhb abhc abhd abhe abhf abhg abhh abhi abhj abhk abhl +abhm abhn abho abhp abhq abhr abhs abht abhu abhv abhw abhx abhy abhz abia +abib abic abid abie abif abig abih abii abij abik abil abim abin abio abip +abiq abir abis abit abiu abiv abiw abix abiy abiz abja abjb abjc abjd abje +abjf abjg abjh abji abjj abjk abjl abjm abjn abjo abjp abjq abjr abjs abjt +abju abjv abjw abjx abjy abjz abka abkb abkc abkd abke abkf abkg abkh abki +abkj abkk abkl abkm abkn abko abkp abkq abkr abks abkt abku abkv abkw abkx +abky abkz abla ablb ablc abld able ablf ablg ablh abli ablj ablk abll ablm +abln ablo ablp ablq ablr abls ablt ablu ablv ablw ablx ably ablz abma abmb +abmc abmd abme abmf abmg abmh abmi abmj abmk abml abmm abmn abmo abmp abmq +abmr abms abmt abmu abmv abmw abmx abmy abmz abna abnb abnc abnd abne abnf +abng abnh abni abnj abnk abnl abnm abnn abno abnp abnq abnr abns abnt abnu +abnv abnw abnx abny abnz aboa abob aboc abod aboe abof abog aboh aboi aboj +abok abol abom abon aboo abop aboq abor abos abot abou abov abow abox aboy +aboz abpa abpb abpc abpd abpe abpf abpg abph abpi abpj abpk abpl abpm abpn +abpo abpp abpq abpr abps abpt abpu abpv abpw abpx abpy abpz abqa abqb abqc +abqd abqe abqf abqg abqh abqi abqj abqk abql abqm abqn abqo abqp abqq abqr +abqs abqt abqu abqv abqw abqx abqy abqz abra abrb abrc abrd abre abrf abrg +abrh abri abrj abrk abrl abrm abrn abro abrp abrq abrr abrs abrt abru abrv +abrw abrx abry abrz absa absb absc absd abse absf absg absh absi absj absk +absl absm absn abso absp absq absr abss abst absu absv absw absx absy absz +abta abtb abtc abtd abte abtf abtg abth abti abtj abtk abtl abtm abtn abto +abtp abtq abtr abts abtt abtu abtv abtw abtx abty abtz abua abub abuc abud +abue abuf abug abuh abui abuj abuk abul abum abun abuo abup abuq abur abus +abut abuu abuv abuw abux abuy abuz abva abvb abvc abvd abve abvf abvg abvh +abvi abvj abvk abvl abvm abvn abvo abvp abvq abvr abvs abvt abvu abvv abvw +abvx abvy abvz abwa abwb abwc abwd abwe abwf abwg abwh abwi abwj abwk abwl +abwm abwn abwo abwp abwq abwr abws abwt abwu abwv abww abwx abwy abwz abxa +abxb abxc abxd abxe abxf abxg abxh abxi abxj abxk abxl abxm abxn abxo abxp +abxq abxr abxs abxt abxu abxv abxw abxx abxy abxz abya abyb abyc abyd abye +abyf abyg abyh abyi abyj abyk abyl abym abyn abyo abyp abyq abyr abys abyt +abyu abyv abyw abyx abyy abyz abza abzb abzc abzd abze abzf abzg abzh abzi +abzj abzk abzl abzm abzn abzo abzp abzq abzr abzs abzt abzu abzv abzw abzx +abzy abzz acaa acab acac acad acae acaf acag acah acai acaj acak acal acam +acan acao acap acaq acar acas acat acau acav acaw acax acay acaz acba acbb +acbc acbd acbe acbf acbg acbh acbi acbj acbk acbl acbm acbn acbo acbp acbq +acbr acbs acbt acbu acbv acbw acbx acby acbz acca accb accc accd acce accf +accg acch acci accj acck accl accm accn acco accp accq accr accs acct accu +accv accw accx accy accz acda acdb acdc acdd acde acdf acdg acdh acdi acdj +acdk acdl acdm acdn acdo acdp acdq acdr acds acdt acdu acdv acdw acdx acdy +acdz acea aceb acec aced acee acef aceg aceh acei acej acek acel acem acen +aceo acep aceq acer aces acet aceu acev acew acex acey acez acfa acfb acfc +acfd acfe acff acfg acfh acfi acfj acfk acfl acfm acfn acfo acfp acfq acfr +acfs acft acfu acfv acfw acfx acfy acfz acga acgb acgc acgd acge acgf acgg +acgh acgi acgj acgk acgl acgm acgn acgo acgp acgq acgr acgs acgt acgu acgv +acgw acgx acgy acgz acha achb achc achd ache achf achg achh achi achj achk +achl achm achn acho achp achq achr achs acht achu achv achw achx achy achz +acia acib acic acid acie acif acig acih acii acij acik acil acim acin acio +acip aciq acir acis acit aciu aciv aciw acix aciy aciz acja acjb acjc acjd +acje acjf acjg acjh acji acjj acjk acjl acjm acjn acjo acjp acjq acjr acjs +acjt acju acjv acjw acjx acjy acjz acka ackb ackc ackd acke ackf ackg ackh +acki ackj ackk ackl ackm ackn acko ackp ackq ackr acks ackt acku ackv ackw +ackx acky ackz acla aclb aclc acld acle aclf aclg aclh acli aclj aclk acll +aclm acln aclo aclp aclq aclr acls aclt aclu aclv aclw aclx acly aclz acma +acmb acmc acmd acme acmf acmg acmh acmi acmj acmk acml acmm acmn acmo acmp +acmq acmr acms acmt acmu acmv acmw acmx acmy acmz acna acnb acnc acnd acne +acnf acng acnh acni acnj acnk acnl acnm acnn acno acnp acnq acnr acns acnt +acnu acnv acnw acnx acny acnz acoa acob acoc acod acoe acof acog acoh acoi +acoj acok acol acom acon acoo acop acoq acor acos acot acou acov acow acox +acoy acoz acpa acpb acpc acpd acpe acpf acpg acph acpi acpj acpk acpl acpm +acpn acpo acpp acpq acpr acps acpt acpu acpv acpw acpx acpy acpz acqa acqb +acqc acqd acqe acqf acqg acqh acqi acqj acqk acql acqm acqn acqo acqp acqq +acqr acqs acqt acqu acqv acqw acqx acqy acqz acra acrb acrc acrd acre acrf +acrg acrh acri acrj acrk acrl acrm acrn acro acrp acrq acrr acrs acrt acru +acrv acrw acrx acry acrz acsa acsb acsc acsd acse acsf acsg acsh acsi acsj +acsk acsl acsm acsn acso acsp acsq acsr acss acst acsu acsv acsw acsx acsy +acsz acta actb actc actd acte actf actg acth acti actj actk actl actm actn +acto actp actq actr acts actt actu actv actw actx acty actz acua acub acuc +acud acue acuf acug acuh acui acuj acuk acul acum acun acuo acup acuq acur +acus acut acuu acuv acuw acux acuy acuz acva acvb acvc acvd acve acvf acvg +acvh acvi acvj acvk acvl acvm acvn acvo acvp acvq acvr acvs acvt acvu acvv +acvw acvx acvy acvz acwa acwb acwc acwd acwe acwf acwg acwh acwi acwj acwk +acwl acwm acwn acwo acwp acwq acwr acws acwt acwu acwv acww acwx acwy acwz +acxa acxb acxc acxd acxe acxf acxg acxh acxi acxj acxk acxl acxm acxn acxo +acxp acxq acxr acxs acxt acxu acxv acxw acxx acxy acxz acya acyb acyc acyd +acye acyf acyg acyh acyi acyj acyk acyl acym acyn acyo acyp acyq acyr acys +acyt acyu acyv acyw acyx acyy acyz acza aczb aczc aczd acze aczf aczg aczh +aczi aczj aczk aczl aczm aczn aczo aczp aczq aczr aczs aczt aczu aczv aczw +aczx aczy aczz adaa adab adac adad adae adaf adag adah adai adaj adak adal +adam adan adao adap adaq adar adas adat adau adav adaw adax aday adaz adba +adbb adbc adbd adbe adbf adbg adbh adbi adbj adbk adbl adbm adbn adbo adbp +adbq adbr adbs adbt adbu adbv adbw adbx adby adbz adca adcb adcc adcd adce +adcf adcg adch adci adcj adck adcl adcm adcn adco adcp adcq adcr adcs adct +adcu adcv adcw adcx adcy adcz adda addb addc addd adde addf addg addh addi +addj addk addl addm addn addo addp addq addr adds addt addu addv addw addx +addy addz adea adeb adec aded adee adef adeg adeh adei adej adek adel adem +aden adeo adep adeq ader ades adet adeu adev adew adex adey adez adfa adfb +adfc adfd adfe adff adfg adfh adfi adfj adfk adfl adfm adfn adfo adfp adfq +adfr adfs adft adfu adfv adfw adfx adfy adfz adga adgb adgc adgd adge adgf +adgg adgh adgi adgj adgk adgl adgm adgn adgo adgp adgq adgr adgs adgt adgu +adgv adgw adgx adgy adgz adha adhb adhc adhd adhe adhf adhg adhh adhi adhj +adhk adhl adhm adhn adho adhp adhq adhr adhs adht adhu adhv adhw adhx adhy +adhz adia adib adic adid adie adif adig adih adii adij adik adil adim adin +adio adip adiq adir adis adit adiu adiv adiw adix adiy adiz adja adjb adjc +adjd adje adjf adjg adjh adji adjj adjk adjl adjm adjn adjo adjp adjq adjr +adjs adjt adju adjv adjw adjx adjy adjz adka adkb adkc adkd adke adkf adkg +adkh adki adkj adkk adkl adkm adkn adko adkp adkq adkr adks adkt adku adkv +adkw adkx adky adkz adla adlb adlc adld adle adlf adlg adlh adli adlj adlk +adll adlm adln adlo adlp adlq adlr adls adlt adlu adlv adlw adlx adly adlz +adma admb admc admd adme admf admg admh admi admj admk adml admm admn admo +admp admq admr adms admt admu admv admw admx admy admz adna adnb adnc adnd +adne adnf adng adnh adni adnj adnk adnl adnm adnn adno adnp adnq adnr adns +adnt adnu adnv adnw adnx adny adnz adoa adob adoc adod adoe adof adog adoh +adoi adoj adok adol adom adon adoo adop adoq ador ados adot adou adov adow +adox adoy adoz adpa adpb adpc adpd adpe adpf adpg adph adpi adpj adpk adpl +adpm adpn adpo adpp adpq adpr adps adpt adpu adpv adpw adpx adpy adpz adqa +adqb adqc adqd adqe adqf adqg adqh adqi adqj adqk adql adqm adqn adqo adqp +adqq adqr adqs adqt adqu adqv adqw adqx adqy adqz adra adrb adrc adrd adre +adrf adrg adrh adri adrj adrk adrl adrm adrn adro adrp adrq adrr adrs adrt +adru adrv adrw adrx adry adrz adsa adsb adsc adsd adse adsf adsg adsh adsi +adsj adsk adsl adsm adsn adso adsp adsq adsr adss adst adsu adsv adsw adsx +adsy adsz adta adtb adtc adtd adte adtf adtg adth adti adtj adtk adtl adtm +adtn adto adtp adtq adtr adts adtt adtu adtv adtw adtx adty adtz adua adub +aduc adud adue aduf adug aduh adui aduj aduk adul adum adun aduo adup aduq +adur adus adut aduu aduv aduw adux aduy aduz adva advb advc advd adve advf +advg advh advi advj advk advl advm advn advo advp advq advr advs advt advu +advv advw advx advy advz adwa adwb adwc adwd adwe adwf adwg adwh adwi adwj +adwk adwl adwm adwn adwo adwp adwq adwr adws adwt adwu adwv adww adwx adwy +adwz adxa adxb adxc adxd adxe adxf adxg adxh adxi adxj adxk adxl adxm adxn +adxo adxp adxq adxr adxs adxt adxu adxv adxw adxx adxy adxz adya adyb adyc +adyd adye adyf adyg adyh adyi adyj adyk adyl adym adyn adyo adyp adyq adyr +adys adyt adyu adyv adyw adyx adyy adyz adza adzb adzc adzd adze adzf adzg +adzh adzi adzj adzk adzl adzm adzn adzo adzp adzq adzr adzs adzt adzu adzv +adzw adzx adzy adzz aeaa aeab aeac aead aeae aeaf aeag aeah aeai aeaj aeak +aeal aeam aean aeao aeap aeaq aear aeas aeat aeau aeav aeaw aeax aeay aeaz +aeba aebb aebc aebd aebe aebf aebg aebh aebi aebj aebk aebl aebm aebn aebo +aebp aebq aebr aebs aebt aebu aebv aebw aebx aeby aebz aeca aecb aecc aecd +aece aecf aecg aech aeci aecj aeck aecl aecm aecn aeco aecp aecq aecr aecs +aect aecu aecv aecw aecx aecy aecz aeda aedb aedc aedd aede aedf aedg aedh +aedi aedj aedk aedl aedm aedn aedo aedp aedq aedr aeds aedt aedu aedv aedw +aedx aedy aedz aeea aeeb aeec aeed aeee aeef aeeg aeeh aeei aeej aeek aeel +aeem aeen aeeo aeep aeeq aeer aees aeet aeeu aeev aeew aeex aeey aeez aefa +aefb aefc aefd aefe aeff aefg aefh aefi aefj aefk aefl aefm aefn aefo aefp +aefq aefr aefs aeft aefu aefv aefw aefx aefy aefz aega aegb aegc aegd aege +aegf aegg aegh aegi aegj aegk aegl aegm aegn aego aegp aegq aegr aegs aegt +aegu aegv aegw aegx aegy aegz aeha aehb aehc aehd aehe aehf aehg aehh aehi +aehj aehk aehl aehm aehn aeho aehp aehq aehr aehs aeht aehu aehv aehw aehx +aehy aehz aeia aeib aeic aeid aeie aeif aeig aeih aeii aeij aeik aeil aeim +aein aeio aeip aeiq aeir aeis aeit aeiu aeiv aeiw aeix aeiy aeiz aeja aejb +aejc aejd aeje aejf aejg aejh aeji aejj aejk aejl aejm aejn aejo aejp aejq +aejr aejs aejt aeju aejv aejw aejx aejy aejz aeka aekb aekc aekd aeke aekf +aekg aekh aeki aekj aekk aekl aekm aekn aeko aekp aekq aekr aeks aekt aeku +aekv aekw aekx aeky aekz aela aelb aelc aeld aele aelf aelg aelh aeli aelj +aelk aell aelm aeln aelo aelp aelq aelr aels aelt aelu aelv aelw aelx aely +aelz aema aemb aemc aemd aeme aemf aemg aemh aemi aemj aemk aeml aemm aemn +aemo aemp aemq aemr aems aemt aemu aemv aemw aemx aemy aemz aena aenb aenc +aend aene aenf aeng aenh aeni aenj aenk aenl aenm aenn aeno aenp aenq aenr +aens aent aenu aenv aenw aenx aeny aenz aeoa aeob aeoc aeod aeoe aeof aeog +aeoh aeoi aeoj aeok aeol aeom aeon aeoo aeop aeoq aeor aeos aeot aeou aeov +aeow aeox aeoy aeoz aepa aepb aepc aepd aepe aepf aepg aeph aepi aepj aepk +aepl aepm aepn aepo aepp aepq aepr aeps aept aepu aepv aepw aepx aepy aepz +aeqa aeqb aeqc aeqd aeqe aeqf aeqg aeqh aeqi aeqj aeqk aeql aeqm aeqn aeqo +aeqp aeqq aeqr aeqs aeqt aequ aeqv aeqw aeqx aeqy aeqz aera aerb aerc aerd +aere aerf aerg aerh aeri aerj aerk aerl aerm aern aero aerp aerq aerr aers +aert aeru aerv aerw aerx aery aerz aesa aesb aesc aesd aese aesf aesg aesh +aesi aesj aesk aesl aesm aesn aeso aesp aesq aesr aess aest aesu aesv aesw +aesx aesy aesz aeta aetb aetc aetd aete aetf aetg aeth aeti aetj aetk aetl +aetm aetn aeto aetp aetq aetr aets aett aetu aetv aetw aetx aety aetz aeua +aeub aeuc aeud aeue aeuf aeug aeuh aeui aeuj aeuk aeul aeum aeun aeuo aeup +aeuq aeur aeus aeut aeuu aeuv aeuw aeux aeuy aeuz aeva aevb aevc aevd aeve +aevf aevg aevh aevi aevj aevk aevl aevm aevn aevo aevp aevq aevr aevs aevt +aevu aevv aevw aevx aevy aevz aewa aewb aewc aewd aewe aewf aewg aewh aewi +aewj aewk aewl aewm aewn aewo aewp aewq aewr aews aewt aewu aewv aeww aewx +aewy aewz aexa aexb aexc aexd aexe aexf aexg aexh aexi aexj aexk aexl aexm +aexn aexo aexp aexq aexr aexs aext aexu aexv aexw aexx aexy aexz aeya aeyb +aeyc aeyd aeye aeyf aeyg aeyh aeyi aeyj aeyk aeyl aeym aeyn aeyo aeyp aeyq +aeyr aeys aeyt aeyu aeyv aeyw aeyx aeyy aeyz aeza aezb aezc aezd aeze aezf +aezg aezh aezi aezj aezk aezl aezm aezn aezo aezp aezq aezr aezs aezt aezu +aezv aezw aezx aezy aezz afaa afab afac afad afae afaf afag afah afai afaj +afak afal afam afan afao afap afaq afar afas afat afau afav afaw afax afay +afaz afba afbb afbc afbd afbe afbf afbg afbh afbi afbj afbk afbl afbm afbn +afbo afbp afbq afbr afbs afbt afbu afbv afbw afbx afby afbz afca afcb afcc +afcd afce afcf afcg afch afci afcj afck afcl afcm afcn afco afcp afcq afcr +afcs afct afcu afcv afcw afcx afcy afcz afda afdb afdc afdd afde afdf afdg +afdh afdi afdj afdk afdl afdm afdn afdo afdp afdq afdr afds afdt afdu afdv +afdw afdx afdy afdz afea afeb afec afed afee afef afeg afeh afei afej afek +afel afem afen afeo afep afeq afer afes afet afeu afev afew afex afey afez +affa affb affc affd affe afff affg affh affi affj affk affl affm affn affo +affp affq affr affs afft affu affv affw affx affy affz afga afgb afgc afgd +afge afgf afgg afgh afgi afgj afgk afgl afgm afgn afgo afgp afgq afgr afgs +afgt afgu afgv afgw afgx afgy afgz afha afhb afhc afhd afhe afhf afhg afhh +afhi afhj afhk afhl afhm afhn afho afhp afhq afhr afhs afht afhu afhv afhw +afhx afhy afhz afia afib afic afid afie afif afig afih afii afij afik afil +afim afin afio afip afiq afir afis afit afiu afiv afiw afix afiy afiz afja +afjb afjc afjd afje afjf afjg afjh afji afjj afjk afjl afjm afjn afjo afjp +afjq afjr afjs afjt afju afjv afjw afjx afjy afjz afka afkb afkc afkd afke +afkf afkg afkh afki afkj afkk afkl afkm afkn afko afkp afkq afkr afks afkt +afku afkv afkw afkx afky afkz afla aflb aflc afld afle aflf aflg aflh afli +aflj aflk afll aflm afln aflo aflp aflq aflr afls aflt aflu aflv aflw aflx +afly aflz afma afmb afmc afmd afme afmf afmg afmh afmi afmj afmk afml afmm +afmn afmo afmp afmq afmr afms afmt afmu afmv afmw afmx afmy afmz afna afnb +afnc afnd afne afnf afng afnh afni afnj afnk afnl afnm afnn afno afnp afnq +afnr afns afnt afnu afnv afnw afnx afny afnz afoa afob afoc afod afoe afof +afog afoh afoi afoj afok afol afom afon afoo afop afoq afor afos afot afou +afov afow afox afoy afoz afpa afpb afpc afpd afpe afpf afpg afph afpi afpj +afpk afpl afpm afpn afpo afpp afpq afpr afps afpt afpu afpv afpw afpx afpy +afpz afqa afqb afqc afqd afqe afqf afqg afqh afqi afqj afqk afql afqm afqn +afqo afqp afqq afqr afqs afqt afqu afqv afqw afqx afqy afqz afra afrb afrc +afrd afre afrf afrg afrh afri afrj afrk afrl afrm afrn afro afrp afrq afrr +afrs afrt afru afrv afrw afrx afry afrz afsa afsb afsc afsd afse afsf afsg +afsh afsi afsj afsk afsl afsm afsn afso afsp afsq afsr afss afst afsu afsv +afsw afsx afsy afsz afta aftb aftc aftd afte aftf aftg afth afti aftj aftk +aftl aftm aftn afto aftp aftq aftr afts aftt aftu aftv aftw aftx afty aftz +afua afub afuc afud afue afuf afug afuh afui afuj afuk aful afum afun afuo +afup afuq afur afus afut afuu afuv afuw afux afuy afuz afva afvb afvc afvd +afve afvf afvg afvh afvi afvj afvk afvl afvm afvn afvo afvp afvq afvr afvs +afvt afvu afvv afvw afvx afvy afvz afwa afwb afwc afwd afwe afwf afwg afwh +afwi afwj afwk afwl afwm afwn afwo afwp afwq afwr afws afwt afwu afwv afww +afwx afwy afwz afxa afxb afxc afxd afxe afxf afxg afxh afxi afxj afxk afxl +afxm afxn afxo afxp afxq afxr afxs afxt afxu afxv afxw afxx afxy afxz afya +afyb afyc afyd afye afyf afyg afyh afyi afyj afyk afyl afym afyn afyo afyp +afyq afyr afys afyt afyu afyv afyw afyx afyy afyz afza afzb afzc afzd afze +afzf afzg afzh afzi afzj afzk afzl afzm afzn afzo afzp afzq afzr afzs afzt +afzu afzv afzw afzx afzy afzz agaa agab agac agad agae agaf agag agah agai +agaj agak agal agam agan agao agap agaq agar agas agat agau agav agaw agax +agay agaz agba agbb agbc agbd agbe agbf agbg agbh agbi agbj agbk agbl agbm +agbn agbo agbp agbq agbr agbs agbt agbu agbv agbw agbx agby agbz agca agcb +agcc agcd agce agcf agcg agch agci agcj agck agcl agcm agcn agco agcp agcq +agcr agcs agct agcu agcv agcw agcx agcy agcz agda agdb agdc agdd agde agdf +agdg agdh agdi agdj agdk agdl agdm agdn agdo agdp agdq agdr agds agdt agdu +agdv agdw agdx agdy agdz agea ageb agec aged agee agef ageg ageh agei agej +agek agel agem agen ageo agep ageq ager ages aget ageu agev agew agex agey +agez agfa agfb agfc agfd agfe agff agfg agfh agfi agfj agfk agfl agfm agfn +agfo agfp agfq agfr agfs agft agfu agfv agfw agfx agfy agfz agga aggb aggc +aggd agge aggf aggg aggh aggi aggj aggk aggl aggm aggn aggo aggp aggq aggr +aggs aggt aggu aggv aggw aggx aggy aggz agha aghb aghc aghd aghe aghf aghg +aghh aghi aghj aghk aghl aghm aghn agho aghp aghq aghr aghs aght aghu aghv +aghw aghx aghy aghz agia agib agic agid agie agif agig agih agii agij agik +agil agim agin agio agip agiq agir agis agit agiu agiv agiw agix agiy agiz +agja agjb agjc agjd agje agjf agjg agjh agji agjj agjk agjl agjm agjn agjo +agjp agjq agjr agjs agjt agju agjv agjw agjx agjy agjz agka agkb agkc agkd +agke agkf agkg agkh agki agkj agkk agkl agkm agkn agko agkp agkq agkr agks +agkt agku agkv agkw agkx agky agkz agla aglb aglc agld agle aglf aglg aglh +agli aglj aglk agll aglm agln aglo aglp aglq aglr agls aglt aglu aglv aglw +aglx agly aglz agma agmb agmc agmd agme agmf agmg agmh agmi agmj agmk agml +agmm agmn agmo agmp agmq agmr agms agmt agmu agmv agmw agmx agmy agmz agna +agnb agnc agnd agne agnf agng agnh agni agnj agnk agnl agnm agnn agno agnp +agnq agnr agns agnt agnu agnv agnw agnx agny agnz agoa agob agoc agod agoe +agof agog agoh agoi agoj agok agol agom agon agoo agop agoq agor agos agot +agou agov agow agox agoy agoz agpa agpb agpc agpd agpe agpf agpg agph agpi +agpj agpk agpl agpm agpn agpo agpp agpq agpr agps agpt agpu agpv agpw agpx +agpy agpz agqa agqb agqc agqd agqe agqf agqg agqh agqi agqj agqk agql agqm +agqn agqo agqp agqq agqr agqs agqt agqu agqv agqw agqx agqy agqz agra agrb +agrc agrd agre agrf agrg agrh agri agrj agrk agrl agrm agrn agro agrp agrq +agrr agrs agrt agru agrv agrw agrx agry agrz agsa agsb agsc agsd agse agsf +agsg agsh agsi agsj agsk agsl agsm agsn agso agsp agsq agsr agss agst agsu +agsv agsw agsx agsy agsz agta agtb agtc agtd agte agtf agtg agth agti agtj +agtk agtl agtm agtn agto agtp agtq agtr agts agtt agtu agtv agtw agtx agty +agtz agua agub aguc agud ague aguf agug aguh agui aguj aguk agul agum agun +aguo agup aguq agur agus agut aguu aguv aguw agux aguy aguz agva agvb agvc +agvd agve agvf agvg agvh agvi agvj agvk agvl agvm agvn agvo agvp agvq agvr +agvs agvt agvu agvv agvw agvx agvy agvz agwa agwb agwc agwd agwe agwf agwg +agwh agwi agwj agwk agwl agwm agwn agwo agwp agwq agwr agws agwt agwu agwv +agww agwx agwy agwz agxa agxb agxc agxd agxe agxf agxg agxh agxi agxj agxk +agxl agxm agxn agxo agxp agxq agxr agxs agxt agxu agxv agxw agxx agxy agxz +agya agyb agyc agyd agye agyf agyg agyh agyi agyj agyk agyl agym agyn agyo +agyp agyq agyr agys agyt agyu agyv agyw agyx agyy agyz agza agzb agzc agzd +agze agzf agzg agzh agzi agzj agzk agzl agzm agzn agzo agzp agzq agzr agzs +agzt agzu agzv agzw agzx agzy agzz ahaa ahab ahac ahad ahae ahaf ahag ahah +ahai ahaj ahak ahal aham ahan ahao ahap ahaq ahar ahas ahat ahau ahav ahaw +ahax ahay ahaz ahba ahbb ahbc ahbd ahbe ahbf ahbg ahbh ahbi ahbj ahbk ahbl +ahbm ahbn ahbo ahbp ahbq ahbr ahbs ahbt ahbu ahbv ahbw ahbx ahby ahbz ahca +ahcb ahcc ahcd ahce ahcf ahcg ahch ahci ahcj ahck ahcl ahcm ahcn ahco ahcp +ahcq ahcr ahcs ahct ahcu ahcv ahcw ahcx ahcy ahcz ahda ahdb ahdc ahdd ahde +ahdf ahdg ahdh ahdi ahdj ahdk ahdl ahdm ahdn ahdo ahdp ahdq ahdr ahds ahdt +ahdu ahdv ahdw ahdx ahdy ahdz ahea aheb ahec ahed ahee ahef aheg aheh ahei +ahej ahek ahel ahem ahen aheo ahep aheq aher ahes ahet aheu ahev ahew ahex +ahey ahez ahfa ahfb ahfc ahfd ahfe ahff ahfg ahfh ahfi ahfj ahfk ahfl ahfm +ahfn ahfo ahfp ahfq ahfr ahfs ahft ahfu ahfv ahfw ahfx ahfy ahfz ahga ahgb +ahgc ahgd ahge ahgf ahgg ahgh ahgi ahgj ahgk ahgl ahgm ahgn ahgo ahgp ahgq +ahgr ahgs ahgt ahgu ahgv ahgw ahgx ahgy ahgz ahha ahhb ahhc ahhd ahhe ahhf +ahhg ahhh ahhi ahhj ahhk ahhl ahhm ahhn ahho ahhp ahhq ahhr ahhs ahht ahhu +ahhv ahhw ahhx ahhy ahhz ahia ahib ahic ahid ahie ahif ahig ahih ahii ahij +ahik ahil ahim ahin ahio ahip ahiq ahir ahis ahit ahiu ahiv ahiw ahix ahiy +ahiz ahja ahjb ahjc ahjd ahje ahjf ahjg ahjh ahji ahjj ahjk ahjl ahjm ahjn +ahjo ahjp ahjq ahjr ahjs ahjt ahju ahjv ahjw ahjx ahjy ahjz ahka ahkb ahkc +ahkd ahke ahkf ahkg ahkh ahki ahkj ahkk ahkl ahkm ahkn ahko ahkp ahkq ahkr +ahks ahkt ahku ahkv ahkw ahkx ahky ahkz ahla ahlb ahlc ahld ahle ahlf ahlg +ahlh ahli ahlj ahlk ahll ahlm ahln ahlo ahlp ahlq ahlr ahls ahlt ahlu ahlv +ahlw ahlx ahly ahlz ahma ahmb ahmc ahmd ahme ahmf ahmg ahmh ahmi ahmj ahmk +ahml ahmm ahmn ahmo ahmp ahmq ahmr ahms ahmt ahmu ahmv ahmw ahmx ahmy ahmz +ahna ahnb ahnc ahnd ahne ahnf ahng ahnh ahni ahnj ahnk ahnl ahnm ahnn ahno +ahnp ahnq ahnr ahns ahnt ahnu ahnv ahnw ahnx ahny ahnz ahoa ahob ahoc ahod +ahoe ahof ahog ahoh ahoi ahoj ahok ahol ahom ahon ahoo ahop ahoq ahor ahos +ahot ahou ahov ahow ahox ahoy ahoz ahpa ahpb ahpc ahpd ahpe ahpf ahpg ahph +ahpi ahpj ahpk ahpl ahpm ahpn ahpo ahpp ahpq ahpr ahps ahpt ahpu ahpv ahpw +ahpx ahpy ahpz ahqa ahqb ahqc ahqd ahqe ahqf ahqg ahqh ahqi ahqj ahqk ahql +ahqm ahqn ahqo ahqp ahqq ahqr ahqs ahqt ahqu ahqv ahqw ahqx ahqy ahqz ahra +ahrb ahrc ahrd ahre ahrf ahrg ahrh ahri ahrj ahrk ahrl ahrm ahrn ahro ahrp +ahrq ahrr ahrs ahrt ahru ahrv ahrw ahrx ahry ahrz ahsa ahsb ahsc ahsd ahse +ahsf ahsg ahsh ahsi ahsj ahsk ahsl ahsm ahsn ahso ahsp ahsq ahsr ahss ahst +ahsu ahsv ahsw ahsx ahsy ahsz ahta ahtb ahtc ahtd ahte ahtf ahtg ahth ahti +ahtj ahtk ahtl ahtm ahtn ahto ahtp ahtq ahtr ahts ahtt ahtu ahtv ahtw ahtx +ahty ahtz ahua ahub ahuc ahud ahue ahuf ahug ahuh ahui ahuj ahuk ahul ahum +ahun ahuo ahup ahuq ahur ahus ahut ahuu ahuv ahuw ahux ahuy ahuz ahva ahvb +ahvc ahvd ahve ahvf ahvg ahvh ahvi ahvj ahvk ahvl ahvm ahvn ahvo ahvp ahvq +ahvr ahvs ahvt ahvu ahvv ahvw ahvx ahvy ahvz ahwa ahwb ahwc ahwd ahwe ahwf +ahwg ahwh ahwi ahwj ahwk ahwl ahwm ahwn ahwo ahwp ahwq ahwr ahws ahwt ahwu +ahwv ahww ahwx ahwy ahwz ahxa ahxb ahxc ahxd ahxe ahxf ahxg ahxh ahxi ahxj +ahxk ahxl ahxm ahxn ahxo ahxp ahxq ahxr ahxs ahxt ahxu ahxv ahxw ahxx ahxy +ahxz ahya ahyb ahyc ahyd ahye ahyf ahyg ahyh ahyi ahyj ahyk ahyl ahym ahyn +ahyo ahyp ahyq ahyr ahys ahyt ahyu ahyv ahyw ahyx ahyy ahyz ahza ahzb ahzc +ahzd ahze ahzf ahzg ahzh ahzi ahzj ahzk ahzl ahzm ahzn ahzo ahzp ahzq ahzr +ahzs ahzt ahzu ahzv ahzw ahzx ahzy ahzz aiaa aiab aiac aiad aiae aiaf aiag +aiah aiai aiaj aiak aial aiam aian aiao aiap aiaq aiar aias aiat aiau aiav +aiaw aiax aiay aiaz aiba aibb aibc aibd aibe aibf aibg aibh aibi aibj aibk +aibl aibm aibn aibo aibp aibq aibr aibs aibt aibu aibv aibw aibx aiby aibz +aica aicb aicc aicd aice aicf aicg aich aici aicj aick aicl aicm aicn aico +aicp aicq aicr aics aict aicu aicv aicw aicx aicy aicz aida aidb aidc aidd +aide aidf aidg aidh aidi aidj aidk aidl aidm aidn aido aidp aidq aidr aids +aidt aidu aidv aidw aidx aidy aidz aiea aieb aiec aied aiee aief aieg aieh +aiei aiej aiek aiel aiem aien aieo aiep aieq aier aies aiet aieu aiev aiew +aiex aiey aiez aifa aifb aifc aifd aife aiff aifg aifh aifi aifj aifk aifl +aifm aifn aifo aifp aifq aifr aifs aift aifu aifv aifw aifx aify aifz aiga +aigb aigc aigd aige aigf aigg aigh aigi aigj aigk aigl aigm aign aigo aigp +aigq aigr aigs aigt aigu aigv aigw aigx aigy aigz aiha aihb aihc aihd aihe +aihf aihg aihh aihi aihj aihk aihl aihm aihn aiho aihp aihq aihr aihs aiht +aihu aihv aihw aihx aihy aihz aiia aiib aiic aiid aiie aiif aiig aiih aiii +aiij aiik aiil aiim aiin aiio aiip aiiq aiir aiis aiit aiiu aiiv aiiw aiix +aiiy aiiz aija aijb aijc aijd aije aijf aijg aijh aiji aijj aijk aijl aijm +aijn aijo aijp aijq aijr aijs aijt aiju aijv aijw aijx aijy aijz aika aikb +aikc aikd aike aikf aikg aikh aiki aikj aikk aikl aikm aikn aiko aikp aikq +aikr aiks aikt aiku aikv aikw aikx aiky aikz aila ailb ailc aild aile ailf +ailg ailh aili ailj ailk aill ailm ailn ailo ailp ailq ailr ails ailt ailu +ailv ailw ailx aily ailz aima aimb aimc aimd aime aimf aimg aimh aimi aimj +aimk aiml aimm aimn aimo aimp aimq aimr aims aimt aimu aimv aimw aimx aimy +aimz aina ainb ainc aind aine ainf aing ainh aini ainj aink ainl ainm ainn +aino ainp ainq ainr ains aint ainu ainv ainw ainx ainy ainz aioa aiob aioc +aiod aioe aiof aiog aioh aioi aioj aiok aiol aiom aion aioo aiop aioq aior +aios aiot aiou aiov aiow aiox aioy aioz aipa aipb aipc aipd aipe aipf aipg +aiph aipi aipj aipk aipl aipm aipn aipo aipp aipq aipr aips aipt aipu aipv +aipw aipx aipy aipz aiqa aiqb aiqc aiqd aiqe aiqf aiqg aiqh aiqi aiqj aiqk +aiql aiqm aiqn aiqo aiqp aiqq aiqr aiqs aiqt aiqu aiqv aiqw aiqx aiqy aiqz +aira airb airc aird aire airf airg airh airi airj airk airl airm airn airo +airp airq airr airs airt airu airv airw airx airy airz aisa aisb aisc aisd +aise aisf aisg aish aisi aisj aisk aisl aism aisn aiso aisp aisq aisr aiss +aist aisu aisv aisw aisx aisy aisz aita aitb aitc aitd aite aitf aitg aith +aiti aitj aitk aitl aitm aitn aito aitp aitq aitr aits aitt aitu aitv aitw +aitx aity aitz aiua aiub aiuc aiud aiue aiuf aiug aiuh aiui aiuj aiuk aiul +aium aiun aiuo aiup aiuq aiur aius aiut aiuu aiuv aiuw aiux aiuy aiuz aiva +aivb aivc aivd aive aivf aivg aivh aivi aivj aivk aivl aivm aivn aivo aivp +aivq aivr aivs aivt aivu aivv aivw aivx aivy aivz aiwa aiwb aiwc aiwd aiwe +aiwf aiwg aiwh aiwi aiwj aiwk aiwl aiwm aiwn aiwo aiwp aiwq aiwr aiws aiwt +aiwu aiwv aiww aiwx aiwy aiwz aixa aixb aixc aixd aixe aixf aixg aixh aixi +aixj aixk aixl aixm aixn aixo aixp aixq aixr aixs aixt aixu aixv aixw aixx +aixy aixz aiya aiyb aiyc aiyd aiye aiyf aiyg aiyh aiyi aiyj aiyk aiyl aiym +aiyn aiyo aiyp aiyq aiyr aiys aiyt aiyu aiyv aiyw aiyx aiyy aiyz aiza aizb +aizc aizd aize aizf aizg aizh aizi aizj aizk aizl aizm aizn aizo aizp aizq +aizr aizs aizt aizu aizv aizw aizx aizy aizz ajaa ajab ajac ajad ajae ajaf +ajag ajah ajai ajaj ajak ajal ajam ajan ajao ajap ajaq ajar ajas ajat ajau +ajav ajaw ajax ajay ajaz ajba ajbb ajbc ajbd ajbe ajbf ajbg ajbh ajbi ajbj +ajbk ajbl ajbm ajbn ajbo ajbp ajbq ajbr ajbs ajbt ajbu ajbv ajbw ajbx ajby +ajbz ajca ajcb ajcc ajcd ajce ajcf ajcg ajch ajci ajcj ajck ajcl ajcm ajcn +ajco ajcp ajcq ajcr ajcs ajct ajcu ajcv ajcw ajcx ajcy ajcz ajda ajdb ajdc +ajdd ajde ajdf ajdg ajdh ajdi ajdj ajdk ajdl ajdm ajdn ajdo ajdp ajdq ajdr +ajds ajdt ajdu ajdv ajdw ajdx ajdy ajdz ajea ajeb ajec ajed ajee ajef ajeg +ajeh ajei ajej ajek ajel ajem ajen ajeo ajep ajeq ajer ajes ajet ajeu ajev +ajew ajex ajey ajez ajfa ajfb ajfc ajfd ajfe ajff ajfg ajfh ajfi ajfj ajfk +ajfl ajfm ajfn ajfo ajfp ajfq ajfr ajfs ajft ajfu ajfv ajfw ajfx ajfy ajfz +ajga ajgb ajgc ajgd ajge ajgf ajgg ajgh ajgi ajgj ajgk ajgl ajgm ajgn ajgo +ajgp ajgq ajgr ajgs ajgt ajgu ajgv ajgw ajgx ajgy ajgz ajha ajhb ajhc ajhd +ajhe ajhf ajhg ajhh ajhi ajhj ajhk ajhl ajhm ajhn ajho ajhp ajhq ajhr ajhs +ajht ajhu ajhv ajhw ajhx ajhy ajhz ajia ajib ajic ajid ajie ajif ajig ajih +ajii ajij ajik ajil ajim ajin ajio ajip ajiq ajir ajis ajit ajiu ajiv ajiw +ajix ajiy ajiz ajja ajjb ajjc ajjd ajje ajjf ajjg ajjh ajji ajjj ajjk ajjl +ajjm ajjn ajjo ajjp ajjq ajjr ajjs ajjt ajju ajjv ajjw ajjx ajjy ajjz ajka +ajkb ajkc ajkd ajke ajkf ajkg ajkh ajki ajkj ajkk ajkl ajkm ajkn ajko ajkp +ajkq ajkr ajks ajkt ajku ajkv ajkw ajkx ajky ajkz ajla ajlb ajlc ajld ajle +ajlf ajlg ajlh ajli ajlj ajlk ajll ajlm ajln ajlo ajlp ajlq ajlr ajls ajlt +ajlu ajlv ajlw ajlx ajly ajlz ajma ajmb ajmc ajmd ajme ajmf ajmg ajmh ajmi +ajmj ajmk ajml ajmm ajmn ajmo ajmp ajmq ajmr ajms ajmt ajmu ajmv ajmw ajmx +ajmy ajmz ajna ajnb ajnc ajnd ajne ajnf ajng ajnh ajni ajnj ajnk ajnl ajnm +ajnn ajno ajnp ajnq ajnr ajns ajnt ajnu ajnv ajnw ajnx ajny ajnz ajoa ajob +ajoc ajod ajoe ajof ajog ajoh ajoi ajoj ajok ajol ajom ajon ajoo ajop ajoq +ajor ajos ajot ajou ajov ajow ajox ajoy ajoz ajpa ajpb ajpc ajpd ajpe ajpf +ajpg ajph ajpi ajpj ajpk ajpl ajpm ajpn ajpo ajpp ajpq ajpr ajps ajpt ajpu +ajpv ajpw ajpx ajpy ajpz ajqa ajqb ajqc ajqd ajqe ajqf ajqg ajqh ajqi ajqj +ajqk ajql ajqm ajqn ajqo ajqp ajqq ajqr ajqs ajqt ajqu ajqv ajqw ajqx ajqy +ajqz ajra ajrb ajrc ajrd ajre ajrf ajrg ajrh ajri ajrj ajrk ajrl ajrm ajrn +ajro ajrp ajrq ajrr ajrs ajrt ajru ajrv ajrw ajrx ajry ajrz ajsa ajsb ajsc +ajsd ajse ajsf ajsg ajsh ajsi ajsj ajsk ajsl ajsm ajsn ajso ajsp ajsq ajsr +ajss ajst ajsu ajsv ajsw ajsx ajsy ajsz ajta ajtb ajtc ajtd ajte ajtf ajtg +ajth ajti ajtj ajtk ajtl ajtm ajtn ajto ajtp ajtq ajtr ajts ajtt ajtu ajtv +ajtw ajtx ajty ajtz ajua ajub ajuc ajud ajue ajuf ajug ajuh ajui ajuj ajuk +ajul ajum ajun ajuo ajup ajuq ajur ajus ajut ajuu ajuv ajuw ajux ajuy ajuz +ajva ajvb ajvc ajvd ajve ajvf ajvg ajvh ajvi ajvj ajvk ajvl ajvm ajvn ajvo +ajvp ajvq ajvr ajvs ajvt ajvu ajvv ajvw ajvx ajvy ajvz ajwa ajwb ajwc ajwd +ajwe ajwf ajwg ajwh ajwi ajwj ajwk ajwl ajwm ajwn ajwo ajwp ajwq ajwr ajws +ajwt ajwu ajwv ajww ajwx ajwy ajwz ajxa ajxb ajxc ajxd ajxe ajxf ajxg ajxh +ajxi ajxj ajxk ajxl ajxm ajxn ajxo ajxp ajxq ajxr ajxs ajxt ajxu ajxv ajxw +ajxx ajxy ajxz ajya ajyb ajyc ajyd ajye ajyf ajyg ajyh ajyi ajyj ajyk ajyl +ajym ajyn ajyo ajyp ajyq ajyr ajys ajyt ajyu ajyv ajyw ajyx ajyy ajyz ajza +ajzb ajzc ajzd ajze ajzf ajzg ajzh ajzi ajzj ajzk ajzl ajzm ajzn ajzo ajzp +ajzq ajzr ajzs ajzt ajzu ajzv ajzw ajzx ajzy ajzz akaa akab akac akad akae +akaf akag akah akai akaj akak akal akam akan akao akap akaq akar akas akat +akau akav akaw akax akay akaz akba akbb akbc akbd akbe akbf akbg akbh akbi +akbj akbk akbl akbm akbn akbo akbp akbq akbr akbs akbt akbu akbv akbw akbx +akby akbz akca akcb akcc akcd akce akcf akcg akch akci akcj akck akcl akcm +akcn akco akcp akcq akcr akcs akct akcu akcv akcw akcx akcy akcz akda akdb +akdc akdd akde akdf akdg akdh akdi akdj akdk akdl akdm akdn akdo akdp akdq +akdr akds akdt akdu akdv akdw akdx akdy akdz akea akeb akec aked akee akef +akeg akeh akei akej akek akel akem aken akeo akep akeq aker akes aket akeu +akev akew akex akey akez akfa akfb akfc akfd akfe akff akfg akfh akfi akfj +akfk akfl akfm akfn akfo akfp akfq akfr akfs akft akfu akfv akfw akfx akfy +akfz akga akgb akgc akgd akge akgf akgg akgh akgi akgj akgk akgl akgm akgn +akgo akgp akgq akgr akgs akgt akgu akgv akgw akgx akgy akgz akha akhb akhc +akhd akhe akhf akhg akhh akhi akhj akhk akhl akhm akhn akho akhp akhq akhr +akhs akht akhu akhv akhw akhx akhy akhz akia akib akic akid akie akif akig +akih akii akij akik akil akim akin akio akip akiq akir akis akit akiu akiv +akiw akix akiy akiz akja akjb akjc akjd akje akjf akjg akjh akji akjj akjk +akjl akjm akjn akjo akjp akjq akjr akjs akjt akju akjv akjw akjx akjy akjz +akka akkb akkc akkd akke akkf akkg akkh akki akkj akkk akkl akkm akkn akko +akkp akkq akkr akks akkt akku akkv akkw akkx akky akkz akla aklb aklc akld +akle aklf aklg aklh akli aklj aklk akll aklm akln aklo aklp aklq aklr akls +aklt aklu aklv aklw aklx akly aklz akma akmb akmc akmd akme akmf akmg akmh +akmi akmj akmk akml akmm akmn akmo akmp akmq akmr akms akmt akmu akmv akmw +akmx akmy akmz akna aknb aknc aknd akne aknf akng aknh akni aknj aknk aknl +aknm aknn akno aknp aknq aknr akns aknt aknu aknv aknw aknx akny aknz akoa +akob akoc akod akoe akof akog akoh akoi akoj akok akol akom akon akoo akop +akoq akor akos akot akou akov akow akox akoy akoz akpa akpb akpc akpd akpe +akpf akpg akph akpi akpj akpk akpl akpm akpn akpo akpp akpq akpr akps akpt +akpu akpv akpw akpx akpy akpz akqa akqb akqc akqd akqe akqf akqg akqh akqi +akqj akqk akql akqm akqn akqo akqp akqq akqr akqs akqt akqu akqv akqw akqx +akqy akqz akra akrb akrc akrd akre akrf akrg akrh akri akrj akrk akrl akrm +akrn akro akrp akrq akrr akrs akrt akru akrv akrw akrx akry akrz aksa aksb +aksc aksd akse aksf aksg aksh aksi aksj aksk aksl aksm aksn akso aksp aksq +aksr akss akst aksu aksv aksw aksx aksy aksz akta aktb aktc aktd akte aktf +aktg akth akti aktj aktk aktl aktm aktn akto aktp aktq aktr akts aktt aktu +aktv aktw aktx akty aktz akua akub akuc akud akue akuf akug akuh akui akuj +akuk akul akum akun akuo akup akuq akur akus akut akuu akuv akuw akux akuy +akuz akva akvb akvc akvd akve akvf akvg akvh akvi akvj akvk akvl akvm akvn +akvo akvp akvq akvr akvs akvt akvu akvv akvw akvx akvy akvz akwa akwb akwc +akwd akwe akwf akwg akwh akwi akwj akwk akwl akwm akwn akwo akwp akwq akwr +akws akwt akwu akwv akww akwx akwy akwz akxa akxb akxc akxd akxe akxf akxg +akxh akxi akxj akxk akxl akxm akxn akxo akxp akxq akxr akxs akxt akxu akxv +akxw akxx akxy akxz akya akyb akyc akyd akye akyf akyg akyh akyi akyj akyk +akyl akym akyn akyo akyp akyq akyr akys akyt akyu akyv akyw akyx akyy akyz +akza akzb akzc akzd akze akzf akzg akzh akzi akzj akzk akzl akzm akzn akzo +akzp akzq akzr akzs akzt akzu akzv akzw akzx akzy akzz alaa alab alac alad +alae alaf alag alah alai alaj alak alal alam alan alao alap alaq alar alas +alat alau alav alaw alax alay alaz alba albb albc albd albe albf albg albh +albi albj albk albl albm albn albo albp albq albr albs albt albu albv albw +albx alby albz alca alcb alcc alcd alce alcf alcg alch alci alcj alck alcl +alcm alcn alco alcp alcq alcr alcs alct alcu alcv alcw alcx alcy alcz alda +aldb aldc aldd alde aldf aldg aldh aldi aldj aldk aldl aldm aldn aldo aldp +aldq aldr alds aldt aldu aldv aldw aldx aldy aldz alea aleb alec aled alee +alef aleg aleh alei alej alek alel alem alen aleo alep aleq aler ales alet +aleu alev alew alex aley alez alfa alfb alfc alfd alfe alff alfg alfh alfi +alfj alfk alfl alfm alfn alfo alfp alfq alfr alfs alft alfu alfv alfw alfx +alfy alfz alga algb algc algd alge algf algg algh algi algj algk algl algm +algn algo algp algq algr algs algt algu algv algw algx algy algz alha alhb +alhc alhd alhe alhf alhg alhh alhi alhj alhk alhl alhm alhn alho alhp alhq +alhr alhs alht alhu alhv alhw alhx alhy alhz alia alib alic alid alie alif +alig alih alii alij alik alil alim alin alio alip aliq alir alis alit aliu +aliv aliw alix aliy aliz alja aljb aljc aljd alje aljf aljg aljh alji aljj +aljk aljl aljm aljn aljo aljp aljq aljr aljs aljt alju aljv aljw aljx aljy +aljz alka alkb alkc alkd alke alkf alkg alkh alki alkj alkk alkl alkm alkn +alko alkp alkq alkr alks alkt alku alkv alkw alkx alky alkz alla allb allc +alld alle allf allg allh alli allj allk alll allm alln allo allp allq allr +alls allt allu allv allw allx ally allz alma almb almc almd alme almf almg +almh almi almj almk alml almm almn almo almp almq almr alms almt almu almv +almw almx almy almz alna alnb alnc alnd alne alnf alng alnh alni alnj alnk +alnl alnm alnn alno alnp alnq alnr alns alnt alnu alnv alnw alnx alny alnz +aloa alob aloc alod aloe alof alog aloh aloi aloj alok alol alom alon aloo +alop aloq alor alos alot alou alov alow alox aloy aloz alpa alpb alpc alpd +alpe alpf alpg alph alpi alpj alpk alpl alpm alpn alpo alpp alpq alpr alps +alpt alpu alpv alpw alpx alpy alpz alqa alqb alqc alqd alqe alqf alqg alqh +alqi alqj alqk alql alqm alqn alqo alqp alqq alqr alqs alqt alqu alqv alqw +alqx alqy alqz alra alrb alrc alrd alre alrf alrg alrh alri alrj alrk alrl +alrm alrn alro alrp alrq alrr alrs alrt alru alrv alrw alrx alry alrz alsa +alsb alsc alsd alse alsf alsg alsh alsi alsj alsk alsl alsm alsn also alsp +alsq alsr alss alst alsu alsv alsw alsx alsy alsz alta altb altc altd alte +altf altg alth alti altj altk altl altm altn alto altp altq altr alts altt +altu altv altw altx alty altz alua alub aluc alud alue aluf alug aluh alui +aluj aluk alul alum alun aluo alup aluq alur alus alut aluu aluv aluw alux +aluy aluz alva alvb alvc alvd alve alvf alvg alvh alvi alvj alvk alvl alvm +alvn alvo alvp alvq alvr alvs alvt alvu alvv alvw alvx alvy alvz alwa alwb +alwc alwd alwe alwf alwg alwh alwi alwj alwk alwl alwm alwn alwo alwp alwq +alwr alws alwt alwu alwv alww alwx alwy alwz alxa alxb alxc alxd alxe alxf +alxg alxh alxi alxj alxk alxl alxm alxn alxo alxp alxq alxr alxs alxt alxu +alxv alxw alxx alxy alxz alya alyb alyc alyd alye alyf alyg alyh alyi alyj +alyk alyl alym alyn alyo alyp alyq alyr alys alyt alyu alyv alyw alyx alyy +alyz alza alzb alzc alzd alze alzf alzg alzh alzi alzj alzk alzl alzm alzn +alzo alzp alzq alzr alzs alzt alzu alzv alzw alzx alzy alzz amaa amab amac +amad amae amaf amag amah amai amaj amak amal amam aman amao amap amaq amar +amas amat amau amav amaw amax amay amaz amba ambb ambc ambd ambe ambf ambg +ambh ambi ambj ambk ambl ambm ambn ambo ambp ambq ambr ambs ambt ambu ambv +ambw ambx amby ambz amca amcb amcc amcd amce amcf amcg amch amci amcj amck +amcl amcm amcn amco amcp amcq amcr amcs amct amcu amcv amcw amcx amcy amcz +amda amdb amdc amdd amde amdf amdg amdh amdi amdj amdk amdl amdm amdn amdo +amdp amdq amdr amds amdt amdu amdv amdw amdx amdy amdz amea ameb amec amed +amee amef ameg ameh amei amej amek amel amem amen ameo amep ameq amer ames +amet ameu amev amew amex amey amez amfa amfb amfc amfd amfe amff amfg amfh +amfi amfj amfk amfl amfm amfn amfo amfp amfq amfr amfs amft amfu amfv amfw +amfx amfy amfz amga amgb amgc amgd amge amgf amgg amgh amgi amgj amgk amgl +amgm amgn amgo amgp amgq amgr amgs amgt amgu amgv amgw amgx amgy amgz amha +amhb amhc amhd amhe amhf amhg amhh amhi amhj amhk amhl amhm amhn amho amhp +amhq amhr amhs amht amhu amhv amhw amhx amhy amhz amia amib amic amid amie +amif amig amih amii amij amik amil amim amin amio amip amiq amir amis amit +amiu amiv amiw amix amiy amiz amja amjb amjc amjd amje amjf amjg amjh amji +amjj amjk amjl amjm amjn amjo amjp amjq amjr amjs amjt amju amjv amjw amjx +amjy amjz amka amkb amkc amkd amke amkf amkg amkh amki amkj amkk amkl amkm +amkn amko amkp amkq amkr amks amkt amku amkv amkw amkx amky amkz amla amlb +amlc amld amle amlf amlg amlh amli amlj amlk amll amlm amln amlo amlp amlq +amlr amls amlt amlu amlv amlw amlx amly amlz amma ammb ammc ammd amme ammf +ammg ammh ammi ammj ammk amml ammm ammn ammo ammp ammq ammr amms ammt ammu +ammv ammw ammx ammy ammz amna amnb amnc amnd amne amnf amng amnh amni amnj +amnk amnl amnm amnn amno amnp amnq amnr amns amnt amnu amnv amnw amnx amny +amnz amoa amob amoc amod amoe amof amog amoh amoi amoj amok amol amom amon +amoo amop amoq amor amos amot amou amov amow amox amoy amoz ampa ampb ampc +ampd ampe ampf ampg amph ampi ampj ampk ampl ampm ampn ampo ampp ampq ampr +amps ampt ampu ampv ampw ampx ampy ampz amqa amqb amqc amqd amqe amqf amqg +amqh amqi amqj amqk amql amqm amqn amqo amqp amqq amqr amqs amqt amqu amqv +amqw amqx amqy amqz amra amrb amrc amrd amre amrf amrg amrh amri amrj amrk +amrl amrm amrn amro amrp amrq amrr amrs amrt amru amrv amrw amrx amry amrz +amsa amsb amsc amsd amse amsf amsg amsh amsi amsj amsk amsl amsm amsn amso +amsp amsq amsr amss amst amsu amsv amsw amsx amsy amsz amta amtb amtc amtd +amte amtf amtg amth amti amtj amtk amtl amtm amtn amto amtp amtq amtr amts +amtt amtu amtv amtw amtx amty amtz amua amub amuc amud amue amuf amug amuh +amui amuj amuk amul amum amun amuo amup amuq amur amus amut amuu amuv amuw +amux amuy amuz amva amvb amvc amvd amve amvf amvg amvh amvi amvj amvk amvl +amvm amvn amvo amvp amvq amvr amvs amvt amvu amvv amvw amvx amvy amvz amwa +amwb amwc amwd amwe amwf amwg amwh amwi amwj amwk amwl amwm amwn amwo amwp +amwq amwr amws amwt amwu amwv amww amwx amwy amwz amxa amxb amxc amxd amxe +amxf amxg amxh amxi amxj amxk amxl amxm amxn amxo amxp amxq amxr amxs amxt +amxu amxv amxw amxx amxy amxz amya amyb amyc amyd amye amyf amyg amyh amyi +amyj amyk amyl amym amyn amyo amyp amyq amyr amys amyt amyu amyv amyw amyx +amyy amyz amza amzb amzc amzd amze amzf amzg amzh amzi amzj amzk amzl amzm +amzn amzo amzp amzq amzr amzs amzt amzu amzv amzw amzx amzy amzz anaa anab +anac anad anae anaf anag anah anai anaj anak anal anam anan anao anap anaq +anar anas anat anau anav anaw anax anay anaz anba anbb anbc anbd anbe anbf +anbg anbh anbi anbj anbk anbl anbm anbn anbo anbp anbq anbr anbs anbt anbu +anbv anbw anbx anby anbz anca ancb ancc ancd ance ancf ancg anch anci ancj +anck ancl ancm ancn anco ancp ancq ancr ancs anct ancu ancv ancw ancx ancy +ancz anda andb andc andd ande andf andg andh andi andj andk andl andm andn +ando andp andq andr ands andt andu andv andw andx andy andz anea aneb anec +aned anee anef aneg aneh anei anej anek anel anem anen aneo anep aneq aner +anes anet aneu anev anew anex aney anez anfa anfb anfc anfd anfe anff anfg +anfh anfi anfj anfk anfl anfm anfn anfo anfp anfq anfr anfs anft anfu anfv +anfw anfx anfy anfz anga angb angc angd ange angf angg angh angi angj angk +angl angm angn ango angp angq angr angs angt angu angv angw angx angy angz +anha anhb anhc anhd anhe anhf anhg anhh anhi anhj anhk anhl anhm anhn anho +anhp anhq anhr anhs anht anhu anhv anhw anhx anhy anhz ania anib anic anid +anie anif anig anih anii anij anik anil anim anin anio anip aniq anir anis +anit aniu aniv aniw anix aniy aniz anja anjb anjc anjd anje anjf anjg anjh +anji anjj anjk anjl anjm anjn anjo anjp anjq anjr anjs anjt anju anjv anjw +anjx anjy anjz anka ankb ankc ankd anke ankf ankg ankh anki ankj ankk ankl +ankm ankn anko ankp ankq ankr anks ankt anku ankv ankw ankx anky ankz anla +anlb anlc anld anle anlf anlg anlh anli anlj anlk anll anlm anln anlo anlp +anlq anlr anls anlt anlu anlv anlw anlx anly anlz anma anmb anmc anmd anme +anmf anmg anmh anmi anmj anmk anml anmm anmn anmo anmp anmq anmr anms anmt +anmu anmv anmw anmx anmy anmz anna annb annc annd anne annf anng annh anni +annj annk annl annm annn anno annp annq annr anns annt annu annv annw annx +anny annz anoa anob anoc anod anoe anof anog anoh anoi anoj anok anol anom +anon anoo anop anoq anor anos anot anou anov anow anox anoy anoz anpa anpb +anpc anpd anpe anpf anpg anph anpi anpj anpk anpl anpm anpn anpo anpp anpq +anpr anps anpt anpu anpv anpw anpx anpy anpz anqa anqb anqc anqd anqe anqf +anqg anqh anqi anqj anqk anql anqm anqn anqo anqp anqq anqr anqs anqt anqu +anqv anqw anqx anqy anqz anra anrb anrc anrd anre anrf anrg anrh anri anrj +anrk anrl anrm anrn anro anrp anrq anrr anrs anrt anru anrv anrw anrx anry +anrz ansa ansb ansc ansd anse ansf ansg ansh ansi ansj ansk ansl ansm ansn +anso ansp ansq ansr anss anst ansu ansv answ ansx ansy ansz anta antb antc +antd ante antf antg anth anti antj antk antl antm antn anto antp antq antr +ants antt antu antv antw antx anty antz anua anub anuc anud anue anuf anug +anuh anui anuj anuk anul anum anun anuo anup anuq anur anus anut anuu anuv +anuw anux anuy anuz anva anvb anvc anvd anve anvf anvg anvh anvi anvj anvk +anvl anvm anvn anvo anvp anvq anvr anvs anvt anvu anvv anvw anvx anvy anvz +anwa anwb anwc anwd anwe anwf anwg anwh anwi anwj anwk anwl anwm anwn anwo +anwp anwq anwr anws anwt anwu anwv anww anwx anwy anwz anxa anxb anxc anxd +anxe anxf anxg anxh anxi anxj anxk anxl anxm anxn anxo anxp anxq anxr anxs +anxt anxu anxv anxw anxx anxy anxz anya anyb anyc anyd anye anyf anyg anyh +anyi anyj anyk anyl anym anyn anyo anyp anyq anyr anys anyt anyu anyv anyw +anyx anyy anyz anza anzb anzc anzd anze anzf anzg anzh anzi anzj anzk anzl +anzm anzn anzo anzp anzq anzr anzs anzt anzu anzv anzw anzx anzy anzz aoaa +aoab aoac aoad aoae aoaf aoag aoah aoai aoaj aoak aoal aoam aoan aoao aoap +aoaq aoar aoas aoat aoau aoav aoaw aoax aoay aoaz aoba aobb aobc aobd aobe +aobf aobg aobh aobi aobj aobk aobl aobm aobn aobo aobp aobq aobr aobs aobt +aobu aobv aobw aobx aoby aobz aoca aocb aocc aocd aoce aocf aocg aoch aoci +aocj aock aocl aocm aocn aoco aocp aocq aocr aocs aoct aocu aocv aocw aocx +aocy aocz aoda aodb aodc aodd aode aodf aodg aodh aodi aodj aodk aodl aodm +aodn aodo aodp aodq aodr aods aodt aodu aodv aodw aodx aody aodz aoea aoeb +aoec aoed aoee aoef aoeg aoeh aoei aoej aoek aoel aoem aoen aoeo aoep aoeq +aoer aoes aoet aoeu aoev aoew aoex aoey aoez aofa aofb aofc aofd aofe aoff +aofg aofh aofi aofj aofk aofl aofm aofn aofo aofp aofq aofr aofs aoft aofu +aofv aofw aofx aofy aofz aoga aogb aogc aogd aoge aogf aogg aogh aogi aogj +aogk aogl aogm aogn aogo aogp aogq aogr aogs aogt aogu aogv aogw aogx aogy +aogz aoha aohb aohc aohd aohe aohf aohg aohh aohi aohj aohk aohl aohm aohn +aoho aohp aohq aohr aohs aoht aohu aohv aohw aohx aohy aohz aoia aoib aoic +aoid aoie aoif aoig aoih aoii aoij aoik aoil aoim aoin aoio aoip aoiq aoir +aois aoit aoiu aoiv aoiw aoix aoiy aoiz aoja aojb aojc aojd aoje aojf aojg +aojh aoji aojj aojk aojl aojm aojn aojo aojp aojq aojr aojs aojt aoju aojv +aojw aojx aojy aojz aoka aokb aokc aokd aoke aokf aokg aokh aoki aokj aokk +aokl aokm aokn aoko aokp aokq aokr aoks aokt aoku aokv aokw aokx aoky aokz +aola aolb aolc aold aole aolf aolg aolh aoli aolj aolk aoll aolm aoln aolo +aolp aolq aolr aols aolt aolu aolv aolw aolx aoly aolz aoma aomb aomc aomd +aome aomf aomg aomh aomi aomj aomk aoml aomm aomn aomo aomp aomq aomr aoms +aomt aomu aomv aomw aomx aomy aomz aona aonb aonc aond aone aonf aong aonh +aoni aonj aonk aonl aonm aonn aono aonp aonq aonr aons aont aonu aonv aonw +aonx aony aonz aooa aoob aooc aood aooe aoof aoog aooh aooi aooj aook aool +aoom aoon aooo aoop aooq aoor aoos aoot aoou aoov aoow aoox aooy aooz aopa +aopb aopc aopd aope aopf aopg aoph aopi aopj aopk aopl aopm aopn aopo aopp +aopq aopr aops aopt aopu aopv aopw aopx aopy aopz aoqa aoqb aoqc aoqd aoqe +aoqf aoqg aoqh aoqi aoqj aoqk aoql aoqm aoqn aoqo aoqp aoqq aoqr aoqs aoqt +aoqu aoqv aoqw aoqx aoqy aoqz aora aorb aorc aord aore aorf aorg aorh aori +aorj aork aorl aorm aorn aoro aorp aorq aorr aors aort aoru aorv aorw aorx +aory aorz aosa aosb aosc aosd aose aosf aosg aosh aosi aosj aosk aosl aosm +aosn aoso aosp aosq aosr aoss aost aosu aosv aosw aosx aosy aosz aota aotb +aotc aotd aote aotf aotg aoth aoti aotj aotk aotl aotm aotn aoto aotp aotq +aotr aots aott aotu aotv aotw aotx aoty aotz aoua aoub aouc aoud aoue aouf +aoug aouh aoui aouj aouk aoul aoum aoun aouo aoup aouq aour aous aout aouu +aouv aouw aoux aouy aouz aova aovb aovc aovd aove aovf aovg aovh aovi aovj +aovk aovl aovm aovn aovo aovp aovq aovr aovs aovt aovu aovv aovw aovx aovy +aovz aowa aowb aowc aowd aowe aowf aowg aowh aowi aowj aowk aowl aowm aown +aowo aowp aowq aowr aows aowt aowu aowv aoww aowx aowy aowz aoxa aoxb aoxc +aoxd aoxe aoxf aoxg aoxh aoxi aoxj aoxk aoxl aoxm aoxn aoxo aoxp aoxq aoxr +aoxs aoxt aoxu aoxv aoxw aoxx aoxy aoxz aoya aoyb aoyc aoyd aoye aoyf aoyg +aoyh aoyi aoyj aoyk aoyl aoym aoyn aoyo aoyp aoyq aoyr aoys aoyt aoyu aoyv +aoyw aoyx aoyy aoyz aoza aozb aozc aozd aoze aozf aozg aozh aozi aozj aozk +aozl aozm aozn aozo aozp aozq aozr aozs aozt aozu aozv aozw aozx aozy aozz +apaa apab apac apad apae apaf apag apah apai apaj apak apal apam apan apao +apap apaq apar apas apat apau apav apaw apax apay apaz apba apbb apbc apbd +apbe apbf apbg apbh apbi apbj apbk apbl apbm apbn apbo apbp apbq apbr apbs +apbt apbu apbv apbw apbx apby apbz apca apcb apcc apcd apce apcf apcg apch +apci apcj apck apcl apcm apcn apco apcp apcq apcr apcs apct apcu apcv apcw +apcx apcy apcz apda apdb apdc apdd apde apdf apdg apdh apdi apdj apdk apdl +apdm apdn apdo apdp apdq apdr apds apdt apdu apdv apdw apdx apdy apdz apea +apeb apec aped apee apef apeg apeh apei apej apek apel apem apen apeo apep +apeq aper apes apet apeu apev apew apex apey apez apfa apfb apfc apfd apfe +apff apfg apfh apfi apfj apfk apfl apfm apfn apfo apfp apfq apfr apfs apft +apfu apfv apfw apfx apfy apfz apga apgb apgc apgd apge apgf apgg apgh apgi +apgj apgk apgl apgm apgn apgo apgp apgq apgr apgs apgt apgu apgv apgw apgx +apgy apgz apha aphb aphc aphd aphe aphf aphg aphh aphi aphj aphk aphl aphm +aphn apho aphp aphq aphr aphs apht aphu aphv aphw aphx aphy aphz apia apib +apic apid apie apif apig apih apii apij apik apil apim apin apio apip apiq +apir apis apit apiu apiv apiw apix apiy apiz apja apjb apjc apjd apje apjf +apjg apjh apji apjj apjk apjl apjm apjn apjo apjp apjq apjr apjs apjt apju +apjv apjw apjx apjy apjz apka apkb apkc apkd apke apkf apkg apkh apki apkj +apkk apkl apkm apkn apko apkp apkq apkr apks apkt apku apkv apkw apkx apky +apkz apla aplb aplc apld aple aplf aplg aplh apli aplj aplk apll aplm apln +aplo aplp aplq aplr apls aplt aplu aplv aplw aplx aply aplz apma apmb apmc +apmd apme apmf apmg apmh apmi apmj apmk apml apmm apmn apmo apmp apmq apmr +apms apmt apmu apmv apmw apmx apmy apmz apna apnb apnc apnd apne apnf apng +apnh apni apnj apnk apnl apnm apnn apno apnp apnq apnr apns apnt apnu apnv +apnw apnx apny apnz apoa apob apoc apod apoe apof apog apoh apoi apoj apok +apol apom apon apoo apop apoq apor apos apot apou apov apow apox apoy apoz +appa appb appc appd appe appf appg apph appi appj appk appl appm appn appo +appp appq appr apps appt appu appv appw appx appy appz apqa apqb apqc apqd +apqe apqf apqg apqh apqi apqj apqk apql apqm apqn apqo apqp apqq apqr apqs +apqt apqu apqv apqw apqx apqy apqz apra aprb aprc aprd apre aprf aprg aprh +apri aprj aprk aprl aprm aprn apro aprp aprq aprr aprs aprt apru aprv aprw +aprx apry aprz apsa apsb apsc apsd apse apsf apsg apsh apsi apsj apsk apsl +apsm apsn apso apsp apsq apsr apss apst apsu apsv apsw apsx apsy apsz apta +aptb aptc aptd apte aptf aptg apth apti aptj aptk aptl aptm aptn apto aptp +aptq aptr apts aptt aptu aptv aptw aptx apty aptz apua apub apuc apud apue +apuf apug apuh apui apuj apuk apul apum apun apuo apup apuq apur apus aput +apuu apuv apuw apux apuy apuz apva apvb apvc apvd apve apvf apvg apvh apvi +apvj apvk apvl apvm apvn apvo apvp apvq apvr apvs apvt apvu apvv apvw apvx +apvy apvz apwa apwb apwc apwd apwe apwf apwg apwh apwi apwj apwk apwl apwm +apwn apwo apwp apwq apwr apws apwt apwu apwv apww apwx apwy apwz apxa apxb +apxc apxd apxe apxf apxg apxh apxi apxj apxk apxl apxm apxn apxo apxp apxq +apxr apxs apxt apxu apxv apxw apxx apxy apxz apya apyb apyc apyd apye apyf +apyg apyh apyi apyj apyk apyl apym apyn apyo apyp apyq apyr apys apyt apyu +apyv apyw apyx apyy apyz apza apzb apzc apzd apze apzf apzg apzh apzi apzj +apzk apzl apzm apzn apzo apzp apzq apzr apzs apzt apzu apzv apzw apzx apzy +apzz aqaa aqab aqac aqad aqae aqaf aqag aqah aqai aqaj aqak aqal aqam aqan +aqao aqap aqaq aqar aqas aqat aqau aqav aqaw aqax aqay aqaz aqba aqbb aqbc +aqbd aqbe aqbf aqbg aqbh aqbi aqbj aqbk aqbl aqbm aqbn aqbo aqbp aqbq aqbr +aqbs aqbt aqbu aqbv aqbw aqbx aqby aqbz aqca aqcb aqcc aqcd aqce aqcf aqcg +aqch aqci aqcj aqck aqcl aqcm aqcn aqco aqcp aqcq aqcr aqcs aqct aqcu aqcv +aqcw aqcx aqcy aqcz aqda aqdb aqdc aqdd aqde aqdf aqdg aqdh aqdi aqdj aqdk +aqdl aqdm aqdn aqdo aqdp aqdq aqdr aqds aqdt aqdu aqdv aqdw aqdx aqdy aqdz +aqea aqeb aqec aqed aqee aqef aqeg aqeh aqei aqej aqek aqel aqem aqen aqeo +aqep aqeq aqer aqes aqet aqeu aqev aqew aqex aqey aqez aqfa aqfb aqfc aqfd +aqfe aqff aqfg aqfh aqfi aqfj aqfk aqfl aqfm aqfn aqfo aqfp aqfq aqfr aqfs +aqft aqfu aqfv aqfw aqfx aqfy aqfz aqga aqgb aqgc aqgd aqge aqgf aqgg aqgh +aqgi aqgj aqgk aqgl aqgm aqgn aqgo aqgp aqgq aqgr aqgs aqgt aqgu aqgv aqgw +aqgx aqgy aqgz aqha aqhb aqhc aqhd aqhe aqhf aqhg aqhh aqhi aqhj aqhk aqhl +aqhm aqhn aqho aqhp aqhq aqhr aqhs aqht aqhu aqhv aqhw aqhx aqhy aqhz aqia +aqib aqic aqid aqie aqif aqig aqih aqii aqij aqik aqil aqim aqin aqio aqip +aqiq aqir aqis aqit aqiu aqiv aqiw aqix aqiy aqiz aqja aqjb aqjc aqjd aqje +aqjf aqjg aqjh aqji aqjj aqjk aqjl aqjm aqjn aqjo aqjp aqjq aqjr aqjs aqjt +aqju aqjv aqjw aqjx aqjy aqjz aqka aqkb aqkc aqkd aqke aqkf aqkg aqkh aqki +aqkj aqkk aqkl aqkm aqkn aqko aqkp aqkq aqkr aqks aqkt aqku aqkv aqkw aqkx +aqky aqkz aqla aqlb aqlc aqld aqle aqlf aqlg aqlh aqli aqlj aqlk aqll aqlm +aqln aqlo aqlp aqlq aqlr aqls aqlt aqlu aqlv aqlw aqlx aqly aqlz aqma aqmb +aqmc aqmd aqme aqmf aqmg aqmh aqmi aqmj aqmk aqml aqmm aqmn aqmo aqmp aqmq +aqmr aqms aqmt aqmu aqmv aqmw aqmx aqmy aqmz aqna aqnb aqnc aqnd aqne aqnf +aqng aqnh aqni aqnj aqnk aqnl aqnm aqnn aqno aqnp aqnq aqnr aqns aqnt aqnu +aqnv aqnw aqnx aqny aqnz aqoa aqob aqoc aqod aqoe aqof aqog aqoh aqoi aqoj +aqok aqol aqom aqon aqoo aqop aqoq aqor aqos aqot aqou aqov aqow aqox aqoy +aqoz aqpa aqpb aqpc aqpd aqpe aqpf aqpg aqph aqpi aqpj aqpk aqpl aqpm aqpn +aqpo aqpp aqpq aqpr aqps aqpt aqpu aqpv aqpw aqpx aqpy aqpz aqqa aqqb aqqc +aqqd aqqe aqqf aqqg aqqh aqqi aqqj aqqk aqql aqqm aqqn aqqo aqqp aqqq aqqr +aqqs aqqt aqqu aqqv aqqw aqqx aqqy aqqz aqra aqrb aqrc aqrd aqre aqrf aqrg +aqrh aqri aqrj aqrk aqrl aqrm aqrn aqro aqrp aqrq aqrr aqrs aqrt aqru aqrv +aqrw aqrx aqry aqrz aqsa aqsb aqsc aqsd aqse aqsf aqsg aqsh aqsi aqsj aqsk +aqsl aqsm aqsn aqso aqsp aqsq aqsr aqss aqst aqsu aqsv aqsw aqsx aqsy aqsz +aqta aqtb aqtc aqtd aqte aqtf aqtg aqth aqti aqtj aqtk aqtl aqtm aqtn aqto +aqtp aqtq aqtr aqts aqtt aqtu aqtv aqtw aqtx aqty aqtz aqua aqub aquc aqud +aque aquf aqug aquh aqui aquj aquk aqul aqum aqun aquo aqup aquq aqur aqus +aqut aquu aquv aquw aqux aquy aquz aqva aqvb aqvc aqvd aqve aqvf aqvg aqvh +aqvi aqvj aqvk aqvl aqvm aqvn aqvo aqvp aqvq aqvr aqvs aqvt aqvu aqvv aqvw +aqvx aqvy aqvz aqwa aqwb aqwc aqwd aqwe aqwf aqwg aqwh aqwi aqwj aqwk aqwl +aqwm aqwn aqwo aqwp aqwq aqwr aqws aqwt aqwu aqwv aqww aqwx aqwy aqwz aqxa +aqxb aqxc aqxd aqxe aqxf aqxg aqxh aqxi aqxj aqxk aqxl aqxm aqxn aqxo aqxp +aqxq aqxr aqxs aqxt aqxu aqxv aqxw aqxx aqxy aqxz aqya aqyb aqyc aqyd aqye +aqyf aqyg aqyh aqyi aqyj aqyk aqyl aqym aqyn aqyo aqyp aqyq aqyr aqys aqyt +aqyu aqyv aqyw aqyx aqyy aqyz aqza aqzb aqzc aqzd aqze aqzf aqzg aqzh aqzi +aqzj aqzk aqzl aqzm aqzn aqzo aqzp aqzq aqzr aqzs aqzt aqzu aqzv aqzw aqzx +aqzy aqzz araa arab arac arad arae araf arag arah arai araj arak aral aram +aran arao arap araq arar aras arat arau arav araw arax aray araz arba arbb +arbc arbd arbe arbf arbg arbh arbi arbj arbk arbl arbm arbn arbo arbp arbq +arbr arbs arbt arbu arbv arbw arbx arby arbz arca arcb arcc arcd arce arcf +arcg arch arci arcj arck arcl arcm arcn arco arcp arcq arcr arcs arct arcu +arcv arcw arcx arcy arcz arda ardb ardc ardd arde ardf ardg ardh ardi ardj +ardk ardl ardm ardn ardo ardp ardq ardr ards ardt ardu ardv ardw ardx ardy +ardz area areb arec ared aree aref areg areh arei arej arek arel arem aren +areo arep areq arer ares aret areu arev arew arex arey arez arfa arfb arfc +arfd arfe arff arfg arfh arfi arfj arfk arfl arfm arfn arfo arfp arfq arfr +arfs arft arfu arfv arfw arfx arfy arfz arga argb argc argd arge argf argg +argh argi argj argk argl argm argn argo argp argq argr args argt argu argv +argw argx argy argz arha arhb arhc arhd arhe arhf arhg arhh arhi arhj arhk +arhl arhm arhn arho arhp arhq arhr arhs arht arhu arhv arhw arhx arhy arhz +aria arib aric arid arie arif arig arih arii arij arik aril arim arin ario +arip ariq arir aris arit ariu ariv ariw arix ariy ariz arja arjb arjc arjd +arje arjf arjg arjh arji arjj arjk arjl arjm arjn arjo arjp arjq arjr arjs +arjt arju arjv arjw arjx arjy arjz arka arkb arkc arkd arke arkf arkg arkh +arki arkj arkk arkl arkm arkn arko arkp arkq arkr arks arkt arku arkv arkw +arkx arky arkz arla arlb arlc arld arle arlf arlg arlh arli arlj arlk arll +arlm arln arlo arlp arlq arlr arls arlt arlu arlv arlw arlx arly arlz arma +armb armc armd arme armf armg armh armi armj armk arml armm armn armo armp +armq armr arms armt armu armv armw armx army armz arna arnb arnc arnd arne +arnf arng arnh arni arnj arnk arnl arnm arnn arno arnp arnq arnr arns arnt +arnu arnv arnw arnx arny arnz aroa arob aroc arod aroe arof arog aroh aroi +aroj arok arol arom aron aroo arop aroq aror aros arot arou arov arow arox +aroy aroz arpa arpb arpc arpd arpe arpf arpg arph arpi arpj arpk arpl arpm +arpn arpo arpp arpq arpr arps arpt arpu arpv arpw arpx arpy arpz arqa arqb +arqc arqd arqe arqf arqg arqh arqi arqj arqk arql arqm arqn arqo arqp arqq +arqr arqs arqt arqu arqv arqw arqx arqy arqz arra arrb arrc arrd arre arrf +arrg arrh arri arrj arrk arrl arrm arrn arro arrp arrq arrr arrs arrt arru +arrv arrw arrx arry arrz arsa arsb arsc arsd arse arsf arsg arsh arsi arsj +arsk arsl arsm arsn arso arsp arsq arsr arss arst arsu arsv arsw arsx arsy +arsz arta artb artc artd arte artf artg arth arti artj artk artl artm artn +arto artp artq artr arts artt artu artv artw artx arty artz arua arub aruc +arud arue aruf arug aruh arui aruj aruk arul arum arun aruo arup aruq arur +arus arut aruu aruv aruw arux aruy aruz arva arvb arvc arvd arve arvf arvg +arvh arvi arvj arvk arvl arvm arvn arvo arvp arvq arvr arvs arvt arvu arvv +arvw arvx arvy arvz arwa arwb arwc arwd arwe arwf arwg arwh arwi arwj arwk +arwl arwm arwn arwo arwp arwq arwr arws arwt arwu arwv arww arwx arwy arwz +arxa arxb arxc arxd arxe arxf arxg arxh arxi arxj arxk arxl arxm arxn arxo +arxp arxq arxr arxs arxt arxu arxv arxw arxx arxy arxz arya aryb aryc aryd +arye aryf aryg aryh aryi aryj aryk aryl arym aryn aryo aryp aryq aryr arys +aryt aryu aryv aryw aryx aryy aryz arza arzb arzc arzd arze arzf arzg arzh +arzi arzj arzk arzl arzm arzn arzo arzp arzq arzr arzs arzt arzu arzv arzw +arzx arzy arzz asaa asab asac asad asae asaf asag asah asai asaj asak asal +asam asan asao asap asaq asar asas asat asau asav asaw asax asay asaz asba +asbb asbc asbd asbe asbf asbg asbh asbi asbj asbk asbl asbm asbn asbo asbp +asbq asbr asbs asbt asbu asbv asbw asbx asby asbz asca ascb ascc ascd asce +ascf ascg asch asci ascj asck ascl ascm ascn asco ascp ascq ascr ascs asct +ascu ascv ascw ascx ascy ascz asda asdb asdc asdd asde asdf asdg asdh asdi +asdj asdk asdl asdm asdn asdo asdp asdq asdr asds asdt asdu asdv asdw asdx +asdy asdz asea aseb asec ased asee asef aseg aseh asei asej asek asel asem +asen aseo asep aseq aser ases aset aseu asev asew asex asey asez asfa asfb +asfc asfd asfe asff asfg asfh asfi asfj asfk asfl asfm asfn asfo asfp asfq +asfr asfs asft asfu asfv asfw asfx asfy asfz asga asgb asgc asgd asge asgf +asgg asgh asgi asgj asgk asgl asgm asgn asgo asgp asgq asgr asgs asgt asgu +asgv asgw asgx asgy asgz asha ashb ashc ashd ashe ashf ashg ashh ashi ashj +ashk ashl ashm ashn asho ashp ashq ashr ashs asht ashu ashv ashw ashx ashy +ashz asia asib asic asid asie asif asig asih asii asij asik asil asim asin +asio asip asiq asir asis asit asiu asiv asiw asix asiy asiz asja asjb asjc +asjd asje asjf asjg asjh asji asjj asjk asjl asjm asjn asjo asjp asjq asjr +asjs asjt asju asjv asjw asjx asjy asjz aska askb askc askd aske askf askg +askh aski askj askk askl askm askn asko askp askq askr asks askt asku askv +askw askx asky askz asla aslb aslc asld asle aslf aslg aslh asli aslj aslk +asll aslm asln aslo aslp aslq aslr asls aslt aslu aslv aslw aslx asly aslz +asma asmb asmc asmd asme asmf asmg asmh asmi asmj asmk asml asmm asmn asmo +asmp asmq asmr asms asmt asmu asmv asmw asmx asmy asmz asna asnb asnc asnd +asne asnf asng asnh asni asnj asnk asnl asnm asnn asno asnp asnq asnr asns +asnt asnu asnv asnw asnx asny asnz asoa asob asoc asod asoe asof asog asoh +asoi asoj asok asol asom ason asoo asop asoq asor asos asot asou asov asow +asox asoy asoz aspa aspb aspc aspd aspe aspf aspg asph aspi aspj aspk aspl +aspm aspn aspo aspp aspq aspr asps aspt aspu aspv aspw aspx aspy aspz asqa +asqb asqc asqd asqe asqf asqg asqh asqi asqj asqk asql asqm asqn asqo asqp +asqq asqr asqs asqt asqu asqv asqw asqx asqy asqz asra asrb asrc asrd asre +asrf asrg asrh asri asrj asrk asrl asrm asrn asro asrp asrq asrr asrs asrt +asru asrv asrw asrx asry asrz assa assb assc assd asse assf assg assh assi +assj assk assl assm assn asso assp assq assr asss asst assu assv assw assx +assy assz asta astb astc astd aste astf astg asth asti astj astk astl astm +astn asto astp astq astr asts astt astu astv astw astx asty astz asua asub +asuc asud asue asuf asug asuh asui asuj asuk asul asum asun asuo asup asuq +asur asus asut asuu asuv asuw asux asuy asuz asva asvb asvc asvd asve asvf +asvg asvh asvi asvj asvk asvl asvm asvn asvo asvp asvq asvr asvs asvt asvu +asvv asvw asvx asvy asvz aswa aswb aswc aswd aswe aswf aswg aswh aswi aswj +aswk aswl aswm aswn aswo aswp aswq aswr asws aswt aswu aswv asww aswx aswy +aswz asxa asxb asxc asxd asxe asxf asxg asxh asxi asxj asxk asxl asxm asxn +asxo asxp asxq asxr asxs asxt asxu asxv asxw asxx asxy asxz asya asyb asyc +asyd asye asyf asyg asyh asyi asyj asyk asyl asym asyn asyo asyp asyq asyr +asys asyt asyu asyv asyw asyx asyy asyz asza aszb aszc aszd asze aszf aszg +aszh aszi aszj aszk aszl aszm aszn aszo aszp aszq aszr aszs aszt aszu aszv +aszw aszx aszy aszz ataa atab atac atad atae ataf atag atah atai ataj atak +atal atam atan atao atap ataq atar atas atat atau atav ataw atax atay ataz +atba atbb atbc atbd atbe atbf atbg atbh atbi atbj atbk atbl atbm atbn atbo +atbp atbq atbr atbs atbt atbu atbv atbw atbx atby atbz atca atcb atcc atcd +atce atcf atcg atch atci atcj atck atcl atcm atcn atco atcp atcq atcr atcs +atct atcu atcv atcw atcx atcy atcz atda atdb atdc atdd atde atdf atdg atdh +atdi atdj atdk atdl atdm atdn atdo atdp atdq atdr atds atdt atdu atdv atdw +atdx atdy atdz atea ateb atec ated atee atef ateg ateh atei atej atek atel +atem aten ateo atep ateq ater ates atet ateu atev atew atex atey atez atfa +atfb atfc atfd atfe atff atfg atfh atfi atfj atfk atfl atfm atfn atfo atfp +atfq atfr atfs atft atfu atfv atfw atfx atfy atfz atga atgb atgc atgd atge +atgf atgg atgh atgi atgj atgk atgl atgm atgn atgo atgp atgq atgr atgs atgt +atgu atgv atgw atgx atgy atgz atha athb athc athd athe athf athg athh athi +athj athk athl athm athn atho athp athq athr aths atht athu athv athw athx +athy athz atia atib atic atid atie atif atig atih atii atij atik atil atim +atin atio atip atiq atir atis atit atiu ativ atiw atix atiy atiz atja atjb +atjc atjd atje atjf atjg atjh atji atjj atjk atjl atjm atjn atjo atjp atjq +atjr atjs atjt atju atjv atjw atjx atjy atjz atka atkb atkc atkd atke atkf +atkg atkh atki atkj atkk atkl atkm atkn atko atkp atkq atkr atks atkt atku +atkv atkw atkx atky atkz atla atlb atlc atld atle atlf atlg atlh atli atlj +atlk atll atlm atln atlo atlp atlq atlr atls atlt atlu atlv atlw atlx atly +atlz atma atmb atmc atmd atme atmf atmg atmh atmi atmj atmk atml atmm atmn +atmo atmp atmq atmr atms atmt atmu atmv atmw atmx atmy atmz atna atnb atnc +atnd atne atnf atng atnh atni atnj atnk atnl atnm atnn atno atnp atnq atnr +atns atnt atnu atnv atnw atnx atny atnz atoa atob atoc atod atoe atof atog +atoh atoi atoj atok atol atom aton atoo atop atoq ator atos atot atou atov +atow atox atoy atoz atpa atpb atpc atpd atpe atpf atpg atph atpi atpj atpk +atpl atpm atpn atpo atpp atpq atpr atps atpt atpu atpv atpw atpx atpy atpz +atqa atqb atqc atqd atqe atqf atqg atqh atqi atqj atqk atql atqm atqn atqo +atqp atqq atqr atqs atqt atqu atqv atqw atqx atqy atqz atra atrb atrc atrd +atre atrf atrg atrh atri atrj atrk atrl atrm atrn atro atrp atrq atrr atrs +atrt atru atrv atrw atrx atry atrz atsa atsb atsc atsd atse atsf atsg atsh +atsi atsj atsk atsl atsm atsn atso atsp atsq atsr atss atst atsu atsv atsw +atsx atsy atsz atta attb attc attd atte attf attg atth atti attj attk attl +attm attn atto attp attq attr atts attt attu attv attw attx atty attz atua +atub atuc atud atue atuf atug atuh atui atuj atuk atul atum atun atuo atup +atuq atur atus atut atuu atuv atuw atux atuy atuz atva atvb atvc atvd atve +atvf atvg atvh atvi atvj atvk atvl atvm atvn atvo atvp atvq atvr atvs atvt +atvu atvv atvw atvx atvy atvz atwa atwb atwc atwd atwe atwf atwg atwh atwi +atwj atwk atwl atwm atwn atwo atwp atwq atwr atws atwt atwu atwv atww atwx +atwy atwz atxa atxb atxc atxd atxe atxf atxg atxh atxi atxj atxk atxl atxm +atxn atxo atxp atxq atxr atxs atxt atxu atxv atxw atxx atxy atxz atya atyb +atyc atyd atye atyf atyg atyh atyi atyj atyk atyl atym atyn atyo atyp atyq +atyr atys atyt atyu atyv atyw atyx atyy atyz atza atzb atzc atzd atze atzf +atzg atzh atzi atzj atzk atzl atzm atzn atzo atzp atzq atzr atzs atzt atzu +atzv atzw atzx atzy atzz auaa auab auac auad auae auaf auag auah auai auaj +auak aual auam auan auao auap auaq auar auas auat auau auav auaw auax auay +auaz auba aubb aubc aubd aube aubf aubg aubh aubi aubj aubk aubl aubm aubn +aubo aubp aubq aubr aubs aubt aubu aubv aubw aubx auby aubz auca aucb aucc +aucd auce aucf aucg auch auci aucj auck aucl aucm aucn auco aucp aucq aucr +aucs auct aucu aucv aucw aucx aucy aucz auda audb audc audd aude audf audg +audh audi audj audk audl audm audn audo audp audq audr auds audt audu audv +audw audx audy audz auea aueb auec aued auee auef aueg aueh auei auej auek +auel auem auen aueo auep aueq auer aues auet aueu auev auew auex auey auez +aufa aufb aufc aufd aufe auff aufg aufh aufi aufj aufk aufl aufm aufn aufo +aufp aufq aufr aufs auft aufu aufv aufw aufx aufy aufz auga augb augc augd +auge augf augg augh augi augj augk augl augm augn augo augp augq augr augs +augt augu augv augw augx augy augz auha auhb auhc auhd auhe auhf auhg auhh +auhi auhj auhk auhl auhm auhn auho auhp auhq auhr auhs auht auhu auhv auhw +auhx auhy auhz auia auib auic auid auie auif auig auih auii auij auik auil +auim auin auio auip auiq auir auis auit auiu auiv auiw auix auiy auiz auja +aujb aujc aujd auje aujf aujg aujh auji aujj aujk aujl aujm aujn aujo aujp +aujq aujr aujs aujt auju aujv aujw aujx aujy aujz auka aukb aukc aukd auke +aukf aukg aukh auki aukj aukk aukl aukm aukn auko aukp aukq aukr auks aukt +auku aukv aukw aukx auky aukz aula aulb aulc auld aule aulf aulg aulh auli +aulj aulk aull aulm auln aulo aulp aulq aulr auls ault aulu aulv aulw aulx +auly aulz auma aumb aumc aumd aume aumf aumg aumh aumi aumj aumk auml aumm +aumn aumo aump aumq aumr aums aumt aumu aumv aumw aumx aumy aumz auna aunb +aunc aund aune aunf aung aunh auni aunj aunk aunl aunm aunn auno aunp aunq +aunr auns aunt aunu aunv aunw aunx auny aunz auoa auob auoc auod auoe auof +auog auoh auoi auoj auok auol auom auon auoo auop auoq auor auos auot auou +auov auow auox auoy auoz aupa aupb aupc aupd aupe aupf aupg auph aupi aupj +aupk aupl aupm aupn aupo aupp aupq aupr aups aupt aupu aupv aupw aupx aupy +aupz auqa auqb auqc auqd auqe auqf auqg auqh auqi auqj auqk auql auqm auqn +auqo auqp auqq auqr auqs auqt auqu auqv auqw auqx auqy auqz aura aurb aurc +aurd aure aurf aurg aurh auri aurj aurk aurl aurm aurn auro aurp aurq aurr +aurs aurt auru aurv aurw aurx aury aurz ausa ausb ausc ausd ause ausf ausg +aush ausi ausj ausk ausl ausm ausn auso ausp ausq ausr auss aust ausu ausv +ausw ausx ausy ausz auta autb autc autd aute autf autg auth auti autj autk +autl autm autn auto autp autq autr auts autt autu autv autw autx auty autz +auua auub auuc auud auue auuf auug auuh auui auuj auuk auul auum auun auuo +auup auuq auur auus auut auuu auuv auuw auux auuy auuz auva auvb auvc auvd +auve auvf auvg auvh auvi auvj auvk auvl auvm auvn auvo auvp auvq auvr auvs +auvt auvu auvv auvw auvx auvy auvz auwa auwb auwc auwd auwe auwf auwg auwh +auwi auwj auwk auwl auwm auwn auwo auwp auwq auwr auws auwt auwu auwv auww +auwx auwy auwz auxa auxb auxc auxd auxe auxf auxg auxh auxi auxj auxk auxl +auxm auxn auxo auxp auxq auxr auxs auxt auxu auxv auxw auxx auxy auxz auya +auyb auyc auyd auye auyf auyg auyh auyi auyj auyk auyl auym auyn auyo auyp +auyq auyr auys auyt auyu auyv auyw auyx auyy auyz auza auzb auzc auzd auze +auzf auzg auzh auzi auzj auzk auzl auzm auzn auzo auzp auzq auzr auzs auzt +auzu auzv auzw auzx auzy auzz avaa avab avac avad avae avaf avag avah avai +avaj avak aval avam avan avao avap avaq avar avas avat avau avav avaw avax +avay avaz avba avbb avbc avbd avbe avbf avbg avbh avbi avbj avbk avbl avbm +avbn avbo avbp avbq avbr avbs avbt avbu avbv avbw avbx avby avbz avca avcb +avcc avcd avce avcf avcg avch avci avcj avck avcl avcm avcn avco avcp avcq +avcr avcs avct avcu avcv avcw avcx avcy avcz avda avdb avdc avdd avde avdf +avdg avdh avdi avdj avdk avdl avdm avdn avdo avdp avdq avdr avds avdt avdu +avdv avdw avdx avdy avdz avea aveb avec aved avee avef aveg aveh avei avej +avek avel avem aven aveo avep aveq aver aves avet aveu avev avew avex avey +avez avfa avfb avfc avfd avfe avff avfg avfh avfi avfj avfk avfl avfm avfn +avfo avfp avfq avfr avfs avft avfu avfv avfw avfx avfy avfz avga avgb avgc +avgd avge avgf avgg avgh avgi avgj avgk avgl avgm avgn avgo avgp avgq avgr +avgs avgt avgu avgv avgw avgx avgy avgz avha avhb avhc avhd avhe avhf avhg +avhh avhi avhj avhk avhl avhm avhn avho avhp avhq avhr avhs avht avhu avhv +avhw avhx avhy avhz avia avib avic avid avie avif avig avih avii avij avik +avil avim avin avio avip aviq avir avis avit aviu aviv aviw avix aviy aviz +avja avjb avjc avjd avje avjf avjg avjh avji avjj avjk avjl avjm avjn avjo +avjp avjq avjr avjs avjt avju avjv avjw avjx avjy avjz avka avkb avkc avkd +avke avkf avkg avkh avki avkj avkk avkl avkm avkn avko avkp avkq avkr avks +avkt avku avkv avkw avkx avky avkz avla avlb avlc avld avle avlf avlg avlh +avli avlj avlk avll avlm avln avlo avlp avlq avlr avls avlt avlu avlv avlw +avlx avly avlz avma avmb avmc avmd avme avmf avmg avmh avmi avmj avmk avml +avmm avmn avmo avmp avmq avmr avms avmt avmu avmv avmw avmx avmy avmz avna +avnb avnc avnd avne avnf avng avnh avni avnj avnk avnl avnm avnn avno avnp +avnq avnr avns avnt avnu avnv avnw avnx avny avnz avoa avob avoc avod avoe +avof avog avoh avoi avoj avok avol avom avon avoo avop avoq avor avos avot +avou avov avow avox avoy avoz avpa avpb avpc avpd avpe avpf avpg avph avpi +avpj avpk avpl avpm avpn avpo avpp avpq avpr avps avpt avpu avpv avpw avpx +avpy avpz avqa avqb avqc avqd avqe avqf avqg avqh avqi avqj avqk avql avqm +avqn avqo avqp avqq avqr avqs avqt avqu avqv avqw avqx avqy avqz avra avrb +avrc avrd avre avrf avrg avrh avri avrj avrk avrl avrm avrn avro avrp avrq +avrr avrs avrt avru avrv avrw avrx avry avrz avsa avsb avsc avsd avse avsf +avsg avsh avsi avsj avsk avsl avsm avsn avso avsp avsq avsr avss avst avsu +avsv avsw avsx avsy avsz avta avtb avtc avtd avte avtf avtg avth avti avtj +avtk avtl avtm avtn avto avtp avtq avtr avts avtt avtu avtv avtw avtx avty +avtz avua avub avuc avud avue avuf avug avuh avui avuj avuk avul avum avun +avuo avup avuq avur avus avut avuu avuv avuw avux avuy avuz avva avvb avvc +avvd avve avvf avvg avvh avvi avvj avvk avvl avvm avvn avvo avvp avvq avvr +avvs avvt avvu avvv avvw avvx avvy avvz avwa avwb avwc avwd avwe avwf avwg +avwh avwi avwj avwk avwl avwm avwn avwo avwp avwq avwr avws avwt avwu avwv +avww avwx avwy avwz avxa avxb avxc avxd avxe avxf avxg avxh avxi avxj avxk +avxl avxm avxn avxo avxp avxq avxr avxs avxt avxu avxv avxw avxx avxy avxz +avya avyb avyc avyd avye avyf avyg avyh avyi avyj avyk avyl avym avyn avyo +avyp avyq avyr avys avyt avyu avyv avyw avyx avyy avyz avza avzb avzc avzd +avze avzf avzg avzh avzi avzj avzk avzl avzm avzn avzo avzp avzq avzr avzs +avzt avzu avzv avzw avzx avzy avzz awaa awab awac awad awae awaf awag awah +awai awaj awak awal awam awan awao awap awaq awar awas awat awau awav awaw +awax away awaz awba awbb awbc awbd awbe awbf awbg awbh awbi awbj awbk awbl +awbm awbn awbo awbp awbq awbr awbs awbt awbu awbv awbw awbx awby awbz awca +awcb awcc awcd awce awcf awcg awch awci awcj awck awcl awcm awcn awco awcp +awcq awcr awcs awct awcu awcv awcw awcx awcy awcz awda awdb awdc awdd awde +awdf awdg awdh awdi awdj awdk awdl awdm awdn awdo awdp awdq awdr awds awdt +awdu awdv awdw awdx awdy awdz awea aweb awec awed awee awef aweg aweh awei +awej awek awel awem awen aweo awep aweq awer awes awet aweu awev awew awex +awey awez awfa awfb awfc awfd awfe awff awfg awfh awfi awfj awfk awfl awfm +awfn awfo awfp awfq awfr awfs awft awfu awfv awfw awfx awfy awfz awga awgb +awgc awgd awge awgf awgg awgh awgi awgj awgk awgl awgm awgn awgo awgp awgq +awgr awgs awgt awgu awgv awgw awgx awgy awgz awha awhb awhc awhd awhe awhf +awhg awhh awhi awhj awhk awhl awhm awhn awho awhp awhq awhr awhs awht awhu +awhv awhw awhx awhy awhz awia awib awic awid awie awif awig awih awii awij +awik awil awim awin awio awip awiq awir awis awit awiu awiv awiw awix awiy +awiz awja awjb awjc awjd awje awjf awjg awjh awji awjj awjk awjl awjm awjn +awjo awjp awjq awjr awjs awjt awju awjv awjw awjx awjy awjz awka awkb awkc +awkd awke awkf awkg awkh awki awkj awkk awkl awkm awkn awko awkp awkq awkr +awks awkt awku awkv awkw awkx awky awkz awla awlb awlc awld awle awlf awlg +awlh awli awlj awlk awll awlm awln awlo awlp awlq awlr awls awlt awlu awlv +awlw awlx awly awlz awma awmb awmc awmd awme awmf awmg awmh awmi awmj awmk +awml awmm awmn awmo awmp awmq awmr awms awmt awmu awmv awmw awmx awmy awmz +awna awnb awnc awnd awne awnf awng awnh awni awnj awnk awnl awnm awnn awno +awnp awnq awnr awns awnt awnu awnv awnw awnx awny awnz awoa awob awoc awod +awoe awof awog awoh awoi awoj awok awol awom awon awoo awop awoq awor awos +awot awou awov awow awox awoy awoz awpa awpb awpc awpd awpe awpf awpg awph +awpi awpj awpk awpl awpm awpn awpo awpp awpq awpr awps awpt awpu awpv awpw +awpx awpy awpz awqa awqb awqc awqd awqe awqf awqg awqh awqi awqj awqk awql +awqm awqn awqo awqp awqq awqr awqs awqt awqu awqv awqw awqx awqy awqz awra +awrb awrc awrd awre awrf awrg awrh awri awrj awrk awrl awrm awrn awro awrp +awrq awrr awrs awrt awru awrv awrw awrx awry awrz awsa awsb awsc awsd awse +awsf awsg awsh awsi awsj awsk awsl awsm awsn awso awsp awsq awsr awss awst +awsu awsv awsw awsx awsy awsz awta awtb awtc awtd awte awtf awtg awth awti +awtj awtk awtl awtm awtn awto awtp awtq awtr awts awtt awtu awtv awtw awtx +awty awtz awua awub awuc awud awue awuf awug awuh awui awuj awuk awul awum +awun awuo awup awuq awur awus awut awuu awuv awuw awux awuy awuz awva awvb +awvc awvd awve awvf awvg awvh awvi awvj awvk awvl awvm awvn awvo awvp awvq +awvr awvs awvt awvu awvv awvw awvx awvy awvz awwa awwb awwc awwd awwe awwf +awwg awwh awwi awwj awwk awwl awwm awwn awwo awwp awwq awwr awws awwt awwu +awwv awww awwx awwy awwz awxa awxb awxc awxd awxe awxf awxg awxh awxi awxj +awxk awxl awxm awxn awxo awxp awxq awxr awxs awxt awxu awxv awxw awxx awxy +awxz awya awyb awyc awyd awye awyf awyg awyh awyi awyj awyk awyl awym awyn +awyo awyp awyq awyr awys awyt awyu awyv awyw awyx awyy awyz awza awzb awzc +awzd awze awzf awzg awzh awzi awzj awzk awzl awzm awzn awzo awzp awzq awzr +awzs awzt awzu awzv awzw awzx awzy awzz axaa axab axac axad axae axaf axag +axah axai axaj axak axal axam axan axao axap axaq axar axas axat axau axav +axaw axax axay axaz axba axbb axbc axbd axbe axbf axbg axbh axbi axbj axbk +axbl axbm axbn axbo axbp axbq axbr axbs axbt axbu axbv axbw axbx axby axbz +axca axcb axcc axcd axce axcf axcg axch axci axcj axck axcl axcm axcn axco +axcp axcq axcr axcs axct axcu axcv axcw axcx axcy axcz axda axdb axdc axdd +axde axdf axdg axdh axdi axdj axdk axdl axdm axdn axdo axdp axdq axdr axds +axdt axdu axdv axdw axdx axdy axdz axea axeb axec axed axee axef axeg axeh +axei axej axek axel axem axen axeo axep axeq axer axes axet axeu axev axew +axex axey axez axfa axfb axfc axfd axfe axff axfg axfh axfi axfj axfk axfl +axfm axfn axfo axfp axfq axfr axfs axft axfu axfv axfw axfx axfy axfz axga +axgb axgc axgd axge axgf axgg axgh axgi axgj axgk axgl axgm axgn axgo axgp +axgq axgr axgs axgt axgu axgv axgw axgx axgy axgz axha axhb axhc axhd axhe +axhf axhg axhh axhi axhj axhk axhl axhm axhn axho axhp axhq axhr axhs axht +axhu axhv axhw axhx axhy axhz axia axib axic axid axie axif axig axih axii +axij axik axil axim axin axio axip axiq axir axis axit axiu axiv axiw axix +axiy axiz axja axjb axjc axjd axje axjf axjg axjh axji axjj axjk axjl axjm +axjn axjo axjp axjq axjr axjs axjt axju axjv axjw axjx axjy axjz axka axkb +axkc axkd axke axkf axkg axkh axki axkj axkk axkl axkm axkn axko axkp axkq +axkr axks axkt axku axkv axkw axkx axky axkz axla axlb axlc axld axle axlf +axlg axlh axli axlj axlk axll axlm axln axlo axlp axlq axlr axls axlt axlu +axlv axlw axlx axly axlz axma axmb axmc axmd axme axmf axmg axmh axmi axmj +axmk axml axmm axmn axmo axmp axmq axmr axms axmt axmu axmv axmw axmx axmy +axmz axna axnb axnc axnd axne axnf axng axnh axni axnj axnk axnl axnm axnn +axno axnp axnq axnr axns axnt axnu axnv axnw axnx axny axnz axoa axob axoc +axod axoe axof axog axoh axoi axoj axok axol axom axon axoo axop axoq axor +axos axot axou axov axow axox axoy axoz axpa axpb axpc axpd axpe axpf axpg +axph axpi axpj axpk axpl axpm axpn axpo axpp axpq axpr axps axpt axpu axpv +axpw axpx axpy axpz axqa axqb axqc axqd axqe axqf axqg axqh axqi axqj axqk +axql axqm axqn axqo axqp axqq axqr axqs axqt axqu axqv axqw axqx axqy axqz +axra axrb axrc axrd axre axrf axrg axrh axri axrj axrk axrl axrm axrn axro +axrp axrq axrr axrs axrt axru axrv axrw axrx axry axrz axsa axsb axsc axsd +axse axsf axsg axsh axsi axsj axsk axsl axsm axsn axso axsp axsq axsr axss +axst axsu axsv axsw axsx axsy axsz axta axtb axtc axtd axte axtf axtg axth +axti axtj axtk axtl axtm axtn axto axtp axtq axtr axts axtt axtu axtv axtw +axtx axty axtz axua axub axuc axud axue axuf axug axuh axui axuj axuk axul +axum axun axuo axup axuq axur axus axut axuu axuv axuw axux axuy axuz axva +axvb axvc axvd axve axvf axvg axvh axvi axvj axvk axvl axvm axvn axvo axvp +axvq axvr axvs axvt axvu axvv axvw axvx axvy axvz axwa axwb axwc axwd axwe +axwf axwg axwh axwi axwj axwk axwl axwm axwn axwo axwp axwq axwr axws axwt +axwu axwv axww axwx axwy axwz axxa axxb axxc axxd axxe axxf axxg axxh axxi +axxj axxk axxl axxm axxn axxo axxp axxq axxr axxs axxt axxu axxv axxw axxx +axxy axxz axya axyb axyc axyd axye axyf axyg axyh axyi axyj axyk axyl axym +axyn axyo axyp axyq axyr axys axyt axyu axyv axyw axyx axyy axyz axza axzb +axzc axzd axze axzf axzg axzh axzi axzj axzk axzl axzm axzn axzo axzp axzq +axzr axzs axzt axzu axzv axzw axzx axzy axzz ayaa ayab ayac ayad ayae ayaf +ayag ayah ayai ayaj ayak ayal ayam ayan ayao ayap ayaq ayar ayas ayat ayau +ayav ayaw ayax ayay ayaz ayba aybb aybc aybd aybe aybf aybg aybh aybi aybj +aybk aybl aybm aybn aybo aybp aybq aybr aybs aybt aybu aybv aybw aybx ayby +aybz ayca aycb aycc aycd ayce aycf aycg aych ayci aycj ayck aycl aycm aycn +ayco aycp aycq aycr aycs ayct aycu aycv aycw aycx aycy aycz ayda aydb aydc +aydd ayde aydf aydg aydh aydi aydj aydk aydl aydm aydn aydo aydp aydq aydr +ayds aydt aydu aydv aydw aydx aydy aydz ayea ayeb ayec ayed ayee ayef ayeg +ayeh ayei ayej ayek ayel ayem ayen ayeo ayep ayeq ayer ayes ayet ayeu ayev +ayew ayex ayey ayez ayfa ayfb ayfc ayfd ayfe ayff ayfg ayfh ayfi ayfj ayfk +ayfl ayfm ayfn ayfo ayfp ayfq ayfr ayfs ayft ayfu ayfv ayfw ayfx ayfy ayfz +ayga aygb aygc aygd ayge aygf aygg aygh aygi aygj aygk aygl aygm aygn aygo +aygp aygq aygr aygs aygt aygu aygv aygw aygx aygy aygz ayha ayhb ayhc ayhd +ayhe ayhf ayhg ayhh ayhi ayhj ayhk ayhl ayhm ayhn ayho ayhp ayhq ayhr ayhs +ayht ayhu ayhv ayhw ayhx ayhy ayhz ayia ayib ayic ayid ayie ayif ayig ayih +ayii ayij ayik ayil ayim ayin ayio ayip ayiq ayir ayis ayit ayiu ayiv ayiw +ayix ayiy ayiz ayja ayjb ayjc ayjd ayje ayjf ayjg ayjh ayji ayjj ayjk ayjl +ayjm ayjn ayjo ayjp ayjq ayjr ayjs ayjt ayju ayjv ayjw ayjx ayjy ayjz ayka +aykb aykc aykd ayke aykf aykg aykh ayki aykj aykk aykl aykm aykn ayko aykp +aykq aykr ayks aykt ayku aykv aykw aykx ayky aykz ayla aylb aylc ayld ayle +aylf aylg aylh ayli aylj aylk ayll aylm ayln aylo aylp aylq aylr ayls aylt +aylu aylv aylw aylx ayly aylz ayma aymb aymc aymd ayme aymf aymg aymh aymi +aymj aymk ayml aymm aymn aymo aymp aymq aymr ayms aymt aymu aymv aymw aymx +aymy aymz ayna aynb aync aynd ayne aynf ayng aynh ayni aynj aynk aynl aynm +aynn ayno aynp aynq aynr ayns aynt aynu aynv aynw aynx ayny aynz ayoa ayob +ayoc ayod ayoe ayof ayog ayoh ayoi ayoj ayok ayol ayom ayon ayoo ayop ayoq +ayor ayos ayot ayou ayov ayow ayox ayoy ayoz aypa aypb aypc aypd aype aypf +aypg ayph aypi aypj aypk aypl aypm aypn aypo aypp aypq aypr ayps aypt aypu +aypv aypw aypx aypy aypz ayqa ayqb ayqc ayqd ayqe ayqf ayqg ayqh ayqi ayqj +ayqk ayql ayqm ayqn ayqo ayqp ayqq ayqr ayqs ayqt ayqu ayqv ayqw ayqx ayqy +ayqz ayra ayrb ayrc ayrd ayre ayrf ayrg ayrh ayri ayrj ayrk ayrl ayrm ayrn +ayro ayrp ayrq ayrr ayrs ayrt ayru ayrv ayrw ayrx ayry ayrz aysa aysb aysc +aysd ayse aysf aysg aysh aysi aysj aysk aysl aysm aysn ayso aysp aysq aysr +ayss ayst aysu aysv aysw aysx aysy aysz ayta aytb aytc aytd ayte aytf aytg +ayth ayti aytj aytk aytl aytm aytn ayto aytp aytq aytr ayts aytt aytu aytv +aytw aytx ayty aytz ayua ayub ayuc ayud ayue ayuf ayug ayuh ayui ayuj ayuk +ayul ayum ayun ayuo ayup ayuq ayur ayus ayut ayuu ayuv ayuw ayux ayuy ayuz +ayva ayvb ayvc ayvd ayve ayvf ayvg ayvh ayvi ayvj ayvk ayvl ayvm ayvn ayvo +ayvp ayvq ayvr ayvs ayvt ayvu ayvv ayvw ayvx ayvy ayvz aywa aywb aywc aywd +aywe aywf aywg aywh aywi aywj aywk aywl aywm aywn aywo aywp aywq aywr ayws +aywt aywu aywv ayww aywx aywy aywz ayxa ayxb ayxc ayxd ayxe ayxf ayxg ayxh +ayxi ayxj ayxk ayxl ayxm ayxn ayxo ayxp ayxq ayxr ayxs ayxt ayxu ayxv ayxw +ayxx ayxy ayxz ayya ayyb ayyc ayyd ayye ayyf ayyg ayyh ayyi ayyj ayyk ayyl +ayym ayyn ayyo ayyp ayyq ayyr ayys ayyt ayyu ayyv ayyw ayyx ayyy ayyz ayza +ayzb ayzc ayzd ayze ayzf ayzg ayzh ayzi ayzj ayzk ayzl ayzm ayzn ayzo ayzp +ayzq ayzr ayzs ayzt ayzu ayzv ayzw ayzx ayzy ayzz azaa azab azac azad azae +azaf azag azah azai azaj azak azal azam azan azao azap azaq azar azas azat +azau azav azaw azax azay azaz azba azbb azbc azbd azbe azbf azbg azbh azbi +azbj azbk azbl azbm azbn azbo azbp azbq azbr azbs azbt azbu azbv azbw azbx +azby azbz azca azcb azcc azcd azce azcf azcg azch azci azcj azck azcl azcm +azcn azco azcp azcq azcr azcs azct azcu azcv azcw azcx azcy azcz azda azdb +azdc azdd azde azdf azdg azdh azdi azdj azdk azdl azdm azdn azdo azdp azdq +azdr azds azdt azdu azdv azdw azdx azdy azdz azea azeb azec azed azee azef +azeg azeh azei azej azek azel azem azen azeo azep azeq azer azes azet azeu +azev azew azex azey azez azfa azfb azfc azfd azfe azff azfg azfh azfi azfj +azfk azfl azfm azfn azfo azfp azfq azfr azfs azft azfu azfv azfw azfx azfy +azfz azga azgb azgc azgd azge azgf azgg azgh azgi azgj azgk azgl azgm azgn +azgo azgp azgq azgr azgs azgt azgu azgv azgw azgx azgy azgz azha azhb azhc +azhd azhe azhf azhg azhh azhi azhj azhk azhl azhm azhn azho azhp azhq azhr +azhs azht azhu azhv azhw azhx azhy azhz azia azib azic azid azie azif azig +azih azii azij azik azil azim azin azio azip aziq azir azis azit aziu aziv +aziw azix aziy aziz azja azjb azjc azjd azje azjf azjg azjh azji azjj azjk +azjl azjm azjn azjo azjp azjq azjr azjs azjt azju azjv azjw azjx azjy azjz +azka azkb azkc azkd azke azkf azkg azkh azki azkj azkk azkl azkm azkn azko +azkp azkq azkr azks azkt azku azkv azkw azkx azky azkz azla azlb azlc azld +azle azlf azlg azlh azli azlj azlk azll azlm azln azlo azlp azlq azlr azls +azlt azlu azlv azlw azlx azly azlz azma azmb azmc azmd azme azmf azmg azmh +azmi azmj azmk azml azmm azmn azmo azmp azmq azmr azms azmt azmu azmv azmw +azmx azmy azmz azna aznb aznc aznd azne aznf azng aznh azni aznj aznk aznl +aznm aznn azno aznp aznq aznr azns aznt aznu aznv aznw aznx azny aznz azoa +azob azoc azod azoe azof azog azoh azoi azoj azok azol azom azon azoo azop +azoq azor azos azot azou azov azow azox azoy azoz azpa azpb azpc azpd azpe +azpf azpg azph azpi azpj azpk azpl azpm azpn azpo azpp azpq azpr azps azpt +azpu azpv azpw azpx azpy azpz azqa azqb azqc azqd azqe azqf azqg azqh azqi +azqj azqk azql azqm azqn azqo azqp azqq azqr azqs azqt azqu azqv azqw azqx +azqy azqz azra azrb azrc azrd azre azrf azrg azrh azri azrj azrk azrl azrm +azrn azro azrp azrq azrr azrs azrt azru azrv azrw azrx azry azrz azsa azsb +azsc azsd azse azsf azsg azsh azsi azsj azsk azsl azsm azsn azso azsp azsq +azsr azss azst azsu azsv azsw azsx azsy azsz azta aztb aztc aztd azte aztf +aztg azth azti aztj aztk aztl aztm aztn azto aztp aztq aztr azts aztt aztu +aztv aztw aztx azty aztz azua azub azuc azud azue azuf azug azuh azui azuj +azuk azul azum azun azuo azup azuq azur azus azut azuu azuv azuw azux azuy +azuz azva azvb azvc azvd azve azvf azvg azvh azvi azvj azvk azvl azvm azvn +azvo azvp azvq azvr azvs azvt azvu azvv azvw azvx azvy azvz azwa azwb azwc +azwd azwe azwf azwg azwh azwi azwj azwk azwl azwm azwn azwo azwp azwq azwr +azws azwt azwu azwv azww azwx azwy azwz azxa azxb azxc azxd azxe azxf azxg +azxh azxi azxj azxk azxl azxm azxn azxo azxp azxq azxr azxs azxt azxu azxv +azxw azxx azxy azxz azya azyb azyc azyd azye azyf azyg azyh azyi azyj azyk +azyl azym azyn azyo azyp azyq azyr azys azyt azyu azyv azyw azyx azyy azyz +azza azzb azzc azzd azze azzf azzg azzh azzi azzj azzk azzl azzm azzn azzo +azzp azzq azzr azzs azzt azzu azzv azzw azzx azzy azzz baaa baab baac baad +baae baaf baag baah baai baaj baak baal baam baan baao baap baaq baar baas +baat baau baav baaw baax baay baaz baba babb babc babd babe babf babg babh +babi babj babk babl babm babn babo babp babq babr babs babt babu babv babw +babx baby babz baca bacb bacc bacd bace bacf bacg bach baci bacj back bacl +bacm bacn baco bacp bacq bacr bacs bact bacu bacv bacw bacx bacy bacz bada +badb badc badd bade badf badg badh badi badj badk badl badm badn bado badp +badq badr bads badt badu badv badw badx bady badz baea baeb baec baed baee +baef baeg baeh baei baej baek bael baem baen baeo baep baeq baer baes baet +baeu baev baew baex baey baez bafa bafb bafc bafd bafe baff bafg bafh bafi +bafj bafk bafl bafm bafn bafo bafp bafq bafr bafs baft bafu bafv bafw bafx +bafy bafz baga bagb bagc bagd bage bagf bagg bagh bagi bagj bagk bagl bagm +bagn bago bagp bagq bagr bags bagt bagu bagv bagw bagx bagy bagz baha bahb +bahc bahd bahe bahf bahg bahh bahi bahj bahk bahl bahm bahn baho bahp bahq +bahr bahs baht bahu bahv bahw bahx bahy bahz baia baib baic baid baie baif +baig baih baii baij baik bail baim bain baio baip baiq bair bais bait baiu +baiv baiw baix baiy baiz baja bajb bajc bajd baje bajf bajg bajh baji bajj +bajk bajl bajm bajn bajo bajp bajq bajr bajs bajt baju bajv bajw bajx bajy +bajz baka bakb bakc bakd bake bakf bakg bakh baki bakj bakk bakl bakm bakn +bako bakp bakq bakr baks bakt baku bakv bakw bakx baky bakz bala balb balc +bald bale balf balg balh bali balj balk ball balm baln balo balp balq balr +bals balt balu balv balw balx baly balz bama bamb bamc bamd bame bamf bamg +bamh bami bamj bamk baml bamm bamn bamo bamp bamq bamr bams bamt bamu bamv +bamw bamx bamy bamz bana banb banc band bane banf bang banh bani banj bank +banl banm bann bano banp banq banr bans bant banu banv banw banx bany banz +baoa baob baoc baod baoe baof baog baoh baoi baoj baok baol baom baon baoo +baop baoq baor baos baot baou baov baow baox baoy baoz bapa bapb bapc bapd +bape bapf bapg baph bapi bapj bapk bapl bapm bapn bapo bapp bapq bapr baps +bapt bapu bapv bapw bapx bapy bapz baqa baqb baqc baqd baqe baqf baqg baqh +baqi baqj baqk baql baqm baqn baqo baqp baqq baqr baqs baqt baqu baqv baqw +baqx baqy baqz bara barb barc bard bare barf barg barh bari barj bark barl +barm barn baro barp barq barr bars bart baru barv barw barx bary barz basa +basb basc basd base basf basg bash basi basj bask basl basm basn baso basp +basq basr bass bast basu basv basw basx basy basz bata batb batc batd bate +batf batg bath bati batj batk batl batm batn bato batp batq batr bats batt +batu batv batw batx baty batz baua baub bauc baud baue bauf baug bauh baui +bauj bauk baul baum baun bauo baup bauq baur baus baut bauu bauv bauw baux +bauy bauz bava bavb bavc bavd bave bavf bavg bavh bavi bavj bavk bavl bavm +bavn bavo bavp bavq bavr bavs bavt bavu bavv bavw bavx bavy bavz bawa bawb +bawc bawd bawe bawf bawg bawh bawi bawj bawk bawl bawm bawn bawo bawp bawq +bawr baws bawt bawu bawv baww bawx bawy bawz baxa baxb baxc baxd baxe baxf +baxg baxh baxi baxj baxk baxl baxm baxn baxo baxp baxq baxr baxs baxt baxu +baxv baxw baxx baxy baxz baya bayb bayc bayd baye bayf bayg bayh bayi bayj +bayk bayl baym bayn bayo bayp bayq bayr bays bayt bayu bayv bayw bayx bayy +bayz baza bazb bazc bazd baze bazf bazg bazh bazi bazj bazk bazl bazm bazn +bazo bazp bazq bazr bazs bazt bazu bazv bazw bazx bazy bazz bbaa bbab bbac +bbad bbae bbaf bbag bbah bbai bbaj bbak bbal bbam bban bbao bbap bbaq bbar +bbas bbat bbau bbav bbaw bbax bbay bbaz bbba bbbb diff --git a/camlp4/test/fixtures/if.ml b/camlp4/test/fixtures/if.ml new file mode 100644 index 0000000..3f9b452 --- /dev/null +++ b/camlp4/test/fixtures/if.ml @@ -0,0 +1,8 @@ +let x = if x then a else b in x + +let x = if StringSet.mem "*" sections then a else b in x + +let x = +if StringSet.mem "*" sections then fun _ -> true else + fun x -> StringSet.mem x sections +in x diff --git a/camlp4/test/fixtures/label.ml b/camlp4/test/fixtures/label.ml new file mode 100644 index 0000000..a60f367 --- /dev/null +++ b/camlp4/test/fixtures/label.ml @@ -0,0 +1 @@ +value f ~a:_ ?b:_ = (); diff --git a/camlp4/test/fixtures/lambda_free.ml b/camlp4/test/fixtures/lambda_free.ml new file mode 100644 index 0000000..4d6f135 --- /dev/null +++ b/camlp4/test/fixtures/lambda_free.ml @@ -0,0 +1,68 @@ +open Format; + +module S = Set.Make String; + +type term = + [ Lambda of string and term + | Atom of string + | App of term and term + | Opt of term and option term and term + ]; + +value free_vars = + let rec fv t env free = + match t with + [ Lambda x t -> fv t (S.add x env) free + | Atom x -> if S.mem x env then free else S.add x free + | App t1 t2 -> fv t1 env (fv t2 env free) + | Opt _ _ _ -> assert False ] + in fun t -> fv t S.empty S.empty; + +value print_set f s = do { + fprintf f "@[<2>{ "; + S.iter (fprintf f "%s@ ") s; + fprintf f "}@]"; +}; + +value t1 = Lambda "x" (App (Lambda "y" (App (Atom "y") (Atom "x"))) (Lambda "x" (Atom "x"))); +value t2 = Lambda "x" (App (Lambda "y" (App (Atom "y") (Atom "x"))) (Lambda "z" (Atom "z"))); +value t3 = Lambda "x" (App (Lambda "y" (App (Atom "y") (Atom "x"))) (Lambda "x" (Atom "z"))); +value t4 = Lambda "a" (App (Lambda "y" (App (Atom "y") (Atom "x"))) (Lambda "x" (Atom "z"))); + +printf "t1: %a@." print_set (free_vars t1); +printf "t2: %a@." print_set (free_vars t2); +printf "t3: %a@." print_set (free_vars t3); +printf "t4: %a@." print_set (free_vars t4); + +class fold ['accu] init = + object (o : 'self_type) + value accu : 'accu = init; + method accu = accu; + method term t = + match t with + [ Lambda x t -> (o#string x)#term t + | Atom x -> o#string x + | App t1 t2 -> (o#term t1)#term t2 + | Opt t1 ot t2 -> ((o#term t1)#option (fun o -> o#term) ot)#term t2 ]; + method string : string -> 'self_type = fun _ -> o; + method option : ! 'a. ('self_type -> 'a -> 'self_type) -> option 'a -> 'self_type = + fun f opt -> + match opt with + [ None -> o + | Some x -> f o x ]; + end; + +class fold_atoms ['accu] f init = + object (o : 'self_type) + inherit fold ['accu] init as super; + method term t = + match t with + [ Atom x -> {< accu = f x accu >} + | _ -> super#term t ]; + end; + +value t5 = Opt (Atom "a") (Some (Atom "b")) (Atom "c"); + +value atoms = ((new fold_atoms S.add S.empty)#term t5)#accu; + +printf "atoms: %a@." print_set atoms; diff --git a/camlp4/test/fixtures/loc-bug.ml b/camlp4/test/fixtures/loc-bug.ml new file mode 100644 index 0000000..2901e6f --- /dev/null +++ b/camlp4/test/fixtures/loc-bug.ml @@ -0,0 +1,3 @@ +#default_quotation "expr";; +Lwt.return + << 3 + >> diff --git a/camlp4/test/fixtures/macrotest.ml b/camlp4/test/fixtures/macrotest.ml new file mode 100644 index 0000000..023a5b4 --- /dev/null +++ b/camlp4/test/fixtures/macrotest.ml @@ -0,0 +1,70 @@ +DEFINE A = 42; +DEFINE B = 51; + +IFDEF A THEN + value a_should_be_present = B + 2; + print_int (a_should_be_present + 1); +ENDIF; + +print_int (a_should_be_present + 2); + +IFNDEF C THEN + print_int (a_should_be_present + 3); +ENDIF; + +IFNDEF C THEN + print_int (a_should_be_present + 4); +ELSE + print_int (c_should_not_be_present + 1); +ENDIF; + +IFDEF C THEN + print_int (c_should_not_be_present + 2); +ELSIF + print_int (A * a_should_be_present + 5); +ENDIF; + +IFDEF DNE THEN + print_int (c_should_not_be_present + 2); +ELSIF + print_int (A * a_should_be_present + 5); +ENDIF; + +IFDEF OPT THEN + print_int (c_should_not_be_present + 2); +ELSIF + print_int (A * a_should_be_present + 5); +ENDIF; + +value e = + IFDEF DNE THEN + print_int (c_should_not_be_present + 2) + ELSE + print_int (A * a_should_be_present + 5) + ENDIF; + +value f = + fun _ -> + IFDEF DNE THEN + print_int (c_should_not_be_present + 2) + ELSE + print_int (A * a_should_be_present + 5) + ENDIF; + +IFDEF A THEN + DEFINE Z = "ok"; +ELSE + DEFINE Z = "ko"; +ENDIF; + +Z; + +IFDEF DNE THEN + DEFINE Z = "ko2"; +ELSE + DEFINE Z = "ok2"; +ENDIF; + +Z; + +pouet; diff --git a/camlp4/test/fixtures/macrotest.mli b/camlp4/test/fixtures/macrotest.mli new file mode 100644 index 0000000..4912fd3 --- /dev/null +++ b/camlp4/test/fixtures/macrotest.mli @@ -0,0 +1,25 @@ +DEFINE A; +DEFINE B; + +IFDEF A THEN + value a_should_be_present : int; +ENDIF; + +IFNDEF C THEN + value b_should_be_present : int; +ENDIF; + +IFNDEF C THEN + value c_should_be_present : int; +ELSE + value a_should_NOT_be_present : int; +END; + +IFDEF C THEN + value b_should_NOT_be_present : int; +ELSE + value d_should_be_present : int; + value e_should_be_present : int; +ENDIF; + +value f_should_be_present : int; diff --git a/camlp4/test/fixtures/macrotest2.ml b/camlp4/test/fixtures/macrotest2.ml new file mode 100644 index 0000000..cb2d4cf --- /dev/null +++ b/camlp4/test/fixtures/macrotest2.ml @@ -0,0 +1,6 @@ +IFNDEF UNDEFINED_VARIABLE THEN + DEFINE SQUARE (x) = x * x ;; + DEFINE DOUBLE_SQUARE (x) = (SQUARE x) * 2 ;; +END;; + +Printf.printf "%d\n" (DOUBLE_SQUARE(42)) ;; diff --git a/camlp4/test/fixtures/macrotest3.ml b/camlp4/test/fixtures/macrotest3.ml new file mode 100644 index 0000000..ef618d2 --- /dev/null +++ b/camlp4/test/fixtures/macrotest3.ml @@ -0,0 +1,11 @@ +IFNDEF UNDEFINED_VARIABLE THEN + DEFINE UNDEFINED_VARIABLE + + IFDEF UNDEFINED_VARIABLE THEN + DEFINE SQUARE (x) = x * x ;; + DEFINE DOUBLE_SQUARE (x) = (SQUARE x) * 2 ;; + END +END;; + +Printf.printf "%d\n" (DOUBLE_SQUARE(42)) ;; + diff --git a/camlp4/test/fixtures/make_extend.ml b/camlp4/test/fixtures/make_extend.ml new file mode 100644 index 0000000..f2d625c --- /dev/null +++ b/camlp4/test/fixtures/make_extend.ml @@ -0,0 +1 @@ +<:expr< EXTEND G expr: [[ "foo" -> <:expr< foo >> ]]; END >>; diff --git a/camlp4/test/fixtures/match.ml b/camlp4/test/fixtures/match.ml new file mode 100644 index 0000000..9fb52cb --- /dev/null +++ b/camlp4/test/fixtures/match.ml @@ -0,0 +1,9 @@ +let x = + match y with + | A z -> z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z + | B l -> + (match l with + | [] -> () + | x::xs -> p x; self xs) + | C -> () +in x diff --git a/camlp4/test/fixtures/match_parser.ml b/camlp4/test/fixtures/match_parser.ml new file mode 100644 index 0000000..e053ee8 --- /dev/null +++ b/camlp4/test/fixtures/match_parser.ml @@ -0,0 +1,10 @@ +open Camlp4.PreCast; + +let _loc = Loc.ghost in +let e = <:expr< parser [: `"a" :] -> t >> in +let a = + match e with + [ <:expr< parser [: `$str:x$ :] -> t >> -> x + | _ -> assert False ] +in Format.printf "a: %S@." a; + diff --git a/camlp4/test/fixtures/meta_multi_term.ml b/camlp4/test/fixtures/meta_multi_term.ml new file mode 100644 index 0000000..35e96b2 --- /dev/null +++ b/camlp4/test/fixtures/meta_multi_term.ml @@ -0,0 +1,16 @@ +open Camlp4.PreCast; +value _loc = Loc.ghost; + +module Term = struct + type patt = + [ PApp of patt and patt + | PAny + | PVar of string + | POlb of string and expr ] + and expr = + [ EApp of expr and expr + | EVar of string + | ELam of patt and expr ]; +end; + +module MetaTerm = MetaGenerator Term; diff --git a/camlp4/test/fixtures/metalib.ml b/camlp4/test/fixtures/metalib.ml new file mode 100644 index 0000000..22dff11 --- /dev/null +++ b/camlp4/test/fixtures/metalib.ml @@ -0,0 +1,5 @@ +#load "camlp4of.cma";; +open Camlp4.PreCast;; +module M = Ast.Meta.Make(Ast.Meta.MetaGhostLoc);; +let ghost = Loc.ghost;; +M.Expr.meta_ctyp ghost <:ctyp@ghost< int >>;; diff --git a/camlp4/test/fixtures/method_private_virtual.ml b/camlp4/test/fixtures/method_private_virtual.ml new file mode 100644 index 0000000..6c0b94a --- /dev/null +++ b/camlp4/test/fixtures/method_private_virtual.ml @@ -0,0 +1,9 @@ +class virtual c1 = object method virtual private f : unit end;; +class virtual c2 = object method private virtual f : unit end;; + +<:str_item< class virtual c1 = object method virtual private f : unit; end >>;; +<:str_item< class virtual c2 = object method private virtual f : unit; end >>;; +<:str_item< class virtual c2 = object method $private:p$ virtual f : unit; end >>;; +<:str_item< class virtual c2 = object method virtual $private:p$ f : unit; end >>;; +<:str_item< class $virtual:v$ c2 [$t1$] = + object ($pat:self$) method virtual $private:p$ $lid:f$ : $t2$; end >>;; diff --git a/camlp4/test/fixtures/mod.ml b/camlp4/test/fixtures/mod.ml new file mode 100644 index 0000000..ca2b3e0 --- /dev/null +++ b/camlp4/test/fixtures/mod.ml @@ -0,0 +1,15 @@ +module type S = sig type t end +module F (A : S) = struct + type t2 = A.t + module A = A +end + +module A = struct type t = int end + +module type S3 = sig + module M : S +end + +module type S2 = S with type t = F(A).t2 + +module type S4 = S3 with module M = F(A).A diff --git a/camlp4/test/fixtures/mod2.ml b/camlp4/test/fixtures/mod2.ml new file mode 100644 index 0000000..c0a1667 --- /dev/null +++ b/camlp4/test/fixtures/mod2.ml @@ -0,0 +1,8 @@ +module type S = sig type t = 'a; end; +module F (A : S) = struct + type t2 = A.t; +end; + +module A = struct type t = int; end; + +module type S2 = S with type t = (F A).t2; diff --git a/camlp4/test/fixtures/operators.ml b/camlp4/test/fixtures/operators.ml new file mode 100644 index 0000000..467c37c --- /dev/null +++ b/camlp4/test/fixtures/operators.ml @@ -0,0 +1,7 @@ +let _ : int = 42 +let (+) = M.(+) +let (+) = M.(+) in 42 +let (+) : int -> int -> int = (+) +let (+) : int -> int -> int = (+) in 42 +let None = None +let None : int option = None diff --git a/camlp4/test/fixtures/operators.mli b/camlp4/test/fixtures/operators.mli new file mode 100644 index 0000000..af44530 --- /dev/null +++ b/camlp4/test/fixtures/operators.mli @@ -0,0 +1 @@ +val (+) : int -> int -> int diff --git a/camlp4/test/fixtures/original_syntax.ml b/camlp4/test/fixtures/original_syntax.ml new file mode 100644 index 0000000..bf08d56 --- /dev/null +++ b/camlp4/test/fixtures/original_syntax.ml @@ -0,0 +1,17 @@ +fun x when x <> 0 -> x / 42 +;; +object val virtual mutable x : int val mutable virtual y : int end +;; +- !r +;; +! -r +;; +-32 +;; +- - 32 +;; +!(r.b) +;; +(!r).b = !r.b +;; +let l : (unit -> int) list = [(fun _ -> 42); (fun _ -> 42)] diff --git a/camlp4/test/fixtures/outside-scope.ml b/camlp4/test/fixtures/outside-scope.ml new file mode 100644 index 0000000..6b8b80b --- /dev/null +++ b/camlp4/test/fixtures/outside-scope.ml @@ -0,0 +1,21 @@ +type t 'a = [ Nil | Cons of 'a and t 'a ]; + +module A : sig + value app_hd : t 'a -> ('a -> 'a) -> option 'a; +end = struct + value app_hd x f = + match x with + [ Nil -> None + | Cons x _ -> Some (f x) ]; +end; +open A; + +module M = struct + external mk_nil : unit -> t 'a = "%identity"; + value nil = mk_nil (); + (* value is_nil x = x = nil; *) +end; + +(* M.app_hd succ (M.Cons 1 M.Nil); *) +(* M.hd (M.Cons 1 M.Nil); *) +app_hd (M.nil : t 'a) (fun (x : int) -> (x : 'a)); diff --git a/camlp4/test/fixtures/parser.ml b/camlp4/test/fixtures/parser.ml new file mode 100644 index 0000000..7e41f35 --- /dev/null +++ b/camlp4/test/fixtures/parser.ml @@ -0,0 +1,61 @@ +open Camlp4.PreCast; +type t = [ A of t and t | B of string ]; +value lex = Lexer.mk (); + + (* value list0 symb = + let rec loop al = + parser + [ [: a = symb; s :] -> loop [a :: al] s + | [: :] -> al ] + in + parser [: a = loop [] :] -> List.rev a + ; + value list0sep symb sep = + let rec kont al = + parser + [ [: v = sep; a = symb; s :] -> kont [a :: al] s + | [: :] -> al ] + in + parser + [ [: a = symb; s :] -> List.rev (kont [a] s) + | [: :] -> [] ] + ; + value list1 symb = + let rec loop al = + parser + [ [: a = symb; s :] -> loop [a :: al] s + | [: :] -> al ] + in + parser [: a = symb; s :] -> List.rev (loop [a] s) + ; + value list1sep symb sep = + let rec kont al = + parser + [ [: v = sep; a = symb; s :] -> kont [a :: al] s + | [: :] -> al ] + in + parser [: a = symb; s :] -> List.rev (kont [a] s) + ; *) + +value list1 = + let rec self stream acc = + match stream with parser + [ [: `(EOI, _) :] -> acc + | [: `(LIDENT x, _); xs :] -> self xs (A acc (B x)) + | [: `(BLANKS _ | NEWLINE, _); xs :] -> self xs acc ] + in + parser [: `(LIDENT x, _); xs :] -> self xs (B x); +value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc ]; +(* value length _ _ = -1; *) +open Format; +try + let f = Sys.argv.(1) in + let () = printf "parsing...@." in + let a = list1 (lex (Loc.mk f) (Stream.of_channel (open_in f))) in + let () = printf "counting...@." in + let n = length a 0 in + printf "%d@." n +with e -> eprintf "error: %a@." Camlp4.ErrorHandler.print e; diff --git a/camlp4/test/fixtures/pp_let_in.ml b/camlp4/test/fixtures/pp_let_in.ml new file mode 100644 index 0000000..c616249 --- /dev/null +++ b/camlp4/test/fixtures/pp_let_in.ml @@ -0,0 +1,10 @@ +let i = "toto" in do { (let i = 42 in print_int i); print_string i }; +let i = "toto" in do { print_string i; let i = 42 in print_int i; print_int i }; +let i = "toto" in do { + (let i = 42 in print_int i); + let i = i ^ i; + let i = i ^ i; + print_string i; + print_string i; + let i = i ^ i; + print_string i }; diff --git a/camlp4/test/fixtures/pp_let_in2.ml b/camlp4/test/fixtures/pp_let_in2.ml new file mode 100644 index 0000000..7e9b349 --- /dev/null +++ b/camlp4/test/fixtures/pp_let_in2.ml @@ -0,0 +1 @@ +let i = "toto" in ((let i = 42 in print_int i); print_string i) diff --git a/camlp4/test/fixtures/pp_xml.ml b/camlp4/test/fixtures/pp_xml.ml new file mode 100644 index 0000000..986998c --- /dev/null +++ b/camlp4/test/fixtures/pp_xml.ml @@ -0,0 +1,31 @@ + +type xml = Elt of string * xml list | Pcdata of string + +let pp = Format.fprintf + +let rec print_elt f = + function + | Elt (tag, contents) -> + pp f "@[@[<%s>@,%a@]@,@]" + tag print_list_elts contents tag + | Pcdata s -> + Format.pp_print_string f s + +and print_list_elts f = + let rec loop = + function + | [] -> () + | x::xs -> (pp f "@,"; print_elt f x; loop xs) in + function + | [] -> () + | [x] -> print_elt f x + | x::xs -> (print_elt f x; loop xs) + +let tree = + Elt ("div", [ + Elt ("p", [Pcdata "a short text"]); + Elt ("p", [Pcdata "a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text"]) + ]) + +let () = Format.printf "%a@." print_elt tree + diff --git a/camlp4/test/fixtures/pprecordtyp.ml b/camlp4/test/fixtures/pprecordtyp.ml new file mode 100644 index 0000000..1b140af --- /dev/null +++ b/camlp4/test/fixtures/pprecordtyp.ml @@ -0,0 +1,26 @@ +open Camlp4.PreCast + +let _loc = Loc.mk "?" + +let base base fields ty = + let fields = List.fold_right (fun field acc -> + let c = <:ctyp< $lid:field$ : $uid:field$.record >> in + <:ctyp< $c$ ; $acc$ >>) fields <:ctyp< >> + in + <:module_binding< $uid:base$ : + sig type record = { + key : $ty$; + $fields$ + } end = struct + type record = { + key : $ty$; + $fields$ + } end + >> + +module CleanAst = Camlp4.Struct.CleanAst.Make(Ast) +let _ = + let b = base "b" ["f1"; "f2"] <:ctyp< int >> in + Camlp4.PreCast.Printers.OCaml.print_implem + ((new CleanAst.clean_ast)#str_item + <:str_item< module rec $b$ >>) diff --git a/camlp4/test/fixtures/pr4314.ml b/camlp4/test/fixtures/pr4314.ml new file mode 100644 index 0000000..9e6b23b --- /dev/null +++ b/camlp4/test/fixtures/pr4314.ml @@ -0,0 +1 @@ +(int_of_string "1" : unit); diff --git a/camlp4/test/fixtures/pr4314gram1.ml b/camlp4/test/fixtures/pr4314gram1.ml new file mode 100644 index 0000000..a83b073 --- /dev/null +++ b/camlp4/test/fixtures/pr4314gram1.ml @@ -0,0 +1,36 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value exp = G.Entry.mk "exp" ; +value prog = G.Entry.mk "prog" ; + +EXTEND G +exp: +[ "apply" + [ e1 = SELF; e2 = SELF -> + let p = Loc.dump in + let () = + Format.eprintf "e1: %a,@.e2: %a,@.e1-e2: %a,@._loc: %a@." + p e1 p e2 p (Loc.merge e1 e2) p _loc + in + _loc + ] +| "simple" + [ _ = LIDENT -> _loc ] +]; +prog: [[ e = exp; `EOI -> e ]]; +END ; + +(* and the following function: *) + +value parse_string entry s = +try + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + failwith "Syntax Error" +end ] ; + +parse_string prog "f x"; diff --git a/camlp4/test/fixtures/pr4314gram2.ml b/camlp4/test/fixtures/pr4314gram2.ml new file mode 100644 index 0000000..38a5222 --- /dev/null +++ b/camlp4/test/fixtures/pr4314gram2.ml @@ -0,0 +1,36 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value exp = G.Entry.mk "exp" ; +value prog = G.Entry.mk "prog" ; + +EXTEND G +exp: +[ "apply" + [ e1 = exp LEVEL "simple"; e2 = SELF -> + let p = Loc.dump in + let () = + Format.eprintf "e1: %a,@.e2: %a,@.e1-e2: %a,@._loc: %a@." + p e1 p e2 p (Loc.merge e1 e2) p _loc + in + _loc + ] +| "simple" + [ _ = LIDENT -> _loc ] +]; +prog: [[ e = exp; `EOI -> e ]]; +END ; + +(* and the following function: *) + +value parse_string entry s = +try + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + failwith "Syntax Error" +end ] ; + +parse_string prog "f x"; diff --git a/camlp4/test/fixtures/pr4314gram3.ml b/camlp4/test/fixtures/pr4314gram3.ml new file mode 100644 index 0000000..3298bcb --- /dev/null +++ b/camlp4/test/fixtures/pr4314gram3.ml @@ -0,0 +1,36 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value exp = G.Entry.mk "exp" ; +value prog = G.Entry.mk "prog" ; + +EXTEND G +exp: +[ "apply" + [ e1 = SELF; e2 = exp LEVEL "simple" -> + let p = Loc.dump in + let () = + Format.eprintf "e1: %a,@.e2: %a,@.e1-e2: %a,@._loc: %a@." + p e1 p e2 p (Loc.merge e1 e2) p _loc + in + _loc + ] +| "simple" + [ _ = LIDENT -> _loc ] +]; +prog: [[ e = exp; `EOI -> e ]]; +END ; + +(* and the following function: *) + +value parse_string entry s = +try + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + failwith "Syntax Error" +end ] ; + +parse_string prog "f x"; diff --git a/camlp4/test/fixtures/pr4314gram4.ml b/camlp4/test/fixtures/pr4314gram4.ml new file mode 100644 index 0000000..1c6712e --- /dev/null +++ b/camlp4/test/fixtures/pr4314gram4.ml @@ -0,0 +1,36 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value exp = G.Entry.mk "exp" ; +value prog = G.Entry.mk "prog" ; + +EXTEND G +exp: +[ "apply" + [ e1 = SELF; e2 = exp LEVEL "simple"; e3 = exp LEVEL "simple" -> + let p = Loc.dump in + let () = + Format.eprintf "e1: %a,@.e2: %a,@.e3: %a,@._loc: %a@." + p e1 p e2 p e3 p _loc + in + _loc + ] +| "simple" + [ _ = LIDENT -> _loc ] +]; +prog: [[ e = exp; `EOI -> e ]]; +END ; + +(* and the following function: *) + +value parse_string entry s = +try + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + failwith "Syntax Error" +end ] ; + +parse_string prog "f x y"; diff --git a/camlp4/test/fixtures/pr4314gram5.ml b/camlp4/test/fixtures/pr4314gram5.ml new file mode 100644 index 0000000..bd2fb11 --- /dev/null +++ b/camlp4/test/fixtures/pr4314gram5.ml @@ -0,0 +1,38 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value exp = G.Entry.mk "exp" ; +value prog = G.Entry.mk "prog" ; + +EXTEND G +exp: +[ "apply" +[ e1 = SELF; e2 = exp LEVEL "simple"; e3 = SELF -> + let p = Loc.dump in + let () = + Format.eprintf "e1: %a,@.e2: %a,@.e3: %a,@._loc: %a@." + p e1 p e2 p e3 p _loc + in + _loc + ] +| "simple" +[ x = LIDENT; y = LIDENT -> + let () = Format.eprintf "reduce expr simple (%S, %S) at %a@." x y Loc.dump _loc in _loc ] +]; +prog: [[ e = exp; `EOI -> e ]]; +END ; + +(* and the following function: *) + +value parse_string entry s = +try + print_endline s; + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + failwith "Syntax Error" +end ] ; + +parse_string prog "f1 f2 x1 x2 y1 y2"; diff --git a/camlp4/test/fixtures/pr4329.ml b/camlp4/test/fixtures/pr4329.ml new file mode 100644 index 0000000..72f2b78 --- /dev/null +++ b/camlp4/test/fixtures/pr4329.ml @@ -0,0 +1,50 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram; + +value ab_eoi = G.Entry.mk "ab_eoi" ; +value a_or_ab = G.Entry.mk "a_or_ab" ; +value a_or_ab_eoi = G.Entry.mk "a_or_ab_eoi" ; +value c_a_or_ab_eoi = G.Entry.mk "c_a_or_ab_eoi" ; + +EXTEND G +ab_eoi: [[ "a"; "b"; `EOI -> () ]]; +a_or_ab: [[ "a" -> () | "a"; "b" -> () ]]; +a_or_ab_eoi: [[ a_or_ab; `EOI -> () ]]; +c_a_or_ab_eoi: [[ "c"; a_or_ab; `EOI -> () ]]; +END ; + +value parse_string entry s = +try + G.parse_string entry (Loc.mk "") s +with [ Loc.Exc_located loc exn -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + (* failwith "Syntax Error" *) +end ] ; + +(* Consider the following syntax errors: *) +parse_string ab_eoi "a c" ; +(* File "", line 1, characters 2-3 +Stream.Error("illegal begin of ab_eoi") +Exception: Failure "Syntax Error". +--> "Illegal begin": at least the first symbol was correct +--> nevertheless, the reported position is correct +--> The message used to be: "b" then EOI expected after "a" in [ab_eoi] *) + +parse_string a_or_ab_eoi "a c" ; +(* File "", line 1, characters 0-1 +Stream.Error("illegal begin of a_or_ab_eoi") +Exception: Failure "Syntax Error". +--> "Illegal begin": at least the first non-terminal was correct +--> the reported position is weird +--> I think the message used to be either: "b" expected after "a" in +[a_or_ab] +or: EOI expected after [a_or_ab] in [a_or_ab_eoi] *) + +parse_string c_a_or_ab_eoi "c a c" ; +(* File "", line 1, characters 2-3 +Stream.Error("[a_or_ab] expected after \"c\" (in [c_a_or_ab_eoi])") +Exception: Failure "Syntax Error". +--> "[a_or_ab] expected": this is very confusing: there is a valid a_or_ab +there, namely "a" *) diff --git a/camlp4/test/fixtures/pr4330.ml b/camlp4/test/fixtures/pr4330.ml new file mode 100644 index 0000000..1959358 --- /dev/null +++ b/camlp4/test/fixtures/pr4330.ml @@ -0,0 +1,57 @@ +open Camlp4.PreCast ; +module G = Camlp4.PreCast.Gram ; + +value a = G.Entry.mk "a" ; +value a_eoi = G.Entry.mk "a_eoi" ; + +EXTEND G +a: [[ "one" -> 1 | x = a; "plus"; y = a -> x+y ]]; +a_eoi: [[ x = a; `EOI -> x ]]; +END ; + +(* and the following function: *) + +value parse_string entry s o = +try + Printf.eprintf "Parsing %S\n%!" s; + assert (o = Some (G.parse_string entry (Loc.mk "") s)) +with [ Loc.Exc_located loc exn when o <> None -> +begin + print_endline (Loc.to_string loc); + print_endline (Printexc.to_string exn); + assert (o = None) +end +| exn when o = None -> Printf.eprintf "Fail as expected\n%!" +| exn -> begin + Printf.eprintf "Unexpected exception: \n%!"; + print_endline (Printexc.to_string exn); + assert (o = None) +end ] ; + +(* The following is correct: *) + +parse_string a_eoi "one plus one" (Some 2); + +(* While all of the following inputs should be rejected because they are not *) +(* legal according to the grammar: *) + +parse_string a_eoi "one plus" None; +(* - : int = 1 *) +parse_string a_eoi "one plus plus" None; +(* - : int = 1 *) +parse_string a_eoi "one plus one plus" None; +(* - : int = 2 *) +parse_string a_eoi "one plus one plus plus" None; +(* - : int = 2 *) + +(* Curiously, you may only repeat the operator twice. If you specify it three +times, gramlib complains. *) + +parse_string a_eoi "one plus plus plus" None ; +(* File "", line 1, characters 9-13 *) +(* Stream.Error("EOI expected after [a] (in [a_eoi])") *) +(* Exception: Failure "Syntax Error". *) +parse_string a_eoi "one plus one plus plus plus" None ; +(* File "", line 1, characters 18-22 *) +(* Stream.Error("EOI expected after [a] (in [a_eoi])") *) +(* Exception: Failure "Syntax Error". *) diff --git a/camlp4/test/fixtures/pr4357.ml b/camlp4/test/fixtures/pr4357.ml new file mode 100644 index 0000000..2d84004 --- /dev/null +++ b/camlp4/test/fixtures/pr4357.ml @@ -0,0 +1,16 @@ +open Camlp4.PreCast + +let sample_expr _loc _loc_name s = + Printf.eprintf "file=%s line=%d offset=%d bol=%d\n%!" + (Loc.file_name _loc) + (Loc.start_line _loc) + (Loc.start_off _loc) + (Loc.start_bol _loc); + <:expr< $lid:s$ >> +;; + +Quotation.add + "sample" + Syntax.Quotation.DynAst.expr_tag + sample_expr +;; diff --git a/camlp4/test/fixtures/pr4357sample.ml b/camlp4/test/fixtures/pr4357sample.ml new file mode 100644 index 0000000..789bcb8 --- /dev/null +++ b/camlp4/test/fixtures/pr4357sample.ml @@ -0,0 +1,3 @@ +let u = "Hello";; +let s = <:sample>;; +print_string s diff --git a/camlp4/test/fixtures/pr4357sample2.ml b/camlp4/test/fixtures/pr4357sample2.ml new file mode 100644 index 0000000..f6fe8d0 --- /dev/null +++ b/camlp4/test/fixtures/pr4357sample2.ml @@ -0,0 +1,5 @@ +#default_quotation "sample";; +let u = "Hello";; +let s = <>;; +let s = <:sample>;; +print_string s diff --git a/camlp4/test/fixtures/pr4452.ml b/camlp4/test/fixtures/pr4452.ml new file mode 100644 index 0000000..bed7db7 --- /dev/null +++ b/camlp4/test/fixtures/pr4452.ml @@ -0,0 +1,24 @@ +open Camlp4.PreCast + +let _loc = Loc.mk "?" + +let base base fields ty = + let fields = List.fold_right (fun field acc -> + let c = <:ctyp< $lid:field$ : $uid:field$.record >> in + <:ctyp< $c$ ; $acc$ >>) fields <:ctyp< >> + in + <:module_binding< $uid:base$ : + sig type record = { + key : $ty$; + $fields$ + } end = struct + type record = { + key : $ty$; + $fields$ + } end + >> + +let _ = + let b = base "b" ["f1"; "f2"] <:ctyp< int >> in + Camlp4.PreCast.Printers.OCaml.print_implem + <:str_item< module rec $b$ >> diff --git a/camlp4/test/fixtures/private_row.ml b/camlp4/test/fixtures/private_row.ml new file mode 100644 index 0000000..53ada77 --- /dev/null +++ b/camlp4/test/fixtures/private_row.ml @@ -0,0 +1,27 @@ + + +module type Ops = sig + type expr + val eval : expr -> int + end + ;; + + +module Plus = struct + type 'a expr0 = [`Num of int | `Plus of 'a * 'a ] + module F(X : Ops with type expr = private ([> 'a expr0] as 'a)) = + struct + type expr = X.expr expr0 + let eval : expr -> int = function + `Num n -> n + |`Plus(e1,e2) -> X.eval e1 + X.eval e2 + end + module rec L : (Ops with type expr = L.expr expr0) = F(L) + end + ;; + + +open Printf +;; + +let _ = Printf.printf "%d\n%!" (Plus.L.eval (`Plus ((`Num 5),(`Num 2))));; diff --git a/camlp4/test/fixtures/rec.ml b/camlp4/test/fixtures/rec.ml new file mode 100644 index 0000000..1c74b24 --- /dev/null +++ b/camlp4/test/fixtures/rec.ml @@ -0,0 +1,2 @@ +(* rec.ml *) +value rec x = 42; diff --git a/camlp4/test/fixtures/seq.ml b/camlp4/test/fixtures/seq.ml new file mode 100644 index 0000000..dd563d4 --- /dev/null +++ b/camlp4/test/fixtures/seq.ml @@ -0,0 +1,1003 @@ +module M = struct + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; +end; diff --git a/camlp4/test/fixtures/seq2.ml b/camlp4/test/fixtures/seq2.ml new file mode 100644 index 0000000..d47c254 --- /dev/null +++ b/camlp4/test/fixtures/seq2.ml @@ -0,0 +1,3003 @@ +module M = struct + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; + foo bar; +end; diff --git a/camlp4/test/fixtures/simplify.ml b/camlp4/test/fixtures/simplify.ml new file mode 100644 index 0000000..d910641 --- /dev/null +++ b/camlp4/test/fixtures/simplify.ml @@ -0,0 +1,11 @@ +open Camlp4.PreCast + +let simplify = + object + inherit Ast.map as super + method expr e = + match super#expr e with + | <:expr< $x$ + 0 >> | <:expr< 0 + $x$ >> -> x + | x -> x + end +in AstFilters.register_str_item_filter simplify#str_item diff --git a/camlp4/test/fixtures/simplify_r.ml b/camlp4/test/fixtures/simplify_r.ml new file mode 100644 index 0000000..fa60135 --- /dev/null +++ b/camlp4/test/fixtures/simplify_r.ml @@ -0,0 +1,11 @@ +open Camlp4.PreCast; + +let simplify = + object + inherit Ast.map as super; + method expr e = + match super#expr e with + [ <:expr< $x$ + 0 >> | <:expr< 0 + $x$ >> -> x + | x -> x ]; + end +in AstFilters.register_str_item_filter simplify#str_item; diff --git a/camlp4/test/fixtures/stream-parser-bug.ml b/camlp4/test/fixtures/stream-parser-bug.ml new file mode 100644 index 0000000..6c17793 --- /dev/null +++ b/camlp4/test/fixtures/stream-parser-bug.ml @@ -0,0 +1,6 @@ +let foo = parser + | [< '42; ps >] -> + let ps = ps + 42 in + type_phrases ps + | [< >] -> [< >] + diff --git a/camlp4/test/fixtures/string.ml b/camlp4/test/fixtures/string.ml new file mode 100644 index 0000000..5b0e646 --- /dev/null +++ b/camlp4/test/fixtures/string.ml @@ -0,0 +1 @@ +"abc"; diff --git a/camlp4/test/fixtures/superfluous.ml b/camlp4/test/fixtures/superfluous.ml new file mode 100644 index 0000000..79b086b --- /dev/null +++ b/camlp4/test/fixtures/superfluous.ml @@ -0,0 +1,12 @@ +open Camlp4.PreCast;; +open Syntax;; + +let _loc = Loc.ghost;; +let st = <:str_item< >>;; +let e = <:expr< 1 >> +let bi = <:binding< x = 0 >>;; + +(* none of these holds due to superfluous StSem and StNil *) +assert (Ast.StSem (_loc, st, st) = <:str_item< $st$ $st$ >>);; +assert (Ast.StExp (_loc, e) = <:str_item< $exp:e$ >>);; +assert (Ast.StVal (_loc, bi) = <:str_item< let $bi$ >>);; diff --git a/camlp4/test/fixtures/transform-examples.ml b/camlp4/test/fixtures/transform-examples.ml new file mode 100644 index 0000000..0aea9c4 --- /dev/null +++ b/camlp4/test/fixtures/transform-examples.ml @@ -0,0 +1,3 @@ +<:expr< $x$ + $y$ - $z$ >> -> <:expr< plus_minus $x$ $y$ $z$ >> + +<< List.rev (List.rev $l$) >> -> l diff --git a/camlp4/test/fixtures/try.ml b/camlp4/test/fixtures/try.ml new file mode 100644 index 0000000..90c01a3 --- /dev/null +++ b/camlp4/test/fixtures/try.ml @@ -0,0 +1,6 @@ +try + let f = Sys.getenv "CAMLP4_DEBUG_FILE" + in + foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar +with Not_found -> stderr + diff --git a/camlp4/test/fixtures/tuple_as_retval.ml b/camlp4/test/fixtures/tuple_as_retval.ml new file mode 100644 index 0000000..1dd68e6 --- /dev/null +++ b/camlp4/test/fixtures/tuple_as_retval.ml @@ -0,0 +1,3 @@ +EXTEND Gram + abc: [ [ (x,y) = foo -> x+y ] ]; +END; diff --git a/camlp4/test/fixtures/type.ml b/camlp4/test/fixtures/type.ml new file mode 100644 index 0000000..f17cc50 --- /dev/null +++ b/camlp4/test/fixtures/type.ml @@ -0,0 +1,3 @@ +type t = [ A of int | B of t ]; +type t2 = [ A of int | B of t ]; +type t3 = [ A of int | B of t ]; diff --git a/camlp4/test/fixtures/type_decl.ml b/camlp4/test/fixtures/type_decl.ml new file mode 100644 index 0000000..8610ba2 --- /dev/null +++ b/camlp4/test/fixtures/type_decl.ml @@ -0,0 +1,22 @@ +module M = struct + type t = A of int * int * int * int * int * int * int * int * int * int + | B | B | B | B | B | B | B | B + and t2 = + | B | B | B | B | B | B | B | B + and t3 = + | B | B | B of a * a * a * a * a * a * a * a * a * a * a | B | B | B | B | B + and t4 = + | B | B | B | B | B | B | B | B + and t5 = + | B | B | B | B | B | B | B | B + and t6 = + | B | B | B | A of int * int * int * int * int * int * int * int * int * int * int * int * int * int * int * int * int * int * int | B | B | B | B | B + and t7 = + | B | B | B | B | B | B | B | B + and t8 = + | B | B | B | B | B | B | B | B + and t9 = + | B | B | B | B | B | B | B | B + and t10 = + | A of (a * a) +end diff --git a/camlp4/test/fixtures/unit.ml b/camlp4/test/fixtures/unit.ml new file mode 100644 index 0000000..52241df --- /dev/null +++ b/camlp4/test/fixtures/unit.ml @@ -0,0 +1,4 @@ +type t1 = ();; +type t2 = unit;; +let x : t1 = ();; +let y : t2 = ();; diff --git a/camlp4/test/fixtures/use.ml b/camlp4/test/fixtures/use.ml new file mode 100644 index 0000000..36e2f69 --- /dev/null +++ b/camlp4/test/fixtures/use.ml @@ -0,0 +1,4 @@ +(* use.ml *) +#use "test/fixtures/rec.ml"; +(* value use *) +value use = 3; diff --git a/camlp4/test/fixtures/where.o.ml b/camlp4/test/fixtures/where.o.ml new file mode 100644 index 0000000..8295d4a --- /dev/null +++ b/camlp4/test/fixtures/where.o.ml @@ -0,0 +1 @@ +let where = 42 diff --git a/camlp4/test/fixtures/where.r.ml b/camlp4/test/fixtures/where.r.ml new file mode 100644 index 0000000..e48c308 --- /dev/null +++ b/camlp4/test/fixtures/where.r.ml @@ -0,0 +1 @@ +x where x = 42; diff --git a/camlp4/unmaintained/Makefile b/camlp4/unmaintained/Makefile new file mode 100644 index 0000000..b6db075 --- /dev/null +++ b/camlp4/unmaintained/Makefile @@ -0,0 +1,20 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# The unmaintained directory +# + +include ../config/Makefile.cnf + +DIRS=format lefteval ocamllex olabl scheme sml + +include ../config/Makefile.base diff --git a/camlp4/unmaintained/compile/.cvsignore b/camlp4/unmaintained/compile/.cvsignore new file mode 100644 index 0000000..47817cc --- /dev/null +++ b/camlp4/unmaintained/compile/.cvsignore @@ -0,0 +1,4 @@ +*.fast +*.fast.opt +o_fast.ml +pa_o_fast.ml diff --git a/camlp4/unmaintained/compile/.depend b/camlp4/unmaintained/compile/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/compile/Makefile b/camlp4/unmaintained/compile/Makefile new file mode 100644 index 0000000..bd4078f --- /dev/null +++ b/camlp4/unmaintained/compile/Makefile @@ -0,0 +1,37 @@ + + +include ../config/Makefile.cnf + +INCLUDES=-I ../camlp4 -I ../lib +SRC=../etc/pa_o.ml ../etc/pa_op.ml # FIXME and why not pa_$D.ml? +D=o +COMP_OPT=-strict_parsing -e "Grammar.Entry.obj Pcaml.interf" -e "Grammar.Entry.obj Pcaml.implem" -e "Grammar.Entry.obj Pcaml.top_phrase" -e "Grammar.Entry.obj Pcaml.use_file" +CLEANFILES=pa_*_fast.ml *_fast.ml + +# FIXME +EXECUTABLES=#camlp4$D.fast + +include ../config/Makefile.base + +WARNINGS=Ay + +camlp4$D.fast: pa_$D_fast.cmo + rm -f camlp4$D.fast + cd ../camlp4; $(MAKE) CAMLP4=../compile/camlp4$D.fast CAMLP4M="../compile/pa_$D_fast.cmo ../meta/pr_dump.cmo" + +camlp4$D.fast.opt: pa_$D_fast.cmx + rm -f camlp4$D.fast.opt + cd ../camlp4; $(MAKE) ../compile/camlp4$D.fast.opt CAMLP4OPT=../compile/camlp4$D.fast.opt CAMLP4M="../compile/pa_$D_fast.cmx ../meta/pr_dump.cmx" + +pa_$D_fast.ml: comp_head.ml $D_fast.ml comp_trail.ml + cat $(SRC) | sed -e "s/Plexer.make_lexer *()/P.lexer_pos/" -e "/EXTEND/,/END/d" -e "/Grammar.Entry.of_parser/d" -e "/Grammar.Entry.gcreate/d" | cat comp_head.ml - $D_fast.ml comp_trail.ml > pa_$D_fast.ml + +$D_fast.ml: compile.cmo $(SRC) + echo '(* camlp4r *)' >$D_fast.ml + OTOP=$(OTOP) EXE=$(EXE) ./compile.sh $(COMP_OPT) $(SRC) >> $D_fast.ml + +install-local: + if test -f camlp4$D.fast.opt; then cp camlp4$D.fast.opt $(BINDIR)/camlp4$D.opt$(EXE); fi + for TARG in pa_$D_fast.cmi pa_$D_fast.cmo pa_$D_fast.cmx ; do if test -f $$TARG; then cp $$TARG "$(LIBDIR)/camlp4/."; fi; done + +include .depend diff --git a/camlp4/unmaintained/compile/comp_head.ml b/camlp4/unmaintained/compile/comp_head.ml new file mode 100644 index 0000000..cd62343 --- /dev/null +++ b/camlp4/unmaintained/compile/comp_head.ml @@ -0,0 +1,70 @@ +(* camlp4r q_MLast.cmo pa_extend.cmo *) + + +module P = + struct + value gloc bp strm = Grammar.loc_of_token_interval bp (Stream.count strm); + value list0 symb = + let rec loop al = + parser + [ [: a = symb; s :] -> loop [a :: al] s + | [: :] -> al ] + in + parser [: a = loop [] :] -> List.rev a + ; + value list0sep symb sep = + let rec kont al = + parser + [ [: v = sep; a = symb; s :] -> kont [a :: al] s + | [: :] -> al ] + in + parser + [ [: a = symb; s :] -> List.rev (kont [a] s) + | [: :] -> [] ] + ; + value list1 symb = + let rec loop al = + parser + [ [: a = symb; s :] -> loop [a :: al] s + | [: :] -> al ] + in + parser [: a = symb; s :] -> List.rev (loop [a] s) + ; + value list1sep symb sep = + let rec kont al = + parser + [ [: v = sep; a = symb; s :] -> kont [a :: al] s + | [: :] -> al ] + in + parser [: a = symb; s :] -> List.rev (kont [a] s) + ; + value option f = + parser + [ [: x = f :] -> Some x + | [: :] -> None ] + ; + value token (p_con, p_prm) = + if p_prm = "" then parser [: `(con, prm) when con = p_con :] -> prm + else parser [: `(con, prm) when con = p_con && prm = p_prm :] -> prm + ; + value orzero f f0 = + parser bp + [ [: x = f :] -> x + | [: x = f0 :] ep -> +(* +let (loc1, loc2) = Grammar.loc_of_token_interval bp ep in +let _ = do { Printf.eprintf "recovered or_zero at loc (%d, %d)\n" loc1 loc2; flush stderr } in +*) + x ] + ; + value error entry prev_symb symb = + symb ^ " expected" ^ + (if prev_symb = "" then "" else " after " ^ prev_symb) ^ + " (in [" ^ entry ^ "])" + ; + value lexer = Plexer.gmake(); + end +; + +(****************************************) + diff --git a/camlp4/unmaintained/compile/comp_trail.ml b/camlp4/unmaintained/compile/comp_trail.ml new file mode 100644 index 0000000..75f40ab --- /dev/null +++ b/camlp4/unmaintained/compile/comp_trail.ml @@ -0,0 +1,33 @@ +(* camlp4r pa_extend.cmo *) +(****************************************) + +value interf_p = + Grammar.Entry.of_parser Pcaml.gram "interf" interf_0 +; + +value implem_p = + Grammar.Entry.of_parser Pcaml.gram "implem" implem_0 +; + +value top_phrase_p = + Grammar.Entry.of_parser Pcaml.gram "top_phrase" top_phrase_0 +; + +value use_file_p = + Grammar.Entry.of_parser Pcaml.gram "use_file" use_file_0 +; + +EXTEND + interf: + [ [ x = interf_p -> x ] ] + ; + implem: + [ [ x = implem_p -> x ] ] + ; + top_phrase: + [ [ x = top_phrase_p -> x ] ] + ; + use_file: + [ [ x = use_file_p -> x ] ] + ; +END; diff --git a/camlp4/unmaintained/compile/compile.ml b/camlp4/unmaintained/compile/compile.ml new file mode 100644 index 0000000..b5e6ba5 --- /dev/null +++ b/camlp4/unmaintained/compile/compile.ml @@ -0,0 +1,574 @@ +(* camlp4r *) + + +open Gramext; + +value strict_parsing = ref False; +value keywords = ref []; + +value _loc = Loc.ghost; + +(* Watch the segmentation faults here! the compiled file must have been + loaded in camlp4 with the option pa_extend.cmo -meta_action. *) +value magic_act (act : Obj.t) : MLast.expr = Obj.magic act; + +(* Names of symbols for error messages; code borrowed to grammar.ml *) + +value rec name_of_symbol entry = + fun + [ Snterm e -> "[" ^ e.ename ^ "]" + | Snterml e l -> "[" ^ e.ename ^ " level " ^ l ^ "]" + | Sself | Snext -> "[" ^ entry.ename ^ "]" + | Stoken tok -> entry.egram.glexer.Token.tok_text tok + | _ -> "???" ] +; + +value rec name_of_symbol_failed entry = + fun + [ Slist0 s -> name_of_symbol_failed entry s + | Slist0sep s _ -> name_of_symbol_failed entry s + | Slist1 s -> name_of_symbol_failed entry s + | Slist1sep s _ -> name_of_symbol_failed entry s + | Sopt s -> name_of_symbol_failed entry s + | Stree t -> name_of_tree_failed entry t + | s -> name_of_symbol entry s ] +and name_of_tree_failed entry = + fun + [ Node {node = s; brother = bro; son = son} -> + let txt = name_of_symbol_failed entry s in + let txt = + match (s, son) with + [ (Sopt _, Node _) -> txt ^ " or " ^ name_of_tree_failed entry son + | _ -> txt ] + in + let txt = + match bro with + [ DeadEnd | LocAct _ _ -> txt + | _ -> txt ^ " or " ^ name_of_tree_failed entry bro ] + in + txt + | DeadEnd | LocAct _ _ -> "???" ] +; + +value tree_failed entry prev_symb tree = + let (s2, s3) = + let txt = name_of_tree_failed entry tree in + match prev_symb with + [ Slist0 s -> + let txt1 = name_of_symbol_failed entry s in + ("", txt1 ^ " or " ^ txt) + | Slist1 s -> + let txt1 = name_of_symbol_failed entry s in + ("", txt1 ^ " or " ^ txt) + | Slist0sep s sep -> + let txt1 = name_of_symbol_failed entry s in + ("", txt1 ^ " or " ^ txt) + | Slist1sep s sep -> + let txt1 = name_of_symbol_failed entry s in + ("", txt1 ^ " or " ^ txt) + | Sopt _ | Stree _ -> ("", txt) + | _ -> (name_of_symbol entry prev_symb, txt) ] + in + <:expr< + P.error $str:entry.ename$ $`str:s2$ $`str:s3$ + >> +; + +(* Compilation *) + +value rec find_act = + fun + [ DeadEnd -> failwith "find_act" + | LocAct act _ -> (magic_act act, 0) + | Node {son = son; brother = bro} -> + let (act, n) = try find_act son with [ Failure _ -> find_act bro ] in + (act, n + 1) ] +; + +value level_number e l = + match e.edesc with + [ Dlevels elevs -> + loop 0 elevs where rec loop n = + fun + [ [lev :: levs] -> if lev.lname = Some l then n else loop (n + 1) levs + | [] -> failwith ("level " ^ l ^ " not found in entry " ^ e.ename) ] + | Dparser _ -> 0 ] +; + +value nth_patt_of_act (e, n) = + let patt_list = + loop e where rec loop = + fun + [ <:expr< fun (_loc : Locaction.t) -> $_$ >> -> + [] + | <:expr< fun ($p$ : $_$) -> $e$ >> -> [p :: loop e] + | <:expr< fun $p$ -> $e$ >> -> [p :: loop e] + | _ -> failwith "nth_patt_of_act" ] + in + List.nth patt_list n +; + +value rec last_patt_of_act = + fun + [ <:expr< fun ($p$ : $_$) (_loc : Locaction.t) -> + $_$ >> -> p + | <:expr< fun $_$ -> $e$ >> -> last_patt_of_act e + | _ -> failwith "last_patt_of_act" ] +; + +#load "pr_r.cmo"; +value rec final_action = + fun + [ + <:expr< fun (_loc : Loc.t) -> ($e$ : $_$) >> -> e + | <:expr< fun $_$ -> $e$ >> -> final_action e + | ast -> do { + print_endline "final_action failed"; + Pcaml.print_implem.val [(MLast.StExp _loc ast, _loc)]; + failwith "final_action"; + } ] +; + +value parse_standard_symbol e rkont fkont ending_act = + <:expr< + match try Some ($e$ __strm) with [ Stream.Failure -> None ] with + [ Some $nth_patt_of_act ending_act$ -> $rkont$ + | _ -> $fkont$ ] + >> +; + +value parse_symbol_no_failure e rkont fkont ending_act = + <:expr< + let $nth_patt_of_act ending_act$ = + try $e$ __strm with [ Stream.Failure -> raise (Stream.Error "") ] + in + $rkont$ + >> +; + +value rec contain_loc = + fun + [ <:expr< $lid:s$ >> -> (s = "loc") || (s = "_loc") + | <:expr< $uid:_$ >> -> False + | <:expr< $str:_$ >> -> False + | <:expr< ($list:el$) >> -> List.exists contain_loc el + | <:expr< $e1$ $e2$ >> -> contain_loc e1 || contain_loc e2 + | _ -> True ] +; + +value gen_let_loc _loc e = + if contain_loc e then <:expr< let _loc = P.gloc bp __strm in $e$ >> else e +; + +value phony_entry = Grammar.Entry.obj Pcaml.implem; + +value rec parse_tree entry nlevn alevn (tree, fst_symb) act_kont kont = + match tree with + [ DeadEnd -> kont + | LocAct act _ -> + let act = magic_act act in + act_kont False act + | Node {node = Sself; son = LocAct act _; brother = bro} -> + let act = magic_act act in + let n = entry.ename ^ "_" ^ string_of_int alevn in + let e = + if strict_parsing.val || alevn = 0 || fst_symb then <:expr< $lid:n$ >> + else <:expr< P.orzero $lid:n$ $lid:entry.ename ^ "_0"$ >> + in + let p2 = + match bro with + [ DeadEnd -> kont + | _ -> parse_tree entry nlevn alevn (bro, fst_symb) act_kont kont ] + in + let p1 = act_kont True act in + parse_standard_symbol e p1 p2 (act, 0) + | Node {node = s; son = LocAct act _; brother = bro} -> + let act = magic_act act in + let p2 = parse_tree entry nlevn alevn (bro, fst_symb) act_kont kont in + let p1 = act_kont False act in + parse_symbol entry nlevn s p1 p2 (act, 0) + | Node {node = s; son = son; brother = bro} -> + let p2 = parse_tree entry nlevn alevn (bro, fst_symb) act_kont kont in + let p1 = + let err = + let txt = tree_failed entry s son in + <:expr< raise (Stream.Error $txt$) >> + in + match son with + [ Node {brother = DeadEnd} -> + parse_tree entry nlevn alevn (son, False) act_kont err + | _ -> + let p1 = + parse_tree entry nlevn alevn (son, True) act_kont + <:expr< raise Stream.Failure >> + in + <:expr< try $p1$ with [ Stream.Failure -> $err$ ] >> ] + in + parse_symbol entry nlevn s p1 p2 (find_act son) ] +and parse_symbol entry nlevn s rkont fkont ending_act = + match s with + [ Slist0 s -> + let e = <:expr< P.list0 $symbol_parser entry nlevn s$ >> in + parse_symbol_no_failure e rkont fkont ending_act + | Slist1 s -> + let e = <:expr< P.list1 $symbol_parser entry nlevn s$ >> in + parse_standard_symbol e rkont fkont ending_act + | Slist0sep s sep -> + let e = + <:expr< + P.list0sep $symbol_parser entry nlevn s$ + $symbol_parser entry nlevn sep$ >> + in + parse_symbol_no_failure e rkont fkont ending_act + | Slist1sep s sep -> + let e = + <:expr< + P.list1sep $symbol_parser entry nlevn s$ + $symbol_parser entry nlevn sep$ >> + in + parse_standard_symbol e rkont fkont ending_act + | Sopt s -> + let e = <:expr< P.option $symbol_parser entry nlevn s$ >> in + parse_symbol_no_failure e rkont fkont ending_act + | Stree tree -> + let kont = <:expr< raise Stream.Failure >> in + let act_kont _ act = gen_let_loc _loc (final_action act) in + let e = parse_tree phony_entry 0 0 (tree, True) act_kont kont in + parse_standard_symbol <:expr< fun __strm -> $e$ >> rkont fkont ending_act + | Snterm e -> + let n = + match e.edesc with + [ Dparser _ -> e.ename + | Dlevels _ -> e.ename ^ "_0" ] + in + parse_standard_symbol <:expr< $lid:n$ >> rkont fkont ending_act + | Snterml e l -> + let n = e.ename ^ "_" ^ string_of_int (level_number e l) in + parse_standard_symbol <:expr< $lid:n$ >> rkont fkont ending_act + | Sself -> + let n = entry.ename ^ "_0" in + parse_standard_symbol <:expr< $lid:n$ >> rkont fkont ending_act + | Snext -> + let n = entry.ename ^ "_" ^ string_of_int nlevn in + parse_standard_symbol <:expr< $lid:n$ >> rkont fkont ending_act + | Stoken tok -> + let _ = + do { + if fst tok = "" && not (List.mem (snd tok) keywords.val) then + keywords.val := [snd tok :: keywords.val] + else () + } + in + let p = + let patt = nth_patt_of_act ending_act in + let p_con = fst tok in + let p_prm = snd tok in + if snd tok = "" then + if fst tok = "ANY" then <:patt< (_, $patt$) >> + else <:patt< ($`str:p_con$, $patt$) >> + else + match patt with + [ <:patt< _ >> -> <:patt< ($`str:p_con$, $`str:p_prm$) >> + | _ -> <:patt< ($`str:p_con$, ($`str:p_prm$ as $patt$)) >> ] + in + <:expr< + match Stream.peek __strm with + [ Some $p$ -> do { Stream.junk __strm; $rkont$ } + | _ -> $fkont$ ] + >> + | _ -> + parse_standard_symbol <:expr< not_impl >> rkont fkont ending_act ] +and symbol_parser entry nlevn = + fun + [ Snterm e -> + let n = e.ename ^ "_0" in + <:expr< $lid:n$ >> + | Snterml e l -> + let n = e.ename ^ "_" ^ string_of_int (level_number e l) in + <:expr< $lid:n$ >> + | Snext -> + let n = entry.ename ^ "_" ^ string_of_int nlevn in + if strict_parsing.val then <:expr< $lid:n$ >> + else + let n0 = entry.ename ^ "_0" in + <:expr< P.orzero $lid:n$ $lid:n0$ >> + | Stoken tok -> + let _ = + do { + if fst tok = "" && not (List.mem (snd tok) keywords.val) then + keywords.val := [snd tok :: keywords.val] + else () + } + in + <:expr< P.token ($`str:fst tok$, $`str:snd tok$) >> + | Stree tree -> + let kont = <:expr< raise Stream.Failure >> in + let act_kont _ act = final_action act in + <:expr< + fun __strm -> + $parse_tree phony_entry 0 0 (tree, True) act_kont kont$ + >> + | _ -> + <:expr< aaa >> ] +; + +value rec start_parser_of_levels entry clevn levs = + let n = entry.ename ^ "_" ^ string_of_int clevn in + let next = entry.ename ^ "_" ^ string_of_int (clevn + 1) in + let p = <:patt< $lid:n$ >> in + match levs with + [ [] -> [Some (p, <:expr< fun __strm -> raise Stream.Failure >>)] + | [lev :: levs] -> + let pel = start_parser_of_levels entry (succ clevn) levs in + match lev.lprefix with + [ DeadEnd -> + let ncont = + if not strict_parsing.val && clevn = 0 then + entry.ename ^ "_gen_cont" + else entry.ename ^ "_" ^ string_of_int clevn ^ "_cont" + in + let curr = + <:expr< let a = $lid:next$ __strm in $lid:ncont$ bp a __strm >> + in + let curr = <:expr< let bp = Stream.count __strm in $curr$ >> in + let e = <:expr< fun __strm -> $curr$ >> in + let pel = if levs = [] then [] else pel in + [Some (p, e) :: pel] + | tree -> + let alevn = clevn in + let (kont, pel) = + match levs with + [ [] -> (<:expr< raise Stream.Failure >>, []) + | _ -> + let e = + match (lev.assoc, lev.lsuffix) with + [ (NonA, _) | (_, DeadEnd) -> <:expr< $lid:next$ __strm >> + | _ -> + let ncont = + entry.ename ^ "_" ^ string_of_int clevn ^ "_cont" + in + <:expr< + let a = $lid:next$ __strm in + $lid:ncont$ bp a __strm + >> ] + in + (e, pel) ] + in + let act_kont end_with_self act = + if lev.lsuffix = DeadEnd then gen_let_loc _loc (final_action act) + else + let ncont = entry.ename ^ "_" ^ string_of_int clevn ^ "_cont" in + gen_let_loc _loc + <:expr< $lid:ncont$ bp $final_action act$ __strm >> + in + let curr = + parse_tree entry (succ clevn) alevn (tree, True) act_kont kont + in + let curr = <:expr< let bp = Stream.count __strm in $curr$ >> in + let e = <:expr< fun __strm -> $curr$ >> in + [Some (p, e) :: pel] ] ] +; + +value rec continue_parser_of_levels entry clevn levs = + let n = entry.ename ^ "_" ^ string_of_int clevn ^ "_cont" in + let p = <:patt< $lid:n$ >> in + match levs with + [ [] -> [None] + | [lev :: levs] -> + let pel = continue_parser_of_levels entry (succ clevn) levs in + match lev.lsuffix with + [ DeadEnd -> + [None :: pel] + | tree -> + let alevn = + match lev.assoc with + [ LeftA | NonA -> succ clevn + | RightA -> clevn ] + in + let (kont, pel) = + match levs with + [ [] -> (<:expr< a__ >>, []) + | _ -> (<:expr< a__ >>, pel) ] + in + let act_kont end_with_self act = + let p = last_patt_of_act act in + match lev.assoc with + [ RightA | NonA -> + <:expr< + let $p$ = a__ in + $gen_let_loc _loc (final_action act)$ + >> + | LeftA -> + let ncont = + entry.ename ^ "_" ^ string_of_int clevn ^ "_cont" + in + gen_let_loc _loc + <:expr< + let $p$ = a__ in + $lid:ncont$ bp $final_action act$ __strm + >> ] + in + let curr = + parse_tree entry (succ clevn) alevn (tree, True) act_kont kont + in + let e = <:expr< fun bp a__ __strm -> $curr$ >> in + [Some (p, e) :: pel] ] ] +; + +value continue_parser_of_levels_again entry levs = + let n = entry.ename ^ "_gen_cont" in + let e = + loop <:expr< a__ >> 0 levs where rec loop var levn = + fun + [ [] -> <:expr< if x == a__ then x else $lid:n$ bp x __strm >> + | [lev :: levs] -> + match lev.lsuffix with + [ DeadEnd -> loop var (levn + 1) levs + | _ -> + let n = entry.ename ^ "_" ^ string_of_int levn ^ "_cont" in + let rest = loop <:expr< x >> (levn + 1) levs in + <:expr< let x = $lid:n$ bp $var$ __strm in $rest$ >> ] ] + in + (<:patt< $lid:n$ >>, <:expr< fun bp a__ __strm -> $e$ >>) +; + +value empty_entry ename = + let p = <:patt< $lid:ename$ >> in + let e = + <:expr< + fun __strm -> + raise (Stream.Error $str:"entry [" ^ ename ^ "] is empty"$) >> + in + [Some (p, e)] +; + +value start_parser_of_entry entry = + match entry.edesc with + [ Dlevels [] -> empty_entry entry.ename + | Dlevels elev -> start_parser_of_levels entry 0 elev + | Dparser p -> [] ] +; + +value continue_parser_of_entry entry = + match entry.edesc with + [ Dlevels elev -> continue_parser_of_levels entry 0 elev + | Dparser p -> [] ] +; + +value continue_parser_of_entry_again entry = + if strict_parsing.val then [] + else + match entry.edesc with + [ Dlevels ([_; _ :: _] as levs) -> + [continue_parser_of_levels_again entry levs] + | _ -> [] ] +; + +value rec list_alternate l1 l2 = + match (l1, l2) with + [ ([x1 :: l1], [x2 :: l2]) -> [x1; x2 :: list_alternate l1 l2] + | ([], l2) -> l2 + | (l1, []) -> l1 ] +; + +value compile_entry entry = + let pel1 = start_parser_of_entry entry in + let pel2 = continue_parser_of_entry entry in + let pel = list_alternate pel1 pel2 in + List.fold_right + (fun pe list -> + match pe with + [ Some pe -> [pe :: list] + | None -> list ]) + pel (continue_parser_of_entry_again entry) +; + +(* get all entries connected together *) + +value rec scan_tree list = + fun + [ Node {node = n; son = son; brother = bro} -> + let list = scan_symbol list n in + let list = scan_tree list son in + let list = scan_tree list bro in + list + | LocAct _ _ | DeadEnd -> list ] +and scan_symbol list = + fun + [ Snterm e -> scan_entry list e + | Snterml e l -> scan_entry list e + | Slist0 s -> scan_symbol list s + | Slist0sep s sep -> scan_symbol (scan_symbol list s) sep + | Slist1 s -> scan_symbol list s + | Slist1sep s sep -> scan_symbol (scan_symbol list s) sep + | Sopt s -> scan_symbol list s + | Stree t -> scan_tree list t + | Smeta _ _ _ | Sself | Snext | Stoken _ -> list ] +and scan_level list lev = + let list = scan_tree list lev.lsuffix in + let list = scan_tree list lev.lprefix in + list +and scan_levels list levs = List.fold_left scan_level list levs +and scan_entry list entry = + if List.memq entry list then list + else + match entry.edesc with + [ Dlevels levs -> scan_levels [entry :: list] levs + | Dparser _ -> list ] +; + +value all_entries_in_graph list entry = + List.rev (scan_entry list entry) +; + +(* main *) + +value entries = ref []; + +value rec list_mem_right_assoc x = + fun + [ [] -> False + | [(a, b) :: l] -> x = b || list_mem_right_assoc x l ] +; + +value rec expr_list = + fun + [ [] -> <:expr< [] >> + | [x :: l] -> <:expr< [$`str:x$ :: $expr_list l$] >> ] +; + +value compile () = + let _ = do { keywords.val := []; } in + let list = List.fold_left all_entries_in_graph [] entries.val in + let list = + List.filter (fun e -> List.memq e list) entries.val @ + List.filter (fun e -> not (List.memq e entries.val)) list + in + let list = + let set = ref [] in + List.fold_right + (fun entry list -> + if List.mem entry.ename set.val then + list + else do { set.val := [entry.ename :: set.val]; [entry :: list] }) + list [] + in + let pell = List.map compile_entry list in + let pel = List.flatten pell in + let si1 = <:str_item< value rec $list:pel$ >> in + let si2 = + let list = List.sort compare keywords.val in + <:str_item< + List.iter (fun kw -> P.lexer.Token.tok_using ("", kw)) + $expr_list list$ + >> + in + let loc = Loc.ghost in + ([(si1, loc); (si2, loc)], False) +; + +Pcaml.parse_implem.val := fun _ _ -> compile (); + +Pcaml.add_option "-strict_parsing" (Arg.Set strict_parsing) + "Don't generate error recovering by trying continuations or first levels" +; diff --git a/camlp4/unmaintained/compile/compile.sh b/camlp4/unmaintained/compile/compile.sh new file mode 100755 index 0000000..a2f4f77 --- /dev/null +++ b/camlp4/unmaintained/compile/compile.sh @@ -0,0 +1,27 @@ +#!/bin/sh -e + +ARGS= +FILES= +ENTRIES= +while test "" != "$1"; do + case $1 in + -e) + shift; + if test "$ENTRIES" != ""; then ENTRIES="$ENTRIES; "; fi + ENTRIES="$ENTRIES$1";; + *.ml*) FILES="$FILES $1";; + *) ARGS="$ARGS $1";; + esac + shift +done + +cat $FILES | sed -e 's/Pcaml.parse_i.*$//' > tmp.ml +echo "Compile.entries.val := [$ENTRIES];" >> tmp.ml +> tmp.mli +set -x +$OTOP/boot/ocamlrun$EXE $OTOP/boot/ocamlc -I $OTOP/boot -c tmp.mli +$OTOP/boot/ocamlrun$EXE ../boot/camlp4boot$EXE -meta_action tmp.ml -o tmp.ppo +$OTOP/boot/ocamlrun$EXE $OTOP/boot/ocamlc -I $OTOP/boot -I ../lib -I ../camlp4 -c -impl tmp.ppo +rm tmp.ppo +> tmp.null +$OTOP/boot/ocamlrun$EXE ../camlp4/camlp4$EXE ./compile.cmo ./tmp.cmo ../etc/pr_r.cmo ../etc/pr_rp.cmo $ARGS -sep "\n\n" -impl tmp.null && rm tmp.* diff --git a/camlp4/unmaintained/etc/.cvsignore b/camlp4/unmaintained/etc/.cvsignore new file mode 100644 index 0000000..50d8a8e --- /dev/null +++ b/camlp4/unmaintained/etc/.cvsignore @@ -0,0 +1,7 @@ +*.cm[oia] +camlp4o +camlp4sch +camlp4o.opt +version.sh +mkcamlp4.sh +mkcamlp4.mpw diff --git a/camlp4/unmaintained/etc/.depend b/camlp4/unmaintained/etc/.depend new file mode 100644 index 0000000..863adc1 --- /dev/null +++ b/camlp4/unmaintained/etc/.depend @@ -0,0 +1,6 @@ +parserify.cmo: parserify.cmi +parserify.cmx: parserify.cmi +pr_op_main.cmo: parserify.cmi +pr_op_main.cmx: parserify.cmx +pr_rp_main.cmo: parserify.cmi +pr_rp_main.cmx: parserify.cmx diff --git a/camlp4/unmaintained/etc/Makefile b/camlp4/unmaintained/etc/Makefile new file mode 100644 index 0000000..196dd2b --- /dev/null +++ b/camlp4/unmaintained/etc/Makefile @@ -0,0 +1,62 @@ + + +include ../config/Makefile.cnf + +INCLUDES=-I ../camlp4 -I ../lib -I ../meta -I $(OTOP)/lex -I $(OTOP)/parsing +OBJS=q_phony.cmo pa_o.cmo pa_op.cmo pa_oop.cmo pa_ru.cmo pa_extfun.cmo pa_fstream.cmo pa_ifdef.cmo pr_r.cmo pr_rp.cmo pr_o.cmo pr_op.cmo pr_extend.cmo pr_extfun.cmo pr_null.cmo pr_depend.cmo genTraversal.cmo fi_exc_tracer.cmo +INTF=pa_o.cmi +CAMLP4OM=pa_o.cmo pa_op.cmo ../meta/pr_dump.cmo +CAMLP4OMX=$(CAMLP4OM:.cmo=.cmx) +EXECUTABLES=camlp4o + +include ../config/Makefile.base + +all-local: mkcamlp4.sh + +pr_rp.cmo: parserify.cmo pr_rp_main.cmo + $(OCAMLC) parserify.cmo pr_rp_main.cmo -a -o $@ + +pr_op.cmo: parserify.cmo pr_op_main.cmo + $(OCAMLC) parserify.cmo pr_op_main.cmo -a -o $@ + +pr_rp.cmx: parserify.cmx pr_rp_main.cmx + $(OCAMLOPT) parserify.cmx pr_rp_main.cmx -a -o pr_rp.cmxa + mv pr_rp.cmxa pr_rp.cmx + mv pr_rp.$(A) pr_rp.$(O) + +pr_op.cmx: parserify.cmx pr_op_main.cmx + $(OCAMLOPT) parserify.cmx pr_op_main.cmx -a -o pr_op.cmxa + mv pr_op.cmxa pr_op.cmx + mv pr_op.$(A) pr_op.$(O) + +camlp4o$(EXE): ../camlp4/camlp4$(EXE) $(CAMLP4OM) + rm -f camlp4o$(EXE) + cd ../camlp4; $(MAKE) CAMLP4=../etc/camlp4o$(EXE) CAMLP4M="-I ../etc $(CAMLP4OM)" + +camlp4o.opt: $(CAMLP4OMX) + rm -f camlp4o.opt + cd ../camlp4; $(MAKE) ../etc/camlp4o.opt CAMLP4OPT=../etc/camlp4o.opt CAMLP4M="-I ../etc $(CAMLP4OMX)" + +mkcamlp4.sh: mkcamlp4.sh.tpl version.sh + sed -e "s!LIBDIR!$(LIBDIR)!g" -e "/define VERSION/r version.sh" \ + mkcamlp4.sh.tpl > mkcamlp4.sh + +version.sh : $(OTOP)/VERSION + echo "VERSION=\"`head -1 ../VERSION`\"" >version.sh + +install-local: + -$(MKDIR) "$(LIBDIR)/camlp4" "$(BINDIR)" + cp $(OBJS) "$(LIBDIR)/camlp4/." + cp $(INTF) "$(LIBDIR)/camlp4/." + cp camlp4o$(EXE) "$(BINDIR)/." + if test -f camlp4o.opt; then \ + cp camlp4o.opt "$(BINDIR)/camlp4o.opt$(EXE)"; \ + cp $(OBJSX) "$(LIBDIR)/camlp4/."; \ + for file in $(OBJSX); do \ + cp "`echo $$file | sed -e 's/\.cmx$$/.$(O)/'`" "$(LIBDIR)/camlp4/."; \ + done ; \ + fi + cp mkcamlp4.sh "$(BINDIR)/mkcamlp4" + chmod a+x "$(BINDIR)/mkcamlp4" + +include .depend diff --git a/camlp4/unmaintained/etc/pa_fstream.ml b/camlp4/unmaintained/etc/pa_fstream.ml new file mode 100644 index 0000000..e5027b5 --- /dev/null +++ b/camlp4/unmaintained/etc/pa_fstream.ml @@ -0,0 +1,163 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) + + +open Pcaml; + +type spat_comp = + [ SpTrm of Loc.t and MLast.patt and option MLast.expr + | SpNtr of Loc.t and MLast.patt and MLast.expr + | SpStr of Loc.t and MLast.patt ] +; +type sexp_comp = + [ SeTrm of Loc.t and MLast.expr + | SeNtr of Loc.t and MLast.expr ] +; + +(* parsers *) + +value strm_n = "__strm"; +value next_fun _loc = <:expr< Fstream.next >>; + +value rec pattern_eq_expression p e = + match (p, e) with + [ (<:patt< $lid:a$ >>, <:expr< $lid:b$ >>) -> a = b + | (<:patt< $uid:a$ >>, <:expr< $uid:b$ >>) -> a = b + | (<:patt< $p1$ $p2$ >>, <:expr< $e1$ $e2$ >>) -> + pattern_eq_expression p1 e1 && pattern_eq_expression p2 e2 + | (<:patt< ($list:pl$) >>, <:expr< ($list:el$) >>) -> + loop pl el where rec loop pl el = + match (pl, el) with + [ ([p :: pl], [e :: el]) -> + pattern_eq_expression p e && loop pl el + | ([], []) -> True + | _ -> False ] + | _ -> False ] +; + +value stream_pattern_component skont = + fun + [ SpTrm _loc p wo -> + let p = <:patt< Some ($p$, $lid:strm_n$) >> in + if wo = None && pattern_eq_expression p skont then + <:expr< $next_fun _loc$ $lid:strm_n$ >> + else + <:expr< match $next_fun _loc$ $lid:strm_n$ with + [ $p$ $when:wo$ -> $skont$ + | _ -> None ] >> + | SpNtr _loc p e -> + let p = <:patt< Some ($p$, $lid:strm_n$) >> in + if pattern_eq_expression p skont then <:expr< $e$ $lid:strm_n$ >> + else + <:expr< match $e$ $lid:strm_n$ with + [ $p$ -> $skont$ + | _ -> None ] >> + | SpStr _loc p -> + <:expr< let $p$ = $lid:strm_n$ in $skont$ >> ] +; + +value rec stream_pattern _loc epo e = + fun + [ [] -> + let e = + match epo with + [ Some ep -> <:expr< let $ep$ = Fstream.count $lid:strm_n$ in $e$ >> + | None -> e ] + in + <:expr< Some ($e$, $lid:strm_n$) >> + | [spc :: spcl] -> + let skont = stream_pattern _loc epo e spcl in + stream_pattern_component skont spc ] +; + +value rec parser_cases _loc = + fun + [ [] -> <:expr< None >> + | [(spcl, epo, e) :: spel] -> + match parser_cases _loc spel with + [ <:expr< None >> -> stream_pattern _loc epo e spcl + | pc -> + <:expr< match $stream_pattern _loc epo e spcl$ with + [ Some _ as x -> x + | None -> $pc$ ] >> ] ] +; + +value cparser_match _loc me bpo pc = + let pc = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >> + | None -> pc ] + in + <:expr< let ($lid:strm_n$ : Stream.t _) = $me$ in $e$ >> +; + +value cparser _loc bpo pc = + let e = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Fstream.count $lid:strm_n$ in $e$ >> + | None -> e ] + in + let p = <:patt< ($lid:strm_n$ : Fstream.t _) >> in <:expr< fun $p$ -> $e$ >> +; + +(* streams *) + +value slazy _loc x = <:expr< fun () -> $x$ >>; + +value rec cstream _loc = + fun + [ [] -> <:expr< Fstream.nil >> + | [SeTrm _loc e :: sel] -> + let e2 = cstream _loc sel in + let x = <:expr< Fstream.cons $e$ $e2$ >> in + <:expr< Fstream.flazy $slazy _loc x$ >> + | [SeNtr _loc e] -> + e + | [SeNtr _loc e :: sel] -> + let e2 = cstream _loc sel in + let x = <:expr< Fstream.app $e$ $e2$ >> in + <:expr< Fstream.flazy $slazy _loc x$ >> ] +; + +EXTEND + GLOBAL: expr; + expr: LEVEL "top" + [ [ "fparser"; po = OPT ipatt; "["; pcl = LIST0 parser_case SEP "|"; "]" -> + <:expr< $cparser _loc po pcl$ >> + | "fparser"; po = OPT ipatt; pc = parser_case -> + <:expr< $cparser _loc po [pc]$ >> + | "match"; e = SELF; "with"; "parser"; po = OPT ipatt; "["; + pcl = LIST0 parser_case SEP "|"; "]" -> + <:expr< $cparser_match _loc e po pcl$ >> + | "match"; e = SELF; "with"; "parser"; po = OPT ipatt; + pc = parser_case -> + <:expr< $cparser_match _loc e po [pc]$ >> ] ] + ; + parser_case: + [ [ "[:"; sp = stream_patt; ":]"; po = OPT ipatt; "->"; e = expr -> + (sp, po, e) ] ] + ; + stream_patt: + [ [ spc = stream_patt_comp -> [spc] + | spc = stream_patt_comp; ";"; sp = LIST1 stream_patt_comp SEP ";" -> + [spc :: sp] + | -> [] ] ] + ; + stream_patt_comp: + [ [ "`"; p = patt; eo = OPT [ "when"; e = expr -> e ] -> SpTrm _loc p eo + | p = patt; "="; e = expr -> SpNtr _loc p e + | p = patt -> SpStr _loc p ] ] + ; + ipatt: + [ [ i = LIDENT -> <:patt< $lid:i$ >> ] ] + ; + expr: LEVEL "simple" + [ [ "fstream"; "[:"; se = LIST0 stream_expr_comp SEP ";"; ":]" -> + <:expr< $cstream _loc se$ >> ] ] + ; + stream_expr_comp: + [ [ "`"; e = expr -> SeTrm _loc e + | e = expr -> SeNtr _loc e ] ] + ; +END; diff --git a/camlp4/unmaintained/etc/pa_ifdef.ml b/camlp4/unmaintained/etc/pa_ifdef.ml new file mode 100644 index 0000000..0665263 --- /dev/null +++ b/camlp4/unmaintained/etc/pa_ifdef.ml @@ -0,0 +1,91 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) + + +(* This module is deprecated since version 3.07; use pa_macro.ml instead *) + +value _ = + prerr_endline "Warning: pa_ifdef is deprecated since OCaml 3.07. Use pa_macro instead." +; + +type item_or_def 'a = + [ SdStr of 'a | SdDef of string | SdUnd of string | SdNop ] +; + +value list_remove x l = + List.fold_right (fun e l -> if e = x then l else [e :: l]) l [] +; + +value defined = ref ["OCAML_308"; "OCAML_307"; "OCAML_305"; "CAMLP4_300"; "NEWSEQ"]; +value define x = defined.val := [x :: defined.val]; +value undef x = defined.val := list_remove x defined.val; + +EXTEND + GLOBAL: Pcaml.expr Pcaml.str_item Pcaml.sig_item; + Pcaml.expr: LEVEL "top" + [ [ "ifdef"; c = UIDENT; "then"; e1 = Pcaml.expr; "else"; + e2 = Pcaml.expr -> + if List.mem c defined.val then e1 else e2 + | "ifndef"; c = UIDENT; "then"; e1 = Pcaml.expr; "else"; + e2 = Pcaml.expr -> + if List.mem c defined.val then e2 else e1 ] ] + ; + Pcaml.str_item: FIRST + [ [ x = def_undef_str -> + match x with + [ SdStr si -> si + | SdDef x -> do { define x; <:str_item< declare end >> } + | SdUnd x -> do { undef x; <:str_item< declare end >> } + | SdNop -> <:str_item< declare end >> ] ] ] + ; + def_undef_str: + [ [ "ifdef"; c = UIDENT; "then"; e1 = str_item_def_undef; + "else"; e2 = str_item_def_undef -> + if List.mem c defined.val then e1 else e2 + | "ifdef"; c = UIDENT; "then"; e1 = str_item_def_undef -> + if List.mem c defined.val then e1 else SdNop + | "ifndef"; c = UIDENT; "then"; e1 = str_item_def_undef; + "else"; e2 = str_item_def_undef -> + if List.mem c defined.val then e2 else e1 + | "ifndef"; c = UIDENT; "then"; e1 = str_item_def_undef -> + if List.mem c defined.val then SdNop else e1 + | "define"; c = UIDENT -> SdDef c + | "undef"; c = UIDENT -> SdUnd c ] ] + ; + str_item_def_undef: + [ [ d = def_undef_str -> d + | si = Pcaml.str_item -> SdStr si ] ] + ; + Pcaml.sig_item: FIRST + [ [ x = def_undef_sig -> + match x with + [ SdStr si -> si + | SdDef x -> do { define x; <:sig_item< declare end >> } + | SdUnd x -> do { undef x; <:sig_item< declare end >> } + | SdNop -> <:sig_item< declare end >> ] ] ] + ; + def_undef_sig: + [ [ "ifdef"; c = UIDENT; "then"; e1 = sig_item_def_undef; + "else"; e2 = sig_item_def_undef -> + if List.mem c defined.val then e1 else e2 + | "ifdef"; c = UIDENT; "then"; e1 = sig_item_def_undef -> + if List.mem c defined.val then e1 else SdNop + | "ifndef"; c = UIDENT; "then"; e1 = sig_item_def_undef; + "else"; e2 = sig_item_def_undef -> + if List.mem c defined.val then e2 else e1 + | "ifndef"; c = UIDENT; "then"; e1 = sig_item_def_undef -> + if List.mem c defined.val then SdNop else e1 + | "define"; c = UIDENT -> SdDef c + | "undef"; c = UIDENT -> SdUnd c ] ] + ; + sig_item_def_undef: + [ [ d = def_undef_sig -> d + | si = Pcaml.sig_item -> SdStr si ] ] + ; +END; + +Pcaml.add_option "-D" (Arg.String define) + " Define for ifdef instruction." +; +Pcaml.add_option "-U" (Arg.String undef) + " Undefine for ifdef instruction." +; diff --git a/camlp4/unmaintained/etc/pa_oop.ml b/camlp4/unmaintained/etc/pa_oop.ml new file mode 100644 index 0000000..bb5684b --- /dev/null +++ b/camlp4/unmaintained/etc/pa_oop.ml @@ -0,0 +1,155 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; + +type spat_comp = + [ SpTrm of Loc.t and MLast.patt and option MLast.expr + | SpNtr of Loc.t and MLast.patt and MLast.expr + | SpStr of Loc.t and MLast.patt ] +; +type sexp_comp = + [ SeTrm of Loc.t and MLast.expr | SeNtr of Loc.t and MLast.expr ] +; + +value strm_n = "__strm"; +value peek_fun _loc = <:expr< Stream.peek >>; +value junk_fun _loc = <:expr< Stream.junk >>; + +(* Parsers. *) + +value stream_pattern_component skont = + fun + [ SpTrm _loc p wo -> + (<:expr< $peek_fun _loc$ $lid:strm_n$ >>, p, wo, + <:expr< do { $junk_fun _loc$ $lid:strm_n$; $skont$ } >>) + | SpNtr _loc p e -> + (<:expr< try Some ($e$ $lid:strm_n$) with + [ Stream.Failure -> None ] >>, + p, None, skont) + | SpStr _loc p -> + (<:expr< Some $lid:strm_n$ >>, p, None, skont) ] +; + +value rec stream_pattern _loc epo e ekont = + fun + [ [] -> + match epo with + [ Some ep -> <:expr< let $ep$ = Stream.count $lid:strm_n$ in $e$ >> + | _ -> e ] + | [(spc, err) :: spcl] -> + let skont = + let ekont err = + let str = + match err with + [ Some estr -> estr + | _ -> <:expr< "" >> ] + in + <:expr< raise (Stream.Error $str$) >> + in + stream_pattern _loc epo e ekont spcl + in + let (tst, p, wo, e) = stream_pattern_component skont spc in + let ckont = ekont err in + <:expr< match $tst$ with + [ Some $p$ $when:wo$ -> $e$ | _ -> $ckont$ ] >> ] +; + +value rec parser_cases _loc = + fun + [ [] -> <:expr< raise Stream.Failure >> + | [(spcl, epo, e) :: spel] -> + stream_pattern _loc epo e (fun _ -> parser_cases _loc spel) spcl ] +; + +value cparser _loc bpo pc = + let e = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $e$ >> + | None -> e ] + in + let p = <:patt< ($lid:strm_n$ : Stream.t _) >> in + <:expr< fun $p$ -> $e$ >> +; + +value cparser_match _loc me bpo pc = + let pc = parser_cases _loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >> + | None -> pc ] + in + <:expr< let $lid:strm_n$ = $me$ in $e$ >> +; + +(* streams *) + +value slazy _loc e = <:expr< fun _ -> $e$ >>; + +value rec cstream gloc = + fun + [ [] -> let _loc = gloc in <:expr< Stream.sempty >> + | [SeTrm _loc e :: secl] -> + <:expr< Stream.lcons $slazy _loc e$ $cstream gloc secl$ >> + | [SeNtr _loc e :: secl] -> + <:expr< Stream.lapp $slazy _loc e$ $cstream gloc secl$ >> ] +; + +(* Syntax extensions in Ocaml grammar *) + + +EXTEND + GLOBAL: expr; + expr: LEVEL "expr1" + [ [ "parser"; po = OPT ipatt; OPT "|"; pcl = LIST1 parser_case SEP "|" -> + <:expr< $cparser _loc po pcl$ >> + | "match"; e = expr; "with"; "parser"; po = OPT ipatt; OPT "|"; + pcl = LIST1 parser_case SEP "|" -> + <:expr< $cparser_match _loc e po pcl$ >> ] ] + ; + parser_case: + [ [ "[<"; sp = stream_patt; ">]"; po = OPT ipatt; "->"; e = expr -> + (sp, po, e) ] ] + ; + stream_patt: + [ [ spc = stream_patt_comp -> [(spc, None)] + | spc = stream_patt_comp; ";"; sp = LIST1 stream_patt_comp_err SEP ";" -> + [(spc, None) :: sp] + | (* empty *) -> [] ] ] + ; + stream_patt_comp_err: + [ [ spc = stream_patt_comp; + eo = OPT [ "??"; e = expr LEVEL "expr1" -> e ] -> + (spc, eo) ] ] + ; + stream_patt_comp: + [ [ "'"; p = patt; eo = OPT [ "when"; e = (expr LEVEL "expr1") -> e ] -> + SpTrm _loc p eo + | p = patt; "="; e = (expr LEVEL "expr1") -> SpNtr _loc p e + | p = patt -> SpStr _loc p ] ] + ; + ipatt: + [ [ i = LIDENT -> <:patt< $lid:i$ >> ] ] + ; + + expr: LEVEL "simple" + [ [ "[<"; se = LIST0 stream_expr_comp SEP ";"; ">]" -> + <:expr< $cstream _loc se$ >> ] ] + ; + stream_expr_comp: + [ [ "'"; e = expr LEVEL "expr1" -> SeTrm _loc e + | e = expr LEVEL "expr1" -> SeNtr _loc e ] ] + ; +END; diff --git a/camlp4/unmaintained/etc/pa_ru.ml b/camlp4/unmaintained/etc/pa_ru.ml new file mode 100644 index 0000000..1761c5e --- /dev/null +++ b/camlp4/unmaintained/etc/pa_ru.ml @@ -0,0 +1,46 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; + +value o2b = + fun + [ Some _ -> True + | None -> False ] +; + +EXTEND + GLOBAL: expr; + expr: LEVEL "top" + [ [ "do"; "{"; seq = sequence; "}" -> + match seq with + [ [e] -> e + | _ -> <:expr< do { $list:seq$ } >> ] ] ] + ; + sequence: + [ [ "let"; o = OPT "rec"; l = LIST1 let_binding SEP "and"; [ "in" | ";" ]; + el = SELF -> + let e = + match el with + [ [e] -> e + | _ -> <:expr< do { $list:el$ } >> ] + in + [ <:expr< let $opt:o2b o$ $list:l$ in $e$ >> ] + | e = expr; ";"; el = SELF -> + let e = let _loc = MLast.loc_of_expr e in <:expr< ($e$ : unit) >> in + [e :: el] + | e = expr; ";" -> [e] + | e = expr -> [e] ] ] + ; +END; diff --git a/camlp4/unmaintained/etc/parserify.ml b/camlp4/unmaintained/etc/parserify.ml new file mode 100644 index 0000000..f0a3be8 --- /dev/null +++ b/camlp4/unmaintained/etc/parserify.ml @@ -0,0 +1,305 @@ +(* camlp4r q_MLast.cmo *) + + +(* FIXME FIXME *) +value _loc = Loc.mk "FIXME parserify.ml"; + +type spc = + [ SPCterm of (MLast.patt * option MLast.expr) + | SPCnterm of MLast.patt and MLast.expr + | SPCsterm of MLast.patt ] +; + +exception NotImpl; + +value rec subst v = + MLast.Map.Expr.expr (fun [ <:expr@_loc< __strm >> -> <:expr< $lid:v$ >> + | e -> e ]) +(* FIXME FIXME *) + (* match e with + [ <:expr< $lid:x$ >> -> if x = "__strm" then <:expr< $lid:v$ >> else e + | <:expr< $uid:_$ >> -> e + | <:expr< $int:_$ >> -> e + | <:expr< $chr:_$ >> -> e + | <:expr< $str:_$ >> -> e + | <:expr@_loc< $e1$ . $lab$ >> -> <:expr< $subst v e1$ . $lab$ >> + | <:expr@_loc< $x$ $y$ >> -> <:expr< $subst v x$ $subst v y$ >> + | <:expr@_loc< let $lid:s1$ = $e1$ in $e2$ >> -> + if s1 = v then <:expr< let $lid:s1$ = $subst v e1$ in $e2$ >> + else <:expr< let $lid:s1$ = $subst v e1$ in $subst v e2$ >> + | <:expr@_loc< let _ = $e1$ in $e2$ >> -> + <:expr< let _ = $subst v e1$ in $subst v e2$ >> + | <:expr@_loc< ($list:el$) >> -> <:expr< ($list:List.map (subst v) el$) >> + | _ -> raise NotImpl ] *) +; + +value rec is_free v = + fun + [ <:expr< $lid:x$ >> -> x <> v + | <:expr< $uid:_$ >> -> True + | <:expr< $int:_$ >> -> True + | <:expr< $chr:_$ >> -> True + | <:expr< $str:_$ >> -> True + | <:expr< $e$ . $_$ >> -> is_free v e + | <:expr< $x$ $y$ >> -> is_free v x && is_free v y + | <:expr< let $lid:s1$ = $e1$ in $e2$ >> -> + is_free v e1 && (s1 = v || is_free v e2) + | <:expr< let _ = $e1$ in $e2$ >> -> is_free v e1 && is_free v e2 + | <:expr< ($list:el$) >> -> List.for_all (is_free v) el + | _ -> raise NotImpl ] +; + +value gensym = + let cnt = ref 0 in + fun () -> + do { incr cnt; "pr_rp_symb_" ^ string_of_int cnt.val } +; + +value free_var_in_expr c e = + let rec loop_alpha v = + let x = String.make 1 v in + if is_free x e then Some x + else if v = 'z' then None + else loop_alpha (Char.chr (Char.code v + 1)) + in + let rec loop_count cnt = + let x = String.make 1 c ^ string_of_int cnt in + if is_free x e then x else loop_count (succ cnt) + in + try + match loop_alpha c with + [ Some v -> v + | None -> loop_count 1 ] + with + [ NotImpl -> gensym () ] +; + +value parserify _loc = + fun + [ <:expr< $e$ __strm >> -> e + | e -> <:expr< fun __strm -> $e$ >> ] +; + +value is_raise_failure = + fun + [ <:expr< raise Stream.Failure >> -> True + | _ -> False ] +; + +value is_raise_error = + fun + [ <:expr< raise (Stream.Error $_$) >> -> True + | _ -> False ] +; + +value semantic _loc e = + try + if is_free "__strm" e then e + else + let v = free_var_in_expr 's' e in + <:expr< let $lid:v$ = __strm in $subst v e$ >> + with + [ NotImpl -> e ] +; + +value rewrite_parser = + rewrite True where rec rewrite top ge = + match ge with + [ <:expr@_loc< let $p$ = try $e$ with [ Stream.Failure -> raise $exc$ ] in + $sp_kont$ >> -> + let f = parserify _loc e in + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $rewrite False sp_kont$ + | _ -> raise $exc$ ] + >> + | <:expr@_loc< let $p$ = Stream.count __strm in $f$ >> -> + try + if is_free "__strm" f then ge + else + let v = free_var_in_expr 's' f in + <:expr< + let $lid:v$ = __strm in + let $p$ = Stream.count __strm in $subst v f$ + >> + with + [ NotImpl -> ge ] + | <:expr@_loc< let $p$ = __strm in $e$ >> -> + <:expr< let $p$ = __strm in $rewrite False e$ >> + | <:expr@_loc< let $p$ = $f$ __strm in $sp_kont$ >> when top -> + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $rewrite False sp_kont$ + | _ -> raise Stream.Failure ] + >> + | <:expr@_loc< let $p$ = $e$ in $sp_kont$ >> -> + if match e with + [ <:expr< match try Some $_$ with [ Stream.Failure -> None ] with + [ $list:_$ ] >> + | <:expr< match Stream.peek __strm with [ $list:_$ ] >> + | <:expr< try $_$ with [ Stream.Failure -> $_$ ] >> + | <:expr< let $_$ = Stream.count __strm in $_$ >> -> True + | _ -> False ] + then + let f = rewrite True <:expr< fun __strm -> $e$ >> in + let exc = + if top then <:expr< Stream.Failure >> + else <:expr< Stream.Error "" >> + in + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $rewrite False sp_kont$ + | _ -> raise $exc$ ] + >> + else semantic _loc ge + | <:expr@_loc< match try Some $e$ with [ Stream.Failure -> None ] with + [ Some $p$ -> $sp_kont$ + | _ -> $p_kont$ ] >> -> + let f = parserify _loc e in + if not top && is_raise_failure p_kont then semantic _loc ge + else + let (p, f, sp_kont, p_kont) = + if top || is_raise_error p_kont then + (p, f, rewrite False sp_kont, rewrite top p_kont) + else + let f = + <:expr< + fun __strm -> + match + try Some ($f$ __strm) with [ Stream.Failure -> None ] + with + [ Some $p$ -> $rewrite False sp_kont$ + | _ -> $rewrite top p_kont$ ] + >> + in + (<:patt< a >>, f, <:expr< a >>, + <:expr< raise (Stream.Error "") >>) + in + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $sp_kont$ + | _ -> $p_kont$ ] + >> + | <:expr< match Stream.peek __strm with [ $list:pel$ ] >> -> + let rec iter pel = + match pel with + [ [(<:patt< Some $p$ >>, eo, + <:expr< do { Stream.junk __strm; $sp_kont$ } >>); + (<:patt< _ >>, None, p_kont) :: _] -> + <:expr< + match Stream.peek __strm with + [ Some $p$ $when:eo$ -> + do { Stream.junk __strm; $rewrite False sp_kont$ } + | _ -> $rewrite top p_kont$ ] + >> + | [(<:patt< Some $p$ >>, eo, + <:expr< do { Stream.junk __strm; $sp_kont$ } >>) :: pel] -> + let p_kont = iter pel in + <:expr< + match Stream.peek __strm with + [ Some $p$ $when:eo$ -> + do { Stream.junk __strm; $rewrite False sp_kont$ } + | _ -> $p_kont$ ] + >> + | _ -> + <:expr< match Stream.peek __strm with [ $list:pel$ ] >> ] + in + iter pel + | <:expr@_loc< try Some $e$ with [ Stream.Failure -> $p_kont$ ] >> -> + let f = parserify _loc e in + let e = + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some a -> Some a + | _ -> $p_kont$ ] + >> + in + rewrite top e + | <:expr@_loc< try $e$ with [ Stream.Failure -> $p_kont$ ] >> -> + let f = parserify _loc e in + let e = + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some a -> a + | _ -> $rewrite top p_kont$ ] + >> + in + rewrite top e + | <:expr< $f$ __strm >> -> + if top then + <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some a -> a + | _ -> raise Stream.Failure ] + >> + else + let v = free_var_in_expr 's' f in + <:expr< let $lid:v$ = __strm in $subst v f$ $lid:v$ >> + | e -> let loc = MLast.loc_of_expr e in semantic loc e ] +; + +value spc_of_parser = + let rec parser_cases e = + match e with + [ <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $sp_kont$ + | _ -> $p_kont$ ] + >> -> + let spc = (SPCnterm p f, None) in + let (sp, epo, e) = kont sp_kont in + [([spc :: sp], epo, e) :: parser_cases p_kont] + | <:expr< + match Stream.peek __strm with + [ Some $p$ $when:wo$ -> do { Stream.junk __strm; $sp_kont$ } + | _ -> $p_kont$ ] + >> -> + let spc = (SPCterm (p, wo), None) in + let (sp, epo, e) = kont sp_kont in + [([spc :: sp], epo, e) :: parser_cases p_kont] + | <:expr< let $p$ = __strm in $sp_kont$ >> -> + let spc = (SPCsterm p, None) in + let (sp, epo, e) = kont sp_kont in + [([spc :: sp], epo, e)] + | <:expr< let $p$ = Stream.count __strm in $e$ >> -> [([], Some p, e)] + | <:expr< raise Stream.Failure >> -> [] + | _ -> [([], None, e)] ] + and kont e = + match e with + [ <:expr< + match try Some ($f$ __strm) with [ Stream.Failure -> None ] with + [ Some $p$ -> $sp_kont$ + | _ -> raise (Stream.Error $err$) ] + >> -> + let err = + match err with + [ <:expr< "" >> -> None + | _ -> Some err ] + in + let spc = (SPCnterm p f, err) in + let (sp, epo, e) = kont sp_kont in + ([spc :: sp], epo, e) + | <:expr< + match Stream.peek __strm with + [ Some $p$ $when:wo$ -> do { Stream.junk __strm; $sp_kont$ } + | _ -> raise (Stream.Error $err$) ] + >> -> + let err = + match err with + [ <:expr< "" >> -> None + | _ -> Some err ] + in + let spc = (SPCterm (p, wo), err) in + let (sp, epo, e) = kont sp_kont in + ([spc :: sp], epo, e) + | <:expr< let $p$ = __strm in $sp_kont$ >> -> + let spc = (SPCsterm p, None) in + let (sp, epo, e) = kont sp_kont in + ([spc :: sp], epo, e) + | <:expr< let $p$ = Stream.count __strm in $e$ >> -> ([], Some p, e) + | _ -> ([], None, e) ] + in + parser_cases +; + +value parser_of_expr e = spc_of_parser (rewrite_parser e); diff --git a/camlp4/unmaintained/etc/parserify.mli b/camlp4/unmaintained/etc/parserify.mli new file mode 100644 index 0000000..c1affdb --- /dev/null +++ b/camlp4/unmaintained/etc/parserify.mli @@ -0,0 +1,12 @@ +(* camlp4r *) + + +type spc = + [ SPCterm of (MLast.patt * option MLast.expr) + | SPCnterm of MLast.patt and MLast.expr + | SPCsterm of MLast.patt ] +; + +value parser_of_expr : + MLast.expr -> + list (list (spc * option MLast.expr) * option MLast.patt * MLast.expr); diff --git a/camlp4/unmaintained/etc/pr_depend.ml b/camlp4/unmaintained/etc/pr_depend.ml new file mode 100644 index 0000000..53224da --- /dev/null +++ b/camlp4/unmaintained/etc/pr_depend.ml @@ -0,0 +1,321 @@ +(* camlp4r *) + + +open MLast; + +value not_impl name x = + Format.eprintf "pr_depend: not impl: %s; %a@." name ObjTools.print (Obj.repr x) +; + +module StrSet = + Set.Make (struct type t = string; value compare = compare; end) +; + +value fset = ref StrSet.empty; +value addmodule s = fset.val := StrSet.add s fset.val; + +value list = List.iter; + +value option f = + fun + [ Some x -> f x + | None -> () ] +; + +value longident = + fun + [ [s; _ :: _] -> addmodule s + | _ -> () ] +; + +value rec ctyp = + fun + [ TyAcc _ t _ -> ctyp_module t + | TyAli _ t1 t2 -> do { ctyp t1; ctyp t2; } + | TyApp _ t1 t2 -> do { ctyp t1; ctyp t2; } + | TyAny _ -> () + | TyArr _ t1 t2 -> do { ctyp t1; ctyp t2; } + | TyCls _ li -> longident li + | TyLab _ _ t -> ctyp t + | TyLid _ _ -> () + | TyMan _ t1 t2 -> do { ctyp t1; ctyp t2; } + | TyOlb _ _ t -> ctyp t + | TyQuo _ _ -> () + | TyRec _ ldl -> list label_decl ldl + | TySum _ cdl -> list constr_decl cdl + | TyPrv _ t -> ctyp t + | TyTup _ tl -> list ctyp tl + | TyVrn _ sbtll _ -> list variant sbtll + | x -> not_impl "ctyp" x ] +and constr_decl (_, _, tl) = list ctyp tl +and label_decl (_, _, _, t) = ctyp t +and variant = + fun + [ RfTag _ _ tl -> list ctyp tl + | RfInh t -> ctyp t ] +and ctyp_module = + fun + [ TyAcc _ t _ -> ctyp_module t + | TyApp _ t1 t2 -> do { ctyp t1; ctyp t2; } + | TyUid _ m -> addmodule m + | x -> not_impl "ctyp_module" x ] +; + +value rec patt = + fun + [ PaAcc _ p _ -> patt_module p + | PaAli _ p1 p2 -> do { patt p1; patt p2; } + | PaAny _ -> () + | PaApp _ p1 p2 -> do { patt p1; patt p2; } + | PaArr _ pl -> list patt pl + | PaChr _ _ -> () + | PaInt _ _ -> () + | PaLab _ _ po -> option patt po + | PaLid _ _ -> () + | PaOlb _ _ peoo -> + option (fun (p, eo) -> do { patt p; option expr eo }) peoo + | PaOrp _ p1 p2 -> do { patt p1; patt p2; } + | PaRec _ lpl -> list label_patt lpl + | PaRng _ p1 p2 -> do { patt p1; patt p2; } + | PaStr _ _ -> () + | PaTup _ pl -> list patt pl + | PaTyc _ p t -> do { patt p; ctyp t; } + | PaUid _ _ -> () + | PaVrn _ _ -> () + | x -> not_impl "patt" x ] +and patt_module = + fun + [ PaUid _ m -> addmodule m + | PaAcc _ p _ -> patt_module p + | x -> not_impl "patt_module" x ] +and label_patt (p1, p2) = do { patt p1; patt p2; } +and expr = + fun + [ ExAcc _ e1 e2 -> do { expr_module e1; expr e2; } + | ExApp _ e1 e2 -> do { expr e1; expr e2; } + | ExAre _ e1 e2 -> do { expr e1; expr e2; } + | ExArr _ el -> list expr el + | ExAsf _ -> () + | ExAsr _ e -> do { expr e; } + | ExAss _ e1 e2 -> do { expr e1; expr e2; } + | ExChr _ _ -> () + | ExCoe _ e t1 t2 -> do { expr e; option ctyp t1; ctyp t2 } + | ExFor _ _ e1 e2 _ el -> do { expr e1; expr e2; list expr el; } + | ExFun _ pwel -> list match_case pwel + | ExIfe _ e1 e2 e3 -> do { expr e1; expr e2; expr e3; } + | ExInt _ _ -> () + | ExInt32 _ _ -> () + | ExInt64 _ _ -> () + | ExNativeInt _ _ -> () + | ExFlo _ _ -> () + | ExLab _ _ eo -> option expr eo + | ExLaz _ e -> expr e + | ExLet _ _ pel e -> do { list let_binding pel; expr e; } + | ExLid _ _ -> () + | ExLmd _ _ me e -> do { module_expr me; expr e; } + | ExMat _ e pwel -> do { expr e; list match_case pwel; } + | ExNew _ li -> longident li + | ExOlb _ _ eo -> option expr eo + | ExRec _ lel w -> do { list label_expr lel; option expr w; } + | ExSeq _ el -> list expr el + | ExSnd _ e _ -> expr e + | ExSte _ e1 e2 -> do { expr e1; expr e2; } + | ExStr _ _ -> () + | ExTry _ e pwel -> do { expr e; list match_case pwel; } + | ExTup _ el -> list expr el + | ExTyc _ e t -> do { expr e; ctyp t; } + | ExUid _ _ -> () + | ExVrn _ _ -> () + | ExWhi _ e el -> do { expr e; list expr el; } + | x -> not_impl "expr" x ] +and expr_module = + fun + [ ExUid _ m -> addmodule m + | e -> expr e ] +and let_binding (p, e) = do { patt p; expr e } +and label_expr (p, e) = do { patt p; expr e } +and match_case (p, w, e) = do { patt p; option expr w; expr e; } +and module_type = + fun + [ MtAcc _ (MtUid _ m) _ -> addmodule m + | MtFun _ _ mt1 mt2 -> do { module_type mt1; module_type mt2; } + | MtSig _ sil -> list sig_item sil + | MtUid _ _ -> () + | MtWit _ mt wc -> do { module_type mt; list with_constr wc; } + | x -> not_impl "module_type" x ] +and with_constr = + fun + [ WcTyp _ _ _ t -> ctyp t + | x -> not_impl "with_constr" x ] +and sig_item = + fun + [ SgDcl _ sil -> list sig_item sil + | SgExc _ _ tl -> list ctyp tl + | SgExt _ _ t _ -> ctyp t + | SgMod _ _ mt -> module_type mt + | SgRecMod _ mts -> list (fun (_, mt) -> module_type mt) mts + | SgMty _ _ mt -> module_type mt + | SgOpn _ [s :: _] -> addmodule s + | SgTyp _ tdl -> list type_decl tdl + | SgVal _ _ t -> ctyp t + | x -> not_impl "sig_item" x ] +and module_expr = + fun + [ MeAcc _ (MeUid _ m) _ -> addmodule m + | MeApp _ me1 me2 -> do { module_expr me1; module_expr me2; } + | MeFun _ _ mt me -> do { module_type mt; module_expr me; } + | MeStr _ sil -> list str_item sil + | MeTyc _ me mt -> do { module_expr me; module_type mt; } + | MeUid _ _ -> () + | x -> not_impl "module_expr" x ] +and str_item = + fun + [ StCls _ cil -> list (fun ci -> class_expr ci.ciExp) cil + | StDcl _ sil -> list str_item sil + | StDir _ _ _ -> () + | StExc _ _ tl _ -> list ctyp tl + | StExp _ e -> expr e + | StExt _ _ t _ -> ctyp t + | StMod _ _ me -> module_expr me + | StRecMod _ nmtmes -> list (fun (_, mt, me) -> do { module_expr me; module_type mt; }) nmtmes + | StMty _ _ mt -> module_type mt + | StOpn _ [s :: _] -> addmodule s + | StTyp _ tdl -> list type_decl tdl + | StVal _ _ pel -> list let_binding pel + | x -> not_impl "str_item" x ] +and type_decl (_, _, t, _) = ctyp t +and class_expr = + fun + [ CeApp _ ce e -> do { class_expr ce; expr e; } + | CeCon _ li tl -> do { longident li; list ctyp tl; } + | CeFun _ p ce -> do { patt p; class_expr ce; } + | CeLet _ _ pel ce -> do { list let_binding pel; class_expr ce; } + | CeStr _ po csil -> do { option patt po; list class_str_item csil; } + | x -> not_impl "class_expr" x ] +and class_str_item = + fun + [ CrInh _ ce _ -> class_expr ce + | CrIni _ e -> expr e + | CrMth _ _ _ e None -> expr e + | CrMth _ _ _ e (Some t) -> do { expr e; ctyp t } + | CrVal _ _ _ e -> expr e + | CrVir _ _ _ t -> ctyp t + | x -> not_impl "class_str_item" x ] +; + +(* Print dependencies *) + +value load_path = ref [""]; + +value find_in_path path name = + if not (Filename.is_implicit name) then + if Sys.file_exists name then name else raise Not_found + else + let rec try_dir = + fun + [ [] -> raise Not_found + | [dir :: rem] -> + let fullname = Filename.concat dir name in + if Sys.file_exists fullname then fullname else try_dir rem ] + in + try_dir path +; + +value find_depend modname (byt_deps, opt_deps) = + let name = String.uncapitalize modname in + try + let filename = find_in_path load_path.val (name ^ ".mli") in + let basename = Filename.chop_suffix filename ".mli" in + let byt_dep = basename ^ ".cmi" in + let opt_dep = + if Sys.file_exists (basename ^ ".ml") then basename ^ ".cmx" + else basename ^ ".cmi" + in + ([byt_dep :: byt_deps], [opt_dep :: opt_deps]) + with + [ Not_found -> + try + let filename = find_in_path load_path.val (name ^ ".ml") in + let basename = Filename.chop_suffix filename ".ml" in + ([basename ^ ".cmo" :: byt_deps], [basename ^ ".cmx" :: opt_deps]) + with + [ Not_found -> (byt_deps, opt_deps) ] ] +; + +value (depends_on, escaped_eol) = + match Sys.os_type with + [ "Unix" | "Win32" | "Cygwin" -> (": ", "\\\n ") + | "MacOS" -> ("\196 ", "\182\n ") + | _ -> assert False ] +; + +value print_depend target_file deps = + match deps with + [ [] -> () + | _ -> + do { + print_string target_file; + print_string depends_on; + let rec print_items pos = + fun + [ [] -> print_string "\n" + | [dep :: rem] -> + if pos + String.length dep <= 77 then do { + print_string dep; + print_string " "; + print_items (pos + String.length dep + 1) rem + } + else do { + print_string escaped_eol; + print_string dep; + print_string " "; + print_items (String.length dep + 5) rem + } ] + in + print_items (String.length target_file + 2) deps + } ] +; + +(* Main *) + +value depend_sig ast = + do { + fset.val := StrSet.empty; + List.iter (fun (si, _) -> sig_item si) ast; + let basename = Filename.chop_suffix Pcaml.input_file.val ".mli" in + let (byt_deps, _) = StrSet.fold find_depend fset.val ([], []) in + print_depend (basename ^ ".cmi") byt_deps; + } +; + +value depend_str ast = + do { + fset.val := StrSet.empty; + List.iter (fun (si, _) -> str_item si) ast; + let basename = + if Filename.check_suffix Pcaml.input_file.val ".ml" then + Filename.chop_suffix Pcaml.input_file.val ".ml" + else + try + let len = String.rindex Pcaml.input_file.val '.' in + String.sub Pcaml.input_file.val 0 len + with + [ Failure _ | Not_found -> Pcaml.input_file.val ] + in + let init_deps = + if Sys.file_exists (basename ^ ".mli") then + let cmi_name = basename ^ ".cmi" in ([cmi_name], [cmi_name]) + else ([], []) + in + let (byt_deps, opt_deps) = StrSet.fold find_depend fset.val init_deps in + print_depend (basename ^ ".cmo") byt_deps; + print_depend (basename ^ ".cmx") opt_deps; + } +; + +Pcaml.print_interf.val := depend_sig; +Pcaml.print_implem.val := depend_str; + +Pcaml.add_option "-I" + (Arg.String (fun dir -> load_path.val := load_path.val @ [dir])) + " Add to the list of include directories."; diff --git a/camlp4/unmaintained/etc/pr_extend.ml b/camlp4/unmaintained/etc/pr_extend.ml new file mode 100644 index 0000000..5f8b693 --- /dev/null +++ b/camlp4/unmaintained/etc/pr_extend.ml @@ -0,0 +1,518 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; +open Spretty; + +value no_slist = ref False; + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +(* Utilities *) + +value rec list elem el k = + match el with + [ [] -> k + | [x] -> [: `elem x k :] + | [x :: l] -> [: `elem x [: :]; list elem l k :] ] +; + +value rec listws elem sep el k = + match el with + [ [] -> k + | [x] -> [: `elem x k :] + | [x :: l] -> [: `elem x [: `sep :]; listws elem sep l k :] ] +; + +value rec listwbws elem b sep el dg k = + match el with + [ [] -> [: b; k :] + | [x] -> [: `elem b x dg k :] + | [x :: l] -> + let sdg = + match sep with + [ S _ x -> x + | _ -> "" ] + in + [: `elem b x sdg [: :]; listwbws elem [: `sep :] sep l dg k :] ] +; + +(* Extracting *) + +value rec get_globals = + fun + [ [(<:patt< _ >>, <:expr< ($e$ : $uid:gmod1$.Entry.e '$_$) >>) :: pel] -> + let (gmod, gl) = get_globals pel in + if gmod = "" || gmod = gmod1 then (gmod1, [e :: gl]) + else raise Not_found + | [] -> ("", []) + | _ -> raise Not_found ] +; + +value rec get_locals = + fun + [ [(<:patt< $_$ >>, + <:expr< (grammar_entry_create $_$ : $_$) >>) :: pel] -> + get_locals pel + | [] -> () + | _ -> raise Not_found ] +; + +value unposition = + fun + [ <:expr< None >> -> None + | <:expr< Some Gramext.First >> -> Some Gramext.First + | <:expr< Some Gramext.Last >> -> Some Gramext.Last + | <:expr< Some (Gramext.Before $str:s$) >> -> Some (Gramext.Before s) + | <:expr< Some (Gramext.After $str:s$) >> -> Some (Gramext.After s) + | <:expr< Some (Gramext.Level $str:s$) >> -> Some (Gramext.Level s) + | _ -> raise Not_found ] +; + +value unlabel = + fun + [ <:expr< None >> -> None + | <:expr< Some $str:s$ >> -> Some s + | _ -> raise Not_found ] +; + +value unassoc = + fun + [ <:expr< None >> -> None + | <:expr< Some Gramext.NonA >> -> Some Gramext.NonA + | <:expr< Some Gramext.LeftA >> -> Some Gramext.LeftA + | <:expr< Some Gramext.RightA >> -> Some Gramext.RightA + | _ -> raise Not_found ] +; + +value rec unaction = + fun + [ <:expr< fun ($lid:locp$ : Loc.t) -> ($a$ : $_$) >> + when locp = Stdpp.loc_name.val -> + let ao = + match a with + [ <:expr< () >> -> None + | _ -> Some a ] + in + ([], ao) + | <:expr< fun ($p$ : $_$) -> $e$ >> -> + let (pl, a) = unaction e in ([p :: pl], a) + | <:expr@_loc< fun _ -> $e$ >> -> + let (pl, a) = unaction e in ([ <:patt< _ >> :: pl ], a) + | _ -> raise Not_found ] +; + +value untoken = + fun + [ <:expr< ($str:x$, $str:y$) >> -> (x, y) + | _ -> raise Not_found ] +; + +type symbol = + [ Snterm of MLast.expr + | Snterml of MLast.expr and string + | Slist0 of symbol + | Slist0sep of symbol and symbol + | Slist1 of symbol + | Slist1sep of symbol and symbol + | Sopt of symbol + | Sself + | Snext + | Stoken of Token.pattern + | Srules of list (list (option MLast.patt * symbol) * option MLast.expr) ] +; + +value rec unsymbol = + fun + [ <:expr< Gramext.Snterm ($uid:_$.Entry.obj ($e$ : $_$)) >> -> Snterm e + | <:expr< Gramext.Snterml ($uid:_$.Entry.obj ($e$ : $_$)) $str:s$ >> -> + Snterml e s + | <:expr< Gramext.Snterml ($uid:_$.Entry.obj ($e$ : $_$), $str:s$) >> -> + Snterml e s + | <:expr< Gramext.Slist0 $e$ >> -> Slist0 (unsymbol e) + | <:expr< Gramext.Slist0sep $e1$ $e2$ >> -> + Slist0sep (unsymbol e1) (unsymbol e2) + | <:expr< Gramext.Slist0sep ($e1$, $e2$) >> -> + Slist0sep (unsymbol e1) (unsymbol e2) + | <:expr< Gramext.Slist1 $e$ >> -> Slist1 (unsymbol e) + | <:expr< Gramext.Slist1sep $e1$ $e2$ >> -> + Slist1sep (unsymbol e1) (unsymbol e2) + | <:expr< Gramext.Slist1sep ($e1$, $e2$) >> -> + Slist1sep (unsymbol e1) (unsymbol e2) + | <:expr< Gramext.Sopt $e$ >> -> Sopt (unsymbol e) + | <:expr< Gramext.Sself >> -> Sself + | <:expr< Gramext.Snext >> -> Snext + | <:expr< Gramext.Stoken $e$ >> -> Stoken (untoken e) + | <:expr< Gramext.srules $e$ >> -> Srules (unrule_list [] e) + | _ -> raise Not_found ] +and unpsymbol_list pl e = + match (pl, e) with + [ ([], <:expr< [] >>) -> [] + | ([p :: pl], <:expr< [$e$ :: $el$] >>) -> + let op = + match p with + [ <:patt< _ >> -> None + | _ -> Some p ] + in + [(op, unsymbol e) :: unpsymbol_list pl el] + | _ -> raise Not_found ] +and unrule = + fun + [ <:expr@_loc< ($e1$, Gramext.action $e2$) >> -> + let (pl, a) = + match unaction e2 with + [ ([], None) -> ([], Some <:expr< () >>) + | x -> x ] + in + let sl = unpsymbol_list (List.rev pl) e1 in + (sl, a) + | _ -> raise Not_found ] +and unrule_list rl = + fun + [ <:expr< [$e$ :: $el$] >> -> unrule_list [unrule e :: rl] el + | <:expr< [] >> -> rl + | _ -> raise Not_found ] +; + +value unlevel = + fun + [ <:expr< ($e1$, $e2$, $e3$) >> -> + (unlabel e1, unassoc e2, unrule_list [] e3) + | _ -> raise Not_found ] +; + +value rec unlevel_list = + fun + [ <:expr< [$e$ :: $el$] >> -> [unlevel e :: unlevel_list el] + | <:expr< [] >> -> [] + | _ -> raise Not_found ] +; + +value unentry = + fun + [ <:expr< (Grammar.Entry.obj ($e$ : Grammar.Entry.e '$_$), $pos$, $ll$) >> -> + (e, unposition pos, unlevel_list ll) + | _ -> raise Not_found ] +; + +value rec unentry_list = + fun + [ <:expr< [$e$ :: $el$] >> -> [unentry e :: unentry_list el] + | <:expr< [] >> -> [] + | _ -> raise Not_found ] +; + +value unextend_body e = + let ((_, globals), e) = + match e with + [ <:expr< let $list:pel$ in $e1$ >> -> + try (get_globals pel, e1) with + [ Not_found -> (("", []), e) ] + | _ -> (("", []), e) ] + in + let e = + match e with + [ <:expr< + let grammar_entry_create s = + Grammar.Entry.create (Grammar.of_entry $_$) s + in + $e$ >> -> + let e = + match e with + [ <:expr< let $list:pel$ in $e1$ >> -> + try let _ = get_locals pel in e1 with + [ Not_found -> e ] + | _ -> e ] + in + e + | _ -> e ] + in + let el = unentry_list e in + (globals, el) +; + +value ungextend_body e = + let e = + match e with + [ <:expr< + let grammar_entry_create = Gram.Entry.create in + let $list:ll$ in $e$ + >> -> + let _ = get_locals ll in e + | _ -> e ] + in + match e with + [ <:expr< do { $list:el$ } >> -> + List.map + (fun + [ <:expr< $uid:_$.extend ($e$ : $uid:_$.Entry.e '$_$) $pos$ $ll$ >> -> + (e, unposition pos, unlevel_list ll) + | _ -> raise Not_found ]) + el + | _ -> raise Not_found ] +; + +(* Printing *) + +value ident s k = HVbox [: `S LR s; k :]; +value string s k = HVbox [: `S LR ("\"" ^ s ^ "\""); k :]; + +value position = + fun + [ None -> [: :] + | Some Gramext.First -> [: `S LR "FIRST" :] + | Some Gramext.Last -> [: `S LR "LAST" :] + | Some (Gramext.Before s) -> [: `S LR "BEFORE"; `string s [: :] :] + | Some (Gramext.After s) -> [: `S LR "AFTER"; `string s [: :] :] + | Some (Gramext.Level s) -> [: `S LR "LEVEL"; `string s [: :] :] ] +; + +value action expr a dg k = + expr a dg k +; + +value token (con, prm) k = + if con = "" then string prm k + else if prm = "" then HVbox [: `S LR con; k :] + else HVbox [: `S LR con; `string prm k :] +; + +value simplify_rules rl = + try + List.map + (fun + [ ([(Some <:patt< $lid:x$ >>, s)], Some <:expr< $lid:y$ >>) -> + if x = y then ([(None, s)], None) else raise Exit + | ([], _) as r -> r + | _ -> raise Exit ]) + rl + with + [ Exit -> rl ] +; + +value rec symbol s k = + match s with + [ Snterm e -> expr e "" k + | Snterml e s -> HVbox [: `expr e "" [: :]; `S LR "LEVEL"; `string s k :] + | Slist0 s -> HVbox [: `S LR "LIST0"; `symbol s k :] + | Slist0sep s sep -> + HVbox + [: `S LR "LIST0"; `symbol s [: :]; `S LR "SEP"; + `symbol sep k :] + | Slist1 s -> HVbox [: `S LR "LIST1"; `symbol s k :] + | Slist1sep s sep -> + HVbox + [: `S LR "LIST1"; `symbol s [: :]; `S LR "SEP"; + `symbol sep k :] + | Sopt s -> HVbox [: `S LR "OPT"; `symbol s k :] + | Sself -> HVbox [: `S LR "SELF"; k :] + | Snext -> HVbox [: `S LR "NEXT"; k :] + | Stoken tok -> token tok k + | Srules + [([(Some <:patt< a >>, Snterm <:expr< a_list >>)], Some <:expr< a >>); + ([(Some <:patt< a >>, + ((Slist0 _ | Slist1 _ | Slist0sep _ _ | Slist1sep _ _) as s))], + Some <:expr< Qast.List a >>)] + when not no_slist.val + -> + match s with + [ Slist0 s -> HVbox [: `S LR "SLIST0"; `simple_symbol s k :] + | Slist1 s -> HVbox [: `S LR "SLIST1"; `simple_symbol s k :] + | Slist0sep s sep -> + HVbox + [: `S LR "SLIST0"; `simple_symbol s [: :]; `S LR "SEP"; + `symbol sep k :] + | Slist1sep s sep -> + HVbox + [: `S LR "SLIST1"; `simple_symbol s [: :]; `S LR "SEP"; + `simple_symbol sep k :] + | _ -> assert False ] + | Srules + [([(Some <:patt< a >>, Snterm <:expr< a_opt >>)], Some <:expr< a >>); + ([(Some <:patt< a >>, Sopt s)], Some <:expr< Qast.Option a >>)] + when not no_slist.val + -> + let s = + match s with + [ Srules + [([(Some <:patt< x >>, Stoken ("", str))], + Some <:expr< Qast.Str x >>)] -> + Stoken ("", str) + | s -> s ] + in + HVbox [: `S LR "SOPT"; `simple_symbol s k :] + | Srules rl -> + let rl = simplify_rules rl in + HVbox [: `HVbox [: :]; rule_list rl k :] ] +and simple_symbol s k = + match s with + [ Snterml _ _ -> HVbox [: `S LO "("; `symbol s [: `S RO ")"; k :] :] + | s -> symbol s k ] +and psymbol (p, s) k = + match p with + [ None -> symbol s k + | Some p -> HVbox [: `patt p "" [: `S LR "=" :]; `symbol s k :] ] +and psymbol_list sl k = + listws psymbol (S RO ";") sl k +and rule b (sl, a) dg k = + match a with + [ None -> HVbox [: b; `HOVbox [: psymbol_list sl k :] :] + | Some a -> + HVbox + [: b; + `HOVbox + [: `HOVbox + [: `HVbox [: :]; + psymbol_list sl [: `S LR "->" :] :]; + `action expr a dg k :] :] ] +and rule_list ll k = + listwbws rule [: `S LR "[" :] (S LR "|") ll "" + [: `S LR "]"; k :] +; + +value label = + fun + [ Some s -> [: `S LR ("\"" ^ s ^ "\"") :] + | None -> [: :] ] +; + +value intloc loc = ((Loc.start_off loc), (Loc.stop_off loc)); + +value intloc2 (bp, ep) = (bp.Lexing.pos_cnum, ep.Lexing.pos_cnum); + + +value assoc = + fun + [ Some Gramext.NonA -> [: `S LR "NONA" :] + | Some Gramext.LeftA -> [: `S LR "LEFTA" :] + | Some Gramext.RightA -> [: `S LR "RIGHTA" :] + | None -> [: :] ] +; + +value level b (lab, ass, rl) _ k = + let s = + if rl = [] then [: `S LR "[ ]"; k :] + else [: `Vbox [: `HVbox [: :]; rule_list rl k :] :] + in + match (lab, ass) with + [ (None, None) -> HVbox [: b; s :] + | _ -> + Vbox + [: `HVbox [: b; label lab; assoc ass :]; + `HVbox [: `HVbox [: :]; s :] :] ] +; + +value level_list ll k = + Vbox + [: `HVbox [: :]; + listwbws level [: `S LR "[" :] (S LR "|") ll "" + [: `S LR "]"; k :] :] +; + +value entry (e, pos, ll) k = + BEbox + [: `LocInfo (intloc(MLast.loc_of_expr e)) + (HVbox [: `expr e "" [: `S RO ":" :]; position pos :]); + `level_list ll [: :]; + `HVbox [: `S RO ";"; k :] :] +; + +value entry_list el k = + Vbox [: `HVbox [: :]; list entry el k :] +; + +value extend_body (globals, e) k = + let s = entry_list e k in + match globals with + [ [] -> s + | sl -> + HVbox + [: `HVbox [: :]; + `HOVbox + [: `S LR "GLOBAL"; `S RO ":"; + list (fun e k -> HVbox [: `expr e "" k :]) sl + [: `S RO ";" :] :]; + `s :] ] +; + +value extend e _ k = + match e with + [ <:expr< Grammar.extend $e$ >> -> + try + let ex = unextend_body e in + BEbox + [: `S LR "EXTEND"; `extend_body ex [: :]; + `HVbox [: `S LR "END"; k :] :] + with + [ Not_found -> + HVbox + [: `S LR "Grammar.extend"; + `HOVbox + [: `S LO "("; + `expr e "" [: `HVbox [: `S RO ")"; k :] :] :] :] ] + | _ -> expr e "" k ] +; + +value get_gextend = + fun + [ <:expr< let $list:gl$ in $e$ >> -> + try + let (gmod, gl) = get_globals gl in + let el = ungextend_body e in + Some (gmod, gl, el) + with + [ Not_found -> None ] + | _ -> None ] +; + +value gextend e _ k = + match get_gextend e with + [ Some (gmod, gl, el) -> + BEbox + [: `HVbox [: `S LR "GEXTEND"; `S LR gmod :]; + `extend_body (gl, el) [: :]; + `HVbox [: `S LR "END"; k :] :] + | None -> expr e "" k ] +; + +value is_gextend e = get_gextend e <> None; + +(* Printer extensions *) + +let lev = + try find_pr_level "expr1" pr_expr.pr_levels with + [ Failure _ -> find_pr_level "top" pr_expr.pr_levels ] +in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< let $list:_$ in $_$ >> as e when is_gextend e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Grammar.extend $_$ >> as e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "simple" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Grammar.extend $_$ >> as e -> + fun _ _ _ k -> [: `extend e "" k :] + | <:expr< let $list:_$ in $_$ >> as e when is_gextend e -> + fun _ _ _ k -> [: `gextend e "" k :] ]; + +Pcaml.add_option "-no_slist" (Arg.Set no_slist) + "Don't reconstruct SLIST and SOPT"; diff --git a/camlp4/unmaintained/etc/pr_extfun.ml b/camlp4/unmaintained/etc/pr_extfun.ml new file mode 100644 index 0000000..4479bb4 --- /dev/null +++ b/camlp4/unmaintained/etc/pr_extfun.ml @@ -0,0 +1,92 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) + + +open Pcaml; +open Spretty; + +value _loc = Loc.mk "FIXME pr_extfun.ml"; + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +value rec un_extfun rpel = + fun + [ <:expr< [ ($_$, $_$, fun [ $list:pel$ ]) :: $el$ ] >> -> + let (p, wo, e) = + match pel with + [ [(p, wo, <:expr< Some $e$ >>); + (<:patt< _ >>, None, <:expr< None >>)] -> + (p, wo, e) + | [(p, wo, <:expr< Some $e$ >>)] -> (p, wo, e) + | _ -> raise Not_found ] + in + let rpel = + match rpel with + [ [(p1, wo1, e1) :: pel] -> + if wo1 = wo && e1 = e then + let p = + match (p1, p) with + [ (<:patt< ($x1$ as $x2$) >>, <:patt< ($y1$ as $y2$) >>) -> + if x2 = y2 then <:patt< ($x1$ | $y1$ as $x2$) >> + else <:patt< $p1$ | $p$ >> + | _ -> <:patt< $p1$ | $p$ >> ] + in + [(p, wo, e) :: pel] + else [(p, wo, e) :: rpel] + | [] -> [(p, wo, e)] ] + in + un_extfun rpel el + | <:expr< [] >> -> List.rev rpel + | _ -> raise Not_found ] +; + +value rec listwbws elem b sep el k = + match el with + [ [] -> [: b; k :] + | [x] -> [: `elem b x k :] + | [x :: l] -> [: `elem b x [: :]; listwbws elem [: `sep :] sep l k :] ] +; + +value rec match_assoc_list pwel k = + match pwel with + [ [pwe] -> match_assoc [: `S LR "[" :] pwe [: `S LR "]"; k :] + | pel -> + Vbox + [: `HVbox [: :]; + listwbws match_assoc [: `S LR "[" :] (S LR "|") pel + [: `S LR "]"; k :] :] ] +and match_assoc b (p, w, e) k = + let s = + let (p, k) = + match p with + [ <:patt< ($p$ as $p2$) >> -> (p, [: `S LR "as"; `patt p2 "" [: :] :]) + | _ -> (p, [: :]) ] + in + match w with + [ Some e1 -> + [: `HVbox + [: `HVbox [: :]; `patt p "" k; + `HVbox [: `S LR "when"; `expr e1 "" [: `S LR "->" :] :] :] :] + | _ -> [: `patt p "" [: k; `S LR "->" :] :] ] + in + HVbox [: b; `HVbox [: `HVbox s; `expr e "" k :] :] +; + +let lev = find_pr_level "top" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Extfun.extend $e$ $list$ >> as ge -> + fun _ next dg k -> + try + let pel = un_extfun [] list in + [: `HVbox [: :]; + `BEbox [: `S LR "extfun"; `expr e "" [: :]; `S LR "with" :]; + `match_assoc_list pel k :] + with + [ Not_found -> [: `next ge dg k :] ] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Extfun.extend $_$ $_$ >> as ge -> + fun _ next dg k -> [: `next ge dg k :] ]; diff --git a/camlp4/unmaintained/etc/pr_null.ml b/camlp4/unmaintained/etc/pr_null.ml new file mode 100644 index 0000000..22f3cb7 --- /dev/null +++ b/camlp4/unmaintained/etc/pr_null.ml @@ -0,0 +1,16 @@ +(* camlp4r *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +Pcaml.print_interf.val := fun _ -> (); +Pcaml.print_implem.val := fun _ -> (); diff --git a/camlp4/unmaintained/etc/pr_op.ml b/camlp4/unmaintained/etc/pr_op.ml new file mode 100644 index 0000000..9b2aebc --- /dev/null +++ b/camlp4/unmaintained/etc/pr_op.ml @@ -0,0 +1,210 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; +open Spretty; + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +value spatt p dg k = + match p with + [ <:patt< $lid:s$ >> -> + if String.length s >= 2 && s.[1] == ''' then + HVbox [: `S LR (" " ^ s); k :] + else patt p dg k + | _ -> patt p dg k ] +; + +(* Streams *) + +value stream e _ k = + let rec get = + fun + [ <:expr< Stream.iapp $x$ $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.icons $x$ $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.ising $x$ >> -> [(True, x)] + | <:expr< Stream.lapp (fun _ -> $x$) $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.lcons (fun _ -> $x$) $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.lsing (fun _ -> $x$) >> -> [(True, x)] + | <:expr< Stream.sempty >> -> [] + | <:expr< Stream.slazy (fun _ -> $x$) >> -> [(False, x)] + | <:expr< Stream.slazy $x$ >> -> [(False, <:expr< $x$ () >>)] + | e -> [(False, e)] ] + in + let elem e dg k = + match e with + [ (True, e) -> [: `HOVbox [: `S LO "'"; `expr e dg k :] :] + | (False, e) -> [: `expr e dg k :] ] + in + let rec glop e k = + match e with + [ [] -> k + | [e] -> [: elem e "" k :] + | [e :: el] -> [: elem e ";" [: `S RO ";" :]; glop el k :] ] + in + HOVbox [: `S LR "[<"; glop (get e) [: `S LR ">]"; k :] :] +; + +(* Parsers *) + +value parser_cases b spel dg k = + let rec parser_cases b spel dg k = + match spel with + [ [] -> [: `HVbox [: b; k :] :] + | [(sp, epo, e)] -> [: `parser_case b sp epo e dg k :] + | [(sp, epo, e) :: spel] -> + [: `parser_case b sp epo e "|" [: :]; + parser_cases [: `S LR "|" :] spel dg k :] ] + and parser_case b sp epo e dg k = + let epo = + match epo with + [ Some p -> [: `patt p "" [: `S LR "->" :] :] + | _ -> [: `S LR "->" :] ] + in + HVbox + [: b; + `HOVbox + [: `HOVbox + [: `S LR "[<"; + stream_patt [: :] sp [: `S LR ">]"; epo :] :]; + `expr e dg k :] :] + and stream_patt b sp k = + match sp with + [ [] -> [: `HVbox [: b; k :] :] + | [(spc, None)] -> [: `stream_patt_comp b spc "" k :] + | [(spc, Some e)] -> + [: `HVbox + [: `stream_patt_comp b spc "" [: :]; + `HVbox [: `S LR "??"; `expr e "" k :] :] :] + | [(spc, None) :: spcl] -> + [: `stream_patt_comp b spc ";" [: `S RO ";" :]; + stream_patt [: :] spcl k :] + | [(spc, Some e) :: spcl] -> + [: `HVbox + [: `stream_patt_comp b spc "" [: :]; + `HVbox [: `S LR "??"; `expr e ";" [: `S RO ";" :] :] :]; + stream_patt [: :] spcl k :] ] + and stream_patt_comp b spc dg k = + match spc with + [ SPCterm (p, w) -> + HVbox [: b; `S LO "'"; `spatt p "" (when_opt w k) :] + | SPCnterm p e -> + HVbox [: b; `HVbox [: `patt p "" [: `S LR "=" :]; `expr e dg k :] :] + | SPCsterm p -> HVbox [: b; `patt p "" k :] ] + and when_opt wo k = + match wo with + [ Some e -> [: `S LR "when"; `expr e "" k :] + | _ -> k ] + in + parser_cases b spel dg k +; + +value parser_body e dg k = + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + match Parserify.parser_of_expr e with + [ [] -> + let spe = ([], None, <:expr< raise Stream.Failure >>) in + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] [spe] dg k :] + | spel -> + BEVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] spel dg k :] ] +; + +value pmatch e dg k = + let (me, e) = + match e with + [ <:expr< let (__strm : Stream.t _) = $me$ in $e$ >> -> (me, e) + | _ -> failwith "Pr_op.pmatch" ] + in + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + let spel = Parser_of_expr.parser_of_expr e in + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "match"; `expr me "" [: `S LR "with" :]; `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + `BEbox [: `HVbox [: :]; parser_cases [: :] spel dg k :] :] +; + +(* Printer extensions *) + +pr_expr_fun_args.val := + extfun pr_expr_fun_args.val with + [ <:expr< fun __strm -> $_$ >> as ge -> ([], ge) + | <:expr< fun [(__strm : $_$) -> $_$] >> as ge -> ([], ge) ]; + +let lev = find_pr_level "expr1" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< let (__strm : Stream.t _) = $_$ in $_$ >> as e -> + fun curr next dg k -> + if not (List.mem dg ["|"; ";"]) then [: `pmatch e dg k :] + else [: `S LO "("; `pmatch e "" [: `S RO ")"; k :] :] + | <:expr< fun __strm -> $x$ >> -> + fun curr next dg k -> + if not (List.mem dg ["|"; ";"]) then [: `parser_body x dg k :] + else [: `S LO "("; `parser_body x "" [: `S RO ")"; k :] :] + | <:expr< fun [ (__strm : $_$) -> $x$ ] >> -> + fun curr next dg k -> + if not (List.mem dg ["|"; ";"]) then [: `parser_body x dg k :] + else [: `S LO "("; `parser_body x "" [: `S RO ")"; k :] :] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun curr next dg k -> [: `next e "" k :] ]; + +let lev = find_pr_level "dot" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.sempty >> as e -> + fun curr next dg k -> [: `next e "" k :] ]; + +let lev = find_pr_level "simple" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun curr next dg k -> + [: `stream e "" k :] ]; diff --git a/camlp4/unmaintained/etc/pr_op_main.ml b/camlp4/unmaintained/etc/pr_op_main.ml new file mode 100644 index 0000000..3ea53ba --- /dev/null +++ b/camlp4/unmaintained/etc/pr_op_main.ml @@ -0,0 +1,214 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; +open Spretty; + +value _loc = Loc.mk "FIXME pr_op_main.ml"; + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +value spatt p dg k = + match p with + [ <:patt< $lid:s$ >> -> + if String.length s >= 2 && s.[1] == ''' then + HVbox [: `S LR (" " ^ s); k :] + else patt p dg k + | _ -> patt p dg k ] +; + +(* Streams *) + +value stream e _ k = + let rec get = + fun + [ <:expr< Stream.iapp $x$ $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.icons $x$ $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.ising $x$ >> -> [(True, x)] + | <:expr< Stream.lapp (fun _ -> $x$) $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.lcons (fun _ -> $x$) $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.lsing (fun _ -> $x$) >> -> [(True, x)] + | <:expr< Stream.sempty >> -> [] + | <:expr< Stream.slazy (fun _ -> $x$) >> -> [(False, x)] + | <:expr< Stream.slazy $x$ >> -> [(False, <:expr< $x$ () >>)] + | e -> [(False, e)] ] + in + let elem e dg k = + match e with + [ (True, e) -> [: `HOVbox [: `S LO "'"; `expr e dg k :] :] + | (False, e) -> [: `expr e dg k :] ] + in + let rec glop e k = + match e with + [ [] -> k + | [e] -> [: elem e "" k :] + | [e :: el] -> [: elem e ";" [: `S RO ";" :]; glop el k :] ] + in + HOVbox [: `S LR "[<"; glop (get e) [: `S LR ">]"; k :] :] +; + +(* Parsers *) + +open Parserify; + +value parser_cases b spel dg k = + let rec parser_cases b spel dg k = + match spel with + [ [] -> [: `HVbox [: b; k :] :] + | [(sp, epo, e)] -> [: `parser_case b sp epo e dg k :] + | [(sp, epo, e) :: spel] -> + [: `parser_case b sp epo e "|" [: :]; + parser_cases [: `S LR "|" :] spel dg k :] ] + and parser_case b sp epo e dg k = + let epo = + match epo with + [ Some p -> [: `patt p "" [: `S LR "->" :] :] + | _ -> [: `S LR "->" :] ] + in + HVbox + [: b; + `HOVbox + [: `HOVbox + [: `S LR "[<"; + stream_patt [: :] sp [: `S LR ">]"; epo :] :]; + `expr e dg k :] :] + and stream_patt b sp k = + match sp with + [ [] -> [: `HVbox [: b; k :] :] + | [(spc, None)] -> [: `stream_patt_comp b spc "" k :] + | [(spc, Some e)] -> + [: `HVbox + [: `stream_patt_comp b spc "" [: :]; + `HVbox [: `S LR "??"; `expr e "" k :] :] :] + | [(spc, None) :: spcl] -> + [: `stream_patt_comp b spc ";" [: `S RO ";" :]; + stream_patt [: :] spcl k :] + | [(spc, Some e) :: spcl] -> + [: `HVbox + [: `stream_patt_comp b spc "" [: :]; + `HVbox [: `S LR "??"; `expr e ";" [: `S RO ";" :] :] :]; + stream_patt [: :] spcl k :] ] + and stream_patt_comp b spc dg k = + match spc with + [ SPCterm (p, w) -> + HVbox [: b; `S LO "'"; `spatt p "" (when_opt w k) :] + | SPCnterm p e -> + HVbox [: b; `HVbox [: `patt p "" [: `S LR "=" :]; `expr e dg k :] :] + | SPCsterm p -> HVbox [: b; `patt p "" k :] ] + and when_opt wo k = + match wo with + [ Some e -> [: `S LR "when"; `expr e "" k :] + | _ -> k ] + in + parser_cases b spel dg k +; + +value parser_body e dg k = + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + match parser_of_expr e with + [ [] -> + let spe = ([], None, <:expr< raise Stream.Failure >>) in + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] [spe] dg k :] + | spel -> + BEVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] spel dg k :] ] +; + +value pmatch e dg k = + let (me, e) = + match e with + [ <:expr< let (__strm : Stream.t _) = $me$ in $e$ >> -> (me, e) + | _ -> failwith "Pr_op.pmatch" ] + in + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + let spel = parser_of_expr e in + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "match"; `expr me "" [: `S LR "with" :]; `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + `BEbox [: `HVbox [: :]; parser_cases [: :] spel dg k :] :] +; + +(* Printer extensions *) + +pr_expr_fun_args.val := + extfun pr_expr_fun_args.val with + [ <:expr< fun __strm -> $_$ >> as ge -> ([], ge) + | <:expr< fun [(__strm : $_$) -> $_$] >> as ge -> ([], ge) ]; + +let lev = find_pr_level "expr1" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< let (__strm : Stream.t _) = $_$ in $_$ >> as e -> + fun _ _ dg k -> + if not (List.mem dg ["|"; ";"]) then [: `pmatch e dg k :] + else [: `S LO "("; `pmatch e "" [: `S RO ")"; k :] :] + | <:expr< fun __strm -> $x$ >> -> + fun _ _ dg k -> + if not (List.mem dg ["|"; ";"]) then [: `parser_body x dg k :] + else [: `S LO "("; `parser_body x "" [: `S RO ")"; k :] :] + | <:expr< fun [ (__strm : $_$) -> $x$ ] >> -> + fun _ _ dg k -> + if not (List.mem dg ["|"; ";"]) then [: `parser_body x dg k :] + else [: `S LO "("; `parser_body x "" [: `S RO ")"; k :] :] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "dot" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.sempty >> as e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "simple" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun _ _ _ k -> + [: `stream e "" k :] ]; diff --git a/camlp4/unmaintained/etc/pr_rp.ml b/camlp4/unmaintained/etc/pr_rp.ml new file mode 100644 index 0000000..0604b46 --- /dev/null +++ b/camlp4/unmaintained/etc/pr_rp.ml @@ -0,0 +1,207 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; +open Spretty; + +value _loc = (Token.nowhere, Token.nowhere); + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +(* Streams *) + +value stream e dg k = + let rec get = + fun + [ <:expr< Stream.iapp $x$ $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.icons $x$ $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.ising $x$ >> -> [(True, x)] + | <:expr< Stream.lapp (fun _ -> $x$) $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.lcons (fun _ -> $x$) $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.lsing (fun _ -> $x$) >> -> [(True, x)] + | <:expr< Stream.sempty >> -> [] + | <:expr< Stream.slazy (fun _ -> $x$) >> -> [(False, x)] + | <:expr< Stream.slazy $x$ >> -> [(False, <:expr< $x$ () >>)] + | e -> [(False, e)] ] + in + let elem e k = + match e with + [ (True, e) -> [: `HOVbox [: `S LO "`"; `expr e "" k :] :] + | (False, e) -> [: `expr e "" k :] ] + in + let rec glop e k = + match e with + [ [] -> k + | [e] -> [: elem e k :] + | [e :: el] -> [: elem e [: `S RO ";" :]; glop el k :] ] + in + HOVbox [: `S LR "[:"; glop (get e) [: `S LR ":]"; k :] :] +; + +(* Parsers *) + +value parser_cases b spel k = + let rec parser_cases b spel k = + match spel with + [ [] -> [: `HVbox [: b; k :] :] + | [(sp, epo, e)] -> [: `parser_case b sp epo e k :] + | [(sp, epo, e) :: spel] -> + [: `parser_case b sp epo e [: :]; + parser_cases [: `S LR "|" :] spel k :] ] + and parser_case b sp epo e k = + let epo = + match epo with + [ Some p -> [: `patt p "" [: `S LR "->" :] :] + | _ -> [: `S LR "->" :] ] + in + HVbox + [: b; + `HOVbox + [: `HOVbox + [: `S LR "[:"; + stream_patt [: :] sp [: `S LR ":]"; epo :] :]; + `expr e "" k :] :] + and stream_patt b sp k = + match sp with + [ [] -> [: `HVbox [: b; k :] :] + | [(spc, None)] -> [: `stream_patt_comp b spc k :] + | [(spc, Some e)] -> + [: `HVbox + [: `stream_patt_comp b spc [: :]; + `HVbox [: `S LR "?"; `expr e "" k :] :] :] + | [(spc, None) :: spcl] -> + [: `stream_patt_comp b spc [: `S RO ";" :]; + stream_patt [: :] spcl k :] + | [(spc, Some e) :: spcl] -> + [: `HVbox + [: `stream_patt_comp b spc [: :]; + `HVbox [: `S LR "?"; `expr e "" [: `S RO ";" :] :] :]; + stream_patt [: :] spcl k :] ] + and stream_patt_comp b spc k = + match spc with + [ SPCterm (p, w) -> + HVbox [: b; `S LO "`"; `patt p "" [: :]; `HVbox [: when_opt w k :] :] + | SPCnterm p e -> + HVbox [: b; `HVbox [: `patt p "" [: `S LR "=" :]; `expr e "" k :] :] + | SPCsterm p -> HVbox [: b; `patt p "" k :] ] + and when_opt wo k = + match wo with + [ Some e -> [: `S LR "when"; `expr e "" k :] + | _ -> k ] + in + parser_cases b spel k +; + +value parser_body e dg k = + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + match Parserify.parser_of_expr e with + [ [] -> + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + `HVbox [: `S LR "[]"; k :] :] + | [spe] -> + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] [spe] k :] + | spel -> + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: `S LR "[" :] spel [: `S LR "]"; k :] :] ] +; + +value pmatch e dg k = + let (me, e) = + match e with + [ <:expr< let (__strm : Stream.t _) = $me$ in $e$ >> -> (me, e) + | <:expr< match $_$ __strm with [ $list:_$ ] >> -> (<:expr< __strm >>, e) + | _ -> failwith "Pr_rp.pmatch" ] + in + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + let spel = Parserify.parser_of_expr e in + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "match"; `expr me "" [: `S LR "with" :]; `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: `S LR "[" :] spel [: `S LR "]"; k :] :] +; + +(* Printer extensions *) + +pr_expr_fun_args.val := + extfun pr_expr_fun_args.val with + [ <:expr< fun __strm -> $_$ >> as ge -> ([], ge) + | <:expr< fun [(__strm : $_$) -> $_$] >> as ge -> ([], ge) ]; + +let lev = find_pr_level "top" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< let (__strm : Stream.t _) = $_$ in $_$ >> as e -> + fun curr next _ k -> [: `pmatch e "" k :] + | <:expr< match $_$ __strm with [ $list:_$ ] >> as e -> + fun curr next _ k -> [: `pmatch e "" k :] + | <:expr< fun __strm -> $x$ >> -> + fun curr next _ k -> [: `parser_body x "" k :] + | <:expr< fun (__strm : $_$) -> $x$ >> -> + fun curr next _ k -> [: `parser_body x "" k :] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun curr next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "dot" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.sempty >> as e -> + fun curr next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "simple" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun curr next _ k -> [: `stream e "" k :] ]; diff --git a/camlp4/unmaintained/etc/pr_rp_main.ml b/camlp4/unmaintained/etc/pr_rp_main.ml new file mode 100644 index 0000000..534d407 --- /dev/null +++ b/camlp4/unmaintained/etc/pr_rp_main.ml @@ -0,0 +1,206 @@ +(* camlp4r q_MLast.cmo ./pa_extfun.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; +open Spretty; + +value _loc = Loc.mk "FIXME pr_rp_main.ml"; + +value expr e dg k = pr_expr.pr_fun "top" e dg k; +value patt e dg k = pr_patt.pr_fun "top" e dg k; + +(* Streams *) + +value stream e _ k = + let rec get = + fun + [ <:expr< Stream.iapp $x$ $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.icons $x$ $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.ising $x$ >> -> [(True, x)] + | <:expr< Stream.lapp (fun _ -> $x$) $y$ >> -> [(False, x) :: get y] + | <:expr< Stream.lcons (fun _ -> $x$) $y$ >> -> [(True, x) :: get y] + | <:expr< Stream.lsing (fun _ -> $x$) >> -> [(True, x)] + | <:expr< Stream.sempty >> -> [] + | <:expr< Stream.slazy (fun _ -> $x$) >> -> [(False, x)] + | <:expr< Stream.slazy $x$ >> -> [(False, <:expr< $x$ () >>)] + | e -> [(False, e)] ] + in + let elem e k = + match e with + [ (True, e) -> [: `HOVbox [: `S LO "`"; `expr e "" k :] :] + | (False, e) -> [: `expr e "" k :] ] + in + let rec glop e k = + match e with + [ [] -> k + | [e] -> [: elem e k :] + | [e :: el] -> [: elem e [: `S RO ";" :]; glop el k :] ] + in + HOVbox [: `S LR "[:"; glop (get e) [: `S LR ":]"; k :] :] +; + +(* Parsers *) + +open Parserify; + +value parser_cases b spel k = + let rec parser_cases b spel k = + match spel with + [ [] -> [: `HVbox [: b; k :] :] + | [(sp, epo, e)] -> [: `parser_case b sp epo e k :] + | [(sp, epo, e) :: spel] -> + [: `parser_case b sp epo e [: :]; + parser_cases [: `S LR "|" :] spel k :] ] + and parser_case b sp epo e k = + let epo = + match epo with + [ Some p -> [: `patt p "" [: `S LR "->" :] :] + | _ -> [: `S LR "->" :] ] + in + HVbox + [: b; + `HOVbox + [: `HOVbox + [: `S LR "[:"; + stream_patt [: :] sp [: `S LR ":]"; epo :] :]; + `expr e "" k :] :] + and stream_patt b sp k = + match sp with + [ [] -> [: `HVbox [: b; k :] :] + | [(spc, None)] -> [: `stream_patt_comp b spc k :] + | [(spc, Some e)] -> + [: `HVbox + [: `stream_patt_comp b spc [: :]; + `HVbox [: `S LR "?"; `expr e "" k :] :] :] + | [(spc, None) :: spcl] -> + [: `stream_patt_comp b spc [: `S RO ";" :]; + stream_patt [: :] spcl k :] + | [(spc, Some e) :: spcl] -> + [: `HVbox + [: `stream_patt_comp b spc [: :]; + `HVbox [: `S LR "?"; `expr e "" [: `S RO ";" :] :] :]; + stream_patt [: :] spcl k :] ] + and stream_patt_comp b spc k = + match spc with + [ SPCterm (p, w) -> + HVbox [: b; `S LO "`"; `patt p "" [: :]; `HVbox [: when_opt w k :] :] + | SPCnterm p e -> + HVbox [: b; `HVbox [: `patt p "" [: `S LR "=" :]; `expr e "" k :] :] + | SPCsterm p -> HVbox [: b; `patt p "" k :] ] + and when_opt wo k = + match wo with + [ Some e -> [: `S LR "when"; `expr e "" k :] + | _ -> k ] + in + parser_cases b spel k +; + +value parser_body e _ k = + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + match parser_of_expr e with + [ [] -> + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + `HVbox [: `S LR "[]"; k :] :] + | [spe] -> + HVbox + [: `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: :] [spe] k :] + | spel -> + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: `S LR "[" :] spel [: `S LR "]"; k :] :] ] +; + +value pmatch e _ k = + let (me, e) = + match e with + [ <:expr< let (__strm : Stream.t _) = $me$ in $e$ >> -> (me, e) + | _ -> failwith "Pr_rp.pmatch" ] + in + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + let spel = parser_of_expr e in + Vbox + [: `HVbox [: :]; + `HVbox + [: `S LR "match"; `expr me "" [: `S LR "with" :]; `S LR "parser"; + match bp with + [ Some p -> [: `patt p "" [: :] :] + | _ -> [: :] ] :]; + parser_cases [: `S LR "[" :] spel [: `S LR "]"; k :] :] +; + +(* Printer extensions *) + +pr_expr_fun_args.val := + extfun pr_expr_fun_args.val with + [ <:expr< fun __strm -> $_$ >> as ge -> ([], ge) + | <:expr< fun [(__strm : $_$) -> $_$] >> as ge -> ([], ge) ]; + +let lev = find_pr_level "top" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< let (__strm : Stream.t _) = $_$ in $_$ >> as e -> + fun _ _ _ k -> [: `pmatch e "" k :] + | <:expr< fun __strm -> $x$ >> -> + fun _ _ _ k -> [: `parser_body x "" k :] + | <:expr< fun (__strm : $_$) -> $x$ >> -> + fun _ _ _ k -> [: `parser_body x "" k :] ]; + +let lev = find_pr_level "apply" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "dot" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.sempty >> as e -> + fun _ next _ k -> [: `next e "" k :] ]; + +let lev = find_pr_level "simple" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< Stream.iapp $_$ $_$ >> | <:expr< Stream.icons $_$ $_$ >> | + <:expr< Stream.ising $_$ >> | <:expr< Stream.lapp (fun _ -> $_$) $_$ >> | + <:expr< Stream.lcons (fun _ -> $_$) $_$ >> | + <:expr< Stream.lsing (fun _ -> $_$) >> | <:expr< Stream.sempty >> | + <:expr< Stream.slazy $_$ >> as e -> + fun _ _ _ k -> [: `stream e "" k :] ]; diff --git a/camlp4/unmaintained/etc/q_phony.ml b/camlp4/unmaintained/etc/q_phony.ml new file mode 100644 index 0000000..e490808 --- /dev/null +++ b/camlp4/unmaintained/etc/q_phony.ml @@ -0,0 +1,38 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +open Pcaml; + +value t = ref ""; + +Quotation.add "" + (Quotation.ExAst + (fun c s -> + let _loc = c.Quotation.loc in + let t = + if t.val = "" then "<<" ^ s ^ ">>" + else "<:" ^ t.val ^ "<" ^ s ^ ">>" + in + <:expr< $uid:t$ >>, + fun c s -> + let _loc = c.Quotation.loc in + let t = + if t.val = "" then "<<" ^ s ^ ">>" + else "<:" ^ t.val ^ "<" ^ s ^ ">>" + in + <:patt< $uid:t$ >>)) +; + +Quotation.default.val := ""; +Quotation.translate.val := fun s -> do { t.val := s; "" }; diff --git a/camlp4/unmaintained/extfold/README b/camlp4/unmaintained/extfold/README new file mode 100644 index 0000000..2a09ff0 --- /dev/null +++ b/camlp4/unmaintained/extfold/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + Nicolas Pouillard diff --git a/camlp4/unmaintained/extfold/pa_extfold.ml b/camlp4/unmaintained/extfold/pa_extfold.ml new file mode 100644 index 0000000..aa8e922 --- /dev/null +++ b/camlp4/unmaintained/extfold/pa_extfold.ml @@ -0,0 +1,42 @@ +(* camlp4r pa_extend.cmo q_MLast.cmo *) + + +open Pcaml; +open Pa_extend; + +value sfold _loc n foldfun f e s = + let styp = STquo _loc (new_type_var ()) in + let e = <:expr< Extfold.$lid:foldfun$ $f$ $e$ >> in + let t = STapp _loc (STapp _loc (STtyp <:ctyp< Extfold.t _ >>) s.styp) styp in + {used = s.used; text = TXmeta _loc n [s.text] e t; styp = styp} +; + +value sfoldsep _loc n foldfun f e s sep = + let styp = STquo _loc (new_type_var ()) in + let e = <:expr< Extfold.$lid:foldfun$ $f$ $e$ >> in + let t = + STapp _loc (STapp _loc (STtyp <:ctyp< Extfold.tsep _ >>) s.styp) styp + in + {used = s.used @ sep.used; text = TXmeta _loc n [s.text; sep.text] e t; + styp = styp} +; + +EXTEND + GLOBAL: symbol; + symbol: LEVEL "top" + [ [ UIDENT "FOLD0"; f = simple_expr; e = simple_expr; s = SELF -> + sfold _loc "FOLD0" "sfold0" f e s + | UIDENT "FOLD1"; f = simple_expr; e = simple_expr; s = SELF -> + sfold _loc "FOLD1" "sfold1" f e s + | UIDENT "FOLD0"; f = simple_expr; e = simple_expr; s = SELF; + UIDENT "SEP"; sep = symbol -> + sfoldsep _loc "FOLD0 SEP" "sfold0sep" f e s sep + | UIDENT "FOLD1"; f = simple_expr; e = simple_expr; s = SELF; + UIDENT "SEP"; sep = symbol -> + sfoldsep _loc "FOLD1 SEP" "sfold1sep" f e s sep ] ] + ; + simple_expr: + [ [ i = LIDENT -> <:expr< $lid:i$ >> + | "("; e = expr; ")" -> e ] ] + ; +END; diff --git a/camlp4/unmaintained/format/.depend b/camlp4/unmaintained/format/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/format/Makefile b/camlp4/unmaintained/format/Makefile new file mode 100644 index 0000000..c388720 --- /dev/null +++ b/camlp4/unmaintained/format/Makefile @@ -0,0 +1,61 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_format +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. +CAMLP4=../../camlp4/camlp4$(EXE) + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) + +P4INCLUDES= -nolib -I ../../lib -I ../../meta -I ../../etc +OCAMLINCLUDES= -nostdlib -I $(OCAMLTOP)/stdlib -I ../../lib -I ../../camlp4 +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SRC=pa_format.ml +OBJS=$(SRC:.ml=.cmo) +OBJSX=$(SRC:.ml=.cmx) + +all: $(OBJS) + +opt: $(OBJSX) + +depend: + cp .depend .depend.bak + > .depend + for file in $(SRC); do \ + $(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $$file` pr_depend.cmo $$i | \ + sed -e 's| \.\./\.\./\.\.| $$(OCAMLTOP)|g' >> .depend; \ + done + +clean: + rm -f *.cm* *.$(O) *.bak .*.bak + + +.SUFFIXES: .cmx .cmo .cmi .ml .mli + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +include .depend diff --git a/camlp4/unmaintained/format/README b/camlp4/unmaintained/format/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/format/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/format/pa_format.ml b/camlp4/unmaintained/format/pa_format.ml new file mode 100644 index 0000000..640a750 --- /dev/null +++ b/camlp4/unmaintained/format/pa_format.ml @@ -0,0 +1,52 @@ +(* pa_r.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + +open Pcaml; + +EXTEND + GLOBAL: expr; + expr: LEVEL "top" + [ [ n = box_type; d = SELF; "begin"; + el = LIST0 [ e = box_expr; ";" -> e ]; "end" -> + let el = [<:expr< Format.$lid:"open_" ^ n$ $d$ >> :: el] in + let el = el @ [<:expr< Format.close_box () >>] in + <:expr< do { $list:el$ } >> + | "hbox"; "begin"; el = LIST0 [ e = box_expr; ";" -> e ]; "end" -> + let el = [<:expr< Format.open_hbox () >> :: el] in + let el = el @ [<:expr< Format.close_box () >>] in + <:expr< do { $list:el$ } >> + | "nobox"; "begin"; el = LIST0 [ e = box_expr; ";" -> e ]; "end" -> + match el with + [ [e] -> e + | _ -> <:expr< do { $list:el$ } >> ] ] ] + ; + box_type: + [ [ n = "hovbox" -> n + | n = "hvbox" -> n + | n = "vbox" -> n + | n = "box" -> n ] ] + ; + box_expr: + [ [ s = STRING -> <:expr< Format.print_string $str:s$ >> + | UIDENT "STRING"; e = expr -> <:expr< Format.print_string $e$ >> + | UIDENT "INT"; e = expr -> <:expr< Format.print_int $e$ >> + | "/-" -> <:expr< Format.print_space () >> + | "//" -> <:expr< Format.print_cut () >> + | "!/" -> <:expr< Format.force_newline () >> + | "?/" -> <:expr< Format.print_if_newline () >> + | e = expr -> e ] ] + ; +END; diff --git a/camlp4/unmaintained/lefteval/.depend b/camlp4/unmaintained/lefteval/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/lefteval/Makefile b/camlp4/unmaintained/lefteval/Makefile new file mode 100644 index 0000000..7e5cdd0 --- /dev/null +++ b/camlp4/unmaintained/lefteval/Makefile @@ -0,0 +1,61 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_lefteval +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. +CAMLP4=../../camlp4/camlp4$(EXE) + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) + +P4INCLUDES= -nolib -I ../../meta -I ../../etc +OCAMLINCLUDES= -nostdlib -I $(OCAMLTOP)/stdlib -I ../../camlp4 +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SRC=pa_lefteval.ml +OBJS=$(SRC:.ml=.cmo) +OBJSX=$(SRC:.ml=.cmx) + +all: $(OBJS) + +opt: $(OBJSX) + +depend: + cp .depend .depend.bak + > .depend + for file in $(SRC); do \ + $(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $$file` pr_depend.cmo $$i | \ + sed -e 's| \.\./\.\./\.\.| $$(OCAMLTOP)|g' >> .depend; \ + done + +clean: + rm -f *.cm* *.$(O) *.bak .*.bak + + +.SUFFIXES: .cmx .cmo .cmi .ml .mli + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +include .depend diff --git a/camlp4/unmaintained/lefteval/README b/camlp4/unmaintained/lefteval/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/lefteval/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/lefteval/pa_lefteval.ml b/camlp4/unmaintained/lefteval/pa_lefteval.ml new file mode 100644 index 0000000..56ad297 --- /dev/null +++ b/camlp4/unmaintained/lefteval/pa_lefteval.ml @@ -0,0 +1,241 @@ +(* pa_r.cmo q_MLast.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + +value not_impl name x = + let desc = + if Obj.is_block (Obj.repr x) then + "tag = " ^ string_of_int (Obj.tag (Obj.repr x)) + else "int_val = " ^ string_of_int (Obj.magic x) + in + failwith ("pa_lefteval: not impl: " ^ name ^ "; " ^ desc ^ ">") +; + +value rec expr_fa al = + fun + [ <:expr< $f$ $a$ >> -> expr_fa [a :: al] f + | f -> (f, al) ] +; + +(* generating let..in before functions calls which evaluates + several (more than one) of their arguments *) + +value no_side_effects_ht = + let ht = Hashtbl.create 73 in + do { + List.iter (fun s -> Hashtbl.add ht s True) + ["<"; "="; "@"; "^"; "+"; "-"; "ref"]; + ht + } +; + +value no_side_effects = + fun + [ <:expr< $uid:_$ >> -> True + | <:expr< $uid:_$ . $uid:_$ >> -> True + | <:expr< $lid:s$ >> -> + try Hashtbl.find no_side_effects_ht s with [ Not_found -> False ] + | _ -> False ] +; + +value rec may_side_effect = + fun + [ <:expr< $lid:_$ >> | <:expr< $uid:_$ >> | <:expr< $str:_$ >> | + <:expr< $chr:_$ >> | <:expr< $int:_$ >> | <:expr< $flo:_$ >> | + <:expr< $_$ . $_$ >> | <:expr< fun [ $list:_$ ] >> -> + False + | <:expr< ($list:el$) >> -> List.exists may_side_effect el + | <:expr< $_$ $_$ >> as e -> + let (f, el) = expr_fa [] e in + not (no_side_effects f) || List.exists may_side_effect el + | _ -> True ] +; + +value rec may_be_side_effect_victim = + fun + [ <:expr< $lid:_$ . $_$ >> -> True + | <:expr< $uid:_$ . $e$ >> -> may_be_side_effect_victim e + | _ -> False ] +; + +value rec may_depend_on_order el = + loop False False el where rec loop + side_effect_found side_effect_victim_found = + fun + [ [e :: el] -> + if may_side_effect e then + if side_effect_found || side_effect_victim_found then True + else loop True True el + else if may_be_side_effect_victim e then + if side_effect_found then True else loop False True el + else loop side_effect_found side_effect_victim_found el + | [] -> False ] +; + +value gen_let_in loc expr el = + let (pel, el) = + loop 0 (List.rev el) where rec loop n = + fun + [ [e :: el] -> + if may_side_effect e || may_be_side_effect_victim e then + if n = 0 then + let (pel, el) = loop 1 el in + (pel, [expr e :: el]) + else + let id = "xxx" ^ string_of_int n in + let (pel, el) = loop (n + 1) el in + ([(<:patt< $lid:id$ >>, expr e) :: pel], + [<:expr< $lid:id$ >> :: el]) + else + let (pel, el) = loop n el in + (pel, [expr e :: el]) + | [] -> ([], []) ] + in + match List.rev el with + [ [e :: el] -> (pel, e, el) + | _ -> assert False ] +; + +value left_eval_apply loc expr e1 e2 = + let (f, el) = expr_fa [] <:expr< $e1$ $e2$ >> in + if not (may_depend_on_order [f :: el]) then <:expr< $expr e1$ $expr e2$ >> + else + let (pel, e, el) = gen_let_in loc expr [f :: el] in + let e = List.fold_left (fun e e1 -> <:expr< $e$ $e1$ >>) e el in + List.fold_left (fun e (p1, e1) -> <:expr< let $p1$ = $e1$ in $e$ >>) e pel +; + +value left_eval_tuple loc expr el = + if not (may_depend_on_order el) then <:expr< ($list:List.map expr el$) >> + else + let (pel, e, el) = gen_let_in loc expr el in + List.fold_left (fun e (p1, e1) -> <:expr< let $p1$ = $e1$ in $e$ >>) + <:expr< ($list:[e :: el]$) >> pel +; + +value left_eval_record loc expr lel = + let el = List.map snd lel in + if not (may_depend_on_order el) then + let lel = List.map (fun (p, e) -> (p, expr e)) lel in + <:expr< { $list:lel$ } >> + else + let (pel, e, el) = gen_let_in loc expr el in + let e = + let lel = List.combine (List.map fst lel) [e :: el] in + <:expr< { $list:lel$ } >> + in + List.fold_left (fun e (p1, e1) -> <:expr< let $p1$ = $e1$ in $e$ >>) e pel +; + +value left_eval_assign loc expr e1 e2 = <:expr< $e1$ := $expr e2$ >>; + +(* scanning the input tree, calling "left_eval_*" functions if necessary *) + +value map_option f = + fun + [ Some x -> Some (f x) + | None -> None ] +; + +value class_infos f ci = + {MLast.ciLoc = ci.MLast.ciLoc; MLast.ciVir = ci.MLast.ciVir; + MLast.ciPrm = ci.MLast.ciPrm; MLast.ciNam = ci.MLast.ciNam; + MLast.ciExp = f ci.MLast.ciExp} +; + +value rec expr x = + let loc = MLast.loc_of_expr x in + match x with + [ <:expr< fun [ $list:pwel$ ] >> -> + <:expr< fun [ $list:List.map match_assoc pwel$ ] >> + | <:expr< match $e$ with [ $list:pwel$ ] >> -> + <:expr< match $expr e$ with [ $list:List.map match_assoc pwel$ ] >> + | <:expr< try $e$ with [ $list:pwel$ ] >> -> + <:expr< try $expr e$ with [ $list:List.map match_assoc pwel$ ] >> + | <:expr< let $opt:rf$ $list:pel$ in $e$ >> -> + <:expr< let $opt:rf$ $list:List.map let_binding pel$ in $expr e$ >> + | <:expr< let module $s$ = $me$ in $e$ >> -> + <:expr< let module $s$ = $module_expr me$ in $expr e$ >> + | <:expr< if $e1$ then $e2$ else $e3$ >> -> + <:expr< if $expr e1$ then $expr e2$ else $expr e3$ >> + | <:expr< while $e$ do { $list:el$ } >> -> + <:expr< while $expr e$ do { $list:List.map expr el$ } >> + | <:expr< do { $list:el$ } >> -> <:expr< do { $list:List.map expr el$ } >> + | <:expr< $e$ # $s$ >> -> <:expr< $expr e$ # $s$ >> + | <:expr< ($e$ : $t$) >> -> <:expr< ($expr e$ : $t$) >> + | <:expr< $e1$ || $e2$ >> -> <:expr< $expr e1$ || $expr e2$ >> + | <:expr< $e1$ && $e2$ >> -> <:expr< $expr e1$ && $expr e2$ >> + | <:expr< $e1$ $e2$ >> -> left_eval_apply loc expr e1 e2 + | <:expr< ($list:el$) >> -> left_eval_tuple loc expr el + | <:expr< { $list:lel$ } >> -> left_eval_record loc expr lel + | <:expr< $e1$ := $e2$ >> -> left_eval_assign loc expr e1 e2 + | <:expr< $_$ . $_$ >> | <:expr< $uid:_$ >> | <:expr< $lid:_$ >> | + <:expr< $str:_$ >> | <:expr< $chr:_$ >> | <:expr< $int:_$ >> | + <:expr< $flo:_$ >> | <:expr< new $list:_$ >> -> + x + | x -> not_impl "expr" x ] +and let_binding (p, e) = (p, expr e) +and match_assoc (p, eo, e) = (p, map_option expr eo, expr e) +and module_expr x = + let loc = MLast.loc_of_module_expr x in + match x with + [ <:module_expr< functor ($s$ : $mt$) -> $me$ >> -> + <:module_expr< functor ($s$ : $mt$) -> $module_expr me$ >> + | <:module_expr< ($me$ : $mt$) >> -> + <:module_expr< ($module_expr me$ : $mt$) >> + | <:module_expr< struct $list:sil$ end >> -> + <:module_expr< struct $list:List.map str_item sil$ end >> + | <:module_expr< $_$ . $_$ >> | <:module_expr< $_$ $_$ >> | + <:module_expr< $uid:_$ >> -> + x ] +and str_item x = + let loc = MLast.loc_of_str_item x in + match x with + [ <:str_item< module $s$ = $me$ >> -> + <:str_item< module $s$ = $module_expr me$ >> + | <:str_item< value $opt:rf$ $list:pel$ >> -> + <:str_item< value $opt:rf$ $list:List.map let_binding pel$ >> + | <:str_item< declare $list:sil$ end >> -> + <:str_item< declare $list:List.map str_item sil$ end >> + | <:str_item< class $list:ce$ >> -> + <:str_item< class $list:List.map (class_infos class_expr) ce$ >> + | <:str_item< $exp:e$ >> -> <:str_item< $exp:expr e$ >> + | <:str_item< open $_$ >> | <:str_item< type $list:_$ >> | + <:str_item< exception $_$ of $list:_$ = $_$ >> | + <:str_item< module type $_$ = $_$ >> | <:str_item< # $_$ $opt:_$ >> -> + x + | x -> not_impl "str_item" x ] +and class_expr x = + let loc = MLast.loc_of_class_expr x in + match x with + [ <:class_expr< object $opt:p$ $list:csil$ end >> -> + <:class_expr< object $opt:p$ $list:List.map class_str_item csil$ end >> + | x -> not_impl "class_expr" x ] +and class_str_item x = + let loc = MLast.loc_of_class_str_item x in + match x with + [ <:class_str_item< value $opt:mf$ $s$ = $e$ >> -> + <:class_str_item< value $opt:mf$ $s$ = $expr e$ >> + | <:class_str_item< method $s$ = $e$ >> -> + <:class_str_item< method $s$ = $expr e$ >> + | x -> not_impl "class_str_item" x ] +; + +value parse_implem = Pcaml.parse_implem.val; +value parse_implem_with_left_eval strm = + let (r, b) = parse_implem strm in + (List.map (fun (si, loc) -> (str_item si, loc)) r, b) +; +Pcaml.parse_implem.val := parse_implem_with_left_eval; diff --git a/camlp4/unmaintained/lib/.cvsignore b/camlp4/unmaintained/lib/.cvsignore new file mode 100644 index 0000000..c77a681 --- /dev/null +++ b/camlp4/unmaintained/lib/.cvsignore @@ -0,0 +1,3 @@ +*.cm[oiax] +*.cmxa +*.lib diff --git a/camlp4/unmaintained/lib/.depend b/camlp4/unmaintained/lib/.depend new file mode 100644 index 0000000..a779396 --- /dev/null +++ b/camlp4/unmaintained/lib/.depend @@ -0,0 +1,14 @@ +debug.cmo: debug.cmi +debug.cmx: debug.cmi +extfun.cmo: extfun.cmi +extfun.cmx: extfun.cmi +fstream.cmo: fstream.cmi +fstream.cmx: fstream.cmi +grammar.cmo: token.cmi plexer.cmi loc.cmi +grammar.cmx: token.cmx plexer.cmi loc.cmx +loc.cmo: loc.cmi +loc.cmx: loc.cmi +token.cmo: loc.cmi token.cmi +token.cmx: loc.cmx token.cmi +plexer.cmi: token.cmi loc.cmi +token.cmi: loc.cmi diff --git a/camlp4/unmaintained/lib/Makefile b/camlp4/unmaintained/lib/Makefile new file mode 100644 index 0000000..3d5be9b --- /dev/null +++ b/camlp4/unmaintained/lib/Makefile @@ -0,0 +1,52 @@ + + +include ../config/Makefile.cnf + +INCLUDES=-I $(OTOP)/parsing -I $(OTOP)/utils +LIBRARIES=gramlib.cma +OBJS=$(OTOP)/utils/misc.cmo $(OTOP)/parsing/linenum.cmo \ + $(OTOP)/utils/warnings.cmo $(OTOP)/parsing/location.cmo \ + $(OTOP)/utils/config.cmo debug.cmo loc.cmo \ + token.cmo lexer_token.cmo lexer_error.cmo \ + plexer.cmo grammar.cmo extfun.cmo \ + fstream.cmo +CLEANFILES=plexer.ml + +include ../config/Makefile.base + +debug.cmo: debug.cmi +debug.cmo: debug.ml + $(OCAMLC) -pp '$(CAMLP4BOOT)' -rectypes $(OCAMLCFLAGS) $< -c -o $@ + +plexer.cmo: plexer.ml plexer.cmi + $(OCAMLC) $(OCAMLCFLAGS) $< -c -o $@ + +plexer.cmx: plexer.ml plexer.cmi + $(OCAMLOPT) $(OCAMLCFLAGS) $< -c -o $@ + +$(LIBRARIES): $(OBJS) + $(OCAMLC) -linkall $(OBJS) -a -o $(LIBRARIES) + +$(LIBRARIESX): $(OBJSX) + $(OCAMLOPT) -linkall $(OBJSX) -a -o $(LIBRARIESX) + +$(LIBRARIESP): $(OBJSP) + $(OCAMLOPT) -linkall $(OBJSP) -a -o $(LIBRARIESP) + +install-local: + -$(MKDIR) "$(LIBDIR)/camlp4" + cp $(LIBRARIES) *.mli "$(LIBDIR)/camlp4/." + cp *.cmi "$(LIBDIR)/camlp4/." + test -f $(LIBRARIESX) && $(MAKE) installopt LIBDIR="$(LIBDIR)" || true + +installopt: + for f in $(LIBRARIESX) $(LIBRARIESP) *.cmx ; do \ + test -f $$f && cp $$f "$(LIBDIR)/camlp4/." || true ; \ + done + # Special treatment for this one: some versions of make don't like $(A) in $(TARGET:.cma=.$(A)) + target="`echo $(LIBRARIES) | sed -e 's/\.cma$$/.$(A)/'`" ; \ + if test -f $$target ; then \ + cp $$target "$(LIBDIR)/camlp4/." && ( cd "$(LIBDIR)/camlp4/." && $(RANLIB) $$target ) \ + fi + +include .depend diff --git a/camlp4/unmaintained/lib/extfun.ml b/camlp4/unmaintained/lib/extfun.ml new file mode 100644 index 0000000..4f4cbbd --- /dev/null +++ b/camlp4/unmaintained/lib/extfun.ml @@ -0,0 +1,107 @@ +(* camlp4r *) + +(* Copyright 2001 INRIA *) + +(* Extensible Functions *) + +type t 'a 'b = list (matching 'a 'b) +and matching 'a 'b = { patt : patt; has_when : bool; expr : expr 'a 'b } +and patt = + [ Eapp of list patt + | Eacc of list patt + | Econ of string + | Estr of string + | Eint of string + | Etup of list patt + | Evar of unit ] +and expr 'a 'b = 'a -> option 'b +; + +exception Failure; + +value empty = []; + +(*** Apply ***) + +value rec apply_matchings a = + fun + [ [m :: ml] -> + match m.expr a with + [ None -> apply_matchings a ml + | x -> x ] + | [] -> None ] +; + +value apply ef a = + match apply_matchings a ef with + [ Some x -> x + | None -> raise Failure ] +; + +(*** Trace ***) + +value rec list_iter_sep f s = + fun + [ [] -> () + | [x] -> f x + | [x :: l] -> do { f x; s (); list_iter_sep f s l } ] +; + +value rec print_patt = + fun + [ Eapp pl -> list_iter_sep print_patt2 (fun () -> print_string " ") pl + | p -> print_patt2 p ] +and print_patt2 = + fun + [ Eacc pl -> list_iter_sep print_patt1 (fun () -> print_string ".") pl + | p -> print_patt1 p ] +and print_patt1 = + fun + [ Econ s -> print_string s + | Estr s -> do { print_string "\""; print_string s; print_string "\"" } + | Eint s -> print_string s + | Evar () -> print_string "_" + | Etup pl -> + do { + print_string "("; + list_iter_sep print_patt (fun () -> print_string ", ") pl; + print_string ")" + } + | Eapp _ | Eacc _ as p -> + do { print_string "("; print_patt p; print_string ")" } ] +; + +value print ef = + List.iter + (fun m -> + do { + print_patt m.patt; + if m.has_when then print_string " when ..." else (); + print_newline () + }) + ef +; + +(*** Extension ***) + +value insert_matching matchings (patt, has_when, expr) = + let m1 = {patt = patt; has_when = has_when; expr = expr} in + let rec loop = + fun + [ [m :: ml] as gml -> + if m1.has_when && not m.has_when then [m1 :: gml] else + if not m1.has_when && m.has_when then [m :: loop ml] else + (* either both or none have a when clause *) + if compare m1.patt m.patt = 0 then + if not m1.has_when then [m1 :: ml] else [m1 :: gml] + else [m :: loop ml] + | [] -> [m1] ] + in + loop matchings +; + +(* available extension function *) + +value extend ef matchings_def = + List.fold_left insert_matching ef matchings_def +; diff --git a/camlp4/unmaintained/lib/extfun.mli b/camlp4/unmaintained/lib/extfun.mli new file mode 100644 index 0000000..6d71fc1 --- /dev/null +++ b/camlp4/unmaintained/lib/extfun.mli @@ -0,0 +1,35 @@ +(* camlp4r *) + + +(** Extensible functions. + + This module implements pattern matching extensible functions. + To extend, use syntax [pa_extfun.cmo]: + + [extfun e with [ pattern_matching ]] *) + +type t 'a 'b = 'x; + (** The type of the extensible functions of type ['a -> 'b] *) +value empty : t 'a 'b; + (** Empty extensible function *) +value apply : t 'a 'b -> 'a -> 'b; + (** Apply an extensible function *) +exception Failure; + (** Match failure while applying an extensible function *) +value print : t 'a 'b -> unit; + (** Print patterns in the order they are recorded *) + +(**/**) + +type patt = + [ Eapp of list patt + | Eacc of list patt + | Econ of string + | Estr of string + | Eint of string + | Etup of list patt + | Evar of unit ] +and expr 'a 'b = 'a -> option 'b +; + +value extend : t 'a 'b -> list (patt * bool * expr 'a 'b) -> t 'a 'b; diff --git a/camlp4/unmaintained/lib/fstream.ml b/camlp4/unmaintained/lib/fstream.ml new file mode 100644 index 0000000..8c3171a --- /dev/null +++ b/camlp4/unmaintained/lib/fstream.ml @@ -0,0 +1,77 @@ +(* camlp4r *) + +(* Copyright 2001 INRIA *) + +type t 'a = { count : int; data : Lazy.t (data 'a) } +and data 'a = + [ Nil + | Cons of 'a and t 'a + | App of t 'a and t 'a ] +; + +value from f = + loop 0 where rec loop i = + {count = 0; + data = + lazy + (match f i with + [ Some x -> Cons x (loop (i + 1)) + | None -> Nil ])} +; + +value rec next s = + let count = s.count + 1 in + match Lazy.force s.data with + [ Nil -> None + | Cons a s -> Some (a, {count = count; data = s.data}) + | App s1 s2 -> + match next s1 with + [ Some (a, s1) -> Some (a, {count = count; data = lazy (App s1 s2)}) + | None -> + match next s2 with + [ Some (a, s2) -> Some (a, {count = count; data = s2.data}) + | None -> None ] ] ] +; + +value empty s = + match next s with + [ Some _ -> None + | None -> Some ((), s) ] +; + +value nil = {count = 0; data = lazy Nil}; +value cons a s = Cons a s; +value app s1 s2 = App s1 s2; +value flazy f = {count = 0; data = Lazy.lazy_from_fun f}; + +value of_list l = + List.fold_right (fun x s -> flazy (fun () -> cons x s)) l nil +; + +value of_string s = + from (fun c -> if c < String.length s then Some s.[c] else None) +; + +value of_channel ic = + from (fun _ -> try Some (input_char ic) with [ End_of_file -> None ]) +; + +value iter f = + do_rec where rec do_rec strm = + match next strm with + [ Some (a, strm) -> + let _ = f a in + do_rec strm + | None -> () ] +; + +value count s = s.count; + +value count_unfrozen s = + loop 0 s where rec loop cnt s = + if Lazy.lazy_is_val s.data then + match Lazy.force s.data with + [ Cons _ s -> loop (cnt + 1) s + | _ -> cnt ] + else cnt +; diff --git a/camlp4/unmaintained/lib/fstream.mli b/camlp4/unmaintained/lib/fstream.mli new file mode 100644 index 0000000..723389a --- /dev/null +++ b/camlp4/unmaintained/lib/fstream.mli @@ -0,0 +1,60 @@ +(* camlp4r *) + + +(* Module [Fstream]: functional streams *) + +(* This module implement functional streams. + To be used with syntax [pa_fstream.cmo]. The syntax is: +- stream: [fstream [: ... :]] +- parser: [parser [ [: ... :] -> ... | ... ]] + + Functional parsers are of type: [Fstream.t 'a -> option ('a * Fstream.t 'a)] + + They have limited backtrack, i.e if a rule fails, the next rule is tested + with the initial stream; limited because when in case of a rule with two + consecutive symbols [a] and [b], if [b] fails, the rule fails: there is + no try with the next rule of [a]. +*) + +type t 'a = 'x; + (* The type of 'a functional streams *) +value from : (int -> option 'a) -> t 'a; + (* [Fstream.from f] returns a stream built from the function [f]. + To create a new stream element, the function [f] is called with + the current stream count. The user function [f] must return either + [Some ] for a value or [None] to specify the end of the + stream. *) + +value of_list : list 'a -> t 'a; + (* Return the stream holding the elements of the list in the same + order. *) +value of_string : string -> t char; + (* Return the stream of the characters of the string parameter. *) +value of_channel : in_channel -> t char; + (* Return the stream of the characters read from the input channel. *) + +value iter : ('a -> unit) -> t 'a -> unit; + (* [Fstream.iter f s] scans the whole stream s, applying function [f] + in turn to each stream element encountered. *) + +value next : t 'a -> option ('a * t 'a); + (* Return [Some (a, s)] where [a] is the first element of the stream + and [s] the remaining stream, or [None] if the stream is empty. *) +value empty : t 'a -> option (unit * t 'a); + (* Return [Some ((), s)] if the stream is empty where [s] is itself, + else [None] *) +value count : t 'a -> int; + (* Return the current count of the stream elements, i.e. the number + of the stream elements discarded. *) +value count_unfrozen : t 'a -> int; + (* Return the number of unfrozen elements in the beginning of the + stream; useful to determine the position of a parsing error (longuest + path). *) + +(*--*) + +value nil : t 'a; +type data 'a = 'x; +value cons : 'a -> t 'a -> data 'a; +value app : t 'a -> t 'a -> data 'a; +value flazy : (unit -> data 'a) -> t 'a; diff --git a/camlp4/unmaintained/ocamllex/Makefile b/camlp4/unmaintained/ocamllex/Makefile new file mode 100644 index 0000000..b232023 --- /dev/null +++ b/camlp4/unmaintained/ocamllex/Makefile @@ -0,0 +1,59 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_ocamllex +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. + +CAMLP4=../../camlp4/camlp4$(EXE) + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) + +P4INCLUDES= -nolib -I ../../etc -I ../../meta +OCAMLINCLUDES= -nostdlib -I $(OCAMLTOP)/stdlib -I ../../camlp4 -I ../../lib -I $(OCAMLTOP)/lex +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SRC=pa_ocamllex.ml +OBJS=pa_ocamllex.cmo +OBJSX=$(OBJS:.cmo=.cmx) + +all: $(OBJS) pa_ocamllex.cma + +opt: $(OBJSX) pa_ocamllex.cmxa + +pa_ocamllex.cma: pa_ocamllex.cmo + $(OCAMLC) $(OCAMLCFLAGS) cset.cmo syntax.cmo table.cmo lexgen.cmo compact.cmo pa_ocamllex.cmo -a -o pa_ocamllex.cma + +pa_ocamllex.cmxa: pa_ocamllex.cmo + $(OCAMLOPT) $(OCAMLCFLAGS) cset.cmx syntax.cmx table.cmx lexgen.cmx compact.cmx pa_ocamllex.cmx -a -o pa_ocamllex.cmxa + +clean: + rm -f *.cm* *.$(O) *.$(A) *.bak .*.bak + +depend: + +.SUFFIXES: .cmx .cmo .cmi .ml .mli + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< diff --git a/camlp4/unmaintained/ocamllex/README b/camlp4/unmaintained/ocamllex/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/ocamllex/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/ocamllex/pa_ocamllex.ml b/camlp4/unmaintained/ocamllex/pa_ocamllex.ml new file mode 100644 index 0000000..e1d4a8e --- /dev/null +++ b/camlp4/unmaintained/ocamllex/pa_ocamllex.ml @@ -0,0 +1,356 @@ +(* pa_o.cmo q_MLast.cmo pa_extend.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Alain Frisch, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + +open Syntax +open Lexgen +open Compact + +(* Adapted from output.ml *) +(**************************) + +(* Output the DFA tables and its entry points *) + +(* To output an array of short ints, encoded as a string *) + +let output_byte buf b = + Buffer.add_char buf '\\'; + Buffer.add_char buf (Char.chr(48 + b / 100)); + Buffer.add_char buf (Char.chr(48 + (b / 10) mod 10)); + Buffer.add_char buf (Char.chr(48 + b mod 10)) + +let loc = (Lexing.dummy_pos,Lexing.dummy_pos) + +let output_array v = + let b = Buffer.create (Array.length v * 3) in + for i = 0 to Array.length v - 1 do + output_byte b (v.(i) land 0xFF); + output_byte b ((v.(i) asr 8) land 0xFF); + if i land 7 = 7 then Buffer.add_string b "\\\n " + done; + let s = Buffer.contents b in + <:expr< $str:s$ >> + +let output_byte_array v = + let b = Buffer.create (Array.length v * 2) in + for i = 0 to Array.length v - 1 do + output_byte b (v.(i) land 0xFF); + if i land 15 = 15 then Buffer.add_string b "\\\n " + done; + let s = Buffer.contents b in + <:expr< $str:s$ >> + + + +(* Output the tables *) + +let output_tables tbl = + <:str_item< value lex_tables = { + Lexing.lex_base = $output_array tbl.tbl_base$; + Lexing.lex_backtrk = $output_array tbl.tbl_backtrk$; + Lexing.lex_default = $output_array tbl.tbl_default$; + Lexing.lex_trans = $output_array tbl.tbl_trans$; + Lexing.lex_check = $output_array tbl.tbl_check$; + Lexing.lex_base_code = $output_array tbl.tbl_base_code$; + Lexing.lex_backtrk_code = $output_array tbl.tbl_backtrk_code$; + Lexing.lex_default_code = $output_array tbl.tbl_default_code$; + Lexing.lex_trans_code = $output_array tbl.tbl_trans_code$; + Lexing.lex_check_code = $output_array tbl.tbl_check_code$; + Lexing.lex_code = $output_byte_array tbl.tbl_code$ + } >> + +(* Output the entries *) + +let rec make_alias n = function + | [] -> [] + | h::t -> + (h, "__ocaml_lex_arg_" ^ (string_of_int n)) :: (make_alias (succ n) t) + +let abstraction = + List.fold_right (fun (p,a) e -> <:expr< fun ($p$ as $lid:a$) -> $e$ >>) + + +let application = + List.fold_left (fun f (_,a) -> <:expr< $f$ $lid:a$ >>) + +let int i = <:expr< $int:string_of_int i$ >> + +let output_memory_actions acts = + let aux = function + | Copy (tgt, src) -> + <:expr< lexbuf.Lexing.lex_mem.($int tgt$) := + lexbuf.Lexing.lex_mem.($int src$) >> + | Set tgt -> + <:expr< lexbuf.Lexing.lex_mem.($int tgt$) := + lexbuf.Lexing.lex_curr_pos >> + in + <:expr< do { $list:List.map aux acts$ } >> + +let output_base_mem = function + | Mem i -> <:expr< lexbuf.Lexing.lex_mem.($int i$) >> + | Start -> <:expr< lexbuf.Lexing.lex_start_pos >> + | End -> <:expr< lexbuf.Lexing.lex_curr_pos >> + +let output_tag_access = function + | Sum (a,0) -> output_base_mem a + | Sum (a,i) -> <:expr< $output_base_mem a$ + $int i$ >> + +let rec output_env e = function + | [] -> e + | (x, Ident_string (o,nstart,nend)) :: rem -> + <:expr< + let $lid:x$ = + Lexing.$lid:if o then "sub_lexeme_opt" else "sub_lexeme"$ + lexbuf $output_tag_access nstart$ $output_tag_access nend$ + in $output_env e rem$ + >> + | (x, Ident_char (o,nstart)) :: rem -> + <:expr< + let $lid:x$ = + Lexing.$lid: if o then "sub_lexeme_char_opt" else "sub_lexeme_char"$ + lexbuf $output_tag_access nstart$ + in $output_env e rem$ + >> + +let output_entry e = + let init_num, init_moves = e.auto_initial_state in + let args = make_alias 0 (e.auto_args @ [ <:patt< lexbuf >> ]) in + let f = "__ocaml_lex_rec_" ^ e.auto_name ^ "_rec" in + let call_f = application <:expr< $lid:f$ >> args in + let body_wrapper = + <:expr< + do { + lexbuf.Lexing.lex_mem := Array.create $int e.auto_mem_size$ (-1) ; + $output_memory_actions init_moves$; + $call_f$ $int init_num$ + } >> in + let cases = + List.map + (fun (num, env, (loc,e)) -> + <:patt< $int:string_of_int num$ >>, + None, + output_env <:expr< $e$ >> env + (* Note: the <:expr<...>> above is there to set the location *) + ) e.auto_actions @ + [ <:patt< __ocaml_lex_n >>, + None, + <:expr< do + { lexbuf.Lexing.refill_buff lexbuf; $call_f$ __ocaml_lex_n }>> ] + in + let engine = + if e.auto_mem_size = 0 + then <:expr< Lexing.engine >> + else <:expr< Lexing.new_engine >> in + let body = + <:expr< fun state -> + match $engine$ lex_tables state lexbuf with [ $list:cases$ ] >> in + [ + <:patt< $lid:e.auto_name$ >>, (abstraction args body_wrapper); + <:patt< $lid:f$ >>, (abstraction args body) + ] + +(* Main output function *) + +exception Table_overflow + +let output_lexdef tables entry_points = + Printf.eprintf + "pa_ocamllex: lexer found; %d states, %d transitions, table size %d bytes\n" + (Array.length tables.tbl_base) + (Array.length tables.tbl_trans) + (2 * (Array.length tables.tbl_base + Array.length tables.tbl_backtrk + + Array.length tables.tbl_default + Array.length tables.tbl_trans + + Array.length tables.tbl_check)); + let size_groups = + (2 * (Array.length tables.tbl_base_code + + Array.length tables.tbl_backtrk_code + + Array.length tables.tbl_default_code + + Array.length tables.tbl_trans_code + + Array.length tables.tbl_check_code) + + Array.length tables.tbl_code) in + if size_groups > 0 then + Printf.eprintf "pa_ocamllex: %d additional bytes used for bindings\n" + size_groups ; + flush stderr; + if Array.length tables.tbl_trans > 0x8000 then raise Table_overflow; + + let entries = List.map output_entry entry_points in + [output_tables tables; <:str_item< value rec $list:List.flatten entries$ >> ] + + +(* Adapted from parser.mly and main.ml *) +(***************************************) + +(* Auxiliaries for the parser. *) + +let char s = Char.code (Token.eval_char s) + +let named_regexps = + (Hashtbl.create 13 : (string, regular_expression) Hashtbl.t) + +let regexp_for_string s = + let rec re_string n = + if n >= String.length s then Epsilon + else if succ n = String.length s then + Characters (Cset.singleton (Char.code s.[n])) + else + Sequence + (Characters(Cset.singleton (Char.code s.[n])), + re_string (succ n)) + in re_string 0 + +let char_class c1 c2 = Cset.interval c1 c2 + +let all_chars = Cset.all_chars + +let rec remove_as = function + | Bind (e,_) -> remove_as e + | Epsilon|Eof|Characters _ as e -> e + | Sequence (e1, e2) -> Sequence (remove_as e1, remove_as e2) + | Alternative (e1, e2) -> Alternative (remove_as e1, remove_as e2) + | Repetition e -> Repetition (remove_as e) + +let () = + Hashtbl.add named_regexps "eof" (Characters Cset.eof) + +(* The parser *) + +let let_regexp = Grammar.Entry.create Pcaml.gram "pa_ocamllex let" +let header = Grammar.Entry.create Pcaml.gram "pa_ocamllex header" +let lexer_def = Grammar.Entry.create Pcaml.gram "pa_ocaml lexerdef" + +EXTEND + GLOBAL: Pcaml.str_item let_regexp header lexer_def; + + let_regexp: [ + [ x = LIDENT; "="; r = regexp -> + if Hashtbl.mem named_regexps x then + Printf.eprintf + "pa_ocamllex (warning): multiple definition of named regexp '%s'\n" + x; + Hashtbl.add named_regexps x r; + ] + ]; + + lexer_def: [ + [ def = LIST0 definition SEP "and" -> + (try + let (entries, transitions) = make_dfa def in + let tables = compact_tables transitions in + let output = output_lexdef tables entries in + <:str_item< declare $list: output$ end >> + with + |Table_overflow -> + failwith "Transition table overflow in lexer, automaton is too big" + | Lexgen.Memory_overflow -> + failwith "Position memory overflow in lexer, too many as variables") + ] + ]; + + + Pcaml.str_item: [ + [ "pa_ocamllex"; LIDENT "rule"; d = lexer_def -> d + | "pa_ocamllex"; "let"; let_regexp -> + <:str_item< declare $list: []$ end >> + ] + ]; + + definition: [ + [ x=LIDENT; pl = LIST0 Pcaml.patt LEVEL "simple"; "="; + short=[ LIDENT "parse" -> false | LIDENT "shortest" -> true ]; + OPT "|"; l = LIST0 [ r=regexp; a=action -> (r,a) ] SEP "|" -> + { name=x ; shortest=short ; args=pl ; clauses = l } ] + ]; + + action: [ + [ "{"; e = OPT Pcaml.expr; "}" -> + let e = match e with + | Some e -> e + | None -> <:expr< () >> + in + (loc,e) + ] + ]; + + header: [ + [ "{"; e = LIST0 [ si = Pcaml.str_item; OPT ";;" -> si ]; "}" -> + [<:str_item< declare $list:e$ end>>, loc] ] + | [ -> [] ] + ]; + + regexp: [ + [ r = regexp; "as"; i = LIDENT -> Bind (r,i) ] + | [ r1 = regexp; "|"; r2 = regexp -> Alternative(r1,r2) ] + | [ r1 = regexp; r2 = regexp -> Sequence(r1,r2) ] + | [ r = regexp; "*" -> Repetition r + | r = regexp; "+" -> Sequence(Repetition (remove_as r), r) + | r = regexp; "?" -> Alternative(Epsilon, r) + | "("; r = regexp; ")" -> r + | "_" -> Characters all_chars + | c = CHAR -> Characters (Cset.singleton (char c)) + | s = STRING -> regexp_for_string (Token.eval_string loc s) + | "["; cc = ch_class; "]" -> Characters cc + | x = LIDENT -> + try Hashtbl.find named_regexps x + with Not_found -> + failwith + ("pa_ocamllex (error): reference to unbound regexp name `"^x^"'") + ] + ]; + + ch_class: [ + [ "^"; cc = ch_class -> Cset.complement cc] + | [ c1 = CHAR; "-"; c2 = CHAR -> Cset.interval (char c1) (char c2) + | c = CHAR -> Cset.singleton (char c) + | cc1 = ch_class; cc2 = ch_class -> Cset.union cc1 cc2 + ] + ]; +END + +(* We have to be careful about "rule"; in standalone mode, + it is used as a keyword (otherwise, there is a conflict + with named regexp); in normal mode, it is used as LIDENT + (we do not want to reserve such an useful identifier). + + Plexer does not like identifiers used as keyword _and_ + as LIDENT ... +*) + +let standalone = + let already = ref false in + fun () -> + if not (!already) then + begin + already := true; + Printf.eprintf "pa_ocamllex: stand-alone mode\n"; + + DELETE_RULE Pcaml.str_item: "pa_ocamllex"; LIDENT "rule";lexer_def END; + DELETE_RULE Pcaml.str_item: "pa_ocamllex"; "let"; let_regexp END; + let ocamllex = Grammar.Entry.create Pcaml.gram "pa_ocamllex" in + EXTEND GLOBAL: ocamllex let_regexp header lexer_def; + ocamllex: [ + [ h = header; + l = [LIST0 ["let"; let_regexp]; "rule"; d = lexer_def -> (d,loc)]; + t = header; EOI -> h @ (l :: t) ,false + ] + ]; + END; + Pcaml.parse_implem := Grammar.Entry.parse ocamllex + end + +let () = + Pcaml.add_option "-ocamllex" (Arg.Unit standalone) + "Activate (standalone) ocamllex emulation mode." + diff --git a/camlp4/unmaintained/ocpp/.cvsignore b/camlp4/unmaintained/ocpp/.cvsignore new file mode 100644 index 0000000..baef26c --- /dev/null +++ b/camlp4/unmaintained/ocpp/.cvsignore @@ -0,0 +1,3 @@ +*.cm[oia] +ocpp +crc.ml diff --git a/camlp4/unmaintained/ocpp/.depend b/camlp4/unmaintained/ocpp/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/ocpp/Makefile b/camlp4/unmaintained/ocpp/Makefile new file mode 100644 index 0000000..b92fa3c --- /dev/null +++ b/camlp4/unmaintained/ocpp/Makefile @@ -0,0 +1,24 @@ + + +include ../config/Makefile.cnf + +EXECUTABLES=ocpp +OBJS=ocpp.cmo +INCLUDES=-I ../camlp4 -I ../lib -I ../odyl -I $(OTOP)/otherlibs/dynlink +OCPPM=../lib/debug.cmo ../lib/loc.cmo ../lib/stdpp.cmo ../camlp4/quotation.cmo + +include ../config/Makefile.base + +ocpp$(EXE): $(OBJS) + $(OCAMLC) $(LINKFLAGS) $(OCPPM) ../odyl/odyl.cma $(OBJS) ../odyl/odyl.cmo -linkall -o $@ + +ocpp.opt: $(OBJSX) + $(OCAMLOPT) $(LINKFLAGS) $(OCPPM:.cmo=.cmx) ../odyl/odyl.cmxa $(OBJSX) ../odyl/odyl.cmx -linkall -o $@ + +install-local: + -$(MKDIR) "$(LIBDIR)/camlp4" "$(BINDIR)" + cp $(OBJS) "$(LIBDIR)/camlp4/." + cp ocpp$(EXE) "$(BINDIR)/." + if test -f ocpp.opt ; then \ + cp ocpp.opt "$(LIBDIR)/camlp4/." ; \ + fi diff --git a/camlp4/unmaintained/ocpp/ocpp.ml b/camlp4/unmaintained/ocpp/ocpp.ml new file mode 100644 index 0000000..eb2ccdf --- /dev/null +++ b/camlp4/unmaintained/ocpp/ocpp.ml @@ -0,0 +1,129 @@ +(* camlp4r *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + + +value buff = ref (String.create 80); +value store len x = + do { + if len >= String.length buff.val then + buff.val := buff.val ^ String.create (String.length buff.val) + else (); + buff.val.[len] := x; + succ len + } +; +value get_buff len = String.sub buff.val 0 len; + +value rec copy_strip_locate cs = + match cs with parser + [ [: `'$' :] -> maybe_locate cs + | [: `c :] -> do { print_char c; copy_strip_locate cs } + | [: :] -> () ] +and maybe_locate cs = + match cs with parser + [ [: `'1'..'9' :] -> locate cs + | [: :] -> do { print_char '$'; copy_strip_locate cs } ] +and locate cs = + match cs with parser + [ [: `'0'..'9' :] -> locate cs + | [: `':' :] -> inside_locate cs + | [: :] -> raise (Stream.Error "colon char expected") ] +and inside_locate cs = + match cs with parser + [ [: `'$' :] -> copy_strip_locate cs + | [: `'\\'; `c :] -> do { print_char c; inside_locate cs } + | [: `c :] -> do { print_char c; inside_locate cs } + | [: :] -> raise (Stream.Error "end of file in locate directive") ] +; + +value file = ref ""; + +value quot name loc str = + let loc = Loc.move `stop (String.length str) loc in + let exp = + try + match Quotation.find name with + [ Quotation.ExStr f -> f + | _ -> raise Not_found ] + with + [ Not_found -> Stdpp.raise_with_loc loc Not_found ] + in + let new_str = + try exp True { Quotation.loc = Loc.mk file.val ; loc_name_opt = None } str with + [ Loc.Exc_located loc exc -> Stdpp.raise_with_loc loc exc + | exc -> Stdpp.raise_with_loc loc exc ] + in + let cs = Stream.of_string new_str in copy_strip_locate cs +; + +value rec ident len = + parser + [ [: `('A'..'Z' | 'a'..'z' | '0'..'9' | '_' | ''' as c); s :] -> + ident (store len c) s + | [: :] -> get_buff len ] +; + +value loc_of_ep ep = + Loc.set_all `start 1 0 ep (Loc.mk file.val); + +value rec copy cs = + match cs with parser + [ [: `'<' :] -> maybe_quot cs + | [: `'"' :] -> do { print_char '"'; inside_string cs } + | [: `c :] -> do { print_char c; copy cs } + | [: :] -> () ] +and maybe_quot cs = + match cs with parser + [ [: `'<' :] ep -> inside_quot "" (loc_of_ep ep) 0 cs + | [: `':'; i = ident 0; `'<' ?? "less char expected" :] ep -> + inside_quot i (loc_of_ep ep) 0 cs + | [: :] -> do { print_char '<'; copy cs } ] +and inside_quot name loc len cs = + match cs with parser + [ [: `'>' :] -> maybe_end_quot name loc len cs + | [: `c :] -> inside_quot name loc (store len c) cs + | [: :] -> raise (Stream.Error "end of file in quotation") ] +and maybe_end_quot name loc len cs = + match cs with parser + [ [: `'>' :] -> do { quot name loc (get_buff len); copy cs } + | [: :] -> inside_quot name loc (store len '>') cs ] +and inside_string cs = + match cs with parser + [ [: `'"' :] -> do { print_char '"'; copy cs } + | [: `c :] -> do { print_char c; inside_string cs } + | [: :] -> raise (Stream.Error "end of file in string") ] +; + +value copy_quot cs = do { copy cs; flush stdout; }; + +Arg.parse [] (fun x -> file.val := x) "ocpp "; + +value main () = + try + if file.val <> "" then + copy_quot (Stream.of_channel (open_in_bin file.val)) + else () + with exc -> + do { + Format.printf "@."; + raise + (match exc with + [ Loc.Exc_located loc exc -> + do { Format.eprintf "%a@." Loc.print loc; exc } + | exc -> exc ]) + } +; + +Odyl_main.name.val := "ocpp"; +Odyl_main.go.val := main; diff --git a/camlp4/unmaintained/odyl/.cvsignore b/camlp4/unmaintained/odyl/.cvsignore new file mode 100644 index 0000000..8ae0ebb --- /dev/null +++ b/camlp4/unmaintained/odyl/.cvsignore @@ -0,0 +1,4 @@ +*.cm[oia] +odyl +*.lib +odyl_config.ml diff --git a/camlp4/unmaintained/odyl/.depend b/camlp4/unmaintained/odyl/.depend new file mode 100644 index 0000000..a262944 --- /dev/null +++ b/camlp4/unmaintained/odyl/.depend @@ -0,0 +1,4 @@ +odyl.cmo: odyl_main.cmi odyl_config.cmo +odyl.cmx: odyl_main.cmx odyl_config.cmx +odyl_main.cmo: odyl_config.cmo odyl_main.cmi +odyl_main.cmx: odyl_config.cmx odyl_main.cmi diff --git a/camlp4/unmaintained/odyl/Makefile b/camlp4/unmaintained/odyl/Makefile new file mode 100644 index 0000000..f4f5d87 --- /dev/null +++ b/camlp4/unmaintained/odyl/Makefile @@ -0,0 +1,61 @@ + + +include ../config/Makefile.cnf + +EXECUTABLES=odyl +INCLUDES=-I $(OTOP)/otherlibs/dynlink +OBJS=odyl_config.cmo odyl_main.cmo +OBJSX=odyl.cmx odyl.cmxa +CLEANFILES=odyl_config.ml + +include ../config/Makefile.base + +odyl$(EXE): odyl.cma odyl.cmo + $(OCAMLC) odyl.cma odyl.cmo -o $@ + +odyl.opt: odyl.cmxa odyl.cmx + $(OCAMLOPT) odyl.cmxa odyl.cmx -o $@ + +odyl.cma: $(OBJS) + $(OCAMLC) $(LINKFLAGS) dynlink.cma $(OBJS) -a -o $@ + +odyl.cmxa: $(OBJSX) + $(OCAMLOPT) $(LINKFLAGS) $(OBJSX) -a -o $@ + +odyl.p.cmxa: $(OBJSP) + $(OCAMLOPT) $(LINKFLAGS) $(OBJSP) -a -o $@ + +odyl_main.cmx: odyl_main.ml + $(CAMLP4BOOT) -nolib -DOPT -o odyl_main.ppo odyl_main.ml + $(OCAMLOPT) -c -impl odyl_main.ppo + rm -f odyl_main.ppo + +odyl_main.p.cmx: odyl_main.ml + $(CAMLP4BOOT) -nolib -DOPT -o odyl_main.ppo odyl_main.ml + $(OCAMLOPT) -p -c -o $@ -impl odyl_main.ppo + rm -f odyl_main.ppo + +odyl_config.ml: + (echo '(* camlp4r *)'; \ + echo 'value standard_library ='; \ + echo ' try Sys.getenv "CAMLP4LIB" with [ Not_found -> '; \ + echo ' try Sys.getenv "OCAMLLIB" ^ "/camlp4" with [ Not_found -> '; \ + echo ' try Sys.getenv "CAMLLIB" ^ "/camlp4" with [ Not_found -> '; \ + echo ' "$(LIBDIR)/camlp4"]]];') \ + | sed -e 's|\\|/|g' > odyl_config.ml + +install-local: + -$(MKDIR) "$(LIBDIR)/camlp4" "$(BINDIR)" + cp odyl.cmo odyl.cma odyl_main.cmi $(LIBDIR)/camlp4/. + for f in odyl.$(A) odyl.p.$(A) ; do \ + if test -f $$f ; then \ + cp $$f "$(LIBDIR)/camlp4/." && ( cd "$(LIBDIR)/camlp4/." && $(RANLIB) $$f ) ; \ + fi ; \ + done + for f in odyl.cmx odyl.o odyl.p.cmx odyl.p.o odyl.cmxa odyl.p.cmxa ; do \ + if test -f $$f ; then \ + cp $$f "$(LIBDIR)/camlp4/." ; \ + fi ; \ + done + +include .depend diff --git a/camlp4/unmaintained/odyl/odyl.ml b/camlp4/unmaintained/odyl/odyl.ml new file mode 100644 index 0000000..23b7136 --- /dev/null +++ b/camlp4/unmaintained/odyl/odyl.ml @@ -0,0 +1,57 @@ +(* camlp4r *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +value apply_load () = + let i = ref 1 in + let stop = ref False in + while not stop.val && i.val < Array.length Sys.argv do { + let s = Sys.argv.(i.val) in + if s = "-I" && i.val + 1 < Array.length Sys.argv then do { + Odyl_main.directory Sys.argv.(i.val + 1); + i.val := i.val + 2 + } + else if s = "-nolib" then do { Odyl_main.nolib.val := True; incr i } + else if s = "-where" then do { + print_string Odyl_config.standard_library; + print_newline (); + flush stdout; + exit 0 + } + else if s = "-version" then do { + print_string Sys.ocaml_version; + print_newline (); + flush stdout; + exit 0 + } + else if s = "--" then do { incr i; stop.val := True; () } + else if String.length s > 0 && s.[0] == '-' then stop.val := True + else if Filename.check_suffix s ".cmo" || Filename.check_suffix s ".cma" + then do { Odyl_main.loadfile s; incr i } + else stop.val := True + } +; + +value main () = + try do { apply_load () ; Odyl_main.go.val () } with + [ Odyl_main.Error fname str -> + do { + flush stdout; + Printf.eprintf "Error while loading \"%s\": " fname; + Printf.eprintf "%s.\n" str; + flush stderr; + exit 2 + } ] +; + +Printexc.catch main (); diff --git a/camlp4/unmaintained/odyl/odyl_main.mli b/camlp4/unmaintained/odyl/odyl_main.mli new file mode 100644 index 0000000..122c933 --- /dev/null +++ b/camlp4/unmaintained/odyl/odyl_main.mli @@ -0,0 +1,13 @@ +(* camlp4r *) + + +exception Error of string and string; + +value nolib : ref bool; +value initialized : ref bool; +value path : ref (list string); +value loadfile : string -> unit; +value directory : string -> unit; + +value go : ref (unit -> unit); +value name : ref string; diff --git a/camlp4/unmaintained/olabl/.depend b/camlp4/unmaintained/olabl/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/olabl/Makefile b/camlp4/unmaintained/olabl/Makefile new file mode 100644 index 0000000..f928d45 --- /dev/null +++ b/camlp4/unmaintained/olabl/Makefile @@ -0,0 +1,61 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_lefteval +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. +CAMLP4=../../camlp4/camlp4$(EXE) + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) + +P4INCLUDES= -nolib -I ../../meta -I ../../lib -I ../../etc +OCAMLINCLUDES= -nostdlib -I $(OCAMLTOP)/stdlib -I ../../lib -I ../../camlp4 +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SRC=pa_olabl.ml +OBJS=$(SRC:.ml=.cmo) +OBJSX=$(SRC:.ml=.cmx) + +all: $(OBJS) + +opt: $(OBJSX) + +depend: + cp .depend .depend.bak + > .depend + for file in $(SRC); do \ + $(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $$file` pr_depend.cmo $$i | \ + sed -e 's| \.\./\.\./\.\.| $$(OCAMLTOP)|g' >> .depend; \ + done + +clean: + rm -f *.cm* *.$(O) *.bak .*.bak + + +.SUFFIXES: .cmx .cmo .cmi .ml .mli + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +include .depend diff --git a/camlp4/unmaintained/olabl/README b/camlp4/unmaintained/olabl/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/olabl/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/olabl/pa_olabl.ml b/camlp4/unmaintained/olabl/pa_olabl.ml new file mode 100644 index 0000000..285902a --- /dev/null +++ b/camlp4/unmaintained/olabl/pa_olabl.ml @@ -0,0 +1,2022 @@ +(* pa_r.cmo pa_rp.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + + +module Plexer = + struct + open Stdpp; + open Token; + value buff = ref (String.create 80); + value store len x = + do { + if len >= String.length buff.val then + buff.val := buff.val ^ String.create (String.length buff.val) + else (); + buff.val.[len] := x; + succ len + } + ; + value mstore len s = + add_rec len 0 where rec add_rec len i = + if i == String.length s then len + else add_rec (store len s.[i]) (succ i) + ; + value get_buff len = String.sub buff.val 0 len; + value rec ident len = + parser + [ [: `('A'..'Z' | 'a'..'z' | '\192'..'\214' | '\216'..'\246' | + '\248'..'\255' | '0'..'9' | '_' | ''' as + c) + ; + s :] -> + ident (store len c) s + | [: :] -> len ] + and ident2 len = + parser + [ [: `('!' | '?' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' | + '%' | '.' | ':' | '<' | '>' | '|' as + c) + ; + s :] -> + ident2 (store len c) s + | [: :] -> len ] + and ident3 len = + parser + [ [: `('0'..'9' | 'A'..'Z' | 'a'..'z' | '\192'..'\214' | + '\216'..'\246' | '\248'..'\255' | '_' | '!' | '%' | '&' | '*' | + '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | + '|' | '~' | ''' | '$' as + c) + ; + s :] -> + ident3 (store len c) s + | [: :] -> len ] + and ident4 len = + parser + [ [: `('!' | '?' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' | + '%' | '.' | '<' | '>' | '|' as + c) + ; + s :] -> + ident4 (store len c) s + | [: :] -> len ] + and base_number len = + parser + [ [: `'o' | 'O'; s :] -> octal_digits (store len 'o') s + | [: `'x' | 'X'; s :] -> hexa_digits (store len 'x') s + | [: `'b' | 'B'; s :] -> binary_digits (store len 'b') s + | [: a = number len :] -> a ] + and octal_digits len = + parser + [ [: `('0'..'7' as d); s :] -> octal_digits (store len d) s + | [: :] -> ("INT", get_buff len) ] + and hexa_digits len = + parser + [ [: `('0'..'9' | 'a'..'f' | 'A'..'F' as d); s :] -> + hexa_digits (store len d) s + | [: :] -> ("INT", get_buff len) ] + and binary_digits len = + parser + [ [: `('0'..'1' as d); s :] -> binary_digits (store len d) s + | [: :] -> ("INT", get_buff len) ] + and number len = + parser + [ [: `('0'..'9' as c); s :] -> number (store len c) s + | [: `'.'; s :] -> decimal_part (store len '.') s + | [: `'e' | 'E'; s :] -> exponent_part (store len 'E') s + | [: :] -> ("INT", get_buff len) ] + and decimal_part len = + parser + [ [: `('0'..'9' as c); s :] -> decimal_part (store len c) s + | [: `'e' | 'E'; s :] -> exponent_part (store len 'E') s + | [: :] -> ("FLOAT", get_buff len) ] + and exponent_part len = + parser + [ [: `('+' | '-' as c); s :] -> end_exponent_part (store len c) s + | [: a = end_exponent_part len :] -> a ] + and end_exponent_part len = + parser + [ [: `('0'..'9' as c); s :] -> end_exponent_part (store len c) s + | [: :] -> ("FLOAT", get_buff len) ] + ; + value valch x = Char.code x - Char.code '0'; + value rec backslash s i = + if i = String.length s then raise Not_found + else + match s.[i] with + [ 'n' -> ('\n', i + 1) + | 'r' -> ('\r', i + 1) + | 't' -> ('\t', i + 1) + | 'b' -> ('\b', i + 1) + | '\\' -> ('\\', i + 1) + | '0'..'9' as c -> backslash1 (valch c) s (i + 1) + | _ -> raise Not_found ] + and backslash1 cod s i = + if i = String.length s then (Char.chr cod, i) + else + match s.[i] with + [ '0'..'9' as c -> backslash2 (10 * cod + valch c) s (i + 1) + | _ -> (Char.chr cod, i) ] + and backslash2 cod s i = + if i = String.length s then (Char.chr cod, i) + else + match s.[i] with + [ '0'..'9' as c -> (Char.chr (10 * cod + valch c), i + 1) + | _ -> (Char.chr cod, i) ] + ; + value rec skip_indent s i = + if i = String.length s then i + else + match s.[i] with + [ ' ' | '\t' -> skip_indent s (i + 1) + | _ -> i ] + ; + value skip_opt_linefeed s i = + if i = String.length s then i else if s.[i] = '\010' then i + 1 else i + ; + value char_of_char_token s = + if String.length s = 1 then s.[0] + else if String.length s = 0 then failwith "invalid char token" + else if s.[0] = '\\' then + if String.length s = 2 && s.[1] = ''' then ''' + else + try + let (c, i) = backslash s 1 in + if i = String.length s then c else raise Not_found + with + [ Not_found -> failwith "invalid char token" ] + else failwith "invalid char token" + ; + value string_of_string_token s = + loop 0 0 where rec loop len i = + if i = String.length s then get_buff len + else + let (len, i) = + if s.[i] = '\\' then + let i = i + 1 in + if i = String.length s then failwith "invalid string token" + else if s.[i] = '"' then (store len '"', i + 1) + else + match s.[i] with + [ '\010' -> (len, skip_indent s (i + 1)) + | '\013' -> (len, skip_indent s (skip_opt_linefeed s (i + 1))) + | c -> + try + let (c, i) = backslash s i in + (store len c, i) + with + [ Not_found -> (store (store len '\\') c, i + 1) ] ] + else (store len s.[i], i + 1) + in + loop len i + ; + value rec skip_spaces = + parser + [ [: `' ' | '\n' | '\r' | '\t' | '\026' | '\012'; s :] -> skip_spaces s + | [: :] -> () ] + ; + value error_on_unknown_keywords = ref False; + value next_token_fun find_id_kwd find_spe_kwd fname lnum bolpos = + let make_pos p = + {Lexing.pos_fname = fname.val; Lexing.pos_lnum = lnum.val; + Lexing.pos_bol = bolpos.val; Lexing.pos_cnum = p} in + let mkloc (bp, ep) = (make_pos bp, make_pos ep) in + + let err loc msg = raise_with_loc loc (Token.Error msg) in + let keyword_or_error (bp,ep) s = + try ("", find_spe_kwd s) with + [ Not_found -> + if error_on_unknown_keywords.val then + err (mkloc (bp, ep)) ("illegal token: " ^ s) + else ("", s) ] + in + let rec next_token = + parser bp + [ [: `('A'..'Z' | 'À'..'Ö' | 'Ø'..'Þ' as c); s :] -> + let id = get_buff (ident (store 0 c) s) in + try ("", find_id_kwd id) with [ Not_found -> ("UIDENT", id) ] + | [: `('a'..'z' | 'ß'..'ö' | 'ø'..'ÿ' | '_' as c); s :] -> + let id = get_buff (ident (store 0 c) s) in + let is_label = + match Stream.peek s with + [ Some ':' -> + match Stream.npeek 2 s with + [ [_; ':' | '=' | '>'] -> False + | _ -> True ] + | _ -> False ] + in + if is_label then do { Stream.junk s; ("LABEL", id) } + else try ("", find_id_kwd id) with [ Not_found -> ("LIDENT", id) ] + | [: `('1'..'9' as c); s :] -> number (store 0 c) s + | [: `'0'; s :] -> base_number (store 0 '0') s + | [: `'''; s :] ep -> + match Stream.npeek 2 s with + [ [_; '''] | ['\\'; _] -> ("CHAR", char bp 0 s) + | _ -> keyword_or_error (bp, ep) "'" ] + | [: `'"'; s :] -> ("STRING", string bp 0 s) + | [: `'$'; s :] -> locate_or_antiquot bp 0 s + | [: `('!' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' | + '%' as + c) + ; + s :] -> + let id = get_buff (ident2 (store 0 c) s) in + keyword_or_error (bp, Stream.count s) id + | [: `('?' as c); s :] -> + let id = get_buff (ident4 (store 0 c) s) in + keyword_or_error (bp, Stream.count s) id + | [: `'<'; s :] -> less bp s + | [: `(':' as c1); + (is_label, len) = + parser + [ [: `(']' | ':' | '=' | '>' as c2) :] -> + (False, store (store 0 c1) c2) + | [: `('a'..'z' | 'ß'..'ö' | 'ø'..'ÿ' | '_' as c); s :] -> + (True, ident (store 0 c) s) + | [: :] -> (False, store 0 c1) ] :] ep -> + let id = get_buff len in + if is_label then ("ELABEL", id) else keyword_or_error (bp, ep) id + | [: `('>' | '|' as c1); + len = + parser + [ [: `(']' | '}' as c2) :] -> store (store 0 c1) c2 + | [: a = ident2 (store 0 c1) :] -> a ] :] ep -> + let id = get_buff len in + keyword_or_error (bp, ep) id + | [: `('[' | '{' as c1); s :] -> + let len = + match Stream.npeek 2 s with + [ ['<'; '<' | ':'] -> store 0 c1 + | _ -> + match s with parser + [ [: `('|' | '<' | ':' as c2) :] -> store (store 0 c1) c2 + | [: :] -> store 0 c1 ] ] + in + let ep = Stream.count s in + let id = get_buff len in + keyword_or_error (bp, ep) id + | [: `'.'; id = parser [ [: `'.' :] -> ".." | [: :] -> "." ] :] ep -> + keyword_or_error (bp, ep) id + | [: `';'; id = parser [ [: `';' :] -> ";;" | [: :] -> ";" ] :] ep -> + keyword_or_error (bp, ep) id + | [: `'\\'; s :] -> ("LIDENT", get_buff (ident3 0 s)) + | [: `c :] ep -> keyword_or_error (bp, ep) (String.make 1 c) ] + and less bp = + parser + [ [: `'<'; s :] -> ("QUOTATION", ":" ^ get_buff (quotation bp 0 s)) + | [: `':'; i = parser [: len = ident 0 :] -> get_buff len; + `'<' ? "character '<' expected"; s :] -> + ("QUOTATION", i ^ ":" ^ get_buff (quotation bp 0 s)) + | [: s :] ep -> + let id = get_buff (ident2 (store 0 '<') s) in + keyword_or_error (bp, ep) id ] + and string bp len = + parser + [ [: `'"' :] -> get_buff len + | [: `'\\'; `c; s :] -> string bp (store (store len '\\') c) s + | [: `c; s :] -> string bp (store len c) s + | [: :] ep -> err (mkloc (bp, ep)) "string not terminated" ] + and char bp len = + parser + [ [: `'''; s :] -> + if len = 0 then char bp (store len ''') s else get_buff len + | [: `'\\'; `c; s :] -> char bp (store (store len '\\') c) s + | [: `c; s :] -> char bp (store len c) s + | [: :] ep -> err (mkloc(bp,ep)) "char not terminated" ] + and locate_or_antiquot bp len = + parser + [ [: `'$' :] -> ("ANTIQUOT", ":" ^ get_buff len) + | [: `('a'..'z' | 'A'..'Z' as c); s :] -> antiquot bp (store len c) s + | [: `('0'..'9' as c); s :] -> maybe_locate bp (store len c) s + | [: `':'; s :] -> + let k = get_buff len in + ("ANTIQUOT", k ^ ":" ^ locate_or_antiquot_rest bp 0 s) + | [: `'\\'; `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: :] ep -> err (mkloc(bp,ep)) "antiquotation not terminated" ] + and maybe_locate bp len = + parser + [ [: `'$' :] -> ("ANTIQUOT", ":" ^ get_buff len) + | [: `('0'..'9' as c); s :] -> maybe_locate bp (store len c) s + | [: `':'; s :] -> + ("LOCATE", get_buff len ^ ":" ^ locate_or_antiquot_rest bp 0 s) + | [: `'\\'; `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: :] ep -> err (mkloc(bp,ep)) "antiquotation not terminated" ] + and antiquot bp len = + parser + [ [: `'$' :] -> ("ANTIQUOT", ":" ^ get_buff len) + | [: `('a'..'z' | 'A'..'Z' | '0'..'9' as c); s :] -> + antiquot bp (store len c) s + | [: `':'; s :] -> + let k = get_buff len in + ("ANTIQUOT", k ^ ":" ^ locate_or_antiquot_rest bp 0 s) + | [: `'\\'; `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: `c; s :] -> + ("ANTIQUOT", ":" ^ locate_or_antiquot_rest bp (store len c) s) + | [: :] ep -> err (mkloc(bp,ep)) "antiquotation not terminated" ] + and locate_or_antiquot_rest bp len = + parser + [ [: `'$' :] -> get_buff len + | [: `'\\'; `c; s :] -> locate_or_antiquot_rest bp (store len c) s + | [: `c; s :] -> locate_or_antiquot_rest bp (store len c) s + | [: :] ep -> err (mkloc(bp,ep)) "antiquotation not terminated" ] + and quotation bp len = + parser + [ [: `'>'; s :] -> maybe_end_quotation bp len s + | [: `'<'; s :] -> + quotation bp (maybe_nested_quotation bp (store len '<') __strm) s + | [: `'\\'; + len = + parser + [ [: `('>' | '<' | '\\' as c) :] -> store len c + | [: :] -> store len '\\' ]; + s :] -> + quotation bp len s + | [: `c; s :] -> quotation bp (store len c) s + | [: :] ep -> err (mkloc(bp,ep)) "quotation not terminated" ] + and maybe_nested_quotation bp len = + parser + [ [: `'<'; s :] -> mstore (quotation bp (store len '<') s) ">>" + | [: `':'; len = ident (store len ':'); + a = + parser + [ [: `'<'; s :] -> mstore (quotation bp (store len '<') s) ">>" + | [: :] -> len ] :] -> + a + | [: :] -> len ] + and maybe_end_quotation bp len = + parser + [ [: `'>' :] -> len + | [: a = quotation bp (store len '>') :] -> a ] + in + let rec next_token_loc = + parser bp + [ [: `' ' | '\n' | '\r' | '\t' | '\026' | '\012'; s :] -> + next_token_loc s + | [: `'('; s :] -> maybe_comment bp s + | [: `'#'; _ = spaces_tabs; a = linenum bp :] -> a + | [: tok = next_token :] ep -> (tok, mkloc(bp, ep)) + | [: _ = Stream.empty :] -> (("EOI", ""), mkloc(bp, succ bp)) ] + and maybe_comment bp = + parser + [ [: `'*'; s :] -> do { comment bp s; next_token_loc s } + | [: :] ep -> + let tok = keyword_or_error (bp, ep) "(" in + (tok, mkloc(bp, ep)) ] + and comment bp = + parser + [ [: `'('; s :] -> maybe_nested_comment bp s + | [: `'*'; s :] -> maybe_end_comment bp s + | [: `c; s :] -> comment bp s + | [: :] ep -> err (mkloc(bp,ep)) "comment not terminated" ] + and maybe_nested_comment bp = + parser + [ [: `'*'; s :] -> do { comment bp s; comment bp s } + | [: a = comment bp :] -> a ] + and maybe_end_comment bp = + parser [ [: `')' :] -> () | [: a = comment bp :] -> a ] + and linenum bp = + parser + [ [: `'0'..'9'; _ = digits; _ = spaces_tabs; `'"'; _ = any_to_nl; + s :] -> + next_token_loc s + | [: :] -> (keyword_or_error (bp, bp + 1) "#", mkloc(bp, bp + 1)) ] + and spaces_tabs = + parser [ [: `' ' | '\t'; s :] -> spaces_tabs s | [: :] -> () ] + and digits = parser [ [: `'0'..'9'; s :] -> digits s | [: :] -> () ] + and any_to_nl = + parser + [ [: `'\r' | '\n' :] -> () + | [: `_; s :] -> any_to_nl s + | [: :] -> () ] + in + fun cstrm -> + try next_token_loc cstrm with + [ Stream.Error str -> + err (mkloc(Stream.count cstrm, Stream.count cstrm + 1)) str ] + ; + value locerr () = invalid_arg "Lexer: location function"; + value loct_create () = ref (Array.create 1024 None); + value loct_func loct i = + match + if i < 0 || i >= Array.length loct.val then None + else Array.unsafe_get loct.val i + with + [ Some loc -> loc + | _ -> locerr () ] + ; + value loct_add loct i loc = + do { + if i >= Array.length loct.val then do { + let new_tmax = Array.length loct.val * 2 in + let new_loct = Array.create new_tmax None in + Array.blit loct.val 0 new_loct 0 (Array.length loct.val); + loct.val := new_loct + } + else (); + loct.val.(i) := Some loc + } + ; + value func kwd_table = + let bolpos = ref 0 in + let lnum = ref 0 in + let fname = ref "" in + let find = Hashtbl.find kwd_table in + let lex cstrm = + let next_token_loc = next_token_fun find find fname lnum bolpos in + let loct = loct_create () in + let ts = + Stream.from + (fun i -> + let (tok, loc) = next_token_loc cstrm in + do { loct_add loct i loc; Some tok }) + in + let locf = loct_func loct in + (ts, locf) + in + lex + ; + value rec check_keyword_stream = + parser [: _ = check; _ = Stream.empty :] -> True + and check = + parser + [ [: `'A'..'Z' | 'a'..'z' | 'À'..'Ö' | 'Ø'..'ö' | 'ø'..'ÿ'; s :] -> + check_ident s + | [: `'!' | '?' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' | + '%' | '.' + ; + s :] -> + check_ident2 s + | [: `'<'; s :] -> + match Stream.npeek 1 s with + [ [':' | '<'] -> () + | _ -> check_ident2 s ] + | [: `':'; + _ = + parser + [ [: `']' | ':' | '=' | '>' :] -> () + | [: :] -> () ] :] ep -> + () + | [: `'>' | '|'; + _ = + parser + [ [: `']' | '}' :] -> () + | [: a = check_ident2 :] -> a ] :] -> + () + | [: `'[' | '{'; s :] -> + match Stream.npeek 2 s with + [ ['<'; '<' | ':'] -> () + | _ -> + match s with parser + [ [: :] -> + match Stream.peek __strm with + [ Some ('|' | '<' | ':') -> Stream.junk __strm + | _ -> () ] ] ] + | [: `';'; _ = parser [ [: `';' :] -> () | [: :] -> () ] :] -> () + | [: `_ :] -> () ] + and check_ident = + parser + [ [: `'A'..'Z' | 'a'..'z' | 'À'..'Ö' | 'Ø'..'ö' | 'ø'..'ÿ' | '0'..'9' | + '_' | ''' + ; + s :] -> + check_ident s + | [: :] -> () ] + and check_ident2 = + parser + [ [: `'!' | '?' | '~' | '=' | '@' | '^' | '&' | '+' | '-' | '*' | '/' | + '%' | '.' | ':' | '<' | '>' | '|' + ; + s :] -> + check_ident2 s + | [: :] -> () ] + ; + value check_keyword s = + try check_keyword_stream (Stream.of_string s) with _ -> False + ; + value using_token kwd_table (p_con, p_prm) = + match p_con with + [ "" -> + try + let _ = Hashtbl.find kwd_table p_prm in + () + with + [ Not_found -> + if check_keyword p_prm then Hashtbl.add kwd_table p_prm p_prm + else + raise + (Token.Error + ("the token \"" ^ p_prm ^ + "\" does not respect Plexer rules")) ] + | "LIDENT" | "UIDENT" | "INT" | "FLOAT" | "CHAR" | "STRING" | + "QUOTATION" | "ANTIQUOT" | "LOCATE" | "LABEL" | "ELABEL" | "EOI" -> + () + | _ -> + raise + (Token.Error + ("the constructor \"" ^ p_con ^ + "\" is not recognized by Llexer")) ] + ; + value removing_token kwd_table (p_con, p_prm) = + if p_con = "" then Hashtbl.remove kwd_table p_prm else () + ; + value text = + fun + [ ("", t) -> "'" ^ t ^ "'" + | ("LIDENT", "") -> "lowercase identifier" + | ("LIDENT", t) -> "'" ^ t ^ "'" + | ("UIDENT", "") -> "uppercase identifier" + | ("UIDENT", t) -> "'" ^ t ^ "'" + | ("INT", "") -> "integer" + | ("INT", s) -> "'" ^ s ^ "'" + | ("FLOAT", "") -> "float" + | ("STRING", "") -> "string" + | ("CHAR", "") -> "char" + | ("QUOTATION", "") -> "quotation" + | ("ANTIQUOT", k) -> "antiquot \"" ^ k ^ "\"" + | ("LOCATE", "") -> "locate" + | ("LABEL", "") -> "label" + | ("ELABEL", "") -> "elabel" + | ("EOI", "") -> "end of input" + | (con, "") -> con + | (con, prm) -> con ^ " \"" ^ prm ^ "\"" ] + ; + value eq_before_colon p e = + loop 0 where rec loop i = + if i == String.length e then + failwith "Internal error in Plexer: incorrect ANTIQUOT" + else if i == String.length p then e.[i] == ':' + else if p.[i] == e.[i] then loop (i + 1) + else False + ; + value after_colon e = + try + let i = String.index e ':' in + String.sub e (i + 1) (String.length e - i - 1) + with + [ Not_found -> "" ] + ; + value gmake () = + let kwd_table = Hashtbl.create 301 in + {tok_func = func kwd_table; tok_using = using_token kwd_table; + tok_removing = removing_token kwd_table; + tok_match = Token.default_match; tok_text = text; tok_comm = None} + ; + end +; + +open Stdpp; +open Pcaml; + +Pcaml.no_constructors_arity.val := True; + +do { + Grammar.Unsafe.gram_reinit gram (Plexer.gmake ()); + Grammar.Unsafe.clear_entry interf; + Grammar.Unsafe.clear_entry implem; + Grammar.Unsafe.clear_entry top_phrase; + Grammar.Unsafe.clear_entry use_file; + Grammar.Unsafe.clear_entry module_type; + Grammar.Unsafe.clear_entry module_expr; + Grammar.Unsafe.clear_entry sig_item; + Grammar.Unsafe.clear_entry str_item; + Grammar.Unsafe.clear_entry expr; + Grammar.Unsafe.clear_entry patt; + Grammar.Unsafe.clear_entry ctyp; + Grammar.Unsafe.clear_entry let_binding; + Grammar.Unsafe.clear_entry class_type; + Grammar.Unsafe.clear_entry class_expr; + Grammar.Unsafe.clear_entry class_sig_item; + Grammar.Unsafe.clear_entry class_str_item +}; + +Pcaml.parse_interf.val := Grammar.Entry.parse interf; +Pcaml.parse_implem.val := Grammar.Entry.parse implem; + +value o2b = + fun + [ Some _ -> True + | None -> False ] +; + +value mkumin loc f arg = + match arg with + [ <:expr< $int:n$ >> when int_of_string n > 0 -> + let n = "-" ^ n in + <:expr< $int:n$ >> + | <:expr< $flo:n$ >> when float_of_string n > 0.0 -> + let n = "-" ^ n in + <:expr< $flo:n$ >> + | _ -> + let f = "~" ^ f in + <:expr< $lid:f$ $arg$ >> ] +; + +external loc_of_node : 'a -> Loc.t = "%field0"; + +value mklistexp loc last = + loop True where rec loop top = + fun + [ [] -> + match last with + [ Some e -> e + | None -> <:expr< [] >> ] + | [e1 :: el] -> + let loc = if top then loc else (fst (loc_of_node e1), snd loc) in + <:expr< [$e1$ :: $loop False el$] >> ] +; + +value mklistpat loc last = + loop True where rec loop top = + fun + [ [] -> + match last with + [ Some p -> p + | None -> <:patt< [] >> ] + | [p1 :: pl] -> + let loc = if top then loc else (fst (loc_of_node p1), snd loc) in + <:patt< [$p1$ :: $loop False pl$] >> ] +; + +value neg s = string_of_int (- int_of_string s); + +value is_operator = + let ht = Hashtbl.create 73 in + let ct = Hashtbl.create 73 in + do { + List.iter (fun x -> Hashtbl.add ht x True) + ["asr"; "land"; "lor"; "lsl"; "lsr"; "lxor"; "mod"; "or"]; + List.iter (fun x -> Hashtbl.add ct x True) + ['!'; '&'; '*'; '+'; '-'; '/'; ':'; '<'; '='; '>'; '@'; '^'; '|'; '~'; + '?'; '%'; '.']; + fun x -> + try Hashtbl.find ht x with + [ Not_found -> try Hashtbl.find ct x.[0] with _ -> False ] + } +; + +(* +value p_operator strm = + match Stream.peek strm with + [ Some (Token.Tterm "(") -> + match Stream.npeek 3 strm with + [ [_; Token.Tterm x; Token.Tterm ")"] when is_operator x -> + do { Stream.junk strm; Stream.junk strm; Stream.junk strm; x } + | _ -> raise Stream.Failure ] + | _ -> raise Stream.Failure ] +; + +value operator = Grammar.Entry.of_parser gram "operator" p_operator; +*) + +value operator = + Grammar.Entry.of_parser gram "operator" + (parser [: `("", x) when is_operator x :] -> x) +; + +value symbolchar = + let list = + ['!'; '$'; '%'; '&'; '*'; '+'; '-'; '.'; '/'; ':'; '<'; '='; '>'; '?'; + '@'; '^'; '|'; '~'] + in + let rec loop s i = + if i == String.length s then True + else if List.mem s.[i] list then loop s (i + 1) + else False + in + loop +; + +value prefixop = + let list = ['!'; '?'; '~'] in + let excl = ["!="] in + Grammar.Entry.of_parser gram "prefixop" + (parser + [: `("", x) + when + not (List.mem x excl) && String.length x >= 2 && + List.mem x.[0] list && symbolchar x 1 :] -> + x) +; + +value infixop0 = + let list = ['='; '<'; '>'; '|'; '&'; '$'] in + let excl = ["<-"; "||"; "&&"] in + Grammar.Entry.of_parser gram "infixop0" + (parser + [: `("", x) + when + not (List.mem x excl) && String.length x >= 2 && + List.mem x.[0] list && symbolchar x 1 :] -> + x) +; + +value infixop1 = + let list = ['@'; '^'] in + Grammar.Entry.of_parser gram "infixop1" + (parser + [: `("", x) + when + String.length x >= 2 && List.mem x.[0] list && + symbolchar x 1 :] -> + x) +; + +value infixop2 = + let list = ['+'; '-'] in + Grammar.Entry.of_parser gram "infixop2" + (parser + [: `("", x) + when + x <> "->" && String.length x >= 2 && List.mem x.[0] list && + symbolchar x 1 :] -> + x) +; + +value infixop3 = + let list = ['*'; '/'; '%'] in + Grammar.Entry.of_parser gram "infixop3" + (parser + [: `("", x) + when + String.length x >= 2 && List.mem x.[0] list && + symbolchar x 1 :] -> + x) +; + +value infixop4 = + Grammar.Entry.of_parser gram "infixop4" + (parser + [: `("", x) + when + String.length x >= 3 && x.[0] == '*' && x.[1] == '*' && + symbolchar x 2 :] -> + x) +; + +value test_constr_decl = + Grammar.Entry.of_parser gram "test_constr_decl" + (fun strm -> + match Stream.npeek 1 strm with + [ [("UIDENT", _)] -> + match Stream.npeek 2 strm with + [ [_; ("", ".")] -> raise Stream.Failure + | [_; ("", "(")] -> raise Stream.Failure + | [_ :: _] -> () + | _ -> raise Stream.Failure ] + | [("", "|")] -> () + | _ -> raise Stream.Failure ]) +; + +value stream_peek_nth n strm = + loop n (Stream.npeek n strm) where rec loop n = + fun + [ [] -> None + | [x] -> if n == 1 then Some x else None + | [_ :: l] -> loop (n - 1) l ] +; + +value test_label_eq = + let rec test lev strm = + match stream_peek_nth lev strm with + [ Some (("UIDENT", _) | ("LIDENT", _) | ("", ".")) -> test (lev + 1) strm + | Some ("", "=") -> () + | _ -> raise Stream.Failure ] + in + Grammar.Entry.of_parser gram "test_label_eq" (test 1) +; + +value constr_arity = ref [("Some", 1); ("Match_Failure", 1)]; + +value rec constr_expr_arity = + fun + [ <:expr< $uid:c$ >> -> + try List.assoc c constr_arity.val with [ Not_found -> 0 ] + | <:expr< $uid:_$.$e$ >> -> constr_expr_arity e + | _ -> 1 ] +; + +value rec constr_patt_arity = + fun + [ <:patt< $uid:c$ >> -> + try List.assoc c constr_arity.val with [ Not_found -> 0 ] + | <:patt< $uid:_$.$p$ >> -> constr_patt_arity p + | _ -> 1 ] +; + +value rec get_seq = + fun + [ <:expr< do { $list:el$ } >> -> el + | e -> [e] ] +; + +value choose_tvar tpl = + let rec find_alpha v = + let s = String.make 1 v in + if List.mem_assoc s tpl then + if v = 'z' then None else find_alpha (Char.chr (Char.code v + 1)) + else Some (String.make 1 v) + in + let rec make_n n = + let v = "a" ^ string_of_int n in + if List.mem_assoc v tpl then make_n (succ n) else v + in + match find_alpha 'a' with + [ Some x -> x + | None -> make_n 1 ] +; + +value rec patt_lid = + fun + [ <:patt< $lid:i$ $p$ >> -> Some (i, [p]) + | <:patt< $p1$ $p2$ >> -> + match patt_lid p1 with + [ Some (i, pl) -> Some (i, [p2 :: pl]) + | None -> None ] + | _ -> None ] +; + +value type_parameter = Grammar.Entry.create gram "type_parameter"; +value fun_def = Grammar.Entry.create gram "fun_def"; +value fun_binding = Grammar.Entry.create gram "fun_binding"; + +EXTEND + GLOBAL: interf implem top_phrase use_file sig_item str_item ctyp patt expr + module_type module_expr let_binding type_parameter fun_def fun_binding; + (* Main entry points *) + interf: + [ [ st = LIST0 [ s = sig_item; OPT ";;" -> (s, loc) ]; EOI -> + (st, False) ] ] + ; + implem: + [ [ st = LIST0 [ s = str_item; OPT ";;" -> (s, loc) ]; EOI -> + (st, False) ] ] + ; + top_phrase: + [ [ ph = phrase; ";;" -> Some ph + | EOI -> None ] ] + ; + use_file: + [ [ l = LIST0 [ ph = phrase; OPT ";;" -> ph ]; EOI -> (l, False) ] ] + ; + phrase: + [ [ sti = str_item -> sti + | "#"; n = LIDENT; dp = dir_param -> MLast.StDir loc n dp ] ] + ; + dir_param: + [ [ -> None + | e = expr -> Some e ] ] + ; + (* Module expressions *) + module_expr: + [ [ "functor"; "("; i = UIDENT; ":"; t = module_type; ")"; "->"; + me = SELF -> + <:module_expr< functor ( $i$ : $t$ ) -> $me$ >> + | "struct"; st = LIST0 [ s = str_item; OPT ";;" -> s ]; "end" -> + <:module_expr< struct $list:st$ end >> ] + | [ me1 = SELF; me2 = SELF -> <:module_expr< $me1$ $me2$ >> ] + | [ i = mod_expr_ident -> i + | "("; me = SELF; ":"; mt = module_type; ")" -> + <:module_expr< ( $me$ : $mt$ ) >> + | "("; me = SELF; ")" -> <:module_expr< $me$ >> ] ] + ; + mod_expr_ident: + [ LEFTA + [ m1 = SELF; "."; m2 = SELF -> <:module_expr< $m1$ . $m2$ >> ] + | [ m = UIDENT -> <:module_expr< $uid:m$ >> ] ] + ; + str_item: + [ "top" + [ "exception"; (_, c, tl) = constructor_declaration -> + <:str_item< exception $c$ of $list:tl$ >> + | "external"; i = LIDENT; ":"; t = ctyp; "="; pd = LIST1 STRING -> + <:str_item< external $i$ : $t$ = $list:pd$ >> + | "external"; i = LABEL; t = ctyp; "="; pd = LIST1 STRING -> + <:str_item< external $i$ : $t$ = $list:pd$ >> + | "external"; "("; i = operator; ")"; ":"; t = ctyp; "="; + pd = LIST1 STRING -> + <:str_item< external $i$ : $t$ = $list:pd$ >> + | "module"; i = UIDENT; mb = module_binding -> + <:str_item< module $i$ = $mb$ >> + | "module"; "type"; i = UIDENT; "="; mt = module_type -> + <:str_item< module type $i$ = $mt$ >> + | "open"; i = mod_ident -> <:str_item< open $i$ >> + | "type"; tdl = LIST1 type_declaration SEP "and" -> + <:str_item< type $list:tdl$ >> + | "let"; r = OPT "rec"; l = LIST1 let_binding SEP "and"; "in"; + x = expr -> + let e = <:expr< let $opt:o2b r$ $list:l$ in $x$ >> in + <:str_item< $exp:e$ >> + | "let"; r = OPT "rec"; l = LIST1 let_binding SEP "and" -> + match l with + [ [(<:patt< _ >>, e)] -> <:str_item< $exp:e$ >> + | _ -> <:str_item< value $opt:o2b r$ $list:l$ >> ] + | "let"; "module"; m = UIDENT; mb = module_binding; "in"; e = expr -> + <:str_item< let module $m$ = $mb$ in $e$ >> + | e = expr -> <:str_item< $exp:e$ >> ] ] + ; + module_binding: + [ RIGHTA + [ "("; m = UIDENT; ":"; mt = module_type; ")"; mb = SELF -> + <:module_expr< functor ( $m$ : $mt$ ) -> $mb$ >> + | ":"; mt = module_type; "="; me = module_expr -> + <:module_expr< ( $me$ : $mt$ ) >> + | "="; me = module_expr -> <:module_expr< $me$ >> ] ] + ; + (* Module types *) + module_type: + [ [ "functor"; "("; i = UIDENT; ":"; t = SELF; ")"; "->"; mt = SELF -> + <:module_type< functor ( $i$ : $t$ ) -> $mt$ >> ] + | [ mt = SELF; "with"; wcl = LIST1 with_constr SEP "and" -> + <:module_type< $mt$ with $list:wcl$ >> ] + | [ "sig"; sg = LIST0 [ s = sig_item; OPT ";;" -> s ]; "end" -> + <:module_type< sig $list:sg$ end >> + | i = mod_type_ident -> i + | "("; mt = SELF; ")" -> <:module_type< $mt$ >> ] ] + ; + mod_type_ident: + [ LEFTA + [ m1 = SELF; "."; m2 = SELF -> <:module_type< $m1$ . $m2$ >> + | m1 = SELF; "("; m2 = SELF; ")" -> <:module_type< $m1$ $m2$ >> ] + | [ m = UIDENT -> <:module_type< $uid:m$ >> + | m = LIDENT -> <:module_type< $lid:m$ >> ] ] + ; + sig_item: + [ "top" + [ "exception"; (_, c, tl) = constructor_declaration -> + <:sig_item< exception $c$ of $list:tl$ >> + | "external"; i = LIDENT; ":"; t = ctyp; "="; pd = LIST1 STRING -> + <:sig_item< external $i$ : $t$ = $list:pd$ >> + | "external"; i = LABEL; t = ctyp; "="; pd = LIST1 STRING -> + <:sig_item< external $i$ : $t$ = $list:pd$ >> + | "external"; "("; i = operator; ")"; ":"; t = ctyp; "="; + pd = LIST1 STRING -> + <:sig_item< external $i$ : $t$ = $list:pd$ >> + | "include"; mt = module_type -> <:sig_item< include $mt$ >> + | "module"; i = UIDENT; mt = module_declaration -> + <:sig_item< module $i$ : $mt$ >> + | "module"; "type"; i = UIDENT; "="; mt = module_type -> + <:sig_item< module type $i$ = $mt$ >> + | "open"; i = mod_ident -> <:sig_item< open $i$ >> + | "type"; tdl = LIST1 type_declaration SEP "and" -> + <:sig_item< type $list:tdl$ >> + | "val"; i = LIDENT; ":"; t = ctyp -> <:sig_item< value $i$ : $t$ >> + | "val"; i = LABEL; t = ctyp -> <:sig_item< value $i$ : $t$ >> + | "val"; "("; i = operator; ")"; ":"; t = ctyp -> + <:sig_item< value $i$ : $t$ >> ] ] + ; + module_declaration: + [ RIGHTA + [ ":"; mt = module_type -> <:module_type< $mt$ >> + | "("; i = UIDENT; ":"; t = module_type; ")"; mt = SELF -> + <:module_type< functor ( $i$ : $t$ ) -> $mt$ >> ] ] + ; + (* "with" constraints (additional type equations over signature + components) *) + with_constr: + [ [ "type"; tp = type_parameters; i = mod_ident; "="; t = ctyp -> + MLast.WcTyp loc i tp t + | "module"; i = mod_ident; "="; me = module_expr -> + MLast.WcMod loc i me ] ] + ; + (* Core expressions *) + expr: + [ "top" LEFTA + [ e1 = SELF; ";"; e2 = SELF -> + <:expr< do { $list:[e1 :: get_seq e2]$ } >> + | e1 = SELF; ";" -> e1 ] + | "expr1" + [ "let"; o = OPT "rec"; l = LIST1 let_binding SEP "and"; "in"; + x = expr LEVEL "top" -> + <:expr< let $opt:o2b o$ $list:l$ in $x$ >> + | "let"; "module"; m = UIDENT; mb = module_binding; "in"; + e = expr LEVEL "top" -> + <:expr< let module $m$ = $mb$ in $e$ >> + | "function"; OPT "|"; l = LIST1 match_case SEP "|" -> + <:expr< fun [ $list:l$ ] >> + | "fun"; p = patt LEVEL "simple"; e = fun_def -> + <:expr< fun [$p$ -> $e$] >> + | "match"; x = SELF; "with"; OPT "|"; l = LIST1 match_case SEP "|" -> + <:expr< match $x$ with [ $list:l$ ] >> + | "try"; x = SELF; "with"; OPT "|"; l = LIST1 match_case SEP "|" -> + <:expr< try $x$ with [ $list:l$ ] >> + | "if"; e1 = SELF; "then"; e2 = expr LEVEL "expr1"; + e3 = [ "else"; e = expr LEVEL "expr1" -> e | -> <:expr< () >> ] -> + <:expr< if $e1$ then $e2$ else $e3$ >> + | "for"; i = LIDENT; "="; e1 = SELF; df = direction_flag; e2 = SELF; + "do"; e = SELF; "done" -> + <:expr< for $i$ = $e1$ $to:df$ $e2$ do { $list:get_seq e$ } >> + | "while"; e1 = SELF; "do"; e2 = SELF; "done" -> + <:expr< while $e1$ do { $list:get_seq e2$ } >> ] + | [ e = SELF; ","; el = LIST1 NEXT SEP "," -> + <:expr< ( $list:[e :: el]$ ) >> ] + | ":=" NONA + [ e1 = SELF; ":="; e2 = expr LEVEL "expr1" -> + <:expr< $e1$.val := $e2$ >> + | e1 = SELF; "<-"; e2 = expr LEVEL "expr1" -> <:expr< $e1$ := $e2$ >> ] + | "||" RIGHTA + [ e1 = SELF; f = [ op = "or" -> op | op = "||" -> op ]; e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "&&" RIGHTA + [ e1 = SELF; f = [ op = "&" -> op | op = "&&" -> op ]; e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "<" LEFTA + [ e1 = SELF; + f = + [ op = "<" -> op + | op = ">" -> op + | op = "<=" -> op + | op = ">=" -> op + | op = "=" -> op + | op = "<>" -> op + | op = "==" -> op + | op = "!=" -> op + | op = infixop0 -> op ]; + e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "^" RIGHTA + [ e1 = SELF; + f = [ op = "^" -> op | op = "@" -> op | op = infixop1 -> op ]; + e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | RIGHTA + [ e1 = SELF; "::"; e2 = SELF -> <:expr< [$e1$ :: $e2$] >> ] + | "+" LEFTA + [ e1 = SELF; + f = + [ op = "+" -> op + | op = "-" -> op + | op = "+." -> op + | op = "-." -> op + | op = infixop2 -> op ]; + e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "*" LEFTA + [ e1 = SELF; + f = + [ op = "*" -> op + | op = "/" -> op + | op = "*." -> op + | op = "/." -> op + | op = "land" -> op + | op = "lor" -> op + | op = "lxor" -> op + | op = "mod" -> op + | op = infixop3 -> op ]; + e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "**" RIGHTA + [ e1 = SELF; + f = + [ op = "**" -> op + | op = "asr" -> op + | op = "lsl" -> op + | op = "lsr" -> op + | op = infixop4 -> op ]; + e2 = SELF -> + <:expr< $lid:f$ $e1$ $e2$ >> ] + | "unary minus" NONA + [ f = [ op = "-" -> op | op = "-." -> op ]; e = SELF -> + <:expr< $mkumin loc f e$ >> ] + | "apply" LEFTA + [ e1 = SELF; e2 = SELF -> + match constr_expr_arity e1 with + [ 1 -> <:expr< $e1$ $e2$ >> + | _ -> + match e2 with + [ <:expr< ( $list:el$ ) >> -> + List.fold_left (fun e1 e2 -> <:expr< $e1$ $e2$ >>) e1 el + | _ -> <:expr< $e1$ $e2$ >> ] ] + | "assert"; e = expr LEVEL "simple" -> + match e with + [ <:expr< False >> -> MLast.ExAsf loc + | _ -> MLast.ExAsr loc e ] + | "lazy"; e = SELF -> + <:expr< lazy ($e$) >> ] + | "simple" LEFTA + [ e1 = SELF; "."; "("; e2 = SELF; ")" -> <:expr< $e1$ .( $e2$ ) >> + | e1 = SELF; "."; "["; e2 = SELF; "]" -> <:expr< $e1$ .[ $e2$ ] >> + | e1 = SELF; "."; e2 = SELF -> <:expr< $e1$ . $e2$ >> + | "!"; e = SELF -> <:expr< $e$ . val>> + | f = + [ op = "~-" -> op + | op = "~-." -> op + | op = "~" -> op + | op = prefixop -> op ]; + e = SELF -> + <:expr< $lid:f$ $e$ >> + | s = INT -> <:expr< $int:s$ >> + | s = FLOAT -> <:expr< $flo:s$ >> + | s = STRING -> <:expr< $str:s$ >> + | c = CHAR -> <:expr< $chr:c$ >> + | i = expr_ident -> i + | s = "false" -> <:expr< False >> + | s = "true" -> <:expr< True >> + | "["; "]" -> <:expr< [] >> + | "["; el = expr1_semi_list; "]" -> <:expr< $mklistexp loc None el$ >> + | "[|"; "|]" -> <:expr< [| |] >> + | "[|"; el = expr1_semi_list; "|]" -> <:expr< [| $list:el$ |] >> + | "{"; test_label_eq; lel = lbl_expr_list; "}" -> + <:expr< { $list:lel$ } >> + | "{"; e = expr LEVEL "simple"; "with"; lel = lbl_expr_list; "}" -> + <:expr< { ($e$) with $list:lel$ } >> + | "("; ")" -> <:expr< () >> + | "("; e = SELF; ":"; t = ctyp; ")" -> <:expr< ($e$ : $t$) >> + | "("; e = SELF; ")" -> <:expr< $e$ >> + | "("; "-"; ")" -> <:expr< $lid:"-"$ >> + | "("; "-."; ")" -> <:expr< $lid:"-."$ >> + | "("; op = operator; ")" -> <:expr< $lid:op$ >> + | "begin"; e = SELF; "end" -> <:expr< $e$ >> + | x = LOCATE -> + let x = + try + let i = String.index x ':' in + ({Lexing.pos_fname = ""; + Lexing.pos_lnum = 0; + Lexing.pos_bol = 0; + Lexing.pos_cnum = int_of_string (String.sub x 0 i)}, + String.sub x (i + 1) (String.length x - i - 1)) + with + [ Not_found | Failure _ -> (Token.nowhere, x) ] + in + Pcaml.handle_expr_locate loc x + | x = QUOTATION -> + let x = + try + let i = String.index x ':' in + (String.sub x 0 i, + String.sub x (i + 1) (String.length x - i - 1)) + with + [ Not_found -> ("", x) ] + in + Pcaml.handle_expr_quotation loc x ] ] + ; + let_binding: + [ [ p = patt; e = fun_binding -> + match patt_lid p with + [ Some (i, pl) -> + let e = + List.fold_left (fun e p -> <:expr< fun $p$ -> $e$ >>) e pl + in + (<:patt< $lid:i$ >>, e) + | None -> (p, e) ] ] ] + ; + fun_binding: + [ RIGHTA + [ p = patt LEVEL "simple"; e = SELF -> <:expr< fun $p$ -> $e$ >> + | "="; e = expr -> <:expr< $e$ >> + | ":"; t = ctyp; "="; e = expr -> <:expr< ($e$ : $t$) >> ] ] + ; + match_case: + [ [ x1 = patt; w = OPT [ "when"; e = expr -> e ]; "->"; x2 = expr -> + (x1, w, x2) ] ] + ; + lbl_expr_list: + [ [ le = lbl_expr; ";"; lel = SELF -> [le :: lel] + | le = lbl_expr; ";" -> [le] + | le = lbl_expr -> [le] ] ] + ; + lbl_expr: + [ [ i = patt_label_ident; "="; e = expr LEVEL "expr1" -> (i, e) ] ] + ; + expr1_semi_list: + [ [ e = expr LEVEL "expr1"; ";"; el = SELF -> [e :: el] + | e = expr LEVEL "expr1"; ";" -> [e] + | e = expr LEVEL "expr1" -> [e] ] ] + ; + fun_def: + [ RIGHTA + [ p = patt LEVEL "simple"; e = SELF -> <:expr< fun $p$ -> $e$ >> + | "->"; e = expr -> <:expr< $e$ >> ] ] + ; + expr_ident: + [ RIGHTA + [ i = LIDENT -> <:expr< $lid:i$ >> + | i = UIDENT -> <:expr< $uid:i$ >> + | m = UIDENT; "."; i = SELF -> + let rec loop m = + fun + [ <:expr< $x$ . $y$ >> -> loop <:expr< $m$ . $x$ >> y + | e -> <:expr< $m$ . $e$ >> ] + in + loop <:expr< $uid:m$ >> i + | m = UIDENT; "."; "("; i = operator; ")" -> + <:expr< $uid:m$ . $lid:i$ >> ] ] + ; + (* Patterns *) + patt: + [ LEFTA + [ p1 = SELF; "as"; i = LIDENT -> <:patt< ($p1$ as $lid:i$) >> ] + | LEFTA + [ p1 = SELF; "|"; p2 = SELF -> <:patt< $p1$ | $p2$ >> ] + | [ p = SELF; ","; pl = LIST1 NEXT SEP "," -> + <:patt< ( $list:[p :: pl]$) >> ] + | NONA + [ p1 = SELF; ".."; p2 = SELF -> <:patt< $p1$ .. $p2$ >> ] + | RIGHTA + [ p1 = SELF; "::"; p2 = SELF -> <:patt< [$p1$ :: $p2$] >> ] + | LEFTA + [ p1 = SELF; p2 = SELF -> + match constr_patt_arity p1 with + [ 1 -> <:patt< $p1$ $p2$ >> + | n -> + let p2 = + match p2 with + [ <:patt< _ >> when n > 1 -> + let pl = + loop n where rec loop n = + if n = 0 then [] else [<:patt< _ >> :: loop (n - 1)] + in + <:patt< ( $list:pl$ ) >> + | _ -> p2 ] + in + match p2 with + [ <:patt< ( $list:pl$ ) >> -> + List.fold_left (fun p1 p2 -> <:patt< $p1$ $p2$ >>) p1 pl + | _ -> <:patt< $p1$ $p2$ >> ] ] ] + | LEFTA + [ p1 = SELF; "."; p2 = SELF -> <:patt< $p1$ . $p2$ >> ] + | "simple" + [ s = LIDENT -> <:patt< $lid:s$ >> + | s = UIDENT -> <:patt< $uid:s$ >> + | s = INT -> <:patt< $int:s$ >> + | "-"; s = INT -> <:patt< $int:neg s$ >> + | s = STRING -> <:patt< $str:s$ >> + | s = CHAR -> <:patt< $chr:s$ >> + | s = "false" -> <:patt< False >> + | s = "true" -> <:patt< True >> + | "["; "]" -> <:patt< [] >> + | "["; pl = patt_semi_list; "]" -> <:patt< $mklistpat loc None pl$ >> + | "[|"; "|]" -> <:patt< [| |] >> + | "[|"; pl = patt_semi_list; "|]" -> <:patt< [| $list:pl$ |] >> + | "{"; lpl = lbl_patt_list; "}" -> <:patt< { $list:lpl$ } >> + | "("; ")" -> <:patt< () >> + | "("; p = SELF; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> + | "("; p = SELF; ")" -> <:patt< $p$ >> + | "("; "-"; ")" -> <:patt< $lid:"-"$ >> + | "("; op = operator; ")" -> <:patt< $lid:op$ >> + | "_" -> <:patt< _ >> + | x = LOCATE -> + let x = + try + let i = String.index x ':' in + ({Lexing.pos_fname = ""; + Lexing.pos_lnum = 0; + Lexing.pos_bol = 0; + Lexing.pos_cnum = int_of_string (String.sub x 0 i)}, + String.sub x (i + 1) (String.length x - i - 1)) + with + [ Not_found | Failure _ -> (Token.nowhere, x) ] + in + Pcaml.handle_patt_locate loc x + | x = QUOTATION -> + let x = + try + let i = String.index x ':' in + (String.sub x 0 i, + String.sub x (i + 1) (String.length x - i - 1)) + with + [ Not_found -> ("", x) ] + in + Pcaml.handle_patt_quotation loc x ] ] + ; + patt_semi_list: + [ [ p = patt; ";"; pl = SELF -> [p :: pl] + | p = patt; ";" -> [p] + | p = patt -> [p] ] ] + ; + lbl_patt_list: + [ [ le = lbl_patt; ";"; lel = SELF -> [le :: lel] + | le = lbl_patt; ";" -> [le] + | le = lbl_patt -> [le] ] ] + ; + lbl_patt: + [ [ i = patt_label_ident; "="; p = patt -> (i, p) ] ] + ; + patt_label_ident: + [ RIGHTA + [ i = UIDENT -> <:patt< $uid:i$ >> + | i = LIDENT -> <:patt< $lid:i$ >> + | m = UIDENT; "."; i = SELF -> <:patt< $uid:m$ . $i$ >> ] ] + ; + (* Type declaration *) + type_declaration: + [ [ tpl = type_parameters; n = type_patt; "="; tk = type_kind; + cl = LIST0 constrain -> + (n, tpl, tk, cl) + | tpl = type_parameters; n = type_patt; cl = LIST0 constrain -> + (n, tpl, <:ctyp< '$choose_tvar tpl$ >>, cl) ] ] + ; + type_patt: + [ [ n = LIDENT -> (loc, n) ] ] + ; + constrain: + [ [ "constraint"; t1 = ctyp; "="; t2 = ctyp -> (t1, t2) ] ] + ; + type_kind: + [ [ test_constr_decl; OPT "|"; + cdl = LIST1 constructor_declaration SEP "|" -> + <:ctyp< [ $list:cdl$ ] >> + | t = ctyp -> <:ctyp< $t$ >> + | t = ctyp; "="; "{"; ldl = label_declarations; "}" -> + <:ctyp< $t$ == { $list:ldl$ } >> + | t = ctyp; "="; OPT "|"; cdl = LIST1 constructor_declaration SEP "|" -> + <:ctyp< $t$ == [ $list:cdl$ ] >> + | "{"; ldl = label_declarations; "}" -> <:ctyp< { $list:ldl$ } >> ] ] + ; + type_parameters: + [ [ -> (* empty *) [] + | tp = type_parameter -> [tp] + | "("; tpl = LIST1 type_parameter SEP ","; ")" -> tpl ] ] + ; + type_parameter: + [ [ "'"; i = ident -> (i, (False, False)) ] ] + ; + constructor_declaration: + [ [ ci = UIDENT; "of"; cal = LIST1 ctyp LEVEL "ctyp1" SEP "*" -> + (loc, ci, cal) + | ci = UIDENT -> (loc, ci, []) ] ] + ; + label_declarations: + [ [ ld = label_declaration; ";"; ldl = SELF -> [ld :: ldl] + | ld = label_declaration; ";" -> [ld] + | ld = label_declaration -> [ld] ] ] + ; + label_declaration: + [ [ i = LIDENT; ":"; t = ctyp -> (loc, i, False, t) + | i = LABEL; t = ctyp -> (loc, i, False, t) + | "mutable"; i = LIDENT; ":"; t = ctyp -> (loc, i, True, t) + | "mutable"; i = LABEL; t = ctyp -> (loc, i, True, t) ] ] + ; + (* Core types *) + ctyp: + [ [ t1 = SELF; "as"; "'"; i = ident -> <:ctyp< $t1$ as '$i$ >> ] + | "arrow" RIGHTA + [ t1 = SELF; "->"; t2 = SELF -> <:ctyp< $t1$ -> $t2$ >> ] + | [ t = SELF; "*"; tl = LIST1 ctyp LEVEL "ctyp1" SEP "*" -> + <:ctyp< ( $list:[t :: tl]$ ) >> ] + | "ctyp1" + [ t1 = SELF; t2 = SELF -> <:ctyp< $t2$ $t1$ >> ] + | "ctyp2" + [ t1 = SELF; "."; t2 = SELF -> <:ctyp< $t1$ . $t2$ >> + | t1 = SELF; "("; t2 = SELF; ")" -> <:ctyp< $t1$ $t2$ >> ] + | "simple" + [ "'"; i = ident -> <:ctyp< '$i$ >> + | "_" -> <:ctyp< _ >> + | i = LIDENT -> <:ctyp< $lid:i$ >> + | i = UIDENT -> <:ctyp< $uid:i$ >> + | "("; t = SELF; ","; tl = LIST1 ctyp SEP ","; ")"; + i = ctyp LEVEL "ctyp2" -> + List.fold_left (fun c a -> <:ctyp< $c$ $a$ >>) i [t :: tl] + | "("; t = SELF; ")" -> <:ctyp< $t$ >> ] ] + ; + (* Identifiers *) + ident: + [ [ i = LIDENT -> i + | i = UIDENT -> i ] ] + ; + mod_ident: + [ RIGHTA + [ i = UIDENT -> [i] + | i = LIDENT -> [i] + | m = UIDENT; "."; i = SELF -> [m :: i] ] ] + ; + (* Miscellaneous *) + direction_flag: + [ [ "to" -> True + | "downto" -> False ] ] + ; +END; + +(* Objects and Classes *) + +value rec class_type_of_ctyp loc t = + match t with + [ <:ctyp< $lid:i$ >> -> <:class_type< $list:[i]$ >> + | <:ctyp< $uid:m$.$t$ >> -> <:class_type< $list:[m :: type_id_list t]$ >> + | _ -> raise_with_loc loc (Stream.Error "lowercase identifier expected") ] +and type_id_list = + fun + [ <:ctyp< $uid:m$.$t$ >> -> [m :: type_id_list t] + | <:ctyp< $lid:i$ >> -> [i] + | t -> + raise_with_loc (loc_of_node t) + (Stream.Error "lowercase identifier expected") ] +; + +value class_fun_binding = Grammar.Entry.create gram "class_fun_binding"; + +EXTEND + GLOBAL: str_item sig_item expr ctyp class_sig_item class_str_item class_type + class_expr class_fun_binding; + str_item: + [ [ "class"; cd = LIST1 class_declaration SEP "and" -> + <:str_item< class $list:cd$ >> + | "class"; "type"; ctd = LIST1 class_type_declaration SEP "and" -> + <:str_item< class type $list:ctd$ >> ] ] + ; + sig_item: + [ [ "class"; cd = LIST1 class_description SEP "and" -> + <:sig_item< class $list:cd$ >> + | "class"; "type"; ctd = LIST1 class_type_declaration SEP "and" -> + <:sig_item< class type $list:ctd$ >> ] ] + ; + (* Class expressions *) + class_declaration: + [ [ vf = OPT "virtual"; ctp = class_type_parameters; i = LIDENT; + cfb = class_fun_binding -> + {MLast.ciLoc = loc; MLast.ciVir = o2b vf; MLast.ciPrm = ctp; + MLast.ciNam = i; MLast.ciExp = cfb} ] ] + ; + class_fun_binding: + [ [ "="; ce = class_expr -> ce + | ":"; ct = class_type; "="; ce = class_expr -> + <:class_expr< ($ce$ : $ct$) >> + | p = patt LEVEL "simple"; cfb = SELF -> + <:class_expr< fun $p$ -> $cfb$ >> ] ] + ; + class_type_parameters: + [ [ -> (loc, []) + | "["; tpl = LIST1 type_parameter SEP ","; "]" -> (loc, tpl) ] ] + ; + class_fun_def: + [ [ p = patt LEVEL "simple"; "->"; ce = class_expr -> + <:class_expr< fun $p$ -> $ce$ >> + | p = patt LEVEL "simple"; cfd = SELF -> + <:class_expr< fun $p$ -> $cfd$ >> ] ] + ; + class_expr: + [ "top" + [ "fun"; cfd = class_fun_def -> cfd + | "let"; rf = OPT "rec"; lb = LIST1 let_binding SEP "and"; "in"; + ce = SELF -> + <:class_expr< let $opt:o2b rf$ $list:lb$ in $ce$ >> ] + | "apply" NONA + [ ce = SELF; e = expr LEVEL "label" -> + <:class_expr< $ce$ $e$ >> ] + | "simple" + [ "["; ct = ctyp; ","; ctcl = LIST1 ctyp SEP ","; "]"; + ci = class_longident -> + <:class_expr< $list:ci$ [ $list:[ct :: ctcl]$ ] >> + | "["; ct = ctyp; "]"; ci = class_longident -> + <:class_expr< $list:ci$ [ $ct$ ] >> + | ci = class_longident -> <:class_expr< $list:ci$ >> + | "object"; cspo = OPT class_self_patt; cf = class_structure; "end" -> + <:class_expr< object $opt:cspo$ $list:cf$ end >> + | "("; ce = SELF; ":"; ct = class_type; ")" -> + <:class_expr< ($ce$ : $ct$) >> + | "("; ce = SELF; ")" -> ce ] ] + ; + class_structure: + [ [ cf = LIST0 class_str_item -> cf ] ] + ; + class_self_patt: + [ [ "("; p = patt; ")" -> p + | "("; p = patt; ":"; t = ctyp; ")" -> <:patt< ($p$ : $t$) >> ] ] + ; + class_str_item: + [ [ "inherit"; ce = class_expr; pb = OPT [ "as"; i = LIDENT -> i ] -> + <:class_str_item< inherit $ce$ $opt:pb$ >> + | "val"; (lab, mf, e) = cvalue -> + <:class_str_item< value $opt:mf$ $lab$ = $e$ >> + | "method"; "private"; "virtual"; l = label; ":"; t = ctyp -> + <:class_str_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; "private"; l = label; ":"; t = ctyp -> + <:class_str_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; l = label; ":"; t = ctyp -> + <:class_str_item< method virtual $l$ : $t$ >> + | "method"; "private"; l = label; fb = fun_binding -> + <:class_str_item< method private $l$ = $fb$ >> + | "method"; l = label; fb = fun_binding -> + <:class_str_item< method $l$ = $fb$ >> + | "constraint"; t1 = ctyp; "="; t2 = ctyp -> + <:class_str_item< type $t1$ = $t2$ >> + | "initializer"; se = expr -> <:class_str_item< initializer $se$ >> ] ] + ; + cvalue: + [ [ mf = OPT "mutable"; l = label; "="; e = expr -> (l, o2b mf, e) + | mf = OPT "mutable"; l = label; ":"; t = ctyp; "="; e = expr -> + (l, o2b mf, <:expr< ($e$ : $t$) >>) + | mf = OPT "mutable"; l = label; ":"; t1 = ctyp; ":>"; t2 = ctyp; "="; + e = expr -> + (l, o2b mf, <:expr< ($e$ : $t1$ :> $t2$) >>) + | mf = OPT "mutable"; l = label; ":>"; t = ctyp; "="; e = expr -> + (l, o2b mf, <:expr< ($e$ :> $t$) >>) ] ] + ; + label: + [ [ i = LIDENT -> i ] ] + ; + (* Class types *) + class_type: + [ [ t = ctyp LEVEL "ctyp1" -> class_type_of_ctyp loc t + | t = ctyp LEVEL "ctyp1"; "->"; ct = SELF -> + <:class_type< [ $t$ ] -> $ct$ >> + | t = ctyp LEVEL "ctyp1"; "*"; tl = LIST1 ctyp LEVEL "simple" SEP "*"; + "->"; ct = SELF -> + <:class_type< [ ($t$ * $list:tl$) ] -> $ct$ >> + | cs = class_signature -> cs ] ] + ; + class_signature: + [ [ "["; tl = LIST1 ctyp SEP ","; "]"; id = clty_longident -> + <:class_type< $list:id$ [ $list:tl$ ] >> + | id = clty_longident -> <:class_type< $list:id$ >> + | "object"; cst = OPT class_self_type; csf = LIST0 class_sig_item; + "end" -> + <:class_type< object $opt:cst$ $list:csf$ end >> ] ] + ; + class_self_type: + [ [ "("; t = ctyp; ")" -> t ] ] + ; + class_sig_item: + [ [ "inherit"; cs = class_signature -> <:class_sig_item< inherit $cs$ >> + | "val"; mf = OPT "mutable"; l = label; ":"; t = ctyp -> + <:class_sig_item< value $opt:o2b mf$ $l$ : $t$ >> + | "method"; "private"; "virtual"; l = label; ":"; t = ctyp -> + <:class_sig_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; "private"; l = label; ":"; t = ctyp -> + <:class_sig_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; l = label; ":"; t = ctyp -> + <:class_sig_item< method virtual $l$ : $t$ >> + | "method"; "private"; l = label; ":"; t = ctyp -> + <:class_sig_item< method private $l$ : $t$ >> + | "method"; l = label; ":"; t = ctyp -> + <:class_sig_item< method $l$ : $t$ >> + | "constraint"; t1 = ctyp; "="; t2 = ctyp -> + <:class_sig_item< type $t1$ = $t2$ >> ] ] + ; + class_description: + [ [ vf = OPT "virtual"; ctp = class_type_parameters; n = LIDENT; ":"; + ct = class_type -> + {MLast.ciLoc = loc; MLast.ciVir = o2b vf; MLast.ciPrm = ctp; + MLast.ciNam = n; MLast.ciExp = ct} + | vf = OPT "virtual"; ctp = class_type_parameters; n = LABEL; + ct = class_type -> + {MLast.ciLoc = loc; MLast.ciVir = o2b vf; MLast.ciPrm = ctp; + MLast.ciNam = n; MLast.ciExp = ct} ] ] + ; + class_type_declaration: + [ [ vf = OPT "virtual"; ctp = class_type_parameters; n = LIDENT; "="; + cs = class_signature -> + {MLast.ciLoc = loc; MLast.ciVir = o2b vf; MLast.ciPrm = ctp; + MLast.ciNam = n; MLast.ciExp = cs} ] ] + ; + (* Expressions *) + expr: LEVEL "apply" + [ LEFTA + [ "new"; i = class_longident -> <:expr< new $list:i$ >> ] ] + ; + expr: LEVEL "simple" + [ [ e = SELF; "#"; lab = label -> <:expr< $e$ # $lab$ >> ] ] + ; + expr: LEVEL "simple" + [ [ "("; e = SELF; ":"; t1 = ctyp; ":>"; t2 = ctyp; ")" -> + <:expr< ($e$ : $t1$ :> $t2$) >> + | "("; e = SELF; ":>"; t = ctyp; ")" -> <:expr< ($e$ :> $t$) >> + | "{<"; ">}" -> <:expr< {< >} >> + | "{<"; fel = field_expr_list; ">}" -> <:expr< {< $list:fel$ >} >> ] ] + ; + field_expr_list: + [ [ l = label; "="; e = expr LEVEL "expr1"; ";"; fel = SELF -> + [(l, e) :: fel] + | l = label; "="; e = expr LEVEL "expr1"; ";" -> [(l, e)] + | l = label; "="; e = expr LEVEL "expr1" -> [(l, e)] ] ] + ; + (* Core types *) + ctyp: LEVEL "simple" + [ [ "#"; id = class_longident -> <:ctyp< # $list:id$ >> + | "<"; (ml, v) = meth_list; ">" -> <:ctyp< < $list:ml$ $opt:v$ > >> + | "<"; ">" -> <:ctyp< < > >> ] ] + ; + meth_list: + [ [ f = field; ";"; (ml, v) = SELF -> ([f :: ml], v) + | f = field; ";" -> ([f], False) + | f = field -> ([f], False) + | ".." -> ([], True) ] ] + ; + field: + [ [ lab = LIDENT; ":"; t = ctyp -> (lab, t) + | lab = LABEL; t = ctyp -> (lab, t) ] ] + ; + (* Identifiers *) + clty_longident: + [ [ m = UIDENT; "."; l = SELF -> [m :: l] + | i = LIDENT -> [i] ] ] + ; + class_longident: + [ [ m = UIDENT; "."; l = SELF -> [m :: l] + | i = LIDENT -> [i] ] ] + ; +END; + +(* Labels *) + +EXTEND + GLOBAL: ctyp expr patt fun_def fun_binding class_type class_fun_binding; + ctyp: AFTER "arrow" + [ NONA + [ i = LABEL; t = SELF -> <:ctyp< ~ $i$ : $t$ >> + | "?"; i = LABEL; t = SELF -> <:ctyp< ? $i$ : $t$ >> ] ] + ; + ctyp: LEVEL "simple" + [ [ "["; OPT "|"; rfl = LIST0 row_field SEP "|"; "]" -> + <:ctyp< [ = $list:rfl$ ] >> + | "["; ">"; OPT "|"; rfl = LIST1 row_field SEP "|"; "]" -> + <:ctyp< [ > $list:rfl$ ] >> + | "[<"; OPT "|"; rfl = LIST1 row_field SEP "|"; "]" -> + <:ctyp< [ < $list:rfl$ ] >> + | "[<"; OPT "|"; rfl = LIST1 row_field SEP "|"; ">"; + ntl = LIST1 name_tag; "]" -> + <:ctyp< [ < $list:rfl$ > $list:ntl$ ] >> ] ] + ; + row_field: + [ [ "`"; i = ident -> MLast.RfTag i False [] + | "`"; i = ident; "of"; ao = OPT "&"; l = LIST1 ctyp SEP "&" -> + MLast.RfTag i (o2b ao) l + | "`"; i = ident; "&"; l = LIST1 ctyp SEP "&" -> MLast.RfTag i True l + | "`"; i = ident; l = LIST1 ctyp SEP "&" -> MLast.RfTag i False l ] ] + ; + name_tag: + [ [ "`"; i = ident -> i ] ] + ; + expr: LEVEL "expr1" + [ [ "fun"; p = labeled_patt; e = fun_def -> <:expr< fun $p$ -> $e$ >> ] ] + ; + expr: AFTER "apply" + [ "label" + [ i = LABEL; e = SELF -> <:expr< ~ $i$ : $e$ >> + | i = ELABEL -> <:expr< ~ $i$ >> + | "?"; i = LABEL; e = SELF -> <:expr< ? $i$ : $e$ >> + | "?"; i = ELABEL -> <:expr< ? $i$ >> ] ] + ; + expr: LEVEL "simple" + [ [ "`"; s = ident -> <:expr< ` $s$ >> ] ] + ; + fun_def: + [ [ p = labeled_patt; e = SELF -> <:expr< fun $p$ -> $e$ >> ] ] + ; + fun_binding: + [ [ p = labeled_patt; e = SELF -> <:expr< fun $p$ -> $e$ >> ] ] + ; + patt: LEVEL "simple" + [ [ "`"; s = ident -> <:patt< ` $s$ >> ] ] + ; + labeled_patt: + [ [ i = LABEL; p = patt LEVEL "simple" -> <:patt< ~ $i$ : $p$ >> + | i = ELABEL -> <:patt< ~ $i$ >> + | "?"; i = LABEL; j = LIDENT -> <:patt< ? $i$ : ($lid:j$) >> + | "?"; "("; i = LABEL; j = LIDENT; ")" -> <:patt< ? $i$ : ($lid:j$) >> + | "?"; "("; i = LABEL; j = LIDENT; "="; e = expr; ")" -> + <:patt< ? $i$ : ( $lid:j$ = $e$ ) >> + | "?"; i = ELABEL -> <:patt< ? $i$ : ($lid:i$) >> + | "?"; "("; i = ELABEL; "="; e = expr; ")" -> + <:patt< ? $i$ : ( $lid:i$ = $e$ ) >> ] ] + ; + class_type: + [ [ i = LABEL; t = ctyp LEVEL "ctyp1"; "->"; ct = SELF -> + <:class_type< [ ~ $i$ : $t$ ] -> $ct$ >> + | "?"; i = LABEL; t = ctyp LEVEL "ctyp1"; "->"; ct = SELF -> + <:class_type< [ ? $i$ : $t$ ] -> $ct$ >> ] ] + ; + class_fun_binding: + [ [ p = labeled_patt; cfb = SELF -> <:class_expr< fun $p$ -> $cfb$ >> ] ] + ; + ident: + [ [ i = LIDENT -> i + | i = UIDENT -> i ] ] + ; +END; + +type spat_comp = + [ SpTrm of Loc.t and MLast.patt and option MLast.expr + | SpNtr of Loc.t and MLast.patt and MLast.expr + | SpStr of Loc.t and MLast.patt ] +; +type sexp_comp = + [ SeTrm of Loc.t and MLast.expr | SeNtr of Loc.t and MLast.expr ] +; + +value strm_n = "__strm"; +value peek_fun loc = <:expr< Stream.peek >>; +value junk_fun loc = <:expr< Stream.junk >>; + +(* Parsers. *) +(* In syntax generated, many cases are optimisations. *) + +value rec pattern_eq_expression p e = + match (p, e) with + [ (<:patt< $lid:a$ >>, <:expr< $lid:b$ >>) -> a = b + | (<:patt< $uid:a$ >>, <:expr< $uid:b$ >>) -> a = b + | (<:patt< $p1$ $p2$ >>, <:expr< $e1$ $e2$ >>) -> + pattern_eq_expression p1 e1 && pattern_eq_expression p2 e2 + | _ -> False ] +; + +value is_raise e = + match e with + [ <:expr< raise $_$ >> -> True + | _ -> False ] +; + +value is_raise_failure e = + match e with + [ <:expr< raise Stream.Failure >> -> True + | _ -> False ] +; + +value rec handle_failure e = + match e with + [ <:expr< try $te$ with [ Stream.Failure -> $e$] >> -> handle_failure e + | <:expr< match $me$ with [ $list:pel$ ] >> -> + handle_failure me && + List.for_all + (fun + [ (_, None, e) -> handle_failure e + | _ -> False ]) + pel + | <:expr< let $list:pel$ in $e$ >> -> + List.for_all (fun (p, e) -> handle_failure e) pel && handle_failure e + | <:expr< $lid:_$ >> | <:expr< $int:_$ >> | <:expr< $str:_$ >> | + <:expr< $chr:_$ >> | <:expr< fun [ $list:_$ ] >> | <:expr< $uid:_$ >> -> + True + | <:expr< raise $e$ >> -> + match e with + [ <:expr< Stream.Failure >> -> False + | _ -> True ] + | <:expr< $f$ $x$ >> -> + is_constr_apply f && handle_failure f && handle_failure x + | _ -> False ] +and is_constr_apply = + fun + [ <:expr< $uid:_$ >> -> True + | <:expr< $lid:_$ >> -> False + | <:expr< $x$ $_$ >> -> is_constr_apply x + | _ -> False ] +; + +value rec subst v e = + let loc = MLast.loc_of_expr e in + match e with + [ <:expr< $lid:x$ >> -> + let x = if x = v then strm_n else x in + <:expr< $lid:x$ >> + | <:expr< $uid:_$ >> -> e + | <:expr< $int:_$ >> -> e + | <:expr< $chr:_$ >> -> e + | <:expr< $str:_$ >> -> e + | <:expr< $_$ . $_$ >> -> e + | <:expr< let $opt:rf$ $list:pel$ in $e$ >> -> + <:expr< let $opt:rf$ $list:List.map (subst_pe v) pel$ in $subst v e$ >> + | <:expr< $e1$ $e2$ >> -> <:expr< $subst v e1$ $subst v e2$ >> + | <:expr< ( $list:el$ ) >> -> <:expr< ( $list:List.map (subst v) el$ ) >> + | _ -> raise Not_found ] +and subst_pe v (p, e) = + match p with + [ <:patt< $lid:v'$ >> -> if v = v' then (p, e) else (p, subst v e) + | _ -> raise Not_found ] +; + +value stream_pattern_component skont ckont = + fun + [ SpTrm loc p wo -> + <:expr< match $peek_fun loc$ $lid:strm_n$ with + [ Some $p$ $when:wo$ -> + do { $junk_fun loc$ $lid:strm_n$; $skont$ } + | _ -> $ckont$ ] >> + | SpNtr loc p e -> + let e = + match e with + [ <:expr< fun [ ($lid:v$ : Stream.t _) -> $e$ ] >> when v = strm_n -> + e + | _ -> <:expr< $e$ $lid:strm_n$ >> ] + in + if pattern_eq_expression p skont then + if is_raise_failure ckont then e + else if handle_failure e then e + else <:expr< try $e$ with [ Stream.Failure -> $ckont$ ] >> + else if is_raise_failure ckont then <:expr< let $p$ = $e$ in $skont$ >> + else if pattern_eq_expression <:patt< Some $p$ >> skont then + <:expr< try Some $e$ with [ Stream.Failure -> $ckont$ ] >> + else if is_raise ckont then + let tst = + if handle_failure e then e + else <:expr< try $e$ with [ Stream.Failure -> $ckont$ ] >> + in + <:expr< let $p$ = $tst$ in $skont$ >> + else + <:expr< match try Some $e$ with [ Stream.Failure -> None ] with + [ Some $p$ -> $skont$ + | _ -> $ckont$ ] >> + | SpStr loc p -> + try + match p with + [ <:patt< $lid:v$ >> -> subst v skont + | _ -> raise Not_found ] + with + [ Not_found -> <:expr< let $p$ = $lid:strm_n$ in $skont$ >> ] ] +; + +value rec stream_pattern loc epo e ekont = + fun + [ [] -> + match epo with + [ Some ep -> <:expr< let $ep$ = Stream.count $lid:strm_n$ in $e$ >> + | _ -> e ] + | [(spc, err) :: spcl] -> + let skont = + let ekont err = + let str = + match err with + [ Some estr -> estr + | _ -> <:expr< "" >> ] + in + <:expr< raise (Stream.Error $str$) >> + in + stream_pattern loc epo e ekont spcl + in + let ckont = ekont err in + stream_pattern_component skont ckont spc ] +; + +value stream_patterns_term loc ekont tspel = + let pel = + List.map + (fun (p, w, loc, spcl, epo, e) -> + let p = <:patt< Some $p$ >> in + let e = + let ekont err = + let str = + match err with + [ Some estr -> estr + | _ -> <:expr< "" >> ] + in + <:expr< raise (Stream.Error $str$) >> + in + let skont = stream_pattern loc epo e ekont spcl in + <:expr< do { $junk_fun loc$ $lid:strm_n$; $skont$ } >> + in + (p, w, e)) + tspel + in + let pel = pel @ [(<:patt< _ >>, None, ekont ())] in + <:expr< match $peek_fun loc$ $lid:strm_n$ with [ $list:pel$ ] >> +; + +value rec group_terms = + fun + [ [([(SpTrm loc p w, None) :: spcl], epo, e) :: spel] -> + let (tspel, spel) = group_terms spel in + ([(p, w, loc, spcl, epo, e) :: tspel], spel) + | spel -> ([], spel) ] +; + +value rec parser_cases loc = + fun + [ [] -> <:expr< raise Stream.Failure >> + | spel -> + match group_terms spel with + [ ([], [(spcl, epo, e) :: spel]) -> + stream_pattern loc epo e (fun _ -> parser_cases loc spel) spcl + | (tspel, spel) -> + stream_patterns_term loc (fun _ -> parser_cases loc spel) tspel ] ] +; + +value cparser loc bpo pc = + let e = parser_cases loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $e$ >> + | None -> e ] + in + let p = <:patt< ($lid:strm_n$ : Stream.t _) >> in + <:expr< fun $p$ -> $e$ >> +; + +value cparser_match loc me bpo pc = + let pc = parser_cases loc pc in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >> + | None -> pc ] + in + <:expr< let $lid:strm_n$ = $me$ in $e$ >> +; + +(* streams *) + +value rec not_computing = + fun + [ <:expr< $lid:_$ >> | <:expr< $uid:_$ >> | <:expr< $int:_$ >> | + <:expr< $flo:_$ >> | <:expr< $chr:_$ >> | <:expr< $str:_$ >> -> + True + | <:expr< $x$ $y$ >> -> is_cons_apply_not_computing x && not_computing y + | _ -> False ] +and is_cons_apply_not_computing = + fun + [ <:expr< $uid:_$ >> -> True + | <:expr< $lid:_$ >> -> False + | <:expr< $x$ $y$ >> -> is_cons_apply_not_computing x && not_computing y + | _ -> False ] +; + +value slazy loc e = + match e with + [ <:expr< $f$ () >> -> + match f with + [ <:expr< $lid:_$ >> -> f + | _ -> <:expr< fun _ -> $e$ >> ] + | _ -> <:expr< fun _ -> $e$ >> ] +; + +value rec cstream gloc = + fun + [ [] -> + let loc = gloc in + <:expr< Stream.sempty >> + | [SeTrm loc e] -> + if not_computing e then <:expr< Stream.ising $e$ >> + else <:expr< Stream.lsing $slazy loc e$ >> + | [SeTrm loc e :: secl] -> + if not_computing e then <:expr< Stream.icons $e$ $cstream gloc secl$ >> + else <:expr< Stream.lcons $slazy loc e$ $cstream gloc secl$ >> + | [SeNtr loc e] -> + if not_computing e then e else <:expr< Stream.slazy $slazy loc e$ >> + | [SeNtr loc e :: secl] -> + if not_computing e then <:expr< Stream.iapp $e$ $cstream gloc secl$ >> + else <:expr< Stream.lapp $slazy loc e$ $cstream gloc secl$ >> ] +; + +(* Syntax extensions in Ocaml grammar *) + +EXTEND + GLOBAL: expr; + expr: LEVEL "expr1" + [ [ "parser"; po = OPT ipatt; OPT "|"; pcl = LIST1 parser_case SEP "|" -> + <:expr< $cparser loc po pcl$ >> + | "match"; e = SELF; "with"; "parser"; po = OPT ipatt; OPT "|"; + pcl = LIST1 parser_case SEP "|" -> + <:expr< $cparser_match loc e po pcl$ >> ] ] + ; + parser_case: + [ [ "[<"; sp = stream_patt; ">]"; po = OPT ipatt; "->"; e = expr -> + (sp, po, e) ] ] + ; + stream_patt: + [ [ spc = stream_patt_comp -> [(spc, None)] + | spc = stream_patt_comp; ";" -> [(spc, None)] + | spc = stream_patt_comp; ";"; sp = stream_patt_comp_err_list -> + [(spc, None) :: sp] + | -> (* empty *) [] ] ] + ; + stream_patt_comp_err_list: + [ [ spc = stream_patt_comp_err -> [spc] + | spc = stream_patt_comp_err; ";" -> [spc] + | spc = stream_patt_comp_err; ";"; sp = SELF -> [spc :: sp] ] ] + ; + stream_patt_comp: + [ [ "'"; p = patt; eo = OPT [ "when"; e = expr LEVEL "expr1" -> e ] -> + SpTrm loc p eo + | p = patt; "="; e = expr LEVEL "expr1" -> SpNtr loc p e + | p = patt -> SpStr loc p ] ] + ; + stream_patt_comp_err: + [ [ spc = stream_patt_comp; + eo = OPT [ "?"; e = expr LEVEL "expr1" -> e ] -> + (spc, eo) ] ] + ; + ipatt: + [ [ i = LIDENT -> <:patt< $lid:i$ >> ] ] + ; + expr: LEVEL "simple" + [ [ "[<"; ">]" -> <:expr< $cstream loc []$ >> + | "[<"; sel = stream_expr_comp_list; ">]" -> + <:expr< $cstream loc sel$ >> ] ] + ; + stream_expr_comp_list: + [ [ se = stream_expr_comp; ";"; sel = SELF -> [se :: sel] + | se = stream_expr_comp; ";" -> [se] + | se = stream_expr_comp -> [se] ] ] + ; + stream_expr_comp: + [ [ "'"; e = expr LEVEL "expr1" -> SeTrm loc e + | e = expr LEVEL "expr1" -> SeNtr loc e ] ] + ; +END; diff --git a/camlp4/unmaintained/scheme/.depend b/camlp4/unmaintained/scheme/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/scheme/Makefile b/camlp4/unmaintained/scheme/Makefile new file mode 100644 index 0000000..01036c2 --- /dev/null +++ b/camlp4/unmaintained/scheme/Makefile @@ -0,0 +1,85 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_lefteval +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. +CAMLP4=../../camlp4/camlp4$(EXE) + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) + +P4INCLUDES= -nolib -I ../../meta -I ../../etc +OCAMLINCLUDES= -nostdlib -I $(OCAMLTOP)/stdlib -I ../../camlp4 -I ../../lib -I ../../etc +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SCHSRC=pa_scheme.sc +SRC=pa_scheme.ml pr_scheme.ml pr_schp_main.ml +OBJS=$(SRC:.ml=.cmo) +OBJSX=$(OCAMLSRC:.ml=.cmx) + +all: $(OBJS) pr_schemep.cmo camlp4sch$(EXE) + +opt: all + +bootstrap: camlp4sch$(EXE) save + ./camlp4sch$(EXE) ../../etc/q_phony.cmo ../../meta/pa_extend.cmo ../../etc/pr_r.cmo ../../etc/pr_extend.cmo ../../etc/pr_rp.cmo -impl pa_scheme.sc \ + | sed -e 's/^;; \(.*\)$$/(* \1 *)/' -e 's/^; \(.*\)$$/(* \1 *)/' \ + -e 's/$$Id.*\$$/File generated by pretty print; do not edit!/' > pa_scheme.ml + @if cmp -s pa_scheme.ml SAVED/pa_scheme.ml; then \ + echo 'pa_scheme.ml and SAVED/pa_scheme.ml are identical' ; \ + else \ + echo '**** Note: pa_scheme.ml differs from SAVED/pa_scheme.ml'; \ + fi + +save: + test -d SAVED || mkdir SAVED + mkdir SAVED.$$$$ && mv SAVED pa_scheme.ml SAVED.$$$$ && mv SAVED.$$$$ SAVED + +restore: + mv SAVED SAVED.$$$$ && mv SAVED.$$$$/* . && rmdir SAVED.$$$$ + +depend: + cp .depend .depend.bak + > .depend + for file in $(SRC); do \ + $(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $$file` pr_depend.cmo $$i | \ + sed -e 's| \.\./\.\./\.\.| $$(OCAMLTOP)|g' >> .depend; \ + done + +clean: + rm -f camlp4sch$(EXE) *.cm* *.$(O) *.bak .*.bak + +camlp4sch: pa_scheme.cmo + rm -f camlp4sch + DIR=`pwd` && cd ../../camlp4 && $(MAKE) CAMLP4=$$DIR/camlp4sch CAMLP4M="-I $$DIR pa_scheme.cmo ../meta/pr_dump.cmo" + +pr_schemep.cmo: pr_schp_main.cmo + $(OCAMLC) ../../etc/parserify.cmo pr_schp_main.cmo -a -o $@ + +.SUFFIXES: .cmx .cmo .cmi .ml .mli + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<` -loc loc" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<` -loc loc" -c $< + +include .depend diff --git a/camlp4/unmaintained/scheme/README b/camlp4/unmaintained/scheme/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/scheme/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/scheme/pa_scheme.ml b/camlp4/unmaintained/scheme/pa_scheme.ml new file mode 100644 index 0000000..4389321 --- /dev/null +++ b/camlp4/unmaintained/scheme/pa_scheme.ml @@ -0,0 +1,1093 @@ +(* pa_r.cmo pa_rp.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo *) +(* ********************************************************************** *) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(* ********************************************************************** *) +(* File generated by pretty print; do not edit! *) + +open Pcaml; +open Stdpp; + +type choice 'a 'b = + [ Left of 'a + | Right of 'b ] +; + +(* Buffer *) + +module Buff = + struct + value buff = ref (String.create 80); + value store len x = + do { + if len >= String.length buff.val then + buff.val := buff.val ^ String.create (String.length buff.val) + else (); + buff.val.[len] := x; + succ len + } + ; + value get len = String.sub buff.val 0 len; + end +; + +(* Lexer *) + +value rec skip_to_eol = + parser + [ [: `'\n' | '\r' :] -> () + | [: `_; s :] -> skip_to_eol s ] +; + +value no_ident = ['('; ')'; '['; ']'; '{'; '}'; ' '; '\t'; '\n'; '\r'; ';']; + +value rec ident len = + parser + [ [: `'.' :] -> (Buff.get len, True) + | [: `x when not (List.mem x no_ident); s :] -> ident (Buff.store len x) s + | [: :] -> (Buff.get len, False) ] +; + +value identifier kwt (s, dot) = + let con = + try do { (Hashtbl.find kwt s : unit); "" } with + [ Not_found -> + match s.[0] with + [ 'A'..'Z' -> if dot then "UIDENTDOT" else "UIDENT" + | _ -> if dot then "LIDENTDOT" else "LIDENT" ] ] + in + (con, s) +; + +value rec string len = + parser + [ [: `'"' :] -> Buff.get len + | [: `'\\'; `c; s :] -> string (Buff.store (Buff.store len '\\') c) s + | [: `x; s :] -> string (Buff.store len x) s ] +; + +value rec end_exponent_part_under len = + parser + [ [: `('0'..'9' as c); s :] -> end_exponent_part_under (Buff.store len c) s + | [: :] -> ("FLOAT", Buff.get len) ] +; + +value end_exponent_part len = + parser + [ [: `('0'..'9' as c); s :] -> end_exponent_part_under (Buff.store len c) s + | [: :] -> raise (Stream.Error "ill-formed floating-point constant") ] +; + +value exponent_part len = + parser + [ [: `('+' | '-' as c); s :] -> end_exponent_part (Buff.store len c) s + | [: a = end_exponent_part len :] -> a ] +; + +value rec decimal_part len = + parser + [ [: `('0'..'9' as c); s :] -> decimal_part (Buff.store len c) s + | [: `'e' | 'E'; s :] -> exponent_part (Buff.store len 'E') s + | [: :] -> ("FLOAT", Buff.get len) ] +; + +value rec number len = + parser + [ [: `('0'..'9' as c); s :] -> number (Buff.store len c) s + | [: `'.'; s :] -> decimal_part (Buff.store len '.') s + | [: `'e' | 'E'; s :] -> exponent_part (Buff.store len 'E') s + | [: :] -> ("INT", Buff.get len) ] +; + +value binary = parser [: `('0'..'1' as c) :] -> c; + +value octal = parser [: `('0'..'7' as c) :] -> c; + +value hexa = parser [: `('0'..'9' | 'a'..'f' | 'A'..'F' as c) :] -> c; + +value rec digits_under kind len = + parser + [ [: d = kind; s :] -> digits_under kind (Buff.store len d) s + | [: :] -> Buff.get len ] +; + +value digits kind bp len = + parser + [ [: d = kind; s :] -> ("INT", digits_under kind (Buff.store len d) s) + | [: s :] ep -> + raise_with_loc + (Reloc.shift_pos bp Reloc.zero_loc, Reloc.shift_pos ep Reloc.zero_loc) + (Failure "ill-formed integer constant") ] +; + +value base_number kwt bp len = + parser + [ [: `'b' | 'B'; s :] -> digits binary bp (Buff.store len 'b') s + | [: `'o' | 'O'; s :] -> digits octal bp (Buff.store len 'o') s + | [: `'x' | 'X'; s :] -> digits hexa bp (Buff.store len 'x') s + | [: id = ident (Buff.store 0 '#') :] -> identifier kwt id ] +; + +value rec operator len = + parser + [ [: `'.' :] -> Buff.get (Buff.store len '.') + | [: :] -> Buff.get len ] +; + +value char_or_quote_id x = + parser + [ [: `''' :] -> ("CHAR", String.make 1 x) + | [: s :] ep -> + if List.mem x no_ident then + Stdpp.raise_with_loc + (Reloc.shift_pos (ep - 2) Reloc.zero_loc, + Reloc.shift_pos (ep - 1) Reloc.zero_loc) + (Stream.Error "bad quote") + else + let len = Buff.store (Buff.store 0 ''') x in + let (s, dot) = ident len s in + (if dot then "LIDENTDOT" else "LIDENT", s) ] +; + +value rec char len = + parser + [ [: `''' :] -> len + | [: `x; s :] -> char (Buff.store len x) s ] +; + +value quote = + parser + [ [: `'\\'; len = char (Buff.store 0 '\\') :] -> ("CHAR", Buff.get len) + | [: `x; s :] -> char_or_quote_id x s ] +; + +(* The system with LIDENTDOT and UIDENTDOT is not great (it would be *) +(* better to have a token DOT (actually SPACEDOT and DOT)) but it is *) +(* the only way (that I have found) to have a good behaviour in the *) +(* toplevel (not expecting tokens after a phrase). Drawbacks: 1/ to be *) +(* complete, we should have STRINGDOT, RIGHTPARENDOT, and so on 2/ the *) +(* parser rule with dot is right associative and we have to reverse *) +(* the resulting tree (using the function leftify). *) +(* This is a complicated issue: the behaviour of the OCaml toplevel *) +(* is strange, anyway. For example, even without Camlp4, The OCaml *) +(* toplevel accepts that: *) +(* # let x = 32;; foo bar match let ) *) + +value rec lexer kwt = parser [: t = lexer0 kwt; _ = no_dot :] -> t +and no_dot = + parser + [ [: `'.' :] ep -> + Stdpp.raise_with_loc + (Reloc.shift_pos (ep - 1) Reloc.zero_loc, + Reloc.shift_pos ep Reloc.zero_loc) + (Stream.Error "bad dot") + | [: :] -> () ] +and lexer0 kwt = + parser bp + [ [: `'\t' | '\n' | '\r'; s :] -> lexer0 kwt s + | [: `' '; s :] -> after_space kwt s + | [: `';'; _ = skip_to_eol; s :] -> lexer kwt s + | [: `'(' :] -> (("", "("), (bp, bp + 1)) + | [: `')'; s :] ep -> (("", rparen s), (bp, ep)) + | [: `'[' :] -> (("", "["), (bp, bp + 1)) + | [: `']' :] -> (("", "]"), (bp, bp + 1)) + | [: `'{' :] -> (("", "{"), (bp, bp + 1)) + | [: `'}' :] -> (("", "}"), (bp, bp + 1)) + | [: `'"'; s = string 0 :] ep -> (("STRING", s), (bp, ep)) + | [: `'''; tok = quote :] ep -> (tok, (bp, ep)) + | [: `'<'; tok = less kwt :] ep -> (tok, (bp, ep)) + | [: `'-'; tok = minus kwt :] ep -> (tok, (bp, ep)) + | [: `'~'; tok = tilde :] ep -> (tok, (bp, ep)) + | [: `'?'; tok = question :] ep -> (tok, (bp, ep)) + | [: `'#'; tok = base_number kwt bp (Buff.store 0 '0') :] ep -> + (tok, (bp, ep)) + | [: `('0'..'9' as c); tok = number (Buff.store 0 c) :] ep -> + (tok, (bp, ep)) + | [: `('+' | '*' | '/' as c); id = operator (Buff.store 0 c) :] ep -> + (identifier kwt (id, False), (bp, ep)) + | [: `x; id = ident (Buff.store 0 x) :] ep -> (identifier kwt id, (bp, ep)) + | [: :] -> (("EOI", ""), (bp, bp + 1)) ] +and rparen = + parser + [ [: `'.' :] -> ")." + | [: ___ :] -> ")" ] +and after_space kwt = + parser + [ [: `'.' :] ep -> (("", "."), (ep - 1, ep)) + | [: x = lexer0 kwt :] -> x ] +and tilde = + parser + [ [: `('a'..'z' as c); (s, dot) = ident (Buff.store 0 c) :] -> + ("TILDEIDENT", s) + | [: :] -> ("LIDENT", "~") ] +and question = + parser + [ [: `('a'..'z' as c); (s, dot) = ident (Buff.store 0 c) :] -> + ("QUESTIONIDENT", s) + | [: :] -> ("LIDENT", "?") ] +and minus kwt = + parser + [ [: `'.' :] -> identifier kwt ("-.", False) + | [: `('0'..'9' as c); n = number (Buff.store (Buff.store 0 '-') c) :] -> + n + | [: id = ident (Buff.store 0 '-') :] -> identifier kwt id ] +and less kwt = + parser + [ [: `':'; lab = label 0; `'<' ? "'<' expected"; q = quotation 0 :] -> + ("QUOT", lab ^ ":" ^ q) + | [: id = ident (Buff.store 0 '<') :] -> identifier kwt id ] +and label len = + parser + [ [: `('a'..'z' | 'A'..'Z' | '_' as c); s :] -> label (Buff.store len c) s + | [: :] -> Buff.get len ] +and quotation len = + parser + [ [: `'>'; s :] -> quotation_greater len s + | [: `x; s :] -> quotation (Buff.store len x) s + | [: :] -> failwith "quotation not terminated" ] +and quotation_greater len = + parser + [ [: `'>' :] -> Buff.get len + | [: a = quotation (Buff.store len '>') :] -> a ] +; + +value lexer_using kwt (con, prm) = + match con with + [ "CHAR" | "EOI" | "INT" | "FLOAT" | "LIDENT" | "LIDENTDOT" | + "QUESTIONIDENT" | "QUOT" | "STRING" | "TILDEIDENT" | "UIDENT" | + "UIDENTDOT" -> + () + | "ANTIQUOT" -> () + | "" -> + try Hashtbl.find kwt prm with [ Not_found -> Hashtbl.add kwt prm () ] + | _ -> + raise + (Token.Error + ("the constructor \"" ^ con ^ "\" is not recognized by Plexer")) ] +; + +value lexer_text (con, prm) = + if con = "" then "'" ^ prm ^ "'" + else if prm = "" then con + else con ^ " \"" ^ prm ^ "\"" +; + +value lexer_gmake () = + let kwt = Hashtbl.create 89 in + {Token.tok_func = + Token.lexer_func_of_parser + (fun s -> + let (r, (bp, ep)) = lexer kwt s in + (r, + (Reloc.shift_pos bp Reloc.zero_loc, + Reloc.shift_pos ep Reloc.zero_loc))); + Token.tok_using = lexer_using kwt; Token.tok_removing = fun []; + Token.tok_match = Token.default_match; Token.tok_text = lexer_text; + Token.tok_comm = None} +; + +(* Building AST *) + +type sexpr = + [ Sacc of Loc.t and sexpr and sexpr + | Schar of Loc.t and string + | Sexpr of Loc.t and list sexpr + | Sint of Loc.t and string + | Sfloat of Loc.t and string + | Slid of Loc.t and string + | Slist of Loc.t and list sexpr + | Sqid of Loc.t and string + | Squot of Loc.t and string and string + | Srec of Loc.t and list sexpr + | Sstring of Loc.t and string + | Stid of Loc.t and string + | Suid of Loc.t and string ] +; + +value loc_of_sexpr = + fun [ + Sacc loc _ _ | Schar loc _ | Sexpr loc _ | Sint loc _ | Sfloat loc _ | + Slid loc _ | Slist loc _ | Sqid loc _ | Squot loc _ _ | Srec loc _ | + Sstring loc _ | Stid loc _ | Suid loc _ -> + loc ] +; +value error_loc loc err = + raise_with_loc loc (Stream.Error (err ^ " expected")) +; +value error se err = error_loc (loc_of_sexpr se) err; + +value strm_n = "__strm"; +value peek_fun loc = <:expr< Stream.peek >>; +value junk_fun loc = <:expr< Stream.junk >>; + +value assoc_left_parsed_op_list = + ["+"; "*"; "+."; "*."; "land"; "lor"; "lxor"] +; +value assoc_right_parsed_op_list = ["and"; "or"; "^"; "@"]; +value and_by_couple_op_list = ["="; "<>"; "<"; ">"; "<="; ">="; "=="; "!="]; + +value op_apply loc e1 e2 = + fun + [ "and" -> <:expr< $e1$ && $e2$ >> + | "or" -> <:expr< $e1$ || $e2$ >> + | x -> <:expr< $lid:x$ $e1$ $e2$ >> ] +; + +value string_se = + fun + [ Sstring loc s -> s + | se -> error se "string" ] +; + +value mod_ident_se = + fun + [ Suid _ s -> [Pcaml.rename_id.val s] + | Slid _ s -> [Pcaml.rename_id.val s] + | se -> error se "mod_ident" ] +; + +value lident_expr loc s = + if String.length s > 1 && s.[0] = '`' then + let s = String.sub s 1 (String.length s - 1) in + <:expr< ` $s$ >> + else <:expr< $lid:(Pcaml.rename_id.val s)$ >> +; + +value rec module_expr_se = + fun + [ Sexpr loc [Slid _ "functor"; Suid _ s; se1; se2] -> + let s = Pcaml.rename_id.val s in + let mt = module_type_se se1 in + let me = module_expr_se se2 in + <:module_expr< functor ($s$ : $mt$) -> $me$ >> + | Sexpr loc [Slid _ "struct" :: sl] -> + let mel = List.map str_item_se sl in + <:module_expr< struct $list:mel$ end >> + | Sexpr loc [se1; se2] -> + let me1 = module_expr_se se1 in + let me2 = module_expr_se se2 in + <:module_expr< $me1$ $me2$ >> + | Suid loc s -> <:module_expr< $uid:(Pcaml.rename_id.val s)$ >> + | se -> error se "module expr" ] +and module_type_se = + fun + [ Sexpr loc [Slid _ "functor"; Suid _ s; se1; se2] -> + let s = Pcaml.rename_id.val s in + let mt1 = module_type_se se1 in + let mt2 = module_type_se se2 in + <:module_type< functor ($s$ : $mt1$) -> $mt2$ >> + | Sexpr loc [Slid _ "sig" :: sel] -> + let sil = List.map sig_item_se sel in + <:module_type< sig $list:sil$ end >> + | Sexpr loc [Slid _ "with"; se; Sexpr _ sel] -> + let mt = module_type_se se in + let wcl = List.map with_constr_se sel in + <:module_type< $mt$ with $list:wcl$ >> + | Suid loc s -> <:module_type< $uid:(Pcaml.rename_id.val s)$ >> + | se -> error se "module type" ] +and with_constr_se = + fun + [ Sexpr loc [Slid _ "type"; se1; se2] -> + let tn = mod_ident_se se1 in + let te = ctyp_se se2 in + MLast.WcTyp loc tn [] te + | se -> error se "with constr" ] +and sig_item_se = + fun + [ Sexpr loc [Slid _ "type" :: sel] -> + let tdl = type_declaration_list_se sel in + <:sig_item< type $list:tdl$ >> + | Sexpr loc [Slid _ "exception"; Suid _ c :: sel] -> + let c = Pcaml.rename_id.val c in + let tl = List.map ctyp_se sel in + <:sig_item< exception $c$ of $list:tl$ >> + | Sexpr loc [Slid _ "value"; Slid _ s; se] -> + let s = Pcaml.rename_id.val s in + let t = ctyp_se se in + <:sig_item< value $s$ : $t$ >> + | Sexpr loc [Slid _ "external"; Slid _ i; se :: sel] -> + let i = Pcaml.rename_id.val i in + let pd = List.map string_se sel in + let t = ctyp_se se in + <:sig_item< external $i$ : $t$ = $list:pd$ >> + | Sexpr loc [Slid _ "module"; Suid _ s; se] -> + let s = Pcaml.rename_id.val s in + let mb = module_type_se se in + <:sig_item< module $s$ : $mb$ >> + | Sexpr loc [Slid _ "moduletype"; Suid _ s; se] -> + let s = Pcaml.rename_id.val s in + let mt = module_type_se se in + <:sig_item< module type $s$ = $mt$ >> + | se -> error se "sig item" ] +and str_item_se se = + match se with + [ Sexpr loc [Slid _ "open"; se] -> + let s = mod_ident_se se in + <:str_item< open $s$ >> + | Sexpr loc [Slid _ "type" :: sel] -> + let tdl = type_declaration_list_se sel in + <:str_item< type $list:tdl$ >> + | Sexpr loc [Slid _ "exception"; Suid _ c :: sel] -> + let c = Pcaml.rename_id.val c in + let tl = List.map ctyp_se sel in + <:str_item< exception $c$ of $list:tl$ >> + | Sexpr loc [Slid _ ("define" | "definerec" as r); se :: sel] -> + let r = r = "definerec" in + let (p, e) = fun_binding_se se (begin_se loc sel) in + <:str_item< value $opt:r$ $p$ = $e$ >> + | Sexpr loc [Slid _ ("define*" | "definerec*" as r) :: sel] -> + let r = r = "definerec*" in + let lbs = List.map let_binding_se sel in + <:str_item< value $opt:r$ $list:lbs$ >> + | Sexpr loc [Slid _ "external"; Slid _ i; se :: sel] -> + let i = Pcaml.rename_id.val i in + let pd = List.map string_se sel in + let t = ctyp_se se in + <:str_item< external $i$ : $t$ = $list:pd$ >> + | Sexpr loc [Slid _ "module"; Suid _ i; se] -> + let i = Pcaml.rename_id.val i in + let mb = module_binding_se se in + <:str_item< module $i$ = $mb$ >> + | Sexpr loc [Slid _ "moduletype"; Suid _ s; se] -> + let s = Pcaml.rename_id.val s in + let mt = module_type_se se in + <:str_item< module type $s$ = $mt$ >> + | _ -> + let loc = loc_of_sexpr se in + let e = expr_se se in + <:str_item< $exp:e$ >> ] +and module_binding_se se = module_expr_se se +and expr_se = + fun + [ Sacc loc se1 se2 -> + let e1 = expr_se se1 in + match se2 with + [ Slist loc [se2] -> + let e2 = expr_se se2 in + <:expr< $e1$ .[ $e2$ ] >> + | Sexpr loc [se2] -> + let e2 = expr_se se2 in + <:expr< $e1$ .( $e2$ ) >> + | _ -> + let e2 = expr_se se2 in + <:expr< $e1$ . $e2$ >> ] + | Slid loc s -> lident_expr loc s + | Suid loc s -> <:expr< $uid:(Pcaml.rename_id.val s)$ >> + | Sint loc s -> <:expr< $int:s$ >> + | Sfloat loc s -> <:expr< $flo:s$ >> + | Schar loc s -> <:expr< $chr:s$ >> + | Sstring loc s -> <:expr< $str:s$ >> + | Stid loc s -> <:expr< ~ $(Pcaml.rename_id.val s)$ >> + | Sqid loc s -> <:expr< ? $(Pcaml.rename_id.val s)$ >> + | Sexpr loc [] -> <:expr< () >> + | Sexpr loc [Slid _ s; e1 :: ([_ :: _] as sel)] + when List.mem s assoc_left_parsed_op_list -> + let rec loop e1 = + fun + [ [] -> e1 + | [e2 :: el] -> loop (op_apply loc e1 e2 s) el ] + in + loop (expr_se e1) (List.map expr_se sel) + | Sexpr loc [Slid _ s :: ([_; _ :: _] as sel)] + when List.mem s assoc_right_parsed_op_list -> + let rec loop = + fun + [ [] -> assert False + | [e1] -> e1 + | [e1 :: el] -> + let e2 = loop el in + op_apply loc e1 e2 s ] + in + loop (List.map expr_se sel) + | Sexpr loc [Slid _ s :: ([_; _ :: _] as sel)] + when List.mem s and_by_couple_op_list -> + let rec loop = + fun + [ [] | [_] -> assert False + | [e1; e2] -> <:expr< $lid:s$ $e1$ $e2$ >> + | [e1 :: ([e2; _ :: _] as el)] -> + let a1 = op_apply loc e1 e2 s in + let a2 = loop el in + <:expr< $a1$ && $a2$ >> ] + in + loop (List.map expr_se sel) + | Sexpr loc [Stid _ s; se] -> + let e = expr_se se in + <:expr< ~ $s$ : $e$ >> + | Sexpr loc [Slid _ "-"; se] -> + let e = expr_se se in + <:expr< - $e$ >> + | Sexpr loc [Slid _ "if"; se; se1] -> + let e = expr_se se in + let e1 = expr_se se1 in + <:expr< if $e$ then $e1$ else () >> + | Sexpr loc [Slid _ "if"; se; se1; se2] -> + let e = expr_se se in + let e1 = expr_se se1 in + let e2 = expr_se se2 in + <:expr< if $e$ then $e1$ else $e2$ >> + | Sexpr loc [Slid _ "cond" :: sel] -> + let rec loop = + fun + [ [Sexpr loc [Slid _ "else" :: sel]] -> begin_se loc sel + | [Sexpr loc [se1 :: sel1] :: sel] -> + let e1 = expr_se se1 in + let e2 = begin_se loc sel1 in + let e3 = loop sel in + <:expr< if $e1$ then $e2$ else $e3$ >> + | [] -> <:expr< () >> + | [se :: _] -> error se "cond clause" ] + in + loop sel + | Sexpr loc [Slid _ "while"; se :: sel] -> + let e = expr_se se in + let el = List.map expr_se sel in + <:expr< while $e$ do { $list:el$ } >> + | Sexpr loc [Slid _ "for"; Slid _ i; se1; se2 :: sel] -> + let i = Pcaml.rename_id.val i in + let e1 = expr_se se1 in + let e2 = expr_se se2 in + let el = List.map expr_se sel in + <:expr< for $i$ = $e1$ to $e2$ do { $list:el$ } >> + | Sexpr loc [Slid loc1 "lambda"] -> <:expr< fun [] >> + | Sexpr loc [Slid loc1 "lambda"; sep :: sel] -> + let e = begin_se loc1 sel in + match ipatt_opt_se sep with + [ Left p -> <:expr< fun $p$ -> $e$ >> + | Right (se, sel) -> + List.fold_right + (fun se e -> + let p = ipatt_se se in + <:expr< fun $p$ -> $e$ >>) + [se :: sel] e ] + | Sexpr loc [Slid _ "lambda_match" :: sel] -> + let pel = List.map (match_case loc) sel in + <:expr< fun [ $list:pel$ ] >> + | Sexpr loc [Slid _ ("let" | "letrec" as r) :: sel] -> + match sel with + [ [Sexpr _ sel1 :: sel2] -> + let r = r = "letrec" in + let lbs = List.map let_binding_se sel1 in + let e = begin_se loc sel2 in + <:expr< let $opt:r$ $list:lbs$ in $e$ >> + | [Slid _ n; Sexpr _ sl :: sel] -> + let n = Pcaml.rename_id.val n in + let (pl, el) = + List.fold_right + (fun se (pl, el) -> + match se with + [ Sexpr _ [se1; se2] -> + ([patt_se se1 :: pl], [expr_se se2 :: el]) + | se -> error se "named let" ]) + sl ([], []) + in + let e1 = + List.fold_right (fun p e -> <:expr< fun $p$ -> $e$ >>) pl + (begin_se loc sel) + in + let e2 = + List.fold_left (fun e1 e2 -> <:expr< $e1$ $e2$ >>) + <:expr< $lid:n$ >> el + in + <:expr< let rec $lid:n$ = $e1$ in $e2$ >> + | [se :: _] -> error se "let_binding" + | _ -> error_loc loc "let_binding" ] + | Sexpr loc [Slid _ "let*" :: sel] -> + match sel with + [ [Sexpr _ sel1 :: sel2] -> + List.fold_right + (fun se ek -> + let (p, e) = let_binding_se se in + <:expr< let $p$ = $e$ in $ek$ >>) + sel1 (begin_se loc sel2) + | [se :: _] -> error se "let_binding" + | _ -> error_loc loc "let_binding" ] + | Sexpr loc [Slid _ "match"; se :: sel] -> + let e = expr_se se in + let pel = List.map (match_case loc) sel in + <:expr< match $e$ with [ $list:pel$ ] >> + | Sexpr loc [Slid _ "parser" :: sel] -> + let e = + match sel with + [ [(Slid _ _ as se) :: sel] -> + let p = patt_se se in + let pc = parser_cases_se loc sel in + <:expr< let $p$ = Stream.count $lid:strm_n$ in $pc$ >> + | _ -> parser_cases_se loc sel ] + in + <:expr< fun ($lid:strm_n$ : Stream.t _) -> $e$ >> + | Sexpr loc [Slid _ "match_with_parser"; se :: sel] -> + let me = expr_se se in + let (bpo, sel) = + match sel with + [ [(Slid _ _ as se) :: sel] -> (Some (patt_se se), sel) + | _ -> (None, sel) ] + in + let pc = parser_cases_se loc sel in + let e = + match bpo with + [ Some bp -> <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >> + | None -> pc ] + in + match me with + [ <:expr< $lid:x$ >> when x = strm_n -> e + | _ -> <:expr< let ($lid:strm_n$ : Stream.t _) = $me$ in $e$ >> ] + | Sexpr loc [Slid _ "try"; se :: sel] -> + let e = expr_se se in + let pel = List.map (match_case loc) sel in + <:expr< try $e$ with [ $list:pel$ ] >> + | Sexpr loc [Slid _ "begin" :: sel] -> + let el = List.map expr_se sel in + <:expr< do { $list:el$ } >> + | Sexpr loc [Slid _ ":="; se1; se2] -> + let e1 = expr_se se1 in + let e2 = expr_se se2 in + <:expr< $e1$ := $e2$ >> + | Sexpr loc [Slid _ "values" :: sel] -> + let el = List.map expr_se sel in + <:expr< ( $list:el$ ) >> + | Srec loc [Slid _ "with"; se :: sel] -> + let e = expr_se se in + let lel = List.map (label_expr_se loc) sel in + <:expr< { ($e$) with $list:lel$ } >> + | Srec loc sel -> + let lel = List.map (label_expr_se loc) sel in + <:expr< { $list:lel$ } >> + | Sexpr loc [Slid _ ":"; se1; se2] -> + let e = expr_se se1 in + let t = ctyp_se se2 in + <:expr< ( $e$ : $t$ ) >> + | Sexpr loc [se] -> + let e = expr_se se in + <:expr< $e$ () >> + | Sexpr loc [Slid _ "assert"; Suid _ "False"] -> <:expr< assert False >> + | Sexpr loc [Slid _ "assert"; se] -> + let e = expr_se se in + <:expr< assert $e$ >> + | Sexpr loc [Slid _ "lazy"; se] -> + let e = expr_se se in + <:expr< lazy $e$ >> + | Sexpr loc [se :: sel] -> + List.fold_left + (fun e se -> + let e1 = expr_se se in + <:expr< $e$ $e1$ >>) + (expr_se se) sel + | Slist loc sel -> + let rec loop = + fun + [ [] -> <:expr< [] >> + | [se1; Slid _ "."; se2] -> + let e = expr_se se1 in + let el = expr_se se2 in + <:expr< [$e$ :: $el$] >> + | [se :: sel] -> + let e = expr_se se in + let el = loop sel in + <:expr< [$e$ :: $el$] >> ] + in + loop sel + | Squot loc typ txt -> Pcaml.handle_expr_quotation loc (typ, txt) ] +and begin_se loc = + fun + [ [] -> <:expr< () >> + | [se] -> expr_se se + | sel -> + let el = List.map expr_se sel in + let loc = (fst (loc_of_sexpr (List.hd sel)), snd loc) in + <:expr< do { $list:el$ } >> ] +and let_binding_se = + fun + [ Sexpr loc [se :: sel] -> + let e = begin_se loc sel in + match ipatt_opt_se se with + [ Left p -> (p, e) + | Right _ -> fun_binding_se se e ] + | se -> error se "let_binding" ] +and fun_binding_se se e = + match se with + [ Sexpr _ [Slid _ "values" :: _] -> (ipatt_se se, e) + | Sexpr _ [Slid loc s :: sel] -> + let s = Pcaml.rename_id.val s in + let e = + List.fold_right + (fun se e -> + let loc = (fst (loc_of_sexpr se), snd (MLast.loc_of_expr e)) in + let p = ipatt_se se in + <:expr< fun $p$ -> $e$ >>) + sel e + in + let p = <:patt< $lid:s$ >> in + (p, e) + | _ -> (ipatt_se se, e) ] +and match_case loc = + fun + [ Sexpr loc [Sexpr _ [Slid _ "when"; se; sew] :: sel] -> + (patt_se se, Some (expr_se sew), begin_se loc sel) + | Sexpr loc [se :: sel] -> (patt_se se, None, begin_se loc sel) + | se -> error se "match_case" ] +and label_expr_se loc = + fun + [ Sexpr _ [se1; se2] -> (patt_se se1, expr_se se2) + | se -> error se "label_expr" ] +and label_patt_se loc = + fun + [ Sexpr _ [se1; se2] -> (patt_se se1, patt_se se2) + | se -> error se "label_patt" ] +and parser_cases_se loc = + fun + [ [] -> <:expr< raise Stream.Failure >> + | [Sexpr loc [Sexpr _ spsel :: act] :: sel] -> + let ekont _ = parser_cases_se loc sel in + let act = + match act with + [ [se] -> expr_se se + | [sep; se] -> + let p = patt_se sep in + let e = expr_se se in + <:expr< let $p$ = Stream.count $lid:strm_n$ in $e$ >> + | _ -> error_loc loc "parser_case" ] + in + stream_pattern_se loc act ekont spsel + | [se :: _] -> error se "parser_case" ] +and stream_pattern_se loc act ekont = + fun + [ [] -> act + | [se :: sel] -> + let ckont err = <:expr< raise (Stream.Error $err$) >> in + let skont = stream_pattern_se loc act ckont sel in + stream_pattern_component skont ekont <:expr< "" >> se ] +and stream_pattern_component skont ekont err = + fun + [ Sexpr loc [Slid _ "`"; se :: wol] -> + let wo = + match wol with + [ [se] -> Some (expr_se se) + | [] -> None + | _ -> error_loc loc "stream_pattern_component" ] + in + let e = peek_fun loc in + let p = patt_se se in + let j = junk_fun loc in + let k = ekont err in + <:expr< match $e$ $lid:strm_n$ with + [ Some $p$ $when:wo$ -> do { $j$ $lid:strm_n$ ; $skont$ } + | _ -> $k$ ] >> + | Sexpr loc [se1; se2] -> + let p = patt_se se1 in + let e = + let e = expr_se se2 in + <:expr< try Some ($e$ $lid:strm_n$) with [ Stream.Failure -> None ] >> + in + let k = ekont err in + <:expr< match $e$ with [ Some $p$ -> $skont$ | _ -> $k$ ] >> + | Sexpr loc [Slid _ "?"; se1; se2] -> + stream_pattern_component skont ekont (expr_se se2) se1 + | Slid loc s -> + let s = Pcaml.rename_id.val s in + <:expr< let $lid:s$ = $lid:strm_n$ in $skont$ >> + | se -> error se "stream_pattern_component" ] +and patt_se = + fun + [ Sacc loc se1 se2 -> + let p1 = patt_se se1 in + let p2 = patt_se se2 in + <:patt< $p1$ . $p2$ >> + | Slid loc "_" -> <:patt< _ >> + | Slid loc s -> <:patt< $lid:(Pcaml.rename_id.val s)$ >> + | Suid loc s -> <:patt< $uid:(Pcaml.rename_id.val s)$ >> + | Sint loc s -> <:patt< $int:s$ >> + | Sfloat loc s -> <:patt< $flo:s$ >> + | Schar loc s -> <:patt< $chr:s$ >> + | Sstring loc s -> <:patt< $str:s$ >> + | Stid loc _ -> error_loc loc "patt" + | Sqid loc _ -> error_loc loc "patt" + | Srec loc sel -> + let lpl = List.map (label_patt_se loc) sel in + <:patt< { $list:lpl$ } >> + | Sexpr loc [Slid _ ":"; se1; se2] -> + let p = patt_se se1 in + let t = ctyp_se se2 in + <:patt< ($p$ : $t$) >> + | Sexpr loc [Slid _ "or"; se :: sel] -> + List.fold_left + (fun p se -> + let p1 = patt_se se in + <:patt< $p$ | $p1$ >>) + (patt_se se) sel + | Sexpr loc [Slid _ "range"; se1; se2] -> + let p1 = patt_se se1 in + let p2 = patt_se se2 in + <:patt< $p1$ .. $p2$ >> + | Sexpr loc [Slid _ "values" :: sel] -> + let pl = List.map patt_se sel in + <:patt< ( $list:pl$ ) >> + | Sexpr loc [Slid _ "as"; se1; se2] -> + let p1 = patt_se se1 in + let p2 = patt_se se2 in + <:patt< ($p1$ as $p2$) >> + | Sexpr loc [se :: sel] -> + List.fold_left + (fun p se -> + let p1 = patt_se se in + <:patt< $p$ $p1$ >>) + (patt_se se) sel + | Sexpr loc [] -> <:patt< () >> + | Slist loc sel -> + let rec loop = + fun + [ [] -> <:patt< [] >> + | [se1; Slid _ "."; se2] -> + let p = patt_se se1 in + let pl = patt_se se2 in + <:patt< [$p$ :: $pl$] >> + | [se :: sel] -> + let p = patt_se se in + let pl = loop sel in + <:patt< [$p$ :: $pl$] >> ] + in + loop sel + | Squot loc typ txt -> Pcaml.handle_patt_quotation loc (typ, txt) ] +and ipatt_se se = + match ipatt_opt_se se with + [ Left p -> p + | Right (se, _) -> error se "ipatt" ] +and ipatt_opt_se = + fun + [ Slid loc "_" -> Left <:patt< _ >> + | Slid loc s -> Left <:patt< $lid:(Pcaml.rename_id.val s)$ >> + | Stid loc s -> Left <:patt< ~ $(Pcaml.rename_id.val s)$ >> + | Sqid loc s -> Left <:patt< ? $(Pcaml.rename_id.val s)$ >> + | Sexpr loc [Sqid _ s; se] -> + let s = Pcaml.rename_id.val s in + let e = expr_se se in + Left <:patt< ? ( $lid:s$ = $e$ ) >> + | Sexpr loc [Slid _ ":"; se1; se2] -> + let p = ipatt_se se1 in + let t = ctyp_se se2 in + Left <:patt< ($p$ : $t$) >> + | Sexpr loc [Slid _ "values" :: sel] -> + let pl = List.map ipatt_se sel in + Left <:patt< ( $list:pl$ ) >> + | Sexpr loc [] -> Left <:patt< () >> + | Sexpr loc [se :: sel] -> Right (se, sel) + | se -> error se "ipatt" ] +and type_declaration_list_se = + fun + [ [se1; se2 :: sel] -> + let (n1, loc1, tpl) = + match se1 with + [ Sexpr _ [Slid loc n :: sel] -> + (n, loc, List.map type_parameter_se sel) + | Slid loc n -> (n, loc, []) + | se -> error se "type declaration" ] + in + [((loc1, Pcaml.rename_id.val n1), tpl, ctyp_se se2, []) :: + type_declaration_list_se sel] + | [] -> [] + | [se :: _] -> error se "type_declaration" ] +and type_parameter_se = + fun + [ Slid _ s when String.length s >= 2 && s.[0] = ''' -> + (String.sub s 1 (String.length s - 1), (False, False)) + | se -> error se "type_parameter" ] +and ctyp_se = + fun + [ Sexpr loc [Slid _ "sum" :: sel] -> + let cdl = List.map constructor_declaration_se sel in + <:ctyp< [ $list:cdl$ ] >> + | Srec loc sel -> + let ldl = List.map label_declaration_se sel in + <:ctyp< { $list:ldl$ } >> + | Sexpr loc [Slid _ "->" :: ([_; _ :: _] as sel)] -> + let rec loop = + fun + [ [] -> assert False + | [se] -> ctyp_se se + | [se :: sel] -> + let t1 = ctyp_se se in + let loc = (fst (loc_of_sexpr se), snd loc) in + let t2 = loop sel in + <:ctyp< $t1$ -> $t2$ >> ] + in + loop sel + | Sexpr loc [Slid _ "*" :: sel] -> + let tl = List.map ctyp_se sel in + <:ctyp< ($list:tl$) >> + | Sexpr loc [se :: sel] -> + List.fold_left + (fun t se -> + let t2 = ctyp_se se in + <:ctyp< $t$ $t2$ >>) + (ctyp_se se) sel + | Sacc loc se1 se2 -> + let t1 = ctyp_se se1 in + let t2 = ctyp_se se2 in + <:ctyp< $t1$ . $t2$ >> + | Slid loc "_" -> <:ctyp< _ >> + | Slid loc s -> + if s.[0] = ''' then + let s = String.sub s 1 (String.length s - 1) in + <:ctyp< '$s$ >> + else <:ctyp< $lid:(Pcaml.rename_id.val s)$ >> + | Suid loc s -> <:ctyp< $uid:(Pcaml.rename_id.val s)$ >> + | se -> error se "ctyp" ] +and constructor_declaration_se = + fun + [ Sexpr loc [Suid _ ci :: sel] -> + (loc, Pcaml.rename_id.val ci, List.map ctyp_se sel) + | se -> error se "constructor_declaration" ] +and label_declaration_se = + fun + [ Sexpr loc [Slid _ lab; Slid _ "mutable"; se] -> + (loc, Pcaml.rename_id.val lab, True, ctyp_se se) + | Sexpr loc [Slid _ lab; se] -> + (loc, Pcaml.rename_id.val lab, False, ctyp_se se) + | se -> error se "label_declaration" ] +; + +value directive_se = + fun + [ Sexpr _ [Slid _ s] -> (s, None) + | Sexpr _ [Slid _ s; se] -> + let e = expr_se se in + (s, Some e) + | se -> error se "directive" ] +; + +(* Parser *) + +Pcaml.syntax_name.val := "Scheme"; +Pcaml.no_constructors_arity.val := False; + +do { + Grammar.Unsafe.gram_reinit gram (lexer_gmake ()); + Grammar.Unsafe.clear_entry interf; + Grammar.Unsafe.clear_entry implem; + Grammar.Unsafe.clear_entry top_phrase; + Grammar.Unsafe.clear_entry use_file; + Grammar.Unsafe.clear_entry module_type; + Grammar.Unsafe.clear_entry module_expr; + Grammar.Unsafe.clear_entry sig_item; + Grammar.Unsafe.clear_entry str_item; + Grammar.Unsafe.clear_entry expr; + Grammar.Unsafe.clear_entry patt; + Grammar.Unsafe.clear_entry ctyp; + Grammar.Unsafe.clear_entry let_binding; + Grammar.Unsafe.clear_entry type_declaration; + Grammar.Unsafe.clear_entry class_type; + Grammar.Unsafe.clear_entry class_expr; + Grammar.Unsafe.clear_entry class_sig_item; + Grammar.Unsafe.clear_entry class_str_item +}; + +Pcaml.parse_interf.val := Grammar.Entry.parse interf; +Pcaml.parse_implem.val := Grammar.Entry.parse implem; + +value sexpr = Grammar.Entry.create gram "sexpr"; + +value rec leftify = + fun + [ Sacc loc1 se1 se2 -> + match leftify se2 with + [ Sacc loc2 se2 se3 -> Sacc loc1 (Sacc loc2 se1 se2) se3 + | se2 -> Sacc loc1 se1 se2 ] + | x -> x ] +; + +EXTEND + GLOBAL: implem interf top_phrase use_file str_item sig_item expr patt sexpr; + implem: + [ [ "#"; se = sexpr -> + let (n, dp) = directive_se se in + ([(<:str_item< # $n$ $opt:dp$ >>, loc)], True) + | si = str_item; x = SELF -> + let (sil, stopped) = x in + let loc = MLast.loc_of_str_item si in + ([(si, loc) :: sil], stopped) + | EOI -> ([], False) ] ] + ; + interf: + [ [ "#"; se = sexpr -> + let (n, dp) = directive_se se in + ([(<:sig_item< # $n$ $opt:dp$ >>, loc)], True) + | si = sig_item; x = SELF -> + let (sil, stopped) = x in + let loc = MLast.loc_of_sig_item si in + ([(si, loc) :: sil], stopped) + | EOI -> ([], False) ] ] + ; + top_phrase: + [ [ "#"; se = sexpr -> + let (n, dp) = directive_se se in + Some <:str_item< # $n$ $opt:dp$ >> + | se = sexpr -> Some (str_item_se se) + | EOI -> None ] ] + ; + use_file: + [ [ "#"; se = sexpr -> + let (n, dp) = directive_se se in + ([<:str_item< # $n$ $opt:dp$ >>], True) + | si = str_item; x = SELF -> + let (sil, stopped) = x in + ([si :: sil], stopped) + | EOI -> ([], False) ] ] + ; + str_item: + [ [ se = sexpr -> str_item_se se + | e = expr -> <:str_item< $exp:e$ >> ] ] + ; + sig_item: + [ [ se = sexpr -> sig_item_se se ] ] + ; + expr: + [ "top" + [ se = sexpr -> expr_se se ] ] + ; + patt: + [ [ se = sexpr -> patt_se se ] ] + ; + sexpr: + [ [ se1 = sexpr_dot; se2 = SELF -> leftify (Sacc loc se1 se2) ] + | [ "("; sl = LIST0 sexpr; ")" -> Sexpr loc sl + | "("; sl = LIST0 sexpr; ")."; se = SELF -> + leftify (Sacc loc (Sexpr loc sl) se) + | "["; sl = LIST0 sexpr; "]" -> Slist loc sl + | "{"; sl = LIST0 sexpr; "}" -> Srec loc sl + | a = pa_extend_keyword -> Slid loc a + | s = LIDENT -> Slid loc s + | s = UIDENT -> Suid loc s + | s = TILDEIDENT -> Stid loc s + | s = QUESTIONIDENT -> Sqid loc s + | s = INT -> Sint loc s + | s = FLOAT -> Sfloat loc s + | s = CHAR -> Schar loc s + | s = STRING -> Sstring loc s + | s = QUOT -> + let i = String.index s ':' in + let typ = String.sub s 0 i in + let txt = String.sub s (i + 1) (String.length s - i - 1) in + Squot loc typ txt ] ] + ; + sexpr_dot: + [ [ s = LIDENTDOT -> Slid loc s + | s = UIDENTDOT -> Suid loc s ] ] + ; + pa_extend_keyword: + [ [ "_" -> "_" + | "," -> "," + | "=" -> "=" + | ":" -> ":" + | "." -> "." + | "/" -> "/" ] ] + ; +END; diff --git a/camlp4/unmaintained/scheme/pa_scheme.sc b/camlp4/unmaintained/scheme/pa_scheme.sc new file mode 100644 index 0000000..cc6de18 --- /dev/null +++ b/camlp4/unmaintained/scheme/pa_scheme.sc @@ -0,0 +1,1029 @@ +; pa_r.cmo pa_rp.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo +; ********************************************************************** +; +; Camlp4 +; +; Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt +; +; Copyright 2002 Institut National de Recherche en Informatique et +; en Automatique. All rights reserved. This file is distributed +; under the terms of the GNU Library General Public License, with +; the special exception on linking described in file +; ../../../LICENSE. +; +; ********************************************************************** + +(open Pcaml) +(open Stdpp) + +(type (choice 'a 'b) (sum (Left 'a) (Right 'b))) + +; Buffer + +(module Buff + (struct + (define buff (ref (String.create 80))) + (define (store len x) + (if (>= len (String.length buff.val)) + (:= buff.val (^ buff.val (String.create (String.length buff.val))))) + (:= buff.val.[len] x) + (succ len)) + (define (get len) (String.sub buff.val 0 len)))) + +; Lexer + +(definerec skip_to_eol + (parser + (((` (or '\n' '\r'))) ()) + (((` _) s) (skip_to_eol s)))) + +(define no_ident ['(' ')' '[' ']' '{' '}' ' ' '\t' '\n' '\r' ';']) + +(definerec (ident len) + (parser + (((` '.')) (values (Buff.get len) True)) + (((` x (not (List.mem x no_ident))) s) (ident (Buff.store len x) s)) + (() (values (Buff.get len) False)))) + +(define (identifier kwt (values s dot)) + (let ((con + (try (begin (: (Hashtbl.find kwt s) unit) "") + (Not_found + (match s.[0] + ((range 'A' 'Z') (if dot "UIDENTDOT" "UIDENT")) + (_ (if dot "LIDENTDOT" "LIDENT"))))))) + (values con s))) + +(definerec (string len) + (parser + (((` '"')) (Buff.get len)) + (((` '\\') (` c) s) (string (Buff.store (Buff.store len '\\') c) s)) + (((` x) s) (string (Buff.store len x) s)))) + +(definerec (end_exponent_part_under len) + (parser + (((` (as (range '0' '9') c)) s) + (end_exponent_part_under (Buff.store len c) s)) + (() (values "FLOAT" (Buff.get len))))) + +(define (end_exponent_part len) + (parser + (((` (as (range '0' '9') c)) s) + (end_exponent_part_under (Buff.store len c) s)) + (() (raise (Stream.Error "ill-formed floating-point constant"))))) + +(define (exponent_part len) + (parser + (((` (as (or '+' '-') c)) s) (end_exponent_part (Buff.store len c) s)) + (((a (end_exponent_part len))) a))) + +(definerec (decimal_part len) + (parser + (((` (as (range '0' '9') c)) s) (decimal_part (Buff.store len c) s)) + (((` (or 'e' 'E')) s) (exponent_part (Buff.store len 'E') s)) + (() (values "FLOAT" (Buff.get len))))) + +(definerec (number len) + (parser + (((` (as (range '0' '9') c)) s) (number (Buff.store len c) s)) + (((` '.') s) (decimal_part (Buff.store len '.') s)) + (((` (or 'e' 'E')) s) (exponent_part (Buff.store len 'E') s)) + (() (values "INT" (Buff.get len))))) + +(define binary + (parser + (((` (as (range '0' '1') c))) c))) + +(define octal + (parser + (((` (as (range '0' '7') c))) c))) + +(define hexa + (parser + (((` (as (or (range '0' '9') (range 'a' 'f') (range 'A' 'F')) c))) c))) + +(definerec (digits_under kind len) + (parser + (((d kind) s) (digits_under kind (Buff.store len d) s)) + (() (Buff.get len)))) + +(define (digits kind bp len) + (parser + (((d kind) s) (values "INT" (digits_under kind (Buff.store len d) s))) + ((s) ep + (raise_with_loc (values + (Reloc.shift_pos bp Reloc.zero_loc) + (Reloc.shift_pos ep Reloc.zero_loc)) + (Failure "ill-formed integer constant"))))) + +(define (base_number kwt bp len) + (parser + (((` (or 'b' 'B')) s) (digits binary bp (Buff.store len 'b') s)) + (((` (or 'o' 'O')) s) (digits octal bp (Buff.store len 'o') s)) + (((` (or 'x' 'X')) s) (digits hexa bp (Buff.store len 'x') s)) + (((id (ident (Buff.store 0 '#')))) (identifier kwt id)))) + +(definerec (operator len) + (parser + (((` '.')) (Buff.get (Buff.store len '.'))) + (() (Buff.get len)))) + +(define (char_or_quote_id x) + (parser + (((` ''')) (values "CHAR" (String.make 1 x))) + ((s) ep + (if (List.mem x no_ident) + (Stdpp.raise_with_loc (values + (Reloc.shift_pos (- ep 2) Reloc.zero_loc) + (Reloc.shift_pos (- ep 1) Reloc.zero_loc)) + (Stream.Error "bad quote")) + (let* ((len (Buff.store (Buff.store 0 ''') x)) + ((values s dot) (ident len s))) + (values (if dot "LIDENTDOT" "LIDENT") s)))))) + +(definerec (char len) + (parser + (((` ''')) len) + (((` x) s) (char (Buff.store len x) s)))) + +(define quote + (parser + (((` '\\') (len (char (Buff.store 0 '\\')))) + (values "CHAR" (Buff.get len))) + (((` x) s) (char_or_quote_id x s)))) + +; The system with LIDENTDOT and UIDENTDOT is not great (it would be +; better to have a token DOT (actually SPACEDOT and DOT)) but it is +; the only way (that I have found) to have a good behaviour in the +; toplevel (not expecting tokens after a phrase). Drawbacks: 1/ to be +; complete, we should have STRINGDOT, RIGHTPARENDOT, and so on 2/ the +; parser rule with dot is right associative and we have to reverse +; the resulting tree (using the function leftify). +; This is a complicated issue: the behaviour of the OCaml toplevel +; is strange, anyway. For example, even without Camlp4, The OCaml +; toplevel accepts that: +; # let x = 32;; foo bar match let ) + +(definerec* + ((lexer kwt) + (parser + (((t (lexer0 kwt)) + (_ no_dot)) t))) + (no_dot + (parser + (((` '.')) ep + (Stdpp.raise_with_loc (values + (Reloc.shift_pos (- ep 1) Reloc.zero_loc) + (Reloc.shift_pos ep Reloc.zero_loc)) + (Stream.Error "bad dot"))) + (() ()))) + ((lexer0 kwt) + (parser bp + (((` (or '\t' '\n' '\r')) s) (lexer0 kwt s)) + (((` ' ') s) (after_space kwt s)) + (((` ';') (_ skip_to_eol) s) (lexer kwt s)) + (((` '(')) (values (values "" "(") (values bp (+ bp 1)))) + (((` ')') s) ep (values (values "" (rparen s)) (values bp ep))) + (((` '[')) (values (values "" "[") (values bp (+ bp 1)))) + (((` ']')) (values (values "" "]") (values bp (+ bp 1)))) + (((` '{')) (values (values "" "{") (values bp (+ bp 1)))) + (((` '}')) (values (values "" "}") (values bp (+ bp 1)))) + (((` '"') (s (string 0))) ep + (values (values "STRING" s) (values bp ep))) + (((` ''') (tok quote)) ep (values tok (values bp ep))) + (((` '<') (tok (less kwt))) ep (values tok (values bp ep))) + (((` '-') (tok (minus kwt))) ep (values tok (values bp ep))) + (((` '~') (tok tilde)) ep (values tok (values bp ep))) + (((` '?') (tok question)) ep (values tok (values bp ep))) + (((` '#') (tok (base_number kwt bp (Buff.store 0 '0')))) ep + (values tok (values bp ep))) + (((` (as (range '0' '9') c)) (tok (number (Buff.store 0 c)))) ep + (values tok (values bp ep))) + (((` (as (or '+' '*' '/') c)) (id (operator (Buff.store 0 c)))) ep + (values (identifier kwt (values id False)) (values bp ep))) + (((` x) (id (ident (Buff.store 0 x)))) ep + (values (identifier kwt id) (values bp ep))) + (() (values (values "EOI" "") (values bp (+ bp 1)))))) + (rparen + (parser + (((` '.')) ").") + ((_) ")"))) + ((after_space kwt) + (parser + (((` '.')) ep (values (values "" ".") (values (- ep 1) ep))) + (((x (lexer0 kwt))) x))) + (tilde + (parser + (((` (as (range 'a' 'z') c)) ((values s dot) (ident (Buff.store 0 c)))) + (values "TILDEIDENT" s)) + (() (values "LIDENT" "~")))) + (question + (parser + (((` (as (range 'a' 'z') c)) ((values s dot) (ident (Buff.store 0 c)))) + (values "QUESTIONIDENT" s)) + (() (values "LIDENT" "?")))) + ((minus kwt) + (parser + (((` '.')) (identifier kwt (values "-." False))) + (((` (as (range '0' '9') c)) + (n (number (Buff.store (Buff.store 0 '-') c)))) ep n) + (((id (ident (Buff.store 0 '-')))) (identifier kwt id)))) + ((less kwt) + (parser + (((` ':') (lab (label 0)) (? (` '<') "'<' expected") (q (quotation 0))) + (values "QUOT" (^ lab ":" q))) + (((id (ident (Buff.store 0 '<')))) (identifier kwt id)))) + ((label len) + (parser + (((` (as (or (range 'a' 'z') (range 'A' 'Z') '_') c)) s) + (label (Buff.store len c) s)) + (() (Buff.get len)))) + ((quotation len) + (parser + (((` '>') s) (quotation_greater len s)) + (((` x) s) (quotation (Buff.store len x) s)) + (() (failwith "quotation not terminated")))) + ((quotation_greater len) + (parser + (((` '>')) (Buff.get len)) + (((a (quotation (Buff.store len '>')))) a)))) + +(define (lexer_using kwt (values con prm)) + (match con + ((or "CHAR" "EOI" "INT" "FLOAT" "LIDENT" "LIDENTDOT" "QUESTIONIDENT" + "QUOT" "STRING" "TILDEIDENT" "UIDENT" "UIDENTDOT") + ()) + ("ANTIQUOT" ()) + ("" (try (Hashtbl.find kwt prm) (Not_found (Hashtbl.add kwt prm ())))) + (_ + (raise + (Token.Error + (^ "the constructor \"" con "\" is not recognized by Plexer")))))) + +(define (lexer_text (values con prm)) + (cond + ((= con "") (^ "'"prm "'")) + ((= prm "") con) + (else (^ con " \"" prm "\"")))) + +(define (lexer_gmake ()) + (let ((kwt (Hashtbl.create 89))) + {(Token.tok_func + (Token.lexer_func_of_parser + (lambda (s) + (let (((values r (values bp ep)) (lexer kwt s))) + (values r (values (Reloc.shift_pos bp Reloc.zero_loc) + (Reloc.shift_pos ep Reloc.zero_loc))))))) + (Token.tok_using (lexer_using kwt)) + (Token.tok_removing (lambda)) + (Token.tok_match Token.default_match) + (Token.tok_text lexer_text) + (Token.tok_comm None)})) + +; Building AST + +(type sexpr + (sum + (Sacc MLast.loc sexpr sexpr) + (Schar MLast.loc string) + (Sexpr MLast.loc (list sexpr)) + (Sint MLast.loc string) + (Sfloat MLast.loc string) + (Slid MLast.loc string) + (Slist MLast.loc (list sexpr)) + (Sqid MLast.loc string) + (Squot MLast.loc string string) + (Srec MLast.loc (list sexpr)) + (Sstring MLast.loc string) + (Stid MLast.loc string) + (Suid MLast.loc string))) + +(define loc_of_sexpr + (lambda_match + ((or (Sacc loc _ _) (Schar loc _) (Sexpr loc _) (Sint loc _) + (Sfloat loc _) (Slid loc _) (Slist loc _) (Sqid loc _) (Squot loc _ _) + (Srec loc _) (Sstring loc _) (Stid loc _) (Suid loc _)) + loc))) +(define (error_loc loc err) + (raise_with_loc loc (Stream.Error (^ err " expected")))) +(define (error se err) (error_loc (loc_of_sexpr se) err)) + +(define strm_n "strm__") +(define (peek_fun loc) <:expr< Stream.peek >>) +(define (junk_fun loc) <:expr< Stream.junk >>) + +(define assoc_left_parsed_op_list ["+" "*" "+." "*." "land" "lor" "lxor"]) +(define assoc_right_parsed_op_list ["and" "or" "^" "@"]) +(define and_by_couple_op_list ["=" "<>" "<" ">" "<=" ">=" "==" "!="]) + +(define (op_apply loc e1 e2) + (lambda_match + ("and" <:expr< $e1$ && $e2$ >>) + ("or" <:expr< $e1$ || $e2$ >>) + (x <:expr< $lid:x$ $e1$ $e2$ >>))) + +(define string_se + (lambda_match + ((Sstring loc s) s) + (se (error se "string")))) + +(define mod_ident_se + (lambda_match + ((Suid _ s) [(Pcaml.rename_id.val s)]) + ((Slid _ s) [(Pcaml.rename_id.val s)]) + (se (error se "mod_ident")))) + +(define (lident_expr loc s) + (if (&& (> (String.length s) 1) (= s.[0] '`')) + (let ((s (String.sub s 1 (- (String.length s) 1)))) + <:expr< ` $s$ >>) + <:expr< $lid:(Pcaml.rename_id.val s)$ >>)) + +(definerec* + (module_expr_se + (lambda_match + ((Sexpr loc [(Slid _ "functor") (Suid _ s) se1 se2]) + (let* ((s (Pcaml.rename_id.val s)) + (mt (module_type_se se1)) + (me (module_expr_se se2))) + <:module_expr< functor ($s$ : $mt$) -> $me$ >>)) + ((Sexpr loc [(Slid _ "struct") . sl]) + (let ((mel (List.map str_item_se sl))) + <:module_expr< struct $list:mel$ end >>)) + ((Sexpr loc [se1 se2]) + (let* ((me1 (module_expr_se se1)) + (me2 (module_expr_se se2))) + <:module_expr< $me1$ $me2$ >>)) + ((Suid loc s) <:module_expr< $uid:(Pcaml.rename_id.val s)$ >>) + (se (error se "module expr")))) + (module_type_se + (lambda_match + ((Sexpr loc [(Slid _ "functor") (Suid _ s) se1 se2]) + (let* ((s (Pcaml.rename_id.val s)) + (mt1 (module_type_se se1)) + (mt2 (module_type_se se2))) + <:module_type< functor ($s$ : $mt1$) -> $mt2$ >>)) + ((Sexpr loc [(Slid _ "sig") . sel]) + (let ((sil (List.map sig_item_se sel))) + <:module_type< sig $list:sil$ end >>)) + ((Sexpr loc [(Slid _ "with") se (Sexpr _ sel)]) + (let* ((mt (module_type_se se)) + (wcl (List.map with_constr_se sel))) + <:module_type< $mt$ with $list:wcl$ >>)) + ((Suid loc s) <:module_type< $uid:(Pcaml.rename_id.val s)$ >>) + (se (error se "module type")))) + (with_constr_se + (lambda_match + ((Sexpr loc [(Slid _ "type") se1 se2]) + (let* ((tn (mod_ident_se se1)) + (te (ctyp_se se2))) + (MLast.WcTyp loc tn [] te))) + (se (error se "with constr")))) + (sig_item_se + (lambda_match + ((Sexpr loc [(Slid _ "type") . sel]) + (let ((tdl (type_declaration_list_se sel))) + <:sig_item< type $list:tdl$ >>)) + ((Sexpr loc [(Slid _ "exception") (Suid _ c) . sel]) + (let* ((c (Pcaml.rename_id.val c)) + (tl (List.map ctyp_se sel))) + <:sig_item< exception $c$ of $list:tl$ >>)) + ((Sexpr loc [(Slid _ "value") (Slid _ s) se]) + (let* ((s (Pcaml.rename_id.val s)) + (t (ctyp_se se))) + <:sig_item< value $s$ : $t$ >>)) + ((Sexpr loc [(Slid _ "external") (Slid _ i) se . sel]) + (let* ((i (Pcaml.rename_id.val i)) + (pd (List.map string_se sel)) + (t (ctyp_se se))) + <:sig_item< external $i$ : $t$ = $list:pd$ >>)) + ((Sexpr loc [(Slid _ "module") (Suid _ s) se]) + (let* ((s (Pcaml.rename_id.val s)) + (mb (module_type_se se))) + <:sig_item< module $s$ : $mb$ >>)) + ((Sexpr loc [(Slid _ "moduletype") (Suid _ s) se]) + (let* ((s (Pcaml.rename_id.val s)) + (mt (module_type_se se))) + <:sig_item< module type $s$ = $mt$ >>)) + (se (error se "sig item")))) + ((str_item_se se) + (match se + ((Sexpr loc [(Slid _ "open") se]) + (let ((s (mod_ident_se se))) <:str_item< open $s$ >>)) + ((Sexpr loc [(Slid _ "type") . sel]) + (let ((tdl (type_declaration_list_se sel))) + <:str_item< type $list:tdl$ >>)) + ((Sexpr loc [(Slid _ "exception") (Suid _ c) . sel]) + (let* ((c (Pcaml.rename_id.val c)) + (tl (List.map ctyp_se sel))) + <:str_item< exception $c$ of $list:tl$ >>)) + ((Sexpr loc [(Slid _ (as (or "define" "definerec") r)) se . sel]) + (let* ((r (= r "definerec")) + ((values p e) (fun_binding_se se (begin_se loc sel)))) + <:str_item< value $opt:r$ $p$ = $e$ >>)) + ((Sexpr loc [(Slid _ (as (or "define*" "definerec*") r)) . sel]) + (let* ((r (= r "definerec*")) + (lbs (List.map let_binding_se sel))) + <:str_item< value $opt:r$ $list:lbs$ >>)) + ((Sexpr loc [(Slid _ "external") (Slid _ i) se . sel]) + (let* ((i (Pcaml.rename_id.val i)) + (pd (List.map string_se sel)) + (t (ctyp_se se))) + <:str_item< external $i$ : $t$ = $list:pd$ >>)) + ((Sexpr loc [(Slid _ "module") (Suid _ i) se]) + (let* ((i (Pcaml.rename_id.val i)) + (mb (module_binding_se se))) + <:str_item< module $i$ = $mb$ >>)) + ((Sexpr loc [(Slid _ "moduletype") (Suid _ s) se]) + (let* ((s (Pcaml.rename_id.val s)) + (mt (module_type_se se))) + <:str_item< module type $s$ = $mt$ >>)) + (_ + (let* ((loc (loc_of_sexpr se)) + (e (expr_se se))) + <:str_item< $exp:e$ >>)))) + ((module_binding_se se) (module_expr_se se)) + (expr_se + (lambda_match + ((Sacc loc se1 se2) + (let ((e1 (expr_se se1))) + (match se2 + ((Slist loc [se2]) + (let ((e2 (expr_se se2))) <:expr< $e1$ .[ $e2$ ] >>)) + ((Sexpr loc [se2]) + (let ((e2 (expr_se se2))) <:expr< $e1$ .( $e2$ ) >>)) + (_ (let ((e2 (expr_se se2))) <:expr< $e1$ . $e2$ >>))))) + ((Slid loc s) (lident_expr loc s)) + ((Suid loc s) <:expr< $uid:(Pcaml.rename_id.val s)$ >>) + ((Sint loc s) <:expr< $int:s$ >>) + ((Sfloat loc s) <:expr< $flo:s$ >>) + ((Schar loc s) <:expr< $chr:s$ >>) + ((Sstring loc s) <:expr< $str:s$ >>) + ((Stid loc s) <:expr< ~ $(Pcaml.rename_id.val s)$ >>) + ((Sqid loc s) <:expr< ? $(Pcaml.rename_id.val s)$ >>) + ((Sexpr loc []) <:expr< () >>) + ((when (Sexpr loc [(Slid _ s) e1 . (as [_ . _] sel)]) + (List.mem s assoc_left_parsed_op_list)) + (letrec + (((loop e1) + (lambda_match + ([] e1) + ([e2 . el] (loop (op_apply loc e1 e2 s) el))))) + (loop (expr_se e1) (List.map expr_se sel)))) + ((when (Sexpr loc [(Slid _ s) . (as [_ _ . _] sel)]) + (List.mem s assoc_right_parsed_op_list)) + (letrec + ((loop + (lambda_match + ([] + (assert False)) + ([e1] e1) + ([e1 . el] (let ((e2 (loop el))) (op_apply loc e1 e2 s)))))) + (loop (List.map expr_se sel)))) + ((when (Sexpr loc [(Slid _ s) . (as [_ _ . _] sel)]) + (List.mem s and_by_couple_op_list)) + (letrec + ((loop + (lambda_match + ((or [] [_]) (assert False)) + ([e1 e2] <:expr< $lid:s$ $e1$ $e2$ >>) + ([e1 . (as [e2 _ . _] el)] + (let* ((a1 (op_apply loc e1 e2 s)) + (a2 (loop el))) + <:expr< $a1$ && $a2$ >>))))) + (loop (List.map expr_se sel)))) + ((Sexpr loc [(Stid _ s) se]) + (let ((e (expr_se se))) <:expr< ~ $s$ : $e$ >>)) + ((Sexpr loc [(Slid _ "-") se]) + (let ((e (expr_se se))) <:expr< - $e$ >>)) + ((Sexpr loc [(Slid _ "if") se se1]) + (let* ((e (expr_se se)) + (e1 (expr_se se1))) + <:expr< if $e$ then $e1$ else () >>)) + ((Sexpr loc [(Slid _ "if") se se1 se2]) + (let* ((e (expr_se se)) + (e1 (expr_se se1)) + (e2 (expr_se se2))) + <:expr< if $e$ then $e1$ else $e2$ >>)) + ((Sexpr loc [(Slid _ "cond") . sel]) + (letrec + ((loop + (lambda_match + ([(Sexpr loc [(Slid _ "else") . sel])] (begin_se loc sel)) + ([(Sexpr loc [se1 . sel1]) . sel] + (let* ((e1 (expr_se se1)) + (e2 (begin_se loc sel1)) + (e3 (loop sel))) + <:expr< if $e1$ then $e2$ else $e3$ >>)) + ([] <:expr< () >>) + ([se . _] (error se "cond clause"))))) + (loop sel))) + ((Sexpr loc [(Slid _ "while") se . sel]) + (let* ((e (expr_se se)) + (el (List.map expr_se sel))) + <:expr< while $e$ do { $list:el$ } >>)) + ((Sexpr loc [(Slid _ "for") (Slid _ i) se1 se2 . sel]) + (let* ((i (Pcaml.rename_id.val i)) + (e1 (expr_se se1)) + (e2 (expr_se se2)) + (el (List.map expr_se sel))) + <:expr< for $i$ = $e1$ to $e2$ do { $list:el$ } >>)) + ((Sexpr loc [(Slid loc1 "lambda")]) <:expr< fun [] >>) + ((Sexpr loc [(Slid loc1 "lambda") sep . sel]) + (let ((e (begin_se loc1 sel))) + (match (ipatt_opt_se sep) + ((Left p) <:expr< fun $p$ -> $e$ >>) + ((Right (values se sel)) + (List.fold_right + (lambda (se e) + (let ((p (ipatt_se se))) <:expr< fun $p$ -> $e$ >>)) + [se . sel] e))))) + ((Sexpr loc [(Slid _ "lambda_match") . sel]) + (let ((pel (List.map (match_case loc) sel))) + <:expr< fun [ $list:pel$ ] >>)) + ((Sexpr loc [(Slid _ (as (or "let" "letrec") r)) . sel]) + (match sel + ([(Sexpr _ sel1) . sel2] + (let* ((r (= r "letrec")) + (lbs (List.map let_binding_se sel1)) + (e (begin_se loc sel2))) + <:expr< let $opt:r$ $list:lbs$ in $e$ >>)) + ([(Slid _ n) (Sexpr _ sl) . sel] + (let* ((n (Pcaml.rename_id.val n)) + ((values pl el) + (List.fold_right + (lambda (se (values pl el)) + (match se + ((Sexpr _ [se1 se2]) + (values [(patt_se se1) . pl] + [(expr_se se2) . el])) + (se (error se "named let")))) + sl (values [] []))) + (e1 + (List.fold_right + (lambda (p e) <:expr< fun $p$ -> $e$ >>) + pl (begin_se loc sel))) + (e2 + (List.fold_left + (lambda (e1 e2) <:expr< $e1$ $e2$ >>) + <:expr< $lid:n$ >> el))) + <:expr< let rec $lid:n$ = $e1$ in $e2$ >>)) + ([se . _] (error se "let_binding")) + (_ (error_loc loc "let_binding")))) + ((Sexpr loc [(Slid _ "let*") . sel]) + (match sel + ([(Sexpr _ sel1) . sel2] + (List.fold_right + (lambda (se ek) + (let (((values p e) (let_binding_se se))) + <:expr< let $p$ = $e$ in $ek$ >>)) + sel1 (begin_se loc sel2))) + ([se . _] (error se "let_binding")) + (_ (error_loc loc "let_binding")))) + ((Sexpr loc [(Slid _ "match") se . sel]) + (let* ((e (expr_se se)) + (pel (List.map (match_case loc) sel))) + <:expr< match $e$ with [ $list:pel$ ] >>)) + ((Sexpr loc [(Slid _ "parser") . sel]) + (let ((e + (match sel + ([(as (Slid _ _) se) . sel] + (let* ((p (patt_se se)) + (pc (parser_cases_se loc sel))) + <:expr< let $p$ = Stream.count $lid:strm_n$ in $pc$ >>)) + (_ (parser_cases_se loc sel))))) + <:expr< fun ($lid:strm_n$ : Stream.t _) -> $e$ >>)) + ((Sexpr loc [(Slid _ "match_with_parser") se . sel]) + (let* ((me (expr_se se)) + ((values bpo sel) + (match sel + ([(as (Slid _ _) se) . sel] (values (Some (patt_se se)) sel)) + (_ (values None sel)))) + (pc (parser_cases_se loc sel)) + (e + (match bpo + ((Some bp) + <:expr< let $bp$ = Stream.count $lid:strm_n$ in $pc$ >>) + (None pc)))) + (match me + ((when <:expr< $lid:x$ >> (= x strm_n)) e) + (_ <:expr< let ($lid:strm_n$ : Stream.t _) = $me$ in $e$ >>)))) + ((Sexpr loc [(Slid _ "try") se . sel]) + (let* ((e (expr_se se)) + (pel (List.map (match_case loc) sel))) + <:expr< try $e$ with [ $list:pel$ ] >>)) + ((Sexpr loc [(Slid _ "begin") . sel]) + (let ((el (List.map expr_se sel))) <:expr< do { $list:el$ } >>)) + ((Sexpr loc [(Slid _ ":=") se1 se2]) + (let* ((e1 (expr_se se1)) + (e2 (expr_se se2))) + <:expr< $e1$ := $e2$ >>)) + ((Sexpr loc [(Slid _ "values") . sel]) + (let ((el (List.map expr_se sel))) <:expr< ( $list:el$ ) >>)) + ((Srec loc [(Slid _ "with") se . sel]) + (let* ((e (expr_se se)) + (lel (List.map (label_expr_se loc) sel))) + <:expr< { ($e$) with $list:lel$ } >>)) + ((Srec loc sel) + (let ((lel (List.map (label_expr_se loc) sel))) + <:expr< { $list:lel$ } >>)) + ((Sexpr loc [(Slid _ ":") se1 se2]) + (let* ((e (expr_se se1)) (t (ctyp_se se2))) <:expr< ( $e$ : $t$ ) >>)) + ((Sexpr loc [se]) (let ((e (expr_se se))) <:expr< $e$ () >>)) + ((Sexpr loc [(Slid _ "assert") (Suid _ "False")]) + <:expr< assert False >>) + ((Sexpr loc [(Slid _ "assert") se]) + (let ((e (expr_se se))) <:expr< assert $e$ >>)) + ((Sexpr loc [(Slid _ "lazy") se]) + (let ((e (expr_se se))) <:expr< lazy $e$ >>)) + ((Sexpr loc [se . sel]) + (List.fold_left + (lambda (e se) (let ((e1 (expr_se se))) <:expr< $e$ $e1$ >>)) + (expr_se se) sel)) + ((Slist loc sel) + (letrec ((loop + (lambda_match + ([] <:expr< [] >>) + ([se1 (Slid _ ".") se2] + (let* ((e (expr_se se1)) + (el (expr_se se2))) + <:expr< [$e$ :: $el$] >>)) + ([se . sel] + (let* ((e (expr_se se)) + (el (loop sel))) + <:expr< [$e$ :: $el$] >>))))) + (loop sel))) + ((Squot loc typ txt) + (Pcaml.handle_expr_quotation loc (values typ txt))))) + ((begin_se loc) + (lambda_match + ([] <:expr< () >>) + ([se] (expr_se se)) + ((sel) + (let* ((el (List.map expr_se sel)) + (loc (values (fst (loc_of_sexpr (List.hd sel))) (snd loc)))) + <:expr< do { $list:el$ } >>)))) + (let_binding_se + (lambda_match + ((Sexpr loc [se . sel]) + (let ((e (begin_se loc sel))) + (match (ipatt_opt_se se) + ((Left p) (values p e)) + ((Right _) (fun_binding_se se e))))) + (se (error se "let_binding")))) + ((fun_binding_se se e) + (match se + ((Sexpr _ [(Slid _ "values") . _]) (values (ipatt_se se) e)) + ((Sexpr _ [(Slid loc s) . sel]) + (let* ((s (Pcaml.rename_id.val s)) + (e + (List.fold_right + (lambda (se e) + (let* ((loc + (values (fst (loc_of_sexpr se)) + (snd (MLast.loc_of_expr e)))) + (p (ipatt_se se))) + <:expr< fun $p$ -> $e$ >>)) + sel e)) + (p <:patt< $lid:s$ >>)) + (values p e))) + ((_) (values (ipatt_se se) e)))) + ((match_case loc) + (lambda_match + ((Sexpr loc [(Sexpr _ [(Slid _ "when") se sew]) . sel]) + (values (patt_se se) (Some (expr_se sew)) (begin_se loc sel))) + ((Sexpr loc [se . sel]) + (values (patt_se se) None (begin_se loc sel))) + (se (error se "match_case")))) + ((label_expr_se loc) + (lambda_match + ((Sexpr _ [se1 se2]) (values (patt_se se1) (expr_se se2))) + (se (error se "label_expr")))) + ((label_patt_se loc) + (lambda_match + ((Sexpr _ [se1 se2]) (values (patt_se se1) (patt_se se2))) + (se (error se "label_patt")))) + ((parser_cases_se loc) + (lambda_match + ([] <:expr< raise Stream.Failure >>) + ([(Sexpr loc [(Sexpr _ spsel) . act]) . sel] + (let* ((ekont (lambda _ (parser_cases_se loc sel))) + (act (match act + ([se] (expr_se se)) + ([sep se] + (let* ((p (patt_se sep)) + (e (expr_se se))) + <:expr< let $p$ = Stream.count $lid:strm_n$ in $e$ >>)) + (_ (error_loc loc "parser_case"))))) + (stream_pattern_se loc act ekont spsel))) + ([se . _] + (error se "parser_case")))) + ((stream_pattern_se loc act ekont) + (lambda_match + ([] act) + ([se . sel] + (let* ((ckont (lambda err <:expr< raise (Stream.Error $err$) >>)) + (skont (stream_pattern_se loc act ckont sel))) + (stream_pattern_component skont ekont <:expr< "" >> se))))) + ((stream_pattern_component skont ekont err) + (lambda_match + ((Sexpr loc [(Slid _ "`") se . wol]) + (let* ((wo (match wol + ([se] (Some (expr_se se))) + ([] None) + (_ (error_loc loc "stream_pattern_component")))) + (e (peek_fun loc)) + (p (patt_se se)) + (j (junk_fun loc)) + (k (ekont err))) + <:expr< match $e$ $lid:strm_n$ with + [ Some $p$ $when:wo$ -> do { $j$ $lid:strm_n$ ; $skont$ } + | _ -> $k$ ] >>)) + ((Sexpr loc [se1 se2]) + (let* ((p (patt_se se1)) + (e (let ((e (expr_se se2))) + <:expr< try Some ($e$ $lid:strm_n$) with [ Stream.Failure -> None ] >>)) + (k (ekont err))) + <:expr< match $e$ with [ Some $p$ -> $skont$ | _ -> $k$ ] >>)) + ((Sexpr loc [(Slid _ "?") se1 se2]) + (stream_pattern_component skont ekont (expr_se se2) se1)) + ((Slid loc s) + (let ((s (Pcaml.rename_id.val s))) + <:expr< let $lid:s$ = $lid:strm_n$ in $skont$ >>)) + (se + (error se "stream_pattern_component")))) + (patt_se + (lambda_match + ((Sacc loc se1 se2) + (let* ((p1 (patt_se se1)) (p2 (patt_se se2))) <:patt< $p1$ . $p2$ >>)) + ((Slid loc "_") <:patt< _ >>) + ((Slid loc s) <:patt< $lid:(Pcaml.rename_id.val s)$ >>) + ((Suid loc s) <:patt< $uid:(Pcaml.rename_id.val s)$ >>) + ((Sint loc s) <:patt< $int:s$ >>) + ((Sfloat loc s) <:patt< $flo:s$ >>) + ((Schar loc s) <:patt< $chr:s$ >>) + ((Sstring loc s) <:patt< $str:s$ >>) + ((Stid loc _) (error_loc loc "patt")) + ((Sqid loc _) (error_loc loc "patt")) + ((Srec loc sel) + (let ((lpl (List.map (label_patt_se loc) sel))) + <:patt< { $list:lpl$ } >>)) + ((Sexpr loc [(Slid _ ":") se1 se2]) + (let* ((p (patt_se se1)) (t (ctyp_se se2))) <:patt< ($p$ : $t$) >>)) + ((Sexpr loc [(Slid _ "or") se . sel]) + (List.fold_left + (lambda (p se) (let ((p1 (patt_se se))) <:patt< $p$ | $p1$ >>)) + (patt_se se) sel)) + ((Sexpr loc [(Slid _ "range") se1 se2]) + (let* ((p1 (patt_se se1)) (p2 (patt_se se2))) <:patt< $p1$ .. $p2$ >>)) + ((Sexpr loc [(Slid _ "values") . sel]) + (let ((pl (List.map patt_se sel))) <:patt< ( $list:pl$ ) >>)) + ((Sexpr loc [(Slid _ "as") se1 se2]) + (let* ((p1 (patt_se se1)) + (p2 (patt_se se2))) + <:patt< ($p1$ as $p2$) >>)) + ((Sexpr loc [se . sel]) + (List.fold_left + (lambda (p se) (let ((p1 (patt_se se))) <:patt< $p$ $p1$ >>)) + (patt_se se) sel)) + ((Sexpr loc []) <:patt< () >>) + ((Slist loc sel) + (letrec ((loop + (lambda_match + ([] <:patt< [] >>) + ([se1 (Slid _ ".") se2] + (let* ((p (patt_se se1)) + (pl (patt_se se2))) + <:patt< [$p$ :: $pl$] >>)) + ([se . sel] + (let* ((p (patt_se se)) + (pl (loop sel))) + <:patt< [$p$ :: $pl$] >>))))) + (loop sel))) + ((Squot loc typ txt) + (Pcaml.handle_patt_quotation loc (values typ txt))))) + ((ipatt_se se) + (match (ipatt_opt_se se) + ((Left p) p) + ((Right (values se _)) (error se "ipatt")))) + (ipatt_opt_se + (lambda_match + ((Slid loc "_") (Left <:patt< _ >>)) + ((Slid loc s) (Left <:patt< $lid:(Pcaml.rename_id.val s)$ >>)) + ((Stid loc s) (Left <:patt< ~ $(Pcaml.rename_id.val s)$ >>)) + ((Sqid loc s) (Left <:patt< ? $(Pcaml.rename_id.val s)$ >>)) + ((Sexpr loc [(Sqid _ s) se]) + (let* ((s (Pcaml.rename_id.val s)) + (e (expr_se se))) + (Left <:patt< ? ( $lid:s$ = $e$ ) >>))) + ((Sexpr loc [(Slid _ ":") se1 se2]) + (let* ((p (ipatt_se se1)) (t (ctyp_se se2))) + (Left <:patt< ($p$ : $t$) >>))) + ((Sexpr loc [(Slid _ "values") . sel]) + (let ((pl (List.map ipatt_se sel))) (Left <:patt< ( $list:pl$ ) >>))) + ((Sexpr loc []) (Left <:patt< () >>)) + ((Sexpr loc [se . sel]) (Right (values se sel))) + (se (error se "ipatt")))) + (type_declaration_list_se + (lambda_match + ([se1 se2 . sel] + (let (((values n1 loc1 tpl) + (match se1 + ((Sexpr _ [(Slid loc n) . sel]) + (values n loc (List.map type_parameter_se sel))) + ((Slid loc n) + (values n loc [])) + ((se) + (error se "type declaration"))))) + [(values (values loc1 (Pcaml.rename_id.val n1)) tpl (ctyp_se se2) []) . + (type_declaration_list_se sel)])) + ([] []) + ([se . _] (error se "type_declaration")))) + (type_parameter_se + (lambda_match + ((when (Slid _ s) (and (>= (String.length s) 2) (= s.[0] '''))) + (values (String.sub s 1 (- (String.length s) 1)) (values False False))) + (se + (error se "type_parameter")))) + (ctyp_se + (lambda_match + ((Sexpr loc [(Slid _ "sum") . sel]) + (let ((cdl (List.map constructor_declaration_se sel))) + <:ctyp< [ $list:cdl$ ] >>)) + ((Srec loc sel) + (let ((ldl (List.map label_declaration_se sel))) + <:ctyp< { $list:ldl$ } >>)) + ((Sexpr loc [(Slid _ "->") . (as [_ _ . _] sel)]) + (letrec + ((loop + (lambda_match + ([] (assert False)) + ([se] (ctyp_se se)) + ([se . sel] + (let* ((t1 (ctyp_se se)) + (loc (values (fst (loc_of_sexpr se)) (snd loc))) + (t2 (loop sel))) + <:ctyp< $t1$ -> $t2$ >>))))) + (loop sel))) + ((Sexpr loc [(Slid _ "*") . sel]) + (let ((tl (List.map ctyp_se sel))) <:ctyp< ($list:tl$) >>)) + ((Sexpr loc [se . sel]) + (List.fold_left + (lambda (t se) (let ((t2 (ctyp_se se))) <:ctyp< $t$ $t2$ >>)) + (ctyp_se se) sel)) + ((Sacc loc se1 se2) + (let* ((t1 (ctyp_se se1)) (t2 (ctyp_se se2))) <:ctyp< $t1$ . $t2$ >>)) + ((Slid loc "_") <:ctyp< _ >>) + ((Slid loc s) + (if (= s.[0] ''') + (let ((s (String.sub s 1 (- (String.length s) 1)))) + <:ctyp< '$s$ >>) + <:ctyp< $lid:(Pcaml.rename_id.val s)$ >>)) + ((Suid loc s) <:ctyp< $uid:(Pcaml.rename_id.val s)$ >>) + (se (error se "ctyp")))) + (constructor_declaration_se + (lambda_match + ((Sexpr loc [(Suid _ ci) . sel]) + (values loc (Pcaml.rename_id.val ci) (List.map ctyp_se sel))) + (se + (error se "constructor_declaration")))) + (label_declaration_se + (lambda_match + ((Sexpr loc [(Slid _ lab) (Slid _ "mutable") se]) + (values loc (Pcaml.rename_id.val lab) True (ctyp_se se))) + ((Sexpr loc [(Slid _ lab) se]) + (values loc (Pcaml.rename_id.val lab) False (ctyp_se se))) + (se + (error se "label_declaration"))))) + +(define directive_se + (lambda_match + ((Sexpr _ [(Slid _ s)]) (values s None)) + ((Sexpr _ [(Slid _ s) se]) (let ((e (expr_se se))) (values s (Some e)))) + (se (error se "directive")))) + +; Parser + +(:= Pcaml.syntax_name.val "Scheme") +(:= Pcaml.no_constructors_arity.val False) + +(begin + (Grammar.Unsafe.gram_reinit gram (lexer_gmake ())) + (Grammar.Unsafe.clear_entry interf) + (Grammar.Unsafe.clear_entry implem) + (Grammar.Unsafe.clear_entry top_phrase) + (Grammar.Unsafe.clear_entry use_file) + (Grammar.Unsafe.clear_entry module_type) + (Grammar.Unsafe.clear_entry module_expr) + (Grammar.Unsafe.clear_entry sig_item) + (Grammar.Unsafe.clear_entry str_item) + (Grammar.Unsafe.clear_entry expr) + (Grammar.Unsafe.clear_entry patt) + (Grammar.Unsafe.clear_entry ctyp) + (Grammar.Unsafe.clear_entry let_binding) + (Grammar.Unsafe.clear_entry type_declaration) + (Grammar.Unsafe.clear_entry class_type) + (Grammar.Unsafe.clear_entry class_expr) + (Grammar.Unsafe.clear_entry class_sig_item) + (Grammar.Unsafe.clear_entry class_str_item)) + +(:= Pcaml.parse_interf.val (Grammar.Entry.parse interf)) +(:= Pcaml.parse_implem.val (Grammar.Entry.parse implem)) + +(define sexpr (Grammar.Entry.create gram "sexpr")) + +(definerec leftify + (lambda_match + ((Sacc loc1 se1 se2) + (match (leftify se2) + ((Sacc loc2 se2 se3) (Sacc loc1 (Sacc loc2 se1 se2) se3)) + (se2 (Sacc loc1 se1 se2)))) + (x x))) + +EXTEND + GLOBAL : implem interf top_phrase use_file str_item sig_item expr + patt sexpr / + implem : + [ [ "#" / se = sexpr -> + (let (((values n dp) (directive_se se))) + (values [(values <:str_item< # $n$ $opt:dp$ >> loc)] True)) + | si = str_item / x = SELF -> + (let* (((values sil stopped) x) + (loc (MLast.loc_of_str_item si))) + (values [(values si loc) . sil] stopped)) + | EOI -> (values [] False) ] ] + / + interf : + [ [ "#" / se = sexpr -> + (let (((values n dp) (directive_se se))) + (values [(values <:sig_item< # $n$ $opt:dp$ >> loc)] True)) + | si = sig_item / x = SELF -> + (let* (((values sil stopped) x) + (loc (MLast.loc_of_sig_item si))) + (values [(values si loc) . sil] stopped)) + | EOI -> (values [] False) ] ] + / + top_phrase : + [ [ "#" / se = sexpr -> + (let (((values n dp) (directive_se se))) + (Some <:str_item< # $n$ $opt:dp$ >>)) + | se = sexpr -> (Some (str_item_se se)) + | EOI -> None ] ] + / + use_file : + [ [ "#" / se = sexpr -> + (let (((values n dp) (directive_se se))) + (values [<:str_item< # $n$ $opt:dp$ >>] True)) + | si = str_item / x = SELF -> + (let (((values sil stopped) x)) (values [si . sil] stopped)) + | EOI -> (values [] False) ] ] + / + str_item : + [ [ se = sexpr -> (str_item_se se) + | e = expr -> <:str_item< $exp:e$ >> ] ] + / + sig_item : + [ [ se = sexpr -> (sig_item_se se) ] ] + / + expr : + [ "top" + [ se = sexpr -> (expr_se se) ] ] + / + patt : + [ [ se = sexpr -> (patt_se se) ] ] + / + sexpr : + [ [ se1 = sexpr_dot / se2 = sexpr -> (leftify (Sacc loc se1 se2)) ] + | [ "(" / sl = LIST0 sexpr / ")" -> (Sexpr loc sl) + | "(" / sl = LIST0 sexpr / ")." / se = sexpr -> + (leftify (Sacc loc (Sexpr loc sl) se)) + | "[" / sl = LIST0 sexpr / "]" -> (Slist loc sl) + | "{" / sl = LIST0 sexpr / "}" -> (Srec loc sl) + | a = pa_extend_keyword -> (Slid loc a) + | s = LIDENT -> (Slid loc s) + | s = UIDENT -> (Suid loc s) + | s = TILDEIDENT -> (Stid loc s) + | s = QUESTIONIDENT -> (Sqid loc s) + | s = INT -> (Sint loc s) + | s = FLOAT -> (Sfloat loc s) + | s = CHAR -> (Schar loc s) + | s = STRING -> (Sstring loc s) + | s = QUOT -> + (let* ((i (String.index s ':')) + (typ (String.sub s 0 i)) + (txt (String.sub s (+ i 1) (- (- (String.length s) i) 1)))) + (Squot loc typ txt)) ] ] + / + sexpr_dot : + [ [ s = LIDENTDOT -> (Slid loc s) + | s = UIDENTDOT -> (Suid loc s) ] ] + / + pa_extend_keyword : + [ [ "_" -> "_" + | "," -> "," + | "=" -> "=" + | ":" -> ":" + | "." -> "." + | "/" -> "/" ] ] + / +END diff --git a/camlp4/unmaintained/scheme/pr_scheme.ml b/camlp4/unmaintained/scheme/pr_scheme.ml new file mode 100644 index 0000000..a9cf348 --- /dev/null +++ b/camlp4/unmaintained/scheme/pr_scheme.ml @@ -0,0 +1,826 @@ +(* pa_r.cmo q_MLast.cmo pa_extfun.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + +open Pcaml; +open Format; + +type printer_t 'a = + { pr_fun : mutable string -> next 'a; + pr_levels : mutable list (pr_level 'a) } +and pr_level 'a = + { pr_label : string; + pr_box : formatter -> (formatter -> unit) -> 'a -> unit; + pr_rules : mutable pr_rule 'a } +and pr_rule 'a = + Extfun.t 'a (formatter -> curr 'a -> next 'a -> string -> kont -> unit) +and curr 'a = formatter -> ('a * string * kont) -> unit +and next 'a = formatter -> ('a * string * kont) -> unit +and kont = formatter -> unit; + +value not_impl name x ppf k = + let desc = + if Obj.is_block (Obj.repr x) then + "tag = " ^ string_of_int (Obj.tag (Obj.repr x)) + else "int_val = " ^ string_of_int (Obj.magic x) + in + fprintf ppf "%t" name desc k +; + +value pr_fun name pr lab = + loop False pr.pr_levels where rec loop app = + fun + [ [] -> fun ppf (x, dg, k) -> failwith ("unable to print " ^ name) + | [lev :: levl] -> + if app || lev.pr_label = lab then + let next = loop True levl in + let rec curr ppf (x, dg, k) = + Extfun.apply lev.pr_rules x ppf curr next dg k + in + fun ppf ((x, _, _) as n) -> lev.pr_box ppf (fun ppf -> curr ppf n) x + else loop app levl ] +; + +value rec find_pr_level lab = + fun + [ [] -> failwith ("level " ^ lab ^ " not found") + | [lev :: levl] -> + if lev.pr_label = lab then lev else find_pr_level lab levl ] +; + +value pr_constr_decl = {pr_fun = fun []; pr_levels = []}; +value constr_decl ppf (x, k) = pr_constr_decl.pr_fun "top" ppf (x, "", k); +pr_constr_decl.pr_fun := pr_fun "constr_decl" pr_constr_decl; + +value pr_ctyp = {pr_fun = fun []; pr_levels = []}; +pr_ctyp.pr_fun := pr_fun "ctyp" pr_ctyp; +value ctyp ppf (x, k) = pr_ctyp.pr_fun "top" ppf (x, "", k); + +value pr_expr = {pr_fun = fun []; pr_levels = []}; +pr_expr.pr_fun := pr_fun "expr" pr_expr; +value expr ppf (x, k) = pr_expr.pr_fun "top" ppf (x, "", k); + +value pr_label_decl = {pr_fun = fun []; pr_levels = []}; +value label_decl ppf (x, k) = pr_label_decl.pr_fun "top" ppf (x, "", k); +pr_label_decl.pr_fun := pr_fun "label_decl" pr_label_decl; + +value pr_let_binding = {pr_fun = fun []; pr_levels = []}; +pr_let_binding.pr_fun := pr_fun "let_binding" pr_let_binding; +value let_binding ppf (x, k) = pr_let_binding.pr_fun "top" ppf (x, "", k); + +value pr_match_assoc = {pr_fun = fun []; pr_levels = []}; +pr_match_assoc.pr_fun := pr_fun "match_assoc" pr_match_assoc; +value match_assoc ppf (x, k) = pr_match_assoc.pr_fun "top" ppf (x, "", k); + +value pr_mod_ident = {pr_fun = fun []; pr_levels = []}; +pr_mod_ident.pr_fun := pr_fun "mod_ident" pr_mod_ident; +value mod_ident ppf (x, k) = pr_mod_ident.pr_fun "top" ppf (x, "", k); + +value pr_module_binding = {pr_fun = fun []; pr_levels = []}; +pr_module_binding.pr_fun := pr_fun "module_binding" pr_module_binding; +value module_binding ppf (x, k) = + pr_module_binding.pr_fun "top" ppf (x, "", k); + +value pr_module_expr = {pr_fun = fun []; pr_levels = []}; +pr_module_expr.pr_fun := pr_fun "module_expr" pr_module_expr; +value module_expr ppf (x, k) = pr_module_expr.pr_fun "top" ppf (x, "", k); + +value pr_module_type = {pr_fun = fun []; pr_levels = []}; +pr_module_type.pr_fun := pr_fun "module_type" pr_module_type; +value module_type ppf (x, k) = pr_module_type.pr_fun "top" ppf (x, "", k); + +value pr_patt = {pr_fun = fun []; pr_levels = []}; +pr_patt.pr_fun := pr_fun "patt" pr_patt; +value patt ppf (x, k) = pr_patt.pr_fun "top" ppf (x, "", k); + +value pr_sig_item = {pr_fun = fun []; pr_levels = []}; +pr_sig_item.pr_fun := pr_fun "sig_item" pr_sig_item; +value sig_item ppf (x, k) = pr_sig_item.pr_fun "top" ppf (x, "", k); + +value pr_str_item = {pr_fun = fun []; pr_levels = []}; +pr_str_item.pr_fun := pr_fun "str_item" pr_str_item; +value str_item ppf (x, k) = pr_str_item.pr_fun "top" ppf (x, "", k); + +value pr_type_decl = {pr_fun = fun []; pr_levels = []}; +value type_decl ppf (x, k) = pr_type_decl.pr_fun "top" ppf (x, "", k); +pr_type_decl.pr_fun := pr_fun "type_decl" pr_type_decl; + +value pr_type_params = {pr_fun = fun []; pr_levels = []}; +value type_params ppf (x, k) = pr_type_params.pr_fun "top" ppf (x, "", k); +pr_type_params.pr_fun := pr_fun "type_params" pr_type_params; + +value pr_with_constr = {pr_fun = fun []; pr_levels = []}; +value with_constr ppf (x, k) = pr_with_constr.pr_fun "top" ppf (x, "", k); +pr_with_constr.pr_fun := pr_fun "with_constr" pr_with_constr; + +(* general functions *) + +value nok ppf = (); +value ks s k ppf = fprintf ppf "%s%t" s k; + +value rec list f ppf (l, k) = + match l with + [ [] -> k ppf + | [x] -> f ppf (x, k) + | [x :: l] -> fprintf ppf "%a@ %a" f (x, nok) (list f) (l, k) ] +; + +value rec listwb b f ppf (l, k) = + match l with + [ [] -> k ppf + | [x] -> f ppf ((b, x), k) + | [x :: l] -> fprintf ppf "%a@ %a" f ((b, x), nok) (listwb "" f) (l, k) ] +; + +(* specific functions *) + +value rec is_irrefut_patt = + fun + [ <:patt< $lid:_$ >> -> True + | <:patt< () >> -> True + | <:patt< _ >> -> True + | <:patt< ($x$ as $y$) >> -> is_irrefut_patt x && is_irrefut_patt y + | <:patt< { $list:fpl$ } >> -> + List.for_all (fun (_, p) -> is_irrefut_patt p) fpl + | <:patt< ($p$ : $_$) >> -> is_irrefut_patt p + | <:patt< ($list:pl$) >> -> List.for_all is_irrefut_patt pl + | <:patt< ? $_$ : ( $p$ ) >> -> is_irrefut_patt p + | <:patt< ? $_$ : ($p$ = $_$) >> -> is_irrefut_patt p + | <:patt< ~ $_$ >> -> True + | <:patt< ~ $_$ : $p$ >> -> is_irrefut_patt p + | _ -> False ] +; + +value expr_fun_args ge = Extfun.apply pr_expr_fun_args.val ge; + +pr_expr_fun_args.val := + extfun Extfun.empty with + [ <:expr< fun [$p$ -> $e$] >> as ge -> + if is_irrefut_patt p then + let (pl, e) = expr_fun_args e in + ([p :: pl], e) + else ([], ge) + | ge -> ([], ge) ]; + +value sequence ppf (e, k) = + match e with + [ <:expr< do { $list:el$ } >> -> + fprintf ppf "@[%a@]" (list expr) (el, k) + | _ -> expr ppf (e, k) ] +; + +value string ppf (s, k) = fprintf ppf "\"%s\"%t" s k; + +value int_repr s = + if String.length s > 2 && s.[0] = '0' then + match s.[1] with + [ 'b' | 'o' | 'x' | 'B' | 'O' | 'X' -> + "#" ^ String.sub s 1 (String.length s - 1) + | _ -> s ] + else s +; + +value assoc_left_parsed_op_list = ["+"; "*"; "land"; "lor"; "lxor"]; +value assoc_right_parsed_op_list = ["and"; "or"; "^"; "@"]; +value and_by_couple_op_list = ["="; "<>"; "<"; ">"; "<="; ">="; "=="; "!="]; + +(* extensible pretty print functions *) + +pr_constr_decl.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (loc, c, []) -> + fun ppf curr next dg k -> fprintf ppf "(@[%s%t@]" c (ks ")" k) + | (loc, c, tl) -> + fun ppf curr next dg k -> + fprintf ppf "(@[%s@ %a@]" c (list ctyp) (tl, ks ")" k) ]}]; + +pr_ctyp.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:ctyp< [ $list:cdl$ ] >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[sum@ %a@]" (list constr_decl) (cdl, ks ")" k) + | <:ctyp< { $list:cdl$ } >> -> + fun ppf curr next dg k -> + fprintf ppf "{@[%a@]" (list label_decl) (cdl, ks "}" k) + | <:ctyp< ( $list:tl$ ) >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[* @[%a@]@]" (list ctyp) (tl, ks ")" k) + | <:ctyp< $t1$ -> $t2$ >> -> + fun ppf curr next dg k -> + let tl = + loop t2 where rec loop = + fun + [ <:ctyp< $t1$ -> $t2$ >> -> [t1 :: loop t2] + | t -> [t] ] + in + fprintf ppf "(@[-> @[%a@]@]" (list ctyp) + ([t1 :: tl], ks ")" k) + | <:ctyp< $t1$ $t2$ >> -> + fun ppf curr next dg k -> + let (t, tl) = + loop [t2] t1 where rec loop tl = + fun + [ <:ctyp< $t1$ $t2$ >> -> loop [t2 :: tl] t1 + | t1 -> (t1, tl) ] + in + fprintf ppf "(@[%a@ %a@]" ctyp (t, nok) (list ctyp) (tl, ks ")" k) + | <:ctyp< $t1$ . $t2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "%a.%a" ctyp (t1, nok) ctyp (t2, k) + | <:ctyp< $lid:s$ >> | <:ctyp< $uid:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | <:ctyp< ' $s$ >> -> + fun ppf curr next dg k -> fprintf ppf "'%s%t" s k + | <:ctyp< _ >> -> + fun ppf curr next dg k -> fprintf ppf "_%t" k + | x -> + fun ppf curr next dg k -> not_impl "ctyp" x ppf k ]}]; + +pr_expr.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:expr< fun [] >> -> + fun ppf curr next dg k -> + fprintf ppf "(lambda%t" (ks ")" k) + | <:expr< fun $lid:s$ -> $e$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(lambda@ %s@;<1 1>%a" s expr (e, ks ")" k) + | <:expr< fun [ $list:pwel$ ] >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[lambda_match@ %a@]" (list match_assoc) + (pwel, ks ")" k) + | <:expr< match $e$ with [ $list:pwel$ ] >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[match@ %a@]@ %a@]" expr (e, nok) + (list match_assoc) (pwel, ks ")" k) + | <:expr< try $e$ with [ $list:pwel$ ] >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[try@ %a@]@ %a@]" expr (e, nok) + (list match_assoc) (pwel, ks ")" k) + | <:expr< let $p1$ = $e1$ in $e2$ >> -> + fun ppf curr next dg k -> + let (pel, e) = + loop [(p1, e1)] e2 where rec loop pel = + fun + [ <:expr< let $p1$ = $e1$ in $e2$ >> -> + loop [(p1, e1) :: pel] e2 + | e -> (List.rev pel, e) ] + in + let b = + match pel with + [ [_] -> "let" + | _ -> "let*" ] + in + fprintf ppf "(@[@[%s (@[%a@]@]@;<1 2>%a@]" b + (listwb "" let_binding) (pel, ks ")" nok) + sequence (e, ks ")" k) + | <:expr< let $opt:rf$ $list:pel$ in $e$ >> -> + fun ppf curr next dg k -> + let b = if rf then "letrec" else "let" in + fprintf ppf "(@[%s@ (@[%a@]@ %a@]" b + (listwb "" let_binding) (pel, ks ")" nok) expr (e, ks ")" k) + | <:expr< if $e1$ then $e2$ else () >> -> + fun ppf curr next dg k -> + fprintf ppf "(if @[%a@;<1 0>%a@]" expr (e1, nok) + expr (e2, ks ")" k) + | <:expr< if $e1$ then $e2$ else $e3$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(if @[%a@ %a@ %a@]" expr (e1, nok) + expr (e2, nok) expr (e3, ks ")" k) + | <:expr< do { $list:el$ } >> -> + fun ppf curr next dg k -> + fprintf ppf "(begin@;<1 1>@[%a@]" (list expr) (el, ks ")" k) + | <:expr< for $i$ = $e1$ to $e2$ do { $list:el$ } >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[for %s@ %a@ %a %a@]" i expr (e1, nok) + expr (e2, nok) (list expr) (el, ks ")" k) + | <:expr< ($e$ : $t$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(:@ %a@ %a" expr (e, nok) ctyp (t, ks ")" k) + | <:expr< ($list:el$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(values @[%a@]" (list expr) (el, ks ")" k) + | <:expr< { $list:fel$ } >> -> + fun ppf curr next dg k -> + let record_binding ppf ((p, e), k) = + fprintf ppf "(@[%a@ %a@]" patt (p, nok) expr (e, ks ")" k) + in + fprintf ppf "{@[%a@]" (list record_binding) (fel, ks "}" k) + | <:expr< { ($e$) with $list:fel$ } >> -> + fun ppf curr next dg k -> + let record_binding ppf ((p, e), k) = + fprintf ppf "(@[%a@ %a@]" patt (p, nok) expr (e, ks ")" k) + in + fprintf ppf "{@[@[with@ %a@]@ @[%a@]@]" expr (e, nok) + (list record_binding) (fel, ks "}" k) + | <:expr< $e1$ := $e2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(:=@;<1 1>%a@;<1 1>%a" expr (e1, nok) + expr (e2, ks ")" k) + | <:expr< [$_$ :: $_$] >> as e -> + fun ppf curr next dg k -> + let (el, c) = + make_list e where rec make_list e = + match e with + [ <:expr< [$e$ :: $y$] >> -> + let (el, c) = make_list y in + ([e :: el], c) + | <:expr< [] >> -> ([], None) + | x -> ([], Some e) ] + in + match c with + [ None -> + fprintf ppf "[%a" (list expr) (el, ks "]" k) + | Some x -> + fprintf ppf "[%a@ %a" (list expr) (el, ks " ." nok) + expr (x, ks "]" k) ] + | <:expr< lazy ($x$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[lazy@ %a@]" expr (x, ks ")" k) + | <:expr< $lid:s$ $e1$ $e2$ >> + when List.mem s assoc_right_parsed_op_list -> + fun ppf curr next dg k -> + let el = + loop [e1] e2 where rec loop el = + fun + [ <:expr< $lid:s1$ $e1$ $e2$ >> when s1 = s -> + loop [e1 :: el] e2 + | e -> List.rev [e :: el] ] + in + fprintf ppf "(@[%s %a@]" s (list expr) (el, ks ")" k) + | <:expr< $e1$ $e2$ >> -> + fun ppf curr next dg k -> + let (f, el) = + loop [e2] e1 where rec loop el = + fun + [ <:expr< $e1$ $e2$ >> -> loop [e2 :: el] e1 + | e1 -> (e1, el) ] + in + fprintf ppf "(@[%a@ %a@]" expr (f, nok) (list expr) (el, ks ")" k) + | <:expr< ~ $s$ : ($e$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(~%s@ %a" s expr (e, ks ")" k) + | <:expr< $e1$ .[ $e2$ ] >> -> + fun ppf curr next dg k -> + fprintf ppf "%a.[%a" expr (e1, nok) expr (e2, ks "]" k) + | <:expr< $e1$ .( $e2$ ) >> -> + fun ppf curr next dg k -> + fprintf ppf "%a.(%a" expr (e1, nok) expr (e2, ks ")" k) + | <:expr< $e1$ . $e2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "%a.%a" expr (e1, nok) expr (e2, k) + | <:expr< $int:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" (int_repr s) k + | <:expr< $lid:s$ >> | <:expr< $uid:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | <:expr< ` $s$ >> -> + fun ppf curr next dg k -> fprintf ppf "`%s%t" s k + | <:expr< $str:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "\"%s\"%t" s k + | <:expr< $chr:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "'%s'%t" s k + | x -> + fun ppf curr next dg k -> not_impl "expr" x ppf k ]}]; + +pr_label_decl.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (loc, f, m, t) -> + fun ppf curr next dg k -> + fprintf ppf "(@[%s%t@ %a@]" f + (fun ppf -> if m then fprintf ppf "@ mutable" else ()) + ctyp (t, ks ")" k) ]}]; + +pr_let_binding.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (b, (p, e)) -> + fun ppf curr next dg k -> + let (pl, e) = expr_fun_args e in + match pl with + [ [] -> + fprintf ppf "(@[%s%s%a@ %a@]" b + (if b = "" then "" else " ") patt (p, nok) + sequence (e, ks ")" k) + | _ -> + fprintf ppf "(@[%s%s(%a)@ %a@]" b + (if b = "" then "" else " ") (list patt) ([p :: pl], nok) + sequence (e, ks ")" k) ] ]}]; + +pr_match_assoc.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (p, we, e) -> + fun ppf curr next dg k -> + fprintf ppf "(@[%t@ %a@]" + (fun ppf -> + match we with + [ Some e -> + fprintf ppf "(when@ %a@ %a" patt (p, nok) + expr (e, ks ")" nok) + | None -> patt ppf (p, nok) ]) + sequence (e, ks ")" k) ]}]; + +pr_mod_ident.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ [s] -> + fun ppf curr next dg k -> + fprintf ppf "%s%t" s k + | [s :: sl] -> + fun ppf curr next dg k -> + fprintf ppf "%s.%a" s curr (sl, "", k) + | x -> + fun ppf curr next dg k -> not_impl "mod_ident" x ppf k ]}]; + +pr_module_binding.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (b, s, me) -> + fun ppf curr next dg k -> + fprintf ppf "%s@ %s@ %a" b s module_expr (me, k) ]}]; + +pr_module_expr.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:module_expr< functor ($i$ : $mt$) -> $me$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[@[functor@ %s@]@ %a@]@ %a@]" + i module_type (mt, nok) module_expr (me, ks ")" k) + | <:module_expr< struct $list:sil$ end >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[struct@ @[%a@]@]" (list str_item) + (sil, ks ")" k) + | <:module_expr< $me1$ $me2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[%a@ %a@]" module_expr (me1, nok) + module_expr (me2, ks ")" k) + | <:module_expr< $uid:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | x -> + fun ppf curr next dg k -> not_impl "module_expr" x ppf k ]}]; + +pr_module_type.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:module_type< functor ($i$ : $mt1$) -> $mt2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[@[functor@ %s@]@ %a@]@ %a@]" + i module_type (mt1, nok) module_type (mt2, ks ")" k) + | <:module_type< sig $list:sil$ end >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[sig@ @[%a@]@]" (list sig_item) (sil, ks ")" k) + | <:module_type< $mt$ with $list:wcl$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[with@;<1 2>@[%a@ (%a@]@]" module_type (mt, nok) + (list with_constr) (wcl, ks "))" k) + | <:module_type< $uid:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | x -> + fun ppf curr next dg k -> not_impl "module_type" x ppf k ]}]; + +pr_patt.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:patt< $p1$ | $p2$ >> -> + fun ppf curr next dg k -> + let (f, pl) = + loop [p2] p1 where rec loop pl = + fun + [ <:patt< $p1$ | $p2$ >> -> loop [p2 :: pl] p1 + | p1 -> (p1, pl) ] + in + fprintf ppf "(@[or@ %a@ %a@]" patt (f, nok) (list patt) + (pl, ks ")" k) + | <:patt< ($p1$ as $p2$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[as@ %a@ %a@]" patt (p1, nok) patt (p2, ks ")" k) + | <:patt< $p1$ .. $p2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[range@ %a@ %a@]" patt (p1, nok) patt (p2, ks ")" k) + | <:patt< [$_$ :: $_$] >> as p -> + fun ppf curr next dg k -> + let (pl, c) = + make_list p where rec make_list p = + match p with + [ <:patt< [$p$ :: $y$] >> -> + let (pl, c) = make_list y in + ([p :: pl], c) + | <:patt< [] >> -> ([], None) + | x -> ([], Some p) ] + in + match c with + [ None -> + fprintf ppf "[%a" (list patt) (pl, ks "]" k) + | Some x -> + fprintf ppf "[%a@ %a" (list patt) (pl, ks " ." nok) + patt (x, ks "]" k) ] + | <:patt< $p1$ $p2$ >> -> + fun ppf curr next dg k -> + let pl = + loop [p2] p1 where rec loop pl = + fun + [ <:patt< $p1$ $p2$ >> -> loop [p2 :: pl] p1 + | p1 -> [p1 :: pl] ] + in + fprintf ppf "(@[%a@]" (list patt) (pl, ks ")" k) + | <:patt< ($p$ : $t$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(:@ %a@ %a" patt (p, nok) ctyp (t, ks ")" k) + | <:patt< ($list:pl$) >> -> + fun ppf curr next dg k -> + fprintf ppf "(values @[%a@]" (list patt) (pl, ks ")" k) + | <:patt< { $list:fpl$ } >> -> + fun ppf curr next dg k -> + let record_binding ppf ((p1, p2), k) = + fprintf ppf "(@[%a@ %a@]" patt (p1, nok) patt (p2, ks ")" k) + in + fprintf ppf "(@[{}@ %a@]" (list record_binding) (fpl, ks ")" k) + | <:patt< ? $x$ >> -> + fun ppf curr next dg k -> fprintf ppf "?%s%t" x k + | <:patt< ? ($lid:x$ = $e$) >> -> + fun ppf curr next dg k -> fprintf ppf "(?%s@ %a" x expr (e, ks ")" k) + | <:patt< $p1$ . $p2$ >> -> + fun ppf curr next dg k -> + fprintf ppf "%a.%a" patt (p1, nok) patt (p2, k) + | <:patt< $lid:s$ >> | <:patt< $uid:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | <:patt< $str:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "\"%s\"%t" s k + | <:patt< $chr:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "'%s'%t" s k + | <:patt< $int:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" (int_repr s) k + | <:patt< $flo:s$ >> -> + fun ppf curr next dg k -> fprintf ppf "%s%t" s k + | <:patt< _ >> -> + fun ppf curr next dg k -> fprintf ppf "_%t" k + | x -> + fun ppf curr next dg k -> not_impl "patt" x ppf k ]}]; + +pr_sig_item.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:sig_item< type $list:tdl$ >> -> + fun ppf curr next dg k -> + match tdl with + [ [td] -> fprintf ppf "(%a" type_decl (("type", td), ks ")" k) + | tdl -> + fprintf ppf "(@[type@ %a@]" (listwb "" type_decl) + (tdl, ks ")" k) ] + | <:sig_item< exception $c$ of $list:tl$ >> -> + fun ppf curr next dg k -> + match tl with + [ [] -> fprintf ppf "(@[exception@ %s%t@]" c (ks ")" k) + | tl -> + fprintf ppf "(@[@[exception@ %s@]@ %a@]" c + (list ctyp) (tl, ks ")" k) ] + | <:sig_item< value $i$ : $t$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[value %s@]@ %a@]" i ctyp (t, ks ")" k) + | <:sig_item< external $i$ : $t$ = $list:pd$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[external@ %s@]@ %a@ %a@]" i ctyp (t, nok) + (list string) (pd, ks ")" k) + | <:sig_item< module $s$ : $mt$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[module@ %s@]@ %a@]" s + module_type (mt, ks ")" k) + | <:sig_item< module type $s$ = $mt$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[moduletype@ %s@]@ %a@]" s + module_type (mt, ks ")" k) + | <:sig_item< declare $list:s$ end >> -> + fun ppf curr next dg k -> + if s = [] then fprintf ppf "; ..." + else fprintf ppf "%a" (list sig_item) (s, k) + | MLast.SgUse _ _ _ -> + fun ppf curr next dg k -> () + | x -> + fun ppf curr next dg k -> not_impl "sig_item" x ppf k ]}]; + +pr_str_item.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ <:str_item< open $i$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(open@ %a" mod_ident (i, ks ")" k) + | <:str_item< type $list:tdl$ >> -> + fun ppf curr next dg k -> + match tdl with + [ [td] -> fprintf ppf "(%a" type_decl (("type", td), ks ")" k) + | tdl -> + fprintf ppf "(@[type@ %a@]" (listwb "" type_decl) + (tdl, ks ")" k) ] + | <:str_item< exception $c$ of $list:tl$ >> -> + fun ppf curr next dg k -> + match tl with + [ [] -> fprintf ppf "(@[exception@ %s%t@]" c (ks ")" k) + | tl -> + fprintf ppf "(@[@[exception@ %s@]@ %a@]" c + (list ctyp) (tl, ks ")" k) ] + | <:str_item< value $opt:rf$ $list:pel$ >> -> + fun ppf curr next dg k -> + let b = if rf then "definerec" else "define" in + match pel with + [ [(p, e)] -> + fprintf ppf "%a" let_binding ((b, (p, e)), k) + | pel -> + fprintf ppf "(@[%s*@ %a@]" b (listwb "" let_binding) + (pel, ks ")" k) ] + | <:str_item< module $s$ = $me$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(%a" module_binding (("module", s, me), ks ")" k) + | <:str_item< module type $s$ = $mt$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[@[moduletype@ %s@]@ %a@]" s + module_type (mt, ks ")" k) + | <:str_item< external $i$ : $t$ = $list:pd$ >> -> + fun ppf curr next dg k -> + fprintf ppf "(@[external@ %s@ %a@ %a@]" i ctyp (t, nok) + (list string) (pd, ks ")" k) + | <:str_item< $exp:e$ >> -> + fun ppf curr next dg k -> + fprintf ppf "%a" expr (e, k) + | <:str_item< # $s$ $opt:x$ >> -> + fun ppf curr next dg k -> + match x with + [ Some e -> fprintf ppf "; # (%s %a" s expr (e, ks ")" k) + | None -> fprintf ppf "; # (%s%t" s (ks ")" k) ] + | <:str_item< declare $list:s$ end >> -> + fun ppf curr next dg k -> + if s = [] then fprintf ppf "; ..." + else fprintf ppf "%a" (list str_item) (s, k) + | MLast.StUse _ _ _ -> + fun ppf curr next dg k -> () + | x -> + fun ppf curr next dg k -> not_impl "str_item" x ppf k ]}]; + +pr_type_decl.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ (b, ((_, tn), tp, te, cl)) -> + fun ppf curr next dg k -> + fprintf ppf "%t%t@;<1 1>%a" + (fun ppf -> + if b <> "" then fprintf ppf "%s@ " b + else ()) + (fun ppf -> + match tp with + [ [] -> fprintf ppf "%s" tn + | tp -> fprintf ppf "(%s%a)" tn type_params (tp, nok) ]) + ctyp (te, k) ]}]; + +pr_type_params.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ [(s, vari) :: tpl] -> + fun ppf curr next dg k -> + fprintf ppf "@ '%s%a" s type_params (tpl, k) + | [] -> + fun ppf curr next dg k -> () ]}]; + +pr_with_constr.pr_levels := + [{pr_label = "top"; + pr_box ppf f x = fprintf ppf "@[%t@]" f; + pr_rules = + extfun Extfun.empty with + [ MLast.WcTyp _ m tp te -> + fun ppf curr next dg k -> + fprintf ppf "(type@ %t@;<1 1>%a" + (fun ppf -> + match tp with + [ [] -> fprintf ppf "%a" mod_ident (m, nok) + | tp -> + fprintf ppf "(%a@ %a)" mod_ident (m, nok) + type_params (tp, nok) ]) + ctyp (te, ks ")" k) + | x -> + fun ppf curr next dg k -> not_impl "with_constr" x ppf k ]}]; + +(* main *) + +value output_string_eval ppf s = + loop 0 where rec loop i = + if i == String.length s then () + else if i == String.length s - 1 then pp_print_char ppf s.[i] + else + match (s.[i], s.[i + 1]) with + [ ('\\', 'n') -> do { pp_print_char ppf '\n'; loop (i + 2) } + | (c, _) -> do { pp_print_char ppf c; loop (i + 1) } ] +; + +value sep = Pcaml.inter_phrases; + +value input_source ic len = + let buff = Buffer.create 20 in + try + let rec loop i = + if i >= len then Buffer.contents buff + else do { let c = input_char ic in Buffer.add_char buff c; loop (i + 1) } + in + loop 0 + with + [ End_of_file -> + let s = Buffer.contents buff in + if s = "" then + match sep.val with + [ Some s -> s + | None -> "\n" ] + else s ] +; + +value copy_source ppf (ic, first, bp, ep) = + match sep.val with + [ Some str -> + if first then () + else if ep == in_channel_length ic then pp_print_string ppf "\n" + else output_string_eval ppf str + | None -> + do { + seek_in ic bp; + let s = input_source ic (ep - bp) in pp_print_string ppf s + } ] +; + +value copy_to_end ppf (ic, first, bp) = + let ilen = in_channel_length ic in + if bp < ilen then copy_source ppf (ic, first, bp, ilen) + else pp_print_string ppf "\n" +; + +value apply_printer printer ast = + let ppf = std_formatter in + if Pcaml.input_file.val <> "-" && Pcaml.input_file.val <> "" then do { + let ic = open_in_bin Pcaml.input_file.val in + try + let (first, last_pos) = + List.fold_left + (fun (first, last_pos) (si, (bp, ep)) -> + do { + fprintf ppf "@[%a@]@?" copy_source (ic, first, last_pos.Lexing.pos_cnum, bp.Lexing.pos_cnum); + fprintf ppf "@[%a@]@?" printer (si, nok); + (False, ep) + }) + (True, Token.nowhere) ast + in + fprintf ppf "@[%a@]@?" copy_to_end (ic, first, last_pos.Lexing.pos_cnum) + with x -> + do { fprintf ppf "@."; close_in ic; raise x }; + close_in ic; + } + else failwith "not implemented" +; + +Pcaml.print_interf.val := apply_printer sig_item; +Pcaml.print_implem.val := apply_printer str_item; + +Pcaml.add_option "-l" (Arg.Int (fun x -> set_margin x)) + " Maximum line length for pretty printing."; + +Pcaml.add_option "-sep" (Arg.String (fun x -> sep.val := Some x)) + " Use this string between phrases instead of reading source."; diff --git a/camlp4/unmaintained/scheme/pr_schp_main.ml b/camlp4/unmaintained/scheme/pr_schp_main.ml new file mode 100644 index 0000000..4d3a6fb --- /dev/null +++ b/camlp4/unmaintained/scheme/pr_schp_main.ml @@ -0,0 +1,132 @@ +(* pa_r.cmo q_MLast.cmo pa_extfun.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + +open Format; +open Pcaml; +open Parserify; + +value nok = Pr_scheme.nok; +value ks = Pr_scheme.ks; +value patt = Pr_scheme.patt; +value expr = Pr_scheme.expr; +value find_pr_level = Pr_scheme.find_pr_level; +value pr_expr = Pr_scheme.pr_expr; +type printer_t 'a = Pr_scheme.printer_t 'a == + { pr_fun : mutable string -> Pr_scheme.next 'a; + pr_levels : mutable list (pr_level 'a) } +and pr_level 'a = Pr_scheme.pr_level 'a == + { pr_label : string; + pr_box : formatter -> (formatter -> unit) -> 'a -> unit; + pr_rules : mutable Pr_scheme.pr_rule 'a } +; + +(* extensions for rebuilding syntax of parsers *) + +value parser_cases ppf (spel, k) = + let rec parser_cases ppf (spel, k) = + match spel with + [ [] -> fprintf ppf "[: `HVbox [: b; k :] :]" + | [(sp, epo, e)] -> parser_case ppf (sp, epo, e, k) + | [(sp, epo, e) :: spel] -> + fprintf ppf "%a@ %a" parser_case (sp, epo, e, nok) + parser_cases (spel, k) ] + and parser_case ppf (sp, epo, e, k) = + fprintf ppf "(@[@[(%a)%t@]@ %a@]" stream_patt (sp, nok) + (fun ppf -> + match epo with + [ Some p -> fprintf ppf "@ %a" patt (p, nok) + | None -> () ]) + expr (e, ks ")" k) + and stream_patt ppf (sp, k) = + match sp with + [ [] -> k ppf + | [(spc, None)] -> fprintf ppf "%a" stream_patt_comp (spc, k) + | [(spc, Some e)] -> + fprintf ppf "(@[? %a@ %a@]" stream_patt_comp (spc, nok) + expr (e, ks ")" k) + | [(spc, None) :: spcl] -> + fprintf ppf "%a@ %a" stream_patt_comp (spc, nok) stream_patt (spcl, k) + | [(spc, Some e) :: spcl] -> + fprintf ppf "(@[? %a@ %a@]@ %a" stream_patt_comp (spc, nok) + expr (e, ks ")" nok) stream_patt (spcl, k) ] + and stream_patt_comp ppf (spc, k) = + match spc with + [ SPCterm (p, w) -> + match w with + [ Some e -> + fprintf ppf "(` %a@ %a" patt (p, nok) expr (e, ks ")" k) + | None -> fprintf ppf "(` %a" patt (p, ks ")" k) ] + | SPCnterm p e -> + fprintf ppf "(@[%a %a@]" patt (p, nok) expr (e, ks ")" k) + | SPCsterm p -> fprintf ppf "%a" patt (p, k) ] + in + parser_cases ppf (spel, k) +; + +value parser_body ppf (e, k) = + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + match parser_of_expr e with + [ [] -> + fprintf ppf "(parser%t%t" + (fun ppf -> + match bp with + [ Some p -> fprintf ppf "@ %a" patt (p, nok) + | _ -> ()]) + (ks ")" k) + | spel -> + fprintf ppf "(@[@[parser%t@]@ @[%a@]@]" + (fun ppf -> + match bp with + [ Some p -> fprintf ppf "@ %a" patt (p, nok) + | _ -> ()]) + parser_cases (spel, ks ")" k) ] +; + +value pmatch ppf (e, k) = + let (me, e) = + match e with + [ <:expr< let (__strm : Stream.t _) = $me$ in $e$ >> -> (me, e) + | _ -> failwith "Pr_schp_main.pmatch" ] + in + let (bp, e) = + match e with + [ <:expr< let $bp$ = Stream.count __strm in $e$ >> -> (Some bp, e) + | e -> (None, e) ] + in + let spel = parser_of_expr e in + fprintf ppf "(@[@[match_with_parser@ %a@]%t@ @[%a@]@]" expr (me, nok) + (fun ppf -> + match bp with + [ Some p -> fprintf ppf "@ %a" patt (p, nok) + | _ -> () ]) + parser_cases (spel, ks ")" k) +; + +pr_expr_fun_args.val := + extfun pr_expr_fun_args.val with + [ <:expr< fun [(__strm : $_$) -> $_$] >> as ge -> ([], ge) ]; + +let lev = find_pr_level "top" pr_expr.pr_levels in +lev.pr_rules := + extfun lev.pr_rules with + [ <:expr< fun (__strm : $_$) -> $x$ >> -> + fun ppf curr next dg k -> fprintf ppf "%a" parser_body (x, k) + | <:expr< let (__strm : Stream.t _) = $_$ in $_$ >> as e -> + fun ppf curr next dg k -> fprintf ppf "%a" pmatch (e, k) ]; diff --git a/camlp4/unmaintained/sml/.depend b/camlp4/unmaintained/sml/.depend new file mode 100644 index 0000000..e69de29 diff --git a/camlp4/unmaintained/sml/Makefile b/camlp4/unmaintained/sml/Makefile new file mode 100644 index 0000000..ea3980b --- /dev/null +++ b/camlp4/unmaintained/sml/Makefile @@ -0,0 +1,68 @@ +######################################################################### +# # +# Objective Caml # +# # +# Camlp4 # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### +# +# Makefile for pa_sml +# M.Mauny +# + +include ../../config/Makefile.cnf + +OCAMLTOP=../../.. + +OCAMLC=$(OCAMLTOP)/ocamlc$(EXE) -nostdlib -I $(OCAMLTOP)/stdlib +OCAMLOPT=$(OCAMLTOP)/ocamlopt$(EXE) -nostdlib -I $(OCAMLTOP)/stdlib + +P4INCLUDES=-I ../../meta -I ../../etc -I ../../lib -I ../../camlp4 +OCAMLINCLUDES=-I ../../meta -I ../../lib -I ../../camlp4 + +CAMLP4=camlp4$(EXE) -nolib +OCAMLCFLAGS=-warn-error A $(OCAMLINCLUDES) + +SRC=pa_sml.ml +OBJS=$(SRC:.ml=.cmo) +OBJSX=$(SRC:.ml=.cmx) + +all: $(OBJS) smllib.cmo + +opt: $(OBJSX) smllib.cmx + +depend: + cp .depend .depend.bak + > .depend + for file in $(SRC); do \ + $(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $$file` pr_depend.cmo $$i | \ + sed -e 's| \.\./\.\./\.\.| $$(OCAMLTOP)|g' >> .depend; \ + done + +clean: + rm -f *.cm* *.o *.bak .*.bak + + +.SUFFIXES: .cmx .cmo .cmi .ml .mli .sml + +.mli.cmi: + $(OCAMLC) $(OCAMLCFLAGS) -c $< + + +.sml.cmo: + $(OCAMLC) -I ../../../otherlibs/unix -pp "$(CAMLP4) ./pa_sml.cmo ../../meta/pr_dump.cmo -impl" -c -o $*.cmo -impl $< + +.sml.cmx: + $(OCAMLOPT) -I ../../../otherlibs/unix -pp "$(CAMLP4) ./pa_sml.cmo ../../meta/pr_dump.cmo -impl" -c -o $*.cmx -impl $< + +.ml.cmo: + $(OCAMLC) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +.ml.cmx: + $(OCAMLOPT) $(OCAMLCFLAGS) -pp "$(CAMLP4) $(P4INCLUDES) `awk 'NR == 1 { ORS=" "; for (i=2; i < NF; i++) print $$i; } ' $<`" -c $< + +include .depend diff --git a/camlp4/unmaintained/sml/README b/camlp4/unmaintained/sml/README new file mode 100644 index 0000000..809d42f --- /dev/null +++ b/camlp4/unmaintained/sml/README @@ -0,0 +1,15 @@ +This is an application of or an extension for Camlp4. Although it is +currently distributed with OCaml/Camlp4, it may or may not be +actively maintained. + +It probably won't be part of future OCaml/Camlp4 distributions but be +accessible from the Camlp4 hump. If you are interested in developing +this package further and/or actively maintain it, please let us know +(caml@inria.fr) + +This package is distributed under the same license as the Objective +Caml Library (that is, LGPL with a special exception allowing both +static and dynamic link). + +-- Michel Mauny + diff --git a/camlp4/unmaintained/sml/pa_sml.ml b/camlp4/unmaintained/sml/pa_sml.ml new file mode 100644 index 0000000..1808cde --- /dev/null +++ b/camlp4/unmaintained/sml/pa_sml.ml @@ -0,0 +1,952 @@ +(* pa_r.cmo pa_rp.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo *) +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file *) +(* ../../../LICENSE. *) +(* *) +(***********************************************************************) + + + +open Stdpp; +open Pcaml; + +value ocaml_records = ref False; + +Pcaml.no_constructors_arity.val := True; + +value lexer = Plexer.gmake (); + +do { + Grammar.Unsafe.gram_reinit gram lexer; + Grammar.Unsafe.clear_entry interf; + Grammar.Unsafe.clear_entry implem; + Grammar.Unsafe.clear_entry top_phrase; + Grammar.Unsafe.clear_entry use_file; + Grammar.Unsafe.clear_entry module_type; + Grammar.Unsafe.clear_entry module_expr; + Grammar.Unsafe.clear_entry sig_item; + Grammar.Unsafe.clear_entry str_item; + Grammar.Unsafe.clear_entry expr; + Grammar.Unsafe.clear_entry patt; + Grammar.Unsafe.clear_entry ctyp; + Grammar.Unsafe.clear_entry let_binding; +}; + +Pcaml.parse_interf.val := Grammar.Entry.parse interf; +Pcaml.parse_implem.val := Grammar.Entry.parse implem; + +value not_impl loc s = + raise_with_loc loc (Stream.Error ("not implemented feature [" ^ s ^ "]")) +; + +type altern 'a 'b = [ Left of 'a | Right of 'b ]; + +value get_seq = + fun + [ <:expr< do { $list:el$ } >> -> el + | e -> [e] ] +; + +value choose_tvar tpl = + let rec find_alpha v = + let s = String.make 1 v in + if List.mem_assoc s tpl then + if v = 'z' then None else find_alpha (Char.chr (Char.code v + 1)) + else Some (String.make 1 v) + in + let rec make_n n = + let v = "a" ^ string_of_int n in + if List.mem_assoc v tpl then make_n (succ n) else v + in + match find_alpha 'a' with + [ Some x -> x + | None -> make_n 1 ] +; + +value mklistexp loc last = + loop True where rec loop top = + fun + [ [] -> + match last with + [ Some e -> e + | None -> <:expr< [] >> ] + | [e1 :: el] -> + let loc = if top then loc else (fst (MLast.loc_of_expr e1), snd loc) in + <:expr< [$e1$ :: $loop False el$] >> ] +; + +value mklistpat loc last = + loop True where rec loop top = + fun + [ [] -> + match last with + [ Some p -> p + | None -> <:patt< [] >> ] + | [p1 :: pl] -> + let loc = if top then loc else (fst (MLast.loc_of_patt p1), snd loc) in + <:patt< [$p1$ :: $loop False pl$] >> ] +; + +value expr_of_patt p = + let loc = MLast.loc_of_patt p in + match p with + [ <:patt< $lid:x$ >> -> <:expr< $lid:x$ >> + | _ -> Stdpp.raise_with_loc loc (Stream.Error "identifier expected") ] +; + +value apply_bind loc e bl = + let rec loop e = + fun + [ [] -> e + | [<:str_item< value $p1$ = $e1$ >> :: list] -> + loop_let e [(p1, e1)] list + | [<:str_item< value rec $p1$ = $e1$ >> :: list] -> + loop_letrec e [(p1, e1)] list + | [<:str_item< module $s$ = $me$ >> :: list] -> + let e = <:expr< let module $s$ = $me$ in $e$ >> in + loop e list + | [si :: list] -> + raise Exit ] + and loop_let e pel = + fun + [ [<:str_item< value $p1$ = $e1$ >> :: list] -> + loop_let e [(p1, e1) :: pel] list + | list -> + let e = <:expr< let $list:pel$ in $e$ >> in + loop e list ] + and loop_letrec e pel = + fun + [ [<:str_item< value rec $p1$ = $e1$ >> :: list] -> + loop_letrec e [(p1, e1) :: pel] list + | list -> + let e = <:expr< let rec $list:pel$ in $e$ >> in + loop e list ] + in + loop e (List.rev bl) +; + +value make_local loc sl1 sl2 = + try + let pl = + List.map + (fun + [ <:str_item< value $opt:_$ $p$ = $_$ >> -> p + | _ -> raise Exit ]) + sl2 + in + let e1 = + match List.map expr_of_patt pl with + [ [e] -> e + | el -> <:expr< ($list:el$) >> ] + in + let p1 = + match pl with + [ [p] -> p + | pl -> <:patt< ($list:pl$) >> ] + in + let e = apply_bind loc e1 sl2 in + let e = apply_bind loc e sl1 in + <:str_item< value $p1$ = $e$ >> + with + [ Exit -> + do { + Printf.eprintf "\ +*** Warning: a 'local' statement will be defined global because of bindings +which cannot be defined as first class values (modules, exceptions, ...)\n"; + flush stderr; + <:str_item< declare $list:sl1 @ sl2$ end >> + } ] +; + +value str_declare loc = + fun + [ [d] -> d + | dl -> <:str_item< declare $list:dl$ end >> ] +; + +value sig_declare loc = + fun + [ [d] -> d + | dl -> <:sig_item< declare $list:dl$ end >> ] +; + +value extract_label_types loc tn tal cdol = + let (cdl, aux) = + List.fold_right + (fun (loc, c, tl, aux_opt) (cdl, aux) -> + match aux_opt with + [ Some anon_record_type -> + let new_tn = tn ^ "_" ^ c in + let loc = MLast.loc_of_ctyp anon_record_type in + let aux_def = ((loc, new_tn), [], anon_record_type, []) in + let tl = [<:ctyp< $lid:new_tn$ >>] in + ([(loc, c, tl) :: cdl], [aux_def :: aux]) + | None -> ([(loc, c, tl) :: cdl], aux) ]) + cdol ([], []) + in + [((loc, tn), tal, <:ctyp< [ $list:cdl$ ] >>, []) :: aux] +; + +value function_of_clause_list loc xl = + let (fname, fname_loc, nbpat, l) = + List.fold_left + (fun (fname, fname_loc, nbpat, l) ((x1, loc), x2, x3, x4) -> + let (fname, fname_loc, nbpat) = + if fname = "" then (x1, loc, List.length x2) + else if x1 <> fname then + raise_with_loc loc + (Stream.Error ("'" ^ fname ^ "' expected")) + else if List.length x2 <> nbpat then + raise_with_loc loc + (Stream.Error "bad number of patterns in that clause") + else (fname, fname_loc, nbpat) + in + let x4 = + match x3 with + [ Some t -> <:expr< ($x4$ : $t$) >> + | _ -> x4 ] + in + let l = [(x2, x4) :: l] in + (fname, fname_loc, nbpat, l)) + ("", loc, 0, []) xl + in + let l = List.rev l in + let e = + match l with + [ [(pl, e)] -> + List.fold_right (fun p e -> <:expr< fun $p$ -> $e$ >>) pl e + | _ -> + if nbpat = 1 then + let pwel = + List.map + (fun (pl, e) -> (<:patt< $List.hd pl$ >>, None, e)) l + in + <:expr< fun [ $list:pwel$ ] >> + else + let sl = + loop 0 where rec loop n = + if n = nbpat then [] + else ["a" ^ string_of_int (n + 1) :: loop (n + 1)] + in + let e = + let el = List.map (fun s -> <:expr< $lid:s$ >>) sl in + let pwel = + List.map + (fun (pl, e) -> (<:patt< ($list:pl$) >>, None, e)) l + in + <:expr< match ($list:el$) with [ $list:pwel$ ] >> + in + List.fold_right (fun s e -> <:expr< fun $lid:s$ -> $e$ >>) sl e ] + in + (let loc = fname_loc in <:patt< $lid:fname$ >>, e) +; + +value record_expr loc x1 = + if ocaml_records.val then <:expr< { $list:x1$ } >> + else + let list1 = + List.map + (fun (l, v) -> + let id = + match l with + [ <:patt< $lid:l$ >> -> l + | _ -> "" ] + in + let loc = MLast.loc_of_expr v in + <:class_str_item< value $id$ = $v$ >>) + x1 + in + let list2 = + List.map + (fun (l, v) -> + let id = + match l with + [ <:patt< $lid:l$ >> -> l + | _ -> "" ] + in + let loc = MLast.loc_of_patt l in + <:class_str_item< method $id$ = $lid:id$ >>) + x1 + in + <:expr< + let module M = + struct + class a = object $list:list1 @ list2$ end; + end + in + new M.a + >> +; + +value record_match_assoc loc lpl e = + if ocaml_records.val then (<:patt< { $list:lpl$ } >>, e) + else + let pl = List.map (fun (_, p) -> p) lpl in + let e = + let el = + List.map + (fun (l, _) -> + let s = + match l with + [ <:patt< $lid:l$ >> -> l + | _ -> "" ] + in + let loc = MLast.loc_of_patt l in + <:expr< v # $lid:s$ >>) + lpl + in + let loc = MLast.loc_of_expr e in + <:expr< let v = $e$ in ($list:el$) >> + in + let p = <:patt< ($list:pl$) >> in + (p, e) +; + +value op = + Grammar.Entry.of_parser gram "op" + (parser [: `("", "op"); `(_, x) :] -> x) +; +lexer.Token.tok_using ("", "op"); + +value special x = + if String.length x >= 2 then + match x.[0] with + [ '+' | '<' | '^' -> True + | _ -> False ] + else False +; + +value idd = + let p = + parser + [ [: `("LIDENT", x) :] -> x + | [: `("UIDENT", x) :] -> x + | [: `("", "op"); `(_, x) :] -> x + | [: `("", x) when special x :] -> x ] + in + Grammar.Entry.of_parser Pcaml.gram "ID" p +; + +value uncap s = String.uncapitalize s; + +EXTEND + GLOBAL: implem interf top_phrase use_file sig_item str_item ctyp patt expr + module_type module_expr; + + implem: + [ [ x = interdec; EOI -> x ] ] + ; + interf: + [ [ x = LIST1 [ s = sig_item; OPT ";" -> (s, loc) ] -> (x, False) ] ] + ; + top_phrase: + [ [ ph = phrase; ";" -> Some ph + | EOI -> None ] ] + ; + use_file: + [ [ l = LIST0 phrase; EOI -> (l, False) ] ] + ; + phrase: + [ [ x = str_item -> x + | x = expr -> <:str_item< $exp:x$ >> + | "#"; n = LIDENT; dp = dir_param -> MLast.StDir loc n dp ] ] + ; + dir_param: + [ [ -> None + | e = expr -> Some e ] ] + ; + sdecs: + [ [ x = sdec; l = sdecs -> [x :: l] + | ";"; l = sdecs -> l + | -> [] ] ] + ; + + fsigb: [ [ -> not_impl loc "fsigb" ] ]; + fsigconstraint_op: [ [ -> not_impl loc "fsigconstraint_op" ] ]; + fct_exp: [ [ -> not_impl loc "fct_exp" ] ]; + exp_pa: [ [ -> not_impl loc "exp_pa" ] ]; + rvb: [ [ -> not_impl loc "rvb" ] ]; + tyvarseq: [ [ -> not_impl loc "tyvarseq" ] ]; + + tyvar_pc: + [ [ "'"; x1 = LIDENT -> [(x1, (False, False))] + | "'"; x1 = LIDENT; ","; l = tyvar_pc -> [(x1, (False, False)) :: l] ] ] + ; + id: + [ [ x1 = idd -> x1 + | "*" -> "*" ] ] + ; + ident: + [ [ x1 = idd -> x1 + | "*" -> "*" + | "=" -> "=" + | "<" -> "<" + | ">" -> ">" + | "<=" -> "<=" + | ">=" -> ">=" + | "^" -> "^" ] ] + ; + op_op: + [ [ x1 = op -> not_impl loc "op_op 1" + | -> () ] ] + ; + qid: + [ [ x1 = idd; "."; x2 = qid -> <:module_expr< $uid:x1$ . $x2$ >> + | x1 = idd -> <:module_expr< $uid:x1$ >> + | x1 = "*" -> <:module_expr< $uid:x1$ >> + | x1 = "=" -> <:module_expr< $uid:x1$ >> ] ] + ; + eqid: + [ [ x1 = UIDENT; "."; x2 = eqid -> <:expr< $uid:x1$ . $x2$ >> + | x1 = UIDENT -> <:expr< $uid:x1$ >> + | x1 = idd -> <:expr< $lid:x1$ >> + | x1 = "*" -> <:expr< $lid:x1$ >> + | x1 = "=" -> <:expr< $lid:x1$ >> ] ] + ; + sqid: + [ [ x1 = idd; "."; x2 = sqid -> [x1 :: x2] + | x1 = idd -> [x1] + | x1 = "*" -> [x1] + | x1 = "=" -> [x1] ] ] + ; + tycon: + [ [ LIDENT "real" -> <:ctyp< float >> + | x1 = idd; "."; x2 = tycon -> + let r = <:ctyp< $uid:x1$ . $x2$ >> in + loop r where rec loop = + fun + [ <:ctyp< $a$ . ($b$ . $c$) >> -> <:ctyp< $a$ . $b$ . $loop c$ >> + | x -> x ] + | x1 = idd -> <:ctyp< $lid:uncap x1$ >> ] ] + ; + selector: + [ [ x1 = id -> x1 + | x1 = INT -> not_impl loc "selector 1" ] ] + ; + tlabel: + [ [ x1 = selector; ":"; x2 = ctyp -> (loc, x1, False, x2) ] ] + ; + tuple_ty: + [ [ x1 = ctyp LEVEL "ty'"; "*"; x2 = tuple_ty -> [x1 :: x2] + | x1 = ctyp LEVEL "ty'" -> [x1] ] ] + ; + ctyp: + [ RIGHTA + [ x1 = ctyp; "->"; x2 = ctyp -> <:ctyp< $x1$ -> $x2$ >> ] + | [ x1 = ctyp; "*"; x2 = tuple_ty -> <:ctyp< ($list:[x1 :: x2]$) >> ] + | "ty'" + [ "'"; x1 = LIDENT -> <:ctyp< '$x1$ >> + | "'"; "'"; x1 = LIDENT -> <:ctyp< '$x1$ >> + | "{"; x1 = LIST1 tlabel SEP ","; "}" -> + if ocaml_records.val then <:ctyp< { $list:x1$ } >> + else + let list = List.map (fun (_, l, _, t) -> (l, t)) x1 in + <:ctyp< < $list:list$ > >> + | "{"; "}" -> not_impl loc "ty' 3" + | "("; x1 = ctyp; ","; x2 = LIST1 ctyp SEP ","; ")"; x3 = tycon -> + List.fold_left (fun t1 t2 -> <:ctyp< $t1$ $t2$ >>) x3 [x1 :: x2] + | "("; x1 = ctyp; ")" -> x1 + | x1 = ctyp; x2 = tycon -> <:ctyp< $x2$ $x1$ >> + | x1 = tycon -> x1 ] ] + ; + rule: + [ [ x1 = patt; "=>"; x2 = expr -> (x1, None, x2) ] ] + ; + elabel: + [ [ x1 = selector; "="; x2 = expr -> (<:patt< $lid:x1$ >>, x2) ] ] + ; + exp_ps: + [ [ x1 = expr -> x1 + | x1 = expr; ";"; x2 = exp_ps -> + <:expr< do { $list:[x1 :: get_seq x2]$ } >> ] ] + ; + expr: + [ [ "if"; x1 = expr; "then"; x2 = expr; "else"; x3 = expr -> + <:expr< if $x1$ then $x2$ else $x3$ >> + | "fn"; x1 = LIST1 rule SEP "|" -> <:expr< fun [$list:x1$] >> + | "case"; x1 = expr; "of"; x2 = LIST1 rule SEP "|" -> + <:expr< match $x1$ with [$list:x2$] >> + | "while"; x1 = expr; "do"; x2 = expr -> + <:expr< while $x1$ do { $x2$ } >> + | x1 = expr; "handle"; x2 = LIST1 rule SEP "|" -> + <:expr< try $x1$ with [$list:x2$] >> ] + | RIGHTA + [ "raise"; x1 = expr -> <:expr< raise $x1$ >> ] + | [ e1 = expr; ":="; e2 = expr -> <:expr< $e1$.val := $e2$ >> ] + | LEFTA + [ x1 = expr; "orelse"; x2 = expr -> <:expr< $x1$ || $x2$ >> ] + | LEFTA + [ x1 = expr; "andalso"; x2 = expr -> <:expr< $x1$ && $x2$ >> ] + | LEFTA + [ x1 = expr; ":"; x2 = ctyp -> <:expr< ($x1$ : $x2$) >> ] + | "4" NONA + [ x1 = expr; "<"; x2 = expr -> <:expr< $x1$ < $x2$ >> + | x1 = expr; ">"; x2 = expr -> <:expr< $x1$ > $x2$ >> + | x1 = expr; "<>"; x2 = expr -> <:expr< $x1$ <> $x2$ >> + | x1 = expr; "="; x2 = expr -> <:expr< $x1$ = $x2$ >> + | x1 = expr; ">="; x2 = expr -> <:expr< $x1$ >= $x2$ >> + | x1 = expr; "<="; x2 = expr -> <:expr< $x1$ <= $x2$ >> ] + | RIGHTA + [ x1 = expr; "^"; x2 = expr -> <:expr< $x1$ ^ $x2$ >> + | x1 = expr; "@"; x2 = expr -> <:expr< $x1$ @ $x2$ >> + | x1 = expr; "o"; x2 = expr -> <:expr< ooo $x1$ $x2$ >> ] + | "5" RIGHTA + [ x1 = expr; "::"; x2 = expr -> <:expr< [$x1$ :: $x2$] >> ] + | "6" LEFTA + [ x1 = expr; "+"; x2 = expr -> <:expr< $x1$ + $x2$ >> + | x1 = expr; "-"; x2 = expr -> <:expr< $x1$ - $x2$ >> ] + | "7" LEFTA + [ x1 = expr; "*"; x2 = expr -> <:expr< $x1$ * $x2$ >> + | x1 = expr; "/"; x2 = expr -> <:expr< $x1$ / $x2$ >> + | x1 = expr; "div"; x2 = expr -> <:expr< $x1$ / $x2$ >> + | x1 = expr; "mod"; x2 = expr -> <:expr< $x1$ mod $x2$ >> ] + | LEFTA + [ x1 = expr; x2 = expr -> <:expr< $x1$ $x2$ >> ] + | [ "#"; x1 = STRING -> <:expr< $chr:x1$ >> + | "#"; x1 = selector; x2 = expr -> + if ocaml_records.val then <:expr< $x2$ . $lid:x1$ >> + else <:expr< $x2$ # $lid:x1$ >> + | x1 = expr; "ocaml_record_access"; x2 = expr -> <:expr< $x1$ . $x2$ >> ] + | [ "!"; x1 = expr -> <:expr< $x1$ . val >> + | "~"; x1 = expr -> <:expr< - $x1$ >> ] + | [ x1 = LIDENT -> + match x1 with + [ "true" | "false" -> <:expr< $uid:String.capitalize x1$ >> + | "nil" -> <:expr< [] >> + | _ -> <:expr< $lid:x1$ >> ] + | x1 = UIDENT -> <:expr< $uid:x1$ >> + | x1 = UIDENT; "."; x2 = eqid -> <:expr< $uid:x1$ . $x2$ >> + | x1 = INT -> <:expr< $int:x1$ >> + | x1 = FLOAT -> <:expr< $flo:x1$ >> + | x1 = STRING -> <:expr< $str:x1$ >> + | "~"; x1 = INT -> <:expr< $int:"-"^x1$ >> + | i = op -> + if i = "::" then <:expr< fun (x, y) -> [x :: y] >> + else <:expr< fun (x, y) -> $lid:i$ x y >> + | "let"; x1 = ldecs; "in"; x2 = exp_ps; "end" -> + List.fold_right + (fun pel x2 -> + let loc = + match pel with + [ [(p, _) :: _] -> + (fst (MLast.loc_of_patt p), snd (MLast.loc_of_expr x2)) + | _ -> loc ] + in + match pel with + [ [(_, <:expr< fun [$list:_$] >>) :: _] -> + <:expr< let rec $list:pel$ in $x2$ >> + | _ -> + let pel = + List.map + (fun (p, e) -> + match p with + [ <:patt< { $list:lpl$ } >> -> + record_match_assoc (MLast.loc_of_patt p) lpl e + | _ -> (p, e) ]) + pel + in + <:expr< let $list:pel$ in $x2$ >> ]) + x1 x2 + | "{"; x1 = LIST1 elabel SEP ","; "}" -> record_expr loc x1 + | "["; "]" -> <:expr< [] >> + | "["; x1 = expr; "]" -> <:expr< [$x1$] >> + | "["; x1 = expr; ","; x2 = LIST1 SELF SEP ","; "]" -> + mklistexp loc None [x1 :: x2] + | "("; ")" -> <:expr< () >> + | "("; x1 = expr; ","; x2 = LIST1 SELF SEP ","; ")" -> + <:expr< ($list:[x1::x2]$) >> + | "("; x1 = expr; ";"; x2 = LIST1 SELF SEP ";"; ")" -> + <:expr< do { $list:[x1::x2]$ } >> + | "("; x1 = expr; ")" -> x1 ] ] + ; + fixity: + [ [ "infix" -> ("infix", None) + | "infix"; x1 = INT -> not_impl loc "fixity 2" + | "infixr" -> not_impl loc "fixity 3" + | "infixr"; x1 = INT -> ("infixr", Some x1) + | "nonfix" -> not_impl loc "fixity 5" ] ] + ; + patt: + [ [ x1 = patt; "as"; x2 = patt -> <:patt< ($x1$ as $x2$) >> ] + | LEFTA + [ x1 = patt; ":"; x2 = ctyp -> <:patt< ($x1$ : $x2$) >> ] + | RIGHTA + [ x1 = patt; "::"; x2 = patt -> <:patt< [$x1$ :: $x2$] >> ] + | [ x1 = patt; x2 = patt -> + match x1 with + [ <:patt< ref >> -> <:patt< {contents = $x2$} >> + | _ -> <:patt< $x1$ $x2$ >> ] ] + | "apat" + [ x1 = patt; "."; x2 = patt -> <:patt< $x1$ . $x2$ >> + | x1 = INT -> <:patt< $int:x1$ >> + | x1 = UIDENT -> <:patt< $uid:x1$ >> + | x1 = STRING -> <:patt< $str:x1$ >> + | "#"; x1 = STRING -> <:patt< $chr:x1$ >> + | "~"; x1 = INT -> <:patt< $int:"-"^x1$ >> + | LIDENT "nil" -> <:patt< [] >> + | LIDENT "false" -> <:patt< False >> + | LIDENT "true" -> <:patt< True >> + | x1 = id -> <:patt< $lid:x1$ >> + | x1 = op -> <:patt< $lid:x1$ >> + | "_" -> <:patt< _ >> + | "["; "]" -> <:patt< [] >> + | "["; x1 = patt; "]" -> <:patt< [$x1$] >> + | "["; x1 = patt; ","; x2 = LIST1 SELF SEP ","; "]" -> + mklistpat loc None [x1 :: x2] + | "{"; x1 = LIST1 plabel SEP ","; "}" -> <:patt< {$list:x1$} >> + | "("; ")" -> <:patt< () >> + | "("; x1 = patt; ","; x2 = LIST1 SELF SEP ","; ")" -> + <:patt< ($list:[x1::x2]$) >> + | "("; x1 = patt; ")" -> x1 ] ] + ; + plabel: + [ [ x1 = selector; "="; x2 = patt -> (<:patt< $lid:x1$ >>, x2) + | x1 = selector -> (<:patt< $lid:x1$ >>, <:patt< $lid:x1$ >>) ] ] + ; + vb: + [ [ "lazy"; x1 = patt; "="; x2 = expr -> not_impl loc "vb 1" + | x1 = patt; "="; x2 = expr -> (x1, x2) ] ] + ; + constrain: + [ [ -> None + | ":"; x1 = ctyp -> Some x1 ] ] + ; + fb: + [ [ xl = LIST1 clause SEP "|" -> function_of_clause_list loc xl + | "lazy"; x1 = LIST1 clause SEP "|" -> not_impl loc "fb 2" ] ] + ; + clause: + [ [ x1 = patt LEVEL "apat"; x2 = LIST1 (patt LEVEL "apat"); + x3 = constrain; "="; x4 = expr -> + let x1 = + match x1 with + [ <:patt< $lid:id$ >> -> (id, MLast.loc_of_patt x1) + | _ -> not_impl loc "clause 1" ] + in + (x1, x2, x3, x4) ] ] + ; + tb: + [ [ x1 = tyvars; x2 = idd; "="; x3 = ctyp -> + ((loc, uncap x2), x1, x3, []) + | x1 = tyvars; x2 = idd; "="; x3 = ctyp; "=="; x4 = dbrhs -> + let x4 = List.map (fun (loc, c, tl, _) -> (loc, c, tl)) x4 in + ((loc, uncap x2), x1, <:ctyp< $x3$ == [ $list:x4$ ] >>, []) ] ] + ; + tyvars: + [ [ "'"; x1 = LIDENT -> [(x1, (False, False))] + | "("; x1 = tyvar_pc; ")" -> x1 + | -> [] ] ] + ; + db1: + [ [ x1 = tyvars; x2 = ident; "="; x3 = dbrhs -> + let x2 = uncap x2 in + extract_label_types loc x2 x1 x3 + | "lazy"; x1 = tyvars; x2 = ident; "="; x3 = dbrhs -> + not_impl loc "db 2" ] ] + ; + db: + [ [ x1 = LIST1 db1 SEP "and" -> + List.fold_right (fun td tdl -> td @ tdl) x1 [] ] ] + ; + dbrhs: + [ [ x1 = LIST1 constr SEP "|" -> x1 + | "datatype"; x1 = tycon -> not_impl loc "dbrhs 2" ] ] + ; + constr: + [ [ x1 = op_op; x2 = ident -> (loc, x2, [], None) + | x1 = op_op; x2 = ident; "of"; x3 = ctyp -> + match x3 with + [ <:ctyp< {$list:_$} >> -> (loc, x2, [], Some x3) + | _ -> (loc, x2, [x3], None) ] ] ] + ; + eb: + [ [ x1 = op_op; x2 = ident -> (x2, [], []) + | x1 = op_op; x2 = ident; "of"; x3 = ctyp -> (x2, [x3], []) + | x1 = op_op; x2 = ident; "="; x3 = sqid -> (x2, [], x3) ] ] + ; + ldec1: + [ [ "val"; x1 = LIST1 vb SEP "and" -> x1 + | "fun"; x1 = LIST1 fb SEP "and" -> x1 ] ] + ; + ldecs: + [ [ -> [] + | x1 = ldec1; x2 = ldecs -> [x1 :: x2] + | ";"; x1 = ldecs -> x1 + | "local"; x1 = ldecs; "in"; x2 = ldecs; "end"; x3 = ldecs -> + not_impl loc "ldecs 4" ] ] + ; + spec_s: + [ [ -> [] + | x1 = spec; x2 = spec_s -> [x1 :: x2] + | ";"; x1 = spec_s -> x1 ] ] + ; + spec: + [ [ "structure"; x1 = LIST1 strspec SEP "and" -> sig_declare loc x1 + | "functor"; x1 = LIST1 fctspec SEP "and" -> sig_declare loc x1 + | "datatype"; x1 = db -> <:sig_item< type $list:x1$ >> + | "type"; x1 = LIST1 tyspec SEP "and" -> <:sig_item< type $list:x1$ >> + | "eqtype"; x1 = LIST1 tyspec SEP "and" -> <:sig_item< type $list:x1$ >> + | "val"; x1 = LIST1 valspec SEP "and" -> sig_declare loc x1 + | "exception"; x1 = LIST1 exnspec SEP "and" -> sig_declare loc x1 + | "sharing"; x1 = LIST1 sharespec SEP "and" -> <:sig_item< declare end >> + | "include"; x1 = module_type -> <:sig_item< include $x1$ >> ] ] + ; + sig_item: + [ [ x = spec -> x ] ] + ; + strspec: + [ [ x1 = ident; ":"; x2 = module_type; x3 = LIST0 sharing_def -> + let x2 = + List.fold_left + (fun mt sdl -> + List.fold_right + (fun spl mt -> + match spl with + [ Right ([m1], m2) -> + let (m1, m2) = + match m2 with + [ <:module_expr< $uid:x$ . $_$ >> -> + if x = x1 then (m2, m1) else (m1, m2) + | _ -> (m1, m2) ] + in + let m1 = + loop m1 where rec loop = + fun + [ <:module_expr< $uid:x$ >> -> x + | <:module_expr< $uid:x$ . $y$ >> -> loop y + | _ -> not_impl loc "strspec 2" ] + in + <:module_type< $mt$ with module $[m1]$ = $m2$ >> + | _ -> not_impl loc "strspec 1" ]) + sdl mt) + x2 x3 + in + <:sig_item< module $x1$ : $x2$ >> ] ] + ; + sharing_def: + [ [ "sharing"; x3 = LIST1 sharespec SEP "and" -> x3 ] ] + ; + fctspec: + [ [ x1 = ident; x2 = fsig -> <:sig_item< module $x1$ : $x2$ >> ] ] + ; + tyspec: + [ [ x1 = tyvars; x2 = idd -> + ((loc, uncap x2), x1, <:ctyp< '$choose_tvar x1$ >>, []) + | x1 = tyvars; x2 = idd; "="; x3 = ctyp -> + ((loc, uncap x2), x1, x3, []) ] ] + ; + valspec: + [ [ x1 = op_op; x2 = ident; ":"; x3 = ctyp -> + <:sig_item< value $x2$ : $x3$ >> ] ] + ; + exnspec: + [ [ x1 = ident -> <:sig_item< exception $x1$ >> + | x1 = ident; "of"; x2 = ctyp -> + <:sig_item< exception $x1$ of $x2$ >> ] ] + ; + sharespec: + [ [ "type"; x1 = patheqn -> Left x1 + | x1 = patheqn -> Right x1 ] ] + ; + patheqn: + [ [ l = patheqn1 -> l ] ] + ; + patheqn1: + [ [ (l, y) = patheqn1; "="; x = qid -> ([y :: l], x) + | x = qid -> ([], x) ] ] + ; + whspec: + [ [ "type"; x1 = tyvars; x2 = sqid; "="; x3 = ctyp -> + MLast.WcTyp loc x2 x1 x3 + | x1 = sqid; "="; x2 = qid -> MLast.WcMod loc x1 x2 ] ] + ; + module_type: + [ [ x1 = ident -> <:module_type< $uid:x1$ >> + | "sig"; x1 = spec_s; "end" -> <:module_type< sig $list:x1$ end >> + | x1 = module_type; "where"; x2 = LIST1 whspec SEP "and" -> + <:module_type< $x1$ with $list:x2$ >> ] ] + ; + sigconstraint_op: + [ [ -> None + | ":"; x1 = module_type -> Some x1 + | ":>"; x1 = module_type -> not_impl loc "sigconstraint_op 3" ] ] + ; + sigb: + [ [ x1 = ident; "="; x2 = module_type -> + <:str_item< module type $x1$ = $x2$ >> ] ] + ; + fsig: + [ [ ":"; x1 = ident -> not_impl loc "fsig 1" + | x1 = fparamList; ":"; x2 = module_type -> not_impl loc "fsig 2" ] ] + ; + module_expr: + [ [ x1 = qid -> x1 + | "struct"; x1 = strdecs; "end" -> <:module_expr< struct $list:x1$ end >> + | x1 = qid; x2 = arg_fct -> + match x2 with + [ Left [] -> x1 + | Left x2 -> <:module_expr< $x1$ (struct $list:x2$ end) >> + | Right x2 -> <:module_expr< $x1$ $x2$ >> ] + | "let"; x1 = strdecs; "in"; x2 = module_expr; "end" -> + not_impl loc "str 4" + | x1 = module_expr; ":"; x2 = module_type -> not_impl loc "str 5" + | x1 = module_expr; x2 = ":>"; x3 = module_type -> + not_impl loc "str 6" ] ] + ; + arg_fct: + [ [ "("; x1 = strdecs; ")"; x2 = arg_fct -> not_impl loc "arg_fct 1" + | "("; x1 = module_expr; ")"; x2 = arg_fct -> not_impl loc "arg_fct 2" + | "("; x1 = module_expr; ")" -> Right x1 + | "("; x2 = strdecs; ")" -> Left x2 ] ] + ; + strdecs: + [ [ x1 = str_item LEVEL "strdec"; x2 = strdecs -> [x1 :: x2] + | ";"; x1 = strdecs -> x1 + | -> [] ] ] + ; + str_item: + [ [ "signature"; x1 = LIST1 sigb SEP "and" -> str_declare loc x1 + | "funsig"; x1 = fsigb -> not_impl loc "sdec 3" ] + | "strdec" + [ "structure"; x1 = LIST1 strb SEP "and" -> str_declare loc x1 + | "functor"; x1 = LIST1 fctb SEP "and" -> str_declare loc x1 + | "local"; x1 = sdecs; "in"; x2 = sdecs; "end" -> + make_local loc x1 x2 ] + | [ "val"; x1 = LIST1 vb SEP "and" -> <:str_item< value $list:x1$ >> + | "val"; x1 = tyvarseq; x3 = LIST1 vb SEP "and" -> + not_impl loc "ldec 2" + | "val"; "rec"; x1 = rvb -> not_impl loc "ldec 3" + | "val"; "rec"; x1 = tyvarseq; x2 = rvb -> not_impl loc "ldec 4" + | "fun"; x1 = LIST1 fb SEP "and" -> <:str_item< value rec $list:x1$ >> + | "fun"; x1 = tyvarseq; x2 = fb -> not_impl loc "ldec 6" + | "type"; x1 = LIST1 tb SEP "and" -> <:str_item< type $list:x1$ >> + | "datatype"; x1 = db -> <:str_item< type $list:x1$ >> + | "datatype"; x1 = db; "withtype"; x2 = tb -> + <:str_item< type $list:x1 @ [x2]$ >> + | "abstype"; x1 = db; "with"; x2 = ldecs; "end" -> not_impl loc "ldec 10" + | "abstype"; x1 = db; "withtype"; x2 = tb; "with"; x3 = ldecs; "end" -> + not_impl loc "ldec 11" + | "exception"; x1 = LIST1 eb SEP "and" -> + let dl = + List.map + (fun (s, tl, eqn) -> + <:str_item< exception $s$ of $list:tl$ = $eqn$ >>) + x1 + in + str_declare loc dl + | "open"; x1 = LIST1 sqid -> + let dl = List.map (fun sl -> <:str_item< open $sl$ >>) x1 in + str_declare loc dl + | LIDENT "use"; s = STRING -> + <:str_item< #use $str:s$ >> + | x1 = fixity; list = LIST1 idd -> + match x1 with + [ ("infixr", Some n) -> + do { + List.iter + (fun s -> + EXTEND + expr: LEVEL $n$ + [ [ x1 = expr; $s$; x2 = expr -> + <:expr< $lid:s$ ($x1$, $x2$) >> ] ] + ; + END) + list; + str_declare loc [] + } + | ("infix", None) -> + do { + List.iter + (fun s -> + EXTEND + expr: LEVEL "4" + [ [ x1 = expr; $s$; x2 = expr -> + <:expr< $lid:s$ ($x1$, $x2$) >> ] ] + ; + clause: + [ [ x1 = patt LEVEL "apat"; $s$; + x2 = patt LEVEL "apat"; "="; x4 = expr -> + ((s, loc), [<:patt< ($x1$, $x2$) >>], + None, x4) ] ] + ; + END) + list; + str_declare loc [] + } + | _ -> not_impl loc "ldec 14" ] + | "overload"; x1 = ident; ":"; x2 = ctyp; "as"; x3 = exp_pa -> + not_impl loc "ldec 15" + | x = expr -> <:str_item< $exp:x$ >> ] ] + ; + sdec: + [ [ x = str_item -> x ] ] + ; + strb: + [ [ x1 = ident; x2 = sigconstraint_op; "="; x3 = module_expr -> + let x3 = + match x2 with + [ Some x2 -> <:module_expr< ($x3$ : $x2$) >> + | None -> x3 ] + in + <:str_item< module $x1$ = $x3$ >> ] ] + ; + fparam: + [ [ x1 = idd; ":"; x2 = module_type -> [<:sig_item< module $x1$ : $x2$ >>] + | x1 = spec_s -> x1 ] ] + ; + fparamList: + [ [ "("; x1 = fparam; ")" -> [x1] + | "("; x1 = fparam; ")"; x2 = fparamList -> [x1 :: x2] ] ] + ; + fctb: + [ [ x1 = ident; x2 = fparamList; x3 = sigconstraint_op; "="; + x4 = module_expr -> + let list = List.flatten x2 in + let x4 = + if list = [] then x4 + else + match x4 with + [ <:module_expr< struct $list:list$ end >> -> + let si = + let loc = (Token.nowhere, Token.nowhere) in + <:str_item< open AAA >> in + <:module_expr< struct $list:[si :: list]$ end >> + | _ -> not_impl loc "fctb 1" ] + in + let x4 = + match x3 with + [ Some x3 -> <:module_expr< ($x4$ : $x3$) >> + | None -> x4 ] + in + let x4 = + if list = [] then x4 + else + let mt = + let loc = + (fst (MLast.loc_of_sig_item (List.hd list)), + snd (MLast.loc_of_sig_item (List.hd (List.rev list)))) + in + <:module_type< sig $list:list$ end >> + in + <:module_expr< functor (AAA : $mt$) -> $x4$ >> + in + <:str_item< module $x1$ = $x4$ >> + | x1 = ident; x2 = fsigconstraint_op; "="; x3 = fct_exp -> + not_impl loc "fctb 2" ] ] + ; + interdec: + [ [ x = LIST1 [ s = str_item; OPT ";" -> (s, loc) ] -> (x, False) + | x = expr; OPT ";" -> not_impl loc "interdec 2" ] ] + ; +END; + +Pcaml.add_option "-records" (Arg.Set ocaml_records) + "Convert record into OCaml records, instead of objects"; diff --git a/camlp4/unmaintained/sml/smllib.sml b/camlp4/unmaintained/sml/smllib.sml new file mode 100644 index 0000000..5ecd093 --- /dev/null +++ b/camlp4/unmaintained/sml/smllib.sml @@ -0,0 +1,395 @@ +(***********************************************************************) +(* *) +(* Camlp4 *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* Automatique. Distributed only by permission. *) +(* *) +(***********************************************************************) + + + +datatype 'a option = SOME of 'a | NONE +exception Fail of string +exception Domain +exception Subscript +type 'a vector = 'a array + +structure OCaml = + struct + structure List = List + structure String = String + end + +structure Time = + struct + datatype time = TIME of { sec : int, usec : int } + fun toString _ = failwith "not implemented Time.toString" + fun now _ = failwith "not implemented Time.now" + end + +datatype cpu_timer = + CPUT of { gc : Time.time, sys : Time.time, usr : Time.time } + +datatype real_timer = + RealT of Time.time + +structure Char = + struct + val ord = Char.code + end + +structure General = + struct + datatype order = LESS | EQUAL | GREATER + end +type order = General.order == LESS | EQUAL | GREATER + +structure OS = + struct + exception SysErr + structure Path = + struct + fun dir s = + let val r = Filename.dirname s in + if r = "." then "" else r + end + val file = Filename.basename + fun ext s = + let fun loop i = + if i < 0 then NONE + else if String.get s i = #"." then + let val len = String.length s - i - 1 in + if len = 0 then NONE else SOME (String.sub s (i + 1) len) + end + else loop (i - 1) + in + loop (String.length s - 1) + end + fun splitDirFile s = + {dir = Filename.dirname s, + file = Filename.basename s} + fun joinDirFile x = + let val {dir,file} = x in Filename.concat dir file end + end + structure FileSys = + struct + datatype access_mode = A_READ | A_WRITE | A_EXEC + val chDir = Sys.chdir + fun isDir s = + (Unix.stat s) ocaml_record_access Unix.st_kind = Unix.S_DIR + handle Unix.Unix_error _ => raise SysErr + fun access (s, accs) = + let val st = Unix.stat s + val prm = st ocaml_record_access Unix.st_perm + val prm = + if st ocaml_record_access Unix.st_uid = Unix.getuid () then + lsr prm 6 + else if st ocaml_record_access Unix.st_uid = Unix.getgid () + then + lsr prm 3 + else prm + val rf = + if List.mem A_READ accs then land prm 4 <> 0 else true + val wf = + if List.mem A_WRITE accs then land prm 2 <> 0 else true + val xf = + if List.mem A_EXEC accs then land prm 1 <> 0 else true + in + rf andalso wf andalso xf + end + handle Unix.Unix_error (_, f, _) => + if f = "stat" then false else raise SysErr + end + structure Process = + struct + fun system s = (flush stdout; flush stderr; Sys.command s) + fun getEnv s = SOME (Sys.getenv s) handle Not_found => NONE + val success = 0 + end + end + +exception SysErr = OS.SysErr + +structure IO = + struct + exception Io of {cause:exn, function:string, name:string} + end + +structure TextIO = + struct + type instream = in_channel * char option option ref + type outstream = out_channel + type elem = char + type vector = string + fun openIn fname = + (open_in fname, ref NONE) handle exn => + raise IO.Io {cause = exn, function = "openIn", name = fname} + val openOut = open_out + fun closeIn (ic, ahc) = (ahc := SOME NONE; close_in ic) + val closeOut = close_out + val stdIn = (stdin, ref (NONE : char option option)) + fun endOfStream (ic, _) = pos_in ic = in_channel_length ic + fun inputLine (ic, ahc) = + case !ahc of + NONE => + (input_line ic ^ "\n" handle End_of_file => (ahc := SOME NONE; "")) + | SOME NONE => "" + | SOME (SOME c) => + (ahc := NONE; + if c = #"\n" then "\n" + else + String.make 1 c ^ input_line ic ^ "\n" handle + End_of_file => (ahc := SOME NONE; "")) + fun input1 (ic, ahc) = + case !ahc of + NONE => + (SOME (input_char ic) handle End_of_file => (ahc := SOME NONE; NONE)) + | SOME NONE => NONE + | SOME x => (ahc := NONE; x) + fun inputN (ins, n) = + let fun loop n = + if n <= 0 then "" + else + case input1 ins of + SOME c => String.make 1 c ^ loop (n - 1) + | NONE => "" + in + loop n + end + fun output (oc, v) = output_string oc v + fun inputAll ic = failwith "not implemented TextIO.inputAll" + fun lookahead (ic, ahc) = + case !ahc of + NONE => let val r = SOME (input_char ic) in ahc := SOME r; r end + | SOME x => x + fun print s = (print_string s; flush stdout) + end + +structure Timer = + struct + fun startRealTimer () = failwith "not implemented Timer.startRealTimer" + fun startCPUTimer () = failwith "not implemented Timer.startCPUTimer" + fun checkRealTimer _ = failwith "not implemented Timer.checkRealTimer" + fun checkCPUTimer _ = failwith "not implemented Timer.checkCPUTimer" + end + +structure Date = + struct + datatype month = + Jan | Feb | Mar | Apr | May | Jun | Jul | Sep | Oct | Nov | Dec + datatype wday = Sun | Mon | Tue | Wed | Thu | Fri | Sat + datatype date = + DATE of + {day : int, hour : int, isDst : bool option, minute : int, + month : month, offset : int option, second : int, wday : wday, + yday : int, year : int} + fun fmt _ _ = failwith "not implemented Date.fmt" + fun fromTimeLocal _ = failwith "not implemented Date.fromTimeLocal" + end + +structure Posix = + struct + structure ProcEnv = + struct + fun getenv s = SOME (Sys.getenv s) handle Not_found => NONE + end + end + +structure SMLofNJ = + struct + fun exportML s = failwith ("not implemented exportML " ^ s) + end + +fun null x = x = [] +fun explode s = + let fun loop i = + if i = String.length s then [] + else String.get s i :: loop (i + 1) + in + loop 0 + end + +val app = List.iter +fun implode [] = "" + | implode (c :: l) = String.make 1 c ^ implode l + +fun ooo f g x = f (g x) + +structure Array = + struct + fun array (len, v) = Array.create len v + fun sub _ = failwith "not implemented Array.sub" + fun update _ = failwith "not implemented Array.update" + (* for make the profiler work *) + val set = Array.set + val get = Array.get + end + +structure Vector = + struct + fun tabulate _ = failwith "not implemented Vector.tabulate" + fun sub _ = failwith "not implemented Vector.sub" + end + +structure Bool = + struct + val toString = string_of_bool + end + +structure String = + struct + val size = String.length + fun substring (s, beg, len) = + String.sub s beg len handle Invalid_argument _ => raise Subscript + val concat = String.concat "" + fun sub (s, i) = String.get s i + val str = String.make 1 + fun compare (s1, s2) = + if s1 < s2 then LESS + else if s1 > s2 then GREATER + else EQUAL + fun isPrefix s1 s2 = + let fun loop i1 i2 = + if i1 >= String.length s1 then true + else if i2 >= String.length s2 then false + else if String.get s1 i1 = String.get s2 i2 then loop (i1 + 1) (i2 + 1) + else false + in + loop 0 0 + end + fun tokens p s = + let fun loop tok i = + if i >= String.length s then + if tok = "" then [] else [tok] + else if p (String.get s i) then + if tok <> "" then tok :: loop "" (i + 1) + else loop "" (i + 1) + else loop (tok ^ String.make 1 (String.get s i)) (i + 1) + in + loop "" 0 + end + fun extract _ = failwith "not implemented String.extract" + end + +structure Substring = + struct + type substring = string * int * int + fun string (s : substring) = String.substring s + fun all s : substring = (s, 0, String.size s) + fun splitl f ((s, beg, len) : substring) : substring * substring = + let fun loop di = + if di = len then ((s, beg, len), (s, 0, 0)) + else if f (String.sub (s, beg + di)) then loop (di + 1) + else ((s, beg, di), (s, beg + di, len - di)) + in + loop 0 + end + fun getc (s, i, len) = + if len > 0 andalso i < String.size s then + SOME (String.sub (s, i), (s, i+1, len-1)) + else NONE + fun slice _ = failwith "not implemented: Substring.slice" + fun isEmpty (s, beg, len) = len = 0 + fun concat sl = String.concat (List.map string sl) + end +type substring = Substring.substring + +structure StringCvt = + struct + datatype radix = BIN | OCT | DEC | HEX + type ('a, 'b) reader = 'b -> ('a * 'b) option + end + +structure ListPair = + struct + fun zip (a1::l1, a2::l2) = (a1, a2) :: zip (l1, l2) + | zip _ = [] + val unzip = List.split + fun all f (x1 :: l1, x2 :: l2) = f (x1, x2) andalso all f (l1, l2) + | all _ _ = true + fun map f (a1::l1, a2::l2) = + let val r = f (a1, a2) in r :: map f (l1, l2) end + | map _ _ = [] + end + +structure ListMergeSort = + struct + fun uniqueSort cmp l = + List.sort + (fn x => fn y => + case cmp (x, y) of + LESS => ~1 + | EQUAL => 0 + | GREATER => 1) + l + end + +structure List = + struct + exception Empty + fun hd [] = raise Empty + | hd (x :: l) = x + fun tl [] = raise Empty + | tl (x :: l) = l + fun foldr f a l = + let fun loop a [] = a + | loop a (x :: l) = loop (f (x, a)) l + in + loop a (List.rev l) + end + fun foldl f a l = List.fold_left (fn a => fn x => f (x, a)) a l + val concat = List.flatten + val exists = List.exists + val filter = List.filter + val length = List.length + val map = List.map + val rev = List.rev + val all = List.for_all + fun find f [] = NONE + | find f (x :: l) = if f x then SOME x else find f l + fun last s = + case List.rev s of + [] => raise Empty + | x :: _ => x + fun take _ = failwith "not implemented: List.take" + fun partition _ = failwith "not implemented: List.partition" + fun mapPartial f [] = [] + | mapPartial f (x :: l) = + case f x of + NONE => mapPartial f l + | SOME y => y :: mapPartial f l + fun op @ l1 l2 = List.rev_append (List.rev l1) l2 + end + +structure Int = + struct + type int1 = int + type int = int1 + val toString = string_of_int + fun fromString s = SOME (int_of_string s) handle Failure _ => NONE + fun min (x, y) = if x < y then x else y + fun max (x, y) = if x > y then x else y + fun scan radix getc src = failwith "not impl: Int.scan" + end + +val foldr = List.foldr +val exists = List.exists +val size = String.size +val substring = String.substring +val concat = String.concat +val length = List.length +val op @ = List.op @ +val hd = List.hd +val tl = List.tl +val map = List.map +val rev = List.rev +val use_hook = ref (fn (s : string) => (failwith "no defined directive use" : unit)) +fun use s = !use_hook s +fun isSome (SOME _) = true + | isSome NONE = false +fun valOf (SOME x) = x + | valOf NONE = failwith "valOf" +val print = TextIO.print diff --git a/config/.cvsignore b/config/.cvsignore new file mode 100644 index 0000000..df99fdc --- /dev/null +++ b/config/.cvsignore @@ -0,0 +1,5 @@ +m.h +s.h +Makefile +config.sh + diff --git a/config/Makefile-templ b/config/Makefile-templ new file mode 100644 index 0000000..411c427 --- /dev/null +++ b/config/Makefile-templ @@ -0,0 +1,285 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile-templ,v 1.31 2007-10-30 12:37:16 xleroy Exp $ + +### Compile-time configuration + +########## General configuration + +### Where to install the binaries +BINDIR=/usr/local/bin + +### Where to install the standard library +LIBDIR=/usr/local/lib/ocaml +STUBLIBDIR=$(LIBDIR)/stublibs + +### Where to install the man pages +# Man pages for commands go in $(MANDIR)/man$(MANEXT) +# Man pages for the library go in $(MANDIR)/mano +MANDIR=/usr/local/man +MANEXT=1 + +### Do #! scripts work on your system? +### Beware: on some systems (e.g. SunOS 4), this will work only if +### the string "#!$(BINDIR)/ocamlrun" is less than 32 characters long. +### In doubt, set SHARPBANGSCRIPTS to false. +SHARPBANGSCRIPTS=true +#SHARPBANGSCRIPTS=false + +########## Configuration for the bytecode compiler + +### Which C compiler to use for the bytecode interpreter. +### Performance of the bytecode interpreter is *much* improved +### if Gnu CC version 2 is used. +#BYTECC=gcc +#BYTECC=cc + +### Additional compile-time options for $(BYTECC). +# If using gcc on Intel 386 or Motorola 68k: +# (the -fno-defer-pop option circumvents a bug in certain versions of gcc) +#BYTECCCOMPOPTS=-fno-defer-pop -Wall +# If using gcc and being superstitious: +#BYTECCCOMPOPTS=-Wall +# Under NextStep: +#BYTECCCOMPOPTS=-U__GNUC__ -fno-defer-pop -Wall +# Otherwise: +#BYTECCCOMPOPTS= + +### Additional link-time options for $(BYTECC) +### If using GCC on a Dec Alpha under OSF1: +#BYTECCLINKOPTS=-Wl,-T,12000000 -Wl,-D,14000000 +# To support dynamic loading of shared libraries (they need to look at +# our own symbols): +#BYTECCLINKOPTS=-Wl,-E +# Otherwise: +#BYTECCLINKOPTS= + +### Libraries needed +# On most platforms: +#CCLIBS=-lcurses -ltermcap -lm + +### How to invoke the C preprocessor +# This is not needed anymore. Leave these lines commented out. +# On most machines: +#CPP=/lib/cpp -P +# Under Solaris: +#CPP=/usr/ccs/lib/cpp -P +# Under FreeBSD: +#CPP=cpp -P + +### How to invoke ranlib +# BSD-style: +#RANLIB=ranlib +#RANLIBCMD=ranlib +# If ranlib is not needed: +#RANLIB=ar rs +#RANLIBCMD= + +### Shared library support +# Extension for shared libraries: so if supported, a if not supported +#SO=so +#SO=a +# Set to nothing if shared libraries supported, and to -custom if not supported +#CUSTOM_IF_NOT_SHARED= +#CUSTOM_IF_NOT_SHARED=-custom +# Options to $(BYTECC) to produce shared objects (e.g. PIC) +#SHAREDCCCOMPOPTS=-fPIC +# How to build a shared library, invoked with output .so as first arg +# and object files as remaining args +#MKSHAREDLIB=gcc -shared -o +# Compile-time option to $(BYTECC) to add a directory to be searched +# at run-time for shared libraries +#BYTECCRPATH=-Wl,-rpath + +############# Configuration for the native-code compiler + +### Name of architecture for the native-code compiler +### Currently supported: +### +### alpha Digital/Compaq Alpha machines under DUnix/Tru64 or Linux +### i386 Intel Pentium PCs under Linux, *BSD*, NextStep +### sparc Sun Sparcstation under SunOS 4.1 or Solaris 2 +### mips SGI machines under IRIX +### hppa HP 9000/700 under HPUX and Linux +### power Macintosh under Mac OS X and Linux +### ia64 Intel Itanium/IA64 under Linux +### arm ARM under Linux +### +### Set ARCH=none if your machine is not supported +#ARCH=alpha +#ARCH=i386 +#ARCH=sparc +#ARCH=mips +#ARCH=hppa +#ARCH=power +#ARCH=ia64 +#ARCH=arm +#ARCH=none + +### Name of architecture model for the native-code compiler. +### Some architectures come in several slightly different flavors +### that share a common code generator. This variable tailors the +### behavior of the code generator to the particular flavor used. +### Currently needed only if ARCH=power; leave MODEL=default for +### other architectures. +### If ARCH=power: set MODEL=ppc +### For other architectures: leave MODEL=default +### +#MODEL=ppc +#MODEL=default + +### Name of operating system family for the native-code compiler. +### If ARCH=sparc: choose between +### SYSTEM=sunos SunOS 4.1 +### SYSTEM=solaris Solaris 2 +### +### If ARCH=i386: choose between +### SYSTEM=linux_aout Linux with a.out binaries +### SYSTEM=linux_elf Linux with ELF binaries +### SYSTEM=bsd FreeBSD, probably works for NetBSD also +### SYSTEM=nextstep NextStep +### +### For other architectures: set SYSTEM=unknown +### +#SYSTEM=sunos +#SYSTEM=solaris +#SYSTEM=linux +#SYSTEM=linux_elf +#SYSTEM=bsd +#SYSTEM=nextstep +#SYSTEM=unknown + +### Which C compiler to use for the native-code compiler. +### cc is better than gcc on the Mips and Alpha. +#NATIVECC=cc +#NATIVECC=gcc + +### Additional compile-time options for $(NATIVECC). +# For cc on the Alpha: +#NATIVECCCOMPOPTS=-std1 +# For cc on the Mips: +#NATIVECCCOMPOPTS=-std +# For gcc if superstitious: +#NATIVECCCOMPOPTS=-Wall + +### Additional link-time options for $(NATIVECC) +#NATIVECCLINKOPTS= + +# Compile-time option to $(NATIVECC) to add a directory to be searched +# at run-time for shared libraries +#NATIVECCRPATH=-Wl,-rpath + +### Command and flags to use for assembling ocamlopt-generated code +# For the Alpha or the Mips: +#AS=as -O2 +# For the PowerPC: +#AS=as -u -m ppc -w +# Otherwise: +#AS=as + +### Command and flags to use for assembling .S files (often with preprocessing) +# If gcc is available: +#ASPP=gcc -c +# On SunOS and Solaris: +#ASPP=as -P + +### Extra flags to use for assembling .S files in profiling mode +# On Digital Unix: +#ASPPPROFFLAGS=-pg -DPROFILING +# Otherwise: +#ASPPPROFFLAGS=-DPROFILING + +### Whether profiling with gprof is supported +# If yes: (x86/Linux, Alpha/Digital Unix, Sparc/Solaris): +#PROFILING=prof +# If no: (all others) +#PROFILING=noprof + +### Option to give to the C compiler for profiling +#CC_PROFILE=-pg +#CC_PROFILE=-xpg + +### How to perform a partial link +PARTIALLD=ld -r $(NATIVECCLINKOPTS) + +############# Configuration for the contributed libraries + +### Which libraries to compile and install +# Currently available: +# unix Unix system calls +# str Regular expressions and high-level string processing +# num Arbitrary-precision rational arithmetic +# threads Lightweight concurrent processes +# systhreads Same as threads, requires POSIX threads +# graph Portable drawing primitives for X11 +# dynlink Dynamic linking of bytecode +# labltk Tcl/Tk interface +# bigarray Large, multidimensional numerical arrays + +OTHERLIBRARIES=unix str num threads graph dynlink labltk bigarray + +### Name of the target architecture for the "num" library +# Known targets: +# generic (portable C, works everywhere) +# ia32 (Intel x86) +# amd64 (AMD Opteron, Athlon64) +# alpha +# mips +# ppc (Power PC) +# sparc +# If you don't know, leave BNG_ARCH=generic, which selects a portable +# C implementation of these routines. +BNG_ARCH=generic +BNG_ASM_LEVEL=1 + +### Link-time options to ocamlc or ocamlopt for linking with POSIX threads +# Needed for the "systhreads" package +# Usually: +#PTHREAD_LINK=-cclib -lpthread +# For Solaris: +#PTHREAD_LINK=-cclib -lpthread -cclib -lposix4 + +### -I options for finding the X11/*.h includes +# Needed for the "graph" and "labltk" packages +# Usually: +#X11_INCLUDES=-I/usr/X11R6/include +# For SunOS with OpenLook: +#X11_INCLUDES=/usr/openwin/include + +### Link-time options to ocamlc or ocamlopt for linking with X11 libraries +# Needed for the "graph" and "labltk" packages +# Usually: +#X11_LINK=-lX11 +# For SunOS with OpenLook: +#X11_LINK=-L$(X11_LIB) -lX11 + +### -I options for finding the include file ndbm.h +# Needed for the "dbm" package +# Usually: +#DBM_INCLUDES= +# For recent Linux systems: +#DBM_INCLUDES=-I/usr/include/gdbm + +### Preprocessor options for finding tcl.h and tk.h +# Needed for the "labltk" package +# Required only if not in the standard include path. +# For Tcl/Tk 8.0 on FreeBSD: +#TK_DEFS="-I/usr/local/include/tcl8.0 -I/usr/local/include/tk8.0" + +### Linker options for linking tcl and tk libraries +# Needed for the "labltk" package +# Usually (with appropriate version numbers): +#TK_LINK="-ltk8.0 -ltcl8.0" +# For Tcl/Tk 8.0 on FreeBSD: +#TK_LINK="-L/usr/local/lib -ltk8.0 -ltcl8.0" diff --git a/config/Makefile.mingw b/config/Makefile.mingw new file mode 100644 index 0000000..f7c875e --- /dev/null +++ b/config/Makefile.mingw @@ -0,0 +1,157 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.mingw,v 1.28 2008-12-03 18:09:09 doligez Exp $ + +# Configuration for Windows, Mingw compiler + +######### General configuration + +PREFIX=C:/ocamlmgw + +### Where to install the binaries +BINDIR=$(PREFIX)/bin + +### Where to install the standard library +LIBDIR=$(PREFIX)/lib + +### Where to install the stub DLLs +STUBLIBDIR=$(LIBDIR)/stublibs + +### Where to install the info files +DISTRIB=$(PREFIX) + +### Where to install the man pages +MANDIR=$(PREFIX)/man + +########## Toolchain and OS dependencies + +TOOLCHAIN=mingw +CCOMPTYPE=cc +O=o +A=a +S=s +SO=s.o +DO=d.o +EXE=.exe +EXT_DLL=.dll +EXT_OBJ=.$(O) +EXT_LIB=.$(A) +EXT_ASM=.$(S) +MANEXT=1 +SHARPBANGSCRIPTS=false +PTHREAD_LINK= +X11_INCLUDES= +X11_LINK= +DBM_INCLUDES= +DBM_LINK= +BYTECCRPATH= +SUPPORTS_SHARED_LIBRARIES=true +SHAREDCCCOMPOPTS= +MKSHAREDLIBRPATH= +NATIVECCPROFOPTS= +NATIVECCRPATH= +ASM=as +ASPP=gcc +ASPPPROFFLAGS= +PROFILING=noprof +DYNLINKOPTS= +DEBUGGER=ocamldebugger +CC_PROFILE= +SYSTHREAD_SUPPORT=true +EXTRALIBS= +CMXS=cmxs + +########## Configuration for the bytecode compiler + +### Which C compiler to use for the bytecode interpreter. +BYTECC=gcc -mno-cygwin + +### Additional compile-time options for $(BYTECC). (For static linking.) +BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused + +### Additional link-time options for $(BYTECC). (For static linking.) +BYTECCLINKOPTS= + +### Additional compile-time options for $(BYTECC). (For building a DLL.) +DLLCCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused -DCAML_DLL + +### Libraries needed +BYTECCLIBS=-lws2_32 +NATIVECCLIBS=-lws2_32 + +### How to invoke the C preprocessor +CPP=$(BYTECC) -E + +### Flexlink +FLEXLINK=flexlink -chain mingw +FLEXDIR=$(shell $(FLEXLINK) -where) +IFLEXDIR=-I"$(FLEXDIR)" +MKDLL=$(FLEXLINK) +MKEXE=$(FLEXLINK) -exe +MKMAINDLL=$(FLEXLINK) -maindll + +### How to build a static library +MKLIB=rm -f $(1); ar rcs $(1) $(2) +#ml let mklib out files opts = Printf.sprintf "rm -f %s && ar rcs %s %s %s" out opts out files;; + +### Canonicalize the name of a system library +SYSLIB=-l$(1) +#ml let syslib x = "-l"^x;; + +### The ranlib command +RANLIB=ranlib +RANLIBCMD=ranlib + +############# Configuration for the native-code compiler + +### Name of architecture for the native-code compiler +ARCH=i386 + +### Name of architecture model for the native-code compiler. +MODEL=default + +### Name of operating system family for the native-code compiler. +SYSTEM=mingw + +### Which C compiler to use for the native-code compiler. +NATIVECC=$(BYTECC) + +### Additional compile-time options for $(NATIVECC). +NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused + +### Additional link-time options for $(NATIVECC) +NATIVECCLINKOPTS= + +### Build partially-linked object file +PACKLD=ld -r $(NATIVECCLINKOPTS) -o #there must be a space after this '-o' + +############# Configuration for the contributed libraries + +OTHERLIBRARIES=win32unix str num win32graph dynlink bigarray systhreads labltk + +### Name of the target architecture for the "num" library +BNG_ARCH=ia32 +BNG_ASM_LEVEL=1 + +### Configuration for LablTk +# Set TK_ROOT to the directory where you installed TCL/TK 8.4 +# There must be no spaces or special characters in $(TK_ROOT) +TK_ROOT=c:/tcl +TK_DEFS=-I$(TK_ROOT)/include +TK_LINK=$(TK_ROOT)/bin/tk84.dll $(TK_ROOT)/bin/tcl84.dll -lws2_32 + +############# Aliases for common commands + +MAKEREC=$(MAKE) -f Makefile.nt +MAKECMD=$(MAKE) diff --git a/config/Makefile.msvc b/config/Makefile.msvc new file mode 100644 index 0000000..a005a48 --- /dev/null +++ b/config/Makefile.msvc @@ -0,0 +1,163 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.msvc,v 1.31 2008-12-03 18:09:09 doligez Exp $ + +# Configuration for Windows, Visual C++ compiler + +######### General configuration + +PREFIX=C:/ocamlms + +### Where to install the binaries. +BINDIR=$(PREFIX)/bin + +### Where to install the standard library +LIBDIR=$(PREFIX)/lib + +### Where to install the stub DLLs +STUBLIBDIR=$(LIBDIR)/stublibs + +### Where to install the info files +DISTRIB=$(PREFIX) + +### Where to install the man pages +MANDIR=$(PREFIX)/man + +########## Toolchain and OS dependencies + +TOOLCHAIN=msvc +CCOMPTYPE=msvc +O=obj +A=lib +S=asm +SO=s.obj +DO=d.obj +EXE=.exe +EXT_DLL=.dll +EXT_OBJ=.$(O) +EXT_LIB=.$(A) +EXT_ASM=.$(S) +MANEXT=1 +SHARPBANGSCRIPTS=false +PTHREAD_LINK= +X11_INCLUDES= +X11_LINK= +DBM_INCLUDES= +DBM_LINK= +BYTECCRPATH= +SUPPORTS_SHARED_LIBRARIES=true +SHAREDCCCOMPOPTS= +NATIVECCPROFOPTS= +NATIVECCRPATH= +ASM=ml /nologo /coff /Cp /c /Fo +ASPP= +ASPPPROFFLAGS= +PROFILING=noprof +DYNLINKOPTS= +DEBUGGER=ocamldebugger +CC_PROFILE= +SYSTHREAD_SUPPORT=true +EXTRALIBS= +CMXS=cmxs + +########## Configuration for the bytecode compiler + +### Which C compiler to use for the bytecode interpreter. +BYTECC=cl /nologo -D_CRT_SECURE_NO_DEPRECATE + +### Additional compile-time options for $(BYTECC). (For static linking.) +BYTECCCOMPOPTS=/Ox /MD + +### Additional link-time options for $(BYTECC). (For static linking.) +BYTECCLINKOPTS=/MD /F16777216 + +### Additional compile-time options for $(BYTECC). (For building a DLL.) +DLLCCCOMPOPTS=/Ox /MD + +### Libraries needed +BYTECCLIBS=advapi32.lib ws2_32.lib +NATIVECCLIBS=advapi32.lib ws2_32.lib + +### How to invoke the C preprocessor +CPP=cl /nologo /EP + +### Flexlink +FLEXLINK=flexlink -merge-manifest +FLEXDIR=$(shell $(FLEXLINK) -where) +IFLEXDIR=-I"$(FLEXDIR)" +MKDLL=$(FLEXLINK) +MKEXE=$(FLEXLINK) -exe +MKMAINDLL=$(FLEXLINK) -maindll + +### How to build a static library +MKLIB=link /lib /nologo /out:$(1) $(2) +#ml let mklib out files opts = Printf.sprintf "link /lib /nologo /out:%s %s %s" out opts files;; +MKSHAREDLIBRPATH= + +### Canonicalize the name of a system library +SYSLIB=$(1).lib +#ml let syslib x = x ^ ".lib";; + +### The ranlib command +RANLIB=echo +RANLIBCMD= + +############# Configuration for the native-code compiler + +### Name of architecture for the native-code compiler +ARCH=i386 + +### Name of architecture model for the native-code compiler. +MODEL=default + +### Name of operating system family for the native-code compiler. +SYSTEM=win32 + +### Which C compiler to use for the native-code compiler. +NATIVECC=cl /nologo -D_CRT_SECURE_NO_DEPRECATE + +### Additional compile-time options for $(NATIVECC). +NATIVECCCOMPOPTS=/Ox /MD + +### Additional link-time options for $(NATIVECC) +NATIVECCLINKOPTS=/MD /F16777216 + +### Build partially-linked object file +PACKLD=link /lib /nologo /out:# there must be no space after this '/out:' + +############# Configuration for the contributed libraries + +OTHERLIBRARIES=win32unix systhreads str num win32graph dynlink bigarray labltk + +### Name of the target architecture for the "num" library +BNG_ARCH=generic +BNG_ASM_LEVEL=0 + +### Configuration for LablTk +# Set TK_ROOT to the directory where you installed TCL/TK 8.3 +TK_ROOT=c:/tcl +TK_DEFS=-I$(TK_ROOT)/include +# The following definition avoids hard-wiring $(TK_ROOT) in the libraries +# produced by OCaml, and is therefore required for binary distribution +# of these libraries. However, $(TK_ROOT)/lib must be added to the LIB +# environment variable, as described in README.win32. +TK_LINK=tk84.lib tcl84.lib ws2_32.lib +# An alternative definition that avoids mucking with the LIB variable, +# but hard-wires the Tcl/Tk location in the binaries +# TK_LINK=$(TK_ROOT)/tk84.lib $(TK_ROOT)/tcl84.lib ws2_32.lib + +############# Aliases for common commands + +MAKEREC=$(MAKE) -f Makefile.nt +MAKECMD=$(MAKE) diff --git a/config/Makefile.msvc64 b/config/Makefile.msvc64 new file mode 100644 index 0000000..318649f --- /dev/null +++ b/config/Makefile.msvc64 @@ -0,0 +1,158 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.msvc64,v 1.13 2008-07-29 08:31:41 xleroy Exp $ + +# Configuration for Windows, Visual C++ compiler + +######### General configuration + +PREFIX=C:/ocamlms64 + +### Where to install the binaries. +BINDIR=$(PREFIX)/bin + +### Where to install the standard library +LIBDIR=$(PREFIX)/lib + +### Where to install the stub DLLs +STUBLIBDIR=$(LIBDIR)/stublibs + +### Where to install the info files +DISTRIB=$(PREFIX) + +### Where to install the man pages +MANDIR=$(PREFIX)/man + +########## Toolchain and OS dependencies + +TOOLCHAIN=msvc +CCOMPTYPE=msvc +O=obj +A=lib +S=asm +SO=s.obj +DO=d.obj +DBGO=dbg.obj +EXE=.exe +EXT_DLL=.dll +EXT_OBJ=.$(O) +EXT_LIB=.$(A) +EXT_ASM=.$(S) +MANEXT=1 +SHARPBANGSCRIPTS=false +PTHREAD_LINK= +X11_INCLUDES= +X11_LINK= +DBM_INCLUDES= +DBM_LINK= +BYTECCRPATH= +SUPPORTS_SHARED_LIBRARIES=true +SHAREDCCCOMPOPTS= +NATIVECCPROFOPTS= +NATIVECCRPATH= +ASM=ml64 /nologo /Cp /c /Fo +ASPP= +ASPPPROFFLAGS= +PROFILING=noprof +DYNLINKOPTS= +DEBUGGER=ocamldebugger +CC_PROFILE= +SYSTHREAD_SUPPORT=true +CMXS=cmxs + +########## Configuration for the bytecode compiler + +### Which C compiler to use for the bytecode interpreter. +BYTECC=cl /nologo -D_CRT_SECURE_NO_DEPRECATE + +### Additional compile-time options for $(BYTECC). (For static linking.) +BYTECCCOMPOPTS=/Ox /MD + +### Additional compile-time options for $(BYTECC). (For debug version.) +BYTECCDBGCOMPOPTS=-DDEBUG /Zi /W3 /Wp64 + +### Additional link-time options for $(BYTECC). (For static linking.) +BYTECCLINKOPTS=/MD /F33554432 + +### Additional compile-time options for $(BYTECC). (For building a DLL.) +DLLCCCOMPOPTS=/Ox /MD + +### Libraries needed +EXTRALIBS=bufferoverflowu.lib +BYTECCLIBS=advapi32.lib ws2_32.lib $(EXTRALIBS) +NATIVECCLIBS=advapi32.lib ws2_32.lib $(EXTRALIBS) + +### How to invoke the C preprocessor +CPP=cl /nologo /EP + +### Flexlink +FLEXLINK=flexlink -x64 -merge-manifest +FLEXDIR=$(shell $(FLEXLINK) -where) +IFLEXDIR=-I"$(FLEXDIR)" +MKDLL=$(FLEXLINK) +MKEXE=$(FLEXLINK) -exe +MKMAINDLL=$(FLEXLINK) -maindll + +### How to build a static library +MKLIB=link /lib /nologo /machine:AMD64 /out:$(1) $(2) +#ml let mklib out files opts = Printf.sprintf "link /lib /nologo /machine:AMD64 /out:%s %s %s" out opts files;; +MKSHAREDLIBRPATH= + +### Canonicalize the name of a system library +SYSLIB=$(1).lib +#ml let syslib x = x ^ ".lib";; + +### The ranlib command +RANLIB=echo +RANLIBCMD= + +############# Configuration for the native-code compiler + +### Name of architecture for the native-code compiler +ARCH=amd64 + +### Name of architecture model for the native-code compiler. +MODEL=default + +### Name of operating system family for the native-code compiler. +SYSTEM=win64 + +### Which C compiler to use for the native-code compiler. +NATIVECC=cl /nologo + +### Additional compile-time options for $(NATIVECC). +NATIVECCCOMPOPTS=/Ox /MD + +### Additional link-time options for $(NATIVECC) +NATIVECCLINKOPTS=/MD /F33554432 + +### Build partially-linked object file +PACKLD=link /lib /nologo /machine:AMD64 /out:# there must be no space after this '/out:' + +############# Configuration for the contributed libraries + +OTHERLIBRARIES=win32unix systhreads str num win32graph dynlink bigarray + +### Name of the target architecture for the "num" library +BNG_ARCH=generic +BNG_ASM_LEVEL=0 + +### Configuration for LablTk (not supported) +TK_DEFS= +TK_LINK= + +############# Aliases for common commands + +MAKEREC=$(MAKE) -f Makefile.nt +MAKECMD=$(MAKE) diff --git a/config/auto-aux/.cvsignore b/config/auto-aux/.cvsignore new file mode 100644 index 0000000..cb1ca8a --- /dev/null +++ b/config/auto-aux/.cvsignore @@ -0,0 +1 @@ +camlp4_config.ml diff --git a/config/auto-aux/align.c b/config/auto-aux/align.c new file mode 100644 index 0000000..ba9d200 --- /dev/null +++ b/config/auto-aux/align.c @@ -0,0 +1,103 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: align.c,v 1.7 2001-12-07 13:39:41 xleroy Exp $ */ + +#include +#include +#include + +long foo; + +void access16(short int *p) +{ + foo = *p; +} + +void access32(long int *p) +{ + foo = *p; +} + +jmp_buf failure; + +void sig_handler(int dummy) +{ + longjmp(failure, 1); +} + +int test(void (*fct) (/* ??? */), char *p) +{ + int res; + + signal(SIGSEGV, sig_handler); + signal(SIGBUS, sig_handler); + if(setjmp(failure) == 0) { + fct(p); + res = 0; + } else { + res = 1; + } + signal(SIGSEGV, SIG_DFL); + signal(SIGBUS, SIG_DFL); + return res; +} + +jmp_buf timer; + +void alarm_handler(int dummy) +{ + longjmp(timer, 1); +} + +void use(int n) +{ + return; +} + +int speedtest(char *p) +{ + int * q; + volatile int total; + int i; + volatile int sum; + + signal(SIGALRM, alarm_handler); + sum = 0; + if (setjmp(timer) == 0) { + alarm(1); + total = 0; + while(1) { + for (q = (int *) p, i = 1000; i > 0; q++, i--) + sum += *q; + total++; + } + } + use(sum); + signal(SIGALRM, SIG_DFL); + return total; +} + +main(void) +{ + long n[1001]; + int speed_aligned, speed_unaligned; + + if (test(access16, (char *) n + 1)) exit(1); + if (test(access32, (char *) n + 1)) exit(1); + if (test(access32, (char *) n + 2)) exit(1); + speed_aligned = speedtest((char *) n); + speed_unaligned = speedtest((char *) n + 1); + if (speed_aligned >= 3 * speed_unaligned) exit(1); + exit(0); +} diff --git a/config/auto-aux/ansi.c b/config/auto-aux/ansi.c new file mode 100644 index 0000000..f1a416b --- /dev/null +++ b/config/auto-aux/ansi.c @@ -0,0 +1,21 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1997 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +int main() +{ +#ifdef __STDC__ + return 0; +#else + return 1; +#endif +} diff --git a/config/auto-aux/async_io.c b/config/auto-aux/async_io.c new file mode 100644 index 0000000..ea21b00 --- /dev/null +++ b/config/auto-aux/async_io.c @@ -0,0 +1,60 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: async_io.c,v 1.8 2003-02-11 14:05:36 xleroy Exp $ */ + +#include +#include +#include +#include +#include +#include +#include "s.h" + +int signalled; + +void sigio_handler(int arg) +{ + signalled = 1; +} + +int main(void) +{ +#if defined(SIGIO) && defined(FASYNC) && defined(F_SETFL) && defined(F_SETOWN) + int p[2]; + int ret; +#define OUT 0 +#define IN 1 + if (socketpair(PF_UNIX, SOCK_STREAM, 0, p) == -1) return 1; + signalled = 0; + signal(SIGIO, sigio_handler); + ret = fcntl(p[OUT], F_GETFL, 0); + fcntl(p[OUT], F_SETFL, ret | FASYNC); + fcntl(p[OUT], F_SETOWN, getpid()); + switch(fork()) { + case -1: + return 1; + case 0: + close(p[OUT]); + write(p[IN], "x", 1); + sleep(1); + exit(0); + default: + close(p[IN]); + while(wait(NULL) == -1 && errno == EINTR) /*nothing*/; + } + if (signalled) return 0; else return 1; +#else + return 1; +#endif +} diff --git a/config/auto-aux/bytecopy.c b/config/auto-aux/bytecopy.c new file mode 100644 index 0000000..a771be1 --- /dev/null +++ b/config/auto-aux/bytecopy.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bytecopy.c,v 1.7 2001-12-07 13:39:43 xleroy Exp $ */ + +char buffer[27]; + +#ifdef reverse +#define cpy(s1,s2,n) copy(s2,s1,n) +#else +#define cpy copy +#endif + +int main(int argc, char ** argv) +{ + cpy("abcdefghijklmnopqrstuvwxyz", buffer, 27); + if (strcmp(buffer, "abcdefghijklmnopqrstuvwxyz") != 0) exit(1); + cpy(buffer, buffer+3, 26-3); + if (strcmp(buffer, "abcabcdefghijklmnopqrstuvw") != 0) exit(1); + cpy("abcdefghijklmnopqrstuvwxyz", buffer, 27); + cpy(buffer+3, buffer, 26-3); + if (strcmp(buffer, "defghijklmnopqrstuvwxyzxyz") != 0) exit(1); + exit(0); +} diff --git a/config/auto-aux/dblalign.c b/config/auto-aux/dblalign.c new file mode 100644 index 0000000..265fe45 --- /dev/null +++ b/config/auto-aux/dblalign.c @@ -0,0 +1,55 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dblalign.c,v 1.9 2001-12-07 13:39:43 xleroy Exp $ */ + +#include +#include +#include + +double foo; + +void access_double(double *p) +{ + foo = *p; +} + +jmp_buf failure; + +void sig_handler(int sig) +{ + longjmp(failure, 1); +} + +int main(void) +{ + long n[10]; + int res; + signal(SIGSEGV, sig_handler); +#ifdef SIGBUS + signal(SIGBUS, sig_handler); +#endif + if(setjmp(failure) == 0) { + access_double((double *) n); + access_double((double *) (n+1)); + res = 0; + } else { + res = 1; + } + signal(SIGSEGV, SIG_DFL); +#ifdef SIGBUS + signal(SIGBUS, SIG_DFL); +#endif + exit(res); +} + diff --git a/config/auto-aux/divmod.c b/config/auto-aux/divmod.c new file mode 100644 index 0000000..2dba1f1 --- /dev/null +++ b/config/auto-aux/divmod.c @@ -0,0 +1,47 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: divmod.c,v 1.3 2003-12-30 23:59:47 doligez Exp $ */ + +/* Test semantics of division and modulus for negative arguments */ + +long div4[] = +{ -4,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,-1,-1,0,0,0, + 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4 }; + +long divm4[] = +{ 4,3,3,3,3,2,2,2,2,1,1,1,1,0,0,0, + 0,0,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-3,-3,-3,-3,-4 }; + +long mod4[] = +{ 0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1, + 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0 }; + +long modm4[] = +{ 0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1,0,-3,-2,-1, + 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0 }; + +long q1 = 4; +long q2 = -4; + +int main() +{ + int i; + for (i = -16; i <= 16; i++) { + if (i / q1 != div4[i+16]) return 1; + if (i / q2 != divm4[i+16]) return 1; + if (i % q1 != mod4[i+16]) return 1; + if (i % q2 != modm4[i+16]) return 1; + } + return 0; +} diff --git a/config/auto-aux/elf.c b/config/auto-aux/elf.c new file mode 100644 index 0000000..b263b74 --- /dev/null +++ b/config/auto-aux/elf.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1999 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: elf.c,v 1.4 2001-12-07 13:39:43 xleroy Exp $ */ + +#include + +int main(int argc, char ** argv) +{ +#ifdef __ELF__ + printf("elf\n"); +#else + printf("aout\n"); +#endif + return 0; +} diff --git a/config/auto-aux/endian.c b/config/auto-aux/endian.c new file mode 100644 index 0000000..e339bb9 --- /dev/null +++ b/config/auto-aux/endian.c @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: endian.c,v 1.8 2001-12-07 13:39:43 xleroy Exp $ */ + +#include "m.h" + +#ifndef ARCH_SIXTYFOUR +long intval = 0x41424344L; +char * bigendian = "ABCD"; +char * littleendian = "DCBA"; +#else +long intval = 0x4142434445464748L; +char * bigendian = "ABCDEFGH"; +char * littleendian = "HGFEDCBA"; +#endif + +main(void) +{ + long n[2]; + char * p; + + n[0] = intval; + n[1] = 0; + p = (char *) n; + if (strcmp(p, bigendian) == 0) + exit(0); + if (strcmp(p, littleendian) == 0) + exit(1); + exit(2); +} diff --git a/config/auto-aux/getgroups.c b/config/auto-aux/getgroups.c new file mode 100644 index 0000000..b1db8cb --- /dev/null +++ b/config/auto-aux/getgroups.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getgroups.c,v 1.8 2001-12-07 13:39:43 xleroy Exp $ */ + +#include +#include + +#ifdef NGROUPS_MAX + +int main(void) +{ + int gidset[NGROUPS_MAX]; + if (getgroups(NGROUPS_MAX, gidset) == -1) return 1; + return 0; +} + +#else + +int main(void) { return 1; } + +#endif diff --git a/config/auto-aux/gethostbyaddr.c b/config/auto-aux/gethostbyaddr.c new file mode 100644 index 0000000..7d90493 --- /dev/null +++ b/config/auto-aux/gethostbyaddr.c @@ -0,0 +1,51 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gethostbyaddr.c,v 1.2 2002-05-06 08:29:52 xleroy Exp $ */ + +#ifndef _REENTRANT +/* This helps detection on Digital Unix... */ +#define _REENTRANT +#endif + +#include +#include + +int main(int argc, char ** argv) +{ +#if NUM_ARGS == 7 + char * address; + int length; + int type; + struct hostent h; + char buffer[10]; + int buflen; + int h_errnop; + struct hostent * hp; + hp = gethostbyaddr_r(address, length, type, &h, + buffer, buflen, &h_errnop); +#elif NUM_ARGS == 8 + char * address; + int length; + int type; + struct hostent h; + char buffer[10]; + int buflen; + int h_errnop; + struct hostent * hp; + int rc; + rc = gethostbyaddr_r(address, length, type, &h, + buffer, buflen, &hp, &h_errnop); +#endif + return 0; +} diff --git a/config/auto-aux/gethostbyname.c b/config/auto-aux/gethostbyname.c new file mode 100644 index 0000000..cd0c05e --- /dev/null +++ b/config/auto-aux/gethostbyname.c @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gethostbyname.c,v 1.2 2002-05-06 08:29:52 xleroy Exp $ */ + +#ifndef _REENTRANT +/* This helps detection on Digital Unix... */ +#define _REENTRANT +#endif + +#include +#include + +int main(int argc, char ** argv) +{ +#if NUM_ARGS == 5 + struct hostent *hp; + struct hostent h; + char buffer[1000]; + int h_errno; + hp = gethostbyname_r("www.caml.org", &h, buffer, 10, &h_errno); +#elif NUM_ARGS == 6 + struct hostent *hp; + struct hostent h; + char buffer[1000]; + int h_errno; + int rc; + rc = gethostbyname_r("www.caml.org", &h, buffer, 10, &hp, &h_errno); +#endif + return 0; +} diff --git a/config/auto-aux/hasgot b/config/auto-aux/hasgot new file mode 100755 index 0000000..5014b90 --- /dev/null +++ b/config/auto-aux/hasgot @@ -0,0 +1,29 @@ +#!/bin/sh + +opts="" +libs="$cclibs" +args=$* +rm -f hasgot.c +var="x" +while : ; do + case "$1" in + -i) echo "#include <$2>" >> hasgot.c; shift;; + -t) echo "$2 $var;" >> hasgot.c; var="x$var"; shift;; + -l*|-L*|-F*) libs="$libs $1";; + -framework) libs="$libs $1 $2"; shift;; + -*) opts="$opts $1";; + *) break;; + esac + shift +done + +(echo "main() {" + for f in $*; do echo " $f();"; done + echo "}") >> hasgot.c + +if test "$verbose" = yes; then + echo "hasgot $args: $cc $opts -o tst hasgot.c $libs" >&2 + exec $cc $opts -o tst hasgot.c $libs > /dev/null +else + exec $cc $opts -o tst hasgot.c $libs > /dev/null 2>/dev/null +fi diff --git a/config/auto-aux/ia32sse2.c b/config/auto-aux/ia32sse2.c new file mode 100644 index 0000000..bb58aea --- /dev/null +++ b/config/auto-aux/ia32sse2.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: ia32sse2.c,v 1.2 2005-03-24 17:20:53 doligez Exp $ */ + +/* Test whether IA32 assembler supports SSE2 instructions */ + +int main() +{ + asm("pmuludq %mm1, %mm0"); + asm("paddq %mm1, %mm0"); + asm("psubq %mm1, %mm0"); + return 0; +} diff --git a/config/auto-aux/int64align.c b/config/auto-aux/int64align.c new file mode 100644 index 0000000..072dddf --- /dev/null +++ b/config/auto-aux/int64align.c @@ -0,0 +1,56 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: int64align.c,v 1.2 2001-12-07 13:39:43 xleroy Exp $ */ + +#include +#include +#include +#include "m.h" + +ARCH_INT64_TYPE foo; + +void access_int64(ARCH_INT64_TYPE *p) +{ + foo = *p; +} + +jmp_buf failure; + +void sig_handler(int sig) +{ + longjmp(failure, 1); +} + +int main(void) +{ + long n[10]; + int res; + signal(SIGSEGV, sig_handler); +#ifdef SIGBUS + signal(SIGBUS, sig_handler); +#endif + if(setjmp(failure) == 0) { + access_int64((ARCH_INT64_TYPE *) n); + access_int64((ARCH_INT64_TYPE *) (n+1)); + res = 0; + } else { + res = 1; + } + signal(SIGSEGV, SIG_DFL); +#ifdef SIGBUS + signal(SIGBUS, SIG_DFL); +#endif + exit(res); +} + diff --git a/config/auto-aux/longlong.c b/config/auto-aux/longlong.c new file mode 100644 index 0000000..90452a0 --- /dev/null +++ b/config/auto-aux/longlong.c @@ -0,0 +1,43 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: longlong.c,v 1.4 2002-05-25 08:33:26 xleroy Exp $ */ + +#include +#include + +/* Check for the availability of "long long" type as per ISO C9X */ + +/* Meaning of return code: + 0 long long OK, printf with %ll + 1 long long OK, printf with %q + 2 long long OK, no printf + 3 long long not suitable */ + +int main(int argc, char **argv) +{ + long long l; + unsigned long long u; + char buffer[64]; + + if (sizeof(long long) != 8) return 3; + l = 123456789123456789LL; + buffer[0] = '\0'; + sprintf(buffer, "%lld", l); + if (strcmp(buffer, "123456789123456789") == 0) return 0; + /* the MacOS X library uses qd to format long longs */ + buffer[0] = '\0'; + sprintf (buffer, "%qd", l); + if (strcmp (buffer, "123456789123456789") == 0) return 1; + return 2; +} diff --git a/config/auto-aux/runtest b/config/auto-aux/runtest new file mode 100755 index 0000000..ce65bd0 --- /dev/null +++ b/config/auto-aux/runtest @@ -0,0 +1,8 @@ +#!/bin/sh +if test "$verbose" = yes; then +echo "runtest: $cc -o tst $* $cclibs" >&2 +$cc -o tst $* $cclibs || exit 100 +else +$cc -o tst $* $cclibs 2> /dev/null || exit 100 +fi +exec ./tst diff --git a/config/auto-aux/schar.c b/config/auto-aux/schar.c new file mode 100644 index 0000000..ec8d0f9 --- /dev/null +++ b/config/auto-aux/schar.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: schar.c,v 1.8 2001-12-07 13:39:44 xleroy Exp $ */ + +char foo[]="\377"; + +int main(int argc, char ** argv) +{ + int i; + i = foo[0]; + exit(i != -1); +} diff --git a/config/auto-aux/schar2.c b/config/auto-aux/schar2.c new file mode 100644 index 0000000..78a7e0b --- /dev/null +++ b/config/auto-aux/schar2.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: schar2.c,v 1.8 2001-12-07 13:39:44 xleroy Exp $ */ + +signed char foo[]="\377"; + +int main(int argc, char ** argv) +{ + int i; + i = foo[0]; + exit(i != -1); +} diff --git a/config/auto-aux/searchpath b/config/auto-aux/searchpath new file mode 100755 index 0000000..9b31267 --- /dev/null +++ b/config/auto-aux/searchpath @@ -0,0 +1,9 @@ +#!/bin/sh +# Find a program in the path + +IFS=':' +for dir in $PATH; do + if test -z "$dir"; then dir=.; fi + if test -f $dir/$1; then exit 0; fi +done +exit 1 diff --git a/config/auto-aux/sharpbang b/config/auto-aux/sharpbang new file mode 100755 index 0000000..eb447ba --- /dev/null +++ b/config/auto-aux/sharpbang @@ -0,0 +1,2 @@ +#! /bin/cat +exit 1 diff --git a/config/auto-aux/sharpbang2 b/config/auto-aux/sharpbang2 new file mode 100755 index 0000000..3753096 --- /dev/null +++ b/config/auto-aux/sharpbang2 @@ -0,0 +1,2 @@ +#! /usr/bin/cat +exit 1 diff --git a/config/auto-aux/sighandler.c b/config/auto-aux/sighandler.c new file mode 100644 index 0000000..afbff8d --- /dev/null +++ b/config/auto-aux/sighandler.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sighandler.c,v 1.7 2001-12-07 13:39:44 xleroy Exp $ */ + +#include + +int main(void) +{ + SIGRETURN (*old)(); + old = signal(SIGQUIT, SIG_DFL); + return 0; +} diff --git a/config/auto-aux/signals.c b/config/auto-aux/signals.c new file mode 100644 index 0000000..2f4438a --- /dev/null +++ b/config/auto-aux/signals.c @@ -0,0 +1,68 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals.c,v 1.7 2001-12-07 13:39:44 xleroy Exp $ */ + +/* To determine the semantics of signal handlers + (System V: signal is reset to default behavior on entrance to the handler + BSD: signal handler remains active). */ + +#include +#include + +/* Find a signal that is ignored by default */ + +#ifdef SIGCHLD +#define IGNSIG SIGCHLD +#else +#ifdef SIGIO +#define IGNSIG SIGIO +#else +#ifdef SIGCLD +#define IGNSIG SIGCLD +#else +#ifdef SIGPWR +#define IGNSIG SIGPWR +#endif +#endif +#endif +#endif + +#ifdef IGNSIG + +int counter; + +void sig_handler(int dummy) +{ + counter++; +} + +int main(int argc, char **argv) +{ + signal(IGNSIG, sig_handler); + counter = 0; + kill(getpid(), IGNSIG); + kill(getpid(), IGNSIG); + return (counter == 2 ? 0 : 1); +} + +#else + +/* If no suitable signal was found, assume System V */ + +int main(int argc, char ** argv) +{ + return 1; +} + +#endif diff --git a/config/auto-aux/sizes.c b/config/auto-aux/sizes.c new file mode 100644 index 0000000..6d9aef3 --- /dev/null +++ b/config/auto-aux/sizes.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sizes.c,v 1.9 2001-12-07 13:39:44 xleroy Exp $ */ + +#include + +int main(int argc, char **argv) +{ + printf("%d %d %d %d\n", + sizeof(int), sizeof(long), sizeof(long *), sizeof(short)); + return 0; +} diff --git a/config/auto-aux/solaris-ld b/config/auto-aux/solaris-ld new file mode 100644 index 0000000..3ab90bc --- /dev/null +++ b/config/auto-aux/solaris-ld @@ -0,0 +1,7 @@ +#!/bin/sh +# Determine if gcc calls the Solaris ld or the GNU ld +# Exit code is 0 for Solaris ld, 1 for GNU ld + +echo "int main() { return 0; }" > hasgot.c +$cc -v -o tst hasgot.c 2>&1 | grep -s '^ld:' > /dev/null +exit $? diff --git a/config/auto-aux/stackov.c b/config/auto-aux/stackov.c new file mode 100644 index 0000000..625c5f7 --- /dev/null +++ b/config/auto-aux/stackov.c @@ -0,0 +1,68 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stackov.c,v 1.5 2008-01-11 16:13:16 doligez Exp $ */ + +#include +#include +#include + +static char sig_alt_stack[SIGSTKSZ]; +static char * system_stack_top; + +#if defined(TARGET_i386) && defined(SYS_linux_elf) +static void segv_handler(int signo, struct sigcontext sc) +{ + char * fault_addr = (char *) sc.cr2; +#else +static void segv_handler(int signo, siginfo_t * info, void * context) +{ + char * fault_addr = (char *) info->si_addr; +#endif + struct rlimit limit; + + if (getrlimit(RLIMIT_STACK, &limit) == 0 && + ((long) fault_addr & (sizeof(long) - 1)) == 0 && + fault_addr < system_stack_top && + fault_addr >= system_stack_top - limit.rlim_cur - 0x2000) { + _exit(0); + } else { + _exit(4); + } +} + +int main(int argc, char ** argv) +{ + stack_t stk; + struct sigaction act; + + stk.ss_sp = sig_alt_stack; + stk.ss_size = SIGSTKSZ; + stk.ss_flags = 0; +#if defined(TARGET_i386) && defined(SYS_linux_elf) + act.sa_handler = (void (*)(int)) segv_handler; + act.sa_flags = SA_ONSTACK | SA_NODEFER; +#else + act.sa_sigaction = segv_handler; + act.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_NODEFER; +#endif + sigemptyset(&act.sa_mask); + system_stack_top = (char *) &act; + if (sigaltstack(&stk, NULL) != 0) { perror("sigaltstack"); return 2; } + if (sigaction(SIGSEGV, &act, NULL) != 0) { perror("sigaction"); return 2; } + /* We used to trigger a stack overflow at this point to test whether + the code above works, but this causes problems with POSIX threads + on some BSD systems. So, instead, we just test that all this + code compiles, indicating that the required syscalls are there. */ + return 0; +} diff --git a/config/auto-aux/tclversion.c b/config/auto-aux/tclversion.c new file mode 100644 index 0000000..77c0bb7 --- /dev/null +++ b/config/auto-aux/tclversion.c @@ -0,0 +1,8 @@ +#include +#include +#include + +main () +{ + puts(TCL_VERSION); +} diff --git a/config/auto-aux/trycompile b/config/auto-aux/trycompile new file mode 100755 index 0000000..797a1c3 --- /dev/null +++ b/config/auto-aux/trycompile @@ -0,0 +1,7 @@ +#!/bin/sh +if test "$verbose" = yes; then +echo "trycompile: $cc -o tst $* $cclibs" >&2 +$cc -o tst $* $cclibs || exit 100 +else +$cc -o tst $* $cclibs 2> /dev/null || exit 100 +fi diff --git a/config/gnu/config.guess b/config/gnu/config.guess new file mode 100755 index 0000000..d25d58f --- /dev/null +++ b/config/gnu/config.guess @@ -0,0 +1,1457 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + +timestamp='2004-02-16' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; + amd64:OpenBSD:*:*) + echo x86_64-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + cats:OpenBSD:*:*) + echo arm-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + macppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvmeppc:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pegasos:OpenBSD:*:*) + echo powerpc-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mipseb-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit 0 ;; + macppc:MirBSD:*:*) + echo powerppc-unknown-mirbsd${UNAME_RELEASE} + exit 0 ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit 0 ;; + alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha*:OpenVMS:*:*) + echo alpha-hp-vms + exit 0 ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit 0 ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit 0 ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit 0;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit 0 ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit 0 ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit 0 ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit 0;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit 0 ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit 0 ;; + DRS?6000:UNIX_SV:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7 && exit 0 ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + i86pc:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit 0 ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit 0 ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit 0 ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c \ + && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && exit 0 + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit 0 ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit 0 ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit 0 ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:[45]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + # avoid double evaluation of $set_cc_for_build + test -n "$CC_FOR_BUILD" || eval $set_cc_for_build + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0 + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit 0 ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + *:UNICOS/mp:*:*) + echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit 0 ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit 0 ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit 0 ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + # Determine whether the default compiler uses glibc. + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #if __GLIBC__ >= 2 + LIBC=gnu + #else + LIBC= + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + # GNU/KFreeBSD systems have a "k" prefix to indicate we are using + # FreeBSD's kernel, but not the complete OS. + case ${LIBC} in gnu) kernel_only='k' ;; esac + echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} + exit 0 ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit 0 ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit 0 ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit 0 ;; + x86:Interix*:[34]*) + echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' + exit 0 ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit 0 ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit 0 ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit 0 ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit 0 ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit 0 ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit 0 ;; + arm*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sa110:Linux:*:*) + echo arm-unknown-linux-gnu + exit 0 ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit 0 ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` + test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0 + ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit 0 ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit 0 ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit 0 ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit 0 ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit 0 ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit 0 ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit 0 ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit 0 ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit 0 ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit 0 ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #ifdef __INTEL_COMPILER + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` + test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 + test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit 0 ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit 0 ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit 0 ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit 0 ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit 0 ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit 0 ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit 0 ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit 0 ;; + i*86:*:5:[78]*) + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit 0 ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit 0 ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit 0 ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit 0 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit 0 ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit 0 ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit 0 ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit 0 ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit 0 ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit 0 ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit 0 ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit 0 ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit 0 ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + osfmach3_ppc:*:*:*) + echo powerpc-unknown-linux + exit 0 ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Darwin:*:*) + case `uname -p` in + *86) UNAME_PROCESSOR=i686 ;; + powerpc) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit 0 ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit 0 ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit 0 ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit 0 ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit 0 ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit 0 ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit 0 ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit 0 ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit 0 ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit 0 ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit 0 ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit 0 ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit 0 ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit 0 ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit 0 ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) + char * arch; + int version; +#if !defined (__ARCHITECTURE__) + arch = "m68k"; +#else + arch = __ARCHITECTURE__; + if (strcmp(arch, "hppa") == 0) arch = "hppa1.1"; +#endif + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + printf ("%s-next-nextstep%d\n", arch, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0 + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/config/gnu/config.sub b/config/gnu/config.sub new file mode 100755 index 0000000..d2e3557 --- /dev/null +++ b/config/gnu/config.sub @@ -0,0 +1,1545 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + +timestamp='2004-02-16' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit 0 ;; + --version | -v ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit 0;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \ + kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32r | m68000 | m68k | m88k | mcore \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | msp430 \ + | ns16k | ns32k \ + | openrisc | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ + | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xscale | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* \ + | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32r-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | msp430-* \ + | none-* | np1-* | nv1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ + | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ + | xtensa-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + cr16c) + basic_machine=cr16c-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nv1) + basic_machine=nv1-cray + os=-unicosmp + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + or32 | or32-*) + basic_machine=or32-unknown + os=-coff + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparc | sparcv9 | sparcv9b) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* | -openbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-ibm) + os=-aix + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/config/m-nt.h b/config/m-nt.h new file mode 100644 index 0000000..d70ccc1 --- /dev/null +++ b/config/m-nt.h @@ -0,0 +1,46 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: m-nt.h,v 1.12 2006-05-09 16:01:26 xleroy Exp $ */ + +/* Machine configuration, Intel x86 processors, Win32, + Visual C++ or Mingw compiler */ + +#ifdef _WIN64 +#define ARCH_SIXTYFOUR +#else +#undef ARCH_SIXTYFOUR +#endif +#undef ARCH_BIG_ENDIAN +#undef ARCH_ALIGN_DOUBLE + +#define SIZEOF_INT 4 +#define SIZEOF_LONG 4 +#ifdef _WIN64 +#define SIZEOF_PTR 8 +#else +#define SIZEOF_PTR 4 +#endif +#define SIZEOF_SHORT 2 + +#ifdef __MINGW32__ +#define ARCH_INT64_TYPE long long +#define ARCH_UINT64_TYPE unsigned long long +#else +#define ARCH_INT64_TYPE __int64 +#define ARCH_UINT64_TYPE unsigned __int64 +#endif +#define ARCH_INT64_PRINTF_FORMAT "I64" + +#undef NONSTANDARD_DIV_MOD + diff --git a/config/m-templ.h b/config/m-templ.h new file mode 100644 index 0000000..dd7673c --- /dev/null +++ b/config/m-templ.h @@ -0,0 +1,83 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: m-templ.h,v 1.15 2005-09-22 14:21:50 xleroy Exp $ */ + +/* Processor dependencies */ + +#define ARCH_SIXTYFOUR + +/* Define ARCH_SIXTYFOUR if the processor has a natural word size of 64 bits. + That is, sizeof(char *) = 8. + Otherwise, leave ARCH_SIXTYFOUR undefined. + This assumes sizeof(char *) = 4. */ + +#define ARCH_BIG_ENDIAN + +/* Define ARCH_BIG_ENDIAN if the processor is big endian (the most + significant byte of an integer stored in memory comes first). + Leave ARCH_BIG_ENDIAN undefined if the processor is little-endian + (the least significant byte comes first). +*/ + +#define ARCH_ALIGN_DOUBLE + +/* Define ARCH_ALIGN_DOUBLE if the processor requires doubles to be + doubleword-aligned. Leave ARCH_ALIGN_DOUBLE undefined if the processor + supports word-aligned doubles. */ + +#undef ARCH_CODE32 + +/* Define ARCH_CODE32 if, on a 64-bit machine, code pointers fit in 32 bits, + i.e. the code segment resides in the low 4G of the addressing space. + ARCH_CODE32 is ignored on 32-bit machines. */ + +#define SIZEOF_INT 4 +#define SIZEOF_LONG 4 +#define SIZEOF_PTR 4 +#define SIZEOF_SHORT 2 + +/* Define SIZEOF_INT, SIZEOF_LONG, SIZEOF_PTR and SIZEOF_SHORT + to the sizes in bytes of the C types "int", "long", "char *" and "short", + respectively. */ + +#define ARCH_INT64_TYPE long long +#define ARCH_UINT64_TYPE unsigned long long + +/* Define ARCH_INT64_TYPE and ARCH_UINT64_TYPE to 64-bit integer types, + typically "long long" and "unsigned long long" on 32-bit platforms, + and "long" and "unsigned long" on 64-bit platforms. + If the C compiler doesn't support any 64-bit integer type, + leave both ARCH_INT64_TYPE and ARCH_UINT64_TYPE undefined. */ + +#define ARCH_INT64_PRINTF_FORMAT "ll" + +/* Define ARCH_INT64_PRINTF_FORMAT to the printf format used for formatting + values of type ARCH_INT64_TYPE. This is usually "ll" on 32-bit + platforms and "l" on 64-bit platforms. + Leave undefined if ARCH_INT64_TYPE is undefined. */ + +#define ARCH_ALIGN_INT64 + +/* Define ARCH_ALIGN_INT64 if the processor requires 64-bit integers to be + doubleword-aligned. Leave ARCH_ALIGN_INT64 undefined if the processor + supports word-aligned 64-bit integers. Leave undefined if + 64-bit integers are not supported. */ + +#undef NONSTANDARD_DIV_MOD + +/* Leave NONSTANDARD_DIV_MOD undefined if the C operators / and % implement + round-towards-zero semantics, as specified by ISO C 9x and implemented + by most contemporary processors. Otherwise, or if you don't know, + define NONSTANDARD_DIV_MOD: this will select a slower but correct + software emulation of division and modulus. */ diff --git a/config/s-nt.h b/config/s-nt.h new file mode 100644 index 0000000..67d6677 --- /dev/null +++ b/config/s-nt.h @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: s-nt.h,v 1.12 2002-06-18 13:00:55 xleroy Exp $ */ + +/* Operating system dependencies, Intel x86 processors, Windows NT */ + +#define OCAML_OS_TYPE "Win32" + +#undef BSD_SIGNALS +#define HAS_STRERROR +#define HAS_SOCKETS +#define HAS_GETCWD +#define HAS_UTIME +#define HAS_DUP2 +#define HAS_GETHOSTNAME +#define HAS_MKTIME +#define HAS_PUTENV +#define HAS_LOCALE diff --git a/config/s-templ.h b/config/s-templ.h new file mode 100644 index 0000000..e9ebf60 --- /dev/null +++ b/config/s-templ.h @@ -0,0 +1,203 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: s-templ.h,v 1.22 2004-05-18 08:50:22 xleroy Exp $ */ + +/* Operating system and standard library dependencies. */ + +/* 0. Operating system type string. */ + +#define OCAML_OS_TYPE "Unix" +/* #define OCAML_OS_TYPE "Win32" */ +/* #define OCAML_OS_TYPE "MacOS" */ + +/* 1. For the runtime system. */ + +#define POSIX_SIGNALS + +/* Define POSIX_SIGNALS if signal handling is POSIX-compliant. + In particular, sigaction(), sigprocmask() and the operations on + sigset_t are provided. */ + +#define BSD_SIGNALS + +/* Define BSD_SIGNALS if signal handlers have the BSD semantics: the handler + remains attached to the signal when the signal is received. Leave it + undefined if signal handlers have the System V semantics: the signal + resets the behavior to default. */ + +#define HAS_SIGSETMASK + +/* Define HAS_SIGSETMASK if you have sigsetmask(), as in BSD. */ + +#define HAS_TERMCAP + +/* Define HAS_TERMCAP if you have the termcap functions to read the + terminal database, e.g. tgetent(), tgetstr(), tgetnum(), tputs(). + Also add the required libraries (e.g. -lcurses -ltermcap) to $(CCLIBS) + in ../Makefile.config */ + +#define SUPPORT_DYNAMIC_LINKING + +/* Define SUPPORT_DYNAMIC_LINKING if dynamic loading of C stub code + via dlopen() is available. */ + +/* 2. For the Unix library. */ + +#define HAS_SOCKETS + +/* Define HAS_SOCKETS if you have BSD sockets. */ + +#define HAS_SOCKLEN_T + +/* Define HAS_SOCKLEN_T if the type socklen_t is defined in + /usr/include/sys/socket.h. */ + +#define HAS_UNISTD + +/* Define HAS_UNISTD if you have /usr/include/unistd.h. */ + +#define HAS_DIRENT + +/* Define HAS_DIRENT if you have /usr/include/dirent.h and the result of + readdir() is of type struct dirent *. + Otherwise, we'll load /usr/include/sys/dir.h, and readdir() is expected to + return a struct direct *. */ + +#define HAS_REWINDDIR + +/* Define HAS_REWINDDIR if you have rewinddir(). */ + +#define HAS_LOCKF + +/* Define HAS_LOCKF if the library provides the lockf() function. */ + +#define HAS_MKFIFO + +/* Define HAS_MKFIFO if the library provides the mkfifo() function. */ + +#define HAS_GETCWD +#define HAS_GETWD + +/* Define HAS_GETCWD if the library provides the getcwd() function. */ +/* Define HAS_GETWD if the library provides the getwd() function. */ + +#define HAS_GETPRIORITY + +/* Define HAS_GETPRIORITY if the library provides getpriority() and + setpriority(). Otherwise, we'll use nice(). */ + +#define HAS_UTIME +#define HAS_UTIMES + +/* Define HAS_UTIME if you have /usr/include/utime.h and the library + provides utime(). Define HAS_UTIMES if the library provides utimes(). */ + +#define HAS_DUP2 + +/* Define HAS_DUP2 if you have dup2(). */ + +#define HAS_FCHMOD + +/* Define HAS_FCHMOD if you have fchmod() and fchown(). */ + +#define HAS_TRUNCATE + +/* Define HAS_TRUNCATE if you have truncate() and + ftruncate(). */ + +#define HAS_SELECT + +/* Define HAS_SELECT if you have select(). */ + +#define HAS_SYS_SELECT_H + +/* Define HAS_SYS_SELECT_H if /usr/include/sys/select.h exists + and should be included before using select(). */ + +#define HAS_SYMLINK + +/* Define HAS_SYMLINK if you have symlink() and readlink() and lstat(). */ + +#define HAS_WAIT4 +#define HAS_WAITPID + +/* Define HAS_WAIT4 if you have wait4(). + Define HAS_WAITPID if you have waitpid(). */ + +#define HAS_GETGROUPS + +/* Define HAS_GETGROUPS if you have getgroups(). */ + +#define HAS_TERMIOS + +/* Define HAS_TERMIOS if you have /usr/include/termios.h and it is + Posix-compliant. */ + +#define HAS_ASYNC_IO + +/* Define HAS_ASYNC_IO if BSD-style asynchronous I/O are supported + (the process can request to be sent a SIGIO signal when a descriptor + is ready for reading). */ + +#define HAS_SETITIMER + +/* Define HAS_SETITIMER if you have setitimer(). */ + +#define HAS_GETHOSTNAME + +/* Define HAS_GETHOSTNAME if you have gethostname(). */ + +#define HAS_UNAME + +/* Define HAS_UNAME if you have uname(). */ + +#define HAS_GETTIMEOFDAY + +/* Define HAS_GETTIMEOFDAY if you have gettimeofday(). */ + +#define HAS_MKTIME + +/* Define HAS_MKTIME if you have mktime(). */ + +#define HAS_SETSID + +/* Define HAS_SETSID if you have setsid(). */ + +#define HAS_PUTENV + +/* Define HAS_PUTENV if you have putenv(). */ + +#define HAS_LOCALE + +/* Define HAS_LOCALE if you have the include file and the + setlocale() function. */ + +#define HAS_MMAP + +/* Define HAS_MMAP if you have the include file and the + functions mmap() and munmap(). */ + +#define HAS_GETHOSTBYNAME_R 6 + +/* Define HAS_GETHOSTBYNAME_R if gethostbyname_r() is available. + The value of this symbol is the number of arguments of + gethostbyname_r(): either 5 or 6 depending on prototype. + (5 is the Solaris version, 6 is the Linux version). */ + +#define HAS_GETHOSTBYADDR_R 8 + +/* Define HAS_GETHOSTBYADDR_R if gethostbyname_r() is available. + The value of this symbol is the number of arguments of + gethostbyaddr_r(): either 7 or 8 depending on prototype. + (7 is the Solaris version, 8 is the Linux version). */ diff --git a/configure b/configure new file mode 100755 index 0000000..aa514f1 --- /dev/null +++ b/configure @@ -0,0 +1,1646 @@ +#! /bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file LICENSE. # +# # +######################################################################### + +# $Id: configure,v 1.267 2008-12-03 18:09:08 doligez Exp $ + +configure_options="$*" +prefix=/usr/local +bindir='' +libdir='' +mandir='' +manext=1 +host_type=unknown +ccoption='' +asoption='' +asppoption='' +cclibs='' +curseslibs='' +mathlib='-lm' +dllib='' +x11_include_dir='' +x11_lib_dir='' +tk_wanted=yes +pthread_wanted=yes +tk_defs='' +tk_libs='' +tk_x11=yes +dl_defs='' +verbose=no +withcurses=yes +withsharedlibs=yes +gcc_warnings="-Wall" +partialld="ld -r" + +# Try to turn internationalization off, can cause config.guess to malfunction! +unset LANG +unset LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME + +# Turn off some MacOS X debugging stuff, same reason +unset RC_TRACE_ARCHIVES RC_TRACE_DYLIBS RC_TRACE_PREBINDING_DISABLED + +# Parse command-line arguments + +while : ; do + case "$1" in + "") break;; + -prefix|--prefix) + prefix=$2; shift;; + -bindir|--bindir) + bindir=$2; shift;; + -libdir|--libdir) + libdir=$2; shift;; + -mandir|--mandir) + case "$2" in + */man[1-9ln]) + mandir=`echo $2 | sed -e 's|^\(.*\)/man.$|\1|'` + manext=`echo $2 | sed -e 's/^.*\(.\)$/\1/'`;; + *) + mandir=$2 + manext=1;; + esac + shift;; + -host*|--host*) + host_type=$2; shift;; + -cc*) + ccoption="$2"; shift;; + -as) + asoption="$2"; shift;; + -aspp) + asppoption="$2"; shift;; + -lib*) + cclibs="$2 $cclibs"; shift;; + -no-curses) + withcurses=no;; + -no-shared-libs) + withsharedlibs=no;; + -x11include*|--x11include*) + x11_include_dir=$2; shift;; + -x11lib*|--x11lib*) + x11_lib_dir=$2; shift;; + -with-pthread*|--with-pthread*) + ;; # Ignored for backward compatibility + -no-pthread*|--no-pthread*) + pthread_wanted=no;; + -no-tk|--no-tk) + tk_wanted=no;; + -tkdefs*|--tkdefs*) + tk_defs=$2; shift;; + -tklibs*|--tklibs*) + tk_libs=$2; shift;; + -tk-no-x11|--tk-no-x11) + tk_x11=no;; + -dldefs*|--dldefs*) + dl_defs="$2"; shift;; + -dllibs*|--dllibs*) + dllib="$2"; shift;; + -verbose|--verbose) + verbose=yes;; + *) echo "Unknown option \"$1\"." 1>&2; exit 2;; + esac + shift +done + +# Sanity checks + +case "$prefix" in + /*) ;; + *) echo "The -prefix directory must be absolute." 1>&2; exit 2;; +esac +case "$bindir" in + /*) ;; + "") ;; + *) echo "The -bindir directory must be absolute." 1>&2; exit 2;; +esac +case "$libdir" in + /*) ;; + "") ;; + *) echo "The -libdir directory must be absolute." 1>&2; exit 2;; +esac +case "$mandir" in + /*) ;; + "") ;; + *) echo "The -mandir directory must be absolute." 1>&2; exit 2;; +esac + +# Generate the files + +cd config/auto-aux +rm -f s.h m.h Makefile +touch s.h m.h Makefile + +# Write options to Makefile + +echo "# generated by ./configure $configure_options" >> Makefile + +# Where to install + +echo "PREFIX=$prefix" >> Makefile +case "$bindir" in + "") echo 'BINDIR=$(PREFIX)/bin' >> Makefile + bindir="$prefix/bin";; + *) echo "BINDIR=$bindir" >> Makefile;; +esac +case "$libdir" in + "") echo 'LIBDIR=$(PREFIX)/lib/ocaml' >> Makefile + libdir="$prefix/lib/ocaml";; + *) echo "LIBDIR=$libdir" >> Makefile;; +esac +echo 'STUBLIBDIR=$(LIBDIR)/stublibs' >> Makefile +case "$mandir" in + "") echo 'MANDIR=$(PREFIX)/man' >> Makefile + mandir="$prefix/man";; + *) echo "MANDIR=$mandir" >> Makefile;; +esac +echo "MANEXT=$manext" >> Makefile + +# Determine the system type + +if test "$host_type" = "unknown"; then + if host_type=`../gnu/config.guess`; then :; else + echo "Cannot guess host type" + echo "You must specify one with the -host option" + exit 2 + fi +fi +if host=`../gnu/config.sub $host_type`; then :; else + echo "Please specify the correct host type with the -host option" + exit 2 +fi +echo "Configuring for a $host ..." + +# Do we have gcc? + +if test -z "$ccoption"; then + if sh ./searchpath gcc; then + echo "gcc found" + cc=gcc + else + cc=cc + fi +else + cc="$ccoption" +fi + +# Check for buggy versions of GCC + +buggycc="no" + +case "$host,$cc" in + i[3456]86-*-*,gcc*) + case `$cc --version` in + 2.7.2.1) cat <<'EOF' + +WARNING: you are using gcc version 2.7.2.1 on an Intel x86 processor. +This version of gcc is known to generate incorrect code for the +Objective Caml runtime system on some Intel x86 machines. (The symptom +is a crash of boot/ocamlc when compiling stdlib/pervasives.mli.) +In particular, the version of gcc 2.7.2.1 that comes with +Linux RedHat 4.x / Intel is affected by this problem. +Other Linux distributions might also be affected. +If you are using one of these configurations, you are strongly advised +to use another version of gcc, such as 2.95, which are +known to work well with Objective Caml. + +Press to proceed or to stop. +EOF + read reply;; + 2.96*) cat <<'EOF' + +WARNING: you are using gcc version 2.96 on an Intel x86 processor. +Certain patched versions of gcc 2.96 are known to generate incorrect +code for the Objective Caml runtime system. (The symptom is a segmentation +violation on boot/ocamlc.) Those incorrectly patched versions can be found +in RedHat 7.2 and Mandrake 8.0 and 8.1; other Linux distributions +might also be affected. (See bug #57760 on bugzilla.redhat.com) + +Auto-configuration will now select gcc compiler flags that work around +the problem. Still, if you observe segmentation faults while running +ocamlc or ocamlopt, you are advised to try another version of gcc, +such as 2.95.3 or 3.2. + +EOF + buggycc="gcc.2.96";; + + esac;; +esac + +# Configure the bytecode compiler + +bytecc="$cc" +mkexe="\$(BYTECC)" +bytecccompopts="" +bytecclinkopts="" +dllccompopts="" +ostype="Unix" +exe="" +iflexdir="" + +case "$bytecc,$host" in + cc,*-*-nextstep*) + # GNU C extensions disabled, but __GNUC__ still defined! + bytecccompopts="-fno-defer-pop $gcc_warnings -U__GNUC__ -posix" + bytecclinkopts="-posix";; + *,*-*-rhapsody*) + # Almost the same as NeXTStep + bytecccompopts="-fno-defer-pop $gcc_warnings -DSHRINKED_GNUC" + mathlib="";; + *,*-*-darwin*) + bytecccompopts="-fno-defer-pop -no-cpp-precomp $gcc_warnings" + mathlib="" + # Tell gcc that we can use 32-bit code addresses for threaded code + # unless we are compiled for a shared library (-fPIC option) + echo "#ifndef __PIC__" >> m.h + echo "# define ARCH_CODE32" >> m.h + echo "#endif" >> m.h;; + *,*-*-beos*) + bytecccompopts="-fno-defer-pop $gcc_warnings" + # No -lm library + mathlib="";; + gcc,alpha*-*-osf*) + bytecccompopts="-fno-defer-pop $gcc_warnings" + if cc="$bytecc" sh ./hasgot -mieee; then + bytecccompopts="-mieee $bytecccompopts"; + fi + # Put code and static data in lower 4GB + bytecclinkopts="-Wl,-T,12000000 -Wl,-D,14000000" + # Tell gcc that we can use 32-bit code addresses for threaded code + echo "#define ARCH_CODE32" >> m.h;; + cc,alpha*-*-osf*) + bytecccompopts="-std1 -ieee";; + gcc,alpha*-*-linux*) + if cc="$bytecc" sh ./hasgot -mieee; then + bytecccompopts="-mieee $bytecccompopts"; + fi;; + cc,mips-*-irix6*) + # Add -n32 flag to ensure compatibility with native-code compiler + bytecccompopts="-n32" + # Turn off warning "unused library" + bytecclinkopts="-n32 -Wl,-woff,84";; + cc*,mips-*-irix6*) + # (For those who want to force "cc -64") + # Turn off warning "unused library" + bytecclinkopts="-Wl,-woff,84";; + *,alpha*-*-unicos*) + # For the Cray T3E + bytecccompopts="-DUMK";; + gcc*,powerpc-*-aix*) + # Avoid name-space pollution by requiring Unix98-conformant includes + bytecccompopts="-fno-defer-pop $gcc_warnings -D_XOPEN_SOURCE=500";; + *,powerpc-*-aix*) + bytecccompopts="-D_XOPEN_SOURCE=500";; + gcc*,*-*-cygwin*) + bytecccompopts="-fno-defer-pop $gcc_warnings -U_WIN32" + dllccompopts="-D_WIN32 -DCAML_DLL" + flexlink="flexlink -chain cygwin -merge-manifest" + flexdir=`$flexlink -where | dos2unix` + iflexdir="-I\"$flexdir\"" + mkexe="$flexlink -exe" + exe=".exe" + ostype="Cygwin";; + gcc*,x86_64-*-linux*) + bytecccompopts="-fno-defer-pop $gcc_warnings" + # Tell gcc that we can use 32-bit code addresses for threaded code + # unless we are compiled for a shared library (-fPIC option) + echo "#ifndef __PIC__" >> m.h + echo "# define ARCH_CODE32" >> m.h + echo "#endif" >> m.h;; + gcc*) + bytecccompopts="-fno-defer-pop $gcc_warnings";; +esac + +# Configure compiler to use in further tests + +cc="$bytecc -O $bytecclinkopts" +export cc cclibs verbose + +# Check C compiler + +sh ./runtest ansi.c +case $? in + 0) echo "The C compiler is ANSI-compliant.";; + 1) echo "The C compiler $cc is not ANSI-compliant." + echo "You need an ANSI C compiler to build Objective Caml." + exit 2;; + *) echo "Unable to compile the test program." + echo "Make sure the C compiler $cc is properly installed." + exit 2;; +esac + +# Check the sizes of data types + +echo "Checking the sizes of integers and pointers..." +set `sh ./runtest sizes.c` +case "$2,$3" in + 4,4) echo "OK, this is a regular 32 bit architecture." + echo "#undef ARCH_SIXTYFOUR" >> m.h + arch64=false;; + *,8) echo "Wow! A 64 bit architecture!" + echo "#define ARCH_SIXTYFOUR" >> m.h + arch64=true;; + *,*) echo "This architecture seems to be neither 32 bits nor 64 bits." + echo "Objective Caml won't run on this architecture." + exit 2;; + *) echo "Unable to compile the test program." + echo "Make sure the C compiler $cc is properly installed." + exit 2;; +esac +if test $1 != 4 && test $2 != 4 && test $4 != 4; then + echo "Sorry, we can't find a 32-bit integer type" + echo "(sizeof(short) = $4, sizeof(int) = $1, sizeof(long) = $2)" + echo "Objective Caml won't run on this architecture." + exit 2 +fi + +echo "#define SIZEOF_INT $1" >> m.h +echo "#define SIZEOF_LONG $2" >> m.h +echo "#define SIZEOF_PTR $3" >> m.h +echo "#define SIZEOF_SHORT $4" >> m.h + +if test $2 = 8; then + echo "#define ARCH_INT64_TYPE long" >> m.h + echo "#define ARCH_UINT64_TYPE unsigned long" >> m.h + echo '#define ARCH_INT64_PRINTF_FORMAT "l"' >> m.h + int64_native=true +else + sh ./runtest longlong.c + case $? in + 0) echo "64-bit \"long long\" integer type found (printf with \"%ll\")." + echo "#define ARCH_INT64_TYPE long long" >> m.h + echo "#define ARCH_UINT64_TYPE unsigned long long" >> m.h + echo '#define ARCH_INT64_PRINTF_FORMAT "ll"' >> m.h + int64_native=true;; + 1) echo "64-bit \"long long\" integer type found (printf with \"%q\")." + echo "#define ARCH_INT64_TYPE long long" >> m.h + echo "#define ARCH_UINT64_TYPE unsigned long long" >> m.h + echo '#define ARCH_INT64_PRINTF_FORMAT "q"' >> m.h + int64_native=true;; + 2) echo "64-bit \"long long\" integer type found (but no printf)." + echo "#define ARCH_INT64_TYPE long long" >> m.h + echo "#define ARCH_UINT64_TYPE unsigned long long" >> m.h + echo '#undef ARCH_INT64_PRINTF_FORMAT' >> m.h + int64_native=true;; + *) echo "No suitable 64-bit integer type found, will use software emulation." + echo "#undef ARCH_INT64_TYPE" >> m.h + echo "#undef ARCH_UINT64_TYPE" >> m.h + echo '#undef ARCH_INT64_PRINTF_FORMAT' >> m.h + int64_native=false;; + esac +fi + +if test $3 = 8 && test $int64_native = false; then + echo "This architecture has 64-bit pointers but no 64-bit integer type." + echo "Objective Caml won't run on this architecture." + exit 2 +fi + +# Determine endianness + +sh ./runtest endian.c +case $? in + 0) echo "This is a big-endian architecture." + echo "#define ARCH_BIG_ENDIAN" >> m.h;; + 1) echo "This is a little-endian architecture." + echo "#undef ARCH_BIG_ENDIAN" >> m.h;; + 2) echo "This architecture seems to be neither big endian nor little endian." + echo "Objective Caml won't run on this architecture." + exit 2;; + *) echo "Something went wrong during endianness determination." + echo "You'll have to figure out endianness yourself" + echo "(option ARCH_BIG_ENDIAN in m.h).";; +esac + +# Determine alignment constraints + +case "$host" in + sparc*-*-*|hppa*-*-*) + # On Sparc V9 with certain versions of gcc, determination of double + # alignment is not reliable (PR#1521), hence force it. + # Same goes for hppa. + # But there's a knack (PR#2572): + # if we're in 64-bit mode (sizeof(long) == 8), + # we must not doubleword-align floats... + if test $2 = 8; then + echo "Doubles can be word-aligned." + echo "#undef ARCH_ALIGN_DOUBLE" >> m.h + else + echo "Doubles must be doubleword-aligned." + echo "#define ARCH_ALIGN_DOUBLE" >> m.h + fi;; + *) + sh ./runtest dblalign.c + case $? in + 0) echo "Doubles can be word-aligned." + echo "#undef ARCH_ALIGN_DOUBLE" >> m.h;; + 1) echo "Doubles must be doubleword-aligned." + echo "#define ARCH_ALIGN_DOUBLE" >> m.h;; + *) echo "Something went wrong during alignment determination for doubles." + echo "I'm going to assume this architecture has alignment constraints over doubles." + echo "That's a safe bet: Objective Caml will work even if" + echo "this architecture has actually no alignment constraints." + echo "#define ARCH_ALIGN_DOUBLE" >> m.h;; + esac;; +esac + +if $int64_native; then + case "$host" in + sparc*-*-*|hppa*-*-*) + if test $2 = 8; then + echo "64-bit integers can be word-aligned." + echo "#undef ARCH_ALIGN_INT64" >> m.h + else + echo "64-bit integers must be doubleword-aligned." + echo "#define ARCH_ALIGN_INT64" >> m.h + fi;; + *) + sh ./runtest int64align.c + case $? in + 0) echo "64-bit integers can be word-aligned." + echo "#undef ARCH_ALIGN_INT64" >> m.h;; + 1) echo "64-bit integers must be doubleword-aligned." + echo "#define ARCH_ALIGN_INT64" >> m.h;; + *) echo "Something went wrong during alignment determination for 64-bit integers." + echo "I'm going to assume this architecture has alignment constraints." + echo "That's a safe bet: Objective Caml will work even if" + echo "this architecture has actually no alignment constraints." + echo "#define ARCH_ALIGN_INT64" >> m.h;; + esac + esac +else + echo "#undef ARCH_ALIGN_INT64" >> m.h +fi + +# Check semantics of division and modulus + +sh ./runtest divmod.c +case $? in + 0) echo "Native division and modulus have round-towards-zero semantics, will use them." + echo "#undef NONSTANDARD_DIV_MOD" >> m.h;; + 1) echo "Native division and modulus do not have round-towards-zero semantics, will use software emulation." + echo "#define NONSTANDARD_DIV_MOD" >> m.h;; + *) echo "Something went wrong while checking native division and modulus, please report it." + echo "#define NONSTANDARD_DIV_MOD" >> m.h;; +esac + +# Shared library support + +shared_libraries_supported=false +dl_needs_underscore=false +sharedcccompopts='' +mksharedlib='' +byteccrpath='' +mksharedlibrpath='' +natdynlinkopts="" +cmxs="cmxa" + +if test $withsharedlibs = "yes"; then + case "$host" in + *-*-cygwin*) + cmxs="cmxs" + mksharedlib="$flexlink" + mkmaindll="$flexlink -maindll" + shared_libraries_supported=true;; + *-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*) + cmxs="cmxs" + sharedcccompopts="-fPIC" + mksharedlib="$bytecc -shared" + bytecclinkopts="$bytecclinkopts -Wl,-E" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-Wl,-rpath," + natdynlinkopts="-Wl,-E" + shared_libraries_supported=true;; + alpha*-*-osf*) + case "$bytecc" in + gcc*) + sharedcccompopts="-fPIC" + mksharedlib="$bytecc -shared" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-Wl,-rpath," + shared_libraries_supported=true;; + cc*) + sharedcccompopts="" + mksharedlib="ld -shared -expect_unresolved '*'" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-rpath " + shared_libraries_supported=true;; + esac;; + *-*-solaris2*) + case "$bytecc" in + gcc*) + sharedcccompopts="-fPIC" + if sh ./solaris-ld; then + mksharedlib="$bytecc -shared" + byteccrpath="-R" + mksharedlibrpath="-R" + else + mksharedlib="$bytecc -shared" + bytecclinkopts="$bytecclinkopts -Wl,-E" + natdynlinkopts="-Wl,-E" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-Wl,-rpath," + fi + shared_libraries_supported=true;; + *) + sharedcccompopts="-KPIC" + byteccrpath="-R" + mksharedlibrpath="-R" + mksharedlib="/usr/ccs/bin/ld -G" + shared_libraries_supported=true;; + esac;; + mips*-*-irix[56]*) + case "$bytecc" in + cc*) sharedcccompopts="";; + gcc*) sharedcccompopts="-fPIC";; + esac + mksharedlib="ld -shared -rdata_shared" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-rpath " + shared_libraries_supported=true;; + i[3456]86-*-darwin*) + mksharedlib="$bytecc -bundle -flat_namespace -undefined suppress -read_only_relocs suppress" + bytecccompopts="$dl_defs $bytecccompopts" + dl_needs_underscore=false + shared_libraries_supported=true;; + *-apple-darwin*) + mksharedlib="$bytecc -bundle -flat_namespace -undefined suppress" + bytecccompopts="$dl_defs $bytecccompopts" + dl_needs_underscore=false + shared_libraries_supported=true;; + m88k-*-openbsd*) + shared_libraries_supported=false;; + vax-*-openbsd*) + shared_libraries_supported=false;; + *-*-openbsd*) + sharedcccompopts="-fPIC" + mksharedlib="$bytecc -shared" + bytecclinkopts="$bytecclinkopts -Wl,-E" + natdynlinkopts="-Wl,-E" + byteccrpath="-Wl,-rpath," + mksharedlibrpath="-Wl,-rpath," + shared_libraries_supported=true;; + esac +fi + +if test -z "$mkmaindll"; then + mkmaindll=$mksharedlib +fi + +# Configure the native-code compiler + +arch=none +model=default +system=unknown + +case "$host" in + alpha*-*-osf*) arch=alpha; system=digital;; + alpha*-*-linux*) arch=alpha; system=linux;; + alpha*-*-gnu*) arch=alpha; system=gnu;; + alpha*-*-freebsd*) arch=alpha; system=freebsd;; + alpha*-*-netbsd*) arch=alpha; system=netbsd;; + alpha*-*-openbsd*) arch=alpha; system=openbsd;; + sparc*-*-sunos4.*) arch=sparc; system=sunos;; + sparc*-*-solaris2.*) arch=sparc; system=solaris;; + sparc*-*-*bsd*) arch=sparc; system=bsd;; + sparc*-*-linux*) arch=sparc; system=linux;; + sparc*-*-gnu*) arch=sparc; system=gnu;; + i[3456]86-*-linux*) arch=i386; system=linux_`sh ./runtest elf.c`;; + i[3456]86-*-*bsd*) arch=i386; system=bsd_`sh ./runtest elf.c`;; + i[3456]86-*-nextstep*) arch=i386; system=nextstep;; + i[3456]86-*-solaris*) arch=i386; system=solaris;; + i[3456]86-*-beos*) arch=i386; system=beos;; + i[3456]86-*-cygwin*) arch=i386; system=cygwin;; + i[3456]86-*-darwin*) if $arch64; then + arch=amd64; system=macosx + else + arch=i386; system=macosx + fi;; + i[3456]86-*-gnu*) arch=i386; system=gnu;; + mips-*-irix6*) arch=mips; system=irix;; + hppa1.1-*-hpux*) arch=hppa; system=hpux;; + hppa2.0*-*-hpux*) arch=hppa; system=hpux;; + hppa*-*-linux*) arch=hppa; system=linux;; + hppa*-*-gnu*) arch=hppa; system=gnu;; + powerpc*-*-linux*) arch=power; model=ppc; system=elf;; + powerpc-*-netbsd*) arch=power; model=ppc; system=elf;; + powerpc-*-rhapsody*) arch=power; model=ppc; system=rhapsody;; + powerpc-*-darwin*) arch=power; system=rhapsody + if $arch64; then model=ppc64; else model=ppc; fi;; + arm*-*-linux*) arch=arm; system=linux;; + arm*-*-gnu*) arch=arm; system=gnu;; + ia64-*-linux*) arch=ia64; system=linux;; + ia64-*-gnu*) arch=ia64; system=gnu;; + ia64-*-freebsd*) arch=ia64; system=freebsd;; + x86_64-*-linux*) arch=amd64; system=linux;; + x86_64-*-gnu*) arch=amd64; system=gnu;; + x86_64-*-freebsd*) arch=amd64; system=freebsd;; + x86_64-*-netbsd*) arch=amd64; system=netbsd;; + x86_64-*-openbsd*) arch=amd64; system=openbsd;; + x86_64-*-darwin9.5) arch=amd64; system=macosx;; +esac + +# Some platforms exist both in 32-bit and 64-bit variants, not distinguished +# by $host. Turn off native code compilation on platforms where 64-bit mode +# is not supported. (PR#4441) + +if $arch64; then + case "$arch,$model" in + sparc,default|mips,default|hppa,default|power,ppc) + arch=none; model=default; system=unknown;; + esac +fi + +if test -z "$ccoption"; then + case "$arch,$system,$cc" in + alpha,digital,gcc*) nativecc=cc;; + mips,*,gcc*) nativecc=cc;; + *) nativecc="$bytecc";; + esac +else + nativecc="$ccoption" +fi + +nativecccompopts='' +nativecclinkopts='' +nativeccrpath="$byteccrpath" + +case "$arch,$nativecc,$system,$host_type" in + alpha,cc*,digital,*) nativecccompopts=-std1;; + mips,cc*,irix,*) nativecccompopts=-n32 + nativecclinkopts="-n32 -Wl,-woff,84";; + *,*,nextstep,*) nativecccompopts="$gcc_warnings -U__GNUC__ -posix" + nativecclinkopts="-posix";; + *,*,rhapsody,*darwin[1-5].*) + nativecccompopts="$gcc_warnings -DSHRINKED_GNUC";; + *,*,rhapsody,*) nativecccompopts="$gcc_warnings -DDARWIN_VERSION_6 $dl_defs" + if $arch64; then partialld="ld -r -arch ppc64"; fi;; + *,gcc*,cygwin,*) nativecccompopts="$gcc_warnings -U_WIN32";; + amd64,gcc*,macosx,*) partialld="ld -r -arch x86_64";; + *,gcc*,*,*) nativecccompopts="$gcc_warnings";; +esac + +asppprofflags='-DPROFILING' + +case "$arch,$model,$system" in + alpha,*,digital) as='as -O2 -nocpp' + aspp='as -O2' + asppprofflags='-pg -DPROFILING';; + alpha,*,*) as='as' + aspp='gcc -c';; + amd64,*,macosx) as='as -arch x86_64' + aspp='gcc -arch x86_64 -c';; + amd64,*,*) as='as' + aspp='gcc -c';; + arm,*,*) as='as'; + aspp='gcc -c';; + hppa,*,*) as='as'; + aspp='gcc -traditional -c';; + i386,*,solaris) as='as' + aspp='/usr/ccs/bin/as -P';; + i386,*,*) as='as' + aspp='gcc -c';; + ia64,*,*) as='as -xexplicit' + aspp='gcc -c -Wa,-xexplicit';; + mips,*,irix) as='as -n32 -O2 -nocpp -g0' + aspp='as -n32 -O2';; + power,*,elf) as='as -u -m ppc' + aspp='gcc -c';; + power,*,bsd) as='as' + aspp='gcc -c';; + power,*,rhapsody) as="as -arch $model" + aspp="$bytecc -c";; + sparc,*,solaris) as='as' + case "$cc" in + gcc*) aspp='gcc -c';; + *) aspp='as -P';; + esac;; + sparc,*,*) as='as' + aspp='gcc -c';; +esac + +if test -n "$asoption"; then as="$asoption"; fi +if test -n "$asppoption"; then aspp="$asppoption"; fi + +cc_profile='-pg' +case "$arch,$model,$system" in + alpha,*,digital) profiling='prof';; + i386,*,linux_elf) profiling='prof';; + i386,*,gnu) profiling='prof';; + i386,*,bsd_elf) profiling='prof';; + amd64,*,macosx) profiling='prof';; + i386,*,macosx) profiling='prof';; + sparc,*,solaris) + profiling='prof' + case "$nativecc" in gcc*) ;; *) cc_profile='-xpg';; esac;; + amd64,*,linux) profiling='prof';; + amd64,*,gnu) profiling='prof';; + *) profiling='noprof';; +esac + +# Where is ranlib? + +if sh ./searchpath ranlib; then + echo "ranlib found" + echo "RANLIB=ranlib" >> Makefile + echo "RANLIBCMD=ranlib" >> Makefile +else + echo "ranlib not used" + echo "RANLIB=ar rs" >> Makefile + echo "RANLIBCMD=" >> Makefile +fi + +# Do #! scripts work? + +if (SHELL=/bin/sh; export SHELL; (./sharpbang || ./sharpbang2) >/dev/null); then + echo "#! appears to work in shell scripts" + case "$host" in + *-*-sunos*|*-*-unicos*) + echo "We won't use it, though, because under SunOS and Unicos it breaks" + echo "on pathnames longer than 30 characters" + echo "SHARPBANGSCRIPTS=false" >> Makefile;; + *-*-cygwin*) + echo "We won't use it, though, because of conflicts with .exe extension" + echo "under Cygwin" + echo "SHARPBANGSCRIPTS=false" >> Makefile;; + *) + echo "SHARPBANGSCRIPTS=true" >> Makefile;; + esac +else + echo "No support for #! in shell scripts" + echo "SHARPBANGSCRIPTS=false" >> Makefile +fi + +# Write the OS type (Unix or Cygwin) + +echo "#define OCAML_OS_TYPE \"$ostype\"" >> s.h +echo "#define OCAML_STDLIB_DIR \"$libdir\"" >> s.h + +# Use 64-bit file offset if possible + +bytecccompopts="$bytecccompopts -D_FILE_OFFSET_BITS=64" +nativecccompopts="$nativecccompopts -D_FILE_OFFSET_BITS=64" + +# Check the semantics of signal handlers + +if sh ./hasgot sigaction sigprocmask; then + echo "POSIX signal handling found." + echo "#define POSIX_SIGNALS" >> s.h +else + if sh ./runtest signals.c; then + echo "Signals have the BSD semantics." + echo "#define BSD_SIGNALS" >> s.h + else + echo "Signals have the System V semantics." + fi + if sh ./hasgot sigsetmask; then + echo "sigsetmask() found" + echo "#define HAS_SIGSETMASK" >> s.h + fi +fi + +# For the sys module + +if sh ./hasgot getrusage; then + echo "getrusage() found." + echo "#define HAS_GETRUSAGE" >> s.h +fi + +if sh ./hasgot times; then + echo "times() found." + echo "#define HAS_TIMES" >> s.h +fi + +# For the terminfo module + +if test "$withcurses" = "yes"; then + for libs in "" "-lcurses" "-ltermcap" "-lcurses -ltermcap" "-lncurses"; do + if sh ./hasgot $libs tgetent tgetstr tgetnum tputs; then + echo "termcap functions found (with libraries '$libs')" + echo "#define HAS_TERMCAP" >> s.h + curseslibs="${libs}" + break + fi + done +fi + +# Configuration for the libraries + +otherlibraries="unix str num dynlink bigarray" + +# For the Unix library + +has_sockets=no +if sh ./hasgot socket socketpair bind listen accept connect; then + echo "You have BSD sockets." + echo "#define HAS_SOCKETS" >> s.h + has_sockets=yes +elif sh ./hasgot -lnsl -lsocket socket socketpair bind listen accept connect; then + echo "You have BSD sockets (with libraries '-lnsl -lsocket')" + cclibs="$cclibs -lnsl -lsocket" + echo "#define HAS_SOCKETS" >> s.h + has_sockets=yes +fi + +if sh ./hasgot -i sys/socket.h -t socklen_t; then + echo "socklen_t is defined in " + echo "#define HAS_SOCKLEN_T" >> s.h +fi + +if sh ./hasgot inet_aton; then + echo "inet_aton() found." + echo "#define HAS_INET_ATON" >> s.h +fi + +if sh ./hasgot -i sys/types.h -i sys/socket.h -i netinet/in.h \ + -t 'struct sockaddr_in6' \ +&& sh ./hasgot getaddrinfo getnameinfo inet_pton inet_ntop; then + echo "IPv6 is supported." + echo "#define HAS_IPV6" >> s.h +fi + +if sh ./hasgot -i unistd.h; then + echo "unistd.h found." + echo "#define HAS_UNISTD" >> s.h +fi + +if sh ./hasgot -i sys/types.h -t off_t; then + echo "off_t is defined in " + echo "#define HAS_OFF_T" >> s.h +fi + +if sh ./hasgot -i sys/types.h -i dirent.h; then + echo "dirent.h found." + echo "#define HAS_DIRENT" >> s.h +fi + +if sh ./hasgot rewinddir; then + echo "rewinddir() found." + echo "#define HAS_REWINDDIR" >> s.h +fi + +if sh ./hasgot lockf; then + echo "lockf() found." + echo "#define HAS_LOCKF" >> s.h +fi + +if sh ./hasgot mkfifo; then + echo "mkfifo() found." + echo "#define HAS_MKFIFO" >> s.h +fi + +if sh ./hasgot getcwd; then + echo "getcwd() found." + echo "#define HAS_GETCWD" >> s.h +fi + +if sh ./hasgot getwd; then + echo "getwd() found." + echo "#define HAS_GETWD" >> s.h +fi + +if sh ./hasgot getpriority setpriority; then + echo "getpriority() found." + echo "#define HAS_GETPRIORITY" >> s.h +fi + +if sh ./hasgot -i sys/types.h -i utime.h && sh ./hasgot utime; then + echo "utime() found." + echo "#define HAS_UTIME" >> s.h +fi + +if sh ./hasgot utimes; then + echo "utimes() found." + echo "#define HAS_UTIMES" >> s.h +fi + +if sh ./hasgot dup2; then + echo "dup2() found." + echo "#define HAS_DUP2" >> s.h +fi + +if sh ./hasgot fchmod fchown; then + echo "fchmod() found." + echo "#define HAS_FCHMOD" >> s.h +fi + +if sh ./hasgot truncate ftruncate; then + echo "truncate() found." + echo "#define HAS_TRUNCATE" >> s.h +fi + +select_include='' +if sh ./hasgot -i sys/types.h -i sys/select.h; then + echo "sys/select.h found." + echo "#define HAS_SYS_SELECT_H" >> s.h + select_include='-i sys/select.h' +fi + +has_select=no +if sh ./hasgot select && \ + sh ./hasgot -i sys/types.h $select_include -t fd_set ; then + echo "select() found." + echo "#define HAS_SELECT" >> s.h + has_select=yes +fi + +if sh ./hasgot symlink readlink lstat; then + echo "symlink() found." + echo "#define HAS_SYMLINK" >> s.h +fi + +has_wait=no +if sh ./hasgot waitpid; then + echo "waitpid() found." + echo "#define HAS_WAITPID" >> s.h + has_wait=yes +fi + +if sh ./hasgot wait4; then + echo "wait4() found." + echo "#define HAS_WAIT4" >> s.h + has_wait=yes +fi + +if sh ./hasgot -i limits.h && sh ./runtest getgroups.c; then + echo "getgroups() found." + echo "#define HAS_GETGROUPS" >> s.h +fi + +if sh ./hasgot -i termios.h && + sh ./hasgot tcgetattr tcsetattr tcsendbreak tcflush tcflow; then + echo "POSIX termios found." + echo "#define HAS_TERMIOS" >> s.h +fi + +# Async I/O under OSF1 3.x are so buggy that the test program hangs... +testasyncio=true +if test -f /usr/bin/uname; then + case "`/usr/bin/uname -s -r`" in + "OSF1 V3."*) testasyncio=false;; + esac +fi +if $testasyncio && sh ./runtest async_io.c; then + echo "Asynchronous I/O are supported." + echo "#define HAS_ASYNC_IO" >> s.h +fi + +has_setitimer=no +if sh ./hasgot setitimer; then + echo "setitimer() found." + echo "#define HAS_SETITIMER" >> s.h + has_setitimer="yes" +fi + +if sh ./hasgot gethostname; then + echo "gethostname() found." + echo "#define HAS_GETHOSTNAME" >> s.h +fi + +if sh ./hasgot -i sys/utsname.h && sh ./hasgot uname; then + echo "uname() found." + echo "#define HAS_UNAME" >> s.h +fi + +has_gettimeofday=no +if sh ./hasgot gettimeofday; then + echo "gettimeofday() found." + echo "#define HAS_GETTIMEOFDAY" >> s.h + has_gettimeofday="yes" +fi + +if sh ./hasgot mktime; then + echo "mktime() found." + echo "#define HAS_MKTIME" >> s.h +fi + +case "$host" in + *-*-cygwin*) ;; # setsid emulation under Cygwin breaks the debugger + *) if sh ./hasgot setsid; then + echo "setsid() found." + echo "#define HAS_SETSID" >> s.h + fi;; +esac + +if sh ./hasgot putenv; then + echo "putenv() found." + echo "#define HAS_PUTENV" >> s.h +fi + +if sh ./hasgot -i locale.h && sh ./hasgot setlocale; then + echo "setlocale() and found." + echo "#define HAS_LOCALE" >> s.h +fi + + +if sh ./hasgot $dllib dlopen; then + echo "dlopen() found." +elif sh ./hasgot $dllib -ldl dlopen; then + echo "dlopen() found in -ldl." + dllib="$dllib -ldl" +else + shared_libraries_supported=false +fi + +if $shared_libraries_supported; then + echo "Dynamic loading of shared libraries is supported." + echo "#define SUPPORT_DYNAMIC_LINKING" >> s.h + if $dl_needs_underscore; then + echo '#define DL_NEEDS_UNDERSCORE' >>s.h + fi +fi + +if sh ./hasgot -i sys/types.h -i sys/mman.h && sh ./hasgot mmap munmap; then + echo "mmap() found." + echo "#define HAS_MMAP" >> s.h +fi + +nargs=none +for i in 5 6; do + if sh ./trycompile -DNUM_ARGS=${i} gethostbyname.c; then nargs=$i; break; fi +done +if test $nargs != "none"; then + echo "gethostbyname_r() found (with ${nargs} arguments)." + echo "#define HAS_GETHOSTBYNAME_R $nargs" >> s.h +fi + +nargs=none +for i in 7 8; do + if sh ./trycompile -DNUM_ARGS=${i} gethostbyaddr.c; then nargs=$i; break; fi +done +if test $nargs != "none"; then + echo "gethostbyaddr_r() found (with ${nargs} arguments)." + echo "#define HAS_GETHOSTBYADDR_R $nargs" >> s.h +fi + +# Determine if the debugger is supported + +if test "$has_sockets" = "yes"; then + echo "Replay debugger supported." + debugger="ocamldebugger" +else + echo "No replay debugger (missing system calls)" + debugger="" +fi + + +# Determine if system stack overflows can be detected + +case "$arch,$system" in + i386,linux_elf|amd64,linux|power,rhapsody|amd64,macosx|i386,macosx|amd64,macosx) + echo "System stack overflow can be detected." + echo "#define HAS_STACK_OVERFLOW_DETECTION" >> s.h;; + *) + echo "Cannot detect system stack overflow.";; +esac + +x# Determine the target architecture for the "num" library + +case "$arch" in + alpha) bng_arch=alpha; bng_asm_level=1;; + i386) bng_arch=ia32 + if sh ./trycompile ia32sse2.c + then bng_asm_level=2 + else bng_asm_level=1 + fi;; + mips) bng_arch=mips; bng_asm_level=1;; + power) bng_arch=ppc; bng_asm_level=1;; + sparc) bng_arch=sparc; bng_asm_level=1;; + amd64) bng_arch=amd64; bng_asm_level=1;; + *) bng_arch=generic; bng_asm_level=0;; +esac + +echo "BNG_ARCH=$bng_arch" >> Makefile +echo "BNG_ASM_LEVEL=$bng_asm_level" >> Makefile + +# Determine if the POSIX threads library is supported + +systhread_support=false + +if test "$pthread_wanted" = "yes"; then + case "$host" in + *-*-solaris*) pthread_link="-lpthread -lposix4" + pthread_caml_link="-cclib -lpthread -cclib -lposix4";; + *-*-freebsd*) pthread_link="-pthread" + pthread_caml_link="-cclib -pthread";; + *-*-openbsd*) pthread_link="-pthread" + pthread_caml_link="-cclib -pthread";; + *) pthread_link="-lpthread" + pthread_caml_link="-cclib -lpthread";; + esac + if ./hasgot -i pthread.h $pthread_link pthread_self; then + echo "POSIX threads library supported." + systhread_support=true + otherlibraries="$otherlibraries systhreads" + bytecccompopts="$bytecccompopts -D_REENTRANT" + nativecccompopts="$nativecccompopts -D_REENTRANT" + case "$host" in + *-*-freebsd*) + bytecccompopts="$bytecccompopts -D_THREAD_SAFE" + nativecccompopts="$nativecccompopts -D_THREAD_SAFE";; + *-*-openbsd*) + bytecccompopts="$bytecccompopts -pthread" + asppflags="$asppflags -pthread" + nativecccompopts="$nativecccompopts -pthread";; + esac + echo "Options for linking with POSIX threads: $pthread_link" + if sh ./hasgot $pthread_link sigwait; then + echo "sigwait() found" + echo "#define HAS_SIGWAIT" >> s.h + fi + else + echo "POSIX threads not found." + pthread_link="" + fi +else + pthread_link="" +fi +echo "PTHREAD_LINK=$pthread_caml_link" >> Makefile + +# Determine if the bytecode thread library is supported + +if test "$has_select" = "yes" \ +&& test "$has_setitimer" = "yes" \ +&& test "$has_gettimeofday" = "yes" \ +&& test "$has_wait" = "yes"; then + echo "Bytecode threads library supported." + otherlibraries="$otherlibraries threads" +else + echo "Bytecode threads library not supported (missing system calls)" +fi + +# Determine the location of X include files and libraries + +x11_include="not found" +x11_link="not found" + +for dir in \ + $x11_include_dir \ + \ + /usr/X11R6/include \ + /usr/include/X11R6 \ + /usr/local/X11R6/include \ + /usr/local/include/X11R6 \ + /opt/X11R6/include \ + \ + /usr/X11/include \ + /usr/include/X11 \ + /usr/local/X11/include \ + /usr/local/include/X11 \ + /opt/X11/include \ + \ + /usr/X11R5/include \ + /usr/include/X11R5 \ + /usr/local/X11R5/include \ + /usr/local/include/X11R5 \ + /usr/local/x11r5/include \ + /opt/X11R5/include \ + \ + /usr/X11R4/include \ + /usr/include/X11R4 \ + /usr/local/X11R4/include \ + /usr/local/include/X11R4 \ + \ + /usr/X386/include \ + /usr/x386/include \ + /usr/XFree86/include/X11 \ + \ + /usr/include \ + /usr/local/include \ + /usr/unsupported/include \ + /usr/athena/include \ + /usr/lpp/Xamples/include \ + \ + /usr/openwin/include \ + /usr/openwin/share/include \ + ; \ +do + if test -f $dir/X11/X.h; then + x11_include=$dir + break + fi +done + +if test "$x11_include" = "not found"; then + x11_try_lib_dir='' +else + x11_try_lib_dir=`echo $x11_include | sed -e 's|include|lib|'` +fi + +for dir in \ + $x11_lib_dir \ + $x11_try_lib_dir \ + \ + /usr/X11R6/lib64 \ + /usr/X11R6/lib \ + /usr/lib/X11R6 \ + /usr/local/X11R6/lib \ + /usr/local/lib/X11R6 \ + /opt/X11R6/lib \ + \ + /usr/X11/lib \ + /usr/lib/X11 \ + /usr/local/X11/lib \ + /usr/local/lib/X11 \ + /opt/X11/lib \ + \ + /usr/X11R5/lib \ + /usr/lib/X11R5 \ + /usr/local/X11R5/lib \ + /usr/local/lib/X11R5 \ + /usr/local/x11r5/lib \ + /opt/X11R5/lib \ + \ + /usr/X11R4/lib \ + /usr/lib/X11R4 \ + /usr/local/X11R4/lib \ + /usr/local/lib/X11R4 \ + \ + /usr/X386/lib \ + /usr/x386/lib \ + /usr/XFree86/lib/X11 \ + \ + /usr/lib64 \ + /usr/lib \ + /usr/local/lib \ + /usr/unsupported/lib \ + /usr/athena/lib \ + /usr/lpp/Xamples/lib \ + /lib/usr/lib/X11 \ + \ + /usr/openwin/lib \ + /usr/openwin/share/lib \ + ; \ +do + if test -f $dir/libX11.a || \ + test -f $dir/libX11.so || \ + test -f $dir/libX11.dll.a || \ + test -f $dir/libX11.dylib || \ + test -f $dir/libX11.sa; then + if test $dir = /usr/lib; then + x11_link="-lX11" + else + x11_libs="-L$dir" + case "$host" in + *-*-*bsd*) x11_link="-R$dir -L$dir -lX11";; + *) x11_link="-L$dir -lX11";; + esac + fi + break + fi +done + + +if test "$x11_include" = "not found" || test "$x11_link" = "not found" +then + echo "X11 not found, the \"graph\" library will not be supported." + x11_include="" +else + echo "Location of X11 include files: $x11_include/X11" + echo "Options for linking with X11: $x11_link" + otherlibraries="$otherlibraries graph" + if test "$x11_include" = "/usr/include"; then + x11_include="" + else + x11_include="-I$x11_include" + fi +fi +echo "X11_INCLUDES=$x11_include" >> Makefile +echo "X11_LINK=$x11_link" >> Makefile + +# See if we can compile the dbm library + +dbm_include="not found" +dbm_link="not found" +use_gdbm_ndbm=no + +for dir in /usr/include /usr/include/db1 /usr/include/gdbm; do + if test -f $dir/ndbm.h; then + dbm_include=$dir + if sh ./hasgot dbm_open; then + dbm_link="" + elif sh ./hasgot -lndbm dbm_open; then + dbm_link="-lndbm" + elif sh ./hasgot -ldb1 dbm_open; then + dbm_link="-ldb1" + elif sh ./hasgot -lgdbm dbm_open; then + dbm_link="-lgdbm" + elif sh ./hasgot -lgdbm_compat -lgdbm dbm_open; then + dbm_link="-lgdbm_compat -lgdbm" + fi + break + fi + if test -f $dir/gdbm-ndbm.h; then + dbm_include=$dir + use_gdbm_ndbm=yes + if sh ./hasgot -lgdbm_compat -lgdbm dbm_open; then + dbm_link="-lgdbm_compat -lgdbm" + fi + break + fi +done +if test "$dbm_include" = "not found" || test "$dbm_link" = "not found"; then + echo "NDBM not found, the \"dbm\" library will not be supported." +else + echo "NDBM found (in $dbm_include)" + if test "$dbm_include" = "/usr/include"; then + dbm_include="" + else + dbm_include="-I$dbm_include" + fi + if test "$use_gdbm_ndbm" = "yes"; then + echo "#define DBM_USES_GDBM_NDBM" >> s.h + fi + otherlibraries="$otherlibraries dbm" +fi +echo "DBM_INCLUDES=$dbm_include" >> Makefile +echo "DBM_LINK=$dbm_link" >> Makefile + +# Look for tcl/tk + +echo "Configuring LablTk..." + +if test $tk_wanted = no; then + has_tk=false +elif test $tk_x11 = no; then + has_tk=true +elif test "$x11_include" = "not found" || test "$x11_link" = "not found"; then + echo "X11 not found." + has_tk=false +else + tk_x11_include="$x11_include" + tk_x11_libs="$x11_libs -lX11" + has_tk=true +fi + +if test $has_tk = true; then + tcl_version='' + tcl_version=`sh ./runtest $tk_defs $tk_x11_include tclversion.c` + for tk_incs in \ + "-I/usr/local/include" \ + "-I/usr/include" \ + "-I/usr/local/include/tcl8.5 -I/usr/local/include/tk8.5" \ + "-I/usr/include/tcl8.5 -I/usr/include/tk8.5" \ + "-I/usr/local/include/tcl8.4 -I/usr/local/include/tk8.4" \ + "-I/usr/include/tcl8.4 -I/usr/include/tk8.4" \ + "-I/usr/local/include/tcl8.3 -I/usr/local/include/tk8.3" \ + "-I/usr/include/tcl8.3 -I/usr/include/tk8.3" \ + "-I/usr/local/include/tcl8.2 -I/usr/local/include/tk8.2" \ + "-I/usr/include/tcl8.2 -I/usr/include/tk8.2" \ + "-I/sw/include" \ + "-I/usr/pkg/include" + do if test -z "$tcl_version"; then + tk_defs="$tk_incs" + tcl_version=`sh ./runtest $tk_defs $tk_x11_include tclversion.c` + fi; done + if test -n "$tcl_version" && test "x$tcl_version" != "xnone"; then + echo "tcl.h and tk.h version $tcl_version found with \"$tk_defs\"." + case $tcl_version in + 7.5) tclmaj=7 tclmin=5 tkmaj=4 tkmin=1 ;; + 7.6) tclmaj=7 tclmin=6 tkmaj=4 tkmin=2 ;; + 8.0) tclmaj=8 tclmin=0 tkmaj=8 tkmin=0 ;; + 8.1) tclmaj=8 tclmin=1 tkmaj=8 tkmin=1 ;; + 8.2) tclmaj=8 tclmin=2 tkmaj=8 tkmin=2 ;; + 8.3) tclmaj=8 tclmin=3 tkmaj=8 tkmin=3 ;; + 8.4) tclmaj=8 tclmin=4 tkmaj=8 tkmin=4 ;; + 8.5) tclmaj=8 tclmin=5 tkmaj=8 tkmin=5 ;; + *) echo "This version is not known."; has_tk=false ;; + esac + else + echo "tcl.h and/or tk.h not found." + has_tk=false + fi +fi + +tkauxlibs="$mathlib $dllib" +tcllib='' +tklib='' +if test $has_tk = true; then + if test -n "$tk_libs" && \ + sh ./hasgot $tk_libs $tk_x11_libs $tkauxlibs Tcl_DoOneEvent + then tk_libs="$tk_libs $dllib" + elif sh ./hasgot $tk_libs -ltcl$tclmaj.$tclmin $tkauxlibs Tcl_DoOneEvent + then + tk_libs="$tk_libs -ltk$tkmaj.$tkmin -ltcl$tclmaj.$tclmin $dllib" + elif sh ./hasgot $tk_libs -ltcl$tclmaj$tclmin $tkauxlibs Tcl_DoOneEvent + then + tk_libs="$tk_libs -ltk$tkmaj$tkmin -ltcl$tclmaj$tclmin $dllib" + elif test -z "$tk_libs" && tk_libs=-L/usr/local/lib && \ + sh ./hasgot $tk_libs -ltcl$tclmaj.$tclmin $tkauxlibs Tcl_DoOneEvent + then + tk_libs="$tk_libs -ltk$tkmaj.$tkmin -ltcl$tclmaj.$tclmin $dllib" + elif sh ./hasgot $tk_libs -ltcl$tclmaj$tclmin $tkauxlibs Tcl_DoOneEvent + then + tk_libs="$tk_libs -ltk$tkmaj$tkmin -ltcl$tclmaj$tclmin $dllib" + elif sh ./hasgot -L/sw/lib $tk_libs -ltcl$tclmaj.$tclmin $tkauxlibs \ + Tcl_DoOneEvent + then tk_libs="-L/sw/lib -ltk$tkmaj.$tkmin -ltcl$tclmaj.$tclmin $dllib" + elif sh ./hasgot -L/usr/pkg/lib $tk_libs $tk_x11_libs \ + -ltk$tkmaj$tkmin -ltcl$tclmaj$tclmin -lpthread $tkauxlibs \ + Tcl_DoOneEvent + then + case "$host" in + *-*-*bsd*) tk_libs="-R/usr/pkg/lib -L/usr/pkg/lib $tk_libs $tk_x11_libs -ltk$tkmaj$tkmin -ltcl$tclmaj$tclmin -lpthread $tkauxlibs";; + *) tk_libs="-L/usr/pkg/lib $tk_libs $tk_x11_libs -ltk$tkmaj$tkmin -ltcl$tclmaj$tclmin -lpthread $tkauxlibs";; + esac + else + echo "Tcl library not found." + has_tk=false + fi +fi + +if test $has_tk = true; then + if sh ./hasgot $tk_libs $tk_x11_libs $tkauxlibs Tk_SetGrid; then + echo "Tcl/Tk libraries found." + elif sh ./hasgot -L/sw/lib $tk_libs $tk_x11_libs $tkauxlibs Tk_SetGrid; then + case "$host" in + *-*-*bsd*) tk_libs="-R/sw/lib -L/sw/lib $tk_libs";; + *) tk_libs="-L/sw/lib $tk_libs";; + esac + echo "Tcl/Tk libraries found." + elif sh ./hasgot -L/usr/pkg/lib $tk_libs $tk_x11_libs $tkauxlibs \ + Tk_SetGrid; then + case "$host" in + *-*-*bsd*) tk_libs="-R/usr/pkg/lib -L/usr/pkg/lib $tk_libs";; + *) tk_libs="-L/usr/pkg/lib $tk_libs";; + esac + echo "Tcl/Tk libraries found." + else + echo "Tcl library found." + echo "Tk library not found." + has_tk=false + fi +fi + +if test $has_tk = true; then + if test $tk_x11 = yes; then + echo "TK_DEFS=$tk_defs "'$(X11_INCLUDES)' >> Makefile + echo "TK_LINK=$tk_libs "'$(X11_LINK)' >> Makefile + else + echo "TK_DEFS=$tk_defs" >> Makefile + echo "TK_LINK=$tk_libs" >> Makefile + fi + otherlibraries="$otherlibraries labltk" +else + echo "Configuration failed, LablTk will not be built." + echo "TK_DEFS=" >> Makefile + echo "TK_LINK=" >> Makefile +fi + +# Final twiddling of compiler options to work around known bugs + +nativeccprofopts="$nativecccompopts" +case "$buggycc" in + gcc.2.96) + bytecccompopts="$bytecccompopts -fomit-frame-pointer" + nativecccompopts="$nativecccompopts -fomit-frame-pointer";; +esac + +# Finish generated files + +cclibs="$cclibs $mathlib" + +echo "BYTECC=$bytecc" >> Makefile +echo "BYTECCCOMPOPTS=$bytecccompopts" >> Makefile +echo "BYTECCLINKOPTS=$bytecclinkopts" >> Makefile +echo "BYTECCLIBS=$cclibs $dllib $curseslibs $pthread_link" >> Makefile +echo "BYTECCRPATH=$byteccrpath" >> Makefile +echo "EXE=$exe" >> Makefile +echo "SUPPORTS_SHARED_LIBRARIES=$shared_libraries_supported" >> Makefile +echo "SHAREDCCCOMPOPTS=$sharedcccompopts" >> Makefile +echo "MKSHAREDLIBRPATH=$mksharedlibrpath" >> Makefile +echo "NATDYNLINKOPTS=$natdynlinkopts" >> Makefile +cat >> Makefile <> Makefile +echo "MODEL=$model" >> Makefile +echo "SYSTEM=$system" >> Makefile +echo "NATIVECC=$nativecc" >> Makefile +echo "NATIVECCCOMPOPTS=$nativecccompopts" >> Makefile +echo "NATIVECCPROFOPTS=$nativeccprofopts" >> Makefile +echo "NATIVECCLINKOPTS=$nativecclinkopts" >> Makefile +echo "NATIVECCRPATH=$nativeccrpath" >> Makefile +echo "NATIVECCLIBS=$cclibs $dllib" >> Makefile +echo "ASM=$as" >> Makefile +echo "ASPP=$aspp" >> Makefile +echo "ASPPPROFFLAGS=$asppprofflags" >> Makefile +echo "PROFILING=$profiling" >> Makefile +echo "DYNLINKOPTS=$dllib" >> Makefile +echo "OTHERLIBRARIES=$otherlibraries" >> Makefile +echo "DEBUGGER=$debugger" >> Makefile +echo "CC_PROFILE=$cc_profile" >> Makefile +echo "SYSTHREAD_SUPPORT=$systhread_support" >> Makefile +echo "PARTIALLD=$partialld" >> Makefile +echo "PACKLD=\$(PARTIALLD) \$(NATIVECCLINKOPTS) -o " >> Makefile +echo "DLLCCCOMPOPTS=$dllccompopts" >> Makefile +echo "IFLEXDIR=$iflexdir" >> Makefile +echo "O=o" >> Makefile +echo "A=a" >> Makefile +echo "SO=so" >> Makefile +echo "EXT_OBJ=.o" >> Makefile +echo "EXT_ASM=.s" >> Makefile +echo "EXT_LIB=.a" >> Makefile +echo "EXT_DLL=.so" >> Makefile +echo "EXTRALIBS=" >> Makefile +echo "CCOMPTYPE=cc" >> Makefile +echo "TOOLCHAIN=cc" >> Makefile +echo "CMXS=$cmxs" >> Makefile +echo "MKEXE=$mkexe" >> Makefile +echo "MKDLL=$mksharedlib" >> Makefile +echo "MKMAINDLL=$mkmaindll" >> Makefile + +rm -f tst hasgot.c +rm -f ../m.h ../s.h ../Makefile +mv m.h s.h Makefile .. + +# Print a summary + +echo +echo "** Configuration summary **" +echo +echo "Directories where Objective Caml will be installed:" +echo " binaries.................. $bindir" +echo " standard library.......... $libdir" +echo " manual pages.............. $mandir (with extension .$manext)" + +echo "Configuration for the bytecode compiler:" +echo " C compiler used........... $bytecc" +echo " options for compiling..... $bytecccompopts" +echo " options for linking....... $bytecclinkopts $cclibs $dllib $curseslibs $pthread_link" +if $shared_libraries_supported; then +echo " shared libraries are supported" +echo " options for compiling..... $sharedcccompopts $bytecccompopts" +echo " command for building...... $mksharedlib -o lib.so $mksharedlibrpath/a/path objs" +else +echo " shared libraries not supported" +fi + +echo "Configuration for the native-code compiler:" +if test "$arch" = "none"; then + echo " (not supported on this platform)" +else + if test "$model" = "default"; then + echo " hardware architecture..... $arch" + else + echo " hardware architecture..... $arch ($model)" + fi + if test "$system" = "unknown"; then : ; else + echo " OS variant................ $system" + fi + echo " C compiler used........... $nativecc" + echo " options for compiling..... $nativecccompopts" + echo " options for linking....... $nativecclinkopts $cclibs" + echo " assembler ................ $as" + echo " preprocessed assembler ... $aspp" + if test "$profiling" = "prof"; then + echo " profiling with gprof ..... supported" + else + echo " profiling with gprof ..... not supported" + fi +fi + +if test "$debugger" = "ocamldebugger"; then + echo "Source-level replay debugger: supported" +else + echo "Source-level replay debugger: not supported" +fi + +echo "Additional libraries supported:" +echo " $otherlibraries" + +echo "Configuration for the \"num\" library:" +echo " target architecture ...... $bng_arch (asm level $bng_asm_level)" + +if test "$x11_include" != "not found" && test "$x11_lib" != "not found"; then +echo "Configuration for the \"graph\" library:" +echo " options for compiling .... $x11_include" +echo " options for linking ...... $x11_link" +fi + +if test $has_tk = true; then +echo "Configuration for the \"labltk\" library:" +echo " use tcl/tk version ....... $tcl_version" +echo " options for compiling .... $tk_defs" +echo " options for linking ...... $tk_libs" +else +echo "The \"labltk\" library: not supported" +fi + +echo +echo "** Objective Caml configuration completed successfully **" +echo diff --git a/debugger/.cvsignore b/debugger/.cvsignore new file mode 100644 index 0000000..b608cf5 --- /dev/null +++ b/debugger/.cvsignore @@ -0,0 +1,4 @@ +lexer.ml +parser.ml +parser.mli +ocamldebug diff --git a/debugger/.depend b/debugger/.depend new file mode 100644 index 0000000..afac5c0 --- /dev/null +++ b/debugger/.depend @@ -0,0 +1,220 @@ +breakpoints.cmi: primitives.cmi ../bytecomp/instruct.cmi +checkpoints.cmi: primitives.cmi debugcom.cmi +command_line.cmi: +debugcom.cmi: primitives.cmi +debugger_config.cmi: +dynlink.cmi: +envaux.cmi: ../typing/path.cmi ../bytecomp/instruct.cmi ../typing/env.cmi +eval.cmi: ../typing/types.cmi ../typing/path.cmi parser_aux.cmi \ + ../parsing/longident.cmi ../bytecomp/instruct.cmi ../typing/ident.cmi \ + ../typing/env.cmi debugcom.cmi +events.cmi: ../bytecomp/instruct.cmi +exec.cmi: +frames.cmi: primitives.cmi ../bytecomp/instruct.cmi +history.cmi: +input_handling.cmi: primitives.cmi +int64ops.cmi: +lexer.cmi: parser.cmi +loadprinter.cmi: ../parsing/longident.cmi dynlink.cmi +parameters.cmi: +parser.cmi: parser_aux.cmi ../parsing/longident.cmi +parser_aux.cmi: primitives.cmi ../parsing/longident.cmi +pattern_matching.cmi: ../typing/typedtree.cmi parser_aux.cmi debugcom.cmi +pos.cmi: ../bytecomp/instruct.cmi +primitives.cmi: ../otherlibs/unix/unix.cmi +printval.cmi: ../typing/types.cmi ../typing/path.cmi parser_aux.cmi \ + ../typing/env.cmi debugcom.cmi +program_loading.cmi: primitives.cmi +program_management.cmi: +question.cmi: +show_information.cmi: ../bytecomp/instruct.cmi +show_source.cmi: ../bytecomp/instruct.cmi +source.cmi: +symbols.cmi: ../bytecomp/instruct.cmi +time_travel.cmi: primitives.cmi +trap_barrier.cmi: +unix_tools.cmi: ../otherlibs/unix/unix.cmi +breakpoints.cmo: symbols.cmi source.cmi primitives.cmi pos.cmi \ + ../bytecomp/instruct.cmi exec.cmi debugcom.cmi checkpoints.cmi \ + breakpoints.cmi +breakpoints.cmx: symbols.cmx source.cmx primitives.cmx pos.cmx \ + ../bytecomp/instruct.cmx exec.cmx debugcom.cmx checkpoints.cmx \ + breakpoints.cmi +checkpoints.cmo: primitives.cmi int64ops.cmi debugcom.cmi checkpoints.cmi +checkpoints.cmx: primitives.cmx int64ops.cmx debugcom.cmx checkpoints.cmi +command_line.cmo: unix_tools.cmi ../otherlibs/unix/unix.cmi \ + ../typing/types.cmi time_travel.cmi symbols.cmi source.cmi \ + show_source.cmi show_information.cmi question.cmi program_management.cmi \ + program_loading.cmi printval.cmi primitives.cmi pos.cmi parser_aux.cmi \ + parser.cmi parameters.cmi ../utils/misc.cmi ../parsing/location.cmi \ + loadprinter.cmi lexer.cmi int64ops.cmi ../bytecomp/instruct.cmi \ + input_handling.cmi history.cmi frames.cmi events.cmi eval.cmi envaux.cmi \ + debugger_config.cmi debugcom.cmi ../typing/ctype.cmi ../utils/config.cmi \ + checkpoints.cmi breakpoints.cmi command_line.cmi +command_line.cmx: unix_tools.cmx ../otherlibs/unix/unix.cmx \ + ../typing/types.cmx time_travel.cmx symbols.cmx source.cmx \ + show_source.cmx show_information.cmx question.cmx program_management.cmx \ + program_loading.cmx printval.cmx primitives.cmx pos.cmx parser_aux.cmi \ + parser.cmx parameters.cmx ../utils/misc.cmx ../parsing/location.cmx \ + loadprinter.cmx lexer.cmx int64ops.cmx ../bytecomp/instruct.cmx \ + input_handling.cmx history.cmx frames.cmx events.cmx eval.cmx envaux.cmx \ + debugger_config.cmx debugcom.cmx ../typing/ctype.cmx ../utils/config.cmx \ + checkpoints.cmx breakpoints.cmx command_line.cmi +debugcom.cmo: primitives.cmi ../utils/misc.cmi int64ops.cmi \ + input_handling.cmi debugcom.cmi +debugcom.cmx: primitives.cmx ../utils/misc.cmx int64ops.cmx \ + input_handling.cmx debugcom.cmi +debugger_config.cmo: int64ops.cmi debugger_config.cmi +debugger_config.cmx: int64ops.cmx debugger_config.cmi +dynlink.cmo: ../bytecomp/symtable.cmi ../bytecomp/opcodes.cmo \ + ../utils/misc.cmi ../bytecomp/meta.cmi ../bytecomp/dll.cmi \ + ../utils/consistbl.cmi ../utils/config.cmi ../bytecomp/cmo_format.cmi \ + dynlink.cmi +dynlink.cmx: ../bytecomp/symtable.cmx ../bytecomp/opcodes.cmx \ + ../utils/misc.cmx ../bytecomp/meta.cmx ../bytecomp/dll.cmx \ + ../utils/consistbl.cmx ../utils/config.cmx ../bytecomp/cmo_format.cmi \ + dynlink.cmi +envaux.cmo: ../typing/types.cmi ../typing/printtyp.cmi ../typing/path.cmi \ + ../typing/mtype.cmi ../utils/misc.cmi ../bytecomp/instruct.cmi \ + ../typing/env.cmi envaux.cmi +envaux.cmx: ../typing/types.cmx ../typing/printtyp.cmx ../typing/path.cmx \ + ../typing/mtype.cmx ../utils/misc.cmx ../bytecomp/instruct.cmx \ + ../typing/env.cmx envaux.cmi +eval.cmo: ../typing/types.cmi ../bytecomp/symtable.cmi printval.cmi \ + ../typing/printtyp.cmi ../typing/predef.cmi ../typing/path.cmi \ + parser_aux.cmi ../utils/misc.cmi ../parsing/longident.cmi \ + ../bytecomp/instruct.cmi ../typing/ident.cmi frames.cmi ../typing/env.cmi \ + debugger_config.cmi debugcom.cmi ../typing/ctype.cmi ../typing/btype.cmi \ + eval.cmi +eval.cmx: ../typing/types.cmx ../bytecomp/symtable.cmx printval.cmx \ + ../typing/printtyp.cmx ../typing/predef.cmx ../typing/path.cmx \ + parser_aux.cmi ../utils/misc.cmx ../parsing/longident.cmx \ + ../bytecomp/instruct.cmx ../typing/ident.cmx frames.cmx ../typing/env.cmx \ + debugger_config.cmx debugcom.cmx ../typing/ctype.cmx ../typing/btype.cmx \ + eval.cmi +events.cmo: primitives.cmi ../parsing/location.cmi ../bytecomp/instruct.cmi \ + checkpoints.cmi events.cmi +events.cmx: primitives.cmx ../parsing/location.cmx ../bytecomp/instruct.cmx \ + checkpoints.cmx events.cmi +exec.cmo: exec.cmi +exec.cmx: exec.cmi +frames.cmo: symbols.cmi primitives.cmi ../utils/misc.cmi \ + ../bytecomp/instruct.cmi events.cmi debugcom.cmi checkpoints.cmi \ + frames.cmi +frames.cmx: symbols.cmx primitives.cmx ../utils/misc.cmx \ + ../bytecomp/instruct.cmx events.cmx debugcom.cmx checkpoints.cmx \ + frames.cmi +history.cmo: primitives.cmi ../utils/misc.cmi int64ops.cmi \ + debugger_config.cmi checkpoints.cmi history.cmi +history.cmx: primitives.cmx ../utils/misc.cmx int64ops.cmx \ + debugger_config.cmx checkpoints.cmx history.cmi +input_handling.cmo: ../otherlibs/unix/unix.cmi primitives.cmi \ + input_handling.cmi +input_handling.cmx: ../otherlibs/unix/unix.cmx primitives.cmx \ + input_handling.cmi +int64ops.cmo: int64ops.cmi +int64ops.cmx: int64ops.cmi +lexer.cmo: primitives.cmi parser.cmi lexer.cmi +lexer.cmx: primitives.cmx parser.cmx lexer.cmi +loadprinter.cmo: ../typing/types.cmi ../bytecomp/symtable.cmi printval.cmi \ + ../typing/printtyp.cmi ../typing/path.cmi ../utils/misc.cmi \ + ../parsing/longident.cmi ../typing/ident.cmi ../typing/env.cmi \ + dynlink.cmi debugger_config.cmi ../typing/ctype.cmi ../utils/config.cmi \ + loadprinter.cmi +loadprinter.cmx: ../typing/types.cmx ../bytecomp/symtable.cmx printval.cmx \ + ../typing/printtyp.cmx ../typing/path.cmx ../utils/misc.cmx \ + ../parsing/longident.cmx ../typing/ident.cmx ../typing/env.cmx \ + dynlink.cmx debugger_config.cmx ../typing/ctype.cmx ../utils/config.cmx \ + loadprinter.cmi +main.cmo: unix_tools.cmi ../otherlibs/unix/unix.cmi time_travel.cmi \ + show_information.cmi question.cmi program_management.cmi primitives.cmi \ + parameters.cmi ../utils/misc.cmi input_handling.cmi frames.cmi exec.cmi \ + ../typing/env.cmi debugger_config.cmi ../utils/config.cmi \ + command_line.cmi ../utils/clflags.cmi checkpoints.cmi +main.cmx: unix_tools.cmx ../otherlibs/unix/unix.cmx time_travel.cmx \ + show_information.cmx question.cmx program_management.cmx primitives.cmx \ + parameters.cmx ../utils/misc.cmx input_handling.cmx frames.cmx exec.cmx \ + ../typing/env.cmx debugger_config.cmx ../utils/config.cmx \ + command_line.cmx ../utils/clflags.cmx checkpoints.cmx +parameters.cmo: primitives.cmi ../utils/misc.cmi envaux.cmi \ + ../utils/config.cmi parameters.cmi +parameters.cmx: primitives.cmx ../utils/misc.cmx envaux.cmx \ + ../utils/config.cmx parameters.cmi +parser.cmo: primitives.cmi parser_aux.cmi ../parsing/longident.cmi \ + int64ops.cmi input_handling.cmi parser.cmi +parser.cmx: primitives.cmx parser_aux.cmi ../parsing/longident.cmx \ + int64ops.cmx input_handling.cmx parser.cmi +pattern_matching.cmo: ../typing/typedtree.cmi parser_aux.cmi \ + ../utils/misc.cmi debugger_config.cmi debugcom.cmi ../typing/ctype.cmi \ + pattern_matching.cmi +pattern_matching.cmx: ../typing/typedtree.cmx parser_aux.cmi \ + ../utils/misc.cmx debugger_config.cmx debugcom.cmx ../typing/ctype.cmx \ + pattern_matching.cmi +pos.cmo: source.cmi primitives.cmi ../parsing/location.cmi \ + ../bytecomp/instruct.cmi pos.cmi +pos.cmx: source.cmx primitives.cmx ../parsing/location.cmx \ + ../bytecomp/instruct.cmx pos.cmi +primitives.cmo: ../otherlibs/unix/unix.cmi primitives.cmi +primitives.cmx: ../otherlibs/unix/unix.cmx primitives.cmi +printval.cmo: ../typing/types.cmi ../bytecomp/symtable.cmi \ + ../typing/printtyp.cmi ../typing/path.cmi parser_aux.cmi \ + ../typing/outcometree.cmi ../typing/oprint.cmi ../utils/misc.cmi \ + ../toplevel/genprintval.cmi debugcom.cmi printval.cmi +printval.cmx: ../typing/types.cmx ../bytecomp/symtable.cmx \ + ../typing/printtyp.cmx ../typing/path.cmx parser_aux.cmi \ + ../typing/outcometree.cmi ../typing/oprint.cmx ../utils/misc.cmx \ + ../toplevel/genprintval.cmx debugcom.cmx printval.cmi +program_loading.cmo: unix_tools.cmi ../otherlibs/unix/unix.cmi primitives.cmi \ + parameters.cmi ../utils/misc.cmi input_handling.cmi debugger_config.cmi \ + program_loading.cmi +program_loading.cmx: unix_tools.cmx ../otherlibs/unix/unix.cmx primitives.cmx \ + parameters.cmx ../utils/misc.cmx input_handling.cmx debugger_config.cmx \ + program_loading.cmi +program_management.cmo: unix_tools.cmi ../otherlibs/unix/unix.cmi \ + time_travel.cmi symbols.cmi question.cmi program_loading.cmi \ + primitives.cmi parameters.cmi ../utils/misc.cmi int64ops.cmi \ + ../bytecomp/instruct.cmi input_handling.cmi history.cmi \ + debugger_config.cmi debugcom.cmi breakpoints.cmi program_management.cmi +program_management.cmx: unix_tools.cmx ../otherlibs/unix/unix.cmx \ + time_travel.cmx symbols.cmx question.cmx program_loading.cmx \ + primitives.cmx parameters.cmx ../utils/misc.cmx int64ops.cmx \ + ../bytecomp/instruct.cmx input_handling.cmx history.cmx \ + debugger_config.cmx debugcom.cmx breakpoints.cmx program_management.cmi +question.cmo: primitives.cmi lexer.cmi input_handling.cmi question.cmi +question.cmx: primitives.cmx lexer.cmx input_handling.cmx question.cmi +show_information.cmo: symbols.cmi show_source.cmi printval.cmi primitives.cmi \ + ../utils/misc.cmi ../bytecomp/instruct.cmi frames.cmi events.cmi \ + debugcom.cmi checkpoints.cmi breakpoints.cmi show_information.cmi +show_information.cmx: symbols.cmx show_source.cmx printval.cmx primitives.cmx \ + ../utils/misc.cmx ../bytecomp/instruct.cmx frames.cmx events.cmx \ + debugcom.cmx checkpoints.cmx breakpoints.cmx show_information.cmi +show_source.cmo: source.cmi primitives.cmi parameters.cmi ../utils/misc.cmi \ + ../parsing/location.cmi ../bytecomp/instruct.cmi events.cmi \ + debugger_config.cmi show_source.cmi +show_source.cmx: source.cmx primitives.cmx parameters.cmx ../utils/misc.cmx \ + ../parsing/location.cmx ../bytecomp/instruct.cmx events.cmx \ + debugger_config.cmx show_source.cmi +source.cmo: primitives.cmi ../utils/misc.cmi ../utils/config.cmi source.cmi +source.cmx: primitives.cmx ../utils/misc.cmx ../utils/config.cmx source.cmi +symbols.cmo: ../bytecomp/symtable.cmi primitives.cmi ../bytecomp/instruct.cmi \ + events.cmi debugger_config.cmi debugcom.cmi checkpoints.cmi \ + ../bytecomp/bytesections.cmi symbols.cmi +symbols.cmx: ../bytecomp/symtable.cmx primitives.cmx ../bytecomp/instruct.cmx \ + events.cmx debugger_config.cmx debugcom.cmx checkpoints.cmx \ + ../bytecomp/bytesections.cmx symbols.cmi +time_travel.cmo: trap_barrier.cmi symbols.cmi question.cmi \ + program_loading.cmi primitives.cmi ../utils/misc.cmi int64ops.cmi \ + ../bytecomp/instruct.cmi input_handling.cmi exec.cmi events.cmi \ + debugger_config.cmi debugcom.cmi checkpoints.cmi breakpoints.cmi \ + time_travel.cmi +time_travel.cmx: trap_barrier.cmx symbols.cmx question.cmx \ + program_loading.cmx primitives.cmx ../utils/misc.cmx int64ops.cmx \ + ../bytecomp/instruct.cmx input_handling.cmx exec.cmx events.cmx \ + debugger_config.cmx debugcom.cmx checkpoints.cmx breakpoints.cmx \ + time_travel.cmi +trap_barrier.cmo: exec.cmi debugcom.cmi checkpoints.cmi trap_barrier.cmi +trap_barrier.cmx: exec.cmx debugcom.cmx checkpoints.cmx trap_barrier.cmi +unix_tools.cmo: ../otherlibs/unix/unix.cmi primitives.cmi ../utils/misc.cmi \ + unix_tools.cmi +unix_tools.cmx: ../otherlibs/unix/unix.cmx primitives.cmx ../utils/misc.cmx \ + unix_tools.cmi diff --git a/debugger/Makefile b/debugger/Makefile new file mode 100644 index 0000000..51cd7d8 --- /dev/null +++ b/debugger/Makefile @@ -0,0 +1,16 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.33 2008-07-29 08:31:41 xleroy Exp $ + +UNIXDIR=../otherlibs/unix +include Makefile.shared diff --git a/debugger/Makefile.nt b/debugger/Makefile.nt new file mode 100644 index 0000000..872e4ea --- /dev/null +++ b/debugger/Makefile.nt @@ -0,0 +1,17 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.1 2008-07-29 08:31:41 xleroy Exp $ + +UNIXDIR=../otherlibs/win32unix +include Makefile.shared + diff --git a/debugger/Makefile.shared b/debugger/Makefile.shared new file mode 100644 index 0000000..0e3ff9a --- /dev/null +++ b/debugger/Makefile.shared @@ -0,0 +1,116 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.shared,v 1.1 2008-07-29 08:31:41 xleroy Exp $ + +include ../config/Makefile + +CAMLC=../ocamlcomp.sh +COMPFLAGS=-warn-error A $(INCLUDES) +LINKFLAGS=-linkall -I $(UNIXDIR) +CAMLYACC=../boot/ocamlyacc +YACCFLAGS= +CAMLLEX=../boot/ocamlrun ../boot/ocamllex +CAMLDEP=../boot/ocamlrun ../tools/ocamldep +DEPFLAGS=$(INCLUDES) + +INCLUDES=\ + -I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../toplevel \ + -I $(UNIXDIR) + +OTHEROBJS=\ + $(UNIXDIR)/unix.cma \ + ../utils/misc.cmo ../utils/config.cmo \ + ../utils/tbl.cmo ../utils/clflags.cmo ../utils/consistbl.cmo \ + ../parsing/longident.cmo \ + ../typing/ident.cmo ../typing/path.cmo ../typing/types.cmo \ + ../typing/btype.cmo ../typing/primitive.cmo ../typing/typedtree.cmo \ + ../typing/subst.cmo ../typing/predef.cmo \ + ../typing/datarepr.cmo ../typing/env.cmo ../typing/oprint.cmo \ + ../typing/ctype.cmo ../typing/printtyp.cmo ../typing/mtype.cmo \ + ../bytecomp/runtimedef.cmo ../bytecomp/bytesections.cmo \ + ../bytecomp/dll.cmo ../bytecomp/meta.cmo ../bytecomp/symtable.cmo \ + ../bytecomp/opcodes.cmo \ + ../toplevel/genprintval.cmo + + +OBJS=\ + dynlink.cmo \ + int64ops.cmo \ + primitives.cmo \ + unix_tools.cmo \ + debugger_config.cmo \ + envaux.cmo \ + parameters.cmo \ + lexer.cmo \ + input_handling.cmo \ + question.cmo \ + debugcom.cmo \ + exec.cmo \ + source.cmo \ + pos.cmo \ + checkpoints.cmo \ + events.cmo \ + symbols.cmo \ + breakpoints.cmo \ + trap_barrier.cmo \ + history.cmo \ + program_loading.cmo \ + printval.cmo \ + show_source.cmo \ + time_travel.cmo \ + program_management.cmo \ + frames.cmo \ + eval.cmo \ + show_information.cmo \ + loadprinter.cmo \ + parser.cmo \ + command_line.cmo \ + main.cmo + +all: ocamldebug$(EXE) + +ocamldebug$(EXE): $(OBJS) $(OTHEROBJS) + $(CAMLC) $(LINKFLAGS) -o ocamldebug$(EXE) -linkall $(OTHEROBJS) $(OBJS) + +install: + cp ocamldebug$(EXE) $(BINDIR)/ocamldebug$(EXE) + +clean:: + rm -f ocamldebug$(EXE) + rm -f *.cmo *.cmi + +.SUFFIXES: +.SUFFIXES: .ml .cmo .mli .cmi + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +depend: beforedepend + $(CAMLDEP) $(DEPFLAGS) *.mli *.ml > .depend + +lexer.ml: lexer.mll + $(CAMLLEX) lexer.mll +clean:: + rm -f lexer.ml +beforedepend:: lexer.ml + +parser.ml parser.mli: parser.mly + $(CAMLYACC) parser.mly +clean:: + rm -f parser.ml parser.mli +beforedepend:: parser.ml parser.mli + +include .depend diff --git a/debugger/breakpoints.ml b/debugger/breakpoints.ml new file mode 100644 index 0000000..0ba611a --- /dev/null +++ b/debugger/breakpoints.ml @@ -0,0 +1,227 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: breakpoints.ml,v 1.13 2005-08-23 20:16:43 doligez Exp $ *) + +(******************************* Breakpoints ***************************) + +open Checkpoints +open Debugcom +open Instruct +open Primitives +open Printf +open Source + +(*** Debugging. ***) +let debug_breakpoints = ref false + +(*** Data. ***) + +(* Number of the last added breakpoint. *) +let breakpoint_number = ref 0 + +(* Breakpoint number -> event. *) +let breakpoints = ref ([] : (int * debug_event) list) + +(* Program counter -> breakpoint count. *) +let positions = ref ([] : (int * int ref) list) + +(* Versions of the breakpoint list. *) +let current_version = ref 0 +let max_version = ref 0 + +(*** Miscellaneous. ***) + +(* Mark breakpoints as installed in current checkpoint. *) +let copy_breakpoints () = + !current_checkpoint.c_breakpoints <- !positions; + !current_checkpoint.c_breakpoint_version <- !current_version + +(* Announce a new version of the breakpoint list. *) +let new_version () = + incr max_version; + current_version := !max_version + +(*** Information about breakpoints. ***) + +let breakpoints_count () = + List.length !breakpoints + +(* List of breakpoints at `pc'. *) +let rec breakpoints_at_pc pc = + begin try + let ev = Symbols.event_at_pc pc in + match ev.ev_repr with + Event_child {contents = pc'} -> breakpoints_at_pc pc' + | _ -> [] + with Not_found -> + [] + end + @ + List.map fst (filter (function (_, {ev_pos = pos}) -> pos = pc) !breakpoints) + +(* Is there a breakpoint at `pc' ? *) +let breakpoint_at_pc pc = + breakpoints_at_pc pc <> [] + +(*** Set and remove breakpoints ***) + +(* Remove all breakpoints. *) +let remove_breakpoints pos = + if !debug_breakpoints then + (print_string "Removing breakpoints..."; print_newline ()); + List.iter + (function (pos, _) -> + if !debug_breakpoints then begin + print_int pos; + print_newline() + end; + reset_instr pos; + Symbols.set_event_at_pc pos) + pos + +(* Set all breakpoints. *) +let set_breakpoints pos = + if !debug_breakpoints then + (print_string "Setting breakpoints..."; print_newline ()); + List.iter + (function (pos, _) -> + if !debug_breakpoints then begin + print_int pos; + print_newline() + end; + set_breakpoint pos) + pos + +(* Ensure the current version in installed in current checkpoint. *) +let update_breakpoints () = + if !debug_breakpoints then begin + prerr_string "Updating breakpoints... "; + prerr_int !current_checkpoint.c_breakpoint_version; + prerr_string " "; + prerr_int !current_version; + prerr_endline "" + end; + if !current_checkpoint.c_breakpoint_version <> !current_version then + Exec.protect + (function () -> + remove_breakpoints !current_checkpoint.c_breakpoints; + set_breakpoints !positions; + copy_breakpoints ()) + +let change_version version pos = + Exec.protect + (function () -> + current_version := version; + positions := pos) + +(* Execute given function with no breakpoint in current checkpoint. *) +(* --- `goto' runs faster this way (does not stop on each breakpoint). *) +let execute_without_breakpoints f = + let version = !current_version + and pos = !positions + in + change_version 0 []; + try + f (); + change_version version pos + with + x -> + change_version version pos + +(* Add a position in the position list. *) +(* Change version if necessary. *) +let insert_position pos = + try + incr (List.assoc pos !positions) + with + Not_found -> + positions := (pos, ref 1) :: !positions; + new_version () + +(* Remove a position in the position list. *) +(* Change version if necessary. *) +let remove_position pos = + let count = List.assoc pos !positions in + decr count; + if !count = 0 then begin + positions := assoc_remove !positions pos; + new_version () + end + +(* Insert a new breakpoint in lists. *) +let rec new_breakpoint = + function + {ev_repr = Event_child pc} -> + new_breakpoint (Symbols.any_event_at_pc !pc) + | event -> + Exec.protect + (function () -> + incr breakpoint_number; + insert_position event.ev_pos; + breakpoints := (!breakpoint_number, event) :: !breakpoints); + printf "Breakpoint %d at %d : %s" !breakpoint_number event.ev_pos + (Pos.get_desc event); + print_newline () + +(* Remove a breakpoint from lists. *) +let remove_breakpoint number = + try + let ev = List.assoc number !breakpoints in + let pos = ev.ev_pos in + Exec.protect + (function () -> + breakpoints := assoc_remove !breakpoints number; + remove_position pos; + printf "Removed breakpoint %d at %d : %s" number ev.ev_pos + (Pos.get_desc ev); + print_newline () + ) + with + Not_found -> + prerr_endline ("No breakpoint number " ^ (string_of_int number) ^ "."); + raise Not_found + +let remove_all_breakpoints () = + List.iter (function (number, _) -> remove_breakpoint number) !breakpoints + +(*** Temporary breakpoints. ***) + +(* Temporary breakpoint position. *) +let temporary_breakpoint_position = ref (None : int option) + +(* Execute `funct' with a breakpoint added at `pc'. *) +(* --- Used by `finish'. *) +let exec_with_temporary_breakpoint pc funct = + let previous_version = !current_version in + let remove () = + temporary_breakpoint_position := None; + current_version := previous_version; + let count = List.assoc pc !positions in + decr count; + if !count = 0 then begin + positions := assoc_remove !positions pc; + reset_instr pc; + Symbols.set_event_at_pc pc + end + + in + Exec.protect (function () -> insert_position pc); + temporary_breakpoint_position := Some pc; + try + funct (); + Exec.protect remove + with + x -> + Exec.protect remove; + raise x diff --git a/debugger/breakpoints.mli b/debugger/breakpoints.mli new file mode 100644 index 0000000..f01d3f6 --- /dev/null +++ b/debugger/breakpoints.mli @@ -0,0 +1,61 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: breakpoints.mli,v 1.2 1999-11-17 18:57:22 xleroy Exp $ *) + +(******************************* Breakpoints ***************************) + +open Primitives +open Instruct + +(*** Debugging. ***) +val debug_breakpoints : bool ref + +(*** Information about breakpoints. ***) + +val breakpoints_count : unit -> int + +(* Breakpoint number -> debug_event_kind. *) +val breakpoints : (int * debug_event) list ref + +(* Is there a breakpoint at `pc' ? *) +val breakpoint_at_pc : int -> bool + +(* List of breakpoints at `pc'. *) +val breakpoints_at_pc : int -> int list + +(*** Set and remove breakpoints ***) + +(* Ensure the current version in installed in current checkpoint. *) +val update_breakpoints : unit -> unit + +(* Execute given function with no breakpoint in current checkpoint. *) +(* --- `goto' run faster so (does not stop on each breakpoint). *) +val execute_without_breakpoints : (unit -> unit) -> unit + +(* Insert a new breakpoint in lists. *) +val new_breakpoint : debug_event -> unit + +(* Remove a breakpoint from lists. *) +val remove_breakpoint : int -> unit + +val remove_all_breakpoints : unit -> unit + +(*** Temporary breakpoints. ***) + +(* Temporary breakpoint position. *) +val temporary_breakpoint_position : int option ref + +(* Execute `funct' with a breakpoint added at `pc'. *) +(* --- Used by `finish'. *) +val exec_with_temporary_breakpoint : int -> (unit -> unit) -> unit diff --git a/debugger/checkpoints.ml b/debugger/checkpoints.ml new file mode 100644 index 0000000..11b82d3 --- /dev/null +++ b/debugger/checkpoints.ml @@ -0,0 +1,85 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: checkpoints.ml,v 1.4 2002-10-29 17:53:23 doligez Exp $ *) + +(*************************** Checkpoints *******************************) + +open Int64ops +open Debugcom +open Primitives + +(*** A type for checkpoints. ***) + +type checkpoint_state = + C_stopped + | C_running of int64 + +(* `c_valid' is true if and only if the corresponding + * process is connected to the debugger. + * `c_parent' is the checkpoint whose process is parent + * of the checkpoint one (`root' if no parent). + * c_pid = -2 for root pseudo-checkpoint. + * c_pid = 0 for ghost checkpoints. + * c_pid = -1 for kill checkpoints. + *) +type checkpoint = { + mutable c_time : int64; + mutable c_pid : int; + mutable c_fd : io_channel; + mutable c_valid : bool; + mutable c_report : report option; + mutable c_state : checkpoint_state; + mutable c_parent : checkpoint; + mutable c_breakpoint_version : int; + mutable c_breakpoints : (int * int ref) list; + mutable c_trap_barrier : int + } + +(*** Pseudo-checkpoint `root'. ***) +(* --- Parents of all checkpoints which have no parent. *) +let rec root = { + c_time = _0; + c_pid = -2; + c_fd = std_io; + c_valid = false; + c_report = None; + c_state = C_stopped; + c_parent = root; + c_breakpoint_version = 0; + c_breakpoints = []; + c_trap_barrier = 0 + } + +(*** Current state ***) +let checkpoints = + ref ([] : checkpoint list) + +let current_checkpoint = + ref root + +let current_time () = + !current_checkpoint.c_time + +let current_report () = + !current_checkpoint.c_report + +let current_pc () = + match current_report () with + None | Some {rep_type = Exited | Uncaught_exc} -> None + | Some {rep_program_pointer = pc } -> Some pc + +let current_pc_sp () = + match current_report () with + None | Some {rep_type = Exited | Uncaught_exc} -> None + | Some {rep_program_pointer = pc; rep_stack_pointer = sp } -> Some (pc, sp) diff --git a/debugger/checkpoints.mli b/debugger/checkpoints.mli new file mode 100644 index 0000000..ac2efcc --- /dev/null +++ b/debugger/checkpoints.mli @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: checkpoints.mli,v 1.4 2002-10-29 17:53:23 doligez Exp $ *) + +(***************************** Checkpoints *****************************) + +open Primitives +open Debugcom + +(*** A type for checkpoints. ***) + +type checkpoint_state = + C_stopped + | C_running of int64 + +(* `c_valid' is true if and only if the corresponding + * process is connected to the debugger. + * `c_parent' is the checkpoint whose process is parent + * of the checkpoint one (`root' if no parent). + * c_pid = 2 for root pseudo-checkpoint. + * c_pid = 0 for ghost checkpoints. + * c_pid = -1 for kill checkpoints. + *) +type checkpoint = + {mutable c_time : int64; + mutable c_pid : int; + mutable c_fd : io_channel; + mutable c_valid : bool; + mutable c_report : report option; + mutable c_state : checkpoint_state; + mutable c_parent : checkpoint; + mutable c_breakpoint_version : int; + mutable c_breakpoints : (int * int ref) list; + mutable c_trap_barrier : int} + +(*** Pseudo-checkpoint `root'. ***) +(* --- Parents of all checkpoints which have no parent. *) +val root : checkpoint + +(*** Current state ***) +val checkpoints : checkpoint list ref +val current_checkpoint : checkpoint ref + +val current_time : unit -> int64 +val current_report : unit -> report option +val current_pc : unit -> int option +val current_pc_sp : unit -> (int * int) option diff --git a/debugger/command_line.ml b/debugger/command_line.ml new file mode 100644 index 0000000..b0a2517 --- /dev/null +++ b/debugger/command_line.ml @@ -0,0 +1,1099 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: command_line.ml,v 1.25 2008-07-29 08:31:41 xleroy Exp $ *) + +(************************ Reading and executing commands ***************) + +open Int64ops +open Format +open Misc +open Instruct +open Unix +open Debugger_config +open Types +open Primitives +open Unix_tools +open Parser +open Parser_aux +open Lexer +open Input_handling +open Question +open Debugcom +open Program_loading +open Program_management +open Lexing +open Parameters +open Show_source +open Show_information +open Time_travel +open Events +open Symbols +open Source +open Breakpoints +open Checkpoints +open Frames +open Printval + +(** Instructions, variables and infos lists. **) +type dbg_instruction = + { instr_name: string; (* Name of command *) + instr_prio: bool; (* Has priority *) + instr_action: formatter -> lexbuf -> unit; + (* What to do *) + instr_repeat: bool; (* Can be repeated *) + instr_help: string } (* Help message *) + +let instruction_list = ref ([] : dbg_instruction list) + +type dbg_variable = + { var_name: string; (* Name of variable *) + var_action: (lexbuf -> unit) * (formatter -> unit); + (* Reading, writing fns *) + var_help: string } (* Help message *) + +let variable_list = ref ([] : dbg_variable list) + +type dbg_info = + { info_name: string; (* Name of info *) + info_action: lexbuf -> unit; (* What to do *) + info_help: string } (* Help message *) + +let info_list = ref ([] : dbg_info list) + +(** Utilities. **) +let error text = + eprintf "%s@." text; + raise Toplevel + +let check_not_windows feature = + match Sys.os_type with + | "Win32" -> + error ("'"^feature^"' feature not supported on Windows") + | _ -> + () + +let eol = + end_of_line Lexer.lexeme + +let matching_elements list name instr = + filter (function a -> isprefix instr (name a)) !list + +let all_matching_instructions = + matching_elements instruction_list (fun i -> i.instr_name) + +(* itz 04-21-96 don't do priority completion in emacs mode *) +(* XL 25-02-97 why? I find it very confusing. *) + +let matching_instructions instr = + let all = all_matching_instructions instr in + let prio = filter (fun i -> i.instr_prio) all in + if prio = [] then all else prio + +let matching_variables = + matching_elements variable_list (fun v -> v.var_name) + +let matching_infos = + matching_elements info_list (fun i -> i.info_name) + +let find_ident name matcher action alternative ppf lexbuf = + match identifier_or_eol Lexer.lexeme lexbuf with + | None -> alternative ppf + | Some ident -> + match matcher ident with + | [] -> error ("Unknown " ^ name ^ ".") + | [a] -> action a ppf lexbuf + | _ -> error ("Ambiguous " ^ name ^ ".") + +let find_variable action alternative ppf lexbuf = + find_ident "variable name" matching_variables action alternative ppf lexbuf + +let find_info action alternative ppf lexbuf = + find_ident "info command" matching_infos action alternative ppf lexbuf + +let add_breakpoint_at_pc pc = + try + new_breakpoint (any_event_at_pc pc) + with + | Not_found -> + eprintf "Can't add breakpoint at pc %i : no event there.@." pc; + raise Toplevel + +let add_breakpoint_after_pc pc = + let rec try_add n = + if n < 3 then begin + try + new_breakpoint (any_event_at_pc (pc + n * 4)) + with + | Not_found -> + try_add (n+1) + end else begin + error + "Can't add breakpoint at beginning of function: no event there" + end + in try_add 0 + +let convert_module mdle = + match mdle with + | Some m -> + (* Strip .ml extension if any, and capitalize *) + String.capitalize(if Filename.check_suffix m ".ml" + then Filename.chop_suffix m ".ml" + else m) + | None -> + try + (get_current_event ()).ev_module + with + | Not_found -> + error "Not in a module." + +(** Toplevel. **) +let current_line = ref "" + +let interprete_line ppf line = + current_line := line; + let lexbuf = Lexing.from_string line in + try + match identifier_or_eol Lexer.lexeme lexbuf with + | Some x -> + begin match matching_instructions x with + | [] -> + error "Unknown command." + | [i] -> + i.instr_action ppf lexbuf; + resume_user_input (); + i.instr_repeat + | l -> + error "Ambiguous command." + end + | None -> + resume_user_input (); + false + with + | Parsing.Parse_error -> + error "Syntax error." + +let line_loop ppf line_buffer = + resume_user_input (); + let previous_line = ref "" in + try + while true do + if !loaded then + History.add_current_time (); + let new_line = string_trim (line line_buffer) in + let line = + if new_line <> "" then + new_line + else + !previous_line + in + previous_line := ""; + if interprete_line ppf line then + previous_line := line + done + with + | Exit -> + stop_user_input () + | Sys_error s -> + error ("System error : " ^ s) + +(** Instructions. **) +let instr_cd ppf lexbuf = + let dir = argument_eol argument lexbuf in + if ask_kill_program () then + try + Sys.chdir (expand_path dir) + with + | Sys_error s -> + error s + +let instr_shell ppf lexbuf = + let cmdarg = argument_list_eol argument lexbuf in + let cmd = String.concat " " cmdarg in + (* perhaps we should use $SHELL -c ? *) + let err = Sys.command cmd in + if (err != 0) then + eprintf "Shell command %S failed with exit code %d\n%!" cmd err + +let instr_pwd ppf lexbuf = + eol lexbuf; + fprintf ppf "%s@." (Sys.getcwd ()) + +let instr_dir ppf lexbuf = + let new_directory = argument_list_eol argument lexbuf in + if new_directory = [] then begin + if yes_or_no "Reinitialize directory list" then begin + Config.load_path := !default_load_path; + Envaux.reset_cache (); + flush_buffer_list () + end + end + else + List.iter (function x -> add_path (expand_path x)) + (List.rev new_directory); + let print_dirs ppf l = List.iter (function x -> fprintf ppf "@ %s" x) l in + fprintf ppf "@[<2>Directories :%a@]@." print_dirs !Config.load_path + +let instr_kill ppf lexbuf = + eol lexbuf; + if not !loaded then error "The program is not being run."; + if (yes_or_no "Kill the program being debugged") then begin + kill_program (); + show_no_point() + end + +let instr_run ppf lexbuf = + eol lexbuf; + ensure_loaded (); + reset_named_values (); + run (); + show_current_event ppf;; + +let instr_reverse ppf lexbuf = + eol lexbuf; + check_not_windows "reverse"; + ensure_loaded (); + reset_named_values(); + back_run (); + show_current_event ppf + +let instr_step ppf lexbuf = + let step_count = + match opt_signed_int64_eol Lexer.lexeme lexbuf with + | None -> _1 + | Some x -> x + in + ensure_loaded (); + reset_named_values(); + step step_count; + show_current_event ppf + +let instr_back ppf lexbuf = + let step_count = + match opt_signed_int64_eol Lexer.lexeme lexbuf with + | None -> _1 + | Some x -> x + in + check_not_windows "backstep"; + ensure_loaded (); + reset_named_values(); + step (_0 -- step_count); + show_current_event ppf + +let instr_finish ppf lexbuf = + eol lexbuf; + ensure_loaded (); + reset_named_values(); + finish (); + show_current_event ppf + +let instr_next ppf lexbuf = + let step_count = + match opt_integer_eol Lexer.lexeme lexbuf with + | None -> 1 + | Some x -> x + in + ensure_loaded (); + reset_named_values(); + next step_count; + show_current_event ppf + +let instr_start ppf lexbuf = + eol lexbuf; + check_not_windows "start"; + ensure_loaded (); + reset_named_values(); + start (); + show_current_event ppf + +let instr_previous ppf lexbuf = + let step_count = + match opt_integer_eol Lexer.lexeme lexbuf with + | None -> 1 + | Some x -> x + in + check_not_windows "previous"; + ensure_loaded (); + reset_named_values(); + previous step_count; + show_current_event ppf + +let instr_goto ppf lexbuf = + let time = int64_eol Lexer.lexeme lexbuf in + ensure_loaded (); + reset_named_values(); + go_to time; + show_current_event ppf + +let instr_quit _ = + raise Exit + +let print_variable_list ppf = + let pr_vars ppf = List.iter (fun v -> fprintf ppf "%s@ " v.var_name) in + fprintf ppf "List of variables :%a@." pr_vars !variable_list + +let print_info_list ppf = + let pr_infos ppf = List.iter (fun i -> fprintf ppf "%s@ " i.info_name) in + fprintf ppf "List of info commands :%a@." pr_infos !info_list + +let instr_complete ppf lexbuf = + let ppf = Format.err_formatter in + let rec print_list l = + try + eol lexbuf; + List.iter (function i -> fprintf ppf "%s@." i) l + with _ -> + remove_file !user_channel + and match_list lexbuf = + match identifier_or_eol Lexer.lexeme lexbuf with + | None -> + List.map (fun i -> i.instr_name) !instruction_list + | Some x -> + match matching_instructions x with + | [ {instr_name = ("set" | "show" as i_full)} ] -> + if x = i_full then begin + match identifier_or_eol Lexer.lexeme lexbuf with + | Some ident -> + begin match matching_variables ident with + | [v] -> if v.var_name = ident then [] else [v.var_name] + | l -> List.map (fun v -> v.var_name) l + end + | None -> + List.map (fun v -> v.var_name) !variable_list + end + else [i_full] + | [ {instr_name = "info"} ] -> + if x = "info" then begin + match identifier_or_eol Lexer.lexeme lexbuf with + | Some ident -> + begin match matching_infos ident with + | [i] -> if i.info_name = ident then [] else [i.info_name] + | l -> List.map (fun i -> i.info_name) l + end + | None -> + List.map (fun i -> i.info_name) !info_list + end + else ["info"] + | [ {instr_name = "help"} ] -> + if x = "help" then match_list lexbuf else ["help"] + | [ i ] -> + if x = i.instr_name then [] else [i.instr_name] + | l -> + List.map (fun i -> i.instr_name) l + in + print_list(match_list lexbuf) + +let instr_help ppf lexbuf = + let pr_instrs ppf = + List.iter (fun i -> fprintf ppf "%s@ " i.instr_name) in + match identifier_or_eol Lexer.lexeme lexbuf with + | Some x -> + let print_help nm hlp = + eol lexbuf; + fprintf ppf "%s : %s@." nm hlp in + begin match matching_instructions x with + | [] -> + eol lexbuf; + fprintf ppf "No matching command.@." + | [ {instr_name = "set"} ] -> + find_variable + (fun v _ _ -> + print_help ("set " ^ v.var_name) ("set " ^ v.var_help)) + (fun ppf -> + print_help "set" "set debugger variable."; + print_variable_list ppf) + ppf + lexbuf + | [ {instr_name = "show"} ] -> + find_variable + (fun v _ _ -> + print_help ("show " ^ v.var_name) ("show " ^ v.var_help)) + (fun v -> + print_help "show" "display debugger variable."; + print_variable_list ppf) + ppf + lexbuf + | [ {instr_name = "info"} ] -> + find_info + (fun i _ _ -> print_help ("info " ^ i.info_name) i.info_help) + (fun ppf -> + print_help "info" + "display infos about the program being debugged."; + print_info_list ppf) + ppf + lexbuf + | [i] -> + print_help i.instr_name i.instr_help + | l -> + eol lexbuf; + fprintf ppf "Ambiguous command \"%s\" : %a@." x pr_instrs l + end + | None -> + fprintf ppf "List of commands :%a@." pr_instrs !instruction_list + +(* Printing values *) + +let print_expr depth ev env ppf expr = + try + let (v, ty) = Eval.expression ev env expr in + print_named_value depth expr env v ppf ty + with + | Eval.Error msg -> + Eval.report_error ppf msg; + raise Toplevel + +let print_command depth ppf lexbuf = + let exprs = expression_list_eol Lexer.lexeme lexbuf in + ensure_loaded (); + let env = + try + Envaux.env_of_event !selected_event + with + | Envaux.Error msg -> + Envaux.report_error ppf msg; + raise Toplevel + in + List.iter (print_expr depth !selected_event env ppf) exprs + +let instr_print ppf lexbuf = print_command !max_printer_depth ppf lexbuf + +let instr_display ppf lexbuf = print_command 1 ppf lexbuf + +(* Loading of command files *) + +let extract_filename arg = + (* Allow enclosing filename in quotes *) + let l = String.length arg in + let pos1 = if l > 0 && arg.[0] = '"' then 1 else 0 in + let pos2 = if l > 0 && arg.[l-1] = '"' then l-1 else l in + String.sub arg pos1 (pos2 - pos1) + +let instr_source ppf lexbuf = + let file = extract_filename(argument_eol argument lexbuf) + and old_state = !interactif + and old_channel = !user_channel in + let io_chan = + try + io_channel_of_descr + (openfile (find_in_path !Config.load_path (expand_path file)) + [O_RDONLY] 0) + with + | Not_found -> error "Source file not found." + | (Unix_error _) as x -> Unix_tools.report_error x; raise Toplevel + in + try + interactif := false; + user_channel := io_chan; + line_loop ppf (Lexing.from_function read_user_input); + close_io io_chan; + interactif := old_state; + user_channel := old_channel + with + | x -> + stop_user_input (); + close_io io_chan; + interactif := old_state; + user_channel := old_channel; + raise x + +let instr_set = + find_variable + (fun {var_action = (funct, _)} ppf lexbuf -> funct lexbuf) + (function ppf -> error "Argument required.") + +let instr_show = + find_variable + (fun {var_action = (_, funct)} ppf lexbuf -> eol lexbuf; funct ppf) + (function ppf -> + List.iter + (function {var_name = nm; var_action = (_, funct)} -> + fprintf ppf "%s : " nm; + funct ppf) + !variable_list) + +let instr_info = + find_info + (fun i ppf lexbuf -> i.info_action lexbuf) + (function ppf -> + error "\"info\" must be followed by the name of an info command.") + +let instr_break ppf lexbuf = + let argument = break_argument_eol Lexer.lexeme lexbuf in + ensure_loaded (); + match argument with + | BA_none -> (* break *) + (match !selected_event with + | Some ev -> + new_breakpoint ev + | None -> + error "Can't add breakpoint at this point.") + | BA_pc pc -> (* break PC *) + add_breakpoint_at_pc pc + | BA_function expr -> (* break FUNCTION *) + let env = + try + Envaux.env_of_event !selected_event + with + | Envaux.Error msg -> + Envaux.report_error ppf msg; + raise Toplevel + in + begin try + let (v, ty) = Eval.expression !selected_event env expr in + match (Ctype.repr ty).desc with + | Tarrow _ -> + add_breakpoint_after_pc (Remote_value.closure_code v) + | _ -> + eprintf "Not a function.@."; + raise Toplevel + with + | Eval.Error msg -> + Eval.report_error ppf msg; + raise Toplevel + end + | BA_pos1 (mdle, line, column) -> (* break @ [MODULE] LINE [COL] *) + let module_name = convert_module mdle in + new_breakpoint + (try + let buffer = + try get_buffer Lexing.dummy_pos module_name with + | Not_found -> + eprintf "No source file for %s.@." module_name; + raise Toplevel + in + match column with + | None -> + event_at_pos module_name (fst (pos_of_line buffer line)) + | Some col -> + event_near_pos module_name (point_of_coord buffer line col) + with + | Not_found -> (* event_at_pos / event_near pos *) + eprintf "Can't find any event there.@."; + raise Toplevel + | Out_of_range -> (* pos_of_line / point_of_coord *) + eprintf "Position out of range.@."; + raise Toplevel) + | BA_pos2 (mdle, position) -> (* break @ [MODULE] # POSITION *) + try + new_breakpoint (event_near_pos (convert_module mdle) position) + with + | Not_found -> + eprintf "Can't find any event there.@." + +let instr_delete ppf lexbuf = + match integer_list_eol Lexer.lexeme lexbuf with + | [] -> + if breakpoints_count () <> 0 && yes_or_no "Delete all breakpoints" + then remove_all_breakpoints () + | breakpoints -> + List.iter + (function x -> try remove_breakpoint x with | Not_found -> ()) + breakpoints + +let instr_frame ppf lexbuf = + let frame_number = + match opt_integer_eol Lexer.lexeme lexbuf with + | None -> !current_frame + | Some x -> x + in + ensure_loaded (); + try + select_frame frame_number; + show_current_frame ppf true + with + | Not_found -> + error ("No frame number " ^ string_of_int frame_number ^ ".") + +let instr_backtrace ppf lexbuf = + let number = + match opt_signed_integer_eol Lexer.lexeme lexbuf with + | None -> 0 + | Some x -> x in + ensure_loaded (); + match current_report() with + | None | Some {rep_type = Exited | Uncaught_exc} -> () + | Some _ -> + let frame_counter = ref 0 in + let print_frame first_frame last_frame = function + | None -> + fprintf ppf + "(Encountered a function with no debugging information)@."; + false + | Some event -> + if !frame_counter >= first_frame then + show_one_frame !frame_counter ppf event; + incr frame_counter; + if !frame_counter >= last_frame then begin + fprintf ppf "(More frames follow)@." + end; + !frame_counter < last_frame in + fprintf ppf "Backtrace:@."; + if number = 0 then + do_backtrace (print_frame 0 max_int) + else if number > 0 then + do_backtrace (print_frame 0 number) + else begin + let num_frames = stack_depth() in + if num_frames < 0 then + fprintf ppf + "(Encountered a function with no debugging information)@." + else + do_backtrace (print_frame (num_frames + number) max_int) + end + +let instr_up ppf lexbuf = + let offset = + match opt_signed_integer_eol Lexer.lexeme lexbuf with + | None -> 1 + | Some x -> x + in + ensure_loaded (); + try + select_frame (!current_frame + offset); + show_current_frame ppf true + with + | Not_found -> error "No such frame." + +let instr_down ppf lexbuf = + let offset = + match opt_signed_integer_eol Lexer.lexeme lexbuf with + | None -> 1 + | Some x -> x + in + ensure_loaded (); + try + select_frame (!current_frame - offset); + show_current_frame ppf true + with + | Not_found -> error "No such frame." + +let instr_last ppf lexbuf = + let count = + match opt_signed_int64_eol Lexer.lexeme lexbuf with + | None -> _1 + | Some x -> x + in + check_not_windows "last"; + reset_named_values(); + go_to (History.previous_time count); + show_current_event ppf + +let instr_list ppf lexbuf = + let (mo, beg, e) = list_arguments_eol Lexer.lexeme lexbuf in + let (curr_mod, point) = + try + selected_point () + with + | Not_found -> + ("", -1) + in + let mdle = convert_module mo in + let pos = Lexing.dummy_pos in + let beginning = + match beg with + | None when (mo <> None) || (point = -1) -> + 1 + | None -> + let buffer = + try get_buffer pos mdle with + | Not_found -> error ("No source file for " ^ mdle ^ ".") + in + begin try + max 1 ((snd (line_of_pos buffer point)) - 10) + with Out_of_range -> + 1 + end + | Some x -> x + in + let en = + match e with + | None -> beginning + 20 + | Some x -> x + in + if mdle = curr_mod then + show_listing pos mdle beginning en point + (current_event_is_before ()) + else + show_listing pos mdle beginning en (-1) true + +(** Variables. **) +let raw_variable kill name = + (function lexbuf -> + let argument = argument_eol argument lexbuf in + if (not kill) || ask_kill_program () then name := argument), + function ppf -> fprintf ppf "%s@." !name + +let raw_line_variable kill name = + (function lexbuf -> + let argument = argument_eol line_argument lexbuf in + if (not kill) || ask_kill_program () then name := argument), + function ppf -> fprintf ppf "%s@." !name + +let integer_variable kill min msg name = + (function lexbuf -> + let argument = integer_eol Lexer.lexeme lexbuf in + if argument < min then print_endline msg + else if (not kill) || ask_kill_program () then name := argument), + function ppf -> fprintf ppf "%i@." !name + +let int64_variable kill min msg name = + (function lexbuf -> + let argument = int64_eol Lexer.lexeme lexbuf in + if argument < min then print_endline msg + else if (not kill) || ask_kill_program () then name := argument), + function ppf -> fprintf ppf "%Li@." !name + +let boolean_variable kill name = + (function lexbuf -> + let argument = + match identifier_eol Lexer.lexeme lexbuf with + | "on" -> true + | "of" | "off" -> false + | _ -> error "Syntax error." + in + if (not kill) || ask_kill_program () then name := argument), + function ppf -> fprintf ppf "%s@." (if !name then "on" else "off") + +let path_variable kill name = + (function lexbuf -> + let argument = argument_eol argument lexbuf in + if (not kill) || ask_kill_program () then + name := make_absolute (expand_path argument)), + function ppf -> fprintf ppf "%s@." !name + +let loading_mode_variable ppf = + (find_ident + "loading mode" + (matching_elements (ref loading_modes) fst) + (fun (_, mode) ppf lexbuf -> + eol lexbuf; set_launching_function mode) + (function ppf -> error "Syntax error.") + ppf), + function ppf -> + let rec find = function + | [] -> () + | (name, funct) :: l -> + if funct == !launching_func then fprintf ppf "%s" name else find l + in + find loading_modes; + fprintf ppf "@." + +(** Infos. **) + +let pr_modules ppf mods = + let pr_mods ppf = List.iter (function x -> fprintf ppf "%s@ " x) in + fprintf ppf "Used modules :@.%a@?" pr_mods mods + +let info_modules ppf lexbuf = + eol lexbuf; + ensure_loaded (); + pr_modules ppf !modules +(******** + print_endline "Opened modules :"; + if !opened_modules_names = [] then + print_endline "(no module opened)." + else + (List.iter (function x -> print_string x; print_space) !opened_modules_names; + print_newline ()) +*********) + +let info_checkpoints ppf lexbuf = + eol lexbuf; + if !checkpoints = [] then fprintf ppf "No checkpoint.@." + else + (if !debug_breakpoints then + (prerr_endline " Time Pid Version"; + List.iter + (function + {c_time = time; c_pid = pid; c_breakpoint_version = version} -> + Printf.printf "%19Ld %5d %d\n" time pid version) + !checkpoints) + else + (print_endline " Time Pid"; + List.iter + (function + {c_time = time; c_pid = pid} -> + Printf.printf "%19Ld %5d\n" time pid) + !checkpoints)) + +let info_one_breakpoint ppf (num, ev) = + fprintf ppf "%3d %10d %s@." num ev.ev_pos (Pos.get_desc ev); +;; + +let info_breakpoints ppf lexbuf = + eol lexbuf; + if !breakpoints = [] then fprintf ppf "No breakpoints.@." + else begin + fprintf ppf "Num Address Where@."; + List.iter (info_one_breakpoint ppf) (List.rev !breakpoints); + end +;; + +let info_events ppf lexbuf = + ensure_loaded (); + let mdle = convert_module (opt_identifier_eol Lexer.lexeme lexbuf) in + print_endline ("Module : " ^ mdle); + print_endline " Address Characters Kind Repr."; + List.iter + (function ev -> + Printf.printf + "%10d %6d-%-6d %10s %10s\n" + ev.ev_pos + ev.ev_loc.Location.loc_start.Lexing.pos_cnum + ev.ev_loc.Location.loc_end.Lexing.pos_cnum + ((match ev.ev_kind with + Event_before -> "before" + | Event_after _ -> "after" + | Event_pseudo -> "pseudo") + ^ + (match ev.ev_info with + Event_function -> "/fun" + | Event_return _ -> "/ret" + | Event_other -> "")) + (match ev.ev_repr with + Event_none -> "" + | Event_parent _ -> "(repr)" + | Event_child repr -> string_of_int !repr)) + (events_in_module mdle) + +(** User-defined printers **) + +let instr_load_printer ppf lexbuf = + let filename = extract_filename(argument_eol argument lexbuf) in + try + Loadprinter.loadfile ppf filename + with Loadprinter.Error e -> + Loadprinter.report_error ppf e; raise Toplevel + +let instr_install_printer ppf lexbuf = + let lid = longident_eol Lexer.lexeme lexbuf in + try + Loadprinter.install_printer ppf lid + with Loadprinter.Error e -> + Loadprinter.report_error ppf e; raise Toplevel + +let instr_remove_printer ppf lexbuf = + let lid = longident_eol Lexer.lexeme lexbuf in + try + Loadprinter.remove_printer lid + with Loadprinter.Error e -> + Loadprinter.report_error ppf e; raise Toplevel + +(** Initialization. **) +let init ppf = + instruction_list := [ + { instr_name = "cd"; instr_prio = false; + instr_action = instr_cd; instr_repeat = true; instr_help = +"set working directory to DIR for debugger and program being debugged." }; + { instr_name = "complete"; instr_prio = false; + instr_action = instr_complete; instr_repeat = false; instr_help = +"complete word at cursor according to context. Useful for Emacs." }; + { instr_name = "pwd"; instr_prio = false; + instr_action = instr_pwd; instr_repeat = true; instr_help = +"print working directory." }; + { instr_name = "directory"; instr_prio = false; + instr_action = instr_dir; instr_repeat = false; instr_help = +"add directory DIR to beginning of search path for source and\n\ +interface files.\n\ +Forget cached info on source file locations and line positions.\n\ +With no argument, reset the search path." }; + { instr_name = "kill"; instr_prio = false; + instr_action = instr_kill; instr_repeat = true; instr_help = +"kill the program being debugged." }; + { instr_name = "help"; instr_prio = false; + instr_action = instr_help; instr_repeat = true; instr_help = +"print list of commands." }; + { instr_name = "quit"; instr_prio = false; + instr_action = instr_quit; instr_repeat = false; instr_help = +"exit the debugger." }; + { instr_name = "shell"; instr_prio = false; + instr_action = instr_shell; instr_repeat = true; instr_help = +"Execute a given COMMAND thru the system shell." }; + (* Displacements *) + { instr_name = "run"; instr_prio = true; + instr_action = instr_run; instr_repeat = true; instr_help = +"run the program from current position." }; + { instr_name = "reverse"; instr_prio = false; + instr_action = instr_reverse; instr_repeat = true; instr_help = +"run the program backward from current position." }; + { instr_name = "step"; instr_prio = true; + instr_action = instr_step; instr_repeat = true; instr_help = +"step program until it reaches the next event.\n\ +Argument N means do this N times (or till program stops for another reason)." }; + { instr_name = "backstep"; instr_prio = true; + instr_action = instr_back; instr_repeat = true; instr_help = +"step program backward until it reaches the previous event.\n\ +Argument N means do this N times (or till program stops for another reason)." }; + { instr_name = "goto"; instr_prio = false; + instr_action = instr_goto; instr_repeat = true; instr_help = +"go to the given time." }; + { instr_name = "finish"; instr_prio = true; + instr_action = instr_finish; instr_repeat = true; instr_help = +"execute until topmost stack frame returns." }; + { instr_name = "next"; instr_prio = true; + instr_action = instr_next; instr_repeat = true; instr_help = +"step program until it reaches the next event.\n\ +Skip over function calls.\n\ +Argument N means do this N times (or till program stops for another reason)." }; + { instr_name = "start"; instr_prio = false; + instr_action = instr_start; instr_repeat = true; instr_help = +"execute backward until the current function is exited." }; + { instr_name = "previous"; instr_prio = false; + instr_action = instr_previous; instr_repeat = true; instr_help = +"step program until it reaches the previous event.\n\ +Skip over function calls.\n\ +Argument N means do this N times (or till program stops for another reason)." }; + { instr_name = "print"; instr_prio = true; + instr_action = instr_print; instr_repeat = true; instr_help = +"print value of expressions (deep printing)." }; + { instr_name = "display"; instr_prio = true; + instr_action = instr_display; instr_repeat = true; instr_help = +"print value of expressions (shallow printing)." }; + { instr_name = "source"; instr_prio = false; + instr_action = instr_source; instr_repeat = true; instr_help = +"read command from file FILE." }; + (* Breakpoints *) + { instr_name = "break"; instr_prio = false; + instr_action = instr_break; instr_repeat = false; instr_help = +"Set breakpoint at specified line or function.\n\ +Syntax: break function-name\n\ + break @ [module] linenum\n\ + break @ [module] # characternum" }; + { instr_name = "delete"; instr_prio = false; + instr_action = instr_delete; instr_repeat = false; instr_help = +"delete some breakpoints.\n\ +Arguments are breakpoint numbers with spaces in between.\n\ +To delete all breakpoints, give no argument." }; + { instr_name = "set"; instr_prio = false; + instr_action = instr_set; instr_repeat = false; instr_help = +"--unused--" }; + { instr_name = "show"; instr_prio = false; + instr_action = instr_show; instr_repeat = true; instr_help = +"--unused--" }; + { instr_name = "info"; instr_prio = false; + instr_action = instr_info; instr_repeat = true; instr_help = +"--unused--" }; + (* Frames *) + { instr_name = "frame"; instr_prio = false; + instr_action = instr_frame; instr_repeat = true; instr_help = +"select and print a stack frame.\n\ +With no argument, print the selected stack frame.\n\ +An argument specifies the frame to select." }; + { instr_name = "backtrace"; instr_prio = false; + instr_action = instr_backtrace; instr_repeat = true; instr_help = +"print backtrace of all stack frames, or innermost COUNT frames.\n\ +With a negative argument, print outermost -COUNT frames." }; + { instr_name = "bt"; instr_prio = false; + instr_action = instr_backtrace; instr_repeat = true; instr_help = +"print backtrace of all stack frames, or innermost COUNT frames.\n\ +With a negative argument, print outermost -COUNT frames." }; + { instr_name = "up"; instr_prio = false; + instr_action = instr_up; instr_repeat = true; instr_help = +"select and print stack frame that called this one.\n\ +An argument says how many frames up to go." }; + { instr_name = "down"; instr_prio = false; + instr_action = instr_down; instr_repeat = true; instr_help = +"select and print stack frame called by this one.\n\ +An argument says how many frames down to go." }; + { instr_name = "last"; instr_prio = true; + instr_action = instr_last; instr_repeat = true; instr_help = +"go back to previous time." }; + { instr_name = "list"; instr_prio = false; + instr_action = instr_list; instr_repeat = true; instr_help = +"list the source code." }; + (* User-defined printers *) + { instr_name = "load_printer"; instr_prio = false; + instr_action = instr_load_printer; instr_repeat = false; instr_help = +"load in the debugger a .cmo or .cma file containing printing functions." }; + { instr_name = "install_printer"; instr_prio = false; + instr_action = instr_install_printer; instr_repeat = false; instr_help = +"use the given function for printing values of its input type.\n\ +The code for the function must have previously been loaded in the debugger\n\ +using \"load_printer\"." }; + { instr_name = "remove_printer"; instr_prio = false; + instr_action = instr_remove_printer; instr_repeat = false; instr_help = +"stop using the given function for printing values of its input type." } +]; + variable_list := [ + (* variable name, (writing, reading), help reading, help writing *) + { var_name = "arguments"; + var_action = raw_line_variable true arguments; + var_help = +"arguments to give program being debugged when it is started." }; + { var_name = "program"; + var_action = path_variable true program_name; + var_help = +"name of program to be debugged." }; + { var_name = "loadingmode"; + var_action = loading_mode_variable ppf; + var_help = +"mode of loading.\n\ +It can be either : + direct : the program is directly called by the debugger.\n\ + runtime : the debugger execute `ocamlrun programname arguments'.\n\ + manual : the program is not launched by the debugger,\n\ + but manually by the user." }; + { var_name = "processcount"; + var_action = integer_variable false 1 "Must be >= 1." + checkpoint_max_count; + var_help = +"maximum number of process to keep." }; + { var_name = "checkpoints"; + var_action = boolean_variable false make_checkpoints; + var_help = +"whether to make checkpoints or not." }; + { var_name = "bigstep"; + var_action = int64_variable false _1 "Must be >= 1." + checkpoint_big_step; + var_help = +"step between checkpoints during long displacements." }; + { var_name = "smallstep"; + var_action = int64_variable false _1 "Must be >= 1." + checkpoint_small_step; + var_help = +"step between checkpoints during small displacements." }; + { var_name = "socket"; + var_action = raw_variable true socket_name; + var_help = +"name of the socket used by communications debugger-runtime." }; + { var_name = "history"; + var_action = integer_variable false 0 "" history_size; + var_help = +"history size." }; + { var_name = "print_depth"; + var_action = integer_variable false 1 "Must be at least 1" + max_printer_depth; + var_help = +"maximal depth for printing of values." }; + { var_name = "print_length"; + var_action = integer_variable false 1 "Must be at least 1" + max_printer_steps; + var_help = +"maximal number of value nodes printed." }]; + + info_list := + (* info name, function, help *) + [{ info_name = "modules"; + info_action = info_modules ppf; + info_help = "list opened modules." }; + { info_name = "checkpoints"; + info_action = info_checkpoints ppf; + info_help = "list checkpoints." }; + { info_name = "breakpoints"; + info_action = info_breakpoints ppf; + info_help = "list breakpoints." }; + { info_name = "events"; + info_action = info_events ppf; + info_help = "list events in MODULE (default is current module)." }] + +let _ = init std_formatter diff --git a/debugger/command_line.mli b/debugger/command_line.mli new file mode 100644 index 0000000..98d4033 --- /dev/null +++ b/debugger/command_line.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: command_line.mli,v 1.4 2000-03-07 18:22:14 weis Exp $ *) + +(************************ Reading and executing commands ***************) + +open Lexing;; +open Format;; + +val interprete_line : formatter -> string -> bool;; +val line_loop : formatter -> lexbuf -> unit;; diff --git a/debugger/debugcom.ml b/debugger/debugcom.ml new file mode 100644 index 0000000..d42ad88 --- /dev/null +++ b/debugger/debugcom.ml @@ -0,0 +1,281 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: debugcom.ml,v 1.13 2008-07-29 08:31:41 xleroy Exp $ *) + +(* Low-level communication with the debuggee *) + +open Int64ops +open Primitives + +(* The current connection with the debuggee *) + +let conn = ref Primitives.std_io + +let set_current_connection io_chan = + conn := io_chan + +(* Modify the program code *) + +let set_event pos = + output_char !conn.io_out 'e'; + output_binary_int !conn.io_out pos + +let set_breakpoint pos = + output_char !conn.io_out 'B'; + output_binary_int !conn.io_out pos + +let reset_instr pos = + output_char !conn.io_out 'i'; + output_binary_int !conn.io_out pos + +(* Basic commands for flow control *) + +type execution_summary = + Event + | Breakpoint + | Exited + | Trap_barrier + | Uncaught_exc + +type report = { + rep_type : execution_summary; + rep_event_count : int; + rep_stack_pointer : int; + rep_program_pointer : int +} + +type checkpoint_report = + Checkpoint_done of int + | Checkpoint_failed + +(* Run the debuggee for N events *) + +let do_go_smallint n = + output_char !conn.io_out 'g'; + output_binary_int !conn.io_out n; + flush !conn.io_out; + Input_handling.execute_with_other_controller + Input_handling.exit_main_loop + !conn + (function () -> + Input_handling.main_loop (); + let summary = + match input_char !conn.io_in with + 'e' -> Event + | 'b' -> Breakpoint + | 'x' -> Exited + | 's' -> Trap_barrier + | 'u' -> Uncaught_exc + | _ -> Misc.fatal_error "Debugcom.do_go" in + let event_counter = input_binary_int !conn.io_in in + let stack_pos = input_binary_int !conn.io_in in + let pc = input_binary_int !conn.io_in in + { rep_type = summary; + rep_event_count = event_counter; + rep_stack_pointer = stack_pos; + rep_program_pointer = pc }) + +let rec do_go n = + assert (n >= _0); + if n > max_small_int then( + ignore (do_go_smallint max_int); + do_go (n -- max_small_int) + )else( + do_go_smallint (Int64.to_int n) + ) +;; + +(* Perform a checkpoint *) + +let do_checkpoint () = + match Sys.os_type with + "Win32" -> failwith "do_checkpoint" + | _ -> + output_char !conn.io_out 'c'; + flush !conn.io_out; + let pid = input_binary_int !conn.io_in in + if pid = -1 then Checkpoint_failed else Checkpoint_done pid + +(* Kill the given process. *) +let stop chan = + try + output_char chan.io_out 's'; + flush chan.io_out + with + Sys_error _ | End_of_file -> () + +(* Ask a process to wait for its child which has been killed. *) +(* (so as to eliminate zombies). *) +let wait_child chan = + try + output_char chan.io_out 'w' + with + Sys_error _ | End_of_file -> () + +(* Move to initial frame (that of current function). *) +(* Return stack position and current pc *) + +let initial_frame () = + output_char !conn.io_out '0'; + flush !conn.io_out; + let stack_pos = input_binary_int !conn.io_in in + let pc = input_binary_int !conn.io_in in + (stack_pos, pc) + +let set_initial_frame () = + ignore(initial_frame ()) + +(* Move up one frame *) +(* Return stack position and current pc. + If there's no frame above, return (-1, 0). *) + +let up_frame stacksize = + output_char !conn.io_out 'U'; + output_binary_int !conn.io_out stacksize; + flush !conn.io_out; + let stack_pos = input_binary_int !conn.io_in in + let pc = if stack_pos = -1 then 0 else input_binary_int !conn.io_in in + (stack_pos, pc) + +(* Get and set the current frame position *) + +let get_frame () = + output_char !conn.io_out 'f'; + flush !conn.io_out; + let stack_pos = input_binary_int !conn.io_in in + let pc = input_binary_int !conn.io_in in + (stack_pos, pc) + +let set_frame stack_pos = + output_char !conn.io_out 'S'; + output_binary_int !conn.io_out stack_pos + +(* Set the trap barrier to given stack position. *) + +let set_trap_barrier pos = + output_char !conn.io_out 'b'; + output_binary_int !conn.io_out pos + +(* Handling of remote values *) + +let value_size = if 1 lsl 31 = 0 then 4 else 8 + +let input_remote_value ic = + let v = String.create value_size in + really_input ic v 0 value_size; v + +let output_remote_value ic v = + output ic v 0 value_size + +exception Marshalling_error + +module Remote_value = + struct + type t = Remote of string | Local of Obj.t + + let obj = function + | Local obj -> Obj.obj obj + | Remote v -> + output_char !conn.io_out 'M'; + output_remote_value !conn.io_out v; + flush !conn.io_out; + try + input_value !conn.io_in + with End_of_file | Failure _ -> + raise Marshalling_error + + let is_block = function + | Local obj -> Obj.is_block obj + | Remote v -> Obj.is_block (Array.unsafe_get (Obj.magic v : Obj.t array) 0) + + let tag = function + | Local obj -> Obj.tag obj + | Remote v -> + output_char !conn.io_out 'H'; + output_remote_value !conn.io_out v; + flush !conn.io_out; + let header = input_binary_int !conn.io_in in + header land 0xFF + + let size = function + | Local obj -> Obj.size obj + | Remote v -> + output_char !conn.io_out 'H'; + output_remote_value !conn.io_out v; + flush !conn.io_out; + let header = input_binary_int !conn.io_in in + if header land 0xFF = Obj.double_array_tag && Sys.word_size = 32 + then header lsr 11 + else header lsr 10 + + let field v n = + match v with + | Local obj -> Local(Obj.field obj n) + | Remote v -> + output_char !conn.io_out 'F'; + output_remote_value !conn.io_out v; + output_binary_int !conn.io_out n; + flush !conn.io_out; + if input_byte !conn.io_in = 0 then + Remote(input_remote_value !conn.io_in) + else begin + let buf = String.create 8 in + really_input !conn.io_in buf 0 8; + let floatbuf = float n (* force allocation of a new float *) in + String.unsafe_blit buf 0 (Obj.magic floatbuf) 0 8; + Local(Obj.repr floatbuf) + end + + let of_int n = + Local(Obj.repr n) + + let local pos = + output_char !conn.io_out 'L'; + output_binary_int !conn.io_out pos; + flush !conn.io_out; + Remote(input_remote_value !conn.io_in) + + let from_environment pos = + output_char !conn.io_out 'E'; + output_binary_int !conn.io_out pos; + flush !conn.io_out; + Remote(input_remote_value !conn.io_in) + + let global pos = + output_char !conn.io_out 'G'; + output_binary_int !conn.io_out pos; + flush !conn.io_out; + Remote(input_remote_value !conn.io_in) + + let accu () = + output_char !conn.io_out 'A'; + flush !conn.io_out; + Remote(input_remote_value !conn.io_in) + + let closure_code = function + | Local obj -> assert false + | Remote v -> + output_char !conn.io_out 'C'; + output_remote_value !conn.io_out v; + flush !conn.io_out; + input_binary_int !conn.io_in + + let same rv1 rv2 = + match (rv1, rv2) with + (Local obj1, Local obj2) -> obj1 == obj2 + | (Remote v1, Remote v2) -> v1 = v2 + (* string equality -> equality of remote pointers *) + | (_, _) -> false + + end diff --git a/debugger/debugcom.mli b/debugger/debugcom.mli new file mode 100644 index 0000000..6d5dba2 --- /dev/null +++ b/debugger/debugcom.mli @@ -0,0 +1,102 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: debugcom.mli,v 1.8 2002-10-29 17:53:23 doligez Exp $ *) + +(* Low-level communication with the debuggee *) + +type execution_summary = + Event + | Breakpoint + | Exited + | Trap_barrier + | Uncaught_exc + +type report = + { rep_type : execution_summary; + rep_event_count : int; + rep_stack_pointer : int; + rep_program_pointer : int } + +type checkpoint_report = + Checkpoint_done of int + | Checkpoint_failed + +(* Set the current connection with the debuggee *) +val set_current_connection : Primitives.io_channel -> unit + +(* Put an event at given pc *) +val set_event : int -> unit + +(* Put a breakpoint at given pc *) +val set_breakpoint : int -> unit + +(* Remove breakpoint or event at given pc *) +val reset_instr : int -> unit + +(* Create a new checkpoint (the current process forks). *) +val do_checkpoint : unit -> checkpoint_report + +(* Step N events. *) +val do_go : int64 -> report + +(* Tell given process to terminate *) +val stop : Primitives.io_channel -> unit + +(* Tell given process to wait for its children *) +val wait_child : Primitives.io_channel -> unit + +(* Move to initial frame (that of current function). *) +(* Return stack position and current pc *) +val initial_frame : unit -> int * int +val set_initial_frame : unit -> unit + +(* Get the current frame position *) +(* Return stack position and current pc *) +val get_frame : unit -> int * int + +(* Set the current frame *) +val set_frame : int -> unit + +(* Move up one frame *) +(* Return stack position and current pc. + If there's no frame above, return (-1, 0). *) +val up_frame : int -> int * int + +(* Set the trap barrier to given stack position. *) +val set_trap_barrier : int -> unit + +(* Handling of remote values *) + +exception Marshalling_error + +module Remote_value : + sig + type t + + val obj : t -> 'a + val is_block : t -> bool + val tag : t -> int + val size : t -> int + val field : t -> int -> t + val same : t -> t -> bool + + val of_int : int -> t + + val local : int -> t + val from_environment : int -> t + val global : int -> t + val accu : unit -> t + val closure_code : t -> int + + end diff --git a/debugger/debugger_config.ml b/debugger/debugger_config.ml new file mode 100644 index 0000000..935f65a --- /dev/null +++ b/debugger/debugger_config.ml @@ -0,0 +1,80 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: debugger_config.ml,v 1.11 2008-07-29 08:31:41 xleroy Exp $ *) + +(**************************** Configuration file ***********************) + +open Int64ops + +exception Toplevel + +(*** Miscellaneous parameters. ***) + +(*ISO 6429 color sequences +00 to restore default color +01 for brighter colors +04 for underlined text +05 for flashing text +30 for black foreground +31 for red foreground +32 for green foreground +33 for yellow (or brown) foreground +34 for blue foreground +35 for purple foreground +36 for cyan foreground +37 for white (or gray) foreground +40 for black background +41 for red background +42 for green background +43 for yellow (or brown) background +44 for blue background +45 for purple background +46 for cyan background +47 for white (or gray) background +let debugger_prompt = "\027[1;04m(ocd)\027[0m " +and event_mark_before = "\027[1;31m$\027[0m" +and event_mark_after = "\027[1;34m$\027[0m" +*) +let debugger_prompt = "(ocd) " +let event_mark_before = "<|b|>" +let event_mark_after = "<|a|>" + +(* Name of shell used to launch the debuggee *) +let shell = + match Sys.os_type with + "Win32" -> "cmd" + | _ -> "/bin/sh" + +(* Name of the Objective Caml runtime. *) +let runtime_program = "ocamlrun" + +(* Time history size (for `last') *) +let history_size = ref 30 + +(*** Time travel parameters. ***) + +(* Step between checkpoints for long displacements.*) +let checkpoint_big_step = ref (~~ "10000") + +(* Idem for small ones. *) +let checkpoint_small_step = ref (~~ "1000") + +(* Maximum number of checkpoints. *) +let checkpoint_max_count = ref 15 + +(* Whether to keep checkpoints or not. *) +let make_checkpoints = ref + (match Sys.os_type with + "Win32" -> false + | _ -> true) diff --git a/debugger/debugger_config.mli b/debugger/debugger_config.mli new file mode 100644 index 0000000..e9b7d4a --- /dev/null +++ b/debugger/debugger_config.mli @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: debugger_config.mli,v 1.5 2002-11-17 16:42:10 xleroy Exp $ *) + +(********************** Configuration file *****************************) + +exception Toplevel + +(*** Miscellaneous parameters. ***) + +val debugger_prompt : string +val event_mark_before : string +val event_mark_after : string +val shell : string +val runtime_program : string +val history_size : int ref + +(*** Time travel paramaters. ***) + +val checkpoint_big_step : int64 ref +val checkpoint_small_step : int64 ref +val checkpoint_max_count : int ref +val make_checkpoints : bool ref + diff --git a/debugger/dynlink.ml b/debugger/dynlink.ml new file mode 100644 index 0000000..33d7168 --- /dev/null +++ b/debugger/dynlink.ml @@ -0,0 +1,252 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dynlink.ml,v 1.2 2006-09-28 21:36:38 xleroy Exp $ *) + +(* Dynamic loading of .cmo files *) + +(* This is a copy of ../otherlibs/dynlink/dynlink.ml that does not + use Dynlinkaux (the module that packs some of the compiler modules). *) + +open Cmo_format + +type linking_error = + Undefined_global of string + | Unavailable_primitive of string + | Uninitialized_global of string + +type error = + Not_a_bytecode_file of string + | Inconsistent_import of string + | Unavailable_unit of string + | Unsafe_file + | Linking_error of string * linking_error + | Corrupted_interface of string + | File_not_found of string + | Cannot_open_dll of string + +exception Error of error + +(* Management of interface CRCs *) + +let crc_interfaces = ref (Consistbl.create ()) +let allow_extension = ref true + +(* Check that the object file being loaded has been compiled against + the same interfaces as the program itself. In addition, check that + only authorized compilation units are referenced. *) + +let check_consistency file_name cu = + try + List.iter + (fun (name, crc) -> + if name = cu.cu_name then + Consistbl.set !crc_interfaces name crc file_name + else if !allow_extension then + Consistbl.check !crc_interfaces name crc file_name + else + Consistbl.check_noadd !crc_interfaces name crc file_name) + cu.cu_imports + with Consistbl.Inconsistency(name, user, auth) -> + raise(Error(Inconsistent_import name)) + | Consistbl.Not_available(name) -> + raise(Error(Unavailable_unit name)) + +(* Empty the crc_interfaces table *) + +let clear_available_units () = + Consistbl.clear !crc_interfaces; + allow_extension := false + +(* Allow only access to the units with the given names *) + +let allow_only names = + Consistbl.filter (fun name -> List.mem name names) !crc_interfaces; + allow_extension := false + +(* Prohibit access to the units with the given names *) + +let prohibit names = + Consistbl.filter (fun name -> not (List.mem name names)) !crc_interfaces; + allow_extension := false + +(* Initialize the crc_interfaces table with a list of units with fixed CRCs *) + +let add_available_units units = + List.iter (fun (unit, crc) -> Consistbl.set !crc_interfaces unit crc "") + units + +(* Default interface CRCs: those found in the current executable *) +let default_crcs = ref [] + +let default_available_units () = + clear_available_units(); + add_available_units !default_crcs; + allow_extension := true + +(* Initialize the linker tables and everything *) + +let init () = + default_crcs := Symtable.init_toplevel(); + default_available_units () + +(* Read the CRC of an interface from its .cmi file *) + +let digest_interface unit loadpath = + let filename = + let shortname = unit ^ ".cmi" in + try + Misc.find_in_path_uncap loadpath shortname + with Not_found -> + raise (Error(File_not_found shortname)) in + let ic = open_in_bin filename in + try + let buffer = String.create (String.length Config.cmi_magic_number) in + really_input ic buffer 0 (String.length Config.cmi_magic_number); + if buffer <> Config.cmi_magic_number then begin + close_in ic; + raise(Error(Corrupted_interface filename)) + end; + ignore (input_value ic); + let crc = + match input_value ic with + (_, crc) :: _ -> crc + | _ -> raise(Error(Corrupted_interface filename)) + in + close_in ic; + crc + with End_of_file | Failure _ -> + close_in ic; + raise(Error(Corrupted_interface filename)) + +(* Initialize the crc_interfaces table with a list of units. + Their CRCs are read from their interfaces. *) + +let add_interfaces units loadpath = + add_available_units + (List.map (fun unit -> (unit, digest_interface unit loadpath)) units) + +(* Check whether the object file being loaded was compiled in unsafe mode *) + +let unsafe_allowed = ref false + +let allow_unsafe_modules b = + unsafe_allowed := b + +let check_unsafe_module cu = + if (not !unsafe_allowed) && cu.cu_primitives <> [] + then raise(Error(Unsafe_file)) + +(* Load in-core and execute a bytecode object file *) + +let load_compunit ic file_name compunit = + check_consistency file_name compunit; + check_unsafe_module compunit; + seek_in ic compunit.cu_pos; + let code_size = compunit.cu_codesize + 8 in + let code = Meta.static_alloc code_size in + unsafe_really_input ic code 0 compunit.cu_codesize; + String.unsafe_set code compunit.cu_codesize (Char.chr Opcodes.opRETURN); + String.unsafe_set code (compunit.cu_codesize + 1) '\000'; + String.unsafe_set code (compunit.cu_codesize + 2) '\000'; + String.unsafe_set code (compunit.cu_codesize + 3) '\000'; + String.unsafe_set code (compunit.cu_codesize + 4) '\001'; + String.unsafe_set code (compunit.cu_codesize + 5) '\000'; + String.unsafe_set code (compunit.cu_codesize + 6) '\000'; + String.unsafe_set code (compunit.cu_codesize + 7) '\000'; + let initial_symtable = Symtable.current_state() in + begin try + Symtable.patch_object code compunit.cu_reloc; + Symtable.check_global_initialized compunit.cu_reloc; + Symtable.update_global_table() + with Symtable.Error error -> + let new_error = + match error with + Symtable.Undefined_global s -> Undefined_global s + | Symtable.Unavailable_primitive s -> Unavailable_primitive s + | Symtable.Uninitialized_global s -> Uninitialized_global s + | _ -> assert false in + raise(Error(Linking_error (file_name, new_error))) + end; + begin try + ignore((Meta.reify_bytecode code code_size) ()) + with exn -> + Symtable.restore_state initial_symtable; + raise exn + end + +let loadfile file_name = + let ic = open_in_bin file_name in + try + let buffer = String.create (String.length Config.cmo_magic_number) in + really_input ic buffer 0 (String.length Config.cmo_magic_number); + if buffer = Config.cmo_magic_number then begin + let compunit_pos = input_binary_int ic in (* Go to descriptor *) + seek_in ic compunit_pos; + load_compunit ic file_name (input_value ic : compilation_unit) + end else + if buffer = Config.cma_magic_number then begin + let toc_pos = input_binary_int ic in (* Go to table of contents *) + seek_in ic toc_pos; + let lib = (input_value ic : library) in + begin try + Dll.open_dlls Dll.For_execution + (List.map Dll.extract_dll_name lib.lib_dllibs) + with Failure reason -> + raise(Error(Cannot_open_dll reason)) + end; + List.iter (load_compunit ic file_name) lib.lib_units + end else + raise(Error(Not_a_bytecode_file file_name)); + close_in ic + with exc -> + close_in ic; raise exc + +let loadfile_private file_name = + let initial_symtable = Symtable.current_state() + and initial_crc = !crc_interfaces in + try + loadfile file_name; + Symtable.hide_additions initial_symtable; + crc_interfaces := initial_crc + with exn -> + Symtable.hide_additions initial_symtable; + crc_interfaces := initial_crc; + raise exn + +(* Error report *) + +let error_message = function + Not_a_bytecode_file name -> + name ^ " is not a bytecode object file" + | Inconsistent_import name -> + "interface mismatch on " ^ name + | Unavailable_unit name -> + "no implementation available for " ^ name + | Unsafe_file -> + "this object file uses unsafe features" + | Linking_error (name, Undefined_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "Reference to undefined global `" ^ s ^ "'" + | Linking_error (name, Unavailable_primitive s) -> + "error while linking " ^ name ^ ".\n" ^ + "The external function `" ^ s ^ "' is not available" + | Linking_error (name, Uninitialized_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "The module `" ^ s ^ "' is not yet initialized" + | Corrupted_interface name -> + "corrupted interface file " ^ name + | File_not_found name -> + "cannot find file " ^ name ^ " in search path" + | Cannot_open_dll reason -> + "error loading shared library: " ^ reason diff --git a/debugger/dynlink.mli b/debugger/dynlink.mli new file mode 100644 index 0000000..c4d7b88 --- /dev/null +++ b/debugger/dynlink.mli @@ -0,0 +1,129 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dynlink.mli,v 1.1 2006-05-11 15:51:31 xleroy Exp $ *) + +(** Dynamic loading of bytecode object files. *) + +(** {6 Initialization} *) + +val init : unit -> unit +(** Initialize the [Dynlink] library. + Must be called before any other function in this module. *) + +(** {6 Dynamic loading of compiled bytecode files} *) + +val loadfile : string -> unit +(** Load the given bytecode object file ([.cmo] file) or + bytecode library file ([.cma] file), and link it with the running program. + All toplevel expressions in the loaded compilation units + are evaluated. No facilities are provided to + access value names defined by the unit. Therefore, the unit + must register itself its entry points with the main program, + e.g. by modifying tables of functions. *) + +val loadfile_private : string -> unit +(** Same as [loadfile], except that the compilation units just loaded + are hidden (cannot be referenced) from other modules dynamically + loaded afterwards. *) + +(** {6 Access control} *) + +val allow_only: string list -> unit +(** [allow_only units] restricts the compilation units that dynamically-linked + units can reference: it only allows references to the units named in + list [units]. References to any other compilation unit will cause + a [Unavailable_unit] error during [loadfile] or [loadfile_private]. + + Initially (just after calling [init]), all compilation units composing + the program currently running are available for reference from + dynamically-linked units. [allow_only] can be used to grant access + to some of them only, e.g. to the units that compose the API for + dynamically-linked code, and prevent access to all other units, + e.g. private, internal modules of the running program. *) + +val prohibit: string list -> unit +(** [prohibit units] prohibits dynamically-linked units from referencing + the units named in list [units]. This can be used to prevent + access to selected units, e.g. private, internal modules of + the running program. *) + +val default_available_units: unit -> unit +(** Reset the set of units that can be referenced from dynamically-linked + code to its default value, that is, all units composing the currently + running program. *) + +val allow_unsafe_modules : bool -> unit +(** Govern whether unsafe object files are allowed to be + dynamically linked. A compilation unit is ``unsafe'' if it contains + declarations of external functions, which can break type safety. + By default, dynamic linking of unsafe object files is + not allowed. *) + +(** {6 Deprecated, low-level API for access control} *) + +(** @deprecated The functions [add_interfaces], [add_available_units] + and [clear_available_units] should not be used in new programs, + since the default initialization of allowed units, along with the + [allow_only] and [prohibit] function, provides a better, safer + mechanism to control access to program units. The three functions + below are provided for backward compatibility only. *) + +val add_interfaces : string list -> string list -> unit +(** [add_interfaces units path] grants dynamically-linked object + files access to the compilation units named in list [units]. + The interfaces ([.cmi] files) for these units are searched in + [path] (a list of directory names). *) + +val add_available_units : (string * Digest.t) list -> unit +(** Same as {!Dynlink.add_interfaces}, but instead of searching [.cmi] files + to find the unit interfaces, uses the interface digests given + for each unit. This way, the [.cmi] interface files need not be + available at run-time. The digests can be extracted from [.cmi] + files using the [extract_crc] program installed in the + Objective Caml standard library directory. *) + +val clear_available_units : unit -> unit +(** Empty the list of compilation units accessible to dynamically-linked + programs. *) + +(** {6 Error reporting} *) + +type linking_error = + Undefined_global of string + | Unavailable_primitive of string + | Uninitialized_global of string + +type error = + Not_a_bytecode_file of string + | Inconsistent_import of string + | Unavailable_unit of string + | Unsafe_file + | Linking_error of string * linking_error + | Corrupted_interface of string + | File_not_found of string + | Cannot_open_dll of string + +exception Error of error +(** Errors in dynamic linking are reported by raising the [Error] + exception with a description of the error. *) + +val error_message : error -> string +(** Convert an error description to a printable message. *) + + +(**/**) + +(** {6 Internal functions} *) + +val digest_interface : string -> string list -> Digest.t diff --git a/debugger/envaux.ml b/debugger/envaux.ml new file mode 100644 index 0000000..14b2d82 --- /dev/null +++ b/debugger/envaux.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: envaux.ml,v 1.7 2000-03-06 22:11:17 weis Exp $ *) + +open Misc +open Types +open Env + +type error = + Module_not_found of Path.t + +exception Error of error + +let env_cache = + (Hashtbl.create 59 : (Env.summary, Env.t) Hashtbl.t) + +let reset_cache () = + Hashtbl.clear env_cache; + Env.reset_cache() + +let extract_sig env mty = + match Mtype.scrape env mty with + Tmty_signature sg -> sg + | _ -> fatal_error "Envaux.extract_sig" + +let rec env_from_summary sum = + try + Hashtbl.find env_cache sum + with Not_found -> + let env = + match sum with + Env_empty -> + Env.empty + | Env_value(s, id, desc) -> + Env.add_value id desc (env_from_summary s) + | Env_type(s, id, desc) -> + Env.add_type id desc (env_from_summary s) + | Env_exception(s, id, desc) -> + Env.add_exception id desc (env_from_summary s) + | Env_module(s, id, desc) -> + Env.add_module id desc (env_from_summary s) + | Env_modtype(s, id, desc) -> + Env.add_modtype id desc (env_from_summary s) + | Env_class(s, id, desc) -> + Env.add_class id desc (env_from_summary s) + | Env_cltype (s, id, desc) -> + Env.add_cltype id desc (env_from_summary s) + | Env_open(s, path) -> + let env = env_from_summary s in + let mty = + try + Env.find_module path env + with Not_found -> + raise (Error (Module_not_found path)) + in + Env.open_signature path (extract_sig env mty) env + in + Hashtbl.add env_cache sum env; + env + +let env_of_event = + function + None -> Env.empty + | Some ev -> env_from_summary ev.Instruct.ev_typenv + +(* Error report *) + +open Format + +let report_error ppf = function + | Module_not_found p -> + fprintf ppf "@[Cannot find module %a@].@." Printtyp.path p diff --git a/debugger/envaux.mli b/debugger/envaux.mli new file mode 100644 index 0000000..a6692b1 --- /dev/null +++ b/debugger/envaux.mli @@ -0,0 +1,33 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: envaux.mli,v 1.5 2000-03-06 22:11:20 weis Exp $ *) + +open Format + +(* Convert environment summaries to environments *) + +val env_of_event: Instruct.debug_event option -> Env.t + +(* Empty the environment caches. To be called when load_path changes. *) + +val reset_cache: unit -> unit + +(* Error report *) + +type error = + Module_not_found of Path.t + +exception Error of error + +val report_error: formatter -> error -> unit diff --git a/debugger/eval.ml b/debugger/eval.ml new file mode 100644 index 0000000..0df77e0 --- /dev/null +++ b/debugger/eval.ml @@ -0,0 +1,207 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: eval.ml,v 1.30 2007-11-28 22:32:14 weis Exp $ *) + +open Debugger_config +open Misc +open Path +open Instruct +open Types +open Parser_aux + +type error = + Unbound_identifier of Ident.t + | Not_initialized_yet of Path.t + | Unbound_long_identifier of Longident.t + | Unknown_name of int + | Tuple_index of type_expr * int * int + | Array_index of int * int + | List_index of int * int + | String_index of string * int * int + | Wrong_item_type of type_expr * int + | Wrong_label of type_expr * string + | Not_a_record of type_expr + | No_result + +exception Error of error + +let abstract_type = + Btype.newgenty (Tconstr (Pident (Ident.create ""), [], ref Mnil)) + +let rec path event = function + Pident id -> + if Ident.global id then + Debugcom.Remote_value.global (Symtable.get_global_position id) + else + begin match event with + Some ev -> + begin try + let pos = Ident.find_same id ev.ev_compenv.ce_stack in + Debugcom.Remote_value.local (ev.ev_stacksize - pos) + with Not_found -> + try + let pos = Ident.find_same id ev.ev_compenv.ce_heap in + Debugcom.Remote_value.from_environment pos + with Not_found -> + raise(Error(Unbound_identifier id)) + end + | None -> + raise(Error(Unbound_identifier id)) + end + | Pdot(root, fieldname, pos) -> + let v = path event root in + if not (Debugcom.Remote_value.is_block v) then + raise(Error(Not_initialized_yet root)); + Debugcom.Remote_value.field v pos + | Papply(p1, p2) -> + fatal_error "Eval.path: Papply" + +let rec expression event env = function + E_ident lid -> + begin try + let (p, valdesc) = Env.lookup_value lid env in + (begin match valdesc.val_kind with + Val_ivar (_, cl_num) -> + let (p0, _) = + Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env + in + let v = path event p0 in + let i = path event p in + Debugcom.Remote_value.field v (Debugcom.Remote_value.obj i) + | _ -> + path event p + end, + Ctype.correct_levels valdesc.val_type) + with Not_found -> + raise(Error(Unbound_long_identifier lid)) + end + | E_result -> + begin match event with + Some {ev_kind = Event_after ty} when !Frames.current_frame = 0 -> + (Debugcom.Remote_value.accu(), ty) + | _ -> + raise(Error(No_result)) + end + | E_name n -> + begin try + Printval.find_named_value n + with Not_found -> + raise(Error(Unknown_name n)) + end + | E_item(arg, n) -> + let (v, ty) = expression event env arg in + begin match (Ctype.repr(Ctype.expand_head_opt env ty)).desc with + Ttuple ty_list -> + if n < 1 || n > List.length ty_list + then raise(Error(Tuple_index(ty, List.length ty_list, n))) + else (Debugcom.Remote_value.field v (n-1), List.nth ty_list (n-1)) + | Tconstr(path, [ty_arg], _) when Path.same path Predef.path_array -> + let size = Debugcom.Remote_value.size v in + if n >= size + then raise(Error(Array_index(size, n))) + else (Debugcom.Remote_value.field v n, ty_arg) + | Tconstr(path, [ty_arg], _) when Path.same path Predef.path_list -> + let rec nth pos v = + if not (Debugcom.Remote_value.is_block v) then + raise(Error(List_index(pos, n))) + else if pos = n then + (Debugcom.Remote_value.field v 0, ty_arg) + else + nth (pos + 1) (Debugcom.Remote_value.field v 1) + in nth 0 v + | Tconstr(path, [], _) when Path.same path Predef.path_string -> + let s = (Debugcom.Remote_value.obj v : string) in + if n >= String.length s + then raise(Error(String_index(s, String.length s, n))) + else (Debugcom.Remote_value.of_int(Char.code s.[n]), + Predef.type_char) + | _ -> + raise(Error(Wrong_item_type(ty, n))) + end + | E_field(arg, lbl) -> + let (v, ty) = expression event env arg in + begin match (Ctype.repr(Ctype.expand_head_opt env ty)).desc with + Tconstr(path, args, _) -> + let tydesc = Env.find_type path env in + begin match tydesc.type_kind with + Type_record(lbl_list, repr) -> + let (pos, ty_res) = + find_label lbl env ty path tydesc 0 lbl_list in + (Debugcom.Remote_value.field v pos, ty_res) + | _ -> raise(Error(Not_a_record ty)) + end + | _ -> raise(Error(Not_a_record ty)) + end + +and find_label lbl env ty path tydesc pos = function + [] -> + raise(Error(Wrong_label(ty, lbl))) + | (name, mut, ty_arg) :: rem -> + if name = lbl then begin + let ty_res = + Btype.newgenty(Tconstr(path, tydesc.type_params, ref Mnil)) + in + (pos, + try Ctype.apply env [ty_res] ty_arg [ty] with Ctype.Cannot_apply -> + abstract_type) + end else + find_label lbl env ty path tydesc (pos + 1) rem + +(* Error report *) + +open Format + +let report_error ppf = function + | Unbound_identifier id -> + fprintf ppf "@[Unbound identifier %s@]@." (Ident.name id) + | Not_initialized_yet path -> + fprintf ppf + "@[The module path %a is not yet initialized.@ \ + Please run program forward@ \ + until its initialization code is executed.@]@." + Printtyp.path path + | Unbound_long_identifier lid -> + fprintf ppf "@[Unbound identifier %a@]@." Printtyp.longident lid + | Unknown_name n -> + fprintf ppf "@[Unknown value name $%i@]@." n + | Tuple_index(ty, len, pos) -> + Printtyp.reset_and_mark_loops ty; + fprintf ppf + "@[Cannot extract field number %i from a %i-components \ + tuple of type@ %a@]@." + pos len Printtyp.type_expr ty + | Array_index(len, pos) -> + fprintf ppf + "@[Cannot extract element number %i from array of length %i@]@." pos len + | List_index(len, pos) -> + fprintf ppf + "@[Cannot extract element number %i from list of length %i@]@." pos len + | String_index(s, len, pos) -> + fprintf ppf + "@[Cannot extract character number %i@ \ + from the following string of length %i:@ %S@]@." + pos len s + | Wrong_item_type(ty, pos) -> + fprintf ppf + "@[Cannot extract item number %i from a value of type@ %a@]@." + pos Printtyp.type_expr ty + | Wrong_label(ty, lbl) -> + fprintf ppf + "@[The record type@ %a@ has no label named %s@]@." + Printtyp.type_expr ty lbl + | Not_a_record ty -> + fprintf ppf + "@[The type@ %a@ is not a record type@]@." Printtyp.type_expr ty + | No_result -> + fprintf ppf "@[No result available at current program event@]@." diff --git a/debugger/eval.mli b/debugger/eval.mli new file mode 100644 index 0000000..77a73f9 --- /dev/null +++ b/debugger/eval.mli @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: eval.mli,v 1.6 2000-03-06 22:11:21 weis Exp $ *) + +open Types +open Parser_aux +open Format + +val expression : + Instruct.debug_event option -> Env.t -> expression -> + Debugcom.Remote_value.t * type_expr + +type error = + | Unbound_identifier of Ident.t + | Not_initialized_yet of Path.t + | Unbound_long_identifier of Longident.t + | Unknown_name of int + | Tuple_index of type_expr * int * int + | Array_index of int * int + | List_index of int * int + | String_index of string * int * int + | Wrong_item_type of type_expr * int + | Wrong_label of type_expr * string + | Not_a_record of type_expr + | No_result + +exception Error of error + +val report_error: formatter -> error -> unit diff --git a/debugger/events.ml b/debugger/events.ml new file mode 100644 index 0000000..23ee955 --- /dev/null +++ b/debugger/events.ml @@ -0,0 +1,50 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: events.ml,v 1.6 2005-08-25 15:35:16 doligez Exp $ *) + +(********************************* Events ******************************) + +open Instruct +open Primitives +open Checkpoints + +let get_pos ev = + match ev.ev_kind with + | Event_before -> ev.ev_loc.Location.loc_start + | Event_after _ -> ev.ev_loc.Location.loc_end + | _ -> ev.ev_loc.Location.loc_start +;; + + +(*** Current events. ***) + +(* Event at current position *) +let current_event = + ref (None : debug_event option) + +(* Current position in source. *) +(* Raise `Not_found' if not on an event (beginning or end of program). *) +let get_current_event () = + match !current_event with + | None -> raise Not_found + | Some ev -> ev + +let current_event_is_before () = + match !current_event with + None -> + raise Not_found + | Some {ev_kind = Event_before} -> + true + | _ -> + false diff --git a/debugger/events.mli b/debugger/events.mli new file mode 100644 index 0000000..6daf25e --- /dev/null +++ b/debugger/events.mli @@ -0,0 +1,30 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: events.mli,v 1.4 2005-08-25 15:35:16 doligez Exp $ *) + +open Instruct + +val get_pos : debug_event -> Lexing.position;; + +(** Current events. **) + +(* The event at current position. *) +val current_event : debug_event option ref + +(* Current position in source. *) +(* Raise `Not_found' if not on an event (beginning or end of program). *) +val get_current_event : unit -> debug_event + +val current_event_is_before : unit -> bool + diff --git a/debugger/exec.ml b/debugger/exec.ml new file mode 100644 index 0000000..1665510 --- /dev/null +++ b/debugger/exec.ml @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: exec.ml,v 1.5 2008-07-29 08:31:41 xleroy Exp $ *) + +(* Handling of keyboard interrupts *) + +let interrupted = ref false + +let is_protected = ref false + +let break signum = + if !is_protected + then interrupted := true + else raise Sys.Break + +let _ = + match Sys.os_type with + "Win32" -> () + | _ -> + Sys.set_signal Sys.sigint (Sys.Signal_handle break); + Sys.set_signal Sys.sigpipe (Sys.Signal_handle (fun _ -> raise End_of_file)) + +let protect f = + if !is_protected then + f () + else begin + is_protected := true; + if not !interrupted then + f (); + is_protected := false; + if !interrupted then begin interrupted := false; raise Sys.Break end + end + +let unprotect f = + if not !is_protected then + f () + else begin + is_protected := false; + if !interrupted then begin interrupted := false; raise Sys.Break end; + f (); + is_protected := true + end diff --git a/debugger/exec.mli b/debugger/exec.mli new file mode 100644 index 0000000..5c0c61d --- /dev/null +++ b/debugger/exec.mli @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: exec.mli,v 1.4 1999-11-17 18:57:24 xleroy Exp $ *) + +(* Handling of keyboard interrupts *) + +val protect : (unit -> unit) -> unit +val unprotect : (unit -> unit) -> unit diff --git a/debugger/frames.ml b/debugger/frames.ml new file mode 100644 index 0000000..df3d6bc --- /dev/null +++ b/debugger/frames.ml @@ -0,0 +1,129 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: frames.ml,v 1.10 2005-08-25 15:35:16 doligez Exp $ *) + +(***************************** Frames **********************************) + +open Instruct +open Primitives +open Debugcom +open Checkpoints +open Events +open Symbols + +(* Current frame number *) +let current_frame = ref 0 + +(* Event at selected position *) +let selected_event = ref (None : debug_event option) + +(* Selected position in source. *) +(* Raise `Not_found' if not on an event. *) +let selected_point () = + match !selected_event with + None -> + raise Not_found + | Some ev -> + (ev.ev_module, (Events.get_pos ev).Lexing.pos_cnum) + +let selected_event_is_before () = + match !selected_event with + None -> + raise Not_found + | Some {ev_kind = Event_before} -> + true + | _ -> + false + +(* Move up `frame_count' frames, assuming current frame pointer + corresponds to event `event'. Return event of final frame. *) + +let rec move_up frame_count event = + if frame_count <= 0 then event else begin + let (sp, pc) = up_frame event.ev_stacksize in + if sp < 0 then raise Not_found; + move_up (frame_count - 1) (any_event_at_pc pc) + end + +(* Select a frame. *) +(* Raise `Not_found' if no such frame. *) +(* --- Assume the current events have already been updated. *) +let select_frame frame_number = + if frame_number < 0 then raise Not_found; + let (initial_sp, _) = get_frame() in + try + match !current_event with + None -> + raise Not_found + | Some curr_event -> + match !selected_event with + Some sel_event when frame_number >= !current_frame -> + selected_event := + Some(move_up (frame_number - !current_frame) sel_event); + current_frame := frame_number + | _ -> + set_initial_frame(); + selected_event := Some(move_up frame_number curr_event); + current_frame := frame_number + with Not_found -> + set_frame initial_sp; + raise Not_found + +(* Select a frame. *) +(* Same as `select_frame' but raise no exception if the frame is not found. *) +(* --- Assume the currents events have already been updated. *) +let try_select_frame frame_number = + try + select_frame frame_number + with + Not_found -> + () + +(* Return to default frame (frame 0). *) +let reset_frame () = + set_initial_frame(); + selected_event := !current_event; + current_frame := 0 + +(* Perform a stack backtrace. + Call the given function with the events for each stack frame, + or None if we've encountered a stack frame with no debugging info + attached. Stop when the function returns false, or frame with no + debugging info reached, or top of stack reached. *) + +let do_backtrace action = + match !current_event with + None -> Misc.fatal_error "Frames.do_backtrace" + | Some curr_ev -> + let (initial_sp, _) = get_frame() in + set_initial_frame(); + let event = ref curr_ev in + begin try + while action (Some !event) do + let (sp, pc) = up_frame !event.ev_stacksize in + if sp < 0 then raise Exit; + event := any_event_at_pc pc + done + with Exit -> () + | Not_found -> ignore (action None) + end; + set_frame initial_sp + +(* Return the number of frames in the stack *) + +let stack_depth () = + let num_frames = ref 0 in + do_backtrace (function Some ev -> incr num_frames; true + | None -> num_frames := -1; false); + !num_frames diff --git a/debugger/frames.mli b/debugger/frames.mli new file mode 100644 index 0000000..dff1a6e --- /dev/null +++ b/debugger/frames.mli @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: frames.mli,v 1.3 1999-11-17 18:57:24 xleroy Exp $ *) + +(****************************** Frames *********************************) + +open Instruct +open Primitives + +(* Current frame number *) +val current_frame : int ref + +(* Event at selected position. *) +val selected_event : debug_event option ref + +(* Selected position in source. *) +(* Raise `Not_found' if not on an event. *) +val selected_point : unit -> string * int + +val selected_event_is_before : unit -> bool + +(* Select a frame. *) +(* Raise `Not_found' if no such frame. *) +(* --- Assume the currents events have already been updated. *) +val select_frame : int -> unit + +(* Select a frame. *) +(* Same as `select_frame' but raise no exception if the frame is not found. *) +(* --- Assume the currents events have already been updated. *) +val try_select_frame : int -> unit + +(* Return to default frame (frame 0). *) +val reset_frame : unit -> unit + +(* Perform a stack backtrace. + Call the given function with the events for each stack frame, + or None if we've encountered a stack frame with no debugging info + attached. Stop when the function returns false, or frame with no + debugging info reached, or top of stack reached. *) +val do_backtrace : (debug_event option -> bool) -> unit + +(* Return the number of frames in the stack, or (-1) if it can't be + determined because some frames have no debugging info. *) +val stack_depth : unit -> int diff --git a/debugger/history.ml b/debugger/history.ml new file mode 100644 index 0000000..3716422 --- /dev/null +++ b/debugger/history.ml @@ -0,0 +1,44 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: history.ml,v 1.5 2002-10-29 17:53:24 doligez Exp $ *) + +open Int64ops +open Checkpoints +open Misc +open Primitives +open Debugger_config + +let history = ref ([] : int64 list) + +let empty_history () = + history := [] + +let add_current_time () = + let time = current_time () in + if !history = [] then + history := [time] + else if time <> List.hd !history then + history := list_truncate !history_size (time::!history) + +let previous_time_1 () = + match !history with + _::((time::_) as hist) -> + history := hist; time + | _ -> + prerr_endline "No more information."; raise Toplevel + +let rec previous_time n = + if n = _1 + then previous_time_1() + else begin ignore(previous_time_1()); previous_time(pre64 n) end diff --git a/debugger/history.mli b/debugger/history.mli new file mode 100644 index 0000000..07e0bb0 --- /dev/null +++ b/debugger/history.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: history.mli,v 1.4 2002-10-29 17:53:24 doligez Exp $ *) + +val empty_history : unit -> unit + +val add_current_time : unit -> unit + +val previous_time : int64 -> int64 diff --git a/debugger/input_handling.ml b/debugger/input_handling.ml new file mode 100644 index 0000000..497e69c --- /dev/null +++ b/debugger/input_handling.ml @@ -0,0 +1,115 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: input_handling.ml,v 1.5 2006-12-09 13:49:10 ertai Exp $ *) + +(**************************** Input control ****************************) + +open Unix +open Primitives + +(*** Actives files. ***) + +(* List of the actives files. *) +let active_files = + ref ([] : (file_descr * ((io_channel -> unit) * io_channel)) list) + +(* Add a file to the list of actives files. *) +let add_file file controller = + active_files := (file.io_fd, (controller, file))::!active_files + +(* Remove a file from the list of actives files. *) +let remove_file file = + active_files := assoc_remove !active_files file.io_fd + +(* Change the controller for the given file. *) +let change_controller file controller = + remove_file file; add_file file controller + +(* Return the controller currently attached to the given file. *) +let current_controller file = + fst (List.assoc file.io_fd !active_files) + +(* Execute a function with `controller' attached to `file'. *) +(* ### controller file funct *) +let execute_with_other_controller controller file funct = + let old_controller = current_controller file in + change_controller file controller; + try + let result = funct () in + change_controller file old_controller; + result + with + x -> + change_controller file old_controller; + raise x + +(*** The "Main Loop" ***) + +let continue_main_loop = + ref true + +let exit_main_loop _ = + continue_main_loop := false + +(* Handle active files until `continue_main_loop' is false. *) +let main_loop () = + let old_state = !continue_main_loop in + try + continue_main_loop := true; + while !continue_main_loop do + try + let (input, _, _) = + select (List.map fst !active_files) [] [] (-1.) + in + List.iter + (function fd -> + let (funct, iochan) = (List.assoc fd !active_files) in + funct iochan) + input + with + Unix_error (EINTR, _, _) -> () + done; + continue_main_loop := old_state + with + x -> + continue_main_loop := old_state; + raise x + +(*** Managing user inputs ***) + +(* Are we in interactive mode ? *) +let interactif = ref true + +let current_prompt = ref "" + +(* Where the user input come from. *) +let user_channel = ref std_io + +let read_user_input buffer length = + main_loop (); + input !user_channel.io_in buffer 0 length + +(* Stop reading user input. *) +let stop_user_input () = + remove_file !user_channel + +(* Resume reading user input. *) +let resume_user_input () = + if not (List.mem_assoc !user_channel.io_fd !active_files) then begin + if !interactif then begin + print_string !current_prompt; + flush Pervasives.stdout + end; + add_file !user_channel exit_main_loop + end diff --git a/debugger/input_handling.mli b/debugger/input_handling.mli new file mode 100644 index 0000000..32f3ff7 --- /dev/null +++ b/debugger/input_handling.mli @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: input_handling.mli,v 1.3 2006-12-09 13:49:10 ertai Exp $ *) + +(***************************** Input control ***************************) + +open Primitives + +(*** Actives files. ***) + +(* Add a file to the list of active files. *) +val add_file : io_channel -> (io_channel -> unit) -> unit + +(* Remove a file from the list of actives files. *) +val remove_file : io_channel -> unit + +(* Return the controller currently attached to the given file. *) +val current_controller : io_channel -> (io_channel -> unit) + +(* Execute a function with `controller' attached to `file'. *) +(* ### controller file funct *) +val execute_with_other_controller : + (io_channel -> unit) -> io_channel -> (unit -> 'a) -> 'a + +(*** The "Main Loop" ***) + +(* Call this function for exiting the main loop. *) +val exit_main_loop : 'a -> unit + +(* Handle active files until `continue_main_loop' is false. *) +val main_loop : unit -> unit + +(*** Managing user inputs ***) + +(* Are we in interactive mode ? *) +val interactif : bool ref + +val current_prompt : string ref + +(* Where the user input come from. *) +val user_channel : io_channel ref + +val read_user_input : string -> int -> int + +(* Stop reading user input. *) +val stop_user_input : unit -> unit + +(* Resume reading user input. *) +val resume_user_input : unit -> unit diff --git a/debugger/int64ops.ml b/debugger/int64ops.ml new file mode 100644 index 0000000..428231a --- /dev/null +++ b/debugger/int64ops.ml @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocqencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: int64ops.ml,v 1.1 2002-10-29 17:53:24 doligez Exp $ *) + +(****************** arithmetic operators for Int64 *********************) + +let ( ++ ) = Int64.add;; +let ( -- ) = Int64.sub;; +let suc64 = Int64.succ;; +let pre64 = Int64.pred;; +let _0 = Int64.zero;; +let _1 = Int64.one;; +let _minus1 = Int64.minus_one;; +let ( ~~ ) = Int64.of_string;; +let max_small_int = Int64.of_int max_int;; +let to_int = Int64.to_int;; diff --git a/debugger/int64ops.mli b/debugger/int64ops.mli new file mode 100644 index 0000000..47e483e --- /dev/null +++ b/debugger/int64ops.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocqencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: int64ops.mli,v 1.1 2002-10-29 17:53:24 doligez Exp $ *) + +(****************** arithmetic operators for Int64 *********************) + +val ( ++ ) : int64 -> int64 -> int64;; +val ( -- ) : int64 -> int64 -> int64;; +val suc64 : int64 -> int64;; +val pre64 : int64 -> int64;; +val _0 : int64;; +val _1 : int64;; +val _minus1 : int64;; +val ( ~~ ) : string -> int64;; +val max_small_int : int64;; +val to_int : int64 -> int;; diff --git a/debugger/lexer.mli b/debugger/lexer.mli new file mode 100644 index 0000000..4444c95 --- /dev/null +++ b/debugger/lexer.mli @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mli,v 1.1 2004-06-13 12:46:11 xleroy Exp $ *) + +val line: Lexing.lexbuf -> string +val lexeme: Lexing.lexbuf -> Parser.token +val argument: Lexing.lexbuf -> Parser.token +val line_argument: Lexing.lexbuf -> Parser.token diff --git a/debugger/lexer.mll b/debugger/lexer.mll new file mode 100644 index 0000000..ebb06c7 --- /dev/null +++ b/debugger/lexer.mll @@ -0,0 +1,98 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mll,v 1.8 2003-01-03 15:39:54 doligez Exp $ *) + +{ + +open Primitives +open Parser + +} + +rule line = (* Read a whole line *) + parse + ([ ^ '\n' '\r' ]* as s) ('\n' | '\r' | "\r\n") + { s } + | [ ^ '\n' '\r' ]* + { Lexing.lexeme lexbuf } + | eof + { raise Exit } + +and argument = (* Read a raw argument *) + parse + [ ^ ' ' '\t' ]+ + { ARGUMENT (Lexing.lexeme lexbuf) } + | [' ' '\t']+ + { argument lexbuf } + | eof + { EOL } + | _ + { raise Parsing.Parse_error } + +and line_argument = + parse + _ * + { ARGUMENT (Lexing.lexeme lexbuf) } + | eof + { EOL } + +and lexeme = (* Read a lexeme *) + parse + [' ' '\t'] + + { lexeme lexbuf } + | ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] + (['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' + '\'' '0'-'9' ]) * + { LIDENT(Lexing.lexeme lexbuf) } + | ['A'-'Z' '\192'-'\214' '\216'-'\222' ] + (['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' + '\'' '0'-'9' ]) * + { UIDENT(Lexing.lexeme lexbuf) } + | '"' [^ '"']* "\"" + { let s = Lexing.lexeme lexbuf in + LIDENT(String.sub s 1 (String.length s - 2)) } + | ['0'-'9']+ + | '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']+ + | '0' ['o' 'O'] ['0'-'7']+ + | '0' ['b' 'B'] ['0'-'1']+ + { INTEGER (Int64.of_string (Lexing.lexeme lexbuf)) } + | '*' + { STAR } + | "-" + { MINUS } + | "." + { DOT } + | "#" + { SHARP } + | "@" + { AT } + | "$" + { DOLLAR } + | "!" + { BANG } + | "(" + { LPAREN } + | ")" + { RPAREN } + | "[" + { LBRACKET } + | "]" + { RBRACKET } + | ['!' '?' '~' '=' '<' '>' '|' '&' '$' '@' '^' '+' '-' '*' '/' '%'] + ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] * + { OPERATOR (Lexing.lexeme lexbuf) } + | eof + { EOL } + | _ + { raise Parsing.Parse_error } diff --git a/debugger/loadprinter.ml b/debugger/loadprinter.ml new file mode 100644 index 0000000..c09d947 --- /dev/null +++ b/debugger/loadprinter.ml @@ -0,0 +1,172 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: loadprinter.ml,v 1.19 2004-11-29 02:27:25 garrigue Exp $ *) + +(* Loading and installation of user-defined printer functions *) + +open Misc +open Debugger_config +open Longident +open Path +open Types + +(* Error report *) + +type error = + | Load_failure of Dynlink.error + | Unbound_identifier of Longident.t + | Unavailable_module of string * Longident.t + | Wrong_type of Longident.t + | No_active_printer of Longident.t + +exception Error of error + +(* Symtable has global state, and normally holds the symbol table + for the debuggee. We need to switch it temporarily to the + symbol table for the debugger. *) + +let debugger_symtable = ref (None: Symtable.global_map option) + +let use_debugger_symtable fn arg = + let old_symtable = Symtable.current_state() in + begin match !debugger_symtable with + | None -> + Dynlink.init(); + Dynlink.allow_unsafe_modules true; + debugger_symtable := Some(Symtable.current_state()) + | Some st -> + Symtable.restore_state st + end; + try + let result = fn arg in + debugger_symtable := Some(Symtable.current_state()); + Symtable.restore_state old_symtable; + result + with exn -> + Symtable.restore_state old_symtable; + raise exn + +(* Load a .cmo or .cma file *) + +open Format + +let rec loadfiles ppf name = + try + let filename = find_in_path !Config.load_path name in + use_debugger_symtable Dynlink.loadfile filename; + let d = Filename.dirname name in + if d <> Filename.current_dir_name then begin + if not (List.mem d !Config.load_path) then + Config.load_path := d :: !Config.load_path; + end; + fprintf ppf "File %s loaded@." filename; + true + with + | Dynlink.Error (Dynlink.Unavailable_unit unit) -> + loadfiles ppf (String.uncapitalize unit ^ ".cmo") + && + loadfiles ppf name + | Not_found -> + fprintf ppf "Cannot find file %s@." name; + false + | Dynlink.Error e -> + raise(Error(Load_failure e)) + +let loadfile ppf name = + ignore(loadfiles ppf name) + +(* Return the value referred to by a path (as in toplevel/topdirs) *) +(* Note: evaluation proceeds in the debugger memory space, not in + the debuggee. *) + +let rec eval_path = function + Pident id -> Symtable.get_global_value id + | Pdot(p, s, pos) -> Obj.field (eval_path p) pos + | Papply(p1, p2) -> fatal_error "Loadprinter.eval_path" + +(* Install, remove a printer (as in toplevel/topdirs) *) + +let match_printer_type desc typename = + let (printer_type, _) = + try + Env.lookup_type (Ldot(Lident "Topdirs", typename)) Env.empty + with Not_found -> + raise (Error(Unbound_identifier(Ldot(Lident "Topdirs", typename)))) in + Ctype.init_def(Ident.current_time()); + Ctype.begin_def(); + let ty_arg = Ctype.newvar() in + Ctype.unify Env.empty + (Ctype.newconstr printer_type [ty_arg]) + (Ctype.instance desc.val_type); + Ctype.end_def(); + Ctype.generalize ty_arg; + ty_arg + +let find_printer_type lid = + try + let (path, desc) = Env.lookup_value lid Env.empty in + let (ty_arg, is_old_style) = + try + (match_printer_type desc "printer_type_new", false) + with Ctype.Unify _ -> + (match_printer_type desc "printer_type_old", true) in + (ty_arg, path, is_old_style) + with + | Not_found -> raise(Error(Unbound_identifier lid)) + | Ctype.Unify _ -> raise(Error(Wrong_type lid)) + +let install_printer ppf lid = + let (ty_arg, path, is_old_style) = find_printer_type lid in + let v = + try + use_debugger_symtable eval_path path + with Symtable.Error(Symtable.Undefined_global s) -> + raise(Error(Unavailable_module(s, lid))) in + let print_function = + if is_old_style then + (fun formatter repr -> Obj.obj v (Obj.obj repr)) + else + (fun formatter repr -> Obj.obj v formatter (Obj.obj repr)) in + Printval.install_printer path ty_arg ppf print_function + +let remove_printer lid = + let (ty_arg, path, is_old_style) = find_printer_type lid in + try + Printval.remove_printer path + with Not_found -> + raise(Error(No_active_printer lid)) + +(* Error report *) + +open Format + +let report_error ppf = function + | Load_failure e -> + fprintf ppf "@[Error during code loading: %s@]@." + (Dynlink.error_message e) + | Unbound_identifier lid -> + fprintf ppf "@[Unbound identifier %a@]@." + Printtyp.longident lid + | Unavailable_module(md, lid) -> + fprintf ppf + "@[The debugger does not contain the code for@ %a.@ \ + Please load an implementation of %s first.@]@." + Printtyp.longident lid md + | Wrong_type lid -> + fprintf ppf "@[%a has the wrong type for a printing function.@]@." + Printtyp.longident lid + | No_active_printer lid -> + fprintf ppf "@[%a is not currently active as a printing function.@]@." + Printtyp.longident lid + + diff --git a/debugger/loadprinter.mli b/debugger/loadprinter.mli new file mode 100644 index 0000000..6bf3064 --- /dev/null +++ b/debugger/loadprinter.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: loadprinter.mli,v 1.4 2000-03-07 18:22:15 weis Exp $ *) + +(* Loading and installation of user-defined printer functions *) + +open Format + +val loadfile : formatter -> string -> unit +val install_printer : formatter -> Longident.t -> unit +val remove_printer : Longident.t -> unit + +(* Error report *) + +type error = + | Load_failure of Dynlink.error + | Unbound_identifier of Longident.t + | Unavailable_module of string * Longident.t + | Wrong_type of Longident.t + | No_active_printer of Longident.t + +exception Error of error + +val report_error: formatter -> error -> unit diff --git a/debugger/main.ml b/debugger/main.ml new file mode 100644 index 0000000..7932ebe --- /dev/null +++ b/debugger/main.ml @@ -0,0 +1,189 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.ml,v 1.21 2008-07-29 08:31:41 xleroy Exp $ *) + +open Primitives +open Misc +open Input_handling +open Question +open Command_line +open Debugger_config +open Checkpoints +open Time_travel +open Parameters +open Program_management +open Frames +open Show_information +open Format + +let line_buffer = Lexing.from_function read_user_input + +let rec loop ppf = + line_loop ppf line_buffer; + if !loaded && (not (yes_or_no "The program is running. Quit anyway")) then + loop ppf + +let current_duration = ref (-1L) + +let rec protect ppf restart loop = + try + loop ppf + with + | End_of_file -> + protect ppf restart (function ppf -> + forget_process + !current_checkpoint.c_fd + !current_checkpoint.c_pid; + pp_print_flush ppf (); + stop_user_input (); + loop ppf) + | Toplevel -> + protect ppf restart (function ppf -> + pp_print_flush ppf (); + stop_user_input (); + loop ppf) + | Sys.Break -> + protect ppf restart (function ppf -> + fprintf ppf "Interrupted.@."; + Exec.protect (function () -> + stop_user_input (); + if !loaded then begin + try_select_frame 0; + show_current_event ppf; + end); + loop ppf) + | Current_checkpoint_lost -> + protect ppf restart (function ppf -> + fprintf ppf "Trying to recover...@."; + stop_user_input (); + recover (); + try_select_frame 0; + show_current_event ppf; + loop ppf) + | Current_checkpoint_lost_start_at (time, init_duration) -> + protect ppf restart (function ppf -> + let b = + if !current_duration = -1L then begin + let msg = sprintf "Restart from time %Ld and try to get closer of the problem" time in + stop_user_input (); + if yes_or_no msg then + (current_duration := init_duration; true) + else + false + end + else + true in + if b then + begin + go_to time; + current_duration := Int64.div !current_duration 10L; + if !current_duration > 0L then + while true do + step !current_duration + done + else begin + current_duration := -1L; + stop_user_input (); + show_current_event ppf; + restart ppf; + end + end + else + begin + recover (); + show_current_event ppf; + restart ppf + end) + | x -> + kill_program (); + raise x + +let toplevel_loop () = protect Format.std_formatter loop loop + +(* Parsing of command-line arguments *) + +exception Found_program_name + +let anonymous s = + program_name := Unix_tools.make_absolute s; raise Found_program_name +let add_include d = + default_load_path := + Misc.expand_directory Config.standard_library d :: !default_load_path +let set_socket s = + socket_name := s +let set_checkpoints n = + checkpoint_max_count := n +let set_directory dir = + Sys.chdir dir +let print_version () = + printf "The Objective Caml debugger, version %s@." Sys.ocaml_version; + exit 0; +;; + +let speclist = [ + "-c", Arg.Int set_checkpoints, + " Set max number of checkpoints kept"; + "-cd", Arg.String set_directory, + " Change working directory"; + "-emacs", Arg.Set emacs, + "For running the debugger under emacs"; + "-I", Arg.String add_include, + " Add to the list of include directories"; + "-s", Arg.String set_socket, + " Set the name of the communication socket"; + "-version", Arg.Unit print_version, + " Print version and exit"; + ] + +let main () = + try + socket_name := + (match Sys.os_type with + "Win32" -> + (Unix.string_of_inet_addr Unix.inet_addr_loopback)^ + ":"^ + (string_of_int (10000 + ((Unix.getpid ()) mod 10000))) + | _ -> Filename.concat Filename.temp_dir_name + ("camldebug" ^ (string_of_int (Unix.getpid ()))) + ); + begin try + Arg.parse speclist anonymous ""; + Arg.usage speclist + "No program name specified\n\ + Usage: ocamldebug [options] [arguments]\n\ + Options are:"; + exit 2 + with Found_program_name -> + for j = !Arg.current + 1 to Array.length Sys.argv - 1 do + arguments := !arguments ^ " " ^ (Filename.quote Sys.argv.(j)) + done + end; + current_prompt := debugger_prompt; + printf "\tObjective Caml Debugger version %s@.@." Config.version; + Config.load_path := !default_load_path; + Clflags.recursive_types := true; (* Allow recursive types. *) + toplevel_loop (); (* Toplevel. *) + kill_program (); + exit 0 + with + Toplevel -> + exit 2 + | Env.Error e -> + eprintf "Debugger [version %s] environment error:@ @[@;" Config.version; + Env.report_error err_formatter e; + eprintf "@]@."; + exit 2 + +let _ = + Printexc.catch (Unix.handle_unix_error main) () diff --git a/debugger/parameters.ml b/debugger/parameters.ml new file mode 100644 index 0000000..50e183b --- /dev/null +++ b/debugger/parameters.ml @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parameters.ml,v 1.3 2002-02-14 15:17:10 doligez Exp $ *) + +(* Miscellaneous parameters *) + +open Primitives +open Config +open Misc + +let program_loaded = ref false +let program_name = ref "" +let socket_name = ref "" +let arguments = ref "" + +let default_load_path = + ref [ Filename.current_dir_name; Config.standard_library ] + +let add_path dir = + load_path := dir :: except dir !load_path; + Envaux.reset_cache() + +(* Used by emacs ? *) +let emacs = ref false diff --git a/debugger/parameters.mli b/debugger/parameters.mli new file mode 100644 index 0000000..4cf2f78 --- /dev/null +++ b/debugger/parameters.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parameters.mli,v 1.2 1999-11-17 18:57:26 xleroy Exp $ *) + +(* Miscellaneous parameters *) + +val program_name : string ref +val socket_name : string ref +val arguments : string ref +val default_load_path : string list ref + +val add_path : string -> unit + +(* Used by emacs ? *) +val emacs : bool ref diff --git a/debugger/parser.mly b/debugger/parser.mly new file mode 100644 index 0000000..773dd85 --- /dev/null +++ b/debugger/parser.mly @@ -0,0 +1,239 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jerome Vouillon, projet Cristal, INRIA Rocquencourt */ +/* Objective Caml port by John Malecki and Xavier Leroy */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: parser.mly,v 1.7 2002-10-29 17:53:24 doligez Exp $ */ + +%{ + +open Int64ops +open Primitives +open Input_handling +open Longident +open Parser_aux + +%} + +%token ARGUMENT +%token LIDENT +%token UIDENT +%token OPERATOR +%token INTEGER +%token STAR /* * */ +%token MINUS /* - */ +%token DOT /* . */ +%token SHARP /* # */ +%token AT /* @ */ +%token DOLLAR /* $ */ +%token BANG /* ! */ +%token LPAREN /* ( */ +%token RPAREN /* ) */ +%token LBRACKET /* [ */ +%token RBRACKET /* ] */ +%token EOL + +%right DOT +%right BANG + +%start argument_list_eol +%type argument_list_eol + +%start argument_eol +%type argument_eol + +%start integer_list_eol +%type integer_list_eol + +%start integer_eol +%type integer_eol + +%start int64_eol +%type int64_eol + +%start integer +%type integer + +%start opt_integer_eol +%type opt_integer_eol + +%start opt_signed_integer_eol +%type opt_signed_integer_eol + +%start opt_signed_int64_eol +%type opt_signed_int64_eol + +%start identifier +%type identifier + +%start identifier_eol +%type identifier_eol + +%start identifier_or_eol +%type identifier_or_eol + +%start opt_identifier +%type opt_identifier + +%start opt_identifier_eol +%type opt_identifier_eol + +%start expression_list_eol +%type expression_list_eol + +%start break_argument_eol +%type break_argument_eol + +%start list_arguments_eol +%type list_arguments_eol + +%start end_of_line +%type end_of_line + +%start longident_eol +%type longident_eol + +%% + +/* Raw arguments */ + +argument_list_eol : + ARGUMENT argument_list_eol + { $1::$2 } + | end_of_line + { [] }; + +argument_eol : + ARGUMENT end_of_line + { $1 }; + +/* Integer */ + +integer_list_eol : + INTEGER integer_list_eol + { (to_int $1) :: $2 } + | end_of_line + { [] }; + +integer_eol : + INTEGER end_of_line + { to_int $1 }; + +int64_eol : + INTEGER end_of_line + { $1 }; + +integer : + INTEGER + { to_int $1 }; + +opt_integer_eol : + INTEGER end_of_line + { Some (to_int $1) } + | end_of_line + { None }; + +opt_int64_eol : + INTEGER end_of_line + { Some $1 } + | end_of_line + { None }; + +opt_signed_integer_eol : + MINUS integer_eol + { Some (- $2) } + | opt_integer_eol + { $1 }; + +opt_signed_int64_eol : + MINUS int64_eol + { Some (Int64.neg $2) } + | opt_int64_eol + { $1 }; + +/* Identifiers and long identifiers */ + +longident : + LIDENT { Lident $1 } + | module_path DOT LIDENT { Ldot($1, $3) } + | OPERATOR { Lident $1 } +; + +module_path : + UIDENT { Lident $1 } + | module_path DOT UIDENT { Ldot($1, $3) } +; + +longident_eol : + longident end_of_line { $1 }; + +identifier : + LIDENT { $1 } + | UIDENT { $1 }; + +identifier_eol : + identifier end_of_line { $1 }; + +identifier_or_eol : + identifier { Some $1 } + | end_of_line { None }; + +opt_identifier : + identifier { Some $1 } + | { None }; + +opt_identifier_eol : + opt_identifier end_of_line { $1 }; + +/* Expressions */ + +expression: + longident { E_ident $1 } + | STAR { E_result } + | DOLLAR INTEGER { E_name (to_int $2) } + | expression DOT INTEGER { E_item($1, (to_int $3)) } + | expression DOT LBRACKET INTEGER RBRACKET { E_item($1, (to_int $4)) } + | expression DOT LPAREN INTEGER RPAREN { E_item($1, (to_int $4)) } + | expression DOT LIDENT { E_field($1, $3) } + | BANG expression { E_field($2, "contents") } + | LPAREN expression RPAREN { $2 } +; + +/* Lists of expressions */ + +expression_list_eol : + expression expression_list_eol { $1::$2 } + | end_of_line { [] } +; + +/* Arguments for breakpoint */ + +break_argument_eol : + end_of_line { BA_none } + | integer_eol { BA_pc $1 } + | expression end_of_line { BA_function $1 } + | AT opt_identifier INTEGER opt_integer_eol { BA_pos1 ($2, (to_int $3), $4)} + | AT opt_identifier SHARP integer_eol { BA_pos2 ($2, $4) } +; + +/* Arguments for list */ + +list_arguments_eol : + opt_identifier integer opt_integer_eol + { ($1, Some $2, $3) } + | opt_identifier_eol + { ($1, None, None) }; + +/* End of line */ + +end_of_line : + EOL { stop_user_input () } +; diff --git a/debugger/parser_aux.mli b/debugger/parser_aux.mli new file mode 100644 index 0000000..1b4b8c2 --- /dev/null +++ b/debugger/parser_aux.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parser_aux.mli,v 1.4 1999-11-17 18:57:26 xleroy Exp $ *) + +(*open Globals*) + +open Primitives + +type expression = + E_ident of Longident.t (* x or Mod.x *) + | E_name of int (* $xxx *) + | E_item of expression * int (* x.1 x.[2] x.(3) *) + | E_field of expression * string (* x.lbl !x *) + | E_result + +type break_arg = + BA_none (* break *) + | BA_pc of int (* break PC *) + | BA_function of expression (* break FUNCTION *) + | BA_pos1 of string option * int * int option + (* break @ [MODULE] LINE [POS] *) + | BA_pos2 of string option * int (* break @ [MODULE] # OFFSET *) + diff --git a/debugger/pattern_matching.ml b/debugger/pattern_matching.ml new file mode 100644 index 0000000..74ce8ed --- /dev/null +++ b/debugger/pattern_matching.ml @@ -0,0 +1,251 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pattern_matching.ml,v 1.4 2000-12-28 13:03:41 weis Exp $ *) + +(************************ Simple pattern matching **********************) + +open Debugger_config +(*open Primitives*) +open Misc +(*open Const*) +(*open Globals*) +(*open Builtins*) +open Typedtree +(*open Modules*) +(*open Symtable*) +(*open Value*) +open Parser_aux + +(* +let rec find_constr tag = function + [] -> + fatal_error "find_constr: unknown constructor for this type" + | constr::rest -> + match constr.info.cs_tag with + ConstrRegular(t, _) -> + if t == tag then constr else find_constr tag rest + | ConstrExtensible _ -> + fatal_error "find_constr: extensible" + +let find_exception tag = + let (qualid, stamp) = get_exn_of_num tag in + let rec select_exn = function + [] -> + raise Not_found + | constr :: rest -> + match constr.info.cs_tag with + ConstrExtensible(_,st) -> + if st == stamp then constr else select_exn rest + | ConstrRegular(_,_) -> + fatal_error "find_exception: regular" in + select_exn(hashtbl__find_all (find_module qualid.qual).mod_constrs qualid.id) +*) + +let error_matching () = + prerr_endline "Pattern matching failed"; + raise Toplevel + +(* +let same_name {qualid = name1} = + function + GRname name2 -> + (name2 = "") || (name1.id = name2) + | GRmodname name2 -> + name1 = name2 + +let check_same_constr constr constr2 = + try + if not (same_name constr constr2) then + error_matching () + with + Desc_not_found -> + prerr_endline "Undefined constructor."; + raise Toplevel +*) + +let rec pattern_matching pattern obj ty = + match pattern with + P_dummy -> + [] + | P_variable var -> + [var, obj, ty] + | _ -> + match (Ctype.repr ty).desc with + Tvar | Tarrow _ -> + error_matching () + | Ttuple(ty_list) -> + (match pattern with + P_tuple pattern_list -> + pattern_matching_list pattern_list obj ty_list + | P_nth (n, patt) -> + if n >= List.length ty_list then + (prerr_endline "Out of range."; raise Toplevel); + pattern_matching patt (Debugcom.get_field obj n) (List.nth ty_list n) + | _ -> + error_matching ()) + | Tconstr(cstr, [ty_arg],_) when same_type_constr cstr constr_type_list -> + (match pattern with + P_list pattern_list -> + let (last, list) = + it_list + (fun (current, list) pattern -> + if value_tag current = 0 then error_matching (); + (Debugcom.get_field current 1, + (pattern, Debugcom.get_field current 0)::list)) + (obj, []) + pattern_list + in + if value_tag last <> 0 then error_matching (); + flat_map + (function (x, y) -> pattern_matching x y ty_arg) + (rev list) + | P_nth (n, patt) -> + let rec find k current = + if value_tag current = 0 then + (prerr_endline "Out of range."; raise Toplevel); + if k = 0 then + pattern_matching patt (Debugcom.get_field current 0) ty_arg + else + find (k - 1) (Debugcom.get_field current 1) + in + find n obj + | P_concat (pattern1, pattern2) -> + if value_tag obj == 0 then error_matching (); + (pattern_matching pattern1 (Debugcom.get_field obj 0) ty_arg) + @ (pattern_matching pattern2 (Debugcom.get_field obj 1) ty) + | _ -> + error_matching ()) + | Tconstr(cstr, [ty_arg]) when same_type_constr cstr constr_type_vect -> + (match pattern with + P_nth (n, patt) -> + if n >= value_size obj then + (prerr_endline "Out of range."; raise Toplevel); + pattern_matching patt (Debugcom.get_field obj n) ty_arg + | _ -> + error_matching ()) + | Tconstr(cstr, ty_list) -> + (match cstr.info.ty_abbr with + Tabbrev(params, body) -> + pattern_matching pattern obj (expand_abbrev params body ty_list) + | _ -> + match_concrete_type pattern obj cstr ty ty_list) + +and match_concrete_type pattern obj cstr ty ty_list = + let typ_descr = + type_descr_of_type_constr cstr in + match typ_descr.info.ty_desc with + Abstract_type -> + error_matching () + | Variant_type constr_list -> + let tag = value_tag obj in + (try + let constr = + if same_type_constr cstr constr_type_exn then + find_exception tag + else + find_constr tag constr_list + in + let (ty_res, ty_arg) = + type_pair_instance (constr.info.cs_res, constr.info.cs_arg) + in + filter (ty_res, ty); + match constr.info.cs_kind with + Constr_constant -> + error_matching () + | Constr_regular -> + (match pattern with + P_constr (constr2, patt) -> + check_same_constr constr constr2; + pattern_matching patt (Debugcom.get_field obj 0) ty_arg + | _ -> + error_matching ()) + | Constr_superfluous n -> + (match pattern with + P_constr (constr2, patt) -> + check_same_constr constr constr2; + (match patt with + P_tuple pattern_list -> + pattern_matching_list + pattern_list + obj + (filter_product n ty_arg) + | P_nth (n2, patt) -> + let ty_list = filter_product n ty_arg in + if n2 >= n then + (prerr_endline "Out of range."; + raise Toplevel); + pattern_matching + patt + (Debugcom.get_field obj n2) + (List.nth ty_list n2) + | P_variable var -> + [var, + obj, + {typ_desc = Tproduct (filter_product n ty_arg); + typ_level = generic}] + | P_dummy -> + [] + | _ -> + error_matching ()) + | _ -> + error_matching ()) + with + Not_found -> + error_matching () + | Unify -> + fatal_error "pattern_matching: types should match") + | Record_type label_list -> + let match_field (label, patt) = + let lbl = + try + primitives__find + (function l -> same_name l label) + label_list + with Not_found -> + prerr_endline "Label not found."; + raise Toplevel + in + let (ty_res, ty_arg) = + type_pair_instance (lbl.info.lbl_res, lbl.info.lbl_arg) + in + (try + filter (ty_res, ty) + with Unify -> + fatal_error "pattern_matching: types should match"); + pattern_matching patt (Debugcom.get_field obj lbl.info.lbl_pos) ty_arg + in + (match pattern with + P_record pattern_label_list -> + flat_map match_field pattern_label_list + | _ -> + error_matching ()) + | Abbrev_type(_,_) -> + fatal_error "pattern_matching: abbrev type" + +and pattern_matching_list pattern_list obj ty_list = + let val_list = + try + pair__combine (pattern_list, ty_list) + with + Invalid_argument _ -> error_matching () + in + flat_map + (function (x, y, z) -> pattern_matching x y z) + (rev + (snd + (it_list + (fun (num, list) (pattern, typ) -> + (num + 1, (pattern, Debugcom.get_field obj num, typ)::list)) + (0, []) + val_list))) diff --git a/debugger/pattern_matching.mli b/debugger/pattern_matching.mli new file mode 100644 index 0000000..f368148 --- /dev/null +++ b/debugger/pattern_matching.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pattern_matching.mli,v 1.2 1999-11-17 18:57:26 xleroy Exp $ *) + +(************************ Simple pattern matching **********************) + +open Parser_aux + +val pattern_matching : + pattern -> Debugcom.remote_value -> Typedtree.type_expr -> (string * Debugcom.remote_value * Typedtree.type_expr) list;; diff --git a/debugger/pos.ml b/debugger/pos.ml new file mode 100644 index 0000000..f480cf3 --- /dev/null +++ b/debugger/pos.ml @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2003 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pos.ml,v 1.3 2006-12-09 13:49:10 ertai Exp $ *) + +open Instruct;; +open Lexing;; +open Location;; +open Primitives;; +open Source;; + +let get_desc ev = + let loc = ev.ev_loc in + if loc.loc_start.pos_fname <> "" + then Printf.sprintf "file %s, line %d, characters %d-%d" + loc.loc_start.pos_fname loc.loc_start.pos_lnum + (loc.loc_start.pos_cnum - loc.loc_start.pos_bol + 1) + (loc.loc_end.pos_cnum - loc.loc_start.pos_bol + 1) + else begin + let filename = source_of_module ev.ev_loc.loc_start ev.ev_module in + try + let (start, line) = line_of_pos (get_buffer loc.loc_start ev.ev_module) + loc.loc_start.pos_cnum + in + Printf.sprintf "file %s, line %d, characters %d-%d" + filename line (loc.loc_start.pos_cnum - start + 1) + (loc.loc_end.pos_cnum - start + 1) + with Not_found | Out_of_range -> + Printf.sprintf "file %s, characters %d-%d" + filename (loc.loc_start.pos_cnum + 1) + (loc.loc_end.pos_cnum + 1) + end +;; diff --git a/debugger/pos.mli b/debugger/pos.mli new file mode 100644 index 0000000..951950c --- /dev/null +++ b/debugger/pos.mli @@ -0,0 +1,15 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2003 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pos.mli,v 1.1 2003-11-21 16:10:57 doligez Exp $ *) + +val get_desc : Instruct.debug_event -> string;; diff --git a/debugger/primitives.ml b/debugger/primitives.ml new file mode 100644 index 0000000..f218c2e --- /dev/null +++ b/debugger/primitives.ml @@ -0,0 +1,194 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: primitives.ml,v 1.6 2002-10-29 17:53:24 doligez Exp $ *) + +(*********************** Basic functions and types *********************) + +(*** Miscellaneous ***) +exception Out_of_range + +let nothing _ = () + +(*** Operations on lists. ***) + +(* Remove an element from a list *) +let except e l = + let rec except_e = function + [] -> [] + | elem::l -> if e = elem then l else elem::except_e l + in except_e l + +(* Position of an element in a list. Head of list has position 0. *) +let index a l = + let rec index_rec i = function + [] -> raise Not_found + | b::l -> if a = b then i else index_rec (i + 1) l + in index_rec 0 l + +(* Remove an element from an association list *) +let assoc_remove lst elem = + let rec remove = + function + [] -> [] + | ((a, _) as c::t) -> + if a = elem then t + else c::(remove t) + in remove lst + +(* Nth element of a list. *) +let rec list_nth p0 p1 = + match (p0,p1) with + ([], _) -> + invalid_arg "list_nth" + | ((a::_), 0) -> + a + | ((_::l), n) -> + list_nth l (n - 1) + +(* Return the `n' first elements of `l' *) +(* ### n l -> l' *) +let rec list_truncate = + fun + p0 p1 -> match (p0,p1) with (0, _) -> [] + | (_, []) -> [] + | (n, (a::l)) -> a::(list_truncate (n - 1) l) + +(* Separe the `n' first elements of `l' and the others *) +(* ### n list -> (first, last) *) +let rec list_truncate2 = + fun + p0 p1 -> match (p0,p1) with (0, l) -> + ([], l) + | (_, []) -> + ([], []) + | (n, (a::l)) -> + let (first, last) = (list_truncate2 (n - 1) l) in + (a::first, last) + +(* Replace x by y in list l *) +(* ### x y l -> l' *) +let list_replace x y = + let rec repl = + function + [] -> [] + | a::l -> + if a == x then y::l + else a::(repl l) + in repl + +(* Filter `list' according to `predicate'. *) +(* ### predicate list -> list' *) +let filter p = + let rec filter2 = + function + [] -> + [] + | a::l -> + if p a then + a::(filter2 l) + else + filter2 l + in filter2 + +(* Find the first element `element' of `list' *) +(* so that `predicate element' holds. *) +(* ### predicate list -> element *) +let find p = + let rec find2 = + function + [] -> + raise Not_found + | a::l -> + if p a then a + else find2 l + in find2 + +(*** Operations on strings. ***) + +(* Return the position of the first occurence of char `c' in string `s' *) +(* Raise `Not_found' if `s' does not contain `c'. *) +(* ### c s -> pos *) +let string_pos s c = + let i = ref 0 and l = String.length s in + while !i < l && String.get s !i != c do i := !i + 1 done; + if !i = l then raise Not_found; + !i + +(* Remove blanks (spaces and tabs) at beginning and end of a string. *) +let is_space = function + | ' ' | '\t' -> true | _ -> false + +let string_trim s = + let l = String.length s and i = ref 0 in + while + !i < l && is_space (String.get s !i) + do + incr i + done; + let j = ref (l - 1) in + while + !j >= !i && is_space (String.get s !j) + do + decr j + done; + String.sub s !i (!j - !i + 1) + +(* isprefix s1 s2 returns true if s1 is a prefix of s2. *) + +let isprefix s1 s2 = + let l1 = String.length s1 and l2 = String.length s2 in + (l1 = l2 && s1 = s2) || (l1 < l2 && s1 = String.sub s2 0 l1) + +(* Split a string at the given delimiter char *) + +let split_string sep str = + let rec split i j = + if j >= String.length str then + if i >= j then [] else [String.sub str i (j-i)] + else if str.[j] = sep then + if i >= j + then skip_sep (j+1) + else String.sub str i (j-i) :: skip_sep (j+1) + else + split i (j+1) + and skip_sep j = + if j < String.length str && str.[j] = sep + then skip_sep (j+1) + else split j j + in split 0 0 + +(*** I/O channels ***) + +type io_channel = { + io_in : in_channel; + io_out : out_channel; + io_fd : Unix.file_descr + } + +let io_channel_of_descr fd = { + io_in = Unix.in_channel_of_descr fd; + io_out = Unix.out_channel_of_descr fd; + io_fd = fd + } + +let close_io io_channel = + close_out_noerr io_channel.io_out; + close_in_noerr io_channel.io_in; +;; + +let std_io = { + io_in = stdin; + io_out = stdout; + io_fd = Unix.stdin + } diff --git a/debugger/primitives.mli b/debugger/primitives.mli new file mode 100644 index 0000000..2e1e6e5 --- /dev/null +++ b/debugger/primitives.mli @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: primitives.mli,v 1.2 1999-11-17 18:57:26 xleroy Exp $ *) + +(********************* Basic functions and types ***********************) + +(*** Miscellaneous ***) +val nothing : 'a -> unit + +(*** Types and exceptions. ***) +exception Out_of_range + +(*** Operations on lists. ***) + +(* Remove an element from a list *) +val except : 'a -> 'a list -> 'a list + +(* Position of an element in a list. Head of list has position 0. *) +val index : 'a -> 'a list -> int + +(* Remove on element from an association list. *) +val assoc_remove : ('a * 'b) list -> 'a -> ('a * 'b) list + +(* Nth element of a list. *) +val list_nth : 'a list -> int -> 'a + +(* Return the `n' first elements of `l'. *) +(* ### n l -> l' *) +val list_truncate : int -> 'a list -> 'a list + +(* Separe the `n' first elements of `l' and the others. *) +(* ### n list -> (first, last) *) +val list_truncate2 : int -> 'a list -> 'a list * 'a list + +(* Replace x by y in list l *) +(* ### x y l -> l' *) +val list_replace : 'a -> 'a -> 'a list -> 'a list + +(* Filter `list' according to `predicate'. *) +(* ### predicate list -> list' *) +val filter : ('a -> bool) -> 'a list -> 'a list + +(* Find the first element `element' of `list' *) +(* so that `predicate element' holds. *) +(* Raise `Not_found' if no such element. *) +(* ### predicate list -> element *) +val find : ('a -> bool) -> 'a list -> 'a + +(*** Operations on strings. ***) + +(* Return the position of the first occurence of char `c' in string `s' *) +(* Raise `Not_found' if `s' does not contain `c'. *) +(* ### c s -> pos *) +val string_pos : string -> char -> int + +(* Remove blanks (spaces and tabs) at beginning and end of a string. *) +val string_trim : string -> string + +(* isprefix s1 s2 returns true if s1 is a prefix of s2. *) +val isprefix : string -> string -> bool + +(* Split a string at the given delimiter char *) +val split_string : char -> string -> string list + +(*** I/O channels ***) + +type io_channel = { + io_in : in_channel; + io_out : out_channel; + io_fd : Unix.file_descr + } + +val io_channel_of_descr : Unix.file_descr -> io_channel +val close_io : io_channel -> unit +val std_io : io_channel diff --git a/debugger/printval.ml b/debugger/printval.ml new file mode 100644 index 0000000..fc914b4 --- /dev/null +++ b/debugger/printval.ml @@ -0,0 +1,111 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printval.ml,v 1.21 2002-02-13 11:09:17 ddr Exp $ *) + +(* To print values *) + +open Misc +open Obj +open Format +open Parser_aux +open Path +open Types + +(* To name printed and ellipsed values *) + +let named_values = + (Hashtbl.create 29 : (int, Debugcom.Remote_value.t * type_expr) Hashtbl.t) +let next_name = ref 1 + +let reset_named_values () = + Hashtbl.clear named_values; + next_name := 1 + +let name_value v ty = + let name = !next_name in + incr next_name; + Hashtbl.add named_values name (v, ty); + name + +let find_named_value name = + Hashtbl.find named_values name + +let check_depth ppf depth obj ty = + if depth <= 0 then begin + let n = name_value obj ty in + Some (Outcometree.Oval_stuff ("$" ^ string_of_int n)) + end else None + +module EvalPath = + struct + type value = Debugcom.Remote_value.t + exception Error + let rec eval_path = function + Pident id -> + begin try + Debugcom.Remote_value.global (Symtable.get_global_position id) + with Symtable.Error _ -> + raise Error + end + | Pdot(root, fieldname, pos) -> + let v = eval_path root in + if not (Debugcom.Remote_value.is_block v) + then raise Error + else Debugcom.Remote_value.field v pos + | Papply(p1, p2) -> + raise Error + let same_value = Debugcom.Remote_value.same + end + +module Printer = Genprintval.Make(Debugcom.Remote_value)(EvalPath) + +let install_printer path ty ppf fn = + Printer.install_printer path ty + (fun ppf remote_val -> + try + fn ppf (Obj.repr (Debugcom.Remote_value.obj remote_val)) + with + Debugcom.Marshalling_error -> + fprintf ppf "") + +let remove_printer = Printer.remove_printer + +let max_printer_depth = ref 20 +let max_printer_steps = ref 300 + +let print_exception ppf obj = + let t = Printer.outval_of_untyped_exception obj in + !Oprint.out_value ppf t + +let print_value max_depth env obj (ppf : Format.formatter) ty = + let t = + Printer.outval_of_value !max_printer_steps max_depth + (check_depth ppf) env obj ty in + !Oprint.out_value ppf t + +let print_named_value max_depth exp env obj ppf ty = + let print_value_name ppf = function + | E_ident lid -> + Printtyp.longident ppf lid + | E_name n -> + fprintf ppf "$%i" n + | _ -> + let n = name_value obj ty in + fprintf ppf "$%i" n in + Printtyp.reset_and_mark_loops ty; + fprintf ppf "@[<2>%a :@ %a@ =@ %a@]@." + print_value_name exp + Printtyp.type_expr ty + (print_value max_depth env obj) ty + diff --git a/debugger/printval.mli b/debugger/printval.mli new file mode 100644 index 0000000..c0e45c2 --- /dev/null +++ b/debugger/printval.mli @@ -0,0 +1,33 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printval.mli,v 1.10 2001-07-03 11:04:09 xleroy Exp $ *) + +open Format + +val max_printer_depth : int ref +val max_printer_steps : int ref + +val print_exception: formatter -> Debugcom.Remote_value.t -> unit +val print_named_value : + int -> Parser_aux.expression -> Env.t -> + Debugcom.Remote_value.t -> formatter -> Types.type_expr -> + unit + +val reset_named_values : unit -> unit +val find_named_value : int -> Debugcom.Remote_value.t * Types.type_expr + +val install_printer : + Path.t -> Types.type_expr -> formatter -> + (formatter -> Obj.t -> unit) -> unit +val remove_printer : Path.t -> unit diff --git a/debugger/program_loading.ml b/debugger/program_loading.ml new file mode 100644 index 0000000..7d72c2a --- /dev/null +++ b/debugger/program_loading.ml @@ -0,0 +1,147 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: program_loading.ml,v 1.8 2008-07-29 08:31:41 xleroy Exp $ *) + +(* Program loading *) + +open Unix +open Misc +open Debugger_config +open Parameters +open Input_handling + +(*** Debugging. ***) + +let debug_loading = ref false + +(*** Load a program. ***) + +(* Function used for launching the program. *) +let launching_func = ref (function () -> ()) + +let load_program () = + !launching_func (); + main_loop () + +(*** Launching functions. ***) + +(* A generic function for launching the program *) +let generic_exec_unix cmdline = function () -> + if !debug_loading then + prerr_endline "Launching program..."; + let child = + try + fork () + with x -> + Unix_tools.report_error x; + raise Toplevel in + match child with + 0 -> + begin try + match fork () with + 0 -> (* Try to detach the process from the controlling terminal, + so that it does not receive SIGINT on ctrl-C. *) + begin try ignore(setsid()) with Invalid_argument _ -> () end; + execv shell [| shell; "-c"; cmdline() |] + | _ -> exit 0 + with x -> + Unix_tools.report_error x; + exit 1 + end + | _ -> + match wait () with + (_, WEXITED 0) -> () + | _ -> raise Toplevel + +let generic_exec_win cmdline = function () -> + if !debug_loading then + prerr_endline "Launching program..."; + try ignore(create_process "cmd.exe" [| "/C"; cmdline() |] stdin stdout stderr) + with x -> + Unix_tools.report_error x; + raise Toplevel + +let generic_exec = + match Sys.os_type with + "Win32" -> generic_exec_win + | _ -> generic_exec_unix + +(* Execute the program by calling the runtime explicitely *) +let exec_with_runtime = + generic_exec + (function () -> + match Sys.os_type with + "Win32" -> + (* This fould fail on a file name with spaces + but quoting is even worse because Unix.create_process + thinks each command line parameter is a file. + So no good solution so far *) + Printf.sprintf "set CAML_DEBUG_SOCKET=%s && %s %s %s" + !socket_name + runtime_program + !program_name + !arguments + | _ -> + Printf.sprintf "CAML_DEBUG_SOCKET=%s %s %s %s" + !socket_name + (Filename.quote runtime_program) + (Filename.quote !program_name) + !arguments) + +(* Excute the program directly *) +let exec_direct = + generic_exec + (function () -> + match Sys.os_type with + "Win32" -> + (* See the comment above *) + Printf.sprintf "set CAML_DEBUG_SOCKET=%s && %s %s" + !socket_name + !program_name + !arguments + | _ -> + Printf.sprintf "CAML_DEBUG_SOCKET=%s %s %s" + !socket_name + (Filename.quote !program_name) + !arguments) + +(* Ask the user. *) +let exec_manual = + function () -> + print_newline (); + print_string "Waiting for connection..."; + print_string ("(the socket is " ^ !socket_name ^ ")"); + print_newline () + +(*** Selection of the launching function. ***) + +type launching_function = (unit -> unit) + +let loading_modes = + ["direct", exec_direct; + "runtime", exec_with_runtime; + "manual", exec_manual] + +let set_launching_function func = + launching_func := func + +(* Initialization *) + +let _ = + set_launching_function exec_direct + +(*** Connection. ***) + +let connection = ref Primitives.std_io +let connection_opened = ref false diff --git a/debugger/program_loading.mli b/debugger/program_loading.mli new file mode 100644 index 0000000..b1b456d --- /dev/null +++ b/debugger/program_loading.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: program_loading.mli,v 1.3 1999-11-17 18:57:27 xleroy Exp $ *) + +(*** Debugging. ***) + +val debug_loading : bool ref + +(*** Load program ***) + +(* Function used for launching the program. *) +val launching_func : (unit -> unit) ref + +val load_program : unit -> unit + +type launching_function = (unit -> unit) + +val loading_modes : (string * launching_function) list +val set_launching_function : launching_function -> unit + +(** Connection **) +val connection : Primitives.io_channel ref +val connection_opened : bool ref diff --git a/debugger/program_management.ml b/debugger/program_management.ml new file mode 100644 index 0000000..7da0082 --- /dev/null +++ b/debugger/program_management.ml @@ -0,0 +1,159 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: program_management.ml,v 1.13 2008-07-29 08:31:41 xleroy Exp $ *) + +(* Manage the loading of the program *) + +open Int64ops +open Unix +open Unix_tools +open Debugger_config +open Misc +open Instruct +open Primitives +open Parameters +open Input_handling +open Question +open Debugcom +open Program_loading +open Time_travel + +(*** Connection opening and control. ***) + +(* Name of the file if the socket is in the unix domain.*) +let file_name = ref (None : string option) + +(* Default connection handler. *) +let buffer = String.create 1024 +let control_connection pid fd = + if (read fd.io_fd buffer 0 1024) = 0 then + forget_process fd pid + else begin + prerr_string "Garbage data from process "; + prerr_int pid; + prerr_endline "" + end + +(* Accept a connection from another process. *) +let accept_connection continue fd = + let (sock, _) = accept fd.io_fd in + let io_chan = io_channel_of_descr sock in + let pid = input_binary_int io_chan.io_in in + if pid = -1 then begin + let pid' = input_binary_int io_chan.io_in in + new_checkpoint pid' io_chan; + Input_handling.add_file io_chan (control_connection pid'); + continue () + end + else begin + if set_file_descriptor pid io_chan then + Input_handling.add_file io_chan (control_connection pid) + end + +(* Initialize the socket. *) +let open_connection address continue = + try + let (sock_domain, sock_address) = convert_address address in + file_name := + (match sock_address with + ADDR_UNIX file -> + Some file + | _ -> + None); + let sock = socket sock_domain SOCK_STREAM 0 in + (try + bind sock sock_address; + setsockopt sock SO_REUSEADDR true; + listen sock 3; + connection := io_channel_of_descr sock; + Input_handling.add_file !connection (accept_connection continue); + connection_opened := true + with x -> close sock; raise x) + with + Failure _ -> raise Toplevel + | (Unix_error _) as err -> report_error err; raise Toplevel + +(* Close the socket. *) +let close_connection () = + if !connection_opened then begin + connection_opened := false; + Input_handling.remove_file !connection; + close_io !connection; + match !file_name with + Some file -> + unlink file + | None -> + () + end + +(*** Kill program. ***) +let loaded = ref false + +let kill_program () = + Breakpoints.remove_all_breakpoints (); + History.empty_history (); + kill_all_checkpoints (); + loaded := false; + close_connection () + +let ask_kill_program () = + if not !loaded then + true + else + let answer = yes_or_no "A program is being debugged already. Kill it" in + if answer then + kill_program (); + answer + +(*** Program loading and initializations. ***) + +let initialize_loading () = + if !debug_loading then + prerr_endline "Loading debugging informations..."; + begin try access !program_name [F_OK] + with Unix_error _ -> + prerr_endline "Program not found."; + raise Toplevel; + end; + Symbols.read_symbols !program_name; + if !debug_loading then + prerr_endline "Opening a socket..."; + open_connection !socket_name + (function () -> + go_to _0; + Symbols.set_all_events(); + exit_main_loop ()) + +(* Ensure the program is already loaded. *) +let ensure_loaded () = + if not !loaded then begin + print_string "Loading program... "; + flush Pervasives.stdout; + if !program_name = "" then begin + prerr_endline "No program specified."; + raise Toplevel + end; + try + initialize_loading(); + !launching_func (); + if !debug_loading then + prerr_endline "Waiting for connection..."; + main_loop (); + loaded := true; + prerr_endline "done." + with + x -> + kill_program(); + raise x + end diff --git a/debugger/program_management.mli b/debugger/program_management.mli new file mode 100644 index 0000000..1b3e783 --- /dev/null +++ b/debugger/program_management.mli @@ -0,0 +1,27 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: program_management.mli,v 1.2 1999-11-17 18:57:27 xleroy Exp $ *) + +(*** Program loading and initializations. ***) + +val loaded : bool ref +val ensure_loaded : unit -> unit + +(*** Kill program. ***) +val kill_program : unit -> unit + +(* Ask wether to kill the program or not. *) +(* If yes, kill it. *) +(* Return true iff the program has been killed. *) +val ask_kill_program : unit -> bool diff --git a/debugger/question.ml b/debugger/question.ml new file mode 100644 index 0000000..8b2d459 --- /dev/null +++ b/debugger/question.ml @@ -0,0 +1,36 @@ +open Input_handling +open Primitives + +(* Ask user a yes or no question. *) +let yes_or_no message = + if !interactif then + let old_prompt = !current_prompt in + try + current_prompt := message ^ " ? (y or n) "; + let answer = + let rec ask () = + resume_user_input (); + let line = + string_trim (Lexer.line (Lexing.from_function read_user_input)) + in + stop_user_input (); + match (if String.length line > 0 then line.[0] else ' ') with + 'y' -> true + | 'n' -> false + | _ -> + print_string "Please answer y or n."; + print_newline (); + ask () + in + ask () + in + current_prompt := old_prompt; + answer + with + x -> + current_prompt := old_prompt; + stop_user_input (); + raise x + else + false + diff --git a/debugger/question.mli b/debugger/question.mli new file mode 100644 index 0000000..3a92dee --- /dev/null +++ b/debugger/question.mli @@ -0,0 +1,2 @@ +(* Ask user a yes or no question. *) +val yes_or_no : string -> bool diff --git a/debugger/show_information.ml b/debugger/show_information.ml new file mode 100644 index 0000000..ebe446d --- /dev/null +++ b/debugger/show_information.ml @@ -0,0 +1,94 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: show_information.ml,v 1.13 2005-08-25 15:35:16 doligez Exp $ *) + +open Instruct +open Format +open Primitives +open Debugcom +open Checkpoints +open Events +open Symbols +open Frames +open Show_source +open Breakpoints + +(* Display information about the current event. *) +let show_current_event ppf = + fprintf ppf "Time : %Li" (current_time ()); + (match current_pc () with + | Some pc -> + fprintf ppf " - pc : %i" pc + | _ -> ()); + update_current_event (); + reset_frame (); + match current_report () with + | None -> + fprintf ppf "@.Beginning of program.@."; + show_no_point () + | Some {rep_type = (Event | Breakpoint); rep_program_pointer = pc} -> + let ev = get_current_event () in + fprintf ppf " - module %s@." ev.ev_module; + (match breakpoints_at_pc pc with + | [] -> + () + | [breakpoint] -> + fprintf ppf "Breakpoint : %i@." breakpoint + | breakpoints -> + fprintf ppf "Breakpoints : %a@." + (fun ppf l -> + List.iter + (function x -> fprintf ppf "%i " x) l) + (List.sort compare breakpoints)); + show_point ev true + | Some {rep_type = Exited} -> + fprintf ppf "@.Program exit.@."; + show_no_point () + | Some {rep_type = Uncaught_exc} -> + fprintf ppf + "@.Program end.@.\ + @[Uncaught exception:@ %a@]@." + Printval.print_exception (Debugcom.Remote_value.accu ()); + show_no_point () + | Some {rep_type = Trap_barrier} -> + (* Trap_barrier not visible outside *) + (* of module `time_travel'. *) + Misc.fatal_error "Show_information.show_current_event" + +(* Display short information about one frame. *) + +let show_one_frame framenum ppf event = + fprintf ppf "#%i Pc : %i %s char %i@." + framenum event.ev_pos event.ev_module + (Events.get_pos event).Lexing.pos_cnum + +(* Display information about the current frame. *) +(* --- `select frame' must have succeded before calling this function. *) +let show_current_frame ppf selected = + match !selected_event with + | None -> + fprintf ppf "@.No frame selected.@." + | Some sel_ev -> + show_one_frame !current_frame ppf sel_ev; + begin match breakpoints_at_pc sel_ev.ev_pos with + | [] -> () + | [breakpoint] -> + fprintf ppf "Breakpoint : %i@." breakpoint + | breakpoints -> + fprintf ppf "Breakpoints : %a@." + (fun ppf l -> + List.iter (function x -> fprintf ppf "%i " x) l) + (List.sort compare breakpoints); + end; + show_point sel_ev selected diff --git a/debugger/show_information.mli b/debugger/show_information.mli new file mode 100644 index 0000000..d8d679a --- /dev/null +++ b/debugger/show_information.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: show_information.mli,v 1.3 2000-03-06 22:11:25 weis Exp $ *) + +open Format;; + +(* Display information about the current event. *) +val show_current_event : formatter -> unit;; + +(* Display information about the current frame. *) +(* --- `select frame' must have succeded before calling this function. *) +val show_current_frame : formatter -> bool -> unit;; + +(* Display short information about one frame. *) +val show_one_frame : int -> formatter -> Instruct.debug_event -> unit diff --git a/debugger/show_source.ml b/debugger/show_source.ml new file mode 100644 index 0000000..4eddfa8 --- /dev/null +++ b/debugger/show_source.ml @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: show_source.ml,v 1.14 2006-12-09 13:49:10 ertai Exp $ *) + +open Debugger_config +open Instruct +open Misc +open Parameters +open Primitives +open Printf +open Source + +(* Print a line; return the beginning of the next line *) +let print_line buffer line_number start point before = + let next = next_linefeed buffer start + and content = buffer_content buffer + in + printf "%i " line_number; + if point <= next && point >= start then + (print_string (String.sub content start (point - start)); + print_string (if before then event_mark_before else event_mark_after); + print_string (String.sub content point (next - point))) + else + print_string (String.sub content start (next - start)); + print_newline (); + next + +(* Tell Emacs we are nowhere in the source. *) +let show_no_point () = + if !emacs then printf "\026\026H\n" + +(* Print the line containing the point *) +let show_point ev selected = + let mdle = ev.ev_module in + let before = (ev.ev_kind = Event_before) in + if !emacs && selected then + begin try + let source = source_of_module ev.ev_loc.Location.loc_start mdle in + printf "\026\026M%s:%i:%i" source + ev.ev_loc.Location.loc_start.Lexing.pos_cnum + ev.ev_loc.Location.loc_end.Lexing.pos_cnum; + printf "%s\n" (if before then ":before" else ":after") + with + Not_found -> (* get_buffer *) + prerr_endline ("No source file for " ^ mdle ^ "."); + show_no_point () + end + else + begin try + let pos = Events.get_pos ev in + let buffer = get_buffer pos mdle in + let point = pos.Lexing.pos_cnum in + let (start, line_number) = line_of_pos buffer point in + ignore(print_line buffer line_number start point before) + with + Out_of_range -> (* line_of_pos *) + prerr_endline "Position out of range." + | Not_found -> (* Events.get_pos || get_buffer *) + prerr_endline ("No source file for " ^ mdle ^ ".") + end + +(* Display part of the source. *) +let show_listing pos mdle start stop point before = + try + let buffer = get_buffer pos mdle in + let rec aff (line_start, line_number) = + if line_number <= stop then + aff (print_line buffer line_number line_start point before + 1, line_number + 1) + in + aff (pos_of_line buffer start) + with + Out_of_range -> (* pos_of_line *) + prerr_endline "Position out of range." + | Not_found -> (* get_buffer *) + prerr_endline ("No source file for " ^ mdle ^ ".") diff --git a/debugger/show_source.mli b/debugger/show_source.mli new file mode 100644 index 0000000..3f9b1e7 --- /dev/null +++ b/debugger/show_source.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: show_source.mli,v 1.5 2006-12-09 13:49:10 ertai Exp $ *) + +(* Print the line containing the point *) +val show_point : Instruct.debug_event -> bool -> unit;; + +(* Tell Emacs we are nowhere in the source. *) +val show_no_point : unit -> unit;; + +(* Display part of the source. *) +val show_listing : Lexing.position -> string -> int -> int -> int -> bool -> unit;; diff --git a/debugger/source.ml b/debugger/source.ml new file mode 100644 index 0000000..1db8ca3 --- /dev/null +++ b/debugger/source.ml @@ -0,0 +1,167 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: source.ml,v 1.8 2006-12-09 13:49:10 ertai Exp $ *) + +(************************ Source management ****************************) + +open Misc +open Primitives + +let source_extensions = [".ml"] + +(*** Conversion function. ***) + +let source_of_module pos mdle = + let fname = pos.Lexing.pos_fname in + if fname = "" then + let rec loop = + function + | [] -> raise Not_found + | ext :: exts -> + try find_in_path_uncap !Config.load_path (mdle ^ ext) + with Not_found -> loop exts + in loop source_extensions + else if Filename.is_implicit fname then + find_in_path !Config.load_path fname + else + fname + +(*** Buffer cache ***) + +(* Buffer and cache (to associate lines and positions in the buffer). *) +type buffer = string * (int * int) list ref + +let buffer_max_count = ref 10 + +let cache_size = 30 + +let buffer_list = + ref ([] : (string * buffer) list) + +let flush_buffer_list () = + buffer_list := [] + +let get_buffer pos mdle = + try List.assoc mdle !buffer_list with + Not_found -> + let inchan = open_in_bin (source_of_module pos mdle) in + let (content, _) as buffer = + (String.create (in_channel_length inchan), ref []) + in + unsafe_really_input inchan content 0 (in_channel_length inchan); + buffer_list := + (list_truncate !buffer_max_count ((mdle, buffer)::!buffer_list)); + buffer + +let buffer_content = + (fst : buffer -> string) + +let buffer_length x = + String.length (buffer_content x) + +(*** Position conversions. ***) + +type position = int * int + +(* Insert a new pair (position, line) in the cache of the given buffer. *) +let insert_pos buffer ((position, line) as pair) = + let rec new_list = + function + [] -> + [(position, line)] + | ((pos, lin) as a::l) as l' -> + if lin < line then + pair::l' + else if lin = line then + l' + else + a::(new_list l) + in + let buffer_cache = snd buffer in + buffer_cache := new_list !buffer_cache + +(* Position of the next linefeed after `pos'. *) +(* Position just after the buffer end if no linefeed found. *) +(* Raise `Out_of_range' if already there. *) +let next_linefeed (buffer, _) pos = + let len = String.length buffer in + if pos >= len then + raise Out_of_range + else + let rec search p = + if p = len || String.get buffer p = '\n' then + p + else + search (succ p) + in + search pos + +(* Go to next line. *) +let next_line buffer (pos, line) = + (next_linefeed buffer pos + 1, line + 1) + +(* Convert a position in the buffer to a line number. *) +let line_of_pos buffer position = + let rec find = + function + | [] -> + if position < 0 then + raise Out_of_range + else + (0, 1) + | ((pos, line) as pair)::l -> + if pos > position then + find l + else + pair + and find_line previous = + let (pos, line) as next = next_line buffer previous in + if pos <= position then + find_line next + else + previous + in + let result = find_line (find !(snd buffer)) in + insert_pos buffer result; + result + +(* Convert a line number to a position. *) +let pos_of_line buffer line = + let rec find = + function + [] -> + if line <= 0 then + raise Out_of_range + else + (0, 1) + | ((pos, lin) as pair)::l -> + if lin > line then + find l + else + pair + and find_pos previous = + let (_, lin) as next = next_line buffer previous in + if lin <= line then + find_pos next + else + previous + in + let result = find_pos (find !(snd buffer)) in + insert_pos buffer result; + result + +(* Convert a coordinate (line / column) into a position. *) +(* --- The first line and column are line 1 and column 1. *) +let point_of_coord buffer line column = + fst (pos_of_line buffer line) + (pred column) diff --git a/debugger/source.mli b/debugger/source.mli new file mode 100644 index 0000000..c30964a --- /dev/null +++ b/debugger/source.mli @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: source.mli,v 1.3 2006-12-09 13:49:10 ertai Exp $ *) + +(************************ Source management ****************************) + +(*** Conversion function. ***) + +val source_of_module: Lexing.position -> string -> string + +(*** buffer cache ***) + +type buffer + +val buffer_max_count : int ref + +val flush_buffer_list : unit -> unit + +val get_buffer : Lexing.position -> string -> buffer + +val buffer_content : buffer -> string +val buffer_length : buffer -> int + +(*** Position conversions. ***) + +(* Pair (position, line) where `position' is the position in character of *) +(* the beginning of the line (first character is 0) and `line' is its *) +(* number (first line number is 1). *) +type position = int * int + +(* Position of the next linefeed after `pos'. *) +(* Position just after the buffer end if no linefeed found. *) +(* Raise `Out_of_range' if already there. *) +val next_linefeed : buffer -> int -> int + +(* Go to next line. *) +val next_line : buffer -> position -> position + +(* Convert a position in the buffer to a line number. *) +val line_of_pos : buffer -> int -> position + +(* Convert a line number to a position. *) +val pos_of_line : buffer -> int -> position + +(* Convert a coordinate (line / column) into a position. *) +(* --- The first line and column are line 1 and column 1. *) +val point_of_coord : buffer -> int -> int -> int diff --git a/debugger/symbols.ml b/debugger/symbols.ml new file mode 100644 index 0000000..dbd32f8 --- /dev/null +++ b/debugger/symbols.ml @@ -0,0 +1,194 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: symbols.ml,v 1.18 2005-08-25 15:35:16 doligez Exp $ *) + +(* Handling of symbol tables (globals and events) *) + +open Instruct +open Debugger_config (* Toplevel *) + +let modules = + ref ([] : string list) + +let events = + ref ([] : debug_event list) +let events_by_pc = + (Hashtbl.create 257 : (int, debug_event) Hashtbl.t) +let events_by_module = + (Hashtbl.create 17 : (string, debug_event array) Hashtbl.t) +let all_events_by_module = + (Hashtbl.create 17 : (string, debug_event list) Hashtbl.t) + +let relocate_event orig ev = + ev.ev_pos <- orig + ev.ev_pos; + match ev.ev_repr with + Event_parent repr -> repr := ev.ev_pos + | _ -> () + +let read_symbols' bytecode_file = + let ic = open_in_bin bytecode_file in + begin try + Bytesections.read_toc ic; + ignore(Bytesections.seek_section ic "SYMB"); + with Bytesections.Bad_magic_number | Not_found -> + prerr_string bytecode_file; prerr_endline " is not a bytecode file."; + raise Toplevel + end; + Symtable.restore_state (input_value ic); + begin try + ignore (Bytesections.seek_section ic "DBUG") + with Not_found -> + prerr_string bytecode_file; prerr_endline " has no debugging info."; + raise Toplevel + end; + let num_eventlists = input_binary_int ic in + let eventlists = ref [] in + for i = 1 to num_eventlists do + let orig = input_binary_int ic in + let evl = (input_value ic : debug_event list) in + (* Relocate events in event list *) + List.iter (relocate_event orig) evl; + eventlists := evl :: !eventlists + done; + close_in_noerr ic; + !eventlists + +let read_symbols bytecode_file = + let all_events = read_symbols' bytecode_file in + + modules := []; events := []; + Hashtbl.clear events_by_pc; Hashtbl.clear events_by_module; + Hashtbl.clear all_events_by_module; + + List.iter + (fun evl -> + List.iter + (fun ev -> + events := ev :: !events; + Hashtbl.add events_by_pc ev.ev_pos ev) + evl) + all_events; + + List.iter + (function + [] -> () + | ev :: _ as evl -> + let md = ev.ev_module in + let cmp ev1 ev2 = compare (Events.get_pos ev1).Lexing.pos_cnum + (Events.get_pos ev2).Lexing.pos_cnum + in + let sorted_evl = List.sort cmp evl in + modules := md :: !modules; + Hashtbl.add all_events_by_module md sorted_evl; + let real_evl = + Primitives.filter + (function + {ev_kind = Event_pseudo} -> false + | _ -> true) + sorted_evl + in + Hashtbl.add events_by_module md (Array.of_list real_evl)) + all_events + +let any_event_at_pc pc = + Hashtbl.find events_by_pc pc + +let event_at_pc pc = + let ev = any_event_at_pc pc in + match ev.ev_kind with + Event_pseudo -> raise Not_found + | _ -> ev + +let set_event_at_pc pc = + try ignore(event_at_pc pc); Debugcom.set_event pc + with Not_found -> () + +(* List all events in module *) +let events_in_module mdle = + try + Hashtbl.find all_events_by_module mdle + with Not_found -> + [] + +(* Binary search of event at or just after char *) +let find_event ev char = + let rec bsearch lo hi = + if lo >= hi then begin + if (Events.get_pos ev.(hi)).Lexing.pos_cnum < char + then raise Not_found + else hi + end else begin + let pivot = (lo + hi) / 2 in + let e = ev.(pivot) in + if char <= (Events.get_pos e).Lexing.pos_cnum + then bsearch lo pivot + else bsearch (pivot + 1) hi + end + in + bsearch 0 (Array.length ev - 1) + +(* Return first event after the given position. *) +(* Raise [Not_found] if module is unknown or no event is found. *) +let event_at_pos md char = + let ev = Hashtbl.find events_by_module md in + ev.(find_event ev char) + +(* Return event closest to given position *) +(* Raise [Not_found] if module is unknown or no event is found. *) +let event_near_pos md char = + let ev = Hashtbl.find events_by_module md in + try + let pos = find_event ev char in + (* Desired event is either ev.(pos) or ev.(pos - 1), + whichever is closest *) + if pos > 0 && char - (Events.get_pos ev.(pos - 1)).Lexing.pos_cnum + <= (Events.get_pos ev.(pos)).Lexing.pos_cnum - char + then ev.(pos - 1) + else ev.(pos) + with Not_found -> + let pos = Array.length ev - 1 in + if pos < 0 then raise Not_found; + ev.(pos) + +(* Flip "event" bit on all instructions *) +let set_all_events () = + Hashtbl.iter + (fun pc ev -> + match ev.ev_kind with + Event_pseudo -> () + | _ -> Debugcom.set_event ev.ev_pos) + events_by_pc + + +(* Previous `pc'. *) +(* Save time if `update_current_event' is called *) +(* several times at the same point. *) +let old_pc = ref (None : int option) + +(* Recompute the current event *) +let update_current_event () = + match Checkpoints.current_pc () with + None -> + Events.current_event := None; + old_pc := None + | (Some pc) as opt_pc when opt_pc <> !old_pc -> + Events.current_event := + begin try + Some (event_at_pc pc) + with Not_found -> + None + end; + old_pc := opt_pc + | _ -> + () diff --git a/debugger/symbols.mli b/debugger/symbols.mli new file mode 100644 index 0000000..36875f7 --- /dev/null +++ b/debugger/symbols.mli @@ -0,0 +1,46 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: symbols.mli,v 1.7 2005-08-25 15:35:16 doligez Exp $ *) + +(* Modules used by the program. *) +val modules : string list ref + +(* Read debugging info from executable file *) +val read_symbols : string -> unit + +(* Flip "event" bit on all instructions *) +val set_all_events : unit -> unit + +(* Return event at given PC, or raise Not_found *) +(* Can also return pseudo-event at beginning of functions *) +val any_event_at_pc : int -> Instruct.debug_event + +(* Return event at given PC, or raise Not_found *) +val event_at_pc : int -> Instruct.debug_event +(* Set event at given PC *) +val set_event_at_pc : int -> unit + +(* List the events in `module'. *) +val events_in_module : string -> Instruct.debug_event list + +(* First event after the given position. *) +(* --- Raise `Not_found' if no such event. *) +val event_at_pos : string -> int -> Instruct.debug_event + +(* Closest event from given position. *) +(* --- Raise `Not_found' if no such event. *) +val event_near_pos : string -> int -> Instruct.debug_event + +(* Recompute the current event *) +val update_current_event : unit -> unit diff --git a/debugger/time_travel.ml b/debugger/time_travel.ml new file mode 100644 index 0000000..55b29a8 --- /dev/null +++ b/debugger/time_travel.ml @@ -0,0 +1,648 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: time_travel.ml,v 1.21 2006-12-09 16:23:37 ertai Exp $ *) + +(**************************** Time travel ******************************) + +open Int64ops +open Instruct +open Events +open Debugcom +open Primitives +open Checkpoints +open Breakpoints +open Trap_barrier +open Input_handling +open Debugger_config +open Program_loading +open Question + +exception Current_checkpoint_lost +exception Current_checkpoint_lost_start_at of int64 * int64 + +let remove_1st key list = + let rec remove = + function + [] -> [] + | a::l -> if a == key then l else a::(remove l) + in + remove list + +(*** Debugging. ***) + +let debug_time_travel = ref false + +(*** Internal utilities. ***) + +(* Insert a checkpoint in the checkpoint list. + * Raise `Exit' if there is already a checkpoint at the same time. + *) +let insert_checkpoint ({c_time = time} as checkpoint) = + let rec traverse = + function + [] -> [checkpoint] + | (({c_time = t} as a)::l) as l' -> + if t > time then + a::(traverse l) + else if t = time then + raise Exit + else + checkpoint::l' + in + checkpoints := traverse !checkpoints + +(* Remove a checkpoint from the checkpoint list. + * --- No error if not found. + *) +let remove_checkpoint checkpoint = + checkpoints := remove_1st checkpoint !checkpoints + +(* Wait for the process used by `checkpoint' to connect. + * --- Usually not called (the process is already connected). + *) +let wait_for_connection checkpoint = + try + Exec.unprotect + (function () -> + let old_controller = Input_handling.current_controller !connection in + execute_with_other_controller + (function + fd -> + old_controller fd; + if checkpoint.c_valid = true then + exit_main_loop ()) + !connection + main_loop) + with + Sys.Break -> + checkpoint.c_parent <- root; + remove_checkpoint checkpoint; + checkpoint.c_pid <- -1; + raise Sys.Break + +(* Select a checkpoint as current. *) +let set_current_checkpoint checkpoint = + if !debug_time_travel then + prerr_endline ("Select : " ^ (string_of_int checkpoint.c_pid)); + if not checkpoint.c_valid then + wait_for_connection checkpoint; + current_checkpoint := checkpoint; + set_current_connection checkpoint.c_fd + +(* Kill `checkpoint'. *) +let kill_checkpoint checkpoint = + if !debug_time_travel then + prerr_endline ("Kill : " ^ (string_of_int checkpoint.c_pid)); + if checkpoint.c_pid > 0 then (* Ghosts don't have to be killed ! *) + (if not checkpoint.c_valid then + wait_for_connection checkpoint; + stop checkpoint.c_fd; + if checkpoint.c_parent.c_pid > 0 then + wait_child checkpoint.c_parent.c_fd; + checkpoint.c_parent <- root; + close_io checkpoint.c_fd; + remove_file checkpoint.c_fd; + remove_checkpoint checkpoint); + checkpoint.c_pid <- -1 (* Don't exist anymore *) + +(*** Cleaning the checkpoint list. ***) + +(* Separe checkpoints before (<=) and after (>) `t'. *) +(* ### t checkpoints -> (after, before) *) +let cut t = + let rec cut_t = + function + [] -> ([], []) + | ({c_time = t'} as a::l) as l' -> + if t' <= t then + ([], l') + else + let (b, e) = cut_t l in + (a::b, e) + in + cut_t + +(* Partition the checkpoints list. *) +let cut2 t0 t l = + let rec cut2_t0 t = + function + [] -> [] + | l -> + let (after, before) = cut (t0 -- t -- _1) l in + let l = cut2_t0 (t ++ t) before in + after::l + in + let (after, before) = cut (t0 -- _1) l in + after::(cut2_t0 t before) + +(* Separe first elements and last element of a list of checkpoint. *) +let chk_merge2 cont = + let rec chk_merge2_cont = + function + [] -> cont + | [a] -> + let (accepted, rejected) = cont in + (a::accepted, rejected) + | a::l -> + let (accepted, rejected) = chk_merge2_cont l in + (accepted, a::rejected) + in chk_merge2_cont + +(* Separe the checkpoint list. *) +(* ### list -> accepted * rejected *) +let rec chk_merge = + function + [] -> ([], []) + | l::tail -> + chk_merge2 (chk_merge tail) l + +let new_checkpoint_list checkpoint_count accepted rejected = + if List.length accepted >= checkpoint_count then + let (k, l) = list_truncate2 checkpoint_count accepted in + (k, l @ rejected) + else + let (k, l) = + list_truncate2 (checkpoint_count - List.length accepted) rejected + in + (List.merge (fun {c_time = t1} {c_time = t2} -> compare t2 t1) accepted k, + l) + +(* Clean the checkpoint list. *) +(* Reference time is `time'. *) +let clean_checkpoints time checkpoint_count = + let (after, before) = cut time !checkpoints in + let (accepted, rejected) = + chk_merge (cut2 time !checkpoint_small_step before) + in + let (kept, lost) = + new_checkpoint_list checkpoint_count accepted after + in + List.iter kill_checkpoint (lost @ rejected); + checkpoints := kept + +(*** Internal functions for moving. ***) + +(* Find the first checkpoint before (or at) `time'. + * Ask for reloading the program if necessary. + *) +let find_checkpoint_before time = + let rec find = + function + [] -> + print_string "Can't go that far in the past !"; print_newline (); + if yes_or_no "Reload program" then begin + load_program (); + find !checkpoints + end + else + raise Toplevel + | { c_time = t } as a::l -> + if t > time then + find l + else + a + in find !checkpoints + +(* Make a copy of the current checkpoint and clean the checkpoint list. *) +(* --- The new checkpoint in not put in the list. *) +let duplicate_current_checkpoint () = + let checkpoint = !current_checkpoint in + if not checkpoint.c_valid then + wait_for_connection checkpoint; + let new_checkpoint = (* Ghost *) + {c_time = checkpoint.c_time; + c_pid = 0; + c_fd = checkpoint.c_fd; + c_valid = false; + c_report = checkpoint.c_report; + c_state = C_stopped; + c_parent = checkpoint; + c_breakpoint_version = checkpoint.c_breakpoint_version; + c_breakpoints = checkpoint.c_breakpoints; + c_trap_barrier = checkpoint.c_trap_barrier} + in + checkpoints := list_replace checkpoint new_checkpoint !checkpoints; + set_current_checkpoint checkpoint; + clean_checkpoints (checkpoint.c_time ++ _1) (!checkpoint_max_count - 1); + if new_checkpoint.c_pid = 0 then (* The ghost has not been killed *) + (match do_checkpoint () with (* Duplicate checkpoint *) + Checkpoint_done pid -> + (new_checkpoint.c_pid <- pid; + if !debug_time_travel then + prerr_endline ("Waiting for connection : " ^ (string_of_int pid))) + | Checkpoint_failed -> + prerr_endline + "A fork failed. Reducing maximum number of checkpoints."; + checkpoint_max_count := List.length !checkpoints - 1; + remove_checkpoint new_checkpoint) + +(* Was the movement interrupted ? *) +(* --- An exception could have been used instead, *) +(* --- but it is not clear where it should be caught. *) +(* --- For instance, it should not be caught in `step' *) +(* --- (as `step' is used in `next_1'). *) +(* --- On the other side, other modules does not need to know *) +(* --- about this exception. *) +let interrupted = ref false + +(* Informations about last breakpoint encountered *) +let last_breakpoint = ref None + +(* Ensure we stop on an event. *) +let rec stop_on_event report = + match report with + {rep_type = Breakpoint; rep_program_pointer = pc; + rep_stack_pointer = sp} -> + last_breakpoint := Some (pc, sp); + Symbols.update_current_event (); + begin match !current_event with + None -> find_event () + | Some _ -> () + end + | {rep_type = Trap_barrier; rep_stack_pointer = trap_frame} -> + (* No event at current position. *) + find_event () + | _ -> + () + +and find_event () = + if !debug_time_travel then begin + print_string "Searching next event..."; + print_newline () + end; + let report = do_go _1 in + !current_checkpoint.c_report <- Some report; + stop_on_event report + +(* Internal function for running debugged program. + * Requires `duration > 0'. + *) +let internal_step duration = + match current_report () with + Some {rep_type = Exited | Uncaught_exc} -> () + | _ -> + Exec.protect + (function () -> + if !make_checkpoints then + duplicate_current_checkpoint () + else + remove_checkpoint !current_checkpoint; + update_breakpoints (); + update_trap_barrier (); + !current_checkpoint.c_state <- C_running duration; + let report = do_go duration in + !current_checkpoint.c_report <- Some report; + !current_checkpoint.c_state <- C_stopped; + if report.rep_type = Event then begin + !current_checkpoint.c_time <- + !current_checkpoint.c_time ++ duration; + interrupted := false; + last_breakpoint := None + end + else begin + !current_checkpoint.c_time <- + !current_checkpoint.c_time ++ duration + -- (Int64.of_int report.rep_event_count) ++ _1; + interrupted := true; + last_breakpoint := None; + stop_on_event report + end; + (try + insert_checkpoint !current_checkpoint + with + Exit -> + kill_checkpoint !current_checkpoint; + set_current_checkpoint + (find_checkpoint_before (current_time ())))); + if !debug_time_travel then begin + print_string "Checkpoints : pid(time)"; print_newline (); + List.iter + (function {c_time = time; c_pid = pid; c_valid = valid} -> + Printf.printf "%d(%Ld)%s " pid time + (if valid then "" else "(invalid)")) + !checkpoints; + print_newline () + end + +(*** Miscellaneous functions (exported). ***) + +(* Create a checkpoint at time 0 (new program). *) +let new_checkpoint pid fd = + let new_checkpoint = + {c_time = _0; + c_pid = pid; + c_fd = fd; + c_valid = true; + c_report = None; + c_state = C_stopped; + c_parent = root; + c_breakpoint_version = 0; + c_breakpoints = []; + c_trap_barrier = 0} + in + insert_checkpoint new_checkpoint + +(* Set the file descriptor of a checkpoint *) +(* (a new process has connected with the debugger). *) +(* --- Return `true' on success (close the connection otherwise). *) +let set_file_descriptor pid fd = + let rec find = + function + [] -> + prerr_endline "Unexpected connection"; + close_io fd; + false + | ({c_pid = pid'} as checkpoint)::l -> + if pid <> pid' then + find l + else + (checkpoint.c_fd <- fd; + checkpoint.c_valid <- true; + true) + in + if !debug_time_travel then + prerr_endline ("New connection : " ^(string_of_int pid)); + find (!current_checkpoint::!checkpoints) + +(* Kill all the checkpoints. *) +let kill_all_checkpoints () = + List.iter kill_checkpoint (!current_checkpoint::!checkpoints) + +(* Kill a checkpoint without killing the process. *) +(* (used when connection with the process is lost). *) +(* --- Assume that the checkpoint is valid. *) +let forget_process fd pid = + let checkpoint = + find (function c -> c.c_pid = pid) (!current_checkpoint::!checkpoints) + in + Printf.eprintf "Lost connection with process %d" pid; + let kont = + if checkpoint == !current_checkpoint then begin + Printf.eprintf " (active process)\n"; + match !current_checkpoint.c_state with + C_stopped -> + Printf.eprintf "at time %Ld" !current_checkpoint.c_time; + fun () -> raise Current_checkpoint_lost + | C_running duration -> + Printf.eprintf "between time %Ld and time %Ld" + !current_checkpoint.c_time + (!current_checkpoint.c_time ++ duration); + fun () -> raise (Current_checkpoint_lost_start_at + (!current_checkpoint.c_time, duration)) + end + else ignore in + Printf.eprintf "\n"; flush stderr; + Input_handling.remove_file fd; + close_io checkpoint.c_fd; + remove_file checkpoint.c_fd; + remove_checkpoint checkpoint; + checkpoint.c_pid <- -1; (* Don't exist anymore *) + if checkpoint.c_parent.c_pid > 0 then + wait_child checkpoint.c_parent.c_fd; + kont () + +(* Try to recover when the current checkpoint is lost. *) +let recover () = + set_current_checkpoint + (find_checkpoint_before (current_time ())) + +(*** Simple movements. ***) + +(* Forward stepping. Requires `duration >= 0'. *) +let rec step_forward duration = + if duration > !checkpoint_small_step then begin + let first_step = + if duration > !checkpoint_big_step then + !checkpoint_big_step + else + !checkpoint_small_step + in + internal_step first_step; + if not !interrupted then + step_forward (duration -- first_step) + end + else if duration != _0 then + internal_step duration + +(* Go to time `time' from current checkpoint (internal). *) +let internal_go_to time = + let duration = time -- (current_time ()) in + if duration > _0 then + execute_without_breakpoints (function () -> step_forward duration) + +(* Move to a given time. *) +let go_to time = + let checkpoint = find_checkpoint_before time in + set_current_checkpoint checkpoint; + internal_go_to time + +(* Return the time of the last breakpoint *) +(* between current time and `max_time'. *) +let rec find_last_breakpoint max_time = + let rec find break = + let time = current_time () in + step_forward (max_time -- time); + match !last_breakpoint, !temporary_breakpoint_position with + (Some _, _) when current_time () < max_time -> + find !last_breakpoint + | (Some (pc, _), Some pc') when pc = pc' -> + (max_time, !last_breakpoint) + | _ -> + (time, break) + in + find + (match current_pc_sp () with + (Some (pc, _)) as state when breakpoint_at_pc pc -> state + | _ -> None) + + +(* Run from `time_max' back to `time'. *) +(* --- Assume 0 <= time < time_max *) +let rec back_to time time_max = + let + {c_time = t} = find_checkpoint_before (pre64 time_max) + in + go_to (max time t); + let (new_time, break) = find_last_breakpoint time_max in + if break <> None || (new_time <= time) then begin + go_to new_time; + interrupted := break <> None; + last_breakpoint := break + end else + back_to time new_time + +(* Backward stepping. *) +(* --- Assume duration > 1 *) +let step_backward duration = + let time = current_time () in + if time > _0 then + back_to (max _0 (time -- duration)) time + +(* Run the program from current time. *) +(* Stop at the first breakpoint, or at the end of the program. *) +let rec run () = + internal_step !checkpoint_big_step; + if not !interrupted then + run () + +(* Run backward the program form current time. *) +(* Stop at the first breakpoint, or at the beginning of the program. *) +let back_run () = + if current_time () > _0 then + back_to _0 (current_time ()) + +(* Step in any direction. *) +(* Stop at the first brakpoint, or after `duration' steps. *) +let step duration = + if duration >= _0 then + step_forward duration + else + step_backward (_0 -- duration) + +(*** Next, finish. ***) + +(* Finish current function. *) +let finish () = + Symbols.update_current_event (); + match !current_event with + None -> + prerr_endline "`finish' not meaningful in outermost frame."; + raise Toplevel + | Some curr_event -> + set_initial_frame(); + let (frame, pc) = up_frame curr_event.ev_stacksize in + if frame < 0 then begin + prerr_endline "`finish' not meaningful in outermost frame."; + raise Toplevel + end; + begin + try ignore(Symbols.any_event_at_pc pc) + with Not_found -> + prerr_endline "Calling function has no debugging information."; + raise Toplevel + end; + exec_with_trap_barrier + frame + (fun () -> + exec_with_temporary_breakpoint + pc + (fun () -> + while + run (); + match !last_breakpoint with + Some (pc', frame') when pc = pc' -> + interrupted := false; + frame <> frame' + | _ -> + false + do + () + done)) + +let next_1 () = + Symbols.update_current_event (); + match !current_event with + None -> (* Beginning of the program. *) + step _1 + | Some event1 -> + let (frame1, pc1) = initial_frame() in + step _1; + if not !interrupted then begin + Symbols.update_current_event (); + match !current_event with + None -> () + | Some event2 -> + let (frame2, pc2) = initial_frame() in + (* Call `finish' if we've entered a function. *) + if frame1 >= 0 && frame2 >= 0 && + frame2 - event2.ev_stacksize > frame1 - event1.ev_stacksize + then finish() + end + +(* Same as `step' (forward) but skip over function calls. *) +let rec next = + function + 0 -> () + | n -> + next_1 (); + if not !interrupted then + next (n - 1) + +(* Run backward until just before current function. *) +let start () = + Symbols.update_current_event (); + match !current_event with + None -> + prerr_endline "`start not meaningful in outermost frame."; + raise Toplevel + | Some curr_event -> + let (frame, _) = initial_frame() in + let (frame', pc) = up_frame curr_event.ev_stacksize in + if frame' < 0 then begin + prerr_endline "`start not meaningful in outermost frame."; + raise Toplevel + end; + let nargs = + match + try Symbols.any_event_at_pc pc with Not_found -> + prerr_endline "Calling function has no debugging information."; + raise Toplevel + with + {ev_info = Event_return nargs} -> nargs + | _ -> Misc.fatal_error "Time_travel.start" + in + let offset = if nargs < 4 then 1 else 2 in + let pc = pc - 4 * offset in + while + exec_with_temporary_breakpoint pc back_run; + match !last_breakpoint with + Some (pc', frame') when pc = pc' -> + step _minus1; + (not !interrupted) + && + (frame' - nargs > frame - curr_event.ev_stacksize) + | _ -> + false + do + () + done + +let previous_1 () = + Symbols.update_current_event (); + match !current_event with + None -> (* End of the program. *) + step _minus1 + | Some event1 -> + let (frame1, pc1) = initial_frame() in + step _minus1; + if not !interrupted then begin + Symbols.update_current_event (); + match !current_event with + None -> () + | Some event2 -> + let (frame2, pc2) = initial_frame() in + (* Call `start' if we've entered a function. *) + if frame1 >= 0 && frame2 >= 0 && + frame2 - event2.ev_stacksize > frame1 - event1.ev_stacksize + then start() + end + +(* Same as `step' (backward) but skip over function calls. *) +let rec previous = + function + 0 -> () + | n -> + previous_1 (); + if not !interrupted then + previous (n - 1) diff --git a/debugger/time_travel.mli b/debugger/time_travel.mli new file mode 100644 index 0000000..5b9daeb --- /dev/null +++ b/debugger/time_travel.mli @@ -0,0 +1,37 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: time_travel.mli,v 1.6 2006-11-20 10:29:45 ertai Exp $ *) + +(**************************** Time travel ******************************) + +open Primitives + +exception Current_checkpoint_lost +exception Current_checkpoint_lost_start_at of int64 * int64 + +val new_checkpoint : int -> io_channel -> unit +val set_file_descriptor : int -> io_channel -> bool +val kill_all_checkpoints : unit -> unit +val forget_process : io_channel -> int -> unit +val recover : unit -> unit + +val go_to : int64 -> unit + +val run : unit -> unit +val back_run : unit -> unit +val step : int64 -> unit +val finish : unit -> unit +val next : int -> unit +val start : unit -> unit +val previous : int -> unit diff --git a/debugger/trap_barrier.ml b/debugger/trap_barrier.ml new file mode 100644 index 0000000..4b14eeb --- /dev/null +++ b/debugger/trap_barrier.ml @@ -0,0 +1,47 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: trap_barrier.ml,v 1.3 1999-11-17 18:57:29 xleroy Exp $ *) + +(************************** Trap barrier *******************************) + +open Debugcom +open Checkpoints + +let current_trap_barrier = ref 0 + +let install_trap_barrier pos = + current_trap_barrier := pos + +let remove_trap_barrier () = + current_trap_barrier := 0 + +(* Ensure the trap barrier state is up to date in current checkpoint. *) +let update_trap_barrier () = + if !current_checkpoint.c_trap_barrier <> !current_trap_barrier then + Exec.protect + (function () -> + set_trap_barrier !current_trap_barrier; + !current_checkpoint.c_trap_barrier <- !current_trap_barrier) + +(* Execute `funct' with a trap barrier. *) +(* --- Used by `finish'. *) +let exec_with_trap_barrier trap_barrier funct = + try + install_trap_barrier trap_barrier; + funct (); + remove_trap_barrier () + with + x -> + remove_trap_barrier (); + raise x diff --git a/debugger/trap_barrier.mli b/debugger/trap_barrier.mli new file mode 100644 index 0000000..57538e2 --- /dev/null +++ b/debugger/trap_barrier.mli @@ -0,0 +1,27 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: trap_barrier.mli,v 1.2 1999-11-17 18:57:29 xleroy Exp $ *) + +(************************* Trap barrier ********************************) + +val install_trap_barrier : int -> unit + +val remove_trap_barrier : unit -> unit + +(* Ensure the trap barrier state is up to date in current checkpoint. *) +val update_trap_barrier : unit -> unit + +(* Execute `funct' with a trap barrier. *) +(* --- Used by `finish'. *) +val exec_with_trap_barrier : int -> (unit -> unit) -> unit diff --git a/debugger/unix_tools.ml b/debugger/unix_tools.ml new file mode 100644 index 0000000..a678145 --- /dev/null +++ b/debugger/unix_tools.ml @@ -0,0 +1,143 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: unix_tools.ml,v 1.9 2008-07-29 08:31:41 xleroy Exp $ *) + +(****************** Tools for Unix *************************************) + +open Misc +open Unix +open Primitives + +(*** Convert a socket name into a socket address. ***) +let convert_address address = + try + let n = string_pos address ':' in + let host = String.sub address 0 n + and port = String.sub address (n + 1) (String.length address - n - 1) + in + (PF_INET, + ADDR_INET + ((try inet_addr_of_string host with Failure _ -> + try (gethostbyname host).h_addr_list.(0) with Not_found -> + prerr_endline ("Unknown host : " ^ host); + failwith "Can't convert address"), + (try int_of_string port with Failure _ -> + prerr_endline "The port number should be an integer"; + failwith "Can't convert address"))) + with Not_found -> + match Sys.os_type with + "Win32" -> failwith "Unix sockets not supported" + | _ -> (PF_UNIX, ADDR_UNIX address) + +(*** Report a unix error. ***) +let report_error = function + | Unix_error (err, fun_name, arg) -> + prerr_string "Unix error : '"; + prerr_string fun_name; + prerr_string "' failed"; + if String.length arg > 0 then + (prerr_string " on '"; + prerr_string arg; + prerr_string "'"); + prerr_string " : "; + prerr_endline (error_message err) + | _ -> fatal_error "report_error: not a Unix error" + +(* Find program `name' in `PATH'. *) +(* Return the full path if found. *) +(* Raise `Not_found' otherwise. *) +let search_in_path name = + let check name = + try access name [X_OK]; name with Unix_error _ -> raise Not_found + in + if not (Filename.is_implicit name) then + check name + else + let path = Sys.getenv "PATH" in + let length = String.length path in + let rec traverse pointer = + if (pointer >= length) || (path.[pointer] = ':') then + pointer + else + traverse (pointer + 1) + in + let rec find pos = + let pos2 = traverse pos in + let directory = (String.sub path pos (pos2 - pos)) in + let fullname = + if directory = "" then name else directory ^ "/" ^ name + in + try check fullname with + | Not_found -> + if pos2 < length then find (pos2 + 1) + else raise Not_found + in + find 0 + +(* Expand a path. *) +(* ### path -> path' *) +let rec expand_path ch = + let rec subst_variable ch = + try + let pos = string_pos ch '$' in + if (pos + 1 < String.length ch) && (ch.[pos + 1] = '$') then + (String.sub ch 0 (pos + 1)) + ^ (subst_variable + (String.sub ch (pos + 2) (String.length ch - pos - 2))) + else + (String.sub ch 0 pos) + ^ (subst2 (String.sub ch (pos + 1) (String.length ch - pos - 1))) + with Not_found -> + ch + and subst2 ch = + let suiv = + let i = ref 0 in + while !i < String.length ch && + (let c = ch.[!i] in (c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') + || c = '_') + do incr i done; + !i + in (Sys.getenv (String.sub ch 0 suiv)) + ^ (subst_variable (String.sub ch suiv (String.length ch - suiv))) + in + let ch = subst_variable ch in + let concat_root nom ch2 = + try Filename.concat (getpwnam nom).pw_dir ch2 + with Not_found -> + "~" ^ nom + in + if ch.[0] = '~' then + try + match string_pos ch '/' with + 1 -> + (let tail = String.sub ch 2 (String.length ch - 2) + in + try Filename.concat (Sys.getenv "HOME") tail + with Not_found -> + concat_root (Sys.getenv "LOGNAME") tail) + | n -> concat_root + (String.sub ch 1 (n - 1)) + (String.sub ch (n + 1) (String.length ch - n - 1)) + with + Not_found -> + expand_path (ch ^ "/") + else ch + +let make_absolute name = + if Filename.is_relative name + then Filename.concat (getcwd ()) name + else name +;; diff --git a/debugger/unix_tools.mli b/debugger/unix_tools.mli new file mode 100644 index 0000000..40e0c41 --- /dev/null +++ b/debugger/unix_tools.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* Objective Caml port by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: unix_tools.mli,v 1.4 2002-11-02 22:36:45 doligez Exp $ *) + +(**************************** Tools for Unix ***************************) + +open Unix + +(* Convert a socket name into a socket address. *) +val convert_address : string -> socket_domain * sockaddr + +(* Report an unix error. *) +val report_error : exn -> unit + +(* Find program `name' in `PATH'. *) +(* Return the full path if found. *) +(* Raise `Not_found' otherwise. *) +val search_in_path : string -> string + +(* Path expansion. *) +val expand_path : string -> string + +val make_absolute : string -> string diff --git a/driver/compile.ml b/driver/compile.ml new file mode 100644 index 0000000..f4e00f6 --- /dev/null +++ b/driver/compile.ml @@ -0,0 +1,152 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compile.ml,v 1.61 2008-10-06 13:53:54 doligez Exp $ *) + +(* The batch compiler *) + +open Misc +open Config +open Format +open Typedtree + +(* Initialize the search path. + The current directory is always searched first, + then the directories specified with the -I option (in command-line order), + then the standard library directory (unless the -nostdlib option is given). + *) + +let init_path () = + let dirs = + if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs + else if !Clflags.use_vmthreads then "+vmthreads" :: !Clflags.include_dirs + else !Clflags.include_dirs in + let exp_dirs = + List.map (expand_directory Config.standard_library) dirs in + load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ()); + Env.reset_cache () + +(* Return the initial environment in which compilation proceeds. *) + +(* Note: do not do init_path() in initial_env, this breaks + toplevel initialization (PR#1775) *) +let initial_env () = + Ident.reinit(); + try + if !Clflags.nopervasives + then Env.initial + else Env.open_pers_signature "Pervasives" Env.initial + with Not_found -> + fatal_error "cannot open pervasives.cmi" + +(* Note: this function is duplicated in optcompile.ml *) +let check_unit_name ppf filename name = + try + begin match name.[0] with + | 'A'..'Z' -> () + | _ -> + Location.print_warning (Location.in_file filename) ppf + (Warnings.Bad_module_name name); + raise Exit; + end; + for i = 1 to String.length name - 1 do + match name.[i] with + | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> () + | _ -> + Location.print_warning (Location.in_file filename) ppf + (Warnings.Bad_module_name name); + raise Exit; + done; + with Exit -> () +;; + +(* Compile a .mli file *) + +let interface ppf sourcefile outputprefix = + Location.input_name := sourcefile; + init_path (); + let modulename = + String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in + check_unit_name ppf sourcefile modulename; + Env.set_unit_name modulename; + let inputfile = Pparse.preprocess sourcefile in + try + let ast = + Pparse.file ppf inputfile Parse.interface ast_intf_magic_number in + if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast; + let sg = Typemod.transl_signature (initial_env()) ast in + if !Clflags.print_types then + fprintf std_formatter "%a@." Printtyp.signature + (Typemod.simplify_signature sg); + Warnings.check_fatal (); + if not !Clflags.print_types then + Env.save_signature sg modulename (outputprefix ^ ".cmi"); + Pparse.remove_preprocessed inputfile + with e -> + Pparse.remove_preprocessed_if_ast inputfile; + raise e + +(* Compile a .ml file *) + +let print_if ppf flag printer arg = + if !flag then fprintf ppf "%a@." printer arg; + arg + +let (++) x f = f x + +let implementation ppf sourcefile outputprefix = + Location.input_name := sourcefile; + init_path (); + let modulename = + String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in + check_unit_name ppf sourcefile modulename; + Env.set_unit_name modulename; + let inputfile = Pparse.preprocess sourcefile in + let env = initial_env() in + if !Clflags.print_types then begin + try ignore( + Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number + ++ print_if ppf Clflags.dump_parsetree Printast.implementation + ++ Typemod.type_implementation sourcefile outputprefix modulename env) + with x -> + Pparse.remove_preprocessed_if_ast inputfile; + raise x + end else begin + let objfile = outputprefix ^ ".cmo" in + let oc = open_out_bin objfile in + try + Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number + ++ print_if ppf Clflags.dump_parsetree Printast.implementation + ++ Unused_var.warn ppf + ++ Typemod.type_implementation sourcefile outputprefix modulename env + ++ Translmod.transl_implementation modulename + ++ print_if ppf Clflags.dump_rawlambda Printlambda.lambda + ++ Simplif.simplify_lambda + ++ print_if ppf Clflags.dump_lambda Printlambda.lambda + ++ Bytegen.compile_implementation modulename + ++ print_if ppf Clflags.dump_instr Printinstr.instrlist + ++ Emitcode.to_file oc modulename; + Warnings.check_fatal (); + close_out oc; + Pparse.remove_preprocessed inputfile; + Stypes.dump (outputprefix ^ ".annot"); + with x -> + close_out oc; + remove_file objfile; + Pparse.remove_preprocessed_if_ast inputfile; + Stypes.dump (outputprefix ^ ".annot"); + raise x + end + +let c_file name = + Location.input_name := name; + if Ccomp.compile_file name <> 0 then exit 2 diff --git a/driver/compile.mli b/driver/compile.mli new file mode 100644 index 0000000..954085f --- /dev/null +++ b/driver/compile.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compile.mli,v 1.8 2004-06-13 12:46:41 xleroy Exp $ *) + +(* Compile a .ml or .mli file *) + +open Format + +val interface: formatter -> string -> string -> unit +val implementation: formatter -> string -> string -> unit +val c_file: string -> unit + +val initial_env: unit -> Env.t +val init_path: unit -> unit diff --git a/driver/errors.ml b/driver/errors.ml new file mode 100644 index 0000000..ab92ee7 --- /dev/null +++ b/driver/errors.ml @@ -0,0 +1,81 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: errors.ml,v 1.27 2007-12-04 13:38:58 doligez Exp $ *) + +(* WARNING: if you change something in this file, you must look at + opterrors.ml and ocamldoc/odoc_analyse.ml + to see if you need to make the same changes there. +*) + +open Format + +(* Report an error *) + +let report_error ppf exn = + let report ppf = function + | Lexer.Error(err, loc) -> + Location.print_error ppf loc; + Lexer.report_error ppf err + | Syntaxerr.Error err -> + Syntaxerr.report_error ppf err + | Pparse.Error -> + Location.print_error_cur_file ppf; + fprintf ppf "Preprocessor error" + | Env.Error err -> + Location.print_error_cur_file ppf; + Env.report_error ppf err + | Ctype.Tags(l, l') -> + Location.print_error_cur_file ppf; + fprintf ppf + "In this program,@ variant constructors@ `%s and `%s@ \ + have the same hash value.@ Change one of them." l l' + | Typecore.Error(loc, err) -> + Location.print_error ppf loc; Typecore.report_error ppf err + | Typetexp.Error(loc, err) -> + Location.print_error ppf loc; Typetexp.report_error ppf err + | Typedecl.Error(loc, err) -> + Location.print_error ppf loc; Typedecl.report_error ppf err + | Typeclass.Error(loc, err) -> + Location.print_error ppf loc; Typeclass.report_error ppf err + | Includemod.Error err -> + Location.print_error_cur_file ppf; + Includemod.report_error ppf err + | Typemod.Error(loc, err) -> + Location.print_error ppf loc; Typemod.report_error ppf err + | Translcore.Error(loc, err) -> + Location.print_error ppf loc; Translcore.report_error ppf err + | Translclass.Error(loc, err) -> + Location.print_error ppf loc; Translclass.report_error ppf err + | Translmod.Error(loc, err) -> + Location.print_error ppf loc; Translmod.report_error ppf err + | Symtable.Error code -> + Location.print_error_cur_file ppf; + Symtable.report_error ppf code + | Bytelink.Error code -> + Location.print_error_cur_file ppf; + Bytelink.report_error ppf code + | Bytelibrarian.Error code -> + Location.print_error_cur_file ppf; + Bytelibrarian.report_error ppf code + | Bytepackager.Error code -> + Location.print_error_cur_file ppf; + Bytepackager.report_error ppf code + | Sys_error msg -> + Location.print_error_cur_file ppf; + fprintf ppf "I/O error: %s" msg + | Warnings.Errors (n) -> + Location.print_error_cur_file ppf; + fprintf ppf "Error-enabled warnings (%d occurrences)" n + | x -> fprintf ppf "@]"; raise x in + + fprintf ppf "@[%a@]@." report exn diff --git a/driver/errors.mli b/driver/errors.mli new file mode 100644 index 0000000..f803140 --- /dev/null +++ b/driver/errors.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: errors.mli,v 1.5 2000-03-06 22:11:31 weis Exp $ *) + +(* Error report *) +open Format + +val report_error: formatter -> exn -> unit diff --git a/driver/main.ml b/driver/main.ml new file mode 100644 index 0000000..034bea5 --- /dev/null +++ b/driver/main.ml @@ -0,0 +1,196 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.ml,v 1.72 2008-12-03 18:09:09 doligez Exp $ *) + +open Config +open Clflags + +let output_prefix name = + let oname = + match !output_name with + | None -> name + | Some n -> if !compile_only then (output_name := None; n) else name in + Misc.chop_extension_if_any oname + +let process_interface_file ppf name = + Compile.interface ppf name (output_prefix name) + +let process_implementation_file ppf name = + let opref = output_prefix name in + Compile.implementation ppf name opref; + objfiles := (opref ^ ".cmo") :: !objfiles + +let process_file ppf name = + if Filename.check_suffix name ".ml" + || Filename.check_suffix name ".mlt" then begin + let opref = output_prefix name in + Compile.implementation ppf name opref; + objfiles := (opref ^ ".cmo") :: !objfiles + end + else if Filename.check_suffix name !Config.interface_suffix then begin + let opref = output_prefix name in + Compile.interface ppf name opref; + if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles + end + else if Filename.check_suffix name ".cmo" + || Filename.check_suffix name ".cma" then + objfiles := name :: !objfiles + else if Filename.check_suffix name ".cmi" && !make_package then + objfiles := name :: !objfiles + else if Filename.check_suffix name ext_obj + || Filename.check_suffix name ext_lib then + ccobjs := name :: !ccobjs + else if Filename.check_suffix name ext_dll then + dllibs := name :: !dllibs + else if Filename.check_suffix name ".c" then begin + Compile.c_file name; + ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj) + :: !ccobjs + end + else + raise(Arg.Bad("don't know what to do with " ^ name)) + +let print_version_and_library () = + print_string "The Objective Caml compiler, version "; + print_string Config.version; print_newline(); + print_string "Standard library directory: "; + print_string Config.standard_library; print_newline(); + exit 0 + +let print_version_string () = + print_string Config.version; print_newline(); exit 0 + +let print_standard_library () = + print_string Config.standard_library; print_newline(); exit 0 + +let usage = "Usage: ocamlc \nOptions are:" + +(* Error messages to standard error formatter *) +let anonymous = process_file Format.err_formatter;; +let impl = process_implementation_file Format.err_formatter;; +let intf = process_interface_file Format.err_formatter;; + +let show_config () = + Config.print_config stdout; + exit 0; +;; + +module Options = Main_args.Make_options (struct + let set r () = r := true + let unset r () = r := false + let _a = set make_archive + let _annot = set annotations + let _c = set compile_only + let _cc s = c_compiler := Some s + let _cclib s = ccobjs := Misc.rev_split_words s @ !ccobjs + let _ccopt s = ccopts := s :: !ccopts + let _config = show_config + let _custom = set custom_runtime + let _dllib s = dllibs := Misc.rev_split_words s @ !dllibs + let _dllpath s = dllpaths := !dllpaths @ [s] + let _g = set debug + let _i () = print_types := true; compile_only := true + let _I s = include_dirs := s :: !include_dirs + let _impl = impl + let _intf = intf + let _intf_suffix s = Config.interface_suffix := s + let _labels = unset classic + let _linkall = set link_everything + let _make_runtime () = + custom_runtime := true; make_runtime := true; link_everything := true + let _noassert = set noassert + let _nolabels = set classic + let _noautolink = set no_auto_link + let _nostdlib = set no_std_include + let _o s = output_name := Some s + let _output_obj () = output_c_object := true; custom_runtime := true + let _pack = set make_package + let _pp s = preprocessor := Some s + let _principal = set principal + let _rectypes = set recursive_types + let _thread = set use_threads + let _vmthread = set use_vmthreads + let _unsafe = set fast + let _use_prims s = use_prims := s + let _use_runtime s = use_runtime := s + let _v = print_version_and_library + let _version = print_version_string + let _w = (Warnings.parse_options false) + let _warn_error = (Warnings.parse_options true) + let _where = print_standard_library + let _verbose = set verbose + let _nopervasives = set nopervasives + let _dparsetree = set dump_parsetree + let _drawlambda = set dump_rawlambda + let _dlambda = set dump_lambda + let _dinstr = set dump_instr + let anonymous = anonymous +end) + +let fatal err = + prerr_endline err; + exit 2 + +let extract_output = function + | Some s -> s + | None -> fatal "Please specify the name of the output file, using option -o" + +let default_output = function + | Some s -> s + | None -> Config.default_executable_name + +let main () = + try + Arg.parse Options.list anonymous usage; + if + List.length (List.filter (fun x -> !x) + [make_archive;make_package;compile_only;output_c_object]) > 1 + then + fatal "Please specify at most one of -pack, -a, -c, -output-obj"; + + if !make_archive then begin + Compile.init_path(); + Bytelibrarian.create_archive (List.rev !objfiles) + (extract_output !output_name) + end + else if !make_package then begin + Compile.init_path(); + Bytepackager.package_files (List.rev !objfiles) + (extract_output !output_name) + end + else if not !compile_only && !objfiles <> [] then begin + let target = + if !output_c_object then + let s = extract_output !output_name in + if (Filename.check_suffix s Config.ext_obj + || Filename.check_suffix s Config.ext_dll + || Filename.check_suffix s ".c") + then s + else + fatal + (Printf.sprintf + "The extension of the output file must be .c, %s or %s" + Config.ext_obj Config.ext_dll + ) + else + default_output !output_name + in + Compile.init_path(); + Bytelink.link (List.rev !objfiles) target + end; + exit 0 + with x -> + Errors.report_error Format.err_formatter x; + exit 2 + +let _ = main () diff --git a/driver/main.mli b/driver/main.mli new file mode 100644 index 0000000..8c8b439 --- /dev/null +++ b/driver/main.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.mli,v 1.1 2000-01-07 16:03:04 doligez Exp $ *) + +(* + this "empty" file is here to speed up garbage collection in ocamlc.opt +*) diff --git a/driver/main_args.ml b/driver/main_args.ml new file mode 100644 index 0000000..b6cb9c0 --- /dev/null +++ b/driver/main_args.ml @@ -0,0 +1,166 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main_args.ml,v 1.50 2007-05-16 08:21:40 doligez Exp $ *) + +module Make_options (F : + sig + val _a : unit -> unit + val _annot : unit -> unit + val _c : unit -> unit + val _cc : string -> unit + val _cclib : string -> unit + val _ccopt : string -> unit + val _config : unit -> unit + val _custom : unit -> unit + val _dllib : string -> unit + val _dllpath : string -> unit + val _g : unit -> unit + val _i : unit -> unit + val _I : string -> unit + val _impl : string -> unit + val _intf : string -> unit + val _intf_suffix : string -> unit + val _labels : unit -> unit + val _linkall : unit -> unit + val _make_runtime : unit -> unit + val _noassert : unit -> unit + val _noautolink : unit -> unit + val _nolabels : unit -> unit + val _nostdlib : unit -> unit + val _o : string -> unit + val _output_obj : unit -> unit + val _pack : unit -> unit + val _pp : string -> unit + val _principal : unit -> unit + val _rectypes : unit -> unit + val _thread : unit -> unit + val _vmthread : unit -> unit + val _unsafe : unit -> unit + val _use_prims : string -> unit + val _use_runtime : string -> unit + val _v : unit -> unit + val _version : unit -> unit + val _verbose : unit -> unit + val _w : string -> unit + val _warn_error : string -> unit + val _where : unit -> unit + + val _nopervasives : unit -> unit + val _dparsetree : unit -> unit + val _drawlambda : unit -> unit + val _dlambda : unit -> unit + val _dinstr : unit -> unit + val anonymous : string -> unit + end) = +struct + let list = [ + "-a", Arg.Unit F._a, " Build a library"; + "-annot", Arg.Unit F._annot, " Save information in .annot"; + "-c", Arg.Unit F._c, " Compile only (do not link)"; + "-cc", Arg.String F._cc, + " Use as the C compiler and linker"; + "-cclib", Arg.String F._cclib, " Pass option to the C linker"; + "-ccopt", Arg.String F._ccopt, + " Pass option to the C compiler and linker"; + "-config", Arg.Unit F._config, + " print configuration values and exit"; + "-custom", Arg.Unit F._custom, " Link in custom mode"; + "-dllib", Arg.String F._dllib, + " Use the dynamically-loaded library "; + "-dllpath", Arg.String F._dllpath, + " Add to the run-time search path for shared libraries"; + "-dtypes", Arg.Unit F._annot, " (deprecated) same as -annot"; + "-for-pack", Arg.String (fun s -> ()), + " Ignored (for compatibility with ocamlopt)"; + "-g", Arg.Unit F._g, " Save debugging information"; + "-i", Arg.Unit F._i, " Print inferred interface"; + "-I", Arg.String F._I, + " Add to the list of include directories"; + "-impl", Arg.String F._impl, " Compile as a .ml file"; + "-intf", Arg.String F._intf, " Compile as a .mli file"; + "-intf-suffix", Arg.String F._intf_suffix, + " Suffix for interface files (default: .mli)"; + "-intf_suffix", Arg.String F._intf_suffix, + " (deprecated) same as -intf-suffix"; + "-labels", Arg.Unit F._labels, " Use commuting label mode"; + "-linkall", Arg.Unit F._linkall, " Link all modules, even unused ones"; + "-make-runtime", Arg.Unit F._make_runtime, + " Build a runtime system with given C objects and libraries"; + "-make_runtime", Arg.Unit F._make_runtime, + " (deprecated) same as -make-runtime"; + "-modern", Arg.Unit F._labels, " (deprecated) same as -labels"; + "-noassert", Arg.Unit F._noassert, " Don't compile assertion checks"; + "-noautolink", Arg.Unit F._noautolink, + " Don't automatically link C libraries specified in .cma files"; + "-nolabels", Arg.Unit F._nolabels, " Ignore non-optional labels in types"; + "-nostdlib", Arg.Unit F._nostdlib, + " do not add default directory to the list of include directories"; + "-o", Arg.String F._o, " Set output file name to "; + "-output-obj", Arg.Unit F._output_obj, + " Output a C object file instead of an executable"; + "-pack", Arg.Unit F._pack, + " Package the given .cmo files into one .cmo"; + "-pp", Arg.String F._pp, + " Pipe sources through preprocessor "; + "-principal", Arg.Unit F._principal, + " Check principality of type inference"; + "-rectypes", Arg.Unit F._rectypes, " Allow arbitrary recursive types"; + "-thread", Arg.Unit F._thread, + " Generate code that supports the system threads library"; + "-unsafe", Arg.Unit F._unsafe, + " No bounds checking on array and string access"; + "-use-runtime", Arg.String F._use_runtime, + " Generate bytecode for the given runtime system"; + "-use_runtime", Arg.String F._use_runtime, + " (deprecated) same as -use-runtime"; + "-v", Arg.Unit F._v, + " Print compiler version and location of standard library and exit"; + "-version", Arg.Unit F._version, " Print compiler version and exit"; + "-verbose", Arg.Unit F._verbose, " Print calls to external commands"; + "-vmthread", Arg.Unit F._vmthread, + " Generate code that supports the threads library with VM-level\n\ + \ scheduling"; + "-w", Arg.String F._w, + " Enable or disable warnings according to :\n\ + \032 C/c enable/disable suspicious comment\n\ + \032 D/d enable/disable deprecated features\n\ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ + \032 M/m enable/disable overriden methods\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ + \032 V/v enable/disable overriden instance variables\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ + \032 A/a enable/disable all warnings\n\ + \032 default setting is \"Aelz\""; + "-warn-error" , Arg.String F._warn_error, + " Treat the warnings of as errors, if they are\n\ + \ enabled. See option -w for the list of flags.\n\ + \ Default setting is \"a\" (warnings are not errors)"; + "-where", Arg.Unit F._where, + " Print location of standard library and exit"; + "-nopervasives", Arg.Unit F._nopervasives, " (undocumented)"; + "-dparsetree", Arg.Unit F._dparsetree, " (undocumented)"; + "-drawlambda", Arg.Unit F._drawlambda, " (undocumented)"; + "-dlambda", Arg.Unit F._dlambda, " (undocumented)"; + "-dinstr", Arg.Unit F._dinstr, " (undocumented)"; + "-use-prims", Arg.String F._use_prims, " (undocumented)"; + + "-", Arg.String F.anonymous, + " Treat as a file name (even if it starts with `-')"; + ] +end;; diff --git a/driver/main_args.mli b/driver/main_args.mli new file mode 100644 index 0000000..48aae4b --- /dev/null +++ b/driver/main_args.mli @@ -0,0 +1,67 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main_args.mli,v 1.27 2007-05-16 08:21:40 doligez Exp $ *) + +module Make_options (F : + sig + val _a : unit -> unit + val _annot : unit -> unit + val _c : unit -> unit + val _cc : string -> unit + val _cclib : string -> unit + val _ccopt : string -> unit + val _config : unit -> unit + val _custom : unit -> unit + val _dllib : string -> unit + val _dllpath : string -> unit + val _g : unit -> unit + val _i : unit -> unit + val _I : string -> unit + val _impl : string -> unit + val _intf : string -> unit + val _intf_suffix : string -> unit + val _labels : unit -> unit + val _linkall : unit -> unit + val _make_runtime : unit -> unit + val _noassert : unit -> unit + val _noautolink : unit -> unit + val _nolabels : unit -> unit + val _nostdlib : unit -> unit + val _o : string -> unit + val _output_obj : unit -> unit + val _pack : unit -> unit + val _pp : string -> unit + val _principal : unit -> unit + val _rectypes : unit -> unit + val _thread : unit -> unit + val _vmthread : unit -> unit + val _unsafe : unit -> unit + val _use_prims : string -> unit + val _use_runtime : string -> unit + val _v : unit -> unit + val _version : unit -> unit + val _verbose : unit -> unit + val _w : string -> unit + val _warn_error : string -> unit + val _where : unit -> unit + + val _nopervasives : unit -> unit + val _dparsetree : unit -> unit + val _drawlambda : unit -> unit + val _dlambda : unit -> unit + val _dinstr : unit -> unit + val anonymous : string -> unit + end) : + sig + val list : (string * Arg.spec * string) list + end diff --git a/driver/ocamlcomp.sh.in b/driver/ocamlcomp.sh.in new file mode 100644 index 0000000..2aeb2de --- /dev/null +++ b/driver/ocamlcomp.sh.in @@ -0,0 +1,5 @@ +#!/bin/sh + +topdir=`dirname $0` + +exec @compiler@ -nostdlib -I $topdir/stdlib "$@" diff --git a/driver/optcompile.ml b/driver/optcompile.ml new file mode 100644 index 0000000..c8baf14 --- /dev/null +++ b/driver/optcompile.ml @@ -0,0 +1,147 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: optcompile.ml,v 1.58 2008-12-03 18:09:09 doligez Exp $ *) + +(* The batch compiler *) + +open Misc +open Config +open Format +open Typedtree + +(* Initialize the search path. + The current directory is always searched first, + then the directories specified with the -I option (in command-line order), + then the standard library directory. *) + +let init_path () = + let dirs = + if !Clflags.use_threads + then "+threads" :: !Clflags.include_dirs + else !Clflags.include_dirs in + let exp_dirs = + List.map (expand_directory Config.standard_library) dirs in + load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ()); + Env.reset_cache () + +(* Return the initial environment in which compilation proceeds. *) + +let initial_env () = + Ident.reinit(); + try + if !Clflags.nopervasives + then Env.initial + else Env.open_pers_signature "Pervasives" Env.initial + with Not_found -> + fatal_error "cannot open pervasives.cmi" + +(* Note: this function is duplicated in compile.ml *) +let check_unit_name ppf filename name = + try + begin match name.[0] with + | 'A'..'Z' -> () + | _ -> + Location.print_warning (Location.in_file filename) ppf + (Warnings.Bad_module_name name); + raise Exit; + end; + for i = 1 to String.length name - 1 do + match name.[i] with + | 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '\'' -> () + | _ -> + Location.print_warning (Location.in_file filename) ppf + (Warnings.Bad_module_name name); + raise Exit; + done; + with Exit -> () +;; + +(* Compile a .mli file *) + +let interface ppf sourcefile outputprefix = + Location.input_name := sourcefile; + init_path (); + let modulename = + String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in + check_unit_name ppf sourcefile modulename; + Env.set_unit_name modulename; + let inputfile = Pparse.preprocess sourcefile in + try + let ast = + Pparse.file ppf inputfile Parse.interface ast_intf_magic_number in + if !Clflags.dump_parsetree then fprintf ppf "%a@." Printast.interface ast; + let sg = Typemod.transl_signature (initial_env()) ast in + if !Clflags.print_types then + fprintf std_formatter "%a@." Printtyp.signature + (Typemod.simplify_signature sg); + Warnings.check_fatal (); + if not !Clflags.print_types then + Env.save_signature sg modulename (outputprefix ^ ".cmi"); + Pparse.remove_preprocessed inputfile; + Stypes.dump (outputprefix ^ ".annot"); + with e -> + Pparse.remove_preprocessed_if_ast inputfile; + Stypes.dump (outputprefix ^ ".annot"); + raise e + +(* Compile a .ml file *) + +let print_if ppf flag printer arg = + if !flag then fprintf ppf "%a@." printer arg; + arg + +let (++) x f = f x +let (+++) (x, y) f = (x, f y) + +let implementation ppf sourcefile outputprefix = + Location.input_name := sourcefile; + init_path (); + let modulename = + String.capitalize(Filename.basename(chop_extension_if_any sourcefile)) in + check_unit_name ppf sourcefile modulename; + Env.set_unit_name modulename; + let inputfile = Pparse.preprocess sourcefile in + let env = initial_env() in + Compilenv.reset ?packname:!Clflags.for_package modulename; + let cmxfile = outputprefix ^ ".cmx" in + let objfile = outputprefix ^ ext_obj in + try + if !Clflags.print_types then ignore( + Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number + ++ print_if ppf Clflags.dump_parsetree Printast.implementation + ++ Unused_var.warn ppf + ++ Typemod.type_implementation sourcefile outputprefix modulename env) + else begin + Pparse.file ppf inputfile Parse.implementation ast_impl_magic_number + ++ print_if ppf Clflags.dump_parsetree Printast.implementation + ++ Unused_var.warn ppf + ++ Typemod.type_implementation sourcefile outputprefix modulename env + ++ Translmod.transl_store_implementation modulename + +++ print_if ppf Clflags.dump_rawlambda Printlambda.lambda + +++ Simplif.simplify_lambda + +++ print_if ppf Clflags.dump_lambda Printlambda.lambda + ++ Asmgen.compile_implementation outputprefix ppf; + Compilenv.save_unit_info cmxfile; + end; + Warnings.check_fatal (); + Pparse.remove_preprocessed inputfile; + Stypes.dump (outputprefix ^ ".annot"); + with x -> + remove_file objfile; + remove_file cmxfile; + Pparse.remove_preprocessed_if_ast inputfile; + Stypes.dump (outputprefix ^ ".annot"); + raise x + +let c_file name = + if Ccomp.compile_file name <> 0 then exit 2 diff --git a/driver/optcompile.mli b/driver/optcompile.mli new file mode 100644 index 0000000..c8b9973 --- /dev/null +++ b/driver/optcompile.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: optcompile.mli,v 1.8 2004-06-13 12:46:41 xleroy Exp $ *) + +(* Compile a .ml or .mli file *) + +open Format + +val interface: formatter -> string -> string -> unit +val implementation: formatter -> string -> string -> unit +val c_file: string -> unit + +val initial_env: unit -> Env.t +val init_path: unit -> unit diff --git a/driver/opterrors.ml b/driver/opterrors.ml new file mode 100644 index 0000000..847db82 --- /dev/null +++ b/driver/opterrors.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opterrors.ml,v 1.20 2007-12-04 13:38:58 doligez Exp $ *) + +(* WARNING: if you change something in this file, you must look at + errors.ml to see if you need to make the same changes there. +*) + +open Format + +(* Report an error *) + +let report_error ppf exn = + let report ppf = function + | Lexer.Error(err, l) -> + Location.print_error ppf l; + Lexer.report_error ppf err + | Syntaxerr.Error err -> + Syntaxerr.report_error ppf err + | Pparse.Error -> + Location.print_error_cur_file ppf; + fprintf ppf "Preprocessor error" + | Env.Error err -> + Location.print_error_cur_file ppf; + Env.report_error ppf err + | Ctype.Tags(l, l') -> + Location.print_error_cur_file ppf; + fprintf ppf + "In this program,@ variant constructors@ `%s and `%s@ \ + have the same hash value.@ Change one of them." l l' + | Typecore.Error(loc, err) -> + Location.print_error ppf loc; Typecore.report_error ppf err + | Typetexp.Error(loc, err) -> + Location.print_error ppf loc; Typetexp.report_error ppf err + | Typedecl.Error(loc, err) -> + Location.print_error ppf loc; Typedecl.report_error ppf err + | Typeclass.Error(loc, err) -> + Location.print_error ppf loc; Typeclass.report_error ppf err + | Includemod.Error err -> + Location.print_error_cur_file ppf; + Includemod.report_error ppf err + | Typemod.Error(loc, err) -> + Location.print_error ppf loc; Typemod.report_error ppf err + | Translcore.Error(loc, err) -> + Location.print_error ppf loc; Translcore.report_error ppf err + | Translclass.Error(loc, err) -> + Location.print_error ppf loc; Translclass.report_error ppf err + | Translmod.Error(loc, err) -> + Location.print_error ppf loc; Translmod.report_error ppf err + | Compilenv.Error code -> + Location.print_error_cur_file ppf; + Compilenv.report_error ppf code + | Asmgen.Error code -> + Location.print_error_cur_file ppf; + Asmgen.report_error ppf code + | Asmlink.Error code -> + Location.print_error_cur_file ppf; + Asmlink.report_error ppf code + | Asmlibrarian.Error code -> + Location.print_error_cur_file ppf; + Asmlibrarian.report_error ppf code + | Asmpackager.Error code -> + Location.print_error_cur_file ppf; + Asmpackager.report_error ppf code + | Sys_error msg -> + Location.print_error_cur_file ppf; + fprintf ppf "I/O error: %s" msg + | Warnings.Errors (n) -> + Location.print_error_cur_file ppf; + fprintf ppf "Error-enabled warnings (%d occurrences)" n + | x -> fprintf ppf "@]"; raise x in + + fprintf ppf "@[%a@]@." report exn diff --git a/driver/opterrors.mli b/driver/opterrors.mli new file mode 100644 index 0000000..bf442df --- /dev/null +++ b/driver/opterrors.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opterrors.mli,v 1.5 2000-03-07 05:02:32 garrigue Exp $ *) + +(* Error report *) + +val report_error: Format.formatter -> exn -> unit diff --git a/driver/optmain.ml b/driver/optmain.ml new file mode 100644 index 0000000..6c31aad --- /dev/null +++ b/driver/optmain.ml @@ -0,0 +1,260 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: optmain.ml,v 1.99 2008-12-03 18:09:09 doligez Exp $ *) + +open Config +open Clflags + +let output_prefix name = + let oname = + match !output_name with + | None -> name + | Some n -> if !compile_only then (output_name := None; n) else name in + Misc.chop_extension_if_any oname + +let process_interface_file ppf name = + Optcompile.interface ppf name (output_prefix name) + +let process_implementation_file ppf name = + let opref = output_prefix name in + Optcompile.implementation ppf name opref; + objfiles := (opref ^ ".cmx") :: !objfiles + +let process_file ppf name = + if Filename.check_suffix name ".ml" + || Filename.check_suffix name ".mlt" then + process_implementation_file ppf name + else if Filename.check_suffix name !Config.interface_suffix then begin + let opref = output_prefix name in + Optcompile.interface ppf name opref; + if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles + end + else if Filename.check_suffix name ".cmx" + || Filename.check_suffix name ".cmxa" then + objfiles := name :: !objfiles + else if Filename.check_suffix name ".cmi" && !make_package then + objfiles := name :: !objfiles + else if Filename.check_suffix name ext_obj + || Filename.check_suffix name ext_lib then + ccobjs := name :: !ccobjs + else if Filename.check_suffix name ".c" then begin + Optcompile.c_file name; + ccobjs := (Filename.chop_suffix (Filename.basename name) ".c" ^ ext_obj) + :: !ccobjs + end + else + raise(Arg.Bad("don't know what to do with " ^ name)) + +let print_version_and_library () = + print_string "The Objective Caml native-code compiler, version "; + print_string Config.version; print_newline(); + print_string "Standard library directory: "; + print_string Config.standard_library; print_newline(); + exit 0 + +let print_version_string () = + print_string Config.version; print_newline(); exit 0 + +let print_standard_library () = + print_string Config.standard_library; print_newline(); exit 0 + +let fatal err = + prerr_endline err; + exit 2 + +let extract_output = function + | Some s -> s + | None -> + fatal "Please specify the name of the output file, using option -o" + +let default_output = function + | Some s -> s + | None -> Config.default_executable_name + +let usage = "Usage: ocamlopt \nOptions are:" + +let show_config () = + Config.print_config stdout; + exit 0; +;; + +let main () = + native_code := true; + let ppf = Format.err_formatter in + try + Arg.parse (Arch.command_line_options @ [ + "-a", Arg.Set make_archive, " Build a library"; + "-annot", Arg.Set annotations, + " Save information in .annot"; + "-c", Arg.Set compile_only, " Compile only (do not link)"; + "-cc", Arg.String(fun s -> c_compiler := Some s), + " Use as the C compiler and linker"; + "-cclib", Arg.String(fun s -> + ccobjs := Misc.rev_split_words s @ !ccobjs), + " Pass option to the C linker"; + "-ccopt", Arg.String(fun s -> ccopts := s :: !ccopts), + " Pass option to the C compiler and linker"; + "-compact", Arg.Clear optimize_for_speed, + " Optimize code size rather than speed"; + "-config", Arg.Unit show_config, + " print configuration values and exit"; + "-dtypes", Arg.Set annotations, + " (deprecated) same as -annot"; + "-for-pack", Arg.String (fun s -> for_package := Some s), + " Generate code that can later be `packed' with\n\ + \ ocamlopt -pack -o .cmx"; + "-g", Arg.Set debug, + " Record debugging information for exception backtrace"; + "-i", Arg.Unit (fun () -> print_types := true; compile_only := true), + " Print inferred interface"; + "-I", Arg.String(fun dir -> include_dirs := dir :: !include_dirs), + " Add to the list of include directories"; + "-impl", Arg.String (process_implementation_file ppf), + " Compile as a .ml file"; + "-inline", Arg.Int(fun n -> inline_threshold := n * 8), + " Set aggressiveness of inlining to "; + "-intf", Arg.String (process_interface_file ppf), + " Compile as a .mli file"; + "-intf-suffix", Arg.String (fun s -> Config.interface_suffix := s), + " Suffix for interface files (default: .mli)"; + "-intf_suffix", Arg.String (fun s -> Config.interface_suffix := s), + " (deprecated) same as -intf-suffix"; + "-labels", Arg.Clear classic, " Use commuting label mode"; + "-linkall", Arg.Set link_everything, + " Link all modules, even unused ones"; + "-noassert", Arg.Set noassert, " Don't compile assertion checks"; + "-noautolink", Arg.Set no_auto_link, + " Don't automatically link C libraries specified in .cmxa files"; + "-nodynlink", Arg.Clear dlcode, + " Enable optimizations for code that will not be dynlinked"; + "-nolabels", Arg.Set classic, " Ignore non-optional labels in types"; + "-nostdlib", Arg.Set no_std_include, + " do not add standard directory to the list of include directories"; + "-o", Arg.String(fun s -> output_name := Some s), + " Set output file name to "; + "-output-obj", Arg.Unit(fun () -> output_c_object := true), + " Output a C object file instead of an executable"; + "-p", Arg.Set gprofile, + " Compile and link with profiling support for \"gprof\"\n\ + \ (not supported on all platforms)"; + "-pack", Arg.Set make_package, + " Package the given .cmx files into one .cmx"; + "-pp", Arg.String(fun s -> preprocessor := Some s), + " Pipe sources through preprocessor "; + "-principal", Arg.Set principal, + " Check principality of type inference"; + "-rectypes", Arg.Set recursive_types, + " Allow arbitrary recursive types"; + "-shared", Arg.Unit (fun () -> shared := true; dlcode := true), + " Produce a dynlinkable plugin"; + "-S", Arg.Set keep_asm_file, " Keep intermediate assembly file"; + "-thread", Arg.Set use_threads, + " Generate code that supports the system threads library"; + "-unsafe", Arg.Set fast, + " No bounds checking on array and string access"; + "-v", Arg.Unit print_version_and_library, + " Print compiler version and standard library location and exit"; + "-version", Arg.Unit print_version_string, + " Print compiler version and exit"; + "-verbose", Arg.Set verbose, " Print calls to external commands"; + "-w", Arg.String (Warnings.parse_options false), + " Enable or disable warnings according to :\n\ + \032 C/c enable/disable suspicious comment\n\ + \032 D/d enable/disable deprecated features\n\ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ + \032 M/m enable/disable overriden methods\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ + \032 V/v enable/disable overriden instance variables\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ + \032 A/a enable/disable all warnings\n\ + \032 default setting is \"Aelz\""; + "-warn-error" , Arg.String (Warnings.parse_options true), + " Treat the warnings of as errors, if they are\n\ + \ enabled. See option -w for the list of flags.\n\ + \ Default setting is \"a\" (warnings are not errors)"; + "-where", Arg.Unit print_standard_library, + " Print location of standard library and exit"; + + "-nopervasives", Arg.Set nopervasives, " (undocumented)"; + "-dparsetree", Arg.Set dump_parsetree, " (undocumented)"; + "-drawlambda", Arg.Set dump_rawlambda, " (undocumented)"; + "-dlambda", Arg.Set dump_lambda, " (undocumented)"; + "-dcmm", Arg.Set dump_cmm, " (undocumented)"; + "-dsel", Arg.Set dump_selection, " (undocumented)"; + "-dcombine", Arg.Set dump_combine, " (undocumented)"; + "-dlive", Arg.Unit(fun () -> dump_live := true; + Printmach.print_live := true), + " (undocumented)"; + "-dspill", Arg.Set dump_spill, " (undocumented)"; + "-dsplit", Arg.Set dump_split, " (undocumented)"; + "-dinterf", Arg.Set dump_interf, " (undocumented)"; + "-dprefer", Arg.Set dump_prefer, " (undocumented)"; + "-dalloc", Arg.Set dump_regalloc, " (undocumented)"; + "-dreload", Arg.Set dump_reload, " (undocumented)"; + "-dscheduling", Arg.Set dump_scheduling, " (undocumented)"; + "-dlinear", Arg.Set dump_linear, " (undocumented)"; + "-dstartup", Arg.Set keep_startup_file, " (undocumented)"; + "-", Arg.String (process_file ppf), + " Treat as a file name (even if it starts with `-')" + ]) (process_file ppf) usage; + if + List.length (List.filter (fun x -> !x) + [make_archive;make_package;shared;compile_only;output_c_object]) > 1 + then + fatal "Please specify at most one of -pack, -a, -shared, -c, -output-obj"; + if !make_archive then begin + Optcompile.init_path(); + let target = extract_output !output_name in + Asmlibrarian.create_archive (List.rev !objfiles) target; + end + else if !make_package then begin + Optcompile.init_path(); + let target = extract_output !output_name in + Asmpackager.package_files ppf (List.rev !objfiles) target; + end + else if !shared then begin + Optcompile.init_path(); + let target = extract_output !output_name in + Asmlink.link_shared ppf (List.rev !objfiles) target; + end + else if not !compile_only && !objfiles <> [] then begin + let target = + if !output_c_object then + let s = extract_output !output_name in + if (Filename.check_suffix s Config.ext_obj + || Filename.check_suffix s Config.ext_dll) + then s + else + fatal + (Printf.sprintf + "The extension of the output file must be %s or %s" + Config.ext_obj Config.ext_dll + ) + else + default_output !output_name + in + Optcompile.init_path(); + Asmlink.link ppf (List.rev !objfiles) target + end; + exit 0 + with x -> + Opterrors.report_error ppf x; + exit 2 + +let _ = main () diff --git a/driver/optmain.mli b/driver/optmain.mli new file mode 100644 index 0000000..c087a3a --- /dev/null +++ b/driver/optmain.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: optmain.mli,v 1.1 2000-01-07 16:03:04 doligez Exp $ *) + +(* + this "empty" file is here to speed up garbage collection in ocamlopt.opt +*) diff --git a/driver/pparse.ml b/driver/pparse.ml new file mode 100644 index 0000000..ae4d9d2 --- /dev/null +++ b/driver/pparse.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pparse.ml,v 1.3 2004-06-16 16:58:46 doligez Exp $ *) + +open Format + +exception Error + +(* Optionally preprocess a source file *) + +let preprocess sourcefile = + match !Clflags.preprocessor with + None -> sourcefile + | Some pp -> + let tmpfile = Filename.temp_file "camlpp" "" in + let comm = Printf.sprintf "%s %s > %s" + pp (Filename.quote sourcefile) tmpfile + in + if Ccomp.command comm <> 0 then begin + Misc.remove_file tmpfile; + raise Error; + end; + tmpfile + +let remove_preprocessed inputfile = + match !Clflags.preprocessor with + None -> () + | Some _ -> Misc.remove_file inputfile + +let remove_preprocessed_if_ast inputfile = + match !Clflags.preprocessor with + None -> () + | Some _ -> + if inputfile <> !Location.input_name then Misc.remove_file inputfile + +(* Parse a file or get a dumped syntax tree in it *) + +exception Outdated_version + +let file ppf inputfile parse_fun ast_magic = + let ic = open_in_bin inputfile in + let is_ast_file = + try + let buffer = String.create (String.length ast_magic) in + really_input ic buffer 0 (String.length ast_magic); + if buffer = ast_magic then true + else if String.sub buffer 0 9 = String.sub ast_magic 0 9 then + raise Outdated_version + else false + with + Outdated_version -> + Misc.fatal_error "Ocaml and preprocessor have incompatible versions" + | _ -> false + in + let ast = + try + if is_ast_file then begin + if !Clflags.fast then + fprintf ppf "@[Warning: %s@]@." + "option -unsafe used with a preprocessor returning a syntax tree"; + Location.input_name := input_value ic; + input_value ic + end else begin + seek_in ic 0; + Location.input_name := inputfile; + let lexbuf = Lexing.from_channel ic in + Location.init lexbuf inputfile; + parse_fun lexbuf + end + with x -> close_in ic; raise x + in + close_in ic; + ast diff --git a/driver/pparse.mli b/driver/pparse.mli new file mode 100644 index 0000000..21e42d1 --- /dev/null +++ b/driver/pparse.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: pparse.mli,v 1.1 2002-02-08 10:14:31 ddr Exp $ *) + +open Format + +exception Error + +val preprocess : string -> string +val remove_preprocessed : string -> unit +val remove_preprocessed_if_ast : string -> unit +val file : formatter -> string -> (Lexing.lexbuf -> 'a) -> string -> 'a diff --git a/emacs/.cvsignore b/emacs/.cvsignore new file mode 100644 index 0000000..e7e261f --- /dev/null +++ b/emacs/.cvsignore @@ -0,0 +1,2 @@ +ocamltags + diff --git a/emacs/COPYING b/emacs/COPYING new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/emacs/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/emacs/Makefile b/emacs/Makefile new file mode 100644 index 0000000..3652c14 --- /dev/null +++ b/emacs/Makefile @@ -0,0 +1,76 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1997 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU General Public License. # +# # +######################################################################### + +# $Id: Makefile,v 1.17 2004-08-20 17:04:35 doligez Exp $ + +include ../config/Makefile + +# Files to install +FILES= caml-font.el caml-hilit.el caml.el camldebug.el \ + inf-caml.el caml-compat.el caml-help.el caml-types.el \ + caml-xemacs.el caml-emacs.el + +# Where to install. If empty, automatically determined. +#EMACSDIR= + +# Name of Emacs executable +EMACS=emacs + +# Where to install ocamltags script +SCRIPTDIR = $(BINDIR) + +# Command for byte-compiling the files +COMPILECMD=(progn \ + (setq load-path (cons "." load-path)) \ + (byte-compile-file "caml-xemacs.el") \ + (byte-compile-file "caml-emacs.el") \ + (byte-compile-file "caml.el") \ + (byte-compile-file "inf-caml.el") \ + (byte-compile-file "caml-help.el") \ + (byte-compile-file "caml-types.el") \ + (byte-compile-file "camldebug.el")) + +install: + @if test "$(EMACSDIR)" = ""; then \ + set xxx `($(EMACS) --batch --eval "(mapcar 'print load-path)") \ + 2>/dev/null | \ + sed -n -e '/\/site-lisp/s/"//gp'`; \ + if test "$$2" = ""; then \ + echo "Cannot determine Emacs site-lisp directory"; \ + exit 2; \ + fi; \ + $(MAKE) EMACSDIR="$$2" simple-install; \ + else \ + $(MAKE) simple-install; \ + fi + +# install the .el files, but do not compile them. +install-el: + $(MAKE) NOCOMPILE=true install + +simple-install: + @echo "Installing in $(EMACSDIR)..." + if test -d $(EMACSDIR); then : ; else mkdir -p $(EMACSDIR); fi + cp $(FILES) $(EMACSDIR) + if [ -z "$(NOCOMPILE)" ]; then \ + cd $(EMACSDIR); $(EMACS) --batch --eval '$(COMPILECMD)'; \ + fi + +ocamltags: ocamltags.in + sed -e 's:@EMACS@:$(EMACS):' ocamltags.in >ocamltags + chmod a+x ocamltags + +install-ocamltags: ocamltags + cp ocamltags $(SCRIPTDIR)/ocamltags + +clean: + rm -f ocamltags *~ #*# diff --git a/emacs/README b/emacs/README new file mode 100644 index 0000000..def69d3 --- /dev/null +++ b/emacs/README @@ -0,0 +1,206 @@ + O'Caml emacs mode, snapshot of $Date: 2008-01-11 16:13:16 $ + +The files in this archive define a caml-mode for emacs, for editing +Objective Caml and Objective Label programs, as well as an +inferior-caml-mode, to run a toplevel. + +Caml-mode supports indentation, compilation and error retrieving, +sending phrases to the toplevel. Moreover support for hilit, +font-lock and imenu was added. + +This package is based on the original caml-mode for caml-light by +Xavier Leroy, extended with indentation by Ian Zimmerman. For details +see README.itz, which is the README from Ian Zimmerman's package. + +To use it, just put the .el files in your path, and add the following +three lines in your .emacs. + + (setq auto-mode-alist + (cons '("\\.ml[iylp]?$" . caml-mode) auto-mode-alist)) + (autoload 'caml-mode "caml" "Major mode for editing Caml code." t) + (autoload 'run-caml "inf-caml" "Run an inferior Caml process." t) + +I added camldebug.el from the original distribution, since there will +soon be a debugger for Objective Caml, but I do not know enough about +it. + +To install the mode itself, edit the Makefile and do + + % make install + +To install ocamltags, do + + % make install-ocamltags + +To use highlighting capabilities, add ONE of the following two lines +to your .emacs. The second one works better on recent versions of +emacs. + + (if window-system (require 'caml-hilit)) + (if window-system (require 'caml-font)) + +caml.el and inf-caml.el can be used collectively, but it might be a +good idea to copy caml-hilit.el or caml-font.el to you own directory, +and edit it to your taste and colors. + +Main key bindings: + +TAB indent current line +M-C-q indent phrase +M-C-h mark phrase +C-c C-a switch between interface and implementation +C-c C-c compile (usually make) +C-x` goto next error (also mouse button 2 in the compilation log) + +Once you have started caml by M-x run-caml: + +M-C-x send phrase to inferior caml process +C-c C-r send region to inferior caml process +C-c C-s show inferior caml process +C-c` goto error in expression sent by M-C-x + +For other bindings, see C-h b. + +Changes log: +----------- +Version 3.10.1: +--------------- +* use caml-font.el from Olivier Andrieu + old version is left as caml-font-old.el for compatibility + +Version 3.07: +------------- +* support for showing type information + +Version 3.05: +------------- +* improved interaction with inferior caml mode + +* access help from the source + +* fixes in indentation code + +Version 3.03: +------------- +* process ;; properly + +Version 3.00: +------------- +* adapt to new label syntax + +* intelligent indentation of parenthesis + +Version 2.02: +------------- +* improved ocamltags + +* added support for multibyte characters in emacs 20 + +Version 2.01+: +-------------- +* corrected a bug in caml-font.el + +* corrected abbreviations and added ocamltags script + +Version 2.01: +------------ +* code for interactive errors added by ITZ + +Version 2.00: +------------ +* changed the algorithm to skip comments + +* adapted for the new object syntax + +Version 1.07: +------------ +* next-error bug fix by John Malecki + +* camldebug.el modified by Xavier Leroy + +Version 1.06: +------------ +* new keywords in O'Caml 1.06 + +* compatibility with GNU Emacs 20 + +* changed from caml-imenu-disable to caml-imenu-enable (off by default) + +Version 1.05: +------------ +* a few indentation bugs corrected. let, val ... are now indented + correctly even when you write them at the beginning of a line. + +* added a Caml menu, and Imenu support. Imenu menu can be disabled + by setting the variable caml-imenu-disable to t. + Xemacs support for the Menu, but no Imenu. + +* key bindings closer to lisp-mode. + +* O'Labl compatibility (":" is part of words) may be switched off by + setting caml-olabl-disable to t. + +* camldebug.el was updated by Xavier Leroy. + +Version 1.03b: +------------- +* many bugs corrected. + +* (partial) compatibility with Caml-Light added. + (setq caml-quote-char "`") + (setq inferior-caml-program "camllight") + Literals will be correctly understood and highlighted. However, + indentation rules are still Objective Caml's: this just happens to + work well in most cases, but is only intended for occasional use. + +* as many people asked for it, application is now indented. This seems + to work well: this time differences in indentation between the + compiler's source and this mode are really exceptionnal. On the + other hand, you may think that some special cases are strange. No + miracle. + +* nicer behaviour when sending a phrase/region to the inferior caml + process. + +Version 1.03: +------------ +* support of Objective Caml and Objective Label. + +* an indentation very close to mine, which happens to be the same as + Xavier's, since the sources of the Objective Caml compiler do not + change if you indent them in this mode. + +* highlighting. + +Some remarks about the style supported: +-------------------------------------- + +Since Objective Caml's syntax is very liberal (more than 100 +shift-reduce conflicts with yacc), automatic indentation is far from +easy. Moreover, you expect the indentation to be not purely syntactic, +but also semantic: reflecting the meaning of your program. + +This mode tries to be intelligent. For instance some operators are +indented differently in the middle and at the end of a line (thanks to +Ian Zimmerman). Also, we do not indent after if .. then .. else, when +else is on the same line, to reflect that this idiom is equivalent to +a return instruction in a more imperative language, or after the in of +let .. in, since you may see that as an assignment. + +However, you may want to use a different indentation style. This is +made partly possible by a number of variables at the beginning of +caml.el. Try to set them. However this only changes the size of +indentations, not really the look of your program. This is enough to +disable the two idioms above, but to do anything more you will have to +edit the code... Enjoy! + +This mode does not force you to put ;; in your program. This means +that we had to use a heuristic to decide where a phrase starts and +stops, to speed up the code. A phrase starts when any of the keywords +let, type, class, module, functor, exception, val, external, appears +at the beginning of a line. Using the first column for such keywords +in other cases may confuse the phrase selection function. + +Comments and bug reports to + + Jacques Garrigue diff --git a/emacs/README.itz b/emacs/README.itz new file mode 100644 index 0000000..8e1366f --- /dev/null +++ b/emacs/README.itz @@ -0,0 +1,177 @@ +DESCRIPTION: + +This directory contains files to help editing Caml code, running a +Caml toplevel, and running the Caml debugger under the Gnu Emacs editor. + +AUTHORS: + +Ian T Zimmerman added indentation to caml mode, beefed +up camldebug to work much like gud/gdb. + +Xavier Leroy (Xavier.Leroy@inria.fr), Jerome Vouillon (Jerome.Vouillon@ens.fr). +camldebug.el is derived from FSF code. + +CONTENTS: + + caml.el A major mode for editing Caml code in Gnu Emacs + inf-caml.el To run a Caml toplevel under Emacs, with input and + output in an Emacs buffer. + camldebug.el To run the Caml debugger under Emacs. + + +NOTE FOR EMACS 18 USERS: + +This package will no longer work with Emacs 18.x. Sorry. You really +should consider upgrading to Emacs 19. + +USAGE: + +Add the following lines to your .emacs file: + +(setq auto-mode-alist (cons '("\\.ml[iylp]?" . caml-mode) auto-mode-alist)) +(autoload 'caml-mode "caml" "Major mode for editing Caml code." t) +(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t) +(autoload 'camldebug "camldebug" "Run the Caml debugger." t) + +The Caml major mode is triggered by visiting a file with extension .ml, +.mli, .mly. .mll or .mlp, or manually by M-x caml-mode. It gives you the +correct syntax table for the Caml language. For a brief description of +the indentation capabilities, see below under NEWS. + +The Caml mode also allows you to run batch Caml compilations from +Emacs (using M-x compile) and browse the errors (C-x `). Typing C-x ` +sets the point at the beginning of the erroneous program fragment, and +the mark at the end. Under Emacs 19, the program fragment is +temporarily highlighted. + +M-x run-caml starts a Caml toplevel with input and output in an Emacs +buffer named *inferior-caml*. This gives you the full power of Emacs +to edit the input to the Caml toplevel. This mode is based on comint +so you get all the usual comint features, including command history. + +After M-x run-caml, typing C-c C-e or M-C-x in a buffer in Caml mode +sends the current phrase (containing the point) to the Caml toplevel, +and evaluates it. + +M-x camldebug FILE starts the Caml debugger camldebug on the executable +FILE, with input and output in an Emacs buffer named *camldebug-FILE*. +For a brief description of the commands available in this buffer, see +NEWS below. + +NEWS: + +Ok, so this is the really important part of this file :-) I took the +original package from the contrib subdirectory of the caml-light +distribution, and hacked on it. First, I added real syntax dependent +indentation to caml mode. Like Xavier has said, it was hard (and I +knew it would be), but I refused to believe it was impossible, partly +because I knew of a Standard ML mode with indentation (written by +Matthew Morley). + +Indentation works pretty much like in other programming modes. C-j at +the end of a line starts a new line properly indented. M-C-\ indents +the current region (this may take a while :-)). I incorporated a +slightly different TAB function, one that I use in other modes: if TAB +is pressed while the point is not in line indentation, the line is +indented to the column where point is (instead of just inserting a TAB +character - you can always to that with C-q C-i). This way, you can +indent a line any time, regardless of where the point lies, by hitting +TAB twice in succession. If you don't like this behaviour (but you +should), it's quite easy to add to your startup code like this: + +(defun caml-old-style-indent () + (if (caml-in-indentation) + (caml-indent-command) + (insert "\t"))) + +(add-hook 'caml-mode-hook + (function (lambda () + (define-key 'caml-mode-map "\t" + caml-old-style-indent)))) + +You can customize the appearance of your caml code by twiddling the +variables listed at the start of caml.el. Good luck. :-) + +Other news in caml mode are the various caml-insert-*-form commands. I +believe they are self-explanatory - just do a C-h m in a caml buffer +to see what you've got. + +The ohter major news is that I changed camldebug mode considerably. I +took many clues from the gud "Grand Unified Debugger" mode distributed +with modern versions of Emacs. The main benefit here is that you can +do debugger commands _from your caml source buffer_. Commands with the +C-c prefix in the debugger buffer have counterparts which do the same +thing (well, a similar thing) in the source buffer, with the C-x C-a +prefix. + +I made the existing debugger commands smarter in that they now attempt +to guess the correct parameter to the underlying camldebug command. A +numeric argument will always override that guess. For example, the +guess for C-c C-b (camldebug-break) is to set a breakpoint at the +current event (which was the only behaviour provided with the old +camldebug.el). But C-u 1 C-c C-b will now send "break 1" to the +camldebug process, setting a break at code address 1. + +This also allowed me to add many more commands for which the +underlying camldebug commands require a parameter. The best way to +learn about them is to do C-h m in the camldebug buffer, and then C-h +f for the commands you'll see listed. + +Finally, I added command completion. To use it, you'll have to apply +the provided patch to the debugger itself +(contrib/debugger/command_line_interpreter.ml), and recompile it +(you'll get one warning from the compiler; it is safe to ignore +it). Then hitting TAB in the following situation, for example: + +(cdb) pri_ + +will complete the "pri" to "print". + +CAVEATS: + +I don't use X and haven't tested this stuff under the X mode of +emacs. It is entirely possible (though not very probable) that I +introduced some undesirable interaction between X (fontification, +highlighting,...) and caml mode. I will welcome reports of such +problems (see REPORTING below), but I won't be able to do much about +them unless you also provide a patch. + +I don't know if the informational messages produced by camldebug are +internationalized. If they are, the debugger mode won't work unless +you set the language to English. The mode uses the messages to +synchronize with camldebug, and looks for fixed Emacs regular +expressions that match them. This may be fixed (if necessary) in a +future release. + +BUGS: + +In the debugger buffer, it's possible to overflow your mental stack by +asking for help on help on help on help on help on help on help on +help... + +THANKS: + +Xavier Leroy for Caml-light. Used together with the +Emacs interface, it is about the most pleasant programming environment +I've known on any platform. + +Eric Raymond for gud, which camldebug mode apes. + +Barry Warsaw for elp, without which I wouldn't have +been able to get the indentation code to perform acceptably. + +Gareth Rees for suggestions how to speed up +Emacs regular expression search, even if I didn't use them in the end. + +Bill Dubuque for alerting me to the +necessity of guarding against C-g inside Emacs code which modifies +syntax tables. + +REPORTING: + +Bug reports (preferably with patches), suggestions, donations etc. to: + +Ian T Zimmerman +-------------------------------------------+ +Box 13445 I With so many executioners available, I +Berkeley CA 94712 USA I suicide is a really foolish thing to do. I +mailto:itz@rahul.net +-------------------------------------------+ diff --git a/emacs/caml-compat.el b/emacs/caml-compat.el new file mode 100644 index 0000000..4e69d07 --- /dev/null +++ b/emacs/caml-compat.el @@ -0,0 +1,42 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +;(* *) +;(* Copyright 1998 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-compat.el,v 1.3 2004-08-20 17:04:35 doligez Exp $ *) + +;; function definitions for old versions of emacs + +;; indent-line-to + +(if (not (fboundp 'indent-line-to)) + (defun indent-line-to (column) + "Indent current line to COLUMN. + +This function removes or adds spaces and tabs at beginning of line +only if necessary. It leaves point at end of indentation." + (if (= (current-indentation) column) + (back-to-indentation) + (beginning-of-line 1) + (delete-horizontal-space) + (indent-to column)))) + +;; buffer-substring-no-properties + +(cond + ((fboundp 'buffer-substring-no-properties)) + ((fboundp 'buffer-substring-without-properties) + (defalias 'buffer-substring-no-properties + 'buffer-substring-without-properties)) + (t + (defalias 'buffer-substring-no-properties 'buffer-substring))) + +(provide 'caml-compat) + diff --git a/emacs/caml-emacs.el b/emacs/caml-emacs.el new file mode 100644 index 0000000..6c894b3 --- /dev/null +++ b/emacs/caml-emacs.el @@ -0,0 +1,43 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Didier Remy, projet Cristal, INRIA Rocquencourt *) +;(* *) +;(* Copyright 2003 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-emacs.el,v 1.7 2004-08-20 17:04:35 doligez Exp $ *) + +;; for caml-help.el +(defalias 'caml-info-other-window 'info-other-window) + +;; for caml-types.el + +(defalias 'caml-line-beginning-position 'line-beginning-position) + +(defalias 'caml-read-event 'read-event) +(defalias 'caml-window-edges 'window-edges) +(defun caml-mouse-vertical-position () + (cddr (mouse-position))) +(defalias 'caml-ignore-event-p 'integer-or-marker-p) +(defalias 'caml-mouse-movement-p 'mouse-movement-p) +(defalias 'caml-sit-for 'sit-for) + +(defmacro caml-track-mouse (&rest body) (cons 'track-mouse body)) + +(defun caml-event-window (e) (posn-window (event-start e))) +(defun caml-event-point-start (e) (posn-point (event-start e))) +(defun caml-event-point-end (e) (posn-point (event-end e))) + +(defun caml-release-event-p (original event) + (and (equal (event-basic-type original) (event-basic-type event)) + (let ((modifiers (event-modifiers event))) + (or (member 'drag modifiers) + (member 'click modifiers))))) + + +(provide 'caml-emacs) diff --git a/emacs/caml-font-old.el b/emacs/caml-font-old.el new file mode 100644 index 0000000..554f271 --- /dev/null +++ b/emacs/caml-font-old.el @@ -0,0 +1,141 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Jacques Garrigue and Ian T Zimmerman *) +;(* *) +;(* Copyright 1997 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-font-old.el,v 1.2 2008-01-11 16:13:16 doligez Exp $ *) + +;; useful colors + +(cond + ((x-display-color-p) + (require 'font-lock) + (cond + ((not (boundp 'font-lock-type-face)) + ; make the necessary faces + (make-face 'Firebrick) + (set-face-foreground 'Firebrick "Firebrick") + (make-face 'RosyBrown) + (set-face-foreground 'RosyBrown "RosyBrown") + (make-face 'Purple) + (set-face-foreground 'Purple "Purple") + (make-face 'MidnightBlue) + (set-face-foreground 'MidnightBlue "MidnightBlue") + (make-face 'DarkGoldenRod) + (set-face-foreground 'DarkGoldenRod "DarkGoldenRod") + (make-face 'DarkOliveGreen) + (set-face-foreground 'DarkOliveGreen "DarkOliveGreen4") + (make-face 'CadetBlue) + (set-face-foreground 'CadetBlue "CadetBlue") + ; assign them as standard faces + (setq font-lock-comment-face 'Firebrick) + (setq font-lock-string-face 'RosyBrown) + (setq font-lock-keyword-face 'Purple) + (setq font-lock-function-name-face 'MidnightBlue) + (setq font-lock-variable-name-face 'DarkGoldenRod) + (setq font-lock-type-face 'DarkOliveGreen) + (setq font-lock-reference-face 'CadetBlue))) + ; extra faces for documention + (make-face 'Stop) + (set-face-foreground 'Stop "White") + (set-face-background 'Stop "Red") + (make-face 'Doc) + (set-face-foreground 'Doc "Red") + (setq font-lock-stop-face 'Stop) + (setq font-lock-doccomment-face 'Doc) +)) + +; The same definition is in caml.el: +; we don't know in which order they will be loaded. +(defvar caml-quote-char "'" + "*Quote for character constants. \"'\" for Objective Caml, \"`\" for Caml-Light.") + +(defconst caml-font-lock-keywords + (list +;stop special comments + '("\\(^\\|[^\"]\\)\\((\\*\\*/\\*\\*)\\)" + 2 font-lock-stop-face) +;doccomments + '("\\(^\\|[^\"]\\)\\((\\*\\*[^*]*\\([^)*][^*]*\\*+\\)*)\\)" + 2 font-lock-doccomment-face) +;comments + '("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)" + 2 font-lock-comment-face) +;character literals + (cons (concat caml-quote-char "\\(\\\\\\([ntbr" caml-quote-char "\\]\\|" + "[0-9][0-9][0-9]\\)\\|.\\)" caml-quote-char + "\\|\"[^\"\\]*\\(\\\\\\(.\\|\n\\)[^\"\\]*\\)*\"") + 'font-lock-string-face) +;modules and constructors + '("`?\\<[A-Z][A-Za-z0-9_']*\\>" . font-lock-function-name-face) +;definition + (cons (concat + "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)" + "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?" + "\\|in\\(herit\\|itializer\\)?\\|let" + "\\|m\\(ethod\\|utable\\|odule\\)" + "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type" + "\\|v\\(al\\|irtual\\)\\)\\>") + 'font-lock-type-face) +;blocking + '("\\<\\(begin\\|end\\|object\\|s\\(ig\\|truct\\)\\)\\>" + . font-lock-keyword-face) +;control + (cons (concat + "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)" + "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)" + "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>" + "\\|\|\\|->\\|&\\|#") + 'font-lock-reference-face) + '("\\" . font-lock-comment-face) +;labels (and open) + '("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" 1 + font-lock-variable-name-face) + '("\\<\\(assert\\|open\\|include\\)\\>\\|[~?][ (]*[a-z][a-zA-Z0-9_']*" + . font-lock-variable-name-face))) + +(defconst inferior-caml-font-lock-keywords + (append + (list +;inferior + '("^[#-]" . font-lock-comment-face)) + caml-font-lock-keywords)) + +;; font-lock commands are similar for caml-mode and inferior-caml-mode +(defun caml-mode-font-hook () + (cond + ((fboundp 'global-font-lock-mode) + (make-local-variable 'font-lock-defaults) + (setq font-lock-defaults + '(caml-font-lock-keywords nil nil ((?' . "w") (?_ . "w"))))) + (t + (setq font-lock-keywords caml-font-lock-keywords))) + (make-local-variable 'font-lock-keywords-only) + (setq font-lock-keywords-only t) + (font-lock-mode 1)) + +(add-hook 'caml-mode-hook 'caml-mode-font-hook) + +(defun inferior-caml-mode-font-hook () + (cond + ((fboundp 'global-font-lock-mode) + (make-local-variable 'font-lock-defaults) + (setq font-lock-defaults + '(inferior-caml-font-lock-keywords + nil nil ((?' . "w") (?_ . "w"))))) + (t + (setq font-lock-keywords inferior-caml-font-lock-keywords))) + (make-local-variable 'font-lock-keywords-only) + (setq font-lock-keywords-only t) + (font-lock-mode 1)) + +(add-hook 'inferior-caml-mode-hooks 'inferior-caml-mode-font-hook) + +(provide 'caml-font) diff --git a/emacs/caml-font.el b/emacs/caml-font.el new file mode 100644 index 0000000..e796abd --- /dev/null +++ b/emacs/caml-font.el @@ -0,0 +1,114 @@ +;; caml-font: font-lock support for OCaml files +;; +;; rewrite and clean-up. +;; Changes: +;; - fontify strings and comments using syntactic font lock +;; - define a `font-lock-syntactic-face-function' to fontify ocamldoc comments +;; - fontify infix operators like mod, land, lsl, etc. +;; - fontify line number directives +;; - fontify "failwith" and "invalid_arg" like "raise" +;; - fontify '\x..' character constants +;; - use the regexp-opt function to build regexps (more readable) +;; - use backquote and comma in sexp (more readable) +;; - drop the `caml-quote-char' variable (I don't use caml-light :)) +;; - stop doing weird things with faces + + +(require 'font-lock) + +(defvar caml-font-stop-face + (progn + (make-face 'caml-font-stop-face) + (set-face-foreground 'caml-font-stop-face "White") + (set-face-background 'caml-font-stop-face "Red") + 'caml-font-stop-face)) + +(defvar caml-font-doccomment-face + (progn + (make-face 'caml-font-doccomment-face) + (set-face-foreground 'caml-font-doccomment-face "Red") + 'caml-font-doccomment-face)) + +(unless (facep 'font-lock-preprocessor-face) + (defvar font-lock-preprocessor-face + (copy-face 'font-lock-builtin-face + 'font-lock-preprocessor-face))) + +(defconst caml-font-lock-keywords + `( +;character literals + ("'\\(.\\|\\\\\\([ntbr\"'\\\\]\\|[0-9]\\{3\\}\\|x[0-9A-Fa-f]\\{2\\}\\)\\)'" + . font-lock-string-face) +;modules and constructors + ("`?\\<[A-Z][A-Za-z0-9_']*\\>" . font-lock-function-name-face) +;definition + (,(regexp-opt '("and" "as" "constraint" "class" + "exception" "external" "fun" "function" "functor" + "in" "inherit" "initializer" "let" + "method" "mutable" "module" "of" "private" "rec" + "type" "val" "virtual") + 'words) + . font-lock-type-face) +;blocking + (,(regexp-opt '("begin" "end" "object" "sig" "struct") 'words) + . font-lock-keyword-face) +;linenums + ("# *[0-9]+" . font-lock-preprocessor-face) +;infix operators + (,(regexp-opt '("asr" "land" "lor" "lsl" "lsr" "lxor" "mod") 'words) + . font-lock-builtin-face) +;control + (,(concat "[|#&]\\|->\\|" + (regexp-opt '("do" "done" "dowto" "else" "for" "if" "ignore" + "lazy" "match" "new" "or" "then" "to" "try" + "when" "while" "with") + 'words)) + . font-lock-constant-face) + ("\\" + . font-lock-comment-face) +;labels (and open) + ("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" + 1 font-lock-variable-name-face) + ("\\<\\(assert\\|open\\|include\\)\\>\\|[~?][ (]*[a-z][a-zA-Z0-9_']*" + . font-lock-variable-name-face))) + + +(defun caml-font-syntactic-face (s) + (let ((in-string (nth 3 s)) + (in-comment (nth 4 s)) + (start (nth 8 s))) + (cond + (in-string 'font-lock-string-face) + (in-comment + (save-excursion + (goto-char start) + (cond + ((looking-at "(\\*\\*/\\*\\*)") 'caml-font-stop-face) + ((looking-at "(\\*\\*[^*]") 'caml-font-doccomment-face) + (t 'font-lock-comment-face))))))) + + +;; font-lock commands are similar for caml-mode and inferior-caml-mode +(defun caml-font-set-font-lock () + (setq font-lock-defaults + '(caml-font-lock-keywords + nil nil nil nil + (font-lock-syntactic-face-function . caml-font-syntactic-face))) + (font-lock-mode 1)) +(add-hook 'caml-mode-hook 'caml-font-set-font-lock) + + + +(defconst inferior-caml-font-lock-keywords + `(("^[#-]" . font-lock-comment-face) + ,@caml-font-lock-keywords)) + +(defun inferior-caml-set-font-lock () + (setq font-lock-defaults + '(inferior-caml-font-lock-keywords + nil nil nil nil + (font-lock-syntactic-face-function . caml-font-syntactic-face))) + (font-lock-mode 1)) +(add-hook 'inferior-caml-mode-hooks 'inferior-caml-set-font-lock) + +(provide 'caml-font) diff --git a/emacs/caml-help.el b/emacs/caml-help.el new file mode 100644 index 0000000..f652a13 --- /dev/null +++ b/emacs/caml-help.el @@ -0,0 +1,829 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Didier Remy, projet Cristal, INRIA Rocquencourt *) +;(* *) +;(* Copyright 2001 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-help.el,v 1.17 2004-08-20 17:04:35 doligez Exp $ *) + +;; caml-info.el --- contextual completion and help to caml-mode + +;; Didier Remy, November 2001. + +;; This provides two functions completion and help +;; look for caml-complete and caml-help + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; This is a preliminary version. +;; +;; Possible improvements? +;; - dump some databaes: Info, Lib, ... +;; - accept a search path for local libraries instead of current dir +;; (then distinguish between different modules lying in different +;; directories) +;; - improve the construction for info files. +;; +;; Abstract over +;; - the viewing method and the database, so that the documentation for +;; and identifier could be search in +;; * info / html / man / mli's sources +;; * viewed in emacs or using an external previewer. +;; +;; Take all identifiers (labels, Constructors, exceptions, etc.) +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +(eval-and-compile + (if (and (boundp 'running-xemacs) running-xemacs) + (require 'caml-xemacs) + (require 'caml-emacs))) + +;; Loading or building databases. +;; + +;; variables to be customized + +(defvar ocaml-lib-path 'lazy + "Path list for ocaml lib sources (mli files) + +'lazy means ask ocaml to find it for your at first use.") +(defun ocaml-lib-path () + "Computes if necessary and returns the path for ocaml libs" + (if (listp ocaml-lib-path) nil + (setq ocaml-lib-path + (split-string + (shell-command-to-string + (or + (and (boundp 'inferior-caml-program) + (string-match "\\([^ ]*/ocaml\\)\\( \\|$\\)" + inferior-caml-program) + (let ((file + (concat (match-string 1 inferior-caml-program) + "c"))) + (and (file-executable-p file) + (concat file " -where")))) + "ocamlc -where"))))) + ocaml-lib-path) + + + +;; General purpose auxiliary functions + +(defun ocaml-capitalize (s) + (concat (capitalize (substring s 0 1)) (substring s 1))) + +(defun ocaml-uncapitalize (s) + (if (> (length s) 0) + (concat (downcase (substring s 0 1)) (substring s 1)) + s)) + +(defun iter (f l) (while (consp l) (apply f (list (car l))) (setq l (cdr l)))) + +(defun ocaml-find-files (path filter &optional depth split) + (let* ((path-string + (if (stringp path) + (if (file-directory-p path) path nil) + (mapconcat '(lambda (d) (if (file-directory-p d) d)) + path " "))) + (command + (and path-string + (concat "find " path-string + " '(' " filter " ')' " + (if depth (concat " -maxdepth " (int-to-string depth))) + (if split nil " -printf '%\p '") + ))) + (files + (and command (shell-command-to-string command)))) + (if (and split (stringp files)) (split-string files "\n") files) + )) + +;; Specialized auxiliary functions + + +;; Global table of modules contents of modules loaded lazily. + +(defvar ocaml-module-alist 'lazy + "A-list of modules with how and where to find help information. + 'delay means non computed yet") + +(defun ocaml-add-mli-modules (modules tag &optional path) + (let ((files + (ocaml-find-files (or path (ocaml-lib-path)) + "-type f -name '*.mli'" 1 t))) + (while (consp files) + (if (string-match "\\([^/]*\\).mli" (car files)) + (let* ((module (ocaml-capitalize (match-string 1 (car files)))) + (dir (file-name-directory (car files))) + (dirp (member dir (ocaml-lib-path)))) + (if (and (consp dirp) (string-equal dir (car dirp))) + (setq dir (car dirp))) + (if (assoc module modules) nil + (setq modules + (cons (cons module (cons (cons tag dir) 'lazy)) modules)) + ))) + (setq files (cdr files))) + modules)) + +(defun ocaml-add-path (dir &optional path) + "Extend ocaml-module-alist with modules of DIR relative to PATH" + (interactive "D") + (let* ((old (ocaml-lib-path)) + (new + (if (file-name-absolute-p dir) dir + (concat + (or (find-if '(lambda (p) (file-directory-p (concat p "/" dir))) + (cons default-directory old)) + (error "Directory not found")) + "/" dir)))) + (setq ocaml-lib-path (cons (car old) (cons new (cdr old)))) + (setq ocaml-module-alist + (ocaml-add-mli-modules (ocaml-module-alist) 'lib new)))) + +(defun ocaml-module-alist () + "Call by need value of variable ocaml-module-alist" + (if (listp ocaml-module-alist) + nil + ;; build list of mli files + (setq ocaml-module-alist (ocaml-add-mli-modules nil 'lib)) + ;; dumping information ? TODO + ) + ocaml-module-alist) + +(defun ocaml-get-or-make-module (module &optional tag) + (let ((info (assoc module (ocaml-module-alist)))) + (if info nil + (setq info (cons module (cons (cons 'local default-directory) 'lazy))) + (setq ocaml-module-alist (cons info ocaml-module-alist)) + ) + info)) + +;; Symbols of module are lazily computed + +(defun ocaml-module-filename (module) + (let ((module (ocaml-uncapitalize module)) (name)) + (if (file-exists-p (setq name (concat module ".mli"))) nil + (let ((tmp (ocaml-lib-path))) + (while (consp tmp) + (setq name (concat (car tmp) "/" module ".mli")) + (if (file-exists-p name) (setq tmp nil) + (setq name nil))))) + name)) + +(defun ocaml-module-symbols (module-info) + (let* ((module (car module-info)) + (tail (and module-info (cdr module-info))) + (tag (caar tail)) + (dir (cdar tail)) + (file) + (alist)) + (if (listp (cdr tail)) + (cdr tail) + (if (equal tag 'info) + (setq dir (car ocaml-lib-path)) ; XXX to be fixed + ) + (setq file (concat dir "/" (ocaml-uncapitalize module) ".mli")) + (message file) + (save-window-excursion + (set-buffer (get-buffer-create "*caml-help*")) + (if (and file (file-exists-p file)) + (progn + (message "Scanning module %s" file) + (insert-file-contents file)) + (message "Module %s not found" module)) + (while (re-search-forward + "\\([ \t]*val\\|let\\|external\\| [|]\\) \\([a-zA-Z_0-9'][a-zA-Z_0-9']*\\)\\|^ *[{]* \\([a-z_][A-Za-z_0-9]*\\) : [^;\n][^;\n]*;" + (point-max) 'move) + (pop-to-buffer (current-buffer)) + (setq alist (cons (or (match-string 2) (match-string 3)) alist))) + (erase-buffer) + ) + (setcdr tail alist) + alist) + )) + +;; Local list of visible modules. + +(defvar ocaml-visible-modules 'lazy + "A-list of open modules, local to every file.") +(make-variable-buffer-local 'ocaml-visible-modules) +(defun ocaml-visible-modules () + (if (listp ocaml-visible-modules) nil + (progn + (setq ocaml-visible-modules + (list (ocaml-get-or-make-module "Pervasives"))) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^ *open *\\([A-Z][a-zA-Z'_0-9]*\\)" + (point-max) t) + (let ((module (match-string 1))) + (if (assoc module ocaml-visible-modules) nil + (setq ocaml-visible-modules + (cons (ocaml-get-or-make-module module) + ocaml-visible-modules))))) + ))) + ocaml-visible-modules) + +(defun ocaml-open-module (arg) + "*Make module of name ARG visible whe ARG is a string. +When call interactively, make completion over known modules." + (interactive "P") + (if (not (stringp arg)) + (let ((modules (ocaml-module-alist))) + (setq arg + (completing-read "Open module: " modules)))) + (if (and (stringp arg) (not (equal arg ""))) + (progn + (if (assoc arg (ocaml-visible-modules)) + (ocaml-close-module arg)) + (setq ocaml-visible-modules + (cons (ocaml-get-or-make-module arg) (ocaml-visible-modules))) + )) + (message "%S" (mapcar 'car (ocaml-visible-modules)))) + +(defun ocaml-close-module (arg) + "*Close module of name ARG when ARG is a string. +When call interactively, make completion over visible modules. +Otherwise if ARG is true, close all modules and reset to default. " + (interactive "P") + (if (= (prefix-numeric-value arg) 4) + (setq ocaml-visible-modules 'lazy) + (let* ((modules (ocaml-visible-modules))) + (if (null modules) (error "No visible module to close")) + (unless (stringp arg) + (setq arg + (completing-read + (concat "Close module [" (caar modules) "] : ") + modules)) + (if (equal arg "") (setq arg (caar modules)))) + (setq ocaml-visible-modules + (remove-if '(lambda (m) (equal (car m) arg)) + ocaml-visible-modules)) + )) + (message "%S" (mapcar 'car (ocaml-visible-modules)))) + + +;; Look for identifiers around point + +(defun ocaml-qualified-identifier (&optional show) + "Search for a qualified identifier (Path. entry) around point. + +Entry may be nil. +Currently, the path may only be nil or a single Module. +For paths is of the form Module.Path', it returns Module +and always nil for entry. + +If defined Module and Entry are represented by a region in the buffer, +and are nil otherwise. + +For debugging purposes, it returns the string Module.entry if called +with an optional non-nil argument. +" + (save-excursion + (let ((module) (entry)) + (if (looking-at "[ \n]") (skip-chars-backward " ")) + (if (re-search-backward + "\\([^A-Za-z0-9_.']\\|\\`\\)\\([A-Za-z0-9_']*[.]\\)*[A-Za-z0-9_']*\\=" + (- (point) 100) t) + (progn + (or (looking-at "\\`[A-Za-z)-9_.]") (forward-char 1)) + (if (looking-at "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)[.]") + (progn + (setq module (cons (match-beginning 1) (match-end 1))) + (goto-char (match-end 0)))) + (if (looking-at "\\<\\([A-Za-z_][A-Za-z0-9_']*\\)\\>") + (setq entry (cons (match-beginning 1) (match-end 1)))))) + (if show + (concat + (and module (buffer-substring (car module) (cdr module))) + "." + (and entry (buffer-substring (car entry) (cdr entry)))) + (cons module entry)) + ))) + +;; completion around point + +(defun ocaml-completion (pattern module) + (let ((list + (or + (and module + (list + (or (assoc module (ocaml-module-alist)) + (error "Unknown module %s" module)))) + (ocaml-visible-modules)))) + (message "Completion from %s" (mapconcat 'car list " ")) + (if (null pattern) + (apply 'append (mapcar 'ocaml-module-symbols list)) + (let ((pat (concat "^" (regexp-quote pattern))) (res)) + (iter + '(lambda (l) + (iter '(lambda (x) + (if (string-match pat (car l)) + (if (member x res) nil (setq res (cons x res))))) + (ocaml-module-symbols l))) + list) + res) + ))) + +(defun caml-complete (arg) + "Does completion for OCaml identifiers qualified. + +It attemps to recognize an qualified identifier Module . entry +around point using function \\[ocaml-qualified-identifier]. + +If Module is defined, it does completion for identifier in Module. + +If Module is undefined, it does completion in visible modules. +Then, if completion fails, it does completion among all modules +where identifier is defined." + (interactive "p") + (let* ((module-entry (ocaml-qualified-identifier)) (entry) + (module) + (beg) (end) (pattern)) + (if (car module-entry) + (progn + (setq module + (buffer-substring (caar module-entry) (cdar module-entry))) + (or (assoc module (ocaml-module-alist)) + (and (setq module + (completing-read "Module: " (ocaml-module-alist) + nil nil module)) + (save-excursion + (goto-char (caar module-entry)) + (delete-region (caar module-entry) (cdar module-entry)) + (insert module) t) + (setq module-entry (ocaml-qualified-identifier)) + (car module-entry) + (progn (setq entry (cdr module-entry)) t)) + (error "Unknown module %s" module)))) + (if (consp (cdr module-entry)) + (progn + (setq beg (cadr module-entry)) + (setq end (cddr module-entry))) + (if (and module + (save-excursion + (goto-char (cdar module-entry)) + (looking-at " *[.]"))) + (progn + (setq beg (match-end 0)) + (setq end beg)))) + (if (not (and beg end)) + (error "Did not find anything to complete around point") + + (setq pattern (buffer-substring beg end)) + (let* ((all-completions (ocaml-completion pattern module)) + (completion + (try-completion pattern (mapcar 'list all-completions)))) + (cond ((eq completion t)) + + ((null completion) + (let* + ((modules (ocaml-find-module pattern)) + (visible (intersection modules (ocaml-visible-modules))) + (hist) + (module + (cond + ((null modules) + nil) + ((equal (length modules) 1) + (caar modules)) + ((equal (length visible) 1) + (caar visible)) + (t + (setq hist (mapcar 'car modules)) + (completing-read "Module: " modules nil t + "" (cons hist 0))) + ))) + (if (null module) + (error "Can't find completion for \"%s\"" pattern) + (message "Completion found in module %s" module) + (if (and (consp module-entry) (consp (cdr module-entry))) + (delete-region (caar module-entry) end) + (delete-region beg end)) + (insert module "." pattern)))) + + ((not (string-equal pattern completion)) + (delete-region beg end) + (goto-char beg) + (insert completion)) + + (t + (with-output-to-temp-buffer "*Completions*" + (display-completion-list all-completions)) + )) + )))) + + +;; Info files (only in ocamldoc style) + + +(defvar ocaml-info-prefix "ocaml-lib" + "Prefix of ocaml info files describing library modules. +Suffix .info will be added to info files. +Additional suffix .gz may be added if info files are compressed. +") +;; + +(defun ocaml-hevea-info-add-entries (entries dir name) + (let* + ((filter + (concat "-type f -regex '.*/" name + "\\(.info\\|\\)\\(-[0-9]*\\|\\)\\([.]gz\\|\\)'" + )) + (section-regexp + "\\* \\(Section [1-9][0-9--]*\\)::[ \t][ \t]*Module *\\([A-Z][A-Za-z_0-9]*\\)") + (files (ocaml-find-files dir filter)) + (command)) + ;; scanning info files + (if (or (null files) + (not (stringp files)) + (string-match files "^ *$")) + (message "No info file found: %s." (mapconcat 'identity files " ")) + (message "Scanning info files %s." files) + (save-window-excursion + (set-buffer (get-buffer-create "*caml-help*")) + (setq command + (concat "zcat -f " files + " | grep -e '" section-regexp "'")) + (message "Scanning files with: %s" command) + (or (shell-command command (current-buffer)) + (error "Error while scanning")) + (goto-char (point-min)) + (while (re-search-forward section-regexp (point-max) t) + (let* ((module (match-string 2)) + (section (match-string 1))) + ;; (message "%s %s" module section) + (if (assoc module entries) nil + (setq entries + (cons (cons module (concat "(" name ")" section)) + entries)) + ))) + (let ((buf (get-buffer "*caml-help*"))) + (if buf (kill-buffer buf))))) + entries)) + +(defun ocaml-hevea-info () + "The default way to create an info data base from the value +of \\[Info-default-directory-list] and the base name \\[ocaml-info-name] +of files to look for. + +This uses info files produced by HeVeA. +" + (let ((collect) (seen)) + (iter '(lambda (d) + (if (member d seen) nil + (setq collect + (ocaml-hevea-info-add-entries + collect d ocaml-info-prefix)) + (setq done (cons d seen)))) + Info-directory-list) + collect)) + +(defun ocaml-ocamldoc-info-add-entries (entries dir name) + (let* + ((module-regexp "^Node: \\([A-Z][A-Za-z_0-9]*\\)[^ ]") + (command + (concat + "find " dir " -type f -regex '.*/" name + "\\(.info\\|\\)\\([.]gz\\|\\)' -print0" + " | xargs -0 zcat -f | grep '" module-regexp "'"))) + (message "Scanning info files in %s" dir) + (save-window-excursion + (set-buffer (get-buffer-create "*caml-help*")) + (or (shell-command command (current-buffer)) (error "HERE")) + (goto-char (point-min)) + (while (re-search-forward module-regexp (point-max) t) + (if (equal (char-after (match-end 1)) 127) + (let* ((module (match-string 1))) + (if (assoc module entries) nil + (setq entries + (cons (cons module (concat "(" name ")" module)) + entries)) + )))) + ; (kill-buffer (current-buffer)) + ) + entries)) + +(defun ocaml-ocamldoc-info () + "The default way to create an info data base from the value +of \\[Info-default-directory-list] and the base name \\[ocaml-info-name] +of files to look for. + +This uses info files produced by ocamldoc." + (require 'info) + (let ((collect) (seen)) + (iter '(lambda (d) + (if (member d seen) nil + (setq collect + (ocaml-ocamldoc-info-add-entries collect d + ocaml-info-prefix)) + (setq done (cons d seen)))) + Info-directory-list) + collect)) + +;; Continuing + +(defvar ocaml-info-alist 'ocaml-ocamldoc-info + "A-list binding module names to info entries: + + nil means do not use info. + + A function to build the list lazily (at the first call). The result of +the function call will be assign permanently to this variable for future +uses. We provide two default functions \\[ocaml-info-default-function] +(info produced by HeVeA is the default) and \\[ocaml-info-default-function] +(info produced by ocamldoc). + + Otherwise, this value should be an alist binding module names to info +entries of the form to \"(entry)section\" be taken by the \\[info] +command. An entry may be an info module or a complete file name." +) + +(defun ocaml-info-alist () + "Call by need value of variable ocaml-info-alist" + (cond + ((listp ocaml-info-alist)) + ((functionp ocaml-info-alist) + (setq ocaml-info-alist (apply ocaml-info-alist nil))) + (t + (error "wrong type for ocaml-info-alist"))) + ocaml-info-alist) + +;; help around point + +(defun ocaml-find-module (symbol &optional module-list) + (let ((list (or module-list (ocaml-module-alist))) + (collect)) + (while (consp list) + (if (member symbol (ocaml-module-symbols (car list))) + (setq collect (cons (car list) collect))) + (setq list (cdr list))) + (nreverse collect) + )) + +(defun ocaml-buffer-substring (region) + (and region (buffer-substring-no-properties (car region) (cdr region)))) + +;; Help function. + + +(defun ocaml-goto-help (&optional module entry same-window) + "Searches info manual for MODULE and ENTRY in MODULE. +If unspecified, MODULE and ENTRY are inferred from the position in the +current buffer using \\[ocaml-qualified-identifier]." + (interactive) + (let ((window (selected-window)) + (info-section (assoc module (ocaml-info-alist)))) + (if info-section + (caml-info-other-window (cdr info-section)) + (ocaml-visible-modules) + (let* ((module-info + (or (assoc module (ocaml-module-alist)) + (and (file-exists-p + (concat (ocaml-uncapitalize module) ".mli")) + (ocaml-get-or-make-module module)))) + (location (cdr (cadr module-info)))) + (cond + (location + (let ((file (concat location (ocaml-uncapitalize module) ".mli"))) + (if (window-live-p same-window) + (progn (select-window same-window) + (view-mode-exit view-return-to-alist view-exit-action)) + ;; (view-buffer (find-file-noselect file) 'view)) + ) + (view-file-other-window file) + (bury-buffer (current-buffer)))) + (info-section (error "Aborted")) + (t (error "No help for module %s" module)))) + ) + (if (stringp entry) + (let ((here (point)) + (case-fold-search nil)) + (goto-char (point-min)) + (if (or (re-search-forward + (concat "\\(val\\|exception\\|type\\|external\\|[|{;]\\) +" + (regexp-quote entry)) + (point-max) t) + (re-search-forward + (concat "type [^{]*{[^}]*" (regexp-quote entry) " :") + (point-max) t) + (progn + (if (window-live-p window) (select-window window)) + (error "Entry %s not found in module %s" + entry module)) + ;; (search-forward entry (point-max) t) + ) + (recenter 1) + (progn + (message "Help for entry %s not found in module %s" + entry module) + (goto-char here))))) + (ocaml-link-activate (cdr info-section)) + (if (window-live-p window) (select-window window)) + )) + +(defun caml-help (arg) + "Find documentation for OCaml qualified identifiers. + +It attemps to recognize an qualified identifier of the form +``Module . entry'' around point using function `ocaml-qualified-identifier'. + +If Module is undetermined it is temptatively guessed from the identifier name +and according to visible modules. If this is still unsucessful, the user is +then prompted for a Module name. + +The documentation for Module is first seach in the info manual if available, +then in the ``module.mli'' source file. The entry is then searched in the documentation. + +Visible modules are computed only once, at the first call. +Modules can be made visible explicitly with `ocaml-open-module' and +hidden with `ocaml-close-module'. + +Prefix arg 0 forces recompilation of visible modules (and their content) +from the file content. + +Prefix arg 4 prompts for Module and identifier instead of guessing values +from the possition of point in the current buffer. +" + (interactive "p") + (let ((module) (entry) (module-entry)) + (cond + ((= arg 4) + (or (and + (setq module + (completing-read "Module: " (ocaml-module-alist) + nil t "" (cons 'hist 0))) + (not (string-equal module ""))) + (error "Quit")) + (let ((symbols + (mapcar 'list + (ocaml-module-symbols + (assoc module (ocaml-module-alist)))))) + (setq entry (completing-read "Value: " symbols nil t))) + (if (string-equal entry "") (setq entry nil)) + ) + (t + (if (= arg 0) (setq ocaml-visible-modules 'lazy)) + (setq module-entry (ocaml-qualified-identifier)) + (setq entry (ocaml-buffer-substring (cdr module-entry))) + (setq module + (or (ocaml-buffer-substring (car module-entry)) + (let ((modules + (or (ocaml-find-module entry (ocaml-visible-modules)) + (ocaml-find-module entry))) + (hist) (default)) + (cond + ((null modules) + (error "No module found for entry %s" entry)) + ((equal (length modules) 1) + (caar modules)) + (t + (setq hist (mapcar 'car modules)) + (setq default (car hist)) + (setq module + (completing-read + (concat "Module: " + (and default (concat "[" default "] "))) + modules nil t "" (cons 'hist 0))) + (if (string-equal module "") default module)) + )))) + )) + (message "Help for %s%s%s" module (if entry "." "") (or entry "")) + (ocaml-goto-help module entry) + )) + +;; auto-links + +(defconst ocaml-link-regexp + "\\(type\\|and\\) \\('[a-z] +\\|(\\('[a-z], *\\)*'[a-z])\\|\\) *\\([a-zA-Z0-9_]*\\)\\( *$\\| =\\)") +(defconst ocaml-longident-regexp + "\\([A-Z][a-zA-Z_0]*\\)[.]\\([a-zA-Z][A-Za-z0-9_]*\\)") + +(defvar ocaml-links nil + "Local links in the current of last info node or interface file. + +The car of the list is a key that indentifies the module to prevent +recompilation when next help command is relative to the same module. +The cdr is a list of elments, each of which is an string and a pair of +buffer positions." +) +(make-variable-buffer-local 'ocaml-links) + +(defun ocaml-info-links (section) + (cdr + (if (and ocaml-links section (equal (car ocaml-links) section)) + ocaml-links + (save-excursion + (goto-char (point-min)) + (let ((regexp (concat (if (equal major-mode 'Info-mode) "^ - " "^") + ocaml-link-regexp)) + (all)) + (while (re-search-forward regexp (point-max) t) + (setq all + (cons (cons (match-string 4) + (cons (match-beginning 4) + (match-end 4))) + all))) + (setq ocaml-links (cons section all)) + ))))) + +(defvar ocaml-link-map (make-sparse-keymap)) +(define-key ocaml-link-map [mouse-2] 'ocaml-link-goto) + +(defun ocaml-link-goto (click) + (interactive "e") + (let* ((pos (caml-event-point-start click)) + (win (caml-event-window click)) + (buf (window-buffer win)) + (window (selected-window)) + (link)) + (setq link + (with-current-buffer buf + (buffer-substring + (previous-single-property-change (+ pos 1) 'local-map + buf (- pos 100)) + (next-single-property-change pos 'local-map + buf (+ pos 100))))) + (if (string-match (concat "^" ocaml-longident-regexp "$") link) + (ocaml-goto-help (match-string 1 link) (match-string 2 link) win) + (if (not (equal (window-buffer window) buf)) + (switch-to-buffer-other-window buf)) + (if (setq link (assoc link (cdr ocaml-links))) + (progn + (goto-char (cadr link)) + (recenter 1))) + (if (window-live-p window) (select-window window)) + ))) + +(cond + ((and (x-display-color-p) + (not (memq 'ocaml-link-face (face-list)))) + (make-face 'ocaml-link-face) + (set-face-foreground 'ocaml-link-face "Purple"))) + + +(defun ocaml-link-activate (section) + (let ((links (ocaml-info-links section))) + (if links + (let ((regexp (concat "[^A-Za-z0-9'_]\\(" + ocaml-longident-regexp "\\|" + (mapconcat 'car links "\\|") + "\\)[^A-Za-z0-9'_]")) + (case-fold-search nil)) + (goto-char (point-min)) + (let ((buffer-read-only nil) + ;; use of dynamic scoping, need not be restored! + (modified-p (buffer-modified-p))) + (unwind-protect + (save-excursion + (goto-char (point-min)) + (while (re-search-forward regexp (point-max) t) + (put-text-property (match-beginning 1) (match-end 1) + 'mouse-face 'highlight) + (put-text-property (match-beginning 1) (match-end 1) + 'local-map ocaml-link-map) + (if (x-display-color-p) + (put-text-property (match-beginning 1) (match-end 1) + 'face 'ocaml-link-face))) + ) + ;; need to restore flag if buffer was unmodified. + (unless modified-p (set-buffer-modified-p nil)) + )) + )))) + + + +;; bindings ---now in caml.el + +; (and +; (boundp 'caml-mode-map) +; (keymapp caml-mode-map) +; (progn +; (define-key caml-mode-map [?\C-c?i] 'ocaml-add-path) +; (define-key caml-mode-map [?\C-c?]] 'ocaml-close-module) +; (define-key caml-mode-map [?\C-c?[] 'ocaml-open-module) +; (define-key caml-mode-map [?\C-c?\C-h] 'caml-help) +; (define-key caml-mode-map [?\C-c?\t] 'caml-complete) +; (let ((map (lookup-key caml-mode-map [menu-bar caml]))) +; (and +; (keymapp map) +; (progn +; (define-key map [separator-help] '("---")) +; (define-key map [open] '("Open add path" . ocaml-add-path )) +; (define-key map [close] +; '("Close module for help" . ocaml-close-module)) +; (define-key map [open] '("Open module for help" . ocaml-open-module)) +; (define-key map [help] '("Help for identifier" . caml-help)) +; (define-key map [complete] '("Complete identifier" . caml-complete)) +; ) +; )))) + + +(provide 'caml-help) diff --git a/emacs/caml-hilit.el b/emacs/caml-hilit.el new file mode 100644 index 0000000..b29717f --- /dev/null +++ b/emacs/caml-hilit.el @@ -0,0 +1,67 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Jacques Garrigue and Ian T Zimmerman *) +;(* *) +;(* Copyright 1997 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-hilit.el,v 1.9 2004-08-20 17:04:35 doligez Exp $ *) + +; Highlighting patterns for hilit19 under caml-mode + +; defined also in caml.el +(defvar caml-quote-char "'" + "*Quote for character constants. \"'\" for Objective Caml, \"`\" for Caml-Light.") + +(defconst caml-mode-patterns + (list +;comments + '("\\(^\\|[^\"]\\)\\((\\*[^*]*\\*+\\([^)*][^*]*\\*+\\)*)\\)" + 2 comment) +;string + (list 'hilit-string-find (string-to-char caml-quote-char) 'string) + (list (concat caml-quote-char "\\(\\\\\\([ntbr" caml-quote-char "\\]\\|" + "[0-9][0-9][0-9]\\)\\|.\\)" caml-quote-char) + nil + 'string) +;labels + '("\\(\\([~?]\\|\\<\\)[a-z][a-zA-Z0-9_']*:\\)[^:=]" 1 brown) + '("[~?][ (]*[a-z][a-zA-Z0-9_']*" nil brown) +;modules + '("\\<\\(assert\\|open\\|include\\)\\>" nil brown) + '("`?\\<[A-Z][A-Za-z0-9_\']*\\>" nil MidnightBlue) +;definition + (list (concat + "\\<\\(a\\(nd\\|s\\)\\|c\\(onstraint\\|lass\\)" + "\\|ex\\(ception\\|ternal\\)\\|fun\\(ct\\(ion\\|or\\)\\)?" + "\\|in\\(herit\\)?\\|let\\|m\\(ethod\\|utable\\|odule\\)" + "\\|of\\|p\\(arser\\|rivate\\)\\|rec\\|type" + "\\|v\\(al\\|irtual\\)\\)\\>") + nil 'ForestGreen) +;blocking + '("\\<\\(object\\|struct\\|sig\\|begin\\|end\\)\\>" 2 include) +;control + (list (concat + "\\<\\(do\\(ne\\|wnto\\)?\\|else\\|for\\|i\\(f\\|gnore\\)" + "\\|lazy\\|match\\|new\\|or\\|t\\(hen\\|o\\|ry\\)" + "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>" + "\\|\|\\|->\\|&\\|#") + nil 'keyword) + '(";" nil struct)) + "Hilit19 patterns used for Caml mode") + +(hilit-set-mode-patterns 'caml-mode caml-mode-patterns) +(hilit-set-mode-patterns + 'inferior-caml-mode + (append + (list +;inferior + '("^[#-]" nil firebrick)) + caml-mode-patterns)) + +(provide 'caml-hilit) diff --git a/emacs/caml-types.el b/emacs/caml-types.el new file mode 100644 index 0000000..1521b3e --- /dev/null +++ b/emacs/caml-types.el @@ -0,0 +1,765 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +;(* *) +;(* Copyright 2003 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-types.el,v 1.38 2008-07-29 15:49:31 doligez Exp $ *) + +; An emacs-lisp complement to the "-annot" option of ocamlc and ocamlopt. + +;; XEmacs compatibility + +(eval-and-compile + (if (and (boundp 'running-xemacs) running-xemacs) + (require 'caml-xemacs) + (require 'caml-emacs))) + + + +(defvar caml-types-location-re nil "Regexp to parse *.annot files. + +Annotation files *.annot may be generated with the \"-annot\" option +of ocamlc and ocamlopt. + +Their format is: + + file ::= block * + block ::= position position annotation * + position ::= filename num num num + annotation ::= keyword open-paren data close-paren + + is a space character (ASCII 0x20) + is a line-feed character (ASCII 0x0A) + num is a sequence of decimal digits + filename is a string with the lexical conventions of O'Caml + open-paren is an open parenthesis (ASCII 0x28) + close-paren is a closed parenthesis (ASCII 0x29) + data is any sequence of characters where is always followed by + at least two space characters. + +- in each block, the two positions are respectively the start and the + end of the range described by the block. +- in a position, the filename is the name of the file, the first num + is the line number, the second num is the offset of the beginning + of the line, the third num is the offset of the position itself. +- the char number within the line is the difference between the third + and second nums. + +The current list of keywords is: +type call ident" +) + +(let* ((caml-types-filename-re "\"\\(\\([^\\\"]\\|\\\\.\\)*\\)\"") + (caml-types-number-re "\\([0-9]*\\)")) + (setq caml-types-position-re + (concat caml-types-filename-re " " + caml-types-number-re " " + caml-types-number-re " " + caml-types-number-re)) + (setq caml-types-location-re + (concat "^" caml-types-position-re " " caml-types-position-re))) + +(defvar caml-types-expr-ovl (make-overlay 1 1)) +(make-face 'caml-types-expr-face) +(set-face-doc-string 'caml-types-expr-face + "face for hilighting expressions and types") +(if (not (face-differs-from-default-p 'caml-types-expr-face)) + (set-face-background 'caml-types-expr-face "#88FF44")) +(overlay-put caml-types-expr-ovl 'face 'caml-types-expr-face) + +(defvar caml-types-typed-ovl (make-overlay 1 1)) +(make-face 'caml-types-typed-face) +(set-face-doc-string 'caml-types-typed-face + "face for hilighting typed expressions") +(if (not (face-differs-from-default-p 'caml-types-typed-face)) + (set-face-background 'caml-types-typed-face "#FF8844")) +(overlay-put caml-types-typed-ovl 'face 'caml-types-typed-face) + +(defvar caml-types-scope-ovl (make-overlay 1 1)) +(make-face 'caml-types-scope-face) +(set-face-doc-string 'caml-types-scope-face + "face for hilighting variable scopes") +(if (not (face-differs-from-default-p 'caml-types-scope-face)) + (set-face-background 'caml-types-scope-face "#BBFFFF")) +(overlay-put caml-types-scope-ovl 'face 'caml-types-scope-face) + +(defvar caml-types-def-ovl (make-overlay 1 1)) +(make-face 'caml-types-def-face) +(set-face-doc-string 'caml-types-def-face + "face for hilighting binding occurrences") +(if (not (face-differs-from-default-p 'caml-types-def-face)) + (set-face-background 'caml-types-def-face "#FF4444")) +(overlay-put caml-types-def-ovl 'face 'caml-types-def-face) + +(defvar caml-types-occ-ovl (make-overlay 1 1)) +(make-face 'caml-types-occ-face) +(set-face-doc-string 'caml-types-occ-face + "face for hilighting variable occurrences") +(if (not (face-differs-from-default-p 'caml-types-occ-face)) + (set-face-background 'caml-types-occ-face "#44FF44")) +(overlay-put caml-types-occ-ovl 'face 'caml-types-occ-face) + + +(defvar caml-types-annotation-tree nil) +(defvar caml-types-annotation-date nil) +(make-variable-buffer-local 'caml-types-annotation-tree) +(make-variable-buffer-local 'caml-types-annotation-date) + +(defvar caml-types-buffer-name "*caml-types*" + "Name of buffer for diplaying caml types") +(defvar caml-types-buffer nil + "buffer for diplaying caml types") + +(defun caml-types-show-type (arg) + "Show the type of expression or pattern at point. + The smallest expression or pattern that contains point is + temporarily highlighted. Its type is highlighted in the .annot + file and the mark is set to the beginning of the type. + The type is also displayed in the mini-buffer. + + Hints on using the type display: + . If you want the type of an identifier, put point within any + occurrence of this identifier. + . If you want the result type of a function application, put point + at the first space after the function name. + . If you want the type of a list, put point on a bracket, on a + semicolon, or on the :: constructor. + . Even if type checking fails, you can still look at the types + in the file, up to where the type checker failed. + +Types are also displayed in the buffer *caml-types*, which is +displayed when the command is called with Prefix argument 4. + +See also `caml-types-explore' for exploration by mouse dragging. +See `caml-types-location-re' for annotation file format. +" + (interactive "p") + (let* ((target-buf (current-buffer)) + (target-file (file-name-nondirectory (buffer-file-name))) + (target-line (1+ (count-lines (point-min) + (caml-line-beginning-position)))) + (target-bol (caml-line-beginning-position)) + (target-cnum (point))) + (caml-types-preprocess (buffer-file-name)) + (setq caml-types-buffer (get-buffer-create caml-types-buffer-name)) + (let* ((targ-loc (vector target-file target-line target-bol target-cnum)) + (node (caml-types-find-location targ-loc "type" () + caml-types-annotation-tree))) + (cond + ((null node) + (delete-overlay caml-types-expr-ovl) + (message "Point is not within a typechecked expression or pattern.")) + (t + (let ((left (caml-types-get-pos target-buf (elt node 0))) + (right (caml-types-get-pos target-buf (elt node 1))) + (type (cdr (assoc "type" (elt node 2))))) + (move-overlay caml-types-expr-ovl left right target-buf) + (with-current-buffer caml-types-buffer + (erase-buffer) + (insert type) + (message (format "type: %s" type))) + )))) + (if (and (= arg 4) + (not (window-live-p (get-buffer-window caml-types-buffer)))) + (display-buffer caml-types-buffer)) + (unwind-protect + (caml-sit-for 60) + (delete-overlay caml-types-expr-ovl) + ))) + +(defun caml-types-show-call (arg) + "Show the kind of call at point. + The smallest function call that contains point is + temporarily highlighted. Its kind is highlighted in the .annot + file and the mark is set to the beginning of the kind. + The kind is also displayed in the mini-buffer. + +The kind is also displayed in the buffer *caml-types*, which is +displayed when the command is called with Prefix argument 4. + +See `caml-types-location-re' for annotation file format. +" + (interactive "p") + (let* ((target-buf (current-buffer)) + (target-file (file-name-nondirectory (buffer-file-name))) + (target-line (1+ (count-lines (point-min) + (caml-line-beginning-position)))) + (target-bol (caml-line-beginning-position)) + (target-cnum (point))) + (caml-types-preprocess (buffer-file-name)) + (setq caml-types-buffer (get-buffer-create caml-types-buffer-name)) + (let* ((targ-loc (vector target-file target-line target-bol target-cnum)) + (node (caml-types-find-location targ-loc "call" () + caml-types-annotation-tree))) + (cond + ((null node) + (delete-overlay caml-types-expr-ovl) + (message "Point is not within a function call.")) + (t + (let ((left (caml-types-get-pos target-buf (elt node 0))) + (right (caml-types-get-pos target-buf (elt node 1))) + (kind (cdr (assoc "call" (elt node 2))))) + (move-overlay caml-types-expr-ovl left right target-buf) + (with-current-buffer caml-types-buffer + (erase-buffer) + (insert kind) + (message (format "%s call" kind))) + )))) + (if (and (= arg 4) + (not (window-live-p (get-buffer-window caml-types-buffer)))) + (display-buffer caml-types-buffer)) + (unwind-protect + (caml-sit-for 60) + (delete-overlay caml-types-expr-ovl) + ))) + +(defun caml-types-show-ident (arg) + "Show the binding of identifier at point. + The identifier that contains point is + temporarily highlighted. Its binding is highlighted in the .annot + file and the mark is set to the beginning of the binding. + The binding is also displayed in the mini-buffer. + +The binding is also displayed in the buffer *caml-types*, which is +displayed when the command is called with Prefix argument 4. + +See `caml-types-location-re' for annotation file format. +" + (interactive "p") + (let* ((target-buf (current-buffer)) + (target-file (file-name-nondirectory (buffer-file-name))) + (target-line (1+ (count-lines (point-min) + (caml-line-beginning-position)))) + (target-bol (caml-line-beginning-position)) + (target-cnum (point))) + (caml-types-preprocess (buffer-file-name)) + (setq caml-types-buffer (get-buffer-create caml-types-buffer-name)) + (let* ((targ-loc (vector target-file target-line target-bol target-cnum)) + (node (caml-types-find-location targ-loc "ident" () + caml-types-annotation-tree))) + (cond + ((null node) + (delete-overlay caml-types-expr-ovl) + (message "Point is not within an identifier.")) + (t + (let ((left (caml-types-get-pos target-buf (elt node 0))) + (right (caml-types-get-pos target-buf (elt node 1))) + (kind (cdr (assoc "ident" (elt node 2))))) + (move-overlay caml-types-expr-ovl left right target-buf) + (let* ((loc-re (concat caml-types-position-re " " + caml-types-position-re)) + (end-re (concat caml-types-position-re " --")) + (def-re (concat "def \\([^ ]\\)* " loc-re)) + (def-end-re (concat "def \\([^ ]\\)* " end-re)) + (internal-re (concat "int_ref \\([^ ]\\)* " loc-re)) + (external-re "ext_ref \\(.*\\)")) + (cond + ((string-match def-re kind) + (let ((var-name (match-string 1 kind)) + (l-file (file-name-nondirectory (match-string 2 kind))) + (l-line (string-to-int (match-string 4 kind))) + (l-bol (string-to-int (match-string 5 kind))) + (l-cnum (string-to-int (match-string 6 kind))) + (r-file (file-name-nondirectory (match-string 7 kind))) + (r-line (string-to-int (match-string 9 kind))) + (r-bol (string-to-int (match-string 10 kind))) + (r-cnum (string-to-int (match-string 11 kind)))) + (let* ((lpos (vector l-file l-line l-bol l-cnum)) + (rpos (vector r-file r-line r-bol r-cnum)) + (left (caml-types-get-pos target-buf lpos)) + (right (caml-types-get-pos target-buf rpos))) + (message (format "local variable %s is bound here" var-name)) + (move-overlay caml-types-scope-ovl left right target-buf)))) + ((string-match def-end-re kind) + (let ((var-name (match-string 1 kind)) + (l-file (file-name-nondirectory (match-string 2 kind))) + (l-line (string-to-int (match-string 4 kind))) + (l-bol (string-to-int (match-string 5 kind))) + (l-cnum (string-to-int (match-string 6 kind)))) + (let* ((lpos (vector l-file l-line l-bol l-cnum)) + (left (caml-types-get-pos target-buf lpos)) + (right (buffer-size target-buf))) + (message (format "global variable %s is bound here" var-name)) + (move-overlay caml-types-scope-ovl left right target-buf)))) + ((string-match internal-re kind) + (let ((var-name (match-string 1 kind)) + (l-file (file-name-nondirectory (match-string 2 kind))) + (l-line (string-to-int (match-string 4 kind))) + (l-bol (string-to-int (match-string 5 kind))) + (l-cnum (string-to-int (match-string 6 kind))) + (r-file (file-name-nondirectory (match-string 7 kind))) + (r-line (string-to-int (match-string 9 kind))) + (r-bol (string-to-int (match-string 10 kind))) + (r-cnum (string-to-int (match-string 11 kind)))) + (let* ((lpos (vector l-file l-line l-bol l-cnum)) + (rpos (vector r-file r-line r-bol r-cnum)) + (left (caml-types-get-pos target-buf lpos)) + (right (caml-types-get-pos target-buf rpos))) + (move-overlay caml-types-def-ovl left right target-buf) + (message (format "%s is bound at line %d char %d" + var-name l-line (- l-cnum l-bol)))))) + ((string-match external-re kind) + (let ((fullname (match-string 1 kind))) + (with-current-buffer caml-types-buffer + (erase-buffer) + (insert fullname) + (message (format "external ident: %s" fullname))))))) + )))) + (if (and (= arg 4) + (not (window-live-p (get-buffer-window caml-types-buffer)))) + (display-buffer caml-types-buffer)) + (unwind-protect + (caml-sit-for 60) + (delete-overlay caml-types-expr-ovl) + (delete-overlay caml-types-def-ovl) + (delete-overlay caml-types-scope-ovl) + ))) + +(defun caml-types-preprocess (target-path) + (let* ((type-path (caml-types-locate-type-file target-path)) + (type-date (nth 5 (file-attributes (file-chase-links type-path)))) + (target-date (nth 5 (file-attributes target-file)))) + (unless (and caml-types-annotation-tree + type-date + caml-types-annotation-date + (not (caml-types-date< caml-types-annotation-date type-date))) + (if (and type-date target-date (caml-types-date< type-date target-date)) + (error (format "`%s' is more recent than `%s'" target-path type-path))) + (message "Reading annotation file...") + (let* ((type-buf (caml-types-find-file type-path)) + (tree (with-current-buffer type-buf + (widen) + (goto-char (point-min)) + (caml-types-build-tree + (file-name-nondirectory target-path))))) + (setq caml-types-annotation-tree tree + caml-types-annotation-date type-date) + (kill-buffer type-buf) + (message "done")) + ))) + +(defun caml-types-locate-type-file (target-path) + (let ((sibling (concat (file-name-sans-extension target-path) ".annot"))) + (if (file-exists-p sibling) + sibling + (defun parent-dir (d) (file-name-directory (directory-file-name d))) + (let ((project-dir (file-name-directory sibling)) + type-path) + (while (not (file-exists-p + (setq type-path + (expand-file-name + (file-relative-name sibling project-dir) + (expand-file-name "_build" project-dir))))) + (if (equal project-dir (parent-dir project-dir)) + (error (concat "No annotation file. " + "You should compile with option \"-dtypes\"."))) + (setq project-dir (parent-dir project-dir))) + type-path)))) + +(defun caml-types-date< (date1 date2) + (or (< (car date1) (car date2)) + (and (= (car date1) (car date2)) + (< (nth 1 date1) (nth 1 date2))))) + + +; we use an obarray for hash-consing the strings within each tree + +(defun caml-types-make-hash-table () + (make-vector 255 0)) + +(defun caml-types-hcons (elem table) + (symbol-name (intern elem table))) + + +(defun next-annotation () + (forward-char 1) + (if (re-search-forward "^[a-z\"]" () t) + (forward-char -1) + (goto-char (point-max))) + (looking-at "[a-z]") +) + +; tree of intervals +; each node is a vector +; [ pos-left pos-right annotation child child child... ] +; annotation is a list of: +; (kind . info) where kind = "type" "call" etc. +; and info = the contents of the annotation + +(defun caml-types-build-tree (target-file) + (let ((stack ()) + (accu ()) + (table (caml-types-make-hash-table)) + (annotation ())) + (while (re-search-forward caml-types-location-re () t) + (let ((l-file (file-name-nondirectory (match-string 1))) + (l-line (string-to-int (match-string 3))) + (l-bol (string-to-int (match-string 4))) + (l-cnum (string-to-int (match-string 5))) + (r-file (file-name-nondirectory (match-string 6))) + (r-line (string-to-int (match-string 8))) + (r-bol (string-to-int (match-string 9))) + (r-cnum (string-to-int (match-string 10)))) + (unless (caml-types-not-in-file l-file r-file target-file) + (setq annotation ()) + (while (next-annotation) + (cond ((looking-at + "^\\([a-z]+\\)(\n \\(\\([^\n)]\\|.)\\|\n[^)]\\)*\\)\n)") + (let ((kind (caml-types-hcons (match-string 1) table)) + (info (caml-types-hcons (match-string 2) table))) + (setq annotation (cons (cons kind info) annotation)))))) + (setq accu ()) + (while (and stack + (caml-types-pos-contains l-cnum r-cnum (car stack))) + (setq accu (cons (car stack) accu)) + (setq stack (cdr stack))) + (let* ((left-pos (vector l-file l-line l-bol l-cnum)) + (right-pos (vector r-file r-line r-bol r-cnum)) + (node (caml-types-make-node left-pos right-pos annotation + accu))) + (setq stack (cons node stack)))))) + (if (null stack) + (error "no annotations found for this source file") + (let* ((left-pos (elt (car (last stack)) 0)) + (right-pos (elt (car stack) 1))) + (if (null (cdr stack)) + (car stack) + (caml-types-make-node left-pos right-pos () (nreverse stack))))))) + +(defun caml-types-not-in-file (l-file r-file target-file) + (or (and (not (string= l-file target-file)) + (not (string= l-file ""))) + (and (not (string= r-file target-file)) + (not (string= r-file ""))))) + +(defun caml-types-make-node (left-pos right-pos annotation children) + (let ((result (make-vector (+ 3 (length children)) ())) + (i 3)) + (aset result 0 left-pos) + (aset result 1 right-pos) + (aset result 2 annotation) + (while children + (aset result i (car children)) + (setq children (cdr children)) + (setq i (1+ i))) + result)) + +(defun caml-types-pos-contains (l-cnum r-cnum node) + (and (<= l-cnum (elt (elt node 0) 3)) + (>= r-cnum (elt (elt node 1) 3)))) + +(defun caml-types-find-location (targ-pos kind curr node) + (if (not (caml-types-pos-inside targ-pos node)) + curr + (if (and (elt node 2) (assoc kind (elt node 2))) + (setq curr node)) + (let ((i (caml-types-search node targ-pos))) + (if (and (> i 3) + (caml-types-pos-inside targ-pos (elt node (1- i)))) + (caml-types-find-location targ-pos kind curr (elt node (1- i))) + curr)))) + +; trouve le premier fils qui commence apres la position +; ou (length node) si tous commencent avant +(defun caml-types-search (node pos) + (let ((min 3) + (max (length node)) + med) + (while (< min max) + (setq med (/ (+ min max) 2)) + (if (caml-types-pos<= (elt (elt node med) 0) pos) + (setq min (1+ med)) + (setq max med))) + min)) + +(defun caml-types-pos-inside (pos node) + (let ((left-pos (elt node 0)) + (right-pos (elt node 1))) + (and (caml-types-pos<= left-pos pos) + (caml-types-pos> right-pos pos)))) + +(defun caml-types-find-interval (buf targ-pos node) + (let ((nleft (elt node 0)) + (nright (elt node 1)) + (left ()) + (right ()) + i) + (cond + ((not (caml-types-pos-inside targ-pos node)) + (if (not (caml-types-pos<= nleft targ-pos)) + (setq right nleft)) + (if (not (caml-types-pos> nright targ-pos)) + (setq left nright))) + (t + (setq left nleft + right nright) + (setq i (caml-types-search node targ-pos)) + (if (< i (length node)) + (setq right (elt (elt node i) 0))) + (if (> i 3) + (setq left (elt (elt node (1- i)) 1))))) + (cons (if left + (caml-types-get-pos buf left) + (with-current-buffer buf (point-min))) + (if right + (caml-types-get-pos buf right) + (with-current-buffer buf (point-max)))))) + + +;; Warning: these comparison functions are not symmetric. +;; The first argument determines the format: +;; when its file component is empty, only the cnum is compared. + +(defun caml-types-pos<= (pos1 pos2) + (let ((file1 (elt pos1 0)) + (line1 (elt pos1 1)) + (bol1 (elt pos1 2)) + (cnum1 (elt pos1 3)) + (file2 (elt pos2 0)) + (line2 (elt pos2 1)) + (bol2 (elt pos2 2)) + (cnum2 (elt pos2 3))) + (if (string= file1 "") + (<= cnum1 cnum2) + (and (string= file1 file2) + (or (< line1 line2) + (and (= line1 line2) + (<= (- cnum1 bol1) (- cnum2 bol2)))))))) + +(defun caml-types-pos> (pos1 pos2) + (let ((file1 (elt pos1 0)) + (line1 (elt pos1 1)) + (bol1 (elt pos1 2)) + (cnum1 (elt pos1 3)) + (file2 (elt pos2 0)) + (line2 (elt pos2 1)) + (bol2 (elt pos2 2)) + (cnum2 (elt pos2 3))) + (if (string= file1 "") + (> cnum1 cnum2) + (and (string= file1 file2) + (or (> line1 line2) + (and (= line1 line2) + (> (- cnum1 bol1) (- cnum2 bol2)))))))) + +(defun caml-types-get-pos (buf pos) + (save-excursion + (set-buffer buf) + (goto-line (elt pos 1)) + (forward-char (- (elt pos 3) (elt pos 2))) + (point))) + +; find-file-read-only-noselect seems to be missing from emacs... +(defun caml-types-find-file (name) + (let (buf) + (cond + ((setq buf (get-file-buffer name)) + (unless (verify-visited-file-modtime buf) + (if (buffer-modified-p buf) + (find-file-noselect name) + (with-current-buffer buf (revert-buffer t t))) + )) + ((and (file-readable-p name) + (setq buf (find-file-noselect name))) + (with-current-buffer buf (toggle-read-only 1)) + ) + (t + (error (format "Can't read the annotation file `%s'" name))) + ) + buf)) + +(defun caml-types-mouse-ignore (event) + (interactive "e") + nil) + +(defun caml-types-time () + (let ((time (current-time))) + (+ (* (mod (cadr time) 1000) 1000) + (/ (cadr (cdr time)) 1000)))) + +(defun caml-types-explore (event) + "Explore type annotations by mouse dragging. + +The expression under the mouse is highlighted and its type is displayed +in the minibuffer, until the move is released, much as `caml-types-show-type'. +The function uses two overlays. + + . One overlay delimits the largest region whose all subnodes + are well-typed. + . Another overlay delimits the current node under the mouse (whose type + annotation is beeing displayed). +" + (interactive "e") + (set-buffer (window-buffer (caml-event-window event))) + (let* ((target-buf (current-buffer)) + (target-file (file-name-nondirectory (buffer-file-name))) + (target-line) (target-bol) + target-pos + Left Right limits cnum node mes type + region + (window (caml-event-window event)) + target-tree + (speed 100) + (last-time (caml-types-time)) + (original-event event) + ) + (select-window window) + (unwind-protect + (progn + (caml-types-preprocess (buffer-file-name)) + (setq target-tree caml-types-annotation-tree) + (setq caml-types-buffer (get-buffer-create caml-types-buffer-name)) + ;; (message "Drag the mouse to explore types") + (unwind-protect + (caml-track-mouse + (while event + (cond + ;; we ignore non mouse events + ((caml-ignore-event-p event)) + ;; we stop when the original button is released + ((caml-release-event-p original-event event) + (setq event nil)) + ;; we scroll when the motion is outside the window + ((and (caml-mouse-movement-p event) + (not (and (equal window (caml-event-window event)) + (integer-or-marker-p + (caml-event-point-end event))))) + (let* ((win (caml-window-edges window)) + (top (nth 1 win)) + (bottom (- (nth 3 win) 1)) + mouse + time + ) + (while (and + (caml-sit-for 0 (/ 500 speed)) + (setq time (caml-types-time)) + (> (- time last-time) (/ 500 speed)) + (setq mouse (caml-mouse-vertical-position)) + (or (< mouse top) (>= mouse bottom)) + ) + (setq last-time time) + (cond + ((< mouse top) + (setq speed (- top mouse)) + (condition-case nil + (scroll-down 1) + (error (message "Beginning of buffer!")))) + ((>= mouse bottom) + (setq speed (+ 1 (- mouse bottom))) + (condition-case nil + (scroll-up 1) + (error (message "End of buffer!")))) + ) + (setq speed (* speed speed)) + ))) + ;; main action, when the motion is inside the window + ;; or on orginal button down event + ((or (caml-mouse-movement-p event) + (equal original-event event)) + (setq cnum (caml-event-point-end event)) + (if (and region + (<= (car region) cnum) (< cnum (cdr region))) + ;; mouse remains in outer region + nil + ;; otherwise, reset the outer region + (setq region + (caml-types-typed-make-overlay + target-buf (caml-event-point-start event)))) + (if + (and limits + (>= cnum (car limits)) (< cnum (cdr limits))) + ;; inner region is unchanged + nil + ;; recompute the inner region and type annotation + (setq target-bol + (save-excursion + (goto-char cnum) (caml-line-beginning-position)) + target-line (1+ (count-lines (point-min) + target-bol)) + target-pos + (vector target-file target-line target-bol cnum)) + (save-excursion + (setq node (caml-types-find-location "type" + target-pos () target-tree)) + (set-buffer caml-types-buffer) + (erase-buffer) + (cond + (node + (setq Left + (caml-types-get-pos target-buf (elt node 0)) + Right + (caml-types-get-pos target-buf (elt node 1))) + (move-overlay + caml-types-expr-ovl Left Right target-buf) + (setq limits + (caml-types-find-interval target-buf + target-pos node) + type (elt node 2)) + ) + (t + (delete-overlay caml-types-expr-ovl) + (setq type "*no type information*") + (setq limits + (caml-types-find-interval + target-buf target-pos target-tree)) + )) + (setq mes (format "type: %s" type)) + (insert type) + )) + (message mes) + ) + ) + ;; we read next event, unless it is nil, and loop back. + (if event (setq event (caml-read-event))) + ) + ) + ;; delete overlays at end of exploration + (delete-overlay caml-types-expr-ovl) + (delete-overlay caml-types-typed-ovl) + )) + ;; When an error occurs, the mouse release event has not been read. + ;; We could wait for mouse release to prevent execution of + ;; a binding of mouse release, such as cut or paste. + ;; In most common cases, next event will be the mouse release. + ;; However, it could also be a key stroke before mouse release. + ;; Emacs does not allow to test whether mouse is up or down. + ;; Not sure it is robust to loop for mouse release after an error + ;; occured, as is done for exploration. + ;; So far, we just ignore next event. (Next line also be uncommenting.) + (if event (caml-read-event)) + ))) + +(defun caml-types-typed-make-overlay (target-buf pos) + (interactive "p") + (let ((start pos) (end pos) len node left right) + (setq len (length caml-types-annotation-tree)) + (while (> len 3) + (setq len (- len 1)) + (setq node (aref caml-types-annotation-tree len)) + (if (and (equal target-buf (current-buffer)) + (setq left (caml-types-get-pos target-buf (elt node 0)) + right (caml-types-get-pos target-buf (elt node 1))) + (<= left pos) (> right pos) + ) + (setq start (min start left) + end (max end right)) + )) + (move-overlay caml-types-typed-ovl + (max (point-min) (- start 1)) + (min (point-max) (+ end 1)) target-buf) + (cons start end))) + +(defun caml-types-version () + "internal version number of caml-types.el" + (interactive) + (message "4") +) + +(provide 'caml-types) diff --git a/emacs/caml-xemacs.el b/emacs/caml-xemacs.el new file mode 100644 index 0000000..1d9a403 --- /dev/null +++ b/emacs/caml-xemacs.el @@ -0,0 +1,53 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Didier Remy, projet Cristal, INRIA Rocquencourt *) +;(* *) +;(* Copyright 2003 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml-xemacs.el,v 1.7 2005-03-24 17:20:53 doligez Exp $ *) + +(require 'overlay) + +;; for caml-help.el +(defun caml-info-other-window (arg) + (save-excursion (info arg)) + (view-buffer-other-window "*info*")) + +;; for caml-types.el +(defun caml-line-beginning-position () + (save-excursion (beginning-of-line) (point))) + +(defalias 'caml-read-event 'next-event) +(defalias 'caml-window-edges 'window-pixel-edges) +(defun caml-mouse-vertical-position () + (let ((e (mouse-position-as-motion-event))) + (and e (event-y-pixel e)))) +(defalias 'caml-mouse-movement-p 'motion-event-p) +(defun caml-event-window (e) + (and (mouse-event-p e) (event-window e))) +(defun caml-event-point-start (e) (event-closest-point e)) +(defun caml-event-point-end (e) (event-closest-point e)) +(defun caml-ignore-event-p (e) + (if (and (key-press-event-p e) (equal (key-binding e) 'keyboard-quit)) + (keyboard-quit)) + (not (mouse-event-p e))) + + +(defun caml-sit-for (sec &optional mili) + (sit-for (+ sec (if mili (* 0.001 mili) 0)))) + + + +(defmacro caml-track-mouse (&rest body) (cons 'progn body)) + +(defun caml-release-event-p (original event) + (and (button-release-event-p event) + (equal (event-button original) (event-button event)))) + +(provide 'caml-xemacs) diff --git a/emacs/caml.el b/emacs/caml.el new file mode 100644 index 0000000..c05d9c9 --- /dev/null +++ b/emacs/caml.el @@ -0,0 +1,1932 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Jacques Garrigue and Ian T Zimmerman *) +;(* *) +;(* Copyright 1997 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: caml.el,v 1.45 2008-12-03 18:09:09 doligez Exp $ *) + +;;; caml.el --- O'Caml code editing commands for Emacs + +;; Xavier Leroy, july 1993. + +;;indentation code is Copyright (C) 1996 by Ian T Zimmerman +;;copying: covered by the current FSF General Public License. + +;; indentation code adapted for Objective Caml by Jacques Garrigue, +;; july 1997. + +;;user customizable variables +(defvar caml-quote-char "'" + "*Quote for character constants. \"'\" for Objective Caml, \"`\" for Caml-Light.") + +(defvar caml-imenu-enable nil + "*Enable Imenu support.") + +(defvar caml-mode-indentation 2 + "*Used for \\[caml-unindent-command].") + +(defvar caml-lookback-limit 5000 + "*How far to look back for syntax things in caml mode.") + +(defvar caml-max-indent-priority 8 + "*Bounds priority of operators permitted to affect caml indentation. + +Priorities are assigned to `interesting' caml operators as follows: + + all keywords 0 to 7 8 + type, val, ... + 0 7 + :: ^ 6 + @ 5 + := <- 4 + if 3 + fun, let, match ... 2 + module 1 + opening keywords 0.") + +(defvar caml-apply-extra-indent 2 + "*How many spaces to add to indentation for an application in caml mode.") +(make-variable-buffer-local 'caml-apply-extra-indent) + +(defvar caml-begin-indent 2 + "*How many spaces to indent from a begin keyword in caml mode.") +(make-variable-buffer-local 'caml-begin-indent) + +(defvar caml-class-indent 2 + "*How many spaces to indent from a class keyword in caml mode.") +(make-variable-buffer-local 'caml-class-indent) + +(defvar caml-exception-indent 2 + "*How many spaces to indent from a exception keyword in caml mode.") +(make-variable-buffer-local 'caml-exception-indent) + +(defvar caml-for-indent 2 + "*How many spaces to indent from a for keyword in caml mode.") +(make-variable-buffer-local 'caml-for-indent) + +(defvar caml-fun-indent 2 + "*How many spaces to indent from a fun keyword in caml mode.") +(make-variable-buffer-local 'caml-fun-indent) + +(defvar caml-function-indent 4 + "*How many spaces to indent from a function keyword in caml mode.") +(make-variable-buffer-local 'caml-function-indent) + +(defvar caml-if-indent 2 + "*How many spaces to indent from a if keyword in caml mode.") +(make-variable-buffer-local 'caml-if-indent) + +(defvar caml-if-else-indent 0 + "*How many spaces to indent from an if .. else line in caml mode.") +(make-variable-buffer-local 'caml-if-else-indent) + +(defvar caml-inherit-indent 2 + "*How many spaces to indent from a inherit keyword in caml mode.") +(make-variable-buffer-local 'caml-inherit-indent) + +(defvar caml-initializer-indent 2 + "*How many spaces to indent from a initializer keyword in caml mode.") +(make-variable-buffer-local 'caml-initializer-indent) + +(defvar caml-include-indent 2 + "*How many spaces to indent from a include keyword in caml mode.") +(make-variable-buffer-local 'caml-include-indent) + +(defvar caml-let-indent 2 + "*How many spaces to indent from a let keyword in caml mode.") +(make-variable-buffer-local 'caml-let-indent) + +(defvar caml-let-in-indent 0 + "*How many spaces to indent from a let .. in keyword in caml mode.") +(make-variable-buffer-local 'caml-let-in-indent) + +(defvar caml-match-indent 2 + "*How many spaces to indent from a match keyword in caml mode.") +(make-variable-buffer-local 'caml-match-indent) + +(defvar caml-method-indent 2 + "*How many spaces to indent from a method keyword in caml mode.") +(make-variable-buffer-local 'caml-method-indent) + +(defvar caml-module-indent 2 + "*How many spaces to indent from a module keyword in caml mode.") +(make-variable-buffer-local 'caml-module-indent) + +(defvar caml-object-indent 2 + "*How many spaces to indent from a object keyword in caml mode.") +(make-variable-buffer-local 'caml-object-indent) + +(defvar caml-of-indent 2 + "*How many spaces to indent from a of keyword in caml mode.") +(make-variable-buffer-local 'caml-of-indent) + +(defvar caml-parser-indent 4 + "*How many spaces to indent from a parser keyword in caml mode.") +(make-variable-buffer-local 'caml-parser-indent) + +(defvar caml-sig-indent 2 + "*How many spaces to indent from a sig keyword in caml mode.") +(make-variable-buffer-local 'caml-sig-indent) + +(defvar caml-struct-indent 2 + "*How many spaces to indent from a struct keyword in caml mode.") +(make-variable-buffer-local 'caml-struct-indent) + +(defvar caml-try-indent 2 + "*How many spaces to indent from a try keyword in caml mode.") +(make-variable-buffer-local 'caml-try-indent) + +(defvar caml-type-indent 4 + "*How many spaces to indent from a type keyword in caml mode.") +(make-variable-buffer-local 'caml-type-indent) + +(defvar caml-val-indent 2 + "*How many spaces to indent from a val keyword in caml mode.") +(make-variable-buffer-local 'caml-val-indent) + +(defvar caml-while-indent 2 + "*How many spaces to indent from a while keyword in caml mode.") +(make-variable-buffer-local 'caml-while-indent) + +(defvar caml-::-indent 2 + "*How many spaces to indent from a :: operator in caml mode.") +(make-variable-buffer-local 'caml-::-indent) + +(defvar caml-@-indent 2 + "*How many spaces to indent from a @ operator in caml mode.") +(make-variable-buffer-local 'caml-@-indent) + +(defvar caml-:=-indent 2 + "*How many spaces to indent from a := operator in caml mode.") +(make-variable-buffer-local 'caml-:=-indent) + +(defvar caml-<--indent 2 + "*How many spaces to indent from a <- operator in caml mode.") +(make-variable-buffer-local 'caml-<--indent) + +(defvar caml-->-indent 2 + "*How many spaces to indent from a -> operator in caml mode.") +(make-variable-buffer-local 'caml-->-indent) + +(defvar caml-lb-indent 2 + "*How many spaces to indent from a \[ operator in caml mode.") +(make-variable-buffer-local 'caml-lb-indent) + +(defvar caml-lc-indent 2 + "*How many spaces to indent from a \{ operator in caml mode.") +(make-variable-buffer-local 'caml-lc-indent) + +(defvar caml-lp-indent 1 + "*How many spaces to indent from a \( operator in caml mode.") +(make-variable-buffer-local 'caml-lp-indent) + +(defvar caml-and-extra-indent nil + "*Extra indent for caml lines starting with the and keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-and-extra-indent) + +(defvar caml-do-extra-indent nil + "*Extra indent for caml lines starting with the do keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-do-extra-indent) + +(defvar caml-done-extra-indent nil + "*Extra indent for caml lines starting with the done keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-done-extra-indent) + +(defvar caml-else-extra-indent nil + "*Extra indent for caml lines starting with the else keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-else-extra-indent) + +(defvar caml-end-extra-indent nil + "*Extra indent for caml lines starting with the end keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-end-extra-indent) + +(defvar caml-in-extra-indent nil + "*Extra indent for caml lines starting with the in keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-in-extra-indent) + +(defvar caml-then-extra-indent nil + "*Extra indent for caml lines starting with the then keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-then-extra-indent) + +(defvar caml-to-extra-indent -1 + "*Extra indent for caml lines starting with the to keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-to-extra-indent) + +(defvar caml-with-extra-indent nil + "*Extra indent for caml lines starting with the with keyword. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-with-extra-indent) + +(defvar caml-comment-indent 3 + "*Indent inside comments.") +(make-variable-buffer-local 'caml-comment-indent) + +(defvar caml-|-extra-indent -2 + "*Extra indent for caml lines starting with the | operator. +Usually negative. nil is align on master.") +(make-variable-buffer-local 'caml-|-extra-indent) + +(defvar caml-rb-extra-indent -2 + "*Extra indent for caml lines statring with ]. +Usually negative. nil is align on master.") + +(defvar caml-rc-extra-indent -2 + "*Extra indent for caml lines starting with }. +Usually negative. nil is align on master.") + +(defvar caml-rp-extra-indent -1 + "*Extra indent for caml lines starting with ). +Usually negative. nil is align on master.") + +(defvar caml-electric-indent t + "*Non-nil means electrically indent lines starting with |, ] or }. + +Many people find eletric keys irritating, so you can disable them if +you are one.") + +(defvar caml-electric-close-vector t + "*Non-nil means electrically insert a | before a vector-closing ]. + +Many people find eletric keys irritating, so you can disable them if +you are one. You should probably have this on, though, if you also +have caml-electric-indent on, which see.") + +;;code +(if (or (not (fboundp 'indent-line-to)) + (not (fboundp 'buffer-substring-no-properties))) + (require 'caml-compat)) + +(defvar caml-shell-active nil + "Non nil when a subshell is running.") + +(defvar running-xemacs (string-match "XEmacs" emacs-version) + "Non-nil if we are running in the XEmacs environment.") + +(defvar caml-mode-map nil + "Keymap used in Caml mode.") +(if caml-mode-map + () + (setq caml-mode-map (make-sparse-keymap)) + (define-key caml-mode-map "|" 'caml-electric-pipe) + (define-key caml-mode-map "}" 'caml-electric-pipe) + (define-key caml-mode-map "]" 'caml-electric-rb) + (define-key caml-mode-map "\t" 'caml-indent-command) + (define-key caml-mode-map [backtab] 'caml-unindent-command) + +;itz 04-21-96 instead of defining a new function, use defadvice +;that way we get out effect even when we do \C-x` in compilation buffer +; (define-key caml-mode-map "\C-x`" 'caml-next-error) + + (if running-xemacs + (define-key caml-mode-map 'backspace 'backward-delete-char-untabify) + (define-key caml-mode-map "\177" 'backward-delete-char-untabify)) + + ;; caml-types + (define-key caml-mode-map [?\C-c?\C-t] 'caml-types-show-type) ; "type" + (define-key caml-mode-map [?\C-c?\C-f] 'caml-types-show-call) ; "function" + (define-key caml-mode-map [?\C-c?\C-l] 'caml-types-show-ident) ; "let" + ;; must be a mouse-down event. Can be any button and any prefix + (define-key caml-mode-map [?\C-c down-mouse-1] 'caml-types-explore) + ;; caml-help + (define-key caml-mode-map [?\C-c?i] 'ocaml-add-path) + (define-key caml-mode-map [?\C-c?]] 'ocaml-close-module) + (define-key caml-mode-map [?\C-c?[] 'ocaml-open-module) + (define-key caml-mode-map [?\C-c?\C-h] 'caml-help) + (define-key caml-mode-map [?\C-c?\t] 'caml-complete) + ;; others + (define-key caml-mode-map "\C-cb" 'caml-insert-begin-form) + (define-key caml-mode-map "\C-cf" 'caml-insert-for-form) + (define-key caml-mode-map "\C-ci" 'caml-insert-if-form) + (define-key caml-mode-map "\C-cl" 'caml-insert-let-form) + (define-key caml-mode-map "\C-cm" 'caml-insert-match-form) + (define-key caml-mode-map "\C-ct" 'caml-insert-try-form) + (define-key caml-mode-map "\C-cw" 'caml-insert-while-form) + (define-key caml-mode-map "\C-c`" 'caml-goto-phrase-error) + (define-key caml-mode-map "\C-c\C-a" 'caml-find-alternate-file) + (define-key caml-mode-map "\C-c\C-c" 'compile) + (define-key caml-mode-map "\C-c\C-e" 'caml-eval-phrase) + (define-key caml-mode-map "\C-c\C-\[" 'caml-backward-to-less-indent) + (define-key caml-mode-map "\C-c\C-\]" 'caml-forward-to-less-indent) + (define-key caml-mode-map "\C-c\C-q" 'caml-indent-phrase) + (define-key caml-mode-map "\C-c\C-r" 'caml-eval-region) + (define-key caml-mode-map "\C-c\C-s" 'caml-show-subshell) + (define-key caml-mode-map "\M-\C-h" 'caml-mark-phrase) + (define-key caml-mode-map "\M-\C-q" 'caml-indent-phrase) + (define-key caml-mode-map "\M-\C-x" 'caml-eval-phrase) + + (if running-xemacs nil ; if not running xemacs + (let ((map (make-sparse-keymap "Caml")) + (forms (make-sparse-keymap "Forms"))) + (define-key caml-mode-map "\C-c\C-d" 'caml-show-imenu) + (define-key caml-mode-map [menu-bar] (make-sparse-keymap)) + (define-key caml-mode-map [menu-bar caml] (cons "Caml" map)) + ;; caml-help + + (define-key map [open] '("Open add path" . ocaml-add-path )) + (define-key map [close] + '("Close module for help" . ocaml-close-module)) + (define-key map [open] '("Open module for help" . ocaml-open-module)) + (define-key map [help] '("Help for identifier" . caml-help)) + (define-key map [complete] '("Complete identifier" . caml-complete)) + (define-key map [separator-help] '("---")) + + ;; caml-types + (define-key map [show-type] + '("Show type at point" . caml-types-show-type )) + (define-key map [separator-types] '("---")) + + ;; others + (define-key map [camldebug] '("Call debugger..." . camldebug)) + (define-key map [run-caml] '("Start subshell..." . run-caml)) + (define-key map [compile] '("Compile..." . compile)) + (define-key map [switch-view] + '("Switch view" . caml-find-alternate-file)) + (define-key map [separator-format] '("--")) + (define-key map [forms] (cons "Forms" forms)) + (define-key map [show-imenu] '("Show index" . caml-show-imenu)) + (put 'caml-show-imenu 'menu-enable '(not caml-imenu-shown)) + (define-key map [show-subshell] '("Show subshell" . caml-show-subshell)) + (put 'caml-show-subshell 'menu-enable 'caml-shell-active) + (define-key map [eval-phrase] '("Eval phrase" . caml-eval-phrase)) + (put 'caml-eval-phrase 'menu-enable 'caml-shell-active) + (define-key map [indent-phrase] '("Indent phrase" . caml-indent-phrase)) + (define-key forms [while] + '("while .. do .. done" . caml-insert-while-form)) + (define-key forms [try] '("try .. with .." . caml-insert-try-form)) + (define-key forms [match] '("match .. with .." . caml-insert-match-form)) + (define-key forms [let] '("let .. in .." . caml-insert-let-form)) + (define-key forms [if] '("if .. then .. else .." . caml-insert-if-form)) + (define-key forms [begin] '("for .. do .. done" . caml-insert-for-form)) + (define-key forms [begin] '("begin .. end" . caml-insert-begin-form))))) + +(defvar caml-mode-xemacs-menu + (if running-xemacs + '("Caml" + [ "Indent phrase" caml-indent-phrase :keys "C-M-q" ] + [ "Eval phrase" caml-eval-phrase + :active caml-shell-active :keys "C-M-x" ] + [ "Show subshell" caml-show-subshell caml-shell-active ] + ("Forms" + [ "while .. do .. done" caml-insert-while-form t] + [ "try .. with .." caml-insert-try-form t ] + [ "match .. with .." caml-insert-match-form t ] + [ "let .. in .." caml-insert-let-form t ] + [ "if .. then .. else .." caml-insert-if-form t ] + [ "for .. do .. done" caml-insert-for-form t ] + [ "begin .. end" caml-insert-begin-form t ]) + "---" + [ "Switch view" caml-find-alternate-file t ] + [ "Compile..." compile t ] + [ "Start subshell..." run-caml t ] + "---" + [ "Show type at point" caml-types-show-type t ] + "---" + [ "Complete identifier" caml-complete t ] + [ "Help for identifier" caml-help t ] + [ "Add path for documentation" ocaml-add-path t ] + [ "Open module for documentation" ocaml-open t ] + [ "Close module for documentation" ocaml-close t ] + )) + "Menu to add to the menubar when running Xemacs") + +(defvar caml-mode-syntax-table nil + "Syntax table in use in Caml mode buffers.") +(if caml-mode-syntax-table + () + (setq caml-mode-syntax-table (make-syntax-table)) + ; backslash is an escape sequence + (modify-syntax-entry ?\\ "\\" caml-mode-syntax-table) + ; ( is first character of comment start + (modify-syntax-entry ?\( "()1n" caml-mode-syntax-table) + ; * is second character of comment start, + ; and first character of comment end + (modify-syntax-entry ?* ". 23n" caml-mode-syntax-table) + ; ) is last character of comment end + (modify-syntax-entry ?\) ")(4" caml-mode-syntax-table) + ; backquote was a string-like delimiter (for character literals) + ; (modify-syntax-entry ?` "\"" caml-mode-syntax-table) + ; quote and underscore are part of words + (modify-syntax-entry ?' "w" caml-mode-syntax-table) + (modify-syntax-entry ?_ "w" caml-mode-syntax-table) + ; ISO-latin accented letters and EUC kanjis are part of words + (let ((i 160)) + (while (< i 256) + (modify-syntax-entry i "w" caml-mode-syntax-table) + (setq i (1+ i))))) + +(defvar caml-mode-abbrev-table nil + "Abbrev table used for Caml mode buffers.") +(if caml-mode-abbrev-table nil + (setq caml-mode-abbrev-table (make-abbrev-table)) + (define-abbrev caml-mode-abbrev-table "and" "and" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "do" "do" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "done" "done" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "else" "else" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "end" "end" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "in" "in" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "then" "then" 'caml-abbrev-hook) + (define-abbrev caml-mode-abbrev-table "with" "with" 'caml-abbrev-hook)) + +;; Other internal variables + +(defvar caml-last-noncomment-pos nil + "Caches last buffer position determined not inside a caml comment.") +(make-variable-buffer-local 'caml-last-noncomment-pos) + +;;last-noncomment-pos can be a simple position, because we nil it +;;anyway whenever buffer changes upstream. last-comment-start and -end +;;have to be markers, because we preserve them when the changes' end +;;doesn't overlap with the comment's start. + +(defvar caml-last-comment-start nil + "A marker caching last determined caml comment start.") +(make-variable-buffer-local 'caml-last-comment-start) + +(defvar caml-last-comment-end nil + "A marker caching last determined caml comment end.") +(make-variable-buffer-local 'caml-last-comment-end) + +(make-variable-buffer-local 'before-change-function) + +(defvar caml-imenu-shown nil + "True if we have computed definition list.") +(make-variable-buffer-local 'caml-imenu-shown) + +(defconst caml-imenu-search-regexp + (concat "\\\\|" + "^[ \t]*\\(let\\|class\\|type\\|m\\(odule\\|ethod\\)" + "\\|functor\\|and\\|val\\)[ \t]+" + "\\(\\('[a-zA-Z0-9]+\\|([^)]+)" + "\\|mutable\\|private\\|rec\\|type\\)[ \t]+\\)?" + "\\([a-zA-Z][a-zA-Z0-9_']*\\)")) + +;;; The major mode +(eval-when-compile + (if (and (boundp 'running-xemacs) running-xemacs) nil + (require 'imenu))) + +;; +(defvar caml-mode-hook nil + "Hook for caml-mode") + +(defun caml-mode () + "Major mode for editing Caml code. + +\\{caml-mode-map}" + + (interactive) + (kill-all-local-variables) + (setq major-mode 'caml-mode) + (setq mode-name "caml") + (use-local-map caml-mode-map) + (set-syntax-table caml-mode-syntax-table) + (setq local-abbrev-table caml-mode-abbrev-table) + (make-local-variable 'paragraph-start) + (setq paragraph-start (concat "^$\\|" page-delimiter)) + (make-local-variable 'paragraph-separate) + (setq paragraph-separate paragraph-start) + (make-local-variable 'paragraph-ignore-fill-prefix) + (setq paragraph-ignore-fill-prefix t) + (make-local-variable 'require-final-newline) + (setq require-final-newline t) + (make-local-variable 'comment-start) + (setq comment-start "(*") + (make-local-variable 'comment-end) + (setq comment-end "*)") + (make-local-variable 'comment-column) + (setq comment-column 40) + (make-local-variable 'comment-start-skip) + (setq comment-start-skip "(\\*+ *") + (make-local-variable 'parse-sexp-ignore-comments) + (setq parse-sexp-ignore-comments nil) + (make-local-variable 'indent-line-function) + (setq indent-line-function 'caml-indent-command) + ;itz Fri Sep 25 13:23:49 PDT 1998 + (make-local-variable 'add-log-current-defun-function) + (setq add-log-current-defun-function 'caml-current-defun) + ;itz 03-25-96 + (setq before-change-function 'caml-before-change-function) + (setq caml-last-noncomment-pos nil) + (setq caml-last-comment-start (make-marker)) + (setq caml-last-comment-end (make-marker)) + ;garrigue 27-11-96 + (setq case-fold-search nil) + ;garrigue july 97 + (if running-xemacs ; from Xemacs lisp mode + (if (and (featurep 'menubar) + current-menubar) + (progn + ;; make a local copy of the menubar, so our modes don't + ;; change the global menubar + (set-buffer-menubar current-menubar) + (add-submenu nil caml-mode-xemacs-menu))) + ;imenu support (not for Xemacs) + (make-local-variable 'imenu-create-index-function) + (setq imenu-create-index-function 'caml-create-index-function) + (make-local-variable 'imenu-generic-expression) + (setq imenu-generic-expression caml-imenu-search-regexp) + (if (and caml-imenu-enable (< (buffer-size) 10000)) + (caml-show-imenu))) + (run-hooks 'caml-mode-hook)) + +(defun caml-set-compile-command () + "Hook to set compile-command locally, unless there is a Makefile or + a _build directory or a _tags file in the current directory." + (interactive) + (unless (or (null buffer-file-name) + (file-exists-p "makefile") + (file-exists-p "Makefile") + (file-exists-p "_build") + (file-exists-p "_tags")) + (let* ((filename (file-name-nondirectory buffer-file-name)) + (basename (file-name-sans-extension filename)) + (command nil)) + (cond + ((string-match ".*\\.mli\$" filename) + (setq command "ocamlc -c")) + ((string-match ".*\\.ml\$" filename) + (setq command "ocamlc -c") ; (concat "ocamlc -o " basename) + ) + ((string-match ".*\\.mll\$" filename) + (setq command "ocamllex")) + ((string-match ".*\\.mll\$" filename) + (setq command "ocamlyacc")) + ) + (if command + (progn + (make-local-variable 'compile-command) + (setq compile-command (concat command " " filename)))) + ))) + +(add-hook 'caml-mode-hook 'caml-set-compile-command) + +;;; Auxiliary function. Garrigue 96-11-01. + +(defun caml-find-alternate-file () + (interactive) + (let ((name (buffer-file-name))) + (if (string-match "^\\(.*\\)\\.\\(ml\\|mli\\)$" name) + (find-file + (concat + (caml-match-string 1 name) + (if (string= "ml" (caml-match-string 2 name)) ".mli" ".ml")))))) + +;;; subshell support + +(defun caml-eval-region (start end) + "Send the current region to the inferior Caml process." + (interactive"r") + (require 'inf-caml) + (inferior-caml-eval-region start end)) + +;; old version ---to be deleted later +; +; (defun caml-eval-phrase () +; "Send the current Caml phrase to the inferior Caml process." +; (interactive) +; (save-excursion +; (let ((bounds (caml-mark-phrase))) +; (inferior-caml-eval-region (car bounds) (cdr bounds))))) + +(defun caml-eval-phrase (arg &optional min max) + "Send the phrase containing the point to the CAML process. +With prefix-arg send as many phrases as its numeric value, +If an error occurs during evalutaion, stop at this phrase and +repport the error. + +Return nil if noerror and position of error if any. + +If arg's numeric value is zero or negative, evaluate the current phrase +or as many as prefix arg, ignoring evaluation errors. +This allows to jump other erroneous phrases. + +Optional arguments min max defines a region within which the phrase +should lies." + (interactive "p") + (require 'inf-caml) + (inferior-caml-eval-phrase arg min max)) + +(defun caml-eval-buffer (arg) + "Evaluate the buffer from the beginning to the phrase under the point. +With prefix arg, evaluate past the whole buffer, no stopping at +the current point." + (interactive "p") + (let ((here (point)) err) + (goto-char (point-min)) + (setq err + (caml-eval-phrase 500 (point-min) (if arg (point-max) here))) + (if err (set-mark err)) + (goto-char here))) + +(defun caml-show-subshell () + (interactive) + (require 'inf-caml) + (inferior-caml-show-subshell)) + + +;;; Imenu support +(defun caml-show-imenu () + (interactive) + (require 'imenu) + (switch-to-buffer (current-buffer)) + (imenu-add-to-menubar "Defs") + (setq caml-imenu-shown t)) + +(defun caml-prev-index-position-function () + (let (found data) + (while (and (setq found + (re-search-backward caml-imenu-search-regexp nil 'move)) + (progn (setq data (match-data)) t) + (or (caml-in-literal-p) + (caml-in-comment-p) + (if (looking-at "in") (caml-find-in-match))))) + (set-match-data data) + found)) +(defun caml-create-index-function () + (let (value-alist + type-alist + class-alist + method-alist + module-alist + and-alist + all-alist + menu-alist + (prev-pos (point-max)) + index) + (goto-char prev-pos) + (imenu-progress-message prev-pos 0 t) + ;; collect definitions + (while (caml-prev-index-position-function) + (setq index (cons (caml-match-string 5) (point))) + (imenu-progress-message prev-pos nil t) + (setq all-alist (cons index all-alist)) + (cond + ((looking-at "[ \t]*and") + (setq and-alist (cons index and-alist))) + ((looking-at "[ \t]*let") + (setq value-alist (cons index (append and-alist value-alist))) + (setq and-alist nil)) + ((looking-at "[ \t]*type") + (setq type-alist (cons index (append and-alist type-alist))) + (setq and-alist nil)) + ((looking-at "[ \t]*class") + (setq class-alist (cons index (append and-alist class-alist))) + (setq and-alist nil)) + ((looking-at "[ \t]*val") + (setq value-alist (cons index value-alist))) + ((looking-at "[ \t]*\\(module\\|functor\\)") + (setq module-alist (cons index module-alist))) + ((looking-at "[ \t]*method") + (setq method-alist (cons index method-alist))))) + ;; build menu + (mapcar + '(lambda (pair) + (if (symbol-value (cdr pair)) + (setq menu-alist + (cons + (cons (car pair) + (sort (symbol-value (cdr pair)) 'imenu--sort-by-name)) + menu-alist)))) + '(("Values" . value-alist) + ("Types" . type-alist) + ("Modules" . module-alist) + ("Methods" . method-alist) + ("Classes" . class-alist))) + (if all-alist (setq menu-alist (cons (cons "Index" all-alist) menu-alist))) + (imenu-progress-message prev-pos 100 t) + menu-alist)) + +;;; Indentation stuff + +(defun caml-in-indentation () + "Tests whether all characters between beginning of line and point +are blanks." + (save-excursion + (skip-chars-backward " \t") + (bolp))) + +;;; The command +;;; Sorry, I didn't like the previous behaviour... Garrigue 96/11/01 + +(defun caml-indent-command (&optional p) + "Indent the current line in Caml mode. + +Compute new indentation based on caml syntax. If prefixed, indent +the line all the way to where point is." + + (interactive "*p") + (cond + ((and p (> p 1)) (indent-line-to (current-column))) + ((caml-in-indentation) (indent-line-to (caml-compute-final-indent))) + (t (save-excursion + (indent-line-to + (caml-compute-final-indent)))))) + +(defun caml-unindent-command () + + "Decrease indentation by one level in Caml mode. + +Works only if the point is at the beginning of an indented line +\(i.e. all characters between beginning of line and point are +blanks\). Does nothing otherwise. The unindent size is given by the +variable caml-mode-indentation." + + (interactive "*") + (let* ((begline + (save-excursion + (beginning-of-line) + (point))) + (current-offset + (- (point) begline))) + (if (and (>= current-offset caml-mode-indentation) + (caml-in-indentation)) + (backward-delete-char-untabify caml-mode-indentation)))) + +;;; +;;; Error processing +;;; + +;; Error positions are given in bytes, not in characters +;; This function switches to monobyte mode + +(if (not (fboundp 'char-bytes)) + (defalias 'forward-byte 'forward-char) + (defun caml-char-bytes (ch) + (let ((l (char-bytes ch))) + (if (> l 1) (- l 1) l))) + (defun forward-byte (count) + (if (> count 0) + (while (> count 0) + (let ((char (char-after))) + (if (null char) + (setq count 0) + (setq count (- count (caml-char-bytes (char-after)))) + (forward-char)))) + (while (< count 0) + (let ((char (char-after))) + (if (null char) + (setq count 0) + (setq count (+ count (caml-char-bytes (char-before)))) + (backward-char)))) + ))) + +(require 'compile) + +;; In Emacs 19, the regexps in compilation-error-regexp-alist do not +;; match the error messages when the language is not English. +;; Hence we add a regexp. + +(defconst caml-error-regexp + "^[ A-\377]+ \"\\([^\"\n]+\\)\", [A-\377]+ \\([0-9]+\\)[-,:]" + "Regular expression matching the error messages produced by camlc.") + +(if (boundp 'compilation-error-regexp-alist) + (or (assoc caml-error-regexp + compilation-error-regexp-alist) + (setq compilation-error-regexp-alist + (cons (list caml-error-regexp 1 2) + compilation-error-regexp-alist)))) + +;; A regexp to extract the range info + +(defconst caml-error-chars-regexp + ".*, .*, [A-\377]+ \\([0-9]+\\)-\\([0-9]+\\):?" + "Regular expression extracting the character numbers +from an error message produced by camlc.") + +;; Wrapper around next-error. + +(defvar caml-error-overlay nil) +(defvar caml-next-error-skip-warnings-flag nil) + +(defun caml-string-to-int (x) + (if (fboundp 'string-to-number) (string-to-number x) (string-to-int x))) + +;;itz 04-21-96 somebody didn't get the documentation for next-error +;;right. When the optional argument is a number n, it should move +;;forward n errors, not reparse. + +;itz 04-21-96 instead of defining a new function, use defadvice +;that way we get our effect even when we do \C-x` in compilation buffer + +(defadvice next-error (after caml-next-error activate) + "Reads the extra positional information provided by the Caml compiler. + +Puts the point and the mark exactly around the erroneous program +fragment. The erroneous fragment is also temporarily highlighted if +possible." + + (if (eq major-mode 'caml-mode) + (let (skip bol beg end) + (save-excursion + (set-buffer + (if (boundp 'compilation-last-buffer) + compilation-last-buffer ;Emacs 19 + "*compilation*")) ;Emacs 18 + (save-excursion + (goto-char (window-point (get-buffer-window (current-buffer)))) + (if (looking-at caml-error-chars-regexp) + (setq beg + (caml-string-to-int + (buffer-substring (match-beginning 1) (match-end 1))) + end + (caml-string-to-int + (buffer-substring (match-beginning 2) (match-end 2))))) + (next-line) + (beginning-of-line) + (if (and (looking-at "Warning") + caml-next-error-skip-warnings-flag) + (setq skip 't)))) + (cond + (skip (next-error)) + (beg + (setq end (- end beg)) + (beginning-of-line) + (forward-byte beg) + (setq beg (point)) + (forward-byte end) + (setq end (point)) + (goto-char beg) + (push-mark end t) + (cond ((fboundp 'make-overlay) + (if caml-error-overlay () + (setq caml-error-overlay (make-overlay 1 1)) + (overlay-put caml-error-overlay 'face 'region)) + (unwind-protect + (progn + (move-overlay caml-error-overlay + beg end (current-buffer)) + (sit-for 60)) + (delete-overlay caml-error-overlay))))))))) + +(defun caml-next-error-skip-warnings (&rest args) + (let ((old-flag caml-next-error-skip-warnings-flag)) + (unwind-protect + (progn (setq caml-next-error-skip-warnings-flag 't) + (apply 'next-error args)) + (setq caml-next-error-skip-warnings-flag old-flag)))) + + +;; Usual match-string doesn't work properly with font-lock-mode +;; on some emacs. + +(defun caml-match-string (num &optional string) + + "Return string of text matched by last search, without properties. + +NUM specifies which parenthesized expression in the last regexp. +Value is nil if NUMth pair didn't match, or there were less than NUM +pairs. Zero means the entire text matched by the whole regexp or +whole string." + + (let* ((data (match-data)) + (begin (nth (* 2 num) data)) + (end (nth (1+ (* 2 num)) data))) + (if string (substring string begin end) + (buffer-substring-no-properties begin end)))) + +;; itz Thu Sep 24 19:02:42 PDT 1998 this is to have some level of +;; comfort when sending phrases to the toplevel and getting errors. +(defun caml-goto-phrase-error () + "Find the error location in current Caml phrase." + (interactive) + (require 'inf-caml) + (let ((bounds (save-excursion (caml-mark-phrase)))) + (inferior-caml-goto-error (car bounds) (cdr bounds)))) + +;;; Phrases + +;itz the heuristics used to see if we're `between two phrases' +;didn't seem right to me. + +(defconst caml-phrase-start-keywords + (concat "\\<\\(class\\|ex\\(ternal\\|ception\\)\\|functor" + "\\|let\\|module\\|open\\|type\\|val\\)\\>") + "Keywords starting phrases in files") + +;; a phrase starts when a toplevel keyword is at the beginning of a line +(defun caml-at-phrase-start-p () + (and (bolp) + (or (looking-at "#") + (looking-at caml-phrase-start-keywords)))) + +(defun caml-skip-comments-forward () + (skip-chars-forward " \n\t") + (while (or (looking-at comment-start-skip) (caml-in-comment-p)) + (if (= (following-char) ?\)) (forward-char) + (search-forward comment-end)) + (skip-chars-forward " \n\t"))) + +(defun caml-skip-comments-backward () + (skip-chars-backward " \n\t") + (while (and (eq (preceding-char) ?\)) (eq (char-after (- (point) 2)) ?*)) + (backward-char) + (while (caml-in-comment-p) (search-backward comment-start)) + (skip-chars-backward " \n\t"))) + +(defconst caml-phrase-sep-keywords (concat ";;\\|" caml-phrase-start-keywords)) + +(defun caml-find-phrase (&optional min-pos max-pos) + "Find the CAML phrase containing the point. +Return the position of the beginning of the phrase, and move point +to the end. +" + (interactive) + (if (not min-pos) (setq min-pos (point-min))) + (if (not max-pos) (setq max-pos (point-max))) + (let (beg end use-semi kwop) + ;(caml-skip-comments-backward) + (cond + ; shall we have special processing for semicolons? + ;((and (eq (char-before (- (point) 1)) ?\;) (eq (char-before) ?\;)) + ; (forward-char) + ; (caml-skip-comments-forward) + ; (setq beg (point)) + ; (while (and (search-forward ";;" max-pos 'move) + ; (or (caml-in-comment-p) (caml-in-literal-p))))) + (t + (caml-skip-comments-forward) + (if (caml-at-phrase-start-p) (forward-char)) + (while (and (cond + ((re-search-forward caml-phrase-sep-keywords max-pos 'move) + (goto-char (match-beginning 0)) t)) + (or (not (or (bolp) (looking-at ";;"))) + (caml-in-comment-p) + (caml-in-literal-p))) + (forward-char)) + (setq end (+ (point) (if (looking-at ";;") 2 0))) + (while (and + (setq kwop (caml-find-kwop caml-phrase-sep-keywords min-pos)) + (not (string= kwop ";;")) + (not (bolp)))) + (if (string= kwop ";;") (forward-char 2)) + (if (not kwop) (goto-char min-pos)) + (caml-skip-comments-forward) + (setq beg (point)) + (if (>= beg end) (error "no phrase before point")) + (goto-char end))) + (caml-skip-comments-forward) + beg)) + +(defun caml-mark-phrase (&optional min-pos max-pos) + "Put mark at end of this Caml phrase, point at beginning. +" + (interactive) + (let* ((beg (caml-find-phrase min-pos max-pos)) (end (point))) + (push-mark) + (goto-char beg) + (cons beg end))) + +;;itz Fri Sep 25 12:58:13 PDT 1998 support for adding change-log entries +(defun caml-current-defun () + (save-excursion + (caml-mark-phrase) + (if (not (looking-at caml-phrase-start-keywords)) nil + (re-search-forward caml-phrase-start-keywords) + (let ((done nil)) + (while (not done) + (cond + ((looking-at "\\s ") + (skip-syntax-forward " ")) + ((char-equal (following-char) ?\( ) + (forward-sexp 1)) + ((char-equal (following-char) ?') + (skip-syntax-forward "w_")) + (t (setq done t))))) + (re-search-forward "\\(\\sw\\|\\s_\\)+") + (match-string 0)))) + +(defun caml-overlap (b1 e1 b2 e2) + (<= (max b1 b2) (min e1 e2))) + +;this clears the last comment cache if necessary +(defun caml-before-change-function (begin end) + (if (and caml-last-noncomment-pos + (> caml-last-noncomment-pos begin)) + (setq caml-last-noncomment-pos nil)) + (if (and (marker-position caml-last-comment-start) + (marker-position caml-last-comment-end) + (caml-overlap begin end + caml-last-comment-start + caml-last-comment-end)) + (prog2 + (set-marker caml-last-comment-start nil) + (set-marker caml-last-comment-end nil))) + (let ((orig-function (default-value 'before-change-function))) + (if orig-function (funcall orig-function begin end)))) + +(defun caml-in-literal-p () + "Returns non-nil if point is inside a caml literal." + (let* ((start-literal (concat "[\"" caml-quote-char "]")) + (char-literal + (concat "\\([^\\]\\|\\\\\\.\\|\\\\[0-9][0-9][0-9]\\)" + caml-quote-char)) + (pos (point)) + (eol (progn (end-of-line 1) (point))) + state in-str) + (beginning-of-line 1) + (while (and (not state) + (re-search-forward start-literal eol t) + (<= (point) pos)) + (cond + ((string= (caml-match-string 0) "\"") + (setq in-str t) + (while (and in-str (not state) + (re-search-forward "\"\\|\\\\\"" eol t)) + (if (> (point) pos) (setq state t)) + (if (string= (caml-match-string 0) "\"") (setq in-str nil))) + (if in-str (setq state t))) + ((looking-at char-literal) + (if (and (>= pos (match-beginning 0)) (< pos (match-end 0))) + (setq state t) + (goto-char (match-end 0)))))) + (goto-char pos) + state)) + +(defun caml-forward-comment () + "Skip one (eventually nested) comment." + (let ((count 1) match) + (while (> count 0) + (if (not (re-search-forward "(\\*\\|\\*)" nil 'move)) + (setq count -1) + (setq match (caml-match-string 0)) + (cond + ((caml-in-literal-p) + nil) + ((string= match comment-start) + (setq count (1+ count))) + (t + (setq count (1- count)))))) + (= count 0))) + +(defun caml-backward-comment () + "Skip one (eventually nested) comment." + (let ((count 1) match) + (while (> count 0) + (if (not (re-search-backward "(\\*\\|\\*)" nil 'move)) + (setq count -1) + (setq match (caml-match-string 0)) + (cond + ((caml-in-literal-p) + nil) + ((string= match comment-start) + (setq count (1- count))) + (t + (setq count (1+ count)))))) + (= count 0))) + +(defun caml-in-comment-p () + "Returns non-nil if point is inside a caml comment. +Returns nil for the parenthesis openning a comment." + ;;we look for comments differently than literals. there are two + ;;reasons for this. first, caml has nested comments and it is not so + ;;clear that parse-partial-sexp supports them; second, if proper + ;;style is used, literals are never split across lines, so we don't + ;;have to worry about bogus phrase breaks inside literals, while we + ;;have to account for that possibility in comments. + (if caml-last-comment-start + (save-excursion + (let* ((cached-pos caml-last-noncomment-pos) + (cached-begin (marker-position caml-last-comment-start)) + (cached-end (marker-position caml-last-comment-end))) + (cond + ((and cached-begin cached-end + (< cached-begin (point)) (< (point) cached-end)) t) + ((and cached-pos (= cached-pos (point))) nil) + ((and cached-pos (> cached-pos (point)) + (< (abs (- cached-pos (point))) caml-lookback-limit)) + (let (end found (here (point))) + ; go back to somewhere sure + (goto-char cached-pos) + (while (> (point) here) + ; look for the end of a comment + (while (and (if (search-backward comment-end (1- here) 'move) + (setq end (match-end 0)) + (setq end nil)) + (caml-in-literal-p))) + (if end (setq found (caml-backward-comment)))) + (if (and found (= (point) here)) (setq end nil)) + (if (not end) + (setq caml-last-noncomment-pos here) + (set-marker caml-last-comment-start (point)) + (set-marker caml-last-comment-end end)) + end)) + (t + (let (begin found (here (point))) + ;; go back to somewhere sure (or far enough) + (goto-char + (if cached-pos cached-pos (- (point) caml-lookback-limit))) + (while (< (point) here) + ;; look for the beginning of a comment + (while (and (if (search-forward comment-start (1+ here) 'move) + (setq begin (match-beginning 0)) + (setq begin nil)) + (caml-in-literal-p))) + (if begin (setq found (caml-forward-comment)))) + (if (and found (= (point) here)) (setq begin nil)) + (if (not begin) + (setq caml-last-noncomment-pos here) + (set-marker caml-last-comment-start begin) + (set-marker caml-last-comment-end (point))) + begin))))))) + +;; Various constants and regexps + +(defconst caml-before-expr-prefix + (concat "\\<\\(asr\\|begin\\|class\\|do\\(wnto\\)?\\|else" + "\\|i\\(f\\|n\\(herit\\|itializer\\)?\\)" + "\\|f\\(or\\|un\\(ct\\(ion\\|or\\)\\)?\\)" + "\\|l\\(and\\|or\\|s[lr]\\|xor\\)\\|m\\(atch\\|od\\)" + "\\|o[fr]\\|parser\\|s\\(ig\\|truct\\)\\|t\\(hen\\|o\\|ry\\)" + "\\|w\\(h\\(en\\|ile\\)\\|ith\\)\\)\\>\\|:begin\\>" + "\\|[=<>@^|&+-*/$%][!$%*+-./:<=>?@^|~]*\\|:[:=]\\|[[({,;]") + + "Keywords that may appear immediately before an expression. +Used to distinguish it from toplevel let construct.") + +(defconst caml-matching-kw-regexp + (concat + "\\<\\(and\\|do\\(ne\\)?\\|e\\(lse\\|nd\\)\\|in\\|t\\(hen\\|o\\)" + "\\|with\\)\\>\\|[^[|]|") + "Regexp used in caml mode for skipping back over nested blocks.") + +(defconst caml-matching-kw-alist + '(("|" . caml-find-pipe-match) + (";" . caml-find-semi-match) + ("," . caml-find-comma-match) + ("end" . caml-find-end-match) + ("done" . caml-find-done-match) + ("in" . caml-find-in-match) + ("with" . caml-find-with-match) + ("else" . caml-find-else-match) + ("then" . caml-find-then-match) + ("to" . caml-find-done-match) + ("do" . caml-find-done-match) + ("and" . caml-find-and-match)) + + "Association list used in caml mode for skipping back over nested blocks.") + +(defconst caml-kwop-regexps (make-vector 9 nil) + "Array of regexps representing caml keywords of different priorities.") + +(defun caml-in-expr-p () + (let ((pos (point)) (in-expr t)) + (caml-find-kwop + (concat caml-before-expr-prefix "\\|" + caml-matching-kw-regexp "\\|" + (aref caml-kwop-regexps caml-max-indent-priority))) + (cond + ; special case for ;; + ((and (> (point) 1) (= (preceding-char) ?\;) (= (following-char) ?\;)) + (setq in-expr nil)) + ((looking-at caml-before-expr-prefix) + (if (not (looking-at "(\\*")) (goto-char (match-end 0))) + (skip-chars-forward " \t\n") + (while (looking-at "(\\*") + (forward-char) + (caml-forward-comment) + (skip-chars-forward " \t\n")) + (if (<= pos (point)) (setq in-expr nil)))) + (goto-char pos) + in-expr)) + +(defun caml-at-sexp-close-p () + (or (char-equal ?\) (following-char)) + (char-equal ?\] (following-char)) + (char-equal ?} (following-char)))) + +(defun caml-find-kwop (kwop-regexp &optional min-pos) + "Look back for a caml keyword or operator matching KWOP-REGEXP. +Second optional argument MIN-POS bounds the search. + +Ignore occurences inside literals. If found, return a list of two +values: the actual text of the keyword or operator, and a boolean +indicating whether the keyword was one we looked for explicitly +{non-nil}, or on the other hand one of the block-terminating +keywords." + + (let ((start-literal (concat "[\"" caml-quote-char "]")) + found kwop) + (while (and (> (point) 1) (not found) + (re-search-backward kwop-regexp min-pos 'move)) + (setq kwop (caml-match-string 0)) + (cond + ((looking-at "(\\*") + (if (> (point) 1) (backward-char))) + ((caml-in-comment-p) + (search-backward "(" min-pos 'move)) + ((looking-at start-literal)) + ((caml-in-literal-p) + (re-search-backward start-literal min-pos 'move)) ;ugly hack + ((setq found t)))) + (if found + (if (not (string-match "\\`[^|[]|[^]|]?\\'" kwop)) ;arrrrgh!! + kwop + (forward-char 1) "|") nil))) + +; Association list of indentation values based on governing keywords. +; +;Each element is of the form (KEYWORD OP-TYPE PRIO INDENT). OP-TYPE is +;non-nil for operator-type nodes, which affect indentation in a +;different way from keywords: subsequent lines are indented to the +;actual occurrence of an operator, but relative to the indentation of +;the line where the governing keyword occurs. + +(defconst caml-no-indent 0) + +(defconst caml-kwop-alist + '(("begin" nil 6 caml-begin-indent) + (":begin" nil 6 caml-begin-indent) ; hack + ("class" nil 0 caml-class-indent) + ("constraint" nil 0 caml-val-indent) + ("sig" nil 1 caml-sig-indent) + ("struct" nil 1 caml-struct-indent) + ("exception" nil 0 caml-exception-indent) + ("for" nil 6 caml-for-indent) + ("fun" nil 3 caml-fun-indent) + ("function" nil 3 caml-function-indent) + ("if" nil 6 caml-if-indent) + ("if-else" nil 6 caml-if-else-indent) + ("include" nil 0 caml-include-indent) + ("inherit" nil 0 caml-inherit-indent) + ("initializer" nil 0 caml-initializer-indent) + ("let" nil 6 caml-let-indent) + ("let-in" nil 6 caml-let-in-indent) + ("match" nil 6 caml-match-indent) + ("method" nil 0 caml-method-indent) + ("module" nil 0 caml-module-indent) + ("object" nil 6 caml-object-indent) + ("of" nil 7 caml-of-indent) + ("open" nil 0 caml-no-indent) + ("parser" nil 3 caml-parser-indent) + ("try" nil 6 caml-try-indent) + ("type" nil 0 caml-type-indent) + ("val" nil 0 caml-val-indent) + ("when" nil 2 caml-if-indent) + ("while" nil 6 caml-while-indent) + ("::" t 5 caml-::-indent) + ("@" t 4 caml-@-indent) + ("^" t 4 caml-@-indent) + (":=" nil 3 caml-:=-indent) + ("<-" nil 3 caml-<--indent) + ("->" nil 2 caml-->-indent) + ("\[" t 8 caml-lb-indent) + ("{" t 8 caml-lc-indent) + ("\(" t 8 caml-lp-indent) + ("|" nil 2 caml-no-indent) + (";;" nil 0 caml-no-indent)) +; if-else and let-in are not keywords but idioms +; "|" is not in the regexps +; all these 3 values correspond to hard-coded names + +"Association list of indentation values based on governing keywords. + +Each element is of the form (KEYWORD OP-TYPE PRIO INDENT). OP-TYPE is +non-nil for operator-type nodes, which affect indentation in a +different way from keywords: subsequent lines are indented to the +actual occurrence of an operator, but relative to the indentation of +the line where the governing keyword occurs.") + +;;Originally, we had caml-kwop-regexp create these at runtime, from an +;;additional field in caml-kwop-alist. That proved way too slow, +;;although I still can't understand why. itz + +(aset caml-kwop-regexps 0 + (concat + "\\<\\(begin\\|object\\|for\\|s\\(ig\\|truct\\)\\|while\\)\\>" + "\\|:begin\\>\\|[[({]\\|;;")) +(aset caml-kwop-regexps 1 + (concat (aref caml-kwop-regexps 0) "\\|\\<\\(class\\|module\\)\\>")) +(aset caml-kwop-regexps 2 + (concat + (aref caml-kwop-regexps 1) + "\\|\\<\\(fun\\(ction\\)?\\|initializer\\|let\\|m\\(atch\\|ethod\\)" + "\\|parser\\|try\\|val\\)\\>\\|->")) +(aset caml-kwop-regexps 3 + (concat (aref caml-kwop-regexps 2) "\\|\\")) +(aset caml-kwop-regexps 4 + (concat (aref caml-kwop-regexps 3) "\\|:=\\|<-")) +(aset caml-kwop-regexps 5 + (concat (aref caml-kwop-regexps 4) "\\|@")) +(aset caml-kwop-regexps 6 + (concat (aref caml-kwop-regexps 5) "\\|::\\|\\^")) +(aset caml-kwop-regexps 7 + (concat + (aref caml-kwop-regexps 0) + "\\|\\<\\(constraint\\|exception\\|in\\(herit\\|clude\\)" + "\\|o\\(f\\|pen\\)\\|type\\|val\\)\\>")) +(aset caml-kwop-regexps 8 + (concat (aref caml-kwop-regexps 6) + "\\|\\<\\(constraint\\|exception\\|in\\(herit\\|clude\\)" + "\\|o\\(f\\|pen\\)\\|type\\)\\>")) + +(defun caml-find-done-match () + (let ((unbalanced 1) (kwop t)) + (while (and (not (= 0 unbalanced)) kwop) + (setq kwop (caml-find-kwop "\\<\\(done\\|for\\|while\\)\\>")) + (cond + ((not kwop)) + ((string= kwop "done") (setq unbalanced (1+ unbalanced))) + (t (setq unbalanced (1- unbalanced))))) + kwop)) + +(defun caml-find-end-match () + (let ((unbalanced 1) (kwop t)) + (while (and (not (= 0 unbalanced)) kwop) + (setq kwop + (caml-find-kwop + "\\<\\(end\\|begin\\|object\\|s\\(ig\\|truct\\)\\)\\>\\|:begin\\>\\|;;")) + (cond + ((not kwop)) + ((string= kwop ";;") (setq kwop nil) (forward-line 1)) + ((string= kwop "end") (setq unbalanced (1+ unbalanced))) + ( t (setq unbalanced (1- unbalanced))))) + (if (string= kwop ":begin") "begin" + kwop))) + +(defun caml-find-in-match () + (let ((unbalanced 1) (kwop t)) + (while (and (not (= 0 unbalanced)) kwop) + (setq kwop (caml-find-kwop "\\<\\(in\\|let\\|end\\)\\>")) + (cond + ((not kwop)) + ((string= kwop "end") (caml-find-end-match)) + ((string= kwop "in") (setq unbalanced (1+ unbalanced))) + (t (setq unbalanced (1- unbalanced))))) + kwop)) + +(defun caml-find-with-match () + (let ((unbalanced 1) (kwop t)) + (while (and (not (= 0 unbalanced)) kwop) + (setq kwop + (caml-find-kwop + "\\<\\(with\\|try\\|m\\(atch\\|odule\\)\\|functor\\)\\>\\|[{}()]")) + (cond + ((not kwop)) + ((caml-at-sexp-close-p) + (caml-find-paren-match (following-char))) + ((string= kwop "with") + (setq unbalanced (1+ unbalanced))) + ((or (string= kwop "module") + (string= kwop "functor") + (string= kwop "{") + (string= kwop "(")) + (setq unbalanced 0)) + (t (setq unbalanced (1- unbalanced))))) + kwop)) + +(defun caml-find-paren-match (close) + (let ((unbalanced 1) + (regexp (cond ((= close ?\)) "[()]") + ((= close ?\]) "[][]") + ((= close ?\}) "[{}]")))) + (while (and (> unbalanced 0) + (caml-find-kwop regexp)) + (if (= close (following-char)) + (setq unbalanced (1+ unbalanced)) + (setq unbalanced (1- unbalanced)))))) + +(defun caml-find-then-match (&optional from-else) + (let ((bol (if from-else + (save-excursion + (progn (beginning-of-line) (point))))) + kwop done matching-fun) + (while (not done) + (setq kwop + (caml-find-kwop + "\\<\\(e\\(nd\\|lse\\)\\|done\\|then\\|if\\|with\\)\\>\\|[])};]")) + (cond + ((not kwop) (setq done t)) + ((caml-at-sexp-close-p) + (caml-find-paren-match (following-char))) + ((string= kwop "if") (setq done t)) + ((string= kwop "then") + (if (not from-else) (setq kwop (caml-find-then-match)))) + ((setq matching-fun (cdr-safe (assoc kwop caml-matching-kw-alist))) + (setq kwop (funcall matching-fun))))) + (if (and bol (>= (point) bol)) + "if-else" + kwop))) + +(defun caml-find-pipe-match () + (let ((done nil) (kwop) + (re (concat + "\\<\\(try\\|match\\|with\\|function\\|parser\\|type" + "\\|e\\(nd\\|lse\\)\\|done\\|then\\|in\\)\\>" + "\\|[^[|]|\\|[])}]"))) + (while (not done) + (setq kwop (caml-find-kwop re)) + (cond + ((not kwop) (setq done t)) + ((looking-at "[^[|]\\(|\\)") + (goto-char (match-beginning 1)) + (setq kwop "|") + (setq done t)) + ((caml-at-sexp-close-p) + (caml-find-paren-match (following-char))) + ((string= kwop "with") + (setq kwop (caml-find-with-match)) + (setq done t)) + ((string= kwop "parser") + (if (re-search-backward "\\" (- (point) 5) t) + (setq kwop (caml-find-with-match))) + (setq done t)) + ((string= kwop "done") (caml-find-done-match)) + ((string= kwop "end") (caml-find-end-match)) + ((string= kwop "then") (caml-find-then-match)) + ((string= kwop "else") (caml-find-else-match)) + ((string= kwop "in") (caml-find-in-match)) + (t (setq done t)))) + kwop)) + +(defun caml-find-and-match () + (let ((done nil) (kwop)) + (while (not done) + (setq kwop (caml-find-kwop + "\\<\\(object\\|exception\\|let\\|type\\|end\\|in\\)\\>")) + (cond + ((not kwop) (setq done t)) + ((string= kwop "end") (caml-find-end-match)) + ((string= kwop "in") (caml-find-in-match)) + (t (setq done t)))) + kwop)) + +(defun caml-find-else-match () + (caml-find-then-match t)) + +(defun caml-find-semi-match () + (caml-find-kwop-skipping-blocks 2)) + +(defun caml-find-comma-match () + (caml-find-kwop-skipping-blocks 3)) + +(defun caml-find-kwop-skipping-blocks (prio) + "Look back for a caml keyword matching caml-kwop-regexps [PRIO]. + + Skip nested blocks." + + (let ((done nil) (kwop nil) (matching-fun) + (kwop-list (aref caml-kwop-regexps prio))) + (while (not done) + (setq kwop (caml-find-kwop + (concat caml-matching-kw-regexp + (cond ((> prio 3) "\\|[])},;]\\|") + ((> prio 2) "\\|[])};]\\|") + (t "\\|[])}]\\|")) + kwop-list))) + (cond + ((not kwop) (setq done t)) + ((caml-at-sexp-close-p) + (caml-find-paren-match (following-char))) + ((or (string= kwop ";;") + (and (string= kwop ";") (= (preceding-char) ?\;))) + (forward-line 1) + (setq kwop ";;") + (setq done t)) + ((and (>= prio 2) (string= kwop "|")) (setq done t)) + ((string= kwop "end") (caml-find-end-match)) + ((string= kwop "done") (caml-find-done-match)) + ((string= kwop "in") + (cond ((and (caml-find-in-match) (>= prio 2)) + (setq kwop "let-in") + (setq done t)))) + ((and (string= kwop "parser") (>= prio 2) + (re-search-backward "\\" (- (point) 5) t)) + (setq kwop (caml-find-with-match)) + (setq done t)) + ((setq matching-fun (cdr-safe (assoc kwop caml-matching-kw-alist))) + (setq kwop (funcall matching-fun)) + (if (looking-at kwop-list) (setq done t))) + (t (let* ((kwop-info (assoc kwop caml-kwop-alist)) + (is-op (and (nth 1 kwop-info) + ; check that we are not at beginning of line + (let ((pos (point)) bti) + (back-to-indentation) + (setq bti (point)) + (goto-char pos) + (< bti pos))))) + (if (and is-op (looking-at + (concat (regexp-quote kwop) + "|?[ \t]*\\(\n\\|(\\*\\)"))) + (setq kwop-list + (aref caml-kwop-regexps (nth 2 kwop-info))) + (setq done t)))))) + kwop)) + +(defun caml-compute-basic-indent (prio) + "Compute indent of current caml line, ignoring leading keywords. + +Find the `governing node' for current line. Compute desired +indentation based on the node and the indentation alists. +Assumes point is exactly at line indentation. +Does not preserve point." + + (let* (in-expr + (kwop (cond + ((looking-at ";;") + (beginning-of-line 1)) + ((looking-at "|\\([^]|]\\|\\'\\)") + (caml-find-pipe-match)) + ((and (looking-at caml-phrase-start-keywords) + (caml-in-expr-p)) + (caml-find-end-match)) + ((and (looking-at caml-matching-kw-regexp) + (assoc (caml-match-string 0) caml-matching-kw-alist)) + (funcall (cdr-safe (assoc (caml-match-string 0) + caml-matching-kw-alist)))) + ((looking-at + (aref caml-kwop-regexps caml-max-indent-priority)) + (let* ((kwop (caml-match-string 0)) + (kwop-info (assoc kwop caml-kwop-alist)) + (prio (if kwop-info (nth 2 kwop-info) + caml-max-indent-priority))) + (if (and (looking-at (aref caml-kwop-regexps 0)) + (not (looking-at "object")) + (caml-in-expr-p)) + (setq in-expr t)) + (caml-find-kwop-skipping-blocks prio))) + (t + (if (and (= prio caml-max-indent-priority) (caml-in-expr-p)) + (setq in-expr t)) + (caml-find-kwop-skipping-blocks prio)))) + (kwop-info (assoc kwop caml-kwop-alist)) + (indent-diff + (cond + ((not kwop-info) (beginning-of-line 1) 0) + ((looking-at "[[({][|<]?[ \t]*") + (length (caml-match-string 0))) + ((nth 1 kwop-info) (symbol-value (nth 3 kwop-info))) + (t + (let ((pos (point))) + (back-to-indentation) +; (if (looking-at "\\") (goto-char pos)) + (- (symbol-value (nth 3 kwop-info)) + (if (looking-at "|") caml-|-extra-indent 0)))))) + (extra (if in-expr caml-apply-extra-indent 0))) + (+ indent-diff extra (current-column)))) + +(defconst caml-leading-kwops-regexp + (concat + "\\<\\(and\\|do\\(ne\\)?\\|e\\(lse\\|nd\\)\\|in" + "\\|t\\(hen\\|o\\)\\|with\\)\\>\\|[]|})]") + + "Regexp matching caml keywords which need special indentation.") + +(defconst caml-leading-kwops-alist + '(("and" caml-and-extra-indent 2) + ("do" caml-do-extra-indent 0) + ("done" caml-done-extra-indent 0) + ("else" caml-else-extra-indent 3) + ("end" caml-end-extra-indent 0) + ("in" caml-in-extra-indent 2) + ("then" caml-then-extra-indent 3) + ("to" caml-to-extra-indent 0) + ("with" caml-with-extra-indent 2) + ("|" caml-|-extra-indent 2) + ("]" caml-rb-extra-indent 0) + ("}" caml-rc-extra-indent 0) + (")" caml-rp-extra-indent 0)) + + "Association list of special caml keyword indent values. + +Each member is of the form (KEYWORD EXTRA-INDENT PRIO) where +EXTRA-INDENT is the variable holding extra indentation amount for +KEYWORD (usually negative) and PRIO is upper bound on priority of +matching nodes to determine KEYWORD's final indentation.") + +(defun caml-compute-final-indent () + (save-excursion + (back-to-indentation) + (cond + ((and (bolp) (looking-at comment-start-skip)) (current-column)) + ((caml-in-comment-p) + (let ((closing (looking-at "\\*)")) + (comment-mark (looking-at "\\*"))) + (caml-backward-comment) + (looking-at comment-start-skip) + (+ (current-column) + (cond + (closing 1) + (comment-mark 1) + (t (- (match-end 0) (match-beginning 0))))))) + (t (let* ((leading (looking-at caml-leading-kwops-regexp)) + (assoc-val (if leading (assoc (caml-match-string 0) + caml-leading-kwops-alist))) + (extra (if leading (symbol-value (nth 1 assoc-val)) 0)) + (prio (if leading (nth 2 assoc-val) + caml-max-indent-priority)) + (basic (caml-compute-basic-indent prio))) + (max 0 (if extra (+ extra basic) (current-column)))))))) + + + +(defun caml-split-string () + "Called whenever a line is broken inside a caml string literal." + (insert-before-markers "\"^\"") + (backward-char 1)) + +(defadvice indent-new-comment-line (around + caml-indent-new-comment-line + activate) + + "Handle multi-line strings in caml mode." + +;this advice doesn't make sense in other modes. I wish there were a +;cleaner way to do this: I haven't found one. + + (let ((hooked (and (eq major-mode 'caml-mode) (caml-in-literal-p))) + (split-mark)) + (if (not hooked) nil + (setq split-mark (set-marker (make-marker) (point))) + (caml-split-string)) + ad-do-it + (if (not hooked) nil + (goto-char split-mark) + (set-marker split-mark nil)))) + +(defadvice newline-and-indent (around + caml-newline-and-indent + activate) + + "Handle multi-line strings in caml mode." + + (let ((hooked (and (eq major-mode 'caml-mode) (caml-in-literal-p))) + (split-mark)) + (if (not hooked) nil + (setq split-mark (set-marker (make-marker) (point))) + (caml-split-string)) + ad-do-it + (if (not hooked) nil + (goto-char split-mark) + (set-marker split-mark nil)))) + +(defun caml-electric-pipe () + "If inserting a | or } operator at beginning of line, reindent the line. + +Unfortunately there is a situation where this mechanism gets +confused. It's when | is the first character of a |] sequence. This is +a misfeature of caml syntax and cannot be fixed, however, as a +workaround, the electric ] inserts | itself if the matching [ is +followed by |." + + (interactive "*") + (let ((electric (and caml-electric-indent + (caml-in-indentation) + (not (caml-in-comment-p))))) + (self-insert-command 1) + (if electric (save-excursion (caml-indent-command))))) + +(defun caml-electric-rb () + "If inserting a ] operator at beginning of line, reindent the line. + +Also, if the matching [ is followed by a | and this ] is not preceded +by |, insert one." + + (interactive "*") + (let* ((prec (preceding-char)) + (use-pipe (and caml-electric-close-vector + (not (caml-in-comment-p)) + (not (caml-in-literal-p)) + (or (not (numberp prec)) + (not (char-equal ?| prec))))) + (electric (and caml-electric-indent + (caml-in-indentation) + (not (caml-in-comment-p))))) + (self-insert-command 1) + (if electric (save-excursion (caml-indent-command))) + (if (and use-pipe + (save-excursion + (condition-case nil + (prog2 + (backward-list 1) + (looking-at "\\[|")) + (error "")))) + (save-excursion + (backward-char 1) + (insert "|"))))) + +(defun caml-abbrev-hook () + "If inserting a leading keyword at beginning of line, reindent the line." + ;itz unfortunately we need a special case + (if (and (not (caml-in-comment-p)) (not (= last-command-char ?_))) + (let* ((bol (save-excursion (beginning-of-line) (point))) + (kw (save-excursion + (and (re-search-backward "^[ \t]*\\(\\sw+\\)\\=" bol t) + (caml-match-string 1))))) + (if kw + (let ((indent (save-excursion + (goto-char (match-beginning 1)) + (caml-indent-command) + (current-column))) + (abbrev-correct (if (= last-command-char ?\ ) 1 0))) + (indent-to (- indent + (or + (symbol-value + (nth 1 + (assoc kw caml-leading-kwops-alist))) + 0) + abbrev-correct))))))) + +; (defun caml-indent-phrase () +; (interactive "*") +; (let ((bounds (caml-mark-phrase))) +; (indent-region (car bounds) (cdr bounds) nil))) + +;;; Additional commands by Didier to report errors in toplevel mode + +(defun caml-skip-blank-forward () + (if (looking-at "[ \t\n]*\\((\\*\\([^*]\\|[^(]\\*[^)]\\)*\\*)[ \t\n]*\\)*") + (goto-char (match-end 0)))) + +;; to mark phrases, so that repeated calls will take several of them +;; knows little about Ocaml appart literals and comments, so it should work +;; with other dialects as long as ;; marks the end of phrase. + +(defun caml-indent-phrase (arg) + "Indent current phrase +with prefix arg, indent that many phrases starting with the current phrase." + (interactive "p") + (save-excursion + (let ((beg (caml-find-phrase))) + (while (progn (setq arg (- arg 1)) (> arg 0)) (caml-find-phrase)) + (indent-region beg (point) nil)))) + +(defun caml-indent-buffer () + (interactive) + (indent-region (point-min) (point-max) nil)) + +(defun caml-backward-to-less-indent (&optional n) + "Move cursor back N lines with less or same indentation." + (interactive "p") + (beginning-of-line 1) + (if (< n 0) (caml-forward-to-less-indent (- n)) + (while (> n 0) + (let ((i (current-indentation))) + (forward-line -1) + (while (or (> (current-indentation) i) + (caml-in-comment-p) + (looking-at + (concat "[ \t]*\\(\n\\|" comment-start-skip "\\)"))) + (forward-line -1))) + (setq n (1- n)))) + (back-to-indentation)) + +(defun caml-forward-to-less-indent (&optional n) + "Move cursor back N lines with less or same indentation." + (interactive "p") + (beginning-of-line 1) + (if (< n 0) (caml-backward-to-less-indent (- n)) + (while (> n 0) + (let ((i (current-indentation))) + (forward-line 1) + (while (or (> (current-indentation) i) + (caml-in-comment-p) + (looking-at + (concat "[ \t]*\\(\n\\|" comment-start-skip "\\)"))) + (forward-line 1))) + (setq n (1- n)))) + (back-to-indentation)) + +(defun caml-insert-begin-form () + "Inserts a nicely formatted begin-end form, leaving a mark after end." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-begin-indent c))) + (insert "begin\n\nend") + (push-mark) + (indent-line-to c) + (forward-line -1) + (indent-line-to i))) + +(defun caml-insert-for-form () + "Inserts a nicely formatted for-do-done form, leaving a mark after do(ne)." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-for-indent c))) + (insert "for do\n\ndone") + (push-mark) + (indent-line-to c) + (forward-line -1) + (indent-line-to i) + (push-mark) + (beginning-of-line 1) + (backward-char 4))) + +(defun caml-insert-if-form () + "Insert nicely formatted if-then-else form leaving mark after then, else." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-if-indent c))) + (insert "if\n\nthen\n\nelse\n") + (indent-line-to i) + (push-mark) + (forward-line -1) + (indent-line-to c) + (forward-line -1) + (indent-line-to i) + (push-mark) + (forward-line -1) + (indent-line-to c) + (forward-line -1) + (indent-line-to i))) + +(defun caml-insert-match-form () + "Insert nicely formatted match-with form leaving mark after with." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-match-indent c))) + (insert "match\n\nwith\n") + (indent-line-to i) + (push-mark) + (forward-line -1) + (indent-line-to c) + (forward-line -1) + (indent-line-to i))) + +(defun caml-insert-let-form () + "Insert nicely formatted let-in form leaving mark after in." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation))) + (insert "let in\n") + (indent-line-to c) + (push-mark) + (forward-line -1) + (forward-char (+ c 4)))) + +(defun caml-insert-try-form () + "Insert nicely formatted try-with form leaving mark after with." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-try-indent c))) + (insert "try\n\nwith\n") + (indent-line-to i) + (push-mark) + (forward-line -1) + (indent-line-to c) + (forward-line -1) + (indent-line-to i))) + +(defun caml-insert-while-form () + "Insert nicely formatted while-do-done form leaving mark after do, done." + (interactive "*") + (let ((prec (preceding-char))) + (if (and (numberp prec) (not (char-equal ?\ (char-syntax prec)))) + (insert " "))) + (let* ((c (current-indentation)) (i (+ caml-if-indent c))) + (insert "while do\n\ndone") + (push-mark) + (indent-line-to c) + (forward-line -1) + (indent-line-to i) + (push-mark) + (beginning-of-line 1) + (backward-char 4))) + +(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t) + +(autoload 'caml-types-show-type "caml-types" + "Show the type of expression or pattern at point." t) +(autoload 'caml-types-explore "caml-types" + "Explore type annotations by mouse dragging." t) + +(autoload 'caml-help "caml-help" + "Show documentation for qualilifed OCaml identifier." t) +(autoload 'caml-complete "caml-help" + "Does completion for documented qualified OCaml identifier." t) +(autoload 'ocaml-open-module "caml-help" + "Add module in documentation search path." t) +(autoload 'ocaml-close-module "caml-help" + "Remove module from documentation search path." t) +(autoload 'ocaml-add-path "caml-help" + "Add search path for documentation." t) + +;;; caml.el ends here + +(provide 'caml) diff --git a/emacs/camldebug.el b/emacs/camldebug.el new file mode 100644 index 0000000..9098497 --- /dev/null +++ b/emacs/camldebug.el @@ -0,0 +1,784 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Jacques Garrigue and Ian T Zimmerman *) +;(* *) +;(* Copyright 1997 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: camldebug.el,v 1.11 2005-10-26 13:23:12 doligez Exp $ *) + +;;; Run camldebug under Emacs +;;; Derived from gdb.el. +;;; gdb.el is Copyright (C) 1988 Free Software Foundation, Inc, and is part +;;; of GNU Emacs +;;; Modified by Jerome Vouillon, 1994. +;;; Modified by Ian T. Zimmerman, 1996. +;;; Modified by Xavier Leroy, 1997. + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 1, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;;itz 04-06-96 I pondered basing this on gud. The potential advantages +;;were: automatic bugfix , keymaps and menus propagation. +;;Disadvantages: gud is not so clean itself, there is little common +;;functionality it abstracts (most of the stuff is done in the +;;debugger specific parts anyway), and, most seriously, gud sees it +;;fit to add C-x C-a bindings to the _global_ map, so there would be a +;;conflict between camldebug and gdb, for instance. While it's OK to +;;assume that a sane person doesn't use gdb and dbx at the same time, +;;it's not so OK (IMHO) for gdb and camldebug. + +;; Xavier Leroy, 21/02/97: adaptation to ocamldebug. + +(require 'comint) +(require 'shell) +(require 'caml) +(require 'derived) +(require 'thingatpt) + +;;; Variables. + +(defvar camldebug-last-frame) +(defvar camldebug-delete-prompt-marker) +(defvar camldebug-filter-accumulator nil) +(defvar camldebug-last-frame-displayed-p) +(defvar camldebug-filter-function) + +(defvar camldebug-prompt-pattern "^(ocd) *" + "A regexp to recognize the prompt for ocamldebug.") + +(defvar camldebug-overlay-event nil + "Overlay for displaying the current event.") +(defvar camldebug-overlay-under nil + "Overlay for displaying the current event.") +(defvar camldebug-event-marker nil + "Marker for displaying the current event.") + +(defvar camldebug-track-frame t + "*If non-nil, always display current frame position in another window.") + +(cond + (window-system + (make-face 'camldebug-event) + (make-face 'camldebug-underline) + (if (not (face-differs-from-default-p 'camldebug-event)) + (invert-face 'camldebug-event)) + (if (not (face-differs-from-default-p 'camldebug-underline)) + (set-face-underline-p 'camldebug-underline t)) + (setq camldebug-overlay-event (make-overlay 1 1)) + (overlay-put camldebug-overlay-event 'face 'camldebug-event) + (setq camldebug-overlay-under (make-overlay 1 1)) + (overlay-put camldebug-overlay-under 'face 'camldebug-underline)) + (t + (setq camldebug-event-marker (make-marker)) + (setq overlay-arrow-string "=>"))) + +;;; Camldebug mode. + +(define-derived-mode camldebug-mode comint-mode "Inferior CDB" + + "Major mode for interacting with an inferior Camldebug process. + +The following commands are available: + +\\{camldebug-mode-map} + +\\[camldebug-display-frame] displays in the other window +the last line referred to in the camldebug buffer. + +\\[camldebug-step], \\[camldebug-back] and \\[camldebug-next], in the camldebug window, +call camldebug to step, backstep or next and then update the other window +with the current file and position. + +If you are in a source file, you may select a point to break +at, by doing \\[camldebug-break]. + +Commands: +Many commands are inherited from comint mode. +Additionally we have: + +\\[camldebug-display-frame] display frames file in other window +\\[camldebug-step] advance one line in program +C-x SPACE sets break point at current line." + + (mapcar 'make-local-variable + '(camldebug-last-frame-displayed-p camldebug-last-frame + camldebug-delete-prompt-marker camldebug-filter-function + camldebug-filter-accumulator paragraph-start)) + (setq + camldebug-last-frame nil + camldebug-delete-prompt-marker (make-marker) + camldebug-filter-accumulator "" + camldebug-filter-function 'camldebug-marker-filter + comint-prompt-regexp camldebug-prompt-pattern + comint-dynamic-complete-functions (cons 'camldebug-complete + comint-dynamic-complete-functions) + paragraph-start comint-prompt-regexp + camldebug-last-frame-displayed-p t) + (make-local-variable 'shell-dirtrackp) + (setq shell-dirtrackp t) + (setq comint-input-sentinel 'shell-directory-tracker)) + +;;; Keymaps. + +(defun camldebug-numeric-arg (arg) + (and arg (prefix-numeric-value arg))) + +(defmacro def-camldebug (name key &optional doc args) + + "Define camldebug-NAME to be a command sending NAME ARGS and bound +to KEY, with optional doc string DOC. Certain %-escapes in ARGS are +interpreted specially if present. These are: + + %m module name of current module. + %d directory of current source file. + %c number of current character position + %e text of the caml variable surrounding point. + + The `current' source file is the file of the current buffer (if +we're in a caml buffer) or the source file current at the last break +or step (if we're in the camldebug buffer), and the `current' module +name is the filename stripped of any *.ml* suffixes (this assumes the +usual correspondence between module and file naming is observed). The +`current' position is that of the current buffer (if we're in a source +file) or the position of the last break or step (if we're in the +camldebug buffer). + +If a numeric is present, it overrides any ARGS flags and its string +representation is simply concatenated with the COMMAND." + + (let* ((fun (intern (format "camldebug-%s" name)))) + (list 'progn + (if doc + (list 'defun fun '(arg) + doc + '(interactive "P") + (list 'camldebug-call name args + '(camldebug-numeric-arg arg)))) + (list 'define-key 'camldebug-mode-map + (concat "\C-c" key) + (list 'quote fun)) + (list 'define-key 'caml-mode-map + (concat "\C-x\C-a" key) + (list 'quote fun))))) + +(def-camldebug "step" "\C-s" "Step one event forward.") +(def-camldebug "backstep" "\C-k" "Step one event backward.") +(def-camldebug "run" "\C-r" "Run the program.") +(def-camldebug "reverse" "\C-v" "Run the program in reverse.") +(def-camldebug "last" "\C-l" "Go to latest time in execution history.") +(def-camldebug "backtrace" "\C-t" "Print the call stack.") +(def-camldebug "finish" "\C-f" "Finish executing current function.") +(def-camldebug "print" "\C-p" "Print value of symbol at point." "%e") +(def-camldebug "display" "\C-d" "Display value of symbol at point." "%e") +(def-camldebug "next" "\C-n" "Step one event forward (skip functions)") +(def-camldebug "up" "<" "Go up N stack frames (numeric arg) with display") +(def-camldebug "down" ">" "Go down N stack frames (numeric arg) with display") +(def-camldebug "break" "\C-b" "Set breakpoint at current line." + "@ \"%m\" # %c") + +(defun camldebug-mouse-display (click) + "Display value of $NNN clicked on." + (interactive "e") + (let* ((start (event-start click)) + (window (car start)) + (pos (car (cdr start))) + symb) + (save-excursion + (select-window window) + (goto-char pos) + (setq symb (thing-at-point 'symbol)) + (if (string-match "^\\$[0-9]+$" symb) + (camldebug-call "display" symb))))) + +(define-key camldebug-mode-map [mouse-2] 'camldebug-mouse-display) + +(defun camldebug-kill-filter (string) + ;gob up stupid questions :-) + (setq camldebug-filter-accumulator + (concat camldebug-filter-accumulator string)) + (if (not (string-match "\\(.* \\)(y or n) " + camldebug-filter-accumulator)) nil + (setq camldebug-kill-output + (cons t (match-string 1 camldebug-filter-accumulator))) + (setq camldebug-filter-accumulator "")) + (if (string-match comint-prompt-regexp camldebug-filter-accumulator) + (let ((output (substring camldebug-filter-accumulator + (match-beginning 0)))) + (setq camldebug-kill-output + (cons nil (substring camldebug-filter-accumulator 0 + (1- (match-beginning 0))))) + (setq camldebug-filter-accumulator "") + output) + "")) + +(def-camldebug "kill" "\C-k") + +(defun camldebug-kill () + "Kill the program." + (interactive) + (let ((camldebug-kill-output)) + (save-excursion + (set-buffer current-camldebug-buffer) + (let ((proc (get-buffer-process (current-buffer))) + (camldebug-filter-function 'camldebug-kill-filter)) + (camldebug-call "kill") + (while (not (and camldebug-kill-output + (zerop (length camldebug-filter-accumulator)))) + (accept-process-output proc)))) + (if (not (car camldebug-kill-output)) + (error (cdr camldebug-kill-output)) + (sit-for 0 300) + (camldebug-call-1 (if (y-or-n-p (cdr camldebug-kill-output)) "y" "n"))))) +;;FIXME: camldebug doesn't output the Hide marker on kill + +(defun camldebug-goto-filter (string) + ;accumulate onto previous output + (setq camldebug-filter-accumulator + (concat camldebug-filter-accumulator string)) + (if (not (or (string-match (concat "\\(\n\\|\\`\\)[ \t]*\\([0-9]+\\)[ \t]+" + camldebug-goto-position + "-[0-9]+[ \t]*\\(before\\).*\n") + camldebug-filter-accumulator) + (string-match (concat "\\(\n\\|\\`\\)[ \t]*\\([0-9]+\\)[ \t]+[0-9]+-" + camldebug-goto-position + "[ \t]*\\(after\\).*\n") + camldebug-filter-accumulator))) + nil + (setq camldebug-goto-output + (match-string 2 camldebug-filter-accumulator)) + (setq camldebug-filter-accumulator + (substring camldebug-filter-accumulator (1- (match-end 0))))) + (if (not (string-match comint-prompt-regexp + camldebug-filter-accumulator)) nil + (setq camldebug-goto-output (or camldebug-goto-output 'fail)) + (setq camldebug-filter-accumulator "")) + (if (string-match "\n\\(.*\\)\\'" camldebug-filter-accumulator) + (setq camldebug-filter-accumulator + (match-string 1 camldebug-filter-accumulator))) + "") + +(def-camldebug "goto" "\C-g") +(defun camldebug-goto (&optional time) + + "Go to the execution time TIME. + +Without TIME, the command behaves as follows: In the camldebug buffer, +if the point at buffer end, goto time 0\; otherwise, try to obtain the +time from context around point. In a caml mode buffer, try to find the +time associated in execution history with the current point location. + +With a negative TIME, move that many lines backward in the camldebug +buffer, then try to obtain the time from context around point." + + (interactive "P") + (cond + (time + (let ((ntime (camldebug-numeric-arg time))) + (if (>= ntime 0) (camldebug-call "goto" nil ntime) + (save-selected-window + (select-window (get-buffer-window current-camldebug-buffer)) + (save-excursion + (if (re-search-backward "^Time : [0-9]+ - pc : [0-9]+ " + nil t (- 1 ntime)) + (camldebug-goto nil) + (error "I don't have %d times in my history" + (- 1 ntime)))))))) + ((eq (current-buffer) current-camldebug-buffer) + (let ((time (cond + ((eobp) 0) + ((save-excursion + (beginning-of-line 1) + (looking-at "^Time : \\([0-9]+\\) - pc : [0-9]+ ")) + (string-to-int (match-string 1))) + ((string-to-int (camldebug-format-command "%e")))))) + (camldebug-call "goto" nil time))) + (t + (let ((module (camldebug-module-name (buffer-file-name))) + (camldebug-goto-position (int-to-string (1- (point)))) + (camldebug-goto-output) (address)) + ;get a list of all events in the current module + (save-excursion + (set-buffer current-camldebug-buffer) + (let* ((proc (get-buffer-process (current-buffer))) + (camldebug-filter-function 'camldebug-goto-filter)) + (camldebug-call-1 (concat "info events " module)) + (while (not (and camldebug-goto-output + (zerop (length camldebug-filter-accumulator)))) + (accept-process-output proc)) + (setq address (if (eq camldebug-goto-output 'fail) nil + (re-search-backward + (concat "^Time : \\([0-9]+\\) - pc : " + camldebug-goto-output + " - module " + module "$") nil t) + (match-string 1))))) + (if address (camldebug-call "goto" nil (string-to-int address)) + (error "No time at %s at %s" module camldebug-goto-position)))))) + + +(defun camldebug-delete-filter (string) + (setq camldebug-filter-accumulator + (concat camldebug-filter-accumulator string)) + (if (not (string-match + (concat "\\(\n\\|\\`\\)[ \t]*\\([0-9]+\\)[ \t]+[0-9]+[ \t]*in " + (regexp-quote camldebug-delete-file) + ", character " + camldebug-delete-position "\n") + camldebug-filter-accumulator)) nil + (setq camldebug-delete-output + (match-string 2 camldebug-filter-accumulator)) + (setq camldebug-filter-accumulator + (substring camldebug-filter-accumulator (1- (match-end 0))))) + (if (not (string-match comint-prompt-regexp + camldebug-filter-accumulator)) nil + (setq camldebug-delete-output (or camldebug-delete-output 'fail)) + (setq camldebug-filter-accumulator "")) + (if (string-match "\n\\(.*\\)\\'" camldebug-filter-accumulator) + (setq camldebug-filter-accumulator + (match-string 1 camldebug-filter-accumulator))) + "") + + +(def-camldebug "delete" "\C-d") + +(defun camldebug-delete (&optional arg) + "Delete the breakpoint numbered ARG. + +Without ARG, the command behaves as follows: In the camldebug buffer, +try to obtain the time from context around point. In a caml mode +buffer, try to find the breakpoint associated with the current point +location. + +With a negative ARG, look for the -ARGth breakpoint pattern in the +camldebug buffer, then try to obtain the breakpoint info from context +around point." + + (interactive "P") + (cond + (arg + (let ((narg (camldebug-numeric-arg arg))) + (if (> narg 0) (camldebug-call "delete" nil narg) + (save-excursion + (set-buffer current-camldebug-buffer) + (if (re-search-backward "^Breakpoint [0-9]+ at [0-9]+ : file " + nil t (- 1 narg)) + (camldebug-delete nil) + (error "I don't have %d breakpoints in my history" + (- 1 narg))))))) + ((eq (current-buffer) current-camldebug-buffer) + (let* ((bpline "^Breakpoint \\([0-9]+\\) at [0-9]+ : file ") + (arg (cond + ((eobp) + (save-excursion (re-search-backward bpline nil t)) + (string-to-int (match-string 1))) + ((save-excursion + (beginning-of-line 1) + (looking-at bpline)) + (string-to-int (match-string 1))) + ((string-to-int (camldebug-format-command "%e")))))) + (camldebug-call "delete" nil arg))) + (t + (let ((camldebug-delete-file + (concat (camldebug-format-command "%m") ".ml")) + (camldebug-delete-position (camldebug-format-command "%c"))) + (save-excursion + (set-buffer current-camldebug-buffer) + (let ((proc (get-buffer-process (current-buffer))) + (camldebug-filter-function 'camldebug-delete-filter) + (camldebug-delete-output)) + (camldebug-call-1 "info break") + (while (not (and camldebug-delete-output + (zerop (length + camldebug-filter-accumulator)))) + (accept-process-output proc)) + (if (eq camldebug-delete-output 'fail) + (error "No breakpoint in %s at %s" + camldebug-delete-file + camldebug-delete-position) + (camldebug-call "delete" nil + (string-to-int camldebug-delete-output))))))))) + +(defun camldebug-complete-filter (string) + (setq camldebug-filter-accumulator + (concat camldebug-filter-accumulator string)) + (while (string-match "\\(\n\\|\\`\\)\\(.+\\)\n" + camldebug-filter-accumulator) + (setq camldebug-complete-list + (cons (match-string 2 camldebug-filter-accumulator) + camldebug-complete-list)) + (setq camldebug-filter-accumulator + (substring camldebug-filter-accumulator + (1- (match-end 0))))) + (if (not (string-match comint-prompt-regexp + camldebug-filter-accumulator)) nil + (setq camldebug-complete-list + (or camldebug-complete-list 'fail)) + (setq camldebug-filter-accumulator "")) + (if (string-match "\n\\(.*\\)\\'" camldebug-filter-accumulator) + (setq camldebug-filter-accumulator + (match-string 1 camldebug-filter-accumulator))) + "") + +(defun camldebug-complete () + + "Perform completion on the camldebug command preceding point." + + (interactive) + (let* ((end (point)) + (command (save-excursion + (beginning-of-line) + (and (looking-at comint-prompt-regexp) + (goto-char (match-end 0))) + (buffer-substring (point) end))) + (camldebug-complete-list nil) (command-word)) + + ;; Find the word break. This match will always succeed. + (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command) + (setq command-word (match-string 2 command)) + + ;itz 04-21-96 if we are trying to complete a word of nonzero + ;length, chop off the last character. This is a nasty hack, but it + ;works - in general, not just for this set of words: the comint + ;call below will weed out false matches - and it avoids further + ;mucking with camldebug's lexer. + (if (> (length command-word) 0) + (setq command (substring command 0 (1- (length command))))) + + (let ((camldebug-filter-function 'camldebug-complete-filter)) + (camldebug-call-1 (concat "complete " command)) + (set-marker camldebug-delete-prompt-marker nil) + (while (not (and camldebug-complete-list + (zerop (length camldebug-filter-accumulator)))) + (accept-process-output (get-buffer-process + (current-buffer))))) + (if (eq camldebug-complete-list 'fail) + (setq camldebug-complete-list nil)) + (setq camldebug-complete-list + (sort camldebug-complete-list 'string-lessp)) + (comint-dynamic-simple-complete command-word camldebug-complete-list))) + +(define-key camldebug-mode-map "\C-l" 'camldebug-refresh) +(define-key camldebug-mode-map "\t" 'comint-dynamic-complete) +(define-key camldebug-mode-map "\M-?" 'comint-dynamic-list-completions) + +(define-key caml-mode-map "\C-x " 'camldebug-break) + + +(defvar current-camldebug-buffer nil) + + +;;;###autoload +(defvar camldebug-command-name "ocamldebug" + "*Pathname for executing camldebug.") + +;;;###autoload +(defun camldebug (path) + "Run camldebug on program FILE in buffer *camldebug-FILE*. +The directory containing FILE becomes the initial working directory +and source-file directory for camldebug. If you wish to change this, use +the camldebug commands `cd DIR' and `directory'." + (interactive "fRun ocamldebug on file: ") + (setq path (expand-file-name path)) + (let ((file (file-name-nondirectory path))) + (pop-to-buffer (concat "*camldebug-" file "*")) + (setq default-directory (file-name-directory path)) + (message "Current directory is %s" default-directory) + (make-comint (concat "camldebug-" file) + (substitute-in-file-name camldebug-command-name) + nil + "-emacs" "-cd" default-directory file) + (set-process-filter (get-buffer-process (current-buffer)) + 'camldebug-filter) + (set-process-sentinel (get-buffer-process (current-buffer)) + 'camldebug-sentinel) + (camldebug-mode) + (camldebug-set-buffer))) + +(defun camldebug-set-buffer () + (if (eq major-mode 'camldebug-mode) + (setq current-camldebug-buffer (current-buffer)) + (save-selected-window (pop-to-buffer current-camldebug-buffer)))) + +;;; Filter and sentinel. + +(defun camldebug-marker-filter (string) + (setq camldebug-filter-accumulator + (concat camldebug-filter-accumulator string)) + (let ((output "") (begin)) + ;; Process all the complete markers in this chunk. + (while (setq begin + (string-match + "\032\032\\(H\\|M\\(.+\\):\\(.+\\):\\(.+\\):\\(before\\|after\\)\\)\n" + camldebug-filter-accumulator)) + (setq camldebug-last-frame + (if (char-equal ?H (aref camldebug-filter-accumulator + (1+ (1+ begin)))) nil + (let ((isbefore + (string= "before" + (match-string 5 camldebug-filter-accumulator))) + (startpos (string-to-int + (match-string 3 camldebug-filter-accumulator))) + (endpos (string-to-int + (match-string 4 camldebug-filter-accumulator)))) + (list (match-string 2 camldebug-filter-accumulator) + (if isbefore startpos endpos) + isbefore + startpos + endpos + ))) + output (concat output + (substring camldebug-filter-accumulator + 0 begin)) + ;; Set the accumulator to the remaining text. + camldebug-filter-accumulator (substring + camldebug-filter-accumulator + (match-end 0)) + camldebug-last-frame-displayed-p nil)) + + + ;; Does the remaining text look like it might end with the + ;; beginning of another marker? If it does, then keep it in + ;; camldebug-filter-accumulator until we receive the rest of it. Since we + ;; know the full marker regexp above failed, it's pretty simple to + ;; test for marker starts. + (if (string-match "\032.*\\'" camldebug-filter-accumulator) + (progn + ;; Everything before the potential marker start can be output. + (setq output (concat output (substring camldebug-filter-accumulator + 0 (match-beginning 0)))) + + ;; Everything after, we save, to combine with later input. + (setq camldebug-filter-accumulator + (substring camldebug-filter-accumulator (match-beginning 0)))) + + (setq output (concat output camldebug-filter-accumulator) + camldebug-filter-accumulator "")) + + output)) + +(defun camldebug-filter (proc string) + (let ((output)) + (if (buffer-name (process-buffer proc)) + (let ((process-window)) + (save-excursion + (set-buffer (process-buffer proc)) + ;; If we have been so requested, delete the debugger prompt. + (if (marker-buffer camldebug-delete-prompt-marker) + (progn + (delete-region (process-mark proc) + camldebug-delete-prompt-marker) + (set-marker camldebug-delete-prompt-marker nil))) + (setq output (funcall camldebug-filter-function string)) + ;; Don't display the specified file unless + ;; (1) point is at or after the position where output appears + ;; and (2) this buffer is on the screen. + (setq process-window (and camldebug-track-frame + (not camldebug-last-frame-displayed-p) + (>= (point) (process-mark proc)) + (get-buffer-window (current-buffer)))) + ;; Insert the text, moving the process-marker. + (comint-output-filter proc output)) + (if process-window + (save-selected-window + (select-window process-window) + (camldebug-display-frame))))))) + +(defun camldebug-sentinel (proc msg) + (cond ((null (buffer-name (process-buffer proc))) + ;; buffer killed + ;; Stop displaying an arrow in a source file. + (camldebug-remove-current-event) + (set-process-buffer proc nil)) + ((memq (process-status proc) '(signal exit)) + ;; Stop displaying an arrow in a source file. + (camldebug-remove-current-event) + ;; Fix the mode line. + (setq mode-line-process + (concat ": " + (symbol-name (process-status proc)))) + (let* ((obuf (current-buffer))) + ;; save-excursion isn't the right thing if + ;; process-buffer is current-buffer + (unwind-protect + (progn + ;; Write something in *compilation* and hack its mode line, + (set-buffer (process-buffer proc)) + ;; Force mode line redisplay soon + (set-buffer-modified-p (buffer-modified-p)) + (if (eobp) + (insert ?\n mode-name " " msg) + (save-excursion + (goto-char (point-max)) + (insert ?\n mode-name " " msg))) + ;; If buffer and mode line will show that the process + ;; is dead, we can delete it now. Otherwise it + ;; will stay around until M-x list-processes. + (delete-process proc)) + ;; Restore old buffer, but don't restore old point + ;; if obuf is the cdb buffer. + (set-buffer obuf)))))) + + +(defun camldebug-refresh (&optional arg) + "Fix up a possibly garbled display, and redraw the mark." + (interactive "P") + (camldebug-display-frame) + (recenter arg)) + +(defun camldebug-display-frame () + "Find, obey and delete the last filename-and-line marker from CDB. +The marker looks like \\032\\032Mfilename:startchar:endchar:beforeflag\\n. +Obeying it means displaying in another window the specified file and line." + (interactive) + (camldebug-set-buffer) + (if (not camldebug-last-frame) + (camldebug-remove-current-event) + (camldebug-display-line (nth 0 camldebug-last-frame) + (nth 3 camldebug-last-frame) + (nth 4 camldebug-last-frame) + (nth 2 camldebug-last-frame))) + (setq camldebug-last-frame-displayed-p t)) + +;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen +;; and that its character CHARACTER is visible. +;; Put the mark on this character in that buffer. + +(defun camldebug-display-line (true-file schar echar kind) + (let* ((pre-display-buffer-function nil) ; screw it, put it all in one screen + (pop-up-windows t) + (buffer (find-file-noselect true-file)) + (window (display-buffer buffer t)) + (spos) (epos) (pos)) + (save-excursion + (set-buffer buffer) + (save-restriction + (widen) + (setq spos (+ (point-min) schar)) + (setq epos (+ (point-min) echar)) + (setq pos (if kind spos epos)) + (camldebug-set-current-event spos epos (current-buffer) kind)) + (cond ((or (< pos (point-min)) (> pos (point-max))) + (widen) + (goto-char pos)))) + (set-window-point window pos))) + +;;; Events. + +(defun camldebug-remove-current-event () + (if window-system + (progn + (delete-overlay camldebug-overlay-event) + (delete-overlay camldebug-overlay-under)) + (setq overlay-arrow-position nil))) + +(defun camldebug-set-current-event (spos epos buffer before) + (if window-system + (if before + (progn + (move-overlay camldebug-overlay-event spos (1+ spos) buffer) + (move-overlay camldebug-overlay-under + (+ spos 1) epos buffer)) + (move-overlay camldebug-overlay-event (1- epos) epos buffer) + (move-overlay camldebug-overlay-under spos (- epos 1) buffer)) + (save-excursion + (set-buffer buffer) + (goto-char pos) + (beginning-of-line) + (move-marker camldebug-event-marker (point)) + (setq overlay-arrow-position camldebug-event-marker)))) + +;;; Miscellaneous. + +(defun camldebug-module-name (filename) + (substring filename (string-match "\\([^/]*\\)\\.ml$" filename) (match-end 1))) + +;;; The camldebug-call function must do the right thing whether its +;;; invoking keystroke is from the camldebug buffer itself (via +;;; major-mode binding) or a caml buffer. In the former case, we want +;;; to supply data from camldebug-last-frame. Here's how we do it: + +(defun camldebug-format-command (str) + (let* ((insource (not (eq (current-buffer) current-camldebug-buffer))) + (frame (if insource nil camldebug-last-frame)) (result)) + (while (and str (string-match "\\([^%]*\\)%\\([mdcep]\\)" str)) + (let ((key (string-to-char (substring str (match-beginning 2)))) + (cmd (substring str (match-beginning 1) (match-end 1))) + (subst)) + (setq str (substring str (match-end 2))) + (cond + ((eq key ?m) + (setq subst (camldebug-module-name + (if insource (buffer-file-name) (nth 0 frame))))) + ((eq key ?d) + (setq subst (file-name-directory + (if insource (buffer-file-name) (nth 0 frame))))) + ((eq key ?c) + (setq subst (int-to-string + (if insource (1- (point)) (nth 1 frame))))) + ((eq key ?e) + (setq subst (thing-at-point 'symbol)))) + (setq result (concat result cmd subst)))) + ;; There might be text left in STR when the loop ends. + (concat result str))) + +(defun camldebug-call (command &optional fmt arg) + "Invoke camldebug COMMAND displaying source in other window. + +Certain %-escapes in FMT are interpreted specially if present. +These are: + + %m module name of current module. + %d directory of current source file. + %c number of current character position + %e text of the caml variable surrounding point. + + The `current' source file is the file of the current buffer (if +we're in a caml buffer) or the source file current at the last break +or step (if we're in the camldebug buffer), and the `current' module +name is the filename stripped of any *.ml* suffixes (this assumes the +usual correspondence between module and file naming is observed). The +`current' position is that of the current buffer (if we're in a source +file) or the position of the last break or step (if we're in the +camldebug buffer). + +If ARG is present, it overrides any FMT flags and its string +representation is simply concatenated with the COMMAND." + + ;; Make sure debugger buffer is displayed in a window. + (camldebug-set-buffer) + (message "Command: %s" (camldebug-call-1 command fmt arg))) + +(defun camldebug-call-1 (command &optional fmt arg) + + ;; Record info on the last prompt in the buffer and its position. + (save-excursion + (set-buffer current-camldebug-buffer) + (goto-char (process-mark (get-buffer-process current-camldebug-buffer))) + (let ((pt (point))) + (beginning-of-line) + (if (looking-at comint-prompt-regexp) + (set-marker camldebug-delete-prompt-marker (point))))) + (let ((cmd (cond + (arg (concat command " " (int-to-string arg))) + (fmt (camldebug-format-command + (concat command " " fmt))) + (command)))) + (process-send-string (get-buffer-process current-camldebug-buffer) + (concat cmd "\n")) + cmd)) + + +(provide 'camldebug) diff --git a/emacs/inf-caml.el b/emacs/inf-caml.el new file mode 100644 index 0000000..8ba9fcd --- /dev/null +++ b/emacs/inf-caml.el @@ -0,0 +1,362 @@ +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Xavier Leroy and Jacques Garrigue *) +;(* *) +;(* Copyright 1997 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: inf-caml.el,v 1.11 2004-08-20 17:04:35 doligez Exp $ *) + +;;; inf-caml.el --- run the Caml toplevel in an Emacs buffer + +;; Xavier Leroy, july 1993. + +;; modified by Jacques Garrigue, july 1997. + +(require 'comint) +(require 'caml) + +;; User modifiable variables + +;; Whether you want the output buffer to be diplayed when you send a phrase + +(defvar caml-display-when-eval t + "*If true, display the inferior caml buffer when evaluating expressions.") + + +;; End of User modifiable variables + + +(defvar inferior-caml-mode-map nil) +(if inferior-caml-mode-map nil + (setq inferior-caml-mode-map + (copy-keymap comint-mode-map))) + +;; Augment Caml mode, so you can process Caml code in the source files. + +(defvar inferior-caml-program "ocaml" + "*Program name for invoking an inferior Caml from Emacs.") + +(defun inferior-caml-mode () + "Major mode for interacting with an inferior Caml process. +Runs a Caml toplevel as a subprocess of Emacs, with I/O through an +Emacs buffer. A history of input phrases is maintained. Phrases can +be sent from another buffer in Caml mode. + +\\{inferior-caml-mode-map}" + (interactive) + (comint-mode) + (setq comint-prompt-regexp "^# ?") + (setq major-mode 'inferior-caml-mode) + (setq mode-name "Inferior Caml") + (make-local-variable 'paragraph-start) + (setq paragraph-start (concat "^$\\|" page-delimiter)) + (make-local-variable 'paragraph-separate) + (setq paragraph-separate paragraph-start) + (make-local-variable 'paragraph-ignore-fill-prefix) + (setq paragraph-ignore-fill-prefix t) + (make-local-variable 'require-final-newline) + (setq require-final-newline t) + (make-local-variable 'comment-start) + (setq comment-start "(*") + (make-local-variable 'comment-end) + (setq comment-end "*)") + (make-local-variable 'comment-column) + (setq comment-column 40) + (make-local-variable 'comment-start-skip) + (setq comment-start-skip "(\\*+ *") + (make-local-variable 'parse-sexp-ignore-comments) + (setq parse-sexp-ignore-comments nil) + (use-local-map inferior-caml-mode-map) + (run-hooks 'inferior-caml-mode-hooks)) + + +(defconst inferior-caml-buffer-subname "inferior-caml") +(defconst inferior-caml-buffer-name + (concat "*" inferior-caml-buffer-subname "*")) + +;; for compatibility with xemacs + +(defun caml-sit-for (second &optional mili redisplay) + (if (and (boundp 'running-xemacs) running-xemacs) + (sit-for (if mili (+ second (* mili 0.001)) second) redisplay) + (sit-for second mili redisplay))) + +;; To show result of evaluation at toplevel + +(defvar inferior-caml-output nil) +(defun inferior-caml-signal-output (s) + (if (string-match "[^ ]" s) (setq inferior-caml-output t))) + +(defun inferior-caml-mode-output-hook () + (setq comint-output-filter-functions + (list (function inferior-caml-signal-output)))) +(add-hook 'inferior-caml-mode-hooks 'inferior-caml-mode-output-hook) + +;; To launch ocaml whenever needed + +(defun caml-run-process-if-needed (&optional cmd) + (if (comint-check-proc inferior-caml-buffer-name) nil + (if (not cmd) + (if (comint-check-proc inferior-caml-buffer-name) + (setq cmd inferior-caml-program) + (setq cmd (read-from-minibuffer "Caml toplevel to run: " + inferior-caml-program)))) + (setq inferior-caml-program cmd) + (let ((cmdlist (inferior-caml-args-to-list cmd)) + (process-connection-type nil)) + (set-buffer (apply (function make-comint) + inferior-caml-buffer-subname + (car cmdlist) nil (cdr cmdlist))) + (inferior-caml-mode) + (display-buffer inferior-caml-buffer-name) + t) + (setq caml-shell-active t) + )) + +;; patched to from original run-caml sharing code with +;; caml-run-process-when-needed + +(defun run-caml (&optional cmd) + "Run an inferior Caml process. +Input and output via buffer `*inferior-caml*'." + (interactive + (list (if (not (comint-check-proc inferior-caml-buffer-name)) + (read-from-minibuffer "Caml toplevel to run: " + inferior-caml-program)))) + (caml-run-process-if-needed cmd) + (switch-to-buffer-other-window inferior-caml-buffer-name)) + + +(defun inferior-caml-args-to-list (string) + (let ((where (string-match "[ \t]" string))) + (cond ((null where) (list string)) + ((not (= where 0)) + (cons (substring string 0 where) + (inferior-caml-args-to-list (substring string (+ 1 where) + (length string))))) + (t (let ((pos (string-match "[^ \t]" string))) + (if (null pos) + nil + (inferior-caml-args-to-list (substring string pos + (length string))))))))) + +(defun inferior-caml-show-subshell () + (interactive) + (caml-run-process-if-needed) + (display-buffer inferior-caml-buffer-name) + ; Added by Didier to move the point of inferior-caml to end of buffer + (let ((buf (current-buffer)) + (caml-buf (get-buffer inferior-caml-buffer-name)) + (count 0)) + (while + (and (< count 10) + (not (equal (buffer-name (current-buffer)) + inferior-caml-buffer-name))) + (next-multiframe-window) + (setq count (+ count 1))) + (if (equal (buffer-name (current-buffer)) + inferior-caml-buffer-name) + (end-of-buffer)) + (while + (> count 0) + (previous-multiframe-window) + (setq count (- count 1))) + ) +) + +;; patched by Didier to move cursor after evaluation + +(defun inferior-caml-eval-region (start end) + "Send the current region to the inferior Caml process." + (interactive "r") + (save-excursion (caml-run-process-if-needed)) + (save-excursion + (goto-char end) + (caml-skip-comments-backward) + (comint-send-region inferior-caml-buffer-name start (point)) + ;; normally, ";;" are part of the region + (if (and (>= (point) 2) + (prog2 (backward-char 2) (looking-at ";;"))) + (comint-send-string inferior-caml-buffer-name "\n") + (comint-send-string inferior-caml-buffer-name ";;\n")) + ;; the user may not want to see the output buffer + (if caml-display-when-eval + (display-buffer inferior-caml-buffer-name t)))) + +;; jump to errors produced by ocaml compiler + +(defun inferior-caml-goto-error (start end) + "Jump to the location of the last error as indicated by inferior toplevel." + (interactive "r") + (let ((loc (+ start + (save-excursion + (set-buffer (get-buffer inferior-caml-buffer-name)) + (re-search-backward + (concat comint-prompt-regexp + "[ \t]*Characters[ \t]+\\([0-9]+\\)-[0-9]+:$")) + (string-to-int (match-string 1)))))) + (goto-char loc))) + + +;;; orgininal inf-caml.el ended here + +;; as eval-phrase, but ignores errors. + +(defun inferior-caml-just-eval-phrase (arg &optional min max) + "Send the phrase containing the point to the CAML process. +With prefix-arg send as many phrases as its numeric value, +ignoring possible errors during evaluation. + +Optional arguments min max defines a region within which the phrase +should lies." + (interactive "p") + (let ((beg)) + (while (> arg 0) + (setq arg (- arg 1)) + (setq beg (caml-find-phrase min max)) + (caml-eval-region beg (point))) + beg)) + +(defvar caml-previous-output nil + "tells the beginning of output in the shell-output buffer, so that the +output can be retreived later, asynchronously.") + +;; enriched version of eval-phrase, to repport errors. + +(defun inferior-caml-eval-phrase (arg &optional min max) + "Send the phrase containing the point to the CAML process. +With prefix-arg send as many phrases as its numeric value, +If an error occurs during evalutaion, stop at this phrase and +repport the error. + +Return nil if noerror and position of error if any. + +If arg's numeric value is zero or negative, evaluate the current phrase +or as many as prefix arg, ignoring evaluation errors. +This allows to jump other erroneous phrases. + +Optional arguments min max defines a region within which the phrase +should lies." + (interactive "p") + (if (save-excursion (caml-run-process-if-needed)) + (progn + (setq inferior-caml-output nil) + (caml-wait-output 10 1))) + (if (< arg 1) (inferior-caml-just-eval-phrase (max 1 (- 0 arg)) min max) + (let ((proc (get-buffer-process inferior-caml-buffer-name)) + (buf (current-buffer)) + previous-output orig beg end err) + (save-window-excursion + (while (and (> arg 0) (not err)) + (setq previous-output (marker-position (process-mark proc))) + (setq caml-previous-output previous-output) + (setq inferior-caml-output nil) + (setq orig (inferior-caml-just-eval-phrase 1 min max)) + (caml-wait-output) + (switch-to-buffer inferior-caml-buffer-name nil) + (goto-char previous-output) + (cond ((re-search-forward + " *Characters \\([01-9][01-9]*\\)-\\([1-9][01-9]*\\):\n[^W]" + (point-max) t) + (setq beg (string-to-int (caml-match-string 1))) + (setq end (string-to-int (caml-match-string 2))) + (switch-to-buffer buf) + (goto-char orig) + (forward-byte end) + (setq end (point)) + (goto-char orig) + (forward-byte beg) + (setq beg (point)) + (setq err beg) + ) + ((looking-at + "Toplevel input:\n[>]\\([^\n]*\\)\n[>]\\(\\( *\\)^*\\)\n") + (let ((expr (caml-match-string 1)) + (column (- (match-end 3) (match-beginning 3))) + (width (- (match-end 2) (match-end 3)))) + (if (string-match "^\\(.*\\)[<]EOF[>]$" expr) + (setq expr (substring expr (match-beginning 1) (match-end 1)))) + (switch-to-buffer buf) + (re-search-backward + (concat "^" (regexp-quote expr) "$") + (- orig 10)) + (goto-char (+ (match-beginning 0) column)) + (setq end (+ (point) width))) + (setq err beg)) + ((looking-at + "Toplevel input:\n>[.]*\\([^.].*\n\\)\\([>].*\n\\)*[>]\\(.*[^.]\\)[.]*\n") + (let* ((e1 (caml-match-string 1)) + (e2 (caml-match-string 3)) + (expr + (concat + (regexp-quote e1) "\\(.*\n\\)*" (regexp-quote e2)))) + (switch-to-buffer buf) + (re-search-backward expr orig 'move) + (setq end (match-end 0))) + (setq err beg)) + (t + (switch-to-buffer buf))) + (setq arg (- arg 1)) + ) + (pop-to-buffer inferior-caml-buffer-name) + (if err + (goto-char (point-max)) + (goto-char previous-output) + (goto-char (point-max))) + (pop-to-buffer buf)) + (if err (progn (beep) (caml-overlay-region (point) end)) + (if inferior-caml-output + (message "No error") + (message "No output yet...") + )) + err))) + +(defun caml-overlay-region (beg end &optional wait) + (interactive "%r") + (cond ((fboundp 'make-overlay) + (if caml-error-overlay () + (setq caml-error-overlay (make-overlay 1 1)) + (overlay-put caml-error-overlay 'face 'region)) + (unwind-protect + (progn + (move-overlay caml-error-overlay beg end (current-buffer)) + (beep) (if wait (read-event) (caml-sit-for 60))) + (delete-overlay caml-error-overlay))))) + +;; wait some amount for ouput, that is, until inferior-caml-output is set +;; to true. Hence, interleaves sitting for shorts delays and checking the +;; flag. Give up after some time. Typing into the source buffer will cancel +;; waiting, i.e. may report 'No result yet' + +(defun caml-wait-output (&optional before after) + (let ((c 1)) + (caml-sit-for 0 (or before 1)) + (let ((c 1)) + (while (and (not inferior-caml-output) (< c 99) (caml-sit-for 0 c t)) + (setq c (+ c 1)))) + (caml-sit-for (or after 0) 1))) + +;; To insert the last output from caml at point +(defun caml-insert-last-output () + "Insert the result of the evaluation of previous phrase" + (interactive) + (let ((pos (process-mark (get-buffer-process inferior-caml-buffer-name)))) + (insert-buffer-substring inferior-caml-buffer-name + caml-previous-output (- pos 2)))) + +;; additional bindings + +;(let ((map (lookup-key caml-mode-map [menu-bar caml]))) +; (define-key map [indent-buffer] '("Indent buffer" . caml-indent-buffer)) +; (define-key map [eval-buffer] '("Eval buffer" . caml-eval-buffer)) +;) +;(define-key caml-mode-map "\C-c\C-b" 'caml-eval-buffer) + + +(provide 'inf-caml) diff --git a/emacs/ocamltags.in b/emacs/ocamltags.in new file mode 100644 index 0000000..a20a1aa --- /dev/null +++ b/emacs/ocamltags.in @@ -0,0 +1,142 @@ +":" ; @EMACS@ -batch -l $0 "$@" ; status=$? ; : '--*-Emacs-Lisp-*--' <<';' + +;(***********************************************************************) +;(* *) +;(* Objective Caml *) +;(* *) +;(* Jacques Garrigue and Ian T Zimmerman *) +;(* *) +;(* Copyright 1998 Institut National de Recherche en Informatique et *) +;(* en Automatique. All rights reserved. This file is distributed *) +;(* under the terms of the GNU General Public License. *) +;(* *) +;(***********************************************************************) + +;(* $Id: ocamltags.in,v 1.6 2004-08-20 17:04:35 doligez Exp $ *) + +;; Copyright (C) 1998 Ian Zimmerman +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 2 of the +;; License, or (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; $Id: ocamltags.in,v 1.6 2004-08-20 17:04:35 doligez Exp $ + +(require 'caml) + +;;itz Fri Oct 30 13:08:37 PST 1998 support for creating TAGS files +;; itz Sun Dec 27 10:26:08 PST 1998 adapted very slightly from +;; Jacques' caml-create-index-function +(defun caml-tags-create-index-function () + (let (all-alist index) + (goto-char (point-max)) + ;; collect definitions + (while (caml-prev-index-position-function) + (if (looking-at "[ \t]*val") nil + (setq index (cons (caml-match-string 5) (point))) + (setq all-alist (cons index all-alist)))) + all-alist)) + +(defun caml-tags-file (filename) + (let* ((output-buffer (current-buffer)) + (basename (file-name-nondirectory filename)) + (backpatch (prog2 + (insert " \n" basename) + (point)))) + (find-file-read-only filename) + (caml-mode) + (let ((all-alist (caml-tags-create-index-function)) + (done nil) + (current-line 1) + (last-point (point-min))) + (mapcar + (lambda (pair) + (let ((tag-name (car pair)) (tag-pos (cdr pair))) + (goto-char tag-pos) + (setq current-line + (+ current-line (count-lines last-point (point)))) + (setq last-point (point)) + (end-of-line 1) + (let ((output-line (format "%s%s%d,%d\n" + (buffer-substring last-point (point)) + tag-name current-line tag-pos))) + (save-excursion + (set-buffer output-buffer) + (insert output-line))))) + all-alist)) + (kill-buffer (current-buffer)) + (set-buffer output-buffer) + (let ((index-size (- (point) backpatch))) + (goto-char backpatch) + (insert "," (int-to-string index-size) "\n") + (goto-char (point-max))))) + +(defsubst prefix-p (prefix str) + (and (<= (length prefix) (length str)) + (string= prefix (substring str 0 (length prefix))))) + +(defsubst eat-args (n) + (setq command-line-args-left (nthcdr n command-line-args-left))) + +;; see Emacs source file print.c +(defun print-error-message (data) + (let ((errname (car data)) errmsg is-file-error tail i) + (if (eq errname 'error) + (progn + (setq data (cdr data)) + (if (not (consp data)) (setq data nil)) + (setq errmsg (car data)) + (setq is-file-error nil)) + (setq errmsg (get errname 'error-message)) + (setq is-file-error (memq 'file-error (get errname 'error-conditions)))) + (setq tail (cdr-safe data)) + (if (and is-file-error tail) + (setq errmsg (car tail) tail (cdr tail))) + (if (stringp errmsg) (princ errmsg) + (princ "peculiar error")) + (setq i 0) + (while (consp tail) + (princ (if (eq i 0) ": " ", ")) + (if is-file-error (princ (car tail)) + (prin1 (car tail))) + (setq tail (cdr tail) i (1+ i))) + (princ "\n"))) + + +(setq gc-cons-threshold 1000000) + +(setq output-file "TAGS") +(setq append-flag nil) +(setq status 0) + +(condition-case foobar + (progn + (while (and command-line-args-left + (let ((arg (car command-line-args-left))) + (cond + ((prefix-p arg "-output-file") + (setq output-file (nth 1 command-line-args-left)) + (eat-args 2) t) + ((prefix-p arg "-append") + (setq append-flag t) + (eat-args 1) t) + (t nil))))) + + (find-file output-file) + (if append-flag (goto-char (point-max)) + (erase-buffer)) + (while command-line-args-left + (caml-tags-file (car command-line-args-left)) + (setq command-line-args-left (cdr command-line-args-left))) + (save-buffer 0)) + (error (setq status 1) (print-error-message foobar))) + +(kill-emacs status) + +; + +":" ; exit $status diff --git a/lex/.cvsignore b/lex/.cvsignore new file mode 100644 index 0000000..9f4f308 --- /dev/null +++ b/lex/.cvsignore @@ -0,0 +1,6 @@ +parser.ml +parser.mli +lexer.ml +ocamllex +ocamllex.opt +parser.output diff --git a/lex/.depend b/lex/.depend new file mode 100644 index 0000000..df03846 --- /dev/null +++ b/lex/.depend @@ -0,0 +1,34 @@ +common.cmi: syntax.cmi lexgen.cmi +compact.cmi: lexgen.cmi +cset.cmi: +lexer.cmi: parser.cmi +lexgen.cmi: syntax.cmi +output.cmi: syntax.cmi lexgen.cmi compact.cmi common.cmi +outputbis.cmi: syntax.cmi lexgen.cmi common.cmi +parser.cmi: syntax.cmi +syntax.cmi: cset.cmi +table.cmi: +common.cmo: syntax.cmi lexgen.cmi common.cmi +common.cmx: syntax.cmx lexgen.cmx common.cmi +compact.cmo: table.cmi lexgen.cmi compact.cmi +compact.cmx: table.cmx lexgen.cmx compact.cmi +cset.cmo: cset.cmi +cset.cmx: cset.cmi +lexer.cmo: syntax.cmi parser.cmi lexer.cmi +lexer.cmx: syntax.cmx parser.cmx lexer.cmi +lexgen.cmo: table.cmi syntax.cmi cset.cmi lexgen.cmi +lexgen.cmx: table.cmx syntax.cmx cset.cmx lexgen.cmi +main.cmo: syntax.cmi parser.cmi outputbis.cmi output.cmi lexgen.cmi lexer.cmi \ + cset.cmi compact.cmi common.cmi +main.cmx: syntax.cmx parser.cmx outputbis.cmx output.cmx lexgen.cmx lexer.cmx \ + cset.cmx compact.cmx common.cmx +output.cmo: syntax.cmi lexgen.cmi compact.cmi common.cmi output.cmi +output.cmx: syntax.cmx lexgen.cmx compact.cmx common.cmx output.cmi +outputbis.cmo: syntax.cmi lexgen.cmi common.cmi outputbis.cmi +outputbis.cmx: syntax.cmx lexgen.cmx common.cmx outputbis.cmi +parser.cmo: syntax.cmi cset.cmi parser.cmi +parser.cmx: syntax.cmx cset.cmx parser.cmi +syntax.cmo: cset.cmi syntax.cmi +syntax.cmx: cset.cmx syntax.cmi +table.cmo: table.cmi +table.cmx: table.cmi diff --git a/lex/Makefile b/lex/Makefile new file mode 100644 index 0000000..e751a06 --- /dev/null +++ b/lex/Makefile @@ -0,0 +1,71 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.19 2004-11-29 14:49:24 doligez Exp $ + +# The lexer generator +CAMLC=../boot/ocamlrun ../boot/ocamlc -nostdlib -I ../boot +CAMLOPT=../boot/ocamlrun ../ocamlopt -nostdlib -I ../stdlib +COMPFLAGS=-warn-error A +CAMLYACC=../boot/ocamlyacc +YACCFLAGS=-v +CAMLLEX=../boot/ocamlrun ../boot/ocamllex +CAMLDEP=../boot/ocamlrun ../tools/ocamldep + + +OBJS=cset.cmo syntax.cmo parser.cmo lexer.cmo table.cmo lexgen.cmo compact.cmo common.cmo output.cmo outputbis.cmo main.cmo + +all: ocamllex +allopt: ocamllex.opt + +ocamllex: $(OBJS) + $(CAMLC) $(LINKFLAGS) -o ocamllex $(OBJS) + +ocamllex.opt: $(OBJS:.cmo=.cmx) + $(CAMLOPT) -o ocamllex.opt $(OBJS:.cmo=.cmx) + +clean:: + rm -f ocamllex ocamllex.opt + rm -f *.cmo *.cmi *.cmx *.o *~ + +parser.ml parser.mli: parser.mly + $(CAMLYACC) $(YACCFLAGS) parser.mly + +clean:: + rm -f parser.ml parser.mli parser.output + +beforedepend:: parser.ml parser.mli + +lexer.ml: lexer.mll + $(CAMLLEX) lexer.mll + +clean:: + rm -f lexer.ml + +beforedepend:: lexer.ml + +.SUFFIXES: +.SUFFIXES: .ml .cmo .mli .cmi .cmx + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: beforedepend + $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/lex/Makefile.nt b/lex/Makefile.nt new file mode 100644 index 0000000..b74e40a --- /dev/null +++ b/lex/Makefile.nt @@ -0,0 +1,73 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.9 2003-01-06 14:57:22 xleroy Exp $ + +# The lexer generator + +CAMLC=../boot/ocamlrun ../boot/ocamlc -I ../boot +CAMLOPT=../boot/ocamlrun ../ocamlopt -I ../stdlib +COMPFLAGS=-warn-error A +LINKFLAGS= +CAMLYACC=../boot/ocamlyacc +YACCFLAGS=-v +CAMLLEX=../boot/ocamlrun ../boot/ocamllex +CAMLDEP=../boot/ocamlrun ../tools/ocamldep +DEPFLAGS= + +OBJS=cset.cmo syntax.cmo parser.cmo lexer.cmo table.cmo lexgen.cmo compact.cmo common.cmo output.cmo outputbis.cmo main.cmo + +all: ocamllex syntax.cmo +allopt: ocamllex.opt + +ocamllex: $(OBJS) + $(CAMLC) $(LINKFLAGS) -o ocamllex $(OBJS) + +ocamllex.opt: $(OBJS:.cmo=.cmx) + $(CAMLOPT) -o ocamllex.opt $(OBJS:.cmo=.cmx) + +clean:: + rm -f ocamllex ocamllex.opt + rm -f *.cmo *.cmi *.cmx *.$(O) + +parser.ml parser.mli: parser.mly + $(CAMLYACC) $(YACCFLAGS) parser.mly + +clean:: + rm -f parser.ml parser.mli + +beforedepend:: parser.ml parser.mli + +lexer.ml: lexer.mll + $(CAMLLEX) lexer.mll + +clean:: + rm -f lexer.ml + +beforedepend:: lexer.ml + +.SUFFIXES: +.SUFFIXES: .ml .cmo .mli .cmi .cmx + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: beforedepend + $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/lex/common.ml b/lex/common.ml new file mode 100644 index 0000000..cacea62 --- /dev/null +++ b/lex/common.ml @@ -0,0 +1,163 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, projet Moscova, *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +open Printf +open Syntax +open Lexgen + + +(* To copy the ML code fragments *) + +type line_tracker = { + file : string; + oc : out_channel; + ic : in_channel; + mutable cur_line : int; +};; + +let open_tracker file oc = { + file = file; + oc = oc; + ic = open_in_bin file; + cur_line = 1; +};; + +let close_tracker tr = close_in_noerr tr.ic;; + +let update_tracker tr = + fprintf tr.oc "\n"; + flush tr.oc; + let cr_seen = ref false in + try while true do + match input_char tr.ic with + | '\010' when not !cr_seen -> tr.cur_line <- tr.cur_line + 1; + | '\013' -> cr_seen := true; tr.cur_line <- tr.cur_line + 1; + | _ -> cr_seen := false; + done with End_of_file -> + fprintf tr.oc "# %d \"%s\"\n" (tr.cur_line+1) tr.file; +;; + +let copy_buffer = String.create 1024 + +let copy_chars_unix ic oc start stop = + let n = ref (stop - start) in + while !n > 0 do + let m = input ic copy_buffer 0 (min !n 1024) in + output oc copy_buffer 0 m; + n := !n - m + done + +let copy_chars_win32 ic oc start stop = + for i = start to stop - 1 do + let c = input_char ic in + if c <> '\r' then output_char oc c + done + +let copy_chars = + match Sys.os_type with + "Win32" | "Cygwin" -> copy_chars_win32 + | _ -> copy_chars_unix + +let copy_chunk sourcefile ic oc trl loc add_parens = + if loc.start_pos < loc.end_pos || add_parens then begin + fprintf oc "# %d \"%s\"\n" loc.start_line sourcefile; + if add_parens then begin + for i = 1 to loc.start_col - 1 do output_char oc ' ' done; + output_char oc '('; + end else begin + for i = 1 to loc.start_col do output_char oc ' ' done; + end; + seek_in ic loc.start_pos; + copy_chars ic oc loc.start_pos loc.end_pos; + if add_parens then output_char oc ')'; + update_tracker trl; + end + +(* Various memory actions *) + +let output_mem_access oc i = fprintf oc "lexbuf.Lexing.lex_mem.(%d)" i + +let output_memory_actions pref oc = function + | [] -> () + | mvs -> + output_string oc "(* " ; + fprintf oc "L=%d " (List.length mvs) ; + List.iter + (fun mv -> match mv with + | Copy (tgt, src) -> + fprintf oc "[%d] <- [%d] ;" tgt src + | Set tgt -> + fprintf oc "[%d] <- p ; " tgt) + mvs ; + output_string oc " *)\n" ; + List.iter + (fun mv -> match mv with + | Copy (tgt, src) -> + fprintf oc + "%s%a <- %a ;\n" + pref output_mem_access tgt output_mem_access src + | Set tgt -> + fprintf oc "%s%a <- lexbuf.Lexing.lex_curr_pos ;\n" + pref output_mem_access tgt) + mvs + +let output_base_mem oc = function + | Mem i -> output_mem_access oc i + | Start -> fprintf oc "lexbuf.Lexing.lex_start_pos" + | End -> fprintf oc "lexbuf.Lexing.lex_curr_pos" + +let output_tag_access oc = function + | Sum (a,0) -> + output_base_mem oc a + | Sum (a,i) -> + fprintf oc "(%a + %d)" output_base_mem a i + +let output_env sourcefile ic oc tr env = + let pref = ref "let" in + match env with + | [] -> () + | _ -> + (* Probably, we are better with variables sorted + in apparition order *) + let env = + List.sort + (fun ((_,p1),_) ((_,p2),_) -> + Pervasives.compare p1.start_pos p2.start_pos) + env in + + List.iter + (fun ((x,pos),v) -> + fprintf oc "%s\n" !pref ; + copy_chunk sourcefile ic oc tr pos false ; + begin match v with + | Ident_string (o,nstart,nend) -> + fprintf oc + "= Lexing.sub_lexeme%s lexbuf %a %a" + (if o then "_opt" else "") + output_tag_access nstart output_tag_access nend + | Ident_char (o,nstart) -> + fprintf oc + "= Lexing.sub_lexeme_char%s lexbuf %a" + (if o then "_opt" else "") + output_tag_access nstart + end ; + pref := "\nand") + env ; + fprintf oc " in\n" + +(* Output the user arguments *) +let output_args oc args = + List.iter (fun x -> (output_string oc x; output_char oc ' ')) args + +(* quiet flag *) +let quiet_mode = ref false;; diff --git a/lex/common.mli b/lex/common.mli new file mode 100644 index 0000000..e5742b4 --- /dev/null +++ b/lex/common.mli @@ -0,0 +1,27 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +type line_tracker;; +val open_tracker : string -> out_channel -> line_tracker +val close_tracker : line_tracker -> unit +val copy_chunk : + string -> + in_channel -> out_channel -> line_tracker -> Syntax.location -> bool -> unit +val output_mem_access : out_channel -> int -> unit +val output_memory_actions : + string -> out_channel -> Lexgen.memory_action list -> unit +val output_env : + string -> in_channel -> out_channel -> line_tracker -> + (Lexgen.ident * Lexgen.ident_info) list -> unit +val output_args : out_channel -> string list -> unit + +val quiet_mode : bool ref;; diff --git a/lex/compact.ml b/lex/compact.ml new file mode 100644 index 0000000..4b75be9 --- /dev/null +++ b/lex/compact.ml @@ -0,0 +1,234 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compact.ml,v 1.7 2002-10-28 16:46:49 maranget Exp $ *) + +(* Compaction of an automata *) + +open Lexgen + +(* Code for memory actions *) +let code = Table.create 0 + +(* instructions are 2 8-bits integers, a 0xff byte means return *) + +let emit_int i = Table.emit code i + +let ins_mem i c = match i with + | Copy (dst, src) -> dst::src::c + | Set dst -> dst::0xff::c + + +let ins_tag i c = match i with + | SetTag (dst, src) -> dst::src::c + | EraseTag dst -> dst::0xff::c + + +let do_emit_code c = + let r = Table.size code in + List.iter emit_int c ; + emit_int 0xff ; + r + +let memory = Hashtbl.create 101 + +let mem_emit_code c = + try Hashtbl.find memory c with + | Not_found -> + let r = do_emit_code c in + Hashtbl.add memory c r ; + r + +(* Code address 0 is the empty code (ie do nothing) *) +let _ = mem_emit_code [] + +let emit_tag_code c = mem_emit_code (List.fold_right ins_tag c []) +and emit_mem_code c =mem_emit_code (List.fold_right ins_mem c []) + +(*******************************************) +(* Compact the transition and check arrays *) +(*******************************************) + + +(* Determine the integer occurring most frequently in an array *) + +let most_frequent_elt v = + let frequencies = Hashtbl.create 17 in + let max_freq = ref 0 in + let most_freq = ref (v.(0)) in + for i = 0 to Array.length v - 1 do + let e = v.(i) in + let r = + try + Hashtbl.find frequencies e + with Not_found -> + let r = ref 1 in Hashtbl.add frequencies e r; r in + incr r; + if !r > !max_freq then begin max_freq := !r; most_freq := e end + done; + !most_freq + +(* Transform an array into a list of (position, non-default element) *) + +let non_default_elements def v = + let rec nondef i = + if i >= Array.length v then [] else begin + let e = v.(i) in + if e = def then nondef(i+1) else (i, e) :: nondef(i+1) + end in + nondef 0 + + +type t_compact = + {mutable c_trans : int array ; + mutable c_check : int array ; + mutable c_last_used : int ; } + +let create_compact () = + { c_trans = Array.create 1024 0 ; + c_check = Array.create 1024 (-1) ; + c_last_used = 0 ; } + +let reset_compact c = + c.c_trans <- Array.create 1024 0 ; + c.c_check <- Array.create 1024 (-1) ; + c.c_last_used <- 0 + +(* One compacted table for transitions, one other for memory actions *) +let trans = create_compact () +and moves = create_compact () + + +let grow_compact c = + let old_trans = c.c_trans + and old_check = c.c_check in + let n = Array.length old_trans in + c.c_trans <- Array.create (2*n) 0; + Array.blit old_trans 0 c.c_trans 0 c.c_last_used; + c.c_check <- Array.create (2*n) (-1); + Array.blit old_check 0 c.c_check 0 c.c_last_used + +let do_pack state_num orig compact = + let default = most_frequent_elt orig in + let nondef = non_default_elements default orig in + let rec pack_from b = + while + b + 257 > Array.length compact.c_trans + do + grow_compact compact + done; + let rec try_pack = function + [] -> b + | (pos, v) :: rem -> + if compact.c_check.(b + pos) = -1 then + try_pack rem + else pack_from (b+1) in + try_pack nondef in + let base = pack_from 0 in + List.iter + (fun (pos, v) -> + compact.c_trans.(base + pos) <- v; + compact.c_check.(base + pos) <- state_num) + nondef; + if base + 257 > compact.c_last_used then + compact.c_last_used <- base + 257; + (base, default) + +let pack_moves state_num move_t = + let move_v = Array.create 257 0 + and move_m = Array.create 257 0 in + for i = 0 to 256 do + let act,c = move_t.(i) in + move_v.(i) <- (match act with Backtrack -> -1 | Goto n -> n) ; + move_m.(i) <- emit_mem_code c + done ; + let pk_trans = do_pack state_num move_v trans + and pk_moves = do_pack state_num move_m moves in + pk_trans, pk_moves + + +(* Build the tables *) + +type lex_tables = + { tbl_base: int array; (* Perform / Shift *) + tbl_backtrk: int array; (* No_remember / Remember *) + tbl_default: int array; (* Default transition *) + tbl_trans: int array; (* Transitions (compacted) *) + tbl_check: int array; (* Check (compacted) *) +(* code addresses are managed in a similar fashion as transitions *) + tbl_base_code : int array; (* code ptr / base for Shift *) + tbl_backtrk_code : int array; (* nothing / code when Remember *) +(* moves to execute before transitions (compacted) *) + tbl_default_code : int array; + tbl_trans_code : int array; + tbl_check_code : int array; +(* byte code itself *) + tbl_code: int array;} + + +let compact_tables state_v = + let n = Array.length state_v in + let base = Array.create n 0 + and backtrk = Array.create n (-1) + and default = Array.create n 0 + and base_code = Array.create n 0 + and backtrk_code = Array.create n 0 + and default_code = Array.create n 0 in + for i = 0 to n - 1 do + match state_v.(i) with + | Perform (n,c) -> + base.(i) <- -(n+1) ; + base_code.(i) <- emit_tag_code c + | Shift(trans, move) -> + begin match trans with + | No_remember -> () + | Remember (n,c) -> + backtrk.(i) <- n ; + backtrk_code.(i) <- emit_tag_code c + end; + let (b_trans, d_trans),(b_moves,d_moves) = pack_moves i move in + base.(i) <- b_trans; default.(i) <- d_trans ; + base_code.(i) <- b_moves; default_code.(i) <- d_moves ; + done; + let code = Table.trim code in + let tables = + if Array.length code > 1 then + { tbl_base = base; + tbl_backtrk = backtrk; + tbl_default = default; + tbl_trans = Array.sub trans.c_trans 0 trans.c_last_used; + tbl_check = Array.sub trans.c_check 0 trans.c_last_used; + tbl_base_code = base_code ; + tbl_backtrk_code = backtrk_code; + tbl_default_code = default_code; + tbl_trans_code = Array.sub moves.c_trans 0 moves.c_last_used; + tbl_check_code = Array.sub moves.c_check 0 moves.c_last_used; + tbl_code = code} + else (* when no memory moves, do not emit related tables *) + { tbl_base = base; + tbl_backtrk = backtrk; + tbl_default = default; + tbl_trans = Array.sub trans.c_trans 0 trans.c_last_used; + tbl_check = Array.sub trans.c_check 0 trans.c_last_used; + tbl_base_code = [||] ; + tbl_backtrk_code = [||]; + tbl_default_code = [||]; + tbl_trans_code = [||]; + tbl_check_code = [||]; + tbl_code = [||]} + in + reset_compact trans ; + reset_compact moves ; + tables + + + diff --git a/lex/compact.mli b/lex/compact.mli new file mode 100644 index 0000000..86bed97 --- /dev/null +++ b/lex/compact.mli @@ -0,0 +1,33 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: compact.mli,v 1.4 2002-10-28 16:46:49 maranget Exp $ *) + +(* Compaction of an automata *) +type lex_tables = + { tbl_base: int array; (* Perform / Shift *) + tbl_backtrk: int array; (* No_remember / Remember *) + tbl_default: int array; (* Default transition *) + tbl_trans: int array; (* Transitions (compacted) *) + tbl_check: int array; (* Check (compacted) *) +(* code addresses are managed in a similar fashion as transitions *) + tbl_base_code : int array; (* code ptr / base for Shift *) + tbl_backtrk_code : int array; (* nothing / code when Remember *) +(* moves to execute before transitions (compacted) *) + tbl_default_code : int array; + tbl_trans_code : int array; + tbl_check_code : int array; +(* byte code itself *) + tbl_code: int array;} + + +val compact_tables: Lexgen.automata array -> lex_tables diff --git a/lex/cset.ml b/lex/cset.ml new file mode 100644 index 0000000..710811e --- /dev/null +++ b/lex/cset.ml @@ -0,0 +1,99 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, Jerome Vouillon projet Cristal, *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cset.ml,v 1.3 2004-04-29 11:12:49 maranget Exp $ *) + + +exception Bad + +type t = (int * int) list + + +let empty = [] +let is_empty = function + | [] -> true + | _ -> false + +let singleton c = [c,c] + +let interval c1 c2 = + if c1 <= c2 then [c1,c2] + else [c2,c1] + + +let rec union s1 s2 = match s1,s2 with +| [],_ -> s2 +| _,[] -> s1 +| (c1,d1) as p1::r1, (c2,d2)::r2 -> + if c1 > c2 then + union s2 s1 + else begin (* c1 <= c2 *) + if d1+1 < c2 then + p1::union r1 s2 + else if d1 < d2 then + union ((c1,d2)::r2) r1 + else + union s1 r2 + end + +let rec inter l l' = match l, l' with + _, [] -> [] + | [], _ -> [] + | (c1, c2)::r, (c1', c2')::r' -> + if c2 < c1' then + inter r l' + else if c2' < c1 then + inter l r' + else if c2 < c2' then + (max c1 c1', c2)::inter r l' + else + (max c1 c1', c2')::inter l r' + +let rec diff l l' = match l, l' with + _, [] -> l + | [], _ -> [] + | (c1, c2)::r, (c1', c2')::r' -> + if c2 < c1' then + (c1, c2)::diff r l' + else if c2' < c1 then + diff l r' + else + let r'' = if c2' < c2 then (c2' + 1, c2) :: r else r in + if c1 < c1' then + (c1, c1' - 1)::diff r'' r' + else + diff r'' r' + + +let eof = singleton 256 +and all_chars = interval 0 255 +and all_chars_eof = interval 0 256 + +let complement s = diff all_chars s + +let env_to_array env = match env with +| [] -> assert false +| (_,x)::rem -> + let res = Array.create 257 x in + List.iter + (fun (c,y) -> + List.iter + (fun (i,j) -> + for k=i to j do + res.(k) <- y + done) + c) + rem ; + res + + diff --git a/lex/cset.mli b/lex/cset.mli new file mode 100644 index 0000000..50210a8 --- /dev/null +++ b/lex/cset.mli @@ -0,0 +1,37 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, Jerome Vouillon projet Cristal, *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cset.mli,v 1.3 2004-04-29 11:12:49 maranget Exp $ *) + +(* Set of characters encoded as list of intervals *) + +type t +exception Bad + +val empty : t +val is_empty : t -> bool +val all_chars : t +exception Bad + +val all_chars_eof : t +val eof : t +val singleton : int -> t +val interval : int -> int -> t +val union : t -> t -> t +val inter : t -> t -> t +val diff : t -> t -> t +val complement : t -> t +val env_to_array : (t * 'a) list -> 'a array + + + diff --git a/lex/lexer.mli b/lex/lexer.mli new file mode 100644 index 0000000..c27061c --- /dev/null +++ b/lex/lexer.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mli,v 1.6 2004-04-21 23:26:05 doligez Exp $ *) + +val main: Lexing.lexbuf -> Parser.token + +exception Lexical_error of string * string * int * int + +(*n +val line_num: int ref +val line_start_pos: int ref +*) diff --git a/lex/lexer.mll b/lex/lexer.mll new file mode 100644 index 0000000..ede87ff --- /dev/null +++ b/lex/lexer.mll @@ -0,0 +1,301 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mll,v 1.22 2006-01-04 16:55:49 doligez Exp $ *) + +(* The lexical analyzer for lexer definitions. Bootstrapped! *) + +{ +open Syntax +open Parser + +(* Auxiliaries for the lexical analyzer *) + +let brace_depth = ref 0 +and comment_depth = ref 0 + +let in_pattern () = !brace_depth = 0 && !comment_depth = 0 + +exception Lexical_error of string * string * int * int + +let string_buff = Buffer.create 256 + +let reset_string_buffer () = Buffer.clear string_buff + +let store_string_char c = Buffer.add_char string_buff c + +let get_stored_string () = Buffer.contents string_buff + +let char_for_backslash = function + 'n' -> '\n' + | 't' -> '\t' + | 'b' -> '\b' + | 'r' -> '\r' + | c -> c + +let raise_lexical_error lexbuf msg = + let p = Lexing.lexeme_start_p lexbuf in + raise (Lexical_error (msg, + p.Lexing.pos_fname, + p.Lexing.pos_lnum, + p.Lexing.pos_cnum - p.Lexing.pos_bol + 1)) +;; + +let handle_lexical_error fn lexbuf = + let p = Lexing.lexeme_start_p lexbuf in + let line = p.Lexing.pos_lnum + and column = p.Lexing.pos_cnum - p.Lexing.pos_bol + 1 + and file = p.Lexing.pos_fname + in + try + fn lexbuf + with Lexical_error (msg, "", 0, 0) -> + raise(Lexical_error(msg, file, line, column)) + +let get_input_name () = Sys.argv.(Array.length Sys.argv - 1) + +let warning lexbuf msg = + let p = Lexing.lexeme_start_p lexbuf in + Printf.eprintf "ocamllex warning:\nFile \"%s\", line %d, character %d: %s.\n" + p.Lexing.pos_fname p.Lexing.pos_lnum + (p.Lexing.pos_cnum - p.Lexing.pos_bol + 1) msg; + flush stderr + +let decimal_code c d u = + 100 * (Char.code c - 48) + 10 * (Char.code d - 48) + (Char.code u - 48) + +let char_for_hexadecimal_code d u = + let d1 = Char.code d in + let val1 = if d1 >= 97 then d1 - 87 + else if d1 >= 65 then d1 - 55 + else d1 - 48 + in + let d2 = Char.code u in + let val2 = if d2 >= 97 then d2 - 87 + else if d2 >= 65 then d2 - 55 + else d2 - 48 + in + Char.chr (val1 * 16 + val2) + +let incr_loc lexbuf delta = + 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 - delta; + } +;; + +let update_loc lexbuf opt_file line = + let pos = lexbuf.Lexing.lex_curr_p in + let new_file = match opt_file with + | None -> pos.Lexing.pos_fname + | Some f -> f + in + lexbuf.Lexing.lex_curr_p <- { pos with + Lexing.pos_fname = new_file; + Lexing.pos_lnum = line; + Lexing.pos_bol = pos.Lexing.pos_cnum; + } +;; + +} + +let identstart = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255'] +let identbody = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let backslash_escapes = + ['\\' '"' '\'' 'n' 't' 'b' 'r'] + +rule main = parse + [' ' '\013' '\009' '\012' ] + + { main lexbuf } + | '\010' + { incr_loc lexbuf 0; + main lexbuf } + | "#" [' ' '\t']* (['0'-'9']+ as num) [' ' '\t']* + ('\"' ([^ '\010' '\013' '\"']* as name) '\"')? + [^ '\010' '\013']* '\010' + { update_loc lexbuf name (int_of_string num); + main lexbuf + } + | "(*" + { comment_depth := 1; + handle_lexical_error comment lexbuf; + main lexbuf } + | '_' { Tunderscore } + | identstart identbody * + { match Lexing.lexeme lexbuf with + "rule" -> Trule + | "parse" -> Tparse + | "shortest" -> Tparse_shortest + | "and" -> Tand + | "eof" -> Teof + | "let" -> Tlet + | "as" -> Tas + | s -> Tident s } + | '"' + { reset_string_buffer(); + handle_lexical_error string lexbuf; + Tstring(get_stored_string()) } +(* note: ''' is a valid character literal (by contrast with the compiler) *) + | "'" [^ '\\'] "'" + { Tchar(Char.code(Lexing.lexeme_char lexbuf 1)) } + | "'" '\\' backslash_escapes "'" + { Tchar(Char.code(char_for_backslash (Lexing.lexeme_char lexbuf 2))) } + | "'" '\\' (['0'-'9'] as c) (['0'-'9'] as d) (['0'-'9'] as u)"'" + { let v = decimal_code c d u in + if v > 255 then + raise_lexical_error lexbuf + (Printf.sprintf "illegal escape sequence \\%c%c%c" c d u) + else + Tchar v } + | "'" '\\' 'x' + (['0'-'9' 'a'-'f' 'A'-'F'] as d) (['0'-'9' 'a'-'f' 'A'-'F'] as u) "'" + { Tchar(Char.code(char_for_hexadecimal_code d u)) } + | "'" '\\' (_ as c) + { raise_lexical_error lexbuf + (Printf.sprintf "illegal escape sequence \\%c" c) + } + | '{' + { let p = Lexing.lexeme_end_p lexbuf in + let n1 = p.Lexing.pos_cnum + and l1 = p.Lexing.pos_lnum + and s1 = p.Lexing.pos_bol in + brace_depth := 1; + let n2 = handle_lexical_error action lexbuf in + Taction({start_pos = n1; end_pos = n2; + start_line = l1; start_col = n1 - s1}) } + | '=' { Tequal } + | '|' { Tor } + | '[' { Tlbracket } + | ']' { Trbracket } + | '*' { Tstar } + | '?' { Tmaybe } + | '+' { Tplus } + | '(' { Tlparen } + | ')' { Trparen } + | '^' { Tcaret } + | '-' { Tdash } + | '#' { Tsharp } + | eof { Tend } + | _ + { raise_lexical_error lexbuf + ("illegal character " ^ String.escaped(Lexing.lexeme lexbuf)) + } + + +(* String parsing comes from the compiler lexer *) +and string = parse + '"' + { () } + | '\\' ("\010" | "\013" | "\013\010") ([' ' '\009'] * as spaces) + { incr_loc lexbuf (String.length spaces); + string lexbuf } + | '\\' (backslash_escapes as c) + { store_string_char(char_for_backslash c); + string lexbuf } + | '\\' (['0'-'9'] as c) (['0'-'9'] as d) (['0'-'9'] as u) + { let v = decimal_code c d u in + if in_pattern () && v > 255 then + warning lexbuf + (Printf.sprintf + "illegal backslash escape in string: `\\%c%c%c'" c d u) ; + store_string_char (Char.chr v); + string lexbuf } + | '\\' 'x' (['0'-'9' 'a'-'f' 'A'-'F'] as d) (['0'-'9' 'a'-'f' 'A'-'F'] as u) + { store_string_char (char_for_hexadecimal_code d u) ; + string lexbuf } + | '\\' (_ as c) + {if in_pattern () then + warning lexbuf + (Printf.sprintf "illegal backslash escape in string: `\\%c'" c) ; + store_string_char '\\' ; + store_string_char c ; + string lexbuf } + | eof + { raise(Lexical_error("unterminated string", "", 0, 0)) } + | '\010' + { store_string_char '\010'; + incr_loc lexbuf 0; + string lexbuf } + | _ as c + { store_string_char c; + string lexbuf } + +(* + Lexers comment and action are quite similar, + they should lex both strings and characters, + in order not to be confused by what is inside then +*) + +and comment = parse + "(*" + { incr comment_depth; comment lexbuf } + | "*)" + { decr comment_depth; + if !comment_depth = 0 then () else comment lexbuf } + | '"' + { reset_string_buffer(); + string lexbuf; + reset_string_buffer(); + comment lexbuf } + | "'" + { skip_char lexbuf ; + comment lexbuf } + | eof + { raise(Lexical_error("unterminated comment", "", 0, 0)) } + | '\010' + { incr_loc lexbuf 0; + comment lexbuf } + | _ + { comment lexbuf } + +and action = parse + '{' + { incr brace_depth; + action lexbuf } + | '}' + { decr brace_depth; + if !brace_depth = 0 then Lexing.lexeme_start lexbuf else action lexbuf } + | '"' + { reset_string_buffer(); + handle_lexical_error string lexbuf; + reset_string_buffer(); + action lexbuf } + | "'" + { skip_char lexbuf ; + action lexbuf } + | "(*" + { comment_depth := 1; + comment lexbuf; + action lexbuf } + | eof + { raise (Lexical_error("unterminated action", "", 0, 0)) } + | '\010' + { incr_loc lexbuf 0; + action lexbuf } + | _ + { action lexbuf } + +and skip_char = parse + | '\\'? '\010' "'" + { incr_loc lexbuf 1; + } + | [^ '\\' '\''] "'" (* regular character *) +(* one character and numeric escape sequences *) + | '\\' _ "'" + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + | '\\' 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'" + {()} +(* A dieu va ! *) + | "" {()} diff --git a/lex/lexgen.ml b/lex/lexgen.ml new file mode 100644 index 0000000..6b9e675 --- /dev/null +++ b/lex/lexgen.ml @@ -0,0 +1,1193 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, *) +(* Luc Maranget, projet Moscova, *) +(* INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexgen.ml,v 1.21 2008-03-07 15:24:48 maranget Exp $ *) + +(* Compiling a lexer definition *) + +open Syntax +open Printf + +exception Memory_overflow + +(* Deep abstract syntax for regular expressions *) + +type ident = string * Syntax.location + +type tag_info = {id : string ; start : bool ; action : int} + +type regexp = + Empty + | Chars of int * bool + | Action of int + | Tag of tag_info + | Seq of regexp * regexp + | Alt of regexp * regexp + | Star of regexp + +type tag_base = Start | End | Mem of int +type tag_addr = Sum of (tag_base * int) +type ident_info = + | Ident_string of bool * tag_addr * tag_addr + | Ident_char of bool * tag_addr +type t_env = (ident * ident_info) list + +type ('args,'action) lexer_entry = + { lex_name: string; + lex_regexp: regexp; + lex_mem_tags: int ; + lex_actions: (int * t_env * 'action) list } + + +type automata = + Perform of int * tag_action list + | Shift of automata_trans * (automata_move * memory_action list) array + +and automata_trans = + No_remember + | Remember of int * tag_action list + +and automata_move = + Backtrack + | Goto of int + +and memory_action = + | Copy of int * int + | Set of int + +and tag_action = SetTag of int * int | EraseTag of int + +(* Representation of entry points *) + +type ('args,'action) automata_entry = + { auto_name: string; + auto_args: 'args ; + auto_mem_size : int ; + auto_initial_state: int * memory_action list; + auto_actions: (int * t_env * 'action) list } + + +(* A lot of sets and map structures *) + +module Ints = Set.Make(struct type t = int let compare = compare end) + +let id_compare (id1,_) (id2,_) = String.compare id1 id2 + +let tag_compare t1 t2 = Pervasives.compare t1 t2 + +module Tags = Set.Make(struct type t = tag_info let compare = tag_compare end) + +module TagMap = + Map.Make (struct type t = tag_info let compare = tag_compare end) + +module IdSet = + Set.Make (struct type t = ident let compare = id_compare end) + +module IdMap = + Map.Make (struct type t = ident let compare = id_compare end) + +(*********************) +(* Variable cleaning *) +(*********************) + +(* Silently eliminate nested variables *) + +let rec do_remove_nested to_remove = function + | Bind (e,x) -> + if IdSet.mem x to_remove then + do_remove_nested to_remove e + else + Bind (do_remove_nested (IdSet.add x to_remove) e, x) + | Epsilon|Eof|Characters _ as e -> e + | Sequence (e1, e2) -> + Sequence + (do_remove_nested to_remove e1, do_remove_nested to_remove e2) + | Alternative (e1, e2) -> + Alternative + (do_remove_nested to_remove e1, do_remove_nested to_remove e2) + | Repetition e -> + Repetition (do_remove_nested to_remove e) + +let remove_nested_as e = do_remove_nested IdSet.empty e + +(*********************) +(* Variable analysis *) +(*********************) + +(* + Optional variables. + A variable is optional when matching of regexp does not + implies it binds. + The typical case is: + ("" | 'a' as x) -> optional + ("" as x | 'a' as x) -> non-optional +*) + +let stringset_delta s1 s2 = + IdSet.union + (IdSet.diff s1 s2) + (IdSet.diff s2 s1) + +let rec find_all_vars = function + | Characters _|Epsilon|Eof -> + IdSet.empty + | Bind (e,x) -> + IdSet.add x (find_all_vars e) + | Sequence (e1,e2)|Alternative (e1,e2) -> + IdSet.union (find_all_vars e1) (find_all_vars e2) + | Repetition e -> find_all_vars e + + +let rec do_find_opt = function + | Characters _|Epsilon|Eof -> IdSet.empty, IdSet.empty + | Bind (e,x) -> + let opt,all = do_find_opt e in + opt, IdSet.add x all + | Sequence (e1,e2) -> + let opt1,all1 = do_find_opt e1 + and opt2,all2 = do_find_opt e2 in + IdSet.union opt1 opt2, IdSet.union all1 all2 + | Alternative (e1,e2) -> + let opt1,all1 = do_find_opt e1 + and opt2,all2 = do_find_opt e2 in + IdSet.union + (IdSet.union opt1 opt2) + (stringset_delta all1 all2), + IdSet.union all1 all2 + | Repetition e -> + let r = find_all_vars e in + r,r + +let find_optional e = + let r,_ = do_find_opt e in r + +(* + Double variables + A variable is double when it can be bound more than once + in a single matching + The typical case is: + (e1 as x) (e2 as x) + +*) + +let rec do_find_double = function + | Characters _|Epsilon|Eof -> IdSet.empty, IdSet.empty + | Bind (e,x) -> + let dbl,all = do_find_double e in + (if IdSet.mem x all then + IdSet.add x dbl + else + dbl), + IdSet.add x all + | Sequence (e1,e2) -> + let dbl1, all1 = do_find_double e1 + and dbl2, all2 = do_find_double e2 in + IdSet.union + (IdSet.inter all1 all2) + (IdSet.union dbl1 dbl2), + IdSet.union all1 all2 + | Alternative (e1,e2) -> + let dbl1, all1 = do_find_double e1 + and dbl2, all2 = do_find_double e2 in + IdSet.union dbl1 dbl2, + IdSet.union all1 all2 + | Repetition e -> + let r = find_all_vars e in + r,r + +let find_double e = do_find_double e + +(* + Type of variables: + A variable is bound to a char when all its occurences + bind a pattern of length 1. + The typical case is: + (_ as x) -> char +*) + +let add_some x = function + | Some i -> Some (x+i) + | None -> None + +let add_some_some x y = match x,y with +| Some i, Some j -> Some (i+j) +| _,_ -> None + +let rec do_find_chars sz = function + | Epsilon|Eof -> IdSet.empty, IdSet.empty, sz + | Characters _ -> IdSet.empty, IdSet.empty, add_some 1 sz + | Bind (e,x) -> + let c,s,e_sz = do_find_chars (Some 0) e in + begin match e_sz with + | Some 1 -> + IdSet.add x c,s,add_some 1 sz + | _ -> + c, IdSet.add x s, add_some_some sz e_sz + end + | Sequence (e1,e2) -> + let c1,s1,sz1 = do_find_chars sz e1 in + let c2,s2,sz2 = do_find_chars sz1 e2 in + IdSet.union c1 c2, + IdSet.union s1 s2, + sz2 + | Alternative (e1,e2) -> + let c1,s1,sz1 = do_find_chars sz e1 + and c2,s2,sz2 = do_find_chars sz e2 in + IdSet.union c1 c2, + IdSet.union s1 s2, + (if sz1 = sz2 then sz1 else None) + | Repetition e -> do_find_chars None e + + + +let find_chars e = + let c,s,_ = do_find_chars (Some 0) e in + IdSet.diff c s + +(*******************************) +(* From shallow to deep syntax *) +(*******************************) + +let chars = ref ([] : Cset.t list) +let chars_count = ref 0 + + +let rec encode_regexp char_vars act = function + Epsilon -> Empty + | Characters cl -> + let n = !chars_count in + chars := cl :: !chars; + incr chars_count; + Chars(n,false) + | Eof -> + let n = !chars_count in + chars := Cset.eof :: !chars; + incr chars_count; + Chars(n,true) + | Sequence(r1,r2) -> + let r1 = encode_regexp char_vars act r1 in + let r2 = encode_regexp char_vars act r2 in + Seq (r1, r2) + | Alternative(r1,r2) -> + let r1 = encode_regexp char_vars act r1 in + let r2 = encode_regexp char_vars act r2 in + Alt(r1, r2) + | Repetition r -> + let r = encode_regexp char_vars act r in + Star r + | Bind (r,((name,_) as x)) -> + let r = encode_regexp char_vars act r in + if IdSet.mem x char_vars then + Seq (Tag {id=name ; start=true ; action=act},r) + else + Seq (Tag {id=name ; start=true ; action=act}, + Seq (r, Tag {id=name ; start=false ; action=act})) + + +(* Optimisation, + Static optimization : + Replace tags by offsets relative to the beginning + or end of matched string. + Dynamic optimization: + Replace some non-optional, non-double tags by offsets w.r.t + a previous similar tag. +*) + +let incr_pos = function + | None -> None + | Some i -> Some (i+1) + +let decr_pos = function + | None -> None + | Some i -> Some (i-1) + + +let opt = true + +let mk_seq r1 r2 = match r1,r2 with +| Empty,_ -> r2 +| _,Empty -> r1 +| _,_ -> Seq (r1,r2) + +let add_pos p i = match p with +| Some (Sum (a,n)) -> Some (Sum (a,n+i)) +| None -> None + +let mem_name name id_set = + IdSet.exists (fun (id_name,_) -> name = id_name) id_set + +let opt_regexp all_vars char_vars optional_vars double_vars r = + +(* From removed tags to their addresses *) + let env = Hashtbl.create 17 in + +(* First static optimizations, from start position *) + let rec size_forward pos = function + | Empty|Chars (_,true)|Tag _ -> Some pos + | Chars (_,false) -> Some (pos+1) + | Seq (r1,r2) -> + begin match size_forward pos r1 with + | None -> None + | Some pos -> size_forward pos r2 + end + | Alt (r1,r2) -> + let pos1 = size_forward pos r1 + and pos2 = size_forward pos r2 in + if pos1=pos2 then pos1 else None + | Star _ -> None + | Action _ -> assert false in + + let rec simple_forward pos r = match r with + | Tag n -> + if mem_name n.id double_vars then + r,Some pos + else begin + Hashtbl.add env (n.id,n.start) (Sum (Start, pos)) ; + Empty,Some pos + end + | Empty -> r, Some pos + | Chars (_,is_eof) -> + r,Some (if is_eof then pos else pos+1) + | Seq (r1,r2) -> + let r1,pos = simple_forward pos r1 in + begin match pos with + | None -> mk_seq r1 r2,None + | Some pos -> + let r2,pos = simple_forward pos r2 in + mk_seq r1 r2,pos + end + | Alt (r1,r2) -> + let pos1 = size_forward pos r1 + and pos2 = size_forward pos r2 in + r,(if pos1=pos2 then pos1 else None) + | Star _ -> r,None + | Action _ -> assert false in + +(* Then static optimizations, from end position *) + let rec size_backward pos = function + | Empty|Chars (_,true)|Tag _ -> Some pos + | Chars (_,false) -> Some (pos-1) + | Seq (r1,r2) -> + begin match size_backward pos r2 with + | None -> None + | Some pos -> size_backward pos r1 + end + | Alt (r1,r2) -> + let pos1 = size_backward pos r1 + and pos2 = size_backward pos r2 in + if pos1=pos2 then pos1 else None + | Star _ -> None + | Action _ -> assert false in + + + let rec simple_backward pos r = match r with + | Tag n -> + if mem_name n.id double_vars then + r,Some pos + else begin + Hashtbl.add env (n.id,n.start) (Sum (End, pos)) ; + Empty,Some pos + end + | Empty -> r,Some pos + | Chars (_,is_eof) -> + r,Some (if is_eof then pos else pos-1) + | Seq (r1,r2) -> + let r2,pos = simple_backward pos r2 in + begin match pos with + | None -> mk_seq r1 r2,None + | Some pos -> + let r1,pos = simple_backward pos r1 in + mk_seq r1 r2,pos + end + | Alt (r1,r2) -> + let pos1 = size_backward pos r1 + and pos2 = size_backward pos r2 in + r,(if pos1=pos2 then pos1 else None) + | Star _ -> r,None + | Action _ -> assert false in + + let r = + if opt then + let r,_ = simple_forward 0 r in + let r,_ = simple_backward 0 r in + r + else + r in + + let loc_count = ref 0 in + let get_tag_addr t = + try + Hashtbl.find env t + with + | Not_found -> + let n = !loc_count in + incr loc_count ; + Hashtbl.add env t (Sum (Mem n,0)) ; + Sum (Mem n,0) in + + let rec alloc_exp pos r = match r with + | Tag n -> + if mem_name n.id double_vars then + r,pos + else begin match pos with + | Some a -> + Hashtbl.add env (n.id,n.start) a ; + Empty,pos + | None -> + let a = get_tag_addr (n.id,n.start) in + r,Some a + end + + | Empty -> r,pos + | Chars (_,is_eof) -> r,(if is_eof then pos else add_pos pos 1) + | Seq (r1,r2) -> + let r1,pos = alloc_exp pos r1 in + let r2,pos = alloc_exp pos r2 in + mk_seq r1 r2,pos + | Alt (_,_) -> + let off = size_forward 0 r in + begin match off with + | Some i -> r,add_pos pos i + | None -> r,None + end + | Star _ -> r,None + | Action _ -> assert false in + + let r,_ = alloc_exp None r in + let m = + IdSet.fold + (fun ((name,_) as x) r -> + + let v = + if IdSet.mem x char_vars then + Ident_char + (IdSet.mem x optional_vars, get_tag_addr (name,true)) + else + Ident_string + (IdSet.mem x optional_vars, + get_tag_addr (name,true), + get_tag_addr (name,false)) in + (x,v)::r) + all_vars [] in + m,r, !loc_count + + + +let encode_casedef casedef = + let r = + List.fold_left + (fun (reg,actions,count,ntags) (expr, act) -> + let expr = remove_nested_as expr in + let char_vars = find_chars expr in + let r = encode_regexp char_vars count expr + and opt_vars = find_optional expr + and double_vars,all_vars = find_double expr in + let m,r,loc_ntags = + opt_regexp all_vars char_vars opt_vars double_vars r in + Alt(reg, Seq(r, Action count)), + (count, m ,act) :: actions, + (succ count), + max loc_ntags ntags) + (Empty, [], 0, 0) + casedef in + r + +let encode_lexdef def = + chars := []; + chars_count := 0; + let entry_list = + List.map + (fun {name=entry_name ; args=args ; shortest=shortest ; clauses= casedef} -> + let (re,actions,_,ntags) = encode_casedef casedef in + { lex_name = entry_name; + lex_regexp = re; + lex_mem_tags = ntags ; + lex_actions = List.rev actions },args,shortest) + def in + let chr = Array.of_list (List.rev !chars) in + chars := []; + (chr, entry_list) + +(* To generate directly a NFA from a regular expression. + Confer Aho-Sethi-Ullman, dragon book, chap. 3 + Extension to tagged automata. + Confer + Ville Larikari + ``NFAs with Tagged Transitions, their Conversion to Deterministic + Automata and Application to Regular Expressions''. + Symposium on String Processing and Information Retrieval (SPIRE 2000), + http://kouli.iki.fi/~vlaurika/spire2000-tnfa.ps +(See also) + http://kouli.iki.fi/~vlaurika/regex-submatch.ps.gz +*) + +type t_transition = + OnChars of int + | ToAction of int + +type transition = t_transition * Tags.t + +let trans_compare (t1,tags1) (t2,tags2) = + match Pervasives.compare t1 t2 with + | 0 -> Tags.compare tags1 tags2 + | r -> r + + +module TransSet = + Set.Make(struct type t = transition let compare = trans_compare end) + +let rec nullable = function + | Empty|Tag _ -> true + | Chars (_,_)|Action _ -> false + | Seq(r1,r2) -> nullable r1 && nullable r2 + | Alt(r1,r2) -> nullable r1 || nullable r2 + | Star r -> true + +let rec emptymatch = function + | Empty | Chars (_,_) | Action _ -> Tags.empty + | Tag t -> Tags.add t Tags.empty + | Seq (r1,r2) -> Tags.union (emptymatch r1) (emptymatch r2) + | Alt(r1,r2) -> + if nullable r1 then + emptymatch r1 + else + emptymatch r2 + | Star r -> + if nullable r then + emptymatch r + else + Tags.empty + +let addtags transs tags = + TransSet.fold + (fun (t,tags_t) r -> TransSet.add (t, Tags.union tags tags_t) r) + transs TransSet.empty + + +let rec firstpos = function + Empty|Tag _ -> TransSet.empty + | Chars (pos,_) -> TransSet.add (OnChars pos,Tags.empty) TransSet.empty + | Action act -> TransSet.add (ToAction act,Tags.empty) TransSet.empty + | Seq(r1,r2) -> + if nullable r1 then + TransSet.union (firstpos r1) (addtags (firstpos r2) (emptymatch r1)) + else + firstpos r1 + | Alt(r1,r2) -> TransSet.union (firstpos r1) (firstpos r2) + | Star r -> firstpos r + + +(* Berry-sethi followpos *) +let followpos size entry_list = + let v = Array.create size TransSet.empty in + let rec fill s = function + | Empty|Action _|Tag _ -> () + | Chars (n,_) -> v.(n) <- s + | Alt (r1,r2) -> + fill s r1 ; fill s r2 + | Seq (r1,r2) -> + fill + (if nullable r2 then + TransSet.union (firstpos r2) (addtags s (emptymatch r2)) + else + (firstpos r2)) + r1 ; + fill s r2 + | Star r -> + fill (TransSet.union (firstpos r) s) r in + List.iter (fun (entry,_,_) -> fill TransSet.empty entry.lex_regexp) entry_list ; + v + +(************************) +(* The algorithm itself *) +(************************) + +let no_action = max_int + +module StateSet = + Set.Make (struct type t = t_transition let compare = Pervasives.compare end) + + +module MemMap = + Map.Make (struct type t = int let compare = Pervasives.compare end) + +type 'a dfa_state = + {final : int * ('a * int TagMap.t) ; + others : ('a * int TagMap.t) MemMap.t} + + +let dtag oc t = + fprintf oc "%s<%s>" t.id (if t.start then "s" else "e") + +let dmem_map dp ds m = + MemMap.iter + (fun k x -> + eprintf "%d -> " k ; dp x ; ds ()) + m + +and dtag_map dp ds m = + TagMap.iter + (fun t x -> + dtag stderr t ; eprintf " -> " ; dp x ; ds ()) + m + +let dstate {final=(act,(_,m)) ; others=o} = + if act <> no_action then begin + eprintf "final=%d " act ; + dtag_map (fun x -> eprintf "%d" x) (fun () -> prerr_string " ,") m ; + prerr_endline "" + end ; + dmem_map + (fun (_,m) -> + dtag_map (fun x -> eprintf "%d" x) (fun () -> prerr_string " ,") m) + (fun () -> prerr_endline "") + o + + +let dfa_state_empty = + {final=(no_action, (max_int,TagMap.empty)) ; + others=MemMap.empty} + +and dfa_state_is_empty {final=(act,_) ; others=o} = + act = no_action && + o = MemMap.empty + + +(* A key is an abstraction on a dfa state, + two states with the same key can be made the same by + copying some memory cells into others *) + + +module StateSetSet = + Set.Make (struct type t = StateSet.t let compare = StateSet.compare end) + +type t_equiv = {tag:tag_info ; equiv:StateSetSet.t} + +module MemKey = + Set.Make + (struct + type t = t_equiv + + let compare e1 e2 = match Pervasives.compare e1.tag e2.tag with + | 0 -> StateSetSet.compare e1.equiv e2.equiv + | r -> r + end) + +type dfa_key = {kstate : StateSet.t ; kmem : MemKey.t} + +(* Map a state to its key *) +let env_to_class m = + let env1 = + MemMap.fold + (fun _ (tag,s) r -> + try + let ss = TagMap.find tag r in + let r = TagMap.remove tag r in + TagMap.add tag (StateSetSet.add s ss) r + with + | Not_found -> + TagMap.add tag (StateSetSet.add s StateSetSet.empty) r) + m TagMap.empty in + TagMap.fold + (fun tag ss r -> MemKey.add {tag=tag ; equiv=ss} r) + env1 MemKey.empty + + +(* trans is nfa_state, m is associated memory map *) +let inverse_mem_map trans m r = + TagMap.fold + (fun tag addr r -> + try + let otag,s = MemMap.find addr r in + assert (tag = otag) ; + let r = MemMap.remove addr r in + MemMap.add addr (tag,StateSet.add trans s) r + with + | Not_found -> + MemMap.add addr (tag,StateSet.add trans StateSet.empty) r) + m r + +let inverse_mem_map_other n (_,m) r = inverse_mem_map (OnChars n) m r + +let get_key {final=(act,(_,m_act)) ; others=o} = + let env = + MemMap.fold inverse_mem_map_other + o + (if act = no_action then MemMap.empty + else inverse_mem_map (ToAction act) m_act MemMap.empty) in + let state_key = + MemMap.fold (fun n _ r -> StateSet.add (OnChars n) r) o + (if act=no_action then StateSet.empty + else StateSet.add (ToAction act) StateSet.empty) in + let mem_key = env_to_class env in + {kstate = state_key ; kmem = mem_key} + + +let key_compare k1 k2 = match StateSet.compare k1.kstate k2.kstate with +| 0 -> MemKey.compare k1.kmem k2.kmem +| r -> r + +(* Association dfa_state -> state_num *) + +module StateMap = + Map.Make(struct type t = dfa_key let compare = key_compare end) + +let state_map = ref (StateMap.empty : int StateMap.t) +let todo = Stack.create() +let next_state_num = ref 0 +let next_mem_cell = ref 0 +let temp_pending = ref false +let tag_cells = Hashtbl.create 17 +let state_table = Table.create dfa_state_empty + + +(* Initial reset of state *) +let reset_state () = + Stack.clear todo; + next_state_num := 0 ; + let _ = Table.trim state_table in + () + +(* Reset state before processing a given automata. + We clear both the memory mapping and + the state mapping, as state sharing beetween different + automata may lead to incorret estimation of the cell memory size + BUG ID 0004517 *) + + +let reset_state_partial ntags = + next_mem_cell := ntags ; + Hashtbl.clear tag_cells ; + temp_pending := false ; + state_map := StateMap.empty + +let do_alloc_temp () = + temp_pending := true ; + let n = !next_mem_cell in + n + +let do_alloc_cell used t = + let available = + try Hashtbl.find tag_cells t with Not_found -> Ints.empty in + try + Ints.choose (Ints.diff available used) + with + | Not_found -> + temp_pending := false ; + let n = !next_mem_cell in + if n >= 255 then raise Memory_overflow ; + Hashtbl.replace tag_cells t (Ints.add n available) ; + incr next_mem_cell ; + n + +let is_old_addr a = a >= 0 +and is_new_addr a = a < 0 + +let old_in_map m r = + TagMap.fold + (fun _ addr r -> + if is_old_addr addr then + Ints.add addr r + else + r) + m r + +let alloc_map used m mvs = + TagMap.fold + (fun tag a (r,mvs) -> + let a,mvs = + if is_new_addr a then + let a = do_alloc_cell used tag in + a,Ints.add a mvs + else a,mvs in + TagMap.add tag a r,mvs) + m (TagMap.empty,mvs) + +let create_new_state {final=(act,(_,m_act)) ; others=o} = + let used = + MemMap.fold (fun _ (_,m) r -> old_in_map m r) + o (old_in_map m_act Ints.empty) in + + let new_m_act,mvs = alloc_map used m_act Ints.empty in + let new_o,mvs = + MemMap.fold (fun k (x,m) (r,mvs) -> + let m,mvs = alloc_map used m mvs in + MemMap.add k (x,m) r,mvs) + o (MemMap.empty,mvs) in + {final=(act,(0,new_m_act)) ; others=new_o}, + Ints.fold (fun x r -> Set x::r) mvs [] + +type new_addr_gen = {mutable count : int ; mutable env : int TagMap.t} + +let create_new_addr_gen () = {count = -1 ; env = TagMap.empty} + +let alloc_new_addr tag r = + try + TagMap.find tag r.env + with + | Not_found -> + let a = r.count in + r.count <- a-1 ; + r.env <- TagMap.add tag a r.env ; + a + + +let create_mem_map tags gen = + Tags.fold + (fun tag r -> TagMap.add tag (alloc_new_addr tag gen) r) + tags TagMap.empty + +let create_init_state pos = + let gen = create_new_addr_gen () in + let st = + TransSet.fold + (fun (t,tags) st -> + match t with + | ToAction n -> + let on,otags = st.final in + if n < on then + {st with final = (n, (0,create_mem_map tags gen))} + else + st + | OnChars n -> + try + let _ = MemMap.find n st.others in assert false + with + | Not_found -> + {st with others = + MemMap.add n (0,create_mem_map tags gen) st.others}) + pos dfa_state_empty in + st + + +let get_map t st = match t with +| ToAction _ -> let _,(_,m) = st.final in m +| OnChars n -> + let (_,m) = MemMap.find n st.others in + m + +let dest = function | Copy (d,_) | Set d -> d +and orig = function | Copy (_,o) -> o | Set _ -> -1 + +let pmv oc mv = fprintf oc "%d <- %d" (dest mv) (orig mv) +let pmvs oc mvs = + List.iter (fun mv -> fprintf oc "%a " pmv mv) mvs ; + output_char oc '\n' ; flush oc + + +(* Topological sort << a la louche >> *) +let sort_mvs mvs = + let rec do_rec r mvs = match mvs with + | [] -> r + | _ -> + let dests = + List.fold_left + (fun r mv -> Ints.add (dest mv) r) + Ints.empty mvs in + let rem,here = + List.partition + (fun mv -> Ints.mem (orig mv) dests) + mvs in + match here with + | [] -> + begin match rem with + | Copy (d,_)::_ -> + let d' = do_alloc_temp () in + Copy (d',d):: + do_rec r + (List.map + (fun mv -> + if orig mv = d then + Copy (dest mv,d') + else + mv) + rem) + | _ -> assert false + end + | _ -> do_rec (here@r) rem in + do_rec [] mvs + +let move_to mem_key src tgt = + let mvs = + MemKey.fold + (fun {tag=tag ; equiv=m} r -> + StateSetSet.fold + (fun s r -> + try + let t = StateSet.choose s in + let src = TagMap.find tag (get_map t src) + and tgt = TagMap.find tag (get_map t tgt) in + if src <> tgt then begin + if is_new_addr src then + Set tgt::r + else + Copy (tgt, src)::r + end else + r + with + | Not_found -> assert false) + m r) + mem_key [] in +(* Moves are topologically sorted *) + sort_mvs mvs + + +let get_state st = + let key = get_key st in + try + let num = StateMap.find key !state_map in + num,move_to key.kmem st (Table.get state_table num) + with Not_found -> + let num = !next_state_num in + incr next_state_num; + let st,mvs = create_new_state st in + Table.emit state_table st ; + state_map := StateMap.add key num !state_map; + Stack.push (st, num) todo; + num,mvs + +let map_on_all_states f old_res = + let res = ref old_res in + begin try + while true do + let (st, i) = Stack.pop todo in + let r = f st in + res := (r, i) :: !res + done + with Stack.Empty -> () + end; + !res + +let goto_state st = + if + dfa_state_is_empty st + then + Backtrack,[] + else + let n,moves = get_state st in + Goto n,moves + +(****************************) +(* compute reachable states *) +(****************************) + +let add_tags_to_map gen tags m = + Tags.fold + (fun tag m -> + let m = TagMap.remove tag m in + TagMap.add tag (alloc_new_addr tag gen) m) + tags m + +let apply_transition gen r pri m = function + | ToAction n,tags -> + let on,(opri,_) = r.final in + if n < on || (on=n && pri < opri) then + let m = add_tags_to_map gen tags m in + {r with final=n,(pri,m)} + else r + | OnChars n,tags -> + try + let (opri,_) = MemMap.find n r.others in + if pri < opri then + let m = add_tags_to_map gen tags m in + {r with others=MemMap.add n (pri,m) (MemMap.remove n r.others)} + else + r + with + | Not_found -> + let m = add_tags_to_map gen tags m in + {r with others=MemMap.add n (pri,m) r.others} + +(* add transitions ts to new state r + transitions in ts start from state pri and memory map m +*) +let apply_transitions gen r pri m ts = + TransSet.fold + (fun t r -> apply_transition gen r pri m t) + ts r + + +(* For a given nfa_state pos, refine char partition *) +let rec split_env gen follow pos m s = function + | [] -> (* Can occur ! because of non-matching regexp ([^'\000'-'\255']) *) + [] + | (s1,st1) as p::rem -> + let here = Cset.inter s s1 in + if Cset.is_empty here then + p::split_env gen follow pos m s rem + else + let rest = Cset.diff s here in + let rem = + if Cset.is_empty rest then + rem + else + split_env gen follow pos m rest rem + and new_st = apply_transitions gen st1 pos m follow in + let stay = Cset.diff s1 here in + if Cset.is_empty stay then + (here, new_st)::rem + else + (stay, st1)::(here, new_st)::rem + + +(* For all nfa_state pos in a dfa state st *) +let comp_shift gen chars follow st = + MemMap.fold + (fun pos (_,m) env -> split_env gen follow.(pos) pos m chars.(pos) env) + st [Cset.all_chars_eof,dfa_state_empty] + + +let reachs chars follow st = + let gen = create_new_addr_gen () in +(* build a association list (char set -> new state) *) + let env = comp_shift gen chars follow st in +(* change it into (char set -> new state_num) *) + let env = + List.map + (fun (s,dfa_state) -> s,goto_state dfa_state) env in +(* finally build the char indexed array -> new state num *) + let shift = Cset.env_to_array env in + shift + + +let get_tag_mem n env t = + try + TagMap.find t env.(n) + with + | Not_found -> assert false + +let do_tag_actions n env m = + + let used,r = + TagMap.fold (fun t m (used,r) -> + let a = get_tag_mem n env t in + Ints.add a used,SetTag (a,m)::r) m (Ints.empty,[]) in + let _,r = + TagMap.fold + (fun tag m (used,r) -> + if not (Ints.mem m used) && tag.start then + Ints.add m used, EraseTag m::r + else + used,r) + env.(n) (used,r) in + r + + +let translate_state shortest_match tags chars follow st = + let (n,(_,m)) = st.final in + if MemMap.empty = st.others then + Perform (n,do_tag_actions n tags m) + else if shortest_match then begin + if n=no_action then + Shift (No_remember,reachs chars follow st.others) + else + Perform(n, do_tag_actions n tags m) + end else begin + Shift ( + (if n = no_action then + No_remember + else + Remember (n,do_tag_actions n tags m)), + reachs chars follow st.others) + end + +let dtags chan tags = + Tags.iter + (fun t -> fprintf chan " %a" dtag t) + tags + +let dtransset s = + TransSet.iter + (fun trans -> match trans with + | OnChars i,tags -> + eprintf " (-> %d,%a)" i dtags tags + | ToAction i,tags -> + eprintf " ([%d],%a)" i dtags tags) + s + +let dfollow t = + eprintf "follow=[" ; + for i = 0 to Array.length t-1 do + eprintf "%d:" i ; + dtransset t.(i) + done ; + prerr_endline "]" + + +let make_tag_entry id start act a r = match a with + | Sum (Mem m,0) -> + TagMap.add {id=id ; start=start ; action=act} m r + | _ -> r + +let extract_tags l = + let envs = Array.create (List.length l) TagMap.empty in + List.iter + (fun (act,m,_) -> + envs.(act) <- + List.fold_right + (fun ((name,_),v) r -> match v with + | Ident_char (_,t) -> make_tag_entry name true act t r + | Ident_string (_,t1,t2) -> + make_tag_entry name true act t1 + (make_tag_entry name false act t2 r)) + m TagMap.empty) + l ; + envs + + +let make_dfa lexdef = + let (chars, entry_list) = encode_lexdef lexdef in + let follow = followpos (Array.length chars) entry_list in +(* + dfollow follow ; +*) + reset_state () ; + let r_states = ref [] in + let initial_states = + List.map + (fun (le,args,shortest) -> + let tags = extract_tags le.lex_actions in + reset_state_partial le.lex_mem_tags ; + let pos_set = firstpos le.lex_regexp in +(* + prerr_string "trans={" ; dtransset pos_set ; prerr_endline "}" ; +*) + let init_state = create_init_state pos_set in + let init_num = get_state init_state in + r_states := + map_on_all_states + (translate_state shortest tags chars follow) !r_states ; + { auto_name = le.lex_name; + auto_args = args ; + auto_mem_size = + (if !temp_pending then !next_mem_cell+1 else !next_mem_cell) ; + auto_initial_state = init_num ; + auto_actions = le.lex_actions }) + entry_list in + let states = !r_states in +(* + prerr_endline "** states **" ; + for i = 0 to !next_state_num-1 do + eprintf "+++ %d +++\n" i ; + dstate (Table.get state_table i) ; + prerr_endline "" + done ; + eprintf "%d states\n" !next_state_num ; +*) + let actions = Array.create !next_state_num (Perform (0,[])) in + List.iter (fun (act, i) -> actions.(i) <- act) states; +(* Useless state reset, so as to restrict GC roots *) + reset_state () ; + reset_state_partial 0 ; + (initial_states, actions) diff --git a/lex/lexgen.mli b/lex/lexgen.mli new file mode 100644 index 0000000..3dfb31a --- /dev/null +++ b/lex/lexgen.mli @@ -0,0 +1,61 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexgen.mli,v 1.6 2007-01-29 16:44:16 maranget Exp $ *) + + +(* raised when there are too many bindings (>= 254 memory cells) *) +exception Memory_overflow + + +(* Representation of automata *) + + +type automata = + Perform of int * tag_action list + | Shift of automata_trans * (automata_move * memory_action list) array +and automata_trans = + No_remember + | Remember of int * tag_action list +and automata_move = + Backtrack + | Goto of int +and memory_action = + | Copy of int * int + | Set of int + +and tag_action = SetTag of int * int | EraseTag of int + +type ident = string * Syntax.location + +(* Representation of entry points *) +type tag_base = Start | End | Mem of int +type tag_addr = Sum of (tag_base * int) +type ident_info = + | Ident_string of bool * tag_addr * tag_addr + | Ident_char of bool * tag_addr + +type t_env = (ident * ident_info) list + +type ('args,'action) automata_entry = + { auto_name: string; + auto_args: 'args ; + auto_mem_size : int ; + auto_initial_state: int * memory_action list ; + auto_actions: (int * t_env * 'action) list } + +(* The entry point *) + +val make_dfa : + ('args, 'action) Syntax.entry list -> + ('args, 'action) automata_entry list * automata array + diff --git a/lex/main.ml b/lex/main.ml new file mode 100644 index 0000000..fd05749 --- /dev/null +++ b/lex/main.ml @@ -0,0 +1,119 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.ml,v 1.22 2004-08-20 17:04:35 doligez Exp $ *) + +(* The lexer generator. Command-line parsing. *) + +open Syntax +open Lexgen + +let ml_automata = ref false +let source_name = ref None +let output_name = ref None + +let usage = "usage: ocamlex [options] sourcefile" + +let print_version_string () = + print_string "The Objective Caml lexer generator, version "; + print_string Sys.ocaml_version ; print_newline(); + exit 0 + +let specs = + ["-ml", Arg.Set ml_automata, + " Output code that does not use the Lexing module built-in automata interpreter"; + "-o", Arg.String (fun x -> output_name := Some x), + " Set output file name to "; + "-q", Arg.Set Common.quiet_mode, " Do not display informational messages"; + "-v", Arg.Unit print_version_string, " Print version and exit"; + "-version", Arg.Unit print_version_string, " Print version and exit"; + ] + +let _ = + Arg.parse + specs + (fun name -> source_name := Some name) + usage + + +let main () = + + let source_name = match !source_name with + | None -> Arg.usage specs usage ; exit 2 + | Some name -> name in + let dest_name = match !output_name with + | Some name -> name + | None -> + if Filename.check_suffix source_name ".mll" then + Filename.chop_suffix source_name ".mll" ^ ".ml" + else + source_name ^ ".ml" in + + let ic = open_in_bin source_name in + let oc = open_out dest_name in + let tr = Common.open_tracker dest_name oc in + let lexbuf = Lexing.from_channel ic in + lexbuf.Lexing.lex_curr_p <- + {Lexing.pos_fname = source_name; Lexing.pos_lnum = 1; + Lexing.pos_bol = 0; Lexing.pos_cnum = 0}; + try + let def = Parser.lexer_definition Lexer.main lexbuf in + let (entries, transitions) = Lexgen.make_dfa def.entrypoints in + if !ml_automata then begin + Outputbis.output_lexdef + source_name ic oc tr + def.header entries transitions def.trailer + end else begin + let tables = Compact.compact_tables transitions in + Output.output_lexdef source_name ic oc tr + def.header tables entries def.trailer + end; + close_in ic; + close_out oc; + Common.close_tracker tr; + with exn -> + close_in ic; + close_out oc; + Common.close_tracker tr; + Sys.remove dest_name; + begin match exn with + | Cset.Bad -> + let p = Lexing.lexeme_start_p lexbuf in + Printf.fprintf stderr + "File \"%s\", line %d, character %d: character set expected.\n" + p.Lexing.pos_fname p.Lexing.pos_lnum + (p.Lexing.pos_cnum - p.Lexing.pos_bol) + | Parsing.Parse_error -> + let p = Lexing.lexeme_start_p lexbuf in + Printf.fprintf stderr + "File \"%s\", line %d, character %d: syntax error.\n" + p.Lexing.pos_fname p.Lexing.pos_lnum + (p.Lexing.pos_cnum - p.Lexing.pos_bol) + | Lexer.Lexical_error(msg, file, line, col) -> + Printf.fprintf stderr + "File \"%s\", line %d, character %d: %s.\n" + file line col msg + | Lexgen.Memory_overflow -> + Printf.fprintf stderr + "File \"%s\":\n Position memory overflow, too many bindings\n" + source_name + | Output.Table_overflow -> + Printf.fprintf stderr + "File \"%s\":\ntransition table overflow, automaton is too big\n" + source_name + | _ -> + raise exn + end; + exit 3 + +let _ = (* Printexc.catch *) main (); exit 0 + diff --git a/lex/output.ml b/lex/output.ml new file mode 100644 index 0000000..3c668b2 --- /dev/null +++ b/lex/output.ml @@ -0,0 +1,140 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: output.ml,v 1.26 2007-01-29 16:44:16 maranget Exp $ *) + +(* Output the DFA tables and its entry points *) + +open Printf +open Syntax +open Lexgen +open Compact +open Common + +(* To output an array of short ints, encoded as a string *) + +let output_byte oc b = + output_char oc '\\'; + output_char oc (Char.chr(48 + b / 100)); + output_char oc (Char.chr(48 + (b / 10) mod 10)); + output_char oc (Char.chr(48 + b mod 10)) + +let output_array oc v = + output_string oc " \""; + for i = 0 to Array.length v - 1 do + output_byte oc (v.(i) land 0xFF); + output_byte oc ((v.(i) asr 8) land 0xFF); + if i land 7 = 7 then output_string oc "\\\n " + done; + output_string oc "\"" + +let output_byte_array oc v = + output_string oc " \""; + for i = 0 to Array.length v - 1 do + output_byte oc (v.(i) land 0xFF); + if i land 15 = 15 then output_string oc "\\\n " + done; + output_string oc "\"" + +(* Output the tables *) + +let output_tables oc tbl = + output_string oc "let __ocaml_lex_tables = {\n"; + + fprintf oc " Lexing.lex_base = \n%a;\n" output_array tbl.tbl_base; + fprintf oc " Lexing.lex_backtrk = \n%a;\n" output_array tbl.tbl_backtrk; + fprintf oc " Lexing.lex_default = \n%a;\n" output_array tbl.tbl_default; + fprintf oc " Lexing.lex_trans = \n%a;\n" output_array tbl.tbl_trans; + fprintf oc " Lexing.lex_check = \n%a;\n" output_array tbl.tbl_check; + fprintf oc " Lexing.lex_base_code = \n%a;\n" output_array tbl.tbl_base_code; + + fprintf oc " Lexing.lex_backtrk_code = \n%a;\n" + output_array tbl.tbl_backtrk_code; + fprintf oc " Lexing.lex_default_code = \n%a;\n" + output_array tbl.tbl_default_code; + fprintf oc " Lexing.lex_trans_code = \n%a;\n" + output_array tbl.tbl_trans_code; + fprintf oc " Lexing.lex_check_code = \n%a;\n" + output_array tbl.tbl_check_code; + fprintf oc " Lexing.lex_code = \n%a;\n" output_byte_array tbl.tbl_code; + + output_string oc "}\n\n" + + +(* Output the entries *) + +let output_entry sourcefile ic oc oci e = + let init_num, init_moves = e.auto_initial_state in + fprintf oc "%s %alexbuf = + %a%a __ocaml_lex_%s_rec %alexbuf %d\n" + e.auto_name + output_args e.auto_args + (fun oc x -> + if x > 0 then + fprintf oc "lexbuf.Lexing.lex_mem <- Array.create %d (-1) ; " x) + e.auto_mem_size + (output_memory_actions " ") init_moves + e.auto_name + output_args e.auto_args + init_num; + fprintf oc "and __ocaml_lex_%s_rec %alexbuf __ocaml_lex_state =\n" + e.auto_name output_args e.auto_args ; + fprintf oc " match Lexing.%sengine" + (if e.auto_mem_size == 0 then "" else "new_"); + fprintf oc " __ocaml_lex_tables __ocaml_lex_state lexbuf with\n "; + List.iter + (fun (num, env, loc) -> + fprintf oc " | "; + fprintf oc "%d ->\n" num; + output_env sourcefile ic oc oci env; + copy_chunk sourcefile ic oc oci loc true; + fprintf oc "\n") + e.auto_actions; + fprintf oc " | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf; \ + __ocaml_lex_%s_rec %alexbuf __ocaml_lex_state\n\n" + e.auto_name output_args e.auto_args + +(* Main output function *) + +exception Table_overflow + +let output_lexdef sourcefile ic oc oci header tables entry_points trailer = + if not !Common.quiet_mode then + Printf.printf "%d states, %d transitions, table size %d bytes\n" + (Array.length tables.tbl_base) + (Array.length tables.tbl_trans) + (2 * (Array.length tables.tbl_base + Array.length tables.tbl_backtrk + + Array.length tables.tbl_default + Array.length tables.tbl_trans + + Array.length tables.tbl_check)); + let size_groups = + (2 * (Array.length tables.tbl_base_code + + Array.length tables.tbl_backtrk_code + + Array.length tables.tbl_default_code + + Array.length tables.tbl_trans_code + + Array.length tables.tbl_check_code) + + Array.length tables.tbl_code) in + if size_groups > 0 && not !Common.quiet_mode then + Printf.printf "%d additional bytes used for bindings\n" size_groups ; + flush stdout; + if Array.length tables.tbl_trans > 0x8000 then raise Table_overflow; + copy_chunk sourcefile ic oc oci header false; + output_tables oc tables; + begin match entry_points with + [] -> () + | entry1 :: entries -> + output_string oc "let rec "; output_entry sourcefile ic oc oci entry1; + List.iter + (fun e -> output_string oc "and "; output_entry sourcefile ic oc oci e) + entries; + output_string oc ";;\n\n"; + end; + copy_chunk sourcefile ic oc oci trailer false diff --git a/lex/output.mli b/lex/output.mli new file mode 100644 index 0000000..88633db --- /dev/null +++ b/lex/output.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: output.mli,v 1.8 2002-12-09 10:44:46 maranget Exp $ *) + +(* Output the DFA tables and its entry points *) + +val output_lexdef: + string -> in_channel -> out_channel -> Common.line_tracker -> + Syntax.location -> + Compact.lex_tables -> + (string list, Syntax.location) Lexgen.automata_entry list -> + Syntax.location -> + unit + +exception Table_overflow diff --git a/lex/outputbis.ml b/lex/outputbis.ml new file mode 100644 index 0000000..fa6e27b --- /dev/null +++ b/lex/outputbis.ml @@ -0,0 +1,193 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: outputbis.ml,v 1.6 2007-01-29 16:44:16 maranget Exp $ *) + +(* Output the DFA tables and its entry points *) + +open Printf +open Syntax +open Lexgen +open Common + +let output_auto_defs oc = + fprintf oc "let __ocaml_lex_init_lexbuf lexbuf mem_size = + let pos = lexbuf.Lexing.lex_curr_pos in + lexbuf.Lexing.lex_mem <- Array.create mem_size (-1) ; + lexbuf.Lexing.lex_start_pos <- pos ; + lexbuf.Lexing.lex_last_pos <- pos ; + lexbuf.Lexing.lex_last_action <- -1 + +" ; + + output_string oc + "let rec __ocaml_lex_next_char lexbuf = + if lexbuf.Lexing.lex_curr_pos >= lexbuf.Lexing.lex_buffer_len then begin + if lexbuf.Lexing.lex_eof_reached then + 256 + else begin + lexbuf.Lexing.refill_buff lexbuf ; + __ocaml_lex_next_char lexbuf + end + end else begin + let i = lexbuf.Lexing.lex_curr_pos in + let c = lexbuf.Lexing.lex_buffer.[i] in + lexbuf.Lexing.lex_curr_pos <- i+1 ; + Char.code c + end + +" + + +let output_pats oc pats = List.iter (fun p -> fprintf oc "|%d" p) pats + +let output_action oc mems r = + output_memory_actions " " oc mems ; + match r with + | Backtrack -> + fprintf oc + " lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ;\n" ; + fprintf oc " lexbuf.Lexing.lex_last_action\n" + | Goto n -> + fprintf oc " __ocaml_lex_state%d lexbuf\n" n + +let output_pat oc i = + if i >= 256 then + fprintf oc "|eof" + else + fprintf oc "|'%s'" (Char.escaped (Char.chr i)) + +let output_clause oc pats mems r = + fprintf oc "(* " ; + List.iter (output_pat oc) pats ; + fprintf oc " *)\n" ; + fprintf oc " %a ->\n" output_pats pats ; output_action oc mems r + +let output_default_clause oc mems r = + fprintf oc " | _ ->\n" ; output_action oc mems r + + +let output_moves oc moves = + let t = Hashtbl.create 17 in + let add_move i (m,mems) = + let mems,r = try Hashtbl.find t m with Not_found -> mems,[] in + Hashtbl.replace t m (mems,(i::r)) in + + for i = 0 to 256 do + add_move i moves.(i) + done ; + + let most_frequent = ref Backtrack + and most_mems = ref [] + and size = ref 0 in + Hashtbl.iter + (fun m (mems,pats) -> + let size_m = List.length pats in + if size_m > !size then begin + most_frequent := m ; + most_mems := mems ; + size := size_m + end) + t ; + Hashtbl.iter + (fun m (mems,pats) -> + if m <> !most_frequent then output_clause oc (List.rev pats) mems m) + t ; + output_default_clause oc !most_mems !most_frequent + + +let output_tag_actions pref oc mvs = + output_string oc "(*" ; + List.iter + (fun i -> match i with + | SetTag (t,m) -> fprintf oc " t%d <- [%d] ;" t m + | EraseTag t -> fprintf oc " t%d <- -1 ;" t) + mvs ; + output_string oc " *)\n" ; + List.iter + (fun i -> match i with + | SetTag (t,m) -> + fprintf oc "%s%a <- %a ;\n" + pref output_mem_access t output_mem_access m + | EraseTag t -> + fprintf oc "%s%a <- -1 ;\n" + pref output_mem_access t) + mvs + +let output_trans pref oc i trans = + fprintf oc "%s __ocaml_lex_state%d lexbuf = " pref i ; + match trans with + | Perform (n,mvs) -> + output_tag_actions " " oc mvs ; + fprintf oc " %d\n" n + | Shift (trans, move) -> + begin match trans with + | Remember (n,mvs) -> + output_tag_actions " " oc mvs ; + fprintf oc + " lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_curr_pos ;\n" ; + fprintf oc " lexbuf.Lexing.lex_last_action <- %d ;\n" n + | No_remember -> () + end ; + fprintf oc " match __ocaml_lex_next_char lexbuf with\n" ; + output_moves oc move + +let output_automata oc auto = + output_auto_defs oc ; + let n = Array.length auto in + output_trans "let rec" oc 0 auto.(0) ; + for i = 1 to n-1 do + output_trans "\nand" oc i auto.(i) + done ; + output_char oc '\n' + + +(* Output the entries *) + +let output_entry sourcefile ic oc tr e = + let init_num, init_moves = e.auto_initial_state in + fprintf oc "%s %alexbuf = + __ocaml_lex_init_lexbuf lexbuf %d; %a + let __ocaml_lex_result = __ocaml_lex_state%d lexbuf in + lexbuf.Lexing.lex_start_p <- lexbuf.Lexing.lex_curr_p; + lexbuf.Lexing.lex_curr_p <- {lexbuf.Lexing.lex_curr_p with + Lexing.pos_cnum = lexbuf.Lexing.lex_abs_pos + lexbuf.Lexing.lex_curr_pos}; + match __ocaml_lex_result with\n" + e.auto_name output_args e.auto_args + e.auto_mem_size (output_memory_actions " ") init_moves init_num ; + List.iter + (fun (num, env, loc) -> + fprintf oc " | "; + fprintf oc "%d ->\n" num; + output_env sourcefile ic oc tr env ; + copy_chunk sourcefile ic oc tr loc true; + fprintf oc "\n") + e.auto_actions; + fprintf oc " | _ -> raise (Failure \"lexing: empty token\")\n\n\n" + + +(* Main output function *) + +let output_lexdef sourcefile ic oc tr header entry_points transitions trailer = + + copy_chunk sourcefile ic oc tr header false; + output_automata oc transitions ; + begin match entry_points with + [] -> () + | entry1 :: entries -> + output_string oc "let rec "; output_entry sourcefile ic oc tr entry1; + List.iter + (fun e -> output_string oc "and "; output_entry sourcefile ic oc tr e) + entries; + output_string oc ";;\n\n"; + end; + copy_chunk sourcefile ic oc tr trailer false diff --git a/lex/outputbis.mli b/lex/outputbis.mli new file mode 100644 index 0000000..3f05af8 --- /dev/null +++ b/lex/outputbis.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget projet Moscova INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: outputbis.mli,v 1.3 2002-12-09 10:44:46 maranget Exp $ *) +val output_lexdef : + string -> + in_channel -> + out_channel -> + Common.line_tracker -> + Syntax.location -> + (string list, Syntax.location) Lexgen.automata_entry list -> + Lexgen.automata array -> Syntax.location -> unit diff --git a/lex/parser.mly b/lex/parser.mly new file mode 100644 index 0000000..4772ffd --- /dev/null +++ b/lex/parser.mly @@ -0,0 +1,192 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: parser.mly,v 1.23 2007-01-29 16:44:16 maranget Exp $ */ + +/* The grammar for lexer definitions */ + +%{ +open Syntax + +(* Auxiliaries for the parser. *) + +let named_regexps = + (Hashtbl.create 13 : (string, regular_expression) Hashtbl.t) + +let regexp_for_string s = + let rec re_string n = + if n >= String.length s then Epsilon + else if succ n = String.length s then + Characters (Cset.singleton (Char.code s.[n])) + else + Sequence + (Characters(Cset.singleton (Char.code s.[n])), + re_string (succ n)) + in re_string 0 + +let rec remove_as = function + | Bind (e,_) -> remove_as e + | Epsilon|Eof|Characters _ as e -> e + | Sequence (e1, e2) -> Sequence (remove_as e1, remove_as e2) + | Alternative (e1, e2) -> Alternative (remove_as e1, remove_as e2) + | Repetition e -> Repetition (remove_as e) + +let as_cset = function + | Characters s -> s + | _ -> raise Cset.Bad + +%} + +%token Tident +%token Tchar +%token Tstring +%token Taction +%token Trule Tparse Tparse_shortest Tand Tequal Tend Tor Tunderscore Teof Tlbracket Trbracket +%token Tstar Tmaybe Tplus Tlparen Trparen Tcaret Tdash Tlet Tas Tsharp + +%right Tas +%left Tsharp +%left Tor +%nonassoc CONCAT +%nonassoc Tmaybe Tstar Tplus + Tident Tchar Tstring Tunderscore Teof Tlbracket Tlparen + +%start lexer_definition +%type lexer_definition + +%% + +lexer_definition: + header named_regexps Trule definition other_definitions header Tend + { {header = $1; + entrypoints = $4 :: List.rev $5; + trailer = $6} } +; +header: + Taction + { $1 } + | /*epsilon*/ + { { start_pos = 0; end_pos = 0; start_line = 1; start_col = 0 } } +; +named_regexps: + named_regexps Tlet Tident Tequal regexp + { Hashtbl.add named_regexps $3 $5 } + | /*epsilon*/ + { () } +; +other_definitions: + other_definitions Tand definition + { $3::$1 } + | /*epsilon*/ + { [] } +; +definition: + Tident arguments Tequal Tparse entry + { {name=$1 ; shortest=false ; args=$2 ; clauses=$5} } + | Tident arguments Tequal Tparse_shortest entry + { {name=$1 ; shortest=true ; args=$2 ; clauses=$5} } +; + +arguments: + Tident arguments { $1::$2 } +| /*epsilon*/ { [] } +; + + +entry: + case rest_of_entry + { $1::List.rev $2 } +| Tor case rest_of_entry + { $2::List.rev $3 } +; + +rest_of_entry: + rest_of_entry Tor case + { $3::$1 } + | + { [] } +; +case: + regexp Taction + { ($1,$2) } +; +regexp: + Tunderscore + { Characters Cset.all_chars } + | Teof + { Eof } + | Tchar + { Characters (Cset.singleton $1) } + | Tstring + { regexp_for_string $1 } + | Tlbracket char_class Trbracket + { Characters $2 } + | regexp Tstar + { Repetition $1 } + | regexp Tmaybe + { Alternative(Epsilon, $1) } + | regexp Tplus + { Sequence(Repetition (remove_as $1), $1) } + | regexp Tsharp regexp + { + let s1 = as_cset $1 + and s2 = as_cset $3 in + Characters (Cset.diff s1 s2) + } + | regexp Tor regexp + { Alternative($1,$3) } + | regexp regexp %prec CONCAT + { Sequence($1,$2) } + | Tlparen regexp Trparen + { $2 } + | Tident + { try + Hashtbl.find named_regexps $1 + with Not_found -> + let p = Parsing.symbol_start_pos () in + Printf.eprintf "File \"%s\", line %d, character %d:\n\ + Reference to unbound regexp name `%s'.\n" + p.Lexing.pos_fname p.Lexing.pos_lnum + (p.Lexing.pos_cnum - p.Lexing.pos_bol) + $1; + exit 2 } + | regexp Tas ident + {let p1 = Parsing.rhs_start_pos 3 + and p2 = Parsing.rhs_end_pos 3 in + let p = { + start_pos = p1.Lexing.pos_cnum ; + end_pos = p2.Lexing.pos_cnum ; + start_line = p1.Lexing.pos_lnum ; + start_col = p1.Lexing.pos_cnum - p1.Lexing.pos_bol ; } in + Bind ($1, ($3, p))} +; + +ident: + Tident {$1} +; + +char_class: + Tcaret char_class1 + { Cset.complement $2 } + | char_class1 + { $1 } +; +char_class1: + Tchar Tdash Tchar + { Cset.interval $1 $3 } + | Tchar + { Cset.singleton $1 } + | char_class1 char_class1 %prec CONCAT + { Cset.union $1 $2 } +; + +%% diff --git a/lex/syntax.ml b/lex/syntax.ml new file mode 100644 index 0000000..71b07f7 --- /dev/null +++ b/lex/syntax.ml @@ -0,0 +1,44 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: syntax.ml,v 1.9 2007-01-29 16:44:16 maranget Exp $ *) + +(* This apparently useless implmentation file is in fact required + by the pa_ocamllex syntax extension *) + +(* The shallow abstract syntax *) + +type location = + { start_pos: int; + end_pos: int; + start_line: int; + start_col: int } + +type regular_expression = + Epsilon + | Characters of Cset.t + | Eof + | Sequence of regular_expression * regular_expression + | Alternative of regular_expression * regular_expression + | Repetition of regular_expression + | Bind of regular_expression * (string * location) + +type ('arg,'action) entry = + {name:string ; + shortest : bool ; + args : 'arg ; + clauses : (regular_expression * 'action) list} + +type lexer_definition = + { header: location; + entrypoints: ((string list, location) entry) list; + trailer: location } diff --git a/lex/syntax.mli b/lex/syntax.mli new file mode 100644 index 0000000..e29c550 --- /dev/null +++ b/lex/syntax.mli @@ -0,0 +1,41 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: syntax.mli,v 1.9 2007-01-29 16:44:16 maranget Exp $ *) + +(* The shallow abstract syntax *) + +type location = + { start_pos: int; + end_pos: int; + start_line: int; + start_col: int } + +type regular_expression = + Epsilon + | Characters of Cset.t + | Eof + | Sequence of regular_expression * regular_expression + | Alternative of regular_expression * regular_expression + | Repetition of regular_expression + | Bind of regular_expression * (string * location) + +type ('arg,'action) entry = + {name:string ; + shortest : bool ; + args : 'arg ; + clauses : (regular_expression * 'action) list} + +type lexer_definition = + { header: location; + entrypoints: ((string list, location) entry) list; + trailer: location } diff --git a/lex/table.ml b/lex/table.ml new file mode 100644 index 0000000..402f52b --- /dev/null +++ b/lex/table.ml @@ -0,0 +1,56 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +type 'a t = {mutable next : int ; mutable data : 'a array} + +let default_size = 32 +;; + +let create x = {next = 0 ; data = Array.create default_size x} +and reset t = t.next <- 0 +;; + +let incr_table table new_size = + let t = Array.create new_size table.data.(0) in + Array.blit table.data 0 t 0 (Array.length table.data) ; + table.data <- t + +let emit table i = + let size = Array.length table.data in + if table.next >= size then + incr_table table (2*size); + table.data.(table.next) <- i ; + table.next <- table.next + 1 +;; + + +exception Error + +let get t i = + if 0 <= i && i < t.next then + t.data.(i) + else + raise Error + +let trim t = + let r = Array.sub t.data 0 t.next in + reset t ; + r + +let iter t f = + let size = t.next + and data = t.data in + for i = 0 to size-1 do + f data.(i) + done + +let size t = t.next diff --git a/lex/table.mli b/lex/table.mli new file mode 100644 index 0000000..e5d55f9 --- /dev/null +++ b/lex/table.mli @@ -0,0 +1,33 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Luc Maranget, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* Table used for code emission, ie extensible arrays *) +type 'a t + +val create : 'a -> 'a t + +val emit : 'a t -> 'a -> unit + +val iter : 'a t -> ('a -> unit) -> unit + +val trim : 'a t -> 'a array + + +exception Error + +val get : 'a t -> int -> 'a + + + +val size : 'a t -> int + + diff --git a/man/Makefile b/man/Makefile new file mode 100644 index 0000000..7a1572a --- /dev/null +++ b/man/Makefile @@ -0,0 +1,22 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.3 2002-04-24 09:09:35 xleroy Exp $ + +include ../config/Makefile + +DIR=$(MANDIR)/man$(MANEXT) + +install: + for i in *.m; do cp $$i $(DIR)/`basename $$i .m`.$(MANEXT); done + echo '.so man$(MANEXT)/ocamlc.$(MANEXT)' > $(DIR)/ocamlc.opt.$(MANEXT) + echo '.so man$(MANEXT)/ocamlopt.$(MANEXT)' > $(DIR)/ocamlopt.opt.$(MANEXT) diff --git a/man/ocaml.help b/man/ocaml.help new file mode 100644 index 0000000..466896d --- /dev/null +++ b/man/ocaml.help @@ -0,0 +1,138 @@ +- +OCaml # Objective Caml toplevel +Usage: ocaml +options are: + -I Add to the list of include directories + -unsafe No bound checking on array and string access + -drawlambda (undocumented) + -dlambda (undocumented) + -dinstr (undocumented) + -rectypes (undocumented) + +- +OCamlc # Objective Caml compiler +Usage: ocamlc +Options are: + -a Build a library + -c Compile only (do not link) + -cc Use as the C compiler and linker + -cclib Pass option to the C linker + -ccopt Pass option to the C compiler and linker + -g Save debugging information + -i Print the types + -I Add to the list of include directories + -impl Compile as a .ml file + -intf Compile as a .mli file + -intf-suffix Suffix for interface file (default: .mli) + -intf_suffix (deprecated) same as -intf-suffix + -linkall Link all modules, even unused ones + -make-runtime Build a runtime system with given C objects and libraries + -make_runtime (deprecated) same as -make-runtime + -noassert Do not compile assertion checks + -o Set output file name to + -output-obj Output a C object file instead of an executable + -pp Pipe sources through preprocessor + -thread Use thread-safe standard library + -unsafe No bounds checking on array and string access + -use-runtime Generate bytecode for the given runtime system + -use_runtime (deprecated) same as -use-runtime + -v Print compiler version number + -verbose Print calls to external commands + -w Enable or disable warnings according to : + A/a enable/disable all warnings + C/c enable/disable suspicious comment + F/f enable/disable partially applied function + M/m enable/disable overriden method + P/p enable/disable partial match + S/s enable/disable non-unit statement + U/u enable/disable unused match case + V/v enable/disable hidden instance variable + X/x enable/disable all other warnings + default setting is A (all warnings enabled) + -nopervasives (undocumented) + -dparsetree (undocumented) + -drawlambda (undocumented) + -dlambda (undocumented) + -dinstr (undocumented) + -use-prims (undocumented) + -rectypes (undocumented) + - Treat as a file name (even if it starts with `-') + +- +OCamlc-custom # Objective Caml compiler for custom runtime mode +Usage: ocamlc-custom +Options are: + -a Build a library + -c Compile only (do not link) + -cc Use as the C compiler and linker + -cclib Pass option to the C linker + -ccopt Pass option to the C compiler and linker + -g Save debugging information + -i Print the types + -I Add to the list of include directories + -impl Compile as a .ml file + -intf Compile as a .mli file + -intf-suffix Suffix for interface file (default: .mli) + -intf_suffix (deprecated) same as -intf-suffix + -linkall Link all modules, even unused ones + -make-runtime Build a runtime system with given C objects and libraries + -make_runtime (deprecated) same as -make-runtime + -noassert Do not compile assertion checks + -o Set output file name to + -output-obj Output a C object file instead of an executable + -pp Pipe sources through preprocessor + -thread Use thread-safe standard library + -unsafe No bounds checking on array and string access + -use-runtime Generate bytecode for the given runtime system + -use_runtime (deprecated) same as -use-runtime + -v Print compiler version number + -verbose Print calls to external commands + -w Enable or disable warnings according to : + A/a enable/disable all warnings + C/c enable/disable suspicious comment + F/f enable/disable partially applied function + M/m enable/disable overriden method + P/p enable/disable partial match + S/s enable/disable non-unit statement + U/u enable/disable unused match case + V/v enable/disable hidden instance variable + X/x enable/disable all other warnings + default setting is A (all warnings enabled) + -nopervasives (undocumented) + -dparsetree (undocumented) + -drawlambda (undocumented) + -dlambda (undocumented) + -dinstr (undocumented) + -use-prims (undocumented) + -rectypes (undocumented) + - Treat as a file name (even if it starts with `-') + +- +OCamlDep # Objective Caml dependency generator +Usage: ocamldep [-I ] + -I Add to the list of include directories + +- +OCamlLex # Objective Caml lexer generator +OCamlLex name.mll + +- +OCamlRun # Objective Caml bytecode interpreter +OCamlRun [-v] file [argumentsÉ] + -v # print GC messages + +Environment variable: +Set -e OCamlRunParam ""); + self#html_of_text_element b text; + bs b "" + + method html_of_Superscript b t = + bs b ""; + self#html_of_text b t; + bs b "" + + method html_of_Subscript b t = + bs b ""; + self#html_of_text b t; + bs b "" + + method virtual html_of_info_first_sentence : _ + + method html_of_Module_list b l = + bs b "
\n\n"; + List.iter + (fun name -> + bs b "" html m.m_name; + bs b "\n" + ) + l; + bs b "
"; + ( + try + let m = + List.find (fun m -> m.m_name = name) self#list_modules + in + let (html, _) = Naming.html_files m.m_name in + bp b "%s"; + self#html_of_info_first_sentence b m.m_info; + with + Not_found -> + Odoc_messages.pwarning (Odoc_messages.cross_module_not_found name); + bp b "%s" name + ); + bs b "
\n" + + method html_of_Index_list b = + let index_if_not_empty l url m = + match l with + [] -> () + | _ -> bp b "
%s
\n" url m + in + index_if_not_empty self#list_types self#index_types Odoc_messages.index_of_types; + index_if_not_empty self#list_exceptions self#index_exceptions Odoc_messages.index_of_exceptions; + index_if_not_empty self#list_values self#index_values Odoc_messages.index_of_values; + index_if_not_empty self#list_attributes self#index_attributes Odoc_messages.index_of_attributes; + index_if_not_empty self#list_methods self#index_methods Odoc_messages.index_of_methods; + index_if_not_empty self#list_classes self#index_classes Odoc_messages.index_of_classes; + index_if_not_empty self#list_class_types self#index_class_types Odoc_messages.index_of_class_types; + index_if_not_empty self#list_modules self#index_modules Odoc_messages.index_of_modules; + index_if_not_empty self#list_module_types self#index_module_types Odoc_messages.index_of_module_types + + method virtual list_types : Odoc_info.Type.t_type list + method virtual index_types : string + method virtual list_exceptions : Odoc_info.Exception.t_exception list + method virtual index_exceptions : string + method virtual list_values : Odoc_info.Value.t_value list + method virtual index_values : string + method virtual list_attributes : Odoc_info.Value.t_attribute list + method virtual index_attributes : string + method virtual list_methods : Odoc_info.Value.t_method list + method virtual index_methods : string + method virtual list_classes : Odoc_info.Class.t_class list + method virtual index_classes : string + method virtual list_class_types : Odoc_info.Class.t_class_type list + method virtual index_class_types : string + method virtual list_modules : Odoc_info.Module.t_module list + method virtual index_modules : string + method virtual list_module_types : Odoc_info.Module.t_module_type list + method virtual index_module_types : string + + end + +(** A class used to generate html code for info structures. *) +class virtual info = + object (self) + (** The list of pairs [(tag, f)] where [f] is a function taking + the [text] associated to [tag] and returning html code. + Add a pair here to handle a tag.*) + val mutable tag_functions = ([] : (string * (Odoc_info.text -> string)) list) + + (** The method used to get html code from a [text]. *) + method virtual html_of_text : Buffer.t -> Odoc_info.text -> unit + + (** Print html for an author list. *) + method html_of_author_list b l = + match l with + [] -> () + | _ -> + bp b "%s: %s
\n" + Odoc_messages.authors + (String.concat ", " l) + + (** Print html code for the given optional version information.*) + method html_of_version_opt b v_opt = + match v_opt with + None -> () + | Some v -> + bp b "%s: %s
\n" Odoc_messages.version v + + (** Print html code for the given optional since information.*) + method html_of_since_opt b s_opt = + match s_opt with + None -> () + | Some s -> + bp b "%s %s
\n" Odoc_messages.since s + + (** Print html code for the given list of raised exceptions.*) + method html_of_raised_exceptions b l = + match l with + [] -> () + | (s, t) :: [] -> + bp b "%s %s " + Odoc_messages.raises + s; + self#html_of_text b t; + bs b "
\n" + | _ -> + bp b "%s
    " Odoc_messages.raises; + List.iter + (fun (ex, desc) -> + bp b "
  • %s " ex ; + self#html_of_text b desc; + bs b "
  • \n" + ) + l; + bs b "
\n" + + (** Print html code for the given "see also" reference. *) + method html_of_see b (see_ref, t) = + let t_ref = + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + in + self#html_of_text b t_ref + + (** Print html code for the given list of "see also" references.*) + method html_of_sees b l = + match l with + [] -> () + | see :: [] -> + bp b "%s " Odoc_messages.see_also; + self#html_of_see b see; + bs b "
\n" + | _ -> + bp b "%s
    " Odoc_messages.see_also; + List.iter + (fun see -> + bs b "
  • " ; + self#html_of_see b see; + bs b "
  • \n" + ) + l; + bs b "
\n" + + (** Print html code for the given optional return information.*) + method html_of_return_opt b return_opt = + match return_opt with + None -> () + | Some s -> + bp b "%s " Odoc_messages.returns; + self#html_of_text b s; + bs b "
\n" + + (** Print html code for the given list of custom tagged texts. *) + method html_of_custom b l = + List.iter + (fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + Buffer.add_string b (f text) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) + ) + l + + (** Print html code for a description, except for the [i_params] field. + @param indent can be specified not to use the style of info comments; + default is [true]. + *) + method html_of_info ?(indent=true) b info_opt = + match info_opt with + None -> + () + | Some info -> + let module M = Odoc_info in + if indent then bs b "
\n"; + ( + match info.M.i_deprecated with + None -> () + | Some d -> + bs b ""; + bs b Odoc_messages.deprecated ; + bs b "" ; + self#html_of_text b d; + bs b "
\n" + ); + ( + match info.M.i_desc with + None -> () + | Some d when d = [Odoc_info.Raw ""] -> () + | Some d -> self#html_of_text b d; bs b "
\n" + ); + self#html_of_author_list b info.M.i_authors; + self#html_of_version_opt b info.M.i_version; + self#html_of_since_opt b info.M.i_since; + self#html_of_raised_exceptions b info.M.i_raised_exceptions; + self#html_of_return_opt b info.M.i_return_value; + self#html_of_sees b info.M.i_sees; + self#html_of_custom b info.M.i_custom; + if indent then bs b "
\n" + + (** Print html code for the first sentence of a description. + The titles and lists in this first sentence has been removed.*) + method html_of_info_first_sentence b info_opt = + match info_opt with + None -> () + | Some info -> + let module M = Odoc_info in + let dep = info.M.i_deprecated <> None in + bs b "
\n"; + if dep then bs b ""; + ( + match info.M.i_desc with + None -> () + | Some d when d = [Odoc_info.Raw ""] -> () + | Some d -> + self#html_of_text b + (Odoc_info.text_no_title_no_list + (Odoc_info.first_sentence_of_text d)); + bs b "\n" + ); + if dep then bs b ""; + bs b "
\n" + + end + + + +let opt = Odoc_info.apply_opt + +let print_concat b sep f = + let rec iter = function + [] -> () + | [c] -> f c + | c :: q -> + f c; + bs b sep; + iter q + in + iter + +let newline_to_indented_br s = + let len = String.length s in + let b = Buffer.create len in + for i = 0 to len - 1 do + match s.[i] with + '\n' -> Buffer.add_string b "
" + | c -> Buffer.add_char b c + done; + Buffer.contents b + +(** This class is used to create objects which can generate a simple html documentation. *) +class html = + object (self) + inherit text + inherit info + + val mutable doctype = + "\n" + val mutable character_encoding = + "\n" + + (** The default style options. *) + val mutable default_style_options = + ["a:visited {color : #416DFF; text-decoration : none; }" ; + "a:link {color : #416DFF; text-decoration : none;}" ; + "a:hover {color : Red; text-decoration : none; background-color: #5FFF88}" ; + "a:active {color : Red; text-decoration : underline; }" ; + ".keyword { font-weight : bold ; color : Red }" ; + ".keywordsign { color : #C04600 }" ; + ".superscript { font-size : 4 }" ; + ".subscript { font-size : 4 }" ; + ".comment { color : Green }" ; + ".constructor { color : Blue }" ; + ".type { color : #5C6585 }" ; + ".string { color : Maroon }" ; + ".warning { color : Red ; font-weight : bold }" ; + ".info { margin-left : 3em; margin-right : 3em }" ; + ".param_info { margin-top: 4px; margin-left : 3em; margin-right : 3em }" ; + ".code { color : #465F91 ; }" ; + "h1 { font-size : 20pt ; text-align: center; }" ; + + "h2 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #90BDFF ;"^ + "padding: 2px; }" ; + + "h3 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #90DDFF ;"^ + "padding: 2px; }" ; + + "h4 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #90EDFF ;"^ + "padding: 2px; }" ; + + "h5 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #90FDFF ;"^ + "padding: 2px; }" ; + + "h6 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #C0FFFF ; "^ + "padding: 2px; }" ; + + "div.h7 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #E0FFFF ; "^ + "padding: 2px; }" ; + + "div.h8 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #F0FFFF ; "^ + "padding: 2px; }" ; + + "div.h9 { font-size : 20pt ; border: 1px solid #000000; "^ + "margin-top: 5px; margin-bottom: 2px;"^ + "text-align: center; background-color: #FFFFFF ; "^ + "padding: 2px; }" ; + + ".typetable { border-style : hidden }" ; + ".indextable { border-style : hidden }" ; + ".paramstable { border-style : hidden ; padding: 5pt 5pt}" ; + "body { background-color : White }" ; + "tr { background-color : White }" ; + "td.typefieldcomment { background-color : #FFFFFF ; font-size: smaller ;}" ; + "pre { margin-bottom: 4px }" ; + + "div.sig_block {margin-left: 2em}" ; + ] + + (** The style file for all pages. *) + val mutable style_file = "style.css" + + (** The code to import the style. Initialized in [init_style]. *) + val mutable style = "" + + (** The known types names. + Used to know if we must create a link to a type + when printing a type. *) + val mutable known_types_names = StringSet.empty + + (** The known class and class type names. + Used to know if we must create a link to a class + or class type or not when printing a type. *) + val mutable known_classes_names = StringSet.empty + + (** The known modules and module types names. + Used to know if we must create a link to a type or not + when printing a module type. *) + val mutable known_modules_names = StringSet.empty + + method index_prefix = + if !Odoc_args.out_file = Odoc_messages.default_out_file then + "index" + else + Filename.basename !Odoc_args.out_file + + (** The main file. *) + method index = + let p = self#index_prefix in + Printf.sprintf "%s.html" p + + (** The file for the index of values. *) + method index_values = Printf.sprintf "%s_values.html" self#index_prefix + (** The file for the index of types. *) + method index_types = Printf.sprintf "%s_types.html" self#index_prefix + (** The file for the index of exceptions. *) + method index_exceptions = Printf.sprintf "%s_exceptions.html" self#index_prefix + (** The file for the index of attributes. *) + method index_attributes = Printf.sprintf "%s_attributes.html" self#index_prefix + (** The file for the index of methods. *) + method index_methods = Printf.sprintf "%s_methods.html" self#index_prefix + (** The file for the index of classes. *) + method index_classes = Printf.sprintf "%s_classes.html" self#index_prefix + (** The file for the index of class types. *) + method index_class_types = Printf.sprintf "%s_class_types.html" self#index_prefix + (** The file for the index of modules. *) + method index_modules = Printf.sprintf "%s_modules.html" self#index_prefix + (** The file for the index of module types. *) + method index_module_types = Printf.sprintf "%s_module_types.html" self#index_prefix + + + (** The list of attributes. Filled in the [generate] method. *) + val mutable list_attributes = [] + method list_attributes = list_attributes + (** The list of methods. Filled in the [generate] method. *) + val mutable list_methods = [] + method list_methods = list_methods + (** The list of values. Filled in the [generate] method. *) + val mutable list_values = [] + method list_values = list_values + (** The list of exceptions. Filled in the [generate] method. *) + val mutable list_exceptions = [] + method list_exceptions = list_exceptions + (** The list of types. Filled in the [generate] method. *) + val mutable list_types = [] + method list_types = list_types + (** The list of modules. Filled in the [generate] method. *) + val mutable list_modules = [] + method list_modules = list_modules + (** The list of module types. Filled in the [generate] method. *) + val mutable list_module_types = [] + method list_module_types = list_module_types + (** The list of classes. Filled in the [generate] method. *) + val mutable list_classes = [] + method list_classes = list_classes + (** The list of class types. Filled in the [generate] method. *) + val mutable list_class_types = [] + method list_class_types = list_class_types + + (** The header of pages. Must be prepared by the [prepare_header] method.*) + val mutable header = fun b -> fun ?(nav=None) -> fun ?(comments=[]) -> fun _ -> () + + (** Init the style. *) + method init_style = + (match !Args.css_style with + None -> + let default_style = String.concat "\n" default_style_options in + ( + try + let file = Filename.concat !Args.target_dir style_file in + if Sys.file_exists file then + Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) + else + ( + let chanout = open_out file in + output_string chanout default_style ; + flush chanout ; + close_out chanout; + Odoc_info.verbose (Odoc_messages.file_generated file) + ) + with + Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors ; + ) + | Some f -> + style_file <- f + ); + style <- "\n" + + (** Get the title given by the user *) + method title = match !Args.title with None -> "" | Some t -> self#escape t + + (** Get the title given by the user completed with the given subtitle. *) + method inner_title s = + (match self#title with "" -> "" | t -> t^" : ")^ + (self#escape s) + + (** Get the page header. *) + method print_header b ?nav ?comments title = header b ?nav ?comments title + + (** A function to build the header of pages. *) + method prepare_header module_list = + let f b ?(nav=None) ?(comments=[]) t = + let link_if_not_empty l m url = + match l with + [] -> () + | _ -> + bp b "\n" m url + in + bs b "\n"; + bs b style; + bs b character_encoding ; + bs b "\n" ; + ( + match nav with + None -> () + | Some (pre_opt, post_opt, name) -> + (match pre_opt with + None -> () + | Some name -> + bp b "\n" + (fst (Naming.html_files name)); + ); + (match post_opt with + None -> () + | Some name -> + bp b "\n" + (fst (Naming.html_files name)); + ); + ( + let father = Name.father name in + let href = if father = "" then self#index else fst (Naming.html_files father) in + bp b "\n" href + ) + ); + link_if_not_empty self#list_types Odoc_messages.index_of_types self#index_types; + link_if_not_empty self#list_exceptions Odoc_messages.index_of_exceptions self#index_exceptions; + link_if_not_empty self#list_values Odoc_messages.index_of_values self#index_values; + link_if_not_empty self#list_attributes Odoc_messages.index_of_attributes self#index_attributes; + link_if_not_empty self#list_methods Odoc_messages.index_of_methods self#index_methods; + link_if_not_empty self#list_classes Odoc_messages.index_of_classes self#index_classes; + link_if_not_empty self#list_class_types Odoc_messages.index_of_class_types self#index_class_types; + link_if_not_empty self#list_modules Odoc_messages.index_of_modules self#index_modules; + link_if_not_empty self#list_module_types Odoc_messages.index_of_module_types self#index_module_types; + let print_one m = + let html_file = fst (Naming.html_files m.m_name) in + bp b "" + m.m_name html_file + in + print_concat b "\n" print_one module_list; + self#html_sections_links b comments; + bs b ""; + bs b t ; + bs b "\n\n" + in + header <- f + + (** Build the html code for the link tags in the header, defining section and + subsections for the titles found in the given comments.*) + method html_sections_links b comments = + let titles = List.flatten (List.map Odoc_info.get_titles_in_text comments) in + let levels = + let rec iter acc l = + match l with + [] -> acc + | (n,_,_) :: q -> + if List.mem n acc + then iter acc q + else iter (n::acc) q + in + iter [] titles + in + let sorted_levels = List.sort compare levels in + let (section_level, subsection_level) = + match sorted_levels with + [] -> (None, None) + | [n] -> (Some n, None) + | n :: m :: _ -> (Some n, Some m) + in + let titles_per_level level_opt = + match level_opt with + None -> [] + | Some n -> List.filter (fun (m,_,_) -> m = n) titles + in + let section_titles = titles_per_level section_level in + let subsection_titles = titles_per_level subsection_level in + let print_lines s_rel titles = + List.iter + (fun (n,lopt,t) -> + let s = Odoc_info.string_of_text t in + let label = self#create_title_label (n,lopt,t) in + bp b "\n" s s_rel label + ) + titles + in + print_lines "Section" section_titles ; + print_lines "Subsection" subsection_titles + + + (** Html code for navigation bar. + @param pre optional name for optional previous module/class + @param post optional name for optional next module/class + @param name name of current module/class *) + method print_navbar b pre post name = + bs b "
"; + ( + match pre with + None -> () + | Some name -> + bp b "%s\n" + (fst (Naming.html_files name)) + Odoc_messages.previous + ); + bs b " "; + let father = Name.father name in + let href = if father = "" then self#index else fst (Naming.html_files father) in + bp b "%s\n" href Odoc_messages.up; + bs b " "; + ( + match post with + None -> () + | Some name -> + bp b "%s\n" + (fst (Naming.html_files name)) + Odoc_messages.next + ); + bs b "
\n" + + (** Return html code with the given string in the keyword style.*) + method keyword s = + ""^s^"" + + (** Return html code with the given string in the constructor style. *) + method constructor s = ""^s^"" + + (** Output the given ocaml code to the given file name. *) + method private output_code in_title file code = + try + let chanout = open_out file in + let b = new_buf () in + bs b ""; + self#print_header b (self#inner_title in_title); + bs b"\n"; + self#html_of_code b code; + bs b ""; + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s + + (** Take a string and return the string where fully qualified + type (or class or class type) idents + have been replaced by links to the type referenced by the ident.*) + method create_fully_qualified_idents_links m_name s = + let f str_t = + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + let s_final = Odoc_info.apply_if_equal + Odoc_info.use_hidden_modules + match_s + rel + in + if StringSet.mem match_s known_types_names then + ""^ + s_final^ + "" + else + if StringSet.mem match_s known_classes_names then + let (html_file, _) = Naming.html_files match_s in + ""^s_final^"" + else + s_final + in + let s2 = Str.global_substitute + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s + in + s2 + + (** Take a string and return the string where fully qualified module idents + have been replaced by links to the module referenced by the ident.*) + method create_fully_qualified_module_idents_links m_name s = + let f str_t = + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + let s_final = Odoc_info.apply_if_equal + Odoc_info.use_hidden_modules + match_s + rel + in + if StringSet.mem match_s known_modules_names then + let (html_file, _) = Naming.html_files match_s in + ""^s_final^"" + else + s_final + in + let s2 = Str.global_substitute + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([A-Z][a-zA-Z_'0-9]*\\)") + f + s + in + s2 + + (** Print html code to display a [Types.type_expr]. *) + method html_of_type_expr b m_name t = + let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_type_expr t) in + let s2 = newline_to_indented_br s in + bs b ""; + bs b (self#create_fully_qualified_idents_links m_name s2); + bs b "" + + (** Print html code to display a [Types.type_expr list]. *) + method html_of_type_expr_list ?par b m_name sep l = + print_DEBUG "html#html_of_type_expr_list"; + let s = Odoc_info.string_of_type_list ?par sep l in + print_DEBUG "html#html_of_type_expr_list: 1"; + let s2 = newline_to_indented_br s in + print_DEBUG "html#html_of_type_expr_list: 2"; + bs b ""; + bs b (self#create_fully_qualified_idents_links m_name s2); + bs b "" + + (** Print html code to display a [Types.type_expr list] as type parameters + of a class of class type. *) + method html_of_class_type_param_expr_list b m_name l = + let s = Odoc_info.string_of_class_type_param_list l in + let s2 = newline_to_indented_br s in + bs b "["; + bs b (self#create_fully_qualified_idents_links m_name s2); + bs b "]" + + method html_of_class_parameter_list b father c = + let s = Odoc_info.string_of_class_params c in + let s = Odoc_info.remove_ending_newline s in + let s2 = newline_to_indented_br s in + bs b ""; + bs b (self#create_fully_qualified_idents_links father s2); + bs b "" + + (** Print html code to display a list of type parameters for the given type.*) + method html_of_type_expr_param_list b m_name t = + let s = Odoc_info.string_of_type_param_list t in + let s2 = newline_to_indented_br s in + bs b ""; + bs b (self#create_fully_qualified_idents_links m_name s2); + bs b "" + + (** Print html code to display a [Types.module_type]. *) + method html_of_module_type b ?code m_name t = + let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_module_type ?code t) in + bs b ""; + bs b (self#create_fully_qualified_module_idents_links m_name s); + bs b "" + + (** Print html code to display the given module kind. *) + method html_of_module_kind b father ?modu kind = + match kind with + Module_struct eles -> + self#html_of_text b [Code "sig"]; + ( + match modu with + None -> + bs b "
"; + List.iter (self#html_of_module_element b father) eles; + bs b "
" + | Some m -> + let (html_file, _) = Naming.html_files m.m_name in + bp b " .. " html_file + ); + self#html_of_text b [Code "end"] + | Module_alias a -> + bs b ""; + bs b (self#create_fully_qualified_module_idents_links father a.ma_name); + bs b "" + | Module_functor (p, k) -> + if !Odoc_info.Args.html_short_functors then + bs b " " + else + bs b "
"; + self#html_of_module_parameter b father p; + ( + match k with + Module_functor _ -> () + | _ when !Odoc_info.Args.html_short_functors -> + bs b ": " + | _ -> () + ); + self#html_of_module_kind b father ?modu k; + if not !Odoc_info.Args.html_short_functors then + bs b "
" + | Module_apply (k1, k2) -> + (* TODO: l'application n'est pas correcte dans un .mli. + Que faire ? -> afficher le module_type du typedtree *) + self#html_of_module_kind b father k1; + self#html_of_text b [Code "("]; + self#html_of_module_kind b father k2; + self#html_of_text b [Code ")"] + | Module_with (k, s) -> + (* TODO: à modifier quand Module_with sera plus détaillé *) + self#html_of_module_type_kind b father ?modu k; + bs b " "; + bs b (self#create_fully_qualified_module_idents_links father s); + bs b "" + | Module_constraint (k, tk) -> + (* TODO: on affiche quoi ? *) + self#html_of_module_kind b father ?modu k + + method html_of_module_parameter b father p = + let (s_functor,s_arrow) = + if !Odoc_info.Args.html_short_functors then + "", "" + else + "functor ", "-> " + in + self#html_of_text b + [ + Code (s_functor^"("); + Code p.mp_name ; + Code " : "; + ] ; + self#html_of_module_type_kind b father p.mp_kind; + self#html_of_text b [ Code (") "^s_arrow)] + + method html_of_module_element b father ele = + match ele with + Element_module m -> + self#html_of_module b ~complete: false m + | Element_module_type mt -> + self#html_of_modtype b ~complete: false mt + | Element_included_module im -> + self#html_of_included_module b im + | Element_class c -> + self#html_of_class b ~complete: false c + | Element_class_type ct -> + self#html_of_class_type b ~complete: false ct + | Element_value v -> + self#html_of_value b v + | Element_exception e -> + self#html_of_exception b e + | Element_type t -> + self#html_of_type b t + | Element_module_comment text -> + self#html_of_module_comment b text + + (** Print html code to display the given module type kind. *) + method html_of_module_type_kind b father ?modu ?mt kind = + match kind with + Module_type_struct eles -> + self#html_of_text b [Code "sig"]; + ( + match mt with + None -> + ( + match modu with + None -> + bs b "
"; + List.iter (self#html_of_module_element b father) eles; + bs b "
" + | Some m -> + let (html_file, _) = Naming.html_files m.m_name in + bp b " .. " html_file + ) + | Some mt -> + let (html_file, _) = Naming.html_files mt.mt_name in + bp b " .. " html_file + ); + self#html_of_text b [Code "end"] + | Module_type_functor (p, k) -> + self#html_of_module_parameter b father p; + self#html_of_module_type_kind b father ?modu ?mt k + | Module_type_alias a -> + bs b ""; + bs b (self#create_fully_qualified_module_idents_links father a.mta_name); + bs b "" + | Module_type_with (k, s) -> + self#html_of_module_type_kind b father ?modu ?mt k; + bs b " "; + bs b (self#create_fully_qualified_module_idents_links father s); + bs b "" + + (** Print html code to display the type of a module parameter.. *) + method html_of_module_parameter_type b m_name p = + self#html_of_module_type b m_name ~code: p.mp_type_code p.mp_type + + (** Generate a file containing the module type in the given file name. *) + method output_module_type in_title file mtyp = + let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_module_type ~complete: true mtyp) in + self#output_code in_title file s + + (** Generate a file containing the class type in the given file name. *) + method output_class_type in_title file ctyp = + let s = Odoc_info.remove_ending_newline (Odoc_info.string_of_class_type ~complete: true ctyp) in + self#output_code in_title file s + + (** Print html code for a value. *) + method html_of_value b v = + Odoc_info.reset_type_names (); + bs b "
";
+      bs b (self#keyword "val");
+      bs b " ";
+      (* html mark *)
+      bp b "" (Naming.value_target v);
+      (
+       match v.val_code with
+         None -> bs b (self#escape (Name.simple v.val_name))
+       | Some c ->
+           let file = Naming.file_code_value_complete_target v in
+           self#output_code v.val_name (Filename.concat !Args.target_dir file) c;
+           bp b "%s" file (self#escape (Name.simple v.val_name))
+      );
+      bs b " : ";
+      self#html_of_type_expr b (Name.father v.val_name) v.val_type;
+      bs b "
"; + self#html_of_info b v.val_info; + ( + if !Args.with_parameter_list then + self#html_of_parameter_list b (Name.father v.val_name) v.val_parameters + else + self#html_of_described_parameter_list b (Name.father v.val_name) v.val_parameters + ) + + (** Print html code for an exception. *) + method html_of_exception b e = + Odoc_info.reset_type_names (); + bs b "
";
+      bs b (self#keyword "exception");
+      bs b " ";
+      (* html mark *)
+      bp b "%s"
+        (Naming.exception_target e)
+        (Name.simple e.ex_name);
+      (
+       match e.ex_args with
+         [] -> ()
+       | _ ->
+           bs b (" "^(self#keyword "of")^" ");
+           self#html_of_type_expr_list
+             ~par: false b (Name.father e.ex_name) " * " e.ex_args
+      );
+      (
+       match e.ex_alias with
+         None -> ()
+       | Some ea ->
+           bs b " = ";
+           (
+            match ea.ea_ex with
+              None -> bs b ea.ea_name
+            | Some e ->
+                bp b "%s" (Naming.complete_exception_target e) e.ex_name
+           )
+      );
+      bs b "
\n"; + self#html_of_info b e.ex_info + + (** Print html code for a type. *) + method html_of_type b t = + Odoc_info.reset_type_names (); + let father = Name.father t.ty_name in + bs b + (match t.ty_manifest, t.ty_kind with + None, Type_abstract -> "
"
+        | None, Type_variant _
+        | None, Type_record _ -> "
" + | Some _, Type_abstract -> "
"
+        | Some _, Type_variant _
+        | Some _, Type_record _ -> "
"
+        );
+      bs b ((self#keyword "type")^" ");
+      (* html mark *)
+      bp b "" (Naming.type_target t);
+      self#html_of_type_expr_param_list b father t;
+      (match t.ty_parameters with [] -> () | _ -> bs b " ");
+      bs b ((Name.simple t.ty_name)^" ");
+      let priv = t.ty_private = Asttypes.Private in
+      (
+       match t.ty_manifest with
+         None -> ()
+       | Some typ ->
+           bs b "= ";
+           if priv then bs b "private ";
+           self#html_of_type_expr b father typ;
+           bs b " "
+      );
+      (match t.ty_kind with
+        Type_abstract -> bs b "
" + | Type_variant l -> + bs b "= "; + if priv then bs b "private "; + bs b + ( + match t.ty_manifest with + None -> "
" + | Some _ -> "
" + ); + bs b "\n"; + let print_one constr = + bs b "\n\n\n"; + ( + match constr.vc_text with + None -> () + | Some t -> + bs b ""; + bs b ""; + bs b ""; + ); + bs b "\n" + in + print_concat b "\n" print_one l; + bs b "
\n"; + bs b ""; + bs b (self#keyword "|"); + bs b "\n"; + bs b ""; + bs b (self#constructor constr.vc_name); + ( + match constr.vc_args with + [] -> () + | l -> + bs b (" " ^ (self#keyword "of") ^ " "); + self#html_of_type_expr_list ~par: false b father " * " l; + ); + bs b ""; + bs b ""; + bs b "(*"; + bs b ""; + self#html_of_text b t; + bs b ""; + bs b ""; + bs b "*)"; + bs b "
\n" + + | Type_record l -> + bs b "= "; + if priv then bs b "private " ; + bs b "{"; + bs b + ( + match t.ty_manifest with + None -> "" + | Some _ -> "
" + ); + bs b "\n" ; + let print_one r = + bs b "\n\n\n"; + ( + match r.rf_text with + None -> () + | Some t -> + bs b ""; + bs b ""; + ); + bs b "\n" + in + print_concat b "\n" print_one l; + bs b "
\n"; + bs b "  "; + bs b "\n"; + bs b ""; + if r.rf_mutable then bs b (self#keyword "mutable ") ; + bs b (r.rf_name ^ " : ") ; + self#html_of_type_expr b father r.rf_type; + bs b ";"; + bs b ""; + bs b "(*"; + bs b ""; + self#html_of_text b t; + bs b ""; + bs b "*)
\n}\n" + ); + bs b "\n"; + self#html_of_info b t.ty_info; + bs b "\n" + + (** Print html code for a class attribute. *) + method html_of_attribute b a = + let module_name = Name.father (Name.father a.att_value.val_name) in + bs b "
" ;
+      bs b (self#keyword "val");
+      bs b " ";
+      (* html mark *)
+      bp b "" (Naming.attribute_target a);
+      (
+       if a.att_virtual then
+         bs b ((self#keyword "virtual")^ " ")
+       else
+         ()
+      );
+      (
+       if a.att_mutable then
+         bs b ((self#keyword Odoc_messages.mutab)^ " ")
+       else
+         ()
+      );(
+       match a.att_value.val_code with
+         None -> bs b (Name.simple a.att_value.val_name)
+       | Some c ->
+           let file = Naming.file_code_attribute_complete_target a in
+           self#output_code a.att_value.val_name (Filename.concat !Args.target_dir file) c;
+           bp b "%s" file (Name.simple a.att_value.val_name);
+      );
+      bs b " : ";
+      self#html_of_type_expr b module_name a.att_value.val_type;
+      bs b "
"; + self#html_of_info b a.att_value.val_info + + (** Print html code for a class method. *) + method html_of_method b m = + let module_name = Name.father (Name.father m.met_value.val_name) in + bs b "
";
+      bs b ((self#keyword "method")^" ");
+      (* html mark *)
+      bp b "" (Naming.method_target m);
+      if m.met_private then bs b ((self#keyword "private")^" ");
+      if m.met_virtual then bs b ((self#keyword "virtual")^" ");
+      (
+       match m.met_value.val_code with
+         None -> bs b  (Name.simple m.met_value.val_name)
+       | Some c ->
+           let file = Naming.file_code_method_complete_target m in
+           self#output_code m.met_value.val_name (Filename.concat !Args.target_dir file) c;
+           bp b "%s" file (Name.simple m.met_value.val_name);
+      );
+      bs b " : ";
+      self#html_of_type_expr b module_name m.met_value.val_type;
+      bs b "
"; + self#html_of_info b m.met_value.val_info; + ( + if !Args.with_parameter_list then + self#html_of_parameter_list b + module_name m.met_value.val_parameters + else + self#html_of_described_parameter_list b + module_name m.met_value.val_parameters + ) + + (** Print html code for the description of a function parameter. *) + method html_of_parameter_description b p = + match Parameter.names p with + [] -> + () + | name :: [] -> + ( + (* Only one name, no need for label for the description. *) + match Parameter.desc_by_name p name with + None -> () + | Some t -> self#html_of_text b t + ) + | l -> + (* A list of names, we display those with a description. *) + let l2 = List.filter + (fun n -> (Parameter.desc_by_name p n) <> None) + l + in + let print_one n = + match Parameter.desc_by_name p n with + None -> () + | Some t -> + bs b ""; + bs b n; + bs b " : "; + self#html_of_text b t + in + print_concat b "
\n" print_one l2 + + (** Print html code for a list of parameters. *) + method html_of_parameter_list b m_name l = + match l with + [] -> () + | _ -> + bs b "
"; + bs b "\n"; + bs b "\n\n" ; + bs b "\n\n
"; + bs b ""; + bs b Odoc_messages.parameters; + bs b ": \n\n"; + let print_one p = + bs b "\n\n\n"; + bs b "\n"; + in + List.iter print_one l; + bs b "
\n"; + bs b + ( + match Parameter.complete_name p with + "" -> "?" + | s -> s + ); + bs b ":"; + self#html_of_type_expr b m_name (Parameter.typ p); + bs b "
\n"; + self#html_of_parameter_description b p; + bs b "\n
\n
\n" + + (** Print html code for the parameters which have a name and description. *) + method html_of_described_parameter_list b m_name l = + (* get the params which have a name, and at least one name described. *) + let l2 = List.filter + (fun p -> + List.exists + (fun n -> (Parameter.desc_by_name p n) <> None) + (Parameter.names p)) + l + in + let f p = + bs b "
"; + bs b (Parameter.complete_name p); + bs b " : " ; + self#html_of_parameter_description b p; + bs b "
\n" + in + List.iter f l2 + + (** Print html code for a list of module parameters. *) + method html_of_module_parameter_list b m_name l = + match l with + [] -> + () + | _ -> + bs b "\n"; + bs b "\n"; + bs b "\n\n\n
"; + bs b Odoc_messages.parameters ; + bs b ": \n"; + bs b "\n"; + List.iter + (fun (p, desc_opt) -> + bs b "\n"; + bs b "\n" ; + bs b "\n"; + bs b "\n" ; + ) + ) + l; + bs b "
\n" ; + bs b p.mp_name; + bs b ":" ; + self#html_of_module_parameter_type b m_name p; + bs b "\n"; + ( + match desc_opt with + None -> () + | Some t -> + bs b "
"; + self#html_of_text b t; + bs b "\n
\n
\n" + + (** Print html code for a module. *) + method html_of_module b ?(info=true) ?(complete=true) ?(with_link=true) m = + let (html_file, _) = Naming.html_files m.m_name in + let father = Name.father m.m_name in + bs b "
";
+      bs b ((self#keyword "module")^" ");
+      (
+       if with_link then
+         bp b "%s" html_file (Name.simple m.m_name)
+       else
+         bs b (Name.simple m.m_name)
+      );
+      (
+       match m.m_kind with
+         Module_functor _ when !Odoc_info.Args.html_short_functors  ->
+           ()
+       | _ -> bs b ": "
+      );
+      self#html_of_module_kind b father ~modu: m m.m_kind;
+      bs b "
"; + if info then + ( + if complete then + self#html_of_info ~indent: false + else + self#html_of_info_first_sentence + ) b m.m_info + else + () + + (** Print html code for a module type. *) + method html_of_modtype b ?(info=true) ?(complete=true) ?(with_link=true) mt = + let (html_file, _) = Naming.html_files mt.mt_name in + let father = Name.father mt.mt_name in + bs b "
";
+      bs b ((self#keyword "module type")^" ");
+      (
+       if with_link then
+         bp b "%s" html_file (Name.simple mt.mt_name)
+         else
+         bs b (Name.simple mt.mt_name)
+      );
+      (match mt.mt_kind with
+        None -> ()
+      | Some k ->
+          bs b " = ";
+          self#html_of_module_type_kind b father ~mt k
+      );
+      bs b "
"; + if info then + ( + if complete then + self#html_of_info ~indent: false + else + self#html_of_info_first_sentence + ) b mt.mt_info + else + () + + (** Print html code for an included module. *) + method html_of_included_module b im = + bs b "
";
+      bs b ((self#keyword "include")^" ");
+      (
+       match im.im_module with
+         None ->
+           bs b im.im_name
+       | Some mmt ->
+           let (file, name) =
+             match mmt with
+               Mod m ->
+                 let (html_file, _) = Naming.html_files m.m_name in
+                 (html_file, m.m_name)
+             | Modtype mt ->
+                 let (html_file, _) = Naming.html_files mt.mt_name in
+                 (html_file, mt.mt_name)
+           in
+           bp b "%s" file name
+      );
+      bs b "
\n"; + self#html_of_info b im.im_info + + method html_of_class_element b element = + match element with + Class_attribute a -> + self#html_of_attribute b a + | Class_method m -> + self#html_of_method b m + | Class_comment t -> + self#html_of_class_comment b t + + method html_of_class_kind b father ?cl kind = + match kind with + Class_structure (inh, eles) -> + self#html_of_text b [Code "object"]; + ( + match cl with + None -> + bs b "\n"; + ( + match inh with + [] -> () + | _ -> + self#generate_inheritance_info b inh + ); + List.iter (self#html_of_class_element b) eles; + | Some cl -> + let (html_file, _) = Naming.html_files cl.cl_name in + bp b " .. " html_file + ); + self#html_of_text b [Code "end"] + + | Class_apply capp -> + (* TODO: afficher le type final à partir du typedtree *) + self#html_of_text b [Raw "class application not handled yet"] + + | Class_constr cco -> + ( + match cco.cco_type_parameters with + [] -> () + | l -> + self#html_of_class_type_param_expr_list b father l; + bs b " " + ); + bs b ""; + bs b (self#create_fully_qualified_idents_links father cco.cco_name); + bs b "" + + | Class_constraint (ck, ctk) -> + self#html_of_text b [Code "( "] ; + self#html_of_class_kind b father ck; + self#html_of_text b [Code " : "] ; + self#html_of_class_type_kind b father ctk; + self#html_of_text b [Code " )"] + + method html_of_class_type_kind b father ?ct kind = + match kind with + Class_type cta -> + ( + match cta.cta_type_parameters with + [] -> () + | l -> + self#html_of_class_type_param_expr_list b father l; + bs b " " + ); + bs b ""; + bs b (self#create_fully_qualified_idents_links father cta.cta_name); + bs b "" + + | Class_signature (inh, eles) -> + self#html_of_text b [Code "object"]; + ( + match ct with + None -> + bs b "\n"; + ( + match inh with + [] -> () + | _ -> self#generate_inheritance_info b inh + ); + List.iter (self#html_of_class_element b) eles + | Some ct -> + let (html_file, _) = Naming.html_files ct.clt_name in + bp b " .. " html_file + ); + self#html_of_text b [Code "end"] + + (** Print html code for a class. *) + method html_of_class b ?(complete=true) ?(with_link=true) c = + let father = Name.father c.cl_name in + Odoc_info.reset_type_names (); + let (html_file, _) = Naming.html_files c.cl_name in + bs b "
";
+      bs b ((self#keyword "class")^" ");
+      (* we add a html tag, the same as for a type so we can
+         go directly here when the class name is used as a type name *)
+      bp b ""
+        (Naming.type_target
+           { ty_name = c.cl_name ;
+             ty_info = None ; ty_parameters = [] ;
+             ty_kind = Type_abstract ; ty_private = Asttypes.Public; ty_manifest = None ;
+             ty_loc = Odoc_info.dummy_loc ;
+             ty_code = None ;
+           }
+        );
+      print_DEBUG "html#html_of_class : virtual or not" ;
+      if c.cl_virtual then bs b ((self#keyword "virtual")^" ");
+      (
+       match c.cl_type_parameters with
+         [] -> ()
+       | l ->
+           self#html_of_class_type_param_expr_list b father l;
+           bs b " "
+      );
+      print_DEBUG "html#html_of_class : with link or not" ;
+      (
+       if with_link then
+         bp b "%s" html_file (Name.simple c.cl_name)
+       else
+         bs b (Name.simple c.cl_name)
+      );
+
+      bs b " : " ;
+      self#html_of_class_parameter_list b father c ;
+      self#html_of_class_kind b father ~cl: c c.cl_kind;
+      bs b "
" ; + print_DEBUG "html#html_of_class : info" ; + ( + if complete then + self#html_of_info ~indent: false + else + self#html_of_info_first_sentence + ) b c.cl_info + + (** Print html code for a class type. *) + method html_of_class_type b ?(complete=true) ?(with_link=true) ct = + Odoc_info.reset_type_names (); + let father = Name.father ct.clt_name in + let (html_file, _) = Naming.html_files ct.clt_name in + bs b "
";
+      bs b ((self#keyword "class type")^" ");
+      (* we add a html tag, the same as for a type so we can
+         go directly here when the class type name is used as a type name *)
+      bp b ""
+        (Naming.type_target
+           { ty_name = ct.clt_name ;
+             ty_info = None ; ty_parameters = [] ;
+             ty_kind = Type_abstract ; ty_private = Asttypes.Public; ty_manifest = None ;
+             ty_loc = Odoc_info.dummy_loc ;
+             ty_code = None ;
+           }
+        );
+      if ct.clt_virtual then bs b ((self#keyword "virtual")^" ");
+      (
+       match ct.clt_type_parameters with
+        [] -> ()
+      | l ->
+          self#html_of_class_type_param_expr_list b father l;
+          bs b " "
+      );
+
+      if with_link then
+        bp b "%s" html_file (Name.simple ct.clt_name)
+      else
+        bs b (Name.simple ct.clt_name);
+
+      bs b " = ";
+      self#html_of_class_type_kind b father ~ct ct.clt_kind;
+      bs b "
"; + ( + if complete then + self#html_of_info ~indent: false + else + self#html_of_info_first_sentence + ) b ct.clt_info + + (** Return html code to represent a dag, represented as in Odoc_dag2html. *) + method html_of_dag dag = + let f n = + let (name, cct_opt) = n.Odoc_dag2html.valu in + (* if we have a c_opt = Some class then we take its information + because we are sure the name is complete. *) + let (name2, html_file) = + match cct_opt with + None -> (name, fst (Naming.html_files name)) + | Some (Cl c) -> (c.cl_name, fst (Naming.html_files c.cl_name)) + | Some (Cltype (ct, _)) -> (ct.clt_name, fst (Naming.html_files ct.clt_name)) + in + let new_v = + "\n\n
"^ + ""^name2^""^ + "
\n" + in + { n with Odoc_dag2html.valu = new_v } + in + let a = Array.map f dag.Odoc_dag2html.dag in + Odoc_dag2html.html_of_dag { Odoc_dag2html.dag = a } + + (** Print html code for a module comment.*) + method html_of_module_comment b text = + bs b "
\n"; + self#html_of_text b text; + bs b "
\n" + + (** Print html code for a class comment.*) + method html_of_class_comment b text = + (* Add some style if there is no style for the first part of the text. *) + let text2 = + match text with + | (Odoc_info.Raw s) :: q -> + (Odoc_info.Title (2, None, [Odoc_info.Raw s])) :: q + | _ -> text + in + self#html_of_text b text2 + + (** Generate html code for the given list of inherited classes.*) + method generate_inheritance_info b inher_l = + let f inh = + match inh.ic_class with + None -> (* we can't make the link. *) + (Odoc_info.Code inh.ic_name) :: + (match inh.ic_text with + None -> [] + | Some t -> (Odoc_info.Raw " ") :: t) + | Some cct -> + (* we can create the link. *) + let real_name = (* even if it should be the same *) + match cct with + Cl c -> c.cl_name + | Cltype (ct, _) -> ct.clt_name + in + let (class_file, _) = Naming.html_files real_name in + (Odoc_info.Link (class_file, [Odoc_info.Code real_name])) :: + (match inh.ic_text with + None -> [] + | Some t -> (Odoc_info.Raw " ") :: t) + in + let text = [ + Odoc_info.Bold [Odoc_info.Raw Odoc_messages.inherits] ; + Odoc_info.List (List.map f inher_l) + ] + in + self#html_of_text b text + + (** Generate html code for the inherited classes of the given class. *) + method generate_class_inheritance_info b cl = + let rec iter_kind k = + match k with + Class_structure ([], _) -> + () + | Class_structure (l, _) -> + self#generate_inheritance_info b l + | Class_constraint (k, ct) -> + iter_kind k + | Class_apply _ + | Class_constr _ -> + () + in + iter_kind cl.cl_kind + + (** Generate html code for the inherited classes of the given class type. *) + method generate_class_type_inheritance_info b clt = + match clt.clt_kind with + Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info b l + | Class_type _ -> + () + + (** A method to create index files. *) + method generate_elements_index : + 'a. + 'a list -> + ('a -> Odoc_info.Name.t) -> + ('a -> Odoc_info.info option) -> + ('a -> string) -> string -> string -> unit = + fun elements name info target title simple_file -> + try + let chanout = open_out (Filename.concat !Args.target_dir simple_file) in + let b = new_buf () in + bs b "\n"; + self#print_header b (self#inner_title title); + bs b "\n

"; + bs b title; + bs b "

\n" ; + + let sorted_elements = List.sort + (fun e1 e2 -> compare (Name.simple (name e1)) (Name.simple (name e2))) + elements + in + let groups = Odoc_info.create_index_lists sorted_elements (fun e -> Name.simple (name e)) in + let f_ele e = + let simple_name = Name.simple (name e) in + let father_name = Name.father (name e) in + bp b "%s " (target e) (self#escape simple_name); + if simple_name <> father_name && father_name <> "" then + bp b "[%s]" (fst (Naming.html_files father_name)) father_name; + bs b "\n"; + self#html_of_info_first_sentence b (info e); + bs b "\n"; + in + let f_group l = + match l with + [] -> () + | e :: _ -> + let s = + match (Char.uppercase (Name.simple (name e)).[0]) with + 'A'..'Z' as c -> String.make 1 c + | _ -> "" + in + bs b "
"; + bs b s ; + bs b "\n" ; + List.iter f_ele l + in + bs b "\n"; + List.iter f_group groups ; + bs b "

\n" ; + bs b "\n"; + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + raise (Failure s) + + (** A method to generate a list of module/class files. *) + method generate_elements : + 'a. ('a option -> 'a option -> 'a -> unit) -> 'a list -> unit = + fun f_generate l -> + let rec iter pre_opt = function + [] -> () + | ele :: [] -> f_generate pre_opt None ele + | ele1 :: ele2 :: q -> + f_generate pre_opt (Some ele2) ele1 ; + iter (Some ele1) (ele2 :: q) + in + iter None l + + (** Generate the code of the html page for the given class.*) + method generate_for_class pre post cl = + Odoc_info.reset_type_names (); + let (html_file, _) = Naming.html_files cl.cl_name in + let type_file = Naming.file_type_class_complete_target cl.cl_name in + try + let chanout = open_out (Filename.concat !Args.target_dir html_file) in + let b = new_buf () in + let pre_name = opt (fun c -> c.cl_name) pre in + let post_name = opt (fun c -> c.cl_name) post in + bs b doctype ; + bs b "\n"; + self#print_header b + ~nav: (Some (pre_name, post_name, cl.cl_name)) + ~comments: (Class.class_comments cl) + (self#inner_title cl.cl_name); + bs b "\n"; + self#print_navbar b pre_name post_name cl.cl_name; + bs b "

"; + bs b (Odoc_messages.clas^" "); + if cl.cl_virtual then bs b "virtual " ; + bp b "%s" type_file cl.cl_name; + bs b "

\n
\n"; + self#html_of_class b ~with_link: false cl; + (* parameters *) + self#html_of_described_parameter_list b + (Name.father cl.cl_name) cl.cl_parameters; + (* class inheritance *) + self#generate_class_inheritance_info b cl; + (* a horizontal line *) + bs b "
\n"; + (* the various elements *) + List.iter (self#html_of_class_element b) + (Class.class_elements ~trans:false cl); + bs b ""; + Buffer.output_buffer chanout b; + close_out chanout; + + (* generate the file with the complete class type *) + self#output_class_type + cl.cl_name + (Filename.concat !Args.target_dir type_file) + cl.cl_type + with + Sys_error s -> + raise (Failure s) + + (** Generate the code of the html page for the given class type.*) + method generate_for_class_type pre post clt = + Odoc_info.reset_type_names (); + let (html_file, _) = Naming.html_files clt.clt_name in + let type_file = Naming.file_type_class_complete_target clt.clt_name in + try + let chanout = open_out (Filename.concat !Args.target_dir html_file) in + let b = new_buf () in + let pre_name = opt (fun ct -> ct.clt_name) pre in + let post_name = opt (fun ct -> ct.clt_name) post in + bs b doctype ; + bs b "\n"; + self#print_header b + ~nav: (Some (pre_name, post_name, clt.clt_name)) + ~comments: (Class.class_type_comments clt) + (self#inner_title clt.clt_name); + + bs b "\n"; + self#print_navbar b pre_name post_name clt.clt_name; + bs b "

"; + bs b (Odoc_messages.class_type^" "); + if clt.clt_virtual then bs b "virtual "; + bp b "%s" type_file clt.clt_name; + bs b "

\n
\n"; + self#html_of_class_type b ~with_link: false clt; + + (* class inheritance *) + self#generate_class_type_inheritance_info b clt; + (* a horizontal line *) + bs b "
\n"; + (* the various elements *) + List.iter (self#html_of_class_element b) + (Class.class_type_elements ~trans: false clt); + bs b ""; + Buffer.output_buffer chanout b; + close_out chanout; + + (* generate the file with the complete class type *) + self#output_class_type + clt.clt_name + (Filename.concat !Args.target_dir type_file) + clt.clt_type + with + Sys_error s -> + raise (Failure s) + + (** Generate the html file for the given module type. + @raise Failure if an error occurs.*) + method generate_for_module_type pre post mt = + try + let (html_file, _) = Naming.html_files mt.mt_name in + let type_file = Naming.file_type_module_complete_target mt.mt_name in + let chanout = open_out (Filename.concat !Args.target_dir html_file) in + let b = new_buf () in + let pre_name = opt (fun mt -> mt.mt_name) pre in + let post_name = opt (fun mt -> mt.mt_name) post in + bs b doctype ; + bs b "\n"; + self#print_header b + ~nav: (Some (pre_name, post_name, mt.mt_name)) + ~comments: (Module.module_type_comments mt) + (self#inner_title mt.mt_name); + bs b "\n"; + self#print_navbar b pre_name post_name mt.mt_name; + bp b "

"; + bs b (Odoc_messages.module_type^" "); + ( + match mt.mt_type with + Some _ -> bp b "%s" type_file mt.mt_name + | None-> bs b mt.mt_name + ); + bs b "

\n
\n" ; + self#html_of_modtype b ~with_link: false mt; + + (* parameters for functors *) + self#html_of_module_parameter_list b + (Name.father mt.mt_name) + (Module.module_type_parameters mt); + (* a horizontal line *) + bs b "
\n"; + (* module elements *) + List.iter + (self#html_of_module_element b (Name.father mt.mt_name)) + (Module.module_type_elements mt); + + bs b ""; + Buffer.output_buffer chanout b; + close_out chanout; + + (* generate html files for submodules *) + self#generate_elements self#generate_for_module (Module.module_type_modules mt); + (* generate html files for module types *) + self#generate_elements self#generate_for_module_type (Module.module_type_module_types mt); + (* generate html files for classes *) + self#generate_elements self#generate_for_class (Module.module_type_classes mt); + (* generate html files for class types *) + self#generate_elements self#generate_for_class_type (Module.module_type_class_types mt); + + (* generate the file with the complete module type *) + ( + match mt.mt_type with + None -> () + | Some mty -> + self#output_module_type + mt.mt_name + (Filename.concat !Args.target_dir type_file) + mty + ) + with + Sys_error s -> + raise (Failure s) + + (** Generate the html file for the given module. + @raise Failure if an error occurs.*) + method generate_for_module pre post modu = + try + Odoc_info.verbose ("Generate for module "^modu.m_name); + let (html_file, _) = Naming.html_files modu.m_name in + let type_file = Naming.file_type_module_complete_target modu.m_name in + let code_file = Naming.file_code_module_complete_target modu.m_name in + let chanout = open_out (Filename.concat !Args.target_dir html_file) in + let b = new_buf () in + let pre_name = opt (fun m -> m.m_name) pre in + let post_name = opt (fun m -> m.m_name) post in + bs b doctype ; + bs b "\n"; + self#print_header b + ~nav: (Some (pre_name, post_name, modu.m_name)) + ~comments: (Module.module_comments modu) + (self#inner_title modu.m_name); + bs b "\n" ; + self#print_navbar b pre_name post_name modu.m_name ; + bs b "

"; + if modu.m_text_only then + bs b modu.m_name + else + ( + bs b + ( + if Module.module_is_functor modu then + Odoc_messages.functo + else + Odoc_messages.modul + ); + bp b " %s" type_file modu.m_name; + ( + match modu.m_code with + None -> () + | Some _ -> bp b " (.ml)" code_file + ) + ); + bs b "

\n
\n"; + + if not modu.m_text_only then self#html_of_module b ~with_link: false modu; + + (* parameters for functors *) + self#html_of_module_parameter_list b + (Name.father modu.m_name) + (Module.module_parameters modu); + + (* a horizontal line *) + if not modu.m_text_only then bs b "
\n"; + + (* module elements *) + List.iter + (self#html_of_module_element b (Name.father modu.m_name)) + (Module.module_elements modu); + + bs b ""; + Buffer.output_buffer chanout b; + close_out chanout; + + (* generate html files for submodules *) + self#generate_elements self#generate_for_module (Module.module_modules modu); + (* generate html files for module types *) + self#generate_elements self#generate_for_module_type (Module.module_module_types modu); + (* generate html files for classes *) + self#generate_elements self#generate_for_class (Module.module_classes modu); + (* generate html files for class types *) + self#generate_elements self#generate_for_class_type (Module.module_class_types modu); + + (* generate the file with the complete module type *) + self#output_module_type + modu.m_name + (Filename.concat !Args.target_dir type_file) + modu.m_type; + + match modu.m_code with + None -> () + | Some code -> + self#output_code + modu.m_name + (Filename.concat !Args.target_dir code_file) + code + with + Sys_error s -> + raise (Failure s) + + (** Generate the [.html] file corresponding to the given module list. + @raise Failure if an error occurs.*) + method generate_index module_list = + try + let chanout = open_out (Filename.concat !Args.target_dir self#index) in + let b = new_buf () in + let title = match !Args.title with None -> "" | Some t -> self#escape t in + bs b doctype ; + bs b "\n"; + self#print_header b self#title; + bs b "\n"; + bs b "

"; + bs b title; + bs b "

\n" ; + let info = Odoc_info.apply_opt + (Odoc_info.info_of_comment_file module_list) + !Odoc_info.Args.intro_file + in + ( + match info with + None -> + self#html_of_Index_list b; + bs b "
"; + self#html_of_Module_list b + (List.map (fun m -> m.m_name) module_list); + bs b "\n" + | Some i -> self#html_of_info ~indent: false b info + ); + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + raise (Failure s) + + (** Generate the values index in the file [index_values.html]. *) + method generate_values_index module_list = + self#generate_elements_index + self#list_values + (fun v -> v.val_name) + (fun v -> v.val_info) + Naming.complete_value_target + Odoc_messages.index_of_values + self#index_values + + (** Generate the exceptions index in the file [index_exceptions.html]. *) + method generate_exceptions_index module_list = + self#generate_elements_index + self#list_exceptions + (fun e -> e.ex_name) + (fun e -> e.ex_info) + Naming.complete_exception_target + Odoc_messages.index_of_exceptions + self#index_exceptions + + (** Generate the types index in the file [index_types.html]. *) + method generate_types_index module_list = + self#generate_elements_index + self#list_types + (fun t -> t.ty_name) + (fun t -> t.ty_info) + Naming.complete_type_target + Odoc_messages.index_of_types + self#index_types + + (** Generate the attributes index in the file [index_attributes.html]. *) + method generate_attributes_index module_list = + self#generate_elements_index + self#list_attributes + (fun a -> a.att_value.val_name) + (fun a -> a.att_value.val_info) + Naming.complete_attribute_target + Odoc_messages.index_of_attributes + self#index_attributes + + (** Generate the methods index in the file [index_methods.html]. *) + method generate_methods_index module_list = + self#generate_elements_index + self#list_methods + (fun m -> m.met_value.val_name) + (fun m -> m.met_value.val_info) + Naming.complete_method_target + Odoc_messages.index_of_methods + self#index_methods + + (** Generate the classes index in the file [index_classes.html]. *) + method generate_classes_index module_list = + self#generate_elements_index + self#list_classes + (fun c -> c.cl_name) + (fun c -> c.cl_info) + (fun c -> fst (Naming.html_files c.cl_name)) + Odoc_messages.index_of_classes + self#index_classes + + (** Generate the class types index in the file [index_class_types.html]. *) + method generate_class_types_index module_list = + self#generate_elements_index + self#list_class_types + (fun ct -> ct.clt_name) + (fun ct -> ct.clt_info) + (fun ct -> fst (Naming.html_files ct.clt_name)) + Odoc_messages.index_of_class_types + self#index_class_types + + (** Generate the modules index in the file [index_modules.html]. *) + method generate_modules_index module_list = + self#generate_elements_index + self#list_modules + (fun m -> m.m_name) + (fun m -> m.m_info) + (fun m -> fst (Naming.html_files m.m_name)) + Odoc_messages.index_of_modules + self#index_modules + + (** Generate the module types index in the file [index_module_types.html]. *) + method generate_module_types_index module_list = + self#generate_elements_index + self#list_module_types + (fun mt -> mt.mt_name) + (fun mt -> mt.mt_info) + (fun mt -> fst (Naming.html_files mt.mt_name)) + Odoc_messages.index_of_module_types + self#index_module_types + + (** Generate all the html files from a module list. The main + file is [.html]. *) + method generate module_list = + (* init the style *) + self#init_style ; + (* init the lists of elements *) + list_values <- Odoc_info.Search.values module_list ; + list_exceptions <- Odoc_info.Search.exceptions module_list ; + list_types <- Odoc_info.Search.types module_list ; + list_attributes <- Odoc_info.Search.attributes module_list ; + list_methods <- Odoc_info.Search.methods module_list ; + list_classes <- Odoc_info.Search.classes module_list ; + list_class_types <- Odoc_info.Search.class_types module_list ; + list_modules <- Odoc_info.Search.modules module_list ; + list_module_types <- Odoc_info.Search.module_types module_list ; + + (* prepare the page header *) + self#prepare_header module_list ; + (* Get the names of all known types. *) + let types = Odoc_info.Search.types module_list in + known_types_names <- + List.fold_left + (fun acc t -> StringSet.add t.ty_name acc) + known_types_names + types ; + (* Get the names of all class and class types. *) + let classes = Odoc_info.Search.classes module_list in + let class_types = Odoc_info.Search.class_types module_list in + known_classes_names <- + List.fold_left + (fun acc c -> StringSet.add c.cl_name acc) + known_classes_names + classes ; + known_classes_names <- + List.fold_left + (fun acc ct -> StringSet.add ct.clt_name acc) + known_classes_names + class_types ; + (* Get the names of all known modules and module types. *) + let module_types = Odoc_info.Search.module_types module_list in + let modules = Odoc_info.Search.modules module_list in + known_modules_names <- + List.fold_left + (fun acc m -> StringSet.add m.m_name acc) + known_modules_names + modules ; + known_modules_names <- + List.fold_left + (fun acc mt -> StringSet.add mt.mt_name acc) + known_modules_names + module_types ; + (* generate html for each module *) + if not !Args.index_only then + self#generate_elements self#generate_for_module module_list ; + + try + self#generate_index module_list; + self#generate_values_index module_list ; + self#generate_exceptions_index module_list ; + self#generate_types_index module_list ; + self#generate_attributes_index module_list ; + self#generate_methods_index module_list ; + self#generate_classes_index module_list ; + self#generate_class_types_index module_list ; + self#generate_modules_index module_list ; + self#generate_module_types_index module_list ; + with + Failure s -> + prerr_endline s ; + incr Odoc_info.errors + + initializer + Odoc_ocamlhtml.html_of_comment := + (fun s -> + let b = new_buf () in + self#html_of_text b (Odoc_text.Texter.text_of_string s); + Buffer.contents b + ) + end diff --git a/ocamldoc/odoc_info.ml b/ocamldoc/odoc_info.ml new file mode 100644 index 0000000..221473b --- /dev/null +++ b/ocamldoc/odoc_info.ml @@ -0,0 +1,321 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_info.ml,v 1.24 2007-10-08 14:19:34 doligez Exp $ *) + +(** Interface for analysing documented OCaml source files and to the collected information. *) + +type ref_kind = Odoc_types.ref_kind = + RK_module + | RK_module_type + | RK_class + | RK_class_type + | RK_value + | RK_type + | RK_exception + | RK_attribute + | RK_method + | RK_section of text + +and text_element = Odoc_types.text_element = + | Raw of string + | Code of string + | CodePre of string + | Verbatim of string + | Bold of text + | Italic of text + | Emphasize of text + | Center of text + | Left of text + | Right of text + | List of text list + | Enum of text list + | Newline + | Block of text + | Title of int * string option * text + | Latex of string + | Link of string * text + | Ref of string * ref_kind option + | Superscript of text + | Subscript of text + | Module_list of string list + | Index_list + | Custom of string * text + +and text = text_element list + +exception Text_syntax = Odoc_text.Text_syntax + +type see_ref = Odoc_types.see_ref = + See_url of string + | See_file of string + | See_doc of string + +type see = see_ref * text + +type param = (string * text) + +type raised_exception = (string * text) + +type info = Odoc_types.info = { + i_desc : text option; + i_authors : string list; + i_version : string option; + i_sees : see list; + i_since : string option; + i_deprecated : text option; + i_params : param list; + i_raised_exceptions : raised_exception list; + i_return_value : text option ; + i_custom : (string * text) list ; + } + +type location = Odoc_types.location = { + loc_impl : (string * int) option ; + loc_inter : (string * int) option ; + } + +let dummy_loc = { loc_impl = None ; loc_inter = None } + +module Name = Odoc_name +module Parameter = Odoc_parameter +module Exception = Odoc_exception +module Type = Odoc_type +module Value = Odoc_value +module Class = Odoc_class +module Module = Odoc_module + + +let analyse_files + ?(merge_options=([] : Odoc_types.merge_option list)) + ?(include_dirs=([] : string list)) + ?(labels=false) + ?(sort_modules=false) + ?(no_stop=false) + ?(init=[]) + files = + Odoc_args.merge_options := merge_options; + Odoc_args.include_dirs := include_dirs; + Odoc_args.classic := not labels; + Odoc_args.sort_modules := sort_modules; + Odoc_args.no_stop := no_stop; + Odoc_analyse.analyse_files ~init: init files + +let dump_modules = Odoc_analyse.dump_modules + +let load_modules = Odoc_analyse.load_modules + +let reset_type_names = Printtyp.reset + +let string_of_variance t (co,cn) = Odoc_str.string_of_variance t (co, cn) + +let string_of_type_expr t = Odoc_print.string_of_type_expr t + +let string_of_class_params = Odoc_str.string_of_class_params + +let string_of_type_list ?par sep type_list = Odoc_str.string_of_type_list ?par sep type_list + +let string_of_type_param_list t = Odoc_str.string_of_type_param_list t + +let string_of_class_type_param_list l = Odoc_str.string_of_class_type_param_list l + +let string_of_module_type = Odoc_print.string_of_module_type + +let string_of_class_type = Odoc_print.string_of_class_type + +let string_of_text t = Odoc_misc.string_of_text t + +let string_of_info i = Odoc_misc.string_of_info i + +let string_of_type t = Odoc_str.string_of_type t + +let string_of_exception e = Odoc_str.string_of_exception e + +let string_of_value v = Odoc_str.string_of_value v + +let string_of_attribute att = Odoc_str.string_of_attribute att + +let string_of_method m = Odoc_str.string_of_method m + +let first_sentence_of_text = Odoc_misc.first_sentence_of_text + +let first_sentence_and_rest_of_text = Odoc_misc.first_sentence_and_rest_of_text + +let text_no_title_no_list = Odoc_misc.text_no_title_no_list + +let text_concat = Odoc_misc.text_concat + +let get_titles_in_text = Odoc_misc.get_titles_in_text + +let create_index_lists = Odoc_misc.create_index_lists + +let remove_ending_newline = Odoc_misc.remove_ending_newline + +let remove_option = Odoc_misc.remove_option + +let is_optional = Odoc_misc.is_optional + +let label_name = Odoc_misc.label_name + +let use_hidden_modules n = + Odoc_name.hide_given_modules !Odoc_args.hidden_modules n + +let verbose s = + if !Odoc_args.verbose then + (print_string s ; print_newline ()) + else + () + +let warning s = Odoc_messages.pwarning s +let print_warnings = Odoc_config.print_warnings + +let errors = Odoc_global.errors + +let apply_opt = Odoc_misc.apply_opt + +let apply_if_equal f v1 v2 = + if v1 = v2 then + f v1 + else + v2 + +let text_of_string = Odoc_text.Texter.text_of_string + +let text_string_of_text = Odoc_text.Texter.string_of_text + + +let escape_arobas s = + let len = String.length s in + let b = Buffer.create len in + for i = 0 to len - 1 do + match s.[i] with + '@' -> Buffer.add_string b "\\@" + | c -> Buffer.add_char b c + done; + Buffer.contents b + +let info_string_of_info i = + let b = Buffer.create 256 in + let p = Printf.bprintf in + ( + match i.i_desc with + None -> () + | Some t -> p b "%s" (escape_arobas (text_string_of_text t)) + ); + List.iter + (fun s -> p b "\n@author %s" (escape_arobas s)) + i.i_authors; + ( + match i.i_version with + None -> () + | Some s -> p b "\n@version %s" (escape_arobas s) + ); + ( + (* TODO: escape characters ? *) + let f_see_ref = function + See_url s -> Printf.sprintf "<%s>" s + | See_file s -> Printf.sprintf "'%s'" s + | See_doc s -> Printf.sprintf "\"%s\"" s + in + List.iter + (fun (sref, t) -> + p b "\n@see %s %s" + (escape_arobas (f_see_ref sref)) + (escape_arobas (text_string_of_text t)) + ) + i.i_sees + ); + ( + match i.i_since with + None -> () + | Some s -> p b "\n@since %s" (escape_arobas s) + ); + ( + match i.i_deprecated with + None -> () + | Some t -> + p b "\n@deprecated %s" + (escape_arobas (text_string_of_text t)) + ); + List.iter + (fun (s, t) -> + p b "\n@param %s %s" + (escape_arobas s) + (escape_arobas (text_string_of_text t)) + ) + i.i_params; + List.iter + (fun (s, t) -> + p b "\n@raise %s %s" + (escape_arobas s) + (escape_arobas (text_string_of_text t)) + ) + i.i_raised_exceptions; + ( + match i.i_return_value with + None -> () + | Some t -> + p b "\n@return %s" + (escape_arobas (text_string_of_text t)) + ); + List.iter + (fun (s, t) -> + p b "\n@%s %s" s + (escape_arobas (text_string_of_text t)) + ) + i.i_custom; + + Buffer.contents b + +let info_of_string = Odoc_comments.info_of_string +let info_of_comment_file = Odoc_comments.info_of_comment_file + +module Search = + struct + type result_element = Odoc_search.result_element = + Res_module of Module.t_module + | Res_module_type of Module.t_module_type + | Res_class of Class.t_class + | Res_class_type of Class.t_class_type + | Res_value of Value.t_value + | Res_type of Type.t_type + | Res_exception of Exception.t_exception + | Res_attribute of Value.t_attribute + | Res_method of Value.t_method + | Res_section of string * text + + type search_result = result_element list + + let search_by_name = Odoc_search.Search_by_name.search + + let values = Odoc_search.values + let exceptions = Odoc_search.exceptions + let types = Odoc_search.types + let attributes = Odoc_search.attributes + let methods = Odoc_search.methods + let classes = Odoc_search.classes + let class_types = Odoc_search.class_types + let modules = Odoc_search.modules + let module_types = Odoc_search.module_types + end + +module Scan = + struct + class scanner = Odoc_scan.scanner + end + +module Dep = + struct + let kernel_deps_of_modules = Odoc_dep.kernel_deps_of_modules + let deps_of_types = Odoc_dep.deps_of_types + end + +module Args = Odoc_args diff --git a/ocamldoc/odoc_info.mli b/ocamldoc/odoc_info.mli new file mode 100644 index 0000000..0b40238 --- /dev/null +++ b/ocamldoc/odoc_info.mli @@ -0,0 +1,1087 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_info.mli,v 1.45 2008-07-25 13:28:23 guesdon Exp $ *) + +(** Interface to the information collected in source files. *) + +(** The differents kinds of element references. *) +type ref_kind = Odoc_types.ref_kind = + RK_module + | RK_module_type + | RK_class + | RK_class_type + | RK_value + | RK_type + | RK_exception + | RK_attribute + | RK_method + | RK_section of text + +and text_element = Odoc_types.text_element = + | Raw of string (** Raw text. *) + | Code of string (** The string is source code. *) + | CodePre of string (** The string is pre-formatted source code. *) + | Verbatim of string (** String 'as is'. *) + | Bold of text (** Text in bold style. *) + | Italic of text (** Text in italic. *) + | Emphasize of text (** Emphasized text. *) + | Center of text (** Centered text. *) + | Left of text (** Left alignment. *) + | Right of text (** Right alignment. *) + | List of text list (** A list. *) + | Enum of text list (** An enumerated list. *) + | Newline (** To force a line break. *) + | Block of text (** Like html's block quote. *) + | Title of int * string option * text + (** Style number, optional label, and text. *) + | Latex of string (** A string for latex. *) + | Link of string * text (** A reference string and the link text. *) + | Ref of string * ref_kind option + (** A reference to an element. Complete name and kind. *) + | Superscript of text (** Superscripts. *) + | Subscript of text (** Subscripts. *) + | Module_list of string list + (** The table of the given modules with their abstract. *) + | Index_list (** The links to the various indexes (values, types, ...) *) + | Custom of string * text (** to extend \{foo syntax *) + +(** A text is a list of [text_element]. The order matters. *) +and text = text_element list + +(** The different forms of references in \@see tags. *) +type see_ref = Odoc_types.see_ref = + See_url of string + | See_file of string + | See_doc of string + +(** Raised when parsing string to build a {!Odoc_info.text} + structure. [(line, char, string)] *) +exception Text_syntax of int * int * string + +(** The information in a \@see tag. *) +type see = see_ref * text + +(** Parameter name and description. *) +type param = (string * text) + +(** Raised exception name and description. *) +type raised_exception = (string * text) + +(** Information in a special comment *) +type info = Odoc_types.info = { + i_desc : text option; (** The description text. *) + i_authors : string list; (** The list of authors in \@author tags. *) + i_version : string option; (** The string in the \@version tag. *) + i_sees : see list; (** The list of \@see tags. *) + i_since : string option; (** The string in the \@since tag. *) + i_deprecated : text option; (** The of the \@deprecated tag. *) + i_params : param list; (** The list of parameter descriptions. *) + i_raised_exceptions : raised_exception list; (** The list of raised exceptions. *) + i_return_value : text option; (** The description text of the return value. *) + i_custom : (string * text) list ; (** A text associated to a custom @-tag. *) + } + +(** Location of elements in implementation and interface files. *) +type location = Odoc_types.location = { + loc_impl : (string * int) option ; (** implementation file name and position *) + loc_inter : (string * int) option ; (** interface file name and position *) + } + +(** A dummy location. *) +val dummy_loc : location + +(** Representation of element names. *) +module Name : + sig + type t = string + + (** Access to the simple name. *) + val simple : t -> t + + (** [concat t1 t2] returns the concatenation of [t1] and [t2].*) + val concat : t -> t -> t + + (** Return the depth of the name, i.e. the numer of levels to the root. + Example : [depth "Toto.Tutu.name"] = [3]. *) + val depth : t -> int + + (** Take two names n1 and n2 = n3.n4 and return n4 if n3=n1 or else n2. *) + val get_relative : t -> t -> t + + (** Return the name of the 'father' (like [dirname] for a file name).*) + val father : t -> t + end + +(** Representation and manipulation of method / function / class / module parameters.*) +module Parameter : + sig + (** {3 Types} *) + (** Representation of a simple parameter name *) + type simple_name = Odoc_parameter.simple_name = + { + sn_name : string ; + sn_type : Types.type_expr ; + mutable sn_text : text option ; + } + + (** Representation of parameter names. We need it to represent parameter names in tuples. + The value [Tuple ([], t)] stands for an anonymous parameter.*) + type param_info = Odoc_parameter.param_info = + Simple_name of simple_name + | Tuple of param_info list * Types.type_expr + + (** A parameter is just a param_info.*) + type parameter = param_info + + (** {3 Functions} *) + (** Acces to the name as a string. For tuples, parenthesis and commas are added. *) + val complete_name : parameter -> string + + (** Access to the complete type. *) + val typ : parameter -> Types.type_expr + + (** Access to the list of names ; only one for a simple parameter, or + a list for a tuple. *) + val names : parameter -> string list + + (** Access to the description of a specific name. + @raise Not_found if no description is associated to the given name. *) + val desc_by_name : parameter -> string -> text option + + (** Access to the type of a specific name. + @raise Not_found if no type is associated to the given name. *) + val type_by_name : parameter -> string -> Types.type_expr + end + +(** Representation and manipulation of exceptions. *) +module Exception : + sig + (** Used when the exception is a rebind of another exception, + when we have [exception Ex = Target_ex].*) + type exception_alias = Odoc_exception.exception_alias = + { + ea_name : Name.t ; (** The complete name of the target exception. *) + mutable ea_ex : t_exception option ; (** The target exception, if we found it.*) + } + + and t_exception = Odoc_exception.t_exception = + { + ex_name : Name.t ; + mutable ex_info : info option ; (** Information found in the optional associated comment. *) + ex_args : Types.type_expr list ; (** The types of the parameters. *) + ex_alias : exception_alias option ; (** [None] when the exception is not a rebind. *) + mutable ex_loc : location ; + mutable ex_code : string option ; + } + end + +(** Representation and manipulation of types.*) +module Type : + sig + type private_flag = Odoc_type.private_flag = + Private | Public + + (** Description of a variant type constructor. *) + type variant_constructor = Odoc_type.variant_constructor = + { + vc_name : string ; (** Name of the constructor. *) + vc_args : Types.type_expr list ; (** Arguments of the constructor. *) + mutable vc_text : text option ; (** Optional description in the associated comment. *) + } + + (** Description of a record type field. *) + type record_field = Odoc_type.record_field = + { + rf_name : string ; (** Name of the field. *) + rf_mutable : bool ; (** [true] if mutable. *) + rf_type : Types.type_expr ; (** Type of the field. *) + mutable rf_text : text option ; (** Optional description in the associated comment.*) + } + + (** The various kinds of a type. *) + type type_kind = Odoc_type.type_kind = + Type_abstract (** Type is abstract, for example [type t]. *) + | Type_variant of variant_constructor list + (** constructors *) + | Type_record of record_field list + (** fields *) + + (** Representation of a type. *) + type t_type = Odoc_type.t_type = + { + ty_name : Name.t ; (** Complete name of the type. *) + mutable ty_info : info option ; (** Information found in the optional associated comment. *) + ty_parameters : (Types.type_expr * bool * bool) list ; + (** type parameters: (type, covariant, contravariant) *) + ty_kind : type_kind; (** Type kind. *) + ty_private : private_flag; (** Private or public type. *) + ty_manifest : Types.type_expr option; (** Type manifest. *) + mutable ty_loc : location ; + mutable ty_code : string option; + } + + end + +(** Representation and manipulation of values, class attributes and class methods. *) +module Value : + sig + (** Representation of a value. *) + type t_value = Odoc_value.t_value = + { + val_name : Name.t ; (** Complete name of the value. *) + mutable val_info : info option ; (** Information found in the optional associated comment. *) + val_type : Types.type_expr ; (** Type of the value. *) + val_recursive : bool ; (** [true] if the value is recursive. *) + mutable val_parameters : Odoc_parameter.parameter list ; (** The parameters, if any. *) + mutable val_code : string option ; (** The code of the value, if we had the only the implementation file. *) + mutable val_loc : location ; + } + + (** Representation of a class attribute. *) + type t_attribute = Odoc_value.t_attribute = + { + att_value : t_value ; (** an attribute has almost all the same information as a value *) + att_mutable : bool ; (** [true] if the attribute is mutable. *) + att_virtual : bool ; (** [true] if the attribute is virtual. *) + } + + (** Representation of a class method. *) + type t_method = Odoc_value.t_method = + { + met_value : t_value ; (** a method has almost all the same information as a value *) + met_private : bool ; (** [true] if the method is private.*) + met_virtual : bool ; (** [true] if the method is virtual. *) + } + + (** Return [true] if the value is a function, i.e. it has a functional type. *) + val is_function : t_value -> bool + + (** Access to the description associated to the given parameter name.*) + val value_parameter_text_by_name : t_value -> string -> text option + end + +(** Representation and manipulation of classes and class types.*) +module Class : + sig + (** {3 Types} *) + (** To keep the order of elements in a class. *) + type class_element = Odoc_class.class_element = + Class_attribute of Value.t_attribute + | Class_method of Value.t_method + | Class_comment of text + + (** Used when we can reference a t_class or a t_class_type. *) + type cct = Odoc_class.cct = + Cl of t_class + | Cltype of t_class_type * Types.type_expr list (** Class type and type parameters. *) + + and inherited_class = Odoc_class.inherited_class = + { + ic_name : Name.t ; (** Complete name of the inherited class. *) + mutable ic_class : cct option ; (** The associated t_class or t_class_type. *) + ic_text : text option ; (** The inheritance description, if any. *) + } + + and class_apply = Odoc_class.class_apply = + { + capp_name : Name.t ; (** The complete name of the applied class. *) + mutable capp_class : t_class option; (** The associated t_class if we found it. *) + capp_params : Types.type_expr list; (** The type of expressions the class is applied to. *) + capp_params_code : string list ; (** The code of these exprssions. *) + } + + and class_constr = Odoc_class.class_constr = + { + cco_name : Name.t ; (** The complete name of the applied class. *) + mutable cco_class : cct option; + (** The associated class or class type if we found it. *) + cco_type_parameters : Types.type_expr list; (** The type parameters of the class, if needed. *) + } + + and class_kind = Odoc_class.class_kind = + Class_structure of inherited_class list * class_element list + (** An explicit class structure, used in implementation and interface. *) + | Class_apply of class_apply + (** Application/alias of a class, used in implementation only. *) + | Class_constr of class_constr + (** A class used to give the type of the defined class, + instead of a structure, used in interface only. + For example, it will be used with the name [M1.M2....bar] + when the class foo is defined like this : + [class foo : int -> bar] *) + | Class_constraint of class_kind * class_type_kind + (** A class definition with a constraint. *) + + (** Representation of a class. *) + and t_class = Odoc_class.t_class = + { + cl_name : Name.t ; (** Complete name of the class. *) + mutable cl_info : info option ; (** Information found in the optional associated comment. *) + cl_type : Types.class_type ; (** Type of the class. *) + cl_type_parameters : Types.type_expr list ; (** Type parameters. *) + cl_virtual : bool ; (** [true] when the class is virtual. *) + mutable cl_kind : class_kind ; (** The way the class is defined. *) + mutable cl_parameters : Parameter.parameter list ; (** The parameters of the class. *) + mutable cl_loc : location ; + } + + and class_type_alias = Odoc_class.class_type_alias = + { + cta_name : Name.t ; (** Complete name of the target class type. *) + mutable cta_class : cct option ; (** The target t_class or t_class_type, if we found it.*) + cta_type_parameters : Types.type_expr list ; (** The type parameters. A VOIR : mettre des string ? *) + } + + and class_type_kind = Odoc_class.class_type_kind = + Class_signature of inherited_class list * class_element list + | Class_type of class_type_alias (** A class type eventually applied to type args. *) + + (** Representation of a class type. *) + and t_class_type = Odoc_class.t_class_type = + { + clt_name : Name.t ; (** Complete name of the type. *) + mutable clt_info : info option ; (** Information found in the optional associated comment. *) + clt_type : Types.class_type ; + clt_type_parameters : Types.type_expr list ; (** Type parameters. *) + clt_virtual : bool ; (** [true] if the class type is virtual *) + mutable clt_kind : class_type_kind ; (** The way the class type is defined. *) + mutable clt_loc : location ; + } + + (** {3 Functions} *) + + (** Access to the elements of a class. *) + val class_elements : ?trans:bool -> t_class -> class_element list + + (** Access to the list of class attributes. *) + val class_attributes : ?trans:bool -> t_class -> Value.t_attribute list + + (** Access to the description associated to the given class parameter name. *) + val class_parameter_text_by_name : t_class -> string -> text option + + (** Access to the methods of a class. *) + val class_methods : ?trans:bool -> t_class -> Value.t_method list + + (** Access to the comments of a class. *) + val class_comments : ?trans:bool -> t_class -> text list + + (** Access to the elements of a class type. *) + val class_type_elements : ?trans:bool -> t_class_type -> class_element list + + (** Access to the list of class type attributes. *) + val class_type_attributes : ?trans:bool -> t_class_type -> Value.t_attribute list + + (** Access to the description associated to the given class type parameter name. *) + val class_type_parameter_text_by_name : t_class_type -> string -> text option + + (** Access to the methods of a class type. *) + val class_type_methods : ?trans:bool -> t_class_type -> Value.t_method list + + (** Access to the comments of a class type. *) + val class_type_comments : ?trans:bool -> t_class_type -> text list + end + +(** Representation and manipulation of modules and module types. *) +module Module : + sig + (** {3 Types} *) + (** To keep the order of elements in a module. *) + type module_element = Odoc_module.module_element = + Element_module of t_module + | Element_module_type of t_module_type + | Element_included_module of included_module + | Element_class of Class.t_class + | Element_class_type of Class.t_class_type + | Element_value of Value.t_value + | Element_exception of Exception.t_exception + | Element_type of Type.t_type + | Element_module_comment of text + + (** Used where we can reference t_module or t_module_type. *) + and mmt = Odoc_module.mmt = + | Mod of t_module + | Modtype of t_module_type + + and included_module = Odoc_module.included_module = + { + im_name : Name.t ; (** Complete name of the included module. *) + mutable im_module : mmt option ; (** The included module or module type, if we found it. *) + mutable im_info : Odoc_types.info option ; (** comment associated to the includ directive *) + } + + and module_alias = Odoc_module.module_alias = + { + ma_name : Name.t ; (** Complete name of the target module. *) + mutable ma_module : mmt option ; (** The real module or module type if we could associate it. *) + } + + and module_parameter = Odoc_module.module_parameter = { + mp_name : string ; (** the name *) + mp_type : Types.module_type ; (** the type *) + mp_type_code : string ; (** the original code *) + mp_kind : module_type_kind ; (** the way the parameter was built *) + } + + (** Different kinds of a module. *) + and module_kind = Odoc_module.module_kind = + | Module_struct of module_element list (** A complete module structure. *) + | Module_alias of module_alias (** Complete name and corresponding module if we found it *) + | Module_functor of module_parameter * module_kind + (** A functor, with its parameter and the rest of its definition *) + | Module_apply of module_kind * module_kind + (** A module defined by application of a functor. *) + | Module_with of module_type_kind * string + (** A module whose type is a with ... constraint. + Should appear in interface files only. *) + | Module_constraint of module_kind * module_type_kind + (** A module constraint by a module type. *) + + (** Representation of a module. *) + and t_module = Odoc_module.t_module = + { + m_name : Name.t ; (** Complete name of the module. *) + mutable m_type : Types.module_type ; (** The type of the module. *) + mutable m_info : info option ; (** Information found in the optional associated comment. *) + m_is_interface : bool ; (** [true] for modules read from interface files *) + m_file : string ; (** The file the module is defined in. *) + mutable m_kind : module_kind ; (** The way the module is defined. *) + mutable m_loc : location ; + mutable m_top_deps : Name.t list ; (** The toplevels module names this module depends on. *) + mutable m_code : string option ; (** The whole code of the module *) + mutable m_code_intf : string option ; (** The whole code of the interface of the module *) + m_text_only : bool ; (** [true] if the module comes from a text file *) + } + + and module_type_alias = Odoc_module.module_type_alias = + { + mta_name : Name.t ; (** Complete name of the target module type. *) + mutable mta_module : t_module_type option ; (** The real module type if we could associate it. *) + } + + (** Different kinds of module type. *) + and module_type_kind = Odoc_module.module_type_kind = + | Module_type_struct of module_element list (** A complete module signature. *) + | Module_type_functor of module_parameter * module_type_kind + (** A functor, with its parameter and the rest of its definition *) + | Module_type_alias of module_type_alias + (** Complete alias name and corresponding module type if we found it. *) + | Module_type_with of module_type_kind * string + (** The module type kind and the code of the with constraint. *) + + (** Representation of a module type. *) + and t_module_type = Odoc_module.t_module_type = + { + mt_name : Name.t ; (** Complete name of the module type. *) + mutable mt_info : info option ; (** Information found in the optional associated comment. *) + mutable mt_type : Types.module_type option ; (** [None] means that the module type is abstract. *) + mt_is_interface : bool ; (** [true] for modules read from interface files. *) + mt_file : string ; (** The file the module type is defined in. *) + mutable mt_kind : module_type_kind option ; + (** The way the module is defined. [None] means that module type is abstract. + It is always [None] when the module type was extracted from the implementation file. + That means module types are only analysed in interface files. *) + mutable mt_loc : location ; + } + + (** {3 Functions for modules} *) + + (** Access to the elements of a module. *) + val module_elements : ?trans:bool -> t_module -> module_element list + + (** Access to the submodules of a module. *) + val module_modules : ?trans:bool -> t_module -> t_module list + + (** Access to the module types of a module. *) + val module_module_types : ?trans:bool -> t_module -> t_module_type list + + (** Access to the included modules of a module. *) + val module_included_modules : ?trans:bool-> t_module -> included_module list + + (** Access to the exceptions of a module. *) + val module_exceptions : ?trans:bool-> t_module -> Exception.t_exception list + + (** Access to the types of a module. *) + val module_types : ?trans:bool-> t_module -> Type.t_type list + + (** Access to the values of a module. *) + val module_values : ?trans:bool -> t_module -> Value.t_value list + + (** Access to functional values of a module. *) + val module_functions : ?trans:bool-> t_module -> Value.t_value list + + (** Access to non-functional values of a module. *) + val module_simple_values : ?trans:bool-> t_module -> Value.t_value list + + (** Access to the classes of a module. *) + val module_classes : ?trans:bool-> t_module -> Class.t_class list + + (** Access to the class types of a module. *) + val module_class_types : ?trans:bool-> t_module -> Class.t_class_type list + + (** The list of classes defined in this module and all its submodules and functors. *) + val module_all_classes : ?trans:bool-> t_module -> Class.t_class list + + (** [true] if the module is functor. *) + val module_is_functor : t_module -> bool + + (** The list of couples (module parameter, optional description). *) + val module_parameters : ?trans:bool-> t_module -> (module_parameter * text option) list + + (** The list of module comments. *) + val module_comments : ?trans:bool-> t_module -> text list + + (** {3 Functions for module types} *) + + (** Access to the elements of a module type. *) + val module_type_elements : ?trans:bool-> t_module_type -> module_element list + + (** Access to the submodules of a module type. *) + val module_type_modules : ?trans:bool-> t_module_type -> t_module list + + (** Access to the module types of a module type. *) + val module_type_module_types : ?trans:bool-> t_module_type -> t_module_type list + + (** Access to the included modules of a module type. *) + val module_type_included_modules : ?trans:bool-> t_module_type -> included_module list + + (** Access to the exceptions of a module type. *) + val module_type_exceptions : ?trans:bool-> t_module_type -> Exception.t_exception list + + (** Access to the types of a module type. *) + val module_type_types : ?trans:bool-> t_module_type -> Type.t_type list + + (** Access to the values of a module type. *) + val module_type_values : ?trans:bool-> t_module_type -> Value.t_value list + + (** Access to functional values of a module type. *) + val module_type_functions : ?trans:bool-> t_module_type -> Value.t_value list + + (** Access to non-functional values of a module type. *) + val module_type_simple_values : ?trans:bool-> t_module_type -> Value.t_value list + + (** Access to the classes of a module type. *) + val module_type_classes : ?trans:bool-> t_module_type -> Class.t_class list + + (** Access to the class types of a module type. *) + val module_type_class_types : ?trans:bool-> t_module_type -> Class.t_class_type list + + (** The list of classes defined in this module type and all its submodules and functors. *) + val module_type_all_classes : ?trans:bool-> t_module_type -> Class.t_class list + + (** [true] if the module type is functor. *) + val module_type_is_functor : t_module_type -> bool + + (** The list of couples (module parameter, optional description). *) + val module_type_parameters : ?trans:bool-> t_module_type -> (module_parameter * text option) list + + (** The list of module comments. *) + val module_type_comments : ?trans:bool-> t_module_type -> text list + end + + +(** {3 Getting strings from values} *) + +(** This function is used to reset the names of type variables. + It must be called when printing the whole type of a function, + but not when printing the type of its parameters. Same for + classes (call it) and methods and attributes (don't call it).*) +val reset_type_names : unit -> unit + +(** [string_of_variance t (covariant, invariant)] returns ["+"] if + the given information means "covariant", ["-"] if the it means + "contravariant", orelse [""], and always [""] if the given + type is not an abstract type with no manifest (i.e. no need + for the variance to be printed.*) +val string_of_variance : Type.t_type -> (bool * bool) -> string + +(** This function returns a string representing a Types.type_expr. *) +val string_of_type_expr : Types.type_expr -> string + +(** @return a string to display the parameters of the given class, + in the same form as the compiler. *) +val string_of_class_params : Class.t_class -> string + +(** This function returns a string to represent the given list of types, + with a given separator. *) +val string_of_type_list : ?par: bool -> string -> Types.type_expr list -> string + +(** This function returns a string to represent the list of type parameters + for the given type. *) +val string_of_type_param_list : Type.t_type -> string + +(** This function returns a string to represent the given list of + type parameters of a class or class type, + with a given separator. *) +val string_of_class_type_param_list : Types.type_expr list -> string + +(** This function returns a string representing a [Types.module_type]. + @param complete indicates if we must print complete signatures + or just [sig end]. Default if [false]. + @param code if [complete = false] and the type contains something else + than identificators and functors, then the given code is used. +*) +val string_of_module_type : ?code: string -> ?complete: bool -> Types.module_type -> string + +(** This function returns a string representing a [Types.class_type]. + @param complete indicates if we must print complete signatures + or just [object end]. Default if [false]. +*) +val string_of_class_type : ?complete: bool -> Types.class_type -> string + + +(** Get a string from a text. *) +val string_of_text : text -> string + +(** Get a string from an info structure. *) +val string_of_info : info -> string + +(** @return a string to describe the given type. *) +val string_of_type : Type.t_type -> string + +(** @return a string to describe the given exception. *) +val string_of_exception : Exception.t_exception -> string + +(** @return a string to describe the given value. *) +val string_of_value : Value.t_value -> string + +(** @return a string to describe the given attribute. *) +val string_of_attribute : Value.t_attribute -> string + +(** @return a string to describe the given method. *) +val string_of_method : Value.t_method -> string + +(** {3 Miscelaneous functions} *) + +(** Return the first sentence (until the first dot followed by a blank + or the first blank line) of a text. + Don't stop in the middle of [Code], [CodePre], [Verbatim], [List], [Enum], + [Latex], [Link], [Ref], [Subscript] or [Superscript]. *) +val first_sentence_of_text : text -> text + +(** Return the first sentence (until the first dot followed by a blank + or the first blank line) of a text, and the remaining text after. + Don't stop in the middle of [Code], [CodePre], [Verbatim], [List], [Enum], + [Latex], [Link], [Ref], [Subscript] or [Superscript].*) +val first_sentence_and_rest_of_text : text -> text * text + +(** Return the given [text] without any title or list. *) +val text_no_title_no_list : text -> text + +(** [concat sep l] concats the given list of text [l], each separated with + the text [sep]. *) +val text_concat : Odoc_types.text -> Odoc_types.text list -> Odoc_types.text + +(** Return the list of titles in a [text]. + A title is a title level, an optional label and a text.*) +val get_titles_in_text : text -> (int * string option * text) list + +(** Take a sorted list of elements, a function to get the name + of an element and return the list of list of elements, + where each list group elements beginning by the same letter. + Since the original list is sorted, elements whose name does not + begin with a letter should be in the first returned list.*) +val create_index_lists : 'a list -> ('a -> string) -> 'a list list + +(** Take a type and remove the option top constructor. This is + useful when printing labels, we we then remove the top option contructor + for optional labels.*) +val remove_option : Types.type_expr -> Types.type_expr + +(** Return [true] if the given label is optional.*) +val is_optional : string -> bool + +(** Return the label name for the given label, + i.e. removes the beginning '?' if present.*) +val label_name : string -> string + +(** Return the given name where the module name or + part of it was removed, according to the list of modules + which must be hidden (cf {!Odoc_args.hidden_modules})*) +val use_hidden_modules : Name.t -> Name.t + +(** Print the given string if the verbose mode is activated. *) +val verbose : string -> unit + +(** Print a warning message to stderr. + If warnings must be treated as errors, then the + error counter is incremented. *) +val warning : string -> unit + +(** A flag to indicate whether ocamldoc warnings must be printed or not. *) +val print_warnings : bool ref + +(** Increment this counter when an error is encountered. + The ocamldoc tool will print the number of errors + encountered exit with code 1 if this number is greater + than 0. *) +val errors : int ref + +(** Apply a function to an optional value. *) +val apply_opt : ('a -> 'b) -> 'a option -> 'b option + +(** Apply a function to a first value if it is + not different from a second value. If the two values + are different, return the second one.*) +val apply_if_equal : ('a -> 'a) -> 'a -> 'a -> 'a + +(** [text_of_string s] returns the text structure from the + given string. + @raise Text_syntax if a syntax error is encountered. *) +val text_of_string : string -> text + +(** [text_string_of_text text] returns the string representing + the given [text]. This string can then be parsed again + by {!Odoc_info.text_of_string}.*) +val text_string_of_text : text -> string + +(** [info_of_string s] parses the given string + like a regular ocamldoc comment and return an + {!Odoc_info.info} structure. + @return an empty structure if there was a syntax error. TODO: change this +*) +val info_of_string : string -> info + +(** [info_string_of_info info] returns the string representing + the given [info]. This string can then be parsed again + by {!Odoc_info.info_of_string}.*) +val info_string_of_info : info -> string + +(** [info_of_comment_file file] parses the given file + and return an {!Odoc_info.info} structure. The content of the + file must have the same syntax as the content of a special comment. + The given module list is used for cross reference. + @raise Failure is the file could not be opened or there is a + syntax error. +*) +val info_of_comment_file : Module.t_module list -> string -> info + +(** [remove_ending_newline s] returns [s] without the optional ending newline. *) +val remove_ending_newline : string -> string + +(** Research in elements *) +module Search : + sig + type result_element = Odoc_search.result_element = + Res_module of Module.t_module + | Res_module_type of Module.t_module_type + | Res_class of Class.t_class + | Res_class_type of Class.t_class_type + | Res_value of Value.t_value + | Res_type of Type.t_type + | Res_exception of Exception.t_exception + | Res_attribute of Value.t_attribute + | Res_method of Value.t_method + | Res_section of string * text + + (** The type representing a research result.*) + type search_result = result_element list + + (** Research of the elements whose name matches the given regular expression.*) + val search_by_name : Module.t_module list -> Str.regexp -> search_result + + (** A function to search all the values in a list of modules. *) + val values : Module.t_module list -> Value.t_value list + + (** A function to search all the exceptions in a list of modules. *) + val exceptions : Module.t_module list -> Exception.t_exception list + + (** A function to search all the types in a list of modules. *) + val types : Module.t_module list -> Type.t_type list + + (** A function to search all the class attributes in a list of modules. *) + val attributes : Module.t_module list -> Value.t_attribute list + + (** A function to search all the class methods in a list of modules. *) + val methods : Module.t_module list -> Value.t_method list + + (** A function to search all the classes in a list of modules. *) + val classes : Module.t_module list -> Class.t_class list + + (** A function to search all the class types in a list of modules. *) + val class_types : Module.t_module list -> Class.t_class_type list + + (** A function to search all the modules in a list of modules. *) + val modules : Module.t_module list -> Module.t_module list + + (** A function to search all the module types in a list of modules. *) + val module_types : Module.t_module list -> Module.t_module_type list + + end + +(** Scanning of collected information *) +module Scan : + sig + class scanner : + object + (** Scan of 'leaf elements'. *) + + method scan_value : Value.t_value -> unit + method scan_type : Type.t_type -> unit + method scan_exception : Exception.t_exception -> unit + method scan_attribute : Value.t_attribute -> unit + method scan_method : Value.t_method -> unit + method scan_included_module : Module.included_module -> unit + + (** Scan of a class. *) + + (** Scan of a comment inside a class. *) + method scan_class_comment : text -> unit + + (** Override this method to perform controls on the class comment + and params. This method is called before scanning the class elements. + @return true if the class elements must be scanned.*) + method scan_class_pre : Class.t_class -> bool + + (** This method scan the elements of the given class. *) + method scan_class_elements : Class.t_class -> unit + + (** Scan of a class. Should not be overriden. It calls [scan_class_pre] + and if [scan_class_pre] returns [true], then it calls scan_class_elements.*) + method scan_class : Class.t_class -> unit + + (** Scan of a class type. *) + + (** Scan of a comment inside a class type. *) + method scan_class_type_comment : text -> unit + + (** Override this method to perform controls on the class type comment + and form. This method is called before scanning the class type elements. + @return true if the class type elements must be scanned.*) + method scan_class_type_pre : Class.t_class_type -> bool + + (** This method scan the elements of the given class type. *) + method scan_class_type_elements : Class.t_class_type -> unit + + (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre] + and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*) + method scan_class_type : Class.t_class_type -> unit + + (** Scan of modules. *) + + (** Scan of a comment inside a module. *) + method scan_module_comment : text -> unit + + (** Override this method to perform controls on the module comment + and form. This method is called before scanning the module elements. + @return true if the module elements must be scanned.*) + method scan_module_pre : Module.t_module -> bool + + (** This method scan the elements of the given module. *) + method scan_module_elements : Module.t_module -> unit + + (** Scan of a module. Should not be overriden. It calls [scan_module_pre] + and if [scan_module_pre] returns [true], then it calls scan_module_elements.*) + method scan_module : Module.t_module -> unit + + (** Scan of module types. *) + + (** Scan of a comment inside a module type. *) + method scan_module_type_comment : text -> unit + + (** Override this method to perform controls on the module type comment + and form. This method is called before scanning the module type elements. + @return true if the module type elements must be scanned. *) + method scan_module_type_pre : Module.t_module_type -> bool + + (** This method scan the elements of the given module type. *) + method scan_module_type_elements : Module.t_module_type -> unit + + (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre] + and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*) + method scan_module_type : Module.t_module_type -> unit + + (** Main scanning method. *) + + (** Scan a list of modules. *) + method scan_module_list : Module.t_module list -> unit + end + end + +(** Computation of dependencies. *) +module Dep : + sig + (** Modify the modules depencies of the given list of modules, + to get the minimum transitivity kernel. *) + val kernel_deps_of_modules : Module.t_module list -> unit + + (** Return the list of dependencies between the given types, + in the form of a list [(type name, names of types it depends on)]. + @param kernel indicates if we must keep only the transitivity kernel + of the dependencies. Default is [false]. + *) + val deps_of_types : ?kernel: bool -> Type.t_type list -> (Type.t_type * (Name.t list)) list + end + +(** {2 Command line arguments} *) + +(** You can use this module to create custom generators.*) +module Args : + sig + (** The kind of source file in arguments. *) + type source_file = + Impl_file of string + | Intf_file of string + | Text_file of string + + (** The class type of documentation generators. *) + class type doc_generator = + object method generate : Module.t_module list -> unit end + + (** The file used by the generators outputting only one file. *) + val out_file : string ref + + (** Verbose mode or not. *) + val verbose : bool ref + + (** The optional title to use in the generated documentation. *) + val title : string option ref + + (** To inverse [.ml] and [.mli] files while merging comments. *) + val inverse_merge_ml_mli : bool ref + + (** To filter module elements according to module type constraints. *) + val filter_with_module_constraints : bool ref + + (** To keep the code while merging, when we have both .ml and .mli files for a module. *) + val keep_code : bool ref + + (** The optional file whose content can be used as intro text. *) + val intro_file : string option ref + + (** Flag to indicate whether we must display the complete list of parameters + for functions and methods. *) + val with_parameter_list : bool ref + + (** The list of module names to hide. *) + val hidden_modules : string list ref + + (** The directory where files have to be generated. *) + val target_dir : string ref + + (** An optional file to use where a CSS style is defined (for HTML). *) + val css_style : string option ref + + (** Generate only index files. (for HTML). *) + val index_only : bool ref + + (** To colorize code in HTML generated documentation pages, not code pages. *) + val colorize_code : bool ref + + (** To display functors in short form rather than with "functor ... -> ", + in HTML generated documentation. *) + val html_short_functors : bool ref + + (** The flag which indicates if we must generate a header (for LaTeX). *) + val with_header : bool ref + + (** The flag which indicates if we must generate a trailer (for LaTeX). *) + val with_trailer : bool ref + + (** The flag to indicate if we must generate one file per module (for LaTeX). *) + val separate_files : bool ref + + (** The list of pairs (title level, sectionning style). *) + val latex_titles : (int * string) list ref + + (** The prefix to use for value labels in LaTeX. *) + val latex_value_prefix : string ref + + (** The prefix to use for type labels in LaTeX. *) + val latex_type_prefix : string ref + + (** The prefix to use for exception labels in LaTeX. *) + val latex_exception_prefix : string ref + + (** The prefix to use for module labels in LaTeX. *) + val latex_module_prefix : string ref + + (** The prefix to use for module type labels in LaTeX. *) + val latex_module_type_prefix : string ref + + (** The prefix to use for class labels in LaTeX. *) + val latex_class_prefix : string ref + + (** The prefix to use for class type labels in LaTeX. *) + val latex_class_type_prefix : string ref + + (** The prefix to use for attribute labels in LaTeX. *) + val latex_attribute_prefix : string ref + + (** The prefix to use for method labels in LaTeX. *) + val latex_method_prefix : string ref + + (** The flag which indicates if we must generate a table of contents (for LaTeX). *) + val with_toc : bool ref + + (** The flag which indicates if we must generate an index (for TeXinfo). *) + val with_index : bool ref + + (** The flag which indicates if we must escape accentuated characters (for TeXinfo).*) + val esc_8bits : bool ref + + (** The Info directory section *) + val info_section : string ref + + (** The Info directory entries to insert *) + val info_entry : string list ref + + (** Include all modules or only the ones on the command line, for the dot ouput. *) + val dot_include_all : bool ref + + (** Generate dependency graph for types. *) + val dot_types : bool ref + + (** Perform transitive reduction before dot output. *) + val dot_reduce : bool ref + + (** The colors used in the dot output. *) + val dot_colors : string list ref + + (** The suffix for man pages. *) + val man_suffix : string ref + + (** The section for man pages. *) + val man_section : string ref + + (** The flag to generate all man pages or only for modules and classes.*) + val man_mini : bool ref + + (** The files to be analysed. *) + val files : source_file list ref + + (** To set the documentation generator. *) + val set_doc_generator : doc_generator option -> unit + + (** Add an option specification. *) + val add_option : string * Arg.spec * string -> unit + end + +(** Analysis of the given source files. + @param init is the list of modules already known from a previous analysis. + @return the list of analysed top modules. *) +val analyse_files : + ?merge_options:Odoc_types.merge_option list -> + ?include_dirs:string list -> + ?labels:bool -> + ?sort_modules:bool -> + ?no_stop:bool -> + ?init: Odoc_module.t_module list -> + Args.source_file list -> + Module.t_module list + +(** Dump of a list of modules into a file. + @raise Failure if an error occurs.*) +val dump_modules : string -> Odoc_module.t_module list -> unit + +(** Load of a list of modules from a file. + @raise Failure if an error occurs.*) +val load_modules : string -> Odoc_module.t_module list diff --git a/ocamldoc/odoc_inherit.ml b/ocamldoc/odoc_inherit.ml new file mode 100644 index 0000000..b247787 --- /dev/null +++ b/ocamldoc/odoc_inherit.ml @@ -0,0 +1,13 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_inherit.ml,v 1.2 2003-11-24 10:41:04 starynke Exp $ *) + diff --git a/ocamldoc/odoc_latex.ml b/ocamldoc/odoc_latex.ml new file mode 100644 index 0000000..b754db4 --- /dev/null +++ b/ocamldoc/odoc_latex.ml @@ -0,0 +1,1145 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_latex.ml,v 1.41 2007-10-09 10:29:36 weis Exp $ *) + +(** Generation of LaTeX documentation. *) + +let print_DEBUG s = print_string s ; print_newline () + +open Odoc_info +open Parameter +open Value +open Type +open Exception +open Class +open Module + +let new_buf () = Buffer.create 1024 +let new_fmt () = + let b = new_buf () in + let fmt = Format.formatter_of_buffer b in + (fmt, + fun () -> + Format.pp_print_flush fmt (); + let s = Buffer.contents b in + Buffer.reset b; + s + ) + +let p = Format.fprintf +let ps f s = Format.fprintf f "%s" s + + +let bp = Printf.bprintf +let bs = Buffer.add_string + +let print_concat fmt sep f = + let rec iter = function + [] -> () + | [c] -> f c + | c :: q -> + f c; + ps fmt sep; + iter q + in + iter + +(** Generation of LaTeX code from text structures. *) +class text = + object (self) + (** Return latex code to make a sectionning according to the given level, + and with the given latex code. *) + method section_style level s = + try + let sec = List.assoc level !Args.latex_titles in + "\\"^sec^"{"^s^"}\n" + with Not_found -> s + + (** Associations of strings to subsitute in latex code. *) + val mutable subst_strings = [ + ("MAXENCE"^"ZZZ", "\\$"); + ("MAXENCE"^"YYY", "\\&"); + ("MAXENCE"^"XXX", "{\\textbackslash}") ; + ("à", "\\`a") ; + ("â", "\\^a") ; + ("é", "\\'e") ; + ("è", "\\`e") ; + ("ê", "\\^e") ; + ("ë", "\\\"e") ; + ("ç", "\\c{c}") ; + ("ô", "\\^o") ; + ("ö", "\\\"o") ; + ("î", "\\^i") ; + ("ï", "\\\"i") ; + ("ù", "\\`u") ; + ("û", "\\^u") ; + ("%", "\\%") ; + ("_", "\\_"); + ("\\.\\.\\.", "$\\ldots$"); + ("~", "\\~{}"); + ("#", "\\verb`#`"); + ("}", "\\}"); + ("{", "\\{"); + ("&", "\\&"); + (">", "$>$"); + ("<", "$<$"); + ("=", "$=$"); + (">=", "$\\geq$"); + ("<=", "$\\leq$"); + ("->", "$\\rightarrow$") ; + ("<-", "$\\leftarrow$"); + ("|", "\\textbar "); + ("\\^", "\\textasciicircum ") ; + ("\\.\\.\\.", "$\\ldots$"); + ("\\\\", "MAXENCE"^"XXX") ; + ("&", "MAXENCE"^"YYY") ; + ("\\$", "MAXENCE"^"ZZZ") + ] + + val mutable subst_strings_simple = + [ + ("MAXENCE"^"XXX", "{\\textbackslash}") ; + "}", "\\}" ; + "{", "\\{" ; + ("\\\\", "MAXENCE"^"XXX") ; + ] + + val mutable subst_strings_code = [ + ("MAXENCE"^"ZZZ", "\\$"); + ("MAXENCE"^"YYY", "\\&"); + ("MAXENCE"^"XXX", "{\\textbackslash}") ; + ("%", "\\%") ; + ("_", "\\_"); + ("~", "\\~{}"); + ("#", "\\verb`#`"); + ("}", "\\}"); + ("{", "\\{"); + ("&", "\\&"); + ("\\^", "\\textasciicircum ") ; + ("&", "MAXENCE"^"YYY") ; + ("\\$", "MAXENCE"^"ZZZ") ; + ("\\\\", "MAXENCE"^"XXX") ; + ] + + method subst l s = + List.fold_right + (fun (s, s2) -> fun acc -> Str.global_replace (Str.regexp s) s2 acc) + l + s + + (** Escape the strings which would clash with LaTeX syntax. *) + method escape s = self#subst subst_strings s + + (** Escape the ['\'], ['{'] and ['}'] characters. *) + method escape_simple s = self#subst subst_strings_simple s + + (** Escape some characters for the code style. *) + method escape_code s = self#subst subst_strings_code s + + (** Make a correct latex label from a name. *) + (* The following characters are forbidden in LaTeX \index: + \ { } $ & # ^ _ % ~ ! " @ | (" to close the double quote) + The following characters are forbidden in LaTeX \label: + \ { } $ & # ^ _ % ~ + So we will use characters not forbidden in \index if no_ = true. + *) + method label ?(no_=true) name = + let len = String.length name in + let buf = Buffer.create len in + for i = 0 to len - 1 do + let (s_no_, s) = + match name.[i] with + '_' -> ("-underscore", "_") + | '~' -> ("-tilde", "~") + | '%' -> ("-percent", "%") + | '@' -> ("-at", "\"@") + | '!' -> ("-bang", "\"!") + | '|' -> ("-pipe", "\"|") + | '<' -> ("-lt", "<") + | '>' -> ("-gt", ">") + | '^' -> ("-exp", "^") + | '&' -> ("-ampersand", "&") + | '+' -> ("-plus", "+") + | '-' -> ("-minus", "-") + | '*' -> ("-star", "*") + | '/' -> ("-slash", "/") + | '$' -> ("-dollar", "$") + | '=' -> ("-equal", "=") + | ':' -> ("-colon", ":") + | c -> (String.make 1 c, String.make 1 c) + in + Buffer.add_string buf (if no_ then s_no_ else s) + done; + Buffer.contents buf + + (** Make a correct label from a value name. *) + method value_label ?no_ name = !Args.latex_value_prefix^(self#label ?no_ name) + + (** Make a correct label from an attribute name. *) + method attribute_label ?no_ name = !Args.latex_attribute_prefix^(self#label ?no_ name) + + (** Make a correct label from a method name. *) + method method_label ?no_ name = !Args.latex_method_prefix^(self#label ?no_ name) + + (** Make a correct label from a class name. *) + method class_label ?no_ name = !Args.latex_class_prefix^(self#label ?no_ name) + + (** Make a correct label from a class type name. *) + method class_type_label ?no_ name = !Args.latex_class_type_prefix^(self#label ?no_ name) + + (** Make a correct label from a module name. *) + method module_label ?no_ name = !Args.latex_module_prefix^(self#label ?no_ name) + + (** Make a correct label from a module type name. *) + method module_type_label ?no_ name = !Args.latex_module_type_prefix^(self#label ?no_ name) + + (** Make a correct label from an exception name. *) + method exception_label ?no_ name = !Args.latex_exception_prefix^(self#label ?no_ name) + + (** Make a correct label from a type name. *) + method type_label ?no_ name = !Args.latex_type_prefix^(self#label ?no_ name) + + (** Return latex code for the label of a given label. *) + method make_label label = "\\label{"^label^"}" + + (** Return latex code for the ref to a given label. *) + method make_ref label = "\\ref{"^label^"}" + + (** Print the LaTeX code corresponding to the [text] parameter.*) + method latex_of_text fmt t = + List.iter (self#latex_of_text_element fmt) t + + (** Print the LaTeX code for the [text_element] in parameter. *) + method latex_of_text_element fmt te = + match te with + | Odoc_info.Raw s -> self#latex_of_Raw fmt s + | Odoc_info.Code s -> self#latex_of_Code fmt s + | Odoc_info.CodePre s -> self#latex_of_CodePre fmt s + | Odoc_info.Verbatim s -> self#latex_of_Verbatim fmt s + | Odoc_info.Bold t -> self#latex_of_Bold fmt t + | Odoc_info.Italic t -> self#latex_of_Italic fmt t + | Odoc_info.Emphasize t -> self#latex_of_Emphasize fmt t + | Odoc_info.Center t -> self#latex_of_Center fmt t + | Odoc_info.Left t -> self#latex_of_Left fmt t + | Odoc_info.Right t -> self#latex_of_Right fmt t + | Odoc_info.List tl -> self#latex_of_List fmt tl + | Odoc_info.Enum tl -> self#latex_of_Enum fmt tl + | Odoc_info.Newline -> self#latex_of_Newline fmt + | Odoc_info.Block t -> self#latex_of_Block fmt t + | Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title fmt n l_opt t + | Odoc_info.Latex s -> self#latex_of_Latex fmt s + | Odoc_info.Link (s, t) -> self#latex_of_Link fmt s t + | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref fmt name ref_opt + | Odoc_info.Superscript t -> self#latex_of_Superscript fmt t + | Odoc_info.Subscript t -> self#latex_of_Subscript fmt t + | Odoc_info.Module_list _ -> () + | Odoc_info.Index_list -> () + | Odoc_info.Custom (s,t) -> self#latex_of_custom_text fmt s t + + method latex_of_custom_text fmt s t = () + + method latex_of_Raw fmt s = + ps fmt (self#escape s) + + method latex_of_Code fmt s = + let s2 = self#escape_code s in + let s3 = Str.global_replace (Str.regexp "\n") ("\\\\\n") s2 in + p fmt "{\\tt{%s}}" s3 + + method latex_of_CodePre fmt s = + ps fmt "\\begin{ocamldoccode}\n"; + ps fmt (self#escape_simple s); + ps fmt "\n\\end{ocamldoccode}\n" + + method latex_of_Verbatim fmt s = + ps fmt "\\begin{verbatim}"; + ps fmt s; + ps fmt "\\end{verbatim}" + + method latex_of_Bold fmt t = + ps fmt "{\\bf "; + self#latex_of_text fmt t; + ps fmt "}" + + method latex_of_Italic fmt t = + ps fmt "{\\it "; + self#latex_of_text fmt t; + ps fmt "}" + + method latex_of_Emphasize fmt t = + ps fmt "{\\em "; + self#latex_of_text fmt t; + ps fmt "}" + + method latex_of_Center fmt t = + ps fmt "\\begin{center}\n"; + self#latex_of_text fmt t; + ps fmt "\\end{center}\n" + + method latex_of_Left fmt t = + ps fmt "\\begin{flushleft}\n"; + self#latex_of_text fmt t; + ps fmt "\\end{flushleft}\n" + + method latex_of_Right fmt t = + ps fmt "\\begin{flushright}\n"; + self#latex_of_text fmt t; + ps fmt "\\end{flushright}\n" + + method latex_of_List fmt tl = + ps fmt "\\begin{itemize}\n"; + List.iter + (fun t -> + ps fmt "\\item "; + self#latex_of_text fmt t; + ps fmt "\n" + ) + tl; + ps fmt "\\end{itemize}\n" + + method latex_of_Enum fmt tl = + ps fmt "\\begin{enumerate}\n"; + List.iter + (fun t -> + ps fmt "\\item "; + self#latex_of_text fmt t; + ps fmt "\n" + ) + tl; + ps fmt "\\end{enumerate}\n" + + method latex_of_Newline fmt = ps fmt "\n\n" + + method latex_of_Block fmt t = + ps fmt "\\begin{ocamldocdescription}\n"; + self#latex_of_text fmt t; + ps fmt "\n\\end{ocamldocdescription}\n" + + method latex_of_Title fmt n label_opt t = + let (fmt2, flush) = new_fmt () in + self#latex_of_text fmt2 t; + let s_title2 = self#section_style n (flush ()) in + ps fmt s_title2; + ( + match label_opt with + None -> () + | Some l -> + ps fmt (self#make_label (self#label ~no_: false l)) + ) + + method latex_of_Latex fmt s = ps fmt s + + method latex_of_Link fmt s t = + self#latex_of_text fmt t ; + ps fmt "[\\url{"; + ps fmt s ; + ps fmt "}]" + + method latex_of_Ref fmt name ref_opt = + match ref_opt with + None -> + self#latex_of_text_element fmt + (Odoc_info.Code (Odoc_info.use_hidden_modules name)) + | Some (RK_section _) -> + self#latex_of_text_element fmt + (Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]")) + | Some kind -> + let f_label = + match kind with + Odoc_info.RK_module -> self#module_label + | Odoc_info.RK_module_type -> self#module_type_label + | Odoc_info.RK_class -> self#class_label + | Odoc_info.RK_class_type -> self#class_type_label + | Odoc_info.RK_value -> self#value_label + | Odoc_info.RK_type -> self#type_label + | Odoc_info.RK_exception -> self#exception_label + | Odoc_info.RK_attribute -> self#attribute_label + | Odoc_info.RK_method -> self#method_label + | Odoc_info.RK_section _ -> assert false + in + self#latex_of_text fmt + [ + Odoc_info.Code (Odoc_info.use_hidden_modules name) ; + Latex ("["^(self#make_ref (f_label name))^"]") + ] + + method latex_of_Superscript fmt t = + ps fmt "$^{"; + self#latex_of_text fmt t; + ps fmt "}$" + + method latex_of_Subscript fmt t = + ps fmt "$_{"; + self#latex_of_text fmt t; + ps fmt "}$" + + end + +(** A class used to generate LaTeX code for info structures. *) +class virtual info = + object (self) + (** The method used to get LaTeX code from a [text]. *) + method virtual latex_of_text : Format.formatter -> Odoc_info.text -> unit + + (** The method used to get a [text] from an optionel info structure. *) + method virtual text_of_info : ?block: bool -> Odoc_info.info option -> Odoc_info.text + + (** Print LaTeX code for a description, except for the [i_params] field. *) + method latex_of_info fmt ?(block=false) info_opt = + self#latex_of_text fmt + (self#text_of_info ~block info_opt) + end + +(** This class is used to create objects which can generate a simple LaTeX documentation. *) +class latex = + object (self) + inherit text + inherit Odoc_to_text.to_text as to_text + inherit info + + (** Get the first sentence and the rest of a description, + from an optional [info] structure. The first sentence + can be empty if it would not appear right in a title. + In the first sentence, the titles and lists has been removed, + since it is used in LaTeX titles and would make LaTeX complain + if we has two nested \section commands. + *) + method first_and_rest_of_info i_opt = + match i_opt with + None -> ([], []) + | Some i -> + match i.Odoc_info.i_desc with + None -> ([], self#text_of_info ~block: true i_opt) + | Some t -> + let (first,_) = Odoc_info.first_sentence_and_rest_of_text t in + let (_, rest) = Odoc_info.first_sentence_and_rest_of_text (self#text_of_info ~block: false i_opt) in + (Odoc_info.text_no_title_no_list first, rest) + + (** Print LaTeX code for a value. *) + method latex_of_value fmt v = + Odoc_info.reset_type_names () ; + let label = self#value_label v.val_name in + let latex = self#make_label label in + self#latex_of_text fmt + ((Latex latex) :: + (to_text#text_of_value v)) + + (** Print LaTeX code for a class attribute. *) + method latex_of_attribute fmt a = + self#latex_of_text fmt + ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: + (to_text#text_of_attribute a)) + + (** Print LaTeX code for a class method. *) + method latex_of_method fmt m = + self#latex_of_text fmt + ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: + (to_text#text_of_method m)) + + (** Print LaTeX code for the parameters of a type. *) + method latex_of_type_params fmt m_name t = + let print_one (p, co, cn) = + ps fmt (Odoc_info.string_of_variance t (co,cn)); + ps fmt (self#normal_type m_name p) + in + match t.ty_parameters with + [] -> () + | [(p,co,cn)] -> print_one (p, co, cn) + | l -> + ps fmt "("; + print_concat fmt ", " print_one t.ty_parameters; + ps fmt ")" + + method latex_of_class_parameter_list fmt father c = + self#latex_of_text fmt + (self#text_of_class_params father c) + + (** Print LaTeX code for a type. *) + method latex_of_type fmt t = + let s_name = Name.simple t.ty_name in + let text = + let (fmt2, flush2) = new_fmt () in + Odoc_info.reset_type_names () ; + let mod_name = Name.father t.ty_name in + Format.fprintf fmt2 "@[type "; + self#latex_of_type_params fmt2 mod_name t; + (match t.ty_parameters with [] -> () | _ -> ps fmt2 " "); + ps fmt2 s_name; + let priv = t.ty_private = Asttypes.Private in + ( + match t.ty_manifest with + None -> () + | Some typ -> + p fmt2 " = %s%s" (if priv then "private " else "") (self#normal_type mod_name typ) + ); + let s_type3 = + p fmt2 + " %s" + ( + match t.ty_kind with + Type_abstract -> "" + | Type_variant _ -> "="^(if priv then " private" else "") + | Type_record _ -> "= "^(if priv then "private " else "")^"{" + ) ; + flush2 () + in + + let defs = + match t.ty_kind with + Type_abstract -> [] + | Type_variant l -> + (List.flatten + (List.map + (fun constr -> + let s_cons = + p fmt2 "@[ | %s" constr.vc_name; + ( + match constr.vc_args with + [] -> () + | l -> + p fmt2 " %s@ %s" + "of" + (self#normal_type_list ~par: false mod_name " * " l) + ); + flush2 () + in + [ CodePre s_cons ] @ + (match constr.vc_text with + None -> [] + | Some t -> + let s = + ps fmt2 "\\begin{ocamldoccomment}\n"; + self#latex_of_text fmt2 t; + ps fmt2 "\n\\end{ocamldoccomment}\n"; + flush2 () + in + [ Latex s] + ) + ) + l + ) + ) + | Type_record l -> + (List.flatten + (List.map + (fun r -> + let s_field = + p fmt2 + "@[ %s%s :@ %s ;" + (if r.rf_mutable then "mutable " else "") + r.rf_name + (self#normal_type mod_name r.rf_type); + flush2 () + in + [ CodePre s_field ] @ + (match r.rf_text with + None -> [] + | Some t -> + let s = + ps fmt2 "\\begin{ocamldoccomment}\n"; + self#latex_of_text fmt2 t; + ps fmt2 "\n\\end{ocamldoccomment}\n"; + flush2 () + in + [ Latex s] + ) + ) + l + ) + ) @ + [ CodePre "}" ] + in + let defs2 = (CodePre s_type3) :: defs in + let rec iter = function + [] -> [] + | [e] -> [e] + | (CodePre s1) :: (CodePre s2) :: q -> + iter ((CodePre (s1^"\n"^s2)) :: q) + | e :: q -> + e :: (iter q) + in + (iter defs2) @ + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info t.ty_info) + in + self#latex_of_text fmt + ((Latex (self#make_label (self#type_label t.ty_name))) :: text) + + (** Print LaTeX code for an exception. *) + method latex_of_exception fmt e = + Odoc_info.reset_type_names () ; + self#latex_of_text fmt + ((Latex (self#make_label (self#exception_label e.ex_name))) :: + (to_text#text_of_exception e)) + + method latex_of_module_parameter fmt m_name p = + self#latex_of_text fmt + [ + Code "functor ("; + Code p.mp_name ; + Code " : "; + ] ; + self#latex_of_module_type_kind fmt m_name p.mp_kind; + self#latex_of_text fmt [ Code ") -> "] + + + method latex_of_module_type_kind fmt father kind = + match kind with + Module_type_struct eles -> + self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; + List.iter (self#latex_of_module_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] + | Module_type_functor (p, k) -> + self#latex_of_module_parameter fmt father p; + self#latex_of_module_type_kind fmt father k + | Module_type_alias a -> + self#latex_of_text fmt + [Code (self#relative_module_idents father a.mta_name)] + | Module_type_with (k, s) -> + self#latex_of_module_type_kind fmt father k; + self#latex_of_text fmt + [ Code " "; + Code (self#relative_idents father s); + ] + + method latex_of_module_kind fmt father kind = + match kind with + Module_struct eles -> + self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; + List.iter (self#latex_of_module_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] + | Module_alias a -> + self#latex_of_text fmt + [Code (self#relative_module_idents father a.ma_name)] + | Module_functor (p, k) -> + self#latex_of_module_parameter fmt father p; + self#latex_of_module_kind fmt father k + | Module_apply (k1, k2) -> + (* TODO: l'application n'est pas correcte dans un .mli. + Que faire ? -> afficher le module_type du typedtree *) + self#latex_of_module_kind fmt father k1; + self#latex_of_text fmt [Code "("]; + self#latex_of_module_kind fmt father k2; + self#latex_of_text fmt [Code ")"] + | Module_with (k, s) -> + (* TODO: à modifier quand Module_with sera plus détaillé *) + self#latex_of_module_type_kind fmt father k; + self#latex_of_text fmt + [ Code " "; + Code (self#relative_idents father s) ; + ] + | Module_constraint (k, tk) -> + (* TODO: on affiche quoi ? *) + self#latex_of_module_kind fmt father k + + method latex_of_class_kind fmt father kind = + match kind with + Class_structure (inh, eles) -> + self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; + self#generate_inheritance_info fmt inh; + List.iter (self#latex_of_class_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] + + | Class_apply capp -> + (* TODO: afficher le type final à partir du typedtree *) + self#latex_of_text fmt [Raw "class application not handled yet"] + + | Class_constr cco -> + ( + match cco.cco_type_parameters with + [] -> () + | l -> + self#latex_of_text fmt + ( + Code "[" :: + (self#text_of_class_type_param_expr_list father l) @ + [Code "] "] + ) + ); + self#latex_of_text fmt + [Code (self#relative_idents father cco.cco_name)] + + | Class_constraint (ck, ctk) -> + self#latex_of_text fmt [Code "( "] ; + self#latex_of_class_kind fmt father ck; + self#latex_of_text fmt [Code " : "] ; + self#latex_of_class_type_kind fmt father ctk; + self#latex_of_text fmt [Code " )"] + + method latex_of_class_type_kind fmt father kind = + match kind with + Class_type cta -> + ( + match cta.cta_type_parameters with + [] -> () + | l -> + self#latex_of_text fmt + (Code "[" :: + (self#text_of_class_type_param_expr_list father l) @ + [Code "] "] + ) + ); + self#latex_of_text fmt + [Code (self#relative_idents father cta.cta_name)] + + | Class_signature (inh, eles) -> + self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; + self#generate_inheritance_info fmt inh; + List.iter (self#latex_of_class_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] + + method latex_for_module_index fmt m = + let s_name = Name.simple m.m_name in + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] + + method latex_for_module_type_index fmt mt = + let s_name = Name.simple mt.mt_name in + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false (Name.simple s_name))^"`}\n" + ) + ] + + method latex_for_module_label fmt m = + ps fmt (self#make_label (self#module_label m.m_name)) + + method latex_for_module_type_label fmt mt = + ps fmt (self#make_label (self#module_type_label mt.mt_name)) + + + method latex_for_class_index fmt c = + let s_name = Name.simple c.cl_name in + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] + + method latex_for_class_type_index fmt ct = + let s_name = Name.simple ct.clt_name in + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] + + method latex_for_class_label fmt c = + ps fmt (self#make_label (self#class_label c.cl_name)) + + method latex_for_class_type_label fmt ct = + ps fmt (self#make_label (self#class_type_label ct.clt_name)) + + (** Print the LaTeX code for the given module. *) + method latex_of_module fmt m = + let father = Name.father m.m_name in + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code "module "; + Code (Name.simple m.m_name); + Code " : "; + ] + in + self#latex_of_text fmt t; + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_module_label fmt m; + self#latex_for_module_index fmt m; + p fmt "@["; + self#latex_of_module_kind fmt father m.m_kind; + ( + match Module.module_is_functor m with + false -> () + | true -> + self#latex_of_text fmt [Newline]; + ( + match List.filter (fun (_,d) -> d <> None) + (module_parameters ~trans: false m) + with + [] -> () + | l -> + let t = + [ Bold [Raw "Parameters: "]; + List + (List.map + (fun (p,text_opt) -> + let t = match text_opt with None -> [] | Some t -> t in + ( Raw p.mp_name :: Raw ": " :: t) + ) + l + ) + ] + in + self#latex_of_text fmt t + ); + ); + self#latex_of_text fmt [Newline]; + self#latex_of_info fmt ~block: true m.m_info; + p fmt "@]"; + + + (** Print the LaTeX code for the given module type. *) + method latex_of_module_type fmt mt = + let father = Name.father mt.mt_name in + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code "module type " ; + Code (Name.simple mt.mt_name); + ] + in + self#latex_of_text fmt t; + ( + match mt.mt_type, mt.mt_kind with + | Some mtyp, Some kind -> + self#latex_of_text fmt [ Code " = " ]; + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_module_type_label fmt mt; + self#latex_for_module_type_index fmt mt; + p fmt "@["; + self#latex_of_module_type_kind fmt father kind + | _ -> + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_module_type_index fmt mt; + p fmt "@["; + ); + ( + match Module.module_type_is_functor mt with + false -> () + | true -> + self#latex_of_text fmt [Newline]; + ( + match List.filter (fun (_,d) -> d <> None) + (module_type_parameters ~trans: false mt) + with + [] -> () + | l -> + let t = + [ Bold [Raw "Parameters: "]; + List + (List.map + (fun (p,text_opt) -> + let t = match text_opt with None -> [] | Some t -> t in + ( Raw p.mp_name :: Raw ": " :: t) + ) + l + ) + ] + in + self#latex_of_text fmt t + ); + ); + self#latex_of_text fmt [Newline]; + self#latex_of_info fmt ~block: true mt.mt_info; + p fmt "@]"; + + (** Print the LaTeX code for the given included module. *) + method latex_of_included_module fmt im = + self#latex_of_text fmt + ((Code "include ") :: + (Code + (match im.im_module with + None -> im.im_name + | Some (Mod m) -> m.m_name + | Some (Modtype mt) -> mt.mt_name) + ) :: + (self#text_of_info im.im_info) + ) + + (** Print the LaTeX code for the given class. *) + method latex_of_class fmt c = + Odoc_info.reset_type_names () ; + let father = Name.father c.cl_name in + let type_params = + match c.cl_type_parameters with + [] -> "" + | l -> (self#normal_class_type_param_list father l)^" " + in + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code (Printf.sprintf + "class %s%s%s : " + (if c.cl_virtual then "virtual " else "") + type_params + (Name.simple c.cl_name) + ) + ] + in + self#latex_of_text fmt t; + self#latex_of_class_parameter_list fmt father c; + (* avoid a big gap if the kind is a consrt *) + ( + match c.cl_kind with + Class.Class_constr _ -> + self#latex_of_class_kind fmt father c.cl_kind + | _ -> + () + ); + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_class_label fmt c; + self#latex_for_class_index fmt c; + p fmt "@["; + (match c.cl_kind with + Class.Class_constr _ -> () + | _ -> self#latex_of_class_kind fmt father c.cl_kind + ); + self#latex_of_text fmt [Newline]; + self#latex_of_info fmt ~block: true c.cl_info; + p fmt "@]" + + (** Print the LaTeX code for the given class type. *) + method latex_of_class_type fmt ct = + Odoc_info.reset_type_names () ; + let father = Name.father ct.clt_name in + let type_params = + match ct.clt_type_parameters with + [] -> "" + | l -> (self#normal_class_type_param_list father l)^" " + in + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code (Printf.sprintf + "class type %s%s%s = " + (if ct.clt_virtual then "virtual " else "") + type_params + (Name.simple ct.clt_name) + ) + ] + in + self#latex_of_text fmt t; + + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_class_type_label fmt ct; + self#latex_for_class_type_index fmt ct; + p fmt "@["; + self#latex_of_class_type_kind fmt father ct.clt_kind; + self#latex_of_text fmt [Newline]; + self#latex_of_info fmt ~block: true ct.clt_info; + p fmt "@]" + + (** Print the LaTeX code for the given class element. *) + method latex_of_class_element fmt class_name class_ele = + self#latex_of_text fmt [Newline]; + match class_ele with + Class_attribute att -> self#latex_of_attribute fmt att + | Class_method met -> self#latex_of_method fmt met + | Class_comment t -> + match t with + | [] -> () + | (Title (_,_,_)) :: _ -> self#latex_of_text fmt t + | _ -> self#latex_of_text fmt [ Title ((Name.depth class_name) + 2, None, t) ] + + (** Print the LaTeX code for the given module element. *) + method latex_of_module_element fmt module_name module_ele = + self#latex_of_text fmt [Newline]; + match module_ele with + Element_module m -> self#latex_of_module fmt m + | Element_module_type mt -> self#latex_of_module_type fmt mt + | Element_included_module im -> self#latex_of_included_module fmt im + | Element_class c -> self#latex_of_class fmt c + | Element_class_type ct -> self#latex_of_class_type fmt ct + | Element_value v -> self#latex_of_value fmt v + | Element_exception e -> self#latex_of_exception fmt e + | Element_type t -> self#latex_of_type fmt t + | Element_module_comment t -> self#latex_of_text fmt t + + (** Generate the LaTeX code for the given list of inherited classes.*) + method generate_inheritance_info fmt inher_l = + let f inh = + match inh.ic_class with + None -> (* we can't make the reference *) + Newline :: + Code ("inherit "^inh.ic_name) :: + (match inh.ic_text with + None -> [] + | Some t -> Newline :: t + ) + | Some cct -> + let label = + match cct with + Cl _ -> self#class_label inh.ic_name + | Cltype _ -> self#class_type_label inh.ic_name + in + (* we can create the reference *) + Newline :: + Odoc_info.Code ("inherit "^inh.ic_name) :: + (Odoc_info.Latex (" ["^(self#make_ref label)^"]")) :: + (match inh.ic_text with + None -> [] + | Some t -> Newline :: t + ) + in + List.iter (self#latex_of_text fmt) (List.map f inher_l) + + (** Generate the LaTeX code for the inherited classes of the given class. *) + method generate_class_inheritance_info fmt cl = + let rec iter_kind k = + match k with + Class_structure ([], _) -> + () + | Class_structure (l, _) -> + self#generate_inheritance_info fmt l + | Class_constraint (k, _) -> + iter_kind k + | Class_apply _ + | Class_constr _ -> + () + in + iter_kind cl.cl_kind + + (** Generate the LaTeX code for the inherited classes of the given class type. *) + method generate_class_type_inheritance_info fmt clt = + match clt.clt_kind with + Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info fmt l + | Class_type _ -> + () + + (** Generate the LaTeX code for the given top module, in the given buffer. *) + method generate_for_top_module fmt m = + let (first_t, rest_t) = self#first_and_rest_of_info m.m_info in + let text = + if m.m_text_only then + [ Title (1, None, [Raw m.m_name] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t) + ) ; + ] + else + [ Title (1, None, + [ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + ] + in + self#latex_of_text fmt text; + self#latex_for_module_label fmt m; + self#latex_for_module_index fmt m; + self#latex_of_text fmt rest_t ; + + self#latex_of_text fmt [ Newline ] ; + if not m.m_text_only then ps fmt "\\ocamldocvspace{0.5cm}\n\n"; + List.iter + (fun ele -> + self#latex_of_module_element fmt m.m_name ele; + ps fmt "\n\n" + ) + (Module.module_elements ~trans: false m) + + (** Print the header of the TeX document. *) + method latex_header fmt module_list = + ps fmt "\\documentclass[11pt]{article} \n"; + ps fmt "\\usepackage[latin1]{inputenc} \n"; + ps fmt "\\usepackage[T1]{fontenc} \n"; + ps fmt "\\usepackage{fullpage} \n"; + ps fmt "\\usepackage{url} \n"; + ps fmt "\\usepackage{ocamldoc}\n"; + ( + match !Args.title with + None -> () + | Some s -> + ps fmt "\\title{"; + ps fmt (self#escape s); + ps fmt "}\n" + ); + ps fmt "\\begin{document}\n"; + (match !Args.title with + None -> () | + Some _ -> ps fmt "\\maketitle\n" + ); + if !Args.with_toc then ps fmt "\\tableofcontents\n"; + ( + let info = Odoc_info.apply_opt + (Odoc_info.info_of_comment_file module_list) + !Odoc_info.Args.intro_file + in + (match info with None -> () | Some _ -> ps fmt "\\vspace{0.2cm}"); + self#latex_of_info fmt info; + (match info with None -> () | Some _ -> ps fmt "\n\n") + ) + + + (** Generate the LaTeX style file, if it does not exists. *) + method generate_style_file = + try + let dir = Filename.dirname !Args.out_file in + let file = Filename.concat dir "ocamldoc.sty" in + if Sys.file_exists file then + Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) + else + ( + let chanout = open_out file in + output_string chanout Odoc_latex_style.content ; + flush chanout ; + close_out chanout; + Odoc_info.verbose (Odoc_messages.file_generated file) + ) + with + Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors ; + + (** Generate the LaTeX file from a module list, in the {!Odoc_info.Args.out_file} file. *) + method generate module_list = + self#generate_style_file ; + let main_file = !Args.out_file in + let dir = Filename.dirname main_file in + if !Args.separate_files then + ( + let f m = + try + let chanout = + open_out ((Filename.concat dir (Name.simple m.m_name))^".tex") + in + let fmt = Format.formatter_of_out_channel chanout in + self#generate_for_top_module fmt m ; + Format.pp_print_flush fmt (); + close_out chanout + with + Failure s + | Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors + in + List.iter f module_list + ); + + try + let chanout = open_out main_file in + let fmt = Format.formatter_of_out_channel chanout in + if !Args.with_header then self#latex_header fmt module_list; + List.iter + (fun m -> + if !Args.separate_files then + ps fmt ("\\input{"^((Name.simple m.m_name))^".tex}\n") + else + self#generate_for_top_module fmt m + ) + module_list ; + if !Args.with_trailer then ps fmt "\\end{document}"; + Format.pp_print_flush fmt (); + close_out chanout + with + Failure s + | Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors + end diff --git a/ocamldoc/odoc_latex_style.ml b/ocamldoc/odoc_latex_style.ml new file mode 100644 index 0000000..1a7c432 --- /dev/null +++ b/ocamldoc/odoc_latex_style.ml @@ -0,0 +1,92 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(** The content of the LaTeX style to generate when generating LaTeX code. *) + +(* $Id: odoc_latex_style.ml,v 1.5 2004-06-11 14:25:50 guesdon Exp $ *) + +let content =" +%% Support macros for LaTeX documentation generated by ocamldoc. +%% This file is in the public domain; do what you want with it. + +\\NeedsTeXFormat{LaTeX2e} +\\ProvidesPackage{ocamldoc} + [2001/12/04 v1.0 ocamldoc support] + +\\newenvironment{ocamldoccode}{% + \\bgroup + \\leftskip\\@totalleftmargin + \\rightskip\\z@skip + \\parindent\\z@ + \\parfillskip\\@flushglue + \\parskip\\z@skip + %\\noindent + \\@@par\\smallskip + \\@tempswafalse + \\def\\par{% + \\if@tempswa + \\leavevmode\\null\\@@par\\penalty\\interlinepenalty + \\else + \\@tempswatrue + \\ifhmode\\@@par\\penalty\\interlinepenalty\\fi + \\fi} + \\obeylines + \\verbatim@font + \\let\\org@prime~% + \\@noligs + \\let\\org@dospecials\\dospecials + \\g@remfrom@specials{\\\\} + \\g@remfrom@specials{\\{} + \\g@remfrom@specials{\\}} + \\let\\do\\@makeother + \\dospecials + \\let\\dospecials\\org@dospecials + \\frenchspacing\\@vobeyspaces + \\everypar \\expandafter{\\the\\everypar \\unpenalty}} +{\\egroup\\par} + +\\def\\g@remfrom@specials#1{% + \\def\\@new@specials{} + \\def\\@remove##1{% + \\ifx##1#1\\else + \\g@addto@macro\\@new@specials{\\do ##1}\\fi} + \\let\\do\\@remove\\dospecials + \\let\\dospecials\\@new@specials + } + +\\newenvironment{ocamldocdescription} +{\\list{}{\\rightmargin0pt \\topsep0pt}\\raggedright\\item\\noindent\\relax\\ignorespaces} +{\\endlist\\medskip} + +\\newenvironment{ocamldoccomment} +{\\list{}{\\leftmargin 2\\leftmargini \\rightmargin0pt \\topsep0pt}\\raggedright\\item\\noindent\\relax} +{\\endlist} + +\\let \\ocamldocparagraph \\paragraph +\\def \\paragraph #1{\\ocamldocparagraph {#1}\\noindent} +\\let \\ocamldocsubparagraph \\subparagraph +\\def \\subparagraph #1{\\ocamldocsubparagraph {#1}\\noindent} + +\\let\\ocamldocvspace\\vspace + +\\newenvironment{ocamldocindent}{\\list{}{}\\item\\relax}{\\endlist} +\\newenvironment{ocamldocsigend} + {\\noindent\\quad\\texttt{sig}\\ocamldocindent} + {\\endocamldocindent\\vskip -\\lastskip + \\noindent\\quad\\texttt{end}\\medskip} +\\newenvironment{ocamldocobjectend} + {\\noindent\\quad\\texttt{object}\\ocamldocindent} + {\\endocamldocindent\\vskip -\\lastskip + \\noindent\\quad\\texttt{end}\\medskip} + +\\endinput +" + diff --git a/ocamldoc/odoc_lexer.mll b/ocamldoc/odoc_lexer.mll new file mode 100644 index 0000000..1a849e1 --- /dev/null +++ b/ocamldoc/odoc_lexer.mll @@ -0,0 +1,412 @@ +{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_lexer.mll,v 1.5 2008-07-23 11:14:22 guesdon Exp $ *) + +(** The lexer for special comments. *) + +open Lexing +open Odoc_parser + +let line_number = ref 0 + + +let string_buffer = Buffer.create 32 + +(** Fonction de remise à zéro de la chaine de caractères tampon *) +let reset_string_buffer () = Buffer.reset string_buffer + +(** Fonction d'ajout d'un caractère dans la chaine de caractères tampon *) +let ajout_char_string = Buffer.add_char string_buffer + +(** Add a string to the buffer. *) +let ajout_string = Buffer.add_string string_buffer + +let lecture_string () = Buffer.contents string_buffer + +(** The variable which will contain the description string. + Is initialized when we encounter the start of a special comment. *) +let description = ref "" + +let blank = "[ \013\009\012]" + +(** The nested comments level. *) +let comments_level = ref 0 + +let print_DEBUG2 s = print_string s; print_newline () + +(** This function returns the given string without the leading and trailing blanks.*) +let remove_blanks s = + print_DEBUG2 ("remove_blanks "^s); + let l = Str.split_delim (Str.regexp "\n") s in + let l2 = + let rec iter liste = + match liste with + h :: q -> + let h2 = Str.global_replace (Str.regexp ("^"^blank^"+")) "" h in + if h2 = "" then + ( + print_DEBUG2 (h^" n'a que des blancs"); + (* we remove this line and must remove leading blanks of the next one *) + iter q + ) + else + (* we don't remove leading blanks in the remaining lines *) + h2 :: q + | _ -> + [] + in iter l + in + let l3 = + let rec iter liste = + match liste with + h :: q -> + let h2 = Str.global_replace (Str.regexp (blank^"+$")) "" h in + if h2 = "" then + ( + print_DEBUG2 (h^" n'a que des blancs"); + (* we remove this line and must remove trailing blanks of the next one *) + iter q + ) + else + (* we don't remove trailing blanks in the remaining lines *) + h2 :: q + | _ -> + [] + in + List.rev (iter (List.rev l2)) + in + String.concat "\n" l3 + +(** Remove first blank characters of each line of a string, until the first '*' *) +let remove_stars s = + let s2 = Str.global_replace (Str.regexp ("^"^blank^"*\\*")) "" s in + s2 +} + +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] + +rule main = parse + [' ' '\013' '\009' '\012'] + + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + main lexbuf + } + + | [ '\010' ] + { + incr line_number; + incr Odoc_comments_global.nb_chars; + main lexbuf + } + | "(**)" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + Description ("", None) + } + + | "(**"("*"+)")" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + main lexbuf + } + + | "(***" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + main lexbuf + } + + | "(**" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + if !comments_level = 1 then + ( + reset_string_buffer (); + description := ""; + special_comment lexbuf + ) + else + main lexbuf + } + + | eof + { EOF } + + | "*)" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + decr comments_level ; + main lexbuf + } + + | "(*" + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level ; + main lexbuf + } + + | _ + { + incr Odoc_comments_global.nb_chars; + main lexbuf + } + +and special_comment = parse + | "*)" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + if !comments_level = 1 then + ( + (* there is just a description *) + let s2 = lecture_string () in + let s3 = remove_blanks s2 in + let s4 = + if !Odoc_args.remove_stars then + remove_stars s3 + else + s3 + in + Description (s4, None) + ) + else + ( + ajout_string s; + decr comments_level; + special_comment lexbuf + ) + } + + | "(*" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level ; + ajout_string s; + special_comment lexbuf + } + + | "\\@" + { + let s = Lexing.lexeme lexbuf in + let c = (Lexing.lexeme_char lexbuf 1) in + ajout_char_string c; + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + special_comment lexbuf + } + + | "@"lowercase+ + { + (* we keep the description before we go further *) + let s = lecture_string () in + description := remove_blanks s; + reset_string_buffer (); + let len = String.length (Lexing.lexeme lexbuf) in + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - len; + lexbuf.Lexing.lex_curr_p <- + { lexbuf.Lexing.lex_curr_p with + pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - len + } ; + (* we don't increment the Odoc_comments_global.nb_chars *) + special_comment_part2 lexbuf + } + + | _ + { + let c = (Lexing.lexeme_char lexbuf 0) in + ajout_char_string c; + if c = '\010' then incr line_number; + incr Odoc_comments_global.nb_chars; + special_comment lexbuf + } + +and special_comment_part2 = parse + | "*)" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + if !comments_level = 1 then + (* finally we return the description we kept *) + let desc = + if !Odoc_args.remove_stars then + remove_stars !description + else + !description + in + let remain = lecture_string () in + let remain2 = + if !Odoc_args.remove_stars then + remove_stars remain + else + remain + in + Description (desc, Some remain2) + else + ( + ajout_string s ; + decr comments_level ; + special_comment_part2 lexbuf + ) + } + + | "(*" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + ajout_string s; + incr comments_level ; + special_comment_part2 lexbuf + } + + | _ + { + let c = (Lexing.lexeme_char lexbuf 0) in + ajout_char_string c; + if c = '\010' then incr line_number; + incr Odoc_comments_global.nb_chars; + special_comment_part2 lexbuf + } + +and elements = parse + | [' ' '\013' '\009' '\012'] + + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + elements lexbuf + } + + | [ '\010' ] + { incr line_number; + incr Odoc_comments_global.nb_chars; + print_DEBUG2 "newline"; + elements lexbuf } + + | "@"lowercase+ + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + let s2 = String.sub s 1 ((String.length s) - 1) in + print_DEBUG2 s2; + match s2 with + "param" -> + T_PARAM + | "author" -> + T_AUTHOR + | "version" -> + T_VERSION + | "see" -> + T_SEE + | "since" -> + T_SINCE + | "deprecated" -> + T_DEPRECATED + | "raise" -> + T_RAISES + | "return" -> + T_RETURN + | s -> + if !Odoc_args.no_custom_tags then + raise (Failure (Odoc_messages.not_a_valid_tag s)) + else + T_CUSTOM s + } + + | ("\\@" | [^'@'])+ + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + let s = Lexing.lexeme lexbuf in + let s = Str.global_replace (Str.regexp_string "\\@") "@" s in + let s = remove_blanks s in + print_DEBUG2 ("Desc "^s); + Desc s + } + | eof + { + EOF + } + + +and simple = parse + [' ' '\013' '\009' '\012'] + + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + simple lexbuf + } + + | [ '\010' ] + { incr line_number; + incr Odoc_comments_global.nb_chars; + simple lexbuf + } + + | "(**"("*"+) + { + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length (Lexing.lexeme lexbuf)); + incr comments_level; + simple lexbuf + } + + | "(*"("*"+)")" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + simple lexbuf + } + | "(**" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level; + simple lexbuf + } + + | "(*" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + incr comments_level; + if !comments_level = 1 then + ( + reset_string_buffer (); + description := ""; + special_comment lexbuf + ) + else + ( + ajout_string s; + simple lexbuf + ) + } + + | eof + { EOF } + + | "*)" + { + let s = Lexing.lexeme lexbuf in + Odoc_comments_global.nb_chars := !Odoc_comments_global.nb_chars + (String.length s); + decr comments_level ; + simple lexbuf + } + + | _ + { + incr Odoc_comments_global.nb_chars; + simple lexbuf + } + diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml new file mode 100644 index 0000000..66e3bac --- /dev/null +++ b/ocamldoc/odoc_man.ml @@ -0,0 +1,1057 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_man.ml,v 1.30 2008-12-03 18:09:09 doligez Exp $ *) + +(** The man pages generator. *) +open Odoc_info +open Parameter +open Value +open Type +open Exception +open Class +open Module +open Search + +let new_buf () = Buffer.create 1024 +let bp = Printf.bprintf +let bs = Buffer.add_string + +(** A class used to get a [text] for info structures. *) +class virtual info = + object (self) + (** The list of pairs [(tag, f)] where [f] is a function taking + the [text] associated to [tag] and returning man code. + Add a pair here to handle a tag.*) + val mutable tag_functions = ([] : (string * (Odoc_info.text -> string)) list) + + (** Return man code for a [text]. *) + method virtual man_of_text : Buffer.t -> Odoc_info.text -> unit + + (** Print groff string for an author list. *) + method man_of_author_list b l = + match l with + [] -> () + | _ -> + bs b ".B \""; + bs b Odoc_messages.authors; + bs b "\"\n:\n"; + bs b (String.concat ", " l); + bs b "\n.sp\n" + + (** Print groff string for the given optional version information.*) + method man_of_version_opt b v_opt = + match v_opt with + None -> () + | Some v -> + bs b ".B \""; + bs b Odoc_messages.version; + bs b "\"\n:\n"; + bs b v; + bs b "\n.sp\n" + + (** Print groff string for the given optional since information.*) + method man_of_since_opt b s_opt = + match s_opt with + None -> () + | Some s -> + bs b ".B \""; + bs b Odoc_messages.since; + bs b "\"\n"; + bs b s; + bs b "\n.sp\n" + + (** Print groff string for the given list of raised exceptions.*) + method man_of_raised_exceptions b l = + match l with + [] -> () + | (s, t) :: [] -> + bs b ".B \""; + bs b Odoc_messages.raises; + bs b (" "^s^"\"\n"); + self#man_of_text b t; + bs b "\n.sp\n" + | _ -> + bs b ".B \""; + bs b Odoc_messages.raises; + bs b "\"\n"; + List.iter + (fun (ex, desc) -> + bs b ".sp\n.B \""; + bs b ex; + bs b "\"\n"; + self#man_of_text b desc; + bs b "\n" + ) + l; + bs b "\n.sp\n" + + (** Print groff string for the given "see also" reference. *) + method man_of_see b (see_ref, t) = + let t_ref = + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + in + self#man_of_text b t_ref + + (** Print groff string for the given list of "see also" references.*) + method man_of_sees b l = + match l with + [] -> () + | see :: [] -> + bs b ".B \""; + bs b Odoc_messages.see_also; + bs b "\"\n"; + self#man_of_see b see; + bs b "\n.sp\n" + | _ -> + bs b ".B \""; + bs b Odoc_messages.see_also; + bs b "\"\n"; + List.iter + (fun see -> + bs b ".sp\n"; + self#man_of_see b see; + bs b "\n" + ) + l; + bs b "\n.sp\n" + + (** Print groff string for the given optional return information.*) + method man_of_return_opt b return_opt = + match return_opt with + None -> () + | Some s -> + bs b ".B "; + bs b Odoc_messages.returns; + bs b "\n"; + self#man_of_text b s; + bs b "\n.sp\n" + + (** Print man code for the given list of custom tagged texts. *) + method man_of_custom b l = + let buf = Buffer.create 50 in + List.iter + (fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + Buffer.add_string buf (f text) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) + ) + l + + (** Print the groff string to display an optional info structure. *) + method man_of_info b info_opt = + match info_opt with + None -> () + | Some info -> + let module M = Odoc_info in + ( + match info.M.i_deprecated with + None -> () + | Some d -> + bs b ".B \""; + bs b Odoc_messages.deprecated; + bs b "\"\n"; + self#man_of_text b d; + bs b "\n.sp\n" + ); + ( + match info.M.i_desc with + None -> () + | Some d when d = [Odoc_info.Raw ""] -> () + | Some d -> + self#man_of_text b d; + bs b "\n.sp\n" + ); + self#man_of_author_list b info.M.i_authors; + self#man_of_version_opt b info.M.i_version; + self#man_of_since_opt b info.M.i_since; + self#man_of_raised_exceptions b info.M.i_raised_exceptions; + self#man_of_return_opt b info.M.i_return_value; + self#man_of_sees b info.M.i_sees; + self#man_of_custom b info.M.i_custom + end + +(** This class is used to create objects which can generate a simple html documentation. *) +class man = + let re_slash = Str.regexp_string "/" in + object (self) + inherit info + + (** Get a file name from a complete name. *) + method file_name name = + let s = Printf.sprintf "%s.%s" name !Args.man_suffix in + Str.global_replace re_slash "slash" s + + (** Escape special sequences of characters in a string. *) + method escape (s : string) = + let len = String.length s in + let b = Buffer.create len in + for i = 0 to len - 1 do + match s.[i] with + '\\' -> Buffer.add_string b "\\(rs" + | '.' -> Buffer.add_string b "\\&." + | '\'' -> Buffer.add_string b "\\&'" + | '-' -> Buffer.add_string b "\\-" + | c -> Buffer.add_char b c + done; + Buffer.contents b + + (** Open a file for output. Add the target directory.*) + method open_out file = + let f = Filename.concat !Args.target_dir file in + open_out f + + (** Print groff string for a text, without correction of blanks. *) + method private man_of_text2 b t = + List.iter (self#man_of_text_element b) t + + (** Print the groff string for a text, with blanks corrected. *) + method man_of_text b t = + let b2 = new_buf () in + self#man_of_text2 b2 t ; + let s = Buffer.contents b2 in + let s2 = Str.global_replace (Str.regexp "\n[ ]*") "\n" s in + bs b (Str.global_replace (Str.regexp "\n\n") "\n" s2) + + (** Return the given string without no newlines. *) + method remove_newlines s = + Str.global_replace (Str.regexp "[ ]*\n[ ]*") " " s + + (** Print the groff string for a text element. *) + method man_of_text_element b te = + match te with + | Odoc_info.Raw s -> bs b (self#escape s) + | Odoc_info.Code s -> + bs b "\n.B "; + bs b ((Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n") + | Odoc_info.CodePre s -> + bs b "\n.B "; + bs b ((Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n") + | Odoc_info.Verbatim s -> + bs b (self#escape s) + | Odoc_info.Bold t + | Odoc_info.Italic t + | Odoc_info.Emphasize t + | Odoc_info.Center t + | Odoc_info.Left t + | Odoc_info.Right t -> + self#man_of_text2 b t + | Odoc_info.List tl -> + List.iter + (fun t -> bs b "\n.sp\n \\-"; self#man_of_text2 b t; bs b "\n") + tl; + bs b "\n" + | Odoc_info.Enum tl -> + List.iter + (fun t -> bs b "\n.sp\n \\-"; self#man_of_text2 b t; bs b "\n") + tl; + bs b "\n" + | Odoc_info.Newline -> + bs b "\n.sp\n" + | Odoc_info.Block t -> + bs b "\n.sp\n"; + self#man_of_text2 b t; + bs b "\n.sp\n" + | Odoc_info.Title (n, l_opt, t) -> + self#man_of_text2 b [Odoc_info.Code (Odoc_info.string_of_text t)] + | Odoc_info.Latex _ -> + (* don't care about LaTeX stuff in HTML. *) + () + | Odoc_info.Link (s, t) -> + self#man_of_text2 b t + | Odoc_info.Ref (name, _) -> + self#man_of_text_element b + (Odoc_info.Code (Odoc_info.use_hidden_modules name)) + | Odoc_info.Superscript t -> + bs b "^{"; self#man_of_text2 b t + | Odoc_info.Subscript t -> + bs b "_{"; self#man_of_text2 b t + | Odoc_info.Module_list _ -> + () + | Odoc_info.Index_list -> + () + | Odoc_info.Custom (s,t) -> self#man_of_custom_text b s t + + method man_of_custom_text b s t = () + + (** Print groff string to display code. *) + method man_of_code b s = self#man_of_text b [ Code s ] + + (** Take a string and return the string where fully qualified idents + have been replaced by idents relative to the given module name.*) + method relative_idents m_name s = + let f str_t = + let match_s = Str.matched_string str_t in + Odoc_info.apply_if_equal + Odoc_info.use_hidden_modules + match_s + (Name.get_relative m_name match_s) + in + let s2 = Str.global_substitute + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s + in + s2 + + (** Print groff string to display a [Types.type_expr].*) + method man_of_type_expr b m_name t = + let s = String.concat "\n" + (Str.split (Str.regexp "\n") (Odoc_print.string_of_type_expr t)) + in + let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in + bs b "\n.B "; + bs b (self#relative_idents m_name s2); + bs b "\n" + + (** Print groff string to display a [Types.class_type].*) + method man_of_class_type_expr b m_name t = + let s = String.concat "\n" + (Str.split (Str.regexp "\n") (Odoc_print.string_of_class_type t)) + in + let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in + bs b "\n.B "; + bs b (self#relative_idents m_name s2); + bs b "\n" + + (** Print groff string to display a [Types.type_expr list].*) + method man_of_type_expr_list ?par b m_name sep l = + let s = Odoc_str.string_of_type_list ?par sep l in + let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in + bs b "\n.B "; + bs b (self#relative_idents m_name s2); + bs b "\n" + + (** Print groff string to display the parameters of a type.*) + method man_of_type_expr_param_list b m_name t = + match t.ty_parameters with + [] -> () + | l -> + let s = Odoc_str.string_of_type_param_list t in + let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in + bs b "\n.B "; + bs b (self#relative_idents m_name s2); + bs b "\n" + + (** Print groff string to display a [Types.module_type]. *) + method man_of_module_type b m_name t = + let s = String.concat "\n" + (Str.split (Str.regexp "\n") (Odoc_print.string_of_module_type t)) + in + let s2 = Str.global_replace (Str.regexp "\n") "\n.B " s in + bs b "\n.B "; + bs b (self#relative_idents m_name s2); + bs b "\n" + + (** Print groff string code for a value. *) + method man_of_value b v = + Odoc_info.reset_type_names () ; + bs b "\n.I val "; + bs b (Name.simple v.val_name); + bs b " \n: "; + self#man_of_type_expr b (Name.father v.val_name) v.val_type; + bs b ".sp\n"; + self#man_of_info b v.val_info; + bs b "\n.sp\n" + + (** Print groff string code for an exception. *) + method man_of_exception b e = + Odoc_info.reset_type_names () ; + bs b "\n.I exception "; + bs b (Name.simple e.ex_name); + bs b " \n"; + ( + match e.ex_args with + [] -> () + | _ -> + bs b ".B of "; + self#man_of_type_expr_list + ~par: false + b (Name.father e.ex_name) " * " e.ex_args + ); + ( + match e.ex_alias with + None -> () + | Some ea -> + bs b " = "; + bs b + ( + match ea.ea_ex with + None -> ea.ea_name + | Some e -> e.ex_name + ) + ); + bs b "\n.sp\n"; + self#man_of_info b e.ex_info; + bs b "\n.sp\n" + + (** Print groff string for a type. *) + method man_of_type b t = + Odoc_info.reset_type_names () ; + let father = Name.father t.ty_name in + bs b ".I type "; + self#man_of_type_expr_param_list b father t; + ( + match t.ty_parameters with + [] -> () + | _ -> bs b ".I " + ); + bs b (Name.simple t.ty_name); + bs b " \n"; + let priv = t.ty_private = Asttypes.Private in + ( + match t.ty_manifest with + None -> () + | Some typ -> + bs b "= "; + if priv then bs b "private "; + self#man_of_type_expr b father typ + ); + ( + match t.ty_kind with + Type_abstract -> () + | Type_variant l -> + bs b "="; + if priv then bs b " private"; + bs b "\n "; + List.iter + (fun constr -> + bs b ("| "^constr.vc_name); + ( + match constr.vc_args, constr.vc_text with + [], None -> bs b "\n " + | [], (Some t) -> + bs b " (* "; + self#man_of_text b t; + bs b " *)\n " + | l, None -> + bs b "\n.B of "; + self#man_of_type_expr_list ~par: false b father " * " l; + bs b " " + | l, (Some t) -> + bs b "\n.B of "; + self#man_of_type_expr_list ~par: false b father " * " l; + bs b ".I \" \"\n"; + bs b "(* "; + self#man_of_text b t; + bs b " *)\n " + ) + ) + l + | Type_record l -> + bs b "= "; + if priv then bs b "private "; + bs b "{"; + List.iter + (fun r -> + bs b (if r.rf_mutable then "\n\n.B mutable \n" else "\n "); + bs b (r.rf_name^" : "); + self#man_of_type_expr b father r.rf_type; + bs b ";"; + ( + match r.rf_text with + None -> () + | Some t -> + bs b " (* "; + self#man_of_text b t; + bs b " *) " + ); + ) + l; + bs b "\n }\n" + ); + bs b "\n.sp\n"; + self#man_of_info b t.ty_info; + bs b "\n.sp\n" + + (** Print groff string for a class attribute. *) + method man_of_attribute b a = + bs b ".I val "; + if a.att_virtual then bs b ("virtual "); + if a.att_mutable then bs b (Odoc_messages.mutab^" "); + bs b ((Name.simple a.att_value.val_name)^" : "); + self#man_of_type_expr b (Name.father a.att_value.val_name) a.att_value.val_type; + bs b "\n.sp\n"; + self#man_of_info b a.att_value.val_info; + bs b "\n.sp\n" + + (** Print groff string for a class method. *) + method man_of_method b m = + bs b ".I method "; + if m.met_private then bs b "private "; + if m.met_virtual then bs b "virtual "; + bs b ((Name.simple m.met_value.val_name)^" : "); + self#man_of_type_expr b + (Name.father m.met_value.val_name) m.met_value.val_type; + bs b "\n.sp\n"; + self#man_of_info b m.met_value.val_info; + bs b "\n.sp\n" + + (** Groff for a list of parameters. *) + method man_of_parameter_list b m_name l = + match l with + [] -> () + | _ -> + bs b "\n.B "; + bs b Odoc_messages.parameters; + bs b ": \n"; + List.iter + (fun p -> + bs b ".sp\n"; + bs b "\""; + bs b (Parameter.complete_name p); + bs b "\"\n"; + self#man_of_type_expr b m_name (Parameter.typ p); + bs b "\n"; + self#man_of_parameter_description b p; + bs b "\n" + ) + l; + bs b "\n" + + (** Groff for the description of a function parameter. *) + method man_of_parameter_description b p = + match Parameter.names p with + [] -> () + | name :: [] -> + ( + (* Only one name, no need for label for the description. *) + match Parameter.desc_by_name p name with + None -> () + | Some t -> bs b "\n "; self#man_of_text b t + ) + | l -> + (* A list of names, we display those with a description. *) + List.iter + (fun n -> + match Parameter.desc_by_name p n with + None -> () + | Some t -> + self#man_of_code b (n^" : "); + self#man_of_text b t + ) + l + + (** Print groff string for a list of module parameters. *) + method man_of_module_parameter_list b m_name l = + match l with + [] -> () + | _ -> + bs b ".B \""; + bs b Odoc_messages.parameters; + bs b ":\"\n"; + List.iter + (fun (p, desc_opt) -> + bs b ".sp\n"; + bs b ("\""^p.mp_name^"\"\n"); + self#man_of_module_type b m_name p.mp_type; + bs b "\n"; + ( + match desc_opt with + None -> () + | Some t -> self#man_of_text b t + ); + bs b "\n" + ) + l; + bs b "\n\n" + + (** Print groff string for a class. *) + method man_of_class b c = + Odoc_info.reset_type_names () ; + let father = Name.father c.cl_name in + bs b ".I class "; + if c.cl_virtual then bs b "virtual "; + ( + match c.cl_type_parameters with + [] -> () + | l -> + bs b (Odoc_str.string_of_class_type_param_list l); + bs b " " + ); + bs b (Name.simple c.cl_name); + bs b " : " ; + self#man_of_class_type_expr b father c.cl_type; + bs b "\n.sp\n"; + self#man_of_info b c.cl_info; + bs b "\n.sp\n" + + (** Print groff string for a class type. *) + method man_of_class_type b ct = + Odoc_info.reset_type_names () ; + bs b ".I class type "; + if ct.clt_virtual then bs b "virtual " ; + ( + match ct.clt_type_parameters with + [] -> () + | l -> + bs b (Odoc_str.string_of_class_type_param_list l); + bs b " " + ); + bs b (Name.simple ct.clt_name); + bs b " = " ; + self#man_of_class_type_expr b (Name.father ct.clt_name) ct.clt_type; + bs b "\n.sp\n"; + self#man_of_info b ct.clt_info; + bs b "\n.sp\n" + + (** Print groff string for a module. *) + method man_of_module b m = + bs b ".I module "; + bs b (Name.simple m.m_name); + bs b " : "; + self#man_of_module_type b (Name.father m.m_name) m.m_type; + bs b "\n.sp\n"; + self#man_of_info b m.m_info; + bs b "\n.sp\n" + + (** Print groff string for a module type. *) + method man_of_modtype b mt = + bs b ".I module type "; + bs b (Name.simple mt.mt_name); + bs b " = "; + (match mt.mt_type with + None -> () + | Some t -> + self#man_of_module_type b (Name.father mt.mt_name) t + ); + bs b "\n.sp\n"; + self#man_of_info b mt.mt_info; + bs b "\n.sp\n" + + (** Print groff string for a module comment.*) + method man_of_module_comment b text = + bs b "\n.PP\n"; + self#man_of_text b [Code ("=== "^(Odoc_misc.string_of_text text)^" ===")]; + bs b "\n.PP\n" + + (** Print groff string for a class comment.*) + method man_of_class_comment b text = + bs b "\n.PP\n"; + self#man_of_text b [Code ("=== "^(Odoc_misc.string_of_text text)^" ===")]; + bs b "\n.PP\n" + + (** Print groff string for an included module. *) + method man_of_included_module b m_name im = + bs b ".I include "; + ( + match im.im_module with + None -> bs b im.im_name + | Some mmt -> + let name = + match mmt with + Mod m -> m.m_name + | Modtype mt -> mt.mt_name + in + bs b (self#relative_idents m_name name) + ); + bs b "\n.sp\n"; + self#man_of_info b im.im_info; + bs b "\n.sp\n" + + (** Generate the man page for the given class.*) + method generate_for_class cl = + Odoc_info.reset_type_names () ; + let date = Unix.time () in + let file = self#file_name cl.cl_name in + try + let chanout = self#open_out file in + let b = new_buf () in + bs b (".TH \""^cl.cl_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" "); + bs b "OCamldoc "; + bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); + + let abstract = + match cl.cl_info with + None | Some { i_desc = None } -> "no description" + | Some { i_desc = Some t } -> + let s = Odoc_info.string_of_text (Odoc_info.first_sentence_of_text t) in + self#remove_newlines s + in + + bs b ".SH NAME\n"; + bs b (cl.cl_name^" \\- "^abstract^"\n"); + bs b (".SH "^Odoc_messages.clas^"\n"); + bs b (Odoc_messages.clas^" "^cl.cl_name^"\n"); + bs b (".SH "^Odoc_messages.documentation^"\n"); + bs b ".sp\n"; + self#man_of_class b cl; + + (* parameters *) + self#man_of_parameter_list b "" cl.cl_parameters; + (* a large blank *) + bs b "\n.sp\n.sp\n"; + +(* + (* class inheritance *) + self#generate_class_inheritance_info chanout cl; +*) + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + self#man_of_attribute b a + | Class_method m -> + self#man_of_method b m + | Class_comment t -> + self#man_of_class_comment b t + ) + (Class.class_elements cl); + + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s + + (** Generate the man page for the given class type.*) + method generate_for_class_type ct = + Odoc_info.reset_type_names () ; + let date = Unix.time () in + let file = self#file_name ct.clt_name in + try + let chanout = self#open_out file in + let b = new_buf () in + bs b (".TH \""^ct.clt_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" "); + bs b "OCamldoc "; + bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); + + let abstract = + match ct.clt_info with + None | Some { i_desc = None } -> "no description" + | Some { i_desc = Some t } -> + let s = Odoc_info.string_of_text (Odoc_info.first_sentence_of_text t) in + self#remove_newlines s + in + + bs b ".SH NAME\n"; + bs b (ct.clt_name^" \\- "^abstract^"\n"); + bs b (".SH "^Odoc_messages.class_type^"\n"); + bs b (Odoc_messages.class_type^" "^ct.clt_name^"\n"); + bs b (".SH "^Odoc_messages.documentation^"\n"); + bs b ".sp\n"; + + self#man_of_class_type b ct; + + (* a large blank *) + bs b "\n.sp\n.sp\n"; +(* + (* class inheritance *) + self#generate_class_inheritance_info chanout cl; +*) + (* the various elements *) + List.iter + (fun element -> + match element with + Class_attribute a -> + self#man_of_attribute b a + | Class_method m -> + self#man_of_method b m + | Class_comment t -> + self#man_of_class_comment b t + ) + (Class.class_type_elements ct); + + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s + + (** Generate the man file for the given module type. + @raise Failure if an error occurs.*) + method generate_for_module_type mt = + let date = Unix.time () in + let file = self#file_name mt.mt_name in + try + let chanout = self#open_out file in + let b = new_buf () in + bs b (".TH \""^mt.mt_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" "); + bs b "OCamldoc "; + bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); + + let abstract = + match mt.mt_info with + None | Some { i_desc = None } -> "no description" + | Some { i_desc = Some t } -> + let s = Odoc_info.string_of_text (Odoc_info.first_sentence_of_text t) in + self#remove_newlines s + in + bs b ".SH NAME\n"; + bs b (mt.mt_name^" \\- "^abstract^"\n"); + bs b (".SH "^Odoc_messages.module_type^"\n"); + bs b (Odoc_messages.module_type^" "^mt.mt_name^"\n"); + bs b (".SH "^Odoc_messages.documentation^"\n"); + bs b ".sp\n"; + bs b (Odoc_messages.module_type^"\n"); + bs b (".BI \""^(Name.simple mt.mt_name)^"\"\n"); + bs b " = "; + ( + match mt.mt_type with + None -> () + | Some t -> + self#man_of_module_type b (Name.father mt.mt_name) t + ); + bs b "\n.sp\n"; + self#man_of_info b mt.mt_info; + bs b "\n.sp\n"; + + (* parameters for functors *) + self#man_of_module_parameter_list b "" (Module.module_type_parameters mt); + (* a large blank *) + bs b "\n.sp\n.sp\n"; + + (* module elements *) + List.iter + (fun ele -> + match ele with + Element_module m -> + self#man_of_module b m + | Element_module_type mt -> + self#man_of_modtype b mt + | Element_included_module im -> + self#man_of_included_module b mt.mt_name im + | Element_class c -> + self#man_of_class b c + | Element_class_type ct -> + self#man_of_class_type b ct + | Element_value v -> + self#man_of_value b v + | Element_exception e -> + self#man_of_exception b e + | Element_type t -> + self#man_of_type b t + | Element_module_comment text -> + self#man_of_module_comment b text + ) + (Module.module_type_elements mt); + + Buffer.output_buffer chanout b; + close_out chanout + + with + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s + + (** Generate the man file for the given module. + @raise Failure if an error occurs.*) + method generate_for_module m = + let date = Unix.time () in + let file = self#file_name m.m_name in + try + let chanout = self#open_out file in + let b = new_buf () in + bs b (".TH \""^m.m_name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" "); + bs b "OCamldoc "; + bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); + + let abstract = + match m.m_info with + None | Some { i_desc = None } -> "no description" + | Some { i_desc = Some t } -> + let s = Odoc_info.string_of_text (Odoc_info.first_sentence_of_text t) in + self#remove_newlines s + in + + bs b ".SH NAME\n"; + bs b (m.m_name^" \\- "^abstract^"\n"); + bs b (".SH "^Odoc_messages.modul^"\n"); + bs b (Odoc_messages.modul^" "^m.m_name^"\n"); + bs b (".SH "^Odoc_messages.documentation^"\n"); + bs b ".sp\n"; + bs b (Odoc_messages.modul^"\n"); + bs b (".BI \""^(Name.simple m.m_name)^"\"\n"); + bs b " : "; + self#man_of_module_type b (Name.father m.m_name) m.m_type; + bs b "\n.sp\n"; + self#man_of_info b m.m_info; + bs b "\n.sp\n"; + + (* parameters for functors *) + self#man_of_module_parameter_list b "" (Module.module_parameters m); + (* a large blank *) + bs b "\n.sp\n.sp\n"; + + (* module elements *) + List.iter + (fun ele -> + match ele with + Element_module m -> + self#man_of_module b m + | Element_module_type mt -> + self#man_of_modtype b mt + | Element_included_module im -> + self#man_of_included_module b m.m_name im + | Element_class c -> + self#man_of_class b c + | Element_class_type ct -> + self#man_of_class_type b ct + | Element_value v -> + self#man_of_value b v + | Element_exception e -> + self#man_of_exception b e + | Element_type t -> + self#man_of_type b t + | Element_module_comment text -> + self#man_of_module_comment b text + ) + (Module.module_elements m); + + Buffer.output_buffer chanout b; + close_out chanout + + with + Sys_error s -> + raise (Failure s) + + (** Create the groups of elements to generate pages for. *) + method create_groups module_list = + let name res_ele = + match res_ele with + Res_module m -> m.m_name + | Res_module_type mt -> mt.mt_name + | Res_class c -> c.cl_name + | Res_class_type ct -> ct.clt_name + | Res_value v -> Name.simple v.val_name + | Res_type t -> Name.simple t.ty_name + | Res_exception e -> Name.simple e.ex_name + | Res_attribute a -> Name.simple a.att_value.val_name + | Res_method m -> Name.simple m.met_value.val_name + | Res_section _ -> assert false + in + let all_items_pre = Odoc_info.Search.search_by_name module_list (Str.regexp ".*") in + let all_items = List.filter + (fun r -> match r with Res_section _ -> false | _ -> true) + all_items_pre + in + let sorted_items = List.sort (fun e1 -> fun e2 -> compare (name e1) (name e2)) all_items in + let rec f acc1 acc2 l = + match l with + [] -> acc2 :: acc1 + | h :: q -> + match acc2 with + [] -> f acc1 [h] q + | h2 :: q2 -> + if (name h) = (name h2) then + if List.mem h acc2 then + f acc1 acc2 q + else + f acc1 (acc2 @ [h]) q + else + f (acc2 :: acc1) [h] q + in + f [] [] sorted_items + + (** Generate a man page for a group of elements with the same name. + A group must not be empty.*) + method generate_for_group l = + let name = + Name.simple + ( + match List.hd l with + Res_module m -> m.m_name + | Res_module_type mt -> mt.mt_name + | Res_class c -> c.cl_name + | Res_class_type ct -> ct.clt_name + | Res_value v -> v.val_name + | Res_type t -> t.ty_name + | Res_exception e -> e.ex_name + | Res_attribute a -> a.att_value.val_name + | Res_method m -> m.met_value.val_name + | Res_section (s,_) -> s + ) + in + let date = Unix.time () in + let file = self#file_name name in + try + let chanout = self#open_out file in + let b = new_buf () in + bs b (".TH \""^name^"\" "); + bs b !Odoc_args.man_section ; + bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" "); + bs b "OCamldoc "; + bs b ("\""^(match !Args.title with Some t -> t | None -> "")^"\"\n"); + bs b ".SH NAME\n"; + bs b (name^" \\- all "^name^" elements\n\n"); + + let f ele = + match ele with + Res_value v -> + bs b ("\n.SH "^Odoc_messages.modul^" "^(Name.father v.val_name)^"\n"); + self#man_of_value b v + | Res_type t -> + bs b ("\n.SH "^Odoc_messages.modul^" "^(Name.father t.ty_name)^"\n"); + self#man_of_type b t + | Res_exception e -> + bs b ("\n.SH "^Odoc_messages.modul^" "^(Name.father e.ex_name)^"\n"); + self#man_of_exception b e + | Res_attribute a -> + bs b ("\n.SH "^Odoc_messages.clas^" "^(Name.father a.att_value.val_name)^"\n"); + self#man_of_attribute b a + | Res_method m -> + bs b ("\n.SH "^Odoc_messages.clas^" "^(Name.father m.met_value.val_name)^"\n"); + self#man_of_method b m + | Res_class c -> + bs b ("\n.SH "^Odoc_messages.modul^" "^(Name.father c.cl_name)^"\n"); + self#man_of_class b c + | Res_class_type ct -> + bs b ("\n.SH "^Odoc_messages.modul^" "^(Name.father ct.clt_name)^"\n"); + self#man_of_class_type b ct + | _ -> + (* normalement on ne peut pas avoir de module ici. *) + () + in + List.iter f l; + Buffer.output_buffer chanout b; + close_out chanout + with + Sys_error s -> + incr Odoc_info.errors ; + prerr_endline s + + (** Generate all the man pages from a module list. *) + method generate module_list = + let sorted_module_list = Sort.list (fun m1 -> fun m2 -> m1.m_name < m2.m_name) module_list in + let groups = self#create_groups sorted_module_list in + let f group = + match group with + [] -> + () + | [Res_module m] -> self#generate_for_module m + | [Res_module_type mt] -> self#generate_for_module_type mt + | [Res_class cl] -> self#generate_for_class cl + | [Res_class_type ct] -> self#generate_for_class_type ct + | l -> + if !Args.man_mini then + () + else + self#generate_for_group l + in + List.iter f groups + end diff --git a/ocamldoc/odoc_merge.ml b/ocamldoc/odoc_merge.ml new file mode 100644 index 0000000..52caaa8 --- /dev/null +++ b/ocamldoc/odoc_merge.ml @@ -0,0 +1,966 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_merge.ml,v 1.13 2007-10-09 10:29:36 weis Exp $ *) + +(** Merge of information from [.ml] and [.mli] for a module.*) + +open Odoc_types + +module Name = Odoc_name +open Odoc_parameter +open Odoc_value +open Odoc_type +open Odoc_exception +open Odoc_class +open Odoc_module + +(** Merge two Odoctypes.info struture, completing the information of + the first one with the information in the second one. + The merge treatment depends on a given merge_option list. + @return the new info structure.*) +let merge_info merge_options (m1 : info) (m2 : info) = + let new_desc_opt = + match m1.i_desc, m2.i_desc with + None, None -> None + | None, Some d + | Some d, None -> Some d + | Some d1, Some d2 -> + if List.mem Merge_description merge_options then + Some (d1 @ (Newline :: d2)) + else + Some d1 + in + let new_authors = + match m1.i_authors, m2.i_authors with + [], [] -> [] + | l, [] + | [], l -> l + | l1, l2 -> + if List.mem Merge_author merge_options then + l1 @ l2 + else + l1 + in + let new_version = + match m1.i_version , m2.i_version with + None, None -> None + | Some v, None + | None, Some v -> Some v + | Some v1, Some v2 -> + if List.mem Merge_version merge_options then + Some (v1^" "^v2) + else + Some v1 + in + let new_sees = + match m1.i_sees, m2.i_sees with + [], [] -> [] + | l, [] + | [], l -> l + | l1, l2 -> + if List.mem Merge_see merge_options then + l1 @ l2 + else + l1 + in + let new_since = + match m1.i_since, m2.i_since with + None, None -> None + | Some v, None + | None, Some v -> Some v + | Some v1, Some v2 -> + if List.mem Merge_since merge_options then + Some (v1^" "^v2) + else + Some v1 + in + let new_dep = + match m1.i_deprecated, m2.i_deprecated with + None, None -> None + | None, Some t + | Some t, None -> Some t + | Some t1, Some t2 -> + if List.mem Merge_deprecated merge_options then + Some (t1 @ (Newline :: t2)) + else + Some t1 + in + let new_params = + match m1.i_params, m2.i_params with + [], [] -> [] + | l, [] + | [], l -> l + | l1, l2 -> + if List.mem Merge_param merge_options then + ( + let l_in_m1_and_m2, l_in_m2_only = List.partition + (fun (param2, _) -> List.mem_assoc param2 l1) + l2 + in + let rec iter = function + [] -> [] + | (param2, desc2) :: q -> + let desc1 = List.assoc param2 l1 in + (param2, desc1 @ (Newline :: desc2)) :: (iter q) + in + let l1_completed = iter l_in_m1_and_m2 in + l1_completed @ l_in_m2_only + ) + else + l1 + in + let new_raised_exceptions = + match m1.i_raised_exceptions, m2.i_raised_exceptions with + [], [] -> [] + | l, [] + | [], l -> l + | l1, l2 -> + if List.mem Merge_raised_exception merge_options then + ( + let l_in_m1_and_m2, l_in_m2_only = List.partition + (fun (exc2, _) -> List.mem_assoc exc2 l1) + l2 + in + let rec iter = function + [] -> [] + | (exc2, desc2) :: q -> + let desc1 = List.assoc exc2 l1 in + (exc2, desc1 @ (Newline :: desc2)) :: (iter q) + in + let l1_completed = iter l_in_m1_and_m2 in + l1_completed @ l_in_m2_only + ) + else + l1 + in + let new_rv = + match m1.i_return_value, m2.i_return_value with + None, None -> None + | None, Some t + | Some t, None -> Some t + | Some t1, Some t2 -> + if List.mem Merge_return_value merge_options then + Some (t1 @ (Newline :: t2)) + else + Some t1 + in + let new_custom = + match m1.i_custom, m2.i_custom with + [], [] -> [] + | [], l + | l, [] -> l + | l1, l2 -> + if List.mem Merge_custom merge_options then + l1 @ l2 + else + l1 + in + { + Odoc_types.i_desc = new_desc_opt ; + Odoc_types.i_authors = new_authors ; + Odoc_types.i_version = new_version ; + Odoc_types.i_sees = new_sees ; + Odoc_types.i_since = new_since ; + Odoc_types.i_deprecated = new_dep ; + Odoc_types.i_params = new_params ; + Odoc_types.i_raised_exceptions = new_raised_exceptions ; + Odoc_types.i_return_value = new_rv ; + Odoc_types.i_custom = new_custom ; + } + +(** Merge of two optional info structures. *) +let merge_info_opt merge_options mli_opt ml_opt = + match mli_opt, ml_opt with + None, Some i -> Some i + | Some i, None -> Some i + | None, None -> None + | Some i1, Some i2 -> Some (merge_info merge_options i1 i2) + +(** merge of two t_type, one for a .mli, another for the .ml. + The .mli type is completed with the information in the .ml type. *) +let merge_types merge_options mli ml = + mli.ty_info <- merge_info_opt merge_options mli.ty_info ml.ty_info; + mli.ty_loc <- { mli.ty_loc with loc_impl = ml.ty_loc.loc_impl } ; + mli.ty_code <- (match mli.ty_code with None -> ml.ty_code | _ -> mli.ty_code) ; + + match mli.ty_kind, ml.ty_kind with + Type_abstract, _ -> + () + + | Type_variant l1, Type_variant l2 -> + let f cons = + try + let cons2 = List.find + (fun c2 -> c2.vc_name = cons.vc_name) + l2 + in + let new_desc = + match cons.vc_text, cons2.vc_text with + None, None -> None + | Some d, None + | None, Some d -> Some d + | Some d1, Some d2 -> + if List.mem Merge_description merge_options then + Some (d1 @ d2) + else + Some d1 + in + cons.vc_text <- new_desc + with + Not_found -> + if !Odoc_args.inverse_merge_ml_mli then + () + else + raise (Failure (Odoc_messages.different_types mli.ty_name)) + in + List.iter f l1 + + | Type_record l1, Type_record l2 -> + let f record = + try + let record2= List.find + (fun r -> r.rf_name = record.rf_name) + l2 + in + let new_desc = + match record.rf_text, record2.rf_text with + None, None -> None + | Some d, None + | None, Some d -> Some d + | Some d1, Some d2 -> + if List.mem Merge_description merge_options then + Some (d1 @ d2) + else + Some d1 + in + record.rf_text <- new_desc + with + Not_found -> + if !Odoc_args.inverse_merge_ml_mli then + () + else + raise (Failure (Odoc_messages.different_types mli.ty_name)) + in + List.iter f l1 + + | _ -> + if !Odoc_args.inverse_merge_ml_mli then + () + else + raise (Failure (Odoc_messages.different_types mli.ty_name)) + +(** Merge of two param_info, one from a .mli, one from a .ml. + The text fields are not handled but will be recreated from the + i_params field of the info structure. + Here, if a parameter in the .mli has no name, we take the one + from the .ml. When two parameters have two different forms, + we take the one from the .mli. *) +let rec merge_param_info pi_mli pi_ml = + match (pi_mli, pi_ml) with + (Simple_name sn_mli, Simple_name sn_ml) -> + if sn_mli.sn_name = "" then + Simple_name { sn_mli with sn_name = sn_ml.sn_name } + else + pi_mli + | (Simple_name _, Tuple _) -> + pi_mli + | (Tuple (_, t_mli), Simple_name sn_ml) -> + (* if we're here, then the tuple in the .mli has no parameter names ; + then we take the name of the parameter of the .ml and the type of the .mli. *) + Simple_name { sn_ml with sn_type = t_mli } + + | (Tuple (l_mli, t_mli), Tuple (l_ml, _)) -> + (* if the two tuples have different lengths + (which should not occurs), we return the pi_mli, + without further investigation.*) + if (List.length l_mli) <> (List.length l_ml) then + pi_mli + else + let new_l = List.map2 merge_param_info l_mli l_ml in + Tuple (new_l, t_mli) + +(** Merge of the parameters of two functions/methods/classes, one for a .mli, another for a .ml. + The prameters in the .mli are completed by the name in the .ml.*) +let rec merge_parameters param_mli param_ml = + match (param_mli, param_ml) with + ([], []) -> [] + | (l, []) | ([], l) -> l + | ((pi_mli :: li), (pi_ml :: l)) -> + (merge_param_info pi_mli pi_ml) :: merge_parameters li l + +(** Merge of two t_class, one for a .mli, another for the .ml. + The .mli class is completed with the information in the .ml class. *) +let merge_classes merge_options mli ml = + mli.cl_info <- merge_info_opt merge_options mli.cl_info ml.cl_info; + mli.cl_loc <- { mli.cl_loc with loc_impl = ml.cl_loc.loc_impl } ; + mli.cl_parameters <- merge_parameters mli.cl_parameters ml.cl_parameters; + + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_class.class_update_parameters_text mli; + + (* merge values *) + List.iter + (fun a -> + try + let _ = List.find + (fun ele -> + match ele with + Class_attribute a2 -> + if a2.att_value.val_name = a.att_value.val_name then + ( + a.att_value.val_info <- merge_info_opt merge_options + a.att_value.val_info a2.att_value.val_info; + a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; + if !Odoc_args.keep_code then + a.att_value.val_code <- a2.att_value.val_code; + true + ) + else + false + | _ -> + false + ) + (* we look for the last attribute with this name defined in the implementation *) + (List.rev (Odoc_class.class_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_class.class_attributes mli); + (* merge methods *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Class_method m2 -> + if m2.met_value.val_name = m.met_value.val_name then + ( + m.met_value.val_info <- merge_info_opt + merge_options m.met_value.val_info m2.met_value.val_info; + m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; + (* merge the parameter names *) + m.met_value.val_parameters <- (merge_parameters + m.met_value.val_parameters + m2.met_value.val_parameters) ; + (* we must reassociate comments in @param to the corresponding + parameters because the associated comment of a parameter may have been changed by the merge.*) + Odoc_value.update_value_parameters_text m.met_value; + + if !Odoc_args.keep_code then + m.met_value.val_code <- m2.met_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last method with this name defined in the implementation *) + (List.rev (Odoc_class.class_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_class.class_methods mli) + +(** merge of two t_class_type, one for a .mli, another for the .ml. + The .mli class is completed with the information in the .ml class. *) +let merge_class_types merge_options mli ml = + mli.clt_info <- merge_info_opt merge_options mli.clt_info ml.clt_info; + mli.clt_loc <- { mli.clt_loc with loc_impl = ml.clt_loc.loc_impl } ; + (* merge values *) + List.iter + (fun a -> + try + let _ = List.find + (fun ele -> + match ele with + Class_attribute a2 -> + if a2.att_value.val_name = a.att_value.val_name then + ( + a.att_value.val_info <- merge_info_opt merge_options + a.att_value.val_info a2.att_value.val_info; + a.att_value.val_loc <- { a.att_value.val_loc with loc_impl = a2.att_value.val_loc.loc_impl } ; + if !Odoc_args.keep_code then + a.att_value.val_code <- a2.att_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last attribute with this name defined in the implementation *) + (List.rev (Odoc_class.class_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_class.class_type_attributes mli); + (* merge methods *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Class_method m2 -> + if m2.met_value.val_name = m.met_value.val_name then + ( + m.met_value.val_info <- merge_info_opt + merge_options m.met_value.val_info m2.met_value.val_info; + m.met_value.val_loc <- { m.met_value.val_loc with loc_impl = m2.met_value.val_loc.loc_impl } ; + m.met_value.val_parameters <- (merge_parameters + m.met_value.val_parameters + m2.met_value.val_parameters) ; + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text m.met_value; + + if !Odoc_args.keep_code then + m.met_value.val_code <- m2.met_value.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last method with this name defined in the implementation *) + (List.rev (Odoc_class.class_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_class.class_type_methods mli) + + +(** merge of two t_module_type, one for a .mli, another for the .ml. + The .mli module is completed with the information in the .ml module. *) +let rec merge_module_types merge_options mli ml = + mli.mt_info <- merge_info_opt merge_options mli.mt_info ml.mt_info; + mli.mt_loc <- { mli.mt_loc with loc_impl = ml.mt_loc.loc_impl } ; + (* merge exceptions *) + List.iter + (fun ex -> + try + let _ = List.find + (fun ele -> + match ele with + Element_exception ex2 -> + if ex2.ex_name = ex.ex_name then + ( + ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; + ex.ex_loc <- { ex.ex_loc with loc_impl = ex2.ex_loc.loc_impl } ; + ex.ex_code <- (match ex.ex_code with None -> ex2.ex_code | _ -> ex.ex_code) ; + true + ) + else + false + | _ -> + false + ) + (* we look for the last exception with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_exceptions mli); + (* merge types *) + List.iter + (fun ty -> + try + let _ = List.find + (fun ele -> + match ele with + Element_type ty2 -> + if ty2.ty_name = ty.ty_name then + ( + merge_types merge_options ty ty2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last type with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_types mli); + (* merge submodules *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Element_module m2 -> + if m2.m_name = m.m_name then + ( + ignore (merge_modules merge_options m m2); +(* + m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; + m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; +*) + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_modules mli); + + (* merge module types *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Element_module_type m2 -> + if m2.mt_name = m.mt_name then + ( + merge_module_types merge_options m m2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_module_types mli); + + (* A VOIR : merge included modules ? *) + + (* merge values *) + List.iter + (fun v -> + try + let _ = List.find + (fun ele -> + match ele with + Element_value v2 -> + if v2.val_name = v.val_name then + ( + v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; + v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; + (* in the .mli we don't know any parameters so we add the ones in the .ml *) + v.val_parameters <- (merge_parameters + v.val_parameters + v2.val_parameters) ; + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text v; + + if !Odoc_args.keep_code then + v.val_code <- v2.val_code; + + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_values mli); + + (* merge classes *) + List.iter + (fun c -> + try + let _ = List.find + (fun ele -> + match ele with + Element_class c2 -> + if c2.cl_name = c.cl_name then + ( + merge_classes merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_classes mli); + + (* merge class types *) + List.iter + (fun c -> + try + let _ = List.find + (fun ele -> + match ele with + Element_class_type c2 -> + if c2.clt_name = c.clt_name then + ( + merge_class_types merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_type_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_type_class_types mli) + +(** merge of two t_module, one for a .mli, another for the .ml. + The .mli module is completed with the information in the .ml module. *) +and merge_modules merge_options mli ml = + mli.m_info <- merge_info_opt merge_options mli.m_info ml.m_info; + mli.m_loc <- { mli.m_loc with loc_impl = ml.m_loc.loc_impl } ; + let rec remove_doubles acc = function + [] -> acc + | h :: q -> + if List.mem h acc then remove_doubles acc q + else remove_doubles (h :: acc) q + in + mli.m_top_deps <- remove_doubles mli.m_top_deps ml.m_top_deps ; + + let code = + if !Odoc_args.keep_code then + match mli.m_code, ml.m_code with + Some s, _ -> Some s + | _, Some s -> Some s + | _ -> None + else + None + in + let code_intf = + if !Odoc_args.keep_code then + match mli.m_code_intf, ml.m_code_intf with + Some s, _ -> Some s + | _, Some s -> Some s + | _ -> None + else + None + in + mli.m_code <- code; + mli.m_code_intf <- code_intf; + + (* merge exceptions *) + List.iter + (fun ex -> + try + let _ = List.find + (fun ele -> + match ele with + Element_exception ex2 -> + if ex2.ex_name = ex.ex_name then + ( + ex.ex_info <- merge_info_opt merge_options ex.ex_info ex2.ex_info; + ex.ex_loc <- { ex.ex_loc with loc_impl = ex.ex_loc.loc_impl } ; + ex.ex_code <- (match ex.ex_code with None -> ex2.ex_code | _ -> ex.ex_code) ; + true + ) + else + false + | _ -> + false + ) + (* we look for the last exception with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_exceptions mli); + (* merge types *) + List.iter + (fun ty -> + try + let _ = List.find + (fun ele -> + match ele with + Element_type ty2 -> + if ty2.ty_name = ty.ty_name then + ( + merge_types merge_options ty ty2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last type with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_types mli); + (* merge submodules *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Element_module m2 -> + if m2.m_name = m.m_name then + ( + ignore (merge_modules merge_options m m2); +(* + m.m_info <- merge_info_opt merge_options m.m_info m2.m_info; + m.m_loc <- { m.m_loc with loc_impl = m2.m_loc.loc_impl } ; +*) + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_modules mli); + + (* merge module types *) + List.iter + (fun m -> + try + let _ = List.find + (fun ele -> + match ele with + Element_module_type m2 -> + if m2.mt_name = m.mt_name then + ( + merge_module_types merge_options m m2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last module with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_module_types mli); + + (* A VOIR : merge included modules ? *) + + (* merge values *) + List.iter + (fun v -> + try + let _ = List.find + (fun v2 -> + if v2.val_name = v.val_name then + ( + v.val_info <- merge_info_opt merge_options v.val_info v2.val_info ; + v.val_loc <- { v.val_loc with loc_impl = v2.val_loc.loc_impl } ; + (* in the .mli we don't know any parameters so we add the ones in the .ml *) + v.val_parameters <- (merge_parameters + v.val_parameters + v2.val_parameters) ; + (* we must reassociate comments in @param to the the corresponding + parameters because the associated comment of a parameter may have been changed y the merge.*) + Odoc_value.update_value_parameters_text v; + + if !Odoc_args.keep_code then + v.val_code <- v2.val_code; + true + ) + else + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_values ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_values mli); + + (* merge classes *) + List.iter + (fun c -> + try + let _ = List.find + (fun ele -> + match ele with + Element_class c2 -> + if c2.cl_name = c.cl_name then + ( + merge_classes merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_classes mli); + + (* merge class types *) + List.iter + (fun c -> + try + let _ = List.find + (fun ele -> + match ele with + Element_class_type c2 -> + if c2.clt_name = c.clt_name then + ( + merge_class_types merge_options c c2; + true + ) + else + false + | _ -> + false + ) + (* we look for the last value with this name defined in the implementation *) + (List.rev (Odoc_module.module_elements ml)) + in + () + with + Not_found -> + () + ) + (Odoc_module.module_class_types mli); + + mli + +let merge merge_options modules_list = + let rec iter = function + [] -> [] + | m :: q -> + (* look for another module with the same name *) + let (l_same, l_others) = List.partition + (fun m2 -> m.m_name = m2.m_name) + q + in + match l_same with + [] -> + (* no other module to merge with *) + m :: (iter l_others) + | m2 :: [] -> + ( + (* we can merge m with m2 if there is an implementation + and an interface.*) + let f b = if !Odoc_args.inverse_merge_ml_mli then not b else b in + match f m.m_is_interface, f m2.m_is_interface with + true, false -> (merge_modules merge_options m m2) :: (iter l_others) + | false, true -> (merge_modules merge_options m2 m) :: (iter l_others) + | false, false -> + if !Odoc_args.inverse_merge_ml_mli then + (* two Module.ts for the .mli ! *) + raise (Failure (Odoc_messages.two_interfaces m.m_name)) + else + (* two Module.t for the .ml ! *) + raise (Failure (Odoc_messages.two_implementations m.m_name)) + | true, true -> + if !Odoc_args.inverse_merge_ml_mli then + (* two Module.t for the .ml ! *) + raise (Failure (Odoc_messages.two_implementations m.m_name)) + else + (* two Module.ts for the .mli ! *) + raise (Failure (Odoc_messages.two_interfaces m.m_name)) + ) + | _ -> + (* two many Module.t ! *) + raise (Failure (Odoc_messages.too_many_module_objects m.m_name)) + + in + iter modules_list diff --git a/ocamldoc/odoc_merge.mli b/ocamldoc/odoc_merge.mli new file mode 100644 index 0000000..7f59a0c --- /dev/null +++ b/ocamldoc/odoc_merge.mli @@ -0,0 +1,32 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_merge.mli,v 1.3 2003-11-24 10:41:05 starynke Exp $ *) + +(** Merge of information from [.ml] and [.mli] for a module.*) + +(** Merge of two optional info structures. + Used to merge a comment before and a comment after + an element in [Odoc_sig.Analyser.analyse_signature_item_desc]. *) +val merge_info_opt : + Odoc_types.merge_option list -> + Odoc_types.info option -> + Odoc_types.info option -> + Odoc_types.info option + +(** Merge of modules which represent the same OCaml module, in a list of t_module. + There must be at most two t_module for the same OCaml module, one for a .mli, another for the .ml. + The function returns the list of t_module where same modules have been merged, according + to the given merge_option list.*) +val merge : + Odoc_types.merge_option list -> + Odoc_module.t_module list -> Odoc_module.t_module list + diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml new file mode 100644 index 0000000..6c89e4a --- /dev/null +++ b/ocamldoc/odoc_messages.ml @@ -0,0 +1,360 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_messages.ml,v 1.32 2008-07-25 13:28:23 guesdon Exp $ *) + +(** The messages of the application. *) + +let ok = "Ok" +let software = "OCamldoc" +let config_version = Config.version +let magic = config_version^"" +let message_version = software^" "^config_version + +(** Messages for command line *) + +let usage = "Usage : "^(Sys.argv.(0))^" [options] \n" +let options_are = "Options are :" +let option_version = "\tPrint version and exit" +let bytecode_only = "(bytecode version only)" +let latex_only = "(LaTeX only)" +let texi_only = "(TeXinfo only)" +let latex_texi_only = "(LaTeX and TeXinfo only)" +let html_only = "(HTML only)" +let html_latex_only = "(HTML and LaTeX only)" +let html_latex_texi_only = "(HTML, LaTeX and TeXinfo only)" +let man_only = "(man only)" +let verbose_mode = "\t\tverbose mode" +let include_dirs = "\tAdd to the list of include directories" +let rectypes = "\tAllow arbitrary recursive types" +let preprocess = "\tPipe sources through preprocessor " +let option_impl ="\tConsider as a .ml file" +let option_intf ="\tConsider as a .mli file" +let option_text ="\tConsider as a .txt file" +let display_custom_generators_dir = "\tDisplay custom generators standard directory and exit" +let add_load_dir = "\tAdd the given directory to the search path for custom\n"^ + "\t\tgenerators "^bytecode_only +let load_file = "\n\t\tLoad file defining a new documentation generator\n\t\t"^bytecode_only +let nolabels = "\tIgnore non-optional labels in types" +let werr = "\tTreat ocamldoc warnings as errors" +let hide_warnings = "\n\t\tdo not print ocamldoc warnings" +let target_dir = "\tGenerate files in directory , rather than in current\n"^ + "\t\tdirectory (for man and HTML generators)" +let dump = "\tDump collected information into " +let load = "\tLoad information from ; may be used several times" +let css_style = "\n\t\tUse content of as CSS style definition "^html_only +let index_only = "\tGenerate index files only "^html_only +let colorize_code = "\n\t\tColorize code even in documentation pages "^html_only +let html_short_functors = "\n\t\tUse short form to display functor types "^html_only +let generate_html = "\tGenerate HTML documentation" +let generate_latex = "\tGenerate LaTeX documentation" +let generate_texinfo = "\tGenerate TeXinfo documentation" +let generate_man = "\t\tGenerate man pages" +let generate_dot = "\t\tGenerate dot code of top modules dependencies" + +let option_not_in_native_code op = "Option "^op^" not available in native code version." + +let default_out_file = "ocamldoc.out" +let out_file = + "\tSet the ouput file name, used by texi, latex and dot generators\n"^ + "\t\t(default is "^default_out_file^")\n"^ + "\t\tor the prefix of index files for the HTML generator\n"^ + "\t\t(default is index)" + +let dot_include_all = + "\n\t\tInclude all modules in the dot output, not only the\n"^ + "\t\tmodules given on the command line" +let dot_types = "\tGenerate dependency graph for types instead of modules" +let default_dot_colors = + [ [ "darkturquoise" ; "darkgoldenrod2" ; "cyan" ; "green" ; ] ; + [ "magenta" ; "yellow" ; "burlywood1" ; "aquamarine" ; "floralwhite" ; "lightpink" ] ; + [ "lightblue" ; "mediumturquoise" ; "salmon" ; "slategray3"] ; + ] + +let dot_colors = + "\n\t\tUse colors c1,c1,...,cn in the dot output\n"^ + "\t\t(default list is "^ + (String.concat ",\n\t\t" (List.map (String.concat ",") default_dot_colors))^")" + +let dot_reduce = + "\tPerform a transitive reduction on the selected dependency graph\n"^ + "\t\tbefore the dot output" + +let man_mini = "\tGenerate man pages only for modules, module types, classes\n"^ + "\t\tand class types "^man_only +let default_man_section = "3" +let man_section = "
\n\t\tUse
in man page files "^ + "(default is "^default_man_section^") "^man_only^"\n" + +let default_man_suffix = default_man_section^"o" +let man_suffix = "\n\t\tUse for man page files "^ + "(default is "^default_man_suffix^") "^man_only^"\n" + +let option_title = "\tUse <title> as title for the generated documentation" +let option_intro = + "<file>\tUse content of <file> as ocamldoc text to use as introduction\n"^ + "\t\t"^(html_latex_texi_only) +let with_parameter_list = "\tDisplay the complete list of parameters for functions and\n"^ + "\t\tmethods "^html_only +let hide_modules = "<M1,M2.M3,...>\n\t\tHide the given complete module names in generated doc" +let no_header = "\tSuppress header in generated documentation\n\t\t"^latex_texi_only +let no_trailer = "\tSuppress trailer in generated documentation\n\t\t"^latex_texi_only +let separate_files = "\tGenerate one file per toplevel module "^latex_only +let latex_title ref_titles = + "n,style\n\t\tAssociate {n } to the given sectionning style\n"^ + "\t\t(e.g. 'section') in the latex output "^latex_only^"\n"^ + "\t\tDefault sectionning is:\n\t\t"^ + (String.concat "\n\t\t" + (List.map (fun (n,t) -> Printf.sprintf " %d -> %s" n t) !ref_titles)) + +let default_latex_value_prefix = "val:" +let latex_value_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of values.\n"^ + "\t\t(default is \""^default_latex_value_prefix^"\")" + +let default_latex_type_prefix = "type:" +let latex_type_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of types.\n"^ + "\t\t(default is \""^default_latex_type_prefix^"\")" + +let default_latex_exception_prefix = "exception:" +let latex_exception_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of exceptions.\n"^ + "\t\t(default is \""^default_latex_exception_prefix^"\")" + +let default_latex_module_prefix = "module:" +let latex_module_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of modules.\n"^ + "\t\t(default is \""^default_latex_module_prefix^"\")" + +let default_latex_module_type_prefix = "moduletype:" +let latex_module_type_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of module types.\n"^ + "\t\t(default is \""^default_latex_module_type_prefix^"\")" + +let default_latex_class_prefix = "class:" +let latex_class_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of classes.\n"^ + "\t\t(default is \""^default_latex_class_prefix^"\")" + +let default_latex_class_type_prefix = "classtype:" +let latex_class_type_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of class types.\n"^ + "\t\t(default is \""^default_latex_class_type_prefix^"\")" + +let default_latex_attribute_prefix = "val:" +let latex_attribute_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of attributes.\n"^ + "\t\t(default is \""^default_latex_attribute_prefix^"\")" + +let default_latex_method_prefix = "method:" +let latex_method_prefix = + "<string>\n\t\tUse <string> as prefix for the LaTeX labels of methods.\n"^ + "\t\t(default is \""^default_latex_method_prefix^"\")" + +let no_toc = "\tDo not generate table of contents "^latex_only +let sort_modules = "\tSort the list of top modules before generating the documentation" +let no_stop = "\tDo not stop at (**/**) comments" +let no_custom_tags = "\n\t\tDo not allow custom @-tags" +let remove_stars = "\tRemove beginning blanks of comment lines, until the first '*'" +let keep_code = "\tAlways keep code when available" +let inverse_merge_ml_mli = "\n\t\tInverse implementations and interfaces when merging" +let no_filter_with_module_constraints = "\n\t\tDo not filter module elements using module type constraints" +let merge_description = ('d', "merge description") +let merge_author = ('a', "merge @author") +let merge_version = ('v', "merge @version") +let merge_see = ('l', "merge @see") +let merge_since = ('s', "merge @since") +let merge_deprecated = ('o', "merge @deprecated") +let merge_param = ('p', "merge @param") +let merge_raised_exception = ('e', "merge @raise") +let merge_return_value = ('r', "merge @return") +let merge_custom = ('c', "merge custom @-tags") +let merge_all = ('A', "merge all") + +let no_index = "\tDo not build index for Info files "^texi_only +let esc_8bits = "\tEscape accentuated characters in Info files "^texi_only +let info_section = "Specify section of Info directory "^texi_only +let info_entry = "\tSpecify Info directory entry "^texi_only + +let options_can_be = "<options> can be one or more of the following characters:" +let string_of_options_list l = + List.fold_left (fun acc -> fun (c, m) -> acc^"\n\t\t"^(String.make 1 c)^" "^m) + "" + l + +let merge_options = + "<options>\tspecify merge options between .mli and .ml\n\t\t"^ + options_can_be^ + (string_of_options_list + [ merge_description ; + merge_author ; + merge_version ; + merge_see ; + merge_since ; + merge_deprecated ; + merge_param ; + merge_raised_exception ; + merge_return_value ; + merge_custom ; + merge_all ] + ) + + +(** Error and warning messages *) + +let warning = "Warning" +let pwarning s = + if !Odoc_config.print_warnings then prerr_endline (warning^": "^s); + if !Odoc_global.warn_error then incr Odoc_global.errors + +let bad_magic_number = + "Bad magic number for this ocamldoc dump!\n"^ + "This dump was not created by this version of OCamldoc." + +let not_a_module_name s = s^" is not a valid module name" +let load_file_error f e = "Error while loading file "^f^":\n"^e +let wrong_format s = "Wrong format for \""^s^"\"" +let errors_occured n = (string_of_int n)^" error(s) encountered" +let parse_error = "Parse error" +let text_parse_error l c s = + let lines = Str.split (Str.regexp_string "\n") s in + "Syntax error in text:\n"^s^"\n"^ + "line "^(string_of_int l)^", character "^(string_of_int c)^":\n"^ + (List.nth lines l)^"\n"^ + (String.make c ' ')^"^" + +let file_not_found_in_paths paths name = + Printf.sprintf "No file %s found in the load paths: \n%s" + name + (String.concat "\n" paths) + +let tag_not_handled tag = "Tag @"^tag^" not handled by this generator" +let bad_tree = "Incorrect tree structure." +let not_a_valid_tag s = s^" is not a valid tag." +let fun_without_param f = "Function "^f^" has no parameter.";; +let method_without_param f = "Méthode "^f^" has no parameter.";; +let anonymous_parameters f = "Function "^f^" has anonymous parameters." +let function_colon f = "Function "^f^": " +let implicit_match_in_parameter = "Parameters contain implicit pattern matching." +let unknown_extension f = "Unknown extension for file "^f^"." +let two_implementations name = "There are two implementations of module "^name^"." +let two_interfaces name = "There are two interfaces of module "^name^"." +let too_many_module_objects name = "There are two many interfaces/implementation of module "^name^"." +let exception_not_found_in_implementation exc m = "Exception "^exc^" was not found in implementation of module "^m^"." +let type_not_found_in_implementation exc m = "Type "^exc^" was not found in implementation of module "^m^"." +let module_not_found_in_implementation m m2 = "Module "^m^" was not found in implementation of module "^m2^"." +let value_not_found_in_implementation v m = "Value "^v^" was not found in implementation of module "^m^"." +let class_not_found_in_implementation c m = "Class "^c^" was not found in implementation of module "^m^"." +let attribute_not_found_in_implementation a c = "Attribute "^a^" was not found in implementation of class "^c^"." +let method_not_found_in_implementation m c = "Method "^m^" was not found in implementation of class "^c^"." +let different_types t = "Definition of type "^t^" doesn't match from interface to implementation." +let attribute_type_not_found cl att = "The type of the attribute "^att^" could not be found in the signature of class "^cl^"." +let method_type_not_found cl met = "The type of the method "^met^" could not be found in the signature of class "^cl^"." +let module_not_found m m2 = "The module "^m2^" could not be found in the signature of module "^m^"." +let module_type_not_found m mt = "The module type "^mt^" could not be found in the signature of module "^m^"." +let value_not_found m v = "The value "^v^" could not be found in the signature of module "^m^"." +let exception_not_found m e = "The exception "^e^" could not be found in the signature of module "^m^"." +let type_not_found m t = "The type "^t^" could not be found in the signature of module "^m^"." +let class_not_found m c = "The class "^c^" could not be found in the signature of module "^m^"." +let class_type_not_found m c = "The class type "^c^" could not be found in the signature of module "^m^"." +let type_not_found_in_typedtree t = "Type "^t^" was not found in typed tree." +let exception_not_found_in_typedtree e = "Exception "^e^" was not found in typed tree." +let module_type_not_found_in_typedtree mt = "Module type "^mt^" was not found in typed tree." +let module_not_found_in_typedtree m = "Module "^m^" was not found in typed tree." +let class_not_found_in_typedtree c = "Class "^c^" was not found in typed tree." +let class_type_not_found_in_typedtree ct = "Class type "^ct^" was not found in typed tree." +let inherit_classexp_not_found_in_typedtree n = "Inheritance class expression number "^(string_of_int n)^" was not found in typed tree." +let attribute_not_found_in_typedtree att = "Class attribute "^att^" was not found in typed tree." +let method_not_found_in_typedtree met = "Class method "^met^" was not found in typed tree." +let misplaced_comment file pos = + Printf.sprintf "Misplaced special comment in file %s, character %d." file pos + +let cross_module_not_found n = "Module "^n^" not found" +let cross_module_type_not_found n = "Module type "^n^" not found" +let cross_module_or_module_type_not_found n = "Module or module type "^n^" not found" +let cross_class_not_found n = "Class "^n^" not found" +let cross_class_type_not_found n = "class type "^n^" not found" +let cross_class_or_class_type_not_found n = "Class or class type "^n^" not found" +let cross_exception_not_found n = "Exception "^n^" not found" +let cross_element_not_found n = "Element "^n^" not found" +let cross_method_not_found n = "Method "^n^" not found" +let cross_attribute_not_found n = "Attribute "^n^" not found" +let cross_section_not_found n = "Section "^n^" not found" +let cross_value_not_found n = "Value "^n^" not found" +let cross_type_not_found n = "Type "^n^" not found" + +let object_end = "object ... end" +let struct_end = "struct ... end" +let sig_end = "sig ... end" + +(** Messages for verbose mode. *) + +let analysing f = "Analysing file "^f^"..." +let merging = "Merging..." +let cross_referencing = "Cross referencing..." +let generating_doc = "Generating documentation..." +let loading f = "Loading "^f^"..." +let file_generated f = "File "^f^" generated." +let file_exists_dont_generate f = + "File "^f^" exists, we don't generate it." + +(** Messages for documentation generation.*) + +let modul = "Module" +let modules = "Modules" +let functors = "Functors" +let values = "Simple values" +let types = "Types" +let exceptions = "Exceptions" +let record = "Record" +let variant = "Variant" +let mutab = "mutable" +let functions = "Functions" +let parameters = "Parameters" +let abstract = "Abstract" +let functo = "Functor" +let clas = "Class" +let classes = "Classes" +let attributes = "Attributes" +let methods = "Methods" +let authors = "Author(s)" +let version = "Version" +let since = "Since" +let deprecated = "Deprecated." +let raises = "Raises" +let returns = "Returns" +let inherits = "Inherits" +let inheritance = "Inheritance" +let privat = "private" +let module_type = "Module type" +let class_type = "Class type" +let description = "Description" +let interface = "Interface" +let type_parameters = "Type parameters" +let class_types = "Class types" +let module_types = "Module types" +let see_also = "See also" +let documentation = "Documentation" +let index_of = "Index of" +let top = "Top" +let index_of_values = index_of^" values" +let index_of_exceptions = index_of^" exceptions" +let index_of_types = index_of^" types" +let index_of_attributes = index_of^" class attributes" +let index_of_methods = index_of^" class methods" +let index_of_classes = index_of^" classes" +let index_of_class_types = index_of^" class types" +let index_of_modules = index_of^" modules" +let index_of_module_types = index_of^" module types" +let previous = "Previous" +let next = "Next" +let up = "Up" diff --git a/ocamldoc/odoc_misc.ml b/ocamldoc/odoc_misc.ml new file mode 100644 index 0000000..46b70a9 --- /dev/null +++ b/ocamldoc/odoc_misc.ml @@ -0,0 +1,486 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_misc.ml,v 1.21 2006-07-06 07:19:06 pouillar Exp $ *) + +let no_blanks s = + let len = String.length s in + let buf = Buffer.create len in + for i = 0 to len - 1 do + match s.[i] with + ' ' | '\n' | '\t' | '\r' -> () + | c -> Buffer.add_char buf c + done; + Buffer.contents buf + +let input_file_as_string nom = + let chanin = open_in_bin nom in + let len = 1024 in + let s = String.create len in + let buf = Buffer.create len in + let rec iter () = + try + let n = input chanin s 0 len in + if n = 0 then + () + else + ( + Buffer.add_substring buf s 0 n; + iter () + ) + with + End_of_file -> () + in + iter (); + close_in chanin; + Buffer.contents buf + +let split_string s chars = + let len = String.length s in + let rec iter acc pos = + if pos >= len then + match acc with + "" -> [] + | _ -> [acc] + else + if List.mem s.[pos] chars then + match acc with + "" -> iter "" (pos + 1) + | _ -> acc :: (iter "" (pos + 1)) + else + iter (Printf.sprintf "%s%c" acc s.[pos]) (pos + 1) + in + iter "" 0 + +let split_with_blanks s = split_string s [' ' ; '\n' ; '\r' ; '\t' ] + +let list_concat sep = + let rec iter = function + [] -> [] + | [h] -> [h] + | h :: q -> h :: sep :: q + in + iter + +let rec string_of_longident li = + match li with + | Longident.Lident s -> s + | Longident.Ldot(li, s) -> string_of_longident li ^ "." ^ s + | Longident.Lapply(l1, l2) -> + string_of_longident l1 ^ "(" ^ string_of_longident l2 ^ ")" + +let get_fields type_expr = + let (fields, _) = Ctype.flatten_fields (Ctype.object_fields type_expr) in + List.fold_left + (fun acc -> fun (label, field_kind, typ) -> + match field_kind with + Types.Fabsent -> + acc + | _ -> + if label = "*dummy method*" then + acc + else + acc @ [label, typ] + ) + [] + fields + +let rec string_of_text t = + let rec iter t_ele = + match t_ele with + | Odoc_types.Raw s + | Odoc_types.Code s + | Odoc_types.CodePre s + | Odoc_types.Verbatim s -> s + | Odoc_types.Bold t + | Odoc_types.Italic t + | Odoc_types.Center t + | Odoc_types.Left t + | Odoc_types.Right t + | Odoc_types.Emphasize t -> string_of_text t + | Odoc_types.List l -> + (String.concat "" + (List.map (fun t -> "\n- "^(string_of_text t)) l))^ + "\n" + | Odoc_types.Enum l -> + let rec f n = function + [] -> "\n" + | t :: q -> + "\n"^(string_of_int n)^". "^(string_of_text t)^ + (f (n + 1) q) + in + f 1 l + | Odoc_types.Newline -> "\n" + | Odoc_types.Block t -> "\t"^(string_of_text t)^"\n" + | Odoc_types.Title (_, _, t) -> "\n"^(string_of_text t)^"\n" + | Odoc_types.Latex s -> "{% "^s^" %}" + | Odoc_types.Link (s, t) -> + "["^s^"]"^(string_of_text t) + | Odoc_types.Ref (name, _) -> + iter (Odoc_types.Code name) + | Odoc_types.Superscript t -> + "^{"^(string_of_text t)^"}" + | Odoc_types.Subscript t -> + "^{"^(string_of_text t)^"}" + | Odoc_types.Module_list l -> + string_of_text + (list_concat (Odoc_types.Raw ", ") + (List.map (fun s -> Odoc_types.Code s) l) + ) + | Odoc_types.Index_list -> + "" + | Odoc_types.Custom (_, t) -> string_of_text t + in + String.concat "" (List.map iter t) + +let string_of_author_list l = + match l with + [] -> + "" + | _ -> + "* "^Odoc_messages.authors^":\n"^ + (String.concat ", " l)^ + "\n" + +let string_of_version_opt v_opt = + match v_opt with + None -> "" + | Some v -> Odoc_messages.version^": "^v^"\n" + +let string_of_since_opt s_opt = + match s_opt with + None -> "" + | Some s -> Odoc_messages.since^" "^s^"\n" + +let string_of_raised_exceptions l = + match l with + [] -> "" + | (s, t) :: [] -> Odoc_messages.raises^" "^s^" "^(string_of_text t)^"\n" + | _ -> + Odoc_messages.raises^"\n"^ + (String.concat "" + (List.map + (fun (ex, desc) -> "- "^ex^" "^(string_of_text desc)^"\n") + l + ) + )^"\n" + +let string_of_see (see_ref, t) = + let t_ref = + match see_ref with + Odoc_types.See_url s -> [ Odoc_types.Link (s, t) ] + | Odoc_types.See_file s -> (Odoc_types.Code s) :: (Odoc_types.Raw " ") :: t + | Odoc_types.See_doc s -> (Odoc_types.Italic [Odoc_types.Raw s]) :: (Odoc_types.Raw " ") :: t + in + string_of_text t_ref + +let string_of_sees l = + match l with + [] -> "" + | see :: [] -> Odoc_messages.see_also^" "^(string_of_see see)^" \n" + | _ -> + Odoc_messages.see_also^"\n"^ + (String.concat "" + (List.map + (fun see -> "- "^(string_of_see see)^"\n") + l + ) + )^"\n" + +let string_of_return_opt return_opt = + match return_opt with + None -> "" + | Some s -> Odoc_messages.returns^" "^(string_of_text s)^"\n" + +let string_of_info i = + let module M = Odoc_types in + (match i.M.i_deprecated with + None -> "" + | Some d -> Odoc_messages.deprecated^"! "^(string_of_text d)^"\n")^ + (match i.M.i_desc with + None -> "" + | Some d when d = [Odoc_types.Raw ""] -> "" + | Some d -> (string_of_text d)^"\n" + )^ + (string_of_author_list i.M.i_authors)^ + (string_of_version_opt i.M.i_version)^ + (string_of_since_opt i.M.i_since)^ + (string_of_raised_exceptions i.M.i_raised_exceptions)^ + (string_of_return_opt i.M.i_return_value) + +let apply_opt f v_opt = + match v_opt with + None -> None + | Some v -> Some (f v) + +let string_of_date ?(hour=true) d = + let add_0 s = if String.length s < 2 then "0"^s else s in + let t = Unix.localtime d in + (string_of_int (t.Unix.tm_year + 1900))^"-"^ + (add_0 (string_of_int (t.Unix.tm_mon + 1)))^"-"^ + (add_0 (string_of_int t.Unix.tm_mday))^ + ( + if hour then + " "^ + (add_0 (string_of_int t.Unix.tm_hour))^":"^ + (add_0 (string_of_int t.Unix.tm_min)) + else + "" + ) + + +let rec text_list_concat sep l = + match l with + [] -> [] + | [t] -> t + | t :: q -> + t @ (sep :: (text_list_concat sep q)) + +let rec text_no_title_no_list t = + let rec iter t_ele = + match t_ele with + | Odoc_types.Title (_,_,t) -> text_no_title_no_list t + | Odoc_types.List l + | Odoc_types.Enum l -> + (Odoc_types.Raw " ") :: + (text_list_concat + (Odoc_types.Raw ", ") + (List.map text_no_title_no_list l)) + | Odoc_types.Raw _ + | Odoc_types.Code _ + | Odoc_types.CodePre _ + | Odoc_types.Verbatim _ + | Odoc_types.Ref _ -> [t_ele] + | Odoc_types.Newline -> [Odoc_types.Newline] + | Odoc_types.Block t -> [Odoc_types.Block (text_no_title_no_list t)] + | Odoc_types.Bold t -> [Odoc_types.Bold (text_no_title_no_list t)] + | Odoc_types.Italic t -> [Odoc_types.Italic (text_no_title_no_list t)] + | Odoc_types.Center t -> [Odoc_types.Center (text_no_title_no_list t)] + | Odoc_types.Left t -> [Odoc_types.Left (text_no_title_no_list t)] + | Odoc_types.Right t -> [Odoc_types.Right (text_no_title_no_list t)] + | Odoc_types.Emphasize t -> [Odoc_types.Emphasize (text_no_title_no_list t)] + | Odoc_types.Latex s -> [Odoc_types.Latex s] + | Odoc_types.Link (s, t) -> [Odoc_types.Link (s, (text_no_title_no_list t))] + | Odoc_types.Superscript t -> [Odoc_types.Superscript (text_no_title_no_list t)] + | Odoc_types.Subscript t -> [Odoc_types.Subscript (text_no_title_no_list t)] + | Odoc_types.Module_list l -> + list_concat (Odoc_types.Raw ", ") + (List.map + (fun s -> Odoc_types.Ref (s, Some Odoc_types.RK_module)) + l + ) + | Odoc_types.Index_list -> [] + | Odoc_types.Custom (s,t) -> [Odoc_types.Custom (s, text_no_title_no_list t)] + in + List.flatten (List.map iter t) + +let get_titles_in_text t = + let l = ref [] in + let rec iter_ele ele = + match ele with + | Odoc_types.Title (n,lopt,t) -> l := (n,lopt,t) :: !l + | Odoc_types.List l + | Odoc_types.Enum l -> List.iter iter_text l + | Odoc_types.Raw _ + | Odoc_types.Code _ + | Odoc_types.CodePre _ + | Odoc_types.Verbatim _ + | Odoc_types.Ref _ -> () + | Odoc_types.Newline -> () + | Odoc_types.Block t + | Odoc_types.Bold t + | Odoc_types.Italic t + | Odoc_types.Center t + | Odoc_types.Left t + | Odoc_types.Right t + | Odoc_types.Emphasize t -> iter_text t + | Odoc_types.Latex s -> () + | Odoc_types.Link (_, t) + | Odoc_types.Superscript t + | Odoc_types.Subscript t -> iter_text t + | Odoc_types.Module_list _ -> () + | Odoc_types.Index_list -> () + | Odoc_types.Custom (_, t) -> iter_text t + and iter_text te = + List.iter iter_ele te + in + iter_text t; + List.rev !l + +let text_concat (sep : Odoc_types.text) l = + let rec iter = function + [] -> [] + | [last] -> last + | h :: q -> h @ sep @ (iter q) + in + iter l + +(*********************************************************) +let rec get_before_dot s = + try + let len = String.length s in + let n = String.index s '.' in + if n + 1 >= len then + (* le point est le dernier caractère *) + (true, s, "") + else + match s.[n+1] with + ' ' | '\n' | '\r' | '\t' -> + (true, String.sub s 0 (n+1), + String.sub s (n+1) (len - n - 1)) + | _ -> + let b, s2, s_after = get_before_dot (String.sub s (n + 1) (len - n - 1)) in + (b, (String.sub s 0 (n+1))^s2, s_after) + with + Not_found -> (false, s, "") + +let rec first_sentence_text t = + match t with + [] -> (false, [], []) + | ele :: q -> + let (stop, ele2, ele3_opt) = first_sentence_text_ele ele in + if stop then + (stop, [ele2], + match ele3_opt with None -> q | Some e -> e :: q) + else + let (stop2, q2, rest) = first_sentence_text q in + (stop2, ele2 :: q2, rest) + + +and first_sentence_text_ele text_ele = + match text_ele with + | Odoc_types.Raw s -> + let b, s2, s_after = get_before_dot s in + (b, Odoc_types.Raw s2, Some (Odoc_types.Raw s_after)) + | Odoc_types.Code _ + | Odoc_types.CodePre _ + | Odoc_types.Verbatim _ -> (false, text_ele, None) + | Odoc_types.Bold t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Bold t2, Some (Odoc_types.Bold t3)) + | Odoc_types.Italic t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Italic t2, Some (Odoc_types.Italic t3)) + | Odoc_types.Center t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Center t2, Some (Odoc_types.Center t3)) + | Odoc_types.Left t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Left t2, Some (Odoc_types.Left t3)) + | Odoc_types.Right t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Right t2, Some (Odoc_types.Right t3)) + | Odoc_types.Emphasize t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Emphasize t2, Some (Odoc_types.Emphasize t3)) + | Odoc_types.Block t -> + let (b, t2, t3) = first_sentence_text t in + (b, Odoc_types.Block t2, Some (Odoc_types.Block t3)) + | Odoc_types.Title (n, l_opt, t) -> + let (b, t2, t3) = first_sentence_text t in + (b, + Odoc_types.Title (n, l_opt, t2), + Some (Odoc_types.Title (n, l_opt, t3))) + | Odoc_types.Newline -> + (true, Odoc_types.Raw "", Some Odoc_types.Newline) + | Odoc_types.List _ + | Odoc_types.Enum _ + | Odoc_types.Latex _ + | Odoc_types.Link _ + | Odoc_types.Ref _ + | Odoc_types.Superscript _ + | Odoc_types.Subscript _ + | Odoc_types.Module_list _ + | Odoc_types.Index_list -> (false, text_ele, None) + | Odoc_types.Custom _ -> (false, text_ele, None) + +let first_sentence_of_text t = + let (_,t2,_) = first_sentence_text t in + t2 + +let first_sentence_and_rest_of_text t = + let (_,t1, t2) = first_sentence_text t in + (t1, t2) + +let remove_ending_newline s = + let len = String.length s in + if len <= 0 then + s + else + match s.[len-1] with + '\n' -> String.sub s 0 (len-1) + | _ -> s + +let search_string_backward ~pat = + let lenp = String.length pat in + let rec iter s = + let len = String.length s in + match compare len lenp with + -1 -> raise Not_found + | 0 -> if pat = s then 0 else raise Not_found + | _ -> + let pos = len - lenp in + let s2 = String.sub s pos lenp in + if s2 = pat then + pos + else + iter (String.sub s 0 pos) + in + fun ~s -> iter s + + + +(*********************************************************) + +let create_index_lists elements string_of_ele = + let rec f current acc0 acc1 acc2 = function + [] -> (acc0 :: acc1) @ [acc2] + | ele :: q -> + let s = string_of_ele ele in + match s with + "" -> f current acc0 acc1 (acc2 @ [ele]) q + | _ -> + let first = Char.uppercase s.[0] in + match first with + 'A' .. 'Z' -> + if current = first then + f current acc0 acc1 (acc2 @ [ele]) q + else + f first acc0 (acc1 @ [acc2]) [ele] q + | _ -> + f current (acc0 @ [ele]) acc1 acc2 q + in + f '_' [] [] [] elements + + +(*** for labels *) + +let is_optional = Btype.is_optional +let label_name = Btype.label_name + +let remove_option typ = + let rec iter t = + match t with + | Types.Tconstr(path, [ty], _) when Path.same path Predef.path_option -> ty.Types.desc + | Types.Tconstr _ + | Types.Tvar + | Types.Tunivar + | Types.Tpoly _ + | Types.Tarrow _ + | Types.Ttuple _ + | Types.Tobject _ + | Types.Tfield _ + | Types.Tnil + | Types.Tvariant _ -> t + | Types.Tlink t2 + | Types.Tsubst t2 -> iter t2.Types.desc + in + { typ with Types.desc = iter typ.Types.desc } diff --git a/ocamldoc/odoc_misc.mli b/ocamldoc/odoc_misc.mli new file mode 100644 index 0000000..ef83dbe --- /dev/null +++ b/ocamldoc/odoc_misc.mli @@ -0,0 +1,115 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_misc.mli,v 1.13 2006-01-04 16:55:50 doligez Exp $ *) + +(** Miscelaneous functions *) + +(** [no_blanks s] returns the given string without any blank + characters, i.e. '\n' '\r' ' ' '\t'. +*) +val no_blanks : string -> string + +(** This function returns a file in the form of one string.*) +val input_file_as_string : string -> string + +(** [split_with_blanks s] splits the given string [s] according to blanks. *) +val split_with_blanks : string -> string list + +(** This function creates a string from a Longident.t .*) +val string_of_longident : Longident.t -> string + +(** This function returns the list of (label, type_expr) describing + the methods of a type_expr in a Tobject.*) +val get_fields : Types.type_expr -> (string * Types.type_expr) list + +(** get a string from a text *) +val string_of_text : Odoc_types.text -> string + +(** @return a string for an authors list. *) +val string_of_author_list : string list -> string + +(** @return a string for the given optional version information.*) +val string_of_version_opt : string option -> string + +(** @return a string for the given optional since information.*) +val string_of_since_opt : string option -> string + +(** @return a string for the given list of raised exceptions.*) +val string_of_raised_exceptions : (string * Odoc_types.text) list -> string + +(** @return a string for the given "see also" reference.*) +val string_of_see : Odoc_types.see_ref * Odoc_types.text -> string + +(** @return a string for the given list of "see also" references.*) +val string_of_sees : (Odoc_types.see_ref * Odoc_types.text) list -> string + +(** @return a string for the given optional return information.*) +val string_of_return_opt : Odoc_types.text option -> string + +(** get a string from a Odoc_info.info structure *) +val string_of_info : Odoc_types.info -> string + +(** Apply a function to an optional value. *) +val apply_opt : ('a -> 'b) -> 'a option -> 'b option + +(** Return a string representing a date given as a number of seconds + since 1970. The hour is optionnaly displayed. *) +val string_of_date : ?hour:bool -> float -> string + +(** Return the first sentence (until the first dot) of a text. + Don't stop in the middle of [Code], [Verbatim], [List], [Lnum], + [Latex], [Link], or [Ref]. *) +val first_sentence_of_text : Odoc_types.text -> Odoc_types.text + +(** Return the first sentence (until the first dot) of a text, + and the remaining text after. + Don't stop in the middle of [Code], [Verbatim], [List], [Lnum], + [Latex], [Link], or [Ref]. *) +val first_sentence_and_rest_of_text : + Odoc_types.text -> Odoc_types.text * Odoc_types.text + +(** Return the given [text] without any title or list. *) +val text_no_title_no_list : Odoc_types.text -> Odoc_types.text + +(** [concat sep l] concats the given list of text [l], each separated with + the text [sep]. *) +val text_concat : Odoc_types.text -> Odoc_types.text list -> Odoc_types.text + +(** Return the list of titles in a [text]. + A title is a title level, an optional label and a text.*) +val get_titles_in_text : Odoc_types.text -> (int * string option * Odoc_types.text) list + +(** Take a sorted list of elements, a function to get the name + of an element and return the list of list of elements, + where each list group elements beginning by the same letter. + Since the original list is sorted, elements whose name does not + begin with a letter should be in the first returned list.*) +val create_index_lists : 'a list -> ('a -> string) -> 'a list list + +(** [remove_ending_newline s] returns [s] without the optional ending newline. *) +val remove_ending_newline : string -> string + +(** [search_string_backward pat s] searches backward string [pat] in string [s]. + Return position in string [s] where [pat] appears, orelse raise [Not_found]. *) +val search_string_backward : pat: string -> s: string -> int + +(** Take a type and remove the option top constructor. This is + useful when printing labels, we we then remove the top option contructor + for optional labels.*) +val remove_option : Types.type_expr -> Types.type_expr + +(** Return [true] if the given label is optional.*) +val is_optional : string -> bool + +(** Return the label name for the given label, + i.e. removes the beginning '?' if present.*) +val label_name : string -> string diff --git a/ocamldoc/odoc_module.ml b/ocamldoc/odoc_module.ml new file mode 100644 index 0000000..7dd018d --- /dev/null +++ b/ocamldoc/odoc_module.ml @@ -0,0 +1,526 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_module.ml,v 1.12 2006-09-20 11:14:37 doligez Exp $ *) + +(** Representation and manipulation of modules and module types. *) + +let print_DEBUG s = print_string s ; print_newline () + +module Name = Odoc_name + +(** To keep the order of elements in a module. *) +type module_element = + Element_module of t_module + | Element_module_type of t_module_type + | Element_included_module of included_module + | Element_class of Odoc_class.t_class + | Element_class_type of Odoc_class.t_class_type + | Element_value of Odoc_value.t_value + | Element_exception of Odoc_exception.t_exception + | Element_type of Odoc_type.t_type + | Element_module_comment of Odoc_types.text + +(** Used where we can reference t_module or t_module_type *) +and mmt = + | Mod of t_module + | Modtype of t_module_type + +and included_module = { + im_name : Name.t ; (** the name of the included module *) + mutable im_module : mmt option ; (** the included module or module type *) + mutable im_info : Odoc_types.info option ; (** comment associated to the includ directive *) + } + +and module_alias = { + ma_name : Name.t ; + mutable ma_module : mmt option ; (** the real module or module type if we could associate it *) + } + +and module_parameter = { + mp_name : string ; (** the name *) + mp_type : Types.module_type ; (** the type *) + mp_type_code : string ; (** the original code *) + mp_kind : module_type_kind ; (** the way the parameter was built *) + } + +(** Different kinds of module. *) +and module_kind = + | Module_struct of module_element list + | Module_alias of module_alias (** complete name and corresponding module if we found it *) + | Module_functor of module_parameter * module_kind + | Module_apply of module_kind * module_kind + | Module_with of module_type_kind * string + | Module_constraint of module_kind * module_type_kind + +(** Representation of a module. *) +and t_module = { + m_name : Name.t ; + mutable m_type : Types.module_type ; + mutable m_info : Odoc_types.info option ; + m_is_interface : bool ; (** true for modules read from interface files *) + m_file : string ; (** the file the module is defined in. *) + mutable m_kind : module_kind ; + mutable m_loc : Odoc_types.location ; + mutable m_top_deps : Name.t list ; (** The toplevels module names this module depends on. *) + mutable m_code : string option ; (** The whole code of the module *) + mutable m_code_intf : string option ; (** The whole code of the interface of the module *) + m_text_only : bool ; (** [true] if the module comes from a text file *) + } + +and module_type_alias = { + mta_name : Name.t ; + mutable mta_module : t_module_type option ; (** the real module type if we could associate it *) + } + +(** Different kinds of module type. *) +and module_type_kind = + | Module_type_struct of module_element list + | Module_type_functor of module_parameter * module_type_kind + | Module_type_alias of module_type_alias (** complete name and corresponding module type if we found it *) + | Module_type_with of module_type_kind * string (** the module type kind and the code of the with constraint *) + +(** Representation of a module type. *) +and t_module_type = { + mt_name : Name.t ; + mutable mt_info : Odoc_types.info option ; + mutable mt_type : Types.module_type option ; (** [None] = abstract module type *) + mt_is_interface : bool ; (** true for modules read from interface files *) + mt_file : string ; (** the file the module type is defined in. *) + mutable mt_kind : module_type_kind option ; (** [None] = abstract module type if mt_type = None ; + Always [None] when the module type was extracted from the implementation file. *) + mutable mt_loc : Odoc_types.location ; + } + + +(** {2 Functions} *) + +(** Returns the list of values from a list of module_element. *) +let values l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_value v -> acc @ [v] + | _ -> acc + ) + [] + l + +(** Returns the list of types from a list of module_element. *) +let types l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_type t -> acc @ [t] + | _ -> acc + ) + [] + l + +(** Returns the list of exceptions from a list of module_element. *) +let exceptions l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_exception e -> acc @ [e] + | _ -> acc + ) + [] + l + +(** Returns the list of classes from a list of module_element. *) +let classes l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_class c -> acc @ [c] + | _ -> acc + ) + [] + l + +(** Returns the list of class types from a list of module_element. *) +let class_types l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_class_type ct -> acc @ [ct] + | _ -> acc + ) + [] + l + +(** Returns the list of modules from a list of module_element. *) +let modules l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_module m -> acc @ [m] + | _ -> acc + ) + [] + l + +(** Returns the list of module types from a list of module_element. *) +let mod_types l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_module_type mt -> acc @ [mt] + | _ -> acc + ) + [] + l + +(** Returns the list of module comment from a list of module_element. *) +let comments l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_module_comment t -> acc @ [t] + | _ -> acc + ) + [] + l + +(** Returns the list of included modules from a list of module_element. *) +let included_modules l = + List.fold_left + (fun acc -> fun ele -> + match ele with + Element_included_module m -> acc @ [m] + | _ -> acc + ) + [] + l + +(** Returns the list of elements of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let rec module_elements ?(trans=true) m = + let rec iter_kind = function + Module_struct l -> + print_DEBUG "Odoc_module.module_element: Module_struct"; + l + | Module_alias ma -> + print_DEBUG "Odoc_module.module_element: Module_alias"; + if trans then + match ma.ma_module with + None -> [] + | Some (Mod m) -> module_elements m + | Some (Modtype mt) -> module_type_elements mt + else + [] + | Module_functor (_, k) + | Module_apply (k, _) -> + print_DEBUG "Odoc_module.module_element: Module_functor ou Module_apply"; + iter_kind k + | Module_with (tk,_) -> + print_DEBUG "Odoc_module.module_element: Module_with"; + module_type_elements ~trans: trans + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc ; + } + | Module_constraint (k, tk) -> + print_DEBUG "Odoc_module.module_element: Module_constraint"; + (* A VOIR : utiliser k ou tk ? *) + module_elements ~trans: trans + { m_name = "" ; + m_info = None ; + m_type = Types.Tmty_signature [] ; + m_is_interface = false ; m_file = "" ; m_kind = k ; + m_loc = Odoc_types.dummy_loc ; + m_top_deps = [] ; + m_code = None ; + m_code_intf = None ; + m_text_only = false ; + } +(* + module_type_elements ~trans: trans + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } +*) + in + iter_kind m.m_kind + +(** Returns the list of elements of a module type. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +and module_type_elements ?(trans=true) mt = + let rec iter_kind = function + | None -> [] + | Some (Module_type_struct l) -> l + | Some (Module_type_functor (_, k)) -> iter_kind (Some k) + | Some (Module_type_with (k, _)) -> + if trans then + iter_kind (Some k) + else + [] + | Some (Module_type_alias mta) -> + if trans then + match mta.mta_module with + None -> [] + | Some mt -> module_type_elements mt + else + [] + in + iter_kind mt.mt_kind + +(** Returns the list of values of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_values ?(trans=true) m = values (module_elements ~trans m) + +(** Returns the list of functional values of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_functions ?(trans=true) m = + List.filter + (fun v -> Odoc_value.is_function v) + (values (module_elements ~trans m)) + +(** Returns the list of non-functional values of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_simple_values ?(trans=true) m = + List.filter + (fun v -> not (Odoc_value.is_function v)) + (values (module_elements ~trans m)) + +(** Returns the list of types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_types ?(trans=true) m = types (module_elements ~trans m) + +(** Returns the list of excptions of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_exceptions ?(trans=true) m = exceptions (module_elements ~trans m) + +(** Returns the list of classes of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_classes ?(trans=true) m = classes (module_elements ~trans m) + +(** Returns the list of class types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_class_types ?(trans=true) m = class_types (module_elements ~trans m) + +(** Returns the list of modules of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_modules ?(trans=true) m = modules (module_elements ~trans m) + +(** Returns the list of module types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_module_types ?(trans=true) m = mod_types (module_elements ~trans m) + +(** Returns the list of included module of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_included_modules ?(trans=true) m = included_modules (module_elements ~trans m) + +(** Returns the list of comments of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_comments ?(trans=true) m = comments (module_elements ~trans m) + +(** Access to the parameters, for a functor type. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let rec module_type_parameters ?(trans=true) mt = + let rec iter k = + match k with + Some (Module_type_functor (p, k2)) -> + let param = + (* we create the couple (parameter, description opt), using + the description of the parameter if we can find it in the comment.*) + match mt.mt_info with + None -> (p, None) + | Some i -> + try + let d = List.assoc p.mp_name i.Odoc_types.i_params in + (p, Some d) + with + Not_found -> + (p, None) + in + param :: (iter (Some k2)) + | Some (Module_type_alias mta) -> + if trans then + match mta.mta_module with + None -> [] + | Some mt2 -> module_type_parameters ~trans mt2 + else + [] + | Some (Module_type_with (k, _)) -> + if trans then + iter (Some k) + else + [] + | Some (Module_type_struct _) -> + [] + | None -> + [] + in + iter mt.mt_kind + +(** Access to the parameters, for a functor. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +and module_parameters ?(trans=true) m = + let rec iter = function + Module_functor (p, k) -> + let param = + (* we create the couple (parameter, description opt), using + the description of the parameter if we can find it in the comment.*) + match m.m_info with + None ->(p, None) + | Some i -> + try + let d = List.assoc p.mp_name i.Odoc_types.i_params in + (p, Some d) + with + Not_found -> + (p, None) + in + param :: (iter k) + + | Module_alias ma -> + if trans then + match ma.ma_module with + None -> [] + | Some (Mod m) -> module_parameters ~trans m + | Some (Modtype mt) -> module_type_parameters ~trans mt + else + [] + | Module_constraint (k, tk) -> + module_type_parameters ~trans: trans + { mt_name = "" ; mt_info = None ; mt_type = None ; + mt_is_interface = false ; mt_file = "" ; mt_kind = Some tk ; + mt_loc = Odoc_types.dummy_loc } + | Module_struct _ + | Module_apply _ + | Module_with _ -> + [] + in + iter m.m_kind + +(** access to all submodules and sudmobules of submodules ... of the given module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let rec module_all_submodules ?(trans=true) m = + let l = module_modules ~trans m in + List.fold_left + (fun acc -> fun m -> acc @ (module_all_submodules ~trans m)) + l + l + +(** The module type is a functor if is defined as a functor or if it is an alias for a functor. *) +let rec module_type_is_functor mt = + let rec iter k = + match k with + Some (Module_type_functor _) -> true + | Some (Module_type_alias mta) -> + ( + match mta.mta_module with + None -> false + | Some mtyp -> module_type_is_functor mtyp + ) + | Some (Module_type_with (k, _)) -> + iter (Some k) + | Some (Module_type_struct _) + | None -> false + in + iter mt.mt_kind + +(** The module is a functor if is defined as a functor or if it is an alias for a functor. *) +let module_is_functor m = + let rec iter = function + Module_functor _ -> true + | Module_alias ma -> + ( + match ma.ma_module with + None -> false + | Some (Mod mo) -> iter mo.m_kind + | Some (Modtype mt) -> module_type_is_functor mt + ) + | Module_constraint (k, _) -> + iter k + | _ -> false + in + iter m.m_kind + +(** Returns the list of values of a module type. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_values ?(trans=true) m = values (module_type_elements ~trans m) + +(** Returns the list of types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_types ?(trans=true) m = types (module_type_elements ~trans m) + +(** Returns the list of excptions of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_exceptions ?(trans=true) m = exceptions (module_type_elements ~trans m) + +(** Returns the list of classes of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_classes ?(trans=true) m = classes (module_type_elements ~trans m) + +(** Returns the list of class types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_class_types ?(trans=true) m = class_types (module_type_elements ~trans m) + +(** Returns the list of modules of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_modules ?(trans=true) m = modules (module_type_elements ~trans m) + +(** Returns the list of module types of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_module_types ?(trans=true) m = mod_types (module_type_elements ~trans m) + +(** Returns the list of included module of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_included_modules ?(trans=true) m = included_modules (module_type_elements ~trans m) + +(** Returns the list of comments of a module. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_comments ?(trans=true) m = comments (module_type_elements ~trans m) + +(** Returns the list of functional values of a module type. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_functions ?(trans=true) mt = + List.filter + (fun v -> Odoc_value.is_function v) + (values (module_type_elements ~trans mt)) + +(** Returns the list of non-functional values of a module type. + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let module_type_simple_values ?(trans=true) mt = + List.filter + (fun v -> not (Odoc_value.is_function v)) + (values (module_type_elements ~trans mt)) + +(** {2 Functions for modules and module types} *) + +(** The list of classes defined in this module and all its modules, functors, .... + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +let rec module_all_classes ?(trans=true) m = + List.fold_left + (fun acc -> fun m -> acc @ (module_all_classes ~trans m)) + ( + List.fold_left + (fun acc -> fun mtyp -> acc @ (module_type_all_classes ~trans mtyp)) + (module_classes ~trans m) + (module_module_types ~trans m) + ) + (module_modules ~trans m) + +(** The list of classes defined in this module type and all its modules, functors, .... + @param trans indicates if, for aliased modules, we must perform a transitive search.*) +and module_type_all_classes ?(trans=true) mt = + List.fold_left + (fun acc -> fun m -> acc @ (module_all_classes ~trans m)) + ( + List.fold_left + (fun acc -> fun mtyp -> acc @ (module_type_all_classes ~trans mtyp)) + (module_type_classes ~trans mt) + (module_type_module_types ~trans mt) + ) + (module_type_modules ~trans mt) diff --git a/ocamldoc/odoc_name.ml b/ocamldoc/odoc_name.ml new file mode 100644 index 0000000..bdadd46 --- /dev/null +++ b/ocamldoc/odoc_name.ml @@ -0,0 +1,176 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_name.ml,v 1.10 2006-07-06 07:19:06 pouillar Exp $ *) + +(** Representation of element names. *) + +let infix_chars = [ '|' ; + '<' ; + '>' ; + '@' ; + '^' ; + '&' ; + '+' ; + '-' ; + '*' ; + '/' ; + '$' ; + '%' ; + '=' ; + ':' ; + '~' ; + '!' ; + ] + +type t = string + +let parens_if_infix name = + match name with + "" -> "" + | s -> + if List.mem s.[0] infix_chars then + "("^s^")" + else + s + +let cut name = + match name with + "" -> ("", "") + | s -> + let len = String.length s in + match s.[len-1] with + ')' -> + ( + let j = ref 0 in + let buf = [|Buffer.create len ; Buffer.create len |] in + for i = 0 to len - 1 do + match s.[i] with + '.' when !j = 0 -> + if i < len - 1 then + match s.[i+1] with + '(' -> + j := 1 + | _ -> + Buffer.add_char buf.(!j) '.' + else + Buffer.add_char buf.(!j) s.[i] + | c -> + Buffer.add_char buf.(!j) c + done; + (Buffer.contents buf.(0), Buffer.contents buf.(1)) + ) + | _ -> + match List.rev (Str.split (Str.regexp_string ".") s) with + [] -> ("", "") + | h :: q -> + (String.concat "." (List.rev q), h) + +let simple name = snd (cut name) +let father name = fst (cut name) + +let concat n1 n2 = n1^"."^n2 + +let head_and_tail n = + try + let pos = String.index n '.' in + if pos > 0 then + let h = String.sub n 0 pos in + try + ignore (String.index h '('); + (n, "") + with + Not_found -> + let len = String.length n in + if pos >= (len - 1) then + (h, "") + else + (h, String.sub n (pos + 1) (len - pos - 1)) + else + (n, "") + with + Not_found -> (n, "") + +let head n = fst (head_and_tail n) +let tail n = snd (head_and_tail n) + +let depth name = + try + List.length (Str.split (Str.regexp "\\.") name) + with + _ -> 1 + +let prefix n1 n2 = + (n1 <> n2) & + (try + let len1 = String.length n1 in + ((String.sub n2 0 len1) = n1) & + (n2.[len1] = '.') + with _ -> false) + +let rec get_relative_raw n1 n2 = + let (f1,s1) = head_and_tail n1 in + let (f2,s2) = head_and_tail n2 in + if f1 = f2 then + if f2 = s2 or s2 = "" then + s2 + else + if f1 = s1 or s1 = "" then + s2 + else + get_relative_raw s1 s2 + else + n2 + +let get_relative n1 n2 = + if prefix n1 n2 then + let len1 = String.length n1 in + try + String.sub n2 (len1+1) ((String.length n2) - len1 - 1) + with + _ -> n2 + else + n2 + +let hide_given_modules l s = + let rec iter = function + [] -> s + | h :: q -> + let s2 = get_relative h s in + if s = s2 then + iter q + else + s2 + in + iter l + +let qualified name = String.contains name '.' + +let from_ident ident = Ident.name ident + + +let from_path path = Path.name path + +let to_path n = + match + List.fold_left + (fun acc_opt -> fun s -> + match acc_opt with + None -> Some (Path.Pident (Ident.create s)) + | Some acc -> Some (Path.Pdot (acc, s, 0))) + None + (Str.split (Str.regexp "\\.") n) + with + None -> raise (Failure "to_path") + | Some p -> p + +let from_longident = Odoc_misc.string_of_longident + diff --git a/ocamldoc/odoc_name.mli b/ocamldoc/odoc_name.mli new file mode 100644 index 0000000..f2211e9 --- /dev/null +++ b/ocamldoc/odoc_name.mli @@ -0,0 +1,66 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_name.mli,v 1.4 2004-03-26 09:09:50 guesdon Exp $ *) + +(** Representation of element names. *) + +type t = string + +(** Add parenthesis to the given simple name if needed. *) +val parens_if_infix : t -> t + +(** Return a simple name from a name.*) +val simple : t -> t + +(** Return the name of the 'father' (like dirname for a file name).*) +val father : t -> t + +(** Concatenates two names. *) +val concat : t -> t -> t + +(** Returns the head of a name. *) +val head : t -> t + +(** Returns the depth of the name, i.e. the numer of levels to the root. + Example : [Toto.Tutu.name] has depth 3. *) +val depth : t -> int + +(** Returns true if the first name is a prefix of the second name. + If the two names are equals, then if is false (strict prefix).*) +val prefix : t -> t -> bool + +(** Take two names n1 and n2 = n3.n4 and return n4 if n3=n1 or else n2. *) +val get_relative : t -> t -> t + +(** Take two names n1=n3.n4 and n2 = n5.n6 and return n6 if n3=n5 or else n2. *) +val get_relative_raw : t -> t -> t + +(** Take a list of module names to hide and a name, + and return the name when the module name (or part of it) + was removed, according to the list of module names to hide.*) +val hide_given_modules : t list -> t -> t + +(** Indicate if a name if qualified or not. *) +val qualified : t -> bool + +(** Get a name from an [Ident.t]. *) +val from_ident : Ident.t -> t + +(** Get a name from a [Path.t]. *) +val from_path : Path.t -> t + +(** Get a [Path.t] from a name.*) +val to_path : t -> Path.t + +(** Get a name from a [Longident.t].*) +val from_longident : Longident.t -> t + diff --git a/ocamldoc/odoc_ocamlhtml.mll b/ocamldoc/odoc_ocamlhtml.mll new file mode 100644 index 0000000..9839f31 --- /dev/null +++ b/ocamldoc/odoc_ocamlhtml.mll @@ -0,0 +1,545 @@ + +{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_ocamlhtml.mll,v 1.11 2008-12-03 18:09:09 doligez Exp $ *) + +(** Generation of html code to display OCaml code. *) +open Lexing + +exception Fatal_error + +let fatal_error msg = + prerr_string ">> Fatal error: "; prerr_endline msg; raise Fatal_error + +type error = + | Illegal_character of char + | Unterminated_comment + | Unterminated_string + | Unterminated_string_in_comment + | Keyword_as_label of string +;; + +exception Error of error * int * int + +let base_escape_strings = [ + ("&", "&") ; + ("<", "<") ; + (">", ">") ; +] + +let pre_escape_strings = [ + (" ", " ") ; + ("\n", "<br>\n") ; + ("\t", "        ") ; + ] + + +let pre = ref false +let fmt = ref Format.str_formatter + +(** Escape the strings which would clash with html syntax, + and some other strings if we want to get a PRE style.*) +let escape s = + List.fold_left + (fun acc -> fun (s, s2) -> Str.global_replace (Str.regexp s) s2 acc) + s + (if !pre then base_escape_strings @ pre_escape_strings else base_escape_strings) + +(** Escape the strings which would clash with html syntax. *) +let escape_base s = + List.fold_left + (fun acc -> fun (s, s2) -> Str.global_replace (Str.regexp s) s2 acc) + s + base_escape_strings + +(** The output functions *) + +let print ?(esc=true) s = + Format.pp_print_string !fmt (if esc then escape s else s) +;; + +let print_class ?(esc=true) cl s = + print ~esc: false ("<span class=\""^cl^"\">"^ + (if esc then escape s else s)^ + "</span>") +;; + +(** The table of keywords with colors *) +let create_hashtable size init = + let tbl = Hashtbl.create size in + List.iter (fun (key, data) -> Hashtbl.add tbl key data) init; + tbl + +(** The function used to return html code for the given comment body. *) +let html_of_comment = ref + (fun (s : string) -> "<b>Odoc_ocamlhtml.html_of_comment not initialized</b>") + +let keyword_table = + create_hashtable 149 [ + "and", "keyword" ; + "as", "keyword" ; + "assert", "keyword" ; + "begin", "keyword" ; + "class", "keyword" ; + "constraint", "keyword" ; + "do", "keyword" ; + "done", "keyword" ; + "downto", "keyword" ; + "else", "keyword" ; + "end", "keyword" ; + "exception", "keyword" ; + "external", "keyword" ; + "false", "keyword" ; + "for", "keyword" ; + "fun", "keyword" ; + "function", "keyword" ; + "functor", "keyword" ; + "if", "keyword" ; + "in", "keyword" ; + "include", "keyword" ; + "inherit", "keyword" ; + "initializer", "keyword" ; + "lazy", "keyword" ; + "let", "keyword" ; + "match", "keyword" ; + "method", "keyword" ; + "module", "keyword" ; + "mutable", "keyword" ; + "new", "keyword" ; + "object", "keyword" ; + "of", "keyword" ; + "open", "keyword" ; + "or", "keyword" ; + "parser", "keyword" ; + "private", "keyword" ; + "rec", "keyword" ; + "sig", "keyword" ; + "struct", "keyword" ; + "then", "keyword" ; + "to", "keyword" ; + "true", "keyword" ; + "try", "keyword" ; + "type", "keyword" ; + "val", "keyword" ; + "virtual", "keyword" ; + "when", "keyword" ; + "while", "keyword" ; + "with", "keyword" ; + + "mod", "keyword" ; + "land", "keyword" ; + "lor", "keyword" ; + "lxor", "keyword" ; + "lsl", "keyword" ; + "lsr", "keyword" ; + "asr", "keyword" ; +] + +let kwsign_class = "keywordsign" +let constructor_class = "constructor" +let comment_class = "comment" +let string_class = "string" +let code_class = "code" + + +(** To buffer and print comments *) + + +let margin = ref 0 + +let comment_buffer = Buffer.create 32 +let reset_comment_buffer () = Buffer.reset comment_buffer +let store_comment_char = Buffer.add_char comment_buffer +let add_comment_string = Buffer.add_string comment_buffer + +let make_margin () = + let rec iter n = + if n <= 0 then "" + else " "^(iter (n-1)) + in + iter !margin + +let print_comment () = + let s = Buffer.contents comment_buffer in + let len = String.length s in + let code = + if len < 1 then + "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" + else + match s.[0] with + '*' -> + ( + try + let html = !html_of_comment (String.sub s 1 (len-1)) in + "</code><table><tr><td>"^(make_margin ())^"</td><td>"^ + "<span class=\""^comment_class^"\">"^ + "(**"^html^"*)"^ + "</span></td></tr></table><code class=\""^code_class^"\">" + with + e -> + prerr_endline (Printexc.to_string e); + "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" + ) + | _ -> + "<span class=\""^comment_class^"\">(*"^(escape s)^"*)</span>" + in + print ~esc: false code + +(** To buffer string literals *) + +let string_buffer = Buffer.create 32 +let reset_string_buffer () = Buffer.reset string_buffer +let store_string_char = Buffer.add_char string_buffer +let get_stored_string () = + let s = Buffer.contents string_buffer in + s + +(** To translate escape sequences *) + +let char_for_backslash = function + | 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in + Char.chr(c land 0xFF) + +let char_for_hexa_code lexbuf i = + let c = 16 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) in + Char.chr(c land 0xFF) + +(** To store the position of the beginning of a string and comment *) +let string_start_pos = ref 0;; +let comment_start_pos = ref [];; +let in_comment () = !comment_start_pos <> [];; + +(** Error report *) + +open Format + +let report_error ppf = function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf "This comment contains an unterminated string literal" + | Keyword_as_label kwd -> + fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd +;; + +} + +let blank = [' ' '\010' '\013' '\009' '\012'] +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let symbolchar = + ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] +let decimal_literal = ['0'-'9']+ +let hex_literal = '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']+ +let oct_literal = '0' ['o' 'O'] ['0'-'7']+ +let bin_literal = '0' ['b' 'B'] ['0'-'1']+ +let float_literal = + ['0'-'9']+ ('.' ['0'-'9']* )? (['e' 'E'] ['+' '-']? ['0'-'9']+)? + +rule token = parse + blank + { + let s = Lexing.lexeme lexbuf in + ( + match s with + " " -> incr margin + | "\t" -> margin := !margin + 8 + | "\n" -> margin := 0 + | _ -> () + ); + print s; + token lexbuf + } + | "_" + { print "_" ; token lexbuf } + | "~" { print "~" ; token lexbuf } + | "~" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Lexing.lexeme_start lexbuf, + Lexing.lexeme_end lexbuf)); + print s ; token lexbuf } + | "?" { print "?" ; token lexbuf } + | "?" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Lexing.lexeme_start lexbuf, + Lexing.lexeme_end lexbuf)); + print s ; token lexbuf } + | lowercase identchar * + { let s = Lexing.lexeme lexbuf in + try + let cl = Hashtbl.find keyword_table s in + (print_class cl s ; token lexbuf ) + with Not_found -> + (print s ; token lexbuf )} + | uppercase identchar * + { print_class constructor_class (Lexing.lexeme lexbuf) ; token lexbuf } (* No capitalized keywords *) + | decimal_literal | hex_literal | oct_literal | bin_literal + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | float_literal + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "\"" + { reset_string_buffer(); + let string_start = Lexing.lexeme_start lexbuf in + string_start_pos := string_start; + string lexbuf; + lexbuf.Lexing.lex_start_pos <- + string_start - lexbuf.Lexing.lex_abs_pos; + print_class string_class ("\""^(get_stored_string())^"\"") ; + token lexbuf } + | "'" [^ '\\' '\''] "'" + { print_class string_class (Lexing.lexeme lexbuf) ; + token lexbuf } + | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { print_class string_class (Lexing.lexeme lexbuf ) ; + token lexbuf } + | "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { print_class string_class (Lexing.lexeme lexbuf ) ; + token lexbuf } + | "(*" + { + reset_comment_buffer (); + comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf ; + print_comment (); + token lexbuf } + | "(*)" + { reset_comment_buffer (); + comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf ; + print_comment (); + token lexbuf + } + | "*)" + { lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + lexbuf.Lexing.lex_curr_p <- + { lexbuf.Lexing.lex_curr_p with + pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - 1 + } ; + print (Lexing.lexeme lexbuf) ; + token lexbuf + } + | "#" [' ' '\t']* ['0'-'9']+ [^ '\n' '\r'] * ('\n' | '\r' | "\r\n") + (* # linenum ... *) + { + print (Lexing.lexeme lexbuf); + token lexbuf + } + | "#" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "&" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "&&" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "`" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "'" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "(" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ")" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "*" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "," { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "??" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "->" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "." { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ".." { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ":" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "::" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ":=" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ":>" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ";" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ";;" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "<" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "<-" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "=" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "[" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "[|" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "[<" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "]" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "{" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "{<" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "|" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "||" { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | "|]" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ">" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ">]" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "}" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ">}" { print (Lexing.lexeme lexbuf) ; token lexbuf } + + | "!=" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "+" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "-" { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "-." { print (Lexing.lexeme lexbuf) ; token lexbuf } + + | "!" symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ['~' '?'] symbolchar + + { print_class kwsign_class (Lexing.lexeme lexbuf) ; token lexbuf } + | ['=' '<' '>' '|' '&' '$'] symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ['@' '^'] symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ['+' '-'] symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | "**" symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | ['*' '/' '%'] symbolchar * + { print (Lexing.lexeme lexbuf) ; token lexbuf } + | eof { () } + | _ + { raise (Error(Illegal_character ((Lexing.lexeme lexbuf).[0]), + Lexing.lexeme_start lexbuf, Lexing.lexeme_end lexbuf)) } + +and comment = parse + "(*" + { comment_start_pos := Lexing.lexeme_start lexbuf :: !comment_start_pos; + store_comment_char '('; + store_comment_char '*'; + comment lexbuf; + } + | "*)" + { match !comment_start_pos with + | [] -> assert false + | [x] -> comment_start_pos := [] + | _ :: l -> + store_comment_char '*'; + store_comment_char ')'; + comment_start_pos := l; + comment lexbuf; + } +(* These filters are useless + | "\"" + { reset_string_buffer(); + string_start_pos := Lexing.lexeme_start lexbuf; + store_comment_char '"'; + begin + try string lexbuf; add_comment_string ((get_stored_string()^"\"")) + with Error (Unterminated_string, _, _) -> + let st = List.hd !comment_start_pos in + raise (Error (Unterminated_string_in_comment, st, st + 2)) + end; + comment lexbuf } + | "'" [^ '\\' '\''] "'" + { + store_comment_char '\''; + store_comment_char (Lexing.lexeme_char lexbuf 1); + store_comment_char '\''; + comment lexbuf } + | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { + store_comment_char '\''; + store_comment_char '\\'; + store_comment_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)) ; + store_comment_char '\''; + comment lexbuf } + | "\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] + { + store_comment_char(char_for_decimal_code lexbuf 1); + comment lexbuf } + | "\\x" ['0'-'9' 'A'-'Z' 'a'-'z' ] ['0'-'9' 'A'-'Z' 'a'-'z'] + { + store_comment_char(char_for_hexa_code lexbuf 2); + string lexbuf } + | "''" + { + store_comment_char '\''; + store_comment_char '\''; + comment lexbuf } +*) + | eof + { let st = List.hd !comment_start_pos in + raise (Error (Unterminated_comment, st, st + 2)); + } + | _ + { store_comment_char(Lexing.lexeme_char lexbuf 0); + comment lexbuf } + +and string = parse + '"' + { () } + | '\\' ("\010" | "\013" | "\013\010") [' ' '\009'] * + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r' ] + { Buffer.add_string string_buffer (Lexing.lexeme lexbuf) ; + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { + Buffer.add_string string_buffer (Lexing.lexeme lexbuf) ; + string lexbuf + } + | '\\' 'x' ['0'-'9' 'A'-'Z' 'a'-'z' ] ['0'-'9' 'A'-'Z' 'a'-'z'] + { Buffer.add_string string_buffer (Lexing.lexeme lexbuf) ; + string lexbuf } + | eof + { raise (Error (Unterminated_string, + !string_start_pos, !string_start_pos+1)) } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } +{ + +let html_of_code b ?(with_pre=true) code = + let old_pre = !pre in + let old_margin = !margin in + let old_comment_buffer = Buffer.contents comment_buffer in + let old_string_buffer = Buffer.contents string_buffer in + let buf = Buffer.create 256 in + let old_fmt = !fmt in + fmt := Format.formatter_of_buffer buf ; + pre := with_pre; + margin := 0; + + let start = "<code class=\""^code_class^"\">" in + let ending = "</code>" in + let html = + ( + try + print ~esc: false start ; + let lexbuf = Lexing.from_string code in + let _ = token lexbuf in + print ~esc: false ending ; + Format.pp_print_flush !fmt () ; + Buffer.contents buf + with + _ -> + (* flush str_formatter because we already output + something in it *) + Format.pp_print_flush !fmt () ; + start^code^ending + ) + in + pre := old_pre; + margin := old_margin ; + Buffer.reset comment_buffer; + Buffer.add_string comment_buffer old_comment_buffer ; + Buffer.reset string_buffer; + Buffer.add_string string_buffer old_string_buffer ; + fmt := old_fmt ; + + Buffer.add_string b html + +} diff --git a/ocamldoc/odoc_opt.ml b/ocamldoc/odoc_opt.ml new file mode 100644 index 0000000..80542dc --- /dev/null +++ b/ocamldoc/odoc_opt.ml @@ -0,0 +1,81 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_opt.ml,v 1.6 2006-09-20 11:14:37 doligez Exp $ *) + +(** Main module for native version.*) + +open Config +open Clflags +open Misc +open Format +open Typedtree + +let _ = Odoc_args.bytecode_mode := false + + +let html_generator = new Odoc_html.html +let default_latex_generator = new Odoc_latex.latex +let default_texi_generator = new Odoc_texi.texi +let default_man_generator = new Odoc_man.man +let default_dot_generator = new Odoc_dot.dot +let _ = Odoc_args.parse + (html_generator :> Odoc_args.doc_generator) + (default_latex_generator :> Odoc_args.doc_generator) + (default_texi_generator :> Odoc_args.doc_generator) + (default_man_generator :> Odoc_args.doc_generator) + (default_dot_generator :> Odoc_args.doc_generator) + +let loaded_modules = + List.flatten + (List.map + (fun f -> + Odoc_info.verbose (Odoc_messages.loading f); + try + let l = Odoc_analyse.load_modules f in + Odoc_info.verbose Odoc_messages.ok; + l + with Failure s -> + prerr_endline s ; + incr Odoc_global.errors ; + [] + ) + !Odoc_args.load + ) + +let modules = Odoc_analyse.analyse_files ~init: loaded_modules !Odoc_args.files + +let _ = + match !Odoc_args.dump with + None -> () + | Some f -> + try Odoc_analyse.dump_modules f modules + with Failure s -> + prerr_endline s ; + incr Odoc_global.errors + +let _ = + match !Odoc_args.doc_generator with + None -> + () + | Some gen -> + Odoc_info.verbose Odoc_messages.generating_doc; + gen#generate modules; + Odoc_info.verbose Odoc_messages.ok + +let _ = + if !Odoc_global.errors > 0 then + ( + prerr_endline (Odoc_messages.errors_occured !Odoc_global.errors) ; + exit 1 + ) + else + exit 0 diff --git a/ocamldoc/odoc_parameter.ml b/ocamldoc/odoc_parameter.ml new file mode 100644 index 0000000..fa154a3 --- /dev/null +++ b/ocamldoc/odoc_parameter.ml @@ -0,0 +1,123 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_parameter.ml,v 1.8 2004-04-02 15:10:57 guesdon Exp $ *) + +(** Representation and manipulation of method / function / class parameters. *) + +let print_DEBUG s = print_string s ; print_newline () + +(** Types *) + +(** Representation of a simple parameter name *) +type simple_name = { + sn_name : string ; + sn_type : Types.type_expr ; + mutable sn_text : Odoc_types.text option ; + } + +(** Representation of parameter names. We need it to represent parameter names in tuples. + The value [Tuple ([], t)] stands for an anonymous parameter.*) +type param_info = + | Simple_name of simple_name + | Tuple of param_info list * Types.type_expr + +(** A parameter is just a param_info.*) +type parameter = param_info + +(** Functions *) + +(** acces to the name as a string. For tuples, parenthesis and commas are added. *) +let complete_name p = + let rec iter pi = + match pi with + Simple_name sn -> + sn.sn_name + | Tuple ([], _) -> (* anonymous parameter *) + "??" + | Tuple (pi_list, _) -> + "("^(String.concat "," (List.map iter pi_list))^")" + in + iter p + +(** access to the complete type *) +let typ pi = + match pi with + Simple_name sn -> sn.sn_type + | Tuple (_, typ) -> typ + +(** Update the text of a parameter using a function returning + the optional text associated to a parameter name.*) +let update_parameter_text f p = + let rec iter pi = + match pi with + Simple_name sn -> + sn.sn_text <- f sn.sn_name + | Tuple (l, _) -> + List.iter iter l + in + iter p + +(** access to the description of a specific name. + @raise Not_found if no description is associated to the given name. *) +let desc_by_name pi name = + let rec iter acc pi = + match pi with + Simple_name sn -> + (sn.sn_name, sn.sn_text) :: acc + | Tuple (pi_list, _) -> + List.fold_left iter acc pi_list + in + let l = iter [] pi in + List.assoc name l + + +(** acces to the list of names ; only one for a simple parameter, or + a list for tuples. *) +let names pi = + let rec iter acc pi = + match pi with + Simple_name sn -> + sn.sn_name :: acc + | Tuple (pi_list, _) -> + List.fold_left iter acc pi_list + in + iter [] pi + +(** access to the type of a specific name. + @raise Not_found if no type is associated to the given name. *) +let type_by_name pi name = + let rec iter acc pi = + match pi with + Simple_name sn -> + (sn.sn_name, sn.sn_type) :: acc + | Tuple (pi_list, _) -> + List.fold_left iter acc pi_list + in + let l = iter [] pi in + List.assoc name l + +(** access to the optional description of a parameter name from an optional info structure.*) +let desc_from_info_opt info_opt s = + print_DEBUG "desc_from_info_opt"; + match info_opt with + None -> None + | Some i -> + match s with + "" -> None + | _ -> + try + Some (List.assoc s i.Odoc_types.i_params) + with + Not_found -> + print_DEBUG ("desc_from_info_opt "^s^" not found in\n"); + List.iter (fun (s, _) -> print_DEBUG s) i.Odoc_types.i_params; + None diff --git a/ocamldoc/odoc_parser.mly b/ocamldoc/odoc_parser.mly new file mode 100644 index 0000000..3661c85 --- /dev/null +++ b/ocamldoc/odoc_parser.mly @@ -0,0 +1,158 @@ +%{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_parser.mly,v 1.3 2003-11-24 10:43:11 starynke Exp $ *) + +open Odoc_types +open Odoc_comments_global + +let uppercase = "[A-Z\192-\214\216-\222]" +let identchar = + "[A-Za-z_\192-\214\216-\246\248-\255'0-9]" +let blank = "[ \010\013\009\012]" + +let print_DEBUG s = print_string s; print_newline () +%} + +%token <string * (string option)> Description + +%token <string> See_url +%token <string> See_file +%token <string> See_doc + +%token T_PARAM +%token T_AUTHOR +%token T_VERSION +%token T_SEE +%token T_SINCE +%token T_DEPRECATED +%token T_RAISES +%token T_RETURN +%token <string> T_CUSTOM + +%token EOF + +%token <string> Desc + +/* Start Symbols */ +%start main info_part2 see_info +%type <(string * (string option)) option> main +%type <unit> info_part2 +%type <Odoc_types.see_ref * string> see_info + + +%% +see_info: + see_ref Desc { ($1, $2) } +; + +see_ref: + See_url { Odoc_types.See_url $1 } +| See_file { Odoc_types.See_file $1 } +| See_doc { Odoc_types.See_doc $1 } +; + +main: + Description { Some $1 } +| EOF { None } +; + +info_part2: + element_list EOF { () } +; + +element_list: + element { () } +| element element_list { () } +; + +element: +| param { () } +| author { () } +| version { () } +| see { () } +| since { () } +| deprecated { () } +| raise_exc { () } +| return { () } +| custom { () } +; + +param: + T_PARAM Desc + { + (* isolate the identificator *) + (* we only look for simple id, no pattern nor tuples *) + let s = $2 in + match Str.split (Str.regexp (blank^"+")) s with + [] + | _ :: [] -> + raise (Failure "usage: @param id description") + | id :: _ -> + print_DEBUG ("Identificator "^id); + let reg = identchar^"+" in + print_DEBUG ("reg="^reg); + if Str.string_match (Str.regexp reg) id 0 then + let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in + print_DEBUG ("T_PARAM Desc remain="^remain); + let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in + params := !params @ [(id, remain2)] + else + raise (Failure (id^" is not a valid parameter identificator in \"@param "^s^"\"")) + } +; +author: + T_AUTHOR Desc { authors := !authors @ [ $2 ] } +; +version: + T_VERSION Desc { version := Some $2 } +; +see: + T_SEE Desc { sees := !sees @ [$2] } +; +since: + T_SINCE Desc { since := Some $2 } +; +deprecated: + T_DEPRECATED Desc { deprecated := Some $2 } +; +raise_exc: + T_RAISES Desc + { + (* isolate the exception construtor name *) + let s = $2 in + match Str.split (Str.regexp (blank^"+")) s with + [] + | _ :: [] -> + raise (Failure "usage: @raise Exception description") + | id :: _ -> + print_DEBUG ("exception "^id); + let reg = uppercase^identchar^"*"^"\\(\\."^uppercase^identchar^"*\\)*" in + print_DEBUG ("reg="^reg); + if Str.string_match (Str.regexp reg) id 0 then + let remain = String.sub s (String.length id) ((String.length s) - (String.length id)) in + let remain2 = Str.replace_first (Str.regexp ("^"^blank^"+")) "" remain in + raised_exceptions := !raised_exceptions @ [(id, remain2)] + else + raise (Failure (id^" is not a valid exception constructor in \"@raise "^s^"\"")) + } +; +return: + T_RETURN Desc { return_value := Some $2 } +; + +custom: + T_CUSTOM Desc { customs := !customs @ [($1, $2)] } +; + + +%% diff --git a/ocamldoc/odoc_print.ml b/ocamldoc/odoc_print.ml new file mode 100644 index 0000000..6e4afc7 --- /dev/null +++ b/ocamldoc/odoc_print.ml @@ -0,0 +1,104 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_print.ml,v 1.3 2004-05-18 13:28:00 garrigue Exp $ *) + +open Format + +let new_fmt () = + let buf = Buffer.create 512 in + let fmt = formatter_of_buffer buf in + let flush () = + pp_print_flush fmt (); + let s = Buffer.contents buf in + Buffer.reset buf ; + s + in + (fmt, flush) + +let (type_fmt, flush_type_fmt) = new_fmt () +let _ = + let (out, flush, outnewline, outspace) = + pp_get_all_formatter_output_functions type_fmt () + in + pp_set_all_formatter_output_functions type_fmt + ~out ~flush + ~newline: (fun () -> out "\n " 0 3) + ~spaces: outspace + +let (modtype_fmt, flush_modtype_fmt) = new_fmt () + + + + +let string_of_type_expr t = + Printtyp.mark_loops t; + Printtyp.type_scheme_max ~b_reset_names: false type_fmt t; + flush_type_fmt () + +exception Use_code of string + +(** Return the given module type where methods and vals have been removed + from the signatures. Used when we don't want to print a too long module type. + @param code when the code is given, we raise the [Use_code] exception is we + encouter a signature, to that the calling function can use the code rather + than the "emptied" type. +*) +let simpl_module_type ?code t = + let rec iter t = + match t with + Types.Tmty_ident p -> t + | Types.Tmty_signature _ -> + ( + match code with + None -> Types.Tmty_signature [] + | Some s -> raise (Use_code s) + ) + | Types.Tmty_functor (id, mt1, mt2) -> + Types.Tmty_functor (id, iter mt1, iter mt2) + in + iter t + +let string_of_module_type ?code ?(complete=false) t = + try + let t2 = if complete then t else simpl_module_type ?code t in + Printtyp.modtype modtype_fmt t2; + flush_modtype_fmt () + with + Use_code s -> s + +(** Return the given class type where methods and vals have been removed + from the signatures. Used when we don't want to print a too long class type.*) +let simpl_class_type t = + let rec iter t = + match t with + Types.Tcty_constr (p,texp_list,ct) -> t + | Types.Tcty_signature cs -> + (* on vire les vals et methods pour ne pas qu'elles soient imprimées + quand on affichera le type *) + let tnil = { Types.desc = Types.Tnil ; Types.level = 0; Types.id = 0 } in + Types.Tcty_signature { Types.cty_self = { cs.Types.cty_self with + Types.desc = Types.Tobject (tnil, ref None) }; + Types.cty_vars = Types.Vars.empty ; + Types.cty_concr = Types.Concr.empty ; + Types.cty_inher = [] + } + | Types.Tcty_fun (l, texp, ct) -> + let new_ct = iter ct in + Types.Tcty_fun (l, texp, new_ct) + in + iter t + +let string_of_class_type ?(complete=false) t = + let t2 = if complete then t else simpl_class_type t in + (* A VOIR : ma propre version de Printtyp.class_type pour ne pas faire reset_names *) + Printtyp.class_type modtype_fmt t2; + flush_modtype_fmt () diff --git a/ocamldoc/odoc_print.mli b/ocamldoc/odoc_print.mli new file mode 100644 index 0000000..3dcc8cf --- /dev/null +++ b/ocamldoc/odoc_print.mli @@ -0,0 +1,33 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_print.mli,v 1.2 2004-03-26 09:09:50 guesdon Exp $ *) + +(** Printing functions. *) + +(** This function takes a Types.type_expr and returns a string. + It writes in and flushes [Format.str_formatter].*) +val string_of_type_expr : Types.type_expr -> string + +(** This function returns a string representing a [Types.module_type]. + @param complete indicates if we must print complete signatures + or just [sig end]. Default if [false]. + @param code if [complete = false] and the type contains something else + than identificators and functors, then the given code is used. +*) +val string_of_module_type : ?code: string -> ?complete: bool -> Types.module_type -> string + +(** This function returns a string representing a [Types.class_type]. + @param complete indicates if we must print complete signatures + or just [object end]. Default if [false]. +*) +val string_of_class_type : ?complete: bool -> Types.class_type -> string + diff --git a/ocamldoc/odoc_scan.ml b/ocamldoc/odoc_scan.ml new file mode 100644 index 0000000..b62e25b --- /dev/null +++ b/ocamldoc/odoc_scan.ml @@ -0,0 +1,156 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_scan.ml,v 1.3 2003-11-24 10:43:11 starynke Exp $ *) + +(** Scanning of modules and elements. + + The class scanner defined in this module can be used to + develop generators which perform controls on the elements + and their comments. +*) + +open Odoc_types + +(** Class which defines the scanning of a list of modules and their + elements. Inherit this class to develop your own scanner, by + overriding some methods.*) +class scanner = + object (self) + (** Scan of 'leaf elements'. *) + + method scan_value (v : Odoc_value.t_value) = () + method scan_type (t : Odoc_type.t_type) = () + method scan_exception (e : Odoc_exception.t_exception) = () + method scan_attribute (a : Odoc_value.t_attribute) = () + method scan_method (m : Odoc_value.t_method) = () + method scan_included_module (im : Odoc_module.included_module) = () + + (** Scan of a class. *) + + (** Scan of a comment inside a class. *) + method scan_class_comment (t : text) = () + + (** Override this method to perform controls on the class comment + and params. This method is called before scanning the class elements. + @return true if the class elements must be scanned.*) + method scan_class_pre (c : Odoc_class.t_class) = true + + (** This method scan the elements of the given class. + A VOIR : scan des classes héritées.*) + method scan_class_elements c = + List.iter + (fun ele -> + match ele with + Odoc_class.Class_attribute a -> self#scan_attribute a + | Odoc_class.Class_method m -> self#scan_method m + | Odoc_class.Class_comment t -> self#scan_class_comment t + ) + (Odoc_class.class_elements c) + + (** Scan of a class. Should not be overriden. It calls [scan_class_pre] + and if [scan_class_pre] returns [true], then it calls scan_class_elements.*) + method scan_class c = if self#scan_class_pre c then self#scan_class_elements c + + (** Scan of a class type. *) + + (** Scan of a comment inside a class type. *) + method scan_class_type_comment (t : text) = () + + (** Override this method to perform controls on the class type comment + and form. This method is called before scanning the class type elements. + @return true if the class type elements must be scanned.*) + method scan_class_type_pre (ct : Odoc_class.t_class_type) = true + + (** This method scan the elements of the given class type. + A VOIR : scan des classes héritées.*) + method scan_class_type_elements ct = + List.iter + (fun ele -> + match ele with + Odoc_class.Class_attribute a -> self#scan_attribute a + | Odoc_class.Class_method m -> self#scan_method m + | Odoc_class.Class_comment t -> self#scan_class_type_comment t + ) + (Odoc_class.class_type_elements ct) + + (** Scan of a class type. Should not be overriden. It calls [scan_class_type_pre] + and if [scan_class_type_pre] returns [true], then it calls scan_class_type_elements.*) + method scan_class_type ct = if self#scan_class_type_pre ct then self#scan_class_type_elements ct + + (** Scan of modules. *) + + (** Scan of a comment inside a module. *) + method scan_module_comment (t : text) = () + + (** Override this method to perform controls on the module comment + and form. This method is called before scanning the module elements. + @return true if the module elements must be scanned.*) + method scan_module_pre (m : Odoc_module.t_module) = true + + (** This method scan the elements of the given module. *) + method scan_module_elements m = + List.iter + (fun ele -> + match ele with + Odoc_module.Element_module m -> self#scan_module m + | Odoc_module.Element_module_type mt -> self#scan_module_type mt + | Odoc_module.Element_included_module im -> self#scan_included_module im + | Odoc_module.Element_class c -> self#scan_class c + | Odoc_module.Element_class_type ct -> self#scan_class_type ct + | Odoc_module.Element_value v -> self#scan_value v + | Odoc_module.Element_exception e -> self#scan_exception e + | Odoc_module.Element_type t -> self#scan_type t + | Odoc_module.Element_module_comment t -> self#scan_module_comment t + ) + (Odoc_module.module_elements m) + + (** Scan of a module. Should not be overriden. It calls [scan_module_pre] + and if [scan_module_pre] returns [true], then it calls scan_module_elements.*) + method scan_module m = if self#scan_module_pre m then self#scan_module_elements m + + (** Scan of module types. *) + + (** Scan of a comment inside a module type. *) + method scan_module_type_comment (t : text) = () + + (** Override this method to perform controls on the module type comment + and form. This method is called before scanning the module type elements. + @return true if the module type elements must be scanned. *) + method scan_module_type_pre (mt : Odoc_module.t_module_type) = true + + (** This method scan the elements of the given module type. *) + method scan_module_type_elements mt = + List.iter + (fun ele -> + match ele with + Odoc_module.Element_module m -> self#scan_module m + | Odoc_module.Element_module_type mt -> self#scan_module_type mt + | Odoc_module.Element_included_module im -> self#scan_included_module im + | Odoc_module.Element_class c -> self#scan_class c + | Odoc_module.Element_class_type ct -> self#scan_class_type ct + | Odoc_module.Element_value v -> self#scan_value v + | Odoc_module.Element_exception e -> self#scan_exception e + | Odoc_module.Element_type t -> self#scan_type t + | Odoc_module.Element_module_comment t -> self#scan_module_comment t + ) + (Odoc_module.module_type_elements mt) + + (** Scan of a module type. Should not be overriden. It calls [scan_module_type_pre] + and if [scan_module_type_pre] returns [true], then it calls scan_module_type_elements.*) + method scan_module_type mt = + if self#scan_module_type_pre mt then self#scan_module_type_elements mt + + (** Main scanning method. *) + + (** Scan a list of modules. *) + method scan_module_list l = List.iter self#scan_module l + end diff --git a/ocamldoc/odoc_search.ml b/ocamldoc/odoc_search.ml new file mode 100644 index 0000000..6e0f699 --- /dev/null +++ b/ocamldoc/odoc_search.ml @@ -0,0 +1,635 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_search.ml,v 1.7 2006-01-04 16:55:50 doligez Exp $ *) + +(** Research of elements through modules. *) + +module Name = Odoc_name +open Odoc_parameter +open Odoc_value +open Odoc_type +open Odoc_exception +open Odoc_class +open Odoc_module + +type result_element = + Res_module of t_module + | Res_module_type of t_module_type + | Res_class of t_class + | Res_class_type of t_class_type + | Res_value of t_value + | Res_type of t_type + | Res_exception of t_exception + | Res_attribute of t_attribute + | Res_method of t_method + | Res_section of string * Odoc_types.text + +type result = result_element list + +module type Predicates = + sig + type t + val p_module : t_module -> t -> bool * bool + val p_module_type : t_module_type -> t -> bool * bool + val p_class : t_class -> t -> bool * bool + val p_class_type : t_class_type -> t -> bool * bool + val p_value : t_value -> t -> bool + val p_type : t_type -> t -> bool + val p_exception : t_exception -> t -> bool + val p_attribute : t_attribute -> t -> bool + val p_method : t_method -> t -> bool + val p_section : string -> t -> bool + end + +module Search = + functor (P : Predicates) -> + struct + let search_section t s v = if P.p_section s v then [Res_section (s,t)] else [] + + let rec search_text root t v = + List.flatten (List.map (fun e -> search_text_ele root e v) t) + + and search_text_ele root e v = + let module T = Odoc_types in + match e with + | T.Raw _ + | T.Code _ + | T.CodePre _ + | T.Latex _ + | T.Verbatim _ + | T.Ref (_, _) -> [] + | T.Bold t + | T.Italic t + | T.Center t + | T.Left t + | T.Right t + | T.Emphasize t + | T.Block t + | T.Superscript t + | T.Subscript t + | T.Custom (_,t) + | T.Link (_, t) -> search_text root t v + | T.List l + | T.Enum l -> List.flatten (List.map (fun t -> search_text root t v) l) + | T.Newline + | T.Module_list _ + | T.Index_list -> [] + | T.Title (n, l_opt, t) -> + (match l_opt with + None -> [] + | Some s -> search_section t (Name.concat root s) v) @ + (search_text root t v) + + let search_value va v = if P.p_value va v then [Res_value va] else [] + + let search_type t v = if P.p_type t v then [Res_type t] else [] + + let search_exception e v = if P.p_exception e v then [Res_exception e] else [] + + let search_attribute a v = if P.p_attribute a v then [Res_attribute a] else [] + + let search_method m v = if P.p_method m v then [Res_method m] else [] + + let search_class c v = + let (go_deeper, ok) = P.p_class c v in + let l = + if go_deeper then + let res_att = + List.fold_left + (fun acc -> fun att -> acc @ (search_attribute att v)) + [] + (Odoc_class.class_attributes c) + in + let res_met = + List.fold_left + (fun acc -> fun m -> acc @ (search_method m v)) + [] + (Odoc_class.class_methods c) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text c.cl_name t v)) + [] + (Odoc_class.class_comments c) + in + let l = res_att @ res_met @ res_sec in + l + else + [] + in + if ok then + (Res_class c) :: l + else + l + + let search_class_type ct v = + let (go_deeper, ok) = P.p_class_type ct v in + let l = + if go_deeper then + let res_att = + List.fold_left + (fun acc -> fun att -> acc @ (search_attribute att v)) + [] + (Odoc_class.class_type_attributes ct) + in + let res_met = + List.fold_left + (fun acc -> fun m -> acc @ (search_method m v)) + [] + (Odoc_class.class_type_methods ct) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text ct.clt_name t v)) + [] + (Odoc_class.class_type_comments ct) + in + let l = res_att @ res_met @ res_sec in + l + else + [] + in + if ok then + (Res_class_type ct) :: l + else + l + + let rec search_module_type mt v = + let (go_deeper, ok) = P.p_module_type mt v in + let l = + if go_deeper then + let res_val = + List.fold_left + (fun acc -> fun va -> acc @ (search_value va v)) + [] + (Odoc_module.module_type_values mt) + in + let res_typ = + List.fold_left + (fun acc -> fun t -> acc @ (search_type t v)) + [] + (Odoc_module.module_type_types mt) + in + let res_exc = + List.fold_left + (fun acc -> fun e -> acc @ (search_exception e v)) + [] + (Odoc_module.module_type_exceptions mt) + in + let res_mod = search (Odoc_module.module_type_modules mt) v in + let res_modtyp = + List.fold_left + (fun acc -> fun mt -> acc @ (search_module_type mt v)) + [] + (Odoc_module.module_type_module_types mt) + in + let res_cl = + List.fold_left + (fun acc -> fun cl -> acc @ (search_class cl v)) + [] + (Odoc_module.module_type_classes mt) + in + let res_cltyp = + List.fold_left + (fun acc -> fun clt -> acc @ (search_class_type clt v)) + [] + (Odoc_module.module_type_class_types mt) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text mt.mt_name t v)) + [] + (Odoc_module.module_type_comments mt) + in + let l = res_val @ res_typ @ res_exc @ res_mod @ + res_modtyp @ res_cl @ res_cltyp @ res_sec + in + l + else + [] + in + if ok then + (Res_module_type mt) :: l + else + l + + and search_module m v = + let (go_deeper, ok) = P.p_module m v in + let l = + if go_deeper then + let res_val = + List.fold_left + (fun acc -> fun va -> acc @ (search_value va v)) + [] + (Odoc_module.module_values m) + in + let res_typ = + List.fold_left + (fun acc -> fun t -> acc @ (search_type t v)) + [] + (Odoc_module.module_types m) + in + let res_exc = + List.fold_left + (fun acc -> fun e -> acc @ (search_exception e v)) + [] + (Odoc_module.module_exceptions m) + in + let res_mod = search (Odoc_module.module_modules m) v in + let res_modtyp = + List.fold_left + (fun acc -> fun mt -> acc @ (search_module_type mt v)) + [] + (Odoc_module.module_module_types m) + in + let res_cl = + List.fold_left + (fun acc -> fun cl -> acc @ (search_class cl v)) + [] + (Odoc_module.module_classes m) + in + let res_cltyp = + List.fold_left + (fun acc -> fun clt -> acc @ (search_class_type clt v)) + [] + (Odoc_module.module_class_types m) + in + let res_sec = + List.fold_left + (fun acc -> fun t -> acc @ (search_text m.m_name t v)) + [] + (Odoc_module.module_comments m) + in + let l = res_val @ res_typ @ res_exc @ res_mod @ + res_modtyp @ res_cl @ res_cltyp @ res_sec + in + l + else + [] + in + if ok then + (Res_module m) :: l + else + l + + and search module_list v = + List.fold_left + (fun acc -> fun m -> + List.fold_left + (fun acc2 -> fun ele -> + if List.mem ele acc2 then acc2 else acc2 @ [ele] + ) + acc + (search_module m v) + ) + [] + module_list + end + +module P_name = + struct + type t = Str.regexp + let (=~) name regexp = Str.string_match regexp name 0 + let p_module m r = (true, m.m_name =~ r) + let p_module_type mt r = (true, mt.mt_name =~ r) + let p_class c r = (true, c.cl_name =~ r) + let p_class_type ct r = (true, ct.clt_name =~ r) + let p_value v r = v.val_name =~ r + let p_type t r = t.ty_name =~ r + let p_exception e r = e.ex_name =~ r + let p_attribute a r = a.att_value.val_name =~ r + let p_method m r = m.met_value.val_name =~ r + let p_section s r = s =~ r + end + +module Search_by_name = Search ( P_name ) + +module P_values = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, false) + let p_value _ _ = true + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_values = Search ( P_values ) +let values l = + let l_ele = Search_values.search l () in + let p v1 v2 = v1.val_name = v2.val_name in + let rec iter acc = function + (Res_value v) :: q -> if List.exists (p v) acc then iter acc q else iter (v :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_exceptions = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = true + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_exceptions = Search ( P_exceptions ) +let exceptions l = + let l_ele = Search_exceptions.search l () in + let p e1 e2 = e1.ex_name = e2.ex_name in + let rec iter acc = function + (Res_exception t) :: q -> if List.exists (p t) acc then iter acc q else iter (t :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_types = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, false) + let p_value _ _ = false + let p_type _ _ = true + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_types = Search ( P_types ) +let types l = + let l_ele = Search_types.search l () in + let p t1 t2 = t1.ty_name = t2.ty_name in + let rec iter acc = function + (Res_type t) :: q -> if List.exists (p t) acc then iter acc q else iter (t :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_attributes = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (true, false) + let p_class_type _ _ = (true, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = true + let p_method _ _ = false + let p_section _ _ = false + end +module Search_attributes = Search ( P_attributes ) +let attributes l = + let l_ele = Search_attributes.search l () in + let p a1 a2 = a1.att_value.val_name = a2.att_value.val_name in + let rec iter acc = function + (Res_attribute t) :: q -> if List.exists (p t) acc then iter acc q else iter (t :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_methods = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (true, false) + let p_class_type _ _ = (true, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = true + let p_section _ _ = true + end +module Search_methods = Search ( P_methods ) +let methods l = + let l_ele = Search_methods.search l () in + let p m1 m2 = m1.met_value.val_name = m2.met_value.val_name in + let rec iter acc = function + (Res_method t) :: q -> if List.exists (p t) acc then iter acc q else iter (t :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_classes = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, true) + let p_class_type _ _ = (false, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_classes = Search ( P_classes ) +let classes l = + let l_ele = Search_classes.search l () in + let p c1 c2 = c1.cl_name = c2.cl_name in + let rec iter acc = function + (Res_class c) :: q -> if List.exists (p c) acc then iter acc q else iter (c :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_class_types = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, true) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_class_types = Search ( P_class_types ) +let class_types l = + let l_ele = Search_class_types.search l () in + let p c1 c2 = c1.clt_name = c2.clt_name in + let rec iter acc = function + (Res_class_type c) :: q -> if List.exists (p c) acc then iter acc q else iter (c :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_modules = + struct + type t = unit + let p_module _ _ = (true, true) + let p_module_type _ _ = (true, false) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_modules = Search ( P_modules ) +let modules l = + let l_ele = Search_modules.search l () in + let p m1 m2 = m1.m_name = m2.m_name in + let rec iter acc = function + (Res_module m) :: q -> if List.exists (p m) acc then iter acc q else iter (m :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +module P_module_types = + struct + type t = unit + let p_module _ _ = (true, false) + let p_module_type _ _ = (true, true) + let p_class _ _ = (false, false) + let p_class_type _ _ = (false, false) + let p_value _ _ = false + let p_type _ _ = false + let p_exception _ _ = false + let p_attribute _ _ = false + let p_method _ _ = false + let p_section _ _ = false + end +module Search_module_types = Search ( P_module_types ) +let module_types l = + let l_ele = Search_module_types.search l () in + let p m1 m2 = m1.mt_name = m2.mt_name in + let rec iter acc = function + (Res_module_type m) :: q -> if List.exists (p m) acc then iter acc q else iter (m :: acc) q + | _ :: q -> iter acc q + | [] -> acc + in + iter [] l_ele + +let type_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_type _ -> true + | _ -> false + ) + l + +let value_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_value _ -> true + | _ -> false + ) + l + +let class_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_class _ -> true + | _ -> false + ) + l + +let class_type_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_class_type _ -> true + | _ -> false + ) + l + +let module_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_module _ -> true + | _ -> false + ) + l + +let module_type_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_module_type _ -> true + | _ -> false + ) + l + +let exception_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_exception _ -> true + | _ -> false + ) + l + +let attribute_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_attribute _ -> true + | _ -> false + ) + l + +let method_exists mods regexp = + let l = Search_by_name.search mods regexp in + List.exists + (function + Res_method _ -> true + | _ -> false + ) + l + +let find_section mods regexp = + let l = Search_by_name.search mods regexp in + match + List.find + (function + Res_section _ -> true + | _ -> false + ) + l + with + Res_section (_,t) -> t + | _ -> assert false + +(* eof $Id: odoc_search.ml,v 1.7 2006-01-04 16:55:50 doligez Exp $ *) diff --git a/ocamldoc/odoc_search.mli b/ocamldoc/odoc_search.mli new file mode 100644 index 0000000..cb1a688 --- /dev/null +++ b/ocamldoc/odoc_search.mli @@ -0,0 +1,199 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_search.mli,v 1.4 2003-11-24 10:43:12 starynke Exp $ *) + +(** Research of elements through modules. *) + +(** The type for an element of the result of a research. *) +type result_element = + Res_module of Odoc_module.t_module + | Res_module_type of Odoc_module.t_module_type + | Res_class of Odoc_class.t_class + | Res_class_type of Odoc_class.t_class_type + | Res_value of Odoc_value.t_value + | Res_type of Odoc_type.t_type + | Res_exception of Odoc_exception.t_exception + | Res_attribute of Odoc_value.t_attribute + | Res_method of Odoc_value.t_method + | Res_section of string * Odoc_types.text + +(** The type representing a research result.*) +type result = result_element list + +(** The type of modules which contain the predicates used during the research. + Some functions return a couple of booleans ; the first indicates if we + must go deeper in the analysed element, the second if the element satisfies + the predicate. +*) +module type Predicates = + sig + type t + val p_module : Odoc_module.t_module -> t -> bool * bool + val p_module_type : Odoc_module.t_module_type -> t -> bool * bool + val p_class : Odoc_class.t_class -> t -> bool * bool + val p_class_type : Odoc_class.t_class_type -> t -> bool * bool + val p_value : Odoc_value.t_value -> t -> bool + val p_type : Odoc_type.t_type -> t -> bool + val p_exception : Odoc_exception.t_exception -> t -> bool + val p_attribute : Odoc_value.t_attribute -> t -> bool + val p_method : Odoc_value.t_method -> t -> bool + val p_section : string -> t -> bool + end + +(** Search for elements verifying the predicates in the module in parameter.*) +module Search : + functor (P : Predicates) -> + sig + (** search in a section title *) + val search_section : Odoc_types.text -> string -> P.t -> result_element list + + (** search in a value *) + val search_value : Odoc_value.t_value -> P.t -> result_element list + + (** search in a type *) + val search_type : Odoc_type.t_type -> P.t -> result_element list + + (** search in an exception *) + val search_exception : + Odoc_exception.t_exception -> P.t -> result_element list + + (** search in an attribute *) + val search_attribute : + Odoc_value.t_attribute -> P.t -> result_element list + + (** search in a method *) + val search_method : Odoc_value.t_method -> P.t -> result_element list + + (** search in a class *) + val search_class : Odoc_class.t_class -> P.t -> result_element list + + (** search in a class type *) + val search_class_type : + Odoc_class.t_class_type -> P.t -> result_element list + + (** search in a module type *) + val search_module_type : + Odoc_module.t_module_type -> P.t -> result_element list + + (** search in a module *) + val search_module : Odoc_module.t_module -> P.t -> result_element list + + (** search in a list of modules *) + val search : Odoc_module.t_module list -> P.t -> result_element list + end + +(** A module of predicates to search elements by name (and accepting regexps).*) +module P_name : + sig + type t = Str.regexp + val ( =~ ) : string -> Str.regexp -> bool + val p_module : Odoc_module.t_module -> Str.regexp -> bool * bool + val p_module_type : + Odoc_module.t_module_type -> Str.regexp -> bool * bool + val p_class : Odoc_class.t_class -> Str.regexp -> bool * bool + val p_class_type : Odoc_class.t_class_type -> Str.regexp -> bool * bool + val p_value : Odoc_value.t_value -> Str.regexp -> bool + val p_type : Odoc_type.t_type -> Str.regexp -> bool + val p_exception : Odoc_exception.t_exception -> Str.regexp -> bool + val p_attribute : Odoc_value.t_attribute -> Str.regexp -> bool + val p_method : Odoc_value.t_method -> Str.regexp -> bool + end + +(** A module to search elements by name. *) +module Search_by_name : + sig + val search_section : Odoc_types.text -> string -> P_name.t -> result_element list + val search_value : Odoc_value.t_value -> P_name.t -> result_element list + val search_type : Odoc_type.t_type -> P_name.t -> result_element list + val search_exception : + Odoc_exception.t_exception -> P_name.t -> result_element list + val search_attribute : + Odoc_value.t_attribute -> P_name.t -> result_element list + val search_method : + Odoc_value.t_method -> P_name.t -> result_element list + val search_class : Odoc_class.t_class -> P_name.t -> result_element list + val search_class_type : + Odoc_class.t_class_type -> P_name.t -> result_element list + val search_module_type : + Odoc_module.t_module_type -> P_name.t -> result_element list + val search_module : + Odoc_module.t_module -> P_name.t -> result_element list + val search : Odoc_module.t_module list -> P_name.t -> result_element list + end + +(** A function to search all the values in a list of modules. *) +val values : Odoc_module.t_module list -> Odoc_value.t_value list + +(** A function to search all the exceptions in a list of modules. *) +val exceptions : Odoc_module.t_module list -> Odoc_exception.t_exception list + +(** A function to search all the types in a list of modules. *) +val types : Odoc_module.t_module list -> Odoc_type.t_type list + +(** A function to search all the class attributes in a list of modules. *) +val attributes : Odoc_module.t_module list -> Odoc_value.t_attribute list + +(** A function to search all the class methods in a list of modules. *) +val methods : Odoc_module.t_module list -> Odoc_value.t_method list + +(** A function to search all the classes in a list of modules. *) +val classes : Odoc_module.t_module list -> Odoc_class.t_class list + +(** A function to search all the class types in a list of modules. *) +val class_types : Odoc_module.t_module list -> Odoc_class.t_class_type list + +(** A function to search all the modules in a list of modules. *) +val modules : Odoc_module.t_module list -> Odoc_module.t_module list + +(** A function to search all the module types in a list of modules. *) +val module_types : Odoc_module.t_module list -> Odoc_module.t_module_type list + +(** Return [true] if a type with the given complete name (regexp) exists + in the given module list.*) +val type_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a value with the given complete name (regexp) exists + in the given module list.*) +val value_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a module with the given complete name (regexp) exists + in the given module list.*) +val module_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a module type with the given complete name (regexp) exists + in the given module list.*) +val module_type_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a class with the given complete name (regexp) exists + in the given module list.*) +val class_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a class type with the given complete name (regexp) exists + in the given module list.*) +val class_type_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a exception with the given complete name (regexp) exists + in the given module list.*) +val exception_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if an attribute with the given complete name (regexp) exists + in the given module list.*) +val attribute_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return [true] if a method with the given complete name (regexp) exists + in the given module list.*) +val method_exists : Odoc_module.t_module list -> Str.regexp -> bool + +(** Return the [text] of the section with the given complete name (regexp) + in the given module list. + @raise Not_found if the section was not found.*) +val find_section : Odoc_module.t_module list -> Str.regexp -> Odoc_types.text diff --git a/ocamldoc/odoc_see_lexer.mll b/ocamldoc/odoc_see_lexer.mll new file mode 100644 index 0000000..6bcdb31 --- /dev/null +++ b/ocamldoc/odoc_see_lexer.mll @@ -0,0 +1,102 @@ +{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_see_lexer.mll,v 1.3 2003-11-24 10:43:12 starynke Exp $ *) + +let print_DEBUG2 s = print_string s ; print_newline () + +(** the lexer for special comments. *) + +open Lexing +open Odoc_parser + +let buf = Buffer.create 32 + +} + +rule main = parse + [' ' '\013' '\009' '\012'] + + { + print_DEBUG2 "[' ' '\013' '\009' '\012'] +"; + main lexbuf + } + + | [ '\010' ] + { + print_DEBUG2 " [ '\010' ] "; + main lexbuf + } + + | "<" + { + print_DEBUG2 "call url lexbuf" ; + url lexbuf + } + + | "\"" + { + print_DEBUG2 "call doc lexbuf" ; + doc lexbuf + } + + + | '\'' + { + print_DEBUG2 "call file lexbuf" ; + file lexbuf + } + + | eof + { + print_DEBUG2 "EOF"; + EOF + } + + | _ + { + Buffer.reset buf ; + Buffer.add_string buf (Lexing.lexeme lexbuf); + desc lexbuf + } + +and url = parse + | ([^'>'] | '\n')+">" + { + let s = Lexing.lexeme lexbuf in + print_DEBUG2 ("([^'>'] | '\n')+ \">\" with "^s) ; + See_url (String.sub s 0 ((String.length s) -1)) + } + + +and doc = parse + | ([^'"'] | '\n' | "\\'")* "\"" + { + let s = Lexing.lexeme lexbuf in + See_doc (String.sub s 0 ((String.length s) -1)) + } + +and file = parse + | ([^'\''] | '\n' | "\\\"")* "'" + { + let s = Lexing.lexeme lexbuf in + See_file (String.sub s 0 ((String.length s) -1)) + } + + +and desc = parse + eof + { Desc (Buffer.contents buf) } + | _ + { + Buffer.add_string buf (Lexing.lexeme lexbuf); + desc lexbuf + } diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml new file mode 100644 index 0000000..9d2acda --- /dev/null +++ b/ocamldoc/odoc_sig.ml @@ -0,0 +1,1313 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_sig.ml,v 1.41 2008-07-23 08:55:36 guesdon Exp $ *) + +(** Analysis of interface files. *) + +open Misc +open Asttypes +open Types +open Typedtree +open Path + +let print_DEBUG s = print_string s ; print_newline ();; + +module Name = Odoc_name +open Odoc_parameter +open Odoc_value +open Odoc_type +open Odoc_exception +open Odoc_class +open Odoc_module +open Odoc_types + +module Signature_search = + struct + type ele = + | M of string + | MT of string + | V of string + | T of string + | C of string + | CT of string + | E of string + | ER of string + | P of string + + type tab = (ele, Types.signature_item) Hashtbl.t + + let add_to_hash table signat = + match signat with + Types.Tsig_value (ident, _) -> + Hashtbl.add table (V (Name.from_ident ident)) signat + | Types.Tsig_exception (ident, _) -> + Hashtbl.add table (E (Name.from_ident ident)) signat + | Types.Tsig_type (ident, _, _) -> + Hashtbl.add table (T (Name.from_ident ident)) signat + | Types.Tsig_class (ident, _, _) -> + Hashtbl.add table (C (Name.from_ident ident)) signat + | Types.Tsig_cltype (ident, _, _) -> + Hashtbl.add table (CT (Name.from_ident ident)) signat + | Types.Tsig_module (ident, _, _) -> + Hashtbl.add table (M (Name.from_ident ident)) signat + | Types.Tsig_modtype (ident,_) -> + Hashtbl.add table (MT (Name.from_ident ident)) signat + + let table signat = + let t = Hashtbl.create 13 in + List.iter (add_to_hash t) signat; + t + + let search_value table name = + match Hashtbl.find table (V name) with + | (Types.Tsig_value (_, val_desc)) -> val_desc.Types.val_type + | _ -> assert false + + let search_exception table name = + match Hashtbl.find table (E name) with + | (Types.Tsig_exception (_, type_expr_list)) -> + type_expr_list + | _ -> assert false + + let search_type table name = + match Hashtbl.find table (T name) with + | (Types.Tsig_type (_, type_decl, _)) -> type_decl + | _ -> assert false + + let search_class table name = + match Hashtbl.find table (C name) with + | (Types.Tsig_class (_, class_decl, _)) -> class_decl + | _ -> assert false + + let search_class_type table name = + match Hashtbl.find table (CT name) with + | (Types.Tsig_cltype (_, cltype_decl, _)) -> cltype_decl + | _ -> assert false + + let search_module table name = + match Hashtbl.find table (M name) with + | (Types.Tsig_module (ident, module_type, _)) -> module_type + | _ -> assert false + + let search_module_type table name = + match Hashtbl.find table (MT name) with + | (Types.Tsig_modtype (_, Types.Tmodtype_manifest module_type)) -> + Some module_type + | (Types.Tsig_modtype (_, Types.Tmodtype_abstract)) -> + None + | _ -> assert false + + let search_attribute_type name class_sig = + let (_, _, type_expr) = Types.Vars.find name class_sig.Types.cty_vars in + type_expr + + let search_method_type name class_sig = + let fields = Odoc_misc.get_fields class_sig.Types.cty_self in + List.assoc name fields + end + +module type Info_retriever = + sig + val all_special : string -> string -> int * (Odoc_types.info list) + val blank_line_outside_simple : string -> string -> bool + val just_after_special : string -> string -> (int * Odoc_types.info option) + val first_special : string -> string -> (int * Odoc_types.info option) + val get_comments : + (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) + end + +module Analyser = + functor (My_ir : Info_retriever) -> + struct + (** This variable is used to load a file as a string and retrieve characters from it.*) + let file = ref "" + (** The name of the analysed file. *) + let file_name = ref "" + + (** This function takes two indexes (start and end) and return the string + corresponding to the indexes in the file global variable. The function + prepare_file must have been called to fill the file global variable.*) + let get_string_of_file the_start the_end = + try + let s = String.sub !file the_start (the_end-the_start) in + s + with + Invalid_argument _ -> + "" + + (** This function loads the given file in the file global variable, + and sets file_name.*) + let prepare_file f input_f = + try + let s = Odoc_misc.input_file_as_string input_f in + file := s; + file_name := f + with + e -> + file := ""; + raise e + + (** The function used to get the comments in a class. *) + let get_comments_in_class pos_start pos_end = + My_ir.get_comments (fun t -> Class_comment t) + !file_name + (get_string_of_file pos_start pos_end) + + (** The function used to get the comments in a module. *) + let get_comments_in_module pos_start pos_end = + My_ir.get_comments (fun t -> Element_module_comment t) + !file_name + (get_string_of_file pos_start pos_end) + + let merge_infos = Odoc_merge.merge_info_opt Odoc_types.all_merge_options + + let name_comment_from_type_kind pos_end pos_limit tk = + match tk with + Parsetree.Ptype_abstract -> + (0, []) + | Parsetree.Ptype_variant cons_core_type_list_list -> + let rec f acc cons_core_type_list_list = + match cons_core_type_list_list with + [] -> + (0, acc) + | (name, core_type_list, loc) :: [] -> + let s = get_string_of_file + loc.Location.loc_end.Lexing.pos_cnum + pos_limit + in + let (len, comment_opt) = My_ir.just_after_special !file_name s in + (len, acc @ [ (name, comment_opt) ]) + | (name, core_type_list, loc) :: (name2, core_type_list2, loc2) + :: q -> + let pos_end_first = loc.Location.loc_end.Lexing.pos_cnum in + let pos_start_second = loc2.Location.loc_start.Lexing.pos_cnum in + let s = get_string_of_file pos_end_first pos_start_second in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + f (acc @ [name, comment_opt]) + ((name2, core_type_list2, loc2) :: q) + in + f [] cons_core_type_list_list + + | Parsetree.Ptype_record name_mutable_type_list (* of (string * mutable_flag * core_type) list*) -> + let rec f = function + [] -> + [] + | (name, _, ct, xxloc) :: [] -> + let pos = ct.Parsetree.ptyp_loc.Location.loc_end.Lexing.pos_cnum in + let s = get_string_of_file pos pos_end in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + [name, comment_opt] + | (name,_,ct,xxloc) :: ((name2,_,ct2,xxloc2) as ele2) :: q -> + let pos = ct.Parsetree.ptyp_loc.Location.loc_end.Lexing.pos_cnum in + let pos2 = ct2.Parsetree.ptyp_loc.Location.loc_start.Lexing.pos_cnum in + let s = get_string_of_file pos pos2 in + let (_,comment_opt) = My_ir.just_after_special !file_name s in + (name, comment_opt) :: (f (ele2 :: q)) + in + (0, f name_mutable_type_list) + + let get_type_kind env name_comment_list type_kind = + match type_kind with + Types.Type_abstract -> + Odoc_type.Type_abstract + + | Types.Type_variant l -> + let f (constructor_name, type_expr_list) = + let comment_opt = + try + match List.assoc constructor_name name_comment_list with + None -> None + | Some d -> d.Odoc_types.i_desc + with Not_found -> None + in + { + vc_name = constructor_name ; + vc_args = List.map (Odoc_env.subst_type env) type_expr_list ; + vc_text = comment_opt + } + in + Odoc_type.Type_variant (List.map f l) + + | Types.Type_record (l, _) -> + let f (field_name, mutable_flag, type_expr) = + let comment_opt = + try + match List.assoc field_name name_comment_list with + None -> None + | Some d -> d.Odoc_types.i_desc + with Not_found -> None + in + { + rf_name = field_name ; + rf_mutable = mutable_flag = Mutable ; + rf_type = Odoc_env.subst_type env type_expr ; + rf_text = comment_opt + } + in + Odoc_type.Type_record (List.map f l) + + (** Analysis of the elements of a class, from the information in the parsetree and in the class + signature. @return the couple (inherited_class list, elements).*) + let analyse_class_elements env current_class_name last_pos pos_limit + class_type_field_list class_signature = + let get_pos_limit2 q = + match q with + [] -> pos_limit + | ele2 :: _ -> + match ele2 with + Parsetree.Pctf_val (_, _, _, _, loc) + | Parsetree.Pctf_virt (_, _, _, loc) + | Parsetree.Pctf_meth (_, _, _, loc) + | Parsetree.Pctf_cstr (_, _, loc) -> loc.Location.loc_start.Lexing.pos_cnum + | Parsetree.Pctf_inher class_type -> + class_type.Parsetree.pcty_loc.Location.loc_start.Lexing.pos_cnum + in + let get_method name comment_opt private_flag loc q = + let complete_name = Name.concat current_class_name name in + let typ = + try Signature_search.search_method_type name class_signature + with Not_found -> + raise (Failure (Odoc_messages.method_type_not_found current_class_name name)) + in + let subst_typ = Odoc_env.subst_type env typ in + let met = + { + met_value = + { + val_name = complete_name ; + val_info = comment_opt ; + val_type = subst_typ ; + val_recursive = false ; + val_parameters = Odoc_value.dummy_parameter_list subst_typ ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start.Lexing.pos_cnum) }; + } ; + met_private = private_flag = Asttypes.Private ; + met_virtual = false ; + } + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end.Lexing.pos_cnum in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + met.met_value.val_info <- merge_infos met.met_value.val_info info_after_opt ; + (* update the parameter description *) + Odoc_value.update_value_parameters_text met.met_value; + (met, maybe_more) + in + let rec f last_pos class_type_field_list = + match class_type_field_list with + [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Class_comment t]) + [] + ele_coms + in + ([], ele_comments) + + | Parsetree.Pctf_val (name, mutable_flag, virtual_flag, _, loc) :: q -> + (* of (string * mutable_flag * core_type option * Location.t)*) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let complete_name = Name.concat current_class_name name in + let typ = + try Signature_search.search_attribute_type name class_signature + with Not_found -> + raise (Failure (Odoc_messages.attribute_type_not_found current_class_name name)) + in + let subst_typ = Odoc_env.subst_type env typ in + let att = + { + att_value = + { + val_name = complete_name ; + val_info = comment_opt ; + val_type = subst_typ; + val_recursive = false ; + val_parameters = [] ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, loc.Location.loc_start.Lexing.pos_cnum)} ; + } ; + att_mutable = mutable_flag = Asttypes.Mutable ; + att_virtual = virtual_flag = Asttypes.Virtual ; + } + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end.Lexing.pos_cnum in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + att.att_value.val_info <- merge_infos att.att_value.val_info info_after_opt ; + let (inher_l, eles) = f (pos_end + maybe_more) q in + (inher_l, eles_comments @ ((Class_attribute att) :: eles)) + + | Parsetree.Pctf_virt (name, private_flag, _, loc) :: q -> + (* of (string * private_flag * core_type * Location.t) *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let (met, maybe_more) = get_method name comment_opt private_flag loc q in + let met2 = { met with met_virtual = true } in + let (inher_l, eles) = f (loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q in + (inher_l, eles_comments @ ((Class_method met2) :: eles)) + + | Parsetree.Pctf_meth (name, private_flag, _, loc) :: q -> + (* of (string * private_flag * core_type * Location.t) *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let (met, maybe_more) = get_method name comment_opt private_flag loc q in + let (inher_l, eles) = f (loc.Location.loc_end.Lexing.pos_cnum + maybe_more) q in + (inher_l, eles_comments @ ((Class_method met) :: eles)) + + | (Parsetree.Pctf_cstr (_, _, loc)) :: q -> + (* of (core_type * core_type * Location.t) *) + (* A VOIR : cela correspond aux contraintes, non ? on ne les garde pas pour l'instant *) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let (inher_l, eles) = f loc.Location.loc_end.Lexing.pos_cnum q in + (inher_l, eles_comments @ eles) + + | Parsetree.Pctf_inher class_type :: q -> + let loc = class_type.Parsetree.pcty_loc in + let (comment_opt, eles_comments) = + get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum + in + let pos_limit2 = get_pos_limit2 q in + let pos_end = loc.Location.loc_end.Lexing.pos_cnum in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + let comment_opt2 = merge_infos comment_opt info_after_opt in + let text_opt = match comment_opt2 with None -> None | Some i -> i.Odoc_types.i_desc in + let inh = + match class_type.Parsetree.pcty_desc with + Parsetree.Pcty_constr (longident, _) -> + (*of Longident.t * core_type list*) + let name = Name.from_longident longident in + let ic = + { + ic_name = Odoc_env.full_class_or_class_type_name env name ; + ic_class = None ; + ic_text = text_opt ; + } + in + ic + + | Parsetree.Pcty_signature _ + | Parsetree.Pcty_fun _ -> + (* we don't have a name for the class signature, so we call it "object ... end" *) + { + ic_name = Odoc_messages.object_end ; + ic_class = None ; + ic_text = text_opt ; + } + in + let (inher_l, eles) = f (pos_end + maybe_more) q in + (inh :: inher_l , eles_comments @ eles) + in + f last_pos class_type_field_list + + (** Analyse of a .mli parse tree, to get the corresponding elements. + last_pos is the position of the first character which may be used to look for special comments. + *) + let rec analyse_parsetree env signat current_module_name last_pos pos_limit sig_item_list = + let table = Signature_search.table signat in + (* we look for the comment of each item then analyse the item *) + let rec f acc_eles acc_env last_pos = function + [] -> + let s = get_string_of_file last_pos pos_limit in + let (_, ele_coms) = My_ir.all_special !file_name s in + let ele_comments = + List.fold_left + (fun acc -> fun sc -> + match sc.Odoc_types.i_desc with + None -> + acc + | Some t -> + acc @ [Element_module_comment t]) + [] + ele_coms + in + acc_eles @ ele_comments + + | ele :: q -> + let (assoc_com, ele_comments) = get_comments_in_module + last_pos + ele.Parsetree.psig_loc.Location.loc_start.Lexing.pos_cnum + in + let (maybe_more, new_env, elements) = analyse_signature_item_desc + acc_env + signat + table + current_module_name + ele.Parsetree.psig_loc.Location.loc_start.Lexing.pos_cnum + ele.Parsetree.psig_loc.Location.loc_end.Lexing.pos_cnum + (match q with + [] -> pos_limit + | ele2 :: _ -> ele2.Parsetree.psig_loc.Location.loc_start.Lexing.pos_cnum + ) + assoc_com + ele.Parsetree.psig_desc + in + f (acc_eles @ (ele_comments @ elements)) + new_env + (ele.Parsetree.psig_loc.Location.loc_end.Lexing.pos_cnum + maybe_more) + (* for the comments of constructors in types, + which are after the constructor definition and can + go beyond ele.Parsetree.psig_loc.Location.loc_end.Lexing.pos_cnum *) + q + in + f [] env last_pos sig_item_list + + (** Analyse the given signature_item_desc to create the corresponding module element + (with the given attached comment).*) + and analyse_signature_item_desc env signat table current_module_name + pos_start_ele pos_end_ele pos_limit comment_opt sig_item_desc = + match sig_item_desc with + Parsetree.Psig_value (name_pre, value_desc) -> + let type_expr = + try Signature_search.search_value table name_pre + with Not_found -> + raise (Failure (Odoc_messages.value_not_found current_module_name name_pre)) + in + let name = Name.parens_if_infix name_pre in + let subst_typ = Odoc_env.subst_type env type_expr in + let v = + { + val_name = Name.concat current_module_name name ; + val_info = comment_opt ; + val_type = subst_typ ; + val_recursive = false ; + val_parameters = Odoc_value.dummy_parameter_list subst_typ ; + val_code = None ; + val_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele)} + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + v.val_info <- merge_infos v.val_info info_after_opt ; + (* update the parameter description *) + Odoc_value.update_value_parameters_text v; + + let new_env = Odoc_env.add_value env v.val_name in + (maybe_more, new_env, [ Element_value v ]) + + | Parsetree.Psig_exception (name, exception_decl) -> + let types_excep_decl = + try Signature_search.search_exception table name + with Not_found -> + raise (Failure (Odoc_messages.exception_not_found current_module_name name)) + in + let e = + { + ex_name = Name.concat current_module_name name ; + ex_info = comment_opt ; + ex_args = List.map (Odoc_env.subst_type env) types_excep_decl ; + ex_alias = None ; + ex_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + ex_code = + ( + if !Odoc_args.keep_code then + Some (get_string_of_file pos_start_ele pos_end_ele) + else + None + ) ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + e.ex_info <- merge_infos e.ex_info info_after_opt ; + let new_env = Odoc_env.add_exception env e.ex_name in + (maybe_more, new_env, [ Element_exception e ]) + + | Parsetree.Psig_type name_type_decl_list -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun (name, _) -> + let complete_name = Name.concat current_module_name name in + Odoc_env.add_type acc_env complete_name + ) + env + name_type_decl_list + in + let rec f ?(first=false) acc_maybe_more last_pos name_type_decl_list = + match name_type_decl_list with + [] -> + (acc_maybe_more, []) + | (name, type_decl) :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum + in + let pos_limit2 = + match q with + [] -> pos_limit + | (_, td) :: _ -> td.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum + in + let (maybe_more, name_comment_list) = + name_comment_from_type_kind + type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + pos_limit2 + type_decl.Parsetree.ptype_kind + in + print_DEBUG ("Type "^name^" : "^(match assoc_com with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)); + let f_DEBUG (name, c_opt) = print_DEBUG ("constructor/field "^name^": "^(match c_opt with None -> "sans commentaire" | Some c -> Odoc_misc.string_of_info c)) in + List.iter f_DEBUG name_comment_list; + (* get the information for the type in the signature *) + let sig_type_decl = + try Signature_search.search_type table name + with Not_found -> + raise (Failure (Odoc_messages.type_not_found current_module_name name)) + in + (* get the type kind with the associated comments *) + let type_kind = get_type_kind new_env name_comment_list sig_type_decl.Types.type_kind in + let loc_start = type_decl.Parsetree.ptype_loc.Location.loc_start.Lexing.pos_cnum in + let new_end = type_decl.Parsetree.ptype_loc.Location.loc_end.Lexing.pos_cnum + maybe_more in + (* associate the comments to each constructor and build the [Type.t_type] *) + let new_type = + { + ty_name = Name.concat current_module_name name ; + ty_info = assoc_com ; + ty_parameters = + List.map2 (fun p (co,cn,_) -> + (Odoc_env.subst_type new_env p, + co, cn) + ) + sig_type_decl.Types.type_params + sig_type_decl.Types.type_variance; + ty_kind = type_kind; + ty_private = sig_type_decl.Types.type_private; + ty_manifest = + (match sig_type_decl.Types.type_manifest with + None -> None + | Some t -> Some (Odoc_env.subst_type new_env t)); + ty_loc = + { loc_impl = None ; + loc_inter = Some (!file_name,loc_start) ; + }; + ty_code = + ( + if !Odoc_args.keep_code then + Some (get_string_of_file loc_start new_end) + else + None + ) ; + } + in + let (maybe_more2, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file new_end pos_limit2) + in + new_type.ty_info <- merge_infos new_type.ty_info info_after_opt ; + let (new_maybe_more, eles) = f + (maybe_more + maybe_more2) + (new_end + maybe_more2) + q + in + (new_maybe_more, (ele_comments @ [Element_type new_type]) @ eles) + in + let (maybe_more, types) = f ~first: true 0 pos_start_ele name_type_decl_list in + (maybe_more, new_env, types) + + | Parsetree.Psig_open _ -> (* A VOIR *) + let ele_comments = match comment_opt with + None -> [] + | Some i -> + match i.i_desc with + None -> [] + | Some t -> [Element_module_comment t] + in + (0, env, ele_comments) + + | Parsetree.Psig_module (name, module_type) -> + let complete_name = Name.concat current_module_name name in + (* get the the module type in the signature by the module name *) + let sig_module_type = + try Signature_search.search_module table name + with Not_found -> + raise (Failure (Odoc_messages.module_not_found current_module_name name)) + in + let module_kind = analyse_module_kind env complete_name module_type sig_module_type in + let code_intf = + if !Odoc_args.keep_code then + let loc = module_type.Parsetree.pmty_loc in + let st = loc.Location.loc_start.Lexing.pos_cnum in + let en = loc.Location.loc_end.Lexing.pos_cnum in + Some (get_string_of_file st en) + else + None + in + let new_module = + { + m_name = complete_name ; + m_type = sig_module_type; + m_info = comment_opt ; + m_is_interface = true ; + m_file = !file_name ; + m_kind = module_kind ; + m_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + m_top_deps = [] ; + m_code = None ; + m_code_intf = code_intf ; + m_text_only = false ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + new_module.m_info <- merge_infos new_module.m_info info_after_opt ; + let new_env = Odoc_env.add_module env new_module.m_name in + let new_env2 = + match new_module.m_type with (* A VOIR : cela peut-il être Tmty_ident ? dans ce cas, on aurait pas la signature *) + Types.Tmty_signature s -> Odoc_env.add_signature new_env new_module.m_name ~rel: (Name.simple new_module.m_name) s + | _ -> new_env + in + (maybe_more, new_env2, [ Element_module new_module ]) + + | Parsetree.Psig_recmodule decls -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun (name, _) -> + let complete_name = Name.concat current_module_name name in + let e = Odoc_env.add_module acc_env complete_name in + (* get the information for the module in the signature *) + let sig_module_type = + try Signature_search.search_module table name + with Not_found -> + raise (Failure (Odoc_messages.module_not_found current_module_name name)) + in + match sig_module_type with + (* A VOIR : cela peut-il être Tmty_ident ? dans ce cas, on aurait pas la signature *) + Types.Tmty_signature s -> + Odoc_env.add_signature e complete_name ~rel: name s + | _ -> + print_DEBUG "not a Tmty_signature"; + e + ) + env + decls + in + let rec f ?(first=false) acc_maybe_more last_pos name_mtype_list = + match name_mtype_list with + [] -> + (acc_maybe_more, []) + | (name, modtype) :: q -> + let complete_name = Name.concat current_module_name name in + let loc_start = modtype.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in + let loc_end = modtype.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + loc_start + in + let pos_limit2 = + match q with + [] -> pos_limit + | (_, mty) :: _ -> mty.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum + in + (* get the information for the module in the signature *) + let sig_module_type = + try Signature_search.search_module table name + with Not_found -> + raise (Failure (Odoc_messages.module_not_found current_module_name name)) + in + (* associate the comments to each constructor and build the [Type.t_type] *) + let module_kind = analyse_module_kind new_env complete_name modtype sig_module_type in + let code_intf = + if !Odoc_args.keep_code then + let loc = modtype.Parsetree.pmty_loc in + let st = loc.Location.loc_start.Lexing.pos_cnum in + let en = loc.Location.loc_end.Lexing.pos_cnum in + Some (get_string_of_file st en) + else + None + in + let new_module = + { + m_name = complete_name ; + m_type = sig_module_type; + m_info = assoc_com ; + m_is_interface = true ; + m_file = !file_name ; + m_kind = module_kind ; + m_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + m_top_deps = [] ; + m_code = None ; + m_code_intf = code_intf ; + m_text_only = false ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file loc_end pos_limit2) + in + new_module.m_info <- merge_infos new_module.m_info info_after_opt ; + + let (maybe_more2, eles) = f + maybe_more + (loc_end + maybe_more) + q + in + (maybe_more2, (ele_comments @ [Element_module new_module]) @ eles) + in + let (maybe_more, mods) = f ~first: true 0 pos_start_ele decls in + (maybe_more, new_env, mods) + + | Parsetree.Psig_modtype (name, Parsetree.Pmodtype_abstract) -> + let sig_mtype = + try Signature_search.search_module_type table name + with Not_found -> + raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) + in + let complete_name = Name.concat current_module_name name in + let mt = + { + mt_name = complete_name ; + mt_info = comment_opt ; + mt_type = sig_mtype ; + mt_is_interface = true ; + mt_file = !file_name ; + mt_kind = None ; + mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + mt.mt_info <- merge_infos mt.mt_info info_after_opt ; + let new_env = Odoc_env.add_module_type env mt.mt_name in + (maybe_more, new_env, [ Element_module_type mt ]) + + | Parsetree.Psig_modtype (name, Parsetree.Pmodtype_manifest module_type) -> + let complete_name = Name.concat current_module_name name in + let sig_mtype_opt = + try Signature_search.search_module_type table name + with Not_found -> + raise (Failure (Odoc_messages.module_type_not_found current_module_name name)) + in + let module_type_kind = + match sig_mtype_opt with + | Some sig_mtype -> Some (analyse_module_type_kind env complete_name module_type sig_mtype) + | None -> None + in + let mt = + { + mt_name = complete_name ; + mt_info = comment_opt ; + mt_type = sig_mtype_opt ; + mt_is_interface = true ; + mt_file = !file_name ; + mt_kind = module_type_kind ; + mt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end_ele pos_limit) + in + mt.mt_info <- merge_infos mt.mt_info info_after_opt ; + let new_env = Odoc_env.add_module_type env mt.mt_name in + let new_env2 = + match sig_mtype_opt with (* A VOIR : cela peut-il être Tmty_ident ? dans ce cas, on aurait pas la signature *) + Some (Types.Tmty_signature s) -> Odoc_env.add_signature new_env mt.mt_name ~rel: (Name.simple mt.mt_name) s + | _ -> new_env + in + (maybe_more, new_env2, [ Element_module_type mt ]) + + | Parsetree.Psig_include module_type -> + let rec f = function + Parsetree.Pmty_ident longident -> + Name.from_longident longident + | Parsetree.Pmty_signature _ -> + "??" + | Parsetree.Pmty_functor _ -> + "??" + | Parsetree.Pmty_with (mt, _) -> + f mt.Parsetree.pmty_desc + in + let name = (f module_type.Parsetree.pmty_desc) in + let full_name = Odoc_env.full_module_or_module_type_name env name in + let im = + { + im_name = full_name ; + im_module = None ; + im_info = comment_opt; + } + in + (0, env, [ Element_included_module im ]) (* A VOIR : étendre l'environnement ? avec quoi ? *) + + | Parsetree.Psig_class class_description_list -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun class_desc -> + let complete_name = Name.concat current_module_name class_desc.Parsetree.pci_name in + Odoc_env.add_class acc_env complete_name + ) + env + class_description_list + in + let rec f ?(first=false) acc_maybe_more last_pos class_description_list = + match class_description_list with + [] -> + (acc_maybe_more, []) + | class_desc :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + class_desc.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + in + let pos_end = class_desc.Parsetree.pci_loc.Location.loc_end.Lexing.pos_cnum in + let pos_limit2 = + match q with + [] -> pos_limit + | cd :: _ -> cd.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + in + let name = class_desc.Parsetree.pci_name in + let complete_name = Name.concat current_module_name name in + let sig_class_decl = + try Signature_search.search_class table name + with Not_found -> + raise (Failure (Odoc_messages.class_not_found current_module_name name)) + in + let sig_class_type = sig_class_decl.Types.cty_type in + let (parameters, class_kind) = + analyse_class_kind + new_env + complete_name + class_desc.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + class_desc.Parsetree.pci_expr + sig_class_type + in + let new_class = + { + cl_name = complete_name ; + cl_info = assoc_com ; + cl_type = Odoc_env.subst_class_type env sig_class_type ; + cl_type_parameters = sig_class_decl.Types.cty_params; + cl_virtual = class_desc.Parsetree.pci_virt = Asttypes.Virtual ; + cl_kind = class_kind ; + cl_parameters = parameters ; + cl_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + new_class.cl_info <- merge_infos new_class.cl_info info_after_opt ; + Odoc_class.class_update_parameters_text new_class ; + let (new_maybe_more, eles) = + f maybe_more (pos_end + maybe_more) q + in + (new_maybe_more, + ele_comments @ (( Element_class new_class ) :: eles)) + in + let (maybe_more, eles) = + f ~first: true 0 pos_start_ele class_description_list + in + (maybe_more, new_env, eles) + + | Parsetree.Psig_class_type class_type_declaration_list -> + (* we start by extending the environment *) + let new_env = + List.fold_left + (fun acc_env -> fun class_type_decl -> + let complete_name = Name.concat current_module_name class_type_decl.Parsetree.pci_name in + Odoc_env.add_class_type acc_env complete_name + ) + env + class_type_declaration_list + in + let rec f ?(first=false) acc_maybe_more last_pos class_type_description_list = + match class_type_description_list with + [] -> + (acc_maybe_more, []) + | ct_decl :: q -> + let (assoc_com, ele_comments) = + if first then + (comment_opt, []) + else + get_comments_in_module + last_pos + ct_decl.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + in + let pos_end = ct_decl.Parsetree.pci_loc.Location.loc_end.Lexing.pos_cnum in + let pos_limit2 = + match q with + [] -> pos_limit + | ct_decl2 :: _ -> ct_decl2.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + in + let name = ct_decl.Parsetree.pci_name in + let complete_name = Name.concat current_module_name name in + let sig_cltype_decl = + try Signature_search.search_class_type table name + with Not_found -> + raise (Failure (Odoc_messages.class_type_not_found current_module_name name)) + in + let sig_class_type = sig_cltype_decl.Types.clty_type in + let kind = analyse_class_type_kind + new_env + complete_name + ct_decl.Parsetree.pci_loc.Location.loc_start.Lexing.pos_cnum + ct_decl.Parsetree.pci_expr + sig_class_type + in + let ct = + { + clt_name = complete_name ; + clt_info = assoc_com ; + clt_type = Odoc_env.subst_class_type env sig_class_type ; + clt_type_parameters = sig_cltype_decl.clty_params ; + clt_virtual = ct_decl.Parsetree.pci_virt = Asttypes.Virtual ; + clt_kind = kind ; + clt_loc = { loc_impl = None ; loc_inter = Some (!file_name, pos_start_ele) } ; + } + in + let (maybe_more, info_after_opt) = + My_ir.just_after_special + !file_name + (get_string_of_file pos_end pos_limit2) + in + ct.clt_info <- merge_infos ct.clt_info info_after_opt ; + let (new_maybe_more, eles) = + f maybe_more (pos_end + maybe_more) q + in + (new_maybe_more, + ele_comments @ (( Element_class_type ct) :: eles)) + in + let (maybe_more, eles) = + f ~first: true 0 pos_start_ele class_type_declaration_list + in + (maybe_more, new_env, eles) + + (** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *) + and analyse_module_type_kind env current_module_name module_type sig_module_type = + match module_type.Parsetree.pmty_desc with + Parsetree.Pmty_ident longident -> + let name = + match sig_module_type with + Types.Tmty_ident path -> Name.from_path path + | _ -> Name.from_longident longident + (* A VOIR cela arrive quand on fait module type F : functor ... -> Toto, Toto n'est pas un ident mais une structure *) + in + Module_type_alias { mta_name = Odoc_env.full_module_type_name env name ; + mta_module = None } + + | Parsetree.Pmty_signature ast -> + ( + (* we must have a signature in the module type *) + match sig_module_type with + Types.Tmty_signature signat -> + let pos_start = module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in + let pos_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let elements = analyse_parsetree env signat current_module_name pos_start pos_end ast in + Module_type_struct elements + | _ -> + raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat") + ) + + | Parsetree.Pmty_functor (_,pmodule_type2, module_type2) -> + ( + let loc_start = pmodule_type2.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in + let loc_end = pmodule_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let mp_type_code = get_string_of_file loc_start loc_end in + print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code); + match sig_module_type with + Types.Tmty_functor (ident, param_module_type, body_module_type) -> + let mp_kind = analyse_module_type_kind env + current_module_name pmodule_type2 param_module_type + in + let param = + { + mp_name = Name.from_ident ident ; + mp_type = Odoc_env.subst_module_type env param_module_type ; + mp_type_code = mp_type_code ; + mp_kind = mp_kind ; + } + in + let k = analyse_module_type_kind env + current_module_name + module_type2 + body_module_type + in + Module_type_functor (param, k) + + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") + ) + + | Parsetree.Pmty_with (module_type2, _) -> + (* of module_type * (Longident.t * with_constraint) list *) + ( + let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let s = get_string_of_file loc_start loc_end in + let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in + Module_type_with (k, s) + ) + + (** Analyse of a Parsetree.module_type and a Types.module_type.*) + and analyse_module_kind env current_module_name module_type sig_module_type = + match module_type.Parsetree.pmty_desc with + Parsetree.Pmty_ident longident -> + let k = analyse_module_type_kind env current_module_name module_type sig_module_type in + Module_with ( k, "" ) + + | Parsetree.Pmty_signature signature -> + ( + match sig_module_type with + Types.Tmty_signature signat -> + Module_struct + (analyse_parsetree + env + signat + current_module_name + module_type.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum + module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum + signature + ) + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_signature signature but not Types.Tmty_signature signat") + ) + | Parsetree.Pmty_functor (_,pmodule_type2,module_type2) (* of string * module_type * module_type *) -> + ( + match sig_module_type with + Types.Tmty_functor (ident, param_module_type, body_module_type) -> + let loc_start = pmodule_type2.Parsetree.pmty_loc.Location.loc_start.Lexing.pos_cnum in + let loc_end = pmodule_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let mp_type_code = get_string_of_file loc_start loc_end in + print_DEBUG (Printf.sprintf "mp_type_code=%s" mp_type_code); + let mp_kind = analyse_module_type_kind env + current_module_name pmodule_type2 param_module_type + in + let param = + { + mp_name = Name.from_ident ident ; + mp_type = Odoc_env.subst_module_type env param_module_type ; + mp_type_code = mp_type_code ; + mp_kind = mp_kind ; + } + in + let k = analyse_module_kind env + current_module_name + module_type2 + body_module_type + in + Module_functor (param, k) + + | _ -> + (* if we're here something's wrong *) + raise (Failure "Parsetree.Pmty_functor _ but not Types.Tmty_functor _") + ) + | Parsetree.Pmty_with (module_type2, _) -> + (*of module_type * (Longident.t * with_constraint) list*) + ( + let loc_start = module_type2.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let loc_end = module_type.Parsetree.pmty_loc.Location.loc_end.Lexing.pos_cnum in + let s = get_string_of_file loc_start loc_end in + let k = analyse_module_type_kind env current_module_name module_type2 sig_module_type in + Module_with (k, s) + ) + + (** Analyse of a Parsetree.class_type and a Types.class_type to return a couple + (class parameters, class_kind).*) + and analyse_class_kind env current_class_name last_pos parse_class_type sig_class_type = + match parse_class_type.Parsetree.pcty_desc, sig_class_type with + (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), + Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> + print_DEBUG "Tcty_constr _"; + let path_name = Name.from_path p in + let name = Odoc_env.full_class_or_class_type_name env path_name in + let k = + Class_constr + { + cco_name = name ; + cco_class = None ; + cco_type_parameters = List.map (Odoc_env.subst_type env) typ_list + } + in + ([], k) + + | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) -> + (* we get the elements of the class in class_type_field_list *) + let (inher_l, ele) = analyse_class_elements env current_class_name + last_pos + parse_class_type.Parsetree.pcty_loc.Location.loc_end.Lexing.pos_cnum + class_type_field_list + class_signature + in + ([], Class_structure (inher_l, ele)) + + | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) -> + (* label = string. Dans les signatures, pas de nom de paramètres à l'intérieur des tuples *) + (* si label = "", pas de label. ici on a l'information pour savoir si on a un label explicite. *) + if parse_label = label then + ( + let new_param = Simple_name + { + sn_name = Btype.label_name label ; + sn_type = Odoc_env.subst_type env type_expr ; + sn_text = None ; (* will be updated when the class will be created *) + } + in + let (l, k) = analyse_class_kind env current_class_name last_pos pclass_type class_type in + ( (new_param :: l), k ) + ) + else + ( + raise (Failure "Parsetree.Pcty_fun (parse_label, _, pclass_type), labels différents") + ) + + | _ -> + raise (Failure "analyse_class_kind pas de correspondance dans le match") + + (** Analyse of a Parsetree.class_type and a Types.class_type to return a class_type_kind.*) + and analyse_class_type_kind env current_class_name last_pos parse_class_type sig_class_type = + match parse_class_type.Parsetree.pcty_desc, sig_class_type with + (Parsetree.Pcty_constr (_, _) (*of Longident.t * core_type list *), + Types.Tcty_constr (p, typ_list, _) (*of Path.t * type_expr list * class_type*)) -> + print_DEBUG "Tcty_constr _"; + let k = + Class_type + { + cta_name = Odoc_env.full_class_or_class_type_name env (Name.from_path p) ; + cta_class = None ; + cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list + } + in + k + + | (Parsetree.Pcty_signature (_, class_type_field_list), Types.Tcty_signature class_signature) -> + (* we get the elements of the class in class_type_field_list *) + let (inher_l, ele) = analyse_class_elements env current_class_name + last_pos + parse_class_type.Parsetree.pcty_loc.Location.loc_end.Lexing.pos_cnum + class_type_field_list + class_signature + in + Class_signature (inher_l, ele) + + | (Parsetree.Pcty_fun (parse_label, _, pclass_type), Types.Tcty_fun (label, type_expr, class_type)) -> + raise (Failure "analyse_class_type_kind : Parsetree.Pcty_fun (...) with Types.Tcty_fun (...)") +(* + | (Parsetree.Pcty_constr (longident, _) (*of Longident.t * core_type list *), + Types.Tcty_signature class_signature) -> + (* A VOIR : c'est pour le cas des contraintes de classes : + class type cons = object + method m : int + end + + class ['a] maxou x = + (object + val a = (x : 'a) + method m = a + end : cons ) + ^^^^^^ + *) + let k = + Class_type + { + cta_name = Odoc_env.full_class_name env (Name.from_longident longident) ; + cta_class = None ; + cta_type_parameters = List.map (Odoc_env.subst_type env) typ_list (* ?? *) + } + in + ([], k) +*) + | _ -> + raise (Failure "analyse_class_type_kind pas de correspondance dans le match") + + let analyse_signature source_file input_file + (ast : Parsetree.signature) (signat : Types.signature) = + let complete_source_file = + try + let curdir = Sys.getcwd () in + let (dirname, basename) = (Filename.dirname source_file, Filename.basename source_file) in + Sys.chdir dirname ; + let complete = Filename.concat (Sys.getcwd ()) basename in + Sys.chdir curdir ; + complete + with + Sys_error s -> + prerr_endline s ; + incr Odoc_global.errors ; + source_file + in + prepare_file complete_source_file input_file; + (* We create the t_module for this file. *) + let mod_name = String.capitalize + (Filename.basename (try Filename.chop_extension source_file with _ -> source_file)) + in + let (len,info_opt) = My_ir.first_special !file_name !file in + let elements = + analyse_parsetree Odoc_env.empty signat mod_name len (String.length !file) ast + in + let code_intf = + if !Odoc_args.keep_code then + Some !file + else + None + in + { + m_name = mod_name ; + m_type = Types.Tmty_signature signat ; + m_info = info_opt ; + m_is_interface = true ; + m_file = !file_name ; + m_kind = Module_struct elements ; + m_loc = { loc_impl = None ; loc_inter = Some (!file_name, 0) } ; + m_top_deps = [] ; + m_code = None ; + m_code_intf = code_intf ; + m_text_only = false ; + } + + end diff --git a/ocamldoc/odoc_sig.mli b/ocamldoc/odoc_sig.mli new file mode 100644 index 0000000..b41e913 --- /dev/null +++ b/ocamldoc/odoc_sig.mli @@ -0,0 +1,177 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_sig.mli,v 1.6 2004-11-03 09:31:19 guesdon Exp $ *) + +(** The module for analysing a signature and source code and creating modules, classes, ..., elements.*) + +(** The functions used to retrieve information from a signature. *) +module Signature_search : + sig + type ele + type tab = (ele, Types.signature_item) Hashtbl.t + + (** Create a table from a signature. This table is used by some + of the search functions below. *) + val table : Types.signature -> tab + + (** This function returns the type expression for the value whose name is given, + in the given signature. + @raise Not_found if error.*) + val search_value : tab -> string -> Types.type_expr + + (** This function returns the type expression list for the exception whose name is given, + in the given table. + @raise Not_found if error.*) + val search_exception : tab -> string -> Types.exception_declaration + + (** This function returns the Types.type_declaration for the type whose name is given, + in the given table. + @raise Not_found if error.*) + val search_type : tab -> string -> Types.type_declaration + + (** This function returns the Types.class_declaration for the class whose name is given, + in the given table. + @raise Not_found if error.*) + val search_class : tab -> string -> Types.class_declaration + + (** This function returns the Types.cltype_declaration for the class type whose name is given, + in the given table. + @raise Not_found if error.*) + val search_class_type : tab -> string -> Types.cltype_declaration + + (** This function returns the Types.module_type for the module whose name is given, + in the given table. + @raise Not_found if error.*) + val search_module : tab -> string -> Types.module_type + + (** This function returns the optional Types.module_type for the module type whose name is given, + in the given table. + @raise Not_found if error.*) + val search_module_type : tab -> string -> Types.module_type option + + (** This function returns the Types.type_expr for the given val name + in the given class signature. + @raise Not_found if error.*) + val search_attribute_type : + Types.Vars.key -> Types.class_signature -> Types.type_expr + + (** This function returns the Types.type_expr for the given method name + in the given class signature. + @raise Not_found if error.*) + val search_method_type : + string -> Types.class_signature -> Types.type_expr + end + +(** Functions to retrieve simple and special comments from strings. *) +module type Info_retriever = + sig + (** Return the couple [(n, list)] where [n] is the number of + characters read to retrieve [list], which is the list + of special comments found in the string. *) + val all_special : + string -> string -> int * Odoc_types.info list + + (** Return true if the given string contains a blank line. *) + val blank_line_outside_simple : + string -> string -> bool + + (** [just_after_special file str] return the pair ([length], [info_opt]) + where [info_opt] is the first optional special comment found + in [str], without any blank line before. [length] is the number + of chars from the beginning of [str] to the end of the special comment. *) + val just_after_special : + string -> string -> (int * Odoc_types.info option) + + (** [first_special file str] return the pair ([length], [info_opt]) + where [info_opt] is the first optional special comment found + in [str]. [length] is the number of chars from the beginning of [str] + to the end of the special comment. *) + val first_special : + string -> string -> (int * Odoc_types.info option) + + (** Return a pair [(comment_opt, element_comment_list)], where [comment_opt] is the last special + comment found in the given string and not followed by a blank line, + and [element_comment_list] the list of values built from the other + special comments found and the given function. *) + val get_comments : + (Odoc_types.text -> 'a) -> string -> string -> (Odoc_types.info option * 'a list) + + end + +module Analyser : + functor (My_ir : Info_retriever) -> + sig + (** This variable is used to load a file as a string and retrieve characters from it.*) + val file : string ref + + (** The name of the analysed file. *) + val file_name : string ref + + (** This function takes two indexes (start and end) and return the string + corresponding to the indexes in the file global variable. The function + prepare_file must have been called to fill the file global variable.*) + val get_string_of_file : int -> int -> string + + (** [prepare_file f input_f] sets [file_name] with [f] and loads the file + [input_f] into [file].*) + val prepare_file : string -> string -> unit + + (** The function used to get the comments in a class. *) + val get_comments_in_class : int -> int -> + (Odoc_types.info option * Odoc_class.class_element list) + + (** The function used to get the comments in a module. *) + val get_comments_in_module : int -> int -> + (Odoc_types.info option * Odoc_module.module_element list) + + (** [name_comment_from_type_kind pos_end pos_limit type_kind]. + This function takes a [Parsetree.type_kind] and returns the list of + (name, optional comment) for the various fields/constructors of the type, + or an empty list for an abstract type. + [pos_end] is last char of the complete type definition. + [pos_limit] is the position of the last char we could use to look for a comment, + i.e. usually the beginning on the next element.*) + val name_comment_from_type_kind : + int -> int -> Parsetree.type_kind -> int * (string * Odoc_types.info option) list + + (** This function converts a [Types.type_kind] into a [Odoc_type.type_kind], + by associating the comment found in the parsetree of each constructor/field, if any.*) + val get_type_kind : + Odoc_env.env -> (string * Odoc_types.info option) list -> + Types.type_kind -> Odoc_type.type_kind + + (** This function merge two optional info structures. *) + val merge_infos : + Odoc_types.info option -> Odoc_types.info option -> + Odoc_types.info option + + (** Return a module_type_kind from a Parsetree.module_type and a Types.module_type *) + val analyse_module_type_kind : + Odoc_env.env -> Odoc_name.t -> + Parsetree.module_type -> Types.module_type -> + Odoc_module.module_type_kind + + (** Analysis of a Parsetree.class_type and a Types.class_type to + return a class_type_kind.*) + val analyse_class_type_kind : Odoc_env.env -> + Odoc_name.t -> int -> Parsetree.class_type -> Types.class_type -> + Odoc_class.class_type_kind + + (** This function takes an interface file name, a file containg the code, a parse tree + and the signature obtained from the compiler. + It goes through the parse tree, creating values for encountered + functions, modules, ..., looking in the source file for comments, + and in the signature for types information. *) + val analyse_signature : + string -> string -> + Parsetree.signature -> Types.signature -> Odoc_module.t_module + end diff --git a/ocamldoc/odoc_str.ml b/ocamldoc/odoc_str.ml new file mode 100644 index 0000000..323930f --- /dev/null +++ b/ocamldoc/odoc_str.ml @@ -0,0 +1,277 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_str.ml,v 1.13 2008-07-23 08:55:36 guesdon Exp $ *) + +(** The functions to get a string from different kinds of elements (types, modules, ...). *) + +module Name = Odoc_name + +let string_of_variance t (co,cn) = + if t.Odoc_type.ty_kind = Odoc_type.Type_abstract && + t.Odoc_type.ty_manifest = None + then + match (co, cn) with + (true, false) -> "+" + | (false, true) -> "-" + | _ -> "" + else + "" +let rec is_arrow_type t = + match t.Types.desc with + Types.Tarrow _ -> true + | Types.Tlink t2 | Types.Tsubst t2 -> is_arrow_type t2 + | Types.Ttuple _ + | Types.Tconstr _ + | Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _ + | Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false + +let raw_string_of_type_list sep type_list = + let buf = Buffer.create 256 in + let fmt = Format.formatter_of_buffer buf in + let rec need_parent t = + match t.Types.desc with + Types.Tarrow _ | Types.Ttuple _ -> true + | Types.Tlink t2 | Types.Tsubst t2 -> need_parent t2 + | Types.Tconstr _ -> + false + | Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _ + | Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false + in + let print_one_type variance t = + Printtyp.mark_loops t; + if need_parent t then + ( + Format.fprintf fmt "(%s" variance; + Printtyp.type_scheme_max ~b_reset_names: false fmt t; + Format.fprintf fmt ")" + ) + else + ( + Format.fprintf fmt "%s" variance; + Printtyp.type_scheme_max ~b_reset_names: false fmt t + ) + in + begin match type_list with + [] -> () + | [(variance, ty)] -> print_one_type variance ty + | (variance, ty) :: tyl -> + Format.fprintf fmt "@[<hov 2>"; + print_one_type variance ty; + List.iter + (fun (variance, t) -> + Format.fprintf fmt "@,%s" sep; + print_one_type variance t + ) + tyl; + Format.fprintf fmt "@]" + end; + Format.pp_print_flush fmt (); + Buffer.contents buf + +let string_of_type_list ?par sep type_list = + let par = + match par with + | Some b -> b + | None -> + match type_list with + [] | [_] -> false + | _ -> true + in + Printf.sprintf "%s%s%s" + (if par then "(" else "") + (raw_string_of_type_list sep (List.map (fun t -> ("", t)) type_list)) + (if par then ")" else "") + +let string_of_type_param_list t = + let par = + match t.Odoc_type.ty_parameters with + [] | [_] -> false + | _ -> true + in + Printf.sprintf "%s%s%s" + (if par then "(" else "") + (raw_string_of_type_list ", " + (List.map + (fun (typ, co, cn) -> (string_of_variance t (co, cn), typ)) + t.Odoc_type.ty_parameters + ) + ) + (if par then ")" else "") + +let string_of_class_type_param_list l = + let par = + match l with + [] | [_] -> false + | _ -> true + in + Printf.sprintf "%s%s%s" + (if par then "[" else "") + (raw_string_of_type_list ", " + (List.map + (fun typ -> ("", typ)) + l + ) + ) + (if par then "]" else "") + +let string_of_class_params c = + let b = Buffer.create 256 in + let rec iter = function + Types.Tcty_fun (label, t, ctype) -> + let parent = is_arrow_type t in + Printf.bprintf b "%s%s%s%s -> " + ( + match label with + "" -> "" + | s -> s^":" + ) + (if parent then "(" else "") + (Odoc_print.string_of_type_expr + (if Odoc_misc.is_optional label then + Odoc_misc.remove_option t + else + t + ) + ) + (if parent then ")" else ""); + iter ctype + | Types.Tcty_signature _ + | Types.Tcty_constr _ -> () + in + iter c.Odoc_class.cl_type; + Buffer.contents b + +let bool_of_private = function + | Asttypes.Private -> true + | _ -> false + +let string_of_type t = + let module M = Odoc_type in + "type "^ + (String.concat "" + (List.map + (fun (p, co, cn) -> + (string_of_variance t (co, cn))^ + (Odoc_print.string_of_type_expr p)^" " + ) + t.M.ty_parameters + ) + )^ + let priv = bool_of_private (t.M.ty_private) in + (Name.simple t.M.ty_name)^" "^ + (match t.M.ty_manifest with + None -> "" + | Some typ -> + "= " ^ (if priv then "private " else "" ) ^ + (Odoc_print.string_of_type_expr typ)^" " + )^ + (match t.M.ty_kind with + M.Type_abstract -> + "" + | M.Type_variant l -> + "="^(if priv then " private" else "")^"\n"^ + (String.concat "" + (List.map + (fun cons -> + " | "^cons.M.vc_name^ + (match cons.M.vc_args with + [] -> "" + | l -> + " of "^(String.concat " * " + (List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") l)) + )^ + (match cons.M.vc_text with + None -> + "" + | Some t -> + "(* "^(Odoc_misc.string_of_text t)^" *)" + )^"\n" + ) + l + ) + ) + | M.Type_record l -> + "= "^(if priv then "private " else "")^"{\n"^ + (String.concat "" + (List.map + (fun record -> + " "^(if record.M.rf_mutable then "mutable " else "")^ + record.M.rf_name^" : "^(Odoc_print.string_of_type_expr record.M.rf_type)^";"^ + (match record.M.rf_text with + None -> + "" + | Some t -> + "(* "^(Odoc_misc.string_of_text t)^" *)" + )^"\n" + ) + l + ) + )^ + "}\n" + )^ + (match t.M.ty_info with + None -> "" + | Some info -> Odoc_misc.string_of_info info) + +let string_of_exception e = + let module M = Odoc_exception in + "exception "^(Name.simple e.M.ex_name)^ + (match e.M.ex_args with + [] -> "" + | _ ->" : "^ + (String.concat " -> " + (List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") e.M.ex_args) + ) + )^ + (match e.M.ex_alias with + None -> "" + | Some ea -> + " = "^ + (match ea.M.ea_ex with + None -> ea.M.ea_name + | Some e2 -> e2.M.ex_name + ) + )^"\n"^ + (match e.M.ex_info with + None -> "" + | Some i -> Odoc_misc.string_of_info i) + +let string_of_value v = + let module M = Odoc_value in + "val "^(Name.simple v.M.val_name)^" : "^ + (Odoc_print.string_of_type_expr v.M.val_type)^"\n"^ + (match v.M.val_info with + None -> "" + | Some i -> Odoc_misc.string_of_info i) + +let string_of_attribute a = + let module M = Odoc_value in + "val "^ + (if a.M.att_virtual then "virtual " else "")^ + (if a.M.att_mutable then Odoc_messages.mutab^" " else "")^ + (Name.simple a.M.att_value.M.val_name)^" : "^ + (Odoc_print.string_of_type_expr a.M.att_value.M.val_type)^"\n"^ + (match a.M.att_value.M.val_info with + None -> "" + | Some i -> Odoc_misc.string_of_info i) + +let string_of_method m = + let module M = Odoc_value in + "method "^ + (if m.M.met_private then Odoc_messages.privat^" " else "")^ + (Name.simple m.M.met_value.M.val_name)^" : "^ + (Odoc_print.string_of_type_expr m.M.met_value.M.val_type)^"\n"^ + (match m.M.met_value.M.val_info with + None -> "" + | Some i -> Odoc_misc.string_of_info i) + +(* eof $Id: odoc_str.ml,v 1.13 2008-07-23 08:55:36 guesdon Exp $ *) diff --git a/ocamldoc/odoc_str.mli b/ocamldoc/odoc_str.mli new file mode 100644 index 0000000..2469c6e --- /dev/null +++ b/ocamldoc/odoc_str.mli @@ -0,0 +1,51 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_str.mli,v 1.6 2004-08-20 17:04:35 doligez Exp $ *) + +(** The functions to get a string from different kinds of elements (types, modules, ...). *) + +(** @return the variance string for the given type and (covariant, contravariant) information. *) +val string_of_variance : Odoc_type.t_type -> (bool * bool) -> string + +(** This function returns a string to represent the given list of types, + with a given separator. + @param par can be used to force the addition or not of parentheses around the returned string. +*) +val string_of_type_list : ?par: bool -> string -> Types.type_expr list -> string + +(** This function returns a string to represent the list of type parameters + for the given type. *) +val string_of_type_param_list : Odoc_type.t_type -> string + +(** This function returns a string to represent the given list of + type parameters of a class or class type, + with a given separator. *) +val string_of_class_type_param_list : Types.type_expr list -> string + +(** @return a string to describe the given type. *) +val string_of_type : Odoc_type.t_type -> string + +(** @return a string to display the parameters of the given class, + in the same form as the compiler. *) +val string_of_class_params : Odoc_class.t_class -> string + +(** @return a string to describe the given exception. *) +val string_of_exception : Odoc_exception.t_exception -> string + +(** @return a string to describe the given value. *) +val string_of_value : Odoc_value.t_value -> string + +(** @return a string to describe the given attribute. *) +val string_of_attribute : Odoc_value.t_attribute -> string + +(** @return a string to describe the given method. *) +val string_of_method : Odoc_value.t_method -> string diff --git a/ocamldoc/odoc_test.ml b/ocamldoc/odoc_test.ml new file mode 100644 index 0000000..8abb148 --- /dev/null +++ b/ocamldoc/odoc_test.ml @@ -0,0 +1,112 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_test.ml,v 1.1 2004-02-20 16:28:27 guesdon Exp $ *) + +(** Custom generator to perform test on ocamldoc. *) + +open Odoc_info +open Odoc_info.Module +open Odoc_info.Type + +type test_kind = + Types_display + +let p = Format.fprintf + +class string_gen = + object(self) + inherit Odoc_info.Scan.scanner + + val mutable test_kinds = [] + val mutable fmt = Format.str_formatter + + method must_display_types = List.mem Types_display test_kinds + + method set_test_kinds_from_module m = + test_kinds <- List.fold_left + (fun acc (s, _) -> + match s with + "test_types_display" -> Types_display :: acc + | _ -> acc + ) + [] + ( + match m.m_info with + None -> [] + | Some i -> i.i_custom + ) + method scan_type t = + match test_kinds with + [] -> () + | _ -> + p fmt "# type %s:\n" t.ty_name; + if self#must_display_types then + ( + p fmt "# manifest (Odoc_info.string_of_type_expr):\n<[%s]>\n" + (match t.ty_manifest with + None -> "None" + | Some e -> Odoc_info.string_of_type_expr e + ); + ); + + + method scan_module_pre m = + p fmt "#\n# module %s:\n" m.m_name ; + if self#must_display_types then + ( + p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n" + (Odoc_info.string_of_module_type m.m_type); + p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n" + (Odoc_info.string_of_module_type ~complete: true m.m_type); + ); + true + + method scan_module_type_pre m = + p fmt "#\n# module type %s:\n" m.mt_name ; + if self#must_display_types then + ( + p fmt "# Odoc_info.string_of_module_type:\n<[%s]>\n" + (match m.mt_type with + None -> "None" + | Some t -> Odoc_info.string_of_module_type t + ); + p fmt "# Odoc_info.string_of_module_type ~complete: true :\n<[%s]>\n" + (match m.mt_type with + None -> "None" + | Some t -> Odoc_info.string_of_module_type ~complete: true t + ); + ); + true + + method generate (module_list: Odoc_info.Module.t_module list) = + let oc = open_out !Odoc_info.Args.out_file in + fmt <- Format.formatter_of_out_channel oc; + ( + try + List.iter + (fun m -> + self#set_test_kinds_from_module m; + self#scan_module_list [m]; + ) + module_list + with + e -> + prerr_endline (Printexc.to_string e) + ); + Format.pp_print_flush fmt (); + close_out oc + end + + +let my_generator = new string_gen +let _ = Odoc_info.Args.set_doc_generator + (Some (my_generator :> Odoc_info.Args.doc_generator)) diff --git a/ocamldoc/odoc_texi.ml b/ocamldoc/odoc_texi.ml new file mode 100644 index 0000000..0d437b9 --- /dev/null +++ b/ocamldoc/odoc_texi.ml @@ -0,0 +1,1222 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Olivier Andrieu, base sur du code de Maxence Guesdon *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(***********************************************************************) + +(* $Id: odoc_texi.ml,v 1.24 2008-07-23 08:55:36 guesdon Exp $ *) + +(** Generation of Texinfo documentation. *) + +open Odoc_info +open Parameter +open Value +open Type +open Exception +open Class +open Module + +(** {2 Some small helper functions} *) + +let puts_nl chan s = + output_string chan s ; + output_char chan '\n' +let puts chan s = + output_string chan s +let nl chan = + output_char chan '\n' + +let is = function + | None -> false + | Some _ -> true + +let pad_to n s = + let len = String.length s in + if len < n + then + let s' = String.make n ' ' in + String.blit s 0 s' 0 len ; s' + else s + +let indent nb_sp s = + let c = ref 0 in + let len = pred (String.length s) in + for i = 0 to len do if s.[i] = '\n' then incr c done ; + let s' = String.make (succ len + (succ !c) * nb_sp ) ' ' in + c := nb_sp ; + for i = 0 to len do + s'.[!c] <- s.[i] ; + if s.[i] = '\n' then c := !c + nb_sp ; + incr c + done ; + s' + +type subparts = [ + | `Module of Odoc_info.Module.t_module + | `Module_type of Odoc_info.Module.t_module_type + | `Class of Odoc_info.Class.t_class + | `Class_type of Odoc_info.Class.t_class_type + ] + +type menu_data = [ + | subparts + | `Blank + | `Comment of string + | `Texi of string + | `Index of string +] list + +let nothing = Verbatim "" + +let module_subparts = + let rec iter acc = function + | [] -> List.rev acc + (* skip aliases *) + | Element_module { m_kind = Module_alias _ } :: n -> + iter acc n + | Element_module_type { mt_kind = Some (Module_type_alias _) } :: n -> + iter acc n + (* keep modules, module types, classes and class types *) + | Element_module m :: n -> + iter (`Module m :: acc) n + | Element_module_type mt :: n -> + iter (`Module_type mt :: acc) n + | Element_class c :: n -> + iter (`Class c :: acc) n + | Element_class_type ct :: n -> + iter (`Class_type ct :: acc) n + (* forget the rest *) + | _ :: n -> iter acc n + in + iter [] + +type indices = [ + | `Type + | `Exception + | `Value + | `Class_att + | `Method + | `Class + | `Class_type + | `Module + | `Module_type +] + +let indices = function + | `Type -> "ty" + | `Exception -> "ex" + | `Value -> "va" + | `Class_att -> "ca" + | `Method -> "me" + | `Class -> "cl" + | `Class_type -> "ct" + | `Module -> "mo" + | `Module_type -> "mt" + +let indices_names = [ + "Types" , "ty" ; + "Exceptions" , "ex" ; + "Values" , "va" ; + "Class attributes", "ca" ; + "Methods" , "me" ; + "Classes" , "cl" ; + "Class types" , "ct" ; + "Modules" , "mo" ; + "Module types" , "mt" ; ] + + + +(** Module for generating various Texinfo things (menus, xrefs, ...) *) +module Texi = +struct + (** Associations of strings to subsitute in Texinfo code. *) + let subst_strings = [ + (Str.regexp "@", "@@") ; + (Str.regexp "{", "@{") ; + (Str.regexp "}", "@}") ; + (Str.regexp "\\.\\.\\.", "@dots{}") ; + ] @ + (if !Args.esc_8bits + then [ + (Str.regexp "à", "@`a") ; + (Str.regexp "â", "@^a") ; + (Str.regexp "é", "@'e") ; + (Str.regexp "è", "@`e") ; + (Str.regexp "ê", "@^e") ; + (Str.regexp "ë", "@\"e") ; + (Str.regexp "ç", "@,{c}") ; + (Str.regexp "ô", "@^o") ; + (Str.regexp "ö", "@\"o") ; + (Str.regexp "î", "@^i") ; + (Str.regexp "ï", "@\"i") ; + (Str.regexp "ù", "@`u") ; + (Str.regexp "û", "@^u") ; + (Str.regexp "æ", "@ae{}" ) ; + (Str.regexp "Æ", "@AE{}" ) ; + (Str.regexp "ß", "@ss{}" ) ; + (Str.regexp "©", "@copyright{}" ) ; + ] + else []) + + (** Escape the strings which would clash with Texinfo syntax. *) + let escape s = + List.fold_left + (fun acc (p, r) -> Str.global_replace p r acc) + s subst_strings + + (** Removes dots (no good for a node name). *) + let fix_nodename s = + Str.global_replace (Str.regexp "\\.") "/" (escape s) + + (** Generates a Texinfo menu. *) + let generate_menu chan subpart_list = + if subpart_list <> [] + then begin + let menu_line part_qual name = + let sname = Name.simple name in + if sname = name + then ( + puts chan (pad_to 35 + ("* " ^ sname ^ ":: ")) ; + puts_nl chan part_qual ) + else ( + puts chan (pad_to 35 + ("* " ^ sname ^ ": " ^ (fix_nodename name) ^ ". " )) ; + puts_nl chan part_qual ) + in + puts_nl chan "@menu" ; + List.iter + (function + | `Module { m_name = name } -> + menu_line Odoc_messages.modul name + | `Module_type { mt_name = name } -> + menu_line Odoc_messages.module_type name + | `Class { cl_name = name } -> + menu_line Odoc_messages.clas name + | `Class_type { clt_name = name } -> + menu_line Odoc_messages.class_type name + | `Blank -> nl chan + | `Comment c -> puts_nl chan (escape c) + | `Texi t -> puts_nl chan t + | `Index ind -> Printf.fprintf chan "* %s::\n" ind) + subpart_list ; + puts_nl chan "@end menu" + end + + (** cross reference to node [name] *) + let xref ?xname name = + "@xref{" ^ (fix_nodename name) ^ + (match xname with | None -> "" | Some s -> "," ^ s) ^ + "}." + + (** enclose the string between [\@ifinfo] tags *) + let ifinfo s = + String.concat "\n" + [ "@ifinfo" ; s ; "@end ifinfo" ; "" ] + + (** [install-info] informations *) + let dirsection sec = + "@dircategory " ^ (escape sec) + + let direntry ent = + [ "@direntry" ] @ + (List.map escape ent) @ + [ "@end direntry" ] +end + + + + + +(** {2 Generation of Texinfo code} *) + +(** This class generates Texinfo code from text structures *) +class text = + object(self) + + (** Associations between a title number and texinfo code. *) + val titles = [ + 1, "@chapter " ; + 2, "@section " ; + 3, "@subsection " ; + 4, "@subsubsection " ; + ] + + val fallback_title = + "@unnumberedsubsubsec " + + val headings = [ + 1, "@majorheading " ; + 2, "@heading " ; + 3, "@subheading " ; + 4, "@subsubheading " ; + ] + + val fallback_heading = + "@subsubheading " + + method escape = + Texi.escape + + (** this method is not used here but is virtual + in a class we will inherit later *) + method label ?(no_ : bool option) (_ : string) : string = + failwith "gni" + + (** Return the Texinfo code corresponding to the [text] parameter.*) + method texi_of_text t = + String.concat "" + (List.map self#texi_of_text_element t) + + + (** {3 Conversion methods} + [texi_of_????] converts a [text_element] to a Texinfo string. *) + + (** Return the Texinfo code for the [text_element] in parameter. *) + method texi_of_text_element = function + | Verbatim s | Latex s -> self#texi_of_Verbatim s + | Raw s -> self#texi_of_Raw s + | Code s -> self#texi_of_Code s + | CodePre s -> self#texi_of_CodePre s + | Bold t -> self#texi_of_Bold t + | Italic t -> self#texi_of_Italic t + | Emphasize t -> self#texi_of_Emphasize t + | Center t -> self#texi_of_Center t + | Left t -> self#texi_of_Left t + | Right t -> self#texi_of_Right t + | List tl -> self#texi_of_List tl + | Enum tl -> self#texi_of_Enum tl + | Newline -> self#texi_of_Newline + | Block t -> self#texi_of_Block t + | Title (n, _, t) -> self#texi_of_Title n t + | Link (s, t) -> self#texi_of_Link s t + | Ref (name, kind) ->self#texi_of_Ref name kind + | Superscript t -> self#texi_of_Superscript t + | Subscript t -> self#texi_of_Subscript t + | Odoc_info.Module_list _ -> "" + | Odoc_info.Index_list -> "" + | Odoc_info.Custom (s,t) -> self#texi_of_custom_text s t + + method texi_of_custom_text s t = "" + + method texi_of_Verbatim s = s + method texi_of_Raw s = self#escape s + method texi_of_Code s = "@code{" ^ (self#escape s) ^ "}" + method texi_of_CodePre s = + String.concat "\n" + [ "" ; "@example" ; self#escape s ; "@end example" ; "" ] + method texi_of_Bold t = "@strong{" ^ (self#texi_of_text t) ^ "}" + method texi_of_Italic t = "@i{" ^ (self#texi_of_text t) ^ "}" + method texi_of_Emphasize t = "@emph{" ^ (self#texi_of_text t) ^ "}" + method texi_of_Center t = + let sl = Str.split (Str.regexp "\n") (self#texi_of_text t) in + String.concat "" + ((List.map (fun s -> "\n@center "^s) sl) @ [ "\n" ]) + method texi_of_Left t = + String.concat "\n" + [ "" ; "@flushleft" ; self#texi_of_text t ; "@end flushleft" ; "" ] + method texi_of_Right t = + String.concat "\n" + [ "" ; "@flushright" ; self#texi_of_text t ; "@end flushright"; "" ] + method texi_of_List tl = + String.concat "\n" + ( [ "" ; "@itemize" ] @ + (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ + [ "@end itemize"; "" ] ) + method texi_of_Enum tl = + String.concat "\n" + ( [ "" ; "@enumerate" ] @ + (List.map (fun t -> "@item\n" ^ (self#texi_of_text t)) tl) @ + [ "@end enumerate"; "" ] ) + method texi_of_Newline = "\n" + method texi_of_Block t = + String.concat "\n" + [ "@format" ; self#texi_of_text t ; "@end format" ; "" ] + method texi_of_Title n t = + let t_begin = + try List.assoc n titles + with Not_found -> fallback_title in + t_begin ^ (self#texi_of_text t) ^ "\n" + method texi_of_Link s t = + String.concat "" + [ "@uref{" ; s ; "," ; self#texi_of_text t ; "}" ] + method texi_of_Ref name kind = + let xname = + match kind with + | Some RK_module -> + Odoc_messages.modul ^ " " ^ (Name.simple name) + | Some RK_module_type -> + Odoc_messages.module_type ^ " " ^ (Name.simple name) + | Some RK_class -> + Odoc_messages.clas ^ " " ^ (Name.simple name) + | Some RK_class_type -> + Odoc_messages.class_type ^ " " ^ (Name.simple name) + | _ -> "" + in + if xname = "" then self#escape name else Texi.xref ~xname name + method texi_of_Superscript t = + "^@{" ^ (self#texi_of_text t) ^ "@}" + method texi_of_Subscript t = + "_@{" ^ (self#texi_of_text t) ^ "@}" + + method heading n t = + let f = + try List.assoc n headings + with Not_found -> fallback_heading + in + f ^ (self#texi_of_text t) ^ "\n" + + method fixedblock t = + Block ( ( Verbatim "@t{" :: t ) @ [ Verbatim "}" ] ) + + end + +exception Aliased_node + +(** This class is used to create objects which can generate a simple + Texinfo documentation. *) +class texi = + object (self) + inherit text as to_texi + inherit Odoc_to_text.to_text as to_text + + (** {3 Small helper stuff.} *) + + val maxdepth = 4 + + val bullet = Verbatim " @bullet{} " + val minus = Verbatim " @minus{} " + val linebreak = Verbatim "@*\n" + + val mutable indices_to_build = [ `Module ] + + (** Keep a set of nodes we create. If we try to create one + a second time, that means it is some kind of alias, so + don't do it, just link to the previous one *) + val node_tbl = Hashtbl.create 37 + + method node depth name = + if Hashtbl.mem node_tbl name + then raise Aliased_node ; + Hashtbl.add node_tbl name () ; + if depth <= maxdepth + then Verbatim ("@node " ^ (Texi.fix_nodename name) ^ ",\n") + else nothing + + method index (ind : indices) ent = + Verbatim + (if !Args.with_index + then (assert(List.mem ind indices_to_build) ; + String.concat "" + [ "@" ; indices ind ; "index " ; + Texi.escape (Name.simple ent) ; "\n" ]) + else "") + + + (** Two hacks to fix linebreaks in the descriptions.*) + method private fix_linebreaks = + let re = Str.regexp "\n[ \t]*" in + fun t -> + List.map + (function + | Newline -> Raw "\n" + | Raw s -> Raw (Str.global_replace re "\n" s) + | List tel -> List (List.map self#fix_linebreaks tel) + | Enum tel -> Enum (List.map self#fix_linebreaks tel) + | te -> te) t + + method private soft_fix_linebreaks = + let re = Str.regexp "\n[ \t]*" in + fun ind t -> + let rep = String.make (succ ind) ' ' in + rep.[0] <- '\n' ; + List.map + (function + | Raw s -> Raw (Str.global_replace re rep s) + | te -> te) t + + (** {3 [text] values generation} + Generates [text] values out of description parts. + Redefines some of methods of {! Odoc_to_text.to_text}. *) + + method text_of_desc = function + | None -> [] + | Some [ Raw "" ] -> [] + | Some t -> (self#fix_linebreaks t) @ [ Newline ] + + method text_of_sees_opt see_l = + List.concat + (List.map + (function + | (See_url s, t) -> + [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; + Raw " " ; Link (s, t) ; Newline ] + | (See_file s, t) + | (See_doc s, t) -> + [ linebreak ; Bold [ Raw Odoc_messages.see_also ] ; + Raw " " ; Raw s ] @ t @ [ Newline ]) + see_l) + + method text_of_params params_list = + List.concat + (List.map + (fun (s, t) -> + [ linebreak ; + Bold [ Raw Odoc_messages.parameters ] ; + Raw " " ; Raw s ; Raw ": " ] @ t @ [ Newline ] ) + params_list) + + method text_of_raised_exceptions = function + | [] -> [] + | (s, t) :: [] -> + [ linebreak ; + Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; Code s ; Raw " " ] + @ t @ [ Newline ] + | l -> + [ linebreak ; + Bold [ Raw Odoc_messages.raises ] ; + Raw " :" ; + List + (List.map + (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) l ) ; + Newline ] + + method text_of_return_opt = function + | None -> [] + | Some t -> + (Bold [Raw Odoc_messages.returns ]) :: Raw " " :: t @ [ Newline ] + + method text_of_custom c_l = + List.flatten + (List.rev + (List.fold_left + (fun acc -> fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + ( linebreak :: (f text) @ [ Newline ] ) :: acc + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; + acc + ) [] c_l)) + + method text_of_info ?(block=false) = function + | None -> [] + | Some info -> + let t = + List.concat + [ ( match info.i_deprecated with + | None -> [] + | Some t -> + (Raw (Odoc_messages.deprecated ^ " ")) :: + (self#fix_linebreaks t) + @ [ Newline ; Newline ] ) ; + self#text_of_desc info.i_desc ; + if info.i_authors <> [] + then ( linebreak :: + self#text_of_author_list info.i_authors ) + else [] ; + if is info.i_version + then ( linebreak :: + self#text_of_version_opt info.i_version ) + else [] ; + self#text_of_sees_opt info.i_sees ; + if is info.i_since + then ( linebreak :: + self#text_of_since_opt info.i_since ) + else [] ; + self#text_of_params info.i_params ; + self#text_of_raised_exceptions info.i_raised_exceptions ; + if is info.i_return_value + then ( linebreak :: + self#text_of_return_opt info.i_return_value ) + else [] ; + self#text_of_custom info.i_custom ; + ] in + if block + then [ Block t ] + else (t @ [ Newline ] ) + + method texi_of_info i = + self#texi_of_text (self#text_of_info i) + + (** {3 Conversion of [module_elements] into Texinfo strings} + The following functions convert [module_elements] and their + description to [text] values then to Texinfo strings using the + functions above. *) + + method text_el_of_type_expr m_name typ = + Raw (indent 5 + (self#relative_idents m_name + (Odoc_info.string_of_type_expr typ))) + + method text_of_short_type_expr m_name typ = + [ Raw (self#normal_type m_name typ) ] + + (** Return Texinfo code for a value. *) + method texi_of_value v = + Odoc_info.reset_type_names () ; + let t = [ self#fixedblock + [ Newline ; minus ; + Raw ("val " ^ (Name.simple v.val_name) ^ " :\n") ; + self#text_el_of_type_expr + (Name.father v.val_name) v.val_type ] ; + self#index `Value v.val_name ; Newline ] @ + (self#text_of_info v.val_info) in + self#texi_of_text t + + + (** Return Texinfo code for a class attribute. *) + method texi_of_attribute a = + Odoc_info.reset_type_names () ; + let t = [ self#fixedblock + [ Newline ; minus ; + Raw "val " ; + Raw (if a.att_virtual then "virtual " else "") ; + Raw (if a.att_mutable then "mutable " else "") ; + Raw (Name.simple a.att_value.val_name) ; + Raw " :\n" ; + self#text_el_of_type_expr + (Name.father a.att_value.val_name) + a.att_value.val_type ] ; + self#index `Class_att a.att_value.val_name ; Newline ] @ + (self#text_of_info a.att_value.val_info) in + self#texi_of_text t + + + (** Return Texinfo code for a class method. *) + method texi_of_method m = + Odoc_info.reset_type_names () ; + let t = [ self#fixedblock + [ Newline ; minus ; Raw "method " ; + Raw (if m.met_private then "private " else "") ; + Raw (if m.met_virtual then "virtual " else "") ; + Raw (Name.simple m.met_value.val_name) ; + Raw " :\n" ; + self#text_el_of_type_expr + (Name.father m.met_value.val_name) + m.met_value.val_type ] ; + self#index `Method m.met_value.val_name ; Newline ] @ + (self#text_of_info m.met_value.val_info) in + self#texi_of_text t + + + method string_of_type_parameters t = + let f (tp, co, cn) = + Printf.sprintf "%s%s" + (Odoc_info.string_of_variance t (co, cn)) + (Odoc_info.string_of_type_expr tp) + in + match t.ty_parameters with + | [] -> "" + | [ (tp, co, cn) ] -> + (f (tp, co, cn))^" " + | l -> + Printf.sprintf "(%s) " + (String.concat ", " (List.map f l)) + + method string_of_type_args = function + | [] -> "" + | args -> " of " ^ (Odoc_info.string_of_type_list " * " args) + + (** Return Texinfo code for a type. *) + method texi_of_type ty = + Odoc_info.reset_type_names () ; + let t = + [ self#fixedblock ( + [ Newline ; minus ; Raw "type " ; + Raw (self#string_of_type_parameters ty) ; + Raw (Name.simple ty.ty_name) ] @ + let priv = ty.ty_private = Asttypes.Private in + ( match ty.ty_manifest with + | None -> [] + | Some typ -> + (Raw " = ") :: + (Raw (if priv then "private " else "")) :: + (self#text_of_short_type_expr (Name.father ty.ty_name) typ) ) @ + ( + match ty.ty_kind with + | Type_abstract -> [ Newline ] + | Type_variant l -> + (Raw (" ="^(if priv then " private" else "")^"\n")) :: + (List.flatten + (List.map + (fun constr -> + (Raw (" | " ^ constr.vc_name)) :: + (Raw (self#string_of_type_args constr.vc_args)) :: + (match constr.vc_text with + | None -> [ Newline ] + | Some t -> + ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ + [ Raw " *)" ; Newline ] + ) ) l ) ) + | Type_record l -> + (Raw (" = "^(if priv then "private " else "")^"{\n")) :: + (List.flatten + (List.map + (fun r -> + [ Raw (" " ^ r.rf_name ^ " : ") ] @ + (self#text_of_short_type_expr + (Name.father r.rf_name) + r.rf_type) @ + [ Raw " ;" ] @ + (match r.rf_text with + | None -> [ Newline ] + | Some t -> + ((Raw (indent 5 "\n(* ")) :: (self#soft_fix_linebreaks 8 t)) @ + [ Raw " *)" ; Newline ] ) ) + l ) ) + @ [ Raw " }" ] + ) ) ; + self#index `Type ty.ty_name ; Newline ] @ + (self#text_of_info ty.ty_info) in + self#texi_of_text t + + (** Return Texinfo code for an exception. *) + method texi_of_exception e = + Odoc_info.reset_type_names () ; + let t = + [ self#fixedblock + ( [ Newline ; minus ; Raw "exception " ; + Raw (Name.simple e.ex_name) ; + Raw (self#string_of_type_args e.ex_args) ] @ + (match e.ex_alias with + | None -> [] + | Some ea -> [ Raw " = " ; Raw + ( match ea.ea_ex with + | None -> ea.ea_name + | Some e -> e.ex_name ) ; ] + ) ) ; + self#index `Exception e.ex_name ; Newline ] @ + (self#text_of_info e.ex_info) in + self#texi_of_text t + + + (** Return the Texinfo code for the given module. *) + method texi_of_module m = + let is_alias = function + | { m_kind = Module_alias _ } -> true + | _ -> false in + let is_alias_there = function + | { m_kind = Module_alias { ma_module = None } } -> false + | _ -> true in + let resolve_alias_name = function + | { m_kind = Module_alias { ma_name = name } } -> name + | { m_name = name } -> name in + let t = + [ [ self#fixedblock + [ Newline ; minus ; Raw "module " ; + Raw (Name.simple m.m_name) ; + Raw (if is_alias m + then " = " ^ (resolve_alias_name m) + else "" ) ] ] ; + ( if is_alias_there m + then [ Ref (resolve_alias_name m, Some RK_module) ; + Newline ; ] + else [] ) ; + ( if is_alias m + then [ self#index `Module m.m_name ; Newline ] + else [ Newline ] ) ; + self#text_of_info m.m_info ] + in + self#texi_of_text (List.flatten t) + + (** Return the Texinfo code for the given module type. *) + method texi_of_module_type mt = + let is_alias = function + | { mt_kind = Some (Module_type_alias _) } -> true + | _ -> false in + let is_alias_there = function + | { mt_kind = Some (Module_type_alias { mta_module = None }) } -> false + | _ -> true in + let resolve_alias_name = function + | { mt_kind = Some (Module_type_alias { mta_name = name }) } -> name + | { mt_name = name } -> name in + let t = + [ [ self#fixedblock + [ Newline ; minus ; Raw "module type " ; + Raw (Name.simple mt.mt_name) ; + Raw (if is_alias mt + then " = " ^ (resolve_alias_name mt) + else "" ) ] ] ; + ( if is_alias_there mt + then [ Ref (resolve_alias_name mt, Some RK_module_type) ; + Newline ; ] + else [] ) ; + ( if is_alias mt + then [ self#index `Module_type mt.mt_name ; Newline ] + else [ Newline ] ) ; + self#text_of_info mt.mt_info ] + in + self#texi_of_text (List.flatten t) + + (** Return the Texinfo code for the given included module. *) + method texi_of_included_module im = + let t = [ self#fixedblock + ( Newline :: minus :: (Raw "include ") :: + ( match im.im_module with + | None -> + [ Raw im.im_name ] + | Some (Mod { m_name = name }) -> + [ Raw name ; Raw "\n " ; + Ref (name, Some RK_module) ] + | Some (Modtype { mt_name = name }) -> + [ Raw name ; Raw "\n " ; + Ref (name, Some RK_module_type) ] + ) @ + [ Newline ] @ + (self#text_of_info im.im_info) + ) + ] + in + self#texi_of_text t + + (** Return the Texinfo code for the given class. *) + method texi_of_class c = + Odoc_info.reset_type_names () ; + let t = [ self#fixedblock + [ Newline ; minus ; Raw "class " ; + Raw (Name.simple c.cl_name) ] ; + Ref (c.cl_name, Some RK_class) ; Newline ; + Newline ] @ (self#text_of_info c.cl_info) in + self#texi_of_text t + + (** Return the Texinfo code for the given class type. *) + method texi_of_class_type ct = + Odoc_info.reset_type_names () ; + let t = [ self#fixedblock + [ Newline ; minus ; Raw "class type " ; + Raw (Name.simple ct.clt_name) ] ; + Ref (ct.clt_name, Some RK_class_type) ; Newline ; + Newline ] @ (self#text_of_info ct.clt_info) in + self#texi_of_text t + + (** Return the Texinfo code for the given class element. *) + method texi_of_class_element class_name class_ele = + match class_ele with + | Class_attribute att -> self#texi_of_attribute att + | Class_method met -> self#texi_of_method met + | Class_comment t -> self#texi_of_text t + + (** Return the Texinfo code for the given module element. *) + method texi_of_module_element module_name module_ele = + (match module_ele with + | Element_module m -> self#texi_of_module m + | Element_module_type mt -> self#texi_of_module_type mt + | Element_included_module im -> self#texi_of_included_module im + | Element_class c -> self#texi_of_class c + | Element_class_type ct -> self#texi_of_class_type ct + | Element_value v -> self#texi_of_value v + | Element_exception e -> self#texi_of_exception e + | Element_type t -> self#texi_of_type t + | Element_module_comment t -> + self#texi_of_text (Newline :: t @ [Newline]) + ) + + (** {3 Generating methods } + These methods write Texinfo code to an [out_channel] *) + + (** Generate the Texinfo code for the given list of inherited classes.*) + method generate_inheritance_info chanout inher_l = + let f inh = + match inh.ic_class with + | None -> (* we can't make the reference *) + (Code inh.ic_name) :: + (match inh.ic_text with + | None -> [] + | Some t -> Newline :: t) + | Some cct -> (* we can create the reference *) + let kind = + match cct with + | Cl _ -> Some RK_class + | Cltype _ -> Some RK_class_type in + (Code inh.ic_name) :: + (Ref (inh.ic_name, kind)) :: + ( match inh.ic_text with + | None -> [] + | Some t -> Newline :: t) + in + let text = [ + Bold [ Raw Odoc_messages.inherits ] ; + List (List.map f inher_l) ; Newline ] + in + puts chanout (self#texi_of_text text) + + + + (** Generate the Texinfo code for the inherited classes + of the given class. *) + method generate_class_inheritance_info chanout cl = + let rec iter_kind = function + | Class_structure ([], _) -> () + | Class_structure (l, _) -> + self#generate_inheritance_info chanout l + | Class_constraint (k, _) -> iter_kind k + | Class_apply _ + | Class_constr _ -> () + in + iter_kind cl.cl_kind + + + + (** Generate the Texinfo code for the inherited classes + of the given class type. *) + method generate_class_type_inheritance_info chanout clt = + match clt.clt_kind with + | Class_signature ([], _) -> + () + | Class_signature (l, _) -> + self#generate_inheritance_info chanout l + | Class_type _ -> + () + + (** Generate the Texinfo code for the given class, + in the given out channel. *) + method generate_for_class chanout c = + try + Odoc_info.reset_type_names () ; + let depth = Name.depth c.cl_name in + let title = [ + self#node depth c.cl_name ; + Title (depth, None, [ Raw (Odoc_messages.clas ^ " ") ; + Code c.cl_name ]) ; + self#index `Class c.cl_name ] in + puts chanout (self#texi_of_text title) ; + + if is c.cl_info + then begin + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info c.cl_info) + end ; + + let intf = [ Title (succ depth, None, + [ Raw Odoc_messages.interface]) ] in + puts chanout (self#texi_of_text intf); + self#generate_class_inheritance_info chanout c ; + List.iter + (fun ele -> puts chanout + (self#texi_of_class_element c.cl_name ele)) + (Class.class_elements ~trans:false c) + with Aliased_node -> () + + + (** Generate the Texinfo code for the given class type, + in the given out channel. *) + method generate_for_class_type chanout ct = + try + Odoc_info.reset_type_names () ; + let depth = Name.depth ct.clt_name in + let title = [ + self#node depth ct.clt_name ; + Title (depth, None, [ Raw (Odoc_messages.class_type ^ " ") ; + Code ct.clt_name ]) ; + self#index `Class_type ct.clt_name ] in + puts chanout (self#texi_of_text title) ; + + if is ct.clt_info + then begin + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info ct.clt_info) + end ; + + let intf = [ Title (succ depth, None, + [ Raw Odoc_messages.interface ]) ] in + puts chanout (self#texi_of_text intf) ; + self#generate_class_type_inheritance_info chanout ct; + List.iter + (fun ele -> puts chanout + (self#texi_of_class_element ct.clt_name ele)) + (Class.class_type_elements ~trans:false ct) + with Aliased_node -> () + + + (** Generate the Texinfo code for the given module type, + in the given out channel. *) + method generate_for_module_type chanout mt = + try + let depth = Name.depth mt.mt_name in + let title = [ + self#node depth mt.mt_name ; + Title (depth, None, [ Raw (Odoc_messages.module_type ^ " ") ; + Code mt.mt_name ]) ; + self#index `Module_type mt.mt_name ; Newline ] in + puts chanout (self#texi_of_text title) ; + + if is mt.mt_info + then begin + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info mt.mt_info) + end ; + + let mt_ele = Module.module_type_elements ~trans:true mt in + let subparts = module_subparts mt_ele in + if depth < maxdepth && subparts <> [] + then begin + let menu = Texi.ifinfo + ( self#heading (succ depth) [ Raw "Subparts" ]) in + puts chanout menu ; + Texi.generate_menu chanout (subparts :> menu_data) + end ; + + let intf = [ Title (succ depth, None, + [ Raw Odoc_messages.interface ]) ] in + puts chanout (self#texi_of_text intf) ; + List.iter + (fun ele -> puts chanout + (self#texi_of_module_element mt.mt_name ele)) + mt_ele ; + + (* create sub parts for modules, module types, classes and class types *) + List.iter + (function + | `Module m -> self#generate_for_module chanout m + | `Module_type mt -> self#generate_for_module_type chanout mt + | `Class c -> self#generate_for_class chanout c + | `Class_type ct -> self#generate_for_class_type chanout ct) + subparts + with Aliased_node -> () + + (** Generate the Texinfo code for the given module, + in the given out channel. *) + method generate_for_module chanout m = + try + Odoc_info.verbose ("Generate for module " ^ m.m_name) ; + let depth = Name.depth m.m_name in + let title = [ + self#node depth m.m_name ; + Title (depth, None, + if m.m_text_only then + [ Raw m.m_name ] + else + [ Raw (Odoc_messages.modul ^ " ") ; + Code m.m_name ] + ) ; + self#index `Module m.m_name ; Newline ] in + puts chanout (self#texi_of_text title) ; + + if is m.m_info + then begin + let descr = [ Title (succ depth, None, + [ Raw Odoc_messages.description ]) ] in + puts chanout (self#texi_of_text descr) ; + puts chanout (self#texi_of_info m.m_info) + end ; + + let m_ele = Module.module_elements ~trans:true m in + let subparts = module_subparts m_ele in + if depth < maxdepth && subparts <> [] + then begin + let menu = Texi.ifinfo + ( self#heading (succ depth) [ Raw "Subparts" ]) in + puts chanout menu ; + Texi.generate_menu chanout (subparts :> menu_data) + end ; + + let intf = [ Title (succ depth, None, + [ Raw Odoc_messages.interface]) ] in + puts chanout (self#texi_of_text intf) ; + + List.iter + (fun ele -> puts chanout + (self#texi_of_module_element m.m_name ele)) + m_ele ; + + (* create sub nodes for modules, module types, classes and class types *) + List.iter + (function + | `Module m -> self#generate_for_module chanout m + | `Module_type mt -> self#generate_for_module_type chanout mt + | `Class c -> self#generate_for_class chanout c + | `Class_type ct -> self#generate_for_class_type chanout ct ) + subparts + with Aliased_node -> () + + + (** Writes the header of the TeXinfo document. *) + method generate_texi_header chan texi_filename m_list = + let title = match !Args.title with + | None -> "" + | Some s -> self#escape s in + let filename = + if texi_filename <> "ocamldoc.texi" + then + let fn = Filename.basename texi_filename in + (if Filename.check_suffix fn ".texi" + then Filename.chop_suffix fn ".texi" + else fn) ^ ".info" + else + if title <> "" + then title ^ ".info" + else "doc.info" + in + (* write a standard Texinfo header *) + List.iter + (puts_nl chan) + (List.flatten + [ [ "\\input texinfo @c -*-texinfo-*-" ; + "@c %**start of header" ; + "@setfilename " ^ filename ; + "@settitle " ^ title ; + "@c %**end of header" ; ] ; + + (if !Args.with_index then + List.map + (fun ind -> + "@defcodeindex " ^ (indices ind)) + indices_to_build + else []) ; + + [ Texi.dirsection !Args.info_section ] ; + + Texi.direntry + (if !Args.info_entry <> [] + then !Args.info_entry + else [ Printf.sprintf "* %s: (%s)." + title + (Filename.chop_suffix filename ".info") ]) ; + + [ "@ifinfo" ; + "This file was generated by Ocamldoc using the Texinfo generator." ; + "@end ifinfo" ; + + "@c no titlepage." ; + + "@node Top, , , (dir)" ; + "@top "^ title ; ] + ] ) ; + + (* insert the intro file *) + begin + match !Odoc_info.Args.intro_file with + | None when title <> "" -> + puts_nl chan "@ifinfo" ; + puts_nl chan ("Documentation for " ^ title) ; + puts_nl chan "@end ifinfo" + | None -> + puts_nl chan "@c no title given" + | Some f -> + nl chan ; + puts_nl chan + (self#texi_of_info + (Some (Odoc_info.info_of_comment_file m_list f))) + end ; + + (* write a top menu *) + Texi.generate_menu chan + ((List.map (fun m -> `Module m) m_list) @ + (if !Args.with_index then + let indices_names_to_build = List.map indices indices_to_build in + List.rev + (List.fold_left + (fun acc -> + function (longname, shortname) + when List.mem shortname indices_names_to_build -> + (`Index (longname ^ " index")) :: acc + | _ -> acc) + [ `Comment "Indices :" ; `Blank ] + indices_names ) + else [] )) + + + (** Writes the trailer of the TeXinfo document. *) + method generate_texi_trailer chan = + nl chan ; + if !Args.with_index + then + let indices_names_to_build = List.map indices indices_to_build in + List.iter (puts_nl chan) + (List.flatten + (List.map + (fun (longname, shortname) -> + if List.mem shortname indices_names_to_build + then [ "@node " ^ longname ^ " index," ; + "@unnumbered " ^ longname ^ " index" ; + "@printindex " ^ shortname ; ] + else []) + indices_names )) ; + if !Args.with_toc + then puts_nl chan "@contents" ; + puts_nl chan "@bye" + + + method do_index it = + if not (List.mem it indices_to_build) + then indices_to_build <- it :: indices_to_build + + (** Scan the whole module information to know which indices need to be build *) + method scan_for_index : subparts -> unit = function + | `Module m -> + let m_ele = Module.module_elements ~trans:true m in + List.iter self#scan_for_index_in_mod m_ele + | `Module_type mt -> + let m_ele = Module.module_type_elements ~trans:true mt in + List.iter self#scan_for_index_in_mod m_ele + | `Class c -> + let c_ele = Class.class_elements ~trans:true c in + List.iter self#scan_for_index_in_class c_ele + | `Class_type ct -> + let c_ele = Class.class_type_elements ~trans:true ct in + List.iter self#scan_for_index_in_class c_ele + + method scan_for_index_in_mod = function + (* no recursion *) + | Element_value _ -> self#do_index `Value + | Element_exception _ -> self#do_index `Exception + | Element_type _ -> self#do_index `Type + | Element_included_module _ + | Element_module_comment _ -> () + (* recursion *) + | Element_module m -> self#do_index `Module ; + self#scan_for_index (`Module m) + | Element_module_type mt -> self#do_index `Module_type ; + self#scan_for_index (`Module_type mt) + | Element_class c -> self#do_index `Class ; + self#scan_for_index (`Class c) + | Element_class_type ct -> self#do_index `Class_type ; + self#scan_for_index (`Class_type ct) + + method scan_for_index_in_class = function + | Class_attribute _ -> self#do_index `Class_att + | Class_method _ -> self#do_index `Method + | Class_comment _ -> () + + + (** Generate the Texinfo file from a module list, + in the {!Odoc_info.Args.out_file} file. *) + method generate module_list = + Hashtbl.clear node_tbl ; + let filename = + if !Args.out_file = Odoc_messages.default_out_file + then "ocamldoc.texi" + else !Args.out_file in + if !Args.with_index + then List.iter self#scan_for_index + (List.map (fun m -> `Module m) module_list) ; + try + let chanout = open_out + (Filename.concat !Args.target_dir filename) in + if !Args.with_header + then self#generate_texi_header chanout filename module_list ; + List.iter + (self#generate_for_module chanout) + module_list ; + if !Args.with_trailer + then self#generate_texi_trailer chanout ; + close_out chanout + with + | Failure s + | Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors + end diff --git a/ocamldoc/odoc_text.ml b/ocamldoc/odoc_text.ml new file mode 100644 index 0000000..2c94943 --- /dev/null +++ b/ocamldoc/odoc_text.ml @@ -0,0 +1,153 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_text.ml,v 1.6 2006-01-04 16:55:50 doligez Exp $ *) + +exception Text_syntax of int * int * string (* line, char, string *) + +open Odoc_types + +module Texter = + struct + (* builds a text structure from a string. *) + let text_of_string s = + let lexbuf = Lexing.from_string s in + try + Odoc_text_lexer.init (); + Odoc_text_parser.main Odoc_text_lexer.main lexbuf + with + _ -> + raise (Text_syntax (!Odoc_text_lexer.line_number, + !Odoc_text_lexer.char_number, + s) + ) + + let count s c = + let count = ref 0 in + for i = 0 to String.length s - 1 do + if s.[i] = c then incr count + done; + !count + + let escape_n s c n = + let remain = ref n in + let len = String.length s in + let b = Buffer.create (len + n) in + for i = 0 to len - 1 do + if s.[i] = c && !remain > 0 then + ( + Printf.bprintf b "\\%c" c; + decr remain + ) + else + Buffer.add_char b s.[i] + done; + Buffer.contents b + + let escape_code s = + let open_brackets = count s '[' in + let close_brackets = count s ']' in + if open_brackets > close_brackets then + escape_n s '[' (open_brackets - close_brackets) + else + if close_brackets > open_brackets then + escape_n s ']' (close_brackets - open_brackets) + else + s + + let escape_raw s = + let len = String.length s in + let b = Buffer.create len in + for i = 0 to len - 1 do + match s.[i] with + '[' | ']' | '{' | '}' -> + Printf.bprintf b "\\%c" s.[i] + | c -> + Buffer.add_char b c + done; + Buffer.contents b + + let p = Printf.bprintf + + let rec p_text b t = + List.iter (p_text_element b) t + + and p_list b l = + List.iter + (fun t -> p b "{- " ; p_text b t ; p b "}\n") + l + + and p_text_element b = function + | Raw s -> p b "%s" (escape_raw s) + | Code s -> p b "[%s]" (escape_code s) + | CodePre s -> p b "{[%s]}" s + | Verbatim s -> p b "{v %s v}" s + | Bold t -> p b "{b " ; p_text b t ; p b "}" + | Italic t -> p b "{i " ; p_text b t ; p b "}" + | Emphasize t -> p b "{e " ; p_text b t ; p b "}" + | Center t -> p b "{C " ; p_text b t ; p b "}" + | Left t -> p b "{L " ; p_text b t ; p b "}" + | Right t -> p b "{R " ; p_text b t ; p b "}" + | List l -> p b "{ul\n"; p_list b l; p b "}" + | Enum l -> p b "{ol\n"; p_list b l; p b "}" + | Newline -> p b "\n" + | Block t -> p_text b t + | Title (n, l_opt, t) -> + p b "{%d%s " + n + (match l_opt with + None -> "" + | Some s -> ":"^s + ); + p_text b t ; + p b "}" + | Latex s -> p b "{%% %s%%}" s + | Link (s,t) -> + p b "{{:%s}" s; + p_text b t ; + p b "}" + | Ref (s,None) -> + p b "{!%s}" s + | Ref (s, Some k) -> + ( + let sk = match k with + RK_module -> "module" + | RK_module_type -> "modtype" + | RK_class -> "class" + | RK_class_type -> "classtype" + | RK_value -> "val" + | RK_type -> "type" + | RK_exception -> "exception" + | RK_attribute -> "attribute" + | RK_method -> "method" + | RK_section _ -> "section" + in + p b "{!%s:%s}" sk s + ) + | Superscript t -> p b "{^" ; p_text b t ; p b "}" + | Subscript t -> p b "{_" ; p_text b t ; p b "}" + | Module_list l -> + p b "{!modules:"; + List.iter (fun s -> p b " %s" s) l; + p b "}" + | Index_list -> + p b "{!indexlist}" + | Custom (s,t) -> + p b "{%s " s; + p_text b t; + p b "}" + + let string_of_text s = + let b = Buffer.create 256 in + p_text b s; + Buffer.contents b + + end diff --git a/ocamldoc/odoc_text.mli b/ocamldoc/odoc_text.mli new file mode 100644 index 0000000..1b11d5d --- /dev/null +++ b/ocamldoc/odoc_text.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_text.mli,v 1.3 2003-11-24 21:20:51 guesdon Exp $ *) + +(** A module with a function to parse strings to obtain a [Odoc_types.text] value. *) + +(** Syntax error in a text. *) +exception Text_syntax of int * int * string (* line, char, string *) + +(** Transformation of strings to text structures. *) +module Texter : + sig + val text_of_string : string -> Odoc_types.text + val string_of_text : Odoc_types.text -> string + end diff --git a/ocamldoc/odoc_text_lexer.mll b/ocamldoc/odoc_text_lexer.mll new file mode 100644 index 0000000..aa3bf28 --- /dev/null +++ b/ocamldoc/odoc_text_lexer.mll @@ -0,0 +1,777 @@ +{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_text_lexer.mll,v 1.9 2006-01-04 16:55:50 doligez Exp $ *) + +(** The lexer for string to build text structures. *) + +open Lexing +open Odoc_text_parser + +let line_number = ref 0 +let char_number = ref 0 + +let string_buffer = Buffer.create 32 + +(** Fonction de remise à zéro de la chaine de caractères tampon *) +let reset_string_buffer () = Buffer.reset string_buffer + +(** Fonction d'ajout d'un caractère dans la chaine de caractères tampon *) +let ajout_char_string = Buffer.add_char string_buffer + +(** Add a string to the buffer. *) +let ajout_string = Buffer.add_string string_buffer + +let lecture_string () = Buffer.contents string_buffer + + +(** the variable which will contain the description string. + Is initialized when we encounter the start of a special comment. *) + +let description = ref "" + +let blank = "[ \013\009\012]" + + +let print_DEBUG s = print_string s; print_newline () + +(** this flag indicates whether we're in a string between begin_code and end_code tokens, to + remember the number of open '[' and handle ']' correctly. *) +let open_brackets = ref 0 + +(** this flag indicates if we're in verbatim mode or not, to handle any special expression + like a string when we're in verbatim mode.*) +let verb_mode = ref false + +(** this flag indicates if we're in latex mode or not, to handle any special expression + like a string when we're in latex mode.*) +let latex_mode = ref false + +(** this flag indicates if we're in shortcut list mode or not, to handle end_shortcut_list correctly.*) +let shortcut_list_mode = ref false + +(** this flag indicates if we're in an element reference. *) +let ele_ref_mode = ref false + +(** this flag indicates if we're in a preformatted code string. *) +let code_pre_mode = ref false + +let init () = + open_brackets := 0; + verb_mode := false; + latex_mode := false; + shortcut_list_mode := false; + ele_ref_mode := false ; + code_pre_mode := false ; + line_number := 0 ; + char_number := 0 + +let incr_cpts lexbuf = + let s = Lexing.lexeme lexbuf in + let l = Str.split_delim (Str.regexp_string "\n") s in + match List.rev l with + [] -> () (* should not occur *) + | [s2] -> (* no newline *) + char_number := !char_number + (String.length s2) + | s2 :: _ -> + line_number := !line_number + ((List.length l) - 1) ; + char_number := String.length s2 + +} + +(** html marks, to use as alternative possible special strings *) + +let html_bold = "<"('b'|'B')">" +let html_end_bold = "</"('b'|'B')">" +let html_italic = "<"('i'|'I')">" +let html_end_italic = "</"('i'|'I')">" +let html_title = "<"('h'|'H')(['0'-'9'])+">" +let html_end_title = "</"('h'|'H')(['0'-'9'])+">" +let html_list = "<"('u'|'U')('l'|'L')">" +let html_end_list = "</"('u'|'U')('l'|'L')">" +let html_enum = "<"('o'|'O')('l'|'L')">" +let html_end_enum = "</"('o'|'O')('l'|'L')">" +let html_item = "<"('l'|'L')('i'|'I')">" +let html_end_item = "</"('l'|'L')('i'|'I')">" +let html_code = "<"('c'|'C')('o'|'O')('d'|'D')('e'|'E')">" +let html_end_code = "</"('c'|'C')('o'|'O')('d'|'D')('e'|'E')">" +let html_center = "<"('c'|'C')('e'|'E')('n'|'N')('t'|'T')('e'|'E')('r'|'R')">" +let html_end_center = "</"('c'|'C')('e'|'E')('n'|'N')('t'|'T')('e'|'E')('r'|'R')">" +let html_left = "<"('l'|'L')('e'|'E')('f'|'F')('t'|'T')">" +let html_end_left = "</"('l'|'L')('e'|'E')('f'|'F')('t'|'T')">" +let html_right = "<"('r'|'R')('i'|'I')('g'|'G')('h'|'H')('t'|'T')">" +let html_end_right = "</"('r'|'R')('i'|'I')('g'|'G')('h'|'H')('t'|'T')">" + + +let blank = [' ' '\013' '\009' '\012'] +let blank_nl = [' ' '\013' '\009' '\012' '\010'] +let label = ['a'-'z']+['a'-'z' 'A'-'Z' '0'-'9' '_']* + +(** special strings *) + +let end = "}" + | html_end_bold + | html_end_italic + | html_end_title + | html_end_list + | html_end_enum + | html_end_item + | html_end_center +let begin_title = + ("{" ['0'-'9']+(":"label)? blank_nl) + | html_title + +let begin_bold = "{b"blank_nl | html_bold +let begin_emp = "{e"blank_nl +let begin_center = "{C"blank_nl | html_center +let begin_left = "{L"blank_nl +let begin_right = "{R"blank_nl +let begin_italic = "{i"blank_nl | html_italic +let begin_list = "{ul"blank_nl? | html_list +let begin_enum = "{ol"blank_nl? | html_enum +let begin_item = "{li"blank_nl | "{- " | html_item +let begin_link = "{{:" +let begin_latex = "{%"blank_nl +let end_latex = "%}" +let begin_code = "[" | html_code +let end_code = "]" | html_end_code +let begin_code_pre = "{[" +let end_code_pre = "]}" +let begin_verb = "{v"blank_nl +let end_verb = blank_nl"v}" + +let begin_ele_ref = "{!"blank_nl | "{!" +let begin_val_ref = "{!val:"blank_nl | "{!val:" +let begin_typ_ref = "{!type:"blank_nl | "{!type:" +let begin_exc_ref = "{!exception:"blank_nl | "{!exception:" +let begin_mod_ref = "{!module:"blank_nl | "{!module:" +let begin_modt_ref = "{!modtype:"blank_nl | "{!modtype:" +let begin_cla_ref = "{!class:"blank_nl | "{!class:" +let begin_clt_ref = "{!classtype:"blank_nl | "{!classtype:" +let begin_att_ref = "{!attribute:"blank_nl | "{!attribute:" +let begin_met_ref = "{!method:"blank_nl | "{!method:" +let begin_sec_ref = "{!section:"blank_nl | "{!section:" +let begin_mod_list_ref = "{!modules:"blank_nl | "{!modules:" +let index_list = "{!indexlist}" +let begin_custom = "{"['a'-'z''A'-'Z']['a'-'z''A'-'Z''0'-'9']* +let begin_superscript = "{^"blank_nl | "{^" +let begin_subscript = "{_"blank_nl | "{_" + +let shortcut_list_item = '\n'blank*"- " +let shortcut_enum_item = '\n'blank*"+ " +let end_shortcut_list = '\n'(blank*'\n')+ + +rule main = parse +| "\\{" +| "\\}" +| "\\[" +| "\\]" + { + incr_cpts lexbuf ; + let s = Lexing.lexeme lexbuf in + Char (String.sub s 1 1) + } + +| end + { + print_DEBUG "end"; + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) then + Char (Lexing.lexeme lexbuf) + else + let _ = + if !ele_ref_mode then + ele_ref_mode := false + in + END + } +| begin_title + { + print_DEBUG "begin_title"; + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + let s = Lexing.lexeme lexbuf in + try + (* chech if the "{..." or html_title mark was used. *) + if s.[0] = '<' then + let (n, l) = (2, (String.length s - 3)) in + let s2 = String.sub s n l in + Title (int_of_string s2, None) + else + let (n, l) = (1, (String.length s - 2)) in + let s2 = String.sub s n l in + try + let i = String.index s2 ':' in + let s_n = String.sub s2 0 i in + let s_label = String.sub s2 (i+1) (l-i-1) in + Title (int_of_string s_n, Some s_label) + with + Not_found -> + Title (int_of_string s2, None) + with + _ -> + Title (1, None) + } +| begin_bold + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + BOLD + } +| begin_italic + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ITALIC + } +| begin_link + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + LINK + } +| begin_emp + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + EMP + } +| begin_superscript + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + SUPERSCRIPT + } +| begin_subscript + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + SUBSCRIPT + } +| begin_center + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + CENTER + } +| begin_left + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + LEFT + } +| begin_right + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode + or (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + RIGHT + } +| begin_list + { + print_DEBUG "LIST"; + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + LIST + } +| begin_enum + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ENUM + } +| begin_item + { + print_DEBUG "ITEM"; + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ITEM + } +| begin_latex + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ( + latex_mode := true; + LATEX + ) + } +| end_latex + { + incr_cpts lexbuf ; + if !verb_mode or (!open_brackets >= 1) or !code_pre_mode or + !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ( + latex_mode := false; + END_LATEX + ) + } +| begin_code end_code + { + incr_cpts lexbuf ; + Char (Lexing.lexeme lexbuf) + } + +| begin_code + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + if !open_brackets <= 0 then + ( + open_brackets := 1; + CODE + ) + else + ( + incr open_brackets; + Char (Lexing.lexeme lexbuf) + ) + } +| end_code + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + if !open_brackets > 1 then + ( + decr open_brackets; + Char "]" + ) + else + ( + open_brackets := 0; + END_CODE + ) + } + +| begin_code_pre end_code_pre + { + incr_cpts lexbuf ; + Char (Lexing.lexeme lexbuf) + } + +| begin_code_pre + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ( + code_pre_mode := true; + CODE_PRE + ) + } +| end_code_pre + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + if !open_brackets >= 1 then + ( + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + lexbuf.Lexing.lex_curr_p <- + { lexbuf.Lexing.lex_curr_p with + pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - 1 + } ; + decr char_number ; + if !open_brackets > 1 then + ( + decr open_brackets; + Char "]" + ) + else + ( + open_brackets := 0; + END_CODE + ) + ) + else + if !code_pre_mode then + ( + code_pre_mode := false; + END_CODE_PRE + ) + else + Char (Lexing.lexeme lexbuf) + } + +| begin_ele_ref end + { + incr_cpts lexbuf ; + Char (Lexing.lexeme lexbuf) + } + +| begin_ele_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + ELE_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + + +| begin_val_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + VAL_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_typ_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + TYP_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_exc_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + EXC_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_mod_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + MOD_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_modt_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + MODT_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_cla_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + CLA_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_clt_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + CLT_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_att_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + ATT_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_met_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + MET_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_sec_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + SEC_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| begin_mod_list_ref + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + ( + ele_ref_mode := true; + MOD_LIST_REF + ) + else + ( + Char (Lexing.lexeme lexbuf) + ) + } + +| index_list + { + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or !open_brackets >= 1 then + Char (Lexing.lexeme lexbuf) + else + if not !ele_ref_mode then + INDEX_LIST + else + Char (Lexing.lexeme lexbuf) + } + +| begin_verb + { + incr_cpts lexbuf ; + if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ( + verb_mode := true; + VERB + ) + } +| end_verb + { + incr_cpts lexbuf ; + if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ( + verb_mode := false; + END_VERB + ) + } + +| shortcut_list_item + { + incr_cpts lexbuf ; + if !shortcut_list_mode then + ( + SHORTCUT_LIST_ITEM + ) + else + ( + shortcut_list_mode := true; + BEGIN_SHORTCUT_LIST_ITEM + ) + } + +| shortcut_enum_item + { + incr_cpts lexbuf ; + if !shortcut_list_mode then + SHORTCUT_ENUM_ITEM + else + ( + shortcut_list_mode := true; + BEGIN_SHORTCUT_ENUM_ITEM + ) + } +| end_shortcut_list + { + incr_cpts lexbuf ; + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + lexbuf.Lexing.lex_curr_p <- + { lexbuf.Lexing.lex_curr_p with + pos_cnum = lexbuf.Lexing.lex_curr_p.pos_cnum - 1 ; + } ; + decr line_number ; + if !shortcut_list_mode then + ( + shortcut_list_mode := false; + (* go back one char to re-use the last '\n', so we can + restart another shortcut-list with a single blank line, + and not two.*) + END_SHORTCUT_LIST + ) + else + if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode or !verb_mode then + Char (Lexing.lexeme lexbuf) + else + BLANK_LINE + } + +| eof { EOF } + +| begin_custom + { + print_DEBUG "begin_custom"; + incr_cpts lexbuf ; + if !verb_mode or !latex_mode or !code_pre_mode or + (!open_brackets >= 1) or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + let s = Lexing.lexeme lexbuf in + let tag = Odoc_misc.no_blanks s in + CUSTOM tag + } + +| "{" + { + incr_cpts lexbuf ; + if !latex_mode or (!open_brackets >= 1) or !code_pre_mode or !ele_ref_mode then + Char (Lexing.lexeme lexbuf) + else + ERROR + } +| _ + { + incr_cpts lexbuf ; + Char (Lexing.lexeme lexbuf) + } diff --git a/ocamldoc/odoc_text_parser.mly b/ocamldoc/odoc_text_parser.mly new file mode 100644 index 0000000..eef1fda --- /dev/null +++ b/ocamldoc/odoc_text_parser.mly @@ -0,0 +1,225 @@ +%{ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_text_parser.mly,v 1.5 2006-01-04 16:55:50 doligez Exp $ *) + +open Odoc_types + +let identchar = + "[A-Z a-z_\192-\214\216-\246\248-\255'0-9]" +let blank = "[ \010\013\009\012]" + +let remove_beginning_blanks s = + Str.global_replace (Str.regexp ("^"^blank^"+")) "" s + +let remove_trailing_blanks s = + Str.global_replace (Str.regexp (blank^"+$")) "" s + +let print_DEBUG s = print_string s; print_newline () +%} + +%token ERROR +%token END +%token <int * string option> Title +%token BOLD +%token EMP +%token CENTER +%token LEFT +%token RIGHT +%token ITALIC +%token <string> CUSTOM +%token LIST +%token ENUM +%token ITEM +%token LINK +%token CODE +%token END_CODE +%token CODE_PRE +%token END_CODE_PRE +%token VERB +%token END_VERB +%token LATEX +%token END_LATEX + +%token ELE_REF +%token VAL_REF +%token TYP_REF +%token EXC_REF +%token MOD_REF +%token MODT_REF +%token CLA_REF +%token CLT_REF +%token ATT_REF +%token MET_REF +%token SEC_REF +%token MOD_LIST_REF +%token INDEX_LIST + +%token SUPERSCRIPT +%token SUBSCRIPT + +%token BEGIN_SHORTCUT_LIST_ITEM +%token BEGIN_SHORTCUT_ENUM_ITEM +%token SHORTCUT_LIST_ITEM +%token SHORTCUT_ENUM_ITEM +%token END_SHORTCUT_LIST + +%token BLANK_LINE + +%token EOF +%token <string> Char + +/* Start Symbols */ +%start main +%type <Odoc_types.text> main + +%% +main: + text EOF { $1 } +| EOF { [Raw ""] } +; + +text: + text_element_list { $1 } +; + +text_element_list: + text_element { [ $1 ] } +| text_element text_element_list { $1 :: $2 } +; + +text_element: + Title text END { let n, l_opt = $1 in Title (n, l_opt, $2) } +| BOLD text END { Bold $2 } +| ITALIC text END { Italic $2 } +| CUSTOM text END { Custom ($1, $2) } +| EMP text END { Emphasize $2 } +| SUPERSCRIPT text END { Superscript $2 } +| SUBSCRIPT text END { Subscript $2 } +| CENTER text END { Center $2 } +| LEFT text END { Left $2 } +| RIGHT text END { Right $2 } +| LIST list END { List $2 } +| ENUM list END { Enum $2 } +| CODE string END_CODE { Code $2 } +| CODE_PRE string END_CODE_PRE { CodePre $2 } +| ELE_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, None) + } +| VAL_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_value) + } +| TYP_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_type) + } +| EXC_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_exception) + } +| MOD_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_module) + } +| MODT_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_module_type) + } +| CLA_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_class) + } +| CLT_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_class_type) + } +| ATT_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_attribute) + } +| MET_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some RK_method) + } +| SEC_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + Ref (s3, Some (RK_section [])) + } +| MOD_LIST_REF string END { + let s2 = remove_beginning_blanks $2 in + let s3 = remove_trailing_blanks s2 in + let l = Odoc_misc.split_with_blanks s3 in + Module_list l + } +| INDEX_LIST { Index_list } +| VERB string END_VERB { Verbatim $2 } +| LATEX string END_LATEX { Latex $2 } +| LINK string END text END { Link ($2, $4) } +| BLANK_LINE { Newline } +| BEGIN_SHORTCUT_LIST_ITEM shortcut_list END_SHORTCUT_LIST { List $2 } +| BEGIN_SHORTCUT_LIST_ITEM shortcut_list EOF { List $2 } +| BEGIN_SHORTCUT_ENUM_ITEM shortcut_enum END_SHORTCUT_LIST { Enum $2 } +| BEGIN_SHORTCUT_ENUM_ITEM shortcut_enum EOF { Enum $2 } +| string { Raw $1 } +; + +list: +| string { [] (* A VOIR : un test pour voir qu'il n'y a que des blancs *) } +| string list { $2 } +| list string { $1 } +| item { [ $1 ] } +| item list { $1 :: $2 } + +; + +item: + ITEM text END { $2 } +; + +shortcut_list: + text shortcut_list2 { $1 :: $2 } +| text { [ $1 ] } +; + +shortcut_list2: +| SHORTCUT_LIST_ITEM shortcut_list { $2 } +; + +shortcut_enum: + text shortcut_enum2 { $1 :: $2 } +| text { [ $1 ] } +; + +shortcut_enum2: +| SHORTCUT_ENUM_ITEM shortcut_enum { $2 } +; + + +string: + Char { $1 } +| Char string { $1^$2 } +; + +%% diff --git a/ocamldoc/odoc_to_text.ml b/ocamldoc/odoc_to_text.ml new file mode 100644 index 0000000..91e1bcf --- /dev/null +++ b/ocamldoc/odoc_to_text.ml @@ -0,0 +1,574 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_to_text.ml,v 1.17 2008-07-23 08:55:36 guesdon Exp $ *) + +(** Text generation. + + This module contains the class [to_text] with methods used to transform + information about elements to a [text] structure.*) + +open Odoc_info +open Exception +open Type +open Value +open Module +open Class +open Parameter + +(** A class used to get a [text] for info structures. *) +class virtual info = + object (self) + (** The list of pairs [(tag, f)] where [f] is a function taking + the [text] associated to [tag] and returning a [text]. + Add a pair here to handle a tag.*) + val mutable tag_functions = ([] : (string * (Odoc_info.text -> Odoc_info.text)) list) + + (** @return [etxt] value for an authors list. *) + method text_of_author_list l = + match l with + [] -> + [] + | _ -> + [ Bold [Raw (Odoc_messages.authors^": ")] ; + Raw (String.concat ", " l) ; + Newline + ] + + (** @return [text] value for the given optional version information.*) + method text_of_version_opt v_opt = + match v_opt with + None -> [] + | Some v -> [ Bold [Raw (Odoc_messages.version^": ")] ; + Raw v ; + Newline + ] + + (** @return [text] value for the given optional since information.*) + method text_of_since_opt s_opt = + match s_opt with + None -> [] + | Some s -> [ Bold [Raw (Odoc_messages.since^": ")] ; + Raw s ; + Newline + ] + + (** @return [text] value for the given list of raised exceptions.*) + method text_of_raised_exceptions l = + match l with + [] -> [] + | (s, t) :: [] -> + [ Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; + Code s ; + Raw " " + ] + @ t + @ [ Newline ] + | _ -> + [ Bold [ Raw Odoc_messages.raises ] ; + Raw " " ; + List + (List.map + (fun (ex, desc) ->(Code ex) :: (Raw " ") :: desc ) + l + ) ; + Newline + ] + + (** Return [text] value for the given "see also" reference. *) + method text_of_see (see_ref, t) = + let t_ref = + match see_ref with + Odoc_info.See_url s -> [ Odoc_info.Link (s, t) ] + | Odoc_info.See_file s -> (Odoc_info.Code s) :: (Odoc_info.Raw " ") :: t + | Odoc_info.See_doc s -> (Odoc_info.Italic [Odoc_info.Raw s]) :: (Odoc_info.Raw " ") :: t + in + t_ref + + (** Return [text] value for the given list of "see also" references.*) + method text_of_sees l = + match l with + [] -> [] + | see :: [] -> + (Bold [ Raw Odoc_messages.see_also ]) :: + (Raw " ") :: + (self#text_of_see see) @ [ Newline ] + | _ -> + (Bold [ Raw Odoc_messages.see_also ]) :: + [ List + (List.map + (fun see -> self#text_of_see see) + l + ); + Newline + ] + + (** @return [text] value for the given optional return information.*) + method text_of_return_opt return_opt = + match return_opt with + None -> [] + | Some t -> (Bold [Raw (Odoc_messages.returns^" ")]) :: t @ [ Newline ] + + (** Return a [text] for the given list of custom tagged texts. *) + method text_of_custom l = + List.fold_left + (fun acc -> fun (tag, text) -> + try + let f = List.assoc tag tag_functions in + match acc with + [] -> f text + | _ -> acc @ (Newline :: (f text)) + with + Not_found -> + Odoc_info.warning (Odoc_messages.tag_not_handled tag) ; + acc + ) + [] + l + + (** @return [text] value for a description, except for the i_params field. *) + method text_of_info ?(block=true) info_opt = + match info_opt with + None -> + [] + | Some info -> + let t = + (match info.i_deprecated with + None -> [] + | Some t -> ( Italic [Raw (Odoc_messages.deprecated^" ")] ) :: t + ) @ + (match info.i_desc with + None -> [] + | Some t when t = [Odoc_info.Raw ""] -> [] + | Some t -> t @ [ Newline ] + ) @ + (self#text_of_author_list info.i_authors) @ + (self#text_of_version_opt info.i_version) @ + (self#text_of_since_opt info.i_since) @ + (self#text_of_raised_exceptions info.i_raised_exceptions) @ + (self#text_of_return_opt info.i_return_value) @ + (self#text_of_sees info.i_sees) @ + (self#text_of_custom info.i_custom) + in + if block then + [Block t] + else + t + end + +(** This class defines methods to generate a [text] structure from elements. *) +class virtual to_text = + object (self) + inherit info + + method virtual label : ?no_: bool -> string -> string + + (** Take a string and return the string where fully qualified idents + have been replaced by idents relative to the given module name. + Also remove the "hidden modules".*) + method relative_idents m_name s = + let f str_t = + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + Odoc_info.apply_if_equal Odoc_info.use_hidden_modules match_s rel + in + let s2 = Str.global_substitute + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([a-z][a-zA-Z_'0-9]*\\)") + f + s + in + s2 + + (** Take a string and return the string where fully qualified idents + have been replaced by idents relative to the given module name. + Also remove the "hidden modules".*) + method relative_module_idents m_name s = + let f str_t = + let match_s = Str.matched_string str_t in + let rel = Name.get_relative m_name match_s in + Odoc_info.apply_if_equal Odoc_info.use_hidden_modules match_s rel + in + let s2 = Str.global_substitute + (Str.regexp "\\([A-Z]\\([a-zA-Z_'0-9]\\)*\\.\\)+\\([A-Z][a-zA-Z_'0-9]*\\)") + f + s + in + s2 + + (** Get a string for a [Types.class_type] where all idents are relative. *) + method normal_class_type m_name t = + self#relative_idents m_name (Odoc_info.string_of_class_type t) + + (** Get a string for a [Types.module_type] where all idents are relative. *) + method normal_module_type ?code m_name t = + self#relative_module_idents m_name (Odoc_info.string_of_module_type ?code t) + + (** Get a string for a type where all idents are relative. *) + method normal_type m_name t = + self#relative_idents m_name (Odoc_info.string_of_type_expr t) + + (** Get a string for a list of types where all idents are relative. *) + method normal_type_list ?par m_name sep t = + self#relative_idents m_name (Odoc_info.string_of_type_list ?par sep t) + + (** Get a string for a list of class or class type type parameters + where all idents are relative. *) + method normal_class_type_param_list m_name t = + self#relative_idents m_name (Odoc_info.string_of_class_type_param_list t) + + (** Get a string for the parameters of a class (with arrows) where all idents are relative. *) + method normal_class_params m_name c = + let s = Odoc_info.string_of_class_params c in + self#relative_idents m_name + (Odoc_info.remove_ending_newline s) + + (** @return [text] value to represent a [Types.type_expr].*) + method text_of_type_expr module_name t = + let t = List.flatten + (List.map + (fun s -> [Code s ; Newline ]) + (Str.split (Str.regexp "\n") + (self#normal_type module_name t)) + ) + in + t + + (** Return [text] value for a given short [Types.type_expr].*) + method text_of_short_type_expr module_name t = + [ Code (self#normal_type module_name t) ] + + (** Return [text] value or the given list of [Types.type_expr], with + the given separator. *) + method text_of_type_expr_list module_name sep l = + [ Code (self#normal_type_list module_name sep l) ] + + (** Return [text] value or the given list of [Types.type_expr], + as type parameters of a class of class type. *) + method text_of_class_type_param_expr_list module_name l = + [ Code (self#normal_class_type_param_list module_name l) ] + + (** @return [text] value to represent parameters of a class (with arraows).*) + method text_of_class_params module_name c = + let t = Odoc_info.text_concat + [Newline] + (List.map + (fun s -> [Code s]) + (Str.split (Str.regexp "\n") + (self#normal_class_params module_name c)) + ) + in + t + + (** @return [text] value to represent a [Types.module_type]. *) + method text_of_module_type t = + let s = String.concat "\n" + (Str.split (Str.regexp "\n") (Odoc_info.string_of_module_type t)) + in + [ Code s ] + + (** @return [text] value for a value. *) + method text_of_value v = + let name = v.val_name in + let s_name = Name.simple name in + let s = + Format.fprintf Format.str_formatter "@[<hov 2>val %s :@ %s" + s_name + (self#normal_type (Name.father v.val_name) v.val_type); + Format.flush_str_formatter () + in + [ CodePre s ] @ + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info v.val_info) + + (** @return [text] value for a class attribute. *) + method text_of_attribute a = + let s_name = Name.simple a.att_value.val_name in + let mod_name = Name.father a.att_value.val_name in + let s = + Format.fprintf Format.str_formatter "@[<hov 2>val %s%s%s :@ %s" + (if a.att_virtual then "virtual " else "") + (if a.att_mutable then "mutable " else "") + s_name + (self#normal_type mod_name a.att_value.val_type); + Format.flush_str_formatter () + in + (CodePre s) :: + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info a.att_value.val_info) + + (** @return [text] value for a class method. *) + method text_of_method m = + let s_name = Name.simple m.met_value.val_name in + let mod_name = Name.father m.met_value.val_name in + let s = + Format.fprintf Format.str_formatter "@[<hov 2>method %s%s%s :@ %s" + (if m.met_private then "private " else "") + (if m.met_virtual then "virtual " else "") + s_name + (self#normal_type mod_name m.met_value.val_type); + Format.flush_str_formatter () + in + (CodePre s) :: + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info m.met_value.val_info) + + + (** @return [text] value for an exception. *) + method text_of_exception e = + let s_name = Name.simple e.ex_name in + Format.fprintf Format.str_formatter "@[<hov 2>exception %s" s_name ; + (match e.ex_args with + [] -> () + | _ -> + Format.fprintf Format.str_formatter "@ of " + ); + let s = self#normal_type_list + ~par: false (Name.father e.ex_name) " * " e.ex_args + in + let s2 = + Format.fprintf Format.str_formatter "%s" s ; + (match e.ex_alias with + None -> () + | Some ea -> + Format.fprintf Format.str_formatter " = %s" + ( + match ea.ea_ex with + None -> ea.ea_name + | Some e -> e.ex_name + ) + ); + Format.flush_str_formatter () + in + [ CodePre s2 ] @ + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ + (self#text_of_info e.ex_info) + + (** Return [text] value for the description of a function parameter. *) + method text_of_parameter_description p = + match Parameter.names p with + [] -> [] + | name :: [] -> + ( + (* Only one name, no need for label for the description. *) + match Parameter.desc_by_name p name with + None -> [] + | Some t -> t + ) + | l -> + (* A list of names, we display those with a description. *) + let l2 = List.filter (fun n -> (Parameter.desc_by_name p n) <> None) l in + match l2 with + [] -> [] + | _ -> + [List + (List.map + (fun n -> + match Parameter.desc_by_name p n with + None -> [] (* should not occur *) + | Some t -> [Code (n^" ") ; Raw ": "] @ t + ) + l2 + ) + ] + + + (** Return [text] value for a list of parameters. *) + method text_of_parameter_list m_name l = + match l with + [] -> + [] + | _ -> + [ Bold [Raw Odoc_messages.parameters] ; + Raw ":" ; + List + (List.map + (fun p -> + (match Parameter.complete_name p with + "" -> Code "?" + | s -> Code s + ) :: + [Code " : "] @ + (self#text_of_short_type_expr m_name (Parameter.typ p)) @ + [Newline] @ + (self#text_of_parameter_description p) + ) + l + ) + ] + + (** Return [text] value for a list of module parameters. *) + method text_of_module_parameter_list l = + match l with + [] -> + [] + | _ -> + [ Newline ; + Bold [Raw Odoc_messages.parameters] ; + Raw ":" ; + List + (List.map + (fun (p, desc_opt) -> + [Code (p.mp_name^" : ")] @ + (self#text_of_module_type p.mp_type) @ + (match desc_opt with + None -> [] + | Some t -> (Raw " ") :: t) + ) + l + ) + ] + +(**/**) + + (** Return [text] value for the given [class_kind].*) + method text_of_class_kind father ckind = + match ckind with + Class_structure _ -> + [Code Odoc_messages.object_end] + + | Class_apply capp -> + [Code + ( + ( + match capp.capp_class with + None -> capp.capp_name + | Some cl -> cl.cl_name + )^ + " "^ + (String.concat " " + (List.map + (fun s -> "("^s^")") + capp.capp_params_code)) + ) + ] + + | Class_constr cco -> + ( + match cco.cco_type_parameters with + [] -> [] + | l -> + (Code "["):: + (self#text_of_type_expr_list father ", " l)@ + [Code "] "] + )@ + [Code ( + match cco.cco_class with + None -> cco.cco_name + | Some (Cl cl) -> Name.get_relative father cl.cl_name + | Some (Cltype (clt,_)) -> Name.get_relative father clt.clt_name + ) + ] + + | Class_constraint (ck, ctk) -> + [Code "( "] @ + (self#text_of_class_kind father ck) @ + [Code " : "] @ + (self#text_of_class_type_kind father ctk) @ + [Code " )"] + + + (** Return [text] value for the given [class_type_kind].*) + method text_of_class_type_kind father ctkind = + match ctkind with + Class_type cta -> + ( + match cta.cta_type_parameters with + [] -> [] + | l -> + (Code "[") :: + (self#text_of_class_type_param_expr_list father l) @ + [Code "] "] + ) @ + ( + match cta.cta_class with + None -> [ Code cta.cta_name ] + | Some (Cltype (clt, _)) -> + let rel = Name.get_relative father clt.clt_name in + [Code rel] + | Some (Cl cl) -> + let rel = Name.get_relative father cl.cl_name in + [Code rel] + ) + | Class_signature _ -> + [Code Odoc_messages.object_end] + + (** Return [text] value for a [module_kind]. *) + method text_of_module_kind ?(with_def_syntax=true) k = + match k with + Module_alias m_alias -> + (match m_alias.ma_module with + None -> + [Code ((if with_def_syntax then " = " else "")^m_alias.ma_name)] + | Some (Mod m) -> + [Code ((if with_def_syntax then " = " else "")^m.m_name)] + | Some (Modtype mt) -> + [Code ((if with_def_syntax then " = " else "")^mt.mt_name)] + ) + | Module_apply (k1, k2) -> + (if with_def_syntax then [Code " = "] else []) @ + (self#text_of_module_kind ~with_def_syntax: false k1) @ + [Code " ( "] @ + (self#text_of_module_kind ~with_def_syntax: false k2) @ + [Code " ) "] + + | Module_with (tk, code) -> + (if with_def_syntax then [Code " : "] else []) @ + (self#text_of_module_type_kind ~with_def_syntax: false tk) @ + [Code code] + + | Module_constraint (k, tk) -> + (if with_def_syntax then [Code " : "] else []) @ + [Code "( "] @ + (self#text_of_module_kind ~with_def_syntax: false k) @ + [Code " : "] @ + (self#text_of_module_type_kind ~with_def_syntax: false tk) @ + [Code " )"] + + | Module_struct _ -> + [Code ((if with_def_syntax then " : " else "")^ + Odoc_messages.struct_end^" ")] + + | Module_functor (p, k) -> + (if with_def_syntax then [Code " : "] else []) @ + [Code "functor ... "] @ + [Code " -> "] @ + (self#text_of_module_kind ~with_def_syntax: false k) + + (** Return html code for a [module_type_kind].*) + method text_of_module_type_kind ?(with_def_syntax=true) tk = + match tk with + | Module_type_struct _ -> + [Code ((if with_def_syntax then " = " else "")^Odoc_messages.sig_end)] + + | Module_type_functor (p, k) -> + let t1 = + [Code ("("^p.mp_name^" : ")] @ + (self#text_of_module_type_kind p.mp_kind) @ + [Code ") -> "] + in + let t2 = self#text_of_module_type_kind ~with_def_syntax: false k in + (if with_def_syntax then [Code " = "] else []) @ t1 @ t2 + + | Module_type_with (tk2, code) -> + let t = self#text_of_module_type_kind ~with_def_syntax: false tk2 in + (if with_def_syntax then [Code " = "] else []) @ + t @ [Code code] + + | Module_type_alias mt_alias -> + [Code ((if with_def_syntax then " = " else "")^ + (match mt_alias.mta_module with + None -> mt_alias.mta_name + | Some mt -> mt.mt_name)) + ] + + + end diff --git a/ocamldoc/odoc_type.ml b/ocamldoc/odoc_type.ml new file mode 100644 index 0000000..662182f --- /dev/null +++ b/ocamldoc/odoc_type.ml @@ -0,0 +1,56 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_type.ml,v 1.7 2008-05-21 05:56:39 guesdon Exp $ *) + +(** Representation and manipulation of a type, but not class nor module type.*) + +module Name = Odoc_name + +type private_flag = Asttypes.private_flag = + Private | Public + +(** Description of a variant type constructor. *) +type variant_constructor = { + vc_name : string ; + vc_args : Types.type_expr list ; (** arguments of the constructor *) + mutable vc_text : Odoc_types.text option ; (** optional user description *) + } + +(** Description of a record type field. *) +type record_field = { + rf_name : string ; + rf_mutable : bool ; (** true if mutable *) + rf_type : Types.type_expr ; + mutable rf_text : Odoc_types.text option ; (** optional user description *) + } + +(** The various kinds of type. *) +type type_kind = + Type_abstract + | Type_variant of variant_constructor list + (** constructors *) + | Type_record of record_field list + (** fields *) + +(** Representation of a type. *) +type t_type = { + ty_name : Name.t ; + mutable ty_info : Odoc_types.info option ; (** optional user information *) + ty_parameters : (Types.type_expr * bool * bool) list ; + (** type parameters: (type, covariant, contravariant) *) + ty_kind : type_kind ; + ty_private : private_flag; + ty_manifest : Types.type_expr option; (** type manifest *) + mutable ty_loc : Odoc_types.location ; + mutable ty_code : string option; + } + diff --git a/ocamldoc/odoc_types.ml b/ocamldoc/odoc_types.ml new file mode 100644 index 0000000..3987b47 --- /dev/null +++ b/ocamldoc/odoc_types.ml @@ -0,0 +1,133 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_types.ml,v 1.9 2006-01-04 16:55:50 doligez Exp $ *) + +type ref_kind = + RK_module + | RK_module_type + | RK_class + | RK_class_type + | RK_value + | RK_type + | RK_exception + | RK_attribute + | RK_method + | RK_section of text + +and text_element = + | Raw of string + | Code of string + | CodePre of string + | Verbatim of string + | Bold of text + | Italic of text + | Emphasize of text + | Center of text + | Left of text + | Right of text + | List of text list + | Enum of text list + | Newline + | Block of text + | Title of int * string option * text + | Latex of string + | Link of string * text + | Ref of string * ref_kind option + | Superscript of text + | Subscript of text + | Module_list of string list + | Index_list + | Custom of string * text + +and text = text_element list + +type see_ref = + See_url of string + | See_file of string + | See_doc of string + +type see = see_ref * text + +type param = (string * text) + +type raised_exception = (string * text) + +type info = { + i_desc : text option; + i_authors : string list; + i_version : string option; + i_sees : see list; + i_since : string option; + i_deprecated : text option; + i_params : param list; + i_raised_exceptions : raised_exception list; + i_return_value : text option ; + i_custom : (string * text) list ; + } + +let dummy_info = { + i_desc = None ; + i_authors = [] ; + i_version = None ; + i_sees = [] ; + i_since = None ; + i_deprecated = None ; + i_params = [] ; + i_raised_exceptions = [] ; + i_return_value = None ; + i_custom = [] ; +} + +type location = { + loc_impl : (string * int) option ; + loc_inter : (string * int) option ; + } + +let dummy_loc = { loc_impl = None ; loc_inter = None } + +type merge_option = + | Merge_description + | Merge_author + | Merge_version + | Merge_see + | Merge_since + | Merge_deprecated + | Merge_param + | Merge_raised_exception + | Merge_return_value + | Merge_custom + +let all_merge_options = [ + Merge_description ; + Merge_author ; + Merge_version ; + Merge_see ; + Merge_since ; + Merge_deprecated ; + Merge_param ; + Merge_raised_exception ; + Merge_return_value ; + Merge_custom ; +] + +type magic = string + +let magic = Odoc_messages.magic + +type 'a dump = Dump of magic * 'a + +let make_dump a = Dump (magic, a) + +let open_dump = function + Dump (m, a) -> + if m = magic then a + else raise (Failure Odoc_messages.bad_magic_number) diff --git a/ocamldoc/odoc_types.mli b/ocamldoc/odoc_types.mli new file mode 100644 index 0000000..352bd49 --- /dev/null +++ b/ocamldoc/odoc_types.mli @@ -0,0 +1,133 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_types.mli,v 1.6 2006-01-04 16:55:50 doligez Exp $ *) + +(** Types for the information collected in comments. *) + +(** The differents kinds of element references. *) +type ref_kind = + RK_module + | RK_module_type + | RK_class + | RK_class_type + | RK_value + | RK_type + | RK_exception + | RK_attribute + | RK_method + | RK_section of text + +and text_element = + | Raw of string (** Raw text. *) + | Code of string (** The string is source code. *) + | CodePre of string (** The string is pre-formatted source code. *) + | Verbatim of string (** String 'as is'. *) + | Bold of text (** Text in bold style. *) + | Italic of text (** Text in italic. *) + | Emphasize of text (** Emphasized text. *) + | Center of text (** Centered text. *) + | Left of text (** Left alignment. *) + | Right of text (** Right alignment. *) + | List of text list (** A list. *) + | Enum of text list (** An enumerated list. *) + | Newline (** To force a line break. *) + | Block of text (** Like html's block quote. *) + | Title of int * string option * text + (** Style number, optional label, and text. *) + | Latex of string (** A string for latex. *) + | Link of string * text (** A reference string and the link text. *) + | Ref of string * ref_kind option + (** A reference to an element. Complete name and kind. *) + | Superscript of text (** Superscripts. *) + | Subscript of text (** Subscripts. *) + | Module_list of string list + (** The table of the given modules with their abstract; *) + | Index_list (** The links to the various indexes (values, types, ...) *) + | Custom of string * text (** to extend \{foo syntax *) + +(** [text] is a list of text_elements. The order matters. *) +and text = text_element list + +(** The different forms of references in \@see tags. *) +type see_ref = + See_url of string + | See_file of string + | See_doc of string + +(** The information in a \@see tag. *) +type see = see_ref * text + +(** Parameter name and description. *) +type param = (string * text) + +(** Raised exception name and description. *) +type raised_exception = (string * text) + +(** Information in a special comment. *) +type info = { + i_desc : text option; (** The description text. *) + i_authors : string list; (** The list of authors in \@author tags. *) + i_version : string option; (** The string in the \@version tag. *) + i_sees : see list; (** The list of \@see tags. *) + i_since : string option; (** The string in the \@since tag. *) + i_deprecated : text option; (** The of the \@deprecated tag. *) + i_params : param list; (** The list of parameter descriptions. *) + i_raised_exceptions : raised_exception list; (** The list of raised exceptions. *) + i_return_value : text option ; (** The description text of the return value. *) + i_custom : (string * text) list ; (** A text associated to a custom @-tag. *) + } + +(** An empty info structure. *) +val dummy_info : info + +(** Location of elements in implementation and interface files. *) +type location = { + loc_impl : (string * int) option ; (** implementation file name and position *) + loc_inter : (string * int) option ; (** interface file name and position *) + } + +(** A dummy location. *) +val dummy_loc : location + +(** The information to merge from two elements when they both have some information. *) +type merge_option = + | Merge_description (** Descriptions are concatenated. *) + | Merge_author (** Lists of authors are concatenated. *) + | Merge_version (** Versions are concatenated. *) + | Merge_see (** See references are concatenated. *) + | Merge_since (** Since information are concatenated. *) + | Merge_deprecated (** Deprecated information are concatenated. *) + | Merge_param (** Information on each parameter is concatenated, + and all parameters are kept. *) + | Merge_raised_exception (** Information on each raised_exception is concatenated, + and all raised exceptions are kept. *) + | Merge_return_value (** Information on return value are concatenated. *) + | Merge_custom (** Merge custom tags (all pairs (tag, text) are kept). *) + +(** The list with all merge options. *) +val all_merge_options : merge_option list + +(** Type of magic numbers. *) +type magic + +(** The magic number for the dumps of this version of ocamldoc. *) +val magic : magic + +(** A dump of a structure. *) +type 'a dump + +(** Create a dump structure. *) +val make_dump : 'a -> 'a dump + +(** Verify that a dump has the correct magic number + and return its content. *) +val open_dump : 'a dump -> 'a diff --git a/ocamldoc/odoc_value.ml b/ocamldoc/odoc_value.ml new file mode 100644 index 0000000..e41e768 --- /dev/null +++ b/ocamldoc/odoc_value.ml @@ -0,0 +1,145 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: odoc_value.ml,v 1.7 2008-07-23 08:55:36 guesdon Exp $ *) + +(** Representation and manipulation of values, class attributes and class methods. *) + +module Name = Odoc_name + +(** Types *) + +(** Representation of a value. *) +type t_value = { + val_name : Name.t ; + mutable val_info : Odoc_types.info option ; + val_type : Types.type_expr ; + val_recursive : bool ; + mutable val_parameters : Odoc_parameter.parameter list ; + mutable val_code : string option ; + mutable val_loc : Odoc_types.location ; + } + +(** Representation of a class attribute. *) +type t_attribute = { + att_value : t_value ; (** an attribute has almost all the same information + as a value *) + att_mutable : bool ; + att_virtual : bool ; + } + +(** Representation of a class method. *) +type t_method = { + met_value : t_value ; (** a method has almost all the same information + as a value *) + met_private : bool ; + met_virtual : bool ; + } + +(** Functions *) + +(** Returns the text associated to the given parameter name + in the given value, or None. *) +let value_parameter_text_by_name v name = + match v.val_info with + None -> None + | Some i -> + try + let t = List.assoc name i.Odoc_types.i_params in + Some t + with + Not_found -> + None + +(** Update the parameters text of a t_value, according to the val_info field. *) +let update_value_parameters_text v = + let f p = + Odoc_parameter.update_parameter_text (value_parameter_text_by_name v) p + in + List.iter f v.val_parameters + +(** Create a list of (parameter name, typ) from a type, according to the arrows. + [parameter_list_from_arrows t = [ a ; b ]] if t = a -> b -> c.*) +let parameter_list_from_arrows typ = + let rec iter t = + match t.Types.desc with + Types.Tarrow (l, t1, t2, _) -> + (l, t1) :: (iter t2) + | Types.Tlink texp + | Types.Tsubst texp -> + iter texp + | Types.Tpoly (texp, _) -> iter texp + | Types.Tvar + | Types.Ttuple _ + | Types.Tconstr _ + | Types.Tobject _ + | Types.Tfield _ + | Types.Tnil + | Types.Tunivar + | Types.Tvariant _ -> + [] + in + iter typ + +(** Create a list of parameters with dummy names "??" from a type list. + Used when we want to merge the parameters of a value, from the .ml + and the .mli file. In the .mli file we don't have parameter names + so there is nothing to merge. With this dummy list we can merge the + parameter names from the .ml and the type from the .mli file. *) +let dummy_parameter_list typ = + let normal_name s = + match s with + "" -> s + | _ -> + match s.[0] with + '?' -> String.sub s 1 ((String.length s) - 1) + | _ -> s + in + Printtyp.mark_loops typ; + let liste_param = parameter_list_from_arrows typ in + let rec iter (label, t) = + match t.Types.desc with + | Types.Ttuple l -> + if label = "" then + Odoc_parameter.Tuple + (List.map (fun t2 -> iter ("", t2)) l, t) + else + (* if there is a label, then we don't want to decompose the tuple *) + Odoc_parameter.Simple_name + { Odoc_parameter.sn_name = normal_name label ; + Odoc_parameter.sn_type = t ; + Odoc_parameter.sn_text = None } + | Types.Tlink t2 + | Types.Tsubst t2 -> + (iter (label, t2)) + + | _ -> + Odoc_parameter.Simple_name + { Odoc_parameter.sn_name = normal_name label ; + Odoc_parameter.sn_type = t ; + Odoc_parameter.sn_text = None } + in + List.map iter liste_param + +(** Return true if the value is a function, i.e. has a functional type.*) +let is_function v = + let rec f t = + match t.Types.desc with + Types.Tarrow _ -> + true + | Types.Tlink t -> + f t + | _ -> + false + in + f v.val_type + + diff --git a/ocamldoc/remove_DEBUG b/ocamldoc/remove_DEBUG new file mode 100755 index 0000000..b1eab18 --- /dev/null +++ b/ocamldoc/remove_DEBUG @@ -0,0 +1,21 @@ +#!/bin/sh + +#(***********************************************************************) +#(* OCamldoc *) +#(* *) +#(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +#(* *) +#(* Copyright 2003 Institut National de Recherche en Informatique et *) +#(* en Automatique. All rights reserved. This file is distributed *) +#(* under the terms of the Q Public License version 1.0. *) +#(* *) +#(***********************************************************************) + +# $Id: remove_DEBUG,v 1.3 2004-04-15 16:18:52 doligez Exp $ + +# usage: remove_DEBUG <file> +# remove from <file> every line that contains the string "DEBUG", +# respecting the cpp # line annotation conventions + +echo "# 1 \"$1\"" +LC_ALL=C sed -e '/DEBUG/s/.*//' "$1" diff --git a/ocamldoc/runocamldoc b/ocamldoc/runocamldoc new file mode 100644 index 0000000..c63a697 --- /dev/null +++ b/ocamldoc/runocamldoc @@ -0,0 +1,12 @@ +#!/bin/sh +# $Id: runocamldoc,v 1.6 2002-07-23 14:11:53 doligez Exp $ + +case "$1" in + true) shift + exec ../boot/ocamlrun -I ../otherlibs/unix -I ../otherlibs/str \ + ./ocamldoc "$@" + ;; + *) shift + exec ./ocamldoc "$@" + ;; +esac diff --git a/otherlibs/Makefile b/otherlibs/Makefile new file mode 100644 index 0000000..d7741d0 --- /dev/null +++ b/otherlibs/Makefile @@ -0,0 +1,24 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.4 2007-11-08 09:17:47 frisch Exp $ + +# Common Makefile for otherlibs on the Unix ports + +CAMLC=$(ROOTDIR)/ocamlcomp.sh +CAMLOPT=$(ROOTDIR)/ocamlcompopt.sh +CFLAGS=-I$(ROOTDIR)/byterun -O $(SHAREDCCCOMPOPTS) $(EXTRACFLAGS) + +include ../Makefile.shared +# Note .. is the current directory (this makefile is included from +# a subdirectory) diff --git a/otherlibs/Makefile.nt b/otherlibs/Makefile.nt new file mode 100644 index 0000000..8ad36e4 --- /dev/null +++ b/otherlibs/Makefile.nt @@ -0,0 +1,25 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.3 2007-11-08 09:17:48 frisch Exp $ + +# Common Makefile for otherlibs on the Win32/MinGW ports + +CAMLC=$(CAMLRUN) $(ROOTDIR)/ocamlc -nostdlib -I $(ROOTDIR)/stdlib -w s +CAMLOPT=$(CAMLRUN) $(ROOTDIR)/ocamlopt -nostdlib -I $(ROOTDIR)/stdlib -w s +CFLAGS=-I$(ROOTDIR)/byterun $(SHAREDCCCOMPOPTS) $(EXTRACFLAGS) + +include ../Makefile.shared +# Note .. is the current directory (this makefile is included from +# a subdirectory) + diff --git a/otherlibs/Makefile.shared b/otherlibs/Makefile.shared new file mode 100644 index 0000000..c9c226c --- /dev/null +++ b/otherlibs/Makefile.shared @@ -0,0 +1,90 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.shared,v 1.3 2008-07-15 15:31:32 frisch Exp $ + +# Common Makefile for otherlibs + +ROOTDIR=../.. +include $(ROOTDIR)/config/Makefile + +# Compilation options +CC=$(BYTECC) +CAMLRUN=$(ROOTDIR)/boot/ocamlrun +COMPFLAGS=-warn-error A -g $(EXTRACAMLFLAGS) +MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib + +# Variables to be defined by individual libraries: +#LIBNAME= +#CLIBNAME= +#CMIFILES= +#CAMLOBJS= +#COBJS= +#EXTRACFLAGS= +#EXTRACAMLFLAGS= +#LINKOPTS= +#LDOPTS= +#HEADERS= + +CMIFILES ?= $(CAMLOBJS:.cmo=.cmi) +CAMLOBJS_NAT ?= $(CAMLOBJS:.cmo=.cmx) +CLIBNAME ?= $(LIBNAME) + +all: lib$(CLIBNAME).$(A) $(LIBNAME).cma $(CMIFILES) + +allopt: lib$(CLIBNAME).$(A) $(LIBNAME).cmxa $(LIBNAME).$(CMXS) $(CMIFILES) + +$(LIBNAME).cma: $(CAMLOBJS) + $(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlc '$(CAMLC)' -linkall $(CAMLOBJS) $(LINKOPTS) + +$(LIBNAME).cmxa: $(CAMLOBJS_NAT) + $(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlopt '$(CAMLOPT)' -linkall $(CAMLOBJS_NAT) $(LINKOPTS) + +$(LIBNAME).cmxs: $(LIBNAME).cmxa lib$(CLIBNAME).$(A) + $(CAMLOPT) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa + +lib$(CLIBNAME).$(A): $(COBJS) + $(MKLIB) -oc $(CLIBNAME) $(COBJS) $(LDOPTS) + +install:: + if test -f dll$(CLIBNAME)$(EXT_DLL); then \ + cp dll$(CLIBNAME)$(EXT_DLL) $(STUBLIBDIR)/; fi + cp lib$(CLIBNAME).$(A) $(LIBDIR)/ + cd $(LIBDIR); $(RANLIB) lib$(CLIBNAME).$(A) + cp $(LIBNAME).cma $(CMIFILES) $(CMIFILES:.cmi=.mli) $(LIBDIR)/ + if test -n "$(HEADERS)"; then cp $(HEADERS) $(LIBDIR)/caml/; fi + +installopt: + cp $(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).$(A) $(LIBDIR)/ + cd $(LIBDIR); $(RANLIB) $(LIBNAME).a + if test -f $(LIBNAME).cmxs; then cp $(LIBNAME).cmxs $(LIBDIR)/; fi + +partialclean: + rm -f *.cm* + +clean:: partialclean + rm -f *.dll *.so *.a *.lib *.o *.obj + +.SUFFIXES: .ml .mli .cmi .cmo .cmx .$(O) + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.c.$(O): + $(BYTECC) $(BYTECCCOMPOPTS) $(CFLAGS) -c $< diff --git a/otherlibs/bigarray/.cvsignore b/otherlibs/bigarray/.cvsignore new file mode 100644 index 0000000..c54b3a3 --- /dev/null +++ b/otherlibs/bigarray/.cvsignore @@ -0,0 +1,3 @@ +*.o +*.x +so_locations diff --git a/otherlibs/bigarray/.depend b/otherlibs/bigarray/.depend new file mode 100644 index 0000000..eb76fc5 --- /dev/null +++ b/otherlibs/bigarray/.depend @@ -0,0 +1,32 @@ +bigarray_stubs.o: bigarray_stubs.c ../../byterun/alloc.h \ + ../../byterun/misc.h ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/mlvalues.h \ + ../../byterun/config.h ../../byterun/misc.h bigarray.h \ + ../../byterun/custom.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/intext.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/io.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fix_code.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/memory.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +mmap_unix.o: mmap_unix.c bigarray.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/mlvalues.h ../../byterun/config.h ../../byterun/misc.h \ + ../../byterun/config.h ../../byterun/custom.h ../../byterun/mlvalues.h \ + ../../byterun/fail.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/io.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/sys.h ../../byterun/misc.h +mmap_win32.o: mmap_win32.c bigarray.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/mlvalues.h ../../byterun/config.h ../../byterun/misc.h \ + ../../byterun/config.h ../../byterun/alloc.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/custom.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/sys.h ../../byterun/misc.h \ + ../unix/unixsupport.h +bigarray.cmi: +bigarray.cmo: bigarray.cmi +bigarray.cmx: bigarray.cmi diff --git a/otherlibs/bigarray/Makefile b/otherlibs/bigarray/Makefile new file mode 100644 index 0000000..7795cd7 --- /dev/null +++ b/otherlibs/bigarray/Makefile @@ -0,0 +1,29 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.25 2008-01-04 09:52:27 xleroy Exp $ + +LIBNAME=bigarray +EXTRACFLAGS=-I../unix -DIN_OCAML_BIGARRAY -DCAML_NAME_SPACE +EXTRACAMLFLAGS=-I ../unix +COBJS=bigarray_stubs.$(O) mmap_unix.$(O) +CAMLOBJS=bigarray.cmo +HEADERS=bigarray.h + +include ../Makefile + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/bigarray/Makefile.nt b/otherlibs/bigarray/Makefile.nt new file mode 100644 index 0000000..66096ff --- /dev/null +++ b/otherlibs/bigarray/Makefile.nt @@ -0,0 +1,29 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.13 2008-01-04 15:01:48 xleroy Exp $ + +LIBNAME=bigarray +EXTRACFLAGS=-I../win32unix -DIN_OCAML_BIGARRAY -DCAML_NAME_SPACE +EXTRACAMLFLAGS=-I ../win32unix +COBJS=bigarray_stubs.$(O) mmap_win32.$(O) +CAMLOBJS=bigarray.cmo +HEADERS=bigarray.h + +include ../Makefile.nt + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/bigarray/bigarray.h b/otherlibs/bigarray/bigarray.h new file mode 100644 index 0000000..3af4366 --- /dev/null +++ b/otherlibs/bigarray/bigarray.h @@ -0,0 +1,95 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bigarray.h,v 1.10 2008-12-03 18:09:09 doligez Exp $ */ + +#ifndef CAML_BIGARRAY_H +#define CAML_BIGARRAY_H + +#ifndef CAML_NAME_SPACE +#include "compatibility.h" +#endif +#include "config.h" +#include "mlvalues.h" + +typedef signed char caml_ba_int8; +typedef unsigned char caml_ba_uint8; +#if SIZEOF_SHORT == 2 +typedef short caml_ba_int16; +typedef unsigned short caml_ba_uint16; +#else +#error "No 16-bit integer type available" +#endif + +#define CAML_BA_MAX_NUM_DIMS 16 + +enum caml_ba_kind { + CAML_BA_FLOAT32, /* Single-precision floats */ + CAML_BA_FLOAT64, /* Double-precision floats */ + CAML_BA_SINT8, /* Signed 8-bit integers */ + CAML_BA_UINT8, /* Unsigned 8-bit integers */ + CAML_BA_SINT16, /* Signed 16-bit integers */ + CAML_BA_UINT16, /* Unsigned 16-bit integers */ + CAML_BA_INT32, /* Signed 32-bit integers */ + CAML_BA_INT64, /* Signed 64-bit integers */ + CAML_BA_CAML_INT, /* Caml-style integers (signed 31 or 63 bits) */ + CAML_BA_NATIVE_INT, /* Platform-native long integers (32 or 64 bits) */ + CAML_BA_COMPLEX32, /* Single-precision complex */ + CAML_BA_COMPLEX64, /* Double-precision complex */ + CAML_BA_KIND_MASK = 0xFF /* Mask for kind in flags field */ +}; + +enum caml_ba_layout { + CAML_BA_C_LAYOUT = 0, /* Row major, indices start at 0 */ + CAML_BA_FORTRAN_LAYOUT = 0x100, /* Column major, indices start at 1 */ + CAML_BA_LAYOUT_MASK = 0x100 /* Mask for layout in flags field */ +}; + +enum caml_ba_managed { + CAML_BA_EXTERNAL = 0, /* Data is not allocated by Caml */ + CAML_BA_MANAGED = 0x200, /* Data is allocated by Caml */ + CAML_BA_MAPPED_FILE = 0x400, /* Data is a memory mapped file */ + CAML_BA_MANAGED_MASK = 0x600 /* Mask for "managed" bits in flags field */ +}; + +struct caml_ba_proxy { + intnat refcount; /* Reference count */ + void * data; /* Pointer to base of actual data */ + uintnat size; /* Size of data in bytes (if mapped file) */ +}; + +struct caml_ba_array { + void * data; /* Pointer to raw data */ + intnat num_dims; /* Number of dimensions */ + intnat flags; /* Kind of element array + memory layout + allocation status */ + struct caml_ba_proxy * proxy; /* The proxy for sub-arrays, or NULL */ + intnat dim[1] /*[num_dims]*/; /* Size in each dimension */ +}; + +#define Caml_ba_array_val(v) ((struct caml_ba_array *) Data_custom_val(v)) + +#define Caml_ba_data_val(v) (Caml_ba_array_val(v)->data) + +#if defined(IN_OCAML_BIGARRAY) +#define CAMLBAextern CAMLexport +#else +#define CAMLBAextern CAMLextern +#endif + +CAMLBAextern value + caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim); +CAMLBAextern value caml_ba_alloc_dims(int flags, int num_dims, void * data, + ... /*dimensions, with type intnat */); +CAMLBAextern uintnat caml_ba_byte_size(struct caml_ba_array * b); + +#endif diff --git a/otherlibs/bigarray/bigarray.ml b/otherlibs/bigarray/bigarray.ml new file mode 100644 index 0000000..bdbe2fe --- /dev/null +++ b/otherlibs/bigarray/bigarray.ml @@ -0,0 +1,253 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Manuel Serrano et Xavier Leroy, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: bigarray.ml,v 1.20 2008-07-14 09:09:53 xleroy Exp $ *) + +(* Module [Bigarray]: large, multi-dimensional, numerical arrays *) + +external init : unit -> unit = "caml_ba_init" + +let _ = init() + +type ('a, 'b) kind = int + +type int8_signed_elt +type int8_unsigned_elt +type int16_signed_elt +type int16_unsigned_elt +type int_elt +type int32_elt +type int64_elt +type nativeint_elt +type float32_elt +type float64_elt +type complex32_elt +type complex64_elt + +(* Keep those constants in sync with the caml_ba_kind enumeration + in bigarray.h *) + +let float32 = 0 +let float64 = 1 +let int8_signed = 2 +let int8_unsigned = 3 +let int16_signed = 4 +let int16_unsigned = 5 +let int32 = 6 +let int64 = 7 +let int = 8 +let nativeint = 9 +let char = int8_unsigned +let complex32 = 10 +let complex64 = 11 + +type 'a layout = int + +type c_layout +type fortran_layout + +(* Keep those constants in sync with the caml_ba_layout enumeration + in bigarray.h *) + +let c_layout = 0 +let fortran_layout = 0x100 + +module Genarray = struct + type ('a, 'b, 'c) t + external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t + = "caml_ba_create" + external get: ('a, 'b, 'c) t -> int array -> 'a + = "caml_ba_get_generic" + external set: ('a, 'b, 'c) t -> int array -> 'a -> unit + = "caml_ba_set_generic" + external num_dims: ('a, 'b, 'c) t -> int = "caml_ba_num_dims" + external nth_dim: ('a, 'b, 'c) t -> int -> int = "caml_ba_dim" + let dims a = + let n = num_dims a in + let d = Array.make n 0 in + for i = 0 to n-1 do d.(i) <- nth_dim a i done; + d + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> + ('a, 'b, fortran_layout) t + = "caml_ba_sub" + external slice_left: ('a, 'b, c_layout) t -> int array -> + ('a, 'b, c_layout) t + = "caml_ba_slice" + external slice_right: ('a, 'b, fortran_layout) t -> int array -> + ('a, 'b, fortran_layout) t + = "caml_ba_slice" + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + external map_internal: Unix.file_descr -> ('a, 'b) kind -> 'c layout -> + bool -> int array -> int64 -> ('a, 'b, 'c) t + = "caml_ba_map_file_bytecode" "caml_ba_map_file" + let map_file fd ?(pos = 0L) kind layout shared dims = + map_internal fd kind layout shared dims pos +end + +module Array1 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim = + Genarray.create kind layout [|dim|] + external get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_ref_1" + external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "%caml_ba_set_1" + external unsafe_get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_unsafe_ref_1" + external unsafe_set: ('a, 'b, 'c) t -> int -> 'a -> unit = "%caml_ba_unsafe_set_1" + let dim a = Genarray.nth_dim a 0 + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t = "caml_ba_sub" + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array kind layout data = + let ba = create kind layout (Array.length data) in + let ofs = if layout = c_layout then 0 else 1 in + for i = 0 to Array.length data - 1 do unsafe_set ba (i + ofs) data.(i) done; + ba + let map_file fd ?pos kind layout shared dim = + Genarray.map_file fd ?pos kind layout shared [|dim|] +end + +module Array2 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim1 dim2 = + Genarray.create kind layout [|dim1; dim2|] + external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%caml_ba_ref_2" + external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "%caml_ba_set_2" + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> 'a = "%caml_ba_unsafe_ref_2" + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "%caml_ba_unsafe_set_2" + let dim1 a = Genarray.nth_dim a 0 + let dim2 a = Genarray.nth_dim a 1 + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + let slice_left a n = Genarray.slice_left a [|n|] + let slice_right a n = Genarray.slice_right a [|n|] + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array kind layout data = + let dim1 = Array.length data in + let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in + let ba = create kind layout dim1 dim2 in + let ofs = if layout = c_layout then 0 else 1 in + for i = 0 to dim1 - 1 do + let row = data.(i) in + if Array.length row <> dim2 then + invalid_arg("Bigarray.Array2.of_array: non-rectangular data"); + for j = 0 to dim2 - 1 do + unsafe_set ba (i + ofs) (j + ofs) row.(j) + done + done; + ba + let map_file fd ?pos kind layout shared dim1 dim2 = + Genarray.map_file fd ?pos kind layout shared [|dim1;dim2|] +end + +module Array3 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim1 dim2 dim3 = + Genarray.create kind layout [|dim1; dim2; dim3|] + external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%caml_ba_ref_3" + external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "%caml_ba_set_3" + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%caml_ba_unsafe_ref_3" + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit = "%caml_ba_unsafe_set_3" + let dim1 a = Genarray.nth_dim a 0 + let dim2 a = Genarray.nth_dim a 1 + let dim3 a = Genarray.nth_dim a 2 + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + let slice_left_1 a n m = Genarray.slice_left a [|n; m|] + let slice_right_1 a n m = Genarray.slice_right a [|n; m|] + let slice_left_2 a n = Genarray.slice_left a [|n|] + let slice_right_2 a n = Genarray.slice_right a [|n|] + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array kind layout data = + let dim1 = Array.length data in + let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in + let dim3 = if dim2 = 0 then 0 else Array.length data.(0).(0) in + let ba = create kind layout dim1 dim2 dim3 in + let ofs = if layout = c_layout then 0 else 1 in + for i = 0 to dim1 - 1 do + let row = data.(i) in + if Array.length row <> dim2 then + invalid_arg("Bigarray.Array3.of_array: non-cubic data"); + for j = 0 to dim2 - 1 do + let col = row.(j) in + if Array.length col <> dim3 then + invalid_arg("Bigarray.Array3.of_array: non-cubic data"); + for k = 0 to dim3 - 1 do + unsafe_set ba (i + ofs) (j + ofs) (k + ofs) col.(k) + done + done + done; + ba + let map_file fd ?pos kind layout shared dim1 dim2 dim3 = + Genarray.map_file fd ?pos kind layout shared [|dim1;dim2;dim3|] +end + +external genarray_of_array1: ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +external genarray_of_array2: ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +external genarray_of_array3: ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +let array1_of_genarray a = + if Genarray.num_dims a = 1 then a + else invalid_arg "Bigarray.array1_of_genarray" +let array2_of_genarray a = + if Genarray.num_dims a = 2 then a + else invalid_arg "Bigarray.array2_of_genarray" +let array3_of_genarray a = + if Genarray.num_dims a = 3 then a + else invalid_arg "Bigarray.array3_of_genarray" + +external reshape: + ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t + = "caml_ba_reshape" +let reshape_1 a dim1 = reshape a [|dim1|] +let reshape_2 a dim1 dim2 = reshape a [|dim1;dim2|] +let reshape_3 a dim1 dim2 dim3 = reshape a [|dim1;dim2;dim3|] + +(* Force caml_ba_get_{1,2,3,N} to be linked in, since we don't refer + to those primitives directly in this file *) + +let _ = + let _ = Genarray.get in + let _ = Array1.get in + let _ = Array2.get in + let _ = Array3.get in + () + +external get1: unit -> unit = "caml_ba_get_1" +external get2: unit -> unit = "caml_ba_get_2" +external get3: unit -> unit = "caml_ba_get_3" +external set1: unit -> unit = "caml_ba_set_1" +external set2: unit -> unit = "caml_ba_set_2" +external set3: unit -> unit = "caml_ba_set_3" diff --git a/otherlibs/bigarray/bigarray.mli b/otherlibs/bigarray/bigarray.mli new file mode 100644 index 0000000..ad630ec --- /dev/null +++ b/otherlibs/bigarray/bigarray.mli @@ -0,0 +1,800 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: bigarray.mli,v 1.29 2008-12-03 18:09:09 doligez Exp $ *) + +(** Large, multi-dimensional, numerical arrays. + + This module implements multi-dimensional arrays of integers and + floating-point numbers, thereafter referred to as ``big arrays''. + The implementation allows efficient sharing of large numerical + arrays between Caml code and C or Fortran numerical libraries. + + Concerning the naming conventions, users of this module are encouraged + to do [open Bigarray] in their source, then refer to array types and + operations via short dot notation, e.g. [Array1.t] or [Array2.sub]. + + Big arrays support all the Caml ad-hoc polymorphic operations: + - comparisons ([=], [<>], [<=], etc, as well as {!Pervasives.compare}); + - hashing (module [Hash]); + - and structured input-output ({!Pervasives.output_value} + and {!Pervasives.input_value}, as well as the functions from the + {!Marshal} module). +*) + +(** {6 Element kinds} *) + +(** Big arrays can contain elements of the following kinds: +- IEEE single precision (32 bits) floating-point numbers + ({!Bigarray.float32_elt}), +- IEEE double precision (64 bits) floating-point numbers + ({!Bigarray.float64_elt}), +- IEEE single precision (2 * 32 bits) floating-point complex numbers + ({!Bigarray.complex32_elt}), +- IEEE double precision (2 * 64 bits) floating-point complex numbers + ({!Bigarray.complex64_elt}), +- 8-bit integers (signed or unsigned) + ({!Bigarray.int8_signed_elt} or {!Bigarray.int8_unsigned_elt}), +- 16-bit integers (signed or unsigned) + ({!Bigarray.int16_signed_elt} or {!Bigarray.int16_unsigned_elt}), +- Caml integers (signed, 31 bits on 32-bit architectures, + 63 bits on 64-bit architectures) ({!Bigarray.int_elt}), +- 32-bit signed integer ({!Bigarray.int32_elt}), +- 64-bit signed integers ({!Bigarray.int64_elt}), +- platform-native signed integers (32 bits on 32-bit architectures, + 64 bits on 64-bit architectures) ({!Bigarray.nativeint_elt}). + + Each element kind is represented at the type level by one + of the abstract types defined below. +*) + +type float32_elt +type float64_elt +type complex32_elt +type complex64_elt +type int8_signed_elt +type int8_unsigned_elt +type int16_signed_elt +type int16_unsigned_elt +type int_elt +type int32_elt +type int64_elt +type nativeint_elt + +type ('a, 'b) kind +(** To each element kind is associated a Caml type, which is + the type of Caml values that can be stored in the big array + or read back from it. This type is not necessarily the same + as the type of the array elements proper: for instance, + a big array whose elements are of kind [float32_elt] contains + 32-bit single precision floats, but reading or writing one of + its elements from Caml uses the Caml type [float], which is + 64-bit double precision floats. + + The abstract type [('a, 'b) kind] captures this association + of a Caml type ['a] for values read or written in the big array, + and of an element kind ['b] which represents the actual contents + of the big array. The following predefined values of type + [kind] list all possible associations of Caml types with + element kinds: *) + +val float32 : (float, float32_elt) kind +(** See {!Bigarray.char}. *) + +val float64 : (float, float64_elt) kind +(** See {!Bigarray.char}. *) + +val complex32 : (Complex.t, complex32_elt) kind +(** See {!Bigarray.char}. *) + +val complex64 : (Complex.t, complex64_elt) kind +(** See {!Bigarray.char}. *) + +val int8_signed : (int, int8_signed_elt) kind +(** See {!Bigarray.char}. *) + +val int8_unsigned : (int, int8_unsigned_elt) kind +(** See {!Bigarray.char}. *) + +val int16_signed : (int, int16_signed_elt) kind +(** See {!Bigarray.char}. *) + +val int16_unsigned : (int, int16_unsigned_elt) kind +(** See {!Bigarray.char}. *) + +val int : (int, int_elt) kind +(** See {!Bigarray.char}. *) + +val int32 : (int32, int32_elt) kind +(** See {!Bigarray.char}. *) + +val int64 : (int64, int64_elt) kind +(** See {!Bigarray.char}. *) + +val nativeint : (nativeint, nativeint_elt) kind +(** See {!Bigarray.char}. *) + +val char : (char, int8_unsigned_elt) kind +(** As shown by the types of the values above, + big arrays of kind [float32_elt] and [float64_elt] are + accessed using the Caml type [float]. Big arrays of complex kinds + [complex32_elt], [complex64_elt] are accessed with the Caml type + {!Complex.t}. Big arrays of + integer kinds are accessed using the smallest Caml integer + type large enough to represent the array elements: + [int] for 8- and 16-bit integer bigarrays, as well as Caml-integer + bigarrays; [int32] for 32-bit integer bigarrays; [int64] + for 64-bit integer bigarrays; and [nativeint] for + platform-native integer bigarrays. Finally, big arrays of + kind [int8_unsigned_elt] can also be accessed as arrays of + characters instead of arrays of small integers, by using + the kind value [char] instead of [int8_unsigned]. *) + +(** {6 Array layouts} *) + +type c_layout +(** See {!Bigarray.fortran_layout}.*) + +type fortran_layout +(** To facilitate interoperability with existing C and Fortran code, + this library supports two different memory layouts for big arrays, + one compatible with the C conventions, + the other compatible with the Fortran conventions. + + In the C-style layout, array indices start at 0, and + multi-dimensional arrays are laid out in row-major format. + That is, for a two-dimensional array, all elements of + row 0 are contiguous in memory, followed by all elements of + row 1, etc. In other terms, the array elements at [(x,y)] + and [(x, y+1)] are adjacent in memory. + + In the Fortran-style layout, array indices start at 1, and + multi-dimensional arrays are laid out in column-major format. + That is, for a two-dimensional array, all elements of + column 0 are contiguous in memory, followed by all elements of + column 1, etc. In other terms, the array elements at [(x,y)] + and [(x+1, y)] are adjacent in memory. + + Each layout style is identified at the type level by the + abstract types {!Bigarray.c_layout} and [fortran_layout] respectively. *) + +type 'a layout +(** The type ['a layout] represents one of the two supported + memory layouts: C-style if ['a] is {!Bigarray.c_layout}, Fortran-style + if ['a] is {!Bigarray.fortran_layout}. *) + + +(** {7 Supported layouts} + + The abstract values [c_layout] and [fortran_layout] represent + the two supported layouts at the level of values. +*) + +val c_layout : c_layout layout +val fortran_layout : fortran_layout layout + + +(** {6 Generic arrays (of arbitrarily many dimensions)} *) + +module Genarray : + sig + type ('a, 'b, 'c) t + (** The type [Genarray.t] is the type of big arrays with variable + numbers of dimensions. Any number of dimensions between 1 and 16 + is supported. + + The three type parameters to [Genarray.t] identify the array element + kind and layout, as follows: + - the first parameter, ['a], is the Caml type for accessing array + elements ([float], [int], [int32], [int64], [nativeint]); + - the second parameter, ['b], is the actual kind of array elements + ([float32_elt], [float64_elt], [int8_signed_elt], [int8_unsigned_elt], + etc); + - the third parameter, ['c], identifies the array layout + ([c_layout] or [fortran_layout]). + + For instance, [(float, float32_elt, fortran_layout) Genarray.t] + is the type of generic big arrays containing 32-bit floats + in Fortran layout; reads and writes in this array use the + Caml type [float]. *) + + external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t + = "caml_ba_create" + (** [Genarray.create kind layout dimensions] returns a new big array + whose element kind is determined by the parameter [kind] (one of + [float32], [float64], [int8_signed], etc) and whose layout is + determined by the parameter [layout] (one of [c_layout] or + [fortran_layout]). The [dimensions] parameter is an array of + integers that indicate the size of the big array in each dimension. + The length of [dimensions] determines the number of dimensions + of the bigarray. + + For instance, [Genarray.create int32 c_layout [|4;6;8|]] + returns a fresh big array of 32-bit integers, in C layout, + having three dimensions, the three dimensions being 4, 6 and 8 + respectively. + + Big arrays returned by [Genarray.create] are not initialized: + the initial values of array elements is unspecified. + + [Genarray.create] raises [Invalid_argument] if the number of dimensions + is not in the range 1 to 16 inclusive, or if one of the dimensions + is negative. *) + + external num_dims: ('a, 'b, 'c) t -> int = "caml_ba_num_dims" + (** Return the number of dimensions of the given big array. *) + + val dims : ('a, 'b, 'c) t -> int array + (** [Genarray.dims a] returns all dimensions of the big array [a], + as an array of integers of length [Genarray.num_dims a]. *) + + external nth_dim: ('a, 'b, 'c) t -> int -> int = "caml_ba_dim" + (** [Genarray.nth_dim a n] returns the [n]-th dimension of the + big array [a]. The first dimension corresponds to [n = 0]; + the second dimension corresponds to [n = 1]; the last dimension, + to [n = Genarray.num_dims a - 1]. + Raise [Invalid_argument] if [n] is less than 0 or greater or equal than + [Genarray.num_dims a]. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + external get: ('a, 'b, 'c) t -> int array -> 'a = "caml_ba_get_generic" + (** Read an element of a generic big array. + [Genarray.get a [|i1; ...; iN|]] returns the element of [a] + whose coordinates are [i1] in the first dimension, [i2] in + the second dimension, ..., [iN] in the [N]-th dimension. + + If [a] has C layout, the coordinates must be greater or equal than 0 + and strictly less than the corresponding dimensions of [a]. + If [a] has Fortran layout, the coordinates must be greater or equal + than 1 and less or equal than the corresponding dimensions of [a]. + Raise [Invalid_argument] if the array [a] does not have exactly [N] + dimensions, or if the coordinates are outside the array bounds. + + If [N > 3], alternate syntax is provided: you can write + [a.{i1, i2, ..., iN}] instead of [Genarray.get a [|i1; ...; iN|]]. + (The syntax [a.{...}] with one, two or three coordinates is + reserved for accessing one-, two- and three-dimensional arrays + as described below.) *) + + external set: ('a, 'b, 'c) t -> int array -> 'a -> unit + = "caml_ba_set_generic" + (** Assign an element of a generic big array. + [Genarray.set a [|i1; ...; iN|] v] stores the value [v] in the + element of [a] whose coordinates are [i1] in the first dimension, + [i2] in the second dimension, ..., [iN] in the [N]-th dimension. + + The array [a] must have exactly [N] dimensions, and all coordinates + must lie inside the array bounds, as described for [Genarray.get]; + otherwise, [Invalid_argument] is raised. + + If [N > 3], alternate syntax is provided: you can write + [a.{i1, i2, ..., iN} <- v] instead of + [Genarray.set a [|i1; ...; iN|] v]. + (The syntax [a.{...} <- v] with one, two or three coordinates is + reserved for updating one-, two- and three-dimensional arrays + as described below.) *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a sub-array of the given big array by restricting the + first (left-most) dimension. [Genarray.sub_left a ofs len] + returns a big array with the same number of dimensions as [a], + and the same dimensions as [a], except the first dimension, + which corresponds to the interval [[ofs ... ofs + len - 1]] + of the first dimension of [a]. No copying of elements is + involved: the sub-array and the original array share the same + storage space. In other terms, the element at coordinates + [[|i1; ...; iN|]] of the sub-array is identical to the + element at coordinates [[|i1+ofs; ...; iN|]] of the original + array [a]. + + [Genarray.sub_left] applies only to big arrays in C layout. + Raise [Invalid_argument] if [ofs] and [len] do not designate + a valid sub-array of [a], that is, if [ofs < 0], or [len < 0], + or [ofs + len > Genarray.nth_dim a 0]. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a sub-array of the given big array by restricting the + last (right-most) dimension. [Genarray.sub_right a ofs len] + returns a big array with the same number of dimensions as [a], + and the same dimensions as [a], except the last dimension, + which corresponds to the interval [[ofs ... ofs + len - 1]] + of the last dimension of [a]. No copying of elements is + involved: the sub-array and the original array share the same + storage space. In other terms, the element at coordinates + [[|i1; ...; iN|]] of the sub-array is identical to the + element at coordinates [[|i1; ...; iN+ofs|]] of the original + array [a]. + + [Genarray.sub_right] applies only to big arrays in Fortran layout. + Raise [Invalid_argument] if [ofs] and [len] do not designate + a valid sub-array of [a], that is, if [ofs < 1], or [len < 0], + or [ofs + len > Genarray.nth_dim a (Genarray.num_dims a - 1)]. *) + + external slice_left: + ('a, 'b, c_layout) t -> int array -> ('a, 'b, c_layout) t + = "caml_ba_slice" + (** Extract a sub-array of lower dimension from the given big array + by fixing one or several of the first (left-most) coordinates. + [Genarray.slice_left a [|i1; ... ; iM|]] returns the ``slice'' + of [a] obtained by setting the first [M] coordinates to + [i1], ..., [iM]. If [a] has [N] dimensions, the slice has + dimension [N - M], and the element at coordinates + [[|j1; ...; j(N-M)|]] in the slice is identical to the element + at coordinates [[|i1; ...; iM; j1; ...; j(N-M)|]] in the original + array [a]. No copying of elements is involved: the slice and + the original array share the same storage space. + + [Genarray.slice_left] applies only to big arrays in C layout. + Raise [Invalid_argument] if [M >= N], or if [[|i1; ... ; iM|]] + is outside the bounds of [a]. *) + + external slice_right: + ('a, 'b, fortran_layout) t -> int array -> ('a, 'b, fortran_layout) t + = "caml_ba_slice" + (** Extract a sub-array of lower dimension from the given big array + by fixing one or several of the last (right-most) coordinates. + [Genarray.slice_right a [|i1; ... ; iM|]] returns the ``slice'' + of [a] obtained by setting the last [M] coordinates to + [i1], ..., [iM]. If [a] has [N] dimensions, the slice has + dimension [N - M], and the element at coordinates + [[|j1; ...; j(N-M)|]] in the slice is identical to the element + at coordinates [[|j1; ...; j(N-M); i1; ...; iM|]] in the original + array [a]. No copying of elements is involved: the slice and + the original array share the same storage space. + + [Genarray.slice_right] applies only to big arrays in Fortran layout. + Raise [Invalid_argument] if [M >= N], or if [[|i1; ... ; iM|]] + is outside the bounds of [a]. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy all elements of a big array in another big array. + [Genarray.blit src dst] copies all elements of [src] into + [dst]. Both arrays [src] and [dst] must have the same number of + dimensions and equal dimensions. Copying a sub-array of [src] + to a sub-array of [dst] can be achieved by applying [Genarray.blit] + to sub-array or slices of [src] and [dst]. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Set all elements of a big array to a given value. + [Genarray.fill a v] stores the value [v] in all elements of + the big array [a]. Setting only some elements of [a] to [v] + can be achieved by applying [Genarray.fill] to a sub-array + or a slice of [a]. *) + + val map_file: + Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout -> + bool -> int array -> ('a, 'b, 'c) t + (** Memory mapping of a file as a big array. + [Genarray.map_file fd kind layout shared dims] + returns a big array of kind [kind], layout [layout], + and dimensions as specified in [dims]. The data contained in + this big array are the contents of the file referred to by + the file descriptor [fd] (as opened previously with + [Unix.openfile], for example). The optional [pos] parameter + is the byte offset in the file of the data being mapped; + it defaults to 0 (map from the beginning of the file). + + If [shared] is [true], all modifications performed on the array + are reflected in the file. This requires that [fd] be opened + with write permissions. If [shared] is [false], modifications + performed on the array are done in memory only, using + copy-on-write of the modified pages; the underlying file is not + affected. + + [Genarray.map_file] is much more efficient than reading + the whole file in a big array, modifying that big array, + and writing it afterwards. + + To adjust automatically the dimensions of the big array to + the actual size of the file, the major dimension (that is, + the first dimension for an array with C layout, and the last + dimension for an array with Fortran layout) can be given as + [-1]. [Genarray.map_file] then determines the major dimension + from the size of the file. The file must contain an integral + number of sub-arrays as determined by the non-major dimensions, + otherwise [Failure] is raised. + + If all dimensions of the big array are given, the file size is + matched against the size of the big array. If the file is larger + than the big array, only the initial portion of the file is + mapped to the big array. If the file is smaller than the big + array, the file is automatically grown to the size of the big array. + This requires write permissions on [fd]. *) + + end + +(** {6 One-dimensional arrays} *) + +(** One-dimensional arrays. The [Array1] structure provides operations + similar to those of + {!Bigarray.Genarray}, but specialized to the case of one-dimensional arrays. + (The [Array2] and [Array3] structures below provide operations + specialized for two- and three-dimensional arrays.) + Statically knowing the number of dimensions of the array allows + faster operations, and more precise static type-checking. *) +module Array1 : sig + type ('a, 'b, 'c) t + (** The type of one-dimensional big arrays whose elements have + Caml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> ('a, 'b, 'c) t + (** [Array1.create kind layout dim] returns a new bigarray of + one dimension, whose size is [dim]. [kind] and [layout] + determine the array element kind and the array layout + as described for [Genarray.create]. *) + + val dim: ('a, 'b, 'c) t -> int + (** Return the size (dimension) of the given one-dimensional + big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + external get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_ref_1" + (** [Array1.get a x], or alternatively [a.{x}], + returns the element of [a] at index [x]. + [x] must be greater or equal than [0] and strictly less than + [Array1.dim a] if [a] has C layout. If [a] has Fortran layout, + [x] must be greater or equal than [1] and less or equal than + [Array1.dim a]. Otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "%caml_ba_set_1" + (** [Array1.set a x v], also written [a.{x} <- v], + stores the value [v] at index [x] in [a]. + [x] must be inside the bounds of [a] as described in + {!Bigarray.Array1.get}; + otherwise, [Invalid_argument] is raised. *) + + external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t + = "caml_ba_sub" + (** Extract a sub-array of the given one-dimensional big array. + See [Genarray.sub_left] for more details. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See [Genarray.blit] for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See [Genarray.fill] for more details. *) + + val of_array: ('a, 'b) kind -> 'c layout -> 'a array -> ('a, 'b, 'c) t + (** Build a one-dimensional big array initialized from the + given array. *) + + val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout -> + bool -> int -> ('a, 'b, 'c) t + (** Memory mapping of a file as a one-dimensional big array. + See {!Bigarray.Genarray.map_file} for more details. *) + + external unsafe_get: ('a, 'b, 'c) t -> int -> 'a = "%caml_ba_unsafe_ref_1" + (** Like {!Bigarray.Array1.get}, but bounds checking is not always performed. + Use with caution and only when the program logic guarantees that + the access is within bounds. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> 'a -> unit + = "%caml_ba_unsafe_set_1" + (** Like {!Bigarray.Array1.set}, but bounds checking is not always performed. + Use with caution and only when the program logic guarantees that + the access is within bounds. *) + +end + + +(** {6 Two-dimensional arrays} *) + +(** Two-dimensional arrays. The [Array2] structure provides operations + similar to those of {!Bigarray.Genarray}, but specialized to the + case of two-dimensional arrays. *) +module Array2 : + sig + type ('a, 'b, 'c) t + (** The type of two-dimensional big arrays whose elements have + Caml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> int -> ('a, 'b, 'c) t + (** [Array2.create kind layout dim1 dim2] returns a new bigarray of + two dimension, whose size is [dim1] in the first dimension + and [dim2] in the second dimension. [kind] and [layout] + determine the array element kind and the array layout + as described for {!Bigarray.Genarray.create}. *) + + val dim1: ('a, 'b, 'c) t -> int + (** Return the first dimension of the given two-dimensional big array. *) + + val dim2: ('a, 'b, 'c) t -> int + (** Return the second dimension of the given two-dimensional big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%caml_ba_ref_2" + (** [Array2.get a x y], also written [a.{x,y}], + returns the element of [a] at coordinates ([x], [y]). + [x] and [y] must be within the bounds + of [a], as described for {!Bigarray.Genarray.get}; + otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "%caml_ba_set_2" + (** [Array2.set a x y v], or alternatively [a.{x,y} <- v], + stores the value [v] at coordinates ([x], [y]) in [a]. + [x] and [y] must be within the bounds of [a], + as described for {!Bigarray.Genarray.set}; + otherwise, [Invalid_argument] is raised. *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a two-dimensional sub-array of the given two-dimensional + big array by restricting the first dimension. + See {!Bigarray.Genarray.sub_left} for more details. + [Array2.sub_left] applies only to arrays with C layout. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a two-dimensional sub-array of the given two-dimensional + big array by restricting the second dimension. + See {!Bigarray.Genarray.sub_right} for more details. + [Array2.sub_right] applies only to arrays with Fortran layout. *) + + val slice_left: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array1.t + (** Extract a row (one-dimensional slice) of the given two-dimensional + big array. The integer parameter is the index of the row to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array2.slice_left] applies only to arrays with C layout. *) + + val slice_right: + ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array1.t + (** Extract a column (one-dimensional slice) of the given + two-dimensional big array. The integer parameter is the + index of the column to extract. See {!Bigarray.Genarray.slice_right} + for more details. [Array2.slice_right] applies only to arrays + with Fortran layout. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Bigarray.Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Bigarray.Genarray.fill} for more details. *) + + val of_array: ('a, 'b) kind -> 'c layout -> 'a array array -> ('a, 'b, 'c) t + (** Build a two-dimensional big array initialized from the + given array of arrays. *) + + val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout -> + bool -> int -> int -> ('a, 'b, 'c) t + (** Memory mapping of a file as a two-dimensional big array. + See {!Bigarray.Genarray.map_file} for more details. *) + + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> 'a + = "%caml_ba_unsafe_ref_2" + (** Like {!Bigarray.Array2.get}, but bounds checking is not always + performed. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit + = "%caml_ba_unsafe_set_2" + (** Like {!Bigarray.Array2.set}, but bounds checking is not always + performed. *) + +end + +(** {6 Three-dimensional arrays} *) + +(** Three-dimensional arrays. The [Array3] structure provides operations + similar to those of {!Bigarray.Genarray}, but specialized to the case + of three-dimensional arrays. *) +module Array3 : + sig + type ('a, 'b, 'c) t + (** The type of three-dimensional big arrays whose elements have + Caml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> int -> int -> ('a, 'b, 'c) t + (** [Array3.create kind layout dim1 dim2 dim3] returns a new bigarray of + three dimension, whose size is [dim1] in the first dimension, + [dim2] in the second dimension, and [dim3] in the third. + [kind] and [layout] determine the array element kind and + the array layout as described for {!Bigarray.Genarray.create}. *) + + val dim1: ('a, 'b, 'c) t -> int + (** Return the first dimension of the given three-dimensional big array. *) + + val dim2: ('a, 'b, 'c) t -> int + (** Return the second dimension of the given three-dimensional big array. *) + + val dim3: ('a, 'b, 'c) t -> int + (** Return the third dimension of the given three-dimensional big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%caml_ba_ref_3" + (** [Array3.get a x y z], also written [a.{x,y,z}], + returns the element of [a] at coordinates ([x], [y], [z]). + [x], [y] and [z] must be within the bounds of [a], + as described for {!Bigarray.Genarray.get}; + otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "%caml_ba_set_3" + (** [Array3.set a x y v], or alternatively [a.{x,y,z} <- v], + stores the value [v] at coordinates ([x], [y], [z]) in [a]. + [x], [y] and [z] must be within the bounds of [a], + as described for {!Bigarray.Genarray.set}; + otherwise, [Invalid_argument] is raised. *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a three-dimensional sub-array of the given + three-dimensional big array by restricting the first dimension. + See {!Bigarray.Genarray.sub_left} for more details. [Array3.sub_left] + applies only to arrays with C layout. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a three-dimensional sub-array of the given + three-dimensional big array by restricting the second dimension. + See {!Bigarray.Genarray.sub_right} for more details. [Array3.sub_right] + applies only to arrays with Fortran layout. *) + + val slice_left_1: + ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) Array1.t + (** Extract a one-dimensional slice of the given three-dimensional + big array by fixing the first two coordinates. + The integer parameters are the coordinates of the slice to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array3.slice_left_1] applies only to arrays with C layout. *) + + val slice_right_1: + ('a, 'b, fortran_layout) t -> + int -> int -> ('a, 'b, fortran_layout) Array1.t + (** Extract a one-dimensional slice of the given three-dimensional + big array by fixing the last two coordinates. + The integer parameters are the coordinates of the slice to + extract. See {!Bigarray.Genarray.slice_right} for more details. + [Array3.slice_right_1] applies only to arrays with Fortran + layout. *) + + val slice_left_2: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array2.t + (** Extract a two-dimensional slice of the given three-dimensional + big array by fixing the first coordinate. + The integer parameter is the first coordinate of the slice to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array3.slice_left_2] applies only to arrays with C layout. *) + + val slice_right_2: + ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array2.t + (** Extract a two-dimensional slice of the given + three-dimensional big array by fixing the last coordinate. + The integer parameter is the coordinate of the slice + to extract. See {!Bigarray.Genarray.slice_right} for more details. + [Array3.slice_right_2] applies only to arrays with Fortran + layout. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Bigarray.Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Bigarray.Genarray.fill} for more details. *) + + val of_array: + ('a, 'b) kind -> 'c layout -> 'a array array array -> ('a, 'b, 'c) t + (** Build a three-dimensional big array initialized from the + given array of arrays of arrays. *) + + val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout -> + bool -> int -> int -> int -> ('a, 'b, 'c) t + (** Memory mapping of a file as a three-dimensional big array. + See {!Bigarray.Genarray.map_file} for more details. *) + + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> int -> 'a + = "%caml_ba_unsafe_ref_3" + (** Like {!Bigarray.Array3.get}, but bounds checking is not always + performed. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "%caml_ba_unsafe_set_3" + (** Like {!Bigarray.Array3.set}, but bounds checking is not always + performed. *) + +end + +(** {6 Coercions between generic big arrays and fixed-dimension big arrays} *) + +external genarray_of_array1 : + ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given one-dimensional + big array. *) + +external genarray_of_array2 : + ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given two-dimensional + big array. *) + +external genarray_of_array3 : + ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given three-dimensional + big array. *) + +val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t +(** Return the one-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly one dimension. *) + +val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t +(** Return the two-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly two dimensions. *) + +val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t +(** Return the three-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly three dimensions. *) + + +(** {6 Re-shaping big arrays} *) + +val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t +(** [reshape b [|d1;...;dN|]] converts the big array [b] to a + [N]-dimensional array of dimensions [d1]...[dN]. The returned + array and the original array [b] share their data + and have the same layout. For instance, assuming that [b] + is a one-dimensional array of dimension 12, [reshape b [|3;4|]] + returns a two-dimensional array [b'] of dimensions 3 and 4. + If [b] has C layout, the element [(x,y)] of [b'] corresponds + to the element [x * 3 + y] of [b]. If [b] has Fortran layout, + the element [(x,y)] of [b'] corresponds to the element + [x + (y - 1) * 4] of [b]. + The returned big array must have exactly the same number of + elements as the original big array [b]. That is, the product + of the dimensions of [b] must be equal to [i1 * ... * iN]. + Otherwise, [Invalid_argument] is raised. *) + +val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + one-dimensional arrays. *) + +val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + two-dimensional arrays. *) + +val reshape_3 : + ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + three-dimensional arrays. *) diff --git a/otherlibs/bigarray/bigarray_stubs.c b/otherlibs/bigarray/bigarray_stubs.c new file mode 100644 index 0000000..118c6a9 --- /dev/null +++ b/otherlibs/bigarray/bigarray_stubs.c @@ -0,0 +1,1083 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bigarray_stubs.c,v 1.24 2008-12-03 18:09:09 doligez Exp $ */ + +#include <stddef.h> +#include <stdarg.h> +#include <string.h> +#include "alloc.h" +#include "bigarray.h" +#include "custom.h" +#include "fail.h" +#include "intext.h" +#include "memory.h" +#include "mlvalues.h" + +#define int8 caml_ba_int8 +#define uint8 caml_ba_uint8 +#define int16 caml_ba_int16 +#define uint16 caml_ba_uint16 + +extern void caml_ba_unmap_file(void * addr, uintnat len); + /* from mmap_xxx.c */ + +/* Compute the number of elements of a big array */ + +static uintnat caml_ba_num_elts(struct caml_ba_array * b) +{ + uintnat num_elts; + int i; + num_elts = 1; + for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; + return num_elts; +} + +/* Size in bytes of a bigarray element, indexed by bigarray kind */ + +int caml_ba_element_size[] = +{ 4 /*FLOAT32*/, 8 /*FLOAT64*/, + 1 /*SINT8*/, 1 /*UINT8*/, + 2 /*SINT16*/, 2 /*UINT16*/, + 4 /*INT32*/, 8 /*INT64*/, + sizeof(value) /*CAML_INT*/, sizeof(value) /*NATIVE_INT*/, + 8 /*COMPLEX32*/, 16 /*COMPLEX64*/ +}; + +/* Compute the number of bytes for the elements of a big array */ + +CAMLexport uintnat caml_ba_byte_size(struct caml_ba_array * b) +{ + return caml_ba_num_elts(b) + * caml_ba_element_size[b->flags & CAML_BA_KIND_MASK]; +} + +/* Operation table for bigarrays */ + +static void caml_ba_finalize(value v); +static int caml_ba_compare(value v1, value v2); +static intnat caml_ba_hash(value v); +static void caml_ba_serialize(value, uintnat *, uintnat *); +uintnat caml_ba_deserialize(void * dst); +static struct custom_operations caml_ba_ops = { + "_bigarray", + caml_ba_finalize, + caml_ba_compare, + caml_ba_hash, + caml_ba_serialize, + caml_ba_deserialize +}; + +/* Multiplication of unsigned longs with overflow detection */ + +static uintnat +caml_ba_multov(uintnat a, uintnat b, int * overflow) +{ +#define HALF_SIZE (sizeof(uintnat) * 4) +#define HALF_MASK (((uintnat)1 << HALF_SIZE) - 1) +#define LOW_HALF(x) ((x) & HALF_MASK) +#define HIGH_HALF(x) ((x) >> HALF_SIZE) + /* Cut in half words */ + uintnat al = LOW_HALF(a); + uintnat ah = HIGH_HALF(a); + uintnat bl = LOW_HALF(b); + uintnat bh = HIGH_HALF(b); + /* Exact product is: + al * bl + + ah * bl << HALF_SIZE + + al * bh << HALF_SIZE + + ah * bh << 2*HALF_SIZE + Overflow occurs if: + ah * bh is not 0, i.e. ah != 0 and bh != 0 + OR ah * bl has high half != 0 + OR ah * bl has high half != 0 + OR the sum al * bl + LOW_HALF(ah * bl) << HALF_SIZE + + LOW_HALF(al * bh) << HALF_SIZE overflows. + This sum is equal to p = (a * b) modulo word size. */ + uintnat p1 = al * bh; + uintnat p2 = ah * bl; + uintnat p = a * b; + if (ah != 0 && bh != 0) *overflow = 1; + if (HIGH_HALF(p1) != 0 || HIGH_HALF(p2) != 0) *overflow = 1; + p1 <<= HALF_SIZE; + p2 <<= HALF_SIZE; + p1 += p2; + if (p < p1 || p1 < p2) *overflow = 1; /* overflow in sums */ + return p; +#undef HALF_SIZE +#undef LOW_HALF +#undef HIGH_HALF +} + +/* Allocation of a big array */ + +#define CAML_BA_MAX_MEMORY 256*1024*1024 +/* 256 Mb -- after allocating that much, it's probably worth speeding + up the major GC */ + +/* [caml_ba_alloc] will allocate a new bigarray object in the heap. + If [data] is NULL, the memory for the contents is also allocated + (with [malloc]) by [caml_ba_alloc]. + [data] cannot point into the Caml heap. + [dim] may point into an object in the Caml heap. +*/ +CAMLexport value +caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim) +{ + uintnat num_elts, size; + int overflow, i; + value res; + struct caml_ba_array * b; + intnat dimcopy[CAML_BA_MAX_NUM_DIMS]; + + Assert(num_dims >= 1 && num_dims <= CAML_BA_MAX_NUM_DIMS); + Assert((flags & CAML_BA_KIND_MASK) <= CAML_BA_COMPLEX64); + for (i = 0; i < num_dims; i++) dimcopy[i] = dim[i]; + size = 0; + if (data == NULL) { + overflow = 0; + num_elts = 1; + for (i = 0; i < num_dims; i++) { + num_elts = caml_ba_multov(num_elts, dimcopy[i], &overflow); + } + size = caml_ba_multov(num_elts, + caml_ba_element_size[flags & CAML_BA_KIND_MASK], + &overflow); + if (overflow) caml_raise_out_of_memory(); + data = malloc(size); + if (data == NULL && size != 0) caml_raise_out_of_memory(); + flags |= CAML_BA_MANAGED; + } + res = caml_alloc_custom(&caml_ba_ops, + sizeof(struct caml_ba_array) + + (num_dims - 1) * sizeof(intnat), + size, CAML_BA_MAX_MEMORY); + b = Caml_ba_array_val(res); + b->data = data; + b->num_dims = num_dims; + b->flags = flags; + b->proxy = NULL; + for (i = 0; i < num_dims; i++) b->dim[i] = dimcopy[i]; + return res; +} + +/* Same as caml_ba_alloc, but dimensions are passed as a list of + arguments */ + +CAMLexport value caml_ba_alloc_dims(int flags, int num_dims, void * data, ...) +{ + va_list ap; + intnat dim[CAML_BA_MAX_NUM_DIMS]; + int i; + value res; + + va_start(ap, data); + for (i = 0; i < num_dims; i++) dim[i] = va_arg(ap, intnat); + va_end(ap); + res = caml_ba_alloc(flags, num_dims, data, dim); + return res; +} + +/* Allocate a bigarray from Caml */ + +CAMLprim value caml_ba_create(value vkind, value vlayout, value vdim) +{ + intnat dim[CAML_BA_MAX_NUM_DIMS]; + mlsize_t num_dims; + int i, flags; + + num_dims = Wosize_val(vdim); + if (num_dims < 1 || num_dims > CAML_BA_MAX_NUM_DIMS) + caml_invalid_argument("Bigarray.create: bad number of dimensions"); + for (i = 0; i < num_dims; i++) { + dim[i] = Long_val(Field(vdim, i)); + if (dim[i] < 0) + caml_invalid_argument("Bigarray.create: negative dimension"); + } + flags = Int_val(vkind) | Int_val(vlayout); + return caml_ba_alloc(flags, num_dims, NULL, dim); +} + +/* Given a big array and a vector of indices, check that the indices + are within the bounds and return the offset of the corresponding + array element in the data part of the array. */ + +static long caml_ba_offset(struct caml_ba_array * b, intnat * index) +{ + intnat offset; + int i; + + offset = 0; + if ((b->flags & CAML_BA_LAYOUT_MASK) == CAML_BA_C_LAYOUT) { + /* C-style layout: row major, indices start at 0 */ + for (i = 0; i < b->num_dims; i++) { + if ((uintnat) index[i] >= (uintnat) b->dim[i]) + caml_array_bound_error(); + offset = offset * b->dim[i] + index[i]; + } + } else { + /* Fortran-style layout: column major, indices start at 1 */ + for (i = b->num_dims - 1; i >= 0; i--) { + if ((uintnat) (index[i] - 1) >= (uintnat) b->dim[i]) + caml_array_bound_error(); + offset = offset * b->dim[i] + (index[i] - 1); + } + } + return offset; +} + +/* Helper function to allocate a record of two double floats */ + +static value copy_two_doubles(double d0, double d1) +{ + value res = caml_alloc_small(2 * Double_wosize, Double_array_tag); + Store_double_field(res, 0, d0); + Store_double_field(res, 1, d1); + return res; +} + +/* Generic code to read from a big array */ + +value caml_ba_get_N(value vb, value * vind, int nind) +{ + struct caml_ba_array * b = Caml_ba_array_val(vb); + intnat index[CAML_BA_MAX_NUM_DIMS]; + int i; + intnat offset; + + /* Check number of indices = number of dimensions of array + (maybe not necessary if ML typing guarantees this) */ + if (nind != b->num_dims) + caml_invalid_argument("Bigarray.get: wrong number of indices"); + /* Compute offset and check bounds */ + for (i = 0; i < b->num_dims; i++) index[i] = Long_val(vind[i]); + offset = caml_ba_offset(b, index); + /* Perform read */ + switch ((b->flags) & CAML_BA_KIND_MASK) { + default: + Assert(0); + case CAML_BA_FLOAT32: + return caml_copy_double(((float *) b->data)[offset]); + case CAML_BA_FLOAT64: + return caml_copy_double(((double *) b->data)[offset]); + case CAML_BA_SINT8: + return Val_int(((int8 *) b->data)[offset]); + case CAML_BA_UINT8: + return Val_int(((uint8 *) b->data)[offset]); + case CAML_BA_SINT16: + return Val_int(((int16 *) b->data)[offset]); + case CAML_BA_UINT16: + return Val_int(((uint16 *) b->data)[offset]); + case CAML_BA_INT32: + return caml_copy_int32(((int32 *) b->data)[offset]); + case CAML_BA_INT64: + return caml_copy_int64(((int64 *) b->data)[offset]); + case CAML_BA_NATIVE_INT: + return caml_copy_nativeint(((intnat *) b->data)[offset]); + case CAML_BA_CAML_INT: + return Val_long(((intnat *) b->data)[offset]); + case CAML_BA_COMPLEX32: + { float * p = ((float *) b->data) + offset * 2; + return copy_two_doubles(p[0], p[1]); } + case CAML_BA_COMPLEX64: + { double * p = ((double *) b->data) + offset * 2; + return copy_two_doubles(p[0], p[1]); } + } +} + +CAMLprim value caml_ba_get_1(value vb, value vind1) +{ + return caml_ba_get_N(vb, &vind1, 1); +} + +CAMLprim value caml_ba_get_2(value vb, value vind1, value vind2) +{ + value vind[2]; + vind[0] = vind1; vind[1] = vind2; + return caml_ba_get_N(vb, vind, 2); +} + +CAMLprim value caml_ba_get_3(value vb, value vind1, value vind2, value vind3) +{ + value vind[3]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + return caml_ba_get_N(vb, vind, 3); +} + +#if 0 +CAMLprim value caml_ba_get_4(value vb, value vind1, value vind2, + value vind3, value vind4) +{ + value vind[4]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; vind[3] = vind4; + return caml_ba_get_N(vb, vind, 4); +} + +CAMLprim value caml_ba_get_5(value vb, value vind1, value vind2, + value vind3, value vind4, value vind5) +{ + value vind[5]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + vind[3] = vind4; vind[4] = vind5; + return caml_ba_get_N(vb, vind, 5); +} + +CAMLprim value caml_ba_get_6(value vb, value vind1, value vind2, + value vind3, value vind4, value vind5, value vind6) +{ + value vind[6]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + vind[3] = vind4; vind[4] = vind5; vind[5] = vind6; + return caml_ba_get_N(vb, vind, 6); +} +#endif + +CAMLprim value caml_ba_get_generic(value vb, value vind) +{ + return caml_ba_get_N(vb, &Field(vind, 0), Wosize_val(vind)); +} + +/* Generic write to a big array */ + +static value caml_ba_set_aux(value vb, value * vind, intnat nind, value newval) +{ + struct caml_ba_array * b = Caml_ba_array_val(vb); + intnat index[CAML_BA_MAX_NUM_DIMS]; + int i; + intnat offset; + + /* Check number of indices = number of dimensions of array + (maybe not necessary if ML typing guarantees this) */ + if (nind != b->num_dims) + caml_invalid_argument("Bigarray.set: wrong number of indices"); + /* Compute offset and check bounds */ + for (i = 0; i < b->num_dims; i++) index[i] = Long_val(vind[i]); + offset = caml_ba_offset(b, index); + /* Perform write */ + switch (b->flags & CAML_BA_KIND_MASK) { + default: + Assert(0); + case CAML_BA_FLOAT32: + ((float *) b->data)[offset] = Double_val(newval); break; + case CAML_BA_FLOAT64: + ((double *) b->data)[offset] = Double_val(newval); break; + case CAML_BA_SINT8: + case CAML_BA_UINT8: + ((int8 *) b->data)[offset] = Int_val(newval); break; + case CAML_BA_SINT16: + case CAML_BA_UINT16: + ((int16 *) b->data)[offset] = Int_val(newval); break; + case CAML_BA_INT32: + ((int32 *) b->data)[offset] = Int32_val(newval); break; + case CAML_BA_INT64: + ((int64 *) b->data)[offset] = Int64_val(newval); break; + case CAML_BA_NATIVE_INT: + ((intnat *) b->data)[offset] = Nativeint_val(newval); break; + case CAML_BA_CAML_INT: + ((intnat *) b->data)[offset] = Long_val(newval); break; + case CAML_BA_COMPLEX32: + { float * p = ((float *) b->data) + offset * 2; + p[0] = Double_field(newval, 0); + p[1] = Double_field(newval, 1); + break; } + case CAML_BA_COMPLEX64: + { double * p = ((double *) b->data) + offset * 2; + p[0] = Double_field(newval, 0); + p[1] = Double_field(newval, 1); + break; } + } + return Val_unit; +} + +CAMLprim value caml_ba_set_1(value vb, value vind1, value newval) +{ + return caml_ba_set_aux(vb, &vind1, 1, newval); +} + +CAMLprim value caml_ba_set_2(value vb, value vind1, value vind2, value newval) +{ + value vind[2]; + vind[0] = vind1; vind[1] = vind2; + return caml_ba_set_aux(vb, vind, 2, newval); +} + +CAMLprim value caml_ba_set_3(value vb, value vind1, value vind2, value vind3, + value newval) +{ + value vind[3]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + return caml_ba_set_aux(vb, vind, 3, newval); +} + +#if 0 +CAMLprim value caml_ba_set_4(value vb, value vind1, value vind2, + value vind3, value vind4, value newval) +{ + value vind[4]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; vind[3] = vind4; + return caml_ba_set_aux(vb, vind, 4, newval); +} + +CAMLprim value caml_ba_set_5(value vb, value vind1, value vind2, + value vind3, value vind4, value vind5, value newval) +{ + value vind[5]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + vind[3] = vind4; vind[4] = vind5; + return caml_ba_set_aux(vb, vind, 5, newval); +} + +CAMLprim value caml_ba_set_6(value vb, value vind1, value vind2, + value vind3, value vind4, value vind5, + value vind6, value newval) +{ + value vind[6]; + vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; + vind[3] = vind4; vind[4] = vind5; vind[5] = vind6; + return caml_ba_set_aux(vb, vind, 6, newval); +} + +value caml_ba_set_N(value vb, value * vind, int nargs) +{ + return caml_ba_set_aux(vb, vind, nargs - 1, vind[nargs - 1]); +} +#endif + +CAMLprim value caml_ba_set_generic(value vb, value vind, value newval) +{ + return caml_ba_set_aux(vb, &Field(vind, 0), Wosize_val(vind), newval); +} + +/* Return the number of dimensions of a big array */ + +CAMLprim value caml_ba_num_dims(value vb) +{ + struct caml_ba_array * b = Caml_ba_array_val(vb); + return Val_long(b->num_dims); +} + +/* Return the n-th dimension of a big array */ + +CAMLprim value caml_ba_dim(value vb, value vn) +{ + struct caml_ba_array * b = Caml_ba_array_val(vb); + intnat n = Long_val(vn); + if (n >= b->num_dims) caml_invalid_argument("Bigarray.dim"); + return Val_long(b->dim[n]); +} + +/* Return the kind of a big array */ + +CAMLprim value caml_ba_kind(value vb) +{ + return Val_int(Caml_ba_array_val(vb)->flags & CAML_BA_KIND_MASK); +} + +/* Return the layout of a big array */ + +CAMLprim value caml_ba_layout(value vb) +{ + return Val_int(Caml_ba_array_val(vb)->flags & CAML_BA_LAYOUT_MASK); +} + +/* Finalization of a big array */ + +static void caml_ba_finalize(value v) +{ + struct caml_ba_array * b = Caml_ba_array_val(v); + + switch (b->flags & CAML_BA_MANAGED_MASK) { + case CAML_BA_EXTERNAL: + break; + case CAML_BA_MANAGED: + if (b->proxy == NULL) { + free(b->data); + } else { + if (-- b->proxy->refcount == 0) { + free(b->proxy->data); + caml_stat_free(b->proxy); + } + } + break; + case CAML_BA_MAPPED_FILE: + if (b->proxy == NULL) { + caml_ba_unmap_file(b->data, caml_ba_byte_size(b)); + } else { + if (-- b->proxy->refcount == 0) { + caml_ba_unmap_file(b->proxy->data, b->proxy->size); + caml_stat_free(b->proxy); + } + } + break; + } +} + +/* Comparison of two big arrays */ + +static int caml_ba_compare(value v1, value v2) +{ + struct caml_ba_array * b1 = Caml_ba_array_val(v1); + struct caml_ba_array * b2 = Caml_ba_array_val(v2); + uintnat n, num_elts; + int i; + + /* Compare number of dimensions */ + if (b1->num_dims != b2->num_dims) return b2->num_dims - b1->num_dims; + /* Same number of dimensions: compare dimensions lexicographically */ + for (i = 0; i < b1->num_dims; i++) { + intnat d1 = b1->dim[i]; + intnat d2 = b2->dim[i]; + if (d1 != d2) return d1 < d2 ? -1 : 1; + } + /* Same dimensions: compare contents lexicographically */ + num_elts = caml_ba_num_elts(b1); + +#define DO_INTEGER_COMPARISON(type) \ + { type * p1 = b1->data; type * p2 = b2->data; \ + for (n = 0; n < num_elts; n++) { \ + type e1 = *p1++; type e2 = *p2++; \ + if (e1 < e2) return -1; \ + if (e1 > e2) return 1; \ + } \ + return 0; \ + } +#define DO_FLOAT_COMPARISON(type) \ + { type * p1 = b1->data; type * p2 = b2->data; \ + for (n = 0; n < num_elts; n++) { \ + type e1 = *p1++; type e2 = *p2++; \ + if (e1 < e2) return -1; \ + if (e1 > e2) return 1; \ + if (e1 != e2) { \ + caml_compare_unordered = 1; \ + if (e1 == e1) return 1; \ + if (e2 == e2) return -1; \ + } \ + } \ + return 0; \ + } + + switch (b1->flags & CAML_BA_KIND_MASK) { + case CAML_BA_COMPLEX32: + num_elts *= 2; /*fallthrough*/ + case CAML_BA_FLOAT32: + DO_FLOAT_COMPARISON(float); + case CAML_BA_COMPLEX64: + num_elts *= 2; /*fallthrough*/ + case CAML_BA_FLOAT64: + DO_FLOAT_COMPARISON(double); + case CAML_BA_SINT8: + DO_INTEGER_COMPARISON(int8); + case CAML_BA_UINT8: + DO_INTEGER_COMPARISON(uint8); + case CAML_BA_SINT16: + DO_INTEGER_COMPARISON(int16); + case CAML_BA_UINT16: + DO_INTEGER_COMPARISON(uint16); + case CAML_BA_INT32: + DO_INTEGER_COMPARISON(int32); + case CAML_BA_INT64: +#ifdef ARCH_INT64_TYPE + DO_INTEGER_COMPARISON(int64); +#else + { int64 * p1 = b1->data; int64 * p2 = b2->data; + for (n = 0; n < num_elts; n++) { + int64 e1 = *p1++; int64 e2 = *p2++; + if ((int32)e1.h > (int32)e2.h) return 1; + if ((int32)e1.h < (int32)e2.h) return -1; + if (e1.l > e2.l) return 1; + if (e1.l < e2.l) return -1; + } + return 0; + } +#endif + case CAML_BA_CAML_INT: + case CAML_BA_NATIVE_INT: + DO_INTEGER_COMPARISON(intnat); + default: + Assert(0); + return 0; /* should not happen */ + } +#undef DO_INTEGER_COMPARISON +#undef DO_FLOAT_COMPARISON +} + +/* Hashing of a bigarray */ + +static intnat caml_ba_hash(value v) +{ + struct caml_ba_array * b = Caml_ba_array_val(v); + intnat num_elts, n, h; + int i; + + num_elts = 1; + for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; + if (num_elts >= 50) num_elts = 50; + h = 0; + +#define COMBINE(h,v) ((h << 4) + h + (v)) + + switch (b->flags & CAML_BA_KIND_MASK) { + case CAML_BA_SINT8: + case CAML_BA_UINT8: { + uint8 * p = b->data; + for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); + break; + } + case CAML_BA_SINT16: + case CAML_BA_UINT16: { + uint16 * p = b->data; + for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); + break; + } + case CAML_BA_FLOAT32: + case CAML_BA_COMPLEX32: + case CAML_BA_INT32: +#ifndef ARCH_SIXTYFOUR + case CAML_BA_CAML_INT: + case CAML_BA_NATIVE_INT: +#endif + { + uint32 * p = b->data; + for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); + break; + } + case CAML_BA_FLOAT64: + case CAML_BA_COMPLEX64: + case CAML_BA_INT64: +#ifdef ARCH_SIXTYFOUR + case CAML_BA_CAML_INT: + case CAML_BA_NATIVE_INT: +#endif +#ifdef ARCH_SIXTYFOUR + { + uintnat * p = b->data; + for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); + break; + } +#else + { + uint32 * p = b->data; + for (n = 0; n < num_elts; n++) { +#ifdef ARCH_BIG_ENDIAN + h = COMBINE(h, p[1]); h = COMBINE(h, p[0]); p += 2; +#else + h = COMBINE(h, p[0]); h = COMBINE(h, p[1]); p += 2; +#endif + } + break; + } +#endif + } +#undef COMBINE + return h; +} + +static void caml_ba_serialize_longarray(void * data, + intnat num_elts, + intnat min_val, intnat max_val) +{ +#ifdef ARCH_SIXTYFOUR + int overflow_32 = 0; + intnat * p, n; + for (n = 0, p = data; n < num_elts; n++, p++) { + if (*p < min_val || *p > max_val) { overflow_32 = 1; break; } + } + if (overflow_32) { + caml_serialize_int_1(1); + caml_serialize_block_8(data, num_elts); + } else { + caml_serialize_int_1(0); + for (n = 0, p = data; n < num_elts; n++, p++) + caml_serialize_int_4((int32) *p); + } +#else + caml_serialize_int_1(0); + caml_serialize_block_4(data, num_elts); +#endif +} + +static void caml_ba_serialize(value v, + uintnat * wsize_32, + uintnat * wsize_64) +{ + struct caml_ba_array * b = Caml_ba_array_val(v); + intnat num_elts; + int i; + + /* Serialize header information */ + caml_serialize_int_4(b->num_dims); + caml_serialize_int_4(b->flags & (CAML_BA_KIND_MASK | CAML_BA_LAYOUT_MASK)); + /* On a 64-bit machine, if any of the dimensions is >= 2^32, + the size of the marshaled data will be >= 2^32 and + extern_value() will fail. So, it is safe to write the dimensions + as 32-bit unsigned integers. */ + for (i = 0; i < b->num_dims; i++) caml_serialize_int_4(b->dim[i]); + /* Compute total number of elements */ + num_elts = 1; + for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; + /* Serialize elements */ + switch (b->flags & CAML_BA_KIND_MASK) { + case CAML_BA_SINT8: + case CAML_BA_UINT8: + caml_serialize_block_1(b->data, num_elts); break; + case CAML_BA_SINT16: + case CAML_BA_UINT16: + caml_serialize_block_2(b->data, num_elts); break; + case CAML_BA_FLOAT32: + case CAML_BA_INT32: + caml_serialize_block_4(b->data, num_elts); break; + case CAML_BA_COMPLEX32: + caml_serialize_block_4(b->data, num_elts * 2); break; + case CAML_BA_FLOAT64: + case CAML_BA_INT64: + caml_serialize_block_8(b->data, num_elts); break; + case CAML_BA_COMPLEX64: + caml_serialize_block_8(b->data, num_elts * 2); break; + case CAML_BA_CAML_INT: + caml_ba_serialize_longarray(b->data, num_elts, -0x40000000, 0x3FFFFFFF); + break; + case CAML_BA_NATIVE_INT: + caml_ba_serialize_longarray(b->data, num_elts, -0x80000000, 0x7FFFFFFF); + break; + } + /* Compute required size in Caml heap. Assumes struct caml_ba_array + is exactly 4 + num_dims words */ + Assert(sizeof(struct caml_ba_array) == 5 * sizeof(value)); + *wsize_32 = (4 + b->num_dims) * 4; + *wsize_64 = (4 + b->num_dims) * 8; +} + +static void caml_ba_deserialize_longarray(void * dest, intnat num_elts) +{ + int sixty = caml_deserialize_uint_1(); +#ifdef ARCH_SIXTYFOUR + if (sixty) { + caml_deserialize_block_8(dest, num_elts); + } else { + intnat * p, n; + for (n = 0, p = dest; n < num_elts; n++, p++) + *p = caml_deserialize_sint_4(); + } +#else + if (sixty) + caml_deserialize_error("input_value: cannot read bigarray " + "with 64-bit Caml ints"); + caml_deserialize_block_4(dest, num_elts); +#endif +} + +uintnat caml_ba_deserialize(void * dst) +{ + struct caml_ba_array * b = dst; + int i, elt_size; + uintnat num_elts; + + /* Read back header information */ + b->num_dims = caml_deserialize_uint_4(); + b->flags = caml_deserialize_uint_4() | CAML_BA_MANAGED; + b->proxy = NULL; + for (i = 0; i < b->num_dims; i++) b->dim[i] = caml_deserialize_uint_4(); + /* Compute total number of elements */ + num_elts = caml_ba_num_elts(b); + /* Determine element size in bytes */ + if ((b->flags & CAML_BA_KIND_MASK) > CAML_BA_COMPLEX64) + caml_deserialize_error("input_value: bad bigarray kind"); + elt_size = caml_ba_element_size[b->flags & CAML_BA_KIND_MASK]; + /* Allocate room for data */ + b->data = malloc(elt_size * num_elts); + if (b->data == NULL) + caml_deserialize_error("input_value: out of memory for bigarray"); + /* Read data */ + switch (b->flags & CAML_BA_KIND_MASK) { + case CAML_BA_SINT8: + case CAML_BA_UINT8: + caml_deserialize_block_1(b->data, num_elts); break; + case CAML_BA_SINT16: + case CAML_BA_UINT16: + caml_deserialize_block_2(b->data, num_elts); break; + case CAML_BA_FLOAT32: + case CAML_BA_INT32: + caml_deserialize_block_4(b->data, num_elts); break; + case CAML_BA_COMPLEX32: + caml_deserialize_block_4(b->data, num_elts * 2); break; + case CAML_BA_FLOAT64: + case CAML_BA_INT64: + caml_deserialize_block_8(b->data, num_elts); break; + case CAML_BA_COMPLEX64: + caml_deserialize_block_8(b->data, num_elts * 2); break; + case CAML_BA_CAML_INT: + case CAML_BA_NATIVE_INT: + caml_ba_deserialize_longarray(b->data, num_elts); break; + } + return sizeof(struct caml_ba_array) + (b->num_dims - 1) * sizeof(intnat); +} + +/* Create / update proxy to indicate that b2 is a sub-array of b1 */ + +static void caml_ba_update_proxy(struct caml_ba_array * b1, + struct caml_ba_array * b2) +{ + struct caml_ba_proxy * proxy; + /* Nothing to do for un-managed arrays */ + if ((b1->flags & CAML_BA_MANAGED_MASK) == CAML_BA_EXTERNAL) return; + if (b1->proxy != NULL) { + /* If b1 is already a proxy for a larger array, increment refcount of + proxy */ + b2->proxy = b1->proxy; + ++ b1->proxy->refcount; + } else { + /* Otherwise, create proxy and attach it to both b1 and b2 */ + proxy = caml_stat_alloc(sizeof(struct caml_ba_proxy)); + proxy->refcount = 2; /* original array + sub array */ + proxy->data = b1->data; + proxy->size = + b1->flags & CAML_BA_MAPPED_FILE ? caml_ba_byte_size(b1) : 0; + b1->proxy = proxy; + b2->proxy = proxy; + } +} + +/* Slicing */ + +CAMLprim value caml_ba_slice(value vb, value vind) +{ + CAMLparam2 (vb, vind); + #define b ((struct caml_ba_array *) Caml_ba_array_val(vb)) + CAMLlocal1 (res); + intnat index[CAML_BA_MAX_NUM_DIMS]; + int num_inds, i; + intnat offset; + intnat * sub_dims; + char * sub_data; + + /* Check number of indices < number of dimensions of array */ + num_inds = Wosize_val(vind); + if (num_inds >= b->num_dims) + caml_invalid_argument("Bigarray.slice: too many indices"); + /* Compute offset and check bounds */ + if ((b->flags & CAML_BA_LAYOUT_MASK) == CAML_BA_C_LAYOUT) { + /* We slice from the left */ + for (i = 0; i < num_inds; i++) index[i] = Long_val(Field(vind, i)); + for (/*nothing*/; i < b->num_dims; i++) index[i] = 0; + offset = caml_ba_offset(b, index); + sub_dims = b->dim + num_inds; + } else { + /* We slice from the right */ + for (i = 0; i < num_inds; i++) + index[b->num_dims - num_inds + i] = Long_val(Field(vind, i)); + for (i = 0; i < b->num_dims - num_inds; i++) index[i] = 1; + offset = caml_ba_offset(b, index); + sub_dims = b->dim; + } + sub_data = + (char *) b->data + + offset * caml_ba_element_size[b->flags & CAML_BA_KIND_MASK]; + /* Allocate a Caml bigarray to hold the result */ + res = caml_ba_alloc(b->flags, b->num_dims - num_inds, sub_data, sub_dims); + /* Create or update proxy in case of managed bigarray */ + caml_ba_update_proxy(b, Caml_ba_array_val(res)); + /* Return result */ + CAMLreturn (res); + + #undef b +} + +/* Extracting a sub-array of same number of dimensions */ + +CAMLprim value caml_ba_sub(value vb, value vofs, value vlen) +{ + CAMLparam3 (vb, vofs, vlen); + CAMLlocal1 (res); + #define b ((struct caml_ba_array *) Caml_ba_array_val(vb)) + intnat ofs = Long_val(vofs); + intnat len = Long_val(vlen); + int i, changed_dim; + intnat mul; + char * sub_data; + + /* Compute offset and check bounds */ + if ((b->flags & CAML_BA_LAYOUT_MASK) == CAML_BA_C_LAYOUT) { + /* We reduce the first dimension */ + mul = 1; + for (i = 1; i < b->num_dims; i++) mul *= b->dim[i]; + changed_dim = 0; + } else { + /* We reduce the last dimension */ + mul = 1; + for (i = 0; i < b->num_dims - 1; i++) mul *= b->dim[i]; + changed_dim = b->num_dims - 1; + ofs--; /* Fortran arrays start at 1 */ + } + if (ofs < 0 || len < 0 || ofs + len > b->dim[changed_dim]) + caml_invalid_argument("Bigarray.sub: bad sub-array"); + sub_data = + (char *) b->data + + ofs * mul * caml_ba_element_size[b->flags & CAML_BA_KIND_MASK]; + /* Allocate a Caml bigarray to hold the result */ + res = caml_ba_alloc(b->flags, b->num_dims, sub_data, b->dim); + /* Doctor the changed dimension */ + Caml_ba_array_val(res)->dim[changed_dim] = len; + /* Create or update proxy in case of managed bigarray */ + caml_ba_update_proxy(b, Caml_ba_array_val(res)); + /* Return result */ + CAMLreturn (res); + + #undef b +} + +/* Copying a big array into another one */ + +CAMLprim value caml_ba_blit(value vsrc, value vdst) +{ + struct caml_ba_array * src = Caml_ba_array_val(vsrc); + struct caml_ba_array * dst = Caml_ba_array_val(vdst); + int i; + intnat num_bytes; + + /* Check same numbers of dimensions and same dimensions */ + if (src->num_dims != dst->num_dims) goto blit_error; + for (i = 0; i < src->num_dims; i++) + if (src->dim[i] != dst->dim[i]) goto blit_error; + /* Compute number of bytes in array data */ + num_bytes = + caml_ba_num_elts(src) + * caml_ba_element_size[src->flags & CAML_BA_KIND_MASK]; + /* Do the copying */ + memmove (dst->data, src->data, num_bytes); + return Val_unit; + blit_error: + caml_invalid_argument("Bigarray.blit: dimension mismatch"); + return Val_unit; /* not reached */ +} + +/* Filling a big array with a given value */ + +CAMLprim value caml_ba_fill(value vb, value vinit) +{ + struct caml_ba_array * b = Caml_ba_array_val(vb); + intnat num_elts = caml_ba_num_elts(b); + + switch (b->flags & CAML_BA_KIND_MASK) { + default: + Assert(0); + case CAML_BA_FLOAT32: { + float init = Double_val(vinit); + float * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_FLOAT64: { + double init = Double_val(vinit); + double * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_SINT8: + case CAML_BA_UINT8: { + int init = Int_val(vinit); + char * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_SINT16: + case CAML_BA_UINT16: { + int init = Int_val(vinit); + int16 * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_INT32: { + int32 init = Int32_val(vinit); + int32 * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_INT64: { + int64 init = Int64_val(vinit); + int64 * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_NATIVE_INT: { + intnat init = Nativeint_val(vinit); + intnat * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_CAML_INT: { + intnat init = Long_val(vinit); + intnat * p; + for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; + break; + } + case CAML_BA_COMPLEX32: { + float init0 = Double_field(vinit, 0); + float init1 = Double_field(vinit, 1); + float * p; + for (p = b->data; num_elts > 0; num_elts--) { *p++ = init0; *p++ = init1; } + break; + } + case CAML_BA_COMPLEX64: { + double init0 = Double_field(vinit, 0); + double init1 = Double_field(vinit, 1); + double * p; + for (p = b->data; num_elts > 0; num_elts--) { *p++ = init0; *p++ = init1; } + break; + } + } + return Val_unit; +} + +/* Reshape an array: change dimensions and number of dimensions, preserving + array contents */ + +CAMLprim value caml_ba_reshape(value vb, value vdim) +{ + CAMLparam2 (vb, vdim); + CAMLlocal1 (res); +#define b ((struct caml_ba_array *) Caml_ba_array_val(vb)) + intnat dim[CAML_BA_MAX_NUM_DIMS]; + mlsize_t num_dims; + uintnat num_elts; + int i; + + num_dims = Wosize_val(vdim); + if (num_dims < 1 || num_dims > CAML_BA_MAX_NUM_DIMS) + caml_invalid_argument("Bigarray.reshape: bad number of dimensions"); + num_elts = 1; + for (i = 0; i < num_dims; i++) { + dim[i] = Long_val(Field(vdim, i)); + if (dim[i] < 0 || dim[i] > 0x7FFFFFFFL) + caml_invalid_argument("Bigarray.reshape: negative dimension"); + num_elts *= dim[i]; + } + /* Check that sizes agree */ + if (num_elts != caml_ba_num_elts(b)) + caml_invalid_argument("Bigarray.reshape: size mismatch"); + /* Create bigarray with same data and new dimensions */ + res = caml_ba_alloc(b->flags, num_dims, b->data, dim); + /* Create or update proxy in case of managed bigarray */ + caml_ba_update_proxy(b, Caml_ba_array_val(res)); + /* Return result */ + CAMLreturn (res); + +#undef b +} + +/* Initialization */ + +CAMLprim value caml_ba_init(value unit) +{ + caml_register_custom_operations(&caml_ba_ops); + return Val_unit; +} diff --git a/otherlibs/bigarray/dllbigarray.dlib b/otherlibs/bigarray/dllbigarray.dlib new file mode 100644 index 0000000..5ab8117 --- /dev/null +++ b/otherlibs/bigarray/dllbigarray.dlib @@ -0,0 +1 @@ +bigarray_stubs.d.o mmap_win32.d.o diff --git a/otherlibs/bigarray/libbigarray.clib b/otherlibs/bigarray/libbigarray.clib new file mode 100644 index 0000000..4dc96a4 --- /dev/null +++ b/otherlibs/bigarray/libbigarray.clib @@ -0,0 +1 @@ +bigarray_stubs.o mmap_unix.o diff --git a/otherlibs/bigarray/libbigarraywin32.clib b/otherlibs/bigarray/libbigarraywin32.clib new file mode 100644 index 0000000..16661bb --- /dev/null +++ b/otherlibs/bigarray/libbigarraywin32.clib @@ -0,0 +1 @@ +bigarray_stubs.o mmap_win32.o diff --git a/otherlibs/bigarray/mmap_unix.c b/otherlibs/bigarray/mmap_unix.c new file mode 100644 index 0000000..3bb22a1 --- /dev/null +++ b/otherlibs/bigarray/mmap_unix.c @@ -0,0 +1,135 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mmap_unix.c,v 1.11 2008-01-04 15:01:48 xleroy Exp $ */ + +#include <stddef.h> +#include <string.h> +#include "bigarray.h" +#include "custom.h" +#include "fail.h" +#include "io.h" +#include "mlvalues.h" +#include "sys.h" + +extern int caml_ba_element_size[]; /* from bigarray_stubs.c */ + +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#ifdef HAS_MMAP +#include <sys/types.h> +#include <sys/mman.h> +#endif + +#if defined(HAS_MMAP) + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *) -1) +#endif + +CAMLprim value caml_ba_map_file(value vfd, value vkind, value vlayout, + value vshared, value vdim, value vstart) +{ + int fd, flags, major_dim, shared; + intnat num_dims, i; + intnat dim[CAML_BA_MAX_NUM_DIMS]; + file_offset currpos, startpos, file_size, data_size; + uintnat array_size, page, delta; + char c; + void * addr; + + fd = Int_val(vfd); + flags = Int_val(vkind) | Int_val(vlayout); + startpos = File_offset_val(vstart); + num_dims = Wosize_val(vdim); + major_dim = flags & CAML_BA_FORTRAN_LAYOUT ? num_dims - 1 : 0; + /* Extract dimensions from Caml array */ + num_dims = Wosize_val(vdim); + if (num_dims < 1 || num_dims > CAML_BA_MAX_NUM_DIMS) + caml_invalid_argument("Bigarray.mmap: bad number of dimensions"); + for (i = 0; i < num_dims; i++) { + dim[i] = Long_val(Field(vdim, i)); + if (dim[i] == -1 && i == major_dim) continue; + if (dim[i] < 0) + caml_invalid_argument("Bigarray.create: negative dimension"); + } + /* Determine file size */ + currpos = lseek(fd, 0, SEEK_CUR); + if (currpos == -1) caml_sys_error(NO_ARG); + file_size = lseek(fd, 0, SEEK_END); + if (file_size == -1) caml_sys_error(NO_ARG); + /* Determine array size in bytes (or size of array without the major + dimension if that dimension wasn't specified) */ + array_size = caml_ba_element_size[flags & CAML_BA_KIND_MASK]; + for (i = 0; i < num_dims; i++) + if (dim[i] != -1) array_size *= dim[i]; + /* Check if the major dimension is unknown */ + if (dim[major_dim] == -1) { + /* Determine major dimension from file size */ + if (file_size < startpos) + caml_failwith("Bigarray.mmap: file position exceeds file size"); + data_size = file_size - startpos; + dim[major_dim] = (uintnat) (data_size / array_size); + array_size = dim[major_dim] * array_size; + if (array_size != data_size) + caml_failwith("Bigarray.mmap: file size doesn't match array dimensions"); + } else { + /* Check that file is large enough, and grow it otherwise */ + if (file_size < startpos + array_size) { + if (lseek(fd, startpos + array_size - 1, SEEK_SET) == -1) + caml_sys_error(NO_ARG); + c = 0; + if (write(fd, &c, 1) != 1) caml_sys_error(NO_ARG); + } + } + /* Restore original file position */ + lseek(fd, currpos, SEEK_SET); + /* Determine offset so that the mapping starts at the given file pos */ + page = getpagesize(); + delta = (uintnat) (startpos % page); + /* Do the mmap */ + shared = Bool_val(vshared) ? MAP_SHARED : MAP_PRIVATE; + addr = mmap(NULL, array_size + delta, PROT_READ | PROT_WRITE, + shared, fd, startpos - delta); + if (addr == (void *) MAP_FAILED) caml_sys_error(NO_ARG); + addr = (void *) ((uintnat) addr + delta); + /* Build and return the Caml bigarray */ + return caml_ba_alloc(flags | CAML_BA_MAPPED_FILE, num_dims, addr, dim); +} + +#else + +value caml_ba_map_file(value vfd, value vkind, value vlayout, + value vshared, value vdim, value vpos) +{ + invalid_argument("Bigarray.map_file: not supported"); + return Val_unit; +} + +#endif + +CAMLprim value caml_ba_map_file_bytecode(value * argv, int argn) +{ + return caml_ba_map_file(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +void caml_ba_unmap_file(void * addr, uintnat len) +{ +#if defined(HAS_MMAP) + uintnat page = getpagesize(); + uintnat delta = (uintnat) addr % page; + munmap((void *)((uintnat)addr - delta), len + delta); +#endif +} diff --git a/otherlibs/bigarray/mmap_win32.c b/otherlibs/bigarray/mmap_win32.c new file mode 100644 index 0000000..ffc96fe --- /dev/null +++ b/otherlibs/bigarray/mmap_win32.c @@ -0,0 +1,155 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mmap_win32.c,v 1.12 2008-01-15 14:55:15 frisch Exp $ */ + +#include <stddef.h> +#include <stdio.h> +#include <string.h> +#include "bigarray.h" +#include "alloc.h" +#include "custom.h" +#include "fail.h" +#include "mlvalues.h" +#include "sys.h" +#include "unixsupport.h" + +extern int caml_ba_element_size[]; /* from bigarray_stubs.c */ + +static void caml_ba_sys_error(void); + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER (-1) +#endif + +static __int64 caml_ba_set_file_pointer(HANDLE h, __int64 dist, DWORD mode) +{ + LARGE_INTEGER i; + DWORD err; + + i.QuadPart = dist; + i.LowPart = SetFilePointer(h, i.LowPart, &i.HighPart, mode); + if (i.LowPart == INVALID_SET_FILE_POINTER) return -1; + return i.QuadPart; +} + +CAMLprim value caml_ba_map_file(value vfd, value vkind, value vlayout, + value vshared, value vdim, value vstart) +{ + HANDLE fd, fmap; + int flags, major_dim, mode, perm; + intnat num_dims, i; + intnat dim[CAML_BA_MAX_NUM_DIMS]; + __int64 currpos, startpos, file_size, data_size; + uintnat array_size, page, delta; + char c; + void * addr; + LARGE_INTEGER li; + SYSTEM_INFO sysinfo; + + fd = Handle_val(vfd); + flags = Int_val(vkind) | Int_val(vlayout); + startpos = Int64_val(vstart); + num_dims = Wosize_val(vdim); + major_dim = flags & CAML_BA_FORTRAN_LAYOUT ? num_dims - 1 : 0; + /* Extract dimensions from Caml array */ + num_dims = Wosize_val(vdim); + if (num_dims < 1 || num_dims > CAML_BA_MAX_NUM_DIMS) + caml_invalid_argument("Bigarray.mmap: bad number of dimensions"); + for (i = 0; i < num_dims; i++) { + dim[i] = Long_val(Field(vdim, i)); + if (dim[i] == -1 && i == major_dim) continue; + if (dim[i] < 0) + caml_invalid_argument("Bigarray.create: negative dimension"); + } + /* Determine file size */ + currpos = caml_ba_set_file_pointer(fd, 0, FILE_CURRENT); + if (currpos == -1) caml_ba_sys_error(); + file_size = caml_ba_set_file_pointer(fd, 0, FILE_END); + if (file_size == -1) caml_ba_sys_error(); + /* Determine array size in bytes (or size of array without the major + dimension if that dimension wasn't specified) */ + array_size = caml_ba_element_size[flags & CAML_BA_KIND_MASK]; + for (i = 0; i < num_dims; i++) + if (dim[i] != -1) array_size *= dim[i]; + /* Check if the first/last dimension is unknown */ + if (dim[major_dim] == -1) { + /* Determine first/last dimension from file size */ + if (file_size < startpos) + caml_failwith("Bigarray.mmap: file position exceeds file size"); + data_size = file_size - startpos; + dim[major_dim] = (uintnat) (data_size / array_size); + array_size = dim[major_dim] * array_size; + if (array_size != data_size) + caml_failwith("Bigarray.mmap: file size doesn't match array dimensions"); + } + /* Restore original file position */ + caml_ba_set_file_pointer(fd, currpos, FILE_BEGIN); + /* Create the file mapping */ + if (Bool_val(vshared)) { + perm = PAGE_READWRITE; + mode = FILE_MAP_WRITE; + } else { + perm = PAGE_READONLY; /* doesn't work under Win98 */ + mode = FILE_MAP_COPY; + } + li.QuadPart = startpos + array_size; + fmap = CreateFileMapping(fd, NULL, perm, li.HighPart, li.LowPart, NULL); + if (fmap == NULL) caml_ba_sys_error(); + /* Determine offset so that the mapping starts at the given file pos */ + GetSystemInfo(&sysinfo); + delta = (uintnat) (startpos % sysinfo.dwPageSize); + /* Map the mapping in memory */ + li.QuadPart = startpos - delta; + addr = + MapViewOfFile(fmap, mode, li.HighPart, li.LowPart, array_size + delta); + if (addr == NULL) caml_ba_sys_error(); + addr = (void *) ((uintnat) addr + delta); + /* Close the file mapping */ + CloseHandle(fmap); + /* Build and return the Caml bigarray */ + return caml_ba_alloc(flags | CAML_BA_MAPPED_FILE, num_dims, addr, dim); +} + +CAMLprim value caml_ba_map_file_bytecode(value * argv, int argn) +{ + return caml_ba_map_file(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +void caml_ba_unmap_file(void * addr, uintnat len) +{ + SYSTEM_INFO sysinfo; + uintnat delta; + + GetSystemInfo(&sysinfo); + delta = (uintnat) addr % sysinfo.dwPageSize; + UnmapViewOfFile((void *)((uintnat)addr - delta)); +} + +static void caml_ba_sys_error(void) +{ + char buffer[512]; + DWORD errnum; + + errnum = GetLastError(); + if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + errnum, + 0, + buffer, + sizeof(buffer), + NULL)) + sprintf(buffer, "Unknown error %ld\n", errnum); + caml_raise_sys_error(caml_copy_string(buffer)); +} diff --git a/otherlibs/db/.depend b/otherlibs/db/.depend new file mode 100644 index 0000000..5d94dce --- /dev/null +++ b/otherlibs/db/.depend @@ -0,0 +1,2 @@ +db.cmo: db.cmi +db.cmx: db.cmi diff --git a/otherlibs/dbm/.cvsignore b/otherlibs/dbm/.cvsignore new file mode 100644 index 0000000..074dd28 --- /dev/null +++ b/otherlibs/dbm/.cvsignore @@ -0,0 +1 @@ +so_locations diff --git a/otherlibs/dbm/.depend b/otherlibs/dbm/.depend new file mode 100644 index 0000000..2092fba --- /dev/null +++ b/otherlibs/dbm/.depend @@ -0,0 +1,3 @@ +dbm.cmi: +dbm.cmo: dbm.cmi +dbm.cmx: dbm.cmi diff --git a/otherlibs/dbm/Makefile b/otherlibs/dbm/Makefile new file mode 100644 index 0000000..4f3771c --- /dev/null +++ b/otherlibs/dbm/Makefile @@ -0,0 +1,31 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.26 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the ndbm library + +LIBNAME=dbm +CLIBNAME=mldbm +CAMLOBJS=dbm.cmo +COBJS=cldbm.o +EXTRACFLAGS=$(DBM_INCLUDES) +LINKOPTS=$(DBM_LINK) + +include ../Makefile + + +depend: + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml > .depend + +include .depend diff --git a/otherlibs/dbm/cldbm.c b/otherlibs/dbm/cldbm.c new file mode 100644 index 0000000..4d768aa --- /dev/null +++ b/otherlibs/dbm/cldbm.c @@ -0,0 +1,166 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Francois Rouaix, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: cldbm.c,v 1.8 2003-07-08 13:50:31 xleroy Exp $ */ + +#include <string.h> +#include <fcntl.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <fail.h> +#include <callback.h> + +#ifdef DBM_USES_GDBM_NDBM +#include <gdbm-ndbm.h> +#else +#include <ndbm.h> +#endif + +/* Quite close to sys_open_flags, but we need RDWR */ +static int dbm_open_flags[] = { + O_RDONLY, O_WRONLY, O_RDWR, O_CREAT +}; + +static void raise_dbm (char *errmsg) Noreturn; + +static void raise_dbm(char *errmsg) +{ + static value * dbm_exn = NULL; + if (dbm_exn == NULL) + dbm_exn = caml_named_value("dbmerror"); + raise_with_string(*dbm_exn, errmsg); +} + +#define DBM_val(v) *((DBM **) &Field(v, 0)) + +static value alloc_dbm(DBM * db) +{ + value res = alloc_small(1, Abstract_tag); + DBM_val(res) = db; + return res; +} + +static DBM * extract_dbm(value vdb) +{ + if (DBM_val(vdb) == NULL) raise_dbm("DBM has been closed"); + return DBM_val(vdb); +} + +/* Dbm.open : string -> Sys.open_flag list -> int -> t */ +value caml_dbm_open(value vfile, value vflags, value vmode) /* ML */ +{ + char *file = String_val(vfile); + int flags = convert_flag_list(vflags, dbm_open_flags); + int mode = Int_val(vmode); + DBM *db = dbm_open(file,flags,mode); + + if (db == NULL) + raise_dbm("Can't open file"); + else + return (alloc_dbm(db)); +} + +/* Dbm.close: t -> unit */ +value caml_dbm_close(value vdb) /* ML */ +{ + dbm_close(extract_dbm(vdb)); + DBM_val(vdb) = NULL; + return Val_unit; +} + +/* Dbm.fetch: t -> string -> string */ +value caml_dbm_fetch(value vdb, value vkey) /* ML */ +{ + datum key,answer; + key.dptr = String_val(vkey); + key.dsize = string_length(vkey); + answer = dbm_fetch(extract_dbm(vdb), key); + if (answer.dptr) { + value res = alloc_string(answer.dsize); + memmove (String_val (res), answer.dptr, answer.dsize); + return res; + } + else raise_not_found(); +} + +value caml_dbm_insert(value vdb, value vkey, value vcontent) /* ML */ +{ + datum key, content; + + key.dptr = String_val(vkey); + key.dsize = string_length(vkey); + content.dptr = String_val(vcontent); + content.dsize = string_length(vcontent); + + switch(dbm_store(extract_dbm(vdb), key, content, DBM_INSERT)) { + case 0: + return Val_unit; + case 1: /* DBM_INSERT and already existing */ + raise_dbm("Entry already exists"); + default: + raise_dbm("dbm_store failed"); + } +} + +value caml_dbm_replace(value vdb, value vkey, value vcontent) /* ML */ +{ + datum key, content; + + key.dptr = String_val(vkey); + key.dsize = string_length(vkey); + content.dptr = String_val(vcontent); + content.dsize = string_length(vcontent); + + switch(dbm_store(extract_dbm(vdb), key, content, DBM_REPLACE)) { + case 0: + return Val_unit; + default: + raise_dbm("dbm_store failed"); + } +} + +value caml_dbm_delete(value vdb, value vkey) /* ML */ +{ + datum key; + key.dptr = String_val(vkey); + key.dsize = string_length(vkey); + + if (dbm_delete(extract_dbm(vdb), key) < 0) + raise_dbm("dbm_delete"); + else return Val_unit; +} + +value caml_dbm_firstkey(value vdb) /* ML */ +{ + datum key = dbm_firstkey(extract_dbm(vdb)); + + if (key.dptr) { + value res = alloc_string(key.dsize); + memmove (String_val (res), key.dptr, key.dsize); + return res; + } + else raise_not_found(); +} + +value caml_dbm_nextkey(value vdb) /* ML */ +{ + datum key = dbm_nextkey(extract_dbm(vdb)); + + if (key.dptr) { + value res = alloc_string(key.dsize); + memmove (String_val (res), key.dptr, key.dsize); + return res; + } + else raise_not_found(); +} diff --git a/otherlibs/dbm/dbm.ml b/otherlibs/dbm/dbm.ml new file mode 100644 index 0000000..bfba080 --- /dev/null +++ b/otherlibs/dbm/dbm.ml @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Francois Rouaix, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dbm.ml,v 1.10 2001-12-07 13:39:51 xleroy Exp $ *) + +type t + +type open_flag = + Dbm_rdonly | Dbm_wronly | Dbm_rdwr | Dbm_create + +type dbm_flag = + DBM_INSERT + | DBM_REPLACE + +exception Dbm_error of string + +external raw_opendbm : string -> open_flag list -> int -> t + = "caml_dbm_open" + +let opendbm file flags mode = + try + raw_opendbm file flags mode + with Dbm_error msg -> + raise(Dbm_error("Can't open file " ^ file)) + + (* By exporting opendbm as val, we are sure to link in this + file (we must register the exception). Since t is abstract, programs + have to call it in order to do anything *) + +external close : t -> unit = "caml_dbm_close" +external find : t -> string -> string = "caml_dbm_fetch" +external add : t -> string -> string -> unit = "caml_dbm_insert" +external replace : t -> string -> string -> unit = "caml_dbm_replace" +external remove : t -> string -> unit = "caml_dbm_delete" +external firstkey : t -> string = "caml_dbm_firstkey" +external nextkey : t -> string = "caml_dbm_nextkey" + +let _ = Callback.register_exception "dbmerror" (Dbm_error "") + +(* Usual iterator *) +let iter f t = + let rec walk = function + None -> () + | Some k -> + f k (find t k); + walk (try Some(nextkey t) with Not_found -> None) + in + walk (try Some(firstkey t) with Not_found -> None) diff --git a/otherlibs/dbm/dbm.mli b/otherlibs/dbm/dbm.mli new file mode 100644 index 0000000..0c3448c --- /dev/null +++ b/otherlibs/dbm/dbm.mli @@ -0,0 +1,80 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Francois Rouaix, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dbm.mli,v 1.15 2001-12-07 13:39:51 xleroy Exp $ *) + +(** Interface to the NDBM database. *) + +type t +(** The type of file descriptors opened on NDBM databases. *) + + +type open_flag = + Dbm_rdonly + | Dbm_wronly + | Dbm_rdwr + | Dbm_create +(** Flags for opening a database (see {!Dbm.opendbm}). *) + + +exception Dbm_error of string +(** Raised by the following functions when an error is encountered. *) + +val opendbm : string -> open_flag list -> int -> t +(** Open a descriptor on an NDBM database. The first argument is + the name of the database (without the [.dir] and [.pag] suffixes). + The second argument is a list of flags: [Dbm_rdonly] opens + the database for reading only, [Dbm_wronly] for writing only, + [Dbm_rdwr] for reading and writing; [Dbm_create] causes the + database to be created if it does not already exist. + The third argument is the permissions to give to the database + files, if the database is created. *) + +external close : t -> unit = "caml_dbm_close" +(** Close the given descriptor. *) + +external find : t -> string -> string = "caml_dbm_fetch" +(** [find db key] returns the data associated with the given + [key] in the database opened for the descriptor [db]. + Raise [Not_found] if the [key] has no associated data. *) + +external add : t -> string -> string -> unit = "caml_dbm_insert" +(** [add db key data] inserts the pair ([key], [data]) in + the database [db]. If the database already contains data + associated with [key], raise [Dbm_error "Entry already exists"]. *) + +external replace : t -> string -> string -> unit = "caml_dbm_replace" +(** [replace db key data] inserts the pair ([key], [data]) in + the database [db]. If the database already contains data + associated with [key], that data is discarded and silently + replaced by the new [data]. *) + +external remove : t -> string -> unit = "caml_dbm_delete" +(** [remove db key data] removes the data associated with [key] + in [db]. If [key] has no associated data, raise + [Dbm_error "dbm_delete"]. *) + +external firstkey : t -> string = "caml_dbm_firstkey" +(** See {!Dbm.nextkey}.*) + +external nextkey : t -> string = "caml_dbm_nextkey" +(** Enumerate all keys in the given database, in an unspecified order. + [firstkey db] returns the first key, and repeated calls + to [nextkey db] return the remaining keys. [Not_found] is raised + when all keys have been enumerated. *) + +val iter : (string -> string -> 'a) -> t -> unit +(** [iter f db] applies [f] to each ([key], [data]) pair in + the database [db]. [f] receives [key] as first argument + and [data] as second argument. *) + diff --git a/otherlibs/dbm/libmldbm.clib b/otherlibs/dbm/libmldbm.clib new file mode 100644 index 0000000..3a63b87 --- /dev/null +++ b/otherlibs/dbm/libmldbm.clib @@ -0,0 +1 @@ +cldbm.o diff --git a/otherlibs/dynlink/.cvsignore b/otherlibs/dynlink/.cvsignore new file mode 100644 index 0000000..5ea9775 --- /dev/null +++ b/otherlibs/dynlink/.cvsignore @@ -0,0 +1 @@ +extract_crc diff --git a/otherlibs/dynlink/Makefile b/otherlibs/dynlink/Makefile new file mode 100644 index 0000000..a303320 --- /dev/null +++ b/otherlibs/dynlink/Makefile @@ -0,0 +1,96 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.34 2008-04-16 06:50:31 frisch Exp $ + +# Makefile for the dynamic link library + +include ../../config/Makefile + +CAMLC=../../boot/ocamlrun ../../ocamlc +CAMLOPT=../../ocamlcompopt.sh +INCLUDES=-I ../../utils -I ../../typing -I ../../bytecomp +COMPFLAGS=-warn-error A -I ../../stdlib $(INCLUDES) + +OBJS=dynlinkaux.cmo dynlink.cmo + +COMPILEROBJS=\ + ../../utils/misc.cmo ../../utils/config.cmo ../../utils/clflags.cmo \ + ../../utils/tbl.cmo ../../utils/consistbl.cmo \ + ../../utils/terminfo.cmo ../../utils/warnings.cmo \ + ../../parsing/asttypes.cmi ../../parsing/linenum.cmo \ + ../../parsing/location.cmo ../../parsing/longident.cmo \ + ../../typing/ident.cmo ../../typing/path.cmo \ + ../../typing/primitive.cmo ../../typing/types.cmo \ + ../../typing/btype.cmo ../../typing/subst.cmo ../../typing/predef.cmo \ + ../../typing/datarepr.cmo ../../typing/env.cmo \ + ../../bytecomp/lambda.cmo ../../bytecomp/instruct.cmo \ + ../../bytecomp/cmo_format.cmi ../../bytecomp/opcodes.cmo \ + ../../bytecomp/runtimedef.cmo ../../bytecomp/bytesections.cmo \ + ../../bytecomp/dll.cmo ../../bytecomp/meta.cmo \ + ../../bytecomp/symtable.cmo + +NATOBJS=dynlink.cmx + +all: dynlink.cma extract_crc + +allopt: dynlink.cmxa + +dynlink.cma: $(OBJS) + $(CAMLC) $(COMPFLAGS) -ccopt "$(NATDYNLINKOPTS)" -a -o dynlink.cma $(OBJS) + +dynlink.cmxa: $(NATOBJS) + $(CAMLOPT) $(COMPFLAGS) -ccopt "$(NATDYNLINKOPTS)" -a -o dynlink.cmxa $(NATOBJS) + +dynlinkaux.cmo: $(COMPILEROBJS) + $(CAMLC) $(COMPFLAGS) -pack -o dynlinkaux.cmo $(COMPILEROBJS) + +dynlinkaux.cmi: dynlinkaux.cmo + +dynlink.cmx: dynlink.cmi natdynlink.ml + cp natdynlink.ml dynlink.mlopt + $(CAMLOPT) -c $(COMPFLAGS) -impl dynlink.mlopt + rm -f dynlink.mlopt + +extract_crc: dynlink.cma extract_crc.cmo + $(CAMLC) $(COMPFLAGS) -o extract_crc dynlink.cma extract_crc.cmo + +install: + cp dynlink.cmi dynlink.cma dynlink.mli $(LIBDIR) + cp extract_crc $(LIBDIR)/extract_crc$(EXE) + +installopt: + cp $(NATOBJS) dynlink.cmxa dynlink.$(A) $(LIBDIR) + cd $(LIBDIR); $(RANLIB) dynlink.$(A) + +partialclean: + rm -f extract_crc *.cm[ioax] *.cmxa + +clean: partialclean + rm -f *.$(A) *.$(O) *.so *.dll dynlink.mlopt + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: + +dynlink.cmo: dynlinkaux.cmi dynlink.cmi +extract_crc.cmo: dynlink.cmi diff --git a/otherlibs/dynlink/Makefile.nt b/otherlibs/dynlink/Makefile.nt new file mode 100644 index 0000000..80e755c --- /dev/null +++ b/otherlibs/dynlink/Makefile.nt @@ -0,0 +1,18 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.17 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the dynamic link library + +include Makefile diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml new file mode 100644 index 0000000..56157d6 --- /dev/null +++ b/otherlibs/dynlink/dynlink.ml @@ -0,0 +1,269 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dynlink.ml,v 1.36 2008-04-22 12:24:10 frisch Exp $ *) + +(* Dynamic loading of .cmo files *) + +open Dynlinkaux +open Dynlinkaux.Cmo_format + +type linking_error = + Undefined_global of string + | Unavailable_primitive of string + | Uninitialized_global of string + +type error = + Not_a_bytecode_file of string + | Inconsistent_import of string + | Unavailable_unit of string + | Unsafe_file + | Linking_error of string * linking_error + | Corrupted_interface of string + | File_not_found of string + | Cannot_open_dll of string + | Inconsistent_implementation of string + +exception Error of error + +(* Management of interface CRCs *) + +let crc_interfaces = ref (Consistbl.create ()) +let allow_extension = ref true + +(* Check that the object file being loaded has been compiled against + the same interfaces as the program itself. In addition, check that + only authorized compilation units are referenced. *) + +let check_consistency file_name cu = + try + List.iter + (fun (name, crc) -> + if name = cu.cu_name then + Consistbl.set !crc_interfaces name crc file_name + else if !allow_extension then + Consistbl.check !crc_interfaces name crc file_name + else + Consistbl.check_noadd !crc_interfaces name crc file_name) + cu.cu_imports + with Consistbl.Inconsistency(name, user, auth) -> + raise(Error(Inconsistent_import name)) + | Consistbl.Not_available(name) -> + raise(Error(Unavailable_unit name)) + +(* Empty the crc_interfaces table *) + +let clear_available_units () = + Consistbl.clear !crc_interfaces; + allow_extension := false + +(* Allow only access to the units with the given names *) + +let allow_only names = + Consistbl.filter (fun name -> List.mem name names) !crc_interfaces; + allow_extension := false + +(* Prohibit access to the units with the given names *) + +let prohibit names = + Consistbl.filter (fun name -> not (List.mem name names)) !crc_interfaces; + allow_extension := false + +(* Initialize the crc_interfaces table with a list of units with fixed CRCs *) + +let add_available_units units = + List.iter (fun (unit, crc) -> Consistbl.set !crc_interfaces unit crc "") + units + +(* Default interface CRCs: those found in the current executable *) +let default_crcs = ref [] + +let default_available_units () = + clear_available_units(); + add_available_units !default_crcs; + allow_extension := true + +(* Initialize the linker tables and everything *) + +let inited = ref false + +let init () = + if not !inited then begin + default_crcs := Symtable.init_toplevel(); + default_available_units (); + inited := true; + end + +let clear_available_units () = init(); clear_available_units () +let allow_only l = init(); allow_only l +let prohibit l = init(); prohibit l +let add_available_units l = init(); add_available_units l +let default_available_units () = init(); default_available_units () + +(* Read the CRC of an interface from its .cmi file *) + +let digest_interface unit loadpath = + let filename = + let shortname = unit ^ ".cmi" in + try + Misc.find_in_path_uncap loadpath shortname + with Not_found -> + raise (Error(File_not_found shortname)) in + let ic = open_in_bin filename in + try + let buffer = String.create (String.length Config.cmi_magic_number) in + really_input ic buffer 0 (String.length Config.cmi_magic_number); + if buffer <> Config.cmi_magic_number then begin + close_in ic; + raise(Error(Corrupted_interface filename)) + end; + ignore (input_value ic); + let crc = + match input_value ic with + (_, crc) :: _ -> crc + | _ -> raise(Error(Corrupted_interface filename)) + in + close_in ic; + crc + with End_of_file | Failure _ -> + close_in ic; + raise(Error(Corrupted_interface filename)) + +(* Initialize the crc_interfaces table with a list of units. + Their CRCs are read from their interfaces. *) + +let add_interfaces units loadpath = + add_available_units + (List.map (fun unit -> (unit, digest_interface unit loadpath)) units) + +(* Check whether the object file being loaded was compiled in unsafe mode *) + +let unsafe_allowed = ref false + +let allow_unsafe_modules b = + unsafe_allowed := b + +let check_unsafe_module cu = + if (not !unsafe_allowed) && cu.cu_primitives <> [] + then raise(Error(Unsafe_file)) + +(* Load in-core and execute a bytecode object file *) + +let load_compunit ic file_name compunit = + check_consistency file_name compunit; + check_unsafe_module compunit; + seek_in ic compunit.cu_pos; + let code_size = compunit.cu_codesize + 8 in + let code = Meta.static_alloc code_size in + unsafe_really_input ic code 0 compunit.cu_codesize; + String.unsafe_set code compunit.cu_codesize (Char.chr Opcodes.opRETURN); + String.unsafe_set code (compunit.cu_codesize + 1) '\000'; + String.unsafe_set code (compunit.cu_codesize + 2) '\000'; + String.unsafe_set code (compunit.cu_codesize + 3) '\000'; + String.unsafe_set code (compunit.cu_codesize + 4) '\001'; + String.unsafe_set code (compunit.cu_codesize + 5) '\000'; + String.unsafe_set code (compunit.cu_codesize + 6) '\000'; + String.unsafe_set code (compunit.cu_codesize + 7) '\000'; + let initial_symtable = Symtable.current_state() in + begin try + Symtable.patch_object code compunit.cu_reloc; + Symtable.check_global_initialized compunit.cu_reloc; + Symtable.update_global_table() + with Symtable.Error error -> + let new_error = + match error with + Symtable.Undefined_global s -> Undefined_global s + | Symtable.Unavailable_primitive s -> Unavailable_primitive s + | Symtable.Uninitialized_global s -> Uninitialized_global s + | _ -> assert false in + raise(Error(Linking_error (file_name, new_error))) + end; + begin try + ignore((Meta.reify_bytecode code code_size) ()) + with exn -> + Symtable.restore_state initial_symtable; + raise exn + end + +let loadfile file_name = + init(); + let ic = open_in_bin file_name in + try + let buffer = String.create (String.length Config.cmo_magic_number) in + really_input ic buffer 0 (String.length Config.cmo_magic_number); + if buffer = Config.cmo_magic_number then begin + let compunit_pos = input_binary_int ic in (* Go to descriptor *) + seek_in ic compunit_pos; + load_compunit ic file_name (input_value ic : compilation_unit) + end else + if buffer = Config.cma_magic_number then begin + let toc_pos = input_binary_int ic in (* Go to table of contents *) + seek_in ic toc_pos; + let lib = (input_value ic : library) in + begin try + Dll.open_dlls Dll.For_execution + (List.map Dll.extract_dll_name lib.lib_dllibs) + with Failure reason -> + raise(Error(Cannot_open_dll reason)) + end; + List.iter (load_compunit ic file_name) lib.lib_units + end else + raise(Error(Not_a_bytecode_file file_name)); + close_in ic + with exc -> + close_in ic; raise exc + +let loadfile_private file_name = + init(); + let initial_symtable = Symtable.current_state() + and initial_crc = !crc_interfaces in + try + loadfile file_name; + Symtable.hide_additions initial_symtable; + crc_interfaces := initial_crc + with exn -> + Symtable.hide_additions initial_symtable; + crc_interfaces := initial_crc; + raise exn + +(* Error report *) + +let error_message = function + Not_a_bytecode_file name -> + name ^ " is not a bytecode object file" + | Inconsistent_import name -> + "interface mismatch on " ^ name + | Unavailable_unit name -> + "no implementation available for " ^ name + | Unsafe_file -> + "this object file uses unsafe features" + | Linking_error (name, Undefined_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "Reference to undefined global `" ^ s ^ "'" + | Linking_error (name, Unavailable_primitive s) -> + "error while linking " ^ name ^ ".\n" ^ + "The external function `" ^ s ^ "' is not available" + | Linking_error (name, Uninitialized_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "The module `" ^ s ^ "' is not yet initialized" + | Corrupted_interface name -> + "corrupted interface file " ^ name + | File_not_found name -> + "cannot find file " ^ name ^ " in search path" + | Cannot_open_dll reason -> + "error loading shared library: " ^ reason + | Inconsistent_implementation name -> + "implementation mismatch on " ^ name + +let is_native = false +let adapt_filename f = f diff --git a/otherlibs/dynlink/dynlink.mli b/otherlibs/dynlink/dynlink.mli new file mode 100644 index 0000000..c839531 --- /dev/null +++ b/otherlibs/dynlink/dynlink.mli @@ -0,0 +1,143 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: dynlink.mli,v 1.23 2008-04-22 12:24:10 frisch Exp $ *) + +(** Dynamic loading of object files. *) + +val is_native: bool +(** [true] if the program is native, + [false] if the program is bytecode. *) + +(** {6 Dynamic loading of compiled files} *) + +val loadfile : string -> unit +(** In bytecode: load the given bytecode object file ([.cmo] file) or + bytecode library file ([.cma] file), and link it with the running + program. In native code: load the given OCaml plugin file (usually + [.cmxs]), and link it with the running + program. + All toplevel expressions in the loaded compilation units + are evaluated. No facilities are provided to + access value names defined by the unit. Therefore, the unit + must register itself its entry points with the main program, + e.g. by modifying tables of functions. *) + +val loadfile_private : string -> unit +(** Same as [loadfile], except that the compilation units just loaded + are hidden (cannot be referenced) from other modules dynamically + loaded afterwards. *) + +val adapt_filename : string -> string +(** In bytecode, the identity function. In native code, replace the last + extension with [.cmxs]. *) + +(** {6 Access control} *) + +val allow_only: string list -> unit +(** [allow_only units] restricts the compilation units that dynamically-linked + units can reference: it only allows references to the units named in + list [units]. References to any other compilation unit will cause + a [Unavailable_unit] error during [loadfile] or [loadfile_private]. + + Initially (just after calling [init]), all compilation units composing + the program currently running are available for reference from + dynamically-linked units. [allow_only] can be used to grant access + to some of them only, e.g. to the units that compose the API for + dynamically-linked code, and prevent access to all other units, + e.g. private, internal modules of the running program. *) + +val prohibit: string list -> unit +(** [prohibit units] prohibits dynamically-linked units from referencing + the units named in list [units]. This can be used to prevent + access to selected units, e.g. private, internal modules of + the running program. *) + +val default_available_units: unit -> unit +(** Reset the set of units that can be referenced from dynamically-linked + code to its default value, that is, all units composing the currently + running program. *) + +val allow_unsafe_modules : bool -> unit +(** Govern whether unsafe object files are allowed to be + dynamically linked. A compilation unit is ``unsafe'' if it contains + declarations of external functions, which can break type safety. + By default, dynamic linking of unsafe object files is + not allowed. In native code, this function does nothing; object files + with external functions are always allowed to be dynamically linked. *) + +(** {6 Deprecated, low-level API for access control} *) + +(** @deprecated The functions [add_interfaces], [add_available_units] + and [clear_available_units] should not be used in new programs, + since the default initialization of allowed units, along with the + [allow_only] and [prohibit] function, provides a better, safer + mechanism to control access to program units. The three functions + below are provided for backward compatibility only and are not + available in native code. *) + +val add_interfaces : string list -> string list -> unit +(** [add_interfaces units path] grants dynamically-linked object + files access to the compilation units named in list [units]. + The interfaces ([.cmi] files) for these units are searched in + [path] (a list of directory names). *) + +val add_available_units : (string * Digest.t) list -> unit +(** Same as {!Dynlink.add_interfaces}, but instead of searching [.cmi] files + to find the unit interfaces, uses the interface digests given + for each unit. This way, the [.cmi] interface files need not be + available at run-time. The digests can be extracted from [.cmi] + files using the [extract_crc] program installed in the + Objective Caml standard library directory. *) + +val clear_available_units : unit -> unit +(** Empty the list of compilation units accessible to dynamically-linked + programs. *) + +(** {6 Deprecated, initialization} *) + +val init : unit -> unit +(** @deprecated Initialize the [Dynlink] library. This function is called + automatically when needed. *) + +(** {6 Error reporting} *) + +type linking_error = + Undefined_global of string + | Unavailable_primitive of string + | Uninitialized_global of string + +type error = + Not_a_bytecode_file of string + | Inconsistent_import of string + | Unavailable_unit of string + | Unsafe_file + | Linking_error of string * linking_error + | Corrupted_interface of string + | File_not_found of string + | Cannot_open_dll of string + | Inconsistent_implementation of string + +exception Error of error +(** Errors in dynamic linking are reported by raising the [Error] + exception with a description of the error. *) + +val error_message : error -> string +(** Convert an error description to a printable message. *) + + +(**/**) + +(** {6 Internal functions} *) + +val digest_interface : string -> string list -> Digest.t diff --git a/otherlibs/dynlink/dynlinkaux.mlpack b/otherlibs/dynlink/dynlinkaux.mlpack new file mode 100644 index 0000000..783e624 --- /dev/null +++ b/otherlibs/dynlink/dynlinkaux.mlpack @@ -0,0 +1,5 @@ +Misc Config Clflags Tbl Consistbl +Terminfo Warnings Asttypes Linenum Location Longident +Ident Path Primitive Types Btype Subst Predef +Datarepr Env Lambda Instruct Cmo_format Opcodes +Runtimedef Bytesections Dll Meta Symtable diff --git a/otherlibs/dynlink/extract_crc.ml b/otherlibs/dynlink/extract_crc.ml new file mode 100644 index 0000000..8ebbf76 --- /dev/null +++ b/otherlibs/dynlink/extract_crc.ml @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: extract_crc.ml,v 1.10 2004-04-09 13:26:41 xleroy Exp $ *) + +(* Print the digests of unit interfaces *) + +let load_path = ref [] +let first = ref true + +let print_crc unit = + try + let crc = Dynlink.digest_interface unit (!load_path @ ["."]) in + if !first then first := false else print_string ";\n"; + print_string " \""; print_string (String.capitalize unit); + print_string "\",\n \""; + for i = 0 to String.length crc - 1 do + Printf.printf "\\%03d" (Char.code crc.[i]) + done; + print_string "\"" + with exn -> + prerr_string "Error while reading the interface for "; + prerr_endline unit; + begin match exn with + Sys_error msg -> prerr_endline msg + | Dynlink.Error(Dynlink.File_not_found name) -> + prerr_string "Cannot find file "; prerr_endline name + | Dynlink.Error _ -> prerr_endline "Ill-formed .cmi file" + | _ -> raise exn + end; + exit 2 + +let usage = "Usage: extract_crc [-I <dir>] <files>" + +let main () = + print_string "let crc_unit_list = [\n"; + Arg.parse + ["-I", Arg.String(fun dir -> load_path := !load_path @ [dir]), + "<dir> Add <dir> to the list of include directories"] + print_crc usage; + print_string "\n]\n" + +let _ = main(); exit 0 + + diff --git a/otherlibs/dynlink/natdynlink.ml b/otherlibs/dynlink/natdynlink.ml new file mode 100644 index 0000000..dcae9e9 --- /dev/null +++ b/otherlibs/dynlink/natdynlink.ml @@ -0,0 +1,259 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Gallium, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: natdynlink.ml,v 1.6 2008-08-28 22:17:51 frisch Exp $ *) + +(* Dynamic loading of .cmx files *) + +type handle + +external ndl_open: string -> bool -> handle * string = "caml_natdynlink_open" +external ndl_run: handle -> string -> unit = "caml_natdynlink_run" +external ndl_getmap: unit -> string = "caml_natdynlink_getmap" +external ndl_globals_inited: unit -> int = "caml_natdynlink_globals_inited" + +type linking_error = + Undefined_global of string + | Unavailable_primitive of string + | Uninitialized_global of string + +type error = + Not_a_bytecode_file of string + | Inconsistent_import of string + | Unavailable_unit of string + | Unsafe_file + | Linking_error of string * linking_error + | Corrupted_interface of string + | File_not_found of string + | Cannot_open_dll of string + | Inconsistent_implementation of string + +exception Error of error + +(* Copied from other places to avoid dependencies *) + +type dynunit = { + name: string; + crc: Digest.t; + imports_cmi: (string * Digest.t) list; + imports_cmx: (string * Digest.t) list; + defines: string list; +} + +type dynheader = { + magic: string; + units: dynunit list; +} + +let dyn_magic_number = "Caml2007D001" + +let dll_filename fname = + if Filename.is_implicit fname then Filename.concat (Sys.getcwd ()) fname + else fname + +let read_file filename priv = + let dll = dll_filename filename in + if not (Sys.file_exists dll) then raise (Error (File_not_found dll)); + + let (handle,data) as res = ndl_open dll (not priv) in + if Obj.tag (Obj.repr res) = Obj.string_tag + then raise (Error (Cannot_open_dll (Obj.magic res))); + + let header : dynheader = Marshal.from_string data 0 in + if header.magic <> dyn_magic_number + then raise(Error(Not_a_bytecode_file dll)); + (dll, handle, header.units) + +let cmx_not_found_crc = + "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + + +(* Management of interface and implementation CRCs *) + +module StrMap = Map.Make(String) + +type implem_state = + | Loaded + | Check_inited of int + +type state = { + ifaces: (string*string) StrMap.t; + implems: (string*string*implem_state) StrMap.t; +} + +let empty_state = { + ifaces = StrMap.empty; + implems = StrMap.empty; +} + +let global_state = ref empty_state + +let allow_extension = ref true + +let inited = ref false + +let default_available_units () = + let map : (string*Digest.t*Digest.t*string list) list = + Marshal.from_string (ndl_getmap ()) 0 in + let exe = Sys.executable_name in + let rank = ref 0 in + global_state := + List.fold_left + (fun st (name,crc_intf,crc_impl,syms) -> + rank := !rank + List.length syms; + { + ifaces = StrMap.add name (crc_intf,exe) st.ifaces; + implems = StrMap.add name (crc_impl,exe,Check_inited !rank) st.implems; + } + ) + empty_state + map; + allow_extension := true; + inited := true + +let init () = + if not !inited then default_available_units () + +let add_check_ifaces allow_ext filename ui ifaces = + List.fold_left + (fun ifaces (name, crc) -> + if name = ui.name + then StrMap.add name (crc,filename) ifaces + else + try + let (old_crc,old_src) = StrMap.find name ifaces in + if old_crc <> crc + then raise(Error(Inconsistent_import(name))) + else ifaces + with Not_found -> + if allow_ext then StrMap.add name (crc,filename) ifaces + else raise (Error(Unavailable_unit name)) + ) ifaces ui.imports_cmi + +let check_implems filename ui implems = + List.iter + (fun (name, crc) -> + match name with + |"Out_of_memory" + |"Sys_error" + |"Failure" + |"Invalid_argument" + |"End_of_file" + |"Division_by_zero" + |"Not_found" + |"Match_failure" + |"Stack_overflow" + |"Sys_blocked_io" + |"Assert_failure" + |"Undefined_recursive_module" -> () + | _ -> + try + let (old_crc,old_src,state) = StrMap.find name implems in + if crc <> cmx_not_found_crc && old_crc <> crc + then raise(Error(Inconsistent_implementation(name))) + else match state with + | Check_inited i -> + if ndl_globals_inited() < i + then raise(Error(Unavailable_unit name)) + | Loaded -> () + with Not_found -> + raise (Error(Unavailable_unit name)) + ) ui.imports_cmx + +let loadunits filename handle units state = + let new_ifaces = + List.fold_left + (fun accu ui -> add_check_ifaces !allow_extension filename ui accu) + state.ifaces units in + let new_implems = + List.fold_left + (fun accu ui -> + check_implems filename ui accu; + StrMap.add ui.name (ui.crc,filename,Loaded) accu) + state.implems units in + + let defines = List.flatten (List.map (fun ui -> ui.defines) units) in + + ndl_run handle "_shared_startup"; + List.iter (ndl_run handle) defines; + { implems = new_implems; ifaces = new_ifaces } + +let load priv filename = + init(); + let (filename,handle,units) = read_file filename priv in + let nstate = loadunits filename handle units !global_state in + if not priv then global_state := nstate + +let loadfile filename = load false filename +let loadfile_private filename = load true filename + +let allow_only names = + init(); + let old = !global_state.ifaces in + let ifaces = + List.fold_left + (fun ifaces name -> + try StrMap.add name (StrMap.find name old) ifaces + with Not_found -> ifaces) + StrMap.empty names in + global_state := { !global_state with ifaces = ifaces }; + allow_extension := false + +let prohibit names = + init(); + let ifaces = List.fold_right StrMap.remove names !global_state.ifaces in + global_state := { !global_state with ifaces = ifaces }; + allow_extension := false + +let digest_interface _ _ = + failwith "Dynlink.digest_interface: not implemented in native code" +let add_interfaces _ _ = + failwith "Dynlink.add_interfaces: not implemented in native code" +let add_available_units _ = + failwith "Dynlink.add_available_units: not implemented in native code" +let clear_available_units _ = + failwith "Dynlink.clear_available_units: not implemented in native code" +let allow_unsafe_modules _ = + () + +(* Error report *) + +let error_message = function + Not_a_bytecode_file name -> + name ^ " is not an object file" + | Inconsistent_import name -> + "interface mismatch on " ^ name + | Unavailable_unit name -> + "no implementation available for " ^ name + | Unsafe_file -> + "this object file uses unsafe features" + | Linking_error (name, Undefined_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "Reference to undefined global `" ^ s ^ "'" + | Linking_error (name, Unavailable_primitive s) -> + "error while linking " ^ name ^ ".\n" ^ + "The external function `" ^ s ^ "' is not available" + | Linking_error (name, Uninitialized_global s) -> + "error while linking " ^ name ^ ".\n" ^ + "The module `" ^ s ^ "' is not yet initialized" + | Corrupted_interface name -> + "corrupted interface file " ^ name + | File_not_found name -> + "cannot find file " ^ name ^ " in search path" + | Cannot_open_dll reason -> + "error loading shared library: " ^ reason + | Inconsistent_implementation name -> + "implementation mismatch on " ^ name + +let is_native = true +let adapt_filename f = Filename.chop_extension f ^ ".cmxs" diff --git a/otherlibs/graph/.cvsignore b/otherlibs/graph/.cvsignore new file mode 100644 index 0000000..074dd28 --- /dev/null +++ b/otherlibs/graph/.cvsignore @@ -0,0 +1 @@ +so_locations diff --git a/otherlibs/graph/.depend b/otherlibs/graph/.depend new file mode 100644 index 0000000..d890515 --- /dev/null +++ b/otherlibs/graph/.depend @@ -0,0 +1,152 @@ +color.o: color.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h +draw.o: draw.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +dump_img.o: dump_img.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h image.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +events.o: events.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +fill.o: fill.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +image.o: image.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h image.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/custom.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h +make_img.o: make_img.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h image.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +open.o: open.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/callback.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +point_col.o: point_col.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h +sound.o: sound.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h +subwindow.o: subwindow.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h +text.o: text.c libgraph.h \ + \ + \ + \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +graphics.cmi: +graphicsX11.cmi: +graphics.cmo: graphics.cmi +graphics.cmx: graphics.cmi +graphicsX11.cmo: graphics.cmi graphicsX11.cmi +graphicsX11.cmx: graphics.cmx graphicsX11.cmi diff --git a/otherlibs/graph/Makefile b/otherlibs/graph/Makefile new file mode 100644 index 0000000..c67f425 --- /dev/null +++ b/otherlibs/graph/Makefile @@ -0,0 +1,34 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.42 2007-11-08 09:23:06 frisch Exp $ + +# Makefile for the portable graphics library + +LIBNAME=graphics +COBJS=open.o draw.o fill.o color.o text.o \ + image.o make_img.o dump_img.o point_col.o sound.o events.o \ + subwindow.o +CAMLOBJS=graphics.cmo graphicsX11.cmo +LINKOPTS=-cclib "\"$(X11_LINK)\"" +LDOPTS=-ldopt "$(X11_LINK)" + +EXTRACFLAGS=$(X11_INCLUDES) + +include ../Makefile + +depend: + gcc -MM $(CFLAGS) *.c | sed -e 's, /usr[^ ]*\.h,,g' > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/graph/color.c b/otherlibs/graph/color.c new file mode 100644 index 0000000..8d4a6d5 --- /dev/null +++ b/otherlibs/graph/color.c @@ -0,0 +1,228 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: color.c,v 1.18 2004-05-17 17:10:00 doligez Exp $ */ + +#include "libgraph.h" +#include <X11/Xatom.h> + +/* Cache to speed up the translation rgb -> pixel value. */ + +struct color_cache_entry { + int rgb; /* RGB value with format 0xRRGGBB */ + unsigned long pixel; /* Pixel value */ +}; + +#define Color_cache_size 512 +static struct color_cache_entry color_cache[Color_cache_size]; +#define Empty (-1) +#define Hash_rgb(r,g,b) \ + ((((r) & 0xE0) << 1) + (((g) & 0xE0) >> 2) + (((b) & 0xE0) >> 5)) +#define Color_cache_slack 16 + +static int num_overflows = 0; + +/* rgb -> pixel conversion *without* display connection */ + +Bool caml_gr_direct_rgb = False; +int caml_gr_red_l, caml_gr_red_r; +int caml_gr_green_l, caml_gr_green_r; +int caml_gr_blue_l, caml_gr_blue_r; +unsigned long caml_gr_red_mask, caml_gr_green_mask, caml_gr_blue_mask; + +/* rgb -> pixel table */ +unsigned long caml_gr_red_vals[256]; +unsigned long caml_gr_green_vals[256]; +unsigned long caml_gr_blue_vals[256]; + +void caml_gr_get_shifts( unsigned long mask, int *lsl, int *lsr ) +{ + int l = 0; + int r = 0; + int bit = 1; + if ( mask == 0 ){ *lsl = -1; *lsr = -1; return; } + + for( l = 0; l < 32; l++ ){ + if( bit & mask ){ break; } + bit = bit << 1; + } + for( r = l; r < 32; r++ ){ + if( ! (bit & mask) ){ break; } + bit = bit << 1; + } + /* fix r */ + if ( r == 32 ) { r = 31; } + *lsl = l; + *lsr = 16 - (r - l); +} + +void caml_gr_init_direct_rgb_to_pixel(void) +{ + Visual *visual; + int i; + + visual = DefaultVisual(caml_gr_display,caml_gr_screen); + + if ( visual->class == TrueColor || visual->class == DirectColor ){ + + caml_gr_red_mask = visual->red_mask; + caml_gr_green_mask = visual->green_mask; + caml_gr_blue_mask = visual->blue_mask; + +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "visual %lx %lx %lx\n", + caml_gr_red_mask, + caml_gr_green_mask, + caml_gr_blue_mask); +#endif + + caml_gr_get_shifts(caml_gr_red_mask, &caml_gr_red_l, &caml_gr_red_r); +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "red %d %d\n", caml_gr_red_l, caml_gr_red_r); +#endif + for(i=0; i<256; i++){ + caml_gr_red_vals[i] = (((i << 8) + i) >> caml_gr_red_r) << caml_gr_red_l; + } + + caml_gr_get_shifts(caml_gr_green_mask, &caml_gr_green_l, &caml_gr_green_r); +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "green %d %d\n", caml_gr_green_l, caml_gr_green_r); +#endif + for(i=0; i<256; i++){ + caml_gr_green_vals[i] = (((i << 8) + i) >> caml_gr_green_r) << caml_gr_green_l; + } + + caml_gr_get_shifts(caml_gr_blue_mask, &caml_gr_blue_l, &caml_gr_blue_r); +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "blue %d %d\n", caml_gr_blue_l, caml_gr_blue_r); +#endif + for(i=0; i<256; i++){ + caml_gr_blue_vals[i] = (((i << 8) + i) >> caml_gr_blue_r) << caml_gr_blue_l; + } + + if( caml_gr_red_l < 0 || caml_gr_red_r < 0 || + caml_gr_green_l < 0 || caml_gr_green_r < 0 || + caml_gr_blue_l < 0 || caml_gr_blue_r < 0 ){ +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "Damn, boost failed\n"); +#endif + caml_gr_direct_rgb = False; + } else { +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "Boost ok\n"); +#endif + caml_gr_direct_rgb = True; + } + } else { + /* we cannot use direct_rgb_to_pixel */ +#ifdef QUICKCOLORDEBUG + fprintf(stderr, "No boost!\n"); +#endif + caml_gr_direct_rgb = False; + } +} + +void caml_gr_init_color_cache(void) +{ + int i; + for (i = 0; i < Color_cache_size; i++) color_cache[i].rgb = Empty; + i = Hash_rgb(0, 0, 0); + color_cache[i].rgb = 0; + color_cache[i].pixel = caml_gr_black; + i = Hash_rgb(0xFF, 0xFF, 0xFF); + color_cache[i].rgb = 0xFFFFFF; + color_cache[i].pixel = caml_gr_white; +} + +unsigned long caml_gr_pixel_rgb(int rgb) +{ + unsigned int r, g, b; + int h, i; + XColor color; + + r = (rgb >> 16) & 0xFF; + g = (rgb >> 8) & 0xFF; + b = rgb & 0xFF; + + if (caml_gr_direct_rgb){ + return caml_gr_red_vals[r] | caml_gr_green_vals[g] | caml_gr_blue_vals[b]; + } + + h = Hash_rgb(r, g, b); + i = h; + while(1) { + if (color_cache[i].rgb == Empty) break; + if (color_cache[i].rgb == rgb) return color_cache[i].pixel; + i = (i + 1) & (Color_cache_size - 1); + if (i == h) { + /* Cache is full. Instead of inserting at slot h, which causes + thrashing if many colors hash to the same value, + insert at h + n where n is pseudo-random and + smaller than Color_cache_slack */ + int slack = num_overflows++ & (Color_cache_slack - 1); + i = (i + slack) & (Color_cache_size - 1); + break; + } + } + color.red = r * 0x101; + color.green = g * 0x101; + color.blue = b * 0x101; + XAllocColor(caml_gr_display, caml_gr_colormap, &color); + color_cache[i].rgb = rgb; + color_cache[i].pixel = color.pixel; + return color.pixel; +} + +int caml_gr_rgb_pixel(long unsigned int pixel) +{ + register int r,g,b; + + XColor color; + int i; + + if (caml_gr_direct_rgb) { + r = (((pixel & caml_gr_red_mask) >> caml_gr_red_l) << 8) >> (16 - caml_gr_red_r); + g = (((pixel & caml_gr_green_mask) >> caml_gr_green_l) << 8) >> (16 - caml_gr_green_r); + b = (((pixel & caml_gr_blue_mask) >> caml_gr_blue_l) << 8) >> (16 - caml_gr_blue_r); + return (r << 16) + (g << 8) + b; + } + + if (pixel == caml_gr_black) return 0; + if (pixel == caml_gr_white) return 0xFFFFFF; + + /* Probably faster to do a linear search than to query the X server. */ + for (i = 0; i < Color_cache_size; i++) { + if (color_cache[i].rgb != Empty && color_cache[i].pixel == pixel) + return color_cache[i].rgb; + } + color.pixel = pixel; + XQueryColor(caml_gr_display, caml_gr_colormap, &color); + return + ((color.red >> 8) << 16) + ((color.green >> 8) << 8) + (color.blue >> 8); +} + +value caml_gr_set_color(value vrgb) +{ + int xcolor; + caml_gr_check_open(); + caml_gr_color = Int_val(vrgb); + if (caml_gr_color >= 0 ){ + xcolor = caml_gr_pixel_rgb(Int_val(vrgb)); + XSetForeground(caml_gr_display, caml_gr_window.gc, xcolor); + XSetForeground(caml_gr_display, caml_gr_bstore.gc, xcolor); + } else { + XSetForeground(caml_gr_display, caml_gr_window.gc, caml_gr_background); + XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background); + } + return Val_unit; +} diff --git a/otherlibs/graph/draw.c b/otherlibs/graph/draw.c new file mode 100644 index 0000000..fffec8b --- /dev/null +++ b/otherlibs/graph/draw.c @@ -0,0 +1,123 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: draw.c,v 1.19 2004-05-30 14:11:41 xleroy Exp $ */ + +#include "libgraph.h" +#include <alloc.h> + +value caml_gr_plot(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XDrawPoint(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, x, Bcvt(y)); + if(caml_gr_display_modeflag) { + XDrawPoint(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, x, Wcvt(y)); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_moveto(value vx, value vy) +{ + caml_gr_x = Int_val(vx); + caml_gr_y = Int_val(vy); + return Val_unit; +} + +value caml_gr_current_x(void) +{ + return Val_int(caml_gr_x); +} + +value caml_gr_current_y(void) +{ + return Val_int(caml_gr_y); +} + +value caml_gr_lineto(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XDrawLine(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + caml_gr_x, Bcvt(caml_gr_y), x, Bcvt(y)); + if(caml_gr_display_modeflag) { + XDrawLine(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + caml_gr_x, Wcvt(caml_gr_y), x, Wcvt(y)); + XFlush(caml_gr_display); + } + caml_gr_x = x; + caml_gr_y = y; + return Val_unit; +} + +value caml_gr_draw_rect(value vx, value vy, value vw, value vh) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int w = Int_val(vw); + int h = Int_val(vh); + + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XDrawRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + x, Bcvt(y) - h, w, h); + if(caml_gr_display_modeflag) { + XDrawRectangle(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + x, Wcvt(y) - h, w, h); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_draw_arc_nat(value vx, value vy, value vrx, value vry, value va1, value va2) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int rx = Int_val(vrx); + int ry = Int_val(vry); + int a1 = Int_val(va1); + int a2 = Int_val(va2); + + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XDrawArc(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + x - rx, Bcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64); + if(caml_gr_display_modeflag) { + XDrawArc(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + x - rx, Wcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_draw_arc(value *argv, int argc) +{ + return caml_gr_draw_arc_nat(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); +} + +value caml_gr_set_line_width(value vwidth) +{ + int width = Int_val(vwidth); + + caml_gr_check_open(); + XSetLineAttributes(caml_gr_display, caml_gr_window.gc, + width, LineSolid, CapRound, JoinRound); + XSetLineAttributes(caml_gr_display, caml_gr_bstore.gc, + width, LineSolid, CapRound, JoinRound); + return Val_unit; +} diff --git a/otherlibs/graph/dump_img.c b/otherlibs/graph/dump_img.c new file mode 100644 index 0000000..07f9338 --- /dev/null +++ b/otherlibs/graph/dump_img.c @@ -0,0 +1,55 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dump_img.c,v 1.11 2004-03-24 15:02:04 starynke Exp $ */ + +#include "libgraph.h" +#include "image.h" +#include <alloc.h> +#include <memory.h> + +value caml_gr_dump_image(value image) +{ + int width, height, i, j; + XImage * idata, * imask; + value m = Val_unit; + + Begin_roots2(image, m); + caml_gr_check_open(); + width = Width_im(image); + height = Height_im(image); + m = alloc(height, 0); + for (i = 0; i < height; i++) { + value v = alloc(width, 0); + modify(&Field(m, i), v); + } + + idata = + XGetImage(caml_gr_display, Data_im(image), 0, 0, width, height, (-1), ZPixmap); + for (i = 0; i < height; i++) + for (j = 0; j < width; j++) + Field(Field(m, i), j) = Val_int(caml_gr_rgb_pixel(XGetPixel(idata, j, i))); + XDestroyImage(idata); + + if (Mask_im(image) != None) { + imask = + XGetImage(caml_gr_display, Mask_im(image), 0, 0, width, height, 1, ZPixmap); + for (i = 0; i < height; i++) + for (j = 0; j < width; j++) + if (XGetPixel(imask, j, i) == 0) + Field(Field(m, i), j) = Val_int(Transparent); + XDestroyImage(imask); + } + End_roots(); + return m; +} diff --git a/otherlibs/graph/events.c b/otherlibs/graph/events.c new file mode 100644 index 0000000..9ea436a --- /dev/null +++ b/otherlibs/graph/events.c @@ -0,0 +1,269 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: events.c,v 1.18 2005-08-13 20:59:37 doligez Exp $ */ + +#include <signal.h> +#include "libgraph.h" +#include <alloc.h> +#include <signals.h> +#include <sys/types.h> +#include <sys/time.h> +#ifdef HAS_SYS_SELECT_H +#include <sys/select.h> +#endif +#include <string.h> +#include <unistd.h> + +struct event_data { + short kind; + short mouse_x, mouse_y; + unsigned char button; + unsigned char key; +}; + +static struct event_data caml_gr_queue[SIZE_QUEUE]; +static unsigned int caml_gr_head = 0; /* position of next read */ +static unsigned int caml_gr_tail = 0; /* position of next write */ + +#define QueueIsEmpty (caml_gr_tail == caml_gr_head) + +static void caml_gr_enqueue_event(int kind, int mouse_x, int mouse_y, + int button, int key) +{ + struct event_data * ev; + + ev = &(caml_gr_queue[caml_gr_tail]); + ev->kind = kind; + ev->mouse_x = mouse_x; + ev->mouse_y = mouse_y; + ev->button = (button != 0); + ev->key = key; + caml_gr_tail = (caml_gr_tail + 1) % SIZE_QUEUE; + /* If queue was full, it now appears empty; drop oldest entry from queue. */ + if (QueueIsEmpty) caml_gr_head = (caml_gr_head + 1) % SIZE_QUEUE; +} + +#define BUTTON_STATE(state) \ + ((state) & (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask)) + +void caml_gr_handle_event(XEvent * event) +{ + switch (event->type) { + + case Expose: + XCopyArea(caml_gr_display, caml_gr_bstore.win, caml_gr_window.win, caml_gr_window.gc, + event->xexpose.x, event->xexpose.y + caml_gr_bstore.h - caml_gr_window.h, + event->xexpose.width, event->xexpose.height, + event->xexpose.x, event->xexpose.y); + XFlush(caml_gr_display); + break; + + case ConfigureNotify: + caml_gr_window.w = event->xconfigure.width; + caml_gr_window.h = event->xconfigure.height; + if (caml_gr_window.w > caml_gr_bstore.w || caml_gr_window.h > caml_gr_bstore.h) { + + /* Allocate a new backing store large enough to accomodate + both the old backing store and the current window. */ + struct canvas newbstore; + newbstore.w = max(caml_gr_window.w, caml_gr_bstore.w); + newbstore.h = max(caml_gr_window.h, caml_gr_bstore.h); + newbstore.win = + XCreatePixmap(caml_gr_display, caml_gr_window.win, newbstore.w, newbstore.h, + XDefaultDepth(caml_gr_display, caml_gr_screen)); + newbstore.gc = XCreateGC(caml_gr_display, newbstore.win, 0, NULL); + XSetBackground(caml_gr_display, newbstore.gc, caml_gr_white); + XSetForeground(caml_gr_display, newbstore.gc, caml_gr_white); + XFillRectangle(caml_gr_display, newbstore.win, newbstore.gc, + 0, 0, newbstore.w, newbstore.h); + XSetForeground(caml_gr_display, newbstore.gc, caml_gr_color); + if (caml_gr_font != NULL) + XSetFont(caml_gr_display, newbstore.gc, caml_gr_font->fid); + + /* Copy the old backing store into the new one */ + XCopyArea(caml_gr_display, caml_gr_bstore.win, newbstore.win, newbstore.gc, + 0, 0, caml_gr_bstore.w, caml_gr_bstore.h, 0, newbstore.h - caml_gr_bstore.h); + + /* Free the old backing store */ + XFreeGC(caml_gr_display, caml_gr_bstore.gc); + XFreePixmap(caml_gr_display, caml_gr_bstore.win); + + /* Use the new backing store */ + caml_gr_bstore = newbstore; + XFlush(caml_gr_display); + } + break; + + case MappingNotify: + XRefreshKeyboardMapping(&(event->xmapping)); + break; + + case KeyPress: + { KeySym thekey; + char keytxt[256]; + int nchars; + char * p; + nchars = XLookupString(&(event->xkey), keytxt, sizeof(keytxt), + &thekey, 0); + for (p = keytxt; nchars > 0; p++, nchars--) + caml_gr_enqueue_event(event->type, event->xkey.x, event->xkey.y, + BUTTON_STATE(event->xkey.state), *p); + break; + } + + case ButtonPress: + case ButtonRelease: + caml_gr_enqueue_event(event->type, event->xbutton.x, event->xbutton.y, + event->type == ButtonPress, 0); + break; + + case MotionNotify: + caml_gr_enqueue_event(event->type, event->xmotion.x, event->xmotion.y, + BUTTON_STATE(event->xmotion.state), 0); + break; + } +} + +static value caml_gr_wait_allocate_result(int mouse_x, int mouse_y, int button, + int keypressed, int key) +{ + value res = alloc_small(5, 0); + Field(res, 0) = Val_int(mouse_x); + Field(res, 1) = Val_int(mouse_y == -1 ? -1 : Wcvt(mouse_y)); + Field(res, 2) = Val_bool(button); + Field(res, 3) = Val_bool(keypressed); + Field(res, 4) = Val_int(key & 0xFF); + return res; +} + +static value caml_gr_wait_event_poll(void) +{ + int mouse_x, mouse_y, button, key, keypressed; + Window rootwin, childwin; + int root_x, root_y, win_x, win_y; + unsigned int modifiers; + unsigned int i; + + if (XQueryPointer(caml_gr_display, caml_gr_window.win, + &rootwin, &childwin, + &root_x, &root_y, &win_x, &win_y, + &modifiers)) { + mouse_x = win_x; + mouse_y = win_y; + } else { + mouse_x = -1; + mouse_y = -1; + } + button = modifiers & (Button1Mask | Button2Mask | Button3Mask + | Button4Mask | Button5Mask); + /* Look inside event queue for pending KeyPress events */ + key = 0; + keypressed = False; + for (i = caml_gr_head; i != caml_gr_tail; i = (i + 1) % SIZE_QUEUE) { + if (caml_gr_queue[i].kind == KeyPress) { + keypressed = True; + key = caml_gr_queue[i].key; + break; + } + } + return caml_gr_wait_allocate_result(mouse_x, mouse_y, button, keypressed, key); +} + +static value caml_gr_wait_event_in_queue(long mask) +{ + struct event_data * ev; + /* Pop events in queue until one matches mask. */ + while (caml_gr_head != caml_gr_tail) { + ev = &(caml_gr_queue[caml_gr_head]); + caml_gr_head = (caml_gr_head + 1) % SIZE_QUEUE; + if ((ev->kind == KeyPress && (mask & KeyPressMask)) + || (ev->kind == ButtonPress && (mask & ButtonPressMask)) + || (ev->kind == ButtonRelease && (mask & ButtonReleaseMask)) + || (ev->kind == MotionNotify && (mask & PointerMotionMask))) + return caml_gr_wait_allocate_result(ev->mouse_x, ev->mouse_y, + ev->button, ev->kind == KeyPress, + ev->key); + } + return Val_false; +} + +static value caml_gr_wait_event_blocking(long mask) +{ + XEvent event; + fd_set readfds; + value res; + + /* First see if we have a matching event in the queue */ + res = caml_gr_wait_event_in_queue(mask); + if (res != Val_false) return res; + + /* Increase the selected events if required */ + if ((mask & ~caml_gr_selected_events) != 0) { + caml_gr_selected_events |= mask; + XSelectInput(caml_gr_display, caml_gr_window.win, caml_gr_selected_events); + } + + /* Replenish our event queue from that of X11 */ + caml_gr_ignore_sigio = True; + while (1) { + if (XCheckMaskEvent(caml_gr_display, -1 /*all events*/, &event)) { + /* One event available: add it to our queue */ + caml_gr_handle_event(&event); + /* See if we now have a matching event */ + res = caml_gr_wait_event_in_queue(mask); + if (res != Val_false) break; + } else { + /* No event available: block on input socket until one is */ + FD_ZERO(&readfds); + FD_SET(ConnectionNumber(caml_gr_display), &readfds); + enter_blocking_section(); + select(FD_SETSIZE, &readfds, NULL, NULL, NULL); + leave_blocking_section(); + caml_gr_check_open(); /* in case another thread closed the display */ + } + } + caml_gr_ignore_sigio = False; + + /* Return result */ + return res; +} + +value caml_gr_wait_event(value eventlist) /* ML */ +{ + int mask; + Bool poll; + + caml_gr_check_open(); + mask = 0; + poll = False; + while (eventlist != Val_int(0)) { + switch (Int_val(Field(eventlist, 0))) { + case 0: /* Button_down */ + mask |= ButtonPressMask | OwnerGrabButtonMask; break; + case 1: /* Button_up */ + mask |= ButtonReleaseMask | OwnerGrabButtonMask; break; + case 2: /* Key_pressed */ + mask |= KeyPressMask; break; + case 3: /* Mouse_motion */ + mask |= PointerMotionMask; break; + case 4: /* Poll */ + poll = True; break; + } + eventlist = Field(eventlist, 1); + } + if (poll) + return caml_gr_wait_event_poll(); + else + return caml_gr_wait_event_blocking(mask); +} diff --git a/otherlibs/graph/fill.c b/otherlibs/graph/fill.c new file mode 100644 index 0000000..b9859cf --- /dev/null +++ b/otherlibs/graph/fill.c @@ -0,0 +1,88 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fill.c,v 1.14 2004-05-30 14:11:41 xleroy Exp $ */ + +#include "libgraph.h" +#include <memory.h> + +value caml_gr_fill_rect(value vx, value vy, value vw, value vh) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int w = Int_val(vw); + int h = Int_val(vh); + + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XFillRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + x, Bcvt(y) - h, w + 1, h + 1); + if(caml_gr_display_modeflag) { + XFillRectangle(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + x, Wcvt(y) - h, w + 1, h + 1); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_fill_poly(value array) +{ + XPoint * points; + int npoints, i; + + caml_gr_check_open(); + npoints = Wosize_val(array); + points = (XPoint *) stat_alloc(npoints * sizeof(XPoint)); + for (i = 0; i < npoints; i++) { + points[i].x = Int_val(Field(Field(array, i), 0)); + points[i].y = Bcvt(Int_val(Field(Field(array, i), 1))); + } + if(caml_gr_remember_modeflag) + XFillPolygon(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, points, + npoints, Complex, CoordModeOrigin); + if(caml_gr_display_modeflag) { + for (i = 0; i < npoints; i++) + points[i].y = BtoW(points[i].y); + XFillPolygon(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, points, + npoints, Complex, CoordModeOrigin); + XFlush(caml_gr_display); + } + stat_free((char *) points); + return Val_unit; +} + +value caml_gr_fill_arc_nat(value vx, value vy, value vrx, value vry, value va1, value va2) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int rx = Int_val(vrx); + int ry = Int_val(vry); + int a1 = Int_val(va1); + int a2 = Int_val(va2); + + caml_gr_check_open(); + if(caml_gr_remember_modeflag) + XFillArc(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + x - rx, Bcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64); + if(caml_gr_display_modeflag) { + XFillArc(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + x - rx, Wcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_fill_arc(value *argv, int argc) +{ + return caml_gr_fill_arc_nat(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); +} diff --git a/otherlibs/graph/graphics.ml b/otherlibs/graph/graphics.ml new file mode 100644 index 0000000..c56be35 --- /dev/null +++ b/otherlibs/graph/graphics.ml @@ -0,0 +1,256 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: graphics.ml,v 1.26 2005-08-13 20:59:37 doligez Exp $ *) + +exception Graphic_failure of string + +(* Initializations *) + +let _ = + Callback.register_exception "Graphics.Graphic_failure" (Graphic_failure "") + +external raw_open_graph: string -> unit = "caml_gr_open_graph" +external raw_close_graph: unit -> unit = "caml_gr_close_graph" +external sigio_signal: unit -> int = "caml_gr_sigio_signal" +external sigio_handler: int -> unit = "caml_gr_sigio_handler" + +let unix_open_graph arg = + Sys.set_signal (sigio_signal()) (Sys.Signal_handle sigio_handler); + raw_open_graph arg + +let unix_close_graph () = + Sys.set_signal (sigio_signal()) Sys.Signal_ignore; + raw_close_graph () + +let (open_graph, close_graph) = + match Sys.os_type with + | "Unix" | "Cygwin" -> (unix_open_graph, unix_close_graph) + | "Win32" -> (raw_open_graph, raw_close_graph) + | "MacOS" -> (raw_open_graph, raw_close_graph) + | _ -> invalid_arg ("Graphics: unknown OS type: " ^ Sys.os_type) + +external set_window_title : string -> unit = "caml_gr_set_window_title" +external resize_window : int -> int -> unit = "caml_gr_resize_window" +external clear_graph : unit -> unit = "caml_gr_clear_graph" +external size_x : unit -> int = "caml_gr_size_x" +external size_y : unit -> int = "caml_gr_size_y" + +(* Double-buffering *) + +external display_mode : bool -> unit = "caml_gr_display_mode" +external remember_mode : bool -> unit = "caml_gr_remember_mode" +external synchronize : unit -> unit = "caml_gr_synchronize" + +let auto_synchronize = function + | true -> display_mode true; remember_mode true; synchronize () + | false -> display_mode false; remember_mode true +;; + + +(* Colors *) + +type color = int + +let rgb r g b = (r lsl 16) + (g lsl 8) + b + +external set_color : color -> unit = "caml_gr_set_color" + +let black = 0x000000 +and white = 0xFFFFFF +and red = 0xFF0000 +and green = 0x00FF00 +and blue = 0x0000FF +and yellow = 0xFFFF00 +and cyan = 0x00FFFF +and magenta = 0xFF00FF + +let background = white +and foreground = black + +(* Drawing *) + +external plot : int -> int -> unit = "caml_gr_plot" +let plots points = + for i = 0 to Array.length points - 1 do + let (x, y) = points.(i) in + plot x y; + done +;; +external point_color : int -> int -> color = "caml_gr_point_color" +external moveto : int -> int -> unit = "caml_gr_moveto" +external current_x : unit -> int = "caml_gr_current_x" +external current_y : unit -> int = "caml_gr_current_y" +let current_point () = current_x (), current_y () +external lineto : int -> int -> unit = "caml_gr_lineto" +let rlineto x y = lineto (current_x () + x) (current_y () + y) +let rmoveto x y = moveto (current_x () + x) (current_y () + y) + +external raw_draw_rect : int -> int -> int -> int -> unit = "caml_gr_draw_rect" +let draw_rect x y w h = + if w < 0 || h < 0 then raise (Invalid_argument "draw_rect") + else raw_draw_rect x y w h +;; + +let draw_poly, draw_poly_line = + let dodraw close_flag points = + if Array.length points > 0 then begin + let (savex, savey) = current_point () in + moveto (fst points.(0)) (snd points.(0)); + for i = 1 to Array.length points - 1 do + let (x, y) = points.(i) in + lineto x y; + done; + if close_flag then lineto (fst points.(0)) (snd points.(0)); + moveto savex savey; + end; + in dodraw true, dodraw false +;; +let draw_segments segs = + let (savex, savey) = current_point () in + for i = 0 to Array.length segs - 1 do + let (x1, y1, x2, y2) = segs.(i) in + moveto x1 y1; + lineto x2 y2; + done; + moveto savex savey; +;; + +external raw_draw_arc : int -> int -> int -> int -> int -> int -> unit + = "caml_gr_draw_arc" "caml_gr_draw_arc_nat" +let draw_arc x y rx ry a1 a2 = + if rx < 0 || ry < 0 then raise (Invalid_argument "draw_arc/ellipse/circle") + else raw_draw_arc x y rx ry a1 a2 +;; + +let draw_ellipse x y rx ry = draw_arc x y rx ry 0 360 +let draw_circle x y r = draw_arc x y r r 0 360 + +external raw_set_line_width : int -> unit = "caml_gr_set_line_width" +let set_line_width w = + if w < 0 then raise (Invalid_argument "set_line_width") + else raw_set_line_width w +;; + +external raw_fill_rect : int -> int -> int -> int -> unit = "caml_gr_fill_rect" +let fill_rect x y w h = + if w < 0 || h < 0 then raise (Invalid_argument "fill_rect") + else raw_fill_rect x y w h +;; + +external fill_poly : (int * int) array -> unit = "caml_gr_fill_poly" +external raw_fill_arc : int -> int -> int -> int -> int -> int -> unit + = "caml_gr_fill_arc" "caml_gr_fill_arc_nat" +let fill_arc x y rx ry a1 a2 = + if rx < 0 || ry < 0 then raise (Invalid_argument "fill_arc/ellipse/circle") + else raw_fill_arc x y rx ry a1 a2 +;; + +let fill_ellipse x y rx ry = fill_arc x y rx ry 0 360 +let fill_circle x y r = fill_arc x y r r 0 360 + +(* Text *) + +external draw_char : char -> unit = "caml_gr_draw_char" +external draw_string : string -> unit = "caml_gr_draw_string" +external set_font : string -> unit = "caml_gr_set_font" +external set_text_size : int -> unit = "caml_gr_set_text_size" +external text_size : string -> int * int = "caml_gr_text_size" + +(* Images *) + +type image + +let transp = -1 + +external make_image : color array array -> image = "caml_gr_make_image" +external dump_image : image -> color array array = "caml_gr_dump_image" +external draw_image : image -> int -> int -> unit = "caml_gr_draw_image" +external create_image : int -> int -> image = "caml_gr_create_image" +external blit_image : image -> int -> int -> unit = "caml_gr_blit_image" + +let get_image x y w h = + let image = create_image w h in + blit_image image x y; + image + +(* Events *) + +type status = + { mouse_x : int; + mouse_y : int; + button : bool; + keypressed : bool; + key : char } + +type event = + Button_down + | Button_up + | Key_pressed + | Mouse_motion + | Poll + +external wait_next_event : event list -> status = "caml_gr_wait_event" + +let mouse_pos () = + let e = wait_next_event [Poll] in (e.mouse_x, e.mouse_y) + +let button_down () = + let e = wait_next_event [Poll] in e.button + +let read_key () = + let e = wait_next_event [Key_pressed] in e.key + +let key_pressed () = + let e = wait_next_event [Poll] in e.keypressed + +(*** Sound *) + +external sound : int -> int -> unit = "caml_gr_sound" + +(* Splines *) +let add (x1, y1) (x2, y2) = (x1 +. x2, y1 +. y2) +and sub (x1, y1) (x2, y2) = (x1 -. x2, y1 -. y2) +and middle (x1, y1) (x2, y2) = ((x1 +. x2) /. 2.0, (y1 +. y2) /. 2.0) +and area (x1, y1) (x2, y2) = abs_float (x1 *. y2 -. x2 *. y1) +and norm (x1, y1) = sqrt (x1 *. x1 +. y1 *. y1);; + +let test a b c d = + let v = sub d a in + let s = norm v in + area v (sub a b) <= s && area v (sub a c) <= s;; + +let spline a b c d = + let rec spl accu a b c d = + if test a b c d then d :: accu else + let a' = middle a b + and o = middle b c in + let b' = middle a' o + and d' = middle c d in + let c' = middle o d' in + let i = middle b' c' in + spl (spl accu a a' b' i) i c' d' d in + spl [a] a b c d;; + +let curveto b c (x, y as d) = + let float_point (x, y) = (float_of_int x, float_of_int y) in + let round f = int_of_float (f +. 0.5) in + let int_point (x, y) = (round x, round y) in + let points = + spline + (float_point (current_point ())) + (float_point b) (float_point c) (float_point d) in + draw_poly_line + (Array.of_list (List.map int_point points)); + moveto x y;; + diff --git a/otherlibs/graph/graphics.mli b/otherlibs/graph/graphics.mli new file mode 100644 index 0000000..1975439 --- /dev/null +++ b/otherlibs/graph/graphics.mli @@ -0,0 +1,379 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: graphics.mli,v 1.37 2005-08-13 20:59:37 doligez Exp $ *) + +(** Machine-independent graphics primitives. *) + +exception Graphic_failure of string +(** Raised by the functions below when they encounter an error. *) + + +(** {6 Initializations} *) + +val open_graph : string -> unit +(** Show the graphics window or switch the screen to graphic mode. + The graphics window is cleared and the current point is set + to (0, 0). The string argument is used to pass optional + information on the desired graphics mode, the graphics window + size, and so on. Its interpretation is implementation-dependent. + If the empty string is given, a sensible default is selected. *) + +val close_graph : unit -> unit +(** Delete the graphics window or switch the screen back to text mode. *) + +val set_window_title : string -> unit +(** Set the title of the graphics window. *) + +val resize_window : int -> int -> unit +(** Resize and erase the graphics window. *) + +external clear_graph : unit -> unit = "caml_gr_clear_graph" +(** Erase the graphics window. *) + +external size_x : unit -> int = "caml_gr_size_x" +(** See {!Graphics.size_y}. *) + +external size_y : unit -> int = "caml_gr_size_y" +(** Return the size of the graphics window. Coordinates of the screen + pixels range over [0 .. size_x()-1] and [0 .. size_y()-1]. + Drawings outside of this rectangle are clipped, without causing + an error. The origin (0,0) is at the lower left corner. *) + +(** {6 Colors} *) + +type color = int +(** A color is specified by its R, G, B components. Each component + is in the range [0..255]. The three components are packed in + an [int]: [0xRRGGBB], where [RR] are the two hexadecimal digits for + the red component, [GG] for the green component, [BB] for the + blue component. *) + +val rgb : int -> int -> int -> color +(** [rgb r g b] returns the integer encoding the color with red + component [r], green component [g], and blue component [b]. + [r], [g] and [b] are in the range [0..255]. *) + +external set_color : color -> unit = "caml_gr_set_color" +(** Set the current drawing color. *) + +val background : color +(** See {!Graphics.foreground}.*) + +val foreground : color +(** Default background and foreground colors (usually, either black + foreground on a white background or white foreground on a + black background). + {!Graphics.clear_graph} fills the screen with the [background] color. + The initial drawing color is [foreground]. *) + + +(** {7 Some predefined colors} *) + +val black : color +val white : color +val red : color +val green : color +val blue : color +val yellow : color +val cyan : color +val magenta : color + + +(** {6 Point and line drawing} *) + +external plot : int -> int -> unit = "caml_gr_plot" +(** Plot the given point with the current drawing color. *) + +val plots : (int * int) array -> unit +(** Plot the given points with the current drawing color. *) + +external point_color : int -> int -> color = "caml_gr_point_color" +(** Return the color of the given point in the backing store + (see "Double buffering" below). *) + +external moveto : int -> int -> unit = "caml_gr_moveto" +(** Position the current point. *) + +val rmoveto : int -> int -> unit +(** [rmoveto dx dy] translates the current point by the given vector. *) + +external current_x : unit -> int = "caml_gr_current_x" +(** Return the abscissa of the current point. *) + +external current_y : unit -> int = "caml_gr_current_y" +(** Return the ordinate of the current point. *) + +val current_point : unit -> int * int +(** Return the position of the current point. *) + +external lineto : int -> int -> unit = "caml_gr_lineto" +(** Draw a line with endpoints the current point and the given point, + and move the current point to the given point. *) + +val rlineto : int -> int -> unit +(** Draw a line with endpoints the current point and the + current point translated of the given vector, + and move the current point to this point. *) + +val curveto : int * int -> int * int -> int * int -> unit +(** [curveto b c d] draws a cubic Bezier curve starting from + the current point to point [d], with control points [b] and + [c], and moves the current point to [d]. *) + +val draw_rect : int -> int -> int -> int -> unit +(** [draw_rect x y w h] draws the rectangle with lower left corner + at [x,y], width [w] and height [h]. + The current point is unchanged. + Raise [Invalid_argument] if [w] or [h] is negative. *) + +val draw_poly_line : (int * int) array -> unit +(** [draw_poly_line points] draws the line that joins the + points given by the array argument. + The array contains the coordinates of the vertices of the + polygonal line, which need not be closed. + The current point is unchanged. *) + +val draw_poly : (int * int) array -> unit +(** [draw_poly polygon] draws the given polygon. + The array contains the coordinates of the vertices of the + polygon. + The current point is unchanged. *) + +val draw_segments : (int * int * int * int) array -> unit +(** [draw_segments segments] draws the segments given in the array + argument. Each segment is specified as a quadruple + [(x0, y0, x1, y1)] where [(x0, y0)] and [(x1, y1)] are + the coordinates of the end points of the segment. + The current point is unchanged. *) + +val draw_arc : int -> int -> int -> int -> int -> int -> unit +(** [draw_arc x y rx ry a1 a2] draws an elliptical arc with center + [x,y], horizontal radius [rx], vertical radius [ry], from angle + [a1] to angle [a2] (in degrees). The current point is unchanged. + Raise [Invalid_argument] if [rx] or [ry] is negative. *) + +val draw_ellipse : int -> int -> int -> int -> unit +(** [draw_ellipse x y rx ry] draws an ellipse with center + [x,y], horizontal radius [rx] and vertical radius [ry]. + The current point is unchanged. + Raise [Invalid_argument] if [rx] or [ry] is negative. *) + +val draw_circle : int -> int -> int -> unit +(** [draw_circle x y r] draws a circle with center [x,y] and + radius [r]. The current point is unchanged. + Raise [Invalid_argument] if [r] is negative. *) + +val set_line_width : int -> unit +(** Set the width of points and lines drawn with the functions above. + Under X Windows, [set_line_width 0] selects a width of 1 pixel + and a faster, but less precise drawing algorithm than the one + used when [set_line_width 1] is specified. + Raise [Invalid_argument] if the argument is negative. *) + +(** {6 Text drawing} *) + +external draw_char : char -> unit = "caml_gr_draw_char" +(** See {!Graphics.draw_string}.*) + +external draw_string : string -> unit = "caml_gr_draw_string" +(** Draw a character or a character string with lower left corner + at current position. After drawing, the current position is set + to the lower right corner of the text drawn. *) + +external set_font : string -> unit = "caml_gr_set_font" +(** Set the font used for drawing text. + The interpretation of the argument to [set_font] + is implementation-dependent. *) + +val set_text_size : int -> unit +(** Set the character size used for drawing text. + The interpretation of the argument to [set_text_size] + is implementation-dependent. *) + +external text_size : string -> int * int = "caml_gr_text_size" +(** Return the dimensions of the given text, if it were drawn with + the current font and size. *) + + +(** {6 Filling} *) + +val fill_rect : int -> int -> int -> int -> unit +(** [fill_rect x y w h] fills the rectangle with lower left corner + at [x,y], width [w] and height [h], with the current color. + Raise [Invalid_argument] if [w] or [h] is negative. *) + +external fill_poly : (int * int) array -> unit = "caml_gr_fill_poly" +(** Fill the given polygon with the current color. The array + contains the coordinates of the vertices of the polygon. *) + +val fill_arc : int -> int -> int -> int -> int -> int -> unit +(** Fill an elliptical pie slice with the current color. The + parameters are the same as for {!Graphics.draw_arc}. *) + +val fill_ellipse : int -> int -> int -> int -> unit +(** Fill an ellipse with the current color. The + parameters are the same as for {!Graphics.draw_ellipse}. *) + +val fill_circle : int -> int -> int -> unit +(** Fill a circle with the current color. The + parameters are the same as for {!Graphics.draw_circle}. *) + + +(** {6 Images} *) + +type image +(** The abstract type for images, in internal representation. + Externally, images are represented as matrices of colors. *) + +val transp : color +(** In matrices of colors, this color represent a ``transparent'' + point: when drawing the corresponding image, all pixels on the + screen corresponding to a transparent pixel in the image will + not be modified, while other points will be set to the color + of the corresponding point in the image. This allows superimposing + an image over an existing background. *) + +external make_image : color array array -> image = "caml_gr_make_image" +(** Convert the given color matrix to an image. + Each sub-array represents one horizontal line. All sub-arrays + must have the same length; otherwise, exception [Graphic_failure] + is raised. *) + +external dump_image : image -> color array array = "caml_gr_dump_image" +(** Convert an image to a color matrix. *) + +external draw_image : image -> int -> int -> unit = "caml_gr_draw_image" +(** Draw the given image with lower left corner at the given point. *) + +val get_image : int -> int -> int -> int -> image +(** Capture the contents of a rectangle on the screen as an image. + The parameters are the same as for {!Graphics.fill_rect}. *) + +external create_image : int -> int -> image = "caml_gr_create_image" +(** [create_image w h] returns a new image [w] pixels wide and [h] + pixels tall, to be used in conjunction with [blit_image]. + The initial image contents are random, except that no point + is transparent. *) + +external blit_image : image -> int -> int -> unit = "caml_gr_blit_image" +(** [blit_image img x y] copies screen pixels into the image [img], + modifying [img] in-place. The pixels copied are those inside the + rectangle with lower left corner at [x,y], and width and height + equal to those of the image. Pixels that were transparent in + [img] are left unchanged. *) + + +(** {6 Mouse and keyboard events} *) + +type status = + { mouse_x : int; (** X coordinate of the mouse *) + mouse_y : int; (** Y coordinate of the mouse *) + button : bool; (** true if a mouse button is pressed *) + keypressed : bool; (** true if a key has been pressed *) + key : char; (** the character for the key pressed *) + } +(** To report events. *) + + +type event = + Button_down (** A mouse button is pressed *) + | Button_up (** A mouse button is released *) + | Key_pressed (** A key is pressed *) + | Mouse_motion (** The mouse is moved *) + | Poll (** Don't wait; return immediately *) +(** To specify events to wait for. *) + + +external wait_next_event : event list -> status = "caml_gr_wait_event" +(** Wait until one of the events specified in the given event list + occurs, and return the status of the mouse and keyboard at + that time. If [Poll] is given in the event list, return immediately + with the current status. If the mouse cursor is outside of the + graphics window, the [mouse_x] and [mouse_y] fields of the event are + outside the range [0..size_x()-1, 0..size_y()-1]. Keypresses + are queued, and dequeued one by one when the [Key_pressed] + event is specified. *) + +(** {6 Mouse and keyboard polling} *) + +val mouse_pos : unit -> int * int +(** Return the position of the mouse cursor, relative to the + graphics window. If the mouse cursor is outside of the graphics + window, [mouse_pos()] returns a point outside of the range + [0..size_x()-1, 0..size_y()-1]. *) + +val button_down : unit -> bool +(** Return [true] if the mouse button is pressed, [false] otherwise. *) + +val read_key : unit -> char +(** Wait for a key to be pressed, and return the corresponding + character. Keypresses are queued. *) + +val key_pressed : unit -> bool +(** Return [true] if a keypress is available; that is, if [read_key] + would not block. *) + + +(** {6 Sound} *) + +external sound : int -> int -> unit = "caml_gr_sound" +(** [sound freq dur] plays a sound at frequency [freq] (in hertz) + for a duration [dur] (in milliseconds). *) + +(** {6 Double buffering} *) + +val auto_synchronize : bool -> unit +(** By default, drawing takes place both on the window displayed + on screen, and in a memory area (the ``backing store''). + The backing store image is used to re-paint the on-screen + window when necessary. + + To avoid flicker during animations, it is possible to turn + off on-screen drawing, perform a number of drawing operations + in the backing store only, then refresh the on-screen window + explicitly. + + [auto_synchronize false] turns on-screen drawing off. All + subsequent drawing commands are performed on the backing store + only. + + [auto_synchronize true] refreshes the on-screen window from + the backing store (as per [synchronize]), then turns on-screen + drawing back on. All subsequent drawing commands are performed + both on screen and in the backing store. + + The default drawing mode corresponds to [auto_synchronize true]. *) + +external synchronize : unit -> unit = "caml_gr_synchronize" +(** Synchronize the backing store and the on-screen window, by + copying the contents of the backing store onto the graphics + window. *) + + +external display_mode : bool -> unit = "caml_gr_display_mode" +(** Set display mode on or off. When turned on, drawings are done + in the graphics window; when turned off, drawings do not affect + the graphics window. This occurs independently of + drawing into the backing store (see the function {!Graphics.remember_mode} + below). Default display mode is on. *) + + +external remember_mode : bool -> unit = "caml_gr_remember_mode" +(** Set remember mode on or off. When turned on, drawings are done + in the backing store; when turned off, the backing store is + unaffected by drawings. This occurs independently of drawing + onto the graphics window (see the function {!Graphics.display_mode} above). + Default remember mode is on. *) + + diff --git a/otherlibs/graph/graphics.mllib b/otherlibs/graph/graphics.mllib new file mode 100644 index 0000000..d5e8f9e --- /dev/null +++ b/otherlibs/graph/graphics.mllib @@ -0,0 +1 @@ +Graphics GraphicsX11 diff --git a/otherlibs/graph/graphicsX11.ml b/otherlibs/graph/graphicsX11.ml new file mode 100644 index 0000000..68bf08d --- /dev/null +++ b/otherlibs/graph/graphicsX11.ml @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis and Jun Furuse, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: graphicsX11.ml,v 1.3 2004-03-24 15:02:06 starynke Exp $ *) + +(* Module [GraphicsX11]: additional graphics primitives for the X Windows system *) + +type window_id = string + +external window_id : unit -> window_id = "caml_gr_window_id" + +let subwindows = Hashtbl.create 13 + +external open_subwindow : int -> int -> int -> int -> window_id + = "caml_gr_open_subwindow" +external close_subwindow : window_id -> unit + = "caml_gr_close_subwindow" + +let open_subwindow ~x ~y ~width ~height = + let wid = open_subwindow x y width height in + Hashtbl.add subwindows wid (); + wid +;; + +let close_subwindow wid = + if Hashtbl.mem subwindows wid then begin + close_subwindow wid; + Hashtbl.remove subwindows wid + end else + raise (Graphics.Graphic_failure ("close_subwindow: no such subwindow: " ^ wid)) +;; + diff --git a/otherlibs/graph/graphicsX11.mli b/otherlibs/graph/graphicsX11.mli new file mode 100644 index 0000000..73f7088 --- /dev/null +++ b/otherlibs/graph/graphicsX11.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis and Jun Furuse, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: graphicsX11.mli,v 1.4 2001-12-07 13:39:54 xleroy Exp $ *) + +(** Additional graphics primitives for the X Windows system. *) + +type window_id = string + +val window_id : unit -> window_id +(** Return the unique identifier of the Caml graphics window. + The returned string is an unsigned 32 bits integer + in decimal form. *) + +val open_subwindow : x:int -> y:int -> width:int -> height:int -> window_id +(** Create a sub-window of the current Caml graphics window + and return its identifier. *) + +val close_subwindow : window_id -> unit +(** Close the sub-window having the given identifier. *) + diff --git a/otherlibs/graph/image.c b/otherlibs/graph/image.c new file mode 100644 index 0000000..a0e823c --- /dev/null +++ b/otherlibs/graph/image.c @@ -0,0 +1,107 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: image.c,v 1.13 2004-03-24 15:02:05 starynke Exp $ */ + +#include "libgraph.h" +#include "image.h" +#include <alloc.h> +#include <custom.h> + +static void caml_gr_free_image(value im) +{ + XFreePixmap(caml_gr_display, Data_im(im)); + if (Mask_im(im) != None) XFreePixmap(caml_gr_display, Mask_im(im)); +} + +static struct custom_operations image_ops = { + "_image", + caml_gr_free_image, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +#define Max_image_mem 2000000 + +value caml_gr_new_image(int w, int h) +{ + value res = alloc_custom(&image_ops, sizeof(struct grimage), + w * h, Max_image_mem); + Width_im(res) = w; + Height_im(res) = h; + Data_im(res) = XCreatePixmap(caml_gr_display, caml_gr_window.win, w, h, + XDefaultDepth(caml_gr_display, caml_gr_screen)); + Mask_im(res) = None; + return res; +} + +value caml_gr_create_image(value vw, value vh) +{ + caml_gr_check_open(); + return caml_gr_new_image(Int_val(vw), Int_val(vh)); +} + +value caml_gr_blit_image(value im, value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + caml_gr_check_open(); + XCopyArea(caml_gr_display, caml_gr_bstore.win, Data_im(im), caml_gr_bstore.gc, + x, Bcvt(y) + 1 - Height_im(im), + Width_im(im), Height_im(im), + 0, 0); + return Val_unit; +} + +value caml_gr_draw_image(value im, value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int wy = Wcvt(y) + 1 - Height_im(im); + int by = Bcvt(y) + 1 - Height_im(im); + + caml_gr_check_open(); + if (Mask_im(im) != None) { + if(caml_gr_remember_modeflag) { + XSetClipOrigin(caml_gr_display, caml_gr_bstore.gc, x, by); + XSetClipMask(caml_gr_display, caml_gr_bstore.gc, Mask_im(im)); + } + if(caml_gr_display_modeflag) { + XSetClipOrigin(caml_gr_display, caml_gr_window.gc, x, wy); + XSetClipMask(caml_gr_display, caml_gr_window.gc, Mask_im(im)); + } + } + if(caml_gr_remember_modeflag) + XCopyArea(caml_gr_display, Data_im(im), caml_gr_bstore.win, caml_gr_bstore.gc, + 0, 0, + Width_im(im), Height_im(im), + x, by); + if(caml_gr_display_modeflag) + XCopyArea(caml_gr_display, Data_im(im), caml_gr_window.win, caml_gr_window.gc, + 0, 0, + Width_im(im), Height_im(im), + x, wy); + if (Mask_im(im) != None) { + if(caml_gr_remember_modeflag) + XSetClipMask(caml_gr_display, caml_gr_bstore.gc, None); + if(caml_gr_display_modeflag) + XSetClipMask(caml_gr_display, caml_gr_window.gc, None); + } + if(caml_gr_display_modeflag) + XFlush(caml_gr_display); + return Val_unit; +} + +/* eof $Id: image.c,v 1.13 2004-03-24 15:02:05 starynke Exp $ */ diff --git a/otherlibs/graph/image.h b/otherlibs/graph/image.h new file mode 100644 index 0000000..ee766c6 --- /dev/null +++ b/otherlibs/graph/image.h @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: image.h,v 1.8 2004-03-24 15:02:06 starynke Exp $ */ + +struct grimage { + int width, height; /* Dimensions of the image */ + Pixmap data; /* Pixels */ + Pixmap mask; /* Mask for transparent points, or None */ +}; + +#define Width_im(i) (((struct grimage *)Data_custom_val(i))->width) +#define Height_im(i) (((struct grimage *)Data_custom_val(i))->height) +#define Data_im(i) (((struct grimage *)Data_custom_val(i))->data) +#define Mask_im(i) (((struct grimage *)Data_custom_val(i))->mask) + +#define Transparent (-1) + +value caml_gr_new_image(int w, int h); diff --git a/otherlibs/graph/libgraph.h b/otherlibs/graph/libgraph.h new file mode 100644 index 0000000..af6da22 --- /dev/null +++ b/otherlibs/graph/libgraph.h @@ -0,0 +1,85 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: libgraph.h,v 1.23 2004-05-30 10:25:08 xleroy Exp $ */ + +#include <stdio.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <mlvalues.h> + +struct canvas { + int w, h; /* Dimensions of the drawable */ + Drawable win; /* The drawable itself */ + GC gc; /* The associated graphics context */ +}; + +extern Display * caml_gr_display; /* The display connection */ +extern int caml_gr_screen; /* The screen number */ +extern Colormap caml_gr_colormap; /* The color map */ +extern struct canvas caml_gr_window; /* The graphics window */ +extern struct canvas caml_gr_bstore; /* The pixmap used for backing store */ +extern int caml_gr_white, caml_gr_black; /* Black and white pixels for X */ +extern int caml_gr_background; /* Background color for X + (used for CAML color -1) */ +extern Bool caml_gr_display_modeflag; /* Display-mode flag */ +extern Bool caml_gr_remember_modeflag; /* Remember-mode flag */ +extern int caml_gr_x, caml_gr_y; /* Coordinates of the current point */ +extern int caml_gr_color; /* Current *CAML* drawing color (can be -1) */ +extern XFontStruct * caml_gr_font; /* Current font */ +extern long caml_gr_selected_events; /* Events we are interested in */ +extern Bool caml_gr_ignore_sigio; /* Whether to consume events on sigio */ + +extern Bool caml_gr_direct_rgb; +extern int caml_gr_byte_order; +extern int caml_gr_bitmap_unit; +extern int caml_gr_bits_per_pixel; + +#define Wcvt(y) (caml_gr_window.h - 1 - (y)) +#define Bcvt(y) (caml_gr_bstore.h - 1 - (y)) +#define WtoB(y) ((y) + caml_gr_bstore.h - caml_gr_window.h) +#define BtoW(y) ((y) + caml_gr_window.h - caml_gr_bstore.h) +#define min(a,b) ((a) < (b) ? (a) : (b)) +#define max(a,b) ((a) > (b) ? (a) : (b)) + +#define DEFAULT_SCREEN_WIDTH 600 +#define DEFAULT_SCREEN_HEIGHT 450 +#define BORDER_WIDTH 2 +#define DEFAULT_WINDOW_NAME "Caml graphics" +#define DEFAULT_SELECTED_EVENTS \ + (ExposureMask | KeyPressMask | StructureNotifyMask) +#define DEFAULT_FONT "fixed" +#define SIZE_QUEUE 256 + +/* To handle events asynchronously */ +#ifdef HAS_ASYNC_IO +#define USE_ASYNC_IO +#define EVENT_SIGNAL SIGIO +#else +#ifdef HAS_SETITIMER +#define USE_INTERVAL_TIMER +#define EVENT_SIGNAL SIGALRM +#else +#define USE_ALARM +#define EVENT_SIGNAL SIGALRM +#endif +#endif + +extern void caml_gr_fail(char *fmt, char *arg); +extern void caml_gr_check_open(void); +extern unsigned long caml_gr_pixel_rgb(int rgb); +extern int caml_gr_rgb_pixel(long unsigned int pixel); +extern void caml_gr_handle_event(XEvent *e); +extern void caml_gr_init_color_cache(void); +extern void caml_gr_init_direct_rgb_to_pixel(void); +extern value caml_gr_id_of_window( Window w ); diff --git a/otherlibs/graph/libgraphics.clib b/otherlibs/graph/libgraphics.clib new file mode 100644 index 0000000..d3b5b7b --- /dev/null +++ b/otherlibs/graph/libgraphics.clib @@ -0,0 +1,3 @@ +open.o draw.o fill.o color.o text.o +image.o make_img.o dump_img.o point_col.o sound.o events.o +subwindow.o diff --git a/otherlibs/graph/make_img.c b/otherlibs/graph/make_img.c new file mode 100644 index 0000000..4a44f91 --- /dev/null +++ b/otherlibs/graph/make_img.c @@ -0,0 +1,95 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: make_img.c,v 1.13 2004-03-24 15:02:05 starynke Exp $ */ + +#include "libgraph.h" +#include "image.h" +#include <memory.h> + +value caml_gr_make_image(value m) +{ + int width, height; + value im; + Bool has_transp; + XImage * idata, * imask; + char * bdata, * bmask; + int i, j, rgb; + value line; + GC gc; + + caml_gr_check_open(); + height = Wosize_val(m); + if (height == 0) return caml_gr_new_image(0, 0); + width = Wosize_val(Field(m, 0)); + for (i = 1; i < height; i++) + if (Wosize_val(Field(m, i)) != width) + caml_gr_fail("make_image: lines of different lengths", NULL); + + /* Build an XImage for the data part of the image */ + idata = + XCreateImage(caml_gr_display, DefaultVisual(caml_gr_display, caml_gr_screen), + XDefaultDepth(caml_gr_display, caml_gr_screen), + ZPixmap, 0, NULL, width, height, + BitmapPad(caml_gr_display), 0); + + bdata = (char *) stat_alloc(height * idata->bytes_per_line); + idata->data = bdata; + has_transp = False; + + for (i = 0; i < height; i++) { + line = Field(m, i); + for (j = 0; j < width; j++) { + rgb = Int_val(Field(line, j)); + if (rgb == Transparent) { has_transp = True; rgb = 0; } + XPutPixel(idata, j, i, caml_gr_pixel_rgb(rgb)); + } + } + + /* If the matrix contains transparent points, + build an XImage for the mask part of the image */ + if (has_transp) { + imask = + XCreateImage(caml_gr_display, DefaultVisual(caml_gr_display, caml_gr_screen), + 1, ZPixmap, 0, NULL, width, height, + BitmapPad(caml_gr_display), 0); + bmask = (char *) stat_alloc(height * imask->bytes_per_line); + imask->data = bmask; + + for (i = 0; i < height; i++) { + line = Field(m, i); + for (j = 0; j < width; j++) { + rgb = Int_val(Field(line, j)); + XPutPixel(imask, j, i, rgb != Transparent); + } + } + } else { + imask = NULL; + } + + /* Allocate the image and store the XImages into the Pixmaps */ + im = caml_gr_new_image(width, height); + gc = XCreateGC(caml_gr_display, Data_im(im), 0, NULL); + XPutImage(caml_gr_display, Data_im(im), gc, idata, 0, 0, 0, 0, width, height); + XDestroyImage(idata); + XFreeGC(caml_gr_display, gc); + if (has_transp) { + Mask_im(im) = XCreatePixmap(caml_gr_display, caml_gr_window.win, width, height, 1); + gc = XCreateGC(caml_gr_display, Mask_im(im), 0, NULL); + XPutImage(caml_gr_display, Mask_im(im), gc, imask, 0, 0, 0, 0, width, height); + XDestroyImage(imask); + XFreeGC(caml_gr_display, gc); + } + XFlush(caml_gr_display); + return im; +} diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c new file mode 100644 index 0000000..01765aa --- /dev/null +++ b/otherlibs/graph/open.c @@ -0,0 +1,395 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: open.c,v 1.34 2005-08-13 20:59:37 doligez Exp $ */ + +#include <string.h> +#include <fcntl.h> +#include <signal.h> +#include "libgraph.h" +#include <alloc.h> +#include <callback.h> +#include <fail.h> +#include <memory.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#ifdef HAS_SETITIMER +#include <sys/time.h> +#endif + +Display * caml_gr_display = NULL; +int caml_gr_screen; +Colormap caml_gr_colormap; +int caml_gr_white, caml_gr_black, caml_gr_background; +struct canvas caml_gr_window; +struct canvas caml_gr_bstore; +Bool caml_gr_display_modeflag; +Bool caml_gr_remember_modeflag; +int caml_gr_x, caml_gr_y; +int caml_gr_color; +extern XFontStruct * caml_gr_font; +long caml_gr_selected_events; +Bool caml_gr_ignore_sigio = False; +static Bool caml_gr_initialized = False; +static char * window_name = NULL; + +static int caml_gr_error_handler(Display *display, XErrorEvent *error); +static int caml_gr_ioerror_handler(Display *display); +value caml_gr_clear_graph(void); + +value caml_gr_open_graph(value arg) +{ + char display_name[256], geometry_spec[64]; + char * p, * q; + XSizeHints hints; + int ret; + XEvent event; + int x, y, w, h; + XWindowAttributes attributes; + + if (caml_gr_initialized) { + caml_gr_clear_graph(); + } else { + + /* Parse the argument */ + for (p = String_val(arg), q = display_name; *p != 0 && *p != ' '; p++) + if (q < display_name + sizeof(display_name) - 1) *q++ = *p; + *q = 0; + while (*p == ' ') p++; + for (q = geometry_spec; *p != 0; p++) + if (q < geometry_spec + sizeof(geometry_spec) - 1) *q++ = *p; + *q = 0; + + /* Open the display */ + if (caml_gr_display == NULL) { + caml_gr_display = XOpenDisplay(display_name); + if (caml_gr_display == NULL) + caml_gr_fail("Cannot open display %s", XDisplayName(display_name)); + caml_gr_screen = DefaultScreen(caml_gr_display); + caml_gr_black = BlackPixel(caml_gr_display, caml_gr_screen); + caml_gr_white = WhitePixel(caml_gr_display, caml_gr_screen); + caml_gr_background = caml_gr_white; + caml_gr_colormap = DefaultColormap(caml_gr_display, caml_gr_screen); + } + + /* Set up the error handlers */ + XSetErrorHandler(caml_gr_error_handler); + XSetIOErrorHandler(caml_gr_ioerror_handler); + + /* Parse the geometry specification */ + hints.x = 0; + hints.y = 0; + hints.width = DEFAULT_SCREEN_WIDTH; + hints.height = DEFAULT_SCREEN_HEIGHT; + hints.flags = PPosition | PSize; + hints.win_gravity = 0; + + ret = XWMGeometry(caml_gr_display, caml_gr_screen, geometry_spec, "", BORDER_WIDTH, + &hints, &x, &y, &w, &h, &hints.win_gravity); + if (ret & (XValue | YValue)) { + hints.x = x; hints.y = y; hints.flags |= USPosition; + } + if (ret & (WidthValue | HeightValue)) { + hints.width = w; hints.height = h; hints.flags |= USSize; + } + + /* Initial drawing color is black */ + caml_gr_color = 0; /* CAML COLOR */ + + /* Create the on-screen window */ + caml_gr_window.w = hints.width; + caml_gr_window.h = hints.height; + caml_gr_window.win = + XCreateSimpleWindow(caml_gr_display, DefaultRootWindow(caml_gr_display), + hints.x, hints.y, hints.width, hints.height, + BORDER_WIDTH, caml_gr_black, caml_gr_background); + p = window_name; + if (p == NULL) p = DEFAULT_WINDOW_NAME; + /* What not use XSetWMProperties? */ + XSetStandardProperties(caml_gr_display, caml_gr_window.win, p, p, + None, NULL, 0, &hints); + caml_gr_window.gc = XCreateGC(caml_gr_display, caml_gr_window.win, 0, NULL); + XSetBackground(caml_gr_display, caml_gr_window.gc, caml_gr_background); + XSetForeground(caml_gr_display, caml_gr_window.gc, caml_gr_black); + + /* Require exposure, resize and keyboard events */ + caml_gr_selected_events = DEFAULT_SELECTED_EVENTS; + XSelectInput(caml_gr_display, caml_gr_window.win, caml_gr_selected_events); + + /* Map the window on the screen and wait for the first Expose event */ + XMapWindow(caml_gr_display, caml_gr_window.win); + do { XNextEvent(caml_gr_display, &event); } while (event.type != Expose); + + /* Get the actual window dimensions */ + XGetWindowAttributes(caml_gr_display, caml_gr_window.win, &attributes); + caml_gr_window.w = attributes.width; + caml_gr_window.h = attributes.height; + + /* Create the pixmap used for backing store */ + caml_gr_bstore.w = caml_gr_window.w; + caml_gr_bstore.h = caml_gr_window.h; + caml_gr_bstore.win = + XCreatePixmap(caml_gr_display, caml_gr_window.win, caml_gr_bstore.w, caml_gr_bstore.h, + XDefaultDepth(caml_gr_display, caml_gr_screen)); + caml_gr_bstore.gc = XCreateGC(caml_gr_display, caml_gr_bstore.win, 0, NULL); + XSetBackground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background); + + /* Clear the pixmap */ + XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background); + XFillRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + 0, 0, caml_gr_bstore.w, caml_gr_bstore.h); + XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_black); + + /* Set the display and remember modes on */ + caml_gr_display_modeflag = True ; + caml_gr_remember_modeflag = True ; + + /* The global data structures are now correctly initialized. + In particular, caml_gr_sigio_handler can now handle events safely. */ + caml_gr_initialized = True; + + /* If possible, request that system calls be restarted after + the EVENT_SIGNAL signal. */ +#ifdef POSIX_SIGNALS +#ifdef SA_RESTART + { struct sigaction action; + sigaction(EVENT_SIGNAL, NULL, &action); + action.sa_flags |= SA_RESTART; + sigaction(EVENT_SIGNAL, &action, NULL); + } +#endif +#endif + +#ifdef USE_ASYNC_IO + /* If BSD-style asynchronous I/O are supported: + arrange for I/O on the connection to trigger the SIGIO signal */ + ret = fcntl(ConnectionNumber(caml_gr_display), F_GETFL, 0); + fcntl(ConnectionNumber(caml_gr_display), F_SETFL, ret | FASYNC); + fcntl(ConnectionNumber(caml_gr_display), F_SETOWN, getpid()); +#endif + } +#ifdef USE_INTERVAL_TIMER + /* If BSD-style interval timers are provided, use the real-time timer + to poll events. */ + { struct itimerval it; + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = 250000; + it.it_value.tv_sec = 0; + it.it_value.tv_usec = 250000; + setitimer(ITIMER_REAL, &it, NULL); + } +#endif +#ifdef USE_ALARM + /* The poor man's solution: use alarm to poll events. */ + alarm(1); +#endif + /* Position the current point at origin */ + caml_gr_x = 0; + caml_gr_y = 0; + /* Reset the color cache */ + caml_gr_init_color_cache(); + caml_gr_init_direct_rgb_to_pixel(); + return Val_unit; +} + +value caml_gr_close_graph(void) +{ + if (caml_gr_initialized) { +#ifdef USE_INTERVAL_TIMER + struct itimerval it; + it.it_value.tv_sec = 0; + it.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &it, NULL); +#endif + caml_gr_initialized = False; + if (caml_gr_font != NULL) { XFreeFont(caml_gr_display, caml_gr_font); caml_gr_font = NULL; } + XFreeGC(caml_gr_display, caml_gr_window.gc); + XDestroyWindow(caml_gr_display, caml_gr_window.win); + XFreeGC(caml_gr_display, caml_gr_bstore.gc); + XFreePixmap(caml_gr_display, caml_gr_bstore.win); + XFlush(caml_gr_display); + XCloseDisplay (caml_gr_display); + caml_gr_display = NULL; + } + return Val_unit; +} + +value caml_gr_id_of_window(Window win) +{ + char tmp[256]; + + sprintf(tmp, "%lu", (unsigned long)win); + return copy_string( tmp ); +} + +value caml_gr_window_id(void) +{ + caml_gr_check_open(); + return caml_gr_id_of_window(caml_gr_window.win); +} + +value caml_gr_set_window_title(value n) +{ + if (window_name != NULL) stat_free(window_name); + window_name = stat_alloc(strlen(String_val(n))+1); + strcpy(window_name, String_val(n)); + if (caml_gr_initialized) { + XStoreName(caml_gr_display, caml_gr_window.win, window_name); + XSetIconName(caml_gr_display, caml_gr_window.win, window_name); + XFlush(caml_gr_display); + } + return Val_unit; +} + +value caml_gr_resize_window (value vx, value vy) +{ + caml_gr_check_open (); + + caml_gr_window.w = Int_val (vx); + caml_gr_window.h = Int_val (vy); + XResizeWindow (caml_gr_display, caml_gr_window.win, caml_gr_window.w, + caml_gr_window.h); + + XFreeGC(caml_gr_display, caml_gr_bstore.gc); + XFreePixmap(caml_gr_display, caml_gr_bstore.win); + + caml_gr_bstore.w = caml_gr_window.w; + caml_gr_bstore.h = caml_gr_window.h; + caml_gr_bstore.win = + XCreatePixmap(caml_gr_display, caml_gr_window.win, caml_gr_bstore.w, + caml_gr_bstore.h, + XDefaultDepth(caml_gr_display, caml_gr_screen)); + caml_gr_bstore.gc = XCreateGC(caml_gr_display, caml_gr_bstore.win, 0, NULL); + XSetBackground(caml_gr_display, caml_gr_bstore.gc, caml_gr_background); + + caml_gr_clear_graph (); + return Val_unit; +} + +value caml_gr_clear_graph(void) +{ + caml_gr_check_open(); + if(caml_gr_remember_modeflag) { + XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_white); + XFillRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + 0, 0, caml_gr_bstore.w, caml_gr_bstore.h); + XSetForeground(caml_gr_display, caml_gr_bstore.gc, caml_gr_color); + } + if(caml_gr_display_modeflag) { + XSetForeground(caml_gr_display, caml_gr_window.gc, caml_gr_white); + XFillRectangle(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + 0, 0, caml_gr_window.w, caml_gr_window.h); + XSetForeground(caml_gr_display, caml_gr_window.gc, caml_gr_color); + XFlush(caml_gr_display); + } + caml_gr_init_color_cache(); + caml_gr_init_direct_rgb_to_pixel(); + return Val_unit; +} + +value caml_gr_size_x(void) +{ + caml_gr_check_open(); + return Val_int(caml_gr_window.w); +} + +value caml_gr_size_y(void) +{ + caml_gr_check_open(); + return Val_int(caml_gr_window.h); +} + +value caml_gr_synchronize(void) +{ + caml_gr_check_open(); + XCopyArea(caml_gr_display, caml_gr_bstore.win, caml_gr_window.win, caml_gr_window.gc, + 0, caml_gr_bstore.h - caml_gr_window.h, + caml_gr_window.w, caml_gr_window.h, + 0, 0); + XFlush(caml_gr_display); + return Val_unit ; +} + +value caml_gr_display_mode(value flag) +{ + caml_gr_display_modeflag = Bool_val (flag); + return Val_unit ; +} + +value caml_gr_remember_mode(value flag) +{ + caml_gr_remember_modeflag = Bool_val(flag); + return Val_unit ; +} + +/* The caml_gr_sigio_handler is called via the signal machinery in the bytecode + interpreter. The signal system ensures that this function will be + called either between two bytecode instructions, or during a blocking + primitive. In either case, not in the middle of an Xlib call. */ + +value caml_gr_sigio_signal(value unit) +{ + return Val_int(EVENT_SIGNAL); +} + +value caml_gr_sigio_handler(void) +{ + XEvent grevent; + + if (caml_gr_initialized && !caml_gr_ignore_sigio) { + while (XCheckMaskEvent(caml_gr_display, -1 /*all events*/, &grevent)) { + caml_gr_handle_event(&grevent); + } + } +#ifdef USE_ALARM + alarm(1); +#endif + return Val_unit; +} + +/* Processing of graphic errors */ + +static value * graphic_failure_exn = NULL; + +void caml_gr_fail(char *fmt, char *arg) +{ + char buffer[1024]; + + if (graphic_failure_exn == NULL) { + graphic_failure_exn = caml_named_value("Graphics.Graphic_failure"); + if (graphic_failure_exn == NULL) + invalid_argument("Exception Graphics.Graphic_failure not initialized, must link graphics.cma"); + } + sprintf(buffer, fmt, arg); + raise_with_string(*graphic_failure_exn, buffer); +} + +void caml_gr_check_open(void) +{ + if (!caml_gr_initialized) caml_gr_fail("graphic screen not opened", NULL); +} + +static int caml_gr_error_handler(Display *display, XErrorEvent *error) +{ + char errmsg[512]; + XGetErrorText(error->display, error->error_code, errmsg, sizeof(errmsg)); + caml_gr_fail("Xlib error: %s", errmsg); + return 0; +} + +static int caml_gr_ioerror_handler(Display *display) +{ + caml_gr_fail("fatal I/O error", NULL); + return 0; +} diff --git a/otherlibs/graph/point_col.c b/otherlibs/graph/point_col.c new file mode 100644 index 0000000..fa0f3f5 --- /dev/null +++ b/otherlibs/graph/point_col.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: point_col.c,v 1.8 2004-03-24 15:02:05 starynke Exp $ */ + +#include "libgraph.h" + +value caml_gr_point_color(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + XImage * im; + int rgb; + + caml_gr_check_open(); + im = XGetImage(caml_gr_display, caml_gr_bstore.win, x, Bcvt(y), 1, 1, (-1), ZPixmap); + rgb = caml_gr_rgb_pixel(XGetPixel(im, 0, 0)); + XDestroyImage(im); + return Val_int(rgb); +} + + diff --git a/otherlibs/graph/sound.c b/otherlibs/graph/sound.c new file mode 100644 index 0000000..3de51d6 --- /dev/null +++ b/otherlibs/graph/sound.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sound.c,v 1.9 2004-03-24 15:02:05 starynke Exp $ */ + +#include "libgraph.h" + +value caml_gr_sound(value vfreq, value vdur) +{ + XKeyboardControl kbdcontrol; + + caml_gr_check_open(); + kbdcontrol.bell_pitch = Int_val(vfreq); + kbdcontrol.bell_duration = Int_val(vdur); + XChangeKeyboardControl(caml_gr_display, KBBellPitch | KBBellDuration, + &kbdcontrol); + XBell(caml_gr_display, 0); + kbdcontrol.bell_pitch = -1; /* restore default value */ + kbdcontrol.bell_duration = -1; /* restore default value */ + XChangeKeyboardControl(caml_gr_display, KBBellPitch | KBBellDuration, + &kbdcontrol); + XFlush(caml_gr_display); + return Val_unit; +} diff --git a/otherlibs/graph/subwindow.c b/otherlibs/graph/subwindow.c new file mode 100644 index 0000000..c4babb0 --- /dev/null +++ b/otherlibs/graph/subwindow.c @@ -0,0 +1,45 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jun Furuse, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: subwindow.c,v 1.6 2004-03-24 15:02:05 starynke Exp $ */ + +#include "libgraph.h" + +value caml_gr_open_subwindow(value vx, value vy, value width, value height) +{ + Window win; + + int h = Int_val(height); + int w = Int_val(width); + int x = Int_val(vx); + int y = Int_val(vy); + + caml_gr_check_open(); + win = XCreateSimpleWindow(caml_gr_display, caml_gr_window.win, + x, Wcvt(y + h), w, h, + 0, caml_gr_black, caml_gr_background); + XMapWindow(caml_gr_display, win); + XFlush(caml_gr_display); + return (caml_gr_id_of_window (win)); +} + +value caml_gr_close_subwindow(value wid) +{ + Window win; + + caml_gr_check_open(); + sscanf( String_val(wid), "%lu", (unsigned long *)(&win) ); + XDestroyWindow(caml_gr_display, win); + XFlush(caml_gr_display); + return Val_unit; +} diff --git a/otherlibs/graph/text.c b/otherlibs/graph/text.c new file mode 100644 index 0000000..f17efea --- /dev/null +++ b/otherlibs/graph/text.c @@ -0,0 +1,84 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: text.c,v 1.15 2004-03-24 15:02:06 starynke Exp $ */ + +#include "libgraph.h" +#include <alloc.h> + +XFontStruct * caml_gr_font = NULL; + +static void caml_gr_get_font(char *fontname) +{ + XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname); + if (font == NULL) caml_gr_fail("cannot find font %s", fontname); + if (caml_gr_font != NULL) XFreeFont(caml_gr_display, caml_gr_font); + caml_gr_font = font; + XSetFont(caml_gr_display, caml_gr_window.gc, caml_gr_font->fid); + XSetFont(caml_gr_display, caml_gr_bstore.gc, caml_gr_font->fid); +} + +value caml_gr_set_font(value fontname) +{ + caml_gr_check_open(); + caml_gr_get_font(String_val(fontname)); + return Val_unit; +} + +value caml_gr_set_text_size (value sz) +{ + return Val_unit; +} + +static void caml_gr_draw_text(char *txt, int len) +{ + if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT); + if (caml_gr_remember_modeflag) + XDrawString(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, + caml_gr_x, Bcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len); + if (caml_gr_display_modeflag) { + XDrawString(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, + caml_gr_x, Wcvt(caml_gr_y) - caml_gr_font->descent + 1, txt, len); + XFlush(caml_gr_display); + } + caml_gr_x += XTextWidth(caml_gr_font, txt, len); +} + +value caml_gr_draw_char(value chr) +{ + char str[1]; + caml_gr_check_open(); + str[0] = Int_val(chr); + caml_gr_draw_text(str, 1); + return Val_unit; +} + +value caml_gr_draw_string(value str) +{ + caml_gr_check_open(); + caml_gr_draw_text(String_val(str), string_length(str)); + return Val_unit; +} + +value caml_gr_text_size(value str) +{ + int width; + value res; + caml_gr_check_open(); + if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT); + width = XTextWidth(caml_gr_font, String_val(str), string_length(str)); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(width); + Field(res, 1) = Val_int(caml_gr_font->ascent + caml_gr_font->descent); + return res; +} diff --git a/otherlibs/labltk/.cvsignore b/otherlibs/labltk/.cvsignore new file mode 100644 index 0000000..f58b073 --- /dev/null +++ b/otherlibs/labltk/.cvsignore @@ -0,0 +1,4 @@ +labltklink +labltkopt +Makefile.config +config.status diff --git a/otherlibs/labltk/Changes b/otherlibs/labltk/Changes new file mode 100644 index 0000000..e98ed27 --- /dev/null +++ b/otherlibs/labltk/Changes @@ -0,0 +1,17 @@ +2005-12-20: +----------- +* Add Protocol.do_one_event and Protocol.do_pending. + +2002-05-03: +----------- +General Changes +* Merging CamlTk and LablTk API interfaces +* Activate and Deactivate Events are added +* Virtual events support +* Added UTF conversion + +Incompatibilities between the previous camltk/labltk versions +* CamlTk's bind_tag and bind_class superseded tag_bind and class_bind. +* added optional arguments to some functions of CamlTk. +* The library name libfrx and libjpf are changed to frxlib and jpflib + respectively, to avoid the library name confusion. diff --git a/otherlibs/labltk/Makefile b/otherlibs/labltk/Makefile new file mode 100644 index 0000000..358de5b --- /dev/null +++ b/otherlibs/labltk/Makefile @@ -0,0 +1,83 @@ +# Top Makefile for mlTk + +SUBDIRS=compiler support lib jpf frx tkanim examples_labltk \ + examples_camltk browser +SUBDIRS_GENERATED=camltk labltk + + +all: + cd support; $(MAKE) + cd compiler; $(MAKE) + cd labltk; $(MAKE) -f Makefile.gen + cd labltk; $(MAKE) + cd camltk; $(MAKE) -f Makefile.gen + cd camltk; $(MAKE) + cd lib; $(MAKE) + cd jpf; $(MAKE) + cd frx; $(MAKE) + cd tkanim; $(MAKE) + cd browser; $(MAKE) + +allopt: + cd support; $(MAKE) opt + cd labltk; $(MAKE) -f Makefile.gen + cd labltk; $(MAKE) opt + cd camltk; $(MAKE) -f Makefile.gen + cd camltk; $(MAKE) opt + cd lib; $(MAKE) opt + cd jpf; $(MAKE) opt + cd frx; $(MAKE) opt + cd tkanim; $(MAKE) opt + +byte: all +opt: allopt + +.PHONY: all allopt byte opt +.PHONY: labltk camltk examples examples_labltk examples_camltk +.PHONY: install installopt partialclean clean depend + +labltk: Widgets.src + compiler/tkcompiler -outdir labltk + cd labltk; $(MAKE) + +camltk: Widgets.src + compiler/tkcompiler -camltk -outdir camltk + cd camltk; $(MAKE) + +examples: examples_labltk examples_camltk + +examples_labltk: + cd examples_labltk; $(MAKE) all + +examples_camltk: + cd examples_camltk; $(MAKE) all + +install: + cd support; $(MAKE) install + cd lib; $(MAKE) install + cd labltk; $(MAKE) install + cd camltk; $(MAKE) install + cd compiler; $(MAKE) install + cd jpf; $(MAKE) install + cd frx; $(MAKE) install + cd tkanim; $(MAKE) install + cd browser; $(MAKE) install + +installopt: + cd support; $(MAKE) installopt + cd lib; $(MAKE) installopt + cd labltk; $(MAKE) installopt + cd camltk; $(MAKE) installopt + cd jpf; $(MAKE) installopt + cd frx; $(MAKE) installopt + cd tkanim; $(MAKE) installopt + +partialclean clean: + for d in $(SUBDIRS); do \ + cd $$d; $(MAKE) -f Makefile clean; cd ..; \ + done + for d in $(SUBDIRS_GENERATED); do \ + cd $$d; $(MAKE) -f Makefile.gen clean; cd ..; \ + done + +depend: diff --git a/otherlibs/labltk/Makefile.nt b/otherlibs/labltk/Makefile.nt new file mode 100644 index 0000000..45d5391 --- /dev/null +++ b/otherlibs/labltk/Makefile.nt @@ -0,0 +1,64 @@ +# Top Makefile for LablTk + +include ../../config/Makefile + + + +SUBDIRS=compiler support lib labltk camltk jpf frx tkanim examples_labltk examples_camltk browser + +all: + cd support ; $(MAKEREC) + cd compiler ; $(MAKEREC) + cd labltk ; $(MAKECMD) -f Makefile.gen.nt + cd labltk ; $(MAKEREC) + cd camltk ; $(MAKECMD) -f Makefile.gen.nt + cd camltk ; $(MAKEREC) + cd lib ; $(MAKEREC) + cd jpf ; $(MAKEREC) + cd frx ; $(MAKEREC) + cd tkanim ; $(MAKEREC) + cd browser ; $(MAKEREC) + +allopt: + cd support ; $(MAKEREC) opt + cd labltk ; $(MAKECMD) -f Makefile.gen.nt + cd labltk ; $(MAKEREC) opt + cd camltk ; $(MAKECMD) -f Makefile.gen.nt + cd camltk ; $(MAKEREC) opt + cd lib ; $(MAKEREC) opt + cd jpf ; $(MAKEREC) opt + cd frx ; $(MAKEREC) opt + cd tkanim ; $(MAKEREC) opt + +.PHONY: examples_labltk examples_camltk + +examples: examples_labltk examples_camltk + +examples_labltk: + cd examples_labltk; $(MAKE) all + +examples_camltk: + cd examples_camltk; $(MAKE) all + +install: + cd labltk ; $(MAKEREC) install + cd camltk ; $(MAKEREC) install + cd lib ; $(MAKEREC) install + cd support ; $(MAKEREC) install + cd compiler ; $(MAKEREC) install + cd jpf ; $(MAKEREC) install + cd frx ; $(MAKEREC) install + cd tkanim ; $(MAKEREC) install + cd browser ; $(MAKEREC) install + +installopt: + cd support ; $(MAKEREC) installopt + cd labltk ; $(MAKEREC) installopt + cd camltk ; $(MAKEREC) installopt + cd lib ; $(MAKEREC) installopt + cd jpf ; $(MAKEREC) installopt + cd frx ; $(MAKEREC) installopt + cd tkanim ; $(MAKEREC) installopt + +partialclean clean: + for d in $(SUBDIRS); do $(MAKEREC) -C $$d clean; done diff --git a/otherlibs/labltk/README b/otherlibs/labltk/README new file mode 100644 index 0000000..6f63b4a --- /dev/null +++ b/otherlibs/labltk/README @@ -0,0 +1,152 @@ +INTRODUCTION +============ +mlTk is a library for interfacing Objective Caml with the scripting +language Tcl/Tk (all versions since 8.0.3, but no betas). + +In addition to the basic interface with Tcl/Tk, this package contains + * the OCamlBrowser code editor / library browser written by Jacques + Garrigue. + * the "jpf" library, written by Jun P. Furuse; it contains a "file + selector" and "balloon help" support + * the "frx" library, written by Francois Rouaix + * the "tkanim" library, which supports animated gif loading/display + +mlTk = CamlTk + LablTk +====================== +There existed two parallel Tcl/Tk interfaces for O'Caml, CamlTk and LablTk. + +CamlTk uses classical features only, therefore it is easy to understand for +the beginners of ML. It makes many conservative O'Caml gurus also happy. +LablTk, on the other hand, uses rather newer features of O'Caml, the labeled +optional arguments and polymorphic variants. Its syntax has much more Tcl/Tk +script flavor, but provides more powerful typing than CamlTk at the same time +(i.e. less run time type checking of widgets). +Until now, these two interfaces have been distributed and maintained +independently. + +mlTk unifies these libraries into one. Since mlTk provides the both API's, +both CamlTk and LablTk users can compile their applications with mlTk, +just with little fixes. + +REQUIREMENTS +============ +You must have already installed + * Objective Caml source, version 3.04+8 or later + + * Tcl/Tk 8.0.3 or later + http://www.scriptics.com/ or various mirrors + +PLATFORMS: +Essentially any Unix/X Window System platform. We have tested +releases on Linux (ELF x86), FreeBSD (x86), SunOS4.1.x (sparc), DEC +OSF/1 V4.0 (alpha), DGUX SVR4 (m88k) and Windows (VC++ and Cygwin). + +INSTALLATION +============ + +0. Check-out the O'Caml CVS source code tree. + +1. Compile O'Caml (= make world). If you want, also make opt. + +2. Untar this mlTk distribution in the otherlibs directory, just like + the labltk source tree. + +3. change directory to otherlibs/mltk, and make (and make opt) + +4. To install the library, make install (and make installopt) + +To compile mlTk, you need the O'Caml source tree, since mltk/camlbrowser +requires some modules of O'Caml. If you are not interested in camlbrowser, +you can compile mlTk without the O'Caml source tree, but you have to modify +support/Makefile.common. + + +Compile your CamlTk/LablTk applications with mlTk +================================================= + +* General + +The names of the additional libraries libjpf and libfrx are changed +to jpflib and frxlib respectively, to avoid the library name space confusion. + +* LablTk users + +Just change the occurrences of labltk in your Makefiles to mltk +(i.e. -I +labltk => -I +mltk, labltk.cma => mltk.cma, and so on) +Since the API functions are 100% compatible, you need not to change +your .ml files. + +* CamlTk users + + - Makefiles : apply the same modification explained above for LablTk users. + + - open Camltk : The API modules and functions are stored in the modules + Camltk. Therefore you need to replace the module name Tk to Camltk. + For example, open Tk => open Camltk. + + open Camltk (* instead of open Tk *) + + let t = openTk ();; + let b = Button.create t [];; + + - You may also need to open the Camltk module explicitly, when your + original module source contain no open Tk phrase. Widget and the other + Tcl/Tk related types are now under Camltk. (e.g. Widget.widget is now + Camltk.Widget.widget) Add open Camltk at the beginning of .mli files, + if these types are used: + + open Camltk (* added for compiling under mlTk *) + + val create_progress_bar : Widget.widget -> Widget.widget + + - Eta expansion to flush optional arguments at registering callbacks. + Functions with the _displayof suffix are unified with their non-displayof + versions, using optional labeled arguments. For example, Bell.ring + had/have the following types: + + before: Bell.ring : unit -> unit + now: Bell.ring : ?displayof:Camltk.widget -> unit -> unit + + If you use these functions as callbacks directly like Command Bell.ring, + you need eta-expansions to flush these new optional arguments: + + Button.create w [Command Bell.ring] + + => Button.create w [Command (fun () -> Bell.ring ())] + +Use the both API's at the same time +=================================== +It is possible to use the both API's in one program. If you want to use +a widget library written in the different API from you use, you need to +do it. (It will be confusing, but easier than porting the library itself +from one to the other API.) + +For the users who mainly use LablTk API, CamlTk API is available +in the modules start with 'C'. For example, the source file of +the CamlTk button widget functions is CButton (and exported also as +Camltk.Button). + +For the users who mainly use CamlTk API, LablTk API modules are exported +inside Labltk module. For example, LablTk's Button module can be also +accessible as Labltk.Button. + +In CamlTk, we have only one widget type, [widget]. This type is equivalent +to the LablTk's type [any widget]. Therefore, if you want to apply CamlTk +functions to LablTk widget, you can use [coe] function to coerce it to +[any widget]. + +To do the converse, the "widget-typers" are available inside the module Labltk. +For example, to recover the type of a button widget, use Labltk.button. +These widget-typers checks the types of widgets at run-time. If the widget +type is different from the context type, a run-time exception is raised. + + open Tk (* open LablTk API *) + + let t = openTk ();; (* t is LablTk widget, toplevel widget *) + (* CButton.create takes [any widget]; [t] must be coerced to the type. *) + let caml_b = CButton.create (coe t) [];; + (* caml_b is [any widget], must be explicitly typed as [button widget], + when it is used with LablTk API functions *) + let b = Labltk.button caml_b in (* recover the type [button widget] *) + ... + diff --git a/otherlibs/labltk/Widgets.src b/otherlibs/labltk/Widgets.src new file mode 100644 index 0000000..e59c435 --- /dev/null +++ b/otherlibs/labltk/Widgets.src @@ -0,0 +1,2288 @@ +%%%%%%%%%%%%%% Standard Tk8.0.3 Widgets and functions %%%%%%%%%%%%%% +type Widget external + +% cget will probably never be implemented with verifications +function (string) cgets [widget; "cget"; string] +% another version with some hack is +type options_constrs external +function (string) cget [widget; "cget"; options_constrs] +% constructors of type options_constrs are of the form C<c> +% where <c> is an option constructor (e.g. CBackground) + +%%%%% Some types for standard options of widgets +type Anchor { + NW ["nw"] N ["n"] NE ["ne"] + W ["w"] Center ["center"] E ["e"] + SW ["sw"] S ["s"] SE ["se"] +} + +type Bitmap external % builtin_GetBitmap.ml +type Cursor external % builtin_GetCursor.ml +type Color external % builtin_GetCursor.ml + +##ifdef CAMLTK + +type ImageBitmap { + BitmapImage [string] + } +type ImagePhoto { + PhotoImage [string] + } + +##else + +variant type ImageBitmap { + Bitmap [string] + } +variant type ImagePhoto { + Photo [string] + } +variant type Image { + Bitmap [string] + Photo [string] +} + +##endif + +type Justification { + Justify_Left ["left"] + Justify_Center ["center"] + Justify_Right ["right"] +} + +type Orientation { + Vertical ["vertical"] + Horizontal ["horizontal"] +} + +type Relief { + Raised ["raised"] + Sunken ["sunken"] + Flat ["flat"] + Ridge ["ridge"] + Solid ["solid"] + Groove ["groove"] +} + +type TextVariable external % textvariable.ml +type Units external % builtin_GetPixel.ml + +%%%%% The standard options, as defined in man page options(n) +%%%%% The subtype is never used +subtype option(standard) { + ActiveBackground ["-activebackground"; Color] + ActiveBorderWidth ["-activeborderwidth"; Units/int] + ActiveForeground ["-activeforeground"; Color] + Anchor ["-anchor"; Anchor] + Background ["-background"; Color] + Bitmap ["-bitmap"; Bitmap] + BorderWidth ["-borderwidth"; Units/int] + Cursor ["-cursor"; Cursor] + DisabledForeground ["-disabledforeground"; Color] + ExportSelection ["-exportselection"; bool] + Font ["-font"; string] + Foreground ["-foreground"; Color] +% Geometry is not one of standard options... + Geometry ["-geometry"; string] % Too variable to encode + HighlightBackground ["-highlightbackground"; Color] + HighlightColor ["-highlightcolor"; Color] + HighlightThickness ["-highlightthickness"; Units/int] +##ifdef CAMLTK + % images are split, to do additionnal static typing + ImageBitmap (ImageBitmap) ["-image"; ImageBitmap] + ImagePhoto (ImagePhoto) ["-image"; ImagePhoto] +##else + Image ["-image"; Image] +##endif + InsertBackground ["-insertbackground"; Color] + InsertBorderWidth ["-insertborderwidth"; Units/int] + InsertOffTime ["-insertofftime"; int] % Positive only + InsertOnTime ["-insertontime"; int] % Idem + InsertWidth ["-insertwidth"; Units/int] + Jump ["-jump"; bool] + Justify ["-justify"; Justification] + Orient ["-orient"; Orientation] + PadX ["-padx"; Units/int] + PadY ["-pady"; Units/int] + Relief ["-relief"; Relief] + RepeatDelay ["-repeatdelay"; int] + RepeatInterval ["-repeatinterval"; int] + SelectBackground ["-selectbackground"; Color] + SelectBorderWidth ["-selectborderwidth"; Units/int] + SelectForeground ["-selectforeground"; Color] + SetGrid ["-setgrid"; bool] + % incomplete description of TakeFocus + TakeFocus ["-takefocus"; bool] + Text ["-text"; string] + TextVariable ["-textvariable"; TextVariable] + TroughColor ["-troughcolor"; Color] + UnderlinedChar ["-underline"; int] + WrapLength ["-wraplength"; Units/int] + XScrollCommand ["-xscrollcommand"; function(first:float, last:float)] + YScrollCommand ["-yscrollcommand"; function(first:float, last:float)] +} + +%%%% Some other common types +type Index external % builtin_index.ml +type sequence ScrollValue external % builtin_ScrollValue.ml +% type sequence ScrollValue { +% MoveTo ["moveto"; float] +% ScrollUnit ["scroll"; int; "unit"] +% ScrollPage ["scroll"; int; "page"] +% } + + + +%%%%% bell(n) +module Bell { +##ifdef CAMLTK + function () ring ["bell"; ?displayof:["-displayof"; widget]] + function () ring_displayof ["bell"; "-displayof" ; displayof: widget] +##else + function () ring ["bell"; ?displayof:["-displayof"; widget]] +##endif + } + +%%%%% bind(n) +% builtin_bind.ml + + +%%%%% bindtags(n) +%type Bindings { +% TagBindings [string] +% WidgetBindings [widget] +% } + +type Bindings external + +function () bindtags ["bindtags"; widget; [bindings: Bindings list]] +function (Bindings list) bindtags_get ["bindtags"; widget] + +%%%%% bitmap(n) +subtype option(bitmapimage) { + Background + Data ["-data"; string] + File ["-file"; string] + Foreground + Maskdata ["-maskdata"; string] + Maskfile ["-maskfile"; string] + } + +module Imagebitmap { + function (ImageBitmap) create ["image"; "create"; "bitmap"; ?name:[ImageBitmap]; option(bitmapimage) list] +##ifdef CAMLTK + function (ImageBitmap) create_named ["image"; "create"; "bitmap"; ImageBitmap; option(bitmapimage) list] +##endif + function () delete ["image"; "delete"; ImageBitmap] + function (int) height ["image"; "height"; ImageBitmap] + function (int) width ["image"; "width"; ImageBitmap] + function () configure [ImageBitmap; "configure"; option(bitmapimage) list] + function (string) configure_get [ImageBitmap; "configure"] + % Functions inherited from the "image" TK class + } + +%%%%% button(n) + +type State { + Normal ["normal"] + Active ["active"] + Disabled ["disabled"] + Hidden ["hidden"] % introduced in tk8.3, requested for Syndex +} + +widget button { + % Standard options + option ActiveBackground + option ActiveForeground + option Anchor + option Background + option Bitmap + option BorderWidth + option Cursor + option DisabledForeground + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness +##ifdef CAMLTK + option ImageBitmap + option ImagePhoto +##else + option Image +##endif + option Justify + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + option UnderlinedChar + option WrapLength + % Widget specific options + option Command ["-command"; function ()] + option Default ["-default"; State] + option Height ["-height"; Units/int] + option State ["-state"; State] + option Width ["-width"; Units/int] + + function () configure [widget(button); "configure"; option(button) list] + function (string) configure_get [widget(button); "configure"] + function () flash [widget(button); "flash"] + function () invoke [widget(button); "invoke"] + } + + +%%%%%% canvas(n) +% Item ids and tags +type TagOrId { + Tag [string] + Id [int] +} + +% Indices: defined internally +% subtype Index(canvas) { +% Number End Insert SelFirst SelLast AtXY +% } + +type SearchSpec { + Above ["above"; TagOrId] + All ["all"] + Below ["below"; TagOrId] + Closest ["closest"; Units/int; Units/int] + ClosestHalo (Closesthalo) ["closest"; Units/int; Units/int; Units/int] + ClosestHaloStart (Closesthalostart) ["closest"; Units/int; Units/int; Units/int; TagOrId] + Enclosed ["enclosed"; Units/int;Units/int;Units/int;Units/int] + Overlapping ["overlapping"; int;int;int;int] + Withtag ["withtag"; TagOrId] +} + +type ColorMode { + Color ["color"] + Gray ["gray"] + Mono ["mono"] +} + +subtype option(postscript) { + % Cannot support this without array variables + % Colormap ["-colormap"; TextVariable] + Colormode ["-colormode"; ColorMode] + File ["-file"; string] + % Fontmap ["-fontmap"; TextVariable] + Height + PageAnchor ["-pageanchor"; Anchor] + PageHeight ["-pageheight"; Units/int] + PageWidth ["-pagewidth"; Units/int] + PageX ["-pagex"; Units/int] + PageY ["-pagey"; Units/int] + Rotate ["-rotate"; bool] + Width + X ["-x"; Units/int] + Y ["-y"; Units/int] + } + + +% Arc item configuration +type ArcStyle { + Arc ["arc"] + Chord ["chord"] + PieSlice ["pieslice"] +} + +subtype option(arc) { + Extent ["-extent"; float] + Dash ["-dash"; string] + % Fill is used by packer + FillColor ["-fill"; Color] + Outline ["-outline"; Color] + OutlineStipple ["-outlinestipple"; Bitmap] + Start ["-start"; float] + Stipple ["-stipple"; Bitmap] + ArcStyle ["-style"; ArcStyle] + Tags ["-tags"; [TagOrId/string list]] + Width + } + +% Bitmap item configuration +subtype option(bitmap) { + Anchor + Background + Bitmap + Foreground + Tags +} + +% Image item configuration +subtype option(image) { + Anchor +##ifdef CAMLTK + ImagePhoto + ImageBitmap +##else + Image +##endif + Tags +} + +% Line item configuration +type ArrowStyle { + Arrow_None ["none"] + Arrow_First ["first"] + Arrow_Last ["last"] + Arrow_Both ["both"] +} + +type CapStyle { + Cap_Butt ["butt"] + Cap_Projecting ["projecting"] + Cap_Round ["round"] +} + +type JoinStyle { + Join_Bevel ["bevel"] + Join_Miter ["miter"] + Join_Round ["round"] +} + +subtype option(line) { + ArrowStyle ["-arrow"; ArrowStyle] + ArrowShape ["-arrowshape"; [Units/int; Units/int; Units/int]] + CapStyle ["-capstyle"; CapStyle] + Dash + FillColor + JoinStyle ["-joinstyle"; JoinStyle] + Smooth ["-smooth"; bool] + SplineSteps ["-splinesteps"; int] + Stipple + Tags + Width + } + +% Oval item configuration +subtype option(oval) { + Dash FillColor Outline Stipple Tags Width + } + +% Polygon item configuration +subtype option(polygon) { + Dash FillColor Outline Smooth SplineSteps + Stipple Tags Width + } + +% Rectangle item configuration +subtype option(rectangle) { + Dash FillColor Outline Stipple Tags Width + } + +% Text item configuration + +##ifndef CAMLTK +% Only for Labltk. CanvasTextState is unified as State in Camltk +type CanvasTextState { + Normal ["normal"] + Disabled ["disabled"] + Hidden ["hidden"] +} +##endif + +subtype option(canvastext) { + Anchor FillColor Font Justify + Stipple Tags Text Width +##ifdef CAMLTK + State % introduced in tk8.3, requested for Syndex +##else + CanvasTextState ["-state"; CanvasTextState] % introduced in tk8.3, requested for Syndex +##endif + } + +% Window item configuration +subtype option(window) { + Anchor Height Tags Width + Window ["-window"; widget] + Dash + } + +% Types of items +type CanvasItem { + Arc_item ["arc"] + Bitmap_item ["bitmap"] + Image_item ["image"] + Line_item ["line"] + Oval_item ["oval"] + Polygon_item ["polygon"] + Rectangle_item ["rectangle"] + Text_item ["text"] + Window_item ["window"] + User_item [string] +} + +widget canvas { + % Standard options + option Background + option BorderWidth + option Cursor + option HighlightBackground + option HighlightColor + option HighlightThickness + option InsertBackground + option InsertBorderWidth + option InsertOffTime + option InsertOnTime + option InsertWidth + option Relief + option SelectBackground + option SelectBorderWidth + option SelectForeground + option TakeFocus + option XScrollCommand + option YScrollCommand + % Widget specific options + option CloseEnough ["-closeenough"; float] + option Confine ["-confine"; bool] + option Height ["-height"; Units/int] + option ScrollRegion ["-scrollregion"; [Units/int;Units/int;Units/int;Units/int]] + option Width ["-width"; Units/int] + option XScrollIncrement ["-xscrollincrement"; Units/int] + option YScrollIncrement ["-yscrollincrement"; Units/int] + + + function () addtag [widget(canvas); "addtag"; tag: TagOrId/string; specs: SearchSpec list] % Tag only + % bbox not fully supported. should be builtin because of ambiguous result + % will raise Protocol.TkError if no items match TagOrId + function (int,int,int,int) bbox [widget(canvas); "bbox"; TagOrId list] + external bind "builtin/canvas_bind" +##ifdef CAMLTK + function (float) canvasx [widget(canvas); "canvasx"; ?spacing:[Units]; Units] + function (float) canvasy [widget(canvas); "canvasy"; ?spacing:[Units]; Units] + function (float) canvasx_grid [widget(canvas); "canvasx"; Units; Units] + function (float) canvasy_grid [widget(canvas); "canvasy"; Units; Units] +##else + function (float) canvasx [widget(canvas); "canvasx"; x:int; ?spacing:[int]] + function (float) canvasy [widget(canvas); "canvasy"; y:int; ?spacing:[int]] +##endif + function () configure [widget(canvas); "configure"; option(canvas) list] + function (string) configure_get [widget(canvas); "configure"] + % TODO: check result + function (float list) coords_get [widget(canvas); "coords"; TagOrId] +##ifdef CAMLTK + function () coords_set [widget(canvas); "coords"; TagOrId; xys: Units list] +##else + function () coords_set [widget(canvas); "coords"; TagOrId; xys: {int, int} list] +##endif + % create variations (see below) + function () dchars [widget(canvas); "dchars"; TagOrId; first: Index(canvas); last: Index(canvas)] + function () delete [widget(canvas); "delete"; TagOrId list] + function () dtag [widget(canvas); "dtag"; TagOrId; tag: TagOrId/string] + function (TagOrId list) find [widget(canvas); "find"; specs: SearchSpec list] + % focus variations + function () focus_reset [widget(canvas); "focus"; ""] + function (TagOrId) focus_get [widget(canvas); "focus"] + function () focus [widget(canvas); "focus"; TagOrId] + function (TagOrId/string list) gettags [widget(canvas); "gettags"; TagOrId] + function () icursor [widget(canvas); "icursor"; TagOrId; index: Index(canvas)] + function (int) index [widget(canvas); "index"; TagOrId; index: Index(canvas)] + function () insert [widget(canvas); "insert"; TagOrId; before: Index(canvas); text: string] + % itemcget, itemconfigure are defined later + function () lower [widget(canvas); "lower"; TagOrId; ?below: [TagOrId]] +##ifdef CAMLTK + function () lower_below [widget(canvas); "lower"; TagOrId; TagOrId] + function () lower_bot [widget(canvas); "lower"; TagOrId] +##endif + function () move [widget(canvas); "move"; TagOrId; x: Units/int; y: Units/int] + unsafe function (string) postscript [widget(canvas); "postscript"; option(postscript) list] + % We use raise with Module name + function () raise [widget(canvas); "raise"; TagOrId; ?above:[TagOrId]] +##ifdef CAMLTK + function () raise_above [widget(canvas); "raise"; TagOrId; TagOrId] + function () raise_top [widget(canvas); "raise"; TagOrId] +##endif + function () scale [widget(canvas); "scale"; TagOrId; xorigin: Units/int; yorigin: Units/int; xscale: float; yscale: float] + % For scan, use x:int and y:int since common usage is with mouse coordinates + function () scan_mark [widget(canvas); "scan"; "mark"; x: int; y: int] + function () scan_dragto [widget(canvas); "scan"; "dragto"; x: int; y: int] + % select variations + function () select_adjust [widget(canvas); "select"; "adjust"; TagOrId; index: Index(canvas)] + function () select_clear [widget(canvas); "select"; "clear"] + function () select_from [widget(canvas); "select"; "from"; TagOrId; index: Index(canvas)] + function (TagOrId) select_item [widget(canvas); "select"; "item"] + function () select_to [widget(canvas); "select"; "to"; TagOrId; index: Index(canvas)] + + function (CanvasItem) typeof [widget(canvas); "type"; TagOrId] + function (float,float) xview_get [widget(canvas); "xview"] + function (float,float) yview_get [widget(canvas); "yview"] + function () xview [widget(canvas); "xview"; scroll: ScrollValue] + function () yview [widget(canvas); "yview"; scroll: ScrollValue] + + % create and configure variations + function (TagOrId) create_arc [widget(canvas); "create"; "arc"; x1: Units/int; y1: Units/int; x2: Units/int; y2: Units/int; option(arc) list] + function (TagOrId) create_bitmap [widget(canvas); "create"; "bitmap"; x: Units/int; y: Units/int; option(bitmap) list] + function (TagOrId) create_image [widget(canvas); "create"; "image"; x: Units/int; y: Units/int; option(image) list] +##ifdef CAMLTK + function (TagOrId) create_line [widget(canvas); "create"; "line"; Units list; option(line) list] + function (TagOrId) create_polygon [widget(canvas); "create"; "polygon"; Units list; option(polygon) list] +##else + function (TagOrId) create_line [widget(canvas); "create"; "line"; xys: {int, int} list; option(line) list] + function (TagOrId) create_polygon [widget(canvas); "create"; "polygon"; xys: {int, int} list; option(polygon) list] +##endif + function (TagOrId) create_oval [widget(canvas); "create"; "oval"; x1: Units/int; y1: Units/int; x2: Units/int; y2: Units/int; option(oval) list] + function (TagOrId) create_rectangle [widget(canvas); "create"; "rectangle"; x1: Units/int; y1: Units/int; x2: Units/int; y2: Units/int; option(rectangle) list] + function (TagOrId) create_text [widget(canvas); "create"; "text"; x: Units/int; y: Units/int; option(canvastext) list] + function (TagOrId) create_window [widget(canvas); "create"; "window"; x: Units/int; y: Units/int; option(window) list] + + function (string) itemconfigure_get [widget(canvas); "itemconfigure"; TagOrId] + + function () configure_arc [widget(canvas); "itemconfigure"; TagOrId; option(arc) list] + function () configure_bitmap [widget(canvas); "itemconfigure"; TagOrId; option(bitmap) list] + function () configure_image [widget(canvas); "itemconfigure"; TagOrId; option(image) list] + function () configure_line [widget(canvas); "itemconfigure"; TagOrId; option(line) list] + function () configure_oval [widget(canvas); "itemconfigure"; TagOrId; option(oval) list] + function () configure_polygon [widget(canvas); "itemconfigure"; TagOrId; option(polygon) list] + function () configure_rectangle [widget(canvas); "itemconfigure"; TagOrId; option(rectangle) list] + function () configure_text [widget(canvas); "itemconfigure"; TagOrId; option(canvastext) list] + function () configure_window [widget(canvas); "itemconfigure"; TagOrId; option(window) list] + } + + +%%%%% checkbutton(n) +widget checkbutton { + % Standard options + option ActiveBackground + option ActiveForeground + option Anchor + option Background + option Bitmap + option BorderWidth + option Cursor + option DisabledForeground + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness +##ifdef CAMLTK + option ImageBitmap + option ImagePhoto +##else + option Image +##endif + option Justify + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + option UnderlinedChar + option WrapLength + % Widget specific options + option Command + option Height + option IndicatorOn ["-indicatoron"; bool] + option OffValue ["-offvalue"; string] + option OnValue ["-onvalue"; string] + option SelectColor ["-selectcolor"; Color] +##ifdef CAMLTK + option SelectImageBitmap (SelectImageBitmap) ["-selectimage"; ImageBitmap] + option SelectImagePhoto (SelectImagePhoto) ["-selectimage"; ImagePhoto] +##else + option SelectImage ["-selectimage"; Image] +##endif + option State + option Variable ["-variable"; TextVariable] + option Width + + function () configure [widget(checkbutton); "configure"; option(checkbutton) list] + function (string) configure_get [widget(checkbutton); "configure"] + function () deselect [widget(checkbutton); "deselect"] + function () flash [widget(checkbutton); "flash"] + function () invoke [widget(checkbutton); "invoke"] + function () select [widget(checkbutton); "select"] + function () toggle [widget(checkbutton); "toggle"] + } + +%%%%% clipboard(n) +subtype icccm(clipboard_append) { + ICCCMFormat ["-format"; string] + ICCCMType ["-type"; string] + } + +module Clipboard { + function () clear ["clipboard"; "clear"; ?displayof:["-displayof"; widget]] + function () append ["clipboard"; "append"; ?displayof:["-displayof"; widget]; icccm(clipboard_append) list; "--"; data: string] + } + +%%%%% destroy(n) +function () destroy ["destroy"; widget] + +%%%%% tk_dialog(n) +module Dialog { + external create "builtin/dialog" + } + +%%%%% entry(n) +% Defined internally +% subtype Index(entry) { +% Number End Insert SelFirst SelLast At AnchorPoint +% } + +##ifndef CAMLTK +% Only for Labltk. InputState is unified as State in Camltk +type InputState { + Normal ["normal"] + Disabled ["disabled"] +} +##endif + +widget entry { + % Standard options + option Background + option BorderWidth + option Cursor + option ExportSelection + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness + option InsertBackground + option InsertBorderWidth + option InsertOffTime + option InsertOnTime + option InsertWidth + option Justify + option Relief + option SelectBackground + option SelectBorderWidth + option SelectForeground + option TakeFocus + option TextVariable + option XScrollCommand + + % Widget specific options + option Show ["-show"; char] +##ifdef CAMLTK + option State +##else + option EntryState ["-state"; InputState] +##endif + option TextWidth (Textwidth) ["-width"; int] + + function (int,int,int,int) bbox [widget(entry); "bbox"; Index(entry)] + function () configure [widget(entry); "configure"; option(entry) list] + function (string) configure_get [widget(entry); "configure"] + function () delete_single [widget(entry); "delete"; index: Index(entry)] + function () delete_range [widget(entry); "delete"; start: Index(entry); stop: Index(entry)] + function (string) get [widget(entry); "get"] + function () icursor [widget(entry); "icursor"; index: Index(entry)] + function (int) index [widget(entry); "index"; index: Index(entry)] + function () insert [widget(entry); "insert"; index: Index(entry); text: string] + function () scan_mark [widget(entry); "scan"; "mark"; x: int] + function () scan_dragto [widget(entry); "scan"; "dragto"; x: int] + % selection variation + function () selection_adjust [widget(entry); "selection"; "adjust"; index: Index(entry)] + function () selection_clear [widget(entry); "selection"; "clear"] + function () selection_from [widget(entry); "selection"; "from"; index: Index(entry)] + function (bool) selection_present [widget(entry); "selection"; "present"] + function () selection_range [widget(entry); "selection"; "range"; start: Index(entry) ; stop: Index(entry)] + function () selection_to [widget(entry); "selection"; "to"; index: Index(entry)] + + function (float,float) xview_get [widget(entry); "xview"] + function () xview [widget(entry); "xview"; scroll: ScrollValue] + function () xview_index [widget(entry); "xview"; index: Index(entry)] + function (float, float) xview_get [widget(entry); "xview"] + } + + +%%%%% focus(n) +%%%%% tk_focusNext(n) +module Focus { + unsafe function (widget) get ["focus"; ?displayof:["-displayof"; widget]] + unsafe function (widget) displayof ["focus"; "-displayof"; widget] + function () set ["focus"; widget] + function () force ["focus"; "-force"; widget] + unsafe function (widget) lastfor ["focus"; "-lastfor"; widget] + unsafe function (widget) next ["tk_focusNext"; widget] + unsafe function (widget) prev ["tk_focusPrev"; widget] + function () follows_mouse ["tk_focusFollowsMouse"] +} + +type font external % builtin/builtin_font.ml + +type weight { + Weight_Normal(Normal) ["normal"] + Weight_Bold(Bold) ["bold"] +} + +type slant { + Slant_Roman(Roman) ["roman"] + Slant_Italic(Italic) ["italic"] +} + +type fontMetrics { + Ascent ["-ascent"] + Descent ["-descent"] + Linespace ["-linespace"] + Fixed ["-fixed"] +} + +subtype options(font) { + Font_Family ["-family"; string] + Font_Size ["-size"; int] + Font_Weight ["-weight"; weight] + Font_Slant ["-slant"; slant] + Font_Underline ["-underline"; bool] + Font_Overstrike ["-overstrike"; bool] +% later, JP only +% Charset ["-charset"; string] +%% Beware of the order of Compound ! Put it as the first option +% Compound ["-compound"; [font list]] +% Copy ["-copy"; string] +} + +module Font { + function (string) actual_family ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-family"] + function (int) actual_size ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-size"] + function (string) actual_weight ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-weight"] + function (string) actual_slant ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-slant"] + function (bool) actual_underline ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-underline"] + function (bool) actual_overstrike ["font"; "actual"; font; + ?displayof:["-displayof"; widget]; + "-overstrike"] + + function () configure ["font"; "configure"; font; options(font) list] + function (font) create ["font"; "create"; ?name:[string]; options(font) list] +##ifdef CAMLTK + function (font) create_named ["font"; "create"; string; options(font) list] +##endif + function () delete ["font"; "delete"; font] + function (string list) families ["font"; "families"; + ?displayof:["-displayof"; widget]] +##ifdef CAMLTK + function (string list) families_displayof ["font"; "families"; + "-displayof"; widget] +##endif + function (int) measure ["font"; "measure"; font; string; + ?displayof:["-displayof"; widget]] +##ifdef CAMLTK + function (int) measure_displayof ["font"; "measure"; font; + "-displayof"; widget; string ] +##endif + function (int) metrics ["font"; "metrics"; font; + ?displayof:["-displayof"; widget]; + fontMetrics ] +##ifdef CAMLTK + function (int) metrics_displayof ["font"; "metrics"; font; + "-displayof"; widget; + fontMetrics ] +##endif + function (string list) names ["font"; "names"] +% JP +% function () failsafe ["font"; "failsafe"; string] +} + +%%%%% frame(n) +type Colormap { + NewColormap (New) ["new"] + WidgetColormap (Widget) [widget] + } + +% Visual classes are: directcolor, grayscale, greyscale, pseudocolor, +% staticcolor, staticgray, staticgrey, truecolor +type Visual { + ClassVisual (Clas) [[string; int]] + DefaultVisual ["default"] + WidgetVisual (Widget) [widget] + BestDepth (Bestdepth) [["best"; int]] + Best ["best"] + } + +widget frame { + % Standard options + option BorderWidth + option Cursor + option HighlightBackground + option HighlightColor + option HighlightThickness + option Relief + option TakeFocus + + % Widget specific options + option Background +##ifdef CAMLTK + option Class ["-class"; string] +##else + option Clas ["-class"; string] +##endif + option Colormap ["-colormap"; Colormap] + option Container ["-container"; bool] + option Height + option Visual ["-visual"; Visual] + option Width + + % Class and Colormap and Visual cannot be changed + function () configure [widget(frame); "configure"; option(frame) list] + function (string) configure_get [widget(frame); "configure"] + } + + + +%%%%% grab(n) +type GrabStatus { + GrabNone ["none"] + GrabLocal ["local"] + GrabGlobal ["global"] +} +type GrabGlobal external +module Grab { + function () set ["grab"; "set"; ?global:[GrabGlobal]; widget] +##ifdef CAMLTK + function () set_global ["grab"; "set"; "-global"; widget] +##endif + unsafe function (widget list) current ["grab"; "current"; ?displayof:[widget]] +##ifdef CAMLTK + % all_current is now current. + % The old current is now current_of + unsafe function (widget list) current_of ["grab"; "current"; widget] +##endif + function () release ["grab"; "release"; widget] + function (GrabStatus) status ["grab"; "status"; widget] +} + +subtype option(rowcolumnconfigure) { + Minsize ["-minsize"; Units/int] + Weight ["-weight"; int] + Pad ["-pad"; Units/int] +} + +subtype option(grid) { + Column ["-column"; int] + ColumnSpan ["-columnspan"; int] + In(Inside) ["-in"; widget] + IPadX ["-ipadx"; Units/int] + IPadY ["-ipady"; Units/int] + PadX + PadY + Row ["-row"; int] + RowSpan ["-rowspan"; int] + Sticky ["-sticky"; string] + } + +% Same as pack +function () grid ["grid"; widget list; option(grid) list] + +module Grid { + function (int,int,int,int) bbox ["grid"; "bbox"; widget] + function (int,int,int,int) bbox_cell ["grid"; "bbox"; widget; column: int; row: int] + function (int,int,int,int) bbox_span ["grid"; "bbox"; widget; column1: int; row1: int; column2: int; row2: int] + function () column_configure + ["grid"; "columnconfigure"; widget; int; + option(rowcolumnconfigure) list] + function () configure ["grid"; "configure"; widget list; option(grid) list] + function (string) column_configure_get ["grid"; "columnconfigure"; widget; + int] + function () forget ["grid"; "forget"; widget list] + %% info returns only a string + function (string) info ["grid"; "info"; widget] + %% TODO: check result values + function (int,int) location ["grid"; "location"; widget; x:Units/int; y:Units/int] + function (bool) propagate_get ["grid"; "propagate"; widget] + function () propagate_set ["grid"; "propagate"; widget; bool] + function () row_configure + ["grid"; "rowconfigure"; widget; int; option(rowcolumnconfigure) list] + function (string) row_configure_get ["grid"; "rowconfigure"; widget; int] + function (int,int) size ["grid"; "size"; widget] + +##ifdef CAMLTK + function (widget list) slaves ["grid"; "slaves"; widget; ?column:["-column"; int]; ?row:["-row"; int]] + function (widget list) row_slaves ["grid"; "slaves"; widget; "-row"; int] + function (widget list) column_slaves ["grid"; "slaves"; widget; "-column"; int] +##else + function (widget list) slaves ["grid"; "slaves"; widget; ?column:["-column"; int]; ?row:["-row"; int]] +##endif + } + +%%%%% image(n) +%%%%% cf Imagephoto and Imagebitmap +% Some functions on images are implemented in Imagephoto or Imagebitmap. +module Image { + external names "builtin/image" +} + +%%%%% label(n) +widget label { + % Standard options + option Anchor + option Background + option Bitmap + option BorderWidth + option Cursor + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness +##ifdef CAMLTK + option ImageBitmap + option ImagePhoto +##else + option Image +##endif + option Justify + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + option UnderlinedChar + option WrapLength + + % Widget specific options + option Height + % use according to label contents + option Width + option TextWidth + + function () configure [widget(label); "configure"; option(label) list] + function (string) configure_get [widget(label); "configure"] + } + + +%%%%% listbox(n) + +% Defined internally +% subtype Index(listbox) { +% Number Active AnchorPoint End AtXY +%} + +type SelectModeType { + Single ["single"] + Browse ["browse"] + Multiple ["multiple"] + Extended ["extended"] + } + + +widget listbox { + % Standard options + option Background + option BorderWidth + option Cursor + option ExportSelection + option Font + option Foreground + % Height is TextHeight + option HighlightBackground + option HighlightColor + option HighlightThickness + option Relief + option SelectBackground + option SelectBorderWidth + option SelectForeground + option SetGrid + option TakeFocus + % Width is TextWidth + option XScrollCommand + option YScrollCommand + % Widget specific options + option TextHeight ["-height"; int] + option TextWidth + option SelectMode ["-selectmode"; SelectModeType] + + function () activate [widget(listbox); "activate"; index: Index(listbox)] + function (int,int,int,int) bbox [widget(listbox); "bbox"; index: Index(listbox)] + function () configure [widget(listbox); "configure"; option(listbox) list] + function (string) configure_get [widget(listbox); "configure"] + function (Index(listbox) as "[>`Num of int]" list) curselection [widget(listbox); "curselection"] + function () delete [widget(listbox); "delete"; first: Index(listbox); last: Index(listbox)] + function (string) get [widget(listbox); "get"; index: Index(listbox)] + function (string list) get_range [widget(listbox); "get"; first: Index(listbox); last: Index(listbox)] + function (Index(listbox) as "[>`Num of int]") index [widget(listbox); "index"; index: Index(listbox)] + function () insert [widget(listbox); "insert"; index: Index(listbox); texts: string list] + function (Index(listbox) as "[>`Num of int]") nearest [widget(listbox); "nearest"; y: int] + function () scan_mark [widget(listbox); "scan"; "mark"; x: int; y: int] + function () scan_dragto [widget(listbox); "scan"; "dragto"; x: int; y: int] + function () see [widget(listbox); "see"; index: Index(listbox)] + function () selection_anchor [widget(listbox); "selection"; "anchor"; index: Index(listbox)] + function () selection_clear [widget(listbox); "selection"; "clear"; first: Index(listbox); last: Index(listbox)] + function (bool) selection_includes [widget(listbox); "selection"; "includes"; index: Index(listbox)] + function () selection_set [widget(listbox); "selection"; "set"; first: Index(listbox); last: Index(listbox)] + function (int) size [widget(listbox); "size"] + + function (float,float) xview_get [widget(listbox); "xview"] + function (float,float) yview_get [widget(listbox); "yview"] + function () xview_index [widget(listbox); "xview"; index: Index(listbox)] + function () yview_index [widget(listbox); "yview"; index: Index(listbox)] + function () xview [widget(listbox); "xview"; scroll: ScrollValue] + function () yview [widget(listbox); "yview"; scroll: ScrollValue] + } + +%%%%% lower(n) +function () lower_window ["lower"; widget; ?below:[widget]] +##ifdef CAMLTK +function () lower_window_below ["lower"; widget; below: widget] +##endif + + +%%%%% menu(n) +%%%%% tk_popup(n) +% defined internally +% subtype Index(menu) { +% Number Active End Last None At Pattern +% } + +type MenuItem { + Cascade_Item ["cascade"] + Checkbutton_Item ["checkbutton"] + Command_Item ["command"] + Radiobutton_Item ["radiobutton"] + Separator_Item ["separator"] + TearOff_Item ["tearoff"] +} + +% notused as a subtype. just for cleaning up the rest. +subtype option(menuentry) { + ActiveBackground + ActiveForeground + Accelerator ["-accelerator"; string] + Background + Bitmap + ColumnBreak ["-columnbreak"; bool] + Command + Font + Foreground + HideMargin ["-hidemargin"; bool] +##ifdef CAMLTK + ImageBitmap + ImagePhoto +##else + Image +##endif + IndicatorOn + Label ["-label"; string] + Menu ["-menu"; widget(menu)] + OffValue + OnValue + SelectColor +##ifdef CAMLTK + SelectImageBitmap + SelectImagePhoto +##else + SelectImage +##endif + State + UnderlinedChar + Value ["-value"; string] + Variable + } + +% Options for cascade entry +subtype option(menucascade) { + ActiveBackground ActiveForeground Accelerator + Background Bitmap ColumnBreak Command Font Foreground + HideMargin +##ifdef CAMLTK + ImageBitmap ImagePhoto +##else + Image +##endif + IndicatorOn Label Menu State UnderlinedChar + } + +% Options for radiobutton entry +subtype option(menuradio) { + ActiveBackground ActiveForeground Accelerator + Background Bitmap ColumnBreak Command Font Foreground +##ifdef CAMLTK + ImageBitmap ImagePhoto SelectImageBitmap SelectImagePhoto +##else + Image SelectImage +##endif + IndicatorOn Label SelectColor + State UnderlinedChar Value Variable + } + +% Options for checkbutton entry +subtype option(menucheck) { + ActiveBackground ActiveForeground Accelerator + Background Bitmap ColumnBreak Command Font Foreground +##ifdef CAMLTK + ImageBitmap SelectImageBitmap ImagePhoto SelectImagePhoto +##else + Image SelectImage +##endif + IndicatorOn Label + OffValue OnValue SelectColor + State UnderlinedChar Variable + } + +% Options for command entry +subtype option(menucommand) { + ActiveBackground ActiveForeground Accelerator + Background Bitmap ColumnBreak Command Font Foreground +##ifdef CAMLTK + ImageBitmap ImagePhoto +##else + Image +##endif + Label State UnderlinedChar + } + +type menuType { + Menu_Menubar ["menubar"] + Menu_Tearoff ["tearoff"] + Menu_Normal ["normal"] +} + +% Separators and tearoffs don't have options + +widget menu { + % Standard options + option ActiveBackground + option ActiveBorderWidth + option ActiveForeground + option Background + option BorderWidth + option Cursor + option DisabledForeground + option Font + option Foreground + option Relief + option TakeFocus + % Widget specific options + option PostCommand ["-postcommand"; function()] + option SelectColor + option TearOff ["-tearoff"; bool] + option TearOffCommand ["-tearoffcommand"; function(menu: widget(any), tornoff: widget(any)) ] + option MenuTitle ["-title"; string] + option MenuType ["-type"; menuType] + + function () activate [widget(menu); "activate"; index: Index(menu)] + % add variations + function () add_cascade [widget(menu); "add"; "cascade"; option(menucascade) list] + function () add_checkbutton [widget(menu); "add"; "checkbutton"; option(menucheck) list] + function () add_command [widget(menu); "add"; "command"; option(menucommand) list] + function () add_radiobutton [widget(menu); "add"; "radiobutton"; option(menuradio) list] + function () add_separator [widget(menu); "add"; "separator"] + % not for user: function clone [widget(menu); "clone"; ???; menuType] + function () configure [widget(menu); "configure"; option(menu) list] + function (string) configure_get [widget(menu); "configure"] + % beware of possible callback leak when deleting menu entries + function () delete [widget(menu); "delete"; first: Index(menu); last: Index(menu)] + function () configure_cascade [widget(menu); "entryconfigure"; Index(menu); option(menucascade) list] + function () configure_checkbutton [widget(menu); "entryconfigure"; Index(menu); option(menucheck) list] + function () configure_command [widget(menu); "entryconfigure"; Index(menu); option(menucommand) list] + function () configure_radiobutton [widget(menu); "entryconfigure"; Index(menu); option(menuradio) list] + function (string) entryconfigure_get [widget(menu); "entryconfigure"; Index(menu)] + function (int) index [widget(menu); "index"; Index(menu)] + function () insert_cascade [widget(menu); "insert"; index: Index(menu); "cascade"; option(menucascade) list] + function () insert_checkbutton [widget(menu); "insert"; index: Index(menu); "checkbutton"; option(menucheck) list] + function () insert_command [widget(menu); "insert"; index: Index(menu); "command"; option(menucommand) list] + function () insert_radiobutton [widget(menu); "insert"; index: Index(menu); "radiobutton"; option(menuradio) list] + function () insert_separator [widget(menu); "insert"; index: Index(menu); "separator"] + function (string) invoke [widget(menu); "invoke"; index: Index(menu)] + function () post [widget(menu); "post"; x: int; y: int] + function () postcascade [widget(menu); "postcascade"; index: Index(menu)] + % can't use type of course + function (MenuItem) typeof [widget(menu); "type"; index: Index(menu)] + function () unpost [widget(menu); "unpost"] + function (int) yposition [widget(menu); "yposition"; index: Index(menu)] + + function () popup ["tk_popup"; widget(menu); x: int; y: int; ?entry:[Index(menu)]] +##ifdef CAMLTK + function () popup_entry ["tk_popup"; widget(menu); x: int; y: int; index: Index(menu)] +##endif + } + + +%%%%% menubutton(n) + +type menubuttonDirection { + Dir_Above ["above"] + Dir_Below ["below"] + Dir_Left ["left"] + Dir_Right ["right"] +} + +widget menubutton { + % Standard options + option ActiveBackground + option ActiveForeground + option Anchor + option Background + option Bitmap + option BorderWidth + option Cursor + option DisabledForeground + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness +##ifdef CAMLTK + option ImageBitmap + option ImagePhoto +##else + option Image +##endif + option Justify + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + option UnderlinedChar + option WrapLength + % Widget specific options + option Direction ["-direction"; menubuttonDirection ] + option Height + option IndicatorOn + option Menu ["-menu"; widget(menu)] + option State + option Width + option TextWidth + + function () configure [widget(menubutton); "configure"; option(menubutton) list] + function (string) configure_get [widget(menubutton); "configure"] + } + + + +%%%%% message(n) +widget message { + % Standard options + option Anchor + option Background + option BorderWidth + option Cursor + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + % Widget specific options + option Aspect ["-aspect"; int] + option Justify + option Width + + function () configure [widget(message); "configure"; option(message) list] + function (string) configure_get [widget(message); "configure"] + } + + +%%%%% option(n) +type OptionPriority { + WidgetDefault ["widgetDefault"] + StartupFile ["startupFile"] + UserDefault ["userDefault"] + Interactive ["interactive"] + Priority [int] + } + +##ifdef CAMLTK + +module Option { + unsafe function () add ["option"; "add"; string; string; OptionPriority] + function () clear ["option"; "clear"] + function (string) get ["option"; "get"; widget; string; string] + unsafe function () readfile ["option"; "readfile"; string; OptionPriority] + } +%% Resource is now superseded by Option +module Resource { + unsafe function () add ["option"; "add"; string; string; OptionPriority] + function () clear ["option"; "clear"] + function (string) get ["option"; "get"; widget; string; string] + unsafe function () readfile ["option"; "readfile"; string; OptionPriority] + } +##else +module Option { + unsafe function () add + ["option"; "add"; path: string; string; ?priority:[OptionPriority]] + function () clear ["option"; "clear"] + function (string) get ["option"; "get"; widget; name: string; clas: string] + unsafe function () readfile + ["option"; "readfile"; string; ?priority:[OptionPriority]] + } +##endif + +%%%%% tk_optionMenu(n) +module Optionmenu { + external create "builtin/optionmenu" + } + + +%%%%% pack(n) +type Side { + Side_Left ["left"] + Side_Right ["right"] + Side_Top ["top"] + Side_Bottom ["bottom"] +} + +type FillMode { + Fill_None ["none"] + Fill_X ["x"] + Fill_Y ["y"] + Fill_Both ["both"] +} + +subtype option(pack) { + After ["-after"; widget] + Anchor + Before ["-before"; widget] + Expand ["-expand"; bool] + Fill ["-fill"; FillMode] + In(Inside) ["-in"; widget] + IPadX ["-ipadx"; Units/int] + IPadY ["-ipady"; Units/int] + PadX + PadY + Side ["-side"; Side] +} + +function () pack ["pack"; widget list; option(pack) list] + +module Pack { + function () configure ["pack"; "configure"; widget list; option(pack) list] + function () forget ["pack"; "forget"; widget list] + function (string) info ["pack"; "info"; widget] + function (bool) propagate_get ["pack"; "propagate"; widget] + function () propagate_set ["pack"; "propagate"; widget; bool] + function (widget list) slaves ["pack"; "slaves"; widget] + } + +subtype TkPalette(any) { % Not sophisticated... + PaletteActiveBackground ["activeBackground"; Color] + PaletteActiveForeground ["activeForeground"; Color] + PaletteBackground ["background"; Color] + PaletteDisabledForeground ["disabledForeground"; Color] + PaletteForeground ["foreground"; Color] + PaletteHighlightBackground ["hilightBackground"; Color] + PaletteHighlightColor ["highlightColor"; Color] + PaletteInsertBackground ["insertBackground"; Color] + PaletteSelectColor ["selectColor"; Color] + PaletteSelectBackground ["selectBackground"; Color] + PaletteForegroundselectColor ["selectForeground"; Color] + PaletteTroughColor ["troughColor"; Color] +} + +%%%%% tk_setPalette(n) +%%%% can't simply encode general form of tk_setPalette +module Palette { + function () set_background ["tk_setPalette"; Color] + function () set ["tk_setPalette"; TkPalette(any) list] + function () bisque ["tk_bisque"] + } + +%%%%% photo(n) +type PaletteType external % builtin_palette.ml + +subtype option(photoimage) { + % Channel ["-channel"; file_descr] % removed in 8.3 ? + Data + Format ["-format"; string] + File + Gamma ["-gamma"; float] + Height + Palette ["-palette"; PaletteType] + Width + } + +subtype photo(copy) { + ImgFrom(Src_area) ["-from"; int; int; int; int] + ImgTo(Dst_area) ["-to"; int; int; int; int] + Shrink ["-shrink"] + Zoom ["-zoom"; int; int] + Subsample ["-subsample"; int; int] + } + +subtype photo(put) { + ImgTo + } + +subtype photo(read) { + ImgFormat ["-format"; string] + ImgFrom + Shrink + TopLeft(Dst_pos) ["-to"; int; int] + } + +subtype photo(write) { + ImgFormat ImgFrom + } + +module Imagephoto { + function (ImagePhoto) create ["image"; "create"; "photo"; ?name:[ImagePhoto]; option(photoimage) list] +##ifdef CAMLTK + function (ImagePhoto) create_named ["image"; "create"; "photo"; ImagePhoto; option(photoimage) list] +##endif + function () delete ["image"; "delete"; ImagePhoto] + function (int) height ["image"; "height"; ImagePhoto] + function (int) width ["image"; "width"; ImagePhoto] + +%name +%type + + function () blank [ImagePhoto; "blank"] + function () configure [ImagePhoto; "configure"; option(photoimage) list] + function (string) configure_get [ImagePhoto; "configure"] + function () copy [ImagePhoto; "copy"; src: ImagePhoto; photo(copy) list] + function (int, int, int) get [ImagePhoto; "get"; x: int; y: int] +% it is buggy ? can't express nested lists ? + function () put [ImagePhoto; "put"; [Color list list]; photo(put) list] +% external put "builtin/imagephoto_put" + function () read [ImagePhoto; "read"; file: string; photo(read) list] + function () redither [ImagePhoto; "redither"] + function () write [ImagePhoto; "write"; file: string; photo(write) list] + % Functions inherited from the "image" TK class + } + + +%%%%% place(n) +type BorderMode { + Inside ["inside"] + Outside ["outside"] + Ignore ["ignore"] +} + +subtype option(place) { + In + X + RelX ["-relx"; float] + Y + RelY ["-rely"; float] + Anchor + Width + RelWidth ["-relwidth"; float] + Height + RelHeight ["-relheight"; float] + BorderMode ["-bordermode"; BorderMode] +} + +function () place ["place"; widget; option(place) list] + +module Place { + function () configure ["place"; "configure"; widget; option(place) list] + function () forget ["place"; "forget"; widget] + function (string) info ["place"; "info"; widget] + function (widget list) slaves ["place"; "slaves"; widget] +} + + +%%%%% radiobutton(n) + +widget radiobutton { + % Standard options + option ActiveBackground + option ActiveForeground + option Anchor + option Background + option Bitmap + option BorderWidth + option Cursor + option DisabledForeground + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness +##ifdef CAMLTK + option ImageBitmap + option ImagePhoto +##else + option Image +##endif + option Justify + option PadX + option PadY + option Relief + option TakeFocus + option Text + option TextVariable + option UnderlinedChar + option WrapLength + + % Widget specific options + option Command + option Height + option IndicatorOn + option SelectColor +##ifdef CAMLTK + option SelectImageBitmap + option SelectImagePhoto +##else + option SelectImage +##endif + option State + option Value + option Variable + option Width + + function () configure [widget(radiobutton); "configure"; option(radiobutton) list] + function (string) configure_get [widget(radiobutton); "configure"] + function () deselect [widget(radiobutton); "deselect"] + function () flash [widget(radiobutton); "flash"] + function () invoke [widget(radiobutton); "invoke"] + function () select [widget(radiobutton); "select"] + } + + +%%%%% raise(n) +% We cannot use raise !! +function () raise_window ["raise"; widget; ?above:[widget]] +##ifdef CAMLTK +function () raise_window_above ["raise"; widget; widget] +##endif + +%%%%% scale(n) +%% shared with scrollbars +##ifdef CAMLTK +subtype WidgetElement(scale) { + Slider ["slider"] + Trough1 ["trough1"] + Trough2 ["trough2"] + Beyond [""] + } +##else +type ScaleElement { + Slider ["slider"] + Trough1 ["trough1"] + Trough2 ["trough2"] + Beyond [""] + } +##endif + +widget scale { + % Standard options + option ActiveBackground + option Background + option BorderWidth + option Cursor + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness + option Orient + option Relief + option RepeatDelay + option RepeatInterval + option TakeFocus + option TroughColor + + % Widget specific options + option BigIncrement ["-bigincrement"; float] + option ScaleCommand ["-command"; function (float)] + option Digits ["-digits"; int] + option From(Min) ["-from"; float] + option Label ["-label"; string] + option Length ["-length"; Units/int] + option Resolution ["-resolution"; float] + option ShowValue ["-showvalue"; bool] + option SliderLength ["-sliderlength"; Units/int] + option State + option TickInterval ["-tickinterval"; float] + option To(Max) ["-to"; float] + option Variable + option Width + +##ifdef CAMLTK + function (int,int) coords [widget(scale); "coords"] + function (int,int) coords_at [widget(scale); "coords"; at: float] +##else + function (int,int) coords [widget(scale); "coords"; ?at: [float]] +##endif + function () configure [widget(scale); "configure"; option(scale) list] + function (string) configure_get [widget(scale); "configure"] + function (float) get [widget(scale); "get"] + function (float) get_xy [widget(scale); "get"; x: int; y: int] + function (WidgetElement/ScaleElement) identify [widget(scale); x: int; y: int] + function () set [widget(scale); "set"; float] + } + + +%%%%% scrollbar(n) +##ifdef CAMLTK +subtype WidgetElement(scrollbar) { + Arrow1 ["arrow1"] + Trough1 + Trough2 + Slider + Arrow2 ["arrow2"] + Beyond + } +##else +type ScrollbarElement { + Arrow1 ["arrow1"] + Trough1 ["through1"] + Trough2 ["through2"] + Slider ["slider"] + Arrow2 ["arrow2"] + Beyond [""] + } +##endif + +widget scrollbar { + % Standard options + option ActiveBackground + option Background + option BorderWidth + option Cursor + option HighlightBackground + option HighlightColor + option HighlightThickness + option Jump + option Orient + option Relief + option RepeatDelay + option RepeatInterval + option TakeFocus + option TroughColor + % Widget specific options + option ActiveRelief ["-activerelief"; Relief] + option ScrollCommand ["-command"; function(scroll: ScrollValue)] + option ElementBorderWidth ["-elementborderwidth"; Units/int] + option Width + +##ifdef CAMLTK + function () activate [widget(scrollbar); "activate"; element: WidgetElement(scrollbar)] +##else + function () activate [widget(scrollbar); "activate"; element: ScrollbarElement] +##endif + function (WidgetElement/ScrollbarElement) activate_get [widget(scrollbar); "activate"] + function () configure [widget(scrollbar); "configure"; option(scrollbar) list] + function (string) configure_get [widget(scrollbar); "configure"] + function (float) delta [widget(scrollbar); "delta"; x: int; y: int] + function (float) fraction [widget(scrollbar); "fraction"; x: int; y: int] + function (float, float) get [widget(scrollbar); "get"] + function (int,int,int,int) old_get [widget(scrollbar); "get"] + function (WidgetElement/ScrollbarElement) identify [widget(scale); "identify"; int; int] + function () set [widget(scrollbar); "set"; first: float; last: float] + function () old_set [widget(scrollbar); "set"; total:int; window:int; first:int; last:int] + } + + +%%%%% selection(n) + +subtype icccm(selection_clear) { + DisplayOf ["-displayof"; widget] + Selection ["-selection"; string] + } + +subtype icccm(selection_get) { + DisplayOf + Selection + ICCCMType + } + +subtype icccm(selection_ownset) { + LostCommand ["-command"; function()] + Selection + } + +subtype icccm(selection_handle) { + Selection + ICCCMType + ICCCMFormat ["-format"; string] + } + +module Selection { + function () clear ["selection"; "clear"; icccm(selection_clear) list] + function (string) get ["selection"; "get"; icccm(selection_get) list] + + % function () handle_set ["selection"; "handle"; icccm(selection_handle) list; widget; function(int,int)] + external handle_set "builtin/selection_handle_set" + unsafe function (widget) own_get ["selection"; "own"; icccm(selection_clear) list] + % builtin + % function () own_set ["selection"; "own"; widget; icccm(selection_ownset) list] + external own_set "builtin/selection_own_set" + } + + +%%%%% send(n) +type SendOption { + SendDisplayOf ["-displayof"; widget] % DisplayOf is used for icccm ! + SendAsync ["-async"] +} + +unsafe function () send ["send"; SendOption list; "--"; app: string; command: string list] + +%%%%% text(n) + +type TextIndex external +type TextTag external +type TextMark external + + +type TabType { + TabLeft [Units/int; "left"] + TabRight [Units/int; "right"] + TabCenter [Units/int; "center"] + TabNumeric [Units/int; "numeric"] + } + +type WrapMode { + WrapNone ["none"] + WrapChar ["char"] + WrapWord ["word"] +} + +type Comparison { + LT (Lt) ["<"] + LE (Le) ["<="] + EQ (Eq) ["=="] + GE (Ge) [">="] + GT (Gt) [">"] + NEQ (Neq) ["!="] +} + +type MarkDirection { + Mark_Left ["left"] + Mark_Right ["right"] + } + +type AlignType { + Align_Top ["top"] + Align_Bottom ["bottom"] + Align_Center ["center"] + Align_Baseline ["baseline"] + } + +subtype option(embeddedi) { + Align ["-align"; AlignType] +##ifdef CAMLTK + ImageBitmap + ImagePhoto +##else + Image +##endif + Name ["-name"; string] + PadX + PadY + } + +subtype option(embeddedw) { + Align ["-align"; AlignType] + PadX + PadY + Stretch ["-stretch"; bool] + Window + } + +type TextSearch { + Forwards ["-forwards"] + Backwards ["-backwards"] + Exact ["-exact"] + Regexp ["-regexp"] + Nocase ["-nocase"] + Count ["-count"; TextVariable] + } + +type text_dump { + DumpAll ["-all"] + DumpCommand ["-command"; function (key: string, value: string, index: string)] + DumpMark ["-mark"] + DumpTag ["-tag"] + DumpText ["-text"] + DumpWindow ["-window"] + } + +widget text { + % Standard options + option Background + option BorderWidth + option Cursor + option ExportSelection + option Font + option Foreground + option HighlightBackground + option HighlightColor + option HighlightThickness + option InsertBackground + option InsertBorderWidth + option InsertOffTime + option InsertOnTime + option InsertWidth + option PadX + option PadY + option Relief + option SelectBackground + option SelectBorderWidth + option SelectForeground + option SetGrid + option TakeFocus + option XScrollCommand + option YScrollCommand + + % Widget specific options + option TextHeight + option Spacing1 ["-spacing1"; Units/int] + option Spacing2 ["-spacing2"; Units/int] + option Spacing3 ["-spacing3"; Units/int] +##ifdef CAMLTK + option State +##else + option EntryState +##endif + option Tabs ["-tabs"; [TabType list]] + option TextWidth + option Wrap ["-wrap"; WrapMode] + + function (int,int,int,int) bbox [widget(text); "bbox"; index: TextIndex] + function (bool) compare [widget(text); "compare"; index: TextIndex; op: Comparison; index: TextIndex] + function () configure [widget(text); "configure"; option(text) list] + function (string) configure_get [widget(text); "configure"] + function () debug [widget(text); "debug"; bool] + function () delete [widget(text); "delete"; start: TextIndex; stop: TextIndex] + function () delete_char [widget(text); "delete"; index: TextIndex] + function (int, int, int, int, int) dlineinfo [widget(text); "dlineinfo"; index: TextIndex] + + % require result parser + function (string list) dump [widget(text); "dump"; text_dump list; start: TextIndex; stop: TextIndex] + function (string list) dump_char [widget(text); "dump"; text_dump list; index: TextIndex] + + function (string) get [widget(text); "get"; start: TextIndex; stop: TextIndex] + function (string) get_char [widget(text); "get"; index: TextIndex] + function () image_configure + [widget(text); "image"; "configure"; name: string; option(embeddedi) list] + function (string) image_configure_get + [widget(text); "image"; "cgets"; name: string] + function (string) image_create + [widget(text); "image"; "create"; index: TextIndex; option(embeddedi) list] + function (string list) image_names [widget(text); "image"; "names"] + function (Index(text) as "[>`Linechar of int * int]") index [widget(text); "index"; index: TextIndex] +##ifdef CAMLTK + function () insert [widget(text); "insert"; index: TextIndex; text: string; [TextTag list]] +##else + function () insert [widget(text); "insert"; index: TextIndex; text: string; ?tags: [TextTag list]] +##endif + % Mark + function () mark_gravity_set [widget(text); "mark"; "gravity"; mark: TextMark; direction: MarkDirection] + function (MarkDirection) mark_gravity_get [widget(text); "mark"; "gravity"; mark: TextMark] + function (TextMark list) mark_names [widget(text); "mark"; "names"] + function (TextMark) mark_next [widget(text); "mark"; "next"; index: TextIndex] + function (TextMark) mark_previous [widget(text); "mark"; "previous"; index: TextIndex] + function () mark_set [widget(text); "mark"; "set"; mark: TextMark; index: TextIndex] + function () mark_unset [widget(text); "mark"; "unset"; marks: TextMark list] + % Scan + function () scan_mark [widget(text); "scan"; "mark"; x: int; y: int] + function () scan_dragto [widget(text); "scan"; "dragto"; x: int; y: int] +##ifdef CAMLTK + function (Index) search [widget(text); "search"; TextSearch list; "--"; string; TextIndex; TextIndex] +##else + function (Index(text) as "[>`Linechar of int * int]") search [widget(text); "search"; switches: TextSearch list; "--"; pattern: string; start: TextIndex; ?stop: [TextIndex]] +##endif + function () see [widget(text); "see"; index: TextIndex] + % Tags + function () tag_add [widget(text); "tag"; "add"; tag: TextTag; start: TextIndex; stop: TextIndex] + function () tag_add_char [widget(text); "tag"; "add"; tag: TextTag; index: TextIndex] + external tag_bind "builtin/text_tag_bind" + function () tag_configure [widget(text); "tag"; "configure"; tag: TextTag; option(texttag) list] + function () tag_delete [widget(text); "tag"; "delete"; TextTag list] + + function () tag_lower [widget(text); "tag"; "lower"; tag: TextTag; ?below: [TextTag]] +##ifdef CAMLTK + function () tag_lower_below [widget(text); "tag"; "lower"; TextTag; TextTag] + function () tag_lower_bot [widget(text); "tag"; "lower"; TextTag] +##endif + + function (TextTag list) tag_names [widget(text); "tag"; "names"; ?index: [TextIndex]] +##ifdef CAMLTK + function (TextTag list) tag_allnames [widget(text); "tag"; "names"] + function (TextTag list) tag_indexnames [widget(text); "tag"; "names"; TextIndex] +##endif + +##ifdef CAMLTK + function (Index, Index) tag_nextrange [widget(text); "tag"; "nextrange"; TextTag; start: TextIndex; stop: TextIndex] + function (Index, Index) tag_prevrange [widget(text); "tag"; "prevrange"; TextTag; start: TextIndex; stop: TextIndex] +##else + function (Index(text) as "[>`Linechar of int * int]", Index(text) as "[>`Linechar of int * int]") tag_nextrange [widget(text); "tag"; "nextrange"; tag: TextTag; start: TextIndex; ?stop: [TextIndex]] + function (Index(text) as "[>`Linechar of int * int]", Index(text) as "[>`Linechar of int * int]") tag_prevrange [widget(text); "tag"; "prevrange"; tag: TextTag; start: TextIndex; ?stop: [TextIndex]] +##endif + + function () tag_raise [widget(text); "tag"; "raise"; tag: TextTag; ?above: [TextTag]] +##ifdef CAMLTK + function () tag_raise_above [widget(text); "tag"; "raise"; TextTag; TextTag] + function () tag_raise_top [widget(text); "tag"; "raise"; TextTag] +##endif + +##ifdef CAMLTK + function (Index list) tag_ranges [widget(text); "tag"; "ranges"; TextTag] +##else + function (Index(text) as "[>`Linechar of int * int]" list) tag_ranges [widget(text); "tag"; "ranges"; tag: TextTag] +##endif + + function () tag_remove [widget(text); "tag"; "remove"; tag: TextTag; start: TextIndex; stop: TextIndex] + function () tag_remove_char [widget(text); "tag"; "remove"; tag: TextTag; index: TextIndex] + + function () window_configure [widget(text); "window"; "configure"; tag: TextTag; option(embeddedw) list] + function () window_create [widget(text); "window"; "create"; index: TextIndex; option(embeddedw) list] + function (widget list) window_names [widget(text); "window"; "names"] + % scrolling + function (float,float) xview_get [widget(text); "xview"] + function (float,float) yview_get [widget(text); "yview"] + function () xview [widget(text); "xview"; scroll: ScrollValue] + function () yview [widget(text); "yview"; scroll: ScrollValue] + function () yview_index [widget(text); "yview"; index: TextIndex] + function () yview_index_pickplace [widget(text); "yview"; "-pickplace"; index: TextIndex] + function () yview_line [widget(text); "yview"; line: int] % obsolete + } + +subtype option(texttag) { + Background + BgStipple ["-bgstipple"; Bitmap] + BorderWidth + FgStipple ["-fgstipple"; Bitmap] + Font + Foreground + Justify + LMargin1 ["-lmargin1"; Units/int] + LMargin2 ["-lmargin2"; Units/int] + Offset ["-offset"; Units/int] + OverStrike ["-overstrike"; bool] + Relief + RMargin ["-rmargin"; Units/int] + Spacing1 + Spacing2 + Spacing3 + Tabs + Underline ["-underline"; bool] + Wrap ["-wrap"; WrapMode] + } + + +%%%%% tk(n) +unsafe function () appname_set ["tk"; "appname"; string] +unsafe function (string) appname_get ["tk"; "appname"] +function (float) scaling_get ["tk"; "scaling"; ?displayof:["-displayof"; widget]] +unsafe function () scaling_set ["tk"; "scaling"; ?displayof:["-displayof"; widget]; float] + +%%%%% tk_chooseColor(n) + +subtype option(chooseColor){ + InitialColor ["-initialcolor"; Color] + Parent ["-parent"; widget] + Title ["-title"; string] + } +function (Color) chooseColor ["tk_chooseColor"; option(chooseColor) list] + +%%%%% tkwait(n) +module Tkwait { + function () variable ["tkwait"; "variable"; TextVariable] + function () visibility ["tkwait"; "visibility"; widget] + function () window ["tkwait"; "window"; widget] + } + + +%%%%% toplevel(n) +% This module will be renamed "toplevelw" to avoid collision with +% Caml Light standard toplevel module. +widget toplevel { + % Standard options + option BorderWidth + option Cursor + option HighlightBackground + option HighlightColor + option HighlightThickness + option Relief + option TakeFocus + + % Widget specific options + option Background +##ifdef CAMLTK + option Class +##else + option Clas +##endif + option Colormap + option Container ["-container"; bool] + option Height + option Menu + option Screen ["-screen"; string] + option Use ["-use"; string] % must be hexadecimal "0x????" + option Visual + option Width + + function () configure [widget(toplevel); "configure"; option(toplevel) list] + function (string) configure_get [widget(toplevel); "configure"] + } + + +%%%%% update(n) +function () update ["update"] +function () update_idletasks ["update"; "idletasks"] + + +%%%%% winfo(n) + +type AtomId { + AtomId [int] + } + +module Winfo { + + unsafe function (AtomId) atom ["winfo"; "atom"; ?displayof:["-displayof"; widget]; string] + unsafe function (string) atomname ["winfo"; "atomname"; ?displayof:["-displayof"; widget]; AtomId] +##ifdef CAMLTK + unsafe function (AtomId) atom_displayof ["winfo"; "atom"; "-displayof"; widget; string] + unsafe function (string) atomname_displayof ["winfo"; "atomname"; "-displayof"; widget; AtomId] +##endif + function (int) cells ["winfo"; "cells"; widget] + function (widget list) children ["winfo"; "children"; widget] + function (string) class_name ["winfo"; "class"; widget] + function (bool) colormapfull ["winfo"; "colormapfull"; widget] + unsafe function (widget) containing ["winfo"; "containing"; ?displayof:["-displayof"; widget]; x: int; y: int] +##ifdef CAMLTK + unsafe function (widget) containing_displayof ["winfo"; "containing"; "-displayof"; widget; int; int] +##endif + % addition for applets + external contained "builtin/winfo_contained" + function (int) depth ["winfo"; "depth"; widget] + function (bool) exists ["winfo"; "exists"; widget] + function (float) fpixels ["winfo"; "fpixels"; widget; length: Units] + function (string) geometry ["winfo"; "geometry"; widget] + function (int) height ["winfo"; "height"; widget] + unsafe function (string) id ["winfo"; "id"; widget] + unsafe function (string list) interps ["winfo"; "interps"; ?displayof:["-displayof"; widget]] +##ifdef CAMLTK + unsafe function (string list) interps_displayof ["winfo"; "interps"; "-displayof"; widget] +##endif + function (bool) ismapped ["winfo"; "ismapped"; widget] + function (string) manager ["winfo"; "manager"; widget] + function (string) name ["winfo"; "name"; widget] + unsafe function (widget) parent ["winfo"; "parent"; widget] % bogus for top + unsafe function (widget) pathname ["winfo"; "pathname"; ?displayof:["-displayof"; widget]; string] +##ifdef CAMLTK + unsafe function (widget) pathname_displayof ["winfo"; "pathname"; "-displayof"; widget; string] +##endif + function (int) pixels ["winfo"; "pixels"; widget; length: Units] + function (int) pointerx ["winfo"; "pointerx"; widget] + function (int) pointery ["winfo"; "pointery"; widget] + function (int, int) pointerxy ["winfo"; "pointerxy"; widget] + function (int) reqheight ["winfo"; "reqheight"; widget] + function (int) reqwidth ["winfo"; "reqwidth"; widget] + function (int,int,int) rgb ["winfo"; "rgb"; widget; color: Color] + function (int) rootx ["winfo"; "rootx"; widget] + function (int) rooty ["winfo"; "rooty"; widget] + unsafe function (string) screen ["winfo"; "screen"; widget] + function (int) screencells ["winfo"; "screencells"; widget] + function (int) screendepth ["winfo"; "screendepth"; widget] + function (int) screenheight ["winfo"; "screenheight"; widget] + function (int) screenmmheight ["winfo"; "screenmmheight"; widget] + function (int) screenmmwidth ["winfo"; "screenmmwidth"; widget] + function (string) screenvisual ["winfo"; "screenvisual"; widget] + function (int) screenwidth ["winfo"; "screenwidth"; widget] + unsafe function (string) server ["winfo"; "server"; widget] + unsafe function (widget(toplevel)) toplevel ["winfo"; "toplevel"; widget] + function (bool) viewable ["winfo"; "viewable"; widget] + function (string) visual ["winfo"; "visual"; widget] + function (int) visualid ["winfo"; "visualid"; widget] + % need special parser + function (string) visualsavailable ["winfo"; "visualsavailable"; widget; ?includeids: [int list]] + function (int) vrootheight ["winfo"; "vrootheight"; widget] + function (int) vrootwidth ["winfo"; "vrootwidth"; widget] + function (int) vrootx ["winfo"; "vrootx"; widget] + function (int) vrooty ["winfo"; "vrooty"; widget] + function (int) width ["winfo"; "width"; widget] + function (int) x ["winfo"; "x"; widget] + function (int) y ["winfo"; "y"; widget] +} + + +%%%%% wm(n) + +type FocusModel { + FocusActive ["active"] + FocusPassive ["passive"] +} + +type WmFrom { + User ["user"] + Program ["program"] +} + +module Wm { +%%% Aspect + function () aspect_set ["wm"; "aspect"; widget(toplevel); minnum:int; mindenom:int; maxnum:int; maxdenom:int] + % aspect: problem with empty return + function (int,int,int,int) aspect_get ["wm"; "aspect"; widget(toplevel)] +%%% WM_CLIENT_MACHINE + function () client_set ["wm"; "client"; widget(toplevel); name: string] + function (string) client_get ["wm"; "client"; widget(toplevel)] +%%% WM_COLORMAP_WINDOWS + function () colormapwindows_set + ["wm"; "colormapwindows"; widget(toplevel); [windows: widget list]] + unsafe function (widget list) colormapwindows_get + ["wm"; "colormapwindows"; widget(toplevel)] +%%% WM_COMMAND + function () command_clear ["wm"; "command"; widget(toplevel); ""] + function () command_set ["wm"; "command"; widget(toplevel); [string list]] + function (string list) command_get ["wm"; "command"; widget(toplevel)] + + function () deiconify ["wm"; "deiconify"; widget(toplevel)] + +%%% Focus model + function () focusmodel_set ["wm"; "focusmodel"; widget(toplevel); FocusModel] + function (FocusModel) focusmodel_get ["wm"; "focusmodel"; widget(toplevel)] + + function (string) frame ["wm"; "frame"; widget(toplevel)] + +%%% Geometry + function () geometry_set ["wm"; "geometry"; widget(toplevel); string] + function (string) geometry_get ["wm"; "geometry"; widget(toplevel)] + +%%% Grid + function () grid_clear ["wm"; "grid"; widget(toplevel); ""; ""; ""; ""] + function () grid_set ["wm"; "grid"; widget(toplevel); basewidth: int; baseheight: int; widthinc: int; heightinc: int] + function (int,int,int,int) grid_get ["wm"; "grid"; widget(toplevel)] + +%%% Groups + function () group_clear ["wm"; "group"; widget(toplevel); ""] + function () group_set ["wm"; "group"; widget(toplevel); leader: widget] + unsafe function (widget) group_get ["wm"; "group"; widget(toplevel)] +%%% Icon bitmap + function () iconbitmap_clear ["wm"; "iconbitmap"; widget(toplevel); ""] + function () iconbitmap_set ["wm"; "iconbitmap"; widget(toplevel); Bitmap] + function (Bitmap) iconbitmap_get ["wm"; "iconbitmap"; widget(toplevel)] + + function () iconify ["wm"; "iconify"; widget(toplevel)] + +%%% Icon mask + function () iconmask_clear ["wm"; "iconmask"; widget(toplevel); ""] + function () iconmask_set ["wm"; "iconmask"; widget(toplevel); Bitmap] + function (Bitmap) iconmask_get ["wm"; "iconmask"; widget(toplevel)] + +%%% Icon name + function () iconname_set ["wm"; "iconname"; widget(toplevel); string] + function (string) iconname_get ["wm"; "iconname"; widget(toplevel)] +%%% Icon position + function () iconposition_clear ["wm"; "iconposition"; widget(toplevel); ""; ""] + function () iconposition_set ["wm"; "iconposition"; widget(toplevel); x: int; y: int] + function (int,int) iconposition_get ["wm"; "iconposition"; widget(toplevel)] +%%% Icon window + function () iconwindow_clear ["wm"; "iconwindow"; widget(toplevel); ""] + function () iconwindow_set ["wm"; "iconwindow"; widget(toplevel); icon: widget(toplevel)] + unsafe function (widget(toplevel)) iconwindow_get ["wm"; "iconwindow"; widget(toplevel)] + +%%% Sizes + function () maxsize_set ["wm"; "maxsize"; widget(toplevel); width: int; height: int] + function (int,int) maxsize_get ["wm"; "maxsize"; widget(toplevel)] + function () minsize_set ["wm"; "minsize"; widget(toplevel); width: int; height: int] + function (int,int) minsize_get ["wm"; "minsize"; widget(toplevel)] +%%% Override + unsafe function () overrideredirect_set ["wm"; "overrideredirect"; widget(toplevel); bool] + function (bool) overrideredirect_get ["wm"; "overrideredirect"; widget(toplevel)] +%%% Position + function () positionfrom_clear ["wm"; "positionfrom"; widget(toplevel); ""] + function () positionfrom_set ["wm"; "positionfrom"; widget(toplevel); WmFrom] + function (WmFrom) positionfrom_get ["wm"; "positionfrom"; widget(toplevel)] +%%% Protocols + function () protocol_set ["wm"; "protocol"; widget(toplevel); name: string; command: function()] + function () protocol_clear ["wm"; "protocol"; widget(toplevel); name: string; ""] + function (string list) protocols ["wm"; "protocol"; widget(toplevel)] +%%% Resize + function () resizable_set ["wm"; "resizable"; widget(toplevel); width: bool; height: bool] + function (bool, bool) resizable_get ["wm"; "resizable"; widget(toplevel)] +%%% Sizefrom + function () sizefrom_clear ["wm"; "sizefrom"; widget(toplevel); ""] + function () sizefrom_set ["wm"; "sizefrom"; widget(toplevel); WmFrom] + function (WmFrom) sizefrom_get ["wm"; "sizefrom"; widget(toplevel)] + + function (string) state ["wm"; "state"; widget(toplevel)] + +%%% Title + function (string) title_get ["wm"; "title"; widget(toplevel)] + function () title_set ["wm"; "title"; widget(toplevel); string] +%%% Transient + function () transient_clear ["wm"; "transient"; widget(toplevel); ""] + function () transient_set ["wm"; "transient"; widget(toplevel); master: widget] + unsafe function (widget) transient_get ["wm"; "transient"; widget(toplevel)] + + function () withdraw ["wm"; "withdraw"; widget(toplevel)] + +} + +%%%%% tk_getOpenFile(n) (since version 8.0) +type FilePattern external + +subtype option(getFile) { + DefaultExtension ["-defaultextension"; string] + FileTypes ["-filetypes"; [FilePattern list]] + InitialDir ["-initialdir"; string] + InitialFile ["-initialfile"; string] + Parent ["-parent"; widget] + Title ["-title"; string] +} + +function (string) getOpenFile ["tk_getOpenFile"; option(getFile) list] +function (string) getSaveFile ["tk_getSaveFile"; option(getFile) list] + +%%%%% tk_messageBox +type MessageIcon { + Error ["error"] + Info ["info"] + Question ["question"] + Warning ["warning"] +} +type MessageType { + AbortRetryIgnore ["abortretryignore"] + Ok ["ok"] + OkCancel ["okcancel"] + RetryCancel ["retrycancel"] + YesNo ["yesno"] + YesNoCancel ["yesnocancel"] +} +subtype option(messageBox) { + MessageDefault ["-default"; string] + MessageIcon ["-icon"; MessageIcon] + Message ["-message"; string] + Parent + Title + MessageType ["-type"; MessageType] +} + +function (string) messageBox ["tk_messageBox"; option(messageBox) list] + +module Tkvars { + function (string) library ["$tk_library"] + function (string) patchLevel ["$tk_patchLevel"] + function (bool) strictMotif ["$tk_strictMotif"] + function () set_strictMotif ["set"; "tk_strictMotif"; bool] + function (string) version ["$tk_version"] +} + +% Direct API calls, non Tcl-based modules + +module Pixmap { + external create "builtin/rawimg" + } + +%%% encodings : require if you want write your application international + +module Encoding { + function (string) convertfrom ["encoding"; "convertfrom"; + ?encoding: [string]; string] + function (string) convertto ["encoding"; "convertto"; + ?encoding: [string]; string] + function (string list) names ["encoding"; "names"] + function () system_set ["encoding"; "system"; string] + function (string) system_get ["encoding"; "system"] +} diff --git a/otherlibs/labltk/browser/.cvsignore b/otherlibs/labltk/browser/.cvsignore new file mode 100644 index 0000000..8ced21d --- /dev/null +++ b/otherlibs/labltk/browser/.cvsignore @@ -0,0 +1,2 @@ +ocamlbrowser +dummy.mli diff --git a/otherlibs/labltk/browser/.depend b/otherlibs/labltk/browser/.depend new file mode 100644 index 0000000..4912011 --- /dev/null +++ b/otherlibs/labltk/browser/.depend @@ -0,0 +1,66 @@ +editor.cmo: viewer.cmi typecheck.cmi shell.cmi setpath.cmi searchpos.cmi \ + searchid.cmi mytypes.cmi lexical.cmi jg_toplevel.cmo jg_tk.cmo \ + jg_text.cmi jg_message.cmi jg_menu.cmo jg_button.cmo jg_bind.cmi \ + fileselect.cmi editor.cmi +editor.cmx: viewer.cmx typecheck.cmx shell.cmx setpath.cmx searchpos.cmx \ + searchid.cmx mytypes.cmi lexical.cmx jg_toplevel.cmx jg_tk.cmx \ + jg_text.cmx jg_message.cmx jg_menu.cmx jg_button.cmx jg_bind.cmx \ + fileselect.cmx editor.cmi +fileselect.cmo: useunix.cmi setpath.cmi list2.cmo jg_toplevel.cmo jg_memo.cmi \ + jg_entry.cmo jg_box.cmo fileselect.cmi +fileselect.cmx: useunix.cmx setpath.cmx list2.cmx jg_toplevel.cmx jg_memo.cmx \ + jg_entry.cmx jg_box.cmx fileselect.cmi +jg_bind.cmo: jg_bind.cmi +jg_bind.cmx: jg_bind.cmi +jg_box.cmo: jg_completion.cmi jg_bind.cmi +jg_box.cmx: jg_completion.cmx jg_bind.cmx +jg_completion.cmo: jg_completion.cmi +jg_completion.cmx: jg_completion.cmi +jg_config.cmo: jg_tk.cmo jg_config.cmi +jg_config.cmx: jg_tk.cmx jg_config.cmi +jg_entry.cmo: jg_bind.cmi +jg_entry.cmx: jg_bind.cmx +jg_memo.cmo: jg_memo.cmi +jg_memo.cmx: jg_memo.cmi +jg_message.cmo: jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_bind.cmi \ + jg_message.cmi +jg_message.cmx: jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_bind.cmx \ + jg_message.cmi +jg_multibox.cmo: jg_completion.cmi jg_bind.cmi jg_multibox.cmi +jg_multibox.cmx: jg_completion.cmx jg_bind.cmx jg_multibox.cmi +jg_text.cmo: jg_toplevel.cmo jg_tk.cmo jg_button.cmo jg_bind.cmi jg_text.cmi +jg_text.cmx: jg_toplevel.cmx jg_tk.cmx jg_button.cmx jg_bind.cmx jg_text.cmi +lexical.cmo: jg_tk.cmo lexical.cmi +lexical.cmx: jg_tk.cmx lexical.cmi +main.cmo: viewer.cmi shell.cmi searchpos.cmi searchid.cmi jg_config.cmi \ + editor.cmi +main.cmx: viewer.cmx shell.cmx searchpos.cmx searchid.cmx jg_config.cmx \ + editor.cmx +searchid.cmo: list2.cmo searchid.cmi +searchid.cmx: list2.cmx searchid.cmi +searchpos.cmo: searchid.cmi lexical.cmi jg_tk.cmo jg_text.cmi jg_message.cmi \ + jg_memo.cmi jg_bind.cmi searchpos.cmi +searchpos.cmx: searchid.cmx lexical.cmx jg_tk.cmx jg_text.cmx jg_message.cmx \ + jg_memo.cmx jg_bind.cmx searchpos.cmi +setpath.cmo: useunix.cmi list2.cmo jg_toplevel.cmo jg_button.cmo jg_box.cmo \ + jg_bind.cmi setpath.cmi +setpath.cmx: useunix.cmx list2.cmx jg_toplevel.cmx jg_button.cmx jg_box.cmx \ + jg_bind.cmx setpath.cmi +shell.cmo: list2.cmo lexical.cmi jg_toplevel.cmo jg_tk.cmo jg_text.cmi \ + jg_message.cmi jg_menu.cmo jg_memo.cmi fileselect.cmi dummy.cmi shell.cmi +shell.cmx: list2.cmx lexical.cmx jg_toplevel.cmx jg_tk.cmx jg_text.cmx \ + jg_message.cmx jg_menu.cmx jg_memo.cmx fileselect.cmx dummy.cmi shell.cmi +typecheck.cmo: mytypes.cmi jg_tk.cmo jg_text.cmi jg_message.cmi typecheck.cmi +typecheck.cmx: mytypes.cmi jg_tk.cmx jg_text.cmx jg_message.cmx typecheck.cmi +useunix.cmo: useunix.cmi +useunix.cmx: useunix.cmi +viewer.cmo: useunix.cmi shell.cmi setpath.cmi searchpos.cmi searchid.cmi \ + mytypes.cmi jg_toplevel.cmo jg_tk.cmo jg_text.cmi jg_multibox.cmi \ + jg_message.cmi jg_menu.cmo jg_entry.cmo jg_completion.cmi jg_button.cmo \ + jg_box.cmo jg_bind.cmi help.cmo viewer.cmi +viewer.cmx: useunix.cmx shell.cmx setpath.cmx searchpos.cmx searchid.cmx \ + mytypes.cmi jg_toplevel.cmx jg_tk.cmx jg_text.cmx jg_multibox.cmx \ + jg_message.cmx jg_menu.cmx jg_entry.cmx jg_completion.cmx jg_button.cmx \ + jg_box.cmx jg_bind.cmx help.cmx viewer.cmi +mytypes.cmi: shell.cmi +typecheck.cmi: mytypes.cmi diff --git a/otherlibs/labltk/browser/Makefile b/otherlibs/labltk/browser/Makefile new file mode 100644 index 0000000..81a153b --- /dev/null +++ b/otherlibs/labltk/browser/Makefile @@ -0,0 +1,6 @@ +OTHERSLIB=-I $(OTHERS)/unix -I $(OTHERS)/str + +include Makefile.shared + +dummy.mli: + cp dummyUnix.mli dummy.mli diff --git a/otherlibs/labltk/browser/Makefile.nt b/otherlibs/labltk/browser/Makefile.nt new file mode 100644 index 0000000..c2a2136 --- /dev/null +++ b/otherlibs/labltk/browser/Makefile.nt @@ -0,0 +1,21 @@ +# $Id: Makefile.nt,v 1.17 2008-12-03 18:09:09 doligez Exp $ + +OTHERSLIB=-I $(OTHERS)/win32unix -I $(OTHERS)/str -I $(OTHERS)/systhreads + +CCFLAGS=-I../../../byterun $(TK_DEFS) + +include ../support/Makefile.common + +ifeq ($(CCOMPTYPE),cc) +WINDOWS_APP=-ccopt "-link -Wl,--subsystem,windows" +else +WINDOWS_APP=-ccopt "-link /subsystem:windows" +endif + +XTRAOBJ=winmain.$(O) +XTRALIBS=threads.cma -custom $(WINDOWS_APP) + +include Makefile.shared + +dummy.mli: + cp dummyWin.mli dummy.mli diff --git a/otherlibs/labltk/browser/Makefile.shared b/otherlibs/labltk/browser/Makefile.shared new file mode 100644 index 0000000..c5080b7 --- /dev/null +++ b/otherlibs/labltk/browser/Makefile.shared @@ -0,0 +1,63 @@ +include ../support/Makefile.common + +LABLTKLIB=-I ../labltk -I ../lib -I ../support +OCAMLTOPLIB=-I $(TOPDIR)/parsing -I $(TOPDIR)/utils -I $(TOPDIR)/typing +INCLUDES=$(OTHERSLIB) $(LABLTKLIB) $(OCAMLTOPLIB) + +OBJ = list2.cmo useunix.cmo setpath.cmo lexical.cmo \ + fileselect.cmo searchid.cmo searchpos.cmo shell.cmo \ + help.cmo \ + viewer.cmo typecheck.cmo editor.cmo main.cmo + +JG = jg_tk.cmo jg_config.cmo jg_bind.cmo jg_completion.cmo \ + jg_box.cmo \ + jg_button.cmo jg_toplevel.cmo jg_text.cmo jg_message.cmo \ + jg_menu.cmo jg_entry.cmo jg_multibox.cmo jg_memo.cmo + +# Default rules + +.SUFFIXES: .ml .mli .cmo .cmi .cmx .c .$(O) + +.ml.cmo: + $(CAMLCOMP) $(INCLUDES) $< + +.mli.cmi: + $(CAMLCOMP) $(INCLUDES) $< + +.c.$(O): + $(BYTECC) $(BYTECCCOMPOPTS) $(CCFLAGS) -c $< + +all: ocamlbrowser$(EXE) + +ocamlbrowser$(EXE): $(TOPDIR)/toplevel/toplevellib.cma jglib.cma $(OBJ) \ + ../support/lib$(LIBNAME).$(A) + $(CAMLC) -o ocamlbrowser$(EXE) $(INCLUDES) \ + $(TOPDIR)/toplevel/toplevellib.cma \ + unix.cma str.cma $(OCAMLBR) $(LIBNAME).cma jglib.cma $(OBJ) + +ocamlbrowser.cma: jglib.cma $(OBJ) + $(CAMLC) -a -o $@ -linkall jglib.cma $(OBJ) + +jglib.cma: $(JG) + $(CAMLC) -a -o $@ $(JG) + +help.ml: + echo 'let text = "\\' > $@ + sed -e 's/^ /\\032/' -e 's/$$/\\n\\/' help.txt >> $@ + echo '";;' >> $@ + +install: + if test -f ocamlbrowser$(EXE); then : ; \ + cp ocamlbrowser$(EXE) $(BINDIR); fi + +clean: + rm -f *.cm? ocamlbrowser$(EXE) dummy.mli *~ *.orig *.$(O) + +depend: + $(CAMLDEP) *.ml *.mli > .depend + +shell.cmo: dummy.cmi +setpath.cmo fileselect.cmo lexical.cmi searchid.cmi typecheck.cmi: $(TOPDIR)/toplevel/toplevellib.cma +mytypes.cmi searchpos.cmi searchpos.cmo typecheck.cmo: $(TOPDIR)/typing/stypes.cmi + +include .depend diff --git a/otherlibs/labltk/browser/README b/otherlibs/labltk/browser/README new file mode 100644 index 0000000..e895354 --- /dev/null +++ b/otherlibs/labltk/browser/README @@ -0,0 +1,170 @@ + + Installing and Using OCamlBrowser + + +INSTALLATION + If you installed it with LablTk, nothing to do. + Otherwise, the source is in labltk/browser. + After installing LablTk, simply do "make" and "make install". + The name of the command is `ocamlbrowser'. + +USE + OCamlBrowser is composed of three tools, the Viewer, to walk around + compiled modules, the Editor, which allows one to + edit/typecheck/analyse .mli and .ml files, and the Shell, to run an + OCaml subshell. You may only have one instance of Editor and + Viewer, but you may use several subshells. + + As with the compiler, you may specify a different path for the + standard library by setting CAMLLIB. You may also extend the + initial load path (only standard library by default) by using the + -I command line option, or set various other options (see -help). + + If you prefered the old GUI, it is still available with the option + -oldui, otherwise you get a new Smalltalkish user interface. + +1) Viewer + + Menus + + File - Open and File - Editor give access to the editor. + + File - Shell opens an OCaml shell. + + View - Show all defs displays all the interface of the currently + selected module + View - Search entry shows/hides the search entry at the top of the + window + + Modules - Path editor changes the load path. + Pressing [Add to path] or Insert key adds selected directories + to the load path. + Pressing [Remove from path] or Delete key removes selected + paths from the load path. + Modules - Reset cache rescans the load path and resets the module + cache. Do it if you recompile some interface, or change the load + path in a conflictual way. + + Modules - Search symbol allows to search a symbol either by its + name, like the bottom line of the viewer, or, more + interestingly, by its type. Exact type searches for a type + with exactly the same information as the pattern (variables + match only variables), included type allows to give only + partial information: the actual type may take more arguments + and return more results, and variables in the pattern match + anything. In both cases, argument and tuple order is + irrelevant (*), and unlabeled arguments in the pattern match + any label. + + (*) To avoid combinatorial explosion of the search space, optional + arguments in the actual type are ignored if (1) there are to many + of them, and (2) they do not appear explicitly in the pattern. + + Search entry + + The entry line at the top allows one to search for an identifier + in all modules, either by its name (? and * patterns allowed) or by + its type. When search by type is used, it is done in inclusion mode + (cf. Modules - search symbol) + + The Close all button at the bottom is there to dismiss the windows + created by the Detach button. By double-clicking on it you will + quit the browser. + + Module browsing + + You select a module in the leftmost box by either cliking on it or + pressing return when it is selected. Fast access is available in + all boxes pressing the first few letter of the desired + name. Double-clicking / double-return displays the whole signature + for the module. + + Defined identifiers inside the module are displayed in a box to the + right of the previous one. If you click on one, this will either + display its contents in another box (if this is a sub-module) or + display the signature for this identifier below. + + Signatures are clickable. Double clicking with the left mouse + button on an identifier in a signature brings you to its signature. + A single click on the right button pops up a menu displaying the + type declaration for the selected identifier. Its title, when + selectable, also brings you to its signature. + + At the bottom, a series of buttons, depending on the context. + * Detach copies the currently displayed signature in a new window, + to keep it. You can discard these windows with Close all. + * Impl and Intf bring you to the implementation or interface of + the currently displayed signature, if it is available. + + C-s opens a text search dialog for the displayed signature. + +2) Editor + You can edit files with it, but there is no auto-save nor undo at + the moment. Otherwise you can use it as a browser, making + occasional corrections. + + The Edit menu contains commands for jump (C-g), search (C-s), and + sending the current selection to a sub-shell (M-x). For this last + option, you may choose the shell via a dialog. + + Essential function are in the Compiler menu. + + Preferences opens a dialog to set internals of the editor and + type checker. + + Lex (M-l) adds colors according to lexical categories. + + Typecheck (M-t) verifies typing, and memorizes it to let one see an + expression's type by double-clicking on it. This is also valid for + interfaces. If an error occurs, the part of the interface preceding + the error is computed. + + After typechecking, pressing the right button pops up a menu giving + the type of the pointed expression, and eventually allowing to + follow some links. + + Clear errors dismisses type checker error messages and warnings. + + Signature shows the signature of the current file. + +3) Shell + When you create a shell, a dialog is presented to you, letting you + choose which command you want to run, and the title of the shell + (to choose it in the Editor). + + You may change the default command by setting the OLABL environment + variable. + + The executed subshell is given the current load path. + File: use a source file or load a bytecode file. + You may also import the browser's path into the subprocess. + History: M-p and M-n browse up and down. + Signal: C-c interrupts and you can kill the subprocess. + +BUGS + +* This not really a bug, but OCamlBrowser is a huge memory consumer. + Go and buy some. + +* When you quit the editor and some file was modified, a dialogue is + displayed asking wether you want to really quit or not. But 1) if + you quit directly from the viewer, there is no dialogue at all, and + 2) if you close from the window manager, the dialogue is displayed, + but you cannot cancel the destruction... Beware. + +* When you run it through xon, the shell hangs at the first error. But + its ok if you start ocamlbrowser from a remote shell... + +TODO + +* Complete cross-references. + +* Power up editor. + +* Add support for the debugger. + +* Make this a real programming environment, both for beginners an + experimented users. + + +Bug reports and comments to <garrigue@kurims.kyoto-u.ac.jp> diff --git a/otherlibs/labltk/browser/dummyUnix.mli b/otherlibs/labltk/browser/dummyUnix.mli new file mode 100644 index 0000000..2f18717 --- /dev/null +++ b/otherlibs/labltk/browser/dummyUnix.mli @@ -0,0 +1,27 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: dummyUnix.mli,v 1.4 2003-12-29 22:15:01 doligez Exp $ *) + +module Mutex : sig + type t + external create : unit -> t = "%ignore" + external lock : t -> unit = "%ignore" + external unlock : t -> unit = "%ignore" +end + +module Thread : sig + type t + external create : ('a -> 'b) -> 'a -> t = "caml_ml_input" +end diff --git a/otherlibs/labltk/browser/dummyWin.mli b/otherlibs/labltk/browser/dummyWin.mli new file mode 100644 index 0000000..a7a572b --- /dev/null +++ b/otherlibs/labltk/browser/dummyWin.mli @@ -0,0 +1,15 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: dummyWin.mli,v 1.2 2001-12-07 13:39:55 xleroy Exp $ *) diff --git a/otherlibs/labltk/browser/editor.ml b/otherlibs/labltk/browser/editor.ml new file mode 100644 index 0000000..e66f981 --- /dev/null +++ b/otherlibs/labltk/browser/editor.ml @@ -0,0 +1,667 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: editor.ml,v 1.41 2006-01-04 16:55:50 doligez Exp $ *) + +open StdLabels +open Tk +open Parsetree +open Location +open Jg_tk +open Mytypes + +let lex_on_load = ref true +and type_on_load = ref false + +let compiler_preferences master = + let tl = Jg_toplevel.titled "Compiler" in + Wm.transient_set tl ~master; + let mk_chkbutton ~text ~ref ~invert = + let variable = Textvariable.create ~on:tl () in + if (if invert then not !ref else !ref) then + Textvariable.set variable "1"; + Checkbutton.create tl ~text ~variable, + (fun () -> + ref := Textvariable.get variable = (if invert then "0" else "1")) + in + let use_pp = ref (!Clflags.preprocessor <> None) in + let chkbuttons, setflags = List.split + (List.map + ~f:(fun (text, ref, invert) -> mk_chkbutton ~text ~ref ~invert) + [ "No pervasives", Clflags.nopervasives, false; + "No warnings", Typecheck.nowarnings, false; + "No labels", Clflags.classic, false; + "Recursive types", Clflags.recursive_types, false; + "Lex on load", lex_on_load, false; + "Type on load", type_on_load, false; + "Preprocessor", use_pp, false ]) + in + let pp_command = Entry.create tl (* ~state:(if !use_pp then `Normal else`Disabled) *) in + begin match !Clflags.preprocessor with None -> () + | Some pp -> Entry.insert pp_command ~index:(`Num 0) ~text:pp + end; + let buttons = Frame.create tl in + let ok = Button.create buttons ~text:"Ok" ~padx:20 ~command: + begin fun () -> + List.iter ~f:(fun f -> f ()) setflags; + Clflags.preprocessor := + if !use_pp then Some (Entry.get pp_command) else None; + destroy tl + end + and cancel = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" + in + pack chkbuttons ~side:`Top ~anchor:`W; + pack [pp_command] ~side:`Top ~anchor:`E; + pack [ok;cancel] ~side:`Left ~fill:`X ~expand:true; + pack [buttons] ~side:`Bottom ~fill:`X + +let rec exclude txt = function + [] -> [] + | x :: l -> if txt.number = x.number then l else x :: exclude txt l + +let goto_line tw = + let tl = Jg_toplevel.titled "Go to" in + Wm.transient_set tl ~master:(Winfo.toplevel tw); + Jg_bind.escape_destroy tl; + let ef = Frame.create tl in + let fl = Frame.create ef + and fi = Frame.create ef in + let ll = Label.create fl ~text:"Line ~number:" + and il = Entry.create fi ~width:10 + and lc = Label.create fl ~text:"Col ~number:" + and ic = Entry.create fi ~width:10 + and get_int ew = + try int_of_string (Entry.get ew) + with Failure "int_of_string" -> 0 + in + let buttons = Frame.create tl in + let ok = Button.create buttons ~text:"Ok" ~command: + begin fun () -> + let l = get_int il + and c = get_int ic in + Text.mark_set tw ~mark:"insert" ~index:(`Linechar (l,0), [`Char c]); + Text.see tw ~index:(`Mark "insert", []); + destroy tl + end + and cancel = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" in + + Focus.set il; + List.iter [il; ic] ~f: + begin fun w -> + Jg_bind.enter_focus w; + Jg_bind.return_invoke w ~button:ok + end; + pack [ll; lc] ~side:`Top ~anchor:`W; + pack [il; ic] ~side:`Top ~fill:`X ~expand:true; + pack [fl; fi] ~side:`Left ~fill:`X ~expand:true; + pack [ok; cancel] ~side:`Left ~fill:`X ~expand:true; + pack [ef; buttons] ~side:`Top ~fill:`X ~expand:true + +let select_shell txt = + let shells = Shell.get_all () in + let shells = List.sort shells ~cmp:compare in + let tl = Jg_toplevel.titled "Select Shell" in + Jg_bind.escape_destroy tl; + Wm.transient_set tl ~master:(Winfo.toplevel txt.tw); + let label = Label.create tl ~text:"Send to:" + and box = Listbox.create tl + and frame = Frame.create tl in + Jg_bind.enter_focus box; + let cancel = Jg_button.create_destroyer tl ~parent:frame ~text:"Cancel" + and ok = Button.create frame ~text:"Ok" ~command: + begin fun () -> + try + let name = Listbox.get box ~index:`Active in + txt.shell <- Some (name, List.assoc name shells); + destroy tl + with Not_found -> txt.shell <- None; destroy tl + end + in + Listbox.insert box ~index:`End ~texts:(List.map ~f:fst shells); + Listbox.configure box ~height:(List.length shells); + bind box ~events:[`KeyPressDetail"Return"] ~breakable:true + ~action:(fun _ -> Button.invoke ok; break ()); + bind box ~events:[`Modified([`Double],`ButtonPressDetail 1)] ~breakable:true + ~fields:[`MouseX;`MouseY] + ~action:(fun ev -> + Listbox.activate box ~index:(`Atxy (ev.ev_MouseX, ev.ev_MouseY)); + Button.invoke ok; break ()); + pack [label] ~side:`Top ~anchor:`W; + pack [box] ~side:`Top ~fill:`Both; + pack [frame] ~side:`Bottom ~fill:`X ~expand:true; + pack [ok;cancel] ~side:`Left ~fill:`X ~expand:true + +open Parser + +let send_phrase txt = + if txt.shell = None then begin + match Shell.get_all () with [] -> () + | [sh] -> txt.shell <- Some sh + | l -> select_shell txt + end; + match txt.shell with None -> () + | Some (_,sh) -> + try + let i1,i2 = Text.tag_nextrange txt.tw ~tag:"sel" ~start:tstart in + let phrase = Text.get txt.tw ~start:(i1,[]) ~stop:(i2,[]) in + sh#send phrase; + if Str.string_match (Str.regexp ";;") phrase 0 + then sh#send "\n" else sh#send ";;\n" + with Not_found | Protocol.TkError _ -> + let text = Text.get txt.tw ~start:tstart ~stop:tend in + let buffer = Lexing.from_string text in + let start = ref 0 + and block_start = ref [] + and pend = ref (-1) + and after = ref false in + while !pend = -1 do + let token = Lexer.token buffer in + let pos = + if token = SEMISEMI then Lexing.lexeme_end buffer + else Lexing.lexeme_start buffer + in + let bol = (pos = 0) || text.[pos-1] = '\n' in + if not !after && + Text.compare txt.tw ~index:(tpos pos) ~op:(if bol then `Gt else `Ge) + ~index:(`Mark"insert",[]) + then begin + after := true; + let anon, real = + List.partition !block_start ~f:(fun x -> x = -1) in + block_start := anon; + if real <> [] then start := List.hd real; + end; + match token with + CLASS | EXTERNAL | EXCEPTION | FUNCTOR + | LET | MODULE | OPEN | TYPE | VAL | SHARP when bol -> + if !block_start = [] then + if !after then pend := pos else start := pos + else block_start := pos :: List.tl !block_start + | SEMISEMI -> + if !block_start = [] then + if !after then pend := Lexing.lexeme_start buffer + else start := pos + else block_start := pos :: List.tl !block_start + | BEGIN | OBJECT -> + block_start := -1 :: !block_start + | STRUCT | SIG -> + block_start := Lexing.lexeme_end buffer :: !block_start + | END -> + if !block_start = [] then + if !after then pend := pos else () + else block_start := List.tl !block_start + | EOF -> + pend := pos + | _ -> + () + done; + let phrase = String.sub text ~pos:!start ~len:(!pend - !start) in + sh#send phrase; + sh#send ";;\n" + +let search_pos_window txt ~x ~y = + if txt.type_info = [] && txt.psignature = [] then () else + let `Linechar (l, c) = Text.index txt.tw ~index:(`Atxy(x,y), []) in + let text = Jg_text.get_all txt.tw in + let pos = Searchpos.lines_to_chars l ~text + c in + try if txt.type_info <> [] then begin match + Searchpos.search_pos_info txt.type_info ~pos + with [] -> () + | (kind, env, loc) :: _ -> Searchpos.view_type kind ~env + end else begin match + Searchpos.search_pos_signature txt.psignature ~pos ~env:!Searchid.start_env + with [] -> () + | ((kind, lid), env, loc) :: _ -> + Searchpos.view_decl lid ~kind ~env + end + with Not_found -> () + +let search_pos_menu txt ~x ~y = + if txt.type_info = [] && txt.psignature = [] then () else + let `Linechar (l, c) = Text.index txt.tw ~index:(`Atxy(x,y), []) in + let text = Jg_text.get_all txt.tw in + let pos = Searchpos.lines_to_chars l ~text + c in + try if txt.type_info <> [] then begin match + Searchpos.search_pos_info txt.type_info ~pos + with [] -> () + | (kind, env, loc) :: _ -> + let menu = Searchpos.view_type_menu kind ~env ~parent:txt.tw in + let x = x + Winfo.rootx txt.tw and y = y + Winfo.rooty txt.tw - 10 in + Menu.popup menu ~x ~y + end else begin match + Searchpos.search_pos_signature txt.psignature ~pos ~env:!Searchid.start_env + with [] -> () + | ((kind, lid), env, loc) :: _ -> + let menu = Searchpos.view_decl_menu lid ~kind ~env ~parent:txt.tw in + let x = x + Winfo.rootx txt.tw and y = y + Winfo.rooty txt.tw - 10 in + Menu.popup menu ~x ~y + end + with Not_found -> () + +let string_width s = + let width = ref 0 in + for i = 0 to String.length s - 1 do + if s.[i] = '\t' then width := (!width / 8 + 1) * 8 + else incr width + done; + !width + +let indent_line = + let ins = `Mark"insert" and reg = Str.regexp "[ \t]*" in + fun tw -> + let `Linechar(l,c) = Text.index tw ~index:(ins,[]) + and line = Text.get tw ~start:(ins,[`Linestart]) ~stop:(ins,[`Lineend]) in + ignore (Str.string_match reg line 0); + let len = Str.match_end () in + if len < c then Text.insert tw ~index:(ins,[]) ~text:"\t" else + let width = string_width (Str.matched_string line) in + Text.mark_set tw ~mark:"insert" ~index:(ins,[`Linestart;`Char len]); + let indent = + if l <= 1 then 2 else + let previous = + Text.get tw ~start:(ins,[`Line(-1);`Linestart]) + ~stop:(ins,[`Line(-1);`Lineend]) in + ignore (Str.string_match reg previous 0); + let previous = Str.matched_string previous in + let width_previous = string_width previous in + if width_previous <= width then 2 else width_previous - width + in + Text.insert tw ~index:(ins,[]) ~text:(String.make indent ' ') + +(* The editor class *) + +class editor ~top ~menus = object (self) + val file_menu = new Jg_menu.c "File" ~parent:menus + val edit_menu = new Jg_menu.c "Edit" ~parent:menus + val compiler_menu = new Jg_menu.c "Compiler" ~parent:menus + val module_menu = new Jg_menu.c "Modules" ~parent:menus + val window_menu = new Jg_menu.c "Windows" ~parent:menus + initializer + Menu.add_checkbutton menus ~state:`Disabled + ~onvalue:"modified" ~offvalue:"unchanged" + val mutable current_dir = Unix.getcwd () + val mutable error_messages = [] + val mutable windows = [] + val mutable current_tw = Text.create top + val vwindow = Textvariable.create ~on:top () + val mutable window_counter = 0 + + method has_window name = + List.exists windows ~f:(fun x -> x.name = name) + + method reset_window_menu = + Menu.delete window_menu#menu ~first:(`Num 0) ~last:`End; + List.iter + (List.sort windows ~cmp: + (fun w1 w2 -> + compare (Filename.basename w1.name) (Filename.basename w2.name))) + ~f: + begin fun txt -> + Menu.add_radiobutton window_menu#menu + ~label:(Filename.basename txt.name) + ~variable:vwindow ~value:txt.number + ~command:(fun () -> self#set_edit txt) + end + + method set_file_name txt = + Menu.configure_checkbutton menus `Last + ~label:(Filename.basename txt.name) + ~variable:txt.modified + + method set_edit txt = + if windows <> [] then + Pack.forget [(List.hd windows).frame]; + windows <- txt :: exclude txt windows; + self#reset_window_menu; + current_tw <- txt.tw; + self#set_file_name txt; + Textvariable.set vwindow txt.number; + Text.yview txt.tw ~scroll:(`Page 0); + pack [txt.frame] ~fill:`Both ~expand:true ~side:`Bottom + + method new_window name = + let tl, tw, sb = Jg_text.create_with_scrollbar top in + Text.configure tw ~background:`White; + Jg_bind.enter_focus tw; + window_counter <- window_counter + 1; + let txt = + { name = name; tw = tw; frame = tl; + number = string_of_int window_counter; + modified = Textvariable.create ~on:tw (); + shell = None; + structure = []; type_info = []; signature = []; psignature = [] } + in + let control c = Char.chr (Char.code c - 96) in + bind tw ~events:[`Modified([`Alt], `KeyPress)] ~action:ignore; + bind tw ~events:[`KeyPress] ~fields:[`Char] + ~action:(fun ev -> + if ev.ev_Char <> "" && + (ev.ev_Char.[0] >= ' ' || + List.mem ev.ev_Char.[0] + (List.map ~f:control ['d'; 'h'; 'i'; 'k'; 'o'; 't'; 'w'; 'y'])) + then Textvariable.set txt.modified "modified"); + bind tw ~events:[`KeyPressDetail"Tab"] ~breakable:true + ~action:(fun _ -> + indent_line tw; + Textvariable.set txt.modified "modified"; + break ()); + bind tw ~events:[`Modified([`Control],`KeyPressDetail"k")] + ~action:(fun _ -> + let text = + Text.get tw ~start:(`Mark"insert",[]) ~stop:(`Mark"insert",[`Lineend]) + in ignore (Str.string_match (Str.regexp "[ \t]*") text 0); + if Str.match_end () <> String.length text then begin + Clipboard.clear (); + Clipboard.append ~data:text () + end); + bind tw ~events:[`KeyRelease] ~fields:[`Char] + ~action:(fun ev -> + if ev.ev_Char <> "" then + Lexical.tag tw ~start:(`Mark"insert", [`Linestart]) + ~stop:(`Mark"insert", [`Lineend])); + bind tw ~events:[`Motion] ~action:(fun _ -> Focus.set tw); + bind tw ~events:[`ButtonPressDetail 2] + ~action:(fun _ -> + Textvariable.set txt.modified "modified"; + Lexical.tag txt.tw ~start:(`Mark"insert", [`Linestart]) + ~stop:(`Mark"insert", [`Lineend])); + bind tw ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~fields:[`MouseX;`MouseY] + ~action:(fun ev -> search_pos_window txt ~x:ev.ev_MouseX ~y:ev.ev_MouseY); + bind tw ~events:[`ButtonPressDetail 3] ~fields:[`MouseX;`MouseY] + ~action:(fun ev -> search_pos_menu txt ~x:ev.ev_MouseX ~y:ev.ev_MouseY); + + pack [sb] ~fill:`Y ~side:`Right; + pack [tw] ~fill:`Both ~expand:true ~side:`Left; + self#set_edit txt; + Textvariable.set txt.modified "unchanged"; + Lexical.init_tags txt.tw + + method clear_errors () = + Text.tag_remove current_tw ~tag:"error" ~start:tstart ~stop:tend; + List.iter error_messages + ~f:(fun tl -> try destroy tl with Protocol.TkError _ -> ()); + error_messages <- [] + + method typecheck () = + self#clear_errors (); + error_messages <- Typecheck.f (List.hd windows) + + method lex () = + List.iter [ Widget.default_toplevel; top ] + ~f:(Toplevel.configure ~cursor:(`Xcursor "watch")); + Text.configure current_tw ~cursor:(`Xcursor "watch"); + ignore (Timer.add ~ms:1 ~callback: + begin fun () -> + Text.tag_remove current_tw ~tag:"error" ~start:tstart ~stop:tend; + Lexical.tag current_tw; + Text.configure current_tw ~cursor:(`Xcursor "xterm"); + List.iter [ Widget.default_toplevel; top ] + ~f:(Toplevel.configure ~cursor:(`Xcursor "")) + end) + + method save_text ?name:l txt = + let l = match l with None -> [txt.name] | Some l -> l in + if l = [] then () else + let name = List.hd l in + if txt.name <> name then current_dir <- Filename.dirname name; + try + if Sys.file_exists name then + if txt.name = name then begin + let backup = name ^ "~" in + if Sys.file_exists backup then Sys.remove backup; + try Sys.rename name backup with Sys_error _ -> () + end else begin + match Jg_message.ask ~master:top ~title:"Save" + ("File `" ^ name ^ "' exists. Overwrite it?") + with `Yes -> Sys.remove name + | `No -> raise (Sys_error "") + | `Cancel -> raise Exit + end; + let file = open_out name in + let text = Text.get txt.tw ~start:tstart ~stop:(tposend 1) in + output_string file text; + close_out file; + txt.name <- name; + self#set_file_name txt + with + Sys_error _ -> + Jg_message.info ~master:top ~title:"Error" + ("Could not save `" ^ name ^ "'.") + | Exit -> () + + method load_text l = + if l = [] then () else + let name = List.hd l in + try + let index = + try + self#set_edit (List.find windows ~f:(fun x -> x.name = name)); + let txt = List.hd windows in + if Textvariable.get txt.modified = "modified" then + begin match Jg_message.ask ~master:top ~title:"Open" + ("`" ^ Filename.basename txt.name ^ "' modified. Save it?") + with `Yes -> self#save_text txt + | `No -> () + | `Cancel -> raise Exit + end; + Textvariable.set txt.modified "unchanged"; + (Text.index current_tw ~index:(`Mark"insert", []), []) + with Not_found -> self#new_window name; tstart + in + current_dir <- Filename.dirname name; + let file = open_in name + and tw = current_tw + and len = ref 0 + and buf = String.create 4096 in + Text.delete tw ~start:tstart ~stop:tend; + while + len := input file buf 0 4096; + !len > 0 + do + Jg_text.output tw ~buf ~pos:0 ~len:!len + done; + close_in file; + Text.mark_set tw ~mark:"insert" ~index; + Text.see tw ~index; + if Filename.check_suffix name ".ml" || + Filename.check_suffix name ".mli" + then begin + if !lex_on_load then self#lex (); + if !type_on_load then self#typecheck () + end + with + Sys_error _ | Exit -> () + + method close_window txt = + try + if Textvariable.get txt.modified = "modified" then + begin match Jg_message.ask ~master:top ~title:"Close" + ("`" ^ Filename.basename txt.name ^ "' modified. Save it?") + with `Yes -> self#save_text txt + | `No -> () + | `Cancel -> raise Exit + end; + windows <- exclude txt windows; + if windows = [] then + self#new_window (current_dir ^ "/untitled") + else self#set_edit (List.hd windows); + destroy txt.frame + with Exit -> () + + method open_file () = + Fileselect.f ~title:"Open File" ~action:self#load_text + ~dir:current_dir ~filter:("*.{ml,mli}") ~sync:true () + + method save_file () = self#save_text (List.hd windows) + + method close_file () = self#close_window (List.hd windows) + + method quit ?(cancel=true) () = + try + List.iter windows ~f: + begin fun txt -> + if Textvariable.get txt.modified = "modified" then + match Jg_message.ask ~master:top ~title:"Quit" ~cancel + ("`" ^ Filename.basename txt.name ^ "' modified. Save it?") + with `Yes -> self#save_text txt + | `No -> () + | `Cancel -> raise Exit + end; + bind top ~events:[`Destroy]; + destroy top + with Exit -> () + + method reopen ~file ~pos = + if not (Winfo.ismapped top) then Wm.deiconify top; + match file with None -> () + | Some file -> + self#load_text [file]; + Text.mark_set current_tw ~mark:"insert" ~index:(tpos pos); + try + let index = + Text.search current_tw ~switches:[`Backwards] ~pattern:"*)" + ~start:(tpos pos) ~stop:(tpos pos ~modi:[`Line(-1)]) in + let index = + Text.search current_tw ~switches:[`Backwards] ~pattern:"(*" + ~start:(index,[]) ~stop:(tpos pos ~modi:[`Line(-20)]) in + let s = Text.get current_tw ~start:(index,[`Line(-1);`Linestart]) + ~stop:(index,[`Line(-1);`Lineend]) in + for i = 0 to String.length s - 1 do + match s.[i] with '\t'|' ' -> () | _ -> raise Not_found + done; + Text.yview_index current_tw ~index:(index,[`Line(-1)]) + with _ -> + Text.yview_index current_tw ~index:(tpos pos ~modi:[`Line(-2)]) + + initializer + (* Create a first window *) + self#new_window (current_dir ^ "/untitled"); + + (* Bindings for the main window *) + List.iter + [ [`Control], "s", (fun () -> Jg_text.search_string current_tw); + [`Control], "g", (fun () -> goto_line current_tw); + [`Alt], "s", self#save_file; + [`Alt], "x", (fun () -> send_phrase (List.hd windows)); + [`Alt], "l", self#lex; + [`Alt], "t", self#typecheck ] + ~f:begin fun (modi,key,act) -> + bind top ~events:[`Modified(modi, `KeyPressDetail key)] ~breakable:true + ~action:(fun _ -> act (); break ()) + end; + + bind top ~events:[`Destroy] ~fields:[`Widget] ~action: + begin fun ev -> + if Widget.name ev.ev_Widget = Widget.name top + then self#quit ~cancel:false () + end; + + (* File menu *) + file_menu#add_command "Open File..." ~command:self#open_file; + file_menu#add_command "Reopen" + ~command:(fun () -> self#load_text [(List.hd windows).name]); + file_menu#add_command "Save File" ~command:self#save_file ~accelerator:"M-s"; + file_menu#add_command "Save As..." ~underline:5 ~command: + begin fun () -> + let txt = List.hd windows in + Fileselect.f ~title:"Save as File" + ~action:(fun name -> self#save_text txt ~name) + ~dir:(Filename.dirname txt.name) + ~filter:"*.{ml,mli}" + ~file:(Filename.basename txt.name) + ~sync:true ~usepath:false () + end; + file_menu#add_command "Close File" ~command:self#close_file; + file_menu#add_command "Close Window" ~command:self#quit ~underline:6; + + (* Edit menu *) + edit_menu#add_command "Paste selection" ~command: + begin fun () -> + Text.insert current_tw ~index:(`Mark"insert",[]) + ~text:(Selection.get ~displayof:top ()) + end; + edit_menu#add_command "Goto..." ~accelerator:"C-g" + ~command:(fun () -> goto_line current_tw); + edit_menu#add_command "Search..." ~accelerator:"C-s" + ~command:(fun () -> Jg_text.search_string current_tw); + edit_menu#add_command "To shell" ~accelerator:"M-x" + ~command:(fun () -> send_phrase (List.hd windows)); + edit_menu#add_command "Select shell..." + ~command:(fun () -> select_shell (List.hd windows)); + + (* Compiler menu *) + compiler_menu#add_command "Preferences..." + ~command:(fun () -> compiler_preferences top); + compiler_menu#add_command "Lex" ~accelerator:"M-l" + ~command:self#lex; + compiler_menu#add_command "Typecheck" ~accelerator:"M-t" + ~command:self#typecheck; + compiler_menu#add_command "Clear errors" + ~command:self#clear_errors; + compiler_menu#add_command "Signature..." ~command: + begin fun () -> + let txt = List.hd windows in if txt.signature <> [] then + let basename = Filename.basename txt.name in + let modname = String.capitalize + (try Filename.chop_extension basename with _ -> basename) in + let env = + Env.add_module (Ident.create modname) + (Types.Tmty_signature txt.signature) + Env.initial + in Viewer.view_defined (Longident.Lident modname) ~env ~show_all:true + end; + + (* Modules *) + module_menu#add_command "Path editor..." + ~command:(fun () -> Setpath.set ~dir:current_dir); + module_menu#add_command "Reset cache" + ~command:(fun () -> Setpath.exec_update_hooks (); Env.reset_cache ()); + module_menu#add_command "Search symbol..." + ~command:Viewer.search_symbol; + module_menu#add_command "Close all" + ~command:Viewer.close_all_views; +end + +(* The main function starts here ! *) + +let already_open : editor list ref = ref [] + +let editor ?file ?(pos=0) ?(reuse=false) () = + + if !already_open <> [] && + let ed = List.hd !already_open + (* try + let name = match file with Some f -> f | None -> raise Not_found in + List.find !already_open ~f:(fun ed -> ed#has_window name) + with Not_found -> List.hd !already_open *) + in try + ed#reopen ~file ~pos; + true + with Protocol.TkError _ -> + already_open := [] (* List.filter !already_open ~f:((<>) ed) *); + false + then () else + let top = Jg_toplevel.titled "OCamlBrowser Editor" in + let menus = Jg_menu.menubar top in + let ed = new editor ~top ~menus in + already_open := !already_open @ [ed]; + if file <> None then ed#reopen ~file ~pos + +let f ?file ?pos ?(opendialog=false) () = + if opendialog then + Fileselect.f ~title:"Open File" + ~action:(function [file] -> editor ~file () | _ -> ()) + ~filter:("*.{ml,mli}") ~sync:true () + else editor ?file ?pos ~reuse:(file <> None) () diff --git a/otherlibs/labltk/browser/editor.mli b/otherlibs/labltk/browser/editor.mli new file mode 100644 index 0000000..94ee3d4 --- /dev/null +++ b/otherlibs/labltk/browser/editor.mli @@ -0,0 +1,20 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: editor.mli,v 1.5 2001-12-07 13:39:57 xleroy Exp $ *) + +open Widget + +val f : ?file:string -> ?pos:int -> ?opendialog:bool -> unit -> unit + (* open the file editor *) diff --git a/otherlibs/labltk/browser/fileselect.ml b/otherlibs/labltk/browser/fileselect.ml new file mode 100644 index 0000000..577f642 --- /dev/null +++ b/otherlibs/labltk/browser/fileselect.ml @@ -0,0 +1,290 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: fileselect.ml,v 1.21 2005-01-28 16:13:11 doligez Exp $ *) + +(* file selection box *) + +open StdLabels +open Str +open Filename +open Tk + +open Useunix + +(**** Memoized rexgexp *) + +let (~!) = Jg_memo.fast ~f:Str.regexp + +(************************************************************ Path name *) + +(* Convert Windows-style directory separator '\' to caml-style '/' *) +let caml_dir path = + if Sys.os_type = "Win32" then + global_replace ~!"\\\\" "/" path + else path + +let parse_filter s = + let s = caml_dir s in + (* replace // by / *) + let s = global_replace ~!"/+" "/" s in + (* replace /./ by / *) + let s = global_replace ~!"/\\./" "/" s in + (* replace hoge/../ by "" *) + let s = global_replace + ~!"\\([^/]\\|[^\\./][^/]\\|[^/][^\\./]\\|[^/][^/]+\\)/\\.\\./" "" s in + (* replace hoge/..$ by *) + let s = global_replace + ~!"\\([^/]\\|[^\\./][^/]\\|[^/][^\\./]\\|[^/][^/]+\\)/\\.\\.$" "" s in + (* replace ^/hoge/../ by / *) + let s = global_replace ~!"^\\(/\\.\\.\\)+/" "/" s in + if string_match ~!"^\\([^\\*?[]*[/:]\\)\\(.*\\)" s 0 then + let dirs = matched_group 1 s + and ptrn = matched_group 2 s + in + dirs, ptrn + else "", s + +let rec fixpoint ~f v = + let v' = f v in + if v = v' then v else fixpoint ~f v' + +let unix_regexp s = + let s = Str.global_replace ~!"[$^.+]" "\\\\\\0" s in + let s = Str.global_replace ~!"\\*" ".*" s in + let s = Str.global_replace ~!"\\?" ".?" s in + let s = + fixpoint s + ~f:(Str.replace_first ~!"\\({.*\\),\\(.*}\\)" "\\1\\|\\2") in + let s = + Str.global_replace ~!"{\\(.*\\)}" "\\(\\1\\)" s in + Str.regexp s + +let exact_match ~pat s = + Str.string_match pat s 0 && Str.match_end () = String.length s + +let ls ~dir ~pattern = + let files = get_files_in_directory dir in + let regexp = unix_regexp pattern in + List.filter files ~f:(exact_match ~pat:regexp) + +(********************************************* Creation *) +let load_in_path = ref false + +let search_in_path ~name = Misc.find_in_path !Config.load_path name + +let f ~title ~action:proc ?(dir = Unix.getcwd ()) + ?filter:(deffilter ="*") ?file:(deffile ="") + ?(multi=false) ?(sync=false) ?(usepath=true) () = + + let current_pattern = ref "" + and current_dir = ref (caml_dir dir) in + + let may_prefix name = + if Filename.is_relative name then concat !current_dir name else name in + + let tl = Jg_toplevel.titled title in + Focus.set tl; + + let new_var () = Textvariable.create ~on:tl () in + let filter_var = new_var () + and selection_var = new_var () + and sync_var = new_var () in + Textvariable.set filter_var deffilter; + + let frm = Frame.create tl ~borderwidth:1 ~relief:`Raised in + let df = Frame.create frm in + let dfl = Frame.create df in + let dfll = Label.create dfl ~text:"Directories" in + let dflf, directory_listbox, directory_scrollbar = + Jg_box.create_with_scrollbar dfl in + let dfr = Frame.create df in + let dfrl = Label.create dfr ~text:"Files" in + let dfrf, filter_listbox, filter_scrollbar = + Jg_box.create_with_scrollbar dfr in + let cfrm = Frame.create tl ~borderwidth:1 ~relief:`Raised in + + let configure ~filter = + let filter = may_prefix filter in + let dir, pattern = parse_filter filter in + let dir = if !load_in_path && usepath then "" else + (current_dir := Filename.dirname dir; dir) + and pattern = if pattern = "" then "*" else pattern in + current_pattern := pattern; + let filter = + if !load_in_path && usepath then pattern else dir ^ pattern in + let directories = get_directories_in_files ~path:dir + (get_files_in_directory dir) in + let matched_files = (* get matched file by subshell call. *) + if !load_in_path && usepath then + List.fold_left !Config.load_path ~init:[] ~f: + begin fun acc dir -> + let files = ls ~dir ~pattern in + Sort.merge (<) files + (List.fold_left files ~init:acc + ~f:(fun acc name -> List2.exclude name acc)) + end + else + List.fold_left directories ~init:(ls ~dir ~pattern) + ~f:(fun acc dir -> List2.exclude dir acc) + in + Textvariable.set filter_var filter; + Textvariable.set selection_var (dir ^ deffile); + Listbox.delete filter_listbox ~first:(`Num 0) ~last:`End; + Listbox.insert filter_listbox ~index:`End ~texts:matched_files; + Jg_box.recenter filter_listbox ~index:(`Num 0); + if !load_in_path && usepath then + Listbox.configure directory_listbox ~takefocus:false + else + begin + Listbox.configure directory_listbox ~takefocus:true; + Listbox.delete directory_listbox ~first:(`Num 0) ~last:`End; + Listbox.insert directory_listbox ~index:`End ~texts:directories; + Jg_box.recenter directory_listbox ~index:(`Num 0) + end + in + + let selected_files = ref [] in (* used for synchronous mode *) + let activate l = + Grab.release tl; + destroy tl; + let l = + if !load_in_path && usepath then + List.fold_right l ~init:[] ~f: + begin fun name acc -> + if not (Filename.is_implicit name) then + may_prefix name :: acc + else try search_in_path ~name :: acc with Not_found -> acc + end + else + List.map l ~f:may_prefix + in + if sync then + begin + selected_files := l; + Textvariable.set sync_var "1" + end + else proc l + in + + (* entries *) + let fl = Label.create frm ~text:"Filter" in + let sl = Label.create frm ~text:"Selection" in + let filter_entry = Jg_entry.create frm ~textvariable:filter_var + ~command:(fun filter -> configure ~filter) in + let selection_entry = Jg_entry.create frm ~textvariable:selection_var + ~command:(fun file -> activate [file]) in + + (* and buttons *) + let set_path = Button.create dfl ~text:"Path editor" ~command: + begin fun () -> + Setpath.add_update_hook (fun () -> configure ~filter:!current_pattern); + let w = Setpath.f ~dir:!current_dir in + Grab.set w; + bind w ~events:[`Destroy] ~extend:true ~action:(fun _ -> Grab.set tl) + end in + let toggle_in_path = Checkbutton.create dfl ~text:"Use load path" + ~command: + begin fun () -> + load_in_path := not !load_in_path; + if !load_in_path then + pack [set_path] ~side:`Bottom ~fill:`X ~expand:true + else + Pack.forget [set_path]; + configure ~filter:(Textvariable.get filter_var) + end + and okb = Button.create cfrm ~text:"Ok" ~command: + begin fun () -> + let files = + List.map (Listbox.curselection filter_listbox) ~f: + begin fun x -> + !current_dir ^ Listbox.get filter_listbox ~index:x + end + in + let files = if files = [] then [Textvariable.get selection_var] + else files in + activate files + end + and flb = Button.create cfrm ~text:"Filter" + ~command:(fun () -> configure ~filter:(Textvariable.get filter_var)) + and ccb = Button.create cfrm ~text:"Cancel" + ~command:(fun () -> activate []) in + + (* binding *) + bind tl ~events:[`KeyPressDetail "Escape"] ~action:(fun _ -> activate []); + Jg_box.add_completion filter_listbox + ~action:(fun index -> activate [Listbox.get filter_listbox ~index]); + if multi then Listbox.configure filter_listbox ~selectmode:`Multiple else + bind filter_listbox ~events:[`ButtonPressDetail 1] ~fields:[`MouseY] + ~action:(fun ev -> + let name = Listbox.get filter_listbox + ~index:(Listbox.nearest filter_listbox ~y:ev.ev_MouseY) in + if !load_in_path && usepath then + try Textvariable.set selection_var (search_in_path ~name) + with Not_found -> () + else Textvariable.set selection_var (may_prefix name)); + + Jg_box.add_completion directory_listbox ~action: + begin fun index -> + let filter = + may_prefix (Listbox.get directory_listbox ~index) ^ + "/" ^ !current_pattern + in configure ~filter + end; + + pack [frm] ~fill:`Both ~expand:true; + (* filter *) + pack [fl] ~side:`Top ~anchor:`W; + pack [filter_entry] ~side:`Top ~fill:`X; + + (* directory + files *) + pack [df] ~side:`Top ~fill:`Both ~expand:true; + (* directory *) + pack [dfl] ~side:`Left ~fill:`Both ~expand:true; + pack [dfll] ~side:`Top ~anchor:`W; + if usepath then pack [toggle_in_path] ~side:`Bottom ~anchor:`W; + pack [dflf] ~side:`Top ~fill:`Both ~expand:true; + pack [directory_scrollbar] ~side:`Right ~fill:`Y; + pack [directory_listbox] ~side:`Left ~fill:`Both ~expand:true; + (* files *) + pack [dfr] ~side:`Right ~fill:`Both ~expand:true; + pack [dfrl] ~side:`Top ~anchor:`W; + pack [dfrf] ~side:`Top ~fill:`Both ~expand:true; + pack [filter_scrollbar] ~side:`Right ~fill:`Y; + pack [filter_listbox] ~side:`Left ~fill:`Both ~expand:true; + + (* selection *) + pack [sl] ~before:df ~side:`Bottom ~anchor:`W; + pack [selection_entry] ~before:sl ~side:`Bottom ~fill:`X; + + (* create OK, Filter and Cancel buttons *) + pack [okb; flb; ccb] ~side:`Left ~fill:`X ~expand:true; + pack [cfrm] ~before:frm ~side:`Bottom ~fill:`X; + + if !load_in_path && usepath then begin + load_in_path := false; + Checkbutton.invoke toggle_in_path; + Checkbutton.select toggle_in_path + end + else configure ~filter:deffilter; + + Tkwait.visibility tl; + Grab.set tl; + + if sync then + begin + Tkwait.variable sync_var; + proc !selected_files + end; + () diff --git a/otherlibs/labltk/browser/fileselect.mli b/otherlibs/labltk/browser/fileselect.mli new file mode 100644 index 0000000..9abcf9b --- /dev/null +++ b/otherlibs/labltk/browser/fileselect.mli @@ -0,0 +1,39 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: fileselect.mli,v 1.7 2002-04-26 12:15:33 furuse Exp $ *) + +val f : + title:string -> + action:(string list -> unit) -> + ?dir:string -> + ?filter:string -> + ?file:string -> + ?multi:bool -> ?sync:bool -> ?usepath:bool -> unit -> unit + +(* action + [] means canceled + if multi select is false, then the list is null or a singleton *) + +(* multi + If true then more than one file are selectable *) + +(* sync + If true then synchronous mode *) + +(* usepath + Enables/disables load path search. Defaults to true *) + +val caml_dir : string -> string +(* Convert Windows-style directory separator '\' to caml-style '/' *) diff --git a/otherlibs/labltk/browser/help.ml b/otherlibs/labltk/browser/help.ml new file mode 100644 index 0000000..632e762 --- /dev/null +++ b/otherlibs/labltk/browser/help.ml @@ -0,0 +1,168 @@ +let text = "\ +\032 OCamlBrowser Help\n\ +\n\ +USE\n\ +\n\ +\032 OCamlBrowser is composed of three tools, the Editor, which allows\n\ +\032 one to edit/typecheck/analyse .mli and .ml files, the Viewer, to\n\ +\032 walk around compiled modules, and the Shell, to run an OCaml\n\ +\032 subshell. You may only have one instance of Editor and Viewer, but\n\ +\032 you may use several subshells.\n\ +\n\ +\032 As with the compiler, you may specify a different path for the\n\ +\032 standard library by setting OCAMLLIB. You may also extend the\n\ +\032 initial load path (only standard library by default) by using the\n\ +\032 -I command line option. The -nolabels, -rectypes and -w options are\n\ +\032 also accepted, and inherited by subshells.\n\ +\032 The -oldui options selects the old multi-window interface. The\n\ +\032 default is now more like Smalltalk's class browser.\n\ +\n\ +1) Viewer\n\ +\n\ +\032 This is the first window you get when you start OCamlBrowser. It\n\ +\032 displays a search window, and the list of modules in the load path.\n\ +\032 At the top a row of menus.\n\ +\n\ +\032 File - Open and File - Editor give access to the editor.\n\ +\n\ +\032 File - Shell opens an OCaml shell.\n\ +\n\ +\032 View - Show all defs displays the signature of the currently\n\ +\032 selected module.\n\ +\n\ +\032 View - Search entry shows/hides the search entry just\n\ +\032 below the menu bar.\n\ +\n\ +\032 Modules - Path editor changes the load path.\n\ +\032 Pressing [Add to path] or Insert key adds selected directories\n\ +\032 to the load path.\n\ +\032 Pressing [Remove from path] or Delete key removes selected\n\ +\032 paths from the load path.\n\ +\n\ +\032 Modules - Reset cache rescans the load path and resets the module\n\ +\032 cache. Do it if you recompile some interface, or change the load\n\ +\032 path in a conflictual way.\n\ +\n\ +\032 Modules - Search symbol allows to search a symbol either by its\n\ +\032 name, like the bottom line of the viewer, or, more interestingly,\n\ +\032 by its type. Exact type searches for a type with exactly the same\n\ +\032 information as the pattern (variables match only variables),\n\ +\032 included type allows to give only partial information: the actual\n\ +\032 type may take more arguments and return more results, and variables\n\ +\032 in the pattern match anything. In both cases, argument and tuple\n\ +\032 order is irrelevant (*), and unlabeled arguments in the pattern\n\ +\032 match any label.\n\ +\n\ +\032 (*) To avoid combinatorial explosion of the search space, optional\n\ +\032 arguments in the actual type are ignored if (1) there are to many\n\ +\032 of them, and (2) they do not appear explicitly in the pattern.\n\ +\n\ +\032 The Search entry just below the menu bar allows one to search for\n\ +\032 an identifier in all modules, either by its name (? and * patterns\n\ +\032 allowed) or by its type (if there is an arrow in the input). When\n\ +\032 search by type is used, it is done in inclusion mode (cf. Modules -\n\ +\032 search symbol)\n\ +\n\ +\032 The Close all button is there to dismiss the windows created\n\ +\032 by the Detach button. By double-clicking on it you will quit the\n\ +\032 browser.\n\ +\n\ +\n\ +2) Module browsing\n\ +\n\ +\032 You select a module in the leftmost box by either cliking on it or\n\ +\032 pressing return when it is selected. Fast access is available in\n\ +\032 all boxes pressing the first few letter of the desired name.\n\ +\032 Double-clicking / double-return displays the whole signature for\n\ +\032 the module.\n\ +\n\ +\032 Defined identifiers inside the module are displayed in a box to the\n\ +\032 right of the previous one. If you click on one, this will either\n\ +\032 display its contents in another box (if this is a sub-module) or\n\ +\032 display the signature for this identifier below.\n\ +\n\ +\032 Signatures are clickable. Double clicking with the left mouse\n\ +\032 button on an identifier in a signature brings you to its signature,\n\ +\032 inside its module box.\n\ +\032 A single click on the right button pops up a menu displaying the\n\ +\032 type declaration for the selected identifier. Its title, when\n\ +\032 selectable, also brings you to its signature.\n\ +\n\ +\032 At the bottom, a series of buttons, depending on the context.\n\ +\032 * Detach copies the currently displayed signature in a new window,\n\ +\032 to keep it.\n\ +\032 * Impl and Intf bring you to the implementation or interface of\n\ +\032 the currently displayed signature, if it is available.\n\ +\n\ +\032 C-s opens a text search dialog for the displayed signature.\n\ +\n\ +3) File editor\n\ +\n\ +\032 You can edit files with it, but there is no auto-save nor undo at\n\ +\032 the moment. Otherwise you can use it as a browser, making\n\ +\032 occasional corrections.\n\ +\n\ +\032 The Edit menu contains commands for jump (C-g), search (C-s), and\n\ +\032 sending the current selection to a sub-shell (M-x). For this last\n\ +\032 option, you may choose the shell via a dialog.\n\ +\n\ +\032 Essential function are in the Compiler menu.\n\ +\n\ +\032 Preferences opens a dialog to set internals of the editor and\n\ +\032 type checker.\n\ +\n\ +\032 Lex (M-l) adds colors according to lexical categories.\n\ +\n\ +\032 Typecheck (M-t) verifies typing, and memorizes it to let one see an\n\ +\032 expression's type by double-clicking on it. This is also valid for\n\ +\032 interfaces. If an error occurs, the part of the interface preceding\n\ +\032 the error is computed.\n\ +\n\ +\032 After typechecking, pressing the right button pops up a menu giving\n\ +\032 the type of the pointed expression, and eventually allowing to\n\ +\032 follow some links.\n\ +\n\ +\032 Clear errors dismisses type checker error messages and warnings.\n\ +\n\ +\032 Signature shows the signature of the current file.\n\ +\n\ +4) Shell\n\ +\n\ +\032 When you create a shell, a dialog is presented to you, letting you\n\ +\032 choose which command you want to run, and the title of the shell\n\ +\032 (to choose it in the Editor).\n\ +\n\ +\032 You may change the default command by setting the OLABL environment\n\ +\032 variable.\n\ +\n\ +\032 The executed subshell is given the current load path.\n\ +\032 File: use a source file or load a bytecode file.\n\ +\032 You may also import the browser's path into the subprocess.\n\ +\032 History: M-p and M-n browse up and down.\n\ +\032 Signal: C-c interrupts and you can kill the subprocess.\n\ +\n\ +BUGS\n\ +\n\ +* When you quit the editor and some file was modified, a dialogue is\n\ +\032 displayed asking wether you want to really quit or not. But 1) if\n\ +\032 you quit directly from the viewer, there is no dialogue at all, and\n\ +\032 2) if you close from the window manager, the dialogue is displayed,\n\ +\032 but you cannot cancel the destruction... Beware.\n\ +\n\ +* When you run it through xon, the shell hangs at the first error. But\n\ +\032 its ok if you start ocamlbrowser from a remote shell...\n\ +\n\ +TODO\n\ +\n\ +* Complete cross-references.\n\ +\n\ +* Power up editor.\n\ +\n\ +* Add support for the debugger.\n\ +\n\ +* Make this a real programming environment, both for beginners an\n\ +\032 experimented users.\n\ +\n\ +\n\ +Bug reports and comments to <garrigue@kurims.kyoto-u.ac.jp>\n\ +";; diff --git a/otherlibs/labltk/browser/help.txt b/otherlibs/labltk/browser/help.txt new file mode 100644 index 0000000..62bfc59 --- /dev/null +++ b/otherlibs/labltk/browser/help.txt @@ -0,0 +1,166 @@ + OCamlBrowser Help + +USE + + OCamlBrowser is composed of three tools, the Editor, which allows + one to edit/typecheck/analyse .mli and .ml files, the Viewer, to + walk around compiled modules, and the Shell, to run an OCaml + subshell. You may only have one instance of Editor and Viewer, but + you may use several subshells. + + As with the compiler, you may specify a different path for the + standard library by setting OCAMLLIB. You may also extend the + initial load path (only standard library by default) by using the + -I command line option. The -nolabels, -rectypes and -w options are + also accepted, and inherited by subshells. + The -oldui options selects the old multi-window interface. The + default is now more like Smalltalk's class browser. + +1) Viewer + + This is the first window you get when you start OCamlBrowser. It + displays a search window, and the list of modules in the load path. + At the top a row of menus. + + File - Open and File - Editor give access to the editor. + + File - Shell opens an OCaml shell. + + View - Show all defs displays the signature of the currently + selected module. + + View - Search entry shows/hides the search entry just + below the menu bar. + + Modules - Path editor changes the load path. + Pressing [Add to path] or Insert key adds selected directories + to the load path. + Pressing [Remove from path] or Delete key removes selected + paths from the load path. + + Modules - Reset cache rescans the load path and resets the module + cache. Do it if you recompile some interface, or change the load + path in a conflictual way. + + Modules - Search symbol allows to search a symbol either by its + name, like the bottom line of the viewer, or, more interestingly, + by its type. Exact type searches for a type with exactly the same + information as the pattern (variables match only variables), + included type allows to give only partial information: the actual + type may take more arguments and return more results, and variables + in the pattern match anything. In both cases, argument and tuple + order is irrelevant (*), and unlabeled arguments in the pattern + match any label. + + (*) To avoid combinatorial explosion of the search space, optional + arguments in the actual type are ignored if (1) there are to many + of them, and (2) they do not appear explicitly in the pattern. + + The Search entry just below the menu bar allows one to search for + an identifier in all modules, either by its name (? and * patterns + allowed) or by its type (if there is an arrow in the input). When + search by type is used, it is done in inclusion mode (cf. Modules - + search symbol) + + The Close all button is there to dismiss the windows created + by the Detach button. By double-clicking on it you will quit the + browser. + + +2) Module browsing + + You select a module in the leftmost box by either cliking on it or + pressing return when it is selected. Fast access is available in + all boxes pressing the first few letter of the desired name. + Double-clicking / double-return displays the whole signature for + the module. + + Defined identifiers inside the module are displayed in a box to the + right of the previous one. If you click on one, this will either + display its contents in another box (if this is a sub-module) or + display the signature for this identifier below. + + Signatures are clickable. Double clicking with the left mouse + button on an identifier in a signature brings you to its signature, + inside its module box. + A single click on the right button pops up a menu displaying the + type declaration for the selected identifier. Its title, when + selectable, also brings you to its signature. + + At the bottom, a series of buttons, depending on the context. + * Detach copies the currently displayed signature in a new window, + to keep it. + * Impl and Intf bring you to the implementation or interface of + the currently displayed signature, if it is available. + + C-s opens a text search dialog for the displayed signature. + +3) File editor + + You can edit files with it, but there is no auto-save nor undo at + the moment. Otherwise you can use it as a browser, making + occasional corrections. + + The Edit menu contains commands for jump (C-g), search (C-s), and + sending the current selection to a sub-shell (M-x). For this last + option, you may choose the shell via a dialog. + + Essential function are in the Compiler menu. + + Preferences opens a dialog to set internals of the editor and + type checker. + + Lex (M-l) adds colors according to lexical categories. + + Typecheck (M-t) verifies typing, and memorizes it to let one see an + expression's type by double-clicking on it. This is also valid for + interfaces. If an error occurs, the part of the interface preceding + the error is computed. + + After typechecking, pressing the right button pops up a menu giving + the type of the pointed expression, and eventually allowing to + follow some links. + + Clear errors dismisses type checker error messages and warnings. + + Signature shows the signature of the current file. + +4) Shell + + When you create a shell, a dialog is presented to you, letting you + choose which command you want to run, and the title of the shell + (to choose it in the Editor). + + You may change the default command by setting the OLABL environment + variable. + + The executed subshell is given the current load path. + File: use a source file or load a bytecode file. + You may also import the browser's path into the subprocess. + History: M-p and M-n browse up and down. + Signal: C-c interrupts and you can kill the subprocess. + +BUGS + +* When you quit the editor and some file was modified, a dialogue is + displayed asking wether you want to really quit or not. But 1) if + you quit directly from the viewer, there is no dialogue at all, and + 2) if you close from the window manager, the dialogue is displayed, + but you cannot cancel the destruction... Beware. + +* When you run it through xon, the shell hangs at the first error. But + its ok if you start ocamlbrowser from a remote shell... + +TODO + +* Complete cross-references. + +* Power up editor. + +* Add support for the debugger. + +* Make this a real programming environment, both for beginners an + experimented users. + + +Bug reports and comments to <garrigue@kurims.kyoto-u.ac.jp> diff --git a/otherlibs/labltk/browser/jg_bind.ml b/otherlibs/labltk/browser/jg_bind.ml new file mode 100644 index 0000000..0cae909 --- /dev/null +++ b/otherlibs/labltk/browser/jg_bind.ml @@ -0,0 +1,28 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_bind.ml,v 1.7 2001-12-07 13:39:57 xleroy Exp $ *) + +open Tk + +let enter_focus w = + bind w ~events:[`Enter] ~action:(fun _ -> Focus.set w) + +let escape_destroy ?destroy:tl w = + let tl = match tl with Some w -> w | None -> w in + bind w ~events:[`KeyPressDetail "Escape"] ~action:(fun _ -> destroy tl) + +let return_invoke w ~button = + bind w ~events:[`KeyPressDetail "Return"] + ~action:(fun _ -> Button.invoke button) diff --git a/otherlibs/labltk/browser/jg_bind.mli b/otherlibs/labltk/browser/jg_bind.mli new file mode 100644 index 0000000..053220b --- /dev/null +++ b/otherlibs/labltk/browser/jg_bind.mli @@ -0,0 +1,21 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_bind.mli,v 1.5 2001-12-07 13:39:57 xleroy Exp $ *) + +open Widget + +val enter_focus : 'a widget -> unit +val escape_destroy : ?destroy:'a widget -> 'a widget ->unit +val return_invoke : 'a widget -> button:button widget -> unit diff --git a/otherlibs/labltk/browser/jg_box.ml b/otherlibs/labltk/browser/jg_box.ml new file mode 100644 index 0000000..df5a1f7 --- /dev/null +++ b/otherlibs/labltk/browser/jg_box.ml @@ -0,0 +1,82 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_box.ml,v 1.8 2001-12-07 13:39:58 xleroy Exp $ *) + +open Tk + +let add_scrollbar lb = + let sb = + Scrollbar.create (Winfo.parent lb) ~command:(Listbox.yview lb) in + Listbox.configure lb ~yscrollcommand:(Scrollbar.set sb); sb + +let create_with_scrollbar ?selectmode parent = + let frame = Frame.create parent in + let lb = Listbox.create frame ?selectmode in + frame, lb, add_scrollbar lb + +(* from frx_listbox,adapted *) + +let recenter lb ~index = + Listbox.selection_clear lb ~first:(`Num 0) ~last:`End; + (* Activate it, to keep consistent with Up/Down. + You have to be in Extended or Browse mode *) + Listbox.activate lb ~index; + Listbox.selection_anchor lb ~index; + Listbox.yview_index lb ~index + +class timed ?wait ?nocase get_texts = object + val get_texts = get_texts + inherit Jg_completion.timed [] ?wait ?nocase as super + method reset = + texts <- get_texts (); + super#reset +end + +let add_completion ?action ?wait ?nocase ?(double=true) lb = + let comp = + new timed ?wait ?nocase + (fun () -> Listbox.get_range lb ~first:(`Num 0) ~last:`End) in + + Jg_bind.enter_focus lb; + + bind lb ~events:[`KeyPress] ~fields:[`Char] ~action: + begin fun ev -> + (* consider only keys producing characters. The callback is called + even if you press Shift. *) + if ev.ev_Char <> "" then + recenter lb ~index:(`Num (comp#add ev.ev_Char)) + end; + + begin match action with + Some action -> + bind lb ~events:[`KeyPressDetail "Return"] + ~action:(fun _ -> action `Active); + let bmod = if double then [`Double] else [] in + bind lb ~events:[`Modified(bmod, `ButtonPressDetail 1)] + ~breakable:true ~fields:[`MouseY] + ~action: + begin fun ev -> + let index = Listbox.nearest lb ~y:ev.ev_MouseY in + if not double then begin + Listbox.selection_clear lb ~first:(`Num 0) ~last:`End; + Listbox.selection_set lb ~first:index ~last:index; + end; + action index; + break () + end + | None -> () + end; + + recenter lb ~index:(`Num 0) (* so that first item is active *) diff --git a/otherlibs/labltk/browser/jg_button.ml b/otherlibs/labltk/browser/jg_button.ml new file mode 100644 index 0000000..af75ad6 --- /dev/null +++ b/otherlibs/labltk/browser/jg_button.ml @@ -0,0 +1,25 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_button.ml,v 1.8 2001-12-07 13:39:58 xleroy Exp $ *) + +open Tk + +let create_destroyer ~parent ?(text="Ok") tl = + Button.create parent ~text ~command:(fun () -> destroy tl) + +let add_destroyer ?text tl = + let b = create_destroyer tl ~parent:tl ?text in + pack [b] ~side:`Bottom ~fill:`X; + b diff --git a/otherlibs/labltk/browser/jg_completion.ml b/otherlibs/labltk/browser/jg_completion.ml new file mode 100644 index 0000000..88d53f9 --- /dev/null +++ b/otherlibs/labltk/browser/jg_completion.ml @@ -0,0 +1,53 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_completion.ml,v 1.10 2001-12-07 13:39:58 xleroy Exp $ *) + +let lt_string ?(nocase=false) s1 s2 = + if nocase then String.lowercase s1 < String.lowercase s2 else s1 < s2 + +class completion ?nocase texts = object + val mutable texts = texts + val nocase = nocase + val mutable prefix = "" + val mutable current = 0 + method add c = + prefix <- prefix ^ c; + while current < List.length texts - 1 && + lt_string (List.nth texts current) prefix ?nocase + do + current <- current + 1 + done; + current + method current = current + method get_current = List.nth texts current + method reset = + prefix <- ""; + current <- 0 +end + +class timed ?nocase ?wait texts = object (self) + inherit completion texts ?nocase as super + val wait = match wait with None -> 500 | Some n -> n + val mutable timer = None + method add c = + begin match timer with + None -> self#reset + | Some t -> Timer.remove t + end; + timer <- Some (Timer.add ~ms:wait ~callback:(fun () -> self#reset)); + super#add c + method reset = + timer <- None; super#reset +end diff --git a/otherlibs/labltk/browser/jg_completion.mli b/otherlibs/labltk/browser/jg_completion.mli new file mode 100644 index 0000000..11896af --- /dev/null +++ b/otherlibs/labltk/browser/jg_completion.mli @@ -0,0 +1,25 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_completion.mli,v 1.6 2001-12-07 13:39:58 xleroy Exp $ *) + +val lt_string : ?nocase:bool -> string -> string -> bool + +class timed : ?nocase:bool -> ?wait:int -> string list -> object + val mutable texts : string list + method add : string -> int + method current : int + method get_current : string + method reset : unit +end diff --git a/otherlibs/labltk/browser/jg_config.ml b/otherlibs/labltk/browser/jg_config.ml new file mode 100644 index 0000000..2be13d4 --- /dev/null +++ b/otherlibs/labltk/browser/jg_config.ml @@ -0,0 +1,40 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_config.ml,v 1.10 2001-12-07 13:39:58 xleroy Exp $ *) + +open StdLabels +open Jg_tk + +let fixed = if wingui then "{Courier New} 8" else "fixed" +let variable = if wingui then "Arial 9" else "variable" + +let init () = + if wingui then Option.add ~path:"*font" fixed; + let font = + let font = + Option.get Widget.default_toplevel ~name:"variableFont" ~clas:"Font" in + if font = "" then variable else font + in + List.iter ["Button"; "Label"; "Menu"; "Menubutton"; "Radiobutton"] + ~f:(fun cl -> Option.add ~path:("*" ^ cl ^ ".font") font); + Option.add ~path:"*Menu.tearOff" "0" ~priority:`StartupFile; + Option.add ~path:"*Button.padY" "0" ~priority:`StartupFile; + Option.add ~path:"*Text.highlightThickness" "0" ~priority:`StartupFile; + Option.add ~path:"*interface.background" "gray85" ~priority:`StartupFile; + let foreground = + Option.get Widget.default_toplevel + ~name:"disabledForeground" ~clas:"Foreground" in + if foreground = "" then + Option.add ~path:"*disabledForeground" "black" diff --git a/otherlibs/labltk/browser/jg_config.mli b/otherlibs/labltk/browser/jg_config.mli new file mode 100644 index 0000000..c8af68f --- /dev/null +++ b/otherlibs/labltk/browser/jg_config.mli @@ -0,0 +1,17 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_config.mli,v 1.5 2001-12-07 13:39:58 xleroy Exp $ *) + +val init: unit -> unit diff --git a/otherlibs/labltk/browser/jg_entry.ml b/otherlibs/labltk/browser/jg_entry.ml new file mode 100644 index 0000000..13d4d2c --- /dev/null +++ b/otherlibs/labltk/browser/jg_entry.ml @@ -0,0 +1,27 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_entry.ml,v 1.7 2001-12-07 13:39:58 xleroy Exp $ *) + +open Tk + +let create ?command ?width ?textvariable parent = + let ew = Entry.create parent ?width ?textvariable in + Jg_bind.enter_focus ew; + begin match command with Some command -> + bind ew ~events:[`KeyPressDetail "Return"] + ~action:(fun _ -> command (Entry.get ew)) + | None -> () + end; + ew diff --git a/otherlibs/labltk/browser/jg_memo.ml b/otherlibs/labltk/browser/jg_memo.ml new file mode 100644 index 0000000..1c2e85d --- /dev/null +++ b/otherlibs/labltk/browser/jg_memo.ml @@ -0,0 +1,35 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_memo.ml,v 1.8 2001-12-07 13:39:58 xleroy Exp $ *) + +type ('a, 'b) assoc_list = + Nil + | Cons of 'a * 'b * ('a, 'b) assoc_list + +let rec assq key = function + Nil -> raise Not_found + | Cons (a, b, l) -> + if key == a then b else assq key l + +let fast ~f = + let memo = ref Nil in + fun key -> + try assq key !memo + with Not_found -> + let data = f key in + memo := Cons(key, data, !memo); + data + + diff --git a/otherlibs/labltk/browser/jg_memo.mli b/otherlibs/labltk/browser/jg_memo.mli new file mode 100644 index 0000000..e10e2e3 --- /dev/null +++ b/otherlibs/labltk/browser/jg_memo.mli @@ -0,0 +1,19 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_memo.mli,v 1.7 2001-12-07 13:39:59 xleroy Exp $ *) + +val fast : f:('a -> 'b) -> 'a -> 'b +(* "fast" memoizer: uses a List.assq like function *) +(* Good for a smallish number of keys, phisically equal *) diff --git a/otherlibs/labltk/browser/jg_menu.ml b/otherlibs/labltk/browser/jg_menu.ml new file mode 100644 index 0000000..89831fd --- /dev/null +++ b/otherlibs/labltk/browser/jg_menu.ml @@ -0,0 +1,44 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_menu.ml,v 1.9 2006-01-04 16:55:50 doligez Exp $ *) + +open Tk + +class c ~parent ?(underline=0) label = object (self) + val menu = + let menu = Menu.create parent in + Menu.add_cascade parent ~menu ~label ~underline; + menu + method menu = menu + method virtual add_command : + ?underline:int -> + ?accelerator:string -> ?activebackground:color -> + ?activeforeground:color -> ?background:color -> + ?bitmap:bitmap -> ?command:(unit -> unit) -> + ?font:string -> ?foreground:color -> + ?image:image -> ?state:state -> + string -> unit + method add_command ?(underline=0) ?accelerator ?activebackground + ?activeforeground ?background ?bitmap ?command ?font ?foreground + ?image ?state label = + Menu.add_command menu ~label ~underline ?accelerator + ?activebackground ?activeforeground ?background ?bitmap + ?command ?font ?foreground ?image ?state +end + +let menubar tl = + let menu = Menu.create tl ~name:"menubar" ~typ:`Menubar in + Toplevel.configure tl ~menu; + menu diff --git a/otherlibs/labltk/browser/jg_message.ml b/otherlibs/labltk/browser/jg_message.ml new file mode 100644 index 0000000..eca73ce --- /dev/null +++ b/otherlibs/labltk/browser/jg_message.ml @@ -0,0 +1,111 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_message.ml,v 1.18 2002-07-26 00:04:05 garrigue Exp $ *) + +open StdLabels +open Tk +open Jg_tk + +(* +class formatted ~parent ~width ~maxheight ~minheight = + val parent = (parent : Widget.any Widget.widget) + val width = width + val maxheight = maxheight + val minheight = minheight + val tw = Text.create ~parent ~width ~wrap:`Word + val fof = Format.get_formatter_output_functions () + method parent = parent + method init = + pack [tw] ~side:`Left ~fill:`Both ~expand:true; + Format.print_flush (); + Format.set_margin (width - 2); + Format.set_formatter_output_functions ~out:(Jg_text.output tw) + ~flush:(fun () -> ()) + method finish = + Format.print_flush (); + Format.set_formatter_output_functions ~out:(fst fof) ~flush:(snd fof); + let `Linechar (l, _) = Text.index tw ~index:(tposend 1) in + Text.configure tw ~height:(max minheight (min l maxheight)); + if l > 5 then + pack [Jg_text.add_scrollbar tw] ~before:tw ~side:`Right ~fill:`Y +end +*) + +let formatted ~title ?on ?(ppf = Format.std_formatter) + ?(width=60) ?(maxheight=10) ?(minheight=0) () = + let tl, frame = + match on with + Some frame -> +(* let label = Label.create frame ~anchor:`W ~padx:10 ~text:title in + pack [label] ~side:`Top ~fill:`X; + let frame2 = Frame.create frame in + pack [frame2] ~side:`Bottom ~fill:`Both ~expand:true; *) + coe frame, frame + | None -> + let tl = Jg_toplevel.titled title in + Jg_bind.escape_destroy tl; + let frame = Frame.create tl in + pack [frame] ~side:`Top ~fill:`Both ~expand:true; + coe tl, frame + in + let tw = Text.create frame ~width ~wrap:`Word in + pack [tw] ~side:`Left ~fill:`Both ~expand:true; + Format.pp_print_flush ppf (); + Format.pp_set_margin ppf (width - 2); + let fof,fff = Format.pp_get_formatter_output_functions ppf () in + Format.pp_set_formatter_output_functions ppf + (fun buf pos len -> Jg_text.output tw ~buf ~pos ~len) + ignore; + tl, tw, + begin fun () -> + Format.pp_print_flush ppf (); + Format.pp_set_formatter_output_functions ppf fof fff; + let `Linechar (l, _) = Text.index tw ~index:(tposend 1) in + Text.configure tw ~height:(max minheight (min l maxheight)); + if l > 5 then + pack [Jg_text.add_scrollbar tw] ~before:tw ~side:`Right ~fill:`Y + end + +let ask ~title ?master ?(no=true) ?(cancel=true) text = + let tl = Jg_toplevel.titled title in + begin match master with None -> () + | Some master -> Wm.transient_set tl ~master + end; + let mw = Message.create tl ~text ~padx:20 ~pady:10 + ~width:250 ~justify:`Left ~aspect:400 ~anchor:`W + and fw = Frame.create tl + and sync = Textvariable.create ~on:tl () + and r = ref (`Cancel : [`Yes|`No|`Cancel]) in + let accept = Button.create fw + ~text:(if no || cancel then "Yes" else "Dismiss") + ~command:(fun () -> r := `Yes; destroy tl) + and refuse = Button.create fw ~text:"No" + ~command:(fun () -> r := `No; destroy tl) + and cancelB = Button.create fw ~text:"Cancel" + ~command:(fun () -> r := `Cancel; destroy tl) + in + bind tl ~events:[`Destroy] ~extend:true + ~action:(fun _ -> Textvariable.set sync "1"); + pack [accept] ~side:`Left ~fill:`X ~expand:true; + if no then pack [refuse] ~side:`Left ~fill:`X ~expand:true; + if cancel then pack [cancelB] ~side:`Left ~fill:`X ~expand:true; + pack [mw] ~side:`Top ~fill:`Both; + pack [fw] ~side:`Bottom ~fill:`X ~expand:true; + Grab.set tl; + Tkwait.variable sync; + !r + +let info ~title ?master text = + ignore (ask ~title ?master ~no:false ~cancel:false text) diff --git a/otherlibs/labltk/browser/jg_message.mli b/otherlibs/labltk/browser/jg_message.mli new file mode 100644 index 0000000..23ba719 --- /dev/null +++ b/otherlibs/labltk/browser/jg_message.mli @@ -0,0 +1,33 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_message.mli,v 1.10 2002-07-26 00:04:05 garrigue Exp $ *) + +open Widget + +val formatted : + title:string -> + ?on:frame widget -> + ?ppf:Format.formatter -> + ?width:int -> + ?maxheight:int -> + ?minheight:int -> + unit -> any widget * text widget * (unit -> unit) + +val ask : + title:string -> ?master:toplevel widget -> + ?no:bool -> ?cancel:bool -> string -> [`Cancel|`No|`Yes] + +val info : + title:string -> ?master:toplevel widget -> string -> unit diff --git a/otherlibs/labltk/browser/jg_multibox.ml b/otherlibs/labltk/browser/jg_multibox.ml new file mode 100644 index 0000000..fae87ba --- /dev/null +++ b/otherlibs/labltk/browser/jg_multibox.ml @@ -0,0 +1,185 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_multibox.ml,v 1.11 2001-12-07 13:39:59 xleroy Exp $ *) + +open StdLabels + +let rec gen_list ~f:f ~len = + if len = 0 then [] else f () :: gen_list ~f:f ~len:(len - 1) + +let rec make_list ~len ~fill = + if len = 0 then [] else fill :: make_list ~len:(len - 1) ~fill + +(* By column version +let rec firsts ~len l = + if len = 0 then ([],l) else + match l with + a::l -> + let (f,l) = firsts l len:(len - 1) in + (a::f,l) + | [] -> + (l,[]) + +let rec split ~len = function + [] -> [] + | l -> + let (f,r) = firsts l ~len in + let ret = split ~len r in + f :: ret + +let extend l ~len ~fill = + if List.length l >= len then l + else l @ make_list ~fill len:(len - List.length l) +*) + +(* By row version *) + +let rec first l ~len = + if len = 0 then [], l else + match l with + [] -> make_list ~len ~fill:"", [] + | a::l -> + let (l',r) = first ~len:(len - 1) l in a::l',r + +let rec split l ~len = + if l = [] then make_list ~len ~fill:[] else + let (cars,r) = first l ~len in + let cdrs = split r ~len in + List.map2 cars cdrs ~f:(fun a l -> a::l) + + +open Tk + +class c ~cols ~texts ?maxheight ?width parent = object (self) + val parent' = coe parent + val length = List.length texts + val boxes = + let height = (List.length texts - 1) / cols + 1 in + let height = + match maxheight with None -> height + | Some max -> min max height + in + gen_list ~len:cols ~f: + begin fun () -> + Listbox.create parent ~height ?width + ~highlightthickness:0 + ~borderwidth:1 + end + val mutable current = 0 + method cols = cols + method texts = texts + method parent = parent' + method boxes = boxes + method current = current + method recenter ?(aligntop=false) n = + current <- + if n < 0 then 0 else + if n < length then n else length - 1; + (* Activate it, to keep consistent with Up/Down. + You have to be in Extended or Browse mode *) + let box = List.nth boxes (current mod cols) + and index = `Num (current / cols) in + List.iter boxes ~f: + begin fun box -> + Listbox.selection_clear box ~first:(`Num 0) ~last:`End; + Listbox.selection_anchor box ~index; + Listbox.activate box ~index + end; + Focus.set box; + if aligntop then Listbox.yview_index box ~index + else Listbox.see box ~index; + let (first,last) = Listbox.yview_get box in + List.iter boxes ~f:(Listbox.yview ~scroll:(`Moveto first)) + method init = + let textl = split ~len:cols texts in + List.iter2 boxes textl ~f: + begin fun box texts -> + Jg_bind.enter_focus box; + Listbox.insert box ~texts ~index:`End + end; + pack boxes ~side:`Left ~expand:true ~fill:`Both; + self#bind_mouse ~events:[`ButtonPressDetail 1] + ~action:(fun _ ~index:n -> self#recenter n; break ()); + let current_height () = + let (top,bottom) = Listbox.yview_get (List.hd boxes) in + truncate ((bottom -. top) *. float (Listbox.size (List.hd boxes)) + +. 0.99) + in + List.iter + [ "Right", (fun n -> n+1); + "Left", (fun n -> n-1); + "Up", (fun n -> n-cols); + "Down", (fun n -> n+cols); + "Prior", (fun n -> n - current_height () * cols); + "Next", (fun n -> n + current_height () * cols); + "Home", (fun _ -> 0); + "End", (fun _ -> List.length texts) ] + ~f:begin fun (key,f) -> + self#bind_kbd ~events:[`KeyPressDetail key] + ~action:(fun _ ~index:n -> self#recenter (f n); break ()) + end; + self#recenter 0 + method bind_mouse ~events ~action = + let i = ref 0 in + List.iter boxes ~f: + begin fun box -> + let b = !i in + bind box ~events ~breakable:true ~fields:[`MouseX;`MouseY] + ~action:(fun ev -> + let `Num n = Listbox.nearest box ~y:ev.ev_MouseY + in action ev ~index:(n * cols + b)); + incr i + end + method bind_kbd ~events ~action = + let i = ref 0 in + List.iter boxes ~f: + begin fun box -> + let b = !i in + bind box ~events ~breakable:true ~fields:[`Char] + ~action:(fun ev -> + let `Num n = Listbox.index box ~index:`Active in + action ev ~index:(n * cols + b)); + incr i + end +end + +let add_scrollbar (box : c) = + let boxes = box#boxes in + let sb = + Scrollbar.create (box#parent) + ~command:(fun ~scroll -> List.iter boxes ~f:(Listbox.yview ~scroll)) in + List.iter boxes + ~f:(fun lb -> Listbox.configure lb ~yscrollcommand:(Scrollbar.set sb)); + pack [sb] ~before:(List.hd boxes) ~side:`Right ~fill:`Y; + sb + +let add_completion ?action ?wait (box : c) = + let comp = new Jg_completion.timed (box#texts) ?wait in + box#bind_kbd ~events:[`KeyPress] + ~action:(fun ev ~index -> + (* consider only keys producing characters. The callback is called + * even if you press Shift. *) + if ev.ev_Char <> "" then + box#recenter (comp#add ev.ev_Char) ~aligntop:true); + match action with + Some action -> + box#bind_kbd ~events:[`KeyPressDetail "space"] + ~action:(fun ev ~index -> action (box#current)); + box#bind_kbd ~events:[`KeyPressDetail "Return"] + ~action:(fun ev ~index -> action (box#current)); + box#bind_mouse ~events:[`ButtonPressDetail 1] + ~action:(fun ev ~index -> + box#recenter index; action (box#current); break ()) + | None -> () diff --git a/otherlibs/labltk/browser/jg_multibox.mli b/otherlibs/labltk/browser/jg_multibox.mli new file mode 100644 index 0000000..76afca7 --- /dev/null +++ b/otherlibs/labltk/browser/jg_multibox.mli @@ -0,0 +1,35 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_multibox.mli,v 1.6 2001-12-07 13:39:59 xleroy Exp $ *) + +class c : + cols:int -> texts:string list -> + ?maxheight:int -> ?width:int -> 'a Widget.widget -> +object + method cols : int + method texts : string list + method parent : Widget.any Widget.widget + method boxes : Widget.listbox Widget.widget list + method current : int + method init : unit + method recenter : ?aligntop:bool -> int -> unit + method bind_mouse : + events:Tk.event list -> action:(Tk.eventInfo -> index:int -> unit) -> unit + method bind_kbd : + events:Tk.event list -> action:(Tk.eventInfo -> index:int -> unit) -> unit +end + +val add_scrollbar : c -> Widget.scrollbar Widget.widget +val add_completion : ?action:(int -> unit) -> ?wait:int -> c -> unit diff --git a/otherlibs/labltk/browser/jg_text.ml b/otherlibs/labltk/browser/jg_text.ml new file mode 100644 index 0000000..9589a10 --- /dev/null +++ b/otherlibs/labltk/browser/jg_text.ml @@ -0,0 +1,104 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_text.ml,v 1.11 2002-08-09 10:34:44 garrigue Exp $ *) + +open StdLabels +open Tk +open Jg_tk + +let get_all tw = Text.get tw ~start:tstart ~stop:(tposend 1) + +let tag_and_see tw ~tag ~start ~stop = + Text.tag_remove tw ~start:(tpos 0) ~stop:tend ~tag; + Text.tag_add tw ~start ~stop ~tag; + try + Text.see tw ~index:(`Tagfirst tag, []); + Text.mark_set tw ~mark:"insert" ~index:(`Tagfirst tag, []) + with Protocol.TkError _ -> () + +let output tw ~buf ~pos ~len = + Text.insert tw ~index:tend ~text:(String.sub buf ~pos ~len) + +let add_scrollbar tw = + let sb = Scrollbar.create (Winfo.parent tw) ~command:(Text.yview tw) + in Text.configure tw ~yscrollcommand:(Scrollbar.set sb); sb + +let create_with_scrollbar parent = + let frame = Frame.create parent in + let tw = Text.create frame in + frame, tw, add_scrollbar tw + +let goto_tag tw ~tag = + let index = (`Tagfirst tag, []) in + try Text.see tw ~index; + Text.mark_set tw ~index ~mark:"insert" + with Protocol.TkError _ -> () + +let search_string tw = + let tl = Jg_toplevel.titled "Search" in + Wm.transient_set tl ~master:(Winfo.toplevel tw); + let fi = Frame.create tl + and fd = Frame.create tl + and fm = Frame.create tl + and buttons = Frame.create tl + and direction = Textvariable.create ~on:tl () + and mode = Textvariable.create ~on:tl () + and count = Textvariable.create ~on:tl () + in + let label = Label.create fi ~text:"Pattern:" + and text = Entry.create fi ~width:20 + and back = Radiobutton.create fd ~variable:direction + ~text:"Backwards" ~value:"backward" + and forw = Radiobutton.create fd ~variable:direction + ~text:"Forwards" ~value:"forward" + and exact = Radiobutton.create fm ~variable:mode + ~text:"Exact" ~value:"exact" + and nocase = Radiobutton.create fm ~variable:mode + ~text:"No case" ~value:"nocase" + and regexp = Radiobutton.create fm ~variable:mode + ~text:"Regexp" ~value:"regexp" + in + let search = Button.create buttons ~text:"Search" ~command: + begin fun () -> + try + let pattern = Entry.get text in + let dir, ofs = match Textvariable.get direction with + "forward" -> `Forwards, 1 + | "backward" -> `Backwards, -1 + | _ -> assert false + and mode = match Textvariable.get mode with "exact" -> [`Exact] + | "nocase" -> [`Nocase] | "regexp" -> [`Regexp] | _ -> [] + in + let ndx = + Text.search tw ~pattern ~switches:([dir;`Count count] @ mode) + ~start:(`Mark "insert", [`Char ofs]) + in + tag_and_see tw ~tag:"sel" ~start:(ndx,[]) + ~stop:(ndx,[`Char(int_of_string (Textvariable.get count))]) + with Invalid_argument _ -> () + end + and ok = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" in + + Focus.set text; + Jg_bind.return_invoke text ~button:search; + Jg_bind.escape_destroy tl; + Textvariable.set direction "forward"; + Textvariable.set mode "nocase"; + pack [label] ~side:`Left; + pack [text] ~side:`Right ~fill:`X ~expand:true; + pack [back; forw] ~side:`Left; + pack [exact; nocase; regexp] ~side:`Left; + pack [search; ok] ~side:`Left ~fill:`X ~expand:true; + pack [fi; fd; fm; buttons] ~side:`Top ~fill:`X diff --git a/otherlibs/labltk/browser/jg_text.mli b/otherlibs/labltk/browser/jg_text.mli new file mode 100644 index 0000000..9c7e1da --- /dev/null +++ b/otherlibs/labltk/browser/jg_text.mli @@ -0,0 +1,28 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_text.mli,v 1.7 2001-12-07 13:40:00 xleroy Exp $ *) + +open Widget + +val get_all : text widget -> string +val tag_and_see : + text widget -> + tag:Tk.textTag -> start:Tk.textIndex -> stop:Tk.textIndex -> unit +val output : text widget -> buf:string -> pos:int -> len:int -> unit +val add_scrollbar : text widget -> scrollbar widget +val create_with_scrollbar : + 'a widget -> frame widget * text widget * scrollbar widget +val goto_tag : text widget -> tag:string -> unit +val search_string : text widget -> unit diff --git a/otherlibs/labltk/browser/jg_tk.ml b/otherlibs/labltk/browser/jg_tk.ml new file mode 100644 index 0000000..d86f5f3 --- /dev/null +++ b/otherlibs/labltk/browser/jg_tk.ml @@ -0,0 +1,24 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_tk.ml,v 1.7 2001-12-07 13:40:00 xleroy Exp $ *) + +open Tk + +let tpos ?(modi=[]) x : textIndex = `Linechar (1,0), `Char x :: modi +and tposend ?(modi=[]) x : textIndex = `End, `Char (-x) :: modi +let tstart : textIndex = `Linechar (1,0), [] +and tend : textIndex = `End, [] + +let wingui = Sys.os_type = "Win32" || Sys.os_type = "Cygwin" diff --git a/otherlibs/labltk/browser/jg_toplevel.ml b/otherlibs/labltk/browser/jg_toplevel.ml new file mode 100644 index 0000000..792699c --- /dev/null +++ b/otherlibs/labltk/browser/jg_toplevel.ml @@ -0,0 +1,25 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: jg_toplevel.ml,v 1.8 2001-12-07 13:40:00 xleroy Exp $ *) + +open Tk + +let titled ?iconname title = + let iconname = match iconname with None -> title | Some s -> s in + let tl = Toplevel.create Widget.default_toplevel in + Wm.title_set tl title; + Wm.iconname_set tl iconname; + Wm.group_set tl ~leader: Widget.default_toplevel; + tl diff --git a/otherlibs/labltk/browser/jglib.mllib b/otherlibs/labltk/browser/jglib.mllib new file mode 100644 index 0000000..5c254ff --- /dev/null +++ b/otherlibs/labltk/browser/jglib.mllib @@ -0,0 +1,13 @@ +Jg_tk +Jg_config +Jg_bind +Jg_completion +Jg_box +Jg_button +Jg_toplevel +Jg_text +Jg_message +Jg_menu +Jg_entry +Jg_multibox +Jg_memo diff --git a/otherlibs/labltk/browser/lexical.ml b/otherlibs/labltk/browser/lexical.ml new file mode 100644 index 0000000..66fae75 --- /dev/null +++ b/otherlibs/labltk/browser/lexical.ml @@ -0,0 +1,143 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: lexical.ml,v 1.15 2002-11-01 17:06:45 doligez Exp $ *) + +open StdLabels +open Tk +open Jg_tk +open Parser + +let tags = + ["control"; "define"; "structure"; "char"; + "infix"; "label"; "uident"] +and colors = + ["blue"; "forestgreen"; "purple"; "gray40"; + "indianred4"; "saddlebrown"; "midnightblue"] + +let init_tags tw = + List.iter2 tags colors ~f: + begin fun tag col -> + Text.tag_configure tw ~tag ~foreground:(`Color col) + end; + Text.tag_configure tw ~tag:"error" ~foreground:`Red; + Text.tag_configure tw ~tag:"error" ~relief:`Raised; + Text.tag_raise tw ~tag:"error" + +let tag ?(start=tstart) ?(stop=tend) tw = + let tpos c = (Text.index tw ~index:start, [`Char c]) in + let text = Text.get tw ~start ~stop in + let buffer = Lexing.from_string text in + List.iter tags + ~f:(fun tag -> Text.tag_remove tw ~start ~stop ~tag); + let last = ref (EOF, 0, 0) in + try + while true do + let token = Lexer.token buffer + and start = Lexing.lexeme_start buffer + and stop = Lexing.lexeme_end buffer in + let tag = + match token with + AMPERAMPER + | AMPERSAND + | BARBAR + | DO | DONE + | DOWNTO + | ELSE + | FOR + | IF + | LAZY + | MATCH + | OR + | THEN + | TO + | TRY + | WHEN + | WHILE + | WITH + -> "control" + | AND + | AS + | BAR + | CLASS + | CONSTRAINT + | EXCEPTION + | EXTERNAL + | FUN + | FUNCTION + | FUNCTOR + | IN + | INHERIT + | INITIALIZER + | LET + | METHOD + | MODULE + | MUTABLE + | NEW + | OF + | PRIVATE + | REC + | TYPE + | VAL + | VIRTUAL + -> "define" + | BEGIN + | END + | INCLUDE + | OBJECT + | OPEN + | SIG + | STRUCT + -> "structure" + | CHAR _ + | STRING _ + -> "char" + | BACKQUOTE + | INFIXOP1 _ + | INFIXOP2 _ + | INFIXOP3 _ + | INFIXOP4 _ + | PREFIXOP _ + | SHARP + -> "infix" + | LABEL _ + | OPTLABEL _ + | QUESTION + | TILDE + -> "label" + | UIDENT _ -> "uident" + | LIDENT _ -> + begin match !last with + (QUESTION | TILDE), _, _ -> "label" + | _ -> "" + end + | COLON -> + begin match !last with + LIDENT _, lstart, lstop -> + if lstop = start then + Text.tag_add tw ~tag:"label" + ~start:(tpos lstart) ~stop:(tpos stop); + "" + | _ -> "" + end + | EOF -> raise End_of_file + | _ -> "" + in + if tag <> "" then + Text.tag_add tw ~tag ~start:(tpos start) ~stop:(tpos stop); + last := (token, start, stop) + done + with + End_of_file -> () + | Lexer.Error (err, loc) -> () diff --git a/otherlibs/labltk/browser/lexical.mli b/otherlibs/labltk/browser/lexical.mli new file mode 100644 index 0000000..c1c64cd --- /dev/null +++ b/otherlibs/labltk/browser/lexical.mli @@ -0,0 +1,20 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: lexical.mli,v 1.6 2001-12-07 13:40:00 xleroy Exp $ *) + +open Widget + +val init_tags : text widget -> unit +val tag : ?start:Tk.textIndex -> ?stop:Tk.textIndex -> text widget -> unit diff --git a/otherlibs/labltk/browser/list2.ml b/otherlibs/labltk/browser/list2.ml new file mode 100644 index 0000000..257ffff --- /dev/null +++ b/otherlibs/labltk/browser/list2.ml @@ -0,0 +1,23 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: list2.ml,v 1.9 2001-12-07 13:40:00 xleroy Exp $ *) + +open StdLabels + +let exclude x l = List.filter l ~f:((<>) x) + +let rec flat_map ~f = function + [] -> [] + | x :: l -> f x @ flat_map ~f l diff --git a/otherlibs/labltk/browser/main.ml b/otherlibs/labltk/browser/main.ml new file mode 100644 index 0000000..576be82 --- /dev/null +++ b/otherlibs/labltk/browser/main.ml @@ -0,0 +1,140 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: main.ml,v 1.34 2006-04-16 23:28:21 doligez Exp $ *) + +open StdLabels +module Unix = UnixLabels +open Tk + +let fatal_error text = + let top = openTk ~clas:"OCamlBrowser" () in + let mw = Message.create top ~text ~padx:20 ~pady:10 + ~width:400 ~justify:`Left ~aspect:400 ~anchor:`W + and b = Button.create top ~text:"OK" ~command:(fun () -> destroy top) in + pack [mw] ~side:`Top ~fill:`Both; + pack [b] ~side:`Bottom; + mainLoop (); + exit 0 + +let rec get_incr key = function + [] -> raise Not_found + | (k, c, d) :: rem -> + if k = key then + match c with Arg.Set _ | Arg.Clear _ | Arg.Unit _ -> false | _ -> true + else get_incr key rem + +let check ~spec argv = + let i = ref 1 in + while !i < Array.length argv do + try + let a = get_incr argv.(!i) spec in + incr i; if a then incr i + with Not_found -> + i := Array.length argv + 1 + done; + !i = Array.length argv + +open Printf + +let print_version () = + printf "The Objective Caml browser, version %s\n" Sys.ocaml_version; + exit 0; +;; + +let usage ~spec errmsg = + let b = Buffer.create 1024 in + bprintf b "%s\n" errmsg; + List.iter (function (key, _, doc) -> bprintf b " %s %s\n" key doc) spec; + Buffer.contents b + +let _ = + let is_win32 = Sys.os_type = "Win32" in + if is_win32 then + Format.pp_set_formatter_output_functions Format.err_formatter + (fun _ _ _ -> ()) (fun _ -> ()); + + let path = ref [] in + let st = ref true in + let spec = + [ "-I", Arg.String (fun s -> path := s :: !path), + "<dir> Add <dir> to the list of include directories"; + "-labels", Arg.Clear Clflags.classic, " <obsolete>"; + "-nolabels", Arg.Set Clflags.classic, + " Ignore non-optional labels in types"; + "-oldui", Arg.Clear st, " Revert back to old UI"; + "-pp", Arg.String (fun s -> Clflags.preprocessor := Some s), + "<command> Pipe sources through preprocessor <command>"; + "-rectypes", Arg.Set Clflags.recursive_types, + " Allow arbitrary recursive types"; + "-version", Arg.Unit print_version, + " Print version and exit"; + "-w", Arg.String (fun s -> Shell.warnings := s), + "<flags> Enable or disable warnings according to <flags>:\n\ + \032 A/a enable/disable all warnings\n\ + \032 C/c enable/disable suspicious comment\n\ + \032 D/d enable/disable deprecated features\n\ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ + \032 M/m enable/disable overriden method\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ + \032 V/v enable/disable hidden instance variable\n\ + \032 X/x enable/disable all other warnings\n\ + \032 default setting is \"Ale\"\n\ + \032 (all warnings but labels and fragile match enabled)"; ] + and errmsg = "Command line: ocamlbrowser <options>" in + if not (check ~spec Sys.argv) then fatal_error (usage ~spec errmsg); + Arg.parse spec + (fun name -> raise(Arg.Bad("don't know what to do with " ^ name))) + errmsg; + Config.load_path := + Sys.getcwd () + :: List.rev_map ~f:(Misc.expand_directory Config.standard_library) !path + @ [Config.standard_library]; + Warnings.parse_options false !Shell.warnings; + Unix.putenv "TERM" "noterminal"; + begin + try Searchid.start_env := Env.open_pers_signature "Pervasives" Env.initial + with _ -> + fatal_error + (Printf.sprintf "%s\nPlease check that %s %s\nCurrent value is `%s'" + "Couldn't initialize environment." + (if is_win32 then "%OCAMLLIB%" else "$OCAMLLIB") + "points to the Objective Caml library." + Config.standard_library) + end; + + Searchpos.view_defined_ref := (fun s ~env -> Viewer.view_defined s ~env); + Searchpos.editor_ref := Editor.f; + + let top = openTk ~clas:"OCamlBrowser" () in + Jg_config.init (); + + (* bind top ~events:[`Destroy] ~action:(fun _ -> exit 0); *) + at_exit Shell.kill_all; + + + if !st then Viewer.st_viewer ~on:top () + else Viewer.f ~on:top (); + + while true do + try + if is_win32 then mainLoop () + else Printexc.print mainLoop () + with Protocol.TkError _ -> + if not is_win32 then flush stderr + done diff --git a/otherlibs/labltk/browser/mytypes.mli b/otherlibs/labltk/browser/mytypes.mli new file mode 100644 index 0000000..249e5de --- /dev/null +++ b/otherlibs/labltk/browser/mytypes.mli @@ -0,0 +1,29 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: mytypes.mli,v 1.7 2007-05-16 08:21:40 doligez Exp $ *) + +open Widget + +type edit_window = + { mutable name: string; + tw: text widget; + frame: frame widget; + modified: Textvariable.textVariable; + mutable shell: (string * Shell.shell) option; + mutable structure: Typedtree.structure; + mutable type_info: Stypes.annotation list; + mutable signature: Types.signature; + mutable psignature: Parsetree.signature; + number: string } diff --git a/otherlibs/labltk/browser/searchid.ml b/otherlibs/labltk/browser/searchid.ml new file mode 100644 index 0000000..360dc3c --- /dev/null +++ b/otherlibs/labltk/browser/searchid.ml @@ -0,0 +1,533 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: searchid.ml,v 1.25 2008-07-09 14:03:08 mauny Exp $ *) + +open StdLabels +open Location +open Longident +open Path +open Types +open Typedtree +open Env +open Btype +open Ctype + +(* only initial here, but replaced by Pervasives later *) +let start_env = ref initial +let module_list = ref [] + +type pkind = + Pvalue + | Ptype + | Plabel + | Pconstructor + | Pmodule + | Pmodtype + | Pclass + | Pcltype + +let string_of_kind = function + Pvalue -> "v" + | Ptype -> "t" + | Plabel -> "l" + | Pconstructor -> "cn" + | Pmodule -> "m" + | Pmodtype -> "s" + | Pclass -> "c" + | Pcltype -> "ct" + +let rec longident_of_path = function + Pident id -> Lident (Ident.name id) + | Pdot (path, s, _) -> Ldot (longident_of_path path, s) + | Papply (p1, p2) -> Lapply (longident_of_path p1, longident_of_path p2) + +let rec remove_prefix lid ~prefix = + let rec remove_hd lid ~name = + match lid with + Ldot (Lident s1, s2) when s1 = name -> Lident s2 + | Ldot (l, s) -> Ldot (remove_hd ~name l, s) + | _ -> raise Not_found + in + match prefix with + [] -> lid + | name :: prefix -> + try remove_prefix ~prefix (remove_hd ~name lid) + with Not_found -> lid + +let rec permutations l = match l with + [] | [_] -> [l] + | [a;b] -> [l; [b;a]] + | _ -> + let _, perms = + List.fold_left l ~init:(l,[]) ~f: + begin fun (l, perms) a -> + let l = List.tl l in + l @ [a], + List.map (permutations l) ~f:(fun l -> a :: l) @ perms + end + in perms + +let rec choose n ~card:l = + let len = List.length l in + if n = len then [l] else + if n = 1 then List.map l ~f:(fun x -> [x]) else + if n = 0 then [[]] else + if n > len then [] else + match l with [] -> [] + | a :: l -> + List.map (choose (n-1) ~card:l) ~f:(fun l -> a :: l) + @ choose n ~card:l + +let rec arr p ~card:n = + if p = 0 then 1 else n * arr (p-1) ~card:(n-1) + +let rec all_args ty = + let ty = repr ty in + match ty.desc with + Tarrow(l, ty1, ty2, _) -> let (tl,ty) = all_args ty2 in ((l,ty1)::tl, ty) + | _ -> ([], ty) + +let rec equal ~prefix t1 t2 = + match (repr t1).desc, (repr t2).desc with + Tvar, Tvar -> true + | Tvariant row1, Tvariant row2 -> + let row1 = row_repr row1 and row2 = row_repr row2 in + let fields1 = filter_row_fields false row1.row_fields + and fields2 = filter_row_fields false row1.row_fields + in + let r1, r2, pairs = merge_row_fields fields1 fields2 in + row1.row_closed = row2.row_closed && r1 = [] && r2 = [] && + List.for_all pairs ~f: + begin fun (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent None, Rpresent None -> true + | Rpresent(Some t1), Rpresent (Some t2) -> equal t1 t2 ~prefix + | Reither(c1, tl1, _, _), Reither(c2, tl2, _, _) -> + c1 = c2 && List.length tl1 = List.length tl2 && + List.for_all2 tl1 tl2 ~f:(equal ~prefix) + | _ -> false + end + | Tarrow _, Tarrow _ -> + let l1, t1 = all_args t1 and l2, t2 = all_args t2 in + equal t1 t2 ~prefix && + List.length l1 = List.length l2 && + List.exists (permutations l1) ~f: + begin fun l1 -> + List.for_all2 l1 l2 ~f: + begin fun (p1,t1) (p2,t2) -> + (p1 = "" || p1 = p2) && equal t1 t2 ~prefix + end + end + | Ttuple l1, Ttuple l2 -> + List.length l1 = List.length l2 && + List.for_all2 l1 l2 ~f:(equal ~prefix) + | Tconstr (p1, l1, _), Tconstr (p2, l2, _) -> + remove_prefix ~prefix (longident_of_path p1) = (longident_of_path p2) + && List.length l1 = List.length l2 + && List.for_all2 l1 l2 ~f:(equal ~prefix) + | _ -> false + +let is_opt s = s <> "" && s.[0] = '?' +let get_options = List.filter ~f:is_opt + +let rec included ~prefix t1 t2 = + match (repr t1).desc, (repr t2).desc with + Tvar, _ -> true + | Tvariant row1, Tvariant row2 -> + let row1 = row_repr row1 and row2 = row_repr row2 in + let fields1 = filter_row_fields false row1.row_fields + and fields2 = filter_row_fields false row2.row_fields + in + let r1, r2, pairs = merge_row_fields fields1 fields2 in + r1 = [] && + List.for_all pairs ~f: + begin fun (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent None, Rpresent None -> true + | Rpresent(Some t1), Rpresent (Some t2) -> included t1 t2 ~prefix + | Reither(c1, tl1, _, _), Reither(c2, tl2, _, _) -> + c1 = c2 && List.length tl1 = List.length tl2 && + List.for_all2 tl1 tl2 ~f:(included ~prefix) + | _ -> false + end + | Tarrow _, Tarrow _ -> + let l1, t1 = all_args t1 and l2, t2 = all_args t2 in + included t1 t2 ~prefix && + let len1 = List.length l1 and len2 = List.length l2 in + let l2 = if arr len1 ~card:len2 < 100 then l2 else + let ll1 = get_options (fst (List.split l1)) in + List.filter l2 + ~f:(fun (l,_) -> not (is_opt l) || List.mem l ll1) + in + len1 <= len2 && + List.exists (List2.flat_map ~f:permutations (choose len1 ~card:l2)) ~f: + begin fun l2 -> + List.for_all2 l1 l2 ~f: + begin fun (p1,t1) (p2,t2) -> + (p1 = "" || p1 = p2) && included t1 t2 ~prefix + end + end + | Ttuple l1, Ttuple l2 -> + let len1 = List.length l1 in + len1 <= List.length l2 && + List.exists (List2.flat_map ~f:permutations (choose len1 ~card:l2)) ~f: + begin fun l2 -> + List.for_all2 l1 l2 ~f:(included ~prefix) + end + | _, Ttuple _ -> included (newty (Ttuple [t1])) t2 ~prefix + | Tconstr (p1, l1, _), Tconstr (p2, l2, _) -> + remove_prefix ~prefix (longident_of_path p1) = (longident_of_path p2) + && List.length l1 = List.length l2 + && List.for_all2 l1 l2 ~f:(included ~prefix) + | _ -> false + +let mklid = function + [] -> raise (Invalid_argument "Searchid.mklid") + | x :: l -> + List.fold_left l ~init:(Lident x) ~f:(fun acc x -> Ldot (acc, x)) + +let mkpath = function + [] -> raise (Invalid_argument "Searchid.mklid") + | x :: l -> + List.fold_left l ~init:(Pident (Ident.create x)) + ~f:(fun acc x -> Pdot (acc, x, 0)) + +let get_fields ~prefix ~sign self = + let env = open_signature (mkpath prefix) sign initial in + match (expand_head env self).desc with + Tobject (ty_obj, _) -> + let l,_ = flatten_fields ty_obj in l + | _ -> [] + +let rec search_type_in_signature t ~sign ~prefix ~mode = + let matches = match mode with + `Included -> included t ~prefix + | `Exact -> equal t ~prefix + and lid_of_id id = mklid (prefix @ [Ident.name id]) in + List2.flat_map sign ~f: + begin fun item -> match item with + Tsig_value (id, vd) -> + if matches vd.val_type then [lid_of_id id, Pvalue] else [] + | Tsig_type (id, td, _) -> + if + begin match td.type_manifest with + None -> false + | Some t -> matches t + end || + begin match td.type_kind with + Type_abstract -> false + | Type_variant l -> + List.exists l ~f:(fun (_, l) -> List.exists l ~f:matches) + | Type_record(l, rep) -> + List.exists l ~f:(fun (_, _, t) -> matches t) + end + then [lid_of_id id, Ptype] else [] + | Tsig_exception (id, l) -> + if List.exists l ~f:matches + then [lid_of_id id, Pconstructor] + else [] + | Tsig_module (id, Tmty_signature sign, _) -> + search_type_in_signature t ~sign ~mode + ~prefix:(prefix @ [Ident.name id]) + | Tsig_module _ -> [] + | Tsig_modtype _ -> [] + | Tsig_class (id, cl, _) -> + let self = self_type cl.cty_type in + if matches self + || (match cl.cty_new with None -> false | Some ty -> matches ty) + (* || List.exists (get_fields ~prefix ~sign self) + ~f:(fun (_,_,ty_field) -> matches ty_field) *) + then [lid_of_id id, Pclass] else [] + | Tsig_cltype (id, cl, _) -> + let self = self_type cl.clty_type in + if matches self + (* || List.exists (get_fields ~prefix ~sign self) + ~f:(fun (_,_,ty_field) -> matches ty_field) *) + then [lid_of_id id, Pclass] else [] + end + +let search_all_types t ~mode = + let tl = match mode, t.desc with + `Exact, _ -> [t] + | `Included, Tarrow _ -> [t] + | `Included, _ -> + [t; newty(Tarrow("",t,newvar(),Cok)); newty(Tarrow("",newvar(),t,Cok))] + in List2.flat_map !module_list ~f: + begin fun modname -> + let mlid = Lident modname in + try match lookup_module mlid initial with + _, Tmty_signature sign -> + List2.flat_map tl + ~f:(search_type_in_signature ~sign ~prefix:[modname] ~mode) + | _ -> [] + with Not_found | Env.Error _ -> [] + end + +exception Error of int * int + +let search_string_type text ~mode = + try + let sexp = Parse.interface (Lexing.from_string ("val z : " ^ text)) in + let sign = + try Typemod.transl_signature !start_env sexp with _ -> + let env = List.fold_left !module_list ~init:initial ~f: + begin fun acc m -> + try open_pers_signature m acc with Env.Error _ -> acc + end in + try Typemod.transl_signature env sexp + with Env.Error err -> [] + | Typemod.Error (l,_) -> + let start_c = l.loc_start.Lexing.pos_cnum in + let end_c = l.loc_end.Lexing.pos_cnum in + raise (Error (start_c - 8, end_c - 8)) + | Typetexp.Error (l,_) -> + let start_c = l.loc_start.Lexing.pos_cnum in + let end_c = l.loc_end.Lexing.pos_cnum in + raise (Error (start_c - 8, end_c - 8)) + in match sign with + [Tsig_value (_, vd)] -> + search_all_types vd.val_type ~mode + | _ -> [] + with + Syntaxerr.Error(Syntaxerr.Unclosed(l,_,_,_)) -> + let start_c = l.loc_start.Lexing.pos_cnum in + let end_c = l.loc_end.Lexing.pos_cnum in + raise (Error (start_c - 8, end_c - 8)) + | Syntaxerr.Error(Syntaxerr.Other l) -> + let start_c = l.loc_start.Lexing.pos_cnum in + let end_c = l.loc_end.Lexing.pos_cnum in + raise (Error (start_c - 8, end_c - 8)) + | Lexer.Error (_, l) -> + let start_c = l.loc_start.Lexing.pos_cnum in + let end_c = l.loc_end.Lexing.pos_cnum in + raise (Error (start_c - 8, end_c - 8)) + +let longident_of_string text = + let exploded = ref [] and l = ref 0 in + for i = 0 to String.length text - 2 do + if text.[i] ='.' then + (exploded := String.sub text ~pos:!l ~len:(i - !l) :: !exploded; l := i+1) + done; + let sym = String.sub text ~pos:!l ~len:(String.length text - !l) in + let rec mklid = function + [s] -> Lident s + | s :: l -> Ldot (mklid l, s) + | [] -> assert false in + sym, fun l -> mklid (sym :: !exploded @ l) + + +let explode s = + let l = ref [] in + for i = String.length s - 1 downto 0 do + l := s.[i] :: !l + done; !l + +let rec check_match ~pattern s = + match pattern, s with + [], [] -> true + | '*'::l, l' -> check_match ~pattern:l l' + || check_match ~pattern:('?'::'*'::l) l' + | '?'::l, _::l' -> check_match ~pattern:l l' + | x::l, y::l' when x == y -> check_match ~pattern:l l' + | _ -> false + +let search_pattern_symbol text = + if text = "" then [] else + let pattern = explode text in + let check i = check_match ~pattern (explode (Ident.name i)) in + let l = List.map !module_list ~f: + begin fun modname -> Lident modname, + try match lookup_module (Lident modname) initial with + _, Tmty_signature sign -> + List2.flat_map sign ~f: + begin function + Tsig_value (i, _) when check i -> [i, Pvalue] + | Tsig_type (i, _, _) when check i -> [i, Ptype] + | Tsig_exception (i, _) when check i -> [i, Pconstructor] + | Tsig_module (i, _, _) when check i -> [i, Pmodule] + | Tsig_modtype (i, _) when check i -> [i, Pmodtype] + | Tsig_class (i, cl, _) when check i + || List.exists + (get_fields ~prefix:[modname] ~sign (self_type cl.cty_type)) + ~f:(fun (name,_,_) -> check_match ~pattern (explode name)) + -> [i, Pclass] + | Tsig_cltype (i, cl, _) when check i + || List.exists + (get_fields ~prefix:[modname] ~sign (self_type cl.clty_type)) + ~f:(fun (name,_,_) -> check_match ~pattern (explode name)) + -> [i, Pcltype] + | _ -> [] + end + | _ -> [] + with Env.Error _ -> [] + end + in + List2.flat_map l ~f: + begin fun (m, l) -> + List.map l ~f:(fun (i, p) -> Ldot (m, Ident.name i), p) + end + +(* +let is_pattern s = + try for i = 0 to String.length s -1 do + if s.[i] = '?' || s.[i] = '*' then raise Exit + done; false + with Exit -> true +*) + +let search_string_symbol text = + if text = "" then [] else + let lid = snd (longident_of_string text) [] in + let try_lookup f k = + try let _ = f lid Env.initial in [lid, k] + with Not_found | Env.Error _ -> [] + in + try_lookup lookup_constructor Pconstructor @ + try_lookup lookup_module Pmodule @ + try_lookup lookup_modtype Pmodtype @ + try_lookup lookup_value Pvalue @ + try_lookup lookup_type Ptype @ + try_lookup lookup_label Plabel @ + try_lookup lookup_class Pclass + +open Parsetree + +let rec bound_variables pat = + match pat.ppat_desc with + Ppat_any | Ppat_constant _ | Ppat_type _ -> [] + | Ppat_var s -> [s] + | Ppat_alias (pat,s) -> s :: bound_variables pat + | Ppat_tuple l -> List2.flat_map l ~f:bound_variables + | Ppat_construct (_,None,_) -> [] + | Ppat_construct (_,Some pat,_) -> bound_variables pat + | Ppat_variant (_,None) -> [] + | Ppat_variant (_,Some pat) -> bound_variables pat + | Ppat_record l -> + List2.flat_map l ~f:(fun (_,pat) -> bound_variables pat) + | Ppat_array l -> + List2.flat_map l ~f:bound_variables + | Ppat_or (pat1,pat2) -> + bound_variables pat1 @ bound_variables pat2 + | Ppat_constraint (pat,_) -> bound_variables pat + | Ppat_lazy pat -> bound_variables pat + +let search_structure str ~name ~kind ~prefix = + let loc = ref 0 in + let rec search_module str ~prefix = + match prefix with [] -> str + | modu::prefix -> + let str = + List.fold_left ~init:[] str ~f: + begin fun acc item -> + match item.pstr_desc with + Pstr_module (s, mexp) when s = modu -> + loc := mexp.pmod_loc.loc_start.Lexing.pos_cnum; + begin match mexp.pmod_desc with + Pmod_structure str -> str + | _ -> [] + end + | _ -> acc + end + in search_module str ~prefix + in + List.iter (search_module str ~prefix) ~f: + begin fun item -> + if match item.pstr_desc with + Pstr_value (_, l) when kind = Pvalue -> + List.iter l ~f: + begin fun (pat,_) -> + if List.mem name (bound_variables pat) + then loc := pat.ppat_loc.loc_start.Lexing.pos_cnum + end; + false + | Pstr_primitive (s, _) when kind = Pvalue -> name = s + | Pstr_type l when kind = Ptype -> + List.iter l ~f: + begin fun (s, td) -> + if s = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum + end; + false + | Pstr_exception (s, _) when kind = Pconstructor -> name = s + | Pstr_module (s, _) when kind = Pmodule -> name = s + | Pstr_modtype (s, _) when kind = Pmodtype -> name = s + | Pstr_class l when kind = Pclass || kind = Ptype || kind = Pcltype -> + List.iter l ~f: + begin fun c -> + if c.pci_name = name + then loc := c.pci_loc.loc_start.Lexing.pos_cnum + end; + false + | Pstr_class_type l when kind = Pcltype || kind = Ptype -> + List.iter l ~f: + begin fun c -> + if c.pci_name = name + then loc := c.pci_loc.loc_start.Lexing.pos_cnum + end; + false + | _ -> false + then loc := item.pstr_loc.loc_start.Lexing.pos_cnum + end; + !loc + +let search_signature sign ~name ~kind ~prefix = + let loc = ref 0 in + let rec search_module_type sign ~prefix = + match prefix with [] -> sign + | modu::prefix -> + let sign = + List.fold_left ~init:[] sign ~f: + begin fun acc item -> + match item.psig_desc with + Psig_module (s, mtyp) when s = modu -> + loc := mtyp.pmty_loc.loc_start.Lexing.pos_cnum; + begin match mtyp.pmty_desc with + Pmty_signature sign -> sign + | _ -> [] + end + | _ -> acc + end + in search_module_type sign ~prefix + in + List.iter (search_module_type sign ~prefix) ~f: + begin fun item -> + if match item.psig_desc with + Psig_value (s, _) when kind = Pvalue -> name = s + | Psig_type l when kind = Ptype -> + List.iter l ~f: + begin fun (s, td) -> + if s = name then loc := td.ptype_loc.loc_start.Lexing.pos_cnum + end; + false + | Psig_exception (s, _) when kind = Pconstructor -> name = s + | Psig_module (s, _) when kind = Pmodule -> name = s + | Psig_modtype (s, _) when kind = Pmodtype -> name = s + | Psig_class l when kind = Pclass || kind = Ptype || kind = Pcltype -> + List.iter l ~f: + begin fun c -> + if c.pci_name = name + then loc := c.pci_loc.loc_start.Lexing.pos_cnum + end; + false + | Psig_class_type l when kind = Ptype || kind = Pcltype -> + List.iter l ~f: + begin fun c -> + if c.pci_name = name + then loc := c.pci_loc.loc_start.Lexing.pos_cnum + end; + false + | _ -> false + then loc := item.psig_loc.loc_start.Lexing.pos_cnum + end; + !loc diff --git a/otherlibs/labltk/browser/searchid.mli b/otherlibs/labltk/browser/searchid.mli new file mode 100644 index 0000000..38bbfb0 --- /dev/null +++ b/otherlibs/labltk/browser/searchid.mli @@ -0,0 +1,45 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: searchid.mli,v 1.6 2002-07-25 22:51:47 garrigue Exp $ *) + +val start_env : Env.t ref +val module_list : string list ref +val longident_of_path : Path.t ->Longident.t + +type pkind = + Pvalue + | Ptype + | Plabel + | Pconstructor + | Pmodule + | Pmodtype + | Pclass + | Pcltype + +val string_of_kind : pkind -> string + +exception Error of int * int + +val search_string_type : + string -> mode:[`Exact|`Included] -> (Longident.t * pkind) list +val search_pattern_symbol : string -> (Longident.t * pkind) list +val search_string_symbol : string -> (Longident.t * pkind) list + +val search_structure : + Parsetree.structure -> + name:string -> kind:pkind -> prefix:string list -> int +val search_signature : + Parsetree.signature -> + name:string -> kind:pkind -> prefix:string list -> int diff --git a/otherlibs/labltk/browser/searchpos.ml b/otherlibs/labltk/browser/searchpos.ml new file mode 100644 index 0000000..d859107 --- /dev/null +++ b/otherlibs/labltk/browser/searchpos.ml @@ -0,0 +1,882 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: searchpos.ml,v 1.52 2008-07-09 14:03:08 mauny Exp $ *) + +open StdLabels +open Support +open Tk +open Jg_tk +open Parsetree +open Types +open Typedtree +open Location +open Longident +open Path +open Env +open Searchid + +(* auxiliary functions *) + +let (~!) = Jg_memo.fast ~f:Str.regexp + +let lines_to_chars n ~text:s = + let l = String.length s in + let rec ltc n ~pos = + if n = 1 || pos >= l then pos else + if s.[pos] = '\n' then ltc (n-1) ~pos:(pos+1) else ltc n ~pos:(pos+1) + in ltc n ~pos:0 + +let in_loc loc ~pos = + loc.loc_ghost || pos >= loc.loc_start.Lexing.pos_cnum + && pos < loc.loc_end.Lexing.pos_cnum + +let le_loc loc1 loc2 = + loc1.loc_start.Lexing.pos_cnum <= loc2.loc_start.Lexing.pos_cnum + && loc1.loc_end.Lexing.pos_cnum >= loc2.loc_end.Lexing.pos_cnum + +let add_found ~found sol ~env ~loc = + if loc.loc_ghost then () else + if List.exists !found ~f:(fun (_,_,loc') -> le_loc loc loc') then () + else found := (sol, env, loc) :: + List.filter !found ~f:(fun (_,_,loc') -> not (le_loc loc' loc)) + +let observe ~ref ?init f x = + let old = !ref in + begin match init with None -> () | Some x -> ref := x end; + try (f x : unit); let v = !ref in ref := old; v + with exn -> ref := old; raise exn + +let rec string_of_longident = function + Lident s -> s + | Ldot (id,s) -> string_of_longident id ^ "." ^ s + | Lapply (id1, id2) -> + string_of_longident id1 ^ "(" ^ string_of_longident id2 ^ ")" + +let string_of_path p = string_of_longident (Searchid.longident_of_path p) + +let parent_path = function + Pdot (path, _, _) -> Some path + | Pident _ | Papply _ -> None + +let ident_of_path ~default = function + Pident i -> i + | Pdot (_, s, _) -> Ident.create s + | Papply _ -> Ident.create default + +let rec head_id = function + Pident id -> id + | Pdot (path,_,_) -> head_id path + | Papply (path,_) -> head_id path (* wrong, but ... *) + +let rec list_of_path = function + Pident id -> [Ident.name id] + | Pdot (path, s, _) -> list_of_path path @ [s] + | Papply (path, _) -> list_of_path path (* wrong, but ... *) + +(* a simple wrapper *) + +class buffer ~size = object + val buffer = Buffer.create size + method out buf = Buffer.add_substring buffer buf + method get = Buffer.contents buffer +end + +(* Search in a signature *) + +type skind = [`Type|`Class|`Module|`Modtype] + +let found_sig = ref ([] : ((skind * Longident.t) * Env.t * Location.t) list) +let add_found_sig = add_found ~found:found_sig + +let rec search_pos_type t ~pos ~env = + if in_loc ~pos t.ptyp_loc then + begin match t.ptyp_desc with + Ptyp_any + | Ptyp_var _ -> () + | Ptyp_variant(tl, _, _) -> + List.iter tl ~f: + begin function + Rtag (_,_,tl) -> List.iter tl ~f:(search_pos_type ~pos ~env) + | Rinherit st -> search_pos_type ~pos ~env st + end + | Ptyp_arrow (_, t1, t2) -> + search_pos_type t1 ~pos ~env; + search_pos_type t2 ~pos ~env + | Ptyp_tuple tl -> + List.iter tl ~f:(search_pos_type ~pos ~env) + | Ptyp_constr (lid, tl) -> + List.iter tl ~f:(search_pos_type ~pos ~env); + add_found_sig (`Type, lid) ~env ~loc:t.ptyp_loc + | Ptyp_object fl -> + List.iter fl ~f: + begin function + | {pfield_desc = Pfield (_, ty)} -> search_pos_type ty ~pos ~env + | _ -> () + end + | Ptyp_class (lid, tl, _) -> + List.iter tl ~f:(search_pos_type ~pos ~env); + add_found_sig (`Type, lid) ~env ~loc:t.ptyp_loc + | Ptyp_alias (t, _) + | Ptyp_poly (_, t) -> search_pos_type ~pos ~env t + end + +let rec search_pos_class_type cl ~pos ~env = + if in_loc cl.pcty_loc ~pos then + begin match cl.pcty_desc with + Pcty_constr (lid, _) -> + add_found_sig (`Class, lid) ~env ~loc:cl.pcty_loc + | Pcty_signature (_, cfl) -> + List.iter cfl ~f: + begin function + Pctf_inher cty -> search_pos_class_type cty ~pos ~env + | Pctf_val (_, _, _, ty, loc) -> + if in_loc loc ~pos then search_pos_type ty ~pos ~env + | Pctf_virt (_, _, ty, loc) -> + if in_loc loc ~pos then search_pos_type ty ~pos ~env + | Pctf_meth (_, _, ty, loc) -> + if in_loc loc ~pos then search_pos_type ty ~pos ~env + | Pctf_cstr (ty1, ty2, loc) -> + if in_loc loc ~pos then begin + search_pos_type ty1 ~pos ~env; + search_pos_type ty2 ~pos ~env + end + end + | Pcty_fun (_, ty, cty) -> + search_pos_type ty ~pos ~env; + search_pos_class_type cty ~pos ~env + end + +let search_pos_type_decl td ~pos ~env = + if in_loc ~pos td.ptype_loc then begin + begin match td.ptype_manifest with + Some t -> search_pos_type t ~pos ~env + | None -> () + end; + let rec search_tkind = function + Ptype_abstract -> () + | Ptype_variant dl -> + List.iter dl + ~f:(fun (_, tl, _) -> List.iter tl ~f:(search_pos_type ~pos ~env)) + | Ptype_record dl -> + List.iter dl ~f:(fun (_, _, t, _) -> search_pos_type t ~pos ~env) in + search_tkind td.ptype_kind; + List.iter td.ptype_cstrs ~f: + begin fun (t1, t2, _) -> + search_pos_type t1 ~pos ~env; + search_pos_type t2 ~pos ~env + end + end + +let rec search_pos_signature l ~pos ~env = + ignore ( + List.fold_left l ~init:env ~f: + begin fun env pt -> + let env = match pt.psig_desc with + Psig_open id -> + let path, mt = lookup_module id env in + begin match mt with + Tmty_signature sign -> open_signature path sign env + | _ -> env + end + | sign_item -> + try add_signature (Typemod.transl_signature env [pt]) env + with Typemod.Error _ | Typeclass.Error _ + | Typetexp.Error _ | Typedecl.Error _ -> env + in + if in_loc ~pos pt.psig_loc then + begin match pt.psig_desc with + Psig_value (_, desc) -> search_pos_type desc.pval_type ~pos ~env + | Psig_type l -> + List.iter l ~f:(fun (_,desc) -> search_pos_type_decl ~pos desc ~env) + | Psig_exception (_, l) -> + List.iter l ~f:(search_pos_type ~pos ~env); + add_found_sig (`Type, Lident "exn") ~env ~loc:pt.psig_loc + | Psig_module (_, t) -> + search_pos_module t ~pos ~env + | Psig_recmodule decls -> + List.iter decls ~f:(fun (_, t) -> search_pos_module t ~pos ~env) + | Psig_modtype (_, Pmodtype_manifest t) -> + search_pos_module t ~pos ~env + | Psig_modtype _ -> () + | Psig_class l -> + List.iter l + ~f:(fun ci -> search_pos_class_type ci.pci_expr ~pos ~env) + | Psig_class_type l -> + List.iter l + ~f:(fun ci -> search_pos_class_type ci.pci_expr ~pos ~env) + (* The last cases should not happen in generated interfaces *) + | Psig_open lid -> add_found_sig (`Module, lid) ~env ~loc:pt.psig_loc + | Psig_include t -> search_pos_module t ~pos ~env + end; + env + end) + +and search_pos_module m ~pos ~env = + if in_loc m.pmty_loc ~pos then begin + begin match m.pmty_desc with + Pmty_ident lid -> add_found_sig (`Modtype, lid) ~env ~loc:m.pmty_loc + | Pmty_signature sg -> search_pos_signature sg ~pos ~env + | Pmty_functor (_ , m1, m2) -> + search_pos_module m1 ~pos ~env; + search_pos_module m2 ~pos ~env + | Pmty_with (m, l) -> + search_pos_module m ~pos ~env; + List.iter l ~f: + begin function + _, Pwith_type t -> search_pos_type_decl t ~pos ~env + | _ -> () + end + end + end + +let search_pos_signature l ~pos ~env = + observe ~ref:found_sig (search_pos_signature ~pos ~env) l + +(* the module display machinery *) + +type module_widgets = + { mw_frame: Widget.frame Widget.widget; + mw_title: Widget.label Widget.widget option; + mw_detach: Widget.button Widget.widget; + mw_edit: Widget.button Widget.widget; + mw_intf: Widget.button Widget.widget } + +let shown_modules = Hashtbl.create 17 +let default_frame = ref None +let set_path = ref (fun _ ~sign -> assert false) +let filter_modules () = + Hashtbl.iter + (fun key data -> + if not (Winfo.exists data.mw_frame) then + Hashtbl.remove shown_modules key) + shown_modules +let add_shown_module path ~widgets = + Hashtbl.add shown_modules path widgets +let find_shown_module path = + try + filter_modules (); + Hashtbl.find shown_modules path + with Not_found -> + match !default_frame with + None -> raise Not_found + | Some mw -> mw + +let is_shown_module path = + !default_frame <> None || + (filter_modules (); Hashtbl.mem shown_modules path) + +(* Viewing a signature *) + +(* Forward definitions of Viewer.view_defined and Editor.editor *) +let view_defined_ref = ref (fun lid ~env -> ()) +let editor_ref = ref (fun ?file ?pos ?opendialog () -> ()) + +let edit_source ~file ~path ~sign = + match sign with + [item] -> + let id, kind = + match item with + Tsig_value (id, _) -> id, Pvalue + | Tsig_type (id, _, _) -> id, Ptype + | Tsig_exception (id, _) -> id, Pconstructor + | Tsig_module (id, _, _) -> id, Pmodule + | Tsig_modtype (id, _) -> id, Pmodtype + | Tsig_class (id, _, _) -> id, Pclass + | Tsig_cltype (id, _, _) -> id, Pcltype + in + let prefix = List.tl (list_of_path path) and name = Ident.name id in + let pos = + try + let chan = open_in file in + if Filename.check_suffix file ".ml" then + let parsed = Parse.implementation (Lexing.from_channel chan) in + close_in chan; + Searchid.search_structure parsed ~name ~kind ~prefix + else + let parsed = Parse.interface (Lexing.from_channel chan) in + close_in chan; + Searchid.search_signature parsed ~name ~kind ~prefix + with _ -> 0 + in !editor_ref ~file ~pos () + | _ -> !editor_ref ~file () + +(* List of windows to destroy by Close All *) +let top_widgets = ref [] + +let dummy_item = Tsig_modtype (Ident.create "dummy", Tmodtype_abstract) + +let rec view_signature ?title ?path ?(env = !start_env) ?(detach=false) sign = + let env = + match path with None -> env + | Some path -> Env.open_signature path sign env in + let title = + match title, path with Some title, _ -> title + | None, Some path -> string_of_path path + | None, None -> "Signature" + in + let tl, tw, finish = + try match path, !default_frame with + None, Some ({mw_title=Some label} as mw) when not detach -> + Button.configure mw.mw_detach + ~command:(fun () -> view_signature sign ~title ~env ~detach:true); + pack [mw.mw_detach] ~side:`Left; + Pack.forget [mw.mw_edit; mw.mw_intf]; + List.iter ~f:destroy (Winfo.children mw.mw_frame); + Label.configure label ~text:title; + pack [label] ~fill:`X ~side:`Bottom; + Jg_message.formatted ~title ~on:mw.mw_frame ~maxheight:15 () + | None, _ -> raise Not_found + | Some path, _ -> + let mw = + try find_shown_module path + with Not_found -> + view_module path ~env; + find_shown_module path + in + (try !set_path path ~sign with _ -> ()); + begin match mw.mw_title with None -> () + | Some label -> + Label.configure label ~text:title; + pack [label] ~fill:`X ~side:`Bottom + end; + Button.configure mw.mw_detach + ~command:(fun () -> view_signature sign ~title ~env ~detach:true); + pack [mw.mw_detach] ~side:`Left; + let repack = ref false in + List.iter2 [mw.mw_edit; mw.mw_intf] [".ml"; ".mli"] ~f: + begin fun button ext -> + try + let id = head_id path in + let file = + Misc.find_in_path_uncap !Config.load_path + ((Ident.name id) ^ ext) in + Button.configure button + ~command:(fun () -> edit_source ~file ~path ~sign); + if !repack then Pack.forget [button] else + if not (Winfo.viewable button) then repack := true; + pack [button] ~side:`Left + with Not_found -> + Pack.forget [button] + end; + let top = Winfo.toplevel mw.mw_frame in + if not (Winfo.ismapped top) then Wm.deiconify top; + List.iter ~f:destroy (Winfo.children mw.mw_frame); + Jg_message.formatted ~title ~on:mw.mw_frame ~maxheight:15 () + with Not_found -> + let tl, tw, finish = Jg_message.formatted ~title ~maxheight:15 () in + top_widgets := tl :: !top_widgets; + tl, tw, finish + in + Format.set_max_boxes 100; + Printtyp.signature Format.std_formatter sign; + finish (); + Lexical.init_tags tw; + Lexical.tag tw; + Text.configure tw ~state:`Disabled; + let text = Jg_text.get_all tw in + let pt = + try Parse.interface (Lexing.from_string text) + with Syntaxerr.Error e -> + let l = + match e with + Syntaxerr.Unclosed(l,_,_,_) -> l + | Syntaxerr.Other l -> l + in + Jg_text.tag_and_see tw ~start:(tpos l.loc_start.Lexing.pos_cnum) + ~stop:(tpos l.loc_end.Lexing.pos_cnum) ~tag:"error"; [] + | Lexer.Error (_, l) -> + let s = l.loc_start.Lexing.pos_cnum in + let e = l.loc_end.Lexing.pos_cnum in + Jg_text.tag_and_see tw ~start:(tpos s) ~stop:(tpos e) ~tag:"error"; [] + in + Jg_bind.enter_focus tw; + bind tw ~events:[`Modified([`Control], `KeyPressDetail"s")] + ~action:(fun _ -> Jg_text.search_string tw); + bind tw ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~fields:[`MouseX;`MouseY] ~breakable:true + ~action:(fun ev -> + let `Linechar (l, c) = + Text.index tw ~index:(`Atxy(ev.ev_MouseX,ev.ev_MouseY), []) in + try + match search_pos_signature pt ~pos:(lines_to_chars l ~text + c) ~env + with [] -> break () + | ((kind, lid), env, loc) :: _ -> view_decl lid ~kind ~env + with Not_found | Env.Error _ -> ()); + bind tw ~events:[`ButtonPressDetail 3] ~breakable:true + ~fields:[`MouseX;`MouseY] + ~action:(fun ev -> + let x = ev.ev_MouseX and y = ev.ev_MouseY in + let `Linechar (l, c) = + Text.index tw ~index:(`Atxy(x,y), []) in + try + match search_pos_signature pt ~pos:(lines_to_chars l ~text + c) ~env + with [] -> break () + | ((kind, lid), env, loc) :: _ -> + let menu = view_decl_menu lid ~kind ~env ~parent:tw in + let x = x + Winfo.rootx tw and y = y + Winfo.rooty tw - 10 in + Menu.popup menu ~x ~y + with Not_found -> ()) + +and view_signature_item sign ~path ~env = + view_signature sign ~title:(string_of_path path) + ?path:(parent_path path) ~env + +and view_module path ~env = + match find_module path env with + Tmty_signature sign -> + !view_defined_ref (Searchid.longident_of_path path) ~env + | modtype -> + let id = ident_of_path path ~default:"M" in + view_signature_item [Tsig_module (id, modtype, Trec_not)] ~path ~env + +and view_module_id id ~env = + let path, _ = lookup_module id env in + view_module path ~env + +and view_type_decl path ~env = + let td = find_type path env in + try match td.type_manifest with None -> raise Not_found + | Some ty -> match Ctype.repr ty with + {desc = Tobject _} -> + let clt = find_cltype path env in + view_signature_item ~path ~env + [Tsig_cltype(ident_of_path path ~default:"ct", clt, Trec_first); + dummy_item; dummy_item] + | _ -> raise Not_found + with Not_found -> + view_signature_item ~path ~env + [Tsig_type(ident_of_path path ~default:"t", td, Trec_first)] + +and view_type_id li ~env = + let path, decl = lookup_type li env in + view_type_decl path ~env + +and view_class_id li ~env = + let path, cl = lookup_class li env in + view_signature_item ~path ~env + [Tsig_class(ident_of_path path ~default:"c", cl, Trec_first); + dummy_item; dummy_item; dummy_item] + +and view_cltype_id li ~env = + let path, clt = lookup_cltype li env in + view_signature_item ~path ~env + [Tsig_cltype(ident_of_path path ~default:"ct", clt, Trec_first); + dummy_item; dummy_item] + +and view_modtype_id li ~env = + let path, td = lookup_modtype li env in + view_signature_item ~path ~env + [Tsig_modtype(ident_of_path path ~default:"S", td)] + +and view_expr_type ?title ?path ?env ?(name="noname") t = + let title = + match title, path with Some title, _ -> title + | None, Some path -> string_of_path path + | None, None -> "Expression type" + and path, id = + match path with None -> None, Ident.create name + | Some path -> parent_path path, ident_of_path path ~default:name + in + view_signature ~title ?path ?env + [Tsig_value (id, {val_type = t; val_kind = Val_reg})] + +and view_decl lid ~kind ~env = + match kind with + `Type -> view_type_id lid ~env + | `Class -> view_class_id lid ~env + | `Module -> view_module_id lid ~env + | `Modtype -> view_modtype_id lid ~env + +and view_decl_menu lid ~kind ~env ~parent = + let path, kname = + try match kind with + `Type -> fst (lookup_type lid env), "Type" + | `Class -> fst (lookup_class lid env), "Class" + | `Module -> fst (lookup_module lid env), "Module" + | `Modtype -> fst (lookup_modtype lid env), "Module type" + with Env.Error _ -> raise Not_found + in + let menu = Menu.create parent ~tearoff:false in + let label = kname ^ " " ^ string_of_path path in + begin match path with + Pident _ -> + Menu.add_command menu ~label ~state:`Disabled + | _ -> + Menu.add_command menu ~label + ~command:(fun () -> view_decl lid ~kind ~env); + end; + if kind = `Type || kind = `Modtype then begin + let buf = new buffer ~size:60 in + let (fo,ff) = Format.get_formatter_output_functions () + and margin = Format.get_margin () in + Format.set_formatter_output_functions buf#out (fun () -> ()); + Format.set_margin 60; + Format.open_hbox (); + if kind = `Type then + Printtyp.type_declaration + (ident_of_path path ~default:"t") + Format.std_formatter + (find_type path env) + else + Printtyp.modtype_declaration + (ident_of_path path ~default:"S") + Format.std_formatter + (find_modtype path env); + Format.close_box (); Format.print_flush (); + Format.set_formatter_output_functions fo ff; + Format.set_margin margin; + let l = Str.split ~!"\n" buf#get in + let font = + let font = + Option.get Widget.default_toplevel ~name:"font" ~clas:"Font" in + if font = "" then "7x14" else font + in + (* Menu.add_separator menu; *) + List.iter l + ~f:(fun label -> Menu.add_command menu ~label ~font ~state:`Disabled) + end; + menu + +(* search and view in a structure *) + +type fkind = [ + `Exp of + [`Expr|`Pat|`Const|`Val of Path.t|`Var of Path.t|`New of Path.t] + * Types.type_expr + | `Class of Path.t * Types.class_type + | `Module of Path.t * Types.module_type +] + +let view_type kind ~env = + match kind with + `Exp (k, ty) -> + begin match k with + `Expr -> view_expr_type ty ~title:"Expression type" ~env + | `Pat -> view_expr_type ty ~title:"Pattern type" ~env + | `Const -> view_expr_type ty ~title:"Constant type" ~env + | `Val path -> + begin try + let vd = find_value path env in + view_signature_item ~path ~env + [Tsig_value(ident_of_path path ~default:"v", vd)] + with Not_found -> + view_expr_type ty ~path ~env + end + | `Var path -> + let vd = find_value path env in + view_expr_type vd.val_type ~env ~path ~title:"Variable type" + | `New path -> + let cl = find_class path env in + view_signature_item ~path ~env + [Tsig_class(ident_of_path path ~default:"c", cl, Trec_first)] + end + | `Class (path, cty) -> + let cld = { cty_params = []; cty_variance = []; cty_type = cty; + cty_path = path; cty_new = None } in + view_signature_item ~path ~env + [Tsig_class(ident_of_path path ~default:"c", cld, Trec_first)] + | `Module (path, mty) -> + match mty with + Tmty_signature sign -> view_signature sign ~path ~env + | modtype -> + view_signature_item ~path ~env + [Tsig_module(ident_of_path path ~default:"M", mty, Trec_not)] + +let view_type_menu kind ~env ~parent = + let title = + match kind with + `Exp (`Expr,_) -> "Expression :" + | `Exp (`Pat, _) -> "Pattern :" + | `Exp (`Const, _) -> "Constant :" + | `Exp (`Val path, _) -> "Value " ^ string_of_path path ^ " :" + | `Exp (`Var path, _) -> + "Variable " ^ Ident.name (ident_of_path path ~default:"noname") ^ " :" + | `Exp (`New path, _) -> "Class " ^ string_of_path path ^ " :" + | `Class (path, _) -> "Class " ^ string_of_path path ^ " :" + | `Module (path,_) -> "Module " ^ string_of_path path in + let menu = Menu.create parent ~tearoff:false in + begin match kind with + `Exp((`Expr | `Pat | `Const | `Val (Pident _)),_) -> + Menu.add_command menu ~label:title ~state:`Disabled + | `Exp _ | `Class _ | `Module _ -> + Menu.add_command menu ~label:title + ~command:(fun () -> view_type kind ~env) + end; + begin match kind with `Module _ | `Class _ -> () + | `Exp(_, ty) -> + let buf = new buffer ~size:60 in + let (fo,ff) = Format.get_formatter_output_functions () + and margin = Format.get_margin () in + Format.set_formatter_output_functions buf#out ignore; + Format.set_margin 60; + Format.open_hbox (); + Printtyp.reset (); + Printtyp.mark_loops ty; + Printtyp.type_expr Format.std_formatter ty; + Format.close_box (); Format.print_flush (); + Format.set_formatter_output_functions fo ff; + Format.set_margin margin; + let l = Str.split ~!"\n" buf#get in + let font = + let font = + Option.get Widget.default_toplevel ~name:"font" ~clas:"Font" in + if font = "" then "7x14" else font + in + (* Menu.add_separator menu; *) + List.iter l ~f: + begin fun label -> match (Ctype.repr ty).desc with + Tconstr (path,_,_) -> + Menu.add_command menu ~label ~font + ~command:(fun () -> view_type_decl path ~env) + | Tvariant {row_name = Some (path, _)} -> + Menu.add_command menu ~label ~font + ~command:(fun () -> view_type_decl path ~env) + | _ -> + Menu.add_command menu ~label ~font ~state:`Disabled + end + end; + menu + +let found_str = ref ([] : (fkind * Env.t * Location.t) list) +let add_found_str = add_found ~found:found_str + +let rec search_pos_structure ~pos str = + List.iter str ~f: + begin function + Tstr_eval exp -> search_pos_expr exp ~pos + | Tstr_value (rec_flag, l) -> + List.iter l ~f: + begin fun (pat, exp) -> + let env = + if rec_flag = Asttypes.Recursive then exp.exp_env else Env.empty in + search_pos_pat pat ~pos ~env; + search_pos_expr exp ~pos + end + | Tstr_primitive (_, vd) ->() + | Tstr_type _ -> () + | Tstr_exception _ -> () + | Tstr_exn_rebind(_, _) -> () + | Tstr_module (_, m) -> search_pos_module_expr m ~pos + | Tstr_recmodule bindings -> + List.iter bindings ~f:(fun (_, m) -> search_pos_module_expr m ~pos) + | Tstr_modtype _ -> () + | Tstr_open _ -> () + | Tstr_class l -> + List.iter l ~f:(fun (id, _, _, cl, _) -> search_pos_class_expr cl ~pos) + | Tstr_cltype _ -> () + | Tstr_include (m, _) -> search_pos_module_expr m ~pos + end + +and search_pos_class_structure ~pos cls = + List.iter cls.cl_field ~f: + begin function + Cf_inher (cl, _, _) -> + search_pos_class_expr cl ~pos + | Cf_val (_, _, Some exp, _) -> search_pos_expr exp ~pos + | Cf_val _ -> () + | Cf_meth (_, exp) -> search_pos_expr exp ~pos + | Cf_let (_, pel, iel) -> + List.iter pel ~f: + begin fun (pat, exp) -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp ~pos + end; + List.iter iel ~f:(fun (_,exp) -> search_pos_expr exp ~pos) + | Cf_init exp -> search_pos_expr exp ~pos + end + +and search_pos_class_expr ~pos cl = + if in_loc cl.cl_loc ~pos then begin + begin match cl.cl_desc with + Tclass_ident path -> + add_found_str (`Class (path, cl.cl_type)) + ~env:!start_env ~loc:cl.cl_loc + | Tclass_structure cls -> + search_pos_class_structure ~pos cls + | Tclass_fun (pat, iel, cl, _) -> + search_pos_pat pat ~pos ~env:pat.pat_env; + List.iter iel ~f:(fun (_,exp) -> search_pos_expr exp ~pos); + search_pos_class_expr cl ~pos + | Tclass_apply (cl, el) -> + search_pos_class_expr cl ~pos; + List.iter el ~f:(fun (x,_) -> Misc.may (search_pos_expr ~pos) x) + | Tclass_let (_, pel, iel, cl) -> + List.iter pel ~f: + begin fun (pat, exp) -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp ~pos + end; + List.iter iel ~f:(fun (_,exp) -> search_pos_expr exp ~pos); + search_pos_class_expr cl ~pos + | Tclass_constraint (cl, _, _, _) -> + search_pos_class_expr cl ~pos + end; + add_found_str (`Class (Pident (Ident.create "c"), cl.cl_type)) + ~env:!start_env ~loc:cl.cl_loc + end + +and search_pos_expr ~pos exp = + if in_loc exp.exp_loc ~pos then begin + begin match exp.exp_desc with + Texp_ident (path, _) -> + add_found_str (`Exp(`Val path, exp.exp_type)) + ~env:exp.exp_env ~loc:exp.exp_loc + | Texp_constant v -> + add_found_str (`Exp(`Const, exp.exp_type)) + ~env:exp.exp_env ~loc:exp.exp_loc + | Texp_let (_, expl, exp) -> + List.iter expl ~f: + begin fun (pat, exp') -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp' ~pos + end; + search_pos_expr exp ~pos + | Texp_function (l, _) -> + List.iter l ~f: + begin fun (pat, exp) -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp ~pos + end + | Texp_apply (exp, l) -> + List.iter l ~f:(fun (x,_) -> Misc.may (search_pos_expr ~pos) x); + search_pos_expr exp ~pos + | Texp_match (exp, l, _) -> + search_pos_expr exp ~pos; + List.iter l ~f: + begin fun (pat, exp) -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp ~pos + end + | Texp_try (exp, l) -> + search_pos_expr exp ~pos; + List.iter l ~f: + begin fun (pat, exp) -> + search_pos_pat pat ~pos ~env:exp.exp_env; + search_pos_expr exp ~pos + end + | Texp_tuple l -> List.iter l ~f:(search_pos_expr ~pos) + | Texp_construct (_, l) -> List.iter l ~f:(search_pos_expr ~pos) + | Texp_variant (_, None) -> () + | Texp_variant (_, Some exp) -> search_pos_expr exp ~pos + | Texp_record (l, opt) -> + List.iter l ~f:(fun (_, exp) -> search_pos_expr exp ~pos); + (match opt with None -> () | Some exp -> search_pos_expr exp ~pos) + | Texp_field (exp, _) -> search_pos_expr exp ~pos + | Texp_setfield (a, _, b) -> + search_pos_expr a ~pos; search_pos_expr b ~pos + | Texp_array l -> List.iter l ~f:(search_pos_expr ~pos) + | Texp_ifthenelse (a, b, c) -> + search_pos_expr a ~pos; search_pos_expr b ~pos; + begin match c with None -> () + | Some exp -> search_pos_expr exp ~pos + end + | Texp_sequence (a,b) -> + search_pos_expr a ~pos; search_pos_expr b ~pos + | Texp_while (a,b) -> + search_pos_expr a ~pos; search_pos_expr b ~pos + | Texp_for (_, a, b, _, c) -> + List.iter [a;b;c] ~f:(search_pos_expr ~pos) + | Texp_when (a, b) -> + search_pos_expr a ~pos; search_pos_expr b ~pos + | Texp_send (exp, _) -> search_pos_expr exp ~pos + | Texp_new (path, _) -> + add_found_str (`Exp(`New path, exp.exp_type)) + ~env:exp.exp_env ~loc:exp.exp_loc + | Texp_instvar (_,path) -> + add_found_str (`Exp(`Var path, exp.exp_type)) + ~env:exp.exp_env ~loc:exp.exp_loc + | Texp_setinstvar (_, path, exp) -> + search_pos_expr exp ~pos; + add_found_str (`Exp(`Var path, exp.exp_type)) + ~env:exp.exp_env ~loc:exp.exp_loc + | Texp_override (_, l) -> + List.iter l ~f:(fun (_, exp) -> search_pos_expr exp ~pos) + | Texp_letmodule (id, modexp, exp) -> + search_pos_module_expr modexp ~pos; + search_pos_expr exp ~pos + | Texp_assertfalse -> () + | Texp_assert exp -> + search_pos_expr exp ~pos + | Texp_lazy exp -> + search_pos_expr exp ~pos + | Texp_object (cls, _, _) -> + search_pos_class_structure ~pos cls + end; + add_found_str (`Exp(`Expr, exp.exp_type)) ~env:exp.exp_env ~loc:exp.exp_loc + end + +and search_pos_pat ~pos ~env pat = + if in_loc pat.pat_loc ~pos then begin + begin match pat.pat_desc with + Tpat_any -> () + | Tpat_var id -> + add_found_str (`Exp(`Val (Pident id), pat.pat_type)) + ~env ~loc:pat.pat_loc + | Tpat_alias (pat, _) -> search_pos_pat pat ~pos ~env + | Tpat_lazy pat -> search_pos_pat pat ~pos ~env + | Tpat_constant _ -> + add_found_str (`Exp(`Const, pat.pat_type)) ~env ~loc:pat.pat_loc + | Tpat_tuple l -> + List.iter l ~f:(search_pos_pat ~pos ~env) + | Tpat_construct (_, l) -> + List.iter l ~f:(search_pos_pat ~pos ~env) + | Tpat_variant (_, None, _) -> () + | Tpat_variant (_, Some pat, _) -> search_pos_pat pat ~pos ~env + | Tpat_record l -> + List.iter l ~f:(fun (_, pat) -> search_pos_pat pat ~pos ~env) + | Tpat_array l -> + List.iter l ~f:(search_pos_pat ~pos ~env) + | Tpat_or (a, b, None) -> + search_pos_pat a ~pos ~env; search_pos_pat b ~pos ~env + | Tpat_or (_, _, Some _) -> + () + end; + add_found_str (`Exp(`Pat, pat.pat_type)) ~env ~loc:pat.pat_loc + end + +and search_pos_module_expr ~pos m = + if in_loc m.mod_loc ~pos then begin + begin match m.mod_desc with + Tmod_ident path -> + add_found_str (`Module (path, m.mod_type)) + ~env:m.mod_env ~loc:m.mod_loc + | Tmod_structure str -> search_pos_structure str ~pos + | Tmod_functor (_, _, m) -> search_pos_module_expr m ~pos + | Tmod_apply (a, b, _) -> + search_pos_module_expr a ~pos; search_pos_module_expr b ~pos + | Tmod_constraint (m, _, _) -> search_pos_module_expr m ~pos + end; + add_found_str (`Module (Pident (Ident.create "M"), m.mod_type)) + ~env:m.mod_env ~loc:m.mod_loc + end + +let search_pos_structure ~pos str = + observe ~ref:found_str (search_pos_structure ~pos) str + +open Stypes + +let search_pos_ti ~pos = function + Ti_pat p -> search_pos_pat ~pos ~env:p.pat_env p + | Ti_expr e -> search_pos_expr ~pos e + | Ti_class c -> search_pos_class_expr ~pos c + | Ti_mod m -> search_pos_module_expr ~pos m + | _ -> () + +let rec search_pos_info ~pos = function + [] -> [] + | ti :: l -> + if in_loc ~pos (get_location ti) + then observe ~ref:found_str (search_pos_ti ~pos) ti + else search_pos_info ~pos l diff --git a/otherlibs/labltk/browser/searchpos.mli b/otherlibs/labltk/browser/searchpos.mli new file mode 100644 index 0000000..8030fd7 --- /dev/null +++ b/otherlibs/labltk/browser/searchpos.mli @@ -0,0 +1,78 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: searchpos.mli,v 1.13 2007-05-16 08:21:40 doligez Exp $ *) + +open Widget + +val top_widgets : any widget list ref + +type module_widgets = + { mw_frame: frame widget; + mw_title: label widget option; + mw_detach: button widget; + mw_edit: button widget; + mw_intf: button widget } + +val add_shown_module : Path.t -> widgets:module_widgets -> unit +val find_shown_module : Path.t -> module_widgets +val is_shown_module : Path.t -> bool +val default_frame : module_widgets option ref +val set_path : (Path.t -> sign:Types.signature -> unit) ref + +val view_defined_ref : (Longident.t -> env:Env.t -> unit) ref +val editor_ref : + (?file:string -> ?pos:int -> ?opendialog:bool -> unit -> unit) ref + +val view_signature : + ?title:string -> + ?path:Path.t -> ?env:Env.t -> ?detach:bool -> Types.signature -> unit +val view_signature_item : + Types.signature -> path:Path.t -> env:Env.t -> unit +val view_module_id : Longident.t -> env:Env.t -> unit +val view_type_id : Longident.t -> env:Env.t -> unit +val view_class_id : Longident.t -> env:Env.t -> unit +val view_cltype_id : Longident.t -> env:Env.t -> unit +val view_modtype_id : Longident.t -> env:Env.t -> unit +val view_type_decl : Path.t -> env:Env.t -> unit + +type skind = [`Type|`Class|`Module|`Modtype] +val search_pos_signature : + Parsetree.signature -> pos:int -> env:Env.t -> + ((skind * Longident.t) * Env.t * Location.t) list +val view_decl : Longident.t -> kind:skind -> env:Env.t -> unit +val view_decl_menu : + Longident.t -> + kind:skind -> env:Env.t -> parent:text widget -> menu widget + +type fkind = [ + `Exp of + [`Expr|`Pat|`Const|`Val of Path.t|`Var of Path.t|`New of Path.t] + * Types.type_expr + | `Class of Path.t * Types.class_type + | `Module of Path.t * Types.module_type +] +val search_pos_structure : + pos:int -> Typedtree.structure_item list -> + (fkind * Env.t * Location.t) list +val search_pos_info : + pos:int -> Stypes.annotation list -> (fkind * Env.t * Location.t) list +val view_type : fkind -> env:Env.t -> unit +val view_type_menu : fkind -> env:Env.t -> parent:'a widget -> menu widget + +val parent_path : Path.t -> Path.t option +val string_of_path : Path.t -> string +val string_of_longident : Longident.t -> string +val lines_to_chars : int -> text:string -> int + diff --git a/otherlibs/labltk/browser/setpath.ml b/otherlibs/labltk/browser/setpath.ml new file mode 100644 index 0000000..426ca85 --- /dev/null +++ b/otherlibs/labltk/browser/setpath.ml @@ -0,0 +1,162 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: setpath.ml,v 1.16 2002-04-26 12:15:34 furuse Exp $ *) + +open StdLabels +open Tk + +(* Listboxes *) + +let update_hooks = ref [] + +let add_update_hook f = update_hooks := f :: !update_hooks + +let exec_update_hooks () = + update_hooks := List.filter !update_hooks ~f: + begin fun f -> + try f (); true + with Protocol.TkError _ -> false + end + +let set_load_path l = + Config.load_path := l; + exec_update_hooks () + +let get_load_path () = !Config.load_path + +let renew_dirs box ~var ~dir = + Textvariable.set var dir; + Listbox.delete box ~first:(`Num 0) ~last:`End; + Listbox.insert box ~index:`End + ~texts:(Useunix.get_directories_in_files ~path:dir + (Useunix.get_files_in_directory dir)); + Jg_box.recenter box ~index:(`Num 0) + +let renew_path box = + Listbox.delete box ~first:(`Num 0) ~last:`End; + Listbox.insert box ~index:`End ~texts:!Config.load_path; + Jg_box.recenter box ~index:(`Num 0) + +let add_to_path ~dirs ?(base="") box = + let dirs = + if base = "" then dirs else + if dirs = [] then [base] else + List.map dirs ~f: + begin function + "." -> base + | ".." -> Filename.dirname base + | x -> Filename.concat base x + end + in + set_load_path + (dirs @ List.fold_left dirs ~init:(get_load_path ()) + ~f:(fun acc x -> List2.exclude x acc)) + +let remove_path box ~dirs = + set_load_path + (List.fold_left dirs ~init:(get_load_path ()) + ~f:(fun acc x -> List2.exclude x acc)) + +(* main function *) + +let f ~dir = + let current_dir = ref dir in + let tl = Jg_toplevel.titled "Edit Load Path" in + Jg_bind.escape_destroy tl; + let var_dir = Textvariable.create ~on:tl () in + let caplab = Label.create tl ~text:"Path" + and dir_name = Entry.create tl ~textvariable:var_dir + and browse = Frame.create tl in + let dirs = Frame.create browse + and path = Frame.create browse in + let dirframe, dirbox, dirsb = Jg_box.create_with_scrollbar dirs + and pathframe, pathbox, pathsb = Jg_box.create_with_scrollbar path + in + add_update_hook (fun () -> renew_path pathbox); + Listbox.configure pathbox ~width:40 ~selectmode:`Multiple; + Listbox.configure dirbox ~selectmode:`Multiple; + Jg_box.add_completion dirbox ~action: + begin fun index -> + begin match Listbox.get dirbox ~index with + "." -> () + | ".." -> current_dir := Filename.dirname !current_dir + | x -> current_dir := !current_dir ^ "/" ^ x + end; + renew_dirs dirbox ~var:var_dir ~dir:!current_dir; + Listbox.selection_clear dirbox ~first:(`Num 0) ~last:`End + end; + Jg_box.add_completion pathbox ~action: + begin fun index -> + current_dir := Listbox.get pathbox ~index; + renew_dirs dirbox ~var:var_dir ~dir:!current_dir + end; + + bind dir_name ~events:[`KeyPressDetail"Return"] + ~action:(fun _ -> + let dir = Textvariable.get var_dir in + if Useunix.is_directory dir then begin + current_dir := dir; + renew_dirs dirbox ~var:var_dir ~dir + end); + + (* Avoid space being used by the completion mechanism *) + let bind_space_toggle lb = + bind lb ~events:[`KeyPressDetail "space"] ~extend:true ~action:ignore in + bind_space_toggle dirbox; + bind_space_toggle pathbox; + + let add_paths _ = + add_to_path pathbox ~base:!current_dir + ~dirs:(List.map (Listbox.curselection dirbox) + ~f:(fun x -> Listbox.get dirbox ~index:x)); + Listbox.selection_clear dirbox ~first:(`Num 0) ~last:`End + and remove_paths _ = + remove_path pathbox + ~dirs:(List.map (Listbox.curselection pathbox) + ~f:(fun x -> Listbox.get pathbox ~index:x)) + in + bind dirbox ~events:[`KeyPressDetail "Insert"] ~action:add_paths; + bind pathbox ~events:[`KeyPressDetail "Delete"] ~action:remove_paths; + + let dirlab = Label.create dirs ~text:"Directories" + and pathlab = Label.create path ~text:"Load path" + and addbutton = Button.create dirs ~text:"Add to path" ~command:add_paths + and pathbuttons = Frame.create path in + let removebutton = + Button.create pathbuttons ~text:"Remove from path" ~command:remove_paths + and ok = + Jg_button.create_destroyer tl ~parent:pathbuttons + in + renew_dirs dirbox ~var:var_dir ~dir:!current_dir; + renew_path pathbox; + pack [dirsb] ~side:`Right ~fill:`Y; + pack [dirbox] ~side:`Left ~fill:`Y ~expand:true; + pack [pathsb] ~side:`Right ~fill:`Y; + pack [pathbox] ~side:`Left ~fill:`Both ~expand:true; + pack [dirlab] ~side:`Top ~anchor:`W ~padx:10; + pack [addbutton] ~side:`Bottom ~fill:`X; + pack [dirframe] ~fill:`Y ~expand:true; + pack [pathlab] ~side:`Top ~anchor:`W ~padx:10; + pack [removebutton; ok] ~side:`Left ~fill:`X ~expand:true; + pack [pathbuttons] ~fill:`X ~side:`Bottom; + pack [pathframe] ~fill:`Both ~expand:true; + pack [dirs] ~side:`Left ~fill:`Y; + pack [path] ~side:`Right ~fill:`Both ~expand:true; + pack [caplab] ~side:`Top ~anchor:`W ~padx:10; + pack [dir_name] ~side:`Top ~anchor:`W ~fill:`X; + pack [browse] ~side:`Bottom ~expand:true ~fill:`Both; + tl + +let set ~dir = ignore (f ~dir);; diff --git a/otherlibs/labltk/browser/setpath.mli b/otherlibs/labltk/browser/setpath.mli new file mode 100644 index 0000000..df18c7f --- /dev/null +++ b/otherlibs/labltk/browser/setpath.mli @@ -0,0 +1,25 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: setpath.mli,v 1.6 2001-12-07 13:40:02 xleroy Exp $ *) + +open Widget + +val add_update_hook : (unit -> unit) -> unit +val exec_update_hooks : unit -> unit + (* things to do when Config.load_path changes *) + +val set : dir:string -> unit +val f : dir:string -> toplevel widget + (* edit the load path *) diff --git a/otherlibs/labltk/browser/shell.ml b/otherlibs/labltk/browser/shell.ml new file mode 100644 index 0000000..57751b0 --- /dev/null +++ b/otherlibs/labltk/browser/shell.ml @@ -0,0 +1,365 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: shell.ml,v 1.41 2006-01-18 13:26:03 garrigue Exp $ *) + +open StdLabels +module Unix = UnixLabels +open Tk +open Jg_tk +open Dummy + +(* Here again, memoize regexps *) + +let (~!) = Jg_memo.fast ~f:Str.regexp + +(* Nice history class. May reuse *) + +class ['a] history () = object + val mutable history = ([] : 'a list) + val mutable count = 0 + method empty = history = [] + method add s = count <- 0; history <- s :: history + method previous = + let s = List.nth history count in + count <- (count + 1) mod List.length history; + s + method next = + let l = List.length history in + count <- (l + count - 1) mod l; + List.nth history ((l + count - 1) mod l) +end + +let dump_handle (h : Unix.file_descr) = + let obj = Obj.repr h in + if Obj.is_int obj || Obj.tag obj <> Obj.custom_tag then + invalid_arg "Shell.dump_handle"; + Nativeint.format "%x" (Obj.obj obj) + +(* The shell class. Now encapsulated *) + +let protect f x = try f x with _ -> () + +let is_win32 = Sys.os_type = "Win32" +let use_threads = is_win32 +let use_sigpipe = is_win32 + +class shell ~textw ~prog ~args ~env ~history = + let (in2,out1) = Unix.pipe () + and (in1,out2) = Unix.pipe () + and (err1,err2) = Unix.pipe () + and (sig2,sig1) = Unix.pipe () in +object (self) + val pid = + let env = + if use_sigpipe then + let sigdef = "CAMLSIGPIPE=" ^ dump_handle sig2 in + Array.append env [|sigdef|] + else env + in + Unix.create_process_env ~prog ~args ~env + ~stdin:in2 ~stdout:out2 ~stderr:err2 + val out = Unix.out_channel_of_descr out1 + val h : _ history = history + val mutable alive = true + val mutable reading = false + val ibuffer = Buffer.create 1024 + val imutex = Mutex.create () + val mutable ithreads = [] + method alive = alive + method kill = + if Winfo.exists textw then Text.configure textw ~state:`Disabled; + if alive then begin + alive <- false; + protect close_out out; + try + if use_sigpipe then ignore (Unix.write sig1 ~buf:"T" ~pos:0 ~len:1); + List.iter ~f:(protect Unix.close) [in1; err1; sig1; sig2]; + if not use_threads then begin + Fileevent.remove_fileinput ~fd:in1; + Fileevent.remove_fileinput ~fd:err1; + end; + if not use_sigpipe then begin + Unix.kill ~pid ~signal:Sys.sigkill; + ignore (Unix.waitpid ~mode:[] pid) + end + with _ -> () + end + method interrupt = + if alive then try + reading <- false; + if use_sigpipe then begin + ignore (Unix.write sig1 ~buf:"C" ~pos:0 ~len:1); + self#send " " + end else + Unix.kill ~pid ~signal:Sys.sigint + with Unix.Unix_error _ -> () + method send s = + if alive then try + output_string out s; + flush out + with Sys_error _ -> () + method private read ~fd ~len = + begin try + let buf = String.create len in + let len = Unix.read fd ~buf ~pos:0 ~len in + if len > 0 then begin + self#insert (String.sub buf ~pos:0 ~len); + Text.mark_set textw ~mark:"input" ~index:(`Mark"insert",[`Char(-1)]) + end; + len + with Unix.Unix_error _ -> 0 + end; + method history (dir : [`Next|`Previous]) = + if not h#empty then begin + if reading then begin + Text.delete textw ~start:(`Mark"input",[`Char 1]) + ~stop:(`Mark"insert",[]) + end else begin + reading <- true; + Text.mark_set textw ~mark:"input" + ~index:(`Mark"insert",[`Char(-1)]) + end; + self#insert (if dir = `Previous then h#previous else h#next) + end + method private lex ?(start = `Mark"insert",[`Linestart]) + ?(stop = `Mark"insert",[`Lineend]) () = + Lexical.tag textw ~start ~stop + method insert text = + let idx = Text.index textw + ~index:(`Mark"insert",[`Char(-1);`Linestart]) in + Text.insert textw ~text ~index:(`Mark"insert",[]); + self#lex ~start:(idx,[`Linestart]) (); + Text.see textw ~index:(`Mark"insert",[]) + method private keypress c = + if not reading && c > " " then begin + reading <- true; + Text.mark_set textw ~mark:"input" ~index:(`Mark"insert",[`Char(-1)]) + end + method private keyrelease c = if c <> "" then self#lex () + method private return = + if reading then reading <- false + else Text.mark_set textw ~mark:"input" + ~index:(`Mark"insert",[`Linestart;`Char 1]); + Text.mark_set textw ~mark:"insert" ~index:(`Mark"insert",[`Lineend]); + self#lex ~start:(`Mark"input",[`Linestart]) (); + let s = + (* input is one character before real input *) + Text.get textw ~start:(`Mark"input",[`Char 1]) + ~stop:(`Mark"insert",[]) in + h#add s; + Text.insert textw ~index:(`Mark"insert",[]) ~text:"\n"; + Text.yview_index textw ~index:(`Mark"insert",[]); + self#send s; + self#send "\n" + method private paste ev = + if not reading then begin + reading <- true; + Text.mark_set textw ~mark:"input" + ~index:(`Atxy(ev.ev_MouseX, ev.ev_MouseY),[`Char(-1)]) + end + initializer + Lexical.init_tags textw; + let rec bindings = + [ ([], `KeyPress, [`Char], fun ev -> self#keypress ev.ev_Char); + ([], `KeyRelease, [`Char], fun ev -> self#keyrelease ev.ev_Char); + (* [], `KeyPressDetail"Return", [], fun _ -> self#return; *) + ([], `ButtonPressDetail 2, [`MouseX; `MouseY], self#paste); + ([`Alt], `KeyPressDetail"p", [], fun _ -> self#history `Previous); + ([`Alt], `KeyPressDetail"n", [], fun _ -> self#history `Next); + ([`Meta], `KeyPressDetail"p", [], fun _ -> self#history `Previous); + ([`Meta], `KeyPressDetail"n", [], fun _ -> self#history `Next); + ([`Control], `KeyPressDetail"c", [], fun _ -> self#interrupt); + ([], `Destroy, [], fun _ -> self#kill) ] + in + List.iter bindings ~f: + begin fun (modif,event,fields,action) -> + bind textw ~events:[`Modified(modif,event)] ~fields ~action + end; + bind textw ~events:[`KeyPressDetail"Return"] ~breakable:true + ~action:(fun _ -> self#return; break()); + List.iter ~f:Unix.close [in2;out2;err2]; + if use_threads then begin + let fileinput_thread fd = + let buf = String.create 1024 in + let len = ref 0 in + try while len := Unix.read fd ~buf ~pos:0 ~len:1024; !len > 0 do + Mutex.lock imutex; + Buffer.add_substring ibuffer buf 0 !len; + Mutex.unlock imutex + done with Unix.Unix_error _ -> () + in + ithreads <- List.map [in1; err1] ~f:(Thread.create fileinput_thread); + let rec read_buffer () = + Mutex.lock imutex; + if Buffer.length ibuffer > 0 then begin + self#insert (Str.global_replace ~!"\r\n" "\n" + (Buffer.contents ibuffer)); + Buffer.reset ibuffer; + Text.mark_set textw ~mark:"input" ~index:(`Mark"insert",[`Char(-1)]) + end; + Mutex.unlock imutex; + Timer.set ~ms:100 ~callback:read_buffer + in + read_buffer () + end else begin + try + List.iter [in1;err1] ~f: + begin fun fd -> + Fileevent.add_fileinput ~fd + ~callback:(fun () -> ignore (self#read ~fd ~len:1024)) + end + with _ -> () + end +end + +(* Specific use of shell, for OCamlBrowser *) + +let shells : (string * shell) list ref = ref [] + +(* Called before exiting *) +let kill_all () = + List.iter !shells ~f:(fun (_,sh) -> if sh#alive then sh#kill); + shells := [] + +let get_all () = + let all = List.filter !shells ~f:(fun (_,sh) -> sh#alive) in + shells := all; + all + +let may_exec_unix prog = + try Unix.access prog ~perm:[Unix.X_OK]; prog + with Unix.Unix_error _ -> "" + +let may_exec_win prog = + let has_ext = + List.exists ~f:(Filename.check_suffix prog) ["exe"; "com"; "bat"] in + if has_ext then may_exec_unix prog else + List.fold_left [prog^".bat"; prog^".exe"; prog^".com"] ~init:"" + ~f:(fun res prog -> if res = "" then may_exec_unix prog else res) + +let may_exec = + if is_win32 then may_exec_win else may_exec_unix + +let path_sep = if is_win32 then ";" else ":" + +let warnings = ref "Al" + +let program_not_found prog = + Jg_message.info ~title:"Error" + ("Program \"" ^ prog ^ "\"\nwas not found in path") + +let protect_arg s = + if String.contains s ' ' then "\"" ^ s ^ "\"" else s + +let f ~prog ~title = + let progargs = + List.filter ~f:((<>) "") (Str.split ~!" " prog) in + if progargs = [] then () else + let prog = List.hd progargs in + let path = + try Sys.getenv "PATH" with Not_found -> "/bin" ^ path_sep ^ "/usr/bin" in + let exec_path = Str.split ~!path_sep path in + let exec_path = if is_win32 then "."::exec_path else exec_path in + let progpath = + if not (Filename.is_implicit prog) then may_exec prog else + List.fold_left exec_path ~init:"" ~f: + (fun res dir -> + if res = "" then may_exec (Filename.concat dir prog) else res) in + if progpath = "" then program_not_found prog else + let tl = Jg_toplevel.titled title in + let menus = Menu.create tl ~name:"menubar" ~typ:`Menubar in + Toplevel.configure tl ~menu:menus; + let file_menu = new Jg_menu.c "File" ~parent:menus + and history_menu = new Jg_menu.c "History" ~parent:menus + and signal_menu = new Jg_menu.c "Signal" ~parent:menus in + let frame, tw, sb = Jg_text.create_with_scrollbar tl in + Text.configure tw ~background:`White; + pack [sb] ~fill:`Y ~side:`Right; + pack [tw] ~fill:`Both ~expand:true ~side:`Left; + pack [frame] ~fill:`Both ~expand:true; + let env = Array.map (Unix.environment ()) ~f: + begin fun s -> + if Str.string_match ~!"TERM=" s 0 then "TERM=dumb" else s + end in + let load_path = + List2.flat_map !Config.load_path ~f:(fun dir -> ["-I"; dir]) in + let load_path = + if is_win32 then List.map ~f:protect_arg load_path else load_path in + let labels = if !Clflags.classic then ["-nolabels"] else [] in + let rectypes = if !Clflags.recursive_types then ["-rectypes"] else [] in + let warnings = + if List.mem "-w" progargs || !warnings = "Al" then [] + else ["-w"; !warnings] + in + let args = + Array.of_list (progargs @ labels @ warnings @ rectypes @ load_path) in + let history = new history () in + let start_shell () = + let sh = new shell ~textw:tw ~prog:progpath ~env ~args ~history in + shells := (title, sh) :: !shells; + sh + in + let sh = ref (start_shell ()) in + let current_dir = ref (Unix.getcwd ()) in + file_menu#add_command "Restart" ~command: + begin fun () -> + (!sh)#kill; + Text.configure tw ~state:`Normal; + Text.insert tw ~index:(`End,[]) ~text:"\n"; + Text.see tw ~index:(`End,[]); + Text.mark_set tw ~mark:"insert" ~index:(`End,[]); + sh := start_shell (); + end; + file_menu#add_command "Use..." ~command: + begin fun () -> + Fileselect.f ~title:"Use File" ~filter:"*.ml" + ~sync:true ~dir:!current_dir () + ~action:(fun l -> + if l = [] then () else + let name = Fileselect.caml_dir (List.hd l) in + current_dir := Filename.dirname name; + if Filename.check_suffix name ".ml" + then + let cmd = "#use \"" ^ String.escaped name ^ "\";;\n" in + (!sh)#insert cmd; (!sh)#send cmd) + end; + file_menu#add_command "Load..." ~command: + begin fun () -> + Fileselect.f ~title:"Load File" ~filter:"*.cm[oa]" ~sync:true () + ~dir:!current_dir + ~action:(fun l -> + if l = [] then () else + let name = Fileselect.caml_dir (List.hd l) in + current_dir := Filename.dirname name; + if Filename.check_suffix name ".cmo" || + Filename.check_suffix name ".cma" + then + let cmd = "#load \"" ^ String.escaped name ^ "\";;\n" in + (!sh)#insert cmd; (!sh)#send cmd) + end; + file_menu#add_command "Import path" ~command: + begin fun () -> + List.iter (List.rev !Config.load_path) ~f: + (fun dir -> + (!sh)#send ("#directory \"" ^ String.escaped dir ^ "\";;\n")) + end; + file_menu#add_command "Close" ~command:(fun () -> destroy tl); + history_menu#add_command "Previous " ~accelerator:"M-p" + ~command:(fun () -> (!sh)#history `Previous); + history_menu#add_command "Next" ~accelerator:"M-n" + ~command:(fun () -> (!sh)#history `Next); + signal_menu#add_command "Interrupt " ~accelerator:"C-c" + ~command:(fun () -> (!sh)#interrupt); + signal_menu#add_command "Kill" ~command:(fun () -> (!sh)#kill) diff --git a/otherlibs/labltk/browser/shell.mli b/otherlibs/labltk/browser/shell.mli new file mode 100644 index 0000000..68e83e7 --- /dev/null +++ b/otherlibs/labltk/browser/shell.mli @@ -0,0 +1,46 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: shell.mli,v 1.8 2002-07-25 22:51:47 garrigue Exp $ *) + +class ['a] history : + unit -> + object + val mutable count : int + val mutable history : 'a list + method add : 'a -> unit + method empty : bool + method next : 'a + method previous : 'a + end + +(* toplevel shell *) + +class shell : + textw:Widget.text Widget.widget -> prog:string -> + args:string array -> env:string array -> history:string history -> + object + method alive : bool + method kill : unit + method interrupt : unit + method insert : string -> unit + method send : string -> unit + method history : [`Next|`Previous] -> unit + end + +val kill_all : unit -> unit +val get_all : unit -> (string * shell) list +val warnings : string ref + +val f : prog:string -> title:string -> unit diff --git a/otherlibs/labltk/browser/typecheck.ml b/otherlibs/labltk/browser/typecheck.ml new file mode 100644 index 0000000..feb20d7 --- /dev/null +++ b/otherlibs/labltk/browser/typecheck.ml @@ -0,0 +1,181 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: typecheck.ml,v 1.16 2007-05-16 08:21:40 doligez Exp $ *) + +open StdLabels +open Tk +open Parsetree +open Location +open Jg_tk +open Mytypes + +(* Optionally preprocess a source file *) + +let preprocess ~pp ~ext text = + let sourcefile = Filename.temp_file "caml" ext in + begin try + let oc = open_out_bin sourcefile in + output_string oc text; + flush oc; + close_out oc + with _ -> + failwith "Preprocessing error" + end; + let tmpfile = Filename.temp_file "camlpp" ext in + let comm = Printf.sprintf "%s %s > %s" pp sourcefile tmpfile in + if Ccomp.command comm <> 0 then begin + Sys.remove sourcefile; + Sys.remove tmpfile; + failwith "Preprocessing error" + end; + Sys.remove sourcefile; + tmpfile + +exception Outdated_version + +let parse_pp ~parse ~wrap ~ext text = + match !Clflags.preprocessor with + None -> parse (Lexing.from_string text) + | Some pp -> + let tmpfile = preprocess ~pp ~ext text in + let ast_magic = + if ext = ".ml" then Config.ast_impl_magic_number + else Config.ast_intf_magic_number in + let ic = open_in_bin tmpfile in + let ast = + try + let buffer = String.create (String.length ast_magic) in + really_input ic buffer 0 (String.length ast_magic); + if buffer = ast_magic then begin + ignore (input_value ic); + wrap (input_value ic) + end else if String.sub buffer 0 9 = String.sub ast_magic 0 9 then + raise Outdated_version + else + raise Exit + with + Outdated_version -> + close_in ic; + Sys.remove tmpfile; + failwith "Ocaml and preprocessor have incompatible versions" + | _ -> + seek_in ic 0; + parse (Lexing.from_channel ic) + in + close_in ic; + Sys.remove tmpfile; + ast + +let nowarnings = ref false + +let f txt = + let error_messages = ref [] in + let text = Jg_text.get_all txt.tw + and env = ref (Env.open_pers_signature "Pervasives" Env.initial) in + let tl, ew, end_message = + Jg_message.formatted ~title:"Warnings" ~ppf:Format.err_formatter () in + Text.tag_remove txt.tw ~tag:"error" ~start:tstart ~stop:tend; + txt.structure <- []; + txt.type_info <- []; + txt.signature <- []; + txt.psignature <- []; + ignore (Stypes.get_info ()); + Clflags.annotations := true; + + begin try + + if Filename.check_suffix txt.name ".mli" then + let psign = parse_pp text ~ext:".mli" + ~parse:Parse.interface ~wrap:(fun x -> x) in + txt.psignature <- psign; + txt.signature <- Typemod.transl_signature !env psign + + else (* others are interpreted as .ml *) + + let psl = parse_pp text ~ext:".ml" + ~parse:Parse.use_file ~wrap:(fun x -> [Parsetree.Ptop_def x]) in + List.iter psl ~f: + begin function + Ptop_def pstr -> + let str, sign, env' = Typemod.type_structure !env pstr Location.none in + txt.structure <- txt.structure @ str; + txt.signature <- txt.signature @ sign; + env := env' + | Ptop_dir _ -> () + end; + txt.type_info <- Stypes.get_info (); + + with + Lexer.Error _ | Syntaxerr.Error _ + | Typecore.Error _ | Typemod.Error _ + | Typeclass.Error _ | Typedecl.Error _ + | Typetexp.Error _ | Includemod.Error _ + | Env.Error _ | Ctype.Tags _ | Failure _ as exn -> + txt.type_info <- Stypes.get_info (); + let et, ew, end_message = Jg_message.formatted ~title:"Error !" () in + error_messages := et :: !error_messages; + let range = match exn with + Lexer.Error (err, l) -> + Lexer.report_error Format.std_formatter err; l + | Syntaxerr.Error err -> + Syntaxerr.report_error Format.std_formatter err; + begin match err with + Syntaxerr.Unclosed(l,_,_,_) -> l + | Syntaxerr.Other l -> l + end + | Typecore.Error (l,err) -> + Typecore.report_error Format.std_formatter err; l + | Typeclass.Error (l,err) -> + Typeclass.report_error Format.std_formatter err; l + | Typedecl.Error (l, err) -> + Typedecl.report_error Format.std_formatter err; l + | Typemod.Error (l,err) -> + Typemod.report_error Format.std_formatter err; l + | Typetexp.Error (l,err) -> + Typetexp.report_error Format.std_formatter err; l + | Includemod.Error errl -> + Includemod.report_error Format.std_formatter errl; Location.none + | Env.Error err -> + Env.report_error Format.std_formatter err; Location.none + | Ctype.Tags(l, l') -> + Format.printf "In this program,@ variant constructors@ `%s and `%s@ have same hash value.@." l l'; + Location.none + | Failure s -> + Format.printf "%s.@." s; Location.none + | _ -> assert false + in + end_message (); + let s = range.loc_start.Lexing.pos_cnum in + let e = range.loc_end.Lexing.pos_cnum in + if s < e then + Jg_text.tag_and_see txt.tw ~start:(tpos s) ~stop:(tpos e) ~tag:"error" + end; + end_message (); + if !nowarnings || Text.index ew ~index:tend = `Linechar (2,0) + then destroy tl + else begin + error_messages := tl :: !error_messages; + Text.configure ew ~state:`Disabled; + bind ew ~events:[`Modified([`Double], `ButtonReleaseDetail 1)] + ~action:(fun _ -> + try + let start, ende = Text.tag_nextrange ew ~tag:"sel" ~start:(tpos 0) in + let s = Text.get ew ~start:(start,[]) ~stop:(ende,[]) in + let n = int_of_string s in + Text.mark_set txt.tw ~index:(tpos n) ~mark:"insert"; + Text.see txt.tw ~index:(`Mark "insert", []) + with _ -> ()) + end; + !error_messages diff --git a/otherlibs/labltk/browser/typecheck.mli b/otherlibs/labltk/browser/typecheck.mli new file mode 100644 index 0000000..a7c17b5 --- /dev/null +++ b/otherlibs/labltk/browser/typecheck.mli @@ -0,0 +1,23 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: typecheck.mli,v 1.5 2001-12-07 13:40:02 xleroy Exp $ *) + +open Widget +open Mytypes + +val nowarnings : bool ref + +val f : edit_window -> any widget list + (* Typechecks the window as much as possible *) diff --git a/otherlibs/labltk/browser/useunix.ml b/otherlibs/labltk/browser/useunix.ml new file mode 100644 index 0000000..191b5f7 --- /dev/null +++ b/otherlibs/labltk/browser/useunix.ml @@ -0,0 +1,69 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: useunix.ml,v 1.13 2002-08-09 10:34:44 garrigue Exp $ *) + +open StdLabels +open UnixLabels + +let get_files_in_directory dir = + let len = String.length dir in + let dir = + if len > 0 && Sys.os_type = "Win32" && + (dir.[len-1] = '/' || dir.[len-1] = '\\') + then String.sub dir ~pos:0 ~len:(len-1) + else dir + in match + try Some(opendir dir) with Unix_error _ -> None + with + None -> [] + | Some dirh -> + let rec get_them l = + match + try Some(readdir dirh) with _ -> None + with + | Some x -> + get_them (x::l) + | None -> + closedir dirh; l + in + List.sort ~cmp:compare (get_them []) + +let is_directory name = + try + (stat name).st_kind = S_DIR + with _ -> false + +let concat dir name = + let len = String.length dir in + if len = 0 then name else + if dir.[len-1] = '/' then dir ^ name + else dir ^ "/" ^ name + +let get_directories_in_files ~path = + List.filter ~f:(fun x -> is_directory (concat path x)) + +(************************************************** Subshell call *) +let subshell ~cmd = + let rc = open_process_in cmd in + let rec it l = + match + try Some(input_line rc) with _ -> None + with + Some x -> it (x::l) + | None -> List.rev l + in + let answer = it [] in + ignore (close_process_in rc); + answer diff --git a/otherlibs/labltk/browser/useunix.mli b/otherlibs/labltk/browser/useunix.mli new file mode 100644 index 0000000..39455f4 --- /dev/null +++ b/otherlibs/labltk/browser/useunix.mli @@ -0,0 +1,23 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: useunix.mli,v 1.6 2002-08-09 10:34:44 garrigue Exp $ *) + +(* Unix utilities *) + +val get_files_in_directory : string -> string list +val is_directory : string -> bool +val concat : string -> string -> string +val get_directories_in_files : path:string -> string list -> string list +val subshell : cmd:string -> string list diff --git a/otherlibs/labltk/browser/viewer.ml b/otherlibs/labltk/browser/viewer.ml new file mode 100644 index 0000000..a1c8bdf --- /dev/null +++ b/otherlibs/labltk/browser/viewer.ml @@ -0,0 +1,631 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: viewer.ml,v 1.33 2006-01-04 16:55:50 doligez Exp $ *) + +open StdLabels +open Tk +open Jg_tk +open Mytypes +open Longident +open Types +open Typedtree +open Env +open Searchpos +open Searchid + +(* Managing the module list *) + +let list_modules ~path = + List.fold_left path ~init:[] ~f: + begin fun modules dir -> + let l = + List.filter (Useunix.get_files_in_directory dir) + ~f:(fun x -> Filename.check_suffix x ".cmi") in + let l = List.map l ~f: + begin fun x -> + String.capitalize (Filename.chop_suffix x ".cmi") + end in + List.fold_left l ~init:modules + ~f:(fun modules item -> + if List.mem item modules then modules else item :: modules) + end + +let reset_modules box = + Listbox.delete box ~first:(`Num 0) ~last:`End; + module_list := Sort.list (Jg_completion.lt_string ~nocase:true) + (list_modules ~path:!Config.load_path); + Listbox.insert box ~index:`End ~texts:!module_list; + Jg_box.recenter box ~index:(`Num 0) + + +(* How to display a symbol *) + +let view_symbol ~kind ~env ?path id = + let name = match id with + Lident x -> x + | Ldot (_, x) -> x + | _ -> match kind with Pvalue | Ptype | Plabel -> "z" | _ -> "Z" + in + match kind with + Pvalue -> + let path, vd = lookup_value id env in + view_signature_item ~path ~env [Tsig_value (Ident.create name, vd)] + | Ptype -> view_type_id id ~env + | Plabel -> let ld = lookup_label id env in + begin match ld.lbl_res.desc with + Tconstr (path, _, _) -> view_type_decl path ~env + | _ -> () + end + | Pconstructor -> + let cd = lookup_constructor id env in + begin match cd.cstr_res.desc with + Tconstr (cpath, _, _) -> + if Path.same cpath Predef.path_exn then + view_signature ~title:(string_of_longident id) ~env ?path + [Tsig_exception (Ident.create name, cd.cstr_args)] + else + view_type_decl cpath ~env + | _ -> () + end + | Pmodule -> view_module_id id ~env + | Pmodtype -> view_modtype_id id ~env + | Pclass -> view_class_id id ~env + | Pcltype -> view_cltype_id id ~env + + +(* Create a list of symbols you can choose from *) + +let choose_symbol ~title ~env ?signature ?path l = + if match path with + None -> false + | Some path -> is_shown_module path + then () else + let tl = Jg_toplevel.titled title in + Jg_bind.escape_destroy tl; + top_widgets := coe tl :: !top_widgets; + let buttons = Frame.create tl in + let all = Button.create buttons ~text:"Show all" ~padx:20 + and ok = Jg_button.create_destroyer tl ~parent:buttons + and detach = Button.create buttons ~text:"Detach" + and edit = Button.create buttons ~text:"Impl" + and intf = Button.create buttons ~text:"Intf" in + let l = List.sort l ~cmp:(fun (li1, _) (li2,_) -> compare li1 li2) in + let nl = List.map l ~f: + begin fun (li, k) -> + string_of_longident li ^ " (" ^ string_of_kind k ^ ")" + end in + let fb = Frame.create tl in + let box = + new Jg_multibox.c fb ~cols:3 ~texts:nl ~maxheight:3 ~width:21 in + box#init; + box#bind_kbd ~events:[`KeyPressDetail"Escape"] + ~action:(fun _ ~index -> destroy tl; break ()); + if List.length nl > 9 then ignore (Jg_multibox.add_scrollbar box); + Jg_multibox.add_completion box ~action: + begin fun pos -> + let li, k = List.nth l pos in + let path = + match path, li with + None, Ldot (lip, _) -> + begin try + Some (fst (lookup_module lip env)) + with Not_found -> None + end + | _ -> path + in view_symbol li ~kind:k ~env ?path + end; + pack [buttons] ~side:`Bottom ~fill:`X; + pack [fb] ~side:`Top ~fill:`Both ~expand:true; + begin match signature with + None -> pack [ok] ~fill:`X ~expand:true + | Some signature -> + Button.configure all ~command: + begin fun () -> + view_signature signature ~title ~env ?path + end; + pack [ok; all] ~side:`Right ~fill:`X ~expand:true + end; + begin match path with None -> () + | Some path -> + let frame = Frame.create tl in + pack [frame] ~side:`Bottom ~fill:`X; + add_shown_module path + ~widgets:{ mw_frame = frame; mw_title = None; mw_detach = detach; + mw_edit = edit; mw_intf = intf } + end + +let choose_symbol_ref = ref choose_symbol + + +(* Search, both by type and name *) + +let guess_search_mode s : [`Type | `Long | `Pattern] = + let is_type = ref false and is_long = ref false in + for i = 0 to String.length s - 2 do + if s.[i] = '-' && s.[i+1] = '>' then is_type := true; + if s.[i] = '.' then is_long := true + done; + if !is_type then `Type else if !is_long then `Long else `Pattern + + +let search_string ?(mode="symbol") ew = + let text = Entry.get ew in + try + if text = "" then () else + let l = match mode with + "Name" -> + begin match guess_search_mode text with + `Long -> search_string_symbol text + | `Pattern -> search_pattern_symbol text + | `Type -> search_string_type text ~mode:`Included + end + | "Type" -> search_string_type text ~mode:`Included + | "Exact" -> search_string_type text ~mode:`Exact + | _ -> assert false + in + match l with [] -> () + | [lid,kind] -> view_symbol lid ~kind ~env:!start_env + | l -> choose_symbol ~title:"Choose symbol" ~env:!start_env l + with Searchid.Error (s,e) -> + Entry.icursor ew ~index:(`Num s) + +let search_which = ref "Name" + +let search_symbol () = + if !module_list = [] then + module_list := List.sort ~cmp:compare (list_modules ~path:!Config.load_path); + let tl = Jg_toplevel.titled "Search symbol" in + Jg_bind.escape_destroy tl; + let ew = Entry.create tl ~width:30 in + let choice = Frame.create tl + and which = Textvariable.create ~on:tl () in + let itself = Radiobutton.create choice ~text:"Itself" + ~variable:which ~value:"Name" + and extype = Radiobutton.create choice ~text:"Exact type" + ~variable:which ~value:"Exact" + and iotype = Radiobutton.create choice ~text:"Included type" + ~variable:which ~value:"Type" + and buttons = Frame.create tl in + let search = Button.create buttons ~text:"Search" ~command: + begin fun () -> + search_which := Textvariable.get which; + search_string ew ~mode:!search_which + end + and ok = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" in + + Focus.set ew; + Jg_bind.return_invoke ew ~button:search; + Textvariable.set which !search_which; + pack [itself; extype; iotype] ~side:`Left ~anchor:`W; + pack [search; ok] ~side:`Left ~fill:`X ~expand:true; + pack [coe ew; coe choice; coe buttons] + ~side:`Top ~fill:`X ~expand:true + + +(* Display the contents of a module *) + +let ident_of_decl ~modlid = function + Tsig_value (id, _) -> Lident (Ident.name id), Pvalue + | Tsig_type (id, _, _) -> Lident (Ident.name id), Ptype + | Tsig_exception (id, _) -> Ldot (modlid, Ident.name id), Pconstructor + | Tsig_module (id, _, _) -> Lident (Ident.name id), Pmodule + | Tsig_modtype (id, _) -> Lident (Ident.name id), Pmodtype + | Tsig_class (id, _, _) -> Lident (Ident.name id), Pclass + | Tsig_cltype (id, _, _) -> Lident (Ident.name id), Pcltype + +let view_defined ~env ?(show_all=false) modlid = + try match lookup_module modlid env with path, Tmty_signature sign -> + let rec iter_sign sign idents = + match sign with + [] -> List.rev idents + | decl :: rem -> + let rem = match decl, rem with + Tsig_class _, cty :: ty1 :: ty2 :: rem -> rem + | Tsig_cltype _, ty1 :: ty2 :: rem -> rem + | _, rem -> rem + in iter_sign rem (ident_of_decl ~modlid decl :: idents) + in + let l = iter_sign sign [] in + let title = string_of_path path in + let env = open_signature path sign env in + !choose_symbol_ref l ~title ~signature:sign ~env ~path; + if show_all then view_signature sign ~title ~env ~path + | _ -> () + with Not_found -> () + | Env.Error err -> + let tl, tw, finish = Jg_message.formatted ~title:"Error!" () in + Env.report_error Format.std_formatter err; + finish () + + +(* Manage toplevel windows *) + +let close_all_views () = + List.iter !top_widgets + ~f:(fun tl -> try destroy tl with Protocol.TkError _ -> ()); + top_widgets := [] + + +(* Launch a shell *) + +let shell_counter = ref 1 +let default_shell = ref "ocaml" + +let start_shell master = + let tl = Jg_toplevel.titled "Start New Shell" in + Wm.transient_set tl ~master; + let input = Frame.create tl + and buttons = Frame.create tl in + let ok = Button.create buttons ~text:"Ok" + and cancel = Jg_button.create_destroyer tl ~parent:buttons ~text:"Cancel" + and labels = Frame.create input + and entries = Frame.create input in + let l1 = Label.create labels ~text:"Command:" + and l2 = Label.create labels ~text:"Title:" + and e1 = + Jg_entry.create entries ~command:(fun _ -> Button.invoke ok) + and e2 = + Jg_entry.create entries ~command:(fun _ -> Button.invoke ok) + and names = List.map ~f:fst (Shell.get_all ()) in + Entry.insert e1 ~index:`End ~text:!default_shell; + let shell_name () = "Shell #" ^ string_of_int !shell_counter in + while List.mem (shell_name ()) names do + incr shell_counter + done; + Entry.insert e2 ~index:`End ~text:(shell_name ()); + Button.configure ok ~command:(fun () -> + if not (List.mem (Entry.get e2) names) then begin + default_shell := Entry.get e1; + Shell.f ~prog:!default_shell ~title:(Entry.get e2); + destroy tl + end); + pack [l1;l2] ~side:`Top ~anchor:`W; + pack [e1;e2] ~side:`Top ~fill:`X ~expand:true; + pack [labels;entries] ~side:`Left ~fill:`X ~expand:true; + pack [ok;cancel] ~side:`Left ~fill:`X ~expand:true; + pack [input;buttons] ~side:`Top ~fill:`X ~expand:true + + +(* Help window *) + +let show_help () = + let tl = Jg_toplevel.titled "OCamlBrowser Help" in + Jg_bind.escape_destroy tl; + let fw, tw, sb = Jg_text.create_with_scrollbar tl in + let ok = Jg_button.create_destroyer ~parent:tl ~text:"Ok" tl in + Text.insert tw ~index:tend ~text:Help.text; + Text.configure tw ~state:`Disabled; + Jg_bind.enter_focus tw; + pack [tw] ~side:`Left ~fill:`Both ~expand:true; + pack [sb] ~side:`Right ~fill:`Y; + pack [fw] ~side:`Top ~expand:true ~fill:`Both; + pack [ok] ~side:`Bottom ~fill:`X + +(* Launch the classical viewer *) + +let f ?(dir=Unix.getcwd()) ?on () = + let (top, tl) = match on with + None -> + let tl = Jg_toplevel.titled "Module viewer" in + ignore (Jg_bind.escape_destroy tl); (tl, coe tl) + | Some top -> + Wm.title_set top "OCamlBrowser"; + Wm.iconname_set top "OCamlBrowser"; + let tl = Frame.create top in + bind tl ~events:[`Destroy] ~action:(fun _ -> exit 0); + pack [tl] ~expand:true ~fill:`Both; + (top, coe tl) + in + let menus = Jg_menu.menubar top in + let filemenu = new Jg_menu.c "File" ~parent:menus + and modmenu = new Jg_menu.c "Modules" ~parent:menus in + let fmbox, mbox, msb = Jg_box.create_with_scrollbar tl in + + Jg_box.add_completion mbox ~nocase:true ~action: + begin fun index -> + view_defined (Lident (Listbox.get mbox ~index)) ~env:!start_env + end; + Setpath.add_update_hook (fun () -> reset_modules mbox); + + let ew = Entry.create tl in + let buttons = Frame.create tl in + let search = Button.create buttons ~text:"Search" ~pady:1 + ~command:(fun () -> search_string ew) + and close = + Button.create buttons ~text:"Close all" ~pady:1 ~command:close_all_views + in + (* bindings *) + Jg_bind.enter_focus ew; + Jg_bind.return_invoke ew ~button:search; + bind close ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~action:(fun _ -> destroy tl); + + (* File menu *) + filemenu#add_command "Open..." + ~command:(fun () -> !editor_ref ~opendialog:true ()); + filemenu#add_command "Editor..." ~command:(fun () -> !editor_ref ()); + filemenu#add_command "Shell..." ~command:(fun () -> start_shell tl); + filemenu#add_command "Quit" ~command:(fun () -> destroy tl); + + (* modules menu *) + modmenu#add_command "Path editor..." + ~command:(fun () -> Setpath.set ~dir); + modmenu#add_command "Reset cache" + ~command:(fun () -> reset_modules mbox; Env.reset_cache ()); + modmenu#add_command "Search symbol..." ~command:search_symbol; + + pack [close; search] ~fill:`X ~side:`Right ~expand:true; + pack [coe buttons; coe ew] ~fill:`X ~side:`Bottom; + pack [msb] ~side:`Right ~fill:`Y; + pack [mbox] ~side:`Left ~fill:`Both ~expand:true; + pack [fmbox] ~fill:`Both ~expand:true ~side:`Top; + reset_modules mbox + +(* Smalltalk-like version *) + +class st_viewer ?(dir=Unix.getcwd()) ?on () = + let (top, tl) = match on with + None -> + let tl = Jg_toplevel.titled "Module viewer" in + ignore (Jg_bind.escape_destroy tl); (tl, coe tl) + | Some top -> + Wm.title_set top "OCamlBrowser"; + Wm.iconname_set top "OCamlBrowser"; + let tl = Frame.create top in + bind tl ~events:[`Destroy] ~action:(fun _ -> exit 0); + pack [tl] ~side:`Bottom ~expand:true ~fill:`Both; + (top, coe tl) + in + let menus = Menu.create top ~name:"menubar" ~typ:`Menubar in + let () = Toplevel.configure top ~menu:menus in + let filemenu = new Jg_menu.c "File" ~parent:menus + and modmenu = new Jg_menu.c "Modules" ~parent:menus + and viewmenu = new Jg_menu.c "View" ~parent:menus + and helpmenu = new Jg_menu.c "Help" ~parent:menus in + let search_frame = Frame.create tl in + let boxes_frame = Frame.create tl ~name:"boxes" in + let label = Label.create tl ~anchor:`W ~padx:5 in + let view = Frame.create tl in + let buttons = Frame.create tl in + let _all = Button.create buttons ~text:"Show all" ~padx:20 + and close = Button.create buttons ~text:"Close all" ~command:close_all_views + and detach = Button.create buttons ~text:"Detach" + and edit = Button.create buttons ~text:"Impl" + and intf = Button.create buttons ~text:"Intf" in +object (self) + val mutable boxes = [] + val mutable show_all = fun () -> () + + method create_box = + let fmbox, mbox, sb = Jg_box.create_with_scrollbar boxes_frame in + bind mbox ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~action:(fun _ -> show_all ()); + bind mbox ~events:[`Modified([`Double], `KeyPressDetail "Return")] + ~action:(fun _ -> show_all ()); + boxes <- boxes @ [fmbox, mbox]; + pack [sb] ~side:`Right ~fill:`Y; + pack [mbox] ~side:`Left ~fill:`Both ~expand:true; + pack [fmbox] ~side:`Left ~fill:`Both ~expand:true; + fmbox, mbox + + initializer + (* Search *) + let ew = Entry.create search_frame + and searchtype = Textvariable.create ~on:tl () in + bind ew ~events:[`KeyPressDetail "Return"] ~action: + (fun _ -> search_string ew ~mode:(Textvariable.get searchtype)); + Jg_bind.enter_focus ew; + let search_button ?value text = + Radiobutton.create search_frame + ~text ~variable:searchtype ~value:text in + let symbol = search_button "Name" + and atype = search_button "Type" in + Radiobutton.select symbol; + pack [Label.create search_frame ~text:"Search"] ~side:`Left ~ipadx:5; + pack [ew] ~fill:`X ~expand:true ~side:`Left; + pack [Label.create search_frame ~text:"by"] ~side:`Left ~ipadx:5; + pack [symbol; atype] ~side:`Left; + pack [Label.create search_frame] ~side:`Right + + initializer + (* Boxes *) + let fmbox, mbox = self#create_box in + Jg_box.add_completion mbox ~nocase:true ~double:false ~action: + begin fun index -> + view_defined (Lident (Listbox.get mbox ~index)) ~env:!start_env + end; + Setpath.add_update_hook (fun () -> reset_modules mbox; self#hide_after 1); + List.iter [1;2] ~f:(fun _ -> ignore self#create_box); + Searchpos.default_frame := Some + { mw_frame = view; mw_title = Some label; + mw_detach = detach; mw_edit = edit; mw_intf = intf }; + Searchpos.set_path := self#set_path; + + (* Buttons *) + pack [close] ~side:`Right ~fill:`X ~expand:true; + bind close ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~action:(fun _ -> destroy tl); + + (* File menu *) + filemenu#add_command "Open..." + ~command:(fun () -> !editor_ref ~opendialog:true ()); + filemenu#add_command "Editor..." ~command:(fun () -> !editor_ref ()); + filemenu#add_command "Shell..." ~command:(fun () -> start_shell tl); + filemenu#add_command "Quit" ~command:(fun () -> destroy tl); + + (* View menu *) + viewmenu#add_command "Show all defs" ~command:(fun () -> show_all ()); + let show_search = Textvariable.create ~on:tl () in + Textvariable.set show_search "1"; + Menu.add_checkbutton viewmenu#menu ~label:"Search Entry" + ~variable:show_search ~indicatoron:true ~state:`Active + ~command: + begin fun () -> + let v = Textvariable.get show_search in + if v = "1" then begin + pack [search_frame] ~after:menus ~fill:`X + end else Pack.forget [search_frame] + end; + + (* modules menu *) + modmenu#add_command "Path editor..." + ~command:(fun () -> Setpath.set ~dir); + modmenu#add_command "Reset cache" + ~command:(fun () -> reset_modules mbox; Env.reset_cache ()); + modmenu#add_command "Search symbol..." ~command:search_symbol; + + (* Help menu *) + helpmenu#add_command "Manual..." ~command:show_help; + + pack [search_frame] ~fill:`X; + pack [boxes_frame] ~fill:`Both ~expand:true; + pack [buttons] ~fill:`X ~side:`Bottom; + pack [view] ~fill:`Both ~side:`Bottom ~expand:true; + reset_modules mbox + + val mutable shown_paths = [] + + method hide_after n = + for i = n to List.length boxes - 1 do + let fm, box = List.nth boxes i in + if i < 3 then Listbox.delete box ~first:(`Num 0) ~last:`End + else destroy fm + done; + let rec firsts n = function [] -> [] + | a :: l -> if n > 0 then a :: firsts (pred n) l else [] in + shown_paths <- firsts (n-1) shown_paths; + boxes <- firsts (max 3 n) boxes + + method get_box ~path = + let rec path_index p = function + [] -> raise Not_found + | a :: l -> if Path.same p a then 1 else path_index p l + 1 in + try + let n = path_index path shown_paths in + self#hide_after (n+1); + n + with Not_found -> + match path with + Path.Pdot (path', _, _) -> + let n = self#get_box ~path:path' in + shown_paths <- shown_paths @ [path]; + if n + 1 >= List.length boxes then ignore self#create_box; + n+1 + | _ -> + self#hide_after 2; + shown_paths <- [path]; + 1 + + method set_path path ~sign = + let rec path_elems l path = + match path with + Path.Pdot (path, _, _) -> path_elems (path::l) path + | _ -> [] + in + let path_elems path = + match path with + | Path.Pident _ -> [path] + | _ -> path_elems [] path + in + let see_path ~box:n ?(sign=[]) path = + let (_, box) = List.nth boxes n in + let texts = Listbox.get_range box ~first:(`Num 0) ~last:`End in + let rec index s = function + [] -> raise Not_found + | a :: l -> if a = s then 0 else 1 + index s l + in + try + let modlid, s = + match path with + Path.Pdot (p, s, _) -> longident_of_path p, s + | Path.Pident i -> Longident.Lident "M", Ident.name i + | _ -> assert false + in + let li, k = + if sign = [] then Longident.Lident s, Pmodule else + ident_of_decl ~modlid (List.hd sign) in + let s = + if n = 0 then string_of_longident li else + string_of_longident li ^ " (" ^ string_of_kind k ^ ")" in + let n = index s texts in + Listbox.see box (`Num n); + Listbox.activate box (`Num n) + with Not_found -> () + in + let l = path_elems path in + if l <> [] then begin + List.iter l ~f: + begin fun path -> + if not (List.mem path shown_paths) then + view_symbol (longident_of_path path) ~kind:Pmodule + ~env:Env.initial ~path; + let n = self#get_box path - 1 in + see_path path ~box:n + end; + see_path path ~box:(self#get_box path) ~sign + end + + method choose_symbol ~title ~env ?signature ?path l = + let n = + match path with None -> 1 + | Some path -> self#get_box ~path + in + let l = List.sort l ~cmp:(fun (li1, _) (li2,_) -> compare li1 li2) in + let nl = List.map l ~f: + begin fun (li, k) -> + string_of_longident li ^ " (" ^ string_of_kind k ^ ")" + end in + let _, box = List.nth boxes n in + Listbox.delete box ~first:(`Num 0) ~last:`End; + Listbox.insert box ~index:`End ~texts:nl; + + let current = ref None in + let display index = + let `Num pos = Listbox.index box ~index in + try + let li, k = List.nth l pos in + self#hide_after (n+1); + if !current = Some (li,k) then () else + let path = + match path, li with + None, Ldot (lip, _) -> + begin try + Some (fst (lookup_module lip env)) + with Not_found -> None + end + | _ -> path + in + current := Some (li,k); + view_symbol li ~kind:k ~env ?path + with Failure "nth" -> () + in + Jg_box.add_completion box ~double:false ~action:display; + bind box ~events:[`KeyRelease] ~fields:[`Char] + ~action:(fun ev -> display `Active); + + begin match signature with + None -> () + | Some signature -> + show_all <- + begin fun () -> + current := None; + view_signature signature ~title ~env ?path + end + end +end + +let st_viewer ?dir ?on () = + let viewer = new st_viewer ?dir ?on () in + choose_symbol_ref := viewer#choose_symbol diff --git a/otherlibs/labltk/browser/viewer.mli b/otherlibs/labltk/browser/viewer.mli new file mode 100644 index 0000000..3c6ba78 --- /dev/null +++ b/otherlibs/labltk/browser/viewer.mli @@ -0,0 +1,31 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: viewer.mli,v 1.7 2002-07-11 13:49:51 garrigue Exp $ *) + +(* Module viewer *) +open Widget + +val search_symbol : unit -> unit + (* search a symbol in all modules in the path *) + +val f : ?dir:string -> ?on:toplevel widget -> unit -> unit + (* open then module viewer *) +val st_viewer : ?dir:string -> ?on:toplevel widget -> unit -> unit + (* one-box viewer *) + +val view_defined : env:Env.t -> ?show_all:bool -> Longident.t -> unit + (* displays a signature, found in environment *) + +val close_all_views : unit -> unit diff --git a/otherlibs/labltk/browser/winmain.c b/otherlibs/labltk/browser/winmain.c new file mode 100644 index 0000000..43d3b7f --- /dev/null +++ b/otherlibs/labltk/browser/winmain.c @@ -0,0 +1,26 @@ +/* $Id: winmain.c,v 1.6 2008-12-03 18:09:09 doligez Exp $ */ + +#include <windows.h> +#include <mlvalues.h> +#include <callback.h> +#include <sys.h> + +/*CAMLextern int __argc; */ +/* CAMLextern char **__argv; */ +/* CAMLextern void caml_expand_command_line(int * argcp, char *** argvp); */ +/* extern void caml_main (char **); */ + +int WINAPI WinMain(HINSTANCE h, HINSTANCE HPrevInstance, + LPSTR lpCmdLine, int nCmdShow) +{ + char exe_name[1024]; + char * argv[2]; + + GetModuleFileName(NULL, exe_name, sizeof(exe_name) - 1); + exe_name[sizeof(exe_name) - 1] = '0'; + argv[0] = exe_name; + argv[1] = NULL; + caml_main(argv); + sys_exit(Val_int(0)); + return 0; +} diff --git a/otherlibs/labltk/builtin/LICENSE b/otherlibs/labltk/builtin/LICENSE new file mode 100644 index 0000000..efbdbb1 --- /dev/null +++ b/otherlibs/labltk/builtin/LICENSE @@ -0,0 +1,19 @@ +(*************************************************************************) +(* *) +(* Objective Caml LablTk library *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../../../LICENSE. *) +(* *) +(*************************************************************************) + +(* $Id: LICENSE,v 1.2 2001-12-07 13:40:03 xleroy Exp $ *) + +All the files in this directory are subject to the above copyright notice. \ No newline at end of file diff --git a/otherlibs/labltk/builtin/builtin_FilePattern.ml b/otherlibs/labltk/builtin/builtin_FilePattern.ml new file mode 100644 index 0000000..f7dd1d6 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_FilePattern.ml @@ -0,0 +1,20 @@ +(* File patterns *) +(* type *) +type filePattern = { + typename : string; + extensions : string list; + mactypes : string list + } +(* /type *) + +let cCAMLtoTKfilePattern fp = + let typename = TkQuote (TkToken fp.typename) in + let extensions = + TkQuote (TkTokenList (List.map (fun x -> TkToken x) fp.extensions)) in + let mactypes = + match fp.mactypes with + | [] -> [] + | [s] -> [TkToken s] + | _ -> [TkQuote (TkTokenList (List.map (fun x -> TkToken x) fp.mactypes))] + in + TkQuote (TkTokenList (typename :: extensions :: mactypes)) diff --git a/otherlibs/labltk/builtin/builtin_GetBitmap.ml b/otherlibs/labltk/builtin/builtin_GetBitmap.ml new file mode 100644 index 0000000..bf02d20 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_GetBitmap.ml @@ -0,0 +1,22 @@ +(* Tk_GetBitmap emulation *) + +##ifdef CAMLTK + +(* type *) +type bitmap = + | BitmapFile of string (* path of file *) + | Predefined of string (* bitmap name *) +;; +(* /type *) + +##else + +(* type *) +type bitmap = [ + | `File of string (* path of file *) + | `Predefined of string (* bitmap name *) +] +;; +(* /type *) + +##endif diff --git a/otherlibs/labltk/builtin/builtin_GetCursor.ml b/otherlibs/labltk/builtin/builtin_GetCursor.ml new file mode 100644 index 0000000..6c7034b --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_GetCursor.ml @@ -0,0 +1,61 @@ +(* Color *) + +##ifdef CAMLTK + +(* type *) +type color = + | NamedColor of string + | Black (* tk keyword: black *) + | White (* tk keyword: white *) + | Red (* tk keyword: red *) + | Green (* tk keyword: green *) + | Blue (* tk keyword: blue *) + | Yellow (* tk keyword: yellow *) +;; +(* /type *) + +##else + +(* type *) +type color = [ + | `Color of string + | `Black (* tk keyword: black *) + | `White (* tk keyword: white *) + | `Red (* tk keyword: red *) + | `Green (* tk keyword: green *) + | `Blue (* tk keyword: blue *) + | `Yellow (* tk keyword: yellow *) +] +;; +(* /type *) + +##endif + +##ifdef CAMLTK + +(* type *) +type cursor = + | XCursor of string + | XCursorFg of string * color + | XCursortFgBg of string * color * color + | CursorFileFg of string * color + | CursorMaskFile of string * string * color * color +;; +(* /type *) + +##else + +(* Tk_GetCursor emulation *) +(* type *) +type cursor = [ + | `Xcursor of string + | `Xcursorfg of string * color + | `Xcursorfgbg of string * color * color + | `Cursorfilefg of string * color + | `Cursormaskfile of string * string * color * color +] +;; +(* /type *) + +##endif + diff --git a/otherlibs/labltk/builtin/builtin_GetPixel.ml b/otherlibs/labltk/builtin/builtin_GetPixel.ml new file mode 100644 index 0000000..772a2c2 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_GetPixel.ml @@ -0,0 +1,28 @@ +(* Tk_GetPixels emulation *) + +##ifdef CAMLTK + +(* type *) +type units = + | Pixels of int (* specified as floating-point, but inconvenient *) + | Centimeters of float + | Inches of float + | Millimeters of float + | PrinterPoint of float +;; +(* /type *) + +##else + +(* type *) +type units = [ + | `Pix of int + | `Cm of float + | `In of float + | `Mm of float + | `Pt of float +] +;; +(* /type *) + +##endif diff --git a/otherlibs/labltk/builtin/builtin_ScrollValue.ml b/otherlibs/labltk/builtin/builtin_ScrollValue.ml new file mode 100644 index 0000000..75a509e --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_ScrollValue.ml @@ -0,0 +1,22 @@ +##ifdef CAMLTK + +(* type *) +type scrollValue = + | ScrollPage of int (* tk option: scroll <int> page *) + | ScrollUnit of int (* tk option: scroll <int> unit *) + | MoveTo of float (* tk option: moveto <float> *) +;; +(* /type *) + +##else + +(* type *) +type scrollValue = [ + | `Page of int (* tk option: scroll <int> page *) + | `Unit of int (* tk option: scroll <int> unit *) + | `Moveto of float (* tk option: moveto <float> *) +] +;; +(* /type *) + +##endif diff --git a/otherlibs/labltk/builtin/builtin_bind.ml b/otherlibs/labltk/builtin/builtin_bind.ml new file mode 100644 index 0000000..35d0d3c --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_bind.ml @@ -0,0 +1,469 @@ +##ifdef CAMLTK + +open Widget;; + +(* Events and bindings *) +(* Builtin types *) +(* type *) +type xEvent = + | Activate + | ButtonPress (* also Button, but we omit it *) + | ButtonPressDetail of int + | ButtonRelease + | ButtonReleaseDetail of int + | Circulate + | ColorMap (* not Colormap, avoiding confusion between the Colormap option *) + | Configure + | Deactivate + | Destroy + | Enter + | Expose + | FocusIn + | FocusOut + | Gravity + | KeyPress (* also Key, but we omit it *) + | KeyPressDetail of string (* /usr/include/X11/keysymdef.h *) + | KeyRelease + | KeyReleaseDetail of string + | Leave + | Map + | Motion + | Property + | Reparent + | Unmap + | Visibility + | Virtual of string (* Virtual event. Must be without modifiers *) +;; +(* /type *) + +(* type *) +type modifier = + | Control + | Shift + | Lock + | Button1 + | Button2 + | Button3 + | Button4 + | Button5 + | Double + | Triple + | Mod1 + | Mod2 + | Mod3 + | Mod4 + | Mod5 + | Meta + | Alt +;; +(* /type *) + +(* Event structure, passed to bounded functions *) + +(* type *) +type eventInfo = + { + (* %# : event serial number is unsupported *) + mutable ev_Above : int; (* tk: %a *) + mutable ev_ButtonNumber : int; (* tk: %b *) + mutable ev_Count : int; (* tk: %c *) + mutable ev_Detail : string; (* tk: %d *) + mutable ev_Focus : bool; (* tk: %f *) + mutable ev_Height : int; (* tk: %h *) + mutable ev_KeyCode : int; (* tk: %k *) + mutable ev_Mode : string; (* tk: %m *) + mutable ev_OverrideRedirect : bool; (* tk: %o *) + mutable ev_Place : string; (* tk: %p *) + mutable ev_State : string; (* tk: %s *) + mutable ev_Time : int; (* tk: %t *) + mutable ev_Width : int; (* tk: %w *) + mutable ev_MouseX : int; (* tk: %x *) + mutable ev_MouseY : int; (* tk: %y *) + mutable ev_Char : string; (* tk: %A *) + mutable ev_BorderWidth : int; (* tk: %B *) + mutable ev_SendEvent : bool; (* tk: %E *) + mutable ev_KeySymString : string; (* tk: %K *) + mutable ev_KeySymInt : int; (* tk: %N *) + mutable ev_RootWindow : int; (* tk: %R *) + mutable ev_SubWindow : int; (* tk: %S *) + mutable ev_Type : int; (* tk: %T *) + mutable ev_Widget : widget; (* tk: %W *) + mutable ev_RootX : int; (* tk: %X *) + mutable ev_RootY : int (* tk: %Y *) + } +;; +(* /type *) + + +(* To avoid collision with other constructors (Width, State), + use Ev_ prefix *) +(* type *) +type eventField = + | Ev_Above + | Ev_ButtonNumber + | Ev_Count + | Ev_Detail + | Ev_Focus + | Ev_Height + | Ev_KeyCode + | Ev_Mode + | Ev_OverrideRedirect + | Ev_Place + | Ev_State + | Ev_Time + | Ev_Width + | Ev_MouseX + | Ev_MouseY + | Ev_Char + | Ev_BorderWidth + | Ev_SendEvent + | Ev_KeySymString + | Ev_KeySymInt + | Ev_RootWindow + | Ev_SubWindow + | Ev_Type + | Ev_Widget + | Ev_RootX + | Ev_RootY +;; +(* /type *) + +let filleventInfo ev v = function + | Ev_Above -> ev.ev_Above <- int_of_string v + | Ev_ButtonNumber -> ev.ev_ButtonNumber <- int_of_string v + | Ev_Count -> ev.ev_Count <- int_of_string v + | Ev_Detail -> ev.ev_Detail <- v + | Ev_Focus -> ev.ev_Focus <- v = "1" + | Ev_Height -> ev.ev_Height <- int_of_string v + | Ev_KeyCode -> ev.ev_KeyCode <- int_of_string v + | Ev_Mode -> ev.ev_Mode <- v + | Ev_OverrideRedirect -> ev.ev_OverrideRedirect <- v = "1" + | Ev_Place -> ev.ev_Place <- v + | Ev_State -> ev.ev_State <- v + | Ev_Time -> ev.ev_Time <- int_of_string v + | Ev_Width -> ev.ev_Width <- int_of_string v + | Ev_MouseX -> ev.ev_MouseX <- int_of_string v + | Ev_MouseY -> ev.ev_MouseY <- int_of_string v + | Ev_Char -> ev.ev_Char <- v + | Ev_BorderWidth -> ev.ev_BorderWidth <- int_of_string v + | Ev_SendEvent -> ev.ev_SendEvent <- v = "1" + | Ev_KeySymString -> ev.ev_KeySymString <- v + | Ev_KeySymInt -> ev.ev_KeySymInt <- int_of_string v + | Ev_RootWindow -> ev.ev_RootWindow <- int_of_string v + | Ev_SubWindow -> ev.ev_SubWindow <- int_of_string v + | Ev_Type -> ev.ev_Type <- int_of_string v + | Ev_Widget -> ev.ev_Widget <- cTKtoCAMLwidget v + | Ev_RootX -> ev.ev_RootX <- int_of_string v + | Ev_RootY -> ev.ev_RootY <- int_of_string v +;; + +let wrapeventInfo f what = + let ev = { + ev_Above = 0; + ev_ButtonNumber = 0; + ev_Count = 0; + ev_Detail = ""; + ev_Focus = false; + ev_Height = 0; + ev_KeyCode = 0; + ev_Mode = ""; + ev_OverrideRedirect = false; + ev_Place = ""; + ev_State = ""; + ev_Time = 0; + ev_Width = 0; + ev_MouseX = 0; + ev_MouseY = 0; + ev_Char = ""; + ev_BorderWidth = 0; + ev_SendEvent = false; + ev_KeySymString = ""; + ev_KeySymInt = 0; + ev_RootWindow = 0; + ev_SubWindow = 0; + ev_Type = 0; + ev_Widget = Widget.default_toplevel; + ev_RootX = 0; + ev_RootY = 0 } in + function args -> + let l = ref args in + List.iter (function field -> + match !l with + [] -> () + | v::rest -> filleventInfo ev v field; l:=rest) + what; + f ev +;; + +let rec writeeventField = function + | [] -> "" + | field::rest -> + begin + match field with + | Ev_Above -> " %a" + | Ev_ButtonNumber ->" %b" + | Ev_Count -> " %c" + | Ev_Detail -> " %d" + | Ev_Focus -> " %f" + | Ev_Height -> " %h" + | Ev_KeyCode -> " %k" + | Ev_Mode -> " %m" + | Ev_OverrideRedirect -> " %o" + | Ev_Place -> " %p" + | Ev_State -> " %s" + | Ev_Time -> " %t" + | Ev_Width -> " %w" + | Ev_MouseX -> " %x" + | Ev_MouseY -> " %y" + (* Quoting is done by Tk *) + | Ev_Char -> " %A" + | Ev_BorderWidth -> " %B" + | Ev_SendEvent -> " %E" + | Ev_KeySymString -> " %K" + | Ev_KeySymInt -> " %N" + | Ev_RootWindow ->" %R" + | Ev_SubWindow -> " %S" + | Ev_Type -> " %T" + | Ev_Widget ->" %W" + | Ev_RootX -> " %X" + | Ev_RootY -> " %Y" + end + ^ writeeventField rest +;; + +##else + +open Widget;; + +(* Events and bindings *) +(* Builtin types *) + +(* type *) +type event = [ + | `Activate + | `ButtonPress (* also Button, but we omit it *) + | `ButtonPressDetail of int + | `ButtonRelease + | `ButtonReleaseDetail of int + | `Circulate + | `Colormap + | `Configure + | `Deactivate + | `Destroy + | `Enter + | `Expose + | `FocusIn + | `FocusOut + | `Gravity + | `KeyPress (* also Key, but we omit it *) + | `KeyPressDetail of string (* /usr/include/X11/keysymdef.h *) + | `KeyRelease + | `KeyReleaseDetail of string + | `Leave + | `Map + | `Motion + | `Property + | `Reparent + | `Unmap + | `Visibility + | `Virtual of string (* Virtual event. Must be without modifiers *) + | `Modified of modifier list * event +] + +and modifier = [ + | `Control + | `Shift + | `Lock + | `Button1 + | `Button2 + | `Button3 + | `Button4 + | `Button5 + | `Double + | `Triple + | `Mod1 + | `Mod2 + | `Mod3 + | `Mod4 + | `Mod5 + | `Meta + | `Alt +] +;; +(* /type *) + +(* Event structure, passed to bounded functions *) + +(* type *) +type eventInfo = { + (* %# : event serial number is unsupported *) + mutable ev_Above : int; (* tk: %a *) + mutable ev_ButtonNumber : int; (* tk: %b *) + mutable ev_Count : int; (* tk: %c *) + mutable ev_Detail : string; (* tk: %d *) + mutable ev_Focus : bool; (* tk: %f *) + mutable ev_Height : int; (* tk: %h *) + mutable ev_KeyCode : int; (* tk: %k *) + mutable ev_Mode : string; (* tk: %m *) + mutable ev_OverrideRedirect : bool; (* tk: %o *) + mutable ev_Place : string; (* tk: %p *) + mutable ev_State : string; (* tk: %s *) + mutable ev_Time : int; (* tk: %t *) + mutable ev_Width : int; (* tk: %w *) + mutable ev_MouseX : int; (* tk: %x *) + mutable ev_MouseY : int; (* tk: %y *) + mutable ev_Char : string; (* tk: %A *) + mutable ev_BorderWidth : int; (* tk: %B *) + mutable ev_SendEvent : bool; (* tk: %E *) + mutable ev_KeySymString : string; (* tk: %K *) + mutable ev_KeySymInt : int; (* tk: %N *) + mutable ev_RootWindow : int; (* tk: %R *) + mutable ev_SubWindow : int; (* tk: %S *) + mutable ev_Type : int; (* tk: %T *) + mutable ev_Widget : any widget; (* tk: %W *) + mutable ev_RootX : int; (* tk: %X *) + mutable ev_RootY : int (* tk: %Y *) + } +;; +(* /type *) + + +(* To avoid collision with other constructors (Width, State), + use Ev_ prefix *) +(* type *) +type eventField = [ + | `Above + | `ButtonNumber + | `Count + | `Detail + | `Focus + | `Height + | `KeyCode + | `Mode + | `OverrideRedirect + | `Place + | `State + | `Time + | `Width + | `MouseX + | `MouseY + | `Char + | `BorderWidth + | `SendEvent + | `KeySymString + | `KeySymInt + | `RootWindow + | `SubWindow + | `Type + | `Widget + | `RootX + | `RootY +] +;; +(* /type *) + +let filleventInfo ev v : eventField -> unit = function + | `Above -> ev.ev_Above <- int_of_string v + | `ButtonNumber -> ev.ev_ButtonNumber <- int_of_string v + | `Count -> ev.ev_Count <- int_of_string v + | `Detail -> ev.ev_Detail <- v + | `Focus -> ev.ev_Focus <- v = "1" + | `Height -> ev.ev_Height <- int_of_string v + | `KeyCode -> ev.ev_KeyCode <- int_of_string v + | `Mode -> ev.ev_Mode <- v + | `OverrideRedirect -> ev.ev_OverrideRedirect <- v = "1" + | `Place -> ev.ev_Place <- v + | `State -> ev.ev_State <- v + | `Time -> ev.ev_Time <- int_of_string v + | `Width -> ev.ev_Width <- int_of_string v + | `MouseX -> ev.ev_MouseX <- int_of_string v + | `MouseY -> ev.ev_MouseY <- int_of_string v + | `Char -> ev.ev_Char <- v + | `BorderWidth -> ev.ev_BorderWidth <- int_of_string v + | `SendEvent -> ev.ev_SendEvent <- v = "1" + | `KeySymString -> ev.ev_KeySymString <- v + | `KeySymInt -> ev.ev_KeySymInt <- int_of_string v + | `RootWindow -> ev.ev_RootWindow <- int_of_string v + | `SubWindow -> ev.ev_SubWindow <- int_of_string v + | `Type -> ev.ev_Type <- int_of_string v + | `Widget -> ev.ev_Widget <- cTKtoCAMLwidget v + | `RootX -> ev.ev_RootX <- int_of_string v + | `RootY -> ev.ev_RootY <- int_of_string v +;; + +let wrapeventInfo f (what : eventField list) = + let ev = { + ev_Above = 0; + ev_ButtonNumber = 0; + ev_Count = 0; + ev_Detail = ""; + ev_Focus = false; + ev_Height = 0; + ev_KeyCode = 0; + ev_Mode = ""; + ev_OverrideRedirect = false; + ev_Place = ""; + ev_State = ""; + ev_Time = 0; + ev_Width = 0; + ev_MouseX = 0; + ev_MouseY = 0; + ev_Char = ""; + ev_BorderWidth = 0; + ev_SendEvent = false; + ev_KeySymString = ""; + ev_KeySymInt = 0; + ev_RootWindow = 0; + ev_SubWindow = 0; + ev_Type = 0; + ev_Widget = forget_type default_toplevel; + ev_RootX = 0; + ev_RootY = 0 } in + function args -> + let l = ref args in + List.iter what ~f: + begin fun field -> + match !l with + | [] -> () + | v :: rest -> filleventInfo ev v field; l := rest + end; + f ev +;; + +let rec writeeventField : eventField list -> string = function + | [] -> "" + | field :: rest -> + begin + match field with + | `Above -> " %a" + | `ButtonNumber ->" %b" + | `Count -> " %c" + | `Detail -> " %d" + | `Focus -> " %f" + | `Height -> " %h" + | `KeyCode -> " %k" + | `Mode -> " %m" + | `OverrideRedirect -> " %o" + | `Place -> " %p" + | `State -> " %s" + | `Time -> " %t" + | `Width -> " %w" + | `MouseX -> " %x" + | `MouseY -> " %y" + (* Quoting is done by Tk *) + | `Char -> " %A" + | `BorderWidth -> " %B" + | `SendEvent -> " %E" + | `KeySymString -> " %K" + | `KeySymInt -> " %N" + | `RootWindow ->" %R" + | `SubWindow -> " %S" + | `Type -> " %T" + | `Widget -> " %W" + | `RootX -> " %X" + | `RootY -> " %Y" + end + ^ writeeventField rest +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtin_bindtags.ml b/otherlibs/labltk/builtin/builtin_bindtags.ml new file mode 100644 index 0000000..4529fcd --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_bindtags.ml @@ -0,0 +1,21 @@ +##ifdef CAMLTK + +(* type *) +type bindings = + | TagBindings of string (* tk option: <string> *) + | WidgetBindings of widget (* tk option: <widget> *) +;; +(* /type *) + +##else + +(* type *) +type bindings = [ + | `Tag of string (* tk option: <string> *) + | `Widget of any widget (* tk option: <widget> *) +] +;; +(* /type *) + +##endif + diff --git a/otherlibs/labltk/builtin/builtin_font.ml b/otherlibs/labltk/builtin/builtin_font.ml new file mode 100644 index 0000000..3425391 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_font.ml @@ -0,0 +1,4 @@ +(* type *) +type font = string +(* /type *) + diff --git a/otherlibs/labltk/builtin/builtin_grab.ml b/otherlibs/labltk/builtin/builtin_grab.ml new file mode 100644 index 0000000..2569268 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_grab.ml @@ -0,0 +1,3 @@ +(* type *) +type grabGlobal = bool +(* /type *) diff --git a/otherlibs/labltk/builtin/builtin_index.ml b/otherlibs/labltk/builtin/builtin_index.ml new file mode 100644 index 0000000..a42af55 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_index.ml @@ -0,0 +1,92 @@ +(* Various indexes + canvas + entry + listbox +*) + +##ifdef CAMLTK + +(* A large type for all indices in all widgets *) +(* a bit overkill though *) + +(* type *) +type index = + | Number of int (* no keyword *) + | ActiveElement (* tk keyword: active *) + | End (* tk keyword: end *) + | Last (* tk keyword: last *) + | NoIndex (* tk keyword: none *) + | Insert (* tk keyword: insert *) + | SelFirst (* tk keyword: sel.first *) + | SelLast (* tk keyword: sel.last *) + | At of int (* tk keyword: @n *) + | AtXY of int * int (* tk keyword: @x,y *) + | AnchorPoint (* tk keyword: anchor *) + | Pattern of string (* no keyword *) + | LineChar of int * int (* tk keyword: l.c *) + | Mark of string (* no keyword *) + | TagFirst of string (* tk keyword: tag.first *) + | TagLast of string (* tk keyword: tag.last *) + | Embedded of widget (* no keyword *) +;; +(* /type *) + +##else + +type canvas_index = [ + | `Num of int + | `End + | `Insert + | `Selfirst + | `Sellast + | `Atxy of int * int +] +;; + +type entry_index = [ + | `Num of int + | `End + | `Insert + | `Selfirst + | `Sellast + | `At of int + | `Anchor +] +;; + +type listbox_index = [ + | `Num of int + | `Active + | `Anchor + | `End + | `Atxy of int * int +] +;; + +type menu_index = [ + | `Num of int + | `Active + | `End + | `Last + | `None + | `At of int + | `Pattern of string +] +;; + +type text_index = [ + | `Linechar of int * int + | `Atxy of int * int + | `End + | `Mark of string + | `Tagfirst of string + | `Taglast of string + | `Window of any widget + | `Image of string +] +;; + +type linechar_index = int * int;; +type num_index = int;; + +##endif diff --git a/otherlibs/labltk/builtin/builtin_palette.ml b/otherlibs/labltk/builtin/builtin_palette.ml new file mode 100644 index 0000000..4eab69a --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_palette.ml @@ -0,0 +1,20 @@ +##ifdef CAMLTK + +(* type *) +type paletteType = + | GrayShades of int + | RGBShades of int * int * int +;; +(* /type *) + +##else + +(* type *) +type paletteType = [ + | `Gray of int + | `Rgb of int * int * int +] +;; +(* /type *) + +##endif diff --git a/otherlibs/labltk/builtin/builtin_text.ml b/otherlibs/labltk/builtin/builtin_text.ml new file mode 100644 index 0000000..b2d6958 --- /dev/null +++ b/otherlibs/labltk/builtin/builtin_text.ml @@ -0,0 +1,50 @@ +(* Not a string as such, more like a symbol *) + +(* type *) +type textMark = string;; +(* /type *) + +(* type *) +type textTag = string;; +(* /type *) + +##ifdef CAMLTK + +(* type *) +type textModifier = + | CharOffset of int (* tk keyword: +/- Xchars *) + | LineOffset of int (* tk keyword: +/- Xlines *) + | LineStart (* tk keyword: linestart *) + | LineEnd (* tk keyword: lineend *) + | WordStart (* tk keyword: wordstart *) + | WordEnd (* tk keyword: wordend *) +;; +(* /type *) + +(* type *) +type textIndex = + | TextIndex of index * textModifier list + | TextIndexNone +;; +(* /type *) + +##else + +(* type *) +type textModifier = [ + | `Char of int (* tk keyword: +/- Xchars *) + | `Line of int (* tk keyword: +/- Xlines *) + | `Linestart (* tk keyword: linestart *) + | `Lineend (* tk keyword: lineend *) + | `Wordstart (* tk keyword: wordstart *) + | `Wordend (* tk keyword: wordend *) +] +;; +(* /type *) + +(* type *) +type textIndex = text_index * textModifier list +;; +(* /type *) + +##endif diff --git a/otherlibs/labltk/builtin/builtina_empty.ml b/otherlibs/labltk/builtin/builtina_empty.ml new file mode 100644 index 0000000..e69de29 diff --git a/otherlibs/labltk/builtin/builtinf_GetPixel.ml b/otherlibs/labltk/builtin/builtinf_GetPixel.ml new file mode 100644 index 0000000..7e7c596 --- /dev/null +++ b/otherlibs/labltk/builtin/builtinf_GetPixel.ml @@ -0,0 +1,23 @@ +##ifdef CAMLTK + +let pixels units = + let res = + tkEval + [|TkToken"winfo"; + TkToken"pixels"; + cCAMLtoTKwidget widget_any_table default_toplevel; + cCAMLtoTKunits units|] in + int_of_string res + +##else + +let pixels units = + let res = + tkEval + [|TkToken"winfo"; + TkToken"pixels"; + cCAMLtoTKwidget default_toplevel; + cCAMLtoTKunits units|] in + int_of_string res + +##endif diff --git a/otherlibs/labltk/builtin/builtinf_bind.ml b/otherlibs/labltk/builtin/builtinf_bind.ml new file mode 100644 index 0000000..d78541e --- /dev/null +++ b/otherlibs/labltk/builtin/builtinf_bind.ml @@ -0,0 +1,133 @@ +##ifdef CAMLTK + +(* type *) +type bindAction = + | BindSet of eventField list * (eventInfo -> unit) + | BindSetBreakable of eventField list * (eventInfo -> unit) + | BindRemove + | BindExtend of eventField list * (eventInfo -> unit) +(* /type *) + +(* +FUNCTION + val bind: + widget -> (modifier list * xEvent) list -> bindAction -> unit +/FUNCTION +*) +let bind widget eventsequence action = + tkCommand [| TkToken "bind"; + TkToken (Widget.name widget); + cCAMLtoTKeventSequence eventsequence; + begin match action with + BindRemove -> TkToken "" + | BindSet (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) + in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)) + | BindSetBreakable (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) + in + TkToken ("camlcb " ^ cbId ^ (writeeventField what) ^ + " ; if { $BreakBindingsSequence == 1 } then { break ;} ; set BreakBindingsSequence 0") + | BindExtend (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) + in + TkToken ("+camlcb " ^ cbId ^ (writeeventField what)) + end |] +;; + +(* FUNCTION +(* unsafe *) + val bind_class : + string -> (modifier list * xEvent) list -> bindAction -> unit +(* /unsafe *) +/FUNCTION class arg is not constrained *) + +let bind_class clas eventsequence action = + tkCommand [| TkToken "bind"; + TkToken clas; + cCAMLtoTKeventSequence eventsequence; + begin match action with + BindRemove -> TkToken "" + | BindSet (what, f) -> + let cbId = register_callback Widget.dummy + (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)) + | BindSetBreakable (what, f) -> + let cbId = register_callback Widget.dummy + (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)^ + " ; if { $BreakBindingsSequence == 1 } then { break ;} ; set BreakBindingsSequence 0" ) + | BindExtend (what, f) -> + let cbId = register_callback Widget.dummy + (wrapeventInfo f what) in + TkToken ("+camlcb " ^ cbId ^ (writeeventField what)) + end |] +;; + +(* FUNCTION +(* unsafe *) + val bind_tag : + string -> (modifier list * xEvent) list -> bindAction -> unit +(* /unsafe *) +/FUNCTION *) + +let bind_tag = bind_class +;; + +(* +FUNCTION + val break : unit -> unit +/FUNCTION +*) +let break = function () -> + Textvariable.set (Textvariable.coerce "BreakBindingsSequence") "1" +;; + +(* Legacy functions *) +let tag_bind = bind_tag;; +let class_bind = bind_class;; + +##else + +let bind_class ~events ?(extend = false) ?(breakable = false) ?(fields = []) + ?action ?on:widget name = + let widget = match widget with None -> Widget.dummy | Some w -> coe w in + tkCommand + [| TkToken "bind"; + TkToken name; + cCAMLtoTKeventSequence events; + begin match action with None -> TkToken "" + | Some f -> + let cbId = + register_callback widget ~callback: (wrapeventInfo f fields) in + let cb = if extend then "+camlcb " else "camlcb " in + let cb = cb ^ cbId ^ writeeventField fields in + let cb = + if breakable then + cb ^ " ; if { $BreakBindingsSequence == 1 } then { break ;}" + ^ " ; set BreakBindingsSequence 0" + else cb in + TkToken cb + end + |] +;; + +let bind ~events ?extend ?breakable ?fields ?action widget = + bind_class ~events ?extend ?breakable ?fields ?action ~on:widget + (Widget.name widget) +;; + +let bind_tag = bind_class +;; + +(* +FUNCTION + val break : unit -> unit +/FUNCTION +*) +let break = function () -> + tkCommand [| TkToken "set" ; TkToken "BreakBindingsSequence" ; TkToken "1" |] +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_GetBitmap.ml b/otherlibs/labltk/builtin/builtini_GetBitmap.ml new file mode 100644 index 0000000..1afa0cd --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_GetBitmap.ml @@ -0,0 +1,28 @@ +##ifdef CAMLTK + +let cCAMLtoTKbitmap = function + BitmapFile s -> TkToken ("@" ^ s) +| Predefined s -> TkToken s +;; + +let cTKtoCAMLbitmap s = + if s = "" then Predefined "" + else if String.get s 0 = '@' + then BitmapFile (String.sub s 1 (String.length s - 1)) + else Predefined s +;; + +##else + +let cCAMLtoTKbitmap : bitmap -> tkArgs = function + | `File s -> TkToken ("@" ^ s) + | `Predefined s -> TkToken s +;; + +let cTKtoCAMLbitmap s = + if String.get s 0 = '@' + then `File (String.sub s ~pos:1 ~len:(String.length s - 1)) + else `Predefined s +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_GetCursor.ml b/otherlibs/labltk/builtin/builtini_GetCursor.ml new file mode 100644 index 0000000..8f4e397 --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_GetCursor.ml @@ -0,0 +1,55 @@ +##ifdef CAMLTK + +let cCAMLtoTKcolor = function + NamedColor x -> TkToken x + | Black -> TkToken "black" + | White -> TkToken "white" + | Red -> TkToken "red" + | Green -> TkToken "green" + | Blue -> TkToken "blue" + | Yellow -> TkToken "yellow" +;; + +let cTKtoCAMLcolor = function s -> NamedColor s +;; + +let cCAMLtoTKcursor = function + XCursor s -> TkToken s + | XCursorFg (s,fg) -> + TkQuote(TkTokenList [TkToken s; cCAMLtoTKcolor fg]) + | XCursortFgBg (s,fg,bg) -> + TkQuote(TkTokenList [TkToken s; cCAMLtoTKcolor fg; cCAMLtoTKcolor bg]) + | CursorFileFg (s,fg) -> + TkQuote(TkTokenList [TkToken ("@"^s); cCAMLtoTKcolor fg]) + | CursorMaskFile (s,m,fg,bg) -> + TkQuote(TkTokenList [TkToken ("@"^s); TkToken m; cCAMLtoTKcolor fg; cCAMLtoTKcolor bg]) +;; + +##else + +let cCAMLtoTKcolor : color -> tkArgs = function + | `Color x -> TkToken x + | `Black -> TkToken "black" + | `White -> TkToken "white" + | `Red -> TkToken "red" + | `Green -> TkToken "green" + | `Blue -> TkToken "blue" + | `Yellow -> TkToken "yellow" +;; + +let cTKtoCAMLcolor = function s -> `Color s +;; + +let cCAMLtoTKcursor : cursor -> tkArgs = function + | `Xcursor s -> TkToken s + | `Xcursorfg (s,fg) -> + TkQuote(TkTokenList [TkToken s; cCAMLtoTKcolor fg]) + | `Xcursorfgbg (s,fg,bg) -> + TkQuote(TkTokenList [TkToken s; cCAMLtoTKcolor fg; cCAMLtoTKcolor bg]) + | `Cursorfilefg (s,fg) -> + TkQuote(TkTokenList [TkToken ("@"^s); cCAMLtoTKcolor fg]) + | `Cursormaskfile (s,m,fg,bg) -> + TkQuote(TkTokenList [TkToken ("@"^s); TkToken m; cCAMLtoTKcolor fg; cCAMLtoTKcolor bg]) +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_GetPixel.ml b/otherlibs/labltk/builtin/builtini_GetPixel.ml new file mode 100644 index 0000000..12e7890 --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_GetPixel.ml @@ -0,0 +1,43 @@ +##ifdef CAMLTK + +let cCAMLtoTKunits = function + Pixels (foo) -> TkToken (string_of_int foo) + | Millimeters (foo) -> TkToken(Printf.sprintf "%gm" foo) + | Inches (foo) -> TkToken(Printf.sprintf "%gi" foo) + | PrinterPoint (foo) -> TkToken(Printf.sprintf "%gp" foo) + | Centimeters (foo) -> TkToken(Printf.sprintf "%gc" foo) +;; + +let cTKtoCAMLunits str = + let len = String.length str in + let num_part str = String.sub str 0 (len - 1) in + match String.get str (pred len) with + 'c' -> Centimeters (float_of_string (num_part str)) + | 'i' -> Inches (float_of_string (num_part str)) + | 'm' -> Millimeters (float_of_string (num_part str)) + | 'p' -> PrinterPoint (float_of_string (num_part str)) + | _ -> Pixels(int_of_string str) +;; + +##else + +let cCAMLtoTKunits : units -> tkArgs = function + | `Pix (foo) -> TkToken (string_of_int foo) + | `Mm (foo) -> TkToken(Printf.sprintf "%gm" foo) + | `In (foo) -> TkToken(Printf.sprintf "%gi" foo) + | `Pt (foo) -> TkToken(Printf.sprintf "%gp" foo) + | `Cm (foo) -> TkToken(Printf.sprintf "%gc" foo) +;; + +let cTKtoCAMLunits str = + let len = String.length str in + let num_part str = String.sub str ~pos:0 ~len:(len - 1) in + match String.get str (pred len) with + | 'c' -> `Cm (float_of_string (num_part str)) + | 'i' -> `In (float_of_string (num_part str)) + | 'm' -> `Mm (float_of_string (num_part str)) + | 'p' -> `Pt (float_of_string (num_part str)) + | _ -> `Pix(int_of_string str) +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_ScrollValue.ml b/otherlibs/labltk/builtin/builtini_ScrollValue.ml new file mode 100644 index 0000000..08498a0 --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_ScrollValue.ml @@ -0,0 +1,45 @@ +##ifdef CAMLTK + +let cCAMLtoTKscrollValue = function + ScrollPage v1 -> + TkTokenList [TkToken"scroll"; TkToken (string_of_int v1); TkToken"pages"] + | ScrollUnit v1 -> + TkTokenList [TkToken"scroll"; TkToken (string_of_int v1); TkToken"units"] + | MoveTo v1 -> + TkTokenList [TkToken"moveto"; TkToken (Printf.sprintf "%g" v1)] +;; + +(* str l -> scrllv -> str l *) +let cTKtoCAMLscrollValue = function + "scroll"::n::"pages"::l -> + ScrollPage (int_of_string n), l + | "scroll"::n::"units"::l -> + ScrollUnit (int_of_string n), l + | "moveto"::f::l -> + MoveTo (float_of_string f), l + | _ -> raise (Invalid_argument "TKtoCAMLscrollValue") +;; + +##else + +let cCAMLtoTKscrollValue : scrollValue -> tkArgs = function + | `Page v1 -> + TkTokenList [TkToken"scroll"; TkToken (string_of_int v1); TkToken"pages"] + | `Unit v1 -> + TkTokenList [TkToken"scroll"; TkToken (string_of_int v1); TkToken"units"] + | `Moveto v1 -> + TkTokenList [TkToken"moveto"; TkToken (Printf.sprintf "%g" v1)] +;; + +(* str l -> scrllv -> str l *) +let cTKtoCAMLscrollValue = function + | "scroll" :: n :: "pages" :: l -> + `Page (int_of_string n), l + | "scroll" :: n :: "units" :: l -> + `Unit (int_of_string n), l + | "moveto" :: f :: l -> + `Moveto (float_of_string f), l + | _ -> raise (Invalid_argument "TKtoCAMLscrollValue") +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_bind.ml b/otherlibs/labltk/builtin/builtini_bind.ml new file mode 100644 index 0000000..13109cb --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_bind.ml @@ -0,0 +1,136 @@ +##ifdef CAMLTK + +let cCAMLtoTKxEvent = function + | Activate -> "Activate" + | ButtonPress -> "ButtonPress" + | ButtonPressDetail n -> "ButtonPress-"^string_of_int n + | ButtonRelease -> "ButtonRelease" + | ButtonReleaseDetail n -> "ButtonRelease-"^string_of_int n + | Circulate -> "Circulate" + | ColorMap -> "Colormap" + | Configure -> "Configure" + | Deactivate -> "Deactivate" + | Destroy -> "Destroy" + | Enter -> "Enter" + | Expose -> "Expose" + | FocusIn -> "FocusIn" + | FocusOut -> "FocusOut" + | Gravity -> "Gravity" + | KeyPress -> "KeyPress" + | KeyPressDetail s -> "KeyPress-"^s + | KeyRelease -> "KeyRelease" + | KeyReleaseDetail s -> "KeyRelease-"^s + | Leave -> "Leave" + | Map -> "Map" + | Motion -> "Motion" + | Property -> "Property" + | Reparent -> "Reparent" + | Unmap -> "Unmap" + | Visibility -> "Visibility" + | Virtual s -> "<"^s^">" +;; + +let cCAMLtoTKmodifier = function + | Control -> "Control-" + | Shift -> "Shift-" + | Lock -> "Lock-" + | Button1 -> "Button1-" + | Button2 -> "Button2-" + | Button3 -> "Button3-" + | Button4 -> "Button4-" + | Button5 -> "Button5-" + | Double -> "Double-" + | Triple -> "Triple-" + | Mod1 -> "Mod1-" + | Mod2 -> "Mod2-" + | Mod3 -> "Mod3-" + | Mod4 -> "Mod4-" + | Mod5 -> "Mod5-" + | Meta -> "Meta-" + | Alt -> "Alt-" +;; + +exception IllegalVirtualEvent + +(* type event = modifier list * xEvent *) +let cCAMLtoTKevent (ml, xe) = + match xe with + | Virtual s -> + if ml = [] then "<<"^s^">>" + else raise IllegalVirtualEvent + | _ -> + "<" ^ (String.concat " " (List.map cCAMLtoTKmodifier ml)) + ^ (cCAMLtoTKxEvent xe) ^ ">" +;; + +(* type eventSequence == (modifier list * xEvent) list *) +let cCAMLtoTKeventSequence l = + TkToken(List.fold_left (^) "" (List.map cCAMLtoTKevent l)) + +##else + +let cCAMLtoTKmodifier : modifier -> string = function + | `Control -> "Control-" + | `Shift -> "Shift-" + | `Lock -> "Lock-" + | `Button1 -> "Button1-" + | `Button2 -> "Button2-" + | `Button3 -> "Button3-" + | `Button4 -> "Button4-" + | `Button5 -> "Button5-" + | `Double -> "Double-" + | `Triple -> "Triple-" + | `Mod1 -> "Mod1-" + | `Mod2 -> "Mod2-" + | `Mod3 -> "Mod3-" + | `Mod4 -> "Mod4-" + | `Mod5 -> "Mod5-" + | `Meta -> "Meta-" + | `Alt -> "Alt-" +;; + +exception IllegalVirtualEvent + +let cCAMLtoTKevent (ev : event) = + let modified = ref false in + let rec convert = function + | `Activate -> "Activate" + | `ButtonPress -> "ButtonPress" + | `ButtonPressDetail n -> "ButtonPress-"^string_of_int n + | `ButtonRelease -> "ButtonRelease" + | `ButtonReleaseDetail n -> "ButtonRelease-"^string_of_int n + | `Circulate -> "Circulate" + | `Colormap -> "Colormap" + | `Configure -> "Configure" + | `Deactivate -> "Deactivate" + | `Destroy -> "Destroy" + | `Enter -> "Enter" + | `Expose -> "Expose" + | `FocusIn -> "FocusIn" + | `FocusOut -> "FocusOut" + | `Gravity -> "Gravity" + | `KeyPress -> "KeyPress" + | `KeyPressDetail s -> "KeyPress-"^s + | `KeyRelease -> "KeyRelease" + | `KeyReleaseDetail s -> "KeyRelease-"^s + | `Leave -> "Leave" + | `Map -> "Map" + | `Motion -> "Motion" + | `Property -> "Property" + | `Reparent -> "Reparent" + | `Unmap -> "Unmap" + | `Visibility -> "Visibility" + | `Virtual s -> + if !modified then raise IllegalVirtualEvent else "<"^s^">" + | `Modified(ml, ev) -> + modified := true; + String.concat ~sep:"" (List.map ~f:cCAMLtoTKmodifier ml) + ^ convert ev + in "<" ^ convert ev ^ ">" +;; + +let cCAMLtoTKeventSequence (l : event list) = + TkToken(String.concat ~sep:"" (List.map ~f:cCAMLtoTKevent l)) +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_bindtags.ml b/otherlibs/labltk/builtin/builtini_bindtags.ml new file mode 100644 index 0000000..e097348 --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_bindtags.ml @@ -0,0 +1,29 @@ +##ifdef CAMLTK + +let cCAMLtoTKbindings = function + | WidgetBindings v1 -> cCAMLtoTKwidget widget_any_table v1 + | TagBindings v1 -> TkToken v1 +;; + +(* this doesn't really belong here *) +let cTKtoCAMLbindings s = + if String.length s > 0 && s.[0] = '.' then + WidgetBindings (cTKtoCAMLwidget s) + else TagBindings s +;; + +##else + +let cCAMLtoTKbindings = function +| `Widget v1 -> cCAMLtoTKwidget v1 +| `Tag v1 -> TkToken v1 +;; + +(* this doesn't really belong here *) +let cTKtoCAMLbindings s = + if String.length s > 0 && s.[0] = '.' then + `Widget (cTKtoCAMLwidget s) + else `Tag s +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_font.ml b/otherlibs/labltk/builtin/builtini_font.ml new file mode 100644 index 0000000..521b24d --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_font.ml @@ -0,0 +1,3 @@ +let cCAMLtoTKfont (s : font) = TkToken s +let cTKtoCAMLfont (s : font) = s + diff --git a/otherlibs/labltk/builtin/builtini_grab.ml b/otherlibs/labltk/builtin/builtini_grab.ml new file mode 100644 index 0000000..9007d04 --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_grab.ml @@ -0,0 +1,2 @@ +let cCAMLtoTKgrabGlobal x = + if x then TkToken "-global" else TkTokenList [] diff --git a/otherlibs/labltk/builtin/builtini_index.ml b/otherlibs/labltk/builtin/builtini_index.ml new file mode 100644 index 0000000..7718cab --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_index.ml @@ -0,0 +1,140 @@ +##ifdef CAMLTK + +(* sp to avoid being picked up by doc scripts *) + type index_constrs = + CNumber + | CActiveElement + | CEnd + | CLast + | CNoIndex + | CInsert + | CSelFirst + | CSelLast + | CAt + | CAtXY + | CAnchorPoint + | CPattern + | CLineChar + | CMark + | CTagFirst + | CTagLast + | CEmbedded +;; + +let index_any_table = + [CNumber; CActiveElement; CEnd; CLast; CNoIndex; CInsert; CSelFirst; + CSelLast; CAt; CAtXY; CAnchorPoint; CPattern; CLineChar; + CMark; CTagFirst; CTagLast; CEmbedded] +;; + +let index_canvas_table = + [CNumber; CEnd; CInsert; CSelFirst; CSelLast; CAtXY] +;; +let index_entry_table = + [CNumber; CAnchorPoint; CEnd; CInsert; CSelFirst; CSelLast; CAt] +;; +let index_listbox_table = + [CNumber; CActiveElement; CAnchorPoint; CEnd; CAtXY] +;; +let index_menu_table = + [CNumber; CActiveElement; CEnd; CLast; CNoIndex; CAt; CPattern] +;; +let index_text_table = + [CLineChar; CAtXY; CEnd; CMark; CTagFirst; CTagLast; CEmbedded] +;; + +let cCAMLtoTKindex table = function + Number x -> chk_sub "Number" table CNumber; TkToken (string_of_int x) + | ActiveElement -> chk_sub "ActiveElement" table CActiveElement; TkToken "active" + | End -> chk_sub "End" table CEnd; TkToken "end" + | Last -> chk_sub "Last" table CLast; TkToken "last" + | NoIndex -> chk_sub "NoIndex" table CNoIndex; TkToken "none" + | Insert -> chk_sub "Insert" table CInsert; TkToken "insert" + | SelFirst -> chk_sub "SelFirst" table CSelFirst; TkToken "sel.first" + | SelLast -> chk_sub "SelLast" table CSelLast; TkToken "sel.last" + | At n -> chk_sub "At" table CAt; TkToken ("@"^string_of_int n) + | AtXY (x,y) -> chk_sub "AtXY" table CAtXY; + TkToken ("@"^string_of_int x^","^string_of_int y) + | AnchorPoint -> chk_sub "AnchorPoint" table CAnchorPoint; TkToken "anchor" + | Pattern s -> chk_sub "Pattern" table CPattern; TkToken s + | LineChar (l,c) -> chk_sub "LineChar" table CLineChar; + TkToken (string_of_int l^"."^string_of_int c) + | Mark s -> chk_sub "Mark" table CMark; TkToken s + | TagFirst t -> chk_sub "TagFirst" table CTagFirst; + TkToken (t^".first") + | TagLast t -> chk_sub "TagLast" table CTagLast; + TkToken (t^".last") + | Embedded w -> chk_sub "Embedded" table CEmbedded; + cCAMLtoTKwidget widget_any_table w +;; + +let char_index c s = + let rec find i = + if i >= String.length s + then raise Not_found + else if String.get s i = c then i + else find (i+1) in + find 0 +;; + +(* Assume returned values are only numerical and l.c *) +(* .menu index returns none if arg is none, but blast it *) +let cTKtoCAMLindex s = + try + let p = char_index '.' s in + LineChar(int_of_string (String.sub s 0 p), + int_of_string (String.sub s (p+1) (String.length s - p - 1))) + with + Not_found -> + try Number (int_of_string s) + with _ -> raise (Invalid_argument ("TKtoCAMLindex: "^s)) +;; + +##else + +let cCAMLtoTKindex (* Don't put explicit typing *) = function + | `Num x -> TkToken (string_of_int x) + | `Active -> TkToken "active" + | `End -> TkToken "end" + | `Last -> TkToken "last" + | `None -> TkToken "none" + | `Insert -> TkToken "insert" + | `Selfirst -> TkToken "sel.first" + | `Sellast -> TkToken "sel.last" + | `At n -> TkToken ("@" ^ string_of_int n) + | `Atxy (x,y) -> TkToken ("@" ^ string_of_int x ^ "," ^ string_of_int y) + | `Anchor -> TkToken "anchor" + | `Pattern s -> TkToken s + | `Linechar (l,c) -> TkToken (string_of_int l ^ "." ^ string_of_int c) + | `Mark s -> TkToken s + | `Tagfirst t -> TkToken (t ^ ".first") + | `Taglast t -> TkToken (t ^ ".last") + | `Window (w : any widget) -> cCAMLtoTKwidget w + | `Image s -> TkToken s +;; + +let cCAMLtoTKcanvas_index = (cCAMLtoTKindex : canvas_index -> tkArgs);; +let cCAMLtoTKentry_index = (cCAMLtoTKindex : entry_index -> tkArgs);; +let cCAMLtoTKlistbox_index = (cCAMLtoTKindex : listbox_index -> tkArgs);; +let cCAMLtoTKmenu_index = (cCAMLtoTKindex : menu_index -> tkArgs);; +let cCAMLtoTKtext_index = (cCAMLtoTKindex : text_index -> tkArgs);; + +(* Assume returned values are only numerical and l.c *) + +let cTKtoCAMLtext_index s = + try + let p = String.index s '.' in + `Linechar (int_of_string (String.sub s ~pos:0 ~len:p), + int_of_string (String.sub s ~pos:(p + 1) + ~len:(String.length s - p - 1))) + with + Not_found -> + raise (Invalid_argument ("TKtoCAMLtext_index: " ^ s)) +;; + +let cTKtoCAMLlistbox_index s = + try `Num (int_of_string s) + with _ -> raise (Invalid_argument ("TKtoCAMLlistbox_index: " ^ s)) +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_palette.ml b/otherlibs/labltk/builtin/builtini_palette.ml new file mode 100644 index 0000000..e1fe37d --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_palette.ml @@ -0,0 +1,19 @@ +##ifdef CAMLTK + +let cCAMLtoTKpaletteType = function + GrayShades (foo) -> TkToken (string_of_int foo) + | RGBShades (r,v,b) -> TkToken (string_of_int r^"/"^ + string_of_int v^"/"^ + string_of_int b) +;; + +##else + +let cCAMLtoTKpaletteType : paletteType -> tkArgs = function + | `Gray (foo) -> TkToken (string_of_int foo) + | `Rgb (r,v,b) -> TkToken (string_of_int r ^ "/" ^ + string_of_int v ^ "/" ^ + string_of_int b) +;; + +##endif diff --git a/otherlibs/labltk/builtin/builtini_text.ml b/otherlibs/labltk/builtin/builtini_text.ml new file mode 100644 index 0000000..966c28a --- /dev/null +++ b/otherlibs/labltk/builtin/builtini_text.ml @@ -0,0 +1,64 @@ +let cCAMLtoTKtextMark x = TkToken x;; +let cTKtoCAMLtextMark x = x;; + +let cCAMLtoTKtextTag x = TkToken x;; +let cTKtoCAMLtextTag x = x;; + +##ifdef CAMLTK + +(* TextModifiers are never returned by Tk *) +let ppTextModifier = function + CharOffset n -> + if n > 0 then "+" ^ (string_of_int n) ^ "chars" + else if n = 0 then "" + else (string_of_int n) ^ "chars" + | LineOffset n -> + if n > 0 then "+" ^ (string_of_int n) ^ "lines" + else if n = 0 then "" + else (string_of_int n) ^ "lines" + | LineStart -> " linestart" + | LineEnd -> " lineend" + | WordStart -> " wordstart" + | WordEnd -> " wordend" +;; + +let ppTextIndex = function + | TextIndexNone -> "" + | TextIndex (base, ml) -> + match cCAMLtoTKindex index_text_table base with + | TkToken ppbase -> List.fold_left (^) ppbase (List.map ppTextModifier ml) + | _ -> assert false +;; + +let cCAMLtoTKtextIndex i = + TkToken (ppTextIndex i) +;; + +##else + +(* TextModifiers are never returned by Tk *) +let cCAMLtoTKtextIndex (i : textIndex) = + let ppTextModifier = function + | `Char n -> + if n > 0 then "+" ^ (string_of_int n) ^ "chars" + else if n = 0 then "" + else (string_of_int n) ^ "chars" + | `Line n -> + if n > 0 then "+" ^ (string_of_int n) ^ "lines" + else if n = 0 then "" + else (string_of_int n) ^ "lines" + | `Linestart -> " linestart" + | `Lineend -> " lineend" + | `Wordstart -> " wordstart" + | `Wordend -> " wordend" + in + let ppTextIndex (base, ml : textIndex) = + match cCAMLtoTKtext_index base with + TkToken ppbase -> + String.concat ~sep:"" (ppbase :: List.map ~f:ppTextModifier ml) + | _ -> assert false + in + TkToken (ppTextIndex i) +;; + +##endif diff --git a/otherlibs/labltk/builtin/canvas_bind.ml b/otherlibs/labltk/builtin/canvas_bind.ml new file mode 100644 index 0000000..1b46fae --- /dev/null +++ b/otherlibs/labltk/builtin/canvas_bind.ml @@ -0,0 +1,52 @@ +##ifdef CAMLTK + +let bind widget tag eventsequence action = + tkCommand [| + cCAMLtoTKwidget widget_canvas_table widget; + TkToken "bind"; + cCAMLtoTKtagOrId tag; + cCAMLtoTKeventSequence eventsequence; + begin match action with + | BindRemove -> TkToken "" + | BindSet (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)) + | BindSetBreakable (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)^ + " ; if { $BreakBindingsSequence == 1 } then { break ;} ; \ + set BreakBindingsSequence 0") + | BindExtend (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("+camlcb " ^ cbId ^ (writeeventField what)) + end + |] +;; + +##else + +let bind ~events + ?(extend = false) ?(breakable = false) ?(fields = []) + ?action widget tag = + tkCommand + [| cCAMLtoTKwidget widget; + TkToken "bind"; + cCAMLtoTKtagOrId tag; + cCAMLtoTKeventSequence events; + begin match action with None -> TkToken "" + | Some f -> + let cbId = + register_callback widget ~callback: (wrapeventInfo f fields) in + let cb = if extend then "+camlcb " else "camlcb " in + let cb = cb ^ cbId ^ writeeventField fields in + let cb = + if breakable then + cb ^ " ; if { $BreakBindingsSequence == 1 } then { break ;}" + ^ " ; set BreakBindingsSequence 0" + else cb in + TkToken cb + end + |] +;; + +##endif diff --git a/otherlibs/labltk/builtin/canvas_bind.mli b/otherlibs/labltk/builtin/canvas_bind.mli new file mode 100644 index 0000000..39ce93e --- /dev/null +++ b/otherlibs/labltk/builtin/canvas_bind.mli @@ -0,0 +1,16 @@ +##ifdef CAMLTK + +val bind : widget -> tagOrId -> + (modifier list * xEvent) list -> bindAction -> unit + +##else + +val bind : + events: event list -> + ?extend: bool -> + ?breakable: bool -> + ?fields: eventField list -> + ?action: (eventInfo -> unit) -> + canvas widget -> tagOrId -> unit + +##endif diff --git a/otherlibs/labltk/builtin/dialog.ml b/otherlibs/labltk/builtin/dialog.ml new file mode 100644 index 0000000..e6654d8 --- /dev/null +++ b/otherlibs/labltk/builtin/dialog.ml @@ -0,0 +1,45 @@ +##ifdef CAMLTK + +let create ?name parent title mesg bitmap def buttons = + let w = Widget.new_atom "toplevel" ~parent ?name in + let res = tkEval [|TkToken"tk_dialog"; + cCAMLtoTKwidget widget_any_table w; + TkToken title; + TkToken mesg; + cCAMLtoTKbitmap bitmap; + TkToken (string_of_int def); + TkTokenList (List.map (function x -> TkToken x) buttons)|] + in + int_of_string res +;; + +let create_named parent name title mesg bitmap def buttons = + let w = Widget.new_atom "toplevel" ~parent ~name in + let res = tkEval [|TkToken"tk_dialog"; + cCAMLtoTKwidget widget_any_table w; + TkToken title; + TkToken mesg; + cCAMLtoTKbitmap bitmap; + TkToken (string_of_int def); + TkTokenList (List.map (function x -> TkToken x) buttons)|] + in + int_of_string res +;; + +##else + +let create ~parent ~title ~message ~buttons ?name + ?(bitmap = `Predefined "") ?(default = -1) () = + let w = Widget.new_atom "toplevel" ?name ~parent in + let res = tkEval [|TkToken"tk_dialog"; + cCAMLtoTKwidget w; + TkToken title; + TkToken message; + cCAMLtoTKbitmap bitmap; + TkToken (string_of_int default); + TkTokenList (List.map ~f:(fun x -> TkToken x) buttons)|] + in + int_of_string res +;; + +##endif diff --git a/otherlibs/labltk/builtin/dialog.mli b/otherlibs/labltk/builtin/dialog.mli new file mode 100644 index 0000000..debb6ce --- /dev/null +++ b/otherlibs/labltk/builtin/dialog.mli @@ -0,0 +1,24 @@ +##ifdef CAMLTK + +val create : ?name: string -> + widget -> string -> string -> bitmap -> int -> string list -> int + (* [create ~name parent title message bitmap default button_names] + cf. tk_dialog *) + +val create_named : + widget -> string -> string -> string -> bitmap -> int -> string list -> int + (* [create_named parent name title message bitmap default button_names] + cf. tk_dialog *) + +##else + +val create : + parent: 'a widget -> + title: string -> + message: string -> + buttons: string list -> + ?name: string -> ?bitmap: bitmap -> ?default: int -> unit ->int + (* [create title message bitmap default button_names parent] + cf. tk_dialog *) + +##endif diff --git a/otherlibs/labltk/builtin/image.ml b/otherlibs/labltk/builtin/image.ml new file mode 100644 index 0000000..ac4c723 --- /dev/null +++ b/otherlibs/labltk/builtin/image.ml @@ -0,0 +1,33 @@ +##ifdef CAMLTK + +let cTKtoCAMLimage s = + let res = tkEval [|TkToken "image"; TkToken "type"; TkToken s|] in + match res with + | "bitmap" -> ImageBitmap (BitmapImage s) + | "photo" -> ImagePhoto (PhotoImage s) + | _ -> raise (TkError ("unknown image type \"" ^ res ^ "\"")) +;; + +let names () = + let res = tkEval [|TkToken "image"; TkToken "names"|] in + let names = splitlist res in + List.map cTKtoCAMLimage names +;; + +##else + +let cTKtoCAMLimage s = + let res = tkEval [|TkToken "image"; TkToken "type"; TkToken s|] in + match res with + | "bitmap" -> `Bitmap s + | "photo" -> `Photo s + | _ -> raise (TkError ("unknown image type \"" ^ res ^ "\"")) +;; + +let names () = + let res = tkEval [|TkToken "image"; TkToken "names"|] in + let names = splitlist res in + List.map cTKtoCAMLimage names +;; + +##endif diff --git a/otherlibs/labltk/builtin/image.mli b/otherlibs/labltk/builtin/image.mli new file mode 100644 index 0000000..a92a9f8 --- /dev/null +++ b/otherlibs/labltk/builtin/image.mli @@ -0,0 +1,9 @@ +##ifdef CAMLTK + +val names : unit -> options list + +##else + +val names : unit -> image list + +##endif diff --git a/otherlibs/labltk/builtin/optionmenu.ml b/otherlibs/labltk/builtin/optionmenu.ml new file mode 100644 index 0000000..c0a760a --- /dev/null +++ b/otherlibs/labltk/builtin/optionmenu.ml @@ -0,0 +1,54 @@ +##ifdef CAMLTK + +open Protocol;; +(* Implementation of the tk_optionMenu *) + +let create ?name parent variable values = + let w = Widget.new_atom "menubutton" ~parent ?name in + let mw = Widget.new_atom "menu" ~parent:w ~name:"menu" in + let res = + tkEval [|TkToken "tk_optionMenu"; + TkToken (Widget.name w); + cCAMLtoTKtextVariable variable; + TkTokenList (List.map (function x -> TkToken x) values)|] in + if res <> Widget.name mw then + raise (TkError "internal error in Optionmenu.create") + else + w,mw +;; + +let create_named parent name variable values = + let w = Widget.new_atom "menubutton" ~parent ~name in + let mw = Widget.new_atom "menu" ~parent:w ~name: "menu" in + let res = + tkEval [|TkToken "tk_optionMenu"; + TkToken (Widget.name w); + cCAMLtoTKtextVariable variable; + TkTokenList (List.map (function x -> TkToken x) values)|] in + if res <> Widget.name mw then + raise (TkError "internal error in Optionmenu.create") + else + w,mw +;; + +##else + +open Protocol;; +(* Implementation of the tk_optionMenu *) + +let create ~parent ~variable ?name values = + let w = Widget.new_atom "menubutton" ~parent ?name in + let mw = Widget.new_atom "menu" ~parent:w ~name:"menu" in + (* assumes .menu naming *) + let res = + tkEval [|TkToken "tk_optionMenu"; + TkToken (Widget.name w); + cCAMLtoTKtextVariable variable; + TkTokenList (List.map ~f:(fun x -> TkToken x) values)|] in + if res <> Widget.name mw then + raise (TkError "internal error in Optionmenu.create") + else + w, mw +;; + +##endif diff --git a/otherlibs/labltk/builtin/optionmenu.mli b/otherlibs/labltk/builtin/optionmenu.mli new file mode 100644 index 0000000..0c6b5c9 --- /dev/null +++ b/otherlibs/labltk/builtin/optionmenu.mli @@ -0,0 +1,21 @@ +##ifdef CAMLTK + +(* Support for tk_optionMenu *) +val create: ?name: string -> + widget -> textVariable -> string list -> widget * widget +(** [create ?name parent var options] creates a multi-option menubutton and + its associated menu. The option is also stored in the variable. + Both widgets (menubutton and menu) are returned. *) + +##else + +(* Support for tk_optionMenu *) +val create: + parent:'a widget -> + variable:textVariable -> + ?name: string -> string list -> menubutton widget * menu widget +(** [create ~parent ~var ~name options] creates a multi-option menubutton + and its associated menu. The option is also stored in the variable. + Both widgets (menubutton and menu) are returned *) + +##endif diff --git a/otherlibs/labltk/builtin/rawimg.ml b/otherlibs/labltk/builtin/rawimg.ml new file mode 100644 index 0000000..6bd0ad2 --- /dev/null +++ b/otherlibs/labltk/builtin/rawimg.ml @@ -0,0 +1,142 @@ +external rawget : string -> string + = "camltk_getimgdata" +external rawset : string -> string -> int -> int -> int -> int -> unit + = "camltk_setimgdata_bytecode" (* all int parameters MUST be positive *) + "camltk_setimgdata_native" + +type t = { + pixmap_width : int; + pixmap_height: int; + pixmap_data: string +} + +type pixel = string (* 3 chars *) + +(* pixmap will be an abstract type *) +let width pix = pix.pixmap_width +let height pix = pix.pixmap_height + + +(* note: invalid size would have been caught by String.create, but we put + * it here for documentation purpose *) +let create w h = + if w < 0 || h < 0 then invalid_arg "invalid size" + else { + pixmap_width = w; + pixmap_height = h; + pixmap_data = String.create (w * h * 3); + } + +(* + * operations on pixmaps + *) +let unsafe_copy pix_from pix_to = + String.unsafe_blit pix_from.pixmap_data 0 + pix_to.pixmap_data 0 + (String.length pix_from.pixmap_data) + +(* We check only the length. w,h might be different... *) +let copy pix_from pix_to = + let l = String.length pix_from.pixmap_data in + if l <> String.length pix_to.pixmap_data then + raise (Invalid_argument "copy: incompatible length") + else unsafe_copy pix_from pix_to + + +(* Pixel operations *) +let unsafe_get_pixel pixmap x y = + let pos = (y * pixmap.pixmap_width + x) * 3 in + let r = String.create 3 in + String.unsafe_blit pixmap.pixmap_data pos r 0 3; + r + +let unsafe_set_pixel pixmap x y pixel = + let pos = (y * pixmap.pixmap_width + x) * 3 in + String.unsafe_blit pixel 0 pixmap.pixmap_data pos 3 + +(* To get safe operations, we can either check x,y wrt [0,w[ and [0,h[ + or rely on blit checking. We choose the first for clarity. + *) +let get_pixel pix x y = + if x < 0 || y < 0 || x >= pix.pixmap_width || y >= pix.pixmap_height + then invalid_arg "invalid pixel" + else unsafe_get_pixel pix x y + +(* same check (pixel being abstract, it must be of good size *) +let set_pixel pix x y pixel = + if x < 0 || y < 0 || x >= pix.pixmap_width || y >= pix.pixmap_height + then invalid_arg "invalid pixel" + else unsafe_set_pixel pix x y pixel + +(* black as default_color, if at all needed *) +let default_color = "\000\000\000" + +(* Char.chr does range checking *) +let pixel r g b = + let s = String.create 3 in + s.[0] <- Char.chr r; + s.[1] <- Char.chr g; + s.[2] <- Char.chr b; + s + +##ifdef CAMLTK + +(* create pixmap from an existing image *) +let get photo = + match photo with + | PhotoImage s -> { + pixmap_width = CImagephoto.width photo; + pixmap_height = CImagephoto.height photo; + pixmap_data = rawget s; + } + +(* copy a full pixmap into an image *) +let set photo pix = + match photo with + | PhotoImage s -> + rawset s pix.pixmap_data 0 0 pix.pixmap_width pix.pixmap_height + +(* general blit of pixmap into image *) +let blit photo pix x y w h = + if x < 0 || y < 0 || w < 0 || h < 0 then invalid_arg "negative argument" + else match photo with + | PhotoImage s -> + rawset s pix.pixmap_data x y w h + +(* get from a file *) +let from_file filename = + let img = CImagephoto.create [File filename] in + let pix = get img in + CImagephoto.delete img; + pix + +##else + +(* create pixmap from an existing image *) +let get photo = + match photo with + | `Photo s -> { + pixmap_width = Imagephoto.width photo; + pixmap_height = Imagephoto.height photo; + pixmap_data = rawget s; + } + +(* copy a full pixmap into an image *) +let set photo pix = + match photo with + | `Photo s -> rawset s pix.pixmap_data 0 0 pix.pixmap_width pix.pixmap_height + +(* general blit of pixmap into image *) +let blit photo pix x y w h = + if x < 0 || y < 0 || w < 0 || h < 0 then invalid_arg "negative argument" + else match photo with + | `Photo s -> rawset s pix.pixmap_data x y w h + +(* get from a file *) +let from_file filename = + let img = Imagephoto.create ~file: filename () in + let pix = get img in + Imagephoto.delete img; + pix + +##endif diff --git a/otherlibs/labltk/builtin/rawimg.mli b/otherlibs/labltk/builtin/rawimg.mli new file mode 100644 index 0000000..1bb120f --- /dev/null +++ b/otherlibs/labltk/builtin/rawimg.mli @@ -0,0 +1,44 @@ +(* + * Minimal pixmap support + *) + +type t +type pixel + +val width : t -> int + (* [width pixmap] *) +val height : t -> int + (* [height pixmap] *) + +val create : int -> int -> t + (* [create width height] *) +val get : imagePhoto -> t + (* [get img] *) +val set : imagePhoto -> t -> unit + (* [set img pixmap] *) +val blit : imagePhoto -> t -> int -> int -> int -> int -> unit + (* [blit img pixmap x y w h] (all ints must be non-negative) *) +val from_file : string -> t + (* [from_file filename] *) + +val copy : t -> t -> unit + (* [copy src dst] *) + +(* + * Pixel operations + *) +val get_pixel : t -> int -> int -> pixel + (* [get_pixel pixmap x y] *) +val set_pixel : t -> int -> int -> pixel -> unit + (* [set_pixel pixmap x y pixel] *) +val default_color : pixel + +val pixel : int -> int -> int -> pixel + (* [pixel r g b] (r,g,b must be in [0..255]) *) + +(*-*) +(* unsafe *) +val unsafe_copy : t -> t -> unit +val unsafe_get_pixel : t -> int -> int -> pixel +val unsafe_set_pixel : t -> int -> int -> pixel -> unit +(* /unsafe *) diff --git a/otherlibs/labltk/builtin/report.ml b/otherlibs/labltk/builtin/report.ml new file mode 100644 index 0000000..852b4c1 --- /dev/null +++ b/otherlibs/labltk/builtin/report.ml @@ -0,0 +1,17 @@ +(* Report globals from protocol *) +let opentk = Protocol.opentk +let keywords = Protocol.keywords +let opentk_with_args = Protocol.opentk_with_args +let openTk = Protocol.openTk +let openTkClass = Protocol.openTkClass +let openTkDisplayClass = Protocol.openTkDisplayClass +let closeTk = Protocol.closeTk +let mainLoop = Protocol.mainLoop +let register = Protocol.register + +(* From support *) +let may = Support.may +let maycons = Support.maycons + +(* From widget *) +let coe = Widget.coe diff --git a/otherlibs/labltk/builtin/selection_handle_set.ml b/otherlibs/labltk/builtin/selection_handle_set.ml new file mode 100644 index 0000000..fe19489 --- /dev/null +++ b/otherlibs/labltk/builtin/selection_handle_set.ml @@ -0,0 +1,41 @@ +##ifdef CAMLTK + +(* The function *must* use tkreturn *) +let handle_set opts w cmd = + tkCommand [| + TkToken"selection"; + TkToken"handle"; + TkTokenList + (List.map + (function x -> cCAMLtoTKicccm w icccm_selection_handle_table x) + opts); + cCAMLtoTKwidget widget_any_table w; + let id = register_callback w (function args -> + let (a1,args) = int_of_string (List.hd args), List.tl args in + let (a2,args) = int_of_string (List.hd args), List.tl args in + cmd a1 a2) in + TkToken ("camlcb "^id) + |] +;; + +##else + +(* The function *must* use tkreturn *) +let handle_set ~command = +selection_handle_icccm_optionals (fun opts w -> + tkCommand [| + TkToken"selection"; + TkToken"handle"; + TkTokenList opts; + cCAMLtoTKwidget w; + let id = register_callback w ~callback: + begin fun args -> + let pos = int_of_string (List.hd args) in + let len = int_of_string (List.nth args 1) in + tkreturn (command ~pos ~len) + end + in TkToken ("camlcb " ^ id) + |]) +;; + +##endif diff --git a/otherlibs/labltk/builtin/selection_handle_set.mli b/otherlibs/labltk/builtin/selection_handle_set.mli new file mode 100644 index 0000000..66ae6b7 --- /dev/null +++ b/otherlibs/labltk/builtin/selection_handle_set.mli @@ -0,0 +1,13 @@ +##ifdef CAMLTK + +val handle_set : icccm list -> widget -> (int -> int -> unit) -> unit +(** tk invocation: selection handle <icccm list> <widget> <command> *) + +##else + +val handle_set : + command: (pos:int -> len:int -> string) -> + ?format: string -> ?selection:string -> ?typ: string -> 'a widget -> unit +(** tk invocation: selection handle <icccm list> <widget> <command> *) + +##endif diff --git a/otherlibs/labltk/builtin/selection_own_set.ml b/otherlibs/labltk/builtin/selection_own_set.ml new file mode 100644 index 0000000..253cdb5 --- /dev/null +++ b/otherlibs/labltk/builtin/selection_own_set.ml @@ -0,0 +1,29 @@ +##ifdef CAMLTK + +(* builtin to handle callback association to widget *) +let own_set v1 v2 = + tkCommand [| + TkToken"selection"; + TkToken"own"; + TkTokenList + (List.map + (function x -> cCAMLtoTKicccm v2 icccm_selection_ownset_table x) + v1); + cCAMLtoTKwidget widget_any_table v2 + |] +;; + +##else + +(* builtin to handle callback association to widget *) +let own_set ?command = + selection_ownset_icccm_optionals ?command (fun opts w -> + tkCommand [| + TkToken"selection"; + TkToken"own"; + TkTokenList opts; + cCAMLtoTKwidget w + |]) +;; + +##endif diff --git a/otherlibs/labltk/builtin/selection_own_set.mli b/otherlibs/labltk/builtin/selection_own_set.mli new file mode 100644 index 0000000..95b3de3 --- /dev/null +++ b/otherlibs/labltk/builtin/selection_own_set.mli @@ -0,0 +1,12 @@ +##ifdef CAMLTK + +val own_set : icccm list -> widget -> unit +(** tk invocation: selection own <icccm list> <widget> *) + +##else + +val own_set : + ?command:(unit->unit) -> ?selection:string -> 'a widget -> unit +(** tk invocation: selection own <icccm list> <widget> *) + +##endif diff --git a/otherlibs/labltk/builtin/text_tag_bind.ml b/otherlibs/labltk/builtin/text_tag_bind.ml new file mode 100644 index 0000000..7a1bab3 --- /dev/null +++ b/otherlibs/labltk/builtin/text_tag_bind.ml @@ -0,0 +1,55 @@ +##ifdef CAMLTK + +let tag_bind widget tag eventsequence action = + check_class widget widget_text_table; + tkCommand [| + cCAMLtoTKwidget widget_text_table widget; + TkToken "tag"; + TkToken "bind"; + cCAMLtoTKtextTag tag; + cCAMLtoTKeventSequence eventsequence; + begin match action with + | BindRemove -> TkToken "" + | BindSet (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what)) + | BindSetBreakable (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("camlcb " ^ cbId ^ (writeeventField what) ^ + " ; if { $BreakBindingsSequence == 1 } then { break ;} ; \ + set BreakBindingsSequence 0") + | BindExtend (what, f) -> + let cbId = register_callback widget (wrapeventInfo f what) in + TkToken ("+camlcb " ^ cbId ^ (writeeventField what)) + end + |] +;; + +##else + +let tag_bind ~tag ~events ?(extend = false) ?(breakable = false) + ?(fields = []) ?action widget = + tkCommand [| + cCAMLtoTKwidget widget; + TkToken "tag"; + TkToken "bind"; + cCAMLtoTKtextTag tag; + cCAMLtoTKeventSequence events; + begin match action with + | None -> TkToken "" + | Some f -> + let cbId = + register_callback widget ~callback: (wrapeventInfo f fields) in + let cb = if extend then "+camlcb " else "camlcb " in + let cb = cb ^ cbId ^ writeeventField fields in + let cb = + if breakable then + cb ^ " ; if { $BreakBindingsSequence == 1 } then { break ;}" + ^ " ; set BreakBindingsSequence 0" + else cb in + TkToken cb + end + |] +;; + +##endif diff --git a/otherlibs/labltk/builtin/text_tag_bind.mli b/otherlibs/labltk/builtin/text_tag_bind.mli new file mode 100644 index 0000000..1f334a7 --- /dev/null +++ b/otherlibs/labltk/builtin/text_tag_bind.mli @@ -0,0 +1,13 @@ +##ifdef CAMLTK + +val tag_bind: + widget -> textTag -> (modifier list * xEvent) list -> bindAction -> unit + +##else + +val tag_bind : + tag: string -> events: event list -> + ?extend: bool -> ?breakable: bool -> ?fields: eventField list -> + ?action: (eventInfo -> unit) -> text widget -> unit + +##endif diff --git a/otherlibs/labltk/builtin/winfo_contained.ml b/otherlibs/labltk/builtin/winfo_contained.ml new file mode 100644 index 0000000..f1fb373 --- /dev/null +++ b/otherlibs/labltk/builtin/winfo_contained.ml @@ -0,0 +1,13 @@ +##ifdef CAMLTK + +let contained x y w = + w = containing x y +;; + +##else + +let contained ~x ~y w = + forget_type w = containing ~x ~y () +;; + +##endif diff --git a/otherlibs/labltk/builtin/winfo_contained.mli b/otherlibs/labltk/builtin/winfo_contained.mli new file mode 100644 index 0000000..41cc57c --- /dev/null +++ b/otherlibs/labltk/builtin/winfo_contained.mli @@ -0,0 +1,11 @@ +##ifdef CAMLTK + +val contained : int -> int -> widget -> bool +(** [contained x y w] returns true if (x,y) is in w *) + +##else + +val contained : x:int -> y:int -> 'a widget -> bool +(** [contained x y w] returns true if (x,y) is in w *) + +##endif diff --git a/otherlibs/labltk/camltk/.cvsignore b/otherlibs/labltk/camltk/.cvsignore new file mode 100644 index 0000000..5850676 --- /dev/null +++ b/otherlibs/labltk/camltk/.cvsignore @@ -0,0 +1,3 @@ +*.ml *.mli labltktop labltk +modules +.depend diff --git a/otherlibs/labltk/camltk/Makefile b/otherlibs/labltk/camltk/Makefile new file mode 100644 index 0000000..19300ea --- /dev/null +++ b/otherlibs/labltk/camltk/Makefile @@ -0,0 +1,43 @@ +include ../support/Makefile.common + +COMPFLAGS= -I ../support -I $(OTHERS)/win32unix -I $(OTHERS)/unix + +all: camltkobjs + +opt: camltkobjsx + +include ./modules + +CAMLTKOBJS= $(CWIDGETOBJS) cTk.cmo camltk.cmo +CAMLTKOBJSX = $(CAMLTKOBJS:.cmo=.cmx) + +camltkobjs: $(CAMLTKOBJS) + +camltkobjsx: $(CAMLTKOBJSX) + +clean: + $(MAKE) -f Makefile.gen clean + +install: + if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(CAMLTKOBJS:.cmo=.cmi) $(CWIDGETOBJS:.cmo=.mli) $(INSTALLDIR) + chmod 644 $(INSTALLDIR)/*.cmi + +installopt: + @if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(CAMLTKOBJSX) $(INSTALLDIR) + chmod 644 $(INSTALLDIR)/*.cmx + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmx .cmo .mlp + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +include .depend diff --git a/otherlibs/labltk/camltk/Makefile.gen b/otherlibs/labltk/camltk/Makefile.gen new file mode 100644 index 0000000..bedc9c5 --- /dev/null +++ b/otherlibs/labltk/camltk/Makefile.gen @@ -0,0 +1,52 @@ +include ../support/Makefile.common + +all: cTk.ml camltk.ml .depend + +_tkgen.ml: ../Widgets.src ../compiler/tkcompiler$(EXE) + cd ..; $(CAMLRUNGEN) compiler/tkcompiler$(EXE) -camltk -outdir camltk + +#cTk.ml camltk.ml .depend: generate + +cTk.ml camltk.ml .depend: _tkgen.ml ../builtin/report.ml ../compiler/pp$(EXE) #../builtin/builtin_*.ml + (echo '##define CAMLTK'; \ + echo 'include Camltkwrap'; \ + echo 'open Widget'; \ + echo 'open Protocol'; \ + echo 'open Textvariable'; \ + echo ; \ + cat ../builtin/report.ml; \ + echo ; \ + cat ../builtin/builtin_*.ml; \ + echo ; \ + cat _tkgen.ml; \ + echo ; \ + echo ; \ + echo 'module Tkintf = struct'; \ + cat ../builtin/builtini_*.ml; \ + cat _tkigen.ml; \ + echo 'end (* module Tkintf *)'; \ + echo ; \ + echo ; \ + echo 'open Tkintf' ;\ + echo ; \ + echo ; \ + cat ../builtin/builtinf_*.ml; \ + cat _tkfgen.ml; \ + echo ; \ + ) > _cTk.ml + $(CAMLRUN) ../compiler/pp < _cTk.ml > cTk.ml + rm -f _cTk.ml + $(CAMLDEP) -slash -I ../support [a-z]*.mli [a-z]*.ml > .depend + +../compiler/pp$(EXE): + cd ../compiler; $(MAKE) pp($EXE) + +../compiler/tkcompiler$(EXE): + cd ../compiler; $(MAKE) tkcompiler($EXE) + +# All .{ml,mli} files are generated in this directory +clean: + rm -f *.cm* *.ml *.mli *.$(O) *.$(A) .depend +# rm -f modules + +.PHONY: all generate clean diff --git a/otherlibs/labltk/camltk/Makefile.gen.nt b/otherlibs/labltk/camltk/Makefile.gen.nt new file mode 100644 index 0000000..046b878 --- /dev/null +++ b/otherlibs/labltk/camltk/Makefile.gen.nt @@ -0,0 +1 @@ +include Makefile.gen diff --git a/otherlibs/labltk/camltk/Makefile.nt b/otherlibs/labltk/camltk/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/camltk/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/camltk/byte.itarget b/otherlibs/labltk/camltk/byte.itarget new file mode 100644 index 0000000..1b841be --- /dev/null +++ b/otherlibs/labltk/camltk/byte.itarget @@ -0,0 +1,9 @@ +cPlace.cmo cResource.cmo cWm.cmo cImagephoto.cmo cCanvas.cmo cButton.cmo +cText.cmo cLabel.cmo cScrollbar.cmo cImage.cmo cEncoding.cmo cPixmap.cmo +cPalette.cmo cFont.cmo cMessage.cmo cMenu.cmo cEntry.cmo cListbox.cmo +cFocus.cmo cMenubutton.cmo cPack.cmo cOption.cmo cToplevel.cmo cFrame.cmo +cDialog.cmo cImagebitmap.cmo cClipboard.cmo cRadiobutton.cmo cTkwait.cmo +cGrab.cmo cSelection.cmo cScale.cmo cOptionmenu.cmo cWinfo.cmo cGrid.cmo +cCheckbutton.cmo cBell.cmo cTkvars.cmo + +cTk.cmo camltk.cmo diff --git a/otherlibs/labltk/camltk/modules b/otherlibs/labltk/camltk/modules new file mode 100644 index 0000000..c1a2eed --- /dev/null +++ b/otherlibs/labltk/camltk/modules @@ -0,0 +1,80 @@ +CWIDGETOBJS=cPlace.cmo cResource.cmo cWm.cmo cImagephoto.cmo cCanvas.cmo cButton.cmo cText.cmo cLabel.cmo cScrollbar.cmo cImage.cmo cEncoding.cmo cPixmap.cmo cPalette.cmo cFont.cmo cMessage.cmo cMenu.cmo cEntry.cmo cListbox.cmo cFocus.cmo cMenubutton.cmo cPack.cmo cOption.cmo cToplevel.cmo cFrame.cmo cDialog.cmo cImagebitmap.cmo cClipboard.cmo cRadiobutton.cmo cTkwait.cmo cGrab.cmo cSelection.cmo cScale.cmo cOptionmenu.cmo cWinfo.cmo cGrid.cmo cCheckbutton.cmo cBell.cmo cTkvars.cmo +cPlace.ml cResource.ml cWm.ml cImagephoto.ml cCanvas.ml cButton.ml cText.ml cLabel.ml cScrollbar.ml cImage.ml cEncoding.ml cPixmap.ml cPalette.ml cFont.ml cMessage.ml cMenu.ml cEntry.ml cListbox.ml cFocus.ml cMenubutton.ml cPack.ml cOption.ml cToplevel.ml cFrame.ml cDialog.ml cImagebitmap.ml cClipboard.ml cRadiobutton.ml cTkwait.ml cGrab.ml cSelection.ml cScale.ml cOptionmenu.ml cWinfo.ml cGrid.ml cCheckbutton.ml cBell.ml cTkvars.ml : _tkgen.ml + +cPlace.cmo : cPlace.ml +cPlace.cmi : cPlace.mli +cResource.cmo : cResource.ml +cResource.cmi : cResource.mli +cWm.cmo : cWm.ml +cWm.cmi : cWm.mli +cImagephoto.cmo : cImagephoto.ml +cImagephoto.cmi : cImagephoto.mli +cCanvas.cmo : cCanvas.ml +cCanvas.cmi : cCanvas.mli +cButton.cmo : cButton.ml +cButton.cmi : cButton.mli +cText.cmo : cText.ml +cText.cmi : cText.mli +cLabel.cmo : cLabel.ml +cLabel.cmi : cLabel.mli +cScrollbar.cmo : cScrollbar.ml +cScrollbar.cmi : cScrollbar.mli +cImage.cmo : cImage.ml +cImage.cmi : cImage.mli +cEncoding.cmo : cEncoding.ml +cEncoding.cmi : cEncoding.mli +cPixmap.cmo : cPixmap.ml +cPixmap.cmi : cPixmap.mli +cPalette.cmo : cPalette.ml +cPalette.cmi : cPalette.mli +cFont.cmo : cFont.ml +cFont.cmi : cFont.mli +cMessage.cmo : cMessage.ml +cMessage.cmi : cMessage.mli +cMenu.cmo : cMenu.ml +cMenu.cmi : cMenu.mli +cEntry.cmo : cEntry.ml +cEntry.cmi : cEntry.mli +cListbox.cmo : cListbox.ml +cListbox.cmi : cListbox.mli +cFocus.cmo : cFocus.ml +cFocus.cmi : cFocus.mli +cMenubutton.cmo : cMenubutton.ml +cMenubutton.cmi : cMenubutton.mli +cPack.cmo : cPack.ml +cPack.cmi : cPack.mli +cOption.cmo : cOption.ml +cOption.cmi : cOption.mli +cToplevel.cmo : cToplevel.ml +cToplevel.cmi : cToplevel.mli +cFrame.cmo : cFrame.ml +cFrame.cmi : cFrame.mli +cDialog.cmo : cDialog.ml +cDialog.cmi : cDialog.mli +cImagebitmap.cmo : cImagebitmap.ml +cImagebitmap.cmi : cImagebitmap.mli +cClipboard.cmo : cClipboard.ml +cClipboard.cmi : cClipboard.mli +cRadiobutton.cmo : cRadiobutton.ml +cRadiobutton.cmi : cRadiobutton.mli +cTkwait.cmo : cTkwait.ml +cTkwait.cmi : cTkwait.mli +cGrab.cmo : cGrab.ml +cGrab.cmi : cGrab.mli +cSelection.cmo : cSelection.ml +cSelection.cmi : cSelection.mli +cScale.cmo : cScale.ml +cScale.cmi : cScale.mli +cOptionmenu.cmo : cOptionmenu.ml +cOptionmenu.cmi : cOptionmenu.mli +cWinfo.cmo : cWinfo.ml +cWinfo.cmi : cWinfo.mli +cGrid.cmo : cGrid.ml +cGrid.cmi : cGrid.mli +cCheckbutton.cmo : cCheckbutton.ml +cCheckbutton.cmi : cCheckbutton.mli +cBell.cmo : cBell.ml +cBell.cmi : cBell.mli +cTkvars.cmo : cTkvars.ml +cTkvars.cmi : cTkvars.mli +camltk.cmo : cTk.cmo cPlace.cmo cResource.cmo cWm.cmo cImagephoto.cmo cCanvas.cmo cButton.cmo cText.cmo cLabel.cmo cScrollbar.cmo cImage.cmo cEncoding.cmo cPixmap.cmo cPalette.cmo cFont.cmo cMessage.cmo cMenu.cmo cEntry.cmo cListbox.cmo cFocus.cmo cMenubutton.cmo cPack.cmo cOption.cmo cToplevel.cmo cFrame.cmo cDialog.cmo cImagebitmap.cmo cClipboard.cmo cRadiobutton.cmo cTkwait.cmo cGrab.cmo cSelection.cmo cScale.cmo cOptionmenu.cmo cWinfo.cmo cGrid.cmo cCheckbutton.cmo cBell.cmo cTkvars.cmo diff --git a/otherlibs/labltk/camltk/native.itarget b/otherlibs/labltk/camltk/native.itarget new file mode 100644 index 0000000..9c589f1 --- /dev/null +++ b/otherlibs/labltk/camltk/native.itarget @@ -0,0 +1,7 @@ +cPlace.cmx cResource.cmx cWm.cmx cImagephoto.cmx cCanvas.cmx cButton.cmx +cText.cmx cLabel.cmx cScrollbar.cmx cImage.cmx cEncoding.cmx cPixmap.cmx +cPalette.cmx cFont.cmx cMessage.cmx cMenu.cmx cEntry.cmx cListbox.cmx +cFocus.cmx cMenubutton.cmx cPack.cmx cOption.cmx cToplevel.cmx cFrame.cmx +cDialog.cmx cImagebitmap.cmx cClipboard.cmx cRadiobutton.cmx cTkwait.cmx +cGrab.cmx cSelection.cmx cScale.cmx cOptionmenu.cmx cWinfo.cmx cGrid.cmx +cCheckbutton.cmx cBell.cmx cTkvars.cmx diff --git a/otherlibs/labltk/compiler/.cvsignore b/otherlibs/labltk/compiler/.cvsignore new file mode 100644 index 0000000..060114e --- /dev/null +++ b/otherlibs/labltk/compiler/.cvsignore @@ -0,0 +1,11 @@ +lexer.ml +parser.output +parser.ml +parser.mli +tkcompiler +pp +copyright.ml +pplex.ml +ppyac.ml +ppyac.output +ppyac.mli diff --git a/otherlibs/labltk/compiler/.depend b/otherlibs/labltk/compiler/.depend new file mode 100644 index 0000000..d33149e --- /dev/null +++ b/otherlibs/labltk/compiler/.depend @@ -0,0 +1,28 @@ +pplex.cmi: ppyac.cmi +ppyac.cmi: code.cmi +compile.cmo: code.cmi flags.cmo ppexec.cmo ppparse.cmo tables.cmo +compile.cmx: code.cmi flags.cmx ppexec.cmx ppparse.cmx tables.cmx +intf.cmo: code.cmi compile.cmo flags.cmo ppexec.cmo ppparse.cmo tables.cmo +intf.cmx: code.cmi compile.cmx flags.cmx ppexec.cmx ppparse.cmx tables.cmx +lexer.cmo: parser.cmi +lexer.cmx: parser.cmx +maincompile.cmo: code.cmi compile.cmo flags.cmo intf.cmo lexer.cmo parser.cmi \ + ppexec.cmo ppparse.cmo printer.cmo tables.cmo tsort.cmo +maincompile.cmx: code.cmi compile.cmx flags.cmx intf.cmx lexer.cmx parser.cmx \ + ppexec.cmx ppparse.cmx printer.cmx tables.cmx tsort.cmx +parser.cmo: flags.cmo tables.cmo parser.cmi +parser.cmx: flags.cmx tables.cmx parser.cmi +pp.cmo: ppexec.cmo ppparse.cmo +pp.cmx: ppexec.cmx ppparse.cmx +ppexec.cmo: code.cmi +ppexec.cmx: code.cmi +pplex.cmo: ppyac.cmi pplex.cmi +pplex.cmx: ppyac.cmx pplex.cmi +ppparse.cmo: pplex.cmi ppyac.cmi +ppparse.cmx: pplex.cmx ppyac.cmx +ppyac.cmo: code.cmi ppyac.cmi +ppyac.cmx: code.cmi ppyac.cmi +printer.cmo: tables.cmo +printer.cmx: tables.cmx +tables.cmo: tsort.cmo +tables.cmx: tsort.cmx diff --git a/otherlibs/labltk/compiler/Makefile b/otherlibs/labltk/compiler/Makefile new file mode 100644 index 0000000..a2b8453 --- /dev/null +++ b/otherlibs/labltk/compiler/Makefile @@ -0,0 +1,63 @@ +include ../support/Makefile.common + +OBJS= ../support/support.cmo flags.cmo copyright.cmo \ + tsort.cmo tables.cmo printer.cmo lexer.cmo \ + pplex.cmo ppyac.cmo ppexec.cmo ppparse.cmo \ + parser.cmo compile.cmo intf.cmo maincompile.cmo + +PPOBJS= pplex.cmo ppyac.cmo ppexec.cmo ppparse.cmo pp.cmo + +all: tkcompiler$(EXE) pp$(EXE) + +tkcompiler$(EXE) : $(OBJS) + $(CAMLC) -g $(LINKFLAGS) -o tkcompiler$(EXE) $(OBJS) + +pp$(EXE): $(PPOBJS) + $(CAMLC) -g $(LINKFLAGS) -o pp$(EXE) $(PPOBJS) + +lexer.ml: lexer.mll + $(CAMLLEX) lexer.mll + +parser.ml parser.mli: parser.mly + $(CAMLYACC) -v parser.mly + +pplex.ml: pplex.mll + $(CAMLLEX) pplex.mll + +pplex.mli: ppyac.cmi + +ppyac.ml ppyac.mli: ppyac.mly + $(CAMLYACC) -v ppyac.mly + +copyright.ml: copyright + (echo "let copyright=\"\\"; \ + cat copyright; \ + echo "\""; \ + echo "let write ~w = w copyright;;") > copyright.ml + +clean : + rm -f *.cm* parser.ml parser.mli lexer.ml copyright.ml + rm -f pplex.ml ppyac.ml ppyac.mli ppyac.output + rm -f tkcompiler$(EXE) pp$(EXE) parser.output + +scratch : + rm -f *.cm* parser.ml parser.mli lexer.ml tkcompiler$(EXE) + rm -f *.cm* pplex.ml ppyac.ml ppyac.mli pp$(EXE) + +install: + cp tkcompiler$(EXE) $(INSTALLDIR) + cp pp$(EXE) $(INSTALLDIR) + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo .mlp + +.mli.cmi: + $(CAMLCOMP) -g $(COMPFLAGS) -I ../support $< + +.ml.cmo: + $(CAMLCOMP) -g $(COMPFLAGS) -I ../support $< + +depend: parser.ml parser.mli lexer.ml pplex.ml ppyac.ml ppyac.mli + $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/otherlibs/labltk/compiler/Makefile.nt b/otherlibs/labltk/compiler/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/compiler/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/compiler/code.mli b/otherlibs/labltk/compiler/code.mli new file mode 100644 index 0000000..6f3e292 --- /dev/null +++ b/otherlibs/labltk/compiler/code.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +type code = + | Line of string + | Ifdef of bool * string * code list * code list option + | Define of string + | Undef of string +;; diff --git a/otherlibs/labltk/compiler/compile.ml b/otherlibs/labltk/compiler/compile.ml new file mode 100644 index 0000000..c0b0b33 --- /dev/null +++ b/otherlibs/labltk/compiler/compile.ml @@ -0,0 +1,1074 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: compile.ml,v 1.32 2005-01-28 16:13:11 doligez Exp $ *) + +open StdLabels +open Tables + +(* CONFIGURE *) +(* if you set it true, ImagePhoto and ImageBitmap will annoy you... *) +let safetype = true + +let labeloff ~at l = match l with + "", t -> t +| l, t -> raise (Failure ("labeloff: " ^ l ^ " at " ^ at)) + +let labltk_labelstring l = + if l = "" then l else + if l.[0] = '?' then l ^ ":" else + "~" ^ l ^ ":" + +let camltk_labelstring l = + if l = "" then l else + if l.[0] = '?' then l ^ ":" else "" + +let labelstring l = + if !Flags.camltk then camltk_labelstring l + else labltk_labelstring l + +let labltk_typelabel l = + if l = "" then l else l ^ ":" + +let camltk_typelabel l = + if l = "" then l + else if l.[0] = '?' then l ^ ":" else "" + +let typelabel l = + if !Flags.camltk then camltk_typelabel l + else labltk_typelabel l + +let forbidden = [ "class"; "type"; "in"; "from"; "to" ] +let nicknames = + [ "class", "clas"; + "type", "typ" ] + +let small = String.lowercase + +let gettklabel fc = + match fc.template with + ListArg( StringArg s :: _ ) -> + let s = small s in + if s = "" then s else + let s = + if s.[0] = '-' + then String.sub s ~pos:1 ~len:(String.length s - 1) + else s + in begin + if List.mem s forbidden then + try List.assoc s nicknames + with Not_found -> small fc.var_name + else s + end + | _ -> raise (Failure "gettklabel") + +let count ~item:x l = + let count = ref 0 in + List.iter ~f:(fun y -> if x = y then incr count) l; + !count + +(* Extract all types from a template *) +let rec types_of_template = function + StringArg _ -> [] + | TypeArg (l, t) -> [l, t] + | ListArg l -> List.flatten (List.map ~f:types_of_template l) + | OptionalArgs (l, tl, _) -> + begin + match List.flatten (List.map ~f:types_of_template tl) with + ["", t] -> ["?" ^ l, t] + | [_, _] -> raise (Failure "0 label required") + | _ -> raise (Failure "0 or more than 1 args in for optionals") + end + +(* + * Pretty print a type + * used to write ML type definitions + *) +let ppMLtype ?(any=false) ?(return=false) ?(def=false) ?(counter=ref 0) = + let rec ppMLtype = + function + Unit -> "unit" + | Int -> "int" + | Float -> "float" + | Bool -> "bool" + | Char -> "char" + | String -> "string" +(* new *) + | List (Subtype (sup, sub)) -> + if !Flags.camltk then "(* " ^ sub ^ " *) " ^ sup ^ " list" + else begin + if return then + sub ^ "_" ^ sup ^ " list" + else begin + try + let typdef = Hashtbl.find types_table sup in + let fcl = List.assoc sub typdef.subtypes in + let tklabels = List.map ~f:gettklabel fcl in + let l = List.map fcl ~f: + begin fun fc -> + "?" ^ begin let p = gettklabel fc in + if count ~item:p tklabels > 1 then small fc.var_name else p + end + ^ ":" ^ + let l = types_of_template fc.template in + match l with + [] -> "unit" + | [lt] -> ppMLtype (labeloff lt ~at:"ppMLtype") + | l -> + "(" ^ String.concat ~sep:"*" + (List.map l + ~f:(fun lt -> ppMLtype (labeloff lt ~at:"ppMLtype"))) + ^ ")" + end in + String.concat ~sep:" ->\n" l + with + Not_found -> Printf.eprintf "ppMLtype %s/%s\n" sup sub; exit (-1) + end + end + | List ty -> (ppMLtype ty) ^ " list" + | Product tyl -> + "(" ^ String.concat ~sep:" * " (List.map ~f:ppMLtype tyl) ^ ")" + | Record tyl -> + String.concat ~sep:" * " + (List.map tyl ~f:(fun (l, t) -> typelabel l ^ ppMLtype t)) + | Subtype ("widget", sub) -> + if !Flags.camltk then "(* " ^ sub ^" *) widget" else sub ^ " widget" + | UserDefined "widget" -> + if !Flags.camltk then "widget" + else begin + if any then "any widget" else + let c = String.make 1 (Char.chr(Char.code 'a' + !counter)) in + incr counter; + "'" ^ c ^ " widget" + end + | UserDefined s -> + if !Flags.camltk then s + else begin + (* a bit dirty hack for ImageBitmap and ImagePhoto *) + try + let typdef = Hashtbl.find types_table s in + if typdef.variant then + if return then try + "[>" ^ + String.concat ~sep:"|" + (List.map typdef.constructors ~f: + begin + fun c -> + "`" ^ c.var_name ^ + (match types_of_template c.template with + [] -> "" + | l -> " of " ^ ppMLtype (Product (List.map l + ~f:(labeloff ~at:"ppMLtype UserDefined")))) + end) ^ "]" + with + Not_found -> prerr_endline ("ppMLtype " ^ s ^ " ?"); s + else if not def && List.length typdef.constructors > 1 then + "[< " ^ s ^ "]" + else s + else s + with Not_found -> s + end + | Subtype (s, s') -> + if !Flags.camltk then "(* " ^ s' ^ " *) " ^ s else s' ^ "_" ^ s + | Function (Product tyl) -> + raise (Failure "Function (Product tyl) ? ppMLtype") + | Function (Record tyl) -> + "(" ^ String.concat ~sep:" -> " + (List.map tyl ~f:(fun (l, t) -> typelabel l ^ ppMLtype t)) + ^ " -> unit)" + | Function ty -> + "(" ^ (ppMLtype ty) ^ " -> unit)" + | As (t, s) -> + if !Flags.camltk then ppMLtype t + else s + in + ppMLtype + +(* Produce a documentation version of a template *) +let rec ppTemplate = function + StringArg s -> s + | TypeArg (l, t) -> "<" ^ ppMLtype t ^ ">" + | ListArg l -> "{" ^ String.concat ~sep:" " (List.map ~f:ppTemplate l) ^ "}" + | OptionalArgs (l, tl, d) -> + "?" ^ l ^ "{" ^ String.concat ~sep:" " (List.map ~f:ppTemplate tl) + ^ "}[<" ^ String.concat ~sep:" " (List.map ~f:ppTemplate d) ^ ">]" + +let doc_of_template = function + ListArg l -> String.concat ~sep:" " (List.map ~f:ppTemplate l) + | t -> ppTemplate t + +(* + * Type definitions + *) + +(* Write an ML constructor *) +let write_constructor ~w {ml_name = mlconstr; template = t} = + w mlconstr; + begin match types_of_template t with + [] -> () + | l -> w " of "; + w (ppMLtype ~any:true (Product (List.map l + ~f:(labeloff ~at:"write_constructor")))) + end; + w " (* tk option: "; w (doc_of_template t); w " *)" + +(* Write a rhs type decl *) +let write_constructors ~w = function + [] -> fatal_error "empty type" + | x :: l -> + write_constructor ~w x; + List.iter l ~f: + begin fun x -> + w "\n | "; + write_constructor ~w x + end + +(* Write an ML variant *) +let write_variant ~w {var_name = varname; template = t} = + w "`"; + w varname; + begin match types_of_template t with + [] -> () + | l -> + w " of "; + w (ppMLtype ~any:true ~def:true + (Product (List.map l ~f:(labeloff ~at:"write_variant")))) + end; + w " (* tk option: "; w (doc_of_template t); w " *)" + +let write_variants ~w = function + [] -> fatal_error "empty variants" + | l -> + List.iter l ~f: + begin fun x -> + w "\n | "; + write_variant ~w x + end + +(* Definition of a type *) +let labltk_write_type ~intf:w ~impl:w' name ~def:typdef = + (* Only needed if no subtypes, otherwise use optionals *) + if typdef.subtypes = [] then begin + w "(* Variant type *)\n"; + w ("type " ^ name ^ " = ["); + write_variants ~w (sort_components typdef.constructors); + w "\n]\n\n" + end + +(* CamlTk: List of constructors, for runtime subtyping *) +let write_constructor_set ~w ~sep = function + | [] -> fatal_error "empty type" + | x::l -> + w ("C" ^ x.ml_name); + List.iter l ~f: (function x -> + w sep; + w ("C" ^ x.ml_name)) + +(* CamlTk: Definition of a type *) +let camltk_write_type ~intf:w ~impl:w' name ~def:typdef = + (* Put markers for extraction *) + w "(* type *)\n"; + w ("type " ^ name ^ " =\n"); + w " | "; + write_constructors ~w (sort_components typdef.constructors); + w "\n(* /type *)\n\n"; + (* Dynamic Subtyping *) + if typdef.subtypes <> [] then begin + (* The set of its constructors *) + if name = "options" then begin + w "(* type *)\n"; + w ("type "^name^"_constrs =\n\t") + end else begin + (* added some prefix to avoid being picked up in documentation *) + w ("(* no doc *) type "^name^"_constrs =\n") + end; + w " | "; + write_constructor_set ~w:w ~sep: "\n | " + (sort_components typdef.constructors); + w "\n\n"; + (* The set of all constructors *) + w' ("let "^name^"_any_table = ["); + write_constructor_set ~w:w' ~sep:"; " + (sort_components typdef.constructors); + w' ("]\n\n"); + (* The subset of constructors for each subtype *) + List.iter ~f:(function (s,l) -> + w' ("let "^name^"_"^s^"_table = ["); + write_constructor_set ~w:w' ~sep:"; " (sort_components l); + w' ("]\n\n")) + typdef.subtypes + end + +let write_type ~intf:w ~impl:w' name ~def:typdef = + (if !Flags.camltk then camltk_write_type else labltk_write_type) + ~intf:w ~impl:w' name ~def:typdef + +(************************************************************) +(* Converters *) +(************************************************************) + +let rec converterTKtoCAML ~arg = function + | Int -> "int_of_string " ^ arg + | Float -> "float_of_string " ^ arg + | Bool -> "(match " ^ arg ^ " with + | \"1\" -> true + | \"0\" -> false + | s -> Pervasives.raise (Invalid_argument (\"cTKtoCAMLbool\" ^ s)))" + | Char -> "String.get " ^ arg ^ " 0" + | String -> arg + | UserDefined s -> "cTKtoCAML" ^ s ^ " " ^ arg + | Subtype ("widget", s') when not !Flags.camltk -> + String.concat ~sep:" " + ["(Obj.magic (cTKtoCAMLwidget "; arg; ") :"; s'; "widget)"] + | Subtype (s, s') -> + if !Flags.camltk then + "cTKtoCAML" ^ s ^ " " ^ arg + else + "cTKtoCAML" ^ s' ^ "_" ^ s ^ " " ^ arg + | List ty -> + begin match type_parser_arity ty with + OneToken -> + String.concat ~sep:" " + ["(List.map (function x ->"; + converterTKtoCAML ~arg:"x" ty; ")"; arg; ")"] + | MultipleToken -> + String.concat ~sep:" " + ["iterate_converter (function x ->"; + converterTKtoCAML ~arg:"x" ty; ")"; arg; ")"] + end + | As (ty, _) -> converterTKtoCAML ~arg ty + | t -> + prerr_endline ("ERROR with " ^ arg ^ " " ^ ppMLtype t); + fatal_error "converterTKtoCAML" + + +(*******************************) +(* Wrappers *) +(*******************************) +let varnames ~prefix n = + let rec var i = + if i > n then [] + else (prefix ^ string_of_int i) :: var (succ i) + in var 1 + +(* + * generate wrapper source for callbacks + * transform a function ... -> unit in a function : unit -> unit + * using primitives arg_ ... from the protocol + * Warning: sequentiality is important in generated code + * TODO: remove arg_ stuff and process lists directly ? + *) + +let rec wrapper_code ~name ty = + match ty with + Unit -> "(fun _ -> " ^ name ^ " ())" + | As (ty, _) -> wrapper_code ~name ty + | ty -> + "(fun args ->\n " ^ + begin match ty with + Product tyl -> raise (Failure "Product -> record was done. ???") + | Record tyl -> + (* variables for each component of the product *) + let vnames = varnames ~prefix:"a" (List.length tyl) in + (* getting the arguments *) + let readarg = + List.map2 vnames tyl ~f: + begin fun v (l, ty) -> + match type_parser_arity ty with + OneToken -> + "let (" ^ v ^ ", args) = " ^ + converterTKtoCAML ~arg:"(List.hd args)" ty ^ + ", List.tl args in\n " + | MultipleToken -> + "let (" ^ v ^ ", args) = " ^ + converterTKtoCAML ~arg:"args" ty ^ + " in\n " + end in + String.concat ~sep:"" readarg ^ name ^ " " ^ + String.concat ~sep:" " + (List.map2 ~f:(fun v (l, _) -> + if !Flags.camltk then v + else labelstring l ^ v) vnames tyl) + + (* all other types are read in one operation *) + | List ty -> + name ^ "(" ^ converterTKtoCAML ~arg:"args" ty ^ ")" + | String -> + name ^ "(" ^ converterTKtoCAML ~arg:"(List.hd args)" ty ^ ")" + | ty -> + begin match type_parser_arity ty with + OneToken -> + name ^ "(" ^ converterTKtoCAML ~arg:"(List.hd args)" ty ^ ")" + | MultipleToken -> + "let (v, _) = " ^ converterTKtoCAML ~arg:"args" ty ^ + " in\n " ^ name ^ " v" + end + end ^ ")" + +(*************************************************************) +(* Parsers *) +(* are required only for values returned by commands and *) +(* functions (table is computed by the parser) *) + +(* Tuples/Lists are Ok if they don't contain strings *) +(* they will be returned as list of strings *) + +(* Can we generate a "parser" ? + -> all constructors are unit and at most one int and one string, with null constr +*) +type parser_pieces = + { mutable zeroary : (string * string) list ; (* kw string, ml name *) + mutable intpar : string list; (* one at most, mlname *) + mutable stringpar : string list (* idem *) + } + +type mini_parser = + NoParser + | ParserPieces of parser_pieces + +let can_generate_parser constructors = + let pp = {zeroary = []; intpar = []; stringpar = []} in + if List.for_all constructors ~f: + begin fun c -> + let vname = if !Flags.camltk then c.ml_name else c.var_name in + match c.template with + ListArg [StringArg s] -> + pp.zeroary <- (s, vname) :: + pp.zeroary; true + | ListArg [TypeArg(_, Int)] | ListArg[TypeArg(_, Float)] -> + if pp.intpar <> [] then false + else (pp.intpar <- [vname]; true) + | ListArg [TypeArg(_, String)] -> + if pp.stringpar <> [] then false + else (pp.stringpar <- [vname]; true) + | _ -> false + end + then ParserPieces pp + else NoParser + + +(* We can generate parsers only for simple types *) +(* we should avoid multiple walks *) +let labltk_write_TKtoCAML ~w name ~def:typdef = + if typdef.parser_arity = MultipleToken then + prerr_string ("You must write cTKtoCAML" ^ name ^ + " : string list ->" ^ name ^ " * string list\n") + else + let write ~consts ~name = + match can_generate_parser consts with + NoParser -> + prerr_string + ("You must write cTKtoCAML" ^ name ^ " : string ->" ^ name ^ "\n") + | ParserPieces pp -> + w ("let cTKtoCAML" ^ name ^ " n =\n"); + (* First check integer *) + if pp.intpar <> [] then + begin + w (" try `" ^ List.hd pp.intpar ^ " (int_of_string n)\n"); + w (" with _ ->\n") + end; + w (" match n with\n"); + List.iter pp.zeroary ~f: + begin fun (tk, ml) -> + w " | \""; w tk; w "\" -> `"; w ml; w "\n" + end; + let final = if pp.stringpar <> [] then + "n -> `" ^ List.hd pp.stringpar ^ " n" + else "s -> Pervasives.raise (Invalid_argument (\"cTKtoCAML" + ^ name ^ ": \" ^ s))" + in + w " | "; + w final; + w "\n\n" + in + begin + write ~name ~consts:typdef.constructors; + List.iter typdef.subtypes ~f: begin + fun (subname, consts) -> write ~name:(subname ^ "_" ^ name) ~consts + end + end + +let camltk_write_TKtoCAML ~w name ~def:typdef = + if typdef.parser_arity = MultipleToken then + prerr_string ("You must write cTKtoCAML" ^ name ^ + " : string list ->" ^ name ^ " * string list\n") + else + let write ~consts ~name = + match can_generate_parser consts with + NoParser -> + prerr_string + ("You must write cTKtoCAML" ^ name ^ " : string ->" ^ name ^ "\n") + | ParserPieces pp -> + w ("let cTKtoCAML" ^ name ^ " n =\n"); + (* First check integer *) + if pp.intpar <> [] then + begin + w (" try " ^ List.hd pp.intpar ^ " (int_of_string n)\n"); + w (" with _ ->\n") + end; + w (" match n with\n"); + List.iter pp.zeroary ~f: + begin fun (tk, ml) -> + w " | \""; w tk; w "\" -> "; w ml; w "\n" + end; + let final = if pp.stringpar <> [] then + "n -> " ^ List.hd pp.stringpar ^ " n" + else "s -> Pervasives.raise (Invalid_argument (\"cTKtoCAML" + ^ name ^ ": \" ^ s))" + in + w " | "; + w final; + w "\n\n" + in + begin + write ~name ~consts:typdef.constructors; + List.iter typdef.subtypes ~f: begin + fun (subname, consts) -> write ~name:(subname ^ "_" ^ name) ~consts + end + end + +let write_TKtoCAML ~w name ~def:typdef = + (if !Flags.camltk then camltk_write_TKtoCAML else labltk_write_TKtoCAML) + ~w name ~def: typdef + +(******************************) +(* Converters *) +(******************************) + +(* Produce an in-lined converter Caml -> Tk for simple types *) +(* the converter is a function of type: <type> -> string *) +let rec converterCAMLtoTK ~context_widget argname ty = + match ty with + Int -> "TkToken (string_of_int " ^ argname ^ ")" + | Float -> "TkToken (Printf.sprintf \"%g\" " ^ argname ^ ")" + | Bool -> "if " ^ argname ^ " then TkToken \"1\" else TkToken \"0\"" + | Char -> "TkToken (Char.escaped " ^ argname ^ ")" + | String -> "TkToken " ^ argname + | As (ty, _) -> converterCAMLtoTK ~context_widget argname ty + | UserDefined s -> + let name = "cCAMLtoTK" ^ s ^ " " in + let args = argname in + let args = + if !Flags.camltk then begin + if is_subtyped s then (* unconstraint subtype *) + s ^ "_any_table " ^ args + else args + end else args + in + let args = + if requires_widget_context s then + context_widget ^ " " ^ args + else args in + name ^ args + | Subtype ("widget", s') -> + if !Flags.camltk then + let name = "cCAMLtoTKwidget " in + let args = "widget_"^s'^"_table "^argname in + let args = + if requires_widget_context "widget" then + context_widget^" "^args + else args in + name^args + else begin + let name = "cCAMLtoTKwidget " in + let args = "(" ^ argname ^ " : " ^ s' ^ " widget)" in + name ^ args + end + | Subtype (s, s') -> + let name = + if !Flags.camltk then "cCAMLtoTK" ^ s ^ " " + else "cCAMLtoTK" ^ s' ^ "_" ^ s ^ " " + in + let args = + if !Flags.camltk then begin + s^"_"^s'^"_table "^argname + end else begin + if safetype then "(" ^ argname ^ " : [< " ^ s' ^ "_" ^ s ^ "])" + else argname + end + in + let args = + if requires_widget_context s then context_widget ^ " " ^ args + else args in + name ^ args + | Product tyl -> + let vars = varnames ~prefix:"z" (List.length tyl) in + String.concat ~sep:" " + ("let" :: String.concat ~sep:"," vars :: "=" :: argname :: + "in TkTokenList [" :: + String.concat ~sep:"; " + (List.map2 vars tyl ~f:(converterCAMLtoTK ~context_widget)) :: + ["]"]) + | List ty -> (* Just added for Imagephoto.put *) + String.concat ~sep:" " + [(if !Flags.camltk then + "TkQuote (TkTokenList (List.map (fun y -> " + else + "TkQuote (TkTokenList (List.map ~f:(fun y -> "); + converterCAMLtoTK ~context_widget "y" ty; + ")"; + argname; + "))"] + | Function _ -> fatal_error "unexpected function type in converterCAMLtoTK" + | Unit -> fatal_error "unexpected unit type in converterCAMLtoTK" + | Record _ -> fatal_error "unexpected product type in converterCAMLtoTK" + +(* + * Produce a list of arguments from a template + * The idea here is to avoid allocation as much as possible + * + *) + +let code_of_template ~context_widget ?func:(funtemplate=false) template = + let catch_opts = ref ("", "") in (* class name and first option *) + let variables = ref [] in + let variables2 = ref [] in + let varcnter = ref 0 in + let optionvar = ref None in + let newvar1 l = + match !optionvar with + Some v -> optionvar := None; v + | None -> + incr varcnter; + let v = "v" ^ (string_of_int !varcnter) in + variables := (l, v) :: !variables; v in + let newvar2 l = + match !optionvar with + Some v -> optionvar := None; v + | None -> + incr varcnter; + let v = "v" ^ (string_of_int !varcnter) in + variables2 := (l, v) :: !variables2; v in + let newvar = ref newvar1 in + let rec coderec = function + StringArg s -> "TkToken \"" ^ s ^ "\"" + | TypeArg (_, List (Subtype (sup, sub))) when not !Flags.camltk -> + begin try + let typdef = Hashtbl.find types_table sup in + let classdef = List.assoc sub typdef.subtypes in + let lbl = gettklabel (List.hd classdef) in + catch_opts := (sub ^ "_" ^ sup, lbl); + newvar := newvar2; + "TkTokenList opts" + with Not_found -> + raise (Failure (Printf.sprintf "type %s(%s) not found" sup sub)); + end + | TypeArg (l, List ty) -> + (if !Flags.camltk then + "TkTokenList (List.map (function x -> " + else + "TkTokenList (List.map ~f:(function x -> ") + ^ converterCAMLtoTK ~context_widget "x" ty + ^ ") " ^ !newvar l ^ ")" + | TypeArg (l, Function tyarg) -> + "let id = register_callback " ^ context_widget + ^ " ~callback: " ^ wrapper_code ~name:(!newvar l) tyarg + ^ " in TkToken (\"camlcb \" ^ id)" + | TypeArg (l, ty) -> converterCAMLtoTK ~context_widget (!newvar l) ty + | ListArg l -> + "TkQuote (TkTokenList [" + ^ String.concat ~sep:";\n " (List.map ~f:coderec l) ^ "])" + | OptionalArgs (l, tl, d) -> + let nv = !newvar ("?" ^ l) in + optionvar := Some nv; (* Store *) + let argstr = String.concat ~sep:"; " (List.map ~f:coderec tl) in + let defstr = String.concat ~sep:"; " (List.map ~f:coderec d) in + "TkTokenList (match " ^ nv ^ " with\n" + ^ " | Some " ^ nv ^ " -> [" ^ argstr ^ "]\n" + ^ " | None -> [" ^ defstr ^ "])" + in + let code = + if funtemplate then + match template with + ListArg l -> + "[|" ^ String.concat ~sep:";\n " (List.map ~f:coderec l) ^ "|]" + | _ -> "[|" ^ coderec template ^ "|]" + else + match template with + ListArg [x] -> coderec x + | ListArg l -> + "TkTokenList [" ^ + String.concat ~sep:";\n " (List.map ~f:coderec l) ^ + "]" + | _ -> coderec template + in + code, List.rev !variables, List.rev !variables2, !catch_opts + +(* + * Converters for user defined types + *) + +(* For each case of a concrete type *) +let labltk_write_clause ~w ~context_widget comp = + let warrow () = w " -> " in + w "`"; + w comp.var_name; + + let code, variables, variables2, (co, _) = + code_of_template ~context_widget comp.template in + + (* no subtype I think ... *) + if co <> "" then raise (Failure "write_clause subtype ?"); + begin match variables with + | [] -> warrow() + | [x] -> w " "; w (labeloff x ~at:"write_clause"); warrow() + | l -> + w " ( "; + w (String.concat ~sep:", " (List.map ~f:(labeloff ~at:"write_clause") l)); + w ")"; + warrow() + end; + w code + +let camltk_write_clause ~w ~context_widget ~subtype comp = + let warrow () = + w " -> "; + if subtype then + w ("chk_sub \""^comp.ml_name^"\" table C" ^ comp.ml_name ^ "; ") + in + + w comp.ml_name; (* we use ml_name, not var_name, specialized for labltk *) + + let code, variables, variables2, (co, _) = + code_of_template ~context_widget comp.template in + + (* no subtype I think ... *) + if co <> "" then raise (Failure "write_clause subtype ?"); + begin match variables with + | [] -> warrow() + | [x] -> w " "; w (labeloff x ~at:"write_clause"); warrow() + | l -> + w " ( "; + w (String.concat ~sep:", " (List.map ~f:(labeloff ~at:"write_clause") l)); + w ")"; + warrow() + end; + w code + +let write_clause ~w ~context_widget ~subtype comp = + if !Flags.camltk then camltk_write_clause ~w ~context_widget ~subtype comp + else labltk_write_clause ~w ~context_widget comp + +(* The full converter *) +let write_CAMLtoTK ~w ~def:typdef ?safetype:(st = true) name = + let write_one name constrs = + let subtype = typdef.subtypes <> [] in + w ("let cCAMLtoTK" ^ name); + let context_widget = + if typdef.requires_widget_context then begin + w " w"; "w" + end + else + "dummy" in + if !Flags.camltk && subtype then w " table"; + if st then begin + w " : "; + if typdef.variant then w ("[< " ^ name ^ "]") else w name; + w " -> tkArgs " + end; + w (" = function"); + List.iter constrs + ~f:(fun c -> w "\n | "; write_clause ~w ~context_widget ~subtype c); + w "\n\n\n" + in + + let constrs = typdef.constructors in + if !Flags.camltk then write_one name constrs + else begin + (* Only needed if no subtypes, otherwise use optionals *) + if typdef.subtypes == [] then + write_one name constrs + else + List.iter constrs ~f: + begin fun fc -> + let code, vars, _, (co, _) = + code_of_template ~context_widget:"dummy" fc.template in + if co <> "" then fatal_error "optionals in optionals"; + let vars = List.map ~f:snd vars in + w "let ccCAMLtoTK"; w name; w "_"; w (small fc.ml_name); + w " ("; w (String.concat ~sep:", " vars); w ") =\n "; + w code; w "\n\n" + end + end + +(* Tcl does not really return "lists". It returns sp separated tokens *) +let rec write_result_parsing ~w = function + List String -> + w "(splitlist res)" + | List ty -> + if !Flags.camltk then + w (" List.map " ^ converterTKtoCAML ~arg:"(splitlist res)" ty) + else + w (" List.map ~f: " ^ converterTKtoCAML ~arg:"(splitlist res)" ty) + | Product tyl -> raise (Failure "Product -> record was done. ???") + | Record tyl -> (* of course all the labels are "" *) + let rnames = varnames ~prefix:"r" (List.length tyl) in + w " let l = splitlist res in"; + w ("\n if List.length l <> " ^ string_of_int (List.length tyl)); + w ("\n then Pervasives.raise (TkError (\"unexpected result: \" ^ res))"); + w ("\n else "); + List.iter2 rnames tyl ~f: + begin fun r (l, ty) -> + if l <> "" then raise (Failure "lables in return type!!!"); + w (" let " ^ r ^ ", l = "); + begin match type_parser_arity ty with + OneToken -> + w (converterTKtoCAML ~arg:"(List.hd l)" ty); w (", List.tl l") + | MultipleToken -> + w (converterTKtoCAML ~arg:"l" ty) + end; + w (" in\n") + end; + w (String.concat ~sep:", " rnames) + | String -> + w (converterTKtoCAML ~arg:"res" String) + | As (ty, _) -> write_result_parsing ~w ty + | ty -> + match type_parser_arity ty with + OneToken -> w (converterTKtoCAML ~arg:"res" ty) + | MultipleToken -> w (converterTKtoCAML ~arg:"(splitlist res)" ty) + +let labltk_write_function ~w def = + w ("let " ^ def.ml_name); + (* a bit approximative *) + let context_widget = match def.template with + ListArg (TypeArg(_, UserDefined("widget")) :: _) -> "v1" + | ListArg (TypeArg(_, Subtype("widget", _)) :: _) -> "v1" + | _ -> "dummy" in + + let code, variables, variables2, (co, lbl) = + code_of_template ~func:true ~context_widget def.template in + (* Arguments *) + let uv, lv, ov = + let rec replace_args ~u ~l ~o = function + [] -> u, l, o + | ("", x) :: ls -> + replace_args ~u:(x :: u) ~l ~o ls + | (p, _ as x) :: ls when p.[0] = '?' -> + replace_args ~u ~l ~o:(x :: o) ls + | x :: ls -> + replace_args ~u ~l:(x :: l) ~o ls + in + replace_args ~u:[] ~l:[] ~o:[] (List.rev (variables @ variables2)) + in + let has_opts = (ov <> [] || co <> "") in + if not has_opts then List.iter uv ~f:(fun x -> w " "; w x); + List.iter (lv@ov) ~f:(fun (l, v) -> w " "; w (labelstring l); w v); + if co <> "" then begin + if lv = [] && ov = [] then w (" ?" ^ lbl ^ ":eta"); + w " =\n"; + w (co ^ "_optionals"); + if lv = [] && ov = [] then w (" ?" ^ lbl ^ ":eta"); + w " (fun opts"; + if uv = [] then w " ()" else + if has_opts then List.iter uv ~f:(fun x -> w " "; w x); + w " ->\n" + end else begin + if (ov <> [] || lv = []) && uv = [] then w " ()" else + if has_opts then List.iter uv ~f:(fun x -> w " "; w x); + w " =\n" + end; + begin match def.result with + | Unit | As (Unit, _) -> w "tkCommand "; w code + | ty -> + w "let res = tkEval "; w code ; w " in \n"; + write_result_parsing ~w ty + end; + if co <> "" then w ")"; + w "\n\n" + +let camltk_write_function ~w def = + w ("let " ^ def.ml_name); + (* a bit approximative *) + let context_widget = match def.template with + ListArg (TypeArg(_, UserDefined("widget")) :: _) -> "v1" + | ListArg (TypeArg(_, Subtype("widget", _)) :: _) -> "v1" + | _ -> "dummy" in + + let code, variables, variables2, (co, lbl) = + code_of_template ~func:true ~context_widget def.template in + (* Arguments *) + let uv, ov = + let rec replace_args ~u ~o = function + [] -> u, o + | ("", x) :: ls -> + replace_args ~u:(x :: u) ~o ls + | (p, _ as x) :: ls when p.[0] = '?' -> + replace_args ~u ~o:(x :: o) ls + | (_,x) :: ls -> + replace_args ~u:(x::u) ~o ls + in + replace_args ~u:[] ~o:[] (List.rev (variables @ variables2)) + in + let has_opts = ov <> [] (* (ov <> [] || co <> "") *) in + if not has_opts then List.iter uv ~f:(fun x -> w " "; w x); + List.iter ov ~f:(fun (l, v) -> w " "; w (labelstring l); w v); + begin + if uv = [] then w " ()" else + if has_opts then List.iter uv ~f:(fun x -> w " "; w x); + w " =\n" + end; + begin match def.result with + | Unit | As (Unit, _) -> w "tkCommand "; w code + | ty -> + w "let res = tkEval "; w code ; w " in \n"; + write_result_parsing ~w ty + end; + w "\n\n" + +(* + w ("let " ^ def.ml_name); + (* a bit approximative *) + let context_widget = match def.template with + ListArg (TypeArg(_, UserDefined("widget")) :: _) -> "v1" + | ListArg (TypeArg(_, Subtype("widget", _)) :: _) -> "v1" + | _ -> "dummy" in + + let code, variables, variables2, (co, lbl) = + code_of_template ~func:true ~context_widget def.template in + let variables = variables @ variables2 in + (* Arguments *) + begin match variables with + [] -> w " () =\n" + | l -> + let has_normal_argument = ref false in + List.iter (fun (l,x) -> + w " "; + if l <> "" then + if l.[0] = '?' then w (l ^ ":") else has_normal_argument := true + else has_normal_argument := true; + w x) l; + if not !has_normal_argument then w " ()"; + w " =\n" + end; + begin match def.result with + | Unit | As (Unit, _) -> w "tkCommand "; w code + | ty -> + w "let res = tkEval "; w code ; w " in \n"; + write_result_parsing ~w ty + end; + w "\n\n" +*) + +let write_function ~w def = + if !Flags.camltk then camltk_write_function ~w def + else labltk_write_function ~w def +;; + +let labltk_write_create ~w clas = + w ("let create ?name =\n"); + w (" " ^ clas ^ "_options_optionals (fun opts parent ->\n"); + w (" let w = new_atom \"" ^ clas ^ "\" ~parent ?name in\n"); + w " tkCommand [|"; + w ("TkToken \"" ^ clas ^ "\";\n"); + w (" TkToken (Widget.name w);\n"); + w (" TkTokenList opts |];\n"); + w (" w)\n\n\n") + +let camltk_write_create ~w clas = + w ("let create ?name parent options =\n"); + w (" let w = new_atom \"" ^ clas ^ "\" ~parent ?name in\n"); + w " tkCommand [|"; + w ("TkToken \"" ^ clas ^ "\";\n"); + w (" TkToken (Widget.name w);\n"); + w (" TkTokenList (List.map (function x -> "^ + converterCAMLtoTK "w" "x" (Subtype("options",clas)) ^ ") options)\n"); + w (" |];\n"); + w (" w\n\n") + +let camltk_write_named_create ~w clas = + w ("let create_named parent name options =\n"); + w (" let w = new_atom \"" ^ clas ^ "\" ~parent ~name in\n"); + w " tkCommand [|"; + w ("TkToken \"" ^ clas ^ "\";\n"); + w (" TkToken (Widget.name w);\n"); + w (" TkTokenList (List.map (function x -> "^ + converterCAMLtoTK "w" "x" (Subtype("options",clas)) ^ ") options)\n"); + w (" |];\n"); + w (" w\n\n") + +(* Search Path. *) +let search_path = ref ["."] + +(* taken from utils/misc.ml *) +let find_in_path path name = + if not (Filename.is_implicit name) then + if Sys.file_exists name then name else raise Not_found + else begin + let rec try_dir = function + [] -> raise Not_found + | dir :: rem -> + let fullname = Filename.concat dir name in + if Sys.file_exists fullname then fullname else try_dir rem + in try_dir path + end + +(* builtin-code: the file (without suffix) is in .template... *) +(* not efficient, but hell *) +let write_external ~w def = + match def.template with + | StringArg fname -> + begin try + let realname = find_in_path !search_path (fname ^ ".ml") in + let ic = open_in_bin realname in + try + let code_list = Ppparse.parse_channel ic in + close_in ic; + List.iter (Ppexec.exec (fun _ -> ()) w) + (if !Flags.camltk then + Code.Define "CAMLTK" :: code_list else code_list ); + with + | Ppparse.Error s -> + close_in ic; + raise (Compiler_Error (Printf.sprintf "Preprocess error: %s" s)) + with + | Not_found -> + raise (Compiler_Error ("can't find external file: " ^ fname)) + end + | _ -> raise (Compiler_Error "invalid external definition") + +let write_catch_optionals ~w clas ~def:typdef = + if typdef.subtypes = [] then () else + List.iter typdef.subtypes ~f: + begin fun (subclass, classdefs) -> + w ("let " ^ subclass ^ "_" ^ clas ^ "_optionals f = fun\n"); + let tklabels = List.map ~f:gettklabel classdefs in + let l = + List.map classdefs ~f: + begin fun fc -> + (* + let code, vars, _, (co, _) = + code_of_template ~context_widget:"dummy" fc.template in + if co <> "" then fatal_error "optionals in optionals"; + *) + let p = gettklabel fc in + (if count ~item:p tklabels > 1 then small fc.var_name else p), + small fc.ml_name + end in + let p = List.map l ~f:(fun (si, _) -> " ?" ^ si) in + let v = + List.map l ~f: + begin fun (si, s) -> + "(maycons ccCAMLtoTK" ^ clas ^ "_" ^ s ^ " " ^ si + end in + w (String.concat ~sep:"\n" p); + w " ->\n"; + w " f "; + w (String.concat ~sep:"\n " v); + w "\n []"; + w (String.make (List.length v) ')'); + w "\n\n" + end diff --git a/otherlibs/labltk/compiler/copyright b/otherlibs/labltk/compiler/copyright new file mode 100644 index 0000000..23dff46 --- /dev/null +++ b/otherlibs/labltk/compiler/copyright @@ -0,0 +1,15 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) diff --git a/otherlibs/labltk/compiler/flags.ml b/otherlibs/labltk/compiler/flags.ml new file mode 100644 index 0000000..009d5e7 --- /dev/null +++ b/otherlibs/labltk/compiler/flags.ml @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +let camltk = ref false;; diff --git a/otherlibs/labltk/compiler/intf.ml b/otherlibs/labltk/compiler/intf.ml new file mode 100644 index 0000000..e3f0ad9 --- /dev/null +++ b/otherlibs/labltk/compiler/intf.ml @@ -0,0 +1,191 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: intf.ml,v 1.20 2002-07-23 14:11:55 doligez Exp $ *) + +open StdLabels + +(* Write .mli for widgets *) + +open Tables +open Compile + +let labltk_write_create_p ~w wname = + w "val create :\n ?name:string ->\n"; + begin + try + let option = Hashtbl.find types_table "options" in + let classdefs = List.assoc wname option.subtypes in + let tklabels = List.map ~f:gettklabel classdefs in + let l = List.map classdefs ~f: + begin fun fc -> + begin let p = gettklabel fc in + if count ~item:p tklabels > 1 then small fc.var_name else p + end, + fc.template + end in + w (String.concat ~sep:" ->\n" + (List.map l ~f: + begin fun (s, t) -> + " ?" ^ s ^ ":" + ^(ppMLtype + (match types_of_template t with + | [t] -> labeloff t ~at:"write_create_p" + | [] -> fatal_error "multiple" + | l -> Product (List.map ~f:(labeloff ~at:"write_create_p") l))) + end)) + with Not_found -> fatal_error "in write_create_p" + end; + w (" ->\n 'a widget -> " ^ wname ^ " widget\n"); + w "(** [create ?name parent options...] creates a new widget with\n"; + w " parent [parent] and new patch component [name], if specified. *)\n\n" +;; + +let camltk_write_create_p ~w wname = + w "val create : ?name: string -> widget -> options list -> widget \n"; + w "(** [create ?name parent options] creates a new widget with\n"; + w " parent [parent] and new patch component [name] if specified.\n"; + w " Options are restricted to the widget class subset, and checked\n"; + w " dynamically. *)\n\n" +;; + +let camltk_write_named_create_p ~w wname = + w "val create_named : widget -> string -> options list -> widget \n"; + w "(** [create_named parent name options] creates a new widget with\n"; + w " parent [parent] and new patch component [name].\n"; + w " This function is now obsolete and unified with [create]. *)\n\n"; +;; + +(* Unsafe: write special comment *) +let labltk_write_function_type ~w def = + if not def.safe then w "(* unsafe *)\n"; + w "val "; w def.ml_name; w " : "; + let us, ls, os = + let tys = types_of_template def.template in + let rec replace_args ~u ~l ~o = function + [] -> u, l, o + | (_, List(Subtype _) as x)::ls -> + replace_args ~u ~l ~o:(x::o) ls + | ("", _ as x)::ls -> + replace_args ~u:(x::u) ~l ~o ls + | (p, _ as x)::ls when p.[0] = '?' -> + replace_args ~u ~l ~o:(x::o) ls + | x::ls -> + replace_args ~u ~l:(x::l) ~o ls + in + replace_args ~u:[] ~l:[] ~o:[] (List.rev tys) + in + let counter = ref 0 in + let params = + if os = [] then us @ ls else ls @ os @ us in + List.iter params ~f: + begin fun (l, t) -> + if l <> "" then w (l ^ ":"); + w (ppMLtype t ~counter); + w " -> " + end; + if (os <> [] || ls = []) && us = [] then w "unit -> "; + w (ppMLtype ~any:true ~return:true def.result); (* RETURN TYPE !!! *) + w " \n"; +(* w "(* tk invocation: "; w (doc_of_template def.template); w " *)"; *) + if def.safe then w "\n" + else w "\n(* /unsafe *)\n" + +let camltk_write_function_type ~w def = + if not def.safe then w "(* unsafe *)\n"; + w "val "; w def.ml_name; w " : "; + let us, os = + let tys = types_of_template def.template in + let rec replace_args ~u ~o = function + [] -> u, o + | ("", _ as x)::ls -> + replace_args ~u:(x::u) ~o ls + | (p, _ as x)::ls when p.[0] = '?' -> + replace_args ~u ~o:(x::o) ls + | x::ls -> + replace_args ~u:(x::u) ~o ls + in + replace_args ~u:[] ~o:[] (List.rev tys) + in + let counter = ref 0 in + let params = + if os = [] then us else os @ us in + List.iter params ~f: + begin fun (l, t) -> + if l <> "" then if l.[0] = '?' then w (l ^ ":"); + w (ppMLtype t ~counter); + w " -> " + end; + if us = [] then w "unit -> "; + w (ppMLtype ~any:true ~return:true def.result); (* RETURN TYPE !!! *) + w " \n"; +(* w "(* tk invocation: "; w (doc_of_template def.template); w " *)"; *) + if def.safe then w "\n" + else w "\n(* /unsafe *)\n" + +(* + if not def.safe then w "(* unsafe *)\n"; + w "val "; w def.ml_name; w " : "; + let tys = types_of_template def.template in + let counter = ref 0 in + let have_normal_arg = ref false in + List.iter tys ~f: + begin fun (l, t) -> + if l <> "" then + if l.[0] = '?' then w (l^":") + else begin + have_normal_arg := true; + w (" (* " ^ l ^ ":*)") + end + else have_normal_arg := true; + w (ppMLtype t ~counter); + w " -> " + end; + if not !have_normal_arg then w "unit -> "; + w (ppMLtype ~any:true ~return:true def.result); (* RETURN TYPE !!! *) + w " \n"; + if def.safe then w "\n" + else w "\n(* /unsafe *)\n" +*) + +let write_function_type ~w def = + if !Flags.camltk then camltk_write_function_type ~w def + else labltk_write_function_type ~w def + +let write_external_type ~w def = + match def.template with + | StringArg fname -> + begin try + let realname = find_in_path !search_path (fname ^ ".mli") in + let ic = open_in_bin realname in + try + let code_list = Ppparse.parse_channel ic in + close_in ic; + if not def.safe then w "(* unsafe *)\n"; + List.iter (Ppexec.exec (fun _ -> ()) w) + (if !Flags.camltk then + Code.Define "CAMLTK" :: code_list else code_list ); + if def.safe then w "\n\n" + else w "\n(* /unsafe *)\n\n" + with + | Ppparse.Error s -> + close_in ic; + raise (Compiler_Error (Printf.sprintf "Preprocess error: %s" s)) + with + | Not_found -> + raise (Compiler_Error ("can't find external file: " ^ fname)) + end + | _ -> raise (Compiler_Error "invalid external definition") diff --git a/otherlibs/labltk/compiler/lexer.mll b/otherlibs/labltk/compiler/lexer.mll new file mode 100644 index 0000000..6717387 --- /dev/null +++ b/otherlibs/labltk/compiler/lexer.mll @@ -0,0 +1,170 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mll,v 1.14 2002-07-23 14:11:55 doligez Exp $ *) + +{ +open StdLabels +open Lexing +open Parser +open Support + +exception Lexical_error of string +let current_line = ref 1 + + +(* The table of keywords *) + +let keyword_table = (Hashtbl.create 149 : (string, token) Hashtbl.t) + +let _ = List.iter + ~f:(fun (str,tok) -> Hashtbl.add keyword_table str tok) + [ + "int", TYINT; + "float", TYFLOAT; + "bool", TYBOOL; + "char", TYCHAR; + "string", TYSTRING; + "list", LIST; + "as", AS; + "variant", VARIANT; + "widget", WIDGET; + "option", OPTION; + "type", TYPE; + "subtype", SUBTYPE; + "function", FUNCTION; + "module", MODULE; + "external", EXTERNAL; + "sequence", SEQUENCE; + "unsafe", UNSAFE +] + + +(* To buffer string literals *) + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0; + () + +let store_string_char c = + if !string_index >= String.length (!string_buff) then begin + let new_buff = String.create (String.length (!string_buff) * 2) in + String.blit ~src:(!string_buff) ~src_pos:0 ~dst:new_buff ~dst_pos:0 + ~len:(String.length (!string_buff)); + string_buff := new_buff + end; + String.set (!string_buff) (!string_index) c; + incr string_index + +let get_stored_string () = + let s = String.sub (!string_buff) ~pos:0 ~len:(!string_index) in + string_buff := initial_string_buffer; + s +(* To translate escape sequences *) + +let char_for_backslash = function + 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + Char.chr(100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48)) + +let saved_string_start = ref 0 + +} + +rule main = parse + '\010' { incr current_line; main lexbuf } + | [' ' '\013' '\009' '\026' '\012'] + + { main lexbuf } + | ['A'-'Z' 'a'-'z' '\192'-'\214' '\216'-'\246' '\248'-'\255' ] + ( '_' ? ['A'-'Z' 'a'-'z' '\192'-'\214' '\216'-'\246' '\248'-'\255' (*'*) '0'-'9' ] ) * + { let s = Lexing.lexeme lexbuf in + try + Hashtbl.find keyword_table s + with Not_found -> + IDENT s } + + | "\"" + { reset_string_buffer(); + (* Start of token is start of string. *) + saved_string_start := lexbuf.lex_start_pos; + string lexbuf; + lexbuf.lex_start_pos <- !saved_string_start; + STRING (get_stored_string()) } + | "(" { LPAREN } + | ")" { RPAREN } + | "[" { LBRACKET } + | "]" { RBRACKET } + | "{" { LBRACE } + | "}" { RBRACE } + | "," { COMMA } + | ";" { SEMICOLON } + | ":" {COLON} + | "?" {QUESTION} + | "/" {SLASH} + | "%" { comment lexbuf; main lexbuf } + | "##line" { line lexbuf; main lexbuf } + | eof { EOF } + | _ + { raise (Lexical_error("illegal character")) } + + +and string = parse + '"' + { () } + | '\\' [' ' '\010' '\013' '\009' '\026' '\012'] + + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise (Lexical_error("string not terminated")) } + | '\010' + { incr current_line; + store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } + +and comment = parse + '\010' { incr current_line } + | eof { () } + | _ { comment lexbuf } + +and linenum = parse + | ['0'-'9']+ { + let next_line = int_of_string (Lexing.lexeme lexbuf) in + current_line := next_line - 1 + } + | _ { raise (Lexical_error("illegal ##line directive: no line number"))} + +and line = parse + | [' ' '\t']* { linenum lexbuf } diff --git a/otherlibs/labltk/compiler/maincompile.ml b/otherlibs/labltk/compiler/maincompile.ml new file mode 100644 index 0000000..dc24c97 --- /dev/null +++ b/otherlibs/labltk/compiler/maincompile.ml @@ -0,0 +1,418 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: maincompile.ml,v 1.20 2005-01-28 16:13:11 doligez Exp $ *) + +open StdLabels +open Support +open Tables +open Printer +open Compile +open Intf + +let flag_verbose = ref false +let verbose_string s = + if !flag_verbose then prerr_string s +let verbose_endline s = + if !flag_verbose then prerr_endline s + +let input_name = ref "Widgets.src" +let output_dir = ref "" +let destfile f = Filename.concat !output_dir f + +let usage () = + prerr_string "Usage: tkcompiler input.src\n"; + flush stderr; + exit 1 + + +let prerr_error_header () = + prerr_string "File \""; prerr_string !input_name; + prerr_string "\", line "; + prerr_string (string_of_int !Lexer.current_line); + prerr_string ": " + +(* parse Widget.src config file *) +let parse_file filename = + let ic = open_in_bin filename in + let lexbuf = + try + let code_list = Ppparse.parse_channel ic in + close_in ic; + let buf = Buffer.create 50000 in + List.iter (Ppexec.exec + (fun l -> Buffer.add_string buf + (Printf.sprintf "##line %d\n" l)) + (Buffer.add_string buf)) + (if !Flags.camltk then Code.Define "CAMLTK" :: code_list + else code_list); + Lexing.from_string (Buffer.contents buf) + with + | Ppparse.Error s -> + close_in ic; + raise (Compiler_Error (Printf.sprintf "Preprocess error: %s" s)) + in + try + while true do + Parser.entry Lexer.main lexbuf + done + with + | Parsing.Parse_error -> + prerr_error_header(); + prerr_string "Syntax error \n"; + exit 1 + | Lexer.Lexical_error s -> + prerr_error_header(); + prerr_string "Lexical error ("; + prerr_string s; + prerr_string ")\n"; + exit 1 + | Duplicate_Definition (s,s') -> + prerr_error_header(); + prerr_string s; prerr_string " "; prerr_string s'; + prerr_string " is defined twice.\n"; + exit 1 + | Compiler_Error s -> + prerr_error_header(); + prerr_string "Internal error: "; prerr_string s; prerr_string "\n"; + prerr_string "Please report bug\n"; + exit 1 + | End_of_file -> + () + +(* The hack to provoke the production of cCAMLtoTKoptions_constrs *) + +(* Auxiliary function: the list of all the elements associated to keys + in an hash table. *) +let elements t = + let elems = ref [] in + Hashtbl.iter (fun _ d -> elems := d :: !elems) t; + !elems;; + +(* Verifies that duplicated clauses are semantically equivalent and + returns a unique set of clauses. *) +let uniq_clauses = function + | [] -> [] + | l -> + let check_constr constr1 constr2 = + if constr1.template <> constr2.template then + begin + let code1, vars11, vars12, opts1 = + code_of_template ~context_widget:"dummy" constr1.template in + let code2, vars12, vars22, opts2 = + code_of_template ~context_widget:"dummy" constr2.template in + let err = + Printf.sprintf + "uncompatible redondant clauses for variant %s:\n %s\n and\n %s" + constr1.var_name code1 code2 in + Format.print_newline(); + print_fullcomponent constr1; + Format.print_newline(); + print_fullcomponent constr2; + Format.print_newline(); + prerr_endline err; + fatal_error err + end in + let t = Hashtbl.create 11 in + List.iter l + ~f:(fun constr -> + let c = constr.var_name in + if Hashtbl.mem t c + then (check_constr constr (Hashtbl.find t c)) + else Hashtbl.add t c constr); + elements t;; + +let option_hack oc = + if Hashtbl.mem types_table "options" then + let typdef = Hashtbl.find types_table "options" in + let hack = + { parser_arity = OneToken; + constructors = begin + let constrs = + List.map typdef.constructors ~f: + begin fun c -> + { component = Constructor; + ml_name = (if !Flags.camltk then "C" ^ c.ml_name + else c.ml_name); + var_name = c.var_name; (* as variants *) + template = + begin match c.template with + ListArg (x :: _) -> x + | _ -> fatal_error "bogus hack" + end; + result = UserDefined "options_constrs"; + safe = true } + end in + if !Flags.camltk then constrs else uniq_clauses constrs (* JPF ?? *) + end; + subtypes = []; + requires_widget_context = false; + variant = false } + in + write_CAMLtoTK + ~w:(output_string oc) ~def:hack ~safetype:false "options_constrs" + +let realname name = + (* module name fix for camltk *) + if !Flags.camltk then "c" ^ String.capitalize name + else name +;; + +(* analize the parsed Widget.src and output source files *) +let compile () = + verbose_endline "Creating _tkgen.ml ..."; + let oc = open_out_bin (destfile "_tkgen.ml") in + let oc' = open_out_bin (destfile "_tkigen.ml") in + let oc'' = open_out_bin (destfile "_tkfgen.ml") in + let sorted_types = Tsort.sort types_order in + verbose_endline " writing types ..."; + List.iter sorted_types ~f: + begin fun typname -> + verbose_string (" " ^ typname ^ " "); + try + let typdef = Hashtbl.find types_table typname in + verbose_string "type "; + write_type ~intf:(output_string oc) + ~impl:(output_string oc') + typname ~def:typdef; + verbose_string "C2T "; + write_CAMLtoTK ~w:(output_string oc') typname ~def:typdef; + verbose_string "T2C "; + if List.mem typname !types_returned then + write_TKtoCAML ~w:(output_string oc') typname ~def:typdef; + verbose_string "CO "; + if not !Flags.camltk then (* only for LablTk *) + write_catch_optionals ~w:(output_string oc') typname ~def:typdef; + verbose_endline "." + with Not_found -> + if not (List.mem_assoc typname !types_external) then + begin + verbose_string "Type "; + verbose_string typname; + verbose_string " is undeclared external or undefined\n" + end + else verbose_endline "." + end; + verbose_endline " option hacking ..."; + option_hack oc'; + verbose_endline " writing functions ..."; + List.iter ~f:(write_function ~w:(output_string oc'')) !function_table; + close_out oc; + close_out oc'; + close_out oc''; + (* Write the interface for public functions *) + (* this interface is used only for documentation *) + verbose_endline "Creating _tkgen.mli ..."; + let oc = open_out_bin (destfile "_tkgen.mli") in + List.iter (sort_components !function_table) + ~f:(write_function_type ~w:(output_string oc)); + close_out oc; + verbose_endline "Creating other ml, mli ..."; + let write_module wname wdef = + verbose_endline (" "^wname); + let modname = realname wname in + let oc = open_out_bin (destfile (modname ^ ".ml")) + and oc' = open_out_bin (destfile (modname ^ ".mli")) in + Copyright.write ~w:(output_string oc); + Copyright.write ~w:(output_string oc'); + begin match wdef.module_type with + Widget -> output_string oc' ("(* The "^wname^" widget *)\n") + | Family -> output_string oc' ("(* The "^wname^" commands *)\n") + end; + List.iter ~f:(fun s -> output_string oc s; output_string oc' s) + begin + if !Flags.camltk then + [ "open CTk\n"; + "open Tkintf\n"; + "open Widget\n"; + "open Textvariable\n\n" ] + else + [ "open StdLabels\n"; + "open Tk\n"; + "open Tkintf\n"; + "open Widget\n"; + "open Textvariable\n\n" ] + end; + output_string oc "open Protocol\n"; + begin match wdef.module_type with + Widget -> + if !Flags.camltk then begin + camltk_write_create ~w:(output_string oc) wname; + camltk_write_named_create ~w:(output_string oc) wname; + camltk_write_create_p ~w:(output_string oc') wname; + camltk_write_named_create_p ~w:(output_string oc') wname; + end else begin + labltk_write_create ~w:(output_string oc) wname; + labltk_write_create_p ~w:(output_string oc') wname + end + | Family -> () + end; + List.iter ~f:(write_function ~w:(output_string oc)) + (sort_components wdef.commands); + List.iter ~f:(write_function_type ~w:(output_string oc')) + (sort_components wdef.commands); + List.iter ~f:(write_external ~w:(output_string oc)) + (sort_components wdef.externals); + List.iter ~f:(write_external_type ~w:(output_string oc')) + (sort_components wdef.externals); + close_out oc; + close_out oc' + in Hashtbl.iter write_module module_table; + + (* wrapper code camltk.ml and labltk.ml *) + if !Flags.camltk then begin + let oc = open_out_bin (destfile "camltk.ml") in + Copyright.write ~w:(output_string oc); + output_string oc +"(** This module Camltk provides the module name spaces of the CamlTk API. + + The users of the CamlTk API should open this module first to access + the types, functions and modules of the CamlTk API easier. + For the documentation of each sub modules such as [Button] and [Toplevel], + refer to its defintion file, [cButton.mli], [cToplevel.mli], etc. + *) + +"; + output_string oc "include CTk\n"; + output_string oc "module Tk = CTk\n"; + Hashtbl.iter (fun name _ -> + let cname = realname name in + output_string oc (Printf.sprintf "module %s = %s;;\n" + (String.capitalize name) + (String.capitalize cname))) module_table; + close_out oc + end else begin + let oc = open_out_bin (destfile "labltk.ml") in + Copyright.write ~w:(output_string oc); + output_string oc +"(** This module Labltk provides the module name spaces of the LablTk API, + useful to call LablTk functions inside CamlTk programs. 100% LablTk users + do not need to use this. *) + +"; + output_string oc "module Widget = Widget;; +module Protocol = Protocol;; +module Textvariable = Textvariable;; +module Fileevent = Fileevent;; +module Timer = Timer;; +"; + Hashtbl.iter (fun name _ -> + let cname = realname name in + output_string oc (Printf.sprintf "module %s = %s;;\n" + (String.capitalize name) + (String.capitalize cname))) module_table; + (* widget typer *) + output_string oc "\n(** Widget typers *)\n\nopen Widget\n\n"; + Hashtbl.iter (fun name def -> + match def.module_type with + | Widget -> + output_string oc (Printf.sprintf + "let %s (w : any widget) =\n" name); + output_string oc (Printf.sprintf + " Rawwidget.check_class w widget_%s_table;\n" name); + output_string oc (Printf.sprintf + " (Obj.magic w : %s widget);;\n\n" name); + | _ -> () ) module_table; + close_out oc + end; + + (* write the module list for the Makefile *) + (* and hack to death until it works *) + let oc = open_out_bin (destfile "modules") in + if !Flags.camltk then output_string oc "CWIDGETOBJS=" + else output_string oc "WIDGETOBJS="; + Hashtbl.iter + (fun name _ -> + let name = realname name in + output_string oc name; + output_string oc ".cmo ") + module_table; + output_string oc "\n"; + Hashtbl.iter + (fun name _ -> + let name = realname name in + output_string oc name; + output_string oc ".ml ") + module_table; + output_string oc ": _tkgen.ml\n\n"; + Hashtbl.iter + (fun name _ -> + let name = realname name in + output_string oc name; + output_string oc ".cmo : "; + output_string oc name; + output_string oc ".ml\n"; + output_string oc name; + output_string oc ".cmi : "; + output_string oc name; + output_string oc ".mli\n") + module_table; + + (* for camltk.ml wrapper *) + if !Flags.camltk then begin + output_string oc "camltk.cmo : cTk.cmo "; + Hashtbl.iter + (fun name _ -> + let name = realname name in + output_string oc name; + output_string oc ".cmo ") module_table; + output_string oc "\n" + end; + close_out oc + +let main () = + Arg.parse + [ "-verbose", Arg.Unit (fun () -> flag_verbose := true), + "Make output verbose"; + "-camltk", Arg.Unit (fun () -> Flags.camltk := true), + "Make CamlTk interface"; + "-outdir", Arg.String (fun s -> output_dir := s), + "output directory"; + "-debugpp", Arg.Unit (fun () -> Ppexec.debug := true), + "debug preprocessor" + ] + (fun filename -> input_name := filename) + "Usage: tkcompiler <source file>" ; + if !output_dir = "" then begin + prerr_endline "specify -outdir option"; + exit 1 + end; + try + verbose_endline "Parsing..."; + parse_file !input_name; + verbose_endline "Compiling..."; + compile (); + verbose_endline "Finished"; + exit 0 + with + | Lexer.Lexical_error s -> + prerr_string "Invalid lexical character: "; + prerr_endline s; + exit 1 + | Duplicate_Definition (s, s') -> + prerr_string s; prerr_string " "; prerr_string s'; + prerr_endline " is redefined illegally"; + exit 1 + | Invalid_implicit_constructor c -> + prerr_string "Constructor "; + prerr_string c; + prerr_endline " is used implicitly before defined"; + exit 1 + | Tsort.Cyclic -> + prerr_endline "Cyclic dependency of types"; + exit 1 + +let () = Printexc.catch main () diff --git a/otherlibs/labltk/compiler/parser.mly b/otherlibs/labltk/compiler/parser.mly new file mode 100644 index 0000000..b641b8e --- /dev/null +++ b/otherlibs/labltk/compiler/parser.mly @@ -0,0 +1,330 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: parser.mly,v 1.9 2003-03-27 15:04:44 furuse Exp $ */ + +%{ + +open Tables + +%} + +/* Tokens */ +%token <string> IDENT +%token <string> STRING +%token EOF + +%token LPAREN /* "(" */ +%token RPAREN /* ")" */ +%token COMMA /* "," */ +%token SEMICOLON /* ";" */ +%token COLON /* ":" */ +%token QUESTION /* "?" */ +%token LBRACKET /* "[" */ +%token RBRACKET /* "]" */ +%token LBRACE /* "{" */ +%token RBRACE /* "}" */ +%token SLASH /* "/" */ + +%token TYINT /* "int" */ +%token TYFLOAT /* "float" */ +%token TYBOOL /* "bool" */ +%token TYCHAR /* "char" */ +%token TYSTRING /* "string" */ +%token LIST /* "list" */ + +%token AS /* "as" */ +%token VARIANT /* "variant" */ +%token WIDGET /* "widget" */ +%token OPTION /* "option" */ +%token TYPE /* "type" */ +%token SEQUENCE /* "sequence" */ +%token SUBTYPE /* "subtype" */ +%token FUNCTION /* "function" */ +%token MODULE /* "module" */ +%token EXTERNAL /* "external" */ +%token UNSAFE /* "unsafe" */ +/* Entry points */ +%start entry +%type <unit> entry + +%% +TypeName: + IDENT { String.uncapitalize $1 } + | WIDGET { "widget" } +; + +/* Atomic types */ +Type0 : + TYINT + { Int } + | TYFLOAT + { Float } + | TYBOOL + { Bool } + | TYCHAR + { Char } + | TYSTRING + { String } + | TypeName + { UserDefined $1 } +; + +/* Camltk/Labltk types */ +Type0_5: + | Type0 SLASH Type0 { if !Flags.camltk then $1 else $3 } + | Type0 { $1 } +; + +/* with subtypes */ +Type1 : + Type0_5 + { $1 } + | TypeName LPAREN IDENT RPAREN + { Subtype ($1, $3) } + | WIDGET LPAREN IDENT RPAREN + { Subtype ("widget", $3) } + | OPTION LPAREN IDENT RPAREN + { Subtype ("options", $3) } + | Type1 AS STRING + { As ($1, $3) } + | LBRACE Type_list RBRACE + { Product $2 } +; + +/* with list constructors */ +Type2 : + Type1 + { $1 } + | Type2 LIST + { List $1 } +; + +Labeled_type2 : + Type2 + { "", $1 } + | IDENT COLON Type2 + { $1, $3 } +; + +/* products */ +Type_list : + Type2 COMMA Type_list + { $1 :: $3 } + | Type2 + { [$1] } +; + +/* records */ +Type_record : + Labeled_type2 COMMA Type_record + { $1 :: $3 } + | Labeled_type2 + { [$1] } +; + +/* callback arguments or function results*/ +FType : + LPAREN RPAREN + { Unit } + | LPAREN Type2 RPAREN + { $2 } + | LPAREN Type_record RPAREN + { Record $2 } +; + +Type : + Type2 + { $1 } + | FUNCTION FType + { Function $2 } +; + + + +SimpleArg: + STRING + {StringArg $1} + | Type + {TypeArg ("", $1) } +; + +Arg: + STRING + {StringArg $1} + | Type + {TypeArg ("", $1) } + | IDENT COLON Type + {TypeArg ($1, $3)} + | QUESTION IDENT COLON LBRACKET SimpleArgList RBRACKET DefaultList + {OptionalArgs ( $2, $5, $7 )} + | QUESTION WIDGET COLON LBRACKET SimpleArgList RBRACKET DefaultList + {OptionalArgs ( "widget", $5, $7 )} + | QUESTION IDENT COLON LBRACKET SimpleArgList RBRACKET + {OptionalArgs ( $2, $5, [] )} + | QUESTION WIDGET COLON LBRACKET SimpleArgList RBRACKET + {OptionalArgs ( "widget", $5, [] )} + | WIDGET COLON Type + {TypeArg ("widget", $3)} + | Template + { $1 } +; + +SimpleArgList: + SimpleArg SEMICOLON SimpleArgList + { $1 :: $3} + | SimpleArg + { [$1] } +; + +ArgList: + Arg SEMICOLON ArgList + { $1 :: $3} + | Arg + { [$1] } +; + +/* DefaultList Only one TypeArg in ArgList and it must be unlabeled */ +DefaultList : + LBRACKET LBRACE ArgList RBRACE RBRACKET + {$3} + +/* Template */ +Template : + LBRACKET ArgList RBRACKET + { ListArg $2 } +; + + +/* Constructors for type declarations */ +Constructor : + IDENT Template + {{ component = Constructor; + ml_name = $1; + var_name = getvarname $1 $2; + template = $2; + result = Unit; + safe = true }} + | IDENT LPAREN IDENT RPAREN Template + {{ component = Constructor; + ml_name = $1; + var_name = $3; + template = $5; + result = Unit; + safe = true }} +; + +AbbrevConstructor : + Constructor + { Full $1 } + | IDENT + { Abbrev $1 } +; + +Constructors : + Constructor Constructors + { $1 :: $2 } +| Constructor + { [$1] } +; + +AbbrevConstructors : + AbbrevConstructor AbbrevConstructors + { $1 :: $2 } +| AbbrevConstructor + { [$1] } +; + +Safe: + /* */ + { true } + | UNSAFE + { false } + +Command : + Safe FUNCTION FType IDENT Template + {{component = Command; ml_name = $4; var_name = ""; + template = $5; result = $3; safe = $1 }} +; + +External : + Safe EXTERNAL IDENT STRING + {{component = External; ml_name = $3; var_name = ""; + template = StringArg $4; result = Unit; safe = $1}} +; + +Option : + OPTION IDENT Template + {{component = Constructor; ml_name = $2; var_name = getvarname $2 $3; + template = $3; result = Unit; safe = true }} + /* Abbreviated */ +| OPTION IDENT LPAREN IDENT RPAREN Template + {{component = Constructor; ml_name = $2; var_name = $4; + template = $6; result = Unit; safe = true }} + /* Abbreviated */ +| OPTION IDENT + { retrieve_option $2 } +; + +WidgetComponents : + /* */ + { [] } + | Command WidgetComponents + { $1 :: $2 } + | Option WidgetComponents + { $1 :: $2 } + | External WidgetComponents + { $1 :: $2 } +; + +ModuleComponents : + /* */ + { [] } + | Command ModuleComponents + { $1 :: $2 } + | External ModuleComponents + { $1 :: $2 } +; + +ParserArity : + /* */ + { OneToken } + | SEQUENCE + { MultipleToken } +; + + + +entry : + TYPE ParserArity TypeName LBRACE Constructors RBRACE + { enter_type $3 $2 $5 } +| VARIANT TYPE ParserArity TypeName LBRACE Constructors RBRACE + { enter_type $4 $3 $6 ~variant: true } +| TYPE ParserArity TypeName EXTERNAL + { enter_external_type $3 $2 } +| SUBTYPE ParserArity OPTION LPAREN IDENT RPAREN LBRACE AbbrevConstructors RBRACE + { enter_subtype "options" $2 $5 $8 } +| SUBTYPE ParserArity TypeName LPAREN IDENT RPAREN LBRACE AbbrevConstructors RBRACE + { enter_subtype $3 $2 $5 $8 } +| Command + { enter_function $1 } +| WIDGET IDENT LBRACE WidgetComponents RBRACE + { enter_widget $2 $4 } +| MODULE IDENT LBRACE ModuleComponents RBRACE + { enter_module (String.uncapitalize $2) $4 } +| EOF + { raise End_of_file } +; diff --git a/otherlibs/labltk/compiler/pp.ml b/otherlibs/labltk/compiler/pp.ml new file mode 100644 index 0000000..5c46766 --- /dev/null +++ b/otherlibs/labltk/compiler/pp.ml @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +let _ = + try + let code_list = Ppparse.parse_channel stdin in + List.iter (Ppexec.exec (fun _ -> ()) print_string) code_list + with + | Ppparse.Error s -> prerr_endline s; exit 2 +;; diff --git a/otherlibs/labltk/compiler/ppexec.ml b/otherlibs/labltk/compiler/ppexec.ml new file mode 100644 index 0000000..9946882 --- /dev/null +++ b/otherlibs/labltk/compiler/ppexec.ml @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +open Code + +let debug = ref false +let defined = ref [] +let linenum = ref 1 + +let rec nop = function + | Line _ -> incr linenum + | Ifdef (_, _, c1, c2o) -> + List.iter nop c1; + begin match c2o with + | Some c2 -> List.iter nop c2 + | None -> () + end + | _ -> () +;; + +let rec exec lp f = function + | Line line -> + if !debug then + prerr_endline (Printf.sprintf "%03d: %s" !linenum + (String.sub line 0 ((String.length line) - 1))); + f line; incr linenum + | Ifdef (sw, k, c1, c2o) -> + if List.mem k !defined = sw then begin + List.iter (exec lp f) c1; + begin match c2o with + | Some c2 -> List.iter nop c2 + | None -> () + end; + lp !linenum + end else begin + List.iter nop c1; + match c2o with + | Some c2 -> + lp !linenum; + List.iter (exec lp f) c2 + | None -> () + end + | Define k -> defined := k :: !defined + | Undef k -> + defined := List.fold_right (fun k' s -> + if k = k' then s else k' :: s) [] !defined +;; diff --git a/otherlibs/labltk/compiler/pplex.mli b/otherlibs/labltk/compiler/pplex.mli new file mode 100644 index 0000000..4eaa183 --- /dev/null +++ b/otherlibs/labltk/compiler/pplex.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +exception Error of string +val token : Lexing.lexbuf -> Ppyac.token diff --git a/otherlibs/labltk/compiler/pplex.mll b/otherlibs/labltk/compiler/pplex.mll new file mode 100644 index 0000000..61ca9f4 --- /dev/null +++ b/otherlibs/labltk/compiler/pplex.mll @@ -0,0 +1,56 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +{ +open Ppyac +exception Error of string +let linenum = ref 1 +} + +let blank = [' ' '\013' '\009' '\012'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] + +rule token = parse + blank + { token lexbuf } +| "##" [' ' '\t']* { directive lexbuf } +| ("#")? [^ '#' '\n']* '\n'? { + begin + let str = Lexing.lexeme lexbuf in + if String.length str <> 0 && str.[String.length str - 1] = '\n' then + begin + incr linenum + end; + OTHER (str) + end + } +| eof { EOF } + +and directive = parse +| "ifdef" [' ' '\t']+ { IFDEF (ident lexbuf)} +| "ifndef" [' ' '\t']+ { IFNDEF (ident lexbuf)} +| "else" { ELSE } +| "endif" { ENDIF } +| "define" [' ' '\t']+* { DEFINE (ident lexbuf)} +| "undef" [' ' '\t']+ { UNDEF (ident lexbuf)} +| _ { raise (Error (Printf.sprintf "unknown directive at line %d" !linenum))} + +and ident = parse +| lowercase identchar* | uppercase identchar* + { Lexing.lexeme lexbuf } +| _ { raise (Error (Printf.sprintf "illegal identifier at line %d" !linenum)) } diff --git a/otherlibs/labltk/compiler/ppparse.ml b/otherlibs/labltk/compiler/ppparse.ml new file mode 100644 index 0000000..3d1ee2a --- /dev/null +++ b/otherlibs/labltk/compiler/ppparse.ml @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +exception Error of string + +let parse_channel ic = + let lexbuf = Lexing.from_channel ic in + try + Ppyac.code_list Pplex.token lexbuf + with + | Pplex.Error s -> + let loc_start = Lexing.lexeme_start lexbuf + and loc_end = Lexing.lexeme_end lexbuf + in + raise (Error (Printf.sprintf "parse error at char %d, %d: %s" + loc_start loc_end s)) + | Parsing.Parse_error -> + let loc_start = Lexing.lexeme_start lexbuf + and loc_end = Lexing.lexeme_end lexbuf + in + raise (Error (Printf.sprintf "parse error at char %d, %d" + loc_start loc_end)) +;; diff --git a/otherlibs/labltk/compiler/ppyac.mly b/otherlibs/labltk/compiler/ppyac.mly new file mode 100644 index 0000000..da7ee68 --- /dev/null +++ b/otherlibs/labltk/compiler/ppyac.mly @@ -0,0 +1,52 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +%{ +open Code +%} + +%token <string> IFDEF +%token <string> IFNDEF +%token ELSE +%token ENDIF +%token <string> DEFINE +%token <string> UNDEF +%token <string> OTHER +%token EOF + +/* entry */ + +%start code_list +%type <Code.code list> code_list + +%% + +code_list: + /* empty */ { [] } + | code code_list { $1 :: $2 } +; + +code: + | DEFINE { Define $1 } + | UNDEF { Undef $1 } + | IFDEF code_list ELSE code_list ENDIF { Ifdef (true, $1, $2, Some ($4)) } + | IFNDEF code_list ELSE code_list ENDIF { Ifdef (false, $1, $2, Some ($4)) } + | IFDEF code_list ENDIF { Ifdef (true, $1, $2, None) } + | IFNDEF code_list ENDIF { Ifdef (false, $1, $2, None) } + | OTHER { Line $1 } +; + +%% diff --git a/otherlibs/labltk/compiler/printer.ml b/otherlibs/labltk/compiler/printer.ml new file mode 100644 index 0000000..60362d1 --- /dev/null +++ b/otherlibs/labltk/compiler/printer.ml @@ -0,0 +1,173 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +open Tables;; + +open Format;; + +let escape_string s = + let more = ref 0 in + for i = 0 to String.length s - 1 do + match s.[i] with + | '\\' | '"' -> incr more + | _ -> () + done; + if !more = 0 then s else + let res = String.create (String.length s + !more) in + let j = ref 0 in + for i = 0 to String.length s - 1 do + let c = s.[i] in + match c with + | '\\' | '"' -> res.[!j] <- '\\'; incr j; res.[!j] <- c; incr j + | _ -> res.[!j] <- c; incr j + done; + res;; + +let escape_char c = if c = '\'' then "\\'" else String.make 1 c;; + +let print_quoted_string s = printf "\"%s\"" (escape_string s);; +let print_quoted_char c = printf "'%s'" (escape_char c);; +let print_quoted_int i = + if i < 0 then printf "(%d)" i else printf "%d" i;; +let print_quoted_float f = + if f <= 0.0 then printf "(%f)" f else printf "%f" f;; + +(* Iterators *) +let print_list f l = + printf "@[<1>["; + let rec pl = function + | [] -> printf "@;<0 -1>]@]" + | [x] -> f x; pl [] + | x :: xs -> f x; printf ";@ "; pl xs in + pl l;; + +let print_array f v = + printf "@[<2>[|"; + let l = Array.length v in + if l >= 1 then f v.(0); + if l >= 2 then + for i = 1 to l - 1 do + printf ";@ "; f v.(i) + done; + printf "@;<0 -1>|]@]";; + +let print_option f = function + | None -> print_string "None" + | Some x -> printf "@[<1>Some@ "; f x; printf "@]";; + +let print_bool = function + | true -> print_string "true" | _ -> print_string "false";; + +let print_poly x = print_string "<poly>";; + +(* Types of the description language *) +let rec print_mltype = function + | Unit -> printf "Unit" | Int -> printf "Int" | Float -> printf "Float" + | Bool -> printf "Bool" | Char -> printf "Char" | String -> printf "String" + | List m -> printf "@[<1>(%s@ " "List"; print_mltype m; printf ")@]" + | Product l_m -> + printf "@[<1>(%s@ " "Product"; print_list print_mltype l_m; printf ")@]" + | Record l_t_s_m -> + printf "@[<1>(%s@ " "Record"; + print_list + (function (s, m) -> + printf "@[<1>("; print_quoted_string s; printf ",@ "; print_mltype m; + printf ")@]") + l_t_s_m; + printf ")@]" + | UserDefined s -> + printf "@[<1>(%s@ " "UserDefined"; print_quoted_string s; printf ")@]" + | Subtype (s, s0) -> + printf "@[<1>(%s@ " "Subtype"; printf "@[<1>("; print_quoted_string s; + printf ",@ "; print_quoted_string s0; printf ")@]"; printf ")@]" + | Function m -> + printf "@[<1>(%s@ " "Function"; print_mltype m; printf ")@]" + | As (m, s) -> + printf "@[<1>(%s@ " "As"; printf "@[<1>("; print_mltype m; printf ",@ "; + print_quoted_string s; printf ")@]"; printf ")@]";; + +let rec print_template = function + | StringArg s -> + printf "@[<1>(%s@ " "StringArg"; print_quoted_string s; printf ")@]" + | TypeArg (s, m) -> + printf "@[<1>(%s@ " "TypeArg"; printf "@[<1>("; print_quoted_string s; + printf ",@ "; print_mltype m; printf ")@]"; printf ")@]" + | ListArg l_t -> + printf "@[<1>(%s@ " "ListArg"; print_list print_template l_t; + printf ")@]" + | OptionalArgs (s, l_t, l_t0) -> + printf "@[<1>(%s@ " "OptionalArgs"; printf "@[<1>("; + print_quoted_string s; printf ",@ "; print_list print_template l_t; + printf ",@ "; print_list print_template l_t0; printf ")@]"; printf ")@]";; + +(* Sorts of components *) +let rec print_component_type = function + | Constructor -> printf "Constructor" | Command -> printf "Command" + | External -> printf "External";; + +(* Full definition of a component *) +let rec print_fullcomponent = function + {component = c; ml_name = s; var_name = s0; template = t; result = m; + safe = b; + } -> + printf "@[<1>{"; printf "@[<1>component =@ "; print_component_type c; + printf ";@]@ "; printf "@[<1>ml_name =@ "; print_quoted_string s; + printf ";@]@ "; printf "@[<1>var_name =@ "; print_quoted_string s0; + printf ";@]@ "; printf "@[<1>template =@ "; print_template t; + printf ";@]@ "; printf "@[<1>result =@ "; print_mltype m; printf ";@]@ "; + printf "@[<1>safe =@ "; print_bool b; printf ";@]@ "; printf "@,}@]";; + +(* components are given either in full or abbreviated *) +let rec print_component = function + | Full f -> printf "@[<1>(%s@ " "Full"; print_fullcomponent f; printf ")@]" + | Abbrev s -> + printf "@[<1>(%s@ " "Abbrev"; print_quoted_string s; printf ")@]";; + +(* A type definition *) +(* + requires_widget_context: the converter of the type MUST be passed + an additional argument of type Widget. +*) +let rec print_parser_arity = function + | OneToken -> printf "OneToken" | MultipleToken -> printf "MultipleToken";; + +let rec print_type_def = function + {parser_arity = p; constructors = l_f; subtypes = l_t_s_l_f; + requires_widget_context = b; variant = b0; + } -> + printf "@[<1>{"; printf "@[<1>parser_arity =@ "; print_parser_arity p; + printf ";@]@ "; printf "@[<1>constructors =@ "; + print_list print_fullcomponent l_f; printf ";@]@ "; + printf "@[<1>subtypes =@ "; + print_list + (function (s, l_f0) -> + printf "@[<1>("; print_quoted_string s; printf ",@ "; + print_list print_fullcomponent l_f0; printf ")@]") + l_t_s_l_f; + printf ";@]@ "; printf "@[<1>requires_widget_context =@ "; print_bool b; + printf ";@]@ "; printf "@[<1>variant =@ "; print_bool b0; printf ";@]@ "; + printf "@,}@]";; + +let rec print_module_type = function + | Widget -> printf "Widget" | Family -> printf "Family";; + +let rec print_module_def = function + {module_type = m; commands = l_f; externals = l_f0; } -> + printf "@[<1>{"; printf "@[<1>module_type =@ "; print_module_type m; + printf ";@]@ "; printf "@[<1>commands =@ "; + print_list print_fullcomponent l_f; printf ";@]@ "; + printf "@[<1>externals =@ "; print_list print_fullcomponent l_f0; + printf ";@]@ "; printf "@,}@]";; diff --git a/otherlibs/labltk/compiler/tables.ml b/otherlibs/labltk/compiler/tables.ml new file mode 100644 index 0000000..9739a3c --- /dev/null +++ b/otherlibs/labltk/compiler/tables.ml @@ -0,0 +1,427 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tables.ml,v 1.20 2002-04-26 12:15:48 furuse Exp $ *) + +open StdLabels +open Support + +(* Internal compiler errors *) + +exception Compiler_Error of string +let fatal_error s = raise (Compiler_Error s) + + +(* Types of the description language *) +type mltype = + Unit + | Int + | Float + | Bool + | Char + | String + | List of mltype + | Product of mltype list + | Record of (string * mltype) list + | UserDefined of string + | Subtype of string * string + | Function of mltype (* arg type only *) + | As of mltype * string + +type template = + StringArg of string + | TypeArg of string * mltype + | ListArg of template list + | OptionalArgs of string * template list * template list + +(* Sorts of components *) +type component_type = + Constructor + | Command + | External + +(* Full definition of a component *) +type fullcomponent = { + component : component_type; + ml_name : string; (* used for camltk *) + var_name : string; (* used just for labltk *) + template : template; + result : mltype; + safe : bool + } + +let sort_components = + List.sort ~cmp:(fun c1 c2 -> compare c1.ml_name c2.ml_name) + + +(* components are given either in full or abbreviated *) +type component = + Full of fullcomponent + | Abbrev of string + +(* A type definition *) +(* + requires_widget_context: the converter of the type MUST be passed + an additional argument of type Widget. +*) + +type parser_arity = + OneToken +| MultipleToken + +type type_def = { + parser_arity : parser_arity; + mutable constructors : fullcomponent list; + mutable subtypes : (string * fullcomponent list) list; + mutable requires_widget_context : bool; + mutable variant : bool +} + +type module_type = + Widget + | Family + +type module_def = { + module_type : module_type; + commands : fullcomponent list; + externals : fullcomponent list +} + +(******************** The tables ********************) + +(* the table of all explicitly defined types *) +let types_table = (Hashtbl.create 37 : (string, type_def) Hashtbl.t) +(* "builtin" types *) +let types_external = ref ([] : (string * parser_arity) list) +(* dependancy order *) +let types_order = (Tsort.create () : string Tsort.porder) +(* Types of atomic values returned by Tk functions *) +let types_returned = ref ([] : string list) +(* Function table *) +let function_table = ref ([] : fullcomponent list) +(* Widget/Module table *) +let module_table = (Hashtbl.create 37 : (string, module_def) Hashtbl.t) + + +(* variant name *) +let rec getvarname ml_name temp = + let offhypben s = + let s = String.copy s in + if (try String.sub s ~pos:0 ~len:1 with _ -> "") = "-" then + String.sub s ~pos:1 ~len:(String.length s - 1) + else s + and makecapital s = + begin + try + let cd = s.[0] in + if cd >= 'a' && cd <= 'z' then + s.[0] <- Char.chr (Char.code cd + (Char.code 'A' - Char.code 'a')) + with + _ -> () + end; + s + in + let head = makecapital (offhypben begin + match temp with + StringArg s -> s + | TypeArg (s,t) -> s + | ListArg (h::_) -> getvarname ml_name h + | OptionalArgs (s,_,_) -> s + | ListArg [] -> "" + end) + in + let varname = if head = "" then ml_name + else if head.[0] >= 'A' && head.[0] <= 'Z' then head + else ml_name + in varname + +(***** Some utilities on the various tables *****) +(* Enter a new empty type *) +let new_type typname arity = + Tsort.add_element types_order typname; + let typdef = {parser_arity = arity; + constructors = []; + subtypes = []; + requires_widget_context = false; + variant = false} in + Hashtbl.add types_table typname typdef; + typdef + + +(* Assume that types not yet defined are not subtyped *) +(* Widget is builtin and implicitly subtyped *) +let is_subtyped s = + s = "widget" || + try + let typdef = Hashtbl.find types_table s in + typdef.subtypes <> [] + with + Not_found -> false + +let requires_widget_context s = + try + (Hashtbl.find types_table s).requires_widget_context + with + Not_found -> false + +let declared_type_parser_arity s = + try + (Hashtbl.find types_table s).parser_arity + with + Not_found -> + try List.assoc s !types_external + with + Not_found -> + prerr_string "Type "; prerr_string s; + prerr_string " is undeclared external or undefined\n"; + prerr_string ("Assuming cTKtoCAML"^s^" : string -> "^s^"\n"); + OneToken + +let rec type_parser_arity = function + Unit -> OneToken + | Int -> OneToken + | Float -> OneToken + | Bool -> OneToken + | Char -> OneToken + | String -> OneToken + | List _ -> MultipleToken + | Product _ -> MultipleToken + | Record _ -> MultipleToken + | UserDefined s -> declared_type_parser_arity s + | Subtype (s,_) -> declared_type_parser_arity s + | Function _ -> OneToken + | As (ty, _) -> type_parser_arity ty + +let enter_external_type s v = + types_external := (s,v)::!types_external + +(*** Stuff for topological Sort.list of types ***) +(* Make sure all types used in commands and functions are in *) +(* the table *) +let rec enter_argtype = function + Unit | Int | Float | Bool | Char | String -> () + | List ty -> enter_argtype ty + | Product tyl -> List.iter ~f:enter_argtype tyl + | Record tyl -> List.iter tyl ~f:(fun (l,t) -> enter_argtype t) + | UserDefined s -> Tsort.add_element types_order s + | Subtype (s,_) -> Tsort.add_element types_order s + | Function ty -> enter_argtype ty + | As (ty, _) -> enter_argtype ty + +let rec enter_template_types = function + StringArg _ -> () + | TypeArg (l,t) -> enter_argtype t + | ListArg l -> List.iter ~f:enter_template_types l + | OptionalArgs (_,tl,_) -> List.iter ~f:enter_template_types tl + +(* Find type dependancies on s *) +let rec add_dependancies s = + function + List ty -> add_dependancies s ty + | Product tyl -> List.iter ~f:(add_dependancies s) tyl + | Subtype(s',_) -> if s <> s' then Tsort.add_relation types_order (s', s) + | UserDefined s' -> if s <> s' then Tsort.add_relation types_order (s', s) + | Function ty -> add_dependancies s ty + | As (ty, _) -> add_dependancies s ty + | _ -> () + +let rec add_template_dependancies s = function + StringArg _ -> () + | TypeArg (l,t) -> add_dependancies s t + | ListArg l -> List.iter ~f:(add_template_dependancies s) l + | OptionalArgs (_,tl,_) -> List.iter ~f:(add_template_dependancies s) tl + +(* Assumes functions are not nested in products, which is reasonable due to syntax*) +let rec has_callback = function + StringArg _ -> false + | TypeArg (l,Function _ ) -> true + | TypeArg _ -> false + | ListArg l -> List.exists ~f:has_callback l + | OptionalArgs (_,tl,_) -> List.exists ~f:has_callback tl + +(*** Returned types ***) +let really_add ty = + if List.mem ty !types_returned then () + else types_returned := ty :: !types_returned + +let rec add_return_type = function + Unit -> () + | Int -> () + | Float -> () + | Bool -> () + | Char -> () + | String -> () + | List ty -> add_return_type ty + | Product tyl -> List.iter ~f:add_return_type tyl + | Record tyl -> List.iter tyl ~f:(fun (l,t) -> add_return_type t) + | UserDefined s -> really_add s + | Subtype (s,_) -> really_add s + | Function _ -> fatal_error "unexpected return type (function)" (* whoah *) + | As (ty, _) -> add_return_type ty + +(*** Update tables for a component ***) +let enter_component_types {template = t; result = r} = + add_return_type r; + enter_argtype r; + enter_template_types t + + +(******************** Types and subtypes ********************) +exception Duplicate_Definition of string * string +exception Invalid_implicit_constructor of string + +(* Checking duplicate definition of constructor in subtypes *) +let rec check_duplicate_constr allowed c = + function + [] -> false (* not defined *) + | c'::rest -> + if c.ml_name = c'.ml_name then (* defined *) + if allowed then + if c.template = c'.template then true (* same arg *) + else raise (Duplicate_Definition ("constructor",c.ml_name)) + else raise (Duplicate_Definition ("constructor", c.ml_name)) + else check_duplicate_constr allowed c rest + +(* Retrieve constructor *) +let rec find_constructor cname = function + [] -> raise (Invalid_implicit_constructor cname) + | c::l -> if c.ml_name = cname then c + else find_constructor cname l + +(* Enter a type, must not be previously defined *) +let enter_type typname ?(variant = false) arity constructors = + if Hashtbl.mem types_table typname then + raise (Duplicate_Definition ("type", typname)) else + let typdef = new_type typname arity in + if variant then typdef.variant <- true; + List.iter constructors ~f: + begin fun c -> + if not (check_duplicate_constr false c typdef.constructors) + then begin + typdef.constructors <- c :: typdef.constructors; + add_template_dependancies typname c.template + end; + (* Callbacks require widget context *) + typdef.requires_widget_context <- + typdef.requires_widget_context || + has_callback c.template + end + +(* Enter a subtype *) +let enter_subtype typ arity subtyp constructors = + (* Retrieve the type if already defined, else add a new one *) + let typdef = + try Hashtbl.find types_table typ + with Not_found -> new_type typ arity + in + if List.mem_assoc subtyp typdef.subtypes + then raise (Duplicate_Definition ("subtype", typ ^" "^subtyp)) + else begin + let real_constructors = + List.map constructors ~f: + begin function + Full c -> + if not (check_duplicate_constr true c typdef.constructors) + then begin + add_template_dependancies typ c.template; + typdef.constructors <- c :: typdef.constructors + end; + typdef.requires_widget_context <- + typdef.requires_widget_context || + has_callback c.template; + c + | Abbrev name -> find_constructor name typdef.constructors + end + in + (* TODO: duplicate def in subtype are not checked *) + typdef.subtypes <- + (subtyp , List.sort real_constructors + ~cmp:(fun c1 c2 -> compare c1.var_name c2.var_name)) :: + typdef.subtypes + end + +(******************** Widgets ********************) +(* used by the parser; when enter_widget is called, + all components are assumed to be in Full form *) +let retrieve_option optname = + let optiontyp = + try Hashtbl.find types_table "options" + with + Not_found -> raise (Invalid_implicit_constructor optname) + in find_constructor optname optiontyp.constructors + +(* Sort components by type *) +let rec add_sort l obj = + match l with + [] -> [obj.component ,[obj]] + | (s',l)::rest -> + if obj.component = s' then + (s',obj::l)::rest + else + (s',l)::(add_sort rest obj) + +let separate_components = List.fold_left ~f:add_sort ~init:[] + +let enter_widget name components = + if Hashtbl.mem module_table name then + raise (Duplicate_Definition ("widget/module", name)) else + let sorted_components = separate_components components in + List.iter sorted_components ~f: + begin function + Constructor, l -> + enter_subtype "options" MultipleToken + name (List.map ~f:(fun c -> Full c) l) + | Command, l -> + List.iter ~f:enter_component_types l + | External, _ -> () + end; + let commands = + try List.assoc Command sorted_components + with Not_found -> [] + and externals = + try List.assoc External sorted_components + with Not_found -> [] + in + Hashtbl.add module_table name + {module_type = Widget; commands = commands; externals = externals} + +(******************** Functions ********************) + +let enter_function comp = + enter_component_types comp; + function_table := comp :: !function_table + + +(******************** Modules ********************) +let enter_module name components = + if Hashtbl.mem module_table name then + raise (Duplicate_Definition ("widget/module", name)) else + let sorted_components = separate_components components in + List.iter sorted_components ~f: + begin function + Constructor, l -> fatal_error "unexpected Constructor" + | Command, l -> List.iter ~f:enter_component_types l + | External, _ -> () + end; + let commands = + try List.assoc Command sorted_components + with Not_found -> [] + and externals = + try List.assoc External sorted_components + with Not_found -> [] + in + Hashtbl.add module_table name + {module_type = Family; commands = commands; externals = externals} diff --git a/otherlibs/labltk/compiler/tsort.ml b/otherlibs/labltk/compiler/tsort.ml new file mode 100644 index 0000000..bc3478e --- /dev/null +++ b/otherlibs/labltk/compiler/tsort.ml @@ -0,0 +1,89 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tsort.ml,v 1.12 2002-04-26 12:15:48 furuse Exp $ *) + +open StdLabels + +(* Topological Sort.list *) +(* d'apres More Programming Pearls *) + +(* node * pred count * successors *) + +type 'a entry = + {node : 'a; + mutable pred_count : int; + mutable successors : 'a entry list + } + +type 'a porder = 'a entry list ref + +exception Cyclic + +let find_entry order node = + let rec search_entry = + function + [] -> raise Not_found + | x::l -> if x.node = node then x else search_entry l + in + try + search_entry !order + with + Not_found -> let entry = {node = node; + pred_count = 0; + successors = []} in + order := entry::!order; + entry + +let create () = ref [] + +(* Inverted args because Sort.list builds list in reverse order *) +let add_relation order (succ,pred) = + let pred_entry = find_entry order pred + and succ_entry = find_entry order succ in + succ_entry.pred_count <- succ_entry.pred_count + 1; + pred_entry.successors <- succ_entry::pred_entry.successors + +(* Just add it *) +let add_element order e = + ignore (find_entry order e) + +let sort order = + let q = Queue.create () + and result = ref [] in + List.iter !order + ~f:(function {pred_count = n} as node -> + if n = 0 then Queue.add node q); + begin try + while true do + let t = Queue.take q in + result := t.node :: !result; + List.iter t.successors ~f: + begin fun s -> + let n = s.pred_count - 1 in + s.pred_count <- n; + if n = 0 then Queue.add s q + end + done + with + Queue.Empty -> + List.iter !order + ~f:(fun node -> if node.pred_count <> 0 + then raise Cyclic) + end; + !result + + diff --git a/otherlibs/labltk/examples_camltk/.cvsignore b/otherlibs/labltk/examples_camltk/.cvsignore new file mode 100644 index 0000000..801812f --- /dev/null +++ b/otherlibs/labltk/examples_camltk/.cvsignore @@ -0,0 +1,8 @@ +addition +eyes +fileinput +fileopen +helloworld +tetris +winskel +mytext diff --git a/otherlibs/labltk/examples_camltk/Makefile b/otherlibs/labltk/examples_camltk/Makefile new file mode 100644 index 0000000..4261305 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/Makefile @@ -0,0 +1,52 @@ +include ../support/Makefile.common + +# We are using the non-installed library ! +COMPFLAGS=-I ../lib -I ../camltk -I ../support -I $(OTHERS)/unix -w s -dllpath ../support + + +all: addition$(EXE) helloworld$(EXE) winskel$(EXE) fileinput$(EXE) \ + eyes$(EXE) tetris$(EXE) mytext$(EXE) fileopen$(EXE) + +addition$(EXE): addition.cmo + $(CAMLC) $(COMPFLAGS) -o $@ $(LIBNAME).cma addition.cmo + +helloworld$(EXE): helloworld.cmo + $(CAMLC) $(COMPFLAGS) -o $@ $(LIBNAME).cma helloworld.cmo + +winskel$(EXE): winskel.cmo + $(CAMLC) $(COMPFLAGS) -o $@ $(LIBNAME).cma winskel.cmo + +fileinput$(EXE): fileinput.cmo + $(CAMLC) $(COMPFLAGS) -o $@ unix.cma $(LIBNAME).cma fileinput.cmo + +socketinput$(EXE): socketinput.cmo + $(CAMLC) $(COMPFLAGS) -o $@ unix.cma $(LIBNAME).cma socketinput.cmo + +eyes$(EXE): eyes.cmo + $(CAMLC) $(COMPFLAGS) -o $@ unix.cma $(LIBNAME).cma eyes.cmo + +tetris$(EXE): tetris.cmo + $(CAMLC) $(COMPFLAGS) -o $@ unix.cma $(LIBNAME).cma tetris.cmo + +mytext$(EXE): mytext.cmo + $(CAMLC) $(COMPFLAGS) -o $@ unix.cma $(LIBNAME).cma mytext.cmo + +# graph$(EXE): graphics.cmo graphics_test.cmo +# $(CAMLC) -o $@ graphics.cmo graphics_test.cmo +# +# graphics_test.cmo: graphics.cmo + +fileopen$(EXE): fileopen.cmo + $(CAMLC) $(COMPFLAGS) -o $@ $(LIBNAME).cma fileopen.cmo + +clean : + rm -f *.cm? $(EXECS) addition eyes fileinput fileopen helloworld jptest mytext tetris winskel + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< diff --git a/otherlibs/labltk/examples_camltk/Makefile.nt b/otherlibs/labltk/examples_camltk/Makefile.nt new file mode 100644 index 0000000..13f27a0 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/Makefile.nt @@ -0,0 +1,38 @@ +include ../support/Makefile.common.nt + +# We are using the non-installed library ! +COMPFLAGS= -I ../lib -I ../camltk -I ../support +LINKFLAGS= -I ../lib -I ../camltk -I ../support + +# Use pieces of Makefile.config +TKLINKOPT=$(LIBNAME).cma $(TKLIBS) + +all: addition.exe helloworld.exe winskel.exe socketinput.exe + +addition.exe: addition.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ addition.cmo + +helloworld.exe: helloworld.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ helloworld.cmo + +winskel.exe: winskel.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ winskel.cmo + +socketinput.exe: socketinput.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) unix.cma \ + -o $@ socketinput.cmo + +clean : + rm -f *.cm? *.exe + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< diff --git a/otherlibs/labltk/examples_camltk/addition.ml b/otherlibs/labltk/examples_camltk/addition.ml new file mode 100644 index 0000000..d4b333d --- /dev/null +++ b/otherlibs/labltk/examples_camltk/addition.ml @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let main () = + let top = opentk () in + (* The widgets. They all have "top" as parent widget. *) + let en1 = Entry.create top [TextWidth 6; Relief Sunken] in + let lab1 = Label.create top [Text "plus"] in + let en2 = Entry.create top [TextWidth 6 ; Relief Sunken] in + let lab2 = Label.create top [Text "="] in + let result_display = Label.create top [] in + (* References holding values of entry widgets *) + let n1 = ref 0 + and n2 = ref 0 in + (* Refresh result *) + let refresh () = + Label.configure result_display [Text (string_of_int (!n1 + !n2))] in + (* Electric *) + let get_and_refresh (w,r) = + fun _ _ -> + try + r := int_of_string (Entry.get w); + refresh () + with + Failure "int_of_string" -> + Label.configure result_display [Text "error"] + in + (* Set the callbacks *) + Entry.configure en1 [XScrollCommand (get_and_refresh (en1,n1)) ]; + Entry.configure en2 [XScrollCommand (get_and_refresh (en2,n2)) ]; + (* Map the widgets *) + pack [en1;lab1;en2;lab2;result_display] []; + (* Make the window resizable *) + Wm.minsize_set top 1 1; + (* Start interaction (event-driven program) *) + mainLoop () +;; + +let _ = Printexc.catch main () ;; diff --git a/otherlibs/labltk/examples_camltk/eyes.ml b/otherlibs/labltk/examples_camltk/eyes.ml new file mode 100644 index 0000000..5666c69 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/eyes.ml @@ -0,0 +1,67 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* The eyes of Caml (CamlTk) *) + +open Camltk;; + +let _ = + let top = opentk () in + + let fw = Frame.create top [] in + pack [fw] []; + let c = Canvas.create fw [Width (Pixels 200); Height (Pixels 200)] in + let create_eye cx cy wx wy ewx ewy bnd = + let o2 = + Canvas.create_oval c + (Pixels (cx - wx)) (Pixels (cy - wy)) + (Pixels (cx + wx)) (Pixels (cy + wy)) + [Outline (NamedColor "black"); Width (Pixels 7); + FillColor (NamedColor "white")] + and o = + Canvas.create_oval c + (Pixels (cx - ewx)) (Pixels (cy - ewy)) + (Pixels (cx + ewx)) (Pixels (cy + ewy)) + [FillColor (NamedColor "black")] in + let curx = ref cx + and cury = ref cy in + bind c [[], Motion] + (BindExtend ([Ev_MouseX; Ev_MouseY], + (fun e -> + let nx, ny = + let xdiff = e.ev_MouseX - cx + and ydiff = e.ev_MouseY - cy in + let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +. + (float ydiff /. (float wy *. bnd)) ** 2.0) in + if diff > 1.0 then + truncate ((float xdiff) *. (1.0 /. diff)) + cx, + truncate ((float ydiff) *. (1.0 /. diff)) + cy + else + e.ev_MouseX, e.ev_MouseY + in + Canvas.move c o (Pixels (nx - !curx)) (Pixels (ny - !cury)); + curx := nx; + cury := ny))) + in + create_eye 60 100 30 40 5 6 0.6; + create_eye 140 100 30 40 5 6 0.6; + pack [c] [] + +let _ = Printexc.print mainLoop () + + + + diff --git a/otherlibs/labltk/examples_camltk/fileinput.ml b/otherlibs/labltk/examples_camltk/fileinput.ml new file mode 100644 index 0000000..c6190bd --- /dev/null +++ b/otherlibs/labltk/examples_camltk/fileinput.ml @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk ;; + +let top_w = opentk () ;; +let buffer = String.create 256 ;; +let (fd_in, fd_out) = Unix.pipe () ;; +let text0_w = Text.create top_w [] ;; +let entry0_w = Entry.create top_w [] ;; +let button0_w = Button.create top_w [Text "Quit"; Command (fun _ -> exit 0)] ;; +Fileevent.add_fileinput fd_in (fun _ -> + let n = Unix.read fd_in buffer 0 (String.length buffer) in + let txt = String.sub buffer 0 n in + Text.insert text0_w (TextIndex (End, [])) txt []) ;; +let send _ = + let txt = Entry.get entry0_w ^ "\n" in + Entry.delete_range entry0_w (At 0) End ; + ignore (Unix.write fd_out txt 0 (String.length txt));; + +bind entry0_w [([], KeyPressDetail "Return")] (BindSet ([], send)) ; +pack [text0_w; entry0_w; button0_w][Side Side_Top; Fill Fill_X; Expand true] ;; +mainLoop () ;; diff --git a/otherlibs/labltk/examples_camltk/fileopen.ml b/otherlibs/labltk/examples_camltk/fileopen.ml new file mode 100644 index 0000000..927c248 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/fileopen.ml @@ -0,0 +1,56 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk;; + +let win = opentk();; + +let cvs = Canvas.create win [];; + +let t = Label.create cvs [Text "File name"];; + +let b = + Button.create cvs + [Text "Save"; + Command + (function _ -> + let s = + getSaveFile + [Title "SAVE FILE TEST"; + DefaultExtension ".foo"; + FileTypes [ { typename= "just test"; + extensions= [".foo"; ".test"]; + mactypes= ["FOOO"; "BARR"] } ]; + InitialDir Filename.temp_dir_name; + InitialFile "hogehoge" ] in + Label.configure t [Text s])];; + +let bb = + Button.create cvs + [Text "Open"; + Command + (function _ -> + let s = getOpenFile [] in + Label.configure t [Text s])];; + +let q = + Button.create cvs + [Text "Quit"; + Command + (function _ -> closeTk (); exit 0)];; + +pack [cvs; q; bb; b; t] [];; + +mainLoop ();; diff --git a/otherlibs/labltk/examples_camltk/helloworld.ml b/otherlibs/labltk/examples_camltk/helloworld.ml new file mode 100644 index 0000000..b32b515 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/helloworld.ml @@ -0,0 +1,37 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk;; (* Make interface functions available *) + +let top = opentk ();; (* Initialisation of the interface *) +(* top is now the toplevel widget *) + +(* Widget initialisation *) +let b = Button.create top + [Text "foobar"; + Command (function () -> + print_string "foobar"; + print_newline(); + flush stdout)];; +(* b exists but is not yet visible *) + +let q = Button.create top + [Text "quit"; + Command closeTk];; +(* q exists but is not yet visible *) + +pack [b; q][] ;; (* Make b visible *) +mainLoop() ;; (* User interaction*) +(* You can quit this program by deleting its main window *) diff --git a/otherlibs/labltk/examples_camltk/images/CamlBook.gif b/otherlibs/labltk/examples_camltk/images/CamlBook.gif new file mode 100644 index 0000000000000000000000000000000000000000..ca9bd63d4712dd5f4bdb03ae4d80eb707e8a3165 GIT binary patch literal 15168 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 W#(f}<&o6PUV;?Vk(}qF;{r>@?I})-0 literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/examples_camltk/images/Lambda2.back.gif b/otherlibs/labltk/examples_camltk/images/Lambda2.back.gif new file mode 100644 index 0000000000000000000000000000000000000000..7cb3d2c1396865be23a8741740a4c4af2768ee18 GIT binary patch literal 53442 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 AB>(^b literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/examples_camltk/images/dojoji.back.gif b/otherlibs/labltk/examples_camltk/images/dojoji.back.gif new file mode 100644 index 0000000000000000000000000000000000000000..d397f02e359584cd6b5857a3d1bc683469768092 GIT binary patch literal 49935 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 literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/examples_camltk/jptest.ml b/otherlibs/labltk/examples_camltk/jptest.ml new file mode 100644 index 0000000..38d9694 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/jptest.ml @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Tk + +let win = opentk();; + +let b = Button.create win [ Text "¤³¤ó¤Á¤Ï" ];; +let _ = pack [b] [];; + +mainLoop();; diff --git a/otherlibs/labltk/examples_camltk/mytext.ml b/otherlibs/labltk/examples_camltk/mytext.ml new file mode 100644 index 0000000..0695d93 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/mytext.ml @@ -0,0 +1,63 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let top = opentk () + +let scroll_link sb tx = + Text.configure tx [YScrollCommand (Scrollbar.set sb)]; + Scrollbar.configure sb [ScrollCommand (Text.yview tx)] + +let f = Frame.create top [] +let text = Text.create f [] +let scrollbar = Scrollbar.create f [] + +(* kill buffer *) +let buffer = ref "" + +(* Note: for the text widgets, the insertion cursor is + not TextIndex(Insert, []), + but TextIndex(Mark "insert", []) +*) +let insertMark = TextIndex(Mark "insert", []) +let eol_insertMark = TextIndex(Mark "insert", [LineEnd]) + +let kill () = + buffer := + Text.get text insertMark eol_insertMark; + prerr_endline ("Killed: " ^ !buffer); + Text.delete text insertMark eol_insertMark +;; + +let yank () = + Text.insert text insertMark !buffer []; + prerr_endline ("Yanked: " ^ !buffer) +;; + +let _ = + scroll_link scrollbar text; + + pack [text; scrollbar][Side Side_Left; Fill Fill_Y]; + pack [f][]; + + bind text [[Control], KeyPressDetail "y"] + (BindSet ([], fun _ -> yank () )); + bind text [[Control], KeyPressDetail "k"] + (BindSet ([], fun _ -> kill () )); + + mainLoop () +;; + diff --git a/otherlibs/labltk/examples_camltk/socketinput.ml b/otherlibs/labltk/examples_camltk/socketinput.ml new file mode 100644 index 0000000..d23b8fd --- /dev/null +++ b/otherlibs/labltk/examples_camltk/socketinput.ml @@ -0,0 +1,43 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let _ = + let top_w = opentk () in + let text0_w = Text.create top_w [] in + let entry0_w = Entry.create top_w [] in + let button0_w = Button.create top_w + [Text "Quit"; Command (fun _ -> exit 0)] in + let buffer = String.create 256 in + let master_socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in + Unix.bind master_socket (Unix.ADDR_INET(Unix.inet_addr_any, 6789)); + Unix.listen master_socket 3; + print_string "Please connect to port 6789..."; print_newline(); + let (sock, _) = Unix.accept master_socket in + Fileevent.add_fileinput sock + (fun _ -> + let n = Unix.recv sock buffer 0 (String.length buffer) [] in + let txt = String.sub buffer 0 n in + Text.insert text0_w (TextIndex (End, [])) txt []); + let send _ = + let txt = Entry.get entry0_w ^ "\n" in + Entry.delete_range entry0_w (At 0) End ; + Unix.send sock txt 0 (String.length txt) []; + () in + bind entry0_w [([], KeyPressDetail "Return")] (BindSet ([], send)); + pack [text0_w; entry0_w; button0_w][Side Side_Top; Fill Fill_X; Expand true]; + mainLoop () + diff --git a/otherlibs/labltk/examples_camltk/taddition.ml b/otherlibs/labltk/examples_camltk/taddition.ml new file mode 100644 index 0000000..990812d --- /dev/null +++ b/otherlibs/labltk/examples_camltk/taddition.ml @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Tk + +let main () = + let top = opentk () in + (* The widgets. They all have "top" as parent widget. *) + let en1 = Entry.create top [TextWidth 6; Relief Sunken] in + let lab1 = Label.create top [Text "plus"] in + let en2 = Entry.create top [TextWidth 6 ; Relief Sunken] in + let lab2 = Label.create top [Text "="] in + let result_display = Label.create top [] in + (* References holding values of entry widgets *) + let n1 = ref 0 + and n2 = ref 0 in + (* Refresh result *) + let refresh () = + Label.configure result_display [Text (string_of_int (!n1 + !n2))] in + (* Electric *) + let get_and_refresh (w,r) = + fun _ _ -> + try + r := int_of_string (Entry.get w); + refresh () + with + Failure "int_of_string" -> + Label.configure result_display [Text "error"] + in + (* Set the callbacks *) + Entry.configure en1 [XScrollCommand (get_and_refresh (en1,n1)) ]; + Entry.configure en2 [XScrollCommand (get_and_refresh (en2,n2)) ]; + (* Map the widgets *) + pack [en1;lab1;en2;lab2;result_display] []; + (* Make the window resizable *) + Wm.minsize_set top 1 1; + (* Start interaction (event-driven program) *) + Threadtk.mainLoop () +;; + +let _ = Printexc.catch main () ;; diff --git a/otherlibs/labltk/examples_camltk/tetris.ml b/otherlibs/labltk/examples_camltk/tetris.ml new file mode 100644 index 0000000..79d9e3f --- /dev/null +++ b/otherlibs/labltk/examples_camltk/tetris.ml @@ -0,0 +1,685 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* A Tetris game for CamlTk *) +(* written by Jun P. Furuse *) + +open Camltk + +exception Done + +type cell = {mutable color : int; + tag : tagOrId * tagOrId * tagOrId} + +type falling_block = { + mutable pattern: int array list; + mutable bcolor: int; + mutable x: int; + mutable y: int; + mutable d: int; + mutable alive: bool +} + +let stop_a_bit = 300 + +let colors = [| + NamedColor "red"; + NamedColor "yellow"; + + NamedColor "blue"; + NamedColor "orange"; + + NamedColor "magenta"; + NamedColor "green"; + + NamedColor "cyan" +|] + +let baseurl = "images/" + +let backgrounds = + List.map (fun s -> baseurl ^ s) + [ "dojoji.back.gif"; + "Lambda2back.gif"; + "CamlBook.gif"; + ] + +(* blocks *) +let block_size = 16 +let cell_border = 2 + +let blocks = [ + [ [|"0000"; + "0000"; + "1111"; + "0000" |]; + + [|"0010"; + "0010"; + "0010"; + "0010" |]; + + [|"0000"; + "0000"; + "1111"; + "0000" |]; + + [|"0010"; + "0010"; + "0010"; + "0010" |] ]; + + [ [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "0111"; + "0100"; + "0000" |]; + + [|"0000"; + "0110"; + "0010"; + "0010" |]; + + [|"0000"; + "0010"; + "1110"; + "0000" |]; + + [|"0100"; + "0100"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "0100"; + "0111"; + "0000" |]; + + [|"0000"; + "0110"; + "0100"; + "0100" |]; + + [|"0000"; + "1110"; + "0010"; + "0000" |]; + + [|"0010"; + "0010"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "1100"; + "0110"; + "0000" |]; + + [|"0010"; + "0110"; + "0100"; + "0000" |]; + + [|"0000"; + "1100"; + "0110"; + "0000" |]; + + [|"0010"; + "0110"; + "0100"; + "0000" |] ]; + + [ [|"0000"; + "0011"; + "0110"; + "0000" |]; + + [|"0100"; + "0110"; + "0010"; + "0000" |]; + + [|"0000"; + "0011"; + "0110"; + "0000" |]; + + [|"0000"; + "0100"; + "0110"; + "0010" |] ]; + + [ [|"0000"; + "0000"; + "1110"; + "0100" |]; + + [|"0000"; + "0100"; + "1100"; + "0100" |]; + + [|"0000"; + "0100"; + "1110"; + "0000" |]; + + [|"0000"; + "0100"; + "0110"; + "0100" |] ] + +] + +let line_empty = int_of_string "0b1110000000000111" +let line_full = int_of_string "0b1111111111111111" + +let decode_block dvec = + let btoi d = int_of_string ("0b"^d) in + Array.map btoi dvec + +let init fw = + let scorev = Textvariable.create () + and linev = Textvariable.create () + and levv = Textvariable.create () + and namev = Textvariable.create () + in + let f = Frame.create fw [BorderWidth (Pixels 2)] in + let c = Canvas.create f [Width (Pixels (block_size * 10)); + Height (Pixels (block_size * 20)); + BorderWidth (Pixels cell_border); + Relief Sunken; + Background Black] + and r = Frame.create f [] + and r' = Frame.create f [] in + + let nl = Label.create r [Text "Next"; Font "variable"] in + let nc = Canvas.create r [Width (Pixels (block_size * 4)); + Height (Pixels (block_size * 4)); + BorderWidth (Pixels cell_border); + Relief Sunken; + Background Black] in + let scl = Label.create r [Text "Score"; Font "variable"] in + let sc = Label.create r [TextVariable scorev; Font "variable"] in + let lnl = Label.create r [Text "Lines"; Font "variable"] in + let ln = Label.create r [TextVariable linev; Font "variable"] in + let levl = Label.create r [Text "Level"; Font "variable"] in + let lev = Label.create r [TextVariable levv; Font "Variable"] in + let newg = Button.create r [Text "New Game"; Font "variable"] in + let exitg = Button.create r [Text "Quit"; Font "variable"] in + + pack [f] []; + pack [c; r; r'] [Side Side_Left; Fill Fill_Y]; + pack [nl; nc] [Side Side_Top]; + pack [scl; sc; lnl; ln; levl; lev; newg; exitg] [Side Side_Top]; + + let cells_src = Array.create 20 (Array.create 10 ()) in + let cells = Array.map (Array.map (fun () -> + {tag= + (let t1, t2, t3 = + Canvas.create_rectangle c + (Pixels (-block_size - 8)) (Pixels (-block_size - 8)) + (Pixels (-9)) (Pixels (-9)) [], + Canvas.create_rectangle c + (Pixels (-block_size - 10)) (Pixels (-block_size - 10)) + (Pixels (-11)) (Pixels (-11)) [], + Canvas.create_rectangle c + (Pixels (-block_size - 12)) (Pixels (-block_size - 12)) + (Pixels (-13)) (Pixels (-13)) [] + in + Canvas.raise_top c t1; + Canvas.raise_top c t2; + Canvas.lower_bot c t3; + t1,t2,t3); + color= 0})) cells_src + in + let nexts_src = Array.create 4 (Array.create 4 ()) in + let nexts = + Array.map (Array.map (fun () -> + {tag= + (let t1, t2, t3 = + Canvas.create_rectangle nc + (Pixels (-block_size - 8)) (Pixels (-block_size - 8)) + (Pixels (-9)) (Pixels (-9)) [], + Canvas.create_rectangle nc + (Pixels (-block_size - 10)) (Pixels (-block_size - 10)) + (Pixels (-11)) (Pixels (-11)) [], + Canvas.create_rectangle nc + (Pixels (-block_size - 12)) (Pixels (-block_size - 12)) + (Pixels (-13)) (Pixels (-13)) [] + in + Canvas.raise_top nc t1; + Canvas.raise_top nc t2; + Canvas.lower_bot nc t3; + t1, t2, t3); + color= 0})) nexts_src in + let game_over () = () + in + [f; c; r; nl; nc; scl; sc; levl; lev; lnl; ln], newg, exitg, + (c, cells), (nc, nexts), scorev, linev, levv, game_over + +let cell_get (c, cf) x y = + (Array.get (Array.get cf y) x).color + +let cell_set (c, cf) x y col = + let cur = Array.get (Array.get cf y) x in + let t1,t2,t3 = cur.tag in + if cur.color = col then () + else + if cur.color <> 0 && col = 0 then + begin + Canvas.move c t1 + (Pixels (- block_size * (x + 1) -10 - cell_border * 2)) + (Pixels (- block_size * (y + 1) -10 - cell_border * 2)); + Canvas.move c t2 + (Pixels (- block_size * (x + 1) -10 - cell_border * 2)) + (Pixels (- block_size * (y + 1) -10 - cell_border * 2)); + Canvas.move c t3 + (Pixels (- block_size * (x + 1) -10 - cell_border * 2)) + (Pixels (- block_size * (y + 1) -10 - cell_border * 2)) + end + else + begin + Canvas.configure_rectangle c t2 + [FillColor (Array.get colors (col - 1)); + Outline (Array.get colors (col - 1))]; + Canvas.configure_rectangle c t1 + [FillColor Black; + Outline Black]; + Canvas.configure_rectangle c t3 + [FillColor (NamedColor "light gray"); + Outline (NamedColor "light gray")]; + if cur.color = 0 && col <> 0 then + begin + Canvas.move c t1 + (Pixels (block_size * (x+1)+10+ cell_border*2)) + (Pixels (block_size * (y+1)+10+ cell_border*2)); + Canvas.move c t2 + (Pixels (block_size * (x+1)+10+ cell_border*2)) + (Pixels (block_size * (y+1)+10+ cell_border*2)); + Canvas.move c t3 + (Pixels (block_size * (x+1)+10+ cell_border*2)) + (Pixels (block_size * (y+1)+10+ cell_border*2)) + end + end; + cur.color <- col + +let draw_block field col d x y = + for iy = 0 to 3 do + let base = ref 1 in + let xd = Array.get d iy in + for ix = 0 to 3 do + if xd land !base <> 0 then + begin + try cell_set field (ix + x) (iy + y) col with _ -> () + end + else + begin + (* cell_set field (ix + x) (iy + y) 0 *) () + end; + base := !base lsl 1 + done + done + +let timer_ref = (ref None : Timer.t option ref) +(* I know, this should be timer ref, but I'm not sure what should be + the initial value ... *) + +let remove_timer () = + match !timer_ref with + | None -> () + | Some t -> Timer.remove t (* ; prerr_endline "removed!" *) + +let do_after milli f = + timer_ref := Some (Timer.add milli f) + +let copy_block c = + { pattern= !c.pattern; + bcolor= !c.bcolor; + x= !c.x; + y= !c.y; + d= !c.d; + alive= !c.alive } + +let _ = + let top = opentk () in + let lb = Label.create top [] + and fw = Frame.create top [] + in + let set_message s = Label.configure lb [Text s] in + pack [lb; fw] [Side Side_Top]; + let score = ref 0 in + let line = ref 0 in + let level = ref 0 in + let time = ref 1000 in + let blocks = List.map (List.map decode_block) blocks in + let field = Array.create 26 0 in + let widgets, newg, exitg, cell_field, next_field, + scorev, linev, levv, game_over = + init fw in + let canvas = fst cell_field in + + let init_field () = + for i = 0 to 25 do + field.(i) <- line_empty + done; + field.(23) <- line_full; + for i = 0 to 19 do + for j = 0 to 9 do + cell_set cell_field j i 0 + done + done; + for i = 0 to 3 do + for j = 0 to 3 do + cell_set next_field j i 0 + done + done + in + + let draw_falling_block fb = + draw_block cell_field fb.bcolor + (List.nth fb.pattern fb.d) (fb.x - 3) (fb.y - 3) + + and erase_falling_block fb = + draw_block cell_field 0 (List.nth fb.pattern fb.d) (fb.x - 3) (fb.y - 3) + in + + let stone fb = + for i=0 to 3 do + let cur = field.(i + fb.y) in + field.(i + fb.y) <- + cur lor ((List.nth fb.pattern fb.d).(i) lsl fb.x) + done; + for i=0 to 2 do + field.(i) <- line_empty + done + + and clear fb = + let l = ref 0 in + for i = 0 to 3 do + if i + fb.y >= 3 && i + fb.y <= 22 then + if field.(i + fb.y) = line_full then + begin + incr l; + field.(i + fb.y) <- line_empty; + for j = 0 to 9 do + cell_set cell_field j (i + fb.y - 3) 0 + done + end + done; + !l + + and fall_lines () = + let eye = ref 22 (* bottom *) + and cur = ref 22 (* bottom *) + in + try + while !eye >= 3 do + while field.(!eye) = line_empty do + decr eye; + if !eye = 2 then raise Done + done; + field.(!cur) <- field.(!eye); + for j = 0 to 9 do + cell_set cell_field j (!cur-3) (cell_get cell_field j (!eye-3)) + done; + decr eye; + decr cur + done + with Done -> (); + for i = 3 to !cur do + field.(i) <- line_empty; + for j = 0 to 9 do + cell_set cell_field j (i-3) 0 + done + done + in + + let next = ref 42 (* THE ANSWER *) + and current = + ref { pattern= [[|0;0;0;0|]]; bcolor=0; x=0; y=0; d=0; alive= false} + in + + let draw_next () = + draw_block next_field (!next+1) (List.hd (List.nth blocks !next)) 0 0 + + and erase_next () = + draw_block next_field 0 (List.hd (List.nth blocks !next)) 0 0 + in + + let set_nextblock () = + current := + { pattern= (List.nth blocks !next); + bcolor= !next+1; + x=6; y= 1; d= 0; alive= true}; + erase_next (); + next := Random.int 7; + draw_next () + in + + let death_check fb = + try + for i=0 to 3 do + let cur = field.(i + fb.y) in + if cur land ((List.nth fb.pattern fb.d).(i) lsl fb.x) <> 0 + then raise Done + done; + false + with + Done -> true + in + + let try_to_move m = + if !current.alive then + let sub m = + if death_check m then false + else + begin + erase_falling_block !current; + draw_falling_block m; + current := m; + true + end + in + if sub m then () + else + begin + m.x <- m.x + 1; + if sub m then () + else + begin + m.x <- m.x - 2; + ignore (sub m) + end + end + else () + in + + let image_load = + let i = Canvas.create_image canvas + (Pixels (block_size * 5 + block_size / 2)) + (Pixels (block_size * 10 + block_size / 2)) + [Anchor Center] in + Canvas.lower_bot canvas i; + let img = Imagephoto.create [] in + fun file -> + try + Imagephoto.configure img [File file]; + Canvas.configure_image canvas i [ImagePhoto img] + with + _ -> + begin + Printf.eprintf "%s : No such image...\n" file; + flush stderr + end + in + + let add_score l = + let pline = !line in + if l <> 0 then + begin + line := !line + l; + score := !score + l * l; + set_message (Printf.sprintf "%d pts" (1 lsl ((l - 1) * 2))) + end; + Textvariable.set linev (string_of_int !line); + Textvariable.set scorev (string_of_int !score); + + if !line /10 <> pline /10 then + (* update the background every 10 lines. *) + begin + let num_image = List.length backgrounds - 1 in + let n = !line/10 in + let n = if n > num_image then num_image else n in + let file = List.nth backgrounds n in + image_load file; + (* Future work: We should gain level after an image is put... *) + incr level; + Textvariable.set levv (string_of_int !level) + end + in + + let rec newblock () = + set_message "TETRIS"; + set_nextblock (); + draw_falling_block !current; + if death_check !current then + begin + !current.alive <- false; + set_message "GAME OVER"; + game_over () + end + else + begin + time := 1100 - (!level / 4 * 300) - ((!level mod 4) * 200); + if !time < 60 - !level * 3 then time := 60 - !level * 3; + do_after stop_a_bit loop + end + + and loop () = + let m = copy_block current in + m.y <- m.y + 1; + if death_check m then + begin + !current.alive <- false; + stone !current; + do_after stop_a_bit (fun () -> + let l = clear !current in + if l > 0 then + do_after stop_a_bit (fun () -> + fall_lines (); + add_score l; + do_after stop_a_bit newblock) + else + newblock ()) + end + else + begin + erase_falling_block !current; + draw_falling_block m; + current := m; + do_after !time loop + end + in + + let bind_game w = + bind w [([], KeyPress)] (BindSet ([Ev_KeySymString], + fun e -> + match e.ev_KeySymString with + | "h" -> + let m = copy_block current in + m.x <- m.x - 1; + try_to_move m + | "j" -> + let m = copy_block current in + m.d <- m.d + 1; + if m.d = List.length m.pattern then m.d <- 0; + try_to_move m + | "k" -> + let m = copy_block current in + m.d <- m.d - 1; + if m.d < 0 then m.d <- List.length m.pattern - 1; + try_to_move m + | "l" -> + let m = copy_block current in + m.x <- m.x + 1; + try_to_move m + | "m" -> + remove_timer (); + loop () + | "space" -> + if !current.alive then + begin + let m = copy_block current + and n = copy_block current in + while + m.y <- m.y + 1; + if death_check m then false + else begin n.y <- m.y; true end + do () done; + erase_falling_block !current; + draw_falling_block n; + current := n; + remove_timer (); + loop () + end + | _ -> () + )) + in + + let game_init () = + (* Game Initialization *) + set_message "Initializing ..."; + remove_timer (); + image_load (List.hd backgrounds); + time := 1000; + score := 0; + line := 0; + level := 1; + add_score 0; + init_field (); + next := Random.int 7; + set_message "Welcome to TETRIS"; + set_nextblock (); + draw_falling_block !current; + do_after !time loop + in + bind_game top; + Button.configure newg [Command game_init]; + Button.configure exitg [Command (fun () -> closeTk (); exit 0)]; + game_init () + +let _ = Printexc.print mainLoop () diff --git a/otherlibs/labltk/examples_camltk/text.ml b/otherlibs/labltk/examples_camltk/text.ml new file mode 100644 index 0000000..0001ae7 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/text.ml @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Tk + +let top = opentk () + +let scroll_link sb tx = + Text.configure tx [YScrollCommand (Scrollbar.set sb)]; + Scrollbar.configure sb [ScrollCommand (Text.yview tx)] + +let f = Frame.create top [] +let text = Text.create f [] +let scrollbar = Scrollbar.create f [] + +let buffer = ref "" + +let kill () = + buffer := + Text.get text (TextIndex (Insert, [])) + (TextIndex (Insert, [LineEnd])); + Text.delete text (TextIndex (Insert, [])) + (TextIndex (Insert, [LineEnd])) +;; + +let yank () = + Text.insert text (TextIndex (Insert, [])) !buffer [] + +let _ = bind text [[Control], KeyPressDetail "y"] (BindSet ([], fun _ -> + yank () )) +;; +let _ = bind text [[Control], KeyPressDetail "k"] (BindSet ([], fun _ -> + kill () )) +;; + +let _ = + scroll_link scrollbar text; + + pack [text;f][]; + pack [f][]; + mainLoop () +;; + diff --git a/otherlibs/labltk/examples_camltk/winskel.ml b/otherlibs/labltk/examples_camltk/winskel.ml new file mode 100644 index 0000000..2ca1da1 --- /dev/null +++ b/otherlibs/labltk/examples_camltk/winskel.ml @@ -0,0 +1,63 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* This examples is based on Ousterhout's book (fig 16.15) *) +open Camltk + +let main () = + let top = opentk() in + let mbar = Frame.create top [Relief Raised; BorderWidth (Pixels 2)] + and dummy = + Frame.create top [Width (Centimeters 10.); Height (Centimeters 5.)] in + pack [mbar; dummy] [Side Side_Top; Fill Fill_X]; + let file = Menubutton.create mbar [Text "File"; UnderlinedChar 0] + and edit = Menubutton.create mbar [Text "Edit"; UnderlinedChar 0] + and graphics = Menubutton.create mbar [Text "Graphics"; UnderlinedChar 0] + and text = Menubutton.create mbar [Text "Text"; UnderlinedChar 0] + and view = Menubutton.create mbar [Text "View"; UnderlinedChar 0] + and help = Menubutton.create mbar [Text "Help"; UnderlinedChar 0] in + pack [file;edit;graphics;text;view] [Side Side_Left]; + pack [help] [Side Side_Right]; + (* same code as chap16-14 *) + let m = Menu.create text [] in + let bold = Textvariable.create() + and italic = Textvariable.create() + and underline = Textvariable.create() in + Menu.add_checkbutton m [Label "Bold"; Variable bold]; + Menu.add_checkbutton m [Label "Italic"; Variable italic]; + Menu.add_checkbutton m [Label "Underline"; Variable underline]; + Menu.add_separator m; + let font = Textvariable.create() in + Menu.add_radiobutton m [Label "Times"; Variable font; Value "times"]; + Menu.add_radiobutton m [Label "Helvetica"; Variable font; Value "helvetica"] +; + Menu.add_radiobutton m [Label "Courier"; Variable font; Value "courier"]; + Menu.add_separator m; + Menu.add_command m [Label "Insert Bullet"; + Command (function () -> + print_string "Insert Bullet\n"; + flush stdout)]; + Menu.add_command m [Label "Margins and Tags..."; + Command (function () -> + print_string "margins\n"; + flush stdout)]; + Menubutton.configure text [Menu m]; + + mainLoop() + + + +let _ = + Printexc.catch main () diff --git a/otherlibs/labltk/examples_labltk/.cvsignore b/otherlibs/labltk/examples_labltk/.cvsignore new file mode 100644 index 0000000..c1f6ec6 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/.cvsignore @@ -0,0 +1,8 @@ +calc +clock +demo +eyes +hello +tetris +lang +taquin diff --git a/otherlibs/labltk/examples_labltk/Lambda2.back.gif b/otherlibs/labltk/examples_labltk/Lambda2.back.gif new file mode 100644 index 0000000000000000000000000000000000000000..7cb3d2c1396865be23a8741740a4c4af2768ee18 GIT binary patch literal 53442 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 AB>(^b literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/examples_labltk/Makefile b/otherlibs/labltk/examples_labltk/Makefile new file mode 100644 index 0000000..3fa0263 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/Makefile @@ -0,0 +1,53 @@ +include ../support/Makefile.common + +COMPFLAGS=-I ../lib -I ../labltk -I ../support -I $(OTHERS)/unix -w s -dllpath ../support + +all: hello demo eyes calc clock tetris lang + +opt: hello.opt demo.opt eyes.opt calc.opt clock.opt tetris.opt + +hello: hello.cmo + $(CAMLC) $(COMPFLAGS) -o hello $(LIBNAME).cma hello.cmo + +demo: demo.cmo + $(CAMLC) $(COMPFLAGS) -o demo $(LIBNAME).cma demo.cmo + +eyes: eyes.cmo + $(CAMLC) $(COMPFLAGS) -o eyes $(LIBNAME).cma eyes.cmo + +calc: calc.cmo + $(CAMLC) $(COMPFLAGS) -o calc $(LIBNAME).cma calc.cmo + +clock: clock.cmo + $(CAMLC) $(COMPFLAGS) -o clock $(LIBNAME).cma unix.cma clock.cmo + +clock.opt: clock.cmx + $(CAMLOPT) $(COMPFLAGS) -o clock.opt \ + $(LIBNAME).cmxa unix.cmxa clock.cmx + +tetris: tetris.cmo + $(CAMLC) $(COMPFLAGS) -o tetris $(LIBNAME).cma tetris.cmo + +taquin: taquin.cmo + $(CAMLC) $(COMPFLAGS) -o taquin $(LIBNAME).cma taquin.cmo + +lang: lang.cmo + $(CAMLC) $(COMPFLAGS) -o lang $(LIBNAME).cma lang.cmo + +clean: + rm -f hello demo eyes calc clock tetris lang *.opt *.o *.cm* + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmx .cmo .opt + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.cmx.opt: + $(CAMLOPT) $(COMPFLAGS) -o $@ $(LIBNAME).cmxa $< diff --git a/otherlibs/labltk/examples_labltk/Makefile.nt b/otherlibs/labltk/examples_labltk/Makefile.nt new file mode 100644 index 0000000..825d9e4 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/Makefile.nt @@ -0,0 +1,50 @@ +include ../support/Makefile.common.nt + +# We are using the non-installed library ! +COMPFLAGS= -I ../lib -I ../labltk -I ../support +LINKFLAGS= -I ../lib -I ../labltk -I ../support + +# Use pieces of Makefile.config +TKLINKOPT=$(LIBNAME).cma $(TKLIBS) + +all: hello.exe demo.exe eyes.exe calc.exe clock.exe tetris.exe lang.exe + +hello.exe: hello.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ hello.cmo + +demo.exe: demo.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ demo.cmo + +eyes.exe: eyes.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ eyes.cmo + +calc.exe: calc.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ calc.cmo + +clock.exe: clock.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) unix.cma \ + -o $@ clock.cmo + +tetris.exe: tetris.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ tetris.cmo + +lang.exe: lang.cmo + $(CAMLC) -custom $(LINKFLAGS) $(TKLINKOPT) \ + -o $@ lang.cmo + +clean : + rm -f *.cm? *.exe + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< diff --git a/otherlibs/labltk/examples_labltk/README b/otherlibs/labltk/examples_labltk/README new file mode 100644 index 0000000..d3c5f74 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/README @@ -0,0 +1,20 @@ +$Id: README,v 1.2 2002-04-26 12:15:57 furuse Exp $ + +Some examples for LablTk. +They are written in classic mode, except testris.ml which uses label +commutation. +You may either compile them here, or just run them as scripts with + labltk example.ml + +hello.ml A very simple example of CamlTk +hello.tcl The same programme in Tcl/Tk + +demo.ml A demonstration using many widget classes + +eyes.ml A "bind" test + +calc.ml A little calculator + +clock.ml An analog clock (uses unix.cma) + +tetris.ml You NEED a game also (uses -labels) diff --git a/otherlibs/labltk/examples_labltk/calc.ml b/otherlibs/labltk/examples_labltk/calc.ml new file mode 100644 index 0000000..de77724 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/calc.ml @@ -0,0 +1,129 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: calc.ml,v 1.3 2002-10-11 18:56:18 doligez Exp $ *) + +(* A simple calculator demonstrating OO programming with O'Labl + and LablTk. + + LablTk itself is not OO, but it is good to wrap complex + structures in objects. Even if the absence of initializers + makes things a little bit awkward. +*) + +open StdLabels +open Tk + +let mem_string ~elt:c s = + try + for i = 0 to String.length s -1 do + if s.[i] = c then raise Exit + done; false + with Exit -> true + +let ops = ['+',(+.); '-',(-.); '*',( *.); '/',(/.)] + +(* The abstract calculator class. + Does not use Tk (only Textvariable) *) + +class calc () = object (calc) + val variable = Textvariable.create () + val mutable x = 0.0 + val mutable op = None + val mutable displaying = true + + method set = Textvariable.set variable + method get = Textvariable.get variable + method insert s = calc#set (calc#get ^ s) + method get_float = float_of_string (calc#get) + + method command s = + if s <> "" then match s.[0] with + '0'..'9' -> + if displaying then (calc#set ""; displaying <- false); + calc#insert s + | '.' -> + if displaying then + (calc#set "0."; displaying <- false) + else + if not (mem_string ~elt:'.' calc#get) then calc#insert s + | '+'|'-'|'*'|'/' as c -> + displaying <- true; + begin match op with + None -> + x <- calc#get_float; + op <- Some (List.assoc c ops) + | Some f -> + x <- f x (calc#get_float); + op <- Some (List.assoc c ops); + calc#set (Printf.sprintf "%g" x) + end + | '='|'\n'|'\r' -> + displaying <- true; + begin match op with + None -> () + | Some f -> + x <- f x (calc#get_float); + op <- None; + calc#set (Printf.sprintf "%g" x) + end + | 'q' -> closeTk (); exit 0 + | _ -> () +end + +(* Buttons for the calculator *) + +let m = + [|["7";"8";"9";"+"]; + ["4";"5";"6";"-"]; + ["1";"2";"3";"*"]; + ["0";".";"=";"/"]|] + +(* The physical calculator. Inherits from the abstract one *) + +class calculator ~parent = object + inherit calc () as calc + + val label = Label.create ~anchor:`E ~relief:`Sunken ~padx:10 parent + val frame = Frame.create parent + + initializer + let buttons = + Array.map ~f: + (List.map ~f: + (fun text -> + Button.create ~text ~command:(fun () -> calc#command text) frame)) + m + in + Label.configure ~textvariable:variable label; + calc#set "0"; + bind ~events:[`KeyPress] ~fields:[`Char] + ~action:(fun ev -> calc#command ev.ev_Char) + parent; + for i = 0 to Array.length m - 1 do + Grid.configure ~row:i buttons.(i) + done; + pack ~side:`Top ~fill:`X [label]; + pack ~side:`Bottom ~fill:`Both ~expand:true [frame]; +end + +(* Finally start everything *) + +let top = openTk () + +let applet = new calculator ~parent:top + +let _ = mainLoop () diff --git a/otherlibs/labltk/examples_labltk/clock.ml b/otherlibs/labltk/examples_labltk/clock.ml new file mode 100644 index 0000000..1a8d62a --- /dev/null +++ b/otherlibs/labltk/examples_labltk/clock.ml @@ -0,0 +1,133 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: clock.ml,v 1.2 2002-04-26 12:15:58 furuse Exp $ *) + +(* Clock/V, a simple clock. + Reverts every time you push the right button. + Adapted from ASCII/V May 1997 + + Uses Tk and Unix, so you must link with + labltklink unix.cma clock.ml -o clock -cclib -lunix +*) + +open Tk + +(* pi is not a constant! *) +let pi = acos (-1.) + +(* The main class: + * create it with a parent: [new clock parent:top] + * initialize with [#init] +*) + +class clock ~parent = object (self) + + (* Instance variables *) + val canvas = Canvas.create ~width:100 ~height:100 parent + val mutable height = 100 + val mutable width = 100 + val mutable rflag = -1 + + (* Convert from -1.0 .. 1.0 to actual positions on the canvas *) + method x x0 = truncate (float width *. (x0 +. 1.) /. 2.) + method y y0 = truncate (float height *. (y0 +. 1.) /. 2.) + + initializer + (* Create the oval border *) + Canvas.create_oval canvas ~tags:["cadran"] + ~x1:1 ~y1:1 ~x2:(width - 2) ~y2:(height - 2) + ~width:3 ~outline:`Yellow ~fill:`White; + (* Draw the figures *) + self#draw_figures; + (* Create the arrows with dummy position *) + Canvas.create_line canvas + ~xys:[self#x 0., self#y 0.; self#x 0., self#y 0.] + ~tags:["hours"] ~fill:`Red; + Canvas.create_line canvas + ~xys:[self#x 0., self#y 0.; self#x 0., self#y 0.] + ~tags:["minutes"] ~fill:`Blue; + Canvas.create_line canvas + ~xys:[self#x 0., self#y 0.; self#x 0., self#y 0.] + ~tags:["seconds"] ~fill:`Black; + (* Setup a timer every second *) + let rec timer () = + self#draw_arrows (Unix.localtime (Unix.time ())); + Timer.add ~ms:1000 ~callback:timer; () + in timer (); + (* Redraw when configured (changes size) *) + bind canvas ~events:[`Configure] ~action: + begin fun _ -> + width <- Winfo.width canvas; + height <- Winfo.height canvas; + self#redraw + end; + (* Change direction with right button *) + bind canvas ~events:[`ButtonPressDetail 3] + ~action:(fun _ -> rflag <- -rflag; self#redraw); + (* Pack, expanding in both directions *) + pack ~fill:`Both ~expand:true [canvas] + + (* Redraw everything *) + method redraw = + Canvas.coords_set canvas (`Tag "cadran") + ~xys:[ 1, 1; width - 2, height - 2 ]; + self#draw_figures; + self#draw_arrows (Unix.localtime (Unix.time ())) + + (* Delete and redraw the figures *) + method draw_figures = + Canvas.delete canvas [`Tag "figures"]; + for i = 1 to 12 do + let angle = float (rflag * i - 3) *. pi /. 6. in + Canvas.create_text canvas + ~x:(self#x (0.8 *. cos angle)) ~y:(self#y (0.8 *. sin angle)) + ~tags:["figures"] + ~text:(string_of_int i) ~font:"variable" + ~anchor:`Center + done + + (* Resize and reposition the arrows *) + method draw_arrows tm = + Canvas.configure_line ~width:(min width height / 40) + canvas (`Tag "hours"); + let hangle = + float (rflag * (tm.Unix.tm_hour * 60 + tm.Unix.tm_min) - 180) + *. pi /. 360. in + Canvas.coords_set canvas (`Tag "hours") + ~xys:[ self#x 0., self#y 0.; + self#x (cos hangle /. 2.), self#y (sin hangle /. 2.) ]; + Canvas.configure_line ~width:(min width height / 50) + canvas (`Tag "minutes"); + let mangle = float (rflag * tm.Unix.tm_min - 15) *. pi /. 30. in + Canvas.coords_set canvas (`Tag "minutes") + ~xys:[ self#x 0., self#y 0.; + self#x (cos mangle /. 1.5), self#y (sin mangle /. 1.5) ]; + let sangle = float (rflag * tm.Unix.tm_sec - 15) *. pi /. 30. in + Canvas.coords_set canvas (`Tag "seconds") + ~xys:[ self#x 0., self#y 0.; + self#x (cos sangle /. 1.25), self#y (sin sangle /. 1.25) ] +end + +(* Initialize the Tcl interpreter *) +let top = openTk () + +(* Create a clock on the main window *) +let clock = + new clock ~parent:top + +(* Wait for events *) +let _ = mainLoop () diff --git a/otherlibs/labltk/examples_labltk/demo.ml b/otherlibs/labltk/examples_labltk/demo.ml new file mode 100644 index 0000000..a4c328e --- /dev/null +++ b/otherlibs/labltk/examples_labltk/demo.ml @@ -0,0 +1,167 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: demo.ml,v 1.2 2002-04-26 12:15:58 furuse Exp $ *) + +(* Some CamlTk4 Demonstration by JPF *) + +(* First, open these modules for convenience *) +open StdLabels +open Tk + +(* Dummy let *) +let _ = + +(* Initialize Tk *) +let top = openTk () in +(* Title setting *) +Wm.title_set top "LablTk demo"; + +(* Base frame *) +let base = Frame.create top in +pack [base]; + +(* Menu bar *) +let bar = Frame.create ~borderwidth:2 ~relief:`Raised base in +pack ~fill:`X [bar]; + + (* Menu and Menubutton *) + let meb = Menubutton.create ~text:"Menu" bar in + let men = Menu.create meb in + Menu.add_command ~label:"Quit" ~command:(fun () -> closeTk (); exit 0) men; + Menubutton.configure ~menu:men meb; + + (* Frames *) + let base2 = Frame.create base in + let left = Frame.create base2 in + let right = Frame.create base2 in + pack [base2]; + pack ~side:`Left [left; right]; + + (* Widgets on left and right *) + + (* Button *) + let but = Button.create ~text:"Welcome to LablTk" left in + + (* Canvas *) + let can = + Canvas.create ~width:100 ~height:100 ~borderwidth:1 ~relief:`Sunken left + in + let oval = Canvas.create_oval ~x1: 10 ~y1: 10 + ~x2: 90 ~y2: 90 + ~fill: `Red + can + in ignore oval; + + (* Check button *) + let che = Checkbutton.create ~text:"Check" left in + + (* Entry *) + let ent = Entry.create ~width:10 left in + + (* Label *) + let lab = Label.create ~text:"Welcome to LablTk" left in + + (* Listbox *) + let lis = Listbox.create left in + Listbox.insert lis ~index:`End ~texts:["This"; "is"; "Listbox"]; + + (* Message *) + let mes = Message.create + ~text: "Hello this is a message widget with very long text, but ..." + left in + + (* Radio buttons *) + let tv = Textvariable.create () in + Textvariable.set tv "One"; + let radf = Frame.create right in + let rads = List.map + ~f:(fun t -> Radiobutton.create ~text:t ~value:t ~variable:tv radf) + ["One"; "Two"; "Three"] in + + (* Scale *) + let sca = Scale.create ~label:"Scale" ~length:100 ~showvalue:true right in + + (* Text and scrollbar *) + let texf = Frame.create right in + + (* Text *) + let tex = Text.create ~width:20 ~height:8 texf in + Text.insert ~index:(`End,[]) ~text:"This is a text widget." tex; + + (* Scrollbar *) + let scr = Scrollbar.create texf in + + (* Text and Scrollbar widget link *) + let scroll_link sb tx = + Text.configure ~yscrollcommand:(Scrollbar.set sb) tx; + Scrollbar.configure ~command:(Text.yview tx) sb in + scroll_link scr tex; + + pack ~side:`Right ~fill:`Y [scr]; + pack ~side:`Left ~fill:`Both ~expand:true [tex]; + + (* Pack them *) + pack ~side:`Left [meb]; + pack [coe but; coe can; coe che; coe ent; coe lab; coe lis; coe mes]; + pack [coe radf; coe sca; coe texf]; + pack rads; + + (* Toplevel *) + let top2 = Toplevel.create top in + Wm.title_set top2 "LablTk demo control"; + let defcol = `Color "#dfdfdf" in + let selcol = `Color "#ffdfdf" in + let buttons = + List.map ~f:(fun (w, t, c, a) -> + let b = Button.create ~text:t ~command:c top2 in + bind ~events:[`Enter] ~action:(fun _ -> a selcol) b; + bind ~events:[`Leave] ~action:(fun _ -> a defcol) b; + b) + [coe bar, "Frame", (fun () -> ()), + (fun background -> Frame.configure ~background bar); + coe meb, "Menubutton", (fun () -> ()), + (fun background -> Menubutton.configure ~background meb); + coe but, "Button", (fun () -> ()), + (fun background -> Button.configure ~background but); + coe can, "Canvas", (fun () -> ()), + (fun background -> Canvas.configure ~background can); + coe che, "CheckButton", (fun () -> ()), + (fun background -> Checkbutton.configure ~background che); + coe ent, "Entry", (fun () -> ()), + (fun background -> Entry.configure ~background ent); + coe lab, "Label", (fun () -> ()), + (fun background -> Label.configure ~background lab); + coe lis, "Listbox", (fun () -> ()), + (fun background -> Listbox.configure ~background lis); + coe mes, "Message", (fun () -> ()), + (fun background -> Message.configure ~background mes); + coe radf, "Radiobox", (fun () -> ()), + (fun background -> + List.iter ~f:(fun b -> Radiobutton.configure ~background b) rads); + coe sca, "Scale", (fun () -> ()), + (fun background -> Scale.configure ~background sca); + coe tex, "Text", (fun () -> ()), + (fun background -> Text.configure ~background tex); + coe scr, "Scrollbar", (fun () -> ()), + (fun background -> Scrollbar.configure ~background scr) + ] + in + pack ~fill:`X buttons; + +(* Main Loop *) +Printexc.print mainLoop () + diff --git a/otherlibs/labltk/examples_labltk/eyes.ml b/otherlibs/labltk/examples_labltk/eyes.ml new file mode 100644 index 0000000..b7820c6 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/eyes.ml @@ -0,0 +1,65 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: eyes.ml,v 1.2 2002-04-26 12:15:58 furuse Exp $ *) + +open Tk + +let _ = + let top = openTk () in + let fw = Frame.create top in + pack [fw]; + let c = Canvas.create ~width: 200 ~height: 200 fw in + let create_eye cx cy wx wy ewx ewy bnd = + let o2 = Canvas.create_oval + ~x1:(cx - wx) ~y1:(cy - wy) + ~x2:(cx + wx) ~y2:(cy + wy) + ~outline: `Black ~width: 7 + ~fill: `White + c + and o = Canvas.create_oval + ~x1:(cx - ewx) ~y1:(cy - ewy) + ~x2:(cx + ewx) ~y2:(cy + ewy) + ~fill:`Black + c in + let curx = ref cx + and cury = ref cy in + bind ~events:[`Motion] ~extend:true ~fields:[`MouseX; `MouseY] + ~action:(fun e -> + let nx, ny = + let xdiff = e.ev_MouseX - cx + and ydiff = e.ev_MouseY - cy in + let diff = sqrt ((float xdiff /. (float wx *. bnd)) ** 2.0 +. + (float ydiff /. (float wy *. bnd)) ** 2.0) in + if diff > 1.0 then + truncate ((float xdiff) *. (1.0 /. diff)) + cx, + truncate ((float ydiff) *. (1.0 /. diff)) + cy + else + e.ev_MouseX, e.ev_MouseY + in + Canvas.move c o ~x: (nx - !curx) ~y: (ny - !cury); + curx := nx; + cury := ny) + c + in + create_eye 60 100 30 40 5 6 0.6; + create_eye 140 100 30 40 5 6 0.6; + pack [c] + +let _ = Printexc.print mainLoop () + + + diff --git a/otherlibs/labltk/examples_labltk/hello.ml b/otherlibs/labltk/examples_labltk/hello.ml new file mode 100644 index 0000000..056fc22 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/hello.ml @@ -0,0 +1,38 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: hello.ml,v 1.2 2002-04-26 12:15:58 furuse Exp $ *) + +(* LablTk4 Demonstration by JPF *) + +(* First, open this modules for convenience *) +open Tk + +(* initialization of Tk --- the result is a toplevel widget *) +let top = openTk () + +(* create a button on top *) +(* Button.create : use of create function defined in button.ml *) +(* But you shouldn't open Button module for other widget class modules use *) +let b = Button.create ~text: "Hello, LablTk!" top + +(* Lack of toplevel expressions in lsl, you must use dummy let exp. *) +let _ = pack [coe b] + +(* Last, you must call mainLoop *) +(* You can write just let _ = mainLoop () *) +(* But Printexc.print will help you *) +let _ = Printexc.print mainLoop () diff --git a/otherlibs/labltk/examples_labltk/hello.tcl b/otherlibs/labltk/examples_labltk/hello.tcl new file mode 100755 index 0000000..84ceccd --- /dev/null +++ b/otherlibs/labltk/examples_labltk/hello.tcl @@ -0,0 +1,5 @@ +#!/usr/bin/wish + +button .hello -text "Hello, TclTk!" + +pack .hello diff --git a/otherlibs/labltk/examples_labltk/lang.ml b/otherlibs/labltk/examples_labltk/lang.ml new file mode 100644 index 0000000..e92377e --- /dev/null +++ b/otherlibs/labltk/examples_labltk/lang.ml @@ -0,0 +1,75 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* language encoding using UTF-8 *) +open Tk + +let top = opentk () + +(* declare Tk that we use utf-8 to communicate *) +(* problem: Text display is highly dependent on your font installation + and configulation. The fonts with no-scale setting are selected + only if the point sizes are exactly same??? +*) +let _ = + Encoding.system_set "utf-8"; + let l = Label.create top ~text: "???" in + pack [l]; + let t = Text.create top in + pack [t]; + + let create_hello lang hello = + let b = Button.create t ~text: lang ~command: (fun () -> + Label.configure l ~text: hello) + in + Text.window_create t ~index: (`End,[]) ~window: b + in + List.iter (fun (lang, hello) -> create_hello lang hello) + ["Amharic(አማርኛ)", "ሠላም"; + "Arabic", "�����������"; + "Croatian (Hrvatski)", "Bog (Bok), Dobar dan"; + "Czech (česky)", "Dobrý den"; + "Danish (Dansk)", "Hej, Goddag"; + "English", "Hello"; + "Esperanto", "Saluton"; + "Estonian", "Tere, Tervist"; + "FORTRAN", "PROGRAM"; + "Finnish (Suomi)", "Hei"; + "French (Français)", "Bonjour, Salut"; + "German (Deutsch Nord)", "Guten Tag"; + "German (Deutsch Süd)", "Grüß Gott"; + "Greek (Ελληνικά)", "Γειά σας"; + "Hebrew", "שלום"; + "Italiano", "Ciao, Buon giorno"; + "Maltese", "Ciao"; + "Nederlands, Vlaams", "Hallo, Hoi, Goedendag"; + "Norwegian (Norsk)", "Hei, God dag"; + "Polish", "Cześć!"; + "Russian (Русский)", "Здравствуйте!"; + "Slovak", "Dobrý deň"; + "Spanish (Español)", "¡Hola!"; + "Swedish (Svenska)", "Hej, Goddag"; + "Thai (�������)", "�������, ������"; + "Tigrigna (ትግርኛ)", "ሰላማት"; + "Turkish (Türkçe)", "Merhaba"; + "Vietnamese (Tiếng Việt)", "Chào bạn"; + "Japanese (日本語)", "こんにちは"; + "Chinese (中文,普通话,汉语)", "你好"; + "Cantonese (粵語,廣東話)", "早晨, 你好"; + "Hangul (한글)", "안녕하세요, 안녕하십니까" ] +;; + +let _ = Printexc.print mainLoop () diff --git a/otherlibs/labltk/examples_labltk/taquin.ml b/otherlibs/labltk/examples_labltk/taquin.ml new file mode 100644 index 0000000..f750ef0 --- /dev/null +++ b/otherlibs/labltk/examples_labltk/taquin.ml @@ -0,0 +1,143 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: taquin.ml,v 1.2 2002-04-26 12:15:59 furuse Exp $ *) + +open Tk;; + +let découpe_image img nx ny = + let l = Imagephoto.width img + and h = Imagephoto.height img in + let tx = l / nx and ty = h / ny in + let pièces = ref [] in + for x = 0 to nx - 1 do + for y = 0 to ny - 1 do + let pièce = Imagephoto.create ~width:tx ~height:ty () in + Imagephoto.copy ~src:img + ~src_area:(x * tx, y * ty, (x + 1) * tx, (y + 1) * ty) pièce; + pièces := pièce :: !pièces + done + done; + (tx, ty, List.tl !pièces);; + +let remplir_taquin c nx ny tx ty pièces = + let trou_x = ref (nx - 1) + and trou_y = ref (ny - 1) in + let trou = + Canvas.create_rectangle + ~x1:(!trou_x * tx) ~y1:(!trou_y * ty) ~x2:tx ~y2:ty c in + let taquin = Array.make_matrix nx ny trou in + let p = ref pièces in + for x = 0 to nx - 1 do + for y = 0 to ny - 1 do + match !p with + | [] -> () + | pièce :: reste -> + taquin.(x).(y) <- + Canvas.create_image + ~x:(x * tx) ~y:(y * ty) + ~image:pièce ~anchor:`Nw ~tags:["pièce"] c; + p := reste + done + done; + let déplacer x y = + let pièce = taquin.(x).(y) in + Canvas.coords_set c pièce + ~xys:[!trou_x * tx, !trou_y * ty]; + Canvas.coords_set c trou + ~xys:[x * tx, y * ty; tx, ty]; + taquin.(!trou_x).(!trou_y) <- pièce; + taquin.(x).(y) <- trou; + trou_x := x; trou_y := y in + let jouer ei = + let x = ei.ev_MouseX / tx and y = ei.ev_MouseY / ty in + if x = !trou_x && (y = !trou_y - 1 || y = !trou_y + 1) + || y = !trou_y && (x = !trou_x - 1 || x = !trou_x + 1) + then déplacer x y in + Canvas.bind ~events:[`ButtonPress] + ~fields:[`MouseX; `MouseY] ~action:jouer c (`Tag "pièce");; + +let rec permutation = function + | [] -> [] + | l -> let n = Random.int (List.length l) in + let (élément, reste) = partage l n in + élément :: permutation reste + +and partage l n = + match l with + | [] -> failwith "partage" + | tête :: reste -> + if n = 0 then (tête, reste) else + let (élément, reste') = partage reste (n - 1) in + (élément, tête :: reste');; + +let create_filled_text parent lines = + let lnum = List.length lines + and lwidth = + List.fold_right + (fun line max -> + let l = String.length line in + if l > max then l else max) + lines 1 in + let txtw = Text.create ~width:lwidth ~height:lnum parent in + List.iter + (fun line -> + Text.insert ~index:(`End, []) ~text:line txtw; + Text.insert ~index:(`End, []) ~text:"\n" txtw) + lines; + txtw;; + +let give_help parent lines () = + let help_window = Toplevel.create parent in + Wm.title_set help_window "Help"; + + let help_frame = Frame.create help_window in + + let help_txtw = create_filled_text help_frame lines in + + let quit_help () = destroy help_window in + let ok_button = Button.create ~text:"Ok" ~command:quit_help help_frame in + + pack ~side:`Bottom [help_txtw]; + pack ~side:`Bottom [ok_button ]; + pack [help_frame];; + +let taquin nom_fichier nx ny = + let fp = openTk () in + Wm.title_set fp "Taquin"; + let img = Imagephoto.create ~file:nom_fichier () in + let c = + Canvas.create ~background:`Black + ~width:(Imagephoto.width img) + ~height:(Imagephoto.height img) fp in + let (tx, ty, pièces) = découpe_image img nx ny in + remplir_taquin c nx ny tx ty (permutation pièces); + pack [c]; + + let quit = Button.create ~text:"Quit" ~command:closeTk fp in + let help_lines = + ["Pour jouer, cliquer sur une des pièces"; + "entourant le trou"; + ""; + "To play, click on a part around the hole"] in + let help = + Button.create ~text:"Help" ~command:(give_help fp help_lines) fp in + pack ~side:`Left ~fill:`X [quit] ; + pack ~side:`Left ~fill:`X [help] ; + mainLoop ();; + +if !Sys.interactive then () else +begin taquin "Lambda2.back.gif" 4 4; exit 0 end;; diff --git a/otherlibs/labltk/examples_labltk/tetris.ml b/otherlibs/labltk/examples_labltk/tetris.ml new file mode 100644 index 0000000..961ed9b --- /dev/null +++ b/otherlibs/labltk/examples_labltk/tetris.ml @@ -0,0 +1,710 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tetris.ml,v 1.4 2004-06-12 03:20:00 garrigue Exp $ *) + +(* A Tetris game for LablTk *) +(* written by Jun P. Furuse *) + +open StdLabels +open Tk + +exception Done + +type falling_block = { + mutable pattern: int array list; + mutable bcolor: int; + mutable x: int; + mutable y: int; + mutable d: int; + mutable alive: bool + } + +let stop_a_bit = 300 + +let field_width = 10 +let field_height = 20 + +let colors = [| + `Color "red"; + `Color "yellow"; + + `Color "blue"; + `Color "orange"; + + `Color "magenta"; + `Color "green"; + + `Color "cyan" +|] + +(* Put here your favorite image files *) +let backgrounds = [ + "Lambda2.back.gif" +] + +(* blocks *) +let block_size = 16 +let cell_border = 2 + +let blocks = [ + [ [|"0000"; + "0000"; + "1111"; + "0000" |]; + + [|"0010"; + "0010"; + "0010"; + "0010" |]; + + [|"0000"; + "0000"; + "1111"; + "0000" |]; + + [|"0010"; + "0010"; + "0010"; + "0010" |] ]; + + [ [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |]; + + [|"0000"; + "0110"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "0111"; + "0100"; + "0000" |]; + + [|"0000"; + "0110"; + "0010"; + "0010" |]; + + [|"0000"; + "0010"; + "1110"; + "0000" |]; + + [|"0100"; + "0100"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "0100"; + "0111"; + "0000" |]; + + [|"0000"; + "0110"; + "0100"; + "0100" |]; + + [|"0000"; + "1110"; + "0010"; + "0000" |]; + + [|"0010"; + "0010"; + "0110"; + "0000" |] ]; + + [ [|"0000"; + "1100"; + "0110"; + "0000" |]; + + [|"0010"; + "0110"; + "0100"; + "0000" |]; + + [|"0000"; + "1100"; + "0110"; + "0000" |]; + + [|"0010"; + "0110"; + "0100"; + "0000" |] ]; + + [ [|"0000"; + "0011"; + "0110"; + "0000" |]; + + [|"0100"; + "0110"; + "0010"; + "0000" |]; + + [|"0000"; + "0011"; + "0110"; + "0000" |]; + + [|"0000"; + "0100"; + "0110"; + "0010" |] ]; + + [ [|"0000"; + "0000"; + "1110"; + "0100" |]; + + [|"0000"; + "0100"; + "1100"; + "0100" |]; + + [|"0000"; + "0100"; + "1110"; + "0000" |]; + + [|"0000"; + "0100"; + "0110"; + "0100" |] ] + +] + +let line_empty = int_of_string "0b1110000000000111" +let line_full = int_of_string "0b1111111111111111" + +let decode_block dvec = + let btoi d = int_of_string ("0b"^d) in + Array.map ~f:btoi dvec + +class cell t1 t2 t3 ~canvas ~x ~y = object + val mutable color = 0 + method get = color + method set ~color:col = + if color = col then () else + if color <> 0 && col = 0 then begin + Canvas.move canvas t1 + ~x:(- block_size * (x + 1) -10 - cell_border * 2) + ~y:(- block_size * (y + 1) -10 - cell_border * 2); + Canvas.move canvas t2 + ~x:(- block_size * (x + 1) -10 - cell_border * 2) + ~y:(- block_size * (y + 1) -10 - cell_border * 2); + Canvas.move canvas t3 + ~x:(- block_size * (x + 1) -10 - cell_border * 2) + ~y:(- block_size * (y + 1) -10 - cell_border * 2) + end else begin + Canvas.configure_rectangle canvas t2 + ~fill: colors.(col - 1) + ~outline: colors.(col - 1); + Canvas.configure_rectangle canvas t1 + ~fill: `Black + ~outline: `Black; + Canvas.configure_rectangle canvas t3 + ~fill: (`Color "light gray") + ~outline: (`Color "light gray"); + if color = 0 && col <> 0 then begin + Canvas.move canvas t1 + ~x: (block_size * (x+1)+10+ cell_border*2) + ~y: (block_size * (y+1)+10+ cell_border*2); + Canvas.move canvas t2 + ~x: (block_size * (x+1)+10+ cell_border*2) + ~y: (block_size * (y+1)+10+ cell_border*2); + Canvas.move canvas t3 + ~x: (block_size * (x+1)+10+ cell_border*2) + ~y: (block_size * (y+1)+10+ cell_border*2) + end + end; + color <- col +end + +let cell_get (c, cf) x y = cf.(y).(x) #get + +let cell_set (c, cf) ~x ~y ~color = + if x >= 0 && y >= 0 && Array.length cf > y && Array.length cf.(y) > x then + let cur = cf.(y).(x) in + if cur#get = color then () else cur#set ~color + +let create_base_matrix ~cols ~rows = + let m = Array.create_matrix ~dimx:rows ~dimy:cols (0,0) in + for x = 0 to cols - 1 do for y = 0 to rows - 1 do + m.(y).(x) <- (x,y) + done done; + m + +let init fw = + let scorev = Textvariable.create () + and linev = Textvariable.create () + and levv = Textvariable.create () + and namev = Textvariable.create () + in + let f = Frame.create fw ~borderwidth: 2 in + let c = Canvas.create f ~width: (block_size * 10) + ~height: (block_size * 20) + ~borderwidth: cell_border + ~relief: `Sunken + ~background: `Black + and r = Frame.create f + and r' = Frame.create f in + + let nl = Label.create r ~text: "Next" ~font: "variable" in + let nc = Canvas.create r ~width: (block_size * 4) + ~height: (block_size * 4) + ~borderwidth: cell_border + ~relief: `Sunken + ~background: `Black in + let scl = Label.create r ~text: "Score" ~font: "variable" in + let sc = Label.create r ~textvariable: scorev ~font: "variable" in + let lnl = Label.create r ~text: "Lines" ~font: "variable" in + let ln = Label.create r ~textvariable: linev ~font: "variable" in + let levl = Label.create r ~text: "Level" ~font: "variable" in + let lev = Label.create r ~textvariable: levv ~font: "variable" in + let newg = Button.create r ~text: "New Game" ~font: "variable" in + + pack [f]; + pack [coe c; coe r; coe r'] ~side: `Left ~fill: `Y; + pack [coe nl; coe nc] ~side: `Top; + pack [coe scl; coe sc; coe lnl; coe ln; coe levl; coe lev; coe newg] + ~side: `Top; + + let cells_src = create_base_matrix ~cols:field_width ~rows:field_height in + let cells = + Array.map cells_src ~f: + (Array.map ~f: + begin fun (x,y) -> + let t1 = + Canvas.create_rectangle c + ~x1:(-block_size - 8) ~y1:(-block_size - 8) + ~x2:(-9) ~y2:(-9) + and t2 = + Canvas.create_rectangle c + ~x1:(-block_size - 10) ~y1:(-block_size - 10) + ~x2:(-11) ~y2:(-11) + and t3 = + Canvas.create_rectangle c + ~x1:(-block_size - 12) ~y1:(-block_size - 12) + ~x2:(-13) ~y2:(-13) + in + Canvas.raise c t1; + Canvas.raise c t2; + Canvas.lower c t3; + new cell ~canvas:c ~x ~y t1 t2 t3 + end) + in + let nexts_src = create_base_matrix ~cols:4 ~rows:4 in + let nexts = + Array.map nexts_src ~f: + (Array.map ~f: + begin fun (x,y) -> + let t1 = + Canvas.create_rectangle nc + ~x1:(-block_size - 8) ~y1:(-block_size - 8) + ~x2:(-9) ~y2:(-9) + and t2 = + Canvas.create_rectangle nc + ~x1:(-block_size - 10) ~y1:(-block_size - 10) + ~x2:(-11) ~y2:(-11) + and t3 = + Canvas.create_rectangle nc + ~x1:(-block_size - 12) ~y1:(-block_size - 12) + ~x2:(-13) ~y2:(-13) + in + Canvas.raise nc t1; + Canvas.raise nc t2; + Canvas.lower nc t3; + new cell ~canvas:nc ~x ~y t1 t2 t3 + end) + in + let game_over () = () + in + (* What a mess ! *) + [ coe f; coe c; coe r; coe nl; coe nc; coe scl; coe sc; coe levl; coe lev; + coe lnl; coe ln ], + newg, (c, cells), (nc, nexts), scorev, linev, levv, game_over + + +let draw_block field ~color ~block ~x ~y = + for iy = 0 to 3 do + let base = ref 1 in + let xd = block.(iy) in + for ix = 0 to 3 do + if xd land !base <> 0 then + cell_set field ~x:(ix + x) ~y:(iy + y) ~color; + base := !base lsl 1 + done + done + +let timer_ref = (ref None : Timer.t option ref) +(* I know, this should be timer ref, but I'm not sure what should be + the initial value ... *) + +let remove_timer () = + match !timer_ref with + None -> () + | Some t -> Timer.remove t (* ; prerr_endline "removed!" *) + +let do_after ~ms ~callback = + timer_ref := Some (Timer.add ~ms ~callback) + +let copy_block c = + { pattern= !c.pattern; + bcolor= !c.bcolor; + x= !c.x; + y= !c.y; + d= !c.d; + alive= !c.alive } + +let _ = + let top = openTk () in + let lb = Label.create top + and fw = Frame.create top + in + let set_message s = Label.configure lb ~text:s in + pack [coe lb; coe fw] ~side: `Top; + let score = ref 0 in + let line = ref 0 in + let level = ref 0 in + let time = ref 1000 in + let blocks = List.map ~f:(List.map ~f:decode_block) blocks in + let field = Array.create 26 0 in + let widgets, button, cell_field, next_field, scorev, linev, levv, game_over + = init fw in + let canvas = fst cell_field in + + let init_field () = + for i = 0 to 25 do + field.(i) <- line_empty + done; + field.(23) <- line_full; + for i = 0 to 19 do + for j = 0 to 9 do + cell_set cell_field ~x:j ~y:i ~color:0 + done + done; + for i = 0 to 3 do + for j = 0 to 3 do + cell_set next_field ~x:j ~y:i ~color:0 + done + done + in + + let draw_falling_block fb = + draw_block cell_field ~color: fb.bcolor + ~block: (List.nth fb.pattern fb.d) + ~x: (fb.x - 3) + ~y: (fb.y - 3) + + and erase_falling_block fb = + draw_block cell_field ~color: 0 + ~block: (List.nth fb.pattern fb.d) + ~x: (fb.x - 3) + ~y: (fb.y - 3) + in + + let stone fb = + for i=0 to 3 do + let cur = field.(i + fb.y) in + field.(i + fb.y) <- + cur lor ((List.nth fb.pattern fb.d).(i) lsl fb.x) + done; + for i=0 to 2 do + field.(i) <- line_empty + done + + and clear fb = + let l = ref 0 in + for i = 0 to 3 do + if i + fb.y >= 3 && i + fb.y <= 22 then + if field.(i + fb.y) = line_full then + begin + incr l; + field.(i + fb.y) <- line_empty; + for j = 0 to 9 do + cell_set cell_field ~x:j ~y:(i + fb.y - 3) ~color:0 + done + end + done; + !l + + and fall_lines () = + let eye = ref 22 (* bottom *) + and cur = ref 22 (* bottom *) + in + try + while !eye >= 3 do + while field.(!eye) = line_empty do + decr eye; + if !eye = 2 then raise Done + done; + field.(!cur) <- field.(!eye); + for j = 0 to 9 do + cell_set cell_field ~x:j ~y:(!cur-3) + ~color:(cell_get cell_field j (!eye-3)) + done; + decr eye; + decr cur + done + with Done -> (); + for i = 3 to !cur do + field.(i) <- line_empty; + for j = 0 to 9 do + cell_set cell_field ~x:j ~y:(i-3) ~color:0 + done + done + in + + let next = ref 42 (* THE ANSWER *) + and current = + ref { pattern= [[|0;0;0;0|]]; bcolor=0; x=0; y=0; d=0; alive= false} + in + + let draw_next () = + draw_block next_field ~color: (!next+1) + ~block: (List.hd (List.nth blocks !next)) + ~x: 0 ~y: 0 + + and erase_next () = + draw_block next_field ~color: 0 + ~block: (List.hd (List.nth blocks !next)) + ~x: 0 ~y: 0 + in + + let set_nextblock () = + current := + { pattern= (List.nth blocks !next); + bcolor= !next+1; + x=6; y= 1; d= 0; alive= true}; + erase_next (); + next := Random.int 7; + draw_next () + in + + let death_check fb = + try + for i=0 to 3 do + let cur = field.(i + fb.y) in + if cur land ((List.nth fb.pattern fb.d).(i) lsl fb.x) <> 0 + then raise Done + done; + false + with + Done -> true + in + + let try_to_move m = + if !current.alive then + let sub m = + if death_check m then false + else + begin + erase_falling_block !current; + draw_falling_block m; + current := m; + true + end + in + if sub m then true + else + begin + m.x <- m.x + 1; + if sub m then true + else + begin + m.x <- m.x - 2; + sub m + end + end + else false + in + + let image_load = + let i = Canvas.create_image canvas + ~x: (block_size * 5 + block_size / 2) + ~y: (block_size * 10 + block_size / 2) + ~anchor: `Center in + Canvas.lower canvas i; + let img = Imagephoto.create () in + fun file -> + try + Imagephoto.configure img ~file: file; + Canvas.configure_image canvas i ~image: img + with + _ -> + begin + Printf.eprintf "%s : No such image...\n" file; + flush stderr + end + in + + let add_score l = + let pline = !line in + if l <> 0 then + begin + line := !line + l; + score := !score + l * l; + set_message (Printf.sprintf "%d pts" (1 lsl ((l - 1) * 2))) + end; + Textvariable.set linev (string_of_int !line); + Textvariable.set scorev (string_of_int !score); + + if !line /10 <> pline /10 then + (* update the background every 10 lines. *) + begin + let num_image = List.length backgrounds - 1 in + let n = !line/10 in + let n = if n > num_image then num_image else n in + let file = List.nth backgrounds n in + image_load file; + incr level; + Textvariable.set levv (string_of_int !level) + end + in + + let rec newblock () = + set_message "TETRIS"; + set_nextblock (); + draw_falling_block !current; + if death_check !current then + begin + !current.alive <- false; + set_message "GAME OVER"; + game_over () + end + else + begin + time := 1100 - (!level / 4 * 300) - ((!level mod 4) * 200); + if !time < 60 - !level * 3 then time := 60 - !level * 3; + do_after ~ms:stop_a_bit ~callback:loop + end + + and loop () = + let m = copy_block current in + m.y <- m.y + 1; + if death_check m then + begin + !current.alive <- false; + stone !current; + do_after ~ms:stop_a_bit ~callback: + begin fun () -> + let l = clear !current in + if l > 0 then + do_after ~ms:stop_a_bit ~callback: + begin fun () -> + fall_lines (); + add_score l; + do_after ~ms:stop_a_bit ~callback:newblock + end + else + newblock () + end + end + else + begin + erase_falling_block !current; + draw_falling_block m; + current := m; + do_after ~ms:!time ~callback:loop + end + in + + let bind_game w = + bind w ~events:[`KeyPress] ~fields:[`KeySymString] ~action: + begin fun e -> + match e.ev_KeySymString with + | "h"|"Left" -> + let m = copy_block current in + m.x <- m.x - 1; + ignore (try_to_move m) + | "j"|"Up" -> + let m = copy_block current in + m.d <- m.d + 1; + if m.d = List.length m.pattern then m.d <- 0; + ignore (try_to_move m) + | "k"|"Down" -> + let m = copy_block current in + m.d <- m.d - 1; + if m.d < 0 then m.d <- List.length m.pattern - 1; + ignore (try_to_move m) + | "l"|"Right" -> + let m = copy_block current in + m.x <- m.x + 1; + ignore (try_to_move m) + | "m" -> + remove_timer (); + loop () + | "space" -> + if !current.alive then + begin + let m = copy_block current + and n = copy_block current in + while + m.y <- m.y + 1; + if death_check m then false + else begin n.y <- m.y; true end + do () done; + erase_falling_block !current; + draw_falling_block n; + current := n; + remove_timer (); + loop () + end + | _ -> () + end + in + + let game_init () = + (* Game Initialization *) + set_message "Initializing ..."; + remove_timer (); + image_load (List.hd backgrounds); + time := 1000; + score := 0; + line := 0; + level := 1; + add_score 0; + init_field (); + next := Random.int 7; + set_message "Welcome to TETRIS"; + set_nextblock (); + draw_falling_block !current; + do_after ~ms:!time ~callback:loop + in + (* As an applet, it was required... *) + (* List.iter f: bind_game widgets; *) + bind_game top; + Button.configure button ~command: game_init; + game_init () + +let _ = Printexc.print mainLoop () diff --git a/otherlibs/labltk/frx/.depend b/otherlibs/labltk/frx/.depend new file mode 100644 index 0000000..d815ab0 --- /dev/null +++ b/otherlibs/labltk/frx/.depend @@ -0,0 +1,38 @@ +frx_after.cmo: frx_after.cmi +frx_after.cmx: frx_after.cmi +frx_color.cmo: frx_color.cmi +frx_color.cmx: frx_color.cmi +frx_ctext.cmo: frx_fit.cmi frx_text.cmi frx_ctext.cmi +frx_ctext.cmx: frx_fit.cmx frx_text.cmx frx_ctext.cmi +frx_dialog.cmo: frx_dialog.cmi +frx_dialog.cmx: frx_dialog.cmi +frx_entry.cmo: frx_entry.cmi +frx_entry.cmx: frx_entry.cmi +frx_fillbox.cmo: frx_fillbox.cmi +frx_fillbox.cmx: frx_fillbox.cmi +frx_fit.cmo: frx_after.cmi frx_fit.cmi +frx_fit.cmx: frx_after.cmx frx_fit.cmi +frx_focus.cmo: frx_focus.cmi +frx_focus.cmx: frx_focus.cmi +frx_font.cmo: frx_misc.cmi frx_font.cmi +frx_font.cmx: frx_misc.cmx frx_font.cmi +frx_lbutton.cmo: frx_lbutton.cmi +frx_lbutton.cmx: frx_lbutton.cmi +frx_listbox.cmo: frx_listbox.cmi +frx_listbox.cmx: frx_listbox.cmi +frx_mem.cmo: frx_mem.cmi +frx_mem.cmx: frx_mem.cmi +frx_misc.cmo: frx_misc.cmi +frx_misc.cmx: frx_misc.cmi +frx_req.cmo: frx_entry.cmi frx_listbox.cmi frx_widget.cmi frx_req.cmi +frx_req.cmx: frx_entry.cmx frx_listbox.cmx frx_widget.cmx frx_req.cmi +frx_rpc.cmo: frx_rpc.cmi +frx_rpc.cmx: frx_rpc.cmi +frx_selection.cmo: frx_selection.cmi +frx_selection.cmx: frx_selection.cmi +frx_synth.cmo: frx_synth.cmi +frx_synth.cmx: frx_synth.cmi +frx_text.cmo: frx_misc.cmi frx_text.cmi +frx_text.cmx: frx_misc.cmx frx_text.cmi +frx_widget.cmo: frx_widget.cmi +frx_widget.cmx: frx_widget.cmi diff --git a/otherlibs/labltk/frx/Makefile b/otherlibs/labltk/frx/Makefile new file mode 100644 index 0000000..0f9c9e3 --- /dev/null +++ b/otherlibs/labltk/frx/Makefile @@ -0,0 +1,51 @@ +include ../support/Makefile.common + +COMPFLAGS=-I ../camltk -I ../support + +OBJS= frx_misc.cmo frx_widget.cmo frx_font.cmo frx_entry.cmo frx_text.cmo \ + frx_listbox.cmo frx_req.cmo frx_fillbox.cmo frx_focus.cmo \ + frx_dialog.cmo frx_mem.cmo frx_rpc.cmo frx_synth.cmo frx_selection.cmo \ + frx_after.cmo frx_fit.cmo frx_ctext.cmo frx_color.cmo + +OBJSX = $(OBJS:.cmo=.cmx) + +all: frxlib.cma + +opt: frxlib.cmxa + +frxlib.cma: $(OBJS) + $(CAMLLIBR) -o frxlib.cma $(OBJS) + +frxlib.cmxa: $(OBJSX) + $(CAMLOPTLIBR) -o frxlib.cmxa $(OBJSX) + +install: + cp *.cmi *.mli frxlib.cma $(INSTALLDIR) + +installopt: + cp frxlib.cmxa frxlib.$(A) $(INSTALLDIR) + +clean: + rm -f *.cm* *.$(O) *.$(A) + +$(OBJS) $(OBJS:.cmo=.cmi): ../lib/$(LIBNAME).cma + +$(OBJSX): ../lib/$(LIBNAME).cmxa + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo .cmx + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + + +depend: + $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/otherlibs/labltk/frx/Makefile.nt b/otherlibs/labltk/frx/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/frx/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/frx/README b/otherlibs/labltk/frx/README new file mode 100644 index 0000000..b86f8dc --- /dev/null +++ b/otherlibs/labltk/frx/README @@ -0,0 +1,2 @@ +This is Francois Rouaix's widget set library, Frx. +It uses CamlTk API. \ No newline at end of file diff --git a/otherlibs/labltk/frx/frx_after.ml b/otherlibs/labltk/frx/frx_after.ml new file mode 100644 index 0000000..7fe6a4f --- /dev/null +++ b/otherlibs/labltk/frx/frx_after.ml @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Protocol +let idle f = + let id = new_function_id () in + let wrapped _ = + clear_callback id; (* do it first in case f raises exception *) + f() in + Hashtbl.add callback_naming_table id wrapped; + tkCommand [| TkToken "after"; TkToken "idle"; + TkToken ("camlcb "^ string_of_cbid id) |] diff --git a/otherlibs/labltk/frx/frx_after.mli b/otherlibs/labltk/frx/frx_after.mli new file mode 100644 index 0000000..73c07f7 --- /dev/null +++ b/otherlibs/labltk/frx/frx_after.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val idle : (unit -> unit) -> unit + (* [idle f] is equivalent to Tk "after idle {camlcb f}" *) diff --git a/otherlibs/labltk/frx/frx_color.ml b/otherlibs/labltk/frx/frx_color.ml new file mode 100644 index 0000000..4df3eb6 --- /dev/null +++ b/otherlibs/labltk/frx/frx_color.ml @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Protocol + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +(* should we keep a negative cache ? *) +let available_colors = ref (StringSet.empty) + +let check s = + if StringSet.mem s !available_colors then true + else begin + try + let f = Frame.create_named Widget.default_toplevel "frxcolorcheck" + [Background (NamedColor s)] in + available_colors := StringSet.add s !available_colors; + destroy f; + true + with + TkError _ -> false + end diff --git a/otherlibs/labltk/frx/frx_color.mli b/otherlibs/labltk/frx/frx_color.mli new file mode 100644 index 0000000..513cb08 --- /dev/null +++ b/otherlibs/labltk/frx/frx_color.mli @@ -0,0 +1,16 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val check : string -> bool diff --git a/otherlibs/labltk/frx/frx_ctext.ml b/otherlibs/labltk/frx/frx_ctext.ml new file mode 100644 index 0000000..0d4fd83 --- /dev/null +++ b/otherlibs/labltk/frx/frx_ctext.ml @@ -0,0 +1,66 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* A trick by Steve Ball to do pixel scrolling on text widgets *) +(* USES frx_fit *) +open Camltk + +let create top opts navigation = + let f = Frame.create top [BorderWidth (Pixels 2); Relief Raised] in + let lf = Frame.create f [] in + let rf = Frame.create f [] in + let c = Canvas.create lf [BorderWidth (Pixels 0)] + and xscroll = Scrollbar.create lf [Orient Horizontal] + and yscroll = Scrollbar.create rf [Orient Vertical] + and secret = Frame.create_named rf "secret" [] + in + let t = Text.create c (BorderWidth(Pixels 0) :: opts) in + if navigation then Frx_text.navigation_keys t; + + (* Make the text widget an embedded canvas object *) + ignore + (Canvas.create_window c (Pixels 0) (Pixels 0) + [Anchor NW; Window t; Tags [Tag "main"]]); + Canvas.focus c (Tag "main"); + (* + Canvas.configure c [Width (Pixels (Winfo.reqwidth t)); + Height(Pixels (Winfo.reqheight t))]; + *) + Canvas.configure c [YScrollCommand (Scrollbar.set yscroll)]; + (* The horizontal scrollbar is directly attached to the + * text widget, because h scrolling works properly *) + Scrollbar.configure xscroll [ScrollCommand (Text.xview t)]; + (* But vertical scroll is attached to the canvas *) + Scrollbar.configure yscroll [ScrollCommand (Canvas.yview c)]; + let scroll, check = Frx_fit.vert t in + Text.configure t [ + XScrollCommand (Scrollbar.set xscroll); + YScrollCommand (fun first last -> + scroll first last; + let x,y,w,h = Canvas.bbox c [Tag "main"] in + Canvas.configure c + [ScrollRegion (Pixels x, Pixels y, Pixels w, Pixels h)]) + ]; + + bind c [[],Configure] (BindSet ([Ev_Width], (fun ei -> + Canvas.configure_window c (Tag "main") [Width (Pixels ei.ev_Width)]))); + + pack [rf] [Side Side_Right; Fill Fill_Y]; + pack [lf] [Side Side_Left; Fill Fill_Both; Expand true]; + pack [secret] [Side Side_Bottom]; + pack [yscroll] [Side Side_Top; Fill Fill_Y; Expand true]; + pack [xscroll] [Side Side_Bottom; Fill Fill_X]; + pack [c] [Side Side_Left; Fill Fill_Both; Expand true]; + f, t diff --git a/otherlibs/labltk/frx/frx_ctext.mli b/otherlibs/labltk/frx/frx_ctext.mli new file mode 100644 index 0000000..157c0ca --- /dev/null +++ b/otherlibs/labltk/frx/frx_ctext.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +val create : + Widget.widget -> Camltk.options list -> bool -> Widget.widget * Widget.widget + (* [create parent opts nav_keys] creates a text widget + with "pixel scrolling". Based on a trick learned from Steve Ball. + Returns (frame widget, text widget). + *) + + diff --git a/otherlibs/labltk/frx/frx_dialog.ml b/otherlibs/labltk/frx/frx_dialog.ml new file mode 100644 index 0000000..0b65b41 --- /dev/null +++ b/otherlibs/labltk/frx/frx_dialog.ml @@ -0,0 +1,115 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Protocol + +let rec mapi f n l = + match l with + [] -> [] + | x::l -> let v = f n x in v::(mapi f (succ n) l) + +(* Same as tk_dialog, but not sharing the tkwait variable *) +(* w IS the parent widget *) +let f w name title mesg bitmap def buttons = + let t = Toplevel.create_named w name [Class "Dialog"] in + Wm.title_set t title; + Wm.iconname_set t "Dialog"; + Wm.protocol_set t "WM_DELETE_WINDOW" (function () -> ()); + (* Wm.transient_set t (Winfo.toplevel w); *) + let ftop = + Frame.create_named t "top" [Relief Raised; BorderWidth (Pixels 1)] + and fbot = + Frame.create_named t "bot" [Relief Raised; BorderWidth (Pixels 1)] + in + pack [ftop][Side Side_Top; Fill Fill_Both]; + pack [fbot][Side Side_Bottom; Fill Fill_Both]; + + let l = + Label.create_named ftop "msg" + [Justify Justify_Left; Text mesg; WrapLength (Pixels 600)] in + pack [l][Side Side_Right; Expand true; Fill Fill_Both; + PadX (Millimeters 3.0); PadY (Millimeters 3.0)]; + begin match bitmap with + Predefined "" -> () + | _ -> + let b = + Label.create_named ftop "bitmap" [Bitmap bitmap] in + pack [b][Side Side_Left; PadX (Millimeters 3.0); PadY (Millimeters 3.0)] + end; + + let waitv = Textvariable.create_temporary t in + + let buttons = + mapi (fun i bname -> + let b = Button.create t + [Text bname; + Command (fun () -> Textvariable.set waitv (string_of_int i))] in + if i = def then begin + let f = Frame.create_named fbot "default" + [Relief Sunken; BorderWidth (Pixels 1)] in + raise_window_above b f; + pack [f][Side Side_Left; Expand true; + PadX (Millimeters 3.0); PadY (Millimeters 2.0)]; + pack [b][In f; PadX (Millimeters 2.0); PadY (Millimeters 2.0)]; + bind t [[], KeyPressDetail "Return"] + (BindSet ([], (fun _ -> Button.flash b; Button.invoke b))) + end + else + pack [b][In fbot; Side Side_Left; Expand true; + PadX (Millimeters 3.0); PadY (Millimeters 2.0)]; + b + ) + 0 buttons in + + Wm.withdraw t; + update_idletasks(); + let x = (Winfo.screenwidth t)/2 - (Winfo.reqwidth t)/2 - + (Winfo.vrootx (Winfo.parent t)) + and y = (Winfo.screenheight t)/2 - (Winfo.reqheight t)/2 - + (Winfo.vrooty (Winfo.parent t)) in + Wm.geometry_set t (Printf.sprintf "+%d+%d" x y); + Wm.deiconify t; + + let oldfocus = try Some (Focus.get()) with _ -> None + and oldgrab = Grab.current ~displayof: t () + and grabstatus = ref None in + begin match oldgrab with + [] -> () + | x::l -> grabstatus := Some(Grab.status x) + end; + + (* avoid errors here because it makes the entire app useless *) + (try Grab.set t with TkError _ -> ()); + Tkwait.visibility t; + Focus.set (if def >= 0 then List.nth buttons def else t); + + Tkwait.variable waitv; + begin match oldfocus with + None -> () + | Some w -> try Focus.set w with _ -> () + end; + destroy t; + begin match oldgrab with + [] -> () + | x::l -> + try + match !grabstatus with + Some(GrabGlobal) -> Grab.set_global x + | _ -> Grab.set x + with TkError _ -> () + end; + + int_of_string (Textvariable.get waitv) diff --git a/otherlibs/labltk/frx/frx_dialog.mli b/otherlibs/labltk/frx/frx_dialog.mli new file mode 100644 index 0000000..2124150 --- /dev/null +++ b/otherlibs/labltk/frx/frx_dialog.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +val f : + Widget.widget -> + string -> string -> string -> Camltk.bitmap -> int -> string list -> int + (* same as Dialog.create_named, but with a local variable for + synchronisation. Makes it possible to have several dialogs + simultaneously *) diff --git a/otherlibs/labltk/frx/frx_entry.ml b/otherlibs/labltk/frx/frx_entry.ml new file mode 100644 index 0000000..96adfe4 --- /dev/null +++ b/otherlibs/labltk/frx/frx_entry.ml @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let version = "$Id: frx_entry.ml,v 1.2 2002-04-26 12:16:02 furuse Exp $" + +(* + * Tk 4.0 has emacs bindings for entry widgets + *) + +let new_label_entry parent txt action = + let f = Frame.create parent [] in + let m = Label.create f [Text txt] + and e = Entry.create f [Relief Sunken; TextWidth 0] in + Camltk.bind e [[], KeyPressDetail "Return"] + (BindSet ([], fun _ -> action(Entry.get e))); + pack [m][Side Side_Left]; + pack [e][Side Side_Right; Fill Fill_X; Expand true]; + f,e + +let new_labelm_entry parent txt memo = + let f = Frame.create parent [] in + let m = Label.create f [Text txt] + and e = Entry.create f [Relief Sunken; TextVariable memo; TextWidth 0] in + pack [m][Side Side_Left]; + pack [e][Side Side_Right; Fill Fill_X; Expand true]; + f,e + + diff --git a/otherlibs/labltk/frx/frx_entry.mli b/otherlibs/labltk/frx/frx_entry.mli new file mode 100644 index 0000000..2f34a7e --- /dev/null +++ b/otherlibs/labltk/frx/frx_entry.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +val new_label_entry : + Widget.widget -> + string -> (string -> unit) -> Widget.widget * Widget.widget + (* [new_label_entry parent label action] + creates a "labelled" entry widget where [action] will be invoked + when the user types Return in the widget. + Returns (frame widget, entry widget) + *) +val new_labelm_entry : + Widget.widget -> + string -> Textvariable.textVariable -> Widget.widget * Widget.widget + (* [new_labelm_entry parent label variable] + creates a "labelled" entry widget whose contents is [variable]. + Returns (frame widget, entry widget) + *) diff --git a/otherlibs/labltk/frx/frx_fileinput.ml b/otherlibs/labltk/frx/frx_fileinput.ml new file mode 100644 index 0000000..1be4012 --- /dev/null +++ b/otherlibs/labltk/frx/frx_fileinput.ml @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let version = "$Id: frx_fileinput.ml,v 1.2 2002-04-26 12:16:03 furuse Exp $" + +(* + * Simple spooling for fileinput callbacks + *) + +let waiting_list = Queue. new() +and waiting = ref 0 +and max_open = ref 10 +and cur_open = ref 0 + +let add fd f = + if !cur_open < !max_open then begin + incr cur_open; + add_fileinput fd f + end + else begin + incr waiting; + Queue.add (fd,f) waiting_list + end + +let remove fd = + diff --git a/otherlibs/labltk/frx/frx_fillbox.ml b/otherlibs/labltk/frx/frx_fillbox.ml new file mode 100644 index 0000000..d9e4741 --- /dev/null +++ b/otherlibs/labltk/frx/frx_fillbox.ml @@ -0,0 +1,65 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +(* + * Progress indicators + *) +let okcolor = NamedColor "#3cb371" +and kocolor = NamedColor "#dc5c5c" + + +let new_vertical parent w h = + let c = Canvas.create_named parent "fillbox" + [Width (Pixels w); Height (Pixels h); BorderWidth (Pixels 1); + Relief Sunken] + in + let i = Canvas.create_rectangle c (Pixels 0) (Pixels 0) (Pixels w) (Pixels 0) + [FillColor okcolor; Outline okcolor] + in + c, (function + 0 -> Canvas.configure_rectangle c i [FillColor okcolor; + Outline okcolor]; + Canvas.coords_set c i [Pixels 0; Pixels 0; + Pixels w; Pixels 0] + | -1 -> Canvas.configure_rectangle c i [FillColor kocolor; + Outline kocolor] + | n -> + let percent = if n > 100 then 100 else n in + let hf = percent*h/100 in + Canvas.coords_set c i [Pixels 0; Pixels 0; + Pixels w; Pixels hf]) + +let new_horizontal parent w h = + let c = Canvas.create_named parent "fillbox" + [Width (Pixels w); Height (Pixels h); BorderWidth (Pixels 1); + Relief Sunken] + in + let i = Canvas.create_rectangle c (Pixels 0) (Pixels 0) (Pixels 0) (Pixels h) + [FillColor okcolor; Outline okcolor] + in + c, (function + 0 -> Canvas.configure_rectangle c i [FillColor okcolor; + Outline okcolor]; + Canvas.coords_set c i [Pixels 0; Pixels 0; + Pixels 0; Pixels h] + | -1 -> Canvas.configure_rectangle c i [FillColor kocolor; + Outline kocolor] + | n -> + let percent = if n > 100 then 100 else n in + let wf = percent*w/100 in + Canvas.coords_set c i [Pixels 0; Pixels 0; + Pixels wf; Pixels h]) diff --git a/otherlibs/labltk/frx/frx_fillbox.mli b/otherlibs/labltk/frx/frx_fillbox.mli new file mode 100644 index 0000000..a825524 --- /dev/null +++ b/otherlibs/labltk/frx/frx_fillbox.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +val new_vertical : + Widget.widget -> int -> int -> Widget.widget * (int -> unit) + (* [new_vertical parent width height] + creates a vertical fillbox of [width] and [height]. + Returns a frame widget and a function to set the current value of + the fillbox. The value can be + n < 0 : the fillbox changes color (reddish) + 0 <= n <= 100: the fillbox fills up to n percent + 100 <= n : the fillbox fills up to 95% + *) + +val new_horizontal : + Widget.widget -> int -> int -> Widget.widget * (int -> unit) + (* save as above, except the widget is horizontal *) diff --git a/otherlibs/labltk/frx/frx_fit.ml b/otherlibs/labltk/frx/frx_fit.ml new file mode 100644 index 0000000..2011699 --- /dev/null +++ b/otherlibs/labltk/frx/frx_fit.ml @@ -0,0 +1,83 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let debug = ref false + +let vert wid = + let newsize = ref 0 + and pending_resize = ref false + and last_last = ref 0.0 in + let rec resize () = + pending_resize := false; + if !debug then + (Printf.eprintf "%s Resize %d\n" + (Widget.name wid) !newsize; flush stderr); + Text.configure wid [TextHeight !newsize]; + () + and check () = + let first, last = Text.yview_get wid in + check1 first last + + and check1 first last = + let curheight = int_of_string (cget wid CHeight) in + if !debug then begin + Printf.eprintf "%s C %d %f %f\n" + (Widget.name wid) curheight first last; + flush stderr + end; + if first = 0.0 && last = 1.0 then () + (* Don't attempt anything if widget is not visible *) + else if not (Winfo.viewable wid) then begin + if !debug then + (Printf.eprintf "%s C notviewable\n" (Widget.name wid); + flush stderr); + (* Try again later *) + bind wid [[], Expose] (BindSet ([], fun _ -> + bind wid [[], Expose] BindRemove; + check())) + end + else begin + let delta = + if last = 0.0 then 1 + else if last = !last_last then + (* it didn't change since our last resize ! *) + 1 + else begin + last_last := last; + (* never to more than double *) + let visible = max 0.5 (last -. first) in + max 1 (truncate (float curheight *. (1. -. visible))) + end in + newsize := max (curheight + delta) !newsize; + if !debug then + (Printf.eprintf "%s newsize: %d\n" (Widget.name wid) !newsize; + flush stderr); + if !pending_resize then () + else begin + pending_resize := true; + Timer.set 300 (fun () -> Frx_after.idle resize) + end + end + + and scroll first last = + if !debug then + (Printf.eprintf "%s V %f %f\n" (Widget.name wid) first last; + flush stderr); + if first = 0.0 && last = 1.0 then () + else check1 first last + in + scroll, check diff --git a/otherlibs/labltk/frx/frx_fit.mli b/otherlibs/labltk/frx/frx_fit.mli new file mode 100644 index 0000000..29479d8 --- /dev/null +++ b/otherlibs/labltk/frx/frx_fit.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget + +val debug: bool ref +val vert: widget -> (float -> float -> unit) * (unit -> unit) + +(* [vert widget] + can be applied to a text widget so that it expands to show its full + contents. Returns [scroll] and [check]. [scroll] must be used as + the YScrollCommand of the widget. [check] can be called when some + modification occurs in the content of the widget (such as a size change + in some embedded windows. + This feature is a terrible hack and should be used with extreme caution. + *) diff --git a/otherlibs/labltk/frx/frx_focus.ml b/otherlibs/labltk/frx/frx_focus.ml new file mode 100644 index 0000000..f33b9e6 --- /dev/null +++ b/otherlibs/labltk/frx/frx_focus.ml @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +(* Temporary focus *) + +(* ? use bind tag ? how about the global reference then *) +let auto w = + let old_focus = ref w in + bind w [[],Enter] + (BindSet([], fun _ -> old_focus := Focus.get (); Focus.set w)); + bind w [[],Leave] + (BindSet([], fun _ -> Focus.set !old_focus)) diff --git a/otherlibs/labltk/frx/frx_focus.mli b/otherlibs/labltk/frx/frx_focus.mli new file mode 100644 index 0000000..919f704 --- /dev/null +++ b/otherlibs/labltk/frx/frx_focus.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +val auto : Widget.widget -> unit + (* *) diff --git a/otherlibs/labltk/frx/frx_font.ml b/otherlibs/labltk/frx/frx_font.ml new file mode 100644 index 0000000..2d57d00 --- /dev/null +++ b/otherlibs/labltk/frx/frx_font.ml @@ -0,0 +1,51 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget + +let version = "$Id: frx_font.ml,v 1.3 2002-07-23 14:11:56 doligez Exp $" + +(* + * Finding fonts. Inspired by code in Ical by Sanjay Ghemawat. + * Possibly bogus because some families use "i" for italic where others + * use "o". + * wght: bold, medium + * slant: i, o, r + * pxlsz: 8, 10, ... +*) +module StringSet = Set.Make(struct type t = string let compare = compare end) + +let available_fonts = ref (StringSet.empty) + +let get_canvas = + Frx_misc.autodef (fun () -> Canvas.create Widget.default_toplevel []) + + +let find fmly wght slant pxlsz = + let fontspec = + "-*-"^fmly^"-"^wght^"-"^slant^"-normal-*-"^string_of_int pxlsz^"-*-*-*-*-*-iso8859-1" in + if StringSet.mem fontspec !available_fonts then fontspec + else + let c = get_canvas() in + try + let tag = Canvas.create_text c (Pixels 0) (Pixels 0) + [Text "foo"; Font fontspec] in + Canvas.delete c [tag]; + available_fonts := StringSet.add fontspec !available_fonts; + fontspec + with + _ -> raise (Invalid_argument fontspec) + diff --git a/otherlibs/labltk/frx/frx_font.mli b/otherlibs/labltk/frx/frx_font.mli new file mode 100644 index 0000000..c0b7e68 --- /dev/null +++ b/otherlibs/labltk/frx/frx_font.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val find : string -> string -> string -> int -> string + (* [find family weight slant pxlsz] returns the X11 full name of + the font required font, if available. + Raises Invalid_argument fullname otherwise. + *) diff --git a/otherlibs/labltk/frx/frx_group.ml b/otherlibs/labltk/frx/frx_group.ml new file mode 100644 index 0000000..17c8a03 --- /dev/null +++ b/otherlibs/labltk/frx/frx_group.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let vgroup top l = + let f = Frame.create top [] in + Pack.forget l; + Pack.configure l [In f]; + f diff --git a/otherlibs/labltk/frx/frx_lbutton.ml b/otherlibs/labltk/frx/frx_lbutton.ml new file mode 100644 index 0000000..1046082 --- /dev/null +++ b/otherlibs/labltk/frx/frx_lbutton.ml @@ -0,0 +1,50 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +open Widget + + +let version = "$Id: frx_lbutton.ml,v 1.2 2002-04-26 12:16:05 furuse Exp $" + +(* + * Simulate a button with a bitmap AND a label + *) + +let rec sort_options but lab com = function + [] -> but,lab,com + |(Command f as o)::l -> sort_options (o::but) lab com l + |(Bitmap b as o)::l -> sort_options (o::but) lab com l + |(Text t as o)::l -> sort_options but (o::lab) com l + |o::l -> sort_options but lab (o::com) l + +let create parent options = + let but,lab,com = sort_options [] [] [] options in + let f = Frame.create parent com in + let b = Button.create f (but@com) + and l = Label.create f (lab@com) in + pack [b;l][]; + bind l [[],ButtonPressDetail 1] (BindSet ([],(function _ -> Button.invoke b))); + f + +let configure f options = + let but,lab,com = sort_options [] [] [] options in + match Pack.slaves f with + [b;l] -> + Frame.configure f com; + Button.configure b (but@com); + Label.configure l (lab@com) + | _ -> raise (Invalid_argument "lbutton configure") diff --git a/otherlibs/labltk/frx/frx_lbutton.mli b/otherlibs/labltk/frx/frx_lbutton.mli new file mode 100644 index 0000000..d79431f --- /dev/null +++ b/otherlibs/labltk/frx/frx_lbutton.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Widget +open Camltk + + +val version : string + +val create : Widget -> option list -> Widget +and configure : Widget -> option list -> unit + diff --git a/otherlibs/labltk/frx/frx_listbox.ml b/otherlibs/labltk/frx/frx_listbox.ml new file mode 100644 index 0000000..817e832 --- /dev/null +++ b/otherlibs/labltk/frx/frx_listbox.ml @@ -0,0 +1,92 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let version = "$Id: frx_listbox.ml,v 1.3 2002-07-23 14:11:56 doligez Exp $" + +(* + * Link a scrollbar and a listbox + *) +let scroll_link sb lb = + Listbox.configure lb + [YScrollCommand (Scrollbar.set sb)]; + Scrollbar.configure sb + [ScrollCommand (Listbox.yview lb)] + +(* + * Completion for listboxes, Macintosh style. + * As long as you type fast enough, the listbox is repositioned to the + * first entry "greater" than the typed prefix. + * assumes: + * sorted list (otherwise it's stupid) + * fixed size, because we don't recompute size at each callback invocation + *) + +let add_completion lb action = + let prefx = ref "" (* current match prefix *) + and maxi = Listbox.size lb - 1 (* maximum index (doesn't matter actually) *) + and current = ref 0 (* current position *) + and lastevent = ref 0 in + + let rec move_forward () = + if Listbox.get lb (Number !current) < !prefx then + if !current < maxi then begin incr current; move_forward() end + + and recenter () = + let element = Number !current in + (* Clean the selection *) + Listbox.selection_clear lb (Number 0) End; + (* Set it to our unique element *) + Listbox.selection_set lb element element; + (* Activate it, to keep consistent with Up/Down. + You have to be in Extended or Browse mode *) + Listbox.activate lb element; + Listbox.selection_anchor lb element; + Listbox.see lb element in + + let complete time s = + if time - !lastevent < 500 then (* sorry, hard coded limit *) + prefx := !prefx ^ s + else begin (* reset *) + current := 0; + prefx := s + end; + lastevent := time; + move_forward(); + recenter() in + + + bind lb [[], KeyPress] + (BindSet([Ev_Char; Ev_Time], + (function ev -> + (* consider only keys producing characters. The callback is called + * even if you press Shift. + *) + if ev.ev_Char <> "" then complete ev.ev_Time ev.ev_Char))); + (* Key specific bindings override KeyPress *) + bind lb [[], KeyPressDetail "Return"] (BindSet([], action)); + (* Finally, we have to set focus, otherwise events dont get through *) + Focus.set lb; + recenter() (* so that first item is selected *) + +let new_scrollable_listbox top options = + let f = Frame.create top [] in + let lb = Listbox.create f options + and sb = Scrollbar.create f [] in + scroll_link sb lb; + pack [lb] [Side Side_Left; Fill Fill_Both; Expand true]; + pack [sb] [Side Side_Left; Fill Fill_Y]; + f, lb diff --git a/otherlibs/labltk/frx/frx_listbox.mli b/otherlibs/labltk/frx/frx_listbox.mli new file mode 100644 index 0000000..b44b6ee --- /dev/null +++ b/otherlibs/labltk/frx/frx_listbox.mli @@ -0,0 +1,32 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +val scroll_link : Widget.widget -> Widget.widget -> unit + (* [scroll_link scrollbar listbox] links [scrollbar] and [listbox] + as expected. + *) + +val add_completion : Widget.widget -> (eventInfo -> unit) -> unit + (* [add_completion listbox action] adds Macintosh like electric navigation + in the listbox when characters are typed in. + [action] is invoked if Return is pressed + *) + +val new_scrollable_listbox : + Widget.widget -> options list -> Widget.widget * Widget.widget + (* [new_scrollable_listbox parent options] makes a scrollable listbox and + returns (frame, listbox) + *) diff --git a/otherlibs/labltk/frx/frx_mem.ml b/otherlibs/labltk/frx/frx_mem.ml new file mode 100644 index 0000000..4bab868 --- /dev/null +++ b/otherlibs/labltk/frx/frx_mem.ml @@ -0,0 +1,89 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Memory gauge *) +open Camltk +open Gc + +let inited = ref None +let w = ref 300 +let delay = ref 5 (* in seconds *) +let wordsize = (* officially approved *) + if 1 lsl 31 = 0 then 4 else 8 + + +let init () = + let top = Toplevel.create Widget.default_toplevel [Class "CamlGC"] in + let name = Camltk.appname_get () in + Wm.title_set top (name ^ " Memory Gauge"); + Wm.withdraw top; + inited := Some top; + (* this should be executed before the internal "all" binding *) + bind top [[], Destroy] (BindSet ([], (fun _ -> inited := None))); + let fminors = Frame.create top [] in + let lminors = Label.create fminors [Text "Minor collections"] + and vminors = Label.create fminors [] in + pack [lminors][Side Side_Left]; + pack [vminors][Side Side_Right; Fill Fill_X; Expand true]; + let fmajors = Frame.create top [] in + let lmajors = Label.create fmajors [Text "Major collections"] + and vmajors = Label.create fmajors [] in + pack [lmajors][Side Side_Left]; + pack [vmajors][Side Side_Right; Fill Fill_X; Expand true]; + let fcompacts = Frame.create top [] in + let lcompacts = Label.create fcompacts [Text "Compactions"] + and vcompacts = Label.create fcompacts [] in + pack [lcompacts][Side Side_Left]; + pack [vcompacts][Side Side_Right; Fill Fill_X; Expand true]; + let fsize = Frame.create top [] in + let lsize = Label.create fsize [Text "Heap size (bytes)"] + and vsize = Label.create fsize [] in + pack [lsize][Side Side_Left]; + pack [vsize][Side Side_Right; Fill Fill_X; Expand true]; + let fheap = Frame.create top [Width (Pixels !w); Height (Pixels 10)] in + let flive = Frame.create fheap [Background Red] + and ffree = Frame.create fheap [Background Green] + and fdead = Frame.create fheap [Background Black] in + pack [fminors; fmajors; fcompacts; fsize; fheap][Fill Fill_X]; + + let display () = + let st = Gc.stat() in + Label.configure vminors [Text (string_of_int st.minor_collections)]; + Label.configure vmajors [Text (string_of_int st.major_collections)]; + Label.configure vcompacts [Text (string_of_int st.compactions)]; + Label.configure vsize [Text (string_of_int (wordsize * st.heap_words))]; + let liver = (float st.live_words) /. (float st.heap_words) + and freer = (float st.free_words) /. (float st.heap_words) in + Place.configure flive [X (Pixels 0); Y (Pixels 0); + RelWidth liver; RelHeight 1.0]; + Place.configure ffree [RelX liver; Y (Pixels 0); + RelWidth freer; RelHeight 1.0]; + Place.configure fdead [RelX (liver +. freer); Y (Pixels 0); + RelWidth (1.0 -. freer -. liver); RelHeight 1.0] + + in + let rec tim () = + if Winfo.exists top then begin + display(); + Timer.set (!delay * 1000) tim + end + in + tim() + + +let rec f () = + match !inited with + Some w -> Wm.deiconify w + | None -> init (); f() diff --git a/otherlibs/labltk/frx/frx_mem.mli b/otherlibs/labltk/frx/frx_mem.mli new file mode 100644 index 0000000..f3069ec --- /dev/null +++ b/otherlibs/labltk/frx/frx_mem.mli @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* A Garbage Collector Gauge for Caml *) + +val init : unit -> unit + (* [init ()] creates the gauge and its updater, but keeps it iconified *) + +val f : unit -> unit + (* [f ()] makes the gauge visible if it has not been destroyed *) diff --git a/otherlibs/labltk/frx/frx_misc.ml b/otherlibs/labltk/frx/frx_misc.ml new file mode 100644 index 0000000..d2be009 --- /dev/null +++ b/otherlibs/labltk/frx/frx_misc.ml @@ -0,0 +1,69 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Delayed global, a.k.a cache&carry *) +let autodef f = + let v = ref None in + (function () -> + match !v with + None -> + let x = f() in + v := Some x; + x + | Some x -> x) + +open Camltk + +(* allows Data in options *) +let create_photo options = + let hasopt = ref None in + (* Check options *) + List.iter (function + Data s -> + begin match !hasopt with + None -> hasopt := Some (Data s) + | Some _ -> raise (Protocol.TkError "two data sources in options") + end + | File f -> + begin match !hasopt with + None -> hasopt := Some (File f) + | Some _ -> raise (Protocol.TkError "two data sources in options") + end + | o -> ()) + options; + match !hasopt with + None -> raise (Protocol.TkError "no data source in options") + | Some (Data s) -> + begin + let tmpfile = Filename.temp_file "img" "" in + let oc = open_out_bin tmpfile in + output_string oc s; + close_out oc; + let newopts = + List.map (function + | Data s -> File tmpfile + | o -> o) + options in + try + let i = Imagephoto.create newopts in + (try Sys.remove tmpfile with Sys_error _ -> ()); + i + with + e -> + (try Sys.remove tmpfile with Sys_error _ -> ()); + raise e + end + | Some (File s) -> Imagephoto.create options + | _ -> assert false diff --git a/otherlibs/labltk/frx/frx_misc.mli b/otherlibs/labltk/frx/frx_misc.mli new file mode 100644 index 0000000..2df8ce3 --- /dev/null +++ b/otherlibs/labltk/frx/frx_misc.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +val autodef : (unit -> 'a) -> (unit -> 'a) + (* [autodef make] is a pleasant wrapper around 'a option ref *) + +val create_photo : Camltk.options list -> Camltk.imagePhoto + (* [create_photo options] allows Data in options (by saving to tmp file) *) diff --git a/otherlibs/labltk/frx/frx_req.ml b/otherlibs/labltk/frx/frx_req.ml new file mode 100644 index 0000000..0d85855 --- /dev/null +++ b/otherlibs/labltk/frx/frx_req.ml @@ -0,0 +1,198 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +(* + * Some standard requesters (in Amiga techspeak) or dialog boxes (in Apple + * jargon). +*) + +let version = "$Id: frx_req.ml,v 1.3 2002-07-23 14:11:58 doligez Exp $" + +(* + * Simple requester + * an entry field, unrestricted, with emacs-like bindings + * Note: grabs focus, thus always unique at one given moment, and we + * shouldn't have to worry about toplevel widget name. + * We add a title widget in case the window manager does not decorate + * toplevel windows. +*) + +let open_simple title action notaction memory = + let t = Toplevel.create Widget.default_toplevel [Class "Dialog"] in + Focus.set t; + Wm.title_set t title; + let tit = Label.create t [Text title] in + let len = max 40 (String.length (Textvariable.get memory)) in + let e = + Entry.create t [Relief Sunken; TextVariable memory; TextWidth len] in + + let activate _ = + let v = Entry.get e in + Grab.release t; (* because of wm *) + destroy t; (* so action can call open_simple *) + action v in + + bind e [[], KeyPressDetail "Return"] (BindSet ([], activate)); + + let f = Frame.create t [] in + let bok = Button.create f [Text "Ok"; Command activate] in + let bcancel = Button.create f + [Text "Cancel"; + Command (fun () -> notaction(); Grab.release t; destroy t)] in + + bind e [[], KeyPressDetail "Escape"] + (BindSet ([], (fun _ -> Button.invoke bcancel))); + pack [bok] [Side Side_Left; Expand true]; + pack [bcancel] [Side Side_Right; Expand true]; + pack [tit;e] [Fill Fill_X]; + pack [f] [Side Side_Bottom; Fill Fill_X]; + Frx_widget.resizeable t; + Focus.set e; + Tkwait.visibility t; + Grab.set t + +(* A synchronous version *) +let open_simple_synchronous title memory = + let t = Toplevel.create Widget.default_toplevel [Class "Dialog"] in + Focus.set t; + Wm.title_set t title; + let tit = Label.create t [Text title] in + let len = max 40 (String.length (Textvariable.get memory)) in + let e = + Entry.create t [Relief Sunken; TextVariable memory; TextWidth len] in + + let waiting = Textvariable.create_temporary t in + + let activate _ = + Grab.release t; (* because of wm *) + destroy t; (* so action can call open_simple *) + Textvariable.set waiting "1" in + + bind e [[], KeyPressDetail "Return"] (BindSet ([], activate)); + + let f = Frame.create t [] in + let bok = Button.create f [Text "Ok"; Command activate] in + let bcancel = + Button.create f + [Text "Cancel"; + Command (fun () -> + Grab.release t; destroy t; Textvariable.set waiting "0")] in + + bind e [[], KeyPressDetail "Escape"] + (BindSet ([], (fun _ -> Button.invoke bcancel))); + pack [bok] [Side Side_Left; Expand true]; + pack [bcancel] [Side Side_Right; Expand true]; + pack [tit;e] [Fill Fill_X]; + pack [f] [Side Side_Bottom; Fill Fill_X]; + Frx_widget.resizeable t; + Focus.set e; + Tkwait.visibility t; + Grab.set t; + Tkwait.variable waiting; + begin match Textvariable.get waiting with + "1" -> true + | _ -> false + end + +(* + * Simple list requester + * Same remarks as in open_simple. + * focus seems to be in the listbox automatically + *) +let open_list title elements action notaction = + let t = Toplevel.create Widget.default_toplevel [Class "Dialog"] in + Wm.title_set t title; + + let tit = Label.create t [Text title] in + let fls = Frame.create t [Relief Sunken; BorderWidth (Pixels 2)] in + let lb = Listbox.create fls [SelectMode Extended] in + let sb = Scrollbar.create fls [] in + Frx_listbox.scroll_link sb lb; + Listbox.insert lb End elements; + + (* activation: we have to break() because we destroy the requester *) + let activate _ = + let l = List.map (Listbox.get lb) (Listbox.curselection lb) in + Grab.release t; + destroy t; + List.iter action l; + break() in + + + bind lb [[Double], ButtonPressDetail 1] (BindSetBreakable ([], activate)); + + Frx_listbox.add_completion lb activate; + + let f = Frame.create t [] in + let bok = Button.create f [Text "Ok"; Command activate] in + let bcancel = Button.create f + [Text "Cancel"; + Command (fun () -> notaction(); Grab.release t; destroy t)] in + + pack [bok; bcancel] [Side Side_Left; Fill Fill_X; Expand true]; + pack [lb] [Side Side_Left; Fill Fill_Both; Expand true]; + pack [sb] [Side Side_Right; Fill Fill_Y]; + pack [tit] [Fill Fill_X]; + pack [fls] [Fill Fill_Both; Expand true]; + pack [f] [Side Side_Bottom; Fill Fill_X]; + Frx_widget.resizeable t; + Tkwait.visibility t; + Grab.set t + + +(* Synchronous *) +let open_passwd title = + let username = ref "" + and password = ref "" + and cancelled = ref false in + let t = Toplevel.create Widget.default_toplevel [Class "Dialog"] in + Focus.set t; + Wm.title_set t title; + let tit = Label.create t [Text title] + and fu,eu = Frx_entry.new_label_entry t "Username" (fun s -> ()) + and fp,ep = Frx_entry.new_label_entry t "Password" (fun s -> ()) + in + let fb = Frame.create t [] in + let bok = Button.create fb + [Text "Ok"; Command (fun _ -> + username := Entry.get eu; + password := Entry.get ep; + Grab.release t; (* because of wm *) + destroy t)] (* will return from tkwait *) + and bcancel = Button.create fb + [Text "Cancel"; Command (fun _ -> + cancelled := true; + Grab.release t; (* because of wm *) + destroy t)] (* will return from tkwait *) + in + Entry.configure ep [Show '*']; + bind eu [[], KeyPressDetail "Return"] + (BindSetBreakable ([], (fun _ -> Focus.set ep; break()))); + bind ep [[], KeyPressDetail "Return"] + (BindSetBreakable ([], (fun _ -> Button.flash bok; + Button.invoke bok; + break()))); + + pack [bok] [Side Side_Left; Expand true]; + pack [bcancel] [Side Side_Right; Expand true]; + pack [tit;fu;fp;fb] [Fill Fill_X]; + Tkwait.visibility t; + Focus.set eu; + Grab.set t; + Tkwait.window t; + if !cancelled then failwith "cancelled" + else (!username, !password) diff --git a/otherlibs/labltk/frx/frx_req.mli b/otherlibs/labltk/frx/frx_req.mli new file mode 100644 index 0000000..815b284 --- /dev/null +++ b/otherlibs/labltk/frx/frx_req.mli @@ -0,0 +1,43 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Various dialog boxes *) +val open_simple : + string -> + (string -> unit) -> (unit -> 'a) -> Textvariable.textVariable -> unit + (* [open_simple title action cancelled memory] + A dialog with a message and an entry field (with memory between + invocations). Either [action] or [cancelled] is called when the user + answers to the dialog (with Ok or Cancel) + *) + +val open_simple_synchronous : string -> Textvariable.textVariable -> bool + (* [open_simple_synchronous title memory] + A synchronous dialog with a message and an entry field (with + memory between invocations). Returns true if the user clicks Ok + or false if the user clicks Cancel. + *) +val open_list : + string -> string list -> (string -> unit) -> (unit -> unit) -> unit + (* [open_list title elements action cancelled] + A dialog for selecting from a list of elements. [action] is called + on each selected element, or [cancelled] is called if the user clicks + Cancel. + *) + +val open_passwd : string -> string * string + (* [open_passwd title] pops up a username/password dialog and returns + (username, password). + *) diff --git a/otherlibs/labltk/frx/frx_rpc.ml b/otherlibs/labltk/frx/frx_rpc.ml new file mode 100644 index 0000000..5f29cbc --- /dev/null +++ b/otherlibs/labltk/frx/frx_rpc.ml @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Some notion of RPC *) +open Camltk +open Protocol + +(* A RPC is just a callback with a particular name, plus a Tcl procedure *) +let register name f = + let id = new_function_id() in + Hashtbl.add callback_naming_table id f; + (* For rpc_info *) + Textvariable.set (Textvariable.coerce ("camltkrpc("^name^")")) + (string_of_cbid id); + tkCommand [| TkToken "proc"; TkToken name; TkToken "args"; + TkToken ("camlcb "^(string_of_cbid id)^" $args") |] + +(* RPC *) +let invoke interp f args = + tkEval [| + TkToken "send"; + TkToken interp; + TkToken f; + TkTokenList (List.map (fun s -> TkToken s) args) + |] + +let async_invoke interp f args = + tkCommand [| + TkToken "send"; + TkToken "-async"; + TkToken interp; + TkToken f; + TkTokenList (List.map (fun s -> TkToken s) args) + |] + +let rpc_info interp = + tkEval [| + TkToken "send"; + TkToken interp; + TkToken "array"; + TkToken "names"; + TkToken "camltkrpc" + |] diff --git a/otherlibs/labltk/frx/frx_rpc.mli b/otherlibs/labltk/frx/frx_rpc.mli new file mode 100644 index 0000000..808fe87 --- /dev/null +++ b/otherlibs/labltk/frx/frx_rpc.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Some notion of RPC *) + +val register : string -> (string list -> unit) -> unit + (* [register external_name f] *) +val invoke : string -> string -> string list -> string + (* [invoke interp name args] *) +val async_invoke : string -> string -> string list -> unit + (* [async_invoke interp name args] *) +val rpc_info : string -> string + (* [rpc_info interp] *) diff --git a/otherlibs/labltk/frx/frx_selection.ml b/otherlibs/labltk/frx/frx_selection.ml new file mode 100644 index 0000000..7ef64ce --- /dev/null +++ b/otherlibs/labltk/frx/frx_selection.ml @@ -0,0 +1,45 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* A selection handler *) +open Widget +open Protocol +open Camltk + +let frame = ref None +let selection = ref "" + +let read ofs n = + let res = + if ofs < 0 then "" + else if ofs + n > String.length !selection + then String.sub !selection ofs (String.length !selection - ofs) + else String.sub !selection ofs n in + tkreturn res + +(* As long as we don't loose the selection, we keep the widget *) +(* Calling this function means that we own the selection *) +(* When we loose the selection, both cb are destroyed *) +let own () = + match !frame with + None -> + let f = Frame.create_named Widget.default_toplevel "frx_selection" [] in + let lost () = selection := ""; destroy f; frame := None in + Selection.own_set [Selection "PRIMARY"; LostCommand lost] f; + Selection.handle_set [Selection "PRIMARY"; ICCCMType "STRING"] f read; + frame := Some f + | Some f -> () + +let set s = own(); selection := s diff --git a/otherlibs/labltk/frx/frx_selection.mli b/otherlibs/labltk/frx/frx_selection.mli new file mode 100644 index 0000000..dfb27ee --- /dev/null +++ b/otherlibs/labltk/frx/frx_selection.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val set : string -> unit + (* [set s] sets the X PRIMARY selection to [s] *) diff --git a/otherlibs/labltk/frx/frx_synth.ml b/otherlibs/labltk/frx/frx_synth.ml new file mode 100644 index 0000000..d7acf06 --- /dev/null +++ b/otherlibs/labltk/frx/frx_synth.ml @@ -0,0 +1,88 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Some notion of synthetic events *) +open Camltk +open Widget +open Protocol + +(* To each event is associated a table of (widget, callback) *) +let events = Hashtbl.create 37 + +(* Notes: + * "cascading" events (on the same event) are not supported + * Only one binding active at a time for each event on each widget. + *) + +(* Get the callback table associated with <name>. Initializes if required *) +let get_event name = + try Hashtbl.find events name + with + Not_found -> + let h = Hashtbl.create 37 in + Hashtbl.add events name h; + (* Initialize the callback invocation mechanism, based on + variable trace + *) + let var = "camltk_events(" ^ name ^")" in + let tkvar = Textvariable.coerce var in + let rec set () = + Textvariable.handle tkvar + (fun () -> + begin match Textvariable.get tkvar with + "all" -> (* Invoke all callbacks *) + Hashtbl.iter + (fun p f -> + try + f (cTKtoCAMLwidget p) + with _ -> ()) + h + | p -> (* Invoke callback for p *) + try + let w = cTKtoCAMLwidget p + and f = Hashtbl.find h p in + f w + with + _ -> () + end; + set ()(* reactivate the callback *) + ) in + set(); + h + +(* Remove binding for event <name> on widget <w> *) +let remove w name = + Hashtbl.remove (get_event name) (Widget.name w) + +(* Adds <f> as callback for widget <w> on event <name> *) +let bind w name f = + remove w name; + Hashtbl.add (get_event name) (Widget.name w) f + +(* Sends event <name> to all widgets *) +let broadcast name = + Textvariable.set (Textvariable.coerce ("camltk_events(" ^ name ^")")) "all" + +(* Sends event <name> to widget <w> *) +let send name w = + Textvariable.set (Textvariable.coerce ("camltk_events(" ^ name ^")")) + (Widget.name w) + +(* Remove all callbacks associated to widget <w> *) +let remove_callbacks w = + Hashtbl.iter (fun _ h -> Hashtbl.remove h (Widget.name w)) events + +let _ = + add_destroy_hook remove_callbacks diff --git a/otherlibs/labltk/frx/frx_synth.mli b/otherlibs/labltk/frx/frx_synth.mli new file mode 100644 index 0000000..0b8d85d --- /dev/null +++ b/otherlibs/labltk/frx/frx_synth.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* Synthetic events *) +open Camltk +open Widget + + +val send : string -> widget -> unit + (* [send event_name widget] *) + +val broadcast : string -> unit + (* [broadcase event_name] *) + +val bind : widget -> string -> (widget -> unit) -> unit + (* [bind event_name callback] *) + +val remove : widget -> string -> unit + (* [remove widget event_name] *) diff --git a/otherlibs/labltk/frx/frx_text.ml b/otherlibs/labltk/frx/frx_text.ml new file mode 100644 index 0000000..d3d7127 --- /dev/null +++ b/otherlibs/labltk/frx/frx_text.ml @@ -0,0 +1,229 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +let version = "$Id: frx_text.ml,v 1.3 2002-07-23 14:11:58 doligez Exp $" + +(* + * convert an integer to an absolute index +*) +let abs_index n = + TextIndex (LineChar(0,0), [CharOffset n]) + +let insertMark = + TextIndex(Mark "insert", []) + +let currentMark = + TextIndex(Mark "current", []) + +let textEnd = + TextIndex(End, []) + +let textBegin = + TextIndex (LineChar(0,0), []) + +(* + * Link a scrollbar and a text widget +*) +let scroll_link sb tx = + Text.configure tx [YScrollCommand (Scrollbar.set sb)]; + Scrollbar.configure sb [ScrollCommand (Text.yview tx)] + + +(* + * Tk 4.0 has navigation in Text widgets, sometimes using scrolling + * sometimes using the insertion mark. It is a pain to add more + * compatible bindings. We do our own. + *) +let page_up tx = Text.yview tx (ScrollPage (-1)) +and page_down tx = Text.yview tx (ScrollPage 1) +and line_up tx = Text.yview tx (ScrollUnit (-1)) +and line_down tx = Text.yview tx (ScrollUnit 1) +and top tx = Text.yview_index tx textBegin +and bottom tx = Text.yview_index tx textEnd + +let navigation_keys tx = + let tags = bindtags_get tx in + match tags with + (WidgetBindings t)::l when t = tx -> + bindtags tx ((WidgetBindings tx) :: (TagBindings "TEXT_RO") :: l) + | _ -> () + +let new_scrollable_text top options navigation = + let f = Frame.create top [] in + let tx = Text.create f options + and sb = Scrollbar.create f [] in + scroll_link sb tx; + (* IN THIS ORDER -- RESIZING *) + pack [sb] [Side Side_Right; Fill Fill_Y]; + pack [tx] [Side Side_Left; Fill Fill_Both; Expand true]; + if navigation then navigation_keys tx; + f, tx + +(* + * Searching + *) +let patternv = Frx_misc.autodef Textvariable.create +and casev = Frx_misc.autodef Textvariable.create + +let topsearch t = + (* The user interface *) + let top = Toplevel.create t [Class "TextSearch"] in + Wm.title_set top "Text search"; + let f = Frame.create_named top "fpattern" [] in + let m = Label.create_named f "search" [Text "Search pattern"] + and e = Entry.create_named f "pattern" + [Relief Sunken; TextVariable (patternv()) ] in + let hgroup = Frame.create top [] + and bgroup = Frame.create top [] in + let fdir = Frame.create hgroup [] + and fmisc = Frame.create hgroup [] in + let direction = Textvariable.create_temporary fdir + and exactv = Textvariable.create_temporary fdir + in + let forw = Radiobutton.create_named fdir "forward" + [Text "Forward"; Variable direction; Value "f"] + and backw = Radiobutton.create_named fdir "backward" + [Text "Backward"; Variable direction; Value "b"] + and exact = Checkbutton.create_named fmisc "exact" + [Text "Exact match"; Variable exactv] + and case = Checkbutton.create_named fmisc "case" + [Text "Fold Case"; Variable (casev())] + and searchb = Button.create_named bgroup "search" [Text "Search"] + and contb = Button.create_named bgroup "continue" [Text "Continue"] + and dismissb = Button.create_named bgroup "dismiss" + [Text "Dismiss"; + Command (fun () -> Text.tag_delete t ["search"]; destroy top)] in + + Radiobutton.invoke forw; + pack [m][Side Side_Left]; + pack [e][Side Side_Right; Fill Fill_X; Expand true]; + pack [forw; backw] [Anchor W]; + pack [exact; case] [Anchor W]; + pack [fdir; fmisc] [Side Side_Left; Anchor Center]; + pack [searchb; contb; dismissb] [Side Side_Left; Fill Fill_X]; + pack [f;hgroup;bgroup] [Fill Fill_X; Expand true]; + + let current_index = ref textBegin in + + let search cont = fun () -> + let opts = ref [] in + if Textvariable.get direction = "f" then + opts := Forwards :: !opts + else opts := Backwards :: !opts ; + if Textvariable.get exactv = "1" then + opts := Exact :: !opts; + if Textvariable.get (casev()) = "1" then + opts := Nocase :: !opts; + try + let forward = Textvariable.get direction = "f" in + let i = Text.search t !opts (Entry.get e) + (if cont then !current_index + else if forward then textBegin + else TextIndex(End, [CharOffset (-1)])) (* does not work with end *) + (if forward then textEnd + else textBegin) in + let found = TextIndex (i, []) in + current_index := + TextIndex(i, [CharOffset (if forward then 1 else (-1))]); + Text.tag_delete t ["search"]; + Text.tag_add t "search" found (TextIndex (i, [WordEnd])); + Text.tag_configure t "search" + [Relief Raised; BorderWidth (Pixels 1); + Background Red]; + Text.see t found + with + Invalid_argument _ -> Bell.ring() in + + bind e [[], KeyPressDetail "Return"] + (BindSet ([], fun _ -> search false ())); + Button.configure searchb [Command (search false)]; + Button.configure contb [Command (search true)]; + Tkwait.visibility top; + Focus.set e + +let addsearch tx = + let tags = bindtags_get tx in + match tags with + (WidgetBindings t)::l when t = tx -> + bindtags tx ((WidgetBindings tx) :: (TagBindings "SEARCH") :: l) + | _ -> () + +(* We use Mod1 instead of Meta or Alt *) +let init () = + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> page_up ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "BackSpace"]; + [[], KeyPressDetail "Delete"]; + [[], KeyPressDetail "Prior"]; + [[], KeyPressDetail "b"]; + [[Mod1], KeyPressDetail "v"] + ]; + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> page_down ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "space"]; + [[], KeyPressDetail "Next"]; + [[Control], KeyPressDetail "v"] + ]; + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> line_up ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "Up"]; + [[Mod1], KeyPressDetail "z"] + ]; + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> line_down ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "Down"]; + [[Control], KeyPressDetail "z"] + ]; + + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> top ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "Home"]; + [[Mod1], KeyPressDetail "less"] + ]; + + List.iter (function ev -> + tag_bind "TEXT_RO" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> bottom ei.ev_Widget; break())))) + [ + [[], KeyPressDetail "End"]; + [[Mod1], KeyPressDetail "greater"] + ]; + + List.iter (function ev -> + tag_bind "SEARCH" ev + (BindSetBreakable ([Ev_Widget], + (fun ei -> topsearch ei.ev_Widget; break())))) + [ + [[Control], KeyPressDetail "s"] + ] + diff --git a/otherlibs/labltk/frx/frx_text.mli b/otherlibs/labltk/frx/frx_text.mli new file mode 100644 index 0000000..ac03844 --- /dev/null +++ b/otherlibs/labltk/frx/frx_text.mli @@ -0,0 +1,46 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk + +val abs_index : int -> textIndex + (* [abs_index offs] returns the corresponding TextIndex *) + +val insertMark : textIndex +val currentMark : textIndex +val textEnd : textIndex +val textBegin : textIndex + (* shortcuts for various positions in a text widget *) + +val scroll_link : Widget.widget -> Widget.widget -> unit + (* [scroll_link scrollbar text] links a scrollbar and a text widget + as expected + *) + +val new_scrollable_text : + Widget.widget -> options list -> bool -> Widget.widget * Widget.widget + (* [new_scrollable_text parent opts nav_keys] makes a scrollable text + widget with optional navigation keys. Returns frame and text widget. + *) +val addsearch : Widget.widget -> unit + (* [addsearch textw] adds a search dialog bound on [Control-s] + on the text widget + *) + +val navigation_keys : Widget.widget -> unit + (* [navigation_keys textw] adds common navigations functions to [textw] *) + +val init : unit -> unit + (* [init ()] must be called before any of the above features is used *) diff --git a/otherlibs/labltk/frx/frx_toplevel.mli b/otherlibs/labltk/frx/frx_toplevel.mli new file mode 100644 index 0000000..3608e1e --- /dev/null +++ b/otherlibs/labltk/frx/frx_toplevel.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Widget +val make_visible : Widget -> unit diff --git a/otherlibs/labltk/frx/frx_widget.ml b/otherlibs/labltk/frx/frx_widget.ml new file mode 100644 index 0000000..cca7df0 --- /dev/null +++ b/otherlibs/labltk/frx/frx_widget.ml @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget + +let version = "$Id: frx_widget.ml,v 1.2 2002-04-26 12:16:10 furuse Exp $" +(* Make a window (toplevel widget) resizeable *) +let resizeable t = + update_idletasks(); (* wait until layout is computed *) + Wm.minsize_set t (Winfo.width t) (Winfo.height t) + diff --git a/otherlibs/labltk/frx/frx_widget.mli b/otherlibs/labltk/frx/frx_widget.mli new file mode 100644 index 0000000..ff26749 --- /dev/null +++ b/otherlibs/labltk/frx/frx_widget.mli @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget +val resizeable : widget -> unit diff --git a/otherlibs/labltk/frx/frxlib.mllib b/otherlibs/labltk/frx/frxlib.mllib new file mode 100644 index 0000000..3641ae5 --- /dev/null +++ b/otherlibs/labltk/frx/frxlib.mllib @@ -0,0 +1,4 @@ +Frx_misc Frx_widget Frx_font Frx_entry Frx_text +Frx_listbox Frx_req Frx_fillbox Frx_focus +Frx_dialog Frx_mem Frx_rpc Frx_synth Frx_selection +Frx_after Frx_fit Frx_ctext Frx_color diff --git a/otherlibs/labltk/jpf/Makefile b/otherlibs/labltk/jpf/Makefile new file mode 100644 index 0000000..0d33f41 --- /dev/null +++ b/otherlibs/labltk/jpf/Makefile @@ -0,0 +1,77 @@ +include ../support/Makefile.common + +COMPFLAGS=-I ../labltk -I ../support -I $(OTHERS)/win32unix -I $(OTHERS)/unix -I $(OTHERS)/str + +OBJS= fileselect.cmo balloon.cmo shell.cmo jpf_font.cmo + +OBJSX = $(OBJS:.cmo=.cmx) + +all: jpflib.cma + +opt: jpflib.cmxa + +test: balloontest + +testopt: balloontest.opt + +jpflib.cma: $(OBJS) + $(CAMLLIBR) -o jpflib.cma $(OBJS) + +jpflib.cmxa: $(OBJSX) + $(CAMLOPTLIBR) -o jpflib.cmxa $(OBJSX) + +install: + cp $(OBJS:.cmo=.cmi) $(OBJS:.cmo=.mli) jpflib.cma $(INSTALLDIR) + +installopt: + cp jpflib.cmxa jpflib.$(A) $(OBJS:.cmo=.cmx) $(INSTALLDIR) + +clean: + rm -f *.cm* *.$(O) *.$(A) *~ *test + +$(OBJS) $(OBJS:.cmo=.cmi): ../lib/$(LIBNAME).cma + +$(OBJSX): ../lib/$(LIBNAME).cmxa + +### Tests + +balloontest: balloontest.cmo + $(CAMLC) -o balloontest -I ../support -I ../lib \ + -custom $(LIBNAME).cma jpflib.cma balloontest.cmo + +balloontest.opt: balloontest.cmx + $(CAMLOPT) -o balloontest.opt -I ../support -I ../lib \ + $(LIBNAME).cmxa jpflib.cmxa balloontest.cmx + +balloontest.cmo : balloon.cmo jpflib.cma + +balloontest.cmx : balloon.cmx jpflib.cmxa + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmx .cmo + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: + mv Makefile Makefile.bak + (sed -n -e '1,/^### DO NOT DELETE THIS LINE/p' Makefile.bak; \ + $(CAMLDEP) *.mli *.ml) > Makefile + + +### EVERYTHING THAT GOES BEYOND THIS COMMENT IS GENERATED +### DO NOT DELETE THIS LINE +balloon.cmo: balloon.cmi +balloon.cmx: balloon.cmi +fileselect.cmo: fileselect.cmi +fileselect.cmx: fileselect.cmi +jpf_font.cmo: shell.cmi jpf_font.cmi +jpf_font.cmx: shell.cmx jpf_font.cmi +shell.cmo: shell.cmi +shell.cmx: shell.cmi diff --git a/otherlibs/labltk/jpf/Makefile.nt b/otherlibs/labltk/jpf/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/jpf/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/jpf/README b/otherlibs/labltk/jpf/README new file mode 100644 index 0000000..275c2d7 --- /dev/null +++ b/otherlibs/labltk/jpf/README @@ -0,0 +1,2 @@ +This is Jun Furuse's widget set library, Jpf. +It uses LablTk API. diff --git a/otherlibs/labltk/jpf/balloon.ml b/otherlibs/labltk/jpf/balloon.ml new file mode 100644 index 0000000..5b858c0 --- /dev/null +++ b/otherlibs/labltk/jpf/balloon.ml @@ -0,0 +1,102 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: balloon.ml,v 1.15 2002-04-26 12:16:12 furuse Exp $ *) + +open StdLabels + +(* easy balloon help facility *) + +open Tk +open Widget +open Protocol +open Support + +(* switch -- if you do not want balloons, set false *) +let flag = ref true +let debug = ref false + +(* We assume we have at most one popup label at a time *) +let topw = ref default_toplevel +and popupw = ref (Obj.magic dummy : message widget) + +let configure_cursor w cursor = + (* DDDDDDDDDIIIIIIIRRRRRRRRTTTTTTTTYYYYYYY *) + Protocol.tkCommand [| TkToken (name w); + TkToken "configure"; + TkToken "-cursor"; + TkToken cursor |] + +let put ~on: w ~ms: millisec mesg = + let t = ref None in + let cursor = ref "" in + + let reset () = + begin + match !t with + Some t -> Timer.remove t + | _ -> () + end; + (* if there is a popup label, unmap it *) + if Winfo.exists !topw && Wm.state !topw <> "withdrawn" then + begin + Wm.withdraw !topw; + if Winfo.exists w then configure_cursor w !cursor + end + and set ev = + if !flag then + t := Some (Timer.add ~ms: millisec ~callback: (fun () -> + t := None; + if !debug then + prerr_endline ("Balloon: " ^ Widget.name w); + update_idletasks(); + Message.configure !popupw ~text: mesg; + raise_window !topw; + Wm.geometry_set !topw (* 9 & 8 are some kind of magic... *) + ("+"^(string_of_int (ev.ev_RootX + 9))^ + "+"^(string_of_int (ev.ev_RootY + 8))); + Wm.deiconify !topw; + cursor := cget w `Cursor; + configure_cursor w "hand2")) + in + + List.iter [[`Leave]; [`ButtonPress]; [`ButtonRelease]; [`Destroy]; + [`KeyPress]; [`KeyRelease]] + ~f:(fun events -> bind w ~events ~extend:true ~action:(fun _ -> reset ())); + List.iter [[`Enter]; [`Motion]] ~f: + begin fun events -> + bind w ~events ~extend:true ~fields:[`RootX; `RootY] + ~action:(fun ev -> reset (); set ev) + end + +let init () = + let t = Hashtbl.create 101 in + Protocol.add_destroy_hook (fun w -> + Hashtbl.remove t w); + topw := Toplevel.create default_toplevel; + Wm.overrideredirect_set !topw true; + Wm.withdraw !topw; + popupw := Message.create !topw ~name: "balloon" + ~background: (`Color "yellow") ~aspect: 300; + pack [!popupw]; + bind_class "all" ~events: [`Enter] ~extend:true ~fields:[`Widget] ~action: + begin fun w -> + try Hashtbl.find t w.ev_Widget + with Not_found -> + Hashtbl.add t w.ev_Widget (); + let x = Option.get w.ev_Widget ~name: "balloon" ~clas: "Balloon" in + if x <> "" then put ~on: w.ev_Widget ~ms: 1000 x + end diff --git a/otherlibs/labltk/jpf/balloon.mli b/otherlibs/labltk/jpf/balloon.mli new file mode 100644 index 0000000..067561a --- /dev/null +++ b/otherlibs/labltk/jpf/balloon.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: balloon.mli,v 1.7 2002-04-26 12:16:12 furuse Exp $ *) + +(* easy balloon help facility *) +open Widget + +val flag : bool ref +val init : unit -> unit +val put : on: 'a widget -> ms: int -> string -> unit diff --git a/otherlibs/labltk/jpf/balloontest.ml b/otherlibs/labltk/jpf/balloontest.ml new file mode 100644 index 0000000..35bf5fd --- /dev/null +++ b/otherlibs/labltk/jpf/balloontest.ml @@ -0,0 +1,32 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: balloontest.ml,v 1.8 2002-04-26 12:16:12 furuse Exp $ *) + +open Tk +open Widget +open Balloon +open Protocol + +let _ = + let t = openTk () in + Balloon.init (); + let b = Button.create t ~text: "hello" in + Button.configure b ~command: (fun () -> destroy b); + pack [b]; + Balloon.put ~on: b ~ms: 1000 "Balloon"; + Printexc.catch mainLoop () + diff --git a/otherlibs/labltk/jpf/fileselect.ml b/otherlibs/labltk/jpf/fileselect.ml new file mode 100644 index 0000000..8f919d2 --- /dev/null +++ b/otherlibs/labltk/jpf/fileselect.ml @@ -0,0 +1,367 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: fileselect.ml,v 1.21 2005-01-28 16:13:11 doligez Exp $ *) + +(* file selection box *) + +(* This file selecter works only under the OS with the full unix support. + For the portability, Tk.getOpenFile and Tk.getSaveFile are recommended. *) + +open StdLabels +open UnixLabels +open Str +open Filename + +open Tk +open Widget + +exception Not_selected + +(********************************************************** Search directory *) +(* Default is curdir *) +let global_dir = ref (getcwd ()) + +(***************************************************** Some widgets creation *) + +(* from frx_listbox.ml *) +let scroll_link sb lb = + Listbox.configure lb ~yscrollcommand: (Scrollbar.set sb); + Scrollbar.configure sb ~command: (Listbox.yview lb) + +(* focus when enter binding *) +let bind_enter_focus w = + bind w ~events:[`Enter] ~action:(fun _ -> Focus.set w);; + +let myentry_create p ~variable = + let w = Entry.create p ~relief: `Sunken ~textvariable: variable in + bind_enter_focus w; w + +(************************************************************* Subshell call *) + +let subshell cmd = + let r,w = pipe () in + match fork () with + 0 -> close r; dup2 ~src:w ~dst:stdout; + execv ~prog:"/bin/sh" ~args:[| "/bin/sh"; "-c"; cmd |] + | id -> + close w; + let rc = in_channel_of_descr r in + let rec it l = + match + try Some(input_line rc) with _ -> None + with + Some x -> it (x::l) + | None -> List.rev l + in + let answer = it [] in + close_in rc; (* because of finalize_channel *) + let _ = waitpid ~mode:[] id in answer + +(***************************************************************** Path name *) + +(* find directory name which doesn't contain "?*[" *) +let dirget = regexp "^\\([^\\*?[]*/\\)\\(.*\\)" + +let parse_filter src = + (* replace // by / *) + let s = global_replace (regexp "/+") "/" src in + (* replace /./ by / *) + let s = global_replace (regexp "/\\./") "/" s in + (* replace ????/../ by "" *) + let s = global_replace + (regexp "\\([^/]\\|[^\\./][^/]\\|[^/][^\\./]\\|[^/][^/]+\\)/\\.\\./") + "" + s in + (* replace ????/..$ by "" *) + let s = global_replace + (regexp "\\([^/]\\|[^\\./][^/]\\|[^/][^\\./]\\|[^/][^/]+\\)/\\.\\.$") + "" + s in + (* replace ^/../../ by / *) + let s = global_replace (regexp "^\\(/\\.\\.\\)+/") "/" s in + if string_match dirget s 0 then + let dirs = matched_group 1 s + and ptrn = matched_group 2 s + in + dirs, ptrn + else "", s + +let ls dir pattern = + subshell ("cd " ^ dir ^ ";/bin/ls -ad " ^ pattern ^" 2>/dev/null") + +(*************************************************************** File System *) + +let get_files_in_directory dir = + let dirh = opendir dir in + let rec get_them l = + match + try Some(Unix.readdir dirh) with _ -> None + with + | None -> + Unix.closedir dirh; l + | Some x -> + get_them (x::l) + in + List.sort ~cmp:compare (get_them []) + +let rec get_directories_in_files path = + List.filter + ~f:(fun x -> try (stat (path ^ x)).st_kind = S_DIR with _ -> false) + +let remove_directories path = + List.filter + ~f:(fun x -> try (stat (path ^ x)).st_kind <> S_DIR with _ -> false) + +(************************* a nice interface to listbox - from frx_listbox.ml *) + +let add_completion lb action = + let prefx = ref "" (* current match prefix *) + and maxi = ref 0 (* maximum index (doesn'y matter actually) *) + and current = ref 0 (* current position *) + and lastevent = ref 0 in + + let rec move_forward () = + if Listbox.get lb ~index:(`Num !current) < !prefx then + if !current < !maxi then begin incr current; move_forward() end + + and recenter () = + let element = `Num !current in + (* Clean the selection *) + Listbox.selection_clear lb ~first:(`Num 0) ~last:`End; + (* Set it to our unique element *) + Listbox.selection_set lb ~first:element ~last:element; + (* Activate it, to keep consistent with Up/Down. + You have to be in Extended or Browse mode *) + Listbox.activate lb ~index:element; + Listbox.selection_anchor lb ~index:element; + Listbox.see lb ~index:element in + + let complete time s = + if time - !lastevent < 500 then (* sorry, hard coded limit *) + prefx := !prefx ^ s + else begin (* reset *) + current := 0; + prefx := s + end; + lastevent := time; + move_forward(); + recenter() in + + + bind lb ~events:[`KeyPress] ~fields:[`Char; `Time] + (* consider only keys producing characters. The callback is called + if you press Shift. *) + ~action:(fun ev -> if ev.ev_Char <> "" then complete ev.ev_Time ev.ev_Char); + (* Key specific bindings override KeyPress *) + bind lb ~events:[`KeyPressDetail "Return"] ~action; + (* Finally, we have to set focus, otherwise events dont get through *) + Focus.set lb; + recenter() (* so that first item is selected *); + (* returns init_completion function *) + (fun lb -> + prefx := ""; + maxi := Listbox.size lb - 1; + current := 0) + +(****************************************************************** Creation *) + +let f ~title ~action:proc ~filter:deffilter ~file:deffile ~multi ~sync = + (* Ah ! Now I regret about the names of the widgets... *) + + let current_pattern = ref "" + and current_dir = ref "" in + + (* init_completions *) + let filter_init_completion = ref (fun _ -> ()) + and directory_init_completion = ref (fun _ -> ()) in + + let tl = Toplevel.create default_toplevel in + Focus.set tl; + Wm.title_set tl title; + + let filter_var = Textvariable.create ~on:tl () (* new_temporary *) + and selection_var = Textvariable.create ~on:tl () + and sync_var = Textvariable.create ~on:tl () in + + let frm' = Frame.create tl ~borderwidth: 1 ~relief: `Raised in + let frm = Frame.create frm' ~borderwidth: 8 in + let fl = Label.create frm ~text: "Filter" in + let df = Frame.create frm in + let dfl = Frame.create df in + let dfll = Label.create dfl ~text: "Directories" in + let dflf = Frame.create dfl in + let directory_listbox = Listbox.create dflf ~relief: `Sunken + and directory_scrollbar = Scrollbar.create dflf in + scroll_link directory_scrollbar directory_listbox; + let dfr = Frame.create df in + let dfrl = Label.create dfr ~text: "Files" in + let dfrf = Frame.create dfr in + let filter_listbox = Listbox.create dfrf ~relief: `Sunken in + let filter_scrollbar = Scrollbar.create dfrf in + scroll_link filter_scrollbar filter_listbox; + let sl = Label.create frm ~text: "Selection" in + let filter_entry = myentry_create frm ~variable: filter_var in + let selection_entry = myentry_create frm ~variable: selection_var + in + let cfrm' = Frame.create tl ~borderwidth: 1 ~relief: `Raised in + let cfrm = Frame.create cfrm' ~borderwidth: 8 in + let dumf = Frame.create cfrm in + let dumf2 = Frame.create cfrm in + + let configure filter = + (* OLDER let curdir = getcwd () in *) +(* Printf.eprintf "CURDIR %s\n" curdir; *) + let filter = + if string_match (regexp "^/.*") filter 0 then filter + else + if filter = "" then !global_dir ^ "/*" + else !global_dir ^ "/" ^ filter in +(* Printf.eprintf "FILTER %s\n" filter; *) + let dirname, patternname = parse_filter filter in +(* Printf.eprintf "DIRNAME %s PATTERNNAME %s\n" dirname patternname; *) + current_dir := dirname; + global_dir := dirname; + let patternname = if patternname = "" then "*" else patternname in + current_pattern := patternname; + let filter = dirname ^ patternname in +(* Printf.eprintf "FILTER : %s\n\n" filter; *) +(* flush Pervasives.stderr; *) + try + let directories = get_directories_in_files dirname + (get_files_in_directory dirname) in + (* get matched file by subshell call. *) + let matched_files = remove_directories dirname (ls dirname patternname) + in + Textvariable.set filter_var filter; + Textvariable.set selection_var (dirname ^ deffile); + Listbox.delete directory_listbox ~first:(`Num 0) ~last:`End; + Listbox.insert directory_listbox ~index:`End ~texts:directories; + Listbox.delete filter_listbox ~first:(`Num 0) ~last:`End; + Listbox.insert filter_listbox ~index:`End ~texts:matched_files; + !directory_init_completion directory_listbox; + !filter_init_completion filter_listbox + with + Unix_error (ENOENT,_,_) -> + (* Directory is not found (maybe) *) + Bell.ring () + in + + let selected_files = ref [] in (* used for synchronous mode *) + let activate l () = + Grab.release tl; + destroy tl; + if sync then + begin + selected_files := l; + Textvariable.set sync_var "1" + end + else + begin + proc l; + break () + end + in + + (* and buttons *) + let okb = Button.create cfrm ~text: "OK" ~command: + begin fun () -> + let files = + List.map (Listbox.curselection filter_listbox) + ~f:(fun x -> !current_dir ^ (Listbox.get filter_listbox ~index:x)) + in + let files = if files = [] then [Textvariable.get selection_var] + else files in + activate files () + end + in + let flb = Button.create cfrm ~text: "Filter" + ~command: (fun () -> configure (Textvariable.get filter_var)) in + let ccb = Button.create cfrm ~text: "Cancel" + ~command: (fun () -> activate [] ()) in + + (* binding *) + bind selection_entry ~events:[`KeyPressDetail "Return"] ~breakable:true + ~action:(fun _ -> activate [Textvariable.get selection_var] ()); + bind filter_entry ~events:[`KeyPressDetail "Return"] + ~action:(fun _ -> configure (Textvariable.get filter_var)); + + let action _ = + let files = + List.map (Listbox.curselection filter_listbox) + ~f:(fun x -> !current_dir ^ (Listbox.get filter_listbox ~index:x)) + in + activate files () + in + bind filter_listbox ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~breakable:true ~action; + if multi then Listbox.configure filter_listbox ~selectmode: `Multiple; + filter_init_completion := add_completion filter_listbox action; + + let action _ = + try + configure (!current_dir ^ ((function + [x] -> Listbox.get directory_listbox ~index:x + | _ -> (* you must choose at least one directory. *) + Bell.ring (); raise Not_selected) + (Listbox.curselection directory_listbox)) ^ "/" ^ !current_pattern) + with _ -> () in + bind directory_listbox ~events:[`Modified([`Double], `ButtonPressDetail 1)] + ~breakable:true ~action; + Listbox.configure directory_listbox ~selectmode: `Browse; + directory_init_completion := add_completion directory_listbox action; + + pack [frm'; frm] ~fill: `X; + (* filter *) + pack [fl] ~side: `Top ~anchor: `W; + pack [filter_entry] ~side: `Top ~fill: `X; + (* directory + files *) + pack [df] ~side: `Top ~fill: `X ~ipadx: 8; + (* directory *) + pack [dfl] ~side: `Left; + pack [dfll] ~side: `Top ~anchor: `W; + pack [dflf] ~side: `Top; + pack [coe directory_listbox; coe directory_scrollbar] + ~side: `Left ~fill: `Y; + (* files *) + pack [dfr] ~side: `Right; + pack [dfrl] ~side: `Top ~anchor: `W; + pack [dfrf] ~side: `Top; + pack [coe filter_listbox; coe filter_scrollbar] ~side: `Left ~fill: `Y; + (* selection *) + pack [sl] ~side: `Top ~anchor: `W; + pack [selection_entry] ~side: `Top ~fill: `X; + + (* create OK, Filter and Cancel buttons *) + pack [cfrm'] ~fill: `X; + pack [cfrm] ~fill: `X; + pack [okb] ~side: `Left; + pack [dumf] ~side: `Left ~expand: true; + pack [flb] ~side: `Left; + pack [dumf2] ~side: `Left ~expand: true; + pack [ccb] ~side: `Left; + + configure deffilter; + + Tkwait.visibility tl; + Grab.set tl; + + if sync then + begin + Tkwait.variable sync_var; + proc !selected_files + end; + () diff --git a/otherlibs/labltk/jpf/fileselect.mli b/otherlibs/labltk/jpf/fileselect.mli new file mode 100644 index 0000000..b104e28 --- /dev/null +++ b/otherlibs/labltk/jpf/fileselect.mli @@ -0,0 +1,37 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: fileselect.mli,v 1.7 2002-04-26 12:16:12 furuse Exp $ *) + +(* This file selecter works only under the OS with the full unix support. + For the portability, Tk.getOpenFile and Tk.getSaveFile are recommended. *) + +open Support + +val f : + title:string -> + action:(string list -> unit) -> + filter:string -> file:string -> multi:bool -> sync:bool -> unit + +(* action + [] means canceled + if multi select is false, then the list is null or a singleton *) + +(* multi select + if true then more than one file are selectable *) + +(* sync it + if true then in synchronous mode *) diff --git a/otherlibs/labltk/jpf/jpf_font.ml b/otherlibs/labltk/jpf/jpf_font.ml new file mode 100644 index 0000000..c9c3d05 --- /dev/null +++ b/otherlibs/labltk/jpf/jpf_font.ml @@ -0,0 +1,218 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +(* find font information *) + +let debug = ref false +let log s = + if !debug then try prerr_endline s with _ -> () + +type ('s, 'i) xlfd = { + (* some of them are currently not interesting for me *) + mutable foundry: 's; + mutable family: 's; + mutable weight: 's; + mutable slant: 's; + mutable setWidth: 's; + mutable addStyle: 's; + mutable pixelSize: 'i; + mutable pointSize: 'i; + mutable resolutionX: 'i; + mutable resolutionY: 'i; + mutable spacing: 's; + mutable averageWidth: 'i; + mutable registry: 's; + mutable encoding: 's + } + +let copy xlfd = {xlfd with foundry= xlfd.foundry} + +let string_of_xlfd s i xlfd = + let foundry= s xlfd.foundry + and family= s xlfd.family + and weight= s xlfd.weight + and slant= s xlfd.slant + and setWidth = s xlfd.setWidth + and addStyle = s xlfd.addStyle + and pixelSize= i xlfd.pixelSize + and pointSize = i xlfd.pointSize + and resolutionX = i xlfd.resolutionX + and resolutionY = i xlfd.resolutionY + and spacing= s xlfd.spacing + and averageWidth = i xlfd.averageWidth + and registry= s xlfd.registry + and encoding = s xlfd.encoding in + + "-"^foundry^ + "-"^family^ + "-"^weight^ + "-"^slant^ + "-"^setWidth ^ + "-"^addStyle ^ + "-"^pixelSize^ + "-"^pointSize ^ + "-"^resolutionX ^ + "-"^resolutionY ^ + "-"^spacing^ + "-"^averageWidth ^ + "-"^registry^ + "-"^encoding + +exception Parse_Xlfd_Failure of string + +let parse_xlfd xlfd_string = + (* this must not be a pattern *) + let split_str char_sep str = + let len = String.length str in + let rec split beg cur = + if cur >= len then [String.sub str beg (len - beg)] + else if char_sep (String.get str cur) + then + let nextw = succ cur in + (String.sub str beg (cur - beg)) + ::(split nextw nextw) + else split beg (succ cur) in + split 0 0 + in + match split_str (function '-' -> true | _ -> false) xlfd_string with + | [ _; foundry; family; weight; slant; setWidth; addStyle; pixelSize; + pointSize; resolutionX; resolutionY; spacing; averageWidth; + registry; encoding ] -> + { foundry= foundry; + family= family; + weight= weight; + slant= slant; + setWidth= setWidth; + addStyle= addStyle; + pixelSize= int_of_string pixelSize; + pointSize= int_of_string pointSize; + resolutionX= int_of_string resolutionX; + resolutionY= int_of_string resolutionY; + spacing= spacing; + averageWidth= int_of_string averageWidth; + registry= registry; + encoding= encoding; + } + | _ -> raise (Parse_Xlfd_Failure xlfd_string) + +type valid_xlfd = (string, int) xlfd + +let string_of_valid_xlfd = string_of_xlfd (fun x -> x) string_of_int + +type pattern = (string option, int option) xlfd + +let empty_pattern = + { foundry= None; + family= None; + weight= None; + slant= None; + setWidth= None; + addStyle= None; + pixelSize= None; + pointSize= None; + resolutionX= None; + resolutionY= None; + spacing= None; + averageWidth= None; + registry= None; + encoding= None; + } + +let string_of_pattern = + let pat f = function + Some x -> f x + | None -> "*" + in + let pat_string = pat (fun x -> x) in + let pat_int = pat string_of_int in + string_of_xlfd pat_string pat_int + +let is_vector_font xlfd = + (xlfd.pixelSize = 0 && xlfd.resolutionX = 0 && xlfd.resolutionY = 0) || + xlfd.spacing <> "c" + +let list_fonts dispname pattern = + let dispopt = match dispname with + None -> "" + | Some x -> "-display " ^ x + in + let result = List.map parse_xlfd + (Shell.subshell ("xlsfonts "^dispopt^" -fn "^string_of_pattern pattern)) + in + if result = [] then raise Not_found + else result + +let available_pixel_size_aux dispname pattern = + (* return available pixel size without font resizing *) + (* to obtain good result, *) + (* the pattern should contain as many information as possible *) + let pattern = copy pattern in + pattern.pixelSize <- None; + let xlfds = list_fonts dispname pattern in + let pxszs = Hashtbl.create 107 in + List.iter (fun xlfd -> + Hashtbl.add pxszs xlfd.pixelSize xlfd) xlfds; + pxszs + +let extract_size_font_hash tbl = + let keys = ref [] in + Hashtbl.iter (fun k _ -> + if not (List.mem k !keys) then keys := k :: !keys) tbl; + Sort.list (fun (k1,_) (k2,_) -> k1 < k2) + (List.map (fun k -> k, Hashtbl.find_all tbl k) !keys) + +let available_pixel_size dispname pattern = + let pxszs = available_pixel_size_aux dispname pattern in + extract_size_font_hash pxszs + +let nearest_pixel_size dispname vector_ok pattern = + (* find the font with the nearest pixel size *) + log ("\n*** "^string_of_pattern pattern); + let pxlsz = + match pattern.pixelSize with + None -> raise (Failure "invalid pixelSize pattern") + | Some x -> x + in + let tbl = available_pixel_size_aux dispname pattern in + let newtbl = Hashtbl.create 107 in + Hashtbl.iter (fun s xlfd -> + if vector_ok then + if s = 0 then begin + if is_vector_font xlfd then begin + log (Printf.sprintf "%s is vector" (string_of_valid_xlfd xlfd)); + xlfd.pixelSize <- pxlsz; + Hashtbl.add newtbl pxlsz xlfd + end + end else Hashtbl.add newtbl s xlfd + else if not (is_vector_font xlfd) && s <> 0 then + Hashtbl.add newtbl s xlfd) tbl; + + let size_font_table = extract_size_font_hash newtbl in + + let diff = ref 10000 in + let min = ref None in + List.iter (fun (s,xlfds) -> + let d = abs(s - pxlsz) in + if d < !diff then begin + min := Some (s,xlfds); + diff := d + end) size_font_table; + (* if it contains more than one font, just return the first *) + match !min with + | None -> raise Not_found + | Some(s, xlfds) -> + log (Printf.sprintf "Size %d is selected" s); + List.iter (fun xlfd -> log (string_of_valid_xlfd xlfd)) xlfds; + List.hd xlfds diff --git a/otherlibs/labltk/jpf/jpf_font.mli b/otherlibs/labltk/jpf/jpf_font.mli new file mode 100644 index 0000000..cd1e212 --- /dev/null +++ b/otherlibs/labltk/jpf/jpf_font.mli @@ -0,0 +1,54 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val debug : bool ref + +type ('a, 'b) xlfd = + { mutable foundry: 'a; + mutable family: 'a; + mutable weight: 'a; + mutable slant: 'a; + mutable setWidth: 'a; + mutable addStyle: 'a; + mutable pixelSize: 'b; + mutable pointSize: 'b; + mutable resolutionX: 'b; + mutable resolutionY: 'b; + mutable spacing: 'a; + mutable averageWidth: 'b; + mutable registry: 'a; + mutable encoding: 'a } + +exception Parse_Xlfd_Failure of string + +type valid_xlfd = (string, int) xlfd +type pattern = (string option, int option) xlfd + +val empty_pattern : pattern + +val copy : ('a, 'b) xlfd -> ('a, 'b) xlfd + +val string_of_valid_xlfd : valid_xlfd -> string +val string_of_pattern : pattern -> string + +val is_vector_font : valid_xlfd -> bool + +val list_fonts : string option -> pattern -> valid_xlfd list + +val available_pixel_size : + string option -> pattern -> (int * valid_xlfd list) list + +val nearest_pixel_size : + string option -> bool -> pattern -> valid_xlfd diff --git a/otherlibs/labltk/jpf/jpflib.mllib b/otherlibs/labltk/jpf/jpflib.mllib new file mode 100644 index 0000000..6a04d14 --- /dev/null +++ b/otherlibs/labltk/jpf/jpflib.mllib @@ -0,0 +1 @@ +Fileselect Balloon Shell Jpf_font diff --git a/otherlibs/labltk/jpf/shell.ml b/otherlibs/labltk/jpf/shell.ml new file mode 100644 index 0000000..03e69e4 --- /dev/null +++ b/otherlibs/labltk/jpf/shell.ml @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Unix + +(************************************************************* Subshell call *) + +let subshell cmd = + let r,w = pipe () in + match fork () with + 0 -> close r; dup2 w stdout; + close stderr; + execv "/bin/sh" [| "/bin/sh"; "-c"; cmd |] + | id -> + close w; + let rc = in_channel_of_descr r in + let rec it () = try + let x = input_line rc in x:: it () + with _ -> [] + in + let answer = it() in + close_in rc; (* because of finalize_channel *) + let _ = waitpid [] id in answer + diff --git a/otherlibs/labltk/jpf/shell.mli b/otherlibs/labltk/jpf/shell.mli new file mode 100644 index 0000000..be93f5f --- /dev/null +++ b/otherlibs/labltk/jpf/shell.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +val subshell : string -> string list + diff --git a/otherlibs/labltk/labl.gif b/otherlibs/labltk/labl.gif new file mode 100644 index 0000000000000000000000000000000000000000..d0a29fab1d0f58c94935caaaf65aa77023053344 GIT binary patch literal 1533 zcmcJM|5K880LMSi!{Z|&=0k!$e#sCYn;My(xX@S=g-GjZFn#)B(4><yOKw=Yvs)Ar zBARk$YF3LQQYvpF^UA*6JWvx?tt>68d0Fd=x7wC#-O81+`Xl!G;r-L=?)}3{ma|-# zu1*I@U=RRrzqhxy*XFRb9%}8m*i%taVQsR0prTBx-%;UmxokF@-l$h8MAix^DdtPX zQnS&lqDXU@)LBPPbgML!KqM5AIV827a&|hkB^s@ow3dm+T&js4O-~a^ks|L^uUT)_ zlxWO#W-5p8bx;**!OOp2`ri2{l5};uG-}Fblv1R0a&nSVP(3|8H#$`+l0Wv#SZiym z%SujO)TmUdH}Bq9%~rEk)NA|T3MOAns?;iyByD=BM!_E&8FM<FA^{;t7U;E7empVp zctTsI)vgygt&~P3ZPiO}+_=HU*se|&lg^Baiqh-#1VKnegh(V%Q7VmE<Mnze1*t93 z_FnAOYPH~hCT1FeK3?!Y&c`Oe-)8{EJpeM*SZeF`)>~kjxuLqLxdrh<_w7ae=>d$E zqjiByq#lC(g60HcET`i%V4OOP&JAI6Lc{Rzz(d_lG`}uOL}b*w==t0j1}_#T;J)U- zIFAuJu;3HU{OEXQLSh0!EM)TUSP+I8L6Q6DqR^!I|0XTwCHfKz=|foThD%};$D7JB z4NNGINi-Waq345BH{<dCQ(pzqM!07K3*BZegz}mj@yEv6$kf-5-VVpef(#iMPRs-P z(V#zgp}E4WVXMEW{HOQB{WU1(bK$dV(=VeMxgBQ|j<iCt>69_qju|)6>3WX5)WR?T zR%fE`;d87lW`%RzD;!@ZA8^x=1tvV*2n7hS#b98D1=!3^osU(EnUG`!RD^FC-`{T{ z2wc$iNWB8FmZ`CLo?|>1&YgX_3M!<T<LuwF?z-Cp8nD%s`IX&puD4S{KOfg*Fq!Ai z+a1qkwYPTBLlUpqhx_~MQ5x6l_cq%E=b=fZl}ne|tGFqW!A)+{!QNm|fqMn?qh5wL zEYeBXfkT`yHfx~p;F`UN+>NYE>o73VR@^*PI{R}6K=Rn!meps)jbLd@GI!ix*j^3F z6EKf)LtcZ7VxaQV8;f)^c1V0Dg=Yx<VqE57)a_fc5}ckcUhP8^!kVJ`S$+P&oprcd zvPxK)nT`C~aR&#(m)o*9Yv_O*KT~mGzkqnsIs``zy!M2IV^wNd#^}@>_K6O+ffMrV z!emXx(d}z_%wa5VIouW-tz2aDJ_sh{DKXoczR9@_`z6y2Ez#}LzFiP9b@xd3jE-P_ z&M%YfJL$Tw2?}R-SQ1l(*_o@0jkQOWz)^1EAoh&010~O=qH8S<U7v8~a?5w{&Yt7_ zO2F?Dql(PJ<5jo1-7q`7*5En%^(LKPXxH`4(a@3^IW1?sQir7FtW&#B?xW(2CwFam z^xLO!qYk3Y+6(poW_>1%gekG?1j(oY@}UgjKU=?j+GX&-&5ikEaL%AK7F|Q!yb21p z5q+!&olZ}6Zl@gyh-ChLoz6%co=9&S0tS?URYd?<k=wBs$zOPk5jX(y`3yGj%mup9 z$xFw1KL|1tO3Q3>8*fHbr9u46EGDa~rufvY_2R5EK6i3pTSj{qE$kX2`%9*>@qM{6 zZOCqbWQ}|Fm*!#*gMkv)4RiU)@`Lb+DpCR|20*r%`fDw~GQ376N<R?079<=F(8wZ< zqUo5Dykhsc$F~7AxOv%UVF5?3+bm43MlLzCt4Y4cHtKNpgOu|LA|Agh2gpE@eq&I& zxXN>HB-J4<2*c|$x0jDgIAZj*Y4;Tv3D=Dr+3^Bgc=G4Uxj<7OIw#DJ<W_~fDz1g! x5?h7$<Y{!g`~K+$CHsmY3%7*R>R09JkJ;mR?&`(mkSc;*4Tpl@Tm%M7{{yv~E$RRO literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/labltk/.cvsignore b/otherlibs/labltk/labltk/.cvsignore new file mode 100644 index 0000000..5850676 --- /dev/null +++ b/otherlibs/labltk/labltk/.cvsignore @@ -0,0 +1,3 @@ +*.ml *.mli labltktop labltk +modules +.depend diff --git a/otherlibs/labltk/labltk/Makefile b/otherlibs/labltk/labltk/Makefile new file mode 100644 index 0000000..f678954 --- /dev/null +++ b/otherlibs/labltk/labltk/Makefile @@ -0,0 +1,43 @@ +include ../support/Makefile.common + +COMPFLAGS= -I ../support -I $(OTHERS)/win32unix -I $(OTHERS)/unix + +all: labltkobjs + +opt: labltkobjsx + +include ./modules + +LABLTKOBJS = $(WIDGETOBJS) tk.cmo labltk.cmo +LABLTKOBJSX = $(LABLTKOBJS:.cmo=.cmx) + +labltkobjs: $(LABLTKOBJS) + +labltkobjsx: $(LABLTKOBJSX) + +install: + if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(LABLTKOBJS:.cmo=.cmi) $(WIDGETOBJS:.cmo=.mli) $(INSTALLDIR) + chmod 644 $(INSTALLDIR)/*.cmi + +installopt: + @if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(LABLTKOBJSX) $(INSTALLDIR) + chmod 644 $(INSTALLDIR)/*.cmx + +clean: + $(MAKE) -f Makefile.gen clean + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmx .cmo .mlp + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +include .depend diff --git a/otherlibs/labltk/labltk/Makefile.gen b/otherlibs/labltk/labltk/Makefile.gen new file mode 100644 index 0000000..d73bb34 --- /dev/null +++ b/otherlibs/labltk/labltk/Makefile.gen @@ -0,0 +1,52 @@ +include ../support/Makefile.common + +all: tk.ml labltk.ml .depend + +_tkgen.ml: ../Widgets.src ../compiler/tkcompiler$(EXE) + cd ..; $(CAMLRUNGEN) compiler/tkcompiler$(EXE) -outdir labltk + +# dependencies are broken: wouldn't work with gmake 3.77 + +#tk.ml labltk.ml .depend: generate + +tk.ml labltk.ml .depend: _tkgen.ml ../builtin/report.ml ../compiler/pp$(EXE) #../builtin/builtin_*.ml + (echo 'open StdLabels'; \ + echo 'open Widget'; \ + echo 'open Protocol'; \ + echo 'open Support'; \ + echo 'open Textvariable'; \ + cat ../builtin/report.ml; \ + cat ../builtin/builtin_*.ml; \ + cat _tkgen.ml; \ + echo ; \ + echo ; \ + echo 'module Tkintf = struct'; \ + cat ../builtin/builtini_*.ml; \ + cat _tkigen.ml; \ + echo 'end (* module Tkintf *)'; \ + echo ; \ + echo ; \ + echo 'open Tkintf' ;\ + echo ; \ + echo ; \ + cat ../builtin/builtinf_*.ml; \ + cat _tkfgen.ml; \ + echo ; \ + ) > _tk.ml + $(CAMLRUN) ../compiler/pp < _tk.ml > tk.ml + rm -f _tk.ml + $(CAMLDEP) -slash -I ../support [a-z]*.mli [a-z]*.ml > .depend + +../compiler/pp$(EXE): + cd ../compiler; $(MAKE) pp$(EXE) + +../compiler/tkcompiler$(EXE): + cd ../compiler; $(MAKE) tkcompiler$(EXE) + +# All .{ml,mli} files are generated in this directory +clean: + rm -f *.cm* *.ml *.mli *.$(O) *.$(A) .depend + +# rm -f modules + +.PHONY: all generate clean diff --git a/otherlibs/labltk/labltk/Makefile.gen.nt b/otherlibs/labltk/labltk/Makefile.gen.nt new file mode 100644 index 0000000..046b878 --- /dev/null +++ b/otherlibs/labltk/labltk/Makefile.gen.nt @@ -0,0 +1 @@ +include Makefile.gen diff --git a/otherlibs/labltk/labltk/Makefile.nt b/otherlibs/labltk/labltk/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/labltk/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/labltk/byte.itarget b/otherlibs/labltk/labltk/byte.itarget new file mode 100644 index 0000000..1f061ac --- /dev/null +++ b/otherlibs/labltk/labltk/byte.itarget @@ -0,0 +1,8 @@ +place.cmo wm.cmo imagephoto.cmo canvas.cmo button.cmo text.cmo label.cmo +scrollbar.cmo image.cmo encoding.cmo pixmap.cmo palette.cmo font.cmo +message.cmo menu.cmo entry.cmo listbox.cmo focus.cmo menubutton.cmo pack.cmo +option.cmo toplevel.cmo frame.cmo dialog.cmo imagebitmap.cmo clipboard.cmo +radiobutton.cmo tkwait.cmo grab.cmo selection.cmo scale.cmo optionmenu.cmo +winfo.cmo grid.cmo checkbutton.cmo bell.cmo tkvars.cmo + +tk.cmo labltk.cmo diff --git a/otherlibs/labltk/labltk/modules b/otherlibs/labltk/labltk/modules new file mode 100644 index 0000000..a17b6ab --- /dev/null +++ b/otherlibs/labltk/labltk/modules @@ -0,0 +1,77 @@ +WIDGETOBJS=place.cmo wm.cmo imagephoto.cmo canvas.cmo button.cmo text.cmo label.cmo scrollbar.cmo image.cmo encoding.cmo pixmap.cmo palette.cmo font.cmo message.cmo menu.cmo entry.cmo listbox.cmo focus.cmo menubutton.cmo pack.cmo option.cmo toplevel.cmo frame.cmo dialog.cmo imagebitmap.cmo clipboard.cmo radiobutton.cmo tkwait.cmo grab.cmo selection.cmo scale.cmo optionmenu.cmo winfo.cmo grid.cmo checkbutton.cmo bell.cmo tkvars.cmo +place.ml wm.ml imagephoto.ml canvas.ml button.ml text.ml label.ml scrollbar.ml image.ml encoding.ml pixmap.ml palette.ml font.ml message.ml menu.ml entry.ml listbox.ml focus.ml menubutton.ml pack.ml option.ml toplevel.ml frame.ml dialog.ml imagebitmap.ml clipboard.ml radiobutton.ml tkwait.ml grab.ml selection.ml scale.ml optionmenu.ml winfo.ml grid.ml checkbutton.ml bell.ml tkvars.ml : _tkgen.ml + +place.cmo : place.ml +place.cmi : place.mli +wm.cmo : wm.ml +wm.cmi : wm.mli +imagephoto.cmo : imagephoto.ml +imagephoto.cmi : imagephoto.mli +canvas.cmo : canvas.ml +canvas.cmi : canvas.mli +button.cmo : button.ml +button.cmi : button.mli +text.cmo : text.ml +text.cmi : text.mli +label.cmo : label.ml +label.cmi : label.mli +scrollbar.cmo : scrollbar.ml +scrollbar.cmi : scrollbar.mli +image.cmo : image.ml +image.cmi : image.mli +encoding.cmo : encoding.ml +encoding.cmi : encoding.mli +pixmap.cmo : pixmap.ml +pixmap.cmi : pixmap.mli +palette.cmo : palette.ml +palette.cmi : palette.mli +font.cmo : font.ml +font.cmi : font.mli +message.cmo : message.ml +message.cmi : message.mli +menu.cmo : menu.ml +menu.cmi : menu.mli +entry.cmo : entry.ml +entry.cmi : entry.mli +listbox.cmo : listbox.ml +listbox.cmi : listbox.mli +focus.cmo : focus.ml +focus.cmi : focus.mli +menubutton.cmo : menubutton.ml +menubutton.cmi : menubutton.mli +pack.cmo : pack.ml +pack.cmi : pack.mli +option.cmo : option.ml +option.cmi : option.mli +toplevel.cmo : toplevel.ml +toplevel.cmi : toplevel.mli +frame.cmo : frame.ml +frame.cmi : frame.mli +dialog.cmo : dialog.ml +dialog.cmi : dialog.mli +imagebitmap.cmo : imagebitmap.ml +imagebitmap.cmi : imagebitmap.mli +clipboard.cmo : clipboard.ml +clipboard.cmi : clipboard.mli +radiobutton.cmo : radiobutton.ml +radiobutton.cmi : radiobutton.mli +tkwait.cmo : tkwait.ml +tkwait.cmi : tkwait.mli +grab.cmo : grab.ml +grab.cmi : grab.mli +selection.cmo : selection.ml +selection.cmi : selection.mli +scale.cmo : scale.ml +scale.cmi : scale.mli +optionmenu.cmo : optionmenu.ml +optionmenu.cmi : optionmenu.mli +winfo.cmo : winfo.ml +winfo.cmi : winfo.mli +grid.cmo : grid.ml +grid.cmi : grid.mli +checkbutton.cmo : checkbutton.ml +checkbutton.cmi : checkbutton.mli +bell.cmo : bell.ml +bell.cmi : bell.mli +tkvars.cmo : tkvars.ml +tkvars.cmi : tkvars.mli diff --git a/otherlibs/labltk/labltk/native.itarget b/otherlibs/labltk/labltk/native.itarget new file mode 100644 index 0000000..4bdc92c --- /dev/null +++ b/otherlibs/labltk/labltk/native.itarget @@ -0,0 +1,6 @@ +place.cmx wm.cmx imagephoto.cmx canvas.cmx button.cmx text.cmx label.cmx +scrollbar.cmx image.cmx encoding.cmx pixmap.cmx palette.cmx font.cmx +message.cmx menu.cmx entry.cmx listbox.cmx focus.cmx menubutton.cmx pack.cmx +option.cmx toplevel.cmx frame.cmx dialog.cmx imagebitmap.cmx clipboard.cmx +radiobutton.cmx tkwait.cmx grab.cmx selection.cmx scale.cmx optionmenu.cmx +winfo.cmx grid.cmx checkbutton.cmx bell.cmx tkvars.cmx diff --git a/otherlibs/labltk/lib/.cvsignore b/otherlibs/labltk/lib/.cvsignore new file mode 100644 index 0000000..80df441 --- /dev/null +++ b/otherlibs/labltk/lib/.cvsignore @@ -0,0 +1,8 @@ +labltktop labltk mltktop mltk +.depend +*.ml +*.mli +modules +labltk.cma +labltk.cmxa + diff --git a/otherlibs/labltk/lib/Makefile b/otherlibs/labltk/lib/Makefile new file mode 100644 index 0000000..e2fe5f1 --- /dev/null +++ b/otherlibs/labltk/lib/Makefile @@ -0,0 +1,74 @@ +include ../support/Makefile.common + +all: $(LIBNAME).cma $(LIBNAME)top$(EXE) $(LIBNAME) + +opt: $(LIBNAME).cmxa + +clean: + rm -f $(LIBNAME)top$(EXE) $(LIBNAME) *.cm* *.$(A) + +superclean: + - if test -f tk.cmo; then \ + echo We have changes... Now lib directory has no .cmo files; \ + rm -f *.cm* *.$(O); \ + fi + +include ../labltk/modules +LABLTKOBJS=tk.cmo $(WIDGETOBJS) + +include ../camltk/modules +CAMLTKOBJS=cTk.cmo $(CWIDGETOBJS) labltk.cmo camltk.cmo + +SUPPORT=../support/support.cmo ../support/rawwidget.cmo \ + ../support/widget.cmo ../support/protocol.cmo \ + ../support/textvariable.cmo ../support/timer.cmo \ + ../support/fileevent.cmo ../support/camltkwrap.cmo + +TKOBJS=$(SUPPORT) $(LABLTKOBJS) $(CAMLTKOBJS) + +TOPDEPS = $(TOPDIR)/toplevel/toplevellib.cma $(TOPDIR)/toplevel/topmain.cmo + +$(LIBNAME).cma: $(SUPPORT) ../Widgets.src + $(MAKE) superclean + cd ../labltk; $(MAKE) + cd ../camltk; $(MAKE) + $(MKLIB) -ocamlc '$(CAMLC)' -o $(LIBNAME) \ + -I ../labltk -I ../camltk $(TKOBJS) \ + -ccopt "\"$(TK_LINK)\"" + +$(LIBNAME).cmxa: $(SUPPORT:.cmo=.cmx) ../Widgets.src + $(MAKE) superclean + cd ../labltk; $(MAKE) opt + cd ../camltk; $(MAKE) opt + $(MKLIB) -ocamlopt '$(CAMLOPT)' -o $(LIBNAME) -oc $(LIBNAME) \ + -I ../labltk -I ../camltk $(TKOBJS:.cmo=.cmx) \ + -ccopt "\"$(TK_LINK)\"" + +$(LIBNAME)top$(EXE) : $(TOPDEPS) $(LIBNAME).cma ../support/lib$(LIBNAME).$(A) + $(CAMLC) -verbose -linkall -o $(LIBNAME)top$(EXE) -I ../support \ + -I $(TOPDIR)/toplevel toplevellib.cma \ + -I $(OTHERS)/unix -I $(OTHERS)/win32unix unix.cma \ + -I ../labltk -I ../camltk $(LIBNAME).cma \ + -I $(OTHERS)/str str.cma \ + topstart.cmo + +$(LIBNAME): Makefile $(TOPDIR)/config/Makefile + @echo Generate $@ + @echo "#!/bin/sh" > $@ + @echo 'exec $(INSTALLDIR)/$(LIBNAME)top$(EXE) -I $(INSTALLDIR) $$*' >> $@ + +install: + if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(LIBNAME).cma $(LIBNAME)top$(EXE) $(INSTALLDIR) + chmod 644 $(INSTALLDIR)/$(LIBNAME).cma + chmod 755 $(INSTALLDIR)/$(LIBNAME)top$(EXE) + @if test -d $(BINDIR); then : ; else mkdir $(BINDIR); fi + cp $(LIBNAME) $(BINDIR) + chmod 755 $(BINDIR)/$(LIBNAME) + +installopt: + @if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(LIBNAME).cmxa $(LIBNAME).$(A) $(INSTALLDIR) + cd $(INSTALLDIR); $(RANLIB) $(LIBNAME).$(A) + chmod 644 $(INSTALLDIR)/$(LIBNAME).cmxa + chmod 644 $(INSTALLDIR)/$(LIBNAME).$(A) diff --git a/otherlibs/labltk/lib/Makefile.nt b/otherlibs/labltk/lib/Makefile.nt new file mode 100644 index 0000000..67bf904 --- /dev/null +++ b/otherlibs/labltk/lib/Makefile.nt @@ -0,0 +1 @@ +include Makefile \ No newline at end of file diff --git a/otherlibs/labltk/support/.depend b/otherlibs/labltk/support/.depend new file mode 100644 index 0000000..069735b --- /dev/null +++ b/otherlibs/labltk/support/.depend @@ -0,0 +1,27 @@ +camltkwrap.cmi: widget.cmi timer.cmi textvariable.cmi protocol.cmi +protocol.cmi: widget.cmi +textvariable.cmi: widget.cmi protocol.cmi +tkthread.cmi: widget.cmi +widget.cmi: rawwidget.cmi +camltkwrap.cmo: timer.cmi textvariable.cmi rawwidget.cmi protocol.cmi \ + fileevent.cmi camltkwrap.cmi +camltkwrap.cmx: timer.cmx textvariable.cmx rawwidget.cmx protocol.cmx \ + fileevent.cmx camltkwrap.cmi +fileevent.cmo: support.cmi protocol.cmi fileevent.cmi +fileevent.cmx: support.cmx protocol.cmx fileevent.cmi +protocol.cmo: widget.cmi support.cmi protocol.cmi +protocol.cmx: widget.cmx support.cmx protocol.cmi +rawwidget.cmo: support.cmi rawwidget.cmi +rawwidget.cmx: support.cmx rawwidget.cmi +slave.cmo: widget.cmi +slave.cmx: widget.cmx +support.cmo: support.cmi +support.cmx: support.cmi +textvariable.cmo: widget.cmi support.cmi protocol.cmi textvariable.cmi +textvariable.cmx: widget.cmx support.cmx protocol.cmx textvariable.cmi +timer.cmo: support.cmi protocol.cmi timer.cmi +timer.cmx: support.cmx protocol.cmx timer.cmi +tkthread.cmo: widget.cmi timer.cmi protocol.cmi tkthread.cmi +tkthread.cmx: widget.cmx timer.cmx protocol.cmx tkthread.cmi +widget.cmo: rawwidget.cmi widget.cmi +widget.cmx: rawwidget.cmx widget.cmi diff --git a/otherlibs/labltk/support/Makefile b/otherlibs/labltk/support/Makefile new file mode 100644 index 0000000..dd037a2 --- /dev/null +++ b/otherlibs/labltk/support/Makefile @@ -0,0 +1,75 @@ +include Makefile.common + +all: support.cmo rawwidget.cmo widget.cmo protocol.cmo \ + textvariable.cmo timer.cmo fileevent.cmo camltkwrap.cmo \ + tkthread.cmo lib$(LIBNAME).$(A) + +opt: support.cmx rawwidget.cmx widget.cmx protocol.cmx \ + textvariable.cmx timer.cmx fileevent.cmx camltkwrap.cmx \ + tkthread.cmx lib$(LIBNAME).$(A) + +COBJS=cltkCaml.$(O) cltkUtf.$(O) cltkEval.$(O) cltkEvent.$(O) \ + cltkFile.$(O) cltkMain.$(O) cltkMisc.$(O) cltkTimer.$(O) \ + cltkVar.$(O) cltkWait.$(O) cltkImg.$(O) + +CCFLAGS=-I../../../byterun $(TK_DEFS) $(SHAREDCCCOMPOPTS) + +COMPFLAGS=-I $(OTHERS)/win32unix -I $(OTHERS)/unix +THFLAGS=-I $(OTHERS)/systhreads -I $(OTHERS)/threads + +lib$(LIBNAME).$(A): $(COBJS) + $(MKLIB) -o $(LIBNAME) $(COBJS) -ldopt "$(TK_LINK)" + +PUBMLI=fileevent.mli protocol.mli textvariable.mli timer.mli \ + rawwidget.mli widget.mli +PUB= $(PUBMLI) $(PUBMLI:.mli=.cmi) tkthread.mli tkthread.cmi tkthread.cmo + +install: + if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(PUB) lib$(LIBNAME).$(A) $(INSTALLDIR) + cd $(INSTALLDIR); $(RANLIB) lib$(LIBNAME).$(A) + cd $(INSTALLDIR); chmod 644 $(PUB) lib$(LIBNAME).$(A) + if test -f dll$(LIBNAME)$(EXT_DLL); then \ + cp dll$(LIBNAME)$(EXT_DLL) $(STUBLIBDIR)/; fi + +installopt: + @if test -d $(INSTALLDIR); then : ; else mkdir $(INSTALLDIR); fi + cp $(PUBMLI:.mli=.cmx) $(INSTALLDIR) + if test -f tkthread.$(O); then \ + cp tkthread.cmx tkthread.$(O) $(INSTALLDIR); \ + chmod 644 $(INSTALLDIR)/tkthread.cmx $(INSTALLDIR)/tkthread.$(O); \ + fi + +clean: + rm -f *.cm* *.o *.a *.so *.obj *.lib *.dll *.exp + +.SUFFIXES: +.SUFFIXES: .mli .ml .cmi .cmo .cmx .mlp .c .$(O) + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.c.$(O): + $(BYTECC) $(BYTECCCOMPOPTS) $(CCFLAGS) -c $< + +tkthread.cmi: tkthread.mli + $(CAMLCOMP) $(COMPFLAGS) $(THFLAGS) $< +tkthread.cmo: tkthread.ml + $(CAMLCOMP) $(COMPFLAGS) $(THFLAGS) $< +tkthread.cmx: tkthread.ml + if test -f $(OTHERS)/systhreads/threads.cmxa; then \ + $(CAMLOPT) -c $(COMPFLAGS) $(THFLAGS) $< ; \ + fi + +depend: + $(CAMLDEP) *.mli *.ml > .depend + +$(COBJS): $(TOPDIR)/config/Makefile camltk.h + +include .depend diff --git a/otherlibs/labltk/support/Makefile.common b/otherlibs/labltk/support/Makefile.common new file mode 100644 index 0000000..2158048 --- /dev/null +++ b/otherlibs/labltk/support/Makefile.common @@ -0,0 +1,27 @@ +## Paths are relative to subdirectories +## Where you compiled Objective Caml +TOPDIR=../../.. +## Path to the otherlibs subdirectory +OTHERS=$(TOPDIR)/otherlibs + +LIBNAME=labltk + +include $(TOPDIR)/config/Makefile + +INSTALLDIR=$(LIBDIR)/$(LIBNAME) + +## Tools from the Objective Caml distribution + +CAMLRUN=$(TOPDIR)/boot/ocamlrun +CAMLC=$(CAMLRUN) $(TOPDIR)/ocamlc -nostdlib -I $(TOPDIR)/stdlib +CAMLOPT=$(CAMLRUN) $(TOPDIR)/ocamlopt -nostdlib -I $(TOPDIR)/stdlib +CAMLCOMP=$(CAMLC) -c -warn-error A +CAMLYACC=$(TOPDIR)/boot/ocamlyacc -v +CAMLLEX=$(CAMLRUN) $(TOPDIR)/boot/ocamllex +CAMLLIBR=$(CAMLC) -a +CAMLDEP=$(CAMLRUN) $(TOPDIR)/tools/ocamldep +COMPFLAGS=-g +LINKFLAGS= +CAMLOPTLIBR=$(CAMLOPT) -a +MKLIB=$(CAMLRUN) $(TOPDIR)/tools/ocamlmklib +CAMLRUNGEN=../../boot/ocamlrun diff --git a/otherlibs/labltk/support/Makefile.nt b/otherlibs/labltk/support/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/support/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/support/byte.itarget b/otherlibs/labltk/support/byte.itarget new file mode 100644 index 0000000..6f31e01 --- /dev/null +++ b/otherlibs/labltk/support/byte.itarget @@ -0,0 +1,3 @@ +support.cmo rawwidget.cmo widget.cmo protocol.cmo +textvariable.cmo timer.cmo fileevent.cmo camltkwrap.cmo +tkthread.cmo diff --git a/otherlibs/labltk/support/camltk.h b/otherlibs/labltk/support/camltk.h new file mode 100644 index 0000000..8776cb0 --- /dev/null +++ b/otherlibs/labltk/support/camltk.h @@ -0,0 +1,61 @@ +/*************************************************************************/ +/* */ +/* Objective Caml LablTk library */ +/* */ +/* Francois Rouaix, Francois Pessaux and Jun Furuse */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 1999 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file ../../../LICENSE. */ +/* */ +/*************************************************************************/ + +/* $Id: camltk.h,v 1.13 2008-09-26 07:35:24 garrigue Exp $ */ + +#if defined(_WIN32) && defined(CAML_DLL) && defined(IN_CAMLTKSUPPORT) +#define CAMLTKextern CAMLexport +#else +#define CAMLTKextern CAMLextern +#endif + +/* compatibility with earlier versions of Tcl/Tk */ +#ifndef CONST84 +#define CONST84 +#endif + +/* cltkMisc.c */ +/* copy a Caml string to the C heap. Must be deallocated with stat_free */ +extern char *string_to_c(value s); + +/* cltkUtf.c */ +extern value tcl_string_to_caml( char * ); +extern char * caml_string_to_tcl( value ); + +/* cltkEval.c */ +CAMLTKextern Tcl_Interp *cltclinterp; /* The Tcl interpretor */ +extern value copy_string_list(int argc, char **argv); + +/* cltkCaml.c */ +/* pointers to Caml values */ +extern value *tkerror_exn; +extern value *handler_code; +extern int CamlCBCmd(ClientData clientdata, Tcl_Interp *interp, + int argc, CONST84 char *argv[]); +CAMLTKextern void tk_error(char * errmsg) Noreturn; + +/* cltkMain.c */ +extern int signal_events; +extern void invoke_pending_caml_signals(ClientData clientdata); +extern Tk_Window cltk_mainWindow; +extern int cltk_slave_mode; + +/* check that initialisations took place */ +#define CheckInit() if (!cltclinterp) tk_error("Tcl/Tk not initialised") + +#define RCNAME ".camltkrc" +#define CAMLCB "camlcb" + diff --git a/otherlibs/labltk/support/camltkwrap.ml b/otherlibs/labltk/support/camltkwrap.ml new file mode 100644 index 0000000..5afe864 --- /dev/null +++ b/otherlibs/labltk/support/camltkwrap.ml @@ -0,0 +1,77 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +module Widget = struct + include Rawwidget + type widget = raw_any raw_widget + + let default_toplevel = coe default_toplevel +end + +module Protocol = struct + open Widget + include Protocol + + let opentk () = coe (opentk ()) + let opentk_with_args args = coe (opentk_with_args args) + let openTk ?display ?clas () = coe (openTk ?display ?clas ()) + + let cCAMLtoTKwidget table w = + Widget.check_class w table; (* we need run time type check of widgets *) + TkToken (Widget.name w) + + (* backward compatibility *) + let openTkClass s = coe (openTkClass s) + let openTkDisplayClass disp c = coe (openTkDisplayClass disp c) +end + +module Textvariable = struct + open Textvariable + type textVariable = Textvariable.textVariable + let create = create + let set = set + let get = get + let name = name + let cCAMLtoTKtextVariable = cCAMLtoTKtextVariable + let handle tv cbk = handle tv ~callback:cbk + let coerce = coerce + + (*-*) + let free = free + + (* backward compatibility *) + let create_temporary w = create ~on: w () +end + +module Fileevent = struct + open Fileevent + let add_fileinput fd callback = add_fileinput ~fd ~callback + let remove_fileinput fd = remove_fileinput ~fd + let add_fileoutput fd callback = add_fileoutput ~fd ~callback + let remove_fileoutput fd = remove_fileoutput ~fd +end + +module Timer = struct + open Timer + type t = Timer.t + let add ms callback = add ~ms ~callback + let set ms callback = set ~ms ~callback + let remove = remove +end + +(* +Not compiled in support +module Tkwait = Tkwait +*) diff --git a/otherlibs/labltk/support/camltkwrap.mli b/otherlibs/labltk/support/camltkwrap.mli new file mode 100644 index 0000000..9c9321c --- /dev/null +++ b/otherlibs/labltk/support/camltkwrap.mli @@ -0,0 +1,251 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +module Widget : sig + type widget = Widget.any Widget.widget + (* widget is an abstract type *) + + val default_toplevel : widget + (* [default_toplevel] is "." in Tk, the toplevel widget that is + always existing during a Tk session. Destroying [default_toplevel] + ends the main loop + *) + + val atom : parent: widget -> name: string -> widget + (* [atom parent name] returns the widget [parent.name]. The widget is + not created. Only its name is returned. In a given parent, there may + only exist one children for a given name. + This function should only be used to check the existence of a widget + with a known name. It doesn't add the widget to the internal tables + of CamlTk. + *) + + val name : widget -> string + (* [name w] returns the name (tk "path") of a widget *) + + (*--*) + (* The following functions are used internally. + There is normally no need for them in users programs + *) + + val known_class : widget -> string + (* [known_class w] returns the class of a widget (e.g. toplevel, frame), + as known by the CamlTk interface. + Not equivalent to "winfo w" in Tk. + *) + + val dummy : widget + (* [dummy] is a widget used as context when we don't have any. + It is *not* a real widget. + *) + + val new_atom : parent: widget -> ?name: string -> string -> widget + (* incompatible with the classic camltk *) + + val get_atom : string -> widget + (* [get_atom path] returns the widget with Tk path [path] *) + + val remove : widget -> unit + (* [remove w] removes widget from the internal tables *) + + (* Subtypes tables *) + val widget_any_table : string list + val widget_button_table : string list + val widget_canvas_table : string list + val widget_checkbutton_table : string list + val widget_entry_table : string list + val widget_frame_table : string list + val widget_label_table : string list + val widget_listbox_table : string list + val widget_menu_table : string list + val widget_menubutton_table : string list + val widget_message_table : string list + val widget_radiobutton_table : string list + val widget_scale_table : string list + val widget_scrollbar_table : string list + val widget_text_table : string list + val widget_toplevel_table : string list + + val chk_sub : string -> 'a list -> 'a -> unit + val check_class : widget -> string list -> unit + (* Widget subtyping *) + + exception IllegalWidgetType of string + (* Raised when widget command applied illegally*) + + (* this function is not used, but introduced for the compatibility + with labltk. useless for camltk users *) + val coe : 'a Widget.widget -> Widget.any Widget.widget +end + +module Protocol : sig + open Widget + + (* Lower level interface *) + exception TkError of string + (* Raised by the communication functions *) + + val debug : bool ref + (* When set to true, displays approximation of intermediate Tcl code *) + + type tkArgs = + TkToken of string + | TkTokenList of tkArgs list (* to be expanded *) + | TkQuote of tkArgs (* mapped to Tcl list *) + + + (* Misc *) + external splitlist : string -> string list + = "camltk_splitlist" + + val add_destroy_hook : (widget -> unit) -> unit + + + (* Opening, closing, and mainloop *) + val default_display : unit -> string + + val opentk : unit -> widget + (* The basic initialization function. [opentk ()] parses automatically + the command line options and use the tk related options in them + such as "-display localhost:0" to initialize Tk applications. + Consult wish manpage about the supported options. *) + + val keywords : (string * Arg.spec * string) list + (* Command line parsing specification for Arg.parse, which contains + the standard Tcl/Tk command line options such as "-display" and "-name". + These Tk command line options are used by opentk *) + + val opentk_with_args : string list -> widget + (* [opentk_with_args argv] invokes [opentk] with the tk related + command line options given by [argv] to the executable program. *) + + val openTk : ?display:string -> ?clas:string -> unit -> widget + (* [openTk ~display:display ~clas:clas ()] is equivalent to + [opentk ["-display"; display; "-name"; clas]] *) + + (* Legacy opentk functions *) + val openTkClass: string -> widget + (* [openTkClass class] is equivalent to [opentk ["-name"; class]] *) + val openTkDisplayClass: string -> string -> widget + (* [openTkDisplayClass disp class] is equivalent to + [opentk ["-display"; disp; "-name"; class]] *) + + val closeTk : unit -> unit + val finalizeTk : unit -> unit + (* Finalize tcl/tk before exiting. This function will be automatically + called when you call [Pervasives.exit ()] *) + + val mainLoop : unit -> unit + + + (* Direct evaluation of tcl code *) + val tkEval : tkArgs array -> string + + val tkCommand : tkArgs array -> unit + + (* Returning a value from a Tcl callback *) + val tkreturn: string -> unit + + + (* Callbacks: this is private *) + + type cbid = Protocol.cbid + + type callback_buffer = string list + (* Buffer for reading callback arguments *) + + val callback_naming_table : (cbid, callback_buffer -> unit) Hashtbl.t + (* CAMLTK val callback_memo_table : (widget, cbid) Hashtbl.t *) + val callback_memo_table : (widget, cbid) Hashtbl.t + (* Exported for debug purposes only. Don't use them unless you + know what you are doing *) + val new_function_id : unit -> cbid + val string_of_cbid : cbid -> string + val register_callback : widget -> callback:(callback_buffer -> unit) -> string + (* Callback support *) + val clear_callback : cbid -> unit + (* Remove a given callback from the table *) + val remove_callbacks : widget -> unit + (* Clean up callbacks associated to widget. Must be used only when + the Destroy event is bind by the user and masks the default + Destroy event binding *) + + val cTKtoCAMLwidget : string -> widget + val cCAMLtoTKwidget : string list -> widget -> tkArgs + + val register : string -> callback:(callback_buffer -> unit) -> unit + + (*-*) + val prerr_cbid : cbid -> unit +end + +module Textvariable : sig + open Widget + open Protocol + + type textVariable = Textvariable.textVariable + (* TextVariable is an abstract type *) + + val create : ?on: widget -> unit -> textVariable + (* Allocation of a textVariable with lifetime associated to widget + if a widget is specified *) + val create_temporary : widget -> textVariable + (* for backward compatibility + [create_temporary w] is equivalent to [create ~on:w ()] *) + + val set : textVariable -> string -> unit + (* Setting the val of a textVariable *) + val get : textVariable -> string + (* Reading the val of a textVariable *) + val name : textVariable -> string + (* Its tcl name *) + + val cCAMLtoTKtextVariable : textVariable -> tkArgs + (* Internal conversion function *) + + val handle : textVariable -> (unit -> unit) -> unit + (* Callbacks on variable modifications *) + + val coerce : string -> textVariable + + (*-*) + val free : textVariable -> unit +end + +module Fileevent : sig + open Unix + + val add_fileinput : file_descr -> (unit -> unit) -> unit + val remove_fileinput: file_descr -> unit + val add_fileoutput : file_descr -> (unit -> unit) -> unit + val remove_fileoutput: file_descr -> unit + (* see [tk] module *) +end + +module Timer : sig + type t = Timer.t + + val add : int -> (unit -> unit) -> t + val set : int -> (unit -> unit) -> unit + val remove : t -> unit +end + +(* +Tkwait exists, but is not used in support +module Tkwait : sig + val internal_tracevis : string -> string -> unit + val internal_tracedestroy : string -> string -> unit +end +*) diff --git a/otherlibs/labltk/support/cltkCaml.c b/otherlibs/labltk/support/cltkCaml.c new file mode 100644 index 0000000..636402a --- /dev/null +++ b/otherlibs/labltk/support/cltkCaml.c @@ -0,0 +1,85 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkCaml.c,v 1.10 2008-09-26 07:35:24 garrigue Exp $ */ + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <alloc.h> +#include <callback.h> +#include <fail.h> +#include "camltk.h" + +value * tkerror_exn = NULL; +value * handler_code = NULL; + +/* The Tcl command for evaluating callback in Caml */ +int CamlCBCmd(ClientData clientdata, Tcl_Interp *interp, + int argc, CONST84 char **argv) +{ + CheckInit(); + + /* Assumes no result */ + Tcl_SetResult(interp, NULL, NULL); + if (argc >= 2) { + int id; + if (Tcl_GetInt(interp, argv[1], &id) != TCL_OK) + return TCL_ERROR; + callback2(*handler_code,Val_int(id), + copy_string_list(argc - 2,(char **)&argv[2])); + /* Never fails (Caml would have raised an exception) */ + /* but result may have been set by callback */ + return TCL_OK; + } + else + return TCL_ERROR; +} + +/* Callbacks are always of type _ -> unit, to simplify storage + * But a callback can nevertheless return something (to Tcl) by + * using the following. TCL_VOLATILE ensures that Tcl will make + * a copy of the string + */ +CAMLprim value camltk_return (value v) +{ + CheckInit(); + + Tcl_SetResult(cltclinterp, String_val(v), TCL_VOLATILE); + return Val_unit; +} + +/* Note: raise_with_string WILL copy the error message */ +CAMLprim void tk_error(char *errmsg) +{ + raise_with_string(*tkerror_exn, errmsg); +} + + +/* The initialisation of the C global variables pointing to Caml values + must be made accessible from Caml, so that we are sure that it *always* + takes place during loading of the protocol module + */ + +CAMLprim value camltk_init(value v) +{ + /* Initialize the Caml pointers */ + if (tkerror_exn == NULL) + tkerror_exn = caml_named_value("tkerror"); + if (handler_code == NULL) + handler_code = caml_named_value("camlcb"); + return Val_unit; +} diff --git a/otherlibs/labltk/support/cltkDMain.c b/otherlibs/labltk/support/cltkDMain.c new file mode 100644 index 0000000..f5a729c --- /dev/null +++ b/otherlibs/labltk/support/cltkDMain.c @@ -0,0 +1,247 @@ +/*************************************************************************/ +/* */ +/* Objective Caml LablTk library */ +/* */ +/* Francois Rouaix, Francois Pessaux and Jun Furuse */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 1999 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file ../../../LICENSE. */ +/* */ +/*************************************************************************/ + +/* $Id: cltkDMain.c,v 1.7 2008-07-01 09:55:52 weis Exp $ */ + +#include <unistd.h> +#include <fcntl.h> +#include <tcl.h> +#include <tk.h> +#include "gc.h" +#include "exec.h" +#include "sys.h" +#include "fail.h" +#include "io.h" +#include "mlvalues.h" +#include "memory.h" +#include "camltk.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + + +/* + * Dealing with signals: when a signal handler is defined in Caml, + * the actual execution of the signal handler upon reception of the + * signal is delayed until we are sure we are out of the GC. + * If a signal occurs during the MainLoop, we would have to wait + * the next event for the handler to be invoked. + * The following function will invoke a pending signal handler if any, + * and we put in on a regular timer. + */ + +#define SIGNAL_INTERVAL 300 + +int signal_events = 0; /* do we have a pending timer */ + +void invoke_pending_caml_signals (clientdata) + ClientData clientdata; +{ + signal_events = 0; + enter_blocking_section(); /* triggers signal handling */ + /* Rearm timer */ + Tk_CreateTimerHandler(SIGNAL_INTERVAL, invoke_pending_caml_signals, NULL); + signal_events = 1; + leave_blocking_section(); +} +/* The following is taken from byterun/startup.c */ +header_t atom_table[256]; +code_t start_code; +asize_t code_size; + +static void init_atoms() +{ + int i; + for(i = 0; i < 256; i++) atom_table[i] = Make_header(0, i, White); +} + +static unsigned long read_size(p) + unsigned char * p; +{ + return ((unsigned long) p[0] << 24) + ((unsigned long) p[1] << 16) + + ((unsigned long) p[2] << 8) + p[3]; +} + +#define FILE_NOT_FOUND (-1) +#define TRUNCATED_FILE (-2) +#define BAD_MAGIC_NUM (-3) + +static int read_trailer(fd, trail) + int fd; + struct exec_trailer * trail; +{ + char buffer[TRAILER_SIZE]; + + lseek(fd, (long) -TRAILER_SIZE, 2); + if (read(fd, buffer, TRAILER_SIZE) < TRAILER_SIZE) return TRUNCATED_FILE; + trail->code_size = read_size(buffer); + trail->data_size = read_size(buffer+4); + trail->symbol_size = read_size(buffer+8); + trail->debug_size = read_size(buffer+12); + if (strncmp(buffer + 16, EXEC_MAGIC, 12) == 0) + return 0; + else + return BAD_MAGIC_NUM; +} + +int attempt_open(name, trail, do_open_script) + char ** name; + struct exec_trailer * trail; + int do_open_script; +{ + char * truename; + int fd; + int err; + char buf [2]; + + truename = searchpath(*name); + if (truename == 0) truename = *name; else *name = truename; + fd = open(truename, O_RDONLY | O_BINARY); + if (fd == -1) return FILE_NOT_FOUND; + if (!do_open_script){ + err = read (fd, buf, 2); + if (err < 2) { close(fd); return TRUNCATED_FILE; } + if (buf [0] == '#' && buf [1] == '!') { close(fd); return BAD_MAGIC_NUM; } + } + err = read_trailer(fd, trail); + if (err != 0) { close(fd); return err; } + return fd; +} + + +/* Command for loading the bytecode file */ +int CamlRunCmd(dummy, interp, argc, argv) + ClientData dummy; /* Not used. */ + Tcl_Interp *interp; /* Current interpreter. */ + int argc; /* Number of arguments. */ + char **argv; /* Argument strings. */ +{ + int fd; + struct exec_trailer trail; + struct longjmp_buffer raise_buf; + struct channel * chan; + + if (argc < 2) { + Tcl_AppendResult(interp, "wrong # args: should be \"", + argv[0], " foo.cmo args\"", (char *) NULL); + return TCL_ERROR; + } + fd = attempt_open(&argv[1], &trail, 1); + + switch(fd) { + case FILE_NOT_FOUND: + fatal_error_arg("Fatal error: cannot find file %s\n", argv[1]); + break; + case TRUNCATED_FILE: + case BAD_MAGIC_NUM: + fatal_error_arg( + "Fatal error: the file %s is not a bytecode executable file\n", + argv[1]); + break; + } + + if (sigsetjmp(raise_buf.buf, 1) == 0) { + + external_raise = &raise_buf; + + lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size + + trail.symbol_size + trail.debug_size), 2); + + code_size = trail.code_size; + start_code = (code_t) stat_alloc(code_size); + if (read(fd, (char *) start_code, code_size) != code_size) + fatal_error("Fatal error: truncated bytecode file.\n"); + +#ifdef ARCH_BIG_ENDIAN + fixup_endianness(start_code, code_size); +#endif + + chan = open_descr(fd); + global_data = input_value(chan); + close_channel(chan); + /* Ensure that the globals are in the major heap. */ + oldify(global_data, &global_data); + + sys_init(argv + 1); + interprete(start_code, code_size); + return TCL_OK; + } else { + Tcl_AppendResult(interp, "Caml program", argv[1], " raised exception \"", + String_val(Field(Field(exn_bucket, 0), 0))); + return TCL_ERROR; + } +} + +int CamlInvokeCmd(dummy + + + +/* Now the real Tk stuff */ +Tk_Window cltk_mainWindow; + +#define RCNAME ".camltkrc" +#define CAMLCB "camlcb" + +/* Initialisation of the dynamically loaded module */ +int Caml_Init(interp) + Tcl_Interp *interp; +{ + cltclinterp = interp; + /* Create the camlcallback command */ + Tcl_CreateCommand(cltclinterp, + CAMLCB, CamlCBCmd, + (ClientData)NULL,(Tcl_CmdDeleteProc *)NULL); + + /* This is required by "unknown" and thus autoload */ + Tcl_SetVar(cltclinterp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); + /* Our hack for implementing break in callbacks */ + Tcl_SetVar(cltclinterp, "BreakBindingsSequence", "0", TCL_GLOBAL_ONLY); + + /* Load the traditional rc file */ + { + char *home = getenv("HOME"); + if (home != NULL) { + char *f = stat_alloc(strlen(home)+strlen(RCNAME)+2); + f[0]='\0'; + strcat(f, home); + strcat(f, "/"); + strcat(f, RCNAME); + if (0 == access(f,R_OK)) + if (TCL_OK != Tcl_EvalFile(cltclinterp,f)) { + stat_free(f); + tk_error(cltclinterp->result); + }; + stat_free(f); + } + } + + /* Initialisations from caml_main */ + { + int verbose_init = 0, + percent_free_init = Percent_free_def; + long minor_heap_init = Minor_heap_def, + heap_chunk_init = Heap_chunk_def; + + /* Machine-dependent initialization of the floating-point hardware + so that it behaves as much as possible as specified in IEEE */ + init_ieee_floats(); + init_gc (minor_heap_init, heap_chunk_init, percent_free_init, + verbose_init); + init_stack(); + init_atoms(); + } +} diff --git a/otherlibs/labltk/support/cltkEval.c b/otherlibs/labltk/support/cltkEval.c new file mode 100644 index 0000000..5e8994e --- /dev/null +++ b/otherlibs/labltk/support/cltkEval.c @@ -0,0 +1,243 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkEval.c,v 1.15 2008-07-01 09:55:52 weis Exp $ */ + +#include <stdlib.h> +#include <string.h> + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#include "camltk.h" + +/* The Tcl interpretor */ +Tcl_Interp *cltclinterp = NULL; + +/* Copy a list of strings from the C heap to Caml */ +value copy_string_list(int argc, char **argv) +{ + CAMLparam0(); + CAMLlocal3( res, oldres, str ); + int i; + oldres = Val_unit; + str = Val_unit; + + res = Val_int(0); /* [] */ + for (i = argc-1; i >= 0; i--) { + oldres = res; + str = tcl_string_to_caml(argv[i]); + res = alloc(2, 0); + Field(res, 0) = str; + Field(res, 1) = oldres; + } + CAMLreturn(res); +} + +/* + * Calling Tcl from Caml + * this version works on an arbitrary Tcl command, + * and does parsing and substitution + */ +CAMLprim value camltk_tcl_eval(value str) +{ + int code; + char *cmd = NULL; + + CheckInit(); + + /* Tcl_Eval may write to its argument, so we take a copy + * If the evaluation raises a Caml exception, we have a space + * leak + */ + Tcl_ResetResult(cltclinterp); + cmd = caml_string_to_tcl(str); + code = Tcl_Eval(cltclinterp, cmd); + stat_free(cmd); + + switch (code) { + case TCL_OK: + return tcl_string_to_caml(cltclinterp->result); + case TCL_ERROR: + tk_error(cltclinterp->result); + default: /* TCL_BREAK, TCL_CONTINUE, TCL_RETURN */ + tk_error("bad tcl result"); + } +} + +/* + * Calling Tcl from Caml + * direct call, argument is TkArgs vect + type TkArgs = + TkToken of string + | TkTokenList of TkArgs list (* to be expanded *) + | TkQuote of TkArgs (* mapped to Tcl list *) + * NO PARSING, NO SUBSTITUTION + */ + +/* + * Compute the size of the argument (of type TkArgs). + * TkTokenList must be expanded, + * TkQuote count for one. + */ +int argv_size(value v) +{ + switch (Tag_val(v)) { + case 0: /* TkToken */ + return 1; + case 1: /* TkTokenList */ + { int n = 0; + value l; + for (l=Field(v,0), n=0; Is_block(l); l=Field(l,1)) + n+=argv_size(Field(l,0)); + return n; + } + case 2: /* TkQuote */ + return 1; + default: + tk_error("argv_size: illegal tag"); + } +} + +/* Fill a preallocated vector arguments, doing expansion and all. + * Assumes Tcl will + * not tamper with our strings + * make copies if strings are "persistent" + */ +int fill_args (char **argv, int where, value v) +{ + value l; + + switch (Tag_val(v)) { + case 0: + argv[where] = caml_string_to_tcl(Field(v,0)); /* must free by stat_free */ + return (where + 1); + case 1: + for (l=Field(v,0); Is_block(l); l=Field(l,1)) + where = fill_args(argv,where,Field(l,0)); + return where; + case 2: + { char **tmpargv; + char *merged; + int i; + int size = argv_size(Field(v,0)); + tmpargv = (char **)stat_alloc((size + 1) * sizeof(char *)); + fill_args(tmpargv,0,Field(v,0)); + tmpargv[size] = NULL; + merged = Tcl_Merge(size,tmpargv); + for(i = 0; i<size; i++){ stat_free(tmpargv[i]); } + stat_free((char *)tmpargv); + /* must be freed by stat_free */ + argv[where] = (char*)stat_alloc(strlen(merged)+1); + strcpy(argv[where], merged); + Tcl_Free(merged); + return (where + 1); + } + default: + tk_error("fill_args: illegal tag"); + } +} + +/* v is an array of TkArg */ +CAMLprim value camltk_tcl_direct_eval(value v) +{ + int i; + int size; /* size of argv */ + char **argv, **allocated; + int result; + Tcl_CmdInfo info; + + CheckInit(); + + /* walk the array to compute final size for Tcl */ + for(i=0, size=0; i<Wosize_val(v); i++) + size += argv_size(Field(v,i)); + + /* +2: one slot for NULL + one slot for "unknown" if command not found */ + argv = (char **)stat_alloc((size + 2) * sizeof(char *)); + allocated = (char **)stat_alloc(size * sizeof(char *)); + + /* Copy -- argv[i] must be freed by stat_free */ + { + int where; + for(i=0, where=0; i<Wosize_val(v); i++){ + where = fill_args(argv,where,Field(v,i)); + } + if( size != where ){ tk_error("fill_args error!!! Call the CamlTk maintainer!"); } + for(i=0; i<where; i++){ allocated[i] = argv[i]; } + argv[size] = NULL; + argv[size + 1] = NULL; + } + + /* Eval */ + Tcl_ResetResult(cltclinterp); + if (Tcl_GetCommandInfo(cltclinterp,argv[0],&info)) { /* command found */ +#if (TCL_MAJOR_VERSION >= 8) + /* info.proc might be a NULL pointer + * We should probably attempt an Obj invocation, but the following quick + * hack is easier. + */ + if (info.proc == NULL) { + Tcl_DString buf; + Tcl_DStringInit(&buf); + Tcl_DStringAppend(&buf, argv[0], -1); + for (i=1; i<size; i++) { + Tcl_DStringAppend(&buf, " ", -1); + Tcl_DStringAppend(&buf, argv[i], -1); + } + result = Tcl_Eval(cltclinterp, Tcl_DStringValue(&buf)); + Tcl_DStringFree(&buf); + } else { + result = (*info.proc)(info.clientData,cltclinterp,size,argv); + } +#else + result = (*info.proc)(info.clientData,cltclinterp,size,argv); +#endif + } else { /* implement the autoload stuff */ + if (Tcl_GetCommandInfo(cltclinterp,"unknown",&info)) { /* unknown found */ + for (i = size; i >= 0; i--) + argv[i+1] = argv[i]; + argv[0] = "unknown"; + result = (*info.proc)(info.clientData,cltclinterp,size+1,argv); + } else { /* ah, it isn't there at all */ + result = TCL_ERROR; + Tcl_AppendResult(cltclinterp, "Unknown command \"", + argv[0], "\"", NULL); + } + } + + /* Free the various things we allocated */ + for(i=0; i< size; i ++){ + stat_free((char *) allocated[i]); + } + stat_free((char *)argv); + stat_free((char *)allocated); + + switch (result) { + case TCL_OK: + return tcl_string_to_caml (cltclinterp->result); + case TCL_ERROR: + tk_error(cltclinterp->result); + default: /* TCL_BREAK, TCL_CONTINUE, TCL_RETURN */ + tk_error("bad tcl result"); + } +} diff --git a/otherlibs/labltk/support/cltkEvent.c b/otherlibs/labltk/support/cltkEvent.c new file mode 100644 index 0000000..f8503e7 --- /dev/null +++ b/otherlibs/labltk/support/cltkEvent.c @@ -0,0 +1,55 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkEvent.c,v 1.8 2002-04-26 12:16:17 furuse Exp $ */ + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <alloc.h> +#include "camltk.h" + +CAMLprim value camltk_tk_mainloop(void) +{ + CheckInit(); + + if (cltk_slave_mode) return Val_unit; + + if (!signal_events) { + /* Initialise signal handling */ + signal_events = 1; + Tk_CreateTimerHandler(100, invoke_pending_caml_signals, NULL); + } + Tk_MainLoop(); + return Val_unit; +} + +/* Note: this HAS to be reported "as-is" in ML source */ +static int event_flag_table[] = { + TK_DONT_WAIT, TK_X_EVENTS, TK_FILE_EVENTS, TK_TIMER_EVENTS, TK_IDLE_EVENTS, + TK_ALL_EVENTS +}; + +CAMLprim value camltk_dooneevent(value flags) +{ + int ret; + + CheckInit(); + + ret = Tk_DoOneEvent(convert_flag_list(flags, event_flag_table)); + return Val_int(ret); +} + diff --git a/otherlibs/labltk/support/cltkFile.c b/otherlibs/labltk/support/cltkFile.c new file mode 100644 index 0000000..9a6df30 --- /dev/null +++ b/otherlibs/labltk/support/cltkFile.c @@ -0,0 +1,158 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkFile.c,v 1.12 2002-04-26 12:16:17 furuse Exp $ */ + +#ifdef __CYGWIN__ +#define _WIN32 +#endif + +#ifdef _WIN32 +#include <wtypes.h> +#include <winbase.h> +#include <winsock.h> +#endif +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <callback.h> +#include "camltk.h" + +/* + * File descriptor callbacks + */ + +void FileProc(ClientData clientdata, int mask) +{ + callback2(*handler_code,Val_int(clientdata),Val_int(0)); +} + +/* Map Unix.file_descr values to Tcl file handles */ + +#ifndef _WIN32 + +/* Under Unix, we use file handlers */ + +/* Map Unix.file_descr values to Tcl file handles (for tcl 7) + or Unix file descriptors (for tcl 8). */ + +#if (TCL_MAJOR_VERSION < 8) +static Tcl_File tcl_filehandle(value fd) +{ + return Tcl_GetFile((ClientData)Long_val(fd), TCL_UNIX_FD); +} +#else +#define tcl_filehandle(fd) Int_val(fd) +#define Tcl_File int +#endif + +CAMLprim value camltk_add_file_input(value fd, value cbid) +{ + CheckInit(); + Tcl_CreateFileHandler(tcl_filehandle(fd), TCL_READABLE, + FileProc, (ClientData)(Long_val(cbid))); + return Val_unit; +} + +/* We have to free the Tcl handle when we are finished using it (Tcl + * asks us to, and moreover it is probably dangerous to keep the same + * handle over two allocations of the same fd by the kernel). + * But we don't know when we are finished with the fd, so we free it + * in rem_file (it doesn't close the fd anyway). For fds for which we + * repeatedly add/rem, this will cause some overhead. + */ +CAMLprim value camltk_rem_file_input(value fd, value cbid) +{ + Tcl_File fh = tcl_filehandle(fd); + Tcl_DeleteFileHandler(fh); +#if (TCL_MAJOR_VERSION < 8) + Tcl_FreeFile(fh); +#endif + return Val_unit; +} + +CAMLprim value camltk_add_file_output(value fd, value cbid) +{ + CheckInit(); + Tcl_CreateFileHandler(tcl_filehandle(fd), TCL_WRITABLE, + FileProc, (ClientData) (Long_val(cbid))); + return Val_unit; +} + +CAMLprim value camltk_rem_file_output(value fd, value cbid) +{ + Tcl_File fh = tcl_filehandle(fd); + Tcl_DeleteFileHandler(fh); +#if (TCL_MAJOR_VERSION < 8) + Tcl_FreeFile(fh); +#endif + return Val_unit; +} + +#else + +/* Under Win32, we go through the generic channel abstraction */ + +#define Handle_val(v) (*((HANDLE *) Data_custom_val(v))) + +/* Map Unix.file_descr values to Tcl channels */ + +static Tcl_Channel tcl_channel(value fd, int flags) +{ + HANDLE h = Handle_val(fd); + int optval, optsize; + + optsize = sizeof(optval); + if (getsockopt((SOCKET) h, SOL_SOCKET, SO_TYPE, + (char *)&optval, &optsize) == 0) + return Tcl_MakeTcpClientChannel((ClientData) h); + else + return Tcl_MakeFileChannel((ClientData) h, flags); +} + +CAMLprim value camltk_add_file_input(value fd, value cbid) +{ + CheckInit(); + Tcl_CreateChannelHandler(tcl_channel(fd, TCL_READABLE), + TCL_READABLE, + FileProc, (ClientData) (Int_val(cbid))); + return Val_unit; +} + +CAMLprim value camltk_rem_file_input(value fd, value cbid) +{ + Tcl_DeleteChannelHandler(tcl_channel(fd, TCL_READABLE), + FileProc, (ClientData) (Int_val(cbid))); + return Val_unit; +} + +CAMLprim value camltk_add_file_output(value fd, value cbid) +{ + CheckInit(); + Tcl_CreateChannelHandler(tcl_channel(fd, TCL_WRITABLE), + TCL_WRITABLE, + FileProc, (ClientData) (Int_val(cbid))); + return Val_unit; +} + +CAMLprim value camltk_rem_file_output(value fd, value cbid) +{ + Tcl_DeleteChannelHandler(tcl_channel(fd, TCL_WRITABLE), + FileProc, (ClientData) (Int_val(cbid))); + return Val_unit; +} + +#endif diff --git a/otherlibs/labltk/support/cltkImg.c b/otherlibs/labltk/support/cltkImg.c new file mode 100644 index 0000000..d8d5dd3 --- /dev/null +++ b/otherlibs/labltk/support/cltkImg.c @@ -0,0 +1,118 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ +#include <string.h> +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include "camltk.h" + +/* + * Pixmap manipulation from OCaml : get the pixmap from an arbitrary photo + * image, and put it back in some (possibly other) image. + * TODO: other blits + * We use the same format of "internal" pixmap data as in Tk, that is + * 24 bits per pixel + */ + +CAMLprim value camltk_getimgdata (value imgname) /* ML */ +{ + CAMLparam1(imgname); + CAMLlocal1(res); + Tk_PhotoHandle ph; + Tk_PhotoImageBlock pib; + int code,size; + +#if (TK_MAJOR_VERSION < 8) + if (NULL == (ph = Tk_FindPhoto(String_val(imgname)))) + tk_error("no such image"); +#else + if (NULL == (ph = Tk_FindPhoto(cltclinterp, String_val(imgname)))) + tk_error("no such image"); +#endif + + code = Tk_PhotoGetImage(ph,&pib); /* never fails ? */ + size = pib.width * pib.height * pib.pixelSize; + res = alloc_string(size); + + /* no holes, default format ? */ + if ((pib.pixelSize == 3) && + (pib.pitch == (pib.width * pib.pixelSize)) && + (pib.offset[0] == 0) && + (pib.offset[1] == 1) && + (pib.offset[2] == 2)) { + memcpy(pib.pixelPtr, String_val(res),size); + CAMLreturn(res); + } else { + int y; /* varies from 0 to height - 1 */ + int yoffs = 0; /* byte offset of line in src */ + int yidx = 0; /* byte offset of line in dst */ + for (y=0; y<pib.height; y++,yoffs+=pib.pitch,yidx+=pib.width * 3) { + int x; /* varies from 0 to width - 1 */ + int xoffs = yoffs; /* byte offset of pxl in src */ + int xidx = yidx; /* byte offset of pxl in dst */ + for (x=0; x<pib.width; x++,xoffs+=pib.pixelSize,xidx+=3) { + Byte(res, xidx) = pib.pixelPtr[xoffs+pib.offset[0]]; + Byte(res, xidx + 1) = pib.pixelPtr[xoffs+pib.offset[1]]; + Byte(res, xidx + 2) = pib.pixelPtr[xoffs+pib.offset[2]]; + }; + } + CAMLreturn(res); + } +} + +CAMLprim void +camltk_setimgdata_native (value imgname, value pixmap, value x, value y, + value w, value h) /* ML */ +{ + Tk_PhotoHandle ph; + Tk_PhotoImageBlock pib; + +#if (TK_MAJOR_VERSION < 8) + if (NULL == (ph = Tk_FindPhoto(String_val(imgname)))) + tk_error("no such image"); +#else + if (NULL == (ph = Tk_FindPhoto(cltclinterp, String_val(imgname)))) + tk_error("no such image"); +#endif + + pib.pixelPtr = String_val(pixmap); + pib.width = Int_val(w); + pib.height = Int_val(h); + pib.pitch = pib.width * 3; + pib.pixelSize = 3; + pib.offset[0] = 0; + pib.offset[1] = 1; + pib.offset[2] = 2; + Tk_PhotoPutBlock( +#if (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION >= 5 || TK_MAJOR_VERSION > 8) + NULL, +#endif +ph,&pib,Int_val(x),Int_val(y),Int_val(w),Int_val(h) +#if (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION >= 4 || TK_MAJOR_VERSION > 8) + , TK_PHOTO_COMPOSITE_SET +#endif + ); +} + +CAMLprim void camltk_setimgdata_bytecode(argv,argn) + value *argv; + int argn; +{ + camltk_setimgdata_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5]); +} diff --git a/otherlibs/labltk/support/cltkMain.c b/otherlibs/labltk/support/cltkMain.c new file mode 100644 index 0000000..0e31495 --- /dev/null +++ b/otherlibs/labltk/support/cltkMain.c @@ -0,0 +1,181 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkMain.c,v 1.15 2008-07-01 09:55:52 weis Exp $ */ + +#include <string.h> +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include <callback.h> +#include <signals.h> +#include <fail.h> +#ifdef HAS_UNISTD +#include <unistd.h> /* for R_OK */ +#endif +#include "camltk.h" + +#ifndef R_OK +#define R_OK 4 +#endif + +/* + * Dealing with signals: when a signal handler is defined in Caml, + * the actual execution of the signal handler upon reception of the + * signal is delayed until we are sure we are out of the GC. + * If a signal occurs during the MainLoop, we would have to wait + * the next event for the handler to be invoked. + * The following function will invoke a pending signal handler if any, + * and we put in on a regular timer. + */ + +#define SIGNAL_INTERVAL 300 + +int signal_events = 0; /* do we have a pending timer */ + +void invoke_pending_caml_signals (ClientData clientdata) +{ + signal_events = 0; + enter_blocking_section(); /* triggers signal handling */ + /* Rearm timer */ + Tk_CreateTimerHandler(SIGNAL_INTERVAL, invoke_pending_caml_signals, NULL); + signal_events = 1; + leave_blocking_section(); +} + +/* Now the real Tk stuff */ + +Tk_Window cltk_mainWindow; + + +/* In slave mode, the interpreter *already* exists */ +int cltk_slave_mode = 0; + +/* Initialisation, based on tkMain.c */ +CAMLprim value camltk_opentk(value argv) +{ + CAMLparam1(argv); + CAMLlocal1(tmp); + char *argv0; + + /* argv must contain argv[0], the application command name */ + tmp = Val_unit; + + if ( argv == Val_int(0) ){ + failwith("camltk_opentk: argv is empty"); + } + argv0 = String_val( Field( argv, 0 ) ); + + if (!cltk_slave_mode) { + /* Create an interpreter, dies if error */ +#if TCL_MAJOR_VERSION >= 8 + Tcl_FindExecutable(String_val(argv0)); +#endif + cltclinterp = Tcl_CreateInterp(); + { + /* Register cltclinterp for use in other related extensions */ + value *interp = caml_named_value("cltclinterp"); + if (interp != NULL) + Store_field(*interp,0,copy_nativeint((intnat)cltclinterp)); + } + + if (Tcl_Init(cltclinterp) != TCL_OK) + tk_error(cltclinterp->result); + Tcl_SetVar(cltclinterp, "argv0", String_val (argv0), TCL_GLOBAL_ONLY); + + { /* Sets argv */ + int argc = 0; + + tmp = Field(argv, 1); /* starts from argv[1] */ + while ( tmp != Val_int(0) ) { + argc++; + tmp = Field(tmp, 1); + } + + if( argc != 0 ){ + int i; + char *args; + char **tkargv; + char argcstr[256]; /* string of argc */ + + tkargv = (char**)stat_alloc(sizeof( char* ) * argc ); + tmp = Field(argv, 1); /* starts from argv[1] */ + i = 0; + + while ( tmp != Val_int(0) ) { + tkargv[i] = String_val(Field(tmp, 0)); + tmp = Field(tmp, 1); + i++; + } + + sprintf( argcstr, "%d", argc ); + Tcl_SetVar(cltclinterp, "argc", argcstr, TCL_GLOBAL_ONLY); + args = Tcl_Merge(argc, tkargv); /* args must be freed by Tcl_Free */ + Tcl_SetVar(cltclinterp, "argv", args, TCL_GLOBAL_ONLY); + Tcl_Free(args); + stat_free( tkargv ); + } + } + if (Tk_Init(cltclinterp) != TCL_OK) + tk_error(cltclinterp->result); + + /* Retrieve the main window */ + cltk_mainWindow = Tk_MainWindow(cltclinterp); + + if (NULL == cltk_mainWindow) + tk_error(cltclinterp->result); + + Tk_GeometryRequest(cltk_mainWindow,200,200); + } + + /* Create the camlcallback command */ + Tcl_CreateCommand(cltclinterp, + CAMLCB, CamlCBCmd, + (ClientData)NULL,(Tcl_CmdDeleteProc *)NULL); + + /* This is required by "unknown" and thus autoload */ + Tcl_SetVar(cltclinterp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); + /* Our hack for implementing break in callbacks */ + Tcl_SetVar(cltclinterp, "BreakBindingsSequence", "0", TCL_GLOBAL_ONLY); + + /* Load the traditional rc file */ + { + char *home = getenv("HOME"); + if (home != NULL) { + char *f = stat_alloc(strlen(home)+strlen(RCNAME)+2); + f[0]='\0'; + strcat(f, home); + strcat(f, "/"); + strcat(f, RCNAME); + if (0 == access(f,R_OK)) + if (TCL_OK != Tcl_EvalFile(cltclinterp,f)) { + stat_free(f); + tk_error(cltclinterp->result); + }; + stat_free(f); + } + } + + CAMLreturn(Val_unit); +} + +CAMLprim value camltk_finalize(value unit) /* ML */ +{ + Tcl_Finalize(); + return Val_unit; +} diff --git a/otherlibs/labltk/support/cltkMisc.c b/otherlibs/labltk/support/cltkMisc.c new file mode 100644 index 0000000..3c71978 --- /dev/null +++ b/otherlibs/labltk/support/cltkMisc.c @@ -0,0 +1,64 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkMisc.c,v 1.10 2002-07-23 14:11:59 doligez Exp $ */ + +#include <string.h> +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <memory.h> +#include "camltk.h" + +/* Parsing results */ +CAMLprim value camltk_splitlist (value v) +{ + int argc; + char **argv; + int result; + char *utf; + + CheckInit(); + + utf = caml_string_to_tcl(v); + /* argv is allocated by Tcl, to be freed by us */ + result = Tcl_SplitList(cltclinterp,utf,&argc,&argv); + switch(result) { + case TCL_OK: + { value res = copy_string_list(argc,argv); + Tcl_Free((char *)argv); /* only one large block was allocated */ + /* argv points into utf: utf must be freed after argv are freed */ + stat_free( utf ); + return res; + } + case TCL_ERROR: + default: + stat_free( utf ); + tk_error(cltclinterp->result); + } +} + +/* Copy a Caml string to the C heap. Should deallocate with stat_free */ +char *string_to_c(value s) +{ + int l = string_length(s); + char *res = stat_alloc(l + 1); + memmove (res, String_val (s), l); + res[l] = '\0'; + return res; +} + + diff --git a/otherlibs/labltk/support/cltkTimer.c b/otherlibs/labltk/support/cltkTimer.c new file mode 100644 index 0000000..2bae380 --- /dev/null +++ b/otherlibs/labltk/support/cltkTimer.c @@ -0,0 +1,45 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkTimer.c,v 1.9 2002-04-26 12:16:19 furuse Exp $ */ + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <callback.h> +#include "camltk.h" + + +/* Basically the same thing as FileProc */ +void TimerProc (ClientData clientdata) +{ + callback2(*handler_code,Val_long(clientdata),Val_int(0)); +} + +CAMLprim value camltk_add_timer(value milli, value cbid) +{ + CheckInit(); + /* look at tkEvent.c , Tk_Token is an int */ + return (Val_int(Tcl_CreateTimerHandler(Int_val(milli), TimerProc, + (ClientData) (Int_val(cbid))))); +} + +CAMLprim value camltk_rem_timer(value token) +{ + Tcl_DeleteTimerHandler((Tcl_TimerToken) Int_val(token)); + return Val_unit; +} + diff --git a/otherlibs/labltk/support/cltkUtf.c b/otherlibs/labltk/support/cltkUtf.c new file mode 100644 index 0000000..0fc25b6 --- /dev/null +++ b/otherlibs/labltk/support/cltkUtf.c @@ -0,0 +1,89 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkUtf.c,v 1.2 2002-04-26 12:16:19 furuse Exp $ */ + +#include <stdlib.h> +#include <string.h> + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#include "camltk.h" + +#if (TCL_MAJOR_VERSION > 8 || \ + (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 1)) /* 8.1 */ +# define UTFCONVERSION +#endif + +#ifdef UTFCONVERSION + +char *external_to_utf( char *str ){ + char *res; + Tcl_DString dstr; + int length; + + Tcl_ExternalToUtfDString(NULL, str, strlen(str), &dstr); + length = Tcl_DStringLength(&dstr); + res = stat_alloc(length + 1); + memmove( res, Tcl_DStringValue(&dstr), length+1); + Tcl_DStringFree(&dstr); + + return res; +} + +char *utf_to_external( char *str ){ + char *res; + Tcl_DString dstr; + int length; + + Tcl_UtfToExternalDString(NULL, str, strlen(str), &dstr); + length = Tcl_DStringLength(&dstr); + res = stat_alloc(length + 1); + memmove( res, Tcl_DStringValue(&dstr), length+1); + Tcl_DStringFree(&dstr); + + return res; +} + +char *caml_string_to_tcl( value s ) +{ + return external_to_utf( String_val(s) ); +} + +value tcl_string_to_caml( char *s ) +{ + CAMLparam0(); + CAMLlocal1(res); + char *str; + + str = utf_to_external( s ); + res = copy_string(str); + stat_free(str); + CAMLreturn(res); +} + +#else + +char *caml_string_to_tcl(value s){ return string_to_c(s); } +value tcl_string_to_caml(char *s){ return copy_string(s); } + +#endif diff --git a/otherlibs/labltk/support/cltkVar.c b/otherlibs/labltk/support/cltkVar.c new file mode 100644 index 0000000..d657b21 --- /dev/null +++ b/otherlibs/labltk/support/cltkVar.c @@ -0,0 +1,128 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkVar.c,v 1.9 2002-07-23 14:11:59 doligez Exp $ */ + +/* Alternative to tkwait variable */ +#include <string.h> +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include <callback.h> +#include "camltk.h" + +CAMLprim value camltk_getvar(value var) +{ + char *s; + char *stable_var = NULL; + CheckInit(); + + stable_var = string_to_c(var); + s = Tcl_GetVar(cltclinterp,stable_var, + TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); + stat_free(stable_var); + + if (s == NULL) + tk_error(cltclinterp->result); + else + return(tcl_string_to_caml(s)); +} + +CAMLprim value camltk_setvar(value var, value contents) +{ + char *s; + char *stable_var = NULL; + char *utf_contents; + CheckInit(); + + /* SetVar makes a copy of the contents. */ + /* In case we have write traces in Caml, it's better to make sure that + var doesn't move... */ + stable_var = string_to_c(var); + utf_contents = caml_string_to_tcl(contents); + s = Tcl_SetVar(cltclinterp,stable_var, utf_contents, + TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG); + stat_free(stable_var); + if( s == utf_contents ){ + tk_error("camltk_setvar: Tcl_SetVar returned strange result. Call the author of mlTk!"); + } + stat_free(utf_contents); + + if (s == NULL) + tk_error(cltclinterp->result); + else + return(Val_unit); +} + + +/* The appropriate type is +typedef char *(Tcl_VarTraceProc) _ANSI_ARGS_((ClientData clientData, + Tcl_Interp *interp, char *part1, char *part2, int flags)); + */ +static char * tracevar(clientdata, interp, name1, name2, flags) + ClientData clientdata; + Tcl_Interp *interp; /* Interpreter containing variable. */ + char *name1; /* Name of variable. */ + char *name2; /* Second part of variable name. */ + int flags; /* Information about what happened. */ +{ + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + tracevar, clientdata); + callback2(*handler_code,Val_int(clientdata),Val_unit); + return (char *)NULL; +} + +/* Sets up a callback upon modification of a variable */ +CAMLprim value camltk_trace_var(value var, value cbid) +{ + char *cvar = NULL; + + CheckInit(); + /* Make a copy of var, since Tcl will modify it in place, and we + * don't trust that much what it will do here + */ + cvar = string_to_c(var); + if (Tcl_TraceVar(cltclinterp, cvar, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + tracevar, + (ClientData) (Long_val(cbid))) + != TCL_OK) { + stat_free(cvar); + tk_error(cltclinterp->result); + }; + stat_free(cvar); + return Val_unit; +} + +CAMLprim value camltk_untrace_var(value var, value cbid) +{ + char *cvar = NULL; + + CheckInit(); + /* Make a copy of var, since Tcl will modify it in place, and we + * don't trust that much what it will do here + */ + cvar = string_to_c(var); + Tcl_UntraceVar(cltclinterp, cvar, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + tracevar, + (ClientData) (Long_val(cbid))); + stat_free(cvar); + return Val_unit; +} diff --git a/otherlibs/labltk/support/cltkWait.c b/otherlibs/labltk/support/cltkWait.c new file mode 100644 index 0000000..d054892 --- /dev/null +++ b/otherlibs/labltk/support/cltkWait.c @@ -0,0 +1,102 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ + +/* $Id: cltkWait.c,v 1.9 2002-07-23 14:11:59 doligez Exp $ */ + +#include <tcl.h> +#include <tk.h> +#include <mlvalues.h> +#include <memory.h> +#include <callback.h> +#include "camltk.h" + +/* The following are replacements for + tkwait visibility + tkwait window + in the case where we use threads (tkwait internally calls an event loop, + and thus prevents thread scheduling from taking place). + + Instead, one should set up a callback, wait for a signal, and signal + from inside the callback +*/ + +static void WaitVisibilityProc _ANSI_ARGS_((ClientData clientData, + XEvent *eventPtr)); +static void WaitWindowProc _ANSI_ARGS_((ClientData clientData, + XEvent *eventPtr)); + +/* For the other handlers, we need a bit more data */ +struct WinCBData { + int cbid; + Tk_Window win; +}; + +static void WaitVisibilityProc(clientData, eventPtr) + ClientData clientData; + XEvent *eventPtr; /* Information about event (not used). */ +{ + struct WinCBData *vis = clientData; + value cbid = Val_int(vis->cbid); + + Tk_DeleteEventHandler(vis->win, VisibilityChangeMask, + WaitVisibilityProc, clientData); + + stat_free((char *)vis); + callback2(*handler_code,cbid,Val_int(0)); +} + +/* Sets up a callback upon Visibility of a window */ +CAMLprim value camltk_wait_vis(value win, value cbid) +{ + struct WinCBData *vis = + (struct WinCBData *)stat_alloc(sizeof(struct WinCBData)); + vis->win = Tk_NameToWindow(cltclinterp, String_val(win), cltk_mainWindow); + if (vis -> win == NULL) { + stat_free((char *)vis); + tk_error(cltclinterp->result); + }; + vis->cbid = Int_val(cbid); + Tk_CreateEventHandler(vis->win, VisibilityChangeMask, + WaitVisibilityProc, (ClientData) vis); + return Val_unit; +} + +static void WaitWindowProc(ClientData clientData, XEvent *eventPtr) +{ + if (eventPtr->type == DestroyNotify) { + struct WinCBData *vis = clientData; + value cbid = Val_int(vis->cbid); + stat_free((char *)clientData); + /* The handler is destroyed by Tk itself */ + callback2(*handler_code,cbid,Val_int(0)); + } +} + +/* Sets up a callback upon window destruction */ +CAMLprim value camltk_wait_des(value win, value cbid) +{ + struct WinCBData *vis = + (struct WinCBData *)stat_alloc(sizeof(struct WinCBData)); + vis->win = Tk_NameToWindow(cltclinterp, String_val(win), cltk_mainWindow); + if (vis -> win == NULL) { + stat_free((char *)vis); + tk_error(cltclinterp->result); + }; + vis->cbid = Int_val(cbid); + Tk_CreateEventHandler(vis->win, StructureNotifyMask, + WaitWindowProc, (ClientData) vis); + return Val_unit; +} diff --git a/otherlibs/labltk/support/fileevent.ml b/otherlibs/labltk/support/fileevent.ml new file mode 100644 index 0000000..71f6ae9 --- /dev/null +++ b/otherlibs/labltk/support/fileevent.ml @@ -0,0 +1,81 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: fileevent.ml,v 1.12 2002-04-26 12:16:19 furuse Exp $ *) + +open Unix +open Support +open Protocol + +external add_file_input : file_descr -> cbid -> unit + = "camltk_add_file_input" +external rem_file_input : file_descr -> cbid -> unit + = "camltk_rem_file_input" +external add_file_output : file_descr -> cbid -> unit + = "camltk_add_file_output" +external rem_file_output : file_descr -> cbid -> unit + = "camltk_rem_file_output" + +(* File input handlers *) + +let fd_table = Hashtbl.create 37 (* Avoid space leak in callback table *) + +let add_fileinput ~fd ~callback:f = + let id = new_function_id () in + Hashtbl.add callback_naming_table id (fun _ -> f()); + Hashtbl.add fd_table (fd, 'r') id; + if !Protocol.debug then begin + Protocol.prerr_cbid id; prerr_endline " for fileinput" + end; + add_file_input fd id + +let remove_fileinput ~fd = + try + let id = Hashtbl.find fd_table (fd, 'r') in + clear_callback id; + Hashtbl.remove fd_table (fd, 'r'); + if !Protocol.debug then begin + prerr_string "clear "; + Protocol.prerr_cbid id; + prerr_endline " for fileinput" + end; + rem_file_input fd id + with + Not_found -> () + +let add_fileoutput ~fd ~callback:f = + let id = new_function_id () in + Hashtbl.add callback_naming_table id (fun _ -> f()); + Hashtbl.add fd_table (fd, 'w') id; + if !Protocol.debug then begin + Protocol.prerr_cbid id; prerr_endline " for fileoutput" + end; + add_file_output fd id + +let remove_fileoutput ~fd = + try + let id = Hashtbl.find fd_table (fd, 'w') in + clear_callback id; + Hashtbl.remove fd_table (fd, 'w'); + if !Protocol.debug then begin + prerr_string "clear "; + Protocol.prerr_cbid id; + prerr_endline " for fileoutput" + end; + rem_file_output fd id + with + Not_found -> () + diff --git a/otherlibs/labltk/support/fileevent.mli b/otherlibs/labltk/support/fileevent.mli new file mode 100644 index 0000000..3a14ed9 --- /dev/null +++ b/otherlibs/labltk/support/fileevent.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: fileevent.mli,v 1.7 2002-04-26 12:16:20 furuse Exp $ *) + +open Unix + +val add_fileinput : fd:file_descr -> callback:(unit -> unit) -> unit +val remove_fileinput: fd:file_descr -> unit +val add_fileoutput : fd:file_descr -> callback:(unit -> unit) -> unit +val remove_fileoutput: fd:file_descr -> unit + (* see [tk] module *) diff --git a/otherlibs/labltk/support/liblabltk.clib b/otherlibs/labltk/support/liblabltk.clib new file mode 100644 index 0000000..0a127dc --- /dev/null +++ b/otherlibs/labltk/support/liblabltk.clib @@ -0,0 +1,2 @@ +cltkCaml.o cltkUtf.o cltkEval.o cltkEvent.o cltkFile.o cltkMain.o +cltkMisc.o cltkTimer.o cltkVar.o cltkWait.o cltkImg.o diff --git a/otherlibs/labltk/support/native.itarget b/otherlibs/labltk/support/native.itarget new file mode 100644 index 0000000..2d2ef8d --- /dev/null +++ b/otherlibs/labltk/support/native.itarget @@ -0,0 +1,3 @@ +support.cmx rawwidget.cmx widget.cmx protocol.cmx +textvariable.cmx timer.cmx fileevent.cmx camltkwrap.cmx +tkthread.cmx diff --git a/otherlibs/labltk/support/protocol.ml b/otherlibs/labltk/support/protocol.ml new file mode 100644 index 0000000..2d58450 --- /dev/null +++ b/otherlibs/labltk/support/protocol.ml @@ -0,0 +1,276 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: protocol.ml,v 1.21 2005-12-21 05:29:08 garrigue Exp $ *) + +open Support +open Widget + +type callback_buffer = string list + (* Buffer for reading callback arguments *) + +type tkArgs = + TkToken of string + | TkTokenList of tkArgs list (* to be expanded *) + | TkQuote of tkArgs (* mapped to Tcl list *) + +type cbid = int + +external opentk_low : string list -> unit + = "camltk_opentk" +external tcl_eval : string -> string + = "camltk_tcl_eval" +external tk_mainloop : unit -> unit + = "camltk_tk_mainloop" +external tcl_direct_eval : tkArgs array -> string + = "camltk_tcl_direct_eval" +external splitlist : string -> string list + = "camltk_splitlist" +external tkreturn : string -> unit + = "camltk_return" +external callback_init : unit -> unit + = "camltk_init" +external finalizeTk : unit -> unit + = "camltk_finalize" + (* Finalize tcl/tk before exiting. This function will be automatically + called when you call [Pervasives.exit ()] (This is installed at + [install_cleanup ()] *) + +let tcl_command s = ignore (tcl_eval s);; + +type event_flag = + DONT_WAIT | X_EVENTS | FILE_EVENTS | TIMER_EVENTS | IDLE_EVENTS | ALL_EVENTS +external do_one_event : event_flag list -> bool = "camltk_dooneevent" + +let do_pending () = while do_one_event [DONT_WAIT] do () done + +exception TkError of string + (* Raised by the communication functions *) +let () = Callback.register_exception "tkerror" (TkError "") + +let cltclinterp = ref Nativeint.zero + (* For use in other extensions *) +let () = Callback.register "cltclinterp" cltclinterp + +(* Debugging support *) +let debug = + ref (try ignore (Sys.getenv "CAMLTKDEBUG"); true + with Not_found -> false) + +(* This is approximative, since we don't quote what needs to be quoted *) +let dump_args args = + let rec print_arg = function + TkToken s -> prerr_string s; prerr_string " " + | TkTokenList l -> List.iter print_arg l + | TkQuote a -> prerr_string "{"; print_arg a; prerr_string "} " + in + Array.iter print_arg args; + prerr_newline() + +(* + * Evaluating Tcl code + * debugging support should not affect performances... + *) + +let tkEval args = + if !debug then dump_args args; + let res = tcl_direct_eval args in + if !debug then begin + prerr_string "->>"; + prerr_endline res + end; + res + +let tkCommand args = ignore (tkEval args) + +(* + * Callbacks + *) + +(* LablTk only *) +let cCAMLtoTKwidget w = + (* Widget.check_class w table; (* with subtyping, it is redundant *) *) + TkToken (Widget.name w) + +let cTKtoCAMLwidget = function + "" -> raise (Invalid_argument "cTKtoCAMLwidget") + | s -> Widget.get_atom s + +let callback_naming_table = + (Hashtbl.create 401 : (int, callback_buffer -> unit) Hashtbl.t) + +let callback_memo_table = + (Hashtbl.create 401 : (any widget, int) Hashtbl.t) + +let new_function_id = + let counter = ref 0 in + function () -> incr counter; !counter + +let string_of_cbid = string_of_int + +(* Add a new callback, associated to widget w *) +(* The callback should be cleared when w is destroyed *) +let register_callback w ~callback:f = + let id = new_function_id () in + Hashtbl.add callback_naming_table id f; + if (forget_type w) <> (forget_type Widget.dummy) then + Hashtbl.add callback_memo_table (forget_type w) id; + (string_of_cbid id) + +let clear_callback id = + Hashtbl.remove callback_naming_table id + +(* Clear callbacks associated to a given widget *) +let remove_callbacks w = + let w = forget_type w in + let cb_ids = Hashtbl.find_all callback_memo_table w in + List.iter clear_callback cb_ids; + for i = 1 to List.length cb_ids do + Hashtbl.remove callback_memo_table w + done + +(* Hand-coded callback for destroyed widgets + * This may be extended by the application, or by other layers of Camltk. + * Could use bind + of Tk, but I'd rather give an alternate mechanism so + * that hooks can be set up at load time (i.e. before openTk) + *) +let destroy_hooks = ref [] +let add_destroy_hook f = + destroy_hooks := f :: !destroy_hooks + +let _ = + add_destroy_hook (fun w -> remove_callbacks w; Widget.remove w) + +let install_cleanup () = + let call_destroy_hooks = function + [wname] -> + let w = cTKtoCAMLwidget wname in + List.iter (fun f -> f w) !destroy_hooks + | _ -> raise (TkError "bad cleanup callback") in + let fid = new_function_id () in + Hashtbl.add callback_naming_table fid call_destroy_hooks; + (* setup general destroy callback *) + tcl_command ("bind all <Destroy> {camlcb " ^ (string_of_cbid fid) ^" %W}"); + at_exit finalizeTk + +let prerr_cbid id = + prerr_string "camlcb "; prerr_int id + +(* The callback dispatch function *) +let dispatch_callback id args = + if !debug then begin + prerr_cbid id; + List.iter (fun x -> prerr_string " "; prerr_string x) args; + prerr_newline() + end; + (Hashtbl.find callback_naming_table id) args; + if !debug then prerr_endline "<<-" + +let protected_dispatch id args = + try + dispatch_callback id args + with e -> + Printf.eprintf "Uncaught exception: %s\n" (Printexc.to_string e); + flush stderr + +let _ = Callback.register "camlcb" protected_dispatch + +(* Make sure the C variables are initialised *) +let _ = callback_init () + +(* Different version of initialisation functions *) +let default_display_name = ref "" +let default_display () = !default_display_name + +let camltk_argv = ref [] + +(* options for Arg.parse *) +let keywords = [ + "-display", Arg.String (fun s -> + camltk_argv := "-display" :: s :: !camltk_argv), + "<disp> : X server to contact (CamlTk)"; + "-colormap", Arg.String (fun s -> + camltk_argv := "-colormap" :: s :: !camltk_argv), + "<colormap> : colormap to use (CamlTk)"; + "-geometry", Arg.String (fun s -> + camltk_argv := "-geometry" :: s :: !camltk_argv), + "<geom> : size and position (CamlTk)"; + "-name", Arg.String (fun s -> + camltk_argv := "-name" :: s :: !camltk_argv), + "<name> : application class (CamlTk)"; + "-sync", Arg.Unit (fun () -> + camltk_argv := "-sync" :: !camltk_argv), + ": sync mode (CamlTk)"; + "-use", Arg.String (fun s -> + camltk_argv := "-use" :: s :: !camltk_argv), + "<id> : parent window id (CamlTk)"; + "-window", Arg.String (fun s -> + camltk_argv := "-use" :: s :: !camltk_argv), + "<id> : parent window id (CamlTk)"; + "-visual", Arg.String (fun s -> + camltk_argv := "-visual" :: s :: !camltk_argv), + "<visual> : visual to use (CamlTk)" ] + +let opentk_with_args argv (* = [argv1;..;argvn] *) = + (* argv must be command line for wish *) + let argv0 = Sys.argv.(0) in + let rec find_display = function + | "-display" :: s :: xs -> s + | "-colormap" :: s :: xs -> find_display xs + | "-geometry" :: s :: xs -> find_display xs + | "-name" :: s :: xs -> find_display xs + | "-sync" :: xs -> find_display xs + | "-use" :: s :: xs -> find_display xs + | "-window" :: s :: xs -> find_display xs + | "-visual" :: s :: xs -> find_display xs + | "--" :: _ -> "" + | _ :: xs -> find_display xs + | [] -> "" + in + default_display_name := find_display argv; + opentk_low (argv0 :: argv); + install_cleanup(); + Widget.default_toplevel + +let opentk () = opentk_with_args !camltk_argv;; + +let openTkClass s = opentk_with_args ["-name"; s] +let openTkDisplayClass disp cl = opentk_with_args ["-display"; disp; "-name"; cl] + +(*JPF CAMLTK/LABLTK? *) +let openTk ?(display = "") ?(clas = "LablTk") () = + let dispopt = + match display with + | "" -> [] + | _ -> ["-display"; display] + in + opentk_with_args (dispopt @ ["-name"; clas]) + +(* Destroy all widgets, thus cleaning up table and exiting the loop *) +let closeTk () = + tcl_command "destroy ." + +let mainLoop = + tk_mainloop + + +(* [register tclname f] makes [f] available from Tcl with + name [tclname] *) +let register tclname ~callback = + let s = register_callback Widget.default_toplevel ~callback in + tcl_command (Printf.sprintf "proc %s {args} {eval {camlcb %s} $args}" + tclname s) + diff --git a/otherlibs/labltk/support/protocol.mli b/otherlibs/labltk/support/protocol.mli new file mode 100644 index 0000000..a5c077c --- /dev/null +++ b/otherlibs/labltk/support/protocol.mli @@ -0,0 +1,124 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: protocol.mli,v 1.12 2005-12-21 05:29:08 garrigue Exp $ *) + +open Widget + +(* Lower level interface *) +exception TkError of string + (* Raised by the communication functions *) + +val debug : bool ref + (* When set to true, displays approximation of intermediate Tcl code *) + +type tkArgs = + TkToken of string + | TkTokenList of tkArgs list (* to be expanded *) + | TkQuote of tkArgs (* mapped to Tcl list *) + + +(* Misc *) +external splitlist : string -> string list + = "camltk_splitlist" + +val add_destroy_hook : (any widget -> unit) -> unit + + +(* Opening, closing, and mainloop *) +val default_display : unit -> string + +val opentk : unit -> toplevel widget + (* The basic initialization function. *) + +val keywords : (string * Arg.spec * string) list + (* Command line parsing specification for Arg.parse, which contains + the standard Tcl/Tk command line options such as "-display" and "-name". + Add [keywords] to a [Arg.parse] call, then call [opentk]. + Then [opentk] can make use of these command line options + to initiate applications. *) + +val opentk_with_args : string list -> toplevel widget + (* [opentk_with_args] is a lower level interface to initiate Tcl/Tk + applications. [opentk_with_args argv] initializes Tcl/Tk with + the command line options given by [argv] *) + +val openTk : ?display:string -> ?clas:string -> unit -> toplevel widget + (* [openTk ~display:display ~clas:clas ()] is equivalent to + [opentk_with_args ["-display"; display; "-name"; clas]] *) + +(* Legacy opentk functions *) +val openTkClass: string -> toplevel widget + (* [openTkClass class] is equivalent to [opentk ["-name"; class]] *) +val openTkDisplayClass: string -> string -> toplevel widget + (* [openTkDisplayClass disp class] is equivalent to + [opentk ["-display"; disp; "-name"; class]] *) + +val closeTk : unit -> unit +val finalizeTk : unit -> unit + (* Finalize tcl/tk before exiting. This function will be automatically + called when you call [Pervasives.exit ()] *) + +val mainLoop : unit -> unit + (* Start the event loop *) + +type event_flag = + DONT_WAIT | X_EVENTS | FILE_EVENTS | TIMER_EVENTS | IDLE_EVENTS | ALL_EVENTS +val do_one_event : event_flag list -> bool + (* Process a single event *) +val do_pending : unit -> unit + (* Process all pending events, without waiting. + This lets you use Tk from the toplevel, for instance. *) + + +(* Direct evaluation of tcl code *) +val tkEval : tkArgs array -> string + +val tkCommand : tkArgs array -> unit + +(* Returning a value from a Tcl callback *) +val tkreturn: string -> unit + + +(* Callbacks: this is private *) + +type cbid + +type callback_buffer = string list + (* Buffer for reading callback arguments *) + +val callback_naming_table : (cbid, callback_buffer -> unit) Hashtbl.t +val callback_memo_table : (any widget, cbid) Hashtbl.t + (* Exported for debug purposes only. Don't use them unless you + know what you are doing *) +val new_function_id : unit -> cbid +val string_of_cbid : cbid -> string +val register_callback : 'a widget -> callback:(callback_buffer -> unit) -> string + (* Callback support *) +val clear_callback : cbid -> unit + (* Remove a given callback from the table *) +val remove_callbacks : 'a widget -> unit + (* Clean up callbacks associated to widget. Must be used only when + the Destroy event is bind by the user and masks the default + Destroy event binding *) + +val cTKtoCAMLwidget : string -> any widget +val cCAMLtoTKwidget : 'a widget -> tkArgs + +val register : string -> callback:(callback_buffer -> unit) -> unit + +(*-*) +val prerr_cbid : cbid -> unit diff --git a/otherlibs/labltk/support/rawwidget.ml b/otherlibs/labltk/support/rawwidget.ml new file mode 100644 index 0000000..10dc4cf --- /dev/null +++ b/otherlibs/labltk/support/rawwidget.ml @@ -0,0 +1,176 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: rawwidget.ml,v 1.3 2002-07-23 14:11:59 doligez Exp $ *) + +open Support + +(* + * Widgets + *) + +exception IllegalWidgetType of string + (* Raised when widget command applied illegally*) + +(***************************************************) +(* Widgets *) +(* This 'a raw_widget will be 'a Widget.widget *) +(***************************************************) +type 'a raw_widget = + Untyped of string +| Typed of string * string + +type raw_any (* will be Widget.any *) +and button +and canvas +and checkbutton +and entry +and frame +and label +and listbox +and menu +and menubutton +and message +and radiobutton +and scale +and scrollbar +and text +and toplevel + +let forget_type w = (Obj.magic (w : 'a raw_widget) : raw_any raw_widget) +let coe = forget_type + +(* table of widgets *) +let table = (Hashtbl.create 401 : (string, raw_any raw_widget) Hashtbl.t) + +let name = function + Untyped s -> s + | Typed (s,_) -> s + +(* Normally all widgets are known *) +(* this is a provision for send commands to external tk processes *) +let known_class = function + Untyped _ -> "unknown" + | Typed (_,c) -> c + +(* This one is always created by opentk *) +let default_toplevel = + let wname = "." in + let w = Typed (wname, "toplevel") in + Hashtbl.add table wname w; + w + +(* Dummy widget to which global callbacks are associated *) +(* also passed around by camltotkoption when no widget in context *) +let dummy = + Untyped "dummy" + +let remove w = + Hashtbl.remove table (name w) + +(* Retype widgets returned from Tk *) +(* JPF report: sometime s is "", see Protocol.cTKtoCAMLwidget *) +let get_atom s = + try + Hashtbl.find table s + with + Not_found -> Untyped s + +let naming_scheme = [ + "button", "b"; + "canvas", "ca"; + "checkbutton", "cb"; + "entry", "en"; + "frame", "f"; + "label", "l"; + "listbox", "li"; + "menu", "me"; + "menubutton", "mb"; + "message", "ms"; + "radiobutton", "rb"; + "scale", "sc"; + "scrollbar", "sb"; + "text", "t"; + "toplevel", "top" ] + + +let widget_any_table = List.map fst naming_scheme +(* subtypes *) +let widget_button_table = [ "button" ] +and widget_canvas_table = [ "canvas" ] +and widget_checkbutton_table = [ "checkbutton" ] +and widget_entry_table = [ "entry" ] +and widget_frame_table = [ "frame" ] +and widget_label_table = [ "label" ] +and widget_listbox_table = [ "listbox" ] +and widget_menu_table = [ "menu" ] +and widget_menubutton_table = [ "menubutton" ] +and widget_message_table = [ "message" ] +and widget_radiobutton_table = [ "radiobutton" ] +and widget_scale_table = [ "scale" ] +and widget_scrollbar_table = [ "scrollbar" ] +and widget_text_table = [ "text" ] +and widget_toplevel_table = [ "toplevel" ] + +let new_suffix clas n = + try + (List.assoc clas naming_scheme) ^ (string_of_int n) + with + Not_found -> "w" ^ (string_of_int n) + +(* The function called by generic creation *) +let counter = ref 0 +let new_atom ~parent ?name:nom clas = + let parentpath = name parent in + let path = + match nom with + None -> + incr counter; + if parentpath = "." + then "." ^ (new_suffix clas !counter) + else parentpath ^ "." ^ (new_suffix clas !counter) + | Some name -> + if parentpath = "." + then "." ^ name + else parentpath ^ "." ^ name + in + let w = Typed(path,clas) in + Hashtbl.add table path w; + w + +(* Just create a path. Only to check existence of widgets *) +(* Use with care *) +let atom ~parent ~name:pathcomp = + let parentpath = name parent in + let path = + if parentpath = "." + then "." ^ pathcomp + else parentpath ^ "." ^ pathcomp in + Untyped path + +(* LablTk: Redundant with subtyping of Widget, backward compatibility *) +let check_class w clas = + match w with + Untyped _ -> () (* assume run-time check by tk*) + | Typed(_,c) -> + if List.mem c clas then () + else raise (IllegalWidgetType c) + + +(* Checking membership of constructor in subtype table *) +let chk_sub errname table c = + if List.mem c table then () + else raise (Invalid_argument errname) diff --git a/otherlibs/labltk/support/rawwidget.mli b/otherlibs/labltk/support/rawwidget.mli new file mode 100644 index 0000000..173931b --- /dev/null +++ b/otherlibs/labltk/support/rawwidget.mli @@ -0,0 +1,109 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: rawwidget.mli,v 1.2 2002-04-26 12:16:20 furuse Exp $ *) + +(* Support for widget manipulations *) + +type 'a raw_widget + (* widget is an abstract type *) + +type raw_any +and button +and canvas +and checkbutton +and entry +and frame +and label +and listbox +and menu +and menubutton +and message +and radiobutton +and scale +and scrollbar +and text +and toplevel + +val forget_type : 'a raw_widget -> raw_any raw_widget +val coe : 'a raw_widget -> raw_any raw_widget + +val default_toplevel : toplevel raw_widget + (* [default_toplevel] is "." in Tk, the toplevel widget that is + always existing during a Tk session. Destroying [default_toplevel] + ends the main loop + *) + +val atom : parent: 'a raw_widget -> name: string -> raw_any raw_widget + (* [atom parent name] returns the widget [parent.name]. The widget is + not created. Only its name is returned. In a given parent, there may + only exist one children for a given name. + This function should only be used to check the existence of a widget + with a known name. It doesn't add the widget to the internal tables + of CamlTk. + *) + +val name : 'a raw_widget -> string + (* [name w] returns the name (tk "path") of a widget *) + +(*--*) +(* The following functions are used internally. + There is normally no need for them in users programs + *) + +val known_class : 'a raw_widget -> string + (* [known_class w] returns the class of a widget (e.g. toplevel, frame), + as known by the CamlTk interface. + Not equivalent to "winfo w" in Tk. + *) + +val dummy : raw_any raw_widget + (* [dummy] is a widget used as context when we don't have any. + It is *not* a real widget. + *) + +val new_atom : parent:'a raw_widget -> ?name: string -> string -> 'b raw_widget + +val get_atom : string -> raw_any raw_widget + (* [get_atom path] returns the widget with Tk path [path] *) + +val remove : 'a raw_widget -> unit + (* [remove w] removes widget from the internal tables *) + +(* Subtypes tables *) +val widget_any_table : string list +val widget_button_table : string list +val widget_canvas_table : string list +val widget_checkbutton_table : string list +val widget_entry_table : string list +val widget_frame_table : string list +val widget_label_table : string list +val widget_listbox_table : string list +val widget_menu_table : string list +val widget_menubutton_table : string list +val widget_message_table : string list +val widget_radiobutton_table : string list +val widget_scale_table : string list +val widget_scrollbar_table : string list +val widget_text_table : string list +val widget_toplevel_table : string list + +val chk_sub : string -> 'a list -> 'a -> unit +val check_class : 'a raw_widget -> string list -> unit + (* Widget subtyping *) + +exception IllegalWidgetType of string + (* Raised when widget command applied illegally*) diff --git a/otherlibs/labltk/support/slave.ml b/otherlibs/labltk/support/slave.ml new file mode 100644 index 0000000..e460aba --- /dev/null +++ b/otherlibs/labltk/support/slave.ml @@ -0,0 +1,51 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: slave.ml,v 1.5 2002-04-26 12:16:21 furuse Exp $ *) + +(* The code run on initialisation, in addition to normal Tk code + * NOTE: camltk has not fully been initialised yet + *) +external tcl_eval : string -> string + = "camltk_tcl_eval" +let tcl_command s = ignore (tcl_eval s);; +open Printf + +let dynload args = + List.iter Dynlink.loadfile args + +(* Default modules include everything from +let default_modules = [] +*) + +(* [caml::run foo.cmo .. bar.cmo] is now available from Tcl *) +let init () = + Dynlink.init(); + (* Make it unsafe by default, with everything available *) + Dynlink.allow_unsafe_modules true; + Dynlink.add_interfaces [] []; + let s = register_callback Widget.dummy dynload in + tcl_command (sprintf "proc caml::run {l} {camlcb %s l}" s) + +let _ = + Printexc.print init () + +(* A typical master program would then + * caml::run foo.cmo + * # during initialisation, "foo" was registered as a tcl procedure + * foo x y z + * # proceed with some Tcl code calling foo + *) diff --git a/otherlibs/labltk/support/support.ml b/otherlibs/labltk/support/support.ml new file mode 100644 index 0000000..b7c2c2b --- /dev/null +++ b/otherlibs/labltk/support/support.ml @@ -0,0 +1,48 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: support.ml,v 1.9 2002-04-26 12:16:21 furuse Exp $ *) + +(* Parsing results of Tcl *) +(* List.split a string according to char_sep predicate *) +let split_str ~pred:char_sep str = + let len = String.length str in + let rec skip_sep cur = + if cur >= len then cur + else if char_sep str.[cur] then skip_sep (succ cur) + else cur in + let rec split beg cur = + if cur >= len then + if beg = cur then [] + else [String.sub str beg (len - beg)] + else if char_sep str.[cur] + then + let nextw = skip_sep cur in + (String.sub str beg (cur - beg)) + ::(split nextw nextw) + else split beg (succ cur) in + let wstart = skip_sep 0 in + split wstart wstart + +(* Very easy hack for option type *) +let may f = function + Some x -> Some (f x) +| None -> None + +let maycons f x l = + match x with + Some x -> f x :: l + | None -> l diff --git a/otherlibs/labltk/support/support.mli b/otherlibs/labltk/support/support.mli new file mode 100644 index 0000000..79ace29 --- /dev/null +++ b/otherlibs/labltk/support/support.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: support.mli,v 1.8 2002-04-26 12:16:21 furuse Exp $ *) + +val split_str : pred:(char -> bool) -> string -> string list +val may : ('a -> 'b) -> 'a option -> 'b option +val maycons : ('a -> 'b) -> 'a option -> 'b list -> 'b list diff --git a/otherlibs/labltk/support/textvariable.ml b/otherlibs/labltk/support/textvariable.ml new file mode 100644 index 0000000..e193e14 --- /dev/null +++ b/otherlibs/labltk/support/textvariable.ml @@ -0,0 +1,152 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: textvariable.ml,v 1.16 2002-07-23 14:11:59 doligez Exp $ *) + +open Support +open Protocol + +external internal_tracevar : string -> cbid -> unit + = "camltk_trace_var" +external internal_untracevar : string -> cbid -> unit + = "camltk_untrace_var" +external set : string -> string -> unit = "camltk_setvar" +external get : string -> string = "camltk_getvar" + + +type textVariable = string + +(* List of handles *) +let handles = Hashtbl.create 401 + +let add_handle var cbid = + try + let r = Hashtbl.find handles var in + r := cbid :: !r + with + Not_found -> + Hashtbl.add handles var (ref [cbid]) + +let exceptq x = + let rec ex acc = function + [] -> acc + | y::l when y == x -> ex acc l + | y::l -> ex (y::acc) l + in + ex [] + +let rem_handle var cbid = + try + let r = Hashtbl.find handles var in + match exceptq cbid !r with + [] -> Hashtbl.remove handles var + | remaining -> r := remaining + with + Not_found -> () + +(* Used when we "free" the variable (otherwise, old handlers would apply to + * new usage of the variable) + *) +let rem_all_handles var = + try + let r = Hashtbl.find handles var in + List.iter (internal_untracevar var) !r; + Hashtbl.remove handles var + with + Not_found -> () + + +(* Variable trace *) +let handle vname ~callback:f = + let id = new_function_id() in + let wrapped _ = + clear_callback id; + rem_handle vname id; + f() in + Hashtbl.add callback_naming_table id wrapped; + add_handle vname id; + if !Protocol.debug then begin + prerr_cbid id; prerr_string " for variable "; prerr_endline vname + end; + internal_tracevar vname id + +(* Avoid space leak (all variables are global in Tcl) *) +module StringSet = + Set.Make(struct type t = string let compare = compare end) +let freelist = ref (StringSet.empty) +let memo = Hashtbl.create 101 + +(* Added a variable v referenced by widget w *) +let add w v = + let w = Widget.forget_type w in + let r = + try Hashtbl.find memo w + with + Not_found -> + let r = ref StringSet.empty in + Hashtbl.add memo w r; + r in + r := StringSet.add v !r + +(* to be used with care ! *) +let free v = + rem_all_handles v; + freelist := StringSet.add v !freelist + +(* Free variables associated with a widget *) +let freew w = + try + let r = Hashtbl.find memo w in + StringSet.iter free !r; + Hashtbl.remove memo w + with + Not_found -> () + +let _ = add_destroy_hook freew + +(* Allocate a new variable *) +let counter = ref 0 +let getv () = + let v = + if StringSet.is_empty !freelist then begin + incr counter; + "camlv("^ string_of_int !counter ^")" + end + else + let v = StringSet.choose !freelist in + freelist := StringSet.remove v !freelist; + v in + set v ""; + v + +let create ?on: w () = + let v = getv() in + begin + match w with + Some w -> add w v + | None -> () + end; + v + +(* to be used with care ! *) +let free v = + freelist := StringSet.add v !freelist + +let cCAMLtoTKtextVariable s = TkToken s + +let name s = s +let coerce s = s + diff --git a/otherlibs/labltk/support/textvariable.mli b/otherlibs/labltk/support/textvariable.mli new file mode 100644 index 0000000..88785de --- /dev/null +++ b/otherlibs/labltk/support/textvariable.mli @@ -0,0 +1,45 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: textvariable.mli,v 1.10 2002-04-26 12:16:21 furuse Exp $ *) + +(* Support for Tk -textvariable option *) +open Widget +open Protocol + +type textVariable + (* TextVariable is an abstract type *) + +val create : ?on: 'a widget -> unit -> textVariable + (* Allocation of a textVariable with lifetime associated to widget + if a widget is specified *) +val set : textVariable -> string -> unit + (* Setting the val of a textVariable *) +val get : textVariable -> string + (* Reading the val of a textVariable *) +val name : textVariable -> string + (* Its tcl name *) + +val cCAMLtoTKtextVariable : textVariable -> tkArgs + (* Internal conversion function *) + +val handle : textVariable -> callback:(unit -> unit) -> unit + (* Callbacks on variable modifications *) + +val coerce : string -> textVariable + +(*-*) +val free : textVariable -> unit diff --git a/otherlibs/labltk/support/timer.ml b/otherlibs/labltk/support/timer.ml new file mode 100644 index 0000000..c58a4ee --- /dev/null +++ b/otherlibs/labltk/support/timer.ml @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: timer.ml,v 1.10 2002-09-12 10:12:26 furuse Exp $ *) + +(* Timers *) +open Support +open Protocol + +type tkTimer = int + +external internal_add_timer : int -> cbid -> tkTimer + = "camltk_add_timer" +external internal_rem_timer : tkTimer -> unit + = "camltk_rem_timer" + +type t = tkTimer * cbid (* the token and the cb id *) + +(* A timer is used only once, so we must clean the callback table *) +let add ~ms ~callback = + if !Protocol.debug then begin + prerr_string "Timer.add "; flush stderr; + end; + let id = new_function_id () in + if !Protocol.debug then begin + prerr_string "id="; prerr_cbid id; flush stderr; + end; + let wrapped _ = + clear_callback id; (* do it first in case f raises exception *) + callback() in + Hashtbl.add callback_naming_table id wrapped; + let t = internal_add_timer ms id in + if !Protocol.debug then begin + prerr_endline " done" + end; + t,id + +let set ~ms ~callback = ignore (add ~ms ~callback);; + +(* If the timer has never been used, there is a small space leak in + the C heap, where a copy of id has been stored *) +let remove (tkTimer, id) = + internal_rem_timer tkTimer; + clear_callback id + diff --git a/otherlibs/labltk/support/timer.mli b/otherlibs/labltk/support/timer.mli new file mode 100644 index 0000000..8084537 --- /dev/null +++ b/otherlibs/labltk/support/timer.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: timer.mli,v 1.8 2002-04-26 12:16:21 furuse Exp $ *) + +type t + +val add : ms:int -> callback:(unit -> unit) -> t +val set : ms:int -> callback:(unit -> unit) -> unit +val remove : t -> unit diff --git a/otherlibs/labltk/support/tkthread.ml b/otherlibs/labltk/support/tkthread.ml new file mode 100644 index 0000000..6cde27b --- /dev/null +++ b/otherlibs/labltk/support/tkthread.ml @@ -0,0 +1,67 @@ +(***********************************************************************) +(* *) +(* LablTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Jacques Garrigue, Nagoya University Mathematics Dept. *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tkthread.ml,v 1.3 2008-01-11 16:13:16 doligez Exp $ *) + +let jobs : (unit -> unit) Queue.t = Queue.create () +let m = Mutex.create () +let with_jobs f = + Mutex.lock m; let y = f jobs in Mutex.unlock m; y + +let loop_id = ref None +let gui_safe () = + !loop_id = Some(Thread.id (Thread.self ())) +let running () = + !loop_id <> None + +let has_jobs () = not (with_jobs Queue.is_empty) +let n_jobs () = with_jobs Queue.length +let do_next_job () = with_jobs Queue.take () +let async j x = with_jobs (Queue.add (fun () -> j x)) +let sync f x = + if !loop_id = None then failwith "Tkthread.sync"; + if gui_safe () then f x else + let m = Mutex.create () in + let res = ref None in + Mutex.lock m; + let c = Condition.create () in + let j x = + let y = f x in Mutex.lock m; res := Some y; Mutex.unlock m; + Condition.signal c + in + async j x; + Condition.wait c m; + match !res with Some y -> y | None -> assert false + +let rec job_timer () = + Timer.set ~ms:10 ~callback: + (fun () -> for i = 1 to n_jobs () do do_next_job () done; job_timer()) + +let thread_main () = + try + loop_id := Some (Thread.id (Thread.self ())); + ignore (Protocol.openTk()); + job_timer(); + Protocol.mainLoop(); + loop_id := None; + with exn -> + loop_id := None; + raise exn + +let start () = + let th = Thread.create thread_main () in + loop_id := Some (Thread.id th); + th + +let top = Widget.default_toplevel diff --git a/otherlibs/labltk/support/tkthread.mli b/otherlibs/labltk/support/tkthread.mli new file mode 100644 index 0000000..714f634 --- /dev/null +++ b/otherlibs/labltk/support/tkthread.mli @@ -0,0 +1,46 @@ +(***********************************************************************) +(* *) +(* LablTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Jacques Garrigue, Nagoya University Mathematics Dept. *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tkthread.mli,v 1.4 2008-01-11 16:13:16 doligez Exp $ *) + +(* Helper functions for using LablTk with threads. + To use, add tkthread.cmo or tkthread.cmx to your command line *) + +(** Start the main loop in a new GUI thread. Do not use recursively. *) +val start : unit -> Thread.t +(** The actual function executed in the GUI thread *) +val thread_main : unit -> unit +(** The toplevel widget (an alias of [Widget.default_toplevel]) *) +val top : Widget.toplevel Widget.widget + +(* Jobs are needed for Windows, as you cannot do GUI work from + another thread. This is apparently true on OSX/Aqua too. + And even using X11 some calls need to come from the main thread. + The basic idea is to either use async (if you don't need a result) + or sync whenever you call a Tk related function from another thread + (for instance with the threaded toplevel). + With sync, beware of deadlocks! +*) + +(** Add an asynchronous job (to do in the GUI thread) *) +val async : ('a -> unit) -> 'a -> unit +(** Add a synchronous job (to do in the GUI thread). + Raise [Failure "Tkthread.sync"] if there is no such thread. *) +val sync : ('a -> 'b) -> 'a -> 'b +(** Whether the current thread is the GUI thread. + Note that when using X11 it is generally safe to call + most Tk functions from other threads too. *) +val gui_safe : unit -> bool +(** Whether a GUI thread is running *) +val running : unit -> bool diff --git a/otherlibs/labltk/support/tkwait.ml b/otherlibs/labltk/support/tkwait.ml new file mode 100644 index 0000000..d263692 --- /dev/null +++ b/otherlibs/labltk/support/tkwait.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: tkwait.ml,v 1.7 2002-04-26 12:16:21 furuse Exp $ *) + +external internal_tracevis : string -> string -> unit + = "camltk_wait_vis" +external internal_tracedestroy : string -> string -> unit + = "camltk_wait_des" diff --git a/otherlibs/labltk/support/widget.ml b/otherlibs/labltk/support/widget.ml new file mode 100644 index 0000000..fbb0014 --- /dev/null +++ b/otherlibs/labltk/support/widget.ml @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: widget.ml,v 1.16 2002-04-26 12:16:22 furuse Exp $ *) + +(* Hack to permit having the different data type with the same name + [widget] for CamlTk and LablTk. *) +include Rawwidget +type 'a widget = 'a raw_widget +type any = raw_any diff --git a/otherlibs/labltk/support/widget.mli b/otherlibs/labltk/support/widget.mli new file mode 100644 index 0000000..9f04e57 --- /dev/null +++ b/otherlibs/labltk/support/widget.mli @@ -0,0 +1,109 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) + +(* $Id: widget.mli,v 1.7 2002-04-26 12:16:22 furuse Exp $ *) + +(* Support for widget manipulations *) + +type 'a widget = 'a Rawwidget.raw_widget + (* widget is an abstract type *) + +type any = Rawwidget.raw_any +and button +and canvas +and checkbutton +and entry +and frame +and label +and listbox +and menu +and menubutton +and message +and radiobutton +and scale +and scrollbar +and text +and toplevel + +val forget_type : 'a widget -> any widget +val coe : 'a widget -> any widget + +val default_toplevel : toplevel widget + (* [default_toplevel] is "." in Tk, the toplevel widget that is + always existing during a Tk session. Destroying [default_toplevel] + ends the main loop + *) + +val atom : parent: 'a widget -> name: string -> any widget + (* [atom parent name] returns the widget [parent.name]. The widget is + not created. Only its name is returned. In a given parent, there may + only exist one children for a given name. + This function should only be used to check the existence of a widget + with a known name. It doesn't add the widget to the internal tables + of CamlTk. + *) + +val name : 'a widget -> string + (* [name w] returns the name (tk "path") of a widget *) + +(*--*) +(* The following functions are used internally. + There is normally no need for them in users programs + *) + +val known_class : 'a widget -> string + (* [known_class w] returns the class of a widget (e.g. toplevel, frame), + as known by the CamlTk interface. + Not equivalent to "winfo w" in Tk. + *) + +val dummy : any widget + (* [dummy] is a widget used as context when we don't have any. + It is *not* a real widget. + *) + +val new_atom : parent:'a widget -> ?name: string -> string -> 'b widget + +val get_atom : string -> any widget + (* [get_atom path] returns the widget with Tk path [path] *) + +val remove : 'a widget -> unit + (* [remove w] removes widget from the internal tables *) + +(* Subtypes tables *) +val widget_any_table : string list +val widget_button_table : string list +val widget_canvas_table : string list +val widget_checkbutton_table : string list +val widget_entry_table : string list +val widget_frame_table : string list +val widget_label_table : string list +val widget_listbox_table : string list +val widget_menu_table : string list +val widget_menubutton_table : string list +val widget_message_table : string list +val widget_radiobutton_table : string list +val widget_scale_table : string list +val widget_scrollbar_table : string list +val widget_text_table : string list +val widget_toplevel_table : string list + +val chk_sub : string -> 'a list -> 'a -> unit +val check_class : 'a widget -> string list -> unit + (* Widget subtyping *) + +exception IllegalWidgetType of string + (* Raised when widget command applied illegally*) diff --git a/otherlibs/labltk/tkanim/.cvsignore b/otherlibs/labltk/tkanim/.cvsignore new file mode 100644 index 0000000..e1c7014 --- /dev/null +++ b/otherlibs/labltk/tkanim/.cvsignore @@ -0,0 +1,2 @@ +gifanimtest +gifanimtest-static diff --git a/otherlibs/labltk/tkanim/.depend b/otherlibs/labltk/tkanim/.depend new file mode 100644 index 0000000..6009347 --- /dev/null +++ b/otherlibs/labltk/tkanim/.depend @@ -0,0 +1,2 @@ +tkanim.cmo: tkanim.cmi +tkanim.cmx: tkanim.cmi diff --git a/otherlibs/labltk/tkanim/Makefile b/otherlibs/labltk/tkanim/Makefile new file mode 100644 index 0000000..574069e --- /dev/null +++ b/otherlibs/labltk/tkanim/Makefile @@ -0,0 +1,71 @@ +# tkAnimGIF.c used the function Tk_ImageObjCmd, which is not available +# in a plain Tk installation. Should we disable this subdirectory ? + +include ../support/Makefile.common + +COMPFLAGS=-I ../support -I ../camltk -I ../../unix -I ../../win32unix +CCFLAGS=-I../../../byterun -I../support $(TK_DEFS) $(SHAREDCCCOMPOPTS) + +all: tkanim.cma libtkanim.$(A) +opt: tkanim.cmxa libtkanim.$(A) +example: gifanimtest$(EXE) + +OBJS=tkanim.cmo +COBJS= cltkaniminit.$(O) tkAnimGIF.$(O) + +tkanim.cma: $(OBJS) + $(MKLIB) -ocamlc '$(CAMLC)' -o tkanim $(OBJS) + +tkanim.cmxa: $(OBJS:.cmo=.cmx) + $(MKLIB) -ocamlopt '$(CAMLOPT)' -o tkanim $(OBJS:.cmo=.cmx) + +libtkanim.$(A): $(COBJS) + $(MKLIB) -o tkanim $(COBJS) + +gifanimtest-static$(EXE): all gifanimtest.cmo + $(CAMLC) -custom -o $@ -I ../lib -I ../support -I ../../win32unix -I ../../unix -dllpath ../support -dllpath . unix.cma -ccopt -L. $(LIBNAME).cma tkanim.cma gifanimtest.cmo + +# dynamic loading +gifanimtest$(EXE): all gifanimtest.cmo + $(CAMLC) -o $@ -I ../lib -I ../support -I ../../win32unix -I ../../unix -dllpath ../support -dllpath . unix.cma $(LIBNAME).cma tkanim.cma gifanimtest.cmo + +#animwish: $(TKANIM_LIB) tkAppInit.o +# $(CC) -o $@ tkAppInit.o $(TK_LINK) $(X11_LINK) \ +# -L. -ltkanim $(LIBS) + +$(OBJS) $(OBJS:.cmo=.cmi): ../lib/$(LIBNAME).cma + +$(OBJS:.cmo=.cmx): ../lib/$(LIBNAME).cmxa + +clean: + rm -f *.cm* *.$(O) *.$(A) dlltkanim$(EXT_DLL) gifanimtest$(EXE) gifanimtest-static$(EXE) + +.SUFFIXES : +.SUFFIXES : .mli .ml .cmi .cmo .mlp .cmx .c .$(O) + +.mli.cmi: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLCOMP) $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.c.$(O): + $(BYTECC) $(BYTECCCOMPOPTS) $(CCFLAGS) -c $< + + +install: + cp tkanim.cma *.cmi *.mli libtkanim.$(A) $(INSTALLDIR) + if [ -f dlltkanim$(EXT_DLL) ]; then \ + cp dlltkanim$(EXT_DLL) $(STUBLIBDIR)/; \ + fi + +installopt: + cp tkanim.cmxa tkanim.$(A) $(INSTALLDIR) + +depend: tkanim.ml + $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/otherlibs/labltk/tkanim/Makefile.nt b/otherlibs/labltk/tkanim/Makefile.nt new file mode 100644 index 0000000..2b0b5ab --- /dev/null +++ b/otherlibs/labltk/tkanim/Makefile.nt @@ -0,0 +1 @@ +include Makefile diff --git a/otherlibs/labltk/tkanim/README b/otherlibs/labltk/tkanim/README new file mode 100644 index 0000000..175401f --- /dev/null +++ b/otherlibs/labltk/tkanim/README @@ -0,0 +1,5 @@ +This ML code is an interface for Tkanim Tcl/Tk extension. Unfortunately +it is still test implementation. Look example directory for an example. + +The codes under this directory are mainly written by Jun Furuse +(Jun.Furuse@inria.fr). diff --git a/otherlibs/labltk/tkanim/cltkaniminit.c b/otherlibs/labltk/tkanim/cltkaniminit.c new file mode 100644 index 0000000..a45bedc --- /dev/null +++ b/otherlibs/labltk/tkanim/cltkaniminit.c @@ -0,0 +1,28 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ +#include <tk.h> +#include <mlvalues.h> +#include "camltk.h" + +extern int Tkanim_Init(Tcl_Interp *); + +CAMLprim value tkanim_init (rien) /* ML */ + value rien; +{ + if (Tkanim_Init(cltclinterp) != TCL_OK) + tk_error ("Can't initialize TkAnim"); + return Val_unit; +} diff --git a/otherlibs/labltk/tkanim/gifanimtest.ml b/otherlibs/labltk/tkanim/gifanimtest.ml new file mode 100644 index 0000000..5b79985 --- /dev/null +++ b/otherlibs/labltk/tkanim/gifanimtest.ml @@ -0,0 +1,71 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget +open Tkanim +open Tk + +let main () = + let file = ref "" in + Arg.parse [] (fun s -> file := s) + "usage: gifanimtest file (animated gif)\n\ + \tbutton 1 toggles the animation,\n\ + \tbutton 2 displays the next frame,\n\ + \tbutton 3 quits."; + let t = openTk () in + + (* First of all, you must initialize the extension. *) + Tkanim.init (); + + prerr_endline !file; + + (* Then load the animated gif. *) + let anim = Tkanim.create !file in + prerr_endline "load done"; + + (* Check it is really animated or not. *) + match anim with + | Still x -> + (* Use whatever you want in CamlTk with this ImagePhoto. *) + prerr_endline "Sorry, it is not an animated GIF." + + | Animated x -> + (* OK, let's animate it. *) + let l = Label.create t [] in + pack [l] []; + + (* animate returns an interface function. *) + let f = animate l x in + + (* Button1 toggles the animation *) + bind l [[], ButtonPressDetail 1] (BindSet ([], (fun _ -> + f false))); + + (* Button2 displays the next frame. *) + bind l [[], ButtonPressDetail 2] (BindSet ([], (fun _ -> + f true))); + + (* Button3 quits. *) + bind l [[], ButtonPressDetail 3] (BindSet ([], (fun _ -> + closeTk ()))); + + (* start the animation *) + f false; + + (* Go to the main loop. *) + mainLoop () + +let _ = Printexc.print main () diff --git a/otherlibs/labltk/tkanim/libtkanim.clib b/otherlibs/labltk/tkanim/libtkanim.clib new file mode 100644 index 0000000..0db9d16 --- /dev/null +++ b/otherlibs/labltk/tkanim/libtkanim.clib @@ -0,0 +1 @@ +cltkaniminit.o tkAnimGIF.o diff --git a/otherlibs/labltk/tkanim/mmm.anim.gif b/otherlibs/labltk/tkanim/mmm.anim.gif new file mode 100644 index 0000000000000000000000000000000000000000..2cddf81958f292b6081d8a771a1a68790a09e5c4 GIT binary patch literal 18501 zcmb@ubyOQ#*X|o9MhGFeG`K_1;>8K>?(QzdN(t`n?(SA-X^T58QVMOM1*%l3?Rxi3 z-~E1jzu!4~pYz>u?;3-VjEs;!vYs{PGw1xR=;&(8$-AloQ~~b+zm}w=q?wsnR8*8y zrIca0p?RZuP+m}QM{pix_2>2V_w~*9t*x&;dGdtvX3pPHMp_o;8fqq5l43+K@YhRU zAc;uIqX^}X@}a7LS<2)8s}F_z#4hP}UzK~Ye&zQDdTE$zoj145%uGW_Vak5P)aTBg zsSSeszN_jL5k2`?H(-ij!t{(wtSWUjU|Mwik!baFu`~dVE+cJ|pW5P^R`uNm*V%E8 zvg9SOj|LOTNy#Z3qSX4-Sy?D%5H$i?R18I3OvRbFLg2Z0m0(xN3Q^ZcemFG{MeW)t z&`d_SNI2>@R`Z`XM_9Vm5k$v{dYW|IK@;Ki;i!QHwyW|`7_zKl@6O$O`v>>$m*0(0 zLr>8oFthx6_Ym!Jog&n4h=_m`QQtNxTzBsTtbtmgNIwS&K(KTqdp_o1;BzG?e8D}* z6Q?r+l_K4!sU>26UjEEOY6w=9qv>`KC2aK^W=h2^oZ$920m}rvM9yaVM>ilqZ}>H( z%IVrp|N6237IW9B8U<)y$X-P=-8v#1E3kJt#kf9TsjTON#)s-V!#>+xj;mw6_b!E? zzHAbw$lHa{>z?{k0J8ISNC*4mVRAc5dIbrh8yQxbOynCyM2D87qD;RJtgo~ZhEry$ zG0*5n^qdQ(J#h>U$tOAb3pl&PIdXf!T+(e7;kvY$L~qqE4plb3@12XXAvUNX*A;0X zNiv+c5n)qc!d6=J(aPiV;}X~F8Z8c!DNg*>87w9X(I3I#Vs6xmyQ4*Vv*{?qNBe>` zfO_S^hKpERxW$o)0mG$n9x$zWbc$*8=9;!D+o0g6U7+&F2*!=2r^wkw*!1+4pMpHS zV;Gy82?1TZKU*(gZUVT)_ElhUI&d^6Z7rSb`q|usJ=3x{YEKm4YBGyIwAQ(U-l#>~ zZt-c-74(Y&$RuQrYUYIgz^mFirU^c&@W^8Z{_hH&`$NG-Mn>n)pQjuPQZ>oE#XK}O zG`Ksspr9acIB#HZpmeUZce!_UZFS@E#_Kn)f2sd}yr4e`ggg)5I-jn-fEU*Wm_=w@ zADjmwJcwv4+v}<9!9;Z9I~edYLvHJat0okO5mY-0A*8_5)mI`l1Jg7kd2Di8QR#;# zJNL&EAGo|7<;)@?P%twn3dL)jY(|ygFOUun&o3!0D;Ec1vD7qm*m^^L5C%onj%Wu1 zEBFxDlqj?x*Ex)?87!|Na9rP8jv57~8Pr28AQSU#F6cYjOhw7I#$ljmQLEyhBs=&l zH#jMH;s^kG7$kp1H138T64lfD@wZQ(zkL1n{Y(FzKF0>v+lN3UY4AHlqDc@UiHc`y zb7Sl9ehy(9E=Q`MT9SscN$^Gki0&0<Ui@Tx(h%mW$}Z?uQnE7CqAJ9Od8W+8Ye-5K z+nr*Y3?+~^i&i++8%{RVK>pO%<wr*o4_MSRf+J`*d$T39{o*?`y0+)*I^-USnwRgS zan_z25GrUF-EIti3V(g1alV2lI|&Jgo%bPc>i)n9JFSfmK3pu|)~}0q3qG1bjA;eX zx!kB3`jq$~0tJlFk<!CdEJO^pU|~%kX6z(4>Jq7%LzR5^CC-wiKRb<HeM@K&9XYQ) z<dnFXhY1zCzB2N3>yy8xij$#~Mew7L`dA!+v8h3}Ro0-CBu?1yy!V0LexYRM(50f# zE~rW3;tu%(t82?s9mZ6-)RHjEwO$uTW*-?M2V-c9WoDcmK;{88?7Pl7QIK}(fW>;U zMHA>a{>WLI!)V7KjBsBoEz5D74+=6q2?bzYO`Ya3gbqj=2{N-6m?)gve`b{@>M)p? z^KzqUDf+C370MpKwWQ8!l0;XenT?mshr2<e7X1WWT2qxgJBN9gUqy`Vnga`bQ_ns* z)oHbdVWTnv*%ykfHMOVj<P%;n6L;%M1T$^D!pxpLYc9}6+QR?we3+P+#Kpx?&WBE| zj%ABwWOig=XJAorQQlDA;P7D0d`;hS-^%LB-ow5Bujc~|p2J4hotq}{=O^Wv*vvU4 z0YjGNIN8qWNVQ|xEJw85?Ly@68mT3=4oo3wbEDF%B2(*6kG<=Tvk<YEK^PBRq#-Pv zTQ`WTpk;M||6(wz0HmDr>wNI&qOd*?7#xYlNP<u_G^&La{L&bjC^;lJ!8XKzx?2TI z12>0zD_|1G6j17Q!(|sSQwGKe%)-E6c(A-*jx8z*sSSv@cg-&?(IT4|h`MTCP(1PG z^zFO%A94c0prY3w#ig<KhAD*&5>wL(Lf^uEkV6bM1OS1!{g5cJ@^fzHY)nGYA*8DF zwhIQ_8-|DlMfsnYp0Dp4Y?%_}S0dJ2MQ^vtI>*O^ZV;`CgC4u_PByLI010duN!k`r zVToY+e35Eh&pb}j09ItY{k72$_elwk%){ko$Ty^kh2RCdP|DXBEGEBZ2wscMb4Yl; zfM>l<ukkyQ!(e>iXf}gR*o%h%Oj#`8yjZFxm)Xq+CA_?Hw_6nmc6;_E`DC;Du9Y%^ zP*LNb=3cJB!jmmvrjtCivOhVrJ+F5;)8KpG3?e>@Yzn!u5Nf|H0~u7nKk|ht?kO5x z(Lpw=Rb>Kimk!~Lr5|N3*IT3sAIWF|wNF;kZ;1e|(L^ayS1j*3+g15JaT(>h9qLrV zXmoL`qSDJ)*g~Gx&`80eoyDBIVZAKbY09}~O1)CPXbV5QeUmdPy3sH#b1#wuGXq^R zb?~p{U1Ez+;^jgyEzkqx-^v$HDXY;oxS+KLA5uFC6t%#t;qg}U^d}^_GUvmQOC*5J z^VtgAPkHWLxL5CRx#QVBQ`A}e!o<g%;1b_Ve`Re_nOjWf6Aqr3@h`jR=&^~t`b3zY z&EK4bf4d!1GgG@LyO`J*%5gBLHL!2A|CKIUg0r%+^1JeT`+64^7XC;N|LJxP=>>R( z@jh9SINdrS+zod`_vh&nSe}?v{?t6_Gg1MT7rIoLpte5X@qsxCqW<=?xrb|JN2+Si zaUVpLpl?Hr?VMBRyg!aN&`5ISf;|7_b^u^8Y8`5Npauj4x|qUpKEnZuIB%dLQbaEn z6e4#PYK?4ev2?8k)CcPXMH`ldw+SE$$uezyDgyz=DhdI10#u;H%h3*T<J~uIZftIC zv*jSE_xO+nx6ag;%7bxfyh2p#H_dmw<P&&2UXm6!F2|P%Yc>kPd{5GcKKaz%J=<@t z%&U|5!v<@tLj#5)3TK<eG4-bO;$$v*3C2S5Phln>wI$Cy2HRtp=Sl_y#q8wmAf_rv zs=b<my6rJd_XY>9^%!eJ6`|YYVeiu_Lmui>t&^$tzrQR~Q#Dc9@9;ZV8SUQfce$>D zyrSlq3<+zIZP2h%-+&%kJSs7HlgOrW3lnw}@zmnFk8yeHN%q6Ck%nEHK9j{$13jMy zuTKad;tdn^kE$!{-mT3%!^-Yuieayr-I~8yEOnNGQ_<eNdR9&>!xi57vcI|QhmEYb zXL^#}yPn<76b6^S=!u_C_gIF`qb508Rt=Zgk<M=qNdh72g@ax(uFA?LZ7bitj)Y#D zTh)C%e(BrZLnnP7X+_r(#^M-eGg-W?J|~V9JrQaTr+YhwVArEAQ9TFb;n(K-l-UAH zwAb{UAt&MIi!g;mb$~ou)bT;QIk~if8K!!P(^gBSJu$@<N>t4ZeB9v<r~L=-Eh8hN ztgCEkX=xT=78n03J{#5;`d0adG=@;jOKxj!dwctzPUSz<=)xe-GDFbr;^U3!&=fFt zU+sv_Dmc$^v%xO&?F>5;ik_>}ZXW}5(OJ@eghpwpO|MCeEvG~bk2>bxof-3%V_2wD zTm7IQM-LuPxJhMZC=WNq0l~oJ3moB^)-Vwzc~B-xn5dP!Bb9@ku1PUNDX*g*x;nSD zww~@{j+1YqlOGa61+VWZmxH6b%u=sTP0!4lHS(d1T4UzS!<z+%cq366bDm0C6{2_Q z*0S&P4d|^cwB_0iTaV3V3uyQ1G^51NP4#%Ad-H0LAEtMC>X`Q|RnO#!|3KfWo?AJX zmget^zw=Igi$5`fr%mwLz`C~5m#a@I%tJjAS!BNGNq|jm9IBQIOJo?>ings+%Y{GR zUoLK}$y65K_b;B(HBrA2#zu?~J+oBtI7|ju5y&jh%5L6JC>zA9S}w@pX<@p3zbV}Q zPK(V{fKRi?@kp7ar4eB{(Hf7HN_%8b9KmyMt@f4?*YY((A*4H0Olxk`jIqJS`?mH& z?$asxn73{3u<`l*9%`I0CT;SSV-AsM7eQhnh>lRw<@VduZkd*bQfpiBj%H5eD(<tN z<iRkDCv(KMV!hB_yGowIhAmS>Ypc=L^!IyG`8|P5_^m#dkp4sRhj#(XukyZ>O1&zH zy|~RY^;+lsi#OQ6vAw@S8KX3#n3$N1k&L2`q9J9)83qIdNLNamRhtFY2F5nVmX?+l zHy1ZIH&fpHmw1M;RNN6Bx{^N62_i);Nc)NpRxQ5UW60r=l&THfjD%Y+?A=p49&L@r zsihE}D9o+b^Qw^M5w4)r^+5)yfdV^E8O`V8@nZPqB}qhySnKmBWfc)bJl|Pu0}&Fn zfi*CdJ%AL1wiXpfq!cixyO)XB28s&8!PSgW=k3w$G9W0FYKY3WckI&m1aqeq5<_*F zcQTQvJk6M(2oKf~abCpLdac+Nw`~Bn1TL;5CC5z{DPBa9Dv^7~x);mDTNlkOidXM9 zE9_3Zt@B(@7C=^o`F6iUsCDQydyub`>RDtbTl%TFCsUCn0+u@DmXZdW7xS+WG_u%q zfpZmSQCjbYS_qF9U6n#ea~+{O=NQEzcOIobGF|kTn}nvc1>fbxXL>ysx@^dNRr7Nm zwE;eyV}ZQykXTi|ZKcumh=r4w`09n6er`fbGpJ0rIgaj5UiY&m+#UDlsvqA!Z4u^a z6F^>D&QjICWuMr4D$Er9te2d1hU;MSmiU<^C{2QyYo(FKWh(y2v=0-k7)pMA9WRHv zadSt+CbMPFjSOz>&y^;frttu#XfL471aX4?cUSkX?H6Md6%`fK7bJQUDO~~0P|eWL zP}xdZ^J??Z>d=ISgqqr#f~JC|rl$YC{Q_DKb9B7xo=Ef=B@+UZZbVG?i65^-+`Mx( z9aKn~#9!mlp7I%TfTu|`!Ug(qUg4`DO!U;L>WQM^6E0yf>p|WYm!L_9Vzah6?g=KJ zfWhWk;TL3#M8Xgz)DbECb`GLC8E9B8zqh?}nKBg>bu9tvSKZRuR(4+4x1GO}I|GAm z?qTX16h~p;!z1(;MZ^)8bFMO6m($Uvr2R1`xCTmV?V4kvrUo3fdJB-BE*`T%I=Ju6 zou!D1Kgci8$(p?S+QFF`4Sj4|VYs>f74SK-kZPb|IvGxj#Gbxs=!Jd3-7TWqbj8}x z16ATVQ)(6nS;s8n#OMHs5`?<5^wxYRcB)kV-RZ`qtqcq|ByNX?OTcrmRs+vNxJ@lU z>jQv7XlJBsjI0dAaD^HzX7ZwE(|EA$i2}pH!X0{K+2Sfi7t=?HZxJ7BmIV}92419{ zh*mIieR%7R(5_U8H992g3K4DilR@oDqI@Pkh~&iTcs+sB(3#b*Tz``ZW+)pZB_*Y& zrxzR?oRN_+F)^{Wwnljod<?(5|C6|)+ewrwUy0+de3IKj=cU=1x9f}cccAX$T#B}M z85i|*N-I%E1d_DWf-_MR3+*j_&kUaE7_S1dvi_#NztgaU>V_px-C7H}LMGq6XC5;B zL`wd?*_AiEk^HO|ai*N-QfSh+GO<?t8M$Z>nNzR`qv=vX?GagCgDk1@uc?C;Hg<LQ z^xF7=d=k2{nfhXTF7%cP^yXK0OI!DZigngp?wMq2=(^5)&9G-wd|PI{aresj4VlFv z_ozANsjjMxm8Y=Q3J<2?8h4Mqigz9l>pput$ZbFE1Jv{U&DZg(q{m6&WMpMH^f_d0 zWQqPna|?65AidbwSeXhL<9uU_W()sJ|In_`va+)L!Tg@lp8lo&jm?d3-@Z})_y4;7 zv!oY>nTr^w`9JW+8D^?1;%ZJANJRYA1#vzm1?zN35vQY3(#-(D5NR_yoWHp~gBESZ z{n;$hD_U^vXxq4ZZyq(xWZlH!=upa5m<t+O+R7^WY3g8SM}Pg)Trm*R0vT!<U#em1 zl2X@9IRfpX4vObWIs`!y$q{{mP(5XoRpbcoMMng-c9JL7Ik9+_*W3(I)U(VDB_VvX z&jB|84$A0CE4n*?12Z`3h7|UW&m-sXbMPa84~7(X`7Iah$%D^4FdV>>6awh4ryKz~ z7Rke@DJ3d*^iK^w2{KOm2b$^dgS+(@*fn;%cvHxpEaR7!;>q36QdgQJOt(Qd(Lycl z?0jQ6qusmes`s5NL)HnY{UMI&GEIZAHC8PjDm>edG-^8_iS$P8o|i{fX~YIcsDFDA zW4Yi?QPi5OQSt832yw7^qUAXe_*J^~0&@^I3lF0NOzV(9x5>mY99Xiv;35xuP?koQ zczBvp^cl{*(J>I-iv9brM%i{nM@3<GVM<KX2+_E3;Q}S485S4@rUn+47M66CjEszI zY;64a@q@C@e`U2e-ZbvK6z@9K5VqBfo^HuJn4kZtD^u`|8%<k*a%xQ0ne;P<?f`c6 zrrrUAnKD@S&|3>qFgb+A-^7OoAy)7<&{-9c9Q!2l-kaB|G(U2V4V4v@R3uepE^@@_ zyUQD?MrN>p^;K--;dv2-%pe;(4{u-N^lAY}oKHA+L2GYc|G=OC(3Yygc!-%(%({zf zf?jBB(%Kj^MHj25*fBf41c(b=kH0ykLlTEKE-YEpk0lck2NM>f)@$;QZVx~ej*p%b zQ&oq6q0inas))XtfZ!ep&py(-%Dh4J7z}&itd54jA<?A4rul59bgavOiyE`lB=h-! z?GoBEIR@N(Ry+-WlqP<ZfLCSn((Yi&jCK=?d=j;^Clx-#H_a?X&t+!g^!>DXim`|L z6Z*I?>0OS_hjr44Z30f>T_*j08j%~md!cu45QtXvWuj?!C(9yFrOOJF#%4N4@7&&z zw<rr+>;3k;#;)+i-pcclh)NZEE%t!iNHLDe+IV+~+f>iZ9xeC#AhHw`LeF@N!m8f( zeB^|KX&<w^f4}i)SB6(BsJb>3lp&8&{f)zj%?9%K`!6mouBfMIU}|6#X++t4iX}G5 zHwj1!C@d`O@9*E<-hTG%*`Fu;ul@f<t=UNAF^~2+%k*-vWNrFJ08mP;%U<{bUbSi? zF}jc;tG38RZpn*k4s9B}g+(m5U11V1mGq1B0f1U(&YXYoBM1aO1O)L`t@||kTn+hV z3Wgw%;TO}=GZ<n-xp^;S3aOm;FobIJ@E0&E7sVK9z;o@9@>TSb=d!I;BSjJMfo%X+ zuikU#yJX^ZhZMo^UQOh{)%k_RrR9sEQ<sU56?z~S(Oq5Z<|d%VGjDo^IJpdp9W9~C z)mhmWaVzP|L$xjl*PGWtJ!ExImGcJYwhROdvf=eQR{=0i?uEOhuKrn@b^^Xz*ogSp z<*CvqMxgYcCQiL?z0o%+(^T7_ii9G4P#`m?Lh0e$R#iFimn9x<zgf@FMo++^o<Xn> z+nEAyyy~#viNPrwQNRdb>F2VhFKdWQ3Ypjt-C+Q%sNf!mSY~Sntq`CDjr$o3uWy_U z$txLUUwXc8E2@<}c%}4>V@I@o+~Dv-UFXTEq34lFLz3BLqM3%ko@9VCakPB?V-ap% zheOD9I7d1S*+MTdt?v1Kv7)GAKz1VI_AP}V>hN8=p-rFk!+FKjk8C{mHyGZn#D}~S z3!3EONW)H4T)unfwU877cX&VbWtVcvnPO+!`@B^KQmFtesrtgIaigw=b}-U~uiz!Z z1HSMe5yH@6{tr^3Og4;+jjThg<1fThbVNxUL8(EMx@vfMczJpGPZ9m`<S!{*!9d77 zh@;vn7kq#kPgW60$A4H{zFFzQaGJ@pPbiAtH3E<Xa8|u0xzS7~MODBTgcP$>&NsbX zQm%sJWIH){%SDH=6k;R?^yy^6%{OnVwX6`oT2wAzw~(ZiRG%zSHDg(-0y!OE9sp!e ztXZp}scn4$XyOvl)B&m^E5NI4ddy&>q8>a0gI6Z6Uc25pVxTic2LwkDB`Sk8xfG(W z)yTr&5=e+pJ#?r4n%%jMGFf?^%E9#`vs?A!yw6M`O?#mZ^#>DG+iLIZZ#llolYS01 zGP^F}vT($G<gHg@a>In3t?i)$hq>IGJa8CMAf@*6vfFymJK~%?_TfIK;O*&L0B}i@ zFt9ZA@9HY1knbjPab_I#C0w;tA}Ri7STez08o=>8t$ml5)~LT1Ul^T7+b&KI(ubJZ zGuqg8++O1JsS0Gf6ejFW{#G7x?_TGXCrR{f=TY2FbiA$4UvLRdM!n!Vpu=Cn<4LXp zzLC2-G<P}-=0cc1<;>Zt+)YwdP@oCt8PEGo%_3f5usc4%g65ia`3n2FLyo(moslII zDwtHC$VOAVyGptL11#F>-i9($<;^x>h+puyUW}%WCXEFgAh3F@{E%;Iuh>{RIdj3! z{wYLLMj|dVARzU1JM?FSe9;XSpL2nzLv4zbd=AM>ntx+S{@pn;H#etv5Q>zHij0D? zgD4H7o}QlnMMwXun&N0?Bp^;PP-tV<d<bC)&*XoVB{-mJ<my<m%gv{=(<H_9!!aI~ zG@*T<pA=VtuHIo3mbyc$pHRYu>)B(^+MzB2tq+h?LrZHXBBE}-`SyDv1NgiQR6c^t z2=Y=30wjB#lLu!?x}>U6r9h|((}+}LDdF5|%``5@I{C&68o6NiP?e56pm||UL+J&A z`;g<bBfMntS72IMjdX-TJ+<do2x2#V@U>p`@Qg)Jn<#PqaN;s?X}BWy(i78|$>u^> zrA3?YtOEHlWWz{I7VQ{IHCtWJ`9X}nf$L>mR{X`=AN-{UOjy0&V?NsAp$sjgpVMy2 zTV61GTnxlz^NRrgQVN!S!ch3_LOBQHjXEVnrw%<SdMydbt~b)L*-R=HYUP`%T5iQb zlu*e=J^-vZWIw{k^G>m%6}pH=QjqyN3(UnK({8YSA-G*~w8&5F<)yd}EXrYvf{TM$ zF*-Tx^D8!M+T)+Yq?iUpv4)nC9J+HiooN+i3DwK(=`@Q8$m@^~6Sjd3avx45=f-<` z&XnYid17FnMbE^jYF2me%pWl~#0ky5`+<3Tcn5CxN{zbv)f<8xU42+>>X%c?!26{3 zyMZ^mwe4)Je5I%xJT554KH>l-igCDY2eJ1Tg0E72F>l~b3eV?<R&>84xUE@2R%Yr5 z=FdLROQV2PmQaY({9ZEN%I7GR$?u;kdTD8CYisL28ug~drXjf@dHH#5ZEgP-iCw9m z<~P$&tMQQ_km#9wYB)%8VXY$Fvj8|>Z9#|}Jg8!Sx#1QwX4*D1TIg#*ky_3j)~Sw; zr$=@<3fX5xyX3}zlNMufl5&ajd%pq}H#nSLRU<k<%voJno6f{VUpfr{jN<o_3@DMv zO(}>Imr~Bi({zt)QjjKd)R#J{01eflVRRs>_HvoRe+4W`JBR@YiqwL^pu<#C14}Cq zn1~L(xU4GsYNev|`snz9=oQdWZzN}NbG~)Lev0x!*<RJ<_{XjvAVQZ8s?}3JgrKyb z<rRXVBb>}5bEPU5RaQ(YWnQNVSPyVmxtRxUUD5xER3?_(Zf#~Uau>Q4Lo%gL({-DJ zSAc~p4XfG2qbFnDmzBDzCjTk1uYyrM8LQ1>WsO5mdn$Ulc7(pueL`il`ogb~KQkpa z_1n01m<~LCrhA3t@oA^?v$lI_NukZM-KN;<TkSU5pd9|?8q9E-k(pp-@PUeS0=oU# zI|-KdOEDi*lrmPtX(6`na}2BooNZ-Y%wCzUX+G%b4?uG-G*#xlxUnd!@slpK^2Brv z7HyFGX~D<3X!d(bC5tpJ$O^W^TKazR&1{#JPt?cRuo-X=55`s2&EwQBM31pN1=|V- z+V|`&eO8u^TRx|ZetGPr5Y^7G$D4G<k`)hLA}g#zG5}~hC{r?)1?<Yc0BF0F%H-8? zl*Z;p`wyKXO54c5z#t+bf)dJ1OHD(HL-LFAJ32c4Z#w(^FcPoni<=LDm$}psvml)3 z=ROlRrZRq~a>~VxS0b;SIdV~At}xtpB|^|nZS8$bmSV|td?%kE)C;@<*<n-11yngU zwtaWse4bRnV@;%VB@E)|L5{=_&2+iQSTQGlL4_c`z=+WEWM>7R0s(^y26`k7(-1{m zxRY@OU0QajKWhRQ1iCPka`_LPT^<vH&l|w6r%{yVqcB0I<pke|8xR0X(O2c%O|dS3 zDbO9(>0gZ5sw)CMH*#``Zrg<%?}yY9kIz5m?J3Cs1mRkFoN{B#zs78FscEV3_o~#$ zPq#1tJYT@HxZy2!FpZzs_JPJvtyM^}4ws**kI76oXthkOvqCL3&+bydC>^ec;<5hJ zndbLsrLHE!Veb2}qwm3~^fz;9esI2!k$@HTraqI|nitL1mKCUNxc5*jog{1PYC=~w zrin}r)X`esjx5O{M$&e!c^K{250!rq`0&mkwPD=(oe#2S7KhF=>*LT&hP*q759#CF z{C-q;2iT2S?@^RZQ5PkvC7aFrh-RoZ(*91mm3%*og|Ke)7X0O1Fu>tZwD-;lAN|@X zT9$pM2<(^DU{=_3eylO*^_ja|%ulz%rXO;1p5Jx3`@j&HmgU`FFxe1@zJS=Dd|t5@ zYi+Q^F}Gsy%ykM%?yw<hsmt97Lz!W<1&&fEp{x=5Pkn77k!Wme92OS#%XZZm+cesQ z)`o^RhnH29<+tZ|bau?m{i^c+SpVU?C`<{Drf*eNqUgd2gZ`3ehJU%9Bve220jjh| zU4fG!%lTwLZjWK(uDBeY$1qjX4Z!4B$~T)NtV<|GhVdVv{ZsLxOoea<Sa!-$qRFEM zlMs#Ml+?6z0uTrSg28sI%Bl((^hJ8aC_LC%Pp6by+yxaSB3>@*mKwkhvkP;P)yXyy zJxf(WK&S}VRRQt?n<sGG9qsHjR8;c)rT?0;+}gR#n3ZpbLhl4j_Ri7QoFn?(M3|W; z&7%gpZZ;0qhmH-pm$nV^BGe!8L#JxL%J?KIfQVBWv?h;IKmtB<WS3{hr30+BWjPYz zSb`w)&vynJonU|GOeNgu__sptl)8`~S*=p?{^^z3VjU3!W}&FUv~zhi#RR}HjRTwd z@hPvmJ`f!DbuuZUw`-@{X86CREQ6q=<HdX<UoQZ!NusJxTGL}DEF==Wx~RyUJD2er z3893F4A+xxdDEfEF(^5YdfD{2E$=Lz`*`Aw2w-98Hx9Q^V@c0q8XCb1IwzjplYAo9 z%Ng5Hu{p6kRU_ryR%MVI<Swz8vEVhaN)5z2@QTBTDN%{q=ys@3#RCI2=K1mX**?1Q zu^ySquiT4ag6cU@zdid+S#n|RUT^O-!GM$3U4m>rGLU`UKPdk@y)&XD)Ei<hV*z_; z%DWxXd8nb8$TXNd4Pcx&rh}qK+pGf@Y)AmQm$aewQKP<%bqE8Q(nTf^(M>0v-XtPP ziqYV42Di{qMh1gaTL;NT>9=PO^HpJ;YX49VP)bXRD*wQz49X3xo2-L#gF`z*b8>PD zx(j;yd+Vm^hGvJ>Z>&Fh^yt5-l2?vGI<<3WWF=o)z=mbMyWfdMXXjq0I_Mb^Xh3Hl z-y8`6(q+!R8DP2Xl%*w;ZPSDV9}qUHtrUTeI|oP(O9y8@E72AdZ>YJPdr5I{<OGl| z#t?&{p+PZ&X{exug?tEL5(AGD1fD|&L}0Y_UCNStiB2_2)Z$P?Q*UhoQiWev2~|Zz zxS9+&2XUrc@4}}{RH?NBfJ*&xuxaVgG1MykI%v0?LOMM-JUTvTy?21QB~Go5U#Ge5 zKXhQN55wH!J~>PE<f8AX9LthI+baDfC~pMqKsz;FDUt6pRIeeJtRkX|t5ZEpq|XEW zME*RTs+dDnv%1cZrb8QUp2OGd7j(A1P~`=V6IdD^l8>`_>WWkYN)OinV&-368_si~ zjMb$>Q#uoeALW896yO<lFV(d{P&A>Tv^CvK)wk%7wjr>FLOMNMsnx&KcW@>8Mc-a{ zRC=<63260wTLUm@7LH~TNIV4IMC6I#;5aclX(~n)WgD{(teoO#7&uX3rRtKT6AP&r zdq*D~<~P~VvEAhL0LzWKU#x0ZUZ)SI$1QOIOCGV33^?hosTzaw1#sV^sWUneP>pGY z3WR&2HX&aFa*pir#dDQEK;_Cx(1JJKv-#TLh&WMGHlc^kL@^<@y9C@*lHw4}{^61d z&e!w22E%&D;#MGIK<cKGI>MVyYMkwoov|r!p4IR2>5RS6#>gc#mIs`JRmpvpW>hrq zv_=|XI_tX*P+I{K08gI-JVt@BK5C!`)ckfy%^7=n`S28(GCO2NMP&??p6-Ta&O`-s zinR7)JdD@{O_g={IXDGOXAeoVi*dyQDgze;pVma&Uj92-|B9lNU`v_){2PC&B3ZXu zN90C?^n~Q*=H`#&4-O4h%vB7o4N}0sttVTrUcdUUxcfhP{LfzLf8kGZJO$GQs&f0T zjPBHgtcESGL`ZD*g5;h+lNSbzIa)G8z;w(iNcfV}6bk+%l7vcc*wu;;eSLqbmzwLA z1OjzI78=ACm+XuH^8!KOaDOgT4zReQvZ|W+3xT4hX=<t$2*gq$sCv4}Ym`t}@AGIB zHyG^Z47)TCh)x*AfN4f#9rWRv6$nh!S*T;E*?BqNiEe#lzXUKT0hP<8f^v6;qx$cl zHg>Ox#XXfpqSkmpWd{S_fBgI%07kOOoupqO&@2=#L62NGqkrT<zRes0^ObkX<WBjg zfLMPB8^Dd^lPPEO;3r23Tbci^j5Jo_L_uKP6-yPG#KaWhqMICNb=RY1cYc~3iV0ni zkJ2E|a6PymFg>xzOR}7Z|A2P$$!#b~y9I1`IB%DvUocX&zuT0narP7L4*s3=3xFLI zN$B_#p;a9N*_wv{mJRQNV9zIL7t72oz_8!MI1C1c9<NqN`QKlg7=C&)gQ1-Epu(_K zPXz+Vg}XKx@n=L#Tyu39b+;7`CPWVy)1>S}=E5R~7R%ra<pcu>Ku7(wA~gEpT`9#S z^0g{Zw1)yzHnA)`IN;Il;AcFPwRm^DIL|qW>ZlYe9N?4*x@YCpL*@Gr*zA4V*TRmL z-Lf60!1Zc+5t8U&YLy~okm`!pnuC&^!27g^7JN1~ds-I^fo)l`za25=TgpnCSj1;I za+8>uqed6bdWw<^7^g(19b^&DGHOv5V>+s&2zR}W#e#Y~=Q(ucLo#XP-YzbkSK%qB z&Z&)0)et{j@-!5GI8e+9I@g7L#K4~km<KTzNhEQ221pT*Nt3)a@Gnfi%}1g<XOY~6 zN`<W!BkX4C@`>~yKGk<A?)F?+mR!rKcE_RoKJHr2wL!&h&rjML(w_el5+xxaL2<x; zR9f1#+E&e0u6eG(o&Q1x2lIx8hid0*hn9v`S6BakL84M9NR$RyZkvX^Zy@8USEi2I z5)XlGB&E619G)X|*R9K6j>RG=soGuyuRaU#-?|@huLI1!P}z)1HkpROVTc$7O)Zt^ zU;~st4^a66x1CoJA}_zJyrPo(A_}WPfui8()EqF120`|+t_lQWJS>oigdhv*zBJto z2=uBtHTf!X3f5bG(M;bG<As^BfMt<0%j|~SP}VD6Yld*GbF;psI+qlX_b4Y4ghGIx zT>kJcWKaZn`cC=%S33Z3TayXFGVq~gb`ddimJi0k1eyb|Nm`%d*y!9o%x6f&`kyqt zZOzLIN&E><J8IUgEGouu)JbcIR96_Bd-9BkMcrMgJ%!Xld^EH5*xW7VB{MBH1>G5Q z1>RRC^S6=+)!4UiAGNBEr$&Jz=E$2ioJX3`Xb%^=b4?;6HCnne&CJS;Gas+)ioO6! z0o@a+{|kw7TKjC82*GmcmrXu{I9wY@l8y;^y9k0n)zgJMX-M;YFajH-XeV<imK2cU zJK(dw$u{vabc^lD^mT#uRD85D?si~?7B-<R$z`DROkt&vYP4P(hU$YHd;2i~nET37 z*qe)apT}6$y_s`rDV9GvaJ4&{U2}iywX#B}{8B9AtH(?{2e-}r<?#d*=X=rG2n5c8 zdea<y`>0??+W0~#njq1-eZb(ouAXZmPdKetbwdoMp0~#?K|~9QoOQJFA7{2@9YwLO zmZt(#2H_VBK4Klcb|efHqnGAzIihXDdENxc!rL^w7*~L(&E5`+i=S55!w9<Crlky# zi1!=PbCJa^mJy{4t?}YjyqStFD!cSVuQ_I$vs4*PH`sG4-O|oS{U-RVA;k^%55r`N zHKH`PY=UiKVt!#!y4AWAEGi^B<PR(=w=0)|MO~V?w6wHD$r}G@jecQK#lNs9plVUJ zortUGq=CpP%$((l?RvQIi3tM6ZR5gbmR%#X$>IhZHy7$82pFu*kkw8(<}F{$*>7># zCaP67pv551Z@j1`X_i8KV<?6_#fArCETl{i1fd|{=rpzfB*qnrh(l!yp-UO#^v%_j zkvddC)lE2VIY~V|)hbk{H&s&10Pm1TxJ%TOm(b<pt0-?N>3)zW54dleV%T^0IB#P1 zG3P-gcR0jN)u<piE$4+Rx1MJiC|^bPKw(Eaa;u6ey!C>x7RxIT<88EaJLK|nOaA!^ zJISJP-5GeTu%`3R^{(_8z#Qo(ngGMM8f9sy@;&^B>IA9rnqj>^3v3ffMJ~TP;Dln@ zsL0+MHG3s^17>i%-;=?85Y-f$g5CEB->1*b^x{0`Vq7|00G7Qjvsvu=V?B3<0aJ|! zr+xWDuzh?_Z6fz}9@LVFgUBMpIty$6TGaK-`b=@S*pk+FJB0f*L1#I%Brdn+U{>n- zoMu?=kqYyr1c<3zZo8VrivUTE6jK4!YL&d`fJz$e&b<0+k&xl@D}KUl#y=HL_>jW2 zO?JP3oAm%{LXcP{4ZVyKZQcpXeOy{oC1>kG$*II%|I=XXv}w+XnN&#S!Cm1}5Bk>C z@|W&OSv<AgL;<&l(~hz_LT_n{)&hki=+Q}cm9?m_u+O0!RPPOei;321N2P$UXo(}L zmVqKo6mX4J%YataGS_VNBfXC4$G6^wy67hakZsE|7XZj~$%jF3SU~l_0ig7bvyjC1 zkJg>i%D1qv(Dm1ijr-MqrPP$(Ro-EZVSi9k|4WPPKlSOt$Kx?X(CXsg_5B4(srh$B z`xWRr!G}$HN26OA=4*}`^cm3PhQ%?H9tKFUL^}yv13%%rH`K-8l=QX4K11!1*=B<( z-~G>%P6{HG))Y(%M2<USVJ`;{lUGe+wh$03l2a^#*{9~yaeE5Ee2i4G5!$e7x(iBj zk$%o4LXQ5z)m?lg4ZuD>r>YLt<ZIVw=jIpAgkB=~<Snv|T~u%q6_1#iTW*r`;k9qS zF{Z2{=y<mDP<B(r@%ZUN#^7_Pr9uhS{L#G+dd1(M;JvL2$9(y02tA2}=@*OL?A^X4 zRm{(Myt8}KGM`N7ndmfe3jN$<fbT^n=aIYtGl6P{u*Wb~zKV$&-Qj<=@-f?<TtLoR z#*Sx1ghj!W9z=Vk@Wib2y3MjdjEMFogpPNAWG-xiNF~Tv-zUf;`5JLH9r~Jm)q0H0 zPGGUCij^v>nI>_eYiM)u#%ntB#mhqD3L9uXdh;`#IjLibN&2sDy?&X+(+pfnp?g#K zBBYXrTjZ`Ff$x*?!PRDxL+Ur->XTt+>I73-uO7A;s*QL-f$kE_U@$}RY>`&=%R7QN zmE*OnXoeU@ecFSPfY+1K^HO3=JPnExLa&||p`EGNX>IN;u2wBqhKR9Db&Azs@J|qm zZ+)YT+a@}G|D8pXa?|B+FS-Z`3CWwt|AM8A4fP}R1A_u7lV!^q%fOnzxW+gNELGH8 z^am{U-(sAMg!V@6qwyM_@E)opzHXZv99fbg-6BZ)4b^Pw9YukxZVpgX0o0d#)I_$C zFxuJom5JU$o0ZDUt79jPPw<UC(i^AaO7O8vYwyHxOzCl$n36C&E}k_~R?9$`S}!_{ z-Os=}I~hfU7qFOWSmcO%@?T7?!ew~W%eL|WAwU8lrh9l~bd0&(oC-k=yTs!vk2pJf zoiRaPn_uhP0$okiG8J{X2<Qe5vb2?yya$-r(Y6)Uv#h*Pq+6FP>b8DqL)O;%e3`+} z=sW(G)~JgjMlN4ld+DySHkv$YrhknYWfWuhY4-5c9+q`g#BYD;7cVu%=6t7-Z_vF@ z5lISEs?<=c&0$R*WJ+sI)wBN=@i=<vQI%Gu0;G@RBEhe!e^3=KCG-keR5XgbD;L|p zcD7UVF0=;{X*JG8ijr3Vys?(!LkhXhM1+?raO+6?II(*kSgj|@U?J$QzpmCLmeo=m zw&8RiDjYwL3MZZ%g+rM0H<?eJbL?%tc;4Z}cRIlWsXd*fDkVW+hy$~K#ba0RjR!14 zA<C_4K6ZHTWJtligP<&Q$EzFisjpu@Jj4AD8lW(9lvKx{$slYhEbJ$2Y+`H>YY-9= zB2y`2Uh|8ay4ZNJx~4k6DWAek{S`-siKJ~MnyuPrnFTLrd6pmY_y)3yqWHxFe`j-e zJ!m3=Lu#o50-PWkwlkpy()b%MH3=-EIMiZKgDCj2kN7qPy%Fx-&;EX6A)Khit=94T zYf)X2E;vEPL_;Tzgo;RGcQ7@#cFE1>_Z87~^Dh^|z#AK3brfPG%@mEU?O;vhkwVf? zxAZX&@DR~bm&S`oG>E)wcy;+CEtPrv1Wl5X?%IN>ma-mj8<!DgrROp?zb`6<$;Kcr zY&$qPPwJqkd#}CZBD+#!#_oDo-qimt)N=C9#c7H{j0iahOc7=rMj1dM1p?F8(lwl( zg%%KZbC`0_7?-uToBNUpSl2oI0?~$H_L&(8#owR{*OPBt`zS{;FV+hH#uX7INn`_O z^-LZ`oCUop(dKim``cr8T;vOj7;{0hd$(+?x*Q5wTK5+jMJq3q4u!2GslT{;0nzNC zMoNG@H3Np5vawu^Ga!BZWI$$`PX3{*Z}X-fWQC-<tC3?8242BQF=qeGe*VIyC=(M( z?MvCf{QUgCu&GCXVN=x<Y|8EzHswaarlx)26l_XN<bg@!n~L1uv!;S<04({WRN*gI zYU0=EpW!oB99UoIb)bB$!N;$=S<n#6q1biVF{41^Bk7EApAf~z>|HPT!#TAs;-WcC zQuz3jGil77a%t501q(46EWTwZS4~(#H4@~e(1>n<HndT&sXkrMpjWR^L63f~Om9AO zX?NPyk@4<PmW*n#Yi(qfmBvY~p83r=v99WEfr;#UG2I)=J+2X3j_W-RYfQZr%!`GP zy87dm8)da_&pN)g?3Q)>bV4W<{mmEhs~Nx`!5}Fkc}DGwu!*psuONkW*9p{#jsG_| zW!q>Qm>C!|5c4bA4HgZJ4ArjG4y+99?C$(e*s1?)1_&eRcyA_Az$q?MUEIwfL{Kyx z4^!5Ckemj#zB`Fa-je9O(IeR4@`368ne7JA>u>~g=G(Yg%9C+{L{)>=?h^^Y7@jig zcv~MlN;wFVq?w?jjKBtEX_)CE;K)F0Y|+^=U39rsVT~LJj&Ulm&TRP?WFrDX(^d@$ z1B278jm8C_)JhkFJg)PBbxOMo7Udn4k#15UH@MB6bSn+6-3CyV=59*??*ky_%8fzz zCkb%pQ*==EeJYYpxk}K%{qjijy;3Qi8C8(0br&t0>tWukBIc`T4F$5%vVj@N@4;PN z=F_f<u+%JSa;kx;YPZHa2T!MJIUWk!;?D48n(;!RL^>@3I2EW$-KrweU=L`|a`b-D zZ4cX-@yT-=<F4SdPYP7EiES?7YcLP@W#cW>Gs)r>AM0ZpmQ55as#Z-qK0emEb4^(H z;^vQIPaRTg-8*&<DyuUcf@ZrMQl)|G+?tSy4l=)xiHC`5>&KRgEpa+4I;o;L`^{S# z5;#Wnio>Zy@+70XF!CQ}J(Nn9!q7<uN>Ug)<9Opgc`E-j|NO%I;;v!}Peq|>{+6do zqwrLTY^&oOA(D9zKmRwbO!DypQl_u8YkIJmV6JlF6gIb^*<zBqMA12*+(J9~mJm{t z5J9ufF8*7s;M^(7XP4vZ!_V;!kHJYFWmSBYMa(o3+2!H>5;|xz*9>Os>=Z*slY$}& zPX+V#@pD8(a-FYc2P#5<K!|vYS$hX1>s=Zb=+doJo1jotDsVIE>kP&e(j2ph7thXF zRa>|Luro~YS-Y)6+(I<(FP1de4?LWJ+B`{?IJs22sqAY+Opw~S1gZPY-cQAjGzbIC zWyK<i$}FT)^~4Y&!&kqK>7671Ug}?2FCDOoR%fvpn0g42l1wUjxx~*kn*+fM0QggZ z^VWf}BsTJ<UE+DJXS%j0IW!;wHM}%z<Ne;vi)C4~Y-7n-2|>e)5`}!EE-BH{G-cZ= z`tq~vSx%7Er!NCQS``(gqobHioL0_h?!cGqqN}~3gMRaFC)+4;z|P<{?l~Rn^!WEM z!*H*s84mBpUChD$CyjQs5poPX&oe!#;sakD8&rLiU0S^TL#kk7WVb0iO2FpOSlpO0 zQ)#;|;P)zLg2hraU}I{^yLhAdVb<TohhG!}CHu+S%gcqz8JQRvgc<xnSp7-HPzbB7 zt*t)^tG^Q9H|mr@X^-Y;A05IXndmt?CfzhgUHH08^%6Y!R7Z)&g=Zmi@%<=HO0!9z zhB-J#B)M`3NqyV-7}X~@a);L%%*CpHlx*)>v8DO!RqPv1><w5v<+d+ll$S(oDjVdS znscbMj)X!svyqr;q*l5%$*znMeBM(_tiUU#v=LzHQ5e)J3X4JYa1bcspo7#RP+gaP z8R^A%PLp90PxlfI$R$y&S<HKLA-9MZT`0EBw^3p2+@{KXuyoH&L(>X=LT!7er@{(R zYn-m8YfGL(l8!$ak@)R=ZVkLM>s@M2(@ydoj9e{MGk3ox631nV>NokxAdahapW0-W z{uo4FN^jt0h9X<06+5*!rO{i`d<}@_ZT}wq;mgUO%Te^b8?da&7=8YLc-)OA>mbzq zXItkF(XG{64TLFLK__(9i-djById=D_v{`sE%1FcHQUA`l@iZhA<3}t?wS|7qMia1 z?fbRh+lHp9M%eoAA&SPC5@c2B&{EGaN$_kcF>p=iF=I~VJdt&fyOrP#t~+<G&Qfxi zJG@B2>&uefC@G!ApU@+Zem^_kZ`RmD%IfElY<o{^?~NW}jh@|3L1MQi*v?*$kUDhq zxpV*S?duzrw%HYCfNMcl5S(f40Um*F%!l)5<H|Y!OL%<hg%HFjiWw)0rAtK1K66R_ zKMedR)FveroB5c<$N!?ODAeAcwAISW3PpN<uD@h;1*26cfS`@`k!92N$FFdKfyeh3 zfWq<5jb$CgEa1ps1&))ah(n|Z<A)5mmVG*{`1CC%>YWX1CcZpcJFQ0hPEJgS8(g!r z-`CvQEXM8EXeH?)RL54&A(<KC5oK-R3&~>0w^q<fbLY|n7Xwmb-E>G{rHV=y5`p<q z?u}tUNQ0P<9<t65*hxnS4iTxgAODxEk_lR-amq`$6}W_CEuc?yv||x0moAAAZkG4W zoXb&<IyUp2&yRK8l|Oq2Syb2k{(a2Bw})eO`%aD%QHbqamyh^$kj5PQIr)Pn>R5}m z2Xu-*ss#6Tp!Im2pJ^{i#Bt0fPaZhybCUTW3jpMf5sWEQ-%SJ#Y2pt_zo@-m6Xg}2 zDL|cO%;S{eCq`T4m=jJ>FKIPIIZES);_YlL24)m)zIbBJM%4~6Rh2=-m%Hlfy=!}L za@x?_nKXnUcjN`gJM3<C`ghND@+W!0F3FA3mM?1a6k6zozu=fpW*GEn{bXHGoLnY( zJ>&b#tCkS6YZ*ZqDUwcnq2jj4Wjh*At*6rIOb!Lo%5h}Kv*D&bH;>$Y^Y~61Hg3#~ zB!LxIfBwgnZCy5G{8pT|p1E&Pc=UdpXdoBPL;3nEo$}2ZXkK29P`h3KN50%UDQDDw zro3sX!2foOpDDEg5(2hs&`<h5%8F9<|H)h#7a0d<|GK2t+uQr6l>YO{U$Tm0{DZlI zHTHpzjh+ehFTAbtQs|#QJahS=?+MqDbov3ILz3v7{;W8I$RU_Cv$nW{j4?HJ0o0iG zjwhBc(32p^!JJAR1-pj!A6I@cS7a7&w2N3!5~Hm;%z-DxSu!><6Xz$DdM?$aqBu!H zQdy-shs#5^F_!A0agz!VWb9=M&H#FLiglNgFS%ZqEt&k6td`2o898+=4|u?!-gv4O zNVwKQcC8q^Y-kvMWwt}HFY-wt#3CcJ!8vy`EERUS6r>TY{Cv1K_O(sq5Q7lgm~(2= z{%N>wn$npUJ{3h=7_}+xFJmF(@t{0G#7~bXf$vdJr{Y{fe+>ReY!2`33tFl{fT$CF zjKYkXBWYDjIAe<_H`)HpTseM4=i!xQ%NOoy8g{H<83NUXWH8K9vSKL*c2va`%f)vA zHLtt|ZDvJXNg>&{@@&|&1-{Lr?8LSfu(Z}Ch8|c}MhEgRC-(M>yUU7UPHoiE)>>B! z;$FOMbqIb?L~?z8fQqnQ5J*p*{f=VoD9yJDOVGVPJ5V6Jh~dYTKz58hqgX?`8|c*g z)x)eMtM1$EN%qoSvO53R{O-F4y>SzhYBf)>XLj=z<oHy8VXv2Y@2mXwmQO|$c}+9O zsJ_@X*LsDt^BG?MZF+Oo;S3Z6_bA|0wKxlWTSey)y=VcGTK;hO3sg8ty`cFI`H*t& zf`VNA5wd<ESNS3N1^*Kird;hbx5NbNV~3_PgX##a_NqqB%CEj40zk7t8C?g&iP|GV ziD=~P<0F8UZhrBjwZj)ynJFjJFqaGcEz>4SSY60nN40o~VEca|SMCRlYMMR?c%Y#v z+}+mM)I1fC?josTUTh#04o|$8A>`;+tYi)bl}U-#oGGeoz=7-XvgwEt9m53^|3+cb zLfj}2jK0`apvpY-hG@08g^Rw&<*_hPD*QlGRaZP;u_G6;NpPoN@0Lni?z76y3q8%f z6`JAOM)|Q%6rJqFGHtCP<WW{2%VYPb8!LEL5jWo%b!@7z+|ze~)ggWl@@an_k410} zzjQ=OP>~}v-@XDDyBW9{na=lA7*^0op!Z`A-3R_cVMt$6m}I4VGrit6{jgi%YKLC9 z)AC$0RJ(daHzh3fYx-0}qmABYwRimKsa8F=VxKhaTJ=H3T^`XRbv-;<vOb^USx{*X zHQ}z`8UyX=19o%cAf8``+#cr%I_GExeelqp8!xke&YAPN4mtU)jfCI#g{$(rNV{Dt zewpFH(O}^9VglX2!<x>X<j2J4-Mi{V?&lm02%T&bviAQtRc2OBnm+$cB$<&p^Im&g z(KP(GPu;J3LPPk<=VNG}jfl{Zp1OwayyB(W91LNz48w3j2;&xTMhIcbj0#zBNM>f* z%S&n%cy{X#g)u$<C)!F_SeWwj6yf3Fzp`SPNl;->LD9djW&LOP`s4XuLF~#Ov{e}u z&L%1Jnr36#KJdZpAn4(%GoUJ7mn-a;zTHi0Nwzrt2JFUVdQ38qKqN>Q?t&jzNXx4w zzgy1i#qRWX|Hh?SMoN7j@e3R!P#_pZCU^*6U?M)!83qr>X*zqkCHj`Q*yI{S`NJ=m zhzICbR@p^rRi&QkYSvM7=sRbI*Bpk7vO3s;Q&N(8vi}HT%kfDdF#IOmcqtOL;{-8M z<8p@Iog1%epl?!<oO3KODy(SBN+_;`+9n-(g-SK5>=0q{yF}N+XO(8q!{Un)Sgp;_ zM-S+O$<LLSn+nQg{rY_x9;SO5F{J#o+Sm2z;K5NDh1TJZ%_It2k)1A+`zHPMeF*t3 z<vR%BWO3knBEnqzzk=AxNT<2(dYa0*?Rp|3vl$S${!Wt}#zlCOA<ReUQ7Wc0xz8k* zvtK2`pd@i(-NTVp?IIP)y3ps4r|wtj;`oTc1yduclluxRUfVQN>-Ac&qSIOG%EVzt z&DJMPV2bx+mbuY#V?&2`ga<K2lKxaH;sWpV<9WQbZ+Kk+eGh{qzDhMGe0o7|^}zko zS!HRfq}1}xE2(-~<UQAi!dkV^Pjw;PGVr6TJf6<gN^RcDEM@hF$UTMLMi1@AkCkzX zMmzt{4BzxS`^h$cxK+4SvBaf*(uXa=joTC!3JbBv8JzI9=llvwVrdq@H2~I%Kg%;R ui*nL4(-aK#3=9-BoHZ4)6I1fDQ_CE3i_`V;QcLs{j13hsa}(23ix~jBh!9o) literal 0 HcmV?d00001 diff --git a/otherlibs/labltk/tkanim/tkAnimGIF.c b/otherlibs/labltk/tkanim/tkAnimGIF.c new file mode 100644 index 0000000..8a6ef52 --- /dev/null +++ b/otherlibs/labltk/tkanim/tkAnimGIF.c @@ -0,0 +1,914 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ +#define TKANIM_VERSION "1.0" +/* #define TKANIM_DEBUG */ + +#include <tk.h> +#include <string.h> + +/* + * The format record for the Animated GIF file format: + */ + +static int FileMatchGIF _ANSI_ARGS_((FILE *f, char *fileName, + char *formatString, int *widthPtr, int *heightPtr)); +static int FileReadGIF _ANSI_ARGS_((Tcl_Interp *interp, + FILE *f, char *fileName, char *formatString)); + +#define INTERLACE 0x40 +#define LOCALCOLORMAP 0x80 +#define BitSet(byte, bit) (((byte) & (bit)) == (bit)) +#define MAXCOLORMAPSIZE 256 +#define CM_RED 0 +#define CM_GREEN 1 +#define CM_BLUE 2 +#define MAX_LWZ_BITS 12 +#define LM_to_uint(a,b) (((b)<<8)|(a)) +#define ReadOK(file,buffer,len) (fread(buffer, len, 1, file) != 0) + +/* + * Prototypes for local procedures defined in this file: + */ + +static int DoExtension _ANSI_ARGS_((FILE *fd, int label, + int *transparent, int *delay, int *loop)); +static int GetCode _ANSI_ARGS_((FILE *fd, int code_size, + int flag)); +static int GetDataBlock _ANSI_ARGS_((FILE *fd, + unsigned char *buf)); +static int LWZReadByte _ANSI_ARGS_((FILE *fd, int flag, + int input_code_size)); +static int ReadColorMap _ANSI_ARGS_((FILE *fd, int number, + unsigned char buffer[3][MAXCOLORMAPSIZE])); +static int ReadGIFHeader _ANSI_ARGS_((FILE *f, int *widthPtr, + int *heightPtr)); +static int ReadImage _ANSI_ARGS_((Tcl_Interp *interp, + char *imagePtr, FILE *fd, int len, int height, + unsigned char cmap[3][MAXCOLORMAPSIZE], + int interlace, int transparent)); + +static int +FileMatchGIF(f, fileName, formatString, widthPtr, heightPtr) + FILE *f; /* The image file, open for reading. */ + char *fileName; /* The name of the image file. */ + char *formatString; /* User-specified format string, or NULL. */ + int *widthPtr, *heightPtr; /* The dimensions of the image are + * returned here if the file is a valid + * raw GIF file. */ +{ + return ReadGIFHeader(f, widthPtr, heightPtr); +} + +static int +FileReadGIF(interp, f, fileName, formatString) + Tcl_Interp *interp; /* Interpreter to use for reporting errors. */ + FILE *f; /* The image file, open for reading. */ + char *fileName; /* The name of the image file. */ + char *formatString; /* User-specified format string, or NULL. */ +{ + int logicalWidth, logicalHeight; + int nBytes; + Tk_PhotoImageBlock block; + unsigned char buf[100]; + int bitPixel; + unsigned int colorResolution; + unsigned int background; + unsigned int aspectRatio; + unsigned char localColorMap[3][MAXCOLORMAPSIZE]; + unsigned char colorMap[3][MAXCOLORMAPSIZE]; + int useGlobalColormap; + int transparent = -1; + int delay = 0; + Tk_Window winPtr; + int imageLeftPos, imageTopPos, imageWidth, imageHeight; + Tk_PhotoHandle photoHandle; + + char widthbuf[32], heightbuf[32]; + Tcl_DString resultbuf; + + char newresbuf[640]; + char *imageName; + char *resultptr; + int loop = -1; + + if((winPtr = Tk_MainWindow(interp)) == NULL){ + return TCL_ERROR; + } + +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\t\tHeader check..."); +#endif + if (!ReadGIFHeader(f, &logicalWidth, &logicalHeight)) { + Tcl_AppendResult(interp, "couldn't read GIF header from file \"", + fileName, "\"", NULL); + return TCL_ERROR; + } +#ifdef TKANIM_DEBUG + fprintf(stderr, "done "); +#endif + if ((logicalWidth <= 0) || (logicalHeight <= 0)) { + Tcl_AppendResult(interp, "GIF image file \"", fileName, + "\" has dimension(s) <= 0", (char *) NULL); + return TCL_ERROR; + } + + if (fread(buf, 1, 3, f) != 3) { + return TCL_OK; + } + bitPixel = 2<<(buf[0]&0x07); + colorResolution = (((buf[0]&0x70)>>3)+1); + background = buf[1]; + aspectRatio = buf[2]; + + if (BitSet(buf[0], LOCALCOLORMAP)) { /* Global Colormap */ + if (!ReadColorMap(f, bitPixel, colorMap)) { + Tcl_AppendResult(interp, "error reading color map", + (char *) NULL); + return TCL_ERROR; + } + } + +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\t\tReading frames "); + prevpos = ftell(f); +#endif + sprintf( widthbuf, "%d ", logicalWidth); + sprintf( heightbuf, "%d ", logicalHeight); + + Tcl_DStringInit(&resultbuf); + Tcl_DStringAppend(&resultbuf, widthbuf, -1); + Tcl_DStringAppend(&resultbuf, " ", -1); + Tcl_DStringAppend(&resultbuf, heightbuf, -1); + Tcl_DStringAppend(&resultbuf, " ", -1); + Tcl_DStringAppend(&resultbuf, "{", -1); + + while (1) { + if (fread(buf, 1, 1, f) != 1) { + /* + * Premature end of image. We should really notify + * the user, but for now just show garbage. + */ +#ifdef TKANIM_DEBUG + fprintf(stderr, "Premature end of image"); +#endif + + break; + } + + if (buf[0] == ';') { + /* + * GIF terminator. + */ +#ifdef TKANIM_DEBUG + fprintf(stderr, ";"); + prevpos = ftell(f); +#endif + + break; + } + + if (buf[0] == '!') { + /* + * This is a GIF extension. + */ +#ifdef TKANIM_DEBUG + fprintf(stderr, "!"); + prevpos = ftell(f); +#endif + + if (fread(buf, 1, 1, f) != 1) { + Tcl_AppendResult( interp, + "error reading extension function code in GIF image", NULL ); +/* + interp->result = + "error reading extension function code in GIF image"; +*/ + goto error; + } + if (DoExtension(f, buf[0], &transparent, &delay, &loop) < 0) { + Tcl_AppendResult( interp, + "error reading extension in GIF image", NULL ); +/* + interp->result = "error reading extension in GIF image"; +*/ goto error; + } + continue; + } + + if (buf[0] == '\0') { + /* + * Not a valid start character; ignore it. + */ +#ifdef TKANIM_DEBUG + fprintf(stderr, "0", buf[0]); + prevpos = ftell(f); +#endif + continue; + } + + if (buf[0] != ',') { + /* + * Not a valid start character; ignore it. + */ +#ifdef TKANIM_DEBUG + fprintf(stderr, "?(%c)", buf[0]); + prevpos = ftell(f); +#endif + continue; + } + + if (fread(buf, 1, 9, f) != 9) { + Tcl_AppendResult( interp, + "couldn't read left/top/width/height in GIF image", NULL ); +/* + interp->result = "couldn't read left/top/width/height in GIF image"; +*/ + goto error; + } + + useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP); + + bitPixel = 1<<((buf[8]&0x07)+1); + + imageLeftPos= LM_to_uint(buf[0], buf[1]); + imageTopPos= LM_to_uint(buf[2], buf[3]); + imageWidth= LM_to_uint(buf[4], buf[5]); + imageHeight= LM_to_uint(buf[6], buf[7]); + + block.width = imageWidth; + block.height = imageHeight; + block.pixelSize = 3; + block.pitch = 3 * imageWidth; + block.offset[0] = 0; + block.offset[1] = 1; + block.offset[2] = 2; + block.offset[3] = 3; + nBytes = imageHeight * block.pitch; + block.pixelPtr = (unsigned char *) ckalloc((unsigned) nBytes); + + sprintf(widthbuf, "%d", imageWidth); + sprintf(heightbuf, "%d", imageHeight); + + /* save result */ + + { +#if (TK_MAJOR_VERSION >= 8 && TK_MINOR_VERSION >= 1) + Tcl_Obj *argv[7]; + int i; + + argv[0] = Tcl_NewStringObj("image", -1); + argv[1] = Tcl_NewStringObj("create", -1); + argv[2] = Tcl_NewStringObj("photo", -1); + argv[3] = Tcl_NewStringObj("-width", -1); + argv[4] = Tcl_NewStringObj(widthbuf, -1); + argv[5] = Tcl_NewStringObj("-height", -1); + argv[6] = Tcl_NewStringObj(heightbuf, -1); + + for(i=0; i<7; i++){ Tcl_IncrRefCount(argv[i]); } + + if( Tk_ImageObjCmd((ClientData) winPtr, interp, + /* "image create photo -width <imageWidth> + -height <imageHeight>" */ + 7, argv) == TCL_ERROR ){ + return TCL_ERROR; + } + + for(i=0; i<7; i++){ Tcl_DecrRefCount(argv[i]); } + +#else + char *argv[7] = {"image", "create", "photo", "-width", NULL, + "-height", NULL}; + argv[4] = widthbuf; + argv[6] = heightbuf; +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\t\timage creation (%s %s %s %s %s %s %s)", + argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); +#endif + if( Tk_ImageCmd((ClientData) winPtr, interp, + /* "image create photo -width <imageWidth> + -height <imageHeight>" */ + 7, argv) == TCL_ERROR ){ + return TCL_ERROR; + } +#endif + +#ifdef TKANIM_DEBUG + fprintf(stderr, " done "); +#endif + } + + imageName = interp->result; +#if (TK_MAJOR_VERSION < 8) + photoHandle = Tk_FindPhoto(interp->result); +#else + photoHandle = Tk_FindPhoto(interp, interp->result); +#endif + if (!useGlobalColormap) { + if (!ReadColorMap(f, bitPixel, localColorMap)) { + Tcl_AppendResult(interp, "error reading color map", + (char *) NULL); + goto error; + } + if (ReadImage(interp, (char *) block.pixelPtr, f, imageWidth, + imageHeight, localColorMap, BitSet(buf[8], INTERLACE), + transparent) != TCL_OK) { + goto error; + } + } else { + if (ReadImage(interp, (char *) block.pixelPtr, f, imageWidth, + imageHeight, colorMap, BitSet(buf[8], INTERLACE), + transparent) != TCL_OK) { + goto error; + } + } + Tk_PhotoPutBlock( +#if (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION >= 5 || TK_MAJOR_VERSION > 8) + NULL, +#endif +photoHandle, &block, 0, 0, imageWidth, imageHeight +#if (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION >= 4 || TK_MAJOR_VERSION > 8) + , TK_PHOTO_COMPOSITE_SET +#endif + ); +#ifdef TKANIM_DEBUG + fprintf(stderr, " Retrieving result\n"); +#endif + /* retrieve result */ + sprintf(newresbuf, "{%s %d %d %d %d %d} ", + imageName, imageWidth, imageHeight, imageLeftPos, imageTopPos, + delay); +#ifdef TKANIM_DEBUG + fprintf(stderr, " newresbuf = %s\n", newresbuf); +#endif + ckfree((char *) block.pixelPtr); +#ifdef TKANIM_DEBUG + fprintf(stderr, " free done (now append result)"); +#endif + Tcl_DStringAppend( &resultbuf, newresbuf, -1 ); +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\t\tFrame done (%d)", ftell(f) - prevpos); + prevpos = ftell(f); +#endif + } + sprintf( widthbuf, "%d", loop ); + Tcl_DStringAppend( &resultbuf, "} ", -1 ); + resultptr = Tcl_DStringAppend( &resultbuf, widthbuf, -1 ); +#ifdef TKANIM_DEBUG + fprintf(stderr, "\nResult = %s\n", resultptr); +#endif + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, resultptr, NULL); + Tcl_DStringFree(&resultbuf); + return TCL_OK; + + error: + Tcl_DStringFree(&resultbuf); + ckfree((char *) block.pixelPtr); + return TCL_ERROR; + +} + +static int +DoExtension(fd, label, transparent, delay, loop) +FILE *fd; +int label; +int *transparent; +int *delay; +int *loop; +{ + static unsigned char buf[256]; + int count = 0; + + switch (label) { + case 0x01: /* Plain Text Extension */ + break; + + case 0xff: /* Application Extension */ + count = GetDataBlock(fd, (unsigned char*) buf); + if( count < 0){ + return 1; + } + if( !strncmp (buf, "NETSCAPE", 8) ) { + /* we ignore check of "2.0" */ + count = GetDataBlock (fd, (unsigned char*) buf); + if( count < 0){ + return 1; + } + if( buf[0] != 1 ){ + fprintf(stderr, "??? %d", buf[0]); + } + *loop = LM_to_uint(buf[1], buf[2]); + } + do { + count = GetDataBlock(fd, (unsigned char*) buf); + } while (count > 0); + return count; + break; + + case 0xfe: /* Comment Extension */ + do { + count = GetDataBlock(fd, (unsigned char*) buf); + } while (count > 0); + return count; + + case 0xf9: /* Graphic Control Extension */ + count = GetDataBlock(fd, (unsigned char*) buf); + if (count < 0) { + return 1; + } + if ((buf[0] & 0x1) != 0) { + *transparent = buf[3]; + } + + /* Delay time */ + *delay = LM_to_uint(buf[1],buf[2]); + + do { + count = GetDataBlock(fd, (unsigned char*) buf); + } while (count > 0); + return count; + } + + do { + count = GetDataBlock(fd, (unsigned char*) buf); + } while (count > 0); + return count; +} + +/* + *---------------------------------------------------------------------- + * + * ReadGIFHeader -- + * + * This procedure reads the GIF header from the beginning of a + * GIF file and returns the dimensions of the image. + * + * Results: + * The return value is 1 if file "f" appears to start with + * a valid GIF header, 0 otherwise. If the header is valid, + * then *widthPtr and *heightPtr are modified to hold the + * dimensions of the image. + * + * Side effects: + * The access position in f advances. + * + *---------------------------------------------------------------------- + */ + +static int +ReadGIFHeader(f, widthPtr, heightPtr) + FILE *f; /* Image file to read the header from */ + int *widthPtr, *heightPtr; /* The dimensions of the image are + * returned here. */ +{ + unsigned char buf[7]; + + if ((fread(buf, 1, 6, f) != 6) + || ((strncmp("GIF87a", (char *) buf, 6) != 0) + && (strncmp("GIF89a", (char *) buf, 6) != 0))) { + return 0; + } + + if (fread(buf, 1, 4, f) != 4) { + return 0; + } + + *widthPtr = LM_to_uint(buf[0],buf[1]); + *heightPtr = LM_to_uint(buf[2],buf[3]); + return 1; +} + +/* + *----------------------------------------------------------------- + * The code below is copied from the giftoppm program and modified + * just slightly. + *----------------------------------------------------------------- + */ + +static int +ReadColorMap(fd,number,buffer) +FILE *fd; +int number; +unsigned char buffer[3][MAXCOLORMAPSIZE]; +{ + int i; + unsigned char rgb[3]; + + for (i = 0; i < number; ++i) { + if (! ReadOK(fd, rgb, sizeof(rgb))) + return 0; + + buffer[CM_RED][i] = rgb[0] ; + buffer[CM_GREEN][i] = rgb[1] ; + buffer[CM_BLUE][i] = rgb[2] ; + } + return 1; +} + + + +static int ZeroDataBlock = 0; + +static int +GetDataBlock(fd, buf) +FILE *fd; +unsigned char *buf; +{ + unsigned char count; + + if (! ReadOK(fd,&count,1)) { + return -1; + } + + ZeroDataBlock = count == 0; + + if ((count != 0) && (! ReadOK(fd, buf, count))) { + return -1; + } + + return count; +} + + +static int +ReadImage(interp, imagePtr, fd, len, height, cmap, interlace, transparent) +Tcl_Interp *interp; +char *imagePtr; +FILE *fd; +int len, height; +unsigned char cmap[3][MAXCOLORMAPSIZE]; +int interlace; +int transparent; +{ + unsigned char c; + int v; + int xpos = 0, ypos = 0, pass = 0; + char *colStr; + + + /* + * Initialize the Compression routines + */ + if (! ReadOK(fd,&c,1)) { + Tcl_AppendResult(interp, "error reading GIF image: ", + Tcl_PosixError(interp), (char *) NULL); + return TCL_ERROR; + } + + if (LWZReadByte(fd, 1, c) < 0) { + interp->result = "format error in GIF image"; + return TCL_ERROR; + } + + if (transparent!=-1 && + (colStr = Tcl_GetVar(interp, "TRANSPARENT_GIF_COLOR", 0L))) { + XColor *colorPtr; + colorPtr = Tk_GetColor(interp, Tk_MainWindow(interp), + Tk_GetUid(colStr)); + if (colorPtr) { +/* + printf("color is %d %d %d\n", + colorPtr->red >> 8, + colorPtr->green >> 8, + colorPtr->blue >> 8); +*/ + cmap[CM_RED][transparent] = colorPtr->red >> 8; + cmap[CM_GREEN][transparent] = colorPtr->green >> 8; + cmap[CM_BLUE][transparent] = colorPtr->blue >> 8; + Tk_FreeColor(colorPtr); + } + } + + while ((v = LWZReadByte(fd,0,c)) >= 0 ) { + + imagePtr[ (xpos*3) + (ypos *len*3)] = cmap[CM_RED][v]; + imagePtr[ (xpos*3) + (ypos *len*3) +1] = cmap[CM_GREEN][v]; + imagePtr[ (xpos*3) + (ypos *len*3) +2] = cmap[CM_BLUE][v]; + + ++xpos; + if (xpos == len) { + xpos = 0; + if (interlace) { + switch (pass) { + case 0: + case 1: + ypos += 8; break; + case 2: + ypos += 4; break; + case 3: + ypos += 2; break; + } + + if (ypos >= height) { + ++pass; + switch (pass) { + case 1: + ypos = 4; break; + case 2: + ypos = 2; break; + case 3: + ypos = 1; break; + default: + return TCL_OK; + } + } + } else { + ++ypos; + } + } + if (ypos >= height) + break; + } + return TCL_OK; +} + +static int +LWZReadByte(fd, flag, input_code_size) +FILE *fd; +int flag; +int input_code_size; +{ + static int fresh = 0; + int code, incode; + static int code_size, set_code_size; + static int max_code, max_code_size; + static int firstcode, oldcode; + static int clear_code, end_code; + static int table[2][(1<< MAX_LWZ_BITS)]; + static int stack[(1<<(MAX_LWZ_BITS))*2], *sp; + register int i; + + + if (flag) { + + set_code_size = input_code_size; + code_size = set_code_size+1; + clear_code = 1 << set_code_size ; + end_code = clear_code + 1; + max_code_size = 2*clear_code; + max_code = clear_code+2; + + GetCode(fd, 0, 1); + + fresh = 1; + + for (i = 0; i < clear_code; ++i) { + table[0][i] = 0; + table[1][i] = i; + } + for (; i < (1<<MAX_LWZ_BITS); ++i) { + table[0][i] = table[1][0] = 0; + } + + sp = stack; + + return 0; + + } else if (fresh) { + + fresh = 0; + do { + firstcode = oldcode = GetCode(fd, code_size, 0); + } while (firstcode == clear_code); + return firstcode; + } + + if (sp > stack) + return *--sp; + + while ((code = GetCode(fd, code_size, 0)) >= 0) { + if (code == clear_code) { + for (i = 0; i < clear_code; ++i) { + table[0][i] = 0; + table[1][i] = i; + } + + for (; i < (1<<MAX_LWZ_BITS); ++i) { + table[0][i] = table[1][i] = 0; + } + + code_size = set_code_size+1; + max_code_size = 2*clear_code; + max_code = clear_code+2; + sp = stack; + firstcode = oldcode = GetCode(fd, code_size, 0); + return firstcode; + + } else if (code == end_code) { + int count; + unsigned char buf[260]; + + if (ZeroDataBlock) + return -2; + + while ((count = GetDataBlock(fd, buf)) > 0) + ; + + if (count != 0) + return -2; + } + + incode = code; + + if (code >= max_code) { + *sp++ = firstcode; + code = oldcode; + } + + while (code >= clear_code) { + *sp++ = table[1][code]; + if (code == table[0][code]) { + return -2; + + fprintf(stderr, "circular table entry BIG ERROR\n"); + /* + * Used to be this instead, Steve Ball suggested + * the change to just return. + + printf("circular table entry BIG ERROR\n"); + */ + } + code = table[0][code]; + } + + *sp++ = firstcode = table[1][code]; + + if ((code = max_code) <(1<<MAX_LWZ_BITS)) { + + table[0][code] = oldcode; + table[1][code] = firstcode; + ++max_code; + if ((max_code>=max_code_size) && (max_code_size < (1<<MAX_LWZ_BITS))) { + max_code_size *= 2; + ++code_size; + } + } + + oldcode = incode; + + if (sp > stack) + return *--sp; + } + return code; +} + + +static int +GetCode(fd, code_size, flag) +FILE *fd; +int code_size; +int flag; +{ + static unsigned char buf[280]; + static int curbit, lastbit, done, last_byte; + int i, j, ret; + unsigned char count; + + if (flag) { + curbit = 0; + lastbit = 0; + done = 0; + return 0; + } + + + if ( (curbit+code_size) >= lastbit) { + if (done) { + /* ran off the end of my bits */ + return -1; + } + buf[0] = buf[last_byte-2]; + buf[1] = buf[last_byte-1]; + + if ((count = GetDataBlock(fd, &buf[2])) == 0) + done = 1; + + last_byte = 2 + count; + curbit = (curbit - lastbit) + 16; + lastbit = (2+count)*8 ; + } + + ret = 0; + for (i = curbit, j = 0; j < code_size; ++i, ++j) + ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j; + + + curbit += code_size; + + return ret; +} + +int Tk_AnimationCmd(clientData, interp, argc, argv) + ClientData clientData; /* Main window associated with interpreter. */ + Tcl_Interp *interp; /* Current interpreter. */ + int argc; /* Number of arguments. */ + char **argv; /* Argument strings. */ +{ + char c; + int length; + + if (argc < 2) { + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], + " option ?arg arg ...?\"", (char *) NULL); + return TCL_ERROR; + } + c = argv[1][0]; + length = strlen(argv[1]); + if((c == 'c') && (length >= 2) + && (strncmp(argv[1], "create", length) == 0)) { + + char * realFileName; + Tcl_DString buffer; + FILE *f; + +#ifdef TKANIM_DEBUG + fprintf(stderr, "AnimationCmd => create "); +#endif + + if ( argc != 3 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], + " create GifFile\"", (char *) NULL); + return TCL_ERROR; + } +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\tRealFileName = "); +#endif + realFileName = Tcl_TranslateFileName(interp, argv[2], + &buffer); + if(realFileName == NULL) { + Tcl_DStringFree(&buffer); + return TCL_ERROR; + } +#ifdef TKANIM_DEBUG + fprintf(stderr, "%s ", realFileName); +#endif +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\tOpen ", realFileName); +#endif + f = fopen(realFileName, "rb"); + Tcl_DStringFree(&buffer); + if (f == NULL ){ + Tcl_AppendResult(interp, "couldn't read image file \"", + argv[2], "\": ", Tcl_PosixError(interp), + (char *) NULL); + return TCL_ERROR; + } +#ifdef TKANIM_DEBUG + fprintf(stderr, "success ", realFileName); +#endif +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\tRead ", realFileName); +#endif + if( FileReadGIF(interp, f, argv[2], "gif") != TCL_OK ){ +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\tRead failed", realFileName); +#endif + return TCL_ERROR; + } + fclose(f); +#ifdef TKANIM_DEBUG + fprintf(stderr, "\n\tRead done", realFileName); +#endif +#ifdef TKANIM_DEBUG + fprintf(stderr, "done\n"); +#endif + } + return TCL_OK; +} + +void +TkDeleteTkAnim(clientData) + ClientData clientData; +{ +#ifdef TKANIM_DEBUG + fprintf(stderr, "TkDeleteTkAnim\n"); +#endif +} + +int Tkanim_Init(interp) + Tcl_Interp *interp; +{ +#ifdef TKANIM_DEBUG + fprintf(stderr, "Tkanim initialize..."); +#endif + Tcl_CreateCommand(interp, "animation", Tk_AnimationCmd, + (ClientData) NULL, + (Tcl_CmdDeleteProc *) TkDeleteTkAnim); +#ifdef TKANIM_DEBUG + fprintf(stderr, "done\n"); +#endif + return Tcl_PkgProvide(interp, "Tkanim", TKANIM_VERSION ); +} diff --git a/otherlibs/labltk/tkanim/tkAppInit.c b/otherlibs/labltk/tkanim/tkAppInit.c new file mode 100644 index 0000000..60807d9 --- /dev/null +++ b/otherlibs/labltk/tkanim/tkAppInit.c @@ -0,0 +1,141 @@ +/***********************************************************************/ +/* */ +/* MLTk, Tcl/Tk interface of Objective Caml */ +/* */ +/* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis */ +/* projet Cristal, INRIA Rocquencourt */ +/* Jacques Garrigue, Kyoto University RIMS */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique and Kyoto University. All rights reserved. */ +/* This file is distributed under the terms of the GNU Library */ +/* General Public License, with the special exception on linking */ +/* described in file LICENSE found in the Objective Caml source tree. */ +/* */ +/***********************************************************************/ +/* + * tkAppInit.c -- + * + * Provides a default version of the Tcl_AppInit procedure for + * use in wish and similar Tk-based applications. + * + * Copyright (c) 1993 The Regents of the University of California. + * Copyright (c) 1994 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + */ + +#ifndef lint +static char sccsid[] = "@(#) tkAppInit.c 1.19 95/12/23 17:09:24"; +#endif /* not lint */ + +#include "tk.h" + +int Tkanimation_Init _ANSI_ARGS_ ((Tcl_Interp *interp)); + +/* + * The following variable is a special hack that is needed in order for + * Sun shared libraries to be used for Tcl. + */ + +extern int matherr(); +int *tclDummyMathPtr = (int *) matherr; + +#ifdef TK_TEST +EXTERN int Tktest_Init _ANSI_ARGS_((Tcl_Interp *interp)); +#endif /* TK_TEST */ + +/* + *---------------------------------------------------------------------- + * + * main -- + * + * This is the main program for the application. + * + * Results: + * None: Tk_Main never returns here, so this procedure never + * returns either. + * + * Side effects: + * Whatever the application does. + * + *---------------------------------------------------------------------- + */ + +int +main(argc, argv) + int argc; /* Number of command-line arguments. */ + char **argv; /* Values of command-line arguments. */ +{ + Tk_Main(argc, argv, Tcl_AppInit); + return 0; /* Needed only to prevent compiler warning. */ +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_AppInit -- + * + * This procedure performs application-specific initialization. + * Most applications, especially those that incorporate additional + * packages, will have their own version of this procedure. + * + * Results: + * Returns a standard Tcl completion code, and leaves an error + * message in interp->result if an error occurs. + * + * Side effects: + * Depends on the startup script. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_AppInit(interp) + Tcl_Interp *interp; /* Interpreter for application. */ +{ + if (Tcl_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + if (Tk_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL); +#ifdef TK_TEST + if (Tktest_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } +#endif /* TK_TEST */ + + + /* + * Call the init procedures for included packages. Each call should + * look like this: + * + * if (Mod_Init(interp) == TCL_ERROR) { + * return TCL_ERROR; + * } + * + * where "Mod" is the name of the module. + */ + + if (Tkanim_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + + /* + * Call Tcl_CreateCommand for application-specific commands, if + * they weren't already created by the init procedures called above. + */ + + /* + * Specify a user-specific startup file to invoke if the application + * is run interactively. Typically the startup file is "~/.apprc" + * where "app" is the name of the application. If this line is deleted + * then no user-specific startup file will be run under any conditions. + */ + + Tcl_SetVar(interp, "tcl_rcFileName", "~/.tkanimationrc", TCL_GLOBAL_ONLY); + return TCL_OK; +} diff --git a/otherlibs/labltk/tkanim/tkanim.ml b/otherlibs/labltk/tkanim/tkanim.ml new file mode 100644 index 0000000..d4d693f --- /dev/null +++ b/otherlibs/labltk/tkanim/tkanim.ml @@ -0,0 +1,230 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget +open Support +open Protocol +open Tkintf + +external init : unit -> unit = "tkanim_init" + +type gifFrame = { + imagephoto : imagePhoto; + frameWidth : int; + frameHeight : int; + left : int; + top : int; + delay : int + } + +type animatedGif = { + frames : gifFrame list; + animWidth : int; + animHeight : int; + loop : int +} + +type imageType = + | Still of Tk.options + | Animated of animatedGif + +let debug = ref false + +let cTKtoCAMLgifFrame s = + match splitlist s with + | [photo; width; height; left; top; delay] -> + {imagephoto = cTKtoCAMLimagePhoto photo; + frameWidth = int_of_string width; + frameHeight = int_of_string height; + left = int_of_string left; + top = int_of_string top; + delay = int_of_string delay} + | _ -> raise (Invalid_argument ("cTKtoCAMLgifFrame: " ^ s)) + +let cTKtoCAMLanimatedGif s = + match splitlist s with + | [width; height; frames; loop] -> + {frames = List.map cTKtoCAMLgifFrame (splitlist frames); + animWidth = int_of_string width; + animHeight = int_of_string height; + loop = int_of_string loop} + | _ -> raise (Invalid_argument ("cTKtoCAMLgifFrame: " ^ s)) + +(* check Tkanim package is in the interpreter *) +let available () = + let packages = + splitlist (Protocol.tkEval [| TkToken "package"; + TkToken "names" |]) + in + List.mem "Tkanim" packages + +let create file = + let s = + Protocol.tkEval [| TkToken "animation"; + TkToken "create"; + TkToken file |] + in + let anmgif = cTKtoCAMLanimatedGif s in + match anmgif.frames with + | [] -> raise (TkError "Null frame in a gif ?") + | [x] -> Still (ImagePhoto x.imagephoto) + | _ -> Animated anmgif + +let delete anim = + List.iter (fun {imagephoto = i} -> Imagephoto.delete i) anim.frames + +let width anm = anm.animWidth +let height anm = anm.animHeight +let images anm = List.map (fun x -> x.imagephoto) anm.frames + +let image_existence_check img = + (* I found there is a bug in Tk (even v8.0a2). *) + (* We can copy from deleted images, Tk never says "it doesn't exist", *) + (* But just do some operation. And sometimes it causes Seg-fault. *) + (* So, before using Imagephoto.copy, I should check the source image *) + (* really exists. *) + try ignore (Imagephoto.height img) with + TkError s -> prerr_endline ("tkanim: " ^ s); raise (TkError s) + +let imagephoto_copy dst src opts = + image_existence_check src; + Imagephoto.copy dst src opts + +let animate_gen w i anim = + let length = List.length anim.frames in + let frames = Array.of_list anim.frames in + let current = ref 0 in + let loop = ref anim.loop in + let f = frames.(!current) in + imagephoto_copy i f.imagephoto + [ImgTo (f.left, f.top, f.left + f.frameWidth, + f.top + f.frameHeight)]; + let visible = ref true in + let animated = ref false in + let timer = ref None in + (* Loop *) + let display_current () = + let f = frames.(!current) in + imagephoto_copy i f.imagephoto + [ImgTo (f.left, f.top, + f.left + f.frameWidth, f.top + f.frameHeight)] + in + let rec tick () = + if not (Winfo.exists w && Winfo.viewable w) then begin + (* the widget is invisible. stop animation for efficiency *) + if !debug then prerr_endline "Stopped (Visibility)"; + visible := false; + end else + begin + display_current (); + let t = + Timer.add (if f.delay = 0 then 100 else f.delay * 10) + (fun () -> + incr current; + if !current = length then begin + current := 0; + (* loop check *) + if !loop > 1 then begin + decr loop; + if !loop = 0 then begin + if !debug then prerr_endline "Loop end"; + (* stop *) + loop := anim.loop; + timer := None + end + end + end; + tick ()) + in + timer := Some t + end + in + let start () = + animated := true; + tick () + in + let stop () = + match !timer with + | Some t -> + Timer.remove t; + timer := None; + animated := false + | None -> () + in + let next () = + if !timer = None then begin + incr current; + if !current = length then current := 0; + display_current () + end + in + (* We shouldn't delete the animation here. *) +(* + bind w [[], Destroy] + (BindSet ([], (fun _ -> Imagephoto.delete i))); +*) + bind w [[], Visibility] + (BindSet ([], (fun _ -> + if not !visible then begin + visible := true; + if !animated then start () + end))); + (function + | false -> + if !animated then stop () else start () + | true -> next ()) + +let animate label anim = + (* prerr_endline "animate"; *) + let i = Imagephoto.create [Width (Pixels anim.animWidth); + Height (Pixels anim.animHeight)] + in + bind label [[], Destroy] (BindExtend ([], (fun _ -> + Imagephoto.delete i))); + Label.configure label [ImagePhoto i]; + animate_gen label i anim + +let animate_canvas_item canvas tag anim = +(* prerr_endline "animate"; *) + let i = Imagephoto.create [Width (Pixels anim.animWidth); + Height (Pixels anim.animHeight)] + in + bind canvas [[], Destroy] (BindExtend ([], (fun _ -> + Imagephoto.delete i))); + Canvas.configure_image canvas tag [ImagePhoto i]; + animate_gen canvas i anim + +let gifdata s = + let tmp_dir = ref Filename.temp_dir_name in + let mktemp = + let cnter = ref 0 + and pid = Unix.getpid() in + (function prefx -> + incr cnter; + (Filename.concat !tmp_dir + (prefx ^ string_of_int pid ^ "." ^ string_of_int !cnter))) + in + let fname = mktemp "gifdata" in + let oc = open_out_bin fname in + try + output_string oc s; + close_out oc; + let anim = create fname in + Unix.unlink fname; + anim + with + e -> begin Unix.unlink fname; raise e end + diff --git a/otherlibs/labltk/tkanim/tkanim.mli b/otherlibs/labltk/tkanim/tkanim.mli new file mode 100644 index 0000000..e83ceb9 --- /dev/null +++ b/otherlibs/labltk/tkanim/tkanim.mli @@ -0,0 +1,95 @@ +(***********************************************************************) +(* *) +(* MLTk, Tcl/Tk interface of Objective Caml *) +(* *) +(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *) +(* projet Cristal, INRIA Rocquencourt *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique and Kyoto University. All rights reserved. *) +(* This file is distributed under the terms of the GNU Library *) +(* General Public License, with the special exception on linking *) +(* described in file LICENSE found in the Objective Caml source tree. *) +(* *) +(***********************************************************************) +open Camltk +open Widget +open Support + +(*** Data types ***) + +type animatedGif + + (* This data type contains all the information of an animation of + gif89a format. It is still test implementation, so I should + keep it abstract. --- JPF *) + +type imageType = + | Still of Tk.options + | Animated of animatedGif + + (* This data type is required to distinguish normal still images + and animated gifs. Usually objects typed imagePhoto or + imageBitmap are used for Still. *) + +(*** Flags ***) + +val debug : bool ref + +(*** Library availability check ***) + +val init : unit -> unit + + (* This function calls the initialization function for Tkanim + Tcl/Tk extension. *) + +val available : unit -> bool + + (* [available ()] returns true if there is Tkanim Tcl/Tk + extension linked statically/dynamically in Tcl/Tk + interpreter. Otherwise, return false. *) + +(*** User interface ***) + +(* create is unsafe *) +val create : string -> imageType + + (* [create file] loads a gif87 or gif89 image file and parse it, + and returns [Animated animated_gif] if the image file has + more than one images. Otherwise, it returns + [Still (ImagePhoto image_photo)] *) + +val delete : animatedGif -> unit + + (* [delete anim] deletes all the images in anim. Usually + animatedGifs contain many images, so you must not forget to + use this function to free the memory. *) + +val width : animatedGif -> int +val height : animatedGif -> int + (* [width anim] and [height anim] return the width and height of + given animated gif. *) + +val images : animatedGif -> imagePhoto list + (* [images anim] returns the list of still images used in the + animation *) + +val animate : widget -> animatedGif -> bool -> unit +val animate_canvas_item : widget -> tagOrId -> animatedGif -> bool -> unit + (* The display functions for animated gifs. Since [animatedGif] is + an abstract type, you must use those functions to display + [animatedGif] images. + [animate label anim] and [animate_canvas_item canvas tag anim] + display animation [anim] on a label widget [label] or an + image tag [tag] on a canvas widget [canvas] respectively. + + Note that animation is stopped by default. + These functions return interface functions, say, [inter : + bool -> unit]. Currently, [inter false] toggles start/stop of + the animation, and [inter true] displays the next frame of + the animation if the animation is stopped. *) + +val gifdata : string -> imageType + (* [gifdata data] reads [data] as a row data of a gif file and + decodes it. *) diff --git a/otherlibs/num/.cvsignore b/otherlibs/num/.cvsignore new file mode 100644 index 0000000..7786c62 --- /dev/null +++ b/otherlibs/num/.cvsignore @@ -0,0 +1,3 @@ +libnums.x +*.c.x +so_locations diff --git a/otherlibs/num/.depend b/otherlibs/num/.depend new file mode 100644 index 0000000..51dcc1c --- /dev/null +++ b/otherlibs/num/.depend @@ -0,0 +1,50 @@ +bng.o: bng.c bng.h ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h bng_ia32.c \ + bng_digit.c +bng_alpha.o: bng_alpha.c +bng_amd64.o: bng_amd64.c +bng_digit.o: bng_digit.c +bng_ia32.o: bng_ia32.c +bng_mips.o: bng_mips.c +bng_ppc.o: bng_ppc.c +bng_sparc.o: bng_sparc.c +nat_stubs.o: nat_stubs.c ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h ../../byterun/custom.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/intext.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/io.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fix_code.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h bng.h nat.h +arith_flags.cmi: +arith_status.cmi: +big_int.cmi: nat.cmi +int_misc.cmi: +nat.cmi: +num.cmi: ratio.cmi nat.cmi big_int.cmi +ratio.cmi: nat.cmi big_int.cmi +arith_flags.cmo: arith_flags.cmi +arith_flags.cmx: arith_flags.cmi +arith_status.cmo: arith_flags.cmi arith_status.cmi +arith_status.cmx: arith_flags.cmx arith_status.cmi +big_int.cmo: nat.cmi int_misc.cmi big_int.cmi +big_int.cmx: nat.cmx int_misc.cmx big_int.cmi +int_misc.cmo: int_misc.cmi +int_misc.cmx: int_misc.cmi +nat.cmo: int_misc.cmi nat.cmi +nat.cmx: int_misc.cmx nat.cmi +num.cmo: ratio.cmi nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi num.cmi +num.cmx: ratio.cmx nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx num.cmi +ratio.cmo: nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi ratio.cmi +ratio.cmx: nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx ratio.cmi diff --git a/otherlibs/num/.depend.nt b/otherlibs/num/.depend.nt new file mode 100644 index 0000000..fbb31b2 --- /dev/null +++ b/otherlibs/num/.depend.nt @@ -0,0 +1,66 @@ +bng.dobj: bng.c bng.h ../../byterun/config.h ../../config/m.h \ + ../../config/s.h ../../byterun/compatibility.h bng_ppc.c bng_digit.c +bng_alpha.dobj: bng_alpha.c +bng_amd64.dobj: bng_amd64.c +bng_digit.dobj: bng_digit.c +bng_ia32.dobj: bng_ia32.c +bng_mips.dobj: bng_mips.c +bng_ppc.dobj: bng_ppc.c +bng_sparc.dobj: bng_sparc.c +nat_stubs.dobj: nat_stubs.c ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/config.h ../../config/m.h ../../config/s.h \ + ../../byterun/mlvalues.h ../../byterun/custom.h ../../byterun/intext.h \ + ../../byterun/io.h ../../byterun/fix_code.h ../../byterun/fail.h \ + ../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/minor_gc.h bng.h nat.h +big_int.cmi: nat.cmi +num.cmi: ratio.cmi nat.cmi big_int.cmi +ratio.cmi: nat.cmi big_int.cmi +arith_flags.cmo: arith_flags.cmi +arith_flags.cmx: arith_flags.cmi +arith_status.cmo: arith_flags.cmi arith_status.cmi +arith_status.cmx: arith_flags.cmx arith_status.cmi +big_int.cmo: nat.cmi int_misc.cmi big_int.cmi +big_int.cmx: nat.cmx int_misc.cmx big_int.cmi +int_misc.cmo: int_misc.cmi +int_misc.cmx: int_misc.cmi +nat.cmo: int_misc.cmi nat.cmi +nat.cmx: int_misc.cmx nat.cmi +num.cmo: ratio.cmi nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi num.cmi +num.cmx: ratio.cmx nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx num.cmi +ratio.cmo: nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi ratio.cmi +ratio.cmx: nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx ratio.cmi +bng.sobj: bng.c bng.h ../../byterun/config.h ../../config/m.h \ + ../../config/s.h ../../byterun/compatibility.h bng_ppc.c bng_digit.c +bng_alpha.sobj: bng_alpha.c +bng_amd64.sobj: bng_amd64.c +bng_digit.sobj: bng_digit.c +bng_ia32.sobj: bng_ia32.c +bng_mips.sobj: bng_mips.c +bng_ppc.sobj: bng_ppc.c +bng_sparc.sobj: bng_sparc.c +nat_stubs.sobj: nat_stubs.c ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/config.h ../../config/m.h ../../config/s.h \ + ../../byterun/mlvalues.h ../../byterun/custom.h ../../byterun/intext.h \ + ../../byterun/io.h ../../byterun/fix_code.h ../../byterun/fail.h \ + ../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/minor_gc.h bng.h nat.h +big_int.cmi: nat.cmi +num.cmi: ratio.cmi nat.cmi big_int.cmi +ratio.cmi: nat.cmi big_int.cmi +arith_flags.cmo: arith_flags.cmi +arith_flags.cmx: arith_flags.cmi +arith_status.cmo: arith_flags.cmi arith_status.cmi +arith_status.cmx: arith_flags.cmx arith_status.cmi +big_int.cmo: nat.cmi int_misc.cmi big_int.cmi +big_int.cmx: nat.cmx int_misc.cmx big_int.cmi +int_misc.cmo: int_misc.cmi +int_misc.cmx: int_misc.cmi +nat.cmo: int_misc.cmi nat.cmi +nat.cmx: int_misc.cmx nat.cmi +num.cmo: ratio.cmi nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi num.cmi +num.cmx: ratio.cmx nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx num.cmi +ratio.cmo: nat.cmi int_misc.cmi big_int.cmi arith_flags.cmi ratio.cmi +ratio.cmx: nat.cmx int_misc.cmx big_int.cmx arith_flags.cmx ratio.cmi diff --git a/otherlibs/num/Makefile b/otherlibs/num/Makefile new file mode 100644 index 0000000..35a2889 --- /dev/null +++ b/otherlibs/num/Makefile @@ -0,0 +1,38 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.37 2008-09-10 16:10:43 weis Exp $ + +# Makefile for the "num" (exact rational arithmetic) library + +LIBNAME=nums +EXTRACFLAGS=-DBNG_ARCH_$(BNG_ARCH) -DBNG_ASM_LEVEL=$(BNG_ASM_LEVEL) +CAMLOBJS=int_misc.cmo nat.cmo big_int.cmo arith_flags.cmo \ + ratio.cmo num.cmo arith_status.cmo +CMIFILES=big_int.cmi nat.cmi num.cmi ratio.cmi arith_status.cmi +COBJS=bng.$(O) nat_stubs.$(O) + +include ../Makefile + +clean:: + rm -f *~ + cd test; $(MAKE) clean + +bng.$(O): bng.h bng_digit.c \ + bng_alpha.c bng_amd64.c bng_ia32.c bng_mips.c bng_ppc.c bng_sparc.c + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/num/Makefile.nt b/otherlibs/num/Makefile.nt new file mode 100644 index 0000000..814c741 --- /dev/null +++ b/otherlibs/num/Makefile.nt @@ -0,0 +1,36 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.22 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the "num" (exact rational arithmetic) library + +LIBNAME=nums +EXTRACFLAGS=-DBNG_ARCH_$(BNG_ARCH) -DBNG_ASM_LEVEL=$(BNG_ASM_LEVEL) +CAMLOBJS=int_misc.cmo nat.cmo big_int.cmo arith_flags.cmo \ + ratio.cmo num.cmo arith_status.cmo +CMIFILES=big_int.cmi nat.cmi num.cmi ratio.cmi arith_status.cmi +COBJS=bng.$(O) nat_stubs.$(O) + +include ../Makefile.nt + +clean:: + cd test ; $(MAKEREC) clean + +bng.$(O): bng.h bng_digit.c \ + bng_alpha.c bng_amd64.c bng_ia32.c bng_mips.c bng_ppc.c bng_sparc.c + +depend: + sed -e 's/\.o/.$(O)/g' .depend > .depend.nt + +include .depend.nt diff --git a/otherlibs/num/README b/otherlibs/num/README new file mode 100644 index 0000000..d4969bf --- /dev/null +++ b/otherlibs/num/README @@ -0,0 +1,55 @@ +The "libnum" library implements exact-precision arithmetic on +big integers and on rationals. + +This library is derived from Valerie Menissie-Morain's implementation +of rational arithmetic for Caml V3.1 (INRIA). Xavier Leroy (INRIA) +did the Caml Light port. Victor Manuel Gulias Fernandez did the +initial Caml Special Light port. Pierre Weis did most of the +maintenance and bug fixing. + +Initially, the low-level big integer operations were provided by the +BigNum package developed by Bernard Serpette, Jean Vuillemin and +Jean-Claude Herve (INRIA and Digital PRL). License issues forced us to +replace the BigNum package. The current implementation of low-level +big integer operations is due to Xavier Leroy. + +This library is documented in "The CAML Numbers Reference Manual" by +Valerie Menissier-Morain, technical report 141, INRIA, july 1992, +available at ftp://ftp.inria.fr/INRIA/publication/RT/RT-0141.ps.gz + + +USAGE: + +To use the bignum library from your programs, just do + + ocamlc <options> nums.cma <.cmo and .ml files> +or + ocamlopt <options> nums.cmxa <.cmx and .ml files> + +for the linking phase. + +If you'd like to have the bignum functions available at toplevel, do + + ocamlmktop -o ocamltopnum <options> nums.cma <.cmo and .ml files> + ./ocamltopnum + +As an example, try: + + open Num;; + let rec fact n = + if n = 0 then Int 1 else mult_num (num_of_int n) (fact(n-1));; + string_of_num(fact 1000);; + + +PROCESSOR-SPECIFIC OPTIMIZATIONS: + +When compiled with GCC, the low-level primitives use "inline extended asm" +to exploit useful features of the target processor (additions and +subtractions with carry; double-width multiplication, division). +Here are the processors for which such optimizations are available: + IA32 (x86) (carry, dwmult, dwdiv, 64-bit ops with SSE2 if available) + AMD64 (Opteron) (carry, dwmult, dwdiv) + PowerPC (carry, dwmult) + Alpha (dwmult) + SPARC (carry, dwmult, dwdiv) + MIPS (dwmult) diff --git a/otherlibs/num/arith_flags.ml b/otherlibs/num/arith_flags.ml new file mode 100644 index 0000000..abc4bd9 --- /dev/null +++ b/otherlibs/num/arith_flags.ml @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arith_flags.ml,v 1.4 2001-12-07 13:40:14 xleroy Exp $ *) + +let error_when_null_denominator_flag = ref true;; + +let normalize_ratio_flag = ref false;; + +let normalize_ratio_when_printing_flag = ref true;; + +let floating_precision = ref 12;; + +let approx_printing_flag = ref false;; + diff --git a/otherlibs/num/arith_flags.mli b/otherlibs/num/arith_flags.mli new file mode 100644 index 0000000..fb65541 --- /dev/null +++ b/otherlibs/num/arith_flags.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arith_flags.mli,v 1.5 2001-12-07 13:40:14 xleroy Exp $ *) + +val error_when_null_denominator_flag : bool ref +val normalize_ratio_flag : bool ref +val normalize_ratio_when_printing_flag : bool ref +val floating_precision : int ref +val approx_printing_flag : bool ref diff --git a/otherlibs/num/arith_status.ml b/otherlibs/num/arith_status.ml new file mode 100644 index 0000000..6a03dab --- /dev/null +++ b/otherlibs/num/arith_status.ml @@ -0,0 +1,100 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arith_status.ml,v 1.4 2001-12-07 13:40:14 xleroy Exp $ *) + +open Arith_flags;; + +let get_error_when_null_denominator () = + !error_when_null_denominator_flag +and set_error_when_null_denominator choice = + error_when_null_denominator_flag := choice;; + +let get_normalize_ratio () = !normalize_ratio_flag +and set_normalize_ratio choice = normalize_ratio_flag := choice;; + +let get_normalize_ratio_when_printing () = + !normalize_ratio_when_printing_flag +and set_normalize_ratio_when_printing choice = + normalize_ratio_when_printing_flag := choice;; + +let get_floating_precision () = !floating_precision +and set_floating_precision i = floating_precision := i;; + +let get_approx_printing () = !approx_printing_flag +and set_approx_printing b = approx_printing_flag := b;; + +let arith_print_string s = print_string s; print_string " --> ";; + +let arith_print_bool = function + true -> print_string "ON" +| _ -> print_string "OFF" +;; + +let arith_status () = + print_newline (); + + arith_print_string + "Normalization during computation"; + arith_print_bool (get_normalize_ratio ()); + print_newline (); + print_string " (returned by get_normalize_ratio ())"; + print_newline (); + print_string " (modifiable with set_normalize_ratio <your choice>)"; + print_newline (); + print_newline (); + + arith_print_string + "Normalization when printing"; + arith_print_bool (get_normalize_ratio_when_printing ()); + print_newline (); + print_string + " (returned by get_normalize_ratio_when_printing ())"; + print_newline (); + print_string + " (modifiable with set_normalize_ratio_when_printing <your choice>)"; + print_newline (); + print_newline (); + + arith_print_string + "Floating point approximation when printing rational numbers"; + arith_print_bool (get_approx_printing ()); + print_newline (); + print_string + " (returned by get_approx_printing ())"; + print_newline (); + print_string + " (modifiable with set_approx_printing <your choice>)"; + print_newline (); + (if (get_approx_printing ()) + then (print_string " Default precision = "; + print_int (get_floating_precision ()); + print_newline (); + print_string " (returned by get_floating_precision ())"; + print_newline (); + print_string + " (modifiable with set_floating_precision <your choice>)"; + print_newline (); + print_newline ()) + else print_newline()); + + arith_print_string + "Error when a rational denominator is null"; + arith_print_bool (get_error_when_null_denominator ()); + print_newline (); + print_string " (returned by get_error_when_null_denominator ())"; + print_newline (); + print_string + " (modifiable with set_error_when_null_denominator <your choice>)"; + print_newline () +;; diff --git a/otherlibs/num/arith_status.mli b/otherlibs/num/arith_status.mli new file mode 100644 index 0000000..7682022 --- /dev/null +++ b/otherlibs/num/arith_status.mli @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arith_status.mli,v 1.6 2001-12-07 13:40:14 xleroy Exp $ *) + +(** Flags that control rational arithmetic. *) + +val arith_status: unit -> unit + (** Print the current status of the arithmetic flags. *) + +val get_error_when_null_denominator : unit -> bool + (** See {!Arith_status.set_error_when_null_denominator}.*) +val set_error_when_null_denominator : bool -> unit + (** Get or set the flag [null_denominator]. When on, attempting to + create a rational with a null denominator raises an exception. + When off, rationals with null denominators are accepted. + Initially: on. *) + +val get_normalize_ratio : unit -> bool + (** See {!Arith_status.set_normalize_ratio}.*) +val set_normalize_ratio : bool -> unit + (** Get or set the flag [normalize_ratio]. When on, rational + numbers are normalized after each operation. When off, + rational numbers are not normalized until printed. + Initially: off. *) + +val get_normalize_ratio_when_printing : unit -> bool + (** See {!Arith_status.set_normalize_ratio_when_printing}.*) +val set_normalize_ratio_when_printing : bool -> unit + (** Get or set the flag [normalize_ratio_when_printing]. + When on, rational numbers are normalized before being printed. + When off, rational numbers are printed as is, without normalization. + Initially: on. *) + +val get_approx_printing : unit -> bool + (** See {!Arith_status.set_approx_printing}.*) +val set_approx_printing : bool -> unit + (** Get or set the flag [approx_printing]. + When on, rational numbers are printed as a decimal approximation. + When off, rational numbers are printed as a fraction. + Initially: off. *) + +val get_floating_precision : unit -> int + (** See {!Arith_status.set_floating_precision}.*) +val set_floating_precision : int -> unit + (** Get or set the parameter [floating_precision]. + This parameter is the number of digits displayed when + [approx_printing] is on. + Initially: 12. *) + diff --git a/otherlibs/num/big_int.ml b/otherlibs/num/big_int.ml new file mode 100644 index 0000000..024946c --- /dev/null +++ b/otherlibs/num/big_int.ml @@ -0,0 +1,658 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: big_int.ml,v 1.24 2008-08-03 09:04:40 xleroy Exp $ *) + +open Int_misc +open Nat + +type big_int = + { sign : int; + abs_value : nat } + +let create_big_int sign nat = + if sign = 1 || sign = -1 || + (sign = 0 && + is_zero_nat nat 0 (num_digits_nat nat 0 (length_nat nat))) + then { sign = sign; + abs_value = nat } + else invalid_arg "create_big_int" + +(* Sign of a big_int *) +let sign_big_int bi = bi.sign + +let zero_big_int = + { sign = 0; + abs_value = make_nat 1 } + +let unit_big_int = + { sign = 1; + abs_value = nat_of_int 1 } + +(* Number of digits in a big_int *) +let num_digits_big_int bi = + num_digits_nat (bi.abs_value) 0 (length_nat bi.abs_value) + +(* Opposite of a big_int *) +let minus_big_int bi = + { sign = - bi.sign; + abs_value = copy_nat (bi.abs_value) 0 (num_digits_big_int bi)} + +(* Absolute value of a big_int *) +let abs_big_int bi = + { sign = if bi.sign = 0 then 0 else 1; + abs_value = copy_nat (bi.abs_value) 0 (num_digits_big_int bi)} + +(* Comparison operators on big_int *) + +(* + compare_big_int (bi, bi2) = sign of (bi-bi2) + i.e. 1 if bi > bi2 + 0 if bi = bi2 + -1 if bi < bi2 +*) +let compare_big_int bi1 bi2 = + if bi1.sign = 0 && bi2.sign = 0 then 0 + else if bi1.sign < bi2.sign then -1 + else if bi1.sign > bi2.sign then 1 + else if bi1.sign = 1 then + compare_nat (bi1.abs_value) 0 (num_digits_big_int bi1) + (bi2.abs_value) 0 (num_digits_big_int bi2) + else + compare_nat (bi2.abs_value) 0 (num_digits_big_int bi2) + (bi1.abs_value) 0 (num_digits_big_int bi1) + +let eq_big_int bi1 bi2 = compare_big_int bi1 bi2 = 0 +and le_big_int bi1 bi2 = compare_big_int bi1 bi2 <= 0 +and ge_big_int bi1 bi2 = compare_big_int bi1 bi2 >= 0 +and lt_big_int bi1 bi2 = compare_big_int bi1 bi2 < 0 +and gt_big_int bi1 bi2 = compare_big_int bi1 bi2 > 0 + +let max_big_int bi1 bi2 = if lt_big_int bi1 bi2 then bi2 else bi1 +and min_big_int bi1 bi2 = if gt_big_int bi1 bi2 then bi2 else bi1 + +(* Operations on big_int *) + +let pred_big_int bi = + match bi.sign with + 0 -> { sign = -1; abs_value = nat_of_int 1} + | 1 -> let size_bi = num_digits_big_int bi in + let copy_bi = copy_nat (bi.abs_value) 0 size_bi in + ignore (decr_nat copy_bi 0 size_bi 0); + { sign = if is_zero_nat copy_bi 0 size_bi then 0 else 1; + abs_value = copy_bi } + | _ -> let size_bi = num_digits_big_int bi in + let size_res = succ (size_bi) in + let copy_bi = create_nat (size_res) in + blit_nat copy_bi 0 (bi.abs_value) 0 size_bi; + set_digit_nat copy_bi size_bi 0; + ignore (incr_nat copy_bi 0 size_res 1); + { sign = -1; + abs_value = copy_bi } + +let succ_big_int bi = + match bi.sign with + 0 -> {sign = 1; abs_value = nat_of_int 1} + | -1 -> let size_bi = num_digits_big_int bi in + let copy_bi = copy_nat (bi.abs_value) 0 size_bi in + ignore (decr_nat copy_bi 0 size_bi 0); + { sign = if is_zero_nat copy_bi 0 size_bi then 0 else -1; + abs_value = copy_bi } + | _ -> let size_bi = num_digits_big_int bi in + let size_res = succ (size_bi) in + let copy_bi = create_nat (size_res) in + blit_nat copy_bi 0 (bi.abs_value) 0 size_bi; + set_digit_nat copy_bi size_bi 0; + ignore (incr_nat copy_bi 0 size_res 1); + { sign = 1; + abs_value = copy_bi } + +let add_big_int bi1 bi2 = + let size_bi1 = num_digits_big_int bi1 + and size_bi2 = num_digits_big_int bi2 in + if bi1.sign = bi2.sign + then (* Add absolute values if signs are the same *) + { sign = bi1.sign; + abs_value = + match compare_nat (bi1.abs_value) 0 size_bi1 + (bi2.abs_value) 0 size_bi2 with + -1 -> let res = create_nat (succ size_bi2) in + (blit_nat res 0 (bi2.abs_value) 0 size_bi2; + set_digit_nat res size_bi2 0; + ignore + (add_nat res 0 (succ size_bi2) + (bi1.abs_value) 0 size_bi1 0); + res) + |_ -> let res = create_nat (succ size_bi1) in + (blit_nat res 0 (bi1.abs_value) 0 size_bi1; + set_digit_nat res size_bi1 0; + ignore (add_nat res 0 (succ size_bi1) + (bi2.abs_value) 0 size_bi2 0); + res)} + + else (* Subtract absolute values if signs are different *) + match compare_nat (bi1.abs_value) 0 size_bi1 + (bi2.abs_value) 0 size_bi2 with + 0 -> zero_big_int + | 1 -> { sign = bi1.sign; + abs_value = + let res = copy_nat (bi1.abs_value) 0 size_bi1 in + (ignore (sub_nat res 0 size_bi1 + (bi2.abs_value) 0 size_bi2 1); + res) } + | _ -> { sign = bi2.sign; + abs_value = + let res = copy_nat (bi2.abs_value) 0 size_bi2 in + (ignore (sub_nat res 0 size_bi2 + (bi1.abs_value) 0 size_bi1 1); + res) } + +(* Coercion with int type *) +let big_int_of_int i = + { sign = sign_int i; + abs_value = + let res = (create_nat 1) + in (if i = monster_int + then (set_digit_nat res 0 biggest_int; + ignore (incr_nat res 0 1 1)) + else set_digit_nat res 0 (abs i)); + res } + +let add_int_big_int i bi = add_big_int (big_int_of_int i) bi + +let sub_big_int bi1 bi2 = add_big_int bi1 (minus_big_int bi2) + +(* Returns i * bi *) +let mult_int_big_int i bi = + let size_bi = num_digits_big_int bi in + let size_res = succ size_bi in + if i = monster_int + then let res = create_nat size_res in + blit_nat res 0 (bi.abs_value) 0 size_bi; + set_digit_nat res size_bi 0; + ignore (mult_digit_nat res 0 size_res (bi.abs_value) 0 size_bi + (nat_of_int biggest_int) 0); + { sign = - (sign_big_int bi); + abs_value = res } + else let res = make_nat (size_res) in + ignore (mult_digit_nat res 0 size_res (bi.abs_value) 0 size_bi + (nat_of_int (abs i)) 0); + { sign = (sign_int i) * (sign_big_int bi); + abs_value = res } + +let mult_big_int bi1 bi2 = + let size_bi1 = num_digits_big_int bi1 + and size_bi2 = num_digits_big_int bi2 in + let size_res = size_bi1 + size_bi2 in + let res = make_nat (size_res) in + { sign = bi1.sign * bi2.sign; + abs_value = + if size_bi2 > size_bi1 + then (ignore (mult_nat res 0 size_res (bi2.abs_value) 0 size_bi2 + (bi1.abs_value) 0 size_bi1);res) + else (ignore (mult_nat res 0 size_res (bi1.abs_value) 0 size_bi1 + (bi2.abs_value) 0 size_bi2);res) } + +(* (quotient, rest) of the euclidian division of 2 big_int *) +let quomod_big_int bi1 bi2 = + if bi2.sign = 0 then raise Division_by_zero + else + let size_bi1 = num_digits_big_int bi1 + and size_bi2 = num_digits_big_int bi2 in + match compare_nat (bi1.abs_value) 0 size_bi1 + (bi2.abs_value) 0 size_bi2 with + -1 -> (* 1/2 -> 0, reste 1, -1/2 -> -1, reste 1 *) + (* 1/-2 -> 0, reste 1, -1/-2 -> 1, reste 1 *) + if bi1.sign >= 0 then + (big_int_of_int 0, bi1) + else if bi2.sign >= 0 then + (big_int_of_int(-1), add_big_int bi2 bi1) + else + (big_int_of_int 1, sub_big_int bi1 bi2) + | 0 -> (big_int_of_int (bi1.sign * bi2.sign), zero_big_int) + | _ -> let bi1_negatif = bi1.sign = -1 in + let size_q = + if bi1_negatif + then succ (max (succ (size_bi1 - size_bi2)) 1) + else max (succ (size_bi1 - size_bi2)) 1 + and size_r = succ (max size_bi1 size_bi2) + (* r is long enough to contain both quotient and remainder *) + (* of the euclidian division *) + in + (* set up quotient, remainder *) + let q = create_nat size_q + and r = create_nat size_r in + blit_nat r 0 (bi1.abs_value) 0 size_bi1; + set_to_zero_nat r size_bi1 (size_r - size_bi1); + + (* do the division of |bi1| by |bi2| + - at the beginning, r contains |bi1| + - at the end, r contains + * in the size_bi2 least significant digits, the remainder + * in the size_r-size_bi2 most significant digits, the quotient + note the conditions for application of div_nat are verified here + *) + div_nat r 0 size_r (bi2.abs_value) 0 size_bi2; + + (* separate quotient and remainder *) + blit_nat q 0 r size_bi2 (size_r - size_bi2); + let not_null_mod = not (is_zero_nat r 0 size_bi2) in + + (* correct the signs, adjusting the quotient and remainder *) + if bi1_negatif && not_null_mod + then + (* bi1<0, r>0, noting r for (r, size_bi2) the remainder, *) + (* we have |bi1|=q * |bi2| + r with 0 < r < |bi2|, *) + (* thus -bi1 = q * |bi2| + r *) + (* and bi1 = (-q) * |bi2| + (-r) with -|bi2| < (-r) < 0 *) + (* thus bi1 = -(q+1) * |bi2| + (|bi2|-r) *) + (* with 0 < (|bi2|-r) < |bi2| *) + (* so the quotient has for sign the opposite of the bi2'one *) + (* and for value q+1 *) + (* and the remainder is strictly positive *) + (* has for value |bi2|-r *) + (let new_r = copy_nat (bi2.abs_value) 0 size_bi2 in + (* new_r contains (r, size_bi2) the remainder *) + { sign = - bi2.sign; + abs_value = (set_digit_nat q (pred size_q) 0; + ignore (incr_nat q 0 size_q 1); q) }, + { sign = 1; + abs_value = + (ignore (sub_nat new_r 0 size_bi2 r 0 size_bi2 1); + new_r) }) + else + (if bi1_negatif then set_digit_nat q (pred size_q) 0; + { sign = if is_zero_nat q 0 size_q + then 0 + else bi1.sign * bi2.sign; + abs_value = q }, + { sign = if not_null_mod then 1 else 0; + abs_value = copy_nat r 0 size_bi2 }) + +let div_big_int bi1 bi2 = fst (quomod_big_int bi1 bi2) +and mod_big_int bi1 bi2 = snd (quomod_big_int bi1 bi2) + +let gcd_big_int bi1 bi2 = + let size_bi1 = num_digits_big_int bi1 + and size_bi2 = num_digits_big_int bi2 in + if is_zero_nat (bi1.abs_value) 0 size_bi1 then abs_big_int bi2 + else if is_zero_nat (bi2.abs_value) 0 size_bi2 then + { sign = 1; + abs_value = bi1.abs_value } + else + { sign = 1; + abs_value = + match compare_nat (bi1.abs_value) 0 size_bi1 + (bi2.abs_value) 0 size_bi2 with + 0 -> bi1.abs_value + | 1 -> + let res = copy_nat (bi1.abs_value) 0 size_bi1 in + let len = + gcd_nat res 0 size_bi1 (bi2.abs_value) 0 size_bi2 in + copy_nat res 0 len + | _ -> + let res = copy_nat (bi2.abs_value) 0 size_bi2 in + let len = + gcd_nat res 0 size_bi2 (bi1.abs_value) 0 size_bi1 in + copy_nat res 0 len + } + +(* Coercion operators *) + +let monster_big_int = big_int_of_int monster_int;; + +let monster_nat = monster_big_int.abs_value;; + +let is_int_big_int bi = + num_digits_big_int bi == 1 && + match compare_nat bi.abs_value 0 1 monster_nat 0 1 with + | 0 -> bi.sign == -1 + | -1 -> true + | _ -> false;; + +let int_of_big_int bi = + try let n = int_of_nat bi.abs_value in + if bi.sign = -1 then - n else n + with Failure _ -> + if eq_big_int bi monster_big_int then monster_int + else failwith "int_of_big_int";; + +let big_int_of_nativeint i = + if i = 0n then + zero_big_int + else if i > 0n then begin + let res = create_nat 1 in + set_digit_nat_native res 0 i; + { sign = 1; abs_value = res } + end else begin + let res = create_nat 1 in + set_digit_nat_native res 0 (Nativeint.neg i); + { sign = -1; abs_value = res } + end + +let nativeint_of_big_int bi = + if num_digits_big_int bi > 1 then failwith "nativeint_of_big_int"; + let i = nth_digit_nat_native bi.abs_value 0 in + if bi.sign >= 0 then + if i >= 0n then i else failwith "nativeint_of_big_int" + else + if i >= 0n || i = Nativeint.min_int + then Nativeint.neg i + else failwith "nativeint_of_big_int" + +let big_int_of_int32 i = big_int_of_nativeint (Nativeint.of_int32 i) + +let int32_of_big_int bi = + let i = nativeint_of_big_int bi in + if i <= 0x7FFF_FFFFn && i >= -0x8000_0000n + then Nativeint.to_int32 i + else failwith "int32_of_big_int" + +let big_int_of_int64 i = + if Sys.word_size = 64 then + big_int_of_nativeint (Int64.to_nativeint i) + else begin + let (sg, absi) = + if i = 0L then (0, 0L) + else if i > 0L then (1, i) + else (-1, Int64.neg i) in + let res = create_nat 2 in + set_digit_nat_native res 0 (Int64.to_nativeint i); + set_digit_nat_native res 1 (Int64.to_nativeint (Int64.shift_right i 32)); + { sign = sg; abs_value = res } + end + +let int64_of_big_int bi = + if Sys.word_size = 64 then + Int64.of_nativeint (nativeint_of_big_int bi) + else begin + let i = + match num_digits_big_int bi with + | 1 -> Int64.of_nativeint (nth_digit_nat_native bi.abs_value 0) + | 2 -> Int64.logor + (Int64.logand + (Int64.of_nativeint (nth_digit_nat_native bi.abs_value 0)) + 0xFFFFFFFFL) + (Int64.shift_left + (Int64.of_nativeint (nth_digit_nat_native bi.abs_value 1)) + 32) + | _ -> failwith "int64_of_big_int" in + if bi.sign >= 0 then + if i >= 0L then i else failwith "int64_of_big_int" + else + if i >= 0L || i = Int64.min_int + then Int64.neg i + else failwith "int64_of_big_int" + end + +(* Coercion with nat type *) +let nat_of_big_int bi = + if bi.sign = -1 + then failwith "nat_of_big_int" + else copy_nat (bi.abs_value) 0 (num_digits_big_int bi) + +let sys_big_int_of_nat nat off len = + let length = num_digits_nat nat off len in + { sign = if is_zero_nat nat off length then 0 else 1; + abs_value = copy_nat nat off length } + +let big_int_of_nat nat = + sys_big_int_of_nat nat 0 (length_nat nat) + +(* Coercion with string type *) + +let string_of_big_int bi = + if bi.sign = -1 + then "-" ^ string_of_nat bi.abs_value + else string_of_nat bi.abs_value + + +let sys_big_int_of_string_aux s ofs len sgn = + if len < 1 then failwith "sys_big_int_of_string"; + let n = sys_nat_of_string 10 s ofs len in + if is_zero_nat n 0 (length_nat n) then zero_big_int + else {sign = sgn; abs_value = n} +;; + +let sys_big_int_of_string s ofs len = + if len < 1 then failwith "sys_big_int_of_string"; + match s.[ofs] with + | '-' -> sys_big_int_of_string_aux s (ofs+1) (len-1) (-1) + | '+' -> sys_big_int_of_string_aux s (ofs+1) (len-1) 1 + | _ -> sys_big_int_of_string_aux s ofs len 1 +;; + +let big_int_of_string s = + sys_big_int_of_string s 0 (String.length s) + +let power_base_nat base nat off len = + if base = 0 then nat_of_int 0 else + if is_zero_nat nat off len || base = 1 then nat_of_int 1 else + let power_base = make_nat (succ length_of_digit) in + let (pmax, pint) = make_power_base base power_base in + let (n, rem) = + let (x, y) = quomod_big_int (sys_big_int_of_nat nat off len) + (big_int_of_int (succ pmax)) in + (int_of_big_int x, int_of_big_int y) in + if n = 0 then copy_nat power_base (pred rem) 1 else + begin + let res = make_nat n + and res2 = make_nat (succ n) + and l = num_bits_int n - 2 in + let p = ref (1 lsl l) in + blit_nat res 0 power_base pmax 1; + for i = l downto 0 do + let len = num_digits_nat res 0 n in + let len2 = min n (2 * len) in + let succ_len2 = succ len2 in + ignore (square_nat res2 0 len2 res 0 len); + begin + if n land !p > 0 + then (set_to_zero_nat res 0 len; + ignore (mult_digit_nat res 0 succ_len2 + res2 0 len2 power_base pmax)) + else blit_nat res 0 res2 0 len2 + end; + set_to_zero_nat res2 0 len2; + p := !p lsr 1 + done; + if rem > 0 + then (ignore (mult_digit_nat res2 0 (succ n) + res 0 n power_base (pred rem)); + res2) + else res + end + +let power_int_positive_int i n = + match sign_int n with + 0 -> unit_big_int + | -1 -> invalid_arg "power_int_positive_int" + | _ -> let nat = power_base_int (abs i) n in + { sign = if i >= 0 + then sign_int i + else if n land 1 = 0 + then 1 + else -1; + abs_value = nat} + +let power_big_int_positive_int bi n = + match sign_int n with + 0 -> unit_big_int + | -1 -> invalid_arg "power_big_int_positive_int" + | _ -> let bi_len = num_digits_big_int bi in + let res_len = bi_len * n in + let res = make_nat res_len + and res2 = make_nat res_len + and l = num_bits_int n - 2 in + let p = ref (1 lsl l) in + blit_nat res 0 bi.abs_value 0 bi_len; + for i = l downto 0 do + let len = num_digits_nat res 0 res_len in + let len2 = min res_len (2 * len) in + set_to_zero_nat res2 0 len2; + ignore (square_nat res2 0 len2 res 0 len); + if n land !p > 0 then begin + let lenp = min res_len (len2 + bi_len) in + set_to_zero_nat res 0 lenp; + ignore(mult_nat res 0 lenp res2 0 len2 (bi.abs_value) 0 bi_len) + end else begin + blit_nat res 0 res2 0 len2 + end; + p := !p lsr 1 + done; + {sign = if bi.sign >= 0 then bi.sign + else if n land 1 = 0 then 1 else -1; + abs_value = res} + +let power_int_positive_big_int i bi = + match sign_big_int bi with + 0 -> unit_big_int + | -1 -> invalid_arg "power_int_positive_big_int" + | _ -> let nat = power_base_nat + (abs i) (bi.abs_value) 0 (num_digits_big_int bi) in + { sign = if i >= 0 + then sign_int i + else if is_digit_odd (bi.abs_value) 0 + then -1 + else 1; + abs_value = nat } + +let power_big_int_positive_big_int bi1 bi2 = + match sign_big_int bi2 with + 0 -> unit_big_int + | -1 -> invalid_arg "power_big_int_positive_big_int" + | _ -> try + power_big_int_positive_int bi1 (int_of_big_int bi2) + with Failure _ -> + try + power_int_positive_big_int (int_of_big_int bi1) bi2 + with Failure _ -> + raise Out_of_memory + (* If neither bi1 nor bi2 is a small integer, bi1^bi2 is not + representable. Indeed, on a 32-bit platform, + |bi1| >= 2 and |bi2| >= 2^30, hence bi1^bi2 has at least + 2^30 bits = 2^27 bytes, greater than the max size of + allocated blocks. On a 64-bit platform, + |bi1| >= 2 and |bi2| >= 2^62, hence bi1^bi2 has at least + 2^62 bits = 2^59 bytes, greater than the max size of + allocated blocks. *) + +(* base_power_big_int compute bi*base^n *) +let base_power_big_int base n bi = + match sign_int n with + 0 -> bi + | -1 -> let nat = power_base_int base (-n) in + let len_nat = num_digits_nat nat 0 (length_nat nat) + and len_bi = num_digits_big_int bi in + if len_bi < len_nat then + invalid_arg "base_power_big_int" + else if len_bi = len_nat && + compare_digits_nat (bi.abs_value) len_bi nat len_nat = -1 + then invalid_arg "base_power_big_int" + else + let copy = create_nat (succ len_bi) in + blit_nat copy 0 (bi.abs_value) 0 len_bi; + set_digit_nat copy len_bi 0; + div_nat copy 0 (succ len_bi) + nat 0 len_nat; + if not (is_zero_nat copy 0 len_nat) + then invalid_arg "base_power_big_int" + else { sign = bi.sign; + abs_value = copy_nat copy len_nat 1 } + | _ -> let nat = power_base_int base n in + let len_nat = num_digits_nat nat 0 (length_nat nat) + and len_bi = num_digits_big_int bi in + let new_len = len_bi + len_nat in + let res = make_nat new_len in + ignore + (if len_bi > len_nat + then mult_nat res 0 new_len + (bi.abs_value) 0 len_bi + nat 0 len_nat + else mult_nat res 0 new_len + nat 0 len_nat + (bi.abs_value) 0 len_bi) + ; if is_zero_nat res 0 new_len + then zero_big_int + else create_big_int (bi.sign) res + +(* Coercion with float type *) + +let float_of_big_int bi = + float_of_string (string_of_big_int bi) + +(* XL: suppression de big_int_of_float et nat_of_float. *) + +(* Other functions needed *) + +(* Integer part of the square root of a big_int *) +let sqrt_big_int bi = + match bi.sign with + | 0 -> zero_big_int + | -1 -> invalid_arg "sqrt_big_int" + | _ -> {sign = 1; + abs_value = sqrt_nat (bi.abs_value) 0 (num_digits_big_int bi)} + +let square_big_int bi = + if bi.sign == 0 then zero_big_int else + let len_bi = num_digits_big_int bi in + let len_res = 2 * len_bi in + let res = make_nat len_res in + ignore (square_nat res 0 len_res (bi.abs_value) 0 len_bi); + {sign = 1; abs_value = res} + +(* round off of the futur last digit (of the integer represented by the string + argument of the function) that is now the previous one. + if s contains an integer of the form (10^n)-1 + then s <- only 0 digits and the result_int is true + else s <- the round number and the result_int is false *) +let round_futur_last_digit s off_set length = + let l = pred (length + off_set) in + if Char.code(String.get s l) >= Char.code '5' + then + let rec round_rec l = + if l < off_set then true else begin + let current_char = String.get s l in + if current_char = '9' then + (String.set s l '0'; round_rec (pred l)) + else + (String.set s l (Char.chr (succ (Char.code current_char))); + false) + end + in round_rec (pred l) + else false + + +(* Approximation with floating decimal point a` la approx_ratio_exp *) +let approx_big_int prec bi = + let len_bi = num_digits_big_int bi in + let n = + max 0 + (int_of_big_int ( + add_int_big_int + (-prec) + (div_big_int (mult_big_int (big_int_of_int (pred len_bi)) + (big_int_of_string "963295986")) + (big_int_of_string "100000000")))) in + let s = + string_of_big_int (div_big_int bi (power_int_positive_int 10 n)) in + let (sign, off, len) = + if String.get s 0 = '-' + then ("-", 1, succ prec) + else ("", 0, prec) in + if (round_futur_last_digit s off (succ prec)) + then (sign^"1."^(String.make prec '0')^"e"^ + (string_of_int (n + 1 - off + String.length s))) + else (sign^(String.sub s off 1)^"."^ + (String.sub s (succ off) (pred prec)) + ^"e"^(string_of_int (n - succ off + String.length s))) diff --git a/otherlibs/num/big_int.mli b/otherlibs/num/big_int.mli new file mode 100644 index 0000000..1f968cb --- /dev/null +++ b/otherlibs/num/big_int.mli @@ -0,0 +1,163 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: big_int.mli,v 1.11 2008-01-04 13:15:52 xleroy Exp $ *) + +(** Operations on arbitrary-precision integers. + + Big integers (type [big_int]) are signed integers of arbitrary size. +*) + +open Nat + +type big_int + (** The type of big integers. *) + +val zero_big_int : big_int + (** The big integer [0]. *) +val unit_big_int : big_int + (** The big integer [1]. *) + +(** {6 Arithmetic operations} *) + +val minus_big_int : big_int -> big_int + (** Unary negation. *) +val abs_big_int : big_int -> big_int + (** Absolute value. *) +val add_big_int : big_int -> big_int -> big_int + (** Addition. *) +val succ_big_int : big_int -> big_int + (** Successor (add 1). *) +val add_int_big_int : int -> big_int -> big_int + (** Addition of a small integer to a big integer. *) +val sub_big_int : big_int -> big_int -> big_int + (** Subtraction. *) +val pred_big_int : big_int -> big_int + (** Predecessor (subtract 1). *) +val mult_big_int : big_int -> big_int -> big_int + (** Multiplication of two big integers. *) +val mult_int_big_int : int -> big_int -> big_int + (** Multiplication of a big integer by a small integer *) +val square_big_int: big_int -> big_int + (** Return the square of the given big integer *) +val sqrt_big_int: big_int -> big_int + (** [sqrt_big_int a] returns the integer square root of [a], + that is, the largest big integer [r] such that [r * r <= a]. + Raise [Invalid_argument] if [a] is negative. *) +val quomod_big_int : big_int -> big_int -> big_int * big_int + (** Euclidean division of two big integers. + The first part of the result is the quotient, + the second part is the remainder. + Writing [(q,r) = quomod_big_int a b], we have + [a = q * b + r] and [0 <= r < |b|]. + Raise [Division_by_zero] if the divisor is zero. *) +val div_big_int : big_int -> big_int -> big_int + (** Euclidean quotient of two big integers. + This is the first result [q] of [quomod_big_int] (see above). *) +val mod_big_int : big_int -> big_int -> big_int + (** Euclidean modulus of two big integers. + This is the second result [r] of [quomod_big_int] (see above). *) +val gcd_big_int : big_int -> big_int -> big_int + (** Greatest common divisor of two big integers. *) +val power_int_positive_int: int -> int -> big_int +val power_big_int_positive_int: big_int -> int -> big_int +val power_int_positive_big_int: int -> big_int -> big_int +val power_big_int_positive_big_int: big_int -> big_int -> big_int + (** Exponentiation functions. Return the big integer + representing the first argument [a] raised to the power [b] + (the second argument). Depending + on the function, [a] and [b] can be either small integers + or big integers. Raise [Invalid_argument] if [b] is negative. *) + +(** {6 Comparisons and tests} *) + +val sign_big_int : big_int -> int + (** Return [0] if the given big integer is zero, + [1] if it is positive, and [-1] if it is negative. *) +val compare_big_int : big_int -> big_int -> int + (** [compare_big_int a b] returns [0] if [a] and [b] are equal, + [1] if [a] is greater than [b], and [-1] if [a] is smaller + than [b]. *) +val eq_big_int : big_int -> big_int -> bool +val le_big_int : big_int -> big_int -> bool +val ge_big_int : big_int -> big_int -> bool +val lt_big_int : big_int -> big_int -> bool +val gt_big_int : big_int -> big_int -> bool + (** Usual boolean comparisons between two big integers. *) +val max_big_int : big_int -> big_int -> big_int + (** Return the greater of its two arguments. *) +val min_big_int : big_int -> big_int -> big_int + (** Return the smaller of its two arguments. *) +val num_digits_big_int : big_int -> int + (** Return the number of machine words used to store the + given big integer. *) + +(** {6 Conversions to and from strings} *) + +val string_of_big_int : big_int -> string + (** Return the string representation of the given big integer, + in decimal (base 10). *) +val big_int_of_string : string -> big_int + (** Convert a string to a big integer, in decimal. + The string consists of an optional [-] or [+] sign, + followed by one or several decimal digits. *) + +(** {6 Conversions to and from other numerical types} *) + +val big_int_of_int : int -> big_int + (** Convert a small integer to a big integer. *) +val is_int_big_int : big_int -> bool + (** Test whether the given big integer is small enough to + be representable as a small integer (type [int]) + without loss of precision. On a 32-bit platform, + [is_int_big_int a] returns [true] if and only if + [a] is between 2{^30} and 2{^30}-1. On a 64-bit platform, + [is_int_big_int a] returns [true] if and only if + [a] is between -2{^62} and 2{^62}-1. *) +val int_of_big_int : big_int -> int + (** Convert a big integer to a small integer (type [int]). + Raises [Failure "int_of_big_int"] if the big integer + is not representable as a small integer. *) + +val big_int_of_int32 : int32 -> big_int + (** Convert a 32-bit integer to a big integer. *) +val big_int_of_nativeint : nativeint -> big_int + (** Convert a native integer to a big integer. *) +val big_int_of_int64 : int64 -> big_int + (** Convert a 64-bit integer to a big integer. *) +val int32_of_big_int : big_int -> int32 + (** Convert a big integer to a 32-bit integer. + Raises [Failure] if the big integer is outside the + range [[-2{^31}, 2{^31}-1]]. *) +val nativeint_of_big_int : big_int -> nativeint + (** Convert a big integer to a native integer. + Raises [Failure] if the big integer is outside the + range [[Nativeint.min_int, Nativeint.max_int]]. *) +val int64_of_big_int : big_int -> int64 + (** Convert a big integer to a 64-bit integer. + Raises [Failure] if the big integer is outside the + range [[-2{^63}, 2{^63}-1]]. *) + +val float_of_big_int : big_int -> float + (** Returns a floating-point number approximating the + given big integer. *) + +(**/**) + +(** {6 For internal use} *) +val nat_of_big_int : big_int -> nat +val big_int_of_nat : nat -> big_int +val base_power_big_int: int -> int -> big_int -> big_int +val sys_big_int_of_string: string -> int -> int -> big_int +val round_futur_last_digit : string -> int -> int -> bool +val approx_big_int: int -> big_int -> string diff --git a/otherlibs/num/bignum/.cvsignore b/otherlibs/num/bignum/.cvsignore new file mode 100644 index 0000000..c76baff --- /dev/null +++ b/otherlibs/num/bignum/.cvsignore @@ -0,0 +1 @@ +libbignum.x diff --git a/otherlibs/num/bng.c b/otherlibs/num/bng.c new file mode 100644 index 0000000..620af87 --- /dev/null +++ b/otherlibs/num/bng.c @@ -0,0 +1,435 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng.c,v 1.4 2005-09-22 14:21:50 xleroy Exp $ */ + +#include "bng.h" +#include "config.h" + +#if defined(__GNUC__) && BNG_ASM_LEVEL > 0 +#if defined(BNG_ARCH_ia32) +#include "bng_ia32.c" +#elif defined(BNG_ARCH_amd64) +#include "bng_amd64.c" +#elif defined(BNG_ARCH_ppc) +#include "bng_ppc.c" +#elif defined (BNG_ARCH_alpha) +#include "bng_alpha.c" +#elif defined (BNG_ARCH_sparc) +#include "bng_sparc.c" +#elif defined (BNG_ARCH_mips) +#include "bng_mips.c" +#endif +#endif + +#include "bng_digit.c" + +/**** Operations that cannot be overriden ****/ + +/* Return number of leading zero bits in d */ +int bng_leading_zero_bits(bngdigit d) +{ + int n = BNG_BITS_PER_DIGIT; +#ifdef ARCH_SIXTYFOUR + if ((d & 0xFFFFFFFF00000000L) != 0) { n -= 32; d = d >> 32; } +#endif + if ((d & 0xFFFF0000) != 0) { n -= 16; d = d >> 16; } + if ((d & 0xFF00) != 0) { n -= 8; d = d >> 8; } + if ((d & 0xF0) != 0) { n -= 4; d = d >> 4; } + if ((d & 0xC) != 0) { n -= 2; d = d >> 2; } + if ((d & 2) != 0) { n -= 1; d = d >> 1; } + return n - d; +} + +/* Complement the digits of {a,len} */ +void bng_complement(bng a/*[alen]*/, bngsize alen) +{ + for (/**/; alen > 0; alen--, a++) *a = ~*a; +} + +/* Return number of significant digits in {a,alen}. */ +bngsize bng_num_digits(bng a/*[alen]*/, bngsize alen) +{ + while (1) { + if (alen == 0) return 1; + if (a[alen - 1] != 0) return alen; + alen--; + } +} + +/* Return 0 if {a,alen} = {b,blen} + -1 if {a,alen} < {b,blen} + 1 if {a,alen} > {b,blen}. */ +int bng_compare(bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen) +{ + bngdigit da, db; + + while (alen > 0 && a[alen-1] == 0) alen--; + while (blen > 0 && b[blen-1] == 0) blen--; + if (alen > blen) return 1; + if (alen < blen) return -1; + while (alen > 0) { + alen--; + da = a[alen]; + db = b[alen]; + if (da > db) return 1; + if (da < db) return -1; + } + return 0; +} + +/**** Generic definitions of the overridable operations ****/ + +/* {a,alen} := {a, alen} + carry. Return carry out. */ +static bngcarry bng_generic_add_carry + (bng a/*[alen]*/, bngsize alen, bngcarry carry) +{ + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a,alen} + {b,blen} + carry. Return carry out. + Require alen >= blen. */ +static bngcarry bng_generic_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + alen -= blen; + for (/**/; blen > 0; blen--, a++, b++) { + BngAdd2Carry(*a, carry, *a, *b, carry); + } + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a, alen} - carry. Return carry out. */ +static bngcarry bng_generic_sub_carry + (bng a/*[alen]*/, bngsize alen, bngcarry carry) +{ + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a,alen} - {b,blen} - carry. Return carry out. + Require alen >= blen. */ +static bngcarry bng_generic_sub + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + alen -= blen; + for (/**/; blen > 0; blen--, a++, b++) { + BngSub2Carry(*a, carry, *a, *b, carry); + } + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a,alen} << shift. + Return the bits shifted out of the most significant digit of a. + Require 0 <= shift < BITS_PER_BNGDIGIT. */ +static bngdigit bng_generic_shift_left + (bng a/*[alen]*/, bngsize alen, + int shift) +{ + int shift2 = BNG_BITS_PER_DIGIT - shift; + bngdigit carry = 0; + if (shift > 0) { + for (/**/; alen > 0; alen--, a++) { + bngdigit d = *a; + *a = (d << shift) | carry; + carry = d >> shift2; + } + } + return carry; +} + +/* {a,alen} := {a,alen} >> shift. + Return the bits shifted out of the least significant digit of a. + Require 0 <= shift < BITS_PER_BNGDIGIT. */ +static bngdigit bng_generic_shift_right + (bng a/*[alen]*/, bngsize alen, + int shift) +{ + int shift2 = BNG_BITS_PER_DIGIT - shift; + bngdigit carry = 0; + if (shift > 0) { + for (a = a + alen - 1; alen > 0; alen--, a--) { + bngdigit d = *a; + *a = (d >> shift) | carry; + carry = d << shift2; + } + } + return carry; +} + +/* {a,alen} := {a,alen} + d * {b,blen}. Return carry out. + Require alen >= blen. */ +static bngdigit bng_generic_mult_add_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out, ph, pl; + bngcarry carry; + + alen -= blen; + for (out = 0; blen > 0; blen--, a++, b++) { + bngdigit bd = *b; + /* ph:pl = double-digit product of b's current digit and d */ + BngMult(ph, pl, bd, d); + /* current digit of a += pl + out. Accumulate carries in ph. */ + BngAdd3(*a, ph, *a, pl, out); + /* prepare out for next iteration */ + out = ph; + } + if (alen == 0) return out; + /* current digit of a += out */ + BngAdd2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a,alen} - d * {b,blen}. Return carry out. + Require alen >= blen. */ +static bngdigit bng_generic_mult_sub_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out, ph, pl; + bngcarry carry; + + alen -= blen; + for (out = 0; blen > 0; blen--, a++, b++) { + bngdigit bd = *b; + /* ph:pl = double-digit product of b's current digit and d */ + BngMult(ph, pl, bd, d); + /* current digit of a -= pl + out. Accumulate carrys in ph. */ + BngSub3(*a, ph, *a, pl, out); + /* prepare out for next iteration */ + out = ph; + } + if (alen == 0) return out; + /* current digit of a -= out */ + BngSub2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* {a,alen} := {a,alen} + {b,blen} * {c,clen}. Return carry out. + Require alen >= blen + clen. */ +static bngcarry bng_generic_mult_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bng c/*[clen]*/, bngsize clen) +{ + bngcarry carry; + for (carry = 0; clen > 0; clen--, c++, alen--, a++) + carry += bng_mult_add_digit(a, alen, b, blen, *c); + return carry; +} + +/* {a,alen} := 2 * {a,alen} + {b,blen}^2. Return carry out. + Require alen >= 2 * blen. */ +static bngcarry bng_generic_square_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen) +{ + bngcarry carry1, carry2; + bngsize i, aofs; + bngdigit ph, pl, d; + + /* Double products */ + for (carry1 = 0, i = 1; i < blen; i++) { + aofs = 2 * i - 1; + carry1 += bng_mult_add_digit(a + aofs, alen - aofs, + b + i, blen - i, b[i - 1]); + } + /* Multiply by two */ + carry1 = (carry1 << 1) | bng_shift_left(a, alen, 1); + /* Add square of digits */ + carry2 = 0; + for (i = 0; i < blen; i++) { + d = b[i]; + BngMult(ph, pl, d, d); + BngAdd2Carry(*a, carry2, *a, pl, carry2); + a++; + BngAdd2Carry(*a, carry2, *a, ph, carry2); + a++; + } + alen -= 2 * blen; + if (alen > 0 && carry2 != 0) { + do { + if (++(*a) != 0) { carry2 = 0; break; } + a++; + } while (--alen); + } + return carry1 + carry2; +} + +/* {a,len-1} := {b,len} / d. Return {b,len} modulo d. + Require MSD of b < d. + If BngDivNeedsNormalization is defined, require d normalized. */ +static bngdigit bng_generic_div_rem_norm_digit + (bng a/*[len-1]*/, bng b/*[len]*/, bngsize len, bngdigit d) +{ + bngdigit topdigit, quo, rem; + intnat i; + + topdigit = b[len - 1]; + for (i = len - 2; i >= 0; i--) { + /* Divide topdigit:current digit of numerator by d */ + BngDiv(quo, rem, topdigit, b[i], d); + /* Quotient is current digit of result */ + a[i] = quo; + /* Iterate with topdigit = remainder */ + topdigit = rem; + } + return topdigit; +} + +#ifdef BngDivNeedsNormalization +/* {a,len-1} := {b,len} / d. Return {b,len} modulo d. + Require MSD of b < d. */ +static bngdigit bng_generic_div_rem_digit + (bng a/*[len-1]*/, bng b/*[len]*/, bngsize len, bngdigit d) +{ + bngdigit rem; + int shift; + + /* Normalize d and b */ + shift = bng_leading_zero_bits(d); + d <<= shift; + bng_shift_left(b, len, shift); + /* Do the division */ + rem = bng_div_rem_norm_digit(a, b, len, d); + /* Undo normalization on b and remainder */ + bng_shift_right(b, len, shift); + return rem >> shift; +} +#endif + +/* {n+dlen, nlen-dlen} := {n,nlen} / {d, dlen}. + {n, dlen} := {n,nlen} modulo {d, dlen}. + Require nlen > dlen and MSD of n < MSD of d. + (This implies MSD of d > 0). */ +static void bng_generic_div_rem + (bng n/*[nlen]*/, bngsize nlen, + bng d/*[dlen]*/, bngsize dlen) +{ + bngdigit topden, quo, rem; + int shift; + bngsize i, j; + + /* Normalize d */ + shift = bng_leading_zero_bits(d[dlen - 1]); + /* Note that no bits of n are lost by the following shift, + since n[nlen-1] < d[dlen-1] */ + bng_shift_left(n, nlen, shift); + bng_shift_left(d, dlen, shift); + /* Special case if d is just one digit */ + if (dlen == 1) { + *n = bng_div_rem_norm_digit(n + 1, n, nlen, *d); + } else { + topden = d[dlen - 1]; + /* Long division */ + for (j = nlen - 1; j >= dlen; j--) { + i = j - dlen; + /* At this point: + - the current numerator is n[j] : ...................... : n[0] + - to be subtracted quo times: d[dlen-1] : ... : d[0] : 0... : 0 + (there are i zeroes at the end) */ + /* Under-estimate the next digit of the quotient (quo) */ + if (topden + 1 == 0) + quo = n[j]; + else + BngDiv(quo, rem, n[j], n[j - 1], topden + 1); + /* Subtract d * quo (shifted i places) from numerator */ + n[j] -= bng_mult_sub_digit(n + i, dlen, d, dlen, quo); + /* Adjust if necessary */ + while (n[j] != 0 || bng_compare(n + i, dlen, d, dlen) >= 0) { + /* Numerator is still bigger than shifted divisor. + Increment quotient and subtract shifted divisor. */ + quo++; + n[j] -= bng_sub(n + i, dlen, d, dlen, 0); + } + /* Store quotient digit */ + n[j] = quo; + } + } + /* Undo normalization on remainder and divisor */ + bng_shift_right(n, dlen, shift); + bng_shift_right(d, dlen, shift); +} + +/**** Construction of the table of operations ****/ + +struct bng_operations bng_ops = { + bng_generic_add_carry, + bng_generic_add, + bng_generic_sub_carry, + bng_generic_sub, + bng_generic_shift_left, + bng_generic_shift_right, + bng_generic_mult_add_digit, + bng_generic_mult_sub_digit, + bng_generic_mult_add, + bng_generic_square_add, + bng_generic_div_rem_norm_digit, +#ifdef BngDivNeedsNormalization + bng_generic_div_rem_digit, +#else + bng_generic_div_rem_norm_digit, +#endif + bng_generic_div_rem +}; + +void bng_init(void) +{ +#ifdef BNG_SETUP_OPS + BNG_SETUP_OPS; +#endif +} diff --git a/otherlibs/num/bng.h b/otherlibs/num/bng.h new file mode 100644 index 0000000..b33f058 --- /dev/null +++ b/otherlibs/num/bng.h @@ -0,0 +1,157 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng.h,v 1.3 2005-09-22 14:21:50 xleroy Exp $ */ + +#include <string.h> +#include "config.h" + +typedef uintnat bngdigit; +typedef bngdigit * bng; +typedef unsigned int bngcarry; +typedef uintnat bngsize; + +#define BNG_BITS_PER_DIGIT (sizeof(bngdigit) * 8) +#define BNG_BITS_PER_HALF_DIGIT (sizeof(bngdigit) * 4) + +struct bng_operations { + + /* {a,alen} := {a, alen} + carry. Return carry out. */ + bngcarry (*add_carry) + (bng a/*[alen]*/, bngsize alen, bngcarry carry); +#define bng_add_carry bng_ops.add_carry + + /* {a,alen} := {a,alen} + {b,blen} + carry. Return carry out. + Require alen >= blen. */ + bngcarry (*add) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry); +#define bng_add bng_ops.add + + /* {a,alen} := {a, alen} - carry. Return carry out. */ + bngcarry (*sub_carry) + (bng a/*[alen]*/, bngsize alen, bngcarry carry); +#define bng_sub_carry bng_ops.sub_carry + + /* {a,alen} := {a,alen} - {b,blen} - carry. Return carry out. + Require alen >= blen. */ + bngcarry (*sub) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry); +#define bng_sub bng_ops.sub + + /* {a,alen} := {a,alen} << shift. + Return the bits shifted out of the most significant digit of a. + Require 0 <= shift < BITS_PER_BNGDIGIT. */ + bngdigit (*shift_left) + (bng a/*[alen]*/, bngsize alen, + int shift); +#define bng_shift_left bng_ops.shift_left + + /* {a,alen} := {a,alen} >> shift. + Return the bits shifted out of the least significant digit of a. + Require 0 <= shift < BITS_PER_BNGDIGIT. */ + bngdigit (*shift_right) + (bng a/*[alen]*/, bngsize alen, + int shift); +#define bng_shift_right bng_ops.shift_right + + /* {a,alen} := {a,alen} + d * {b,blen}. Return carry out. + Require alen >= blen. + If alen > blen, the carry out returned is 0 or 1. + If alen == blen, the carry out returned is a full digit. */ + bngdigit (*mult_add_digit) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d); +#define bng_mult_add_digit bng_ops.mult_add_digit + + /* {a,alen} := {a,alen} - d * {b,blen}. Return carry out. + Require alen >= blen. + If alen > blen, the carry out returned is 0 or 1. + If alen == blen, the carry out returned is a full digit. */ + bngdigit (*mult_sub_digit) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d); +#define bng_mult_sub_digit bng_ops.mult_sub_digit + + /* {a,alen} := {a,alen} + {b,blen} * {c,clen}. Return carry out. + Require alen >= blen + clen. */ + bngcarry (*mult_add) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bng c/*[clen]*/, bngsize clen); +#define bng_mult_add bng_ops.mult_add + + /* {a,alen} := 2 * {a,alen} + {b,blen}^2. Return carry out. + Require alen >= 2 * blen. */ + bngcarry (*square_add) + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen); +#define bng_square_add bng_ops.square_add + + /* {a,len-1} := {b,len} / d. Return {b,len} modulo d. + Require d is normalized and MSD of b < d. + See div_rem_digit for a function that does not require d + to be normalized */ + bngdigit (*div_rem_norm_digit) + (bng a/*[len-1]*/, bng b/*[len]*/, bngsize len, bngdigit d); +#define bng_div_rem_norm_digit bng_ops.div_rem_norm_digit + + /* {a,len-1} := {b,len} / d. Return {b,len} modulo d. + Require MSD of b < d. */ + bngdigit (*div_rem_digit) + (bng a/*[len-1]*/, bng b/*[len]*/, bngsize len, bngdigit d); +#define bng_div_rem_digit bng_ops.div_rem_digit + + /* {n+dlen, nlen-dlen} := {n,nlen} / {d, dlen}. + {n, dlen} := {n,nlen} modulo {d, dlen}. + Require nlen > dlen and MSD of n < MSD of d (which implies d != 0). */ + void (*div_rem) + (bng n/*[nlen]*/, bngsize nlen, + bng d/*[nlen]*/, bngsize dlen); +#define bng_div_rem bng_ops.div_rem +}; + +extern struct bng_operations bng_ops; + +/* Initialize the BNG library */ +extern void bng_init(void); + +/* {a,alen} := 0 */ +#define bng_zero(a,alen) memset((a), 0, (alen) * sizeof(bngdigit)) + +/* {a,len} := {b,len} */ +#define bng_assign(a,b,len) memmove((a), (b), (len) * sizeof(bngdigit)) + +/* Complement the digits of {a,len} */ +extern void bng_complement(bng a/*[alen]*/, bngsize alen); + +/* Return number of significant digits in {a,alen}. */ +extern bngsize bng_num_digits(bng a/*[alen]*/, bngsize alen); + +/* Return 1 if {a,alen} is 0, 0 otherwise. */ +#define bng_is_zero(a,alen) (bng_num_digits(a,alen) == 0) + +/* Return 0 if {a,alen} = {b,blen} + <0 if {a,alen} < {b,blen} + >0 if {a,alen} > {b,blen}. */ +extern int bng_compare(bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen); + +/* Return the number of leading zero bits in digit d. */ +extern int bng_leading_zero_bits(bngdigit d); + diff --git a/otherlibs/num/bng_alpha.c b/otherlibs/num/bng_alpha.c new file mode 100644 index 0000000..c23e4e8 --- /dev/null +++ b/otherlibs/num/bng_alpha.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_alpha.c,v 1.1 2003-10-24 09:17:32 xleroy Exp $ */ + +/* Code specific to the Alpha architecture. */ + +#define BngMult(resh,resl,arg1,arg2) \ + asm("mulq %2, %3, %0 \n\t" \ + "umulh %2, %3, %1" \ + : "=&r" (resl), "=r" (resh) \ + : "r" (arg1), "r" (arg2)) + diff --git a/otherlibs/num/bng_amd64.c b/otherlibs/num/bng_amd64.c new file mode 100644 index 0000000..e91adf0 --- /dev/null +++ b/otherlibs/num/bng_amd64.c @@ -0,0 +1,196 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_amd64.c,v 1.1 2003-10-24 09:17:33 xleroy Exp $ */ + +/* Code specific to the AMD x86_64 architecture. */ + +#define BngAdd2(res,carryout,arg1,arg2) \ + asm("xorl %1, %1 \n\t" \ + "addq %3, %0 \n\t" \ + "setc %b1" \ + : "=r" (res), "=&q" (carryout) \ + : "0" (arg1), "rm" (arg2)) + +#define BngSub2(res,carryout,arg1,arg2) \ + asm("xorl %1, %1 \n\t" \ + "subq %3, %0 \n\t" \ + "setc %b1" \ + : "=r" (res), "=&q" (carryout) \ + : "0" (arg1), "rm" (arg2)) + +#define BngMult(resh,resl,arg1,arg2) \ + asm("mulq %3" \ + : "=a" (resl), "=d" (resh) \ + : "a" (arg1), "r" (arg2)) + +#define BngDiv(quo,rem,nh,nl,d) \ + asm("divq %4" \ + : "=a" (quo), "=d" (rem) \ + : "a" (nl), "d" (nh), "r" (d)) + +/* Reimplementation in asm of some of the bng operations. */ + +static bngcarry bng_amd64_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + bngdigit tmp; + alen -= blen; + if (blen > 0) { + asm("negb %b3 \n\t" + "1: \n\t" + "movq (%0), %4 \n\t" + "adcq (%1), %4 \n\t" + "movq %4, (%0) \n\t" + "leaq 8(%0), %0 \n\t" + "leaq 8(%1), %1 \n\t" + "decq %2 \n\t" + "jnz 1b \n\t" + "setc %b3" + : "=r" (a), "=r" (b), "=r" (blen), "=q" (carry), "=r" (tmp) + : "0" (a), "1" (b), "2" (blen), "3" (carry)); + } + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngcarry bng_amd64_sub + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + bngdigit tmp; + alen -= blen; + if (blen > 0) { + asm("negb %b3 \n\t" + "1: \n\t" + "movq (%0), %4 \n\t" + "sbbq (%1), %4 \n\t" + "movq %4, (%0) \n\t" + "leaq 8(%0), %0 \n\t" + "leaq 8(%1), %1 \n\t" + "decq %2 \n\t" + "jnz 1b \n\t" + "setc %b3" + : "=r" (a), "=r" (b), "=r" (blen), "=q" (carry), "=r" (tmp) + : "0" (a), "1" (b), "2" (blen), "3" (carry)); + } + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_amd64_mult_add_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + asm("1: \n\t" + "movq (%1), %%rax \n\t" + "mulq %7\n\t" /* rdx:rax = d * next digit of b */ + "addq (%0), %%rax \n\t" /* add next digit of a to rax */ + "adcq $0, %%rdx \n\t" /* accumulate carry in rdx */ + "addq %3, %%rax \n\t" /* add out to rax */ + "adcq $0, %%rdx \n\t" /* accumulate carry in rdx */ + "movq %%rax, (%0) \n\t" /* rax is next digit of result */ + "movq %%rdx, %3 \n\t" /* rdx is next out */ + "leaq 8(%0), %0 \n\t" + "leaq 8(%1), %1 \n\t" + "decq %2 \n\t" + "jnz 1b" + : "=&r" (a), "=&r" (b), "=&r" (blen), "=&r" (out) + : "0" (a), "1" (b), "2" (blen), "rm" (d), "3" (out) + : "rax", "rdx"); + } + if (alen == 0) return out; + /* current digit of a += out */ + BngAdd2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_amd64_mult_sub_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out, tmp; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + asm("1: \n\t" + "movq (%1), %%rax \n\t" + "movq (%0), %4 \n\t" + "mulq %8\n\t" /* rdx:rax = d * next digit of b */ + "subq %%rax, %4 \n\t" /* subtract rax from next digit of a */ + "adcq $0, %%rdx \n\t" /* accumulate carry in rdx */ + "subq %3, %4 \n\t" /* subtract out */ + "adcq $0, %%rdx \n\t" /* accumulate carry in rdx */ + "movq %4, (%0) \n\t" /* store next digit of result */ + "movq %%rdx, %3 \n\t" /* rdx is next out */ + "leaq 8(%0), %0 \n\t" + "leaq 8(%1), %1 \n\t" + "decq %2 \n\t" + "jnz 1b" + : "=&r" (a), "=&r" (b), "=&rm" (blen), "=&r" (out), "=&r" (tmp) + : "0" (a), "1" (b), "2" (blen), "rm" (d), "3" (out) + : "rax", "rdx"); + } + if (alen == 0) return out; + /* current digit of a -= out */ + BngSub2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static void bng_amd64_setup_ops(void) +{ + bng_ops.add = bng_amd64_add; + bng_ops.sub = bng_amd64_sub; + bng_ops.mult_add_digit = bng_amd64_mult_add_digit; + bng_ops.mult_sub_digit = bng_amd64_mult_sub_digit; +} + +#define BNG_SETUP_OPS bng_amd64_setup_ops() + diff --git a/otherlibs/num/bng_digit.c b/otherlibs/num/bng_digit.c new file mode 100644 index 0000000..1a359ac --- /dev/null +++ b/otherlibs/num/bng_digit.c @@ -0,0 +1,171 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_digit.c,v 1.1 2003-10-24 09:17:33 xleroy Exp $ */ + +/**** Generic operations on digits ****/ + +/* These macros can be defined in the machine-specific include file. + Below are the default definitions (in plain C). + Except for BngMult, all macros are guaranteed to evaluate their + arguments exactly once. */ + +#ifndef BngAdd2 +/* res = arg1 + arg2. carryout = carry out. */ +#define BngAdd2(res,carryout,arg1,arg2) { \ + bngdigit tmp1, tmp2; \ + tmp1 = arg1; \ + tmp2 = tmp1 + (arg2); \ + carryout = (tmp2 < tmp1); \ + res = tmp2; \ +} +#endif + +#ifndef BngAdd2Carry +/* res = arg1 + arg2 + carryin. carryout = carry out. */ +#define BngAdd2Carry(res,carryout,arg1,arg2,carryin) { \ + bngdigit tmp1, tmp2, tmp3; \ + tmp1 = arg1; \ + tmp2 = tmp1 + (arg2); \ + tmp3 = tmp2 + (carryin); \ + carryout = (tmp2 < tmp1) + (tmp3 < tmp2); \ + res = tmp3; \ +} +#endif + +#ifndef BngAdd3 +/* res = arg1 + arg2 + arg3. Each carry increments carryaccu. */ +#define BngAdd3(res,carryaccu,arg1,arg2,arg3) { \ + bngdigit tmp1, tmp2, tmp3; \ + tmp1 = arg1; \ + tmp2 = tmp1 + (arg2); \ + carryaccu += (tmp2 < tmp1); \ + tmp3 = tmp2 + (arg3); \ + carryaccu += (tmp3 < tmp2); \ + res = tmp3; \ +} +#endif + +#ifndef BngSub2 +/* res = arg1 - arg2. carryout = carry out. */ +#define BngSub2(res,carryout,arg1,arg2) { \ + bngdigit tmp1, tmp2; \ + tmp1 = arg1; \ + tmp2 = arg2; \ + res = tmp1 - tmp2; \ + carryout = (tmp1 < tmp2); \ +} +#endif + +#ifndef BngSub2Carry +/* res = arg1 - arg2 - carryin. carryout = carry out. */ +#define BngSub2Carry(res,carryout,arg1,arg2,carryin) { \ + bngdigit tmp1, tmp2, tmp3; \ + tmp1 = arg1; \ + tmp2 = arg2; \ + tmp3 = tmp1 - tmp2; \ + res = tmp3 - (carryin); \ + carryout = (tmp1 < tmp2) + (tmp3 < carryin); \ +} +#endif + +#ifndef BngSub3 +/* res = arg1 - arg2 - arg3. Each carry increments carryaccu. */ +#define BngSub3(res,carryaccu,arg1,arg2,arg3) { \ + bngdigit tmp1, tmp2, tmp3, tmp4; \ + tmp1 = arg1; \ + tmp2 = arg2; \ + tmp3 = arg3; \ + tmp4 = tmp1 - tmp2; \ + res = tmp4 - tmp3; \ + carryaccu += (tmp1 < tmp2) + (tmp4 < tmp3); \ +} +#endif + +#define BngLowHalf(d) ((d) & ((1L << BNG_BITS_PER_HALF_DIGIT) - 1)) +#define BngHighHalf(d) ((d) >> BNG_BITS_PER_HALF_DIGIT) + +#ifndef BngMult +/* resl = low digit of product arg1 * arg2 + resh = high digit of product arg1 * arg2. */ +#define BngMult(resh,resl,arg1,arg2) { \ + bngdigit p11 = BngLowHalf(arg1) * BngLowHalf(arg2); \ + bngdigit p12 = BngLowHalf(arg1) * BngHighHalf(arg2); \ + bngdigit p21 = BngHighHalf(arg1) * BngLowHalf(arg2); \ + bngdigit p22 = BngHighHalf(arg1) * BngHighHalf(arg2); \ + resh = p22 + (p12 >> BNG_BITS_PER_HALF_DIGIT) \ + + (p21 >> BNG_BITS_PER_HALF_DIGIT); \ + BngAdd3(resl, resh, \ + p11, p12 << BNG_BITS_PER_HALF_DIGIT, p21 << BNG_BITS_PER_HALF_DIGIT); \ +} +#endif + +#ifndef BngDiv +/* Divide the double-width number nh:nl by d. + Require d != 0 and nh < d. + Store quotient in quo, remainder in rem. + Can be slow if d is not normalized. */ +#define BngDiv(quo,rem,nh,nl,d) bng_div_aux(&(quo),&(rem),nh,nl,d) +#define BngDivNeedsNormalization + +static void bng_div_aux(bngdigit * quo, bngdigit * rem, + bngdigit nh, bngdigit nl, bngdigit d) +{ + bngdigit dl, dh, ql, qh, pl, ph, nsaved; + + dl = BngLowHalf(d); + dh = BngHighHalf(d); + /* Under-estimate the top half of the quotient (qh) */ + qh = nh / (dh + 1); + /* Shift nh:nl right by BNG_BITS_PER_HALF_DIGIT bits, + so that we focus on the top 1.5 digits of the numerator. + Then, subtract (qh * d) from nh:nl. */ + nsaved = BngLowHalf(nl); + ph = qh * dh; + pl = qh * dl; + nh -= ph; /* Subtract before shifting so that carry propagates for free */ + nl = (nl >> BNG_BITS_PER_HALF_DIGIT) | (nh << BNG_BITS_PER_HALF_DIGIT); + nh = (nh >> BNG_BITS_PER_HALF_DIGIT); + nh -= (nl < pl); /* Borrow */ + nl -= pl; + /* Adjust estimate qh until nh:nl < 0:d */ + while (nh != 0 || nl >= d) { + nh -= (nl < d); /* Borrow */ + nl -= d; + qh++; + } + /* Under-estimate the bottom half of the quotient (ql) */ + ql = nl / (dh + 1); + /* Shift nh:nl left by BNG_BITS_PER_HALF_DIGIT bits, restoring the + low bits we saved earlier, so that we focus on the bottom 1.5 digit + of the numerator. Then, subtract (ql * d) from nh:nl. */ + ph = ql * dh; + pl = ql * dl; + nl -= ph; /* Subtract before shifting so that carry propagates for free */ + nh = (nl >> BNG_BITS_PER_HALF_DIGIT); + nl = (nl << BNG_BITS_PER_HALF_DIGIT) | nsaved; + nh -= (nl < pl); /* Borrow */ + nl -= pl; + /* Adjust estimate ql until nh:nl < 0:d */ + while (nh != 0 || nl >= d) { + nh -= (nl < d); /* Borrow */ + nl -= d; + ql++; + } + /* We're done */ + *quo = (qh << BNG_BITS_PER_HALF_DIGIT) | ql; + *rem = nl; +} + +#endif + diff --git a/otherlibs/num/bng_ia32.c b/otherlibs/num/bng_ia32.c new file mode 100644 index 0000000..2e3baf7 --- /dev/null +++ b/otherlibs/num/bng_ia32.c @@ -0,0 +1,412 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_ia32.c,v 1.4 2005-08-13 20:59:37 doligez Exp $ */ + +/* Code specific to the Intel IA32 (x86) architecture. */ + +#define BngAdd2(res,carryout,arg1,arg2) \ + asm("xorl %1, %1 \n\t" \ + "addl %3, %0 \n\t" \ + "setc %b1" \ + : "=r" (res), "=&q" (carryout) \ + : "0" (arg1), "rm" (arg2)) + +#define BngSub2(res,carryout,arg1,arg2) \ + asm("xorl %1, %1 \n\t" \ + "subl %3, %0 \n\t" \ + "setc %b1" \ + : "=r" (res), "=&q" (carryout) \ + : "0" (arg1), "rm" (arg2)) + +#define BngMult(resh,resl,arg1,arg2) \ + asm("mull %3" \ + : "=a" (resl), "=d" (resh) \ + : "a" (arg1), "r" (arg2)) + +#define BngDiv(quo,rem,nh,nl,d) \ + asm("divl %4" \ + : "=a" (quo), "=d" (rem) \ + : "a" (nl), "d" (nh), "r" (d)) + +/* Reimplementation in asm of some of the bng operations. */ + +static bngcarry bng_ia32_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + bngdigit tmp; + alen -= blen; + if (blen > 0) { + asm("negb %b3 \n\t" + "1: \n\t" + "movl (%0), %4 \n\t" + "adcl (%1), %4 \n\t" + "movl %4, (%0) \n\t" + "leal 4(%0), %0 \n\t" + "leal 4(%1), %1 \n\t" + "decl %2 \n\t" + "jnz 1b \n\t" + "setc %b3" + : "+&r" (a), "+&r" (b), "+&r" (blen), "+&q" (carry), "=&r" (tmp)); + } + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngcarry bng_ia32_sub + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + bngdigit tmp; + alen -= blen; + if (blen > 0) { + asm("negb %b3 \n\t" + "1: \n\t" + "movl (%0), %4 \n\t" + "sbbl (%1), %4 \n\t" + "movl %4, (%0) \n\t" + "leal 4(%0), %0 \n\t" + "leal 4(%1), %1 \n\t" + "decl %2 \n\t" + "jnz 1b \n\t" + "setc %b3" + : "+&r" (a), "+&r" (b), "+&r" (blen), "+&q" (carry), "=&r" (tmp)); + } + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_ia32_mult_add_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + asm("1: \n\t" + "movl (%1), %%eax \n\t" + "mull %4\n\t" /* edx:eax = d * next digit of b */ + "addl (%0), %%eax \n\t" /* add next digit of a to eax */ + "adcl $0, %%edx \n\t" /* accumulate carry in edx */ + "addl %3, %%eax \n\t" /* add out to eax */ + "adcl $0, %%edx \n\t" /* accumulate carry in edx */ + "movl %%eax, (%0) \n\t" /* eax is next digit of result */ + "movl %%edx, %3 \n\t" /* edx is next out */ + "leal 4(%0), %0 \n\t" + "leal 4(%1), %1 \n\t" + "decl %2 \n\t" + "jnz 1b" + : "+&r" (a), "+&r" (b), "+&r" (blen), "=m" (out) + : "m" (d) + : "eax", "edx"); + } + if (alen == 0) return out; + /* current digit of a += out */ + BngAdd2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_ia32_mult_sub_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out, tmp; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + asm("1: \n\t" + "movl (%1), %%eax \n\t" + "movl (%0), %4 \n\t" + "mull %5\n\t" /* edx:eax = d * next digit of b */ + "subl %%eax, %4 \n\t" /* subtract eax from next digit of a */ + "adcl $0, %%edx \n\t" /* accumulate carry in edx */ + "subl %3, %4 \n\t" /* subtract out */ + "adcl $0, %%edx \n\t" /* accumulate carry in edx */ + "movl %4, (%0) \n\t" /* store next digit of result */ + "movl %%edx, %3 \n\t" /* edx is next out */ + "leal 4(%0), %0 \n\t" + "leal 4(%1), %1 \n\t" + "decl %2 \n\t" + "jnz 1b" + : "+&r" (a), "+&r" (b), "=m" (blen), "=m" (out), "=&r" (tmp) + : "m" (d) + : "eax", "edx"); + } + if (alen == 0) return out; + /* current digit of a -= out */ + BngSub2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* This is another asm implementation of some of the bng operations, + using SSE2 operations to provide 64-bit arithmetic. + This is faster than the plain IA32 code above on the Pentium 4. + (Arithmetic operations with carry are slow on the Pentium 4). */ + +#if BNG_ASM_LEVEL >= 2 + +static bngcarry bng_ia32sse2_add + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + alen -= blen; + if (blen > 0) { + asm("movd %3, %%mm0 \n\t" /* MM0 is carry */ + "1: \n\t" + "movd (%0), %%mm1 \n\t" /* MM1 is next digit of a */ + "movd (%1), %%mm2 \n\t" /* MM2 is next digit of b */ + "paddq %%mm1, %%mm0 \n\t" /* Add carry (64 bits) */ + "paddq %%mm2, %%mm0 \n\t" /* Add digits (64 bits) */ + "movd %%mm0, (%0) \n\t" /* Store low 32 bits of result */ + "psrlq $32, %%mm0 \n\t" /* Next carry is top 32 bits of results */ + "addl $4, %0\n\t" + "addl $4, %1\n\t" + "subl $1, %2\n\t" + "jne 1b \n\t" + "movd %%mm0, %3 \n\t" + "emms" + : "+&r" (a), "+&r" (b), "+&r" (blen), "+&rm" (carry)); + } + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngcarry bng_ia32sse2_sub + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngcarry carry) +{ + alen -= blen; + if (blen > 0) { + asm("movd %3, %%mm0 \n\t" /* MM0 is carry */ + "1: \n\t" + "movd (%0), %%mm1 \n\t" /* MM1 is next digit of a */ + "movd (%1), %%mm2 \n\t" /* MM2 is next digit of b */ + "psubq %%mm0, %%mm1 \n\t" /* Subtract carry (64 bits) */ + "psubq %%mm2, %%mm1 \n\t" /* Subtract digits (64 bits) */ + "movd %%mm1, (%0) \n\t" /* Store low 32 bits of result */ + "psrlq $63, %%mm1 \n\t" /* Next carry is sign bit of result */ + "movq %%mm1, %%mm0 \n\t" + "addl $4, %0\n\t" + "addl $4, %1\n\t" + "subl $1, %2\n\t" + "jne 1b \n\t" + "movd %%mm0, %3 \n\t" + "emms" + : "+&r" (a), "+&r" (b), "+&r" (blen), "+&rm" (carry)); + } + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_ia32sse2_mult_add_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + bngdigit out; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + asm("pxor %%mm0, %%mm0 \n\t" /* MM0 is carry */ + "movd %4, %%mm7 \n\t" /* MM7 is digit d */ + "1: \n\t" + "movd (%0), %%mm1 \n\t" /* MM1 is next digit of a */ + "movd (%1), %%mm2 \n\t" /* MM2 is next digit of b */ + "pmuludq %%mm7, %%mm2 \n\t" /* MM2 = d * digit of b */ + "paddq %%mm1, %%mm0 \n\t" /* Add product and carry ... */ + "paddq %%mm2, %%mm0 \n\t" /* ... and digit of a */ + "movd %%mm0, (%0) \n\t" /* Store low 32 bits of result */ + "psrlq $32, %%mm0 \n\t" /* Next carry is high 32 bits result */ + "addl $4, %0\n\t" + "addl $4, %1\n\t" + "subl $1, %2\n\t" + "jne 1b \n\t" + "movd %%mm0, %3 \n\t" + "emms" + : "+&r" (a), "+&r" (b), "+&r" (blen), "=&rm" (out) + : "m" (d)); + } + if (alen == 0) return out; + /* current digit of a += out */ + BngAdd2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if (++(*a) != 0) return 0; + a++; + } while (--alen); + return 1; +} + +static bngdigit bng_ia32sse2_mult_sub_digit + (bng a/*[alen]*/, bngsize alen, + bng b/*[blen]*/, bngsize blen, + bngdigit d) +{ + static unsigned long long bias1 = 0xFFFFFFFF00000000ULL - 0xFFFFFFFFULL; + static unsigned long bias2 = 0xFFFFFFFFUL; + bngdigit out; + bngcarry carry; + + alen -= blen; + out = 0; + if (blen > 0) { + /* Carry C is represented by ENC(C) = 0xFFFFFFFF - C (one's complement) */ + asm("movd %6, %%mm0 \n\t" /* MM0 is carry (initially 0xFFFFFFFF) */ + "movq %5, %%mm6 \n\t" /* MM6 is magic constant bias1 */ + "movd %4, %%mm7 \n\t" /* MM7 is digit d */ + "1: \n\t" + "movd (%0), %%mm1 \n\t" /* MM1 is next digit of a */ + "movd (%1), %%mm2 \n\t" /* MM2 is next digit of b */ + "paddq %%mm6, %%mm1 \n\t" /* bias digit of a */ + "pmuludq %%mm7, %%mm2 \n\t" /* MM2 = d * digit of b */ + /* Compute + digit of a + ENC(carry) + 0xFFFFFFFF00000000 - 0xFFFFFFFF - product + = digit of a - carry + 0xFFFFFFFF00000000 - product + = digit of a - carry - productlow + (ENC(nextcarry) << 32) */ + "psubq %%mm2, %%mm1 \n\t" + "paddq %%mm1, %%mm0 \n\t" + "movd %%mm0, (%0) \n\t" /* Store low 32 bits of result */ + "psrlq $32, %%mm0 \n\t" /* Next carry is 32 high bits of result */ + "addl $4, %0\n\t" + "addl $4, %1\n\t" + "subl $1, %2\n\t" + "jne 1b \n\t" + "movd %%mm0, %3 \n\t" + "emms" + : "+&r" (a), "+&r" (b), "+&r" (blen), "=&rm" (out) + : "m" (d), "m" (bias1), "m" (bias2)); + out = ~out; /* Undo encoding on out digit */ + } + if (alen == 0) return out; + /* current digit of a -= out */ + BngSub2(*a, carry, *a, out); + a++; + alen--; + /* Propagate carry */ + if (carry == 0 || alen == 0) return carry; + do { + if ((*a)-- != 0) return 0; + a++; + } while (--alen); + return 1; +} + +/* Detect whether SSE2 instructions are supported */ + +static int bng_ia32_sse2_supported(void) +{ + unsigned int flags, newflags, max_id, capabilities; + +#define EFLAG_CPUID 0x00200000 +#define CPUID_IDENTIFY 0 +#define CPUID_CAPABILITIES 1 +#define SSE2_CAPABILITY 26 + + /* Check if processor has CPUID instruction */ + asm("pushfl \n\t" + "popl %0" + : "=r" (flags) : ); + newflags = flags ^ EFLAG_CPUID; /* CPUID detection flag */ + asm("pushfl \n\t" + "pushl %1 \n\t" + "popfl \n\t" + "pushfl \n\t" + "popl %0 \n\t" + "popfl" + : "=r" (flags) : "r" (newflags)); + /* If CPUID detection flag cannot be changed, CPUID instruction is not + available */ + if ((flags & EFLAG_CPUID) != (newflags & EFLAG_CPUID)) return 0; + /* See if SSE2 extensions are supported */ + asm("pushl %%ebx \n\t" /* need to preserve %ebx for PIC */ + "cpuid \n\t" + "popl %%ebx" + : "=a" (max_id) : "a" (CPUID_IDENTIFY): "ecx", "edx"); + if (max_id < 1) return 0; + asm("pushl %%ebx \n\t" + "cpuid \n\t" + "popl %%ebx" + : "=d" (capabilities) : "a" (CPUID_CAPABILITIES) : "ecx"); + return capabilities & (1 << SSE2_CAPABILITY); +} + +#endif + +static void bng_ia32_setup_ops(void) +{ +#if BNG_ASM_LEVEL >= 2 + if (bng_ia32_sse2_supported()) { + bng_ops.add = bng_ia32sse2_add; + bng_ops.sub = bng_ia32sse2_sub; + bng_ops.mult_add_digit = bng_ia32sse2_mult_add_digit; + bng_ops.mult_sub_digit = bng_ia32sse2_mult_sub_digit; + return; + } +#endif + bng_ops.add = bng_ia32_add; + bng_ops.sub = bng_ia32_sub; + bng_ops.mult_add_digit = bng_ia32_mult_add_digit; + bng_ops.mult_sub_digit = bng_ia32_mult_sub_digit; +} + +#define BNG_SETUP_OPS bng_ia32_setup_ops() + diff --git a/otherlibs/num/bng_mips.c b/otherlibs/num/bng_mips.c new file mode 100644 index 0000000..b989581 --- /dev/null +++ b/otherlibs/num/bng_mips.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_mips.c,v 1.1 2003-10-24 09:17:33 xleroy Exp $ */ + +/* Code specific to the MIPS architecture. */ + +#define BngMult(resh,resl,arg1,arg2) \ + asm("multu %2, %3 \n\t" \ + "mflo %0 \n\t" \ + "mfhi %1" \ + : "=r" (resl), "=r" (resh) \ + : "r" (arg1), "r" (arg2)) + diff --git a/otherlibs/num/bng_ppc.c b/otherlibs/num/bng_ppc.c new file mode 100644 index 0000000..fb8ec7a --- /dev/null +++ b/otherlibs/num/bng_ppc.c @@ -0,0 +1,94 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_ppc.c,v 1.3 2006-05-31 08:16:34 xleroy Exp $ */ + +/* Code specific to the PowerPC architecture. */ + +#define BngAdd2(res,carryout,arg1,arg2) \ + asm("addc %0, %2, %3 \n\t" \ + "li %1, 0 \n\t" \ + "addze %1, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2)) + +#define BngAdd2Carry(res,carryout,arg1,arg2,carryin) \ + asm("addic %1, %4, -1 \n\t" \ + "adde %0, %2, %3 \n\t" \ + "li %1, 0 \n\t" \ + "addze %1, %1" \ + : "=r" (res), "=&r" (carryout) \ + : "r" (arg1), "r" (arg2), "1" (carryin)) + +#define BngAdd3(res,carryaccu,arg1,arg2,arg3) \ + asm("addc %0, %2, %3 \n\t" \ + "addze %1, %1 \n\t" \ + "addc %0, %0, %4 \n\t" \ + "addze %1, %1" \ + : "=&r" (res), "=&r" (carryaccu) \ + : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu)) + +/* The "subtract" instructions interpret carry differently than what we + need: the processor carry bit CA is 1 if no carry occured, + 0 if a carry occured. In other terms, CA = !carry. + Thus, subfe rd,ra,rb computes rd = ra - rb - !CA + subfe rd,rd,rd sets rd = - !CA + subfe rd,rd,rd; neg rd, rd sets rd = !CA and recovers "our" carry. */ + +#define BngSub2(res,carryout,arg1,arg2) \ + asm("subfc %0, %3, %2 \n\t" \ + "subfe %1, %1, %1\n\t" \ + "neg %1, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2)) + +#define BngSub2Carry(res,carryout,arg1,arg2,carryin) \ + asm("subfic %1, %4, 0 \n\t" \ + "subfe %0, %3, %2 \n\t" \ + "subfe %1, %1, %1 \n\t" \ + "neg %1, %1" \ + : "=r" (res), "=&r" (carryout) \ + : "r" (arg1), "r" (arg2), "1" (carryin)) + +/* Here is what happens with carryaccu: + neg %1, %1 carryaccu = -carryaccu + addze %1, %1 carryaccu += !carry1 + addze %1, %1 carryaccu += !carry2 + subifc %1, %1, 2 carryaccu = 2 - carryaccu + Thus, carryaccu_final = carryaccu_initial + 2 - (1 - carry1) - (1 - carry2) + = carryaccu_initial + carry1 + carry2 +*/ + +#define BngSub3(res,carryaccu,arg1,arg2,arg3) \ + asm("neg %1, %1 \n\t" \ + "subfc %0, %3, %2 \n\t" \ + "addze %1, %1 \n\t" \ + "subfc %0, %4, %0 \n\t" \ + "addze %1, %1 \n\t" \ + "subfic %1, %1, 2 \n\t" \ + : "=&r" (res), "=&r" (carryaccu) \ + : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu)) + +#ifdef __ppc64__ +#define BngMult(resh,resl,arg1,arg2) \ + asm("mulld %0, %2, %3 \n\t" \ + "mulhdu %1, %2, %3" \ + : "=&r" (resl), "=r" (resh) \ + : "r" (arg1), "r" (arg2)) +#else +#define BngMult(resh,resl,arg1,arg2) \ + asm("mullw %0, %2, %3 \n\t" \ + "mulhwu %1, %2, %3" \ + : "=&r" (resl), "=r" (resh) \ + : "r" (arg1), "r" (arg2)) +#endif \ No newline at end of file diff --git a/otherlibs/num/bng_sparc.c b/otherlibs/num/bng_sparc.c new file mode 100644 index 0000000..791c76e --- /dev/null +++ b/otherlibs/num/bng_sparc.c @@ -0,0 +1,77 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bng_sparc.c,v 1.1 2003-10-24 09:17:34 xleroy Exp $ */ + +/* Code specific to the SPARC (V8 and above) architecture. */ + +#define BngAdd2(res,carryout,arg1,arg2) \ + asm("addcc %2, %3, %0 \n\t" \ + "addx %%g0, 0, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2) \ + : "cc") + +#define BngAdd2Carry(res,carryout,arg1,arg2,carryin) \ + asm("subcc %%g0, %4, %%g0 \n\t" \ + "addxcc %2, %3, %0 \n\t" \ + "addx %%g0, 0, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2), "r" (carryin) \ + : "cc") + +#define BngAdd3(res,carryaccu,arg1,arg2,arg3) \ + asm("addcc %2, %3, %0 \n\t" \ + "addx %1, 0, %1 \n\t" \ + "addcc %0, %4, %0 \n\t" \ + "addx %1, 0, %1" \ + : "=r" (res), "=r" (carryaccu) \ + : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu) \ + : "cc") + +#define BngSub2(res,carryout,arg1,arg2) \ + asm("subcc %2, %3, %0 \n\t" \ + "addx %%g0, 0, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2) \ + : "cc") + +#define BngSub2Carry(res,carryout,arg1,arg2,carryin) \ + asm("subcc %%g0, %4, %%g0 \n\t" \ + "subxcc %2, %3, %0 \n\t" \ + "addx %%g0, 0, %1" \ + : "=r" (res), "=r" (carryout) \ + : "r" (arg1), "r" (arg2), "r" (carryin) \ + : "cc") + +#define BngSub3(res,carryaccu,arg1,arg2,arg3) \ + asm("subcc %2, %3, %0 \n\t" \ + "addx %1, 0, %1 \n\t" \ + "subcc %0, %4, %0 \n\t" \ + "addx %1, 0, %1" \ + : "=r" (res), "=r" (carryaccu) \ + : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu) \ + : "cc") + +#define BngMult(resh,resl,arg1,arg2) \ + asm("umul %2, %3, %0 \n\t" \ + "rd %%y, %1" \ + : "=r" (resl), "=r" (resh) \ + : "r" (arg1), "r" (arg2)) + +#define BngDiv(quo,rem,nh,nl,d) \ + asm("wr %1, %%y \n\t" \ + "udiv %2, %3, %0" \ + : "=r" (quo) \ + : "r" (nh), "r" (nl), "r" (d)); \ + rem = nl - d * quo diff --git a/otherlibs/num/dllnums.dlib b/otherlibs/num/dllnums.dlib new file mode 100644 index 0000000..e54aa8e --- /dev/null +++ b/otherlibs/num/dllnums.dlib @@ -0,0 +1 @@ +bng.d.o nat_stubs.d.o diff --git a/otherlibs/num/int_misc.ml b/otherlibs/num/int_misc.ml new file mode 100644 index 0000000..a259251 --- /dev/null +++ b/otherlibs/num/int_misc.ml @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int_misc.ml,v 1.6 2002-05-27 12:06:49 weis Exp $ *) + +(* Some extra operations on integers *) + +let rec gcd_int i1 i2 = + if i2 = 0 then abs i1 else gcd_int i2 (i1 mod i2) +;; + +let rec num_bits_int_aux n = + if n = 0 then 0 else succ(num_bits_int_aux (n lsr 1));; + +let num_bits_int n = num_bits_int_aux (abs n);; + +let sign_int i = if i = 0 then 0 else if i > 0 then 1 else -1;; + +let length_of_int = Sys.word_size - 2;; + +let monster_int = 1 lsl length_of_int;; +let biggest_int = monster_int - 1;; +let least_int = - biggest_int;; + +let compare_int n1 n2 = + if n1 == n2 then 0 else if n1 > n2 then 1 else -1;; diff --git a/otherlibs/num/int_misc.mli b/otherlibs/num/int_misc.mli new file mode 100644 index 0000000..02f3b38 --- /dev/null +++ b/otherlibs/num/int_misc.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int_misc.mli,v 1.4 2001-12-07 13:40:15 xleroy Exp $ *) + +(* Some extra operations on integers *) + +val gcd_int: int -> int -> int +val num_bits_int: int -> int +val compare_int: int -> int -> int +val sign_int: int -> int +val length_of_int: int +val biggest_int: int +val least_int: int +val monster_int: int diff --git a/otherlibs/num/libnums.clib b/otherlibs/num/libnums.clib new file mode 100644 index 0000000..47c751f --- /dev/null +++ b/otherlibs/num/libnums.clib @@ -0,0 +1 @@ +bng.o nat_stubs.o diff --git a/otherlibs/num/nat.h b/otherlibs/num/nat.h new file mode 100644 index 0000000..a67dfee --- /dev/null +++ b/otherlibs/num/nat.h @@ -0,0 +1,19 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1999 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: nat.h,v 1.6 2003-10-24 09:17:34 xleroy Exp $ */ + +/* Nats are represented as unstructured blocks with tag Custom_tag. */ + +#define Digit_val(nat,pos) (((bng) Data_custom_val(nat))[pos]) + diff --git a/otherlibs/num/nat.ml b/otherlibs/num/nat.ml new file mode 100644 index 0000000..1cbbbc2 --- /dev/null +++ b/otherlibs/num/nat.ml @@ -0,0 +1,572 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: nat.ml,v 1.16 2008-01-04 13:15:52 xleroy Exp $ *) + +open Int_misc + +type nat;; + +external create_nat: int -> nat = "create_nat" +external set_to_zero_nat: nat -> int -> int -> unit = "set_to_zero_nat" +external blit_nat: nat -> int -> nat -> int -> int -> unit = "blit_nat" +external set_digit_nat: nat -> int -> int -> unit = "set_digit_nat" +external nth_digit_nat: nat -> int -> int = "nth_digit_nat" +external set_digit_nat_native: nat -> int -> nativeint -> unit = "set_digit_nat_native" +external nth_digit_nat_native: nat -> int -> nativeint = "nth_digit_nat_native" +external num_digits_nat: nat -> int -> int -> int = "num_digits_nat" +external num_leading_zero_bits_in_digit: nat -> int -> int = "num_leading_zero_bits_in_digit" +external is_digit_int: nat -> int -> bool = "is_digit_int" +external is_digit_zero: nat -> int -> bool = "is_digit_zero" +external is_digit_normalized: nat -> int -> bool = "is_digit_normalized" +external is_digit_odd: nat -> int -> bool = "is_digit_odd" +external incr_nat: nat -> int -> int -> int -> int = "incr_nat" +external add_nat: nat -> int -> int -> nat -> int -> int -> int -> int = "add_nat" "add_nat_native" +external complement_nat: nat -> int -> int -> unit = "complement_nat" +external decr_nat: nat -> int -> int -> int -> int = "decr_nat" +external sub_nat: nat -> int -> int -> nat -> int -> int -> int -> int = "sub_nat" "sub_nat_native" +external mult_digit_nat: nat -> int -> int -> nat -> int -> int -> nat -> int -> int = "mult_digit_nat" "mult_digit_nat_native" +external mult_nat: nat -> int -> int -> nat -> int -> int -> nat -> int -> int -> int = "mult_nat" "mult_nat_native" +external square_nat: nat -> int -> int -> nat -> int -> int -> int = "square_nat" "square_nat_native" +external shift_left_nat: nat -> int -> int -> nat -> int -> int -> unit = "shift_left_nat" "shift_left_nat_native" +external div_digit_nat: nat -> int -> nat -> int -> nat -> int -> int -> nat -> int -> unit = "div_digit_nat" "div_digit_nat_native" +external div_nat: nat -> int -> int -> nat -> int -> int -> unit = "div_nat" "div_nat_native" +external shift_right_nat: nat -> int -> int -> nat -> int -> int -> unit = "shift_right_nat" "shift_right_nat_native" +external compare_digits_nat: nat -> int -> nat -> int -> int = "compare_digits_nat" +external compare_nat: nat -> int -> int -> nat -> int -> int -> int = "compare_nat" "compare_nat_native" +external land_digit_nat: nat -> int -> nat -> int -> unit = "land_digit_nat" +external lor_digit_nat: nat -> int -> nat -> int -> unit = "lor_digit_nat" +external lxor_digit_nat: nat -> int -> nat -> int -> unit = "lxor_digit_nat" + +external initialize_nat: unit -> unit = "initialize_nat" +let _ = initialize_nat() + +let length_nat (n : nat) = Obj.size (Obj.repr n) - 1 + +let length_of_digit = Sys.word_size;; + +let make_nat len = + if len < 0 then invalid_arg "make_nat" else + let res = create_nat len in set_to_zero_nat res 0 len; res + +(* Nat temporaries *) +let a_2 = make_nat 2 +and a_1 = make_nat 1 +and b_2 = make_nat 2 + +let copy_nat nat off_set length = + let res = create_nat (length) in + blit_nat res 0 nat off_set length; + res + +let is_zero_nat n off len = + compare_nat (make_nat 1) 0 1 n off (num_digits_nat n off len) = 0 + +let is_nat_int nat off len = + num_digits_nat nat off len = 1 && is_digit_int nat off + +let sys_int_of_nat nat off len = + if is_nat_int nat off len + then nth_digit_nat nat off + else failwith "int_of_nat" + +let int_of_nat nat = + sys_int_of_nat nat 0 (length_nat nat) + +let nat_of_int i = + if i < 0 then invalid_arg "nat_of_int" else + let res = make_nat 1 in + if i = 0 then res else begin set_digit_nat res 0 i; res end + +let eq_nat nat1 off1 len1 nat2 off2 len2 = + compare_nat nat1 off1 (num_digits_nat nat1 off1 len1) + nat2 off2 (num_digits_nat nat2 off2 len2) = 0 +and le_nat nat1 off1 len1 nat2 off2 len2 = + compare_nat nat1 off1 (num_digits_nat nat1 off1 len1) + nat2 off2 (num_digits_nat nat2 off2 len2) <= 0 +and lt_nat nat1 off1 len1 nat2 off2 len2 = + compare_nat nat1 off1 (num_digits_nat nat1 off1 len1) + nat2 off2 (num_digits_nat nat2 off2 len2) < 0 +and ge_nat nat1 off1 len1 nat2 off2 len2 = + compare_nat nat1 off1 (num_digits_nat nat1 off1 len1) + nat2 off2 (num_digits_nat nat2 off2 len2) >= 0 +and gt_nat nat1 off1 len1 nat2 off2 len2 = + compare_nat nat1 off1 (num_digits_nat nat1 off1 len1) + nat2 off2 (num_digits_nat nat2 off2 len2) > 0 + +(* XL: now implemented in C for better performance. + The code below doesn't handle carries correctly. + Fortunately, the carry is never used. *) +(*** +let square_nat nat1 off1 len1 nat2 off2 len2 = + let c = ref 0 + and trash = make_nat 1 in + (* Double product *) + for i = 0 to len2 - 2 do + c := !c + mult_digit_nat + nat1 + (succ (off1 + 2 * i)) + (2 * (pred (len2 - i))) + nat2 + (succ (off2 + i)) + (pred (len2 - i)) + nat2 + (off2 + i) + done; + shift_left_nat nat1 0 len1 trash 0 1; + (* Square of digit *) + for i = 0 to len2 - 1 do + c := !c + mult_digit_nat + nat1 + (off1 + 2 * i) + (len1 - 2 * i) + nat2 + (off2 + i) + 1 + nat2 + (off2 + i) + done; + !c +***) + +let gcd_int_nat i nat off len = + if i = 0 then 1 else + if is_nat_int nat off len then begin + set_digit_nat nat off (gcd_int (nth_digit_nat nat off) i); 0 + end else begin + let len_copy = succ len in + let copy = create_nat len_copy + and quotient = create_nat 1 + and remainder = create_nat 1 in + blit_nat copy 0 nat off len; + set_digit_nat copy len 0; + div_digit_nat quotient 0 remainder 0 copy 0 len_copy (nat_of_int i) 0; + set_digit_nat nat off (gcd_int (nth_digit_nat remainder 0) i); + 0 + end + +let exchange r1 r2 = + let old1 = !r1 in r1 := !r2; r2 := old1 + +let gcd_nat nat1 off1 len1 nat2 off2 len2 = + if is_zero_nat nat1 off1 len1 then begin + blit_nat nat1 off1 nat2 off2 len2; len2 + end else begin + let copy1 = ref (create_nat (succ len1)) + and copy2 = ref (create_nat (succ len2)) in + blit_nat !copy1 0 nat1 off1 len1; + blit_nat !copy2 0 nat2 off2 len2; + set_digit_nat !copy1 len1 0; + set_digit_nat !copy2 len2 0; + if lt_nat !copy1 0 len1 !copy2 0 len2 + then exchange copy1 copy2; + let real_len1 = + ref (num_digits_nat !copy1 0 (length_nat !copy1)) + and real_len2 = + ref (num_digits_nat !copy2 0 (length_nat !copy2)) in + while not (is_zero_nat !copy2 0 !real_len2) do + set_digit_nat !copy1 !real_len1 0; + div_nat !copy1 0 (succ !real_len1) !copy2 0 !real_len2; + exchange copy1 copy2; + real_len1 := !real_len2; + real_len2 := num_digits_nat !copy2 0 !real_len2 + done; + blit_nat nat1 off1 !copy1 0 !real_len1; + !real_len1 + end + +(* Racine carrée entière par la méthode de Newton (entière par défaut). *) + +(* Théorème: la suite xn+1 = (xn + a/xn) / 2 converge vers la racine *) +(* carrée entière de a par défaut, si on part d'une valeur x0 *) +(* strictement plus grande que la racine de a, sauf quand a est un *) +(* carré - 1, cas auquel la suite alterne entre la racine par défaut *) +(* et par excès. Dans tous les cas, le dernier terme de la partie *) +(* strictement décroissante de la suite est le résultat cherché. *) + +let sqrt_nat rad off len = + let len = num_digits_nat rad off len in + (* Copie de travail du radicande *) + let len_parity = len mod 2 in + let rad_len = len + 1 + len_parity in + let rad = + let res = create_nat rad_len in + blit_nat res 0 rad off len; + set_digit_nat res len 0; + set_digit_nat res (rad_len - 1) 0; + res in + let cand_len = (len + 1) / 2 in (* ceiling len / 2 *) + let cand_rest = rad_len - cand_len in + (* Racine carrée supposée cand = "|FFFF .... |" *) + let cand = make_nat cand_len in + (* Amélioration de la racine de départ: + on calcule nbb le nombre de bits significatifs du premier digit du candidat + (la moitié du nombre de bits significatifs dans les deux premiers + digits du radicande étendu à une longueur paire). + shift_cand est word_size - nbb *) + let shift_cand = + ((num_leading_zero_bits_in_digit rad (len-1)) + + Sys.word_size * len_parity) / 2 in + (* Tous les bits du radicande sont à 0, on rend 0. *) + if shift_cand = Sys.word_size then cand else + begin + complement_nat cand 0 cand_len; + shift_right_nat cand 0 1 a_1 0 shift_cand; + let next_cand = create_nat rad_len in + (* Repeat until *) + let rec loop () = + (* next_cand := rad *) + blit_nat next_cand 0 rad 0 rad_len; + (* next_cand <- next_cand / cand *) + div_nat next_cand 0 rad_len cand 0 cand_len; + (* next_cand (poids fort) <- next_cand (poids fort) + cand, + i.e. next_cand <- cand + rad / cand *) + ignore (add_nat next_cand cand_len cand_rest cand 0 cand_len 0); + (* next_cand <- next_cand / 2 *) + shift_right_nat next_cand cand_len cand_rest a_1 0 1; + if lt_nat next_cand cand_len cand_rest cand 0 cand_len then + begin (* cand <- next_cand *) + blit_nat cand 0 next_cand cand_len cand_len; loop () + end + else cand in + loop () + end;; + +let power_base_max = make_nat 2;; + +match length_of_digit with + | 64 -> + set_digit_nat power_base_max 0 (Int64.to_int 1000000000000000000L); + ignore + (mult_digit_nat power_base_max 0 2 + power_base_max 0 1 (nat_of_int 9) 0) + | 32 -> set_digit_nat power_base_max 0 1000000000 + | _ -> assert false +;; + +let pmax = + match length_of_digit with + | 64 -> 19 + | 32 -> 9 + | _ -> assert false +;; + +let max_superscript_10_power_in_int = + match length_of_digit with + | 64 -> 18 + | 32 -> 9 + | _ -> assert false +;; +let max_power_10_power_in_int = + match length_of_digit with + | 64 -> nat_of_int (Int64.to_int 1000000000000000000L) + | 32 -> nat_of_int 1000000000 + | _ -> assert false +;; + +let raw_string_of_digit nat off = + if is_nat_int nat off 1 + then begin string_of_int (nth_digit_nat nat off) end + else begin + blit_nat b_2 0 nat off 1; + div_digit_nat a_2 0 a_1 0 b_2 0 2 max_power_10_power_in_int 0; + let leading_digits = nth_digit_nat a_2 0 + and s1 = string_of_int (nth_digit_nat a_1 0) in + let len = String.length s1 in + if leading_digits < 10 then begin + let result = String.make (max_superscript_10_power_in_int+1) '0' in + String.set result 0 + (Char.chr (48 + leading_digits)); + String.blit s1 0 + result (String.length result - len) len; + result + end else begin + let result = String.make (max_superscript_10_power_in_int+2) '0' in + String.blit (string_of_int leading_digits) 0 result 0 2; + String.blit s1 0 + result (String.length result - len) len; + result + end + end + +(* XL: suppression de string_of_digit et de sys_string_of_digit. + La copie est de toute facon faite dans string_of_nat, qui est le + seul point d entree public dans ce code. *) + +(****** +let sys_string_of_digit nat off = + let s = raw_string_of_digit nat off in + let result = String.create (String.length s) in + String.blit s 0 result 0 (String.length s); + s + +let string_of_digit nat = + sys_string_of_digit nat 0 + +*******) + +let digits = "0123456789ABCDEF" + +(* + make_power_base affecte power_base des puissances successives de base a + partir de la puissance 1-ieme. + A la fin de la boucle i-1 est la plus grande puissance de la base qui tient + sur un seul digit et j est la plus grande puissance de la base qui tient + sur un int. +*) +let make_power_base base power_base = + let i = ref 0 + and j = ref 0 in + set_digit_nat power_base 0 base; + while incr i; is_digit_zero power_base !i do + ignore + (mult_digit_nat power_base !i 2 + power_base (pred !i) 1 + power_base 0) + done; + while !j <= !i && is_digit_int power_base !j do incr j done; + (!i - 2, !j) + +(* + int_to_string place la representation de l entier int en base base + dans la chaine s en le rangeant de la fin indiquee par pos vers le + debut, sur times places et affecte a pos sa nouvelle valeur. +*) +let int_to_string int s pos_ref base times = + let i = ref int + and j = ref times in + while ((!i != 0) || (!j != 0)) && (!pos_ref != -1) do + String.set s !pos_ref (String.get digits (!i mod base)); + decr pos_ref; + decr j; + i := !i / base + done + +(* XL: suppression de adjust_string *) + +let power_base_int base i = + if i = 0 then + nat_of_int 1 + else if i < 0 then + invalid_arg "power_base_int" + else begin + let power_base = make_nat (succ length_of_digit) in + let (pmax, pint) = make_power_base base power_base in + let n = i / (succ pmax) + and rem = i mod (succ pmax) in + if n > 0 then begin + let newn = + if i = biggest_int then n else (succ n) in + let res = make_nat newn + and res2 = make_nat newn + and l = num_bits_int n - 2 in + let p = ref (1 lsl l) in + blit_nat res 0 power_base pmax 1; + for i = l downto 0 do + let len = num_digits_nat res 0 newn in + let len2 = min n (2 * len) in + let succ_len2 = succ len2 in + ignore (square_nat res2 0 len2 res 0 len); + if n land !p > 0 then begin + set_to_zero_nat res 0 len; + ignore + (mult_digit_nat res 0 succ_len2 + res2 0 len2 power_base pmax) + end else + blit_nat res 0 res2 0 len2; + set_to_zero_nat res2 0 len2; + p := !p lsr 1 + done; + if rem > 0 then begin + ignore + (mult_digit_nat res2 0 newn + res 0 n power_base (pred rem)); + res2 + end else res + end else + copy_nat power_base (pred rem) 1 + end + +(* the ith element (i >= 2) of num_digits_max_vector is : + | | + | biggest_string_length * log (i) | + | ------------------------------- | + 1 + | length_of_digit * log (2) | + -- -- +*) + +(* XL: ai specialise le code d origine a length_of_digit = 32. *) +(* Puis suppression (inutile?) *) + +(****** +let num_digits_max_vector = + [|0; 0; 1024; 1623; 2048; 2378; 2647; 2875; 3072; 3246; 3402; + 3543; 3671; 3789; 3899; 4001; 4096|] + +let num_digits_max_vector = + match length_of_digit with + 16 -> [|0; 0; 2048; 3246; 4096; 4755; 5294; 5749; 6144; 6492; 6803; + 7085; 7342; 7578; 7797; 8001; 8192|] +(* If really exotic machines !!!! + | 17 -> [|0; 0; 1928; 3055; 3855; 4476; 4983; 5411; 5783; 6110; 6403; + 6668; 6910; 7133; 7339; 7530; 7710|] + | 18 -> [|0; 0; 1821; 2886; 3641; 4227; 4706; 5111; 5461; 5771; 6047; + 6298; 6526; 6736; 6931; 7112; 7282|] + | 19 -> [|0; 0; 1725; 2734; 3449; 4005; 4458; 4842; 5174; 5467; 5729; + 5966; 6183; 6382; 6566; 6738; 6898|] + | 20 -> [|0; 0; 1639; 2597; 3277; 3804; 4235; 4600; 4915; 5194; 5443; + 5668; 5874; 6063; 6238; 6401; 6553|] + | 21 -> [|0; 0; 1561; 2473; 3121; 3623; 4034; 4381; 4681; 4946; 5183; + 5398; 5594; 5774; 5941; 6096; 6241|] + | 22 -> [|0; 0; 1490; 2361; 2979; 3459; 3850; 4182; 4468; 4722; 4948; + 5153; 5340; 5512; 5671; 5819; 5958|] + | 23 -> [|0; 0; 1425; 2258; 2850; 3308; 3683; 4000; 4274; 4516; 4733; + 4929; 5108; 5272; 5424; 5566; 5699|] + | 24 -> [|0; 0; 1366; 2164; 2731; 3170; 3530; 3833; 4096; 4328; 4536; + 4723; 4895; 5052; 5198; 5334; 5461|] + | 25 -> [|0; 0; 1311; 2078; 2622; 3044; 3388; 3680; 3932; 4155; 4354; + 4534; 4699; 4850; 4990; 5121; 5243|] + | 26 -> [|0; 0; 1261; 1998; 2521; 2927; 3258; 3538; 3781; 3995; 4187; + 4360; 4518; 4664; 4798; 4924; 5041|] + | 27 -> [|0; 0; 1214; 1924; 2428; 2818; 3137; 3407; 3641; 3847; 4032; + 4199; 4351; 4491; 4621; 4742; 4855|] + | 28 -> [|0; 0; 1171; 1855; 2341; 2718; 3025; 3286; 3511; 3710; 3888; + 4049; 4196; 4331; 4456; 4572; 4681|] + | 29 -> [|0; 0; 1130; 1791; 2260; 2624; 2921; 3172; 3390; 3582; 3754; + 3909; 4051; 4181; 4302; 4415; 4520|] + | 30 -> [|0; 0; 1093; 1732; 2185; 2536; 2824; 3067; 3277; 3463; 3629; + 3779; 3916; 4042; 4159; 4267; 4369|] + | 31 -> [|0; 0; 1057; 1676; 2114; 2455; 2733; 2968; 3171; 3351; 3512; + 3657; 3790; 3912; 4025; 4130; 4228|] +*) + | 32 -> [|0; 0; 1024; 1623; 2048; 2378; 2647; 2875; 3072; 3246; 3402; + 3543; 3671; 3789; 3899; 4001; 4096|] + | n -> failwith "num_digits_max_vector" +******) + +(* XL: suppression de string_list_of_nat *) + +let unadjusted_string_of_nat nat off len_nat = + let len = num_digits_nat nat off len_nat in + if len = 1 then + raw_string_of_digit nat off + else + let len_copy = ref (succ len) in + let copy1 = create_nat !len_copy + and copy2 = make_nat !len_copy + and rest_digit = make_nat 2 in + if len > biggest_int / (succ pmax) + then failwith "number too long" + else let len_s = (succ pmax) * len in + let s = String.make len_s '0' + and pos_ref = ref len_s in + len_copy := pred !len_copy; + blit_nat copy1 0 nat off len; + set_digit_nat copy1 len 0; + while not (is_zero_nat copy1 0 !len_copy) do + div_digit_nat copy2 0 + rest_digit 0 + copy1 0 (succ !len_copy) + power_base_max 0; + let str = raw_string_of_digit rest_digit 0 in + String.blit str 0 + s (!pos_ref - String.length str) + (String.length str); + (* XL: il y avait pmax a la place de String.length str + mais ca ne marche pas avec le blit de Caml Light, + qui ne verifie pas les debordements *) + pos_ref := !pos_ref - pmax; + len_copy := num_digits_nat copy2 0 !len_copy; + blit_nat copy1 0 copy2 0 !len_copy; + set_digit_nat copy1 !len_copy 0 + done; + s + +let string_of_nat nat = + let s = unadjusted_string_of_nat nat 0 (length_nat nat) + and index = ref 0 in + begin try + for i = 0 to String.length s - 2 do + if String.get s i <> '0' then (index:= i; raise Exit) + done + with Exit -> () + end; + String.sub s !index (String.length s - !index) + +(* XL: suppression de sys_string_of_nat *) + +(* XL: suppression de debug_string_nat *) + +let base_digit_of_char c base = + let n = Char.code c in + if n >= 48 && n <= 47 + min base 10 then n - 48 + else if n >= 65 && n <= 65 + base - 11 then n - 55 + else failwith "invalid digit" + +(* + La sous-chaine (s, off, len) represente un nat en base base que + on determine ici +*) +let sys_nat_of_string base s off len = + let power_base = make_nat (succ length_of_digit) in + let (pmax, pint) = make_power_base base power_base in + let new_len = ref (1 + len / (pmax + 1)) + and current_len = ref 1 in + let possible_len = ref (min 2 !new_len) in + + let nat1 = make_nat !new_len + and nat2 = make_nat !new_len + + and digits_read = ref 0 + and bound = off + len - 1 + and int = ref 0 in + + for i = off to bound do + (* + on lit pint (au maximum) chiffres, on en fait un int + et on l integre au nombre + *) + let c = String.get s i in + begin match c with + ' ' | '\t' | '\n' | '\r' | '\\' -> () + | _ -> int := !int * base + base_digit_of_char c base; + incr digits_read + end; + if (!digits_read = pint || i = bound) && not (!digits_read = 0) then + begin + set_digit_nat nat1 0 !int; + let erase_len = if !new_len = !current_len then !current_len - 1 + else !current_len in + for j = 1 to erase_len do + set_digit_nat nat1 j 0 + done; + ignore + (mult_digit_nat nat1 0 !possible_len + nat2 0 !current_len power_base (pred !digits_read)); + blit_nat nat2 0 nat1 0 !possible_len; + current_len := num_digits_nat nat1 0 !possible_len; + possible_len := min !new_len (succ !current_len); + int := 0; + digits_read := 0 + end + done; + (* + On recadre le nat + *) + let nat = create_nat !current_len in + blit_nat nat 0 nat1 0 !current_len; + nat + +let nat_of_string s = sys_nat_of_string 10 s 0 (String.length s) + +let float_of_nat nat = float_of_string(string_of_nat nat) diff --git a/otherlibs/num/nat.mli b/otherlibs/num/nat.mli new file mode 100644 index 0000000..a792239 --- /dev/null +++ b/otherlibs/num/nat.mli @@ -0,0 +1,73 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: nat.mli,v 1.12 2008-01-04 13:15:52 xleroy Exp $ *) + +(* Module [Nat]: operations on natural numbers *) + +type nat + +(* Natural numbers (type [nat]) are positive integers of arbitrary size. + All operations on [nat] are performed in-place. *) + +external create_nat: int -> nat = "create_nat" +val make_nat: int -> nat +external set_to_zero_nat: nat -> int -> int -> unit = "set_to_zero_nat" +external blit_nat: nat -> int -> nat -> int -> int -> unit = "blit_nat" +val copy_nat: nat -> int -> int -> nat +external set_digit_nat: nat -> int -> int -> unit = "set_digit_nat" +external nth_digit_nat: nat -> int -> int = "nth_digit_nat" +external set_digit_nat_native: nat -> int -> nativeint -> unit = "set_digit_nat_native" +external nth_digit_nat_native: nat -> int -> nativeint = "nth_digit_nat_native" +val length_nat : nat -> int +external num_digits_nat: nat -> int -> int -> int = "num_digits_nat" +external num_leading_zero_bits_in_digit: nat -> int -> int = "num_leading_zero_bits_in_digit" +external is_digit_int: nat -> int -> bool = "is_digit_int" +external is_digit_zero: nat -> int -> bool = "is_digit_zero" +external is_digit_normalized: nat -> int -> bool = "is_digit_normalized" +external is_digit_odd: nat -> int -> bool = "is_digit_odd" +val is_zero_nat: nat -> int -> int -> bool +val is_nat_int: nat -> int -> int -> bool +val int_of_nat: nat -> int +val nat_of_int: int -> nat +external incr_nat: nat -> int -> int -> int -> int = "incr_nat" +external add_nat: nat -> int -> int -> nat -> int -> int -> int -> int = "add_nat" "add_nat_native" +external complement_nat: nat -> int -> int -> unit = "complement_nat" +external decr_nat: nat -> int -> int -> int -> int = "decr_nat" +external sub_nat: nat -> int -> int -> nat -> int -> int -> int -> int = "sub_nat" "sub_nat_native" +external mult_digit_nat: nat -> int -> int -> nat -> int -> int -> nat -> int -> int = "mult_digit_nat" "mult_digit_nat_native" +external mult_nat: nat -> int -> int -> nat -> int -> int -> nat -> int -> int -> int = "mult_nat" "mult_nat_native" +external square_nat: nat -> int -> int -> nat -> int -> int -> int = "square_nat" "square_nat_native" +external shift_left_nat: nat -> int -> int -> nat -> int -> int -> unit = "shift_left_nat" "shift_left_nat_native" +external div_digit_nat: nat -> int -> nat -> int -> nat -> int -> int -> nat -> int -> unit = "div_digit_nat" "div_digit_nat_native" +external div_nat: nat -> int -> int -> nat -> int -> int -> unit = "div_nat" "div_nat_native" +external shift_right_nat: nat -> int -> int -> nat -> int -> int -> unit = "shift_right_nat" "shift_right_nat_native" +external compare_digits_nat: nat -> int -> nat -> int -> int = "compare_digits_nat" +external compare_nat: nat -> int -> int -> nat -> int -> int -> int = "compare_nat" "compare_nat_native" +val eq_nat : nat -> int -> int -> nat -> int -> int -> bool +val le_nat : nat -> int -> int -> nat -> int -> int -> bool +val lt_nat : nat -> int -> int -> nat -> int -> int -> bool +val ge_nat : nat -> int -> int -> nat -> int -> int -> bool +val gt_nat : nat -> int -> int -> nat -> int -> int -> bool +external land_digit_nat: nat -> int -> nat -> int -> unit = "land_digit_nat" +external lor_digit_nat: nat -> int -> nat -> int -> unit = "lor_digit_nat" +external lxor_digit_nat: nat -> int -> nat -> int -> unit = "lxor_digit_nat" +val gcd_nat : nat -> int -> int -> nat -> int -> int -> int +val sqrt_nat : nat -> int -> int -> nat +val string_of_nat : nat -> string +val nat_of_string : string -> nat +val sys_nat_of_string : int -> string -> int -> int -> nat +val float_of_nat : nat -> float +val make_power_base : int -> nat -> int * int +val power_base_int : int -> int -> nat +val length_of_digit: int diff --git a/otherlibs/num/nat_stubs.c b/otherlibs/num/nat_stubs.c new file mode 100644 index 0000000..b9447aa --- /dev/null +++ b/otherlibs/num/nat_stubs.c @@ -0,0 +1,381 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: nat_stubs.c,v 1.18 2008-01-11 16:13:16 doligez Exp $ */ + +#include "alloc.h" +#include "config.h" +#include "custom.h" +#include "intext.h" +#include "fail.h" +#include "memory.h" +#include "mlvalues.h" + +#include "bng.h" +#include "nat.h" + +/* Stub code for the Nat module. */ + +static void serialize_nat(value, uintnat *, uintnat *); +static uintnat deserialize_nat(void * dst); + +static struct custom_operations nat_operations = { + "_nat", + custom_finalize_default, + custom_compare_default, + custom_hash_default, + serialize_nat, + deserialize_nat +}; + +CAMLprim value initialize_nat(value unit) +{ + bng_init(); + register_custom_operations(&nat_operations); + return Val_unit; +} + +CAMLprim value create_nat(value size) +{ + mlsize_t sz = Long_val(size); + + return alloc_custom(&nat_operations, sz * sizeof(value), 0, 1); +} + +CAMLprim value length_nat(value nat) +{ + return Val_long(Wosize_val(nat) - 1); +} + +CAMLprim value set_to_zero_nat(value nat, value ofs, value len) +{ + bng_zero(&Digit_val(nat, Long_val(ofs)), Long_val(len)); + return Val_unit; +} + +CAMLprim value blit_nat(value nat1, value ofs1, + value nat2, value ofs2, + value len) +{ + bng_assign(&Digit_val(nat1, Long_val(ofs1)), + &Digit_val(nat2, Long_val(ofs2)), + Long_val(len)); + return Val_unit; +} + +CAMLprim value set_digit_nat(value nat, value ofs, value digit) +{ + Digit_val(nat, Long_val(ofs)) = Long_val(digit); + return Val_unit; +} + +CAMLprim value nth_digit_nat(value nat, value ofs) +{ + return Val_long(Digit_val(nat, Long_val(ofs))); +} + +CAMLprim value set_digit_nat_native(value nat, value ofs, value digit) +{ + Digit_val(nat, Long_val(ofs)) = Nativeint_val(digit); + return Val_unit; +} + +CAMLprim value nth_digit_nat_native(value nat, value ofs) +{ + return caml_copy_nativeint(Digit_val(nat, Long_val(ofs))); +} + +CAMLprim value num_digits_nat(value nat, value ofs, value len) +{ + return Val_long(bng_num_digits(&Digit_val(nat, Long_val(ofs)), + Long_val(len))); +} + +CAMLprim value num_leading_zero_bits_in_digit(value nat, value ofs) +{ + return + Val_long(bng_leading_zero_bits(Digit_val(nat, Long_val(ofs)))); +} + +CAMLprim value is_digit_int(value nat, value ofs) +{ + return Val_bool(Digit_val(nat, Long_val(ofs)) <= Max_long); +} + +CAMLprim value is_digit_zero(value nat, value ofs) +{ + return Val_bool(Digit_val(nat, Long_val(ofs)) == 0); +} + +CAMLprim value is_digit_normalized(value nat, value ofs) +{ + return + Val_bool(Digit_val(nat, Long_val(ofs)) & ((bngdigit)1 << (BNG_BITS_PER_DIGIT-1))); +} + +CAMLprim value is_digit_odd(value nat, value ofs) +{ + return Val_bool(Digit_val(nat, Long_val(ofs)) & 1); +} + +CAMLprim value incr_nat(value nat, value ofs, value len, value carry_in) +{ + return Val_long(bng_add_carry(&Digit_val(nat, Long_val(ofs)), + Long_val(len), Long_val(carry_in))); +} + +value add_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2, value carry_in) +{ + return Val_long(bng_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2), + Long_val(carry_in))); +} + +CAMLprim value add_nat(value *argv, int argn) +{ + return add_nat_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6]); +} + +CAMLprim value complement_nat(value nat, value ofs, value len) +{ + bng_complement(&Digit_val(nat, Long_val(ofs)), Long_val(len)); + return Val_unit; +} + +CAMLprim value decr_nat(value nat, value ofs, value len, value carry_in) +{ + return Val_long(1 ^ bng_sub_carry(&Digit_val(nat, Long_val(ofs)), + Long_val(len), 1 ^ Long_val(carry_in))); +} + +value sub_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2, value carry_in) +{ + return Val_long(1 ^ bng_sub(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2), + 1 ^ Long_val(carry_in))); +} + +CAMLprim value sub_nat(value *argv, int argn) +{ + return sub_nat_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6]); +} + +value mult_digit_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2, + value nat3, value ofs3) +{ + return + Val_long(bng_mult_add_digit( + &Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2), + Digit_val(nat3, Long_val(ofs3)))); +} + +CAMLprim value mult_digit_nat(value *argv, int argn) +{ + return mult_digit_nat_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6], argv[7]); +} + +value mult_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2, + value nat3, value ofs3, value len3) +{ + return + Val_long(bng_mult_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2), + &Digit_val(nat3, Long_val(ofs3)), Long_val(len3))); +} + +CAMLprim value mult_nat(value *argv, int argn) +{ + return mult_nat_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6], argv[7], argv[8]); +} + +value square_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2) +{ + return + Val_long(bng_square_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2))); +} + +CAMLprim value square_nat(value *argv, int argn) +{ + return square_nat_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +value shift_left_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value nbits) +{ + Digit_val(nat2, Long_val(ofs2)) = + bng_shift_left(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + Long_val(nbits)); + return Val_unit; +} + +CAMLprim value shift_left_nat(value *argv, int argn) +{ + return shift_left_nat_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +value div_digit_nat_native(value natq, value ofsq, + value natr, value ofsr, + value nat1, value ofs1, value len1, + value nat2, value ofs2) +{ + Digit_val(natr, Long_val(ofsr)) = + bng_div_rem_digit(&Digit_val(natq, Long_val(ofsq)), + &Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + Digit_val(nat2, Long_val(ofs2))); + return Val_unit; +} + +CAMLprim value div_digit_nat(value *argv, int argn) +{ + return div_digit_nat_native(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], argv[6], argv[7], argv[8]); +} + +value div_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2) +{ + bng_div_rem(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2)); + return Val_unit; +} + +CAMLprim value div_nat(value *argv, int argn) +{ + return div_nat_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +value shift_right_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value nbits) +{ + Digit_val(nat2, Long_val(ofs2)) = + bng_shift_right(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + Long_val(nbits)); + return Val_unit; +} + +CAMLprim value shift_right_nat(value *argv, int argn) +{ + return shift_right_nat_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +CAMLprim value compare_digits_nat(value nat1, value ofs1, + value nat2, value ofs2) +{ + bngdigit d1 = Digit_val(nat1, Long_val(ofs1)); + bngdigit d2 = Digit_val(nat2, Long_val(ofs2)); + if (d1 > d2) return Val_int(1); + if (d1 < d2) return Val_int(-1); + return Val_int(0); +} + +value compare_nat_native(value nat1, value ofs1, value len1, + value nat2, value ofs2, value len2) +{ + return + Val_int(bng_compare(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1), + &Digit_val(nat2, Long_val(ofs2)), Long_val(len2))); +} + +CAMLprim value compare_nat(value *argv, int argn) +{ + return compare_nat_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +CAMLprim value land_digit_nat(value nat1, value ofs1, value nat2, value ofs2) +{ + Digit_val(nat1, Long_val(ofs1)) &= Digit_val(nat2, Long_val(ofs2)); + return Val_unit; +} + +CAMLprim value lor_digit_nat(value nat1, value ofs1, value nat2, value ofs2) +{ + Digit_val(nat1, Long_val(ofs1)) |= Digit_val(nat2, Long_val(ofs2)); + return Val_unit; +} + +CAMLprim value lxor_digit_nat(value nat1, value ofs1, value nat2, value ofs2) +{ + Digit_val(nat1, Long_val(ofs1)) ^= Digit_val(nat2, Long_val(ofs2)); + return Val_unit; +} + +/* The wire format for a nat is: + - 32-bit word: number of 32-bit words in nat + - N 32-bit words (big-endian format) + For little-endian platforms, the memory layout between 32-bit and 64-bit + machines is identical, so we can write the nat using serialize_block_4. + For big-endian 64-bit platforms, we need to swap the two 32-bit halves + of 64-bit words to obtain the correct behavior. */ + +static void serialize_nat(value nat, + uintnat * wsize_32, + uintnat * wsize_64) +{ + mlsize_t len = Wosize_val(nat) - 1; + +#ifdef ARCH_SIXTYFOUR + len = len * 2; /* two 32-bit words per 64-bit digit */ + if (len >= ((mlsize_t)1 << 32)) + failwith("output_value: nat too big"); +#endif + serialize_int_4((int32) len); +#if defined(ARCH_SIXTYFOUR) && defined(ARCH_BIG_ENDIAN) + { int32 * p; + mlsize_t i; + for (i = len, p = Data_custom_val(nat); i > 0; i -= 2, p += 2) { + serialize_int_4(p[1]); /* low 32 bits of 64-bit digit */ + serialize_int_4(p[0]); /* high 32 bits of 64-bit digit */ + } + } +#else + serialize_block_4(Data_custom_val(nat), len); +#endif + *wsize_32 = len * 4; + *wsize_64 = len * 4; +} + +static uintnat deserialize_nat(void * dst) +{ + mlsize_t len; + + len = deserialize_uint_4(); +#if defined(ARCH_SIXTYFOUR) && defined(ARCH_BIG_ENDIAN) + { uint32 * p; + mlsize_t i; + for (i = len, p = dst; i > 0; i -= 2, p += 2) { + p[1] = deserialize_uint_4(); /* low 32 bits of 64-bit digit */ + p[0] = deserialize_uint_4(); /* high 32 bits of 64-bit digit */ + } + } +#else + deserialize_block_4(dst, len); +#endif + return len * 4; +} + diff --git a/otherlibs/num/num.ml b/otherlibs/num/num.ml new file mode 100644 index 0000000..2956c1c --- /dev/null +++ b/otherlibs/num/num.ml @@ -0,0 +1,445 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: num.ml,v 1.8 2008-09-10 16:12:05 weis Exp $ *) + +open Int_misc +open Nat +open Big_int +open Arith_flags +open Ratio + +type num = Int of int | Big_int of big_int | Ratio of ratio + (* The type of numbers. *) + +let biggest_INT = big_int_of_int biggest_int +and least_INT = big_int_of_int least_int + +(* Coercion big_int -> num *) +let num_of_big_int bi = + if le_big_int bi biggest_INT && ge_big_int bi least_INT + then Int (int_of_big_int bi) + else Big_int bi + +let numerator_num = function + Ratio r -> ignore (normalize_ratio r); num_of_big_int (numerator_ratio r) +| n -> n + +let denominator_num = function + Ratio r -> ignore (normalize_ratio r); num_of_big_int (denominator_ratio r) +| n -> Int 1 + +let normalize_num = function + Int i -> Int i +| Big_int bi -> num_of_big_int bi +| Ratio r -> if is_integer_ratio r + then num_of_big_int (numerator_ratio r) + else Ratio r + +let cautious_normalize_num_when_printing n = + if (!normalize_ratio_when_printing_flag) then (normalize_num n) else n + +let num_of_ratio r = + ignore (normalize_ratio r); + if not (is_integer_ratio r) then Ratio r + else if is_int_big_int (numerator_ratio r) then + Int (int_of_big_int (numerator_ratio r)) + else Big_int (numerator_ratio r) + +(* Operations on num *) + +let add_num a b = match (a,b) with + ((Int int1), (Int int2)) -> + let r = int1 + int2 in + if (int1 lxor int2) lor (int1 lxor (r lxor (-1))) < 0 + then Int r (* No overflow *) + else Big_int(add_big_int (big_int_of_int int1) (big_int_of_int int2)) + | ((Int i), (Big_int bi)) -> + num_of_big_int (add_int_big_int i bi) + | ((Big_int bi), (Int i)) -> + num_of_big_int (add_int_big_int i bi) + + | ((Int i), (Ratio r)) -> + Ratio (add_int_ratio i r) + | ((Ratio r), (Int i)) -> + Ratio (add_int_ratio i r) + + | ((Big_int bi1), (Big_int bi2)) -> num_of_big_int (add_big_int bi1 bi2) + + | ((Big_int bi), (Ratio r)) -> + Ratio (add_big_int_ratio bi r) + | ((Ratio r), (Big_int bi)) -> + Ratio (add_big_int_ratio bi r) + + | ((Ratio r1), (Ratio r2)) -> num_of_ratio (add_ratio r1 r2) + +let ( +/ ) = add_num + +let minus_num = function + Int i -> if i = monster_int + then Big_int (minus_big_int (big_int_of_int i)) + else Int (-i) +| Big_int bi -> Big_int (minus_big_int bi) +| Ratio r -> Ratio (minus_ratio r) + +let sub_num n1 n2 = add_num n1 (minus_num n2) + +let ( -/ ) = sub_num + +let mult_num a b = match (a,b) with + ((Int int1), (Int int2)) -> + if num_bits_int int1 + num_bits_int int2 < length_of_int + then Int (int1 * int2) + else num_of_big_int (mult_big_int (big_int_of_int int1) + (big_int_of_int int2)) + + | ((Int i), (Big_int bi)) -> + num_of_big_int (mult_int_big_int i bi) + | ((Big_int bi), (Int i)) -> + num_of_big_int (mult_int_big_int i bi) + + | ((Int i), (Ratio r)) -> + num_of_ratio (mult_int_ratio i r) + | ((Ratio r), (Int i)) -> + num_of_ratio (mult_int_ratio i r) + + | ((Big_int bi1), (Big_int bi2)) -> + num_of_big_int (mult_big_int bi1 bi2) + + | ((Big_int bi), (Ratio r)) -> + num_of_ratio (mult_big_int_ratio bi r) + | ((Ratio r), (Big_int bi)) -> + num_of_ratio (mult_big_int_ratio bi r) + + | ((Ratio r1), (Ratio r2)) -> + num_of_ratio (mult_ratio r1 r2) + +let ( */ ) = mult_num + +let square_num = function + Int i -> if 2 * num_bits_int i < length_of_int + then Int (i * i) + else num_of_big_int (square_big_int (big_int_of_int i)) + | Big_int bi -> Big_int (square_big_int bi) + | Ratio r -> Ratio (square_ratio r) + +let div_num n1 n2 = + match n1 with + | Int i1 -> + begin match n2 with + | Int i2 -> + num_of_ratio (create_ratio (big_int_of_int i1) (big_int_of_int i2)) + | Big_int bi2 -> num_of_ratio (create_ratio (big_int_of_int i1) bi2) + | Ratio r2 -> num_of_ratio (div_int_ratio i1 r2) end + + | Big_int bi1 -> + begin match n2 with + | Int i2 -> num_of_ratio (create_ratio bi1 (big_int_of_int i2)) + | Big_int bi2 -> num_of_ratio (create_ratio bi1 bi2) + | Ratio r2 -> num_of_ratio (div_big_int_ratio bi1 r2) end + + | Ratio r1 -> + begin match n2 with + | Int i2 -> num_of_ratio (div_ratio_int r1 i2) + | Big_int bi2 -> num_of_ratio (div_ratio_big_int r1 bi2) + | Ratio r2 -> num_of_ratio (div_ratio r1 r2) end +;; + +let ( // ) = div_num + +let floor_num = function + Int i as n -> n +| Big_int bi as n -> n +| Ratio r -> num_of_big_int (floor_ratio r) + +(* The function [quo_num] is equivalent to + + let quo_num x y = floor_num (div_num x y);; + + However, this definition is vastly inefficient (cf PR #3473): + we define here a better way of computing the same thing. + *) +let quo_num n1 n2 = + match n1 with + | Int i1 -> + begin match n2 with + | Int i2 -> Int (i1 / i2) + | Big_int bi2 -> num_of_big_int (div_big_int (big_int_of_int i1) bi2) + | Ratio r2 -> num_of_big_int (floor_ratio (div_int_ratio i1 r2)) end + + | Big_int bi1 -> + begin match n2 with + | Int i2 -> num_of_big_int (div_big_int bi1 (big_int_of_int i2)) + | Big_int bi2 -> num_of_big_int (div_big_int bi1 bi2) + | Ratio r2 -> num_of_big_int (floor_ratio (div_big_int_ratio bi1 r2)) end + + | Ratio r1 -> + begin match n2 with + | Int i2 -> num_of_big_int (floor_ratio (div_ratio_int r1 i2)) + | Big_int bi2 -> num_of_big_int (floor_ratio (div_ratio_big_int r1 bi2)) + | Ratio r2 -> num_of_big_int (floor_ratio (div_ratio r1 r2)) end +;; + +(* The function [mod_num] is equivalent to: + + let mod_num x y = sub_num x (mult_num y (quo_num x y));; + + However, as for [quo_num] above, this definition is inefficient: + we define here a better way of computing the same thing. + *) +let mod_num n1 n2 = + match n1 with + | Int i1 -> + begin match n2 with + | Int i2 -> Int (i1 mod i2) + | Big_int bi2 -> num_of_big_int (mod_big_int (big_int_of_int i1) bi2) + | Ratio _r2 -> sub_num n1 (mult_num n2 (quo_num n1 n2)) end + + | Big_int bi1 -> + begin match n2 with + | Int i2 -> num_of_big_int (mod_big_int bi1 (big_int_of_int i2)) + | Big_int bi2 -> num_of_big_int (mod_big_int bi1 bi2) + | Ratio _r2 -> sub_num n1 (mult_num n2 (quo_num n1 n2)) end + + | Ratio _r1 -> sub_num n1 (mult_num n2 (quo_num n1 n2)) +;; + +let power_num_int a b = match (a,b) with + ((Int i), n) -> + (match sign_int n with + 0 -> Int 1 + | 1 -> num_of_big_int (power_int_positive_int i n) + | _ -> Ratio (create_normalized_ratio + unit_big_int (power_int_positive_int i (-n)))) +| ((Big_int bi), n) -> + (match sign_int n with + 0 -> Int 1 + | 1 -> num_of_big_int (power_big_int_positive_int bi n) + | _ -> Ratio (create_normalized_ratio + unit_big_int (power_big_int_positive_int bi (-n)))) +| ((Ratio r), n) -> + (match sign_int n with + 0 -> Int 1 + | 1 -> Ratio (power_ratio_positive_int r n) + | _ -> Ratio (power_ratio_positive_int + (inverse_ratio r) (-n))) + +let power_num_big_int a b = match (a,b) with + ((Int i), n) -> + (match sign_big_int n with + 0 -> Int 1 + | 1 -> num_of_big_int (power_int_positive_big_int i n) + | _ -> Ratio (create_normalized_ratio + unit_big_int + (power_int_positive_big_int i (minus_big_int n)))) +| ((Big_int bi), n) -> + (match sign_big_int n with + 0 -> Int 1 + | 1 -> num_of_big_int (power_big_int_positive_big_int bi n) + | _ -> Ratio (create_normalized_ratio + unit_big_int + (power_big_int_positive_big_int bi (minus_big_int n)))) +| ((Ratio r), n) -> + (match sign_big_int n with + 0 -> Int 1 + | 1 -> Ratio (power_ratio_positive_big_int r n) + | _ -> Ratio (power_ratio_positive_big_int + (inverse_ratio r) (minus_big_int n))) + +let power_num a b = match (a,b) with + (n, (Int i)) -> power_num_int n i +| (n, (Big_int bi)) -> power_num_big_int n bi +| _ -> invalid_arg "power_num" + +let ( **/ ) = power_num + +let is_integer_num = function + Int _ -> true +| Big_int _ -> true +| Ratio r -> is_integer_ratio r + +(* integer_num, floor_num, round_num, ceiling_num rendent des nums *) +let integer_num = function + Int i as n -> n +| Big_int bi as n -> n +| Ratio r -> num_of_big_int (integer_ratio r) + +and round_num = function + Int i as n -> n +| Big_int bi as n -> n +| Ratio r -> num_of_big_int (round_ratio r) + +and ceiling_num = function + Int i as n -> n +| Big_int bi as n -> n +| Ratio r -> num_of_big_int (ceiling_ratio r) + +(* Comparisons on nums *) + +let sign_num = function + Int i -> sign_int i +| Big_int bi -> sign_big_int bi +| Ratio r -> sign_ratio r + +let eq_num a b = match (a,b) with + ((Int int1), (Int int2)) -> int1 = int2 + +| ((Int i), (Big_int bi)) -> eq_big_int (big_int_of_int i) bi +| ((Big_int bi), (Int i)) -> eq_big_int (big_int_of_int i) bi + +| ((Int i), (Ratio r)) -> eq_big_int_ratio (big_int_of_int i) r +| ((Ratio r), (Int i)) -> eq_big_int_ratio (big_int_of_int i) r + +| ((Big_int bi1), (Big_int bi2)) -> eq_big_int bi1 bi2 + +| ((Big_int bi), (Ratio r)) -> eq_big_int_ratio bi r +| ((Ratio r), (Big_int bi)) -> eq_big_int_ratio bi r + +| ((Ratio r1), (Ratio r2)) -> eq_ratio r1 r2 + +let ( =/ ) = eq_num + +let ( <>/ ) a b = not(eq_num a b) + +let compare_num a b = match (a,b) with + ((Int int1), (Int int2)) -> compare_int int1 int2 + +| ((Int i), (Big_int bi)) -> compare_big_int (big_int_of_int i) bi +| ((Big_int bi), (Int i)) -> compare_big_int bi (big_int_of_int i) + +| ((Int i), (Ratio r)) -> compare_big_int_ratio (big_int_of_int i) r +| ((Ratio r), (Int i)) -> -(compare_big_int_ratio (big_int_of_int i) r) + +| ((Big_int bi1), (Big_int bi2)) -> compare_big_int bi1 bi2 + +| ((Big_int bi), (Ratio r)) -> compare_big_int_ratio bi r +| ((Ratio r), (Big_int bi)) -> -(compare_big_int_ratio bi r) + +| ((Ratio r1), (Ratio r2)) -> compare_ratio r1 r2 + +let lt_num num1 num2 = compare_num num1 num2 < 0 +and le_num num1 num2 = compare_num num1 num2 <= 0 +and gt_num num1 num2 = compare_num num1 num2 > 0 +and ge_num num1 num2 = compare_num num1 num2 >= 0 + +let ( </ ) = lt_num +and ( <=/ ) = le_num +and ( >/ ) = gt_num +and ( >=/ ) = ge_num + +let max_num num1 num2 = if lt_num num1 num2 then num2 else num1 +and min_num num1 num2 = if gt_num num1 num2 then num2 else num1 + +(* Coercions with basic types *) + +(* Coercion with int type *) +let int_of_num = function + Int i -> i +| Big_int bi -> int_of_big_int bi +| Ratio r -> int_of_ratio r + +and num_of_int i = + if i = monster_int + then Big_int (big_int_of_int i) + else Int i + +(* Coercion with nat type *) +let nat_of_num = function + Int i -> nat_of_int i +| Big_int bi -> nat_of_big_int bi +| Ratio r -> nat_of_ratio r + +and num_of_nat nat = + if (is_nat_int nat 0 (length_nat nat)) + then Int (nth_digit_nat nat 0) + else Big_int (big_int_of_nat nat) + +(* Coercion with big_int type *) +let big_int_of_num = function + Int i -> big_int_of_int i +| Big_int bi -> bi +| Ratio r -> big_int_of_ratio r + +(* Coercion with ratio type *) +let ratio_of_num = function + Int i -> ratio_of_int i +| Big_int bi -> ratio_of_big_int bi +| Ratio r -> r +;; + +let string_of_big_int_for_num bi = + if !approx_printing_flag + then approx_big_int !floating_precision bi + else string_of_big_int bi + +(* Coercion with string type *) + +(* XL: suppression de sys_string_of_num *) + +let string_of_normalized_num = function + Int i -> string_of_int i +| Big_int bi -> string_of_big_int_for_num bi +| Ratio r -> string_of_ratio r +let string_of_num n = + string_of_normalized_num (cautious_normalize_num_when_printing n) +let num_of_string s = + try + let flag = !normalize_ratio_flag in + normalize_ratio_flag := true; + let r = ratio_of_string s in + normalize_ratio_flag := flag; + if eq_big_int (denominator_ratio r) unit_big_int + then num_of_big_int (numerator_ratio r) + else Ratio r + with Failure _ -> + failwith "num_of_string" + +(* Coercion with float type *) +let float_of_num = function + Int i -> float i +| Big_int bi -> float_of_big_int bi +| Ratio r -> float_of_ratio r + +(* XL: suppression de num_of_float, float_num *) + +let succ_num = function + Int i -> if i = biggest_int + then Big_int (succ_big_int (big_int_of_int i)) + else Int (succ i) +| Big_int bi -> num_of_big_int (succ_big_int bi) +| Ratio r -> Ratio (add_int_ratio 1 r) + +and pred_num = function + Int i -> if i = monster_int + then Big_int (pred_big_int (big_int_of_int i)) + else Int (pred i) +| Big_int bi -> num_of_big_int (pred_big_int bi) +| Ratio r -> Ratio (add_int_ratio (-1) r) + +let abs_num = function + Int i -> if i = monster_int + then Big_int (minus_big_int (big_int_of_int i)) + else Int (abs i) + | Big_int bi -> Big_int (abs_big_int bi) + | Ratio r -> Ratio (abs_ratio r) + +let approx_num_fix n num = approx_ratio_fix n (ratio_of_num num) +and approx_num_exp n num = approx_ratio_exp n (ratio_of_num num) + +let incr_num r = r := succ_num !r +and decr_num r = r := pred_num !r + + + + + diff --git a/otherlibs/num/num.mli b/otherlibs/num/num.mli new file mode 100644 index 0000000..597f03b --- /dev/null +++ b/otherlibs/num/num.mli @@ -0,0 +1,171 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: num.mli,v 1.8 2001-12-28 23:15:23 guesdon Exp $ *) + +(** Operation on arbitrary-precision numbers. + + Numbers (type [num]) are arbitrary-precision rational numbers, + plus the special elements [1/0] (infinity) and [0/0] (undefined). +*) + +open Nat +open Big_int +open Ratio + +(** The type of numbers. *) +type num = + Int of int + | Big_int of big_int + | Ratio of ratio + + +(** {6 Arithmetic operations} *) + + +val ( +/ ) : num -> num -> num +(** Same as {!Num.add_num}.*) + +val add_num : num -> num -> num +(** Addition *) + +val minus_num : num -> num +(** Unary negation. *) + +val ( -/ ) : num -> num -> num +(** Same as {!Num.sub_num}.*) + +val sub_num : num -> num -> num +(** Subtraction *) + +val ( */ ) : num -> num -> num +(** Same as {!Num.mult_num}.*) + +val mult_num : num -> num -> num +(** Multiplication *) + +val square_num : num -> num +(** Squaring *) + +val ( // ) : num -> num -> num +(** Same as {!Num.div_num}.*) + +val div_num : num -> num -> num +(** Division *) + +val quo_num : num -> num -> num +(** Euclidean division: quotient. *) + +val mod_num : num -> num -> num +(** Euclidean division: remainder. *) + +val ( **/ ) : num -> num -> num +(** Same as {!Num.power_num}. *) + +val power_num : num -> num -> num +(** Exponentiation *) + +val abs_num : num -> num +(** Absolute value. *) + +val succ_num : num -> num +(** [succ n] is [n+1] *) + +val pred_num : num -> num +(** [pred n] is [n-1] *) + +val incr_num : num ref -> unit +(** [incr r] is [r:=!r+1], where [r] is a reference to a number. *) + +val decr_num : num ref -> unit +(** [decr r] is [r:=!r-1], where [r] is a reference to a number. *) + +val is_integer_num : num -> bool +(** Test if a number is an integer *) + +(** The four following functions approximate a number by an integer : *) + +val integer_num : num -> num +(** [integer_num n] returns the integer closest to [n]. In case of ties, + rounds towards zero. *) + +val floor_num : num -> num +(** [floor_num n] returns the largest integer smaller or equal to [n]. *) + +val round_num : num -> num +(** [round_num n] returns the integer closest to [n]. In case of ties, + rounds off zero. *) + +val ceiling_num : num -> num +(** [ceiling_num n] returns the smallest integer bigger or equal to [n]. *) + + +val sign_num : num -> int +(** Return [-1], [0] or [1] according to the sign of the argument. *) + +(** {7 Comparisons between numbers} *) + +val ( =/ ) : num -> num -> bool +val ( </ ) : num -> num -> bool +val ( >/ ) : num -> num -> bool +val ( <=/ ) : num -> num -> bool +val ( >=/ ) : num -> num -> bool +val ( <>/ ) : num -> num -> bool +val eq_num : num -> num -> bool +val lt_num : num -> num -> bool +val le_num : num -> num -> bool +val gt_num : num -> num -> bool +val ge_num : num -> num -> bool + +val compare_num : num -> num -> int +(** Return [-1], [0] or [1] if the first argument is less than, + equal to, or greater than the second argument. *) + +val max_num : num -> num -> num +(** Return the greater of the two arguments. *) + +val min_num : num -> num -> num +(** Return the smaller of the two arguments. *) + + +(** {6 Coercions with strings} *) + +val string_of_num : num -> string +(** Convert a number to a string, using fractional notation. *) + +val approx_num_fix : int -> num -> string +(** See {!Num.approx_num_exp}.*) + +val approx_num_exp : int -> num -> string +(** Approximate a number by a decimal. The first argument is the + required precision. The second argument is the number to + approximate. {!Num.approx_num_fix} uses decimal notation; the first + argument is the number of digits after the decimal point. + [approx_num_exp] uses scientific (exponential) notation; the + first argument is the number of digits in the mantissa. *) + +val num_of_string : string -> num +(** Convert a string to a number. *) + +(** {6 Coercions between numerical types} *) + +val int_of_num : num -> int +val num_of_int : int -> num +val nat_of_num : num -> nat +val num_of_nat : nat -> num +val num_of_big_int : big_int -> num +val big_int_of_num : num -> big_int +val ratio_of_num : num -> ratio +val num_of_ratio : ratio -> num +val float_of_num : num -> float + diff --git a/otherlibs/num/nums.mllib b/otherlibs/num/nums.mllib new file mode 100644 index 0000000..8db1683 --- /dev/null +++ b/otherlibs/num/nums.mllib @@ -0,0 +1 @@ +Int_misc Nat Big_int Arith_flags Ratio Num Arith_status diff --git a/otherlibs/num/ratio.ml b/otherlibs/num/ratio.ml new file mode 100644 index 0000000..e587efe --- /dev/null +++ b/otherlibs/num/ratio.ml @@ -0,0 +1,575 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +open Int_misc +open Nat +open Big_int +open Arith_flags + +(* Definition of the type ratio : + Conventions : + - the denominator is always a positive number + - the sign of n/0 is the sign of n +These convention is automatically respected when a ratio is created with +the create_ratio primitive +*) + +type ratio = { mutable numerator : big_int; + mutable denominator : big_int; + mutable normalized : bool} + +let failwith_zero name = + let s = "infinite or undefined rational number" in + failwith (if String.length name = 0 then s else name ^ " " ^ s) + +let numerator_ratio r = r.numerator +and denominator_ratio r = r.denominator + +let null_denominator r = sign_big_int r.denominator = 0 + +let verify_null_denominator r = + if sign_big_int r.denominator = 0 + then (if !error_when_null_denominator_flag + then (failwith_zero "") + else true) + else false + +let sign_ratio r = sign_big_int r.numerator + +(* Physical normalization of rational numbers *) +(* 1/0, 0/0 and -1/0 are the normalized forms for n/0 numbers *) +let normalize_ratio r = + if r.normalized then r + else if verify_null_denominator r then begin + r.numerator <- big_int_of_int (sign_big_int r.numerator); + r.normalized <- true; + r + end else begin + let p = gcd_big_int r.numerator r.denominator in + if eq_big_int p unit_big_int + then begin + r.normalized <- true; r + end else begin + r.numerator <- div_big_int (r.numerator) p; + r.denominator <- div_big_int (r.denominator) p; + r.normalized <- true; r + end + end + +let cautious_normalize_ratio r = + if (!normalize_ratio_flag) then (normalize_ratio r) else r + +let cautious_normalize_ratio_when_printing r = + if (!normalize_ratio_when_printing_flag) then (normalize_ratio r) else r + +let create_ratio bi1 bi2 = + match sign_big_int bi2 with + -1 -> cautious_normalize_ratio + { numerator = minus_big_int bi1; + denominator = minus_big_int bi2; + normalized = false } + | 0 -> if !error_when_null_denominator_flag + then (failwith_zero "create_ratio") + else cautious_normalize_ratio + { numerator = bi1; denominator = bi2; normalized = false } + | _ -> cautious_normalize_ratio + { numerator = bi1; denominator = bi2; normalized = false } + +let create_normalized_ratio bi1 bi2 = + match sign_big_int bi2 with + -1 -> { numerator = minus_big_int bi1; + denominator = minus_big_int bi2; + normalized = true } +| 0 -> if !error_when_null_denominator_flag + then failwith_zero "create_normalized_ratio" + else { numerator = bi1; denominator = bi2; normalized = true } +| _ -> { numerator = bi1; denominator = bi2; normalized = true } + +let is_normalized_ratio r = r.normalized + +let report_sign_ratio r bi = + if sign_ratio r = -1 + then minus_big_int bi + else bi + +let abs_ratio r = + { numerator = abs_big_int r.numerator; + denominator = r.denominator; + normalized = r.normalized } + +let is_integer_ratio r = + eq_big_int ((normalize_ratio r).denominator) unit_big_int + +(* Operations on rational numbers *) + +let add_ratio r1 r2 = + if !normalize_ratio_flag then begin + let p = gcd_big_int ((normalize_ratio r1).denominator) + ((normalize_ratio r2).denominator) in + if eq_big_int p unit_big_int then + {numerator = add_big_int (mult_big_int (r1.numerator) r2.denominator) + (mult_big_int (r2.numerator) r1.denominator); + denominator = mult_big_int (r1.denominator) r2.denominator; + normalized = true} + else begin + let d1 = div_big_int (r1.denominator) p + and d2 = div_big_int (r2.denominator) p in + let n = add_big_int (mult_big_int (r1.numerator) d2) + (mult_big_int d1 r2.numerator) in + let p' = gcd_big_int n p in + { numerator = div_big_int n p'; + denominator = mult_big_int d1 (div_big_int (r2.denominator) p'); + normalized = true } + end + end else + { numerator = add_big_int (mult_big_int (r1.numerator) r2.denominator) + (mult_big_int (r1.denominator) r2.numerator); + denominator = mult_big_int (r1.denominator) r2.denominator; + normalized = false } + +let minus_ratio r = + { numerator = minus_big_int (r.numerator); + denominator = r.denominator; + normalized = r.normalized } + +let add_int_ratio i r = + ignore (cautious_normalize_ratio r); + { numerator = add_big_int (mult_int_big_int i r.denominator) r.numerator; + denominator = r.denominator; + normalized = r.normalized } + +let add_big_int_ratio bi r = + ignore (cautious_normalize_ratio r); + { numerator = add_big_int (mult_big_int bi r.denominator) r.numerator ; + denominator = r.denominator; + normalized = r.normalized } + +let sub_ratio r1 r2 = add_ratio r1 (minus_ratio r2) + +let mult_ratio r1 r2 = + if !normalize_ratio_flag then begin + let p1 = gcd_big_int ((normalize_ratio r1).numerator) + ((normalize_ratio r2).denominator) + and p2 = gcd_big_int (r2.numerator) r1.denominator in + let (n1, d2) = + if eq_big_int p1 unit_big_int + then (r1.numerator, r2.denominator) + else (div_big_int (r1.numerator) p1, div_big_int (r2.denominator) p1) + and (n2, d1) = + if eq_big_int p2 unit_big_int + then (r2.numerator, r1.denominator) + else (div_big_int r2.numerator p2, div_big_int r1.denominator p2) in + { numerator = mult_big_int n1 n2; + denominator = mult_big_int d1 d2; + normalized = true } + end else + { numerator = mult_big_int (r1.numerator) r2.numerator; + denominator = mult_big_int (r1.denominator) r2.denominator; + normalized = false } + +let mult_int_ratio i r = + if !normalize_ratio_flag then + begin + let p = gcd_big_int ((normalize_ratio r).denominator) (big_int_of_int i) in + if eq_big_int p unit_big_int + then { numerator = mult_big_int (big_int_of_int i) r.numerator; + denominator = r.denominator; + normalized = true } + else { numerator = mult_big_int (div_big_int (big_int_of_int i) p) + r.numerator; + denominator = div_big_int (r.denominator) p; + normalized = true } + end + else + { numerator = mult_int_big_int i r.numerator; + denominator = r.denominator; + normalized = false } + +let mult_big_int_ratio bi r = + if !normalize_ratio_flag then + begin + let p = gcd_big_int ((normalize_ratio r).denominator) bi in + if eq_big_int p unit_big_int + then { numerator = mult_big_int bi r.numerator; + denominator = r.denominator; + normalized = true } + else { numerator = mult_big_int (div_big_int bi p) r.numerator; + denominator = div_big_int (r.denominator) p; + normalized = true } + end + else + { numerator = mult_big_int bi r.numerator; + denominator = r.denominator; + normalized = false } + +let square_ratio r = + ignore (cautious_normalize_ratio r); + { numerator = square_big_int r.numerator; + denominator = square_big_int r.denominator; + normalized = r.normalized } + +let inverse_ratio r = + if !error_when_null_denominator_flag && (sign_big_int r.numerator) = 0 + then failwith_zero "inverse_ratio" + else {numerator = report_sign_ratio r r.denominator; + denominator = abs_big_int r.numerator; + normalized = r.normalized} + +let div_ratio r1 r2 = + mult_ratio r1 (inverse_ratio r2) + +(* Integer part of a rational number *) +(* Odd function *) +let integer_ratio r = + if null_denominator r then failwith_zero "integer_ratio" + else if sign_ratio r = 0 then zero_big_int + else report_sign_ratio r (div_big_int (abs_big_int r.numerator) + (abs_big_int r.denominator)) + +(* Floor of a rational number *) +(* Always less or equal to r *) +let floor_ratio r = + ignore (verify_null_denominator r); + div_big_int (r.numerator) r.denominator + +(* Round of a rational number *) +(* Odd function, 1/2 -> 1 *) +let round_ratio r = + ignore (verify_null_denominator r); + let abs_num = abs_big_int r.numerator in + let bi = div_big_int abs_num r.denominator in + report_sign_ratio r + (if sign_big_int + (sub_big_int + (mult_int_big_int + 2 + (sub_big_int abs_num (mult_big_int (r.denominator) bi))) + r.denominator) = -1 + then bi + else succ_big_int bi) + +let ceiling_ratio r = + if (is_integer_ratio r) + then r.numerator + else succ_big_int (floor_ratio r) + + +(* Comparison operators on rational numbers *) +let eq_ratio r1 r2 = + ignore (normalize_ratio r1); + ignore (normalize_ratio r2); + eq_big_int (r1.numerator) r2.numerator && + eq_big_int (r1.denominator) r2.denominator + +let compare_ratio r1 r2 = + if verify_null_denominator r1 then + let sign_num_r1 = sign_big_int r1.numerator in + if (verify_null_denominator r2) + then + let sign_num_r2 = sign_big_int r2.numerator in + if sign_num_r1 = 1 && sign_num_r2 = -1 then 1 + else if sign_num_r1 = -1 && sign_num_r2 = 1 then -1 + else 0 + else sign_num_r1 + else if verify_null_denominator r2 then + -(sign_big_int r2.numerator) + else match compare_int (sign_big_int r1.numerator) + (sign_big_int r2.numerator) with + 1 -> 1 + | -1 -> -1 + | _ -> if eq_big_int (r1.denominator) r2.denominator + then compare_big_int (r1.numerator) r2.numerator + else compare_big_int + (mult_big_int (r1.numerator) r2.denominator) + (mult_big_int (r1.denominator) r2.numerator) + + +let lt_ratio r1 r2 = compare_ratio r1 r2 < 0 +and le_ratio r1 r2 = compare_ratio r1 r2 <= 0 +and gt_ratio r1 r2 = compare_ratio r1 r2 > 0 +and ge_ratio r1 r2 = compare_ratio r1 r2 >= 0 + +let max_ratio r1 r2 = if lt_ratio r1 r2 then r2 else r1 +and min_ratio r1 r2 = if gt_ratio r1 r2 then r2 else r1 + +let eq_big_int_ratio bi r = + (is_integer_ratio r) && eq_big_int bi r.numerator + +let compare_big_int_ratio bi r = + ignore (normalize_ratio r); + if (verify_null_denominator r) + then -(sign_big_int r.numerator) + else compare_big_int (mult_big_int bi r.denominator) r.numerator + +let lt_big_int_ratio bi r = compare_big_int_ratio bi r < 0 +and le_big_int_ratio bi r = compare_big_int_ratio bi r <= 0 +and gt_big_int_ratio bi r = compare_big_int_ratio bi r > 0 +and ge_big_int_ratio bi r = compare_big_int_ratio bi r >= 0 + +(* Coercions *) + +(* Coercions with type int *) +let int_of_ratio r = + if ((is_integer_ratio r) && (is_int_big_int r.numerator)) + then (int_of_big_int r.numerator) + else failwith "integer argument required" + +and ratio_of_int i = + { numerator = big_int_of_int i; + denominator = unit_big_int; + normalized = true } + +(* Coercions with type nat *) +let ratio_of_nat nat = + { numerator = big_int_of_nat nat; + denominator = unit_big_int; + normalized = true } + +and nat_of_ratio r = + ignore (normalize_ratio r); + if not (is_integer_ratio r) then + failwith "nat_of_ratio" + else if sign_big_int r.numerator > -1 then + nat_of_big_int (r.numerator) + else failwith "nat_of_ratio" + +(* Coercions with type big_int *) +let ratio_of_big_int bi = + { numerator = bi; denominator = unit_big_int; normalized = true } + +and big_int_of_ratio r = + ignore (normalize_ratio r); + if is_integer_ratio r + then r.numerator + else failwith "big_int_of_ratio" + +let div_int_ratio i r = + ignore (verify_null_denominator r); + mult_int_ratio i (inverse_ratio r) + +let div_ratio_int r i = + div_ratio r (ratio_of_int i) + +let div_big_int_ratio bi r = + ignore (verify_null_denominator r); + mult_big_int_ratio bi (inverse_ratio r) + +let div_ratio_big_int r bi = + div_ratio r (ratio_of_big_int bi) + +(* Functions on type string *) +(* giving floating point approximations of rational numbers *) + +(* Compares strings that contains only digits, have the same length, + from index i to index i + l *) +let rec compare_num_string s1 s2 i len = + if i >= len then 0 else + let c1 = int_of_char s1.[i] + and c2 = int_of_char s2.[i] in + match compare_int c1 c2 with + | 0 -> compare_num_string s1 s2 (succ i) len + | c -> c;; + +(* Position of the leading digit of the decimal expansion *) +(* of a strictly positive rational number *) +(* if the decimal expansion of a non null rational r is equal to *) +(* sigma for k=-P to N of r_k*10^k then msd_ratio r = N *) +(* Nota : for a big_int we have msd_ratio = nums_digits_big_int -1 *) + +(* Tests if s has only zeros characters from index i to index lim *) +let rec only_zeros s i lim = + i >= lim || s.[i] == '0' && only_zeros s (succ i) lim;; + +(* Nota : for a big_int we have msd_ratio = nums_digits_big_int -1 *) +let msd_ratio r = + ignore (cautious_normalize_ratio r); + if null_denominator r then failwith_zero "msd_ratio" + else if sign_big_int r.numerator == 0 then 0 + else begin + let str_num = string_of_big_int r.numerator + and str_den = string_of_big_int r.denominator in + let size_num = String.length str_num + and size_den = String.length str_den in + let size_min = min size_num size_den in + let m = size_num - size_den in + let cmp = compare_num_string str_num str_den 0 size_min in + match cmp with + | 1 -> m + | -1 -> pred m + | _ -> + if m >= 0 then m else + if only_zeros str_den size_min size_den then m + else pred m + end +;; + +(* Decimal approximations of rational numbers *) + +(* Approximation with fix decimal point *) +(* This is an odd function and the last digit is round off *) +(* Format integer_part . decimal_part_with_n_digits *) +let approx_ratio_fix n r = + (* Don't need to normalize *) + if (null_denominator r) then failwith_zero "approx_ratio_fix" + else + let sign_r = sign_ratio r in + if sign_r = 0 + then "+0" (* r = 0 *) + else + (* r.numerator and r.denominator are not null numbers + s1 contains one more digit than desired for the round off operation *) + if n >= 0 then begin + let s1 = + string_of_nat + (nat_of_big_int + (div_big_int + (base_power_big_int + 10 (succ n) (abs_big_int r.numerator)) + r.denominator)) in + (* Round up and add 1 in front if needed *) + let s2 = + if round_futur_last_digit s1 0 (String.length s1) + then "1" ^ s1 + else s1 in + let l2 = String.length s2 - 1 in + (* if s2 without last digit is xxxxyyy with n 'yyy' digits: + <sign> xxxx . yyy + if s2 without last digit is yy with <= n digits: + <sign> 0 . 0yy *) + if l2 > n then begin + let s = String.make (l2 + 2) '0' in + String.set s 0 (if sign_r = -1 then '-' else '+'); + String.blit s2 0 s 1 (l2 - n); + String.set s (l2 - n + 1) '.'; + String.blit s2 (l2 - n) s (l2 - n + 2) n; + s + end else begin + let s = String.make (n + 3) '0' in + String.set s 0 (if sign_r = -1 then '-' else '+'); + String.set s 2 '.'; + String.blit s2 0 s (n + 3 - l2) l2; + s + end + end else begin + (* Dubious; what is this code supposed to do? *) + let s = string_of_big_int + (div_big_int + (abs_big_int r.numerator) + (base_power_big_int + 10 (-n) r.denominator)) in + let len = succ (String.length s) in + let s' = String.make len '0' in + String.set s' 0 (if sign_r = -1 then '-' else '+'); + String.blit s 0 s' 1 (pred len); + s' + end + +(* Number of digits of the decimal representation of an int *) +let num_decimal_digits_int n = + String.length (string_of_int n) + +(* Approximation with floating decimal point *) +(* This is an odd function and the last digit is round off *) +(* Format (+/-)(0. n_first_digits e msd)/(1. n_zeros e (msd+1) *) +let approx_ratio_exp n r = + (* Don't need to normalize *) + if (null_denominator r) then failwith_zero "approx_ratio_exp" + else if n <= 0 then invalid_arg "approx_ratio_exp" + else + let sign_r = sign_ratio r + and i = ref (n + 3) in + if sign_r = 0 + then + let s = String.make (n + 5) '0' in + (String.blit "+0." 0 s 0 3); + (String.blit "e0" 0 s !i 2); s + else + let msd = msd_ratio (abs_ratio r) in + let k = n - msd in + let s = + (let nat = nat_of_big_int + (if k < 0 + then + div_big_int (abs_big_int r.numerator) + (base_power_big_int 10 (- k) + r.denominator) + else + div_big_int (base_power_big_int + 10 k (abs_big_int r.numerator)) + r.denominator) in + string_of_nat nat) in + if (round_futur_last_digit s 0 (String.length s)) + then + let m = num_decimal_digits_int (succ msd) in + let str = String.make (n + m + 4) '0' in + (String.blit (if sign_r = -1 then "-1." else "+1.") 0 str 0 3); + String.set str !i ('e'); + incr i; + (if m = 0 + then String.set str !i '0' + else String.blit (string_of_int (succ msd)) 0 str !i m); + str + else + let m = num_decimal_digits_int (succ msd) + and p = n + 3 in + let str = String.make (succ (m + p)) '0' in + (String.blit (if sign_r = -1 then "-0." else "+0.") 0 str 0 3); + (String.blit s 0 str 3 n); + String.set str p 'e'; + (if m = 0 + then String.set str (succ p) '0' + else (String.blit (string_of_int (succ msd)) 0 str (succ p) m)); + str + +(* String approximation of a rational with a fixed number of significant *) +(* digits printed *) +let float_of_rational_string r = + let s = approx_ratio_exp !floating_precision r in + if String.get s 0 = '+' + then (String.sub s 1 (pred (String.length s))) + else s + +(* Coercions with type string *) +let string_of_ratio r = + ignore (cautious_normalize_ratio_when_printing r); + if !approx_printing_flag + then float_of_rational_string r + else string_of_big_int r.numerator ^ "/" ^ string_of_big_int r.denominator + +(* XL: j'ai puissamment simplifie "ratio_of_string" en virant la notation + scientifique. *) + +let ratio_of_string s = + try + let n = String.index s '/' in + create_ratio (sys_big_int_of_string s 0 n) + (sys_big_int_of_string s (n+1) (String.length s - n - 1)) + with Not_found -> + { numerator = big_int_of_string s; + denominator = unit_big_int; + normalized = true } + +(* Coercion with type float *) + +let float_of_ratio r = + float_of_string (float_of_rational_string r) + +(* XL: suppression de ratio_of_float *) + +let power_ratio_positive_int r n = + create_ratio (power_big_int_positive_int (r.numerator) n) + (power_big_int_positive_int (r.denominator) n) + +let power_ratio_positive_big_int r bi = + create_ratio (power_big_int_positive_big_int (r.numerator) bi) + (power_big_int_positive_big_int (r.denominator) bi) diff --git a/otherlibs/num/ratio.mli b/otherlibs/num/ratio.mli new file mode 100644 index 0000000..bcf0ac5 --- /dev/null +++ b/otherlibs/num/ratio.mli @@ -0,0 +1,88 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: ratio.mli,v 1.4 2001-12-07 13:40:16 xleroy Exp $ *) + +(* Module [Ratio]: operations on rational numbers *) + +open Nat +open Big_int + +(* Rationals (type [ratio]) are arbitrary-precision rational numbers, + plus the special elements [1/0] (infinity) and [0/0] (undefined). + In constrast with numbers (type [num]), the special cases of + small integers and big integers are not optimized specially. *) + +type ratio + +val null_denominator : ratio -> bool +val numerator_ratio : ratio -> big_int +val denominator_ratio : ratio -> big_int +val sign_ratio : ratio -> int +val normalize_ratio : ratio -> ratio +val cautious_normalize_ratio : ratio -> ratio +val cautious_normalize_ratio_when_printing : ratio -> ratio +val create_ratio : big_int -> big_int -> ratio +val create_normalized_ratio : big_int -> big_int -> ratio +val is_normalized_ratio : ratio -> bool +val report_sign_ratio : ratio -> big_int -> big_int +val abs_ratio : ratio -> ratio +val is_integer_ratio : ratio -> bool +val add_ratio : ratio -> ratio -> ratio +val minus_ratio : ratio -> ratio +val add_int_ratio : int -> ratio -> ratio +val add_big_int_ratio : big_int -> ratio -> ratio +val sub_ratio : ratio -> ratio -> ratio +val mult_ratio : ratio -> ratio -> ratio +val mult_int_ratio : int -> ratio -> ratio +val mult_big_int_ratio : big_int -> ratio -> ratio +val square_ratio : ratio -> ratio +val inverse_ratio : ratio -> ratio +val div_ratio : ratio -> ratio -> ratio +val integer_ratio : ratio -> big_int +val floor_ratio : ratio -> big_int +val round_ratio : ratio -> big_int +val ceiling_ratio : ratio -> big_int +val eq_ratio : ratio -> ratio -> bool +val compare_ratio : ratio -> ratio -> int +val lt_ratio : ratio -> ratio -> bool +val le_ratio : ratio -> ratio -> bool +val gt_ratio : ratio -> ratio -> bool +val ge_ratio : ratio -> ratio -> bool +val max_ratio : ratio -> ratio -> ratio +val min_ratio : ratio -> ratio -> ratio +val eq_big_int_ratio : big_int -> ratio -> bool +val compare_big_int_ratio : big_int -> ratio -> int +val lt_big_int_ratio : big_int -> ratio -> bool +val le_big_int_ratio : big_int -> ratio -> bool +val gt_big_int_ratio : big_int -> ratio -> bool +val ge_big_int_ratio : big_int -> ratio -> bool +val int_of_ratio : ratio -> int +val ratio_of_int : int -> ratio +val ratio_of_nat : nat -> ratio +val nat_of_ratio : ratio -> nat +val ratio_of_big_int : big_int -> ratio +val big_int_of_ratio : ratio -> big_int +val div_int_ratio : int -> ratio -> ratio +val div_ratio_int : ratio -> int -> ratio +val div_big_int_ratio : big_int -> ratio -> ratio +val div_ratio_big_int : ratio -> big_int -> ratio +val approx_ratio_fix : int -> ratio -> string +val approx_ratio_exp : int -> ratio -> string +val float_of_rational_string : ratio -> string +val string_of_ratio : ratio -> string +val ratio_of_string : string -> ratio +val float_of_ratio : ratio -> float +val power_ratio_positive_int : ratio -> int -> ratio +val power_ratio_positive_big_int : ratio -> big_int -> ratio + diff --git a/otherlibs/num/test/.depend b/otherlibs/num/test/.depend new file mode 100644 index 0000000..28fea1f --- /dev/null +++ b/otherlibs/num/test/.depend @@ -0,0 +1,10 @@ +end_test.cmo: test.cmo +end_test.cmx: test.cmx +test_big_ints.cmo: test.cmo +test_big_ints.cmx: test.cmx +test_nats.cmo: test.cmo +test_nats.cmx: test.cmx +test_nums.cmo: test.cmo +test_nums.cmx: test.cmx +test_ratios.cmo: test.cmo +test_ratios.cmx: test.cmx diff --git a/otherlibs/num/test/Makefile b/otherlibs/num/test/Makefile new file mode 100644 index 0000000..b332f3e --- /dev/null +++ b/otherlibs/num/test/Makefile @@ -0,0 +1,76 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../../LICENSE.# +# # +######################################################################### + +# $Id: Makefile,v 1.13 2008-09-10 16:02:52 weis Exp $ + +include ../../../config/Makefile + +CAMLC=../../../boot/ocamlrun ../../../ocamlc -I ../../../stdlib -w A -warn-error A +CAMLOPT=../../../boot/ocamlrun ../../../ocamlopt -I ../../../stdlib +CC=$(BYTECC) +CFLAGS=-I.. -I../../../byterun $(BYTECCCOMPOPTS) + +test: test.byt test.opt test_pi + if $(SUPPORTS_SHARED_LIBRARIES); \ + then ../../../byterun/ocamlrun -I .. ./test.byt; else ./test.byt; fi + ./test.opt + +TESTFILES=test.cmo \ + test_nats.cmo test_big_ints.cmo test_ratios.cmo test_nums.cmo \ + test_io.cmo end_test.cmo + +TESTOPTFILES=$(TESTFILES:.cmo=.cmx) + +test.byt: $(TESTFILES) ../nums.cma ../libnums.a + $(CAMLC) -ccopt -L.. -I .. -o test.byt -g ../nums.cma $(TESTFILES) + +test.opt: $(TESTOPTFILES) ../nums.cmxa ../libnums.a + $(CAMLOPT) -ccopt -L.. -I .. -o test.opt ../nums.cmxa $(TESTOPTFILES) + +test_bng: test_bng.o + $(CC) $(CFLAGS) -o test_bng ../bng.o test_bng.o -lbignum + +$(TESTOPTFILES): ../../../ocamlopt + +test_pi: test_pi.byt test_pi.bin + +test_pi.byt: pi_big_int.cmo pi_num.cmo + $(CAMLC) -ccopt -L.. -I .. -o pi_big_int.byt -g ../nums.cma pi_big_int.cmo + $(CAMLC) -ccopt -L.. -I .. -o pi_num.byt -g ../nums.cma pi_num.cmo + ./pi_big_int.byt 1000 + ./pi_num.byt 1000 + +test_pi.bin: pi_big_int.cmx pi_num.cmx + $(CAMLOPT) -ccopt -L.. -I .. -o pi_big_int.bin -g ../nums.cmxa pi_big_int.cmx + $(CAMLOPT) -ccopt -L.. -I .. -o pi_num.bin -g ../nums.cmxa pi_num.cmx + ./pi_big_int.bin 1000 + ./pi_num.bin 1000 + +.SUFFIXES: .ml .cmo .cmx + +.ml.cmo: + $(CAMLC) -I .. -c -g $< + +.ml.cmx: + $(CAMLOPT) -I .. -c $< + +ocamlnum: + ocamlmktop -o ocamlnum -custom ../nums.cma ../libnums.a + +clean: + rm -f *.byt *.opt *.bin test_bng *.o *.cm? ocamlnum *~ + +depend: + ocamldep *.ml > .depend + +include .depend diff --git a/otherlibs/num/test/Makefile.nt b/otherlibs/num/test/Makefile.nt new file mode 100644 index 0000000..059eee0 --- /dev/null +++ b/otherlibs/num/test/Makefile.nt @@ -0,0 +1,61 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../../LICENSE.# +# # +######################################################################### + +# $Id: Makefile.nt,v 1.9 2004-04-01 13:10:12 xleroy Exp $ + +include ../../../config/Makefile + +CAMLC=../../../boot/ocamlrun ../../../ocamlc -I ../../../stdlib -I .. +CAMLOPT=../../../boot/ocamlrun ../../../ocamlopt -I ../../../stdlib -I .. +CC=$(BYTECC) +CFLAGS=-I.. $(BYTECCCOMPOPTS) + +test: test.byt test.opt + ../../../byterun/ocamlrun -I .. ./test.byt + ./test.opt + +TESTFILES=test.cmo \ + test_nats.cmo test_big_ints.cmo test_ratios.cmo test_nums.cmo \ + test_io.cmo end_test.cmo + +TESTOPTFILES=$(TESTFILES:.cmo=.cmx) + +test.byt: $(TESTFILES) ../nums.cma ../libnums.$(A) + $(CAMLC) -o test.byt nums.cma $(TESTFILES) + +test.opt: $(TESTOPTFILES) ../nums.cmxa ../libnums.$(A) + $(CAMLOPT) -o test.opt nums.cmxa $(TESTOPTFILES) + +test_bng.exe: test_bng.o + $(CC) $(CFLAGS) -o test_bng.exe ../bng.o test_bng.o -lbignum + +$(TESTOPTFILES): ../../../ocamlopt + +.SUFFIXES: .ml .cmo .cmx + +.ml.cmo: + $(CAMLC) -c $< + +.ml.cmx: + $(CAMLOPT) -c $< + +ocamltopnum.exe: + ocamlmktop -o ocamltopnum.exe -custom ../nums.cma ../libnums.$(A) + +clean: + rm -f test.byt test.opt test_bng.exe *.$(O) *.cm? ocamltopnum.exe + +depend: + ocamldep *.ml > .depend + +include .depend diff --git a/otherlibs/num/test/end_test.ml b/otherlibs/num/test/end_test.ml new file mode 100644 index 0000000..57e099e --- /dev/null +++ b/otherlibs/num/test/end_test.ml @@ -0,0 +1 @@ +Test.end_tests ();; diff --git a/otherlibs/num/test/pi_big_int.ml b/otherlibs/num/test/pi_big_int.ml new file mode 100644 index 0000000..22872ba --- /dev/null +++ b/otherlibs/num/test/pi_big_int.ml @@ -0,0 +1,78 @@ +(* Pi digits computed with the sreaming algorithm given on pages 4, 6 + & 7 of "Unbounded Spigot Algorithms for the Digits of Pi", Jeremy + Gibbons, August 2004. *) + +open Printf;; +open Big_int;; + +let ( !$ ) = Big_int.big_int_of_int +and ( +$ ) = Big_int.add_big_int +and ( *$ ) = Big_int.mult_big_int +and ( =$ ) = Big_int.eq_big_int +;; + +let zero = Big_int.zero_big_int +and one = Big_int.unit_big_int +and three = !$ 3 +and four = !$ 4 +and ten = !$ 10 +and neg_ten = !$(-10) +;; + +(* Linear Fractional (aka M=F6bius) Transformations *) +module LFT = struct + + let floor_ev (q, r, s, t) x = div_big_int (q *$ x +$ r) (s *$ x +$ t);; + + let unit = (one, zero, zero, one);; + + let comp (q, r, s, t) (q', r', s', t') = + (q *$ q' +$ r *$ s', q *$ r' +$ r *$ t', + s *$ q' +$ t *$ s', s *$ r' +$ t *$ t') +;; + +end +;; + +let next z = LFT.floor_ev z three +and safe z n = (n =$ LFT.floor_ev z four) +and prod z n = LFT.comp (ten, neg_ten *$ n, zero, one) z +and cons z k = + let den = 2 * k + 1 in + LFT.comp z (!$ k, !$(2 * den), zero, !$ den) +;; + +let rec digit k z n row col = + if n > 0 then + let y = next z in + if safe z y then + if col = 10 then ( + let row = row + 10 in + printf "\t:%i\n%s" row (string_of_big_int y); + digit k (prod z y) (n - 1) row 1 + ) + else ( + print_string(string_of_big_int y); + digit k (prod z y) (n - 1) row (col + 1) + ) + else digit (k + 1) (cons z k) n row col + else + printf "%*s\t:%i\n" (10 - col) "" (row + col) +;; + +let digits n = digit 1 LFT.unit n 0 0 +;; + +let usage () = + prerr_endline "Usage: pi_big_int <number of digits to compute for pi>"; + exit 2 +;; + +let main () = + let args = Sys.argv in + if Array.length args <> 2 then usage () else + digits (int_of_string Sys.argv.(1)) +;; + +main () +;; diff --git a/otherlibs/num/test/pi_num.ml b/otherlibs/num/test/pi_num.ml new file mode 100644 index 0000000..b362508 --- /dev/null +++ b/otherlibs/num/test/pi_num.ml @@ -0,0 +1,73 @@ + +(* Pi digits computed with the sreaming algorithm given on pages 4, 6 + & 7 of "Unbounded Spigot Algorithms for the Digits of Pi", Jeremy + Gibbons, August 2004. *) + +open Printf;; +open Num;; + +let zero = num_of_int 0 +and one = num_of_int 1 +and three = num_of_int 3 +and four = num_of_int 4 +and ten = num_of_int 10 +and neg_ten = num_of_int(-10) +;; + +(* Linear Fractional Transformation *) +module LFT = struct + + let floor_ev (q, r, s, t) x = quo_num (q */ x +/ r) (s */ x +/ t);; + + let unit = (one, zero, zero, one);; + + let comp (q, r, s, t) (q', r', s', t') = + (q */ q' +/ r */ s', q */ r' +/ r */ t', + s */ q' +/ t */ s', s */ r' +/ t */ t') +;; + +end +;; + +let next z = LFT.floor_ev z three +and safe z n = (n =/ LFT.floor_ev z four) +and prod z n = LFT.comp (ten, neg_ten */ n, zero, one) z +and cons z k = + let den = 2 * k + 1 in + LFT.comp z (num_of_int k, num_of_int(2 * den), zero, num_of_int den) +;; + +let rec digit k z n row col = + if n > 0 then + let y = next z in + if safe z y then + if col = 10 then ( + let row = row + 10 in + printf "\t:%i\n%s" row (string_of_num y); + digit k (prod z y) (n-1) row 1 + ) + else ( + print_string(string_of_num y); + digit k (prod z y) (n-1) row (col + 1) + ) + else digit (k + 1) (cons z k) n row col + else + printf "%*s\t:%i\n" (10 - col) "" (row + col) +;; + +let digits n = digit 1 LFT.unit n 0 0 +;; + +let usage () = + prerr_endline "Usage: pi_num <number of digits to compute for pi>"; + exit 2 +;; + +let main () = + let args = Sys.argv in + if Array.length args <> 2 then usage () else + digits (int_of_string Sys.argv.(1)) +;; + +main () +;; diff --git a/otherlibs/num/test/test.ml b/otherlibs/num/test/test.ml new file mode 100644 index 0000000..f26ea82 --- /dev/null +++ b/otherlibs/num/test/test.ml @@ -0,0 +1,82 @@ +open Printf;; + +let flush_all () = flush stdout; flush stderr;; + +let message s = print_string s; print_newline ();; + +let error_occurred = ref false;; +let immediate_failure = ref true;; + +let error () = + if !immediate_failure then exit 2 else begin + error_occurred := true; + flush_all (); + false + end;; + +let success () = flush_all (); true;; + +let function_tested = ref "";; + +let testing_function s = + flush_all (); + function_tested := s; + print_newline(); + message s;; + +let test test_number eq_fun (answer, correct_answer) = + flush_all (); + if not (eq_fun answer correct_answer) then begin + fprintf stderr ">>> Bad result (%s, test %d)\n" !function_tested test_number; + error () + end else begin + printf " %d..." test_number; + success () + end;; + +let failure_test test_number fun_to_test arg = + flush_all (); + try + fun_to_test arg; + fprintf stderr ">>> Failure expected (%s, test %d)\n" + !function_tested test_number; + error () + with _ -> + printf " %d..." test_number; + success ();; + +let failwith_test test_number fun_to_test arg correct_failure = + flush_all (); + try + fun_to_test arg; + fprintf stderr ">>> Failure expected (%s, test %d)\n" + !function_tested test_number; + error () + with x -> + if x = correct_failure then begin + printf " %d..." test_number; + success () + end else begin + fprintf stderr ">>> Bad failure (%s, test %d)\n" + !function_tested test_number; + error () + end;; + +let end_tests () = + flush_all (); + print_newline (); + if !error_occurred then begin + prerr_endline "************* TESTS FAILED ****************"; exit 2 + end else begin + prerr_endline "************* TESTS COMPLETED SUCCESSFULLY ****************"; + exit 0 + end;; + +let eq = (==);; +let eq_int (i: int) (j: int) = (i = j);; +let eq_string (i: string) (j: string) = (i = j);; +let eq_nativeint (i: nativeint) (j: nativeint) = (i = j);; +let eq_int32 (i: int32) (j: int32) = (i = j);; +let eq_int64 (i: int64) (j: int64) = (i = j);; + +let sixtyfour = (1 lsl 31) <> 0;; diff --git a/otherlibs/num/test/test_big_ints.ml b/otherlibs/num/test/test_big_ints.ml new file mode 100644 index 0000000..f3080e5 --- /dev/null +++ b/otherlibs/num/test/test_big_ints.ml @@ -0,0 +1,772 @@ +open Test;; +open Nat;; +open Big_int;; +open Int_misc;; +open List;; + +testing_function "compare_big_int";; + +test 1 +eq_int (compare_big_int zero_big_int zero_big_int, 0);; +test 2 +eq_int (compare_big_int zero_big_int (big_int_of_int 1), (-1));; +test 3 +eq_int (compare_big_int zero_big_int (big_int_of_int (-1)), 1);; +test 4 +eq_int (compare_big_int (big_int_of_int 1) zero_big_int, 1);; +test 5 +eq_int (compare_big_int (big_int_of_int (-1)) zero_big_int, (-1));; +test 6 +eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int 1), 0);; +test 7 +eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), 0);; +test 8 +eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int (-1)), 1);; +test 9 +eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int 1), (-1));; +test 10 +eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int 2), (-1));; +test 11 +eq_int (compare_big_int (big_int_of_int 2) (big_int_of_int 1), 1);; +test 12 +eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), 1);; +test 13 +eq_int (compare_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), (-1));; + + +testing_function "pred_big_int";; + +test 1 +eq_big_int (pred_big_int zero_big_int, big_int_of_int (-1));; +test 2 +eq_big_int (pred_big_int unit_big_int, zero_big_int);; +test 3 +eq_big_int (pred_big_int (big_int_of_int (-1)), big_int_of_int (-2));; + +testing_function "succ_big_int";; + +test 1 +eq_big_int (succ_big_int zero_big_int, unit_big_int);; +test 2 +eq_big_int (succ_big_int unit_big_int, big_int_of_int 2);; +test 3 +eq_big_int (succ_big_int (big_int_of_int (-1)), zero_big_int);; + +testing_function "add_big_int";; + +test 1 +eq_big_int (add_big_int zero_big_int zero_big_int, zero_big_int);; +test 2 +eq_big_int (add_big_int zero_big_int (big_int_of_int 1), + big_int_of_int 1);; +test 3 +eq_big_int (add_big_int (big_int_of_int 1) zero_big_int, + big_int_of_int 1);; +test 4 +eq_big_int (add_big_int zero_big_int (big_int_of_int (-1)), + big_int_of_int (-1));; +test 5 +eq_big_int (add_big_int (big_int_of_int (-1)) zero_big_int, + big_int_of_int (-1));; +test 6 +eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int 1), + big_int_of_int 2);; +test 7 +eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int 2), + big_int_of_int 3);; +test 8 +eq_big_int (add_big_int (big_int_of_int 2) (big_int_of_int 1), + big_int_of_int 3);; +test 9 +eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), + big_int_of_int (-2));; +test 10 +eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), + big_int_of_int (-3));; +test 11 +eq_big_int (add_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), + big_int_of_int (-3));; +test 12 +eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int (-1)), + zero_big_int);; +test 13 +eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int 1), + zero_big_int);; +test 14 +eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int (-2)), + big_int_of_int (-1));; +test 15 +eq_big_int (add_big_int (big_int_of_int (-2)) (big_int_of_int 1), + big_int_of_int (-1));; +test 16 +eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int 2), + big_int_of_int 1);; +test 17 +eq_big_int (add_big_int (big_int_of_int 2) (big_int_of_int (-1)), + big_int_of_int 1);; + + +testing_function "sub_big_int";; + +test 1 +eq_big_int (sub_big_int zero_big_int zero_big_int, zero_big_int);; +test 2 +eq_big_int (sub_big_int zero_big_int (big_int_of_int 1), + big_int_of_int (-1));; +test 3 +eq_big_int (sub_big_int (big_int_of_int 1) zero_big_int, + big_int_of_int 1);; +test 4 +eq_big_int (sub_big_int zero_big_int (big_int_of_int (-1)), + big_int_of_int 1);; +test 5 +eq_big_int (sub_big_int (big_int_of_int (-1)) zero_big_int, + big_int_of_int (-1));; +test 6 +eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int 1), + zero_big_int);; +test 7 +eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int 2), + big_int_of_int (-1));; +test 8 +eq_big_int (sub_big_int (big_int_of_int 2) (big_int_of_int 1), + big_int_of_int 1);; +test 9 +eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), + zero_big_int);; +test 10 +eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), + big_int_of_int 1);; +test 11 +eq_big_int (sub_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), + big_int_of_int (-1));; +test 12 +eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int (-1)), + big_int_of_int 2);; +test 13 +eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int 1), + big_int_of_int (-2));; +test 14 +eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int (-2)), + big_int_of_int 3);; +test 15 +eq_big_int (sub_big_int (big_int_of_int (-2)) (big_int_of_int 1), + big_int_of_int (-3));; +test 16 +eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int 2), + big_int_of_int (-3));; +test 17 +eq_big_int (sub_big_int (big_int_of_int 2) (big_int_of_int (-1)), + big_int_of_int 3);; + +testing_function "mult_int_big_int";; + +test 1 +eq_big_int (mult_int_big_int 0 (big_int_of_int 3), zero_big_int);; +test 2 +eq_big_int (mult_int_big_int 1 (big_int_of_int 3), big_int_of_int 3);; +test 3 +eq_big_int (mult_int_big_int 1 zero_big_int, zero_big_int);; +test 4 +eq_big_int (mult_int_big_int 2 (big_int_of_int 3), big_int_of_int 6);; + +testing_function "mult_big_int";; + +test 1 +eq_big_int (mult_big_int zero_big_int zero_big_int, + zero_big_int);; +test 2 +eq_big_int (mult_big_int (big_int_of_int 2) (big_int_of_int 3), + big_int_of_int 6);; +test 3 +eq_big_int (mult_big_int (big_int_of_int 2) (big_int_of_int (-3)), + big_int_of_int (-6));; +test 4 +eq_big_int (mult_big_int (big_int_of_string "12724951") + (big_int_of_string "81749606400"), + big_int_of_string "1040259735709286400");; +test 5 +eq_big_int (mult_big_int (big_int_of_string "26542080") + (big_int_of_string "81749606400"), + big_int_of_string "2169804593037312000");; + +testing_function "quomod_big_int";; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 1) (big_int_of_int 1) in + test 1 eq_big_int (quotient, big_int_of_int 1) && + test 2 eq_big_int (modulo, zero_big_int);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 1) (big_int_of_int (-1)) in + test 3 eq_big_int (quotient, big_int_of_int (-1)) && + test 4 eq_big_int (modulo, zero_big_int);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int (-1)) (big_int_of_int 1) in + test 5 eq_big_int (quotient, big_int_of_int (-1)) && + test 6 eq_big_int (modulo, zero_big_int);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 3) (big_int_of_int 2) in + test 7 eq_big_int (quotient, big_int_of_int 1) && + test 8 eq_big_int (modulo, big_int_of_int 1);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 5) (big_int_of_int 3) in + test 9 eq_big_int (quotient, big_int_of_int 1) && + test 10 eq_big_int (modulo, big_int_of_int 2);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int (-5)) (big_int_of_int 3) in + test 11 eq_big_int (quotient, big_int_of_int (-2)) && + test 12 eq_big_int (modulo, big_int_of_int 1);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 1) (big_int_of_int 2) in + test 13 eq_big_int (quotient, zero_big_int) && + test 14 eq_big_int (modulo, big_int_of_int 1);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int (-1)) (big_int_of_int 3) in + test 15 eq_big_int (quotient, minus_big_int unit_big_int) && + test 16 eq_big_int (modulo, big_int_of_int 2);; + +failwith_test 17 +(quomod_big_int (big_int_of_int 1)) zero_big_int +Division_by_zero +;; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 10) (big_int_of_int 20) in + test 18 eq_big_int (quotient, big_int_of_int 0) && + test 19 eq_big_int (modulo, big_int_of_int 10);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int (-10)) (big_int_of_int 20) in + test 20 eq_big_int (quotient, big_int_of_int (-1)) && + test 21 eq_big_int (modulo, big_int_of_int 10);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int 10) (big_int_of_int (-20)) in + test 22 eq_big_int (quotient, big_int_of_int 0) && + test 23 eq_big_int (modulo, big_int_of_int 10);; + +let (quotient, modulo) = + quomod_big_int (big_int_of_int (-10)) (big_int_of_int (-20)) in + test 24 eq_big_int (quotient, big_int_of_int 1) && + test 25 eq_big_int (modulo, big_int_of_int 10);; + + +testing_function "gcd_big_int";; + +test 1 +eq_big_int (gcd_big_int zero_big_int zero_big_int, + zero_big_int);; +test 2 +eq_big_int (gcd_big_int zero_big_int (big_int_of_int 1), + big_int_of_int 1);; +test 3 +eq_big_int (gcd_big_int (big_int_of_int 1) zero_big_int, + big_int_of_int 1);; +test 4 +eq_big_int (gcd_big_int (big_int_of_int 1) (big_int_of_int 2), + big_int_of_int 1);; +test 5 +eq_big_int (gcd_big_int (big_int_of_int 2) (big_int_of_int 1), + big_int_of_int 1);; +test 6 +eq_big_int (gcd_big_int (big_int_of_int 1) (big_int_of_int 1), + big_int_of_int 1);; +test 7 +eq_big_int (gcd_big_int (big_int_of_int 9) (big_int_of_int 16), + big_int_of_int 1);; +test 8 +eq_big_int (gcd_big_int (big_int_of_int 12) (big_int_of_int 16), + big_int_of_int 4);; + +for i = 9 to 28 do + let n1 = Random.int 1000000000 + and n2 = Random.int 100000 in + let _ = + test i eq + (int_of_big_int (gcd_big_int (big_int_of_int n1) (big_int_of_int n2)), + gcd_int n1 n2) in + () +done;; + +testing_function "int_of_big_int";; + +test 1 +eq_int (int_of_big_int (big_int_of_int 1), 1);; +test 2 +eq_int (int_of_big_int (big_int_of_int(-1)), -1);; +test 3 +eq_int (int_of_big_int zero_big_int, 0);; +test 4 +eq_int (int_of_big_int (big_int_of_int max_int), max_int);; +test 5 +eq_int (int_of_big_int (big_int_of_int min_int), min_int);; +failwith_test 6 + (fun () -> int_of_big_int (succ_big_int (big_int_of_int max_int))) + () (Failure "int_of_big_int");; +failwith_test 7 + (fun () -> int_of_big_int (pred_big_int (big_int_of_int min_int))) + () (Failure "int_of_big_int");; +failwith_test 8 + (fun () -> int_of_big_int (mult_big_int (big_int_of_int min_int) + (big_int_of_int 2))) + () (Failure "int_of_big_int");; + + +testing_function "is_int_big_int";; + +test 1 +eq (is_int_big_int (big_int_of_int 1), true);; +test 2 +eq (is_int_big_int (big_int_of_int (-1)), true);; +test 3 +eq (is_int_big_int (succ_big_int (big_int_of_int biggest_int)), false);; +test 4 +eq (int_of_big_int (big_int_of_int monster_int), monster_int);; +(* Should be true *) +test 5 +eq (is_int_big_int (big_int_of_string (string_of_int biggest_int)), true);; +test 6 +eq (is_int_big_int (big_int_of_string (string_of_int least_int)), true);; +test 7 +eq (is_int_big_int (big_int_of_string (string_of_int monster_int)), true);; + +(* Should be false *) +(* Successor of biggest_int is not an int *) +test 8 +eq (is_int_big_int (succ_big_int (big_int_of_int (biggest_int))), false);; +test 9 +eq (is_int_big_int + (succ_big_int (succ_big_int (big_int_of_int (biggest_int)))), false);; +(* Negation of monster_int (as a big_int) is not an int *) +test 10 +eq (is_int_big_int + (minus_big_int (big_int_of_string (string_of_int monster_int))), false);; + + +testing_function "sys_string_of_big_int";; + +test 1 +eq_string (string_of_big_int (big_int_of_int 1), "1");; + + +testing_function "big_int_of_string";; + +test 1 +eq_big_int (big_int_of_string "1", big_int_of_int 1);; +test 2 +eq_big_int (big_int_of_string "-1", big_int_of_int (-1));; +test 4 +eq_big_int (big_int_of_string "0", zero_big_int);; + +failwith_test 5 big_int_of_string "sdjdkfighdgf" + (Failure "invalid digit");; + +test 6 +eq_big_int (big_int_of_string "123", big_int_of_int 123);; +test 7 +eq_big_int (big_int_of_string "3456", big_int_of_int 3456);; + +test 9 +eq_big_int (big_int_of_string "-3456", big_int_of_int (-3456));; + + +let implode = List.fold_left (^) "";; (* Au diable l'efficacite *) + +let l = rev [ +"174679877494298468451661416292903906557638850173895426081611831060970135303"; +"044177587617233125776581034213405720474892937404345377707655788096850784519"; +"539374048533324740018513057210881137248587265169064879918339714405948322501"; +"445922724181830422326068913963858377101914542266807281471620827145038901025"; +"322784396182858865537924078131032036927586614781817695777639491934361211399"; +"888524140253852859555118862284235219972858420374290985423899099648066366558"; +"238523612660414395240146528009203942793935957539186742012316630755300111472"; +"852707974927265572257203394961525316215198438466177260614187266288417996647"; +"132974072337956513457924431633191471716899014677585762010115338540738783163"; +"739223806648361958204720897858193606022290696766988489073354139289154127309"; +"916985231051926209439373780384293513938376175026016587144157313996556653811"; +"793187841050456120649717382553450099049321059330947779485538381272648295449"; +"847188233356805715432460040567660999184007627415398722991790542115164516290"; +"619821378529926683447345857832940144982437162642295073360087284113248737998"; +"046564369129742074737760485635495880623324782103052289938185453627547195245"; +"688272436219215066430533447287305048225780425168823659431607654712261368560"; +"702129351210471250717394128044019490336608558608922841794819375031757643448"; +"32" +] in + +let bi1 = big_int_of_string (implode (rev l)) in + +let bi2 = big_int_of_string (implode (rev ("3" :: tl l))) in + +test 10 +eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "10")) + (big_int_of_string "2"))) +(* test 11 + && +eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "10e0")) + (big_int_of_string "20e-1"))) && +test 12 +eq_big_int (minus_big_int bi1, + (add_big_int (mult_big_int bi2 (big_int_of_string "-10e0")) + (big_int_of_string "-20e-1"))) && +test 13 +eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "+10e0")) + (big_int_of_string "+20e-1"))) && +test 14 +eq_big_int (minus_big_int bi1, + (add_big_int (mult_big_int bi2 (big_int_of_string "-10e+0")) + (big_int_of_string "-20e-1"))) && +test 15 +eq_big_int (minus_big_int bi1, + (add_big_int (mult_big_int bi2 (big_int_of_string "-1e+1")) + (big_int_of_string "-2e-0"))) && +test 16 +eq_big_int (minus_big_int bi1, + (add_big_int (mult_big_int bi2 (big_int_of_string "-0.1e+2")) + (big_int_of_string "-2.0e-0"))) && +test 17 +eq_big_int (minus_big_int bi1, + (add_big_int (mult_big_int bi2 (big_int_of_string "-1.000e+1")) + (big_int_of_string "-0.02e2")))*) +;; + +testing_function "power_base_int";; + +test 1 +eq_big_int (big_int_of_nat (power_base_int 10 0), unit_big_int) +;; +test 2 +eq_big_int (big_int_of_nat (power_base_int 10 8), big_int_of_int 100000000) +;; +test 3 +eq_big_int (big_int_of_nat (power_base_int 2 (length_of_int + 2)), + big_int_of_nat (let nat = make_nat 2 in + set_digit_nat nat 1 1; + nat)) +;; + +testing_function "base_power_big_int";; + +test 1 +eq_big_int (base_power_big_int 10 0 (big_int_of_int 2), big_int_of_int 2);; +test 2 +eq_big_int (base_power_big_int 10 2 (big_int_of_int 2), big_int_of_int 200);; +test 3 +eq_big_int (base_power_big_int 10 1 (big_int_of_int 123), big_int_of_int 1230) +;; + +testing_function "power_int_positive_big_int";; + +test 1 +eq_big_int (power_int_positive_big_int 2 (big_int_of_int 10), + big_int_of_int 1024);; +test 2 +eq_big_int + (power_int_positive_big_int 2 (big_int_of_int 65), + big_int_of_string "36893488147419103232");; + +test 3 +eq_big_int + (power_int_positive_big_int 3 (big_int_of_string "47"), + big_int_of_string "26588814358957503287787");; + +test 4 +eq_big_int + (power_int_positive_big_int 1 (big_int_of_string "1000000000000000000000"), + big_int_of_int 1);; + +test 5 +eq_big_int + (power_int_positive_big_int (-1) (big_int_of_string "1000000000000000000000"), + big_int_of_int 1);; + +test 6 +eq_big_int + (power_int_positive_big_int (-1) (big_int_of_string "1000000000000000000001"), + big_int_of_int (-1));; + +test 7 +eq_big_int + (power_int_positive_big_int 0 (big_int_of_string "1000000000000000000000"), + big_int_of_int 0);; + +testing_function "power_big_int_positive_int";; + +test 1 +eq_big_int (power_big_int_positive_int (big_int_of_int 2) 10, + big_int_of_int 1024);; +test 2 +eq_big_int + (power_big_int_positive_int (big_int_of_int 100) 20, + big_int_of_string "10000000000000000000000000000000000000000");; + +test 3 +eq_big_int + (power_big_int_positive_int (big_int_of_string "3") 47, + big_int_of_string "26588814358957503287787");; + +test 4 +eq_big_int + (power_big_int_positive_int (big_int_of_string "200000000000000") 34, + big_int_of_string +"17179869184000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000");; + +test 5 +eq_big_int + (power_big_int_positive_int (big_int_of_string "2197609328765") 243, + big_int_of_string +"12415638672345366257764851943822299490113545698929764576040102857365\ +27920436565335427676982530274588056944387957287793378051852205028658\ +73008292720317554332284838709453634119919368441951233982592586680844\ +20765201140575612595182857026804842796931784944918059630667794516774\ +58498235838834599150657873894983300999081942159304585449505963892008\ +97855706440206825609657816209327492197604711437269361628626691080334\ +38432768885637928268354258860147333786379766583179851226375449161073\ +10396958979998161989562418169797611757651190037273397850239552735199\ +63719988832594486235837899145390948533078339399890545062510060406048\ +61331200657727576638170520036143007285549092686618686739320973444703\ +33342725604091818763255601206325426337211467746377586080108631634250\ +11232258578207762608797108802386708549785680783113606089879687396654\ +54004281165259352412815385041917713969718327109245777066079665194617\ +29230093411050053217775067781725651590160086483960457766025246936489\ +92234225900994076609973190516835778346886551506344097474301175288686\ +25662752919718480402972207084177612056491949911377568680526080633587\ +33230060757162252611388973328501680433819585006035301408574879645573\ +47126018243568976860515247053858204554293343161581801846081341003624\ +22906934772131205632200433218165757307182816260714026614324014553342\ +77303133877636489457498062819003614421295692889321460150481573909330\ +77301946991278225819671075907191359721824291923283322225480199446258\ +03302645587072103949599624444368321734975586414930425964782010567575\ +43333331963876294983400462908871215572514487548352925949663431718284\ +14589547315559936497408670231851521193150991888789948397029796279240\ +53117024758684807981605608837291399377902947471927467827290844733264\ +70881963357258978768427852958888430774360783419404195056122644913454\ +24537375432013012467418602205343636983874410969339344956536142566292\ +67710105053213729008973121773436382170956191942409859915563249876601\ +97309463059908818473774872128141896864070835259683384180928526600888\ +17480854811931632353621014638284918544379784608050029606475137979896\ +79160729736625134310450643341951675749112836007180865039256361941093\ +99844921135320096085772541537129637055451495234892640418746420370197\ +76655592198723057553855194566534999101921182723711243608938705766658\ +35660299983828999383637476407321955462859142012030390036241831962713\ +40429407146441598507165243069127531565881439971034178400174881243483\ +00001434950666035560134867554719667076133414445044258086968145695386\ +00575860256380332451841441394317283433596457253185221717167880159573\ +60478649571700878049257386910142909926740023800166057094445463624601\ +79490246367497489548435683835329410376623483996271147060314994344869\ +89606855219181727424853876740423210027967733989284801813769926906846\ +45570461348452758744643550541290031199432061998646306091218518879810\ +17848488755494879341886158379140088252013009193050706458824793551984\ +39285914868159111542391208521561221610797141925061986437418522494485\ +59871215531081904861310222368465288125816137210222223075106739997863\ +76953125");; + +testing_function "power_big_int_positive_big_int";; + +test 1 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int 2) (big_int_of_int 10), + big_int_of_int 1024);; + +test 2 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int 2) (big_int_of_int 65), + big_int_of_string "36893488147419103232");; + +test 3 +eq_big_int + (power_big_int_positive_big_int + (big_int_of_string "3") (big_int_of_string "47"), + big_int_of_string "26588814358957503287787");; + +test 4 +eq_big_int + (power_big_int_positive_big_int + (big_int_of_string "200000000000000") (big_int_of_int 34), + big_int_of_string +"17179869184000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000000000000000000000000000000000000000000000000000000000000\ +00000000000");; + +test 5 +eq_big_int + (power_big_int_positive_big_int (big_int_of_string "2197609328765") + (big_int_of_string "243"), + big_int_of_string +"12415638672345366257764851943822299490113545698929764576040102857365\ +27920436565335427676982530274588056944387957287793378051852205028658\ +73008292720317554332284838709453634119919368441951233982592586680844\ +20765201140575612595182857026804842796931784944918059630667794516774\ +58498235838834599150657873894983300999081942159304585449505963892008\ +97855706440206825609657816209327492197604711437269361628626691080334\ +38432768885637928268354258860147333786379766583179851226375449161073\ +10396958979998161989562418169797611757651190037273397850239552735199\ +63719988832594486235837899145390948533078339399890545062510060406048\ +61331200657727576638170520036143007285549092686618686739320973444703\ +33342725604091818763255601206325426337211467746377586080108631634250\ +11232258578207762608797108802386708549785680783113606089879687396654\ +54004281165259352412815385041917713969718327109245777066079665194617\ +29230093411050053217775067781725651590160086483960457766025246936489\ +92234225900994076609973190516835778346886551506344097474301175288686\ +25662752919718480402972207084177612056491949911377568680526080633587\ +33230060757162252611388973328501680433819585006035301408574879645573\ +47126018243568976860515247053858204554293343161581801846081341003624\ +22906934772131205632200433218165757307182816260714026614324014553342\ +77303133877636489457498062819003614421295692889321460150481573909330\ +77301946991278225819671075907191359721824291923283322225480199446258\ +03302645587072103949599624444368321734975586414930425964782010567575\ +43333331963876294983400462908871215572514487548352925949663431718284\ +14589547315559936497408670231851521193150991888789948397029796279240\ +53117024758684807981605608837291399377902947471927467827290844733264\ +70881963357258978768427852958888430774360783419404195056122644913454\ +24537375432013012467418602205343636983874410969339344956536142566292\ +67710105053213729008973121773436382170956191942409859915563249876601\ +97309463059908818473774872128141896864070835259683384180928526600888\ +17480854811931632353621014638284918544379784608050029606475137979896\ +79160729736625134310450643341951675749112836007180865039256361941093\ +99844921135320096085772541537129637055451495234892640418746420370197\ +76655592198723057553855194566534999101921182723711243608938705766658\ +35660299983828999383637476407321955462859142012030390036241831962713\ +40429407146441598507165243069127531565881439971034178400174881243483\ +00001434950666035560134867554719667076133414445044258086968145695386\ +00575860256380332451841441394317283433596457253185221717167880159573\ +60478649571700878049257386910142909926740023800166057094445463624601\ +79490246367497489548435683835329410376623483996271147060314994344869\ +89606855219181727424853876740423210027967733989284801813769926906846\ +45570461348452758744643550541290031199432061998646306091218518879810\ +17848488755494879341886158379140088252013009193050706458824793551984\ +39285914868159111542391208521561221610797141925061986437418522494485\ +59871215531081904861310222368465288125816137210222223075106739997863\ +76953125");; + +test 6 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int 1) + (big_int_of_string "1000000000000000000000"), + big_int_of_int 1);; + +test 7 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int (-1)) + (big_int_of_string "1000000000000000000000"), + big_int_of_int 1);; + +test 8 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int (-1)) + (big_int_of_string "1000000000000000000001"), + big_int_of_int (-1));; + +test 9 +eq_big_int + (power_big_int_positive_big_int (big_int_of_int 0) + (big_int_of_string "1000000000000000000000"), + big_int_of_int 0);; + +testing_function "square_big_int";; + +test 1 eq_big_int + (square_big_int (big_int_of_string "0"), big_int_of_string "0");; +test 2 eq_big_int + (square_big_int (big_int_of_string "1"), big_int_of_string "1");; +test 3 eq_big_int + (square_big_int (big_int_of_string "-1"), big_int_of_string "1");; +test 4 eq_big_int + (square_big_int (big_int_of_string "-7"), big_int_of_string "49");; + + +testing_function "big_int_of_nativeint";; + +test 1 eq_big_int + (big_int_of_nativeint 0n, zero_big_int);; +test 2 eq_big_int + (big_int_of_nativeint 1234n, big_int_of_string "1234");; +test 3 eq_big_int + (big_int_of_nativeint (-1234n), big_int_of_string "-1234");; + +testing_function "nativeint_of_big_int";; + +test 1 eq_nativeint + (nativeint_of_big_int zero_big_int, 0n);; +test 2 eq_nativeint + (nativeint_of_big_int (big_int_of_string "1234"), 1234n);; +test 2 eq_nativeint + (nativeint_of_big_int (big_int_of_string "-1234"), -1234n);; + +testing_function "big_int_of_int32";; + +test 1 eq_big_int + (big_int_of_int32 0l, zero_big_int);; +test 2 eq_big_int + (big_int_of_int32 2147483647l, big_int_of_string "2147483647");; +test 3 eq_big_int + (big_int_of_int32 (-2147483648l), big_int_of_string "-2147483648");; + +testing_function "int32_of_big_int";; + +test 1 eq_int32 + (int32_of_big_int zero_big_int, 0l);; +test 2 eq_int32 + (int32_of_big_int (big_int_of_string "2147483647"), 2147483647l);; +test 3 eq_int32 + (int32_of_big_int (big_int_of_string "-2147483648"), -2147483648l);; +test 4 eq_int32 + (int32_of_big_int (big_int_of_string "-2147"), -2147l);; +let should_fail s = + try ignore (int32_of_big_int (big_int_of_string s)); 0 + with Failure _ -> 1;; +test 5 eq_int + (should_fail "2147483648", 1);; +test 6 eq_int + (should_fail "-2147483649", 1);; +test 7 eq_int + (should_fail "4294967296", 1);; +test 8 eq_int + (should_fail "18446744073709551616", 1);; + +testing_function "big_int_of_int64";; + +test 1 eq_big_int + (big_int_of_int64 0L, zero_big_int);; +test 2 eq_big_int + (big_int_of_int64 9223372036854775807L, big_int_of_string "9223372036854775807");; +test 3 eq_big_int + (big_int_of_int64 (-9223372036854775808L), big_int_of_string "-9223372036854775808");; + +testing_function "int64_of_big_int";; + +test 1 eq_int64 + (int64_of_big_int zero_big_int, 0L);; +test 2 eq_int64 + (int64_of_big_int (big_int_of_string "9223372036854775807"), 9223372036854775807L);; +test 3 eq_int64 + (int64_of_big_int (big_int_of_string "-9223372036854775808"), -9223372036854775808L);; +test 4 eq_int64 + (int64_of_big_int (big_int_of_string "-9223372036854775"), -9223372036854775L);; +let should_fail s = + try ignore (int64_of_big_int (big_int_of_string s)); 0 + with Failure _ -> 1;; +test 4 eq_int + (should_fail "9223372036854775808", 1);; +test 5 eq_int + (should_fail "-9223372036854775809", 1);; +test 6 eq_int + (should_fail "18446744073709551616", 1);; diff --git a/otherlibs/num/test/test_bng.c b/otherlibs/num/test/test_bng.c new file mode 100644 index 0000000..f14e1f0 --- /dev/null +++ b/otherlibs/num/test/test_bng.c @@ -0,0 +1,408 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2003 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: test_bng.c,v 1.2 2003-11-07 07:59:10 xleroy Exp $ */ + +/* Test harness for the BNG primitives. Use BigNum as a reference. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <BigNum.h> + +#include "../../../config/m.h" +#include "bng.h" + +#if defined(__GNUC__) && BNG_ASM_LEVEL > 0 +#if defined(BNG_ARCH_ia32) +#include "bng_ia32.c" +#elif defined(BNG_ARCH_amd64) +#include "bng_amd64.c" +#elif defined(BNG_ARCH_ppc) +#include "bng_ppc.c" +#elif defined (BNG_ARCH_alpha) +#include "bng_alpha.c" +#elif defined (BNG_ARCH_sparc) +#include "bng_sparc.c" +#elif defined (BNG_ARCH_mips) +#include "bng_mips.c" +#endif +#endif + +#include "bng_digit.c" + +/* Random generator for digits. Can either generate "true" PRN numbers + or numbers consisting of long sequences of 0 and 1 bits. */ + +static int rand_skewed = 0; +static int rand_runlength = 0; +static int rand_bit = 0; +static bngdigit rand_seed = 0; + +static bngdigit randdigit(void) +{ + bngdigit res; + int i; + + if (rand_skewed) { + for (i = 0, res = 0; i < BNG_BITS_PER_DIGIT; i++) { + if (rand_runlength == 0) { + rand_runlength = 1 + (rand() % (2 * BNG_BITS_PER_DIGIT)); + rand_bit ^= 1; + } + res = (res << 1) | rand_bit; + rand_runlength--; + } + return res; + } else { + rand_seed = rand_seed * 69069 + 25173; + return rand_seed; + } +} + +/* Test the operations on digits. + This uses double-width integer arithmetic as reference. + This is only available on 32-bit platforms that support a 64-bit int type. +*/ + +#if defined(ARCH_UINT64_TYPE) && !defined(ARCH_SIXTYFOUR) + +typedef ARCH_UINT64_TYPE dbldigit; + +static int test_digit_ops(int i) +{ + bngdigit a1, a2, a3, r1, r2; + int ci, co, n; + + a1 = randdigit(); + a2 = randdigit(); + a3 = randdigit(); + ci = randdigit() & 1; + + BngAdd2(r1,co,a1,a2); + if ((dbldigit) r1 + ((dbldigit) co << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 + (dbldigit) a2) { + printf("Round %d, BngAdd2(%lx,%x,%lx, %lx)\n", i, r1, co, a1, a2); + return 1; + } + + BngAdd2Carry(r1,co,a1,a2,ci); + if ((dbldigit) r1 + ((dbldigit) co << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 + (dbldigit) a2 + (dbldigit) ci) { + printf("Round %d, BngAdd2Carry(%lx,%x,%lx, %lx, %x)\n", i, r1, co, a1, a2, ci); + return 1; + } + + r2 = 0; + BngAdd3(r1,r2,a1,a2,a3); + if ((dbldigit) r1 + ((dbldigit) r2 << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 + (dbldigit) a2 + (dbldigit) a3) { + printf("Round %d, BngAdd3(%lx,%x,%lx, %lx, %lx)\n", i, r1, co, a1, a2, a3); + return 1; + } + + BngSub2(r1,co,a1,a2); + if ((dbldigit) r1 - ((dbldigit) co << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 - (dbldigit) a2) { + printf("Round %d, BngSub2(%lx,%x,%lx, %lx)\n", i, r1, co, a1, a2); + return 1; + } + + BngSub2Carry(r1,co,a1,a2,ci); + if ((dbldigit) r1 - ((dbldigit) co << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 - (dbldigit) a2 - (dbldigit) ci) { + printf("Round %d, BngSub2Carry(%lx,%x,%lx, %lx, %x)\n", i, r1, co, a1, a2, ci); + return 1; + } + + r2 = 0; + BngSub3(r1,r2,a1,a2,a3); + if ((dbldigit) r1 - ((dbldigit) r2 << BNG_BITS_PER_DIGIT) + != (dbldigit) a1 - (dbldigit) a2 - (dbldigit) a3) { + printf("Round %d, BngSub3(%lx,%x,%lx, %lx, %lx)\n", i, r1, co, a1, a2, a3); + return 1; + } + + BngMult(r1,r2,a1,a2); + if ((((dbldigit) r1 << BNG_BITS_PER_DIGIT) | (dbldigit) r2) + != (dbldigit) a1 * (dbldigit) a2) { + printf("Round %d, BngMult(%lx,%lx,%lx, %lx)\n", i, r1, r2, a1, a2); + return 1; + } + + /* Make sure a3 is normalized */ + a3 |= 1L << (BNG_BITS_PER_DIGIT - 1); + if (a1 < a3) { + BngDiv(r1,r2,a1,a2,a3); + if (r1 != (((dbldigit) a1 << BNG_BITS_PER_DIGIT) | (dbldigit) a2) / a3 + || + r2 != (((dbldigit) a1 << BNG_BITS_PER_DIGIT) | (dbldigit) a2) % a3) + { + printf("Round %d, BngDiv(%lx,%lx,%lx, %lx, %lx)\n", i, r1, r2, a1, a2, a3); + return 1; + } + } + + n = bng_leading_zero_bits(a1); + if (a1 == 0) { + if (n != BNG_BITS_PER_DIGIT) { + printf("Round %d, bng_leading_zero(bits(%lx) = %d", i, a1, n); + return 1; + } + } else { + if ((a1 << n) >> n != a1 || + ((a1 << n) & (1L << (BNG_BITS_PER_DIGIT - 1))) == 0) { + printf("Round %d, bng_leading_zero(bits(%lx) = %d", i, a1, n); + return 1; + } + } + return 0; +} + +#endif + +/* Test the bng operations. Use BigNum as a reference. */ + +#define MAX_DIGITS 32 + +void randbng(bng a, bngsize n) +{ + int i; + for (i = 0; i < n; i++) a[i] = randdigit(); +} + +char * bng2string(bng a, bngsize n) +{ + char * buffer = malloc((BNG_BITS_PER_DIGIT / 4 + 1) * MAX_DIGITS); + char temp[BNG_BITS_PER_DIGIT / 4 + 1]; + int i; + + buffer[0] = 0; + for (i = n - 1; i >= 0; i--) { + sprintf(temp, "%lx", a[i]); + strcat(buffer, temp); + if (i > 0) strcat(buffer, "_"); + } + return buffer; +} + +int bngsame(bng a, bng b, bngsize n) +{ + int i; + for (i = 0; i < n; i++) + if (a[i] != b[i]) return 0; + return 1; +} + +int test_bng_ops(int i) +{ + bngsize p, q; + bngdigit a[MAX_DIGITS], b[MAX_DIGITS], c[MAX_DIGITS], d[MAX_DIGITS]; + bngdigit f[2 * MAX_DIGITS], g[2 * MAX_DIGITS], h[2 * MAX_DIGITS]; + bngcarry ci, co, cp; + bngdigit dg, do_, dp; + int amount; + + /* Determine random lengths p and q between 1 and MAX_DIGITS. + Ensure p >= q. */ + p = 1 + (rand() % MAX_DIGITS); + q = 1 + (rand() % MAX_DIGITS); + if (q > p) { bngsize t = p; p = q; q = t; } + + /* Randomly generate bignums a of size p, b of size q */ + randbng(a, p); + randbng(b, q); + ci = rand() & 1; + + /* comparison */ + co = bng_compare(a, p, b, q); + cp = BnnCompare(a, p, b, q); + if (co != cp) { + printf("Round %d, bng_compare(%s, %ld, %s, %ld) = %d\n", + i, bng2string(a, p), p, bng2string(b, q), q, co); + return 1; + } + co = bng_compare(b, q, a, p); + cp = BnnCompare(b, q, a, p); + if (co != cp) { + printf("Round %d, bng_compare(%s, %ld, %s, %ld) = %d\n", + i, bng2string(b, q), q, bng2string(a, p), p, co); + return 1; + } + /* add carry */ + bng_assign(c, a, p); + co = bng_add_carry(c, p, ci); + BnnAssign(d, a, p); + cp = BnnAddCarry(d, p, ci); + if (co != cp || !bngsame(c, d, p)) { + printf("Round %d, bng_add_carry(%s, %ld, %d) -> %s, %d\n", + i, bng2string(a, p), p, ci, bng2string(c, p), co); + return 1; + } + /* add */ + bng_assign(c, a, p); + co = bng_add(c, p, b, q, ci); + BnnAssign(d, a, p); + cp = BnnAdd(d, p, b, q, ci); + if (co != cp || !bngsame(c, d, p)) { + printf("Round %d, bng_add(%s, %ld, %s, %ld, %d) -> %s, %d\n", + i, bng2string(a, p), p, bng2string(b, q), q, ci, + bng2string(c, p), co); + return 1; + } + /* sub carry */ + bng_assign(c, a, p); + co = bng_sub_carry(c, p, ci); + BnnAssign(d, a, p); + cp = BnnSubtractBorrow(d, p, ci ^ 1) ^ 1; + if (co != cp || !bngsame(c, d, p)) { + printf("Round %d, bng_sub_carry(%s, %ld, %d) -> %s, %d\n", + i, bng2string(a, p), p, ci, bng2string(c, p), co); + return 1; + } + /* sub */ + bng_assign(c, a, p); + co = bng_sub(c, p, b, q, ci); + BnnAssign(d, a, p); + cp = BnnSubtract(d, p, b, q, ci ^ 1) ^ 1; + if (co != cp || !bngsame(c, d, p)) { + printf("Round %d, bng_sub(%s, %ld, %s, %ld, %d) -> %s, %d\n", + i, bng2string(a, p), p, bng2string(b, q), q, ci, + bng2string(c, p), co); + return 1; + } + /* shift left */ + amount = rand() % BNG_BITS_PER_DIGIT; + bng_assign(c, a, p); + do_ = bng_shift_left(c, p, amount); + BnnAssign(d, a, p); + dp = BnnShiftLeft(d, p, amount); + if (do_ != dp || !bngsame(c, d, p)) { + printf("Round %d, bng_shift_left(%s, %ld, %d) -> %s, %ld\n", + i, bng2string(a, p), p, amount, bng2string(c, p), do_); + return 1; + } + /* shift right */ + amount = rand() % BNG_BITS_PER_DIGIT; + bng_assign(c, a, p); + do_ = bng_shift_right(c, p, amount); + BnnAssign(d, a, p); + dp = BnnShiftRight(d, p, amount); + if (do_ != dp || !bngsame(c, d, p)) { + printf("Round %d, bng_shift_right(%s, %ld, %d) -> %s, %ld\n", + i, bng2string(a, p), p, amount, bng2string(c, p), do_); + return 1; + } + /* mult_add_digit */ + dg = randdigit(); + if (p >= q + 1) { + bng_assign(c, a, p); + co = bng_mult_add_digit(c, p, b, q, dg); + BnnAssign(d, a, p); + cp = BnnMultiplyDigit(d, p, b, q, dg); + if (co != cp || !bngsame(c, d, p)) { + printf("Round %d, bng_mult_add_digit(%s, %ld, %s, %ld, %ld) -> %s, %d\n", + i, bng2string(a, p), p, bng2string(b, q), q, dg, + bng2string(c, p), co); + return 1; + } + } + /* mult_sub_digit */ + dg = randdigit(); + bng_assign(c, a, p); + do_ = bng_mult_add_digit(c, p, b, q, dg); + bng_assign(d, c, p); + dp = bng_mult_sub_digit(d, p, b, q, dg); + if (do_ != dp || !bngsame(a, d, p)) { + printf("Round %d, bng_mult_sub_digit(%s, %ld, %s, %ld, %ld) -> %s, %ld\n", + i, bng2string(c, p), p, bng2string(b, q), q, dg, + bng2string(d, p), dp); + return 1; + } + /* mult_add */ + randbng(f, 2*p); + bng_assign(g, f, 2*p); + co = bng_mult_add(g, 2*p, a, p, b, q); + BnnAssign(h, f, 2*p); + cp = BnnMultiply(h, 2*p, a, p, b, q); + if (co != cp || !bngsame(g, h, 2*p)) { + printf("Round %d, bng_mult_add(%s, %ld, %s, %ld, %s, %ld) -> %s, %d\n", + i, bng2string(f, 2*p), 2*p, + bng2string(a, p), p, + bng2string(b, q), q, + bng2string(g, 2*p), co); + return 1; + } + /* square_add */ + randbng(f, 2*p); + bng_assign(g, f, 2*p); + co = bng_square_add(g, 2*p, b, q); + BnnAssign(h, f, 2*p); + cp = BnnAdd(h, 2*p, h, 2*p); + cp += BnnMultiply(h, 2*p, b, q, b, q); + if (co != cp || !bngsame(g, h, 2*p)) { + printf("Round %d, bng_square_add(%s, %ld, %s, %ld) -> %s, %d\n", + i, bng2string(f, 2*p), 2*p, + bng2string(b, q), q, + bng2string(g, 2*p), co); + return 1; + } + /* div_rem_digit */ + if (a[p - 1] < dg) { + do_ = bng_div_rem_digit(c, a, p, dg); + dp = BnnDivideDigit(d, a, p, dg); + if (do_ != dp || !bngsame(c, d, p-1)) { + printf("Round %d, bng_div_rem_digit(%s, %s, %ld, %lx) -> %lx\n", + i, bng2string(d, p-1), bng2string(a, p), p, dg, do_); + return 1; + } + } + /* div_rem */ + if (p > q && a[p - 1] < b[q - 1]) { + bng_assign(c, a, p); + bng_div_rem(c, p, b, q); + BnnAssign(d, a, p); + BnnDivide(d, p, b, q); + if (!bngsame(c, d, p)) { + printf("Round %d, bng_div_rem(%s, %ld, %s, %ld) -> %s, %s\n", + i, bng2string(a, p), p, bng2string(b, q), q, + bng2string(c + q, p - q), + bng2string(c, q)); + return 1; + } + } + return 0; +} + +int main(int argc, char ** argv) +{ + int niter = 100000; + int i, err; + + bng_init(); + if (argc >= 2) niter = atoi(argv[1]); +#if defined(ARCH_UINT64_TYPE) && !defined(ARCH_SIXTYFOUR) + printf("Testing single-digit operations\n"); + for (err = 0, i = 1; i < niter; i++) err += test_digit_ops(i); + printf("%d rounds performed, %d errors found\n", niter, err); +#endif + printf("Testing bignum operations\n"); + for (err = 0, i = 1; i < niter; i++) err += test_bng_ops(i); + printf("%d rounds performed, %d errors found\n", niter, err); + printf("Testing bignum operations with skewed PRNG\n"); + rand_skewed = 1; + for (err = 0, i = 1; i < niter; i++) err += test_bng_ops(i); + printf("%d rounds performed, %d errors found\n", niter, err); + return 0; +} diff --git a/otherlibs/num/test/test_io.ml b/otherlibs/num/test/test_io.ml new file mode 100644 index 0000000..1df11a5 --- /dev/null +++ b/otherlibs/num/test/test_io.ml @@ -0,0 +1,64 @@ +open Test +open Nat +open Big_int +open Num + +let intern_extern obj = + let f = Filename.temp_file "testnum" ".data" in + let oc = open_out_bin f in + output_value oc obj; + close_out oc; + let ic = open_in_bin f in + let res = input_value ic in + close_in ic; + Sys.remove f; + res +;; + +testing_function "output_value/input_value on nats";; + +let equal_nat n1 n2 = + eq_nat n1 0 (length_nat n1) n2 0 (length_nat n2) +;; + +List.iter + (fun (i, s) -> + let n = nat_of_string s in + ignore(test i equal_nat (n, intern_extern n))) + [1, "0"; + 2, "1234"; + 3, "8589934592"; + 4, "340282366920938463463374607431768211455"; + 5, String.make 100 '3'; + 6, String.make 1000 '9'; + 7, String.make 20000 '8'] +;; + +testing_function "output_value/input_value on big ints";; + +List.iter + (fun (i, s) -> + let b = big_int_of_string s in + ignore(test i eq_big_int (b, intern_extern b))) + [1, "0"; + 2, "1234"; + 3, "-1234"; + 4, "1040259735709286400"; + 5, "-" ^ String.make 20000 '7'] +;; + +testing_function "output_value/input_value on nums";; + +List.iter + (fun (i, s) -> + let n = num_of_string s in + ignore(test i eq_num (n, intern_extern n))) + [1, "0"; + 2, "1234"; + 3, "-1234"; + 4, "159873568791325097646845892426782"; + 5, "1/4"; + 6, "-15/2"; + 7, "159873568791325097646845892426782/24098772507410987265987"; + 8, String.make 10000 '3' ^ "/" ^ String.make 5000 '7'] +;; diff --git a/otherlibs/num/test/test_nats.ml b/otherlibs/num/test/test_nats.ml new file mode 100644 index 0000000..923086e --- /dev/null +++ b/otherlibs/num/test/test_nats.ml @@ -0,0 +1,146 @@ +open Test;; +open Nat;; + +(* Can compare nats less than 2**32 *) +let equal_nat n1 n2 = + eq_nat n1 0 (num_digits_nat n1 0 1) + n2 0 (num_digits_nat n2 0 1);; + +testing_function "num_digits_nat";; + +test (-1) eq (false,not true);; +test 0 eq (true,not false);; + +test 1 +eq_int +(let r = make_nat 2 in + set_digit_nat r 1 1; + num_digits_nat r 0 1,1);; + +testing_function "length_nat";; + +test 1 +eq_int +(let r = make_nat 2 in + set_digit_nat r 0 1; + length_nat r,2);; + +testing_function "equal_nat";; + +let zero_nat = make_nat 1 in + +test 1 +equal_nat (zero_nat,zero_nat);; +test 2 +equal_nat (nat_of_int 1,nat_of_int 1);; + +test 3 +equal_nat (nat_of_string "2",nat_of_string "2");; +test 4 +eq (equal_nat (nat_of_string "2")(nat_of_string "3"),false);; + +testing_function "incr_nat";; + +let zero = nat_of_int 0 in +let res = incr_nat zero 0 1 1 in + test 1 + equal_nat (zero, nat_of_int 1) && + test 2 + eq (res,0);; + +let n = nat_of_int 1 in +let res = incr_nat n 0 1 1 in + test 3 + equal_nat (n, nat_of_int 2) && + test 4 + eq (res,0);; + + +testing_function "decr_nat";; + +let n = nat_of_int 1 in +let res = decr_nat n 0 1 0 in + test 1 + equal_nat (n, nat_of_int 0) && + test 2 + eq (res,1);; + +let n = nat_of_int 2 in +let res = decr_nat n 0 1 0 in + test 3 + equal_nat (n, nat_of_int 1) && + test 4 + eq (res,1);; + +testing_function "is_zero_nat";; + +let n = nat_of_int 1 in +test 1 eq (is_zero_nat n 0 1,false) && +test 2 eq (is_zero_nat (make_nat 1) 0 1, true) && +test 3 eq (is_zero_nat (make_nat 2) 0 2, true) && +(let r = make_nat 2 in + set_digit_nat r 1 1; + test 4 eq (is_zero_nat r 0 1, true)) +;; + +testing_function "string_of_nat";; + +let n = make_nat 4;; + +test 1 eq_string (string_of_nat n, "0");; + +complement_nat n 0 (if sixtyfour then 2 else 4);; + +test 2 eq_string (string_of_nat n, "340282366920938463463374607431768211455");; + +testing_function "string_of_nat && nat_of_string";; + +for i = 1 to 20 do + let s = String.make i '0' in + String.set s 0 '1'; + ignore (test i eq_string (string_of_nat (nat_of_string s), s)) +done;; + +let set_mult_digit_nat n1 d1 l1 n2 d2 l2 n3 d3 = + ignore (mult_digit_nat n1 d1 l1 n2 d2 l2 n3 d3) +;; + +let s = "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" in +test 21 equal_nat ( +nat_of_string s, +(let nat = make_nat 15 in + set_digit_nat nat 0 3; + set_mult_digit_nat nat 0 15 + (nat_of_string (String.sub s 0 135)) 0 14 + (nat_of_int 10) 0; + nat)) +;; + +test 22 eq_string (string_of_nat(nat_of_string "1073741824"), "1073741824");; + +testing_function "gcd_nat";; + +for i = 1 to 20 do + let n1 = Random.int 1000000000 + and n2 = Random.int 100000 in + let nat1 = nat_of_int n1 + and nat2 = nat_of_int n2 in + ignore (gcd_nat nat1 0 1 nat2 0 1); + ignore (test i eq (int_of_nat nat1, Int_misc.gcd_int n1 n2)) +done +;; + +testing_function "sqrt_nat";; + +test 1 equal_nat (sqrt_nat (nat_of_int 1) 0 1, nat_of_int 1);; +test 2 equal_nat (let n = nat_of_string "8589934592" in + sqrt_nat n 0 (length_nat n), + nat_of_string "92681");; +test 3 equal_nat (let n = nat_of_string "4294967295" in + sqrt_nat n 0 (length_nat n), + nat_of_string "65535");; +test 4 equal_nat (let n = nat_of_string "18446744065119617025" in + sqrt_nat n 0 (length_nat n), + nat_of_string "4294967295");; +test 5 equal_nat (sqrt_nat (nat_of_int 15) 0 1, + nat_of_int 3);; diff --git a/otherlibs/num/test/test_nums.ml b/otherlibs/num/test/test_nums.ml new file mode 100644 index 0000000..4242858 --- /dev/null +++ b/otherlibs/num/test/test_nums.ml @@ -0,0 +1,220 @@ +open Test;; +open Nat;; +open Big_int;; +open Ratio;; +open Int_misc;; +open Num;; +open Arith_status;; + +testing_function "add_num";; + +test 1 +eq_num (add_num (Int 1) (Int 3), Int 4);; +test 2 +eq_num (add_num (Int 1) (Big_int (big_int_of_int 3)), Int 4);; +test 3 +eq_num (add_num (Int 1) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "7/4"));; +test 4 +eq_num (add_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "7/4"));; +test 5 +eq_num (add_num (Big_int (big_int_of_int 1)) (Big_int (big_int_of_int 3)), + Int 4);; +test 6 +eq_num (add_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "7/4"));; +test 7 +eq_num (add_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "17/12"));; +test 8 +eq_num (add_num (Int least_int) (Int 1), + Int (- (pred biggest_int)));; +test 9 +eq_num (add_num (Int biggest_int) (Int 1), + Big_int (minus_big_int (pred_big_int (big_int_of_int least_int))));; + +testing_function "sub_num";; + +test 1 +eq_num (sub_num (Int 1) (Int 3), Int (-2));; +test 2 +eq_num (sub_num (Int 1) (Big_int (big_int_of_int 3)), Int (-2));; +test 3 +eq_num (sub_num (Int 1) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "1/4"));; +test 4 +eq_num (sub_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "1/4"));; +test 5 +eq_num (sub_num (Big_int (big_int_of_int 1)) (Big_int (big_int_of_int 3)), + Int (-2));; +test 7 +eq_num (sub_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "1/4"));; +test 8 +eq_num (sub_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "-1/12"));; +test 9 +eq_num (sub_num (Int least_int) (Int (-1)), + Int (- (pred biggest_int)));; +test 10 +eq_num (sub_num (Int (-1)) (Int biggest_int), pred_num (Int least_int));; + +testing_function "mult_num";; + +test 1 +eq_num (mult_num (Int 2) (Int 3), Int 6);; +test 2 +eq_num (mult_num (Int 127) (Int (int_of_string "257")), + Int (int_of_string "32639"));; +test 3 +eq_num (mult_num (Int 257) (Int (int_of_string "260")), + Big_int (big_int_of_string "66820"));; +test 4 +eq_num (mult_num (Int 2) (Big_int (big_int_of_int 3)), Int 6);; +test 5 +eq_num (mult_num (Int 10) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "15/2"));; +test 6 +eq_num (mult_num (Big_int (big_int_of_int 10)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "15/2"));; +test 7 +eq_num (mult_num (Big_int (big_int_of_int 2)) (Big_int (big_int_of_int 3)), + Int 6);; +test 8 +eq_num (mult_num (Big_int (big_int_of_int 10)) (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "15/2"));; +test 9 +eq_num (mult_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")) + , Ratio (ratio_of_string "1/2"));; + +testing_function "div_num";; + +test 1 +eq_num (div_num (Int 6) (Int 3), Int 2);; +test 2 +eq_num (div_num (Int (int_of_string "32639")) + (Int (int_of_string "257")), Int 127);; +test 3 +eq_num (div_num (Big_int (big_int_of_string "66820")) + (Int (int_of_string "257")), + Int 260);; +test 4 +eq_num (div_num (Int 6) (Big_int (big_int_of_int 3)), Int 2);; +test 5 +eq_num (div_num (Ratio (ratio_of_string "15/2")) + (Int 10), + Ratio (ratio_of_string "3/4"));; +test 6 +eq_num (div_num (Big_int (big_int_of_int 6)) (Big_int (big_int_of_int 3)), + Int 2);; +test 7 +eq_num (div_num (Ratio (ratio_of_string "15/2")) + (Big_int (big_int_of_int 10)), + Ratio (ratio_of_string "3/4"));; +test 8 +eq_num (div_num (Ratio (ratio_of_string "15/2")) + (Ratio (ratio_of_string "3/4")), + Big_int (big_int_of_int 10));; +test 9 +eq_num (div_num (Ratio (ratio_of_string "1/2")) + (Ratio (ratio_of_string "3/4")), + Ratio (ratio_of_string "2/3"));; + +testing_function "is_integer_num";; + +test 1 +eq (is_integer_num (Int 3),true);; +test 2 +eq (is_integer_num (Big_int (big_int_of_string "1234567890")),true);; +test 3 +eq (not (is_integer_num (Ratio (ratio_of_string "1/2"))),true);; +test 4 +eq (is_integer_num (Ratio (ratio_of_string "1073774590/32770")),true);; + +testing_function "num_of_ratio";; + +test 1 +eq_num (num_of_ratio (ratio_of_string "4/2"), Int 2);; +test 2 +eq_num (num_of_ratio (ratio_of_string "11811160075/11"), + Big_int (big_int_of_string "1073741825"));; +test 3 +eq_num (num_of_ratio (ratio_of_string "123456789012/1234"), + Ratio (ratio_of_string "61728394506/617"));; + +testing_function "num_of_string";; + +test 1 +eq_num (num_of_string "123/3456", Ratio (ratio_of_string "123/3456"));; +(********* +test 2 +eq_num (num_of_string "12.3/34.56", Ratio (ratio_of_string "1230/3456"));; +test 3 +eq_num (num_of_string "1.23/325.6", Ratio (ratio_of_string "123/32560"));; +test 4 +eq_num (num_of_string "12.3/345.6", Ratio (ratio_of_string "123/3456"));; +set_error_when_null_denominator false;; +test 5 +eq_num (num_of_string "12.3/0.0", Ratio (ratio_of_string "123/0"));; +test 6 +eq_num (num_of_string "0/0", Ratio (ratio_of_string "0/0"));; +set_error_when_null_denominator true;; +*********) +test 7 +eq_num (num_of_string "1234567890", + Big_int (big_int_of_string "1234567890"));; +test 8 +eq_num (num_of_string "12345", Int (int_of_string "12345"));; +(********* +test 9 +eq_num (num_of_string "0.23", Ratio (ratio_of_string "23/100"));; +test 10 +eq_num (num_of_string "0.23", Ratio (ratio_of_string "0.23/1"));; +********) + +failwith_test 11 +num_of_string ("frlshjkurty") (Failure "num_of_string");; + +(******* + +testing_function "immediate numbers";; + +standard arith false;; + +let x = (1/2) in +test 0 eq_string (string_of_num x, "1/2");; + +let y = 12345678901 in +test 1 eq_string (string_of_num y, "12345678901");; +testing_function "immediate numbers";; + +let x = (1/2) in +test 0 eq_string (string_of_num x, "1/2");; + +let y = 12345678901 in +test 1 eq_string (string_of_num y, "12345678901");; + +testing_function "pattern_matching on nums";; + +let f1 = function 0 -> true | _ -> false;; + +test 1 eq (f1 0, true);; + +test 2 eq (f1 1, false);; + +test 3 eq (f1 (0/1), true);; + +test 4 eq (f1 (let n = num_of_string "2000000000000000000000000" in n-n) , + true);; + +test 5 eq (f1 (let n = num_of_string "2000000000000000000000000" in n/n-1) , + true);; + +test 6 eq (f1 (let n = num_of_string "2000000000000000000000000" in n+1) , + false);; + +test 7 eq (f1 (1/2), false);; + +**************) diff --git a/otherlibs/num/test/test_ratios.ml b/otherlibs/num/test/test_ratios.ml new file mode 100644 index 0000000..df2001f --- /dev/null +++ b/otherlibs/num/test/test_ratios.ml @@ -0,0 +1,1177 @@ +open Test;; +open Nat;; +open Big_int;; +open Ratio;; +open Int_misc;; +open Arith_status;; + +set_error_when_null_denominator false +;; + +let infinite_failure = "infinite or undefined rational number";; + +testing_function "create_ratio" +;; + +let r = create_ratio (big_int_of_int 1) (big_int_of_int (-2)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 2) +;; + +let r = create_ratio (big_int_of_int 2) (big_int_of_int 3) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) && +test 4 eq_big_int (denominator_ratio r, big_int_of_int 3) +;; + +set_normalize_ratio true +;; + +let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in +test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && +test 6 eq_big_int (denominator_ratio r, big_int_of_int 4) +;; + +set_normalize_ratio false +;; + +let r = create_ratio (big_int_of_int 0) (big_int_of_int 0) in +test 7 eq_big_int (numerator_ratio r, big_int_of_int 0) && +test 8 eq_big_int (denominator_ratio r, big_int_of_int 0) +;; + +testing_function "create_normalized_ratio" +;; + +let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int (-2)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 2) +;; + +let r = create_normalized_ratio (big_int_of_int 2) (big_int_of_int 3) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) && +test 4 eq_big_int (denominator_ratio r, big_int_of_int 3) +;; + +set_normalize_ratio true +;; + +let r = create_normalized_ratio (big_int_of_int 12) (big_int_of_int (-16)) in +test 5 eq_big_int (numerator_ratio r, big_int_of_int (-12)) && +test 6 eq_big_int (denominator_ratio r, big_int_of_int 16) +;; + +set_normalize_ratio false +;; + +let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int 0) in +test 7 eq_big_int (numerator_ratio r, big_int_of_int 1) && +test 8 eq_big_int (denominator_ratio r, big_int_of_int 0) +;; + +let r = create_normalized_ratio (big_int_of_int 0) (big_int_of_int 0) in +test 9 eq_big_int (numerator_ratio r, big_int_of_int 0) && +test 10 eq_big_int (denominator_ratio r, big_int_of_int 0) +;; + +testing_function "null_denominator" +;; + +test 1 + eq (null_denominator (create_ratio (big_int_of_int 1) (big_int_of_int (-2))), + false) +;; +test 2 eq + (null_denominator (create_ratio (big_int_of_int 1) zero_big_int),true) +;; + +(***** +testing_function "verify_null_denominator" +;; + +test 1 + eq (verify_null_denominator (ratio_of_string "0/1"), false) +;; +test 2 + eq (verify_null_denominator (ratio_of_string "0/0"), true) +;; +*****) + +testing_function "sign_ratio" +;; + +test 1 +eq_int (sign_ratio (create_ratio (big_int_of_int (-2)) (big_int_of_int (-3))), + 1) +;; +test 2 +eq_int (sign_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-3))), + (-1)) +;; +test 3 +eq_int (sign_ratio (create_ratio zero_big_int (big_int_of_int (-3))), 0) +;; + +testing_function "normalize_ratio" +;; + +let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in +ignore (normalize_ratio r); +test 1 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 4) +;; + +let r = create_ratio (big_int_of_int (-1)) zero_big_int in +ignore (normalize_ratio r); +test 3 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && +test 4 eq_big_int (denominator_ratio r, zero_big_int) +;; + +testing_function "report_sign_ratio" +;; + +test 1 +eq_big_int (report_sign_ratio + (create_ratio (big_int_of_int 2) (big_int_of_int (-3))) + (big_int_of_int 1), + big_int_of_int (-1)) +;; +test 2 +eq_big_int (report_sign_ratio + (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (big_int_of_int 1), + big_int_of_int 1) +;; + +testing_function "is_integer_ratio" +;; + +test 1 eq + (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-1))), + true) +;; +test 2 eq + (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)), + false) +;; + +testing_function "add_ratio" +;; + +let r = add_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2)) + (create_ratio (big_int_of_int 2) (big_int_of_int 3)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int 7) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 6) +;; + +let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int 1) && +test 4 eq_big_int (denominator_ratio r, big_int_of_int 6) +;; + +let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in +test 5 eq_big_int (numerator_ratio r, big_int_of_int 4) && +test 6 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 7 eq_big_int (numerator_ratio r, big_int_of_int 3) && +test 8 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 9 eq_big_int (numerator_ratio r, zero_big_int) && +test 10 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = add_ratio (create_ratio (big_int_of_string "12724951") + (big_int_of_string "26542080")) + (create_ratio (big_int_of_string "-1") + (big_int_of_string "81749606400")) in +test 11 eq_big_int (numerator_ratio r, + big_int_of_string "1040259735682744320") && +test 12 eq_big_int (denominator_ratio r, + big_int_of_string "2169804593037312000") +;; + +let r1,r2 = + (create_ratio (big_int_of_string "12724951") + (big_int_of_string "26542080"), + create_ratio (big_int_of_string "-1") + (big_int_of_string "81749606400")) in + +let bi1 = mult_big_int (numerator_ratio r1) (denominator_ratio r2) +and bi2 = mult_big_int (numerator_ratio r2) (denominator_ratio r1) +in +test 1 +eq_big_int (bi1, + big_int_of_string "1040259735709286400") +&& +test 2 +eq_big_int (bi2, + big_int_of_string "-26542080") +&& test 3 +eq_big_int (mult_big_int (denominator_ratio r1) (denominator_ratio r2), + big_int_of_string "2169804593037312000") +&& test 4 +eq_big_int (add_big_int bi1 bi2, + big_int_of_string "1040259735682744320") +;; + +testing_function "sub_ratio" +;; + +let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) (big_int_of_int 2)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int 1) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 6) +;; + +let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int 4) && +test 4 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && +test 6 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 7 eq_big_int (numerator_ratio r, zero_big_int) && +test 8 eq_big_int (denominator_ratio r, zero_big_int) +;; + +testing_function "mult_ratio" +;; + +let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 7) (big_int_of_int 5)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 15) +;; + +let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int (-2)) && +test 4 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 5 eq_big_int (numerator_ratio r, big_int_of_int 2) && +test 6 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 7 eq_big_int (numerator_ratio r, big_int_of_int 2) && +test 8 eq_big_int (denominator_ratio r, zero_big_int) +;; + +testing_function "div_ratio" +;; + +let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 5) (big_int_of_int 7)) in +test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) && +test 2 eq_big_int (denominator_ratio r, big_int_of_int 15) +;; + +let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in +test 3 eq_big_int (numerator_ratio r, big_int_of_int (-4)) && +test 4 eq_big_int (denominator_ratio r, zero_big_int) +;; + +let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 5 eq_big_int (numerator_ratio r, zero_big_int) && +test 6 eq_big_int (denominator_ratio r, big_int_of_int 3) +;; + +let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int) + (create_ratio (big_int_of_int 1) zero_big_int) in +test 7 eq_big_int (numerator_ratio r, zero_big_int) && +test 8 eq_big_int (denominator_ratio r, zero_big_int) +;; + +testing_function "integer_ratio" +;; + +test 1 +eq_big_int (integer_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + big_int_of_int 1) +;; +test 2 +eq_big_int (integer_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), + big_int_of_int (-1)) +;; +test 3 +eq_big_int (integer_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), + big_int_of_int 1) +;; +test 4 +eq_big_int (integer_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), + big_int_of_int (-1)) +;; + +failwith_test 5 +integer_ratio (create_ratio (big_int_of_int 3) zero_big_int) +(Failure("integer_ratio "^infinite_failure)) +;; + +testing_function "floor_ratio" +;; + +test 1 +eq_big_int (floor_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + big_int_of_int 1) +;; +test 2 +eq_big_int (floor_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), + big_int_of_int (-2)) +;; +test 3 +eq_big_int (floor_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), + big_int_of_int 1) +;; +test 4 +eq_big_int (floor_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), + big_int_of_int (-2)) +;; + +failwith_test 5 floor_ratio (create_ratio (big_int_of_int 3) zero_big_int) +Division_by_zero +;; + + +testing_function "round_ratio" +;; + +test 1 +eq_big_int (round_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + big_int_of_int 2) +;; +test 2 +eq_big_int (round_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), + big_int_of_int (-2)) +;; +test 3 +eq_big_int (round_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), + big_int_of_int 2) +;; +test 4 +eq_big_int (round_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), + big_int_of_int (-2)) +;; + +failwith_test 5 +round_ratio (create_ratio (big_int_of_int 3) zero_big_int) +Division_by_zero +;; + + +testing_function "ceiling_ratio" +;; + +test 1 +eq_big_int (ceiling_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + big_int_of_int 2) +;; +test 2 +eq_big_int (ceiling_ratio + (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), + big_int_of_int (-1)) +;; +test 3 +eq_big_int (ceiling_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), + big_int_of_int 2) +;; +test 4 +eq_big_int (ceiling_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), + big_int_of_int (-1)) +;; +test 5 +eq_big_int (ceiling_ratio + (create_ratio (big_int_of_int 4) (big_int_of_int 2)), + big_int_of_int 2) +;; +failwith_test 6 +ceiling_ratio (create_ratio (big_int_of_int 3) zero_big_int) +Division_by_zero +;; + +testing_function "eq_ratio" +;; + +test 1 +eq_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3), + create_ratio (big_int_of_int (-20)) (big_int_of_int (-12))) +;; +test 2 +eq_ratio (create_ratio (big_int_of_int 1) zero_big_int, + create_ratio (big_int_of_int 2) zero_big_int) +;; + +let neq_ratio x y = not (eq_ratio x y);; + +test 3 +neq_ratio (create_ratio (big_int_of_int 1) zero_big_int, + create_ratio (big_int_of_int (-1)) zero_big_int) +;; +test 4 +neq_ratio (create_ratio (big_int_of_int 1) zero_big_int, + create_ratio zero_big_int zero_big_int) +;; +test 5 +eq_ratio (create_ratio zero_big_int zero_big_int, + create_ratio zero_big_int zero_big_int) +;; + +testing_function "compare_ratio" +;; + +test 1 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 2 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int 1) (big_int_of_int 0)), + 0) +;; +test 3 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), + 0) +;; +test 4 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 5 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 6 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + 0) +;; +test 7 +eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 8 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), + 0) +;; +test 9 +eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 10 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 1)), + 0) +;; +test 11 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), + 0) +;; +test 12 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int 1) (big_int_of_int 0)), + 0) +;; +test 13 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int 2) (big_int_of_int 0)), + 0) +;; +test 14 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), + 1) +;; +test 15 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int 1) (big_int_of_int 0)), + (-1)) +;; +test 16 +eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) (big_int_of_int 0)), + (-1)) +;; +test 17 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + 1) +;; +test 18 +eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) + (create_ratio (big_int_of_int 1) (big_int_of_int 0)), + (-1)) +;; +test 19 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), + 1) +;; +test 20 +eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 3)), + 1) +;; +test 21 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), + 0) +;; +test 22 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-2)) (big_int_of_int 0)), + 0) +;; +test 23 +eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) + (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), + 1) +;; +test 24 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + (-1)) +;; +test 25 +eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) + (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), + 1) +;; +test 26 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), + (-1)) +;; +test 27 +eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) + (create_ratio (big_int_of_int 0) (big_int_of_int 3)), + (-1)) +;; +test 28 +eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), + 1) +;; +test 29 +eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + (-1)) +;; +test 30 +eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) + (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)), + 1) +;; +test 31 +eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + (-1)) +;; +test 32 +eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) + (create_ratio (big_int_of_int 0) (big_int_of_int 3)), + 1) +;; +test 33 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) + (create_ratio (big_int_of_int 5) (big_int_of_int 3)), + (-1)) +;; +test 34 +eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)) + (create_ratio (big_int_of_int 0) (big_int_of_int 3)), + (-1)) +;; +test 35 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) + (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), + 1) +;; +test 36 +eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) + (create_ratio (big_int_of_int 0) (big_int_of_int 3)), + 0) +;; + +testing_function "eq_big_int_ratio" +;; + +test 1 +eq_big_int_ratio (big_int_of_int 3, + (create_ratio (big_int_of_int 3) (big_int_of_int 1))) +;; +test 2 +eq +(not (eq_big_int_ratio (big_int_of_int 1) + (create_ratio (big_int_of_int 3) (big_int_of_int 1))), +true) +;; + +test 3 +eq +(not (eq_big_int_ratio (big_int_of_int 1) + (create_ratio (big_int_of_int 3) (big_int_of_int 2))), + true) +;; + +test 4 +eq +(not (eq_big_int_ratio (big_int_of_int 1) + (create_ratio (big_int_of_int 3) (big_int_of_int 0))), + true) +;; + +test 5 +eq +(not (eq_big_int_ratio (big_int_of_int 1) + (create_ratio (big_int_of_int (-3)) (big_int_of_int 2))), + true) +;; + +testing_function "compare_big_int_ratio" +;; + +test 1 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1)) +;; +test 2 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0) +;; +test 3 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1) +;; +test 4 +eq_int (compare_big_int_ratio + (big_int_of_int (-1)) + (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1)) +;; +test 5 +eq_int (compare_big_int_ratio + (big_int_of_int (-1)) + (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0) +;; +test 6 +eq_int (compare_big_int_ratio + (big_int_of_int (-1)) + (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1) +;; +test 7 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int 1) (big_int_of_int 1)), 0) +;; +test 8 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int 3) (big_int_of_int 2)), (-1)) +;; +test 9 +eq_int (compare_big_int_ratio + (big_int_of_int 1) + (create_ratio (big_int_of_int 2) (big_int_of_int 3)), 1) +;; + + + +testing_function "int_of_ratio" +;; + +test 1 +eq_int (int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 2)), + 2) +;; + +test 2 +eq_int (int_of_ratio + (create_ratio (big_int_of_int biggest_int) (big_int_of_int 1)), + biggest_int) +;; + +failwith_test 3 +int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 0)) +(Failure "integer argument required") +;; + +failwith_test 4 +int_of_ratio (create_ratio (succ_big_int (big_int_of_int biggest_int)) + (big_int_of_int 1)) +(Failure "integer argument required") +;; + +failwith_test 5 +int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 3)) +(Failure "integer argument required") +;; + +testing_function "ratio_of_int" +;; + +test 1 +eq_ratio (ratio_of_int 3, + create_ratio (big_int_of_int 3) (big_int_of_int 1)) +;; + +test 2 +eq_ratio (ratio_of_nat (nat_of_int 2), + create_ratio (big_int_of_int 2) (big_int_of_int 1)) +;; + +testing_function "nat_of_ratio" +;; + +let nat1 = nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 1)) +and nat2 = nat_of_int 3 in +test 1 +eq (eq_nat nat1 0 (length_nat nat1) nat2 0 (length_nat nat2), true) +;; + +failwith_test 2 +nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0)) +(Failure "nat_of_ratio") +;; + +failwith_test 3 +nat_of_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 1)) +(Failure "nat_of_ratio") +;; + +failwith_test 4 +nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) +(Failure "nat_of_ratio") +;; + +testing_function "ratio_of_big_int" +;; + +test 1 +eq_ratio (ratio_of_big_int (big_int_of_int 3), + create_ratio (big_int_of_int 3) (big_int_of_int 1)) +;; + +testing_function "big_int_of_ratio" +;; + +test 1 +eq_big_int (big_int_of_ratio + (create_ratio (big_int_of_int 3) (big_int_of_int 1)), + big_int_of_int 3) +;; +test 2 +eq_big_int (big_int_of_ratio + (create_ratio (big_int_of_int (-3)) (big_int_of_int 1)), + big_int_of_int (-3)) +;; + +failwith_test 3 +big_int_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0)) +(Failure "big_int_of_ratio") +;; + +testing_function "string_of_ratio" +;; + +test 1 +eq_string (string_of_ratio + (create_ratio (big_int_of_int 43) (big_int_of_int 35)), + "43/35") +;; +test 2 +eq_string (string_of_ratio + (create_ratio (big_int_of_int 42) (big_int_of_int 0)), + "1/0") +;; + +set_normalize_ratio_when_printing false +;; + +test 3 +eq_string (string_of_ratio + (create_ratio (big_int_of_int 42) (big_int_of_int 35)), + "42/35") +;; + +set_normalize_ratio_when_printing true +;; + +test 4 +eq_string (string_of_ratio + (create_ratio (big_int_of_int 42) (big_int_of_int 35)), + "6/5") +;; + +testing_function "ratio_of_string" +;; + +test 1 +eq_ratio (ratio_of_string ("123/3456"), + create_ratio (big_int_of_int 123) (big_int_of_int 3456)) +;; + +(*********** +test 2 +eq_ratio (ratio_of_string ("12.3/34.56"), + create_ratio (big_int_of_int 1230) (big_int_of_int 3456)) +;; +test 3 +eq_ratio (ratio_of_string ("1.23/325.6"), + create_ratio (big_int_of_int 123) (big_int_of_int 32560)) +;; +test 4 +eq_ratio (ratio_of_string ("12.3/345.6"), + create_ratio (big_int_of_int 123) (big_int_of_int 3456)) +;; +test 5 +eq_ratio (ratio_of_string ("12.3/0.0"), + create_ratio (big_int_of_int 123) (big_int_of_int 0)) +;; +***********) +test 6 +eq_ratio (ratio_of_string ("0/0"), + create_ratio (big_int_of_int 0) (big_int_of_int 0)) +;; + +test 7 +eq_ratio (ratio_of_string "1234567890", + create_ratio (big_int_of_string "1234567890") unit_big_int) +;; +failwith_test 8 +ratio_of_string "frlshjkurty" (Failure "invalid digit");; + +(*********** +testing_function "msd_ratio" +;; + +test 1 +eq_int (msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1)), + 0) +;; +test 2 +eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 12)), + (-2)) +;; +test 3 +eq_int (msd_ratio (create_ratio (big_int_of_int 12) (big_int_of_int 1)), + 1) +;; +test 4 +eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2)), + (-1)) +;; +test 5 +eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 1)), + 0) +;; +test 6 +eq_int (msd_ratio (create_ratio (big_int_of_int 25) (big_int_of_int 21)), + 0) +;; +test 7 +eq_int (msd_ratio (create_ratio (big_int_of_int 35) (big_int_of_int 21)), + 0) +;; +test 8 +eq_int (msd_ratio (create_ratio (big_int_of_int 215) (big_int_of_int 31)), + 0) +;; +test 9 +eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 30)), + (-2)) +;; +test 10 +eq_int (msd_ratio (create_ratio (big_int_of_int 2345) + (big_int_of_int 23456)), + (-2)) +;; +test 11 +eq_int (msd_ratio (create_ratio (big_int_of_int 2345) + (big_int_of_int 2346)), + (-1)) +;; +test 12 +eq_int (msd_ratio (create_ratio (big_int_of_int 2345) + (big_int_of_int 2344)), + 0) +;; +test 13 +eq_int (msd_ratio (create_ratio (big_int_of_int 23456) + (big_int_of_int 2345)), + 1) +;; +test 14 +eq_int (msd_ratio (create_ratio (big_int_of_int 23467) + (big_int_of_int 2345)), + 1) +;; +failwith_test 15 +msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) +("msd_ratio "^infinite_failure) +;; +failwith_test 16 +msd_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) +("msd_ratio "^infinite_failure) +;; +failwith_test 17 +msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) +("msd_ratio "^infinite_failure) +;; +*************************) + +testing_function "round_futur_last_digit" +;; + +let s = "+123456" in +test 1 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 2 eq_string (s, "+123466") +;; + +let s = "123456" in +test 3 eq (round_futur_last_digit s 0 (String.length s), false) && +test 4 eq_string (s, "123466") +;; + +let s = "-123456" in +test 5 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 6 eq_string (s, "-123466") +;; + +let s = "+123496" in +test 7 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 8 eq_string (s, "+123506") +;; + +let s = "123496" in +test 9 eq (round_futur_last_digit s 0 (String.length s), false) && +test 10 eq_string (s, "123506") +;; + +let s = "-123496" in +test 11 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 12 eq_string (s, "-123506") +;; + +let s = "+996" in +test 13 eq (round_futur_last_digit s 1 (pred (String.length s)), + true) && +test 14 eq_string (s, "+006") +;; + +let s = "996" in +test 15 eq (round_futur_last_digit s 0 (String.length s), true) && +test 16 eq_string (s, "006") +;; + +let s = "-996" in +test 17 eq (round_futur_last_digit s 1 (pred (String.length s)), + true) && +test 18 eq_string (s, "-006") +;; + +let s = "+6666666" in +test 19 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 20 eq_string (s, "+6666676") +;; + +let s = "6666666" in +test 21 eq (round_futur_last_digit s 0 (String.length s), false) && +test 22 eq_string (s, "6666676") +;; + +let s = "-6666666" in +test 23 eq (round_futur_last_digit s 1 (pred (String.length s)), + false) && +test 24 eq_string (s, "-6666676") +;; + +testing_function "approx_ratio_fix" +;; + +let s = approx_ratio_fix 5 + (create_ratio (big_int_of_int 2) + (big_int_of_int 3)) in +test 1 +eq_string (s, "+0.66667") +;; + +test 2 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_int 20) + (big_int_of_int 3)), + "+6.66667") +;; +test 3 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_int 2) + (big_int_of_int 30)), + "+0.06667") +;; +test 4 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_string "999996") + (big_int_of_string "1000000")), + "+1.00000") +;; +test 5 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_string "299996") + (big_int_of_string "100000")), + "+2.99996") +;; +test 6 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_string "2999996") + (big_int_of_string "1000000")), + "+3.00000") +;; +test 7 +eq_string (approx_ratio_fix 4 + (create_ratio (big_int_of_string "299996") + (big_int_of_string "100000")), + "+3.0000") +;; +test 8 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_int 29996) + (big_int_of_string "100000")), + "+0.29996") +;; +test 9 +eq_string (approx_ratio_fix 5 + (create_ratio (big_int_of_int 0) + (big_int_of_int 1)), + "+0") +;; +failwith_test 10 +(approx_ratio_fix 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0)) +(Failure "approx_ratio_fix infinite or undefined rational number") +;; +failwith_test 11 +(approx_ratio_fix 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0)) +(Failure "approx_ratio_fix infinite or undefined rational number") +;; + +(* PR#4566 *) +test 12 +eq_string (approx_ratio_fix 8 + (create_ratio (big_int_of_int 9603) + (big_int_of_string "100000000000")), + + "+0.00000010") +;; +test 13 +eq_string (approx_ratio_fix 1 + (create_ratio (big_int_of_int 94) + (big_int_of_int 1000)), + "+0.1") +;; +test 14 +eq_string (approx_ratio_fix 1 + (create_ratio (big_int_of_int 49) + (big_int_of_int 1000)), + "+0.0") +;; + +testing_function "approx_ratio_exp" +;; + +test 1 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_int 2) + (big_int_of_int 3)), + "+0.66667e0") +;; +test 2 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_int 20) + (big_int_of_int 3)), + "+0.66667e1") +;; +test 3 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_int 2) + (big_int_of_int 30)), + "+0.66667e-1") +;; +test 4 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_string "999996") + (big_int_of_string "1000000")), + "+1.00000e0") +;; +test 5 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_string "299996") + (big_int_of_string "100000")), + "+0.30000e1") +;; +test 6 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_int 29996) + (big_int_of_string "100000")), + "+0.29996e0") +;; +test 7 +eq_string (approx_ratio_exp 5 + (create_ratio (big_int_of_int 0) + (big_int_of_int 1)), + "+0.00000e0") +;; +failwith_test 8 +(approx_ratio_exp 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0)) +(Failure "approx_ratio_exp infinite or undefined rational number") +;; +failwith_test 9 +(approx_ratio_exp 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0)) +(Failure "approx_ratio_exp infinite or undefined rational number") +;; diff --git a/otherlibs/str/.cvsignore b/otherlibs/str/.cvsignore new file mode 100644 index 0000000..a37b133 --- /dev/null +++ b/otherlibs/str/.cvsignore @@ -0,0 +1,3 @@ +libstr.x +*.c.x +so_locations diff --git a/otherlibs/str/.depend b/otherlibs/str/.depend new file mode 100644 index 0000000..bafddbd --- /dev/null +++ b/otherlibs/str/.depend @@ -0,0 +1,17 @@ +strstubs.o: strstubs.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +str.cmi: +str.cmo: str.cmi +str.cmx: str.cmi diff --git a/otherlibs/str/Makefile b/otherlibs/str/Makefile new file mode 100644 index 0000000..aea38a1 --- /dev/null +++ b/otherlibs/str/Makefile @@ -0,0 +1,34 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.35 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the str library + + +LIBNAME=str +COBJS=strstubs.$(O) +CAMLOBJS=str.cmo + +include ../Makefile + +depend: + +str.cmo: str.cmi +str.cmx: str.cmi + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/str/Makefile.nt b/otherlibs/str/Makefile.nt new file mode 100644 index 0000000..38ee792 --- /dev/null +++ b/otherlibs/str/Makefile.nt @@ -0,0 +1,27 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.16 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the str library + +LIBNAME=str +COBJS=strstubs.$(O) +CAMLOBJS=str.cmo + +include ../Makefile.nt + +depend: + +str.cmo: str.cmi +str.cmx: str.cmi diff --git a/otherlibs/str/dllstr.dlib b/otherlibs/str/dllstr.dlib new file mode 100644 index 0000000..0c34626 --- /dev/null +++ b/otherlibs/str/dllstr.dlib @@ -0,0 +1 @@ +strstubs.d.o diff --git a/otherlibs/str/libstr.clib b/otherlibs/str/libstr.clib new file mode 100644 index 0000000..319e760 --- /dev/null +++ b/otherlibs/str/libstr.clib @@ -0,0 +1 @@ +strstubs.o diff --git a/otherlibs/str/str.ml b/otherlibs/str/str.ml new file mode 100644 index 0000000..6176aa9 --- /dev/null +++ b/otherlibs/str/str.ml @@ -0,0 +1,737 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: str.ml,v 1.22 2008-08-01 12:27:13 xleroy Exp $ *) + +(** String utilities *) + +let string_before s n = String.sub s 0 n + +let string_after s n = String.sub s n (String.length s - n) + +let first_chars s n = String.sub s 0 n + +let last_chars s n = String.sub s (String.length s - n) n + +(** Representation of character sets **) + +module Charset = + struct + type t = string (* of length 32 *) + + let empty = String.make 32 '\000' + let full = String.make 32 '\255' + + let make_empty () = String.make 32 '\000' + + let add s c = + let i = Char.code c in + s.[i lsr 3] <- Char.chr(Char.code s.[i lsr 3] lor (1 lsl (i land 7))) + + let add_range s c1 c2 = + for i = Char.code c1 to Char.code c2 do add s (Char.chr i) done + + let singleton c = + let s = make_empty () in add s c; s + + let range c1 c2 = + let s = make_empty () in add_range s c1 c2; s + + let complement s = + let r = String.create 32 in + for i = 0 to 31 do + r.[i] <- Char.chr(Char.code s.[i] lxor 0xFF) + done; + r + + let union s1 s2 = + let r = String.create 32 in + for i = 0 to 31 do + r.[i] <- Char.chr(Char.code s1.[i] lor Char.code s2.[i]) + done; + r + + let disjoint s1 s2 = + try + for i = 0 to 31 do + if Char.code s1.[i] land Char.code s2.[i] <> 0 then raise Exit + done; + true + with Exit -> + false + + let iter fn s = + for i = 0 to 31 do + let c = Char.code s.[i] in + if c <> 0 then + for j = 0 to 7 do + if c land (1 lsl j) <> 0 then fn (Char.chr ((i lsl 3) + j)) + done + done + + let expand s = + let r = String.make 256 '\000' in + iter (fun c -> r.[Char.code c] <- '\001') s; + r + + let fold_case s = + let r = make_empty() in + iter (fun c -> add r (Char.lowercase c); add r (Char.uppercase c)) s; + r + + end + +(** Abstract syntax tree for regular expressions *) + +type re_syntax = + Char of char + | String of string + | CharClass of Charset.t + | Seq of re_syntax list + | Alt of re_syntax * re_syntax + | Star of re_syntax + | Plus of re_syntax + | Option of re_syntax + | Group of int * re_syntax + | Refgroup of int + | Bol + | Eol + | Wordboundary + +(** Representation of compiled regular expressions *) + +type regexp = { + prog: int array; (* bytecode instructions *) + cpool: string array; (* constant pool (string literals) *) + normtable: string; (* case folding table (if any) *) + numgroups: int; (* number of \(...\) groups *) + numregisters: int; (* number of nullable Star or Plus *) + startchars: int (* index of set of starting chars, or -1 if none *) +} + +(** Opcodes for bytecode instructions; see strstubs.c for description *) + +let op_CHAR = 0 +let op_CHARNORM = 1 +let op_STRING = 2 +let op_STRINGNORM = 3 +let op_CHARCLASS = 4 +let op_BOL = 5 +let op_EOL = 6 +let op_WORDBOUNDARY = 7 +let op_BEGGROUP = 8 +let op_ENDGROUP = 9 +let op_REFGROUP = 10 +let op_ACCEPT = 11 +let op_SIMPLEOPT = 12 +let op_SIMPLESTAR = 13 +let op_SIMPLEPLUS = 14 +let op_GOTO = 15 +let op_PUSHBACK = 16 +let op_SETMARK = 17 +let op_CHECKPROGRESS = 18 + +(* Encoding of bytecode instructions *) + +let instr opc arg = opc lor (arg lsl 8) + +(* Computing relative displacements for GOTO and PUSHBACK instructions *) + +let displ dest from = dest - from - 1 + +(** Compilation of a regular expression *) + +(* Determine if a regexp can match the empty string *) + +let rec is_nullable = function + Char c -> false + | String s -> s = "" + | CharClass cl -> false + | Seq rl -> List.for_all is_nullable rl + | Alt (r1, r2) -> is_nullable r1 || is_nullable r2 + | Star r -> true + | Plus r -> is_nullable r + | Option r -> true + | Group(n, r) -> is_nullable r + | Refgroup n -> true + | Bol -> true + | Eol -> true + | Wordboundary -> true + +(* first r returns a set of characters C such that: + for all string s, s matches r => the first character of s is in C. + For convenience, return Charset.full if r is nullable. *) + +let rec first = function + Char c -> Charset.singleton c + | String s -> if s = "" then Charset.full else Charset.singleton s.[0] + | CharClass cl -> cl + | Seq rl -> first_seq rl + | Alt (r1, r2) -> Charset.union (first r1) (first r2) + | Star r -> Charset.full + | Plus r -> first r + | Option r -> Charset.full + | Group(n, r) -> first r + | Refgroup n -> Charset.full + | Bol -> Charset.full + | Eol -> Charset.full + | Wordboundary -> Charset.full + +and first_seq = function + [] -> Charset.full + | (Bol | Eol | Wordboundary) :: rl -> first_seq rl + | Star r :: rl -> Charset.union (first r) (first_seq rl) + | Option r :: rl -> Charset.union (first r) (first_seq rl) + | r :: rl -> first r + +(* Transform a Char or CharClass regexp into a character class *) + +let charclass_of_regexp fold_case re = + let cl = + match re with + Char c -> Charset.singleton c + | CharClass cl -> cl + | _ -> assert false in + if fold_case then Charset.fold_case cl else cl + +(* The case fold table: maps characters to their lowercase equivalent *) + +let fold_case_table = + let t = String.create 256 in + for i = 0 to 255 do t.[i] <- Char.lowercase(Char.chr i) done; + t + +module StringMap = Map.Make(struct type t = string let compare = compare end) + +(* Compilation of a regular expression *) + +let compile fold_case re = + + (* Instruction buffering *) + let prog = ref (Array.make 32 0) + and progpos = ref 0 + and cpool = ref StringMap.empty + and cpoolpos = ref 0 + and numgroups = ref 1 + and numregs = ref 0 in + (* Add a new instruction *) + let emit_instr opc arg = + if !progpos >= Array.length !prog then begin + let newlen = ref (Array.length !prog) in + while !progpos >= !newlen do newlen := !newlen * 2 done; + let nprog = Array.make !newlen 0 in + Array.blit !prog 0 nprog 0 (Array.length !prog); + prog := nprog + end; + (!prog).(!progpos) <- (instr opc arg); + incr progpos in + (* Reserve an instruction slot and return its position *) + let emit_hole () = + let p = !progpos in incr progpos; p in + (* Fill a reserved instruction slot with a GOTO or PUSHBACK instruction *) + let patch_instr pos opc dest = + (!prog).(pos) <- (instr opc (displ dest pos)) in + (* Return the cpool index for the given string, adding it if not + already there *) + let cpool_index s = + try + StringMap.find s !cpool + with Not_found -> + let p = !cpoolpos in + cpool := StringMap.add s p !cpool; + incr cpoolpos; + p in + (* Allocate fresh register if regexp is nullable *) + let allocate_register_if_nullable r = + if is_nullable r then begin + let n = !numregs in + if n >= 64 then failwith "too many r* or r+ where r is nullable"; + incr numregs; + n + end else + -1 in + (* Main recursive compilation function *) + let rec emit_code = function + Char c -> + if fold_case then + emit_instr op_CHARNORM (Char.code (Char.lowercase c)) + else + emit_instr op_CHAR (Char.code c) + | String s -> + begin match String.length s with + 0 -> () + | 1 -> + if fold_case then + emit_instr op_CHARNORM (Char.code (Char.lowercase s.[0])) + else + emit_instr op_CHAR (Char.code s.[0]) + | _ -> + try + (* null characters are not accepted by the STRING* instructions; + if one is found, split string at null character *) + let i = String.index s '\000' in + emit_code (String (string_before s i)); + emit_instr op_CHAR 0; + emit_code (String (string_after s (i+1))) + with Not_found -> + if fold_case then + emit_instr op_STRINGNORM (cpool_index (String.lowercase s)) + else + emit_instr op_STRING (cpool_index s) + end + | CharClass cl -> + let cl' = if fold_case then Charset.fold_case cl else cl in + emit_instr op_CHARCLASS (cpool_index cl') + | Seq rl -> + emit_seq_code rl + | Alt(r1, r2) -> + (* PUSHBACK lbl1 + <match r1> + GOTO lbl2 + lbl1: <match r2> + lbl2: ... *) + let pos_pushback = emit_hole() in + emit_code r1; + let pos_goto_end = emit_hole() in + let lbl1 = !progpos in + emit_code r2; + let lbl2 = !progpos in + patch_instr pos_pushback op_PUSHBACK lbl1; + patch_instr pos_goto_end op_GOTO lbl2 + | Star r -> + (* Implement longest match semantics for compatibility with old Str *) + (* General translation: + lbl1: PUSHBACK lbl2 + SETMARK regno + <match r> + CHECKPROGRESS regno + GOTO lbl1 + lbl2: + If r cannot match the empty string, code can be simplified: + lbl1: PUSHBACK lbl2 + <match r> + GOTO lbl1 + lbl2: + *) + let regno = allocate_register_if_nullable r in + let lbl1 = emit_hole() in + if regno >= 0 then emit_instr op_SETMARK regno; + emit_code r; + if regno >= 0 then emit_instr op_CHECKPROGRESS regno; + emit_instr op_GOTO (displ lbl1 !progpos); + let lbl2 = !progpos in + patch_instr lbl1 op_PUSHBACK lbl2 + | Plus r -> + (* Implement longest match semantics for compatibility with old Str *) + (* General translation: + lbl1: <match r> + CHECKPROGRESS regno + PUSHBACK lbl2 + SETMARK regno + GOTO lbl1 + lbl2: + If r cannot match the empty string, code can be simplified: + lbl1: <match r> + PUSHBACK lbl2 + GOTO_PLUS lbl1 + lbl2: + *) + let regno = allocate_register_if_nullable r in + let lbl1 = !progpos in + emit_code r; + if regno >= 0 then emit_instr op_CHECKPROGRESS regno; + let pos_pushback = emit_hole() in + if regno >= 0 then emit_instr op_SETMARK regno; + emit_instr op_GOTO (displ lbl1 !progpos); + let lbl2 = !progpos in + patch_instr pos_pushback op_PUSHBACK lbl2 + | Option r -> + (* Implement longest match semantics for compatibility with old Str *) + (* PUSHBACK lbl + <match r> + lbl: + *) + let pos_pushback = emit_hole() in + emit_code r; + let lbl = !progpos in + patch_instr pos_pushback op_PUSHBACK lbl + | Group(n, r) -> + if n >= 32 then failwith "too many \\(...\\) groups"; + emit_instr op_BEGGROUP n; + emit_code r; + emit_instr op_ENDGROUP n; + numgroups := max !numgroups (n+1) + | Refgroup n -> + emit_instr op_REFGROUP n + | Bol -> + emit_instr op_BOL 0 + | Eol -> + emit_instr op_EOL 0 + | Wordboundary -> + emit_instr op_WORDBOUNDARY 0 + + and emit_seq_code = function + [] -> () + | Star(Char _ | CharClass _ as r) :: rl + when disjoint_modulo_case (first r) (first_seq rl) -> + emit_instr op_SIMPLESTAR (cpool_index (charclass_of_regexp fold_case r)); + emit_seq_code rl + | Plus(Char _ | CharClass _ as r) :: rl + when disjoint_modulo_case (first r) (first_seq rl) -> + emit_instr op_SIMPLEPLUS (cpool_index (charclass_of_regexp fold_case r)); + emit_seq_code rl + | Option(Char _ | CharClass _ as r) :: rl + when disjoint_modulo_case (first r) (first_seq rl) -> + emit_instr op_SIMPLEOPT (cpool_index (charclass_of_regexp fold_case r)); + emit_seq_code rl + | r :: rl -> + emit_code r; + emit_seq_code rl + + and disjoint_modulo_case c1 c2 = + if fold_case + then Charset.disjoint (Charset.fold_case c1) (Charset.fold_case c2) + else Charset.disjoint c1 c2 + in + + emit_code re; + emit_instr op_ACCEPT 0; + let start = first re in + let start' = if fold_case then Charset.fold_case start else start in + let start_pos = + if start = Charset.full + then -1 + else cpool_index (Charset.expand start') in + let constantpool = Array.make !cpoolpos "" in + StringMap.iter (fun str idx -> constantpool.(idx) <- str) !cpool; + { prog = Array.sub !prog 0 !progpos; + cpool = constantpool; + normtable = if fold_case then fold_case_table else ""; + numgroups = !numgroups; + numregisters = !numregs; + startchars = start_pos } + +(** Parsing of a regular expression *) + +(* Efficient buffering of sequences *) + +module SeqBuffer = struct + + type t = { sb_chars: Buffer.t; mutable sb_next: re_syntax list } + + let create() = { sb_chars = Buffer.create 16; sb_next = [] } + + let flush buf = + let s = Buffer.contents buf.sb_chars in + Buffer.clear buf.sb_chars; + match String.length s with + 0 -> () + | 1 -> buf.sb_next <- Char s.[0] :: buf.sb_next + | _ -> buf.sb_next <- String s :: buf.sb_next + + let add buf re = + match re with + Char c -> Buffer.add_char buf.sb_chars c + | _ -> flush buf; buf.sb_next <- re :: buf.sb_next + + let extract buf = + flush buf; Seq(List.rev buf.sb_next) + +end + +(* The character class corresponding to `.' *) + +let dotclass = Charset.complement (Charset.singleton '\n') + +(* Parse a regular expression *) + +let parse s = + let len = String.length s in + let group_counter = ref 1 in + + let rec regexp0 i = + let (r, j) = regexp1 i in + regexp0cont r j + and regexp0cont r1 i = + if i + 2 <= len && s.[i] = '\\' && s.[i+1] = '|' then + let (r2, j) = regexp1 (i+2) in + regexp0cont (Alt(r1, r2)) j + else + (r1, i) + and regexp1 i = + regexp1cont (SeqBuffer.create()) i + and regexp1cont sb i = + if i >= len + || i + 2 <= len && s.[i] = '\\' && (let c = s.[i+1] in c = '|' || c = ')') + then + (SeqBuffer.extract sb, i) + else + let (r, j) = regexp2 i in + SeqBuffer.add sb r; + regexp1cont sb j + and regexp2 i = + let (r, j) = regexp3 i in + regexp2cont r j + and regexp2cont r i = + if i >= len then (r, i) else + match s.[i] with + '?' -> regexp2cont (Option r) (i+1) + | '*' -> regexp2cont (Star r) (i+1) + | '+' -> regexp2cont (Plus r) (i+1) + | _ -> (r, i) + and regexp3 i = + match s.[i] with + '\\' -> regexpbackslash (i+1) + | '[' -> let (c, j) = regexpclass0 (i+1) in (CharClass c, j) + | '^' -> (Bol, i+1) + | '$' -> (Eol, i+1) + | '.' -> (CharClass dotclass, i+1) + | c -> (Char c, i+1) + and regexpbackslash i = + if i >= len then (Char '\\', i) else + match s.[i] with + '|' | ')' -> + assert false + | '(' -> + let group_no = !group_counter in + if group_no < 32 then incr group_counter; + let (r, j) = regexp0 (i+1) in + if j + 1 < len && s.[j] = '\\' && s.[j+1] = ')' then + if group_no < 32 + then (Group(group_no, r), j + 2) + else (r, j + 2) + else + failwith "\\( group not closed by \\)" + | '1' .. '9' as c -> + (Refgroup(Char.code c - 48), i + 1) + | 'b' -> + (Wordboundary, i + 1) + | c -> + (Char c, i + 1) + and regexpclass0 i = + if i < len && s.[i] = '^' + then let (c, j) = regexpclass1 (i+1) in (Charset.complement c, j) + else regexpclass1 i + and regexpclass1 i = + let c = Charset.make_empty() in + let j = regexpclass2 c i i in + (c, j) + and regexpclass2 c start i = + if i >= len then failwith "[ class not closed by ]"; + if s.[i] = ']' && i > start then i+1 else begin + let c1 = s.[i] in + if i+2 < len && s.[i+1] = '-' && s.[i+2] <> ']' then begin + let c2 = s.[i+2] in + Charset.add_range c c1 c2; + regexpclass2 c start (i+3) + end else begin + Charset.add c c1; + regexpclass2 c start (i+1) + end + end in + + let (r, j) = regexp0 0 in + if j = len then r else failwith "spurious \\) in regular expression" + +(** Parsing and compilation *) + +let regexp e = compile false (parse e) + +let regexp_case_fold e = compile true (parse e) + +let quote s = + let len = String.length s in + let buf = String.create (2 * len) in + let pos = ref 0 in + for i = 0 to len - 1 do + match s.[i] with + '[' | ']' | '*' | '.' | '\\' | '?' | '+' | '^' | '$' as c -> + buf.[!pos] <- '\\'; buf.[!pos + 1] <- c; pos := !pos + 2 + | c -> + buf.[!pos] <- c; pos := !pos + 1 + done; + String.sub buf 0 !pos + +let regexp_string s = compile false (String s) + +let regexp_string_case_fold s = compile true (String s) + +(** Matching functions **) + +external re_string_match: regexp -> string -> int -> int array + = "re_string_match" +external re_partial_match: regexp -> string -> int -> int array + = "re_partial_match" +external re_search_forward: regexp -> string -> int -> int array + = "re_search_forward" +external re_search_backward: regexp -> string -> int -> int array + = "re_search_backward" + +let last_search_result = ref [||] + +let string_match re s pos = + let res = re_string_match re s pos in + last_search_result := res; + Array.length res > 0 + +let string_partial_match re s pos = + let res = re_partial_match re s pos in + last_search_result := res; + Array.length res > 0 + +let search_forward re s pos = + let res = re_search_forward re s pos in + last_search_result := res; + if Array.length res = 0 then raise Not_found else res.(0) + +let search_backward re s pos = + let res = re_search_backward re s pos in + last_search_result := res; + if Array.length res = 0 then raise Not_found else res.(0) + +let group_beginning n = + let n2 = n + n in + if n < 0 || n2 >= Array.length !last_search_result then + invalid_arg "Str.group_beginning" + else + let pos = !last_search_result.(n2) in + if pos = -1 then raise Not_found else pos + +let group_end n = + let n2 = n + n in + if n < 0 || n2 >= Array.length !last_search_result then + invalid_arg "Str.group_end" + else + let pos = !last_search_result.(n2 + 1) in + if pos = -1 then raise Not_found else pos + +let matched_group n txt = + let n2 = n + n in + if n < 0 || n2 >= Array.length !last_search_result then + invalid_arg "Str.matched_group" + else + let b = !last_search_result.(n2) + and e = !last_search_result.(n2 + 1) in + if b = -1 then raise Not_found else String.sub txt b (e - b) + +let match_beginning () = group_beginning 0 +and match_end () = group_end 0 +and matched_string txt = matched_group 0 txt + +(** Replacement **) + +external re_replacement_text: string -> int array -> string -> string + = "re_replacement_text" + +let replace_matched repl matched = + re_replacement_text repl !last_search_result matched + +let substitute_first expr repl_fun text = + try + let pos = search_forward expr text 0 in + String.concat "" [string_before text pos; + repl_fun text; + string_after text (match_end())] + with Not_found -> + text + +let opt_search_forward re s pos = + try Some(search_forward re s pos) with Not_found -> None + +let global_substitute expr repl_fun text = + let rec replace accu start last_was_empty = + let startpos = if last_was_empty then start + 1 else start in + if startpos > String.length text then + string_after text start :: accu + else + match opt_search_forward expr text startpos with + | None -> + string_after text start :: accu + | Some pos -> + let end_pos = match_end() in + let repl_text = repl_fun text in + replace (repl_text :: String.sub text start (pos-start) :: accu) + end_pos (end_pos = pos) + in + String.concat "" (List.rev (replace [] 0 false)) + +let global_replace expr repl text = + global_substitute expr (replace_matched repl) text +and replace_first expr repl text = + substitute_first expr (replace_matched repl) text + +(** Splitting *) + +let opt_search_forward_progress expr text start = + match opt_search_forward expr text start with + | None -> None + | Some pos -> + if match_end() > start then + Some pos + else if start < String.length text then + opt_search_forward expr text (start + 1) + else None + +let bounded_split expr text num = + let start = + if string_match expr text 0 then match_end() else 0 in + let rec split accu start n = + if start >= String.length text then accu else + if n = 1 then string_after text start :: accu else + match opt_search_forward_progress expr text start with + | None -> + string_after text start :: accu + | Some pos -> + split (String.sub text start (pos-start) :: accu) + (match_end()) (n-1) + in + List.rev (split [] start num) + +let split expr text = bounded_split expr text 0 + +let bounded_split_delim expr text num = + let rec split accu start n = + if start > String.length text then accu else + if n = 1 then string_after text start :: accu else + match opt_search_forward_progress expr text start with + | None -> + string_after text start :: accu + | Some pos -> + split (String.sub text start (pos-start) :: accu) + (match_end()) (n-1) + in + if text = "" then [] else List.rev (split [] 0 num) + +let split_delim expr text = bounded_split_delim expr text 0 + +type split_result = Text of string | Delim of string + +let bounded_full_split expr text num = + let rec split accu start n = + if start >= String.length text then accu else + if n = 1 then Text(string_after text start) :: accu else + match opt_search_forward_progress expr text start with + | None -> + Text(string_after text start) :: accu + | Some pos -> + let s = matched_string text in + if pos > start then + split (Delim(s) :: Text(String.sub text start (pos-start)) :: accu) + (match_end()) (n-1) + else + split (Delim(s) :: accu) + (match_end()) (n-1) + in + List.rev (split [] 0 num) + +let full_split expr text = bounded_full_split expr text 0 diff --git a/otherlibs/str/str.mli b/otherlibs/str/str.mli new file mode 100644 index 0000000..9b99a83 --- /dev/null +++ b/otherlibs/str/str.mli @@ -0,0 +1,249 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: str.mli,v 1.24 2005-03-24 17:20:53 doligez Exp $ *) + +(** Regular expressions and high-level string processing *) + + +(** {6 Regular expressions} *) + + +type regexp +(** The type of compiled regular expressions. *) + + +val regexp : string -> regexp +(** Compile a regular expression. The following constructs are + recognized: + - [. ] Matches any character except newline. + - [* ] (postfix) Matches the preceding expression zero, one or + several times + - [+ ] (postfix) Matches the preceding expression one or + several times + - [? ] (postfix) Matches the preceding expression once or + not at all + - [[..] ] Character set. Ranges are denoted with [-], as in [[a-z]]. + An initial [^], as in [[^0-9]], complements the set. + To include a [\]] character in a set, make it the first + character of the set. To include a [-] character in a set, + make it the first or the last character of the set. + - [^ ] Matches at beginning of line (either at the beginning of + the matched string, or just after a newline character). + - [$ ] Matches at end of line (either at the end of the matched + string, or just before a newline character). + - [\| ] (infix) Alternative between two expressions. + - [\(..\)] Grouping and naming of the enclosed expression. + - [\1 ] The text matched by the first [\(...\)] expression + ([\2] for the second expression, and so on up to [\9]). + - [\b ] Matches word boundaries. + - [\ ] Quotes special characters. The special characters + are [$^.*+?[]]. +*) + +val regexp_case_fold : string -> regexp +(** Same as [regexp], but the compiled expression will match text + in a case-insensitive way: uppercase and lowercase letters will + be considered equivalent. *) + +val quote : string -> string +(** [Str.quote s] returns a regexp string that matches exactly + [s] and nothing else. *) + +val regexp_string : string -> regexp +(** [Str.regexp_string s] returns a regular expression + that matches exactly [s] and nothing else.*) + +val regexp_string_case_fold : string -> regexp +(** [Str.regexp_string_case_fold] is similar to {!Str.regexp_string}, + but the regexp matches in a case-insensitive way. *) + + +(** {6 String matching and searching} *) + + +val string_match : regexp -> string -> int -> bool +(** [string_match r s start] tests whether a substring of [s] that + starts at position [start] matches the regular expression [r]. + The first character of a string has position [0], as usual. *) + +val search_forward : regexp -> string -> int -> int +(** [search_forward r s start] searches the string [s] for a substring + matching the regular expression [r]. The search starts at position + [start] and proceeds towards the end of the string. + Return the position of the first character of the matched + substring, or raise [Not_found] if no substring matches. *) + +val search_backward : regexp -> string -> int -> int +(** [search_backward r s last] searches the string [s] for a + substring matching the regular expression [r]. The search first + considers substrings that start at position [last] and proceeds + towards the beginning of string. Return the position of the first + character of the matched substring; raise [Not_found] if no + substring matches. *) + +val string_partial_match : regexp -> string -> int -> bool +(** Similar to {!Str.string_match}, but also returns true if + the argument string is a prefix of a string that matches. + This includes the case of a true complete match. *) + +val matched_string : string -> string +(** [matched_string s] returns the substring of [s] that was matched + by the latest {!Str.string_match}, {!Str.search_forward} or + {!Str.search_backward}. + The user must make sure that the parameter [s] is the same string + that was passed to the matching or searching function. *) + +val match_beginning : unit -> int +(** [match_beginning()] returns the position of the first character + of the substring that was matched by {!Str.string_match}, + {!Str.search_forward} or {!Str.search_backward}. *) + +val match_end : unit -> int +(** [match_end()] returns the position of the character following the + last character of the substring that was matched by [string_match], + [search_forward] or [search_backward]. *) + +val matched_group : int -> string -> string +(** [matched_group n s] returns the substring of [s] that was matched + by the [n]th group [\(...\)] of the regular expression during + the latest {!Str.string_match}, {!Str.search_forward} or + {!Str.search_backward}. + The user must make sure that the parameter [s] is the same string + that was passed to the matching or searching function. + [matched_group n s] raises [Not_found] if the [n]th group + of the regular expression was not matched. This can happen + with groups inside alternatives [\|], options [?] + or repetitions [*]. For instance, the empty string will match + [\(a\)*], but [matched_group 1 ""] will raise [Not_found] + because the first group itself was not matched. *) + +val group_beginning : int -> int +(** [group_beginning n] returns the position of the first character + of the substring that was matched by the [n]th group of + the regular expression. + @raise Not_found if the [n]th group of the regular expression + was not matched. + @raise Invalid_argument if there are fewer than [n] groups in + the regular expression. *) + +val group_end : int -> int +(** [group_end n] returns + the position of the character following the last character of + substring that was matched by the [n]th group of the regular expression. + @raise Not_found if the [n]th group of the regular expression + was not matched. + @raise Invalid_argument if there are fewer than [n] groups in + the regular expression. *) + + +(** {6 Replacement} *) + + +val global_replace : regexp -> string -> string -> string +(** [global_replace regexp templ s] returns a string identical to [s], + except that all substrings of [s] that match [regexp] have been + replaced by [templ]. The replacement template [templ] can contain + [\1], [\2], etc; these sequences will be replaced by the text + matched by the corresponding group in the regular expression. + [\0] stands for the text matched by the whole regular expression. *) + +val replace_first : regexp -> string -> string -> string +(** Same as {!Str.global_replace}, except that only the first substring + matching the regular expression is replaced. *) + +val global_substitute : regexp -> (string -> string) -> string -> string +(** [global_substitute regexp subst s] returns a string identical + to [s], except that all substrings of [s] that match [regexp] + have been replaced by the result of function [subst]. The + function [subst] is called once for each matching substring, + and receives [s] (the whole text) as argument. *) + +val substitute_first : regexp -> (string -> string) -> string -> string +(** Same as {!Str.global_substitute}, except that only the first substring + matching the regular expression is replaced. *) + +val replace_matched : string -> string -> string +(** [replace_matched repl s] returns the replacement text [repl] + in which [\1], [\2], etc. have been replaced by the text + matched by the corresponding groups in the most recent matching + operation. [s] must be the same string that was matched during + this matching operation. *) + + +(** {6 Splitting} *) + + +val split : regexp -> string -> string list +(** [split r s] splits [s] into substrings, taking as delimiters + the substrings that match [r], and returns the list of substrings. + For instance, [split (regexp "[ \t]+") s] splits [s] into + blank-separated words. An occurrence of the delimiter at the + beginning and at the end of the string is ignored. *) + +val bounded_split : regexp -> string -> int -> string list +(** Same as {!Str.split}, but splits into at most [n] substrings, + where [n] is the extra integer parameter. *) + +val split_delim : regexp -> string -> string list +(** Same as {!Str.split} but occurrences of the + delimiter at the beginning and at the end of the string are + recognized and returned as empty strings in the result. + For instance, [split_delim (regexp " ") " abc "] + returns [[""; "abc"; ""]], while [split] with the same + arguments returns [["abc"]]. *) + +val bounded_split_delim : regexp -> string -> int -> string list +(** Same as {!Str.bounded_split}, but occurrences of the + delimiter at the beginning and at the end of the string are + recognized and returned as empty strings in the result. *) + +type split_result = + Text of string + | Delim of string + +val full_split : regexp -> string -> split_result list +(** Same as {!Str.split_delim}, but returns + the delimiters as well as the substrings contained between + delimiters. The former are tagged [Delim] in the result list; + the latter are tagged [Text]. For instance, + [full_split (regexp "[{}]") "{ab}"] returns + [[Delim "{"; Text "ab"; Delim "}"]]. *) + +val bounded_full_split : regexp -> string -> int -> split_result list +(** Same as {!Str.bounded_split_delim}, but returns + the delimiters as well as the substrings contained between + delimiters. The former are tagged [Delim] in the result list; + the latter are tagged [Text]. *) + + +(** {6 Extracting substrings} *) + + +val string_before : string -> int -> string +(** [string_before s n] returns the substring of all characters of [s] + that precede position [n] (excluding the character at + position [n]). *) + +val string_after : string -> int -> string +(** [string_after s n] returns the substring of all characters of [s] + that follow position [n] (including the character at + position [n]). *) + +val first_chars : string -> int -> string +(** [first_chars s n] returns the first [n] characters of [s]. + This is the same function as {!Str.string_before}. *) + +val last_chars : string -> int -> string +(** [last_chars s n] returns the last [n] characters of [s]. *) + diff --git a/otherlibs/str/strstubs.c b/otherlibs/str/strstubs.c new file mode 100644 index 0000000..3764b37 --- /dev/null +++ b/otherlibs/str/strstubs.c @@ -0,0 +1,524 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: strstubs.c,v 1.27 2005-09-22 14:21:50 xleroy Exp $ */ + +#include <string.h> +#include <ctype.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <fail.h> + +/* The backtracking NFA interpreter */ + +union backtrack_point { + struct { + value * pc; /* with low bit set */ + unsigned char * txt; + } pos; + struct { + unsigned char ** loc; /* with low bit clear */ + unsigned char * val; + } undo; +}; + +#define Set_tag(p) ((value *) ((intnat)(p) | 1)) +#define Clear_tag(p) ((value *) ((intnat)(p) & ~1)) +#define Tag_is_set(p) ((intnat)(p) & 1) + +#define BACKTRACK_STACK_BLOCK_SIZE 500 + +struct backtrack_stack { + struct backtrack_stack * previous; + union backtrack_point point[BACKTRACK_STACK_BLOCK_SIZE]; +}; + +#define Opcode(x) ((x) & 0xFF) +#define Arg(x) ((uintnat)(x) >> 8) +#define SignedArg(x) ((intnat)(x) >> 8) + +enum { + CHAR, /* match a single character */ + CHARNORM, /* match a single character, after normalization */ + STRING, /* match a character string */ + STRINGNORM, /* match a character string, after normalization */ + CHARCLASS, /* match a character class */ + BOL, /* match at beginning of line */ + EOL, /* match at end of line */ + WORDBOUNDARY, /* match on a word boundary */ + BEGGROUP, /* record the beginning of a group */ + ENDGROUP, /* record the end of a group */ + REFGROUP, /* match a previously matched group */ + ACCEPT, /* report success */ + SIMPLEOPT, /* match a character class 0 or 1 times */ + SIMPLESTAR, /* match a character class 0, 1 or several times */ + SIMPLEPLUS, /* match a character class 1 or several times */ + GOTO, /* unconditional branch */ + PUSHBACK, /* record a backtrack point -- + where to jump in case of failure */ + SETMARK, /* remember current position in given register # */ + CHECKPROGRESS /* backtrack if no progress was made w.r.t. reg # */ +}; + +/* Accessors in a compiled regexp */ +#define Prog(re) Field(re, 0) +#define Cpool(re) Field(re, 1) +#define Normtable(re) Field(re, 2) +#define Numgroups(re) Int_val(Field(re, 3)) +#define Numregisters(re) Int_val(Field(re, 4)) +#define Startchars(re) Int_val(Field(re, 5)) + +/* Record positions of matched groups */ +#define NUM_GROUPS 32 +struct re_group { + unsigned char * start; + unsigned char * end; +}; +static struct re_group re_group[NUM_GROUPS]; + +/* Record positions reached during matching; used to check progress + in repeated matching of a regexp. */ +#define NUM_REGISTERS 64 +static unsigned char * re_register[NUM_REGISTERS]; + +/* The initial backtracking stack */ +static struct backtrack_stack initial_stack = { NULL, }; + +/* Free a chained list of backtracking stacks */ +static void free_backtrack_stack(struct backtrack_stack * stack) +{ + struct backtrack_stack * prevstack; + while ((prevstack = stack->previous) != NULL) { + stat_free(stack); + stack = prevstack; + } +} + +/* Membership in a bit vector representing a set of booleans */ +#define In_bitset(s,i,tmp) (tmp = (i), ((s)[tmp >> 3] >> (tmp & 7)) & 1) + +/* Determine if a character is a word constituent */ +static unsigned char re_word_letters[32] = { + 0, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 7, 254, 255, 255, 7, + 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 255, 255, 255, 127, 255 +}; +#define Is_word_letter(c) ((re_word_letters[(c) >> 3] >> ((c) & 7)) & 1) + +/* The bytecode interpreter for the NFA */ +static int re_match(value re, + unsigned char * starttxt, + register unsigned char * txt, + register unsigned char * endtxt, + int accept_partial_match) +{ + register value * pc; + intnat instr; + struct backtrack_stack * stack; + union backtrack_point * sp; + value cpool; + value normtable; + unsigned char c; + union backtrack_point back; + + { int i; + struct re_group * p; + unsigned char ** q; + for (p = &re_group[1], i = Numgroups(re); i > 1; i--, p++) + p->start = p->end = NULL; + for (q = &re_register[0], i = Numregisters(re); i > 0; i--, q++) + *q = NULL; + } + + pc = &Field(Prog(re), 0); + stack = &initial_stack; + sp = stack->point; + cpool = Cpool(re); + normtable = Normtable(re); + re_group[0].start = txt; + + while (1) { + instr = Long_val(*pc++); + switch (Opcode(instr)) { + case CHAR: + if (txt == endtxt) goto prefix_match; + if (*txt != Arg(instr)) goto backtrack; + txt++; + break; + case CHARNORM: + if (txt == endtxt) goto prefix_match; + if (Byte_u(normtable, *txt) != Arg(instr)) goto backtrack; + txt++; + break; + case STRING: { + unsigned char * s = + (unsigned char *) String_val(Field(cpool, Arg(instr))); + while ((c = *s++) != 0) { + if (txt == endtxt) goto prefix_match; + if (c != *txt) goto backtrack; + txt++; + } + break; + } + case STRINGNORM: { + unsigned char * s = + (unsigned char *) String_val(Field(cpool, Arg(instr))); + while ((c = *s++) != 0) { + if (txt == endtxt) goto prefix_match; + if (c != Byte_u(normtable, *txt)) goto backtrack; + txt++; + } + break; + } + case CHARCLASS: + if (txt == endtxt) goto prefix_match; + if (! In_bitset(String_val(Field(cpool, Arg(instr))), *txt, c)) + goto backtrack; + txt++; + break; + case BOL: + if (txt > starttxt && txt[-1] != '\n') goto backtrack; + break; + case EOL: + if (txt < endtxt && *txt != '\n') goto backtrack; + break; + case WORDBOUNDARY: + /* At beginning and end of text: no + At beginning of text: OK if current char is a letter + At end of text: OK if previous char is a letter + Otherwise: + OK if previous char is a letter and current char not a letter + or previous char is not a letter and current char is a letter */ + if (txt == starttxt) { + if (txt == endtxt) goto prefix_match; + if (Is_word_letter(txt[0])) break; + goto backtrack; + } else if (txt == endtxt) { + if (Is_word_letter(txt[-1])) break; + goto backtrack; + } else { + if (Is_word_letter(txt[-1]) != Is_word_letter(txt[0])) break; + goto backtrack; + } + case BEGGROUP: { + int group_no = Arg(instr); + struct re_group * group = &(re_group[group_no]); + back.undo.loc = &(group->start); + back.undo.val = group->start; + group->start = txt; + goto push; + } + case ENDGROUP: { + int group_no = Arg(instr); + struct re_group * group = &(re_group[group_no]); + back.undo.loc = &(group->end); + back.undo.val = group->end; + group->end = txt; + goto push; + } + case REFGROUP: { + int group_no = Arg(instr); + struct re_group * group = &(re_group[group_no]); + unsigned char * s; + if (group->start == NULL || group->end == NULL) goto backtrack; + for (s = group->start; s < group->end; s++) { + if (txt == endtxt) goto prefix_match; + if (*s != *txt) goto backtrack; + txt++; + } + break; + } + case ACCEPT: + goto accept; + case SIMPLEOPT: { + char * set = String_val(Field(cpool, Arg(instr))); + if (txt < endtxt && In_bitset(set, *txt, c)) txt++; + break; + } + case SIMPLESTAR: { + char * set = String_val(Field(cpool, Arg(instr))); + while (txt < endtxt && In_bitset(set, *txt, c)) + txt++; + break; + } + case SIMPLEPLUS: { + char * set = String_val(Field(cpool, Arg(instr))); + if (txt == endtxt) goto prefix_match; + if (! In_bitset(set, *txt, c)) goto backtrack; + txt++; + while (txt < endtxt && In_bitset(set, *txt, c)) + txt++; + break; + } + case GOTO: + pc = pc + SignedArg(instr); + break; + case PUSHBACK: + back.pos.pc = Set_tag(pc + SignedArg(instr)); + back.pos.txt = txt; + goto push; + case SETMARK: { + int reg_no = Arg(instr); + unsigned char ** reg = &(re_register[reg_no]); + back.undo.loc = reg; + back.undo.val = *reg; + *reg = txt; + goto push; + } + case CHECKPROGRESS: { + int reg_no = Arg(instr); + if (re_register[reg_no] == txt) + goto backtrack; + break; + } + default: + caml_fatal_error ("impossible case in re_match"); + } + /* Continue with next instruction */ + continue; + + push: + /* Push an item on the backtrack stack and continue with next instr */ + if (sp == stack->point + BACKTRACK_STACK_BLOCK_SIZE) { + struct backtrack_stack * newstack = + stat_alloc(sizeof(struct backtrack_stack)); + newstack->previous = stack; + stack = newstack; + sp = stack->point; + } + *sp = back; + sp++; + continue; + + prefix_match: + /* We get here when matching failed because the end of text + was encountered. */ + if (accept_partial_match) goto accept; + + backtrack: + /* We get here when matching fails. Backtrack to most recent saved + program point, undoing variable assignments on the way. */ + while (1) { + if (sp == stack->point) { + struct backtrack_stack * prevstack = stack->previous; + if (prevstack == NULL) return 0; + stat_free(stack); + stack = prevstack; + sp = stack->point + BACKTRACK_STACK_BLOCK_SIZE; + } + sp--; + if (Tag_is_set(sp->pos.pc)) { + pc = Clear_tag(sp->pos.pc); + txt = sp->pos.txt; + break; + } else { + *(sp->undo.loc) = sp->undo.val; + } + } + continue; + } + + accept: + /* We get here when the regexp was successfully matched */ + free_backtrack_stack(stack); + re_group[0].end = txt; + return 1; +} + +/* Allocate an integer array containing the positions of the matched groups. + Beginning of group #N is at 2N, end is at 2N+1. + Take position = -1 when group wasn't matched. */ + +static value re_alloc_groups(value re, value str) +{ + CAMLparam1(str); + CAMLlocal1(res); + unsigned char * starttxt = (unsigned char *) String_val(str); + int n = Numgroups(re); + int i; + struct re_group * group; + + res = alloc(n * 2, 0); + for (i = 0; i < n; i++) { + group = &(re_group[i]); + if (group->start == NULL || group->end == NULL) { + Field(res, i * 2) = Val_int(-1); + Field(res, i * 2 + 1) = Val_int(-1); + } else { + Field(res, i * 2) = Val_long(group->start - starttxt); + Field(res, i * 2 + 1) = Val_long(group->end - starttxt); + } + } + CAMLreturn(res); +} + +/* String matching and searching. All functions return the empty array + on failure, and an array of positions on success. */ + +CAMLprim value re_string_match(value re, value str, value pos) +{ + unsigned char * starttxt = &Byte_u(str, 0); + unsigned char * txt = &Byte_u(str, Long_val(pos)); + unsigned char * endtxt = &Byte_u(str, string_length(str)); + + if (txt < starttxt || txt > endtxt) + invalid_argument("Str.string_match"); + if (re_match(re, starttxt, txt, endtxt, 0)) { + return re_alloc_groups(re, str); + } else { + return Atom(0); + } +} + +CAMLprim value re_partial_match(value re, value str, value pos) +{ + unsigned char * starttxt = &Byte_u(str, 0); + unsigned char * txt = &Byte_u(str, Long_val(pos)); + unsigned char * endtxt = &Byte_u(str, string_length(str)); + + if (txt < starttxt || txt > endtxt) + invalid_argument("Str.string_partial_match"); + if (re_match(re, starttxt, txt, endtxt, 1)) { + return re_alloc_groups(re, str); + } else { + return Atom(0); + } +} + +CAMLprim value re_search_forward(value re, value str, value startpos) +{ + unsigned char * starttxt = &Byte_u(str, 0); + unsigned char * txt = &Byte_u(str, Long_val(startpos)); + unsigned char * endtxt = &Byte_u(str, string_length(str)); + unsigned char * startchars; + + if (txt < starttxt || txt > endtxt) + invalid_argument("Str.search_forward"); + if (Startchars(re) == -1) { + do { + if (re_match(re, starttxt, txt, endtxt, 0)) + return re_alloc_groups(re, str); + txt++; + } while (txt <= endtxt); + return Atom(0); + } else { + startchars = + (unsigned char *) String_val(Field(Cpool(re), Startchars(re))); + do { + while (txt < endtxt && startchars[*txt] == 0) txt++; + if (re_match(re, starttxt, txt, endtxt, 0)) + return re_alloc_groups(re, str); + txt++; + } while (txt <= endtxt); + return Atom(0); + } +} + +CAMLprim value re_search_backward(value re, value str, value startpos) +{ + unsigned char * starttxt = &Byte_u(str, 0); + unsigned char * txt = &Byte_u(str, Long_val(startpos)); + unsigned char * endtxt = &Byte_u(str, string_length(str)); + unsigned char * startchars; + + if (txt < starttxt || txt > endtxt) + invalid_argument("Str.search_backward"); + if (Startchars(re) == -1) { + do { + if (re_match(re, starttxt, txt, endtxt, 0)) + return re_alloc_groups(re, str); + txt--; + } while (txt >= starttxt); + return Atom(0); + } else { + startchars = + (unsigned char *) String_val(Field(Cpool(re), Startchars(re))); + do { + while (txt > starttxt && startchars[*txt] == 0) txt--; + if (re_match(re, starttxt, txt, endtxt, 0)) + return re_alloc_groups(re, str); + txt--; + } while (txt >= starttxt); + return Atom(0); + } +} + +/* Replacement */ + +CAMLprim value re_replacement_text(value repl, value groups, value orig) +{ + CAMLparam3(repl, groups, orig); + CAMLlocal1(res); + mlsize_t start, end, len, n; + char * p, * q; + int c; + + len = 0; + p = String_val(repl); + n = string_length(repl); + while (n > 0) { + c = *p++; n--; + if(c != '\\') + len++; + else { + if (n == 0) failwith("Str.replace: illegal backslash sequence"); + c = *p++; n--; + switch (c) { + case '\\': + len++; break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + c -= '0'; + if (c*2 >= Wosize_val(groups)) + failwith("Str.replace: reference to unmatched group"); + start = Long_val(Field(groups, c*2)); + end = Long_val(Field(groups, c*2 + 1)); + if (start == (mlsize_t) -1) + failwith("Str.replace: reference to unmatched group"); + len += end - start; + break; + default: + len += 2; break; + } + } + } + res = alloc_string(len); + p = String_val(repl); + q = String_val(res); + n = string_length(repl); + while (n > 0) { + c = *p++; n--; + if(c != '\\') + *q++ = c; + else { + c = *p++; n--; + switch (c) { + case '\\': + *q++ = '\\'; break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + c -= '0'; + start = Long_val(Field(groups, c*2)); + end = Long_val(Field(groups, c*2 + 1)); + len = end - start; + memmove (q, &Byte(orig, start), len); + q += len; + break; + default: + *q++ = '\\'; *q++ = c; break; + } + } + } + CAMLreturn(res); +} + diff --git a/otherlibs/systhreads/.cvsignore b/otherlibs/systhreads/.cvsignore new file mode 100644 index 0000000..b175e39 --- /dev/null +++ b/otherlibs/systhreads/.cvsignore @@ -0,0 +1,3 @@ +*.x +thread.ml +so_locations diff --git a/otherlibs/systhreads/.depend b/otherlibs/systhreads/.depend new file mode 100644 index 0000000..fa6bbbd --- /dev/null +++ b/otherlibs/systhreads/.depend @@ -0,0 +1,43 @@ +posix.o: posix.c ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/backtrace.h \ + ../../byterun/mlvalues.h ../../byterun/callback.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/custom.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/io.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/printexc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/roots.h \ + ../../byterun/misc.h ../../byterun/memory.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/stacks.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h ../../byterun/sys.h \ + ../../byterun/misc.h +condition.cmi: mutex.cmi +event.cmi: +mutex.cmi: +thread.cmi: +threadUnix.cmi: +condition.cmo: mutex.cmi condition.cmi +condition.cmx: mutex.cmx condition.cmi +event.cmo: mutex.cmi condition.cmi event.cmi +event.cmx: mutex.cmx condition.cmx event.cmi +mutex.cmo: mutex.cmi +mutex.cmx: mutex.cmi +thread.cmo: thread.cmi +thread.cmx: thread.cmi +threadUnix.cmo: thread.cmi threadUnix.cmi +threadUnix.cmx: thread.cmx threadUnix.cmi +thread_posix.cmo: +thread_posix.cmx: +thread_win32.cmo: +thread_win32.cmx: diff --git a/otherlibs/systhreads/Makefile b/otherlibs/systhreads/Makefile new file mode 100644 index 0000000..537cf1b --- /dev/null +++ b/otherlibs/systhreads/Makefile @@ -0,0 +1,108 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.44 2008-07-15 15:31:32 frisch Exp $ + +include ../../config/Makefile + +CAMLC=../../ocamlcomp.sh -I ../unix +CAMLOPT=../../ocamlcompopt.sh -I ../unix +MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib +COMPFLAGS=-warn-error A -g + +BYTECODE_C_OBJS=posix_b.o +NATIVECODE_C_OBJS=posix_n.o + +THREAD_OBJS= thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo + +GENFILES=thread.ml + +all: libthreads.a threads.cma + +allopt: libthreadsnat.a threads.cmxa + +libthreads.a: $(BYTECODE_C_OBJS) + $(MKLIB) -o threads $(BYTECODE_C_OBJS) + +posix_b.o: posix.c + $(BYTECC) -O -I../../byterun $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS) \ + -c posix.c + mv posix.o posix_b.o + +# Dynamic linking with -lpthread is risky on many platforms, so +# do not create a shared object for libthreadsnat. +libthreadsnat.a: $(NATIVECODE_C_OBJS) + $(AR) rc libthreadsnat.a $(NATIVECODE_C_OBJS) + +posix_n.o: posix.c + $(NATIVECC) -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) -c posix.c + mv posix.o posix_n.o + +threads.cma: $(THREAD_OBJS) + $(MKLIB) -ocamlc '$(CAMLC)' -o threads $(THREAD_OBJS) \ + -cclib -lunix $(PTHREAD_LINK) + +# See remark above: force static linking of libthreadsnat.a +threads.cmxa: $(THREAD_OBJS:.cmo=.cmx) + $(CAMLOPT) -a -o threads.cmxa $(THREAD_OBJS:.cmo=.cmx) \ + -cclib -lthreadsnat $(PTHREAD_LINK) + +# Note: I removed "-cclib -lunix" from the line above. +# Indeed, if we link threads.cmxa, then we must also link unix.cmxa, +# which itself will pass -lunix to the C linker. It seems more +# modular to me this way. -- Alain + + +$(THREAD_OBJS:.cmo=.cmx): ../../ocamlopt + +thread.ml: thread_posix.ml + ln -s thread_posix.ml thread.ml + +partialclean: + rm -f *.cm* + +clean: partialclean + rm -f *.o *.a *.so + rm -f $(GENFILES) + +install: + if test -f dllthreads.so; then cp dllthreads.so $(STUBLIBDIR)/dllthreads.so; fi + cp libthreads.a $(LIBDIR)/libthreads.a + cd $(LIBDIR); $(RANLIB) libthreads.a + if test -d $(LIBDIR)/threads; then :; else mkdir $(LIBDIR)/threads; fi + cp $(THREAD_OBJS:.cmo=.cmi) threads.cma $(LIBDIR)/threads + rm -f $(LIBDIR)/threads/stdlib.cma + cp thread.mli mutex.mli condition.mli event.mli threadUnix.mli $(LIBDIR) + +installopt: + cp libthreadsnat.a $(LIBDIR)/libthreadsnat.a + cd $(LIBDIR); $(RANLIB) libthreadsnat.a + cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.a $(LIBDIR)/threads + cd $(LIBDIR)/threads; $(RANLIB) threads.a + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: $(GENFILES) + -gcc -MM -I../../byterun *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/systhreads/Makefile.nt b/otherlibs/systhreads/Makefile.nt new file mode 100644 index 0000000..26bbc23 --- /dev/null +++ b/otherlibs/systhreads/Makefile.nt @@ -0,0 +1,102 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.31 2007-11-06 15:16:56 frisch Exp $ + +include ../../config/Makefile + +# Compilation options +CAMLC=../../boot/ocamlrun ../../ocamlc -I ../../stdlib -I ../win32unix +CAMLOPT=../../boot/ocamlrun ../../ocamlopt -I ../../stdlib -I ../win32unix +COMPFLAGS=-warn-error A -g +MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib +CFLAGS=-I../../byterun $(EXTRACFLAGS) + +CAMLOBJS=thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo +CMIFILES=$(CAMLOBJS:.cmo=.cmi) +COBJS=win32_b.$(O) +COBJS_NAT=win32_n.$(O) + +GENFILES=thread.ml + +LIBNAME=threads + +all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES) + +allopt: lib$(LIBNAME).$(A) $(LIBNAME).cmxa $(LIBNAME).cmxs $(CMIFILES) + +$(LIBNAME).cma: $(CAMLOBJS) + $(MKLIB) -o $(LIBNAME) -ocamlc "..\\..\\boot\\ocamlrun ..\\..\\ocamlc" -linkall $(CAMLOBJS) $(LINKOPTS) + +lib$(LIBNAME).$(A): $(COBJS) + $(MKLIB) -o $(LIBNAME) $(COBJS) $(LDOPTS) + +win32_b.$(O): win32.c + $(BYTECC) $(BYTECCCOMPOPTS) $(CFLAGS) -c win32.c + mv win32.$(O) win32_b.$(O) + + + +$(LIBNAME).cmxa: $(CAMLOBJS:.cmo=.cmx) + $(MKLIB) -o $(LIBNAME)nat -ocamlopt "..\\..\\boot\\ocamlrun ..\\..\\ocamlopt" -linkall $(CAMLOBJS:.cmo=.cmx) $(LINKOPTS) + mv $(LIBNAME)nat.cmxa $(LIBNAME).cmxa + mv $(LIBNAME)nat.$(A) $(LIBNAME).$(A) + +$(LIBNAME).cmxs: $(LIBNAME).cmxa lib$(LIBNAME)nat.$(A) + $(CAMLOPT) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa -linkall + +lib$(LIBNAME)nat.$(A): $(COBJS_NAT) + $(MKLIB) -o $(LIBNAME)nat $(COBJS_NAT) $(LDOPTS) + +win32_n.$(O): win32.c + $(NATIVECC) -DNATIVE_CODE -O -I../../asmrun -I../../byterun $(NATIVECCCOMPOPTS) -c win32.c + mv win32.$(O) win32_n.$(O) + +$(CAMLOBJS:.cmo=.cmx): ../../ocamlopt + +thread.ml: thread_win32.ml + cp thread_win32.ml thread.ml + +partialclean: + rm -f *.cm* + +clean: partialclean + rm -f *.dll *.$(A) *.$(O) + rm -f $(GENFILES) + +install: + cp dllthreads.dll $(STUBLIBDIR)/dllthreads.dll + cp libthreads.$(A) $(LIBDIR)/libthreads.$(A) + mkdir -p $(LIBDIR)/threads + cp $(CMIFILES) threads.cma $(LIBDIR)/threads + rm -f $(LIBDIR)/threads/stdlib.cma + +installopt: + cp libthreadsnat.$(A) $(LIBDIR)/libthreadsnat.$(A) + cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.$(A) $(LIBDIR)/threads + cp threads.cmxs $(LIBDIR)/threads + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLC) -c -g $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: + +include .depend diff --git a/otherlibs/systhreads/Tests/Makefile b/otherlibs/systhreads/Tests/Makefile new file mode 100644 index 0000000..c3e255d --- /dev/null +++ b/otherlibs/systhreads/Tests/Makefile @@ -0,0 +1,44 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../../LICENSE.# +# # +######################################################################### + +# $Id: Makefile,v 1.11 2003-06-16 12:31:14 xleroy Exp $ + +PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt \ + test7.byt test8.byt test9.byt testA.byt sieve.byt \ + testio.byt testsocket.byt testsignal.byt testsignal2.byt \ + torture.byt + +include ../../../config/Makefile + +CAMLC=../../../boot/ocamlrun ../../../ocamlc -I .. -I ../../unix -I ../../../stdlib + +CAMLOPT=../../../boot/ocamlrun ../../../ocamlopt -I .. -I ../../unix -I ../../../stdlib + +all: $(PROGS) + +allopt: $(PROGS:.byt=.out) + +clean: + rm -f *.cm* *.byt *.out + rm -f $(PROGS:.byt=.ml) + +%.byt: ../../threads/Tests/%.ml + cp ../../threads/Tests/$*.ml $*.ml + $(CAMLC) -custom -o $*.byt unix.cma threads.cma $*.ml ../libthreads.a ../../unix/libunix.a -cclib -lpthread + +%.out: ../../threads/Tests/%.ml + cp ../../threads/Tests/$*.ml $*.ml + $(CAMLOPT) -o $*.out unix.cmxa threads.cmxa $*.ml ../libthreadsnat.a ../../unix/libunix.a -cclib -lpthread + +$(PROGS): ../threads.cma ../libthreads.a +$(PROGS:.byt=.out): ../threads.cmxa ../libthreadsnat.a diff --git a/otherlibs/systhreads/Tests/Makefile.nt b/otherlibs/systhreads/Tests/Makefile.nt new file mode 100644 index 0000000..2934028 --- /dev/null +++ b/otherlibs/systhreads/Tests/Makefile.nt @@ -0,0 +1,43 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../../LICENSE.# +# # +######################################################################### + +# $Id: Makefile.nt,v 1.9 2006-09-21 10:01:24 xleroy Exp $ + +PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt \ + test7.byt test8.byt test9.byt testA.byt sieve.byt \ + testio.byt testsocket.byt testwait.byt testsignal.byt testsignal2.byt \ + torture.byt + +include ../../../config/Makefile + +CAMLC=../../../boot/ocamlrun ../../../ocamlc -I .. -I ../../win32unix -I ../../../stdlib + +CAMLOPT=../../../boot/ocamlrun ../../../ocamlopt -I .. -I ../../win32unix -I ../../../stdlib + +all: $(PROGS) + +allopt: $(PROGS:.byt=.out) + +clean: + rm -f *.cm* *.byt *.out + rm -f $(PROGS:.byt=.ml) + +%.byt: ../../threads/Tests/%.ml + cp ../../threads/Tests/$*.ml $*.ml + $(CAMLC) -custom -o $*.byt unix.cma threads.cma $*.ml ../libthreads.$(A) ../../win32unix/libunix.$(A) + +%.out: ../../threads/Tests/%.ml + cp ../../threads/Tests/$*.ml $*.ml + $(CAMLOPT) -o $*.out unix.cmxa threads.cmxa $*.ml ../libthreadsnat.$(A) ../../win32unix/libunix.$(A) -cclib -lpthread + +$(PROGS): ../threads.cma ../libthreads.$(A) diff --git a/otherlibs/systhreads/condition.ml b/otherlibs/systhreads/condition.ml new file mode 100644 index 0000000..820ad4c --- /dev/null +++ b/otherlibs/systhreads/condition.ml @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Caml Special Light *) +(* *) +(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1995 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: condition.ml,v 1.6 2001-12-07 13:40:18 xleroy Exp $ *) + +type t +external create: unit -> t = "caml_condition_new" +external wait: t -> Mutex.t -> unit = "caml_condition_wait" +external signal: t -> unit = "caml_condition_signal" +external broadcast: t -> unit = "caml_condition_broadcast" diff --git a/otherlibs/systhreads/condition.mli b/otherlibs/systhreads/condition.mli new file mode 100644 index 0000000..c22c77c --- /dev/null +++ b/otherlibs/systhreads/condition.mli @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: condition.mli,v 1.6 2001-12-07 13:40:19 xleroy Exp $ *) + +(** Condition variables to synchronize between threads. + + Condition variables are used when one thread wants to wait until another + thread has finished doing something: the former thread ``waits'' on the + condition variable, the latter thread ``signals'' the condition when it + is done. Condition variables should always be protected by a mutex. + The typical use is (if [D] is a shared data structure, [m] its mutex, + and [c] is a condition variable): + {[ + Mutex.lock m; + while (* some predicate P over D is not satisfied *) do + Condition.wait c m + done; + (* Modify D *) + if (* the predicate P over D is now satified *) then Condition.signal c; + Mutex.unlock m + ]} +*) + +type t +(** The type of condition variables. *) + +val create : unit -> t +(** Return a new condition variable. *) + +val wait : t -> Mutex.t -> unit +(** [wait c m] atomically unlocks the mutex [m] and suspends the + calling process on the condition variable [c]. The process will + restart after the condition variable [c] has been signalled. + The mutex [m] is locked again before [wait] returns. *) + +val signal : t -> unit +(** [signal c] restarts one of the processes waiting on the + condition variable [c]. *) + +val broadcast : t -> unit +(** [broadcast c] restarts all processes waiting on the + condition variable [c]. *) diff --git a/otherlibs/systhreads/dllthreads.dlib b/otherlibs/systhreads/dllthreads.dlib new file mode 100644 index 0000000..40686f6 --- /dev/null +++ b/otherlibs/systhreads/dllthreads.dlib @@ -0,0 +1 @@ +win32_b.d.o diff --git a/otherlibs/systhreads/event.ml b/otherlibs/systhreads/event.ml new file mode 100644 index 0000000..331ba76 --- /dev/null +++ b/otherlibs/systhreads/event.ml @@ -0,0 +1,274 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* David Nowak and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: event.ml,v 1.9 2001-12-07 13:40:19 xleroy Exp $ *) + +(* Events *) +type 'a basic_event = + { poll: unit -> bool; + (* If communication can take place immediately, return true. *) + suspend: unit -> unit; + (* Offer the communication on the channel and get ready + to suspend current process. *) + result: unit -> 'a } + (* Return the result of the communication *) + +type 'a behavior = int ref -> Condition.t -> int -> 'a basic_event + +type 'a event = + Communication of 'a behavior + | Choose of 'a event list + | WrapAbort of 'a event * (unit -> unit) + | Guard of (unit -> 'a event) + +(* Communication channels *) +type 'a channel = + { mutable writes_pending: 'a communication Queue.t; + (* All offers to write on it *) + mutable reads_pending: 'a communication Queue.t } + (* All offers to read from it *) + +(* Communication offered *) +and 'a communication = + { performed: int ref; (* -1 if not performed yet, set to the number *) + (* of the matching communication after rendez-vous. *) + condition: Condition.t; (* To restart the blocked thread. *) + mutable data: 'a option; (* The data sent or received. *) + event_number: int } (* Event number in select *) + +(* Create a channel *) + +let new_channel () = + { writes_pending = Queue.create(); + reads_pending = Queue.create() } + +(* Basic synchronization function *) + +let masterlock = Mutex.create() + +let do_aborts abort_env genev performed = + if abort_env <> [] then begin + if performed >= 0 then begin + let ids_done = snd genev.(performed) in + List.iter + (fun (id,f) -> if not (List.mem id ids_done) then f ()) + abort_env + end else begin + List.iter (fun (_,f) -> f ()) abort_env + end + end + +let basic_sync abort_env genev = + let performed = ref (-1) in + let condition = Condition.create() in + let bev = Array.create (Array.length genev) + (fst (genev.(0)) performed condition 0) in + for i = 1 to Array.length genev - 1 do + bev.(i) <- (fst genev.(i)) performed condition i + done; + (* See if any of the events is already activable *) + let rec poll_events i = + if i >= Array.length bev + then false + else bev.(i).poll() || poll_events (i+1) in + Mutex.lock masterlock; + if not (poll_events 0) then begin + (* Suspend on all events *) + for i = 0 to Array.length bev - 1 do bev.(i).suspend() done; + (* Wait until the condition is signalled *) + Condition.wait condition masterlock + end; + Mutex.unlock masterlock; + (* Extract the result *) + if abort_env = [] then + (* Preserve tail recursion *) + bev.(!performed).result() + else begin + let num = !performed in + let result = bev.(num).result() in + (* Handle the aborts and return the result *) + do_aborts abort_env genev num; + result + end + +(* Apply a random permutation on an array *) + +let scramble_array a = + let len = Array.length a in + if len = 0 then invalid_arg "Event.choose"; + for i = len - 1 downto 1 do + let j = Random.int (i + 1) in + let temp = a.(i) in a.(i) <- a.(j); a.(j) <- temp + done; + a + +(* Main synchronization function *) + +let gensym = let count = ref 0 in fun () -> incr count; !count + +let rec flatten_event + (abort_list : int list) + (accu : ('a behavior * int list) list) + (accu_abort : (int * (unit -> unit)) list) + ev = + match ev with + Communication bev -> ((bev,abort_list) :: accu) , accu_abort + | WrapAbort (ev,fn) -> + let id = gensym () in + flatten_event (id :: abort_list) accu ((id,fn)::accu_abort) ev + | Choose evl -> + let rec flatten_list accu' accu_abort'= function + ev :: l -> + let (accu'',accu_abort'') = + flatten_event abort_list accu' accu_abort' ev in + flatten_list accu'' accu_abort'' l + | [] -> (accu',accu_abort') in + flatten_list accu accu_abort evl + | Guard fn -> flatten_event abort_list accu accu_abort (fn ()) + +let sync ev = + let (evl,abort_env) = flatten_event [] [] [] ev in + basic_sync abort_env (scramble_array(Array.of_list evl)) + +(* Event polling -- like sync, but non-blocking *) + +let basic_poll abort_env genev = + let performed = ref (-1) in + let condition = Condition.create() in + let bev = Array.create(Array.length genev) + (fst genev.(0) performed condition 0) in + for i = 1 to Array.length genev - 1 do + bev.(i) <- fst genev.(i) performed condition i + done; + (* See if any of the events is already activable *) + let rec poll_events i = + if i >= Array.length bev + then false + else bev.(i).poll() || poll_events (i+1) in + Mutex.lock masterlock; + let ready = poll_events 0 in + if ready then begin + (* Extract the result *) + Mutex.unlock masterlock; + let result = Some(bev.(!performed).result()) in + do_aborts abort_env genev !performed; result + end else begin + (* Cancel the communication offers *) + performed := 0; + Mutex.unlock masterlock; + do_aborts abort_env genev (-1); + None + end + +let poll ev = + let (evl,abort_env) = flatten_event [] [] [] ev in + basic_poll abort_env (scramble_array(Array.of_list evl)) + +(* Remove all communication opportunities already synchronized *) + +let cleanup_queue q = + let q' = Queue.create() in + Queue.iter (fun c -> if !(c.performed) = -1 then Queue.add c q') q; + q' + +(* Event construction *) + +let always data = + Communication(fun performed condition evnum -> + { poll = (fun () -> performed := evnum; true); + suspend = (fun () -> ()); + result = (fun () -> data) }) + +let send channel data = + Communication(fun performed condition evnum -> + let wcomm = + { performed = performed; + condition = condition; + data = Some data; + event_number = evnum } in + { poll = (fun () -> + let rec poll () = + let rcomm = Queue.take channel.reads_pending in + if !(rcomm.performed) >= 0 then + poll () + else begin + rcomm.data <- wcomm.data; + performed := evnum; + rcomm.performed := rcomm.event_number; + Condition.signal rcomm.condition + end in + try + poll(); + true + with Queue.Empty -> + false); + suspend = (fun () -> + channel.writes_pending <- cleanup_queue channel.writes_pending; + Queue.add wcomm channel.writes_pending); + result = (fun () -> ()) }) + +let receive channel = + Communication(fun performed condition evnum -> + let rcomm = + { performed = performed; + condition = condition; + data = None; + event_number = evnum } in + { poll = (fun () -> + let rec poll () = + let wcomm = Queue.take channel.writes_pending in + if !(wcomm.performed) >= 0 then + poll () + else begin + rcomm.data <- wcomm.data; + performed := evnum; + wcomm.performed := wcomm.event_number; + Condition.signal wcomm.condition + end in + try + poll(); + true + with Queue.Empty -> + false); + suspend = (fun () -> + channel.reads_pending <- cleanup_queue channel.reads_pending; + Queue.add rcomm channel.reads_pending); + result = (fun () -> + match rcomm.data with + None -> invalid_arg "Event.receive" + | Some res -> res) }) + +let choose evl = Choose evl + +let wrap_abort ev fn = WrapAbort(ev,fn) + +let guard fn = Guard fn + +let rec wrap ev fn = + match ev with + Communication genev -> + Communication(fun performed condition evnum -> + let bev = genev performed condition evnum in + { poll = bev.poll; + suspend = bev.suspend; + result = (fun () -> fn(bev.result())) }) + | Choose evl -> + Choose(List.map (fun ev -> wrap ev fn) evl) + | WrapAbort (ev, f') -> + WrapAbort (wrap ev fn, f') + | Guard gu -> + Guard(fun () -> wrap (gu()) fn) + +(* Convenience functions *) + +let select evl = sync(Choose evl) diff --git a/otherlibs/systhreads/event.mli b/otherlibs/systhreads/event.mli new file mode 100644 index 0000000..73b990d --- /dev/null +++ b/otherlibs/systhreads/event.mli @@ -0,0 +1,82 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* David Nowak and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: event.mli,v 1.10 2006-01-12 03:24:56 garrigue Exp $ *) + +(** First-class synchronous communication. + + This module implements synchronous inter-thread communications over + channels. As in John Reppy's Concurrent ML system, the communication + events are first-class values: they can be built and combined + independently before being offered for communication. +*) + +type 'a channel +(** The type of communication channels carrying values of type ['a]. *) + +val new_channel : unit -> 'a channel +(** Return a new channel. *) + +type +'a event +(** The type of communication events returning a result of type ['a]. *) + +(** [send ch v] returns the event consisting in sending the value [v] + over the channel [ch]. The result value of this event is [()]. *) +val send : 'a channel -> 'a -> unit event + +(** [receive ch] returns the event consisting in receiving a value + from the channel [ch]. The result value of this event is the + value received. *) +val receive : 'a channel -> 'a event + +val always : 'a -> 'a event +(** [always v] returns an event that is always ready for + synchronization. The result value of this event is [v]. *) + +val choose : 'a event list -> 'a event +(** [choose evl] returns the event that is the alternative of + all the events in the list [evl]. *) + +val wrap : 'a event -> ('a -> 'b) -> 'b event +(** [wrap ev fn] returns the event that performs the same communications + as [ev], then applies the post-processing function [fn] + on the return value. *) + +val wrap_abort : 'a event -> (unit -> unit) -> 'a event +(** [wrap_abort ev fn] returns the event that performs + the same communications as [ev], but if it is not selected + the function [fn] is called after the synchronization. *) + +val guard : (unit -> 'a event) -> 'a event +(** [guard fn] returns the event that, when synchronized, computes + [fn()] and behaves as the resulting event. This allows to + compute events with side-effects at the time of the synchronization + operation. *) + +val sync : 'a event -> 'a +(** ``Synchronize'' on an event: offer all the communication + possibilities specified in the event to the outside world, + and block until one of the communications succeed. The result + value of that communication is returned. *) + +val select : 'a event list -> 'a +(** ``Synchronize'' on an alternative of events. + [select evl] is shorthand for [sync(choose evl)]. *) + +val poll : 'a event -> 'a option +(** Non-blocking version of {!Event.sync}: offer all the communication + possibilities specified in the event to the outside world, + and if one can take place immediately, perform it and return + [Some r] where [r] is the result value of that communication. + Otherwise, return [None] without blocking. *) + diff --git a/otherlibs/systhreads/libthreads.clib b/otherlibs/systhreads/libthreads.clib new file mode 100644 index 0000000..111ec5a --- /dev/null +++ b/otherlibs/systhreads/libthreads.clib @@ -0,0 +1 @@ +posix_b.o diff --git a/otherlibs/systhreads/libthreadswin32.clib b/otherlibs/systhreads/libthreadswin32.clib new file mode 100644 index 0000000..51b11a2 --- /dev/null +++ b/otherlibs/systhreads/libthreadswin32.clib @@ -0,0 +1 @@ +win32_b.o diff --git a/otherlibs/systhreads/mutex.ml b/otherlibs/systhreads/mutex.ml new file mode 100644 index 0000000..47db158 --- /dev/null +++ b/otherlibs/systhreads/mutex.ml @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Caml Special Light *) +(* *) +(* Xavier Leroy and Pascal Cuoq, INRIA Rocquencourt *) +(* *) +(* Copyright 1995 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: mutex.ml,v 1.4 2001-12-07 13:40:19 xleroy Exp $ *) + +type t +external create: unit -> t = "caml_mutex_new" +external lock: t -> unit = "caml_mutex_lock" +external try_lock: t -> bool = "caml_mutex_try_lock" +external unlock: t -> unit = "caml_mutex_unlock" diff --git a/otherlibs/systhreads/mutex.mli b/otherlibs/systhreads/mutex.mli new file mode 100644 index 0000000..0865e54 --- /dev/null +++ b/otherlibs/systhreads/mutex.mli @@ -0,0 +1,50 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: mutex.mli,v 1.6 2001-12-07 13:40:19 xleroy Exp $ *) + +(** Locks for mutual exclusion. + + Mutexes (mutual-exclusion locks) are used to implement critical sections + and protect shared mutable data structures against concurrent accesses. + The typical use is (if [m] is the mutex associated with the data structure + [D]): + {[ + Mutex.lock m; + (* Critical section that operates over D *); + Mutex.unlock m + ]} +*) + +type t +(** The type of mutexes. *) + +val create : unit -> t +(** Return a new mutex. *) + +val lock : t -> unit +(** Lock the given mutex. Only one thread can have the mutex locked + at any time. A thread that attempts to lock a mutex already locked + by another thread will suspend until the other thread unlocks + the mutex. *) + +val try_lock : t -> bool +(** Same as {!Mutex.lock}, but does not suspend the calling thread if + the mutex is already locked: just return [false] immediately + in that case. If the mutex is unlocked, lock it and + return [true]. *) + +val unlock : t -> unit +(** Unlock the given mutex. Other threads suspended trying to lock + the mutex will restart. *) + diff --git a/otherlibs/systhreads/posix.c b/otherlibs/systhreads/posix.c new file mode 100644 index 0000000..a606727 --- /dev/null +++ b/otherlibs/systhreads/posix.c @@ -0,0 +1,926 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ +/* */ +/* Copyright 1995 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: posix.c,v 1.58 2008-09-27 10:46:55 xleroy Exp $ */ + +/* Thread interface for POSIX 1003.1c threads */ + +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> +#ifdef __sun +#define _POSIX_PTHREAD_SEMANTICS +#endif +#include <signal.h> +#include <sys/time.h> +#ifdef __linux__ +#include <unistd.h> +#endif +#include "alloc.h" +#include "backtrace.h" +#include "callback.h" +#include "custom.h" +#include "fail.h" +#include "io.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "printexc.h" +#include "roots.h" +#include "signals.h" +#ifdef NATIVE_CODE +#include "stack.h" +#else +#include "stacks.h" +#endif +#include "sys.h" + +/* Initial size of stack when a thread is created (4 Ko) */ +#define Thread_stack_size (Stack_size / 4) + +/* Max computation time before rescheduling, in microseconds (50ms) */ +#define Thread_timeout 50000 + +/* The ML value describing a thread (heap-allocated) */ + +struct caml_thread_descr { + value ident; /* Unique integer ID */ + value start_closure; /* The closure to start this thread */ + value terminated; /* Mutex held while the thread is running */ +}; + +#define Ident(v) (((struct caml_thread_descr *)(v))->ident) +#define Start_closure(v) (((struct caml_thread_descr *)(v))->start_closure) +#define Terminated(v) (((struct caml_thread_descr *)(v))->terminated) + +/* The infos on threads (allocated via malloc()) */ + +struct caml_thread_struct { + pthread_t pthread; /* The Posix thread id */ + value descr; /* The heap-allocated descriptor (root) */ + struct caml_thread_struct * next; /* Double linking of running threads */ + struct caml_thread_struct * prev; +#ifdef NATIVE_CODE + char * bottom_of_stack; /* Saved value of caml_bottom_of_stack */ + uintnat last_retaddr; /* Saved value of caml_last_return_address */ + value * gc_regs; /* Saved value of caml_gc_regs */ + char * exception_pointer; /* Saved value of caml_exception_pointer */ + struct caml__roots_block * local_roots; /* Saved value of local_roots */ + struct longjmp_buffer * exit_buf; /* For thread exit */ +#else + value * stack_low; /* The execution stack for this thread */ + value * stack_high; + value * stack_threshold; + value * sp; /* Saved value of extern_sp for this thread */ + value * trapsp; /* Saved value of trapsp for this thread */ + struct caml__roots_block * local_roots; /* Saved value of local_roots */ + struct longjmp_buffer * external_raise; /* Saved external_raise */ +#endif + int backtrace_pos; /* Saved backtrace_pos */ + code_t * backtrace_buffer; /* Saved backtrace_buffer */ + value backtrace_last_exn; /* Saved backtrace_last_exn (root) */ +}; + +typedef struct caml_thread_struct * caml_thread_t; + +/* The descriptor for the currently executing thread */ +static caml_thread_t curr_thread = NULL; + +/* Track whether one thread is running Caml code. There can be + at most one such thread at any time. */ +static volatile int caml_runtime_busy = 1; + +/* Number of threads waiting to run Caml code. */ +static volatile int caml_runtime_waiters = 0; + +/* Mutex that protects the two variables above. */ +static pthread_mutex_t caml_runtime_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* Condition signaled when caml_runtime_busy becomes 0 */ +static pthread_cond_t caml_runtime_is_free = PTHREAD_COND_INITIALIZER; + +/* The key used for storing the thread descriptor in the specific data + of the corresponding Posix thread. */ +static pthread_key_t thread_descriptor_key; + +/* The key used for unlocking I/O channels on exceptions */ +static pthread_key_t last_channel_locked_key; + +/* Identifier for next thread creation */ +static intnat thread_next_ident = 0; + +/* Forward declarations */ +value caml_threadstatus_new (void); +void caml_threadstatus_terminate (value); +int caml_threadstatus_wait (value); +static void caml_pthread_check (int, char *); + +/* Imports for the native-code compiler */ +extern struct longjmp_buffer caml_termination_jmpbuf; +extern void (*caml_termination_hook)(void *); + +/* Hook for scanning the stacks of the other threads */ + +static void (*prev_scan_roots_hook) (scanning_action); + +static void caml_thread_scan_roots(scanning_action action) +{ + caml_thread_t th; + + th = curr_thread; + do { + (*action)(th->descr, &th->descr); + (*action)(th->backtrace_last_exn, &th->backtrace_last_exn); + /* Don't rescan the stack of the current thread, it was done already */ + if (th != curr_thread) { +#ifdef NATIVE_CODE + if (th->bottom_of_stack != NULL) + do_local_roots(action, th->bottom_of_stack, th->last_retaddr, + th->gc_regs, th->local_roots); +#else + do_local_roots(action, th->sp, th->stack_high, th->local_roots); +#endif + } + th = th->next; + } while (th != curr_thread); + /* Hook */ + if (prev_scan_roots_hook != NULL) (*prev_scan_roots_hook)(action); +} + +/* Hooks for enter_blocking_section and leave_blocking_section */ + +static void caml_thread_enter_blocking_section(void) +{ + /* Save the stack-related global variables in the thread descriptor + of the current thread */ +#ifdef NATIVE_CODE + curr_thread->bottom_of_stack = caml_bottom_of_stack; + curr_thread->last_retaddr = caml_last_return_address; + curr_thread->gc_regs = caml_gc_regs; + curr_thread->exception_pointer = caml_exception_pointer; + curr_thread->local_roots = local_roots; +#else + curr_thread->stack_low = stack_low; + curr_thread->stack_high = stack_high; + curr_thread->stack_threshold = stack_threshold; + curr_thread->sp = extern_sp; + curr_thread->trapsp = trapsp; + curr_thread->local_roots = local_roots; + curr_thread->external_raise = external_raise; +#endif + curr_thread->backtrace_pos = backtrace_pos; + curr_thread->backtrace_buffer = backtrace_buffer; + curr_thread->backtrace_last_exn = backtrace_last_exn; + /* Tell other threads that the runtime is free */ + pthread_mutex_lock(&caml_runtime_mutex); + caml_runtime_busy = 0; + pthread_mutex_unlock(&caml_runtime_mutex); + pthread_cond_signal(&caml_runtime_is_free); +} + +static void caml_thread_leave_blocking_section(void) +{ + /* Wait until the runtime is free */ + pthread_mutex_lock(&caml_runtime_mutex); + while (caml_runtime_busy) { + caml_runtime_waiters++; + pthread_cond_wait(&caml_runtime_is_free, &caml_runtime_mutex); + caml_runtime_waiters--; + } + caml_runtime_busy = 1; + pthread_mutex_unlock(&caml_runtime_mutex); + /* Update curr_thread to point to the thread descriptor corresponding + to the thread currently executing */ + curr_thread = pthread_getspecific(thread_descriptor_key); + /* Restore the stack-related global variables */ +#ifdef NATIVE_CODE + caml_bottom_of_stack= curr_thread->bottom_of_stack; + caml_last_return_address = curr_thread->last_retaddr; + caml_gc_regs = curr_thread->gc_regs; + caml_exception_pointer = curr_thread->exception_pointer; + local_roots = curr_thread->local_roots; +#else + stack_low = curr_thread->stack_low; + stack_high = curr_thread->stack_high; + stack_threshold = curr_thread->stack_threshold; + extern_sp = curr_thread->sp; + trapsp = curr_thread->trapsp; + local_roots = curr_thread->local_roots; + external_raise = curr_thread->external_raise; +#endif + backtrace_pos = curr_thread->backtrace_pos; + backtrace_buffer = curr_thread->backtrace_buffer; + backtrace_last_exn = curr_thread->backtrace_last_exn; +} + +static int caml_thread_try_leave_blocking_section(void) +{ + /* Disable immediate processing of signals (PR#3659). + try_leave_blocking_section always fails, forcing the signal to be + recorded and processed at the next leave_blocking_section or + polling. */ + return 0; +} + +/* Hooks for I/O locking */ + +static void caml_io_mutex_free(struct channel *chan) +{ + pthread_mutex_t * mutex = chan->mutex; + if (mutex != NULL) { + pthread_mutex_destroy(mutex); + stat_free((char *) mutex); + } +} + +static void caml_io_mutex_lock(struct channel *chan) +{ + if (chan->mutex == NULL) { + pthread_mutex_t * mutex = + (pthread_mutex_t *) stat_alloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(mutex, NULL); + chan->mutex = (void *) mutex; + } + /* PR#4351: first try to acquire mutex without releasing the master lock */ + if (pthread_mutex_trylock(chan->mutex) == 0) { + pthread_setspecific(last_channel_locked_key, (void *) chan); + return; + } + /* If unsuccessful, block on mutex */ + enter_blocking_section(); + pthread_mutex_lock(chan->mutex); + /* Problem: if a signal occurs at this point, + and the signal handler raises an exception, we will not + unlock the mutex. The alternative (doing the setspecific + before locking the mutex is also incorrect, since we could + then unlock a mutex that is unlocked or locked by someone else. */ + pthread_setspecific(last_channel_locked_key, (void *) chan); + leave_blocking_section(); +} + +static void caml_io_mutex_unlock(struct channel *chan) +{ + pthread_mutex_unlock(chan->mutex); + pthread_setspecific(last_channel_locked_key, NULL); +} + +static void caml_io_mutex_unlock_exn(void) +{ + struct channel * chan = pthread_getspecific(last_channel_locked_key); + if (chan != NULL) caml_io_mutex_unlock(chan); +} + +/* The "tick" thread fakes a SIGVTALRM signal at regular intervals. */ + +static void * caml_thread_tick(void * arg) +{ + struct timeval timeout; + sigset_t mask; +#ifdef __linux__ + int tickcount = 0; +#endif + + /* Block all signals so that we don't try to execute + a Caml signal handler */ + sigfillset(&mask); + pthread_sigmask(SIG_BLOCK, &mask, NULL); + while(1) { + /* select() seems to be the most efficient way to suspend the + thread for sub-second intervals */ + timeout.tv_sec = 0; + timeout.tv_usec = Thread_timeout; + select(0, NULL, NULL, NULL, &timeout); + /* This signal should never cause a callback, so don't go through + handle_signal(), tweak the global variable directly. */ + caml_pending_signals[SIGVTALRM] = 1; + caml_signals_are_pending = 1; +#ifdef NATIVE_CODE + young_limit = young_end; +#else + something_to_do = 1; +#endif +#ifdef __linux__ + /* Hack around LinuxThreads' non-standard signal handling: + if program is killed on a signal, e.g. SIGINT, the current + thread will not die on this signal (because of the signal blocking + above). Hence, periodically check that the thread manager (our + parent process) still exists. */ + tickcount++; + if (tickcount >= 2000000 / Thread_timeout) { /* every 2 secs approx */ + tickcount = 0; + if (getppid() == 1) pthread_exit(NULL); + } +#endif + } + return NULL; /* prevents compiler warning */ +} + +/* Reinitialize the thread machinery after a fork() (PR#4577) */ + +static void caml_thread_reinitialize(void) +{ + caml_thread_t thr, next; + pthread_t tick_pthread; + pthread_attr_t attr; + struct channel * chan; + + /* Remove all other threads (now nonexistent) + from the doubly-linked list of threads */ + thr = curr_thread->next; + while (thr != curr_thread) { + next = thr->next; + stat_free(thr); + thr = next; + } + curr_thread->next = curr_thread; + curr_thread->prev = curr_thread; + /* Reinitialize the master lock machinery, + just in case the fork happened while other threads were doing + leave_blocking_section */ + pthread_mutex_init(&caml_runtime_mutex, NULL); + pthread_cond_init(&caml_runtime_is_free, NULL); + caml_runtime_waiters = 0; /* no other thread is waiting for the RTS */ + caml_runtime_busy = 1; /* normally useless */ + /* Reinitialize all IO mutexes */ + for (chan = caml_all_opened_channels; + chan != NULL; + chan = chan->next) { + if (chan->mutex != NULL) pthread_mutex_init(chan->mutex, NULL); + } + /* Fork a new tick thread */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&tick_pthread, &attr, caml_thread_tick, NULL); +} + +/* Initialize the thread machinery */ + +value caml_thread_initialize(value unit) /* ML */ +{ + pthread_t tick_pthread; + pthread_attr_t attr; + value mu = Val_unit; + value descr; + + /* Protect against repeated initialization (PR#1325) */ + if (curr_thread != NULL) return Val_unit; + Begin_root (mu); + /* Initialize the keys */ + pthread_key_create(&thread_descriptor_key, NULL); + pthread_key_create(&last_channel_locked_key, NULL); + /* Create and initialize the termination semaphore */ + mu = caml_threadstatus_new(); + /* Create a descriptor for the current thread */ + descr = alloc_small(3, 0); + Ident(descr) = Val_long(thread_next_ident); + Start_closure(descr) = Val_unit; + Terminated(descr) = mu; + thread_next_ident++; + /* Create an info block for the current thread */ + curr_thread = + (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); + curr_thread->pthread = pthread_self(); + curr_thread->descr = descr; + curr_thread->next = curr_thread; + curr_thread->prev = curr_thread; +#ifdef NATIVE_CODE + curr_thread->exit_buf = &caml_termination_jmpbuf; +#endif + /* The stack-related fields will be filled in at the next + enter_blocking_section */ + /* Associate the thread descriptor with the thread */ + pthread_setspecific(thread_descriptor_key, (void *) curr_thread); + /* Set up the hooks */ + prev_scan_roots_hook = scan_roots_hook; + scan_roots_hook = caml_thread_scan_roots; + enter_blocking_section_hook = caml_thread_enter_blocking_section; + leave_blocking_section_hook = caml_thread_leave_blocking_section; + try_leave_blocking_section_hook = caml_thread_try_leave_blocking_section; +#ifdef NATIVE_CODE + caml_termination_hook = pthread_exit; +#endif + caml_channel_mutex_free = caml_io_mutex_free; + caml_channel_mutex_lock = caml_io_mutex_lock; + caml_channel_mutex_unlock = caml_io_mutex_unlock; + caml_channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; + /* Fork the tick thread */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + caml_pthread_check( + pthread_create(&tick_pthread, &attr, caml_thread_tick, NULL), + "Thread.init"); + /* Set up fork() to reinitialize the thread machinery in the child + (PR#4577) */ + pthread_atfork(NULL, NULL, caml_thread_reinitialize); + End_roots(); + return Val_unit; +} + +/* Thread cleanup at termination */ + +static void caml_thread_stop(void) +{ + caml_thread_t th = curr_thread; + + /* Signal that the thread has terminated */ + caml_threadstatus_terminate(Terminated(th->descr)); + /* Remove th from the doubly-linked list of threads */ + th->next->prev = th->prev; + th->prev->next = th->next; + /* Release the runtime system */ + pthread_mutex_lock(&caml_runtime_mutex); + caml_runtime_busy = 0; + pthread_mutex_unlock(&caml_runtime_mutex); + pthread_cond_signal(&caml_runtime_is_free); +#ifndef NATIVE_CODE + /* Free the memory resources */ + stat_free(th->stack_low); +#endif + if (th->backtrace_buffer != NULL) free(th->backtrace_buffer); + /* Free the thread descriptor */ + stat_free(th); +} + +/* Create a thread */ + +static void * caml_thread_start(void * arg) +{ + caml_thread_t th = (caml_thread_t) arg; + value clos; +#ifdef NATIVE_CODE + struct longjmp_buffer termination_buf; +#endif + + /* Associate the thread descriptor with the thread */ + pthread_setspecific(thread_descriptor_key, (void *) th); + /* Acquire the global mutex and set up the stack variables */ + leave_blocking_section(); +#ifdef NATIVE_CODE + /* Setup termination handler (for caml_thread_exit) */ + if (sigsetjmp(termination_buf.buf, 0) == 0) { + th->exit_buf = &termination_buf; +#endif + /* Callback the closure */ + clos = Start_closure(th->descr); + modify(&(Start_closure(th->descr)), Val_unit); + callback_exn(clos, Val_unit); + caml_thread_stop(); +#ifdef NATIVE_CODE + } +#endif + /* The thread now stops running */ + return NULL; +} + +value caml_thread_new(value clos) /* ML */ +{ + pthread_attr_t attr; + caml_thread_t th; + value mu = Val_unit; + value descr; + int err; + + Begin_roots2 (clos, mu) + /* Create and initialize the termination semaphore */ + mu = caml_threadstatus_new(); + /* Create a descriptor for the new thread */ + descr = alloc_small(3, 0); + Ident(descr) = Val_long(thread_next_ident); + Start_closure(descr) = clos; + Terminated(descr) = mu; + thread_next_ident++; + /* Create an info block for the current thread */ + th = (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); + th->descr = descr; +#ifdef NATIVE_CODE + th->bottom_of_stack = NULL; + th->exception_pointer = NULL; + th->local_roots = NULL; +#else + /* Allocate the stacks */ + th->stack_low = (value *) stat_alloc(Thread_stack_size); + th->stack_high = th->stack_low + Thread_stack_size / sizeof(value); + th->stack_threshold = th->stack_low + Stack_threshold / sizeof(value); + th->sp = th->stack_high; + th->trapsp = th->stack_high; + th->local_roots = NULL; + th->external_raise = NULL; +#endif + th->backtrace_pos = 0; + th->backtrace_buffer = NULL; + th->backtrace_last_exn = Val_unit; + /* Add thread info block to the list of threads */ + th->next = curr_thread->next; + th->prev = curr_thread; + curr_thread->next->prev = th; + curr_thread->next = th; + /* Fork the new thread */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + err = pthread_create(&th->pthread, &attr, caml_thread_start, (void *) th); + if (err != 0) { + /* Fork failed, remove thread info block from list of threads */ + th->next->prev = curr_thread; + curr_thread->next = th->next; +#ifndef NATIVE_CODE + stat_free(th->stack_low); +#endif + stat_free(th); + caml_pthread_check(err, "Thread.create"); + } + End_roots(); + return descr; +} + +/* Return the current thread */ + +value caml_thread_self(value unit) /* ML */ +{ + if (curr_thread == NULL) invalid_argument("Thread.self: not initialized"); + return curr_thread->descr; +} + +/* Return the identifier of a thread */ + +value caml_thread_id(value th) /* ML */ +{ + return Ident(th); +} + +/* Print uncaught exception and backtrace */ + +value caml_thread_uncaught_exception(value exn) /* ML */ +{ + char * msg = format_caml_exception(exn); + fprintf(stderr, "Thread %d killed on uncaught exception %s\n", + Int_val(Ident(curr_thread->descr)), msg); + free(msg); + if (caml_backtrace_active) print_exception_backtrace(); + fflush(stderr); + return Val_unit; +} + +/* Terminate current thread */ + +value caml_thread_exit(value unit) /* ML */ +{ +#ifdef NATIVE_CODE + /* We cannot call pthread_exit here because on some systems this + raises a C++ exception, and ocamlopt-generated stack frames + cannot be unwound. Instead, we longjmp to the thread creation + point (in caml_thread_start) or to the point in caml_main + where caml_termination_hook will be called. */ + struct longjmp_buffer * exit_buf; + if (curr_thread == NULL) invalid_argument("Thread.exit: not initialized"); + exit_buf = curr_thread->exit_buf; + caml_thread_stop(); + siglongjmp(exit_buf->buf, 1); +#else + /* No such problem in bytecode */ + if (curr_thread == NULL) invalid_argument("Thread.exit: not initialized"); + caml_thread_stop(); + pthread_exit(NULL); +#endif + return Val_unit; /* not reached */ +} + +/* Allow re-scheduling */ + +value caml_thread_yield(value unit) /* ML */ +{ + if (caml_runtime_waiters == 0) return Val_unit; + enter_blocking_section(); +#ifndef __linux__ + /* sched_yield() doesn't do what we want in Linux 2.6 and up (PR#2663) */ + sched_yield(); +#endif + leave_blocking_section(); + return Val_unit; +} + +/* Suspend the current thread until another thread terminates */ + +value caml_thread_join(value th) /* ML */ +{ + int retcode = caml_threadstatus_wait(Terminated(th)); + caml_pthread_check(retcode, "Thread.join"); + return Val_unit; +} + +/* Mutex operations */ + +#define Mutex_val(v) (* ((pthread_mutex_t **) Data_custom_val(v))) +#define Max_mutex_number 1000 + +static void caml_mutex_finalize(value wrapper) +{ + pthread_mutex_t * mut = Mutex_val(wrapper); + pthread_mutex_destroy(mut); + stat_free(mut); +} + +static int caml_mutex_condition_compare(value wrapper1, value wrapper2) +{ + pthread_mutex_t * mut1 = Mutex_val(wrapper1); + pthread_mutex_t * mut2 = Mutex_val(wrapper2); + return mut1 == mut2 ? 0 : mut1 < mut2 ? -1 : 1; +} + +static struct custom_operations caml_mutex_ops = { + "_mutex", + caml_mutex_finalize, + caml_mutex_condition_compare, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +value caml_mutex_new(value unit) /* ML */ +{ + pthread_mutex_t * mut; + value wrapper; + mut = stat_alloc(sizeof(pthread_mutex_t)); + caml_pthread_check(pthread_mutex_init(mut, NULL), "Mutex.create"); + wrapper = alloc_custom(&caml_mutex_ops, sizeof(pthread_mutex_t *), + 1, Max_mutex_number); + Mutex_val(wrapper) = mut; + return wrapper; +} + +value caml_mutex_lock(value wrapper) /* ML */ +{ + int retcode; + pthread_mutex_t * mut = Mutex_val(wrapper); + /* PR#4351: first try to acquire mutex without releasing the master lock */ + retcode = pthread_mutex_trylock(mut); + if (retcode == 0) return Val_unit; + /* If unsuccessful, block on mutex */ + Begin_root(wrapper) /* prevent the deallocation of mutex */ + enter_blocking_section(); + retcode = pthread_mutex_lock(mut); + leave_blocking_section(); + End_roots(); + caml_pthread_check(retcode, "Mutex.lock"); + return Val_unit; +} + +value caml_mutex_unlock(value wrapper) /* ML */ +{ + int retcode; + pthread_mutex_t * mut = Mutex_val(wrapper); + /* PR#4351: no need to release and reacquire master lock */ + retcode = pthread_mutex_unlock(mut); + caml_pthread_check(retcode, "Mutex.unlock"); + return Val_unit; +} + +value caml_mutex_try_lock(value wrapper) /* ML */ +{ + int retcode; + pthread_mutex_t * mut = Mutex_val(wrapper); + retcode = pthread_mutex_trylock(mut); + if (retcode == EBUSY) return Val_false; + caml_pthread_check(retcode, "Mutex.try_lock"); + return Val_true; +} + +/* Conditions operations */ + +#define Condition_val(v) (* ((pthread_cond_t **) Data_custom_val(v))) +#define Max_condition_number 1000 + +static void caml_condition_finalize(value wrapper) +{ + pthread_cond_t * cond = Condition_val(wrapper); + pthread_cond_destroy(cond); + stat_free(cond); +} + +static struct custom_operations caml_condition_ops = { + "_condition", + caml_condition_finalize, + caml_mutex_condition_compare, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +value caml_condition_new(value unit) /* ML */ +{ + pthread_cond_t * cond; + value wrapper; + cond = stat_alloc(sizeof(pthread_cond_t)); + caml_pthread_check(pthread_cond_init(cond, NULL), "Condition.create"); + wrapper = alloc_custom(&caml_condition_ops, sizeof(pthread_cond_t *), + 1, Max_condition_number); + Condition_val(wrapper) = cond; + return wrapper; +} + +value caml_condition_wait(value wcond, value wmut) /* ML */ +{ + int retcode; + pthread_cond_t * cond = Condition_val(wcond); + pthread_mutex_t * mut = Mutex_val(wmut); + Begin_roots2(wcond, wmut) /* prevent deallocation of cond and mutex */ + enter_blocking_section(); + retcode = pthread_cond_wait(cond, mut); + leave_blocking_section(); + End_roots(); + caml_pthread_check(retcode, "Condition.wait"); + return Val_unit; +} + +value caml_condition_signal(value wrapper) /* ML */ +{ + int retcode; + pthread_cond_t * cond = Condition_val(wrapper); + retcode = pthread_cond_signal(cond); + caml_pthread_check(retcode, "Condition.signal"); + return Val_unit; +} + +value caml_condition_broadcast(value wrapper) /* ML */ +{ + int retcode; + pthread_cond_t * cond = Condition_val(wrapper); + retcode = pthread_cond_broadcast(cond); + caml_pthread_check(retcode, "Condition.broadcast"); + return Val_unit; +} + +/* Thread status blocks */ + +struct caml_threadstatus { + pthread_mutex_t lock; /* mutex for mutual exclusion */ + enum { ALIVE, TERMINATED } status; /* status of thread */ + pthread_cond_t terminated; /* signaled when thread terminates */ +}; + +#define Threadstatus_val(v) \ + (* ((struct caml_threadstatus **) Data_custom_val(v))) +#define Max_threadstatus_number 500 + +static void caml_threadstatus_finalize(value wrapper) +{ + struct caml_threadstatus * ts = Threadstatus_val(wrapper); + pthread_mutex_destroy(&ts->lock); + pthread_cond_destroy(&ts->terminated); + stat_free(ts); +} + +static struct custom_operations caml_threadstatus_ops = { + "_threadstatus", + caml_threadstatus_finalize, + caml_mutex_condition_compare, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +value caml_threadstatus_new (void) +{ + struct caml_threadstatus * ts; + value wrapper; + ts = stat_alloc(sizeof(struct caml_threadstatus)); + caml_pthread_check(pthread_mutex_init(&ts->lock, NULL), "Thread.create"); + caml_pthread_check(pthread_cond_init(&ts->terminated, NULL), + "Thread.create"); + ts->status = ALIVE; + wrapper = alloc_custom(&caml_threadstatus_ops, + sizeof(struct caml_threadstatus *), + 1, Max_threadstatus_number); + Threadstatus_val(wrapper) = ts; + return wrapper; +} + +void caml_threadstatus_terminate (value wrapper) +{ + struct caml_threadstatus * ts = Threadstatus_val(wrapper); + pthread_mutex_lock(&ts->lock); + ts->status = TERMINATED; + pthread_mutex_unlock(&ts->lock); + pthread_cond_broadcast(&ts->terminated); +} + +int caml_threadstatus_wait (value wrapper) +{ + struct caml_threadstatus * ts = Threadstatus_val(wrapper); + int retcode; + + Begin_roots1(wrapper) /* prevent deallocation of ts */ + enter_blocking_section(); + retcode = pthread_mutex_lock(&ts->lock); + if (retcode != 0) goto error; + while (ts->status != TERMINATED) { + retcode = pthread_cond_wait(&ts->terminated, &ts->lock); + if (retcode != 0) goto error; + } + retcode = pthread_mutex_unlock(&ts->lock); + error: + leave_blocking_section(); + End_roots(); + return retcode; +} + +/* Signal mask */ + +static void decode_sigset(value vset, sigset_t * set) +{ + sigemptyset(set); + while (vset != Val_int(0)) { + int sig = caml_convert_signal_number(Int_val(Field(vset, 0))); + sigaddset(set, sig); + vset = Field(vset, 1); + } +} + +#ifndef NSIG +#define NSIG 64 +#endif + +static value encode_sigset(sigset_t * set) +{ + value res = Val_int(0); + int i; + + Begin_root(res) + for (i = 1; i < NSIG; i++) + if (sigismember(set, i) > 0) { + value newcons = alloc_small(2, 0); + Field(newcons, 0) = Val_int(caml_rev_convert_signal_number(i)); + Field(newcons, 1) = res; + res = newcons; + } + End_roots(); + return res; +} + +static int sigmask_cmd[3] = { SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK }; + +value caml_thread_sigmask(value cmd, value sigs) /* ML */ +{ + int how; + sigset_t set, oldset; + int retcode; + + how = sigmask_cmd[Int_val(cmd)]; + decode_sigset(sigs, &set); + enter_blocking_section(); + retcode = pthread_sigmask(how, &set, &oldset); + leave_blocking_section(); + caml_pthread_check(retcode, "Thread.sigmask"); + return encode_sigset(&oldset); +} + +/* Synchronous signal wait */ + +value caml_wait_signal(value sigs) /* ML */ +{ +#ifdef HAS_SIGWAIT + sigset_t set; + int retcode, signo; + + decode_sigset(sigs, &set); + enter_blocking_section(); + retcode = sigwait(&set, &signo); + leave_blocking_section(); + caml_pthread_check(retcode, "Thread.wait_signal"); + return Val_int(signo); +#else + invalid_argument("Thread.wait_signal not implemented"); + return Val_int(0); /* not reached */ +#endif +} + +/* Error report */ + +static void caml_pthread_check(int retcode, char *msg) +{ + char * err; + int errlen, msglen; + value str; + + if (retcode == 0) return; + err = strerror(retcode); + msglen = strlen(msg); + errlen = strlen(err); + str = alloc_string(msglen + 2 + errlen); + memmove (&Byte(str, 0), msg, msglen); + memmove (&Byte(str, msglen), ": ", 2); + memmove (&Byte(str, msglen + 2), err, errlen); + raise_sys_error(str); +} + diff --git a/otherlibs/systhreads/thread.mli b/otherlibs/systhreads/thread.mli new file mode 100644 index 0000000..cdaf351 --- /dev/null +++ b/otherlibs/systhreads/thread.mli @@ -0,0 +1,134 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1995 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: thread.mli,v 1.21 2008-01-11 16:13:16 doligez Exp $ *) + +(** Lightweight threads for Posix [1003.1c] and Win32. *) + +type t +(** The type of thread handles. *) + +(** {6 Thread creation and termination} *) + +val create : ('a -> 'b) -> 'a -> t +(** [Thread.create funct arg] creates a new thread of control, + in which the function application [funct arg] + is executed concurrently with the other threads of the program. + The application of [Thread.create] + returns the handle of the newly created thread. + The new thread terminates when the application [funct arg] + returns, either normally or by raising an uncaught exception. + In the latter case, the exception is printed on standard error, + but not propagated back to the parent thread. Similarly, the + result of the application [funct arg] is discarded and not + directly accessible to the parent thread. *) + +val self : unit -> t +(** Return the thread currently executing. *) + +val id : t -> int +(** Return the identifier of the given thread. A thread identifier + is an integer that identifies uniquely the thread. + It can be used to build data structures indexed by threads. *) + +val exit : unit -> unit +(** Terminate prematurely the currently executing thread. *) + +val kill : t -> unit +(** Terminate prematurely the thread whose handle is given. *) + +(** {6 Suspending threads} *) + +val delay: float -> unit +(** [delay d] suspends the execution of the calling thread for + [d] seconds. The other program threads continue to run during + this time. *) + +val join : t -> unit +(** [join th] suspends the execution of the calling thread + until the thread [th] has terminated. *) + +val wait_read : Unix.file_descr -> unit +(** See {!Thread.wait_write}.*) + +val wait_write : Unix.file_descr -> unit +(** This function does nothing in this implementation. *) + +val wait_timed_read : Unix.file_descr -> float -> bool +(** See {!Thread.wait_timed_read}.*) + +val wait_timed_write : Unix.file_descr -> float -> bool +(** Suspend the execution of the calling thread until at least + one character is available for reading ([wait_read]) or + one character can be written without blocking ([wait_write]) + on the given Unix file descriptor. Wait for at most + the amount of time given as second argument (in seconds). + Return [true] if the file descriptor is ready for input/output + and [false] if the timeout expired. + + These functions return immediately [true] in the Win32 + implementation. *) + +val select : + Unix.file_descr list -> Unix.file_descr list -> + Unix.file_descr list -> float -> + Unix.file_descr list * Unix.file_descr list * Unix.file_descr list +(** Suspend the execution of the calling thead until input/output + becomes possible on the given Unix file descriptors. + The arguments and results have the same meaning as for + [Unix.select]. + This function is not implemented yet under Win32. *) + +val wait_pid : int -> int * Unix.process_status +(** [wait_pid p] suspends the execution of the calling thread + until the process specified by the process identifier [p] + terminates. Returns the pid of the child caught and + its termination status, as per [Unix.wait]. + This function is not implemented under MacOS. *) + +val yield : unit -> unit +(** Re-schedule the calling thread without suspending it. + This function can be used to give scheduling hints, + telling the scheduler that now is a good time to + switch to other threads. *) + +(** {6 Management of signals} *) + +(** Signal handling follows the POSIX thread model: signals generated + by a thread are delivered to that thread; signals generated externally + are delivered to one of the threads that does not block it. + Each thread possesses a set of blocked signals, which can be modified + using {!Thread.sigmask}. This set is inherited at thread creation time. + Per-thread signal masks are supported only by the system thread library + under Unix, but not under Win32, nor by the VM thread library. *) + +val sigmask : Unix.sigprocmask_command -> int list -> int list +(** [sigmask cmd sigs] changes the set of blocked signals for the + calling thread. + If [cmd] is [SIG_SETMASK], blocked signals are set to those in + the list [sigs]. + If [cmd] is [SIG_BLOCK], the signals in [sigs] are added to + the set of blocked signals. + If [cmd] is [SIG_UNBLOCK], the signals in [sigs] are removed + from the set of blocked signals. + [sigmask] returns the set of previously blocked signals for the thread. *) + + +val wait_signal : int list -> int +(** [wait_signal sigs] suspends the execution of the calling thread + until the process receives one of the signals specified in the + list [sigs]. It then returns the number of the signal received. + Signal handlers attached to the signals in [sigs] will not + be invoked. The signals [sigs] are expected to be blocked before + calling [wait_signal]. *) + diff --git a/otherlibs/systhreads/threadUnix.ml b/otherlibs/systhreads/threadUnix.ml new file mode 100644 index 0000000..a68549d --- /dev/null +++ b/otherlibs/systhreads/threadUnix.ml @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: threadUnix.ml,v 1.8 2001-12-07 13:40:20 xleroy Exp $ *) + +(* Module [ThreadUnix]: thread-compatible system calls *) + +open Unix + +(*** Process handling *) + +external execv : string -> string array -> unit = "unix_execv" +external execve : string -> string array -> string array -> unit + = "unix_execve" +external execvp : string -> string array -> unit = "unix_execvp" +let wait = Unix.wait +let waitpid = Unix.waitpid +let system = Unix.system +let read = Unix.read +let write = Unix.write +let select = Unix.select + +let timed_read fd buff ofs len timeout = + if Thread.wait_timed_read fd timeout + then Unix.read fd buff ofs len + else raise (Unix_error(ETIMEDOUT, "timed_read", "")) + +let timed_write fd buff ofs len timeout = + if Thread.wait_timed_write fd timeout + then Unix.write fd buff ofs len + else raise (Unix_error(ETIMEDOUT, "timed_write", "")) + +let pipe = Unix.pipe + +let open_process_in = Unix.open_process_in +let open_process_out = Unix.open_process_out +let open_process = Unix.open_process + +external sleep : int -> unit = "unix_sleep" + +let socket = Unix.socket +let accept = Unix.accept +external connect : file_descr -> sockaddr -> unit = "unix_connect" +let recv = Unix.recv +let recvfrom = Unix.recvfrom +let send = Unix.send +let sendto = Unix.sendto + +let open_connection = Unix.open_connection diff --git a/otherlibs/systhreads/threadUnix.mli b/otherlibs/systhreads/threadUnix.mli new file mode 100644 index 0000000..e5759cd --- /dev/null +++ b/otherlibs/systhreads/threadUnix.mli @@ -0,0 +1,85 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: threadUnix.mli,v 1.19 2002-06-26 09:48:00 xleroy Exp $ *) + +(** Thread-compatible system calls. + + @deprecated The functionality of this module has been merged back into + the {!Unix} module. Threaded programs can now call the functions + from module {!Unix} directly, and still get the correct behavior + (block the calling thread, if required, but do not block all threads + in the process). *) + +(** {6 Process handling} *) + +val execv : string -> string array -> unit +val execve : string -> string array -> string array -> unit +val execvp : string -> string array -> unit +val wait : unit -> int * Unix.process_status +val waitpid : Unix.wait_flag list -> int -> int * Unix.process_status +val system : string -> Unix.process_status + +(** {6 Basic input/output} *) + +val read : Unix.file_descr -> string -> int -> int -> int +val write : Unix.file_descr -> string -> int -> int -> int + +(** {6 Input/output with timeout} *) + +val timed_read : + Unix.file_descr -> + string -> int -> int -> float -> int +(** See {!ThreadUnix.timed_write}. *) + +val timed_write : + Unix.file_descr -> + string -> int -> int -> float -> int +(** Behave as {!ThreadUnix.read} and {!ThreadUnix.write}, except that + [Unix_error(ETIMEDOUT,_,_)] is raised if no data is + available for reading or ready for writing after [d] seconds. + The delay [d] is given in the fifth argument, in seconds. *) + +(** {6 Polling} *) + +val select : + Unix.file_descr list -> Unix.file_descr list -> + Unix.file_descr list -> float -> + Unix.file_descr list * Unix.file_descr list * Unix.file_descr list + +(** {6 Pipes and redirections} *) + +val pipe : unit -> Unix.file_descr * Unix.file_descr +val open_process_in: string -> in_channel +val open_process_out: string -> out_channel +val open_process: string -> in_channel * out_channel + +(** {6 Time} *) + +val sleep : int -> unit + +(** {6 Sockets} *) + +val socket : Unix.socket_domain -> + Unix.socket_type -> int -> Unix.file_descr +val accept : Unix.file_descr -> Unix.file_descr * Unix.sockaddr +val connect : Unix.file_descr -> Unix.sockaddr -> unit +val recv : Unix.file_descr -> string -> + int -> int -> Unix.msg_flag list -> int +val recvfrom : Unix.file_descr -> string -> int -> int -> + Unix.msg_flag list -> int * Unix.sockaddr +val send : Unix.file_descr -> string -> int -> int -> + Unix.msg_flag list -> int +val sendto : Unix.file_descr -> string -> int -> int -> + Unix.msg_flag list -> Unix.sockaddr -> int +val open_connection : Unix.sockaddr -> in_channel * out_channel diff --git a/otherlibs/systhreads/thread_posix.ml b/otherlibs/systhreads/thread_posix.ml new file mode 100644 index 0000000..3338e66 --- /dev/null +++ b/otherlibs/systhreads/thread_posix.ml @@ -0,0 +1,74 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: thread_posix.ml,v 1.10 2005-07-31 12:32:41 xleroy Exp $ *) + +(* User-level threads *) + +type t + +external thread_initialize : unit -> unit = "caml_thread_initialize" +external thread_new : (unit -> unit) -> t = "caml_thread_new" +external thread_uncaught_exception : exn -> unit = + "caml_thread_uncaught_exception" + +external yield : unit -> unit = "caml_thread_yield" +external self : unit -> t = "caml_thread_self" +external id : t -> int = "caml_thread_id" +external join : t -> unit = "caml_thread_join" +external exit : unit -> unit = "caml_thread_exit" + +(* For new, make sure the function passed to thread_new never + raises an exception. *) + +let create fn arg = + thread_new + (fun () -> + try + fn arg; () + with exn -> + flush stdout; flush stderr; + thread_uncaught_exception exn) + +(* Thread.kill is currently not implemented due to problems with + cleanup handlers on several platforms *) + +let kill th = invalid_arg "Thread.kill: not implemented" + +(* Preemption *) + +let preempt signal = yield() + +(* Initialization of the scheduler *) + +let _ = + ignore(Sys.signal Sys.sigvtalrm (Sys.Signal_handle preempt)); + thread_initialize() + +(* Wait functions *) + +let delay time = ignore(Unix.select [] [] [] time) + +let wait_read fd = () +let wait_write fd = () + +let wait_timed_read fd d = + match Unix.select [fd] [] [] d with ([], _, _) -> false | (_, _, _) -> true +let wait_timed_write fd d = + match Unix.select [] [fd] [] d with (_, [], _) -> false | (_, _, _) -> true +let select = Unix.select + +let wait_pid p = Unix.waitpid [] p + +external sigmask : Unix.sigprocmask_command -> int list -> int list = "caml_thread_sigmask" +external wait_signal : int list -> int = "caml_wait_signal" diff --git a/otherlibs/systhreads/thread_win32.ml b/otherlibs/systhreads/thread_win32.ml new file mode 100644 index 0000000..d3ec835 --- /dev/null +++ b/otherlibs/systhreads/thread_win32.ml @@ -0,0 +1,77 @@ +(***********************************************************************) +(* *) +(* Caml Special Light *) +(* *) +(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1995 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: thread_win32.ml,v 1.9 2005-07-31 12:32:41 xleroy Exp $ *) + +(* User-level threads *) + +type t + +external thread_initialize : unit -> unit = "caml_thread_initialize" +external thread_new : (unit -> unit) -> t = "caml_thread_new" + +external yield : unit -> unit = "caml_thread_yield" +external self : unit -> t = "caml_thread_self" +external id : t -> int = "caml_thread_id" +external join : t -> unit = "caml_thread_join" +external thread_uncaught_exception : exn -> unit = + "caml_thread_uncaught_exception" + +(* For new, make sure the function passed to thread_new never + raises an exception. *) + +exception Thread_exit + +let create fn arg = + thread_new + (fun () -> + try + fn arg; () + with Thread_exit -> () + | exn -> + flush stdout; flush stderr; + thread_uncaught_exception exn) + +let exit () = raise Thread_exit + +(* Thread.kill is currently not implemented because there is no way + to do correct cleanup under Win32. *) + +let kill th = invalid_arg "Thread.kill: not implemented" + +(* Preemption *) + +let preempt signal = yield() + +(* Initialization of the scheduler *) + +let _ = + ignore(Sys.signal Sys.sigterm (Sys.Signal_handle preempt)); + thread_initialize() + +(* Wait functions *) + +external delay: float -> unit = "caml_thread_delay" + +let wait_read fd = () +let wait_write fd = () + +let wait_timed_read fd delay = true +let wait_timed_write fd delay = true +let select rd wr ex delay = invalid_arg "Thread.select: not implemented" + +let wait_pid p = Unix.waitpid [] p + +let sigmask cmd set = invalid_arg "Thread.sigmask: not implemented" +let wait_signal set = invalid_arg "Thread.wait_signal: not implemented" + diff --git a/otherlibs/systhreads/threads.mllib b/otherlibs/systhreads/threads.mllib new file mode 100644 index 0000000..3ff8841 --- /dev/null +++ b/otherlibs/systhreads/threads.mllib @@ -0,0 +1 @@ +Thread Mutex Condition Event ThreadUnix diff --git a/otherlibs/systhreads/win32.c b/otherlibs/systhreads/win32.c new file mode 100644 index 0000000..0244f5b --- /dev/null +++ b/otherlibs/systhreads/win32.c @@ -0,0 +1,664 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, INRIA Rocquencourt */ +/* */ +/* Copyright 1995 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: win32.c,v 1.45 2007-10-31 09:12:29 xleroy Exp $ */ + +/* Thread interface for Win32 threads */ + +#include <windows.h> +#include <process.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include "alloc.h" +#include "backtrace.h" +#include "callback.h" +#include "custom.h" +#include "fail.h" +#include "io.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "printexc.h" +#include "roots.h" +#include "signals.h" +#ifdef NATIVE_CODE +#include "stack.h" +#else +#include "stacks.h" +#endif +#include "sys.h" + +/* Initial size of stack when a thread is created (4 Ko) */ +#define Thread_stack_size (Stack_size / 4) + +/* Max computation time before rescheduling, in milliseconds (50ms) */ +#define Thread_timeout 50 + +/* Signal used for timer preemption (any unused, legal signal number) */ +#define SIGTIMER SIGTERM + +/* The ML value describing a thread (heap-allocated) */ + +struct caml_thread_handle { + value final_fun; /* Finalization function */ + HANDLE handle; /* Windows handle */ +}; + +struct caml_thread_descr { + value ident; /* Unique integer ID */ + value start_closure; /* The closure to start this thread */ + struct caml_thread_handle * thread_handle; /* Finalized object with handle */ +}; + +#define Ident(v) (((struct caml_thread_descr *)(v))->ident) +#define Start_closure(v) (((struct caml_thread_descr *)(v))->start_closure) +#define Threadhandle(v) (((struct caml_thread_descr *)(v))->thread_handle) + +/* The infos on threads (allocated via malloc()) */ + +struct caml_thread_struct { + HANDLE wthread; /* The Windows thread handle */ + value descr; /* The heap-allocated descriptor (root) */ + struct caml_thread_struct * next; /* Double linking of running threads */ + struct caml_thread_struct * prev; +#ifdef NATIVE_CODE + char * bottom_of_stack; /* Saved value of caml_bottom_of_stack */ + uintnat last_retaddr; /* Saved value of caml_last_return_address */ + value * gc_regs; /* Saved value of caml_gc_regs */ + char * exception_pointer; /* Saved value of caml_exception_pointer */ + struct caml__roots_block * local_roots; /* Saved value of local_roots */ +#else + value * stack_low; /* The execution stack for this thread */ + value * stack_high; + value * stack_threshold; + value * sp; /* Saved value of extern_sp for this thread */ + value * trapsp; /* Saved value of trapsp for this thread */ + struct caml__roots_block * local_roots; /* Saved value of local_roots */ + struct longjmp_buffer * external_raise; /* Saved external_raise */ + int backtrace_pos; /* Saved backtrace_pos */ + code_t * backtrace_buffer; /* Saved backtrace_buffer */ + value backtrace_last_exn; /* Saved backtrace_last_exn (root) */ +#endif +}; + +typedef struct caml_thread_struct * caml_thread_t; + +/* The descriptor for the currently executing thread (thread-specific) */ + +static caml_thread_t curr_thread = NULL; + +/* The global mutex used to ensure that at most one thread is running + Caml code */ +static HANDLE caml_mutex; + +/* The key used for storing the thread descriptor in the specific data + of the corresponding Posix thread. */ +static DWORD thread_descriptor_key; + +/* The key used for unlocking I/O channels on exceptions */ +static DWORD last_channel_locked_key; + +/* Identifier for next thread creation */ +static intnat thread_next_ident = 0; + +/* Forward declarations */ + +static void caml_wthread_error (char * msg); + +/* Hook for scanning the stacks of the other threads */ + +static void (*prev_scan_roots_hook) (scanning_action); + +static void caml_thread_scan_roots(scanning_action action) +{ + caml_thread_t th; + + th = curr_thread; + do { + (*action)(th->descr, &th->descr); +#ifndef NATIVE_CODE + (*action)(th->backtrace_last_exn, &th->backtrace_last_exn); +#endif + /* Don't rescan the stack of the current thread, it was done already */ + if (th != curr_thread) { +#ifdef NATIVE_CODE + if (th->bottom_of_stack != NULL) + do_local_roots(action, th->bottom_of_stack, th->last_retaddr, + th->gc_regs, th->local_roots); +#else + do_local_roots(action, th->sp, th->stack_high, th->local_roots); +#endif + } + th = th->next; + } while (th != curr_thread); + /* Hook */ + if (prev_scan_roots_hook != NULL) (*prev_scan_roots_hook)(action); +} + +/* Hooks for enter_blocking_section and leave_blocking_section */ + +static void caml_thread_enter_blocking_section(void) +{ + /* Save the stack-related global variables in the thread descriptor + of the current thread */ +#ifdef NATIVE_CODE + curr_thread->bottom_of_stack = caml_bottom_of_stack; + curr_thread->last_retaddr = caml_last_return_address; + curr_thread->gc_regs = caml_gc_regs; + curr_thread->exception_pointer = caml_exception_pointer; + curr_thread->local_roots = local_roots; +#else + curr_thread->stack_low = stack_low; + curr_thread->stack_high = stack_high; + curr_thread->stack_threshold = stack_threshold; + curr_thread->sp = extern_sp; + curr_thread->trapsp = trapsp; + curr_thread->local_roots = local_roots; + curr_thread->external_raise = external_raise; + curr_thread->backtrace_pos = backtrace_pos; + curr_thread->backtrace_buffer = backtrace_buffer; + curr_thread->backtrace_last_exn = backtrace_last_exn; +#endif + /* Release the global mutex */ + ReleaseMutex(caml_mutex); +} + +static void caml_thread_leave_blocking_section(void) +{ + WaitForSingleObject(caml_mutex, INFINITE); + /* Update curr_thread to point to the thread descriptor corresponding + to the thread currently executing */ + curr_thread = TlsGetValue(thread_descriptor_key); + /* Restore the stack-related global variables */ +#ifdef NATIVE_CODE + caml_bottom_of_stack= curr_thread->bottom_of_stack; + caml_last_return_address = curr_thread->last_retaddr; + caml_gc_regs = curr_thread->gc_regs; + caml_exception_pointer = curr_thread->exception_pointer; + local_roots = curr_thread->local_roots; +#else + stack_low = curr_thread->stack_low; + stack_high = curr_thread->stack_high; + stack_threshold = curr_thread->stack_threshold; + extern_sp = curr_thread->sp; + trapsp = curr_thread->trapsp; + local_roots = curr_thread->local_roots; + external_raise = curr_thread->external_raise; + backtrace_pos = curr_thread->backtrace_pos; + backtrace_buffer = curr_thread->backtrace_buffer; + backtrace_last_exn = curr_thread->backtrace_last_exn; +#endif +} + +static int caml_thread_try_leave_blocking_section(void) +{ + /* Disable immediate processing of signals (PR#3659). + try_leave_blocking_section always fails, forcing the signal to be + recorded and processed at the next leave_blocking_section or + polling. */ + return 0; +} + +/* Hooks for I/O locking */ + +static void caml_io_mutex_free(struct channel * chan) +{ + HANDLE mutex = chan->mutex; + if (mutex != NULL) { + CloseHandle(mutex); + } +} + +static void caml_io_mutex_lock(struct channel * chan) +{ + if (chan->mutex == NULL) { + HANDLE mutex = CreateMutex(NULL, FALSE, NULL); + if (mutex == NULL) caml_wthread_error("Thread.iolock"); + chan->mutex = (void *) mutex; + } + /* PR#4351: first try to acquire mutex without releasing the master lock */ + if (WaitForSingleObject((HANDLE) chan->mutex, 0) == WAIT_OBJECT_0) { + TlsSetValue(last_channel_locked_key, (void *) chan); + return; + } + enter_blocking_section(); + WaitForSingleObject((HANDLE) chan->mutex, INFINITE); + /* Problem: if a signal occurs at this point, + and the signal handler raises an exception, we will not + unlock the mutex. The alternative (doing the setspecific + before locking the mutex is also incorrect, since we could + then unlock a mutex that is unlocked or locked by someone else. */ + TlsSetValue(last_channel_locked_key, (void *) chan); + leave_blocking_section(); +} + +static void caml_io_mutex_unlock(struct channel * chan) +{ + ReleaseMutex((HANDLE) chan->mutex); + TlsSetValue(last_channel_locked_key, NULL); +} + +static void caml_io_mutex_unlock_exn(void) +{ + struct channel * chan = TlsGetValue(last_channel_locked_key); + if (chan != NULL) caml_io_mutex_unlock(chan); +} + +/* The "tick" thread fakes a signal at regular intervals. */ + +static DWORD WINAPI caml_thread_tick(void * arg) +{ + while(1) { + Sleep(Thread_timeout); + caml_pending_signals[SIGTIMER] = 1; + caml_signals_are_pending = 1; +#ifdef NATIVE_CODE + young_limit = young_end; +#else + something_to_do = 1; +#endif + } +} + +static void caml_thread_finalize(value vthread) +{ + CloseHandle(((struct caml_thread_handle *)vthread)->handle); +} + +/* Initialize the thread machinery */ + +CAMLprim value caml_thread_initialize(value unit) +{ + value vthread = Val_unit; + value descr; + HANDLE tick_thread; + DWORD th_id; + + /* Protect against repeated initialization (PR#1325) */ + if (curr_thread != NULL) return Val_unit; + Begin_root (vthread); + /* Initialize the main mutex and acquire it */ + caml_mutex = CreateMutex(NULL, TRUE, NULL); + if (caml_mutex == NULL) caml_wthread_error("Thread.init"); + /* Initialize the TLS keys */ + thread_descriptor_key = TlsAlloc(); + last_channel_locked_key = TlsAlloc(); + /* Create a finalized value to hold thread handle */ + vthread = alloc_final(sizeof(struct caml_thread_handle) / sizeof(value), + caml_thread_finalize, 1, 1000); + ((struct caml_thread_handle *)vthread)->handle = NULL; + /* Create a descriptor for the current thread */ + descr = alloc_tuple(sizeof(struct caml_thread_descr) / sizeof(value)); + Ident(descr) = Val_long(thread_next_ident); + Start_closure(descr) = Val_unit; + Threadhandle(descr) = (struct caml_thread_handle *) vthread; + thread_next_ident++; + /* Create an info block for the current thread */ + curr_thread = + (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); + DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), + GetCurrentProcess(), &(curr_thread->wthread), + 0, FALSE, DUPLICATE_SAME_ACCESS); + if (curr_thread->wthread == NULL) caml_wthread_error("Thread.init"); + ((struct caml_thread_handle *)vthread)->handle = curr_thread->wthread; + curr_thread->descr = descr; + curr_thread->next = curr_thread; + curr_thread->prev = curr_thread; + /* The stack-related fields will be filled in at the next + enter_blocking_section */ + /* Associate the thread descriptor with the thread */ + TlsSetValue(thread_descriptor_key, (void *) curr_thread); + /* Set up the hooks */ + prev_scan_roots_hook = scan_roots_hook; + scan_roots_hook = caml_thread_scan_roots; + enter_blocking_section_hook = caml_thread_enter_blocking_section; + leave_blocking_section_hook = caml_thread_leave_blocking_section; + try_leave_blocking_section_hook = caml_thread_try_leave_blocking_section; + caml_channel_mutex_free = caml_io_mutex_free; + caml_channel_mutex_lock = caml_io_mutex_lock; + caml_channel_mutex_unlock = caml_io_mutex_unlock; + caml_channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; + /* Fork the tick thread */ + tick_thread = CreateThread(NULL, 0, caml_thread_tick, NULL, 0, &th_id); + if (tick_thread == NULL) caml_wthread_error("Thread.init"); + CloseHandle(tick_thread); + End_roots(); + return Val_unit; +} + +/* Create a thread */ + +static DWORD WINAPI caml_thread_start(void * arg) +{ + caml_thread_t th = (caml_thread_t) arg; + value clos; + + /* Associate the thread descriptor with the thread */ + TlsSetValue(thread_descriptor_key, (void *) th); + TlsSetValue(last_channel_locked_key, NULL); + /* Acquire the global mutex and set up the stack variables */ + leave_blocking_section(); + /* Callback the closure */ + clos = Start_closure(th->descr); + modify(&(Start_closure(th->descr)), Val_unit); + callback_exn(clos, Val_unit); + /* Remove th from the doubly-linked list of threads */ + th->next->prev = th->prev; + th->prev->next = th->next; + /* Release the main mutex (forever) */ + ReleaseMutex(caml_mutex); +#ifndef NATIVE_CODE + /* Free the memory resources */ + stat_free(th->stack_low); + if (th->backtrace_buffer != NULL) free(th->backtrace_buffer); +#endif + /* Free the thread descriptor */ + stat_free(th); + /* The thread now stops running */ + return 0; +} + +CAMLprim value caml_thread_new(value clos) +{ + caml_thread_t th; + value vthread = Val_unit; + value descr; + DWORD th_id; + + Begin_roots2 (clos, vthread) + /* Create a finalized value to hold thread handle */ + vthread = alloc_final(sizeof(struct caml_thread_handle) / sizeof(value), + caml_thread_finalize, 1, 1000); + ((struct caml_thread_handle *)vthread)->handle = NULL; + /* Create a descriptor for the new thread */ + descr = alloc_tuple(sizeof(struct caml_thread_descr) / sizeof(value)); + Ident(descr) = Val_long(thread_next_ident); + Start_closure(descr) = clos; + Threadhandle(descr) = (struct caml_thread_handle *) vthread; + thread_next_ident++; + /* Create an info block for the current thread */ + th = (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); + th->descr = descr; +#ifdef NATIVE_CODE + th->bottom_of_stack = NULL; + th->exception_pointer = NULL; + th->local_roots = NULL; +#else + /* Allocate the stacks */ + th->stack_low = (value *) stat_alloc(Thread_stack_size); + th->stack_high = th->stack_low + Thread_stack_size / sizeof(value); + th->stack_threshold = th->stack_low + Stack_threshold / sizeof(value); + th->sp = th->stack_high; + th->trapsp = th->stack_high; + th->local_roots = NULL; + th->external_raise = NULL; + th->backtrace_pos = 0; + th->backtrace_buffer = NULL; + th->backtrace_last_exn = Val_unit; +#endif + /* Add thread info block to the list of threads */ + th->next = curr_thread->next; + th->prev = curr_thread; + curr_thread->next->prev = th; + curr_thread->next = th; + /* Fork the new thread */ + th->wthread = + CreateThread(NULL, 0, caml_thread_start, (void *) th, 0, &th_id); + if (th->wthread == NULL) { + /* Fork failed, remove thread info block from list of threads */ + th->next->prev = curr_thread; + curr_thread->next = th->next; +#ifndef NATIVE_CODE + stat_free(th->stack_low); +#endif + stat_free(th); + caml_wthread_error("Thread.create"); + } + ((struct caml_thread_handle *)vthread)->handle = th->wthread; + End_roots(); + return descr; +} + +/* Return the current thread */ + +CAMLprim value caml_thread_self(value unit) +{ + if (curr_thread == NULL) invalid_argument("Thread.self: not initialized"); + return curr_thread->descr; +} + +/* Return the identifier of a thread */ + +CAMLprim value caml_thread_id(value th) +{ + return Ident(th); +} + +/* Print uncaught exception and backtrace */ + +CAMLprim value caml_thread_uncaught_exception(value exn) +{ + char * msg = format_caml_exception(exn); + fprintf(stderr, "Thread %d killed on uncaught exception %s\n", + Int_val(Ident(curr_thread->descr)), msg); + free(msg); +#ifndef NATIVE_CODE + if (backtrace_active) print_exception_backtrace(); +#endif + fflush(stderr); + return Val_unit; +} + +/* Allow re-scheduling */ + +CAMLprim value caml_thread_yield(value unit) +{ + enter_blocking_section(); + Sleep(0); + leave_blocking_section(); + return Val_unit; +} + +/* Suspend the current thread until another thread terminates */ + +CAMLprim value caml_thread_join(value th) +{ + HANDLE h; + + Begin_root(th) /* prevent deallocation of handle */ + h = Threadhandle(th)->handle; + enter_blocking_section(); + WaitForSingleObject(h, INFINITE); + leave_blocking_section(); + End_roots(); + return Val_unit; +} + +/* Mutex operations */ + +#define Mutex_val(v) (*((HANDLE *) Data_custom_val(v))) +#define Max_mutex_number 1000 + +static void caml_mutex_finalize(value mut) +{ + CloseHandle(Mutex_val(mut)); +} + +static int caml_mutex_compare(value wrapper1, value wrapper2) +{ + HANDLE h1 = Mutex_val(wrapper1); + HANDLE h2 = Mutex_val(wrapper2); + return h1 == h2 ? 0 : h1 < h2 ? -1 : 1; +} + +static struct custom_operations caml_mutex_ops = { + "_mutex", + caml_mutex_finalize, + caml_mutex_compare, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +CAMLprim value caml_mutex_new(value unit) +{ + value mut; + mut = alloc_custom(&caml_mutex_ops, sizeof(HANDLE), 1, Max_mutex_number); + Mutex_val(mut) = CreateMutex(0, FALSE, NULL); + if (Mutex_val(mut) == NULL) caml_wthread_error("Mutex.create"); + return mut; +} + +CAMLprim value caml_mutex_lock(value mut) +{ + int retcode; + /* PR#4351: first try to acquire mutex without releasing the master lock */ + retcode = WaitForSingleObject(Mutex_val(mut), 0); + if (retcode == WAIT_OBJECT_0) return Val_unit; + Begin_root(mut) /* prevent deallocation of mutex */ + enter_blocking_section(); + retcode = WaitForSingleObject(Mutex_val(mut), INFINITE); + leave_blocking_section(); + End_roots(); + if (retcode == WAIT_FAILED) caml_wthread_error("Mutex.lock"); + return Val_unit; +} + +CAMLprim value caml_mutex_unlock(value mut) +{ + BOOL retcode; + /* PR#4351: no need to release and reacquire master lock */ + retcode = ReleaseMutex(Mutex_val(mut)); + if (!retcode) caml_wthread_error("Mutex.unlock"); + return Val_unit; +} + +CAMLprim value caml_mutex_try_lock(value mut) +{ + int retcode; + retcode = WaitForSingleObject(Mutex_val(mut), 0); + if (retcode == WAIT_FAILED || retcode == WAIT_ABANDONED) + caml_wthread_error("Mutex.try_lock"); + return Val_bool(retcode == WAIT_OBJECT_0); +} + +/* Delay */ + +CAMLprim value caml_thread_delay(value val) +{ + enter_blocking_section(); + Sleep((DWORD)(Double_val(val)*1000)); /* milliseconds */ + leave_blocking_section(); + return Val_unit; +} + +/* Conditions operations */ + +struct caml_condvar { + uintnat count; /* Number of waiting threads */ + HANDLE sem; /* Semaphore on which threads are waiting */ +}; + +#define Condition_val(v) ((struct caml_condvar *) Data_custom_val(v)) +#define Max_condition_number 1000 + +static void caml_condition_finalize(value cond) +{ + CloseHandle(Condition_val(cond)->sem); +} + +static int caml_condition_compare(value wrapper1, value wrapper2) +{ + HANDLE h1 = Condition_val(wrapper1)->sem; + HANDLE h2 = Condition_val(wrapper2)->sem; + return h1 == h2 ? 0 : h1 < h2 ? -1 : 1; +} + +static struct custom_operations caml_condition_ops = { + "_condition", + caml_condition_finalize, + caml_condition_compare, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +CAMLprim value caml_condition_new(value unit) +{ + value cond; + cond = alloc_custom(&caml_condition_ops, sizeof(struct caml_condvar), + 1, Max_condition_number); + Condition_val(cond)->sem = CreateSemaphore(NULL, 0, 0x7FFFFFFF, NULL); + if (Condition_val(cond)->sem == NULL) + caml_wthread_error("Condition.create"); + Condition_val(cond)->count = 0; + return cond; +} + +CAMLprim value caml_condition_wait(value cond, value mut) +{ + int retcode; + HANDLE m = Mutex_val(mut); + HANDLE s = Condition_val(cond)->sem; + HANDLE handles[2]; + + Condition_val(cond)->count ++; + Begin_roots2(cond, mut) /* prevent deallocation of cond and mutex */ + enter_blocking_section(); + /* Release mutex */ + ReleaseMutex(m); + /* Wait for semaphore to be non-null, and decrement it. + Simultaneously, re-acquire mutex. */ + handles[0] = s; + handles[1] = m; + retcode = WaitForMultipleObjects(2, handles, TRUE, INFINITE); + leave_blocking_section(); + End_roots(); + if (retcode == WAIT_FAILED) caml_wthread_error("Condition.wait"); + return Val_unit; +} + +CAMLprim value caml_condition_signal(value cond) +{ + HANDLE s = Condition_val(cond)->sem; + + if (Condition_val(cond)->count > 0) { + Condition_val(cond)->count --; + /* Increment semaphore by 1, waking up one waiter */ + ReleaseSemaphore(s, 1, NULL); + } + return Val_unit; +} + +CAMLprim value caml_condition_broadcast(value cond) +{ + HANDLE s = Condition_val(cond)->sem; + uintnat c = Condition_val(cond)->count; + + if (c > 0) { + Condition_val(cond)->count = 0; + /* Increment semaphore by c, waking up all waiters */ + ReleaseSemaphore(s, c, NULL); + } + return Val_unit; +} + +/* Error report */ + +static void caml_wthread_error(char * msg) +{ + char errmsg[1024]; + sprintf(errmsg, "%s: error code %lx", msg, GetLastError()); + raise_sys_error(copy_string(errmsg)); +} diff --git a/otherlibs/threads/.cvsignore b/otherlibs/threads/.cvsignore new file mode 100644 index 0000000..fb2df56 --- /dev/null +++ b/otherlibs/threads/.cvsignore @@ -0,0 +1,3 @@ +marshal.mli +pervasives.mli +unix.mli diff --git a/otherlibs/threads/.depend b/otherlibs/threads/.depend new file mode 100644 index 0000000..919e092 --- /dev/null +++ b/otherlibs/threads/.depend @@ -0,0 +1,44 @@ +scheduler.o: scheduler.c ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h ../../byterun/backtrace.h ../../byterun/mlvalues.h \ + ../../byterun/callback.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/io.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/printexc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/roots.h \ + ../../byterun/misc.h ../../byterun/memory.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/stacks.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h ../../byterun/sys.h \ + ../../byterun/misc.h +condition.cmi: mutex.cmi +event.cmi: +mutex.cmi: +thread.cmi: unix.cmo +threadUnix.cmi: unix.cmo +condition.cmo: thread.cmi mutex.cmi condition.cmi +condition.cmx: thread.cmx mutex.cmx condition.cmi +event.cmo: mutex.cmi condition.cmi event.cmi +event.cmx: mutex.cmx condition.cmx event.cmi +marshal.cmo: pervasives.cmo +marshal.cmx: pervasives.cmx +mutex.cmo: thread.cmi mutex.cmi +mutex.cmx: thread.cmx mutex.cmi +pervasives.cmo: unix.cmo +pervasives.cmx: unix.cmx +thread.cmo: unix.cmo thread.cmi +thread.cmx: unix.cmx thread.cmi +threadUnix.cmo: unix.cmo thread.cmi threadUnix.cmi +threadUnix.cmx: unix.cmx thread.cmx threadUnix.cmi +unix.cmo: +unix.cmx: diff --git a/otherlibs/threads/Makefile b/otherlibs/threads/Makefile new file mode 100644 index 0000000..8fc67e8 --- /dev/null +++ b/otherlibs/threads/Makefile @@ -0,0 +1,127 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.63 2008-12-03 18:09:09 doligez Exp $ + +include ../../config/Makefile + +CC=$(BYTECC) +CFLAGS=-I../../byterun -O $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -g +CAMLC=../../ocamlcomp.sh -I ../unix +MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib +COMPFLAGS=-warn-error A + +C_OBJS=scheduler.o + +CAML_OBJS=thread.cmo mutex.cmo condition.cmo event.cmo threadUnix.cmo + +LIB=../../stdlib + +LIB_OBJS=pervasives.cmo \ + $(LIB)/array.cmo $(LIB)/list.cmo $(LIB)/char.cmo $(LIB)/string.cmo \ + $(LIB)/sys.cmo $(LIB)/hashtbl.cmo $(LIB)/sort.cmo \ + marshal.cmo $(LIB)/obj.cmo $(LIB)/int32.cmo $(LIB)/int64.cmo \ + $(LIB)/nativeint.cmo \ + $(LIB)/lexing.cmo $(LIB)/parsing.cmo \ + $(LIB)/set.cmo $(LIB)/map.cmo $(LIB)/stack.cmo $(LIB)/queue.cmo \ + $(LIB)/camlinternalLazy.cmo $(LIB)/lazy.cmo \ + $(LIB)/stream.cmo $(LIB)/buffer.cmo \ + $(LIB)/printf.cmo $(LIB)/format.cmo \ + $(LIB)/scanf.cmo $(LIB)/arg.cmo \ + $(LIB)/printexc.cmo $(LIB)/gc.cmo $(LIB)/digest.cmo $(LIB)/random.cmo \ + $(LIB)/camlinternalOO.cmo $(LIB)/oo.cmo $(LIB)/camlinternalMod.cmo \ + $(LIB)/genlex.cmo $(LIB)/callback.cmo $(LIB)/weak.cmo \ + $(LIB)/filename.cmo $(LIB)/complex.cmo \ + $(LIB)/arrayLabels.cmo $(LIB)/listLabels.cmo $(LIB)/stringLabels.cmo \ + $(LIB)/stdLabels.cmo $(LIB)/moreLabels.cmo + +UNIXLIB=../unix + +UNIXLIB_OBJS=unix.cmo $(UNIXLIB)/unixLabels.cmo + +all: libvmthreads.a threads.cma stdlib.cma unix.cma + +allopt: + +libvmthreads.a: $(C_OBJS) + $(MKLIB) -o threads -oc vmthreads $(C_OBJS) + +threads.cma: $(CAML_OBJS) + $(MKLIB) -ocamlc '$(CAMLC)' -o threads -oc vmthreads $(CAML_OBJS) + +stdlib.cma: $(LIB_OBJS) + $(CAMLC) -a -o stdlib.cma $(LIB_OBJS) + +unix.cma: $(UNIXLIB_OBJS) + $(MKLIB) -ocamlc '$(CAMLC)' -o unix -linkall $(UNIXLIB_OBJS) + +pervasives.cmo: pervasives.mli pervasives.cmi pervasives.ml + $(CAMLC) ${COMPFLAGS} -nopervasives -c pervasives.ml + +pervasives.mli: $(LIB)/pervasives.mli + ln -s $(LIB)/pervasives.mli pervasives.mli + +pervasives.cmi: $(LIB)/pervasives.cmi + ln -s $(LIB)/pervasives.cmi pervasives.cmi + +marshal.cmo: marshal.mli marshal.cmi marshal.ml + $(CAMLC) ${COMPFLAGS} -c marshal.ml + +marshal.mli: $(LIB)/marshal.mli + ln -s $(LIB)/marshal.mli marshal.mli + +marshal.cmi: $(LIB)/marshal.cmi + ln -s $(LIB)/marshal.cmi marshal.cmi + +unix.mli: $(UNIXLIB)/unix.mli + ln -s -f $(UNIXLIB)/unix.mli unix.mli + +unix.cmi: $(UNIXLIB)/unix.cmi + ln -s -f $(UNIXLIB)/unix.cmi unix.cmi + +unix.cmo: unix.mli unix.cmi $(UNIXLIB)/unixLabels.cmo + $(CAMLC) ${COMPFLAGS} -c unix.ml + +partialclean: + rm -f *.cm* + +clean: partialclean + rm -f libvmthreads.a dllvmthreads.so *.o + rm -f pervasives.mli marshal.mli unix.mli + +install: + if test -f dllvmthreads.so; then cp dllvmthreads.so $(STUBLIBDIR)/.; fi + mkdir -p $(LIBDIR)/vmthreads + cp libvmthreads.a $(LIBDIR)/vmthreads/libvmthreads.a + cd $(LIBDIR)/vmthreads; $(RANLIB) libvmthreads.a + cp thread.cmi mutex.cmi condition.cmi event.cmi threadUnix.cmi threads.cma stdlib.cma unix.cma $(LIBDIR)/vmthreads + cp thread.mli mutex.mli condition.mli event.mli threadUnix.mli $(LIBDIR)/vmthreads + +installopt: + +.SUFFIXES: .ml .mli .cmo .cmi .cmx + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/threads/Tests/.cvsignore b/otherlibs/threads/Tests/.cvsignore new file mode 100644 index 0000000..e6d9e45 --- /dev/null +++ b/otherlibs/threads/Tests/.cvsignore @@ -0,0 +1 @@ +*.byt diff --git a/otherlibs/threads/Tests/Makefile b/otherlibs/threads/Tests/Makefile new file mode 100644 index 0000000..22240ea --- /dev/null +++ b/otherlibs/threads/Tests/Makefile @@ -0,0 +1,38 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../../LICENSE.# +# # +######################################################################### + +# $Id: Makefile,v 1.16 2007-01-29 12:11:17 xleroy Exp $ + +PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt \ + test7.byt test8.byt test9.byt testA.byt sieve.byt \ + testio.byt testsocket.byt testwait.byt testsignal.byt testsignal2.byt \ + testsieve.byt token1.byt token2.byt + +CAMLC=../../../boot/ocamlrun ../../../ocamlc -I .. -I ../../../stdlib -I ../../unix + +include ../../../config/Makefile + +all: $(PROGS) + +clean: + rm -f *.cm* *.byt + +sorts.byt: sorts.ml + $(CAMLC) -o sorts.byt -I ../../graph threads.cma graphics.cma sorts.ml $(LIBS) $(X11_LINK) + +.SUFFIXES: .ml .byt + +.ml.byt: + $(CAMLC) -custom -o $*.byt unix.cma threads.cma $*.ml $(LIBS) + +$(PROGS): ../threads.cma ../libvmthreads.a diff --git a/otherlibs/threads/Tests/close.ml b/otherlibs/threads/Tests/close.ml new file mode 100644 index 0000000..21ebb44 --- /dev/null +++ b/otherlibs/threads/Tests/close.ml @@ -0,0 +1,14 @@ +let main () = + let (rd, wr) = Unix.pipe() in + Thread.create + (fun () -> + Thread.delay 3.0; + prerr_endline "closing fd..."; + Unix.close rd) + (); + let buf = String.create 10 in + prerr_endline "reading..."; + Unix.read rd buf 0 10; + prerr_endline "read returned" + +let _ = Unix.handle_unix_error main () diff --git a/otherlibs/threads/Tests/sieve.ml b/otherlibs/threads/Tests/sieve.ml new file mode 100644 index 0000000..72e2656 --- /dev/null +++ b/otherlibs/threads/Tests/sieve.ml @@ -0,0 +1,33 @@ +open Printf +open Thread + +let rec integers n ch = + Event.sync (Event.send ch n); + integers (n+1) ch + +let rec sieve n chin chout = + let m = Event.sync (Event.receive chin) + in if m mod n = 0 + then sieve n chin chout + else Event.sync (Event.send chout m); + sieve n chin chout + +let rec print_primes ch max = + let n = Event.sync (Event.receive ch) + in if n > max + then () + else begin + printf "%d\n" n; flush stdout; + let ch_after_n = Event.new_channel () + in Thread.create (sieve n ch) ch_after_n; + print_primes ch_after_n max + end + +let go max = + let ch = Event.new_channel () + in Thread.create (integers 2) ch; + print_primes ch max;; + +let _ = go 1000 + +;; diff --git a/otherlibs/threads/Tests/sorts.ml b/otherlibs/threads/Tests/sorts.ml new file mode 100644 index 0000000..abc8dc1 --- /dev/null +++ b/otherlibs/threads/Tests/sorts.ml @@ -0,0 +1,228 @@ +(* Animation of sorting algorithms. *) + +open Graphics + +(* Information on a given sorting process *) + +type graphic_context = + { array: int array; (* Data to sort *) + x0: int; (* X coordinate, lower left corner *) + y0: int; (* Y coordinate, lower left corner *) + width: int; (* Width in pixels *) + height: int; (* Height in pixels *) + nelts: int; (* Number of elements in the array *) + maxval: int; (* Max val in the array + 1 *) + rad: int (* Dimension of the rectangles *) + } + +(* Array assignment and exchange with screen update *) + +let screen_mutex = Mutex.create() + +let draw gc i v = + fill_rect (gc.x0 + (gc.width * i) / gc.nelts) + (gc.y0 + (gc.height * v) / gc.maxval) + gc.rad gc.rad + +let assign gc i v = + Mutex.lock screen_mutex; + set_color background; draw gc i gc.array.(i); + set_color foreground; draw gc i v; + gc.array.(i) <- v; + Mutex.unlock screen_mutex + +let exchange gc i j = + let val_i = gc.array.(i) in + assign gc i gc.array.(j); + assign gc j val_i + +(* Construction of a graphic context *) + +let initialize name array maxval x y w h = + let (_, label_height) = text_size name in + let rad = (w - 2) / (Array.length array) - 1 in + let gc = + { array = Array.copy array; + x0 = x + 1; (* Leave one pixel left for Y axis *) + y0 = y + 1; (* Leave one pixel below for X axis *) + width = w - 2; (* 1 pixel left, 1 pixel right *) + height = h - 1 - label_height - rad; + nelts = Array.length array; + maxval = maxval; + rad = rad } in + moveto (gc.x0 - 1) (gc.y0 + gc.height); + lineto (gc.x0 - 1) (gc.y0 - 1); + lineto (gc.x0 + gc.width) (gc.y0 - 1); + moveto (gc.x0 - 1) (gc.y0 + gc.height); + draw_string name; + for i = 0 to Array.length array - 1 do + draw gc i array.(i) + done; + gc + +(* Main animation function *) + +let display functs nelts maxval = + let a = Array.create nelts 0 in + for i = 0 to nelts - 1 do + a.(i) <- Random.int maxval + done; + let num_finished = ref 0 in + let lock_finished = Mutex.create() in + let cond_finished = Condition.create() in + for i = 0 to Array.length functs - 1 do + let (name, funct, x, y, w, h) = functs.(i) in + let gc = initialize name a maxval x y w h in + Thread.create + (fun () -> + funct gc; + Mutex.lock lock_finished; + incr num_finished; + Mutex.unlock lock_finished; + Condition.signal cond_finished) + () + done; + Mutex.lock lock_finished; + while !num_finished < Array.length functs do + Condition.wait cond_finished lock_finished + done; + Mutex.unlock lock_finished; + read_key() + +(***** + let delay = ref 0 in + try + while true do + let gc = Queue.take q in + begin match gc.action with + Finished -> () + | Pause f -> + gc.action <- f (); + for i = 0 to !delay do () done; + Queue.add gc q + end; + if key_pressed() then begin + match read_key() with + 'q'|'Q' -> + raise Exit + | '0'..'9' as c -> + delay := (Char.code c - 48) * 500 + | _ -> + () + end + done + with Exit -> () + | Queue.Empty -> read_key(); () +*****) + +(* The sorting functions. *) + +(* Bubble sort *) + +let bubble_sort gc = + let ordered = ref false in + while not !ordered do + ordered := true; + for i = 0 to Array.length gc.array - 2 do + if gc.array.(i+1) < gc.array.(i) then begin + exchange gc i (i+1); + ordered := false + end + done + done + +(* Insertion sort *) + +let insertion_sort gc = + for i = 1 to Array.length gc.array - 1 do + let val_i = gc.array.(i) in + let j = ref (i - 1) in + while !j >= 0 && val_i < gc.array.(!j) do + assign gc (!j + 1) gc.array.(!j); + decr j + done; + assign gc (!j + 1) val_i + done + +(* Selection sort *) + +let selection_sort gc = + for i = 0 to Array.length gc.array - 1 do + let min = ref i in + for j = i+1 to Array.length gc.array - 1 do + if gc.array.(j) < gc.array.(!min) then min := j + done; + exchange gc i !min + done + +(* Quick sort *) + +let quick_sort gc = + let rec quick lo hi = + if lo < hi then begin + let i = ref lo in + let j = ref hi in + let pivot = gc.array.(hi) in + while !i < !j do + while !i < hi && gc.array.(!i) <= pivot do incr i done; + while !j > lo && gc.array.(!j) >= pivot do decr j done; + if !i < !j then exchange gc !i !j + done; + exchange gc !i hi; + quick lo (!i-1); + quick (!i+1) hi + end + in quick 0 (Array.length gc.array - 1) + +(* Merge sort *) + +let merge_sort gc = + let rec merge i l1 l2 = + match (l1, l2) with + ([], []) -> + () + | ([], v2::r2) -> + assign gc i v2; merge (i+1) l1 r2 + | (v1::r1, []) -> + assign gc i v1; merge (i+1) r1 l2 + | (v1::r1, v2::r2) -> + if v1 < v2 + then begin assign gc i v1; merge (i+1) r1 l2 end + else begin assign gc i v2; merge (i+1) l1 r2 end in + let rec msort start len = + if len < 2 then () else begin + let m = len / 2 in + msort start m; + msort (start+m) (len-m); + merge start + (Array.to_list (Array.sub gc.array start m)) + (Array.to_list (Array.sub gc.array (start+m) (len-m))) + end in + msort 0 (Array.length gc.array) + +(* Main program *) + +let animate() = + open_graph ""; + moveto 0 0; draw_string "Press a key to start..."; + let seed = ref 0 in + while not (key_pressed()) do incr seed done; + read_key(); + Random.init !seed; + clear_graph(); + let prompt = "0: fastest ... 9: slowest, press 'q' to quit" in + moveto 0 0; draw_string prompt; + let (_, h) = text_size prompt in + let sx = size_x() / 2 and sy = (size_y() - h) / 3 in + display [| "Bubble", bubble_sort, 0, h, sx, sy; + "Insertion", insertion_sort, 0, h+sy, sx, sy; + "Selection", selection_sort, 0, h+2*sy, sx, sy; + "Quicksort", quick_sort, sx, h, sx, sy; + (** "Heapsort", heap_sort, sx, h+sy, sx, sy; **) + "Mergesort", merge_sort, sx, h+2*sy, sx, sy |] + 100 1000; + close_graph() + +let _ = if !Sys.interactive then () else begin animate(); exit 0 end + +;; diff --git a/otherlibs/threads/Tests/test1.ml b/otherlibs/threads/Tests/test1.ml new file mode 100644 index 0000000..9d2cf0a --- /dev/null +++ b/otherlibs/threads/Tests/test1.ml @@ -0,0 +1,57 @@ +(* Classic producer-consumer *) + +type 'a prodcons = + { buffer: 'a array; + lock: Mutex.t; + mutable readpos: int; + mutable writepos: int; + notempty: Condition.t; + notfull: Condition.t } + +let create size init = + { buffer = Array.create size init; + lock = Mutex.create(); + readpos = 0; + writepos = 0; + notempty = Condition.create(); + notfull = Condition.create() } + +let put p data = + Mutex.lock p.lock; + while (p.writepos + 1) mod Array.length p.buffer = p.readpos do + Condition.wait p.notfull p.lock + done; + p.buffer.(p.writepos) <- data; + p.writepos <- (p.writepos + 1) mod Array.length p.buffer; + Condition.signal p.notempty; + Mutex.unlock p.lock + +let get p = + Mutex.lock p.lock; + while p.writepos = p.readpos do + Condition.wait p.notempty p.lock + done; + let data = p.buffer.(p.readpos) in + p.readpos <- (p.readpos + 1) mod Array.length p.buffer; + Condition.signal p.notfull; + Mutex.unlock p.lock; + data + +(* Test *) + +let buff = create 20 0 + +let rec produce n = + print_int n; print_string "-->"; print_newline(); + put buff n; + if n < 10000 then produce (n+1) + +let rec consume () = + let n = get buff in + print_string "-->"; print_int n; print_newline(); + if n < 10000 then consume () + +let t1 = Thread.create produce 0 +let _ = consume () + +;; diff --git a/otherlibs/threads/Tests/test2.ml b/otherlibs/threads/Tests/test2.ml new file mode 100644 index 0000000..926f090 --- /dev/null +++ b/otherlibs/threads/Tests/test2.ml @@ -0,0 +1,15 @@ +let yield = ref false + +let print_message c = + for i = 1 to 10000 do + print_char c; flush stdout; + if !yield then Thread.yield() + done + +let _ = yield := (Array.length Sys.argv > 1) +let t1 = Thread.create print_message 'a' +let t2 = Thread.create print_message 'b' +let _ = Thread.join t1 +let _ = Thread.join t2 + +;; diff --git a/otherlibs/threads/Tests/test3.ml b/otherlibs/threads/Tests/test3.ml new file mode 100644 index 0000000..c6df332 --- /dev/null +++ b/otherlibs/threads/Tests/test3.ml @@ -0,0 +1,8 @@ +let print_message delay c = + while true do + print_char c; flush stdout; Thread.delay delay + done + +let _ = + Thread.create (print_message 0.6666666666) 'a'; + print_message 1.0 'b' diff --git a/otherlibs/threads/Tests/test4.ml b/otherlibs/threads/Tests/test4.ml new file mode 100644 index 0000000..ff84961 --- /dev/null +++ b/otherlibs/threads/Tests/test4.ml @@ -0,0 +1,13 @@ +let rec fib n = if n <= 2 then 1 else fib(n-1) + fib(n-2) + +let fibtask n = + while true do + print_int(fib n); print_newline() + done + +let _ = + Thread.create fibtask 28; + while true do + let l = read_line () in + print_string ">> "; print_string l; print_newline() + done diff --git a/otherlibs/threads/Tests/test5.ml b/otherlibs/threads/Tests/test5.ml new file mode 100644 index 0000000..2baffe0 --- /dev/null +++ b/otherlibs/threads/Tests/test5.ml @@ -0,0 +1,21 @@ +open Event + +let ch = (new_channel() : string channel) + +let rec sender msg = + sync (send ch msg); + sender msg + +let rec receiver name = + print_string (name ^ ": " ^ sync (receive ch) ^ "\n"); + flush stdout; + receiver name + +let _ = + Thread.create sender "hello"; + Thread.create sender "world"; + Thread.create receiver "A"; + receiver "B"; + exit 0 + + diff --git a/otherlibs/threads/Tests/test6.ml b/otherlibs/threads/Tests/test6.ml new file mode 100644 index 0000000..b846858 --- /dev/null +++ b/otherlibs/threads/Tests/test6.ml @@ -0,0 +1,17 @@ +open Event + +let ch = (new_channel() : string channel) + +let rec f tag msg = + select [ + send ch msg; + wrap (receive ch) (fun x -> print_string(tag ^ ": " ^ x); print_newline()) + ]; + f tag msg + +let _ = + Thread.create (f "A") "hello"; + f "B" "world"; + exit 0 + + diff --git a/otherlibs/threads/Tests/test7.ml b/otherlibs/threads/Tests/test7.ml new file mode 100644 index 0000000..e6bd1d8 --- /dev/null +++ b/otherlibs/threads/Tests/test7.ml @@ -0,0 +1,28 @@ +open Event + +let add_ch = new_channel() +let sub_ch = new_channel() +let read_ch = new_channel() + +let rec accu n = + select [ + wrap (receive add_ch) (fun x -> accu (n+x)); + wrap (receive sub_ch) (fun x -> accu (n-x)); + wrap (send read_ch n) (fun () -> accu n) + ] + +let rec sender chan value = + sync(send chan value); sender chan value + +let read () = + print_int(sync(receive read_ch)); print_newline() + +let main () = + Thread.create accu 0; + Thread.create (sender add_ch) 1; + Thread.create (sender sub_ch) 1; + while true do read() done + +let _ = Printexc.catch main () + + diff --git a/otherlibs/threads/Tests/test8.ml b/otherlibs/threads/Tests/test8.ml new file mode 100644 index 0000000..cc587b0 --- /dev/null +++ b/otherlibs/threads/Tests/test8.ml @@ -0,0 +1,46 @@ +open Event + +type 'a buffer_channel = { input: 'a channel; output: 'a channel } + +let new_buffer_channel() = + let ic = new_channel() in + let oc = new_channel() in + let buff = Queue.create() in + let rec buffer_process front rear = + match (front, rear) with + ([], []) -> buffer_process [sync(receive ic)] [] + | (hd::tl, _) -> + select [ + wrap (receive ic) (fun x -> buffer_process front (x::rear)); + wrap (send oc hd) (fun () -> buffer_process tl rear) + ] + | ([], _) -> buffer_process (List.rev rear) [] in + Thread.create (buffer_process []) []; + { input = ic; output = oc } + +let buffer_send bc data = + sync(send bc.input data) + +let buffer_receive bc = + receive bc.output + +(* Test *) + +let box = new_buffer_channel() +let ch = new_channel() + +let f () = + buffer_send box "un"; + buffer_send box "deux"; + sync (send ch 3) + +let g () = + print_int (sync(receive ch)); print_newline(); + print_string (sync(buffer_receive box)); print_newline(); + print_string (sync(buffer_receive box)); print_newline() + +let _ = + Thread.create f (); + g() + + diff --git a/otherlibs/threads/Tests/test9.ml b/otherlibs/threads/Tests/test9.ml new file mode 100644 index 0000000..1f80beb --- /dev/null +++ b/otherlibs/threads/Tests/test9.ml @@ -0,0 +1,26 @@ +open Event + +type 'a swap_chan = ('a * 'a channel) channel + +let swap msg_out ch = + guard (fun () -> + let ic = new_channel() in + choose [ + wrap (receive ch) (fun (msg_in, oc) -> sync (send oc msg_out); msg_in); + wrap (send ch (msg_out, ic)) (fun () -> sync (receive ic)) + ]) + +let ch = new_channel() + +let f () = + let res = sync (swap "F" ch) in + print_string "f "; print_string res; print_newline() + +let g () = + let res = sync (swap "G" ch) in + print_string "g "; print_string res; print_newline() + +let _ = + let id = Thread.create f () in + g (); + Thread.join id diff --git a/otherlibs/threads/Tests/testA.ml b/otherlibs/threads/Tests/testA.ml new file mode 100644 index 0000000..b1999b8 --- /dev/null +++ b/otherlibs/threads/Tests/testA.ml @@ -0,0 +1,24 @@ +let private_data = (Hashtbl.create 17 : (Thread.t, string) Hashtbl.t) +let private_data_lock = Mutex.create() + +let set_private_data data = + Mutex.lock private_data_lock; + Hashtbl.add private_data (Thread.self()) data; + Mutex.unlock private_data_lock + +let get_private_data () = + Hashtbl.find private_data (Thread.self()) + +let process id data = + set_private_data data; + print_int id; print_string " --> "; print_string(get_private_data()); + print_newline() + +let _ = + let t1 = Thread.create (process 1) "un" in + let t2 = Thread.create (process 2) "deux" in + let t3 = Thread.create (process 3) "trois" in + let t4 = Thread.create (process 4) "quatre" in + let t5 = Thread.create (process 5) "cinq" in + List.iter Thread.join [t1;t2;t3;t4;t5] + diff --git a/otherlibs/threads/Tests/testexit.ml b/otherlibs/threads/Tests/testexit.ml new file mode 100644 index 0000000..2045c25 --- /dev/null +++ b/otherlibs/threads/Tests/testexit.ml @@ -0,0 +1,22 @@ +(* Test Thread.exit *) + +let somethread (name, limit, last) = + let counter = ref 0 in + while true do + incr counter; + if !counter >= limit then begin + print_string (name ^ " exiting\n"); + flush stdout; + if last then exit 0 else Thread.exit() + end; + print_string (name ^ ": " ^ string_of_int !counter ^ "\n"); + flush stdout; + Thread.delay 0.5 + done + +let _ = + let _ = Thread.create somethread ("A", 5, false) in + let _ = Thread.create somethread ("B", 8, false) in + let _ = Thread.create somethread ("C", 11, true) in + somethread ("Main", 3, false) + diff --git a/otherlibs/threads/Tests/testio.ml b/otherlibs/threads/Tests/testio.ml new file mode 100644 index 0000000..5f0ec50 --- /dev/null +++ b/otherlibs/threads/Tests/testio.ml @@ -0,0 +1,120 @@ +(* Test a file copy function *) + +let test msg producer consumer src dst = + print_string msg; print_newline(); + let ic = open_in_bin src in + let oc = open_out_bin dst in + let (in_fd, out_fd) = Unix.pipe() in + let ipipe = Unix.in_channel_of_descr in_fd in + let opipe = Unix.out_channel_of_descr out_fd in + let prod = Thread.create producer (ic, opipe) in + let cons = Thread.create consumer (ipipe, oc) in + Thread.join prod; + Thread.join cons; + if Unix.system ("cmp " ^ src ^ " " ^ dst) = Unix.WEXITED 0 + then print_string "passed" + else print_string "FAILED"; + print_newline() + +(* File copy with constant-sized chunks *) + +let copy_file sz (ic, oc) = + let buffer = String.create sz in + let rec copy () = + let n = input ic buffer 0 sz in + if n = 0 then () else begin + output oc buffer 0 n; + copy () + end in + copy(); + close_in ic; + close_out oc + +(* File copy with random-sized chunks *) + +let copy_random sz (ic, oc) = + let buffer = String.create sz in + let rec copy () = + let s = 1 + Random.int sz in + let n = input ic buffer 0 s in + if n = 0 then () else begin + output oc buffer 0 n; + copy () + end in + copy(); + close_in ic; + close_out oc + +(* File copy line per line *) + +let copy_line (ic, oc) = + try + while true do + output_string oc (input_line ic); output_char oc '\n' + done + with End_of_file -> + close_in ic; + close_out oc + +(* Create long lines of text *) + +let make_lines ofile = + let oc = open_out ofile in + for i = 1 to 256 do + output_string oc (String.make (i*16) '.'); output_char oc '\n' + done; + close_out oc + +(* Test input_line on truncated lines *) + +let test_trunc_line ofile = + print_string "truncated line"; print_newline(); + let oc = open_out ofile in + output_string oc "A line without newline!"; + close_out oc; + try + let ic = open_in ofile in + let s = input_line ic in + close_in ic; + if s = "A line without newline!" + then print_string "passed" + else print_string "FAILED"; + print_newline() + with End_of_file -> + print_string "FAILED"; print_newline() + +(* The test *) + +let main() = + let ifile = Sys.argv.(1) in + let ofile = Filename.temp_file "testio" "" in + test "256-byte chunks, 256-byte chunks" + (copy_file 256) (copy_file 256) ifile ofile; + test "4096-byte chunks, 4096-byte chunks" + (copy_file 4096) (copy_file 4096) ifile ofile; + test "65536-byte chunks, 65536-byte chunks" + (copy_file 65536) (copy_file 65536) ifile ofile; + test "256-byte chunks, 4096-byte chunks" + (copy_file 256) (copy_file 4096) ifile ofile; + test "4096-byte chunks, 256-byte chunks" + (copy_file 4096) (copy_file 256) ifile ofile; + test "4096-byte chunks, 65536-byte chunks" + (copy_file 4096) (copy_file 65536) ifile ofile; + test "263-byte chunks, 4011-byte chunks" + (copy_file 263) (copy_file 4011) ifile ofile; + test "613-byte chunks, 1027-byte chunks" + (copy_file 613) (copy_file 1027) ifile ofile; + test "0...8192 byte chunks" + (copy_random 8192) (copy_random 8192) ifile ofile; + test "line per line, short lines" + copy_line copy_line "/etc/hosts" ofile; + let linesfile = Filename.temp_file "lines" "" in + make_lines linesfile; + test "line per line, short and long lines" + copy_line copy_line linesfile ofile; + test_trunc_line ofile; + Sys.remove linesfile; + Sys.remove ofile; + exit 0 + +let _ = Unix.handle_unix_error main (); exit 0 diff --git a/otherlibs/threads/Tests/testsieve.ml b/otherlibs/threads/Tests/testsieve.ml new file mode 100644 index 0000000..6079d8a --- /dev/null +++ b/otherlibs/threads/Tests/testsieve.ml @@ -0,0 +1,42 @@ +let sieve primes= + Event.sync (Event.send primes 0); + Event.sync (Event.send primes 1); + Event.sync (Event.send primes 2); + let integers = Event.new_channel () in + let rec enumerate n= + Event.sync (Event.send integers n); + enumerate (n + 2) + and filter inpout = + let n = Event.sync (Event.receive inpout) + (* On prepare le terrain pour l'appel recursif *) + and output = Event.new_channel () in + (* Celui qui etait en tete du crible est premier *) + Event.sync (Event.send primes n); + Thread.create filter output; + (* On elimine de la sortie ceux qui sont des multiples de n *) + while true do + let m = Event.sync (Event.receive inpout) in + (* print_int n; print_string ": "; print_int m; print_newline(); *) + if (m mod n) = 0 + then () + else ((Event.sync (Event.send output m));()) + done in + Thread.create filter integers; + Thread.create enumerate 3 + +let premiers = Event.new_channel () + +let main _ = + Thread.create sieve premiers; + while true do + for i = 1 to 100 do + let n = Event.sync (Event.receive premiers) in + print_int n; print_newline() + done; + exit 0 + done + + +let _ = + try main () + with _ -> exit 0;; diff --git a/otherlibs/threads/Tests/testsignal.ml b/otherlibs/threads/Tests/testsignal.ml new file mode 100644 index 0000000..7781f33 --- /dev/null +++ b/otherlibs/threads/Tests/testsignal.ml @@ -0,0 +1,13 @@ +let sighandler _ = + print_string "Got ctrl-C, exiting..."; print_newline(); + exit 0 + +let print_message delay c = + while true do + print_char c; flush stdout; Thread.delay delay + done + +let _ = + Sys.signal Sys.sigint (Sys.Signal_handle sighandler); + Thread.create (print_message 0.6666666666) 'a'; + print_message 1.0 'b' diff --git a/otherlibs/threads/Tests/testsignal2.ml b/otherlibs/threads/Tests/testsignal2.ml new file mode 100644 index 0000000..c73bdb9 --- /dev/null +++ b/otherlibs/threads/Tests/testsignal2.ml @@ -0,0 +1,11 @@ +let print_message delay c = + while true do + print_char c; flush stdout; Thread.delay delay + done + +let _ = + Thread.sigmask Unix.SIG_BLOCK [Sys.sigint; Sys.sigterm]; + let th1 = Thread.create (print_message 0.6666666666) 'a' in + let th2 = Thread.create (print_message 1.0) 'b' in + let s = Thread.wait_signal [Sys.sigint; Sys.sigterm] in + Printf.printf "Got signal %d, exiting...\n" s diff --git a/otherlibs/threads/Tests/testsocket.ml b/otherlibs/threads/Tests/testsocket.ml new file mode 100644 index 0000000..d0f14cb --- /dev/null +++ b/otherlibs/threads/Tests/testsocket.ml @@ -0,0 +1,31 @@ +open Unix + +let engine number address = + print_int number; print_string "> connecting"; print_newline(); + let (ic, oc) = open_connection (ADDR_INET(address, 80)) in + print_int number; print_string "> connected"; print_newline(); + output_string oc "GET / HTTP1.0\r\n\r\n"; flush oc; + try + while true do + let s = input_line ic in + print_int number; print_string ">"; print_string s; print_newline() + done + with End_of_file -> + close_out oc + +let main() = + let addresses = Array.create (Array.length Sys.argv - 1) inet_addr_any in + for i = 1 to Array.length Sys.argv - 1 do + addresses.(i - 1) <- (gethostbyname Sys.argv.(i)).h_addr_list.(0) + done; + let processes = Array.create (Array.length addresses) (Thread.self()) in + for i = 0 to Array.length addresses - 1 do + processes.(i) <- Thread.create (engine i) addresses.(i) + done; + for i = 0 to Array.length processes - 1 do + Thread.join processes.(i) + done + +let _ = Printexc.catch main (); exit 0 + + diff --git a/otherlibs/threads/Tests/token1.ml b/otherlibs/threads/Tests/token1.ml new file mode 100644 index 0000000..fb0ddb2 --- /dev/null +++ b/otherlibs/threads/Tests/token1.ml @@ -0,0 +1,36 @@ +(* Performance test for mutexes and conditions *) + +let mut = Mutex.create() + +let niter = ref 0 + +let token = ref 0 + +let process (n, conds, nprocs) = + while true do + Mutex.lock mut; + while !token <> n do + (* Printf.printf "Thread %d waiting (token = %d)\n" n !token; *) + Condition.wait conds.(n) mut + done; + (* Printf.printf "Thread %d got token %d\n" n !token; *) + incr token; + if !token >= nprocs then token := 0; + if n = 0 then begin + decr niter; + if !niter <= 0 then exit 0 + end; + Condition.signal conds.(!token); + Mutex.unlock mut + done + +let main() = + let nprocs = int_of_string Sys.argv.(1) in + let iter = int_of_string Sys.argv.(2) in + let conds = Array.create nprocs (Condition.create()) in + for i = 1 to nprocs - 1 do conds.(i) <- Condition.create() done; + niter := iter; + for i = 0 to nprocs - 1 do Thread.create process (i, conds, nprocs) done; + Thread.delay 3600. + +let _ = main() diff --git a/otherlibs/threads/Tests/token2.ml b/otherlibs/threads/Tests/token2.ml new file mode 100644 index 0000000..32b897d --- /dev/null +++ b/otherlibs/threads/Tests/token2.ml @@ -0,0 +1,36 @@ +(* Performance test for I/O scheduling *) + +let mut = Mutex.create() + +let niter = ref 0 + +let token = ref 0 + +let process (n, ins, outs, nprocs) = + let buf = String.create 1 in + while true do + Unix.read ins.(n) buf 0 1; + (* Printf.printf "Thread %d got the token\n" n; *) + if n = 0 then begin + decr niter; + if !niter <= 0 then exit 0 + end; + let next = if n + 1 >= nprocs then 0 else n + 1 in + (* Printf.printf "Thread %d sending token to thread %d\n" n next; *) + Unix.write outs.(next) buf 0 1 + done + +let main() = + let nprocs = int_of_string Sys.argv.(1) in + let iter = int_of_string Sys.argv.(2) in + let ins = Array.create nprocs Unix.stdin in + let outs = Array.create nprocs Unix.stdout in + for n = 0 to nprocs - 1 do + let (i, o) = Unix.pipe() in ins.(n) <- i; outs.(n) <- o + done; + niter := iter; + for i = 0 to nprocs - 1 do Thread.create process (i, ins, outs, nprocs) done; + Unix.write outs.(0) "X" 0 1; + Thread.delay 3600. + +let _ = main() diff --git a/otherlibs/threads/Tests/torture.ml b/otherlibs/threads/Tests/torture.ml new file mode 100644 index 0000000..b52766d --- /dev/null +++ b/otherlibs/threads/Tests/torture.ml @@ -0,0 +1,46 @@ +(* Torture test - lots of GC *) + +let gc_thread () = + while true do +(* print_string "gc"; print_newline(); *) + Gc.minor(); + Thread.yield() + done + +let stdin_thread () = + while true do + print_string "> "; flush stdout; + let s = read_line() in + print_string ">>> "; print_string s; print_newline() + done + +let writer_thread (oc, size) = + while true do +(* print_string "writer "; print_int size; print_newline(); *) + let buff = String.make size 'a' in + Unix.write oc buff 0 size + done + +let reader_thread (ic, size) = + while true do +(* print_string "reader "; print_int size; print_newline(); *) + let buff = String.create size in + let n = Unix.read ic buff 0 size in +(* print_string "reader "; print_int n; print_newline(); *) + for i = 0 to n-1 do + if buff.[i] <> 'a' then prerr_endline "error in reader_thread" + done + done + +let main() = + Thread.create gc_thread (); + let (out1, in1) = Unix.pipe() in + Thread.create writer_thread (in1, 4096); + Thread.create reader_thread (out1, 4096); + let (out2, in2) = Unix.pipe() in + Thread.create writer_thread (in2, 16); + Thread.create reader_thread (out2, 16); + stdin_thread() + +let _ = main() + diff --git a/otherlibs/threads/condition.ml b/otherlibs/threads/condition.ml new file mode 100644 index 0000000..2d7abca --- /dev/null +++ b/otherlibs/threads/condition.ml @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: condition.ml,v 1.8 2001-12-07 13:40:21 xleroy Exp $ *) + +type t = { mutable waiting: Thread.t list } + +let create () = { waiting = [] } + +let wait cond mut = + Thread.critical_section := true; + Mutex.unlock mut; + cond.waiting <- Thread.self() :: cond.waiting; + Thread.sleep(); + Mutex.lock mut + +let signal cond = + match cond.waiting with (* atomic *) + [] -> () + | th :: rem -> cond.waiting <- rem (* atomic *); Thread.wakeup th + +let broadcast cond = + let w = cond.waiting in (* atomic *) + cond.waiting <- []; (* atomic *) + List.iter Thread.wakeup w + diff --git a/otherlibs/threads/condition.mli b/otherlibs/threads/condition.mli new file mode 100644 index 0000000..92521df --- /dev/null +++ b/otherlibs/threads/condition.mli @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: condition.mli,v 1.13 2001-12-07 13:40:21 xleroy Exp $ *) + +(** Condition variables to synchronize between threads. + + Condition variables are used when one thread wants to wait until another + thread has finished doing something: the former thread ``waits'' on the + condition variable, the latter thread ``signals'' the condition when it + is done. Condition variables should always be protected by a mutex. + The typical use is (if [D] is a shared data structure, [m] its mutex, + and [c] is a condition variable): + {[ + Mutex.lock m; + while (* some predicate P over D is not satisfied *) do + Condition.wait c m + done; + (* Modify D *) + if (* the predicate P over D is now satified *) then Condition.signal c; + Mutex.unlock m + ]} +*) + +type t +(** The type of condition variables. *) + +val create : unit -> t +(** Return a new condition variable. *) + +val wait : t -> Mutex.t -> unit +(** [wait c m] atomically unlocks the mutex [m] and suspends the + calling process on the condition variable [c]. The process will + restart after the condition variable [c] has been signalled. + The mutex [m] is locked again before [wait] returns. *) + +val signal : t -> unit +(** [signal c] restarts one of the processes waiting on the + condition variable [c]. *) + +val broadcast : t -> unit +(** [broadcast c] restarts all processes waiting on the + condition variable [c]. *) diff --git a/otherlibs/threads/event.ml b/otherlibs/threads/event.ml new file mode 100644 index 0000000..87d5ab4 --- /dev/null +++ b/otherlibs/threads/event.ml @@ -0,0 +1,274 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* David Nowak and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: event.ml,v 1.14 2001-12-07 13:40:21 xleroy Exp $ *) + +(* Events *) +type 'a basic_event = + { poll: unit -> bool; + (* If communication can take place immediately, return true. *) + suspend: unit -> unit; + (* Offer the communication on the channel and get ready + to suspend current process. *) + result: unit -> 'a } + (* Return the result of the communication *) + +type 'a behavior = int ref -> Condition.t -> int -> 'a basic_event + +type 'a event = + Communication of 'a behavior + | Choose of 'a event list + | WrapAbort of 'a event * (unit -> unit) + | Guard of (unit -> 'a event) + +(* Communication channels *) +type 'a channel = + { mutable writes_pending: 'a communication Queue.t; + (* All offers to write on it *) + mutable reads_pending: 'a communication Queue.t } + (* All offers to read from it *) + +(* Communication offered *) +and 'a communication = + { performed: int ref; (* -1 if not performed yet, set to the number *) + (* of the matching communication after rendez-vous. *) + condition: Condition.t; (* To restart the blocked thread. *) + mutable data: 'a option; (* The data sent or received. *) + event_number: int } (* Event number in select *) + +(* Create a channel *) + +let new_channel () = + { writes_pending = Queue.create(); + reads_pending = Queue.create() } + +(* Basic synchronization function *) + +let masterlock = Mutex.create() + +let do_aborts abort_env genev performed = + if abort_env <> [] then begin + if performed >= 0 then begin + let ids_done = snd genev.(performed) in + List.iter + (fun (id,f) -> if not (List.mem id ids_done) then f ()) + abort_env + end else begin + List.iter (fun (_,f) -> f ()) abort_env + end + end + +let basic_sync abort_env genev = + let performed = ref (-1) in + let condition = Condition.create() in + let bev = Array.create (Array.length genev) + (fst (genev.(0)) performed condition 0) in + for i = 1 to Array.length genev - 1 do + bev.(i) <- (fst genev.(i)) performed condition i + done; + (* See if any of the events is already activable *) + let rec poll_events i = + if i >= Array.length bev + then false + else bev.(i).poll() || poll_events (i+1) in + Mutex.lock masterlock; + if not (poll_events 0) then begin + (* Suspend on all events *) + for i = 0 to Array.length bev - 1 do bev.(i).suspend() done; + (* Wait until the condition is signalled *) + Condition.wait condition masterlock + end; + Mutex.unlock masterlock; + (* Extract the result *) + if abort_env = [] then + (* Preserve tail recursion *) + bev.(!performed).result() + else begin + let num = !performed in + let result = bev.(num).result() in + (* Handle the aborts and return the result *) + do_aborts abort_env genev num; + result + end + +(* Apply a random permutation on an array *) + +let scramble_array a = + let len = Array.length a in + if len = 0 then invalid_arg "Event.choose"; + for i = len - 1 downto 1 do + let j = Random.int (i + 1) in + let temp = a.(i) in a.(i) <- a.(j); a.(j) <- temp + done; + a + +(* Main synchronization function *) + +let gensym = let count = ref 0 in fun () -> incr count; !count + +let rec flatten_event + (abort_list : int list) + (accu : ('a behavior * int list) list) + (accu_abort : (int * (unit -> unit)) list) + ev = + match ev with + Communication bev -> ((bev,abort_list) :: accu) , accu_abort + | WrapAbort (ev,fn) -> + let id = gensym () in + flatten_event (id :: abort_list) accu ((id,fn)::accu_abort) ev + | Choose evl -> + let rec flatten_list accu' accu_abort'= function + ev :: l -> + let (accu'',accu_abort'') = + flatten_event abort_list accu' accu_abort' ev in + flatten_list accu'' accu_abort'' l + | [] -> (accu',accu_abort') in + flatten_list accu accu_abort evl + | Guard fn -> flatten_event abort_list accu accu_abort (fn ()) + +let sync ev = + let (evl,abort_env) = flatten_event [] [] [] ev in + basic_sync abort_env (scramble_array(Array.of_list evl)) + +(* Event polling -- like sync, but non-blocking *) + +let basic_poll abort_env genev = + let performed = ref (-1) in + let condition = Condition.create() in + let bev = Array.create(Array.length genev) + (fst genev.(0) performed condition 0) in + for i = 1 to Array.length genev - 1 do + bev.(i) <- fst genev.(i) performed condition i + done; + (* See if any of the events is already activable *) + let rec poll_events i = + if i >= Array.length bev + then false + else bev.(i).poll() || poll_events (i+1) in + Mutex.lock masterlock; + let ready = poll_events 0 in + if ready then begin + (* Extract the result *) + Mutex.unlock masterlock; + let result = Some(bev.(!performed).result()) in + do_aborts abort_env genev !performed; result + end else begin + (* Cancel the communication offers *) + performed := 0; + Mutex.unlock masterlock; + do_aborts abort_env genev (-1); + None + end + +let poll ev = + let (evl,abort_env) = flatten_event [] [] [] ev in + basic_poll abort_env (scramble_array(Array.of_list evl)) + +(* Remove all communication opportunities already synchronized *) + +let cleanup_queue q = + let q' = Queue.create() in + Queue.iter (fun c -> if !(c.performed) = -1 then Queue.add c q') q; + q' + +(* Event construction *) + +let always data = + Communication(fun performed condition evnum -> + { poll = (fun () -> performed := evnum; true); + suspend = (fun () -> ()); + result = (fun () -> data) }) + +let send channel data = + Communication(fun performed condition evnum -> + let wcomm = + { performed = performed; + condition = condition; + data = Some data; + event_number = evnum } in + { poll = (fun () -> + let rec poll () = + let rcomm = Queue.take channel.reads_pending in + if !(rcomm.performed) >= 0 then + poll () + else begin + rcomm.data <- wcomm.data; + performed := evnum; + rcomm.performed := rcomm.event_number; + Condition.signal rcomm.condition + end in + try + poll(); + true + with Queue.Empty -> + false); + suspend = (fun () -> + channel.writes_pending <- cleanup_queue channel.writes_pending; + Queue.add wcomm channel.writes_pending); + result = (fun () -> ()) }) + +let receive channel = + Communication(fun performed condition evnum -> + let rcomm = + { performed = performed; + condition = condition; + data = None; + event_number = evnum } in + { poll = (fun () -> + let rec poll () = + let wcomm = Queue.take channel.writes_pending in + if !(wcomm.performed) >= 0 then + poll () + else begin + rcomm.data <- wcomm.data; + performed := evnum; + wcomm.performed := wcomm.event_number; + Condition.signal wcomm.condition + end in + try + poll(); + true + with Queue.Empty -> + false); + suspend = (fun () -> + channel.reads_pending <- cleanup_queue channel.reads_pending; + Queue.add rcomm channel.reads_pending); + result = (fun () -> + match rcomm.data with + None -> invalid_arg "Event.receive" + | Some res -> res) }) + +let choose evl = Choose evl + +let wrap_abort ev fn = WrapAbort(ev,fn) + +let guard fn = Guard fn + +let rec wrap ev fn = + match ev with + Communication genev -> + Communication(fun performed condition evnum -> + let bev = genev performed condition evnum in + { poll = bev.poll; + suspend = bev.suspend; + result = (fun () -> fn(bev.result())) }) + | Choose evl -> + Choose(List.map (fun ev -> wrap ev fn) evl) + | WrapAbort (ev, f') -> + WrapAbort (wrap ev fn, f') + | Guard gu -> + Guard(fun () -> wrap (gu()) fn) + +(* Convenience functions *) + +let select evl = sync(Choose evl) diff --git a/otherlibs/threads/event.mli b/otherlibs/threads/event.mli new file mode 100644 index 0000000..a493026 --- /dev/null +++ b/otherlibs/threads/event.mli @@ -0,0 +1,82 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* David Nowak and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: event.mli,v 1.15 2006-01-12 03:24:56 garrigue Exp $ *) + +(** First-class synchronous communication. + + This module implements synchronous inter-thread communications over + channels. As in John Reppy's Concurrent ML system, the communication + events are first-class values: they can be built and combined + independently before being offered for communication. +*) + +type 'a channel +(** The type of communication channels carrying values of type ['a]. *) + +val new_channel : unit -> 'a channel +(** Return a new channel. *) + +type +'a event +(** The type of communication events returning a result of type ['a]. *) + +(** [send ch v] returns the event consisting in sending the value [v] + over the channel [ch]. The result value of this event is [()]. *) +val send : 'a channel -> 'a -> unit event + +(** [receive ch] returns the event consisting in receiving a value + from the channel [ch]. The result value of this event is the + value received. *) +val receive : 'a channel -> 'a event + +val always : 'a -> 'a event +(** [always v] returns an event that is always ready for + synchronization. The result value of this event is [v]. *) + +val choose : 'a event list -> 'a event +(** [choose evl] returns the event that is the alternative of + all the events in the list [evl]. *) + +val wrap : 'a event -> ('a -> 'b) -> 'b event +(** [wrap ev fn] returns the event that performs the same communications + as [ev], then applies the post-processing function [fn] + on the return value. *) + +val wrap_abort : 'a event -> (unit -> unit) -> 'a event +(** [wrap_abort ev fn] returns the event that performs + the same communications as [ev], but if it is not selected + the function [fn] is called after the synchronization. *) + +val guard : (unit -> 'a event) -> 'a event +(** [guard fn] returns the event that, when synchronized, computes + [fn()] and behaves as the resulting event. This allows to + compute events with side-effects at the time of the synchronization + operation. *) + +val sync : 'a event -> 'a +(** ``Synchronize'' on an event: offer all the communication + possibilities specified in the event to the outside world, + and block until one of the communications succeed. The result + value of that communication is returned. *) + +val select : 'a event list -> 'a +(** ``Synchronize'' on an alternative of events. + [select evl] is shorthand for [sync(choose evl)]. *) + +val poll : 'a event -> 'a option +(** Non-blocking version of {!Event.sync}: offer all the communication + possibilities specified in the event to the outside world, + and if one can take place immediately, perform it and return + [Some r] where [r] is the result value of that communication. + Otherwise, return [None] without blocking. *) + diff --git a/otherlibs/threads/libvmthreads.clib b/otherlibs/threads/libvmthreads.clib new file mode 100644 index 0000000..0b4f31e --- /dev/null +++ b/otherlibs/threads/libvmthreads.clib @@ -0,0 +1 @@ +scheduler.o diff --git a/otherlibs/threads/marshal.ml b/otherlibs/threads/marshal.ml new file mode 100644 index 0000000..f790f53 --- /dev/null +++ b/otherlibs/threads/marshal.ml @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: marshal.ml,v 1.9 2004-05-27 15:28:05 doligez Exp $ *) + +type extern_flags = + No_sharing + | Closures + +external to_string: 'a -> extern_flags list -> string + = "caml_output_value_to_string" + +let to_channel chan v flags = + output_string chan (to_string v flags) + +external to_buffer_unsafe: + string -> int -> int -> 'a -> extern_flags list -> int + = "caml_output_value_to_buffer" + +let to_buffer buff ofs len v flags = + if ofs < 0 || len < 0 || ofs + len > String.length buff + then invalid_arg "Marshal.to_buffer: substring out of bounds" + else to_buffer_unsafe buff ofs len v flags + +let to_buffer' ~buf ~pos ~len v ~mode = to_buffer buf pos len v mode + +external from_string_unsafe: string -> int -> 'a + = "caml_input_value_from_string" +external data_size_unsafe: string -> int -> int = "caml_marshal_data_size" + +let header_size = 20 +let data_size buff ofs = + if ofs < 0 || ofs > String.length buff - header_size + then invalid_arg "Marshal.data_size" + else data_size_unsafe buff ofs +let total_size buff ofs = header_size + data_size buff ofs + +let from_string buff ofs = + if ofs < 0 || ofs > String.length buff - header_size + then invalid_arg "Marshal.from_size" + else begin + let len = data_size_unsafe buff ofs in + if ofs > String.length buff - (header_size + len) + then invalid_arg "Marshal.from_string" + else from_string_unsafe buff ofs + end + +let from_channel = Pervasives.input_value diff --git a/otherlibs/threads/mutex.ml b/otherlibs/threads/mutex.ml new file mode 100644 index 0000000..e197a3a --- /dev/null +++ b/otherlibs/threads/mutex.ml @@ -0,0 +1,39 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: mutex.ml,v 1.8 2001-12-07 13:40:22 xleroy Exp $ *) + +type t = { mutable locked: bool; mutable waiting: Thread.t list } + +let create () = { locked = false; waiting = [] } + +let rec lock m = + if m.locked then begin (* test and set atomic *) + Thread.critical_section := true; + m.waiting <- Thread.self() :: m.waiting; + Thread.sleep(); + lock m + end else begin + m.locked <- true (* test and set atomic *) + end + +let try_lock m = (* test and set atomic *) + if m.locked then false else begin m.locked <- true; true end + +let unlock m = + (* Don't play with Thread.critical_section here because of Condition.wait *) + let w = m.waiting in (* atomic *) + m.waiting <- []; (* atomic *) + m.locked <- false; (* atomic *) + List.iter Thread.wakeup w + diff --git a/otherlibs/threads/mutex.mli b/otherlibs/threads/mutex.mli new file mode 100644 index 0000000..eb3f802 --- /dev/null +++ b/otherlibs/threads/mutex.mli @@ -0,0 +1,50 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: mutex.mli,v 1.11 2001-12-07 13:40:22 xleroy Exp $ *) + +(** Locks for mutual exclusion. + + Mutexes (mutual-exclusion locks) are used to implement critical sections + and protect shared mutable data structures against concurrent accesses. + The typical use is (if [m] is the mutex associated with the data structure + [D]): + {[ + Mutex.lock m; + (* Critical section that operates over D *); + Mutex.unlock m + ]} +*) + +type t +(** The type of mutexes. *) + +val create : unit -> t +(** Return a new mutex. *) + +val lock : t -> unit +(** Lock the given mutex. Only one thread can have the mutex locked + at any time. A thread that attempts to lock a mutex already locked + by another thread will suspend until the other thread unlocks + the mutex. *) + +val try_lock : t -> bool +(** Same as {!Mutex.lock}, but does not suspend the calling thread if + the mutex is already locked: just return [false] immediately + in that case. If the mutex is unlocked, lock it and + return [true]. *) + +val unlock : t -> unit +(** Unlock the given mutex. Other threads suspended trying to lock + the mutex will restart. *) + diff --git a/otherlibs/threads/pervasives.ml b/otherlibs/threads/pervasives.ml new file mode 100644 index 0000000..7bcdf53 --- /dev/null +++ b/otherlibs/threads/pervasives.ml @@ -0,0 +1,542 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: pervasives.ml,v 1.52 2007-02-25 12:37:30 xleroy Exp $ *) + +(* Same as ../../stdlib/pervasives.ml, except that I/O functions have + been redefined to not block the whole process, but only the calling + thread. *) + +(* type 'a option = None | Some of 'a *) + +(* Exceptions *) + +external raise : exn -> 'a = "%raise" + +let failwith s = raise(Failure s) +let invalid_arg s = raise(Invalid_argument s) + +exception Exit + +(* Comparisons *) + +external (=) : 'a -> 'a -> bool = "%equal" +external (<>) : 'a -> 'a -> bool = "%notequal" +external (<) : 'a -> 'a -> bool = "%lessthan" +external (>) : 'a -> 'a -> bool = "%greaterthan" +external (<=) : 'a -> 'a -> bool = "%lessequal" +external (>=) : 'a -> 'a -> bool = "%greaterequal" +external compare: 'a -> 'a -> int = "%compare" + +let min x y = if x <= y then x else y +let max x y = if x >= y then x else y + +external (==) : 'a -> 'a -> bool = "%eq" +external (!=) : 'a -> 'a -> bool = "%noteq" + +(* Boolean operations *) + +external not : bool -> bool = "%boolnot" +external (&) : bool -> bool -> bool = "%sequand" +external (&&) : bool -> bool -> bool = "%sequand" +external (or) : bool -> bool -> bool = "%sequor" +external (||) : bool -> bool -> bool = "%sequor" + +(* Integer operations *) + +external (~-) : int -> int = "%negint" +external succ : int -> int = "%succint" +external pred : int -> int = "%predint" +external (+) : int -> int -> int = "%addint" +external (-) : int -> int -> int = "%subint" +external ( * ) : int -> int -> int = "%mulint" +external (/) : int -> int -> int = "%divint" +external (mod) : int -> int -> int = "%modint" + +let abs x = if x >= 0 then x else -x + +external (land) : int -> int -> int = "%andint" +external (lor) : int -> int -> int = "%orint" +external (lxor) : int -> int -> int = "%xorint" + +let lnot x = x lxor (-1) + +external (lsl) : int -> int -> int = "%lslint" +external (lsr) : int -> int -> int = "%lsrint" +external (asr) : int -> int -> int = "%asrint" + +let min_int = 1 lsl (if 1 lsl 31 = 0 then 30 else 62) +let max_int = min_int - 1 + +(* Floating-point operations *) + +external (~-.) : float -> float = "%negfloat" +external (+.) : float -> float -> float = "%addfloat" +external (-.) : float -> float -> float = "%subfloat" +external ( *. ) : float -> float -> float = "%mulfloat" +external (/.) : float -> float -> float = "%divfloat" +external ( ** ) : float -> float -> float = "caml_power_float" "pow" "float" +external exp : float -> float = "caml_exp_float" "exp" "float" +external acos : float -> float = "caml_acos_float" "acos" "float" +external asin : float -> float = "caml_asin_float" "asin" "float" +external atan : float -> float = "caml_atan_float" "atan" "float" +external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float" +external cos : float -> float = "caml_cos_float" "cos" "float" +external cosh : float -> float = "caml_cosh_float" "cosh" "float" +external log : float -> float = "caml_log_float" "log" "float" +external log10 : float -> float = "caml_log10_float" "log10" "float" +external sin : float -> float = "caml_sin_float" "sin" "float" +external sinh : float -> float = "caml_sinh_float" "sinh" "float" +external sqrt : float -> float = "caml_sqrt_float" "sqrt" "float" +external tan : float -> float = "caml_tan_float" "tan" "float" +external tanh : float -> float = "caml_tanh_float" "tanh" "float" +external ceil : float -> float = "caml_ceil_float" "ceil" "float" +external floor : float -> float = "caml_floor_float" "floor" "float" +external abs_float : float -> float = "%absfloat" +external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float" +external frexp : float -> float * int = "caml_frexp_float" +external ldexp : float -> int -> float = "caml_ldexp_float" +external modf : float -> float * float = "caml_modf_float" +external float : int -> float = "%floatofint" +external float_of_int : int -> float = "%floatofint" +external truncate : float -> int = "%intoffloat" +external int_of_float : float -> int = "%intoffloat" +external float_of_bits : int64 -> float = "caml_int64_float_of_bits" +let infinity = + float_of_bits 0x7F_F0_00_00_00_00_00_00L +let neg_infinity = + float_of_bits 0xFF_F0_00_00_00_00_00_00L +let nan = + float_of_bits 0x7F_F0_00_00_00_00_00_01L +let max_float = + float_of_bits 0x7F_EF_FF_FF_FF_FF_FF_FFL +let min_float = + float_of_bits 0x00_10_00_00_00_00_00_00L +let epsilon_float = + float_of_bits 0x3C_B0_00_00_00_00_00_00L + +type fpclass = + FP_normal + | FP_subnormal + | FP_zero + | FP_infinite + | FP_nan +external classify_float: float -> fpclass = "caml_classify_float" + +(* String operations -- more in module String *) + +external string_length : string -> int = "%string_length" +external string_create: int -> string = "caml_create_string" +external string_blit : string -> int -> string -> int -> int -> unit + = "caml_blit_string" "noalloc" + +let (^) s1 s2 = + let l1 = string_length s1 and l2 = string_length s2 in + let s = string_create (l1 + l2) in + string_blit s1 0 s 0 l1; + string_blit s2 0 s l1 l2; + s + +(* Character operations -- more in module Char *) + +external int_of_char : char -> int = "%identity" +external unsafe_char_of_int : int -> char = "%identity" +let char_of_int n = + if n < 0 || n > 255 then invalid_arg "char_of_int" else unsafe_char_of_int n + +(* Unit operations *) + +external ignore : 'a -> unit = "%ignore" + +(* Pair operations *) + +external fst : 'a * 'b -> 'a = "%field0" +external snd : 'a * 'b -> 'b = "%field1" + +(* References *) + +type 'a ref = { mutable contents: 'a } +external ref: 'a -> 'a ref = "%makemutable" +external (!): 'a ref -> 'a = "%field0" +external (:=): 'a ref -> 'a -> unit = "%setfield0" +external incr: int ref -> unit = "%incr" +external decr: int ref -> unit = "%decr" + +(* String conversion functions *) + +external format_int: string -> int -> string = "caml_format_int" +external format_float: string -> float -> string = "caml_format_float" + +let string_of_bool b = + if b then "true" else "false" +let bool_of_string = function + | "true" -> true + | "false" -> false + | _ -> invalid_arg "bool_of_string" + +let string_of_int n = + format_int "%d" n + +external int_of_string : string -> int = "caml_int_of_string" + +let valid_float_lexem s = + let l = string_length s in + let rec loop i = + if i >= l then s ^ "." else + match s.[i] with + | '0' .. '9' | '-' -> loop (i+1) + | _ -> s + in + loop 0 +;; + +let string_of_float f = valid_float_lexem (format_float "%.12g" f);; + +external float_of_string : string -> float = "caml_float_of_string" + +(* List operations -- more in module List *) + +let rec (@) l1 l2 = + match l1 with + [] -> l2 + | hd :: tl -> hd :: (tl @ l2) + +(* I/O operations *) + +type in_channel +type out_channel + +external open_descriptor_out: int -> out_channel = "caml_ml_open_descriptor_out" +external open_descriptor_in: int -> in_channel = "caml_ml_open_descriptor_in" + +let stdin = open_descriptor_in 0 +let stdout = open_descriptor_out 1 +let stderr = open_descriptor_out 2 + +(* Non-blocking stuff *) + +external thread_wait_read_prim : Unix.file_descr -> unit = "thread_wait_read" +external thread_wait_write_prim : Unix.file_descr -> unit = "thread_wait_write" + +let thread_wait_read fd = thread_wait_read_prim fd +let thread_wait_write fd = thread_wait_write_prim fd + +external descr_inchan : in_channel -> Unix.file_descr + = "caml_channel_descriptor" +external descr_outchan : out_channel -> Unix.file_descr + = "caml_channel_descriptor" + +let wait_inchan ic = thread_wait_read (descr_inchan ic) + +let wait_outchan oc len = thread_wait_write (descr_outchan oc) + +(* General output functions *) + +type open_flag = + Open_rdonly | Open_wronly | Open_append + | Open_creat | Open_trunc | Open_excl + | Open_binary | Open_text | Open_nonblock + +external open_desc: string -> open_flag list -> int -> int = "caml_sys_open" + +let open_out_gen mode perm name = + open_descriptor_out(open_desc name mode perm) + +let open_out name = + open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_text] 0o666 name + +let open_out_bin name = + open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] 0o666 name + +external flush_partial : out_channel -> bool = "caml_ml_flush_partial" + +let rec flush oc = + let success = + try + flush_partial oc + with Sys_blocked_io -> + wait_outchan oc (-1); false in + if success then () else flush oc + +external out_channels_list : unit -> out_channel list + = "caml_ml_out_channels_list" + +let flush_all () = + let rec iter = function + [] -> () + | a::l -> + begin try + flush a + with Sys_error _ -> + () (* ignore channels closed during a preceding flush. *) + end; + iter l + in iter (out_channels_list ()) + +external unsafe_output_partial : out_channel -> string -> int -> int -> int + = "caml_ml_output_partial" + +let rec unsafe_output oc buf pos len = + if len > 0 then begin + let written = + try + unsafe_output_partial oc buf pos len + with Sys_blocked_io -> + wait_outchan oc len; 0 in + unsafe_output oc buf (pos + written) (len - written) + end + +external output_char_blocking : out_channel -> char -> unit + = "caml_ml_output_char" +external output_byte_blocking : out_channel -> int -> unit + = "caml_ml_output_char" + +let rec output_char oc c = + try + output_char_blocking oc c + with Sys_blocked_io -> + wait_outchan oc 1; output_char oc c + +let output_string oc s = + unsafe_output oc s 0 (string_length s) + +let output oc s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "output" + else unsafe_output oc s ofs len + +let output' oc ~buf ~pos ~len = output oc buf pos len + +let rec output_byte oc b = + try + output_byte_blocking oc b + with Sys_blocked_io -> + wait_outchan oc 1; output_byte oc b + +let output_binary_int oc n = + output_byte oc (n asr 24); + output_byte oc (n asr 16); + output_byte oc (n asr 8); + output_byte oc n + +external marshal_to_string : 'a -> unit list -> string + = "caml_output_value_to_string" + +let output_value oc v = output_string oc (marshal_to_string v []) + +external seek_out_blocking : out_channel -> int -> unit = "caml_ml_seek_out" + +let seek_out oc pos = flush oc; seek_out_blocking oc pos + +external pos_out : out_channel -> int = "caml_ml_pos_out" +external out_channel_length : out_channel -> int = "caml_ml_channel_size" +external close_out_channel : out_channel -> unit = "caml_ml_close_channel" + +let close_out oc = (try flush oc with _ -> ()); close_out_channel oc +let close_out_noerr oc = + (try flush oc with _ -> ()); + (try close_out_channel oc with _ -> ()) +external set_binary_mode_out : out_channel -> bool -> unit + = "caml_ml_set_binary_mode" + +(* General input functions *) + +let open_in_gen mode perm name = + open_descriptor_in(open_desc name mode perm) + +let open_in name = + open_in_gen [Open_rdonly; Open_text] 0 name + +let open_in_bin name = + open_in_gen [Open_rdonly; Open_binary] 0 name + +external input_char_blocking : in_channel -> char = "caml_ml_input_char" +external input_byte_blocking : in_channel -> int = "caml_ml_input_char" + +let rec input_char ic = + try + input_char_blocking ic + with Sys_blocked_io -> + wait_inchan ic; input_char ic + +external unsafe_input_blocking : in_channel -> string -> int -> int -> int + = "caml_ml_input" + +let rec unsafe_input ic s ofs len = + try + unsafe_input_blocking ic s ofs len + with Sys_blocked_io -> + wait_inchan ic; unsafe_input ic s ofs len + +let input ic s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "input" + else unsafe_input ic s ofs len + +let rec unsafe_really_input ic s ofs len = + if len <= 0 then () else begin + let r = unsafe_input ic s ofs len in + if r = 0 + then raise End_of_file + else unsafe_really_input ic s (ofs+r) (len-r) + end + +let really_input ic s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "really_input" + else unsafe_really_input ic s ofs len + +let input_line ic = + let buf = ref (string_create 128) in + let pos = ref 0 in + begin try + while true do + if !pos = string_length !buf then begin + let newbuf = string_create (2 * !pos) in + string_blit !buf 0 newbuf 0 !pos; + buf := newbuf + end; + let c = input_char ic in + if c = '\n' then raise Exit; + !buf.[!pos] <- c; + incr pos + done + with Exit -> () + | End_of_file -> if !pos = 0 then raise End_of_file + end; + let res = string_create !pos in + string_blit !buf 0 res 0 !pos; + res + +let rec input_byte ic = + try + input_byte_blocking ic + with Sys_blocked_io -> + wait_inchan ic; input_byte ic + +let input_binary_int ic = + let b1 = input_byte ic in + let n1 = if b1 >= 128 then b1 - 256 else b1 in + let b2 = input_byte ic in + let b3 = input_byte ic in + let b4 = input_byte ic in + (n1 lsl 24) + (b2 lsl 16) + (b3 lsl 8) + b4 + +external unmarshal : string -> int -> 'a = "caml_input_value_from_string" +external marshal_data_size : string -> int -> int = "caml_marshal_data_size" + +let input_value ic = + let header = string_create 20 in + really_input ic header 0 20; + let bsize = marshal_data_size header 0 in + let buffer = string_create (20 + bsize) in + string_blit header 0 buffer 0 20; + really_input ic buffer 20 bsize; + unmarshal buffer 0 + +external seek_in : in_channel -> int -> unit = "caml_ml_seek_in" +external pos_in : in_channel -> int = "caml_ml_pos_in" +external in_channel_length : in_channel -> int = "caml_ml_channel_size" +external close_in : in_channel -> unit = "caml_ml_close_channel" +let close_in_noerr ic = (try close_in ic with _ -> ());; +external set_binary_mode_in : in_channel -> bool -> unit + = "caml_ml_set_binary_mode" + +(* Output functions on standard output *) + +let print_char c = output_char stdout c +let print_string s = output_string stdout s +let print_int i = output_string stdout (string_of_int i) +let print_float f = output_string stdout (string_of_float f) +let print_endline s = + output_string stdout s; output_char stdout '\n'; flush stdout +let print_newline () = output_char stdout '\n'; flush stdout + +(* Output functions on standard error *) + +let prerr_char c = output_char stderr c +let prerr_string s = output_string stderr s +let prerr_int i = output_string stderr (string_of_int i) +let prerr_float f = output_string stderr (string_of_float f) +let prerr_endline s = + output_string stderr s; output_char stderr '\n'; flush stderr +let prerr_newline () = output_char stderr '\n'; flush stderr + +(* Input functions on standard input *) + +let read_line () = flush stdout; input_line stdin +let read_int () = int_of_string(read_line()) +let read_float () = float_of_string(read_line()) + +(* Operations on large files *) + +module LargeFile = + struct + external seek_out : out_channel -> int64 -> unit = "caml_ml_seek_out_64" + external pos_out : out_channel -> int64 = "caml_ml_pos_out_64" + external out_channel_length : out_channel -> int64 + = "caml_ml_channel_size_64" + external seek_in : in_channel -> int64 -> unit = "caml_ml_seek_in_64" + external pos_in : in_channel -> int64 = "caml_ml_pos_in_64" + external in_channel_length : in_channel -> int64 = "caml_ml_channel_size_64" + end + +(* Formats *) +type ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'c, 'c, 'd) format6 + +type ('a, 'b, 'c) format = ('a, 'b, 'c, 'c) format4 + +external format_of_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" + +external format_to_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string = "%identity" +external string_to_format : + string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" + +let (( ^^ ) : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('f, 'b, 'c, 'e, 'g, 'h) format6 -> + ('a, 'b, 'c, 'd, 'g, 'h) format6) = + fun fmt1 fmt2 -> + string_to_format (format_to_string fmt1 ^ format_to_string fmt2);; + +let string_of_format fmt = + let s = format_to_string fmt in + let l = string_length s in + let r = string_create l in + string_blit s 0 r 0 l; + r + + +(* Miscellaneous *) + +external sys_exit : int -> 'a = "caml_sys_exit" + +let exit_function = ref flush_all + +let at_exit f = + let g = !exit_function in + exit_function := (fun () -> f(); g()) + +let do_at_exit () = (!exit_function) () + +let exit retcode = + do_at_exit (); + sys_exit retcode + +external register_named_value : string -> 'a -> unit + = "caml_register_named_value" + +let _ = register_named_value "Pervasives.do_at_exit" do_at_exit diff --git a/otherlibs/threads/scheduler.c b/otherlibs/threads/scheduler.c new file mode 100644 index 0000000..9cefb28 --- /dev/null +++ b/otherlibs/threads/scheduler.c @@ -0,0 +1,876 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: scheduler.c,v 1.60 2005-09-22 14:21:50 xleroy Exp $ */ + +/* The thread scheduler */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include "alloc.h" +#include "backtrace.h" +#include "callback.h" +#include "config.h" +#include "fail.h" +#include "io.h" +#include "memory.h" +#include "misc.h" +#include "mlvalues.h" +#include "printexc.h" +#include "roots.h" +#include "signals.h" +#include "stacks.h" +#include "sys.h" + +#if ! (defined(HAS_SELECT) && \ + defined(HAS_SETITIMER) && \ + defined(HAS_GETTIMEOFDAY) && \ + (defined(HAS_WAITPID) || defined(HAS_WAIT4))) +#include "Cannot compile libthreads, system calls missing" +#endif + +#include <errno.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <sys/stat.h> +#include <fcntl.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#ifdef HAS_SYS_SELECT_H +#include <sys/select.h> +#endif + +#ifndef HAS_WAITPID +#define waitpid(pid,status,opts) wait4(pid,status,opts,NULL) +#endif + +#ifndef O_NONBLOCK +#define O_NONBLOCK O_NDELAY +#endif + +/* Configuration */ + +/* Initial size of stack when a thread is created (4kB) */ +#define Thread_stack_size (Stack_size / 4) + +/* Max computation time before rescheduling, in microseconds (50ms) */ +#define Thread_timeout 50000 + +/* The thread descriptors */ + +struct caml_thread_struct { + value ident; /* Unique id (for equality comparisons) */ + struct caml_thread_struct * next; /* Double linking of threads */ + struct caml_thread_struct * prev; + value * stack_low; /* The execution stack for this thread */ + value * stack_high; + value * stack_threshold; + value * sp; + value * trapsp; + value backtrace_pos; /* The backtrace info for this thread */ + code_t * backtrace_buffer; + value backtrace_last_exn; + value status; /* RUNNABLE, KILLED. etc (see below) */ + value fd; /* File descriptor on which we're doing read or write */ + value readfds, writefds, exceptfds; + /* Lists of file descriptors on which we're doing select() */ + value delay; /* Time until which this thread is blocked */ + value joining; /* Thread we're trying to join */ + value waitpid; /* PID of process we're waiting for */ + value retval; /* Value to return when thread resumes */ +}; + +typedef struct caml_thread_struct * caml_thread_t; + +#define RUNNABLE Val_int(0) +#define KILLED Val_int(1) +#define SUSPENDED Val_int(2) +#define BLOCKED_READ Val_int(4) +#define BLOCKED_WRITE Val_int(8) +#define BLOCKED_SELECT Val_int(16) +#define BLOCKED_DELAY Val_int(32) +#define BLOCKED_JOIN Val_int(64) +#define BLOCKED_WAIT Val_int(128) + +#define RESUMED_WAKEUP Val_int(0) +#define RESUMED_DELAY Val_int(1) +#define RESUMED_JOIN Val_int(2) +#define RESUMED_IO Val_int(3) + +#define TAG_RESUMED_SELECT 0 +#define TAG_RESUMED_WAIT 1 + +#define NO_FDS Val_unit +#define NO_DELAY Val_unit +#define NO_JOINING Val_unit +#define NO_WAITPID Val_int(0) + +#define DELAY_INFTY 1E30 /* +infty, for this purpose */ + +/* The thread currently active */ +static caml_thread_t curr_thread = NULL; +/* Identifier for next thread creation */ +static value next_ident = Val_int(0); + +#define Assign(dst,src) modify((value *)&(dst), (value)(src)) + +/* Scan the stacks of the other threads */ + +static void (*prev_scan_roots_hook) (scanning_action); + +static void thread_scan_roots(scanning_action action) +{ + caml_thread_t th, start; + + /* Scan all active descriptors */ + start = curr_thread; + (*action)((value) curr_thread, (value *) &curr_thread); + /* Don't scan curr_thread->sp, this has already been done. + Don't scan local roots either, for the same reason. */ + for (th = start->next; th != start; th = th->next) { + do_local_roots(action, th->sp, th->stack_high, NULL); + } + /* Hook */ + if (prev_scan_roots_hook != NULL) (*prev_scan_roots_hook)(action); +} + +/* Forward declarations for async I/O handling */ + +static int stdin_initial_status, stdout_initial_status, stderr_initial_status; +static void thread_restore_std_descr(void); + +/* Initialize the thread machinery */ + +value thread_initialize(value unit) /* ML */ +{ + /* Protect against repeated initialization (PR#1325) */ + if (curr_thread != NULL) return Val_unit; + /* Create a descriptor for the current thread */ + curr_thread = + (caml_thread_t) alloc_shr(sizeof(struct caml_thread_struct) + / sizeof(value), 0); + curr_thread->ident = next_ident; + next_ident = Val_int(Int_val(next_ident) + 1); + curr_thread->next = curr_thread; + curr_thread->prev = curr_thread; + curr_thread->stack_low = stack_low; + curr_thread->stack_high = stack_high; + curr_thread->stack_threshold = stack_threshold; + curr_thread->sp = extern_sp; + curr_thread->trapsp = trapsp; + curr_thread->backtrace_pos = Val_int(backtrace_pos); + curr_thread->backtrace_buffer = backtrace_buffer; + caml_initialize (&curr_thread->backtrace_last_exn, backtrace_last_exn); + curr_thread->status = RUNNABLE; + curr_thread->fd = Val_int(0); + curr_thread->readfds = NO_FDS; + curr_thread->writefds = NO_FDS; + curr_thread->exceptfds = NO_FDS; + curr_thread->delay = NO_DELAY; + curr_thread->joining = NO_JOINING; + curr_thread->waitpid = NO_WAITPID; + curr_thread->retval = Val_unit; + /* Initialize GC */ + prev_scan_roots_hook = scan_roots_hook; + scan_roots_hook = thread_scan_roots; + /* Set standard file descriptors to non-blocking mode */ + stdin_initial_status = fcntl(0, F_GETFL); + stdout_initial_status = fcntl(1, F_GETFL); + stderr_initial_status = fcntl(2, F_GETFL); + if (stdin_initial_status != -1) + fcntl(0, F_SETFL, stdin_initial_status | O_NONBLOCK); + if (stdout_initial_status != -1) + fcntl(1, F_SETFL, stdout_initial_status | O_NONBLOCK); + if (stderr_initial_status != -1) + fcntl(2, F_SETFL, stderr_initial_status | O_NONBLOCK); + /* Register an at-exit function to restore the standard file descriptors */ + atexit(thread_restore_std_descr); + return Val_unit; +} + +/* Initialize the interval timer used for preemption */ + +value thread_initialize_preemption(value unit) /* ML */ +{ + struct itimerval timer; + + timer.it_interval.tv_sec = 0; + timer.it_interval.tv_usec = Thread_timeout; + timer.it_value = timer.it_interval; + setitimer(ITIMER_VIRTUAL, &timer, NULL); + return Val_unit; +} + +/* Create a thread */ + +value thread_new(value clos) /* ML */ +{ + caml_thread_t th; + /* Allocate the thread and its stack */ + Begin_root(clos); + th = (caml_thread_t) alloc_shr(sizeof(struct caml_thread_struct) + / sizeof(value), 0); + End_roots(); + th->ident = next_ident; + next_ident = Val_int(Int_val(next_ident) + 1); + th->stack_low = (value *) stat_alloc(Thread_stack_size); + th->stack_high = th->stack_low + Thread_stack_size / sizeof(value); + th->stack_threshold = th->stack_low + Stack_threshold / sizeof(value); + th->sp = th->stack_high; + th->trapsp = th->stack_high; + /* Set up a return frame that pretends we're applying the function to (). + This way, the next RETURN instruction will run the function. */ + th->sp -= 5; + th->sp[0] = Val_unit; /* dummy local to be popped by RETURN 1 */ + th->sp[1] = (value) Code_val(clos); + th->sp[2] = clos; + th->sp[3] = Val_long(0); /* no extra args */ + th->sp[4] = Val_unit; /* the () argument */ + /* Fake a C call frame */ + th->sp--; + th->sp[0] = Val_unit; /* a dummy environment */ + /* Finish initialization of th */ + th->backtrace_pos = Val_int(0); + th->backtrace_buffer = NULL; + th->backtrace_last_exn = Val_unit; + /* The thread is initially runnable */ + th->status = RUNNABLE; + th->fd = Val_int(0); + th->readfds = NO_FDS; + th->writefds = NO_FDS; + th->exceptfds = NO_FDS; + th->delay = NO_DELAY; + th->joining = NO_JOINING; + th->waitpid = NO_WAITPID; + th->retval = Val_unit; + /* Insert thread in doubly linked list of threads */ + th->prev = curr_thread->prev; + th->next = curr_thread; + Assign(curr_thread->prev->next, th); + Assign(curr_thread->prev, th); + /* Return thread */ + return (value) th; +} + +/* Return the thread identifier */ + +value thread_id(value th) /* ML */ +{ + return ((caml_thread_t)th)->ident; +} + +/* Return the current time as a floating-point number */ + +static double timeofday(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (double) tv.tv_sec + (double) tv.tv_usec * 1e-6; +} + +/* Find a runnable thread and activate it */ + +#define FOREACH_THREAD(x) x = curr_thread; do { x = x->next; +#define END_FOREACH(x) } while (x != curr_thread) + +static value alloc_process_status(int pid, int status); +static void add_fdlist_to_set(value fdl, fd_set *set); +static value inter_fdlist_set(value fdl, fd_set *set, int *count); +static void find_bad_fd(int fd, fd_set *set); +static void find_bad_fds(value fdl, fd_set *set); + +static value schedule_thread(void) +{ + caml_thread_t run_thread, th; + fd_set readfds, writefds, exceptfds; + double delay, now; + int need_select, need_wait; + + /* Don't allow preemption during a callback */ + if (callback_depth > 1) return curr_thread->retval; + + /* Save the status of the current thread */ + curr_thread->stack_low = stack_low; + curr_thread->stack_high = stack_high; + curr_thread->stack_threshold = stack_threshold; + curr_thread->sp = extern_sp; + curr_thread->trapsp = trapsp; + curr_thread->backtrace_pos = Val_int(backtrace_pos); + curr_thread->backtrace_buffer = backtrace_buffer; + caml_modify (&curr_thread->backtrace_last_exn, backtrace_last_exn); + +try_again: + /* Find if a thread is runnable. + Build fdsets and delay for select. + See if some join or wait operations succeeded. */ + run_thread = NULL; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + delay = DELAY_INFTY; + now = -1.0; + need_select = 0; + need_wait = 0; + + FOREACH_THREAD(th) + if (th->status <= SUSPENDED) continue; + + if (th->status & (BLOCKED_READ - 1)) { + FD_SET(Int_val(th->fd), &readfds); + need_select = 1; + } + if (th->status & (BLOCKED_WRITE - 1)) { + FD_SET(Int_val(th->fd), &writefds); + need_select = 1; + } + if (th->status & (BLOCKED_SELECT - 1)) { + add_fdlist_to_set(th->readfds, &readfds); + add_fdlist_to_set(th->writefds, &writefds); + add_fdlist_to_set(th->exceptfds, &exceptfds); + need_select = 1; + } + if (th->status & (BLOCKED_DELAY - 1)) { + double th_delay; + if (now < 0.0) now = timeofday(); + th_delay = Double_val(th->delay) - now; + if (th_delay <= 0) { + th->status = RUNNABLE; + Assign(th->retval,RESUMED_DELAY); + } else { + if (th_delay < delay) delay = th_delay; + } + } + if (th->status & (BLOCKED_JOIN - 1)) { + if (((caml_thread_t)(th->joining))->status == KILLED) { + th->status = RUNNABLE; + Assign(th->retval, RESUMED_JOIN); + } + } + if (th->status & (BLOCKED_WAIT - 1)) { + int status, pid; + pid = waitpid(Int_val(th->waitpid), &status, WNOHANG); + if (pid > 0) { + th->status = RUNNABLE; + Assign(th->retval, alloc_process_status(pid, status)); + } else { + need_wait = 1; + } + } + END_FOREACH(th); + + /* Find if a thread is runnable. */ + run_thread = NULL; + FOREACH_THREAD(th) + if (th->status == RUNNABLE) { run_thread = th; break; } + END_FOREACH(th); + + /* Do the select if needed */ + if (need_select || run_thread == NULL) { + struct timeval delay_tv, * delay_ptr; + int retcode; + /* If a thread is blocked on wait, don't block forever */ + if (need_wait && delay > Thread_timeout * 1e-6) { + delay = Thread_timeout * 1e-6; + } + /* Convert delay to a timeval */ + /* If a thread is runnable, just poll */ + if (run_thread != NULL) { + delay_tv.tv_sec = 0; + delay_tv.tv_usec = 0; + delay_ptr = &delay_tv; + } + else if (delay != DELAY_INFTY) { + delay_tv.tv_sec = (unsigned int) delay; + delay_tv.tv_usec = (delay - (double) delay_tv.tv_sec) * 1E6; + delay_ptr = &delay_tv; + } + else { + delay_ptr = NULL; + } + enter_blocking_section(); + retcode = select(FD_SETSIZE, &readfds, &writefds, &exceptfds, delay_ptr); + leave_blocking_section(); + if (retcode == -1) + switch (errno) { + case EINTR: + break; + case EBADF: + /* One of the descriptors in the sets was closed or is bad. + Find it using fstat() and wake up the threads waiting on it + so that they'll get an error when operating on it. */ + FOREACH_THREAD(th) + if (th->status & (BLOCKED_READ - 1)) { + find_bad_fd(Int_val(th->fd), &readfds); + } + if (th->status & (BLOCKED_WRITE - 1)) { + find_bad_fd(Int_val(th->fd), &writefds); + } + if (th->status & (BLOCKED_SELECT - 1)) { + find_bad_fds(th->readfds, &readfds); + find_bad_fds(th->writefds, &writefds); + find_bad_fds(th->exceptfds, &exceptfds); + } + END_FOREACH(th); + retcode = FD_SETSIZE; + break; + default: + sys_error(NO_ARG); + } + if (retcode > 0) { + /* Some descriptors are ready. + Mark the corresponding threads runnable. */ + FOREACH_THREAD(th) + if (retcode <= 0) break; + if ((th->status & (BLOCKED_READ - 1)) && + FD_ISSET(Int_val(th->fd), &readfds)) { + Assign(th->retval, RESUMED_IO); + th->status = RUNNABLE; + if (run_thread == NULL) run_thread = th; /* Found one. */ + /* Wake up only one thread per fd */ + FD_CLR(Int_val(th->fd), &readfds); + retcode--; + } + if ((th->status & (BLOCKED_WRITE - 1)) && + FD_ISSET(Int_val(th->fd), &writefds)) { + Assign(th->retval, RESUMED_IO); + th->status = RUNNABLE; + if (run_thread == NULL) run_thread = th; /* Found one. */ + /* Wake up only one thread per fd */ + FD_CLR(Int_val(th->fd), &readfds); + retcode--; + } + if (th->status & (BLOCKED_SELECT - 1)) { + value r = Val_unit, w = Val_unit, e = Val_unit; + Begin_roots3(r,w,e) + r = inter_fdlist_set(th->readfds, &readfds, &retcode); + w = inter_fdlist_set(th->writefds, &writefds, &retcode); + e = inter_fdlist_set(th->exceptfds, &exceptfds, &retcode); + if (r != NO_FDS || w != NO_FDS || e != NO_FDS) { + value retval = alloc_small(3, TAG_RESUMED_SELECT); + Field(retval, 0) = r; + Field(retval, 1) = w; + Field(retval, 2) = e; + Assign(th->retval, retval); + th->status = RUNNABLE; + if (run_thread == NULL) run_thread = th; /* Found one. */ + } + End_roots(); + } + END_FOREACH(th); + } + /* If we get here with run_thread still NULL, one of the following + may have happened: + - a delay has expired + - a wait() needs to be polled again + - the select() failed (e.g. was interrupted) + In these cases, we go through the loop once more to make the + corresponding threads runnable. */ + if (run_thread == NULL && + (delay != DELAY_INFTY || need_wait || retcode == -1)) + goto try_again; + } + + /* If we haven't something to run at that point, we're in big trouble. */ + if (run_thread == NULL) invalid_argument("Thread: deadlock"); + + /* Free everything the thread was waiting on */ + Assign(run_thread->readfds, NO_FDS); + Assign(run_thread->writefds, NO_FDS); + Assign(run_thread->exceptfds, NO_FDS); + Assign(run_thread->delay, NO_DELAY); + Assign(run_thread->joining, NO_JOINING); + run_thread->waitpid = NO_WAITPID; + + /* Activate the thread */ + curr_thread = run_thread; + stack_low = curr_thread->stack_low; + stack_high = curr_thread->stack_high; + stack_threshold = curr_thread->stack_threshold; + extern_sp = curr_thread->sp; + trapsp = curr_thread->trapsp; + backtrace_pos = Int_val(curr_thread->backtrace_pos); + backtrace_buffer = curr_thread->backtrace_buffer; + backtrace_last_exn = curr_thread->backtrace_last_exn; + return curr_thread->retval; +} + +/* Since context switching is not allowed in callbacks, a thread that + blocks during a callback is a deadlock. */ + +static void check_callback(void) +{ + if (callback_depth > 1) + caml_fatal_error("Thread: deadlock during callback"); +} + +/* Reschedule without suspending the current thread */ + +value thread_yield(value unit) /* ML */ +{ + Assert(curr_thread != NULL); + Assign(curr_thread->retval, Val_unit); + return schedule_thread(); +} + +/* Honor an asynchronous request for re-scheduling */ + +static void thread_reschedule(void) +{ + value accu; + + Assert(curr_thread != NULL); + /* Pop accu from event frame, making it look like a C_CALL frame + followed by a RETURN frame */ + accu = *extern_sp++; + /* Reschedule */ + Assign(curr_thread->retval, accu); + accu = schedule_thread(); + /* Push accu below C_CALL frame so that it looks like an event frame */ + *--extern_sp = accu; +} + +/* Request a re-scheduling as soon as possible */ + +value thread_request_reschedule(value unit) /* ML */ +{ + async_action_hook = thread_reschedule; + something_to_do = 1; + return Val_unit; +} + +/* Suspend the current thread */ + +value thread_sleep(value unit) /* ML */ +{ + Assert(curr_thread != NULL); + check_callback(); + curr_thread->status = SUSPENDED; + return schedule_thread(); +} + +/* Suspend the current thread on a read() or write() request */ + +static value thread_wait_rw(int kind, value fd) +{ + /* Don't do an error if we're not initialized yet + (we can be called from thread-safe Pervasives before initialization), + just return immediately. */ + if (curr_thread == NULL) return RESUMED_WAKEUP; + /* As a special case, if we're in a callback, don't fail but block + the whole process till I/O is possible */ + if (callback_depth > 1) { + fd_set fds; + FD_ZERO(&fds); + FD_SET(Int_val(fd), &fds); + switch(kind) { + case BLOCKED_READ: select(FD_SETSIZE, &fds, NULL, NULL, NULL); break; + case BLOCKED_WRITE: select(FD_SETSIZE, NULL, &fds, NULL, NULL); break; + } + return RESUMED_IO; + } else { + curr_thread->fd = fd; + curr_thread->status = kind; + return schedule_thread(); + } +} + +value thread_wait_read(value fd) +{ + return thread_wait_rw(BLOCKED_READ, fd); +} + +value thread_wait_write(value fd) +{ + return thread_wait_rw(BLOCKED_WRITE, fd); +} + +/* Suspend the current thread on a read() or write() request with timeout */ + +static value thread_wait_timed_rw(int kind, value arg) +{ + double date; + + check_callback(); + curr_thread->fd = Field(arg, 0); + date = timeofday() + Double_val(Field(arg, 1)); + Assign(curr_thread->delay, copy_double(date)); + curr_thread->status = kind | BLOCKED_DELAY; + return schedule_thread(); +} + +value thread_wait_timed_read(value arg) +{ + return thread_wait_timed_rw(BLOCKED_READ, arg); +} + +value thread_wait_timed_write(value arg) +{ + return thread_wait_timed_rw(BLOCKED_WRITE, arg); +} + +/* Suspend the current thread on a select() request */ + +value thread_select(value arg) /* ML */ +{ + double date; + check_callback(); + Assign(curr_thread->readfds, Field(arg, 0)); + Assign(curr_thread->writefds, Field(arg, 1)); + Assign(curr_thread->exceptfds, Field(arg, 2)); + date = Double_val(Field(arg, 3)); + if (date >= 0.0) { + date += timeofday(); + Assign(curr_thread->delay, copy_double(date)); + curr_thread->status = BLOCKED_SELECT | BLOCKED_DELAY; + } else { + curr_thread->status = BLOCKED_SELECT; + } + return schedule_thread(); +} + +/* Primitives to implement suspension on buffered channels */ + +value thread_inchan_ready(value vchan) /* ML */ +{ + struct channel * chan = Channel(vchan); + return Val_bool(chan->curr < chan->max); +} + +value thread_outchan_ready(value vchan, value vsize) /* ML */ +{ + struct channel * chan = Channel(vchan); + intnat size = Long_val(vsize); + /* Negative size means we want to flush the buffer entirely */ + if (size < 0) { + return Val_bool(chan->curr == chan->buff); + } else { + int free = chan->end - chan->curr; + if (chan->curr == chan->buff) + return Val_bool(size < free); + else + return Val_bool(size <= free); + } +} + +/* Suspend the current thread for some time */ + +value thread_delay(value time) /* ML */ +{ + double date = timeofday() + Double_val(time); + Assert(curr_thread != NULL); + check_callback(); + curr_thread->status = BLOCKED_DELAY; + Assign(curr_thread->delay, copy_double(date)); + return schedule_thread(); +} + +/* Suspend the current thread until another thread terminates */ + +value thread_join(value th) /* ML */ +{ + check_callback(); + Assert(curr_thread != NULL); + if (((caml_thread_t)th)->status == KILLED) return Val_unit; + curr_thread->status = BLOCKED_JOIN; + Assign(curr_thread->joining, th); + return schedule_thread(); +} + +/* Suspend the current thread until a Unix process exits */ + +value thread_wait_pid(value pid) /* ML */ +{ + Assert(curr_thread != NULL); + check_callback(); + curr_thread->status = BLOCKED_WAIT; + curr_thread->waitpid = pid; + return schedule_thread(); +} + +/* Reactivate another thread */ + +value thread_wakeup(value thread) /* ML */ +{ + caml_thread_t th = (caml_thread_t) thread; + switch (th->status) { + case SUSPENDED: + th->status = RUNNABLE; + Assign(th->retval, RESUMED_WAKEUP); + break; + case KILLED: + failwith("Thread.wakeup: killed thread"); + default: + failwith("Thread.wakeup: thread not suspended"); + } + return Val_unit; +} + +/* Return the current thread */ + +value thread_self(value unit) /* ML */ +{ + Assert(curr_thread != NULL); + return (value) curr_thread; +} + +/* Kill a thread */ + +value thread_kill(value thread) /* ML */ +{ + value retval = Val_unit; + caml_thread_t th = (caml_thread_t) thread; + if (th->status == KILLED) failwith("Thread.kill: killed thread"); + /* Don't paint ourselves in a corner */ + if (th == th->next) failwith("Thread.kill: cannot kill the last thread"); + /* This thread is no longer waiting on anything */ + th->status = KILLED; + /* If this is the current thread, activate another one */ + if (th == curr_thread) { + Begin_root(thread); + retval = schedule_thread(); + th = (caml_thread_t) thread; + End_roots(); + } + /* Remove thread from the doubly-linked list */ + Assign(th->prev->next, th->next); + Assign(th->next->prev, th->prev); + /* Free its resources */ + stat_free((char *) th->stack_low); + th->stack_low = NULL; + th->stack_high = NULL; + th->stack_threshold = NULL; + th->sp = NULL; + th->trapsp = NULL; + if (th->backtrace_buffer != NULL) { + free(th->backtrace_buffer); + th->backtrace_buffer = NULL; + } + return retval; +} + +/* Print uncaught exception and backtrace */ + +value thread_uncaught_exception(value exn) /* ML */ +{ + char * msg = format_caml_exception(exn); + fprintf(stderr, "Thread %d killed on uncaught exception %s\n", + Int_val(curr_thread->ident), msg); + free(msg); + if (backtrace_active) print_exception_backtrace(); + fflush(stderr); + return Val_unit; +} + +/* Set a list of file descriptors in a fdset */ + +static void add_fdlist_to_set(value fdl, fd_set *set) +{ + for (/*nothing*/; fdl != NO_FDS; fdl = Field(fdl, 1)) { + int fd = Int_val(Field(fdl, 0)); + /* Ignore funky file descriptors, which can cause crashes */ + if (fd >= 0 && fd < FD_SETSIZE) FD_SET(fd, set); + } +} + +/* Build the intersection of a list and a fdset (the list of file descriptors + which are both in the list and in the fdset). */ + +static value inter_fdlist_set(value fdl, fd_set *set, int *count) +{ + value res = Val_unit; + value cons; + + Begin_roots2(fdl, res); + for (res = NO_FDS; fdl != NO_FDS; fdl = Field(fdl, 1)) { + int fd = Int_val(Field(fdl, 0)); + if (FD_ISSET(fd, set)) { + cons = alloc_small(2, 0); + Field(cons, 0) = Val_int(fd); + Field(cons, 1) = res; + res = cons; + FD_CLR(fd, set); /* wake up only one thread per fd ready */ + (*count)--; + } + } + End_roots(); + return res; +} + +/* Find closed file descriptors in a waiting list and set them to 1 in + the given fdset */ + +static void find_bad_fd(int fd, fd_set *set) +{ + struct stat s; + if (fd >= 0 && fd < FD_SETSIZE && fstat(fd, &s) == -1 && errno == EBADF) + FD_SET(fd, set); +} + +static void find_bad_fds(value fdl, fd_set *set) +{ + for (/*nothing*/; fdl != NO_FDS; fdl = Field(fdl, 1)) + find_bad_fd(Int_val(Field(fdl, 0)), set); +} + +/* Auxiliary function for allocating the result of a waitpid() call */ + +#if !(defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSTOPPED) && \ + defined(WSTOPSIG) && defined(WTERMSIG)) +/* Assume old-style V7 status word */ +#define WIFEXITED(status) (((status) & 0xFF) == 0) +#define WEXITSTATUS(status) (((status) >> 8) & 0xFF) +#define WIFSTOPPED(status) (((status) & 0xFF) == 0xFF) +#define WSTOPSIG(status) (((status) >> 8) & 0xFF) +#define WTERMSIG(status) ((status) & 0x3F) +#endif + +#define TAG_WEXITED 0 +#define TAG_WSIGNALED 1 +#define TAG_WSTOPPED 2 + +static value alloc_process_status(int pid, int status) +{ + value st, res; + + if (WIFEXITED(status)) { + st = alloc_small(1, TAG_WEXITED); + Field(st, 0) = Val_int(WEXITSTATUS(status)); + } + else if (WIFSTOPPED(status)) { + st = alloc_small(1, TAG_WSTOPPED); + Field(st, 0) = Val_int(WSTOPSIG(status)); + } + else { + st = alloc_small(1, TAG_WSIGNALED); + Field(st, 0) = Val_int(WTERMSIG(status)); + } + Begin_root(st); + res = alloc_small(2, TAG_RESUMED_WAIT); + Field(res, 0) = Val_int(pid); + Field(res, 1) = st; + End_roots(); + return res; +} + +/* Restore the standard file descriptors to their initial state */ + +static void thread_restore_std_descr(void) +{ + if (stdin_initial_status != -1) fcntl(0, F_SETFL, stdin_initial_status); + if (stdout_initial_status != -1) fcntl(1, F_SETFL, stdout_initial_status); + if (stderr_initial_status != -1) fcntl(2, F_SETFL, stderr_initial_status); +} diff --git a/otherlibs/threads/thread.ml b/otherlibs/threads/thread.ml new file mode 100644 index 0000000..78f8ef1 --- /dev/null +++ b/otherlibs/threads/thread.ml @@ -0,0 +1,141 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: thread.ml,v 1.23 2003-03-20 16:23:04 xleroy Exp $ *) + +(* User-level threads *) + +type t + +let critical_section = ref false + +type resumption_status = + Resumed_wakeup + | Resumed_delay + | Resumed_join + | Resumed_io + | Resumed_select of + Unix.file_descr list * Unix.file_descr list * Unix.file_descr list + | Resumed_wait of int * Unix.process_status + +(* It is mucho important that the primitives that reschedule are called + through an ML function call, not directly. That's because when such a + primitive returns, the bytecode interpreter is only semi-obedient: + it takes sp from the new thread, but keeps pc from the old thread. + But that's OK if all calls to rescheduling primitives are immediately + followed by a RETURN operation, which will restore the correct pc + from the stack. Furthermore, the RETURNs must all have the same + frame size, which means that both the primitives and their ML wrappers + must take exactly one argument. *) + +external thread_initialize : unit -> unit = "thread_initialize" +external thread_initialize_preemption : unit -> unit = "thread_initialize_preemption" +external thread_new : (unit -> unit) -> t = "thread_new" +external thread_yield : unit -> unit = "thread_yield" +external thread_request_reschedule : unit -> unit = "thread_request_reschedule" +external thread_sleep : unit -> unit = "thread_sleep" +external thread_wait_read : Unix.file_descr -> unit = "thread_wait_read" +external thread_wait_write : Unix.file_descr -> unit = "thread_wait_write" +external thread_wait_timed_read : + Unix.file_descr * float -> resumption_status (* remember: 1 arg *) + = "thread_wait_timed_read" +external thread_wait_timed_write : + Unix.file_descr * float -> resumption_status (* remember: 1 arg *) + = "thread_wait_timed_write" +external thread_select : + Unix.file_descr list * Unix.file_descr list * (* remember: 1 arg *) + Unix.file_descr list * float -> resumption_status + = "thread_select" +external thread_join : t -> unit = "thread_join" +external thread_delay : float -> unit = "thread_delay" +external thread_wait_pid : int -> resumption_status = "thread_wait_pid" +external thread_wakeup : t -> unit = "thread_wakeup" +external thread_self : unit -> t = "thread_self" +external thread_kill : t -> unit = "thread_kill" +external thread_uncaught_exception : exn -> unit = "thread_uncaught_exception" + +external id : t -> int = "thread_id" + +(* In sleep() below, we rely on the fact that signals are detected + only at function applications and beginning of loops, + making all other operations atomic. *) + +let yield () = thread_yield() +let sleep () = critical_section := false; thread_sleep() +let delay duration = thread_delay duration +let join th = thread_join th +let wakeup pid = thread_wakeup pid +let self () = thread_self() +let kill pid = thread_kill pid +let exit () = thread_kill(thread_self()) + +let select_aux arg = thread_select arg + +let select readfds writefds exceptfds delay = + match select_aux (readfds, writefds, exceptfds, delay) with + Resumed_select(r, w, e) -> (r, w, e) + | _ -> ([], [], []) + +let wait_read fd = thread_wait_read fd +let wait_write fd = thread_wait_write fd + +let wait_timed_read_aux arg = thread_wait_timed_read arg +let wait_timed_write_aux arg = thread_wait_timed_write arg + +let wait_timed_read fd delay = + match wait_timed_read_aux (fd, delay) with Resumed_io -> true | _ -> false + +let wait_timed_write fd delay = + match wait_timed_write_aux (fd, delay) with Resumed_io -> true | _ -> false + +let wait_pid_aux pid = thread_wait_pid pid + +let wait_pid pid = + match wait_pid_aux pid with + Resumed_wait(pid, status) -> (pid, status) + | _ -> invalid_arg "Thread.wait_pid" + +let wait_signal sigs = + let gotsig = ref 0 in + let self = thread_self() in + let sighandler s = gotsig := s; wakeup self in + let oldhdlrs = + List.map (fun s -> Sys.signal s (Sys.Signal_handle sighandler)) sigs in + if !gotsig = 0 then sleep(); + List.iter2 Sys.set_signal sigs oldhdlrs; + !gotsig + +(* For Thread.create, make sure the function passed to thread_new + always terminates by calling Thread.exit. *) + +let create fn arg = + thread_new + (fun () -> + try + fn arg; exit() + with x -> + flush stdout; flush stderr; + thread_uncaught_exception x; + exit()) + +(* Preemption *) + +let preempt signal = + if !critical_section then () else thread_request_reschedule() + +(* Initialization of the scheduler *) + +let _ = + thread_initialize(); + Sys.set_signal Sys.sigvtalrm (Sys.Signal_handle preempt); + thread_initialize_preemption() diff --git a/otherlibs/threads/thread.mli b/otherlibs/threads/thread.mli new file mode 100644 index 0000000..c9e3f40 --- /dev/null +++ b/otherlibs/threads/thread.mli @@ -0,0 +1,141 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: thread.mli,v 1.28 2004-07-13 12:25:13 xleroy Exp $ *) + +(** Lightweight threads. *) + +type t +(** The type of thread handles. *) + + +(** {6 Thread creation and termination} *) + +val create : ('a -> 'b) -> 'a -> t +(** [Thread.create funct arg] creates a new thread of control, + in which the function application [funct arg] + is executed concurrently with the other threads of the program. + The application of [Thread.create] + returns the handle of the newly created thread. + The new thread terminates when the application [funct arg] + returns, either normally or by raising an uncaught exception. + In the latter case, the exception is printed on standard error, + but not propagated back to the parent thread. Similarly, the + result of the application [funct arg] is discarded and not + directly accessible to the parent thread. *) + +val self : unit -> t +(** Return the thread currently executing. *) + +external id : t -> int = "thread_id" +(** Return the identifier of the given thread. A thread identifier + is an integer that identifies uniquely the thread. + It can be used to build data structures indexed by threads. *) + +val exit : unit -> unit +(** Terminate prematurely the currently executing thread. *) + +val kill : t -> unit +(** Terminate prematurely the thread whose handle is given. + This functionality is available only with bytecode-level threads. *) + +(** {6 Suspending threads} *) + +val delay : float -> unit +(** [delay d] suspends the execution of the calling thread for + [d] seconds. The other program threads continue to run during + this time. *) + +val join : t -> unit +(** [join th] suspends the execution of the calling thread + until the thread [th] has terminated. *) + +val wait_read : Unix.file_descr -> unit +(** See {!Thread.wait_write}.*) + +val wait_write : Unix.file_descr -> unit +(** Suspend the execution of the calling thread until at least + one character is available for reading ({!Thread.wait_read}) or + one character can be written without blocking ([wait_write]) + on the given Unix file descriptor. *) + +val wait_timed_read : Unix.file_descr -> float -> bool +(** See {!Thread.wait_timed_write}.*) + +val wait_timed_write : Unix.file_descr -> float -> bool +(** Same as {!Thread.wait_read} and {!Thread.wait_write}, but wait for at most + the amount of time given as second argument (in seconds). + Return [true] if the file descriptor is ready for input/output + and [false] if the timeout expired. *) + +val select : + Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> + float -> + Unix.file_descr list * Unix.file_descr list * Unix.file_descr list +(** Suspend the execution of the calling thead until input/output + becomes possible on the given Unix file descriptors. + The arguments and results have the same meaning as for + {!Unix.select}. *) + +val wait_pid : int -> int * Unix.process_status +(** [wait_pid p] suspends the execution of the calling thread + until the Unix process specified by the process identifier [p] + terminates. A pid [p] of [-1] means wait for any child. + A pid of [0] means wait for any child in the same process group + as the current process. Negative pid arguments represent + process groups. Returns the pid of the child caught and + its termination status, as per {!Unix.wait}. *) + +val wait_signal : int list -> int +(** [wait_signal sigs] suspends the execution of the calling thread + until the process receives one of the signals specified in the + list [sigs]. It then returns the number of the signal received. + Signal handlers attached to the signals in [sigs] will not + be invoked. Do not call [wait_signal] concurrently + from several threads on the same signals. *) + +val yield : unit -> unit +(** Re-schedule the calling thread without suspending it. + This function can be used to give scheduling hints, + telling the scheduler that now is a good time to + switch to other threads. *) + +(**/**) + +(** {6 Synchronization primitives} + + The following primitives provide the basis for implementing + synchronization functions between threads. Their direct use is + discouraged, as they are very low-level and prone to race conditions + and deadlocks. The modules {!Mutex}, {!Condition} and {!Event} + provide higher-level synchronization primitives. *) + +val critical_section : bool ref +(** Setting this reference to [true] deactivate thread preemption + (the timer interrupt that transfers control from thread to thread), + causing the current thread to run uninterrupted until + [critical_section] is reset to [false] or the current thread + explicitely relinquishes control using [sleep], [delay], + [wait_inchan] or [wait_descr]. *) + +val sleep : unit -> unit +(** Suspend the calling thread until another thread reactivates it + using {!Thread.wakeup}. Just before suspending the thread, + {!Thread.critical_section} is reset to [false]. Resetting + {!Thread.critical_section} and suspending the calling thread is an + atomic operation. *) + +val wakeup : t -> unit +(** Reactivate the given thread. After the call to [wakeup], + the suspended thread will resume execution at some future time. *) + diff --git a/otherlibs/threads/threadUnix.ml b/otherlibs/threads/threadUnix.ml new file mode 100644 index 0000000..90b7cb1 --- /dev/null +++ b/otherlibs/threads/threadUnix.ml @@ -0,0 +1,61 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: threadUnix.ml,v 1.19 2004-07-13 12:25:13 xleroy Exp $ *) + +(* Module [ThreadUnix]: thread-compatible system calls *) + +let execv = Unix.execv +let execve = Unix.execve +let execvp = Unix.execvp +let wait = Unix.wait +let waitpid = Unix.waitpid +let system = Unix.system +let read = Unix.read +let write = Unix.write +let single_write = Unix.single_write +let select = Unix.select +let pipe = Unix.pipe +let open_process_in = Unix.open_process_in +let open_process_out = Unix.open_process_out +let open_process = Unix.open_process +let open_process_full = Unix.open_process_full +let sleep = Unix.sleep +let socket = Unix.socket +let socketpair = Unix.socketpair +let accept = Unix.accept +let connect = Unix.connect +let recv = Unix.recv +let recvfrom = Unix.recvfrom +let send = Unix.send +let sendto = Unix.sendto +let open_connection = Unix.open_connection +let establish_server = Unix.establish_server + +open Unix + +let rec timed_read fd buff ofs len timeout = + if Thread.wait_timed_read fd timeout + then begin try Unix.read fd buff ofs len + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + timed_read fd buff ofs len timeout + end + else raise (Unix_error(ETIMEDOUT, "timed_read", "")) + +let rec timed_write fd buff ofs len timeout = + if Thread.wait_timed_write fd timeout + then begin try Unix.write fd buff ofs len + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + timed_write fd buff ofs len timeout + end + else raise (Unix_error(ETIMEDOUT, "timed_write", "")) diff --git a/otherlibs/threads/threadUnix.mli b/otherlibs/threads/threadUnix.mli new file mode 100644 index 0000000..d7b74f4 --- /dev/null +++ b/otherlibs/threads/threadUnix.mli @@ -0,0 +1,90 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: threadUnix.mli,v 1.22 2004-07-13 12:25:14 xleroy Exp $ *) + +(** Thread-compatible system calls. + + @deprecated The functionality of this module has been merged back into + the {!Unix} module. Threaded programs can now call the functions + from module {!Unix} directly, and still get the correct behavior + (block the calling thread, if required, but do not block all threads + in the process). *) + +(** {6 Process handling} *) + +val execv : string -> string array -> unit +val execve : string -> string array -> string array -> unit +val execvp : string -> string array -> unit +val wait : unit -> int * Unix.process_status +val waitpid : Unix.wait_flag list -> int -> int * Unix.process_status +val system : string -> Unix.process_status + +(** {6 Basic input/output} *) + +val read : Unix.file_descr -> string -> int -> int -> int +val write : Unix.file_descr -> string -> int -> int -> int +val single_write : Unix.file_descr -> string -> int -> int -> int + +(** {6 Input/output with timeout} *) + +val timed_read : Unix.file_descr -> string -> int -> int -> float -> int +(** See {!ThreadUnix.timed_write}. *) + +val timed_write : Unix.file_descr -> string -> int -> int -> float -> int +(** Behave as {!ThreadUnix.read} and {!ThreadUnix.write}, except that + [Unix_error(ETIMEDOUT,_,_)] is raised if no data is + available for reading or ready for writing after [d] seconds. + The delay [d] is given in the fifth argument, in seconds. *) + +(** {6 Polling} *) + +val select : + Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> + float -> + Unix.file_descr list * Unix.file_descr list * Unix.file_descr list + +(** {6 Pipes and redirections} *) + +val pipe : unit -> Unix.file_descr * Unix.file_descr +val open_process_in : string -> in_channel +val open_process_out : string -> out_channel +val open_process : string -> in_channel * out_channel +val open_process_full : + string -> string array -> in_channel * out_channel * in_channel + +(** {6 Time} *) + +val sleep : int -> unit + +(** {6 Sockets} *) + +val socket : Unix.socket_domain -> Unix.socket_type -> int -> Unix.file_descr +val socketpair : + Unix.socket_domain -> Unix.socket_type -> int -> + Unix.file_descr * Unix.file_descr +val accept : Unix.file_descr -> Unix.file_descr * Unix.sockaddr +val connect : Unix.file_descr -> Unix.sockaddr -> unit +val recv : + Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> int +val recvfrom : + Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> + int * Unix.sockaddr +val send : + Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> int +val sendto : + Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> + Unix.sockaddr -> int +val open_connection : Unix.sockaddr -> in_channel * out_channel +val establish_server : + (in_channel -> out_channel -> unit) -> Unix.sockaddr -> unit diff --git a/otherlibs/threads/threads.mllib b/otherlibs/threads/threads.mllib new file mode 100644 index 0000000..3ff8841 --- /dev/null +++ b/otherlibs/threads/threads.mllib @@ -0,0 +1 @@ +Thread Mutex Condition Event ThreadUnix diff --git a/otherlibs/threads/unix.ml b/otherlibs/threads/unix.ml new file mode 100644 index 0000000..091d4ff --- /dev/null +++ b/otherlibs/threads/unix.ml @@ -0,0 +1,1113 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unix.ml,v 1.22 2008-08-01 16:29:44 mauny Exp $ *) + +(* An alternate implementation of the Unix module from ../unix + which is safe in conjunction with bytecode threads. *) + +(* Type definitions that matter for thread operations *) + +type file_descr = int + +type process_status = + WEXITED of int + | WSIGNALED of int + | WSTOPPED of int + +(* We can't call functions from Thread because of type circularities, + so we redefine here the functions that we need *) + +type resumption_status = + Resumed_wakeup + | Resumed_delay + | Resumed_join + | Resumed_io + | Resumed_select of file_descr list * file_descr list * file_descr list + | Resumed_wait of int * process_status + +external thread_initialize : unit -> unit = "thread_initialize" +external thread_wait_read : file_descr -> unit = "thread_wait_read" +external thread_wait_write : file_descr -> unit = "thread_wait_write" +external thread_select : + file_descr list * file_descr list * file_descr list * float + -> resumption_status + = "thread_select" +external thread_wait_pid : int -> resumption_status = "thread_wait_pid" +external thread_delay : float -> unit = "thread_delay" + +let wait_read fd = thread_wait_read fd +let wait_write fd = thread_wait_write fd +let select_aux arg = thread_select arg +let wait_pid_aux pid = thread_wait_pid pid +let delay duration = thread_delay duration + +(* Make sure that threads are initialized (PR#1516). *) + +let _ = thread_initialize() + +(* Back to the Unix module *) + +type error = + E2BIG + | EACCES + | EAGAIN + | EBADF + | EBUSY + | ECHILD + | EDEADLK + | EDOM + | EEXIST + | EFAULT + | EFBIG + | EINTR + | EINVAL + | EIO + | EISDIR + | EMFILE + | EMLINK + | ENAMETOOLONG + | ENFILE + | ENODEV + | ENOENT + | ENOEXEC + | ENOLCK + | ENOMEM + | ENOSPC + | ENOSYS + | ENOTDIR + | ENOTEMPTY + | ENOTTY + | ENXIO + | EPERM + | EPIPE + | ERANGE + | EROFS + | ESPIPE + | ESRCH + | EXDEV + | EWOULDBLOCK + | EINPROGRESS + | EALREADY + | ENOTSOCK + | EDESTADDRREQ + | EMSGSIZE + | EPROTOTYPE + | ENOPROTOOPT + | EPROTONOSUPPORT + | ESOCKTNOSUPPORT + | EOPNOTSUPP + | EPFNOSUPPORT + | EAFNOSUPPORT + | EADDRINUSE + | EADDRNOTAVAIL + | ENETDOWN + | ENETUNREACH + | ENETRESET + | ECONNABORTED + | ECONNRESET + | ENOBUFS + | EISCONN + | ENOTCONN + | ESHUTDOWN + | ETOOMANYREFS + | ETIMEDOUT + | ECONNREFUSED + | EHOSTDOWN + | EHOSTUNREACH + | ELOOP + | EOVERFLOW + | EUNKNOWNERR of int + +exception Unix_error of error * string * string + +let _ = Callback.register_exception "Unix.Unix_error" + (Unix_error(E2BIG, "", "")) + +external error_message : error -> string = "unix_error_message" + +let handle_unix_error f arg = + try + f arg + with Unix_error(err, fun_name, arg) -> + prerr_string Sys.argv.(0); + prerr_string ": \""; + prerr_string fun_name; + prerr_string "\" failed"; + if String.length arg > 0 then begin + prerr_string " on \""; + prerr_string arg; + prerr_string "\"" + end; + prerr_string ": "; + prerr_endline (error_message err); + exit 2 + +external environment : unit -> string array = "unix_environment" +external getenv: string -> string = "caml_sys_getenv" +external putenv: string -> string -> unit = "unix_putenv" + +type interval_timer = + ITIMER_REAL + | ITIMER_VIRTUAL + | ITIMER_PROF + +type interval_timer_status = + { it_interval: float; (* Period *) + it_value: float } (* Current value of the timer *) + +external getitimer: interval_timer -> interval_timer_status = "unix_getitimer" +external setitimer: + interval_timer -> interval_timer_status -> interval_timer_status + = "unix_setitimer" + +type wait_flag = + WNOHANG + | WUNTRACED + +let stdin = 0 +let stdout = 1 +let stderr = 2 + +type open_flag = + O_RDONLY + | O_WRONLY + | O_RDWR + | O_NONBLOCK + | O_APPEND + | O_CREAT + | O_TRUNC + | O_EXCL + | O_NOCTTY + | O_DSYNC + | O_SYNC + | O_RSYNC + +type file_perm = int + + +external openfile : string -> open_flag list -> file_perm -> file_descr + = "unix_open" + +external close : file_descr -> unit = "unix_close" +external unsafe_read : file_descr -> string -> int -> int -> int = "unix_read" +external unsafe_write : file_descr -> string -> int -> int -> int + = "unix_write" +external unsafe_single_write : file_descr -> string -> int -> int -> int + = "unix_single_write" + +let rec read fd buf ofs len = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.read" + else unsafe_read fd buf ofs len + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_read fd; read fd buf ofs len + +let rec write fd buf ofs len = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.write" + else unsafe_write fd buf ofs len + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_write fd; write fd buf ofs len + +let rec single_write fd buf ofs len = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.partial_write" + else unsafe_single_write fd buf ofs len + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_write fd; single_write fd buf ofs len + +external in_channel_of_descr : file_descr -> in_channel + = "caml_ml_open_descriptor_in" +external out_channel_of_descr : file_descr -> out_channel + = "caml_ml_open_descriptor_out" +external descr_of_in_channel : in_channel -> file_descr + = "caml_channel_descriptor" +external descr_of_out_channel : out_channel -> file_descr + = "caml_channel_descriptor" + +type seek_command = + SEEK_SET + | SEEK_CUR + | SEEK_END + +external lseek : file_descr -> int -> seek_command -> int = "unix_lseek" +external truncate : string -> int -> unit = "unix_truncate" +external ftruncate : file_descr -> int -> unit = "unix_ftruncate" + +type file_kind = + S_REG + | S_DIR + | S_CHR + | S_BLK + | S_LNK + | S_FIFO + | S_SOCK + +type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int; + st_atime : float; + st_mtime : float; + st_ctime : float } + +external stat : string -> stats = "unix_stat" +external lstat : string -> stats = "unix_lstat" +external fstat : file_descr -> stats = "unix_fstat" +external isatty : file_descr -> bool = "unix_isatty" +external unlink : string -> unit = "unix_unlink" +external rename : string -> string -> unit = "unix_rename" +external link : string -> string -> unit = "unix_link" + +module LargeFile = + struct + external lseek : file_descr -> int64 -> seek_command -> int64 + = "unix_lseek_64" + external truncate : string -> int64 -> unit = "unix_truncate_64" + external ftruncate : file_descr -> int64 -> unit = "unix_ftruncate_64" + type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int64; + st_atime : float; + st_mtime : float; + st_ctime : float; + } + external stat : string -> stats = "unix_stat_64" + external lstat : string -> stats = "unix_lstat_64" + external fstat : file_descr -> stats = "unix_fstat_64" + end + +type access_permission = + R_OK + | W_OK + | X_OK + | F_OK + +external chmod : string -> file_perm -> unit = "unix_chmod" +external fchmod : file_descr -> file_perm -> unit = "unix_fchmod" +external chown : string -> int -> int -> unit = "unix_chown" +external fchown : file_descr -> int -> int -> unit = "unix_fchown" +external umask : int -> int = "unix_umask" +external access : string -> access_permission list -> unit = "unix_access" + +external dup : file_descr -> file_descr = "unix_dup" +external dup2 : file_descr -> file_descr -> unit = "unix_dup2" +external set_nonblock : file_descr -> unit = "unix_set_nonblock" +external clear_nonblock : file_descr -> unit = "unix_clear_nonblock" +external set_close_on_exec : file_descr -> unit = "unix_set_close_on_exec" +external clear_close_on_exec : file_descr -> unit = "unix_clear_close_on_exec" + +external mkdir : string -> file_perm -> unit = "unix_mkdir" +external rmdir : string -> unit = "unix_rmdir" +external chdir : string -> unit = "unix_chdir" +external getcwd : unit -> string = "unix_getcwd" +external chroot : string -> unit = "unix_chroot" + +type dir_handle + +external opendir : string -> dir_handle = "unix_opendir" +external readdir : dir_handle -> string = "unix_readdir" +external rewinddir : dir_handle -> unit = "unix_rewinddir" +external closedir : dir_handle -> unit = "unix_closedir" + +external _pipe : unit -> file_descr * file_descr = "unix_pipe" + +let pipe() = + let (out_fd, in_fd as fd_pair) = _pipe() in + set_nonblock in_fd; + set_nonblock out_fd; + fd_pair + +external symlink : string -> string -> unit = "unix_symlink" +external readlink : string -> string = "unix_readlink" +external mkfifo : string -> file_perm -> unit = "unix_mkfifo" + +let select readfds writefds exceptfds delay = + match select_aux (readfds, writefds, exceptfds, delay) with + Resumed_select(r, w, e) -> (r, w, e) + | _ -> ([], [], []) + +type lock_command = + F_ULOCK + | F_LOCK + | F_TLOCK + | F_TEST + | F_RLOCK + | F_TRLOCK + +external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf" + +external _execv : string -> string array -> 'a = "unix_execv" +external _execve : string -> string array -> string array -> 'a = "unix_execve" +external _execvp : string -> string array -> 'a = "unix_execvp" +external _execvpe : string -> string array -> string array -> 'a + = "unix_execvpe" + +(* Disable the timer interrupt before doing exec, because some OS + keep sending timer interrupts to the exec'ed code. + Also restore blocking mode on stdin, stdout and stderr, + since this is what most programs expect! *) + +let safe_clear_nonblock fd = + try clear_nonblock fd with Unix_error(_,_,_) -> () +let safe_set_nonblock fd = + try set_nonblock fd with Unix_error(_,_,_) -> () + +let do_exec fn = + let oldtimer = + setitimer ITIMER_VIRTUAL {it_interval = 0.0; it_value = 0.0} in + safe_clear_nonblock stdin; + safe_clear_nonblock stdout; + safe_clear_nonblock stderr; + try + fn () + with Unix_error(_,_,_) as exn -> + ignore(setitimer ITIMER_VIRTUAL oldtimer); + safe_set_nonblock stdin; + safe_set_nonblock stdout; + safe_set_nonblock stderr; + raise exn + +let execv proc args = + do_exec (fun () -> _execv proc args) + +let execve proc args env = + do_exec (fun () -> _execve proc args env) + +let execvp proc args = + do_exec (fun () -> _execvp proc args) + +let execvpe proc args = + do_exec (fun () -> _execvpe proc args) + +external fork : unit -> int = "unix_fork" +external _waitpid : wait_flag list -> int -> int * process_status + = "unix_waitpid" + +let wait_pid pid = + match wait_pid_aux pid with + Resumed_wait(pid, status) -> (pid, status) + | _ -> invalid_arg "Thread.wait_pid" + +let wait () = wait_pid (-1) + +let waitpid flags pid = + if List.mem WNOHANG flags + then _waitpid flags pid + else wait_pid pid + +external getpid : unit -> int = "unix_getpid" +external getppid : unit -> int = "unix_getppid" +external nice : int -> int = "unix_nice" + +external kill : int -> int -> unit = "unix_kill" +type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK +external sigprocmask: sigprocmask_command -> int list -> int list + = "unix_sigprocmask" +external sigpending: unit -> int list = "unix_sigpending" +external sigsuspend: int list -> unit = "unix_sigsuspend" + +let pause() = + let sigs = sigprocmask SIG_BLOCK [] in sigsuspend sigs + +type process_times = + { tms_utime : float; + tms_stime : float; + tms_cutime : float; + tms_cstime : float } + +type tm = + { tm_sec : int; + tm_min : int; + tm_hour : int; + tm_mday : int; + tm_mon : int; + tm_year : int; + tm_wday : int; + tm_yday : int; + tm_isdst : bool } + +external time : unit -> float = "unix_time" +external gettimeofday : unit -> float = "unix_gettimeofday" +external gmtime : float -> tm = "unix_gmtime" +external localtime : float -> tm = "unix_localtime" +external mktime : tm -> float * tm = "unix_mktime" +external alarm : int -> int = "unix_alarm" + +let sleep secs = delay (float secs) + +external times : unit -> process_times = "unix_times" +external utimes : string -> float -> float -> unit = "unix_utimes" + +external getuid : unit -> int = "unix_getuid" +external geteuid : unit -> int = "unix_geteuid" +external setuid : int -> unit = "unix_setuid" +external getgid : unit -> int = "unix_getgid" +external getegid : unit -> int = "unix_getegid" +external setgid : int -> unit = "unix_setgid" +external getgroups : unit -> int array = "unix_getgroups" + +type passwd_entry = + { pw_name : string; + pw_passwd : string; + pw_uid : int; + pw_gid : int; + pw_gecos : string; + pw_dir : string; + pw_shell : string } + +type group_entry = + { gr_name : string; + gr_passwd : string; + gr_gid : int; + gr_mem : string array } + + +external getlogin : unit -> string = "unix_getlogin" +external getpwnam : string -> passwd_entry = "unix_getpwnam" +external getgrnam : string -> group_entry = "unix_getgrnam" +external getpwuid : int -> passwd_entry = "unix_getpwuid" +external getgrgid : int -> group_entry = "unix_getgrgid" + +type inet_addr = string + +external inet_addr_of_string : string -> inet_addr + = "unix_inet_addr_of_string" +external string_of_inet_addr : inet_addr -> string + = "unix_string_of_inet_addr" + +let inet_addr_any = inet_addr_of_string "0.0.0.0" +let inet_addr_loopback = inet_addr_of_string "127.0.0.1" +let inet6_addr_any = + try inet_addr_of_string "::" with Failure _ -> inet_addr_any +let inet6_addr_loopback = + try inet_addr_of_string "::1" with Failure _ -> inet_addr_loopback + +let is_inet6_addr s = String.length s = 16 + +type socket_domain = + PF_UNIX + | PF_INET + | PF_INET6 + +type socket_type = + SOCK_STREAM + | SOCK_DGRAM + | SOCK_RAW + | SOCK_SEQPACKET + +type sockaddr = + ADDR_UNIX of string + | ADDR_INET of inet_addr * int + +let domain_of_sockaddr = function + ADDR_UNIX _ -> PF_UNIX + | ADDR_INET(a, _) -> if is_inet6_addr a then PF_INET6 else PF_INET + +type shutdown_command = + SHUTDOWN_RECEIVE + | SHUTDOWN_SEND + | SHUTDOWN_ALL + +type msg_flag = + MSG_OOB + | MSG_DONTROUTE + | MSG_PEEK + +external _socket : socket_domain -> socket_type -> int -> file_descr + = "unix_socket" +external _socketpair : + socket_domain -> socket_type -> int -> file_descr * file_descr + = "unix_socketpair" + +let socket dom typ proto = + let s = _socket dom typ proto in + set_nonblock s; + s + +let socketpair dom typ proto = + let (s1, s2 as spair) = _socketpair dom typ proto in + set_nonblock s1; set_nonblock s2; + spair + +external _accept : file_descr -> file_descr * sockaddr = "unix_accept" + +let rec accept req = + wait_read req; + try + let (s, caller as result) = _accept req in + set_nonblock s; + result + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> accept req + +external bind : file_descr -> sockaddr -> unit = "unix_bind" +external listen : file_descr -> int -> unit = "unix_listen" +external shutdown : file_descr -> shutdown_command -> unit = "unix_shutdown" +external getsockname : file_descr -> sockaddr = "unix_getsockname" +external getpeername : file_descr -> sockaddr = "unix_getpeername" + +external _connect : file_descr -> sockaddr -> unit = "unix_connect" + +let connect s addr = + try + _connect s addr + with Unix_error((EINPROGRESS | EWOULDBLOCK | EAGAIN), _, _) -> + wait_write s; + (* Check if it really worked *) + ignore(getpeername s) + +external unsafe_recv : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_recv" +external unsafe_recvfrom : + file_descr -> string -> int -> int -> msg_flag list -> int * sockaddr + = "unix_recvfrom" +external unsafe_send : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_send" +external unsafe_sendto : + file_descr -> string -> int -> int -> msg_flag list -> sockaddr -> int + = "unix_sendto" "unix_sendto_native" + +let rec recv fd buf ofs len flags = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recv" + else unsafe_recv fd buf ofs len flags + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_read fd; recv fd buf ofs len flags + +let rec recvfrom fd buf ofs len flags = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recvfrom" + else unsafe_recvfrom fd buf ofs len flags + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_read fd; + recvfrom fd buf ofs len flags + +let rec send fd buf ofs len flags = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.send" + else unsafe_send fd buf ofs len flags + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_write fd; + send fd buf ofs len flags + +let rec sendto fd buf ofs len flags addr = + try + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.sendto" + else unsafe_sendto fd buf ofs len flags addr + with Unix_error((EAGAIN | EWOULDBLOCK), _, _) -> + wait_write fd; + sendto fd buf ofs len flags addr + +type socket_bool_option = + SO_DEBUG + | SO_BROADCAST + | SO_REUSEADDR + | SO_KEEPALIVE + | SO_DONTROUTE + | SO_OOBINLINE + | SO_ACCEPTCONN + | TCP_NODELAY + | IPV6_ONLY + + +type socket_int_option = + SO_SNDBUF + | SO_RCVBUF + | SO_ERROR + | SO_TYPE + | SO_RCVLOWAT + | SO_SNDLOWAT + +type socket_optint_option = SO_LINGER + +type socket_float_option = + SO_RCVTIMEO + | SO_SNDTIMEO + +type socket_error_option = SO_ERROR + +module SO: sig + type ('opt, 'v) t + val bool: (socket_bool_option, bool) t + val int: (socket_int_option, int) t + val optint: (socket_optint_option, int option) t + val float: (socket_float_option, float) t + val error: (socket_error_option, error option) t + val get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + val set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit +end = struct + type ('opt, 'v) t = int + let bool = 0 + let int = 1 + let optint = 2 + let float = 3 + let error = 4 + external get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + = "unix_getsockopt" + external set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit + = "unix_setsockopt" +end + +let getsockopt fd opt = SO.get SO.bool fd opt +let setsockopt fd opt v = SO.set SO.bool fd opt v + +let getsockopt_int fd opt = SO.get SO.int fd opt +let setsockopt_int fd opt v = SO.set SO.int fd opt v + +let getsockopt_optint fd opt = SO.get SO.optint fd opt +let setsockopt_optint fd opt v = SO.set SO.optint fd opt v + +let getsockopt_float fd opt = SO.get SO.float fd opt +let setsockopt_float fd opt v = SO.set SO.float fd opt v + +let getsockopt_error fd = SO.get SO.error fd SO_ERROR + +type host_entry = + { h_name : string; + h_aliases : string array; + h_addrtype : socket_domain; + h_addr_list : inet_addr array } + +type protocol_entry = + { p_name : string; + p_aliases : string array; + p_proto : int } + +type service_entry = + { s_name : string; + s_aliases : string array; + s_port : int; + s_proto : string } + +external gethostname : unit -> string = "unix_gethostname" +external gethostbyname : string -> host_entry = "unix_gethostbyname" +external gethostbyaddr : inet_addr -> host_entry = "unix_gethostbyaddr" +external getprotobyname : string -> protocol_entry + = "unix_getprotobyname" +external getprotobynumber : int -> protocol_entry + = "unix_getprotobynumber" +external getservbyname : string -> string -> service_entry + = "unix_getservbyname" +external getservbyport : int -> string -> service_entry + = "unix_getservbyport" +type addr_info = + { ai_family : socket_domain; + ai_socktype : socket_type; + ai_protocol : int; + ai_addr : sockaddr; + ai_canonname : string } + +type getaddrinfo_option = + AI_FAMILY of socket_domain + | AI_SOCKTYPE of socket_type + | AI_PROTOCOL of int + | AI_NUMERICHOST + | AI_CANONNAME + | AI_PASSIVE + +external getaddrinfo_system + : string -> string -> getaddrinfo_option list -> addr_info list + = "unix_getaddrinfo" + +let getaddrinfo_emulation node service opts = + (* Parse options *) + let opt_socktype = ref None + and opt_protocol = ref 0 + and opt_passive = ref false in + List.iter + (function AI_SOCKTYPE s -> opt_socktype := Some s + | AI_PROTOCOL p -> opt_protocol := p + | AI_PASSIVE -> opt_passive := true + | _ -> ()) + opts; + (* Determine socket types and port numbers *) + let get_port ty kind = + if service = "" then [ty, 0] else + try + [ty, int_of_string service] + with Failure _ -> + try + [ty, (getservbyname service kind).s_port] + with Not_found -> [] + in + let ports = + match !opt_socktype with + | None -> + get_port SOCK_STREAM "tcp" @ get_port SOCK_DGRAM "udp" + | Some SOCK_STREAM -> + get_port SOCK_STREAM "tcp" + | Some SOCK_DGRAM -> + get_port SOCK_DGRAM "udp" + | Some ty -> + if service = "" then [ty, 0] else [] in + (* Determine IP addresses *) + let addresses = + if node = "" then + if List.mem AI_PASSIVE opts + then [inet_addr_any, "0.0.0.0"] + else [inet_addr_loopback, "127.0.0.1"] + else + try + [inet_addr_of_string node, node] + with Failure _ -> + try + let he = gethostbyname node in + List.map + (fun a -> (a, he.h_name)) + (Array.to_list he.h_addr_list) + with Not_found -> + [] in + (* Cross-product of addresses and ports *) + List.flatten + (List.map + (fun (ty, port) -> + List.map + (fun (addr, name) -> + { ai_family = PF_INET; + ai_socktype = ty; + ai_protocol = !opt_protocol; + ai_addr = ADDR_INET(addr, port); + ai_canonname = name }) + addresses) + ports) + +let getaddrinfo node service opts = + try + List.rev(getaddrinfo_system node service opts) + with Invalid_argument _ -> + getaddrinfo_emulation node service opts + +type name_info = + { ni_hostname : string; + ni_service : string } + +type getnameinfo_option = + NI_NOFQDN + | NI_NUMERICHOST + | NI_NAMEREQD + | NI_NUMERICSERV + | NI_DGRAM + +external getnameinfo_system + : sockaddr -> getnameinfo_option list -> name_info + = "unix_getnameinfo" + +let getnameinfo_emulation addr opts = + match addr with + | ADDR_UNIX f -> + { ni_hostname = ""; ni_service = f } (* why not? *) + | ADDR_INET(a, p) -> + let hostname = + try + if List.mem NI_NUMERICHOST opts then raise Not_found; + (gethostbyaddr a).h_name + with Not_found -> + if List.mem NI_NAMEREQD opts then raise Not_found; + string_of_inet_addr a in + let service = + try + if List.mem NI_NUMERICSERV opts then raise Not_found; + let kind = if List.mem NI_DGRAM opts then "udp" else "tcp" in + (getservbyport p kind).s_name + with Not_found -> + string_of_int p in + { ni_hostname = hostname; ni_service = service } + +let getnameinfo addr opts = + try + getnameinfo_system addr opts + with Invalid_argument _ -> + getnameinfo_emulation addr opts + +type terminal_io = { + mutable c_ignbrk: bool; + mutable c_brkint: bool; + mutable c_ignpar: bool; + mutable c_parmrk: bool; + mutable c_inpck: bool; + mutable c_istrip: bool; + mutable c_inlcr: bool; + mutable c_igncr: bool; + mutable c_icrnl: bool; + mutable c_ixon: bool; + mutable c_ixoff: bool; + mutable c_opost: bool; + mutable c_obaud: int; + mutable c_ibaud: int; + mutable c_csize: int; + mutable c_cstopb: int; + mutable c_cread: bool; + mutable c_parenb: bool; + mutable c_parodd: bool; + mutable c_hupcl: bool; + mutable c_clocal: bool; + mutable c_isig: bool; + mutable c_icanon: bool; + mutable c_noflsh: bool; + mutable c_echo: bool; + mutable c_echoe: bool; + mutable c_echok: bool; + mutable c_echonl: bool; + mutable c_vintr: char; + mutable c_vquit: char; + mutable c_verase: char; + mutable c_vkill: char; + mutable c_veof: char; + mutable c_veol: char; + mutable c_vmin: int; + mutable c_vtime: int; + mutable c_vstart: char; + mutable c_vstop: char + } + +external tcgetattr: file_descr -> terminal_io = "unix_tcgetattr" + +type setattr_when = TCSANOW | TCSADRAIN | TCSAFLUSH + +external tcsetattr: file_descr -> setattr_when -> terminal_io -> unit + = "unix_tcsetattr" +external tcsendbreak: file_descr -> int -> unit = "unix_tcsendbreak" +external tcdrain: file_descr -> unit = "unix_tcdrain" + +type flush_queue = TCIFLUSH | TCOFLUSH | TCIOFLUSH + +external tcflush: file_descr -> flush_queue -> unit = "unix_tcflush" + +type flow_action = TCOOFF | TCOON | TCIOFF | TCION + +external tcflow: file_descr -> flow_action -> unit = "unix_tcflow" + +external setsid : unit -> int = "unix_setsid" + +(* High-level process management (system, popen) *) + +let system cmd = + match fork() with + 0 -> begin try + execv "/bin/sh" [| "/bin/sh"; "-c"; cmd |] + with _ -> + exit 127 + end + | id -> snd(waitpid [] id) + +let rec safe_dup fd = + let new_fd = dup fd in + if new_fd >= 3 then + new_fd + else begin + let res = safe_dup fd in + close new_fd; + res + end + +let safe_close fd = + try close fd with Unix_error(_,_,_) -> () + +let perform_redirections new_stdin new_stdout new_stderr = + let newnewstdin = safe_dup new_stdin in + let newnewstdout = safe_dup new_stdout in + let newnewstderr = safe_dup new_stderr in + safe_close new_stdin; + safe_close new_stdout; + safe_close new_stderr; + dup2 newnewstdin stdin; close newnewstdin; + dup2 newnewstdout stdout; close newnewstdout; + dup2 newnewstderr stderr; close newnewstderr + +let create_process cmd args new_stdin new_stdout new_stderr = + match fork() with + 0 -> + begin try + perform_redirections new_stdin new_stdout new_stderr; + execvp cmd args + with _ -> + exit 127 + end + | id -> id + +let create_process_env cmd args env new_stdin new_stdout new_stderr = + match fork() with + 0 -> + begin try + perform_redirections new_stdin new_stdout new_stderr; + execvpe cmd args env + with _ -> + exit 127 + end + | id -> id + +type popen_process = + Process of in_channel * out_channel + | Process_in of in_channel + | Process_out of out_channel + | Process_full of in_channel * out_channel * in_channel + +let popen_processes = (Hashtbl.create 7 : (popen_process, int) Hashtbl.t) + +let open_proc cmd proc input output toclose = + match fork() with + 0 -> if input <> stdin then begin dup2 input stdin; close input end; + if output <> stdout then begin dup2 output stdout; close output end; + List.iter close toclose; + begin try execv "/bin/sh" [| "/bin/sh"; "-c"; cmd |] + with _ -> exit 127 + end + | id -> Hashtbl.add popen_processes proc id + +let open_process_in cmd = + let (in_read, in_write) = pipe() in + let inchan = in_channel_of_descr in_read in + open_proc cmd (Process_in inchan) stdin in_write [in_read]; + close in_write; + inchan + +let open_process_out cmd = + let (out_read, out_write) = pipe() in + let outchan = out_channel_of_descr out_write in + open_proc cmd (Process_out outchan) out_read stdout [out_write]; + close out_read; + outchan + +let open_process cmd = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + open_proc cmd (Process(inchan, outchan)) out_read in_write + [in_read; out_write]; + close out_read; + close in_write; + (inchan, outchan) + +let open_proc_full cmd env proc input output error toclose = + match fork() with + 0 -> dup2 input stdin; close input; + dup2 output stdout; close output; + dup2 error stderr; close error; + List.iter close toclose; + begin try execve "/bin/sh" [| "/bin/sh"; "-c"; cmd |] env + with _ -> exit 127 + end + | id -> Hashtbl.add popen_processes proc id + +let open_process_full cmd env = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + let (err_read, err_write) = pipe() in + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + let errchan = in_channel_of_descr err_read in + open_proc_full cmd env (Process_full(inchan, outchan, errchan)) + out_read in_write err_write [in_read; out_write; err_read]; + close out_read; + close in_write; + close err_write; + (inchan, outchan, errchan) + +let find_proc_id fun_name proc = + try + let pid = Hashtbl.find popen_processes proc in + Hashtbl.remove popen_processes proc; + pid + with Not_found -> + raise(Unix_error(EBADF, fun_name, "")) + +let rec waitpid_non_intr pid = + try waitpid [] pid + with Unix_error (EINTR, _, _) -> waitpid_non_intr pid + +let close_process_in inchan = + let pid = find_proc_id "close_process_in" (Process_in inchan) in + close_in inchan; + snd(waitpid_non_intr pid) + +let close_process_out outchan = + let pid = find_proc_id "close_process_out" (Process_out outchan) in + close_out outchan; + snd(waitpid_non_intr pid) + +let close_process (inchan, outchan) = + let pid = find_proc_id "close_process" (Process(inchan, outchan)) in + close_in inchan; + begin try close_out outchan with Sys_error _ -> () end; + snd(waitpid_non_intr pid) + +let close_process_full (inchan, outchan, errchan) = + let pid = + find_proc_id "close_process_full" + (Process_full(inchan, outchan, errchan)) in + close_in inchan; + begin try close_out outchan with Sys_error _ -> () end; + close_in errchan; + snd(waitpid_non_intr pid) + +(* High-level network functions *) + +let open_connection sockaddr = + let sock = + socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in + try + connect sock sockaddr; + (in_channel_of_descr sock, out_channel_of_descr sock) + with exn -> + close sock; raise exn + +let shutdown_connection inchan = + shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND + +let establish_server server_fun sockaddr = + let sock = + socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in + setsockopt sock SO_REUSEADDR true; + bind sock sockaddr; + listen sock 5; + while true do + let (s, caller) = accept sock in + (* The "double fork" trick, the process which calls server_fun will not + leave a zombie process *) + match fork() with + 0 -> if fork() <> 0 then exit 0; (* The son exits, the grandson works *) + let inchan = in_channel_of_descr s in + let outchan = out_channel_of_descr s in + server_fun inchan outchan; + close_out outchan; + (* The file descriptor was already closed by close_out. + close_in inchan; + *) + exit 0 + | id -> close s; ignore(waitpid [] id) (* Reclaim the son *) + done + diff --git a/otherlibs/threads/unix.mllib b/otherlibs/threads/unix.mllib new file mode 100644 index 0000000..8d569c5 --- /dev/null +++ b/otherlibs/threads/unix.mllib @@ -0,0 +1 @@ +Unix UnixLabels diff --git a/otherlibs/unix/.cvsignore b/otherlibs/unix/.cvsignore new file mode 100644 index 0000000..074dd28 --- /dev/null +++ b/otherlibs/unix/.cvsignore @@ -0,0 +1 @@ +so_locations diff --git a/otherlibs/unix/.depend b/otherlibs/unix/.depend new file mode 100644 index 0000000..2c589e9 --- /dev/null +++ b/otherlibs/unix/.depend @@ -0,0 +1,796 @@ +accept.o: accept.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +access.o: access.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +addrofstr.o: addrofstr.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +alarm.o: alarm.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +bind.o: bind.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h socketaddr.h +chdir.o: chdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +chmod.o: chmod.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +chown.o: chown.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +chroot.o: chroot.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +close.o: close.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +closedir.o: closedir.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h unixsupport.h +connect.o: connect.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +cst2constr.o: cst2constr.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h cst2constr.h +cstringv.o: cstringv.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/memory.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/gc.h ../../byterun/mlvalues.h \ + ../../byterun/major_gc.h ../../byterun/freelist.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/misc.h ../../byterun/minor_gc.h \ + ../../byterun/misc.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + unixsupport.h +dup.o: dup.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +dup2.o: dup2.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +envir.o: envir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +errmsg.o: errmsg.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +execv.o: execv.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +execve.o: execve.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +execvp.o: execvp.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +exit.o: exit.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +fchmod.o: fchmod.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +fchown.o: fchown.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +fcntl.o: fcntl.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +fork.o: fork.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +ftruncate.o: ftruncate.c ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h ../../byterun/io.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +getaddrinfo.o: getaddrinfo.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h cst2constr.h socketaddr.h +getcwd.o: getcwd.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +getegid.o: getegid.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h unixsupport.h +geteuid.o: geteuid.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h unixsupport.h +getgid.o: getgid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +getgr.o: getgr.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +getgroups.o: getgroups.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +gethost.o: gethost.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +gethostname.o: gethostname.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +getlogin.o: getlogin.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +getnameinfo.o: getnameinfo.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +getpeername.o: getpeername.c ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h unixsupport.h socketaddr.h +getpid.o: getpid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +getppid.o: getppid.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h unixsupport.h +getproto.o: getproto.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +getpw.o: getpw.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +getserv.o: getserv.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +getsockname.o: getsockname.c ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h unixsupport.h socketaddr.h +gettimeofday.o: gettimeofday.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +getuid.o: getuid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +gmtime.o: gmtime.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +isatty.o: isatty.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +itimer.o: itimer.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +kill.o: kill.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h +link.o: link.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +listen.o: listen.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +lockf.o: lockf.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +lseek.o: lseek.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/io.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +mkdir.o: mkdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +mkfifo.o: mkfifo.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +nice.o: nice.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +open.o: open.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +opendir.o: opendir.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +pipe.o: pipe.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +putenv.o: putenv.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +read.o: read.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +readdir.o: readdir.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +readlink.o: readlink.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +rename.o: rename.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +rewinddir.o: rewinddir.c ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/misc.h unixsupport.h +rmdir.o: rmdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +select.o: select.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +sendrecv.o: sendrecv.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +setgid.o: setgid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +setsid.o: setsid.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +setuid.o: setuid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +shutdown.o: shutdown.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +signals.o: signals.c ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +sleep.o: sleep.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +socket.o: socket.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +socketaddr.o: socketaddr.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h \ + socketaddr.h +socketpair.o: socketpair.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +sockopt.o: sockopt.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/memory.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/gc.h ../../byterun/mlvalues.h \ + ../../byterun/major_gc.h ../../byterun/freelist.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/misc.h ../../byterun/minor_gc.h \ + ../../byterun/misc.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +stat.o: stat.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h cst2constr.h ../../byterun/io.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h +strofaddr.o: strofaddr.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h socketaddr.h +symlink.o: symlink.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +termios.o: termios.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +time.o: time.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +times.o: times.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h unixsupport.h +truncate.o: truncate.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/io.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +umask.o: umask.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +unixsupport.o: unixsupport.c ../../byterun/mlvalues.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/../config/m.h ../../byterun/../config/s.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/compatibility.h ../../byterun/config.h \ + ../../byterun/alloc.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/callback.h \ + ../../byterun/compatibility.h ../../byterun/mlvalues.h \ + ../../byterun/memory.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/gc.h ../../byterun/mlvalues.h \ + ../../byterun/major_gc.h ../../byterun/freelist.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/misc.h ../../byterun/minor_gc.h \ + ../../byterun/misc.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/fail.h ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h cst2constr.h +unlink.o: unlink.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h unixsupport.h +utimes.o: utimes.c ../../byterun/fail.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/misc.h unixsupport.h +wait.o: wait.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/alloc.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/fail.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +write.o: write.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/../config/m.h \ + ../../byterun/../config/s.h ../../byterun/compatibility.h \ + ../../byterun/misc.h ../../byterun/compatibility.h \ + ../../byterun/config.h ../../byterun/memory.h \ + ../../byterun/compatibility.h ../../byterun/config.h ../../byterun/gc.h \ + ../../byterun/mlvalues.h ../../byterun/major_gc.h \ + ../../byterun/freelist.h ../../byterun/misc.h ../../byterun/mlvalues.h \ + ../../byterun/misc.h ../../byterun/minor_gc.h ../../byterun/misc.h \ + ../../byterun/misc.h ../../byterun/mlvalues.h ../../byterun/signals.h \ + ../../byterun/compatibility.h ../../byterun/misc.h \ + ../../byterun/mlvalues.h unixsupport.h +unix.cmi: +unixLabels.cmi: unix.cmi +unix.cmo: unix.cmi +unix.cmx: unix.cmi +unixLabels.cmo: unix.cmi unixLabels.cmi +unixLabels.cmx: unix.cmx unixLabels.cmi diff --git a/otherlibs/unix/Makefile b/otherlibs/unix/Makefile new file mode 100644 index 0000000..af76d3d --- /dev/null +++ b/otherlibs/unix/Makefile @@ -0,0 +1,49 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.46 2007-11-06 15:16:56 frisch Exp $ + +# Makefile for the Unix interface library + +LIBNAME=unix + +EXTRACAMLFLAGS=-nolabels + +COBJS=accept.o access.o addrofstr.o alarm.o bind.o chdir.o chmod.o \ + chown.o chroot.o close.o closedir.o connect.o cst2constr.o cstringv.o \ + dup.o dup2.o envir.o errmsg.o execv.o execve.o execvp.o exit.o \ + fchmod.o fchown.o fcntl.o fork.o ftruncate.o \ + getaddrinfo.o getcwd.o getegid.o geteuid.o getgid.o \ + getgr.o getgroups.o gethost.o gethostname.o getlogin.o \ + getnameinfo.o getpeername.o getpid.o getppid.o getproto.o getpw.o \ + gettimeofday.o getserv.o getsockname.o getuid.o \ + gmtime.o isatty.o itimer.o kill.o link.o listen.o lockf.o lseek.o mkdir.o \ + mkfifo.o nice.o open.o opendir.o pipe.o putenv.o read.o \ + readdir.o readlink.o rename.o rewinddir.o rmdir.o select.o sendrecv.o \ + setgid.o setsid.o setuid.o shutdown.o signals.o \ + sleep.o socket.o socketaddr.o \ + socketpair.o sockopt.o stat.o strofaddr.o symlink.o termios.o \ + time.o times.o truncate.o umask.o unixsupport.o unlink.o \ + utimes.o wait.o write.o + +CAMLOBJS=unix.cmo unixLabels.cmo + +HEADERS=unixsupport.h + +include ../Makefile + +depend: + gcc -MM $(CFLAGS) *.c > .depend + ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend + +include .depend diff --git a/otherlibs/unix/accept.c b/otherlibs/unix/accept.c new file mode 100644 index 0000000..6b39629 --- /dev/null +++ b/otherlibs/unix/accept.c @@ -0,0 +1,54 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: accept.c,v 1.13 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_accept(value sock) +{ + int retcode; + value res; + value a; + union sock_addr_union addr; + socklen_param_type addr_len; + + addr_len = sizeof(addr); + enter_blocking_section(); + retcode = accept(Int_val(sock), &addr.s_gen, &addr_len); + leave_blocking_section(); + if (retcode == -1) uerror("accept", Nothing); + a = alloc_sockaddr(&addr, addr_len, retcode); + Begin_root (a); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(retcode); + Field(res, 1) = a; + End_roots(); + return res; +} + +#else + +CAMLprim value unix_accept(value sock) +{ invalid_argument("accept not implemented"); } + +#endif diff --git a/otherlibs/unix/access.c b/otherlibs/unix/access.c new file mode 100644 index 0000000..449a6e7 --- /dev/null +++ b/otherlibs/unix/access.c @@ -0,0 +1,52 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: access.c,v 1.12 2008-01-11 16:13:16 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +#ifdef HAS_UNISTD +# include <unistd.h> +#else +# ifndef _WIN32 +# include <sys/file.h> +# ifndef R_OK +# define R_OK 4/* test for read permission */ +# define W_OK 2/* test for write permission */ +# define X_OK 1/* test for execute (search) permission */ +# define F_OK 0/* test for presence of file */ +# endif +# else +# define R_OK 4/* test for read permission */ +# define W_OK 2/* test for write permission */ +# define X_OK 4/* test for execute permission - not implemented in Win32 */ +# define F_OK 0/* test for presence of file */ +# endif +#endif + +static int access_permission_table[] = { + R_OK, W_OK, X_OK, F_OK +}; + +CAMLprim value unix_access(value path, value perms) +{ + int ret, cv_flags; + + cv_flags = convert_flag_list(perms, access_permission_table); + ret = access(String_val(path), cv_flags); + if (ret == -1) + uerror("access", path); + return Val_unit; +} diff --git a/otherlibs/unix/addrofstr.c b/otherlibs/unix/addrofstr.c new file mode 100644 index 0000000..490425e --- /dev/null +++ b/otherlibs/unix/addrofstr.c @@ -0,0 +1,53 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: addrofstr.c,v 1.11 2004-04-09 13:25:20 xleroy Exp $ */ + +#include <mlvalues.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_inet_addr_of_string(value s) +{ +#if defined(HAS_IPV6) + struct in_addr address; + struct in6_addr address6; + if (inet_pton(AF_INET, String_val(s), &address) > 0) + return alloc_inet_addr(&address); + else if (inet_pton(AF_INET6, String_val(s), &address6) > 0) + return alloc_inet6_addr(&address6); + else + failwith("inet_addr_of_string"); +#elif defined(HAS_INET_ATON) + struct in_addr address; + if (inet_aton(String_val(s), &address) == 0) + failwith("inet_addr_of_string"); + return alloc_inet_addr(&address); +#else + struct in_addr address; + address.s_addr = inet_addr(String_val(s)); + if (address.s_addr == (uint32) -1) failwith("inet_addr_of_string"); + return alloc_inet_addr(&address); +#endif +} + +#else + +CAMLprim value unix_inet_addr_of_string(value s) +{ invalid_argument("inet_addr_of_string not implemented"); } + +#endif diff --git a/otherlibs/unix/alarm.c b/otherlibs/unix/alarm.c new file mode 100644 index 0000000..854e716 --- /dev/null +++ b/otherlibs/unix/alarm.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: alarm.c,v 1.8 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_alarm(value t) +{ + return Val_int(alarm((unsigned int) Long_val(t))); +} diff --git a/otherlibs/unix/bind.c b/otherlibs/unix/bind.c new file mode 100644 index 0000000..f859da1 --- /dev/null +++ b/otherlibs/unix/bind.c @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bind.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_bind(value socket, value address) +{ + int ret; + union sock_addr_union addr; + socklen_param_type addr_len; + + get_sockaddr(address, &addr, &addr_len); + ret = bind(Int_val(socket), &addr.s_gen, addr_len); + if (ret == -1) uerror("bind", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_bind(value socket, value address) +{ invalid_argument("bind not implemented"); } + +#endif diff --git a/otherlibs/unix/chdir.c b/otherlibs/unix/chdir.c new file mode 100644 index 0000000..9d27832 --- /dev/null +++ b/otherlibs/unix/chdir.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: chdir.c,v 1.8 2001-12-07 13:40:24 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_chdir(value path) +{ + int ret; + ret = chdir(String_val(path)); + if (ret == -1) uerror("chdir", path); + return Val_unit; +} diff --git a/otherlibs/unix/chmod.c b/otherlibs/unix/chmod.c new file mode 100644 index 0000000..d0ed458 --- /dev/null +++ b/otherlibs/unix/chmod.c @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: chmod.c,v 1.9 2001-12-07 13:40:26 xleroy Exp $ */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_chmod(value path, value perm) +{ + int ret; + ret = chmod(String_val(path), Int_val(perm)); + if (ret == -1) uerror("chmod", path); + return Val_unit; +} diff --git a/otherlibs/unix/chown.c b/otherlibs/unix/chown.c new file mode 100644 index 0000000..3a8713b --- /dev/null +++ b/otherlibs/unix/chown.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: chown.c,v 1.8 2001-12-07 13:40:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_chown(value path, value uid, value gid) +{ + int ret; + ret = chown(String_val(path), Int_val(uid), Int_val(gid)); + if (ret == -1) uerror("chown", path); + return Val_unit; +} diff --git a/otherlibs/unix/chroot.c b/otherlibs/unix/chroot.c new file mode 100644 index 0000000..4e27f4f --- /dev/null +++ b/otherlibs/unix/chroot.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: chroot.c,v 1.8 2001-12-07 13:40:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_chroot(value path) +{ + int ret; + ret = chroot(String_val(path)); + if (ret == -1) uerror("chroot", path); + return Val_unit; +} diff --git a/otherlibs/unix/close.c b/otherlibs/unix/close.c new file mode 100644 index 0000000..3b6d2bc --- /dev/null +++ b/otherlibs/unix/close.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: close.c,v 1.10 2001-12-07 13:40:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_close(value fd) +{ + if (close(Int_val(fd)) == -1) uerror("close", Nothing); + return Val_unit; +} diff --git a/otherlibs/unix/closedir.c b/otherlibs/unix/closedir.c new file mode 100644 index 0000000..c36b1ba --- /dev/null +++ b/otherlibs/unix/closedir.c @@ -0,0 +1,33 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: closedir.c,v 1.9 2004-02-14 10:21:22 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAS_DIRENT +#include <dirent.h> +#else +#include <sys/dir.h> +#endif + +CAMLprim value unix_closedir(value vd) +{ + DIR * d = DIR_Val(vd); + if (d == (DIR *) NULL) unix_error(EBADF, "closedir", Nothing); + closedir(d); + DIR_Val(vd) = (DIR *) NULL; + return Val_unit; +} diff --git a/otherlibs/unix/connect.c b/otherlibs/unix/connect.c new file mode 100644 index 0000000..94f7f5f --- /dev/null +++ b/otherlibs/unix/connect.c @@ -0,0 +1,44 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: connect.c,v 1.12 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_connect(value socket, value address) +{ + int retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + + get_sockaddr(address, &addr, &addr_len); + enter_blocking_section(); + retcode = connect(Int_val(socket), &addr.s_gen, addr_len); + leave_blocking_section(); + if (retcode == -1) uerror("connect", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_connect(value socket, value address) +{ invalid_argument("connect not implemented"); } + +#endif diff --git a/otherlibs/unix/cst2constr.c b/otherlibs/unix/cst2constr.c new file mode 100644 index 0000000..e93a876 --- /dev/null +++ b/otherlibs/unix/cst2constr.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: cst2constr.c,v 1.7 2001-12-07 13:40:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include <fail.h> +#include "cst2constr.h" + +value cst_to_constr(int n, int *tbl, int size, int deflt) +{ + int i; + for (i = 0; i < size; i++) + if (n == tbl[i]) return Val_int(i); + return Val_int(deflt); +} diff --git a/otherlibs/unix/cst2constr.h b/otherlibs/unix/cst2constr.h new file mode 100644 index 0000000..1c16293 --- /dev/null +++ b/otherlibs/unix/cst2constr.h @@ -0,0 +1,16 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: cst2constr.h,v 1.7 2004-04-09 13:25:21 xleroy Exp $ */ + +extern value cst_to_constr(int n, int * tbl, int size, int deflt); diff --git a/otherlibs/unix/cstringv.c b/otherlibs/unix/cstringv.c new file mode 100644 index 0000000..a0b7d03 --- /dev/null +++ b/otherlibs/unix/cstringv.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: cstringv.c,v 1.7 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include "unixsupport.h" + +char ** cstringvect(value arg) +{ + char ** res; + mlsize_t size, i; + + size = Wosize_val(arg); + res = (char **) stat_alloc((size + 1) * sizeof(char *)); + for (i = 0; i < size; i++) res[i] = String_val(Field(arg, i)); + res[size] = NULL; + return res; +} + + diff --git a/otherlibs/unix/dup.c b/otherlibs/unix/dup.c new file mode 100644 index 0000000..aa463f4 --- /dev/null +++ b/otherlibs/unix/dup.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dup.c,v 1.8 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_dup(value fd) +{ + int ret; + ret = dup(Int_val(fd)); + if (ret == -1) uerror("dup", Nothing); + return Val_int(ret); +} diff --git a/otherlibs/unix/dup2.c b/otherlibs/unix/dup2.c new file mode 100644 index 0000000..fe2dd01 --- /dev/null +++ b/otherlibs/unix/dup2.c @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dup2.c,v 1.9 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_DUP2 + +CAMLprim value unix_dup2(value fd1, value fd2) +{ + if (dup2(Int_val(fd1), Int_val(fd2)) == -1) uerror("dup2", Nothing); + return Val_unit; +} + +#else + +static int do_dup2(int fd1, int fd2) +{ + int fd; + int res; + + fd = dup(fd1); + if (fd == -1) return -1; + if (fd == fd2) return 0; + res = do_dup2(fd1, fd2); + close(fd); + return res; +} + +CAMLprim value unix_dup2(value fd1, value fd2) +{ + close(Int_val(fd2)); + if (do_dup2(Int_val(fd1), Int_val(fd2)) == -1) uerror("dup2", Nothing); + return Val_unit; +} + +#endif diff --git a/otherlibs/unix/envir.c b/otherlibs/unix/envir.c new file mode 100644 index 0000000..62570e7 --- /dev/null +++ b/otherlibs/unix/envir.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: envir.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> + +#ifndef _WIN32 +extern char ** environ; +#endif + +CAMLprim value unix_environment(value unit) +{ + return copy_string_array((const char**)environ); +} diff --git a/otherlibs/unix/errmsg.c b/otherlibs/unix/errmsg.c new file mode 100644 index 0000000..6dbad20 --- /dev/null +++ b/otherlibs/unix/errmsg.c @@ -0,0 +1,28 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: errmsg.c,v 1.12 2004-05-23 15:53:50 xleroy Exp $ */ + +#include <errno.h> +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> + +extern int error_table[]; + +CAMLprim value unix_error_message(value err) +{ + int errnum; + errnum = Is_block(err) ? Int_val(Field(err, 0)) : error_table[Int_val(err)]; + return copy_string(strerror(errnum)); +} diff --git a/otherlibs/unix/execv.c b/otherlibs/unix/execv.c new file mode 100644 index 0000000..44a3985 --- /dev/null +++ b/otherlibs/unix/execv.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: execv.c,v 1.8 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include "unixsupport.h" + +extern char ** cstringvect(); + +CAMLprim value unix_execv(value path, value args) +{ + char ** argv; + argv = cstringvect(args); + (void) execv(String_val(path), argv); + stat_free((char *) argv); + uerror("execv", path); + return Val_unit; /* never reached, but suppress warnings */ + /* from smart compilers */ +} + diff --git a/otherlibs/unix/execve.c b/otherlibs/unix/execve.c new file mode 100644 index 0000000..2ccae11 --- /dev/null +++ b/otherlibs/unix/execve.c @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: execve.c,v 1.8 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include "unixsupport.h" + +extern char ** cstringvect(); + +CAMLprim value unix_execve(value path, value args, value env) +{ + char ** argv; + char ** envp; + argv = cstringvect(args); + envp = cstringvect(env); + (void) execve(String_val(path), argv, envp); + stat_free((char *) argv); + stat_free((char *) envp); + uerror("execve", path); + return Val_unit; /* never reached, but suppress warnings */ + /* from smart compilers */ +} + diff --git a/otherlibs/unix/execvp.c b/otherlibs/unix/execvp.c new file mode 100644 index 0000000..6082906 --- /dev/null +++ b/otherlibs/unix/execvp.c @@ -0,0 +1,51 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: execvp.c,v 1.8 2001-12-07 13:40:27 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include "unixsupport.h" + +extern char ** cstringvect(); +#ifndef _WIN32 +extern char ** environ; +#endif + +CAMLprim value unix_execvp(value path, value args) +{ + char ** argv; + argv = cstringvect(args); + (void) execvp(String_val(path), argv); + stat_free((char *) argv); + uerror("execvp", path); + return Val_unit; /* never reached, but suppress warnings */ + /* from smart compilers */ +} + +CAMLprim value unix_execvpe(value path, value args, value env) +{ + char ** argv; + char ** saved_environ; + argv = cstringvect(args); + saved_environ = environ; + environ = cstringvect(env); + (void) execvp(String_val(path), argv); + stat_free((char *) argv); + stat_free((char *) environ); + environ = saved_environ; + uerror("execvp", path); + return Val_unit; /* never reached, but suppress warnings */ + /* from smart compilers */ +} + diff --git a/otherlibs/unix/exit.c b/otherlibs/unix/exit.c new file mode 100644 index 0000000..80ebc8c --- /dev/null +++ b/otherlibs/unix/exit.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: exit.c,v 1.9 2001-12-07 13:40:28 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_exit(value n) +{ + _exit(Int_val(n)); + return Val_unit; /* never reached, but suppress warnings */ + /* from smart compilers */ +} + + diff --git a/otherlibs/unix/fchmod.c b/otherlibs/unix/fchmod.c new file mode 100644 index 0000000..82b1151 --- /dev/null +++ b/otherlibs/unix/fchmod.c @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fchmod.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_FCHMOD + +CAMLprim value unix_fchmod(value fd, value perm) +{ + if (fchmod(Int_val(fd), Int_val(perm)) == -1) uerror("fchmod", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_fchmod(value fd, value perm) +{ invalid_argument("fchmod not implemented"); } + +#endif diff --git a/otherlibs/unix/fchown.c b/otherlibs/unix/fchown.c new file mode 100644 index 0000000..f449e11 --- /dev/null +++ b/otherlibs/unix/fchown.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fchown.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_FCHMOD + +CAMLprim value unix_fchown(value fd, value uid, value gid) +{ + if (fchown(Int_val(fd), Int_val(uid), Int_val(gid)) == -1) + uerror("fchown", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_fchown(value fd, value uid, value gid) +{ invalid_argument("fchown not implemented"); } + +#endif diff --git a/otherlibs/unix/fcntl.c b/otherlibs/unix/fcntl.c new file mode 100644 index 0000000..ebdf1b5 --- /dev/null +++ b/otherlibs/unix/fcntl.c @@ -0,0 +1,78 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fcntl.c,v 1.12 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#include <fcntl.h> + +#ifndef O_NONBLOCK +#define O_NONBLOCK O_NDELAY +#endif + +CAMLprim value unix_set_nonblock(value fd) +{ + int retcode; + retcode = fcntl(Int_val(fd), F_GETFL, 0); + if (retcode == -1 || + fcntl(Int_val(fd), F_SETFL, retcode | O_NONBLOCK) == -1) + uerror("set_nonblock", Nothing); + return Val_unit; +} + +CAMLprim value unix_clear_nonblock(value fd) +{ + int retcode; + retcode = fcntl(Int_val(fd), F_GETFL, 0); + if (retcode == -1 || + fcntl(Int_val(fd), F_SETFL, retcode & ~O_NONBLOCK) == -1) + uerror("clear_nonblock", Nothing); + return Val_unit; +} + +#ifdef FD_CLOEXEC + +CAMLprim value unix_set_close_on_exec(value fd) +{ + int retcode; + retcode = fcntl(Int_val(fd), F_GETFD, 0); + if (retcode == -1 || + fcntl(Int_val(fd), F_SETFD, retcode | FD_CLOEXEC) == -1) + uerror("set_close_on_exec", Nothing); + return Val_unit; +} + +CAMLprim value unix_clear_close_on_exec(value fd) +{ + int retcode; + retcode = fcntl(Int_val(fd), F_GETFD, 0); + if (retcode == -1 || + fcntl(Int_val(fd), F_SETFD, retcode & ~FD_CLOEXEC) == -1) + uerror("clear_close_on_exec", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_set_close_on_exec(value fd) +{ invalid_argument("set_close_on_exec not implemented"); } + +CAMLprim value unix_clear_close_on_exec(value fd) +{ invalid_argument("clear_close_on_exec not implemented"); } + +#endif diff --git a/otherlibs/unix/fork.c b/otherlibs/unix/fork.c new file mode 100644 index 0000000..019d225 --- /dev/null +++ b/otherlibs/unix/fork.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: fork.c,v 1.8 2001-12-07 13:40:28 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_fork(value unit) +{ + int ret; + ret = fork(); + if (ret == -1) uerror("fork", Nothing); + return Val_int(ret); +} + diff --git a/otherlibs/unix/ftruncate.c b/otherlibs/unix/ftruncate.c new file mode 100644 index 0000000..7ae1c76 --- /dev/null +++ b/otherlibs/unix/ftruncate.c @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: ftruncate.c,v 1.11 2007-02-09 13:31:15 doligez Exp $ */ + +#include <sys/types.h> +#include <fail.h> +#include <mlvalues.h> +#include <io.h> +#include "unixsupport.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +#ifdef HAS_TRUNCATE + +CAMLprim value unix_ftruncate(value fd, value len) +{ + if (ftruncate(Int_val(fd), Long_val(len)) == -1) + uerror("ftruncate", Nothing); + return Val_unit; +} + +CAMLprim value unix_ftruncate_64(value fd, value len) +{ + if (ftruncate(Int_val(fd), File_offset_val(len)) == -1) + uerror("ftruncate", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_ftruncate(value fd, value len) +{ invalid_argument("ftruncate not implemented"); } + +CAMLprim value unix_ftruncate_64(value fd, value len) +{ invalid_argument("ftruncate not implemented"); } + +#endif diff --git a/otherlibs/unix/getaddrinfo.c b/otherlibs/unix/getaddrinfo.c new file mode 100644 index 0000000..a4c25e5 --- /dev/null +++ b/otherlibs/unix/getaddrinfo.c @@ -0,0 +1,136 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2004 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getaddrinfo.c,v 1.3 2005-08-13 20:59:37 doligez Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" +#include "cst2constr.h" + +#if defined(HAS_SOCKETS) && defined(HAS_IPV6) + +#include "socketaddr.h" +#ifndef _WIN32 +#include <sys/types.h> +#include <netdb.h> +#endif + +extern int socket_domain_table[]; /* from socket.c */ +extern int socket_type_table[]; /* from socket.c */ + +static value convert_addrinfo(struct addrinfo * a) +{ + CAMLparam0(); + CAMLlocal3(vres,vaddr,vcanonname); + union sock_addr_union sa; + socklen_param_type len; + + len = a->ai_addrlen; + if (len > sizeof(sa)) len = sizeof(sa); + memcpy(&sa.s_gen, a->ai_addr, len); + vaddr = alloc_sockaddr(&sa, len, -1); + vcanonname = copy_string(a->ai_canonname == NULL ? "" : a->ai_canonname); + vres = alloc_small(5, 0); + Field(vres, 0) = cst_to_constr(a->ai_family, socket_domain_table, 3, 0); + Field(vres, 1) = cst_to_constr(a->ai_socktype, socket_type_table, 4, 0); + Field(vres, 2) = Val_int(a->ai_protocol); + Field(vres, 3) = vaddr; + Field(vres, 4) = vcanonname; + CAMLreturn(vres); +} + +CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts) +{ + CAMLparam3(vnode, vserv, vopts); + CAMLlocal3(vres, v, e); + mlsize_t len; + char * node, * serv; + struct addrinfo hints; + struct addrinfo * res, * r; + int retcode; + + /* Extract "node" parameter */ + len = string_length(vnode); + if (len == 0) { + node = NULL; + } else { + node = stat_alloc(len + 1); + strcpy(node, String_val(vnode)); + } + /* Extract "service" parameter */ + len = string_length(vserv); + if (len == 0) { + serv = NULL; + } else { + serv = stat_alloc(len + 1); + strcpy(serv, String_val(vserv)); + } + /* Parse options, set hints */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + for (/*nothing*/; Is_block(vopts); vopts = Field(vopts, 1)) { + v = Field(vopts, 0); + if (Is_block(v)) + switch (Tag_val(v)) { + case 0: /* AI_FAMILY of socket_domain */ + hints.ai_family = socket_domain_table[Int_val(Field(v, 0))]; + break; + case 1: /* AI_SOCKTYPE of socket_type */ + hints.ai_socktype = socket_type_table[Int_val(Field(v, 0))]; + break; + case 2: /* AI_PROTOCOL of int */ + hints.ai_protocol = Int_val(Field(v, 0)); + break; + } + else + switch (Int_val(v)) { + case 0: /* AI_NUMERICHOST */ + hints.ai_flags |= AI_NUMERICHOST; break; + case 1: /* AI_CANONNAME */ + hints.ai_flags |= AI_CANONNAME; break; + case 2: /* AI_PASSIVE */ + hints.ai_flags |= AI_PASSIVE; break; + } + } + /* Do the call */ + enter_blocking_section(); + retcode = getaddrinfo(node, serv, &hints, &res); + leave_blocking_section(); + if (node != NULL) stat_free(node); + if (serv != NULL) stat_free(serv); + /* Convert result */ + vres = Val_int(0); + if (retcode == 0) { + for (r = res; r != NULL; r = r->ai_next) { + e = convert_addrinfo(r); + v = alloc_small(2, 0); + Field(v, 0) = e; + Field(v, 1) = vres; + vres = v; + } + freeaddrinfo(res); + } + CAMLreturn(vres); +} + +#else + +CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts) +{ invalid_argument("getaddrinfo not implemented"); } + +#endif diff --git a/otherlibs/unix/getcwd.c b/otherlibs/unix/getcwd.c new file mode 100644 index 0000000..eb70c08 --- /dev/null +++ b/otherlibs/unix/getcwd.c @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getcwd.c,v 1.15 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#if !defined (_WIN32) && !macintosh +#include <sys/param.h> +#endif + +#ifndef PATH_MAX +#ifdef MAXPATHLEN +#define PATH_MAX MAXPATHLEN +#else +#define PATH_MAX 512 +#endif +#endif + +#ifdef HAS_GETCWD + +CAMLprim value unix_getcwd(value unit) +{ + char buff[PATH_MAX]; + if (getcwd(buff, sizeof(buff)) == 0) uerror("getcwd", Nothing); + return copy_string(buff); +} + +#else +#ifdef HAS_GETWD + +CAMLprim value unix_getcwd(value unit) +{ + char buff[PATH_MAX]; + if (getwd(buff) == 0) uerror("getcwd", copy_string(buff)); + return copy_string(buff); +} + +#else + +CAMLprim value unix_getcwd(value unit) +{ invalid_argument("getcwd not implemented"); } + +#endif +#endif diff --git a/otherlibs/unix/getegid.c b/otherlibs/unix/getegid.c new file mode 100644 index 0000000..b0255f0 --- /dev/null +++ b/otherlibs/unix/getegid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getegid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_getegid(value unit) +{ + return Val_int(getegid()); +} diff --git a/otherlibs/unix/geteuid.c b/otherlibs/unix/geteuid.c new file mode 100644 index 0000000..c20b04e --- /dev/null +++ b/otherlibs/unix/geteuid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: geteuid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_geteuid(value unit) +{ + return Val_int(geteuid()); +} diff --git a/otherlibs/unix/getgid.c b/otherlibs/unix/getgid.c new file mode 100644 index 0000000..758dcc5 --- /dev/null +++ b/otherlibs/unix/getgid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getgid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_getgid(value unit) +{ + return Val_int(getgid()); +} diff --git a/otherlibs/unix/getgr.c b/otherlibs/unix/getgr.c new file mode 100644 index 0000000..be6151a --- /dev/null +++ b/otherlibs/unix/getgr.c @@ -0,0 +1,56 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getgr.c,v 1.12 2001-12-07 13:40:29 xleroy Exp $ */ + +#include <mlvalues.h> +#include <fail.h> +#include <alloc.h> +#include <memory.h> +#include "unixsupport.h" +#include <stdio.h> +#include <grp.h> + +static value alloc_group_entry(struct group *entry) +{ + value res; + value name = Val_unit, pass = Val_unit, mem = Val_unit; + + Begin_roots3 (name, pass, mem); + name = copy_string(entry->gr_name); + pass = copy_string(entry->gr_passwd); + mem = copy_string_array((const char**)entry->gr_mem); + res = alloc_small(4, 0); + Field(res,0) = name; + Field(res,1) = pass; + Field(res,2) = Val_int(entry->gr_gid); + Field(res,3) = mem; + End_roots(); + return res; +} + +CAMLprim value unix_getgrnam(value name) +{ + struct group * entry; + entry = getgrnam(String_val(name)); + if (entry == NULL) raise_not_found(); + return alloc_group_entry(entry); +} + +CAMLprim value unix_getgrgid(value gid) +{ + struct group * entry; + entry = getgrgid(Int_val(gid)); + if (entry == NULL) raise_not_found(); + return alloc_group_entry(entry); +} diff --git a/otherlibs/unix/getgroups.c b/otherlibs/unix/getgroups.c new file mode 100644 index 0000000..fd67241 --- /dev/null +++ b/otherlibs/unix/getgroups.c @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getgroups.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> + +#ifdef HAS_GETGROUPS + +#include <sys/types.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#include <limits.h> +#include "unixsupport.h" + +CAMLprim value unix_getgroups(value unit) +{ + gid_t gidset[NGROUPS_MAX]; + int n; + value res; + int i; + + n = getgroups(NGROUPS_MAX, gidset); + if (n == -1) uerror("getgroups", Nothing); + res = alloc_tuple(n); + for (i = 0; i < n; i++) + Field(res, i) = Val_int(gidset[i]); + return res; +} + +#else + +CAMLprim value unix_getgroups(value unit) +{ invalid_argument("getgroups not implemented"); } + +#endif diff --git a/otherlibs/unix/gethost.c b/otherlibs/unix/gethost.c new file mode 100644 index 0000000..2662cd6 --- /dev/null +++ b/otherlibs/unix/gethost.c @@ -0,0 +1,183 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gethost.c,v 1.27 2006-09-20 11:14:37 doligez Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" +#ifndef _WIN32 +#include <sys/types.h> +#include <netdb.h> +#endif + +#define NETDB_BUFFER_SIZE 10000 + +#ifdef _WIN32 +#define GETHOSTBYADDR_IS_REENTRANT 1 +#define GETHOSTBYNAME_IS_REENTRANT 1 +#endif + +static int entry_h_length; + +extern int socket_domain_table[]; + +static value alloc_one_addr(char const *a) +{ + struct in_addr addr; +#ifdef HAS_IPV6 + struct in6_addr addr6; + if (entry_h_length == 16) { + memmove(&addr6, a, 16); + return alloc_inet6_addr(&addr6); + } +#endif + memmove (&addr, a, 4); + return alloc_inet_addr(&addr); +} + +static value alloc_host_entry(struct hostent *entry) +{ + value res; + value name = Val_unit, aliases = Val_unit; + value addr_list = Val_unit, adr = Val_unit; + + Begin_roots4 (name, aliases, addr_list, adr); + name = copy_string((char *)(entry->h_name)); + /* PR#4043: protect against buggy implementations of gethostbyname() + that return a NULL pointer in h_aliases */ + if (entry->h_aliases) + aliases = copy_string_array((const char**)entry->h_aliases); + else + aliases = Atom(0); + entry_h_length = entry->h_length; +#ifdef h_addr + addr_list = alloc_array(alloc_one_addr, (const char**)entry->h_addr_list); +#else + adr = alloc_one_addr(entry->h_addr); + addr_list = alloc_small(1, 0); + Field(addr_list, 0) = adr; +#endif + res = alloc_small(4, 0); + Field(res, 0) = name; + Field(res, 1) = aliases; + switch (entry->h_addrtype) { + case PF_UNIX: Field(res, 2) = Val_int(0); break; + case PF_INET: Field(res, 2) = Val_int(1); break; + default: /*PF_INET6 */ Field(res, 2) = Val_int(2); break; + } + Field(res, 3) = addr_list; + End_roots(); + return res; +} + +CAMLprim value unix_gethostbyaddr(value a) +{ + struct in_addr adr = GET_INET_ADDR(a); + struct hostent * hp; +#if HAS_GETHOSTBYADDR_R == 7 + struct hostent h; + char buffer[NETDB_BUFFER_SIZE]; + int h_errnop; + enter_blocking_section(); + hp = gethostbyaddr_r((char *) &adr, 4, AF_INET, + &h, buffer, sizeof(buffer), &h_errnop); + leave_blocking_section(); +#elif HAS_GETHOSTBYADDR_R == 8 + struct hostent h; + char buffer[NETDB_BUFFER_SIZE]; + int h_errnop, rc; + enter_blocking_section(); + rc = gethostbyaddr_r((char *) &adr, 4, AF_INET, + &h, buffer, sizeof(buffer), &hp, &h_errnop); + leave_blocking_section(); + if (rc != 0) hp = NULL; +#else +#ifdef GETHOSTBYADDR_IS_REENTRANT + enter_blocking_section(); +#endif + hp = gethostbyaddr((char *) &adr, 4, AF_INET); +#ifdef GETHOSTBYADDR_IS_REENTRANT + leave_blocking_section(); +#endif +#endif + if (hp == (struct hostent *) NULL) raise_not_found(); + return alloc_host_entry(hp); +} + +CAMLprim value unix_gethostbyname(value name) +{ + struct hostent * hp; + char * hostname; + +#if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT + hostname = stat_alloc(string_length(name) + 1); + strcpy(hostname, String_val(name)); +#else + hostname = String_val(name); +#endif + +#if HAS_GETHOSTBYNAME_R == 5 + { + struct hostent h; + char buffer[NETDB_BUFFER_SIZE]; + int h_errno; + enter_blocking_section(); + hp = gethostbyname_r(hostname, &h, buffer, sizeof(buffer), &h_errno); + leave_blocking_section(); + } +#elif HAS_GETHOSTBYNAME_R == 6 + { + struct hostent h; + char buffer[NETDB_BUFFER_SIZE]; + int h_errno, rc; + enter_blocking_section(); + rc = gethostbyname_r(hostname, &h, buffer, sizeof(buffer), &hp, &h_errno); + leave_blocking_section(); + if (rc != 0) hp = NULL; + } +#else +#ifdef GETHOSTBYNAME_IS_REENTRANT + enter_blocking_section(); +#endif + hp = gethostbyname(hostname); +#ifdef GETHOSTBYNAME_IS_REENTRANT + leave_blocking_section(); +#endif +#endif + +#if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT + stat_free(hostname); +#endif + + if (hp == (struct hostent *) NULL) raise_not_found(); + return alloc_host_entry(hp); +} + +#else + +CAMLprim value unix_gethostbyaddr(value name) +{ invalid_argument("gethostbyaddr not implemented"); } + +CAMLprim value unix_gethostbyname(value name) +{ invalid_argument("gethostbyname not implemented"); } + +#endif diff --git a/otherlibs/unix/gethostname.c b/otherlibs/unix/gethostname.c new file mode 100644 index 0000000..b364997 --- /dev/null +++ b/otherlibs/unix/gethostname.c @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gethostname.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#if defined (_WIN32) +#include <winsock.h> +#else +#include <sys/param.h> +#endif +#include "unixsupport.h" + +#ifdef HAS_GETHOSTNAME + +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 256 +#endif + +CAMLprim value unix_gethostname(value unit) +{ + char name[MAXHOSTNAMELEN]; + gethostname(name, MAXHOSTNAMELEN); + name[MAXHOSTNAMELEN-1] = 0; + return copy_string(name); +} + +#else +#ifdef HAS_UNAME + +#include <sys/utsname.h> + +CAMLprim value unix_gethostname(value unit) +{ + struct utsname un; + uname(&un); + return copy_string(un.nodename); +} + +#else + +CAMLprim value unix_gethostname(value unit) +{ invalid_argument("gethostname not implemented"); } + +#endif +#endif diff --git a/otherlibs/unix/getlogin.c b/otherlibs/unix/getlogin.c new file mode 100644 index 0000000..9f4ce57 --- /dev/null +++ b/otherlibs/unix/getlogin.c @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getlogin.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" +#include <errno.h> + +extern char * getlogin(void); + +CAMLprim value unix_getlogin(value unit) +{ + char * name; + name = getlogin(); + if (name == NULL) unix_error(ENOENT, "getlogin", Nothing); + return copy_string(name); +} diff --git a/otherlibs/unix/getnameinfo.c b/otherlibs/unix/getnameinfo.c new file mode 100644 index 0000000..3070171 --- /dev/null +++ b/otherlibs/unix/getnameinfo.c @@ -0,0 +1,67 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2004 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getnameinfo.c,v 1.2 2005-03-24 17:20:53 doligez Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#if defined(HAS_SOCKETS) && defined(HAS_IPV6) + +#include "socketaddr.h" +#ifndef _WIN32 +#include <sys/types.h> +#include <netdb.h> +#endif + +static int getnameinfo_flag_table[] = { + NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD, NI_NUMERICSERV, NI_DGRAM +}; + +CAMLprim value unix_getnameinfo(value vaddr, value vopts) +{ + CAMLparam0(); + CAMLlocal3(vhost, vserv, vres); + union sock_addr_union addr; + socklen_param_type addr_len; + char host[4096]; + char serv[1024]; + int opts, retcode; + + get_sockaddr(vaddr, &addr, &addr_len); + opts = convert_flag_list(vopts, getnameinfo_flag_table); + enter_blocking_section(); + retcode = + getnameinfo((const struct sockaddr *) &addr.s_gen, addr_len, + host, sizeof(host), serv, sizeof(serv), opts); + leave_blocking_section(); + if (retcode != 0) raise_not_found(); /* TODO: detailed error reporting? */ + vhost = copy_string(host); + vserv = copy_string(serv); + vres = alloc_small(2, 0); + Field(vres, 0) = vhost; + Field(vres, 1) = vserv; + CAMLreturn(vres); +} + +#else + +CAMLprim value unix_getnameinfo(value vaddr, value vopts) +{ invalid_argument("getnameinfo not implemented"); } + +#endif diff --git a/otherlibs/unix/getpeername.c b/otherlibs/unix/getpeername.c new file mode 100644 index 0000000..4e9035d --- /dev/null +++ b/otherlibs/unix/getpeername.c @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getpeername.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_getpeername(value sock) +{ + int retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + + addr_len = sizeof(addr); + retcode = getpeername(Int_val(sock), &addr.s_gen, &addr_len); + if (retcode == -1) uerror("getpeername", Nothing); + return alloc_sockaddr(&addr, addr_len, -1); +} + +#else + +CAMLprim value unix_getpeername(value sock) +{ invalid_argument("getpeername not implemented"); } + +#endif diff --git a/otherlibs/unix/getpid.c b/otherlibs/unix/getpid.c new file mode 100644 index 0000000..4388d94 --- /dev/null +++ b/otherlibs/unix/getpid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getpid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_getpid(value unit) +{ + return Val_int(getpid()); +} diff --git a/otherlibs/unix/getppid.c b/otherlibs/unix/getppid.c new file mode 100644 index 0000000..5bd4658 --- /dev/null +++ b/otherlibs/unix/getppid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getppid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_getppid(value unit) +{ + return Val_int(getppid()); +} diff --git a/otherlibs/unix/getproto.c b/otherlibs/unix/getproto.c new file mode 100644 index 0000000..af1b824 --- /dev/null +++ b/otherlibs/unix/getproto.c @@ -0,0 +1,70 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getproto.c,v 1.13 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#ifndef _WIN32 +#include <netdb.h> +#else +#include <winsock.h> +#endif + +static value alloc_proto_entry(struct protoent *entry) +{ + value res; + value name = Val_unit, aliases = Val_unit; + + Begin_roots2 (name, aliases); + name = copy_string(entry->p_name); + aliases = copy_string_array((const char**)entry->p_aliases); + res = alloc_small(3, 0); + Field(res,0) = name; + Field(res,1) = aliases; + Field(res,2) = Val_int(entry->p_proto); + End_roots(); + return res; +} + +CAMLprim value unix_getprotobyname(value name) +{ + struct protoent * entry; + entry = getprotobyname(String_val(name)); + if (entry == (struct protoent *) NULL) raise_not_found(); + return alloc_proto_entry(entry); +} + +CAMLprim value unix_getprotobynumber(value proto) +{ + struct protoent * entry; + entry = getprotobynumber(Int_val(proto)); + if (entry == (struct protoent *) NULL) raise_not_found(); + return alloc_proto_entry(entry); +} + +#else + +CAMLprim value unix_getprotobynumber(value proto) +{ invalid_argument("getprotobynumber not implemented"); } + +CAMLprim value unix_getprotobyname(value name) +{ invalid_argument("getprotobyname not implemented"); } + +#endif diff --git a/otherlibs/unix/getpw.c b/otherlibs/unix/getpw.c new file mode 100644 index 0000000..e36a103 --- /dev/null +++ b/otherlibs/unix/getpw.c @@ -0,0 +1,65 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getpw.c,v 1.12 2001-12-07 13:40:30 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <fail.h> +#include "unixsupport.h" +#include <pwd.h> + +static value alloc_passwd_entry(struct passwd *entry) +{ + value res; + value name = Val_unit, passwd = Val_unit, gecos = Val_unit; + value dir = Val_unit, shell = Val_unit; + + Begin_roots5 (name, passwd, gecos, dir, shell); + name = copy_string(entry->pw_name); + passwd = copy_string(entry->pw_passwd); +#ifndef __BEOS__ + gecos = copy_string(entry->pw_gecos); +#else + gecos = copy_string(""); +#endif + dir = copy_string(entry->pw_dir); + shell = copy_string(entry->pw_shell); + res = alloc_small(7, 0); + Field(res,0) = name; + Field(res,1) = passwd; + Field(res,2) = Val_int(entry->pw_uid); + Field(res,3) = Val_int(entry->pw_gid); + Field(res,4) = gecos; + Field(res,5) = dir; + Field(res,6) = shell; + End_roots(); + return res; +} + +CAMLprim value unix_getpwnam(value name) +{ + struct passwd * entry; + entry = getpwnam(String_val(name)); + if (entry == (struct passwd *) NULL) raise_not_found(); + return alloc_passwd_entry(entry); +} + +CAMLprim value unix_getpwuid(value uid) +{ + struct passwd * entry; + entry = getpwuid(Int_val(uid)); + if (entry == (struct passwd *) NULL) raise_not_found(); + return alloc_passwd_entry(entry); +} diff --git a/otherlibs/unix/getserv.c b/otherlibs/unix/getserv.c new file mode 100644 index 0000000..1faa2ed --- /dev/null +++ b/otherlibs/unix/getserv.c @@ -0,0 +1,76 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getserv.c,v 1.14 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <sys/types.h> + +#ifndef _WIN32 +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#else +#include <winsock.h> +#endif + +static value alloc_service_entry(struct servent *entry) +{ + value res; + value name = Val_unit, aliases = Val_unit, proto = Val_unit; + + Begin_roots3 (name, aliases, proto); + name = copy_string(entry->s_name); + aliases = copy_string_array((const char**)entry->s_aliases); + proto = copy_string(entry->s_proto); + res = alloc_small(4, 0); + Field(res,0) = name; + Field(res,1) = aliases; + Field(res,2) = Val_int(ntohs(entry->s_port)); + Field(res,3) = proto; + End_roots(); + return res; +} + +CAMLprim value unix_getservbyname(value name, value proto) +{ + struct servent * entry; + entry = getservbyname(String_val(name), String_val(proto)); + if (entry == (struct servent *) NULL) raise_not_found(); + return alloc_service_entry(entry); +} + +CAMLprim value unix_getservbyport(value port, value proto) +{ + struct servent * entry; + entry = getservbyport(htons(Int_val(port)), String_val(proto)); + if (entry == (struct servent *) NULL) raise_not_found(); + return alloc_service_entry(entry); +} + +#else + +CAMLprim value unix_getservbyport(value port, value proto) +{ invalid_argument("getservbyport not implemented"); } + +CAMLprim value unix_getservbyname(value name, value proto) +{ invalid_argument("getservbyname not implemented"); } + +#endif diff --git a/otherlibs/unix/getsockname.c b/otherlibs/unix/getsockname.c new file mode 100644 index 0000000..976aa97 --- /dev/null +++ b/otherlibs/unix/getsockname.c @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getsockname.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_getsockname(value sock) +{ + int retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + + addr_len = sizeof(addr); + retcode = getsockname(Int_val(sock), &addr.s_gen, &addr_len); + if (retcode == -1) uerror("getsockname", Nothing); + return alloc_sockaddr(&addr, addr_len, -1); +} + +#else + +CAMLprim value unix_getsockname(value sock) +{ invalid_argument("getsockname not implemented"); } + +#endif diff --git a/otherlibs/unix/gettimeofday.c b/otherlibs/unix/gettimeofday.c new file mode 100644 index 0000000..8edb2a2 --- /dev/null +++ b/otherlibs/unix/gettimeofday.c @@ -0,0 +1,38 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gettimeofday.c,v 1.8 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_GETTIMEOFDAY + +#include <sys/types.h> +#include <sys/time.h> + +CAMLprim value unix_gettimeofday(value unit) +{ + struct timeval tp; + if (gettimeofday(&tp, NULL) == -1) uerror("gettimeofday", Nothing); + return copy_double((double) tp.tv_sec + (double) tp.tv_usec / 1e6); +} + +#else + +CAMLprim value unix_gettimeofday(value unit) +{ invalid_argument("gettimeofday not implemented"); } + +#endif diff --git a/otherlibs/unix/getuid.c b/otherlibs/unix/getuid.c new file mode 100644 index 0000000..16ef86b --- /dev/null +++ b/otherlibs/unix/getuid.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getuid.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_getuid(value unit) +{ + return Val_int(getuid()); +} diff --git a/otherlibs/unix/gmtime.c b/otherlibs/unix/gmtime.c new file mode 100644 index 0000000..bd566eb --- /dev/null +++ b/otherlibs/unix/gmtime.c @@ -0,0 +1,95 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gmtime.c,v 1.17 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include "unixsupport.h" +#include <time.h> +#include <errno.h> + +static value alloc_tm(struct tm *tm) +{ + value res; + res = alloc_small(9, 0); + Field(res,0) = Val_int(tm->tm_sec); + Field(res,1) = Val_int(tm->tm_min); + Field(res,2) = Val_int(tm->tm_hour); + Field(res,3) = Val_int(tm->tm_mday); + Field(res,4) = Val_int(tm->tm_mon); + Field(res,5) = Val_int(tm->tm_year); + Field(res,6) = Val_int(tm->tm_wday); + Field(res,7) = Val_int(tm->tm_yday); + Field(res,8) = tm->tm_isdst ? Val_true : Val_false; + return res; +} + +CAMLprim value unix_gmtime(value t) +{ + time_t clock; + struct tm * tm; + clock = (time_t) Double_val(t); + tm = gmtime(&clock); + if (tm == NULL) unix_error(EINVAL, "gmtime", Nothing); + return alloc_tm(tm); +} + +CAMLprim value unix_localtime(value t) +{ + time_t clock; + struct tm * tm; + clock = (time_t) Double_val(t); + tm = localtime(&clock); + if (tm == NULL) unix_error(EINVAL, "localtime", Nothing); + return alloc_tm(tm); +} + +#ifdef HAS_MKTIME + +CAMLprim value unix_mktime(value t) +{ + struct tm tm; + time_t clock; + value res; + value tmval = Val_unit, clkval = Val_unit; + + Begin_roots2(tmval, clkval); + tm.tm_sec = Int_val(Field(t, 0)); + tm.tm_min = Int_val(Field(t, 1)); + tm.tm_hour = Int_val(Field(t, 2)); + tm.tm_mday = Int_val(Field(t, 3)); + tm.tm_mon = Int_val(Field(t, 4)); + tm.tm_year = Int_val(Field(t, 5)); + tm.tm_wday = Int_val(Field(t, 6)); + tm.tm_yday = Int_val(Field(t, 7)); + tm.tm_isdst = -1; /* tm.tm_isdst = Bool_val(Field(t, 8)); */ + clock = mktime(&tm); + if (clock == (time_t) -1) unix_error(ERANGE, "mktime", Nothing); + tmval = alloc_tm(&tm); + clkval = copy_double((double) clock); + res = alloc_small(2, 0); + Field(res, 0) = clkval; + Field(res, 1) = tmval; + End_roots (); + return res; +} + +#else + +CAMLprim value unix_mktime(value t) +{ invalid_argument("mktime not implemented"); } + +#endif diff --git a/otherlibs/unix/isatty.c b/otherlibs/unix/isatty.c new file mode 100644 index 0000000..e6f81d0 --- /dev/null +++ b/otherlibs/unix/isatty.c @@ -0,0 +1,22 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Gallium, INRIA Rocquencourt */ +/* */ +/* Copyright 2006 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: isatty.c,v 1.1 2006-09-21 13:54:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_isatty(value fd) +{ + return (Val_bool(isatty(Int_val(fd)))); +} diff --git a/otherlibs/unix/itimer.c b/otherlibs/unix/itimer.c new file mode 100644 index 0000000..5f77cf2 --- /dev/null +++ b/otherlibs/unix/itimer.c @@ -0,0 +1,75 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: itimer.c,v 1.14 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include "unixsupport.h" + +#ifdef HAS_SETITIMER + +#include <math.h> +#include <sys/time.h> + +static void unix_set_timeval(struct timeval * tv, double d) +{ + double integr, frac; + frac = modf(d, &integr); + /* Round time up so that if d is small but not 0, we end up with + a non-0 timeval. */ + tv->tv_sec = integr; + tv->tv_usec = ceil(1e6 * frac); + if (tv->tv_usec >= 1000000) { tv->tv_sec++; tv->tv_usec = 0; } +} + +static value unix_convert_itimer(struct itimerval *tp) +{ +#define Get_timeval(tv) (double) tv.tv_sec + (double) tv.tv_usec / 1e6 + value res = alloc_small(Double_wosize * 2, Double_array_tag); + Store_double_field(res, 0, Get_timeval(tp->it_interval)); + Store_double_field(res, 1, Get_timeval(tp->it_value)); + return res; +#undef Get_timeval +} + +static int itimers[3] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF }; + +CAMLprim value unix_setitimer(value which, value newval) +{ + struct itimerval new, old; + unix_set_timeval(&new.it_interval, Double_field(newval, 0)); + unix_set_timeval(&new.it_value, Double_field(newval, 1)); + if (setitimer(itimers[Int_val(which)], &new, &old) == -1) + uerror("setitimer", Nothing); + return unix_convert_itimer(&old); +} + +CAMLprim value unix_getitimer(value which) +{ + struct itimerval val; + if (getitimer(itimers[Int_val(which)], &val) == -1) + uerror("getitimer", Nothing); + return unix_convert_itimer(&val); +} + +#else + +CAMLprim value unix_setitimer(value which, value newval) +{ invalid_argument("setitimer not implemented"); } +CAMLprim value unix_getitimer(value which) +{ invalid_argument("getitimer not implemented"); } + +#endif diff --git a/otherlibs/unix/kill.c b/otherlibs/unix/kill.c new file mode 100644 index 0000000..8400a56 --- /dev/null +++ b/otherlibs/unix/kill.c @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: kill.c,v 1.10 2001-12-07 13:40:31 xleroy Exp $ */ + +#include <mlvalues.h> +#include <fail.h> +#include "unixsupport.h" +#include <signal.h> +#include <signals.h> + +CAMLprim value unix_kill(value pid, value signal) +{ + int sig; + sig = convert_signal_number(Int_val(signal)); + if (kill(Int_val(pid), sig) == -1) + uerror("kill", Nothing); + return Val_unit; +} diff --git a/otherlibs/unix/libunix.clib b/otherlibs/unix/libunix.clib new file mode 100644 index 0000000..e6ce2d5 --- /dev/null +++ b/otherlibs/unix/libunix.clib @@ -0,0 +1,16 @@ +accept.o access.o addrofstr.o alarm.o bind.o chdir.o chmod.o +chown.o chroot.o close.o closedir.o connect.o cst2constr.o cstringv.o +dup.o dup2.o envir.o errmsg.o execv.o execve.o execvp.o exit.o +fchmod.o fchown.o fcntl.o fork.o ftruncate.o +getaddrinfo.o getcwd.o getegid.o geteuid.o getgid.o +getgr.o getgroups.o gethost.o gethostname.o getlogin.o +getnameinfo.o getpeername.o getpid.o getppid.o getproto.o getpw.o +gettimeofday.o getserv.o getsockname.o getuid.o +gmtime.o isatty.o itimer.o kill.o link.o listen.o lockf.o lseek.o mkdir.o +mkfifo.o nice.o open.o opendir.o pipe.o putenv.o read.o +readdir.o readlink.o rename.o rewinddir.o rmdir.o select.o sendrecv.o +setgid.o setsid.o setuid.o shutdown.o signals.o +sleep.o socket.o socketaddr.o +socketpair.o sockopt.o stat.o strofaddr.o symlink.o termios.o +time.o times.o truncate.o umask.o unixsupport.o unlink.o +utimes.o wait.o write.o diff --git a/otherlibs/unix/link.c b/otherlibs/unix/link.c new file mode 100644 index 0000000..34130c7 --- /dev/null +++ b/otherlibs/unix/link.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: link.c,v 1.8 2001-12-07 13:40:31 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_link(value path1, value path2) +{ + if (link(String_val(path1), String_val(path2)) == -1) uerror("link", path2); + return Val_unit; +} diff --git a/otherlibs/unix/listen.c b/otherlibs/unix/listen.c new file mode 100644 index 0000000..d381ed3 --- /dev/null +++ b/otherlibs/unix/listen.c @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: listen.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <sys/socket.h> + +CAMLprim value unix_listen(value sock, value backlog) +{ + if (listen(Int_val(sock), Int_val(backlog)) == -1) uerror("listen", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_listen(value sock, value backlog) +{ invalid_argument("listen not implemented"); } + +#endif diff --git a/otherlibs/unix/lockf.c b/otherlibs/unix/lockf.c new file mode 100644 index 0000000..46ac8e2 --- /dev/null +++ b/otherlibs/unix/lockf.c @@ -0,0 +1,116 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: lockf.c,v 1.14 2005-03-24 17:20:53 doligez Exp $ */ + +#include <errno.h> +#include <fcntl.h> +#include <fail.h> +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +#if defined(F_GETLK) && defined(F_SETLK) && defined(F_SETLKW) + +CAMLprim value unix_lockf(value fd, value cmd, value span) +{ + struct flock l; + int ret; + int fildes; + long size; + + fildes = Int_val(fd); + size = Long_val(span); + l.l_whence = 1; + if (size < 0) { + l.l_start = size; + l.l_len = -size; + } else { + l.l_start = 0L; + l.l_len = size; + } + switch (Int_val(cmd)) { + case 0: /* F_ULOCK */ + l.l_type = F_UNLCK; + ret = fcntl(fildes, F_SETLK, &l); + break; + case 1: /* F_LOCK */ + l.l_type = F_WRLCK; + enter_blocking_section(); + ret = fcntl(fildes, F_SETLKW, &l); + leave_blocking_section(); + break; + case 2: /* F_TLOCK */ + l.l_type = F_WRLCK; + ret = fcntl(fildes, F_SETLK, &l); + break; + case 3: /* F_TEST */ + l.l_type = F_WRLCK; + ret = fcntl(fildes, F_GETLK, &l); + if (ret != -1) { + if (l.l_type == F_UNLCK) + ret = 0; + else { + errno = EACCES; + ret = -1; + } + } + break; + case 4: /* F_RLOCK */ + l.l_type = F_RDLCK; + enter_blocking_section(); + ret = fcntl(fildes, F_SETLKW, &l); + leave_blocking_section(); + break; + case 5: /* F_TRLOCK */ + l.l_type = F_RDLCK; + ret = fcntl(fildes, F_SETLK, &l); + break; + default: + errno = EINVAL; + ret = -1; + } + if (ret == -1) uerror("lockf", Nothing); + return Val_unit; +} + +#else + +#ifdef HAS_LOCKF +#ifdef HAS_UNISTD +#include <unistd.h> +#else +#define F_ULOCK 0 +#define F_LOCK 1 +#define F_TLOCK 2 +#define F_TEST 3 +#endif + +static int lock_command_table[] = { + F_ULOCK, F_LOCK, F_TLOCK, F_TEST, F_LOCK, F_TLOCK +}; + +CAMLprim value unix_lockf(value fd, value cmd, value span) +{ + if (lockf(Int_val(fd), lock_command_table[Int_val(cmd)], Long_val(span)) + == -1) uerror("lockf", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_lockf(value fd, value cmd, value span) +{ invalid_argument("lockf not implemented"); } + +#endif +#endif diff --git a/otherlibs/unix/lseek.c b/otherlibs/unix/lseek.c new file mode 100644 index 0000000..c67c892 --- /dev/null +++ b/otherlibs/unix/lseek.c @@ -0,0 +1,57 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: lseek.c,v 1.10 2002-03-02 09:16:36 xleroy Exp $ */ + +#include <errno.h> +#include <sys/types.h> +#include <mlvalues.h> +#include <alloc.h> +#include <io.h> +#include "unixsupport.h" + +#ifdef HAS_UNISTD +#include <unistd.h> +#else +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif + +static int seek_command_table[] = { + SEEK_SET, SEEK_CUR, SEEK_END +}; + +CAMLprim value unix_lseek(value fd, value ofs, value cmd) +{ + file_offset ret; + ret = lseek(Int_val(fd), Long_val(ofs), + seek_command_table[Int_val(cmd)]); + if (ret == -1) uerror("lseek", Nothing); + if (ret > Max_long) unix_error(EOVERFLOW, "lseek", Nothing); + return Val_long(ret); +} + +CAMLprim value unix_lseek_64(value fd, value ofs, value cmd) +{ + file_offset ret; + ret = lseek(Int_val(fd), File_offset_val(ofs), + seek_command_table[Int_val(cmd)]); + if (ret == -1) uerror("lseek", Nothing); + return Val_file_offset(ret); +} + diff --git a/otherlibs/unix/mkdir.c b/otherlibs/unix/mkdir.c new file mode 100644 index 0000000..b3d8737 --- /dev/null +++ b/otherlibs/unix/mkdir.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mkdir.c,v 1.9 2001-12-07 13:40:31 xleroy Exp $ */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_mkdir(value path, value perm) +{ + if (mkdir(String_val(path), Int_val(perm)) == -1) uerror("mkdir", path); + return Val_unit; +} diff --git a/otherlibs/unix/mkfifo.c b/otherlibs/unix/mkfifo.c new file mode 100644 index 0000000..e8a48fa --- /dev/null +++ b/otherlibs/unix/mkfifo.c @@ -0,0 +1,53 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mkfifo.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_MKFIFO + +CAMLprim value unix_mkfifo(value path, value mode) +{ + if (mkfifo(String_val(path), Int_val(mode)) == -1) + uerror("mkfifo", path); + return Val_unit; +} + +#else + +#include <sys/types.h> +#include <sys/stat.h> + +#ifdef S_IFIFO + +CAMLprim value unix_mkfifo(value path, value mode) +{ + if (mknod(String_val(path), (Int_val(mode) & 07777) | S_IFIFO, 0) == -1) + uerror("mkfifo", path); + return Val_unit; +} + +#else + +CAMLprim value unix_mkfifo(value path, value mode) +{ + invalid_argument("mkfifo not implemented"); +} + +#endif +#endif diff --git a/otherlibs/unix/nice.c b/otherlibs/unix/nice.c new file mode 100644 index 0000000..cfe824d --- /dev/null +++ b/otherlibs/unix/nice.c @@ -0,0 +1,30 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: nice.c,v 1.11 2008-08-01 13:14:36 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" +#include <errno.h> +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +CAMLprim value unix_nice(value incr) +{ + int ret; + errno = 0; + ret = nice(Int_val(incr)); + if (ret == -1 && errno != 0) uerror("nice", Nothing); + return Val_int(ret); +} diff --git a/otherlibs/unix/open.c b/otherlibs/unix/open.c new file mode 100644 index 0000000..d7127eb --- /dev/null +++ b/otherlibs/unix/open.c @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: open.c,v 1.12 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" +#include <string.h> +#include <fcntl.h> + +#ifndef O_NONBLOCK +#define O_NONBLOCK O_NDELAY +#endif +#ifndef O_DSYNC +#define O_DSYNC 0 +#endif +#ifndef O_SYNC +#define O_SYNC 0 +#endif +#ifndef O_RSYNC +#define O_RSYNC 0 +#endif + +static int open_flag_table[] = { + O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL, + O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC +}; + +CAMLprim value unix_open(value path, value flags, value perm) +{ + CAMLparam3(path, flags, perm); + int ret, cv_flags; + char * p; + + cv_flags = convert_flag_list(flags, open_flag_table); + p = stat_alloc(string_length(path) + 1); + strcpy(p, String_val(path)); + /* open on a named FIFO can block (PR#1533) */ + enter_blocking_section(); + ret = open(p, cv_flags, Int_val(perm)); + leave_blocking_section(); + stat_free(p); + if (ret == -1) uerror("open", path); + CAMLreturn (Val_int(ret)); +} diff --git a/otherlibs/unix/opendir.c b/otherlibs/unix/opendir.c new file mode 100644 index 0000000..aea9a39 --- /dev/null +++ b/otherlibs/unix/opendir.c @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: opendir.c,v 1.9 2004-02-14 10:21:22 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" +#include <sys/types.h> +#ifdef HAS_DIRENT +#include <dirent.h> +#else +#include <sys/dir.h> +#endif + +CAMLprim value unix_opendir(value path) +{ + DIR * d; + value res; + d = opendir(String_val(path)); + if (d == (DIR *) NULL) uerror("opendir", path); + res = alloc_small(1, Abstract_tag); + DIR_Val(res) = d; + return res; +} diff --git a/otherlibs/unix/pipe.c b/otherlibs/unix/pipe.c new file mode 100644 index 0000000..05e4f9e --- /dev/null +++ b/otherlibs/unix/pipe.c @@ -0,0 +1,29 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: pipe.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +CAMLprim value unix_pipe(value unit) +{ + int fd[2]; + value res; + if (pipe(fd) == -1) uerror("pipe", Nothing); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(fd[0]); + Field(res, 1) = Val_int(fd[1]); + return res; +} diff --git a/otherlibs/unix/putenv.c b/otherlibs/unix/putenv.c new file mode 100644 index 0000000..b876693 --- /dev/null +++ b/otherlibs/unix/putenv.c @@ -0,0 +1,46 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: putenv.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <stdlib.h> +#include <string.h> + +#include <fail.h> +#include <memory.h> +#include <mlvalues.h> + +#include "unixsupport.h" + +#ifdef HAS_PUTENV + +CAMLprim value unix_putenv(value name, value val) +{ + mlsize_t namelen = string_length(name); + mlsize_t vallen = string_length(val); + char * s = (char *) stat_alloc(namelen + 1 + vallen + 1); + + memmove (s, String_val(name), namelen); + s[namelen] = '='; + memmove (s + namelen + 1, String_val(val), vallen); + s[namelen + 1 + vallen] = 0; + if (putenv(s) == -1) uerror("putenv", name); + return Val_unit; +} + +#else + +CAMLprim value unix_putenv(value name, value val) +{ invalid_argument("putenv not implemented"); } + +#endif diff --git a/otherlibs/unix/read.c b/otherlibs/unix/read.c new file mode 100644 index 0000000..9d7ce53 --- /dev/null +++ b/otherlibs/unix/read.c @@ -0,0 +1,38 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: read.c,v 1.13 2001-12-07 13:40:32 xleroy Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_read(value fd, value buf, value ofs, value len) +{ + long numbytes; + int ret; + char iobuf[UNIX_BUFFER_SIZE]; + + Begin_root (buf); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + enter_blocking_section(); + ret = read(Int_val(fd), iobuf, (int) numbytes); + leave_blocking_section(); + if (ret == -1) uerror("read", Nothing); + memmove (&Byte(buf, Long_val(ofs)), iobuf, ret); + End_roots(); + return Val_int(ret); +} diff --git a/otherlibs/unix/readdir.c b/otherlibs/unix/readdir.c new file mode 100644 index 0000000..a958b29 --- /dev/null +++ b/otherlibs/unix/readdir.c @@ -0,0 +1,39 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: readdir.c,v 1.12 2004-02-14 10:21:23 xleroy Exp $ */ + +#include <mlvalues.h> +#include <fail.h> +#include <alloc.h> +#include "unixsupport.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAS_DIRENT +#include <dirent.h> +typedef struct dirent directory_entry; +#else +#include <sys/dir.h> +typedef struct direct directory_entry; +#endif + +CAMLprim value unix_readdir(value vd) +{ + DIR * d; + directory_entry * e; + d = DIR_Val(vd); + if (d == (DIR *) NULL) unix_error(EBADF, "readdir", Nothing); + e = readdir((DIR *) d); + if (e == (directory_entry *) NULL) raise_end_of_file(); + return copy_string(e->d_name); +} diff --git a/otherlibs/unix/readlink.c b/otherlibs/unix/readlink.c new file mode 100644 index 0000000..3478583 --- /dev/null +++ b/otherlibs/unix/readlink.c @@ -0,0 +1,48 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: readlink.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> + +#ifdef HAS_SYMLINK + +#include <sys/param.h> +#include "unixsupport.h" + +#ifndef PATH_MAX +#ifdef MAXPATHLEN +#define PATH_MAX MAXPATHLEN +#else +#define PATH_MAX 512 +#endif +#endif + +CAMLprim value unix_readlink(value path) +{ + char buffer[PATH_MAX]; + int len; + len = readlink(String_val(path), buffer, sizeof(buffer) - 1); + if (len == -1) uerror("readlink", path); + buffer[len] = '\0'; + return copy_string(buffer); +} + +#else + +CAMLprim value unix_readlink(value path) +{ invalid_argument("readlink not implemented"); } + +#endif diff --git a/otherlibs/unix/rename.c b/otherlibs/unix/rename.c new file mode 100644 index 0000000..44fd705 --- /dev/null +++ b/otherlibs/unix/rename.c @@ -0,0 +1,25 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: rename.c,v 1.10 2001-12-07 13:40:33 xleroy Exp $ */ + +#include <stdio.h> +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_rename(value path1, value path2) +{ + if (rename(String_val(path1), String_val(path2)) == -1) + uerror("rename", path1); + return Val_unit; +} diff --git a/otherlibs/unix/rewinddir.c b/otherlibs/unix/rewinddir.c new file mode 100644 index 0000000..708089b --- /dev/null +++ b/otherlibs/unix/rewinddir.c @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: rewinddir.c,v 1.12 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAS_DIRENT +#include <dirent.h> +#else +#include <sys/dir.h> +#endif + +#ifdef HAS_REWINDDIR + +CAMLprim value unix_rewinddir(value vd) +{ + DIR * d = DIR_Val(vd); + if (d == (DIR *) NULL) unix_error(EBADF, "rewinddir", Nothing); + rewinddir(d); + return Val_unit; +} + +#else + +CAMLprim value unix_rewinddir(value d) +{ invalid_argument("rewinddir not implemented"); } + +#endif diff --git a/otherlibs/unix/rmdir.c b/otherlibs/unix/rmdir.c new file mode 100644 index 0000000..ecc637b --- /dev/null +++ b/otherlibs/unix/rmdir.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: rmdir.c,v 1.9 2001-12-07 13:40:33 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_rmdir(value path) +{ + if (rmdir(String_val(path)) == -1) uerror("rmdir", path); + return Val_unit; +} diff --git a/otherlibs/unix/select.c b/otherlibs/unix/select.c new file mode 100644 index 0000000..a77ae9d --- /dev/null +++ b/otherlibs/unix/select.c @@ -0,0 +1,110 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: select.c,v 1.22 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#ifdef HAS_SELECT + +#include <sys/types.h> +#include <sys/time.h> +#ifdef HAS_SYS_SELECT_H +#include <sys/select.h> +#endif +#include <string.h> +#include <unistd.h> + +typedef fd_set file_descr_set; + +static void fdlist_to_fdset(value fdlist, fd_set *fdset, int *maxfd) +{ + value l; + FD_ZERO(fdset); + for (l = fdlist; l != Val_int(0); l = Field(l, 1)) { + int fd = Int_val(Field(l, 0)); + FD_SET(fd, fdset); + if (fd > *maxfd) *maxfd = fd; + } +} + +static value fdset_to_fdlist(value fdlist, fd_set *fdset) +{ + value l; + value res = Val_int(0); + + Begin_roots2(l, res); + for (l = fdlist; l != Val_int(0); l = Field(l, 1)) { + int fd = Int_val(Field(l, 0)); + if (FD_ISSET(fd, fdset)) { + value newres = alloc_small(2, 0); + Field(newres, 0) = Val_int(fd); + Field(newres, 1) = res; + res = newres; + } + } + End_roots(); + return res; +} + +CAMLprim value unix_select(value readfds, value writefds, value exceptfds, + value timeout) +{ + fd_set read, write, except; + int maxfd; + double tm; + struct timeval tv; + struct timeval * tvp; + int retcode; + value res; + + Begin_roots3 (readfds, writefds, exceptfds); + maxfd = -1; + fdlist_to_fdset(readfds, &read, &maxfd); + fdlist_to_fdset(writefds, &write, &maxfd); + fdlist_to_fdset(exceptfds, &except, &maxfd); + tm = Double_val(timeout); + if (tm < 0.0) + tvp = (struct timeval *) NULL; + else { + tv.tv_sec = (int) tm; + tv.tv_usec = (int) (1e6 * (tm - tv.tv_sec)); + tvp = &tv; + } + enter_blocking_section(); + retcode = select(maxfd + 1, &read, &write, &except, tvp); + leave_blocking_section(); + if (retcode == -1) uerror("select", Nothing); + readfds = fdset_to_fdlist(readfds, &read); + writefds = fdset_to_fdlist(writefds, &write); + exceptfds = fdset_to_fdlist(exceptfds, &except); + res = alloc_small(3, 0); + Field(res, 0) = readfds; + Field(res, 1) = writefds; + Field(res, 2) = exceptfds; + End_roots(); + return res; +} + +#else + +CAMLprim value unix_select(value readfds, value writefds, value exceptfds, + value timeout) +{ invalid_argument("select not implemented"); } + +#endif diff --git a/otherlibs/unix/sendrecv.c b/otherlibs/unix/sendrecv.c new file mode 100644 index 0000000..5855535 --- /dev/null +++ b/otherlibs/unix/sendrecv.c @@ -0,0 +1,148 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sendrecv.c,v 1.19 2005-03-24 17:20:53 doligez Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS +#include "socketaddr.h" + +static int msg_flag_table[] = { + MSG_OOB, MSG_DONTROUTE, MSG_PEEK +}; + +CAMLprim value unix_recv(value sock, value buff, value ofs, value len, + value flags) +{ + int ret, cv_flags; + long numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + + cv_flags = convert_flag_list(flags, msg_flag_table); + Begin_root (buff); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + enter_blocking_section(); + ret = recv(Int_val(sock), iobuf, (int) numbytes, cv_flags); + leave_blocking_section(); + if (ret == -1) uerror("recv", Nothing); + memmove (&Byte(buff, Long_val(ofs)), iobuf, ret); + End_roots(); + return Val_int(ret); +} + +CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len, + value flags) +{ + int ret, cv_flags; + long numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + value res; + value adr = Val_unit; + union sock_addr_union addr; + socklen_param_type addr_len; + + cv_flags = convert_flag_list(flags, msg_flag_table); + Begin_roots2 (buff, adr); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + addr_len = sizeof(addr); + enter_blocking_section(); + ret = recvfrom(Int_val(sock), iobuf, (int) numbytes, cv_flags, + &addr.s_gen, &addr_len); + leave_blocking_section(); + if (ret == -1) uerror("recvfrom", Nothing); + memmove (&Byte(buff, Long_val(ofs)), iobuf, ret); + adr = alloc_sockaddr(&addr, addr_len, -1); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(ret); + Field(res, 1) = adr; + End_roots(); + return res; +} + +CAMLprim value unix_send(value sock, value buff, value ofs, value len, + value flags) +{ + int ret, cv_flags; + long numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + + cv_flags = convert_flag_list(flags, msg_flag_table); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes); + enter_blocking_section(); + ret = send(Int_val(sock), iobuf, (int) numbytes, cv_flags); + leave_blocking_section(); + if (ret == -1) uerror("send", Nothing); + return Val_int(ret); +} + +CAMLprim value unix_sendto_native(value sock, value buff, value ofs, value len, + value flags, value dest) +{ + int ret, cv_flags; + long numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + union sock_addr_union addr; + socklen_param_type addr_len; + + cv_flags = convert_flag_list(flags, msg_flag_table); + get_sockaddr(dest, &addr, &addr_len); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes); + enter_blocking_section(); + ret = sendto(Int_val(sock), iobuf, (int) numbytes, cv_flags, + &addr.s_gen, addr_len); + leave_blocking_section(); + if (ret == -1) uerror("sendto", Nothing); + return Val_int(ret); +} + +CAMLprim value unix_sendto(value *argv, int argc) +{ + return unix_sendto_native + (argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); +} + +#else + +CAMLprim value unix_recv(value sock, value buff, value ofs, value len, + value flags) +{ invalid_argument("recv not implemented"); } + +CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len, + value flags) +{ invalid_argument("recvfrom not implemented"); } + +CAMLprim value unix_send(value sock, value buff, value ofs, value len, + value flags) +{ invalid_argument("send not implemented"); } + +CAMLprim value unix_sendto_native(value sock, value buff, value ofs, value len, + value flags, value dest) +{ invalid_argument("sendto not implemented"); } + +CAMLprim value unix_sendto(value *argv, int argc) +{ invalid_argument("sendto not implemented"); } + +#endif diff --git a/otherlibs/unix/setgid.c b/otherlibs/unix/setgid.c new file mode 100644 index 0000000..46b9f8f --- /dev/null +++ b/otherlibs/unix/setgid.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: setgid.c,v 1.8 2001-12-07 13:40:33 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_setgid(value gid) +{ + if (setgid(Int_val(gid)) == -1) uerror("setgid", Nothing); + return Val_unit; +} diff --git a/otherlibs/unix/setsid.c b/otherlibs/unix/setsid.c new file mode 100644 index 0000000..5f1b34d --- /dev/null +++ b/otherlibs/unix/setsid.c @@ -0,0 +1,31 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1997 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: setsid.c,v 1.6 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +CAMLprim value unix_setsid(value unit) +{ +#ifdef HAS_SETSID + return Val_int(setsid()); +#else + invalid_argument("setsid not implemented"); + return Val_unit; +#endif +} diff --git a/otherlibs/unix/setuid.c b/otherlibs/unix/setuid.c new file mode 100644 index 0000000..fc2f616 --- /dev/null +++ b/otherlibs/unix/setuid.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: setuid.c,v 1.8 2001-12-07 13:40:33 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_setuid(value uid) +{ + if (setuid(Int_val(uid)) == -1) uerror("setuid", Nothing); + return Val_unit; +} diff --git a/otherlibs/unix/shutdown.c b/otherlibs/unix/shutdown.c new file mode 100644 index 0000000..e391b69 --- /dev/null +++ b/otherlibs/unix/shutdown.c @@ -0,0 +1,40 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: shutdown.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <sys/socket.h> + +static int shutdown_command_table[] = { + 0, 1, 2 +}; + +CAMLprim value unix_shutdown(value sock, value cmd) +{ + if (shutdown(Int_val(sock), shutdown_command_table[Int_val(cmd)]) == -1) + uerror("shutdown", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_shutdown(value sock, value cmd) +{ invalid_argument("shutdown not implemented"); } + +#endif diff --git a/otherlibs/unix/signals.c b/otherlibs/unix/signals.c new file mode 100644 index 0000000..f1c15b2 --- /dev/null +++ b/otherlibs/unix/signals.c @@ -0,0 +1,106 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: signals.c,v 1.11 2008-01-11 16:13:16 doligez Exp $ */ + +#include <errno.h> +#include <signal.h> + +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +#ifndef NSIG +#define NSIG 64 +#endif + +#ifdef POSIX_SIGNALS + +static void decode_sigset(value vset, sigset_t * set) +{ + sigemptyset(set); + while (vset != Val_int(0)) { + int sig = caml_convert_signal_number(Int_val(Field(vset, 0))); + sigaddset(set, sig); + vset = Field(vset, 1); + } +} + +static value encode_sigset(sigset_t * set) +{ + value res = Val_int(0); + int i; + + Begin_root(res) + for (i = 1; i < NSIG; i++) + if (sigismember(set, i) > 0) { + value newcons = alloc_small(2, 0); + Field(newcons, 0) = Val_int(caml_rev_convert_signal_number(i)); + Field(newcons, 1) = res; + res = newcons; + } + End_roots(); + return res; +} + +static int sigprocmask_cmd[3] = { SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK }; + +CAMLprim value unix_sigprocmask(value vaction, value vset) +{ + int how; + sigset_t set, oldset; + int retcode; + + how = sigprocmask_cmd[Int_val(vaction)]; + decode_sigset(vset, &set); + enter_blocking_section(); + retcode = sigprocmask(how, &set, &oldset); + leave_blocking_section(); + if (retcode == -1) uerror("sigprocmask", Nothing); + return encode_sigset(&oldset); +} + +CAMLprim value unix_sigpending(value unit) +{ + sigset_t pending; + if (sigpending(&pending) == -1) uerror("sigpending", Nothing); + return encode_sigset(&pending); +} + +CAMLprim value unix_sigsuspend(value vset) +{ + sigset_t set; + int retcode; + decode_sigset(vset, &set); + enter_blocking_section(); + retcode = sigsuspend(&set); + leave_blocking_section(); + if (retcode == -1 && errno != EINTR) uerror("sigsuspend", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_sigprocmask(value vaction, value vset) +{ invalid_argument("Unix.sigprocmask not available"); } + +CAMLprim value unix_sigpending(value unit) +{ invalid_argument("Unix.sigpending not available"); } + +CAMLprim value unix_sigsuspend(value vset) +{ invalid_argument("Unix.sigsuspend not available"); } + +#endif diff --git a/otherlibs/unix/sleep.c b/otherlibs/unix/sleep.c new file mode 100644 index 0000000..db3dc3f --- /dev/null +++ b/otherlibs/unix/sleep.c @@ -0,0 +1,26 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sleep.c,v 1.9 2001-12-07 13:40:35 xleroy Exp $ */ + +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_sleep(value t) +{ + enter_blocking_section(); + sleep(Int_val(t)); + leave_blocking_section(); + return Val_unit; +} diff --git a/otherlibs/unix/socket.c b/otherlibs/unix/socket.c new file mode 100644 index 0000000..c9f32b6 --- /dev/null +++ b/otherlibs/unix/socket.c @@ -0,0 +1,56 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socket.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <sys/types.h> +#include <sys/socket.h> + +int socket_domain_table[] = { + PF_UNIX, PF_INET, +#if defined(HAS_IPV6) + PF_INET6 +#elif defined(PF_UNDEF) + PF_UNDEF +#else + 0 +#endif +}; + +int socket_type_table[] = { + SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET +}; + +CAMLprim value unix_socket(value domain, value type, value proto) +{ + int retcode; + retcode = socket(socket_domain_table[Int_val(domain)], + socket_type_table[Int_val(type)], + Int_val(proto)); + if (retcode == -1) uerror("socket", Nothing); + return Val_int(retcode); + +} + +#else + +CAMLprim value unix_socket(value domain, value type, value proto) +{ invalid_argument("socket not implemented"); } + +#endif diff --git a/otherlibs/unix/socketaddr.c b/otherlibs/unix/socketaddr.c new file mode 100644 index 0000000..b8c334e --- /dev/null +++ b/otherlibs/unix/socketaddr.c @@ -0,0 +1,138 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socketaddr.c,v 1.23 2005-03-24 17:20:53 doligez Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <errno.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +#ifdef _WIN32 +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif + +CAMLexport value alloc_inet_addr(struct in_addr * a) +{ + value res; + /* Use a string rather than an abstract block so that it can be + marshaled safely. Remember that a is in network byte order, + hence is marshaled in an endian-independent manner. */ + res = alloc_string(4); + memcpy(String_val(res), a, 4); + return res; +} + +#ifdef HAS_IPV6 + +CAMLexport value alloc_inet6_addr(struct in6_addr * a) +{ + value res; + res = alloc_string(16); + memcpy(String_val(res), a, 16); + return res; +} + +#endif + +void get_sockaddr(value mladr, + union sock_addr_union * adr /*out*/, + socklen_param_type * adr_len /*out*/) +{ + switch(Tag_val(mladr)) { +#ifndef _WIN32 + case 0: /* ADDR_UNIX */ + { value path; + mlsize_t len; + path = Field(mladr, 0); + len = string_length(path); + adr->s_unix.sun_family = AF_UNIX; + if (len >= sizeof(adr->s_unix.sun_path)) { + unix_error(ENAMETOOLONG, "", path); + } + memmove (adr->s_unix.sun_path, String_val(path), len + 1); + *adr_len = + ((char *)&(adr->s_unix.sun_path) - (char *)&(adr->s_unix)) + + len; + break; + } +#endif + case 1: /* ADDR_INET */ +#ifdef HAS_IPV6 + if (string_length(Field(mladr, 0)) == 16) { + memset(&adr->s_inet6, 0, sizeof(struct sockaddr_in6)); + adr->s_inet6.sin6_family = AF_INET6; + adr->s_inet6.sin6_addr = GET_INET6_ADDR(Field(mladr, 0)); + adr->s_inet6.sin6_port = htons(Int_val(Field(mladr, 1))); + *adr_len = sizeof(struct sockaddr_in6); + break; + } +#endif + memset(&adr->s_inet, 0, sizeof(struct sockaddr_in)); + adr->s_inet.sin_family = AF_INET; + adr->s_inet.sin_addr = GET_INET_ADDR(Field(mladr, 0)); + adr->s_inet.sin_port = htons(Int_val(Field(mladr, 1))); + *adr_len = sizeof(struct sockaddr_in); + break; + } +} + +value alloc_sockaddr(union sock_addr_union * adr /*in*/, + socklen_param_type adr_len, int close_on_error) +{ + value res; + switch(adr->s_gen.sa_family) { +#ifndef _WIN32 + case AF_UNIX: + { value n = copy_string(adr->s_unix.sun_path); + Begin_root (n); + res = alloc_small(1, 0); + Field(res,0) = n; + End_roots(); + break; + } +#endif + case AF_INET: + { value a = alloc_inet_addr(&adr->s_inet.sin_addr); + Begin_root (a); + res = alloc_small(2, 1); + Field(res,0) = a; + Field(res,1) = Val_int(ntohs(adr->s_inet.sin_port)); + End_roots(); + break; + } +#ifdef HAS_IPV6 + case AF_INET6: + { value a = alloc_inet6_addr(&adr->s_inet6.sin6_addr); + Begin_root (a); + res = alloc_small(2, 1); + Field(res,0) = a; + Field(res,1) = Val_int(ntohs(adr->s_inet6.sin6_port)); + End_roots(); + break; + } +#endif + default: + if (close_on_error != -1) close (close_on_error); + unix_error(EAFNOSUPPORT, "", Nothing); + } + return res; +} + +#endif diff --git a/otherlibs/unix/socketaddr.h b/otherlibs/unix/socketaddr.h new file mode 100644 index 0000000..93de35d --- /dev/null +++ b/otherlibs/unix/socketaddr.h @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socketaddr.h,v 1.16 2005-03-24 17:20:53 doligez Exp $ */ + +#include <misc.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +union sock_addr_union { + struct sockaddr s_gen; + struct sockaddr_un s_unix; + struct sockaddr_in s_inet; +#ifdef HAS_IPV6 + struct sockaddr_in6 s_inet6; +#endif +}; + +#ifdef HAS_SOCKLEN_T +typedef socklen_t socklen_param_type; +#else +typedef int socklen_param_type; +#endif + +extern void get_sockaddr (value mladdr, + union sock_addr_union * addr /*out*/, + socklen_param_type * addr_len /*out*/); +CAMLexport value alloc_sockaddr (union sock_addr_union * addr /*in*/, + socklen_param_type addr_len, int close_on_error); +CAMLexport value alloc_inet_addr (struct in_addr * inaddr); +#define GET_INET_ADDR(v) (*((struct in_addr *) (v))) + +#ifdef HAS_IPV6 +CAMLexport value alloc_inet6_addr (struct in6_addr * inaddr); +#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v))) +#endif diff --git a/otherlibs/unix/socketpair.c b/otherlibs/unix/socketpair.c new file mode 100644 index 0000000..0fc8e4c --- /dev/null +++ b/otherlibs/unix/socketpair.c @@ -0,0 +1,46 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socketpair.c,v 1.12 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <sys/socket.h> + +extern int socket_domain_table[], socket_type_table[]; + +CAMLprim value unix_socketpair(value domain, value type, value proto) +{ + int sv[2]; + value res; + if (socketpair(socket_domain_table[Int_val(domain)], + socket_type_table[Int_val(type)], + Int_val(proto), sv) == -1) + uerror("socketpair", Nothing); + res = alloc_small(2, 0); + Field(res,0) = Val_int(sv[0]); + Field(res,1) = Val_int(sv[1]); + return res; +} + +#else + +CAMLprim value unix_socketpair(value domain, value type, value proto) +{ invalid_argument("socketpair not implemented"); } + +#endif diff --git a/otherlibs/unix/sockopt.c b/otherlibs/unix/sockopt.c new file mode 100644 index 0000000..eb2f63e --- /dev/null +++ b/otherlibs/unix/sockopt.c @@ -0,0 +1,300 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sockopt.c,v 1.21 2008-08-01 13:46:08 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include <errno.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/tcp.h> + +#include "socketaddr.h" + +#ifndef SO_DEBUG +#define SO_DEBUG (-1) +#endif +#ifndef SO_BROADCAST +#define SO_BROADCAST (-1) +#endif +#ifndef SO_REUSEADDR +#define SO_REUSEADDR (-1) +#endif +#ifndef SO_KEEPALIVE +#define SO_KEEPALIVE (-1) +#endif +#ifndef SO_DONTROUTE +#define SO_DONTROUTE (-1) +#endif +#ifndef SO_OOBINLINE +#define SO_OOBINLINE (-1) +#endif +#ifndef SO_ACCEPTCONN +#define SO_ACCEPTCONN (-1) +#endif +#ifndef SO_SNDBUF +#define SO_SNDBUF (-1) +#endif +#ifndef SO_RCVBUF +#define SO_RCVBUF (-1) +#endif +#ifndef SO_ERROR +#define SO_ERROR (-1) +#endif +#ifndef SO_TYPE +#define SO_TYPE (-1) +#endif +#ifndef SO_RCVLOWAT +#define SO_RCVLOWAT (-1) +#endif +#ifndef SO_SNDLOWAT +#define SO_SNDLOWAT (-1) +#endif +#ifndef SO_LINGER +#define SO_LINGER (-1) +#endif +#ifndef SO_RCVTIMEO +#define SO_RCVTIMEO (-1) +#endif +#ifndef SO_SNDTIMEO +#define SO_SNDTIMEO (-1) +#endif +#ifndef TCP_NODELAY +#define TCP_NODELAY (-1) +#endif +#ifndef SO_ERROR +#define SO_ERROR (-1) +#endif +#ifndef IPPROTO_IPV6 +#define IPPROTO_IPV6 (-1) +#endif +#ifndef IPV6_V6ONLY +#define IPV6_V6ONLY (-1) +#endif + +enum option_type { + TYPE_BOOL = 0, + TYPE_INT = 1, + TYPE_LINGER = 2, + TYPE_TIMEVAL = 3, + TYPE_UNIX_ERROR = 4 +}; + +struct socket_option { + int level; + int option; +}; + +/* Table of options, indexed by type */ + +static struct socket_option sockopt_bool[] = { + { SOL_SOCKET, SO_DEBUG }, + { SOL_SOCKET, SO_BROADCAST }, + { SOL_SOCKET, SO_REUSEADDR }, + { SOL_SOCKET, SO_KEEPALIVE }, + { SOL_SOCKET, SO_DONTROUTE }, + { SOL_SOCKET, SO_OOBINLINE }, + { SOL_SOCKET, SO_ACCEPTCONN }, + { IPPROTO_TCP, TCP_NODELAY }, + { IPPROTO_IPV6, IPV6_V6ONLY} +}; + +static struct socket_option sockopt_int[] = { + { SOL_SOCKET, SO_SNDBUF }, + { SOL_SOCKET, SO_RCVBUF }, + { SOL_SOCKET, SO_ERROR }, + { SOL_SOCKET, SO_TYPE }, + { SOL_SOCKET, SO_RCVLOWAT }, + { SOL_SOCKET, SO_SNDLOWAT } }; + +static struct socket_option sockopt_linger[] = { + { SOL_SOCKET, SO_LINGER } +}; + +static struct socket_option sockopt_timeval[] = { + { SOL_SOCKET, SO_RCVTIMEO }, + { SOL_SOCKET, SO_SNDTIMEO } +}; + +static struct socket_option sockopt_unix_error[] = { + { SOL_SOCKET, SO_ERROR } +}; + +static struct socket_option * sockopt_table[] = { + sockopt_bool, + sockopt_int, + sockopt_linger, + sockopt_timeval, + sockopt_unix_error +}; + +static char * getsockopt_fun_name[] = { + "getsockopt", + "getsockopt_int", + "getsockopt_optint", + "getsockopt_float", + "getsockopt_error" +}; + +static char * setsockopt_fun_name[] = { + "setsockopt", + "setsockopt_int", + "setsockopt_optint", + "setsockopt_float", + "setsockopt_error" +}; + +union option_value { + int i; + struct linger lg; + struct timeval tv; +}; + +CAMLexport value +unix_getsockopt_aux(char * name, + enum option_type ty, int level, int option, + value socket) +{ + union option_value optval; + socklen_param_type optsize; + + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + case TYPE_UNIX_ERROR: + optsize = sizeof(optval.i); break; + case TYPE_LINGER: + optsize = sizeof(optval.lg); break; + case TYPE_TIMEVAL: + optsize = sizeof(optval.tv); break; + default: + unix_error(EINVAL, name, Nothing); + } + + if (getsockopt(Int_val(socket), level, option, + (void *) &optval, &optsize) == -1) + uerror(name, Nothing); + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + return Val_int(optval.i); + case TYPE_LINGER: + if (optval.lg.l_onoff == 0) { + return Val_int(0); /* None */ + } else { + value res = alloc_small(1, 0); /* Some */ + Field(res, 0) = Val_int(optval.lg.l_linger); + return res; + } + case TYPE_TIMEVAL: + return copy_double((double) optval.tv.tv_sec + + (double) optval.tv.tv_usec / 1e6); + case TYPE_UNIX_ERROR: + if (optval.i == 0) { + return Val_int(0); /* None */ + } else { + value err, res; + err = unix_error_of_code(optval.i); + Begin_root(err); + res = alloc_small(1, 0); /* Some */ + Field(res, 0) = err; + End_roots(); + return res; + } + default: + unix_error(EINVAL, name, Nothing); + } +} + +CAMLexport value +unix_setsockopt_aux(char * name, + enum option_type ty, int level, int option, + value socket, value val) +{ + union option_value optval; + socklen_param_type optsize; + double f; + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + optsize = sizeof(optval.i); + optval.i = Int_val(val); + break; + case TYPE_LINGER: + optsize = sizeof(optval.lg); + optval.lg.l_onoff = Is_block (val); + if (optval.lg.l_onoff) + optval.lg.l_linger = Int_val (Field (val, 0)); + break; + case TYPE_TIMEVAL: + f = Double_val(val); + optsize = sizeof(optval.tv); + optval.tv.tv_sec = (int) f; + optval.tv.tv_usec = (int) (1e6 * (f - optval.tv.tv_sec)); + break; + case TYPE_UNIX_ERROR: + default: + unix_error(EINVAL, name, Nothing); + } + + if (setsockopt(Int_val(socket), level, option, + (void *) &optval, optsize) == -1) + uerror(name, Nothing); + + return Val_unit; +} + +CAMLprim value unix_getsockopt(value vty, value vsocket, value voption) +{ + enum option_type ty = Int_val(vty); + struct socket_option * opt = &(sockopt_table[ty][Int_val(voption)]); + return unix_getsockopt_aux(getsockopt_fun_name[ty], + ty, + opt->level, + opt->option, + vsocket); +} + +CAMLprim value unix_setsockopt(value vty, value vsocket, value voption, + value val) +{ + enum option_type ty = Int_val(vty); + struct socket_option * opt = &(sockopt_table[ty][Int_val(voption)]); + return unix_setsockopt_aux(setsockopt_fun_name[ty], + ty, + opt->level, + opt->option, + vsocket, + val); +} + +#else + +CAMLprim value unix_getsockopt(value vty, value socket, value option) +{ invalid_argument("getsockopt not implemented"); } + +CAMLprim value unix_setsockopt(value vty, value socket, value option, value val) +{ invalid_argument("setsockopt not implemented"); } + +#endif diff --git a/otherlibs/unix/stat.c b/otherlibs/unix/stat.c new file mode 100644 index 0000000..c06e562 --- /dev/null +++ b/otherlibs/unix/stat.c @@ -0,0 +1,140 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stat.c,v 1.15 2003-05-05 14:20:58 xleroy Exp $ */ + +#include <errno.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include "unixsupport.h" +#include "cst2constr.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <io.h> + +#ifndef S_IFLNK +#define S_IFLNK 0 +#endif +#ifndef S_IFIFO +#define S_IFIFO 0 +#endif +#ifndef S_IFSOCK +#define S_IFSOCK 0 +#endif +#ifndef S_IFBLK +#define S_IFBLK 0 +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif + +static int file_kind_table[] = { + S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFLNK, S_IFIFO, S_IFSOCK +}; + +static value stat_aux(int use_64, struct stat *buf) +{ + CAMLparam0(); + CAMLlocal5(atime, mtime, ctime, offset, v); + + atime = copy_double((double) buf->st_atime); + mtime = copy_double((double) buf->st_mtime); + ctime = copy_double((double) buf->st_ctime); + offset = use_64 ? Val_file_offset(buf->st_size) : Val_int (buf->st_size); + v = alloc_small(12, 0); + Field (v, 0) = Val_int (buf->st_dev); + Field (v, 1) = Val_int (buf->st_ino); + Field (v, 2) = cst_to_constr(buf->st_mode & S_IFMT, file_kind_table, + sizeof(file_kind_table) / sizeof(int), 0); + Field (v, 3) = Val_int (buf->st_mode & 07777); + Field (v, 4) = Val_int (buf->st_nlink); + Field (v, 5) = Val_int (buf->st_uid); + Field (v, 6) = Val_int (buf->st_gid); + Field (v, 7) = Val_int (buf->st_rdev); + Field (v, 8) = offset; + Field (v, 9) = atime; + Field (v, 10) = mtime; + Field (v, 11) = ctime; + CAMLreturn(v); +} + +CAMLprim value unix_stat(value path) +{ + int ret; + struct stat buf; + ret = stat(String_val(path), &buf); + if (ret == -1) uerror("stat", path); + if (buf.st_size > Max_long && (buf.st_mode & S_IFMT) == S_IFREG) + unix_error(EOVERFLOW, "stat", path); + return stat_aux(0, &buf); +} + +CAMLprim value unix_lstat(value path) +{ + int ret; + struct stat buf; +#ifdef HAS_SYMLINK + ret = lstat(String_val(path), &buf); +#else + ret = stat(String_val(path), &buf); +#endif + if (ret == -1) uerror("lstat", path); + if (buf.st_size > Max_long && (buf.st_mode & S_IFMT) == S_IFREG) + unix_error(EOVERFLOW, "lstat", path); + return stat_aux(0, &buf); +} + +CAMLprim value unix_fstat(value fd) +{ + int ret; + struct stat buf; + ret = fstat(Int_val(fd), &buf); + if (ret == -1) uerror("fstat", Nothing); + if (buf.st_size > Max_long && (buf.st_mode & S_IFMT) == S_IFREG) + unix_error(EOVERFLOW, "fstat", Nothing); + return stat_aux(0, &buf); +} + +CAMLprim value unix_stat_64(value path) +{ + int ret; + struct stat buf; + ret = stat(String_val(path), &buf); + if (ret == -1) uerror("stat", path); + return stat_aux(1, &buf); +} + +CAMLprim value unix_lstat_64(value path) +{ + int ret; + struct stat buf; +#ifdef HAS_SYMLINK + ret = lstat(String_val(path), &buf); +#else + ret = stat(String_val(path), &buf); +#endif + if (ret == -1) uerror("lstat", path); + return stat_aux(1, &buf); +} + +CAMLprim value unix_fstat_64(value fd) +{ + int ret; + struct stat buf; + ret = fstat(Int_val(fd), &buf); + if (ret == -1) uerror("fstat", Nothing); + return stat_aux(1, &buf); +} + diff --git a/otherlibs/unix/strofaddr.c b/otherlibs/unix/strofaddr.c new file mode 100644 index 0000000..145b123 --- /dev/null +++ b/otherlibs/unix/strofaddr.c @@ -0,0 +1,50 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: strofaddr.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_SOCKETS + +#include "socketaddr.h" + +CAMLprim value unix_string_of_inet_addr(value a) +{ + char * res; +#ifdef HAS_IPV6 + char buffer[64]; + if (string_length(a) == 16) + res = (char *) + inet_ntop(AF_INET6, (const void *) &GET_INET6_ADDR(a), + buffer, sizeof(buffer)); + else + res = (char *) + inet_ntop(AF_INET, (const void *) &GET_INET_ADDR(a), + buffer, sizeof(buffer)); +#else + res = inet_ntoa(GET_INET_ADDR(a)); +#endif + if (res == NULL) uerror("string_of_inet_addr", Nothing); + return copy_string(res); +} + +#else + +CAMLprim value unix_string_of_inet_addr(value a) +{ invalid_argument("string_of_inet_addr not implemented"); } + +#endif diff --git a/otherlibs/unix/symlink.c b/otherlibs/unix/symlink.c new file mode 100644 index 0000000..e9f043b --- /dev/null +++ b/otherlibs/unix/symlink.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: symlink.c,v 1.9 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_SYMLINK + +CAMLprim value unix_symlink(value path1, value path2) +{ + if (symlink(String_val(path1), String_val(path2)) == -1) + uerror("symlink", path2); + return Val_unit; +} + +#else + +CAMLprim value unix_symlink(value path1, value path2) +{ invalid_argument("symlink not implemented"); } + +#endif diff --git a/otherlibs/unix/termios.c b/otherlibs/unix/termios.c new file mode 100644 index 0000000..76fedcd --- /dev/null +++ b/otherlibs/unix/termios.c @@ -0,0 +1,317 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: termios.c,v 1.15 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +#ifdef HAS_TERMIOS + +#include <termios.h> +#include <errno.h> + +static struct termios terminal_status; + +enum { Bool, Enum, Speed, Char, End }; + +enum { Input, Output }; + +#define iflags ((long)(&terminal_status.c_iflag)) +#define oflags ((long)(&terminal_status.c_oflag)) +#define cflags ((long)(&terminal_status.c_cflag)) +#define lflags ((long)(&terminal_status.c_lflag)) + +/* Number of fields in the terminal_io record field. Cf. unix.mli */ + +#define NFIELDS 38 + +/* Structure of the terminal_io record. Cf. unix.mli */ + +static long terminal_io_descr[] = { + /* Input modes */ + Bool, iflags, IGNBRK, + Bool, iflags, BRKINT, + Bool, iflags, IGNPAR, + Bool, iflags, PARMRK, + Bool, iflags, INPCK, + Bool, iflags, ISTRIP, + Bool, iflags, INLCR, + Bool, iflags, IGNCR, + Bool, iflags, ICRNL, + Bool, iflags, IXON, + Bool, iflags, IXOFF, + /* Output modes */ + Bool, oflags, OPOST, + /* Control modes */ + Speed, Output, + Speed, Input, + Enum, cflags, 5, 4, CSIZE, CS5, CS6, CS7, CS8, + Enum, cflags, 1, 2, CSTOPB, 0, CSTOPB, + Bool, cflags, CREAD, + Bool, cflags, PARENB, + Bool, cflags, PARODD, + Bool, cflags, HUPCL, + Bool, cflags, CLOCAL, + /* Local modes */ + Bool, lflags, ISIG, + Bool, lflags, ICANON, + Bool, lflags, NOFLSH, + Bool, lflags, ECHO, + Bool, lflags, ECHOE, + Bool, lflags, ECHOK, + Bool, lflags, ECHONL, + /* Control characters */ + Char, VINTR, + Char, VQUIT, + Char, VERASE, + Char, VKILL, + Char, VEOF, + Char, VEOL, + Char, VMIN, + Char, VTIME, + Char, VSTART, + Char, VSTOP, + End +}; + +#undef iflags +#undef oflags +#undef cflags +#undef lflags + +struct speedtable_entry ; + +static struct { + speed_t speed; + int baud; +} speedtable[] = { + {B50, 50}, + {B75, 75}, + {B110, 110}, + {B134, 134}, + {B150, 150}, + {B300, 300}, + {B600, 600}, + {B1200, 1200}, + {B1800, 1800}, + {B2400, 2400}, + {B4800, 4800}, + {B9600, 9600}, + {B19200, 19200}, + {B38400, 38400}, +#ifdef B57600 + {B57600, 57600}, +#endif +#ifdef B115200 + {B115200, 115200}, +#endif +#ifdef B230400 + {B230400, 230400}, +#endif + {B0, 0} +}; + +#define NSPEEDS (sizeof(speedtable) / sizeof(speedtable[0])) + +static void encode_terminal_status(value *dst) +{ + long * pc; + int i; + + for(pc = terminal_io_descr; *pc != End; dst++) { + switch(*pc++) { + case Bool: + { int * src = (int *) (*pc++); + int msk = *pc++; + *dst = Val_bool(*src & msk); + break; } + case Enum: + { int * src = (int *) (*pc++); + int ofs = *pc++; + int num = *pc++; + int msk = *pc++; + for (i = 0; i < num; i++) { + if ((*src & msk) == pc[i]) { + *dst = Val_int(i + ofs); + break; + } + } + pc += num; + break; } + case Speed: + { int which = *pc++; + speed_t speed = 0; + *dst = Val_int(9600); /* in case no speed in speedtable matches */ + switch (which) { + case Output: + speed = cfgetospeed(&terminal_status); break; + case Input: + speed = cfgetispeed(&terminal_status); break; + } + for (i = 0; i < NSPEEDS; i++) { + if (speed == speedtable[i].speed) { + *dst = Val_int(speedtable[i].baud); + break; + } + } + break; } + case Char: + { int which = *pc++; + *dst = Val_int(terminal_status.c_cc[which]); + break; } + } + } +} + +static void decode_terminal_status(value *src) +{ + long * pc; + int i; + + for (pc = terminal_io_descr; *pc != End; src++) { + switch(*pc++) { + case Bool: + { int * dst = (int *) (*pc++); + int msk = *pc++; + if (Bool_val(*src)) + *dst |= msk; + else + *dst &= ~msk; + break; } + case Enum: + { int * dst = (int *) (*pc++); + int ofs = *pc++; + int num = *pc++; + int msk = *pc++; + i = Int_val(*src) - ofs; + if (i >= 0 && i < num) { + *dst = (*dst & ~msk) | pc[i]; + } else { + unix_error(EINVAL, "tcsetattr", Nothing); + } + pc += num; + break; } + case Speed: + { int which = *pc++; + int baud = Int_val(*src); + int res = 0; + for (i = 0; i < NSPEEDS; i++) { + if (baud == speedtable[i].baud) { + switch (which) { + case Output: + res = cfsetospeed(&terminal_status, speedtable[i].speed); break; + case Input: + res = cfsetispeed(&terminal_status, speedtable[i].speed); break; + } + if (res == -1) uerror("tcsetattr", Nothing); + goto ok; + } + } + unix_error(EINVAL, "tcsetattr", Nothing); + ok: + break; } + case Char: + { int which = *pc++; + terminal_status.c_cc[which] = Int_val(*src); + break; } + } + } +} + +CAMLprim value unix_tcgetattr(value fd) +{ + value res; + + if (tcgetattr(Int_val(fd), &terminal_status) == -1) + uerror("tcgetattr", Nothing); + res = alloc_tuple(NFIELDS); + encode_terminal_status(&Field(res, 0)); + return res; +} + +static int when_flag_table[] = { + TCSANOW, TCSADRAIN, TCSAFLUSH +}; + +CAMLprim value unix_tcsetattr(value fd, value when, value arg) +{ + if (tcgetattr(Int_val(fd), &terminal_status) == -1) + uerror("tcsetattr", Nothing); + decode_terminal_status(&Field(arg, 0)); + if (tcsetattr(Int_val(fd), + when_flag_table[Int_val(when)], + &terminal_status) == -1) + uerror("tcsetattr", Nothing); + return Val_unit; +} + +CAMLprim value unix_tcsendbreak(value fd, value delay) +{ + if (tcsendbreak(Int_val(fd), Int_val(delay)) == -1) + uerror("tcsendbreak", Nothing); + return Val_unit; +} + +CAMLprim value unix_tcdrain(value fd) +{ + if (tcdrain(Int_val(fd)) == -1) uerror("tcdrain", Nothing); + return Val_unit; +} + +static int queue_flag_table[] = { + TCIFLUSH, TCOFLUSH, TCIOFLUSH +}; + +CAMLprim value unix_tcflush(value fd, value queue) +{ + if (tcflush(Int_val(fd), queue_flag_table[Int_val(queue)]) == -1) + uerror("tcflush", Nothing); + return Val_unit; +} + +static int action_flag_table[] = { + TCOOFF, TCOON, TCIOFF, TCION +}; + +CAMLprim value unix_tcflow(value fd, value action) +{ + if (tcflow(Int_val(fd), action_flag_table[Int_val(action)]) == -1) + uerror("tcflow", Nothing); + return Val_unit; +} + +#else + +CAMLprim value unix_tcgetattr(value fd) +{ invalid_argument("tcgetattr not implemented"); } + +CAMLprim value unix_tcsetattr(value fd, value when, value arg) +{ invalid_argument("tcsetattr not implemented"); } + +CAMLprim value unix_tcsendbreak(value fd, value delay) +{ invalid_argument("tcsendbreak not implemented"); } + +CAMLprim value unix_tcdrain(value fd) +{ invalid_argument("tcdrain not implemented"); } + +CAMLprim value unix_tcflush(value fd, value queue) +{ invalid_argument("tcflush not implemented"); } + +CAMLprim value unix_tcflow(value fd, value action) +{ invalid_argument("tcflow not implemented"); } + +#endif + diff --git a/otherlibs/unix/time.c b/otherlibs/unix/time.c new file mode 100644 index 0000000..8901f84 --- /dev/null +++ b/otherlibs/unix/time.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: time.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <time.h> +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +CAMLprim value unix_time(value unit) +{ + return copy_double((double) time((time_t *) NULL)); +} diff --git a/otherlibs/unix/times.c b/otherlibs/unix/times.c new file mode 100644 index 0000000..f192645 --- /dev/null +++ b/otherlibs/unix/times.c @@ -0,0 +1,67 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: times.c,v 1.16 2006-04-16 23:28:21 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include "unixsupport.h" +#include <time.h> +#include <sys/types.h> +#include <sys/times.h> +#ifdef HAS_GETRUSAGE +#include <sys/time.h> +#include <sys/resource.h> +#endif + +#ifndef CLK_TCK +#ifdef HZ +#define CLK_TCK HZ +#else +#define CLK_TCK 60 +#endif +#endif + +CAMLprim value unix_times(value unit) +{ +#ifdef HAS_GETRUSAGE + + value res; + struct rusage ru; + + res = alloc_small(4 * Double_wosize, Double_array_tag); + + getrusage (RUSAGE_SELF, &ru); + Store_double_field (res, 0, ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1e6); + Store_double_field (res, 1, ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1e6); + getrusage (RUSAGE_CHILDREN, &ru); + Store_double_field (res, 2, ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1e6); + Store_double_field (res, 3, ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1e6); + return res; + +#else + + value res; + struct tms buffer; + + times(&buffer); + res = alloc_small(4 * Double_wosize, Double_array_tag); + Store_double_field(res, 0, (double) buffer.tms_utime / CLK_TCK); + Store_double_field(res, 1, (double) buffer.tms_stime / CLK_TCK); + Store_double_field(res, 2, (double) buffer.tms_cutime / CLK_TCK); + Store_double_field(res, 3, (double) buffer.tms_cstime / CLK_TCK); + return res; + +#endif +} diff --git a/otherlibs/unix/truncate.c b/otherlibs/unix/truncate.c new file mode 100644 index 0000000..9cfba17 --- /dev/null +++ b/otherlibs/unix/truncate.c @@ -0,0 +1,49 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: truncate.c,v 1.11 2007-02-09 13:31:15 doligez Exp $ */ + +#include <sys/types.h> +#include <mlvalues.h> +#include <fail.h> +#include <io.h> +#include "unixsupport.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +#ifdef HAS_TRUNCATE + +CAMLprim value unix_truncate(value path, value len) +{ + if (truncate(String_val(path), Long_val(len)) == -1) + uerror("truncate", path); + return Val_unit; +} + +CAMLprim value unix_truncate_64(value path, value len) +{ + if (truncate(String_val(path), File_offset_val(len)) == -1) + uerror("truncate", path); + return Val_unit; +} + +#else + +CAMLprim value unix_truncate(value path, value len) +{ invalid_argument("truncate not implemented"); } + +CAMLprim value unix_truncate_64(value path, value len) +{ invalid_argument("truncate not implemented"); } + +#endif diff --git a/otherlibs/unix/umask.c b/otherlibs/unix/umask.c new file mode 100644 index 0000000..ebba51c --- /dev/null +++ b/otherlibs/unix/umask.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: umask.c,v 1.9 2001-12-07 13:40:37 xleroy Exp $ */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_umask(value perm) +{ + return Val_int(umask(Int_val(perm))); +} diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml new file mode 100644 index 0000000..4c6f247 --- /dev/null +++ b/otherlibs/unix/unix.ml @@ -0,0 +1,966 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unix.ml,v 1.68 2008-08-01 13:46:08 xleroy Exp $ *) + +type error = + E2BIG + | EACCES + | EAGAIN + | EBADF + | EBUSY + | ECHILD + | EDEADLK + | EDOM + | EEXIST + | EFAULT + | EFBIG + | EINTR + | EINVAL + | EIO + | EISDIR + | EMFILE + | EMLINK + | ENAMETOOLONG + | ENFILE + | ENODEV + | ENOENT + | ENOEXEC + | ENOLCK + | ENOMEM + | ENOSPC + | ENOSYS + | ENOTDIR + | ENOTEMPTY + | ENOTTY + | ENXIO + | EPERM + | EPIPE + | ERANGE + | EROFS + | ESPIPE + | ESRCH + | EXDEV + | EWOULDBLOCK + | EINPROGRESS + | EALREADY + | ENOTSOCK + | EDESTADDRREQ + | EMSGSIZE + | EPROTOTYPE + | ENOPROTOOPT + | EPROTONOSUPPORT + | ESOCKTNOSUPPORT + | EOPNOTSUPP + | EPFNOSUPPORT + | EAFNOSUPPORT + | EADDRINUSE + | EADDRNOTAVAIL + | ENETDOWN + | ENETUNREACH + | ENETRESET + | ECONNABORTED + | ECONNRESET + | ENOBUFS + | EISCONN + | ENOTCONN + | ESHUTDOWN + | ETOOMANYREFS + | ETIMEDOUT + | ECONNREFUSED + | EHOSTDOWN + | EHOSTUNREACH + | ELOOP + | EOVERFLOW + | EUNKNOWNERR of int + +exception Unix_error of error * string * string + +let _ = Callback.register_exception "Unix.Unix_error" + (Unix_error(E2BIG, "", "")) + +external error_message : error -> string = "unix_error_message" + +let handle_unix_error f arg = + try + f arg + with Unix_error(err, fun_name, arg) -> + prerr_string Sys.argv.(0); + prerr_string ": \""; + prerr_string fun_name; + prerr_string "\" failed"; + if String.length arg > 0 then begin + prerr_string " on \""; + prerr_string arg; + prerr_string "\"" + end; + prerr_string ": "; + prerr_endline (error_message err); + exit 2 + +external environment : unit -> string array = "unix_environment" +external getenv: string -> string = "caml_sys_getenv" +external putenv: string -> string -> unit = "unix_putenv" + +type process_status = + WEXITED of int + | WSIGNALED of int + | WSTOPPED of int + +type wait_flag = + WNOHANG + | WUNTRACED + +external execv : string -> string array -> 'a = "unix_execv" +external execve : string -> string array -> string array -> 'a = "unix_execve" +external execvp : string -> string array -> 'a = "unix_execvp" +external execvpe : string -> string array -> string array -> 'a = "unix_execvpe" +external fork : unit -> int = "unix_fork" +external wait : unit -> int * process_status = "unix_wait" +external waitpid : wait_flag list -> int -> int * process_status = "unix_waitpid" +external getpid : unit -> int = "unix_getpid" +external getppid : unit -> int = "unix_getppid" +external nice : int -> int = "unix_nice" + +type file_descr = int + +let stdin = 0 +let stdout = 1 +let stderr = 2 + +type open_flag = + O_RDONLY + | O_WRONLY + | O_RDWR + | O_NONBLOCK + | O_APPEND + | O_CREAT + | O_TRUNC + | O_EXCL + | O_NOCTTY + | O_DSYNC + | O_SYNC + | O_RSYNC + +type file_perm = int + + +external openfile : string -> open_flag list -> file_perm -> file_descr + = "unix_open" + +external close : file_descr -> unit = "unix_close" +external unsafe_read : file_descr -> string -> int -> int -> int = "unix_read" +external unsafe_write : file_descr -> string -> int -> int -> int = "unix_write" +external unsafe_single_write : file_descr -> string -> int -> int -> int = "unix_single_write" + +let read fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.read" + else unsafe_read fd buf ofs len +let write fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.write" + else unsafe_write fd buf ofs len +(* write misbehaves because it attempts to write all data by making repeated + calls to the Unix write function (see comment in write.c and unix.mli). + partial_write fixes this by never calling write twice. *) +let single_write fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.single_write" + else unsafe_single_write fd buf ofs len + +external in_channel_of_descr : file_descr -> in_channel + = "caml_ml_open_descriptor_in" +external out_channel_of_descr : file_descr -> out_channel + = "caml_ml_open_descriptor_out" +external descr_of_in_channel : in_channel -> file_descr + = "caml_channel_descriptor" +external descr_of_out_channel : out_channel -> file_descr + = "caml_channel_descriptor" + +type seek_command = + SEEK_SET + | SEEK_CUR + | SEEK_END + +external lseek : file_descr -> int -> seek_command -> int = "unix_lseek" +external truncate : string -> int -> unit = "unix_truncate" +external ftruncate : file_descr -> int -> unit = "unix_ftruncate" + +type file_kind = + S_REG + | S_DIR + | S_CHR + | S_BLK + | S_LNK + | S_FIFO + | S_SOCK + +type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int; + st_atime : float; + st_mtime : float; + st_ctime : float } + +external stat : string -> stats = "unix_stat" +external lstat : string -> stats = "unix_lstat" +external fstat : file_descr -> stats = "unix_fstat" +external isatty : file_descr -> bool = "unix_isatty" +external unlink : string -> unit = "unix_unlink" +external rename : string -> string -> unit = "unix_rename" +external link : string -> string -> unit = "unix_link" + +module LargeFile = + struct + external lseek : file_descr -> int64 -> seek_command -> int64 = "unix_lseek_64" + external truncate : string -> int64 -> unit = "unix_truncate_64" + external ftruncate : file_descr -> int64 -> unit = "unix_ftruncate_64" + type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int64; + st_atime : float; + st_mtime : float; + st_ctime : float; + } + external stat : string -> stats = "unix_stat_64" + external lstat : string -> stats = "unix_lstat_64" + external fstat : file_descr -> stats = "unix_fstat_64" + end + +type access_permission = + R_OK + | W_OK + | X_OK + | F_OK + +external chmod : string -> file_perm -> unit = "unix_chmod" +external fchmod : file_descr -> file_perm -> unit = "unix_fchmod" +external chown : string -> int -> int -> unit = "unix_chown" +external fchown : file_descr -> int -> int -> unit = "unix_fchown" +external umask : int -> int = "unix_umask" +external access : string -> access_permission list -> unit = "unix_access" + +external dup : file_descr -> file_descr = "unix_dup" +external dup2 : file_descr -> file_descr -> unit = "unix_dup2" +external set_nonblock : file_descr -> unit = "unix_set_nonblock" +external clear_nonblock : file_descr -> unit = "unix_clear_nonblock" +external set_close_on_exec : file_descr -> unit = "unix_set_close_on_exec" +external clear_close_on_exec : file_descr -> unit = "unix_clear_close_on_exec" + +(* FD_CLOEXEC should be supported on all Unix systems these days, + but just in case... *) +let try_set_close_on_exec fd = + try set_close_on_exec fd; true with Invalid_argument _ -> false + +external mkdir : string -> file_perm -> unit = "unix_mkdir" +external rmdir : string -> unit = "unix_rmdir" +external chdir : string -> unit = "unix_chdir" +external getcwd : unit -> string = "unix_getcwd" +external chroot : string -> unit = "unix_chroot" + +type dir_handle + +external opendir : string -> dir_handle = "unix_opendir" +external readdir : dir_handle -> string = "unix_readdir" +external rewinddir : dir_handle -> unit = "unix_rewinddir" +external closedir : dir_handle -> unit = "unix_closedir" + +external pipe : unit -> file_descr * file_descr = "unix_pipe" +external symlink : string -> string -> unit = "unix_symlink" +external readlink : string -> string = "unix_readlink" +external mkfifo : string -> file_perm -> unit = "unix_mkfifo" +external select : + file_descr list -> file_descr list -> file_descr list -> float -> + file_descr list * file_descr list * file_descr list = "unix_select" + +type lock_command = + F_ULOCK + | F_LOCK + | F_TLOCK + | F_TEST + | F_RLOCK + | F_TRLOCK + +external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf" +external kill : int -> int -> unit = "unix_kill" +type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK +external sigprocmask: sigprocmask_command -> int list -> int list + = "unix_sigprocmask" +external sigpending: unit -> int list = "unix_sigpending" +external sigsuspend: int list -> unit = "unix_sigsuspend" + +let pause() = + let sigs = sigprocmask SIG_BLOCK [] in sigsuspend sigs + +type process_times = + { tms_utime : float; + tms_stime : float; + tms_cutime : float; + tms_cstime : float } + +type tm = + { tm_sec : int; + tm_min : int; + tm_hour : int; + tm_mday : int; + tm_mon : int; + tm_year : int; + tm_wday : int; + tm_yday : int; + tm_isdst : bool } + +external time : unit -> float = "unix_time" +external gettimeofday : unit -> float = "unix_gettimeofday" +external gmtime : float -> tm = "unix_gmtime" +external localtime : float -> tm = "unix_localtime" +external mktime : tm -> float * tm = "unix_mktime" +external alarm : int -> int = "unix_alarm" +external sleep : int -> unit = "unix_sleep" +external times : unit -> process_times = "unix_times" +external utimes : string -> float -> float -> unit = "unix_utimes" + +type interval_timer = + ITIMER_REAL + | ITIMER_VIRTUAL + | ITIMER_PROF + +type interval_timer_status = + { it_interval: float; (* Period *) + it_value: float } (* Current value of the timer *) + +external getitimer: interval_timer -> interval_timer_status = "unix_getitimer" +external setitimer: + interval_timer -> interval_timer_status -> interval_timer_status + = "unix_setitimer" + +external getuid : unit -> int = "unix_getuid" +external geteuid : unit -> int = "unix_geteuid" +external setuid : int -> unit = "unix_setuid" +external getgid : unit -> int = "unix_getgid" +external getegid : unit -> int = "unix_getegid" +external setgid : int -> unit = "unix_setgid" +external getgroups : unit -> int array = "unix_getgroups" + +type passwd_entry = + { pw_name : string; + pw_passwd : string; + pw_uid : int; + pw_gid : int; + pw_gecos : string; + pw_dir : string; + pw_shell : string } + +type group_entry = + { gr_name : string; + gr_passwd : string; + gr_gid : int; + gr_mem : string array } + + +external getlogin : unit -> string = "unix_getlogin" +external getpwnam : string -> passwd_entry = "unix_getpwnam" +external getgrnam : string -> group_entry = "unix_getgrnam" +external getpwuid : int -> passwd_entry = "unix_getpwuid" +external getgrgid : int -> group_entry = "unix_getgrgid" + +type inet_addr = string + +let is_inet6_addr s = String.length s = 16 + +external inet_addr_of_string : string -> inet_addr + = "unix_inet_addr_of_string" +external string_of_inet_addr : inet_addr -> string + = "unix_string_of_inet_addr" + +let inet_addr_any = inet_addr_of_string "0.0.0.0" +let inet_addr_loopback = inet_addr_of_string "127.0.0.1" +let inet6_addr_any = + try inet_addr_of_string "::" with Failure _ -> inet_addr_any +let inet6_addr_loopback = + try inet_addr_of_string "::1" with Failure _ -> inet_addr_loopback + +type socket_domain = + PF_UNIX + | PF_INET + | PF_INET6 + +type socket_type = + SOCK_STREAM + | SOCK_DGRAM + | SOCK_RAW + | SOCK_SEQPACKET + +type sockaddr = + ADDR_UNIX of string + | ADDR_INET of inet_addr * int + +let domain_of_sockaddr = function + ADDR_UNIX _ -> PF_UNIX + | ADDR_INET(a, _) -> if is_inet6_addr a then PF_INET6 else PF_INET + +type shutdown_command = + SHUTDOWN_RECEIVE + | SHUTDOWN_SEND + | SHUTDOWN_ALL + +type msg_flag = + MSG_OOB + | MSG_DONTROUTE + | MSG_PEEK + +external socket : socket_domain -> socket_type -> int -> file_descr + = "unix_socket" +external socketpair : + socket_domain -> socket_type -> int -> file_descr * file_descr + = "unix_socketpair" +external accept : file_descr -> file_descr * sockaddr = "unix_accept" +external bind : file_descr -> sockaddr -> unit = "unix_bind" +external connect : file_descr -> sockaddr -> unit = "unix_connect" +external listen : file_descr -> int -> unit = "unix_listen" +external shutdown : file_descr -> shutdown_command -> unit = "unix_shutdown" +external getsockname : file_descr -> sockaddr = "unix_getsockname" +external getpeername : file_descr -> sockaddr = "unix_getpeername" + +external unsafe_recv : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_recv" +external unsafe_recvfrom : + file_descr -> string -> int -> int -> msg_flag list -> int * sockaddr + = "unix_recvfrom" +external unsafe_send : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_send" +external unsafe_sendto : + file_descr -> string -> int -> int -> msg_flag list -> sockaddr -> int + = "unix_sendto" "unix_sendto_native" + +let recv fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recv" + else unsafe_recv fd buf ofs len flags +let recvfrom fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recvfrom" + else unsafe_recvfrom fd buf ofs len flags +let send fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.send" + else unsafe_send fd buf ofs len flags +let sendto fd buf ofs len flags addr = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.sendto" + else unsafe_sendto fd buf ofs len flags addr + +type socket_bool_option = + SO_DEBUG + | SO_BROADCAST + | SO_REUSEADDR + | SO_KEEPALIVE + | SO_DONTROUTE + | SO_OOBINLINE + | SO_ACCEPTCONN + | TCP_NODELAY + | IPV6_ONLY + +type socket_int_option = + SO_SNDBUF + | SO_RCVBUF + | SO_ERROR + | SO_TYPE + | SO_RCVLOWAT + | SO_SNDLOWAT + +type socket_optint_option = SO_LINGER + +type socket_float_option = + SO_RCVTIMEO + | SO_SNDTIMEO + +type socket_error_option = SO_ERROR + +module SO: sig + type ('opt, 'v) t + val bool: (socket_bool_option, bool) t + val int: (socket_int_option, int) t + val optint: (socket_optint_option, int option) t + val float: (socket_float_option, float) t + val error: (socket_error_option, error option) t + val get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + val set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit +end = struct + type ('opt, 'v) t = int + let bool = 0 + let int = 1 + let optint = 2 + let float = 3 + let error = 4 + external get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + = "unix_getsockopt" + external set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit + = "unix_setsockopt" +end + +let getsockopt fd opt = SO.get SO.bool fd opt +let setsockopt fd opt v = SO.set SO.bool fd opt v + +let getsockopt_int fd opt = SO.get SO.int fd opt +let setsockopt_int fd opt v = SO.set SO.int fd opt v + +let getsockopt_optint fd opt = SO.get SO.optint fd opt +let setsockopt_optint fd opt v = SO.set SO.optint fd opt v + +let getsockopt_float fd opt = SO.get SO.float fd opt +let setsockopt_float fd opt v = SO.set SO.float fd opt v + +let getsockopt_error fd = SO.get SO.error fd SO_ERROR + +type host_entry = + { h_name : string; + h_aliases : string array; + h_addrtype : socket_domain; + h_addr_list : inet_addr array } + +type protocol_entry = + { p_name : string; + p_aliases : string array; + p_proto : int } + +type service_entry = + { s_name : string; + s_aliases : string array; + s_port : int; + s_proto : string } + +external gethostname : unit -> string = "unix_gethostname" +external gethostbyname : string -> host_entry = "unix_gethostbyname" +external gethostbyaddr : inet_addr -> host_entry = "unix_gethostbyaddr" +external getprotobyname : string -> protocol_entry + = "unix_getprotobyname" +external getprotobynumber : int -> protocol_entry + = "unix_getprotobynumber" +external getservbyname : string -> string -> service_entry + = "unix_getservbyname" +external getservbyport : int -> string -> service_entry + = "unix_getservbyport" + +type addr_info = + { ai_family : socket_domain; + ai_socktype : socket_type; + ai_protocol : int; + ai_addr : sockaddr; + ai_canonname : string } + +type getaddrinfo_option = + AI_FAMILY of socket_domain + | AI_SOCKTYPE of socket_type + | AI_PROTOCOL of int + | AI_NUMERICHOST + | AI_CANONNAME + | AI_PASSIVE + +external getaddrinfo_system + : string -> string -> getaddrinfo_option list -> addr_info list + = "unix_getaddrinfo" + +let getaddrinfo_emulation node service opts = + (* Parse options *) + let opt_socktype = ref None + and opt_protocol = ref 0 + and opt_passive = ref false in + List.iter + (function AI_SOCKTYPE s -> opt_socktype := Some s + | AI_PROTOCOL p -> opt_protocol := p + | AI_PASSIVE -> opt_passive := true + | _ -> ()) + opts; + (* Determine socket types and port numbers *) + let get_port ty kind = + if service = "" then [ty, 0] else + try + [ty, int_of_string service] + with Failure _ -> + try + [ty, (getservbyname service kind).s_port] + with Not_found -> [] + in + let ports = + match !opt_socktype with + | None -> + get_port SOCK_STREAM "tcp" @ get_port SOCK_DGRAM "udp" + | Some SOCK_STREAM -> + get_port SOCK_STREAM "tcp" + | Some SOCK_DGRAM -> + get_port SOCK_DGRAM "udp" + | Some ty -> + if service = "" then [ty, 0] else [] in + (* Determine IP addresses *) + let addresses = + if node = "" then + if List.mem AI_PASSIVE opts + then [inet_addr_any, "0.0.0.0"] + else [inet_addr_loopback, "127.0.0.1"] + else + try + [inet_addr_of_string node, node] + with Failure _ -> + try + let he = gethostbyname node in + List.map + (fun a -> (a, he.h_name)) + (Array.to_list he.h_addr_list) + with Not_found -> + [] in + (* Cross-product of addresses and ports *) + List.flatten + (List.map + (fun (ty, port) -> + List.map + (fun (addr, name) -> + { ai_family = PF_INET; + ai_socktype = ty; + ai_protocol = !opt_protocol; + ai_addr = ADDR_INET(addr, port); + ai_canonname = name }) + addresses) + ports) + +let getaddrinfo node service opts = + try + List.rev(getaddrinfo_system node service opts) + with Invalid_argument _ -> + getaddrinfo_emulation node service opts + +type name_info = + { ni_hostname : string; + ni_service : string } + +type getnameinfo_option = + NI_NOFQDN + | NI_NUMERICHOST + | NI_NAMEREQD + | NI_NUMERICSERV + | NI_DGRAM + +external getnameinfo_system + : sockaddr -> getnameinfo_option list -> name_info + = "unix_getnameinfo" + +let getnameinfo_emulation addr opts = + match addr with + | ADDR_UNIX f -> + { ni_hostname = ""; ni_service = f } (* why not? *) + | ADDR_INET(a, p) -> + let hostname = + try + if List.mem NI_NUMERICHOST opts then raise Not_found; + (gethostbyaddr a).h_name + with Not_found -> + if List.mem NI_NAMEREQD opts then raise Not_found; + string_of_inet_addr a in + let service = + try + if List.mem NI_NUMERICSERV opts then raise Not_found; + let kind = if List.mem NI_DGRAM opts then "udp" else "tcp" in + (getservbyport p kind).s_name + with Not_found -> + string_of_int p in + { ni_hostname = hostname; ni_service = service } + +let getnameinfo addr opts = + try + getnameinfo_system addr opts + with Invalid_argument _ -> + getnameinfo_emulation addr opts + +type terminal_io = { + mutable c_ignbrk: bool; + mutable c_brkint: bool; + mutable c_ignpar: bool; + mutable c_parmrk: bool; + mutable c_inpck: bool; + mutable c_istrip: bool; + mutable c_inlcr: bool; + mutable c_igncr: bool; + mutable c_icrnl: bool; + mutable c_ixon: bool; + mutable c_ixoff: bool; + mutable c_opost: bool; + mutable c_obaud: int; + mutable c_ibaud: int; + mutable c_csize: int; + mutable c_cstopb: int; + mutable c_cread: bool; + mutable c_parenb: bool; + mutable c_parodd: bool; + mutable c_hupcl: bool; + mutable c_clocal: bool; + mutable c_isig: bool; + mutable c_icanon: bool; + mutable c_noflsh: bool; + mutable c_echo: bool; + mutable c_echoe: bool; + mutable c_echok: bool; + mutable c_echonl: bool; + mutable c_vintr: char; + mutable c_vquit: char; + mutable c_verase: char; + mutable c_vkill: char; + mutable c_veof: char; + mutable c_veol: char; + mutable c_vmin: int; + mutable c_vtime: int; + mutable c_vstart: char; + mutable c_vstop: char + } + +external tcgetattr: file_descr -> terminal_io = "unix_tcgetattr" + +type setattr_when = TCSANOW | TCSADRAIN | TCSAFLUSH + +external tcsetattr: file_descr -> setattr_when -> terminal_io -> unit + = "unix_tcsetattr" +external tcsendbreak: file_descr -> int -> unit = "unix_tcsendbreak" +external tcdrain: file_descr -> unit = "unix_tcdrain" + +type flush_queue = TCIFLUSH | TCOFLUSH | TCIOFLUSH + +external tcflush: file_descr -> flush_queue -> unit = "unix_tcflush" + +type flow_action = TCOOFF | TCOON | TCIOFF | TCION + +external tcflow: file_descr -> flow_action -> unit = "unix_tcflow" + +external setsid : unit -> int = "unix_setsid" + +(* High-level process management (system, popen) *) + +let system cmd = + match fork() with + 0 -> begin try + execv "/bin/sh" [| "/bin/sh"; "-c"; cmd |] + with _ -> + exit 127 + end + | id -> snd(waitpid [] id) + +let rec safe_dup fd = + let new_fd = dup fd in + if new_fd >= 3 then + new_fd + else begin + let res = safe_dup fd in + close new_fd; + res + end + +let safe_close fd = + try close fd with Unix_error(_,_,_) -> () + +let perform_redirections new_stdin new_stdout new_stderr = + let newnewstdin = safe_dup new_stdin in + let newnewstdout = safe_dup new_stdout in + let newnewstderr = safe_dup new_stderr in + safe_close new_stdin; + safe_close new_stdout; + safe_close new_stderr; + dup2 newnewstdin stdin; close newnewstdin; + dup2 newnewstdout stdout; close newnewstdout; + dup2 newnewstderr stderr; close newnewstderr + +let create_process cmd args new_stdin new_stdout new_stderr = + match fork() with + 0 -> + begin try + perform_redirections new_stdin new_stdout new_stderr; + execvp cmd args + with _ -> + exit 127 + end + | id -> id + +let create_process_env cmd args env new_stdin new_stdout new_stderr = + match fork() with + 0 -> + begin try + perform_redirections new_stdin new_stdout new_stderr; + execvpe cmd args env + with _ -> + exit 127 + end + | id -> id + +type popen_process = + Process of in_channel * out_channel + | Process_in of in_channel + | Process_out of out_channel + | Process_full of in_channel * out_channel * in_channel + +let popen_processes = (Hashtbl.create 7 : (popen_process, int) Hashtbl.t) + +let open_proc cmd proc input output toclose = + let cloexec = List.for_all try_set_close_on_exec toclose in + match fork() with + 0 -> if input <> stdin then begin dup2 input stdin; close input end; + if output <> stdout then begin dup2 output stdout; close output end; + if not cloexec then List.iter close toclose; + begin try execv "/bin/sh" [| "/bin/sh"; "-c"; cmd |] + with _ -> exit 127 + end + | id -> Hashtbl.add popen_processes proc id + +let open_process_in cmd = + let (in_read, in_write) = pipe() in + let inchan = in_channel_of_descr in_read in + open_proc cmd (Process_in inchan) stdin in_write [in_read]; + close in_write; + inchan + +let open_process_out cmd = + let (out_read, out_write) = pipe() in + let outchan = out_channel_of_descr out_write in + open_proc cmd (Process_out outchan) out_read stdout [out_write]; + close out_read; + outchan + +let open_process cmd = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + open_proc cmd (Process(inchan, outchan)) out_read in_write + [in_read; out_write]; + close out_read; + close in_write; + (inchan, outchan) + +let open_proc_full cmd env proc input output error toclose = + let cloexec = List.for_all try_set_close_on_exec toclose in + match fork() with + 0 -> dup2 input stdin; close input; + dup2 output stdout; close output; + dup2 error stderr; close error; + if not cloexec then List.iter close toclose; + begin try execve "/bin/sh" [| "/bin/sh"; "-c"; cmd |] env + with _ -> exit 127 + end + | id -> Hashtbl.add popen_processes proc id + +let open_process_full cmd env = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + let (err_read, err_write) = pipe() in + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + let errchan = in_channel_of_descr err_read in + open_proc_full cmd env (Process_full(inchan, outchan, errchan)) + out_read in_write err_write [in_read; out_write; err_read]; + close out_read; + close in_write; + close err_write; + (inchan, outchan, errchan) + +let find_proc_id fun_name proc = + try + let pid = Hashtbl.find popen_processes proc in + Hashtbl.remove popen_processes proc; + pid + with Not_found -> + raise(Unix_error(EBADF, fun_name, "")) + +let rec waitpid_non_intr pid = + try waitpid [] pid + with Unix_error (EINTR, _, _) -> waitpid_non_intr pid + +let close_process_in inchan = + let pid = find_proc_id "close_process_in" (Process_in inchan) in + close_in inchan; + snd(waitpid_non_intr pid) + +let close_process_out outchan = + let pid = find_proc_id "close_process_out" (Process_out outchan) in + close_out outchan; + snd(waitpid_non_intr pid) + +let close_process (inchan, outchan) = + let pid = find_proc_id "close_process" (Process(inchan, outchan)) in + close_in inchan; + begin try close_out outchan with Sys_error _ -> () end; + snd(waitpid_non_intr pid) + +let close_process_full (inchan, outchan, errchan) = + let pid = + find_proc_id "close_process_full" + (Process_full(inchan, outchan, errchan)) in + close_in inchan; + begin try close_out outchan with Sys_error _ -> () end; + close_in errchan; + snd(waitpid_non_intr pid) + +(* High-level network functions *) + +let open_connection sockaddr = + let sock = + socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in + try + connect sock sockaddr; + ignore(try_set_close_on_exec sock); + (in_channel_of_descr sock, out_channel_of_descr sock) + with exn -> + close sock; raise exn + +let shutdown_connection inchan = + shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND + +let rec accept_non_intr s = + try accept s + with Unix_error (EINTR, _, _) -> accept_non_intr s + +let establish_server server_fun sockaddr = + let sock = + socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in + setsockopt sock SO_REUSEADDR true; + bind sock sockaddr; + listen sock 5; + while true do + let (s, caller) = accept_non_intr sock in + (* The "double fork" trick, the process which calls server_fun will not + leave a zombie process *) + match fork() with + 0 -> if fork() <> 0 then exit 0; (* The son exits, the grandson works *) + close sock; + ignore(try_set_close_on_exec s); + let inchan = in_channel_of_descr s in + let outchan = out_channel_of_descr s in + server_fun inchan outchan; + (* Do not close inchan nor outchan, as the server_fun could + have done it already, and we are about to exit anyway + (PR#3794) *) + exit 0 + | id -> close s; ignore(waitpid_non_intr id) (* Reclaim the son *) + done + diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli new file mode 100644 index 0000000..840ff04 --- /dev/null +++ b/otherlibs/unix/unix.mli @@ -0,0 +1,1312 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unix.mli,v 1.89 2008-09-04 13:53:43 doligez Exp $ *) + +(** Interface to the Unix system *) + + +(** {6 Error report} *) + + +type error = + E2BIG (** Argument list too long *) + | EACCES (** Permission denied *) + | EAGAIN (** Resource temporarily unavailable; try again *) + | EBADF (** Bad file descriptor *) + | EBUSY (** Resource unavailable *) + | ECHILD (** No child process *) + | EDEADLK (** Resource deadlock would occur *) + | EDOM (** Domain error for math functions, etc. *) + | EEXIST (** File exists *) + | EFAULT (** Bad address *) + | EFBIG (** File too large *) + | EINTR (** Function interrupted by signal *) + | EINVAL (** Invalid argument *) + | EIO (** Hardware I/O error *) + | EISDIR (** Is a directory *) + | EMFILE (** Too many open files by the process *) + | EMLINK (** Too many links *) + | ENAMETOOLONG (** Filename too long *) + | ENFILE (** Too many open files in the system *) + | ENODEV (** No such device *) + | ENOENT (** No such file or directory *) + | ENOEXEC (** Not an executable file *) + | ENOLCK (** No locks available *) + | ENOMEM (** Not enough memory *) + | ENOSPC (** No space left on device *) + | ENOSYS (** Function not supported *) + | ENOTDIR (** Not a directory *) + | ENOTEMPTY (** Directory not empty *) + | ENOTTY (** Inappropriate I/O control operation *) + | ENXIO (** No such device or address *) + | EPERM (** Operation not permitted *) + | EPIPE (** Broken pipe *) + | ERANGE (** Result too large *) + | EROFS (** Read-only file system *) + | ESPIPE (** Invalid seek e.g. on a pipe *) + | ESRCH (** No such process *) + | EXDEV (** Invalid link *) + | EWOULDBLOCK (** Operation would block *) + | EINPROGRESS (** Operation now in progress *) + | EALREADY (** Operation already in progress *) + | ENOTSOCK (** Socket operation on non-socket *) + | EDESTADDRREQ (** Destination address required *) + | EMSGSIZE (** Message too long *) + | EPROTOTYPE (** Protocol wrong type for socket *) + | ENOPROTOOPT (** Protocol not available *) + | EPROTONOSUPPORT (** Protocol not supported *) + | ESOCKTNOSUPPORT (** Socket type not supported *) + | EOPNOTSUPP (** Operation not supported on socket *) + | EPFNOSUPPORT (** Protocol family not supported *) + | EAFNOSUPPORT (** Address family not supported by protocol family *) + | EADDRINUSE (** Address already in use *) + | EADDRNOTAVAIL (** Can't assign requested address *) + | ENETDOWN (** Network is down *) + | ENETUNREACH (** Network is unreachable *) + | ENETRESET (** Network dropped connection on reset *) + | ECONNABORTED (** Software caused connection abort *) + | ECONNRESET (** Connection reset by peer *) + | ENOBUFS (** No buffer space available *) + | EISCONN (** Socket is already connected *) + | ENOTCONN (** Socket is not connected *) + | ESHUTDOWN (** Can't send after socket shutdown *) + | ETOOMANYREFS (** Too many references: can't splice *) + | ETIMEDOUT (** Connection timed out *) + | ECONNREFUSED (** Connection refused *) + | EHOSTDOWN (** Host is down *) + | EHOSTUNREACH (** No route to host *) + | ELOOP (** Too many levels of symbolic links *) + | EOVERFLOW (** File size or position not representable *) + + | EUNKNOWNERR of int (** Unknown error *) +(** The type of error codes. + Errors defined in the POSIX standard + and additional errors from UNIX98 and BSD. + All other errors are mapped to EUNKNOWNERR. +*) + + +exception Unix_error of error * string * string +(** Raised by the system calls below when an error is encountered. + The first component is the error code; the second component + is the function name; the third component is the string parameter + to the function, if it has one, or the empty string otherwise. *) + +val error_message : error -> string +(** Return a string describing the given error code. *) + +val handle_unix_error : ('a -> 'b) -> 'a -> 'b +(** [handle_unix_error f x] applies [f] to [x] and returns the result. + If the exception [Unix_error] is raised, it prints a message + describing the error and exits with code 2. *) + + +(** {6 Access to the process environment} *) + + +val environment : unit -> string array +(** Return the process environment, as an array of strings + with the format ``variable=value''. *) + +val getenv : string -> string +(** Return the value associated to a variable in the process + environment. Raise [Not_found] if the variable is unbound. + (This function is identical to [Sys.getenv].) *) + +val putenv : string -> string -> unit +(** [Unix.putenv name value] sets the value associated to a + variable in the process environment. + [name] is the name of the environment variable, + and [value] its new associated value. *) + + +(** {6 Process handling} *) + + +type process_status = + WEXITED of int + (** The process terminated normally by [exit]; + the argument is the return code. *) + | WSIGNALED of int + (** The process was killed by a signal; + the argument is the signal number. *) + | WSTOPPED of int + (** The process was stopped by a signal; the argument is the + signal number. *) +(** The termination status of a process. See module {!Sys} for the + definitions of the standard signal numbers. Note that they are + not the numbers used by the OS. *) + + +type wait_flag = + WNOHANG (** do not block if no child has + died yet, but immediately return with a pid equal to 0.*) + | WUNTRACED (** report also the children that receive stop signals. *) +(** Flags for {!Unix.waitpid}. *) + +val execv : string -> string array -> 'a +(** [execv prog args] execute the program in file [prog], with + the arguments [args], and the current process environment. + These [execv*] functions never return: on success, the current + program is replaced by the new one; + on failure, a {!Unix.Unix_error} exception is raised. *) + +val execve : string -> string array -> string array -> 'a +(** Same as {!Unix.execv}, except that the third argument provides the + environment to the program executed. *) + +val execvp : string -> string array -> 'a +(** Same as {!Unix.execv}, except that + the program is searched in the path. *) + +val execvpe : string -> string array -> string array -> 'a +(** Same as {!Unix.execve}, except that + the program is searched in the path. *) + +val fork : unit -> int +(** Fork a new process. The returned integer is 0 for the child + process, the pid of the child process for the parent process. *) + +val wait : unit -> int * process_status +(** Wait until one of the children processes die, and return its pid + and termination status. *) + +val waitpid : wait_flag list -> int -> int * process_status +(** Same as {!Unix.wait}, but waits for the child process whose pid is given. + A pid of [-1] means wait for any child. + A pid of [0] means wait for any child in the same process group + as the current process. + Negative pid arguments represent process groups. + The list of options indicates whether [waitpid] should return + immediately without waiting, or also report stopped children. *) + +val system : string -> process_status +(** Execute the given command, wait until it terminates, and return + its termination status. The string is interpreted by the shell + [/bin/sh] and therefore can contain redirections, quotes, variables, + etc. The result [WEXITED 127] indicates that the shell couldn't + be executed. *) + +val getpid : unit -> int +(** Return the pid of the process. *) + +val getppid : unit -> int +(** Return the pid of the parent process. *) + +val nice : int -> int +(** Change the process priority. The integer argument is added to the + ``nice'' value. (Higher values of the ``nice'' value mean + lower priorities.) Return the new nice value. *) + + +(** {6 Basic file input/output} *) + + +type file_descr +(** The abstract type of file descriptors. *) + +val stdin : file_descr +(** File descriptor for standard input.*) + +val stdout : file_descr +(** File descriptor for standard output.*) + +val stderr : file_descr +(** File descriptor for standard error. *) + +type open_flag = + O_RDONLY (** Open for reading *) + | O_WRONLY (** Open for writing *) + | O_RDWR (** Open for reading and writing *) + | O_NONBLOCK (** Open in non-blocking mode *) + | O_APPEND (** Open for append *) + | O_CREAT (** Create if nonexistent *) + | O_TRUNC (** Truncate to 0 length if existing *) + | O_EXCL (** Fail if existing *) + | O_NOCTTY (** Don't make this dev a controlling tty *) + | O_DSYNC (** Writes complete as `Synchronised I/O data integrity completion' *) + | O_SYNC (** Writes complete as `Synchronised I/O file integrity completion' *) + | O_RSYNC (** Reads complete as writes (depending on O_SYNC/O_DSYNC) *) +(** The flags to {!Unix.openfile}. *) + + +type file_perm = int +(** The type of file access rights, e.g. [0o640] is read and write for user, + read for group, none for others *) + +val openfile : string -> open_flag list -> file_perm -> file_descr +(** Open the named file with the given flags. Third argument is + the permissions to give to the file if it is created. Return + a file descriptor on the named file. *) + +val close : file_descr -> unit +(** Close a file descriptor. *) + +val read : file_descr -> string -> int -> int -> int +(** [read fd buff ofs len] reads [len] characters from descriptor + [fd], storing them in string [buff], starting at position [ofs] + in string [buff]. Return the number of characters actually read. *) + +val write : file_descr -> string -> int -> int -> int +(** [write fd buff ofs len] writes [len] characters to descriptor + [fd], taking them from string [buff], starting at position [ofs] + in string [buff]. Return the number of characters actually + written. [write] repeats the writing operation until all characters + have been written or an error occurs. *) + +val single_write : file_descr -> string -> int -> int -> int +(** Same as [write], but attempts to write only once. + Thus, if an error occurs, [single_write] guarantees that no data + has been written. *) + +(** {6 Interfacing with the standard input/output library} *) + + + +val in_channel_of_descr : file_descr -> in_channel +(** Create an input channel reading from the given descriptor. + The channel is initially in binary mode; use + [set_binary_mode_in ic false] if text mode is desired. *) + +val out_channel_of_descr : file_descr -> out_channel +(** Create an output channel writing on the given descriptor. + The channel is initially in binary mode; use + [set_binary_mode_out oc false] if text mode is desired. *) + +val descr_of_in_channel : in_channel -> file_descr +(** Return the descriptor corresponding to an input channel. *) + +val descr_of_out_channel : out_channel -> file_descr +(** Return the descriptor corresponding to an output channel. *) + + +(** {6 Seeking and truncating} *) + + +type seek_command = + SEEK_SET (** indicates positions relative to the beginning of the file *) + | SEEK_CUR (** indicates positions relative to the current position *) + | SEEK_END (** indicates positions relative to the end of the file *) +(** Positioning modes for {!Unix.lseek}. *) + + +val lseek : file_descr -> int -> seek_command -> int +(** Set the current position for a file descriptor *) + +val truncate : string -> int -> unit +(** Truncates the named file to the given size. *) + +val ftruncate : file_descr -> int -> unit +(** Truncates the file corresponding to the given descriptor + to the given size. *) + + +(** {6 File status} *) + + +type file_kind = + S_REG (** Regular file *) + | S_DIR (** Directory *) + | S_CHR (** Character device *) + | S_BLK (** Block device *) + | S_LNK (** Symbolic link *) + | S_FIFO (** Named pipe *) + | S_SOCK (** Socket *) + +type stats = + { st_dev : int; (** Device number *) + st_ino : int; (** Inode number *) + st_kind : file_kind; (** Kind of the file *) + st_perm : file_perm; (** Access rights *) + st_nlink : int; (** Number of links *) + st_uid : int; (** User id of the owner *) + st_gid : int; (** Group ID of the file's group *) + st_rdev : int; (** Device minor number *) + st_size : int; (** Size in bytes *) + st_atime : float; (** Last access time *) + st_mtime : float; (** Last modification time *) + st_ctime : float; (** Last status change time *) + } +(** The informations returned by the {!Unix.stat} calls. *) + +val stat : string -> stats +(** Return the information for the named file. *) + +val lstat : string -> stats +(** Same as {!Unix.stat}, but in case the file is a symbolic link, + return the information for the link itself. *) + +val fstat : file_descr -> stats +(** Return the information for the file associated with the given + descriptor. *) + +val isatty : file_descr -> bool +(** Return [true] if the given file descriptor refers to a terminal or + console window, [false] otherwise. *) + +(** {6 File operations on large files} *) + +module LargeFile : + sig + val lseek : file_descr -> int64 -> seek_command -> int64 + val truncate : string -> int64 -> unit + val ftruncate : file_descr -> int64 -> unit + type stats = + { st_dev : int; (** Device number *) + st_ino : int; (** Inode number *) + st_kind : file_kind; (** Kind of the file *) + st_perm : file_perm; (** Access rights *) + st_nlink : int; (** Number of links *) + st_uid : int; (** User id of the owner *) + st_gid : int; (** Group ID of the file's group *) + st_rdev : int; (** Device minor number *) + st_size : int64; (** Size in bytes *) + st_atime : float; (** Last access time *) + st_mtime : float; (** Last modification time *) + st_ctime : float; (** Last status change time *) + } + val stat : string -> stats + val lstat : string -> stats + val fstat : file_descr -> stats + end +(** File operations on large files. + This sub-module provides 64-bit variants of the functions + {!Unix.lseek} (for positioning a file descriptor), + {!Unix.truncate} and {!Unix.ftruncate} (for changing the size of a file), + and {!Unix.stat}, {!Unix.lstat} and {!Unix.fstat} (for obtaining + information on files). These alternate functions represent + positions and sizes by 64-bit integers (type [int64]) instead of + regular integers (type [int]), thus allowing operating on files + whose sizes are greater than [max_int]. *) + + +(** {6 Operations on file names} *) + + +val unlink : string -> unit +(** Removes the named file *) + +val rename : string -> string -> unit +(** [rename old new] changes the name of a file from [old] to [new]. *) + +val link : string -> string -> unit +(** [link source dest] creates a hard link named [dest] to the file + named [source]. *) + + +(** {6 File permissions and ownership} *) + + +type access_permission = + R_OK (** Read permission *) + | W_OK (** Write permission *) + | X_OK (** Execution permission *) + | F_OK (** File exists *) +(** Flags for the {!Unix.access} call. *) + + +val chmod : string -> file_perm -> unit +(** Change the permissions of the named file. *) + +val fchmod : file_descr -> file_perm -> unit +(** Change the permissions of an opened file. *) + +val chown : string -> int -> int -> unit +(** Change the owner uid and owner gid of the named file. *) + +val fchown : file_descr -> int -> int -> unit +(** Change the owner uid and owner gid of an opened file. *) + +val umask : int -> int +(** Set the process's file mode creation mask, and return the previous + mask. *) + +val access : string -> access_permission list -> unit +(** Check that the process has the given permissions over the named + file. Raise [Unix_error] otherwise. *) + + +(** {6 Operations on file descriptors} *) + + +val dup : file_descr -> file_descr +(** Return a new file descriptor referencing the same file as + the given descriptor. *) + +val dup2 : file_descr -> file_descr -> unit +(** [dup2 fd1 fd2] duplicates [fd1] to [fd2], closing [fd2] if already + opened. *) + +val set_nonblock : file_descr -> unit +(** Set the ``non-blocking'' flag on the given descriptor. + When the non-blocking flag is set, reading on a descriptor + on which there is temporarily no data available raises the + [EAGAIN] or [EWOULDBLOCK] error instead of blocking; + writing on a descriptor on which there is temporarily no room + for writing also raises [EAGAIN] or [EWOULDBLOCK]. *) + +val clear_nonblock : file_descr -> unit +(** Clear the ``non-blocking'' flag on the given descriptor. + See {!Unix.set_nonblock}.*) + +val set_close_on_exec : file_descr -> unit +(** Set the ``close-on-exec'' flag on the given descriptor. + A descriptor with the close-on-exec flag is automatically + closed when the current process starts another program with + one of the [exec] functions. *) + +val clear_close_on_exec : file_descr -> unit +(** Clear the ``close-on-exec'' flag on the given descriptor. + See {!Unix.set_close_on_exec}.*) + + +(** {6 Directories} *) + + +val mkdir : string -> file_perm -> unit +(** Create a directory with the given permissions. *) + +val rmdir : string -> unit +(** Remove an empty directory. *) + +val chdir : string -> unit +(** Change the process working directory. *) + +val getcwd : unit -> string +(** Return the name of the current working directory. *) + +val chroot : string -> unit +(** Change the process root directory. *) + +type dir_handle +(** The type of descriptors over opened directories. *) + +val opendir : string -> dir_handle +(** Open a descriptor on a directory *) + +val readdir : dir_handle -> string +(** Return the next entry in a directory. + @raise End_of_file when the end of the directory has been reached. *) + +val rewinddir : dir_handle -> unit +(** Reposition the descriptor to the beginning of the directory *) + +val closedir : dir_handle -> unit +(** Close a directory descriptor. *) + + + +(** {6 Pipes and redirections} *) + + +val pipe : unit -> file_descr * file_descr +(** Create a pipe. The first component of the result is opened + for reading, that's the exit to the pipe. The second component is + opened for writing, that's the entrance to the pipe. *) + +val mkfifo : string -> file_perm -> unit +(** Create a named pipe with the given permissions. *) + + +(** {6 High-level process and redirection management} *) + + +val create_process : + string -> string array -> file_descr -> file_descr -> file_descr -> int +(** [create_process prog args new_stdin new_stdout new_stderr] + forks a new process that executes the program + in file [prog], with arguments [args]. The pid of the new + process is returned immediately; the new process executes + concurrently with the current process. + The standard input and outputs of the new process are connected + to the descriptors [new_stdin], [new_stdout] and [new_stderr]. + Passing e.g. [stdout] for [new_stdout] prevents the redirection + and causes the new process to have the same standard output + as the current process. + The executable file [prog] is searched in the path. + The new process has the same environment as the current process. *) + +val create_process_env : + string -> string array -> string array -> file_descr -> file_descr -> + file_descr -> int +(** [create_process_env prog args env new_stdin new_stdout new_stderr] + works as {!Unix.create_process}, except that the extra argument + [env] specifies the environment passed to the program. *) + + +val open_process_in : string -> in_channel +(** High-level pipe and process management. This function + runs the given command in parallel with the program. + The standard output of the command is redirected to a pipe, + which can be read via the returned input channel. + The command is interpreted by the shell [/bin/sh] (cf. [system]). *) + +val open_process_out : string -> out_channel +(** Same as {!Unix.open_process_in}, but redirect the standard input of + the command to a pipe. Data written to the returned output channel + is sent to the standard input of the command. + Warning: writes on output channels are buffered, hence be careful + to call {!Pervasives.flush} at the right times to ensure + correct synchronization. *) + +val open_process : string -> in_channel * out_channel +(** Same as {!Unix.open_process_out}, but redirects both the standard input + and standard output of the command to pipes connected to the two + returned channels. The input channel is connected to the output + of the command, and the output channel to the input of the command. *) + +val open_process_full : + string -> string array -> in_channel * out_channel * in_channel +(** Similar to {!Unix.open_process}, but the second argument specifies + the environment passed to the command. The result is a triple + of channels connected respectively to the standard output, standard input, + and standard error of the command. *) + +val close_process_in : in_channel -> process_status +(** Close channels opened by {!Unix.open_process_in}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process_out : out_channel -> process_status +(** Close channels opened by {!Unix.open_process_out}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process : in_channel * out_channel -> process_status +(** Close channels opened by {!Unix.open_process}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process_full : + in_channel * out_channel * in_channel -> process_status +(** Close channels opened by {!Unix.open_process_full}, + wait for the associated command to terminate, + and return its termination status. *) + + +(** {6 Symbolic links} *) + + +val symlink : string -> string -> unit +(** [symlink source dest] creates the file [dest] as a symbolic link + to the file [source]. *) + +val readlink : string -> string +(** Read the contents of a link. *) + + +(** {6 Polling} *) + + +val select : + file_descr list -> file_descr list -> file_descr list -> float -> + file_descr list * file_descr list * file_descr list +(** Wait until some input/output operations become possible on + some channels. The three list arguments are, respectively, a set + of descriptors to check for reading (first argument), for writing + (second argument), or for exceptional conditions (third argument). + The fourth argument is the maximal timeout, in seconds; a + negative fourth argument means no timeout (unbounded wait). + The result is composed of three sets of descriptors: those ready + for reading (first component), ready for writing (second component), + and over which an exceptional condition is pending (third + component). *) + +(** {6 Locking} *) + + +type lock_command = + F_ULOCK (** Unlock a region *) + | F_LOCK (** Lock a region for writing, and block if already locked *) + | F_TLOCK (** Lock a region for writing, or fail if already locked *) + | F_TEST (** Test a region for other process locks *) + | F_RLOCK (** Lock a region for reading, and block if already locked *) + | F_TRLOCK (** Lock a region for reading, or fail if already locked *) +(** Commands for {!Unix.lockf}. *) + +val lockf : file_descr -> lock_command -> int -> unit +(** [lockf fd cmd size] puts a lock on a region of the file opened + as [fd]. The region starts at the current read/write position for + [fd] (as set by {!Unix.lseek}), and extends [size] bytes forward if + [size] is positive, [size] bytes backwards if [size] is negative, + or to the end of the file if [size] is zero. + A write lock prevents any other + process from acquiring a read or write lock on the region. + A read lock prevents any other + process from acquiring a write lock on the region, but lets + other processes acquire read locks on it. + + The [F_LOCK] and [F_TLOCK] commands attempts to put a write lock + on the specified region. + The [F_RLOCK] and [F_TRLOCK] commands attempts to put a read lock + on the specified region. + If one or several locks put by another process prevent the current process + from acquiring the lock, [F_LOCK] and [F_RLOCK] block until these locks + are removed, while [F_TLOCK] and [F_TRLOCK] fail immediately with an + exception. + The [F_ULOCK] removes whatever locks the current process has on + the specified region. + Finally, the [F_TEST] command tests whether a write lock can be + acquired on the specified region, without actually putting a lock. + It returns immediately if successful, or fails otherwise. *) + + +(** {6 Signals} + Note: installation of signal handlers is performed via + the functions {!Sys.signal} and {!Sys.set_signal}. +*) + +val kill : int -> int -> unit +(** [kill pid sig] sends signal number [sig] to the process + with id [pid]. *) + +type sigprocmask_command = + SIG_SETMASK + | SIG_BLOCK + | SIG_UNBLOCK + +val sigprocmask : sigprocmask_command -> int list -> int list +(** [sigprocmask cmd sigs] changes the set of blocked signals. + If [cmd] is [SIG_SETMASK], blocked signals are set to those in + the list [sigs]. + If [cmd] is [SIG_BLOCK], the signals in [sigs] are added to + the set of blocked signals. + If [cmd] is [SIG_UNBLOCK], the signals in [sigs] are removed + from the set of blocked signals. + [sigprocmask] returns the set of previously blocked signals. *) + +val sigpending : unit -> int list +(** Return the set of blocked signals that are currently pending. *) + +val sigsuspend : int list -> unit +(** [sigsuspend sigs] atomically sets the blocked signals to [sigs] + and waits for a non-ignored, non-blocked signal to be delivered. + On return, the blocked signals are reset to their initial value. *) + +val pause : unit -> unit +(** Wait until a non-ignored, non-blocked signal is delivered. *) + + +(** {6 Time functions} *) + + +type process_times = + { tms_utime : float; (** User time for the process *) + tms_stime : float; (** System time for the process *) + tms_cutime : float; (** User time for the children processes *) + tms_cstime : float; (** System time for the children processes *) + } +(** The execution times (CPU times) of a process. *) + +type tm = + { tm_sec : int; (** Seconds 0..60 *) + tm_min : int; (** Minutes 0..59 *) + tm_hour : int; (** Hours 0..23 *) + tm_mday : int; (** Day of month 1..31 *) + tm_mon : int; (** Month of year 0..11 *) + tm_year : int; (** Year - 1900 *) + tm_wday : int; (** Day of week (Sunday is 0) *) + tm_yday : int; (** Day of year 0..365 *) + tm_isdst : bool; (** Daylight time savings in effect *) + } +(** The type representing wallclock time and calendar date. *) + + +val time : unit -> float +(** Return the current time since 00:00:00 GMT, Jan. 1, 1970, + in seconds. *) + +val gettimeofday : unit -> float +(** Same as {!Unix.time}, but with resolution better than 1 second. *) + +val gmtime : float -> tm +(** Convert a time in seconds, as returned by {!Unix.time}, into a date and + a time. Assumes UTC (Coordinated Universal Time), also known as GMT. *) + +val localtime : float -> tm +(** Convert a time in seconds, as returned by {!Unix.time}, into a date and + a time. Assumes the local time zone. *) + +val mktime : tm -> float * tm +(** Convert a date and time, specified by the [tm] argument, into + a time in seconds, as returned by {!Unix.time}. The [tm_isdst], + [tm_wday] and [tm_yday] fields of [tm] are ignored. Also return a + normalized copy of the given [tm] record, with the [tm_wday], + [tm_yday], and [tm_isdst] fields recomputed from the other fields, + and the other fields normalized (so that, e.g., 40 October is + changed into 9 November). The [tm] argument is interpreted in the + local time zone. *) + +val alarm : int -> int +(** Schedule a [SIGALRM] signal after the given number of seconds. *) + +val sleep : int -> unit +(** Stop execution for the given number of seconds. *) + +val times : unit -> process_times +(** Return the execution times of the process. *) + +val utimes : string -> float -> float -> unit +(** Set the last access time (second arg) and last modification time + (third arg) for a file. Times are expressed in seconds from + 00:00:00 GMT, Jan. 1, 1970. A time of [0.0] is interpreted as the + current time. *) + +type interval_timer = + ITIMER_REAL + (** decrements in real time, and sends the signal [SIGALRM] when expired.*) + | ITIMER_VIRTUAL + (** decrements in process virtual time, and sends [SIGVTALRM] when expired. *) + | ITIMER_PROF + (** (for profiling) decrements both when the process + is running and when the system is running on behalf of the + process; it sends [SIGPROF] when expired. *) +(** The three kinds of interval timers. *) + +type interval_timer_status = + { it_interval : float; (** Period *) + it_value : float; (** Current value of the timer *) + } +(** The type describing the status of an interval timer *) + +val getitimer : interval_timer -> interval_timer_status +(** Return the current status of the given interval timer. *) + +val setitimer : + interval_timer -> interval_timer_status -> interval_timer_status +(** [setitimer t s] sets the interval timer [t] and returns + its previous status. The [s] argument is interpreted as follows: + [s.it_value], if nonzero, is the time to the next timer expiration; + [s.it_interval], if nonzero, specifies a value to + be used in reloading it_value when the timer expires. + Setting [s.it_value] to zero disable the timer. + Setting [s.it_interval] to zero causes the timer to be disabled + after its next expiration. *) + + +(** {6 User id, group id} *) + + +val getuid : unit -> int +(** Return the user id of the user executing the process. *) + +val geteuid : unit -> int +(** Return the effective user id under which the process runs. *) + +val setuid : int -> unit +(** Set the real user id and effective user id for the process. *) + +val getgid : unit -> int +(** Return the group id of the user executing the process. *) + +val getegid : unit -> int +(** Return the effective group id under which the process runs. *) + +val setgid : int -> unit +(** Set the real group id and effective group id for the process. *) + +val getgroups : unit -> int array +(** Return the list of groups to which the user executing the process + belongs. *) + +type passwd_entry = + { pw_name : string; + pw_passwd : string; + pw_uid : int; + pw_gid : int; + pw_gecos : string; + pw_dir : string; + pw_shell : string + } +(** Structure of entries in the [passwd] database. *) + +type group_entry = + { gr_name : string; + gr_passwd : string; + gr_gid : int; + gr_mem : string array + } +(** Structure of entries in the [groups] database. *) + +val getlogin : unit -> string +(** Return the login name of the user executing the process. *) + +val getpwnam : string -> passwd_entry +(** Find an entry in [passwd] with the given name, or raise + [Not_found]. *) + +val getgrnam : string -> group_entry +(** Find an entry in [group] with the given name, or raise + [Not_found]. *) + +val getpwuid : int -> passwd_entry +(** Find an entry in [passwd] with the given user id, or raise + [Not_found]. *) + +val getgrgid : int -> group_entry +(** Find an entry in [group] with the given group id, or raise + [Not_found]. *) + + +(** {6 Internet addresses} *) + + +type inet_addr +(** The abstract type of Internet addresses. *) + +val inet_addr_of_string : string -> inet_addr +(** Conversion from the printable representation of an Internet + address to its internal representation. The argument string + consists of 4 numbers separated by periods ([XXX.YYY.ZZZ.TTT]) + for IPv4 addresses, and up to 8 numbers separated by colons + for IPv6 addresses. Raise [Failure] when given a string that + does not match these formats. *) + +val string_of_inet_addr : inet_addr -> string +(** Return the printable representation of the given Internet address. + See {!Unix.inet_addr_of_string} for a description of the + printable representation. *) + +val inet_addr_any : inet_addr +(** A special IPv4 address, for use only with [bind], representing + all the Internet addresses that the host machine possesses. *) + +val inet_addr_loopback : inet_addr +(** A special IPv4 address representing the host machine ([127.0.0.1]). *) + +val inet6_addr_any : inet_addr +(** A special IPv6 address, for use only with [bind], representing + all the Internet addresses that the host machine possesses. *) + +val inet6_addr_loopback : inet_addr +(** A special IPv6 address representing the host machine ([::1]). *) + + +(** {6 Sockets} *) + + +type socket_domain = + PF_UNIX (** Unix domain *) + | PF_INET (** Internet domain (IPv4) *) + | PF_INET6 (** Internet domain (IPv6) *) +(** The type of socket domains. *) + +type socket_type = + SOCK_STREAM (** Stream socket *) + | SOCK_DGRAM (** Datagram socket *) + | SOCK_RAW (** Raw socket *) + | SOCK_SEQPACKET (** Sequenced packets socket *) +(** The type of socket kinds, specifying the semantics of + communications. *) + +type sockaddr = ADDR_UNIX of string | ADDR_INET of inet_addr * int +(** The type of socket addresses. [ADDR_UNIX name] is a socket + address in the Unix domain; [name] is a file name in the file + system. [ADDR_INET(addr,port)] is a socket address in the Internet + domain; [addr] is the Internet address of the machine, and + [port] is the port number. *) + +val socket : socket_domain -> socket_type -> int -> file_descr +(** Create a new socket in the given domain, and with the + given kind. The third argument is the protocol type; 0 selects + the default protocol for that kind of sockets. *) + +val domain_of_sockaddr: sockaddr -> socket_domain +(** Return the socket domain adequate for the given socket address. *) + +val socketpair : + socket_domain -> socket_type -> int -> file_descr * file_descr +(** Create a pair of unnamed sockets, connected together. *) + +val accept : file_descr -> file_descr * sockaddr +(** Accept connections on the given socket. The returned descriptor + is a socket connected to the client; the returned address is + the address of the connecting client. *) + +val bind : file_descr -> sockaddr -> unit +(** Bind a socket to an address. *) + +val connect : file_descr -> sockaddr -> unit +(** Connect a socket to an address. *) + +val listen : file_descr -> int -> unit +(** Set up a socket for receiving connection requests. The integer + argument is the maximal number of pending requests. *) + +type shutdown_command = + SHUTDOWN_RECEIVE (** Close for receiving *) + | SHUTDOWN_SEND (** Close for sending *) + | SHUTDOWN_ALL (** Close both *) +(** The type of commands for [shutdown]. *) + + +val shutdown : file_descr -> shutdown_command -> unit +(** Shutdown a socket connection. [SHUTDOWN_SEND] as second argument + causes reads on the other end of the connection to return + an end-of-file condition. + [SHUTDOWN_RECEIVE] causes writes on the other end of the connection + to return a closed pipe condition ([SIGPIPE] signal). *) + +val getsockname : file_descr -> sockaddr +(** Return the address of the given socket. *) + +val getpeername : file_descr -> sockaddr +(** Return the address of the host connected to the given socket. *) + +type msg_flag = + MSG_OOB + | MSG_DONTROUTE + | MSG_PEEK +(** The flags for {!Unix.recv}, {!Unix.recvfrom}, + {!Unix.send} and {!Unix.sendto}. *) + +val recv : file_descr -> string -> int -> int -> msg_flag list -> int +(** Receive data from a connected socket. *) + +val recvfrom : + file_descr -> string -> int -> int -> msg_flag list -> int * sockaddr +(** Receive data from an unconnected socket. *) + +val send : file_descr -> string -> int -> int -> msg_flag list -> int +(** Send data over a connected socket. *) + +val sendto : + file_descr -> string -> int -> int -> msg_flag list -> sockaddr -> int +(** Send data over an unconnected socket. *) + + + +(** {6 Socket options} *) + + +type socket_bool_option = + SO_DEBUG (** Record debugging information *) + | SO_BROADCAST (** Permit sending of broadcast messages *) + | SO_REUSEADDR (** Allow reuse of local addresses for bind *) + | SO_KEEPALIVE (** Keep connection active *) + | SO_DONTROUTE (** Bypass the standard routing algorithms *) + | SO_OOBINLINE (** Leave out-of-band data in line *) + | SO_ACCEPTCONN (** Report whether socket listening is enabled *) + | TCP_NODELAY (** Control the Nagle algorithm for TCP sockets *) + | IPV6_ONLY (** Forbid binding an IPv6 socket to an IPv4 address *) +(** The socket options that can be consulted with {!Unix.getsockopt} + and modified with {!Unix.setsockopt}. These options have a boolean + ([true]/[false]) value. *) + +type socket_int_option = + SO_SNDBUF (** Size of send buffer *) + | SO_RCVBUF (** Size of received buffer *) + | SO_ERROR (** Deprecated. Use {!Unix.getsockopt_error} instead. *) + | SO_TYPE (** Report the socket type *) + | SO_RCVLOWAT (** Minimum number of bytes to process for input operations *) + | SO_SNDLOWAT (** Minimum number of bytes to process for output operations *) +(** The socket options that can be consulted with {!Unix.getsockopt_int} + and modified with {!Unix.setsockopt_int}. These options have an + integer value. *) + +type socket_optint_option = + SO_LINGER (** Whether to linger on closed connections + that have data present, and for how long + (in seconds) *) +(** The socket options that can be consulted with {!Unix.getsockopt_optint} + and modified with {!Unix.setsockopt_optint}. These options have a + value of type [int option], with [None] meaning ``disabled''. *) + +type socket_float_option = + SO_RCVTIMEO (** Timeout for input operations *) + | SO_SNDTIMEO (** Timeout for output operations *) +(** The socket options that can be consulted with {!Unix.getsockopt_float} + and modified with {!Unix.setsockopt_float}. These options have a + floating-point value representing a time in seconds. + The value 0 means infinite timeout. *) + +val getsockopt : file_descr -> socket_bool_option -> bool +(** Return the current status of a boolean-valued option + in the given socket. *) + +val setsockopt : file_descr -> socket_bool_option -> bool -> unit +(** Set or clear a boolean-valued option in the given socket. *) + +val getsockopt_int : file_descr -> socket_int_option -> int +(** Same as {!Unix.getsockopt} for an integer-valued socket option. *) + +val setsockopt_int : file_descr -> socket_int_option -> int -> unit +(** Same as {!Unix.setsockopt} for an integer-valued socket option. *) + +val getsockopt_optint : file_descr -> socket_optint_option -> int option +(** Same as {!Unix.getsockopt} for a socket option whose value is an [int option]. *) + +val setsockopt_optint : + file_descr -> socket_optint_option -> int option -> unit +(** Same as {!Unix.setsockopt} for a socket option whose value is an [int option]. *) + +val getsockopt_float : file_descr -> socket_float_option -> float +(** Same as {!Unix.getsockopt} for a socket option whose value is a floating-point number. *) + +val setsockopt_float : file_descr -> socket_float_option -> float -> unit +(** Same as {!Unix.setsockopt} for a socket option whose value is a floating-point number. *) + +val getsockopt_error : file_descr -> error option +(** Return the error condition associated with the given socket, + and clear it. *) + +(** {6 High-level network connection functions} *) + + +val open_connection : sockaddr -> in_channel * out_channel +(** Connect to a server at the given address. + Return a pair of buffered channels connected to the server. + Remember to call {!Pervasives.flush} on the output channel at the right + times to ensure correct synchronization. *) + +val shutdown_connection : in_channel -> unit +(** ``Shut down'' a connection established with {!Unix.open_connection}; + that is, transmit an end-of-file condition to the server reading + on the other side of the connection. *) + +val establish_server : (in_channel -> out_channel -> unit) -> sockaddr -> unit +(** Establish a server on the given address. + The function given as first argument is called for each connection + with two buffered channels connected to the client. A new process + is created for each connection. The function {!Unix.establish_server} + never returns normally. *) + + +(** {6 Host and protocol databases} *) + + +type host_entry = + { h_name : string; + h_aliases : string array; + h_addrtype : socket_domain; + h_addr_list : inet_addr array + } +(** Structure of entries in the [hosts] database. *) + +type protocol_entry = + { p_name : string; + p_aliases : string array; + p_proto : int + } +(** Structure of entries in the [protocols] database. *) + +type service_entry = + { s_name : string; + s_aliases : string array; + s_port : int; + s_proto : string + } +(** Structure of entries in the [services] database. *) + +val gethostname : unit -> string +(** Return the name of the local host. *) + +val gethostbyname : string -> host_entry +(** Find an entry in [hosts] with the given name, or raise + [Not_found]. *) + +val gethostbyaddr : inet_addr -> host_entry +(** Find an entry in [hosts] with the given address, or raise + [Not_found]. *) + +val getprotobyname : string -> protocol_entry +(** Find an entry in [protocols] with the given name, or raise + [Not_found]. *) + +val getprotobynumber : int -> protocol_entry +(** Find an entry in [protocols] with the given protocol number, + or raise [Not_found]. *) + +val getservbyname : string -> string -> service_entry +(** Find an entry in [services] with the given name, or raise + [Not_found]. *) + +val getservbyport : int -> string -> service_entry +(** Find an entry in [services] with the given service number, + or raise [Not_found]. *) + +type addr_info = + { ai_family : socket_domain; (** Socket domain *) + ai_socktype : socket_type; (** Socket type *) + ai_protocol : int; (** Socket protocol number *) + ai_addr : sockaddr; (** Address *) + ai_canonname : string (** Canonical host name *) + } +(** Address information returned by {!Unix.getaddrinfo}. *) + +type getaddrinfo_option = + AI_FAMILY of socket_domain (** Impose the given socket domain *) + | AI_SOCKTYPE of socket_type (** Impose the given socket type *) + | AI_PROTOCOL of int (** Impose the given protocol *) + | AI_NUMERICHOST (** Do not call name resolver, + expect numeric IP address *) + | AI_CANONNAME (** Fill the [ai_canonname] field + of the result *) + | AI_PASSIVE (** Set address to ``any'' address + for use with {!Unix.bind} *) +(** Options to {!Unix.getaddrinfo}. *) + +val getaddrinfo: + string -> string -> getaddrinfo_option list -> addr_info list +(** [getaddrinfo host service opts] returns a list of {!Unix.addr_info} + records describing socket parameters and addresses suitable for + communicating with the given host and service. The empty list is + returned if the host or service names are unknown, or the constraints + expressed in [opts] cannot be satisfied. + + [host] is either a host name or the string representation of an IP + address. [host] can be given as the empty string; in this case, + the ``any'' address or the ``loopback'' address are used, + depending whether [opts] contains [AI_PASSIVE]. + [service] is either a service name or the string representation of + a port number. [service] can be given as the empty string; + in this case, the port field of the returned addresses is set to 0. + [opts] is a possibly empty list of options that allows the caller + to force a particular socket domain (e.g. IPv6 only or IPv4 only) + or a particular socket type (e.g. TCP only or UDP only). *) + +type name_info = + { ni_hostname : string; (** Name or IP address of host *) + ni_service : string } (** Name of service or port number *) +(** Host and service information returned by {!Unix.getnameinfo}. *) + +type getnameinfo_option = + NI_NOFQDN (** Do not qualify local host names *) + | NI_NUMERICHOST (** Always return host as IP address *) + | NI_NAMEREQD (** Fail if host name cannot be determined *) + | NI_NUMERICSERV (** Always return service as port number *) + | NI_DGRAM (** Consider the service as UDP-based + instead of the default TCP *) +(** Options to {!Unix.getnameinfo}. *) + +val getnameinfo : sockaddr -> getnameinfo_option list -> name_info +(** [getnameinfo addr opts] returns the host name and service name + corresponding to the socket address [addr]. [opts] is a possibly + empty list of options that governs how these names are obtained. + Raise [Not_found] if an error occurs. *) + + +(** {6 Terminal interface} *) + + +(** The following functions implement the POSIX standard terminal + interface. They provide control over asynchronous communication ports + and pseudo-terminals. Refer to the [termios] man page for a + complete description. *) + +type terminal_io = + { + (* input modes *) + mutable c_ignbrk : bool; (** Ignore the break condition. *) + mutable c_brkint : bool; (** Signal interrupt on break condition. *) + mutable c_ignpar : bool; (** Ignore characters with parity errors. *) + mutable c_parmrk : bool; (** Mark parity errors. *) + mutable c_inpck : bool; (** Enable parity check on input. *) + mutable c_istrip : bool; (** Strip 8th bit on input characters. *) + mutable c_inlcr : bool; (** Map NL to CR on input. *) + mutable c_igncr : bool; (** Ignore CR on input. *) + mutable c_icrnl : bool; (** Map CR to NL on input. *) + mutable c_ixon : bool; (** Recognize XON/XOFF characters on input. *) + mutable c_ixoff : bool; (** Emit XON/XOFF chars to control input flow. *) + (* Output modes: *) + mutable c_opost : bool; (** Enable output processing. *) + (* Control modes: *) + mutable c_obaud : int; (** Output baud rate (0 means close connection).*) + mutable c_ibaud : int; (** Input baud rate. *) + mutable c_csize : int; (** Number of bits per character (5-8). *) + mutable c_cstopb : int; (** Number of stop bits (1-2). *) + mutable c_cread : bool; (** Reception is enabled. *) + mutable c_parenb : bool; (** Enable parity generation and detection. *) + mutable c_parodd : bool; (** Specify odd parity instead of even. *) + mutable c_hupcl : bool; (** Hang up on last close. *) + mutable c_clocal : bool; (** Ignore modem status lines. *) + (* Local modes: *) + mutable c_isig : bool; (** Generate signal on INTR, QUIT, SUSP. *) + mutable c_icanon : bool; (** Enable canonical processing + (line buffering and editing) *) + mutable c_noflsh : bool; (** Disable flush after INTR, QUIT, SUSP. *) + mutable c_echo : bool; (** Echo input characters. *) + mutable c_echoe : bool; (** Echo ERASE (to erase previous character). *) + mutable c_echok : bool; (** Echo KILL (to erase the current line). *) + mutable c_echonl : bool; (** Echo NL even if c_echo is not set. *) + (* Control characters: *) + mutable c_vintr : char; (** Interrupt character (usually ctrl-C). *) + mutable c_vquit : char; (** Quit character (usually ctrl-\). *) + mutable c_verase : char; (** Erase character (usually DEL or ctrl-H). *) + mutable c_vkill : char; (** Kill line character (usually ctrl-U). *) + mutable c_veof : char; (** End-of-file character (usually ctrl-D). *) + mutable c_veol : char; (** Alternate end-of-line char. (usually none). *) + mutable c_vmin : int; (** Minimum number of characters to read + before the read request is satisfied. *) + mutable c_vtime : int; (** Maximum read wait (in 0.1s units). *) + mutable c_vstart : char; (** Start character (usually ctrl-Q). *) + mutable c_vstop : char; (** Stop character (usually ctrl-S). *) + } + +val tcgetattr : file_descr -> terminal_io +(** Return the status of the terminal referred to by the given + file descriptor. *) + +type setattr_when = + TCSANOW + | TCSADRAIN + | TCSAFLUSH + +val tcsetattr : file_descr -> setattr_when -> terminal_io -> unit +(** Set the status of the terminal referred to by the given + file descriptor. The second argument indicates when the + status change takes place: immediately ([TCSANOW]), + when all pending output has been transmitted ([TCSADRAIN]), + or after flushing all input that has been received but not + read ([TCSAFLUSH]). [TCSADRAIN] is recommended when changing + the output parameters; [TCSAFLUSH], when changing the input + parameters. *) + +val tcsendbreak : file_descr -> int -> unit +(** Send a break condition on the given file descriptor. + The second argument is the duration of the break, in 0.1s units; + 0 means standard duration (0.25s). *) + +val tcdrain : file_descr -> unit +(** Waits until all output written on the given file descriptor + has been transmitted. *) + +type flush_queue = + TCIFLUSH + | TCOFLUSH + | TCIOFLUSH + +val tcflush : file_descr -> flush_queue -> unit +(** Discard data written on the given file descriptor but not yet + transmitted, or data received but not yet read, depending on the + second argument: [TCIFLUSH] flushes data received but not read, + [TCOFLUSH] flushes data written but not transmitted, and + [TCIOFLUSH] flushes both. *) + +type flow_action = + TCOOFF + | TCOON + | TCIOFF + | TCION + +val tcflow : file_descr -> flow_action -> unit +(** Suspend or restart reception or transmission of data on + the given file descriptor, depending on the second argument: + [TCOOFF] suspends output, [TCOON] restarts output, + [TCIOFF] transmits a STOP character to suspend input, + and [TCION] transmits a START character to restart input. *) + +val setsid : unit -> int +(** Put the calling process in a new session and detach it from + its controlling terminal. *) diff --git a/otherlibs/unix/unix.mllib b/otherlibs/unix/unix.mllib new file mode 100644 index 0000000..8d569c5 --- /dev/null +++ b/otherlibs/unix/unix.mllib @@ -0,0 +1 @@ +Unix UnixLabels diff --git a/otherlibs/unix/unixLabels.ml b/otherlibs/unix/unixLabels.ml new file mode 100644 index 0000000..f3517d3 --- /dev/null +++ b/otherlibs/unix/unixLabels.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unixLabels.ml,v 1.3 2001-12-07 13:40:38 xleroy Exp $ *) + +(* Module [UnixLabels]: labelled Unix module *) + +include Unix diff --git a/otherlibs/unix/unixLabels.mli b/otherlibs/unix/unixLabels.mli new file mode 100644 index 0000000..81213f2 --- /dev/null +++ b/otherlibs/unix/unixLabels.mli @@ -0,0 +1,1324 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unixLabels.mli,v 1.19 2008-08-01 13:46:08 xleroy Exp $ *) + +(** Interface to the Unix system. + To use as replacement to default {!Unix} module, + add [module Unix = UnixLabels] in your implementation. +*) + +(** {6 Error report} *) + + +type error = Unix.error = + E2BIG (** Argument list too long *) + | EACCES (** Permission denied *) + | EAGAIN (** Resource temporarily unavailable; try again *) + | EBADF (** Bad file descriptor *) + | EBUSY (** Resource unavailable *) + | ECHILD (** No child process *) + | EDEADLK (** Resource deadlock would occur *) + | EDOM (** Domain error for math functions, etc. *) + | EEXIST (** File exists *) + | EFAULT (** Bad address *) + | EFBIG (** File too large *) + | EINTR (** Function interrupted by signal *) + | EINVAL (** Invalid argument *) + | EIO (** Hardware I/O error *) + | EISDIR (** Is a directory *) + | EMFILE (** Too many open files by the process *) + | EMLINK (** Too many links *) + | ENAMETOOLONG (** Filename too long *) + | ENFILE (** Too many open files in the system *) + | ENODEV (** No such device *) + | ENOENT (** No such file or directory *) + | ENOEXEC (** Not an executable file *) + | ENOLCK (** No locks available *) + | ENOMEM (** Not enough memory *) + | ENOSPC (** No space left on device *) + | ENOSYS (** Function not supported *) + | ENOTDIR (** Not a directory *) + | ENOTEMPTY (** Directory not empty *) + | ENOTTY (** Inappropriate I/O control operation *) + | ENXIO (** No such device or address *) + | EPERM (** Operation not permitted *) + | EPIPE (** Broken pipe *) + | ERANGE (** Result too large *) + | EROFS (** Read-only file system *) + | ESPIPE (** Invalid seek e.g. on a pipe *) + | ESRCH (** No such process *) + | EXDEV (** Invalid link *) + | EWOULDBLOCK (** Operation would block *) + | EINPROGRESS (** Operation now in progress *) + | EALREADY (** Operation already in progress *) + | ENOTSOCK (** Socket operation on non-socket *) + | EDESTADDRREQ (** Destination address required *) + | EMSGSIZE (** Message too long *) + | EPROTOTYPE (** Protocol wrong type for socket *) + | ENOPROTOOPT (** Protocol not available *) + | EPROTONOSUPPORT (** Protocol not supported *) + | ESOCKTNOSUPPORT (** Socket type not supported *) + | EOPNOTSUPP (** Operation not supported on socket *) + | EPFNOSUPPORT (** Protocol family not supported *) + | EAFNOSUPPORT (** Address family not supported by protocol family *) + | EADDRINUSE (** Address already in use *) + | EADDRNOTAVAIL (** Can't assign requested address *) + | ENETDOWN (** Network is down *) + | ENETUNREACH (** Network is unreachable *) + | ENETRESET (** Network dropped connection on reset *) + | ECONNABORTED (** Software caused connection abort *) + | ECONNRESET (** Connection reset by peer *) + | ENOBUFS (** No buffer space available *) + | EISCONN (** Socket is already connected *) + | ENOTCONN (** Socket is not connected *) + | ESHUTDOWN (** Can't send after socket shutdown *) + | ETOOMANYREFS (** Too many references: can't splice *) + | ETIMEDOUT (** Connection timed out *) + | ECONNREFUSED (** Connection refused *) + | EHOSTDOWN (** Host is down *) + | EHOSTUNREACH (** No route to host *) + | ELOOP (** Too many levels of symbolic links *) + | EOVERFLOW (** File size or position not representable *) + + | EUNKNOWNERR of int (** Unknown error *) +(** The type of error codes. + Errors defined in the POSIX standard + and additional errors from UNIX98 and BSD. + All other errors are mapped to EUNKNOWNERR. +*) + + +exception Unix_error of error * string * string +(** Raised by the system calls below when an error is encountered. + The first component is the error code; the second component + is the function name; the third component is the string parameter + to the function, if it has one, or the empty string otherwise. *) + +val error_message : error -> string +(** Return a string describing the given error code. *) + +val handle_unix_error : ('a -> 'b) -> 'a -> 'b +(** [handle_unix_error f x] applies [f] to [x] and returns the result. + If the exception [Unix_error] is raised, it prints a message + describing the error and exits with code 2. *) + + +(** {6 Access to the process environment} *) + + +val environment : unit -> string array +(** Return the process environment, as an array of strings + with the format ``variable=value''. *) + +val getenv : string -> string +(** Return the value associated to a variable in the process + environment. Raise [Not_found] if the variable is unbound. + (This function is identical to [Sys.getenv].) *) + +val putenv : string -> string -> unit +(** [Unix.putenv name value] sets the value associated to a + variable in the process environment. + [name] is the name of the environment variable, + and [value] its new associated value. *) + + +(** {6 Process handling} *) + + +type process_status = Unix.process_status = + WEXITED of int + (** The process terminated normally by [exit]; + the argument is the return code. *) + | WSIGNALED of int + (** The process was killed by a signal; + the argument is the signal number. *) + | WSTOPPED of int + (** The process was stopped by a signal; the argument is the + signal number. *) +(** The termination status of a process. *) + + +type wait_flag = Unix.wait_flag = + WNOHANG (** do not block if no child has + died yet, but immediately return with a pid equal to 0.*) + | WUNTRACED (** report also the children that receive stop signals. *) +(** Flags for {!UnixLabels.waitpid}. *) + +val execv : prog:string -> args:string array -> 'a +(** [execv prog args] execute the program in file [prog], with + the arguments [args], and the current process environment. + These [execv*] functions never return: on success, the current + program is replaced by the new one; + on failure, a {!UnixLabels.Unix_error} exception is raised. *) + +val execve : prog:string -> args:string array -> env:string array -> 'a +(** Same as {!UnixLabels.execv}, except that the third argument provides the + environment to the program executed. *) + +val execvp : prog:string -> args:string array -> 'a +(** Same as {!UnixLabels.execv} respectively, except that + the program is searched in the path. *) + +val execvpe : prog:string -> args:string array -> env:string array -> 'a +(** Same as {!UnixLabels.execvp} respectively, except that + the program is searched in the path. *) + +val fork : unit -> int +(** Fork a new process. The returned integer is 0 for the child + process, the pid of the child process for the parent process. *) + +val wait : unit -> int * process_status +(** Wait until one of the children processes die, and return its pid + and termination status. *) + +val waitpid : mode:wait_flag list -> int -> int * process_status +(** Same as {!UnixLabels.wait}, but waits for the process whose pid is given. + A pid of [-1] means wait for any child. + A pid of [0] means wait for any child in the same process group + as the current process. + Negative pid arguments represent process groups. + The list of options indicates whether [waitpid] should return + immediately without waiting, or also report stopped children. *) + +val system : string -> process_status +(** Execute the given command, wait until it terminates, and return + its termination status. The string is interpreted by the shell + [/bin/sh] and therefore can contain redirections, quotes, variables, + etc. The result [WEXITED 127] indicates that the shell couldn't + be executed. *) + +val getpid : unit -> int +(** Return the pid of the process. *) + +val getppid : unit -> int +(** Return the pid of the parent process. *) + +val nice : int -> int +(** Change the process priority. The integer argument is added to the + ``nice'' value. (Higher values of the ``nice'' value mean + lower priorities.) Return the new nice value. *) + + +(** {6 Basic file input/output} *) + + +type file_descr = Unix.file_descr +(** The abstract type of file descriptors. *) + +val stdin : file_descr +(** File descriptor for standard input.*) + +val stdout : file_descr +(** File descriptor for standard output.*) + +val stderr : file_descr +(** File descriptor for standard error. *) + +type open_flag = Unix.open_flag = + O_RDONLY (** Open for reading *) + | O_WRONLY (** Open for writing *) + | O_RDWR (** Open for reading and writing *) + | O_NONBLOCK (** Open in non-blocking mode *) + | O_APPEND (** Open for append *) + | O_CREAT (** Create if nonexistent *) + | O_TRUNC (** Truncate to 0 length if existing *) + | O_EXCL (** Fail if existing *) + | O_NOCTTY (** Don't make this dev a controlling tty *) + | O_DSYNC (** Writes complete as `Synchronised I/O data integrity completion' *) + | O_SYNC (** Writes complete as `Synchronised I/O file integrity completion' *) + | O_RSYNC (** Reads complete as writes (depending on O_SYNC/O_DSYNC) *) +(** The flags to {!UnixLabels.openfile}. *) + + +type file_perm = int +(** The type of file access rights, e.g. [0o640] is read and write for user, + read for group, none for others *) + +val openfile : string -> mode:open_flag list -> perm:file_perm -> file_descr +(** Open the named file with the given flags. Third argument is + the permissions to give to the file if it is created. Return + a file descriptor on the named file. *) + +val close : file_descr -> unit +(** Close a file descriptor. *) + +val read : file_descr -> buf:string -> pos:int -> len:int -> int +(** [read fd buff ofs len] reads [len] characters from descriptor + [fd], storing them in string [buff], starting at position [ofs] + in string [buff]. Return the number of characters actually read. *) + +val write : file_descr -> buf:string -> pos:int -> len:int -> int +(** [write fd buff ofs len] writes [len] characters to descriptor + [fd], taking them from string [buff], starting at position [ofs] + in string [buff]. Return the number of characters actually + written. [write] repeats the writing operation until all characters + have been written or an error occurs. *) + +val single_write : file_descr -> buf:string -> pos:int -> len:int -> int +(** Same as [write], but attempts to write only once. + Thus, if an error occurs, [single_write] guarantees that no data + has been written. *) + +(** {6 Interfacing with the standard input/output library} *) + + + +val in_channel_of_descr : file_descr -> in_channel +(** Create an input channel reading from the given descriptor. + The channel is initially in binary mode; use + [set_binary_mode_in ic false] if text mode is desired. *) + +val out_channel_of_descr : file_descr -> out_channel +(** Create an output channel writing on the given descriptor. + The channel is initially in binary mode; use + [set_binary_mode_out oc false] if text mode is desired. *) + +val descr_of_in_channel : in_channel -> file_descr +(** Return the descriptor corresponding to an input channel. *) + +val descr_of_out_channel : out_channel -> file_descr +(** Return the descriptor corresponding to an output channel. *) + + +(** {6 Seeking and truncating} *) + + +type seek_command = Unix.seek_command = + SEEK_SET (** indicates positions relative to the beginning of the file *) + | SEEK_CUR (** indicates positions relative to the current position *) + | SEEK_END (** indicates positions relative to the end of the file *) +(** Positioning modes for {!UnixLabels.lseek}. *) + + +val lseek : file_descr -> int -> mode:seek_command -> int +(** Set the current position for a file descriptor *) + +val truncate : string -> len:int -> unit +(** Truncates the named file to the given size. *) + +val ftruncate : file_descr -> len:int -> unit +(** Truncates the file corresponding to the given descriptor + to the given size. *) + + +(** {6 File status} *) + + +type file_kind = Unix.file_kind = + S_REG (** Regular file *) + | S_DIR (** Directory *) + | S_CHR (** Character device *) + | S_BLK (** Block device *) + | S_LNK (** Symbolic link *) + | S_FIFO (** Named pipe *) + | S_SOCK (** Socket *) + +type stats = Unix.stats = + { st_dev : int; (** Device number *) + st_ino : int; (** Inode number *) + st_kind : file_kind; (** Kind of the file *) + st_perm : file_perm; (** Access rights *) + st_nlink : int; (** Number of links *) + st_uid : int; (** User id of the owner *) + st_gid : int; (** Group ID of the file's group *) + st_rdev : int; (** Device minor number *) + st_size : int; (** Size in bytes *) + st_atime : float; (** Last access time *) + st_mtime : float; (** Last modification time *) + st_ctime : float; (** Last status change time *) + } +(** The informations returned by the {!UnixLabels.stat} calls. *) + +val stat : string -> stats +(** Return the information for the named file. *) + +val lstat : string -> stats +(** Same as {!UnixLabels.stat}, but in case the file is a symbolic link, + return the information for the link itself. *) + +val fstat : file_descr -> stats +(** Return the information for the file associated with the given + descriptor. *) + +val isatty : file_descr -> bool +(** Return [true] if the given file descriptor refers to a terminal or + console window, [false] otherwise. *) + +(** {6 File operations on large files} *) + +module LargeFile : + sig + val lseek : file_descr -> int64 -> mode:seek_command -> int64 + val truncate : string -> len:int64 -> unit + val ftruncate : file_descr -> len:int64 -> unit + type stats = Unix.LargeFile.stats = + { st_dev : int; (** Device number *) + st_ino : int; (** Inode number *) + st_kind : file_kind; (** Kind of the file *) + st_perm : file_perm; (** Access rights *) + st_nlink : int; (** Number of links *) + st_uid : int; (** User id of the owner *) + st_gid : int; (** Group ID of the file's group *) + st_rdev : int; (** Device minor number *) + st_size : int64; (** Size in bytes *) + st_atime : float; (** Last access time *) + st_mtime : float; (** Last modification time *) + st_ctime : float; (** Last status change time *) + } + val stat : string -> stats + val lstat : string -> stats + val fstat : file_descr -> stats + end +(** File operations on large files. + This sub-module provides 64-bit variants of the functions + {!UnixLabels.lseek} (for positioning a file descriptor), + {!UnixLabels.truncate} and {!UnixLabels.ftruncate} + (for changing the size of a file), + and {!UnixLabels.stat}, {!UnixLabels.lstat} and {!UnixLabels.fstat} + (for obtaining information on files). These alternate functions represent + positions and sizes by 64-bit integers (type [int64]) instead of + regular integers (type [int]), thus allowing operating on files + whose sizes are greater than [max_int]. *) + + +(** {6 Operations on file names} *) + + +val unlink : string -> unit +(** Removes the named file *) + +val rename : src:string -> dst:string -> unit +(** [rename old new] changes the name of a file from [old] to [new]. *) + +val link : src:string -> dst:string -> unit +(** [link source dest] creates a hard link named [dest] to the file + named [source]. *) + + +(** {6 File permissions and ownership} *) + + +type access_permission = Unix.access_permission = + R_OK (** Read permission *) + | W_OK (** Write permission *) + | X_OK (** Execution permission *) + | F_OK (** File exists *) +(** Flags for the {!UnixLabels.access} call. *) + + +val chmod : string -> perm:file_perm -> unit +(** Change the permissions of the named file. *) + +val fchmod : file_descr -> perm:file_perm -> unit +(** Change the permissions of an opened file. *) + +val chown : string -> uid:int -> gid:int -> unit +(** Change the owner uid and owner gid of the named file. *) + +val fchown : file_descr -> uid:int -> gid:int -> unit +(** Change the owner uid and owner gid of an opened file. *) + +val umask : int -> int +(** Set the process's file mode creation mask, and return the previous + mask. *) + +val access : string -> perm:access_permission list -> unit +(** Check that the process has the given permissions over the named + file. Raise [Unix_error] otherwise. *) + + +(** {6 Operations on file descriptors} *) + + +val dup : file_descr -> file_descr +(** Return a new file descriptor referencing the same file as + the given descriptor. *) + +val dup2 : src:file_descr -> dst:file_descr -> unit +(** [dup2 fd1 fd2] duplicates [fd1] to [fd2], closing [fd2] if already + opened. *) + +val set_nonblock : file_descr -> unit +(** Set the ``non-blocking'' flag on the given descriptor. + When the non-blocking flag is set, reading on a descriptor + on which there is temporarily no data available raises the + [EAGAIN] or [EWOULDBLOCK] error instead of blocking; + writing on a descriptor on which there is temporarily no room + for writing also raises [EAGAIN] or [EWOULDBLOCK]. *) + +val clear_nonblock : file_descr -> unit +(** Clear the ``non-blocking'' flag on the given descriptor. + See {!UnixLabels.set_nonblock}.*) + +val set_close_on_exec : file_descr -> unit +(** Set the ``close-on-exec'' flag on the given descriptor. + A descriptor with the close-on-exec flag is automatically + closed when the current process starts another program with + one of the [exec] functions. *) + +val clear_close_on_exec : file_descr -> unit +(** Clear the ``close-on-exec'' flag on the given descriptor. + See {!UnixLabels.set_close_on_exec}.*) + + + +(** {6 Directories} *) + + +val mkdir : string -> perm:file_perm -> unit +(** Create a directory with the given permissions. *) + +val rmdir : string -> unit +(** Remove an empty directory. *) + +val chdir : string -> unit +(** Change the process working directory. *) + +val getcwd : unit -> string +(** Return the name of the current working directory. *) + +val chroot : string -> unit +(** Change the process root directory. *) + +type dir_handle = Unix.dir_handle +(** The type of descriptors over opened directories. *) + +val opendir : string -> dir_handle +(** Open a descriptor on a directory *) + +val readdir : dir_handle -> string +(** Return the next entry in a directory. + @raise End_of_file when the end of the directory has been reached. *) + +val rewinddir : dir_handle -> unit +(** Reposition the descriptor to the beginning of the directory *) + +val closedir : dir_handle -> unit +(** Close a directory descriptor. *) + + + +(** {6 Pipes and redirections} *) + + +val pipe : unit -> file_descr * file_descr +(** Create a pipe. The first component of the result is opened + for reading, that's the exit to the pipe. The second component is + opened for writing, that's the entrance to the pipe. *) + +val mkfifo : string -> perm:file_perm -> unit +(** Create a named pipe with the given permissions. *) + + +(** {6 High-level process and redirection management} *) + + +val create_process : + prog:string -> args:string array -> stdin:file_descr -> stdout:file_descr -> + stderr:file_descr -> int +(** [create_process prog args new_stdin new_stdout new_stderr] + forks a new process that executes the program + in file [prog], with arguments [args]. The pid of the new + process is returned immediately; the new process executes + concurrently with the current process. + The standard input and outputs of the new process are connected + to the descriptors [new_stdin], [new_stdout] and [new_stderr]. + Passing e.g. [stdout] for [new_stdout] prevents the redirection + and causes the new process to have the same standard output + as the current process. + The executable file [prog] is searched in the path. + The new process has the same environment as the current process. *) + +val create_process_env : + prog:string -> args:string array -> env:string array -> stdin:file_descr -> + stdout:file_descr -> stderr:file_descr -> int +(** [create_process_env prog args env new_stdin new_stdout new_stderr] + works as {!UnixLabels.create_process}, except that the extra argument + [env] specifies the environment passed to the program. *) + + +val open_process_in : string -> in_channel +(** High-level pipe and process management. This function + runs the given command in parallel with the program. + The standard output of the command is redirected to a pipe, + which can be read via the returned input channel. + The command is interpreted by the shell [/bin/sh] (cf. [system]). *) + +val open_process_out : string -> out_channel +(** Same as {!UnixLabels.open_process_in}, but redirect the standard input of + the command to a pipe. Data written to the returned output channel + is sent to the standard input of the command. + Warning: writes on output channels are buffered, hence be careful + to call {!Pervasives.flush} at the right times to ensure + correct synchronization. *) + +val open_process : string -> in_channel * out_channel +(** Same as {!UnixLabels.open_process_out}, but redirects both the standard + input and standard output of the command to pipes connected to the two + returned channels. The input channel is connected to the output + of the command, and the output channel to the input of the command. *) + +val open_process_full : + string -> env:string array -> in_channel * out_channel * in_channel +(** Similar to {!UnixLabels.open_process}, but the second argument specifies + the environment passed to the command. The result is a triple + of channels connected respectively to the standard output, standard input, + and standard error of the command. *) + +val close_process_in : in_channel -> process_status +(** Close channels opened by {!UnixLabels.open_process_in}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process_out : out_channel -> process_status +(** Close channels opened by {!UnixLabels.open_process_out}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process : in_channel * out_channel -> process_status +(** Close channels opened by {!UnixLabels.open_process}, + wait for the associated command to terminate, + and return its termination status. *) + +val close_process_full : + in_channel * out_channel * in_channel -> process_status +(** Close channels opened by {!UnixLabels.open_process_full}, + wait for the associated command to terminate, + and return its termination status. *) + + +(** {6 Symbolic links} *) + + +val symlink : src:string -> dst:string -> unit +(** [symlink source dest] creates the file [dest] as a symbolic link + to the file [source]. *) + +val readlink : string -> string +(** Read the contents of a link. *) + + +(** {6 Polling} *) + + +val select : + read:file_descr list -> write:file_descr list -> except:file_descr list -> + timeout:float -> file_descr list * file_descr list * file_descr list +(** Wait until some input/output operations become possible on + some channels. The three list arguments are, respectively, a set + of descriptors to check for reading (first argument), for writing + (second argument), or for exceptional conditions (third argument). + The fourth argument is the maximal timeout, in seconds; a + negative fourth argument means no timeout (unbounded wait). + The result is composed of three sets of descriptors: those ready + for reading (first component), ready for writing (second component), + and over which an exceptional condition is pending (third + component). *) + +(** {6 Locking} *) + + +type lock_command = Unix.lock_command = + F_ULOCK (** Unlock a region *) + | F_LOCK (** Lock a region for writing, and block if already locked *) + | F_TLOCK (** Lock a region for writing, or fail if already locked *) + | F_TEST (** Test a region for other process locks *) + | F_RLOCK (** Lock a region for reading, and block if already locked *) + | F_TRLOCK (** Lock a region for reading, or fail if already locked *) +(** Commands for {!UnixLabels.lockf}. *) + +val lockf : file_descr -> mode:lock_command -> len:int -> unit +(** [lockf fd cmd size] puts a lock on a region of the file opened + as [fd]. The region starts at the current read/write position for + [fd] (as set by {!UnixLabels.lseek}), and extends [size] bytes forward if + [size] is positive, [size] bytes backwards if [size] is negative, + or to the end of the file if [size] is zero. + A write lock prevents any other + process from acquiring a read or write lock on the region. + A read lock prevents any other + process from acquiring a write lock on the region, but lets + other processes acquire read locks on it. + + The [F_LOCK] and [F_TLOCK] commands attempts to put a write lock + on the specified region. + The [F_RLOCK] and [F_TRLOCK] commands attempts to put a read lock + on the specified region. + If one or several locks put by another process prevent the current process + from acquiring the lock, [F_LOCK] and [F_RLOCK] block until these locks + are removed, while [F_TLOCK] and [F_TRLOCK] fail immediately with an + exception. + The [F_ULOCK] removes whatever locks the current process has on + the specified region. + Finally, the [F_TEST] command tests whether a write lock can be + acquired on the specified region, without actually putting a lock. + It returns immediately if successful, or fails otherwise. *) + + +(** {6 Signals} + Note: installation of signal handlers is performed via + the functions {!Sys.signal} and {!Sys.set_signal}. +*) + + +val kill : pid:int -> signal:int -> unit +(** [kill pid sig] sends signal number [sig] to the process + with id [pid]. *) + +type sigprocmask_command = Unix.sigprocmask_command = + SIG_SETMASK + | SIG_BLOCK + | SIG_UNBLOCK + +val sigprocmask : mode:sigprocmask_command -> int list -> int list +(** [sigprocmask cmd sigs] changes the set of blocked signals. + If [cmd] is [SIG_SETMASK], blocked signals are set to those in + the list [sigs]. + If [cmd] is [SIG_BLOCK], the signals in [sigs] are added to + the set of blocked signals. + If [cmd] is [SIG_UNBLOCK], the signals in [sigs] are removed + from the set of blocked signals. + [sigprocmask] returns the set of previously blocked signals. *) + +val sigpending : unit -> int list +(** Return the set of blocked signals that are currently pending. *) + +val sigsuspend : int list -> unit +(** [sigsuspend sigs] atomically sets the blocked signals to [sigs] + and waits for a non-ignored, non-blocked signal to be delivered. + On return, the blocked signals are reset to their initial value. *) + +val pause : unit -> unit +(** Wait until a non-ignored, non-blocked signal is delivered. *) + + +(** {6 Time functions} *) + + +type process_times = Unix.process_times = + { tms_utime : float; (** User time for the process *) + tms_stime : float; (** System time for the process *) + tms_cutime : float; (** User time for the children processes *) + tms_cstime : float; (** System time for the children processes *) + } +(** The execution times (CPU times) of a process. *) + +type tm = Unix.tm = + { tm_sec : int; (** Seconds 0..60 *) + tm_min : int; (** Minutes 0..59 *) + tm_hour : int; (** Hours 0..23 *) + tm_mday : int; (** Day of month 1..31 *) + tm_mon : int; (** Month of year 0..11 *) + tm_year : int; (** Year - 1900 *) + tm_wday : int; (** Day of week (Sunday is 0) *) + tm_yday : int; (** Day of year 0..365 *) + tm_isdst : bool; (** Daylight time savings in effect *) + } +(** The type representing wallclock time and calendar date. *) + + +val time : unit -> float +(** Return the current time since 00:00:00 GMT, Jan. 1, 1970, + in seconds. *) + +val gettimeofday : unit -> float +(** Same as {!UnixLabels.time}, but with resolution better than 1 second. *) + +val gmtime : float -> tm +(** Convert a time in seconds, as returned by {!UnixLabels.time}, into a date + and a time. Assumes UTC (Coordinated Universal Time), also known as GMT. *) + +val localtime : float -> tm +(** Convert a time in seconds, as returned by {!UnixLabels.time}, into a date + and a time. Assumes the local time zone. *) + +val mktime : tm -> float * tm +(** Convert a date and time, specified by the [tm] argument, into + a time in seconds, as returned by {!UnixLabels.time}. The [tm_isdst], + [tm_wday] and [tm_yday] fields of [tm] are ignored. Also return a + normalized copy of the given [tm] record, with the [tm_wday], + [tm_yday], and [tm_isdst] fields recomputed from the other fields, + and the other fields normalized (so that, e.g., 40 October is + changed into 9 November). The [tm] argument is interpreted in the + local time zone. *) + +val alarm : int -> int +(** Schedule a [SIGALRM] signal after the given number of seconds. *) + +val sleep : int -> unit +(** Stop execution for the given number of seconds. *) + +val times : unit -> process_times +(** Return the execution times of the process. *) + +val utimes : string -> access:float -> modif:float -> unit +(** Set the last access time (second arg) and last modification time + (third arg) for a file. Times are expressed in seconds from + 00:00:00 GMT, Jan. 1, 1970. *) + +type interval_timer = Unix.interval_timer = + ITIMER_REAL + (** decrements in real time, and sends the signal [SIGALRM] when expired.*) + | ITIMER_VIRTUAL + (** decrements in process virtual time, and sends [SIGVTALRM] when expired. *) + | ITIMER_PROF + (** (for profiling) decrements both when the process + is running and when the system is running on behalf of the + process; it sends [SIGPROF] when expired. *) +(** The three kinds of interval timers. *) + +type interval_timer_status = Unix.interval_timer_status = + { it_interval : float; (** Period *) + it_value : float; (** Current value of the timer *) + } +(** The type describing the status of an interval timer *) + +val getitimer : interval_timer -> interval_timer_status +(** Return the current status of the given interval timer. *) + +val setitimer : + interval_timer -> interval_timer_status -> interval_timer_status +(** [setitimer t s] sets the interval timer [t] and returns + its previous status. The [s] argument is interpreted as follows: + [s.it_value], if nonzero, is the time to the next timer expiration; + [s.it_interval], if nonzero, specifies a value to + be used in reloading it_value when the timer expires. + Setting [s.it_value] to zero disable the timer. + Setting [s.it_interval] to zero causes the timer to be disabled + after its next expiration. *) + + +(** {6 User id, group id} *) + + +val getuid : unit -> int +(** Return the user id of the user executing the process. *) + +val geteuid : unit -> int +(** Return the effective user id under which the process runs. *) + +val setuid : int -> unit +(** Set the real user id and effective user id for the process. *) + +val getgid : unit -> int +(** Return the group id of the user executing the process. *) + +val getegid : unit -> int +(** Return the effective group id under which the process runs. *) + +val setgid : int -> unit +(** Set the real group id and effective group id for the process. *) + +val getgroups : unit -> int array +(** Return the list of groups to which the user executing the process + belongs. *) + +type passwd_entry = Unix.passwd_entry = + { pw_name : string; + pw_passwd : string; + pw_uid : int; + pw_gid : int; + pw_gecos : string; + pw_dir : string; + pw_shell : string + } +(** Structure of entries in the [passwd] database. *) + +type group_entry = Unix.group_entry = + { gr_name : string; + gr_passwd : string; + gr_gid : int; + gr_mem : string array + } +(** Structure of entries in the [groups] database. *) + +val getlogin : unit -> string +(** Return the login name of the user executing the process. *) + +val getpwnam : string -> passwd_entry +(** Find an entry in [passwd] with the given name, or raise + [Not_found]. *) + +val getgrnam : string -> group_entry +(** Find an entry in [group] with the given name, or raise + [Not_found]. *) + +val getpwuid : int -> passwd_entry +(** Find an entry in [passwd] with the given user id, or raise + [Not_found]. *) + +val getgrgid : int -> group_entry +(** Find an entry in [group] with the given group id, or raise + [Not_found]. *) + + +(** {6 Internet addresses} *) + + +type inet_addr = Unix.inet_addr +(** The abstract type of Internet addresses. *) + +val inet_addr_of_string : string -> inet_addr +(** Conversion from the printable representation of an Internet + address to its internal representation. The argument string + consists of 4 numbers separated by periods ([XXX.YYY.ZZZ.TTT]) + for IPv4 addresses, and up to 8 numbers separated by colons + for IPv6 addresses. Raise [Failure] when given a string that + does not match these formats. *) + +val string_of_inet_addr : inet_addr -> string +(** Return the printable representation of the given Internet address. + See {!Unix.inet_addr_of_string} for a description of the + printable representation. *) + +val inet_addr_any : inet_addr +(** A special IPv4 address, for use only with [bind], representing + all the Internet addresses that the host machine possesses. *) + +val inet_addr_loopback : inet_addr +(** A special IPv4 address representing the host machine ([127.0.0.1]). *) + +val inet6_addr_any : inet_addr +(** A special IPv6 address, for use only with [bind], representing + all the Internet addresses that the host machine possesses. *) + +val inet6_addr_loopback : inet_addr +(** A special IPv6 address representing the host machine ([::1]). *) + + +(** {6 Sockets} *) + + +type socket_domain = Unix.socket_domain = + PF_UNIX (** Unix domain *) + | PF_INET (** Internet domain (IPv4) *) + | PF_INET6 (** Internet domain (IPv6) *) +(** The type of socket domains. *) + +type socket_type = Unix.socket_type = + SOCK_STREAM (** Stream socket *) + | SOCK_DGRAM (** Datagram socket *) + | SOCK_RAW (** Raw socket *) + | SOCK_SEQPACKET (** Sequenced packets socket *) +(** The type of socket kinds, specifying the semantics of + communications. *) + +type sockaddr = Unix.sockaddr = + ADDR_UNIX of string + | ADDR_INET of inet_addr * int +(** The type of socket addresses. [ADDR_UNIX name] is a socket + address in the Unix domain; [name] is a file name in the file + system. [ADDR_INET(addr,port)] is a socket address in the Internet + domain; [addr] is the Internet address of the machine, and + [port] is the port number. *) + +val socket : + domain:socket_domain -> kind:socket_type -> protocol:int -> file_descr +(** Create a new socket in the given domain, and with the + given kind. The third argument is the protocol type; 0 selects + the default protocol for that kind of sockets. *) + +val domain_of_sockaddr: sockaddr -> socket_domain +(** Return the socket domain adequate for the given socket address. *) + +val socketpair : + domain:socket_domain -> kind:socket_type -> protocol:int -> + file_descr * file_descr +(** Create a pair of unnamed sockets, connected together. *) + +val accept : file_descr -> file_descr * sockaddr +(** Accept connections on the given socket. The returned descriptor + is a socket connected to the client; the returned address is + the address of the connecting client. *) + +val bind : file_descr -> addr:sockaddr -> unit +(** Bind a socket to an address. *) + +val connect : file_descr -> addr:sockaddr -> unit +(** Connect a socket to an address. *) + +val listen : file_descr -> max:int -> unit +(** Set up a socket for receiving connection requests. The integer + argument is the maximal number of pending requests. *) + +type shutdown_command = Unix.shutdown_command = + SHUTDOWN_RECEIVE (** Close for receiving *) + | SHUTDOWN_SEND (** Close for sending *) + | SHUTDOWN_ALL (** Close both *) +(** The type of commands for [shutdown]. *) + + +val shutdown : file_descr -> mode:shutdown_command -> unit +(** Shutdown a socket connection. [SHUTDOWN_SEND] as second argument + causes reads on the other end of the connection to return + an end-of-file condition. + [SHUTDOWN_RECEIVE] causes writes on the other end of the connection + to return a closed pipe condition ([SIGPIPE] signal). *) + +val getsockname : file_descr -> sockaddr +(** Return the address of the given socket. *) + +val getpeername : file_descr -> sockaddr +(** Return the address of the host connected to the given socket. *) + +type msg_flag = Unix.msg_flag = + MSG_OOB + | MSG_DONTROUTE + | MSG_PEEK +(** The flags for {!UnixLabels.recv}, {!UnixLabels.recvfrom}, + {!UnixLabels.send} and {!UnixLabels.sendto}. *) + +val recv : + file_descr -> buf:string -> pos:int -> len:int -> mode:msg_flag list -> int +(** Receive data from a connected socket. *) + +val recvfrom : + file_descr -> buf:string -> pos:int -> len:int -> mode:msg_flag list -> + int * sockaddr +(** Receive data from an unconnected socket. *) + +val send : + file_descr -> buf:string -> pos:int -> len:int -> mode:msg_flag list -> int +(** Send data over a connected socket. *) + +val sendto : + file_descr -> buf:string -> pos:int -> len:int -> mode:msg_flag list -> + addr:sockaddr -> int +(** Send data over an unconnected socket. *) + + + +(** {6 Socket options} *) + + +type socket_bool_option = + SO_DEBUG (** Record debugging information *) + | SO_BROADCAST (** Permit sending of broadcast messages *) + | SO_REUSEADDR (** Allow reuse of local addresses for bind *) + | SO_KEEPALIVE (** Keep connection active *) + | SO_DONTROUTE (** Bypass the standard routing algorithms *) + | SO_OOBINLINE (** Leave out-of-band data in line *) + | SO_ACCEPTCONN (** Report whether socket listening is enabled *) + | TCP_NODELAY (** Control the Nagle algorithm for TCP sockets *) + | IPV6_ONLY (** Forbid binding an IPv6 socket to an IPv4 address *) +(** The socket options that can be consulted with {!UnixLabels.getsockopt} + and modified with {!UnixLabels.setsockopt}. These options have a boolean + ([true]/[false]) value. *) + +type socket_int_option = + SO_SNDBUF (** Size of send buffer *) + | SO_RCVBUF (** Size of received buffer *) + | SO_ERROR (** Deprecated. Use {!Unix.getsockopt_error} instead. *) + | SO_TYPE (** Report the socket type *) + | SO_RCVLOWAT (** Minimum number of bytes to process for input operations *) + | SO_SNDLOWAT (** Minimum number of bytes to process for output operations *) +(** The socket options that can be consulted with {!UnixLabels.getsockopt_int} + and modified with {!UnixLabels.setsockopt_int}. These options have an + integer value. *) + +type socket_optint_option = + SO_LINGER (** Whether to linger on closed connections + that have data present, and for how long + (in seconds) *) +(** The socket options that can be consulted with {!Unix.getsockopt_optint} + and modified with {!Unix.setsockopt_optint}. These options have a + value of type [int option], with [None] meaning ``disabled''. *) + +type socket_float_option = + SO_RCVTIMEO (** Timeout for input operations *) + | SO_SNDTIMEO (** Timeout for output operations *) +(** The socket options that can be consulted with {!UnixLabels.getsockopt_float} + and modified with {!UnixLabels.setsockopt_float}. These options have a + floating-point value representing a time in seconds. + The value 0 means infinite timeout. *) + +val getsockopt : file_descr -> socket_bool_option -> bool +(** Return the current status of a boolean-valued option + in the given socket. *) + +val setsockopt : file_descr -> socket_bool_option -> bool -> unit +(** Set or clear a boolean-valued option in the given socket. *) + +val getsockopt_int : file_descr -> socket_int_option -> int +(** Same as {!Unix.getsockopt} for an integer-valued socket option. *) + +val setsockopt_int : file_descr -> socket_int_option -> int -> unit +(** Same as {!Unix.setsockopt} for an integer-valued socket option. *) + +val getsockopt_optint : file_descr -> socket_optint_option -> int option +(** Same as {!Unix.getsockopt} for a socket option whose value is an [int option]. *) + +val setsockopt_optint : + file_descr -> socket_optint_option -> int option -> unit +(** Same as {!Unix.setsockopt} for a socket option whose value is an [int option]. *) + +val getsockopt_float : file_descr -> socket_float_option -> float +(** Same as {!Unix.getsockopt} for a socket option whose value is a floating-point number. *) + +val setsockopt_float : file_descr -> socket_float_option -> float -> unit +(** Same as {!Unix.setsockopt} for a socket option whose value is a floating-point number. *) + +val getsockopt_error : file_descr -> error option +(** Return the error condition associated with the given socket, + and clear it. *) + +(** {6 High-level network connection functions} *) + + +val open_connection : sockaddr -> in_channel * out_channel +(** Connect to a server at the given address. + Return a pair of buffered channels connected to the server. + Remember to call {!Pervasives.flush} on the output channel at the right + times to ensure correct synchronization. *) + +val shutdown_connection : in_channel -> unit +(** ``Shut down'' a connection established with {!UnixLabels.open_connection}; + that is, transmit an end-of-file condition to the server reading + on the other side of the connection. *) + +val establish_server : + (in_channel -> out_channel -> unit) -> addr:sockaddr -> unit +(** Establish a server on the given address. + The function given as first argument is called for each connection + with two buffered channels connected to the client. A new process + is created for each connection. The function {!UnixLabels.establish_server} + never returns normally. *) + + +(** {6 Host and protocol databases} *) + + +type host_entry = Unix.host_entry = + { h_name : string; + h_aliases : string array; + h_addrtype : socket_domain; + h_addr_list : inet_addr array + } +(** Structure of entries in the [hosts] database. *) + +type protocol_entry = Unix.protocol_entry = + { p_name : string; + p_aliases : string array; + p_proto : int + } +(** Structure of entries in the [protocols] database. *) + +type service_entry = Unix.service_entry = + { s_name : string; + s_aliases : string array; + s_port : int; + s_proto : string + } +(** Structure of entries in the [services] database. *) + +val gethostname : unit -> string +(** Return the name of the local host. *) + +val gethostbyname : string -> host_entry +(** Find an entry in [hosts] with the given name, or raise + [Not_found]. *) + +val gethostbyaddr : inet_addr -> host_entry +(** Find an entry in [hosts] with the given address, or raise + [Not_found]. *) + +val getprotobyname : string -> protocol_entry +(** Find an entry in [protocols] with the given name, or raise + [Not_found]. *) + +val getprotobynumber : int -> protocol_entry +(** Find an entry in [protocols] with the given protocol number, + or raise [Not_found]. *) + +val getservbyname : string -> protocol:string -> service_entry +(** Find an entry in [services] with the given name, or raise + [Not_found]. *) + +val getservbyport : int -> protocol:string -> service_entry +(** Find an entry in [services] with the given service number, + or raise [Not_found]. *) + +type addr_info = + { ai_family : socket_domain; (** Socket domain *) + ai_socktype : socket_type; (** Socket type *) + ai_protocol : int; (** Socket protocol number *) + ai_addr : sockaddr; (** Address *) + ai_canonname : string (** Canonical host name *) + } +(** Address information returned by {!Unix.getaddrinfo}. *) + +type getaddrinfo_option = + AI_FAMILY of socket_domain (** Impose the given socket domain *) + | AI_SOCKTYPE of socket_type (** Impose the given socket type *) + | AI_PROTOCOL of int (** Impose the given protocol *) + | AI_NUMERICHOST (** Do not call name resolver, + expect numeric IP address *) + | AI_CANONNAME (** Fill the [ai_canonname] field + of the result *) + | AI_PASSIVE (** Set address to ``any'' address + for use with {!Unix.bind} *) +(** Options to {!Unix.getaddrinfo}. *) + +val getaddrinfo: + string -> string -> getaddrinfo_option list -> addr_info list +(** [getaddrinfo host service opts] returns a list of {!Unix.addr_info} + records describing socket parameters and addresses suitable for + communicating with the given host and service. The empty list is + returned if the host or service names are unknown, or the constraints + expressed in [opts] cannot be satisfied. + + [host] is either a host name or the string representation of an IP + address. [host] can be given as the empty string; in this case, + the ``any'' address or the ``loopback'' address are used, + depending whether [opts] contains [AI_PASSIVE]. + [service] is either a service name or the string representation of + a port number. [service] can be given as the empty string; + in this case, the port field of the returned addresses is set to 0. + [opts] is a possibly empty list of options that allows the caller + to force a particular socket domain (e.g. IPv6 only or IPv4 only) + or a particular socket type (e.g. TCP only or UDP only). *) + +type name_info = + { ni_hostname : string; (** Name or IP address of host *) + ni_service : string } (** Name of service or port number *) +(** Host and service information returned by {!Unix.getnameinfo}. *) + +type getnameinfo_option = + NI_NOFQDN (** Do not qualify local host names *) + | NI_NUMERICHOST (** Always return host as IP address *) + | NI_NAMEREQD (** Fail if host name cannot be determined *) + | NI_NUMERICSERV (** Always return service as port number *) + | NI_DGRAM (** Consider the service as UDP-based + instead of the default TCP *) +(** Options to {!Unix.getnameinfo}. *) + +val getnameinfo : sockaddr -> getnameinfo_option list -> name_info +(** [getnameinfo addr opts] returns the host name and service name + corresponding to the socket address [addr]. [opts] is a possibly + empty list of options that governs how these names are obtained. + Raise [Not_found] if an error occurs. *) + + +(** {6 Terminal interface} *) + + +(** The following functions implement the POSIX standard terminal + interface. They provide control over asynchronous communication ports + and pseudo-terminals. Refer to the [termios] man page for a + complete description. *) + +type terminal_io = Unix.terminal_io = + { + (* input modes *) + mutable c_ignbrk : bool; (** Ignore the break condition. *) + mutable c_brkint : bool; (** Signal interrupt on break condition. *) + mutable c_ignpar : bool; (** Ignore characters with parity errors. *) + mutable c_parmrk : bool; (** Mark parity errors. *) + mutable c_inpck : bool; (** Enable parity check on input. *) + mutable c_istrip : bool; (** Strip 8th bit on input characters. *) + mutable c_inlcr : bool; (** Map NL to CR on input. *) + mutable c_igncr : bool; (** Ignore CR on input. *) + mutable c_icrnl : bool; (** Map CR to NL on input. *) + mutable c_ixon : bool; (** Recognize XON/XOFF characters on input. *) + mutable c_ixoff : bool; (** Emit XON/XOFF chars to control input flow. *) + (* Output modes: *) + mutable c_opost : bool; (** Enable output processing. *) + (* Control modes: *) + mutable c_obaud : int; (** Output baud rate (0 means close connection).*) + mutable c_ibaud : int; (** Input baud rate. *) + mutable c_csize : int; (** Number of bits per character (5-8). *) + mutable c_cstopb : int; (** Number of stop bits (1-2). *) + mutable c_cread : bool; (** Reception is enabled. *) + mutable c_parenb : bool; (** Enable parity generation and detection. *) + mutable c_parodd : bool; (** Specify odd parity instead of even. *) + mutable c_hupcl : bool; (** Hang up on last close. *) + mutable c_clocal : bool; (** Ignore modem status lines. *) + (* Local modes: *) + mutable c_isig : bool; (** Generate signal on INTR, QUIT, SUSP. *) + mutable c_icanon : bool; (** Enable canonical processing + (line buffering and editing) *) + mutable c_noflsh : bool; (** Disable flush after INTR, QUIT, SUSP. *) + mutable c_echo : bool; (** Echo input characters. *) + mutable c_echoe : bool; (** Echo ERASE (to erase previous character). *) + mutable c_echok : bool; (** Echo KILL (to erase the current line). *) + mutable c_echonl : bool; (** Echo NL even if c_echo is not set. *) + (* Control characters: *) + mutable c_vintr : char; (** Interrupt character (usually ctrl-C). *) + mutable c_vquit : char; (** Quit character (usually ctrl-\). *) + mutable c_verase : char; (** Erase character (usually DEL or ctrl-H). *) + mutable c_vkill : char; (** Kill line character (usually ctrl-U). *) + mutable c_veof : char; (** End-of-file character (usually ctrl-D). *) + mutable c_veol : char; (** Alternate end-of-line char. (usually none). *) + mutable c_vmin : int; (** Minimum number of characters to read + before the read request is satisfied. *) + mutable c_vtime : int; (** Maximum read wait (in 0.1s units). *) + mutable c_vstart : char; (** Start character (usually ctrl-Q). *) + mutable c_vstop : char; (** Stop character (usually ctrl-S). *) + } + +val tcgetattr : file_descr -> terminal_io +(** Return the status of the terminal referred to by the given + file descriptor. *) + +type setattr_when = Unix.setattr_when = + TCSANOW + | TCSADRAIN + | TCSAFLUSH + +val tcsetattr : file_descr -> mode:setattr_when -> terminal_io -> unit +(** Set the status of the terminal referred to by the given + file descriptor. The second argument indicates when the + status change takes place: immediately ([TCSANOW]), + when all pending output has been transmitted ([TCSADRAIN]), + or after flushing all input that has been received but not + read ([TCSAFLUSH]). [TCSADRAIN] is recommended when changing + the output parameters; [TCSAFLUSH], when changing the input + parameters. *) + +val tcsendbreak : file_descr -> duration:int -> unit +(** Send a break condition on the given file descriptor. + The second argument is the duration of the break, in 0.1s units; + 0 means standard duration (0.25s). *) + +val tcdrain : file_descr -> unit +(** Waits until all output written on the given file descriptor + has been transmitted. *) + +type flush_queue = Unix.flush_queue = + TCIFLUSH + | TCOFLUSH + | TCIOFLUSH + +val tcflush : file_descr -> mode:flush_queue -> unit +(** Discard data written on the given file descriptor but not yet + transmitted, or data received but not yet read, depending on the + second argument: [TCIFLUSH] flushes data received but not read, + [TCOFLUSH] flushes data written but not transmitted, and + [TCIOFLUSH] flushes both. *) + +type flow_action = Unix.flow_action = + TCOOFF + | TCOON + | TCIOFF + | TCION + +val tcflow : file_descr -> mode:flow_action -> unit +(** Suspend or restart reception or transmission of data on + the given file descriptor, depending on the second argument: + [TCOOFF] suspends output, [TCOON] restarts output, + [TCIOFF] transmits a STOP character to suspend input, + and [TCION] transmits a START character to restart input. *) + +val setsid : unit -> int +(** Put the calling process in a new session and detach it from + its controlling terminal. *) diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c new file mode 100644 index 0000000..a73e133 --- /dev/null +++ b/otherlibs/unix/unixsupport.c @@ -0,0 +1,293 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unixsupport.c,v 1.18 2005-09-06 12:38:32 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <callback.h> +#include <memory.h> +#include <fail.h> +#include "unixsupport.h" +#include "cst2constr.h" +#include <errno.h> + +#ifndef E2BIG +#define E2BIG (-1) +#endif +#ifndef EACCES +#define EACCES (-1) +#endif +#ifndef EAGAIN +#define EAGAIN (-1) +#endif +#ifndef EBADF +#define EBADF (-1) +#endif +#ifndef EBUSY +#define EBUSY (-1) +#endif +#ifndef ECHILD +#define ECHILD (-1) +#endif +#ifndef EDEADLK +#define EDEADLK (-1) +#endif +#ifndef EDOM +#define EDOM (-1) +#endif +#ifndef EEXIST +#define EEXIST (-1) +#endif + +#ifndef EFAULT +#define EFAULT (-1) +#endif +#ifndef EFBIG +#define EFBIG (-1) +#endif +#ifndef EINTR +#define EINTR (-1) +#endif +#ifndef EINVAL +#define EINVAL (-1) +#endif +#ifndef EIO +#define EIO (-1) +#endif +#ifndef EISDIR +#define EISDIR (-1) +#endif +#ifndef EMFILE +#define EMFILE (-1) +#endif +#ifndef EMLINK +#define EMLINK (-1) +#endif +#ifndef ENAMETOOLONG +#define ENAMETOOLONG (-1) +#endif +#ifndef ENFILE +#define ENFILE (-1) +#endif +#ifndef ENODEV +#define ENODEV (-1) +#endif +#ifndef ENOENT +#define ENOENT (-1) +#endif +#ifndef ENOEXEC +#define ENOEXEC (-1) +#endif +#ifndef ENOLCK +#define ENOLCK (-1) +#endif +#ifndef ENOMEM +#define ENOMEM (-1) +#endif +#ifndef ENOSPC +#define ENOSPC (-1) +#endif +#ifndef ENOSYS +#define ENOSYS (-1) +#endif +#ifndef ENOTDIR +#define ENOTDIR (-1) +#endif +#ifndef ENOTEMPTY +#define ENOTEMPTY (-1) +#endif +#ifndef ENOTTY +#define ENOTTY (-1) +#endif +#ifndef ENXIO +#define ENXIO (-1) +#endif +#ifndef EPERM +#define EPERM (-1) +#endif +#ifndef EPIPE +#define EPIPE (-1) +#endif +#ifndef ERANGE +#define ERANGE (-1) +#endif +#ifndef EROFS +#define EROFS (-1) +#endif +#ifndef ESPIPE +#define ESPIPE (-1) +#endif +#ifndef ESRCH +#define ESRCH (-1) +#endif +#ifndef EXDEV +#define EXDEV (-1) +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK (-1) +#endif +#ifndef EINPROGRESS +#define EINPROGRESS (-1) +#endif +#ifndef EALREADY +#define EALREADY (-1) +#endif +#ifndef ENOTSOCK +#define ENOTSOCK (-1) +#endif +#ifndef EDESTADDRREQ +#define EDESTADDRREQ (-1) +#endif +#ifndef EMSGSIZE +#define EMSGSIZE (-1) +#endif +#ifndef EPROTOTYPE +#define EPROTOTYPE (-1) +#endif +#ifndef ENOPROTOOPT +#define ENOPROTOOPT (-1) +#endif +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT (-1) +#endif +#ifndef ESOCKTNOSUPPORT +#define ESOCKTNOSUPPORT (-1) +#endif +#ifndef EOPNOTSUPP +#define EOPNOTSUPP (-1) +#endif +#ifndef EPFNOSUPPORT +#define EPFNOSUPPORT (-1) +#endif +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT (-1) +#endif +#ifndef EADDRINUSE +#define EADDRINUSE (-1) +#endif +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL (-1) +#endif +#ifndef ENETDOWN +#define ENETDOWN (-1) +#endif +#ifndef ENETUNREACH +#define ENETUNREACH (-1) +#endif +#ifndef ENETRESET +#define ENETRESET (-1) +#endif +#ifndef ECONNABORTED +#define ECONNABORTED (-1) +#endif +#ifndef ECONNRESET +#define ECONNRESET (-1) +#endif +#ifndef ENOBUFS +#define ENOBUFS (-1) +#endif +#ifndef EISCONN +#define EISCONN (-1) +#endif +#ifndef ENOTCONN +#define ENOTCONN (-1) +#endif +#ifndef ESHUTDOWN +#define ESHUTDOWN (-1) +#endif +#ifndef ETOOMANYREFS +#define ETOOMANYREFS (-1) +#endif +#ifndef ETIMEDOUT +#define ETIMEDOUT (-1) +#endif +#ifndef ECONNREFUSED +#define ECONNREFUSED (-1) +#endif +#ifndef EHOSTDOWN +#define EHOSTDOWN (-1) +#endif +#ifndef EHOSTUNREACH +#define EHOSTUNREACH (-1) +#endif +#ifndef ENOTEMPTY +#define ENOTEMPTY (-1) +#endif +#ifndef ELOOP +#define ELOOP (-1) +#endif +#ifndef EOVERFLOW +#define EOVERFLOW (-1) +#endif + +int error_table[] = { + E2BIG, EACCES, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM, + EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK, + ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC, + ENOSYS, ENOTDIR, ENOTEMPTY, ENOTTY, ENXIO, EPERM, EPIPE, ERANGE, + EROFS, ESPIPE, ESRCH, EXDEV, EWOULDBLOCK, EINPROGRESS, EALREADY, + ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, + EPROTONOSUPPORT, ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, + EAFNOSUPPORT, EADDRINUSE, EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, + ENETRESET, ECONNABORTED, ECONNRESET, ENOBUFS, EISCONN, ENOTCONN, + ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, EHOSTDOWN, + EHOSTUNREACH, ELOOP, EOVERFLOW /*, EUNKNOWNERR */ +}; + +static value * unix_error_exn = NULL; + +value unix_error_of_code (int errcode) +{ + int errconstr; + value err; + + errconstr = + cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); + if (errconstr == Val_int(-1)) { + err = alloc_small(1, 0); + Field(err, 0) = Val_int(errcode); + } else { + err = errconstr; + } + return err; +} + +void unix_error(int errcode, char *cmdname, value cmdarg) +{ + value res; + value name = Val_unit, err = Val_unit, arg = Val_unit; + + Begin_roots3 (name, err, arg); + arg = cmdarg == Nothing ? copy_string("") : cmdarg; + name = copy_string(cmdname); + err = unix_error_of_code (errcode); + if (unix_error_exn == NULL) { + unix_error_exn = caml_named_value("Unix.Unix_error"); + if (unix_error_exn == NULL) + invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma"); + } + res = alloc_small(4, 0); + Field(res, 0) = *unix_error_exn; + Field(res, 1) = err; + Field(res, 2) = name; + Field(res, 3) = arg; + End_roots(); + mlraise(res); +} + +void uerror(char *cmdname, value cmdarg) +{ + unix_error(errno, cmdname, cmdarg); +} + diff --git a/otherlibs/unix/unixsupport.h b/otherlibs/unix/unixsupport.h new file mode 100644 index 0000000..e58dbd9 --- /dev/null +++ b/otherlibs/unix/unixsupport.h @@ -0,0 +1,28 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unixsupport.h,v 1.8 2005-09-06 12:38:32 doligez Exp $ */ + +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +#define Nothing ((value) 0) + +extern value unix_error_of_code (int errcode); +extern void unix_error (int errcode, char * cmdname, value arg) Noreturn; +extern void uerror (char * cmdname, value arg) Noreturn; + +#define UNIX_BUFFER_SIZE 16384 + +#define DIR_Val(v) *((DIR **) &Field(v, 0)) diff --git a/otherlibs/unix/unlink.c b/otherlibs/unix/unlink.c new file mode 100644 index 0000000..8c5b560 --- /dev/null +++ b/otherlibs/unix/unlink.c @@ -0,0 +1,23 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unlink.c,v 1.8 2001-12-07 13:40:39 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_unlink(value path) +{ + if (unlink(String_val(path)) == -1) uerror("unlink", path); + return Val_unit; +} diff --git a/otherlibs/unix/utimes.c b/otherlibs/unix/utimes.c new file mode 100644 index 0000000..2b13fe6 --- /dev/null +++ b/otherlibs/unix/utimes.c @@ -0,0 +1,72 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: utimes.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <fail.h> +#include <mlvalues.h> +#include "unixsupport.h" + +#ifdef HAS_UTIME + +#include <sys/types.h> +#ifndef _WIN32 +#include <utime.h> +#else +#include <sys/utime.h> +#endif + +CAMLprim value unix_utimes(value path, value atime, value mtime) +{ + struct utimbuf times, * t; + times.actime = Double_val(atime); + times.modtime = Double_val(mtime); + if (times.actime || times.modtime) + t = × + else + t = (struct utimbuf *) NULL; + if (utime(String_val(path), t) == -1) uerror("utimes", path); + return Val_unit; +} + +#else + +#ifdef HAS_UTIMES + +#include <sys/types.h> +#include <sys/time.h> + +CAMLprim value unix_utimes(value path, value atime, value mtime) +{ + struct timeval tv[2], * t; + double at = Double_val(atime); + double mt = Double_val(mtime); + tv[0].tv_sec = at; + tv[0].tv_usec = (at - tv[0].tv_sec) * 1000000; + tv[1].tv_sec = mt; + tv[1].tv_usec = (mt - tv[1].tv_sec) * 1000000; + if (tv[0].tv_sec || tv[1].tv_sec) + t = tv; + else + t = (struct timeval *) NULL; + if (utimes(String_val(path), t) == -1) uerror("utimes", path); + return Val_unit; +} + +#else + +CAMLprim value unix_utimes(value path, value atime, value mtime) +{ invalid_argument("utimes not implemented"); } + +#endif +#endif diff --git a/otherlibs/unix/wait.c b/otherlibs/unix/wait.c new file mode 100644 index 0000000..43423bf --- /dev/null +++ b/otherlibs/unix/wait.c @@ -0,0 +1,102 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: wait.c,v 1.19 2005-04-17 08:23:51 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <fail.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#include <sys/types.h> +#include <sys/wait.h> + +#if !(defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSTOPPED) && \ + defined(WSTOPSIG) && defined(WTERMSIG)) +/* Assume old-style V7 status word */ +#define WIFEXITED(status) (((status) & 0xFF) == 0) +#define WEXITSTATUS(status) (((status) >> 8) & 0xFF) +#define WIFSTOPPED(status) (((status) & 0xFF) == 0xFF) +#define WSTOPSIG(status) (((status) >> 8) & 0xFF) +#define WTERMSIG(status) ((status) & 0x3F) +#endif + +#define TAG_WEXITED 0 +#define TAG_WSIGNALED 1 +#define TAG_WSTOPPED 2 + +static value alloc_process_status(int pid, int status) +{ + value st, res; + + if (WIFEXITED(status)) { + st = alloc_small(1, TAG_WEXITED); + Field(st, 0) = Val_int(WEXITSTATUS(status)); + } + else if (WIFSTOPPED(status)) { + st = alloc_small(1, TAG_WSTOPPED); + Field(st, 0) = Val_int(caml_rev_convert_signal_number(WSTOPSIG(status))); + } + else { + st = alloc_small(1, TAG_WSIGNALED); + Field(st, 0) = Val_int(caml_rev_convert_signal_number(WTERMSIG(status))); + } + Begin_root (st); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(pid); + Field(res, 1) = st; + End_roots(); + return res; +} + +CAMLprim value unix_wait(value unit) +{ + int pid, status; + + enter_blocking_section(); + pid = wait(&status); + leave_blocking_section(); + if (pid == -1) uerror("wait", Nothing); + return alloc_process_status(pid, status); +} + +#if defined(HAS_WAITPID) || defined(HAS_WAIT4) + +#ifndef HAS_WAITPID +#define waitpid(pid,status,opts) wait4(pid,status,opts,NULL) +#endif + +static int wait_flag_table[] = { + WNOHANG, WUNTRACED +}; + +CAMLprim value unix_waitpid(value flags, value pid_req) +{ + int pid, status, cv_flags; + + cv_flags = convert_flag_list(flags, wait_flag_table); + enter_blocking_section(); + pid = waitpid(Int_val(pid_req), &status, cv_flags); + leave_blocking_section(); + if (pid == -1) uerror("waitpid", Nothing); + return alloc_process_status(pid, status); +} + +#else + +CAMLprim value unix_waitpid(value flags, value pid_req) +{ invalid_argument("waitpid not implemented"); } + +#endif diff --git a/otherlibs/unix/write.c b/otherlibs/unix/write.c new file mode 100644 index 0000000..b087729 --- /dev/null +++ b/otherlibs/unix/write.c @@ -0,0 +1,87 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: write.c,v 1.14 2004-07-13 12:25:15 xleroy Exp $ */ + +#include <errno.h> +#include <string.h> +#include <mlvalues.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +#ifndef EAGAIN +#define EAGAIN (-1) +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK (-1) +#endif + +CAMLprim value unix_write(value fd, value buf, value vofs, value vlen) +{ + long ofs, len, written; + int numbytes, ret; + char iobuf[UNIX_BUFFER_SIZE]; + + Begin_root (buf); + ofs = Long_val(vofs); + len = Long_val(vlen); + written = 0; + while (len > 0) { + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + memmove (iobuf, &Byte(buf, ofs), numbytes); + enter_blocking_section(); + ret = write(Int_val(fd), iobuf, numbytes); + leave_blocking_section(); + if (ret == -1) { + if ((errno == EAGAIN || errno == EWOULDBLOCK) && written > 0) break; + uerror("write", Nothing); + } + written += ret; + ofs += ret; + len -= ret; + } + End_roots(); + return Val_long(written); +} + +/* When an error occurs after the first loop, unix_write reports the + error and discards the number of already written characters. + In this case, it would be better to discard the error and return the + number of bytes written, since most likely, unix_write will be call again, + and the error will be reproduced and this time will be reported. + This problem is avoided in unix_single_write, which is faithful to the + Unix system call. */ + +CAMLprim value unix_single_write(value fd, value buf, value vofs, value vlen) +{ + long ofs, len; + int numbytes, ret; + char iobuf[UNIX_BUFFER_SIZE]; + + Begin_root (buf); + ofs = Long_val(vofs); + len = Long_val(vlen); + ret = 0; + if (len > 0) { + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + memmove (iobuf, &Byte(buf, ofs), numbytes); + enter_blocking_section(); + ret = write(Int_val(fd), iobuf, numbytes); + leave_blocking_section(); + if (ret == -1) uerror("single_write", Nothing); + } + End_roots(); + return Val_int(ret); +} + diff --git a/otherlibs/win32graph/Makefile.nt b/otherlibs/win32graph/Makefile.nt new file mode 100644 index 0000000..8446390 --- /dev/null +++ b/otherlibs/win32graph/Makefile.nt @@ -0,0 +1,35 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 2001 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.8 2007-11-06 15:16:56 frisch Exp $ + +LIBNAME=graphics +COBJS=open.$(O) draw.$(O) events.$(O) dib.$(O) +CAMLOBJS=graphics.cmo +WIN32LIBS=$(call SYSLIB,kernel32) $(call SYSLIB,gdi32) $(call SYSLIB,user32) +LINKOPTS=-cclib "\"$(WIN32LIBS)\"" +LDOPTS=-ldopt "$(WIN32LIBS)" + +include ../Makefile.nt + +graphics.ml: ../graph/graphics.ml + cp ../graph/graphics.ml graphics.ml +graphics.mli: ../graph/graphics.mli + cp ../graph/graphics.mli graphics.mli + +depend: + +graphics.cmo: graphics.cmi +graphics.cmx: graphics.cmi +draw.$(O): libgraph.h +open.$(O): libgraph.h diff --git a/otherlibs/win32graph/dib.c b/otherlibs/win32graph/dib.c new file mode 100644 index 0000000..627e704 --- /dev/null +++ b/otherlibs/win32graph/dib.c @@ -0,0 +1,496 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dib.c,v 1.3 2002-07-23 14:12:00 doligez Exp $ */ + +//----------------------------------------------------------------------------- +// DIB.C +// +// This is a collection of useful DIB manipulation/information gathering +// functions. Many functions are supplied simply to take the burden +// of taking into account whether a DIB is a Win30 style or OS/2 style +// DIB away from the application. +// +// The functions in this module assume that the DIB pointers or handles +// passed to them point to a block of memory in one of two formats: +// +// a) BITMAPINFOHEADER + color table + DIB bits (3.0 style DIB) +// b) BITMAPCOREHEADER + color table + DIB bits (OS/2 PM style) +// +// The SDK Reference, Volume 2 describes these data structures. +// +// A number of functions in this module were lifted from SHOWDIB, +// and modified to handle OS/2 DIBs. +// +// The functions in this module could be streamlined (made faster and +// smaller) by removing the OS/2 DIB specific code, and assuming all +// DIBs passed to it are Win30 style DIBs. The DIB file reading code +// would need to be modified to always convert DIBs to Win30 style +// DIBs. The only reason this isn't done in DIBView is because DIBView +// was written to test display and printer drivers (which are supposed +// to support OS/2 DIBs wherever they support Win30 style DIBs). SHOWDIB +// is a great example of how to go about doing this. +//----------------------------------------------------------------------------- + + +#include <windows.h> +#include <memory.h> +#include <string.h> +#include <io.h> +#include <stdio.h> + // Size of window extra bytes (we store a handle to a PALINFO structure). + +#define PAL_CBWNDEXTRA (1 * sizeof (WORD)) + + +typedef struct + { + HPALETTE hPal; // Handle to palette being displayed. + WORD wEntries; // # of entries in the palette. + int nSquareSize; // Size of palette square (see PAL_SIZE) + HWND hInfoWnd; // Handle to the info bar window. + int nRows, nCols; // # of Rows/Columns in window. + int cxSquare, cySquare; // Pixel width/height of palette square. + WORD wEntry; // Currently selected palette square. + } PALINFO, FAR *LPPALINFO; + // Window Words. +#define WW_PAL_HPALINFO 0 // Handle to PALINFO structure. + // The following define is for CopyPaletteChangingFlags(). +#define DONT_CHANGE_FLAGS -1 + // The following is the palette version that goes in a + // LOGPALETTE's palVersion field. +#define PALVERSION 0x300 +// This is an enumeration for the various ways we can display +// a palette in PaletteWndProc(). +enum PAL_SIZE + { + PALSIZE_TINY = 0, + PALSIZE_SMALL, + PALSIZE_MEDIUM, + PALSIZE_LARGE + }; +#define CopyPalette(hPal) CopyPaletteChangingFlags (hPal, DONT_CHANGE_FLAGS) +#define CopyPalForAnimation(hPal) CopyPaletteChangingFlags (hPal, PC_RESERVED) +// WIDTHBYTES takes # of bits in a scan line and rounds up to nearest +// word. +#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4) + + // Given a pointer to a DIB header, return TRUE if is a Windows 3.0 style + // DIB, false if otherwise (PM style DIB). +#define IS_WIN30_DIB(lpbi) ((*(LPDWORD) (lpbi)) == sizeof (BITMAPINFOHEADER)) + +static WORD PaletteSize (LPSTR lpbi); + +extern void ShowDbgMsg(char *); +static BOOL MyRead (int, LPSTR, DWORD); +/*-------------- DIB header Marker Define -------------------------*/ +#define DIB_HEADER_MARKER ((WORD) ('M' << 8) | 'B') +/*-------------- MyRead Function Define ---------------------------*/ + +// When we read in a DIB, we read it in in chunks. We read half a segment +// at a time. This way we insure that we don't cross any segment +// boundries in _lread() during a read. We don't read in a full segment +// at a time, since _lread takes some "int" type parms instead of +// WORD type params (it'd work, but the compiler would give you warnings)... + +#define BYTES_PER_READ 32767 + +/*-------------- Define for PM DIB -------------------------------*/ +// The constants for RGB, RLE4, RLE8 are already defined inside +// of Windows.h + +#define BI_PM 3L + + +/*-------------- Magic numbers -------------------------------------*/ +// Maximum length of a filename for DOS is 128 characters. + +#define MAX_FILENAME 129 + + +/*-------------- TypeDef Structures -------------------------------*/ + +typedef struct InfoStruct + { + char szName[13]; + char szType[15]; + DWORD cbWidth; + DWORD cbHeight; + DWORD cbColors; + char szCompress[5]; + } INFOSTRUCT; + +// Some macros. +#define RECTWIDTH(lpRect) ((lpRect)->right - (lpRect)->left) +#define RECTHEIGHT(lpRect) ((lpRect)->bottom - (lpRect)->top) +//--------------------------------------------------------------------- +// +// Function: FindDIBBits +// +// Purpose: Given a pointer to a DIB, returns a pointer to the +// DIB's bitmap bits. +// +// Parms: lpbi == pointer to DIB header (either BITMAPINFOHEADER +// or BITMAPCOREHEADER) +// +// History: Date Reason +// 6/01/91 Created +// +//--------------------------------------------------------------------- +static LPSTR FindDIBBits (LPSTR lpbi) +{ + return (lpbi + *(LPDWORD)lpbi + PaletteSize (lpbi)); +} + + +//--------------------------------------------------------------------- +// +// Function: DIBNumColors +// +// Purpose: Given a pointer to a DIB, returns a number of colors in +// the DIB's color table. +// +// Parms: lpbi == pointer to DIB header (either BITMAPINFOHEADER +// or BITMAPCOREHEADER) +// +// History: Date Reason +// 6/01/91 Created +// +//--------------------------------------------------------------------- +static WORD DIBNumColors (LPSTR lpbi) +{ + WORD wBitCount; + + + // If this is a Windows style DIB, the number of colors in the + // color table can be less than the number of bits per pixel + // allows for (i.e. lpbi->biClrUsed can be set to some value). + // If this is the case, return the appropriate value. + + if (IS_WIN30_DIB (lpbi)) + { + DWORD dwClrUsed; + + dwClrUsed = ((LPBITMAPINFOHEADER) lpbi)->biClrUsed; + + if (dwClrUsed) + return (WORD) dwClrUsed; + } + + + // Calculate the number of colors in the color table based on + // the number of bits per pixel for the DIB. + + if (IS_WIN30_DIB (lpbi)) + wBitCount = ((LPBITMAPINFOHEADER) lpbi)->biBitCount; + else + wBitCount = ((LPBITMAPCOREHEADER) lpbi)->bcBitCount; + + switch (wBitCount) + { + case 1: + return 2; + + case 4: + return 16; + + case 8: + return 256; + + default: + return 0; + } +} + +//--------------------------------------------------------------------- +// +// Function: PaletteSize +// +// Purpose: Given a pointer to a DIB, returns number of bytes +// in the DIB's color table. +// +// Parms: lpbi == pointer to DIB header (either BITMAPINFOHEADER +// or BITMAPCOREHEADER) +// +// History: Date Reason +// 6/01/91 Created +// +//--------------------------------------------------------------------- +static WORD PaletteSize (LPSTR lpbi) +{ + if (IS_WIN30_DIB (lpbi)) + return (DIBNumColors (lpbi) * sizeof (RGBQUAD)); + else + return (DIBNumColors (lpbi) * sizeof (RGBTRIPLE)); +} + +//--------------------------------------------------------------------- +// +// Function: DIBHeight +// +// Purpose: Given a pointer to a DIB, returns its height. Note +// that it returns a DWORD (since a Win30 DIB can have +// a DWORD in its height field), but under Win30, the +// high order word isn't used! +// +// Parms: lpDIB == pointer to DIB header (either BITMAPINFOHEADER +// or BITMAPCOREHEADER) +// +// History: Date Reason +// 6/01/91 Created +// +//--------------------------------------------------------------------- +static DWORD DIBHeight (LPSTR lpDIB) +{ + LPBITMAPINFOHEADER lpbmi; + LPBITMAPCOREHEADER lpbmc; + + lpbmi = (LPBITMAPINFOHEADER) lpDIB; + lpbmc = (LPBITMAPCOREHEADER) lpDIB; + + if (lpbmi->biSize == sizeof (BITMAPINFOHEADER)) + return lpbmi->biHeight; + else + return (DWORD) lpbmc->bcHeight; +} + +/************************************************************************* + + Function: ReadDIBFile (int) + + Purpose: Reads in the specified DIB file into a global chunk of + memory. + + Returns: A handle to a dib (hDIB) if successful. + NULL if an error occurs. + + Comments: BITMAPFILEHEADER is stripped off of the DIB. Everything + from the end of the BITMAPFILEHEADER structure on is + returned in the global memory handle. + + History: Date Author Reason + + 6/1/91 Created + 6/27/91 Removed PM bitmap conversion routines. + 6/31/91 Removed logic which overallocated memory + (to account for bad display drivers). + 11/08/91 Again removed logic which overallocated + memory (it had creeped back in!) + +*************************************************************************/ +static HANDLE ReadDIBFile (int hFile,int dwBitsSize) +{ + BITMAPFILEHEADER bmfHeader; + HANDLE hDIB; + LPSTR pDIB; + + + + // Go read the DIB file header and check if it's valid. + + if ((_lread (hFile, (LPSTR) &bmfHeader, sizeof (bmfHeader)) != sizeof (bmfHeader)) || + (bmfHeader.bfType != DIB_HEADER_MARKER)) + { + // ShowDbgMsg("Not a DIB file!"); + return NULL; + } + + // Allocate memory for DIB + + hDIB = GlobalAlloc (GMEM_SHARE|GMEM_MOVEABLE | GMEM_ZEROINIT, dwBitsSize - sizeof(BITMAPFILEHEADER)); + + if (hDIB == 0) + { + // ShowDbgMsg("Couldn't allocate memory!"); + return NULL; + } + + pDIB = GlobalLock (hDIB); + + // Go read the bits. + + if (!MyRead (hFile, pDIB, dwBitsSize - sizeof(BITMAPFILEHEADER))) + { + GlobalUnlock (hDIB); + GlobalFree (hDIB); + // ShowDbgMsg("Error reading file!"); + return NULL; + } + + + GlobalUnlock (hDIB); + return hDIB; +} + +/************************************************************************* + + Function: MyRead (int, LPSTR, DWORD) + + Purpose: Routine to read files greater than 64K in size. + + Returns: TRUE if successful. + FALSE if an error occurs. + + Comments: + + History: Date Reason + + 6/1/91 Created + +*************************************************************************/ +static BOOL MyRead (int hFile, LPSTR lpBuffer, DWORD dwSize) +{ + char *lpInBuf = (char *) lpBuffer; + int nBytes; + + + while (dwSize) + { + nBytes = (int) (dwSize > (DWORD) BYTES_PER_READ ? BYTES_PER_READ : + LOWORD (dwSize)); + + if (_lread (hFile, (LPSTR) lpInBuf, nBytes) != (WORD) nBytes) + return FALSE; + + dwSize -= nBytes; + lpInBuf += nBytes; + } + + return TRUE; +} + +//--------------------------------------------------------------------- +// +// Function: DIBPaint +// +// Purpose: Painting routine for a DIB. Calls StretchDIBits() or +// SetDIBitsToDevice() to paint the DIB. The DIB is +// output to the specified DC, at the coordinates given +// in lpDCRect. The area of the DIB to be output is +// given by lpDIBRect. The specified palette is used. +// +// Parms: hDC == DC to do output to. +// lpDCRect == Rectangle on DC to do output to. +// hDIB == Handle to global memory with a DIB spec +// in it (either a BITMAPINFO or BITMAPCOREINFO +// followed by the DIB bits). +// lpDIBRect == Rect of DIB to output into lpDCRect. +// hPal == Palette to be used. +// +// History: Date Reason +// 6/01/91 Created +// +//--------------------------------------------------------------------- +static void DIBPaint (HDC hDC,LPRECT lpDCRect,HANDLE hDIB) +{ + LPSTR lpDIBHdr, lpDIBBits; + + if (!hDIB) + return; + // Lock down the DIB, and get a pointer to the beginning of the bit + // buffer. + lpDIBHdr = GlobalLock (hDIB); + lpDIBBits = FindDIBBits (lpDIBHdr); + // Make sure to use the stretching mode best for color pictures. + SetStretchBltMode (hDC, COLORONCOLOR); + SetDIBitsToDevice (hDC, // hDC + lpDCRect->left, // DestX + lpDCRect->top, // DestY + RECTWIDTH (lpDCRect), // nDestWidth + RECTHEIGHT (lpDCRect), // nDestHeight + 0, // SrcX + 0, + // (int) DIBHeight (lpDIBHdr), // SrcY + 0, // nStartScan + (WORD) DIBHeight (lpDIBHdr), // nNumScans + lpDIBBits, // lpBits + (LPBITMAPINFO) lpDIBHdr, // lpBitsInfo + DIB_RGB_COLORS); // wUsage + + GlobalUnlock (hDIB); +} + +static unsigned int Getfilesize(char *name) +{ + FILE *f; + unsigned int size; + + f = fopen(name,"rb"); + if (f == NULL) + return 0; + fseek(f,0,SEEK_END); + size = ftell(f); + fclose(f); + return size; +} + + +HANDLE ChargerBitmap(char *FileName,POINT *lppt) +{ + HFILE hFile; + OFSTRUCT ofstruct; + HANDLE result; + LPSTR lpDIBHdr; + unsigned int size; + + size = Getfilesize(FileName); + hFile=OpenFile((LPSTR) FileName, &ofstruct, OF_READ | OF_SHARE_DENY_WRITE); + result = ReadDIBFile(hFile,size); + if (hFile) _lclose(hFile); + if (result) { + LPBITMAPINFOHEADER lpbmi; + LPBITMAPCOREHEADER lpbmc; + + lpDIBHdr = GlobalLock (result); + lpbmi = (LPBITMAPINFOHEADER) lpDIBHdr; + lpbmc = (LPBITMAPCOREHEADER) lpDIBHdr; + + if (lpbmi->biSize == sizeof (BITMAPINFOHEADER)) { + lppt->y = lpbmi->biHeight; + lppt->x = lpbmi->biWidth; + } + else { + lppt->y = lpbmc->bcHeight; + lppt->x = lpbmc->bcWidth; + } + GlobalUnlock(result); + } + return(result); +} + +void DessinerBitmap(HANDLE hDIB,HDC hDC,LPRECT lpDCRect) +{ + DIBPaint (hDC, + lpDCRect, + hDIB); +} + +void AfficheBitmap(char *filename,HDC hDC,int x,int y) +{ + RECT rc; + HANDLE hdib; + POINT pt; + char titi[60]; + + hdib = ChargerBitmap(filename,&pt); + if (hdib == NULL) { + return; + } + rc.top = y; + rc.left = x; + rc.right = pt.x+x; + rc.bottom = pt.y+y; + pt.y += GetSystemMetrics(SM_CYCAPTION); + DessinerBitmap(hdib,hDC,&rc); + GlobalFree(hdib); +} + diff --git a/otherlibs/win32graph/dllgraphics.dlib b/otherlibs/win32graph/dllgraphics.dlib new file mode 100644 index 0000000..ab0ba91 --- /dev/null +++ b/otherlibs/win32graph/dllgraphics.dlib @@ -0,0 +1 @@ +open.d.o draw.d.o events.d.o dib.d.o diff --git a/otherlibs/win32graph/draw.c b/otherlibs/win32graph/draw.c new file mode 100644 index 0000000..31e98ac --- /dev/null +++ b/otherlibs/win32graph/draw.c @@ -0,0 +1,648 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia, based on code by J-M Geffroy and X Leroy */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: draw.c,v 1.11 2005-03-24 17:20:53 doligez Exp $ */ + +#include <math.h> +#include "mlvalues.h" +#include "alloc.h" +#include "fail.h" +#include "libgraph.h" +#include "custom.h" +#include "memory.h" + +HDC gcMetaFile; +int grdisplay_mode; +int grremember_mode; +GR_WINDOW grwindow; + +static void GetCurrentPosition(HDC hDC,POINT *pt) +{ + MoveToEx(hDC,0,0,pt); + MoveToEx(hDC,pt->x,pt->y,0); +} + +static value gr_draw_or_fill_arc(value vx, value vy, value vrx, value vry, + value vstart, value vend, BOOL fill); + +CAMLprim value caml_gr_plot(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + gr_check_open(); + if(grremember_mode) + SetPixel(grwindow.gcBitmap, x, Wcvt(y),grwindow.CurrentColor); + if(grdisplay_mode) { + SetPixel(grwindow.gc, x, Wcvt(y),grwindow.CurrentColor); + } + return Val_unit; +} + +CAMLprim value caml_gr_moveto(value vx, value vy) +{ + grwindow.grx = Int_val(vx); + grwindow.gry = Int_val(vy); + if(grremember_mode) + MoveToEx(grwindow.gcBitmap,grwindow.grx,Wcvt(grwindow.gry),0); + if (grdisplay_mode) + MoveToEx(grwindow.gc,grwindow.grx,Wcvt(grwindow.gry),0); + return Val_unit; +} + +CAMLprim value caml_gr_current_x(void) +{ + return Val_int(grwindow.grx); +} + +CAMLprim value caml_gr_current_y(void) +{ + return Val_int(grwindow.gry); +} + +CAMLprim value caml_gr_lineto(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + gr_check_open(); + SelectObject(grwindow.gc,grwindow.CurrentPen); + SelectObject(grwindow.gcBitmap,grwindow.CurrentPen); + if (grremember_mode) + LineTo(grwindow.gcBitmap,x,Wcvt(y)); + if (grdisplay_mode) + LineTo(grwindow.gc, x, Wcvt(y)); + grwindow.grx = x; + grwindow.gry = y; + return Val_unit; +} + +CAMLprim value caml_gr_draw_rect(value vx, value vy, value vw, value vh) +{ + int x, y, w, h; + POINT pt[5]; + x=Int_val(vx); + y=Wcvt(Int_val(vy)); + w=Int_val(vw); + h=Int_val(vh); + + pt[0].x = x; pt[0].y = y - h; + pt[1].x = x + w; pt[1].y = y - h; + pt[2].x = x + w; pt[2].y = y; + pt[3].x = x; pt[3].y = y; + pt[4].x = x; pt[4].y = y - h; + if (grremember_mode) { + Polyline(grwindow.gcBitmap,pt, 5); + } + if (grdisplay_mode) { + Polyline(grwindow.gc,pt, 5); + } + return Val_unit; +} + +CAMLprim value caml_gr_draw_text(value text,value x) +{ + POINT pt; + int oldmode = SetBkMode(grwindow.gc,TRANSPARENT); + SetBkMode(grwindow.gcBitmap,TRANSPARENT); + SetTextAlign(grwindow.gcBitmap, TA_UPDATECP|TA_BOTTOM); + SetTextAlign(grwindow.gc, TA_UPDATECP|TA_BOTTOM); + if (grremember_mode) { + TextOut(grwindow.gcBitmap,0,0,(char *)text,x); + } + if(grdisplay_mode) { + TextOut(grwindow.gc,0,0,(char *)text,x); + } + GetCurrentPosition(grwindow.gc,&pt); + grwindow.grx = pt.x; + grwindow.gry = grwindow.height - pt.y; + SetBkMode(grwindow.gc,oldmode); + SetBkMode(grwindow.gcBitmap,oldmode); + return Val_unit; +} + +CAMLprim value caml_gr_fill_rect(value vx, value vy, value vw, value vh) +{ + int x = Int_val(vx); + int y = Int_val(vy); + int w = Int_val(vw); + int h = Int_val(vh); + RECT rc; + + gr_check_open(); + rc.left = x; + rc.top = Wcvt(y); + rc.right = x+w; + rc.bottom = Wcvt(y)-h; + if (grdisplay_mode) + FillRect(grwindow.gc,&rc,grwindow.CurrentBrush); + if (grremember_mode) + FillRect(grwindow.gcBitmap,&rc,grwindow.CurrentBrush); + return Val_unit; +} + +CAMLprim value caml_gr_sound(value freq, value vdur) +{ + Beep(freq,vdur); + return Val_unit; +} + +CAMLprim value caml_gr_point_color(value vx, value vy) +{ + int x = Int_val(vx); + int y = Int_val(vy); + COLORREF rgb; + unsigned long b,g,r; + + gr_check_open(); + rgb = GetPixel(grwindow.gcBitmap,x,Wcvt(y)); + b = (unsigned long)((rgb & 0xFF0000) >> 16); + g = (unsigned long)((rgb & 0x00FF00) >> 8); + r = (unsigned long)(rgb & 0x0000FF); + return Val_long((r<<16) + (g<<8) + b); +} + +CAMLprim value caml_gr_circle(value x,value y,value radius) +{ + int left,top,right,bottom; + + gr_check_open(); + left = x - radius/2; + top = Wcvt(y) - radius/2; + right = left+radius; + bottom = top+radius; + Ellipse(grwindow.gcBitmap,left,top,right,bottom); + return Val_unit; +} + +CAMLprim value caml_gr_set_window_title(value text) +{ + SetWindowText(grwindow.hwnd,(char *)text); + return Val_unit; +} + +CAMLprim value caml_gr_draw_arc(value *argv, int argc) +{ + return gr_draw_or_fill_arc(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], FALSE); +} + +CAMLprim value caml_gr_draw_arc_nat(vx, vy, vrx, vry, vstart, vend) +{ + return gr_draw_or_fill_arc(vx, vy, vrx, vry, vstart, vend, FALSE); +} + +CAMLprim value caml_gr_set_line_width(value vwidth) +{ + int width = Int_val(vwidth); + HPEN oldPen,newPen; + + gr_check_open(); + oldPen = grwindow.CurrentPen; + newPen = CreatePen(PS_SOLID,width,grwindow.CurrentColor); + SelectObject(grwindow.gcBitmap,newPen); + SelectObject(grwindow.gc,newPen); + DeleteObject(oldPen); + grwindow.CurrentPen = newPen; + return Val_unit; +} + +CAMLprim value caml_gr_set_color(value vcolor) +{ + HBRUSH oldBrush, newBrush; + LOGBRUSH lb; + LOGPEN pen; + HPEN newPen; + int color = Long_val(vcolor); + + int r = (color & 0xFF0000) >> 16, + g = (color & 0x00FF00) >> 8 , + b = color & 0x0000FF; + COLORREF c = RGB(r,g,b); + memset(&lb,0,sizeof(lb)); + memset(&pen,0,sizeof(LOGPEN)); + gr_check_open(); + GetObject(grwindow.CurrentPen,sizeof(LOGPEN),&pen); + pen.lopnColor = c; + newPen = CreatePenIndirect(&pen); + SelectObject(grwindow.gcBitmap,newPen); + SelectObject(grwindow.gc,newPen); + DeleteObject(grwindow.CurrentPen); + grwindow.CurrentPen = newPen; + SetTextColor(grwindow.gc,c); + SetTextColor(grwindow.gcBitmap,c); + oldBrush = grwindow.CurrentBrush; + lb.lbStyle = BS_SOLID; + lb.lbColor = c; + newBrush = CreateBrushIndirect(&lb); + SelectObject(grwindow.gc,newBrush); + SelectObject(grwindow.gcBitmap,newBrush); + DeleteObject(oldBrush); + grwindow.CurrentBrush = newBrush; + grwindow.CurrentColor = c; + return Val_unit; +} + + +static value gr_draw_or_fill_arc(value vx, value vy, value vrx, value vry, + value vstart, value vend, BOOL fill) +{ + int x, y, r_x, r_y, start, end; + int x1, y1, x2, y2, x3, y3, x4, y4; + double cvt = 3.141592653/180.0; + + r_x = Int_val(vrx); + r_y = Int_val(vry); + if ((r_x < 0) || (r_y < 0)) + invalid_argument("draw_arc: radius must be positive"); + x = Int_val(vx); + y = Int_val(vy); + start = Int_val(vstart); + end = Int_val(vend); + + // Upper-left corner of bounding rect. + x1= x - r_x; + y1= y + r_y; + // Lower-right corner of bounding rect. + x2= x + r_x; + y2= y - r_y; + // Starting point + x3=x + (int)(100.0*cos(cvt*start)); + y3=y + (int)(100.0*sin(cvt*start)); + // Ending point + x4=x + (int)(100.0*cos(cvt*end)); + y4=y + (int)(100.0*sin(cvt*end)); + + if (grremember_mode) { + SelectObject(grwindow.gcBitmap,grwindow.CurrentPen); + SelectObject(grwindow.gcBitmap,grwindow.CurrentBrush); + if( fill ) + Pie(grwindow.gcBitmap,x1, Wcvt(y1), x2, Wcvt(y2), + x3, Wcvt(y3), x4, Wcvt(y4)); + else + Arc(grwindow.gcBitmap,x1, Wcvt(y1), x2, Wcvt(y2), + x3, Wcvt(y3), x4, Wcvt(y4)); + } + if( grdisplay_mode ) { + SelectObject(grwindow.gc,grwindow.CurrentPen); + SelectObject(grwindow.gc,grwindow.CurrentBrush); + if (fill) + Pie(grwindow.gc,x1, Wcvt(y1), x2, Wcvt(y2), + x3, Wcvt(y3), x4, Wcvt(y4)); + else + Arc(grwindow.gc,x1, Wcvt(y1), x2, Wcvt(y2), + x3, Wcvt(y3), x4, Wcvt(y4)); + } + return Val_unit; +} + +CAMLprim value caml_gr_show_bitmap(value filename,int x,int y) +{ + AfficheBitmap(filename,grwindow.gcBitmap,x,Wcvt(y)); + AfficheBitmap(filename,grwindow.gc,x,Wcvt(y)); + return Val_unit; +} + + + +CAMLprim value caml_gr_get_mousex(void) +{ + POINT pt; + GetCursorPos(&pt); + MapWindowPoints(HWND_DESKTOP,grwindow.hwnd,&pt,1); + return pt.x; +} + +CAMLprim value caml_gr_get_mousey(void) +{ + POINT pt; + GetCursorPos(&pt); + MapWindowPoints(HWND_DESKTOP,grwindow.hwnd,&pt,1); + return grwindow.height - pt.y - 1; +} + + +static void gr_font(char *fontname) +{ + HFONT hf = CreationFont(fontname); + + if (hf && hf != INVALID_HANDLE_VALUE) { + HFONT oldFont = SelectObject(grwindow.gc,hf); + SelectObject(grwindow.gcBitmap,hf); + DeleteObject(grwindow.CurrentFont); + grwindow.CurrentFont = hf; + } +} + +CAMLprim value caml_gr_set_font(value fontname) +{ + gr_check_open(); + gr_font(String_val(fontname)); + return Val_unit; +} + +CAMLprim value caml_gr_set_text_size (value sz) +{ + return Val_unit; +} + +CAMLprim value caml_gr_draw_char(value chr) +{ + char str[1]; + gr_check_open(); + str[0] = Int_val(chr); + caml_gr_draw_text((value)str, 1); + return Val_unit; +} + +CAMLprim value caml_gr_draw_string(value str) +{ + gr_check_open(); + caml_gr_draw_text(str, string_length(str)); + return Val_unit; +} + +CAMLprim value caml_gr_text_size(value str) +{ + SIZE extent; + value res; + + mlsize_t len = string_length(str); + if (len > 32767) len = 32767; + + GetTextExtentPoint(grwindow.gc,String_val(str), len,&extent); + + res = alloc_tuple(2); + Field(res, 0) = Val_long(extent.cx); + Field(res, 1) = Val_long(extent.cy); + + return res; +} + +CAMLprim value caml_gr_fill_poly(value vect) +{ + int n_points, i; + POINT *p,*poly; + n_points = Wosize_val(vect); + if (n_points < 3) + gr_fail("fill_poly: not enough points",0); + + poly = (POINT *)malloc(n_points*sizeof(POINT)); + + p = poly; + for( i = 0; i < n_points; i++ ){ + p->x = Int_val(Field(Field(vect,i),0)); + p->y = Wcvt(Int_val(Field(Field(vect,i),1))); + p++; + } + if (grremember_mode) { + SelectObject(grwindow.gcBitmap,grwindow.CurrentBrush); + Polygon(grwindow.gcBitmap,poly,n_points); + } + if (grdisplay_mode) { + SelectObject(grwindow.gcBitmap,grwindow.CurrentBrush); + Polygon(grwindow.gc,poly,n_points); + } + free(poly); + + return Val_unit; +} + +CAMLprim value caml_gr_fill_arc(value *argv, int argc) +{ + return gr_draw_or_fill_arc(argv[0], argv[1], argv[2], argv[3], + argv[4], argv[5], TRUE); +} + +CAMLprim value caml_gr_fill_arc_nat(vx, vy, vrx, vry, vstart, vend) +{ + return gr_draw_or_fill_arc(vx, vy, vrx, vry, vstart, vend, TRUE); +} + +// Image primitives +struct image { + int w; + int h; + HBITMAP data; + HBITMAP mask; +}; + +#define Width(i) (((struct image *)Data_custom_val(i))->w) +#define Height(i) (((struct image *)Data_custom_val(i))->h) +#define Data(i) (((struct image *)Data_custom_val(i))->data) +#define Mask(i) (((struct image *)Data_custom_val(i))->mask) +#define Max_image_mem 500000 + +static void finalize_image (value i) +{ + DeleteObject (Data(i)); + if (Mask(i) != NULL) DeleteObject(Mask(i)); +} + +static struct custom_operations image_ops = { + "_image", + finalize_image, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + +CAMLprim value caml_gr_create_image(value vw, value vh) +{ + HBITMAP cbm; + value res; + int w = Int_val(vw); + int h = Int_val(vh); + + if (w < 0 || h < 0) + gr_fail("create_image: width and height must be positive",0); + + cbm = CreateCompatibleBitmap(grwindow.gc, w, h); + if (cbm == NULL) + gr_fail("create_image: cannot create bitmap", 0); + res = alloc_custom(&image_ops, sizeof(struct image), + w * h, Max_image_mem); + if (res) { + Width (res) = w; + Height (res) = h; + Data (res) = cbm; + Mask (res) = NULL; + } + return res; +} + +CAMLprim value caml_gr_blit_image (value i, value x, value y) +{ + HBITMAP oldBmp = SelectObject(grwindow.tempDC,Data(i)); + int xsrc = Int_val(x); + int ysrc = Wcvt(Int_val(y) + Height(i) - 1); + BitBlt(grwindow.tempDC,0, 0, Width(i), Height(i), + grwindow.gcBitmap, xsrc, ysrc, SRCCOPY); + SelectObject(grwindow.tempDC,oldBmp); + return Val_unit; +} + + +CAMLprim value caml_gr_draw_image(value i, value x, value y) +{ + HBITMAP oldBmp; + + int xdst = Int_val(x); + int ydst = Wcvt(Int_val(y)+Height(i)-1); + if (Mask(i) == NULL) { + if (grremember_mode) { + oldBmp = SelectObject(grwindow.tempDC,Data(i)); + BitBlt(grwindow.gcBitmap,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCCOPY); + SelectObject(grwindow.tempDC,oldBmp); + } + if (grdisplay_mode) { + oldBmp = SelectObject(grwindow.tempDC,Data(i)); + BitBlt(grwindow.gc,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCCOPY); + SelectObject(grwindow.tempDC,oldBmp); + } + } + else { + if (grremember_mode) { + oldBmp = SelectObject(grwindow.tempDC,Mask(i)); + BitBlt(grwindow.gcBitmap,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCAND); + SelectObject(grwindow.tempDC,Data(i)); + BitBlt(grwindow.gcBitmap,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCPAINT); + SelectObject(grwindow.tempDC,oldBmp); + } + if (grdisplay_mode) { + oldBmp = SelectObject(grwindow.tempDC,Mask(i)); + BitBlt(grwindow.gc,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCAND); + SelectObject(grwindow.tempDC,Data(i)); + BitBlt(grwindow.gc,xdst, ydst, Width(i), Height(i), + grwindow.tempDC, 0, 0, SRCPAINT); + SelectObject(grwindow.tempDC,oldBmp); + } + } + + return Val_unit; +} + +CAMLprim value caml_gr_make_image(value matrix) +{ + int width, height,has_transp,i,j; + value img; + HBITMAP oldBmp; + height = Wosize_val(matrix); + if (height == 0) { + width = 0; + } + else { + width = Wosize_val(Field(matrix, 0)); + for (i = 1; i < height; i++) { + if (width != (int) Wosize_val(Field(matrix, i))) + gr_fail("make_image: non-rectangular matrix",0); + } + } + Begin_roots1(matrix) + img = caml_gr_create_image(Val_int(width), Val_int(height)); + End_roots(); + has_transp = 0; + oldBmp = SelectObject(grwindow.tempDC,Data(img)); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int col = Long_val (Field (Field (matrix, i), j)); + if (col == -1){ + has_transp = 1; + SetPixel(grwindow.tempDC,j, i, 0); + } + else { + int red = (col >> 16) & 0xFF; + int green = (col >> 8) & 0xFF; + int blue = col & 0xFF; + SetPixel(grwindow.tempDC,j, i, RGB(red, green, blue)); + } + } + } + SelectObject(grwindow.tempDC,oldBmp); + if (has_transp) { + HBITMAP cbm; + cbm = CreateCompatibleBitmap(grwindow.gc, width, height); + Mask(img) = cbm; + oldBmp = SelectObject(grwindow.tempDC,Mask(img)); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int col = Long_val (Field (Field (matrix, i), j)); + SetPixel(grwindow.tempDC,j, i, col == -1 ? 0xFFFFFF : 0); + } + } + SelectObject(grwindow.tempDC,oldBmp); + } + return img; +} + +static value alloc_int_vect(mlsize_t size) +{ + value res; + mlsize_t i; + + if (size == 0) return Atom(0); + if (size <= Max_young_wosize) { + res = alloc(size, 0); + } + else { + res = alloc_shr(size, 0); + } + for (i = 0; i < size; i++) { + Field(res, i) = Val_long(0); + } + return res; +} + +CAMLprim value caml_gr_dump_image (value img) +{ + int height = Height(img); + int width = Width(img); + value matrix = Val_unit; + int i, j; + HBITMAP oldBmp; + + Begin_roots2(img, matrix) + matrix = alloc_int_vect (height); + for (i = 0; i < height; i++) { + modify (&Field (matrix, i), alloc_int_vect (width)); + } + End_roots(); + + oldBmp = SelectObject(grwindow.tempDC,Data(img)); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int col = GetPixel(grwindow.tempDC,j, i); + int blue = (col >> 16) & 0xFF; + int green = (col >> 8) & 0xFF; + int red = col & 0xFF; + Field(Field(matrix, i), j) = Val_long((red << 16) + + (green << 8) + blue); + } + } + SelectObject(grwindow.tempDC,oldBmp); + if (Mask(img) != NULL) { + oldBmp = SelectObject(grwindow.tempDC,Mask(img)); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + if (GetPixel(grwindow.tempDC,j, i) != 0) + Field(Field(matrix, i), j) = + Val_long(-1); + } + } + SelectObject(grwindow.tempDC,oldBmp); + } + return matrix; +} diff --git a/otherlibs/win32graph/events.c b/otherlibs/win32graph/events.c new file mode 100755 index 0000000..60b9c5f --- /dev/null +++ b/otherlibs/win32graph/events.c @@ -0,0 +1,200 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2004 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: events.c,v 1.2 2004-07-13 12:25:15 xleroy Exp $ */ + +#include "mlvalues.h" +#include "alloc.h" +#include "libgraph.h" +#include <windows.h> + +enum { + EVENT_BUTTON_DOWN = 1, + EVENT_BUTTON_UP = 2, + EVENT_KEY_PRESSED = 4, + EVENT_MOUSE_MOTION = 8 +}; + +struct event_data { + short mouse_x, mouse_y; + unsigned char kind; + unsigned char button; + unsigned char key; +}; + +static struct event_data caml_gr_queue[SIZE_QUEUE]; +static unsigned int caml_gr_head = 0; /* position of next read */ +static unsigned int caml_gr_tail = 0; /* position of next write */ + +static int caml_gr_event_mask = EVENT_KEY_PRESSED; +static int last_button = 0; +static LPARAM last_pos = 0; + +HANDLE caml_gr_queue_semaphore = NULL; +CRITICAL_SECTION caml_gr_queue_mutex; + +void caml_gr_init_event_queue(void) +{ + if (caml_gr_queue_semaphore == NULL) { + caml_gr_queue_semaphore = CreateSemaphore(NULL, 0, SIZE_QUEUE, NULL); + InitializeCriticalSection(&caml_gr_queue_mutex); + } +} + +#define QueueIsEmpty (caml_gr_tail == caml_gr_head) + +static void caml_gr_enqueue_event(int kind, LPARAM mouse_xy, + int button, int key) +{ + struct event_data * ev; + + if ((caml_gr_event_mask & kind) == 0) return; + EnterCriticalSection(&caml_gr_queue_mutex); + ev = &(caml_gr_queue[caml_gr_tail]); + ev->kind = kind; + ev->mouse_x = GET_X_LPARAM(mouse_xy); + ev->mouse_y = GET_Y_LPARAM(mouse_xy); + ev->button = (button != 0); + ev->key = key; + caml_gr_tail = (caml_gr_tail + 1) % SIZE_QUEUE; + /* If queue was full, it now appears empty; + drop oldest entry from queue. */ + if (QueueIsEmpty) { + caml_gr_head = (caml_gr_head + 1) % SIZE_QUEUE; + } else { + /* One more event in queue */ + ReleaseSemaphore(caml_gr_queue_semaphore, 1, NULL); + } + LeaveCriticalSection(&caml_gr_queue_mutex); +} + +void caml_gr_handle_event(UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + last_button = 1; + last_pos = lParam; + caml_gr_enqueue_event(EVENT_BUTTON_DOWN, lParam, 1, 0); + break; + + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + last_button = 0; + last_pos = lParam; + caml_gr_enqueue_event(EVENT_BUTTON_UP, lParam, 0, 0); + break; + + case WM_CHAR: + caml_gr_enqueue_event(EVENT_KEY_PRESSED, last_pos, last_button, wParam); + break; + + case WM_MOUSEMOVE: + last_pos = lParam; + caml_gr_enqueue_event(EVENT_MOUSE_MOTION, lParam, last_button, 0); + break; + } +} + +static value caml_gr_wait_allocate_result(int mouse_x, int mouse_y, + int button, + int keypressed, int key) +{ + value res = alloc_small(5, 0); + Field(res, 0) = Val_int(mouse_x); + Field(res, 1) = Val_int(grwindow.height - 1 - mouse_y); + Field(res, 2) = Val_bool(button); + Field(res, 3) = Val_bool(keypressed); + Field(res, 4) = Val_int(key & 0xFF); + return res; +} + +static value caml_gr_wait_event_poll(void) +{ + int key, keypressed, i; + + /* Look inside event queue for pending KeyPress events */ + EnterCriticalSection(&caml_gr_queue_mutex); + key = 0; + keypressed = 0; + for (i = caml_gr_head; i != caml_gr_tail; i = (i + 1) % SIZE_QUEUE) { + if (caml_gr_queue[i].kind == EVENT_KEY_PRESSED) { + keypressed = 1; + key = caml_gr_queue[i].key; + break; + } + } + LeaveCriticalSection(&caml_gr_queue_mutex); + /* Use global vars for mouse position and buttons */ + return caml_gr_wait_allocate_result(GET_X_LPARAM(last_pos), + GET_Y_LPARAM(last_pos), + last_button, + keypressed, key); +} + +static value caml_gr_wait_event_blocking(int mask) +{ + struct event_data ev; + + /* Increase the selected events if needed */ + caml_gr_event_mask |= mask; + /* Pop events from queue until one matches */ + do { + /* Wait for event queue to be non-empty */ + WaitForSingleObject(caml_gr_queue_semaphore, INFINITE); + /* Pop oldest event in queue */ + EnterCriticalSection(&caml_gr_queue_mutex); + ev = caml_gr_queue[caml_gr_head]; + /* Queue should never be empty at this point, but just in case... */ + if (QueueIsEmpty) { + ev.kind = 0; + } else { + caml_gr_head = (caml_gr_head + 1) % SIZE_QUEUE; + } + LeaveCriticalSection(&caml_gr_queue_mutex); + /* Check if it matches */ + } while ((ev.kind & mask) == 0); + return caml_gr_wait_allocate_result(ev.mouse_x, ev.mouse_y, ev.button, + ev.kind == EVENT_KEY_PRESSED, + ev.key); +} + +CAMLprim value caml_gr_wait_event(value eventlist) /* ML */ +{ + int mask, poll; + + gr_check_open(); + mask = 0; + poll = 0; + while (eventlist != Val_int(0)) { + switch (Int_val(Field(eventlist, 0))) { + case 0: /* Button_down */ + mask |= EVENT_BUTTON_DOWN; break; + case 1: /* Button_up */ + mask |= EVENT_BUTTON_UP; break; + case 2: /* Key_pressed */ + mask |= EVENT_KEY_PRESSED; break; + case 3: /* Mouse_motion */ + mask |= EVENT_MOUSE_MOTION; break; + case 4: /* Poll */ + poll = 1; break; + } + eventlist = Field(eventlist, 1); + } + if (poll) + return caml_gr_wait_event_poll(); + else + return caml_gr_wait_event_blocking(mask); +} diff --git a/otherlibs/win32graph/libgraph.h b/otherlibs/win32graph/libgraph.h new file mode 100644 index 0000000..82c910c --- /dev/null +++ b/otherlibs/win32graph/libgraph.h @@ -0,0 +1,78 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jacob Navia, after Xavier Leroy */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: libgraph.h,v 1.9 2004-07-13 12:25:15 xleroy Exp $ */ + +#include <stdio.h> +#include <windows.h> +#include <windowsx.h> + +struct canvas { + int w, h; /* Dimensions of the drawable */ + HWND win; /* The drawable itself */ + HDC gc; /* The associated graphics context */ +}; + +extern HWND grdisplay; /* The display connection */ +extern COLORREF grbackground; +extern BOOL grdisplay_mode; /* Display-mode flag */ +extern BOOL grremember_mode; /* Remember-mode flag */ +extern int grx, gry; /* Coordinates of the current point */ +extern int grcolor; /* Current *CAML* drawing color (can be -1) */ +extern HFONT * grfont; /* Current font */ + +extern BOOL direct_rgb; +extern int byte_order; +extern int bitmap_unit; +extern int bits_per_pixel; + +#define Wcvt(y) (grwindow.height - 1 - (y)) +#define Bcvt(y) (grwindow.height - 1 - (y)) +#define WtoB(y) ((y) + WindowRect.bottom - grwindow.h) + +#define DEFAULT_SCREEN_WIDTH 1024 +#define DEFAULT_SCREEN_HEIGHT 768 +#define BORDER_WIDTH 2 +#define WINDOW_NAME "Caml graphics" +#define ICON_NAME "Caml graphics" +#define SIZE_QUEUE 256 + +void gr_fail(char *fmt, char *arg); +void gr_check_open(void); +CAMLprim value caml_gr_set_color(value vcolor); + +// Windows specific definitions +extern RECT WindowRect; +extern int grCurrentColor; + +typedef struct tagWindow { + HDC gc; + HDC gcBitmap; + HWND hwnd; + HBRUSH CurrentBrush; + HPEN CurrentPen; + DWORD CurrentColor; + int width; + int height; + int grx; + int gry; + HBITMAP hBitmap; + HFONT CurrentFont; + int CurrentFontSize; + HDC tempDC; // For image operations; +} GR_WINDOW; + +extern GR_WINDOW grwindow; +HFONT CreationFont(char *name); +extern void caml_gr_init_event_queue(void); +extern void caml_gr_handle_event(UINT msg, WPARAM wParam, LPARAM lParam); diff --git a/otherlibs/win32graph/libgraphics.clib b/otherlibs/win32graph/libgraphics.clib new file mode 100644 index 0000000..5084c97 --- /dev/null +++ b/otherlibs/win32graph/libgraphics.clib @@ -0,0 +1 @@ +open.o draw.o events.o dib.o diff --git a/otherlibs/win32graph/open.c b/otherlibs/win32graph/open.c new file mode 100644 index 0000000..9c6e5c5 --- /dev/null +++ b/otherlibs/win32graph/open.c @@ -0,0 +1,364 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia, based on code by J-M Geffroy and X Leroy */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: open.c,v 1.12 2007-11-06 15:16:56 frisch Exp $ */ + +#include <fcntl.h> +#include <signal.h> +#include "mlvalues.h" +#include "fail.h" +#include "libgraph.h" +#include "callback.h" +#include <windows.h> + +static value gr_reset(void); +static long tid; +static HANDLE threadHandle; +HWND grdisplay = NULL; +int grscreen; +COLORREF grwhite, grblack; +COLORREF grbackground; +int grCurrentColor; +struct canvas grbstore; +BOOL grdisplay_mode; +BOOL grremember_mode; +int grx, gry; +int grcolor; +extern HFONT * grfont; +MSG msg; + +static char *szOcamlWindowClass = "OcamlWindowClass"; +static BOOL gr_initialized = 0; +CAMLprim value caml_gr_clear_graph(void); +HANDLE hInst; + +HFONT CreationFont(char *name) +{ + LOGFONT CurrentFont; + memset(&CurrentFont, 0, sizeof(LOGFONT)); + CurrentFont.lfCharSet = ANSI_CHARSET; + CurrentFont.lfWeight = FW_NORMAL; + CurrentFont.lfHeight = grwindow.CurrentFontSize; + CurrentFont.lfPitchAndFamily = (BYTE) (FIXED_PITCH | FF_MODERN); + strcpy(CurrentFont.lfFaceName, name); /* Courier */ + return (CreateFontIndirect(&CurrentFont)); +} + +void SetCoordinates(HWND hwnd) +{ + RECT rc; + + GetClientRect(hwnd,&rc); + grwindow.width = rc.right; + grwindow.height = rc.bottom; + gr_reset(); +} + +void ResetForClose(HWND hwnd) +{ + DeleteDC(grwindow.tempDC); + DeleteDC(grwindow.gcBitmap); + DeleteObject(grwindow.hBitmap); + memset(&grwindow,0,sizeof(grwindow)); + gr_initialized = 0; +} + + + +static LRESULT CALLBACK GraphicsWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + PAINTSTRUCT ps; + HDC hdc; + + switch (msg) { + // Create the MDI client invisible window + case WM_CREATE: + break; + case WM_PAINT: + hdc = BeginPaint(hwnd,&ps); + BitBlt(hdc,0,0,grwindow.width,grwindow.height, + grwindow.gcBitmap,0,0,SRCCOPY); + EndPaint(hwnd,&ps); + break; + // Move the child windows + case WM_SIZE: + // Position the MDI client window between the tool and status bars + if (wParam != SIZE_MINIMIZED) { + SetCoordinates(hwnd); + } + + return 0; + // End application + case WM_DESTROY: + ResetForClose(hwnd); + break; + } + caml_gr_handle_event(msg, wParam, lParam); + return DefWindowProc(hwnd, msg, wParam, lParam); +} + +int DoRegisterClass(void) +{ + WNDCLASS wc; + + memset(&wc,0,sizeof(WNDCLASS)); + wc.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS|CS_OWNDC ; + wc.lpfnWndProc = (WNDPROC)GraphicsWndProc; + wc.hInstance = hInst; + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wc.lpszClassName = szOcamlWindowClass; + wc.lpszMenuName = 0; + wc.hCursor = LoadCursor(NULL,IDC_ARROW); + wc.hIcon = 0; + return RegisterClass(&wc); +} + +static value gr_reset(void) +{ + RECT rc; + int screenx,screeny; + + screenx = GetSystemMetrics(SM_CXSCREEN); + screeny = GetSystemMetrics(SM_CYSCREEN); + GetClientRect(grwindow.hwnd,&rc); + grwindow.gc = GetDC(grwindow.hwnd); + grwindow.width = rc.right; + grwindow.height = rc.bottom; + if (grwindow.gcBitmap == (HDC)0) { + grwindow.hBitmap = CreateCompatibleBitmap(grwindow.gc,screenx,screeny); + grwindow.gcBitmap = CreateCompatibleDC(grwindow.gc); + grwindow.tempDC = CreateCompatibleDC(grwindow.gc); + SelectObject(grwindow.gcBitmap,grwindow.hBitmap); + SetMapMode(grwindow.gcBitmap,MM_TEXT); + MoveToEx(grwindow.gcBitmap,0,grwindow.height-1,0); + BitBlt(grwindow.gcBitmap,0,0,screenx,screeny, + grwindow.gcBitmap,0,0,WHITENESS); + grwindow.CurrentFontSize = 15; + grwindow.CurrentFont = CreationFont("Courier"); + } + grwindow.CurrentColor = GetSysColor(COLOR_WINDOWTEXT); + grwindow.grx = 0; + grwindow.gry = 0; + grwindow.CurrentPen = SelectObject(grwindow.gc,GetStockObject(WHITE_PEN)); + SelectObject(grwindow.gc,grwindow.CurrentPen); + SelectObject(grwindow.gcBitmap,grwindow.CurrentPen); + grwindow.CurrentBrush = SelectObject(grwindow.gc,GetStockObject(WHITE_BRUSH)); + SelectObject(grwindow.gc,grwindow.CurrentBrush); + SelectObject(grwindow.gcBitmap,grwindow.CurrentBrush); + caml_gr_set_color(Val_long(0)); + SelectObject(grwindow.gc,grwindow.CurrentFont); + SelectObject(grwindow.gcBitmap,grwindow.CurrentFont); + grdisplay_mode = grremember_mode = 1; + MoveToEx(grwindow.gc,0,grwindow.height-1,0); + MoveToEx(grwindow.gcBitmap,0,grwindow.height-1,0); + SetTextAlign(grwindow.gcBitmap,TA_BOTTOM); + SetTextAlign(grwindow.gc,TA_BOTTOM); + return Val_unit; +} + +void SuspendGraphicThread(void) +{ + SuspendThread(threadHandle); +} + +void ResumeGraphicThread(void) +{ + ResumeThread(threadHandle); +} + +/* For handshake between the event handling thread and the main thread */ +static char * open_graph_errmsg; +static HANDLE open_graph_event; + +static DWORD WINAPI gr_open_graph_internal(value arg) +{ + RECT rc; + int ret; + int event; + int x, y, w, h; + int screenx,screeny; + int attributes; + static int registered; + MSG msg; + + gr_initialized = TRUE; + hInst = GetModuleHandle(NULL); + x = y = w = h = CW_USEDEFAULT; + sscanf(String_val(arg), "%dx%d+%d+%d", &w, &h, &x, &y); + + /* Open the display */ + if (grwindow.hwnd == NULL || !IsWindow(grwindow.hwnd)) { + if (!registered) { + registered = DoRegisterClass(); + if (!registered) { + open_graph_errmsg = "Cannot register the window class"; + SetEvent(open_graph_event); + return 1; + } + } + grwindow.hwnd = CreateWindow(szOcamlWindowClass, + WINDOW_NAME, + WS_OVERLAPPEDWINDOW, + x,y, + w,h, + NULL,0,hInst,NULL); + if (grwindow.hwnd == NULL) { + open_graph_errmsg = "Cannot create window"; + SetEvent(open_graph_event); + return 1; + } +#if 0 + if (x != CW_USEDEFAULT) { + rc.left = 0; + rc.top = 0; + rc.right = w; + rc.bottom = h; + AdjustWindowRect(&rc,GetWindowLong(grwindow.hwnd,GWL_STYLE),0); + MoveWindow(grwindow.hwnd,x,y,rc.right-rc.left,rc.bottom-rc.top,1); + } +#endif + } + gr_reset(); + ShowWindow(grwindow.hwnd,SW_SHOWNORMAL); + + /* Position the current point at origin */ + grwindow.grx = 0; + grwindow.gry = 0; + + caml_gr_init_event_queue(); + + /* The global data structures are now correctly initialized. + Restart the Caml main thread. */ + open_graph_errmsg = NULL; + SetEvent(open_graph_event); + + /* Enter the message handling loop */ + while (GetMessage(&msg,NULL,0,0)) { + TranslateMessage(&msg); // Translates virtual key codes + DispatchMessage(&msg); // Dispatches message to window + if (!IsWindow(grwindow.hwnd)) + break; + } + return 0; +} + +CAMLprim value caml_gr_open_graph(value arg) +{ + long tid; + if (gr_initialized) return Val_unit; + open_graph_event = CreateEvent(NULL, FALSE, FALSE, NULL); + threadHandle = + CreateThread(NULL,0, + (LPTHREAD_START_ROUTINE)gr_open_graph_internal,(void **)arg, + 0, + &tid); + WaitForSingleObject(open_graph_event, INFINITE); + CloseHandle(open_graph_event); + if (open_graph_errmsg != NULL) gr_fail("%s", open_graph_errmsg); + return Val_unit; +} + +CAMLprim value caml_gr_close_graph(void) +{ + if (gr_initialized) { + PostMessage(grwindow.hwnd, WM_CLOSE, 0, 0); + WaitForSingleObject(threadHandle, INFINITE); + } + return Val_unit; +} + +CAMLprim value caml_gr_clear_graph(void) +{ + gr_check_open(); + if(grremember_mode) { + BitBlt(grwindow.gcBitmap,0,0,grwindow.width,grwindow.height, + grwindow.gcBitmap,0,0,WHITENESS); + } + if(grdisplay_mode) { + BitBlt(grwindow.gc,0,0,grwindow.width,grwindow.height, + grwindow.gc,0,0,WHITENESS); + } + return Val_unit; +} + +CAMLprim value caml_gr_size_x(void) +{ + gr_check_open(); + return Val_int(grwindow.width); +} + +CAMLprim value caml_gr_size_y(void) +{ + gr_check_open(); + return Val_int(grwindow.height); +} + +CAMLprim value caml_gr_resize_window (value vx, value vy) +{ + gr_check_open (); + + /* FIXME TODO implement this function... */ + + return Val_unit; +} + +CAMLprim value caml_gr_synchronize(void) +{ + gr_check_open(); + BitBlt(grwindow.gc,0,0,grwindow.width,grwindow.height, + grwindow.gcBitmap,0,0,SRCCOPY); + return Val_unit ; +} + +CAMLprim value caml_gr_display_mode(value flag) +{ + grdisplay_mode = (Int_val(flag)) ? 1 : 0; + return Val_unit ; +} + +CAMLprim value caml_gr_remember_mode(value flag) +{ + grremember_mode = (Int_val(flag)) ? 1 : 0; + return Val_unit ; +} + +CAMLprim value caml_gr_sigio_signal(value unit) +{ + return Val_unit; +} + +CAMLprim value caml_gr_sigio_handler(void) +{ + return Val_unit; +} + + +/* Processing of graphic errors */ + +static value * graphic_failure_exn = NULL; +void gr_fail(char *fmt, char *arg) +{ + char buffer[1024]; + + if (graphic_failure_exn == NULL) { + graphic_failure_exn = caml_named_value("Graphics.Graphic_failure"); + if (graphic_failure_exn == NULL) + invalid_argument("Exception Graphics.Graphic_failure not initialized, must link graphics.cma"); + } + sprintf(buffer, fmt, arg); + raise_with_string(*graphic_failure_exn, buffer); +} + +void gr_check_open(void) +{ + if (!gr_initialized) gr_fail("graphic screen not opened", NULL); +} diff --git a/otherlibs/win32unix/.cvsignore b/otherlibs/win32unix/.cvsignore new file mode 100644 index 0000000..9aaa716 --- /dev/null +++ b/otherlibs/win32unix/.cvsignore @@ -0,0 +1,3 @@ +unixLabels.ml* +unix.mli +unix.lib \ No newline at end of file diff --git a/otherlibs/win32unix/.depend b/otherlibs/win32unix/.depend new file mode 100644 index 0000000..6e1130b --- /dev/null +++ b/otherlibs/win32unix/.depend @@ -0,0 +1,5 @@ +unix.cmo: unix.cmi +unix.cmx: unix.cmi +unixLabels.cmo: unix.cmi unixLabels.cmi +unixLabels.cmx: unix.cmx unixLabels.cmi +unixLabels.cmi: unix.cmi diff --git a/otherlibs/win32unix/Makefile.nt b/otherlibs/win32unix/Makefile.nt new file mode 100644 index 0000000..6f0de5d --- /dev/null +++ b/otherlibs/win32unix/Makefile.nt @@ -0,0 +1,61 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.37 2008-07-29 08:31:41 xleroy Exp $ + +# Files in this directory +WIN_FILES = accept.c bind.c channels.c close.c \ + close_on.c connect.c createprocess.c dup.c dup2.c errmsg.c \ + getpeername.c getpid.c getsockname.c gettimeofday.c \ + link.c listen.c lockf.c lseek.c nonblock.c \ + mkdir.c open.c pipe.c read.c rename.c \ + select.c sendrecv.c \ + shutdown.c sleep.c socket.c sockopt.c startup.c stat.c \ + system.c unixsupport.c windir.c winwait.c write.c \ + winlist.c winworker.c windbug.c + +# Files from the ../unix directory +UNIX_FILES = access.c addrofstr.c chdir.c chmod.c cst2constr.c \ + cstringv.c envir.c execv.c execve.c execvp.c \ + exit.c getcwd.c gethost.c gethostname.c getproto.c \ + getserv.c gmtime.c putenv.c rmdir.c \ + socketaddr.c strofaddr.c time.c unlink.c utimes.c + +UNIX_CAML_FILES = unix.mli unixLabels.mli unixLabels.ml + +ALL_FILES=$(WIN_FILES) $(UNIX_FILES) +WSOCKLIB=$(call SYSLIB,ws2_32) + +LIBNAME=unix +COBJS=$(ALL_FILES:.c=.$(O)) +CAMLOBJS=unix.cmo unixLabels.cmo +LINKOPTS=-cclib $(WSOCKLIB) +LDOPTS=-ldopt $(WSOCKLIB) +EXTRACAMLFLAGS=-nolabels +EXTRACFLAGS=-I../unix +HEADERS=unixsupport.h + + +include ../Makefile.nt + +clean:: + rm -f $(UNIX_FILES) $(UNIX_CAML_FILES) + +$(UNIX_FILES) $(UNIX_CAML_FILES): %: ../unix/% + cp ../unix/$* $* + +depend: + +$(COBJS): unixsupport.h + +include .depend diff --git a/otherlibs/win32unix/accept.c b/otherlibs/win32unix/accept.c new file mode 100644 index 0000000..e0762df --- /dev/null +++ b/otherlibs/win32unix/accept.c @@ -0,0 +1,66 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: accept.c,v 1.21 2006-10-18 08:26:54 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" +#include "socketaddr.h" + +CAMLprim value unix_accept(sock) + value sock; +{ + SOCKET sconn = Socket_val(sock); + SOCKET snew; + value fd = Val_unit, adr = Val_unit, res; + int oldvalue, oldvaluelen, newvalue, retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + DWORD err = 0; + + oldvaluelen = sizeof(oldvalue); + retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, &oldvaluelen); + if (retcode == 0) { + /* Set sockets to synchronous mode */ + newvalue = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &newvalue, sizeof(newvalue)); + } + addr_len = sizeof(sock_addr); + enter_blocking_section(); + snew = accept(sconn, &addr.s_gen, &addr_len); + if (snew == INVALID_SOCKET) err = WSAGetLastError (); + leave_blocking_section(); + if (retcode == 0) { + /* Restore initial mode */ + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, oldvaluelen); + } + if (snew == INVALID_SOCKET) { + win32_maperr(err); + uerror("accept", Nothing); + } + Begin_roots2 (fd, adr) + fd = win_alloc_socket(snew); + adr = alloc_sockaddr(&addr, addr_len, snew); + res = alloc_small(2, 0); + Field(res, 0) = fd; + Field(res, 1) = adr; + End_roots(); + return res; +} + diff --git a/otherlibs/win32unix/bind.c b/otherlibs/win32unix/bind.c new file mode 100644 index 0000000..764cbd9 --- /dev/null +++ b/otherlibs/win32unix/bind.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: bind.c,v 1.10 2002-04-30 15:00:45 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" +#include "socketaddr.h" + +CAMLprim value unix_bind(socket, address) + value socket, address; +{ + int ret; + union sock_addr_union addr; + socklen_param_type addr_len; + + get_sockaddr(address, &addr, &addr_len); + ret = bind(Socket_val(socket), &addr.s_gen, addr_len); + if (ret == -1) { + win32_maperr(WSAGetLastError()); + uerror("bind", Nothing); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/channels.c b/otherlibs/win32unix/channels.c new file mode 100644 index 0000000..3cf7d3c --- /dev/null +++ b/otherlibs/win32unix/channels.c @@ -0,0 +1,88 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: channels.c,v 1.12 2006-09-21 09:41:04 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <io.h> +#include <memory.h> +#include "unixsupport.h" +#include <fcntl.h> + +extern long _get_osfhandle(int); +extern int _open_osfhandle(long, int); + +int win_CRT_fd_of_filedescr(value handle) +{ + if (CRT_fd_val(handle) != NO_CRT_FD) { + return CRT_fd_val(handle); + } else { + int fd = _open_osfhandle((long) Handle_val(handle), O_BINARY); + if (fd == -1) uerror("channel_of_descr", Nothing); + return fd; + } +} + +CAMLprim value win_inchannel_of_filedescr(value handle) +{ + CAMLparam1(handle); + CAMLlocal1(vchan); + struct channel * chan; + + chan = caml_open_descriptor_in(win_CRT_fd_of_filedescr(handle)); + if (Descr_kind_val(handle) == KIND_SOCKET) + chan->flags |= CHANNEL_FLAG_FROM_SOCKET; + vchan = caml_alloc_channel(chan); + CAMLreturn(vchan); +} + +CAMLprim value win_outchannel_of_filedescr(value handle) +{ + CAMLparam1(handle); + CAMLlocal1(vchan); + int fd; + struct channel * chan; + + chan = caml_open_descriptor_out(win_CRT_fd_of_filedescr(handle)); + if (Descr_kind_val(handle) == KIND_SOCKET) + chan->flags |= CHANNEL_FLAG_FROM_SOCKET; + vchan = caml_alloc_channel(chan); + CAMLreturn(vchan); +} + +CAMLprim value win_filedescr_of_channel(value vchan) +{ + CAMLparam1(vchan); + CAMLlocal1(fd); + struct channel * chan; + HANDLE h; + + chan = Channel(vchan); + if (chan->fd == -1) uerror("descr_of_channel", Nothing); + h = (HANDLE) _get_osfhandle(chan->fd); + if (chan->flags & CHANNEL_FLAG_FROM_SOCKET) + fd = win_alloc_socket((SOCKET) h); + else + fd = win_alloc_handle(h); + CRT_fd_val(fd) = chan->fd; + CAMLreturn(fd); +} + +CAMLprim value win_handle_fd(value vfd) +{ + int crt_fd = Int_val(vfd); + value res = win_alloc_handle_or_socket((HANDLE) _get_osfhandle(crt_fd)); + CRT_fd_val(res) = crt_fd; + return res; +} diff --git a/otherlibs/win32unix/close.c b/otherlibs/win32unix/close.c new file mode 100644 index 0000000..7c01d90 --- /dev/null +++ b/otherlibs/win32unix/close.c @@ -0,0 +1,33 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: close.c,v 1.5 2002-04-30 15:00:46 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_close(value fd) +{ + if (Descr_kind_val(fd) == KIND_SOCKET) { + if (closesocket(Socket_val(fd)) != 0) { + win32_maperr(WSAGetLastError()); + uerror("close", Nothing); + } + } else { + if (! CloseHandle(Handle_val(fd))) { + win32_maperr(GetLastError()); + uerror("close", Nothing); + } + } + return Val_unit; +} diff --git a/otherlibs/win32unix/close_on.c b/otherlibs/win32unix/close_on.c new file mode 100644 index 0000000..086f3a2 --- /dev/null +++ b/otherlibs/win32unix/close_on.c @@ -0,0 +1,46 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: close_on.c,v 1.8 2001-12-07 13:40:43 xleroy Exp $ */ + +#include <mlvalues.h> +#include <windows.h> +#include "unixsupport.h" + +int win_set_inherit(value fd, BOOL inherit) +{ + HANDLE oldh, newh; + + oldh = Handle_val(fd); + if (! DuplicateHandle(GetCurrentProcess(), oldh, + GetCurrentProcess(), &newh, + 0L, inherit, DUPLICATE_SAME_ACCESS)) { + win32_maperr(GetLastError()); + return -1; + } + Handle_val(fd) = newh; + CloseHandle(oldh); + return 0; +} + +CAMLprim value win_set_close_on_exec(value fd) +{ + if (win_set_inherit(fd, FALSE) == -1) uerror("set_close_on_exec", Nothing); + return Val_unit; +} + +CAMLprim value win_clear_close_on_exec(value fd) +{ + if (win_set_inherit(fd, TRUE) == -1) uerror("clear_close_on_exec", Nothing); + return Val_unit; +} diff --git a/otherlibs/win32unix/connect.c b/otherlibs/win32unix/connect.c new file mode 100644 index 0000000..3b48649 --- /dev/null +++ b/otherlibs/win32unix/connect.c @@ -0,0 +1,39 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: connect.c,v 1.13 2006-10-18 08:26:54 xleroy Exp $ */ + +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" +#include "socketaddr.h" + +CAMLprim value unix_connect(socket, address) + value socket, address; +{ + SOCKET s = Socket_val(socket); + union sock_addr_union addr; + socklen_param_type addr_len; + DWORD err = 0; + + get_sockaddr(address, &addr, &addr_len); + enter_blocking_section(); + if (connect(s, &addr.s_gen, addr_len) == -1) + err = WSAGetLastError(); + leave_blocking_section(); + if (err) { + win32_maperr(err); + uerror("connect", Nothing); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/createprocess.c b/otherlibs/win32unix/createprocess.c new file mode 100644 index 0000000..8d048f9 --- /dev/null +++ b/otherlibs/win32unix/createprocess.c @@ -0,0 +1,87 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: createprocess.c,v 1.14 2008-01-11 16:13:16 doligez Exp $ */ + +#include <windows.h> +#include <mlvalues.h> +#include <osdeps.h> +#include "unixsupport.h" + +static int win_has_console(void); + +value win_create_process_native(value cmd, value cmdline, value env, + value fd1, value fd2, value fd3) +{ + PROCESS_INFORMATION pi; + STARTUPINFO si; + char * exefile, * envp; + int flags; + + exefile = search_exe_in_path(String_val(cmd)); + if (env != Val_int(0)) { + envp = String_val(Field(env, 0)); + } else { + envp = NULL; + } + /* Prepare stdin/stdout/stderr redirection */ + GetStartupInfo(&si); + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdInput = Handle_val(fd1); + si.hStdOutput = Handle_val(fd2); + si.hStdError = Handle_val(fd3); + /* If we do not have a console window, then we must create one + before running the process (keep it hidden for apparence). + Also one must suppress spurious flags in si.dwFlags. + Otherwise the redirections are ignored. + If we are starting a GUI application, the newly created + console should not matter. */ + if (win_has_console()) + flags = 0; + else { + flags = CREATE_NEW_CONSOLE; + si.dwFlags = (STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES); + si.wShowWindow = SW_HIDE; + } + /* Create the process */ + if (! CreateProcess(exefile, String_val(cmdline), NULL, NULL, + TRUE, flags, envp, NULL, &si, &pi)) { + win32_maperr(GetLastError()); + uerror("create_process", cmd); + } + CloseHandle(pi.hThread); + /* Return the process handle as pseudo-PID + (this is consistent with the wait() emulation in the MSVC C library */ + return Val_long(pi.hProcess); +} + +CAMLprim value win_create_process(value * argv, int argn) +{ + return win_create_process_native(argv[0], argv[1], argv[2], + argv[3], argv[4], argv[5]); +} + +static int win_has_console(void) +{ + HANDLE h, log; + int i; + + h = CreateFile("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + return 0; + } else { + CloseHandle(h); + return 1; + } +} diff --git a/otherlibs/win32unix/dllunix.dlib b/otherlibs/win32unix/dllunix.dlib new file mode 100644 index 0000000..e3ebf34 --- /dev/null +++ b/otherlibs/win32unix/dllunix.dlib @@ -0,0 +1,17 @@ +# Files in this directory +accept.d.o bind.d.o channels.d.o close.d.o +close_on.d.o connect.d.o createprocess.d.o dup.d.o dup2.d.o errmsg.d.o +getpeername.d.o getpid.d.o getsockname.d.o gettimeofday.d.o +link.d.o listen.d.o lockf.d.o lseek.d.o nonblock.d.o +mkdir.d.o open.d.o pipe.d.o read.d.o rename.d.o +select.d.o sendrecv.d.o +shutdown.d.o sleep.d.o socket.d.o sockopt.d.o startup.d.o stat.d.o +system.d.o unixsupport.d.o windir.d.o winwait.d.o write.d.o +winlist.d.o winworker.d.o windbug.d.o + +# Files from the ../unix directory +access.d.o addrofstr.d.o chdir.d.o chmod.d.o cst2constr.d.o +cstringv.d.o envir.d.o execv.d.o execve.d.o execvp.d.o +exit.d.o getcwd.d.o gethost.d.o gethostname.d.o getproto.d.o +getserv.d.o gmtime.d.o putenv.d.o rmdir.d.o +socketaddr.d.o strofaddr.d.o time.d.o unlink.d.o utimes.d.o diff --git a/otherlibs/win32unix/dup.c b/otherlibs/win32unix/dup.c new file mode 100644 index 0000000..c74c247 --- /dev/null +++ b/otherlibs/win32unix/dup.c @@ -0,0 +1,34 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dup.c,v 1.6 2002-04-30 15:00:46 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_dup(value fd) +{ + HANDLE newh; + value newfd; + int kind = Descr_kind_val(fd); + if (! DuplicateHandle(GetCurrentProcess(), Handle_val(fd), + GetCurrentProcess(), &newh, + 0L, TRUE, DUPLICATE_SAME_ACCESS)) { + win32_maperr(GetLastError()); + return -1; + } + newfd = win_alloc_handle(newh); + Descr_kind_val(newfd) = kind; + return newfd; +} + diff --git a/otherlibs/win32unix/dup2.c b/otherlibs/win32unix/dup2.c new file mode 100644 index 0000000..18918b0 --- /dev/null +++ b/otherlibs/win32unix/dup2.c @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: dup2.c,v 1.9 2006-09-21 09:43:58 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +extern int _dup2(int, int); + +CAMLprim value unix_dup2(value fd1, value fd2) +{ + HANDLE oldh, newh; + + oldh = Handle_val(fd2); + if (! DuplicateHandle(GetCurrentProcess(), Handle_val(fd1), + GetCurrentProcess(), &newh, + 0L, TRUE, DUPLICATE_SAME_ACCESS)) { + win32_maperr(GetLastError()); + return -1; + } + Handle_val(fd2) = newh; + if (Descr_kind_val(fd2) == KIND_SOCKET) + closesocket((SOCKET) oldh); + else + CloseHandle(oldh); + Descr_kind_val(fd2) = Descr_kind_val(fd1); + /* Reflect the dup2 on the CRT fds, if any */ + if (CRT_fd_val(fd1) != NO_CRT_FD || CRT_fd_val(fd2) != NO_CRT_FD) + _dup2(win_CRT_fd_of_filedescr(fd1), win_CRT_fd_of_filedescr(fd2)); + return Val_unit; +} diff --git a/otherlibs/win32unix/errmsg.c b/otherlibs/win32unix/errmsg.c new file mode 100644 index 0000000..781949e --- /dev/null +++ b/otherlibs/win32unix/errmsg.c @@ -0,0 +1,44 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: errmsg.c,v 1.5 2003-12-31 00:00:14 doligez Exp $ */ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +extern int error_table[]; + +CAMLprim value unix_error_message(value err) +{ + int errnum; + char buffer[512]; + + errnum = Is_block(err) ? Int_val(Field(err, 0)) : error_table[Int_val(err)]; + if (errnum > 0) + return copy_string(strerror(errnum)); + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + -errnum, + 0, + buffer, + sizeof(buffer), + NULL)) + return copy_string(buffer); + sprintf(buffer, "unknown error #%d", errnum); + return copy_string(buffer); +} + diff --git a/otherlibs/win32unix/getpeername.c b/otherlibs/win32unix/getpeername.c new file mode 100644 index 0000000..50899f4 --- /dev/null +++ b/otherlibs/win32unix/getpeername.c @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getpeername.c,v 1.10 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" +#include "socketaddr.h" + +CAMLprim value unix_getpeername(sock) + value sock; +{ + int retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + + addr_len = sizeof(sock_addr); + retcode = getpeername(Socket_val(sock), + &addr.s_gen, &addr_len); + if (retcode == -1) { + win32_maperr(WSAGetLastError()); + uerror("getpeername", Nothing); + } + return alloc_sockaddr(&addr, addr_len, -1); +} diff --git a/otherlibs/win32unix/getpid.c b/otherlibs/win32unix/getpid.c new file mode 100644 index 0000000..81f161b --- /dev/null +++ b/otherlibs/win32unix/getpid.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getpid.c,v 1.4 2001-12-07 13:40:44 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +extern value val_process_id; + +CAMLprim value unix_getpid(value unit) +{ + return val_process_id; +} diff --git a/otherlibs/win32unix/getsockname.c b/otherlibs/win32unix/getsockname.c new file mode 100644 index 0000000..51c1e66 --- /dev/null +++ b/otherlibs/win32unix/getsockname.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: getsockname.c,v 1.8 2005-03-24 17:20:53 doligez Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" +#include "socketaddr.h" + +CAMLprim value unix_getsockname(sock) + value sock; +{ + int retcode; + union sock_addr_union addr; + socklen_param_type addr_len; + + addr_len = sizeof(sock_addr); + retcode = getsockname(Socket_val(sock), + &addr.s_gen, &addr_len); + if (retcode == -1) uerror("getsockname", Nothing); + return alloc_sockaddr(&addr, addr_len, -1); +} diff --git a/otherlibs/win32unix/gettimeofday.c b/otherlibs/win32unix/gettimeofday.c new file mode 100644 index 0000000..aa9c9d9 --- /dev/null +++ b/otherlibs/win32unix/gettimeofday.c @@ -0,0 +1,36 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: gettimeofday.c,v 1.7 2007-03-01 13:51:24 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <time.h> + +#include "unixsupport.h" + +static time_t initial_time = 0; /* 0 means uninitialized */ +static DWORD initial_tickcount; + +CAMLprim value unix_gettimeofday(value unit) +{ + DWORD tickcount = GetTickCount(); + if (initial_time == 0 || tickcount < initial_tickcount) { + initial_tickcount = tickcount; + initial_time = time(NULL); + return copy_double((double) initial_time); + } else { + return copy_double((double) initial_time + + (double) (tickcount - initial_tickcount) * 1e-3); + } +} diff --git a/otherlibs/win32unix/libunix.clib b/otherlibs/win32unix/libunix.clib new file mode 100644 index 0000000..043dcf7 --- /dev/null +++ b/otherlibs/win32unix/libunix.clib @@ -0,0 +1,17 @@ +# Files in this directory +accept.o bind.o channels.o close.o +close_on.o connect.o createprocess.o dup.o dup2.o errmsg.o +getpeername.o getpid.o getsockname.o gettimeofday.o +link.o listen.o lockf.o lseek.o nonblock.o +mkdir.o open.o pipe.o read.o rename.o +select.o sendrecv.o +shutdown.o sleep.o socket.o sockopt.o startup.o stat.o +system.o unixsupport.o windir.o winwait.o write.o +winlist.o winworker.o windbug.o + +# Files from the ../unix directory +access.o addrofstr.o chdir.o chmod.o cst2constr.o +cstringv.o envir.o execv.o execve.o execvp.o +exit.o getcwd.o gethost.o gethostname.o getproto.o +getserv.o gmtime.o putenv.o rmdir.o +socketaddr.o strofaddr.o time.o unlink.o utimes.o diff --git a/otherlibs/win32unix/link.c b/otherlibs/win32unix/link.c new file mode 100644 index 0000000..8763633 --- /dev/null +++ b/otherlibs/win32unix/link.c @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* File contributed by Lionel Fourquaux */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: link.c,v 1.3 2001-12-07 13:40:44 xleroy Exp $ */ + +#include <windows.h> +#include <mlvalues.h> +#include <fail.h> +#include "unixsupport.h" + +typedef +BOOL (WINAPI *tCreateHardLink)( + LPCTSTR lpFileName, + LPCTSTR lpExistingFileName, + LPSECURITY_ATTRIBUTES lpSecurityAttributes +); + +CAMLprim value unix_link(value path1, value path2) +{ + HMODULE hModKernel32; + tCreateHardLink pCreateHardLink; + hModKernel32 = GetModuleHandle("KERNEL32.DLL"); + pCreateHardLink = + (tCreateHardLink) GetProcAddress(hModKernel32, "CreateHardLinkA"); + if (pCreateHardLink == NULL) + invalid_argument("Unix.link not implemented"); + if (! pCreateHardLink(String_val(path2), String_val(path1), NULL)) { + win32_maperr(GetLastError()); + uerror("link", path2); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/listen.c b/otherlibs/win32unix/listen.c new file mode 100644 index 0000000..7e17148 --- /dev/null +++ b/otherlibs/win32unix/listen.c @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: listen.c,v 1.9 2002-04-30 15:00:46 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_listen(sock, backlog) + value sock, backlog; +{ + if (listen(Socket_val(sock), Int_val(backlog)) == -1) { + win32_maperr(WSAGetLastError()); + uerror("listen", Nothing); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/lockf.c b/otherlibs/win32unix/lockf.c new file mode 100644 index 0000000..34a7eb0 --- /dev/null +++ b/otherlibs/win32unix/lockf.c @@ -0,0 +1,160 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Tracy Camp, PolyServe Inc., <campt@polyserve.com> */ +/* Further improvements by Reed Wilson */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* under the terms of the GNU Library General Public License. */ +/* */ +/***********************************************************************/ + +/* $Id: lockf.c,v 1.9 2008-12-03 18:09:09 doligez Exp $ */ + +#include <errno.h> +#include <fcntl.h> +#include <mlvalues.h> +#include <memory.h> +#include <fail.h> +#include "unixsupport.h" +#include <stdio.h> +#include <signals.h> + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER (-1) +#endif + +/* Sets handle h to a position based on gohere */ +/* output, if set, is changed to the new location */ + +static void set_file_pointer(HANDLE h, LARGE_INTEGER gohere, + PLARGE_INTEGER output, DWORD method) +{ + LONG high = gohere.HighPart; + DWORD ret = SetFilePointer(h, gohere.LowPart, &high, method); + if(ret == INVALID_SET_FILE_POINTER) { + DWORD err = GetLastError(); + if(err != NO_ERROR) { + win32_maperr(err); + uerror("lockf", Nothing); + } + } + if(output != NULL) { + output->LowPart = ret; + output->HighPart = high; + } +} + +CAMLprim value unix_lockf(value fd, value cmd, value span) +{ + CAMLparam3(fd, cmd, span); + OVERLAPPED overlap; + intnat l_len; + HANDLE h; + OSVERSIONINFO version; + LARGE_INTEGER cur_position; + LARGE_INTEGER beg_position; + LARGE_INTEGER lock_len; + LARGE_INTEGER zero; + DWORD err = NO_ERROR; + + version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if(GetVersionEx(&version) == 0) { + invalid_argument("lockf only supported on WIN32_NT platforms: could not determine current platform."); + } + if(version.dwPlatformId != VER_PLATFORM_WIN32_NT) { + invalid_argument("lockf only supported on WIN32_NT platforms"); + } + + h = Handle_val(fd); + + l_len = Long_val(span); + + /* No matter what, we need the current position in the file */ + zero.HighPart = zero.LowPart = 0; + set_file_pointer(h, zero, &cur_position, FILE_CURRENT); + + /* All unused fields must be set to zero */ + memset(&overlap, 0, sizeof(overlap)); + + if(l_len == 0) { + /* Lock from cur to infinity */ + lock_len.QuadPart = -1; + overlap.OffsetHigh = cur_position.HighPart; + overlap.Offset = cur_position.LowPart ; + } + else if(l_len > 0) { + /* Positive file offset */ + lock_len.QuadPart = l_len; + overlap.OffsetHigh = cur_position.HighPart; + overlap.Offset = cur_position.LowPart ; + } + else { + /* Negative file offset */ + lock_len.QuadPart = - l_len; + if (lock_len.QuadPart > cur_position.QuadPart) { + errno = EINVAL; + uerror("lockf", Nothing); + } + beg_position.QuadPart = cur_position.QuadPart - lock_len.QuadPart; + overlap.OffsetHigh = beg_position.HighPart; + overlap.Offset = beg_position.LowPart ; + } + + switch(Int_val(cmd)) { + case 0: /* F_ULOCK - unlock */ + if (! UnlockFileEx(h, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) + err = GetLastError(); + break; + case 1: /* F_LOCK - blocking write lock */ + enter_blocking_section(); + if (! LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) + err = GetLastError(); + leave_blocking_section(); + break; + case 2: /* F_TLOCK - non-blocking write lock */ + if (! LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) + err = GetLastError(); + break; + case 3: /* F_TEST - check whether a write lock can be obtained */ + /* I'm doing this by aquiring an immediate write + * lock and then releasing it. It is not clear that + * this behavior matches anything in particular, but + * it is not clear the nature of the lock test performed + * by ocaml (unix) currently. */ + if (LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) { + UnlockFileEx(h, 0, lock_len.LowPart, lock_len.HighPart, &overlap); + } else { + err = GetLastError(); + } + break; + case 4: /* F_RLOCK - blocking read lock */ + enter_blocking_section(); + if (! LockFileEx(h, 0, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) + err = GetLastError(); + leave_blocking_section(); + break; + case 5: /* F_TRLOCK - non-blocking read lock */ + if (! LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, + lock_len.LowPart, lock_len.HighPart, &overlap)) + err = GetLastError(); + break; + default: + errno = EINVAL; + uerror("lockf", Nothing); + } + if (err != NO_ERROR) { + win32_maperr(err); + uerror("lockf", Nothing); + } + CAMLreturn(Val_unit); +} diff --git a/otherlibs/win32unix/lseek.c b/otherlibs/win32unix/lseek.c new file mode 100644 index 0000000..a379269 --- /dev/null +++ b/otherlibs/win32unix/lseek.c @@ -0,0 +1,70 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: lseek.c,v 1.7 2005-02-02 15:52:26 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +#ifdef HAS_UNISTD +#include <unistd.h> +#else +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 +#endif + +static DWORD seek_command_table[] = { + FILE_BEGIN, FILE_CURRENT, FILE_END +}; + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER (-1) +#endif + +static __int64 caml_set_file_pointer(HANDLE h, __int64 dist, DWORD mode) +{ + LARGE_INTEGER i; + DWORD err; + + i.QuadPart = dist; + i.LowPart = SetFilePointer(h, i.LowPart, &i.HighPart, mode); + if (i.LowPart == INVALID_SET_FILE_POINTER) { + err = GetLastError(); + if (err != NO_ERROR) { win32_maperr(err); uerror("lseek", Nothing); } + } + return i.QuadPart; +} + +CAMLprim value unix_lseek(value fd, value ofs, value cmd) +{ + __int64 ret; + + ret = caml_set_file_pointer(Handle_val(fd), Long_val(ofs), + seek_command_table[Int_val(cmd)]); + if (ret > Max_long) { + win32_maperr(ERROR_ARITHMETIC_OVERFLOW); + uerror("lseek", Nothing); + } + return Val_long(ret); +} + +CAMLprim value unix_lseek_64(value fd, value ofs, value cmd) +{ + __int64 ret; + + ret = caml_set_file_pointer(Handle_val(fd), Int64_val(ofs), + seek_command_table[Int_val(cmd)]); + return copy_int64(ret); +} diff --git a/otherlibs/win32unix/mkdir.c b/otherlibs/win32unix/mkdir.c new file mode 100644 index 0000000..f09a9e7 --- /dev/null +++ b/otherlibs/win32unix/mkdir.c @@ -0,0 +1,24 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: mkdir.c,v 1.5 2001-12-07 13:40:45 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_mkdir(path, perm) + value path, perm; +{ + if (_mkdir(String_val(path)) == -1) uerror("mkdir", path); + return Val_unit; +} diff --git a/otherlibs/win32unix/nonblock.c b/otherlibs/win32unix/nonblock.c new file mode 100755 index 0000000..ca0906a --- /dev/null +++ b/otherlibs/win32unix/nonblock.c @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: nonblock.c,v 1.1 2003-01-06 16:44:21 xleroy Exp $ */ + +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_set_nonblock(socket) + value socket; +{ + u_long non_block = 1; + + if (ioctlsocket(Socket_val(socket), FIONBIO, &non_block) != 0) { + win32_maperr(WSAGetLastError()); + uerror("unix_set_nonblock", Nothing); + } + return Val_unit; +} + +CAMLprim value unix_clear_nonblock(socket) + value socket; +{ + u_long non_block = 0; + + if (ioctlsocket(Socket_val(socket), FIONBIO, &non_block) != 0) { + win32_maperr(WSAGetLastError()); + uerror("unix_clear_nonblock", Nothing); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/open.c b/otherlibs/win32unix/open.c new file mode 100644 index 0000000..cbed7e1 --- /dev/null +++ b/otherlibs/win32unix/open.c @@ -0,0 +1,67 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: open.c,v 1.10 2008-01-11 16:13:16 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" +#include <fcntl.h> + +static int open_access_flags[12] = { + GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE, + 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +static int open_create_flags[12] = { + 0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0 +}; + +CAMLprim value unix_open(value path, value flags, value perm) +{ + int fileaccess, createflags, fileattrib, filecreate; + SECURITY_ATTRIBUTES attr; + HANDLE h; + + fileaccess = convert_flag_list(flags, open_access_flags); + + createflags = convert_flag_list(flags, open_create_flags); + if ((createflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + filecreate = CREATE_NEW; + else if ((createflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) + filecreate = CREATE_ALWAYS; + else if (createflags & O_TRUNC) + filecreate = TRUNCATE_EXISTING; + else if (createflags & O_CREAT) + filecreate = OPEN_ALWAYS; + else + filecreate = OPEN_EXISTING; + + if ((createflags & O_CREAT) && (Int_val(perm) & 0200) == 0) + fileattrib = FILE_ATTRIBUTE_READONLY; + else + fileattrib = FILE_ATTRIBUTE_NORMAL; + + attr.nLength = sizeof(attr); + attr.lpSecurityDescriptor = NULL; + attr.bInheritHandle = TRUE; + + h = CreateFile(String_val(path), fileaccess, + FILE_SHARE_READ | FILE_SHARE_WRITE, &attr, + filecreate, fileattrib, NULL); + if (h == INVALID_HANDLE_VALUE) { + win32_maperr(GetLastError()); + uerror("open", path); + } + return win_alloc_handle(h); +} diff --git a/otherlibs/win32unix/pipe.c b/otherlibs/win32unix/pipe.c new file mode 100644 index 0000000..25e5f5c --- /dev/null +++ b/otherlibs/win32unix/pipe.c @@ -0,0 +1,45 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: pipe.c,v 1.7 2001-12-07 13:40:45 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include "unixsupport.h" +#include <fcntl.h> + +#define SIZEBUF 1024 + +CAMLprim value unix_pipe(value unit) +{ + SECURITY_ATTRIBUTES attr; + HANDLE readh, writeh; + value readfd = Val_unit, writefd = Val_unit, res; + + attr.nLength = sizeof(attr); + attr.lpSecurityDescriptor = NULL; + attr.bInheritHandle = TRUE; + if (! CreatePipe(&readh, &writeh, &attr, SIZEBUF)) { + win32_maperr(GetLastError()); + uerror("pipe", Nothing); + } + Begin_roots2(readfd, writefd) + readfd = win_alloc_handle(readh); + writefd = win_alloc_handle(writeh); + res = alloc_small(2, 0); + Field(res, 0) = readfd; + Field(res, 1) = writefd; + End_roots(); + return res; +} diff --git a/otherlibs/win32unix/read.c b/otherlibs/win32unix/read.c new file mode 100644 index 0000000..df57d83 --- /dev/null +++ b/otherlibs/win32unix/read.c @@ -0,0 +1,54 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: read.c,v 1.9 2006-10-18 08:26:54 xleroy Exp $ */ + +#include <string.h> +#include <mlvalues.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_read(value fd, value buf, value ofs, value vlen) +{ + intnat len; + DWORD numbytes, numread; + char iobuf[UNIX_BUFFER_SIZE]; + DWORD err = 0; + + Begin_root (buf); + len = Long_val(vlen); + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + if (Descr_kind_val(fd) == KIND_SOCKET) { + int ret; + SOCKET s = Socket_val(fd); + enter_blocking_section(); + ret = recv(s, iobuf, numbytes, 0); + if (ret == SOCKET_ERROR) err = WSAGetLastError(); + leave_blocking_section(); + numread = ret; + } else { + HANDLE h = Handle_val(fd); + enter_blocking_section(); + if (! ReadFile(h, iobuf, numbytes, &numread, NULL)) + err = GetLastError(); + leave_blocking_section(); + } + if (err) { + win32_maperr(err); + uerror("read", Nothing); + } + memmove (&Byte(buf, Long_val(ofs)), iobuf, numread); + End_roots(); + return Val_int(numread); +} diff --git a/otherlibs/win32unix/rename.c b/otherlibs/win32unix/rename.c new file mode 100644 index 0000000..a2efd5a --- /dev/null +++ b/otherlibs/win32unix/rename.c @@ -0,0 +1,43 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Tracy Camp, PolyServe Inc., <campt@polyserve.com> */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: rename.c,v 1.3 2004-07-13 12:25:15 xleroy Exp $ */ + +#include <stdio.h> +#include <mlvalues.h> +#include "unixsupport.h" + +CAMLprim value unix_rename(value path1, value path2) +{ + static int supports_MoveFileEx = -1; /* don't know yet */ + BOOL ok; + + if (supports_MoveFileEx < 0) { + OSVERSIONINFO VersionInfo; + VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + supports_MoveFileEx = + (GetVersionEx(&VersionInfo) != 0) + && (VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); + } + if (supports_MoveFileEx > 0) + ok = MoveFileEx(String_val(path1), String_val(path2), + MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | + MOVEFILE_COPY_ALLOWED); + else + ok = MoveFile(String_val(path1), String_val(path2)); + if (! ok) { + win32_maperr(GetLastError()); + uerror("rename", path1); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/select.c b/otherlibs/win32unix/select.c new file mode 100644 index 0000000..544611d --- /dev/null +++ b/otherlibs/win32unix/select.c @@ -0,0 +1,1155 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: select.c,v 1.15 2008-12-03 18:09:09 doligez Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <signals.h> +#include <winsock2.h> +#include <windows.h> +#include "unixsupport.h" +#include "windbug.h" +#include "winworker.h" +#include "winlist.h" + +/* This constant define the maximum number of objects that + * can be handle by a SELECTDATA. + * It takes the following parameters into account: + * - limitation on number of objects is mostly due to limitation + * a WaitForMultipleObjects + * - there is always an event "hStop" to watch + * + * This lead to pick the following value as the biggest possible + * value + */ +#define MAXIMUM_SELECT_OBJECTS (MAXIMUM_WAIT_OBJECTS - 1) + +/* Manage set of handle */ +typedef struct _SELECTHANDLESET { + LPHANDLE lpHdl; + DWORD nMax; + DWORD nLast; +} SELECTHANDLESET; + +typedef SELECTHANDLESET *LPSELECTHANDLESET; + +void handle_set_init (LPSELECTHANDLESET hds, LPHANDLE lpHdl, DWORD max) +{ + DWORD i; + + hds->lpHdl = lpHdl; + hds->nMax = max; + hds->nLast = 0; + + /* Set to invalid value every entry of the handle */ + for (i = 0; i < hds->nMax; i++) + { + hds->lpHdl[i] = INVALID_HANDLE_VALUE; + }; +} + +void handle_set_add (LPSELECTHANDLESET hds, HANDLE hdl) +{ + LPSELECTHANDLESET res; + + if (hds->nLast < hds->nMax) + { + hds->lpHdl[hds->nLast] = hdl; + hds->nLast++; + } + +#ifdef DBUG + dbug_print("Adding handle %x to set %x", hdl, hds); +#endif +} + +BOOL handle_set_mem (LPSELECTHANDLESET hds, HANDLE hdl) +{ + BOOL res; + DWORD i; + + res = FALSE; + for (i = 0; !res && i < hds->nLast; i++) + { + res = (hds->lpHdl[i] == hdl); + } + + return res; +} + +void handle_set_reset (LPSELECTHANDLESET hds) +{ + DWORD i; + + for (i = 0; i < hds->nMax; i++) + { + hds->lpHdl[i] = INVALID_HANDLE_VALUE; + } + hds->nMax = 0; + hds->nLast = 0; + hds->lpHdl = NULL; +} + +/* Data structure for handling select */ + +typedef enum _SELECTHANDLETYPE { + SELECT_HANDLE_NONE = 0, + SELECT_HANDLE_DISK, + SELECT_HANDLE_CONSOLE, + SELECT_HANDLE_PIPE, + SELECT_HANDLE_SOCKET, +} SELECTHANDLETYPE; + +typedef enum _SELECTMODE { + SELECT_MODE_NONE = 0, + SELECT_MODE_READ, + SELECT_MODE_WRITE, + SELECT_MODE_EXCEPT, +} SELECTMODE; + +typedef enum _SELECTSTATE { + SELECT_STATE_NONE = 0, + SELECT_STATE_INITFAILED, + SELECT_STATE_ERROR, + SELECT_STATE_SIGNALED +} SELECTSTATE; + +typedef enum _SELECTTYPE { + SELECT_TYPE_NONE = 0, + SELECT_TYPE_STATIC, /* Result is known without running anything */ + SELECT_TYPE_CONSOLE_READ, /* Reading data on console */ + SELECT_TYPE_PIPE_READ, /* Reading data on pipe */ + SELECT_TYPE_SOCKET /* Classic select */ +} SELECTTYPE; + +/* Data structure for results */ +typedef struct _SELECTRESULT { + LIST lst; + SELECTMODE EMode; + LPVOID lpOrig; +} SELECTRESULT; + +typedef SELECTRESULT *LPSELECTRESULT; + +/* Data structure for query */ +typedef struct _SELECTQUERY { + LIST lst; + SELECTMODE EMode; + HANDLE hFileDescr; + LPVOID lpOrig; +} SELECTQUERY; + +typedef SELECTQUERY *LPSELECTQUERY; + +typedef struct _SELECTDATA { + LIST lst; + SELECTTYPE EType; + SELECTRESULT aResults[MAXIMUM_SELECT_OBJECTS]; + DWORD nResultsCount; + /* Data following are dedicated to APC like call, they + will be initialized if required. + */ + WORKERFUNC funcWorker; + SELECTQUERY aQueries[MAXIMUM_SELECT_OBJECTS]; + DWORD nQueriesCount; + SELECTSTATE EState; + DWORD nError; + LPWORKER lpWorker; +} SELECTDATA; + +typedef SELECTDATA *LPSELECTDATA; + +/* Get error status if associated condition is false */ +static BOOL check_error(LPSELECTDATA lpSelectData, BOOL bFailed) +{ + if (bFailed && lpSelectData->nError == 0) + { + lpSelectData->EState = SELECT_STATE_ERROR; + lpSelectData->nError = GetLastError(); + } + return bFailed; +} + +/* Create data associated with a select operation */ +LPSELECTDATA select_data_new (LPSELECTDATA lpSelectData, SELECTTYPE EType) +{ + /* Allocate the data structure */ + LPSELECTDATA res; + DWORD i; + + if (!HeapLock(GetProcessHeap())) + { + win32_maperr(GetLastError()); + uerror("select", Nothing); + } + res = (LPSELECTDATA)HeapAlloc(GetProcessHeap(), 0, sizeof(SELECTDATA)); + HeapUnlock(GetProcessHeap()); + + /* Init common data */ + list_init((LPLIST)res); + list_next_set((LPLIST)res, (LPLIST)lpSelectData); + res->EType = EType; + res->nResultsCount = 0; + + + /* Data following are dedicated to APC like call, they + will be initialized if required. For now they are set to + invalid values. + */ + res->funcWorker = NULL; + res->nQueriesCount = 0; + res->EState = SELECT_STATE_NONE; + res->nError = 0; + res->lpWorker = NULL; + + return res; +} + +/* Free select data */ +void select_data_free (LPSELECTDATA lpSelectData) +{ + DWORD i; + +#ifdef DBUG + dbug_print("Freeing data of %x", lpSelectData); +#endif + + /* Free APC related data, if they exists */ + if (lpSelectData->lpWorker != NULL) + { + worker_job_finish(lpSelectData->lpWorker); + lpSelectData->lpWorker = NULL; + }; + + /* Make sure results/queries cannot be accessed */ + lpSelectData->nResultsCount = 0; + lpSelectData->nQueriesCount = 0; + + if (!HeapLock(GetProcessHeap())) + { + win32_maperr(GetLastError()); + uerror("select_data_free", Nothing); + }; + HeapFree(GetProcessHeap(), 0, lpSelectData); + HeapUnlock(GetProcessHeap()); +} + +/* Add a result to select data, return zero if something goes wrong. */ +DWORD select_data_result_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, LPVOID lpOrig) +{ + DWORD res; + DWORD i; + + res = 0; + if (lpSelectData->nResultsCount < MAXIMUM_SELECT_OBJECTS) + { + i = lpSelectData->nResultsCount; + lpSelectData->aResults[i].EMode = EMode; + lpSelectData->aResults[i].lpOrig = lpOrig; + lpSelectData->nResultsCount++; + res = 1; + } + + return res; +} + +/* Add a query to select data, return zero if something goes wrong */ +DWORD select_data_query_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, HANDLE hFileDescr, LPVOID lpOrig) +{ + DWORD res; + DWORD i; + + res = 0; + if (lpSelectData->nQueriesCount < MAXIMUM_SELECT_OBJECTS) + { + i = lpSelectData->nQueriesCount; + lpSelectData->aQueries[i].EMode = EMode; + lpSelectData->aQueries[i].hFileDescr = hFileDescr; + lpSelectData->aQueries[i].lpOrig = lpOrig; + lpSelectData->nQueriesCount++; + res = 1; + } + + return res; +} + +/* Search for a job that has available query slots and that match provided type. + * If none is found, create a new one. Return the corresponding SELECTDATA, and + * update provided SELECTDATA head, if required. + */ +LPSELECTDATA select_data_job_search (LPSELECTDATA *lppSelectData, SELECTTYPE EType) +{ + LPSELECTDATA res; + + res = NULL; + + /* Search for job */ +#ifdef DBUG + dbug_print("Searching an available job for type %d", EType); +#endif + res = *lppSelectData; + while ( + res != NULL + && !( + res->EType == EType + && res->nQueriesCount < MAXIMUM_SELECT_OBJECTS + ) + ) + { + res = LIST_NEXT(LPSELECTDATA, res); + } + + /* No matching job found, create one */ + if (res == NULL) + { +#ifdef DBUG + dbug_print("No job for type %d found, create one", EType); +#endif + res = select_data_new(*lppSelectData, EType); + *lppSelectData = res; + } + + return res; +} + +/***********************/ +/* Console */ +/***********************/ + +void read_console_poll(HANDLE hStop, void *_data) +{ + HANDLE events[2]; + INPUT_RECORD record; + DWORD waitRes; + DWORD n; + LPSELECTDATA lpSelectData; + LPSELECTQUERY lpQuery; + +#ifdef DBUG + dbug_print("Waiting for data on console"); +#endif + + record; + waitRes = 0; + n = 0; + lpSelectData = (LPSELECTDATA)_data; + lpQuery = &(lpSelectData->aQueries[0]); + + events[0] = hStop; + events[1] = lpQuery->hFileDescr; + while (lpSelectData->EState == SELECT_STATE_NONE) + { + waitRes = WaitForMultipleObjects(2, events, FALSE, INFINITE); + if (waitRes == WAIT_OBJECT_0 || check_error(lpSelectData, waitRes == WAIT_FAILED)) + { + /* stop worker event or error */ + break; + } + /* console event */ + if (check_error(lpSelectData, PeekConsoleInput(lpQuery->hFileDescr, &record, 1, &n) == 0)) + { + break; + } + /* check for ASCII keypress only */ + if (record.EventType == KEY_EVENT && + record.Event.KeyEvent.bKeyDown && + record.Event.KeyEvent.uChar.AsciiChar != 0) + { + select_data_result_add(lpSelectData, lpQuery->EMode, lpQuery->lpOrig); + lpSelectData->EState = SELECT_STATE_SIGNALED; + break; + } + else + { + /* discard everything else and try again */ + if (check_error(lpSelectData, ReadConsoleInput(lpQuery->hFileDescr, &record, 1, &n) == 0)) + { + break; + } + } + }; +} + +/* Add a function to monitor console input */ +LPSELECTDATA read_console_poll_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, HANDLE hFileDescr, LPVOID lpOrig) +{ + LPSELECTDATA res; + + res = select_data_new(lpSelectData, SELECT_TYPE_CONSOLE_READ); + res->funcWorker = read_console_poll; + select_data_query_add(res, SELECT_MODE_READ, hFileDescr, lpOrig); + + return res; +} + +/***********************/ +/* Pipe */ +/***********************/ + +/* Monitor a pipe for input */ +void read_pipe_poll (HANDLE hStop, void *_data) +{ + DWORD event; + DWORD n; + LPSELECTQUERY iterQuery; + LPSELECTDATA lpSelectData; + DWORD i; + + /* Poll pipe */ + event = 0; + n = 0; + lpSelectData = (LPSELECTDATA)_data; + +#ifdef DBUG + dbug_print("Checking data pipe"); +#endif + while (lpSelectData->EState == SELECT_STATE_NONE) + { + for (i = 0; i < lpSelectData->nQueriesCount; i++) + { + iterQuery = &(lpSelectData->aQueries[i]); + if (check_error( + lpSelectData, + PeekNamedPipe( + iterQuery->hFileDescr, + NULL, + 0, + NULL, + &n, + NULL) == 0)) + { + break; + }; + + if (n > 0) + { + lpSelectData->EState = SELECT_STATE_SIGNALED; + select_data_result_add(lpSelectData, iterQuery->EMode, iterQuery->lpOrig); + }; + }; + + /* Alas, nothing except polling seems to work for pipes. + Check the state & stop_worker_event every 10 ms + */ + if (lpSelectData->EState == SELECT_STATE_NONE) + { + event = WaitForSingleObject(hStop, 10); + if (event == WAIT_OBJECT_0 || check_error(lpSelectData, event == WAIT_FAILED)) + { + break; + } + } + } +#ifdef DBUG + dbug_print("Finish checking data on pipe"); +#endif +} + +/* Add a function to monitor pipe input */ +LPSELECTDATA read_pipe_poll_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, HANDLE hFileDescr, LPVOID lpOrig) +{ + LPSELECTDATA res; + LPSELECTDATA hd; + + hd = lpSelectData; + /* Polling pipe is a non blocking operation by default. This means that each + worker can handle many pipe. We begin to try to find a worker that is + polling pipe, but for which there is under the limit of pipe per worker. + */ +#ifdef DBUG + dbug_print("Searching an available worker handling pipe"); +#endif + res = select_data_job_search(&hd, SELECT_TYPE_PIPE_READ); + + /* Add a new pipe to poll */ + res->funcWorker = read_pipe_poll; + select_data_query_add(res, EMode, hFileDescr, lpOrig); + + return hd; +} + +/***********************/ +/* Socket */ +/***********************/ + +/* Monitor socket */ +void socket_poll (HANDLE hStop, void *_data) +{ + LPSELECTDATA lpSelectData; + LPSELECTQUERY iterQuery; + HANDLE aEvents[MAXIMUM_SELECT_OBJECTS]; + DWORD nEvents; + long maskEvents; + DWORD i; + u_long iMode; + + lpSelectData = (LPSELECTDATA)_data; + + for (nEvents = 0; nEvents < lpSelectData->nQueriesCount; nEvents++) + { + iterQuery = &(lpSelectData->aQueries[nEvents]); + aEvents[nEvents] = CreateEvent(NULL, TRUE, FALSE, NULL); + maskEvents = 0; + switch (iterQuery->EMode) + { + case SELECT_MODE_READ: + maskEvents = FD_READ | FD_ACCEPT | FD_CLOSE; + break; + case SELECT_MODE_WRITE: + maskEvents = FD_WRITE | FD_CONNECT | FD_CLOSE; + break; + case SELECT_MODE_EXCEPT: + maskEvents = FD_OOB; + break; + } + check_error(lpSelectData, + WSAEventSelect( + (SOCKET)(iterQuery->hFileDescr), + aEvents[nEvents], + maskEvents) == SOCKET_ERROR); + } + + /* Add stop event */ + aEvents[nEvents] = hStop; + nEvents++; + + if (lpSelectData->nError == 0) + { + check_error(lpSelectData, + WaitForMultipleObjects( + nEvents, + aEvents, + FALSE, + INFINITE) == WAIT_FAILED); + }; + + if (lpSelectData->nError == 0) + { + for (i = 0; i < lpSelectData->nQueriesCount; i++) + { + iterQuery = &(lpSelectData->aQueries[i]); + if (WaitForSingleObject(aEvents[i], 0) == WAIT_OBJECT_0) + { +#ifdef DBUG + dbug_print("Socket %d has pending events", (i - 1)); +#endif + if (iterQuery != NULL) + { + select_data_result_add(lpSelectData, iterQuery->EMode, iterQuery->lpOrig); + } + } + /* WSAEventSelect() automatically sets socket to nonblocking mode. + Restore the blocking one. */ + iMode = 0; + check_error(lpSelectData, + WSAEventSelect((SOCKET)(iterQuery->hFileDescr), aEvents[i], 0) != 0 || + ioctlsocket((SOCKET)(iterQuery->hFileDescr), FIONBIO, &iMode) != 0); + + CloseHandle(aEvents[i]); + aEvents[i] = INVALID_HANDLE_VALUE; + } + } +} + +/* Add a function to monitor socket */ +LPSELECTDATA socket_poll_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, HANDLE hFileDescr, LPVOID lpOrig) +{ + LPSELECTDATA res; + LPSELECTDATA hd; + + hd = lpSelectData; + /* Polling socket can be done mulitple handle at the same time. You just + need one worker to use it. Try to find if there is already a worker + handling this kind of request. + */ +#ifdef DBUG + dbug_print("Scanning list of worker to find one that already handle socket"); +#endif + res = select_data_job_search(&hd, SELECT_TYPE_SOCKET); + + /* Add a new socket to poll */ + res->funcWorker = socket_poll; +#ifdef DBUG + dbug_print("Add socket %x to worker", hFileDescr); +#endif + select_data_query_add(res, EMode, hFileDescr, lpOrig); +#ifdef DBUG + dbug_print("Socket %x added", hFileDescr); +#endif + + return hd; +} + +/***********************/ +/* Static */ +/***********************/ + +/* Add a static result */ +LPSELECTDATA static_poll_add (LPSELECTDATA lpSelectData, SELECTMODE EMode, HANDLE hFileDescr, LPVOID lpOrig) +{ + LPSELECTDATA res; + LPSELECTDATA hd; + + /* Look for an already initialized static element */ + hd = lpSelectData; + res = select_data_job_search(&hd, SELECT_TYPE_STATIC); + + /* Add a new query/result */ + select_data_query_add(res, EMode, hFileDescr, lpOrig); + select_data_result_add(res, EMode, lpOrig); + + return hd; +} + +/********************************/ +/* Generic select data handling */ +/********************************/ + +/* Guess handle type */ +static SELECTHANDLETYPE get_handle_type(value fd) +{ + DWORD mode; + SELECTHANDLETYPE res; + + CAMLparam1(fd); + + mode = 0; + res = SELECT_HANDLE_NONE; + + if (Descr_kind_val(fd) == KIND_SOCKET) + { + res = SELECT_HANDLE_SOCKET; + } + else + { + switch(GetFileType(Handle_val(fd))) + { + case FILE_TYPE_DISK: + res = SELECT_HANDLE_DISK; + break; + + case FILE_TYPE_CHAR: /* character file or a console */ + if (GetConsoleMode(Handle_val(fd), &mode) != 0) + { + res = SELECT_HANDLE_CONSOLE; + } + else + { + res = SELECT_HANDLE_NONE; + }; + break; + + case FILE_TYPE_PIPE: /* a named or an anonymous pipe (socket already handled) */ + res = SELECT_HANDLE_PIPE; + break; + }; + }; + + CAMLreturnT(SELECTHANDLETYPE, res); +} + +/* Choose what to do with given data */ +LPSELECTDATA select_data_dispatch (LPSELECTDATA lpSelectData, SELECTMODE EMode, value fd) +{ + LPSELECTDATA res; + HANDLE hFileDescr; + void *lpOrig; + struct sockaddr sa; + int sa_len; + BOOL alreadyAdded; + + CAMLparam1(fd); + + res = lpSelectData; + hFileDescr = Handle_val(fd); + lpOrig = (void *)fd; + sa_len = sizeof(sa); + alreadyAdded = FALSE; + +#ifdef DBUG + dbug_print("Begin dispatching handle %x", hFileDescr); +#endif + +#ifdef DBUG + dbug_print("Waiting for %d on handle %x", EMode, hFileDescr); +#endif + + /* There is only 2 way to have except mode: transmission of OOB data through + a socket TCP/IP and through a strange interaction with a TTY. + With windows, we only consider the TCP/IP except condition + */ + switch(get_handle_type(fd)) + { + case SELECT_HANDLE_DISK: +#ifdef DBUG + dbug_print("Handle %x is a disk handle", hFileDescr); +#endif + /* Disk is always ready in read/write operation */ + if (EMode == SELECT_MODE_READ || EMode == SELECT_MODE_WRITE) + { + res = static_poll_add(res, EMode, hFileDescr, lpOrig); + }; + break; + + case SELECT_HANDLE_CONSOLE: +#ifdef DBUG + dbug_print("Handle %x is a console handle", hFileDescr); +#endif + /* Console is always ready in write operation, need to check for read. */ + if (EMode == SELECT_MODE_READ) + { + res = read_console_poll_add(res, EMode, hFileDescr, lpOrig); + } + else if (EMode == SELECT_MODE_WRITE) + { + res = static_poll_add(res, EMode, hFileDescr, lpOrig); + }; + break; + + case SELECT_HANDLE_PIPE: +#ifdef DBUG + dbug_print("Handle %x is a pipe handle", hFileDescr); +#endif + /* Console is always ready in write operation, need to check for read. */ + if (EMode == SELECT_MODE_READ) + { +#ifdef DBUG + dbug_print("Need to check availability of data on pipe"); +#endif + res = read_pipe_poll_add(res, EMode, hFileDescr, lpOrig); + } + else if (EMode == SELECT_MODE_WRITE) + { +#ifdef DBUG + dbug_print("No need to check availability of data on pipe, write operation always possible"); +#endif + res = static_poll_add(res, EMode, hFileDescr, lpOrig); + }; + break; + + case SELECT_HANDLE_SOCKET: +#ifdef DBUG + dbug_print("Handle %x is a socket handle", hFileDescr); +#endif + if (getsockname((SOCKET)hFileDescr, &sa, &sa_len) == SOCKET_ERROR) + { + if (WSAGetLastError() == WSAEINVAL) + { + /* Socket is not bound */ +#ifdef DBUG + dbug_print("Socket is not connected"); +#endif + if (EMode == SELECT_MODE_WRITE || EMode == SELECT_MODE_READ) + { + res = static_poll_add(res, EMode, hFileDescr, lpOrig); + alreadyAdded = TRUE; + } + } + } + if (!alreadyAdded) + { + res = socket_poll_add(res, EMode, hFileDescr, lpOrig); + } + break; + + default: +#ifdef DBUG + dbug_print("Handle %x is unknown", hFileDescr); +#endif + caml_failwith("Unknown handle"); + break; + }; + +#ifdef DBUG + dbug_print("Finish dispatching handle %x", hFileDescr); +#endif + + CAMLreturnT(LPSELECTDATA, res); +} + +static DWORD caml_list_length (value lst) +{ + DWORD res; + + CAMLparam1 (lst); + CAMLlocal1 (l); + + for (res = 0, l = lst; l != Val_int(0); l = Field(l, 1), res++) + { } + + CAMLreturnT(DWORD, res); +} + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +CAMLprim value unix_select(value readfds, value writefds, value exceptfds, value timeout) +{ + /* Event associated to handle */ + DWORD nEventsCount; + DWORD nEventsMax; + HANDLE *lpEventsDone; + + /* Data for all handles */ + LPSELECTDATA lpSelectData; + LPSELECTDATA iterSelectData; + + /* Iterator for results */ + LPSELECTRESULT iterResult; + + /* Iterator */ + DWORD i; + + /* Error status */ + DWORD err; + + /* Time to wait */ + DWORD milliseconds; + + /* Is there static select data */ + BOOL hasStaticData = FALSE; + + /* Wait return */ + DWORD waitRet; + + /* Set of handle */ + SELECTHANDLESET hds; + DWORD hdsMax; + LPHANDLE hdsData; + + /* Length of each list */ + DWORD readfds_len; + DWORD writefds_len; + DWORD exceptfds_len; + + CAMLparam4 (readfds, writefds, exceptfds, timeout); + CAMLlocal5 (read_list, write_list, except_list, res, l); + CAMLlocal1 (fd); + +#ifdef DBUG + dbug_print("in select"); +#endif + + nEventsCount = 0; + nEventsMax = 0; + lpEventsDone = NULL; + lpSelectData = NULL; + iterSelectData = NULL; + iterResult = NULL; + err = 0; + hasStaticData = 0; + waitRet = 0; + readfds_len = caml_list_length(readfds); + writefds_len = caml_list_length(writefds); + exceptfds_len = caml_list_length(exceptfds); + hdsMax = MAX(readfds_len, MAX(writefds_len, exceptfds_len)); + + if (!HeapLock(GetProcessHeap())) + { + win32_maperr(GetLastError()); + uerror("select", Nothing); + } + hdsData = (HANDLE *)HeapAlloc( + GetProcessHeap(), + 0, + sizeof(HANDLE) * hdsMax); + HeapUnlock(GetProcessHeap()); + + if (Double_val(timeout) >= 0.0) + { + milliseconds = 1000 * Double_val(timeout); +#ifdef DBUG + dbug_print("Will wait %d ms", milliseconds); +#endif + } + else + { + milliseconds = INFINITE; + } + + + /* Create list of select data, based on the different list of fd to watch */ +#ifdef DBUG + dbug_print("Dispatch read fd"); +#endif + handle_set_init(&hds, hdsData, hdsMax); + for (l = readfds; l != Val_int(0); l = Field(l, 1)) + { + fd = Field(l, 0); + if (!handle_set_mem(&hds, Handle_val(fd))) + { + handle_set_add(&hds, Handle_val(fd)); + lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_READ, fd); + } + else + { +#ifdef DBUG + dbug_print("Discarding handle %x which is already monitor for read", Handle_val(fd)); +#endif + } + } + handle_set_reset(&hds); + +#ifdef DBUG + dbug_print("Dispatch write fd"); +#endif + handle_set_init(&hds, hdsData, hdsMax); + for (l = writefds; l != Val_int(0); l = Field(l, 1)) + { + fd = Field(l, 0); + if (!handle_set_mem(&hds, Handle_val(fd))) + { + handle_set_add(&hds, Handle_val(fd)); + lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_WRITE, fd); + } + else + { +#ifdef DBUG + dbug_print("Discarding handle %x which is already monitor for write", Handle_val(fd)); +#endif + } + } + handle_set_reset(&hds); + +#ifdef DBUG + dbug_print("Dispatch exceptional fd"); +#endif + handle_set_init(&hds, hdsData, hdsMax); + for (l = exceptfds; l != Val_int(0); l = Field(l, 1)) + { + fd = Field(l, 0); + if (!handle_set_mem(&hds, Handle_val(fd))) + { + handle_set_add(&hds, Handle_val(fd)); + lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_EXCEPT, fd); + } + else + { +#ifdef DBUG + dbug_print("Discarding handle %x which is already monitor for exceptional", Handle_val(fd)); +#endif + } + } + handle_set_reset(&hds); + + /* Building the list of handle to wait for */ +#ifdef DBUG + dbug_print("Building events done array"); +#endif + nEventsMax = list_length((LPLIST)lpSelectData); + nEventsCount = 0; + if (!HeapLock(GetProcessHeap())) + { + win32_maperr(GetLastError()); + uerror("select", Nothing); + } + lpEventsDone = (HANDLE *)HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE) * nEventsMax); + HeapUnlock(GetProcessHeap()); + + iterSelectData = lpSelectData; + while (iterSelectData != NULL) + { + /* Check if it is static data. If this is the case, launch everything + * but don't wait for events. It helps to test if there are events on + * any other fd (which are not static), knowing that there is at least + * one result (the static data). + */ + if (iterSelectData->EType == SELECT_TYPE_STATIC) + { + hasStaticData = TRUE; + }; + + /* Execute APC */ + if (iterSelectData->funcWorker != NULL) + { + iterSelectData->lpWorker = + worker_job_submit( + iterSelectData->funcWorker, + (void *)iterSelectData); +#ifdef DBUG + dbug_print("Job submitted to worker %x", iterSelectData->lpWorker); +#endif + lpEventsDone[nEventsCount] = worker_job_event_done(iterSelectData->lpWorker); + nEventsCount++; + }; + iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData); + }; + +#ifdef DBUG + dbug_print("Need to watch %d workers", nEventsCount); +#endif + + /* Processing select itself */ + enter_blocking_section(); + /* There are worker started, waiting to be monitored */ + if (nEventsCount > 0) + { + /* Waiting for event */ + if (err == 0 && !hasStaticData) + { +#ifdef DBUG + dbug_print("Waiting for one select worker to be done"); +#endif + switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, FALSE, milliseconds)) + { + case WAIT_FAILED: + err = GetLastError(); + break; + + case WAIT_TIMEOUT: +#ifdef DBUG + dbug_print("Select timeout"); +#endif + break; + + default: +#ifdef DBUG + dbug_print("One worker is done"); +#endif + break; + }; + } + + /* Ordering stop to every worker */ +#ifdef DBUG + dbug_print("Sending stop signal to every select workers"); +#endif + iterSelectData = lpSelectData; + while (iterSelectData != NULL) + { + if (iterSelectData->lpWorker != NULL) + { + worker_job_stop(iterSelectData->lpWorker); + }; + iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData); + }; + +#ifdef DBUG + dbug_print("Waiting for every select worker to be done"); +#endif + switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, TRUE, INFINITE)) + { + case WAIT_FAILED: + err = GetLastError(); + break; + + default: +#ifdef DBUG + dbug_print("Every worker is done"); +#endif + break; + } + } + /* Nothing to monitor but some time to wait. */ + else if (!hasStaticData) + { + Sleep(milliseconds); + } + leave_blocking_section(); + +#ifdef DBUG + dbug_print("Error status: %d (0 is ok)", err); +#endif + /* Build results */ + if (err == 0) + { +#ifdef DBUG + dbug_print("Building result"); +#endif + read_list = Val_unit; + write_list = Val_unit; + except_list = Val_unit; + + iterSelectData = lpSelectData; + while (iterSelectData != NULL) + { + for (i = 0; i < iterSelectData->nResultsCount; i++) + { + iterResult = &(iterSelectData->aResults[i]); + l = alloc_small(2, 0); + Store_field(l, 0, (value)iterResult->lpOrig); + switch (iterResult->EMode) + { + case SELECT_MODE_READ: + Store_field(l, 1, read_list); + read_list = l; + break; + case SELECT_MODE_WRITE: + Store_field(l, 1, write_list); + write_list = l; + break; + case SELECT_MODE_EXCEPT: + Store_field(l, 1, except_list); + except_list = l; + break; + } + } + /* We try to only process the first error, bypass other errors */ + if (err == 0 && iterSelectData->EState == SELECT_STATE_ERROR) + { + err = iterSelectData->nError; + } + iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData); + } + } + + /* Free resources */ +#ifdef DBUG + dbug_print("Free selectdata resources"); +#endif + iterSelectData = lpSelectData; + while (iterSelectData != NULL) + { + lpSelectData = iterSelectData; + iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData); + select_data_free(lpSelectData); + } + lpSelectData = NULL; + + /* Free allocated events/handle set array */ +#ifdef DBUG + dbug_print("Free local allocated resources"); +#endif + if (!HeapLock(GetProcessHeap())) + { + win32_maperr(GetLastError()); + uerror("select", Nothing); + } + HeapFree(GetProcessHeap(), 0, lpEventsDone); + HeapFree(GetProcessHeap(), 0, hdsData); + HeapUnlock(GetProcessHeap()); + +#ifdef DBUG + dbug_print("Raise error if required"); +#endif + if (err != 0) + { + win32_maperr(err); + uerror("select", Nothing); + } + +#ifdef DBUG + dbug_print("Build final result"); +#endif + res = alloc_small(3, 0); + Store_field(res, 0, read_list); + Store_field(res, 1, write_list); + Store_field(res, 2, except_list); + +#ifdef DBUG + dbug_print("out select"); +#endif + + CAMLreturn(res); +} diff --git a/otherlibs/win32unix/sendrecv.c b/otherlibs/win32unix/sendrecv.c new file mode 100644 index 0000000..0b6f1b0 --- /dev/null +++ b/otherlibs/win32unix/sendrecv.c @@ -0,0 +1,141 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sendrecv.c,v 1.21 2006-10-18 08:26:54 xleroy Exp $ */ + +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" +#include "socketaddr.h" + +static int msg_flag_table[] = { + MSG_OOB, MSG_DONTROUTE, MSG_PEEK +}; + +CAMLprim value unix_recv(value sock, value buff, value ofs, value len, value flags) +{ + SOCKET s = Socket_val(sock); + int flg = convert_flag_list(flags, msg_flag_table); + int ret; + intnat numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + DWORD err = 0; + + Begin_root (buff); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + enter_blocking_section(); + ret = recv(s, iobuf, (int) numbytes, flg); + if (ret == -1) err = WSAGetLastError(); + leave_blocking_section(); + if (ret == -1) { + win32_maperr(err); + uerror("recv", Nothing); + } + memmove (&Byte(buff, Long_val(ofs)), iobuf, ret); + End_roots(); + return Val_int(ret); +} + +CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len, value flags) +{ + SOCKET s = Socket_val(sock); + int flg = convert_flag_list(flags, msg_flag_table); + int ret; + intnat numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + value res; + value adr = Val_unit; + union sock_addr_union addr; + socklen_param_type addr_len; + DWORD err = 0; + + Begin_roots2 (buff, adr); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + addr_len = sizeof(sock_addr); + enter_blocking_section(); + ret = recvfrom(s, iobuf, (int) numbytes, flg, &addr.s_gen, &addr_len); + if (ret == -1) err = WSAGetLastError(); + leave_blocking_section(); + if (ret == -1) { + win32_maperr(err); + uerror("recvfrom", Nothing); + } + memmove (&Byte(buff, Long_val(ofs)), iobuf, ret); + adr = alloc_sockaddr(&addr, addr_len, -1); + res = alloc_small(2, 0); + Field(res, 0) = Val_int(ret); + Field(res, 1) = adr; + End_roots(); + return res; +} + +CAMLprim value unix_send(value sock, value buff, value ofs, value len, value flags) +{ + SOCKET s = Socket_val(sock); + int flg = convert_flag_list(flags, msg_flag_table); + int ret; + intnat numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + DWORD err = 0; + + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes); + enter_blocking_section(); + ret = send(s, iobuf, (int) numbytes, flg); + if (ret == -1) err = WSAGetLastError(); + leave_blocking_section(); + if (ret == -1) { + win32_maperr(err); + uerror("send", Nothing); + } + return Val_int(ret); +} + +value unix_sendto_native(value sock, value buff, value ofs, value len, value flags, value dest) +{ + SOCKET s = Socket_val(sock); + int flg = convert_flag_list(flags, msg_flag_table); + int ret; + intnat numbytes; + char iobuf[UNIX_BUFFER_SIZE]; + union sock_addr_union addr; + socklen_param_type addr_len; + DWORD err = 0; + + get_sockaddr(dest, &addr, &addr_len); + numbytes = Long_val(len); + if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE; + memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes); + enter_blocking_section(); + ret = sendto(s, iobuf, (int) numbytes, flg, &addr.s_gen, addr_len); + if (ret == -1) err = WSAGetLastError(); + leave_blocking_section(); + if (ret == -1) { + win32_maperr(err); + uerror("sendto", Nothing); + } + return Val_int(ret); +} + +CAMLprim value unix_sendto(argv, argc) + value * argv; + int argc; +{ + return unix_sendto_native + (argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); +} diff --git a/otherlibs/win32unix/shutdown.c b/otherlibs/win32unix/shutdown.c new file mode 100644 index 0000000..19eb9da --- /dev/null +++ b/otherlibs/win32unix/shutdown.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: shutdown.c,v 1.9 2002-04-30 15:00:47 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +static int shutdown_command_table[] = { + 0, 1, 2 +}; + +CAMLprim value unix_shutdown(sock, cmd) + value sock, cmd; +{ + if (shutdown(Socket_val(sock), + shutdown_command_table[Int_val(cmd)]) == -1) { + win32_maperr(WSAGetLastError()); + uerror("shutdown", Nothing); + } + return Val_unit; +} diff --git a/otherlibs/win32unix/sleep.c b/otherlibs/win32unix/sleep.c new file mode 100644 index 0000000..b0fdabf --- /dev/null +++ b/otherlibs/win32unix/sleep.c @@ -0,0 +1,27 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sleep.c,v 1.5 2002-06-07 09:49:41 xleroy Exp $ */ + +#include <mlvalues.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_sleep(t) + value t; +{ + enter_blocking_section(); + Sleep(Int_val(t) * 1000); + leave_blocking_section(); + return Val_unit; +} diff --git a/otherlibs/win32unix/socket.c b/otherlibs/win32unix/socket.c new file mode 100644 index 0000000..70c948a --- /dev/null +++ b/otherlibs/win32unix/socket.c @@ -0,0 +1,55 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socket.c,v 1.12 2002-04-30 15:00:47 xleroy Exp $ */ + +#include <mlvalues.h> +#include "unixsupport.h" + +int socket_domain_table[] = { + PF_UNIX, PF_INET +}; + +int socket_type_table[] = { + SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET +}; + +CAMLprim value unix_socket(domain, type, proto) + value domain, type, proto; +{ + SOCKET s; + int oldvalue, oldvaluelen, newvalue, retcode; + + oldvaluelen = sizeof(oldvalue); + retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, &oldvaluelen); + if (retcode == 0) { + /* Set sockets to synchronous mode */ + newvalue = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &newvalue, sizeof(newvalue)); + } + s = socket(socket_domain_table[Int_val(domain)], + socket_type_table[Int_val(type)], + Int_val(proto)); + if (retcode == 0) { + /* Restore initial mode */ + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, + (char *) &oldvalue, oldvaluelen); + } + if (s == INVALID_SOCKET) { + win32_maperr(WSAGetLastError()); + uerror("socket", Nothing); + } + return win_alloc_socket(s); +} diff --git a/otherlibs/win32unix/socketaddr.h b/otherlibs/win32unix/socketaddr.h new file mode 100644 index 0000000..2293156 --- /dev/null +++ b/otherlibs/win32unix/socketaddr.h @@ -0,0 +1,37 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: socketaddr.h,v 1.8 2005-03-24 17:20:53 doligez Exp $ */ + +#include <misc.h> + +union sock_addr_union { + struct sockaddr s_gen; + struct sockaddr_in s_inet; +}; + +extern union sock_addr_union sock_addr; + +#ifdef HAS_SOCKLEN_T +typedef socklen_t socklen_param_type; +#else +typedef int socklen_param_type; +#endif + +extern void get_sockaddr (value mladdr, + union sock_addr_union * addr /*out*/, + socklen_param_type * addr_len /*out*/); +CAMLprim value alloc_sockaddr (union sock_addr_union * addr /*in*/, + socklen_param_type addr_len, int close_on_error); +CAMLprim value alloc_inet_addr (struct in_addr * inaddr); +#define GET_INET_ADDR(v) (*((struct in_addr *) (v))) diff --git a/otherlibs/win32unix/sockopt.c b/otherlibs/win32unix/sockopt.c new file mode 100644 index 0000000..696a014 --- /dev/null +++ b/otherlibs/win32unix/sockopt.c @@ -0,0 +1,229 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: sockopt.c,v 1.19 2008-08-01 13:46:08 xleroy Exp $ */ + +#include <errno.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" +#include "socketaddr.h" + +#ifndef IPPROTO_IPV6 +#define IPPROTO_IPV6 (-1) +#endif +#ifndef IPV6_V6ONLY +#define IPV6_V6ONLY (-1) +#endif + +enum option_type { + TYPE_BOOL = 0, + TYPE_INT = 1, + TYPE_LINGER = 2, + TYPE_TIMEVAL = 3, + TYPE_UNIX_ERROR = 4 +}; + +struct socket_option { + int level; + int option; +}; + +/* Table of options, indexed by type */ + +static struct socket_option sockopt_bool[] = { + { SOL_SOCKET, SO_DEBUG }, + { SOL_SOCKET, SO_BROADCAST }, + { SOL_SOCKET, SO_REUSEADDR }, + { SOL_SOCKET, SO_KEEPALIVE }, + { SOL_SOCKET, SO_DONTROUTE }, + { SOL_SOCKET, SO_OOBINLINE }, + { SOL_SOCKET, SO_ACCEPTCONN }, + { IPPROTO_TCP, TCP_NODELAY }, + { IPPROTO_IPV6, IPV6_V6ONLY} +}; + +static struct socket_option sockopt_int[] = { + { SOL_SOCKET, SO_SNDBUF }, + { SOL_SOCKET, SO_RCVBUF }, + { SOL_SOCKET, SO_ERROR }, + { SOL_SOCKET, SO_TYPE }, + { SOL_SOCKET, SO_RCVLOWAT }, + { SOL_SOCKET, SO_SNDLOWAT } }; + +static struct socket_option sockopt_linger[] = { + { SOL_SOCKET, SO_LINGER } +}; + +static struct socket_option sockopt_timeval[] = { + { SOL_SOCKET, SO_RCVTIMEO }, + { SOL_SOCKET, SO_SNDTIMEO } +}; + +static struct socket_option sockopt_unix_error[] = { + { SOL_SOCKET, SO_ERROR } +}; + +static struct socket_option * sockopt_table[] = { + sockopt_bool, + sockopt_int, + sockopt_linger, + sockopt_timeval, + sockopt_unix_error +}; + +static char * getsockopt_fun_name[] = { + "getsockopt", + "getsockopt_int", + "getsockopt_optint", + "getsockopt_float", + "getsockopt_error" +}; + +static char * setsockopt_fun_name[] = { + "setsockopt", + "setsockopt_int", + "setsockopt_optint", + "setsockopt_float", + "setsockopt_error" +}; + +union option_value { + int i; + struct linger lg; + struct timeval tv; +}; + +CAMLexport value +unix_getsockopt_aux(char * name, + enum option_type ty, int level, int option, + value socket) +{ + union option_value optval; + socklen_param_type optsize; + + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + case TYPE_UNIX_ERROR: + optsize = sizeof(optval.i); break; + case TYPE_LINGER: + optsize = sizeof(optval.lg); break; + case TYPE_TIMEVAL: + optsize = sizeof(optval.tv); break; + default: + unix_error(EINVAL, name, Nothing); + } + + if (getsockopt(Socket_val(socket), level, option, + (void *) &optval, &optsize) == -1) + uerror(name, Nothing); + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + return Val_int(optval.i); + case TYPE_LINGER: + if (optval.lg.l_onoff == 0) { + return Val_int(0); /* None */ + } else { + value res = alloc_small(1, 0); /* Some */ + Field(res, 0) = Val_int(optval.lg.l_linger); + return res; + } + case TYPE_TIMEVAL: + return copy_double((double) optval.tv.tv_sec + + (double) optval.tv.tv_usec / 1e6); + case TYPE_UNIX_ERROR: + if (optval.i == 0) { + return Val_int(0); /* None */ + } else { + value err, res; + err = unix_error_of_code(optval.i); + Begin_root(err); + res = alloc_small(1, 0); /* Some */ + Field(res, 0) = err; + End_roots(); + return res; + } + default: + unix_error(EINVAL, name, Nothing); + return Val_unit; /* Avoid warning */ + } +} + +CAMLexport value +unix_setsockopt_aux(char * name, + enum option_type ty, int level, int option, + value socket, value val) +{ + union option_value optval; + socklen_param_type optsize; + double f; + + switch (ty) { + case TYPE_BOOL: + case TYPE_INT: + optsize = sizeof(optval.i); + optval.i = Int_val(val); + break; + case TYPE_LINGER: + optsize = sizeof(optval.lg); + optval.lg.l_onoff = Is_block (val); + if (optval.lg.l_onoff) + optval.lg.l_linger = Int_val (Field (val, 0)); + break; + case TYPE_TIMEVAL: + f = Double_val(val); + optsize = sizeof(optval.tv); + optval.tv.tv_sec = (int) f; + optval.tv.tv_usec = (int) (1e6 * (f - optval.tv.tv_sec)); + break; + case TYPE_UNIX_ERROR: + default: + unix_error(EINVAL, name, Nothing); + } + + if (setsockopt(Socket_val(socket), level, option, + (void *) &optval, optsize) == -1) + uerror(name, Nothing); + + return Val_unit; +} + +CAMLprim value unix_getsockopt(value vty, value vsocket, value voption) +{ + enum option_type ty = Int_val(vty); + struct socket_option * opt = &(sockopt_table[ty][Int_val(voption)]); + return unix_getsockopt_aux(getsockopt_fun_name[ty], + ty, + opt->level, + opt->option, + vsocket); +} + +CAMLprim value unix_setsockopt(value vty, value vsocket, value voption, + value val) +{ + enum option_type ty = Int_val(vty); + struct socket_option * opt = &(sockopt_table[ty][Int_val(voption)]); + return unix_setsockopt_aux(setsockopt_fun_name[ty], + ty, + opt->level, + opt->option, + vsocket, + val); +} diff --git a/otherlibs/win32unix/startup.c b/otherlibs/win32unix/startup.c new file mode 100644 index 0000000..bbf5fe1 --- /dev/null +++ b/otherlibs/win32unix/startup.c @@ -0,0 +1,54 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +#include <stdio.h> +#include <fcntl.h> +#include <stdlib.h> +#include <mlvalues.h> +#include "unixsupport.h" +#include "winworker.h" +#include "windbug.h" + +value val_process_id; + +CAMLprim value win_startup(unit) + value unit; +{ + WSADATA wsaData; + int i; + HANDLE h; + + DBUG_INIT; + + (void) WSAStartup(MAKEWORD(2, 0), &wsaData); + DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(), + GetCurrentProcess(), &h, 0, TRUE, + DUPLICATE_SAME_ACCESS); + val_process_id = Val_int(h); + + worker_init(); + + return Val_unit; +} + +CAMLprim value win_cleanup(unit) + value unit; +{ + worker_cleanup(); + + (void) WSACleanup(); + + DBUG_CLEANUP; + + return Val_unit; +} diff --git a/otherlibs/win32unix/stat.c b/otherlibs/win32unix/stat.c new file mode 100644 index 0000000..02ebf3f --- /dev/null +++ b/otherlibs/win32unix/stat.c @@ -0,0 +1,115 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: stat.c,v 1.3 2006-09-21 13:57:34 xleroy Exp $ */ + +#include <errno.h> +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include "unixsupport.h" +#include "cst2constr.h" +#define _INTEGRAL_MAX_BITS 64 +#include <sys/types.h> +#include <sys/stat.h> + +#ifndef S_IFLNK +#define S_IFLNK 0 +#endif +#ifndef S_IFIFO +#define S_IFIFO 0 +#endif +#ifndef S_IFSOCK +#define S_IFSOCK 0 +#endif +#ifndef S_IFBLK +#define S_IFBLK 0 +#endif + +static int file_kind_table[] = { + S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFLNK, S_IFIFO, S_IFSOCK +}; + +static value stat_aux(int use_64, struct _stati64 *buf) +{ + CAMLparam0 (); + CAMLlocal1 (v); + + v = caml_alloc (12, 0); + Store_field (v, 0, Val_int (buf->st_dev)); + Store_field (v, 1, Val_int (buf->st_ino)); + Store_field (v, 2, cst_to_constr (buf->st_mode & S_IFMT, file_kind_table, + sizeof(file_kind_table) / sizeof(int), 0)); + Store_field (v, 3, Val_int(buf->st_mode & 07777)); + Store_field (v, 4, Val_int (buf->st_nlink)); + Store_field (v, 5, Val_int (buf->st_uid)); + Store_field (v, 6, Val_int (buf->st_gid)); + Store_field (v, 7, Val_int (buf->st_rdev)); + Store_field (v, 8, + use_64 ? copy_int64(buf->st_size) : Val_int (buf->st_size)); + Store_field (v, 9, copy_double((double) buf->st_atime)); + Store_field (v, 10, copy_double((double) buf->st_mtime)); + Store_field (v, 11, copy_double((double) buf->st_ctime)); + CAMLreturn (v); +} + +CAMLprim value unix_stat(value path) +{ + int ret; + struct _stati64 buf; + + ret = _stati64(String_val(path), &buf); + if (ret == -1) uerror("stat", path); + if (buf.st_size > Max_long) { + win32_maperr(ERROR_ARITHMETIC_OVERFLOW); + uerror("stat", path); + } + return stat_aux(0, &buf); +} + +CAMLprim value unix_stat_64(value path) +{ + int ret; + struct _stati64 buf; + ret = _stati64(String_val(path), &buf); + if (ret == -1) uerror("stat", path); + return stat_aux(1, &buf); +} + +CAMLprim value unix_fstat(value handle) +{ + int ret; + struct _stati64 buf; + + ret = _fstati64(win_CRT_fd_of_filedescr(handle), &buf); + if (ret == -1) uerror("fstat", Nothing); + if (buf.st_size > Max_long) { + win32_maperr(ERROR_ARITHMETIC_OVERFLOW); + uerror("fstat", Nothing); + } + return stat_aux(0, &buf); +} + +CAMLprim value unix_fstat_64(value handle) +{ + int ret; + struct _stati64 buf; + + ret = _fstati64(win_CRT_fd_of_filedescr(handle), &buf); + if (ret == -1) uerror("fstat", Nothing); + if (buf.st_size > Max_long) { + win32_maperr(ERROR_ARITHMETIC_OVERFLOW); + uerror("fstat", Nothing); + } + return stat_aux(1, &buf); +} diff --git a/otherlibs/win32unix/system.c b/otherlibs/win32unix/system.c new file mode 100644 index 0000000..42d3cad --- /dev/null +++ b/otherlibs/win32unix/system.c @@ -0,0 +1,47 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: system.c,v 1.9 2006-09-21 08:03:56 xleroy Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include <alloc.h> +#include <signals.h> +#include "unixsupport.h" +#include <process.h> +#include <stdio.h> + +CAMLprim value win_system(cmd) + value cmd; +{ + int ret; + value st; + char *buf; + intnat len; + + len = caml_string_length (cmd); + buf = caml_stat_alloc (len + 1); + memmove (buf, String_val (cmd), len + 1); + enter_blocking_section(); + _flushall(); + ret = system(buf); + leave_blocking_section(); + caml_stat_free(buf); + if (ret == -1) uerror("system", Nothing); + st = alloc_small(1, 0); /* Tag 0: Exited */ + Field(st, 0) = Val_int(ret); + return st; +} + + + diff --git a/otherlibs/win32unix/unix.ml b/otherlibs/win32unix/unix.ml new file mode 100644 index 0000000..17694fb --- /dev/null +++ b/otherlibs/win32unix/unix.ml @@ -0,0 +1,943 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: unix.ml,v 1.48 2008-08-01 13:46:08 xleroy Exp $ *) + +(* Initialization *) + +external startup: unit -> unit = "win_startup" +external cleanup: unit -> unit = "win_cleanup" + +let _ = startup(); at_exit cleanup + +(* Errors *) + +type error = + (* Errors defined in the POSIX standard *) + E2BIG (* Argument list too long *) + | EACCES (* Permission denied *) + | EAGAIN (* Resource temporarily unavailable; try again *) + | EBADF (* Bad file descriptor *) + | EBUSY (* Resource unavailable *) + | ECHILD (* No child process *) + | EDEADLK (* Resource deadlock would occur *) + | EDOM (* Domain error for math functions, etc. *) + | EEXIST (* File exists *) + | EFAULT (* Bad address *) + | EFBIG (* File too large *) + | EINTR (* Function interrupted by signal *) + | EINVAL (* Invalid argument *) + | EIO (* Hardware I/O error *) + | EISDIR (* Is a directory *) + | EMFILE (* Too many open files by the process *) + | EMLINK (* Too many links *) + | ENAMETOOLONG (* Filename too long *) + | ENFILE (* Too many open files in the system *) + | ENODEV (* No such device *) + | ENOENT (* No such file or directory *) + | ENOEXEC (* Not an executable file *) + | ENOLCK (* No locks available *) + | ENOMEM (* Not enough memory *) + | ENOSPC (* No space left on device *) + | ENOSYS (* Function not supported *) + | ENOTDIR (* Not a directory *) + | ENOTEMPTY (* Directory not empty *) + | ENOTTY (* Inappropriate I/O control operation *) + | ENXIO (* No such device or address *) + | EPERM (* Operation not permitted *) + | EPIPE (* Broken pipe *) + | ERANGE (* Result too large *) + | EROFS (* Read-only file system *) + | ESPIPE (* Invalid seek e.g. on a pipe *) + | ESRCH (* No such process *) + | EXDEV (* Invalid link *) + (* Additional errors, mostly BSD *) + | EWOULDBLOCK (* Operation would block *) + | EINPROGRESS (* Operation now in progress *) + | EALREADY (* Operation already in progress *) + | ENOTSOCK (* Socket operation on non-socket *) + | EDESTADDRREQ (* Destination address required *) + | EMSGSIZE (* Message too long *) + | EPROTOTYPE (* Protocol wrong type for socket *) + | ENOPROTOOPT (* Protocol not available *) + | EPROTONOSUPPORT (* Protocol not supported *) + | ESOCKTNOSUPPORT (* Socket type not supported *) + | EOPNOTSUPP (* Operation not supported on socket *) + | EPFNOSUPPORT (* Protocol family not supported *) + | EAFNOSUPPORT (* Address family not supported by protocol family *) + | EADDRINUSE (* Address already in use *) + | EADDRNOTAVAIL (* Can't assign requested address *) + | ENETDOWN (* Network is down *) + | ENETUNREACH (* Network is unreachable *) + | ENETRESET (* Network dropped connection on reset *) + | ECONNABORTED (* Software caused connection abort *) + | ECONNRESET (* Connection reset by peer *) + | ENOBUFS (* No buffer space available *) + | EISCONN (* Socket is already connected *) + | ENOTCONN (* Socket is not connected *) + | ESHUTDOWN (* Can't send after socket shutdown *) + | ETOOMANYREFS (* Too many references: can't splice *) + | ETIMEDOUT (* Connection timed out *) + | ECONNREFUSED (* Connection refused *) + | EHOSTDOWN (* Host is down *) + | EHOSTUNREACH (* No route to host *) + | ELOOP (* Too many levels of symbolic links *) + | EOVERFLOW + (* All other errors are mapped to EUNKNOWNERR *) + | EUNKNOWNERR of int (* Unknown error *) + +exception Unix_error of error * string * string + +let _ = Callback.register_exception "Unix.Unix_error" + (Unix_error(E2BIG, "", "")) + +external error_message : error -> string = "unix_error_message" + +let handle_unix_error f arg = + try + f arg + with Unix_error(err, fun_name, arg) -> + prerr_string Sys.argv.(0); + prerr_string ": \""; + prerr_string fun_name; + prerr_string "\" failed"; + if String.length arg > 0 then begin + prerr_string " on \""; + prerr_string arg; + prerr_string "\"" + end; + prerr_string ": "; + prerr_endline (error_message err); + exit 2 + +external environment : unit -> string array = "unix_environment" +external getenv: string -> string = "caml_sys_getenv" +external putenv: string -> string -> unit = "unix_putenv" + +type process_status = + WEXITED of int + | WSIGNALED of int + | WSTOPPED of int + +type wait_flag = + WNOHANG + | WUNTRACED + +type file_descr + +external execv : string -> string array -> 'a = "unix_execv" +external execve : string -> string array -> string array -> 'a = "unix_execve" +external execvp : string -> string array -> 'a = "unix_execvp" +external execvpe : string -> string array -> string array -> 'a = "unix_execvpe" + +external waitpid : wait_flag list -> int -> int * process_status + = "win_waitpid" +external getpid : unit -> int = "unix_getpid" + +let fork () = invalid_arg "Unix.fork not implemented" +let wait () = invalid_arg "Unix.wait not implemented" +let getppid () = invalid_arg "Unix.getppid not implemented" +let nice prio = invalid_arg "Unix.nice not implemented" + +(* Basic file input/output *) + +external filedescr_of_fd : int -> file_descr = "win_handle_fd" + +let stdin = filedescr_of_fd 0 +let stdout = filedescr_of_fd 1 +let stderr = filedescr_of_fd 2 + +type open_flag = + O_RDONLY + | O_WRONLY + | O_RDWR + | O_NONBLOCK + | O_APPEND + | O_CREAT + | O_TRUNC + | O_EXCL + | O_NOCTTY + | O_DSYNC + | O_SYNC + | O_RSYNC + +type file_perm = int + +external openfile : string -> open_flag list -> file_perm -> file_descr + = "unix_open" +external close : file_descr -> unit = "unix_close" +external unsafe_read : file_descr -> string -> int -> int -> int + = "unix_read" +external unsafe_write : file_descr -> string -> int -> int -> int + = "unix_write" +external unsafe_single_write : file_descr -> string -> int -> int -> int + = "unix_single_write" + +let read fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.read" + else unsafe_read fd buf ofs len +let write fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.write" + else unsafe_write fd buf ofs len +let single_write fd buf ofs len = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.single_write" + else unsafe_single_write fd buf ofs len + +(* Interfacing with the standard input/output library *) + +external in_channel_of_descr: file_descr -> in_channel = "win_inchannel_of_filedescr" +external out_channel_of_descr: file_descr -> out_channel = "win_outchannel_of_filedescr" +external descr_of_in_channel : in_channel -> file_descr = "win_filedescr_of_channel" +external descr_of_out_channel : out_channel -> file_descr = "win_filedescr_of_channel" + +(* Seeking and truncating *) + +type seek_command = + SEEK_SET + | SEEK_CUR + | SEEK_END + +external lseek : file_descr -> int -> seek_command -> int = "unix_lseek" + +let truncate name len = invalid_arg "Unix.truncate not implemented" +let ftruncate fd len = invalid_arg "Unix.ftruncate not implemented" + +(* File statistics *) + +type file_kind = + S_REG + | S_DIR + | S_CHR + | S_BLK + | S_LNK + | S_FIFO + | S_SOCK + +type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int; + st_atime : float; + st_mtime : float; + st_ctime : float } + +external stat : string -> stats = "unix_stat" +let lstat = stat +external fstat : file_descr -> stats = "unix_fstat" +let isatty fd = + match (fstat fd).st_kind with S_CHR -> true | _ -> false + +(* Operations on file names *) + +external unlink : string -> unit = "unix_unlink" +external rename : string -> string -> unit = "unix_rename" +external link : string -> string -> unit = "unix_link" + +(* Operations on large files *) + +module LargeFile = + struct + external lseek : file_descr -> int64 -> seek_command -> int64 = "unix_lseek_64" + let truncate name len = invalid_arg "Unix.LargeFile.truncate not implemented" + let ftruncate name len = invalid_arg "Unix.LargeFile.ftruncate not implemented" + type stats = + { st_dev : int; + st_ino : int; + st_kind : file_kind; + st_perm : file_perm; + st_nlink : int; + st_uid : int; + st_gid : int; + st_rdev : int; + st_size : int64; + st_atime : float; + st_mtime : float; + st_ctime : float; + } + external stat : string -> stats = "unix_stat_64" + let lstat = stat + external fstat : file_descr -> stats = "unix_fstat_64" + end + +(* File permissions and ownership *) + +type access_permission = + R_OK + | W_OK + | X_OK + | F_OK + +external chmod : string -> file_perm -> unit = "unix_chmod" +let fchmod fd perm = invalid_arg "Unix.fchmod not implemented" +let chown file perm = invalid_arg "Unix.chown not implemented" +let fchown fd perm = invalid_arg "Unix.fchown not implemented" +let umask msk = invalid_arg "Unix.umask not implemented" + +external access : string -> access_permission list -> unit = "unix_access" + +(* Operations on file descriptors *) + +external dup : file_descr -> file_descr = "unix_dup" +external dup2 : file_descr -> file_descr -> unit = "unix_dup2" + +external set_nonblock : file_descr -> unit = "unix_set_nonblock" +external clear_nonblock : file_descr -> unit = "unix_clear_nonblock" + +external set_close_on_exec : file_descr -> unit = "win_set_close_on_exec" +external clear_close_on_exec : file_descr -> unit = "win_clear_close_on_exec" + +(* Directories *) + +external mkdir : string -> file_perm -> unit = "unix_mkdir" +external rmdir : string -> unit = "unix_rmdir" +external chdir : string -> unit = "unix_chdir" +external getcwd : unit -> string = "unix_getcwd" +let chroot _ = invalid_arg "Unix.chroot not implemented" + +type dir_entry = + Dir_empty + | Dir_read of string + | Dir_toread + +type dir_handle = + { dirname: string; mutable handle: int; mutable entry_read: dir_entry } + +external findfirst : string -> string * int = "win_findfirst" +external findnext : int -> string= "win_findnext" + +let opendir dirname = + try + let (first_entry, handle) = findfirst (Filename.concat dirname "*.*") in + { dirname = dirname; handle = handle; entry_read = Dir_read first_entry } + with End_of_file -> + { dirname = dirname; handle = 0; entry_read = Dir_empty } + +let readdir d = + match d.entry_read with + Dir_empty -> raise End_of_file + | Dir_read name -> d.entry_read <- Dir_toread; name + | Dir_toread -> findnext d.handle + +external win_findclose : int -> unit = "win_findclose" + +let closedir d = + match d.entry_read with + Dir_empty -> () + | _ -> win_findclose d.handle + +let rewinddir d = + closedir d; + try + let (first_entry, handle) = findfirst (d.dirname ^ "\\*.*") in + d.handle <- handle; d.entry_read <- Dir_read first_entry + with End_of_file -> + d.handle <- 0; d.entry_read <- Dir_empty + +(* Pipes *) + +external pipe : unit -> file_descr * file_descr = "unix_pipe" + +let mkfifo name perm = invalid_arg "Unix.mkfifo not implemented" + +(* Symbolic links *) + +let readlink path = invalid_arg "Unix.readlink not implemented" +let symlink path1 path2 = invalid_arg "Unix.symlink not implemented" + +(* Locking *) + +type lock_command = + F_ULOCK + | F_LOCK + | F_TLOCK + | F_TEST + | F_RLOCK + | F_TRLOCK + +external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf" +let kill pid signo = invalid_arg "Unix.kill not implemented" +type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK +let sigprocmask cmd sigs = invalid_arg "Unix.sigprocmask not implemented" +let sigpending () = invalid_arg "Unix.sigpending not implemented" +let sigsuspend sigs = invalid_arg "Unix.sigsuspend not implemented" +let pause () = invalid_arg "Unix.pause not implemented" + +(* Time functions *) + +type process_times = + { tms_utime : float; + tms_stime : float; + tms_cutime : float; + tms_cstime : float } + +type tm = + { tm_sec : int; + tm_min : int; + tm_hour : int; + tm_mday : int; + tm_mon : int; + tm_year : int; + tm_wday : int; + tm_yday : int; + tm_isdst : bool } + +external time : unit -> float = "unix_time" +external gettimeofday : unit -> float = "unix_gettimeofday" +external gmtime : float -> tm = "unix_gmtime" +external localtime : float -> tm = "unix_localtime" +external mktime : tm -> float * tm = "unix_mktime" +let alarm n = invalid_arg "Unix.alarm not implemented" +external sleep : int -> unit = "unix_sleep" +let times () = + { tms_utime = Sys.time(); tms_stime = 0.0; + tms_cutime = 0.0; tms_cstime = 0.0 } +external utimes : string -> float -> float -> unit = "unix_utimes" + +type interval_timer = + ITIMER_REAL + | ITIMER_VIRTUAL + | ITIMER_PROF + +type interval_timer_status = + { it_interval: float; + it_value: float } + +let getitimer it = invalid_arg "Unix.getitimer not implemented" +let setitimer it tm = invalid_arg "Unix.setitimer not implemented" + +(* User id, group id *) + +let getuid () = 1 +let geteuid = getuid +let setuid id = invalid_arg "Unix.setuid not implemented" + +let getgid () = 1 +let getegid = getgid +let setgid id = invalid_arg "Unix.setgid not implemented" + +let getgroups () = [|1|] + +type passwd_entry = + { pw_name : string; + pw_passwd : string; + pw_uid : int; + pw_gid : int; + pw_gecos : string; + pw_dir : string; + pw_shell : string } + +type group_entry = + { gr_name : string; + gr_passwd : string; + gr_gid : int; + gr_mem : string array } + +let getlogin () = try Sys.getenv "USERNAME" with Not_found -> "" +let getpwnam x = raise Not_found +let getgrnam = getpwnam +let getpwuid = getpwnam +let getgrgid = getpwnam + +(* Internet addresses *) + +type inet_addr = string + +let is_inet6_addr s = String.length s = 16 + +external inet_addr_of_string : string -> inet_addr + = "unix_inet_addr_of_string" +external string_of_inet_addr : inet_addr -> string + = "unix_string_of_inet_addr" + +let inet_addr_any = inet_addr_of_string "0.0.0.0" +let inet_addr_loopback = inet_addr_of_string "127.0.0.1" +let inet6_addr_any = + try inet_addr_of_string "::" with Failure _ -> inet_addr_any +let inet6_addr_loopback = + try inet_addr_of_string "::1" with Failure _ -> inet_addr_loopback + +(* Sockets *) + +type socket_domain = + PF_UNIX + | PF_INET + | PF_INET6 + +type socket_type = + SOCK_STREAM + | SOCK_DGRAM + | SOCK_RAW + | SOCK_SEQPACKET + +type sockaddr = + ADDR_UNIX of string + | ADDR_INET of inet_addr * int + +let domain_of_sockaddr = function + ADDR_UNIX _ -> PF_UNIX + | ADDR_INET(a, _) -> if is_inet6_addr a then PF_INET6 else PF_INET + +type shutdown_command = + SHUTDOWN_RECEIVE + | SHUTDOWN_SEND + | SHUTDOWN_ALL + +type msg_flag = + MSG_OOB + | MSG_DONTROUTE + | MSG_PEEK + +external socket : socket_domain -> socket_type -> int -> file_descr + = "unix_socket" +let socketpair dom ty proto = invalid_arg "Unix.socketpair not implemented" +external accept : file_descr -> file_descr * sockaddr = "unix_accept" +external bind : file_descr -> sockaddr -> unit = "unix_bind" +external connect : file_descr -> sockaddr -> unit = "unix_connect" +external listen : file_descr -> int -> unit = "unix_listen" +external shutdown : file_descr -> shutdown_command -> unit = "unix_shutdown" +external getsockname : file_descr -> sockaddr = "unix_getsockname" +external getpeername : file_descr -> sockaddr = "unix_getpeername" + +external unsafe_recv : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_recv" +external unsafe_recvfrom : + file_descr -> string -> int -> int -> msg_flag list -> int * sockaddr + = "unix_recvfrom" +external unsafe_send : + file_descr -> string -> int -> int -> msg_flag list -> int + = "unix_send" +external unsafe_sendto : + file_descr -> string -> int -> int -> msg_flag list -> sockaddr -> int + = "unix_sendto" "unix_sendto_native" + +let recv fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recv" + else unsafe_recv fd buf ofs len flags +let recvfrom fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.recvfrom" + else unsafe_recvfrom fd buf ofs len flags +let send fd buf ofs len flags = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.send" + else unsafe_send fd buf ofs len flags +let sendto fd buf ofs len flags addr = + if ofs < 0 || len < 0 || ofs > String.length buf - len + then invalid_arg "Unix.sendto" + else unsafe_sendto fd buf ofs len flags addr + +type socket_bool_option = + SO_DEBUG + | SO_BROADCAST + | SO_REUSEADDR + | SO_KEEPALIVE + | SO_DONTROUTE + | SO_OOBINLINE + | SO_ACCEPTCONN + | TCP_NODELAY + | IPV6_ONLY + +type socket_int_option = + SO_SNDBUF + | SO_RCVBUF + | SO_ERROR + | SO_TYPE + | SO_RCVLOWAT + | SO_SNDLOWAT + +type socket_optint_option = SO_LINGER + +type socket_float_option = + SO_RCVTIMEO + | SO_SNDTIMEO + +type socket_error_option = SO_ERROR + +module SO: sig + type ('opt, 'v) t + val bool: (socket_bool_option, bool) t + val int: (socket_int_option, int) t + val optint: (socket_optint_option, int option) t + val float: (socket_float_option, float) t + val error: (socket_error_option, error option) t + val get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + val set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit +end = struct + type ('opt, 'v) t = int + let bool = 0 + let int = 1 + let optint = 2 + let float = 3 + let error = 4 + external get: ('opt, 'v) t -> file_descr -> 'opt -> 'v + = "unix_getsockopt" + external set: ('opt, 'v) t -> file_descr -> 'opt -> 'v -> unit + = "unix_setsockopt" +end + +let getsockopt fd opt = SO.get SO.bool fd opt +let setsockopt fd opt v = SO.set SO.bool fd opt v + +let getsockopt_int fd opt = SO.get SO.int fd opt +let setsockopt_int fd opt v = SO.set SO.int fd opt v + +let getsockopt_optint fd opt = SO.get SO.optint fd opt +let setsockopt_optint fd opt v = SO.set SO.optint fd opt v + +let getsockopt_float fd opt = SO.get SO.float fd opt +let setsockopt_float fd opt v = SO.set SO.float fd opt v + +let getsockopt_error fd = SO.get SO.error fd SO_ERROR + +(* Host and protocol databases *) + +type host_entry = + { h_name : string; + h_aliases : string array; + h_addrtype : socket_domain; + h_addr_list : inet_addr array } + +type protocol_entry = + { p_name : string; + p_aliases : string array; + p_proto : int } + +type service_entry = + { s_name : string; + s_aliases : string array; + s_port : int; + s_proto : string } + +external gethostname : unit -> string = "unix_gethostname" +external gethostbyname : string -> host_entry = "unix_gethostbyname" +external gethostbyaddr : inet_addr -> host_entry = "unix_gethostbyaddr" +external getprotobyname : string -> protocol_entry + = "unix_getprotobyname" +external getprotobynumber : int -> protocol_entry + = "unix_getprotobynumber" + +external getservbyname : string -> string -> service_entry + = "unix_getservbyname" +external getservbyport : int -> string -> service_entry + = "unix_getservbyport" + +type addr_info = + { ai_family : socket_domain; + ai_socktype : socket_type; + ai_protocol : int; + ai_addr : sockaddr; + ai_canonname : string } + +type getaddrinfo_option = + AI_FAMILY of socket_domain + | AI_SOCKTYPE of socket_type + | AI_PROTOCOL of int + | AI_NUMERICHOST + | AI_CANONNAME + | AI_PASSIVE + +let getaddrinfo node service opts = + (* Parse options *) + let opt_socktype = ref None + and opt_protocol = ref 0 + and opt_passive = ref false in + List.iter + (function AI_SOCKTYPE s -> opt_socktype := Some s + | AI_PROTOCOL p -> opt_protocol := p + | AI_PASSIVE -> opt_passive := true + | _ -> ()) + opts; + (* Determine socket types and port numbers *) + let get_port ty kind = + if service = "" then [ty, 0] else + try + [ty, int_of_string service] + with Failure _ -> + try + [ty, (getservbyname service kind).s_port] + with Not_found -> [] + in + let ports = + match !opt_socktype with + | None -> + get_port SOCK_STREAM "tcp" @ get_port SOCK_DGRAM "udp" + | Some SOCK_STREAM -> + get_port SOCK_STREAM "tcp" + | Some SOCK_DGRAM -> + get_port SOCK_DGRAM "udp" + | Some ty -> + if service = "" then [ty, 0] else [] in + (* Determine IP addresses *) + let addresses = + if node = "" then + if List.mem AI_PASSIVE opts + then [inet_addr_any, "0.0.0.0"] + else [inet_addr_loopback, "127.0.0.1"] + else + try + [inet_addr_of_string node, node] + with Failure _ -> + try + let he = gethostbyname node in + List.map + (fun a -> (a, he.h_name)) + (Array.to_list he.h_addr_list) + with Not_found -> + [] in + (* Cross-product of addresses and ports *) + List.flatten + (List.map + (fun (ty, port) -> + List.map + (fun (addr, name) -> + { ai_family = PF_INET; + ai_socktype = ty; + ai_protocol = !opt_protocol; + ai_addr = ADDR_INET(addr, port); + ai_canonname = name }) + addresses) + ports) + +type name_info = + { ni_hostname : string; + ni_service : string } + +type getnameinfo_option = + NI_NOFQDN + | NI_NUMERICHOST + | NI_NAMEREQD + | NI_NUMERICSERV + | NI_DGRAM + +let getnameinfo addr opts = + match addr with + | ADDR_UNIX f -> + { ni_hostname = ""; ni_service = f } (* why not? *) + | ADDR_INET(a, p) -> + let hostname = + try + if List.mem NI_NUMERICHOST opts then raise Not_found; + (gethostbyaddr a).h_name + with Not_found -> + if List.mem NI_NAMEREQD opts then raise Not_found; + string_of_inet_addr a in + let service = + try + if List.mem NI_NUMERICSERV opts then raise Not_found; + let kind = if List.mem NI_DGRAM opts then "udp" else "tcp" in + (getservbyport p kind).s_name + with Not_found -> + string_of_int p in + { ni_hostname = hostname; ni_service = service } + +(* High-level process management (system, popen) *) + +external win_create_process : string -> string -> string option -> + file_descr -> file_descr -> file_descr -> int + = "win_create_process" "win_create_process_native" + +let make_cmdline args = + let maybe_quote f = + if String.contains f ' ' || String.contains f '\"' + then Filename.quote f + else f in + String.concat " " (List.map maybe_quote (Array.to_list args)) + +let create_process prog args fd1 fd2 fd3 = + win_create_process prog (make_cmdline args) None fd1 fd2 fd3 + +let create_process_env prog args env fd1 fd2 fd3 = + win_create_process prog (make_cmdline args) + (Some(String.concat "\000" (Array.to_list env) ^ "\000")) + fd1 fd2 fd3 + +external system: string -> process_status = "win_system" + +type popen_process = + Process of in_channel * out_channel + | Process_in of in_channel + | Process_out of out_channel + | Process_full of in_channel * out_channel * in_channel + +let popen_processes = (Hashtbl.create 7 : (popen_process, int) Hashtbl.t) + +let open_proc cmd optenv proc input output error = + let shell = + try Sys.getenv "COMSPEC" + with Not_found -> raise(Unix_error(ENOEXEC, "open_proc", cmd)) in + let pid = + win_create_process shell (shell ^ " /c " ^ cmd) optenv + input output error in + Hashtbl.add popen_processes proc pid + +let open_process_in cmd = + let (in_read, in_write) = pipe() in + set_close_on_exec in_read; + let inchan = in_channel_of_descr in_read in + open_proc cmd None (Process_in inchan) stdin in_write stderr; + close in_write; + inchan + +let open_process_out cmd = + let (out_read, out_write) = pipe() in + set_close_on_exec out_write; + let outchan = out_channel_of_descr out_write in + open_proc cmd None (Process_out outchan) out_read stdout stderr; + close out_read; + outchan + +let open_process cmd = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + set_close_on_exec in_read; + set_close_on_exec out_write; + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + open_proc cmd None (Process(inchan, outchan)) out_read in_write stderr; + close out_read; close in_write; + (inchan, outchan) + +let open_process_full cmd env = + let (in_read, in_write) = pipe() in + let (out_read, out_write) = pipe() in + let (err_read, err_write) = pipe() in + set_close_on_exec in_read; + set_close_on_exec out_write; + set_close_on_exec err_read; + let inchan = in_channel_of_descr in_read in + let outchan = out_channel_of_descr out_write in + let errchan = in_channel_of_descr err_read in + open_proc cmd (Some(String.concat "\000" (Array.to_list env) ^ "\000")) + (Process_full(inchan, outchan, errchan)) + out_read in_write err_write; + close out_read; close in_write; close err_write; + (inchan, outchan, errchan) + +let find_proc_id fun_name proc = + try + let pid = Hashtbl.find popen_processes proc in + Hashtbl.remove popen_processes proc; + pid + with Not_found -> + raise(Unix_error(EBADF, fun_name, "")) + +let close_process_in inchan = + let pid = find_proc_id "close_process_in" (Process_in inchan) in + close_in inchan; + snd(waitpid [] pid) + +let close_process_out outchan = + let pid = find_proc_id "close_process_out" (Process_out outchan) in + close_out outchan; + snd(waitpid [] pid) + +let close_process (inchan, outchan) = + let pid = find_proc_id "close_process" (Process(inchan, outchan)) in + close_in inchan; close_out outchan; + snd(waitpid [] pid) + +let close_process_full (inchan, outchan, errchan) = + let pid = + find_proc_id "close_process_full" + (Process_full(inchan, outchan, errchan)) in + close_in inchan; close_out outchan; close_in errchan; + snd(waitpid [] pid) + +(* Polling *) + +external select : + file_descr list -> file_descr list -> file_descr list -> float -> + file_descr list * file_descr list * file_descr list = "unix_select" + +(* High-level network functions *) + +let open_connection sockaddr = + let domain = + match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in + let sock = + socket domain SOCK_STREAM 0 in + connect sock sockaddr; + (in_channel_of_descr sock, out_channel_of_descr sock) + +let shutdown_connection inchan = + shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND + +let establish_server server_fun sockaddr = + invalid_arg "Unix.establish_server not implemented" + +(* Terminal interface *) + +type terminal_io = { + mutable c_ignbrk: bool; + mutable c_brkint: bool; + mutable c_ignpar: bool; + mutable c_parmrk: bool; + mutable c_inpck: bool; + mutable c_istrip: bool; + mutable c_inlcr: bool; + mutable c_igncr: bool; + mutable c_icrnl: bool; + mutable c_ixon: bool; + mutable c_ixoff: bool; + mutable c_opost: bool; + mutable c_obaud: int; + mutable c_ibaud: int; + mutable c_csize: int; + mutable c_cstopb: int; + mutable c_cread: bool; + mutable c_parenb: bool; + mutable c_parodd: bool; + mutable c_hupcl: bool; + mutable c_clocal: bool; + mutable c_isig: bool; + mutable c_icanon: bool; + mutable c_noflsh: bool; + mutable c_echo: bool; + mutable c_echoe: bool; + mutable c_echok: bool; + mutable c_echonl: bool; + mutable c_vintr: char; + mutable c_vquit: char; + mutable c_verase: char; + mutable c_vkill: char; + mutable c_veof: char; + mutable c_veol: char; + mutable c_vmin: int; + mutable c_vtime: int; + mutable c_vstart: char; + mutable c_vstop: char + } + +type setattr_when = TCSANOW | TCSADRAIN | TCSAFLUSH + +let tcgetattr fd = invalid_arg "Unix.tcgetattr not implemented" +let tcsetattr fd wh = invalid_arg "Unix.tcsetattr not implemented" +let tcsendbreak fd n = invalid_arg "Unix.tcsendbreak not implemented" +let tcdrain fd = invalid_arg "Unix.tcdrain not implemented" + +type flush_queue = TCIFLUSH | TCOFLUSH | TCIOFLUSH +let tcflush fd q = invalid_arg "Unix.tcflush not implemented" +type flow_action = TCOOFF | TCOON | TCIOFF | TCION +let tcflow fd fl = invalid_arg "Unix.tcflow not implemented" +let setsid () = invalid_arg "Unix.setsid not implemented" diff --git a/otherlibs/win32unix/unixsupport.c b/otherlibs/win32unix/unixsupport.c new file mode 100644 index 0000000..89fd372 --- /dev/null +++ b/otherlibs/win32unix/unixsupport.c @@ -0,0 +1,269 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unixsupport.c,v 1.21 2007-02-07 14:45:46 doligez Exp $ */ + +#include <stddef.h> +#include <mlvalues.h> +#include <callback.h> +#include <alloc.h> +#include <memory.h> +#include <fail.h> +#include <custom.h> +#include "unixsupport.h" +#include "cst2constr.h" +#include <errno.h> + +/* Heap-allocation of Windows file handles */ + +static int win_handle_compare(value v1, value v2) +{ + HANDLE h1 = Handle_val(v1); + HANDLE h2 = Handle_val(v2); + return h1 == h2 ? 0 : h1 < h2 ? -1 : 1; +} + +static intnat win_handle_hash(value v) +{ + return (intnat) Handle_val(v); +} + +static struct custom_operations win_handle_ops = { + "_handle", + custom_finalize_default, + win_handle_compare, + win_handle_hash, + custom_serialize_default, + custom_deserialize_default +}; + +value win_alloc_handle(HANDLE h) +{ + value res = alloc_custom(&win_handle_ops, sizeof(struct filedescr), 0, 1); + Handle_val(res) = h; + Descr_kind_val(res) = KIND_HANDLE; + CRT_fd_val(res) = NO_CRT_FD; + return res; +} + +value win_alloc_socket(SOCKET s) +{ + value res = alloc_custom(&win_handle_ops, sizeof(struct filedescr), 0, 1); + Socket_val(res) = s; + Descr_kind_val(res) = KIND_SOCKET; + CRT_fd_val(res) = NO_CRT_FD; + return res; +} + +value win_alloc_handle_or_socket(HANDLE h) +{ + value res = win_alloc_handle(h); + int opt; + int optlen = sizeof(opt); + if (getsockopt((SOCKET) h, SOL_SOCKET, SO_TYPE, (char *)&opt, &optlen) == 0) + Descr_kind_val(res) = KIND_SOCKET; + return res; +} + +/* Mapping of Windows error codes to POSIX error codes */ + +struct error_entry { DWORD win_code; int range; int posix_code; }; + +static struct error_entry win_error_table[] = { + { ERROR_INVALID_FUNCTION, 0, EINVAL}, + { ERROR_FILE_NOT_FOUND, 0, ENOENT}, + { ERROR_PATH_NOT_FOUND, 0, ENOENT}, + { ERROR_TOO_MANY_OPEN_FILES, 0, EMFILE}, + { ERROR_ACCESS_DENIED, 0, EACCES}, + { ERROR_INVALID_HANDLE, 0, EBADF}, + { ERROR_ARENA_TRASHED, 0, ENOMEM}, + { ERROR_NOT_ENOUGH_MEMORY, 0, ENOMEM}, + { ERROR_INVALID_BLOCK, 0, ENOMEM}, + { ERROR_BAD_ENVIRONMENT, 0, E2BIG}, + { ERROR_BAD_FORMAT, 0, ENOEXEC}, + { ERROR_INVALID_ACCESS, 0, EINVAL}, + { ERROR_INVALID_DATA, 0, EINVAL}, + { ERROR_INVALID_DRIVE, 0, ENOENT}, + { ERROR_CURRENT_DIRECTORY, 0, EACCES}, + { ERROR_NOT_SAME_DEVICE, 0, EXDEV}, + { ERROR_NO_MORE_FILES, 0, ENOENT}, + { ERROR_LOCK_VIOLATION, 0, EACCES}, + { ERROR_BAD_NETPATH, 0, ENOENT}, + { ERROR_NETWORK_ACCESS_DENIED, 0, EACCES}, + { ERROR_BAD_NET_NAME, 0, ENOENT}, + { ERROR_FILE_EXISTS, 0, EEXIST}, + { ERROR_CANNOT_MAKE, 0, EACCES}, + { ERROR_FAIL_I24, 0, EACCES}, + { ERROR_INVALID_PARAMETER, 0, EINVAL}, + { ERROR_NO_PROC_SLOTS, 0, EAGAIN}, + { ERROR_DRIVE_LOCKED, 0, EACCES}, + { ERROR_BROKEN_PIPE, 0, EPIPE}, + { ERROR_DISK_FULL, 0, ENOSPC}, + { ERROR_INVALID_TARGET_HANDLE, 0, EBADF}, + { ERROR_INVALID_HANDLE, 0, EINVAL}, + { ERROR_WAIT_NO_CHILDREN, 0, ECHILD}, + { ERROR_CHILD_NOT_COMPLETE, 0, ECHILD}, + { ERROR_DIRECT_ACCESS_HANDLE, 0, EBADF}, + { ERROR_NEGATIVE_SEEK, 0, EINVAL}, + { ERROR_SEEK_ON_DEVICE, 0, EACCES}, + { ERROR_DIR_NOT_EMPTY, 0, ENOTEMPTY}, + { ERROR_NOT_LOCKED, 0, EACCES}, + { ERROR_BAD_PATHNAME, 0, ENOENT}, + { ERROR_MAX_THRDS_REACHED, 0, EAGAIN}, + { ERROR_LOCK_FAILED, 0, EACCES}, + { ERROR_ALREADY_EXISTS, 0, EEXIST}, + { ERROR_FILENAME_EXCED_RANGE, 0, ENOENT}, + { ERROR_NESTING_NOT_ALLOWED, 0, EAGAIN}, + { ERROR_NOT_ENOUGH_QUOTA, 0, ENOMEM}, + { ERROR_INVALID_STARTING_CODESEG, + ERROR_INFLOOP_IN_RELOC_CHAIN - ERROR_INVALID_STARTING_CODESEG, + ENOEXEC }, + { ERROR_WRITE_PROTECT, + ERROR_SHARING_BUFFER_EXCEEDED - ERROR_WRITE_PROTECT, + EACCES }, + { WSAEINVAL, 0, EINVAL }, + { WSAEACCES, 0, EACCES }, + { WSAEBADF, 0, EBADF }, + { WSAEFAULT, 0, EFAULT }, + { WSAEINTR, 0, EINTR }, + { WSAEINVAL, 0, EINVAL }, + { WSAEMFILE, 0, EMFILE }, +#ifdef WSANAMETOOLONG + { WSANAMETOOLONG, 0, ENAMETOOLONG }, +#endif +#ifdef WSAENFILE + { WSAENFILE, 0, ENFILE }, +#endif + { WSAENOTEMPTY, 0, ENOTEMPTY }, + { 0, -1, 0 } +}; + +void win32_maperr(DWORD errcode) +{ + int i; + + for (i = 0; win_error_table[i].range >= 0; i++) { + if (errcode >= win_error_table[i].win_code && + errcode <= win_error_table[i].win_code + win_error_table[i].range) { + errno = win_error_table[i].posix_code; + return; + } + } + /* Not found: save original error code, negated so that we can + recognize it in unix_error_message */ + errno = -errcode; +} + +/* Windows socket errors */ + +#define EWOULDBLOCK -WSAEWOULDBLOCK +#define EINPROGRESS -WSAEINPROGRESS +#define EALREADY -WSAEALREADY +#define ENOTSOCK -WSAENOTSOCK +#define EDESTADDRREQ -WSAEDESTADDRREQ +#define EMSGSIZE -WSAEMSGSIZE +#define EPROTOTYPE -WSAEPROTOTYPE +#define ENOPROTOOPT -WSAENOPROTOOPT +#define EPROTONOSUPPORT -WSAEPROTONOSUPPORT +#define ESOCKTNOSUPPORT -WSAESOCKTNOSUPPORT +#define EOPNOTSUPP -WSAEOPNOTSUPP +#define EPFNOSUPPORT -WSAEPFNOSUPPORT +#define EAFNOSUPPORT -WSAEAFNOSUPPORT +#define EADDRINUSE -WSAEADDRINUSE +#define EADDRNOTAVAIL -WSAEADDRNOTAVAIL +#define ENETDOWN -WSAENETDOWN +#define ENETUNREACH -WSAENETUNREACH +#define ENETRESET -WSAENETRESET +#define ECONNABORTED -WSAECONNABORTED +#define ECONNRESET -WSAECONNRESET +#define ENOBUFS -WSAENOBUFS +#define EISCONN -WSAEISCONN +#define ENOTCONN -WSAENOTCONN +#define ESHUTDOWN -WSAESHUTDOWN +#define ETOOMANYREFS -WSAETOOMANYREFS +#define ETIMEDOUT -WSAETIMEDOUT +#define ECONNREFUSED -WSAECONNREFUSED +#define ELOOP -WSAELOOP +#define EHOSTDOWN -WSAEHOSTDOWN +#define EHOSTUNREACH -WSAEHOSTUNREACH +#define EPROCLIM -WSAEPROCLIM +#define EUSERS -WSAEUSERS +#define EDQUOT -WSAEDQUOT +#define ESTALE -WSAESTALE +#define EREMOTE -WSAEREMOTE + +#define EOVERFLOW -ERROR_ARITHMETIC_OVERFLOW +#define EACCESS EACCES + +int error_table[] = { + E2BIG, EACCESS, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM, + EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK, + ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC, + ENOSYS, ENOTDIR, ENOTEMPTY, ENOTTY, ENXIO, EPERM, EPIPE, ERANGE, + EROFS, ESPIPE, ESRCH, EXDEV, EWOULDBLOCK, EINPROGRESS, EALREADY, + ENOTSOCK, EDESTADDRREQ, EMSGSIZE, EPROTOTYPE, ENOPROTOOPT, + EPROTONOSUPPORT, ESOCKTNOSUPPORT, EOPNOTSUPP, EPFNOSUPPORT, + EAFNOSUPPORT, EADDRINUSE, EADDRNOTAVAIL, ENETDOWN, ENETUNREACH, + ENETRESET, ECONNABORTED, ECONNRESET, ENOBUFS, EISCONN, ENOTCONN, + ESHUTDOWN, ETOOMANYREFS, ETIMEDOUT, ECONNREFUSED, EHOSTDOWN, + EHOSTUNREACH, ELOOP, EOVERFLOW /*, EUNKNOWNERR */ +}; + +static value * unix_error_exn = NULL; + +value unix_error_of_code (int errcode) +{ + int errconstr; + value err; + + errconstr = + cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1); + if (errconstr == Val_int(-1)) { + err = alloc_small(1, 0); + Field(err, 0) = Val_int(errcode); + } else { + err = errconstr; + } + return err; +} + +void unix_error(int errcode, char *cmdname, value cmdarg) +{ + value res; + value name = Val_unit, err = Val_unit, arg = Val_unit; + int errconstr; + + Begin_roots3 (name, err, arg); + arg = cmdarg == Nothing ? copy_string("") : cmdarg; + name = copy_string(cmdname); + err = unix_error_of_code (errcode); + if (unix_error_exn == NULL) { + unix_error_exn = caml_named_value("Unix.Unix_error"); + if (unix_error_exn == NULL) + invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma"); + } + res = alloc_small(4, 0); + Field(res, 0) = *unix_error_exn; + Field(res, 1) = err; + Field(res, 2) = name; + Field(res, 3) = arg; + End_roots(); + mlraise(res); +} + +void uerror(cmdname, cmdarg) + char * cmdname; + value cmdarg; +{ + unix_error(errno, cmdname, cmdarg); +} diff --git a/otherlibs/win32unix/unixsupport.h b/otherlibs/win32unix/unixsupport.h new file mode 100644 index 0000000..fa2e229 --- /dev/null +++ b/otherlibs/win32unix/unixsupport.h @@ -0,0 +1,53 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: unixsupport.h,v 1.19 2007-02-07 14:45:46 doligez Exp $ */ + +#define WIN32_LEAN_AND_MEAN +#include <wtypes.h> +#include <winbase.h> +#include <stdlib.h> +#include <direct.h> +#include <process.h> +#include <sys/types.h> +#include <winsock.h> + +struct filedescr { + union { + HANDLE handle; + SOCKET socket; + } fd; + enum { KIND_HANDLE, KIND_SOCKET } kind; + int crt_fd; +}; + +#define Handle_val(v) (((struct filedescr *) Data_custom_val(v))->fd.handle) +#define Socket_val(v) (((struct filedescr *) Data_custom_val(v))->fd.socket) +#define Descr_kind_val(v) (((struct filedescr *) Data_custom_val(v))->kind) +#define CRT_fd_val(v) (((struct filedescr *) Data_custom_val(v))->crt_fd) + +extern value win_alloc_handle_or_socket(HANDLE); +extern value win_alloc_handle(HANDLE); +extern value win_alloc_socket(SOCKET); +extern int win_CRT_fd_of_filedescr(value handle); + +#define NO_CRT_FD (-1) +#define Nothing ((value) 0) + +extern void win32_maperr(DWORD errcode); +extern value unix_error_of_code (int errcode); +extern void unix_error (int errcode, char * cmdname, value arg); +extern void uerror (char * cmdname, value arg); +extern value unix_freeze_buffer (value); + +#define UNIX_BUFFER_SIZE 16384 diff --git a/otherlibs/win32unix/windbug.c b/otherlibs/win32unix/windbug.c new file mode 100644 index 0000000..dd65de5 --- /dev/null +++ b/otherlibs/win32unix/windbug.c @@ -0,0 +1,32 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: windbug.c,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ + +#include <windows.h> + +int dbug = 0; + +void dbug_init (void) +{ + dbug = (getenv("OCAMLDBUG") != NULL); +} + +void dbug_cleanup (void) +{ +} + +int dbug_test (void) +{ + return dbug; +} diff --git a/otherlibs/win32unix/windbug.h b/otherlibs/win32unix/windbug.h new file mode 100644 index 0000000..f065652 --- /dev/null +++ b/otherlibs/win32unix/windbug.h @@ -0,0 +1,50 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: windbug.h,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ + +/*#define DBUG*/ + +#ifdef DBUG + +#include <stdio.h> +#include <windows.h> + +#define DBUG_PRINT(fmt, ...) \ + do \ + { \ + if (dbug_test()) \ + { \ + fprintf(stderr, "DBUG (pid:%d, tid: %d): ", GetCurrentProcessId(), GetCurrentThreadId()); \ + fprintf(stderr, fmt, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + fflush(stderr); \ + }; \ + } while(0) + +/* Initialize and cleanup dbug variable */ +void dbug_init (void); +void dbug_cleanup (void); + +/* Test if we are in dbug mode */ +int dbug_test (void); + +#define DBUG_INIT dbug_init() +#define DBUG_CLEANUP dbug_cleanup() + +#else +#define DBUG_PRINT(fmt, ...) +#define DBUG_INIT +#define DBUG_CLEANUP +#endif + diff --git a/otherlibs/win32unix/windir.c b/otherlibs/win32unix/windir.c new file mode 100644 index 0000000..3b5ad87 --- /dev/null +++ b/otherlibs/win32unix/windir.c @@ -0,0 +1,80 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: windir.c,v 1.13 2002-07-23 14:12:01 doligez Exp $ */ + +#include <mlvalues.h> +#include <memory.h> +#include <errno.h> +#include <alloc.h> +#include <fail.h> +#include "unixsupport.h" + +CAMLprim value win_findfirst(name) + value name; +{ + HANDLE h; + value v; + WIN32_FIND_DATA fileinfo; + value valname = Val_unit; + value valh = Val_unit; + + Begin_roots2 (valname,valh); + h = FindFirstFile(String_val(name),&fileinfo); + if (h == INVALID_HANDLE_VALUE) { + DWORD err = GetLastError(); + if (err == ERROR_NO_MORE_FILES) + raise_end_of_file(); + else { + win32_maperr(err); + uerror("opendir", Nothing); + } + } + valname = copy_string(fileinfo.cFileName); + valh = win_alloc_handle(h); + v = alloc_small(2, 0); + Field(v,0) = valname; + Field(v,1) = valh; + End_roots(); + return v; +} + +CAMLprim value win_findnext(valh) + value valh; +{ + WIN32_FIND_DATA fileinfo; + BOOL retcode; + + retcode = FindNextFile(Handle_val(valh), &fileinfo); + if (!retcode) { + DWORD err = GetLastError(); + if (err == ERROR_NO_MORE_FILES) + raise_end_of_file(); + else { + win32_maperr(err); + uerror("readdir", Nothing); + } + } + return copy_string(fileinfo.cFileName); +} + +CAMLprim value win_findclose(valh) + value valh; +{ + if (! FindClose(Handle_val(valh))) { + win32_maperr(GetLastError()); + uerror("closedir", Nothing); + } + return Val_unit; +} + diff --git a/otherlibs/win32unix/winlist.c b/otherlibs/win32unix/winlist.c new file mode 100644 index 0000000..2e490d7 --- /dev/null +++ b/otherlibs/win32unix/winlist.c @@ -0,0 +1,80 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: winlist.c,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ + +/* Basic list function in C. */ + +#include "winlist.h" +#include <windows.h> + +void list_init (LPLIST lst) +{ + lst->lpNext = NULL; +} + +void list_cleanup (LPLIST lst) +{ + lst->lpNext = NULL; +} + +void list_next_set (LPLIST lst, LPLIST next) +{ + lst->lpNext = next; +} + +LPLIST list_next (LPLIST lst) +{ + return lst->lpNext; +} + +int list_length (LPLIST lst) +{ + int length = 0; + LPLIST iter = lst; + while (iter != NULL) + { + length++; + iter = list_next(iter); + }; + return length; +} + +LPLIST list_concat (LPLIST lsta, LPLIST lstb) +{ + LPLIST res = NULL; + LPLIST iter = NULL; + LPLIST iterPrev = NULL; + + if (lsta == NULL) + { + res = lstb; + } + else if (lstb == NULL) + { + res = lsta; + } + else + { + res = lsta; + iter = lsta; + while (iter != NULL) + { + iterPrev = iter; + iter = list_next(iter); + }; + iterPrev->lpNext = lstb; + }; + + return res; +} diff --git a/otherlibs/win32unix/winlist.h b/otherlibs/win32unix/winlist.h new file mode 100644 index 0000000..17064a2 --- /dev/null +++ b/otherlibs/win32unix/winlist.h @@ -0,0 +1,54 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: winlist.h,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ +#ifndef _WINLIST_H +#define _WINLIST_H + +/* Basic list function in C. */ + +/* Singly-linked list data structure. + * To transform a C struct into a list structure, you must include + * at first position of your C struct a "LIST lst" and call list_init + * on this data structure. + * + * See winworker.c for example. + */ +typedef struct _LIST LIST; +typedef LIST *LPLIST; + +struct _LIST { + LPLIST lpNext; +}; + +/* Initialize list data structure */ +void list_init (LPLIST lst); + +/* Cleanup list data structure */ +void list_cleanup (LPLIST lst); + +/* Set next element */ +void list_next_set (LPLIST lst, LPLIST next); + +/* Return next element */ +LPLIST list_next (LPLIST); + +#define LIST_NEXT(T, e) ((T)(list_next((LPLIST)(e)))) + +/* Get number of element */ +int list_length (LPLIST); + +/* Concat two list. */ +LPLIST list_concat (LPLIST, LPLIST); + +#endif /* _WINLIST_H */ diff --git a/otherlibs/win32unix/winwait.c b/otherlibs/win32unix/winwait.c new file mode 100644 index 0000000..be21b22 --- /dev/null +++ b/otherlibs/win32unix/winwait.c @@ -0,0 +1,70 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: winwait.c,v 1.20 2008-01-11 16:13:16 doligez Exp $ */ + +#include <windows.h> +#include <mlvalues.h> +#include <alloc.h> +#include <memory.h> +#include "unixsupport.h" +#include <sys/types.h> +#include <signals.h> + +static value alloc_process_status(HANDLE pid, int status) +{ + value res, st; + + st = alloc(1, 0); + Field(st, 0) = Val_int(status); + Begin_root (st); + res = alloc_small(2, 0); + Field(res, 0) = Val_long((intnat) pid); + Field(res, 1) = st; + End_roots(); + return res; +} + +enum { CAML_WNOHANG = 1, CAML_WUNTRACED = 2 }; + +static int wait_flag_table[] = { CAML_WNOHANG, CAML_WUNTRACED }; + +CAMLprim value win_waitpid(value vflags, value vpid_req) +{ + int flags; + DWORD status, retcode; + HANDLE pid_req = (HANDLE) Long_val(vpid_req); + DWORD err = 0; + + flags = convert_flag_list(vflags, wait_flag_table); + if ((flags & CAML_WNOHANG) == 0) { + enter_blocking_section(); + retcode = WaitForSingleObject(pid_req, INFINITE); + if (retcode == WAIT_FAILED) err = GetLastError(); + leave_blocking_section(); + if (err) { + win32_maperr(err); + uerror("waitpid", Nothing); + } + } + if (! GetExitCodeProcess(pid_req, &status)) { + win32_maperr(GetLastError()); + uerror("waitpid", Nothing); + } + if (status == STILL_ACTIVE) + return alloc_process_status((HANDLE) 0, 0); + else { + CloseHandle(pid_req); + return alloc_process_status(pid_req, status); + } +} diff --git a/otherlibs/win32unix/winworker.c b/otherlibs/win32unix/winworker.c new file mode 100644 index 0000000..7d51513 --- /dev/null +++ b/otherlibs/win32unix/winworker.c @@ -0,0 +1,338 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: winworker.c,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ + +#include "winworker.h" +#include "winlist.h" +#include "windbug.h" +#include <mlvalues.h> +#include <alloc.h> +#include "unixsupport.h" + +typedef enum { + WORKER_CMD_NONE = 0, + WORKER_CMD_EXEC, + WORKER_CMD_STOP +} WORKERCMD; + +struct _WORKER { + LIST lst; /* This structure is used as a list. */ + HANDLE hJobStarted; /* Event representing that the function has begun. */ + HANDLE hJobStop; /* Event that can be used to notify the function that it + should stop processing. */ + HANDLE hJobDone; /* Event representing that the function has finished. */ + void *lpJobUserData; /* User data for the job. */ + WORKERFUNC hJobFunc; /* Function to be called during APC */ + HANDLE hWorkerReady; /* Worker is ready. */ + HANDLE hCommandReady; /* Worker should execute command. */ + WORKERCMD ECommand; /* Command to execute */ + HANDLE hThread; /* Thread handle of the worker. */ +}; + +#define THREAD_WORKERS_MAX 16 +#define THREAD_WORKERS_MEM 4000 + +LPWORKER lpWorkers = NULL; +DWORD nWorkersCurrent = 0; +DWORD nWorkersMax = 0; +HANDLE hWorkersMutex = INVALID_HANDLE_VALUE; +HANDLE hWorkerHeap = INVALID_HANDLE_VALUE; + +DWORD WINAPI worker_wait (LPVOID _data) +{ + BOOL bExit; + LPWORKER lpWorker; + + lpWorker = (LPWORKER )_data; + bExit = FALSE; + + DBUG_PRINT("Worker %x starting", lpWorker); + while ( + !bExit + && SignalObjectAndWait( + lpWorker->hWorkerReady, + lpWorker->hCommandReady, + INFINITE, + TRUE) == WAIT_OBJECT_0) + { + DBUG_PRINT("Worker %x running", lpWorker); + switch (lpWorker->ECommand) + { + case WORKER_CMD_NONE: + break; + + case WORKER_CMD_EXEC: + if (lpWorker->hJobFunc != NULL) + { + SetEvent(lpWorker->hJobStarted); + lpWorker->hJobFunc(lpWorker->hJobStop, lpWorker->lpJobUserData); + SetEvent(lpWorker->hJobDone); + }; + break; + + case WORKER_CMD_STOP: + bExit = TRUE; + break; + } + }; + DBUG_PRINT("Worker %x exiting", lpWorker); + + return 0; +} + +LPWORKER worker_new (void) +{ + LPWORKER lpWorker = NULL; + + if (!HeapLock(hWorkerHeap)) + { + win32_maperr(GetLastError()); + uerror("worker_new", Nothing); + }; + lpWorker = (LPWORKER)HeapAlloc(hWorkerHeap, 0, sizeof(WORKER)); + HeapUnlock(hWorkerHeap); + list_init((LPLIST)lpWorker); + lpWorker->hJobStarted = CreateEvent(NULL, TRUE, FALSE, NULL); + lpWorker->hJobStop = CreateEvent(NULL, TRUE, FALSE, NULL); + lpWorker->hJobDone = CreateEvent(NULL, TRUE, FALSE, NULL); + lpWorker->lpJobUserData = NULL; + lpWorker->hWorkerReady = CreateEvent(NULL, FALSE, FALSE, NULL); + lpWorker->hCommandReady = CreateEvent(NULL, FALSE, FALSE, NULL); + lpWorker->ECommand = WORKER_CMD_NONE; + lpWorker->hThread = CreateThread( + NULL, + THREAD_WORKERS_MEM, + worker_wait, + (LPVOID)lpWorker, + 0, + NULL); + + return lpWorker; +}; + +void worker_free (LPWORKER lpWorker) +{ + /* Wait for termination of the worker */ + DBUG_PRINT("Shutting down worker %x", lpWorker); + WaitForSingleObject(lpWorker->hWorkerReady, INFINITE); + lpWorker->ECommand = WORKER_CMD_STOP; + SetEvent(lpWorker->hCommandReady); + WaitForSingleObject(lpWorker->hThread, INFINITE); + + /* Free resources */ + DBUG_PRINT("Freeing resources of worker %x", lpWorker); + if (lpWorker->hThread != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hThread); + lpWorker->hThread = INVALID_HANDLE_VALUE; + } + + if (lpWorker->hJobStarted != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hJobStarted); + lpWorker->hJobStarted = INVALID_HANDLE_VALUE; + } + + if (lpWorker->hJobStop != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hJobStop); + lpWorker->hJobStop = INVALID_HANDLE_VALUE; + } + + if (lpWorker->hJobDone != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hJobDone); + lpWorker->hJobDone = INVALID_HANDLE_VALUE; + } + + lpWorker->lpJobUserData = NULL; + lpWorker->hJobFunc = NULL; + + if (lpWorker->hWorkerReady != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hWorkerReady); + lpWorker->hWorkerReady = INVALID_HANDLE_VALUE; + } + + if (lpWorker->hCommandReady != INVALID_HANDLE_VALUE) + { + CloseHandle(lpWorker->hCommandReady); + lpWorker->hCommandReady = INVALID_HANDLE_VALUE; + } + + if (!HeapLock(hWorkerHeap)) + { + win32_maperr(GetLastError()); + uerror("worker_new", Nothing); + }; + HeapFree(hWorkerHeap, 0, lpWorker); + HeapUnlock(hWorkerHeap); +}; + +LPWORKER worker_pop (void) +{ + LPWORKER lpWorkerFree = NULL; + + WaitForSingleObject(hWorkersMutex, INFINITE); + /* Get the first worker of the list */ + if (lpWorkers != NULL) + { + lpWorkerFree = lpWorkers; + lpWorkers = LIST_NEXT(LPWORKER, lpWorkers); + } + nWorkersCurrent++; + nWorkersMax = (nWorkersCurrent > nWorkersMax ? nWorkersCurrent : nWorkersMax); + DBUG_PRINT("Workers running current/runnning max/waiting: %d/%d/%d", + nWorkersCurrent, + nWorkersMax, + list_length((LPLIST)lpWorkers)); + ReleaseMutex(hWorkersMutex); + + if (lpWorkerFree == NULL) + { + /* We cannot find a free worker, create one. */ + lpWorkerFree = worker_new(); + } + + /* Ensure that we don't get dangling pointer to old data. */ + list_init((LPLIST)lpWorkerFree); + lpWorkerFree->lpJobUserData = NULL; + + /* Reset events */ + ResetEvent(lpWorkerFree->hJobStarted); + ResetEvent(lpWorkerFree->hJobStop); + ResetEvent(lpWorkerFree->hJobDone); + + return lpWorkerFree; +} + +void worker_push(LPWORKER lpWorker) +{ + BOOL bFreeWorker; + + bFreeWorker = TRUE; + + WaitForSingleObject(hWorkersMutex, INFINITE); + DBUG_PRINT("Testing if we are under the maximum number of running workers"); + if (list_length((LPLIST)lpWorkers) < THREAD_WORKERS_MAX) + { + DBUG_PRINT("Saving this worker for future use"); + DBUG_PRINT("Next: %x", ((LPLIST)lpWorker)->lpNext); + lpWorkers = (LPWORKER)list_concat((LPLIST)lpWorker, (LPLIST)lpWorkers); + bFreeWorker = FALSE; + }; + nWorkersCurrent--; + DBUG_PRINT("Workers running current/runnning max/waiting: %d/%d/%d", + nWorkersCurrent, + nWorkersMax, + list_length((LPLIST)lpWorkers)); + ReleaseMutex(hWorkersMutex); + + if (bFreeWorker) + { + DBUG_PRINT("Freeing worker %x", lpWorker); + worker_free(lpWorker); + } +} + +void worker_init (void) +{ + int i = 0; + + /* Init a shared variable. The only way to ensure that no other + worker will be at the same point is to use a critical section. + */ + DBUG_PRINT("Allocating mutex for workers"); + if (hWorkersMutex == INVALID_HANDLE_VALUE) + { + hWorkersMutex = CreateMutex(NULL, FALSE, NULL); + } + + if (hWorkerHeap == INVALID_HANDLE_VALUE) + { + hWorkerHeap = HeapCreate(0, sizeof(WORKER) * THREAD_WORKERS_MAX * 4, 0); + } +} + +void worker_cleanup(void) +{ + LPWORKER lpWorker = NULL; + + /* WARNING: we can have a race condition here, if while this code + is executed another worker is waiting to access hWorkersMutex, + he will never be able to get it... + */ + if (hWorkersMutex != INVALID_HANDLE_VALUE) + { + WaitForSingleObject(hWorkersMutex, INFINITE); + DBUG_PRINT("Freeing global resource of workers"); + /* Empty the queue of worker worker */ + while (lpWorkers != NULL) + { + ReleaseMutex(hWorkersMutex); + lpWorker = worker_pop(); + DBUG_PRINT("Freeing worker %x", lpWorker); + WaitForSingleObject(hWorkersMutex, INFINITE); + worker_free(lpWorker); + }; + ReleaseMutex(hWorkersMutex); + + /* Destroy associated mutex */ + CloseHandle(hWorkersMutex); + hWorkersMutex = INVALID_HANDLE_VALUE; + }; +} + +LPWORKER worker_job_submit (WORKERFUNC f, void *user_data) +{ + LPWORKER lpWorker = worker_pop(); + + DBUG_PRINT("Waiting for worker to be ready"); + enter_blocking_section(); + WaitForSingleObject(lpWorker->hWorkerReady, INFINITE); + ResetEvent(lpWorker->hWorkerReady); + leave_blocking_section(); + DBUG_PRINT("Worker is ready"); + + lpWorker->hJobFunc = f; + lpWorker->lpJobUserData = user_data; + lpWorker->ECommand = WORKER_CMD_EXEC; + + DBUG_PRINT("Call worker (func: %x, worker: %x)", f, lpWorker); + SetEvent(lpWorker->hCommandReady); + + return (LPWORKER)lpWorker; +} + +HANDLE worker_job_event_done (LPWORKER lpWorker) +{ + return lpWorker->hJobDone; +} + +void worker_job_stop (LPWORKER lpWorker) +{ + DBUG_PRINT("Sending stop signal to worker %x", lpWorker); + SetEvent(lpWorker->hJobStop); + DBUG_PRINT("Signal sent to worker %x", lpWorker); +} + +void worker_job_finish (LPWORKER lpWorker) +{ + DBUG_PRINT("Finishing call of worker %x", lpWorker); + enter_blocking_section(); + WaitForSingleObject(lpWorker->hJobDone, INFINITE); + leave_blocking_section(); + + worker_push(lpWorker); +} diff --git a/otherlibs/win32unix/winworker.h b/otherlibs/win32unix/winworker.h new file mode 100644 index 0000000..2d135a4 --- /dev/null +++ b/otherlibs/win32unix/winworker.h @@ -0,0 +1,70 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Contributed by Sylvain Le Gall for Lexifi */ +/* */ +/* Copyright 2008 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: winworker.h,v 1.2 2008-07-31 12:09:18 xleroy Exp $ */ +#ifndef _WINWORKER_H +#define _WINWORKER_H + +#define _WIN32_WINNT 0x0400 +#include <windows.h> + +/* Pool of worker threads. + * + * These functions help to manage a pool of worker thread and submit task to + * the pool. It helps to reduce the number of thread creation. + * + * Each worker are started in alertable wait state and jobs are submitted as + * APC (asynchronous procedure call). + */ + +/* Data associated with submitted job */ +typedef struct _WORKER WORKER; +typedef WORKER *LPWORKER; + +/* Function type of submitted job: + * void worker_call (HANDLE hStop, void *data) + * + * This function will be called using the data following: + * - hStop must be watched for change, since it represents an external command + * to stop the call. This event is shared through the WORKER structure, which + * can be access throuhg worker_job_event_done. + * - data is user provided data for the function. + */ +typedef void (*WORKERFUNC) (HANDLE, void *); + +/* Initialize global data structure for worker + */ +void worker_init (void); + +/* Free global data structure for worker + */ +void worker_cleanup (void); + +/* Submit a job to worker. Use returned data to synchronize with the procedure + * submitted. + */ +LPWORKER worker_job_submit (WORKERFUNC f, void *data); + +/* Get event to know when a job is done. + */ +HANDLE worker_job_event_done (LPWORKER); + +/* Ask a job to stop processing. + */ +void worker_job_stop (LPWORKER); + +/* End a job submitted to worker. + */ +void worker_job_finish (LPWORKER); + +#endif /* _WINWORKER_H */ diff --git a/otherlibs/win32unix/write.c b/otherlibs/win32unix/write.c new file mode 100644 index 0000000..fd20c57 --- /dev/null +++ b/otherlibs/win32unix/write.c @@ -0,0 +1,101 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: write.c,v 1.11 2006-10-18 08:26:54 xleroy Exp $ */ + +#include <errno.h> +#include <string.h> +#include <mlvalues.h> +#include <memory.h> +#include <signals.h> +#include "unixsupport.h" + +CAMLprim value unix_write(value fd, value buf, value vofs, value vlen) +{ + intnat ofs, len, written; + DWORD numbytes, numwritten; + char iobuf[UNIX_BUFFER_SIZE]; + DWORD err = 0; + + Begin_root (buf); + ofs = Long_val(vofs); + len = Long_val(vlen); + written = 0; + while (len > 0) { + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + memmove (iobuf, &Byte(buf, ofs), numbytes); + if (Descr_kind_val(fd) == KIND_SOCKET) { + int ret; + SOCKET s = Socket_val(fd); + enter_blocking_section(); + ret = send(s, iobuf, numbytes, 0); + if (ret == SOCKET_ERROR) err = WSAGetLastError(); + leave_blocking_section(); + numwritten = ret; + } else { + HANDLE h = Handle_val(fd); + enter_blocking_section(); + if (! WriteFile(h, iobuf, numbytes, &numwritten, NULL)) + err = GetLastError(); + leave_blocking_section(); + } + if (err) { + win32_maperr(err); + uerror("write", Nothing); + } + written += numwritten; + ofs += numwritten; + len -= numwritten; + } + End_roots(); + return Val_long(written); +} + +CAMLprim value unix_single_write(value fd, value buf, value vofs, value vlen) +{ + intnat ofs, len, written; + DWORD numbytes, numwritten; + char iobuf[UNIX_BUFFER_SIZE]; + DWORD err; + + Begin_root (buf); + ofs = Long_val(vofs); + len = Long_val(vlen); + written = 0; + if (len > 0) { + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + memmove (iobuf, &Byte(buf, ofs), numbytes); + if (Descr_kind_val(fd) == KIND_SOCKET) { + int ret; + SOCKET s = Socket_val(fd); + enter_blocking_section(); + ret = send(s, iobuf, numbytes, 0); + if (ret == SOCKET_ERROR) err = WSAGetLastError(); + leave_blocking_section(); + numwritten = ret; + } else { + HANDLE h = Handle_val(fd); + enter_blocking_section(); + if (! WriteFile(h, iobuf, numbytes, &numwritten, NULL)) + err = GetLastError(); + leave_blocking_section(); + } + if (err) { + win32_maperr(err); + uerror("single_write", Nothing); + } + written = numwritten; + } + End_roots(); + return Val_long(written); +} diff --git a/parsing/.cvsignore b/parsing/.cvsignore new file mode 100644 index 0000000..5602bf8 --- /dev/null +++ b/parsing/.cvsignore @@ -0,0 +1,9 @@ +parser.ml +parser.mli +lexer.ml +lexer_tmp.mll +lexer_tmp.ml +linenum.ml +parser.output +parser.automaton +parser.conflicts diff --git a/parsing/asttypes.mli b/parsing/asttypes.mli new file mode 100644 index 0000000..0b240e8 --- /dev/null +++ b/parsing/asttypes.mli @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: asttypes.mli,v 1.9 2003-04-25 12:27:30 xleroy Exp $ *) + +(* Auxiliary a.s.t. types used by parsetree and typedtree. *) + +type constant = + Const_int of int + | Const_char of char + | Const_string of string + | Const_float of string + | Const_int32 of int32 + | Const_int64 of int64 + | Const_nativeint of nativeint + +type rec_flag = Nonrecursive | Recursive | Default + +type direction_flag = Upto | Downto + +type private_flag = Private | Public + +type mutable_flag = Immutable | Mutable + +type virtual_flag = Virtual | Concrete + +type label = string diff --git a/parsing/lexer.mli b/parsing/lexer.mli new file mode 100644 index 0000000..ed526b4 --- /dev/null +++ b/parsing/lexer.mli @@ -0,0 +1,36 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mli,v 1.14 2003-11-21 16:01:13 xleroy Exp $ *) + +(* The lexical analyzer *) + +val token: Lexing.lexbuf -> Parser.token +val skip_sharp_bang: Lexing.lexbuf -> unit + +type error = + | Illegal_character of char + | Illegal_escape of string + | Unterminated_comment + | Unterminated_string + | Unterminated_string_in_comment + | Keyword_as_label of string + | Literal_overflow of string +;; + +exception Error of error * Location.t + +open Format + +val report_error: formatter -> error -> unit + +val in_comment : unit -> bool;; diff --git a/parsing/lexer.mll b/parsing/lexer.mll new file mode 100644 index 0000000..890c466 --- /dev/null +++ b/parsing/lexer.mll @@ -0,0 +1,502 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer.mll,v 1.75 2008-12-03 18:09:09 doligez Exp $ *) + +(* The lexer definition *) + +{ +open Lexing +open Misc +open Parser + +type error = + | Illegal_character of char + | Illegal_escape of string + | Unterminated_comment + | Unterminated_string + | Unterminated_string_in_comment + | Keyword_as_label of string + | Literal_overflow of string +;; + +exception Error of error * Location.t;; + +(* The table of keywords *) + +let keyword_table = + create_hashtable 149 [ + "and", AND; + "as", AS; + "assert", ASSERT; + "begin", BEGIN; + "class", CLASS; + "constraint", CONSTRAINT; + "do", DO; + "done", DONE; + "downto", DOWNTO; + "else", ELSE; + "end", END; + "exception", EXCEPTION; + "external", EXTERNAL; + "false", FALSE; + "for", FOR; + "fun", FUN; + "function", FUNCTION; + "functor", FUNCTOR; + "if", IF; + "in", IN; + "include", INCLUDE; + "inherit", INHERIT; + "initializer", INITIALIZER; + "lazy", LAZY; + "let", LET; + "match", MATCH; + "method", METHOD; + "module", MODULE; + "mutable", MUTABLE; + "new", NEW; + "object", OBJECT; + "of", OF; + "open", OPEN; + "or", OR; +(* "parser", PARSER; *) + "private", PRIVATE; + "rec", REC; + "sig", SIG; + "struct", STRUCT; + "then", THEN; + "to", TO; + "true", TRUE; + "try", TRY; + "type", TYPE; + "val", VAL; + "virtual", VIRTUAL; + "when", WHEN; + "while", WHILE; + "with", WITH; + + "mod", INFIXOP3("mod"); + "land", INFIXOP3("land"); + "lor", INFIXOP3("lor"); + "lxor", INFIXOP3("lxor"); + "lsl", INFIXOP4("lsl"); + "lsr", INFIXOP4("lsr"); + "asr", INFIXOP4("asr") +] + +(* To buffer string literals *) + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0 + +let store_string_char c = + if !string_index >= String.length (!string_buff) then begin + let new_buff = String.create (String.length (!string_buff) * 2) in + String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff)); + string_buff := new_buff + end; + String.unsafe_set (!string_buff) (!string_index) c; + incr string_index + +let get_stored_string () = + let s = String.sub (!string_buff) 0 (!string_index) in + string_buff := initial_string_buffer; + s + +(* To store the position of the beginning of a string and comment *) +let string_start_loc = ref Location.none;; +let comment_start_loc = ref [];; +let in_comment () = !comment_start_loc <> [];; + +(* To translate escape sequences *) + +let char_for_backslash = function + | 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in + if (c < 0 || c > 255) then + if in_comment () + then 'x' + else raise (Error(Illegal_escape (Lexing.lexeme lexbuf), + Location.curr lexbuf)) + else Char.chr c + +let char_for_hexadecimal_code lexbuf i = + let d1 = Char.code (Lexing.lexeme_char lexbuf i) in + let val1 = if d1 >= 97 then d1 - 87 + else if d1 >= 65 then d1 - 55 + else d1 - 48 + in + let d2 = Char.code (Lexing.lexeme_char lexbuf (i+1)) in + let val2 = if d2 >= 97 then d2 - 87 + else if d2 >= 65 then d2 - 55 + else d2 - 48 + in + Char.chr (val1 * 16 + val2) + +(* Remove underscores from float literals *) + +let remove_underscores s = + let l = String.length s in + let rec remove src dst = + if src >= l then + if dst >= l then s else String.sub s 0 dst + else + match s.[src] with + '_' -> remove (src + 1) dst + | c -> s.[dst] <- c; remove (src + 1) (dst + 1) + in remove 0 0 + +(* Update the current location with file name and line number. *) + +let update_loc lexbuf file line absolute chars = + let pos = lexbuf.lex_curr_p in + let new_file = match file with + | None -> pos.pos_fname + | Some s -> s + in + lexbuf.lex_curr_p <- { pos with + pos_fname = new_file; + pos_lnum = if absolute then line else pos.pos_lnum + line; + pos_bol = pos.pos_cnum - chars; + } +;; + +(* Error report *) + +open Format + +let report_error ppf = function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Illegal_escape s -> + fprintf ppf "Illegal backslash escape in string or character (%s)" s + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf "This comment contains an unterminated string literal" + | Keyword_as_label kwd -> + fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd + | Literal_overflow ty -> + fprintf ppf "Integer literal exceeds the range of representable integers of type %s" ty +;; + +} + +let newline = ('\010' | '\013' | "\013\010") +let blank = [' ' '\009' '\012'] +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let symbolchar = + ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] +let decimal_literal = + ['0'-'9'] ['0'-'9' '_']* +let hex_literal = + '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']['0'-'9' 'A'-'F' 'a'-'f' '_']* +let oct_literal = + '0' ['o' 'O'] ['0'-'7'] ['0'-'7' '_']* +let bin_literal = + '0' ['b' 'B'] ['0'-'1'] ['0'-'1' '_']* +let int_literal = + decimal_literal | hex_literal | oct_literal | bin_literal +let float_literal = + ['0'-'9'] ['0'-'9' '_']* + ('.' ['0'-'9' '_']* )? + (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)? + +rule token = parse + | newline + { update_loc lexbuf None 1 false 0; + token lexbuf + } + | blank + + { token lexbuf } + | "_" + { UNDERSCORE } + | "~" { TILDE } + | "~" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Location.curr lexbuf)); + LABEL name } + | "?" { QUESTION } + | "??" { QUESTIONQUESTION } + | "?" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Location.curr lexbuf)); + OPTLABEL name } + | lowercase identchar * + { let s = Lexing.lexeme lexbuf in + try + Hashtbl.find keyword_table s + with Not_found -> + LIDENT s } + | uppercase identchar * + { UIDENT(Lexing.lexeme lexbuf) } (* No capitalized keywords *) + | int_literal + { try + INT (int_of_string(Lexing.lexeme lexbuf)) + with Failure _ -> + raise (Error(Literal_overflow "int", Location.curr lexbuf)) + } + | float_literal + { FLOAT (remove_underscores(Lexing.lexeme lexbuf)) } + | int_literal "l" + { let s = Lexing.lexeme lexbuf in + try + INT32 (Int32.of_string(String.sub s 0 (String.length s - 1))) + with Failure _ -> + raise (Error(Literal_overflow "int32", Location.curr lexbuf)) } + | int_literal "L" + { let s = Lexing.lexeme lexbuf in + try + INT64 (Int64.of_string(String.sub s 0 (String.length s - 1))) + with Failure _ -> + raise (Error(Literal_overflow "int64", Location.curr lexbuf)) } + | int_literal "n" + { let s = Lexing.lexeme lexbuf in + try + NATIVEINT + (Nativeint.of_string(String.sub s 0 (String.length s - 1))) + with Failure _ -> + raise (Error(Literal_overflow "nativeint", Location.curr lexbuf)) } + | "\"" + { reset_string_buffer(); + let string_start = lexbuf.lex_start_p in + string_start_loc := Location.curr lexbuf; + string lexbuf; + lexbuf.lex_start_p <- string_start; + STRING (get_stored_string()) } + | "'" newline "'" + { update_loc lexbuf None 1 false 1; + CHAR (Lexing.lexeme_char lexbuf 1) } + | "'" [^ '\\' '\'' '\010' '\013'] "'" + { CHAR(Lexing.lexeme_char lexbuf 1) } + | "'\\" ['\\' '\'' '"' 'n' 't' 'b' 'r' ' '] "'" + { CHAR(char_for_backslash (Lexing.lexeme_char lexbuf 2)) } + | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { CHAR(char_for_decimal_code lexbuf 2) } + | "'\\" 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'" + { CHAR(char_for_hexadecimal_code lexbuf 3) } + | "'\\" _ + { let l = Lexing.lexeme lexbuf in + let esc = String.sub l 1 (String.length l - 1) in + raise (Error(Illegal_escape esc, Location.curr lexbuf)) + } + | "(*" + { comment_start_loc := [Location.curr lexbuf]; + comment lexbuf; + token lexbuf } + | "(*)" + { let loc = Location.curr lexbuf in + Location.prerr_warning loc Warnings.Comment_start; + comment_start_loc := [Location.curr lexbuf]; + comment lexbuf; + token lexbuf + } + | "*)" + { let loc = Location.curr lexbuf in + Location.prerr_warning loc Warnings.Comment_not_end; + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + let curpos = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { curpos with pos_cnum = curpos.pos_cnum - 1 }; + STAR + } + | "#" [' ' '\t']* (['0'-'9']+ as num) [' ' '\t']* + ("\"" ([^ '\010' '\013' '"' ] * as name) "\"")? + [^ '\010' '\013'] * newline + { update_loc lexbuf name (int_of_string num) true 0; + token lexbuf + } + | "#" { SHARP } + | "&" { AMPERSAND } + | "&&" { AMPERAMPER } + | "`" { BACKQUOTE } + | "'" { QUOTE } + | "(" { LPAREN } + | ")" { RPAREN } + | "*" { STAR } + | "," { COMMA } + | "->" { MINUSGREATER } + | "." { DOT } + | ".." { DOTDOT } + | ":" { COLON } + | "::" { COLONCOLON } + | ":=" { COLONEQUAL } + | ":>" { COLONGREATER } + | ";" { SEMI } + | ";;" { SEMISEMI } + | "<" { LESS } + | "<-" { LESSMINUS } + | "=" { EQUAL } + | "[" { LBRACKET } + | "[|" { LBRACKETBAR } + | "[<" { LBRACKETLESS } + | "[>" { LBRACKETGREATER } + | "]" { RBRACKET } + | "{" { LBRACE } + | "{<" { LBRACELESS } + | "|" { BAR } + | "||" { BARBAR } + | "|]" { BARRBRACKET } + | ">" { GREATER } + | ">]" { GREATERRBRACKET } + | "}" { RBRACE } + | ">}" { GREATERRBRACE } + + | "!=" { INFIXOP0 "!=" } + | "+" { PLUS } + | "-" { MINUS } + | "-." { MINUSDOT } + + | "!" symbolchar * + { PREFIXOP(Lexing.lexeme lexbuf) } + | ['~' '?'] symbolchar + + { PREFIXOP(Lexing.lexeme lexbuf) } + | ['=' '<' '>' '|' '&' '$'] symbolchar * + { INFIXOP0(Lexing.lexeme lexbuf) } + | ['@' '^'] symbolchar * + { INFIXOP1(Lexing.lexeme lexbuf) } + | ['+' '-'] symbolchar * + { INFIXOP2(Lexing.lexeme lexbuf) } + | "**" symbolchar * + { INFIXOP4(Lexing.lexeme lexbuf) } + | ['*' '/' '%'] symbolchar * + { INFIXOP3(Lexing.lexeme lexbuf) } + | eof { EOF } + | _ + { raise (Error(Illegal_character (Lexing.lexeme_char lexbuf 0), + Location.curr lexbuf)) + } + +and comment = parse + "(*" + { comment_start_loc := (Location.curr lexbuf) :: !comment_start_loc; + comment lexbuf; + } + | "*)" + { match !comment_start_loc with + | [] -> assert false + | [x] -> comment_start_loc := []; + | _ :: l -> comment_start_loc := l; + comment lexbuf; + } + | "\"" + { reset_string_buffer(); + string_start_loc := Location.curr lexbuf; + begin try string lexbuf + with Error (Unterminated_string, _) -> + match !comment_start_loc with + | [] -> assert false + | loc :: _ -> comment_start_loc := []; + raise (Error (Unterminated_string_in_comment, loc)) + end; + reset_string_buffer (); + comment lexbuf } + | "''" + { comment lexbuf } + | "'" newline "'" + { update_loc lexbuf None 1 false 1; + comment lexbuf + } + | "'" [^ '\\' '\'' '\010' '\013' ] "'" + { comment lexbuf } + | "'\\" ['\\' '"' '\'' 'n' 't' 'b' 'r' ' '] "'" + { comment lexbuf } + | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { comment lexbuf } + | "'\\" 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] "'" + { comment lexbuf } + | eof + { match !comment_start_loc with + | [] -> assert false + | loc :: _ -> comment_start_loc := []; + raise (Error (Unterminated_comment, loc)) + } + | newline + { update_loc lexbuf None 1 false 0; + comment lexbuf + } + | _ + { comment lexbuf } + +and string = parse + '"' + { () } + | '\\' newline ([' ' '\t'] * as space) + { update_loc lexbuf None 1 false (String.length space); + string lexbuf + } + | '\\' ['\\' '\'' '"' 'n' 't' 'b' 'r' ' '] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | '\\' 'x' ['0'-'9' 'a'-'f' 'A'-'F'] ['0'-'9' 'a'-'f' 'A'-'F'] + { store_string_char(char_for_hexadecimal_code lexbuf 2); + string lexbuf } + | '\\' _ + { if in_comment () + then string lexbuf + else begin +(* Should be an error, but we are very lax. + raise (Error (Illegal_escape (Lexing.lexeme lexbuf), + Location.curr lexbuf)) +*) + let loc = Location.curr lexbuf in + Location.prerr_warning loc Warnings.Illegal_backslash; + store_string_char (Lexing.lexeme_char lexbuf 0); + store_string_char (Lexing.lexeme_char lexbuf 1); + string lexbuf + end + } + | newline + { update_loc lexbuf None 1 false 0; + let s = Lexing.lexeme lexbuf in + for i = 0 to String.length s - 1 do + store_string_char s.[i]; + done; + string lexbuf + } + | eof + { raise (Error (Unterminated_string, !string_start_loc)) } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } + +and skip_sharp_bang = parse + | "#!" [^ '\n']* '\n' [^ '\n']* "\n!#\n" + { update_loc lexbuf None 3 false 0 } + | "#!" [^ '\n']* '\n' + { update_loc lexbuf None 1 false 0 } + | "" { () } diff --git a/parsing/linenum.mli b/parsing/linenum.mli new file mode 100644 index 0000000..58285ce --- /dev/null +++ b/parsing/linenum.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: linenum.mli,v 1.2 1999-11-17 18:58:17 xleroy Exp $ *) + +(* An auxiliary lexer for determining the line number corresponding to + a file position, honoring the directives # linenum "filename" *) + +val for_position: string -> int -> string * int * int + (* [Linenum.for_position file loc] returns a triple describing + the location [loc] in the file named [file]. + First result is name of actual source file. + Second result is line number in that source file. + Third result is position of beginning of that line in [file]. *) diff --git a/parsing/linenum.mll b/parsing/linenum.mll new file mode 100644 index 0000000..5f89edf --- /dev/null +++ b/parsing/linenum.mll @@ -0,0 +1,74 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: linenum.mll,v 1.7 1999-11-17 18:58:17 xleroy Exp $ *) + +(* An auxiliary lexer for determining the line number corresponding to + a file position, honoring the directives # linenum "filename" *) + +{ +let filename = ref "" +let linenum = ref 0 +let linebeg = ref 0 + +let parse_sharp_line s = + try + (* Update the line number and file name *) + let l1 = ref 0 in + while let c = s.[!l1] in c < '0' || c > '9' do incr l1 done; + let l2 = ref (!l1 + 1) in + while let c = s.[!l2] in c >= '0' && c <= '9' do incr l2 done; + linenum := int_of_string(String.sub s !l1 (!l2 - !l1)); + let f1 = ref (!l2 + 1) in + while !f1 < String.length s && s.[!f1] <> '"' do incr f1 done; + let f2 = ref (!f1 + 1) in + while !f2 < String.length s && s.[!f2] <> '"' do incr f2 done; + if !f1 < String.length s then + filename := String.sub s (!f1 + 1) (!f2 - !f1 - 1) + with Failure _ | Invalid_argument _ -> + Misc.fatal_error "Linenum.parse_sharp_line" +} + +rule skip_line = parse + "#" [' ' '\t']* ['0'-'9']+ [' ' '\t']* + ("\"" [^ '\n' '\r' '"' (* '"' *) ] * "\"")? + [^ '\n' '\r'] * + ('\n' | '\r' | "\r\n") + { parse_sharp_line(Lexing.lexeme lexbuf); + linebeg := Lexing.lexeme_start lexbuf; + Lexing.lexeme_end lexbuf } + | [^ '\n' '\r'] * + ('\n' | '\r' | "\r\n") + { incr linenum; + linebeg := Lexing.lexeme_start lexbuf; + Lexing.lexeme_end lexbuf } + | [^ '\n' '\r'] * eof + { incr linenum; + linebeg := Lexing.lexeme_start lexbuf; + raise End_of_file } + +{ + +let for_position file loc = + let ic = open_in_bin file in + let lb = Lexing.from_channel ic in + filename := file; + linenum := 1; + linebeg := 0; + begin try + while skip_line lb <= loc do () done + with End_of_file -> () + end; + close_in ic; + (!filename, !linenum - 1, !linebeg) + +} diff --git a/parsing/location.ml b/parsing/location.ml new file mode 100644 index 0000000..6c262af --- /dev/null +++ b/parsing/location.ml @@ -0,0 +1,259 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: location.ml,v 1.50 2008-01-11 16:13:16 doligez Exp $ *) + +open Lexing + +type t = { loc_start: position; loc_end: position; loc_ghost: bool };; + +let none = { loc_start = dummy_pos; loc_end = dummy_pos; loc_ghost = true };; + +let in_file name = + let loc = { + pos_fname = name; + pos_lnum = 1; + pos_bol = 0; + pos_cnum = -1; + } in + { loc_start = loc; loc_end = loc; loc_ghost = true } +;; + +let curr lexbuf = { + loc_start = lexbuf.lex_start_p; + loc_end = lexbuf.lex_curr_p; + loc_ghost = false +};; + +let init lexbuf fname = + lexbuf.lex_curr_p <- { + pos_fname = fname; + pos_lnum = 1; + pos_bol = 0; + pos_cnum = 0; + } +;; + +let symbol_rloc () = { + loc_start = Parsing.symbol_start_pos (); + loc_end = Parsing.symbol_end_pos (); + loc_ghost = false; +};; + +let symbol_gloc () = { + loc_start = Parsing.symbol_start_pos (); + loc_end = Parsing.symbol_end_pos (); + loc_ghost = true; +};; + +let rhs_loc n = { + loc_start = Parsing.rhs_start_pos n; + loc_end = Parsing.rhs_end_pos n; + loc_ghost = false; +};; + +let input_name = ref "_none_" +let input_lexbuf = ref (None : lexbuf option) + +(* Terminal info *) + +let status = ref Terminfo.Uninitialised + +let num_loc_lines = ref 0 (* number of lines already printed after input *) + +(* Highlight the locations using standout mode. *) + +let highlight_terminfo ppf num_lines lb loc1 loc2 = + Format.pp_print_flush ppf (); (* avoid mixing Format and normal output *) + (* Char 0 is at offset -lb.lex_abs_pos in lb.lex_buffer. *) + let pos0 = -lb.lex_abs_pos in + (* Do nothing if the buffer does not contain the whole phrase. *) + if pos0 < 0 then raise Exit; + (* Count number of lines in phrase *) + let lines = ref !num_loc_lines in + for i = pos0 to lb.lex_buffer_len - 1 do + if lb.lex_buffer.[i] = '\n' then incr lines + done; + (* If too many lines, give up *) + if !lines >= num_lines - 2 then raise Exit; + (* Move cursor up that number of lines *) + flush stdout; Terminfo.backup !lines; + (* Print the input, switching to standout for the location *) + let bol = ref false in + print_string "# "; + for pos = 0 to lb.lex_buffer_len - pos0 - 1 do + if !bol then (print_string " "; bol := false); + if pos = loc1.loc_start.pos_cnum || pos = loc2.loc_start.pos_cnum then + Terminfo.standout true; + if pos = loc1.loc_end.pos_cnum || pos = loc2.loc_end.pos_cnum then + Terminfo.standout false; + let c = lb.lex_buffer.[pos + pos0] in + print_char c; + bol := (c = '\n') + done; + (* Make sure standout mode is over *) + Terminfo.standout false; + (* Position cursor back to original location *) + Terminfo.resume !num_loc_lines; + flush stdout + +(* Highlight the location by printing it again. *) + +let highlight_dumb ppf lb loc = + (* Char 0 is at offset -lb.lex_abs_pos in lb.lex_buffer. *) + let pos0 = -lb.lex_abs_pos in + (* Do nothing if the buffer does not contain the whole phrase. *) + if pos0 < 0 then raise Exit; + let end_pos = lb.lex_buffer_len - pos0 - 1 in + (* Determine line numbers for the start and end points *) + let line_start = ref 0 and line_end = ref 0 in + for pos = 0 to end_pos do + if lb.lex_buffer.[pos + pos0] = '\n' then begin + if loc.loc_start.pos_cnum > pos then incr line_start; + if loc.loc_end.pos_cnum > pos then incr line_end; + end + done; + (* Print character location (useful for Emacs) *) + Format.fprintf ppf "Characters %i-%i:@." + loc.loc_start.pos_cnum loc.loc_end.pos_cnum; + (* Print the input, underlining the location *) + Format.pp_print_string ppf " "; + let line = ref 0 in + let pos_at_bol = ref 0 in + for pos = 0 to end_pos do + let c = lb.lex_buffer.[pos + pos0] in + if c <> '\n' then begin + if !line = !line_start && !line = !line_end then + (* loc is on one line: print whole line *) + Format.pp_print_char ppf c + else if !line = !line_start then + (* first line of multiline loc: print ... before loc_start *) + if pos < loc.loc_start.pos_cnum + then Format.pp_print_char ppf '.' + else Format.pp_print_char ppf c + else if !line = !line_end then + (* last line of multiline loc: print ... after loc_end *) + if pos < loc.loc_end.pos_cnum + then Format.pp_print_char ppf c + else Format.pp_print_char ppf '.' + else if !line > !line_start && !line < !line_end then + (* intermediate line of multiline loc: print whole line *) + Format.pp_print_char ppf c + end else begin + if !line = !line_start && !line = !line_end then begin + (* loc is on one line: underline location *) + Format.fprintf ppf "@. "; + for i = !pos_at_bol to loc.loc_start.pos_cnum - 1 do + Format.pp_print_char ppf ' ' + done; + for i = loc.loc_start.pos_cnum to loc.loc_end.pos_cnum - 1 do + Format.pp_print_char ppf '^' + done + end; + if !line >= !line_start && !line <= !line_end then begin + Format.fprintf ppf "@."; + if pos < loc.loc_end.pos_cnum then Format.pp_print_string ppf " " + end; + incr line; + pos_at_bol := pos + 1; + end + done + +(* Highlight the location using one of the supported modes. *) + +let rec highlight_locations ppf loc1 loc2 = + match !status with + Terminfo.Uninitialised -> + status := Terminfo.setup stdout; highlight_locations ppf loc1 loc2 + | Terminfo.Bad_term -> + begin match !input_lexbuf with + None -> false + | Some lb -> + let norepeat = + try Sys.getenv "TERM" = "norepeat" with Not_found -> false in + if norepeat then false else + try highlight_dumb ppf lb loc1; true + with Exit -> false + end + | Terminfo.Good_term num_lines -> + begin match !input_lexbuf with + None -> false + | Some lb -> + try highlight_terminfo ppf num_lines lb loc1 loc2; true + with Exit -> false + end + +(* Print the location in some way or another *) + +open Format + +let reset () = + num_loc_lines := 0 + +let (msg_file, msg_line, msg_chars, msg_to, msg_colon, msg_head) = + ("File \"", "\", line ", ", characters ", "-", ":", "") + +(* return file, line, char from the given position *) +let get_pos_info pos = + let (filename, linenum, linebeg) = + if pos.pos_fname = "" && !input_name = "" then + ("", -1, 0) + else if pos.pos_fname = "" then + Linenum.for_position !input_name pos.pos_cnum + else + (pos.pos_fname, pos.pos_lnum, pos.pos_bol) + in + (filename, linenum, pos.pos_cnum - linebeg) +;; + +let print ppf loc = + let (file, line, startchar) = get_pos_info loc.loc_start in + let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in + let (startchar, endchar) = + if startchar < 0 then (0, 1) else (startchar, endchar) + in + if file = "" then begin + if highlight_locations ppf loc none then () else + fprintf ppf "Characters %i-%i:@." + loc.loc_start.pos_cnum loc.loc_end.pos_cnum + end else begin + fprintf ppf "%s%s%s%i" msg_file file msg_line line; + fprintf ppf "%s%i" msg_chars startchar; + fprintf ppf "%s%i%s@.%s" msg_to endchar msg_colon msg_head; + end +;; + +let print_error ppf loc = + print ppf loc; + fprintf ppf "Error: "; +;; + +let print_error_cur_file ppf = print_error ppf (in_file !input_name);; + +let print_warning loc ppf w = + if Warnings.is_active w then begin + let printw ppf w = + let n = Warnings.print ppf w in + num_loc_lines := !num_loc_lines + n + in + fprintf ppf "%a" print loc; + fprintf ppf "Warning %a@." printw w; + pp_print_flush ppf (); + incr num_loc_lines; + end +;; + +let prerr_warning loc w = print_warning loc err_formatter w;; + +let echo_eof () = + print_newline (); + incr num_loc_lines diff --git a/parsing/location.mli b/parsing/location.mli new file mode 100644 index 0000000..ba7db88 --- /dev/null +++ b/parsing/location.mli @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: location.mli,v 1.17 2007-12-04 13:38:58 doligez Exp $ *) + +(* Source code locations (ranges of positions), used in parsetree. *) + +open Format + +type t = { + loc_start: Lexing.position; + loc_end: Lexing.position; + loc_ghost: bool; +} + +(* Note on the use of Lexing.position in this module. + If [pos_fname = ""], then use [!input_name] instead. + If [pos_lnum = -1], then [pos_bol = 0]. Use [pos_cnum] and + re-parse the file to get the line and character numbers. + Else all fields are correct. +*) + +val none : t +(** An arbitrary value of type [t]; describes an empty ghost range. *) +val in_file : string -> t;; +(** Return an empty ghost range located in a given file. *) +val init : Lexing.lexbuf -> string -> unit +(** Set the file name and line number of the [lexbuf] to be the start + of the named file. *) +val curr : Lexing.lexbuf -> t +(** Get the location of the current token from the [lexbuf]. *) + +val symbol_rloc: unit -> t +val symbol_gloc: unit -> t +val rhs_loc: int -> t + +val input_name: string ref +val input_lexbuf: Lexing.lexbuf option ref + +val get_pos_info : Lexing.position -> string * int * int (* file, line, char *) +val print_error: formatter -> t -> unit +val print_error_cur_file: formatter -> unit +val print_warning: t -> formatter -> Warnings.t -> unit +val prerr_warning: t -> Warnings.t -> unit +val echo_eof: unit -> unit +val reset: unit -> unit + +val highlight_locations: formatter -> t -> t -> bool diff --git a/parsing/longident.ml b/parsing/longident.ml new file mode 100644 index 0000000..e2aaecd --- /dev/null +++ b/parsing/longident.ml @@ -0,0 +1,38 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: longident.ml,v 1.4 2000-03-25 18:55:44 xleroy Exp $ *) + +type t = + Lident of string + | Ldot of t * string + | Lapply of t * t + +let rec flat accu = function + Lident s -> s :: accu + | Ldot(lid, s) -> flat (s :: accu) lid + | Lapply(l1, l2) -> Misc.fatal_error "Longident.flat" + +let flatten lid = flat [] lid + +let rec split_at_dots s pos = + try + let dot = String.index_from s pos '.' in + String.sub s pos (dot - pos) :: split_at_dots s (dot + 1) + with Not_found -> + [String.sub s pos (String.length s - pos)] + +let parse s = + match split_at_dots s 0 with + [] -> Lident "" (* should not happen, but don't put assert false + so as not to crash the toplevel (see Genprintval) *) + | hd :: tl -> List.fold_left (fun p s -> Ldot(p, s)) (Lident hd) tl diff --git a/parsing/longident.mli b/parsing/longident.mli new file mode 100644 index 0000000..50f6cbd --- /dev/null +++ b/parsing/longident.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: longident.mli,v 1.7 2000-03-25 18:55:44 xleroy Exp $ *) + +(* Long identifiers, used in parsetree. *) + +type t = + Lident of string + | Ldot of t * string + | Lapply of t * t + +val flatten: t -> string list +val parse: string -> t diff --git a/parsing/parse.ml b/parsing/parse.ml new file mode 100644 index 0000000..14a50cd --- /dev/null +++ b/parsing/parse.ml @@ -0,0 +1,64 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parse.ml,v 1.15 2002-11-01 17:06:46 doligez Exp $ *) + +(* Entry points in the parser *) + +open Location + +(* Skip tokens to the end of the phrase *) + +let rec skip_phrase lexbuf = + try + match Lexer.token lexbuf with + Parser.SEMISEMI | Parser.EOF -> () + | _ -> skip_phrase lexbuf + with + | Lexer.Error (Lexer.Unterminated_comment, _) -> () + | Lexer.Error (Lexer.Unterminated_string, _) -> () + | Lexer.Error (Lexer.Unterminated_string_in_comment, _) -> () + | Lexer.Error (Lexer.Illegal_character _, _) -> skip_phrase lexbuf +;; + +let maybe_skip_phrase lexbuf = + if Parsing.is_current_lookahead Parser.SEMISEMI + || Parsing.is_current_lookahead Parser.EOF + then () + else skip_phrase lexbuf + +let wrap parsing_fun lexbuf = + try + let ast = parsing_fun Lexer.token lexbuf in + Parsing.clear_parser(); + ast + with + | Lexer.Error(Lexer.Unterminated_comment, _) as err -> raise err + | Lexer.Error(Lexer.Unterminated_string, _) as err -> raise err + | Lexer.Error(Lexer.Unterminated_string_in_comment, _) as err -> raise err + | Lexer.Error(Lexer.Illegal_character _, _) as err -> + if !Location.input_name = "" then skip_phrase lexbuf; + raise err + | Syntaxerr.Error _ as err -> + if !Location.input_name = "" then maybe_skip_phrase lexbuf; + raise err + | Parsing.Parse_error | Syntaxerr.Escape_error -> + let loc = Location.curr lexbuf in + if !Location.input_name = "" + then maybe_skip_phrase lexbuf; + raise(Syntaxerr.Error(Syntaxerr.Other loc)) +;; + +let implementation = wrap Parser.implementation +and interface = wrap Parser.interface +and toplevel_phrase = wrap Parser.toplevel_phrase +and use_file = wrap Parser.use_file diff --git a/parsing/parse.mli b/parsing/parse.mli new file mode 100644 index 0000000..dce86f8 --- /dev/null +++ b/parsing/parse.mli @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parse.mli,v 1.6 1999-11-17 18:58:19 xleroy Exp $ *) + +(* Entry points in the parser *) + +val implementation : Lexing.lexbuf -> Parsetree.structure +val interface : Lexing.lexbuf -> Parsetree.signature +val toplevel_phrase : Lexing.lexbuf -> Parsetree.toplevel_phrase +val use_file : Lexing.lexbuf -> Parsetree.toplevel_phrase list + diff --git a/parsing/parser.mly b/parsing/parser.mly new file mode 100644 index 0000000..884aa0a --- /dev/null +++ b/parsing/parser.mly @@ -0,0 +1,1536 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: parser.mly,v 1.131 2008-07-14 09:09:53 xleroy Exp $ */ + +/* The parser definition */ + +%{ +open Location +open Asttypes +open Longident +open Parsetree + +let mktyp d = + { ptyp_desc = d; ptyp_loc = symbol_rloc() } +let mkpat d = + { ppat_desc = d; ppat_loc = symbol_rloc() } +let mkexp d = + { pexp_desc = d; pexp_loc = symbol_rloc() } +let mkmty d = + { pmty_desc = d; pmty_loc = symbol_rloc() } +let mksig d = + { psig_desc = d; psig_loc = symbol_rloc() } +let mkmod d = + { pmod_desc = d; pmod_loc = symbol_rloc() } +let mkstr d = + { pstr_desc = d; pstr_loc = symbol_rloc() } +let mkfield d = + { pfield_desc = d; pfield_loc = symbol_rloc() } +let mkclass d = + { pcl_desc = d; pcl_loc = symbol_rloc() } +let mkcty d = + { pcty_desc = d; pcty_loc = symbol_rloc() } + +let reloc_pat x = { x with ppat_loc = symbol_rloc () };; +let reloc_exp x = { x with pexp_loc = symbol_rloc () };; + +let mkoperator name pos = + { pexp_desc = Pexp_ident(Lident name); pexp_loc = rhs_loc pos } + +(* + Ghost expressions and patterns: + expressions and patterns that do not appear explicitely in the + source file they have the loc_ghost flag set to true. + Then the profiler will not try to instrument them and the + -stypes option will not try to display their type. + + Every grammar rule that generates an element with a location must + make at most one non-ghost element, the topmost one. + + How to tell whether your location must be ghost: + A location corresponds to a range of characters in the source file. + If the location contains a piece of code that is syntactically + valid (according to the documentation), and corresponds to the + AST node, then the location must be real; in all other cases, + it must be ghost. +*) +let ghexp d = { pexp_desc = d; pexp_loc = symbol_gloc () };; +let ghpat d = { ppat_desc = d; ppat_loc = symbol_gloc () };; +let ghtyp d = { ptyp_desc = d; ptyp_loc = symbol_gloc () };; + +let mkassert e = + match e with + | {pexp_desc = Pexp_construct (Lident "false", None, false) } -> + mkexp (Pexp_assertfalse) + | _ -> mkexp (Pexp_assert (e)) +;; + +let mkinfix arg1 name arg2 = + mkexp(Pexp_apply(mkoperator name 2, ["", arg1; "", arg2])) + +let neg_float_string f = + if String.length f > 0 && f.[0] = '-' + then String.sub f 1 (String.length f - 1) + else "-" ^ f + +let mkuminus name arg = + match name, arg.pexp_desc with + | "-", Pexp_constant(Const_int n) -> + mkexp(Pexp_constant(Const_int(-n))) + | "-", Pexp_constant(Const_int32 n) -> + mkexp(Pexp_constant(Const_int32(Int32.neg n))) + | "-", Pexp_constant(Const_int64 n) -> + mkexp(Pexp_constant(Const_int64(Int64.neg n))) + | "-", Pexp_constant(Const_nativeint n) -> + mkexp(Pexp_constant(Const_nativeint(Nativeint.neg n))) + | _, Pexp_constant(Const_float f) -> + mkexp(Pexp_constant(Const_float(neg_float_string f))) + | _ -> + mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg])) + +let rec mktailexp = function + [] -> + ghexp(Pexp_construct(Lident "[]", None, false)) + | e1 :: el -> + let exp_el = mktailexp el in + let l = {loc_start = e1.pexp_loc.loc_start; + loc_end = exp_el.pexp_loc.loc_end; + loc_ghost = true} + in + let arg = {pexp_desc = Pexp_tuple [e1; exp_el]; pexp_loc = l} in + {pexp_desc = Pexp_construct(Lident "::", Some arg, false); pexp_loc = l} + +let rec mktailpat = function + [] -> + ghpat(Ppat_construct(Lident "[]", None, false)) + | p1 :: pl -> + let pat_pl = mktailpat pl in + let l = {loc_start = p1.ppat_loc.loc_start; + loc_end = pat_pl.ppat_loc.loc_end; + loc_ghost = true} + in + let arg = {ppat_desc = Ppat_tuple [p1; pat_pl]; ppat_loc = l} in + {ppat_desc = Ppat_construct(Lident "::", Some arg, false); ppat_loc = l} + +let ghstrexp e = + { pstr_desc = Pstr_eval e; pstr_loc = {e.pexp_loc with loc_ghost = true} } + +let array_function str name = + Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name)) + +let rec deep_mkrangepat c1 c2 = + if c1 = c2 then ghpat(Ppat_constant(Const_char c1)) else + ghpat(Ppat_or(ghpat(Ppat_constant(Const_char c1)), + deep_mkrangepat (Char.chr(Char.code c1 + 1)) c2)) + +let rec mkrangepat c1 c2 = + if c1 > c2 then mkrangepat c2 c1 else + if c1 = c2 then mkpat(Ppat_constant(Const_char c1)) else + reloc_pat (deep_mkrangepat c1 c2) + +let syntax_error () = + raise Syntaxerr.Escape_error + +let unclosed opening_name opening_num closing_name closing_num = + raise(Syntaxerr.Error(Syntaxerr.Unclosed(rhs_loc opening_num, opening_name, + rhs_loc closing_num, closing_name))) + +let bigarray_function str name = + Ldot(Ldot(Lident "Bigarray", str), name) + +let bigarray_untuplify = function + { pexp_desc = Pexp_tuple explist} -> explist + | exp -> [exp] + +let bigarray_get arr arg = + let get = if !Clflags.fast then "unsafe_get" else "get" in + match bigarray_untuplify arg with + [c1] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" get)), + ["", arr; "", c1])) + | [c1;c2] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" get)), + ["", arr; "", c1; "", c2])) + | [c1;c2;c3] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" get)), + ["", arr; "", c1; "", c2; "", c3])) + | coords -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "get")), + ["", arr; "", ghexp(Pexp_array coords)])) + +let bigarray_set arr arg newval = + let set = if !Clflags.fast then "unsafe_set" else "set" in + match bigarray_untuplify arg with + [c1] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" set)), + ["", arr; "", c1; "", newval])) + | [c1;c2] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" set)), + ["", arr; "", c1; "", c2; "", newval])) + | [c1;c2;c3] -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" set)), + ["", arr; "", c1; "", c2; "", c3; "", newval])) + | coords -> + mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "set")), + ["", arr; + "", ghexp(Pexp_array coords); + "", newval])) +%} + +/* Tokens */ + +%token AMPERAMPER +%token AMPERSAND +%token AND +%token AS +%token ASSERT +%token BACKQUOTE +%token BAR +%token BARBAR +%token BARRBRACKET +%token BEGIN +%token <char> CHAR +%token CLASS +%token COLON +%token COLONCOLON +%token COLONEQUAL +%token COLONGREATER +%token COMMA +%token CONSTRAINT +%token DO +%token DONE +%token DOT +%token DOTDOT +%token DOWNTO +%token ELSE +%token END +%token EOF +%token EQUAL +%token EXCEPTION +%token EXTERNAL +%token FALSE +%token <string> FLOAT +%token FOR +%token FUN +%token FUNCTION +%token FUNCTOR +%token GREATER +%token GREATERRBRACE +%token GREATERRBRACKET +%token IF +%token IN +%token INCLUDE +%token <string> INFIXOP0 +%token <string> INFIXOP1 +%token <string> INFIXOP2 +%token <string> INFIXOP3 +%token <string> INFIXOP4 +%token INHERIT +%token INITIALIZER +%token <int> INT +%token <int32> INT32 +%token <int64> INT64 +%token <string> LABEL +%token LAZY +%token LBRACE +%token LBRACELESS +%token LBRACKET +%token LBRACKETBAR +%token LBRACKETLESS +%token LBRACKETGREATER +%token LESS +%token LESSMINUS +%token LET +%token <string> LIDENT +%token LPAREN +%token MATCH +%token METHOD +%token MINUS +%token MINUSDOT +%token MINUSGREATER +%token MODULE +%token MUTABLE +%token <nativeint> NATIVEINT +%token NEW +%token OBJECT +%token OF +%token OPEN +%token <string> OPTLABEL +%token OR +/* %token PARSER */ +%token PLUS +%token <string> PREFIXOP +%token PRIVATE +%token QUESTION +%token QUESTIONQUESTION +%token QUOTE +%token RBRACE +%token RBRACKET +%token REC +%token RPAREN +%token SEMI +%token SEMISEMI +%token SHARP +%token SIG +%token STAR +%token <string> STRING +%token STRUCT +%token THEN +%token TILDE +%token TO +%token TRUE +%token TRY +%token TYPE +%token <string> UIDENT +%token UNDERSCORE +%token VAL +%token VIRTUAL +%token WHEN +%token WHILE +%token WITH + +/* Precedences and associativities. + +Tokens and rules have precedences. A reduce/reduce conflict is resolved +in favor of the first rule (in source file order). A shift/reduce conflict +is resolved by comparing the precedence and associativity of the token to +be shifted with those of the rule to be reduced. + +By default, a rule has the precedence of its rightmost terminal (if any). + +When there is a shift/reduce conflict between a rule and a token that +have the same precedence, it is resolved using the associativity: +if the token is left-associative, the parser will reduce; if +right-associative, the parser will shift; if non-associative, +the parser will declare a syntax error. + +We will only use associativities with operators of the kind x * x -> x +for example, in the rules of the form expr: expr BINOP expr +in all other cases, we define two precedences if needed to resolve +conflicts. + +The precedences must be listed from low to high. +*/ + +%nonassoc IN +%nonassoc below_SEMI +%nonassoc SEMI /* below EQUAL ({lbl=...; lbl=...}) */ +%nonassoc LET /* above SEMI ( ...; let ... in ...) */ +%nonassoc below_WITH +%nonassoc FUNCTION WITH /* below BAR (match ... with ...) */ +%nonassoc AND /* above WITH (module rec A: SIG with ... and ...) */ +%nonassoc THEN /* below ELSE (if ... then ...) */ +%nonassoc ELSE /* (if ... then ... else ...) */ +%nonassoc LESSMINUS /* below COLONEQUAL (lbl <- x := e) */ +%right COLONEQUAL /* expr (e := e := e) */ +%nonassoc AS +%left BAR /* pattern (p|p|p) */ +%nonassoc below_COMMA +%left COMMA /* expr/expr_comma_list (e,e,e) */ +%right MINUSGREATER /* core_type2 (t -> t -> t) */ +%right OR BARBAR /* expr (e || e || e) */ +%right AMPERSAND AMPERAMPER /* expr (e && e && e) */ +%nonassoc below_EQUAL +%left INFIXOP0 EQUAL LESS GREATER /* expr (e OP e OP e) */ +%right INFIXOP1 /* expr (e OP e OP e) */ +%right COLONCOLON /* expr (e :: e :: e) */ +%left INFIXOP2 PLUS MINUS MINUSDOT /* expr (e OP e OP e) */ +%left INFIXOP3 STAR /* expr (e OP e OP e) */ +%right INFIXOP4 /* expr (e OP e OP e) */ +%nonassoc prec_unary_minus /* unary - */ +%nonassoc prec_constant_constructor /* cf. simple_expr (C versus C x) */ +%nonassoc prec_constr_appl /* above AS BAR COLONCOLON COMMA */ +%nonassoc below_SHARP +%nonassoc SHARP /* simple_expr/toplevel_directive */ +%nonassoc below_DOT +%nonassoc DOT +/* Finally, the first tokens of simple_expr are above everything else. */ +%nonassoc BACKQUOTE BEGIN CHAR FALSE FLOAT INT INT32 INT64 + LBRACE LBRACELESS LBRACKET LBRACKETBAR LIDENT LPAREN + NEW NATIVEINT PREFIXOP STRING TRUE UIDENT + + +/* Entry points */ + +%start implementation /* for implementation files */ +%type <Parsetree.structure> implementation +%start interface /* for interface files */ +%type <Parsetree.signature> interface +%start toplevel_phrase /* for interactive use */ +%type <Parsetree.toplevel_phrase> toplevel_phrase +%start use_file /* for the #use directive */ +%type <Parsetree.toplevel_phrase list> use_file + +%% + +/* Entry points */ + +implementation: + structure EOF { $1 } +; +interface: + signature EOF { List.rev $1 } +; +toplevel_phrase: + top_structure SEMISEMI { Ptop_def $1 } + | seq_expr SEMISEMI { Ptop_def[ghstrexp $1] } + | toplevel_directive SEMISEMI { $1 } + | EOF { raise End_of_file } +; +top_structure: + structure_item { [$1] } + | structure_item top_structure { $1 :: $2 } +; +use_file: + use_file_tail { $1 } + | seq_expr use_file_tail { Ptop_def[ghstrexp $1] :: $2 } +; +use_file_tail: + EOF { [] } + | SEMISEMI EOF { [] } + | SEMISEMI seq_expr use_file_tail { Ptop_def[ghstrexp $2] :: $3 } + | SEMISEMI structure_item use_file_tail { Ptop_def[$2] :: $3 } + | SEMISEMI toplevel_directive use_file_tail { $2 :: $3 } + | structure_item use_file_tail { Ptop_def[$1] :: $2 } + | toplevel_directive use_file_tail { $1 :: $2 } +; + +/* Module expressions */ + +module_expr: + mod_longident + { mkmod(Pmod_ident $1) } + | STRUCT structure END + { mkmod(Pmod_structure($2)) } + | STRUCT structure error + { unclosed "struct" 1 "end" 3 } + | FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_expr + { mkmod(Pmod_functor($3, $5, $8)) } + | module_expr LPAREN module_expr RPAREN + { mkmod(Pmod_apply($1, $3)) } + | module_expr LPAREN module_expr error + { unclosed "(" 2 ")" 4 } + | LPAREN module_expr COLON module_type RPAREN + { mkmod(Pmod_constraint($2, $4)) } + | LPAREN module_expr COLON module_type error + { unclosed "(" 1 ")" 5 } + | LPAREN module_expr RPAREN + { $2 } + | LPAREN module_expr error + { unclosed "(" 1 ")" 3 } +; +structure: + structure_tail { $1 } + | seq_expr structure_tail { ghstrexp $1 :: $2 } +; +structure_tail: + /* empty */ { [] } + | SEMISEMI { [] } + | SEMISEMI seq_expr structure_tail { ghstrexp $2 :: $3 } + | SEMISEMI structure_item structure_tail { $2 :: $3 } + | structure_item structure_tail { $1 :: $2 } +; +structure_item: + LET rec_flag let_bindings + { match $3 with + [{ppat_desc = Ppat_any}, exp] -> mkstr(Pstr_eval exp) + | _ -> mkstr(Pstr_value($2, List.rev $3)) } + | EXTERNAL val_ident COLON core_type EQUAL primitive_declaration + { mkstr(Pstr_primitive($2, {pval_type = $4; pval_prim = $6})) } + | TYPE type_declarations + { mkstr(Pstr_type(List.rev $2)) } + | EXCEPTION UIDENT constructor_arguments + { mkstr(Pstr_exception($2, $3)) } + | EXCEPTION UIDENT EQUAL constr_longident + { mkstr(Pstr_exn_rebind($2, $4)) } + | MODULE UIDENT module_binding + { mkstr(Pstr_module($2, $3)) } + | MODULE REC module_rec_bindings + { mkstr(Pstr_recmodule(List.rev $3)) } + | MODULE TYPE ident EQUAL module_type + { mkstr(Pstr_modtype($3, $5)) } + | OPEN mod_longident + { mkstr(Pstr_open $2) } + | CLASS class_declarations + { mkstr(Pstr_class (List.rev $2)) } + | CLASS TYPE class_type_declarations + { mkstr(Pstr_class_type (List.rev $3)) } + | INCLUDE module_expr + { mkstr(Pstr_include $2) } +; +module_binding: + EQUAL module_expr + { $2 } + | COLON module_type EQUAL module_expr + { mkmod(Pmod_constraint($4, $2)) } + | LPAREN UIDENT COLON module_type RPAREN module_binding + { mkmod(Pmod_functor($2, $4, $6)) } +; +module_rec_bindings: + module_rec_binding { [$1] } + | module_rec_bindings AND module_rec_binding { $3 :: $1 } +; +module_rec_binding: + UIDENT COLON module_type EQUAL module_expr { ($1, $3, $5) } +; + +/* Module types */ + +module_type: + mty_longident + { mkmty(Pmty_ident $1) } + | SIG signature END + { mkmty(Pmty_signature(List.rev $2)) } + | SIG signature error + { unclosed "sig" 1 "end" 3 } + | FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_type + %prec below_WITH + { mkmty(Pmty_functor($3, $5, $8)) } + | module_type WITH with_constraints + { mkmty(Pmty_with($1, List.rev $3)) } + | LPAREN module_type RPAREN + { $2 } + | LPAREN module_type error + { unclosed "(" 1 ")" 3 } +; +signature: + /* empty */ { [] } + | signature signature_item { $2 :: $1 } + | signature signature_item SEMISEMI { $2 :: $1 } +; +signature_item: + VAL val_ident COLON core_type + { mksig(Psig_value($2, {pval_type = $4; pval_prim = []})) } + | EXTERNAL val_ident COLON core_type EQUAL primitive_declaration + { mksig(Psig_value($2, {pval_type = $4; pval_prim = $6})) } + | TYPE type_declarations + { mksig(Psig_type(List.rev $2)) } + | EXCEPTION UIDENT constructor_arguments + { mksig(Psig_exception($2, $3)) } + | MODULE UIDENT module_declaration + { mksig(Psig_module($2, $3)) } + | MODULE REC module_rec_declarations + { mksig(Psig_recmodule(List.rev $3)) } + | MODULE TYPE ident + { mksig(Psig_modtype($3, Pmodtype_abstract)) } + | MODULE TYPE ident EQUAL module_type + { mksig(Psig_modtype($3, Pmodtype_manifest $5)) } + | OPEN mod_longident + { mksig(Psig_open $2) } + | INCLUDE module_type + { mksig(Psig_include $2) } + | CLASS class_descriptions + { mksig(Psig_class (List.rev $2)) } + | CLASS TYPE class_type_declarations + { mksig(Psig_class_type (List.rev $3)) } +; + +module_declaration: + COLON module_type + { $2 } + | LPAREN UIDENT COLON module_type RPAREN module_declaration + { mkmty(Pmty_functor($2, $4, $6)) } +; +module_rec_declarations: + module_rec_declaration { [$1] } + | module_rec_declarations AND module_rec_declaration { $3 :: $1 } +; +module_rec_declaration: + UIDENT COLON module_type { ($1, $3) } +; + +/* Class expressions */ + +class_declarations: + class_declarations AND class_declaration { $3 :: $1 } + | class_declaration { [$1] } +; +class_declaration: + virtual_flag class_type_parameters LIDENT class_fun_binding + { let params, variance = List.split (fst $2) in + {pci_virt = $1; pci_params = params, snd $2; + pci_name = $3; pci_expr = $4; pci_variance = variance; + pci_loc = symbol_rloc ()} } +; +class_fun_binding: + EQUAL class_expr + { $2 } + | COLON class_type EQUAL class_expr + { mkclass(Pcl_constraint($4, $2)) } + | labeled_simple_pattern class_fun_binding + { let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $2)) } +; +class_type_parameters: + /*empty*/ { [], symbol_gloc () } + | LBRACKET type_parameter_list RBRACKET { List.rev $2, symbol_rloc () } +; +class_fun_def: + labeled_simple_pattern MINUSGREATER class_expr + { let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $3)) } + | labeled_simple_pattern class_fun_def + { let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $2)) } +; +class_expr: + class_simple_expr + { $1 } + | FUN class_fun_def + { $2 } + | class_simple_expr simple_labeled_expr_list + { mkclass(Pcl_apply($1, List.rev $2)) } + | LET rec_flag let_bindings IN class_expr + { mkclass(Pcl_let ($2, List.rev $3, $5)) } +; +class_simple_expr: + LBRACKET core_type_comma_list RBRACKET class_longident + { mkclass(Pcl_constr($4, List.rev $2)) } + | class_longident + { mkclass(Pcl_constr($1, [])) } + | OBJECT class_structure END + { mkclass(Pcl_structure($2)) } + | OBJECT class_structure error + { unclosed "object" 1 "end" 3 } + | LPAREN class_expr COLON class_type RPAREN + { mkclass(Pcl_constraint($2, $4)) } + | LPAREN class_expr COLON class_type error + { unclosed "(" 1 ")" 5 } + | LPAREN class_expr RPAREN + { $2 } + | LPAREN class_expr error + { unclosed "(" 1 ")" 3 } +; +class_structure: + class_self_pattern class_fields + { $1, List.rev $2 } +; +class_self_pattern: + LPAREN pattern RPAREN + { reloc_pat $2 } + | LPAREN pattern COLON core_type RPAREN + { mkpat(Ppat_constraint($2, $4)) } + | /* empty */ + { ghpat(Ppat_any) } +; +class_fields: + /* empty */ + { [] } + | class_fields INHERIT class_expr parent_binder + { Pcf_inher ($3, $4) :: $1 } + | class_fields VAL virtual_value + { Pcf_valvirt $3 :: $1 } + | class_fields VAL value + { Pcf_val $3 :: $1 } + | class_fields virtual_method + { Pcf_virt $2 :: $1 } + | class_fields concrete_method + { Pcf_meth $2 :: $1 } + | class_fields CONSTRAINT constrain + { Pcf_cstr $3 :: $1 } + | class_fields INITIALIZER seq_expr + { Pcf_init $3 :: $1 } +; +parent_binder: + AS LIDENT + { Some $2 } + | /* empty */ + { None } +; +virtual_value: + MUTABLE VIRTUAL label COLON core_type + { $3, Mutable, $5, symbol_rloc () } + | VIRTUAL mutable_flag label COLON core_type + { $3, $2, $5, symbol_rloc () } +; +value: + mutable_flag label EQUAL seq_expr + { $2, $1, $4, symbol_rloc () } + | mutable_flag label type_constraint EQUAL seq_expr + { $2, $1, (let (t, t') = $3 in ghexp(Pexp_constraint($5, t, t'))), + symbol_rloc () } +; +virtual_method: + METHOD PRIVATE VIRTUAL label COLON poly_type + { $4, Private, $6, symbol_rloc () } + | METHOD VIRTUAL private_flag label COLON poly_type + { $4, $3, $6, symbol_rloc () } +; +concrete_method : + METHOD private_flag label strict_binding + { $3, $2, ghexp(Pexp_poly ($4, None)), symbol_rloc () } + | METHOD private_flag label COLON poly_type EQUAL seq_expr + { $3, $2, ghexp(Pexp_poly($7,Some $5)), symbol_rloc () } +; + +/* Class types */ + +class_type: + class_signature + { $1 } + | QUESTION LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type + { mkcty(Pcty_fun("?" ^ $2 , + {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$4]); + ptyp_loc = $4.ptyp_loc}, + $6)) } + | OPTLABEL simple_core_type_or_tuple MINUSGREATER class_type + { mkcty(Pcty_fun("?" ^ $1 , + {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$2]); + ptyp_loc = $2.ptyp_loc}, + $4)) } + | LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type + { mkcty(Pcty_fun($1, $3, $5)) } + | simple_core_type_or_tuple MINUSGREATER class_type + { mkcty(Pcty_fun("", $1, $3)) } +; +class_signature: + LBRACKET core_type_comma_list RBRACKET clty_longident + { mkcty(Pcty_constr ($4, List.rev $2)) } + | clty_longident + { mkcty(Pcty_constr ($1, [])) } + | OBJECT class_sig_body END + { mkcty(Pcty_signature $2) } + | OBJECT class_sig_body error + { unclosed "object" 1 "end" 3 } +; +class_sig_body: + class_self_type class_sig_fields + { $1, List.rev $2 } +; +class_self_type: + LPAREN core_type RPAREN + { $2 } + | /* empty */ + { mktyp(Ptyp_any) } +; +class_sig_fields: + /* empty */ { [] } + | class_sig_fields INHERIT class_signature { Pctf_inher $3 :: $1 } + | class_sig_fields VAL value_type { Pctf_val $3 :: $1 } + | class_sig_fields virtual_method { Pctf_virt $2 :: $1 } + | class_sig_fields method_type { Pctf_meth $2 :: $1 } + | class_sig_fields CONSTRAINT constrain { Pctf_cstr $3 :: $1 } +; +value_type: + VIRTUAL mutable_flag label COLON core_type + { $3, $2, Virtual, $5, symbol_rloc () } + | MUTABLE virtual_flag label COLON core_type + { $3, Mutable, $2, $5, symbol_rloc () } + | label COLON core_type + { $1, Immutable, Concrete, $3, symbol_rloc () } +; +method_type: + METHOD private_flag label COLON poly_type + { $3, $2, $5, symbol_rloc () } +; +constrain: + core_type EQUAL core_type { $1, $3, symbol_rloc () } +; +class_descriptions: + class_descriptions AND class_description { $3 :: $1 } + | class_description { [$1] } +; +class_description: + virtual_flag class_type_parameters LIDENT COLON class_type + { let params, variance = List.split (fst $2) in + {pci_virt = $1; pci_params = params, snd $2; + pci_name = $3; pci_expr = $5; pci_variance = variance; + pci_loc = symbol_rloc ()} } +; +class_type_declarations: + class_type_declarations AND class_type_declaration { $3 :: $1 } + | class_type_declaration { [$1] } +; +class_type_declaration: + virtual_flag class_type_parameters LIDENT EQUAL class_signature + { let params, variance = List.split (fst $2) in + {pci_virt = $1; pci_params = params, snd $2; + pci_name = $3; pci_expr = $5; pci_variance = variance; + pci_loc = symbol_rloc ()} } +; + +/* Core expressions */ + +seq_expr: + | expr %prec below_SEMI { $1 } + | expr SEMI { reloc_exp $1 } + | expr SEMI seq_expr { mkexp(Pexp_sequence($1, $3)) } +; +labeled_simple_pattern: + QUESTION LPAREN label_let_pattern opt_default RPAREN + { ("?" ^ fst $3, $4, snd $3) } + | QUESTION label_var + { ("?" ^ fst $2, None, snd $2) } + | OPTLABEL LPAREN let_pattern opt_default RPAREN + { ("?" ^ $1, $4, $3) } + | OPTLABEL pattern_var + { ("?" ^ $1, None, $2) } + | TILDE LPAREN label_let_pattern RPAREN + { (fst $3, None, snd $3) } + | TILDE label_var + { (fst $2, None, snd $2) } + | LABEL simple_pattern + { ($1, None, $2) } + | simple_pattern + { ("", None, $1) } +; +pattern_var: + LIDENT { mkpat(Ppat_var $1) } + | UNDERSCORE { mkpat Ppat_any } +; +opt_default: + /* empty */ { None } + | EQUAL seq_expr { Some $2 } +; +label_let_pattern: + label_var + { $1 } + | label_var COLON core_type + { let (lab, pat) = $1 in (lab, mkpat(Ppat_constraint(pat, $3))) } +; +label_var: + LIDENT { ($1, mkpat(Ppat_var $1)) } +; +let_pattern: + pattern + { $1 } + | pattern COLON core_type + { mkpat(Ppat_constraint($1, $3)) } +; +expr: + simple_expr %prec below_SHARP + { $1 } + | simple_expr simple_labeled_expr_list + { mkexp(Pexp_apply($1, List.rev $2)) } + | LET rec_flag let_bindings IN seq_expr + { mkexp(Pexp_let($2, List.rev $3, $5)) } + | LET MODULE UIDENT module_binding IN seq_expr + { mkexp(Pexp_letmodule($3, $4, $6)) } + | FUNCTION opt_bar match_cases + { mkexp(Pexp_function("", None, List.rev $3)) } + | FUN labeled_simple_pattern fun_def + { let (l,o,p) = $2 in mkexp(Pexp_function(l, o, [p, $3])) } + | MATCH seq_expr WITH opt_bar match_cases + { mkexp(Pexp_match($2, List.rev $5)) } + | TRY seq_expr WITH opt_bar match_cases + { mkexp(Pexp_try($2, List.rev $5)) } + | TRY seq_expr WITH error + { syntax_error() } + | expr_comma_list %prec below_COMMA + { mkexp(Pexp_tuple(List.rev $1)) } + | constr_longident simple_expr %prec below_SHARP + { mkexp(Pexp_construct($1, Some $2, false)) } + | name_tag simple_expr %prec below_SHARP + { mkexp(Pexp_variant($1, Some $2)) } + | IF seq_expr THEN expr ELSE expr + { mkexp(Pexp_ifthenelse($2, $4, Some $6)) } + | IF seq_expr THEN expr + { mkexp(Pexp_ifthenelse($2, $4, None)) } + | WHILE seq_expr DO seq_expr DONE + { mkexp(Pexp_while($2, $4)) } + | FOR val_ident EQUAL seq_expr direction_flag seq_expr DO seq_expr DONE + { mkexp(Pexp_for($2, $4, $6, $5, $8)) } + | expr COLONCOLON expr + { mkexp(Pexp_construct(Lident "::", + Some(ghexp(Pexp_tuple[$1;$3])), + false)) } + | LPAREN COLONCOLON RPAREN LPAREN expr COMMA expr RPAREN + { mkexp(Pexp_construct(Lident "::", + Some(ghexp(Pexp_tuple[$5;$7])), + false)) } + | expr INFIXOP0 expr + { mkinfix $1 $2 $3 } + | expr INFIXOP1 expr + { mkinfix $1 $2 $3 } + | expr INFIXOP2 expr + { mkinfix $1 $2 $3 } + | expr INFIXOP3 expr + { mkinfix $1 $2 $3 } + | expr INFIXOP4 expr + { mkinfix $1 $2 $3 } + | expr PLUS expr + { mkinfix $1 "+" $3 } + | expr MINUS expr + { mkinfix $1 "-" $3 } + | expr MINUSDOT expr + { mkinfix $1 "-." $3 } + | expr STAR expr + { mkinfix $1 "*" $3 } + | expr EQUAL expr + { mkinfix $1 "=" $3 } + | expr LESS expr + { mkinfix $1 "<" $3 } + | expr GREATER expr + { mkinfix $1 ">" $3 } + | expr OR expr + { mkinfix $1 "or" $3 } + | expr BARBAR expr + { mkinfix $1 "||" $3 } + | expr AMPERSAND expr + { mkinfix $1 "&" $3 } + | expr AMPERAMPER expr + { mkinfix $1 "&&" $3 } + | expr COLONEQUAL expr + { mkinfix $1 ":=" $3 } + | subtractive expr %prec prec_unary_minus + { mkuminus $1 $2 } + | simple_expr DOT label_longident LESSMINUS expr + { mkexp(Pexp_setfield($1, $3, $5)) } + | simple_expr DOT LPAREN seq_expr RPAREN LESSMINUS expr + { mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "set")), + ["",$1; "",$4; "",$7])) } + | simple_expr DOT LBRACKET seq_expr RBRACKET LESSMINUS expr + { mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "set")), + ["",$1; "",$4; "",$7])) } + | simple_expr DOT LBRACE expr RBRACE LESSMINUS expr + { bigarray_set $1 $4 $7 } + | label LESSMINUS expr + { mkexp(Pexp_setinstvar($1, $3)) } + | ASSERT simple_expr %prec below_SHARP + { mkassert $2 } + | LAZY simple_expr %prec below_SHARP + { mkexp (Pexp_lazy ($2)) } + | OBJECT class_structure END + { mkexp (Pexp_object($2)) } + | OBJECT class_structure error + { unclosed "object" 1 "end" 3 } +; +simple_expr: + val_longident + { mkexp(Pexp_ident $1) } + | constant + { mkexp(Pexp_constant $1) } + | constr_longident %prec prec_constant_constructor + { mkexp(Pexp_construct($1, None, false)) } + | name_tag %prec prec_constant_constructor + { mkexp(Pexp_variant($1, None)) } + | LPAREN seq_expr RPAREN + { reloc_exp $2 } + | LPAREN seq_expr error + { unclosed "(" 1 ")" 3 } + | BEGIN seq_expr END + { reloc_exp $2 } + | BEGIN END + { mkexp (Pexp_construct (Lident "()", None, false)) } + | BEGIN seq_expr error + { unclosed "begin" 1 "end" 3 } + | LPAREN seq_expr type_constraint RPAREN + { let (t, t') = $3 in mkexp(Pexp_constraint($2, t, t')) } + | simple_expr DOT label_longident + { mkexp(Pexp_field($1, $3)) } + | simple_expr DOT LPAREN seq_expr RPAREN + { mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "get")), + ["",$1; "",$4])) } + | simple_expr DOT LPAREN seq_expr error + { unclosed "(" 3 ")" 5 } + | simple_expr DOT LBRACKET seq_expr RBRACKET + { mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "get")), + ["",$1; "",$4])) } + | simple_expr DOT LBRACKET seq_expr error + { unclosed "[" 3 "]" 5 } + | simple_expr DOT LBRACE expr RBRACE + { bigarray_get $1 $4 } + | simple_expr DOT LBRACE expr_comma_list error + { unclosed "{" 3 "}" 5 } + | LBRACE record_expr RBRACE + { let (exten, fields) = $2 in mkexp(Pexp_record(fields, exten)) } + | LBRACE record_expr error + { unclosed "{" 1 "}" 3 } + | LBRACKETBAR expr_semi_list opt_semi BARRBRACKET + { mkexp(Pexp_array(List.rev $2)) } + | LBRACKETBAR expr_semi_list opt_semi error + { unclosed "[|" 1 "|]" 4 } + | LBRACKETBAR BARRBRACKET + { mkexp(Pexp_array []) } + | LBRACKET expr_semi_list opt_semi RBRACKET + { reloc_exp (mktailexp (List.rev $2)) } + | LBRACKET expr_semi_list opt_semi error + { unclosed "[" 1 "]" 4 } + | PREFIXOP simple_expr + { mkexp(Pexp_apply(mkoperator $1 1, ["",$2])) } + | NEW class_longident + { mkexp(Pexp_new($2)) } + | LBRACELESS field_expr_list opt_semi GREATERRBRACE + { mkexp(Pexp_override(List.rev $2)) } + | LBRACELESS field_expr_list opt_semi error + { unclosed "{<" 1 ">}" 4 } + | LBRACELESS GREATERRBRACE + { mkexp(Pexp_override []) } + | simple_expr SHARP label + { mkexp(Pexp_send($1, $3)) } +; +simple_labeled_expr_list: + labeled_simple_expr + { [$1] } + | simple_labeled_expr_list labeled_simple_expr + { $2 :: $1 } +; +labeled_simple_expr: + simple_expr %prec below_SHARP + { ("", $1) } + | label_expr + { $1 } +; +label_expr: + LABEL simple_expr %prec below_SHARP + { ($1, $2) } + | TILDE label_ident + { $2 } + | QUESTION label_ident + { ("?" ^ fst $2, snd $2) } + | OPTLABEL simple_expr %prec below_SHARP + { ("?" ^ $1, $2) } +; +label_ident: + LIDENT { ($1, mkexp(Pexp_ident(Lident $1))) } +; +let_bindings: + let_binding { [$1] } + | let_bindings AND let_binding { $3 :: $1 } +; +let_binding: + val_ident fun_binding + { ({ppat_desc = Ppat_var $1; ppat_loc = rhs_loc 1}, $2) } + | pattern EQUAL seq_expr + { ($1, $3) } +; +fun_binding: + strict_binding + { $1 } + | type_constraint EQUAL seq_expr + { let (t, t') = $1 in ghexp(Pexp_constraint($3, t, t')) } +; +strict_binding: + EQUAL seq_expr + { $2 } + | labeled_simple_pattern fun_binding + { let (l, o, p) = $1 in ghexp(Pexp_function(l, o, [p, $2])) } +; +match_cases: + pattern match_action { [$1, $2] } + | match_cases BAR pattern match_action { ($3, $4) :: $1 } +; +fun_def: + match_action { $1 } + | labeled_simple_pattern fun_def + { let (l,o,p) = $1 in ghexp(Pexp_function(l, o, [p, $2])) } +; +match_action: + MINUSGREATER seq_expr { $2 } + | WHEN seq_expr MINUSGREATER seq_expr { mkexp(Pexp_when($2, $4)) } +; +expr_comma_list: + expr_comma_list COMMA expr { $3 :: $1 } + | expr COMMA expr { [$3; $1] } +; +record_expr: + simple_expr WITH lbl_expr_list opt_semi { (Some $1, List.rev $3) } + | lbl_expr_list opt_semi { (None, List.rev $1) } +; +lbl_expr_list: + label_longident EQUAL expr + { [$1,$3] } + | lbl_expr_list SEMI label_longident EQUAL expr + { ($3, $5) :: $1 } +; +field_expr_list: + label EQUAL expr + { [$1,$3] } + | field_expr_list SEMI label EQUAL expr + { ($3, $5) :: $1 } +; +expr_semi_list: + expr { [$1] } + | expr_semi_list SEMI expr { $3 :: $1 } +; +type_constraint: + COLON core_type { (Some $2, None) } + | COLON core_type COLONGREATER core_type { (Some $2, Some $4) } + | COLONGREATER core_type { (None, Some $2) } + | COLON error { syntax_error() } + | COLONGREATER error { syntax_error() } +; + +/* Patterns */ + +pattern: + simple_pattern + { $1 } + | pattern AS val_ident + { mkpat(Ppat_alias($1, $3)) } + | pattern_comma_list %prec below_COMMA + { mkpat(Ppat_tuple(List.rev $1)) } + | constr_longident pattern %prec prec_constr_appl + { mkpat(Ppat_construct($1, Some $2, false)) } + | name_tag pattern %prec prec_constr_appl + { mkpat(Ppat_variant($1, Some $2)) } + | pattern COLONCOLON pattern + { mkpat(Ppat_construct(Lident "::", Some(ghpat(Ppat_tuple[$1;$3])), + false)) } + | LPAREN COLONCOLON RPAREN LPAREN pattern COMMA pattern RPAREN + { mkpat(Ppat_construct(Lident "::", Some(ghpat(Ppat_tuple[$5;$7])), + false)) } + | pattern BAR pattern + { mkpat(Ppat_or($1, $3)) } + | LAZY simple_pattern + { mkpat(Ppat_lazy $2) } +; +simple_pattern: + val_ident %prec below_EQUAL + { mkpat(Ppat_var $1) } + | UNDERSCORE + { mkpat(Ppat_any) } + | signed_constant + { mkpat(Ppat_constant $1) } + | CHAR DOTDOT CHAR + { mkrangepat $1 $3 } + | constr_longident + { mkpat(Ppat_construct($1, None, false)) } + | name_tag + { mkpat(Ppat_variant($1, None)) } + | SHARP type_longident + { mkpat(Ppat_type $2) } + | LBRACE lbl_pattern_list opt_semi RBRACE + { mkpat(Ppat_record(List.rev $2)) } + | LBRACE lbl_pattern_list opt_semi error + { unclosed "{" 1 "}" 4 } + | LBRACKET pattern_semi_list opt_semi RBRACKET + { reloc_pat (mktailpat (List.rev $2)) } + | LBRACKET pattern_semi_list opt_semi error + { unclosed "[" 1 "]" 4 } + | LBRACKETBAR pattern_semi_list opt_semi BARRBRACKET + { mkpat(Ppat_array(List.rev $2)) } + | LBRACKETBAR BARRBRACKET + { mkpat(Ppat_array []) } + | LBRACKETBAR pattern_semi_list opt_semi error + { unclosed "[|" 1 "|]" 4 } + | LPAREN pattern RPAREN + { reloc_pat $2 } + | LPAREN pattern error + { unclosed "(" 1 ")" 3 } + | LPAREN pattern COLON core_type RPAREN + { mkpat(Ppat_constraint($2, $4)) } + | LPAREN pattern COLON core_type error + { unclosed "(" 1 ")" 5 } +; + +pattern_comma_list: + pattern_comma_list COMMA pattern { $3 :: $1 } + | pattern COMMA pattern { [$3; $1] } +; +pattern_semi_list: + pattern { [$1] } + | pattern_semi_list SEMI pattern { $3 :: $1 } +; +lbl_pattern_list: + label_longident EQUAL pattern { [($1, $3)] } + | lbl_pattern_list SEMI label_longident EQUAL pattern { ($3, $5) :: $1 } +; + +/* Primitive declarations */ + +primitive_declaration: + STRING { [$1] } + | STRING primitive_declaration { $1 :: $2 } +; + +/* Type declarations */ + +type_declarations: + type_declaration { [$1] } + | type_declarations AND type_declaration { $3 :: $1 } +; + +type_declaration: + type_parameters LIDENT type_kind constraints + { let (params, variance) = List.split $1 in + let (kind, private_flag, manifest) = $3 in + ($2, {ptype_params = params; + ptype_cstrs = List.rev $4; + ptype_kind = kind; + ptype_private = private_flag; + ptype_manifest = manifest; + ptype_variance = variance; + ptype_loc = symbol_rloc()}) } +; +constraints: + constraints CONSTRAINT constrain { $3 :: $1 } + | /* empty */ { [] } +; +type_kind: + /*empty*/ + { (Ptype_abstract, Public, None) } + | EQUAL core_type + { (Ptype_abstract, Public, Some $2) } + | EQUAL constructor_declarations + { (Ptype_variant(List.rev $2), Public, None) } + | EQUAL PRIVATE constructor_declarations + { (Ptype_variant(List.rev $3), Private, None) } + | EQUAL private_flag BAR constructor_declarations + { (Ptype_variant(List.rev $4), $2, None) } + | EQUAL private_flag LBRACE label_declarations opt_semi RBRACE + { (Ptype_record(List.rev $4), $2, None) } + | EQUAL core_type EQUAL private_flag opt_bar constructor_declarations + { (Ptype_variant(List.rev $6), $4, Some $2) } + | EQUAL core_type EQUAL private_flag LBRACE label_declarations opt_semi RBRACE + { (Ptype_record(List.rev $6), $4, Some $2) } + | EQUAL PRIVATE core_type + { (Ptype_abstract, Private, Some $3) } +; +type_parameters: + /*empty*/ { [] } + | type_parameter { [$1] } + | LPAREN type_parameter_list RPAREN { List.rev $2 } +; +type_parameter: + type_variance QUOTE ident { $3, $1 } +; +type_variance: + /* empty */ { false, false } + | PLUS { true, false } + | MINUS { false, true } +; +type_parameter_list: + type_parameter { [$1] } + | type_parameter_list COMMA type_parameter { $3 :: $1 } +; +constructor_declarations: + constructor_declaration { [$1] } + | constructor_declarations BAR constructor_declaration { $3 :: $1 } +; +constructor_declaration: + constr_ident constructor_arguments { ($1, $2, symbol_rloc()) } +; +constructor_arguments: + /*empty*/ { [] } + | OF core_type_list { List.rev $2 } +; +label_declarations: + label_declaration { [$1] } + | label_declarations SEMI label_declaration { $3 :: $1 } +; +label_declaration: + mutable_flag label COLON poly_type { ($2, $1, $4, symbol_rloc()) } +; + +/* "with" constraints (additional type equations over signature components) */ + +with_constraints: + with_constraint { [$1] } + | with_constraints AND with_constraint { $3 :: $1 } +; +with_constraint: + TYPE type_parameters label_longident with_type_binder core_type constraints + { let params, variance = List.split $2 in + ($3, Pwith_type {ptype_params = params; + ptype_cstrs = List.rev $6; + ptype_kind = Ptype_abstract; + ptype_manifest = Some $5; + ptype_private = $4; + ptype_variance = variance; + ptype_loc = symbol_rloc()}) } + /* used label_longident instead of type_longident to disallow + functor applications in type path */ + | MODULE mod_longident EQUAL mod_ext_longident + { ($2, Pwith_module $4) } +; +with_type_binder: + EQUAL { Public } + | EQUAL PRIVATE { Private } +; + +/* Polymorphic types */ + +typevar_list: + QUOTE ident { [$2] } + | typevar_list QUOTE ident { $3 :: $1 } +; +poly_type: + core_type + { mktyp(Ptyp_poly([], $1)) } + | typevar_list DOT core_type + { mktyp(Ptyp_poly(List.rev $1, $3)) } +; + +/* Core types */ + +core_type: + core_type2 + { $1 } + | core_type2 AS QUOTE ident + { mktyp(Ptyp_alias($1, $4)) } +; +core_type2: + simple_core_type_or_tuple + { $1 } + | QUESTION LIDENT COLON core_type2 MINUSGREATER core_type2 + { mktyp(Ptyp_arrow("?" ^ $2 , + {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$4]); + ptyp_loc = $4.ptyp_loc}, $6)) } + | OPTLABEL core_type2 MINUSGREATER core_type2 + { mktyp(Ptyp_arrow("?" ^ $1 , + {ptyp_desc = Ptyp_constr(Ldot (Lident "*predef*", "option"), [$2]); + ptyp_loc = $2.ptyp_loc}, $4)) } + | LIDENT COLON core_type2 MINUSGREATER core_type2 + { mktyp(Ptyp_arrow($1, $3, $5)) } + | core_type2 MINUSGREATER core_type2 + { mktyp(Ptyp_arrow("", $1, $3)) } +; + +simple_core_type: + simple_core_type2 %prec below_SHARP + { $1 } + | LPAREN core_type_comma_list RPAREN %prec below_SHARP + { match $2 with [sty] -> sty | _ -> raise Parse_error } +; +simple_core_type2: + QUOTE ident + { mktyp(Ptyp_var $2) } + | UNDERSCORE + { mktyp(Ptyp_any) } + | type_longident + { mktyp(Ptyp_constr($1, [])) } + | simple_core_type2 type_longident + { mktyp(Ptyp_constr($2, [$1])) } + | LPAREN core_type_comma_list RPAREN type_longident + { mktyp(Ptyp_constr($4, List.rev $2)) } + | LESS meth_list GREATER + { mktyp(Ptyp_object $2) } + | LESS GREATER + { mktyp(Ptyp_object []) } + | SHARP class_longident opt_present + { mktyp(Ptyp_class($2, [], $3)) } + | simple_core_type2 SHARP class_longident opt_present + { mktyp(Ptyp_class($3, [$1], $4)) } + | LPAREN core_type_comma_list RPAREN SHARP class_longident opt_present + { mktyp(Ptyp_class($5, List.rev $2, $6)) } + | LBRACKET tag_field RBRACKET + { mktyp(Ptyp_variant([$2], true, None)) } +/* PR#3835: this is not LR(1), would need lookahead=2 + | LBRACKET simple_core_type2 RBRACKET + { mktyp(Ptyp_variant([$2], true, None)) } +*/ + | LBRACKET BAR row_field_list RBRACKET + { mktyp(Ptyp_variant(List.rev $3, true, None)) } + | LBRACKET row_field BAR row_field_list RBRACKET + { mktyp(Ptyp_variant($2 :: List.rev $4, true, None)) } + | LBRACKETGREATER opt_bar row_field_list RBRACKET + { mktyp(Ptyp_variant(List.rev $3, false, None)) } + | LBRACKETGREATER RBRACKET + { mktyp(Ptyp_variant([], false, None)) } + | LBRACKETLESS opt_bar row_field_list RBRACKET + { mktyp(Ptyp_variant(List.rev $3, true, Some [])) } + | LBRACKETLESS opt_bar row_field_list GREATER name_tag_list RBRACKET + { mktyp(Ptyp_variant(List.rev $3, true, Some (List.rev $5))) } +; +row_field_list: + row_field { [$1] } + | row_field_list BAR row_field { $3 :: $1 } +; +row_field: + tag_field { $1 } + | simple_core_type2 { Rinherit $1 } +; +tag_field: + name_tag OF opt_ampersand amper_type_list + { Rtag ($1, $3, List.rev $4) } + | name_tag + { Rtag ($1, true, []) } +; +opt_ampersand: + AMPERSAND { true } + | /* empty */ { false } +; +amper_type_list: + core_type { [$1] } + | amper_type_list AMPERSAND core_type { $3 :: $1 } +; +opt_present: + LBRACKETGREATER name_tag_list RBRACKET { List.rev $2 } + | /* empty */ { [] } +; +name_tag_list: + name_tag { [$1] } + | name_tag_list name_tag { $2 :: $1 } +; +simple_core_type_or_tuple: + simple_core_type { $1 } + | simple_core_type STAR core_type_list + { mktyp(Ptyp_tuple($1 :: List.rev $3)) } +; +core_type_comma_list: + core_type { [$1] } + | core_type_comma_list COMMA core_type { $3 :: $1 } +; +core_type_list: + simple_core_type { [$1] } + | core_type_list STAR simple_core_type { $3 :: $1 } +; +meth_list: + field SEMI meth_list { $1 :: $3 } + | field opt_semi { [$1] } + | DOTDOT { [mkfield Pfield_var] } +; +field: + label COLON poly_type { mkfield(Pfield($1, $3)) } +; +label: + LIDENT { $1 } +; + +/* Constants */ + +constant: + INT { Const_int $1 } + | CHAR { Const_char $1 } + | STRING { Const_string $1 } + | FLOAT { Const_float $1 } + | INT32 { Const_int32 $1 } + | INT64 { Const_int64 $1 } + | NATIVEINT { Const_nativeint $1 } +; +signed_constant: + constant { $1 } + | MINUS INT { Const_int(- $2) } + | MINUS FLOAT { Const_float("-" ^ $2) } + | MINUS INT32 { Const_int32(Int32.neg $2) } + | MINUS INT64 { Const_int64(Int64.neg $2) } + | MINUS NATIVEINT { Const_nativeint(Nativeint.neg $2) } +; +/* Identifiers and long identifiers */ + +ident: + UIDENT { $1 } + | LIDENT { $1 } +; +val_ident: + LIDENT { $1 } + | LPAREN operator RPAREN { $2 } +; +operator: + PREFIXOP { $1 } + | INFIXOP0 { $1 } + | INFIXOP1 { $1 } + | INFIXOP2 { $1 } + | INFIXOP3 { $1 } + | INFIXOP4 { $1 } + | PLUS { "+" } + | MINUS { "-" } + | MINUSDOT { "-." } + | STAR { "*" } + | EQUAL { "=" } + | LESS { "<" } + | GREATER { ">" } + | OR { "or" } + | BARBAR { "||" } + | AMPERSAND { "&" } + | AMPERAMPER { "&&" } + | COLONEQUAL { ":=" } +; +constr_ident: + UIDENT { $1 } +/* | LBRACKET RBRACKET { "[]" } */ + | LPAREN RPAREN { "()" } + | COLONCOLON { "::" } +/* | LPAREN COLONCOLON RPAREN { "::" } */ + | FALSE { "false" } + | TRUE { "true" } +; + +val_longident: + val_ident { Lident $1 } + | mod_longident DOT val_ident { Ldot($1, $3) } +; +constr_longident: + mod_longident %prec below_DOT { $1 } + | LBRACKET RBRACKET { Lident "[]" } + | LPAREN RPAREN { Lident "()" } + | FALSE { Lident "false" } + | TRUE { Lident "true" } +; +label_longident: + LIDENT { Lident $1 } + | mod_longident DOT LIDENT { Ldot($1, $3) } +; +type_longident: + LIDENT { Lident $1 } + | mod_ext_longident DOT LIDENT { Ldot($1, $3) } +; +mod_longident: + UIDENT { Lident $1 } + | mod_longident DOT UIDENT { Ldot($1, $3) } +; +mod_ext_longident: + UIDENT { Lident $1 } + | mod_ext_longident DOT UIDENT { Ldot($1, $3) } + | mod_ext_longident LPAREN mod_ext_longident RPAREN { Lapply($1, $3) } +; +mty_longident: + ident { Lident $1 } + | mod_ext_longident DOT ident { Ldot($1, $3) } +; +clty_longident: + LIDENT { Lident $1 } + | mod_ext_longident DOT LIDENT { Ldot($1, $3) } +; +class_longident: + LIDENT { Lident $1 } + | mod_longident DOT LIDENT { Ldot($1, $3) } +; + +/* Toplevel directives */ + +toplevel_directive: + SHARP ident { Ptop_dir($2, Pdir_none) } + | SHARP ident STRING { Ptop_dir($2, Pdir_string $3) } + | SHARP ident INT { Ptop_dir($2, Pdir_int $3) } + | SHARP ident val_longident { Ptop_dir($2, Pdir_ident $3) } + | SHARP ident FALSE { Ptop_dir($2, Pdir_bool false) } + | SHARP ident TRUE { Ptop_dir($2, Pdir_bool true) } +; + +/* Miscellaneous */ + +name_tag: + BACKQUOTE ident { $2 } +; +rec_flag: + /* empty */ { Nonrecursive } + | REC { Recursive } +; +direction_flag: + TO { Upto } + | DOWNTO { Downto } +; +private_flag: + /* empty */ { Public } + | PRIVATE { Private } +; +mutable_flag: + /* empty */ { Immutable } + | MUTABLE { Mutable } +; +virtual_flag: + /* empty */ { Concrete } + | VIRTUAL { Virtual } +; +opt_bar: + /* empty */ { () } + | BAR { () } +; +opt_semi: + | /* empty */ { () } + | SEMI { () } +; +subtractive: + | MINUS { "-" } + | MINUSDOT { "-." } +; +%% diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli new file mode 100644 index 0000000..802e3ef --- /dev/null +++ b/parsing/parsetree.mli @@ -0,0 +1,276 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parsetree.mli,v 1.45 2008-07-09 13:03:37 mauny Exp $ *) + +(* Abstract syntax tree produced by parsing *) + +open Asttypes + +(* Type expressions for the core language *) + +type core_type = + { ptyp_desc: core_type_desc; + ptyp_loc: Location.t } + +and core_type_desc = + Ptyp_any + | Ptyp_var of string + | Ptyp_arrow of label * core_type * core_type + | Ptyp_tuple of core_type list + | Ptyp_constr of Longident.t * core_type list + | Ptyp_object of core_field_type list + | Ptyp_class of Longident.t * core_type list * label list + | Ptyp_alias of core_type * string + | Ptyp_variant of row_field list * bool * label list option + | Ptyp_poly of string list * core_type + +and core_field_type = + { pfield_desc: core_field_desc; + pfield_loc: Location.t } + +and core_field_desc = + Pfield of string * core_type + | Pfield_var + +and row_field = + Rtag of label * bool * core_type list + | Rinherit of core_type + +(* XXX Type expressions for the class language *) + +type 'a class_infos = + { pci_virt: virtual_flag; + pci_params: string list * Location.t; + pci_name: string; + pci_expr: 'a; + pci_variance: (bool * bool) list; + pci_loc: Location.t } + +(* Value expressions for the core language *) + +type pattern = + { ppat_desc: pattern_desc; + ppat_loc: Location.t } + +and pattern_desc = + Ppat_any + | Ppat_var of string + | Ppat_alias of pattern * string + | Ppat_constant of constant + | Ppat_tuple of pattern list + | Ppat_construct of Longident.t * pattern option * bool + | Ppat_variant of label * pattern option + | Ppat_record of (Longident.t * pattern) list + | Ppat_array of pattern list + | Ppat_or of pattern * pattern + | Ppat_constraint of pattern * core_type + | Ppat_type of Longident.t + | Ppat_lazy of pattern + +type expression = + { pexp_desc: expression_desc; + pexp_loc: Location.t } + +and expression_desc = + Pexp_ident of Longident.t + | Pexp_constant of constant + | Pexp_let of rec_flag * (pattern * expression) list * expression + | Pexp_function of label * expression option * (pattern * expression) list + | Pexp_apply of expression * (label * expression) list + | Pexp_match of expression * (pattern * expression) list + | Pexp_try of expression * (pattern * expression) list + | Pexp_tuple of expression list + | Pexp_construct of Longident.t * expression option * bool + | Pexp_variant of label * expression option + | Pexp_record of (Longident.t * expression) list * expression option + | Pexp_field of expression * Longident.t + | Pexp_setfield of expression * Longident.t * expression + | Pexp_array of expression list + | Pexp_ifthenelse of expression * expression * expression option + | Pexp_sequence of expression * expression + | Pexp_while of expression * expression + | Pexp_for of string * expression * expression * direction_flag * expression + | Pexp_constraint of expression * core_type option * core_type option + | Pexp_when of expression * expression + | Pexp_send of expression * string + | Pexp_new of Longident.t + | Pexp_setinstvar of string * expression + | Pexp_override of (string * expression) list + | Pexp_letmodule of string * module_expr * expression + | Pexp_assert of expression + | Pexp_assertfalse + | Pexp_lazy of expression + | Pexp_poly of expression * core_type option + | Pexp_object of class_structure + +(* Value descriptions *) + +and value_description = + { pval_type: core_type; + pval_prim: string list } + +(* Type declarations *) + +and type_declaration = + { ptype_params: string list; + ptype_cstrs: (core_type * core_type * Location.t) list; + ptype_kind: type_kind; + ptype_private: private_flag; + ptype_manifest: core_type option; + ptype_variance: (bool * bool) list; + ptype_loc: Location.t } + +and type_kind = + Ptype_abstract + | Ptype_variant of (string * core_type list * Location.t) list + | Ptype_record of + (string * mutable_flag * core_type * Location.t) list + +and exception_declaration = core_type list + +(* Type expressions for the class language *) + +and class_type = + { pcty_desc: class_type_desc; + pcty_loc: Location.t } + +and class_type_desc = + Pcty_constr of Longident.t * core_type list + | Pcty_signature of class_signature + | Pcty_fun of label * core_type * class_type + +and class_signature = core_type * class_type_field list + +and class_type_field = + Pctf_inher of class_type + | Pctf_val of (string * mutable_flag * virtual_flag * core_type * Location.t) + | Pctf_virt of (string * private_flag * core_type * Location.t) + | Pctf_meth of (string * private_flag * core_type * Location.t) + | Pctf_cstr of (core_type * core_type * Location.t) + +and class_description = class_type class_infos + +and class_type_declaration = class_type class_infos + +(* Value expressions for the class language *) + +and class_expr = + { pcl_desc: class_expr_desc; + pcl_loc: Location.t } + +and class_expr_desc = + Pcl_constr of Longident.t * core_type list + | Pcl_structure of class_structure + | Pcl_fun of label * expression option * pattern * class_expr + | Pcl_apply of class_expr * (label * expression) list + | Pcl_let of rec_flag * (pattern * expression) list * class_expr + | Pcl_constraint of class_expr * class_type + +and class_structure = pattern * class_field list + +and class_field = + Pcf_inher of class_expr * string option + | Pcf_valvirt of (string * mutable_flag * core_type * Location.t) + | Pcf_val of (string * mutable_flag * expression * Location.t) + | Pcf_virt of (string * private_flag * core_type * Location.t) + | Pcf_meth of (string * private_flag * expression * Location.t) + | Pcf_cstr of (core_type * core_type * Location.t) + | Pcf_let of rec_flag * (pattern * expression) list * Location.t + | Pcf_init of expression + +and class_declaration = class_expr class_infos + +(* Type expressions for the module language *) + +and module_type = + { pmty_desc: module_type_desc; + pmty_loc: Location.t } + +and module_type_desc = + Pmty_ident of Longident.t + | Pmty_signature of signature + | Pmty_functor of string * module_type * module_type + | Pmty_with of module_type * (Longident.t * with_constraint) list + +and signature = signature_item list + +and signature_item = + { psig_desc: signature_item_desc; + psig_loc: Location.t } + +and signature_item_desc = + Psig_value of string * value_description + | Psig_type of (string * type_declaration) list + | Psig_exception of string * exception_declaration + | Psig_module of string * module_type + | Psig_recmodule of (string * module_type) list + | Psig_modtype of string * modtype_declaration + | Psig_open of Longident.t + | Psig_include of module_type + | Psig_class of class_description list + | Psig_class_type of class_type_declaration list + +and modtype_declaration = + Pmodtype_abstract + | Pmodtype_manifest of module_type + +and with_constraint = + Pwith_type of type_declaration + | Pwith_module of Longident.t + +(* Value expressions for the module language *) + +and module_expr = + { pmod_desc: module_expr_desc; + pmod_loc: Location.t } + +and module_expr_desc = + Pmod_ident of Longident.t + | Pmod_structure of structure + | Pmod_functor of string * module_type * module_expr + | Pmod_apply of module_expr * module_expr + | Pmod_constraint of module_expr * module_type + +and structure = structure_item list + +and structure_item = + { pstr_desc: structure_item_desc; + pstr_loc: Location.t } + +and structure_item_desc = + Pstr_eval of expression + | Pstr_value of rec_flag * (pattern * expression) list + | Pstr_primitive of string * value_description + | Pstr_type of (string * type_declaration) list + | Pstr_exception of string * exception_declaration + | Pstr_exn_rebind of string * Longident.t + | Pstr_module of string * module_expr + | Pstr_recmodule of (string * module_type * module_expr) list + | Pstr_modtype of string * module_type + | Pstr_open of Longident.t + | Pstr_class of class_declaration list + | Pstr_class_type of class_type_declaration list + | Pstr_include of module_expr + +(* Toplevel phrases *) + +type toplevel_phrase = + Ptop_def of structure + | Ptop_dir of string * directive_argument + +and directive_argument = + Pdir_none + | Pdir_string of string + | Pdir_int of int + | Pdir_ident of Longident.t + | Pdir_bool of bool diff --git a/parsing/printast.ml b/parsing/printast.ml new file mode 100644 index 0000000..13eb605 --- /dev/null +++ b/parsing/printast.ml @@ -0,0 +1,702 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printast.ml,v 1.34 2008-07-09 13:03:37 mauny Exp $ *) + +open Asttypes;; +open Format;; +open Lexing;; +open Location;; +open Parsetree;; + +let fmt_position f l = + if l.pos_fname = "" && l.pos_lnum = 1 + then fprintf f "%d" l.pos_cnum + else if l.pos_lnum = -1 + then fprintf f "%s[%d]" l.pos_fname l.pos_cnum + else fprintf f "%s[%d,%d+%d]" l.pos_fname l.pos_lnum l.pos_bol + (l.pos_cnum - l.pos_bol) +;; + +let fmt_location f loc = + fprintf f "(%a..%a)" fmt_position loc.loc_start fmt_position loc.loc_end; + if loc.loc_ghost then fprintf f " ghost"; +;; + +let rec fmt_longident_aux f x = + match x with + | Longident.Lident (s) -> fprintf f "%s" s; + | Longident.Ldot (y, s) -> fprintf f "%a.%s" fmt_longident_aux y s; + | Longident.Lapply (y, z) -> + fprintf f "%a(%a)" fmt_longident_aux y fmt_longident_aux z; +;; + +let fmt_longident f x = fprintf f "\"%a\"" fmt_longident_aux x;; + +let fmt_constant f x = + match x with + | Const_int (i) -> fprintf f "Const_int %d" i; + | Const_char (c) -> fprintf f "Const_char %02x" (Char.code c); + | Const_string (s) -> fprintf f "Const_string %S" s; + | Const_float (s) -> fprintf f "Const_float %s" s; + | Const_int32 (i) -> fprintf f "Const_int32 %ld" i; + | Const_int64 (i) -> fprintf f "Const_int64 %Ld" i; + | Const_nativeint (i) -> fprintf f "Const_nativeint %nd" i; +;; + +let fmt_mutable_flag f x = + match x with + | Immutable -> fprintf f "Immutable"; + | Mutable -> fprintf f "Mutable"; +;; + +let fmt_virtual_flag f x = + match x with + | Virtual -> fprintf f "Virtual"; + | Concrete -> fprintf f "Concrete"; +;; + +let fmt_rec_flag f x = + match x with + | Nonrecursive -> fprintf f "Nonrec"; + | Recursive -> fprintf f "Rec"; + | Default -> fprintf f "Default"; +;; + +let fmt_direction_flag f x = + match x with + | Upto -> fprintf f "Up"; + | Downto -> fprintf f "Down"; +;; + +let fmt_private_flag f x = + match x with + | Public -> fprintf f "Public"; + | Private -> fprintf f "Private"; +;; + +let line i f s (*...*) = + fprintf f "%s" (String.make (2*i) ' '); + fprintf f s (*...*) +;; + +let list i f ppf l = + match l with + | [] -> line i ppf "[]\n"; + | h::t -> + line i ppf "[\n"; + List.iter (f (i+1) ppf) l; + line i ppf "]\n"; +;; + +let option i f ppf x = + match x with + | None -> line i ppf "None\n"; + | Some x -> + line i ppf "Some\n"; + f (i+1) ppf x; +;; + +let longident i ppf li = line i ppf "%a\n" fmt_longident li;; +let string i ppf s = line i ppf "\"%s\"\n" s;; +let bool i ppf x = line i ppf "%s\n" (string_of_bool x);; +let label i ppf x = line i ppf "label=\"%s\"\n" x;; + +let rec core_type i ppf x = + line i ppf "core_type %a\n" fmt_location x.ptyp_loc; + let i = i+1 in + match x.ptyp_desc with + | Ptyp_any -> line i ppf "Ptyp_any\n"; + | Ptyp_var (s) -> line i ppf "Ptyp_var %s\n" s; + | Ptyp_arrow (l, ct1, ct2) -> + line i ppf "Ptyp_arrow\n"; + string i ppf l; + core_type i ppf ct1; + core_type i ppf ct2; + | Ptyp_tuple l -> + line i ppf "Ptyp_tuple\n"; + list i core_type ppf l; + | Ptyp_constr (li, l) -> + line i ppf "Ptyp_constr %a\n" fmt_longident li; + list i core_type ppf l; + | Ptyp_variant (l, closed, low) -> + line i ppf "Ptyp_variant closed=%s\n" (string_of_bool closed); + list i label_x_bool_x_core_type_list ppf l; + option i (fun i -> list i string) ppf low + | Ptyp_object (l) -> + line i ppf "Ptyp_object\n"; + list i core_field_type ppf l; + | Ptyp_class (li, l, low) -> + line i ppf "Ptyp_class %a\n" fmt_longident li; + list i core_type ppf l; + list i string ppf low + | Ptyp_alias (ct, s) -> + line i ppf "Ptyp_alias \"%s\"\n" s; + core_type i ppf ct; + | Ptyp_poly (sl, ct) -> + line i ppf "Ptyp_poly%a\n" + (fun ppf -> List.iter (fun x -> fprintf ppf " '%s" x)) sl; + core_type i ppf ct; + +and core_field_type i ppf x = + line i ppf "core_field_type %a\n" fmt_location x.pfield_loc; + let i = i+1 in + match x.pfield_desc with + | Pfield (s, ct) -> + line i ppf "Pfield \"%s\"\n" s; + core_type i ppf ct; + | Pfield_var -> line i ppf "Pfield_var\n"; + +and pattern i ppf x = + line i ppf "pattern %a\n" fmt_location x.ppat_loc; + let i = i+1 in + match x.ppat_desc with + | Ppat_any -> line i ppf "Ppat_any\n"; + | Ppat_var (s) -> line i ppf "Ppat_var \"%s\"\n" s; + | Ppat_alias (p, s) -> + line i ppf "Ppat_alias \"%s\"\n" s; + pattern i ppf p; + | Ppat_constant (c) -> line i ppf "Ppat_constant %a\n" fmt_constant c; + | Ppat_tuple (l) -> + line i ppf "Ppat_tuple\n"; + list i pattern ppf l; + | Ppat_construct (li, po, b) -> + line i ppf "Ppat_construct %a\n" fmt_longident li; + option i pattern ppf po; + bool i ppf b; + | Ppat_variant (l, po) -> + line i ppf "Ppat_variant \"%s\"\n" l; + option i pattern ppf po; + | Ppat_record (l) -> + line i ppf "Ppat_record\n"; + list i longident_x_pattern ppf l; + | Ppat_array (l) -> + line i ppf "Ppat_array\n"; + list i pattern ppf l; + | Ppat_or (p1, p2) -> + line i ppf "Ppat_or\n"; + pattern i ppf p1; + pattern i ppf p2; + | Ppat_lazy p -> + line i ppf "Ppat_lazy\n"; + pattern i ppf p; + | Ppat_constraint (p, ct) -> + line i ppf "Ppat_constraint"; + pattern i ppf p; + core_type i ppf ct; + | Ppat_type li -> + line i ppf "Ppat_type"; + longident i ppf li + +and expression i ppf x = + line i ppf "expression %a\n" fmt_location x.pexp_loc; + let i = i+1 in + match x.pexp_desc with + | Pexp_ident (li) -> line i ppf "Pexp_ident %a\n" fmt_longident li; + | Pexp_constant (c) -> line i ppf "Pexp_constant %a\n" fmt_constant c; + | Pexp_let (rf, l, e) -> + line i ppf "Pexp_let %a\n" fmt_rec_flag rf; + list i pattern_x_expression_def ppf l; + expression i ppf e; + | Pexp_function (p, eo, l) -> + line i ppf "Pexp_function \"%s\"\n" p; + option i expression ppf eo; + list i pattern_x_expression_case ppf l; + | Pexp_apply (e, l) -> + line i ppf "Pexp_apply\n"; + expression i ppf e; + list i label_x_expression ppf l; + | Pexp_match (e, l) -> + line i ppf "Pexp_match\n"; + expression i ppf e; + list i pattern_x_expression_case ppf l; + | Pexp_try (e, l) -> + line i ppf "Pexp_try\n"; + expression i ppf e; + list i pattern_x_expression_case ppf l; + | Pexp_tuple (l) -> + line i ppf "Pexp_tuple\n"; + list i expression ppf l; + | Pexp_construct (li, eo, b) -> + line i ppf "Pexp_construct %a\n" fmt_longident li; + option i expression ppf eo; + bool i ppf b; + | Pexp_variant (l, eo) -> + line i ppf "Pexp_variant \"%s\"\n" l; + option i expression ppf eo; + | Pexp_record (l, eo) -> + line i ppf "Pexp_record\n"; + list i longident_x_expression ppf l; + option i expression ppf eo; + | Pexp_field (e, li) -> + line i ppf "Pexp_field\n"; + expression i ppf e; + longident i ppf li; + | Pexp_setfield (e1, li, e2) -> + line i ppf "Pexp_setfield\n"; + expression i ppf e1; + longident i ppf li; + expression i ppf e2; + | Pexp_array (l) -> + line i ppf "Pexp_array\n"; + list i expression ppf l; + | Pexp_ifthenelse (e1, e2, eo) -> + line i ppf "Pexp_ifthenelse\n"; + expression i ppf e1; + expression i ppf e2; + option i expression ppf eo; + | Pexp_sequence (e1, e2) -> + line i ppf "Pexp_sequence\n"; + expression i ppf e1; + expression i ppf e2; + | Pexp_while (e1, e2) -> + line i ppf "Pexp_while\n"; + expression i ppf e1; + expression i ppf e2; + | Pexp_for (s, e1, e2, df, e3) -> + line i ppf "Pexp_for \"%s\" %a\n" s fmt_direction_flag df; + expression i ppf e1; + expression i ppf e2; + expression i ppf e3; + | Pexp_constraint (e, cto1, cto2) -> + line i ppf "Pexp_constraint\n"; + expression i ppf e; + option i core_type ppf cto1; + option i core_type ppf cto2; + | Pexp_when (e1, e2) -> + line i ppf "Pexp_when\n"; + expression i ppf e1; + expression i ppf e2; + | Pexp_send (e, s) -> + line i ppf "Pexp_send \"%s\"\n" s; + expression i ppf e; + | Pexp_new (li) -> line i ppf "Pexp_new %a\n" fmt_longident li; + | Pexp_setinstvar (s, e) -> + line i ppf "Pexp_setinstvar \"%s\"\n" s; + expression i ppf e; + | Pexp_override (l) -> + line i ppf "Pexp_override\n"; + list i string_x_expression ppf l; + | Pexp_letmodule (s, me, e) -> + line i ppf "Pexp_letmodule \"%s\"\n" s; + module_expr i ppf me; + expression i ppf e; + | Pexp_assert (e) -> + line i ppf "Pexp_assert"; + expression i ppf e; + | Pexp_assertfalse -> + line i ppf "Pexp_assertfalse"; + | Pexp_lazy (e) -> + line i ppf "Pexp_lazy"; + expression i ppf e; + | Pexp_poly (e, cto) -> + line i ppf "Pexp_poly\n"; + expression i ppf e; + option i core_type ppf cto; + | Pexp_object s -> + line i ppf "Pexp_object"; + class_structure i ppf s + +and value_description i ppf x = + line i ppf "value_description\n"; + core_type (i+1) ppf x.pval_type; + list (i+1) string ppf x.pval_prim; + +and type_declaration i ppf x = + line i ppf "type_declaration %a\n" fmt_location x.ptype_loc; + let i = i+1 in + line i ppf "ptype_params =\n"; + list (i+1) string ppf x.ptype_params; + line i ppf "ptype_cstrs =\n"; + list (i+1) core_type_x_core_type_x_location ppf x.ptype_cstrs; + line i ppf "ptype_kind =\n"; + type_kind (i+1) ppf x.ptype_kind; + line i ppf "ptype_private = %a\n" fmt_private_flag x.ptype_private; + line i ppf "ptype_manifest =\n"; + option (i+1) core_type ppf x.ptype_manifest; + +and type_kind i ppf x = + match x with + | Ptype_abstract -> + line i ppf "Ptype_abstract\n" + | Ptype_variant l -> + line i ppf "Ptype_variant\n"; + list (i+1) string_x_core_type_list_x_location ppf l; + | Ptype_record l -> + line i ppf "Ptype_record\n"; + list (i+1) string_x_mutable_flag_x_core_type_x_location ppf l; + +and exception_declaration i ppf x = list i core_type ppf x + +and class_type i ppf x = + line i ppf "class_type %a\n" fmt_location x.pcty_loc; + let i = i+1 in + match x.pcty_desc with + | Pcty_constr (li, l) -> + line i ppf "Pcty_constr %a\n" fmt_longident li; + list i core_type ppf l; + | Pcty_signature (cs) -> + line i ppf "Pcty_signature\n"; + class_signature i ppf cs; + | Pcty_fun (l, co, cl) -> + line i ppf "Pcty_fun \"%s\"\n" l; + core_type i ppf co; + class_type i ppf cl; + +and class_signature i ppf (ct, l) = + line i ppf "class_signature\n"; + core_type (i+1) ppf ct; + list (i+1) class_type_field ppf l; + +and class_type_field i ppf x = + match x with + | Pctf_inher (ct) -> + line i ppf "Pctf_inher\n"; + class_type i ppf ct; + | Pctf_val (s, mf, vf, ct, loc) -> + line i ppf + "Pctf_val \"%s\" %a %a %a\n" s + fmt_mutable_flag mf fmt_virtual_flag vf fmt_location loc; + core_type (i+1) ppf ct; + | Pctf_virt (s, pf, ct, loc) -> + line i ppf + "Pctf_virt \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc; + core_type (i+1) ppf ct; + | Pctf_meth (s, pf, ct, loc) -> + line i ppf + "Pctf_meth \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc; + core_type (i+1) ppf ct; + | Pctf_cstr (ct1, ct2, loc) -> + line i ppf "Pctf_cstr %a\n" fmt_location loc; + core_type i ppf ct1; + core_type i ppf ct2; + +and class_description i ppf x = + line i ppf "class_description %a\n" fmt_location x.pci_loc; + let i = i+1 in + line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt; + line i ppf "pci_params =\n"; + string_list_x_location (i+1) ppf x.pci_params; + line i ppf "pci_name = \"%s\"\n" x.pci_name; + line i ppf "pci_expr =\n"; + class_type (i+1) ppf x.pci_expr; + +and class_type_declaration i ppf x = + line i ppf "class_type_declaration %a\n" fmt_location x.pci_loc; + let i = i+1 in + line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt; + line i ppf "pci_params =\n"; + string_list_x_location (i+1) ppf x.pci_params; + line i ppf "pci_name = \"%s\"\n" x.pci_name; + line i ppf "pci_expr =\n"; + class_type (i+1) ppf x.pci_expr; + +and class_expr i ppf x = + line i ppf "class_expr %a\n" fmt_location x.pcl_loc; + let i = i+1 in + match x.pcl_desc with + | Pcl_constr (li, l) -> + line i ppf "Pcl_constr %a\n" fmt_longident li; + list i core_type ppf l; + | Pcl_structure (cs) -> + line i ppf "Pcl_structure\n"; + class_structure i ppf cs; + | Pcl_fun (l, eo, p, e) -> + line i ppf "Pcl_fun\n"; + label i ppf l; + option i expression ppf eo; + pattern i ppf p; + class_expr i ppf e; + | Pcl_apply (ce, l) -> + line i ppf "Pcl_apply\n"; + class_expr i ppf ce; + list i label_x_expression ppf l; + | Pcl_let (rf, l, ce) -> + line i ppf "Pcl_let %a\n" fmt_rec_flag rf; + list i pattern_x_expression_def ppf l; + class_expr i ppf ce; + | Pcl_constraint (ce, ct) -> + line i ppf "Pcl_constraint\n"; + class_expr i ppf ce; + class_type i ppf ct; + +and class_structure i ppf (p, l) = + line i ppf "class_structure\n"; + pattern (i+1) ppf p; + list (i+1) class_field ppf l; + +and class_field i ppf x = + match x with + | Pcf_inher (ce, so) -> + line i ppf "Pcf_inher\n"; + class_expr (i+1) ppf ce; + option (i+1) string ppf so; + | Pcf_valvirt (s, mf, ct, loc) -> + line i ppf + "Pcf_valvirt \"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; + core_type (i+1) ppf ct; + | Pcf_val (s, mf, e, loc) -> + line i ppf + "Pcf_val \"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; + expression (i+1) ppf e; + | Pcf_virt (s, pf, ct, loc) -> + line i ppf + "Pcf_virt \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc; + core_type (i+1) ppf ct; + | Pcf_meth (s, pf, e, loc) -> + line i ppf + "Pcf_meth \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc; + expression (i+1) ppf e; + | Pcf_cstr (ct1, ct2, loc) -> + line i ppf "Pcf_cstr %a\n" fmt_location loc; + core_type (i+1) ppf ct1; + core_type (i+1) ppf ct2; + | Pcf_let (rf, l, loc) -> + line i ppf "Pcf_let %a %a\n" fmt_rec_flag rf fmt_location loc; + list (i+1) pattern_x_expression_def ppf l; + | Pcf_init (e) -> + line i ppf "Pcf_init\n"; + expression (i+1) ppf e; + +and class_declaration i ppf x = + line i ppf "class_declaration %a\n" fmt_location x.pci_loc; + let i = i+1 in + line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt; + line i ppf "pci_params =\n"; + string_list_x_location (i+1) ppf x.pci_params; + line i ppf "pci_name = \"%s\"\n" x.pci_name; + line i ppf "pci_expr =\n"; + class_expr (i+1) ppf x.pci_expr; + +and module_type i ppf x = + line i ppf "module_type %a\n" fmt_location x.pmty_loc; + let i = i+1 in + match x.pmty_desc with + | Pmty_ident (li) -> line i ppf "Pmty_ident %a\n" fmt_longident li; + | Pmty_signature (s) -> + line i ppf "Pmty_signature\n"; + signature i ppf s; + | Pmty_functor (s, mt1, mt2) -> + line i ppf "Pmty_functor \"%s\"\n" s; + module_type i ppf mt1; + module_type i ppf mt2; + | Pmty_with (mt, l) -> + line i ppf "Pmty_with\n"; + module_type i ppf mt; + list i longident_x_with_constraint ppf l; + +and signature i ppf x = list i signature_item ppf x + +and signature_item i ppf x = + line i ppf "signature_item %a\n" fmt_location x.psig_loc; + let i = i+1 in + match x.psig_desc with + | Psig_value (s, vd) -> + line i ppf "Psig_value \"%s\"\n" s; + value_description i ppf vd; + | Psig_type (l) -> + line i ppf "Psig_type\n"; + list i string_x_type_declaration ppf l; + | Psig_exception (s, ed) -> + line i ppf "Psig_exception \"%s\"\n" s; + exception_declaration i ppf ed; + | Psig_module (s, mt) -> + line i ppf "Psig_module \"%s\"\n" s; + module_type i ppf mt; + | Psig_recmodule decls -> + line i ppf "Psig_recmodule\n"; + list i string_x_module_type ppf decls; + | Psig_modtype (s, md) -> + line i ppf "Psig_modtype \"%s\"\n" s; + modtype_declaration i ppf md; + | Psig_open (li) -> line i ppf "Psig_open %a\n" fmt_longident li; + | Psig_include (mt) -> + line i ppf "Psig_include\n"; + module_type i ppf mt; + | Psig_class (l) -> + line i ppf "Psig_class\n"; + list i class_description ppf l; + | Psig_class_type (l) -> + line i ppf "Psig_class_type\n"; + list i class_type_declaration ppf l; + +and modtype_declaration i ppf x = + match x with + | Pmodtype_abstract -> line i ppf "Pmodtype_abstract\n"; + | Pmodtype_manifest (mt) -> + line i ppf "Pmodtype_manifest\n"; + module_type (i+1) ppf mt; + +and with_constraint i ppf x = + match x with + | Pwith_type (td) -> + line i ppf "Pwith_type\n"; + type_declaration (i+1) ppf td; + | Pwith_module (li) -> line i ppf "Pwith_module %a\n" fmt_longident li; + +and module_expr i ppf x = + line i ppf "module_expr %a\n" fmt_location x.pmod_loc; + let i = i+1 in + match x.pmod_desc with + | Pmod_ident (li) -> line i ppf "Pmod_ident %a\n" fmt_longident li; + | Pmod_structure (s) -> + line i ppf "Pmod_structure\n"; + structure i ppf s; + | Pmod_functor (s, mt, me) -> + line i ppf "Pmod_functor \"%s\"\n" s; + module_type i ppf mt; + module_expr i ppf me; + | Pmod_apply (me1, me2) -> + line i ppf "Pmod_apply\n"; + module_expr i ppf me1; + module_expr i ppf me2; + | Pmod_constraint (me, mt) -> + line i ppf "Pmod_constraint\n"; + module_expr i ppf me; + module_type i ppf mt; + +and structure i ppf x = list i structure_item ppf x + +and structure_item i ppf x = + line i ppf "structure_item %a\n" fmt_location x.pstr_loc; + let i = i+1 in + match x.pstr_desc with + | Pstr_eval (e) -> + line i ppf "Pstr_eval\n"; + expression i ppf e; + | Pstr_value (rf, l) -> + line i ppf "Pstr_value %a\n" fmt_rec_flag rf; + list i pattern_x_expression_def ppf l; + | Pstr_primitive (s, vd) -> + line i ppf "Pstr_primitive \"%s\"\n" s; + value_description i ppf vd; + | Pstr_type (l) -> + line i ppf "Pstr_type\n"; + list i string_x_type_declaration ppf l; + | Pstr_exception (s, ed) -> + line i ppf "Pstr_exception \"%s\"\n" s; + exception_declaration i ppf ed; + | Pstr_exn_rebind (s, li) -> + line i ppf "Pstr_exn_rebind \"%s\" %a\n" s fmt_longident li; + | Pstr_module (s, me) -> + line i ppf "Pstr_module \"%s\"\n" s; + module_expr i ppf me; + | Pstr_recmodule bindings -> + line i ppf "Pstr_recmodule\n"; + list i string_x_modtype_x_module ppf bindings; + | Pstr_modtype (s, mt) -> + line i ppf "Pstr_modtype \"%s\"\n" s; + module_type i ppf mt; + | Pstr_open (li) -> line i ppf "Pstr_open %a\n" fmt_longident li; + | Pstr_class (l) -> + line i ppf "Pstr_class\n"; + list i class_declaration ppf l; + | Pstr_class_type (l) -> + line i ppf "Pstr_class_type\n"; + list i class_type_declaration ppf l; + | Pstr_include me -> + line i ppf "Pstr_include"; + module_expr i ppf me + +and string_x_type_declaration i ppf (s, td) = + string i ppf s; + type_declaration (i+1) ppf td; + +and string_x_module_type i ppf (s, mty) = + string i ppf s; + module_type (i+1) ppf mty; + +and string_x_modtype_x_module i ppf (s, mty, modl) = + string i ppf s; + module_type (i+1) ppf mty; + module_expr (i+1) ppf modl; + +and longident_x_with_constraint i ppf (li, wc) = + line i ppf "%a\n" fmt_longident li; + with_constraint (i+1) ppf wc; + +and core_type_x_core_type_x_location i ppf (ct1, ct2, l) = + line i ppf "<constraint> %a\n" fmt_location l; + core_type (i+1) ppf ct1; + core_type (i+1) ppf ct2; + +and string_x_core_type_list_x_location i ppf (s, l, loc) = + line i ppf "\"%s\" %a\n" s fmt_location loc; + list (i+1) core_type ppf l; + +and string_x_mutable_flag_x_core_type_x_location i ppf (s, mf, ct, loc) = + line i ppf "\"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; + core_type (i+1) ppf ct; + +and string_list_x_location i ppf (l, loc) = + line i ppf "<params> %a\n" fmt_location loc; + list (i+1) string ppf l; + +and longident_x_pattern i ppf (li, p) = + line i ppf "%a\n" fmt_longident li; + pattern (i+1) ppf p; + +and pattern_x_expression_case i ppf (p, e) = + line i ppf "<case>\n"; + pattern (i+1) ppf p; + expression (i+1) ppf e; + +and pattern_x_expression_def i ppf (p, e) = + line i ppf "<def>\n"; + pattern (i+1) ppf p; + expression (i+1) ppf e; + +and string_x_expression i ppf (s, e) = + line i ppf "<override> \"%s\"\n" s; + expression (i+1) ppf e; + +and longident_x_expression i ppf (li, e) = + line i ppf "%a\n" fmt_longident li; + expression (i+1) ppf e; + +and label_x_expression i ppf (l,e) = + line i ppf "<label> \"%s\"\n" l; + expression (i+1) ppf e; + +and label_x_bool_x_core_type_list i ppf x = + match x with + Rtag (l, b, ctl) -> + line i ppf "Rtag \"%s\" %s\n" l (string_of_bool b); + list (i+1) core_type ppf ctl + | Rinherit (ct) -> + line i ppf "Rinherit\n"; + core_type (i+1) ppf ct +;; + +let rec toplevel_phrase i ppf x = + match x with + | Ptop_def (s) -> + line i ppf "Ptop_def\n"; + structure (i+1) ppf s; + | Ptop_dir (s, da) -> + line i ppf "Ptop_dir \"%s\"\n" s; + directive_argument i ppf da; + +and directive_argument i ppf x = + match x with + | Pdir_none -> line i ppf "Pdir_none\n" + | Pdir_string (s) -> line i ppf "Pdir_string \"%s\"\n" s; + | Pdir_int (i) -> line i ppf "Pdir_int %d\n" i; + | Pdir_ident (li) -> line i ppf "Pdir_ident %a\n" fmt_longident li; + | Pdir_bool (b) -> line i ppf "Pdir_bool %s\n" (string_of_bool b); +;; + +let interface ppf x = list 0 signature_item ppf x;; + +let implementation ppf x = list 0 structure_item ppf x;; + +let top_phrase ppf x = toplevel_phrase 0 ppf x;; diff --git a/parsing/printast.mli b/parsing/printast.mli new file mode 100644 index 0000000..97206f2 --- /dev/null +++ b/parsing/printast.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printast.mli,v 1.2 2000-03-06 22:11:39 weis Exp $ *) + +open Parsetree;; +open Format;; + +val interface : formatter -> signature_item list -> unit;; +val implementation : formatter -> structure_item list -> unit;; +val top_phrase : formatter -> toplevel_phrase -> unit;; diff --git a/parsing/syntaxerr.ml b/parsing/syntaxerr.ml new file mode 100644 index 0000000..3d67f21 --- /dev/null +++ b/parsing/syntaxerr.ml @@ -0,0 +1,39 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: syntaxerr.ml,v 1.9 2007-12-04 13:38:58 doligez Exp $ *) + +(* Auxiliary type for reporting syntax errors *) + +open Format + +type error = + Unclosed of Location.t * string * Location.t * string + | Other of Location.t + +exception Error of error +exception Escape_error + +let report_error ppf = function + | Unclosed(opening_loc, opening, closing_loc, closing) -> + if String.length !Location.input_name = 0 + && Location.highlight_locations ppf opening_loc closing_loc + then fprintf ppf "Syntax error: '%s' expected, \ + the highlighted '%s' might be unmatched" closing opening + else begin + fprintf ppf "%aSyntax error: '%s' expected@." + Location.print_error closing_loc closing; + fprintf ppf "%aThis '%s' might be unmatched" + Location.print_error opening_loc opening + end + | Other loc -> + fprintf ppf "%aSyntax error" Location.print_error loc diff --git a/parsing/syntaxerr.mli b/parsing/syntaxerr.mli new file mode 100644 index 0000000..9df00c3 --- /dev/null +++ b/parsing/syntaxerr.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: syntaxerr.mli,v 1.4 2000-03-06 22:11:40 weis Exp $ *) + +(* Auxiliary type for reporting syntax errors *) + +open Format + +type error = + Unclosed of Location.t * string * Location.t * string + | Other of Location.t + +exception Error of error +exception Escape_error + +val report_error: formatter -> error -> unit diff --git a/stdlib/.cvsignore b/stdlib/.cvsignore new file mode 100644 index 0000000..343f6ab --- /dev/null +++ b/stdlib/.cvsignore @@ -0,0 +1,6 @@ +camlheader +camlheader_ur +labelled-* +caml +*.annot +sys.ml diff --git a/stdlib/.depend b/stdlib/.depend new file mode 100644 index 0000000..faa3382 --- /dev/null +++ b/stdlib/.depend @@ -0,0 +1,144 @@ +arg.cmi: +array.cmi: +arrayLabels.cmi: +buffer.cmi: +callback.cmi: +camlinternalLazy.cmi: +camlinternalMod.cmi: obj.cmi +camlinternalOO.cmi: obj.cmi +char.cmi: +complex.cmi: +digest.cmi: +filename.cmi: +format.cmi: buffer.cmi +gc.cmi: +genlex.cmi: stream.cmi +hashtbl.cmi: +int32.cmi: +int64.cmi: +lazy.cmi: +lexing.cmi: +list.cmi: +listLabels.cmi: +map.cmi: +marshal.cmi: +moreLabels.cmi: set.cmi map.cmi hashtbl.cmi +nativeint.cmi: +obj.cmi: +oo.cmi: camlinternalOO.cmi +parsing.cmi: obj.cmi lexing.cmi +pervasives.cmi: +printexc.cmi: +printf.cmi: obj.cmi buffer.cmi +queue.cmi: +random.cmi: nativeint.cmi int64.cmi int32.cmi +scanf.cmi: +set.cmi: +sort.cmi: +stack.cmi: +stdLabels.cmi: +stream.cmi: +string.cmi: +stringLabels.cmi: +sys.cmi: +weak.cmi: hashtbl.cmi +arg.cmo: sys.cmi string.cmi printf.cmi list.cmi buffer.cmi array.cmi arg.cmi +arg.cmx: sys.cmx string.cmx printf.cmx list.cmx buffer.cmx array.cmx arg.cmi +array.cmo: array.cmi +array.cmx: array.cmi +arrayLabels.cmo: array.cmi arrayLabels.cmi +arrayLabels.cmx: array.cmx arrayLabels.cmi +buffer.cmo: sys.cmi string.cmi buffer.cmi +buffer.cmx: sys.cmx string.cmx buffer.cmi +callback.cmo: obj.cmi callback.cmi +callback.cmx: obj.cmx callback.cmi +camlinternalLazy.cmo: obj.cmi camlinternalLazy.cmi +camlinternalLazy.cmx: obj.cmx camlinternalLazy.cmi +camlinternalMod.cmo: obj.cmi camlinternalOO.cmi array.cmi camlinternalMod.cmi +camlinternalMod.cmx: obj.cmx camlinternalOO.cmx array.cmx camlinternalMod.cmi +camlinternalOO.cmo: sys.cmi string.cmi obj.cmi map.cmi list.cmi char.cmi \ + array.cmi camlinternalOO.cmi +camlinternalOO.cmx: sys.cmx string.cmx obj.cmx map.cmx list.cmx char.cmx \ + array.cmx camlinternalOO.cmi +char.cmo: char.cmi +char.cmx: char.cmi +complex.cmo: complex.cmi +complex.cmx: complex.cmi +digest.cmo: string.cmi printf.cmi digest.cmi +digest.cmx: string.cmx printf.cmx digest.cmi +filename.cmo: sys.cmi string.cmi random.cmi printf.cmi buffer.cmi \ + filename.cmi +filename.cmx: sys.cmx string.cmx random.cmx printf.cmx buffer.cmx \ + filename.cmi +format.cmo: string.cmi printf.cmi obj.cmi list.cmi buffer.cmi format.cmi +format.cmx: string.cmx printf.cmx obj.cmx list.cmx buffer.cmx format.cmi +gc.cmo: sys.cmi printf.cmi gc.cmi +gc.cmx: sys.cmx printf.cmx gc.cmi +genlex.cmo: string.cmi stream.cmi list.cmi hashtbl.cmi char.cmi genlex.cmi +genlex.cmx: string.cmx stream.cmx list.cmx hashtbl.cmx char.cmx genlex.cmi +hashtbl.cmo: sys.cmi array.cmi hashtbl.cmi +hashtbl.cmx: sys.cmx array.cmx hashtbl.cmi +int32.cmo: pervasives.cmi int32.cmi +int32.cmx: pervasives.cmx int32.cmi +int64.cmo: pervasives.cmi int64.cmi +int64.cmx: pervasives.cmx int64.cmi +lazy.cmo: obj.cmi camlinternalLazy.cmi lazy.cmi +lazy.cmx: obj.cmx camlinternalLazy.cmx lazy.cmi +lexing.cmo: sys.cmi string.cmi array.cmi lexing.cmi +lexing.cmx: sys.cmx string.cmx array.cmx lexing.cmi +list.cmo: list.cmi +list.cmx: list.cmi +listLabels.cmo: list.cmi listLabels.cmi +listLabels.cmx: list.cmx listLabels.cmi +map.cmo: map.cmi +map.cmx: map.cmi +marshal.cmo: string.cmi marshal.cmi +marshal.cmx: string.cmx marshal.cmi +moreLabels.cmo: set.cmi map.cmi hashtbl.cmi moreLabels.cmi +moreLabels.cmx: set.cmx map.cmx hashtbl.cmx moreLabels.cmi +nativeint.cmo: sys.cmi pervasives.cmi nativeint.cmi +nativeint.cmx: sys.cmx pervasives.cmx nativeint.cmi +obj.cmo: marshal.cmi obj.cmi +obj.cmx: marshal.cmx obj.cmi +oo.cmo: camlinternalOO.cmi oo.cmi +oo.cmx: camlinternalOO.cmx oo.cmi +parsing.cmo: obj.cmi lexing.cmi array.cmi parsing.cmi +parsing.cmx: obj.cmx lexing.cmx array.cmx parsing.cmi +pervasives.cmo: pervasives.cmi +pervasives.cmx: pervasives.cmi +printexc.cmo: printf.cmi obj.cmi buffer.cmi array.cmi printexc.cmi +printexc.cmx: printf.cmx obj.cmx buffer.cmx array.cmx printexc.cmi +printf.cmo: string.cmi obj.cmi list.cmi char.cmi buffer.cmi array.cmi \ + printf.cmi +printf.cmx: string.cmx obj.cmx list.cmx char.cmx buffer.cmx array.cmx \ + printf.cmi +queue.cmo: obj.cmi queue.cmi +queue.cmx: obj.cmx queue.cmi +random.cmo: string.cmi pervasives.cmi nativeint.cmi int64.cmi int32.cmi \ + digest.cmi char.cmi array.cmi random.cmi +random.cmx: string.cmx pervasives.cmx nativeint.cmx int64.cmx int32.cmx \ + digest.cmx char.cmx array.cmx random.cmi +scanf.cmo: string.cmi printf.cmi obj.cmi list.cmi hashtbl.cmi buffer.cmi \ + array.cmi scanf.cmi +scanf.cmx: string.cmx printf.cmx obj.cmx list.cmx hashtbl.cmx buffer.cmx \ + array.cmx scanf.cmi +set.cmo: set.cmi +set.cmx: set.cmi +sort.cmo: array.cmi sort.cmi +sort.cmx: array.cmx sort.cmi +stack.cmo: list.cmi stack.cmi +stack.cmx: list.cmx stack.cmi +stdLabels.cmo: stringLabels.cmi listLabels.cmi arrayLabels.cmi stdLabels.cmi +stdLabels.cmx: stringLabels.cmx listLabels.cmx arrayLabels.cmx stdLabels.cmi +std_exit.cmo: +std_exit.cmx: +stream.cmo: string.cmi obj.cmi list.cmi lazy.cmi stream.cmi +stream.cmx: string.cmx obj.cmx list.cmx lazy.cmx stream.cmi +string.cmo: pervasives.cmi list.cmi char.cmi string.cmi +string.cmx: pervasives.cmx list.cmx char.cmx string.cmi +stringLabels.cmo: string.cmi stringLabels.cmi +stringLabels.cmx: string.cmx stringLabels.cmi +sys.cmo: sys.cmi +sys.cmx: sys.cmi +weak.cmo: sys.cmi obj.cmi hashtbl.cmi array.cmi weak.cmi +weak.cmx: sys.cmx obj.cmx hashtbl.cmx array.cmx weak.cmi diff --git a/stdlib/Compflags b/stdlib/Compflags new file mode 100755 index 0000000..db51b2b --- /dev/null +++ b/stdlib/Compflags @@ -0,0 +1,27 @@ +#!/bin/sh +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Compflags,v 1.5 2004-11-25 00:04:15 doligez Exp $ + +case $1 in + pervasives.cm[iox]|pervasives.p.cmx) echo ' -nopervasives';; + camlinternalOO.cmi) echo ' -nopervasives';; + camlinternalOO.cmx|camlinternalOO.p.cmx) echo ' -inline 0';; + scanf.cmx|scanf.p.cmx) echo ' -inline 9';; + arrayLabels.cm[ox]|arrayLabels.p.cmx) echo ' -nolabels';; + listLabels.cm[ox]|listLabels.p.cmx) echo ' -nolabels';; + stringLabels.cm[ox]|stringLabels.p.cmx) echo ' -nolabels';; + moreLabels.cm[ox]|moreLabels.p.cmx) echo ' -nolabels';; + *) echo ' ';; +esac diff --git a/stdlib/Makefile b/stdlib/Makefile new file mode 100644 index 0000000..9fc77f9 --- /dev/null +++ b/stdlib/Makefile @@ -0,0 +1,59 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.91 2008-07-24 05:18:31 frisch Exp $ + +include Makefile.shared + +allopt: stdlib.cmxa std_exit.cmx allopt-$(PROFILING) + +allopt-noprof: + +allopt-prof: stdlib.p.cmxa std_exit.p.cmx + rm -f std_exit.p.cmi + +installopt: installopt-default installopt-$(PROFILING) + +installopt-default: + cp stdlib.cmxa stdlib.a std_exit.o *.cmx $(LIBDIR) + cd $(LIBDIR); $(RANLIB) stdlib.a + +installopt-noprof: + rm -f $(LIBDIR)/stdlib.p.cmxa; ln -s stdlib.cmxa $(LIBDIR)/stdlib.p.cmxa + rm -f $(LIBDIR)/stdlib.p.a; ln -s stdlib.a $(LIBDIR)/stdlib.p.a + rm -f $(LIBDIR)/std_exit.p.cmx; \ + ln -s std_exit.cmx $(LIBDIR)/std_exit.p.cmx + rm -f $(LIBDIR)/std_exit.p.o; ln -s std_exit.o $(LIBDIR)/std_exit.p.o + +installopt-prof: + cp stdlib.p.cmxa stdlib.p.a std_exit.p.cmx std_exit.p.o $(LIBDIR) + cd $(LIBDIR); $(RANLIB) stdlib.p.a + +stdlib.p.cmxa: $(OBJS:.cmo=.p.cmx) + $(CAMLOPT) -a -o stdlib.p.cmxa $(OBJS:.cmo=.p.cmx) + +camlheader camlheader_ur: header.c ../config/Makefile + if $(SHARPBANGSCRIPTS); then \ + echo '#!$(BINDIR)/ocamlrun' > camlheader && \ + echo '#!' | tr -d '\012' > camlheader_ur; \ + else \ + $(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) \ + -DRUNTIME_NAME='"$(BINDIR)/ocamlrun"' \ + header.c -o tmpheader$(EXE) && \ + strip tmpheader$(EXE) && \ + mv tmpheader$(EXE) camlheader && \ + cp camlheader camlheader_ur; \ + fi + +.PHONY: all allopt allopt-noprof allopt-prof install installopt +.PHONY: installopt-default installopt-noprof installopt-prof clean depend diff --git a/stdlib/Makefile.nt b/stdlib/Makefile.nt new file mode 100644 index 0000000..3b24b24 --- /dev/null +++ b/stdlib/Makefile.nt @@ -0,0 +1,32 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.46 2008-07-24 05:18:31 frisch Exp $ + +include Makefile.shared + +allopt: stdlib.cmxa std_exit.cmx + +installopt: + cp stdlib.cmxa stdlib.$(A) std_exit.$(O) *.cmx $(LIBDIR) + +camlheader camlheader_ur: headernt.c ../config/Makefile + $(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun headernt.c + $(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS) + rm -f camlheader.exe + mv tmpheader.exe camlheader + cp camlheader camlheader_ur + +# TODO: do not call flexlink to build tmpheader.exe (we don't need +# the export table) + diff --git a/stdlib/Makefile.shared b/stdlib/Makefile.shared new file mode 100755 index 0000000..629f49e --- /dev/null +++ b/stdlib/Makefile.shared @@ -0,0 +1,96 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile.shared,v 1.2 2008-08-01 16:57:10 mauny Exp $ + +include ../config/Makefile +RUNTIME=../boot/ocamlrun +COMPILER=../ocamlc +CAMLC=$(RUNTIME) $(COMPILER) +COMPFLAGS=-g -warn-error A -nostdlib +OPTCOMPILER=../ocamlopt +CAMLOPT=$(RUNTIME) $(OPTCOMPILER) +OPTCOMPFLAGS=-warn-error A -nostdlib -g +CAMLDEP=../boot/ocamlrun ../tools/ocamldep + +OBJS=pervasives.cmo $(OTHERS) +OTHERS=array.cmo list.cmo char.cmo string.cmo sys.cmo \ + hashtbl.cmo sort.cmo marshal.cmo obj.cmo \ + int32.cmo int64.cmo nativeint.cmo \ + lexing.cmo parsing.cmo \ + set.cmo map.cmo stack.cmo queue.cmo \ + camlinternalLazy.cmo lazy.cmo stream.cmo \ + buffer.cmo printf.cmo format.cmo scanf.cmo \ + arg.cmo printexc.cmo gc.cmo \ + digest.cmo random.cmo callback.cmo \ + camlinternalOO.cmo oo.cmo camlinternalMod.cmo \ + genlex.cmo weak.cmo \ + filename.cmo complex.cmo \ + arrayLabels.cmo listLabels.cmo stringLabels.cmo moreLabels.cmo stdLabels.cmo + +all: stdlib.cma std_exit.cmo camlheader camlheader_ur + +install: + cp stdlib.cma std_exit.cmo *.cmi *.mli *.ml camlheader camlheader_ur $(LIBDIR) + +stdlib.cma: $(OBJS) + $(CAMLC) -a -o stdlib.cma $(OBJS) + +stdlib.cmxa: $(OBJS:.cmo=.cmx) + $(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx) + +sys.ml: sys.mlp ../VERSION + sed -e "s|%%VERSION%%|`head -1 ../VERSION`|" sys.mlp >sys.ml + +clean:: + rm -f sys.ml + +clean:: + rm -f camlheader camlheader_ur + +.SUFFIXES: .mli .ml .cmi .cmo .cmx .p.cmx + +.mli.cmi: + $(CAMLC) $(COMPFLAGS) `./Compflags $@` -c $< + +.ml.cmo: + $(CAMLC) $(COMPFLAGS) `./Compflags $@` -c $< + +.ml.cmx: + $(CAMLOPT) $(OPTCOMPFLAGS) `./Compflags $@` -c $< + +.ml.p.cmx: + $(CAMLOPT) $(OPTCOMPFLAGS) `./Compflags $@` -p -c -o $*.p.cmx $< + +# Dependencies on the compiler +$(OBJS) std_exit.cmo: $(COMPILER) +$(OBJS:.cmo=.cmi) std_exit.cmi: $(COMPILER) +$(OBJS:.cmo=.cmx) std_exit.cmx: $(OPTCOMPILER) +$(OBJS:.cmo=.p.cmx) std_exit.p.cmx: $(OPTCOMPILER) + +# Dependencies on Pervasives (not tracked by ocamldep) +$(OBJS) std_exit.cmo: pervasives.cmi +$(OTHERS:.cmo=.cmi) std_exit.cmi: pervasives.cmi +$(OBJS:.cmo=.cmx) std_exit.cmx: pervasives.cmi +$(OBJS:.cmo=.p.cmx) std_exit.p.cmx: pervasives.cmi +$(OTHERS:.cmo=.cmx) std_exit.cmx: pervasives.cmx +$(OTHERS:.cmo=.p.cmx) std_exit.p.cmx: pervasives.cmx + +clean:: + rm -f *.cm* *.$(O) *.$(A) + rm -f *~ + +include .depend + +depend: + $(CAMLDEP) *.mli *.ml > .depend diff --git a/stdlib/StdlibModules b/stdlib/StdlibModules new file mode 100644 index 0000000..96f1c41 --- /dev/null +++ b/stdlib/StdlibModules @@ -0,0 +1,49 @@ +# This file lists all standard library modules. -*- Makefile -*- +# It is used in particular to know what to expunge in toplevels. +# $Id: StdlibModules,v 1.4 2008-08-01 16:57:10 mauny Exp $ + +STDLIB_MODULES=\ + arg \ + array \ + arrayLabels \ + buffer \ + callback \ + camlinternalLazy \ + camlinternalMod \ + camlinternalOO \ + char \ + complex \ + digest \ + filename \ + format \ + gc \ + genlex \ + hashtbl \ + int32 \ + int64 \ + lazy \ + lexing \ + list \ + listLabels \ + map \ + marshal \ + moreLabels \ + nativeint \ + obj \ + oo \ + parsing \ + pervasives \ + printexc \ + printf \ + queue \ + random \ + scanf \ + set \ + sort \ + stack \ + stdLabels \ + stream \ + string \ + stringLabels \ + sys \ + weak diff --git a/stdlib/arg.ml b/stdlib/arg.ml new file mode 100644 index 0000000..db9c29b --- /dev/null +++ b/stdlib/arg.ml @@ -0,0 +1,252 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arg.ml,v 1.36 2008-01-11 16:13:16 doligez Exp $ *) + +type key = string +type doc = string +type usage_msg = string +type anon_fun = (string -> unit) + +type spec = + | Unit of (unit -> unit) (* Call the function with unit argument *) + | Bool of (bool -> unit) (* Call the function with a bool argument *) + | Set of bool ref (* Set the reference to true *) + | Clear of bool ref (* Set the reference to false *) + | String of (string -> unit) (* Call the function with a string argument *) + | Set_string of string ref (* Set the reference to the string argument *) + | Int of (int -> unit) (* Call the function with an int argument *) + | Set_int of int ref (* Set the reference to the int argument *) + | Float of (float -> unit) (* Call the function with a float argument *) + | Set_float of float ref (* Set the reference to the float argument *) + | Tuple of spec list (* Take several arguments according to the + spec list *) + | Symbol of string list * (string -> unit) + (* Take one of the symbols as argument and + call the function with the symbol. *) + | Rest of (string -> unit) (* Stop interpreting keywords and call the + function with each remaining argument *) + +exception Bad of string +exception Help of string + +type error = + | Unknown of string + | Wrong of string * string * string (* option, actual, expected *) + | Missing of string + | Message of string + +exception Stop of error;; (* used internally *) + +open Printf + +let rec assoc3 x l = + match l with + | [] -> raise Not_found + | (y1, y2, y3) :: t when y1 = x -> y2 + | _ :: t -> assoc3 x t +;; + +let make_symlist prefix sep suffix l = + match l with + | [] -> "<none>" + | h::t -> (List.fold_left (fun x y -> x ^ sep ^ y) (prefix ^ h) t) ^ suffix +;; + +let print_spec buf (key, spec, doc) = + match spec with + | Symbol (l, _) -> bprintf buf " %s %s%s\n" key (make_symlist "{" "|" "}" l) + doc + | _ -> bprintf buf " %s %s\n" key doc +;; + +let help_action () = raise (Stop (Unknown "-help"));; + +let add_help speclist = + let add1 = + try ignore (assoc3 "-help" speclist); [] + with Not_found -> + ["-help", Unit help_action, " Display this list of options"] + and add2 = + try ignore (assoc3 "--help" speclist); [] + with Not_found -> + ["--help", Unit help_action, " Display this list of options"] + in + speclist @ (add1 @ add2) +;; + +let usage_b buf speclist errmsg = + bprintf buf "%s\n" errmsg; + List.iter (print_spec buf) (add_help speclist); +;; + +let usage speclist errmsg = + let b = Buffer.create 200 in + usage_b b speclist errmsg; + eprintf "%s" (Buffer.contents b); +;; + +let current = ref 0;; + +let parse_argv ?(current=current) argv speclist anonfun errmsg = + let l = Array.length argv in + let b = Buffer.create 200 in + let initpos = !current in + let stop error = + let progname = if initpos < l then argv.(initpos) else "(?)" in + begin match error with + | Unknown "-help" -> () + | Unknown "--help" -> () + | Unknown s -> + bprintf b "%s: unknown option `%s'.\n" progname s + | Missing s -> + bprintf b "%s: option `%s' needs an argument.\n" progname s + | Wrong (opt, arg, expected) -> + bprintf b "%s: wrong argument `%s'; option `%s' expects %s.\n" + progname arg opt expected + | Message s -> + bprintf b "%s: %s.\n" progname s + end; + usage_b b speclist errmsg; + if error = Unknown "-help" || error = Unknown "--help" + then raise (Help (Buffer.contents b)) + else raise (Bad (Buffer.contents b)) + in + incr current; + while !current < l do + let s = argv.(!current) in + if String.length s >= 1 && String.get s 0 = '-' then begin + let action = + try assoc3 s speclist + with Not_found -> stop (Unknown s) + in + begin try + let rec treat_action = function + | Unit f -> f (); + | Bool f when !current + 1 < l -> + let arg = argv.(!current + 1) in + begin try f (bool_of_string arg) + with Invalid_argument "bool_of_string" -> + raise (Stop (Wrong (s, arg, "a boolean"))) + end; + incr current; + | Set r -> r := true; + | Clear r -> r := false; + | String f when !current + 1 < l -> + f argv.(!current + 1); + incr current; + | Symbol (symb, f) when !current + 1 < l -> + let arg = argv.(!current + 1) in + if List.mem arg symb then begin + f argv.(!current + 1); + incr current; + end else begin + raise (Stop (Wrong (s, arg, "one of: " + ^ (make_symlist "" " " "" symb)))) + end + | Set_string r when !current + 1 < l -> + r := argv.(!current + 1); + incr current; + | Int f when !current + 1 < l -> + let arg = argv.(!current + 1) in + begin try f (int_of_string arg) + with Failure "int_of_string" -> + raise (Stop (Wrong (s, arg, "an integer"))) + end; + incr current; + | Set_int r when !current + 1 < l -> + let arg = argv.(!current + 1) in + begin try r := (int_of_string arg) + with Failure "int_of_string" -> + raise (Stop (Wrong (s, arg, "an integer"))) + end; + incr current; + | Float f when !current + 1 < l -> + let arg = argv.(!current + 1) in + begin try f (float_of_string arg); + with Failure "float_of_string" -> + raise (Stop (Wrong (s, arg, "a float"))) + end; + incr current; + | Set_float r when !current + 1 < l -> + let arg = argv.(!current + 1) in + begin try r := (float_of_string arg); + with Failure "float_of_string" -> + raise (Stop (Wrong (s, arg, "a float"))) + end; + incr current; + | Tuple specs -> + List.iter treat_action specs; + | Rest f -> + while !current < l - 1 do + f argv.(!current + 1); + incr current; + done; + | _ -> raise (Stop (Missing s)) + in + treat_action action + with Bad m -> stop (Message m); + | Stop e -> stop e; + end; + incr current; + end else begin + (try anonfun s with Bad m -> stop (Message m)); + incr current; + end; + done; +;; + +let parse l f msg = + try + parse_argv Sys.argv l f msg; + with + | Bad msg -> eprintf "%s" msg; exit 2; + | Help msg -> printf "%s" msg; exit 0; +;; + +let rec second_word s = + let len = String.length s in + let rec loop n = + if n >= len then len + else if s.[n] = ' ' then loop (n+1) + else n + in + try loop (String.index s ' ') + with Not_found -> len +;; + +let max_arg_len cur (kwd, spec, doc) = + match spec with + | Symbol _ -> max cur (String.length kwd) + | _ -> max cur (String.length kwd + second_word doc) +;; + +let add_padding len ksd = + match ksd with + | (kwd, (Symbol (l, _) as spec), msg) -> + let cutcol = second_word msg in + let spaces = String.make (len - cutcol + 3) ' ' in + (kwd, spec, "\n" ^ spaces ^ msg) + | (kwd, spec, msg) -> + let cutcol = second_word msg in + let spaces = String.make (len - String.length kwd - cutcol) ' ' in + let prefix = String.sub msg 0 cutcol in + let suffix = String.sub msg cutcol (String.length msg - cutcol) in + (kwd, spec, prefix ^ spaces ^ suffix) +;; + +let align speclist = + let completed = add_help speclist in + let len = List.fold_left max_arg_len 0 completed in + List.map (add_padding len) completed +;; diff --git a/stdlib/arg.mli b/stdlib/arg.mli new file mode 100644 index 0000000..0428d18 --- /dev/null +++ b/stdlib/arg.mli @@ -0,0 +1,135 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arg.mli,v 1.37 2008-01-11 16:13:16 doligez Exp $ *) + +(** Parsing of command line arguments. + + This module provides a general mechanism for extracting options and + arguments from the command line to the program. + + Syntax of command lines: + A keyword is a character string starting with a [-]. + An option is a keyword alone or followed by an argument. + The types of keywords are: [Unit], [Bool], [Set], [Clear], + [String], [Set_string], [Int], [Set_int], [Float], [Set_float], + [Tuple], [Symbol], and [Rest]. + [Unit], [Set] and [Clear] keywords take no argument. A [Rest] + keyword takes the remaining of the command line as arguments. + Every other keyword takes the following word on the command line + as argument. + Arguments not preceded by a keyword are called anonymous arguments. + + Examples ([cmd] is assumed to be the command name): +- [cmd -flag ](a unit option) +- [cmd -int 1 ](an int option with argument [1]) +- [cmd -string foobar ](a string option with argument ["foobar"]) +- [cmd -float 12.34 ](a float option with argument [12.34]) +- [cmd a b c ](three anonymous arguments: ["a"], ["b"], and ["c"]) +- [cmd a b -- c d ](two anonymous arguments and a rest option with + two arguments) +*) + +type spec = + | Unit of (unit -> unit) (** Call the function with unit argument *) + | Bool of (bool -> unit) (** Call the function with a bool argument *) + | Set of bool ref (** Set the reference to true *) + | Clear of bool ref (** Set the reference to false *) + | String of (string -> unit) (** Call the function with a string argument *) + | Set_string of string ref (** Set the reference to the string argument *) + | Int of (int -> unit) (** Call the function with an int argument *) + | Set_int of int ref (** Set the reference to the int argument *) + | Float of (float -> unit) (** Call the function with a float argument *) + | Set_float of float ref (** Set the reference to the float argument *) + | Tuple of spec list (** Take several arguments according to the + spec list *) + | Symbol of string list * (string -> unit) + (** Take one of the symbols as argument and + call the function with the symbol *) + | Rest of (string -> unit) (** Stop interpreting keywords and call the + function with each remaining argument *) +(** The concrete type describing the behavior associated + with a keyword. *) + +type key = string +type doc = string +type usage_msg = string +type anon_fun = (string -> unit) + +val parse : + (key * spec * doc) list -> anon_fun -> usage_msg -> unit +(** [Arg.parse speclist anon_fun usage_msg] parses the command line. + [speclist] is a list of triples [(key, spec, doc)]. + [key] is the option keyword, it must start with a ['-'] character. + [spec] gives the option type and the function to call when this option + is found on the command line. + [doc] is a one-line description of this option. + [anon_fun] is called on anonymous arguments. + The functions in [spec] and [anon_fun] are called in the same order + as their arguments appear on the command line. + + If an error occurs, [Arg.parse] exits the program, after printing + an error message as follows: +- The reason for the error: unknown option, invalid or missing argument, etc. +- [usage_msg] +- The list of options, each followed by the corresponding [doc] string. + + For the user to be able to specify anonymous arguments starting with a + [-], include for example [("-", String anon_fun, doc)] in [speclist]. + + By default, [parse] recognizes two unit options, [-help] and [--help], + which will display [usage_msg] and the list of options, and exit + the program. You can override this behaviour by specifying your + own [-help] and [--help] options in [speclist]. +*) + +val parse_argv : ?current: int ref -> string array -> + (key * spec * doc) list -> anon_fun -> usage_msg -> unit +(** [Arg.parse_argv ~current args speclist anon_fun usage_msg] parses + the array [args] as if it were the command line. It uses and updates + the value of [~current] (if given), or [Arg.current]. You must set + it before calling [parse_argv]. The initial value of [current] + is the index of the program name (argument 0) in the array. + If an error occurs, [Arg.parse_argv] raises [Arg.Bad] with + the error message as argument. If option [-help] or [--help] is + given, [Arg.parse_argv] raises [Arg.Help] with the help message + as argument. +*) + +exception Help of string +(** Raised by [Arg.parse_argv] when the user asks for help. *) + +exception Bad of string +(** Functions in [spec] or [anon_fun] can raise [Arg.Bad] with an error + message to reject invalid arguments. + [Arg.Bad] is also raised by [Arg.parse_argv] in case of an error. *) + +val usage : (key * spec * doc) list -> usage_msg -> unit +(** [Arg.usage speclist usage_msg] prints an error message including + the list of valid options. This is the same message that + {!Arg.parse} prints in case of error. + [speclist] and [usage_msg] are the same as for [Arg.parse]. *) + +val align: (key * spec * doc) list -> (key * spec * doc) list;; +(** Align the documentation strings by inserting spaces at the first + space, according to the length of the keyword. Use a + space as the first character in a doc string if you want to + align the whole string. The doc strings corresponding to + [Symbol] arguments are aligned on the next line. *) + +val current : int ref +(** Position (in {!Sys.argv}) of the argument being processed. You can + change this value, e.g. to force {!Arg.parse} to skip some arguments. + {!Arg.parse} uses the initial value of {!Arg.current} as the index of + argument 0 (the program name) and starts parsing arguments + at the next element. *) diff --git a/stdlib/array.ml b/stdlib/array.ml new file mode 100644 index 0000000..44795e6 --- /dev/null +++ b/stdlib/array.ml @@ -0,0 +1,279 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: array.ml,v 1.24 2005-04-11 16:43:19 doligez Exp $ *) + +(* Array operations *) + +external length : 'a array -> int = "%array_length" +external get: 'a array -> int -> 'a = "%array_safe_get" +external set: 'a array -> int -> 'a -> unit = "%array_safe_set" +external unsafe_get: 'a array -> int -> 'a = "%array_unsafe_get" +external unsafe_set: 'a array -> int -> 'a -> unit = "%array_unsafe_set" +external make: int -> 'a -> 'a array = "caml_make_vect" +external create: int -> 'a -> 'a array = "caml_make_vect" + +let init l f = + if l = 0 then [||] else + let res = create l (f 0) in + for i = 1 to pred l do + unsafe_set res i (f i) + done; + res + +let make_matrix sx sy init = + let res = create sx [||] in + for x = 0 to pred sx do + unsafe_set res x (create sy init) + done; + res + +let create_matrix = make_matrix + +let copy a = + let l = length a in + if l = 0 then [||] else begin + let res = create l (unsafe_get a 0) in + for i = 1 to pred l do + unsafe_set res i (unsafe_get a i) + done; + res + end + +let append a1 a2 = + let l1 = length a1 and l2 = length a2 in + if l1 = 0 && l2 = 0 then [||] else begin + let r = create (l1 + l2) (unsafe_get (if l1 > 0 then a1 else a2) 0) in + for i = 0 to l1 - 1 do unsafe_set r i (unsafe_get a1 i) done; + for i = 0 to l2 - 1 do unsafe_set r (i + l1) (unsafe_get a2 i) done; + r + end + +let concat_aux init al = + let rec size accu = function + | [] -> accu + | h::t -> size (accu + length h) t + in + let res = create (size 0 al) init in + let rec fill pos = function + | [] -> () + | h::t -> + for i = 0 to length h - 1 do + unsafe_set res (pos + i) (unsafe_get h i); + done; + fill (pos + length h) t; + in + fill 0 al; + res +;; + +let concat al = + let rec find_init = function + [] -> [||] + | a :: rem -> + if length a > 0 then concat_aux (unsafe_get a 0) al else find_init rem + in find_init al + +let sub a ofs len = + if ofs < 0 || len < 0 || ofs > length a - len then invalid_arg "Array.sub" + else if len = 0 then [||] + else begin + let r = create len (unsafe_get a ofs) in + for i = 1 to len - 1 do unsafe_set r i (unsafe_get a (ofs + i)) done; + r + end + +let fill a ofs len v = + if ofs < 0 || len < 0 || ofs > length a - len + then invalid_arg "Array.fill" + else for i = ofs to ofs + len - 1 do unsafe_set a i v done + +let blit a1 ofs1 a2 ofs2 len = + if len < 0 || ofs1 < 0 || ofs1 > length a1 - len + || ofs2 < 0 || ofs2 > length a2 - len + then invalid_arg "Array.blit" + else if ofs1 < ofs2 then + (* Top-down copy *) + for i = len - 1 downto 0 do + unsafe_set a2 (ofs2 + i) (unsafe_get a1 (ofs1 + i)) + done + else + (* Bottom-up copy *) + for i = 0 to len - 1 do + unsafe_set a2 (ofs2 + i) (unsafe_get a1 (ofs1 + i)) + done + +let iter f a = + for i = 0 to length a - 1 do f(unsafe_get a i) done + +let map f a = + let l = length a in + if l = 0 then [||] else begin + let r = create l (f(unsafe_get a 0)) in + for i = 1 to l - 1 do + unsafe_set r i (f(unsafe_get a i)) + done; + r + end + +let iteri f a = + for i = 0 to length a - 1 do f i (unsafe_get a i) done + +let mapi f a = + let l = length a in + if l = 0 then [||] else begin + let r = create l (f 0 (unsafe_get a 0)) in + for i = 1 to l - 1 do + unsafe_set r i (f i (unsafe_get a i)) + done; + r + end + +let to_list a = + let rec tolist i res = + if i < 0 then res else tolist (i - 1) (unsafe_get a i :: res) in + tolist (length a - 1) [] + +(* Cannot use List.length here because the List module depends on Array. *) +let rec list_length accu = function + | [] -> accu + | h::t -> list_length (succ accu) t +;; + +let of_list = function + [] -> [||] + | hd::tl as l -> + let a = create (list_length 0 l) hd in + let rec fill i = function + [] -> a + | hd::tl -> unsafe_set a i hd; fill (i+1) tl in + fill 1 tl + +let fold_left f x a = + let r = ref x in + for i = 0 to length a - 1 do + r := f !r (unsafe_get a i) + done; + !r + +let fold_right f a x = + let r = ref x in + for i = length a - 1 downto 0 do + r := f (unsafe_get a i) !r + done; + !r + +exception Bottom of int;; +let sort cmp a = + let maxson l i = + let i31 = i+i+i+1 in + let x = ref i31 in + if i31+2 < l then begin + if cmp (get a i31) (get a (i31+1)) < 0 then x := i31+1; + if cmp (get a !x) (get a (i31+2)) < 0 then x := i31+2; + !x + end else + if i31+1 < l && cmp (get a i31) (get a (i31+1)) < 0 + then i31+1 + else if i31 < l then i31 else raise (Bottom i) + in + let rec trickledown l i e = + let j = maxson l i in + if cmp (get a j) e > 0 then begin + set a i (get a j); + trickledown l j e; + end else begin + set a i e; + end; + in + let rec trickle l i e = try trickledown l i e with Bottom i -> set a i e in + let rec bubbledown l i = + let j = maxson l i in + set a i (get a j); + bubbledown l j + in + let bubble l i = try bubbledown l i with Bottom i -> i in + let rec trickleup i e = + let father = (i - 1) / 3 in + assert (i <> father); + if cmp (get a father) e < 0 then begin + set a i (get a father); + if father > 0 then trickleup father e else set a 0 e; + end else begin + set a i e; + end; + in + let l = length a in + for i = (l + 1) / 3 - 1 downto 0 do trickle l i (get a i); done; + for i = l - 1 downto 2 do + let e = (get a i) in + set a i (get a 0); + trickleup (bubble i 0) e; + done; + if l > 1 then (let e = (get a 1) in set a 1 (get a 0); set a 0 e); +;; + +let cutoff = 5;; +let stable_sort cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + set dst d s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 (get a i1) i2 s2 (d + 1) + else + blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + set dst d s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 (get src2 i2) (d + 1) + else + blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs (get a src1ofs) src2ofs (get src2 src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = (get a (srcofs + i)) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp (get dst !j) e > 0) do + set dst (!j + 1) (get dst !j); + decr j; + done; + set dst (!j + 1) e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = make l2 (get a 0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let fast_sort = stable_sort;; diff --git a/stdlib/array.mli b/stdlib/array.mli new file mode 100644 index 0000000..72563cf --- /dev/null +++ b/stdlib/array.mli @@ -0,0 +1,205 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: array.mli,v 1.40 2005-10-25 18:34:07 doligez Exp $ *) + +(** Array operations. *) + +external length : 'a array -> int = "%array_length" +(** Return the length (number of elements) of the given array. *) + +external get : 'a array -> int -> 'a = "%array_safe_get" +(** [Array.get a n] returns the element number [n] of array [a]. + The first element has number 0. + The last element has number [Array.length a - 1]. + You can also write [a.(n)] instead of [Array.get a n]. + + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [(Array.length a - 1)]. *) + +external set : 'a array -> int -> 'a -> unit = "%array_safe_set" +(** [Array.set a n x] modifies array [a] in place, replacing + element number [n] with [x]. + You can also write [a.(n) <- x] instead of [Array.set a n x]. + + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [Array.length a - 1]. *) + +external make : int -> 'a -> 'a array = "caml_make_vect" +(** [Array.make n x] returns a fresh array of length [n], + initialized with [x]. + All the elements of this new array are initially + physically equal to [x] (in the sense of the [==] predicate). + Consequently, if [x] is mutable, it is shared among all elements + of the array, and modifying [x] through one of the array entries + will modify all other entries at the same time. + + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. + If the value of [x] is a floating-point number, then the maximum + size is only [Sys.max_array_length / 2].*) + +external create : int -> 'a -> 'a array = "caml_make_vect" +(** @deprecated [Array.create] is an alias for {!Array.make}. *) + +val init : int -> (int -> 'a) -> 'a array +(** [Array.init n f] returns a fresh array of length [n], + with element number [i] initialized to the result of [f i]. + In other terms, [Array.init n f] tabulates the results of [f] + applied to the integers [0] to [n-1]. + + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. + If the return type of [f] is [float], then the maximum + size is only [Sys.max_array_length / 2].*) + +val make_matrix : int -> int -> 'a -> 'a array array +(** [Array.make_matrix dimx dimy e] returns a two-dimensional array + (an array of arrays) with first dimension [dimx] and + second dimension [dimy]. All the elements of this new matrix + are initially physically equal to [e]. + The element ([x,y]) of a matrix [m] is accessed + with the notation [m.(x).(y)]. + + Raise [Invalid_argument] if [dimx] or [dimy] is negative or + greater than [Sys.max_array_length]. + If the value of [e] is a floating-point number, then the maximum + size is only [Sys.max_array_length / 2]. *) + +val create_matrix : int -> int -> 'a -> 'a array array +(** @deprecated [Array.create_matrix] is an alias for {!Array.make_matrix}. *) + +val append : 'a array -> 'a array -> 'a array +(** [Array.append v1 v2] returns a fresh array containing the + concatenation of the arrays [v1] and [v2]. *) + +val concat : 'a array list -> 'a array +(** Same as [Array.append], but concatenates a list of arrays. *) + +val sub : 'a array -> int -> int -> 'a array +(** [Array.sub a start len] returns a fresh array of length [len], + containing the elements number [start] to [start + len - 1] + of array [a]. + + Raise [Invalid_argument "Array.sub"] if [start] and [len] do not + designate a valid subarray of [a]; that is, if + [start < 0], or [len < 0], or [start + len > Array.length a]. *) + +val copy : 'a array -> 'a array +(** [Array.copy a] returns a copy of [a], that is, a fresh array + containing the same elements as [a]. *) + +val fill : 'a array -> int -> int -> 'a -> unit +(** [Array.fill a ofs len x] modifies the array [a] in place, + storing [x] in elements number [ofs] to [ofs + len - 1]. + + Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not + designate a valid subarray of [a]. *) + +val blit : 'a array -> int -> 'a array -> int -> int -> unit +(** [Array.blit v1 o1 v2 o2 len] copies [len] elements + from array [v1], starting at element number [o1], to array [v2], + starting at element number [o2]. It works correctly even if + [v1] and [v2] are the same array, and the source and + destination chunks overlap. + + Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not + designate a valid subarray of [v1], or if [o2] and [len] do not + designate a valid subarray of [v2]. *) + +val to_list : 'a array -> 'a list +(** [Array.to_list a] returns the list of all the elements of [a]. *) + +val of_list : 'a list -> 'a array +(** [Array.of_list l] returns a fresh array containing the elements + of [l]. *) + +val iter : ('a -> unit) -> 'a array -> unit +(** [Array.iter f a] applies function [f] in turn to all + the elements of [a]. It is equivalent to + [f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. *) + +val map : ('a -> 'b) -> 'a array -> 'b array +(** [Array.map f a] applies function [f] to all the elements of [a], + and builds an array with the results returned by [f]: + [[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. *) + +val iteri : (int -> 'a -> unit) -> 'a array -> unit +(** Same as {!Array.iter}, but the + function is applied to the index of the element as first argument, + and the element itself as second argument. *) + +val mapi : (int -> 'a -> 'b) -> 'a array -> 'b array +(** Same as {!Array.map}, but the + function is applied to the index of the element as first argument, + and the element itself as second argument. *) + +val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a +(** [Array.fold_left f x a] computes + [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)], + where [n] is the length of the array [a]. *) + +val fold_right : ('b -> 'a -> 'a) -> 'b array -> 'a -> 'a +(** [Array.fold_right f a x] computes + [f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))], + where [n] is the length of the array [a]. *) + + +(** {6 Sorting} *) + + +val sort : ('a -> 'a -> int) -> 'a array -> unit +(** Sort an array in increasing order according to a comparison + function. The comparison function must return 0 if its arguments + compare as equal, a positive integer if the first is greater, + and a negative integer if the first is smaller (see below for a + complete specification). For example, {!Pervasives.compare} is + a suitable comparison function, provided there are no floating-point + NaN values in the data. After calling [Array.sort], the + array is sorted in place in increasing order. + [Array.sort] is guaranteed to run in constant heap space + and (at most) logarithmic stack space. + + The current implementation uses Heap Sort. It runs in constant + stack space. + + Specification of the comparison function: + Let [a] be the array and [cmp] the comparison function. The following + must be true for all x, y, z in a : +- [cmp x y] > 0 if and only if [cmp y x] < 0 +- if [cmp x y] >= 0 and [cmp y z] >= 0 then [cmp x z] >= 0 + + When [Array.sort] returns, [a] contains the same elements as before, + reordered in such a way that for all i and j valid indices of [a] : +- [cmp a.(i) a.(j)] >= 0 if and only if i >= j +*) + +val stable_sort : ('a -> 'a -> int) -> 'a array -> unit +(** Same as {!Array.sort}, but the sorting algorithm is stable (i.e. + elements that compare equal are kept in their original order) and + not guaranteed to run in constant heap space. + + The current implementation uses Merge Sort. It uses [n/2] + words of heap space, where [n] is the length of the array. + It is usually faster than the current implementation of {!Array.sort}. +*) + +val fast_sort : ('a -> 'a -> int) -> 'a array -> unit +(** Same as {!Array.sort} or {!Array.stable_sort}, whichever is faster + on typical input. +*) + + +(**/**) +(** {6 Undocumented functions} *) + +external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get" +external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set" diff --git a/stdlib/arrayLabels.ml b/stdlib/arrayLabels.ml new file mode 100644 index 0000000..bf2aae6 --- /dev/null +++ b/stdlib/arrayLabels.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arrayLabels.ml,v 1.3 2001-12-07 13:40:49 xleroy Exp $ *) + +(* Module [ArrayLabels]: labelled Array module *) + +include Array diff --git a/stdlib/arrayLabels.mli b/stdlib/arrayLabels.mli new file mode 100644 index 0000000..ef05aed --- /dev/null +++ b/stdlib/arrayLabels.mli @@ -0,0 +1,209 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: arrayLabels.mli,v 1.12 2007-01-22 08:06:09 garrigue Exp $ *) + +(** Array operations. *) + +external length : 'a array -> int = "%array_length" +(** Return the length (number of elements) of the given array. *) + +external get : 'a array -> int -> 'a = "%array_safe_get" +(** [Array.get a n] returns the element number [n] of array [a]. + The first element has number 0. + The last element has number [Array.length a - 1]. + You can also write [a.(n)] instead of [Array.get a n]. + + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [(Array.length a - 1)]. *) + +external set : 'a array -> int -> 'a -> unit = "%array_safe_set" +(** [Array.set a n x] modifies array [a] in place, replacing + element number [n] with [x]. + You can also write [a.(n) <- x] instead of [Array.set a n x]. + + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [Array.length a - 1]. *) + +external make : int -> 'a -> 'a array = "caml_make_vect" +(** [Array.make n x] returns a fresh array of length [n], + initialized with [x]. + All the elements of this new array are initially + physically equal to [x] (in the sense of the [==] predicate). + Consequently, if [x] is mutable, it is shared among all elements + of the array, and modifying [x] through one of the array entries + will modify all other entries at the same time. + + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. + If the value of [x] is a floating-point number, then the maximum + size is only [Sys.max_array_length / 2].*) + +external create : int -> 'a -> 'a array = "caml_make_vect" +(** @deprecated [Array.create] is an alias for {!ArrayLabels.make}. *) + +val init : int -> f:(int -> 'a) -> 'a array +(** [Array.init n f] returns a fresh array of length [n], + with element number [i] initialized to the result of [f i]. + In other terms, [Array.init n f] tabulates the results of [f] + applied to the integers [0] to [n-1]. + + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. + If the return type of [f] is [float], then the maximum + size is only [Sys.max_array_length / 2].*) + +val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array +(** [Array.make_matrix dimx dimy e] returns a two-dimensional array + (an array of arrays) with first dimension [dimx] and + second dimension [dimy]. All the elements of this new matrix + are initially physically equal to [e]. + The element ([x,y]) of a matrix [m] is accessed + with the notation [m.(x).(y)]. + + Raise [Invalid_argument] if [dimx] or [dimy] is negative or + greater than [Sys.max_array_length]. + If the value of [e] is a floating-point number, then the maximum + size is only [Sys.max_array_length / 2]. *) + +val create_matrix : dimx:int -> dimy:int -> 'a -> 'a array array +(** @deprecated [Array.create_matrix] is an alias for + {!ArrayLabels.make_matrix}. *) + +val append : 'a array -> 'a array -> 'a array +(** [Array.append v1 v2] returns a fresh array containing the + concatenation of the arrays [v1] and [v2]. *) + +val concat : 'a array list -> 'a array +(** Same as [Array.append], but concatenates a list of arrays. *) + +val sub : 'a array -> pos:int -> len:int -> 'a array +(** [Array.sub a start len] returns a fresh array of length [len], + containing the elements number [start] to [start + len - 1] + of array [a]. + + Raise [Invalid_argument "Array.sub"] if [start] and [len] do not + designate a valid subarray of [a]; that is, if + [start < 0], or [len < 0], or [start + len > Array.length a]. *) + +val copy : 'a array -> 'a array +(** [Array.copy a] returns a copy of [a], that is, a fresh array + containing the same elements as [a]. *) + +val fill : 'a array -> pos:int -> len:int -> 'a -> unit +(** [Array.fill a ofs len x] modifies the array [a] in place, + storing [x] in elements number [ofs] to [ofs + len - 1]. + + Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not + designate a valid subarray of [a]. *) + +val blit : + src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int -> len:int -> + unit +(** [Array.blit v1 o1 v2 o2 len] copies [len] elements + from array [v1], starting at element number [o1], to array [v2], + starting at element number [o2]. It works correctly even if + [v1] and [v2] are the same array, and the source and + destination chunks overlap. + + Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not + designate a valid subarray of [v1], or if [o2] and [len] do not + designate a valid subarray of [v2]. *) + +val to_list : 'a array -> 'a list +(** [Array.to_list a] returns the list of all the elements of [a]. *) + +val of_list : 'a list -> 'a array +(** [Array.of_list l] returns a fresh array containing the elements + of [l]. *) + +val iter : f:('a -> unit) -> 'a array -> unit +(** [Array.iter f a] applies function [f] in turn to all + the elements of [a]. It is equivalent to + [f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. *) + +val map : f:('a -> 'b) -> 'a array -> 'b array +(** [Array.map f a] applies function [f] to all the elements of [a], + and builds an array with the results returned by [f]: + [[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. *) + +val iteri : f:(int -> 'a -> unit) -> 'a array -> unit +(** Same as {!ArrayLabels.iter}, but the + function is applied to the index of the element as first argument, + and the element itself as second argument. *) + +val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b array +(** Same as {!ArrayLabels.map}, but the + function is applied to the index of the element as first argument, + and the element itself as second argument. *) + +val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b array -> 'a +(** [Array.fold_left f x a] computes + [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)], + where [n] is the length of the array [a]. *) + +val fold_right : f:('b -> 'a -> 'a) -> 'b array -> init:'a -> 'a +(** [Array.fold_right f a x] computes + [f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))], + where [n] is the length of the array [a]. *) + + +(** {6 Sorting} *) + + +val sort : cmp:('a -> 'a -> int) -> 'a array -> unit +(** Sort an array in increasing order according to a comparison + function. The comparison function must return 0 if its arguments + compare as equal, a positive integer if the first is greater, + and a negative integer if the first is smaller (see below for a + complete specification). For example, {!Pervasives.compare} is + a suitable comparison function, provided there are no floating-point + NaN values in the data. After calling [Array.sort], the + array is sorted in place in increasing order. + [Array.sort] is guaranteed to run in constant heap space + and (at most) logarithmic stack space. + + The current implementation uses Heap Sort. It runs in constant + stack space. + + Specification of the comparison function: + Let [a] be the array and [cmp] the comparison function. The following + must be true for all x, y, z in a : +- [cmp x y] > 0 if and only if [cmp y x] < 0 +- if [cmp x y] >= 0 and [cmp y z] >= 0 then [cmp x z] >= 0 + + When [Array.sort] returns, [a] contains the same elements as before, + reordered in such a way that for all i and j valid indices of [a] : +- [cmp a.(i) a.(j)] >= 0 if and only if i >= j +*) + +val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unit +(** Same as {!ArrayLabels.sort}, but the sorting algorithm is stable (i.e. + elements that compare equal are kept in their original order) and + not guaranteed to run in constant heap space. + + The current implementation uses Merge Sort. It uses [n/2] + words of heap space, where [n] is the length of the array. + It is usually faster than the current implementation of {!ArrayLabels.sort}. +*) + +val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unit +(** Same as {!Array.sort} or {!Array.stable_sort}, whichever is faster + on typical input. +*) + + +(**/**) + +(** {6 Undocumented functions} *) + +external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get" +external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set" diff --git a/stdlib/buffer.ml b/stdlib/buffer.ml new file mode 100644 index 0000000..36e7dda --- /dev/null +++ b/stdlib/buffer.ml @@ -0,0 +1,173 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: buffer.ml,v 1.19 2008-09-09 08:50:39 weis Exp $ *) + +(* Extensible buffers *) + +type t = + {mutable buffer : string; + mutable position : int; + mutable length : int; + initial_buffer : string} + +let create n = + let n = if n < 1 then 1 else n in + let n = if n > Sys.max_string_length then Sys.max_string_length else n in + let s = String.create n in + {buffer = s; position = 0; length = n; initial_buffer = s} + +let contents b = String.sub b.buffer 0 b.position + +let sub b ofs len = + if ofs < 0 || len < 0 || ofs > b.position - len + then invalid_arg "Buffer.sub" + else begin + let r = String.create len in + String.blit b.buffer ofs r 0 len; + r + end +;; + +let nth b ofs = + if ofs < 0 || ofs >= b.position then + invalid_arg "Buffer.nth" + else String.get b.buffer ofs +;; + +let length b = b.position + +let clear b = b.position <- 0 + +let reset b = + b.position <- 0; b.buffer <- b.initial_buffer; + b.length <- String.length b.buffer + +let resize b more = + let len = b.length in + let new_len = ref len in + while b.position + more > !new_len do new_len := 2 * !new_len done; + if !new_len > Sys.max_string_length then begin + if b.position + more <= Sys.max_string_length + then new_len := Sys.max_string_length + else failwith "Buffer.add: cannot grow buffer" + end; + let new_buffer = String.create !new_len in + String.blit b.buffer 0 new_buffer 0 b.position; + b.buffer <- new_buffer; + b.length <- !new_len + +let add_char b c = + let pos = b.position in + if pos >= b.length then resize b 1; + b.buffer.[pos] <- c; + b.position <- pos + 1 + +let add_substring b s offset len = + if offset < 0 || len < 0 || offset > String.length s - len + then invalid_arg "Buffer.add_substring"; + let new_position = b.position + len in + if new_position > b.length then resize b len; + String.blit s offset b.buffer b.position len; + b.position <- new_position + +let add_string b s = + let len = String.length s in + let new_position = b.position + len in + if new_position > b.length then resize b len; + String.blit s 0 b.buffer b.position len; + b.position <- new_position + +let add_buffer b bs = + add_substring b bs.buffer 0 bs.position + +let add_channel b ic len = + if b.position + len > b.length then resize b len; + really_input ic b.buffer b.position len; + b.position <- b.position + len + +let output_buffer oc b = + output oc b.buffer 0 b.position + +let closing = function + | '(' -> ')' + | '{' -> '}' + | _ -> assert false;; + +(* opening and closing: open and close characters, typically ( and ) + k: balance of opening and closing chars + s: the string where we are searching + start: the index where we start the search. *) +let advance_to_closing opening closing k s start = + let rec advance k i lim = + if i >= lim then raise Not_found else + if s.[i] = opening then advance (k + 1) (i + 1) lim else + if s.[i] = closing then + if k = 0 then i else advance (k - 1) (i + 1) lim + else advance k (i + 1) lim in + advance k start (String.length s);; + +let advance_to_non_alpha s start = + let rec advance i lim = + if i >= lim then lim else + match s.[i] with + | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | + 'é'|'à'|'á'|'è'|'ù'|'â'|'ê'| + 'î'|'ô'|'û'|'ë'|'ï'|'ü'|'ç'| + 'É'|'À'|'Á'|'È'|'Ù'|'Â'|'Ê'| + 'Î'|'Ô'|'Û'|'Ë'|'Ï'|'Ü'|'Ç' -> + advance (i + 1) lim + | _ -> i in + advance start (String.length s);; + +(* We are just at the beginning of an ident in s, starting at start. *) +let find_ident s start lim = + if start >= lim then raise Not_found else + match s.[start] with + (* Parenthesized ident ? *) + | '(' | '{' as c -> + let new_start = start + 1 in + let stop = advance_to_closing c (closing c) 0 s new_start in + String.sub s new_start (stop - start - 1), stop + 1 + (* Regular ident *) + | _ -> + let stop = advance_to_non_alpha s (start + 1) in + String.sub s start (stop - start), stop;; + +(* Substitute $ident, $(ident), or ${ident} in s, + according to the function mapping f. *) +let add_substitute b f s = + let lim = String.length s in + let rec subst previous i = + if i < lim then begin + match s.[i] with + | '$' as current when previous = '\\' -> + add_char b current; + subst ' ' (i + 1) + | '$' -> + let j = i + 1 in + let ident, next_i = find_ident s j lim in + add_string b (f ident); + subst ' ' next_i + | current when previous == '\\' -> + add_char b '\\'; + add_char b current; + subst ' ' (i + 1) + | '\\' as current -> + subst current (i + 1) + | current -> + add_char b current; + subst current (i + 1) + end else + if previous = '\\' then add_char b previous in + subst ' ' 0;; diff --git a/stdlib/buffer.mli b/stdlib/buffer.mli new file mode 100644 index 0000000..7d56333 --- /dev/null +++ b/stdlib/buffer.mli @@ -0,0 +1,106 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: buffer.mli,v 1.21 2005-10-25 18:34:07 doligez Exp $ *) + +(** Extensible string buffers. + + This module implements string buffers that automatically expand + as necessary. It provides accumulative concatenation of strings + in quasi-linear time (instead of quadratic time when strings are + concatenated pairwise). +*) + +type t +(** The abstract type of buffers. *) + +val create : int -> t +(** [create n] returns a fresh buffer, initially empty. + The [n] parameter is the initial size of the internal string + that holds the buffer contents. That string is automatically + reallocated when more than [n] characters are stored in the buffer, + but shrinks back to [n] characters when [reset] is called. + For best performance, [n] should be of the same order of magnitude + as the number of characters that are expected to be stored in + the buffer (for instance, 80 for a buffer that holds one output + line). Nothing bad will happen if the buffer grows beyond that + limit, however. In doubt, take [n = 16] for instance. + If [n] is not between 1 and {!Sys.max_string_length}, it will + be clipped to that interval. *) + +val contents : t -> string +(** Return a copy of the current contents of the buffer. + The buffer itself is unchanged. *) + +val sub : t -> int -> int -> string +(** [Buffer.sub b off len] returns (a copy of) the substring of the +current contents of the buffer [b] starting at offset [off] of length +[len] bytes. May raise [Invalid_argument] if out of bounds request. The +buffer itself is unaffected. *) + +val nth : t -> int -> char +(** get the n-th character of the buffer. Raise [Invalid_argument] if +index out of bounds *) + +val length : t -> int +(** Return the number of characters currently contained in the buffer. *) + +val clear : t -> unit +(** Empty the buffer. *) + +val reset : t -> unit +(** Empty the buffer and deallocate the internal string holding the + buffer contents, replacing it with the initial internal string + of length [n] that was allocated by {!Buffer.create} [n]. + For long-lived buffers that may have grown a lot, [reset] allows + faster reclamation of the space used by the buffer. *) + +val add_char : t -> char -> unit +(** [add_char b c] appends the character [c] at the end of the buffer [b]. *) + +val add_string : t -> string -> unit +(** [add_string b s] appends the string [s] at the end of the buffer [b]. *) + +val add_substring : t -> string -> int -> int -> unit +(** [add_substring b s ofs len] takes [len] characters from offset + [ofs] in string [s] and appends them at the end of the buffer [b]. *) + +val add_substitute : t -> (string -> string) -> string -> unit +(** [add_substitute b f s] appends the string pattern [s] at the end + of the buffer [b] with substitution. + The substitution process looks for variables into + the pattern and substitutes each variable name by its value, as + obtained by applying the mapping [f] to the variable name. Inside the + string pattern, a variable name immediately follows a non-escaped + [$] character and is one of the following: + - a non empty sequence of alphanumeric or [_] characters, + - an arbitrary sequence of characters enclosed by a pair of + matching parentheses or curly brackets. + An escaped [$] character is a [$] that immediately follows a backslash + character; it then stands for a plain [$]. + Raise [Not_found] if the closing character of a parenthesized variable + cannot be found. *) + +val add_buffer : t -> t -> unit +(** [add_buffer b1 b2] appends the current contents of buffer [b2] + at the end of buffer [b1]. [b2] is not modified. *) + +val add_channel : t -> in_channel -> int -> unit +(** [add_channel b ic n] reads exactly [n] character from the + input channel [ic] and stores them at the end of buffer [b]. + Raise [End_of_file] if the channel contains fewer than [n] + characters. *) + +val output_buffer : out_channel -> t -> unit +(** [output_buffer oc b] writes the current contents of buffer [b] + on the output channel [oc]. *) diff --git a/stdlib/callback.ml b/stdlib/callback.ml new file mode 100644 index 0000000..ae7a2c5 --- /dev/null +++ b/stdlib/callback.ml @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: callback.ml,v 1.5 2003-12-31 14:20:39 doligez Exp $ *) + +(* Registering Caml values with the C runtime for later callbacks *) + +external register_named_value : string -> Obj.t -> unit + = "caml_register_named_value" + +let register name v = + register_named_value name (Obj.repr v) + +let register_exception name (exn : exn) = + register_named_value name (Obj.field (Obj.repr exn) 0) diff --git a/stdlib/callback.mli b/stdlib/callback.mli new file mode 100644 index 0000000..d6ea581 --- /dev/null +++ b/stdlib/callback.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: callback.mli,v 1.6 2005-10-25 18:34:07 doligez Exp $ *) + +(** Registering Caml values with the C runtime. + + This module allows Caml values to be registered with the C runtime + under a symbolic name, so that C code can later call back registered + Caml functions, or raise registered Caml exceptions. +*) + +val register : string -> 'a -> unit +(** [Callback.register n v] registers the value [v] under + the name [n]. C code can later retrieve a handle to [v] + by calling [caml_named_value(n)]. *) + +val register_exception : string -> exn -> unit +(** [Callback.register_exception n exn] registers the + exception contained in the exception value [exn] + under the name [n]. C code can later retrieve a handle to + the exception by calling [caml_named_value(n)]. The exception + value thus obtained is suitable for passign as first argument + to [raise_constant] or [raise_with_arg]. *) diff --git a/stdlib/camlinternalLazy.ml b/stdlib/camlinternalLazy.ml new file mode 100644 index 0000000..468ce51 --- /dev/null +++ b/stdlib/camlinternalLazy.ml @@ -0,0 +1,64 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalLazy.ml,v 1.1 2008-08-01 16:57:10 mauny Exp $ *) + +(* Internals of forcing lazy values. *) + +exception Undefined;; + +let raise_undefined = Obj.repr (fun () -> raise Undefined);; + +(* Assume [blk] is a block with tag lazy *) +let force_lazy_block (blk : 'arg lazy_t) = + let closure = (Obj.obj (Obj.field (Obj.repr blk) 0) : unit -> 'arg) in + Obj.set_field (Obj.repr blk) 0 raise_undefined; + try + let result = closure () in + Obj.set_field (Obj.repr blk) 0 (Obj.repr result); (* do set_field BEFORE set_tag *) + Obj.set_tag (Obj.repr blk) Obj.forward_tag; + result + with e -> + Obj.set_field (Obj.repr blk) 0 (Obj.repr (fun () -> raise e)); + raise e +;; + +(* Assume [blk] is a block with tag lazy *) +let force_val_lazy_block (blk : 'arg lazy_t) = + let closure = (Obj.obj (Obj.field (Obj.repr blk) 0) : unit -> 'arg) in + Obj.set_field (Obj.repr blk) 0 raise_undefined; + let result = closure () in + Obj.set_field (Obj.repr blk) 0 (Obj.repr result); (* do set_field BEFORE set_tag *) + Obj.set_tag (Obj.repr blk) (Obj.forward_tag); + result +;; + +(* [force] is not used, since [Lazy.force] is declared as a primitive + whose code inlines the tag tests of its argument. This function is + here for the sake of completeness, and for debugging purpose. *) + +let force (lzv : 'arg lazy_t) = + let x = Obj.repr lzv in + let t = Obj.tag x in + if t = Obj.forward_tag then (Obj.obj (Obj.field x 0) : 'arg) else + if t <> Obj.lazy_tag then (Obj.obj x : 'arg) + else force_lazy_block lzv +;; + +let force_val (lzv : 'arg lazy_t) = + let x = Obj.repr lzv in + let t = Obj.tag x in + if t = Obj.forward_tag then (Obj.obj (Obj.field x 0) : 'arg) else + if t <> Obj.lazy_tag then (Obj.obj x : 'arg) + else force_val_lazy_block lzv +;; diff --git a/stdlib/camlinternalLazy.mli b/stdlib/camlinternalLazy.mli new file mode 100644 index 0000000..beffd7c --- /dev/null +++ b/stdlib/camlinternalLazy.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalLazy.mli,v 1.1 2008-08-01 16:57:10 mauny Exp $ *) + +(* Internals of forcing lazy values *) + +exception Undefined;; + +val force_lazy_block : 'a lazy_t -> 'a ;; + +val force_val_lazy_block : 'a lazy_t -> 'a ;; + +val force : 'a lazy_t -> 'a ;; +val force_val : 'a lazy_t -> 'a ;; diff --git a/stdlib/camlinternalMod.ml b/stdlib/camlinternalMod.ml new file mode 100644 index 0000000..802c7ac --- /dev/null +++ b/stdlib/camlinternalMod.ml @@ -0,0 +1,68 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalMod.ml,v 1.6 2008-01-11 16:13:16 doligez Exp $ *) + +type shape = + | Function + | Lazy + | Class + | Module of shape array + +let rec init_mod loc shape = + match shape with + | Function -> + let pad1 = 1 and pad2 = 2 and pad3 = 3 and pad4 = 4 + and pad5 = 5 and pad6 = 6 and pad7 = 7 and pad8 = 8 in + Obj.repr(fun _ -> + ignore pad1; ignore pad2; ignore pad3; ignore pad4; + ignore pad5; ignore pad6; ignore pad7; ignore pad8; + raise (Undefined_recursive_module loc)) + | Lazy -> + Obj.repr (lazy (raise (Undefined_recursive_module loc))) + | Class -> + Obj.repr (CamlinternalOO.dummy_class loc) + | Module comps -> + Obj.repr (Array.map (init_mod loc) comps) + +let overwrite o n = + assert (Obj.size o >= Obj.size n); + for i = 0 to Obj.size n - 1 do + Obj.set_field o i (Obj.field n i) + done + +let rec update_mod shape o n = + match shape with + | Function -> + if Obj.tag n = Obj.closure_tag && Obj.size n <= Obj.size o + then begin overwrite o n; Obj.truncate o (Obj.size n) (* PR #4008 *) end + else overwrite o (Obj.repr (fun x -> (Obj.obj n : _ -> _) x)) + | Lazy -> + if Obj.tag n = Obj.lazy_tag then + Obj.set_field o 0 (Obj.field n 0) + else if Obj.tag n = Obj.forward_tag then begin (* PR#4316 *) + Obj.set_tag o Obj.forward_tag; + Obj.set_field o 0 (Obj.field n 0) + end else begin + (* forwarding pointer was shortcut by GC *) + Obj.set_tag o Obj.forward_tag; + Obj.set_field o 0 n + end + | Class -> + assert (Obj.tag n = 0 && Obj.size n = 4); + overwrite o n + | Module comps -> + assert (Obj.tag n = 0 && Obj.size n >= Array.length comps); + for i = 0 to Array.length comps - 1 do + update_mod comps.(i) (Obj.field o i) (Obj.field n i) + done diff --git a/stdlib/camlinternalMod.mli b/stdlib/camlinternalMod.mli new file mode 100644 index 0000000..eb0dc17 --- /dev/null +++ b/stdlib/camlinternalMod.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalMod.mli,v 1.1 2004-08-12 12:57:00 xleroy Exp $ *) + +type shape = + | Function + | Lazy + | Class + | Module of shape array + +val init_mod: string * int * int -> shape -> Obj.t +val update_mod: shape -> Obj.t -> Obj.t -> unit diff --git a/stdlib/camlinternalOO.ml b/stdlib/camlinternalOO.ml new file mode 100644 index 0000000..874fe5c --- /dev/null +++ b/stdlib/camlinternalOO.ml @@ -0,0 +1,588 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalOO.ml,v 1.16 2008-01-11 16:13:16 doligez Exp $ *) + +open Obj + +(**** Object representation ****) + +let last_id = ref 0 +let new_id () = + let id = !last_id in incr last_id; id + +let set_id o id = + let id0 = !id in + Array.unsafe_set (Obj.magic o : int array) 1 id0; + id := id0 + 1 + +(**** Object copy ****) + +let copy o = + let o = (Obj.obj (Obj.dup (Obj.repr o))) in + set_id o last_id; + o + +(**** Compression options ****) +(* Parameters *) +type params = { + mutable compact_table : bool; + mutable copy_parent : bool; + mutable clean_when_copying : bool; + mutable retry_count : int; + mutable bucket_small_size : int + } + +let params = { + compact_table = true; + copy_parent = true; + clean_when_copying = true; + retry_count = 3; + bucket_small_size = 16 +} + +(**** Parameters ****) + +let step = Sys.word_size / 16 +let initial_object_size = 2 + +(**** Items ****) + +type item = DummyA | DummyB | DummyC of int + +let dummy_item = (magic () : item) + +(**** Types ****) + +type tag +type label = int +type closure = item +type t = DummyA | DummyB | DummyC of int +type obj = t array +external ret : (obj -> 'a) -> closure = "%identity" + +(**** Labels ****) + +let public_method_label s : tag = + let accu = ref 0 in + for i = 0 to String.length s - 1 do + accu := 223 * !accu + Char.code s.[i] + done; + (* reduce to 31 bits *) + accu := !accu land (1 lsl 31 - 1); + (* make it signed for 64 bits architectures *) + let tag = if !accu > 0x3FFFFFFF then !accu - (1 lsl 31) else !accu in + (* Printf.eprintf "%s = %d\n" s tag; flush stderr; *) + magic tag + +(**** Sparse array ****) + +module Vars = Map.Make(struct type t = string let compare = compare end) +type vars = int Vars.t + +module Meths = Map.Make(struct type t = string let compare = compare end) +type meths = label Meths.t +module Labs = Map.Make(struct type t = label let compare = compare end) +type labs = bool Labs.t + +(* The compiler assumes that the first field of this structure is [size]. *) +type table = + { mutable size: int; + mutable methods: closure array; + mutable methods_by_name: meths; + mutable methods_by_label: labs; + mutable previous_states: + (meths * labs * (label * item) list * vars * + label list * string list) list; + mutable hidden_meths: (label * item) list; + mutable vars: vars; + mutable initializers: (obj -> unit) list } + +let dummy_table = + { methods = [| dummy_item |]; + methods_by_name = Meths.empty; + methods_by_label = Labs.empty; + previous_states = []; + hidden_meths = []; + vars = Vars.empty; + initializers = []; + size = 0 } + +let table_count = ref 0 + +(* dummy_met should be a pointer, so use an atom *) +let dummy_met : item = obj (Obj.new_block 0 0) +(* if debugging is needed, this could be a good idea: *) +(* let dummy_met () = failwith "Undefined method" *) + +let rec fit_size n = + if n <= 2 then n else + fit_size ((n+1)/2) * 2 + +let new_table pub_labels = + incr table_count; + let len = Array.length pub_labels in + let methods = Array.create (len*2+2) dummy_met in + methods.(0) <- magic len; + methods.(1) <- magic (fit_size len * Sys.word_size / 8 - 1); + for i = 0 to len - 1 do methods.(i*2+3) <- magic pub_labels.(i) done; + { methods = methods; + methods_by_name = Meths.empty; + methods_by_label = Labs.empty; + previous_states = []; + hidden_meths = []; + vars = Vars.empty; + initializers = []; + size = initial_object_size } + +let resize array new_size = + let old_size = Array.length array.methods in + if new_size > old_size then begin + let new_buck = Array.create new_size dummy_met in + Array.blit array.methods 0 new_buck 0 old_size; + array.methods <- new_buck + end + +let put array label element = + resize array (label + 1); + array.methods.(label) <- element + +(**** Classes ****) + +let method_count = ref 0 +let inst_var_count = ref 0 + +(* type t *) +type meth = item + +let new_method table = + let index = Array.length table.methods in + resize table (index + 1); + index + +let get_method_label table name = + try + Meths.find name table.methods_by_name + with Not_found -> + let label = new_method table in + table.methods_by_name <- Meths.add name label table.methods_by_name; + table.methods_by_label <- Labs.add label true table.methods_by_label; + label + +let get_method_labels table names = + Array.map (get_method_label table) names + +let set_method table label element = + incr method_count; + if Labs.find label table.methods_by_label then + put table label element + else + table.hidden_meths <- (label, element) :: table.hidden_meths + +let get_method table label = + try List.assoc label table.hidden_meths + with Not_found -> table.methods.(label) + +let to_list arr = + if arr == magic 0 then [] else Array.to_list arr + +let narrow table vars virt_meths concr_meths = + let vars = to_list vars + and virt_meths = to_list virt_meths + and concr_meths = to_list concr_meths in + let virt_meth_labs = List.map (get_method_label table) virt_meths in + let concr_meth_labs = List.map (get_method_label table) concr_meths in + table.previous_states <- + (table.methods_by_name, table.methods_by_label, table.hidden_meths, + table.vars, virt_meth_labs, vars) + :: table.previous_states; + table.vars <- + Vars.fold + (fun lab info tvars -> + if List.mem lab vars then Vars.add lab info tvars else tvars) + table.vars Vars.empty; + let by_name = ref Meths.empty in + let by_label = ref Labs.empty in + List.iter2 + (fun met label -> + by_name := Meths.add met label !by_name; + by_label := + Labs.add label + (try Labs.find label table.methods_by_label with Not_found -> true) + !by_label) + concr_meths concr_meth_labs; + List.iter2 + (fun met label -> + by_name := Meths.add met label !by_name; + by_label := Labs.add label false !by_label) + virt_meths virt_meth_labs; + table.methods_by_name <- !by_name; + table.methods_by_label <- !by_label; + table.hidden_meths <- + List.fold_right + (fun ((lab, _) as met) hm -> + if List.mem lab virt_meth_labs then hm else met::hm) + table.hidden_meths + [] + +let widen table = + let (by_name, by_label, saved_hidden_meths, saved_vars, virt_meths, vars) = + List.hd table.previous_states + in + table.previous_states <- List.tl table.previous_states; + table.vars <- + List.fold_left + (fun s v -> Vars.add v (Vars.find v table.vars) s) + saved_vars vars; + table.methods_by_name <- by_name; + table.methods_by_label <- by_label; + table.hidden_meths <- + List.fold_right + (fun ((lab, _) as met) hm -> + if List.mem lab virt_meths then hm else met::hm) + table.hidden_meths + saved_hidden_meths + +let new_slot table = + let index = table.size in + table.size <- index + 1; + index + +let new_variable table name = + try Vars.find name table.vars + with Not_found -> + let index = new_slot table in + if name <> "" then table.vars <- Vars.add name index table.vars; + index + +let to_array arr = + if arr = Obj.magic 0 then [||] else arr + +let new_methods_variables table meths vals = + let meths = to_array meths in + let nmeths = Array.length meths and nvals = Array.length vals in + let res = Array.create (nmeths + nvals) 0 in + for i = 0 to nmeths - 1 do + res.(i) <- get_method_label table meths.(i) + done; + for i = 0 to nvals - 1 do + res.(i+nmeths) <- new_variable table vals.(i) + done; + res + +let get_variable table name = + try Vars.find name table.vars with Not_found -> assert false + +let get_variables table names = + Array.map (get_variable table) names + +let add_initializer table f = + table.initializers <- f::table.initializers + +(* +module Keys = Map.Make(struct type t = tag array let compare = compare end) +let key_map = ref Keys.empty +let get_key tags : item = + try magic (Keys.find tags !key_map : tag array) + with Not_found -> + key_map := Keys.add tags tags !key_map; + magic tags +*) + +let create_table public_methods = + if public_methods == magic 0 then new_table [||] else + (* [public_methods] must be in ascending order for bytecode *) + let tags = Array.map public_method_label public_methods in + let table = new_table tags in + Array.iteri + (fun i met -> + let lab = i*2+2 in + table.methods_by_name <- Meths.add met lab table.methods_by_name; + table.methods_by_label <- Labs.add lab true table.methods_by_label) + public_methods; + table + +let init_class table = + inst_var_count := !inst_var_count + table.size - 1; + table.initializers <- List.rev table.initializers; + resize table (3 + magic table.methods.(1) * 16 / Sys.word_size) + +let inherits cla vals virt_meths concr_meths (_, super, _, env) top = + narrow cla vals virt_meths concr_meths; + let init = + if top then super cla env else Obj.repr (super cla) in + widen cla; + Array.concat + [[| repr init |]; + magic (Array.map (get_variable cla) (to_array vals) : int array); + Array.map + (fun nm -> repr (get_method cla (get_method_label cla nm) : closure)) + (to_array concr_meths) ] + +let make_class pub_meths class_init = + let table = create_table pub_meths in + let env_init = class_init table in + init_class table; + (env_init (Obj.repr 0), class_init, env_init, Obj.repr 0) + +type init_table = { mutable env_init: t; mutable class_init: table -> t } + +let make_class_store pub_meths class_init init_table = + let table = create_table pub_meths in + let env_init = class_init table in + init_class table; + init_table.class_init <- class_init; + init_table.env_init <- env_init + +let dummy_class loc = + let undef = fun _ -> raise (Undefined_recursive_module loc) in + (Obj.magic undef, undef, undef, Obj.repr 0) + +(**** Objects ****) + +let create_object table = + (* XXX Appel de [obj_block] *) + let obj = Obj.new_block Obj.object_tag table.size in + (* XXX Appel de [caml_modify] *) + Obj.set_field obj 0 (Obj.repr table.methods); + set_id obj last_id; + (Obj.obj obj) + +let create_object_opt obj_0 table = + if (Obj.magic obj_0 : bool) then obj_0 else begin + (* XXX Appel de [obj_block] *) + let obj = Obj.new_block Obj.object_tag table.size in + (* XXX Appel de [caml_modify] *) + Obj.set_field obj 0 (Obj.repr table.methods); + set_id obj last_id; + (Obj.obj obj) + end + +let rec iter_f obj = + function + [] -> () + | f::l -> f obj; iter_f obj l + +let run_initializers obj table = + let inits = table.initializers in + if inits <> [] then + iter_f obj inits + +let run_initializers_opt obj_0 obj table = + if (Obj.magic obj_0 : bool) then obj else begin + let inits = table.initializers in + if inits <> [] then iter_f obj inits; + obj + end + +let create_object_and_run_initializers obj_0 table = + if (Obj.magic obj_0 : bool) then obj_0 else begin + let obj = create_object table in + run_initializers obj table; + obj + end + +(* Equivalent primitive below +let sendself obj lab = + (magic obj : (obj -> t) array array).(0).(lab) obj +*) +external send : obj -> tag -> 'a = "%send" +external sendcache : obj -> tag -> t -> int -> 'a = "%sendcache" +external sendself : obj -> label -> 'a = "%sendself" +external get_public_method : obj -> tag -> closure + = "caml_get_public_method" "noalloc" + +(**** table collection access ****) + +type tables = Empty | Cons of closure * tables * tables +type mut_tables = + {key: closure; mutable data: tables; mutable next: tables} +external mut : tables -> mut_tables = "%identity" + +let build_path n keys tables = + let res = Cons (Obj.magic 0, Empty, Empty) in + let r = ref res in + for i = 0 to n do + r := Cons (keys.(i), !r, Empty) + done; + tables.data <- !r; + res + +let rec lookup_keys i keys tables = + if i < 0 then tables else + let key = keys.(i) in + let rec lookup_key tables = + if tables.key == key then lookup_keys (i-1) keys tables.data else + if tables.next <> Empty then lookup_key (mut tables.next) else + let next = Cons (key, Empty, Empty) in + tables.next <- next; + build_path (i-1) keys (mut next) + in + lookup_key (mut tables) + +let lookup_tables root keys = + let root = mut root in + if root.data <> Empty then + lookup_keys (Array.length keys - 1) keys root.data + else + build_path (Array.length keys - 1) keys root + +(**** builtin methods ****) + +let get_const x = ret (fun obj -> x) +let get_var n = ret (fun obj -> Array.unsafe_get obj n) +let get_env e n = + ret (fun obj -> + Array.unsafe_get (Obj.magic (Array.unsafe_get obj e) : obj) n) +let get_meth n = ret (fun obj -> sendself obj n) +let set_var n = ret (fun obj x -> Array.unsafe_set obj n x) +let app_const f x = ret (fun obj -> f x) +let app_var f n = ret (fun obj -> f (Array.unsafe_get obj n)) +let app_env f e n = + ret (fun obj -> + f (Array.unsafe_get (Obj.magic (Array.unsafe_get obj e) : obj) n)) +let app_meth f n = ret (fun obj -> f (sendself obj n)) +let app_const_const f x y = ret (fun obj -> f x y) +let app_const_var f x n = ret (fun obj -> f x (Array.unsafe_get obj n)) +let app_const_meth f x n = ret (fun obj -> f x (sendself obj n)) +let app_var_const f n x = ret (fun obj -> f (Array.unsafe_get obj n) x) +let app_meth_const f n x = ret (fun obj -> f (sendself obj n) x) +let app_const_env f x e n = + ret (fun obj -> + f x (Array.unsafe_get (Obj.magic (Array.unsafe_get obj e) : obj) n)) +let app_env_const f e n x = + ret (fun obj -> + f (Array.unsafe_get (Obj.magic (Array.unsafe_get obj e) : obj) n) x) +let meth_app_const n x = ret (fun obj -> (sendself obj n : _ -> _) x) +let meth_app_var n m = + ret (fun obj -> (sendself obj n : _ -> _) (Array.unsafe_get obj m)) +let meth_app_env n e m = + ret (fun obj -> (sendself obj n : _ -> _) + (Array.unsafe_get (Obj.magic (Array.unsafe_get obj e) : obj) m)) +let meth_app_meth n m = + ret (fun obj -> (sendself obj n : _ -> _) (sendself obj m)) +let send_const m x c = + ret (fun obj -> sendcache x m (Array.unsafe_get obj 0) c) +let send_var m n c = + ret (fun obj -> + sendcache (Obj.magic (Array.unsafe_get obj n) : obj) m + (Array.unsafe_get obj 0) c) +let send_env m e n c = + ret (fun obj -> + sendcache + (Obj.magic (Array.unsafe_get + (Obj.magic (Array.unsafe_get obj e) : obj) n) : obj) + m (Array.unsafe_get obj 0) c) +let send_meth m n c = + ret (fun obj -> + sendcache (sendself obj n) m (Array.unsafe_get obj 0) c) +let new_cache table = + let n = new_method table in + let n = + if n mod 2 = 0 || n > 2 + magic table.methods.(1) * 16 / Sys.word_size + then n else new_method table + in + table.methods.(n) <- Obj.magic 0; + n + +type impl = + GetConst + | GetVar + | GetEnv + | GetMeth + | SetVar + | AppConst + | AppVar + | AppEnv + | AppMeth + | AppConstConst + | AppConstVar + | AppConstEnv + | AppConstMeth + | AppVarConst + | AppEnvConst + | AppMethConst + | MethAppConst + | MethAppVar + | MethAppEnv + | MethAppMeth + | SendConst + | SendVar + | SendEnv + | SendMeth + | Closure of closure + +let method_impl table i arr = + let next () = incr i; magic arr.(!i) in + match next() with + GetConst -> let x : t = next() in get_const x + | GetVar -> let n = next() in get_var n + | GetEnv -> let e = next() and n = next() in get_env e n + | GetMeth -> let n = next() in get_meth n + | SetVar -> let n = next() in set_var n + | AppConst -> let f = next() and x = next() in app_const f x + | AppVar -> let f = next() and n = next () in app_var f n + | AppEnv -> + let f = next() and e = next() and n = next() in app_env f e n + | AppMeth -> let f = next() and n = next () in app_meth f n + | AppConstConst -> + let f = next() and x = next() and y = next() in app_const_const f x y + | AppConstVar -> + let f = next() and x = next() and n = next() in app_const_var f x n + | AppConstEnv -> + let f = next() and x = next() and e = next () and n = next() in + app_const_env f x e n + | AppConstMeth -> + let f = next() and x = next() and n = next() in app_const_meth f x n + | AppVarConst -> + let f = next() and n = next() and x = next() in app_var_const f n x + | AppEnvConst -> + let f = next() and e = next () and n = next() and x = next() in + app_env_const f e n x + | AppMethConst -> + let f = next() and n = next() and x = next() in app_meth_const f n x + | MethAppConst -> + let n = next() and x = next() in meth_app_const n x + | MethAppVar -> + let n = next() and m = next() in meth_app_var n m + | MethAppEnv -> + let n = next() and e = next() and m = next() in meth_app_env n e m + | MethAppMeth -> + let n = next() and m = next() in meth_app_meth n m + | SendConst -> + let m = next() and x = next() in send_const m x (new_cache table) + | SendVar -> + let m = next() and n = next () in send_var m n (new_cache table) + | SendEnv -> + let m = next() and e = next() and n = next() in + send_env m e n (new_cache table) + | SendMeth -> + let m = next() and n = next () in send_meth m n (new_cache table) + | Closure _ as clo -> magic clo + +let set_methods table methods = + let len = Array.length methods and i = ref 0 in + while !i < len do + let label = methods.(!i) and clo = method_impl table i methods in + set_method table label clo; + incr i + done + +(**** Statistics ****) + +type stats = + { classes: int; methods: int; inst_vars: int; } + +let stats () = + { classes = !table_count; + methods = !method_count; inst_vars = !inst_var_count; } diff --git a/stdlib/camlinternalOO.mli b/stdlib/camlinternalOO.mli new file mode 100644 index 0000000..d42aaba --- /dev/null +++ b/stdlib/camlinternalOO.mli @@ -0,0 +1,153 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: camlinternalOO.mli,v 1.10 2006-04-05 02:28:13 garrigue Exp $ *) + +(** Run-time support for objects and classes. + All functions in this module are for system use only, not for the + casual user. *) + +(** {6 Classes} *) + +type tag +type label +type table +type meth +type t +type obj +type closure +val public_method_label : string -> tag +val new_method : table -> label +val new_variable : table -> string -> int +val new_methods_variables : + table -> string array -> string array -> label array +val get_variable : table -> string -> int +val get_variables : table -> string array -> int array +val get_method_label : table -> string -> label +val get_method_labels : table -> string array -> label array +val get_method : table -> label -> meth +val set_method : table -> label -> meth -> unit +val set_methods : table -> label array -> unit +val narrow : table -> string array -> string array -> string array -> unit +val widen : table -> unit +val add_initializer : table -> (obj -> unit) -> unit +val dummy_table : table +val create_table : string array -> table +val init_class : table -> unit +val inherits : + table -> string array -> string array -> string array -> + (t * (table -> obj -> Obj.t) * t * obj) -> bool -> Obj.t array +val make_class : + string array -> (table -> Obj.t -> t) -> + (t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t) +type init_table +val make_class_store : + string array -> (table -> t) -> init_table -> unit +val dummy_class : + string * int * int -> + (t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t) + +(** {6 Objects} *) + +val copy : (< .. > as 'a) -> 'a +val create_object : table -> obj +val create_object_opt : obj -> table -> obj +val run_initializers : obj -> table -> unit +val run_initializers_opt : obj -> obj -> table -> obj +val create_object_and_run_initializers : obj -> table -> obj +external send : obj -> tag -> t = "%send" +external sendcache : obj -> tag -> t -> int -> t = "%sendcache" +external sendself : obj -> label -> t = "%sendself" +external get_public_method : obj -> tag -> closure + = "caml_get_public_method" "noalloc" + +(** {6 Table cache} *) + +type tables +val lookup_tables : tables -> closure array -> tables + +(** {6 Builtins to reduce code size} *) + +(* +val get_const : t -> closure +val get_var : int -> closure +val get_env : int -> int -> closure +val get_meth : label -> closure +val set_var : int -> closure +val app_const : (t -> t) -> t -> closure +val app_var : (t -> t) -> int -> closure +val app_env : (t -> t) -> int -> int -> closure +val app_meth : (t -> t) -> label -> closure +val app_const_const : (t -> t -> t) -> t -> t -> closure +val app_const_var : (t -> t -> t) -> t -> int -> closure +val app_const_env : (t -> t -> t) -> t -> int -> int -> closure +val app_const_meth : (t -> t -> t) -> t -> label -> closure +val app_var_const : (t -> t -> t) -> int -> t -> closure +val app_env_const : (t -> t -> t) -> int -> int -> t -> closure +val app_meth_const : (t -> t -> t) -> label -> t -> closure +val meth_app_const : label -> t -> closure +val meth_app_var : label -> int -> closure +val meth_app_env : label -> int -> int -> closure +val meth_app_meth : label -> label -> closure +val send_const : tag -> obj -> int -> closure +val send_var : tag -> int -> int -> closure +val send_env : tag -> int -> int -> int -> closure +val send_meth : tag -> label -> int -> closure +*) + +type impl = + GetConst + | GetVar + | GetEnv + | GetMeth + | SetVar + | AppConst + | AppVar + | AppEnv + | AppMeth + | AppConstConst + | AppConstVar + | AppConstEnv + | AppConstMeth + | AppVarConst + | AppEnvConst + | AppMethConst + | MethAppConst + | MethAppVar + | MethAppEnv + | MethAppMeth + | SendConst + | SendVar + | SendEnv + | SendMeth + | Closure of closure + +(** {6 Parameters} *) + +(* currently disabled *) +type params = + { mutable compact_table : bool; + mutable copy_parent : bool; + mutable clean_when_copying : bool; + mutable retry_count : int; + mutable bucket_small_size : int } + +val params : params + +(** {6 Statistics} *) + +type stats = + { classes : int; + methods : int; + inst_vars : int } +val stats : unit -> stats diff --git a/stdlib/char.ml b/stdlib/char.ml new file mode 100644 index 0000000..489fe2a --- /dev/null +++ b/stdlib/char.ml @@ -0,0 +1,69 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: char.ml,v 1.14 2007-04-16 11:06:51 weis Exp $ *) + +(* Character operations *) + +external code: char -> int = "%identity" +external unsafe_chr: int -> char = "%identity" + +let chr n = + if n < 0 || n > 255 then invalid_arg "Char.chr" else unsafe_chr n + +external is_printable: char -> bool = "caml_is_printable" + +external string_create: int -> string = "caml_create_string" +external string_unsafe_get : string -> int -> char = "%string_unsafe_get" +external string_unsafe_set : string -> int -> char -> unit + = "%string_unsafe_set" + +let escaped = function + | '\'' -> "\\'" + | '\\' -> "\\\\" + | '\n' -> "\\n" + | '\t' -> "\\t" + | '\r' -> "\\r" + | '\b' -> "\\b" + | c -> + if is_printable c then begin + let s = string_create 1 in + string_unsafe_set s 0 c; + s + end else begin + let n = code c in + let s = string_create 4 in + string_unsafe_set s 0 '\\'; + string_unsafe_set s 1 (unsafe_chr (48 + n / 100)); + string_unsafe_set s 2 (unsafe_chr (48 + (n / 10) mod 10)); + string_unsafe_set s 3 (unsafe_chr (48 + n mod 10)); + s + end + +let lowercase c = + if (c >= 'A' && c <= 'Z') + || (c >= '\192' && c <= '\214') + || (c >= '\216' && c <= '\222') + then unsafe_chr(code c + 32) + else c + +let uppercase c = + if (c >= 'a' && c <= 'z') + || (c >= '\224' && c <= '\246') + || (c >= '\248' && c <= '\254') + then unsafe_chr(code c - 32) + else c + +type t = char + +let compare c1 c2 = code c1 - code c2 diff --git a/stdlib/char.mli b/stdlib/char.mli new file mode 100644 index 0000000..2835456 --- /dev/null +++ b/stdlib/char.mli @@ -0,0 +1,48 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: char.mli,v 1.17 2005-10-25 18:34:07 doligez Exp $ *) + +(** Character operations. *) + +external code : char -> int = "%identity" +(** Return the ASCII code of the argument. *) + +val chr : int -> char +(** Return the character with the given ASCII code. + Raise [Invalid_argument "Char.chr"] if the argument is + outside the range 0--255. *) + +val escaped : char -> string +(** Return a string representing the given character, + with special characters escaped following the lexical conventions + of Objective Caml. *) + +val lowercase : char -> char +(** Convert the given character to its equivalent lowercase character. *) + +val uppercase : char -> char +(** Convert the given character to its equivalent uppercase character. *) + +type t = char +(** An alias for the type of characters. *) + +val compare: t -> t -> int +(** The comparison function for characters, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [Char] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +external unsafe_chr : int -> char = "%identity" diff --git a/stdlib/complex.ml b/stdlib/complex.ml new file mode 100644 index 0000000..268971f --- /dev/null +++ b/stdlib/complex.ml @@ -0,0 +1,87 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: complex.ml,v 1.6 2005-10-25 18:34:07 doligez Exp $ *) + +(* Complex numbers *) + +type t = { re: float; im: float } + +let zero = { re = 0.0; im = 0.0 } +let one = { re = 1.0; im = 0.0 } +let i = { re = 0.0; im = 1.0 } + +let add x y = { re = x.re +. y.re; im = x.im +. y.im } + +let sub x y = { re = x.re -. y.re; im = x.im -. y.im } + +let neg x = { re = -. x.re; im = -. x.im } + +let conj x = { re = x.re; im = -. x.im } + +let mul x y = { re = x.re *. y.re -. x.im *. y.im; + im = x.re *. y.im +. x.im *. y.re } + +let div x y = + if abs_float y.re >= abs_float y.im then + let r = y.im /. y.re in + let d = y.re +. r *. y.im in + { re = (x.re +. r *. x.im) /. d; + im = (x.im -. r *. x.re) /. d } + else + let r = y.re /. y.im in + let d = y.im +. r *. y.re in + { re = (r *. x.re +. x.im) /. d; + im = (r *. x.im -. x.re) /. d } + +let inv x = div one x + +let norm2 x = x.re *. x.re +. x.im *. x.im + +let norm x = + (* Watch out for overflow in computing re^2 + im^2 *) + let r = abs_float x.re and i = abs_float x.im in + if r = 0.0 then i + else if i = 0.0 then r + else if r >= i then + let q = i /. r in r *. sqrt(1.0 +. q *. q) + else + let q = r /. i in i *. sqrt(1.0 +. q *. q) + +let arg x = atan2 x.im x.re + +let polar n a = { re = cos a *. n; im = sin a *. n } + +let sqrt x = + if x.re = 0.0 && x.im = 0.0 then { re = 0.0; im = 0.0 } + else begin + let r = abs_float x.re and i = abs_float x.im in + let w = + if r >= i then begin + let q = i /. r in + sqrt(r) *. sqrt(0.5 *. (1.0 +. sqrt(1.0 +. q *. q))) + end else begin + let q = r /. i in + sqrt(i) *. sqrt(0.5 *. (q +. sqrt(1.0 +. q *. q))) + end in + if x.re >= 0.0 + then { re = w; im = 0.5 *. x.im /. w } + else { re = 0.5 *. i /. w; im = if x.im >= 0.0 then w else -. w } + end + +let exp x = + let e = exp x.re in { re = e *. cos x.im; im = e *. sin x.im } + +let log x = { re = log (norm x); im = atan2 x.im x.re } + +let pow x y = exp (mul y (log x)) diff --git a/stdlib/complex.mli b/stdlib/complex.mli new file mode 100644 index 0000000..100a80d --- /dev/null +++ b/stdlib/complex.mli @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: complex.mli,v 1.4 2005-10-25 18:34:07 doligez Exp $ *) + +(** Complex numbers. + + This module provides arithmetic operations on complex numbers. + Complex numbers are represented by their real and imaginary parts + (cartesian representation). Each part is represented by a + double-precision floating-point number (type [float]). *) + +type t = { re: float; im: float } +(** The type of complex numbers. [re] is the real part and [im] the + imaginary part. *) + +val zero: t +(** The complex number [0]. *) + +val one: t +(** The complex number [1]. *) + +val i: t +(** The complex number [i]. *) + +val neg: t -> t +(** Unary negation. *) + +val conj: t -> t +(** Conjugate: given the complex [x + i.y], returns [x - i.y]. *) + +val add: t -> t -> t +(** Addition *) + +val sub: t -> t -> t +(** Subtraction *) + +val mul: t -> t -> t +(** Multiplication *) + +val inv: t -> t +(** Multiplicative inverse ([1/z]). *) + +val div: t -> t -> t +(** Division *) + +val sqrt: t -> t +(** Square root. The result [x + i.y] is such that [x > 0] or + [x = 0] and [y >= 0]. + This function has a discontinuity along the negative real axis. *) + +val norm2: t -> float +(** Norm squared: given [x + i.y], returns [x^2 + y^2]. *) + +val norm: t -> float +(** Norm: given [x + i.y], returns [sqrt(x^2 + y^2)]. *) + +val arg: t -> float +(** Argument. The argument of a complex number is the angle + in the complex plane between the positive real axis and a line + passing through zero and the number. This angle ranges from + [-pi] to [pi]. This function has a discontinuity along the + negative real axis. *) + +val polar: float -> float -> t +(** [polar norm arg] returns the complex having norm [norm] + and argument [arg]. *) + +val exp: t -> t +(** Exponentiation. [exp z] returns [e] to the [z] power. *) + +val log: t -> t +(** Natural logarithm (in base [e]). *) + +val pow: t -> t -> t +(** Power function. [pow z1 z2] returns [z1] to the [z2] power. *) diff --git a/stdlib/digest.ml b/stdlib/digest.ml new file mode 100644 index 0000000..5e2d132 --- /dev/null +++ b/stdlib/digest.ml @@ -0,0 +1,51 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: digest.ml,v 1.10 2003-12-31 14:20:39 doligez Exp $ *) + +(* Message digest (MD5) *) + +type t = string + +external unsafe_string: string -> int -> int -> t = "caml_md5_string" +external channel: in_channel -> int -> t = "caml_md5_chan" + +let string str = + unsafe_string str 0 (String.length str) + +let substring str ofs len = + if ofs < 0 || len < 0 || ofs > String.length str - len + then invalid_arg "Digest.substring" + else unsafe_string str ofs len + +let file filename = + let ic = open_in_bin filename in + let d = channel ic (-1) in + close_in ic; + d + +let output chan digest = + output chan digest 0 16 + +let input chan = + let digest = String.create 16 in + really_input chan digest 0 16; + digest + +let to_hex d = + let result = String.create 32 in + for i = 0 to 15 do + String.blit (Printf.sprintf "%02x" (int_of_char d.[i])) 0 result (2*i) 2; + done; + result +;; diff --git a/stdlib/digest.mli b/stdlib/digest.mli new file mode 100644 index 0000000..d5c1e6f --- /dev/null +++ b/stdlib/digest.mli @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: digest.mli,v 1.17 2005-10-25 18:34:07 doligez Exp $ *) + +(** MD5 message digest. + + This module provides functions to compute 128-bit ``digests'' of + arbitrary-length strings or files. The digests are of cryptographic + quality: it is very hard, given a digest, to forge a string having + that digest. The algorithm used is MD5. +*) + +type t = string +(** The type of digests: 16-character strings. *) + +val string : string -> t +(** Return the digest of the given string. *) + +val substring : string -> int -> int -> t +(** [Digest.substring s ofs len] returns the digest of the substring + of [s] starting at character number [ofs] and containing [len] + characters. *) + +external channel : in_channel -> int -> t = "caml_md5_chan" +(** If [len] is nonnegative, [Digest.channel ic len] reads [len] + characters from channel [ic] and returns their digest, or raises + [End_of_file] if end-of-file is reached before [len] characters + are read. If [len] is negative, [Digest.channel ic len] reads + all characters from [ic] until end-of-file is reached and return + their digest. *) + +val file : string -> t +(** Return the digest of the file whose name is given. *) + +val output : out_channel -> t -> unit +(** Write a digest on the given output channel. *) + +val input : in_channel -> t +(** Read a digest from the given input channel. *) + +val to_hex : t -> string +(** Return the printable hexadecimal representation of the given digest. *) diff --git a/stdlib/filename.ml b/stdlib/filename.ml new file mode 100644 index 0000000..409ef4e --- /dev/null +++ b/stdlib/filename.ml @@ -0,0 +1,220 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: filename.ml,v 1.42 2008-12-03 18:09:09 doligez Exp $ *) + +let generic_quote quotequote s = + let l = String.length s in + let b = Buffer.create (l + 20) in + Buffer.add_char b '\''; + for i = 0 to l - 1 do + if s.[i] = '\'' + then Buffer.add_string b quotequote + else Buffer.add_char b s.[i] + done; + Buffer.add_char b '\''; + Buffer.contents b + +let generic_basename rindex_dir_sep current_dir_name name = + let raw_name = + try + let p = rindex_dir_sep name + 1 in + String.sub name p (String.length name - p) + with Not_found -> + name + in + if raw_name = "" then current_dir_name else raw_name + +let generic_dirname rindex_dir_sep current_dir_name dir_sep name = + try + match rindex_dir_sep name with + 0 -> dir_sep + | n -> String.sub name 0 n + with Not_found -> + current_dir_name + +module Unix = struct + let current_dir_name = "." + let parent_dir_name = ".." + let dir_sep = "/" + let is_dir_sep s i = s.[i] = '/' + let rindex_dir_sep s = String.rindex s '/' + let is_relative n = String.length n < 1 || n.[0] <> '/';; + let is_implicit n = + is_relative n + && (String.length n < 2 || String.sub n 0 2 <> "./") + && (String.length n < 3 || String.sub n 0 3 <> "../") + let check_suffix name suff = + String.length name >= String.length suff && + String.sub name (String.length name - String.length suff) + (String.length suff) = suff + let temp_dir_name = + try Sys.getenv "TMPDIR" with Not_found -> "/tmp" + let quote = generic_quote "'\\''" + let basename = generic_basename rindex_dir_sep current_dir_name + let dirname = generic_dirname rindex_dir_sep current_dir_name dir_sep +end + +module Win32 = struct + let current_dir_name = "." + let parent_dir_name = ".." + let dir_sep = "\\" + let is_dir_sep s i = let c = s.[i] in c = '/' || c = '\\' || c = ':' + let rindex_dir_sep s = + let rec pos i = + if i < 0 then raise Not_found + else if is_dir_sep s i then i + else pos (i - 1) + in pos (String.length s - 1) + let is_relative n = + (String.length n < 1 || n.[0] <> '/') + && (String.length n < 1 || n.[0] <> '\\') + && (String.length n < 2 || n.[1] <> ':') + let is_implicit n = + is_relative n + && (String.length n < 2 || String.sub n 0 2 <> "./") + && (String.length n < 2 || String.sub n 0 2 <> ".\\") + && (String.length n < 3 || String.sub n 0 3 <> "../") + && (String.length n < 3 || String.sub n 0 3 <> "..\\") + let check_suffix name suff = + String.length name >= String.length suff && + (let s = String.sub name (String.length name - String.length suff) + (String.length suff) in + String.lowercase s = String.lowercase suff) + let temp_dir_name = + try Sys.getenv "TEMP" with Not_found -> "." + let quote s = + let l = String.length s in + let b = Buffer.create (l + 20) in + Buffer.add_char b '\"'; + let rec loop i = + if i = l then Buffer.add_char b '\"' else + match s.[i] with + | '\"' -> loop_bs 0 i; + | '\\' -> loop_bs 0 i; + | c -> Buffer.add_char b c; loop (i+1); + and loop_bs n i = + if i = l then begin + Buffer.add_char b '\"'; + add_bs n; + end else begin + match s.[i] with + | '\"' -> add_bs (2*n+1); Buffer.add_char b '\"'; loop (i+1); + | '\\' -> loop_bs (n+1) (i+1); + | c -> add_bs n; loop i + end + and add_bs n = for j = 1 to n do Buffer.add_char b '\\'; done + in + loop 0; + Buffer.contents b + let has_drive s = + let is_letter = function + | 'A' .. 'Z' | 'a' .. 'z' -> true + | _ -> false + in + String.length s >= 2 && is_letter s.[0] && s.[1] = ':' + let drive_and_path s = + if has_drive s + then (String.sub s 0 2, String.sub s 2 (String.length s - 2)) + else ("", s) + let dirname s = + let (drive, path) = drive_and_path s in + let dir = generic_dirname rindex_dir_sep current_dir_name dir_sep path in + drive ^ dir + let basename s = + let (drive, path) = drive_and_path s in + generic_basename rindex_dir_sep current_dir_name path +end + +module Cygwin = struct + let current_dir_name = "." + let parent_dir_name = ".." + let dir_sep = "/" + let is_dir_sep = Win32.is_dir_sep + let rindex_dir_sep = Win32.rindex_dir_sep + let is_relative = Win32.is_relative + let is_implicit = Win32.is_implicit + let check_suffix = Win32.check_suffix + let temp_dir_name = Unix.temp_dir_name + let quote = Unix.quote + let basename = generic_basename rindex_dir_sep current_dir_name + let dirname = generic_dirname rindex_dir_sep current_dir_name dir_sep +end + +let (current_dir_name, parent_dir_name, dir_sep, is_dir_sep, rindex_dir_sep, + is_relative, is_implicit, check_suffix, temp_dir_name, quote, basename, + dirname) = + match Sys.os_type with + "Unix" -> + (Unix.current_dir_name, Unix.parent_dir_name, Unix.dir_sep, + Unix.is_dir_sep, Unix.rindex_dir_sep, + Unix.is_relative, Unix.is_implicit, Unix.check_suffix, + Unix.temp_dir_name, Unix.quote, Unix.basename, Unix.dirname) + | "Win32" -> + (Win32.current_dir_name, Win32.parent_dir_name, Win32.dir_sep, + Win32.is_dir_sep, Win32.rindex_dir_sep, + Win32.is_relative, Win32.is_implicit, Win32.check_suffix, + Win32.temp_dir_name, Win32.quote, Win32.basename, Win32.dirname) + | "Cygwin" -> + (Cygwin.current_dir_name, Cygwin.parent_dir_name, Cygwin.dir_sep, + Cygwin.is_dir_sep, Cygwin.rindex_dir_sep, + Cygwin.is_relative, Cygwin.is_implicit, Cygwin.check_suffix, + Cygwin.temp_dir_name, Cygwin.quote, Cygwin.basename, Cygwin.dirname) + | _ -> assert false + +let concat dirname filename = + let l = String.length dirname in + if l = 0 || is_dir_sep dirname (l-1) + then dirname ^ filename + else dirname ^ dir_sep ^ filename + +let chop_suffix name suff = + let n = String.length name - String.length suff in + if n < 0 then invalid_arg "Filename.chop_suffix" else String.sub name 0 n + +let chop_extension name = + let rec search_dot i = + if i < 0 || is_dir_sep name i then invalid_arg "Filename.chop_extension" + else if name.[i] = '.' then String.sub name 0 i + else search_dot (i - 1) in + search_dot (String.length name - 1) + +external open_desc: string -> open_flag list -> int -> int = "caml_sys_open" +external close_desc: int -> unit = "caml_sys_close" + +let prng = Random.State.make_self_init ();; + +let temp_file_name prefix suffix = + let rnd = (Random.State.bits prng) land 0xFFFFFF in + concat temp_dir_name (Printf.sprintf "%s%06x%s" prefix rnd suffix) +;; + +let temp_file prefix suffix = + let rec try_name counter = + let name = temp_file_name prefix suffix in + try + close_desc(open_desc name [Open_wronly; Open_creat; Open_excl] 0o600); + name + with Sys_error _ as e -> + if counter >= 1000 then raise e else try_name (counter + 1) + in try_name 0 + +let open_temp_file ?(mode = [Open_text]) prefix suffix = + let rec try_name counter = + let name = temp_file_name prefix suffix in + try + (name, + open_out_gen (Open_wronly::Open_creat::Open_excl::mode) 0o600 name) + with Sys_error _ as e -> + if counter >= 1000 then raise e else try_name (counter + 1) + in try_name 0 diff --git a/stdlib/filename.mli b/stdlib/filename.mli new file mode 100644 index 0000000..709ede7 --- /dev/null +++ b/stdlib/filename.mli @@ -0,0 +1,107 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: filename.mli,v 1.35 2007-01-09 13:42:17 doligez Exp $ *) + +(** Operations on file names. *) + +val current_dir_name : string +(** The conventional name for the current directory (e.g. [.] in Unix). *) + +val parent_dir_name : string +(** The conventional name for the parent of the current directory + (e.g. [..] in Unix). *) + +val concat : string -> string -> string +(** [concat dir file] returns a file name that designates file + [file] in directory [dir]. *) + +val is_relative : string -> bool +(** Return [true] if the file name is relative to the current + directory, [false] if it is absolute (i.e. in Unix, starts + with [/]). *) + +val is_implicit : string -> bool +(** Return [true] if the file name is relative and does not start + with an explicit reference to the current directory ([./] or + [../] in Unix), [false] if it starts with an explicit reference + to the root directory or the current directory. *) + +val check_suffix : string -> string -> bool +(** [check_suffix name suff] returns [true] if the filename [name] + ends with the suffix [suff]. *) + +val chop_suffix : string -> string -> string +(** [chop_suffix name suff] removes the suffix [suff] from + the filename [name]. The behavior is undefined if [name] does not + end with the suffix [suff]. *) + +val chop_extension : string -> string +(** Return the given file name without its extension. The extension + is the shortest suffix starting with a period and not including + a directory separator, [.xyz] for instance. + + Raise [Invalid_argument] if the given name does not contain + an extension. *) + +val basename : string -> string +(** Split a file name into directory name / base file name. + [concat (dirname name) (basename name)] returns a file name + which is equivalent to [name]. Moreover, after setting the + current directory to [dirname name] (with {!Sys.chdir}), + references to [basename name] (which is a relative file name) + designate the same file as [name] before the call to {!Sys.chdir}. + + The result is not specified if the argument is not a valid file name + (for example, under Unix if there is a NUL character in the string). *) + +val dirname : string -> string +(** See {!Filename.basename}. *) + +val temp_file : string -> string -> string +(** [temp_file prefix suffix] returns the name of a + fresh temporary file in the temporary directory. + The base name of the temporary file is formed by concatenating + [prefix], then a suitably chosen integer number, then [suffix]. + The temporary file is created empty, with permissions [0o600] + (readable and writable only by the file owner). The file is + guaranteed to be different from any other file that existed when + [temp_file] was called. +*) + +val open_temp_file : + ?mode: open_flag list -> string -> string -> string * out_channel +(** Same as {!Filename.temp_file}, but returns both the name of a fresh + temporary file, and an output channel opened (atomically) on + this file. This function is more secure than [temp_file]: there + is no risk that the temporary file will be modified (e.g. replaced + by a symbolic link) before the program opens it. The optional argument + [mode] is a list of additional flags to control the opening of the file. + It can contain one or several of [Open_append], [Open_binary], + and [Open_text]. The default is [[Open_text]] (open in text mode). *) + +val temp_dir_name : string +(** The name of the temporary directory: + Under Unix, the value of the [TMPDIR] environment variable, or "/tmp" + if the variable is not set. + Under Windows, the value of the [TEMP] environment variable, or "." + if the variable is not set. +*) + +val quote : string -> string +(** Return a quoted version of a file name, suitable for use as + one argument in a command line, escaping all meta-characters. + Warning: under Windows, the output is only suitable for use + with programs that follow the standard Windows quoting + conventions. + *) diff --git a/stdlib/format.ml b/stdlib/format.ml new file mode 100644 index 0000000..c02cd88 --- /dev/null +++ b/stdlib/format.ml @@ -0,0 +1,1328 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: format.ml,v 1.75 2008-11-08 14:58:40 weis Exp $ *) + +(* A pretty-printing facility and definition of formatters for ``parallel'' + (i.e. unrelated or independent) pretty-printing on multiple out channels. *) + +(************************************************************** + + Data structures definitions. + + **************************************************************) + +type size;; + +external size_of_int : int -> size = "%identity" +;; +external int_of_size : size -> int = "%identity" +;; + +(* Tokens are one of the following : *) + +type pp_token = +| Pp_text of string (* normal text *) +| Pp_break of int * int (* complete break *) +| Pp_tbreak of int * int (* go to next tabulation *) +| Pp_stab (* set a tabulation *) +| Pp_begin of int * block_type (* beginning of a block *) +| Pp_end (* end of a block *) +| Pp_tbegin of tblock (* beginning of a tabulation block *) +| Pp_tend (* end of a tabulation block *) +| Pp_newline (* to force a newline inside a block *) +| Pp_if_newline (* to do something only if this very + line has been broken *) +| Pp_open_tag of string (* opening a tag name *) +| Pp_close_tag (* closing the most recently opened tag *) + +and tag = string + +and block_type = +| Pp_hbox (* Horizontal block no line breaking *) +| Pp_vbox (* Vertical block each break leads to a new line *) +| Pp_hvbox (* Horizontal-vertical block: same as vbox, except if this block + is small enough to fit on a single line *) +| Pp_hovbox (* Horizontal or Vertical block: breaks lead to new line + only when necessary to print the content of the block *) +| Pp_box (* Horizontal or Indent block: breaks lead to new line + only when necessary to print the content of the block, or + when it leads to a new indentation of the current line *) +| Pp_fits (* Internal usage: when a block fits on a single line *) + +and tblock = Pp_tbox of int list ref (* Tabulation box *) +;; + +(* The Queue: + contains all formatting elements. + elements are tuples (size, token, length), where + size is set when the size of the block is known + len is the declared length of the token. *) +type pp_queue_elem = { + mutable elem_size : size; + token : pp_token; + length : int; +} +;; + +(* Scan stack: + each element is (left_total, queue element) where left_total + is the value of pp_left_total when the element has been enqueued. *) +type pp_scan_elem = Scan_elem of int * pp_queue_elem;; + +(* Formatting stack: + used to break the lines while printing tokens. + The formatting stack contains the description of + the currently active blocks. *) +type pp_format_elem = Format_elem of block_type * int;; + +(* General purpose queues, used in the formatter. *) +type 'a queue_elem = + | Nil + | Cons of 'a queue_cell + +and 'a queue_cell = { + mutable head : 'a; + mutable tail : 'a queue_elem; +} +;; + +type 'a queue = { + mutable insert : 'a queue_elem; + mutable body : 'a queue_elem; +} +;; + +(* The formatter specific tag handling functions. *) +type formatter_tag_functions = { + mark_open_tag : tag -> string; + mark_close_tag : tag -> string; + print_open_tag : tag -> unit; + print_close_tag : tag -> unit; +} +;; + +(* A formatter with all its machinery. *) +type formatter = { + mutable pp_scan_stack : pp_scan_elem list; + mutable pp_format_stack : pp_format_elem list; + mutable pp_tbox_stack : tblock list; + mutable pp_tag_stack : tag list; + mutable pp_mark_stack : tag list; + (* Global variables: default initialization is + set_margin 78 + set_min_space_left 0. *) + (* Value of right margin. *) + mutable pp_margin : int; + (* Minimal space left before margin, when opening a block. *) + mutable pp_min_space_left : int; + (* Maximum value of indentation: + no blocks can be opened further. *) + mutable pp_max_indent : int; + (* Space remaining on the current line. *) + mutable pp_space_left : int; + (* Current value of indentation. *) + mutable pp_current_indent : int; + (* True when the line has been broken by the pretty-printer. *) + mutable pp_is_new_line : bool; + (* Total width of tokens already printed. *) + mutable pp_left_total : int; + (* Total width of tokens ever put in queue. *) + mutable pp_right_total : int; + (* Current number of opened blocks. *) + mutable pp_curr_depth : int; + (* Maximum number of blocks which can be simultaneously opened. *) + mutable pp_max_boxes : int; + (* Ellipsis string. *) + mutable pp_ellipsis : string; + (* Output function. *) + mutable pp_output_function : string -> int -> int -> unit; + (* Flushing function. *) + mutable pp_flush_function : unit -> unit; + (* Output of new lines. *) + mutable pp_output_newline : unit -> unit; + (* Output of indentation spaces. *) + mutable pp_output_spaces : int -> unit; + (* Are tags printed ? *) + mutable pp_print_tags : bool; + (* Are tags marked ? *) + mutable pp_mark_tags : bool; + (* Find opening and closing markers of tags. *) + mutable pp_mark_open_tag : tag -> string; + mutable pp_mark_close_tag : tag -> string; + mutable pp_print_open_tag : tag -> unit; + mutable pp_print_close_tag : tag -> unit; + (* The pretty-printer queue. *) + mutable pp_queue : pp_queue_elem queue; +} +;; + +(************************************************************** + + Auxilliaries and basic functions. + + **************************************************************) + + +(* Queues auxilliaries. *) +let make_queue () = { insert = Nil; body = Nil; };; + +let clear_queue q = q.insert <- Nil; q.body <- Nil;; + +let add_queue x q = + let c = Cons { head = x; tail = Nil; } in + match q with + | { insert = Cons cell } -> + q.insert <- c; cell.tail <- c + (* Invariant: when insert is Nil body should be Nil. *) + | _ -> q.insert <- c; q.body <- c;; + +exception Empty_queue;; + +let peek_queue = function + | { body = Cons { head = x; }; } -> x + | _ -> raise Empty_queue +;; + +let take_queue = function + | { body = Cons { head = x; tail = tl; }; } as q -> + q.body <- tl; + if tl = Nil then q.insert <- Nil; (* Maintain the invariant. *) + x + | _ -> raise Empty_queue +;; + +(* Enter a token in the pretty-printer queue. *) +let pp_enqueue state ({length = len} as token) = + state.pp_right_total <- state.pp_right_total + len; + add_queue token state.pp_queue +;; + +let pp_clear_queue state = + state.pp_left_total <- 1; state.pp_right_total <- 1; + clear_queue state.pp_queue +;; + +(* Pp_infinity: large value for default tokens size. + + Pp_infinity is documented as being greater than 1e10; to avoid + confusion about the word ``greater'', we choose pp_infinity greater + than 1e10 + 1; for correct handling of tests in the algorithm, + pp_infinity must be even one more than 1e10 + 1; let's stand on the + safe side by choosing 1.e10+10. + + Pp_infinity could probably be 1073741823 that is 2^30 - 1, that is + the minimal upper bound for integers; now that max_int is defined, + this limit could also be defined as max_int - 1. + + However, before setting pp_infinity to something around max_int, we + must carefully double-check all the integer arithmetic operations + that involve pp_infinity, since any overflow would wreck havoc the + pretty-printing algorithm's invariants. Given that this arithmetic + correctness check is difficult and error prone and given that 1e10 + + 1 is in practice large enough, there is no need to attempt to set + pp_infinity to the theoretically maximum limit. It is not worth the + burden ! *) + +let pp_infinity = 1000000010;; + +(* Output functions for the formatter. *) +let pp_output_string state s = state.pp_output_function s 0 (String.length s) +and pp_output_newline state = state.pp_output_newline () +and pp_display_blanks state n = state.pp_output_spaces n +;; + +(* To format a break, indenting a new line. *) +let break_new_line state offset width = + pp_output_newline state; + state.pp_is_new_line <- true; + let indent = state.pp_margin - width + offset in + (* Don't indent more than pp_max_indent. *) + let real_indent = min state.pp_max_indent indent in + state.pp_current_indent <- real_indent; + state.pp_space_left <- state.pp_margin - state.pp_current_indent; + pp_display_blanks state state.pp_current_indent +;; + +(* To force a line break inside a block: no offset is added. *) +let break_line state width = break_new_line state 0 width;; + +(* To format a break that fits on the current line. *) +let break_same_line state width = + state.pp_space_left <- state.pp_space_left - width; + pp_display_blanks state width +;; + +(* To indent no more than pp_max_indent, if one tries to open a block + beyond pp_max_indent, then the block is rejected on the left + by simulating a break. *) +let pp_force_break_line state = + match state.pp_format_stack with + | Format_elem (bl_ty, width) :: _ -> + if width > state.pp_space_left then + (match bl_ty with + | Pp_fits -> () | Pp_hbox -> () + | _ -> break_line state width) + | _ -> pp_output_newline state +;; + +(* To skip a token, if the previous line has been broken. *) +let pp_skip_token state = + (* When calling pp_skip_token the queue cannot be empty. *) + match take_queue state.pp_queue with + | { elem_size = size; length = len; } -> + state.pp_left_total <- state.pp_left_total - len; + state.pp_space_left <- state.pp_space_left + int_of_size size +;; + +(************************************************************** + + The main pretty printing functions. + + **************************************************************) + +(* To format a token. *) +let format_pp_token state size = function + + | Pp_text s -> + state.pp_space_left <- state.pp_space_left - size; + pp_output_string state s; + state.pp_is_new_line <- false + + | Pp_begin (off, ty) -> + let insertion_point = state.pp_margin - state.pp_space_left in + if insertion_point > state.pp_max_indent then + (* can't open a block right there. *) + begin pp_force_break_line state end; + let offset = state.pp_space_left - off in + let bl_type = + begin match ty with + | Pp_vbox -> Pp_vbox + | _ -> if size > state.pp_space_left then ty else Pp_fits + end in + state.pp_format_stack <- + Format_elem (bl_type, offset) :: state.pp_format_stack + + | Pp_end -> + begin match state.pp_format_stack with + | x :: (y :: l as ls) -> state.pp_format_stack <- ls + | _ -> () (* No more block to close. *) + end + + | Pp_tbegin (Pp_tbox _ as tbox) -> + state.pp_tbox_stack <- tbox :: state.pp_tbox_stack + + | Pp_tend -> + begin match state.pp_tbox_stack with + | x :: ls -> state.pp_tbox_stack <- ls + | _ -> () (* No more tabulation block to close. *) + end + + | Pp_stab -> + begin match state.pp_tbox_stack with + | Pp_tbox tabs :: _ -> + let rec add_tab n = function + | [] -> [n] + | x :: l as ls -> if n < x then n :: ls else x :: add_tab n l in + tabs := add_tab (state.pp_margin - state.pp_space_left) !tabs + | _ -> () (* No opened tabulation block. *) + end + + | Pp_tbreak (n, off) -> + let insertion_point = state.pp_margin - state.pp_space_left in + begin match state.pp_tbox_stack with + | Pp_tbox tabs :: _ -> + let rec find n = function + | x :: l -> if x >= n then x else find n l + | [] -> raise Not_found in + let tab = + match !tabs with + | x :: l -> + begin + try find insertion_point !tabs with + | Not_found -> x + end + | _ -> insertion_point in + let offset = tab - insertion_point in + if offset >= 0 + then break_same_line state (offset + n) + else break_new_line state (tab + off) state.pp_margin + | _ -> () (* No opened tabulation block. *) + end + + | Pp_newline -> + begin match state.pp_format_stack with + | Format_elem (_, width) :: _ -> break_line state width + | _ -> pp_output_newline state + end + + | Pp_if_newline -> + if state.pp_current_indent != state.pp_margin - state.pp_space_left + then pp_skip_token state + + | Pp_break (n, off) -> + begin match state.pp_format_stack with + | Format_elem (ty, width) :: _ -> + begin match ty with + | Pp_hovbox -> + if size > state.pp_space_left + then break_new_line state off width + else break_same_line state n + | Pp_box -> + (* Have the line just been broken here ? *) + if state.pp_is_new_line then break_same_line state n else + if size > state.pp_space_left + then break_new_line state off width else + (* break the line here leads to new indentation ? *) + if state.pp_current_indent > state.pp_margin - width + off + then break_new_line state off width + else break_same_line state n + | Pp_hvbox -> break_new_line state off width + | Pp_fits -> break_same_line state n + | Pp_vbox -> break_new_line state off width + | Pp_hbox -> break_same_line state n + end + | _ -> () (* No opened block. *) + end + + | Pp_open_tag tag_name -> + let marker = state.pp_mark_open_tag tag_name in + pp_output_string state marker; + state.pp_mark_stack <- tag_name :: state.pp_mark_stack + + | Pp_close_tag -> + begin match state.pp_mark_stack with + | tag_name :: tags -> + let marker = state.pp_mark_close_tag tag_name in + pp_output_string state marker; + state.pp_mark_stack <- tags + | _ -> () (* No more tag to close. *) + end +;; + +(* Print if token size is known or printing is delayed. + Size is known when not negative. + Printing is delayed when the text waiting in the queue requires + more room to format than exists on the current line. + + Note: [advance_loop] must be tail recursive to prevent stack overflows. *) +let rec advance_loop state = + match peek_queue state.pp_queue with + | {elem_size = size; token = tok; length = len} -> + let size = int_of_size size in + if not + (size < 0 && + (state.pp_right_total - state.pp_left_total < state.pp_space_left)) + then begin + ignore (take_queue state.pp_queue); + format_pp_token state (if size < 0 then pp_infinity else size) tok; + state.pp_left_total <- len + state.pp_left_total; + advance_loop state + end +;; + +let advance_left state = + try advance_loop state with + | Empty_queue -> () +;; + +let enqueue_advance state tok = pp_enqueue state tok; advance_left state;; + +(* To enqueue a string : try to advance. *) +let make_queue_elem size tok len = + { elem_size = size; token = tok; length = len; };; + +let enqueue_string_as state size s = + let len = int_of_size size in + enqueue_advance state (make_queue_elem size (Pp_text s) len) +;; + +let enqueue_string state s = + let len = String.length s in + enqueue_string_as state (size_of_int len) s +;; + +(* Routines for scan stack + determine sizes of blocks. *) + +(* The scan_stack is never empty. *) +let scan_stack_bottom = + let q_elem = make_queue_elem (size_of_int (-1)) (Pp_text "") 0 in + [Scan_elem (-1, q_elem)] +;; + +(* Set size of blocks on scan stack: + if ty = true then size of break is set else size of block is set; + in each case pp_scan_stack is popped. *) +let clear_scan_stack state = state.pp_scan_stack <- scan_stack_bottom;; + +(* Pattern matching on scan stack is exhaustive, + since scan_stack is never empty. + Pattern matching on token in scan stack is also exhaustive, + since scan_push is used on breaks and opening of boxes. *) +let set_size state ty = + match state.pp_scan_stack with + | Scan_elem + (left_tot, + ({elem_size = size; token = tok} as queue_elem)) :: t -> + let size = int_of_size size in + (* test if scan stack contains any data that is not obsolete. *) + if left_tot < state.pp_left_total then clear_scan_stack state else + begin match tok with + | Pp_break (_, _) | Pp_tbreak (_, _) -> + if ty then + begin + queue_elem.elem_size <- size_of_int (state.pp_right_total + size); + state.pp_scan_stack <- t + end + | Pp_begin (_, _) -> + if not ty then + begin + queue_elem.elem_size <- size_of_int (state.pp_right_total + size); + state.pp_scan_stack <- t + end + | _ -> () (* scan_push is only used for breaks and boxes. *) + end + | _ -> () (* scan_stack is never empty. *) +;; + +(* Push a token on scan stack. If b is true set_size is called. *) +let scan_push state b tok = + pp_enqueue state tok; + if b then set_size state true; + state.pp_scan_stack <- + Scan_elem (state.pp_right_total, tok) :: state.pp_scan_stack +;; + +(* To open a new block : + the user may set the depth bound pp_max_boxes + any text nested deeper is printed as the ellipsis string. *) +let pp_open_box_gen state indent br_ty = + state.pp_curr_depth <- state.pp_curr_depth + 1; + if state.pp_curr_depth < state.pp_max_boxes then + let elem = + make_queue_elem + (size_of_int (- state.pp_right_total)) + (Pp_begin (indent, br_ty)) + 0 in + scan_push state false elem else + if state.pp_curr_depth = state.pp_max_boxes + then enqueue_string state state.pp_ellipsis +;; + +(* The box which is always opened. *) +let pp_open_sys_box state = pp_open_box_gen state 0 Pp_hovbox;; + +(* Close a block, setting sizes of its sub blocks. *) +let pp_close_box state () = + if state.pp_curr_depth > 1 then + begin + if state.pp_curr_depth < state.pp_max_boxes then + begin + pp_enqueue state + { elem_size = size_of_int 0; token = Pp_end; length = 0; }; + set_size state true; set_size state false + end; + state.pp_curr_depth <- state.pp_curr_depth - 1; + end +;; + +(* Open a tag, pushing it on the tag stack. *) +let pp_open_tag state tag_name = + if state.pp_print_tags then + begin + state.pp_tag_stack <- tag_name :: state.pp_tag_stack; + state.pp_print_open_tag tag_name + end; + if state.pp_mark_tags then + pp_enqueue state { + elem_size = size_of_int 0; + token = Pp_open_tag tag_name; + length = 0; + } +;; + +(* Close a tag, popping it from the tag stack. *) +let pp_close_tag state () = + if state.pp_mark_tags then + pp_enqueue state { + elem_size = size_of_int 0; + token = Pp_close_tag; + length = 0; + }; + if state.pp_print_tags then + begin + match state.pp_tag_stack with + | tag_name :: tags -> + state.pp_print_close_tag tag_name; + state.pp_tag_stack <- tags + | _ -> () (* No more tag to close. *) + end +;; + +let pp_set_print_tags state b = state.pp_print_tags <- b;; +let pp_set_mark_tags state b = state.pp_mark_tags <- b;; +let pp_get_print_tags state () = state.pp_print_tags;; +let pp_get_mark_tags state () = state.pp_mark_tags;; +let pp_set_tags state b = pp_set_print_tags state b; pp_set_mark_tags state b;; + +let pp_get_formatter_tag_functions state () = { + mark_open_tag = state.pp_mark_open_tag; + mark_close_tag = state.pp_mark_close_tag; + print_open_tag = state.pp_print_open_tag; + print_close_tag = state.pp_print_close_tag; +} +;; + +let pp_set_formatter_tag_functions state { + mark_open_tag = mot; + mark_close_tag = mct; + print_open_tag = pot; + print_close_tag = pct; + } = + state.pp_mark_open_tag <- mot; + state.pp_mark_close_tag <- mct; + state.pp_print_open_tag <- pot; + state.pp_print_close_tag <- pct +;; + +(* Initialize pretty-printer. *) +let pp_rinit state = + pp_clear_queue state; + clear_scan_stack state; + state.pp_format_stack <- []; + state.pp_tbox_stack <- []; + state.pp_tag_stack <- []; + state.pp_mark_stack <- []; + state.pp_current_indent <- 0; + state.pp_curr_depth <- 0; + state.pp_space_left <- state.pp_margin; + pp_open_sys_box state;; + +(* Flushing pretty-printer queue. *) +let pp_flush_queue state b = + while state.pp_curr_depth > 1 do + pp_close_box state () + done; + state.pp_right_total <- pp_infinity; + advance_left state; + if b then pp_output_newline state; + pp_rinit state +;; + +(************************************************************** + + Procedures to format objects, and use boxes + + **************************************************************) + +(* To format a string. *) +let pp_print_as_size state size s = + if state.pp_curr_depth < state.pp_max_boxes + then enqueue_string_as state size s +;; + +let pp_print_as state isize s = + pp_print_as_size state (size_of_int isize) s +;; + +let pp_print_string state s = + pp_print_as state (String.length s) s +;; + +(* To format an integer. *) +let pp_print_int state i = pp_print_string state (string_of_int i);; + +(* To format a float. *) +let pp_print_float state f = pp_print_string state (string_of_float f);; + +(* To format a boolean. *) +let pp_print_bool state b = pp_print_string state (string_of_bool b);; + +(* To format a char. *) +let pp_print_char state c = + let s = String.create 1 in + s.[0] <- c; + pp_print_as state 1 s +;; + +(* Opening boxes. *) +let pp_open_hbox state () = pp_open_box_gen state 0 Pp_hbox +and pp_open_vbox state indent = pp_open_box_gen state indent Pp_vbox + +and pp_open_hvbox state indent = pp_open_box_gen state indent Pp_hvbox +and pp_open_hovbox state indent = pp_open_box_gen state indent Pp_hovbox +and pp_open_box state indent = pp_open_box_gen state indent Pp_box;; + +(* Print a new line after printing all queued text + (same for print_flush but without a newline). *) +let pp_print_newline state () = + pp_flush_queue state true; state.pp_flush_function () +and pp_print_flush state () = + pp_flush_queue state false; state.pp_flush_function ();; + +(* To get a newline when one does not want to close the current block. *) +let pp_force_newline state () = + if state.pp_curr_depth < state.pp_max_boxes then + enqueue_advance state (make_queue_elem (size_of_int 0) Pp_newline 0) +;; + +(* To format something if the line has just been broken. *) +let pp_print_if_newline state () = + if state.pp_curr_depth < state.pp_max_boxes then + enqueue_advance state (make_queue_elem (size_of_int 0) Pp_if_newline 0) +;; + +(* Breaks: indicate where a block may be broken. + If line is broken then offset is added to the indentation of the current + block else (the value of) width blanks are printed. + To do (?) : add a maximum width and offset value. *) +let pp_print_break state width offset = + if state.pp_curr_depth < state.pp_max_boxes then + let elem = + make_queue_elem + (size_of_int (- state.pp_right_total)) + (Pp_break (width, offset)) + width in + scan_push state true elem +;; + +let pp_print_space state () = pp_print_break state 1 0 +and pp_print_cut state () = pp_print_break state 0 0 +;; + +(* Tabulation boxes. *) +let pp_open_tbox state () = + state.pp_curr_depth <- state.pp_curr_depth + 1; + if state.pp_curr_depth < state.pp_max_boxes then + let elem = + make_queue_elem (size_of_int 0) (Pp_tbegin (Pp_tbox (ref []))) 0 in + enqueue_advance state elem +;; + +(* Close a tabulation block. *) +let pp_close_tbox state () = + if state.pp_curr_depth > 1 then + begin + if state.pp_curr_depth < state.pp_max_boxes then + let elem = make_queue_elem (size_of_int 0) Pp_tend 0 in + enqueue_advance state elem; + state.pp_curr_depth <- state.pp_curr_depth - 1 + end +;; + +(* Print a tabulation break. *) +let pp_print_tbreak state width offset = + if state.pp_curr_depth < state.pp_max_boxes then + let elem = + make_queue_elem + (size_of_int (- state.pp_right_total)) + (Pp_tbreak (width, offset)) + width in + scan_push state true elem +;; + +let pp_print_tab state () = pp_print_tbreak state 0 0;; + +let pp_set_tab state () = + if state.pp_curr_depth < state.pp_max_boxes then + let elem = + make_queue_elem (size_of_int 0) Pp_stab 0 in + enqueue_advance state elem +;; + +(************************************************************** + + Procedures to control the pretty-printers + + **************************************************************) + +(* Fit max_boxes. *) +let pp_set_max_boxes state n = if n > 1 then state.pp_max_boxes <- n;; + +(* To know the current maximum number of boxes allowed. *) +let pp_get_max_boxes state () = state.pp_max_boxes;; + +let pp_over_max_boxes state () = state.pp_curr_depth = state.pp_max_boxes;; + +(* Ellipsis. *) +let pp_set_ellipsis_text state s = state.pp_ellipsis <- s +and pp_get_ellipsis_text state () = state.pp_ellipsis +;; + +(* To set the margin of pretty-printer. *) +let pp_limit n = + if n < pp_infinity then n else pred pp_infinity +;; + +let pp_set_min_space_left state n = + if n >= 1 then + let n = pp_limit n in + state.pp_min_space_left <- n; + state.pp_max_indent <- state.pp_margin - state.pp_min_space_left; + pp_rinit state +;; + +(* Initially, we have : + pp_max_indent = pp_margin - pp_min_space_left, and + pp_space_left = pp_margin. *) +let pp_set_max_indent state n = + pp_set_min_space_left state (state.pp_margin - n) +;; +let pp_get_max_indent state () = state.pp_max_indent;; + +let pp_set_margin state n = + if n >= 1 then + let n = pp_limit n in + state.pp_margin <- n; + let new_max_indent = + (* Try to maintain max_indent to its actual value. *) + if state.pp_max_indent <= state.pp_margin + then state.pp_max_indent else + (* If possible maintain pp_min_space_left to its actual value, + if this leads to a too small max_indent, take half of the + new margin, if it is greater than 1. *) + max (max (state.pp_margin - state.pp_min_space_left) + (state.pp_margin / 2)) 1 in + (* Rebuild invariants. *) + pp_set_max_indent state new_max_indent +;; + +let pp_get_margin state () = state.pp_margin;; + +let pp_set_formatter_output_functions state f g = + state.pp_output_function <- f; state.pp_flush_function <- g;; +let pp_get_formatter_output_functions state () = + (state.pp_output_function, state.pp_flush_function) +;; + +let pp_set_all_formatter_output_functions state + ~out:f ~flush:g ~newline:h ~spaces:i = + pp_set_formatter_output_functions state f g; + state.pp_output_newline <- (function () -> h ()); + state.pp_output_spaces <- (function n -> i n) +;; +let pp_get_all_formatter_output_functions state () = + (state.pp_output_function, state.pp_flush_function, + state.pp_output_newline, state.pp_output_spaces) +;; + +let pp_set_formatter_out_channel state os = + state.pp_output_function <- output os; + state.pp_flush_function <- (fun () -> flush os) +;; + +(************************************************************** + + Creation of specific formatters + + **************************************************************) + +let default_pp_mark_open_tag s = "<" ^ s ^ ">";; +let default_pp_mark_close_tag s = "</" ^ s ^ ">";; + +let default_pp_print_open_tag s = ();; +let default_pp_print_close_tag = default_pp_print_open_tag;; + +let pp_make_formatter f g h i = + (* The initial state of the formatter contains a dummy box. *) + let pp_q = make_queue () in + let sys_tok = + make_queue_elem (size_of_int (-1)) (Pp_begin (0, Pp_hovbox)) 0 in + add_queue sys_tok pp_q; + let sys_scan_stack = + (Scan_elem (1, sys_tok)) :: scan_stack_bottom in + { + pp_scan_stack = sys_scan_stack; + pp_format_stack = []; + pp_tbox_stack = []; + pp_tag_stack = []; + pp_mark_stack = []; + pp_margin = 78; + pp_min_space_left = 10; + pp_max_indent = 78 - 10; + pp_space_left = 78; + pp_current_indent = 0; + pp_is_new_line = true; + pp_left_total = 1; + pp_right_total = 1; + pp_curr_depth = 1; + pp_max_boxes = max_int; + pp_ellipsis = "."; + pp_output_function = f; + pp_flush_function = g; + pp_output_newline = h; + pp_output_spaces = i; + pp_print_tags = false; + pp_mark_tags = false; + pp_mark_open_tag = default_pp_mark_open_tag; + pp_mark_close_tag = default_pp_mark_close_tag; + pp_print_open_tag = default_pp_print_open_tag; + pp_print_close_tag = default_pp_print_close_tag; + pp_queue = pp_q; + } +;; + +(* Default function to output spaces. *) +let blank_line = String.make 80 ' ';; +let rec display_blanks state n = + if n > 0 then + if n <= 80 then state.pp_output_function blank_line 0 n else + begin + state.pp_output_function blank_line 0 80; + display_blanks state (n - 80) + end +;; + +(* Default function to output new lines. *) +let display_newline state () = state.pp_output_function "\n" 0 1;; + +(* Make a formatter with default functions to output spaces and new lines. *) +let make_formatter output flush = + let ppf = pp_make_formatter output flush ignore ignore in + ppf.pp_output_newline <- display_newline ppf; + ppf.pp_output_spaces <- display_blanks ppf; + ppf +;; + +let formatter_of_out_channel oc = + make_formatter (output oc) (fun () -> flush oc) +;; + +let formatter_of_buffer b = + make_formatter (Buffer.add_substring b) ignore +;; + +let stdbuf = Buffer.create 512;; + +(* Predefined formatters. *) +let str_formatter = formatter_of_buffer stdbuf +and std_formatter = formatter_of_out_channel stdout +and err_formatter = formatter_of_out_channel stderr +;; + +let flush_str_formatter () = + pp_flush_queue str_formatter false; + let s = Buffer.contents stdbuf in + Buffer.reset stdbuf; + s +;; + +(************************************************************** + + Basic functions on the standard formatter + + **************************************************************) + +let open_hbox = pp_open_hbox std_formatter +and open_vbox = pp_open_vbox std_formatter +and open_hvbox = pp_open_hvbox std_formatter +and open_hovbox = pp_open_hovbox std_formatter +and open_box = pp_open_box std_formatter +and close_box = pp_close_box std_formatter +and open_tag = pp_open_tag std_formatter +and close_tag = pp_close_tag std_formatter +and print_as = pp_print_as std_formatter +and print_string = pp_print_string std_formatter +and print_int = pp_print_int std_formatter +and print_float = pp_print_float std_formatter +and print_char = pp_print_char std_formatter +and print_bool = pp_print_bool std_formatter +and print_break = pp_print_break std_formatter +and print_cut = pp_print_cut std_formatter +and print_space = pp_print_space std_formatter +and force_newline = pp_force_newline std_formatter +and print_flush = pp_print_flush std_formatter +and print_newline = pp_print_newline std_formatter +and print_if_newline = pp_print_if_newline std_formatter + +and open_tbox = pp_open_tbox std_formatter +and close_tbox = pp_close_tbox std_formatter +and print_tbreak = pp_print_tbreak std_formatter + +and set_tab = pp_set_tab std_formatter +and print_tab = pp_print_tab std_formatter + +and set_margin = pp_set_margin std_formatter +and get_margin = pp_get_margin std_formatter + +and set_max_indent = pp_set_max_indent std_formatter +and get_max_indent = pp_get_max_indent std_formatter + +and set_max_boxes = pp_set_max_boxes std_formatter +and get_max_boxes = pp_get_max_boxes std_formatter +and over_max_boxes = pp_over_max_boxes std_formatter + +and set_ellipsis_text = pp_set_ellipsis_text std_formatter +and get_ellipsis_text = pp_get_ellipsis_text std_formatter + +and set_formatter_out_channel = + pp_set_formatter_out_channel std_formatter + +and set_formatter_output_functions = + pp_set_formatter_output_functions std_formatter +and get_formatter_output_functions = + pp_get_formatter_output_functions std_formatter + +and set_all_formatter_output_functions = + pp_set_all_formatter_output_functions std_formatter +and get_all_formatter_output_functions = + pp_get_all_formatter_output_functions std_formatter + +and set_formatter_tag_functions = + pp_set_formatter_tag_functions std_formatter +and get_formatter_tag_functions = + pp_get_formatter_tag_functions std_formatter +and set_print_tags = + pp_set_print_tags std_formatter +and get_print_tags = + pp_get_print_tags std_formatter +and set_mark_tags = + pp_set_mark_tags std_formatter +and get_mark_tags = + pp_get_mark_tags std_formatter +and set_tags = + pp_set_tags std_formatter +;; + + +(************************************************************** + + Printf implementation. + + **************************************************************) + +module Sformat = Printf.CamlinternalPr.Sformat;; +module Tformat = Printf.CamlinternalPr.Tformat;; + +(* Error messages when processing formats. *) + +(* Trailer: giving up at character number ... *) +let giving_up mess fmt i = + "fprintf: " ^ mess ^ " ``" ^ Sformat.to_string fmt ^ "'', \ + giving up at character number " ^ string_of_int i ^ + (if i < Sformat.length fmt + then " (" ^ String.make 1 (Sformat.get fmt i) ^ ")." + else String.make 1 '.') +;; + +(* When an invalid format deserves a special error explanation. *) +let format_invalid_arg mess fmt i = invalid_arg (giving_up mess fmt i);; + +(* Standard invalid format. *) +let invalid_format fmt i = format_invalid_arg "bad format" fmt i;; + +(* Cannot find a valid integer into that format. *) +let invalid_integer fmt i = + invalid_arg (giving_up "bad integer specification" fmt i);; + +(* Finding an integer out of a sub-string of the format. *) +let format_int_of_string fmt i s = + let sz = + try int_of_string s with + | Failure s -> invalid_integer fmt i in + size_of_int sz +;; + +(* Getting strings out of buffers. *) +let get_buffer_out b = + let s = Buffer.contents b in + Buffer.reset b; + s +;; + +(* [ppf] is supposed to be a pretty-printer that outputs in buffer [b]: + to extract contents of [ppf] as a string we flush [ppf] and get the string + out of [b]. *) +let string_out b ppf = + pp_flush_queue ppf false; + get_buffer_out b +;; + +(* Applies [printer] to a formatter that outputs on a fresh buffer, + then returns the resulting material. *) +let exstring printer arg = + let b = Buffer.create 512 in + let ppf = formatter_of_buffer b in + printer ppf arg; + string_out b ppf +;; + +(* To turn out a character accumulator into the proper string result. *) +let implode_rev s0 = function + | [] -> s0 + | l -> String.concat "" (List.rev (s0 :: l)) +;; + +(* [mkprintf] is the printf-like function generator: given the + - [to_s] flag that tells if we are printing into a string, + - the [get_out] function that has to be called to get a [ppf] function to + output onto. + It generates a [kprintf] function that takes as arguments a [k] + continuation function to be called at the end of formatting, + and a printing format string to print the rest of the arguments + according to the format string. + Regular [fprintf]-like functions of this module are obtained via partial + applications of [mkprintf]. *) +let mkprintf to_s get_out = + + let rec kprintf k fmt = + + let len = Sformat.length fmt in + + let kpr fmt v = + let ppf = get_out fmt in + let print_as = ref None in + let pp_print_as_char c = + match !print_as with + | None -> pp_print_char ppf c + | Some size -> + pp_print_as_size ppf size (String.make 1 c); + print_as := None + and pp_print_as_string s = + match !print_as with + | None -> pp_print_string ppf s + | Some size -> + pp_print_as_size ppf size s; + print_as := None in + + let rec doprn n i = + if i >= len then Obj.magic (k ppf) else + match Sformat.get fmt i with + | '%' -> + Tformat.scan_format fmt v n i cont_s cont_a cont_t cont_f cont_m + | '@' -> + let i = succ i in + if i >= len then invalid_format fmt i else + begin match Sformat.get fmt i with + | '[' -> + do_pp_open_box ppf n (succ i) + | ']' -> + pp_close_box ppf (); + doprn n (succ i) + | '{' -> + do_pp_open_tag ppf n (succ i) + | '}' -> + pp_close_tag ppf (); + doprn n (succ i) + | ' ' -> + pp_print_space ppf (); + doprn n (succ i) + | ',' -> + pp_print_cut ppf (); + doprn n (succ i) + | '?' -> + pp_print_flush ppf (); + doprn n (succ i) + | '.' -> + pp_print_newline ppf (); + doprn n (succ i) + | '\n' -> + pp_force_newline ppf (); + doprn n (succ i) + | ';' -> + do_pp_break ppf n (succ i) + | '<' -> + let got_size size n i = + print_as := Some size; + doprn n (skip_gt i) in + get_int n (succ i) got_size + | '@' as c -> + pp_print_as_char c; + doprn n (succ i) + | c -> invalid_format fmt i + end + | c -> + pp_print_as_char c; + doprn n (succ i) + + and cont_s n s i = + pp_print_as_string s; doprn n i + and cont_a n printer arg i = + if to_s then + pp_print_as_string ((Obj.magic printer : unit -> _ -> string) () arg) + else + printer ppf arg; + doprn n i + and cont_t n printer i = + if to_s then + pp_print_as_string ((Obj.magic printer : unit -> string) ()) + else + printer ppf; + doprn n i + and cont_f n i = + pp_print_flush ppf (); doprn n i + and cont_m n sfmt i = + kprintf (Obj.magic (fun _ -> doprn n i)) sfmt + + and get_int n i c = + if i >= len then invalid_integer fmt i else + match Sformat.get fmt i with + | ' ' -> get_int n (succ i) c + | '%' -> + let cont_s n s i = c (format_int_of_string fmt i s) n i + and cont_a n printer arg i = invalid_integer fmt i + and cont_t n printer i = invalid_integer fmt i + and cont_f n i = invalid_integer fmt i + and cont_m n sfmt i = invalid_integer fmt i in + Tformat.scan_format fmt v n i cont_s cont_a cont_t cont_f cont_m + | _ -> + let rec get j = + if j >= len then invalid_integer fmt j else + match Sformat.get fmt j with + | '0' .. '9' | '-' -> get (succ j) + | _ -> + let size = + if j = i then size_of_int 0 else + let s = Sformat.sub fmt (Sformat.index_of_int i) (j - i) in + format_int_of_string fmt j s in + c size n j in + get i + + and skip_gt i = + if i >= len then invalid_format fmt i else + match Sformat.get fmt i with + | ' ' -> skip_gt (succ i) + | '>' -> succ i + | _ -> invalid_format fmt i + + and get_box_kind i = + if i >= len then Pp_box, i else + match Sformat.get fmt i with + | 'h' -> + let i = succ i in + if i >= len then Pp_hbox, i else + begin match Sformat.get fmt i with + | 'o' -> + let i = succ i in + if i >= len then format_invalid_arg "bad box format" fmt i else + begin match Sformat.get fmt i with + | 'v' -> Pp_hovbox, succ i + | c -> + format_invalid_arg + ("bad box name ho" ^ String.make 1 c) fmt i + end + | 'v' -> Pp_hvbox, succ i + | c -> Pp_hbox, i + end + | 'b' -> Pp_box, succ i + | 'v' -> Pp_vbox, succ i + | _ -> Pp_box, i + + and get_tag_name n i c = + let rec get accu n i j = + if j >= len then + c (implode_rev + (Sformat.sub fmt (Sformat.index_of_int i) (j - i)) + accu) + n j else + match Sformat.get fmt j with + | '>' -> + c (implode_rev + (Sformat.sub fmt (Sformat.index_of_int i) (j - i)) + accu) + n j + | '%' -> + let s0 = Sformat.sub fmt (Sformat.index_of_int i) (j - i) in + let cont_s n s i = get (s :: s0 :: accu) n i i + and cont_a n printer arg i = + let s = + if to_s + then (Obj.magic printer : unit -> _ -> string) () arg + else exstring printer arg in + get (s :: s0 :: accu) n i i + and cont_t n printer i = + let s = + if to_s + then (Obj.magic printer : unit -> string) () + else exstring (fun ppf () -> printer ppf) () in + get (s :: s0 :: accu) n i i + and cont_f n i = + format_invalid_arg "bad tag name specification" fmt i + and cont_m n sfmt i = + format_invalid_arg "bad tag name specification" fmt i in + Tformat.scan_format fmt v n j cont_s cont_a cont_t cont_f cont_m + | c -> get accu n i (succ j) in + get [] n i i + + and do_pp_break ppf n i = + if i >= len then begin pp_print_space ppf (); doprn n i end else + match Sformat.get fmt i with + | '<' -> + let rec got_nspaces nspaces n i = + get_int n i (got_offset nspaces) + and got_offset nspaces offset n i = + pp_print_break ppf (int_of_size nspaces) (int_of_size offset); + doprn n (skip_gt i) in + get_int n (succ i) got_nspaces + | c -> pp_print_space ppf (); doprn n i + + and do_pp_open_box ppf n i = + if i >= len then begin pp_open_box_gen ppf 0 Pp_box; doprn n i end else + match Sformat.get fmt i with + | '<' -> + let kind, i = get_box_kind (succ i) in + let got_size size n i = + pp_open_box_gen ppf (int_of_size size) kind; + doprn n (skip_gt i) in + get_int n i got_size + | c -> pp_open_box_gen ppf 0 Pp_box; doprn n i + + and do_pp_open_tag ppf n i = + if i >= len then begin pp_open_tag ppf ""; doprn n i end else + match Sformat.get fmt i with + | '<' -> + let got_name tag_name n i = + pp_open_tag ppf tag_name; + doprn n (skip_gt i) in + get_tag_name n (succ i) got_name + | c -> pp_open_tag ppf ""; doprn n i in + + doprn (Sformat.index_of_int 0) 0 in + + Tformat.kapr kpr fmt in + + kprintf +;; + +(************************************************************** + + Defining [fprintf] and various flavors of [fprintf]. + + **************************************************************) + +let kfprintf k ppf = mkprintf false (fun _ -> ppf) k;; +let ifprintf ppf = Tformat.kapr (fun _ -> Obj.magic ignore);; + +let fprintf ppf = kfprintf ignore ppf;; +let printf fmt = fprintf std_formatter fmt;; +let eprintf fmt = fprintf err_formatter fmt;; + +let kbprintf k b = + mkprintf false (fun _ -> formatter_of_buffer b) k +;; + +let bprintf b = kbprintf ignore b;; + +let ksprintf k = + let b = Buffer.create 512 in + let k ppf = k (string_out b ppf) in + mkprintf true (fun _ -> formatter_of_buffer b) k +;; + +let kprintf = ksprintf;; + +let sprintf fmt = ksprintf (fun s -> s) fmt;; + +at_exit print_flush +;; diff --git a/stdlib/format.mli b/stdlib/format.mli new file mode 100644 index 0000000..0b07690 --- /dev/null +++ b/stdlib/format.mli @@ -0,0 +1,668 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: format.mli,v 1.74 2006-11-17 08:37:07 weis Exp $ *) + +(** Pretty printing. + + This module implements a pretty-printing facility to format text + within ``pretty-printing boxes''. The pretty-printer breaks lines + at specified break hints, and indents lines according to the box + structure. + + For a gentle introduction to the basics of pretty-printing using + [Format], read + {{:http://caml.inria.fr/resources/doc/guides/format.html}http://caml.inria.fr/resources/doc/guides/format.html}. + + You may consider this module as providing an extension to the + [printf] facility to provide automatic line breaking. The addition of + pretty-printing annotations to your regular [printf] formats gives you + fancy indentation and line breaks. + Pretty-printing annotations are described below in the documentation of + the function {!Format.fprintf}. + + You may also use the explicit box management and printing functions + provided by this module. This style is more basic but more verbose + than the [fprintf] concise formats. + + For instance, the sequence + [open_box 0; print_string "x ="; print_space (); print_int 1; close_box ()] + that prints [x = 1] within a pretty-printing box, can be + abbreviated as [printf "@[%s@ %i@]" "x =" 1], or even shorter + [printf "@[x =@ %i@]" 1]. + + Rule of thumb for casual users of this library: + - use simple boxes (as obtained by [open_box 0]); + - use simple break hints (as obtained by [print_cut ()] that outputs a + simple break hint, or by [print_space ()] that outputs a space + indicating a break hint); + - once a box is opened, display its material with basic printing + functions (e. g. [print_int] and [print_string]); + - when the material for a box has been printed, call [close_box ()] to + close the box; + - at the end of your routine, evaluate [print_newline ()] to close + all remaining boxes and flush the pretty-printer. + + The behaviour of pretty-printing commands is unspecified + if there is no opened pretty-printing box. Each box opened via + one of the [open_] functions below must be closed using [close_box] + for proper formatting. Otherwise, some of the material printed in the + boxes may not be output, or may be formatted incorrectly. + + In case of interactive use, the system closes all opened boxes and + flushes all pending text (as with the [print_newline] function) + after each phrase. Each phrase is therefore executed in the initial + state of the pretty-printer. + + Warning: the material output by the following functions is delayed + in the pretty-printer queue in order to compute the proper line + breaking. Hence, you should not mix calls to the printing functions + of the basic I/O system with calls to the functions of this module: + this could result in some strange output seemingly unrelated with + the evaluation order of printing commands. +*) + + +(** {6 Boxes} *) + +val open_box : int -> unit;; +(** [open_box d] opens a new pretty-printing box + with offset [d]. + This box is the general purpose pretty-printing box. + Material in this box is displayed ``horizontal or vertical'': + break hints inside the box may lead to a new line, if there + is no more room on the line to print the remainder of the box, + or if a new line may lead to a new indentation + (demonstrating the indentation of the box). + When a new line is printed in the box, [d] is added to the + current indentation. *) + +val close_box : unit -> unit;; +(** Closes the most recently opened pretty-printing box. *) + +(** {6 Formatting functions} *) + +val print_string : string -> unit;; +(** [print_string str] prints [str] in the current box. *) + +val print_as : int -> string -> unit;; +(** [print_as len str] prints [str] in the + current box. The pretty-printer formats [str] as if + it were of length [len]. *) + +val print_int : int -> unit;; +(** Prints an integer in the current box. *) + +val print_float : float -> unit;; +(** Prints a floating point number in the current box. *) + +val print_char : char -> unit;; +(** Prints a character in the current box. *) + +val print_bool : bool -> unit;; +(** Prints a boolean in the current box. *) + + +(** {6 Break hints} *) + +val print_space : unit -> unit;; +(** [print_space ()] is used to separate items (typically to print + a space between two words). + It indicates that the line may be split at this + point. It either prints one space or splits the line. + It is equivalent to [print_break 1 0]. *) + +val print_cut : unit -> unit;; +(** [print_cut ()] is used to mark a good break position. + It indicates that the line may be split at this + point. It either prints nothing or splits the line. + This allows line splitting at the current + point, without printing spaces or adding indentation. + It is equivalent to [print_break 0 0]. *) + +val print_break : int -> int -> unit;; +(** Inserts a break hint in a pretty-printing box. + [print_break nspaces offset] indicates that the line may + be split (a newline character is printed) at this point, + if the contents of the current box does not fit on the + current line. + If the line is split at that point, [offset] is added to + the current indentation. If the line is not split, + [nspaces] spaces are printed. *) + +val print_flush : unit -> unit;; +(** Flushes the pretty printer: all opened boxes are closed, + and all pending text is displayed. *) + +val print_newline : unit -> unit;; +(** Equivalent to [print_flush] followed by a new line. *) + +val force_newline : unit -> unit;; +(** Forces a newline in the current box. Not the normal way of + pretty-printing, you should prefer break hints. *) + +val print_if_newline : unit -> unit;; +(** Executes the next formatting command if the preceding line + has just been split. Otherwise, ignore the next formatting + command. *) + + +(** {6 Margin} *) + +val set_margin : int -> unit;; +(** [set_margin d] sets the value of the right margin + to [d] (in characters): this value is used to detect line + overflows that leads to split lines. + Nothing happens if [d] is smaller than 2. + If [d] is too large, the right margin is set to the maximum + admissible value (which is greater than [10^10]). *) + +val get_margin : unit -> int;; +(** Returns the position of the right margin. *) + + +(** {6 Maximum indentation limit} *) + +val set_max_indent : int -> unit;; +(** [set_max_indent d] sets the value of the maximum + indentation limit to [d] (in characters): + once this limit is reached, boxes are rejected to the left, + if they do not fit on the current line. + Nothing happens if [d] is smaller than 2. + If [d] is too large, the limit is set to the maximum + admissible value (which is greater than [10^10]). *) + +val get_max_indent : unit -> int;; +(** Return the value of the maximum indentation limit (in characters). *) + +(** {6 Formatting depth: maximum number of boxes allowed before ellipsis} *) + +val set_max_boxes : int -> unit;; +(** [set_max_boxes max] sets the maximum number + of boxes simultaneously opened. + Material inside boxes nested deeper is printed as an + ellipsis (more precisely as the text returned by + [get_ellipsis_text ()]). + Nothing happens if [max] is smaller than 2. *) + +val get_max_boxes : unit -> int;; +(** Returns the maximum number of boxes allowed before ellipsis. *) + +val over_max_boxes : unit -> bool;; +(** Tests if the maximum number of boxes allowed have already been opened. *) + + +(** {6 Advanced formatting} *) + +val open_hbox : unit -> unit;; +(** [open_hbox ()] opens a new pretty-printing box. + This box is ``horizontal'': the line is not split in this box + (new lines may still occur inside boxes nested deeper). *) + +val open_vbox : int -> unit;; +(** [open_vbox d] opens a new pretty-printing box + with offset [d]. + This box is ``vertical'': every break hint inside this + box leads to a new line. + When a new line is printed in the box, [d] is added to the + current indentation. *) + +val open_hvbox : int -> unit;; +(** [open_hvbox d] opens a new pretty-printing box + with offset [d]. + This box is ``horizontal-vertical'': it behaves as an + ``horizontal'' box if it fits on a single line, + otherwise it behaves as a ``vertical'' box. + When a new line is printed in the box, [d] is added to the + current indentation. *) + +val open_hovbox : int -> unit;; +(** [open_hovbox d] opens a new pretty-printing box + with offset [d]. + This box is ``horizontal or vertical'': break hints + inside this box may lead to a new line, if there is no more room + on the line to print the remainder of the box. + When a new line is printed in the box, [d] is added to the + current indentation. *) + + +(** {6 Tabulations} *) + +val open_tbox : unit -> unit;; +(** Opens a tabulation box. *) + +val close_tbox : unit -> unit;; +(** Closes the most recently opened tabulation box. *) + +val print_tbreak : int -> int -> unit;; +(** Break hint in a tabulation box. + [print_tbreak spaces offset] moves the insertion point to + the next tabulation ([spaces] being added to this position). + Nothing occurs if insertion point is already on a + tabulation mark. + If there is no next tabulation on the line, then a newline + is printed and the insertion point moves to the first + tabulation of the box. + If a new line is printed, [offset] is added to the current + indentation. *) + +val set_tab : unit -> unit;; +(** Sets a tabulation mark at the current insertion point. *) + +val print_tab : unit -> unit;; +(** [print_tab ()] is equivalent to [print_tbreak (0,0)]. *) + + +(** {6 Ellipsis} *) + +val set_ellipsis_text : string -> unit;; +(** Set the text of the ellipsis printed when too many boxes + are opened (a single dot, [.], by default). *) + +val get_ellipsis_text : unit -> string;; +(** Return the text of the ellipsis. *) + + +(** {6 Tags} *) + +type tag = string;; + +(** Tags are used to decorate printed entities for user's defined + purposes, e.g. setting font and giving size indications for a + display device, or marking delimitations of semantics entities + (e.g. HTML or TeX elements or terminal escape sequences). + + By default, those tags do not influence line breaking calculation: + the tag ``markers'' are not considered as part of the printing + material that drives line breaking (in other words, the length of + those strings is considered as zero for line breaking). + + Thus, tag handling is in some sense transparent to pretty-printing + and does not interfere with usual pretty-printing. Hence, a single + pretty printing routine can output both simple ``verbatim'' + material or richer decorated output depending on the treatment of + tags. By default, tags are not active, hence the output is not + decorated with tag information. Once [set_tags] is set to [true], + the pretty printer engine honors tags and decorates the output + accordingly. + + When a tag has been opened (or closed), it is both and successively + ``printed'' and ``marked''. Printing a tag means calling a + formatter specific function with the name of the tag as argument: + that ``tag printing'' function can then print any regular material + to the formatter (so that this material is enqueued as usual in the + formatter queue for further line-breaking computation). Marking a + tag means to output an arbitrary string (the ``tag marker''), + directly into the output device of the formatter. Hence, the + formatter specific ``tag marking'' function must return the tag + marker string associated to its tag argument. Being flushed + directly into the output device of the formatter, tag marker + strings are not considered as part of the printing material that + drives line breaking (in other words, the length of the strings + corresponding to tag markers is considered as zero for line + breaking). In addition, advanced users may take advantage of + the specificity of tag markers to be precisely output when the + pretty printer has already decided where to break the lines, and + precisely when the queue is flushed into the output device. + + In the spirit of HTML tags, the default tag marking functions + output tags enclosed in "<" and ">": hence, the opening marker of + tag [t] is ["<t>"] and the closing marker ["</t>"]. + + Default tag printing functions just do nothing. + + Tag marking and tag printing functions are user definable and can + be set by calling [set_formatter_tag_functions]. *) + +val open_tag : tag -> unit;; +(** [open_tag t] opens the tag named [t]; the [print_open_tag] + function of the formatter is called with [t] as argument; + the tag marker [mark_open_tag t] will be flushed into the output + device of the formatter. *) +val close_tag : unit -> unit;; +(** [close_tag ()] closes the most recently opened tag [t]. + In addition, the [print_close_tag] function of the formatter is called + with [t] as argument. The marker [mark_close_tag t] will be flushed + into the output device of the formatter. *) + +val set_tags : bool -> unit;; +(** [set_tags b] turns on or off the treatment of tags (default is off). *) +val set_print_tags : bool -> unit;; +val set_mark_tags : bool -> unit;; +(** [set_print_tags b] turns on or off the printing of tags, while + [set_mark_tags b] turns on or off the output of tag markers. *) +val get_print_tags : unit -> bool;; +val get_mark_tags : unit -> bool;; +(** Return the current status of tags printing and tags marking. *) + + +(** {6 Redirecting formatter output} *) + +val set_formatter_out_channel : out_channel -> unit;; +(** Redirect the pretty-printer output to the given channel. *) + +val set_formatter_output_functions : + (string -> int -> int -> unit) -> (unit -> unit) -> unit;; +(** [set_formatter_output_functions out flush] redirects the + pretty-printer output to the functions [out] and [flush]. + + The [out] function performs the pretty-printer output. It is called + with a string [s], a start position [p], and a number of characters + [n]; it is supposed to output characters [p] to [p + n - 1] of + [s]. The [flush] function is called whenever the pretty-printer is + flushed using [print_flush] or [print_newline]. *) + +val get_formatter_output_functions : + unit -> (string -> int -> int -> unit) * (unit -> unit);; +(** Return the current output functions of the pretty-printer. *) + +(** {6 Changing the meaning of printing tags} *) + +type formatter_tag_functions = { + mark_open_tag : tag -> string; + mark_close_tag : tag -> string; + print_open_tag : tag -> unit; + print_close_tag : tag -> unit; +};; +(** The tag handling functions specific to a formatter: + [mark] versions are the ``tag marking'' functions that associate a string + marker to a tag in order for the pretty-printing engine to flush + those markers as 0 length tokens in the output device of the formatter. + [print] versions are the ``tag printing'' functions that can perform + regular printing when a tag is closed or opened. *) + +val set_formatter_tag_functions : + formatter_tag_functions -> unit;; + +(** [set_formatter_tag_functions tag_funs] changes the meaning of + opening and closing tags to use the functions in [tag_funs]. + + When opening a tag name [t], the string [t] is passed to the + opening tag marking function (the [mark_open_tag] field of the + record [tag_funs]), that must return the opening tag marker for + that name. When the next call to [close_tag ()] happens, the tag + name [t] is sent back to the closing tag marking function (the + [mark_close_tag] field of record [tag_funs]), that must return a + closing tag marker for that name. + + The [print_] field of the record contains the functions that are + called at tag opening and tag closing time, to output regular + material in the pretty-printer queue. *) + +val get_formatter_tag_functions : + unit -> formatter_tag_functions;; +(** Return the current tag functions of the pretty-printer. *) + +(** {6 Changing the meaning of pretty printing (indentation, line breaking, + and printing material)} *) + +val set_all_formatter_output_functions : + out:(string -> int -> int -> unit) -> + flush:(unit -> unit) -> + newline:(unit -> unit) -> + spaces:(int -> unit) -> + unit;; +(** [set_all_formatter_output_functions out flush outnewline outspace] + redirects the pretty-printer output to the functions [out] and + [flush] as described in [set_formatter_output_functions]. In + addition, the pretty-printer function that outputs a newline is set + to the function [outnewline] and the function that outputs + indentation spaces is set to the function [outspace]. + + This way, you can change the meaning of indentation (which can be + something else than just printing space characters) and the + meaning of new lines opening (which can be connected to any other + action needed by the application at hand). The two functions + [outspace] and [outnewline] are normally connected to [out] and + [flush]: respective default values for [outspace] and [outnewline] + are [out (String.make n ' ') 0 n] and [out "\n" 0 1]. *) + +val get_all_formatter_output_functions : + unit -> + (string -> int -> int -> unit) * + (unit -> unit) * + (unit -> unit) * + (int -> unit);; +(** Return the current output functions of the pretty-printer, + including line breaking and indentation functions. *) + + +(** {6 Multiple formatted output} *) + +type formatter;; +(** Abstract data type corresponding to a pretty-printer (also called a + formatter) and all its machinery. + Defining new pretty-printers permits the output of + material in parallel on several channels. + Parameters of a pretty-printer are local to this pretty-printer: + margin, maximum indentation limit, maximum number of boxes + simultaneously opened, ellipsis, and so on, are specific to + each pretty-printer and may be fixed independently. + Given an output channel [oc], a new formatter writing to + that channel is obtained by calling [formatter_of_out_channel oc]. + Alternatively, the [make_formatter] function allocates a new + formatter with explicit output and flushing functions + (convenient to output material to strings for instance). *) + +val formatter_of_out_channel : out_channel -> formatter;; +(** [formatter_of_out_channel oc] returns a new formatter that + writes to the corresponding channel [oc]. *) + +val std_formatter : formatter;; +(** The standard formatter used by the formatting functions + above. It is defined as [formatter_of_out_channel stdout]. *) + +val err_formatter : formatter;; +(** A formatter to use with formatting functions below for + output to standard error. It is defined as + [formatter_of_out_channel stderr]. *) + +val formatter_of_buffer : Buffer.t -> formatter;; +(** [formatter_of_buffer b] returns a new formatter writing to + buffer [b]. As usual, the formatter has to be flushed at + the end of pretty printing, using [pp_print_flush] or + [pp_print_newline], to display all the pending material. *) + +val stdbuf : Buffer.t;; +(** The string buffer in which [str_formatter] writes. *) + +val str_formatter : formatter;; +(** A formatter to use with formatting functions below for + output to the [stdbuf] string buffer. + [str_formatter] is defined as [formatter_of_buffer stdbuf]. *) + +val flush_str_formatter : unit -> string;; +(** Returns the material printed with [str_formatter], flushes + the formatter and resets the corresponding buffer. *) + +val make_formatter : + (string -> int -> int -> unit) -> (unit -> unit) -> formatter;; +(** [make_formatter out flush] returns a new formatter that + writes according to the output function [out], and the flushing + function [flush]. Hence, a formatter to the out channel [oc] + is returned by [make_formatter (output oc) (fun () -> flush oc)]. *) + +(** {6 Basic functions to use with formatters} *) + +val pp_open_hbox : formatter -> unit -> unit;; +val pp_open_vbox : formatter -> int -> unit;; +val pp_open_hvbox : formatter -> int -> unit;; +val pp_open_hovbox : formatter -> int -> unit;; +val pp_open_box : formatter -> int -> unit;; +val pp_close_box : formatter -> unit -> unit;; +val pp_open_tag : formatter -> string -> unit;; +val pp_close_tag : formatter -> unit -> unit;; +val pp_print_string : formatter -> string -> unit;; +val pp_print_as : formatter -> int -> string -> unit;; +val pp_print_int : formatter -> int -> unit;; +val pp_print_float : formatter -> float -> unit;; +val pp_print_char : formatter -> char -> unit;; +val pp_print_bool : formatter -> bool -> unit;; +val pp_print_break : formatter -> int -> int -> unit;; +val pp_print_cut : formatter -> unit -> unit;; +val pp_print_space : formatter -> unit -> unit;; +val pp_force_newline : formatter -> unit -> unit;; +val pp_print_flush : formatter -> unit -> unit;; +val pp_print_newline : formatter -> unit -> unit;; +val pp_print_if_newline : formatter -> unit -> unit;; +val pp_open_tbox : formatter -> unit -> unit;; +val pp_close_tbox : formatter -> unit -> unit;; +val pp_print_tbreak : formatter -> int -> int -> unit;; +val pp_set_tab : formatter -> unit -> unit;; +val pp_print_tab : formatter -> unit -> unit;; +val pp_set_tags : formatter -> bool -> unit;; +val pp_set_print_tags : formatter -> bool -> unit;; +val pp_set_mark_tags : formatter -> bool -> unit;; +val pp_get_print_tags : formatter -> unit -> bool;; +val pp_get_mark_tags : formatter -> unit -> bool;; +val pp_set_margin : formatter -> int -> unit;; +val pp_get_margin : formatter -> unit -> int;; +val pp_set_max_indent : formatter -> int -> unit;; +val pp_get_max_indent : formatter -> unit -> int;; +val pp_set_max_boxes : formatter -> int -> unit;; +val pp_get_max_boxes : formatter -> unit -> int;; +val pp_over_max_boxes : formatter -> unit -> bool;; +val pp_set_ellipsis_text : formatter -> string -> unit;; +val pp_get_ellipsis_text : formatter -> unit -> string;; +val pp_set_formatter_out_channel : formatter -> out_channel -> unit;; +val pp_set_formatter_output_functions : + formatter -> (string -> int -> int -> unit) -> (unit -> unit) -> unit;; +val pp_get_formatter_output_functions : + formatter -> unit -> (string -> int -> int -> unit) * (unit -> unit);; +val pp_set_all_formatter_output_functions : + formatter -> out:(string -> int -> int -> unit) -> flush:(unit -> unit) -> + newline:(unit -> unit) -> spaces:(int -> unit) -> unit;; +val pp_get_all_formatter_output_functions : + formatter -> unit -> + (string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * + (int -> unit);; +val pp_set_formatter_tag_functions : + formatter -> formatter_tag_functions -> unit;; +val pp_get_formatter_tag_functions : + formatter -> unit -> formatter_tag_functions;; +(** These functions are the basic ones: usual functions + operating on the standard formatter are defined via partial + evaluation of these primitives. For instance, + [print_string] is equal to [pp_print_string std_formatter]. *) + + +(** {6 [printf] like functions for pretty-printing.} *) + +val fprintf : formatter -> ('a, formatter, unit) format -> 'a;; +(** [fprintf ff format arg1 ... argN] formats the arguments + [arg1] to [argN] according to the format string [format], + and outputs the resulting string on the formatter [ff]. + The format is a character string which contains three types of + objects: plain characters and conversion specifications as + specified in the [printf] module, and pretty-printing + indications. + The pretty-printing indication characters are introduced by + a [@] character, and their meanings are: + - [@\[]: open a pretty-printing box. The type and offset of the + box may be optionally specified with the following syntax: + the [<] character, followed by an optional box type indication, + then an optional integer offset, and the closing [>] character. + Box type is one of [h], [v], [hv], [b], or [hov], + which stand respectively for an horizontal box, a vertical box, + an ``horizontal-vertical'' box, or an ``horizontal or + vertical'' box ([b] standing for an ``horizontal or + vertical'' box demonstrating indentation and [hov] standing + for a regular``horizontal or vertical'' box). + For instance, [@\[<hov 2>] opens an ``horizontal or vertical'' + box with indentation 2 as obtained with [open_hovbox 2]. + For more details about boxes, see the various box opening + functions [open_*box]. + - [@\]]: close the most recently opened pretty-printing box. + - [@,]: output a good break as with [print_cut ()]. + - [@ ]: output a space, as with [print_space ()]. + - [@\n]: force a newline, as with [force_newline ()]. + - [@;]: output a good break as with [print_break]. The + [nspaces] and [offset] parameters of the break may be + optionally specified with the following syntax: + the [<] character, followed by an integer [nspaces] value, + then an integer [offset], and a closing [>] character. + If no parameters are provided, the good break defaults to a + space. + - [@?]: flush the pretty printer as with [print_flush ()]. + This is equivalent to the conversion [%!]. + - [@.]: flush the pretty printer and output a new line, as with + [print_newline ()]. + - [@<n>]: print the following item as if it were of length [n]. + Hence, [printf "@<0>%s" arg] is equivalent to [print_as 0 arg]. + If [@<n>] is not followed by a conversion specification, + then the following character of the format is printed as if + it were of length [n]. + - [@\{]: open a tag. The name of the tag may be optionally + specified with the following syntax: + the [<] character, followed by an optional string + specification, and the closing [>] character. The string + specification is any character string that does not contain the + closing character ['>']. If omitted, the tag name defaults to the + empty string. + For more details about tags, see the functions [open_tag] and + [close_tag]. + - [@\}]: close the most recently opened tag. + - [@@]: print a plain [@] character. + + Example: [printf "@[%s@ %d@]" "x =" 1] is equivalent to + [open_box (); print_string "x ="; print_space (); print_int 1; close_box ()]. + It prints [x = 1] within a pretty-printing box. +*) + +val printf : ('a, formatter, unit) format -> 'a;; +(** Same as [fprintf] above, but output on [std_formatter]. *) + +val eprintf : ('a, formatter, unit) format -> 'a;; +(** Same as [fprintf] above, but output on [err_formatter]. *) + +val sprintf : ('a, unit, string) format -> 'a;; +(** Same as [printf] above, but instead of printing on a formatter, + returns a string containing the result of formatting the arguments. + Note that the pretty-printer queue is flushed at the end of each + call to [sprintf]. + + In case of multiple and related calls to [sprintf] to output + material on a single string, you should consider using [fprintf] + with a formatter writing to a buffer: flushing the buffer at the + end of pretty-printing returns the desired string. You can also use + the predefined formatter [str_formatter] and call + [flush_str_formatter ()] to get the result. *) + +val bprintf : Buffer.t -> ('a, formatter, unit) format -> 'a;; +(** Same as [sprintf] above, but instead of printing on a string, + writes into the given extensible buffer. + As for [sprintf], the pretty-printer queue is flushed at the end of each + call to [bprintf]. + + In case of multiple and related calls to [bprintf] to output + material on the same buffer [b], you should consider using + [fprintf] with a formatter writing to the buffer [b] (as obtained + by [formatter_of_buffer b]), otherwise the repeated flushes of the + pretty-printer queue would result in unexpected and badly formatted + output. *) + +val kfprintf : (formatter -> 'a) -> formatter -> + ('b, formatter, unit, 'a) format4 -> 'b;; +(** Same as [fprintf] above, but instead of returning immediately, + passes the formatter to its first argument at the end of printing. *) + +val ifprintf : formatter -> ('a, formatter, unit) format -> 'a;; +(** Same as [fprintf] above, but does not print anything. + Useful to ignore some material when conditionally printing. *) + +val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b;; +(** Same as [sprintf] above, but instead of returning the string, + passes it to the first argument. *) + +val kprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b;; +(** A deprecated synonym for [ksprintf]. *) diff --git a/stdlib/gc.ml b/stdlib/gc.ml new file mode 100644 index 0000000..4666d28 --- /dev/null +++ b/stdlib/gc.ml @@ -0,0 +1,101 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: gc.ml,v 1.21 2008-12-03 18:09:09 doligez Exp $ *) + +type stat = { + minor_words : float; + promoted_words : float; + major_words : float; + minor_collections : int; + major_collections : int; + heap_words : int; + heap_chunks : int; + live_words : int; + live_blocks : int; + free_words : int; + free_blocks : int; + largest_free : int; + fragments : int; + compactions : int; + top_heap_words : int; +};; + +type control = { + mutable minor_heap_size : int; + mutable major_heap_increment : int; + mutable space_overhead : int; + mutable verbose : int; + mutable max_overhead : int; + mutable stack_limit : int; + mutable allocation_policy : int; +};; + +external stat : unit -> stat = "caml_gc_stat";; +external quick_stat : unit -> stat = "caml_gc_quick_stat";; +external counters : unit -> (float * float * float) = "caml_gc_counters";; +external get : unit -> control = "caml_gc_get";; +external set : control -> unit = "caml_gc_set";; +external minor : unit -> unit = "caml_gc_minor";; +external major_slice : int -> int = "caml_gc_major_slice";; +external major : unit -> unit = "caml_gc_major";; +external full_major : unit -> unit = "caml_gc_full_major";; +external compact : unit -> unit = "caml_gc_compaction";; + +open Printf;; + +let print_stat c = + let st = stat () in + fprintf c "minor_words: %.0f\n" st.minor_words; + fprintf c "promoted_words: %.0f\n" st.promoted_words; + fprintf c "major_words: %.0f\n" st.major_words; + fprintf c "minor_collections: %d\n" st.minor_collections; + fprintf c "major_collections: %d\n" st.major_collections; + fprintf c "heap_words: %d\n" st.heap_words; + fprintf c "heap_chunks: %d\n" st.heap_chunks; + fprintf c "top_heap_words: %d\n" st.top_heap_words; + fprintf c "live_words: %d\n" st.live_words; + fprintf c "live_blocks: %d\n" st.live_blocks; + fprintf c "free_words: %d\n" st.free_words; + fprintf c "free_blocks: %d\n" st.free_blocks; + fprintf c "largest_free: %d\n" st.largest_free; + fprintf c "fragments: %d\n" st.fragments; + fprintf c "compactions: %d\n" st.compactions; +;; + +let allocated_bytes () = + let (mi, pro, ma) = counters () in + (mi +. ma -. pro) *. float_of_int (Sys.word_size / 8) +;; + +external finalise : ('a -> unit) -> 'a -> unit = "caml_final_register";; +external finalise_release : unit -> unit = "caml_final_release";; + + +type alarm = bool ref;; +type alarm_rec = {active : alarm; f : unit -> unit};; + +let rec call_alarm arec = + if !(arec.active) then begin + finalise call_alarm arec; + arec.f (); + end; +;; + +let create_alarm f = + let arec = { active = ref true; f = f } in + finalise call_alarm arec; + arec.active +;; + +let delete_alarm a = a := false;; diff --git a/stdlib/gc.mli b/stdlib/gc.mli new file mode 100644 index 0000000..221e186 --- /dev/null +++ b/stdlib/gc.mli @@ -0,0 +1,268 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: gc.mli,v 1.45 2008-12-03 18:09:09 doligez Exp $ *) + +(** Memory management control and statistics; finalised values. *) + +type stat = + { minor_words : float; + (** Number of words allocated in the minor heap since + the program was started. This number is accurate in + byte-code programs, but only an approximation in programs + compiled to native code. *) + + promoted_words : float; + (** Number of words allocated in the minor heap that + survived a minor collection and were moved to the major heap + since the program was started. *) + + major_words : float; + (** Number of words allocated in the major heap, including + the promoted words, since the program was started. *) + + minor_collections : int; + (** Number of minor collections since the program was started. *) + + major_collections : int; + (** Number of major collection cycles completed since the program + was started. *) + + heap_words : int; + (** Total size of the major heap, in words. *) + + heap_chunks : int; + (** Number of contiguous pieces of memory that make up the major heap. *) + + live_words : int; + (** Number of words of live data in the major heap, including the header + words. *) + + live_blocks : int; + (** Number of live blocks in the major heap. *) + + free_words : int; + (** Number of words in the free list. *) + + free_blocks : int; + (** Number of blocks in the free list. *) + + largest_free : int; + (** Size (in words) of the largest block in the free list. *) + + fragments : int; + (** Number of wasted words due to fragmentation. These are + 1-words free blocks placed between two live blocks. They + are not available for allocation. *) + + compactions : int; + (** Number of heap compactions since the program was started. *) + + top_heap_words : int; + (** Maximum size reached by the major heap, in words. *) +} +(** The memory management counters are returned in a [stat] record. + + The total amount of memory allocated by the program since it was started + is (in words) [minor_words + major_words - promoted_words]. Multiply by + the word size (4 on a 32-bit machine, 8 on a 64-bit machine) to get + the number of bytes. +*) + +type control = + { mutable minor_heap_size : int; + (** The size (in words) of the minor heap. Changing + this parameter will trigger a minor collection. Default: 32k. *) + + mutable major_heap_increment : int; + (** The minimum number of words to add to the + major heap when increasing it. Default: 124k. *) + + mutable space_overhead : int; + (** The major GC speed is computed from this parameter. + This is the memory that will be "wasted" because the GC does not + immediatly collect unreachable blocks. It is expressed as a + percentage of the memory used for live data. + The GC will work more (use more CPU time and collect + blocks more eagerly) if [space_overhead] is smaller. + Default: 80. *) + + mutable verbose : int; + (** This value controls the GC messages on standard error output. + It is a sum of some of the following flags, to print messages + on the corresponding events: + - [0x001] Start of major GC cycle. + - [0x002] Minor collection and major GC slice. + - [0x004] Growing and shrinking of the heap. + - [0x008] Resizing of stacks and memory manager tables. + - [0x010] Heap compaction. + - [0x020] Change of GC parameters. + - [0x040] Computation of major GC slice size. + - [0x080] Calling of finalisation functions. + - [0x100] Bytecode executable search at start-up. + - [0x200] Computation of compaction triggering condition. + Default: 0. *) + + mutable max_overhead : int; + (** Heap compaction is triggered when the estimated amount + of "wasted" memory is more than [max_overhead] percent of the + amount of live data. If [max_overhead] is set to 0, heap + compaction is triggered at the end of each major GC cycle + (this setting is intended for testing purposes only). + If [max_overhead >= 1000000], compaction is never triggered. + Default: 500. *) + + mutable stack_limit : int; + (** The maximum size of the stack (in words). This is only + relevant to the byte-code runtime, as the native code runtime + uses the operating system's stack. Default: 256k. *) + + mutable allocation_policy : int; + (** The policy used for allocating in the heap. Possible + values are 0 and 1. 0 is the next-fit policy, which is + quite fast but can result in fragmentation. 1 is the + first-fit policy, which can be slower in some cases but + can be better for programs with fragmentation problems. + Default: 0. *) +} +(** The GC parameters are given as a [control] record. Note that + these parameters can also be initialised by setting the + OCAMLRUNPARAM environment variable. See the documentation of + ocamlrun. *) + +external stat : unit -> stat = "caml_gc_stat" +(** Return the current values of the memory management counters in a + [stat] record. This function examines every heap block to get the + statistics. *) + +external quick_stat : unit -> stat = "caml_gc_quick_stat" +(** Same as [stat] except that [live_words], [live_blocks], [free_words], + [free_blocks], [largest_free], and [fragments] are set to 0. This + function is much faster than [stat] because it does not need to go + through the heap. *) + +external counters : unit -> float * float * float = "caml_gc_counters" +(** Return [(minor_words, promoted_words, major_words)]. This function + is as fast at [quick_stat]. *) + +external get : unit -> control = "caml_gc_get" +(** Return the current values of the GC parameters in a [control] record. *) + +external set : control -> unit = "caml_gc_set" +(** [set r] changes the GC parameters according to the [control] record [r]. + The normal usage is: [Gc.set { (Gc.get()) with Gc.verbose = 0x00d }] *) + +external minor : unit -> unit = "caml_gc_minor" +(** Trigger a minor collection. *) + +external major_slice : int -> int = "caml_gc_major_slice";; +(** Do a minor collection and a slice of major collection. The argument + is the size of the slice, 0 to use the automatically-computed + slice size. In all cases, the result is the computed slice size. *) + +external major : unit -> unit = "caml_gc_major" +(** Do a minor collection and finish the current major collection cycle. *) + +external full_major : unit -> unit = "caml_gc_full_major" +(** Do a minor collection, finish the current major collection cycle, + and perform a complete new cycle. This will collect all currently + unreachable blocks. *) + +external compact : unit -> unit = "caml_gc_compaction" +(** Perform a full major collection and compact the heap. Note that heap + compaction is a lengthy operation. *) + +val print_stat : out_channel -> unit +(** Print the current values of the memory management counters (in + human-readable form) into the channel argument. *) + +val allocated_bytes : unit -> float +(** Return the total number of bytes allocated since the program was + started. It is returned as a [float] to avoid overflow problems + with [int] on 32-bit machines. *) + +val finalise : ('a -> unit) -> 'a -> unit +(** [finalise f v] registers [f] as a finalisation function for [v]. + [v] must be heap-allocated. [f] will be called with [v] as + argument at some point between the first time [v] becomes unreachable + and the time [v] is collected by the GC. Several functions can + be registered for the same value, or even several instances of the + same function. Each instance will be called once (or never, + if the program terminates before [v] becomes unreachable). + + The GC will call the finalisation functions in the order of + deallocation. When several values become unreachable at the + same time (i.e. during the same GC cycle), the finalisation + functions will be called in the reverse order of the corresponding + calls to [finalise]. If [finalise] is called in the same order + as the values are allocated, that means each value is finalised + before the values it depends upon. Of course, this becomes + false if additional dependencies are introduced by assignments. + + Anything reachable from the closure of finalisation functions + is considered reachable, so the following code will not work + as expected: + - [ let v = ... in Gc.finalise (fun x -> ...) v ] + + Instead you should write: + - [ let f = fun x -> ... ;; let v = ... in Gc.finalise f v ] + + + The [f] function can use all features of O'Caml, including + assignments that make the value reachable again. It can also + loop forever (in this case, the other + finalisation functions will be called during the execution of f). + It can call [finalise] on [v] or other values to register other + functions or even itself. It can raise an exception; in this case + the exception will interrupt whatever the program was doing when + the function was called. + + + [finalise] will raise [Invalid_argument] if [v] is not + heap-allocated. Some examples of values that are not + heap-allocated are integers, constant constructors, booleans, + the empty array, the empty list, the unit value. The exact list + of what is heap-allocated or not is implementation-dependent. + Some constant values can be heap-allocated but never deallocated + during the lifetime of the program, for example a list of integer + constants; this is also implementation-dependent. + You should also be aware that compiler optimisations may duplicate + some immutable values, for example floating-point numbers when + stored into arrays, so they can be finalised and collected while + another copy is still in use by the program. + + + The results of calling {!String.make}, {!String.create}, + {!Array.make}, and {!Pervasives.ref} are guaranteed to be + heap-allocated and non-constant except when the length argument is [0]. +*) + +val finalise_release : unit -> unit;; +(** A finalisation function may call [finalise_release] to tell the + GC that it can launch the next finalisation function without waiting + for the current one to return. *) + +type alarm +(** An alarm is a piece of data that calls a user function at the end of + each major GC cycle. The following functions are provided to create + and delete alarms. *) + +val create_alarm : (unit -> unit) -> alarm +(** [create_alarm f] will arrange for [f] to be called at the end of each + major GC cycle, starting with the current cycle or the next one. + A value of type [alarm] is returned that you can + use to call [delete_alarm]. *) + +val delete_alarm : alarm -> unit +(** [delete_alarm a] will stop the calls to the function associated + to [a]. Calling [delete_alarm a] again has no effect. *) diff --git a/stdlib/genlex.ml b/stdlib/genlex.ml new file mode 100644 index 0000000..07fcb10 --- /dev/null +++ b/stdlib/genlex.ml @@ -0,0 +1,202 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: genlex.ml,v 1.9 2002-04-18 07:27:42 garrigue Exp $ *) + +type token = + Kwd of string + | Ident of string + | Int of int + | Float of float + | String of string + | Char of char + + +(* The string buffering machinery *) + +let initial_buffer = String.create 32 + +let buffer = ref initial_buffer +let bufpos = ref 0 + +let reset_buffer () = buffer := initial_buffer; bufpos := 0 + +let store c = + if !bufpos >= String.length !buffer then + begin + let newbuffer = String.create (2 * !bufpos) in + String.blit !buffer 0 newbuffer 0 !bufpos; buffer := newbuffer + end; + String.set !buffer !bufpos c; + incr bufpos + +let get_string () = + let s = String.sub !buffer 0 !bufpos in buffer := initial_buffer; s + +(* The lexer *) + +let make_lexer keywords = + let kwd_table = Hashtbl.create 17 in + List.iter (fun s -> Hashtbl.add kwd_table s (Kwd s)) keywords; + let ident_or_keyword id = + try Hashtbl.find kwd_table id with + Not_found -> Ident id + and keyword_or_error c = + let s = String.make 1 c in + try Hashtbl.find kwd_table s with + Not_found -> raise (Stream.Error ("Illegal character " ^ s)) + in + let rec next_token (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some (' ' | '\010' | '\013' | '\009' | '\026' | '\012') -> + Stream.junk strm__; next_token strm__ + | Some ('A'..'Z' | 'a'..'z' | '_' | '\192'..'\255' as c) -> + Stream.junk strm__; + let s = strm__ in reset_buffer (); store c; ident s + | Some + ('!' | '%' | '&' | '$' | '#' | '+' | '/' | ':' | '<' | '=' | '>' | + '?' | '@' | '\\' | '~' | '^' | '|' | '*' as c) -> + Stream.junk strm__; + let s = strm__ in reset_buffer (); store c; ident2 s + | Some ('0'..'9' as c) -> + Stream.junk strm__; + let s = strm__ in reset_buffer (); store c; number s + | Some '\'' -> + Stream.junk strm__; + let c = + try char strm__ with + Stream.Failure -> raise (Stream.Error "") + in + begin match Stream.peek strm__ with + Some '\'' -> Stream.junk strm__; Some (Char c) + | _ -> raise (Stream.Error "") + end + | Some '"' -> + Stream.junk strm__; + let s = strm__ in reset_buffer (); Some (String (string s)) + | Some '-' -> Stream.junk strm__; neg_number strm__ + | Some '(' -> Stream.junk strm__; maybe_comment strm__ + | Some c -> Stream.junk strm__; Some (keyword_or_error c) + | _ -> None + and ident (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some + ('A'..'Z' | 'a'..'z' | '\192'..'\255' | '0'..'9' | '_' | '\'' as c) -> + Stream.junk strm__; let s = strm__ in store c; ident s + | _ -> Some (ident_or_keyword (get_string ())) + and ident2 (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some + ('!' | '%' | '&' | '$' | '#' | '+' | '-' | '/' | ':' | '<' | '=' | + '>' | '?' | '@' | '\\' | '~' | '^' | '|' | '*' as c) -> + Stream.junk strm__; let s = strm__ in store c; ident2 s + | _ -> Some (ident_or_keyword (get_string ())) + and neg_number (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9' as c) -> + Stream.junk strm__; + let s = strm__ in reset_buffer (); store '-'; store c; number s + | _ -> let s = strm__ in reset_buffer (); store '-'; ident2 s + and number (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9' as c) -> + Stream.junk strm__; let s = strm__ in store c; number s + | Some '.' -> + Stream.junk strm__; let s = strm__ in store '.'; decimal_part s + | Some ('e' | 'E') -> + Stream.junk strm__; let s = strm__ in store 'E'; exponent_part s + | _ -> Some (Int (int_of_string (get_string ()))) + and decimal_part (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9' as c) -> + Stream.junk strm__; let s = strm__ in store c; decimal_part s + | Some ('e' | 'E') -> + Stream.junk strm__; let s = strm__ in store 'E'; exponent_part s + | _ -> Some (Float (float_of_string (get_string ()))) + and exponent_part (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('+' | '-' as c) -> + Stream.junk strm__; let s = strm__ in store c; end_exponent_part s + | _ -> end_exponent_part strm__ + and end_exponent_part (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9' as c) -> + Stream.junk strm__; let s = strm__ in store c; end_exponent_part s + | _ -> Some (Float (float_of_string (get_string ()))) + and string (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '"' -> Stream.junk strm__; get_string () + | Some '\\' -> + Stream.junk strm__; + let c = + try escape strm__ with + Stream.Failure -> raise (Stream.Error "") + in + let s = strm__ in store c; string s + | Some c -> Stream.junk strm__; let s = strm__ in store c; string s + | _ -> raise Stream.Failure + and char (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '\\' -> + Stream.junk strm__; + begin try escape strm__ with + Stream.Failure -> raise (Stream.Error "") + end + | Some c -> Stream.junk strm__; c + | _ -> raise Stream.Failure + and escape (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some 'n' -> Stream.junk strm__; '\n' + | Some 'r' -> Stream.junk strm__; '\r' + | Some 't' -> Stream.junk strm__; '\t' + | Some ('0'..'9' as c1) -> + Stream.junk strm__; + begin match Stream.peek strm__ with + Some ('0'..'9' as c2) -> + Stream.junk strm__; + begin match Stream.peek strm__ with + Some ('0'..'9' as c3) -> + Stream.junk strm__; + Char.chr + ((Char.code c1 - 48) * 100 + (Char.code c2 - 48) * 10 + + (Char.code c3 - 48)) + | _ -> raise (Stream.Error "") + end + | _ -> raise (Stream.Error "") + end + | Some c -> Stream.junk strm__; c + | _ -> raise Stream.Failure + and maybe_comment (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '*' -> + Stream.junk strm__; let s = strm__ in comment s; next_token s + | _ -> Some (keyword_or_error '(') + and comment (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '(' -> Stream.junk strm__; maybe_nested_comment strm__ + | Some '*' -> Stream.junk strm__; maybe_end_comment strm__ + | Some c -> Stream.junk strm__; comment strm__ + | _ -> raise Stream.Failure + and maybe_nested_comment (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '*' -> Stream.junk strm__; let s = strm__ in comment s; comment s + | Some c -> Stream.junk strm__; comment strm__ + | _ -> raise Stream.Failure + and maybe_end_comment (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ')' -> Stream.junk strm__; () + | Some '*' -> Stream.junk strm__; maybe_end_comment strm__ + | Some c -> Stream.junk strm__; comment strm__ + | _ -> raise Stream.Failure + in + fun input -> Stream.from (fun count -> next_token input) diff --git a/stdlib/genlex.mli b/stdlib/genlex.mli new file mode 100644 index 0000000..7368ce3 --- /dev/null +++ b/stdlib/genlex.mli @@ -0,0 +1,66 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: genlex.mli,v 1.9 2005-10-25 18:34:07 doligez Exp $ *) + +(** A generic lexical analyzer. + + + This module implements a simple ``standard'' lexical analyzer, presented + as a function from character streams to token streams. It implements + roughly the lexical conventions of Caml, but is parameterized by the + set of keywords of your language. + + + Example: a lexer suitable for a desk calculator is obtained by + {[ let lexer = make_lexer ["+";"-";"*";"/";"let";"="; "("; ")"] ]} + + The associated parser would be a function from [token stream] + to, for instance, [int], and would have rules such as: + + {[ + let parse_expr = parser + [< 'Int n >] -> n + | [< 'Kwd "("; n = parse_expr; 'Kwd ")" >] -> n + | [< n1 = parse_expr; n2 = parse_remainder n1 >] -> n2 + and parse_remainder n1 = parser + [< 'Kwd "+"; n2 = parse_expr >] -> n1+n2 + | ... + ]} +*) + +(** The type of tokens. The lexical classes are: [Int] and [Float] + for integer and floating-point numbers; [String] for + string literals, enclosed in double quotes; [Char] for + character literals, enclosed in single quotes; [Ident] for + identifiers (either sequences of letters, digits, underscores + and quotes, or sequences of ``operator characters'' such as + [+], [*], etc); and [Kwd] for keywords (either identifiers or + single ``special characters'' such as [(], [}], etc). *) +type token = + Kwd of string + | Ident of string + | Int of int + | Float of float + | String of string + | Char of char + +val make_lexer : string list -> char Stream.t -> token Stream.t +(** Construct the lexer function. The first argument is the list of + keywords. An identifier [s] is returned as [Kwd s] if [s] + belongs to this list, and as [Ident s] otherwise. + A special character [s] is returned as [Kwd s] if [s] + belongs to this list, and cause a lexical error (exception + [Parse_error]) otherwise. Blanks and newlines are skipped. + Comments delimited by [(*] and [*)] are skipped as well, + and can be nested. *) diff --git a/stdlib/hashtbl.ml b/stdlib/hashtbl.ml new file mode 100644 index 0000000..72f23bc --- /dev/null +++ b/stdlib/hashtbl.ml @@ -0,0 +1,279 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: hashtbl.ml,v 1.27 2005-10-25 18:34:07 doligez Exp $ *) + +(* Hash tables *) + +external hash_param : int -> int -> 'a -> int = "caml_hash_univ_param" "noalloc" + +let hash x = hash_param 10 100 x + +(* We do dynamic hashing, and resize the table and rehash the elements + when buckets become too long. *) + +type ('a, 'b) t = + { mutable size: int; (* number of elements *) + mutable data: ('a, 'b) bucketlist array } (* the buckets *) + +and ('a, 'b) bucketlist = + Empty + | Cons of 'a * 'b * ('a, 'b) bucketlist + +let create initial_size = + let s = min (max 1 initial_size) Sys.max_array_length in + { size = 0; data = Array.make s Empty } + +let clear h = + for i = 0 to Array.length h.data - 1 do + h.data.(i) <- Empty + done; + h.size <- 0 + +let copy h = + { size = h.size; + data = Array.copy h.data } + +let length h = h.size + +let resize hashfun tbl = + let odata = tbl.data in + let osize = Array.length odata in + let nsize = min (2 * osize + 1) Sys.max_array_length in + if nsize <> osize then begin + let ndata = Array.create nsize Empty in + let rec insert_bucket = function + Empty -> () + | Cons(key, data, rest) -> + insert_bucket rest; (* preserve original order of elements *) + let nidx = (hashfun key) mod nsize in + ndata.(nidx) <- Cons(key, data, ndata.(nidx)) in + for i = 0 to osize - 1 do + insert_bucket odata.(i) + done; + tbl.data <- ndata; + end + +let add h key info = + let i = (hash key) mod (Array.length h.data) in + let bucket = Cons(key, info, h.data.(i)) in + h.data.(i) <- bucket; + h.size <- succ h.size; + if h.size > Array.length h.data lsl 1 then resize hash h + +let remove h key = + let rec remove_bucket = function + Empty -> + Empty + | Cons(k, i, next) -> + if compare k key = 0 + then begin h.size <- pred h.size; next end + else Cons(k, i, remove_bucket next) in + let i = (hash key) mod (Array.length h.data) in + h.data.(i) <- remove_bucket h.data.(i) + +let rec find_rec key = function + Empty -> + raise Not_found + | Cons(k, d, rest) -> + if compare key k = 0 then d else find_rec key rest + +let find h key = + match h.data.((hash key) mod (Array.length h.data)) with + Empty -> raise Not_found + | Cons(k1, d1, rest1) -> + if compare key k1 = 0 then d1 else + match rest1 with + Empty -> raise Not_found + | Cons(k2, d2, rest2) -> + if compare key k2 = 0 then d2 else + match rest2 with + Empty -> raise Not_found + | Cons(k3, d3, rest3) -> + if compare key k3 = 0 then d3 else find_rec key rest3 + +let find_all h key = + let rec find_in_bucket = function + Empty -> + [] + | Cons(k, d, rest) -> + if compare k key = 0 + then d :: find_in_bucket rest + else find_in_bucket rest in + find_in_bucket h.data.((hash key) mod (Array.length h.data)) + +let replace h key info = + let rec replace_bucket = function + Empty -> + raise Not_found + | Cons(k, i, next) -> + if compare k key = 0 + then Cons(k, info, next) + else Cons(k, i, replace_bucket next) in + let i = (hash key) mod (Array.length h.data) in + let l = h.data.(i) in + try + h.data.(i) <- replace_bucket l + with Not_found -> + h.data.(i) <- Cons(key, info, l); + h.size <- succ h.size; + if h.size > Array.length h.data lsl 1 then resize hash h + +let mem h key = + let rec mem_in_bucket = function + | Empty -> + false + | Cons(k, d, rest) -> + compare k key = 0 || mem_in_bucket rest in + mem_in_bucket h.data.((hash key) mod (Array.length h.data)) + +let iter f h = + let rec do_bucket = function + Empty -> + () + | Cons(k, d, rest) -> + f k d; do_bucket rest in + let d = h.data in + for i = 0 to Array.length d - 1 do + do_bucket d.(i) + done + +let fold f h init = + let rec do_bucket b accu = + match b with + Empty -> + accu + | Cons(k, d, rest) -> + do_bucket rest (f k d accu) in + let d = h.data in + let accu = ref init in + for i = 0 to Array.length d - 1 do + accu := do_bucket d.(i) !accu + done; + !accu + +(* Functorial interface *) + +module type HashedType = + sig + type t + val equal: t -> t -> bool + val hash: t -> int + end + +module type S = + sig + type key + type 'a t + val create: int -> 'a t + val clear: 'a t -> unit + val copy: 'a t -> 'a t + val add: 'a t -> key -> 'a -> unit + val remove: 'a t -> key -> unit + val find: 'a t -> key -> 'a + val find_all: 'a t -> key -> 'a list + val replace : 'a t -> key -> 'a -> unit + val mem : 'a t -> key -> bool + val iter: (key -> 'a -> unit) -> 'a t -> unit + val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b + val length: 'a t -> int + end + +module Make(H: HashedType): (S with type key = H.t) = + struct + type key = H.t + type 'a hashtbl = (key, 'a) t + type 'a t = 'a hashtbl + let create = create + let clear = clear + let copy = copy + + let safehash key = (H.hash key) land max_int + + let add h key info = + let i = (safehash key) mod (Array.length h.data) in + let bucket = Cons(key, info, h.data.(i)) in + h.data.(i) <- bucket; + h.size <- succ h.size; + if h.size > Array.length h.data lsl 1 then resize safehash h + + let remove h key = + let rec remove_bucket = function + Empty -> + Empty + | Cons(k, i, next) -> + if H.equal k key + then begin h.size <- pred h.size; next end + else Cons(k, i, remove_bucket next) in + let i = (safehash key) mod (Array.length h.data) in + h.data.(i) <- remove_bucket h.data.(i) + + let rec find_rec key = function + Empty -> + raise Not_found + | Cons(k, d, rest) -> + if H.equal key k then d else find_rec key rest + + let find h key = + match h.data.((safehash key) mod (Array.length h.data)) with + Empty -> raise Not_found + | Cons(k1, d1, rest1) -> + if H.equal key k1 then d1 else + match rest1 with + Empty -> raise Not_found + | Cons(k2, d2, rest2) -> + if H.equal key k2 then d2 else + match rest2 with + Empty -> raise Not_found + | Cons(k3, d3, rest3) -> + if H.equal key k3 then d3 else find_rec key rest3 + + let find_all h key = + let rec find_in_bucket = function + Empty -> + [] + | Cons(k, d, rest) -> + if H.equal k key + then d :: find_in_bucket rest + else find_in_bucket rest in + find_in_bucket h.data.((safehash key) mod (Array.length h.data)) + + let replace h key info = + let rec replace_bucket = function + Empty -> + raise Not_found + | Cons(k, i, next) -> + if H.equal k key + then Cons(k, info, next) + else Cons(k, i, replace_bucket next) in + let i = (safehash key) mod (Array.length h.data) in + let l = h.data.(i) in + try + h.data.(i) <- replace_bucket l + with Not_found -> + h.data.(i) <- Cons(key, info, l); + h.size <- succ h.size; + if h.size > Array.length h.data lsl 1 then resize safehash h + + let mem h key = + let rec mem_in_bucket = function + | Empty -> + false + | Cons(k, d, rest) -> + H.equal k key || mem_in_bucket rest in + mem_in_bucket h.data.((safehash key) mod (Array.length h.data)) + + let iter = iter + let fold = fold + let length = length + end diff --git a/stdlib/hashtbl.mli b/stdlib/hashtbl.mli new file mode 100644 index 0000000..2ffd243 --- /dev/null +++ b/stdlib/hashtbl.mli @@ -0,0 +1,177 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: hashtbl.mli,v 1.39 2005-05-04 13:36:47 doligez Exp $ *) + +(** Hash tables and hash functions. + + Hash tables are hashed association tables, with in-place modification. +*) + + +(** {6 Generic interface} *) + + +type ('a, 'b) t +(** The type of hash tables from type ['a] to type ['b]. *) + +val create : int -> ('a, 'b) t +(** [Hashtbl.create n] creates a new, empty hash table, with + initial size [n]. For best results, [n] should be on the + order of the expected number of elements that will be in + the table. The table grows as needed, so [n] is just an + initial guess. *) + +val clear : ('a, 'b) t -> unit +(** Empty a hash table. *) + + +val add : ('a, 'b) t -> 'a -> 'b -> unit +(** [Hashtbl.add tbl x y] adds a binding of [x] to [y] in table [tbl]. + Previous bindings for [x] are not removed, but simply + hidden. That is, after performing {!Hashtbl.remove}[ tbl x], + the previous binding for [x], if any, is restored. + (Same behavior as with association lists.) *) + +val copy : ('a, 'b) t -> ('a, 'b) t +(** Return a copy of the given hashtable. *) + +val find : ('a, 'b) t -> 'a -> 'b +(** [Hashtbl.find tbl x] returns the current binding of [x] in [tbl], + or raises [Not_found] if no such binding exists. *) + +val find_all : ('a, 'b) t -> 'a -> 'b list +(** [Hashtbl.find_all tbl x] returns the list of all data + associated with [x] in [tbl]. + The current binding is returned first, then the previous + bindings, in reverse order of introduction in the table. *) + +val mem : ('a, 'b) t -> 'a -> bool +(** [Hashtbl.mem tbl x] checks if [x] is bound in [tbl]. *) + +val remove : ('a, 'b) t -> 'a -> unit +(** [Hashtbl.remove tbl x] removes the current binding of [x] in [tbl], + restoring the previous binding if it exists. + It does nothing if [x] is not bound in [tbl]. *) + +val replace : ('a, 'b) t -> 'a -> 'b -> unit +(** [Hashtbl.replace tbl x y] replaces the current binding of [x] + in [tbl] by a binding of [x] to [y]. If [x] is unbound in [tbl], + a binding of [x] to [y] is added to [tbl]. + This is functionally equivalent to {!Hashtbl.remove}[ tbl x] + followed by {!Hashtbl.add}[ tbl x y]. *) + +val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit +(** [Hashtbl.iter f tbl] applies [f] to all bindings in table [tbl]. + [f] receives the key as first argument, and the associated value + as second argument. Each binding is presented exactly once to [f]. + The order in which the bindings are passed to [f] is unspecified. + However, if the table contains several bindings for the same key, + they are passed to [f] in reverse order of introduction, that is, + the most recent binding is passed first. *) + +val fold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c +(** [Hashtbl.fold f tbl init] computes + [(f kN dN ... (f k1 d1 init)...)], + where [k1 ... kN] are the keys of all bindings in [tbl], + and [d1 ... dN] are the associated values. + Each binding is presented exactly once to [f]. + The order in which the bindings are passed to [f] is unspecified. + However, if the table contains several bindings for the same key, + they are passed to [f] in reverse order of introduction, that is, + the most recent binding is passed first. *) + + +val length : ('a, 'b) t -> int +(** [Hashtbl.length tbl] returns the number of bindings in [tbl]. + Multiple bindings are counted multiply, so [Hashtbl.length] + gives the number of times [Hashtbl.iter] calls its first argument. *) + + +(** {6 Functorial interface} *) + + +module type HashedType = + sig + type t + (** The type of the hashtable keys. *) + val equal : t -> t -> bool + (** The equality predicate used to compare keys. *) + val hash : t -> int + (** A hashing function on keys. It must be such that if two keys are + equal according to [equal], then they have identical hash values + as computed by [hash]. + Examples: suitable ([equal], [hash]) pairs for arbitrary key + types include + ([(=)], {!Hashtbl.hash}) for comparing objects by structure, + ([(fun x y -> compare x y = 0)], {!Hashtbl.hash}) + for comparing objects by structure and handling {!Pervasives.nan} + correctly, and + ([(==)], {!Hashtbl.hash}) for comparing objects by addresses + (e.g. for cyclic keys). *) + end +(** The input signature of the functor {!Hashtbl.Make}. *) + +module type S = + sig + type key + type 'a t + val create : int -> 'a t + val clear : 'a t -> unit + val copy : 'a t -> 'a t + val add : 'a t -> key -> 'a -> unit + val remove : 'a t -> key -> unit + val find : 'a t -> key -> 'a + val find_all : 'a t -> key -> 'a list + val replace : 'a t -> key -> 'a -> unit + val mem : 'a t -> key -> bool + val iter : (key -> 'a -> unit) -> 'a t -> unit + val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b + val length : 'a t -> int + end +(** The output signature of the functor {!Hashtbl.Make}. *) + +module Make (H : HashedType) : S with type key = H.t +(** Functor building an implementation of the hashtable structure. + The functor [Hashtbl.Make] returns a structure containing + a type [key] of keys and a type ['a t] of hash tables + associating data of type ['a] to keys of type [key]. + The operations perform similarly to those of the generic + interface, but use the hashing and equality functions + specified in the functor argument [H] instead of generic + equality and hashing. *) + + +(** {6 The polymorphic hash primitive} *) + + +val hash : 'a -> int +(** [Hashtbl.hash x] associates a positive integer to any value of + any type. It is guaranteed that + if [x = y] or [Pervasives.compare x y = 0], then [hash x = hash y]. + Moreover, [hash] always terminates, even on cyclic + structures. *) + +external hash_param : int -> int -> 'a -> int = "caml_hash_univ_param" "noalloc" +(** [Hashtbl.hash_param n m x] computes a hash value for [x], with the + same properties as for [hash]. The two extra parameters [n] and + [m] give more precise control over hashing. Hashing performs a + depth-first, right-to-left traversal of the structure [x], stopping + after [n] meaningful nodes were encountered, or [m] nodes, + meaningful or not, were encountered. Meaningful nodes are: integers; + floating-point numbers; strings; characters; booleans; and constant + constructors. Larger values of [m] and [n] means that more + nodes are taken into account to compute the final hash + value, and therefore collisions are less likely to happen. + However, hashing takes longer. The parameters [m] and [n] + govern the tradeoff between accuracy and speed. *) diff --git a/stdlib/header.c b/stdlib/header.c new file mode 100644 index 0000000..0dc307e --- /dev/null +++ b/stdlib/header.c @@ -0,0 +1,191 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: header.c,v 1.17 2001-12-07 13:40:52 xleroy Exp $ */ + +/* The launcher for bytecode executables (if #! is not working) */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "../config/s.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "../byterun/mlvalues.h" +#include "../byterun/exec.h" + +char * default_runtime_path = RUNTIME_NAME; + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef __CYGWIN32__ + +/* Normal Unix search path function */ + +static char * searchpath(char * name) +{ + static char fullname[MAXPATHLEN + 1]; + char * path; + char * p; + char * q; + struct stat st; + + for (p = name; *p != 0; p++) { + if (*p == '/') return name; + } + path = getenv("PATH"); + if (path == NULL) return name; + while(1) { + for (p = fullname; *path != 0 && *path != ':'; p++, path++) + if (p < fullname + MAXPATHLEN) *p = *path; + if (p != fullname && p < fullname + MAXPATHLEN) + *p++ = '/'; + for (q = name; *q != 0; p++, q++) + if (p < fullname + MAXPATHLEN) *p = *q; + *p = 0; + if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) break; + if (*path == 0) return name; + path++; + } + return fullname; +} + +#else + +/* Special version for Cygwin32: takes care of the ".exe" implicit suffix */ + +static int file_ok(char * name) +{ + int fd; + /* Cannot use stat() here because it adds ".exe" implicitly */ + fd = open(name, O_RDONLY); + if (fd == -1) return 0; + close(fd); + return 1; +} + +static char * searchpath(char * name) +{ + char * path, * fullname, * p; + + path = getenv("PATH"); + fullname = malloc(strlen(name) + (path == NULL ? 0 : strlen(path)) + 6); + /* 6 = "/" plus ".exe" plus final "\0" */ + if (fullname == NULL) return name; + /* Check for absolute path name */ + for (p = name; *p != 0; p++) { + if (*p == '/' || *p == '\\') { + if (file_ok(name)) return name; + strcpy(fullname, name); + strcat(fullname, ".exe"); + if (file_ok(fullname)) return fullname; + return name; + } + } + /* Search in path */ + if (path == NULL) return name; + while(1) { + for (p = fullname; *path != 0 && *path != ':'; p++, path++) *p = *path; + if (p != fullname) *p++ = '/'; + strcpy(p, name); + if (file_ok(fullname)) return fullname; + strcat(fullname, ".exe"); + if (file_ok(fullname)) return fullname; + if (*path == 0) break; + path++; + } + return name; +} + +#endif + +static unsigned long read_size(char * ptr) +{ + unsigned char * p = (unsigned char *) ptr; + return ((unsigned long) p[0] << 24) + ((unsigned long) p[1] << 16) + + ((unsigned long) p[2] << 8) + p[3]; +} + +static char * read_runtime_path(int fd) +{ + char buffer[TRAILER_SIZE]; + static char runtime_path[MAXPATHLEN]; + int num_sections, i; + uint32 path_size; + long ofs; + + lseek(fd, (long) -TRAILER_SIZE, SEEK_END); + if (read(fd, buffer, TRAILER_SIZE) < TRAILER_SIZE) return NULL; + num_sections = read_size(buffer); + ofs = TRAILER_SIZE + num_sections * 8; + lseek(fd, -ofs, SEEK_END); + path_size = 0; + for (i = 0; i < num_sections; i++) { + if (read(fd, buffer, 8) < 8) return NULL; + if (buffer[0] == 'R' && buffer[1] == 'N' && + buffer[2] == 'T' && buffer[3] == 'M') { + path_size = read_size(buffer + 4); + ofs += path_size; + } else if (path_size > 0) + ofs += read_size(buffer + 4); + } + if (path_size == 0) return default_runtime_path; + if (path_size >= MAXPATHLEN) return NULL; + lseek(fd, -ofs, SEEK_END); + if (read(fd, runtime_path, path_size) != path_size) return NULL; + runtime_path[path_size - 1] = 0; + return runtime_path; +} + +static void errwrite(char * msg) +{ + write(2, msg, strlen(msg)); +} + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +int main(int argc, char ** argv) +{ + char * truename, * runtime_path; + int fd; + + truename = searchpath(argv[0]); + fd = open(truename, O_RDONLY | O_BINARY); + if (fd == -1 || (runtime_path = read_runtime_path(fd)) == NULL) { + errwrite(truename); + errwrite(" not found or is not a bytecode executable file\n"); + return 2; + } + argv[0] = truename; + execv(runtime_path, argv); + errwrite("Cannot exec "); + errwrite(runtime_path); + errwrite("\n"); + return 2; +} diff --git a/stdlib/headernt.c b/stdlib/headernt.c new file mode 100644 index 0000000..d2aef6a --- /dev/null +++ b/stdlib/headernt.c @@ -0,0 +1,175 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: headernt.c,v 1.20 2007-02-07 10:31:36 ertai Exp $ */ + +#define STRICT +#define WIN32_LEAN_AND_MEAN + +#include <windows.h> +#include "mlvalues.h" +#include "exec.h" + +#ifndef __MINGW32__ +#pragma comment(linker , "/entry:headerentry") +#pragma comment(linker , "/subsystem:console") +#pragma comment(lib , "kernel32") +#endif + +char * default_runtime_name = "ocamlrun"; + +static +#if _MSC_VER >= 1200 +__forceinline +#else +__inline +#endif +unsigned long read_size(const char * const ptr) +{ + const unsigned char * const p = (const unsigned char * const) ptr; + return ((unsigned long) p[0] << 24) | ((unsigned long) p[1] << 16) | + ((unsigned long) p[2] << 8) | p[3]; +} + +static __inline char * read_runtime_path(HANDLE h) +{ + char buffer[TRAILER_SIZE]; + static char runtime_path[MAX_PATH]; + DWORD nread; + int num_sections, path_size, i; + long ofs; + + if (SetFilePointer(h, -TRAILER_SIZE, NULL, FILE_END) == -1) return NULL; + if (! ReadFile(h, buffer, TRAILER_SIZE, &nread, NULL)) return NULL; + if (nread != TRAILER_SIZE) return NULL; + num_sections = read_size(buffer); + ofs = TRAILER_SIZE + num_sections * 8; + if (SetFilePointer(h, - ofs, NULL, FILE_END) == -1) return NULL; + path_size = 0; + for (i = 0; i < num_sections; i++) { + if (! ReadFile(h, buffer, 8, &nread, NULL) || nread != 8) return NULL; + if (buffer[0] == 'R' && buffer[1] == 'N' && + buffer[2] == 'T' && buffer[3] == 'M') { + path_size = read_size(buffer + 4); + ofs += path_size; + } else if (path_size > 0) + ofs += read_size(buffer + 4); + } + if (path_size == 0) return default_runtime_name; + if (path_size >= MAX_PATH) return NULL; + if (SetFilePointer(h, -ofs, NULL, FILE_END) == -1) return NULL; + if (! ReadFile(h, runtime_path, path_size, &nread, NULL)) return NULL; + if (nread != path_size) return NULL; + runtime_path[path_size - 1] = 0; + return runtime_path; +} + +static BOOL WINAPI ctrl_handler(DWORD event) +{ + if (event == CTRL_C_EVENT || event == CTRL_BREAK_EVENT) + return TRUE; /* pretend we've handled them */ + else + return FALSE; +} + +#define msg_and_length(msg) msg , (sizeof(msg) - 1) + +static __inline void __declspec(noreturn) run_runtime(char * runtime, + char * const cmdline) +{ + char path[MAX_PATH]; + STARTUPINFO stinfo; + PROCESS_INFORMATION procinfo; + DWORD retcode; + if (SearchPath(NULL, runtime, ".exe", MAX_PATH, path, &runtime) == 0) { + HANDLE errh; + DWORD numwritten; + errh = GetStdHandle(STD_ERROR_HANDLE); + WriteFile(errh, msg_and_length("Cannot exec "), &numwritten, NULL); + WriteFile(errh, runtime, strlen(runtime), &numwritten, NULL); + WriteFile(errh, msg_and_length("\r\n"), &numwritten, NULL); + ExitProcess(2); +#if _MSC_VER >= 1200 + __assume(0); /* Not reached */ +#endif + } + /* Need to ignore ctrl-C and ctrl-break, otherwise we'll die and take + the underlying OCaml program with us! */ + SetConsoleCtrlHandler(ctrl_handler, TRUE); + + stinfo.cb = sizeof(stinfo); + stinfo.lpReserved = NULL; + stinfo.lpDesktop = NULL; + stinfo.lpTitle = NULL; + stinfo.dwFlags = 0; + stinfo.cbReserved2 = 0; + stinfo.lpReserved2 = NULL; + if (!CreateProcess(path, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, + &stinfo, &procinfo)) { + HANDLE errh; + DWORD numwritten; + errh = GetStdHandle(STD_ERROR_HANDLE); + WriteFile(errh, msg_and_length("Cannot exec "), &numwritten, NULL); + WriteFile(errh, runtime, strlen(runtime), &numwritten, NULL); + WriteFile(errh, msg_and_length("\r\n"), &numwritten, NULL); + ExitProcess(2); +#if _MSC_VER >= 1200 + __assume(0); /* Not reached */ +#endif + } + CloseHandle(procinfo.hThread); + WaitForSingleObject(procinfo.hProcess , INFINITE); + GetExitCodeProcess(procinfo.hProcess , &retcode); + CloseHandle(procinfo.hProcess); + ExitProcess(retcode); +#if _MSC_VER >= 1200 + __assume(0); /* Not reached */ +#endif +} + +#ifdef __MINGW32__ +int main() +#else +void __declspec(noreturn) __cdecl headerentry() +#endif +{ + char truename[MAX_PATH]; + char * cmdline = GetCommandLine(); + char * runtime_path; + HANDLE h; + + GetModuleFileName(NULL, truename, sizeof(truename)); + h = CreateFile(truename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (h == INVALID_HANDLE_VALUE || + (runtime_path = read_runtime_path(h)) == NULL) { + HANDLE errh; + DWORD numwritten; + errh = GetStdHandle(STD_ERROR_HANDLE); + WriteFile(errh, truename, strlen(truename), &numwritten, NULL); + WriteFile(errh, msg_and_length(" not found or is not a bytecode executable file\r\n"), + &numwritten, NULL); + ExitProcess(2); +#if _MSC_VER >= 1200 + __assume(0); /* Not reached */ +#endif + } + CloseHandle(h); + run_runtime(runtime_path , cmdline); +#if _MSC_VER >= 1200 + __assume(0); /* Not reached */ +#endif +#ifdef __MINGW32__ + return 0; +#endif +} diff --git a/stdlib/int32.ml b/stdlib/int32.ml new file mode 100644 index 0000000..c7118f7 --- /dev/null +++ b/stdlib/int32.ml @@ -0,0 +1,54 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int32.ml,v 1.10 2007-01-30 09:34:36 xleroy Exp $ *) + +(* Module [Int32]: 32-bit integers *) + +external neg : int32 -> int32 = "%int32_neg" +external add : int32 -> int32 -> int32 = "%int32_add" +external sub : int32 -> int32 -> int32 = "%int32_sub" +external mul : int32 -> int32 -> int32 = "%int32_mul" +external div : int32 -> int32 -> int32 = "%int32_div" +external rem : int32 -> int32 -> int32 = "%int32_mod" +external logand : int32 -> int32 -> int32 = "%int32_and" +external logor : int32 -> int32 -> int32 = "%int32_or" +external logxor : int32 -> int32 -> int32 = "%int32_xor" +external shift_left : int32 -> int -> int32 = "%int32_lsl" +external shift_right : int32 -> int -> int32 = "%int32_asr" +external shift_right_logical : int32 -> int -> int32 = "%int32_lsr" +external of_int : int -> int32 = "%int32_of_int" +external to_int : int32 -> int = "%int32_to_int" +external of_float : float -> int32 = "caml_int32_of_float" +external to_float : int32 -> float = "caml_int32_to_float" +external bits_of_float : float -> int32 = "caml_int32_bits_of_float" +external float_of_bits : int32 -> float = "caml_int32_float_of_bits" + +let zero = 0l +let one = 1l +let minus_one = -1l +let succ n = add n 1l +let pred n = sub n 1l +let abs n = if n >= 0l then n else neg n +let min_int = 0x80000000l +let max_int = 0x7FFFFFFFl +let lognot n = logxor n (-1l) + +external format : string -> int32 -> string = "caml_int32_format" +let to_string n = format "%d" n + +external of_string : string -> int32 = "caml_int32_of_string" + +type t = int32 + +let compare (x: t) (y: t) = Pervasives.compare x y diff --git a/stdlib/int32.mli b/stdlib/int32.mli new file mode 100644 index 0000000..a543cef --- /dev/null +++ b/stdlib/int32.mli @@ -0,0 +1,164 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int32.mli,v 1.19 2008-01-11 16:13:16 doligez Exp $ *) + +(** 32-bit integers. + + This module provides operations on the type [int32] + of signed 32-bit integers. Unlike the built-in [int] type, + the type [int32] is guaranteed to be exactly 32-bit wide on all + platforms. All arithmetic operations over [int32] are taken + modulo 2{^32}. + + Performance notice: values of type [int32] occupy more memory + space than values of type [int], and arithmetic operations on + [int32] are generally slower than those on [int]. Use [int32] + only when the application requires exact 32-bit arithmetic. *) + +val zero : int32 +(** The 32-bit integer 0. *) + +val one : int32 +(** The 32-bit integer 1. *) + +val minus_one : int32 +(** The 32-bit integer -1. *) + +external neg : int32 -> int32 = "%int32_neg" +(** Unary negation. *) + +external add : int32 -> int32 -> int32 = "%int32_add" +(** Addition. *) + +external sub : int32 -> int32 -> int32 = "%int32_sub" +(** Subtraction. *) + +external mul : int32 -> int32 -> int32 = "%int32_mul" +(** Multiplication. *) + +external div : int32 -> int32 -> int32 = "%int32_div" +(** Integer division. Raise [Division_by_zero] if the second + argument is zero. This division rounds the real quotient of + its arguments towards zero, as specified for {!Pervasives.(/)}. *) + +external rem : int32 -> int32 -> int32 = "%int32_mod" +(** Integer remainder. If [y] is not zero, the result + of [Int32.rem x y] satisfies the following property: + [x = Int32.add (Int32.mul (Int32.div x y) y) (Int32.rem x y)]. + If [y = 0], [Int32.rem x y] raises [Division_by_zero]. *) + +val succ : int32 -> int32 +(** Successor. [Int32.succ x] is [Int32.add x Int32.one]. *) + +val pred : int32 -> int32 +(** Predecessor. [Int32.pred x] is [Int32.sub x Int32.one]. *) + +val abs : int32 -> int32 +(** Return the absolute value of its argument. *) + +val max_int : int32 +(** The greatest representable 32-bit integer, 2{^31} - 1. *) + +val min_int : int32 +(** The smallest representable 32-bit integer, -2{^31}. *) + + +external logand : int32 -> int32 -> int32 = "%int32_and" +(** Bitwise logical and. *) + +external logor : int32 -> int32 -> int32 = "%int32_or" +(** Bitwise logical or. *) + +external logxor : int32 -> int32 -> int32 = "%int32_xor" +(** Bitwise logical exclusive or. *) + +val lognot : int32 -> int32 +(** Bitwise logical negation *) + +external shift_left : int32 -> int -> int32 = "%int32_lsl" +(** [Int32.shift_left x y] shifts [x] to the left by [y] bits. + The result is unspecified if [y < 0] or [y >= 32]. *) + +external shift_right : int32 -> int -> int32 = "%int32_asr" +(** [Int32.shift_right x y] shifts [x] to the right by [y] bits. + This is an arithmetic shift: the sign bit of [x] is replicated + and inserted in the vacated bits. + The result is unspecified if [y < 0] or [y >= 32]. *) + +external shift_right_logical : int32 -> int -> int32 = "%int32_lsr" +(** [Int32.shift_right_logical x y] shifts [x] to the right by [y] bits. + This is a logical shift: zeroes are inserted in the vacated bits + regardless of the sign of [x]. + The result is unspecified if [y < 0] or [y >= 32]. *) + +external of_int : int -> int32 = "%int32_of_int" +(** Convert the given integer (type [int]) to a 32-bit integer + (type [int32]). *) + +external to_int : int32 -> int = "%int32_to_int" +(** Convert the given 32-bit integer (type [int32]) to an + integer (type [int]). On 32-bit platforms, the 32-bit integer + is taken modulo 2{^31}, i.e. the high-order bit is lost + during the conversion. On 64-bit platforms, the conversion + is exact. *) + +external of_float : float -> int32 = "caml_int32_of_float" +(** Convert the given floating-point number to a 32-bit integer, + discarding the fractional part (truncate towards 0). + The result of the conversion is undefined if, after truncation, + the number is outside the range \[{!Int32.min_int}, {!Int32.max_int}\]. *) + +external to_float : int32 -> float = "caml_int32_to_float" +(** Convert the given 32-bit integer to a floating-point number. *) + +external of_string : string -> int32 = "caml_int32_of_string" +(** Convert the given string to a 32-bit integer. + The string is read in decimal (by default) or in hexadecimal, + octal or binary if the string begins with [0x], [0o] or [0b] + respectively. + Raise [Failure "int_of_string"] if the given string is not + a valid representation of an integer, or if the integer represented + exceeds the range of integers representable in type [int32]. *) + +val to_string : int32 -> string +(** Return the string representation of its argument, in signed decimal. *) + +external bits_of_float : float -> int32 = "caml_int32_bits_of_float" +(** Return the internal representation of the given float according + to the IEEE 754 floating-point ``single format'' bit layout. + Bit 31 of the result represents the sign of the float; + bits 30 to 23 represent the (biased) exponent; bits 22 to 0 + represent the mantissa. *) + +external float_of_bits : int32 -> float = "caml_int32_float_of_bits" +(** Return the floating-point number whose internal representation, + according to the IEEE 754 floating-point ``single format'' bit layout, + is the given [int32]. *) + +type t = int32 +(** An alias for the type of 32-bit integers. *) + +val compare: t -> t -> int +(** The comparison function for 32-bit integers, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [Int32] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +(** {6 Deprecated functions} *) + +external format : string -> int32 -> string = "caml_int32_format" +(** Do not use this deprecated function. Instead, + used {!Printf.sprintf} with a [%l...] format. *) diff --git a/stdlib/int64.ml b/stdlib/int64.ml new file mode 100644 index 0000000..30bfa39 --- /dev/null +++ b/stdlib/int64.ml @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int64.ml,v 1.12 2007-01-30 09:34:36 xleroy Exp $ *) + +(* Module [Int64]: 64-bit integers *) + +external neg : int64 -> int64 = "%int64_neg" +external add : int64 -> int64 -> int64 = "%int64_add" +external sub : int64 -> int64 -> int64 = "%int64_sub" +external mul : int64 -> int64 -> int64 = "%int64_mul" +external div : int64 -> int64 -> int64 = "%int64_div" +external rem : int64 -> int64 -> int64 = "%int64_mod" +external logand : int64 -> int64 -> int64 = "%int64_and" +external logor : int64 -> int64 -> int64 = "%int64_or" +external logxor : int64 -> int64 -> int64 = "%int64_xor" +external shift_left : int64 -> int -> int64 = "%int64_lsl" +external shift_right : int64 -> int -> int64 = "%int64_asr" +external shift_right_logical : int64 -> int -> int64 = "%int64_lsr" +external of_int : int -> int64 = "%int64_of_int" +external to_int : int64 -> int = "%int64_to_int" +external of_float : float -> int64 = "caml_int64_of_float" +external to_float : int64 -> float = "caml_int64_to_float" +external of_int32 : int32 -> int64 = "%int64_of_int32" +external to_int32 : int64 -> int32 = "%int64_to_int32" +external of_nativeint : nativeint -> int64 = "%int64_of_nativeint" +external to_nativeint : int64 -> nativeint = "%int64_to_nativeint" + +let zero = 0L +let one = 1L +let minus_one = -1L +let succ n = add n 1L +let pred n = sub n 1L +let abs n = if n >= 0L then n else neg n +let min_int = 0x8000000000000000L +let max_int = 0x7FFFFFFFFFFFFFFFL +let lognot n = logxor n (-1L) + +external format : string -> int64 -> string = "caml_int64_format" +let to_string n = format "%d" n + +external of_string : string -> int64 = "caml_int64_of_string" + +external bits_of_float : float -> int64 = "caml_int64_bits_of_float" +external float_of_bits : int64 -> float = "caml_int64_float_of_bits" + +type t = int64 + +let compare (x: t) (y: t) = Pervasives.compare x y diff --git a/stdlib/int64.mli b/stdlib/int64.mli new file mode 100644 index 0000000..4ca4a0b --- /dev/null +++ b/stdlib/int64.mli @@ -0,0 +1,186 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: int64.mli,v 1.20 2008-01-11 16:13:16 doligez Exp $ *) + +(** 64-bit integers. + + This module provides operations on the type [int64] of + signed 64-bit integers. Unlike the built-in [int] type, + the type [int64] is guaranteed to be exactly 64-bit wide on all + platforms. All arithmetic operations over [int64] are taken + modulo 2{^64} + + Performance notice: values of type [int64] occupy more memory + space than values of type [int], and arithmetic operations on + [int64] are generally slower than those on [int]. Use [int64] + only when the application requires exact 64-bit arithmetic. +*) + +val zero : int64 +(** The 64-bit integer 0. *) + +val one : int64 +(** The 64-bit integer 1. *) + +val minus_one : int64 +(** The 64-bit integer -1. *) + +external neg : int64 -> int64 = "%int64_neg" +(** Unary negation. *) + +external add : int64 -> int64 -> int64 = "%int64_add" +(** Addition. *) + +external sub : int64 -> int64 -> int64 = "%int64_sub" +(** Subtraction. *) + +external mul : int64 -> int64 -> int64 = "%int64_mul" +(** Multiplication. *) + +external div : int64 -> int64 -> int64 = "%int64_div" +(** Integer division. Raise [Division_by_zero] if the second + argument is zero. This division rounds the real quotient of + its arguments towards zero, as specified for {!Pervasives.(/)}. *) + +external rem : int64 -> int64 -> int64 = "%int64_mod" +(** Integer remainder. If [y] is not zero, the result + of [Int64.rem x y] satisfies the following property: + [x = Int64.add (Int64.mul (Int64.div x y) y) (Int64.rem x y)]. + If [y = 0], [Int64.rem x y] raises [Division_by_zero]. *) + +val succ : int64 -> int64 +(** Successor. [Int64.succ x] is [Int64.add x Int64.one]. *) + +val pred : int64 -> int64 +(** Predecessor. [Int64.pred x] is [Int64.sub x Int64.one]. *) + +val abs : int64 -> int64 +(** Return the absolute value of its argument. *) + +val max_int : int64 +(** The greatest representable 64-bit integer, 2{^63} - 1. *) + +val min_int : int64 +(** The smallest representable 64-bit integer, -2{^63}. *) + +external logand : int64 -> int64 -> int64 = "%int64_and" +(** Bitwise logical and. *) + +external logor : int64 -> int64 -> int64 = "%int64_or" +(** Bitwise logical or. *) + +external logxor : int64 -> int64 -> int64 = "%int64_xor" +(** Bitwise logical exclusive or. *) + +val lognot : int64 -> int64 +(** Bitwise logical negation *) + +external shift_left : int64 -> int -> int64 = "%int64_lsl" +(** [Int64.shift_left x y] shifts [x] to the left by [y] bits. + The result is unspecified if [y < 0] or [y >= 64]. *) + +external shift_right : int64 -> int -> int64 = "%int64_asr" +(** [Int64.shift_right x y] shifts [x] to the right by [y] bits. + This is an arithmetic shift: the sign bit of [x] is replicated + and inserted in the vacated bits. + The result is unspecified if [y < 0] or [y >= 64]. *) + +external shift_right_logical : int64 -> int -> int64 = "%int64_lsr" +(** [Int64.shift_right_logical x y] shifts [x] to the right by [y] bits. + This is a logical shift: zeroes are inserted in the vacated bits + regardless of the sign of [x]. + The result is unspecified if [y < 0] or [y >= 64]. *) + +external of_int : int -> int64 = "%int64_of_int" +(** Convert the given integer (type [int]) to a 64-bit integer + (type [int64]). *) + +external to_int : int64 -> int = "%int64_to_int" +(** Convert the given 64-bit integer (type [int64]) to an + integer (type [int]). On 64-bit platforms, the 64-bit integer + is taken modulo 2{^63}, i.e. the high-order bit is lost + during the conversion. On 32-bit platforms, the 64-bit integer + is taken modulo 2{^31}, i.e. the top 33 bits are lost + during the conversion. *) + +external of_float : float -> int64 = "caml_int64_of_float" +(** Convert the given floating-point number to a 64-bit integer, + discarding the fractional part (truncate towards 0). + The result of the conversion is undefined if, after truncation, + the number is outside the range \[{!Int64.min_int}, {!Int64.max_int}\]. *) + +external to_float : int64 -> float = "caml_int64_to_float" +(** Convert the given 64-bit integer to a floating-point number. *) + + +external of_int32 : int32 -> int64 = "%int64_of_int32" +(** Convert the given 32-bit integer (type [int32]) + to a 64-bit integer (type [int64]). *) + +external to_int32 : int64 -> int32 = "%int64_to_int32" +(** Convert the given 64-bit integer (type [int64]) to a + 32-bit integer (type [int32]). The 64-bit integer + is taken modulo 2{^32}, i.e. the top 32 bits are lost + during the conversion. *) + +external of_nativeint : nativeint -> int64 = "%int64_of_nativeint" +(** Convert the given native integer (type [nativeint]) + to a 64-bit integer (type [int64]). *) + +external to_nativeint : int64 -> nativeint = "%int64_to_nativeint" +(** Convert the given 64-bit integer (type [int64]) to a + native integer. On 32-bit platforms, the 64-bit integer + is taken modulo 2{^32}. On 64-bit platforms, + the conversion is exact. *) + +external of_string : string -> int64 = "caml_int64_of_string" +(** Convert the given string to a 64-bit integer. + The string is read in decimal (by default) or in hexadecimal, + octal or binary if the string begins with [0x], [0o] or [0b] + respectively. + Raise [Failure "int_of_string"] if the given string is not + a valid representation of an integer, or if the integer represented + exceeds the range of integers representable in type [int64]. *) + +val to_string : int64 -> string +(** Return the string representation of its argument, in decimal. *) + +external bits_of_float : float -> int64 = "caml_int64_bits_of_float" +(** Return the internal representation of the given float according + to the IEEE 754 floating-point ``double format'' bit layout. + Bit 63 of the result represents the sign of the float; + bits 62 to 52 represent the (biased) exponent; bits 51 to 0 + represent the mantissa. *) + +external float_of_bits : int64 -> float = "caml_int64_float_of_bits" +(** Return the floating-point number whose internal representation, + according to the IEEE 754 floating-point ``double format'' bit layout, + is the given [int64]. *) + +type t = int64 +(** An alias for the type of 64-bit integers. *) + +val compare: t -> t -> int +(** The comparison function for 64-bit integers, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [Int64] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +(** {6 Deprecated functions} *) + +external format : string -> int64 -> string = "caml_int64_format" +(** Do not use this deprecated function. Instead, + used {!Printf.sprintf} with a [%L...] format. *) diff --git a/stdlib/lazy.ml b/stdlib/lazy.ml new file mode 100644 index 0000000..6048426 --- /dev/null +++ b/stdlib/lazy.ml @@ -0,0 +1,75 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: lazy.ml,v 1.13 2008-08-01 16:57:10 mauny Exp $ *) + +(* Module [Lazy]: deferred computations *) + + +(* + WARNING: some purple magic is going on here. Do not take this file + as an example of how to program in Objective Caml. +*) + + +(* We make use of two special tags provided by the runtime: + [lazy_tag] and [forward_tag]. + + A value of type ['a Lazy.t] can be one of three things: + 1. A block of size 1 with tag [lazy_tag]. Its field is a closure of + type [unit -> 'a] that computes the value. + 2. A block of size 1 with tag [forward_tag]. Its field is the value + of type ['a] that was computed. + 3. Anything else except a float. This has type ['a] and is the value + that was computed. + Exceptions are stored in format (1). + The GC will magically change things from (2) to (3) according to its + fancy. + + We cannot use representation (3) for a [float Lazy.t] because + [caml_make_array] assumes that only a [float] value can have tag + [Double_tag]. + + We have to use the built-in type constructor [lazy_t] to + let the compiler implement the special typing and compilation + rules for the [lazy] keyword. +*) + +type 'a t = 'a lazy_t;; + +exception Undefined = CamlinternalLazy.Undefined;; + +external make_forward : 'a -> 'a lazy_t = "caml_lazy_make_forward";; + +external force : 'a t -> 'a = "%lazy_force";; + +(* let force = force;; *) + +let force_val = CamlinternalLazy.force_val;; + +let lazy_from_fun (f : unit -> 'arg) = + let x = Obj.new_block Obj.lazy_tag 1 in + Obj.set_field x 0 (Obj.repr f); + (Obj.obj x : 'arg t) +;; + +let lazy_from_val (v : 'arg) = + let t = Obj.tag (Obj.repr v) in + if t = Obj.forward_tag || t = Obj.lazy_tag || t = Obj.double_tag then begin + make_forward v + end else begin + (Obj.magic v : 'arg t) + end +;; + +let lazy_is_val (l : 'arg t) = Obj.tag (Obj.repr l) <> Obj.lazy_tag;; diff --git a/stdlib/lazy.mli b/stdlib/lazy.mli new file mode 100644 index 0000000..a0980aa --- /dev/null +++ b/stdlib/lazy.mli @@ -0,0 +1,73 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: lazy.mli,v 1.11 2008-08-01 16:57:10 mauny Exp $ *) + +(** Deferred computations. *) + +type 'a t = 'a lazy_t;; +(** A value of type ['a Lazy.t] is a deferred computation, called + a suspension, that has a result of type ['a]. The special + expression syntax [lazy (expr)] makes a suspension of the + computation of [expr], without computing [expr] itself yet. + "Forcing" the suspension will then compute [expr] and return its + result. + + Note: [lazy_t] is the built-in type constructor used by the compiler + for the [lazy] keyword. You should not use it directly. Always use + [Lazy.t] instead. + + Note: if the program is compiled with the [-rectypes] option, + ill-founded recursive definitions of the form [let rec x = lazy x] + or [let rec x = lazy(lazy(...(lazy x)))] are accepted by the type-checker + and lead, when forced, to ill-formed values that trigger infinite + loops in the garbage collector and other parts of the run-time system. + Without the [-rectypes] option, such ill-founded recursive definitions + are rejected by the type-checker. +*) + + +exception Undefined;; + +external force : 'a t -> 'a = "%lazy_force";; +(* val force : 'a t -> 'a ;; *) +(** [force x] forces the suspension [x] and returns its result. + If [x] has already been forced, [Lazy.force x] returns the + same value again without recomputing it. If it raised an exception, + the same exception is raised again. + Raise [Undefined] if the forcing of [x] tries to force [x] itself + recursively. +*) + +val force_val : 'a t -> 'a;; +(** [force_val x] forces the suspension [x] and returns its + result. If [x] has already been forced, [force_val x] + returns the same value again without recomputing it. + Raise [Undefined] if the forcing of [x] tries to force [x] itself + recursively. + If the computation of [x] raises an exception, it is unspecified + whether [force_val x] raises the same exception or [Undefined]. +*) + +val lazy_from_fun : (unit -> 'a) -> 'a t;; +(** [lazy_from_fun f] is the same as [lazy (f ())] but slightly more + efficient. *) + +val lazy_from_val : 'a -> 'a t;; +(** [lazy_from_val v] returns an already-forced suspension of [v] + This is for special purposes only and should not be confused with + [lazy (v)]. *) + +val lazy_is_val : 'a t -> bool;; +(** [lazy_is_val x] returns [true] if [x] has already been forced and + did not raise an exception. *) diff --git a/stdlib/lexing.ml b/stdlib/lexing.ml new file mode 100644 index 0000000..013884a --- /dev/null +++ b/stdlib/lexing.ml @@ -0,0 +1,239 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: lexing.ml,v 1.25 2008-01-22 16:27:53 doligez Exp $ *) + +(* The run-time library for lexers generated by camllex *) + +type position = { + pos_fname : string; + pos_lnum : int; + pos_bol : int; + pos_cnum : int; +} + +let dummy_pos = { + pos_fname = ""; + pos_lnum = 0; + pos_bol = 0; + pos_cnum = -1; +} + +type lexbuf = + { refill_buff : lexbuf -> unit; + mutable lex_buffer : string; + mutable lex_buffer_len : int; + mutable lex_abs_pos : int; + mutable lex_start_pos : int; + mutable lex_curr_pos : int; + mutable lex_last_pos : int; + mutable lex_last_action : int; + mutable lex_eof_reached : bool; + mutable lex_mem : int array; + mutable lex_start_p : position; + mutable lex_curr_p : position; + } + +type lex_tables = + { lex_base: string; + lex_backtrk: string; + lex_default: string; + lex_trans: string; + lex_check: string; + lex_base_code : string; + lex_backtrk_code : string; + lex_default_code : string; + lex_trans_code : string; + lex_check_code : string; + lex_code: string;} + +external c_engine : lex_tables -> int -> lexbuf -> int = "caml_lex_engine" +external c_new_engine : lex_tables -> int -> lexbuf -> int + = "caml_new_lex_engine" + +let engine tbl state buf = + let result = c_engine tbl state buf in + if result >= 0 then begin + buf.lex_start_p <- buf.lex_curr_p; + buf.lex_curr_p <- {buf.lex_curr_p + with pos_cnum = buf.lex_abs_pos + buf.lex_curr_pos}; + end; + result +;; + +let new_engine tbl state buf = + let result = c_new_engine tbl state buf in + if result >= 0 then begin + buf.lex_start_p <- buf.lex_curr_p; + buf.lex_curr_p <- {buf.lex_curr_p + with pos_cnum = buf.lex_abs_pos + buf.lex_curr_pos}; + end; + result +;; + +let lex_refill read_fun aux_buffer lexbuf = + let read = + read_fun aux_buffer (String.length aux_buffer) in + let n = + if read > 0 + then read + else (lexbuf.lex_eof_reached <- true; 0) in + (* Current state of the buffer: + <-------|---------------------|-----------> + | junk | valid data | junk | + ^ ^ ^ ^ + 0 start_pos buffer_end String.length buffer + *) + if lexbuf.lex_buffer_len + n > String.length lexbuf.lex_buffer then begin + (* There is not enough space at the end of the buffer *) + if lexbuf.lex_buffer_len - lexbuf.lex_start_pos + n + <= String.length lexbuf.lex_buffer + then begin + (* But there is enough space if we reclaim the junk at the beginning + of the buffer *) + String.blit lexbuf.lex_buffer lexbuf.lex_start_pos + lexbuf.lex_buffer 0 + (lexbuf.lex_buffer_len - lexbuf.lex_start_pos) + end else begin + (* We must grow the buffer. Doubling its size will provide enough + space since n <= String.length aux_buffer <= String.length buffer. + Watch out for string length overflow, though. *) + let newlen = + min (2 * String.length lexbuf.lex_buffer) Sys.max_string_length in + if lexbuf.lex_buffer_len - lexbuf.lex_start_pos + n > newlen + then failwith "Lexing.lex_refill: cannot grow buffer"; + let newbuf = String.create newlen in + (* Copy the valid data to the beginning of the new buffer *) + String.blit lexbuf.lex_buffer lexbuf.lex_start_pos + newbuf 0 + (lexbuf.lex_buffer_len - lexbuf.lex_start_pos); + lexbuf.lex_buffer <- newbuf + end; + (* Reallocation or not, we have shifted the data left by + start_pos characters; update the positions *) + let s = lexbuf.lex_start_pos in + lexbuf.lex_abs_pos <- lexbuf.lex_abs_pos + s; + lexbuf.lex_curr_pos <- lexbuf.lex_curr_pos - s; + lexbuf.lex_start_pos <- 0; + lexbuf.lex_last_pos <- lexbuf.lex_last_pos - s; + lexbuf.lex_buffer_len <- lexbuf.lex_buffer_len - s ; + let t = lexbuf.lex_mem in + for i = 0 to Array.length t-1 do + let v = t.(i) in + if v >= 0 then + t.(i) <- v-s + done + end; + (* There is now enough space at the end of the buffer *) + String.blit aux_buffer 0 + lexbuf.lex_buffer lexbuf.lex_buffer_len + n; + lexbuf.lex_buffer_len <- lexbuf.lex_buffer_len + n + +let zero_pos = { + pos_fname = ""; + pos_lnum = 1; + pos_bol = 0; + pos_cnum = 0; +};; + +let from_function f = + { refill_buff = lex_refill f (String.create 512); + lex_buffer = String.create 1024; + lex_buffer_len = 0; + lex_abs_pos = 0; + lex_start_pos = 0; + lex_curr_pos = 0; + lex_last_pos = 0; + lex_last_action = 0; + lex_mem = [||]; + lex_eof_reached = false; + lex_start_p = zero_pos; + lex_curr_p = zero_pos; + } + +let from_channel ic = + from_function (fun buf n -> input ic buf 0 n) + +let from_string s = + { refill_buff = (fun lexbuf -> lexbuf.lex_eof_reached <- true); + lex_buffer = s ^ ""; + lex_buffer_len = String.length s; + lex_abs_pos = 0; + lex_start_pos = 0; + lex_curr_pos = 0; + lex_last_pos = 0; + lex_last_action = 0; + lex_mem = [||]; + lex_eof_reached = true; + lex_start_p = zero_pos; + lex_curr_p = zero_pos; + } + +let lexeme lexbuf = + let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in + let s = String.create len in + String.unsafe_blit lexbuf.lex_buffer lexbuf.lex_start_pos s 0 len; + s + +let sub_lexeme lexbuf i1 i2 = + let len = i2-i1 in + let s = String.create len in + String.unsafe_blit lexbuf.lex_buffer i1 s 0 len; + s + +let sub_lexeme_opt lexbuf i1 i2 = + if i1 >= 0 then begin + let len = i2-i1 in + let s = String.create len in + String.unsafe_blit lexbuf.lex_buffer i1 s 0 len; + Some s + end else begin + None + end + +let sub_lexeme_char lexbuf i = lexbuf.lex_buffer.[i] + +let sub_lexeme_char_opt lexbuf i = + if i >= 0 then + Some lexbuf.lex_buffer.[i] + else + None + + +let lexeme_char lexbuf i = + String.get lexbuf.lex_buffer (lexbuf.lex_start_pos + i) + +let lexeme_start lexbuf = lexbuf.lex_start_p.pos_cnum;; +let lexeme_end lexbuf = lexbuf.lex_curr_p.pos_cnum;; + +let lexeme_start_p lexbuf = lexbuf.lex_start_p;; +let lexeme_end_p lexbuf = lexbuf.lex_curr_p;; + +let new_line lexbuf = + let lcp = lexbuf.lex_curr_p in + lexbuf.lex_curr_p <- { lcp with + pos_lnum = lcp.pos_lnum + 1; + pos_bol = lcp.pos_cnum; + } +;; + + +(* Discard data left in lexer buffer. *) + +let flush_input lb = + lb.lex_curr_pos <- 0; + lb.lex_abs_pos <- 0; + lb.lex_curr_p <- {lb.lex_curr_p with pos_cnum = 0}; + lb.lex_buffer_len <- 0; +;; diff --git a/stdlib/lexing.mli b/stdlib/lexing.mli new file mode 100644 index 0000000..44b4627 --- /dev/null +++ b/stdlib/lexing.mli @@ -0,0 +1,171 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: lexing.mli,v 1.35 2008-12-03 18:09:09 doligez Exp $ *) + +(** The run-time library for lexers generated by [ocamllex]. *) + +(** {6 Positions} *) + +type position = { + pos_fname : string; + pos_lnum : int; + pos_bol : int; + pos_cnum : int; +} +(** A value of type [position] describes a point in a source file. + [pos_fname] is the file name; [pos_lnum] is the line number; + [pos_bol] is the offset of the beginning of the line (number + of characters between the beginning of the file and the beginning + of the line); [pos_cnum] is the offset of the position (number of + characters between the beginning of the file and the position). + + See the documentation of type [lexbuf] for information about + how the lexing engine will manage positions. + *) + +val dummy_pos : position;; +(** A value of type [position], guaranteed to be different from any + valid position. + *) + + +(** {6 Lexer buffers} *) + + +type lexbuf = + { refill_buff : lexbuf -> unit; + mutable lex_buffer : string; + mutable lex_buffer_len : int; + mutable lex_abs_pos : int; + mutable lex_start_pos : int; + mutable lex_curr_pos : int; + mutable lex_last_pos : int; + mutable lex_last_action : int; + mutable lex_eof_reached : bool; + mutable lex_mem : int array; + mutable lex_start_p : position; + mutable lex_curr_p : position; + } +(** The type of lexer buffers. A lexer buffer is the argument passed + to the scanning functions defined by the generated scanners. + The lexer buffer holds the current state of the scanner, plus + a function to refill the buffer from the input. + + At each token, the lexing engine will copy [lex_curr_p] to + [lex_start_p], then change the [pos_cnum] field + of [lex_curr_p] by updating it with the number of characters read + since the start of the [lexbuf]. The other fields are left + unchanged by the lexing engine. In order to keep them + accurate, they must be initialised before the first use of the + lexbuf, and updated by the relevant lexer actions (i.e. at each + end of line -- see also [new_line]). + *) + +val from_channel : in_channel -> lexbuf +(** Create a lexer buffer on the given input channel. + [Lexing.from_channel inchan] returns a lexer buffer which reads + from the input channel [inchan], at the current reading position. *) + +val from_string : string -> lexbuf +(** Create a lexer buffer which reads from + the given string. Reading starts from the first character in + the string. An end-of-input condition is generated when the + end of the string is reached. *) + +val from_function : (string -> int -> int) -> lexbuf +(** Create a lexer buffer with the given function as its reading method. + When the scanner needs more characters, it will call the given + function, giving it a character string [s] and a character + count [n]. The function should put [n] characters or less in [s], + starting at character number 0, and return the number of characters + provided. A return value of 0 means end of input. *) + + +(** {6 Functions for lexer semantic actions} *) + + +(** The following functions can be called from the semantic actions + of lexer definitions (the ML code enclosed in braces that + computes the value returned by lexing functions). They give + access to the character string matched by the regular expression + associated with the semantic action. These functions must be + applied to the argument [lexbuf], which, in the code generated by + [ocamllex], is bound to the lexer buffer passed to the parsing + function. *) + +val lexeme : lexbuf -> string +(** [Lexing.lexeme lexbuf] returns the string matched by + the regular expression. *) + +val lexeme_char : lexbuf -> int -> char +(** [Lexing.lexeme_char lexbuf i] returns character number [i] in + the matched string. *) + +val lexeme_start : lexbuf -> int +(** [Lexing.lexeme_start lexbuf] returns the offset in the + input stream of the first character of the matched string. + The first character of the stream has offset 0. *) + +val lexeme_end : lexbuf -> int +(** [Lexing.lexeme_end lexbuf] returns the offset in the input stream + of the character following the last character of the matched + string. The first character of the stream has offset 0. *) + +val lexeme_start_p : lexbuf -> position +(** Like [lexeme_start], but return a complete [position] instead + of an offset. *) + +val lexeme_end_p : lexbuf -> position +(** Like [lexeme_end], but return a complete [position] instead + of an offset. *) + +val new_line : lexbuf -> unit +(** Update the [lex_curr_p] field of the lexbuf to reflect the start + of a new line. You can call this function in the semantic action + of the rule that matches the end-of-line character. *) + +(** {6 Miscellaneous functions} *) + +val flush_input : lexbuf -> unit +(** Discard the contents of the buffer and reset the current + position to 0. The next use of the lexbuf will trigger a + refill. *) + +(**/**) + +(** {6 } *) + +(** The following definitions are used by the generated scanners only. + They are not intended to be used by user programs. *) + +val sub_lexeme : lexbuf -> int -> int -> string +val sub_lexeme_opt : lexbuf -> int -> int -> string option +val sub_lexeme_char : lexbuf -> int -> char +val sub_lexeme_char_opt : lexbuf -> int -> char option + +type lex_tables = + { lex_base : string; + lex_backtrk : string; + lex_default : string; + lex_trans : string; + lex_check : string; + lex_base_code : string; + lex_backtrk_code : string; + lex_default_code : string; + lex_trans_code : string; + lex_check_code : string; + lex_code: string;} + +val engine : lex_tables -> int -> lexbuf -> int +val new_engine : lex_tables -> int -> lexbuf -> int diff --git a/stdlib/list.ml b/stdlib/list.ml new file mode 100644 index 0000000..3f3cc13 --- /dev/null +++ b/stdlib/list.ml @@ -0,0 +1,316 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: list.ml,v 1.33 2006-09-11 12:18:00 doligez Exp $ *) + +(* List operations *) + +let rec length_aux len = function + [] -> len + | a::l -> length_aux (len + 1) l + +let length l = length_aux 0 l + +let hd = function + [] -> failwith "hd" + | a::l -> a + +let tl = function + [] -> failwith "tl" + | a::l -> l + +let nth l n = + if n < 0 then invalid_arg "List.nth" else + let rec nth_aux l n = + match l with + | [] -> failwith "nth" + | a::l -> if n = 0 then a else nth_aux l (n-1) + in nth_aux l n + +let append = (@) + +let rec rev_append l1 l2 = + match l1 with + [] -> l2 + | a :: l -> rev_append l (a :: l2) + +let rev l = rev_append l [] + +let rec flatten = function + [] -> [] + | l::r -> l @ flatten r + +let concat = flatten + +let rec map f = function + [] -> [] + | a::l -> let r = f a in r :: map f l + +let rev_map f l = + let rec rmap_f accu = function + | [] -> accu + | a::l -> rmap_f (f a :: accu) l + in + rmap_f [] l +;; + +let rec iter f = function + [] -> () + | a::l -> f a; iter f l + +let rec fold_left f accu l = + match l with + [] -> accu + | a::l -> fold_left f (f accu a) l + +let rec fold_right f l accu = + match l with + [] -> accu + | a::l -> f a (fold_right f l accu) + +let rec map2 f l1 l2 = + match (l1, l2) with + ([], []) -> [] + | (a1::l1, a2::l2) -> let r = f a1 a2 in r :: map2 f l1 l2 + | (_, _) -> invalid_arg "List.map2" + +let rev_map2 f l1 l2 = + let rec rmap2_f accu l1 l2 = + match (l1, l2) with + | ([], []) -> accu + | (a1::l1, a2::l2) -> rmap2_f (f a1 a2 :: accu) l1 l2 + | (_, _) -> invalid_arg "List.rev_map2" + in + rmap2_f [] l1 l2 +;; + +let rec iter2 f l1 l2 = + match (l1, l2) with + ([], []) -> () + | (a1::l1, a2::l2) -> f a1 a2; iter2 f l1 l2 + | (_, _) -> invalid_arg "List.iter2" + +let rec fold_left2 f accu l1 l2 = + match (l1, l2) with + ([], []) -> accu + | (a1::l1, a2::l2) -> fold_left2 f (f accu a1 a2) l1 l2 + | (_, _) -> invalid_arg "List.fold_left2" + +let rec fold_right2 f l1 l2 accu = + match (l1, l2) with + ([], []) -> accu + | (a1::l1, a2::l2) -> f a1 a2 (fold_right2 f l1 l2 accu) + | (_, _) -> invalid_arg "List.fold_right2" + +let rec for_all p = function + [] -> true + | a::l -> p a && for_all p l + +let rec exists p = function + [] -> false + | a::l -> p a || exists p l + +let rec for_all2 p l1 l2 = + match (l1, l2) with + ([], []) -> true + | (a1::l1, a2::l2) -> p a1 a2 && for_all2 p l1 l2 + | (_, _) -> invalid_arg "List.for_all2" + +let rec exists2 p l1 l2 = + match (l1, l2) with + ([], []) -> false + | (a1::l1, a2::l2) -> p a1 a2 || exists2 p l1 l2 + | (_, _) -> invalid_arg "List.exists2" + +let rec mem x = function + [] -> false + | a::l -> compare a x = 0 || mem x l + +let rec memq x = function + [] -> false + | a::l -> a == x || memq x l + +let rec assoc x = function + [] -> raise Not_found + | (a,b)::l -> if compare a x = 0 then b else assoc x l + +let rec assq x = function + [] -> raise Not_found + | (a,b)::l -> if a == x then b else assq x l + +let rec mem_assoc x = function + | [] -> false + | (a, b) :: l -> compare a x = 0 || mem_assoc x l + +let rec mem_assq x = function + | [] -> false + | (a, b) :: l -> a == x || mem_assq x l + +let rec remove_assoc x = function + | [] -> [] + | (a, b as pair) :: l -> + if compare a x = 0 then l else pair :: remove_assoc x l + +let rec remove_assq x = function + | [] -> [] + | (a, b as pair) :: l -> if a == x then l else pair :: remove_assq x l + +let rec find p = function + | [] -> raise Not_found + | x :: l -> if p x then x else find p l + +let find_all p = + let rec find accu = function + | [] -> rev accu + | x :: l -> if p x then find (x :: accu) l else find accu l in + find [] + +let filter = find_all + +let partition p l = + let rec part yes no = function + | [] -> (rev yes, rev no) + | x :: l -> if p x then part (x :: yes) no l else part yes (x :: no) l in + part [] [] l + +let rec split = function + [] -> ([], []) + | (x,y)::l -> + let (rx, ry) = split l in (x::rx, y::ry) + +let rec combine l1 l2 = + match (l1, l2) with + ([], []) -> [] + | (a1::l1, a2::l2) -> (a1, a2) :: combine l1 l2 + | (_, _) -> invalid_arg "List.combine" + +(** sorting *) + +let rec merge cmp l1 l2 = + match l1, l2 with + | [], l2 -> l2 + | l1, [] -> l1 + | h1 :: t1, h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: merge cmp t1 l2 + else h2 :: merge cmp l1 t2 +;; + +let rec chop k l = + if k = 0 then l else begin + match l with + | x::t -> chop (k-1) t + | _ -> assert false + end +;; + +let stable_sort cmp l = + let rec rev_merge l1 l2 accu = + match l1, l2 with + | [], l2 -> rev_append l2 accu + | l1, [] -> rev_append l1 accu + | h1::t1, h2::t2 -> + if cmp h1 h2 <= 0 + then rev_merge t1 l2 (h1::accu) + else rev_merge l1 t2 (h2::accu) + in + let rec rev_merge_rev l1 l2 accu = + match l1, l2 with + | [], l2 -> rev_append l2 accu + | l1, [] -> rev_append l1 accu + | h1::t1, h2::t2 -> + if cmp h1 h2 > 0 + then rev_merge_rev t1 l2 (h1::accu) + else rev_merge_rev l1 t2 (h2::accu) + in + let rec sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 <= 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 <= 0 then begin + if cmp x2 x3 <= 0 then [x1; x2; x3] + else if cmp x1 x3 <= 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 <= 0 then [x2; x1; x3] + else if cmp x2 x3 <= 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + let l2 = chop n1 l in + let s1 = rev_sort n1 l in + let s2 = rev_sort n2 l2 in + rev_merge_rev s1 s2 [] + and rev_sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 > 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 > 0 then begin + if cmp x2 x3 > 0 then [x1; x2; x3] + else if cmp x1 x3 > 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 > 0 then [x2; x1; x3] + else if cmp x2 x3 > 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + let l2 = chop n1 l in + let s1 = sort n1 l in + let s2 = sort n2 l2 in + rev_merge s1 s2 [] + in + let len = length l in + if len < 2 then l else sort len l +;; + +let sort = stable_sort;; +let fast_sort = stable_sort;; + +(* Note: on a list of length between about 100000 (depending on the minor + heap size and the type of the list) and Sys.max_array_size, it is + actually faster to use the following, but it might also use more memory + because the argument list cannot be deallocated incrementally. + + Also, there seems to be a bug in this code or in the + implementation of obj_truncate. + +external obj_truncate : 'a array -> int -> unit = "caml_obj_truncate" + +let array_to_list_in_place a = + let l = Array.length a in + let rec loop accu n p = + if p <= 0 then accu else begin + if p = n then begin + obj_truncate a p; + loop (a.(p-1) :: accu) (n-1000) (p-1) + end else begin + loop (a.(p-1) :: accu) n (p-1) + end + end + in + loop [] (l-1000) l +;; + +let stable_sort cmp l = + let a = Array.of_list l in + Array.stable_sort cmp a; + array_to_list_in_place a +;; +*) diff --git a/stdlib/list.mli b/stdlib/list.mli new file mode 100644 index 0000000..ab868d9 --- /dev/null +++ b/stdlib/list.mli @@ -0,0 +1,277 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: list.mli,v 1.47 2006-09-11 12:18:00 doligez Exp $ *) + +(** List operations. + + Some functions are flagged as not tail-recursive. A tail-recursive + function uses constant stack space, while a non-tail-recursive function + uses stack space proportional to the length of its list argument, which + can be a problem with very long lists. When the function takes several + list arguments, an approximate formula giving stack usage (in some + unspecified constant unit) is shown in parentheses. + + The above considerations can usually be ignored if your lists are not + longer than about 10000 elements. +*) + +val length : 'a list -> int +(** Return the length (number of elements) of the given list. *) + +val hd : 'a list -> 'a +(** Return the first element of the given list. Raise + [Failure "hd"] if the list is empty. *) + +val tl : 'a list -> 'a list +(** Return the given list without its first element. Raise + [Failure "tl"] if the list is empty. *) + +val nth : 'a list -> int -> 'a +(** Return the [n]-th element of the given list. + The first element (head of the list) is at position 0. + Raise [Failure "nth"] if the list is too short. + Raise [Invalid_argument "List.nth"] if [n] is negative. *) + +val rev : 'a list -> 'a list +(** List reversal. *) + +val append : 'a list -> 'a list -> 'a list +(** Catenate two lists. Same function as the infix operator [@]. + Not tail-recursive (length of the first argument). The [@] + operator is not tail-recursive either. *) + +val rev_append : 'a list -> 'a list -> 'a list +(** [List.rev_append l1 l2] reverses [l1] and concatenates it to [l2]. + This is equivalent to {!List.rev}[ l1 @ l2], but [rev_append] is + tail-recursive and more efficient. *) + +val concat : 'a list list -> 'a list +(** Concatenate a list of lists. The elements of the argument are all + concatenated together (in the same order) to give the result. + Not tail-recursive + (length of the argument + length of the longest sub-list). *) + +val flatten : 'a list list -> 'a list +(** Same as [concat]. Not tail-recursive + (length of the argument + length of the longest sub-list). *) + + +(** {6 Iterators} *) + + +val iter : ('a -> unit) -> 'a list -> unit +(** [List.iter f [a1; ...; an]] applies function [f] in turn to + [a1; ...; an]. It is equivalent to + [begin f a1; f a2; ...; f an; () end]. *) + +val map : ('a -> 'b) -> 'a list -> 'b list +(** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], + and builds the list [[f a1; ...; f an]] + with the results returned by [f]. Not tail-recursive. *) + +val rev_map : ('a -> 'b) -> 'a list -> 'b list +(** [List.rev_map f l] gives the same result as + {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and + more efficient. *) + +val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a +(** [List.fold_left f a [b1; ...; bn]] is + [f (... (f (f a b1) b2) ...) bn]. *) + +val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b +(** [List.fold_right f [a1; ...; an] b] is + [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. *) + + +(** {6 Iterators on two lists} *) + + +val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit +(** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn + [f a1 b1; ...; f an bn]. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list +(** [List.map2 f [a1; ...; an] [b1; ...; bn]] is + [[f a1 b1; ...; f an bn]]. + Raise [Invalid_argument] if the two lists have + different lengths. Not tail-recursive. *) + +val rev_map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list +(** [List.rev_map2 f l1 l2] gives the same result as + {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and + more efficient. *) + +val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a +(** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is + [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c +(** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is + [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. + Raise [Invalid_argument] if the two lists have + different lengths. Not tail-recursive. *) + + +(** {6 List scanning} *) + + +val for_all : ('a -> bool) -> 'a list -> bool +(** [for_all p [a1; ...; an]] checks if all elements of the list + satisfy the predicate [p]. That is, it returns + [(p a1) && (p a2) && ... && (p an)]. *) + +val exists : ('a -> bool) -> 'a list -> bool +(** [exists p [a1; ...; an]] checks if at least one element of + the list satisfies the predicate [p]. That is, it returns + [(p a1) || (p a2) || ... || (p an)]. *) + +val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool +(** Same as {!List.for_all}, but for a two-argument predicate. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool +(** Same as {!List.exists}, but for a two-argument predicate. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val mem : 'a -> 'a list -> bool +(** [mem a l] is true if and only if [a] is equal + to an element of [l]. *) + +val memq : 'a -> 'a list -> bool +(** Same as {!List.mem}, but uses physical equality instead of structural + equality to compare list elements. *) + + +(** {6 List searching} *) + + +val find : ('a -> bool) -> 'a list -> 'a +(** [find p l] returns the first element of the list [l] + that satisfies the predicate [p]. + Raise [Not_found] if there is no value that satisfies [p] in the + list [l]. *) + +val filter : ('a -> bool) -> 'a list -> 'a list +(** [filter p l] returns all the elements of the list [l] + that satisfy the predicate [p]. The order of the elements + in the input list is preserved. *) + +val find_all : ('a -> bool) -> 'a list -> 'a list +(** [find_all] is another name for {!List.filter}. *) + +val partition : ('a -> bool) -> 'a list -> 'a list * 'a list +(** [partition p l] returns a pair of lists [(l1, l2)], where + [l1] is the list of all the elements of [l] that + satisfy the predicate [p], and [l2] is the list of all the + elements of [l] that do not satisfy [p]. + The order of the elements in the input list is preserved. *) + + +(** {6 Association lists} *) + + +val assoc : 'a -> ('a * 'b) list -> 'b +(** [assoc a l] returns the value associated with key [a] in the list of + pairs [l]. That is, + [assoc a [ ...; (a,b); ...] = b] + if [(a,b)] is the leftmost binding of [a] in list [l]. + Raise [Not_found] if there is no value associated with [a] in the + list [l]. *) + +val assq : 'a -> ('a * 'b) list -> 'b +(** Same as {!List.assoc}, but uses physical equality instead of structural + equality to compare keys. *) + +val mem_assoc : 'a -> ('a * 'b) list -> bool +(** Same as {!List.assoc}, but simply return true if a binding exists, + and false if no bindings exist for the given key. *) + +val mem_assq : 'a -> ('a * 'b) list -> bool +(** Same as {!List.mem_assoc}, but uses physical equality instead of + structural equality to compare keys. *) + +val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list +(** [remove_assoc a l] returns the list of + pairs [l] without the first pair with key [a], if any. + Not tail-recursive. *) + +val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list +(** Same as {!List.remove_assoc}, but uses physical equality instead + of structural equality to compare keys. Not tail-recursive. *) + + +(** {6 Lists of pairs} *) + + +val split : ('a * 'b) list -> 'a list * 'b list +(** Transform a list of pairs into a pair of lists: + [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. + Not tail-recursive. +*) + +val combine : 'a list -> 'b list -> ('a * 'b) list +(** Transform a pair of lists into a list of pairs: + [combine [a1; ...; an] [b1; ...; bn]] is + [[(a1,b1); ...; (an,bn)]]. + Raise [Invalid_argument] if the two lists + have different lengths. Not tail-recursive. *) + + +(** {6 Sorting} *) + + +val sort : ('a -> 'a -> int) -> 'a list -> 'a list +(** Sort a list in increasing order according to a comparison + function. The comparison function must return 0 if its arguments + compare as equal, a positive integer if the first is greater, + and a negative integer if the first is smaller (see Array.sort for + a complete specification). For example, + {!Pervasives.compare} is a suitable comparison function. + The resulting list is sorted in increasing order. + [List.sort] is guaranteed to run in constant heap space + (in addition to the size of the result list) and logarithmic + stack space. + + The current implementation uses Merge Sort. It runs in constant + heap space and logarithmic stack space. +*) + +val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list +(** Same as {!List.sort}, but the sorting algorithm is guaranteed to + be stable (i.e. elements that compare equal are kept in their + original order) . + + The current implementation uses Merge Sort. It runs in constant + heap space and logarithmic stack space. +*) + +val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list +(** Same as {!List.sort} or {!List.stable_sort}, whichever is faster + on typical input. *) + +val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list +(** Merge two lists: + Assuming that [l1] and [l2] are sorted according to the + comparison function [cmp], [merge cmp l1 l2] will return a + sorted list containting all the elements of [l1] and [l2]. + If several elements compare equal, the elements of [l1] will be + before the elements of [l2]. + Not tail-recursive (sum of the lengths of the arguments). +*) diff --git a/stdlib/listLabels.ml b/stdlib/listLabels.ml new file mode 100644 index 0000000..32aad26 --- /dev/null +++ b/stdlib/listLabels.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: listLabels.ml,v 1.3 2001-12-07 13:40:54 xleroy Exp $ *) + +(* Module [ListLabels]: labelled List module *) + +include List diff --git a/stdlib/listLabels.mli b/stdlib/listLabels.mli new file mode 100644 index 0000000..95b430f --- /dev/null +++ b/stdlib/listLabels.mli @@ -0,0 +1,279 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: listLabels.mli,v 1.12 2007-01-22 08:06:09 garrigue Exp $ *) + +(** List operations. + + Some functions are flagged as not tail-recursive. A tail-recursive + function uses constant stack space, while a non-tail-recursive function + uses stack space proportional to the length of its list argument, which + can be a problem with very long lists. When the function takes several + list arguments, an approximate formula giving stack usage (in some + unspecified constant unit) is shown in parentheses. + + The above considerations can usually be ignored if your lists are not + longer than about 10000 elements. +*) + +val length : 'a list -> int +(** Return the length (number of elements) of the given list. *) + +val hd : 'a list -> 'a +(** Return the first element of the given list. Raise + [Failure "hd"] if the list is empty. *) + +val tl : 'a list -> 'a list +(** Return the given list without its first element. Raise + [Failure "tl"] if the list is empty. *) + +val nth : 'a list -> int -> 'a +(** Return the [n]-th element of the given list. + The first element (head of the list) is at position 0. + Raise [Failure "nth"] if the list is too short. + Raise [Invalid_argument "List.nth"] if [n] is negative. *) + +val rev : 'a list -> 'a list +(** List reversal. *) + +val append : 'a list -> 'a list -> 'a list +(** Catenate two lists. Same function as the infix operator [@]. + Not tail-recursive (length of the first argument). The [@] + operator is not tail-recursive either. *) + +val rev_append : 'a list -> 'a list -> 'a list +(** [List.rev_append l1 l2] reverses [l1] and concatenates it to [l2]. + This is equivalent to {!ListLabels.rev}[ l1 @ l2], but [rev_append] is + tail-recursive and more efficient. *) + +val concat : 'a list list -> 'a list +(** Concatenate a list of lists. The elements of the argument are all + concatenated together (in the same order) to give the result. + Not tail-recursive + (length of the argument + length of the longest sub-list). *) + +val flatten : 'a list list -> 'a list +(** Same as [concat]. Not tail-recursive + (length of the argument + length of the longest sub-list). *) + + +(** {6 Iterators} *) + + +val iter : f:('a -> unit) -> 'a list -> unit +(** [List.iter f [a1; ...; an]] applies function [f] in turn to + [a1; ...; an]. It is equivalent to + [begin f a1; f a2; ...; f an; () end]. *) + +val map : f:('a -> 'b) -> 'a list -> 'b list +(** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], + and builds the list [[f a1; ...; f an]] + with the results returned by [f]. Not tail-recursive. *) + +val rev_map : f:('a -> 'b) -> 'a list -> 'b list +(** [List.rev_map f l] gives the same result as + {!ListLabels.rev}[ (]{!ListLabels.map}[ f l)], but is tail-recursive and + more efficient. *) + +val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b list -> 'a +(** [List.fold_left f a [b1; ...; bn]] is + [f (... (f (f a b1) b2) ...) bn]. *) + +val fold_right : f:('a -> 'b -> 'b) -> 'a list -> init:'b -> 'b +(** [List.fold_right f [a1; ...; an] b] is + [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. *) + + +(** {6 Iterators on two lists} *) + + +val iter2 : f:('a -> 'b -> unit) -> 'a list -> 'b list -> unit +(** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn + [f a1 b1; ...; f an bn]. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val map2 : f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list +(** [List.map2 f [a1; ...; an] [b1; ...; bn]] is + [[f a1 b1; ...; f an bn]]. + Raise [Invalid_argument] if the two lists have + different lengths. Not tail-recursive. *) + +val rev_map2 : f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list +(** [List.rev_map2 f l1 l2] gives the same result as + {!ListLabels.rev}[ (]{!ListLabels.map2}[ f l1 l2)], but is tail-recursive and + more efficient. *) + +val fold_left2 : + f:('a -> 'b -> 'c -> 'a) -> init:'a -> 'b list -> 'c list -> 'a +(** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is + [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val fold_right2 : + f:('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> init:'c -> 'c +(** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is + [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. + Raise [Invalid_argument] if the two lists have + different lengths. Not tail-recursive. *) + + +(** {6 List scanning} *) + + +val for_all : f:('a -> bool) -> 'a list -> bool +(** [for_all p [a1; ...; an]] checks if all elements of the list + satisfy the predicate [p]. That is, it returns + [(p a1) && (p a2) && ... && (p an)]. *) + +val exists : f:('a -> bool) -> 'a list -> bool +(** [exists p [a1; ...; an]] checks if at least one element of + the list satisfies the predicate [p]. That is, it returns + [(p a1) || (p a2) || ... || (p an)]. *) + +val for_all2 : f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool +(** Same as {!ListLabels.for_all}, but for a two-argument predicate. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val exists2 : f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool +(** Same as {!ListLabels.exists}, but for a two-argument predicate. + Raise [Invalid_argument] if the two lists have + different lengths. *) + +val mem : 'a -> set:'a list -> bool +(** [mem a l] is true if and only if [a] is equal + to an element of [l]. *) + +val memq : 'a -> set:'a list -> bool +(** Same as {!ListLabels.mem}, but uses physical equality instead of structural + equality to compare list elements. *) + + +(** {6 List searching} *) + + +val find : f:('a -> bool) -> 'a list -> 'a +(** [find p l] returns the first element of the list [l] + that satisfies the predicate [p]. + Raise [Not_found] if there is no value that satisfies [p] in the + list [l]. *) + +val filter : f:('a -> bool) -> 'a list -> 'a list +(** [filter p l] returns all the elements of the list [l] + that satisfy the predicate [p]. The order of the elements + in the input list is preserved. *) + +val find_all : f:('a -> bool) -> 'a list -> 'a list +(** [find_all] is another name for {!ListLabels.filter}. *) + +val partition : f:('a -> bool) -> 'a list -> 'a list * 'a list +(** [partition p l] returns a pair of lists [(l1, l2)], where + [l1] is the list of all the elements of [l] that + satisfy the predicate [p], and [l2] is the list of all the + elements of [l] that do not satisfy [p]. + The order of the elements in the input list is preserved. *) + + +(** {6 Association lists} *) + + +val assoc : 'a -> ('a * 'b) list -> 'b +(** [assoc a l] returns the value associated with key [a] in the list of + pairs [l]. That is, + [assoc a [ ...; (a,b); ...] = b] + if [(a,b)] is the leftmost binding of [a] in list [l]. + Raise [Not_found] if there is no value associated with [a] in the + list [l]. *) + +val assq : 'a -> ('a * 'b) list -> 'b +(** Same as {!ListLabels.assoc}, but uses physical equality instead of + structural equality to compare keys. *) + +val mem_assoc : 'a -> map:('a * 'b) list -> bool +(** Same as {!ListLabels.assoc}, but simply return true if a binding exists, + and false if no bindings exist for the given key. *) + +val mem_assq : 'a -> map:('a * 'b) list -> bool +(** Same as {!ListLabels.mem_assoc}, but uses physical equality instead of + structural equality to compare keys. *) + +val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list +(** [remove_assoc a l] returns the list of + pairs [l] without the first pair with key [a], if any. + Not tail-recursive. *) + +val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list +(** Same as {!ListLabels.remove_assoc}, but uses physical equality instead + of structural equality to compare keys. Not tail-recursive. *) + + +(** {6 Lists of pairs} *) + + +val split : ('a * 'b) list -> 'a list * 'b list +(** Transform a list of pairs into a pair of lists: + [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. + Not tail-recursive. +*) + +val combine : 'a list -> 'b list -> ('a * 'b) list +(** Transform a pair of lists into a list of pairs: + [combine [a1; ...; an] [b1; ...; bn]] is + [[(a1,b1); ...; (an,bn)]]. + Raise [Invalid_argument] if the two lists + have different lengths. Not tail-recursive. *) + + +(** {6 Sorting} *) + + +val sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list +(** Sort a list in increasing order according to a comparison + function. The comparison function must return 0 if its arguments + compare as equal, a positive integer if the first is greater, + and a negative integer if the first is smaller (see Array.sort for + a complete specification). For example, + {!Pervasives.compare} is a suitable comparison function. + The resulting list is sorted in increasing order. + [List.sort] is guaranteed to run in constant heap space + (in addition to the size of the result list) and logarithmic + stack space. + + The current implementation uses Merge Sort. It runs in constant + heap space and logarithmic stack space. +*) + +val stable_sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list +(** Same as {!ListLabels.sort}, but the sorting algorithm is guaranteed to + be stable (i.e. elements that compare equal are kept in their + original order) . + + The current implementation uses Merge Sort. It runs in constant + heap space and logarithmic stack space. +*) + +val fast_sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list +(** Same as {!List.sort} or {!List.stable_sort}, whichever is faster + on typical input. *) + +val merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list +(** Merge two lists: + Assuming that [l1] and [l2] are sorted according to the + comparison function [cmp], [merge cmp l1 l2] will return a + sorted list containting all the elements of [l1] and [l2]. + If several elements compare equal, the elements of [l1] will be + before the elements of [l2]. + Not tail-recursive (sum of the lengths of the arguments). +*) diff --git a/stdlib/map.ml b/stdlib/map.ml new file mode 100644 index 0000000..84bcba6 --- /dev/null +++ b/stdlib/map.ml @@ -0,0 +1,198 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: map.ml,v 1.17 2005-08-13 20:59:37 doligez Exp $ *) + +module type OrderedType = + sig + type t + val compare: t -> t -> int + end + +module type S = + sig + type key + type +'a t + val empty: 'a t + val is_empty: 'a t -> bool + val add: key -> 'a -> 'a t -> 'a t + val find: key -> 'a t -> 'a + val remove: key -> 'a t -> 'a t + val mem: key -> 'a t -> bool + val iter: (key -> 'a -> unit) -> 'a t -> unit + val map: ('a -> 'b) -> 'a t -> 'b t + val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t + val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b + val compare: ('a -> 'a -> int) -> 'a t -> 'a t -> int + val equal: ('a -> 'a -> bool) -> 'a t -> 'a t -> bool + end + +module Make(Ord: OrderedType) = struct + + type key = Ord.t + + type 'a t = + Empty + | Node of 'a t * key * 'a * 'a t * int + + let height = function + Empty -> 0 + | Node(_,_,_,_,h) -> h + + let create l x d r = + let hl = height l and hr = height r in + Node(l, x, d, r, (if hl >= hr then hl + 1 else hr + 1)) + + let bal l x d r = + let hl = match l with Empty -> 0 | Node(_,_,_,_,h) -> h in + let hr = match r with Empty -> 0 | Node(_,_,_,_,h) -> h in + if hl > hr + 2 then begin + match l with + Empty -> invalid_arg "Map.bal" + | Node(ll, lv, ld, lr, _) -> + if height ll >= height lr then + create ll lv ld (create lr x d r) + else begin + match lr with + Empty -> invalid_arg "Map.bal" + | Node(lrl, lrv, lrd, lrr, _)-> + create (create ll lv ld lrl) lrv lrd (create lrr x d r) + end + end else if hr > hl + 2 then begin + match r with + Empty -> invalid_arg "Map.bal" + | Node(rl, rv, rd, rr, _) -> + if height rr >= height rl then + create (create l x d rl) rv rd rr + else begin + match rl with + Empty -> invalid_arg "Map.bal" + | Node(rll, rlv, rld, rlr, _) -> + create (create l x d rll) rlv rld (create rlr rv rd rr) + end + end else + Node(l, x, d, r, (if hl >= hr then hl + 1 else hr + 1)) + + let empty = Empty + + let is_empty = function Empty -> true | _ -> false + + let rec add x data = function + Empty -> + Node(Empty, x, data, Empty, 1) + | Node(l, v, d, r, h) -> + let c = Ord.compare x v in + if c = 0 then + Node(l, x, data, r, h) + else if c < 0 then + bal (add x data l) v d r + else + bal l v d (add x data r) + + let rec find x = function + Empty -> + raise Not_found + | Node(l, v, d, r, _) -> + let c = Ord.compare x v in + if c = 0 then d + else find x (if c < 0 then l else r) + + let rec mem x = function + Empty -> + false + | Node(l, v, d, r, _) -> + let c = Ord.compare x v in + c = 0 || mem x (if c < 0 then l else r) + + let rec min_binding = function + Empty -> raise Not_found + | Node(Empty, x, d, r, _) -> (x, d) + | Node(l, x, d, r, _) -> min_binding l + + let rec remove_min_binding = function + Empty -> invalid_arg "Map.remove_min_elt" + | Node(Empty, x, d, r, _) -> r + | Node(l, x, d, r, _) -> bal (remove_min_binding l) x d r + + let merge t1 t2 = + match (t1, t2) with + (Empty, t) -> t + | (t, Empty) -> t + | (_, _) -> + let (x, d) = min_binding t2 in + bal t1 x d (remove_min_binding t2) + + let rec remove x = function + Empty -> + Empty + | Node(l, v, d, r, h) -> + let c = Ord.compare x v in + if c = 0 then + merge l r + else if c < 0 then + bal (remove x l) v d r + else + bal l v d (remove x r) + + let rec iter f = function + Empty -> () + | Node(l, v, d, r, _) -> + iter f l; f v d; iter f r + + let rec map f = function + Empty -> Empty + | Node(l, v, d, r, h) -> Node(map f l, v, f d, map f r, h) + + let rec mapi f = function + Empty -> Empty + | Node(l, v, d, r, h) -> Node(mapi f l, v, f v d, mapi f r, h) + + let rec fold f m accu = + match m with + Empty -> accu + | Node(l, v, d, r, _) -> + fold f r (f v d (fold f l accu)) + + type 'a enumeration = End | More of key * 'a * 'a t * 'a enumeration + + let rec cons_enum m e = + match m with + Empty -> e + | Node(l, v, d, r, _) -> cons_enum l (More(v, d, r, e)) + + let compare cmp m1 m2 = + let rec compare_aux e1 e2 = + match (e1, e2) with + (End, End) -> 0 + | (End, _) -> -1 + | (_, End) -> 1 + | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) -> + let c = Ord.compare v1 v2 in + if c <> 0 then c else + let c = cmp d1 d2 in + if c <> 0 then c else + compare_aux (cons_enum r1 e1) (cons_enum r2 e2) + in compare_aux (cons_enum m1 End) (cons_enum m2 End) + + let equal cmp m1 m2 = + let rec equal_aux e1 e2 = + match (e1, e2) with + (End, End) -> true + | (End, _) -> false + | (_, End) -> false + | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) -> + Ord.compare v1 v2 = 0 && cmp d1 d2 && + equal_aux (cons_enum r1 e1) (cons_enum r2 e2) + in equal_aux (cons_enum m1 End) (cons_enum m2 End) + +end diff --git a/stdlib/map.mli b/stdlib/map.mli new file mode 100644 index 0000000..4e816e0 --- /dev/null +++ b/stdlib/map.mli @@ -0,0 +1,111 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: map.mli,v 1.33 2005-10-25 18:34:07 doligez Exp $ *) + +(** Association tables over ordered types. + + This module implements applicative association tables, also known as + finite maps or dictionaries, given a total ordering function + over the keys. + All operations over maps are purely applicative (no side-effects). + The implementation uses balanced binary trees, and therefore searching + and insertion take time logarithmic in the size of the map. +*) + +module type OrderedType = + sig + type t + (** The type of the map keys. *) + val compare : t -> t -> int + (** A total ordering function over the keys. + This is a two-argument function [f] such that + [f e1 e2] is zero if the keys [e1] and [e2] are equal, + [f e1 e2] is strictly negative if [e1] is smaller than [e2], + and [f e1 e2] is strictly positive if [e1] is greater than [e2]. + Example: a suitable ordering function is the generic structural + comparison function {!Pervasives.compare}. *) + end +(** Input signature of the functor {!Map.Make}. *) + +module type S = + sig + type key + (** The type of the map keys. *) + + type (+'a) t + (** The type of maps from type [key] to type ['a]. *) + + val empty: 'a t + (** The empty map. *) + + val is_empty: 'a t -> bool + (** Test whether a map is empty or not. *) + + val add: key -> 'a -> 'a t -> 'a t + (** [add x y m] returns a map containing the same bindings as + [m], plus a binding of [x] to [y]. If [x] was already bound + in [m], its previous binding disappears. *) + + val find: key -> 'a t -> 'a + (** [find x m] returns the current binding of [x] in [m], + or raises [Not_found] if no such binding exists. *) + + val remove: key -> 'a t -> 'a t + (** [remove x m] returns a map containing the same bindings as + [m], except for [x] which is unbound in the returned map. *) + + val mem: key -> 'a t -> bool + (** [mem x m] returns [true] if [m] contains a binding for [x], + and [false] otherwise. *) + + val iter: (key -> 'a -> unit) -> 'a t -> unit + (** [iter f m] applies [f] to all bindings in map [m]. + [f] receives the key as first argument, and the associated value + as second argument. The bindings are passed to [f] in increasing + order with respect to the ordering over the type of the keys. + Only current bindings are presented to [f]: + bindings hidden by more recent bindings are not passed to [f]. *) + + val map: ('a -> 'b) -> 'a t -> 'b t + (** [map f m] returns a map with same domain as [m], where the + associated value [a] of all bindings of [m] has been + replaced by the result of the application of [f] to [a]. + The bindings are passed to [f] in increasing order + with respect to the ordering over the type of the keys. *) + + val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t + (** Same as {!Map.S.map}, but the function receives as arguments both the + key and the associated value for each binding of the map. *) + + val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b + (** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)], + where [k1 ... kN] are the keys of all bindings in [m] + (in increasing order), and [d1 ... dN] are the associated data. *) + + val compare: ('a -> 'a -> int) -> 'a t -> 'a t -> int + (** Total ordering between maps. The first argument is a total ordering + used to compare data associated with equal keys in the two maps. *) + + val equal: ('a -> 'a -> bool) -> 'a t -> 'a t -> bool + (** [equal cmp m1 m2] tests whether the maps [m1] and [m2] are + equal, that is, contain equal keys and associate them with + equal data. [cmp] is the equality predicate used to compare + the data associated with the keys. *) + + end +(** Output signature of the functor {!Map.Make}. *) + +module Make (Ord : OrderedType) : S with type key = Ord.t +(** Functor building an implementation of the map structure + given a totally ordered type. *) diff --git a/stdlib/marshal.ml b/stdlib/marshal.ml new file mode 100644 index 0000000..da093b3 --- /dev/null +++ b/stdlib/marshal.ml @@ -0,0 +1,53 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: marshal.ml,v 1.9 2005-10-25 18:34:07 doligez Exp $ *) + +type extern_flags = + No_sharing + | Closures + +external to_channel: out_channel -> 'a -> extern_flags list -> unit + = "caml_output_value" +external to_string: 'a -> extern_flags list -> string + = "caml_output_value_to_string" +external to_buffer_unsafe: + string -> int -> int -> 'a -> extern_flags list -> int + = "caml_output_value_to_buffer" + +let to_buffer buff ofs len v flags = + if ofs < 0 || len < 0 || ofs > String.length buff - len + then invalid_arg "Marshal.to_buffer: substring out of bounds" + else to_buffer_unsafe buff ofs len v flags + +external from_channel: in_channel -> 'a = "caml_input_value" +external from_string_unsafe: string -> int -> 'a + = "caml_input_value_from_string" +external data_size_unsafe: string -> int -> int = "caml_marshal_data_size" + +let header_size = 20 +let data_size buff ofs = + if ofs < 0 || ofs > String.length buff - header_size + then invalid_arg "Marshal.data_size" + else data_size_unsafe buff ofs +let total_size buff ofs = header_size + data_size buff ofs + +let from_string buff ofs = + if ofs < 0 || ofs > String.length buff - header_size + then invalid_arg "Marshal.from_size" + else begin + let len = data_size_unsafe buff ofs in + if ofs > String.length buff - (header_size + len) + then invalid_arg "Marshal.from_string" + else from_string_unsafe buff ofs + end diff --git a/stdlib/marshal.mli b/stdlib/marshal.mli new file mode 100644 index 0000000..a3467b1 --- /dev/null +++ b/stdlib/marshal.mli @@ -0,0 +1,136 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: marshal.mli,v 1.14 2005-10-25 18:34:07 doligez Exp $ *) + +(** Marshaling of data structures. + + This module provides functions to encode arbitrary data structures + as sequences of bytes, which can then be written on a file or + sent over a pipe or network connection. The bytes can then + be read back later, possibly in another process, and decoded back + into a data structure. The format for the byte sequences + is compatible across all machines for a given version of Objective Caml. + + Warning: marshaling is currently not type-safe. The type + of marshaled data is not transmitted along the value of the data, + making it impossible to check that the data read back possesses the + type expected by the context. In particular, the result type of + the [Marshal.from_*] functions is given as ['a], but this is + misleading: the returned Caml value does not possess type ['a] + for all ['a]; it has one, unique type which cannot be determined + at compile-type. The programmer should explicitly give the expected + type of the returned value, using the following syntax: + - [(Marshal.from_channel chan : type)]. + Anything can happen at run-time if the object in the file does not + belong to the given type. + + The representation of marshaled values is not human-readable, + and uses bytes that are not printable characters. Therefore, + input and output channels used in conjunction with [Marshal.to_channel] + and [Marshal.from_channel] must be opened in binary mode, using e.g. + [open_out_bin] or [open_in_bin]; channels opened in text mode will + cause unmarshaling errors on platforms where text channels behave + differently than binary channels, e.g. Windows. +*) + +type extern_flags = + No_sharing (** Don't preserve sharing *) + | Closures (** Send function closures *) +(** The flags to the [Marshal.to_*] functions below. *) + +val to_channel : out_channel -> 'a -> extern_flags list -> unit +(** [Marshal.to_channel chan v flags] writes the representation + of [v] on channel [chan]. The [flags] argument is a + possibly empty list of flags that governs the marshaling + behavior with respect to sharing and functional values. + + If [flags] does not contain [Marshal.No_sharing], circularities + and sharing inside the value [v] are detected and preserved + in the sequence of bytes produced. In particular, this + guarantees that marshaling always terminates. Sharing + between values marshaled by successive calls to + [Marshal.to_channel] is not detected, though. + If [flags] contains [Marshal.No_sharing], sharing is ignored. + This results in faster marshaling if [v] contains no shared + substructures, but may cause slower marshaling and larger + byte representations if [v] actually contains sharing, + or even non-termination if [v] contains cycles. + + If [flags] does not contain [Marshal.Closures], + marshaling fails when it encounters a functional value + inside [v]: only ``pure'' data structures, containing neither + functions nor objects, can safely be transmitted between + different programs. If [flags] contains [Marshal.Closures], + functional values will be marshaled as a position in the code + of the program. In this case, the output of marshaling can + only be read back in processes that run exactly the same program, + with exactly the same compiled code. (This is checked + at un-marshaling time, using an MD5 digest of the code + transmitted along with the code position.) *) + +external to_string : + 'a -> extern_flags list -> string = "caml_output_value_to_string" +(** [Marshal.to_string v flags] returns a string containing + the representation of [v] as a sequence of bytes. + The [flags] argument has the same meaning as for + {!Marshal.to_channel}. *) + +val to_buffer : string -> int -> int -> 'a -> extern_flags list -> int +(** [Marshal.to_buffer buff ofs len v flags] marshals the value [v], + storing its byte representation in the string [buff], + starting at character number [ofs], and writing at most + [len] characters. It returns the number of characters + actually written to the string. If the byte representation + of [v] does not fit in [len] characters, the exception [Failure] + is raised. *) + +val from_channel : in_channel -> 'a +(** [Marshal.from_channel chan] reads from channel [chan] the + byte representation of a structured value, as produced by + one of the [Marshal.to_*] functions, and reconstructs and + returns the corresponding value.*) + +val from_string : string -> int -> 'a +(** [Marshal.from_string buff ofs] unmarshals a structured value + like {!Marshal.from_channel} does, except that the byte + representation is not read from a channel, but taken from + the string [buff], starting at position [ofs]. *) + +val header_size : int +(** The bytes representing a marshaled value are composed of + a fixed-size header and a variable-sized data part, + whose size can be determined from the header. + {!Marshal.header_size} is the size, in characters, of the header. + {!Marshal.data_size}[ buff ofs] is the size, in characters, + of the data part, assuming a valid header is stored in + [buff] starting at position [ofs]. + Finally, {!Marshal.total_size}[ buff ofs] is the total size, + in characters, of the marshaled value. + Both {!Marshal.data_size} and {!Marshal.total_size} raise [Failure] + if [buff], [ofs] does not contain a valid header. + + To read the byte representation of a marshaled value into + a string buffer, the program needs to read first + {!Marshal.header_size} characters into the buffer, + then determine the length of the remainder of the + representation using {!Marshal.data_size}, + make sure the buffer is large enough to hold the remaining + data, then read it, and finally call {!Marshal.from_string} + to unmarshal the value. *) + +val data_size : string -> int -> int +(** See {!Marshal.header_size}.*) + +val total_size : string -> int -> int +(** See {!Marshal.header_size}.*) diff --git a/stdlib/moreLabels.ml b/stdlib/moreLabels.ml new file mode 100644 index 0000000..2288975 --- /dev/null +++ b/stdlib/moreLabels.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: moreLabels.ml,v 1.2 2001-12-07 13:40:55 xleroy Exp $ *) + +(* Module [MoreLabels]: meta-module for compatibility labelled libraries *) + +module Hashtbl = Hashtbl + +module Map = Map + +module Set = Set diff --git a/stdlib/moreLabels.mli b/stdlib/moreLabels.mli new file mode 100644 index 0000000..10c7464 --- /dev/null +++ b/stdlib/moreLabels.mli @@ -0,0 +1,124 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: moreLabels.mli,v 1.12 2004-04-23 10:01:34 xleroy Exp $ *) + +(** Extra labeled libraries. + + This meta-module provides labelized version of the {!Hashtbl}, + {!Map} and {!Set} modules. + + They only differ by their labels. They are provided to help + porting from previous versions of Objective Caml. + The contents of this module are subject to change. +*) + +module Hashtbl : sig + type ('a, 'b) t = ('a, 'b) Hashtbl.t + val create : int -> ('a, 'b) t + val clear : ('a, 'b) t -> unit + val add : ('a, 'b) t -> key:'a -> data:'b -> unit + val copy : ('a, 'b) t -> ('a, 'b) t + val find : ('a, 'b) t -> 'a -> 'b + val find_all : ('a, 'b) t -> 'a -> 'b list + val mem : ('a, 'b) t -> 'a -> bool + val remove : ('a, 'b) t -> 'a -> unit + val replace : ('a, 'b) t -> key:'a -> data:'b -> unit + val iter : f:(key:'a -> data:'b -> unit) -> ('a, 'b) t -> unit + val fold : + f:(key:'a -> data:'b -> 'c -> 'c) -> + ('a, 'b) t -> init:'c -> 'c + val length : ('a, 'b) t -> int + module type HashedType = Hashtbl.HashedType + module type S = + sig + type key + and 'a t + val create : int -> 'a t + val clear : 'a t -> unit + val copy : 'a t -> 'a t + val add : 'a t -> key:key -> data:'a -> unit + val remove : 'a t -> key -> unit + val find : 'a t -> key -> 'a + val find_all : 'a t -> key -> 'a list + val replace : 'a t -> key:key -> data:'a -> unit + val mem : 'a t -> key -> bool + val iter : f:(key:key -> data:'a -> unit) -> 'a t -> unit + val fold : + f:(key:key -> data:'a -> 'b -> 'b) -> + 'a t -> init:'b -> 'b + val length : 'a t -> int + end + module Make : functor (H : HashedType) -> S with type key = H.t + val hash : 'a -> int + external hash_param : int -> int -> 'a -> int + = "caml_hash_univ_param" "noalloc" +end + +module Map : sig + module type OrderedType = Map.OrderedType + module type S = + sig + type key + and (+'a) t + val empty : 'a t + val is_empty: 'a t -> bool + val add : key:key -> data:'a -> 'a t -> 'a t + val find : key -> 'a t -> 'a + val remove : key -> 'a t -> 'a t + val mem : key -> 'a t -> bool + val iter : f:(key:key -> data:'a -> unit) -> 'a t -> unit + val map : f:('a -> 'b) -> 'a t -> 'b t + val mapi : f:(key -> 'a -> 'b) -> 'a t -> 'b t + val fold : + f:(key:key -> data:'a -> 'b -> 'b) -> + 'a t -> init:'b -> 'b + val compare: cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int + val equal: cmp:('a -> 'a -> bool) -> 'a t -> 'a t -> bool + end + module Make : functor (Ord : OrderedType) -> S with type key = Ord.t +end + +module Set : sig + module type OrderedType = Set.OrderedType + module type S = + sig + type elt + and t + val empty : t + val is_empty : t -> bool + val mem : elt -> t -> bool + val add : elt -> t -> t + val singleton : elt -> t + val remove : elt -> t -> t + val union : t -> t -> t + val inter : t -> t -> t + val diff : t -> t -> t + val compare : t -> t -> int + val equal : t -> t -> bool + val subset : t -> t -> bool + val iter : f:(elt -> unit) -> t -> unit + val fold : f:(elt -> 'a -> 'a) -> t -> init:'a -> 'a + val for_all : f:(elt -> bool) -> t -> bool + val exists : f:(elt -> bool) -> t -> bool + val filter : f:(elt -> bool) -> t -> t + val partition : f:(elt -> bool) -> t -> t * t + val cardinal : t -> int + val elements : t -> elt list + val min_elt : t -> elt + val max_elt : t -> elt + val choose : t -> elt + val split: elt -> t -> t * bool * t + end + module Make : functor (Ord : OrderedType) -> S with type elt = Ord.t +end diff --git a/stdlib/nativeint.ml b/stdlib/nativeint.ml new file mode 100644 index 0000000..040bfa1 --- /dev/null +++ b/stdlib/nativeint.ml @@ -0,0 +1,55 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: nativeint.ml,v 1.11 2007-01-30 09:34:36 xleroy Exp $ *) + +(* Module [Nativeint]: processor-native integers *) + +external neg: nativeint -> nativeint = "%nativeint_neg" +external add: nativeint -> nativeint -> nativeint = "%nativeint_add" +external sub: nativeint -> nativeint -> nativeint = "%nativeint_sub" +external mul: nativeint -> nativeint -> nativeint = "%nativeint_mul" +external div: nativeint -> nativeint -> nativeint = "%nativeint_div" +external rem: nativeint -> nativeint -> nativeint = "%nativeint_mod" +external logand: nativeint -> nativeint -> nativeint = "%nativeint_and" +external logor: nativeint -> nativeint -> nativeint = "%nativeint_or" +external logxor: nativeint -> nativeint -> nativeint = "%nativeint_xor" +external shift_left: nativeint -> int -> nativeint = "%nativeint_lsl" +external shift_right: nativeint -> int -> nativeint = "%nativeint_asr" +external shift_right_logical: nativeint -> int -> nativeint = "%nativeint_lsr" +external of_int: int -> nativeint = "%nativeint_of_int" +external to_int: nativeint -> int = "%nativeint_to_int" +external of_float : float -> nativeint = "caml_nativeint_of_float" +external to_float : nativeint -> float = "caml_nativeint_to_float" +external of_int32: int32 -> nativeint = "%nativeint_of_int32" +external to_int32: nativeint -> int32 = "%nativeint_to_int32" + +let zero = 0n +let one = 1n +let minus_one = -1n +let succ n = add n 1n +let pred n = sub n 1n +let abs n = if n >= 0n then n else neg n +let size = Sys.word_size +let min_int = shift_left 1n (size - 1) +let max_int = sub min_int 1n +let lognot n = logxor n (-1n) + +external format : string -> nativeint -> string = "caml_nativeint_format" +let to_string n = format "%d" n + +external of_string: string -> nativeint = "caml_nativeint_of_string" + +type t = nativeint + +let compare (x: t) (y: t) = Pervasives.compare x y diff --git a/stdlib/nativeint.mli b/stdlib/nativeint.mli new file mode 100644 index 0000000..28a0995 --- /dev/null +++ b/stdlib/nativeint.mli @@ -0,0 +1,185 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: nativeint.mli,v 1.18 2005-10-25 18:34:07 doligez Exp $ *) + +(** Processor-native integers. + + This module provides operations on the type [nativeint] of + signed 32-bit integers (on 32-bit platforms) or + signed 64-bit integers (on 64-bit platforms). + This integer type has exactly the same width as that of a [long] + integer type in the C compiler. All arithmetic operations over + [nativeint] are taken modulo 2{^32} or 2{^64} depending + on the word size of the architecture. + + Performance notice: values of type [nativeint] occupy more memory + space than values of type [int], and arithmetic operations on + [nativeint] are generally slower than those on [int]. Use [nativeint] + only when the application requires the extra bit of precision + over the [int] type. +*) + +val zero : nativeint +(** The native integer 0.*) + +val one : nativeint +(** The native integer 1.*) + +val minus_one : nativeint +(** The native integer -1.*) + +external neg : nativeint -> nativeint = "%nativeint_neg" +(** Unary negation. *) + +external add : nativeint -> nativeint -> nativeint = "%nativeint_add" +(** Addition. *) + +external sub : nativeint -> nativeint -> nativeint = "%nativeint_sub" +(** Subtraction. *) + +external mul : nativeint -> nativeint -> nativeint = "%nativeint_mul" +(** Multiplication. *) + +external div : nativeint -> nativeint -> nativeint = "%nativeint_div" +(** Integer division. Raise [Division_by_zero] if the second + argument is zero. This division rounds the real quotient of + its arguments towards zero, as specified for {!Pervasives.(/)}. *) + +external rem : nativeint -> nativeint -> nativeint = "%nativeint_mod" +(** Integer remainder. If [y] is not zero, the result + of [Nativeint.rem x y] satisfies the following properties: + [Nativeint.zero <= Nativeint.rem x y < Nativeint.abs y] and + [x = Nativeint.add (Nativeint.mul (Nativeint.div x y) y) (Nativeint.rem x y)]. + If [y = 0], [Nativeint.rem x y] raises [Division_by_zero]. *) + +val succ : nativeint -> nativeint +(** Successor. + [Nativeint.succ x] is [Nativeint.add x Nativeint.one]. *) + +val pred : nativeint -> nativeint +(** Predecessor. + [Nativeint.pred x] is [Nativeint.sub x Nativeint.one]. *) + +val abs : nativeint -> nativeint +(** Return the absolute value of its argument. *) + +val size : int +(** The size in bits of a native integer. This is equal to [32] + on a 32-bit platform and to [64] on a 64-bit platform. *) + +val max_int : nativeint +(** The greatest representable native integer, + either 2{^31} - 1 on a 32-bit platform, + or 2{^63} - 1 on a 64-bit platform. *) + +val min_int : nativeint +(** The greatest representable native integer, + either -2{^31} on a 32-bit platform, + or -2{^63} on a 64-bit platform. *) + +external logand : nativeint -> nativeint -> nativeint = "%nativeint_and" +(** Bitwise logical and. *) + +external logor : nativeint -> nativeint -> nativeint = "%nativeint_or" +(** Bitwise logical or. *) + +external logxor : nativeint -> nativeint -> nativeint = "%nativeint_xor" +(** Bitwise logical exclusive or. *) + +val lognot : nativeint -> nativeint +(** Bitwise logical negation *) + +external shift_left : nativeint -> int -> nativeint = "%nativeint_lsl" +(** [Nativeint.shift_left x y] shifts [x] to the left by [y] bits. + The result is unspecified if [y < 0] or [y >= bitsize], + where [bitsize] is [32] on a 32-bit platform and + [64] on a 64-bit platform. *) + +external shift_right : nativeint -> int -> nativeint = "%nativeint_asr" +(** [Nativeint.shift_right x y] shifts [x] to the right by [y] bits. + This is an arithmetic shift: the sign bit of [x] is replicated + and inserted in the vacated bits. + The result is unspecified if [y < 0] or [y >= bitsize]. *) + +external shift_right_logical : + nativeint -> int -> nativeint = "%nativeint_lsr" +(** [Nativeint.shift_right_logical x y] shifts [x] to the right + by [y] bits. + This is a logical shift: zeroes are inserted in the vacated bits + regardless of the sign of [x]. + The result is unspecified if [y < 0] or [y >= bitsize]. *) + + +external of_int : int -> nativeint = "%nativeint_of_int" +(** Convert the given integer (type [int]) to a native integer + (type [nativeint]). *) + +external to_int : nativeint -> int = "%nativeint_to_int" +(** Convert the given native integer (type [nativeint]) to an + integer (type [int]). The high-order bit is lost during + the conversion. *) + +external of_float : float -> nativeint = "caml_nativeint_of_float" +(** Convert the given floating-point number to a native integer, + discarding the fractional part (truncate towards 0). + The result of the conversion is undefined if, after truncation, + the number is outside the range + \[{!Nativeint.min_int}, {!Nativeint.max_int}\]. *) + +external to_float : nativeint -> float = "caml_nativeint_to_float" +(** Convert the given native integer to a floating-point number. *) + +external of_int32 : int32 -> nativeint = "%nativeint_of_int32" +(** Convert the given 32-bit integer (type [int32]) + to a native integer. *) + +external to_int32 : nativeint -> int32 = "%nativeint_to_int32" +(** Convert the given native integer to a + 32-bit integer (type [int32]). On 64-bit platforms, + the 64-bit native integer is taken modulo 2{^32}, + i.e. the top 32 bits are lost. On 32-bit platforms, + the conversion is exact. *) + +external of_string : string -> nativeint = "caml_nativeint_of_string" +(** Convert the given string to a native integer. + The string is read in decimal (by default) or in hexadecimal, + octal or binary if the string begins with [0x], [0o] or [0b] + respectively. + Raise [Failure "int_of_string"] if the given string is not + a valid representation of an integer, or if the integer represented + exceeds the range of integers representable in type [nativeint]. *) + +val to_string : nativeint -> string +(** Return the string representation of its argument, in decimal. *) + +type t = nativeint +(** An alias for the type of native integers. *) + +val compare: t -> t -> int +(** The comparison function for native integers, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [Nativeint] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +(** {6 Deprecated functions} *) + +external format : string -> nativeint -> string = "caml_nativeint_format" +(** [Nativeint.format fmt n] return the string representation of the + native integer [n] in the format specified by [fmt]. + [fmt] is a [Printf]-style format consisting of exactly + one [%d], [%i], [%u], [%x], [%X] or [%o] conversion specification. + This function is deprecated; use {!Printf.sprintf} with a [%nx] format + instead. *) diff --git a/stdlib/obj.ml b/stdlib/obj.ml new file mode 100644 index 0000000..7073c3c --- /dev/null +++ b/stdlib/obj.ml @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: obj.ml,v 1.24 2008-01-29 13:11:15 doligez Exp $ *) + +(* Operations on internal representations of values *) + +type t + +external repr : 'a -> t = "%identity" +external obj : t -> 'a = "%identity" +external magic : 'a -> 'b = "%identity" +external is_block : t -> bool = "caml_obj_is_block" +external is_int : t -> bool = "%obj_is_int" +external tag : t -> int = "caml_obj_tag" +external set_tag : t -> int -> unit = "caml_obj_set_tag" +external size : t -> int = "%obj_size" +external field : t -> int -> t = "%obj_field" +external set_field : t -> int -> t -> unit = "%obj_set_field" +external new_block : int -> int -> t = "caml_obj_block" +external dup : t -> t = "caml_obj_dup" +external truncate : t -> int -> unit = "caml_obj_truncate" + +let marshal (obj : t) = + Marshal.to_string obj [] +let unmarshal str pos = + (Marshal.from_string str pos, pos + Marshal.total_size str pos) + +let lazy_tag = 246 +let closure_tag = 247 +let object_tag = 248 +let infix_tag = 249 +let forward_tag = 250 + +let no_scan_tag = 251 + +let abstract_tag = 251 +let string_tag = 252 +let double_tag = 253 +let double_array_tag = 254 +let custom_tag = 255 +let final_tag = custom_tag + + +let int_tag = 1000 +let out_of_heap_tag = 1001 +let unaligned_tag = 1002 diff --git a/stdlib/obj.mli b/stdlib/obj.mli new file mode 100644 index 0000000..f2fad04 --- /dev/null +++ b/stdlib/obj.mli @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: obj.mli,v 1.30 2008-01-29 13:11:15 doligez Exp $ *) + +(** Operations on internal representations of values. + + Not for the casual user. +*) + +type t + +external repr : 'a -> t = "%identity" +external obj : t -> 'a = "%identity" +external magic : 'a -> 'b = "%identity" +external is_block : t -> bool = "caml_obj_is_block" +external is_int : t -> bool = "%obj_is_int" +external tag : t -> int = "caml_obj_tag" +external set_tag : t -> int -> unit = "caml_obj_set_tag" +external size : t -> int = "%obj_size" +external truncate : t -> int -> unit = "caml_obj_truncate" +external field : t -> int -> t = "%obj_field" +external set_field : t -> int -> t -> unit = "%obj_set_field" +external new_block : int -> int -> t = "caml_obj_block" +external dup : t -> t = "caml_obj_dup" + +val lazy_tag : int +val closure_tag : int +val object_tag : int +val infix_tag : int +val forward_tag : int +val no_scan_tag : int +val abstract_tag : int +val string_tag : int +val double_tag : int +val double_array_tag : int +val custom_tag : int +val final_tag : int (* DEPRECATED *) + +val int_tag : int +val out_of_heap_tag : int +val unaligned_tag : int (* should never happen *) + +(** The following two functions are deprecated. Use module {!Marshal} + instead. *) + +val marshal : t -> string +val unmarshal : string -> int -> t * int diff --git a/stdlib/oo.ml b/stdlib/oo.ml new file mode 100644 index 0000000..4a69c82 --- /dev/null +++ b/stdlib/oo.ml @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: oo.ml,v 1.27 2004-05-26 11:10:52 garrigue Exp $ *) + +let copy = CamlinternalOO.copy +external id : < .. > -> int = "%field1" +let new_method = CamlinternalOO.public_method_label +let public_method_label = CamlinternalOO.public_method_label diff --git a/stdlib/oo.mli b/stdlib/oo.mli new file mode 100644 index 0000000..55a446b --- /dev/null +++ b/stdlib/oo.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: oo.mli,v 1.28 2004-05-26 11:10:52 garrigue Exp $ *) + +(** Operations on objects *) + +val copy : (< .. > as 'a) -> 'a +(** [Oo.copy o] returns a copy of object [o], that is a fresh + object with the same methods and instance variables as [o] *) + +external id : < .. > -> int = "%field1" +(** Return an integer identifying this object, unique for + the current execution of the program. *) + +(**/**) +(** For internal use (CamlIDL) *) +val new_method : string -> CamlinternalOO.tag +val public_method_label : string -> CamlinternalOO.tag diff --git a/stdlib/parsing.ml b/stdlib/parsing.ml new file mode 100644 index 0000000..aefad25 --- /dev/null +++ b/stdlib/parsing.ml @@ -0,0 +1,199 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: parsing.ml,v 1.19 2008-08-06 09:38:21 xleroy Exp $ *) + +(* The parsing engine *) + +open Lexing + +(* Internal interface to the parsing engine *) + +type parser_env = + { mutable s_stack : int array; (* States *) + mutable v_stack : Obj.t array; (* Semantic attributes *) + mutable symb_start_stack : position array; (* Start positions *) + mutable symb_end_stack : position array; (* End positions *) + mutable stacksize : int; (* Size of the stacks *) + mutable stackbase : int; (* Base sp for current parse *) + mutable curr_char : int; (* Last token read *) + mutable lval : Obj.t; (* Its semantic attribute *) + mutable symb_start : position; (* Start pos. of the current symbol*) + mutable symb_end : position; (* End pos. of the current symbol *) + mutable asp : int; (* The stack pointer for attributes *) + mutable rule_len : int; (* Number of rhs items in the rule *) + mutable rule_number : int; (* Rule number to reduce by *) + mutable sp : int; (* Saved sp for parse_engine *) + mutable state : int; (* Saved state for parse_engine *) + mutable errflag : int } (* Saved error flag for parse_engine *) + +type parse_tables = + { actions : (parser_env -> Obj.t) array; + transl_const : int array; + transl_block : int array; + lhs : string; + len : string; + defred : string; + dgoto : string; + sindex : string; + rindex : string; + gindex : string; + tablesize : int; + table : string; + check : string; + error_function : string -> unit; + names_const : string; + names_block : string } + +exception YYexit of Obj.t +exception Parse_error + +type parser_input = + Start + | Token_read + | Stacks_grown_1 + | Stacks_grown_2 + | Semantic_action_computed + | Error_detected + +type parser_output = + Read_token + | Raise_parse_error + | Grow_stacks_1 + | Grow_stacks_2 + | Compute_semantic_action + | Call_error_function + +external parse_engine : + parse_tables -> parser_env -> parser_input -> Obj.t -> parser_output + = "caml_parse_engine" + +external set_trace: bool -> bool + = "caml_set_parser_trace" + +let env = + { s_stack = Array.create 100 0; + v_stack = Array.create 100 (Obj.repr ()); + symb_start_stack = Array.create 100 dummy_pos; + symb_end_stack = Array.create 100 dummy_pos; + stacksize = 100; + stackbase = 0; + curr_char = 0; + lval = Obj.repr (); + symb_start = dummy_pos; + symb_end = dummy_pos; + asp = 0; + rule_len = 0; + rule_number = 0; + sp = 0; + state = 0; + errflag = 0 } + +let grow_stacks() = + let oldsize = env.stacksize in + let newsize = oldsize * 2 in + let new_s = Array.create newsize 0 + and new_v = Array.create newsize (Obj.repr ()) + and new_start = Array.create newsize dummy_pos + and new_end = Array.create newsize dummy_pos in + Array.blit env.s_stack 0 new_s 0 oldsize; + env.s_stack <- new_s; + Array.blit env.v_stack 0 new_v 0 oldsize; + env.v_stack <- new_v; + Array.blit env.symb_start_stack 0 new_start 0 oldsize; + env.symb_start_stack <- new_start; + Array.blit env.symb_end_stack 0 new_end 0 oldsize; + env.symb_end_stack <- new_end; + env.stacksize <- newsize + +let clear_parser() = + Array.fill env.v_stack 0 env.stacksize (Obj.repr ()); + env.lval <- Obj.repr () + +let current_lookahead_fun = ref (fun (x : Obj.t) -> false) + +let yyparse tables start lexer lexbuf = + let rec loop cmd arg = + match parse_engine tables env cmd arg with + Read_token -> + let t = Obj.repr(lexer lexbuf) in + env.symb_start <- lexbuf.lex_start_p; + env.symb_end <- lexbuf.lex_curr_p; + loop Token_read t + | Raise_parse_error -> + raise Parse_error + | Compute_semantic_action -> + let (action, value) = + try + (Semantic_action_computed, tables.actions.(env.rule_number) env) + with Parse_error -> + (Error_detected, Obj.repr ()) in + loop action value + | Grow_stacks_1 -> + grow_stacks(); loop Stacks_grown_1 (Obj.repr ()) + | Grow_stacks_2 -> + grow_stacks(); loop Stacks_grown_2 (Obj.repr ()) + | Call_error_function -> + tables.error_function "syntax error"; + loop Error_detected (Obj.repr ()) in + let init_asp = env.asp + and init_sp = env.sp + and init_stackbase = env.stackbase + and init_state = env.state + and init_curr_char = env.curr_char + and init_errflag = env.errflag in + env.stackbase <- env.sp + 1; + env.curr_char <- start; + env.symb_end <- lexbuf.lex_curr_p; + try + loop Start (Obj.repr ()) + with exn -> + let curr_char = env.curr_char in + env.asp <- init_asp; + env.sp <- init_sp; + env.stackbase <- init_stackbase; + env.state <- init_state; + env.curr_char <- init_curr_char; + env.errflag <- init_errflag; + match exn with + YYexit v -> + Obj.magic v + | _ -> + current_lookahead_fun := + (fun tok -> + if Obj.is_block tok + then tables.transl_block.(Obj.tag tok) = curr_char + else tables.transl_const.(Obj.magic tok) = curr_char); + raise exn + +let peek_val env n = + Obj.magic env.v_stack.(env.asp - n) + +let symbol_start_pos () = + if env.rule_len > 0 + then env.symb_start_stack.(env.asp - env.rule_len + 1) + else env.symb_end_stack.(env.asp) +;; +let symbol_end_pos () = env.symb_end_stack.(env.asp);; +let rhs_start_pos n = env.symb_start_stack.(env.asp - (env.rule_len - n));; +let rhs_end_pos n = env.symb_end_stack.(env.asp - (env.rule_len - n));; + +let symbol_start () = (symbol_start_pos ()).pos_cnum;; +let symbol_end () = (symbol_end_pos ()).pos_cnum;; +let rhs_start n = (rhs_start_pos n).pos_cnum;; +let rhs_end n = (rhs_end_pos n).pos_cnum;; + +let is_current_lookahead tok = + (!current_lookahead_fun)(Obj.repr tok) + +let parse_error (msg : string) = () diff --git a/stdlib/parsing.mli b/stdlib/parsing.mli new file mode 100644 index 0000000..f30477c --- /dev/null +++ b/stdlib/parsing.mli @@ -0,0 +1,103 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: parsing.mli,v 1.19 2008-08-06 09:38:21 xleroy Exp $ *) + +(** The run-time library for parsers generated by [ocamlyacc]. *) + +val symbol_start : unit -> int +(** [symbol_start] and {!Parsing.symbol_end} are to be called in the + action part of a grammar rule only. They return the offset of the + string that matches the left-hand side of the rule: [symbol_start()] + returns the offset of the first character; [symbol_end()] returns the + offset after the last character. The first character in a file is at + offset 0. *) + +val symbol_end : unit -> int +(** See {!Parsing.symbol_start}. *) + +val rhs_start : int -> int +(** Same as {!Parsing.symbol_start} and {!Parsing.symbol_end}, but + return the offset of the string matching the [n]th item on the + right-hand side of the rule, where [n] is the integer parameter + to [rhs_start] and [rhs_end]. [n] is 1 for the leftmost item. *) + +val rhs_end : int -> int +(** See {!Parsing.rhs_start}. *) + +val symbol_start_pos : unit -> Lexing.position;; +(** Same as [symbol_start], but return a [position] instead of an offset. *) + +val symbol_end_pos : unit -> Lexing.position +(** Same as [symbol_end], but return a [position] instead of an offset. *) + +val rhs_start_pos : int -> Lexing.position +(** Same as [rhs_start], but return a [position] instead of an offset. *) + +val rhs_end_pos : int -> Lexing.position +(** Same as [rhs_end], but return a [position] instead of an offset. *) + +val clear_parser : unit -> unit +(** Empty the parser stack. Call it just after a parsing function + has returned, to remove all pointers from the parser stack + to structures that were built by semantic actions during parsing. + This is optional, but lowers the memory requirements of the + programs. *) + +exception Parse_error +(** Raised when a parser encounters a syntax error. + Can also be raised from the action part of a grammar rule, + to initiate error recovery. *) + +val set_trace: bool -> bool +(** Control debugging support for [ocamlyacc]-generated parsers. + After [Parsing.set_trace true], the pushdown automaton that + executes the parsers prints a trace of its actions (reading a token, + shifting a state, reducing by a rule) on standard output. + [Parsing.set_trace false] turns this debugging trace off. + The boolean returned is the previous state of the trace flag. *) + +(**/**) + +(** {6 } *) + +(** The following definitions are used by the generated parsers only. + They are not intended to be used by user programs. *) + +type parser_env + +type parse_tables = + { actions : (parser_env -> Obj.t) array; + transl_const : int array; + transl_block : int array; + lhs : string; + len : string; + defred : string; + dgoto : string; + sindex : string; + rindex : string; + gindex : string; + tablesize : int; + table : string; + check : string; + error_function : string -> unit; + names_const : string; + names_block : string } + +exception YYexit of Obj.t + +val yyparse : + parse_tables -> int -> (Lexing.lexbuf -> 'a) -> Lexing.lexbuf -> 'b +val peek_val : parser_env -> int -> 'a +val is_current_lookahead : 'a -> bool +val parse_error : string -> unit diff --git a/stdlib/pervasives.ml b/stdlib/pervasives.ml new file mode 100644 index 0000000..3344a85 --- /dev/null +++ b/stdlib/pervasives.ml @@ -0,0 +1,447 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: pervasives.ml,v 1.81 2006-11-17 08:34:01 weis Exp $ *) + +(* type 'a option = None | Some of 'a *) + +(* Exceptions *) + +external raise : exn -> 'a = "%raise" + +let failwith s = raise(Failure s) +let invalid_arg s = raise(Invalid_argument s) + +exception Exit + +(* Comparisons *) + +external (=) : 'a -> 'a -> bool = "%equal" +external (<>) : 'a -> 'a -> bool = "%notequal" +external (<) : 'a -> 'a -> bool = "%lessthan" +external (>) : 'a -> 'a -> bool = "%greaterthan" +external (<=) : 'a -> 'a -> bool = "%lessequal" +external (>=) : 'a -> 'a -> bool = "%greaterequal" +external compare: 'a -> 'a -> int = "%compare" + +let min x y = if x <= y then x else y +let max x y = if x >= y then x else y + +external (==) : 'a -> 'a -> bool = "%eq" +external (!=) : 'a -> 'a -> bool = "%noteq" + +(* Boolean operations *) + +external not : bool -> bool = "%boolnot" +external (&) : bool -> bool -> bool = "%sequand" +external (&&) : bool -> bool -> bool = "%sequand" +external (or) : bool -> bool -> bool = "%sequor" +external (||) : bool -> bool -> bool = "%sequor" + +(* Integer operations *) + +external (~-) : int -> int = "%negint" +external succ : int -> int = "%succint" +external pred : int -> int = "%predint" +external (+) : int -> int -> int = "%addint" +external (-) : int -> int -> int = "%subint" +external ( * ) : int -> int -> int = "%mulint" +external (/) : int -> int -> int = "%divint" +external (mod) : int -> int -> int = "%modint" + +let abs x = if x >= 0 then x else -x + +external (land) : int -> int -> int = "%andint" +external (lor) : int -> int -> int = "%orint" +external (lxor) : int -> int -> int = "%xorint" + +let lnot x = x lxor (-1) + +external (lsl) : int -> int -> int = "%lslint" +external (lsr) : int -> int -> int = "%lsrint" +external (asr) : int -> int -> int = "%asrint" + +let min_int = 1 lsl (if 1 lsl 31 = 0 then 30 else 62) +let max_int = min_int - 1 + +(* Floating-point operations *) + +external (~-.) : float -> float = "%negfloat" +external (+.) : float -> float -> float = "%addfloat" +external (-.) : float -> float -> float = "%subfloat" +external ( *. ) : float -> float -> float = "%mulfloat" +external (/.) : float -> float -> float = "%divfloat" +external ( ** ) : float -> float -> float = "caml_power_float" "pow" "float" +external exp : float -> float = "caml_exp_float" "exp" "float" +external acos : float -> float = "caml_acos_float" "acos" "float" +external asin : float -> float = "caml_asin_float" "asin" "float" +external atan : float -> float = "caml_atan_float" "atan" "float" +external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float" +external cos : float -> float = "caml_cos_float" "cos" "float" +external cosh : float -> float = "caml_cosh_float" "cosh" "float" +external log : float -> float = "caml_log_float" "log" "float" +external log10 : float -> float = "caml_log10_float" "log10" "float" +external sin : float -> float = "caml_sin_float" "sin" "float" +external sinh : float -> float = "caml_sinh_float" "sinh" "float" +external sqrt : float -> float = "caml_sqrt_float" "sqrt" "float" +external tan : float -> float = "caml_tan_float" "tan" "float" +external tanh : float -> float = "caml_tanh_float" "tanh" "float" +external ceil : float -> float = "caml_ceil_float" "ceil" "float" +external floor : float -> float = "caml_floor_float" "floor" "float" +external abs_float : float -> float = "%absfloat" +external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float" +external frexp : float -> float * int = "caml_frexp_float" +external ldexp : float -> int -> float = "caml_ldexp_float" +external modf : float -> float * float = "caml_modf_float" +external float : int -> float = "%floatofint" +external float_of_int : int -> float = "%floatofint" +external truncate : float -> int = "%intoffloat" +external int_of_float : float -> int = "%intoffloat" +external float_of_bits : int64 -> float = "caml_int64_float_of_bits" +let infinity = + float_of_bits 0x7F_F0_00_00_00_00_00_00L +let neg_infinity = + float_of_bits 0xFF_F0_00_00_00_00_00_00L +let nan = + float_of_bits 0x7F_F0_00_00_00_00_00_01L +let max_float = + float_of_bits 0x7F_EF_FF_FF_FF_FF_FF_FFL +let min_float = + float_of_bits 0x00_10_00_00_00_00_00_00L +let epsilon_float = + float_of_bits 0x3C_B0_00_00_00_00_00_00L + +type fpclass = + FP_normal + | FP_subnormal + | FP_zero + | FP_infinite + | FP_nan +external classify_float: float -> fpclass = "caml_classify_float" + +(* String operations -- more in module String *) + +external string_length : string -> int = "%string_length" +external string_create: int -> string = "caml_create_string" +external string_blit : string -> int -> string -> int -> int -> unit + = "caml_blit_string" "noalloc" + +let (^) s1 s2 = + let l1 = string_length s1 and l2 = string_length s2 in + let s = string_create (l1 + l2) in + string_blit s1 0 s 0 l1; + string_blit s2 0 s l1 l2; + s + +(* Character operations -- more in module Char *) + +external int_of_char : char -> int = "%identity" +external unsafe_char_of_int : int -> char = "%identity" +let char_of_int n = + if n < 0 || n > 255 then invalid_arg "char_of_int" else unsafe_char_of_int n + +(* Unit operations *) + +external ignore : 'a -> unit = "%ignore" + +(* Pair operations *) + +external fst : 'a * 'b -> 'a = "%field0" +external snd : 'a * 'b -> 'b = "%field1" + +(* String conversion functions *) + +external format_int: string -> int -> string = "caml_format_int" +external format_float: string -> float -> string = "caml_format_float" + +let string_of_bool b = + if b then "true" else "false" +let bool_of_string = function + | "true" -> true + | "false" -> false + | _ -> invalid_arg "bool_of_string" + +let string_of_int n = + format_int "%d" n + +external int_of_string : string -> int = "caml_int_of_string" + +module String = struct + external get : string -> int -> char = "%string_safe_get" +end + +let valid_float_lexem s = + let l = string_length s in + let rec loop i = + if i >= l then s ^ "." else + match s.[i] with + | '0' .. '9' | '-' -> loop (i+1) + | _ -> s + in + loop 0 +;; + +let string_of_float f = valid_float_lexem (format_float "%.12g" f);; + +external float_of_string : string -> float = "caml_float_of_string" + +(* List operations -- more in module List *) + +let rec (@) l1 l2 = + match l1 with + [] -> l2 + | hd :: tl -> hd :: (tl @ l2) + +(* I/O operations *) + +type in_channel +type out_channel + +external open_descriptor_out: int -> out_channel = "caml_ml_open_descriptor_out" +external open_descriptor_in: int -> in_channel = "caml_ml_open_descriptor_in" + +let stdin = open_descriptor_in 0 +let stdout = open_descriptor_out 1 +let stderr = open_descriptor_out 2 + +(* General output functions *) + +type open_flag = + Open_rdonly | Open_wronly | Open_append + | Open_creat | Open_trunc | Open_excl + | Open_binary | Open_text | Open_nonblock + +external open_desc: string -> open_flag list -> int -> int = "caml_sys_open" + +let open_out_gen mode perm name = + open_descriptor_out(open_desc name mode perm) + +let open_out name = + open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_text] 0o666 name + +let open_out_bin name = + open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] 0o666 name + +external flush : out_channel -> unit = "caml_ml_flush" + +external out_channels_list : unit -> out_channel list + = "caml_ml_out_channels_list" + +let flush_all () = + let rec iter = function + [] -> () + | a::l -> (try flush a with _ -> ()); iter l + in iter (out_channels_list ()) + +external unsafe_output : out_channel -> string -> int -> int -> unit + = "caml_ml_output" + +external output_char : out_channel -> char -> unit = "caml_ml_output_char" + +let output_string oc s = + unsafe_output oc s 0 (string_length s) + +let output oc s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "output" + else unsafe_output oc s ofs len + +external output_byte : out_channel -> int -> unit = "caml_ml_output_char" +external output_binary_int : out_channel -> int -> unit = "caml_ml_output_int" + +external marshal_to_channel : out_channel -> 'a -> unit list -> unit + = "caml_output_value" +let output_value chan v = marshal_to_channel chan v [] + +external seek_out : out_channel -> int -> unit = "caml_ml_seek_out" +external pos_out : out_channel -> int = "caml_ml_pos_out" +external out_channel_length : out_channel -> int = "caml_ml_channel_size" +external close_out_channel : out_channel -> unit = "caml_ml_close_channel" +let close_out oc = flush oc; close_out_channel oc +let close_out_noerr oc = + (try flush oc with _ -> ()); + (try close_out_channel oc with _ -> ()) +external set_binary_mode_out : out_channel -> bool -> unit + = "caml_ml_set_binary_mode" + +(* General input functions *) + +let open_in_gen mode perm name = + open_descriptor_in(open_desc name mode perm) + +let open_in name = + open_in_gen [Open_rdonly; Open_text] 0 name + +let open_in_bin name = + open_in_gen [Open_rdonly; Open_binary] 0 name + +external input_char : in_channel -> char = "caml_ml_input_char" + +external unsafe_input : in_channel -> string -> int -> int -> int + = "caml_ml_input" + +let input ic s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "input" + else unsafe_input ic s ofs len + +let rec unsafe_really_input ic s ofs len = + if len <= 0 then () else begin + let r = unsafe_input ic s ofs len in + if r = 0 + then raise End_of_file + else unsafe_really_input ic s (ofs+r) (len-r) + end + +let really_input ic s ofs len = + if ofs < 0 || len < 0 || ofs > string_length s - len + then invalid_arg "really_input" + else unsafe_really_input ic s ofs len + +external input_scan_line : in_channel -> int = "caml_ml_input_scan_line" + +let input_line chan = + let rec build_result buf pos = function + [] -> buf + | hd :: tl -> + let len = string_length hd in + string_blit hd 0 buf (pos - len) len; + build_result buf (pos - len) tl in + let rec scan accu len = + let n = input_scan_line chan in + if n = 0 then begin (* n = 0: we are at EOF *) + match accu with + [] -> raise End_of_file + | _ -> build_result (string_create len) len accu + end else if n > 0 then begin (* n > 0: newline found in buffer *) + let res = string_create (n-1) in + ignore (unsafe_input chan res 0 (n-1)); + ignore (input_char chan); (* skip the newline *) + match accu with + [] -> res + | _ -> let len = len + n - 1 in + build_result (string_create len) len (res :: accu) + end else begin (* n < 0: newline not found *) + let beg = string_create (-n) in + ignore(unsafe_input chan beg 0 (-n)); + scan (beg :: accu) (len - n) + end + in scan [] 0 + +external input_byte : in_channel -> int = "caml_ml_input_char" +external input_binary_int : in_channel -> int = "caml_ml_input_int" +external input_value : in_channel -> 'a = "caml_input_value" +external seek_in : in_channel -> int -> unit = "caml_ml_seek_in" +external pos_in : in_channel -> int = "caml_ml_pos_in" +external in_channel_length : in_channel -> int = "caml_ml_channel_size" +external close_in : in_channel -> unit = "caml_ml_close_channel" +let close_in_noerr ic = (try close_in ic with _ -> ());; +external set_binary_mode_in : in_channel -> bool -> unit + = "caml_ml_set_binary_mode" + +(* Output functions on standard output *) + +let print_char c = output_char stdout c +let print_string s = output_string stdout s +let print_int i = output_string stdout (string_of_int i) +let print_float f = output_string stdout (string_of_float f) +let print_endline s = + output_string stdout s; output_char stdout '\n'; flush stdout +let print_newline () = output_char stdout '\n'; flush stdout + +(* Output functions on standard error *) + +let prerr_char c = output_char stderr c +let prerr_string s = output_string stderr s +let prerr_int i = output_string stderr (string_of_int i) +let prerr_float f = output_string stderr (string_of_float f) +let prerr_endline s = + output_string stderr s; output_char stderr '\n'; flush stderr +let prerr_newline () = output_char stderr '\n'; flush stderr + +(* Input functions on standard input *) + +let read_line () = flush stdout; input_line stdin +let read_int () = int_of_string(read_line()) +let read_float () = float_of_string(read_line()) + +(* Operations on large files *) + +module LargeFile = + struct + external seek_out : out_channel -> int64 -> unit = "caml_ml_seek_out_64" + external pos_out : out_channel -> int64 = "caml_ml_pos_out_64" + external out_channel_length : out_channel -> int64 + = "caml_ml_channel_size_64" + external seek_in : in_channel -> int64 -> unit = "caml_ml_seek_in_64" + external pos_in : in_channel -> int64 = "caml_ml_pos_in_64" + external in_channel_length : in_channel -> int64 = "caml_ml_channel_size_64" + end + +(* References *) + +type 'a ref = { mutable contents: 'a } +external ref: 'a -> 'a ref = "%makemutable" +external (!): 'a ref -> 'a = "%field0" +external (:=): 'a ref -> 'a -> unit = "%setfield0" +external incr: int ref -> unit = "%incr" +external decr: int ref -> unit = "%decr" + +(* Formats *) +type ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'c, 'c, 'd) format6 + +type ('a, 'b, 'c) format = ('a, 'b, 'c, 'c) format4 + +external format_of_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" + +external format_to_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string = "%identity" +external string_to_format : + string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" + +let (( ^^ ) : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('f, 'b, 'c, 'e, 'g, 'h) format6 -> + ('a, 'b, 'c, 'd, 'g, 'h) format6) = + fun fmt1 fmt2 -> + string_to_format (format_to_string fmt1 ^ format_to_string fmt2);; + +let string_of_format fmt = + let s = format_to_string fmt in + let l = string_length s in + let r = string_create l in + string_blit s 0 r 0 l; + r + +(* Miscellaneous *) + +external sys_exit : int -> 'a = "caml_sys_exit" + +let exit_function = ref flush_all + +let at_exit f = + let g = !exit_function in + exit_function := (fun () -> f(); g()) + +let do_at_exit () = (!exit_function) () + +let exit retcode = + do_at_exit (); + sys_exit retcode + +external register_named_value : string -> 'a -> unit + = "caml_register_named_value" + +let _ = register_named_value "Pervasives.do_at_exit" do_at_exit diff --git a/stdlib/pervasives.mli b/stdlib/pervasives.mli new file mode 100644 index 0000000..8a14184 --- /dev/null +++ b/stdlib/pervasives.mli @@ -0,0 +1,883 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: pervasives.mli,v 1.113 2008-10-06 13:33:21 doligez Exp $ *) + +(** The initially opened module. + + This module provides the basic operations over the built-in types + (numbers, booleans, strings, exceptions, references, lists, arrays, + input-output channels, ...) + + This module is automatically opened at the beginning of each compilation. + All components of this module can therefore be referred by their short + name, without prefixing them by [Pervasives]. +*) + +(** {6 Exceptions} *) + +external raise : exn -> 'a = "%raise" +(** Raise the given exception value *) + +val invalid_arg : string -> 'a +(** Raise exception [Invalid_argument] with the given string. *) + +val failwith : string -> 'a +(** Raise exception [Failure] with the given string. *) + +exception Exit +(** The [Exit] exception is not raised by any library function. It is + provided for use in your programs.*) + + +(** {6 Comparisons} *) + + +external ( = ) : 'a -> 'a -> bool = "%equal" +(** [e1 = e2] tests for structural equality of [e1] and [e2]. + Mutable structures (e.g. references and arrays) are equal + if and only if their current contents are structurally equal, + even if the two mutable objects are not the same physical object. + Equality between functional values raises [Invalid_argument]. + Equality between cyclic data structures may not terminate. *) + +external ( <> ) : 'a -> 'a -> bool = "%notequal" +(** Negation of {!Pervasives.(=)}. *) + +external ( < ) : 'a -> 'a -> bool = "%lessthan" +(** See {!Pervasives.(>=)}. *) + +external ( > ) : 'a -> 'a -> bool = "%greaterthan" +(** See {!Pervasives.(>=)}. *) + +external ( <= ) : 'a -> 'a -> bool = "%lessequal" +(** See {!Pervasives.(>=)}. *) + +external ( >= ) : 'a -> 'a -> bool = "%greaterequal" +(** Structural ordering functions. These functions coincide with + the usual orderings over integers, characters, strings + and floating-point numbers, and extend them to a + total ordering over all types. + The ordering is compatible with [(=)]. As in the case + of [(=)], mutable structures are compared by contents. + Comparison between functional values raises [Invalid_argument]. + Comparison between cyclic structures does not terminate. *) + +external compare : 'a -> 'a -> int = "%compare" +(** [compare x y] returns [0] if [x] is equal to [y], + a negative integer if [x] is less than [y], and a positive integer + if [x] is greater than [y]. The ordering implemented by [compare] + is compatible with the comparison predicates [=], [<] and [>] + defined above, with one difference on the treatment of the float value + {!Pervasives.nan}. Namely, the comparison predicates treat [nan] + as different from any other float value, including itself; + while [compare] treats [nan] as equal to itself and less than any + other float value. This treatment of [nan] ensures that [compare] + defines a total ordering relation. + + [compare] applied to functional values may raise [Invalid_argument]. + [compare] applied to cyclic structures may not terminate. + + The [compare] function can be used as the comparison function + required by the {!Set.Make} and {!Map.Make} functors, as well as + the {!List.sort} and {!Array.sort} functions. *) + +val min : 'a -> 'a -> 'a +(** Return the smaller of the two arguments. *) + +val max : 'a -> 'a -> 'a +(** Return the greater of the two arguments. *) + +external ( == ) : 'a -> 'a -> bool = "%eq" +(** [e1 == e2] tests for physical equality of [e1] and [e2]. + On integers and characters, physical equality is identical to structural + equality. On mutable structures, [e1 == e2] is true if and only if + physical modification of [e1] also affects [e2]. + On non-mutable structures, the behavior of [(==)] is + implementation-dependent; however, it is guaranteed that + [e1 == e2] implies [compare e1 e2 = 0]. *) + +external ( != ) : 'a -> 'a -> bool = "%noteq" +(** Negation of {!Pervasives.(==)}. *) + + +(** {6 Boolean operations} *) + + +external not : bool -> bool = "%boolnot" +(** The boolean negation. *) + +external ( && ) : bool -> bool -> bool = "%sequand" +(** The boolean ``and''. Evaluation is sequential, left-to-right: + in [e1 && e2], [e1] is evaluated first, and if it returns [false], + [e2] is not evaluated at all. *) + +external ( & ) : bool -> bool -> bool = "%sequand" +(** @deprecated {!Pervasives.(&&)} should be used instead. *) + +external ( || ) : bool -> bool -> bool = "%sequor" +(** The boolean ``or''. Evaluation is sequential, left-to-right: + in [e1 || e2], [e1] is evaluated first, and if it returns [true], + [e2] is not evaluated at all. *) + +external ( or ) : bool -> bool -> bool = "%sequor" +(** @deprecated {!Pervasives.(||)} should be used instead.*) + + +(** {6 Integer arithmetic} *) + +(** Integers are 31 bits wide (or 63 bits on 64-bit processors). + All operations are taken modulo 2{^31} (or 2{^63}). + They do not fail on overflow. *) + +external ( ~- ) : int -> int = "%negint" +(** Unary negation. You can also write [-e] instead of [~-e]. *) + +external succ : int -> int = "%succint" +(** [succ x] is [x+1]. *) + +external pred : int -> int = "%predint" +(** [pred x] is [x-1]. *) + +external ( + ) : int -> int -> int = "%addint" +(** Integer addition. *) + +external ( - ) : int -> int -> int = "%subint" +(** Integer subtraction. *) + +external ( * ) : int -> int -> int = "%mulint" +(** Integer multiplication. *) + +external ( / ) : int -> int -> int = "%divint" +(** Integer division. + Raise [Division_by_zero] if the second argument is 0. + Integer division rounds the real quotient of its arguments towards zero. + More precisely, if [x >= 0] and [y > 0], [x / y] is the greatest integer + less than or equal to the real quotient of [x] by [y]. Moreover, + [(-x) / y = x / (-y) = -(x / y)]. *) + +external ( mod ) : int -> int -> int = "%modint" +(** Integer remainder. If [y] is not zero, the result + of [x mod y] satisfies the following properties: + [x = (x / y) * y + x mod y] and + [abs(x mod y) <= abs(y)-1]. + If [y = 0], [x mod y] raises [Division_by_zero]. + Notice that [x mod y] is nonpositive if and only if [x < 0]. + Raise [Division_by_zero] if [y] is zero. *) + +val abs : int -> int +(** Return the absolute value of the argument. Note that this may be + negative if the argument is [min_int]. *) + +val max_int : int +(** The greatest representable integer. *) + +val min_int : int +(** The smallest representable integer. *) + + + +(** {7 Bitwise operations} *) + + +external ( land ) : int -> int -> int = "%andint" +(** Bitwise logical and. *) + +external ( lor ) : int -> int -> int = "%orint" +(** Bitwise logical or. *) + +external ( lxor ) : int -> int -> int = "%xorint" +(** Bitwise logical exclusive or. *) + +val lnot : int -> int +(** Bitwise logical negation. *) + +external ( lsl ) : int -> int -> int = "%lslint" +(** [n lsl m] shifts [n] to the left by [m] bits. + The result is unspecified if [m < 0] or [m >= bitsize], + where [bitsize] is [32] on a 32-bit platform and + [64] on a 64-bit platform. *) + +external ( lsr ) : int -> int -> int = "%lsrint" +(** [n lsr m] shifts [n] to the right by [m] bits. + This is a logical shift: zeroes are inserted regardless of + the sign of [n]. + The result is unspecified if [m < 0] or [m >= bitsize]. *) + +external ( asr ) : int -> int -> int = "%asrint" +(** [n asr m] shifts [n] to the right by [m] bits. + This is an arithmetic shift: the sign bit of [n] is replicated. + The result is unspecified if [m < 0] or [m >= bitsize]. *) + + +(** {6 Floating-point arithmetic} + + Caml's floating-point numbers follow the + IEEE 754 standard, using double precision (64 bits) numbers. + Floating-point operations never raise an exception on overflow, + underflow, division by zero, etc. Instead, special IEEE numbers + are returned as appropriate, such as [infinity] for [1.0 /. 0.0], + [neg_infinity] for [-1.0 /. 0.0], and [nan] (``not a number'') + for [0.0 /. 0.0]. These special numbers then propagate through + floating-point computations as expected: for instance, + [1.0 /. infinity] is [0.0], and any operation with [nan] as + argument returns [nan] as result. +*) + +external ( ~-. ) : float -> float = "%negfloat" +(** Unary negation. You can also write [-.e] instead of [~-.e]. *) + +external ( +. ) : float -> float -> float = "%addfloat" +(** Floating-point addition *) + +external ( -. ) : float -> float -> float = "%subfloat" +(** Floating-point subtraction *) + +external ( *. ) : float -> float -> float = "%mulfloat" +(** Floating-point multiplication *) + +external ( /. ) : float -> float -> float = "%divfloat" +(** Floating-point division. *) + +external ( ** ) : float -> float -> float = "caml_power_float" "pow" "float" +(** Exponentiation *) + +external sqrt : float -> float = "caml_sqrt_float" "sqrt" "float" +(** Square root *) + +external exp : float -> float = "caml_exp_float" "exp" "float" +(** Exponential. *) + +external log : float -> float = "caml_log_float" "log" "float" +(** Natural logarithm. *) + +external log10 : float -> float = "caml_log10_float" "log10" "float" +(** Base 10 logarithm. *) + +external cos : float -> float = "caml_cos_float" "cos" "float" +(** See {!Pervasives.atan2}. *) + +external sin : float -> float = "caml_sin_float" "sin" "float" +(** See {!Pervasives.atan2}. *) + +external tan : float -> float = "caml_tan_float" "tan" "float" +(** See {!Pervasives.atan2}. *) + +external acos : float -> float = "caml_acos_float" "acos" "float" +(** See {!Pervasives.atan2}. *) + +external asin : float -> float = "caml_asin_float" "asin" "float" +(** See {!Pervasives.atan2}. *) + +external atan : float -> float = "caml_atan_float" "atan" "float" +(** See {!Pervasives.atan2}. *) + +external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float" +(** The usual trigonometric functions. *) + +external cosh : float -> float = "caml_cosh_float" "cosh" "float" +(** See {!Pervasives.tanh}. *) + +external sinh : float -> float = "caml_sinh_float" "sinh" "float" +(** See {!Pervasives.tanh}. *) + +external tanh : float -> float = "caml_tanh_float" "tanh" "float" +(** The usual hyperbolic trigonometric functions. *) + +external ceil : float -> float = "caml_ceil_float" "ceil" "float" +(** See {!Pervasives.floor}. *) + +external floor : float -> float = "caml_floor_float" "floor" "float" +(** Round the given float to an integer value. + [floor f] returns the greatest integer value less than or + equal to [f]. + [ceil f] returns the least integer value greater than or + equal to [f]. *) + +external abs_float : float -> float = "%absfloat" +(** Return the absolute value of the argument. *) + +external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float" +(** [mod_float a b] returns the remainder of [a] with respect to + [b]. The returned value is [a -. n *. b], where [n] + is the quotient [a /. b] rounded towards zero to an integer. *) + +external frexp : float -> float * int = "caml_frexp_float" +(** [frexp f] returns the pair of the significant + and the exponent of [f]. When [f] is zero, the + significant [x] and the exponent [n] of [f] are equal to + zero. When [f] is non-zero, they are defined by + [f = x *. 2 ** n] and [0.5 <= x < 1.0]. *) + +external ldexp : float -> int -> float = "caml_ldexp_float" +(** [ldexp x n] returns [x *. 2 ** n]. *) + +external modf : float -> float * float = "caml_modf_float" +(** [modf f] returns the pair of the fractional and integral + part of [f]. *) + +external float : int -> float = "%floatofint" +(** Same as {!Pervasives.float_of_int}. *) + +external float_of_int : int -> float = "%floatofint" +(** Convert an integer to floating-point. *) + +external truncate : float -> int = "%intoffloat" +(** Same as {!Pervasives.int_of_float}. *) + +external int_of_float : float -> int = "%intoffloat" +(** Truncate the given floating-point number to an integer. + The result is unspecified if the argument is [nan] or falls outside the + range of representable integers. *) + +val infinity : float +(** Positive infinity. *) + +val neg_infinity : float +(** Negative infinity. *) + +val nan : float +(** A special floating-point value denoting the result of an + undefined operation such as [0.0 /. 0.0]. Stands for + ``not a number''. Any floating-point operation with [nan] as + argument returns [nan] as result. As for floating-point comparisons, + [=], [<], [<=], [>] and [>=] return [false] and [<>] returns [true] + if one or both of their arguments is [nan]. *) + +val max_float : float +(** The largest positive finite value of type [float]. *) + +val min_float : float +(** The smallest positive, non-zero, non-denormalized value of type [float]. *) + +val epsilon_float : float +(** The difference between [1.0] and the smallest exactly representable + floating-point number greater than [1.0]. *) + +type fpclass = + FP_normal (** Normal number, none of the below *) + | FP_subnormal (** Number very close to 0.0, has reduced precision *) + | FP_zero (** Number is 0.0 or -0.0 *) + | FP_infinite (** Number is positive or negative infinity *) + | FP_nan (** Not a number: result of an undefined operation *) +(** The five classes of floating-point numbers, as determined by + the {!Pervasives.classify_float} function. *) + +external classify_float : float -> fpclass = "caml_classify_float" +(** Return the class of the given floating-point number: + normal, subnormal, zero, infinite, or not a number. *) + + +(** {6 String operations} + + More string operations are provided in module {!String}. +*) + +val ( ^ ) : string -> string -> string +(** String concatenation. *) + + +(** {6 Character operations} + + More character operations are provided in module {!Char}. +*) + +external int_of_char : char -> int = "%identity" +(** Return the ASCII code of the argument. *) + +val char_of_int : int -> char +(** Return the character with the given ASCII code. + Raise [Invalid_argument "char_of_int"] if the argument is + outside the range 0--255. *) + + +(** {6 Unit operations} *) + +external ignore : 'a -> unit = "%ignore" +(** Discard the value of its argument and return [()]. + For instance, [ignore(f x)] discards the result of + the side-effecting function [f]. It is equivalent to + [f x; ()], except that the latter may generate a + compiler warning; writing [ignore(f x)] instead + avoids the warning. *) + + +(** {6 String conversion functions} *) + +val string_of_bool : bool -> string +(** Return the string representation of a boolean. *) + +val bool_of_string : string -> bool +(** Convert the given string to a boolean. + Raise [Invalid_argument "bool_of_string"] if the string is not + ["true"] or ["false"]. *) + +val string_of_int : int -> string +(** Return the string representation of an integer, in decimal. *) + +external int_of_string : string -> int = "caml_int_of_string" +(** Convert the given string to an integer. + The string is read in decimal (by default) or in hexadecimal (if it + begins with [0x] or [0X]), octal (if it begins with [0o] or [0O]), + or binary (if it begins with [0b] or [0B]). + Raise [Failure "int_of_string"] if the given string is not + a valid representation of an integer, or if the integer represented + exceeds the range of integers representable in type [int]. *) + +val string_of_float : float -> string +(** Return the string representation of a floating-point number. *) + +external float_of_string : string -> float = "caml_float_of_string" +(** Convert the given string to a float. Raise [Failure "float_of_string"] + if the given string is not a valid representation of a float. *) + + + +(** {6 Pair operations} *) + +external fst : 'a * 'b -> 'a = "%field0" +(** Return the first component of a pair. *) + +external snd : 'a * 'b -> 'b = "%field1" +(** Return the second component of a pair. *) + + +(** {6 List operations} + + More list operations are provided in module {!List}. +*) + +val ( @ ) : 'a list -> 'a list -> 'a list +(** List concatenation. *) + + +(** {6 Input/output} *) + +type in_channel +(** The type of input channel. *) + +type out_channel +(** The type of output channel. *) + +val stdin : in_channel +(** The standard input for the process. *) + +val stdout : out_channel +(** The standard output for the process. *) + +val stderr : out_channel +(** The standard error ouput for the process. *) + + +(** {7 Output functions on standard output} *) + +val print_char : char -> unit +(** Print a character on standard output. *) + +val print_string : string -> unit +(** Print a string on standard output. *) + +val print_int : int -> unit +(** Print an integer, in decimal, on standard output. *) + +val print_float : float -> unit +(** Print a floating-point number, in decimal, on standard output. *) + +val print_endline : string -> unit +(** Print a string, followed by a newline character, on + standard output and flush standard output. *) + +val print_newline : unit -> unit +(** Print a newline character on standard output, and flush + standard output. This can be used to simulate line + buffering of standard output. *) + + +(** {7 Output functions on standard error} *) + +val prerr_char : char -> unit +(** Print a character on standard error. *) + +val prerr_string : string -> unit +(** Print a string on standard error. *) + +val prerr_int : int -> unit +(** Print an integer, in decimal, on standard error. *) + +val prerr_float : float -> unit +(** Print a floating-point number, in decimal, on standard error. *) + +val prerr_endline : string -> unit +(** Print a string, followed by a newline character on standard error + and flush standard error. *) + +val prerr_newline : unit -> unit +(** Print a newline character on standard error, and flush + standard error. *) + + +(** {7 Input functions on standard input} *) + +val read_line : unit -> string +(** Flush standard output, then read characters from standard input + until a newline character is encountered. Return the string of + all characters read, without the newline character at the end. *) + +val read_int : unit -> int +(** Flush standard output, then read one line from standard input + and convert it to an integer. Raise [Failure "int_of_string"] + if the line read is not a valid representation of an integer. *) + +val read_float : unit -> float +(** Flush standard output, then read one line from standard input + and convert it to a floating-point number. + The result is unspecified if the line read is not a valid + representation of a floating-point number. *) + +(** {7 General output functions} *) + + +type open_flag = + Open_rdonly (** open for reading. *) + | Open_wronly (** open for writing. *) + | Open_append (** open for appending: always write at end of file. *) + | Open_creat (** create the file if it does not exist. *) + | Open_trunc (** empty the file if it already exists. *) + | Open_excl (** fail if Open_creat and the file already exists. *) + | Open_binary (** open in binary mode (no conversion). *) + | Open_text (** open in text mode (may perform conversions). *) + | Open_nonblock (** open in non-blocking mode. *) +(** Opening modes for {!Pervasives.open_out_gen} and + {!Pervasives.open_in_gen}. *) + +val open_out : string -> out_channel +(** Open the named file for writing, and return a new output channel + on that file, positionned at the beginning of the file. The + file is truncated to zero length if it already exists. It + is created if it does not already exists. + Raise [Sys_error] if the file could not be opened. *) + +val open_out_bin : string -> out_channel +(** Same as {!Pervasives.open_out}, but the file is opened in binary mode, + so that no translation takes place during writes. On operating + systems that do not distinguish between text mode and binary + mode, this function behaves like {!Pervasives.open_out}. *) + +val open_out_gen : open_flag list -> int -> string -> out_channel +(** [open_out_gen mode perm filename] opens the named file for writing, + as described above. The extra argument [mode] + specify the opening mode. The extra argument [perm] specifies + the file permissions, in case the file must be created. + {!Pervasives.open_out} and {!Pervasives.open_out_bin} are special + cases of this function. *) + +val flush : out_channel -> unit +(** Flush the buffer associated with the given output channel, + performing all pending writes on that channel. + Interactive programs must be careful about flushing standard + output and standard error at the right time. *) + +val flush_all : unit -> unit +(** Flush all open output channels; ignore errors. *) + +val output_char : out_channel -> char -> unit +(** Write the character on the given output channel. *) + +val output_string : out_channel -> string -> unit +(** Write the string on the given output channel. *) + +val output : out_channel -> string -> int -> int -> unit +(** [output oc buf pos len] writes [len] characters from string [buf], + starting at offset [pos], to the given output channel [oc]. + Raise [Invalid_argument "output"] if [pos] and [len] do not + designate a valid substring of [buf]. *) + +val output_byte : out_channel -> int -> unit +(** Write one 8-bit integer (as the single character with that code) + on the given output channel. The given integer is taken modulo + 256. *) + +val output_binary_int : out_channel -> int -> unit +(** Write one integer in binary format (4 bytes, big-endian) + on the given output channel. + The given integer is taken modulo 2{^32}. + The only reliable way to read it back is through the + {!Pervasives.input_binary_int} function. The format is compatible across + all machines for a given version of Objective Caml. *) + +val output_value : out_channel -> 'a -> unit +(** Write the representation of a structured value of any type + to a channel. Circularities and sharing inside the value + are detected and preserved. The object can be read back, + by the function {!Pervasives.input_value}. See the description of module + {!Marshal} for more information. {!Pervasives.output_value} is equivalent + to {!Marshal.to_channel} with an empty list of flags. *) + +val seek_out : out_channel -> int -> unit +(** [seek_out chan pos] sets the current writing position to [pos] + for channel [chan]. This works only for regular files. On + files of other kinds (such as terminals, pipes and sockets), + the behavior is unspecified. *) + +val pos_out : out_channel -> int +(** Return the current writing position for the given channel. Does + not work on channels opened with the [Open_append] flag (returns + unspecified results). *) + +val out_channel_length : out_channel -> int +(** Return the size (number of characters) of the regular file + on which the given channel is opened. If the channel is opened + on a file that is not a regular file, the result is meaningless. *) + +val close_out : out_channel -> unit +(** Close the given channel, flushing all buffered write operations. + Output functions raise a [Sys_error] exception when they are + applied to a closed output channel, except [close_out] and [flush], + which do nothing when applied to an already closed channel. + Note that [close_out] may raise [Sys_error] if the operating + system signals an error when flushing or closing. *) + +val close_out_noerr : out_channel -> unit +(** Same as [close_out], but ignore all errors. *) + +val set_binary_mode_out : out_channel -> bool -> unit +(** [set_binary_mode_out oc true] sets the channel [oc] to binary + mode: no translations take place during output. + [set_binary_mode_out oc false] sets the channel [oc] to text + mode: depending on the operating system, some translations + may take place during output. For instance, under Windows, + end-of-lines will be translated from [\n] to [\r\n]. + This function has no effect under operating systems that + do not distinguish between text mode and binary mode. *) + + +(** {7 General input functions} *) + +val open_in : string -> in_channel +(** Open the named file for reading, and return a new input channel + on that file, positionned at the beginning of the file. + Raise [Sys_error] if the file could not be opened. *) + +val open_in_bin : string -> in_channel +(** Same as {!Pervasives.open_in}, but the file is opened in binary mode, + so that no translation takes place during reads. On operating + systems that do not distinguish between text mode and binary + mode, this function behaves like {!Pervasives.open_in}. *) + +val open_in_gen : open_flag list -> int -> string -> in_channel +(** [open_in_gen mode perm filename] opens the named file for reading, + as described above. The extra arguments + [mode] and [perm] specify the opening mode and file permissions. + {!Pervasives.open_in} and {!Pervasives.open_in_bin} are special + cases of this function. *) + +val input_char : in_channel -> char +(** Read one character from the given input channel. + Raise [End_of_file] if there are no more characters to read. *) + +val input_line : in_channel -> string +(** Read characters from the given input channel, until a + newline character is encountered. Return the string of + all characters read, without the newline character at the end. + Raise [End_of_file] if the end of the file is reached + at the beginning of line. *) + +val input : in_channel -> string -> int -> int -> int +(** [input ic buf pos len] reads up to [len] characters from + the given channel [ic], storing them in string [buf], starting at + character number [pos]. + It returns the actual number of characters read, between 0 and + [len] (inclusive). + A return value of 0 means that the end of file was reached. + A return value between 0 and [len] exclusive means that + not all requested [len] characters were read, either because + no more characters were available at that time, or because + the implementation found it convenient to do a partial read; + [input] must be called again to read the remaining characters, + if desired. (See also {!Pervasives.really_input} for reading + exactly [len] characters.) + Exception [Invalid_argument "input"] is raised if [pos] and [len] + do not designate a valid substring of [buf]. *) + +val really_input : in_channel -> string -> int -> int -> unit +(** [really_input ic buf pos len] reads [len] characters from channel [ic], + storing them in string [buf], starting at character number [pos]. + Raise [End_of_file] if the end of file is reached before [len] + characters have been read. + Raise [Invalid_argument "really_input"] if + [pos] and [len] do not designate a valid substring of [buf]. *) + +val input_byte : in_channel -> int +(** Same as {!Pervasives.input_char}, but return the 8-bit integer representing + the character. + Raise [End_of_file] if an end of file was reached. *) + +val input_binary_int : in_channel -> int +(** Read an integer encoded in binary format (4 bytes, big-endian) + from the given input channel. See {!Pervasives.output_binary_int}. + Raise [End_of_file] if an end of file was reached while reading the + integer. *) + +val input_value : in_channel -> 'a +(** Read the representation of a structured value, as produced + by {!Pervasives.output_value}, and return the corresponding value. + This function is identical to {!Marshal.from_channel}; + see the description of module {!Marshal} for more information, + in particular concerning the lack of type safety. *) + +val seek_in : in_channel -> int -> unit +(** [seek_in chan pos] sets the current reading position to [pos] + for channel [chan]. This works only for regular files. On + files of other kinds, the behavior is unspecified. *) + +val pos_in : in_channel -> int +(** Return the current reading position for the given channel. *) + +val in_channel_length : in_channel -> int +(** Return the size (number of characters) of the regular file + on which the given channel is opened. If the channel is opened + on a file that is not a regular file, the result is meaningless. + The returned size does not take into account the end-of-line + translations that can be performed when reading from a channel + opened in text mode. *) + +val close_in : in_channel -> unit +(** Close the given channel. Input functions raise a [Sys_error] + exception when they are applied to a closed input channel, + except [close_in], which does nothing when applied to an already + closed channel. Note that [close_in] may raise [Sys_error] if + the operating system signals an error. *) + +val close_in_noerr : in_channel -> unit +(** Same as [close_in], but ignore all errors. *) + +val set_binary_mode_in : in_channel -> bool -> unit +(** [set_binary_mode_in ic true] sets the channel [ic] to binary + mode: no translations take place during input. + [set_binary_mode_out ic false] sets the channel [ic] to text + mode: depending on the operating system, some translations + may take place during input. For instance, under Windows, + end-of-lines will be translated from [\r\n] to [\n]. + This function has no effect under operating systems that + do not distinguish between text mode and binary mode. *) + +(** {7 Operations on large files} *) + +module LargeFile : + sig + val seek_out : out_channel -> int64 -> unit + val pos_out : out_channel -> int64 + val out_channel_length : out_channel -> int64 + val seek_in : in_channel -> int64 -> unit + val pos_in : in_channel -> int64 + val in_channel_length : in_channel -> int64 + end +(** Operations on large files. + This sub-module provides 64-bit variants of the channel functions + that manipulate file positions and file sizes. By representing + positions and sizes by 64-bit integers (type [int64]) instead of + regular integers (type [int]), these alternate functions allow + operating on files whose sizes are greater than [max_int]. *) + +(** {6 References} *) + +type 'a ref = { mutable contents : 'a } +(** The type of references (mutable indirection cells) containing + a value of type ['a]. *) + +external ref : 'a -> 'a ref = "%makemutable" +(** Return a fresh reference containing the given value. *) + +external ( ! ) : 'a ref -> 'a = "%field0" +(** [!r] returns the current contents of reference [r]. + Equivalent to [fun r -> r.contents]. *) + +external ( := ) : 'a ref -> 'a -> unit = "%setfield0" +(** [r := a] stores the value of [a] in reference [r]. + Equivalent to [fun r v -> r.contents <- v]. *) + +external incr : int ref -> unit = "%incr" +(** Increment the integer contained in the given reference. + Equivalent to [fun r -> r := succ !r]. *) + +external decr : int ref -> unit = "%decr" +(** Decrement the integer contained in the given reference. + Equivalent to [fun r -> r := pred !r]. *) + + +(** {6 Operations on format strings} *) + +(** Format strings are used to read and print data using formatted input + functions in module {!Scanf} and formatted output in modules {!Printf} and + {!Format}. *) + +(** Format strings have a general and highly polymorphic type + [('a, 'b, 'c, 'd, 'e, 'f) format6]. Type [format6] is built in. + The two simplified types, [format] and [format4] below are + included for backward compatibility with earlier releases of Objective + Caml. + ['a] is the type of the parameters of the format, + ['c] is the result type for the "printf"-style function, + and ['b] is the type of the first argument given to + [%a] and [%t] printing functions. *) +type ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'c, 'c, 'd) format6 + +type ('a, 'b, 'c) format = ('a, 'b, 'c, 'c) format4 + +val string_of_format : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string +(** Converts a format string into a string. *) + +external format_of_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" +(** [format_of_string s] returns a format string read from the string + literal [s]. *) + +val ( ^^ ) : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + ('f, 'b, 'c, 'e, 'g, 'h) format6 -> + ('a, 'b, 'c, 'd, 'g, 'h) format6 +(** [f1 ^^ f2] catenates formats [f1] and [f2]. The result is a format + that accepts arguments from [f1], then arguments from [f2]. *) + + +(** {6 Program termination} *) + + +val exit : int -> 'a +(** Terminate the process, returning the given status code + to the operating system: usually 0 to indicate no errors, + and a small positive integer to indicate failure. + All open output channels are flushed with flush_all. + An implicit [exit 0] is performed each time a program + terminates normally. An implicit [exit 2] is performed if the program + terminates early because of an uncaught exception. *) + +val at_exit : (unit -> unit) -> unit +(** Register the given function to be called at program + termination time. The functions registered with [at_exit] + will be called when the program executes {!Pervasives.exit}, + or terminates, either normally or because of an uncaught exception. + The functions are called in ``last in, first out'' order: + the function most recently added with [at_exit] is called first. *) + + +(**/**) + +(** {6 For system use only, not for the casual user} *) + +val valid_float_lexem : string -> string + +val unsafe_really_input : in_channel -> string -> int -> int -> unit + +val do_at_exit : unit -> unit diff --git a/stdlib/printexc.ml b/stdlib/printexc.ml new file mode 100644 index 0000000..6d45800 --- /dev/null +++ b/stdlib/printexc.ml @@ -0,0 +1,127 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: printexc.ml,v 1.19 2008-03-14 13:47:24 xleroy Exp $ *) + +open Printf;; + +let locfmt = format_of_string "File \"%s\", line %d, characters %d-%d: %s";; + +let field x i = + let f = Obj.field x i in + if not (Obj.is_block f) then + sprintf "%d" (Obj.magic f : int) (* can also be a char *) + else if Obj.tag f = Obj.string_tag then + sprintf "%S" (Obj.magic f : string) + else if Obj.tag f = Obj.double_tag then + string_of_float (Obj.magic f : float) + else + "_" +;; +let rec other_fields x i = + if i >= Obj.size x then "" + else sprintf ", %s%s" (field x i) (other_fields x (i+1)) +;; +let fields x = + match Obj.size x with + | 0 -> "" + | 1 -> "" + | 2 -> sprintf "(%s)" (field x 1) + | n -> sprintf "(%s%s)" (field x 1) (other_fields x 2) +;; + +let to_string = function + | Out_of_memory -> "Out of memory" + | Stack_overflow -> "Stack overflow" + | Match_failure(file, line, char) -> + sprintf locfmt file line char (char+5) "Pattern matching failed" + | Assert_failure(file, line, char) -> + sprintf locfmt file line char (char+6) "Assertion failed" + | x -> + let x = Obj.repr x in + let constructor = (Obj.magic(Obj.field (Obj.field x 0) 0) : string) in + constructor ^ (fields x) +;; + +let print fct arg = + try + fct arg + with x -> + eprintf "Uncaught exception: %s\n" (to_string x); + flush stderr; + raise x + +let catch fct arg = + try + fct arg + with x -> + flush stdout; + eprintf "Uncaught exception: %s\n" (to_string x); + exit 2 + +type loc_info = + | Known_location of bool (* is_raise *) + * string (* filename *) + * int (* line number *) + * int (* start char *) + * int (* end char *) + | Unknown_location of bool (*is_raise*) + +external get_exception_backtrace: + unit -> loc_info array option = "caml_get_exception_backtrace" + +let format_loc_info pos li = + let is_raise = + match li with + | Known_location(is_raise, _, _, _, _) -> is_raise + | Unknown_location(is_raise) -> is_raise in + let info = + if is_raise then + if pos = 0 then "Raised at" else "Re-raised at" + else + if pos = 0 then "Raised by primitive operation at" else "Called from" + in + match li with + | Known_location(is_raise, filename, lineno, startchar, endchar) -> + sprintf "%s file \"%s\", line %d, characters %d-%d" + info filename lineno startchar endchar + | Unknown_location(is_raise) -> + sprintf "%s unknown location" + info + +let print_backtrace outchan = + match get_exception_backtrace() with + | None -> + fprintf outchan + "(Program not linked with -g, cannot print stack backtrace)\n" + | Some a -> + for i = 0 to Array.length a - 1 do + if a.(i) <> Unknown_location true then + fprintf outchan "%s\n" (format_loc_info i a.(i)) + done + +let get_backtrace () = + match get_exception_backtrace() with + | None -> + "(Program not linked with -g, cannot print stack backtrace)\n" + | Some a -> + let b = Buffer.create 1024 in + for i = 0 to Array.length a - 1 do + if a.(i) <> Unknown_location true then + bprintf b "%s\n" (format_loc_info i a.(i)) + done; + Buffer.contents b + +external record_backtrace: bool -> unit = "caml_record_backtrace" +external backtrace_status: unit -> bool = "caml_backtrace_status" + diff --git a/stdlib/printexc.mli b/stdlib/printexc.mli new file mode 100644 index 0000000..47efd05 --- /dev/null +++ b/stdlib/printexc.mli @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: printexc.mli,v 1.13 2008-03-14 13:47:24 xleroy Exp $ *) + +(** Facilities for printing exceptions. *) + +val to_string : exn -> string +(** [Printexc.to_string e] returns a string representation of + the exception [e]. *) + +val print : ('a -> 'b) -> 'a -> 'b +(** [Printexc.print fn x] applies [fn] to [x] and returns the result. + If the evaluation of [fn x] raises any exception, the + name of the exception is printed on standard error output, + and the exception is raised again. + The typical use is to catch and report exceptions that + escape a function application. *) + +val catch : ('a -> 'b) -> 'a -> 'b +(** [Printexc.catch fn x] is similar to {!Printexc.print}, but + aborts the program with exit code 2 after printing the + uncaught exception. This function is deprecated: the runtime + system is now able to print uncaught exceptions as precisely + as [Printexc.catch] does. Moreover, calling [Printexc.catch] + makes it harder to track the location of the exception + using the debugger or the stack backtrace facility. + So, do not use [Printexc.catch] in new code. *) + +val print_backtrace: out_channel -> unit +(** [Printexc.print_backtrace oc] prints an exception backtrace + on the output channel [oc]. The backtrace lists the program + locations where the most-recently raised exception was raised + and where it was propagated through function calls. *) + +val get_backtrace: unit -> string +(** [Printexc.get_backtrace ()] returns a string containing the + same exception backtrace that [Printexc.print_backtrace] would + print. *) + +val record_backtrace: bool -> unit +(** [Printexc.record_backtrace b] turns recording of exception backtraces + on (if [b = true]) or off (if [b = false]). Initially, backtraces + are not recorded, unless the [b] flag is given to the program + through the [OCAMLRUNPARAM] variable. *) + +val backtrace_status: unit -> bool +(** [Printexc.backtrace_status()] returns [true] if exception + backtraces are currently recorded, [false] if not. *) diff --git a/stdlib/printf.ml b/stdlib/printf.ml new file mode 100644 index 0000000..5f3c34f --- /dev/null +++ b/stdlib/printf.ml @@ -0,0 +1,652 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: printf.ml,v 1.58 2008-09-27 20:50:01 weis Exp $ *) + +external format_float: string -> float -> string + = "caml_format_float" +external format_int: string -> int -> string + = "caml_format_int" +external format_int32: string -> int32 -> string + = "caml_int32_format" +external format_nativeint: string -> nativeint -> string + = "caml_nativeint_format" +external format_int64: string -> int64 -> string + = "caml_int64_format" + +module Sformat = struct + + type index;; + + external unsafe_index_of_int : int -> index = "%identity" + ;; + let index_of_int i = + if i >= 0 then unsafe_index_of_int i + else failwith ("Sformat.index_of_int: negative argument " ^ string_of_int i) + ;; + external int_of_index : index -> int = "%identity" + ;; + + let add_int_index i idx = index_of_int (i + int_of_index idx);; + let succ_index = add_int_index 1;; + (* Litteral position are one-based (hence pred p instead of p). *) + let index_of_litteral_position p = index_of_int (pred p);; + + external length : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int + = "%string_length" + ;; + external get : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int -> char + = "%string_safe_get" + ;; + external unsafe_get : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int -> char + = "%string_unsafe_get" + ;; + external unsafe_to_string : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string + = "%identity" + ;; + let sub fmt idx len = + String.sub (unsafe_to_string fmt) (int_of_index idx) len + ;; + let to_string fmt = sub fmt (unsafe_index_of_int 0) (length fmt) + ;; + +end +;; + +let bad_conversion sfmt i c = + invalid_arg + ("Printf: bad conversion %" ^ String.make 1 c ^ ", at char number " ^ + string_of_int i ^ " in format string ``" ^ sfmt ^ "''") +;; + +let bad_conversion_format fmt i c = + bad_conversion (Sformat.to_string fmt) i c +;; + +let incomplete_format fmt = + invalid_arg + ("Printf: premature end of format string ``" ^ + Sformat.to_string fmt ^ "''") +;; + +(* Parses a string conversion to return the specified length and the padding direction. *) +let parse_string_conversion sfmt = + let rec parse neg i = + if i >= String.length sfmt then (0, neg) else + match String.unsafe_get sfmt i with + | '1'..'9' -> + (int_of_string + (String.sub sfmt i (String.length sfmt - i - 1)), + neg) + | '-' -> + parse true (succ i) + | _ -> + parse neg (succ i) in + try parse false 1 with + | Failure _ -> bad_conversion sfmt 0 's' +;; + +(* Pad a (sub) string into a blank string of length [p], + on the right if [neg] is true, on the left otherwise. *) +let pad_string pad_char p neg s i len = + if p = len && i = 0 then s else + if p <= len then String.sub s i len else + let res = String.make p pad_char in + if neg + then String.blit s i res 0 len + else String.blit s i res (p - len) len; + res + +(* Format a string given a %s format, e.g. %40s or %-20s. + To do ?: ignore other flags (#, +, etc). *) +let format_string sfmt s = + let (p, neg) = parse_string_conversion sfmt in + pad_string ' ' p neg s 0 (String.length s) +;; + +(* Extract a format string out of [fmt] between [start] and [stop] inclusive. + ['*'] in the format are replaced by integers taken from the [widths] list. + [extract_format] returns a string which is the string representation of + the resulting format string. *) +let extract_format fmt start stop widths = + let skip_positional_spec start = + match Sformat.unsafe_get fmt start with + | '0'..'9' -> + let rec skip_int_litteral i = + match Sformat.unsafe_get fmt i with + | '0'..'9' -> skip_int_litteral (succ i) + | '$' -> succ i + | _ -> start in + skip_int_litteral (succ start) + | _ -> start in + let start = skip_positional_spec (succ start) in + let b = Buffer.create (stop - start + 10) in + Buffer.add_char b '%'; + let rec fill_format i widths = + if i <= stop then + match (Sformat.unsafe_get fmt i, widths) with + | ('*', h :: t) -> + Buffer.add_string b (string_of_int h); + let i = skip_positional_spec (succ i) in + fill_format i t + | ('*', []) -> + assert false (* should not happen *) + | (c, _) -> + Buffer.add_char b c; fill_format (succ i) widths in + fill_format start (List.rev widths); + Buffer.contents b +;; + +let extract_format_int conv fmt start stop widths = + let sfmt = extract_format fmt start stop widths in + match conv with + | 'n' | 'N' -> + sfmt.[String.length sfmt - 1] <- 'u'; + sfmt + | _ -> sfmt +;; + +(* Returns the position of the next character following the meta format + string, starting from position [i], inside a given format [fmt]. + According to the character [conv], the meta format string is + enclosed by the delimitors %{ and %} (when [conv = '{']) or %( and + %) (when [conv = '(']). Hence, [sub_format] returns the index of + the character following the [')'] or ['}'] that ends the meta format, + according to the character [conv]. *) +let sub_format incomplete_format bad_conversion_format conv fmt i = + let len = Sformat.length fmt in + let rec sub_fmt c i = + let close = if c = '(' then ')' else (* '{' *) '}' in + let rec sub j = + if j >= len then incomplete_format fmt else + match Sformat.get fmt j with + | '%' -> sub_sub (succ j) + | _ -> sub (succ j) + and sub_sub j = + if j >= len then incomplete_format fmt else + match Sformat.get fmt j with + | '(' | '{' as c -> + let j = sub_fmt c (succ j) in + sub (succ j) + | '}' | ')' as c -> + if c = close then succ j else bad_conversion_format fmt i c + | _ -> sub (succ j) in + sub i in + sub_fmt conv i +;; + +let sub_format_for_printf conv = + sub_format incomplete_format bad_conversion_format conv;; + +let iter_on_format_args fmt add_conv add_char = + + let lim = Sformat.length fmt - 1 in + + let rec scan_flags skip i = + if i > lim then incomplete_format fmt else + match Sformat.unsafe_get fmt i with + | '*' -> scan_flags skip (add_conv skip i 'i') + (* | '$' -> scan_flags skip (succ i) *** PR#4321 *) + | '#' | '-' | ' ' | '+' -> scan_flags skip (succ i) + | '_' -> scan_flags true (succ i) + | '0'..'9' + | '.' -> scan_flags skip (succ i) + | _ -> scan_conv skip i + and scan_conv skip i = + if i > lim then incomplete_format fmt else + match Sformat.unsafe_get fmt i with + | '%' | '!' -> succ i + | 's' | 'S' | '[' -> add_conv skip i 's' + | 'c' | 'C' -> add_conv skip i 'c' + | 'd' | 'i' |'o' | 'u' | 'x' | 'X' | 'N' -> add_conv skip i 'i' + | 'f' | 'e' | 'E' | 'g' | 'G' | 'F' -> add_conv skip i 'f' + | 'B' | 'b' -> add_conv skip i 'B' + | 'a' | 'r' | 't' as conv -> add_conv skip i conv + | 'l' | 'n' | 'L' as conv -> + let j = succ i in + if j > lim then add_conv skip i 'i' else begin + match Sformat.get fmt j with + | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' -> + add_char (add_conv skip i conv) 'i' + | c -> add_conv skip i 'i' end + | '{' as conv -> + (* Just get a regular argument, skipping the specification. *) + let i = add_conv skip i conv in + (* To go on, find the index of the next char after the meta format. *) + let j = sub_format_for_printf conv fmt i in + (* Add the meta specification to the summary anyway. *) + let rec loop i = + if i < j - 2 then loop (add_char i (Sformat.get fmt i)) in + loop i; + (* Go on, starting at the closing brace to properly close the meta + specification in the summary. *) + scan_conv skip (j - 1) + | '(' as conv -> + (* Use the static format argument specification instead of + the runtime format argument value: they must have the same type + anyway. *) + scan_fmt (add_conv skip i conv) + | '}' | ')' as conv -> add_conv skip i conv + | conv -> bad_conversion_format fmt i conv + + and scan_fmt i = + if i < lim then + if Sformat.get fmt i = '%' + then scan_fmt (scan_flags false (succ i)) + else scan_fmt (succ i) + else i in + + ignore (scan_fmt 0) +;; + +(* Returns a string that summarizes the typing information that a given + format string contains. + For instance, [summarize_format_type "A number %d\n"] is "%i". + It also checks the well-formedness of the format string. *) +let summarize_format_type fmt = + let len = Sformat.length fmt in + let b = Buffer.create len in + let add_char i c = Buffer.add_char b c; succ i in + let add_conv skip i c = + if skip then Buffer.add_string b "%_" else Buffer.add_char b '%'; + add_char i c in + iter_on_format_args fmt add_conv add_char; + Buffer.contents b +;; + +module Ac = struct + type ac = { + mutable ac_rglr : int; + mutable ac_skip : int; + mutable ac_rdrs : int; + } +end +;; + +open Ac;; + +(* Computes the number of arguments of a format (including the flag + arguments if any). *) +let ac_of_format fmt = + let ac = { ac_rglr = 0; ac_skip = 0; ac_rdrs = 0; } in + let incr_ac skip c = + let inc = if c = 'a' then 2 else 1 in + if c = 'r' then ac.ac_rdrs <- ac.ac_rdrs + 1; + if skip + then ac.ac_skip <- ac.ac_skip + inc + else ac.ac_rglr <- ac.ac_rglr + inc in + let add_conv skip i c = + (* Just finishing a meta format: no additional argument to record. *) + if c <> ')' && c <> '}' then incr_ac skip c; + succ i + and add_char i c = succ i in + + iter_on_format_args fmt add_conv add_char; + ac +;; + +let count_arguments_of_format fmt = + let ac = ac_of_format fmt in + ac.ac_rglr + ac.ac_skip + ac.ac_rdrs +;; + +let list_iter_i f l = + let rec loop i = function + | [] -> () + | [x] -> f i x (* Tail calling [f] *) + | x :: xs -> f i x; loop (succ i) xs in + loop 0 l +;; + +(* ``Abstracting'' version of kprintf: returns a (curried) function that + will print when totally applied. + Note: in the following, we are careful not to be badly caught + by the compiler optimizations for the representation of arrays. *) +let kapr kpr fmt = + match count_arguments_of_format fmt with + | 0 -> kpr fmt [||] + | 1 -> Obj.magic (fun x -> + let a = Array.make 1 (Obj.repr 0) in + a.(0) <- x; + kpr fmt a) + | 2 -> Obj.magic (fun x y -> + let a = Array.make 2 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; + kpr fmt a) + | 3 -> Obj.magic (fun x y z -> + let a = Array.make 3 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + kpr fmt a) + | 4 -> Obj.magic (fun x y z t -> + let a = Array.make 4 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; + kpr fmt a) + | 5 -> Obj.magic (fun x y z t u -> + let a = Array.make 5 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; a.(4) <- u; + kpr fmt a) + | 6 -> Obj.magic (fun x y z t u v -> + let a = Array.make 6 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; a.(4) <- u; a.(5) <- v; + kpr fmt a) + | nargs -> + let rec loop i args = + if i >= nargs then + let a = Array.make nargs (Obj.repr 0) in + list_iter_i (fun i arg -> a.(nargs - i - 1) <- arg) args; + kpr fmt a + else Obj.magic (fun x -> loop (succ i) (x :: args)) in + loop 0 [] +;; + +type positional_specification = + | Spec_none | Spec_index of Sformat.index +;; + +(* To scan an optional positional parameter specification, + i.e. an integer followed by a [$]. + + Calling [got_spec] with appropriate arguments, we ``return'' a positional + specification and an index to go on scanning the [fmt] format at hand. + + Note that this is optimized for the regular case, i.e. no positional + parameter, since in this case we juste ``return'' the constant + [Spec_none]; in case we have a positional parameter, we ``return'' a + [Spec_index] [positional_specification] which a bit more costly. + + Note also that we do not support [*$] specifications, since this would + lead to type checking problems: a [*$] positional specification means + ``take the next argument to [printf] (which must be an integer value)'', + name this integer value $n$; [*$] now designates parameter $n$. + + Unfortunately, the type of a parameter specified via a [*$] positional + specification should be the type of the corresponding argument to + [printf], hence this sould be the type of the $n$-th argument to [printf] + with $n$ being the {\em value} of the integer argument defining [*]; we + clearly cannot statically guess the value of this parameter in the general + case. Put it another way: this means type dependency, which is completely + out of scope of the Caml type algebra. *) + +let scan_positional_spec fmt got_spec n i = + match Sformat.unsafe_get fmt i with + | '0'..'9' as d -> + let rec get_int_litteral accu j = + match Sformat.unsafe_get fmt j with + | '0'..'9' as d -> + get_int_litteral (10 * accu + (int_of_char d - 48)) (succ j) + | '$' -> + if accu = 0 then + failwith "printf: bad positional specification (0)." else + got_spec (Spec_index (Sformat.index_of_litteral_position accu)) (succ j) + (* Not a positional specification: tell so the caller, and go back to + scanning the format from the original [i] position we were called at + first. *) + | _ -> got_spec Spec_none i in + get_int_litteral (int_of_char d - 48) (succ i) + (* No positional specification: tell so the caller, and go back to scanning + the format from the original [i] position. *) + | _ -> got_spec Spec_none i +;; + +(* Get the index of the next argument to printf, according to the given + positional specification. *) +let next_index spec n = + match spec with + | Spec_none -> Sformat.succ_index n + | Spec_index _ -> n +;; + +(* Get the index of the actual argument to printf, according to its + optional positional specification. *) +let get_index spec n = + match spec with + | Spec_none -> n + | Spec_index p -> p +;; + +(* Decode a format string and act on it. + [fmt] is the [printf] format string, and [pos] points to a [%] character in + the format string. + After consuming the appropriate number of arguments and formatting + them, one of the following five continuations described below is called: + + - [cont_s] for outputting a string (arguments: arg num, string, next pos) + - [cont_a] for performing a %a action (arguments: arg num, fn, arg, next pos) + - [cont_t] for performing a %t action (arguments: arg num, fn, next pos) + - [cont_f] for performing a flush action (arguments: arg num, next pos) + - [cont_m] for performing a %( action (arguments: arg num, sfmt, next pos) + + "arg num" is the index in array [args] of the next argument to [printf]. + "next pos" is the position in [fmt] of the first character following + the %conversion specification in [fmt]. *) + +(* Note: here, rather than test explicitly against [Sformat.length fmt] + to detect the end of the format, we use [Sformat.unsafe_get] and + rely on the fact that we'll get a "nul" character if we access + one past the end of the string. These "nul" characters are then + caught by the [_ -> bad_conversion] clauses below. + Don't do this at home, kids. *) +let scan_format fmt args n pos cont_s cont_a cont_t cont_f cont_m = + + let get_arg spec n = + Obj.magic (args.(Sformat.int_of_index (get_index spec n))) in + + let rec scan_positional n widths i = + let got_spec spec i = scan_flags spec n widths i in + scan_positional_spec fmt got_spec n i + + and scan_flags spec n widths i = + match Sformat.unsafe_get fmt i with + | '*' -> + let got_spec wspec i = + let (width : int) = get_arg wspec n in + scan_flags spec (next_index wspec n) (width :: widths) i in + scan_positional_spec fmt got_spec n (succ i) + | '0'..'9' + | '.' | '#' | '-' | ' ' | '+' -> scan_flags spec n widths (succ i) + | _ -> scan_conv spec n widths i + + and scan_conv spec n widths i = + match Sformat.unsafe_get fmt i with + | '%' -> + cont_s n "%" (succ i) + | 's' | 'S' as conv -> + let (x : string) = get_arg spec n in + let x = if conv = 's' then x else "\"" ^ String.escaped x ^ "\"" in + let s = + (* optimize for common case %s *) + if i = succ pos then x else + format_string (extract_format fmt pos i widths) x in + cont_s (next_index spec n) s (succ i) + | 'c' | 'C' as conv -> + let (x : char) = get_arg spec n in + let s = + if conv = 'c' then String.make 1 x else "'" ^ Char.escaped x ^ "'" in + cont_s (next_index spec n) s (succ i) + | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' | 'N' as conv -> + let (x : int) = get_arg spec n in + let s = + format_int (extract_format_int conv fmt pos i widths) x in + cont_s (next_index spec n) s (succ i) + | 'f' | 'e' | 'E' | 'g' | 'G' -> + let (x : float) = get_arg spec n in + let s = format_float (extract_format fmt pos i widths) x in + cont_s (next_index spec n) s (succ i) + | 'F' -> + let (x : float) = get_arg spec n in + cont_s (next_index spec n) (string_of_float x) (succ i) + | 'B' | 'b' -> + let (x : bool) = get_arg spec n in + cont_s (next_index spec n) (string_of_bool x) (succ i) + | 'a' -> + let printer = get_arg spec n in + (* If the printer spec is Spec_none, go on as usual. + If the printer spec is Spec_index p, + printer's argument spec is Spec_index (succ_index p). *) + let n = Sformat.succ_index (get_index spec n) in + let arg = get_arg Spec_none n in + cont_a (next_index spec n) printer arg (succ i) + | 't' -> + let printer = get_arg spec n in + cont_t (next_index spec n) printer (succ i) + | 'l' | 'n' | 'L' as conv -> + begin match Sformat.unsafe_get fmt (succ i) with + | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' -> + let i = succ i in + let s = + match conv with + | 'l' -> + let (x : int32) = get_arg spec n in + format_int32 (extract_format fmt pos i widths) x + | 'n' -> + let (x : nativeint) = get_arg spec n in + format_nativeint (extract_format fmt pos i widths) x + | _ -> + let (x : int64) = get_arg spec n in + format_int64 (extract_format fmt pos i widths) x in + cont_s (next_index spec n) s (succ i) + | _ -> + let (x : int) = get_arg spec n in + let s = format_int (extract_format_int 'n' fmt pos i widths) x in + cont_s (next_index spec n) s (succ i) + end + | '!' -> cont_f n (succ i) + | '{' | '(' as conv (* ')' '}' *) -> + let (xf : ('a, 'b, 'c, 'd, 'e, 'f) format6) = get_arg spec n in + let i = succ i in + let j = sub_format_for_printf conv fmt i in + if conv = '{' (* '}' *) then + (* Just print the format argument as a specification. *) + cont_s + (next_index spec n) + (summarize_format_type xf) + j else + (* Use the format argument instead of the format specification. *) + cont_m (next_index spec n) xf j + | (* '(' *) ')' -> + cont_s n "" (succ i) + | conv -> + bad_conversion_format fmt i conv in + + scan_positional n [] (succ pos) +;; + +let mkprintf to_s get_out outc outs flush k fmt = + + (* [out] is global to this definition of [pr], and must be shared by all its + recursive calls (if any). *) + let out = get_out fmt in + + let rec pr k n fmt v = + + let len = Sformat.length fmt in + + let rec doprn n i = + if i >= len then Obj.magic (k out) else + match Sformat.unsafe_get fmt i with + | '%' -> scan_format fmt v n i cont_s cont_a cont_t cont_f cont_m + | c -> outc out c; doprn n (succ i) + and cont_s n s i = + outs out s; doprn n i + and cont_a n printer arg i = + if to_s then + outs out ((Obj.magic printer : unit -> _ -> string) () arg) + else + printer out arg; + doprn n i + and cont_t n printer i = + if to_s then + outs out ((Obj.magic printer : unit -> string) ()) + else + printer out; + doprn n i + and cont_f n i = + flush out; doprn n i + and cont_m n xf i = + let m = Sformat.add_int_index (count_arguments_of_format xf) n in + pr (Obj.magic (fun _ -> doprn m i)) n xf v in + + doprn n 0 in + + let kpr = pr k (Sformat.index_of_int 0) in + + kapr kpr fmt +;; + +let kfprintf k oc = + mkprintf false (fun _ -> oc) output_char output_string flush k +;; +let ifprintf oc = kapr (fun _ -> Obj.magic ignore);; + +let fprintf oc = kfprintf ignore oc;; +let printf fmt = fprintf stdout fmt;; +let eprintf fmt = fprintf stderr fmt;; + +let kbprintf k b = + mkprintf false (fun _ -> b) Buffer.add_char Buffer.add_string ignore k +;; +let bprintf b = kbprintf ignore b;; + +let get_buff fmt = + let len = 2 * Sformat.length fmt in + Buffer.create len +;; + +let get_contents b = + let s = Buffer.contents b in + Buffer.clear b; + s +;; + +let get_cont k b = k (get_contents b);; + +let ksprintf k = + mkprintf true get_buff Buffer.add_char Buffer.add_string ignore (get_cont k) +;; + +let kprintf = ksprintf;; + +let sprintf fmt = ksprintf (fun s -> s) fmt;; + +module CamlinternalPr = struct + + module Sformat = Sformat;; + + module Tformat = struct + + type ac = + Ac.ac = { + mutable ac_rglr : int; + mutable ac_skip : int; + mutable ac_rdrs : int; + } + ;; + + let ac_of_format = ac_of_format;; + + let sub_format = sub_format;; + + let summarize_format_type = summarize_format_type;; + + let scan_format = scan_format;; + + let kapr = kapr;; + + end + ;; + +end +;; diff --git a/stdlib/printf.mli b/stdlib/printf.mli new file mode 100644 index 0000000..dc1642d --- /dev/null +++ b/stdlib/printf.mli @@ -0,0 +1,209 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: printf.mli,v 1.57 2008-09-27 20:50:01 weis Exp $ *) + +(** Formatted output functions. *) + +val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a +(** [fprintf outchan format arg1 ... argN] formats the arguments + [arg1] to [argN] according to the format string [format], and + outputs the resulting string on the channel [outchan]. + + The format is a character string which contains two types of + objects: plain characters, which are simply copied to the output + channel, and conversion specifications, each of which causes + conversion and printing of arguments. + + Conversion specifications have the following form: + + [% \[flags\] \[width\] \[.precision\] type] + + In short, a conversion specification consists in the [%] character, + followed by optional modifiers and a type which is made of one or + two characters. The types and their meanings are: + + - [d], [i], [n], [l], [L], or [N]: convert an integer argument to + signed decimal. + - [u]: convert an integer argument to unsigned decimal. + - [x]: convert an integer argument to unsigned hexadecimal, + using lowercase letters. + - [X]: convert an integer argument to unsigned hexadecimal, + using uppercase letters. + - [o]: convert an integer argument to unsigned octal. + - [s]: insert a string argument. + - [S]: insert a string argument in Caml syntax (double quotes, escapes). + - [c]: insert a character argument. + - [C]: insert a character argument in Caml syntax (single quotes, escapes). + - [f]: convert a floating-point argument to decimal notation, + in the style [dddd.ddd]. + - [F]: convert a floating-point argument to Caml syntax ([dddd.] + or [dddd.ddd] or [d.ddd e+-dd]). + - [e] or [E]: convert a floating-point argument to decimal notation, + in the style [d.ddd e+-dd] (mantissa and exponent). + - [g] or [G]: convert a floating-point argument to decimal notation, + in style [f] or [e], [E] (whichever is more compact). + - [B]: convert a boolean argument to the string [true] or [false] + - [b]: convert a boolean argument (for backward compatibility; do not + use in new programs). + - [ld], [li], [lu], [lx], [lX], [lo]: convert an [int32] argument to + the format specified by the second letter (decimal, hexadecimal, etc). + - [nd], [ni], [nu], [nx], [nX], [no]: convert a [nativeint] argument to + the format specified by the second letter. + - [Ld], [Li], [Lu], [Lx], [LX], [Lo]: convert an [int64] argument to + the format specified by the second letter. + - [a]: user-defined printer. Takes two arguments and applies the + first one to [outchan] (the current output channel) and to the + second argument. The first argument must therefore have type + [out_channel -> 'b -> unit] and the second ['b]. + The output produced by the function is inserted in the output of + [fprintf] at the current point. + - [t]: same as [%a], but takes only one argument (with type + [out_channel -> unit]) and apply it to [outchan]. + - [\{ fmt %\}]: convert a format string argument. The argument must + have the same type as the internal format string [fmt]. + - [( fmt %)]: format string substitution. Takes a format string + argument and substitutes it to the internal format string [fmt] + to print following arguments. The argument must have the same + type as [fmt]. + - [!]: take no argument and flush the output. + - [%]: take no argument and output one [%] character. + + The optional [flags] are: + - [-]: left-justify the output (default is right justification). + - [0]: for numerical conversions, pad with zeroes instead of spaces. + - [+]: for numerical conversions, prefix number with a [+] sign if positive. + - space: for numerical conversions, prefix number with a space if positive. + - [#]: request an alternate formatting style for numbers. + + The optional [width] is an integer indicating the minimal + width of the result. For instance, [%6d] prints an integer, + prefixing it with spaces to fill at least 6 characters. + + The optional [precision] is a dot [.] followed by an integer + indicating how many digits follow the decimal point in the [%f], + [%e], and [%E] conversions. For instance, [%.4f] prints a [float] with + 4 fractional digits. + + The integer in a [width] or [precision] can also be specified as + [*], in which case an extra integer argument is taken to specify + the corresponding [width] or [precision]. This integer argument + precedes immediately the argument to print. + For instance, [%.*f] prints a [float] with as many fractional + digits as the value of the argument given before the float. *) + +val printf : ('a, out_channel, unit) format -> 'a +(** Same as {!Printf.fprintf}, but output on [stdout]. *) + +val eprintf : ('a, out_channel, unit) format -> 'a +(** Same as {!Printf.fprintf}, but output on [stderr]. *) + +val ifprintf : 'a -> ('b, 'a, unit) format -> 'b +(** Same as {!Printf.fprintf}, but does not print anything. + Useful to ignore some material when conditionally printing. *) + +val sprintf : ('a, unit, string) format -> 'a +(** Same as {!Printf.fprintf}, but instead of printing on an output channel, + return a string containing the result of formatting the arguments. *) + +val bprintf : Buffer.t -> ('a, Buffer.t, unit) format -> 'a +(** Same as {!Printf.fprintf}, but instead of printing on an output channel, + append the formatted arguments to the given extensible buffer + (see module {!Buffer}). *) + +(** Formatted output functions with continuations. *) + +val kfprintf : (out_channel -> 'a) -> out_channel -> + ('b, out_channel, unit, 'a) format4 -> 'b;; +(** Same as [fprintf], but instead of returning immediately, + passes the out channel to its first argument at the end of printing. *) + +val ksprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b;; +(** Same as [sprintf] above, but instead of returning the string, + passes it to the first argument. *) + +val kbprintf : (Buffer.t -> 'a) -> Buffer.t -> + ('b, Buffer.t, unit, 'a) format4 -> 'b;; +(** Same as [bprintf], but instead of returning immediately, + passes the buffer to its first argument at the end of printing. *) + +val kprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b;; +(** A deprecated synonym for [ksprintf]. *) + +(**/**) + +(* For system use only. Don't call directly. *) + +module CamlinternalPr : sig + + module Sformat : sig + type index;; + + val index_of_int : int -> index;; + external int_of_index : index -> int = "%identity";; + external unsafe_index_of_int : int -> index = "%identity";; + + val succ_index : index -> index;; + + val sub : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> index -> int -> string;; + val to_string : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string;; + external length : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int + = "%string_length";; + external get : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int -> char + = "%string_safe_get";; + external unsafe_to_string : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string + = "%identity";; + external unsafe_get : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> int -> char + = "%string_unsafe_get";; + + end;; + + module Tformat : sig + + type ac = { + mutable ac_rglr : int; + mutable ac_skip : int; + mutable ac_rdrs : int; + };; + + val ac_of_format : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ac;; + + val sub_format : + (('a, 'b, 'c, 'd, 'e, 'f) format6 -> int) -> + (('a, 'b, 'c, 'd, 'e, 'f) format6 -> int -> char -> int) -> + char -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + int -> + int + + val summarize_format_type : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string + + val scan_format : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + 'g array -> + Sformat.index -> + int -> + (Sformat.index -> string -> int -> 'h) -> + (Sformat.index -> 'i -> 'j -> int -> 'h) -> + (Sformat.index -> 'k -> int -> 'h) -> + (Sformat.index -> int -> 'h) -> + (Sformat.index -> ('l, 'm, 'n, 'o, 'p, 'q) format6 -> int -> 'h) -> + 'h + + val kapr : + (('a, 'b, 'c, 'd, 'e, 'f) format6 -> Obj.t array -> 'g) -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + 'g + + end;; + +end;; diff --git a/stdlib/queue.ml b/stdlib/queue.ml new file mode 100644 index 0000000..38c3576 --- /dev/null +++ b/stdlib/queue.ml @@ -0,0 +1,165 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* François Pottier, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: queue.ml,v 1.10 2005-08-26 12:10:47 doligez Exp $ *) + +exception Empty + +(* O'Caml currently does not allow the components of a sum type to be + mutable. Yet, for optimal space efficiency, we must have cons cells + whose [next] field is mutable. This leads us to define a type of + cyclic lists, so as to eliminate the [Nil] case and the sum + type. *) + +type 'a cell = { + content: 'a; + mutable next: 'a cell + } + +(* A queue is a reference to either nothing or some cell of a cyclic + list. By convention, that cell is to be viewed as the last cell in + the queue. The first cell in the queue is then found in constant + time: it is the next cell in the cyclic list. The queue's length is + also recorded, so as to make [length] a constant-time operation. + + The [tail] field should really be of type ['a cell option], but + then it would be [None] when [length] is 0 and [Some] otherwise, + leading to redundant memory allocation and accesses. We avoid this + overhead by filling [tail] with a dummy value when [length] is 0. + Of course, this requires bending the type system's arm slightly, + because it does not have dependent sums. *) + +type 'a t = { + mutable length: int; + mutable tail: 'a cell + } + +let create () = { + length = 0; + tail = Obj.magic None +} + +let clear q = + q.length <- 0; + q.tail <- Obj.magic None + +let add x q = + q.length <- q.length + 1; + if q.length = 1 then + let rec cell = { + content = x; + next = cell + } in + q.tail <- cell + else + let tail = q.tail in + let head = tail.next in + let cell = { + content = x; + next = head + } in + tail.next <- cell; + q.tail <- cell + +let push = + add + +let peek q = + if q.length = 0 then + raise Empty + else + q.tail.next.content + +let top = + peek + +let take q = + if q.length = 0 then raise Empty; + q.length <- q.length - 1; + let tail = q.tail in + let head = tail.next in + if head == tail then + q.tail <- Obj.magic None + else + tail.next <- head.next; + head.content + +let pop = + take + +let copy q = + if q.length = 0 then + create() + else + let tail = q.tail in + + let rec tail' = { + content = tail.content; + next = tail' + } in + + let rec copy cell = + if cell == tail then tail' + else { + content = cell.content; + next = copy cell.next + } in + + tail'.next <- copy tail.next; + { + length = q.length; + tail = tail' + } + +let is_empty q = + q.length = 0 + +let length q = + q.length + +let iter f q = + if q.length > 0 then + let tail = q.tail in + let rec iter cell = + f cell.content; + if cell != tail then + iter cell.next in + iter tail.next + +let fold f accu q = + if q.length = 0 then + accu + else + let tail = q.tail in + let rec fold accu cell = + let accu = f accu cell.content in + if cell == tail then + accu + else + fold accu cell.next in + fold accu tail.next + +let transfer q1 q2 = + let length1 = q1.length in + if length1 > 0 then + let tail1 = q1.tail in + clear q1; + if q2.length > 0 then begin + let tail2 = q2.tail in + let head1 = tail1.next in + let head2 = tail2.next in + tail1.next <- head2; + tail2.next <- head1 + end; + q2.length <- q2.length + length1; + q2.tail <- tail1 diff --git a/stdlib/queue.mli b/stdlib/queue.mli new file mode 100644 index 0000000..d321b97 --- /dev/null +++ b/stdlib/queue.mli @@ -0,0 +1,78 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: queue.mli,v 1.16 2002-06-27 08:48:26 xleroy Exp $ *) + +(** First-in first-out queues. + + This module implements queues (FIFOs), with in-place modification. +*) + +type 'a t +(** The type of queues containing elements of type ['a]. *) + + +exception Empty +(** Raised when {!Queue.take} or {!Queue.peek} is applied to an empty queue. *) + + +val create : unit -> 'a t +(** Return a new queue, initially empty. *) + +val add : 'a -> 'a t -> unit +(** [add x q] adds the element [x] at the end of the queue [q]. *) + +val push : 'a -> 'a t -> unit +(** [push] is a synonym for [add]. *) + +val take : 'a t -> 'a +(** [take q] removes and returns the first element in queue [q], + or raises [Empty] if the queue is empty. *) + +val pop : 'a t -> 'a +(** [pop] is a synonym for [take]. *) + +val peek : 'a t -> 'a +(** [peek q] returns the first element in queue [q], without removing + it from the queue, or raises [Empty] if the queue is empty. *) + +val top : 'a t -> 'a +(** [top] is a synonym for [peek]. *) + +val clear : 'a t -> unit +(** Discard all elements from a queue. *) + +val copy : 'a t -> 'a t +(** Return a copy of the given queue. *) + +val is_empty : 'a t -> bool +(** Return [true] if the given queue is empty, [false] otherwise. *) + +val length : 'a t -> int +(** Return the number of elements in a queue. *) + +val iter : ('a -> unit) -> 'a t -> unit +(** [iter f q] applies [f] in turn to all elements of [q], + from the least recently entered to the most recently entered. + The queue itself is unchanged. *) + +val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b +(** [fold f accu q] is equivalent to [List.fold_left f accu l], + where [l] is the list of [q]'s elements. The queue remains + unchanged. *) + +val transfer : 'a t -> 'a t -> unit +(** [transfer q1 q2] adds all of [q1]'s elements at the end of + the queue [q2], then clears [q1]. It is equivalent to the + sequence [iter (fun x -> add x q2) q1; clear q1], but runs + in constant time. *) diff --git a/stdlib/random.ml b/stdlib/random.ml new file mode 100644 index 0000000..a7c5abf --- /dev/null +++ b/stdlib/random.ml @@ -0,0 +1,268 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: random.ml,v 1.22 2003-12-16 18:09:43 doligez Exp $ *) + +(* "Linear feedback shift register" pseudo-random number generator. *) +(* References: Robert Sedgewick, "Algorithms", Addison-Wesley *) + +(* The PRNG is a linear feedback shift register. + It is seeded by a MD5-based PRNG. +*) + +external random_seed: unit -> int = "caml_sys_random_seed";; + +module State = struct + + type t = { st : int array; mutable idx : int };; + + let new_state () = { st = Array.make 55 0; idx = 0 };; + let assign st1 st2 = + Array.blit st2.st 0 st1.st 0 55; + st1.idx <- st2.idx; + ;; + + let full_init s seed = + let combine accu x = Digest.string (accu ^ string_of_int x) in + let extract d = + (Char.code d.[0] + (Char.code d.[1] lsl 8) + (Char.code d.[2] lsl 16)) + lxor (Char.code d.[3] lsl 22) + in + let l = Array.length seed in + for i = 0 to 54 do + s.st.(i) <- i; + done; + let accu = ref "x" in + for i = 0 to 54 + max 55 l do + let j = i mod 55 in + let k = i mod l in + accu := combine !accu seed.(k); + s.st.(j) <- s.st.(j) lxor extract !accu; + done; + s.idx <- 0; + ;; + + let make seed = + let result = new_state () in + full_init result seed; + result + ;; + + let make_self_init () = make [| random_seed () |];; + + let copy s = + let result = new_state () in + assign result s; + result + ;; + + (* Returns 30 random bits as an integer 0 <= x < 1073741824 *) + let bits s = + s.idx <- (s.idx + 1) mod 55; + let newval = (s.st.((s.idx + 24) mod 55) + s.st.(s.idx)) land 0x3FFFFFFF in + s.st.(s.idx) <- newval; + newval + ;; + + let rec intaux s n = + let r = bits s in + let v = r mod n in + if r - v > 0x3FFFFFFF - n + 1 then intaux s n else v + ;; + let int s bound = + if bound > 0x3FFFFFFF || bound <= 0 + then invalid_arg "Random.int" + else intaux s bound + ;; + + let rec int32aux s n = + let b1 = Int32.of_int (bits s) in + let b2 = Int32.shift_left (Int32.of_int (bits s land 1)) 30 in + let r = Int32.logor b1 b2 in + let v = Int32.rem r n in + if Int32.sub r v > Int32.add (Int32.sub Int32.max_int n) 1l + then int32aux s n + else v + ;; + let int32 s bound = + if bound <= 0l + then invalid_arg "Random.int32" + else int32aux s bound + ;; + + let rec int64aux s n = + let b1 = Int64.of_int (bits s) in + let b2 = Int64.shift_left (Int64.of_int (bits s)) 30 in + let b3 = Int64.shift_left (Int64.of_int (bits s land 7)) 60 in + let r = Int64.logor b1 (Int64.logor b2 b3) in + let v = Int64.rem r n in + if Int64.sub r v > Int64.add (Int64.sub Int64.max_int n) 1L + then int64aux s n + else v + ;; + let int64 s bound = + if bound <= 0L + then invalid_arg "Random.int64" + else int64aux s bound + ;; + + let nativeint = + if Nativeint.size = 32 + then fun s bound -> Nativeint.of_int32 (int32 s (Nativeint.to_int32 bound)) + else fun s bound -> Int64.to_nativeint (int64 s (Int64.of_nativeint bound)) + ;; + + (* Returns a float 0 <= x < 1 with at most 90 bits of precision. *) + let rawfloat s = + let scale = 1073741824.0 + and r0 = Pervasives.float (bits s) + and r1 = Pervasives.float (bits s) + and r2 = Pervasives.float (bits s) + in ((r0 /. scale +. r1) /. scale +. r2) /. scale + ;; + + let float s bound = rawfloat s *. bound;; + + let bool s = (bits s land 1 = 0);; + +end;; + +(* This is the state you get with [init 27182818] on a 32-bit machine. *) +let default = { + State.st = [| + 509760043; 399328820; 99941072; 112282318; 611886020; 516451399; + 626288598; 337482183; 748548471; 808894867; 657927153; 386437385; + 42355480; 977713532; 311548488; 13857891; 307938721; 93724463; + 1041159001; 444711218; 1040610926; 233671814; 664494626; 1071756703; + 188709089; 420289414; 969883075; 513442196; 275039308; 918830973; + 598627151; 134083417; 823987070; 619204222; 81893604; 871834315; + 398384680; 475117924; 520153386; 324637501; 38588599; 435158812; + 168033706; 585877294; 328347186; 293179100; 671391820; 846150845; + 283985689; 502873302; 718642511; 938465128; 962756406; 107944131; + 192910970; + |]; + State.idx = 0; +};; + +let bits () = State.bits default;; +let int bound = State.int default bound;; +let int32 bound = State.int32 default bound;; +let nativeint bound = State.nativeint default bound;; +let int64 bound = State.int64 default bound;; +let float scale = State.float default scale;; +let bool () = State.bool default;; + +let full_init seed = State.full_init default seed;; +let init seed = State.full_init default [| seed |];; +let self_init () = init (random_seed());; + +(* Manipulating the current state. *) + +let get_state () = State.copy default;; +let set_state s = State.assign default s;; + +(******************** + +(* Test functions. Not included in the library. + The [chisquare] function should be called with n > 10r. + It returns a triple (low, actual, high). + If low <= actual <= high, the [g] function passed the test, + otherwise it failed. + + Some results: + +init 27182818; chisquare int 100000 1000;; +init 27182818; chisquare int 100000 100;; +init 27182818; chisquare int 100000 5000;; +init 27182818; chisquare int 1000000 1000;; +init 27182818; chisquare int 100000 1024;; +init 299792643; chisquare int 100000 1024;; +init 14142136; chisquare int 100000 1024;; +init 27182818; init_diff 1024; chisquare diff 100000 1024;; +init 27182818; init_diff 100; chisquare diff 100000 100;; +init 27182818; init_diff2 1024; chisquare diff2 100000 1024;; +init 27182818; init_diff2 100; chisquare diff2 100000 100;; +init 14142136; init_diff2 100; chisquare diff2 100000 100;; +init 299792643; init_diff2 100; chisquare diff2 100000 100;; +- : float * float * float = (936.754446796632465, 1032., 1063.24555320336754) +# - : float * float * float = (80., 91.3699999999953434, 120.) +# - : float * float * float = (4858.57864376269026, 4982., 5141.42135623730974) +# - : float * float * float = +(936.754446796632465, 1017.99399999994785, 1063.24555320336754) +# - : float * float * float = (960., 984.565759999997681, 1088.) +# - : float * float * float = (960., 1003.40735999999742, 1088.) +# - : float * float * float = (960., 1035.23328000000038, 1088.) +# - : float * float * float = (960., 1026.79551999999967, 1088.) +# - : float * float * float = (80., 110.194000000003143, 120.) +# - : float * float * float = (960., 1067.98080000000482, 1088.) +# - : float * float * float = (80., 107.292000000001281, 120.) +# - : float * float * float = (80., 85.1180000000022119, 120.) +# - : float * float * float = (80., 86.614000000001397, 120.) + +*) + +(* Return the sum of the squares of v[i0,i1[ *) +let rec sumsq v i0 i1 = + if i0 >= i1 then 0.0 + else if i1 = i0 + 1 then Pervasives.float v.(i0) *. Pervasives.float v.(i0) + else sumsq v i0 ((i0+i1)/2) +. sumsq v ((i0+i1)/2) i1 +;; + +let chisquare g n r = + if n <= 10 * r then invalid_arg "chisquare"; + let f = Array.make r 0 in + for i = 1 to n do + let t = g r in + f.(t) <- f.(t) + 1 + done; + let t = sumsq f 0 r + and r = Pervasives.float r + and n = Pervasives.float n in + let sr = 2.0 *. sqrt r in + (r -. sr, (r *. t /. n) -. n, r +. sr) +;; + +(* This is to test for linear dependencies between successive random numbers. +*) +let st = ref 0;; +let init_diff r = st := int r;; +let diff r = + let x1 = !st + and x2 = int r + in + st := x2; + if x1 >= x2 then + x1 - x2 + else + r + x1 - x2 +;; + +let st1 = ref 0 +and st2 = ref 0 +;; + +(* This is to test for quadratic dependencies between successive random + numbers. +*) +let init_diff2 r = st1 := int r; st2 := int r;; +let diff2 r = + let x1 = !st1 + and x2 = !st2 + and x3 = int r + in + st1 := x2; + st2 := x3; + (x3 - x2 - x2 + x1 + 2*r) mod r +;; + +********************) diff --git a/stdlib/random.mli b/stdlib/random.mli new file mode 100644 index 0000000..bd576b3 --- /dev/null +++ b/stdlib/random.mli @@ -0,0 +1,101 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: random.mli,v 1.17 2007-02-09 13:31:15 doligez Exp $ *) + +(** Pseudo-random number generators (PRNG). *) + +(** {6 Basic functions} *) + +val init : int -> unit +(** Initialize the generator, using the argument as a seed. + The same seed will always yield the same sequence of numbers. *) + +val full_init : int array -> unit +(** Same as {!Random.init} but takes more data as seed. *) + +val self_init : unit -> unit +(** Initialize the generator with a more-or-less random seed chosen + in a system-dependent way. *) + +val bits : unit -> int +(** Return 30 random bits in a nonnegative integer. *) + +val int : int -> int +(** [Random.int bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0 and less + than 2{^30}. *) + +val int32 : Int32.t -> Int32.t;; +(** [Random.int32 bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0. *) + +val nativeint : Nativeint.t -> Nativeint.t;; +(** [Random.nativeint bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0. *) + +val int64 : Int64.t -> Int64.t;; +(** [Random.int64 bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0. *) + +val float : float -> float +(** [Random.float bound] returns a random floating-point number + between 0 (inclusive) and [bound] (exclusive). If [bound] is + negative, the result is negative or zero. If [bound] is 0, + the result is 0. *) + +val bool : unit -> bool +(** [Random.bool ()] returns [true] or [false] with probability 0.5 each. *) + + +(** {6 Advanced functions} *) + +(** The functions from module [State] manipulate the current state + of the random generator explicitely. + This allows using one or several deterministic PRNGs, + even in a multi-threaded program, without interference from + other parts of the program. +*) + +module State : sig + type t + (** The type of PRNG states. *) + + val make : int array -> t + (** Create a new state and initialize it with the given seed. *) + + val make_self_init : unit -> t + (** Create a new state and initialize it with a system-dependent + low-entropy seed. *) + + val copy : t -> t + (** Return a copy of the given state. *) + + val bits : t -> int + val int : t -> int -> int + val int32 : t -> Int32.t -> Int32.t + val nativeint : t -> Nativeint.t -> Nativeint.t + val int64 : t -> Int64.t -> Int64.t + val float : t -> float -> float + val bool : t -> bool + (** These functions are the same as the basic functions, except that they + use (and update) the given PRNG state instead of the default one. + *) +end;; + + +val get_state : unit -> State.t +(** Return the current state of the generator used by the basic functions. *) + +val set_state : State.t -> unit +(** Set the state of the generator used by the basic functions. *) diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml new file mode 100644 index 0000000..0635b9b --- /dev/null +++ b/stdlib/scanf.ml @@ -0,0 +1,1293 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: scanf.ml,v 1.80 2008-09-27 20:45:05 weis Exp $ *) + +(* The run-time library for scanners. *) + +(* Scanning buffers. *) +module type SCANNING = sig + +type scanbuf;; + +val stdib : scanbuf;; +(* The scanning buffer reading from [stdin]. + [stdib] is equivalent to [Scanning.from_channel stdin]. *) + +val next_char : scanbuf -> char;; +(* [Scanning.next_char ib] advance the scanning buffer for + one character. + If no more character can be read, sets a end of file condition and + returns '\000'. *) + +val invalidate_current_char : scanbuf -> unit;; +(* [Scanning.invalidate_current_char ib] mark the current_char as already + scanned. *) + +val peek_char : scanbuf -> char;; +(* [Scanning.peek_char ib] returns the current char available in + the buffer or reads one if necessary (when the current character is + already scanned). + If no character can be read, sets an end of file condition and + returns '\000'. *) + +val checked_peek_char : scanbuf -> char;; +(* Same as above but always returns a valid char or fails: + instead of returning a null char when the reading method of the + input buffer has reached an end of file, the function raises exception + [End_of_file]. *) + +val store_char : scanbuf -> char -> int -> int;; +(* [Scanning.store_char ib c lim] adds [c] to the token buffer + of the scanning buffer. It also advances the scanning buffer for one + character and returns [lim - 1], indicating the new limit + for the length of the current token. *) + +val skip_char : scanbuf -> int -> int;; +(* [Scanning.skip_char ib lim] ignores the current character. *) + +val ignore_char : scanbuf -> int -> int;; +(* [Scanning.ignore_char ib lim] ignores the current character and + decrements the limit. *) + +val token : scanbuf -> string;; +(* [Scanning.token ib] returns the string stored into the token + buffer of the scanning buffer: it returns the token matched by the + format. *) + +val reset_token : scanbuf -> unit;; +(* [Scanning.reset_token ib] resets the token buffer of + the given scanning buffer. *) + +val char_count : scanbuf -> int;; +(* [Scanning.char_count ib] returns the number of characters + read so far from the given buffer. *) + +val line_count : scanbuf -> int;; +(* [Scanning.line_count ib] returns the number of new line + characters read so far from the given buffer. *) + +val token_count : scanbuf -> int;; +(* [Scanning.token_count ib] returns the number of tokens read + so far from [ib]. *) + +val eof : scanbuf -> bool;; +(* [Scanning.eof ib] returns the end of input condition + of the given buffer. *) + +val end_of_input : scanbuf -> bool;; +(* [Scanning.end_of_input ib] tests the end of input condition + of the given buffer (if no char has ever been read, an attempt to + read one is performed). *) + +val beginning_of_input : scanbuf -> bool;; +(* [Scanning.beginning_of_input ib] tests the beginning of input + condition of the given buffer. *) + +val name_of_input : scanbuf -> string;; +(* [Scanning.name_of_input ib] returns the name of the character + source for input buffer [ib]. *) + +val from_string : string -> scanbuf;; +val from_channel : in_channel -> scanbuf;; +val from_file : string -> scanbuf;; +val from_file_bin : string -> scanbuf;; +val from_function : (unit -> char) -> scanbuf;; + +end +;; + +module Scanning : SCANNING = struct + +(* The run-time library for scanf. *) +type file_name = string;; + +type scanbuf = { + mutable eof : bool; + mutable current_char : char; + mutable current_char_is_valid : bool; + mutable char_count : int; + mutable line_count : int; + mutable token_count : int; + mutable get_next_char : unit -> char; + tokbuf : Buffer.t; + file_name : file_name; +} +;; + +let null_char = '\000';; + +(* Reads a new character from input buffer. Next_char never fails, + even in case of end of input: it then simply sets the end of file + condition. *) +let next_char ib = + try + let c = ib.get_next_char () in + ib.current_char <- c; + ib.current_char_is_valid <- true; + ib.char_count <- succ ib.char_count; + if c = '\n' then ib.line_count <- succ ib.line_count; + c with + | End_of_file -> + let c = null_char in + ib.current_char <- c; + ib.current_char_is_valid <- false; + ib.eof <- true; + c +;; + +let peek_char ib = + if ib.current_char_is_valid then ib.current_char else next_char ib;; + +(* Returns a valid current char for the input buffer. In particular + no irrelevant null character (as set by [next_char] in case of end + of input) is returned, since [End_of_file] is raised when + [next_char] sets the end of file condition while trying to read a + new character. *) +let checked_peek_char ib = + let c = peek_char ib in + if ib.eof then raise End_of_file; + c +;; + +let end_of_input ib = + ignore (peek_char ib); + ib.eof +;; + +let eof ib = ib.eof;; + +let beginning_of_input ib = ib.char_count = 0;; +let name_of_input ib = ib.file_name;; +let char_count ib = + if ib.current_char_is_valid then ib.char_count - 1 else ib.char_count +;; +let line_count ib = ib.line_count;; +let reset_token ib = Buffer.reset ib.tokbuf;; +let invalidate_current_char ib = ib.current_char_is_valid <- false;; + +let token ib = + let tokbuf = ib.tokbuf in + let tok = Buffer.contents tokbuf in + Buffer.clear tokbuf; + ib.token_count <- succ ib.token_count; + tok +;; + +let token_count ib = ib.token_count;; + +let skip_char ib max = + invalidate_current_char ib; + max +;; + +let ignore_char ib max = skip_char ib (max - 1);; + +let store_char ib c max = + Buffer.add_char ib.tokbuf c; + ignore_char ib max +;; + +let default_token_buffer_size = 1024;; + +let create fname next = { + eof = false; + current_char = '\000'; + current_char_is_valid = false; + char_count = 0; + line_count = 0; + token_count = 0; + get_next_char = next; + tokbuf = Buffer.create default_token_buffer_size; + file_name = fname; +} +;; + +let from_string s = + let i = ref 0 in + let len = String.length s in + let next () = + if !i >= len then raise End_of_file else + let c = s.[!i] in + incr i; + c in + create "string input" next +;; + +let from_function = create "function input";; + +(* Scanning from an input channel. *) + +(* Position of the problem: + + We cannot prevent the scanning mechanism to use one lookahead character, + if needed by the semantics of the format string specifications (e.g. a + trailing ``skip space'' specification in the format string); in this case, + the mandatory lookahead character is indeed read from the input and not + used to return the token read. It is thus mandatory to be able to store + an unused lookahead character somewhere to get it as the first character + of the next scan. + + To circumvent this problem, all the scanning functions get a low level + input buffer argument where they store the lookahead character when + needed; additionnaly, the input buffer is the only source of character of + a scanner. The [scanbuf] input buffers are defined in module {!Scanning}. + + Now we understand that it is extremely important that related successive + calls to scanners inded read from the same input buffer. In effect, if a + scanner [scan1] is reading from [ib1] and stores an unused lookahead + character [c1] into its input buffer [ib1], then another scanner [scan2] + not reading from the same buffer [ib1] will miss the character [c], + seemingly vanished in the air from the point of view of [scan2]. + + This mechanism works perfectly to read from strings, from files, and from + functions, since in those cases, allocating two buffers reading from the + same source is unnatural. + + Still, there is a difficulty in the case of scanning from an input + channel. In effect, when scanning from an input channel [ic], this channel + may not have been allocated from within this library. Hence, it may be + shared (two functions of the user's program may successively read from + [ic]). This is highly error prone since, one of the function may seek the + input channel, while the other function has still an unused lookahead + character in its input buffer. In conclusion, you should never mixt direct + low level reading and high level scanning from the same input channel. + + This phenomenon of reading mess is even worse when one defines more than + one scanning buffer reading from the same input channel + [ic]. Unfortunately, we have no simple way to get rid of this problem + (unless the basic input channel API is modified to offer a ``consider this + char as unread'' procedure to keep back the unused lookahead character as + available in the input channel for further reading). + + To prevent some of the confusion the scanning buffer allocation function + is a memo function that never allocates two different scanning buffers for + the same input channel. This way, the user can naively perform successive + call to [fscanf] below, without allocating a new scanning buffer at each + invocation and hence preserving the expected semantics. + + As mentioned above, a more ambitious fix could be to change the input + channel API to allow arbitrary mixing of direct and formatted reading from + input channels. *) + +(* Perform bufferized input to improve efficiency. *) +let file_buffer_size = ref 1024;; + +(* The scanner closes the input channel at end of input. *) +let scan_close_at_end ic = close_in ic; raise End_of_file;; + +(* The scanner does not close the input channel at end of input: + it just raises [End_of_file]. *) +let scan_raise_at_end _ic = raise End_of_file;; + +let from_ic scan_close_ic fname ic = + let len = !file_buffer_size in + let buf = String.create len in + let i = ref 0 in + let lim = ref 0 in + let eof = ref false in + let next () = + if !i < !lim then begin let c = buf.[!i] in incr i; c end else + if !eof then raise End_of_file else begin + lim := input ic buf 0 len; + if !lim = 0 then begin eof := true; scan_close_ic ic end else begin + i := 1; + buf.[0] + end + end in + create fname next +;; + +let from_ic_close_at_end = from_ic scan_close_at_end;; + +let from_file fname = from_ic_close_at_end fname (open_in fname);; +let from_file_bin fname = from_ic_close_at_end fname (open_in_bin fname);; + +(* The scanning buffer reading from [stdin]. + One could try to define [stdib] as a scanning buffer reading a character at a + time (no bufferization at all), but unfortunately the toplevel + interaction would be wrong. + This is due to some kind of ``race condition'' when reading from [stdin], + since the interactive compiler and [scanf] will simultaneously read the + material they need from [stdin]; then, confusion will result from what should + be read by the toplevel and what should be read by [scanf]. + This is even more complicated by the one character lookahead that [scanf] + is sometimes obliged to maintain: the lookahead character will be available + for the next ([scanf]) entry, seamingly coming from nowhere. + Also no [End_of_file] is raised when reading from stdin: if not enough + characters have been read, we simply ask to read more. *) +let stdib = from_ic scan_raise_at_end "stdin" stdin;; + +let memo_from_ic = + let memo = ref [] in + (fun scan_close_ic fname ic -> + try List.assq ic !memo with + | Not_found -> + let ib = from_ic scan_close_ic fname ic in + memo := (ic, ib) :: !memo; + ib) +;; + +let from_channel = memo_from_ic scan_raise_at_end "input channel";; + +end +;; + +(* Formatted input functions. *) + +type ('a, 'b, 'c, 'd) scanner = + ('a, Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c +;; + +external string_to_format : + string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" +;; + +(* Reporting errors. *) +exception Scan_failure of string;; + +let bad_input s = raise (Scan_failure s);; +let bad_input_char c = bad_input (String.make 1 c);; + +let bad_input_escape c = + bad_input (Printf.sprintf "illegal escape character %C" c) +;; + +module Sformat = Printf.CamlinternalPr.Sformat;; +module Tformat = Printf.CamlinternalPr.Tformat;; + +let bad_conversion fmt i c = + invalid_arg + (Printf.sprintf + "scanf: bad conversion %%%c, at char number %i \ + in format string ``%s''" c i (Sformat.to_string fmt)) +;; + +let incomplete_format fmt = + invalid_arg + (Printf.sprintf "scanf: premature end of format string ``%s''" + (Sformat.to_string fmt)) +;; + +let bad_float () = bad_input "no dot or exponent part found in +float token" +;; + +let character_mismatch_err c ci = + Printf.sprintf "looking for %C, found %C" c ci +;; + +let character_mismatch c ci = + bad_input (character_mismatch_err c ci) +;; + +let format_mismatch_err fmt1 fmt2 = + Printf.sprintf + "format read ``%s'' does not match specification ``%s''" fmt1 fmt2 +;; + +let format_mismatch fmt1 fmt2 = bad_input (format_mismatch_err fmt1 fmt2);; + +(* Checking that 2 format strings are type compatible. *) +let compatible_format_type fmt1 fmt2 = + Tformat.summarize_format_type (string_to_format fmt1) = + Tformat.summarize_format_type (string_to_format fmt2);; + +(* Checking that [c] is indeed in the input, then skips it. + In this case, the character c has been explicitely specified in the + format as being mandatory in the input; hence we should fail with + End_of_file in case of end_of_input. + That's why we use checked_peek_char here. *) +let check_char ib c = + let ci = Scanning.checked_peek_char ib in + if ci = c then Scanning.invalidate_current_char ib else + character_mismatch c ci +;; + +(* Checks that the current char is indeed one of the stopper characters, + then skips it. + Be careful that if ib has no more character this procedure should + just do nothing (since %s@c defaults to the entire rest of the + buffer, when no character c can be found in the input). *) +let ignore_stoppers stps ib = + if stps <> [] && not (Scanning.eof ib) then + let ci = Scanning.peek_char ib in + if List.memq ci stps then Scanning.invalidate_current_char ib else + let sr = String.concat "" (List.map (String.make 1) stps) in + bad_input + (Printf.sprintf "looking for one of range %S, found %C" sr ci) +;; + +(* Extracting tokens from ouput token buffer. *) + +let token_char ib = (Scanning.token ib).[0];; + +let token_string = Scanning.token;; + +let token_bool ib = + match Scanning.token ib with + | "true" -> true + | "false" -> false + | s -> bad_input ("invalid boolean " ^ s);; + +(* Extract an integer literal token. + Since the functions Pervasives.*int*_of_string do not accept a leading +, + we skip it if necessary. *) +let token_int_literal conv ib = + let tok = + match conv with + | 'd' | 'i' | 'u' -> Scanning.token ib + | 'o' -> "0o" ^ Scanning.token ib + | 'x' | 'X' -> "0x" ^ Scanning.token ib + | 'b' -> "0b" ^ Scanning.token ib + | _ -> assert false in + let l = String.length tok in + if l = 0 || tok.[0] <> '+' then tok else String.sub tok 1 (l - 1) +;; + +(* All the functions that convert a string to a number raise the exception + Failure when the conversion is not possible. + This exception is then trapped in [kscanf]. *) +let token_int conv ib = int_of_string (token_int_literal conv ib);; + +let token_float ib = float_of_string (Scanning.token ib);; + +(* To scan native ints, int32 and int64 integers. + We cannot access to conversions to/from strings for those types, + Nativeint.of_string, Int32.of_string, and Int64.of_string, + since those modules are not available to [Scanf]. + However, we can bind and use the corresponding primitives that are + available in the runtime. *) +external nativeint_of_string : string -> nativeint + = "caml_nativeint_of_string" +;; +external int32_of_string : string -> int32 + = "caml_int32_of_string" +;; +external int64_of_string : string -> int64 + = "caml_int64_of_string" +;; + +let token_nativeint conv ib = nativeint_of_string (token_int_literal conv ib);; +let token_int32 conv ib = int32_of_string (token_int_literal conv ib);; +let token_int64 conv ib = int64_of_string (token_int_literal conv ib);; + +(* Scanning numbers. *) + +(* Digits scanning functions suppose that one character has been + checked and is available, since they return at end of file with the + currently found token selected. The digits scanning functions scan + a possibly empty sequence of digits, (hence a successful scanning + from one of those functions does not imply that the token is a + well-formed number: to get a true number, it is mandatory to check + that at least one digit is available before calling a digit + scanning function). *) + +(* The decimal case is treated especially for optimization purposes. *) +let rec scan_decimal_digits max ib = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + match c with + | '0' .. '9' as c -> + let max = Scanning.store_char ib c max in + scan_decimal_digits max ib + | '_' -> + let max = Scanning.ignore_char ib max in + scan_decimal_digits max ib + | _ -> max +;; + +let scan_decimal_digits_plus max ib = + let c = Scanning.checked_peek_char ib in + match c with + | '0' .. '9' -> + let max = Scanning.store_char ib c max in + scan_decimal_digits max ib + | c -> bad_input_char c +;; + +let scan_digits_plus digitp max ib = + (* To scan numbers from other bases, we use a predicate argument to + scan_digits. *) + let rec scan_digits max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + match c with + | c when digitp c -> + let max = Scanning.store_char ib c max in + scan_digits max + | '_' -> + let max = Scanning.ignore_char ib max in + scan_digits max + | _ -> max in + + let c = Scanning.checked_peek_char ib in + if digitp c then + let max = Scanning.store_char ib c max in + scan_digits max + else bad_input_char c +;; + +let is_binary_digit = function + | '0' .. '1' -> true + | _ -> false +;; + +let scan_binary_int = scan_digits_plus is_binary_digit;; + +let is_octal_digit = function + | '0' .. '7' -> true + | _ -> false +;; + +let scan_octal_int = scan_digits_plus is_octal_digit;; + +let is_hexa_digit = function + | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' -> true + | _ -> false +;; + +let scan_hexadecimal_int = scan_digits_plus is_hexa_digit;; + +(* Scan a decimal integer. *) +let scan_unsigned_decimal_int = scan_decimal_digits_plus;; + +let scan_sign max ib = + let c = Scanning.checked_peek_char ib in + match c with + | '+' -> Scanning.store_char ib c max + | '-' -> Scanning.store_char ib c max + | c -> max +;; + +let scan_optionally_signed_decimal_int max ib = + let max = scan_sign max ib in + scan_unsigned_decimal_int max ib +;; + +(* Scan an unsigned integer that could be given in any (common) basis. + If digits are prefixed by one of 0x, 0X, 0o, or 0b, the number is + assumed to be written respectively in hexadecimal, hexadecimal, + octal, or binary. *) +let scan_unsigned_int max ib = + match Scanning.checked_peek_char ib with + | '0' as c -> + let max = Scanning.store_char ib c max in + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + begin match c with + | 'x' | 'X' -> scan_hexadecimal_int (Scanning.store_char ib c max) ib + | 'o' -> scan_octal_int (Scanning.store_char ib c max) ib + | 'b' -> scan_binary_int (Scanning.store_char ib c max) ib + | c -> scan_decimal_digits max ib end + | c -> scan_unsigned_decimal_int max ib +;; + +let scan_optionally_signed_int max ib = + let max = scan_sign max ib in + scan_unsigned_int max ib +;; + +let scan_int_conv conv max ib = + match conv with + | 'b' -> scan_binary_int max ib + | 'd' -> scan_optionally_signed_decimal_int max ib + | 'i' -> scan_optionally_signed_int max ib + | 'o' -> scan_octal_int max ib + | 'u' -> scan_unsigned_decimal_int max ib + | 'x' | 'X' -> scan_hexadecimal_int max ib + | c -> assert false +;; + +(* Scanning floating point numbers. *) +(* Fractional part is optional and can be reduced to 0 digits. *) +let scan_frac_part max ib = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + match c with + | '0' .. '9' as c -> + scan_decimal_digits (Scanning.store_char ib c max) ib + | _ -> max +;; + +(* Exp part is optional and can be reduced to 0 digits. *) +let scan_exp_part max ib = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + match c with + | 'e' | 'E' as c -> + scan_optionally_signed_decimal_int (Scanning.store_char ib c max) ib + | _ -> max +;; + +(* Scan the integer part of a floating point number, (not using the + Caml lexical convention since the integer part can be empty): + an optional sign, followed by a possibly empty sequence of decimal + digits (e.g. -.1). *) +let scan_int_part max ib = + let max = scan_sign max ib in + scan_decimal_digits max ib +;; + +let scan_float max ib = + let max = scan_int_part max ib in + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + match c with + | '.' -> + let max = Scanning.store_char ib c max in + let max = scan_frac_part max ib in + scan_exp_part max ib + | c -> scan_exp_part max ib +;; + +let scan_Float max ib = + let max = scan_optionally_signed_decimal_int max ib in + if max = 0 then bad_float () else + let c = Scanning.peek_char ib in + if Scanning.eof ib then bad_float () else + match c with + | '.' -> + let max = Scanning.store_char ib c max in + let max = scan_frac_part max ib in + scan_exp_part max ib + | 'e' | 'E' -> + scan_exp_part max ib + | c -> bad_float () +;; + +(* Scan a regular string: stops when encountering a space or one of the + characters in stp. It also stops when the maximum number of + characters has been read.*) +let scan_string stp max ib = + let rec loop max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if stp = [] then + match c with + | ' ' | '\t' | '\n' | '\r' -> max + | c -> loop (Scanning.store_char ib c max) else + if List.memq c stp then Scanning.skip_char ib max else + loop (Scanning.store_char ib c max) in + loop max +;; + +(* Scan a char: peek strictly one character in the input, whatsoever. *) +let scan_char max ib = + Scanning.store_char ib (Scanning.checked_peek_char ib) max +;; + +let char_for_backslash = function + | 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c +;; + +(* The integer value corresponding to the facial value of a valid + decimal digit character. *) +let int_value_of_char c = int_of_char c - 48;; + +let char_for_decimal_code c0 c1 c2 = + let c = + 100 * int_value_of_char c0 + + 10 * int_value_of_char c1 + + int_value_of_char c2 in + if c < 0 || c > 255 + then bad_input (Printf.sprintf "bad char \\%c%c%c" c0 c1 c2) + else char_of_int c +;; + +(* Called when encountering '\\' as starter of a char. + Stops before the corresponding '\''. *) +let scan_backslash_char max ib = + if max = 0 then bad_input "a char" else + let c = Scanning.peek_char ib in + if Scanning.eof ib then bad_input "a char" else + match c with + | '\\' | '\'' | '"' | 'n' | 't' | 'b' | 'r' (* '"' helping Emacs *) -> + Scanning.store_char ib (char_for_backslash c) max + | '0' .. '9' as c -> + let get_digit () = + let c = Scanning.next_char ib in + match c with + | '0' .. '9' as c -> c + | c -> bad_input_escape c in + let c0 = c in + let c1 = get_digit () in + let c2 = get_digit () in + Scanning.store_char ib (char_for_decimal_code c0 c1 c2) (max - 2) + | c -> bad_input_char c +;; + +let scan_Char max ib = + let rec loop s max = + if max = 0 then bad_input "a char" else + let c = Scanning.checked_peek_char ib in + if Scanning.eof ib then bad_input "a char" else + match c, s with + (* Looking for the '\'' at the beginning of the delimited char. *) + | '\'', 3 -> loop 2 (Scanning.ignore_char ib max) + (* Looking for the '\'' at the end of the delimited char. *) + | '\'', 1 -> Scanning.ignore_char ib max + (* Any other char at the beginning or end of the delimited char should be + '\''. *) + | c, (3 | 1) -> character_mismatch '\'' c + (* Found a '\\': check and read this escape char. *) + | '\\', 2 -> loop 1 (scan_backslash_char (Scanning.ignore_char ib max) ib) + (* The regular case, remember the char, then look for the terminal '\\'. *) + | c, 2 -> loop 1 (Scanning.store_char ib c max) + (* Any other case is an error, *) + | c, _ -> bad_input_char c in + loop 3 max +;; + +let scan_String max ib = + let rec loop s max = + if max = 0 then bad_input "a string" else + let c = Scanning.checked_peek_char ib in + if Scanning.eof ib then bad_input "a string" else + match c, s with + | '"', true (* '"' helping Emacs *) -> + loop false (Scanning.ignore_char ib max) + | '"', false (* '"' helping Emacs *) -> + Scanning.ignore_char ib max + | '\\', false -> + skip_spaces true (Scanning.ignore_char ib max) + | c, false -> loop false (Scanning.store_char ib c max) + | c, _ -> bad_input_char c + and skip_spaces s max = + if max = 0 then bad_input "a string" else + let c = Scanning.checked_peek_char ib in + if Scanning.eof ib then bad_input "a string" else + match c, s with + | '\n', true + | ' ', false -> + skip_spaces false (Scanning.ignore_char ib max) + | '\\', false -> loop false max + | c, false -> loop false (Scanning.store_char ib c max) + | _, _ -> loop false (scan_backslash_char (max - 1) ib) in + loop true max +;; + +let scan_bool max ib = + if max < 4 then bad_input "a boolean" else + let c = Scanning.checked_peek_char ib in + if Scanning.eof ib then bad_input "a boolean" else + let m = + match c with + | 't' -> 4 + | 'f' -> 5 + | _ -> bad_input "a boolean" in + scan_string [] (min max m) ib +;; + +(* Reading char sets in %[...] conversions. *) +type char_set = + | Pos_set of string (* Positive (regular) set. *) + | Neg_set of string (* Negative (complementary) set. *) +;; + +(* Char sets are read as sub-strings in the format string. *) +let read_char_set fmt i = + let lim = Sformat.length fmt - 1 in + + let rec find_in_set j = + if j > lim then incomplete_format fmt else + match Sformat.get fmt j with + | ']' -> j + | c -> find_in_set (succ j) + + and find_set i = + if i > lim then incomplete_format fmt else + match Sformat.get fmt i with + | ']' -> find_in_set (succ i) + | c -> find_in_set i in + + if i > lim then incomplete_format fmt else + match Sformat.get fmt i with + | '^' -> + let i = succ i in + let j = find_set i in + j, Neg_set (Sformat.sub fmt (Sformat.index_of_int i) (j - i)) + | _ -> + let j = find_set i in + j, Pos_set (Sformat.sub fmt (Sformat.index_of_int i) (j - i)) +;; + +(* Char sets are now represented as bitvects that are represented as + byte strings. *) + +(* Bit manipulations into bytes. *) +let set_bit_of_byte byte idx b = + (b lsl idx) lor (byte land (* mask idx *) (lnot (1 lsl idx))) +;; + +let get_bit_of_byte byte idx = (byte lsr idx) land 1;; + +(* Bit manipulations in vectors of bytes represented as strings. *) +let set_bit_of_range r c b = + let idx = c land 0x7 in + let ydx = c lsr 3 in + let byte = r.[ydx] in + r.[ydx] <- char_of_int (set_bit_of_byte (int_of_char byte) idx b) +;; + +let get_bit_of_range r c = + let idx = c land 0x7 in + let ydx = c lsr 3 in + let byte = r.[ydx] in + get_bit_of_byte (int_of_char byte) idx +;; + +(* Char sets represented as bitvects represented as fixed length byte + strings. *) +(* Create a full or empty set of chars. *) +let make_range bit = + let c = char_of_int (if bit = 0 then 0 else 0xFF) in + String.make 32 c +;; + +(* Test if a char belongs to a set of chars. *) +let get_char_in_range r c = get_bit_of_range r (int_of_char c);; + +let bit_not b = (lnot b) land 1;; + +(* Build the bit vector corresponding to the set of characters + that belongs to the string argument [set]. + (In the [Scanf] module [set] is always a sub-string of the format.) *) +let make_char_bit_vect bit set = + let r = make_range (bit_not bit) in + let lim = String.length set - 1 in + let rec loop bit rp i = + if i <= lim then + match set.[i] with + | '-' when rp -> + (* if i = 0 then rp is false (since the initial call is + loop bit false 0). Hence i >= 1 and the following is safe. *) + let c1 = set.[i - 1] in + let i = succ i in + if i > lim then loop bit false (i - 1) else + let c2 = set.[i] in + for j = int_of_char c1 to int_of_char c2 do + set_bit_of_range r j bit done; + loop bit false (succ i) + | c -> + set_bit_of_range r (int_of_char set.[i]) bit; + loop bit true (succ i) in + loop bit false 0; + r +;; + +(* Compute the predicate on chars corresponding to a char set. *) +let make_pred bit set stp = + let r = make_char_bit_vect bit set in + List.iter + (fun c -> set_bit_of_range r (int_of_char c) (bit_not bit)) stp; + (fun c -> get_char_in_range r c) +;; + +let make_setp stp char_set = + match char_set with + | Pos_set set -> + begin match String.length set with + | 0 -> (fun c -> 0) + | 1 -> + let p = set.[0] in + (fun c -> if c == p then 1 else 0) + | 2 -> + let p1 = set.[0] and p2 = set.[1] in + (fun c -> if c == p1 || c == p2 then 1 else 0) + | 3 -> + let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in + if p2 = '-' then make_pred 1 set stp else + (fun c -> if c == p1 || c == p2 || c == p3 then 1 else 0) + | n -> make_pred 1 set stp + end + | Neg_set set -> + begin match String.length set with + | 0 -> (fun c -> 1) + | 1 -> + let p = set.[0] in + (fun c -> if c != p then 1 else 0) + | 2 -> + let p1 = set.[0] and p2 = set.[1] in + (fun c -> if c != p1 && c != p2 then 1 else 0) + | 3 -> + let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in + if p2 = '-' then make_pred 0 set stp else + (fun c -> if c != p1 && c != p2 && c != p3 then 1 else 0) + | n -> make_pred 0 set stp + end +;; + +let setp_table = Hashtbl.create 7;; + +let add_setp stp char_set setp = + let char_set_tbl = + try Hashtbl.find setp_table char_set with + | Not_found -> + let char_set_tbl = Hashtbl.create 3 in + Hashtbl.add setp_table char_set char_set_tbl; + char_set_tbl in + Hashtbl.add char_set_tbl stp setp +;; + +let find_setp stp char_set = + try Hashtbl.find (Hashtbl.find setp_table char_set) stp with + | Not_found -> + let setp = make_setp stp char_set in + add_setp stp char_set setp; + setp +;; + +let scan_chars_in_char_set stp char_set max ib = + let rec loop_pos1 cp1 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c == cp1 + then loop_pos1 cp1 (Scanning.store_char ib c max) + else max + and loop_pos2 cp1 cp2 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c == cp1 || c == cp2 + then loop_pos2 cp1 cp2 (Scanning.store_char ib c max) + else max + and loop_pos3 cp1 cp2 cp3 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c == cp1 || c == cp2 || c == cp3 + then loop_pos3 cp1 cp2 cp3 (Scanning.store_char ib c max) + else max + and loop_neg1 cp1 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c != cp1 + then loop_neg1 cp1 (Scanning.store_char ib c max) + else max + and loop_neg2 cp1 cp2 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c != cp1 && c != cp2 + then loop_neg2 cp1 cp2 (Scanning.store_char ib c max) + else max + and loop_neg3 cp1 cp2 cp3 max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if c != cp1 && c != cp2 && c != cp3 + then loop_neg3 cp1 cp2 cp3 (Scanning.store_char ib c max) + else max + and loop setp max = + if max = 0 then max else + let c = Scanning.peek_char ib in + if Scanning.eof ib then max else + if setp c == 1 + then loop setp (Scanning.store_char ib c max) + else max in + + let max = + match char_set with + | Pos_set set -> + begin match String.length set with + | 0 -> loop (fun c -> 0) max + | 1 -> loop_pos1 set.[0] max + | 2 -> loop_pos2 set.[0] set.[1] max + | 3 when set.[1] != '-' -> loop_pos3 set.[0] set.[1] set.[2] max + | n -> loop (find_setp stp char_set) max end + | Neg_set set -> + begin match String.length set with + | 0 -> loop (fun c -> 1) max + | 1 -> loop_neg1 set.[0] max + | 2 -> loop_neg2 set.[0] set.[1] max + | 3 when set.[1] != '-' -> loop_neg3 set.[0] set.[1] set.[2] max + | n -> loop (find_setp stp char_set) max end in + ignore_stoppers stp ib; + max +;; + +let get_count t ib = + match t with + | 'l' -> Scanning.line_count ib + | 'n' -> Scanning.char_count ib + | _ -> Scanning.token_count ib +;; + +let rec skip_whites ib = + let c = Scanning.peek_char ib in + if not (Scanning.eof ib) then begin + match c with + | ' ' | '\t' | '\n' | '\r' -> + Scanning.invalidate_current_char ib; skip_whites ib + | _ -> () + end +;; + +let list_iter_i f l = + let rec loop i = function + | [] -> () + | [x] -> f i x (* Tail calling [f] *) + | x :: xs -> f i x; loop (succ i) xs in + loop 0 l +;; + +(* The global error report function for [Scanf]. *) +let scanf_bad_input ib = function + | Scan_failure s | Failure s -> + let i = Scanning.char_count ib in + bad_input (Printf.sprintf "scanf: bad input at char number %i: %s" i s) + | x -> raise x +;; + +let ascanf sc fmt = + let ac = Tformat.ac_of_format fmt in + match ac.Tformat.ac_rdrs with + | 0 -> + Obj.magic (fun f -> sc fmt [||] f) + | 1 -> + Obj.magic (fun x f -> sc fmt [| Obj.repr x |] f) + | 2 -> + Obj.magic (fun x y f -> sc fmt [| Obj.repr x; Obj.repr y; |] f) + | 3 -> + Obj.magic + (fun x y z f -> sc fmt [| Obj.repr x; Obj.repr y; Obj.repr z; |] f) + | nargs -> + let rec loop i args = + if i >= nargs then + let a = Array.make nargs (Obj.repr 0) in + list_iter_i (fun i arg -> a.(nargs - i - 1) <- arg) args; + Obj.magic (fun f -> sc fmt a f) + else Obj.magic (fun x -> loop (succ i) (x :: args)) in + loop 0 [] +;; + +(* The [scan_format] main scanning function. + It takes as arguments: + - an input buffer [ib] from which to read characters, + - an error handling function [ef], + - a format [fmt] that specifies what to read in the input, + - a vector of user's defined readers rv, + - and a function [f] to pass the tokens read to. + + Then [scan_format] scans the format and the input buffer in parallel to + find out tokens as specified by the format; when it founds one token, it + converts it as specified, remembers the converted value as a future + argument to the function [f], and continues scanning. + + If the entire scanning succeeds (i.e. the format string has been + exhausted and the buffer has provided tokens according to the + format string), [f] is applied to the tokens. + + If the scanning or some conversion fails, the main scanning function + aborts and applies the scanning buffer and a string that explains + the error to the error handling function [ef] (the error continuation). *) + +let scan_format ib ef fmt rv f = + + let lim = Sformat.length fmt - 1 in + + let limr = Array.length rv - 1 in + + let return v = Obj.magic v () in + let delay f x () = f x in + let stack f = delay (return f) in + let no_stack f x = f in + + let rec scan fmt = + + let rec scan_fmt ir f i = + if i > lim then ir, f else + match Sformat.get fmt i with + | ' ' -> skip_whites ib; scan_fmt ir f (succ i) + | '%' -> + if i > lim then incomplete_format fmt else + scan_conversion false max_int ir f (succ i) + | '@' -> + let i = succ i in + if i > lim then incomplete_format fmt else begin + check_char ib (Sformat.get fmt i); + scan_fmt ir f (succ i) end + | c -> check_char ib c; scan_fmt ir f (succ i) + + and scan_conversion skip max ir f i = + let stack = if skip then no_stack else stack in + match Sformat.get fmt i with + | '%' as conv -> + check_char ib conv; scan_fmt ir f (succ i) + | 's' -> + let i, stp = scan_fmt_stoppers (succ i) in + let _x = scan_string stp max ib in + scan_fmt ir (stack f (token_string ib)) (succ i) + | 'S' -> + let _x = scan_String max ib in + scan_fmt ir (stack f (token_string ib)) (succ i) + | '[' (* ']' *) -> + let i, char_set = read_char_set fmt (succ i) in + let i, stp = scan_fmt_stoppers (succ i) in + let _x = scan_chars_in_char_set stp char_set max ib in + scan_fmt ir (stack f (token_string ib)) (succ i) + | 'c' when max = 0 -> + let c = Scanning.checked_peek_char ib in + scan_fmt ir (stack f c) (succ i) + | 'c' | 'C' as conv -> + if max <> 1 && max <> max_int then bad_conversion fmt i conv else + let _x = + if conv = 'c' then scan_char max ib else scan_Char max ib in + scan_fmt ir (stack f (token_char ib)) (succ i) + | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' as conv -> + let _x = scan_int_conv conv max ib in + scan_fmt ir (stack f (token_int conv ib)) (succ i) + | 'N' as conv -> + scan_fmt ir (stack f (get_count conv ib)) (succ i) + | 'f' | 'e' | 'E' | 'g' | 'G' -> + let _x = scan_float max ib in + scan_fmt ir (stack f (token_float ib)) (succ i) + | 'F' -> + let _x = scan_Float max ib in + scan_fmt ir (stack f (token_float ib)) (succ i) + | 'B' | 'b' -> + let _x = scan_bool max ib in + scan_fmt ir (stack f (token_bool ib)) (succ i) + | 'r' -> + if ir > limr then assert false else + let token = Obj.magic rv.(ir) ib in + scan_fmt (succ ir) (stack f token) (succ i) + | 'l' | 'n' | 'L' as conv -> + let i = succ i in + if i > lim then scan_fmt ir (stack f (get_count conv ib)) i else begin + match Sformat.get fmt i with + (* This is in fact an integer conversion (e.g. %ld, %ni, or %Lo). *) + | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' as conv -> + let _x = scan_int_conv conv max ib in + (* Look back to the character that triggered the integer conversion + (this character is either 'l', 'n' or 'L'), to find the + conversion to apply to the integer token read. *) + begin match Sformat.get fmt (i - 1) with + | 'l' -> scan_fmt ir (stack f (token_int32 conv ib)) (succ i) + | 'n' -> scan_fmt ir (stack f (token_nativeint conv ib)) (succ i) + | _ -> scan_fmt ir (stack f (token_int64 conv ib)) (succ i) end + (* This is not an integer conversion, but a regular %l, %n or %L. *) + | _ -> scan_fmt ir (stack f (get_count conv ib)) i end + | '!' -> + if Scanning.end_of_input ib then scan_fmt ir f (succ i) + else bad_input "end of input not found" + | '_' -> + if i > lim then incomplete_format fmt else + scan_conversion true max ir f (succ i) + | '0' .. '9' as conv -> + let rec read_width accu i = + if i > lim then accu, i else + match Sformat.get fmt i with + | '0' .. '9' as c -> + let accu = 10 * accu + int_value_of_char c in + read_width accu (succ i) + | _ -> accu, i in + let max, i = read_width (int_value_of_char conv) (succ i) in + if i > lim then incomplete_format fmt else begin + match Sformat.get fmt i with + | '.' -> + let p, i = read_width 0 (succ i) in + scan_conversion skip (succ (max + p)) ir f i + | _ -> scan_conversion skip max ir f i end + | '(' | '{' as conv (* ')' '}' *) -> + let i = succ i in + (* Find the static specification for the format to read. *) + let j = + Tformat.sub_format + incomplete_format bad_conversion conv fmt i in + let mf = Sformat.sub fmt (Sformat.index_of_int i) (j - 2 - i) in + (* Read the specified format string in the input buffer, + and check its correctness. *) + let _x = scan_String max ib in + let rf = token_string ib in + if not (compatible_format_type rf mf) then format_mismatch rf mf else + (* For conversion %{%}, just return this format string as the token + read. *) + if conv = '{' (* '}' *) then scan_fmt ir (stack f rf) j else + (* Or else, read according to the format string just read. *) + let ir, nf = scan (Obj.magic rf) ir (stack f rf) 0 in + (* Return the format string read and the value just read, + then go on with the rest of the format. *) + scan_fmt ir nf j + + | c -> bad_conversion fmt i c + + and scan_fmt_stoppers i = + if i > lim then i - 1, [] else + match Sformat.get fmt i with + | '@' when i < lim -> let i = succ i in i, [Sformat.get fmt i] + | '@' when i = lim -> incomplete_format fmt + | _ -> i - 1, [] in + + scan_fmt in + + + Scanning.reset_token ib; + + let v = + try snd (scan fmt 0 (fun () -> f) 0) with + | (Scan_failure _ | Failure _ | End_of_file) as exc -> + stack (delay ef ib) exc in + return v +;; + +let mkscanf ib ef fmt = + let sc = scan_format ib ef in + ascanf sc fmt +;; + +let kscanf ib ef fmt = mkscanf ib ef fmt;; + +let bscanf ib = kscanf ib scanf_bad_input;; + +let fscanf ic = bscanf (Scanning.from_channel ic);; + +let sscanf s = bscanf (Scanning.from_string s);; + +let scanf fmt = bscanf Scanning.stdib fmt;; + +let bscanf_format ib fmt f = + let fmt = Sformat.unsafe_to_string fmt in + let fmt1 = ignore (scan_String max_int ib); token_string ib in + if not (compatible_format_type fmt1 fmt) then + format_mismatch fmt1 fmt else + f (string_to_format fmt1) +;; + +let sscanf_format s fmt f = bscanf_format (Scanning.from_string s) fmt f;; + +let quote_string s = + let b = Buffer.create (String.length s + 2) in + Buffer.add_char b '\"'; + Buffer.add_string b s; + Buffer.add_char b '\"'; + Buffer.contents b +;; + +let format_from_string s fmt = + sscanf_format (quote_string s) fmt (fun x -> x) +;; diff --git a/stdlib/scanf.mli b/stdlib/scanf.mli new file mode 100644 index 0000000..8b99254 --- /dev/null +++ b/stdlib/scanf.mli @@ -0,0 +1,417 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: scanf.mli,v 1.79 2008-09-27 20:45:05 weis Exp $ *) + +(** Formatted input functions. *) + +(** {6 Introduction} *) + +(** {7 Functional input with format strings} *) + +(** The module [Scanf] provides formatted input functions or {e scanners}. + + The formatted input functions can read from any kind of input, including + strings, files, or anything that can return characters. The more general + source of characters is named a {e scanning buffer} and has type + {!Scanning.scanbuf}. The more general formatted input function reads from + any scanning buffer and is named [bscanf]. + + Generally speaking, the formatted input functions have 3 arguments: + - the first argument is a source of characters for the input, + - the second argument is a format string that specifies the values to + read, + - the third argument is a {e receiver function} that is applied to the + values read. + + Hence, a typical call to the formatted input function {!Scanf.bscanf} is + [bscanf ib fmt f], where: + + - [ib] is a source of characters (typically a {e + scanning buffer} with type {!Scanning.scanbuf}), + + - [fmt] is a format string (the same format strings as those used to print + material with module {!Printf} or {!Format}), + + - [f] is a function that has as many arguments as the number of values to + read in the input. *) + +(** {7 A simple example} *) + +(** As suggested above, the expression [bscanf ib "%d" f] reads a decimal + integer [n] from the source of characters [ib] and returns [f n]. + + For instance, + + - if we use [stdib] as the source of characters ({!Scanning.stdib} is + the predefined input buffer that reads from standard input), + + - if we define the receiver [f] as [let f x = x + 1], + + then [bscanf stdib "%d" f] reads an integer [n] from the standard input + and returns [f n] (that is [n + 1]). Thus, if we evaluate [bscanf stdib + "%d" f], and then enter [41] at the keyboard, we get [42] as the final + result. *) + +(** {7 Formatted input as a functional feature} *) + +(** The Caml scanning facility is reminiscent of the corresponding C feature. + However, it is also largely different, simpler, and yet more powerful: + the formatted input functions are higher-order functionals and the + parameter passing mechanism is just the regular function application not + the variable assigment based mechanism which is typical for formatted + input in imperative languages; the Caml format strings also feature + useful additions to easily define complex tokens; as expected within a + functional programming language, the formatted input functions also + support polymorphism, in particular arbitrary interaction with + polymorphic user-defined scanners. Furthermore, the Caml formatted input + facility is fully type-checked at compile time. *) + +(** {6 Scanning buffers} *) +module Scanning : sig + +type scanbuf;; +(** The type of scanning buffers. A scanning buffer is the source from which a + formatted input function gets characters. The scanning buffer holds the + current state of the scan, plus a function to get the next char from the + input, and a token buffer to store the string matched so far. + + Note: a scan may often require to examine one character in advance; + when this ``lookahead'' character does not belong to the token read, + it is stored back in the scanning buffer and becomes the next + character read. *) + +val stdib : scanbuf;; +(** The scanning buffer reading from [stdin]. + [stdib] is equivalent to [Scanning.from_channel stdin]. + + Note: when input is read interactively from [stdin], the newline character + that triggers the evaluation is incorporated in the input; thus, scanning + specifications must properly skip this character (simply add a ['\n'] + as the last character of the format string). *) + +val from_string : string -> scanbuf;; +(** [Scanning.from_string s] returns a scanning buffer which reads from the + given string. + Reading starts from the first character in the string. + The end-of-input condition is set when the end of the string is reached. *) + +val from_file : string -> scanbuf;; +(** Bufferized file reading in text mode. The efficient and usual + way to scan text mode files (in effect, [from_file] returns a + scanning buffer that reads characters in large chunks, rather than one + character at a time as buffers returned by [from_channel] do). + [Scanning.from_file fname] returns a scanning buffer which reads + from the given file [fname] in text mode. *) + +val from_file_bin : string -> scanbuf;; +(** Bufferized file reading in binary mode. *) + +val from_function : (unit -> char) -> scanbuf;; +(** [Scanning.from_function f] returns a scanning buffer with the given + function as its reading method. + + When scanning needs one more character, the given function is called. + + When the function has no more character to provide, it must signal an + end-of-input condition by raising the exception [End_of_file]. *) + +val from_channel : in_channel -> scanbuf;; +(** [Scanning.from_channel ic] returns a scanning buffer which reads from the + input channel [ic], starting at the current reading position. *) + +val end_of_input : scanbuf -> bool;; +(** [Scanning.end_of_input ib] tests the end-of-input condition of the given + scanning buffer. *) + +val beginning_of_input : scanbuf -> bool;; +(** [Scanning.beginning_of_input ib] tests the beginning of input condition of + the given scanning buffer. *) + +val name_of_input : scanbuf -> string;; +(** [Scanning.file_name_of_input ib] returns the name of the character source + for the scanning buffer [ib]. *) + +end;; + +(** {6 Type of formatted input functions} *) + +type ('a, 'b, 'c, 'd) scanner = + ('a, Scanning.scanbuf, 'b, 'c, 'a -> 'd, 'd) format6 -> 'c;; +(** The type of formatted input scanners: [('a, 'b, 'c, 'd) scanner] is the + type of a formatted input function that reads from some scanning buffer + according to some format string; more precisely, if [scan] is some + formatted input function, then [scan ib fmt f] applies [f] to the arguments + specified by the format string [fmt], when [scan] has read those arguments + from the scanning input buffer [ib]. + + For instance, the [scanf] function below has type [('a, 'b, 'c, 'd) + scanner], since it is a formatted input function that reads from [stdib]: + [scanf fmt f] applies [f] to the arguments specified by [fmt], reading + those arguments from [stdin] as expected. + + If the format [fmt] has some [%r] indications, the corresponding input + functions must be provided before the receiver [f] argument. For + instance, if [read_elem] is an input function for values of type [t], + then [bscanf ib "%r;" read_elem f] reads a value [v] of type [t] followed + by a [';'] character, and returns [f v]. *) + +exception Scan_failure of string;; +(** The exception that formatted input functions raise when the input cannot be + read according to the given format. *) + +(** {6 The general formatted input function} *) + +val bscanf : Scanning.scanbuf -> ('a, 'b, 'c, 'd) scanner;; +(** [bscanf ib fmt r1 ... rN f] reads arguments for the function [f], from the + scanning buffer [ib], according to the format string [fmt], and applies [f] + to these values. + The result of this call to [f] is returned as the result of the entire + [bscanf] call. + For instance, if [f] is the function [fun s i -> i + 1], then + [Scanf.sscanf "x= 1" "%s = %i" f] returns [2]. + + Arguments [r1] to [rN] are user-defined input functions that read the + argument corresponding to a [%r] conversion. *) + +(** {6 Format string description} *) + +(** The format is a character string which contains three types of + objects: + - plain characters, which are simply matched with the characters of the + input, + - conversion specifications, each of which causes reading and conversion of + one argument for the function [f], + - scanning indications to specify boundaries of tokens. *) + +(** {7 The space character in format strings} *) + +(** As mentioned above, a plain character in the format string is just + matched with the characters of the input; however, one character is a + special exception to this simple rule: the space character (ASCII code + 32) does not match a single space character, but any amount of + ``whitespace'' in the input. More precisely, a space inside the format + string matches {e any number} of tab, space, line feed and carriage + return characters. + + Matching {e any} amount of whitespace, a space in the format string + also matches no amount of whitespace at all; hence, the call [bscanf ib + "Price = %d $" (fun p -> p)] succeds and returns [1] when reading an + input with various whitespace in it, such as [Price = 1 $], + [Price = 1 $], or even [Price=1$]. *) + +(** {7 Conversion specifications in format strings} *) + +(** Conversion specifications consist in the [%] character, followed by + an optional flag, an optional field width, and followed by one or + two conversion characters. The conversion characters and their + meanings are: + + - [d]: reads an optionally signed decimal integer. + - [i]: reads an optionally signed integer + (usual input formats for hexadecimal ([0x[d]+] and [0X[d]+]), + octal ([0o[d]+]), and binary [0b[d]+] notations are understood). + - [u]: reads an unsigned decimal integer. + - [x] or [X]: reads an unsigned hexadecimal integer. + - [o]: reads an unsigned octal integer. + - [s]: reads a string argument that spreads as much as possible, until the + following bounding condition holds: a whitespace has been found, a + scanning indication has been encountered, or the end-of-input has been + reached. + Hence, this conversion always succeeds: it returns an empty + string, if the bounding condition holds when the scan begins. + - [S]: reads a delimited string argument (delimiters and special + escaped characters follow the lexical conventions of Caml). + - [c]: reads a single character. To test the current input character + without reading it, specify a null field width, i.e. use + specification [%0c]. Raise [Invalid_argument], if the field width + specification is greater than 1. + - [C]: reads a single delimited character (delimiters and special + escaped characters follow the lexical conventions of Caml). + - [f], [e], [E], [g], [G]: reads an optionally signed + floating-point number in decimal notation, in the style [dddd.ddd + e/E+-dd]. + - [F]: reads a floating point number according to the lexical + conventions of Caml (hence the decimal point is mandatory if the + exponent part is not mentioned). + - [B]: reads a boolean argument ([true] or [false]). + - [b]: reads a boolean argument (for backward compatibility; do not use + in new programs). + - [ld], [li], [lu], [lx], [lX], [lo]: reads an [int32] argument to + the format specified by the second letter (decimal, hexadecimal, etc). + - [nd], [ni], [nu], [nx], [nX], [no]: reads a [nativeint] argument to + the format specified by the second letter. + - [Ld], [Li], [Lu], [Lx], [LX], [Lo]: reads an [int64] argument to + the format specified by the second letter. + - [\[ range \]]: reads characters that matches one of the characters + mentioned in the range of characters [range] (or not mentioned in + it, if the range starts with [^]). Reads a [string] that can be + empty, if the next input character does not match the range. The set of + characters from [c1] to [c2] (inclusively) is denoted by [c1-c2]. + Hence, [%\[0-9\]] returns a string representing a decimal number + or an empty string if no decimal digit is found; similarly, + [%\[\\048-\\057\\065-\\070\]] returns a string of hexadecimal digits. + If a closing bracket appears in a range, it must occur as the + first character of the range (or just after the [^] in case of + range negation); hence [\[\]\]] matches a [\]] character and + [\[^\]\]] matches any character that is not [\]]. + - [r]: user-defined reader. Takes the next [ri] formatted input function and + applies it to the scanning buffer [ib] to read the next argument. The + input function [ri] must therefore have type [Scanning.scanbuf -> 'a] and + the argument read has type ['a]. + - [\{ fmt %\}]: reads a format string argument. + The format string read must have the same type as the format string + specification [fmt]. + For instance, ["%\{%i%\}"] reads any format string that can read a value of + type [int]; hence [Scanf.sscanf "fmt:\\\"number is %u\\\"" "fmt:%\{%i%\}"] + succeeds and returns the format string ["number is %u"]. + - [\( fmt %\)]: scanning format substitution. + Reads a format string to replace [fmt]. + The format string read must have the same type as the format string + specification [fmt]. + For instance, ["%\( %i% \)"] reads any format string that can read a value + of type [int]; hence [Scanf.sscanf "\\\"%4d\\\"1234.00" "%\(%i%\)"] + is equivalent to [Scanf.sscanf "1234.00" "%4d"]. + - [l]: returns the number of lines read so far. + - [n]: returns the number of characters read so far. + - [N] or [L]: returns the number of tokens read so far. + - [!]: matches the end of input condition. + - [%]: matches one [%] character in the input. + + Following the [%] character that introduces a conversion, there may be + the special flag [_]: the conversion that follows occurs as usual, + but the resulting value is discarded. + For instance, if [f] is the function [fun i -> i + 1], then + [Scanf.sscanf "x = 1" "%_s = %i" f] returns [2]. + + The field width is composed of an optional integer literal + indicating the maximal width of the token to read. + For instance, [%6d] reads an integer, having at most 6 decimal digits; + [%4f] reads a float with at most 4 characters; and [%8\[\\000-\\255\]] + returns the next 8 characters (or all the characters still available, + if fewer than 8 characters are available in the input). + + Notes: + + - as mentioned above, a [%s] convertion always succeeds, even if there is + nothing to read in the input: it simply returns [""]. + + - in addition to the relevant digits, ['_'] characters may appear + inside numbers (this is reminiscent to the usual Caml lexical + conventions). If stricter scanning is desired, use the range + conversion facility instead of the number conversions. + + - the [scanf] facility is not intended for heavy duty lexical + analysis and parsing. If it appears not expressive enough for your + needs, several alternative exists: regular expressions (module + [Str]), stream parsers, [ocamllex]-generated lexers, + [ocamlyacc]-generated parsers. *) + +(** {7 Scanning indications in format strings} *) + +(** Scanning indications appear just after the string conversions [%s] + and [%\[ range \]] to delimit the end of the token. A scanning + indication is introduced by a [@] character, followed by some + constant character [c]. It means that the string token should end + just before the next matching [c] (which is skipped). If no [c] + character is encountered, the string token spreads as much as + possible. For instance, ["%s@\t"] reads a string up to the next + tab character or to the end of input. If a scanning + indication [\@c] does not follow a string conversion, it is treated + as a plain [c] character. + + Note: + + - the scanning indications introduce slight differences in the syntax of + [Scanf] format strings, compared to those used for the [Printf] + module. However, the scanning indications are similar to those used in + the [Format] module; hence, when producing formatted text to be scanned + by [!Scanf.bscanf], it is wise to use printing functions from the + [Format] module (or, if you need to use functions from [Printf], banish + or carefully double check the format strings that contain ['\@'] + characters). *) + +(** {7 Exceptions during scanning} *) + +(** Scanners may raise the following exceptions when the input cannot be read + according to the format string: + + - Raise [Scanf.Scan_failure] if the input does not match the format. + + - Raise [Failure] if a conversion to a number is not possible. + + - Raise [End_of_file] if the end of input is encountered while some more + characters are needed to read the current conversion specification. + + - Raise [Invalid_argument] if the format string is invalid. + + Note: + + - as a consequence, scanning a [%s] conversion never raises exception + [End_of_file]: if the end of input is reached the conversion succeeds and + simply returns the characters read so far, or [""] if none were read. *) + +(** {6 Specialized formatted input functions} *) + +val fscanf : in_channel -> ('a, 'b, 'c, 'd) scanner;; +(** Same as {!Scanf.bscanf}, but reads from the given channel. + + Warning: since all formatted input functions operate from a scanning + buffer, be aware that each [fscanf] invocation will operate with a + scanning buffer reading from the given channel. This extra level of + bufferization can lead to strange scanning behaviour if you use low level + primitives on the channel (reading characters, seeking the reading + position, and so on). + + As a consequence, never mixt direct low level reading and high level + scanning from the same input channel. *) + +val sscanf : string -> ('a, 'b, 'c, 'd) scanner;; +(** Same as {!Scanf.bscanf}, but reads from the given string. *) + +val scanf : ('a, 'b, 'c, 'd) scanner;; +(** Same as {!Scanf.bscanf}, but reads from the predefined scanning + buffer {!Scanf.Scanning.stdib} that is connected to [stdin]. *) + +val kscanf : + Scanning.scanbuf -> (Scanning.scanbuf -> exn -> 'd) -> + ('a, 'b, 'c, 'd) scanner;; +(** Same as {!Scanf.bscanf}, but takes an additional function argument + [ef] that is called in case of error: if the scanning process or + some conversion fails, the scanning function aborts and calls the + error handling function [ef] with the scanning buffer and the + exception that aborted the scanning process. *) + +(** {6 Reading format strings from input} *) + +val bscanf_format : + Scanning.scanbuf -> ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;; +(** [bscanf_format ib fmt f] reads a format string token from the scannning + buffer [ib], according to the given format string [fmt], and applies [f] to + the resulting format string value. + Raise [Scan_failure] if the format string value read does not have the + same type as [fmt]. *) + +val sscanf_format : + string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 -> + (('a, 'b, 'c, 'd, 'e, 'f) format6 -> 'g) -> 'g;; +(** Same as {!Scanf.bscanf_format}, but reads from the given string. *) + +val format_from_string : + string -> + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ('a, 'b, 'c, 'd, 'e, 'f) format6;; +(** [format_from_string s fmt] converts a string argument to a format string, + according to the given format string [fmt]. + Raise [Scan_failure] if [s], considered as a format string, does not + have the same type as [fmt]. *) diff --git a/stdlib/set.ml b/stdlib/set.ml new file mode 100644 index 0000000..a578d33 --- /dev/null +++ b/stdlib/set.ml @@ -0,0 +1,330 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: set.ml,v 1.19 2004-11-25 00:04:15 doligez Exp $ *) + +(* Sets over ordered types *) + +module type OrderedType = + sig + type t + val compare: t -> t -> int + end + +module type S = + sig + type elt + type t + val empty: t + val is_empty: t -> bool + val mem: elt -> t -> bool + val add: elt -> t -> t + val singleton: elt -> t + val remove: elt -> t -> t + val union: t -> t -> t + val inter: t -> t -> t + val diff: t -> t -> t + val compare: t -> t -> int + val equal: t -> t -> bool + val subset: t -> t -> bool + val iter: (elt -> unit) -> t -> unit + val fold: (elt -> 'a -> 'a) -> t -> 'a -> 'a + val for_all: (elt -> bool) -> t -> bool + val exists: (elt -> bool) -> t -> bool + val filter: (elt -> bool) -> t -> t + val partition: (elt -> bool) -> t -> t * t + val cardinal: t -> int + val elements: t -> elt list + val min_elt: t -> elt + val max_elt: t -> elt + val choose: t -> elt + val split: elt -> t -> t * bool * t + end + +module Make(Ord: OrderedType) = + struct + type elt = Ord.t + type t = Empty | Node of t * elt * t * int + + (* Sets are represented by balanced binary trees (the heights of the + children differ by at most 2 *) + + let height = function + Empty -> 0 + | Node(_, _, _, h) -> h + + (* Creates a new node with left son l, value v and right son r. + We must have all elements of l < v < all elements of r. + l and r must be balanced and | height l - height r | <= 2. + Inline expansion of height for better speed. *) + + let create l v r = + let hl = match l with Empty -> 0 | Node(_,_,_,h) -> h in + let hr = match r with Empty -> 0 | Node(_,_,_,h) -> h in + Node(l, v, r, (if hl >= hr then hl + 1 else hr + 1)) + + (* Same as create, but performs one step of rebalancing if necessary. + Assumes l and r balanced and | height l - height r | <= 3. + Inline expansion of create for better speed in the most frequent case + where no rebalancing is required. *) + + let bal l v r = + let hl = match l with Empty -> 0 | Node(_,_,_,h) -> h in + let hr = match r with Empty -> 0 | Node(_,_,_,h) -> h in + if hl > hr + 2 then begin + match l with + Empty -> invalid_arg "Set.bal" + | Node(ll, lv, lr, _) -> + if height ll >= height lr then + create ll lv (create lr v r) + else begin + match lr with + Empty -> invalid_arg "Set.bal" + | Node(lrl, lrv, lrr, _)-> + create (create ll lv lrl) lrv (create lrr v r) + end + end else if hr > hl + 2 then begin + match r with + Empty -> invalid_arg "Set.bal" + | Node(rl, rv, rr, _) -> + if height rr >= height rl then + create (create l v rl) rv rr + else begin + match rl with + Empty -> invalid_arg "Set.bal" + | Node(rll, rlv, rlr, _) -> + create (create l v rll) rlv (create rlr rv rr) + end + end else + Node(l, v, r, (if hl >= hr then hl + 1 else hr + 1)) + + (* Insertion of one element *) + + let rec add x = function + Empty -> Node(Empty, x, Empty, 1) + | Node(l, v, r, _) as t -> + let c = Ord.compare x v in + if c = 0 then t else + if c < 0 then bal (add x l) v r else bal l v (add x r) + + (* Same as create and bal, but no assumptions are made on the + relative heights of l and r. *) + + let rec join l v r = + match (l, r) with + (Empty, _) -> add v r + | (_, Empty) -> add v l + | (Node(ll, lv, lr, lh), Node(rl, rv, rr, rh)) -> + if lh > rh + 2 then bal ll lv (join lr v r) else + if rh > lh + 2 then bal (join l v rl) rv rr else + create l v r + + (* Smallest and greatest element of a set *) + + let rec min_elt = function + Empty -> raise Not_found + | Node(Empty, v, r, _) -> v + | Node(l, v, r, _) -> min_elt l + + let rec max_elt = function + Empty -> raise Not_found + | Node(l, v, Empty, _) -> v + | Node(l, v, r, _) -> max_elt r + + (* Remove the smallest element of the given set *) + + let rec remove_min_elt = function + Empty -> invalid_arg "Set.remove_min_elt" + | Node(Empty, v, r, _) -> r + | Node(l, v, r, _) -> bal (remove_min_elt l) v r + + (* Merge two trees l and r into one. + All elements of l must precede the elements of r. + Assume | height l - height r | <= 2. *) + + let merge t1 t2 = + match (t1, t2) with + (Empty, t) -> t + | (t, Empty) -> t + | (_, _) -> bal t1 (min_elt t2) (remove_min_elt t2) + + (* Merge two trees l and r into one. + All elements of l must precede the elements of r. + No assumption on the heights of l and r. *) + + let concat t1 t2 = + match (t1, t2) with + (Empty, t) -> t + | (t, Empty) -> t + | (_, _) -> join t1 (min_elt t2) (remove_min_elt t2) + + (* Splitting. split x s returns a triple (l, present, r) where + - l is the set of elements of s that are < x + - r is the set of elements of s that are > x + - present is false if s contains no element equal to x, + or true if s contains an element equal to x. *) + + let rec split x = function + Empty -> + (Empty, false, Empty) + | Node(l, v, r, _) -> + let c = Ord.compare x v in + if c = 0 then (l, true, r) + else if c < 0 then + let (ll, pres, rl) = split x l in (ll, pres, join rl v r) + else + let (lr, pres, rr) = split x r in (join l v lr, pres, rr) + + (* Implementation of the set operations *) + + let empty = Empty + + let is_empty = function Empty -> true | _ -> false + + let rec mem x = function + Empty -> false + | Node(l, v, r, _) -> + let c = Ord.compare x v in + c = 0 || mem x (if c < 0 then l else r) + + let singleton x = Node(Empty, x, Empty, 1) + + let rec remove x = function + Empty -> Empty + | Node(l, v, r, _) -> + let c = Ord.compare x v in + if c = 0 then merge l r else + if c < 0 then bal (remove x l) v r else bal l v (remove x r) + + let rec union s1 s2 = + match (s1, s2) with + (Empty, t2) -> t2 + | (t1, Empty) -> t1 + | (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) -> + if h1 >= h2 then + if h2 = 1 then add v2 s1 else begin + let (l2, _, r2) = split v1 s2 in + join (union l1 l2) v1 (union r1 r2) + end + else + if h1 = 1 then add v1 s2 else begin + let (l1, _, r1) = split v2 s1 in + join (union l1 l2) v2 (union r1 r2) + end + + let rec inter s1 s2 = + match (s1, s2) with + (Empty, t2) -> Empty + | (t1, Empty) -> Empty + | (Node(l1, v1, r1, _), t2) -> + match split v1 t2 with + (l2, false, r2) -> + concat (inter l1 l2) (inter r1 r2) + | (l2, true, r2) -> + join (inter l1 l2) v1 (inter r1 r2) + + let rec diff s1 s2 = + match (s1, s2) with + (Empty, t2) -> Empty + | (t1, Empty) -> t1 + | (Node(l1, v1, r1, _), t2) -> + match split v1 t2 with + (l2, false, r2) -> + join (diff l1 l2) v1 (diff r1 r2) + | (l2, true, r2) -> + concat (diff l1 l2) (diff r1 r2) + + type enumeration = End | More of elt * t * enumeration + + let rec cons_enum s e = + match s with + Empty -> e + | Node(l, v, r, _) -> cons_enum l (More(v, r, e)) + + let rec compare_aux e1 e2 = + match (e1, e2) with + (End, End) -> 0 + | (End, _) -> -1 + | (_, End) -> 1 + | (More(v1, r1, e1), More(v2, r2, e2)) -> + let c = Ord.compare v1 v2 in + if c <> 0 + then c + else compare_aux (cons_enum r1 e1) (cons_enum r2 e2) + + let compare s1 s2 = + compare_aux (cons_enum s1 End) (cons_enum s2 End) + + let equal s1 s2 = + compare s1 s2 = 0 + + let rec subset s1 s2 = + match (s1, s2) with + Empty, _ -> + true + | _, Empty -> + false + | Node (l1, v1, r1, _), (Node (l2, v2, r2, _) as t2) -> + let c = Ord.compare v1 v2 in + if c = 0 then + subset l1 l2 && subset r1 r2 + else if c < 0 then + subset (Node (l1, v1, Empty, 0)) l2 && subset r1 t2 + else + subset (Node (Empty, v1, r1, 0)) r2 && subset l1 t2 + + let rec iter f = function + Empty -> () + | Node(l, v, r, _) -> iter f l; f v; iter f r + + let rec fold f s accu = + match s with + Empty -> accu + | Node(l, v, r, _) -> fold f r (f v (fold f l accu)) + + let rec for_all p = function + Empty -> true + | Node(l, v, r, _) -> p v && for_all p l && for_all p r + + let rec exists p = function + Empty -> false + | Node(l, v, r, _) -> p v || exists p l || exists p r + + let filter p s = + let rec filt accu = function + | Empty -> accu + | Node(l, v, r, _) -> + filt (filt (if p v then add v accu else accu) l) r in + filt Empty s + + let partition p s = + let rec part (t, f as accu) = function + | Empty -> accu + | Node(l, v, r, _) -> + part (part (if p v then (add v t, f) else (t, add v f)) l) r in + part (Empty, Empty) s + + let rec cardinal = function + Empty -> 0 + | Node(l, v, r, _) -> cardinal l + 1 + cardinal r + + let rec elements_aux accu = function + Empty -> accu + | Node(l, v, r, _) -> elements_aux (v :: elements_aux accu r) l + + let elements s = + elements_aux [] s + + let choose = min_elt + + end diff --git a/stdlib/set.mli b/stdlib/set.mli new file mode 100644 index 0000000..c96e5bf --- /dev/null +++ b/stdlib/set.mli @@ -0,0 +1,153 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: set.mli,v 1.33 2005-07-21 14:52:45 doligez Exp $ *) + +(** Sets over ordered types. + + This module implements the set data structure, given a total ordering + function over the set elements. All operations over sets + are purely applicative (no side-effects). + The implementation uses balanced binary trees, and is therefore + reasonably efficient: insertion and membership take time + logarithmic in the size of the set, for instance. +*) + +module type OrderedType = + sig + type t + (** The type of the set elements. *) + val compare : t -> t -> int + (** A total ordering function over the set elements. + This is a two-argument function [f] such that + [f e1 e2] is zero if the elements [e1] and [e2] are equal, + [f e1 e2] is strictly negative if [e1] is smaller than [e2], + and [f e1 e2] is strictly positive if [e1] is greater than [e2]. + Example: a suitable ordering function is the generic structural + comparison function {!Pervasives.compare}. *) + end +(** Input signature of the functor {!Set.Make}. *) + +module type S = + sig + type elt + (** The type of the set elements. *) + + type t + (** The type of sets. *) + + val empty: t + (** The empty set. *) + + val is_empty: t -> bool + (** Test whether a set is empty or not. *) + + val mem: elt -> t -> bool + (** [mem x s] tests whether [x] belongs to the set [s]. *) + + val add: elt -> t -> t + (** [add x s] returns a set containing all elements of [s], + plus [x]. If [x] was already in [s], [s] is returned unchanged. *) + + val singleton: elt -> t + (** [singleton x] returns the one-element set containing only [x]. *) + + val remove: elt -> t -> t + (** [remove x s] returns a set containing all elements of [s], + except [x]. If [x] was not in [s], [s] is returned unchanged. *) + + val union: t -> t -> t + (** Set union. *) + + val inter: t -> t -> t + (** Set intersection. *) + + (** Set difference. *) + val diff: t -> t -> t + + val compare: t -> t -> int + (** Total ordering between sets. Can be used as the ordering function + for doing sets of sets. *) + + val equal: t -> t -> bool + (** [equal s1 s2] tests whether the sets [s1] and [s2] are + equal, that is, contain equal elements. *) + + val subset: t -> t -> bool + (** [subset s1 s2] tests whether the set [s1] is a subset of + the set [s2]. *) + + val iter: (elt -> unit) -> t -> unit + (** [iter f s] applies [f] in turn to all elements of [s]. + The elements of [s] are presented to [f] in increasing order + with respect to the ordering over the type of the elements. *) + + val fold: (elt -> 'a -> 'a) -> t -> 'a -> 'a + (** [fold f s a] computes [(f xN ... (f x2 (f x1 a))...)], + where [x1 ... xN] are the elements of [s], in increasing order. *) + + val for_all: (elt -> bool) -> t -> bool + (** [for_all p s] checks if all elements of the set + satisfy the predicate [p]. *) + + val exists: (elt -> bool) -> t -> bool + (** [exists p s] checks if at least one element of + the set satisfies the predicate [p]. *) + + val filter: (elt -> bool) -> t -> t + (** [filter p s] returns the set of all elements in [s] + that satisfy predicate [p]. *) + + val partition: (elt -> bool) -> t -> t * t + (** [partition p s] returns a pair of sets [(s1, s2)], where + [s1] is the set of all the elements of [s] that satisfy the + predicate [p], and [s2] is the set of all the elements of + [s] that do not satisfy [p]. *) + + val cardinal: t -> int + (** Return the number of elements of a set. *) + + val elements: t -> elt list + (** Return the list of all elements of the given set. + The returned list is sorted in increasing order with respect + to the ordering [Ord.compare], where [Ord] is the argument + given to {!Set.Make}. *) + + val min_elt: t -> elt + (** Return the smallest element of the given set + (with respect to the [Ord.compare] ordering), or raise + [Not_found] if the set is empty. *) + + val max_elt: t -> elt + (** Same as {!Set.S.min_elt}, but returns the largest element of the + given set. *) + + val choose: t -> elt + (** Return one element of the given set, or raise [Not_found] if + the set is empty. Which element is chosen is unspecified, + but equal elements will be chosen for equal sets. *) + + val split: elt -> t -> t * bool * t + (** [split x s] returns a triple [(l, present, r)], where + [l] is the set of elements of [s] that are + strictly less than [x]; + [r] is the set of elements of [s] that are + strictly greater than [x]; + [present] is [false] if [s] contains no element equal to [x], + or [true] if [s] contains an element equal to [x]. *) + end +(** Output signature of the functor {!Set.Make}. *) + +module Make (Ord : OrderedType) : S with type elt = Ord.t +(** Functor building an implementation of the set structure + given a totally ordered type. *) diff --git a/stdlib/sharpbang b/stdlib/sharpbang new file mode 100644 index 0000000..04c9334 --- /dev/null +++ b/stdlib/sharpbang @@ -0,0 +1 @@ +#! \ No newline at end of file diff --git a/stdlib/sort.ml b/stdlib/sort.ml new file mode 100644 index 0000000..82dc824 --- /dev/null +++ b/stdlib/sort.ml @@ -0,0 +1,99 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: sort.ml,v 1.10 2005-10-25 18:34:07 doligez Exp $ *) + +(* Merging and sorting *) + +open Array + +let rec merge order l1 l2 = + match l1 with + [] -> l2 + | h1 :: t1 -> + match l2 with + [] -> l1 + | h2 :: t2 -> + if order h1 h2 + then h1 :: merge order t1 l2 + else h2 :: merge order l1 t2 + +let list order l = + let rec initlist = function + [] -> [] + | [e] -> [[e]] + | e1::e2::rest -> + (if order e1 e2 then [e1;e2] else [e2;e1]) :: initlist rest in + let rec merge2 = function + l1::l2::rest -> merge order l1 l2 :: merge2 rest + | x -> x in + let rec mergeall = function + [] -> [] + | [l] -> l + | llist -> mergeall (merge2 llist) in + mergeall(initlist l) + +let swap arr i j = + let tmp = unsafe_get arr i in + unsafe_set arr i (unsafe_get arr j); + unsafe_set arr j tmp + +(* There is a known performance bug in the code below. If you find + it, don't bother reporting it. You're not supposed to use this + module anyway. *) +let array cmp arr = + let rec qsort lo hi = + if hi - lo >= 6 then begin + let mid = (lo + hi) lsr 1 in + (* Select median value from among LO, MID, and HI. Rearrange + LO and HI so the three values are sorted. This lowers the + probability of picking a pathological pivot. It also + avoids extra comparisons on i and j in the two tight "while" + loops below. *) + if cmp (unsafe_get arr mid) (unsafe_get arr lo) then swap arr mid lo; + if cmp (unsafe_get arr hi) (unsafe_get arr mid) then begin + swap arr mid hi; + if cmp (unsafe_get arr mid) (unsafe_get arr lo) then swap arr mid lo + end; + let pivot = unsafe_get arr mid in + let i = ref (lo + 1) and j = ref (hi - 1) in + if not (cmp pivot (unsafe_get arr hi)) + || not (cmp (unsafe_get arr lo) pivot) + then raise (Invalid_argument "Sort.array"); + while !i < !j do + while not (cmp pivot (unsafe_get arr !i)) do incr i done; + while not (cmp (unsafe_get arr !j) pivot) do decr j done; + if !i < !j then swap arr !i !j; + incr i; decr j + done; + (* Recursion on smaller half, tail-call on larger half *) + if !j - lo <= hi - !i then begin + qsort lo !j; qsort !i hi + end else begin + qsort !i hi; qsort lo !j + end + end in + qsort 0 (Array.length arr - 1); + (* Finish sorting by insertion sort *) + for i = 1 to Array.length arr - 1 do + let val_i = (unsafe_get arr i) in + if not (cmp (unsafe_get arr (i - 1)) val_i) then begin + unsafe_set arr i (unsafe_get arr (i - 1)); + let j = ref (i - 1) in + while !j >= 1 && not (cmp (unsafe_get arr (!j - 1)) val_i) do + unsafe_set arr !j (unsafe_get arr (!j - 1)); + decr j + done; + unsafe_set arr !j val_i + end + done diff --git a/stdlib/sort.mli b/stdlib/sort.mli new file mode 100644 index 0000000..9f64df4 --- /dev/null +++ b/stdlib/sort.mli @@ -0,0 +1,41 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: sort.mli,v 1.14 2005-10-25 18:34:07 doligez Exp $ *) + +(** Sorting and merging lists. + + @deprecated This module is obsolete and exists only for backward + compatibility. + The sorting functions in {!Array} and {!List} should be used instead. + The new functions are faster and use less memory. +*) + +val list : ('a -> 'a -> bool) -> 'a list -> 'a list +(** Sort a list in increasing order according to an ordering predicate. + The predicate should return [true] if its first argument is + less than or equal to its second argument. *) + +val array : ('a -> 'a -> bool) -> 'a array -> unit +(** Sort an array in increasing order according to an + ordering predicate. + The predicate should return [true] if its first argument is + less than or equal to its second argument. + The array is sorted in place. *) + +val merge : ('a -> 'a -> bool) -> 'a list -> 'a list -> 'a list +(** Merge two lists according to the given predicate. + Assuming the two argument lists are sorted according to the + predicate, [merge] returns a sorted list containing the elements + from the two lists. The behavior is undefined if the two + argument lists were not sorted. *) diff --git a/stdlib/stack.ml b/stdlib/stack.ml new file mode 100644 index 0000000..e1e767d --- /dev/null +++ b/stdlib/stack.ml @@ -0,0 +1,42 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stack.ml,v 1.9 2002-06-27 08:48:26 xleroy Exp $ *) + +type 'a t = { mutable c : 'a list } + +exception Empty + +let create () = { c = [] } + +let clear s = s.c <- [] + +let copy s = { c = s.c } + +let push x s = s.c <- x :: s.c + +let pop s = + match s.c with + hd::tl -> s.c <- tl; hd + | [] -> raise Empty + +let top s = + match s.c with + hd::_ -> hd + | [] -> raise Empty + +let is_empty s = (s.c = []) + +let length s = List.length s.c + +let iter f s = List.iter f s.c diff --git a/stdlib/stack.mli b/stdlib/stack.mli new file mode 100644 index 0000000..ed74657 --- /dev/null +++ b/stdlib/stack.mli @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stack.mli,v 1.19 2005-10-25 18:34:07 doligez Exp $ *) + +(** Last-in first-out stacks. + + This module implements stacks (LIFOs), with in-place modification. +*) + +type 'a t +(** The type of stacks containing elements of type ['a]. *) + +exception Empty +(** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. *) + + +val create : unit -> 'a t +(** Return a new stack, initially empty. *) + +val push : 'a -> 'a t -> unit +(** [push x s] adds the element [x] at the top of stack [s]. *) + +val pop : 'a t -> 'a +(** [pop s] removes and returns the topmost element in stack [s], + or raises [Empty] if the stack is empty. *) + +val top : 'a t -> 'a +(** [top s] returns the topmost element in stack [s], + or raises [Empty] if the stack is empty. *) + +val clear : 'a t -> unit +(** Discard all elements from a stack. *) + +val copy : 'a t -> 'a t +(** Return a copy of the given stack. *) + +val is_empty : 'a t -> bool +(** Return [true] if the given stack is empty, [false] otherwise. *) + +val length : 'a t -> int +(** Return the number of elements in a stack. *) + +val iter : ('a -> unit) -> 'a t -> unit +(** [iter f s] applies [f] in turn to all elements of [s], + from the element at the top of the stack to the element at the + bottom of the stack. The stack itself is unchanged. *) diff --git a/stdlib/stdLabels.ml b/stdlib/stdLabels.ml new file mode 100644 index 0000000..3fd7875 --- /dev/null +++ b/stdlib/stdLabels.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stdLabels.ml,v 1.3 2001-12-07 13:40:59 xleroy Exp $ *) + +(* Module [StdLabels]: meta-module for labelled libraries *) + +module Array = ArrayLabels + +module List = ListLabels + +module String = StringLabels diff --git a/stdlib/stdLabels.mli b/stdlib/stdLabels.mli new file mode 100644 index 0000000..1804128 --- /dev/null +++ b/stdlib/stdLabels.mli @@ -0,0 +1,141 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stdLabels.mli,v 1.13 2004-11-25 00:04:15 doligez Exp $ *) + +(** Standard labeled libraries. + + This meta-module provides labelized version of the {!Array}, + {!List} and {!String} modules. + + They only differ by their labels. Detailed interfaces can be found + in [arrayLabels.mli], [listLabels.mli] and [stringLabels.mli]. +*) + +module Array : + sig + external length : 'a array -> int = "%array_length" + external get : 'a array -> int -> 'a = "%array_safe_get" + external set : 'a array -> int -> 'a -> unit = "%array_safe_set" + external make : int -> 'a -> 'a array = "caml_make_vect" + external create : int -> 'a -> 'a array = "caml_make_vect" + val init : int -> f:(int -> 'a) -> 'a array + val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array + val create_matrix : dimx:int -> dimy:int -> 'a -> 'a array array + val append : 'a array -> 'a array -> 'a array + val concat : 'a array list -> 'a array + val sub : 'a array -> pos:int -> len:int -> 'a array + val copy : 'a array -> 'a array + val fill : 'a array -> pos:int -> len:int -> 'a -> unit + val blit : + src:'a array -> src_pos:int -> dst:'a array -> dst_pos:int -> len:int -> + unit + val to_list : 'a array -> 'a list + val of_list : 'a list -> 'a array + val iter : f:('a -> unit) -> 'a array -> unit + val map : f:('a -> 'b) -> 'a array -> 'b array + val iteri : f:(int -> 'a -> unit) -> 'a array -> unit + val mapi : f:(int -> 'a -> 'b) -> 'a array -> 'b array + val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b array -> 'a + val fold_right : f:('a -> 'b -> 'b) -> 'a array -> init:'b -> 'b + val sort : cmp:('a -> 'a -> int) -> 'a array -> unit + val stable_sort : cmp:('a -> 'a -> int) -> 'a array -> unit + val fast_sort : cmp:('a -> 'a -> int) -> 'a array -> unit + external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get" + external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set" + end + +module List : + sig + val length : 'a list -> int + val hd : 'a list -> 'a + val tl : 'a list -> 'a list + val nth : 'a list -> int -> 'a + val rev : 'a list -> 'a list + val append : 'a list -> 'a list -> 'a list + val rev_append : 'a list -> 'a list -> 'a list + val concat : 'a list list -> 'a list + val flatten : 'a list list -> 'a list + val iter : f:('a -> unit) -> 'a list -> unit + val map : f:('a -> 'b) -> 'a list -> 'b list + val rev_map : f:('a -> 'b) -> 'a list -> 'b list + val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b list -> 'a + val fold_right : f:('a -> 'b -> 'b) -> 'a list -> init:'b -> 'b + val iter2 : f:('a -> 'b -> unit) -> 'a list -> 'b list -> unit + val map2 : f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list + val rev_map2 : f:('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list + val fold_left2 : + f:('a -> 'b -> 'c -> 'a) -> init:'a -> 'b list -> 'c list -> 'a + val fold_right2 : + f:('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> init:'c -> 'c + val for_all : f:('a -> bool) -> 'a list -> bool + val exists : f:('a -> bool) -> 'a list -> bool + val for_all2 : f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool + val exists2 : f:('a -> 'b -> bool) -> 'a list -> 'b list -> bool + val mem : 'a -> set:'a list -> bool + val memq : 'a -> set:'a list -> bool + val find : f:('a -> bool) -> 'a list -> 'a + val filter : f:('a -> bool) -> 'a list -> 'a list + val find_all : f:('a -> bool) -> 'a list -> 'a list + val partition : f:('a -> bool) -> 'a list -> 'a list * 'a list + val assoc : 'a -> ('a * 'b) list -> 'b + val assq : 'a -> ('a * 'b) list -> 'b + val mem_assoc : 'a -> map:('a * 'b) list -> bool + val mem_assq : 'a -> map:('a * 'b) list -> bool + val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list + val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list + val split : ('a * 'b) list -> 'a list * 'b list + val combine : 'a list -> 'b list -> ('a * 'b) list + val sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list + val stable_sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list + val fast_sort : cmp:('a -> 'a -> int) -> 'a list -> 'a list + val merge : cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list + end + +module String : + sig + external length : string -> int = "%string_length" + external get : string -> int -> char = "%string_safe_get" + external set : string -> int -> char -> unit = "%string_safe_set" + external create : int -> string = "caml_create_string" + val make : int -> char -> string + val copy : string -> string + val sub : string -> pos:int -> len:int -> string + val fill : string -> pos:int -> len:int -> char -> unit + val blit : + src:string -> src_pos:int -> dst:string -> dst_pos:int -> len:int -> + unit + val concat : sep:string -> string list -> string + val iter : f:(char -> unit) -> string -> unit + val escaped : string -> string + val index : string -> char -> int + val rindex : string -> char -> int + val index_from : string -> int -> char -> int + val rindex_from : string -> int -> char -> int + val contains : string -> char -> bool + val contains_from : string -> int -> char -> bool + val rcontains_from : string -> int -> char -> bool + val uppercase : string -> string + val lowercase : string -> string + val capitalize : string -> string + val uncapitalize : string -> string + type t = string + val compare: t -> t -> int + external unsafe_get : string -> int -> char = "%string_unsafe_get" + external unsafe_set : string -> int -> char -> unit = "%string_unsafe_set" + external unsafe_blit : + src:string -> src_pos:int -> dst:string -> dst_pos:int -> len:int -> + unit = "caml_blit_string" "noalloc" + external unsafe_fill : string -> pos:int -> len:int -> char -> unit + = "caml_fill_string" "noalloc" + end diff --git a/stdlib/std_exit.ml b/stdlib/std_exit.ml new file mode 100644 index 0000000..2c66235 --- /dev/null +++ b/stdlib/std_exit.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: std_exit.ml,v 1.5 2001-12-07 13:40:59 xleroy Exp $ *) + +(* Ensure that [at_exit] functions are called at the end of every program *) + +let _ = do_at_exit() diff --git a/stdlib/stdlib.mllib b/stdlib/stdlib.mllib new file mode 100644 index 0000000..e4b57a1 --- /dev/null +++ b/stdlib/stdlib.mllib @@ -0,0 +1,48 @@ +# This file lists all standard library modules. +# It is used in particular to know what to expunge in toplevels. +# $Id: stdlib.mllib,v 1.2 2008-08-01 16:57:10 mauny Exp $ + +Pervasives +Arg +Array +ArrayLabels +Buffer +Callback +CamlinternalLazy +CamlinternalMod +CamlinternalOO +Char +Complex +Digest +Filename +Format +Gc +Genlex +Hashtbl +Int32 +Int64 +Lazy +Lexing +List +ListLabels +Map +Marshal +MoreLabels +Nativeint +Obj +Oo +Parsing +Printexc +Printf +Queue +Random +Scanf +Set +Sort +Stack +StdLabels +Stream +String +StringLabels +Sys +Weak diff --git a/stdlib/stream.ml b/stdlib/stream.ml new file mode 100644 index 0000000..2af3351 --- /dev/null +++ b/stdlib/stream.ml @@ -0,0 +1,200 @@ +(***********************************************************************) +(* *) +(* Ocaml *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stream.ml,v 1.14 2008-06-18 15:35:02 mauny Exp $ *) + +(* The fields of type t are not mutable to preserve polymorphism of + the empty stream. This is type safe because the empty stream is never + patched. *) + +type 'a t = { count : int; data : 'a data } +and 'a data = + Sempty + | Scons of 'a * 'a data + | Sapp of 'a data * 'a data + | Slazy of 'a data Lazy.t + | Sgen of 'a gen + | Sbuffio of buffio +and 'a gen = { mutable curr : 'a option option; func : int -> 'a option } +and buffio = + { ic : in_channel; buff : string; mutable len : int; mutable ind : int } +;; +exception Failure;; +exception Error of string;; + +external count : 'a t -> int = "%field0";; +external set_count : 'a t -> int -> unit = "%setfield0";; +let set_data (s : 'a t) (d : 'a data) = + Obj.set_field (Obj.repr s) 1 (Obj.repr d) +;; + +let fill_buff b = + b.len <- input b.ic b.buff 0 (String.length b.buff); b.ind <- 0 +;; + +let rec get_data count d = match d with + (* Returns either Sempty or Scons(a, _) even when d is a generator + or a buffer. In those cases, the item a is seen as extracted from + the generator/buffer. + The count parameter is used for calling `Sgen-functions'. *) + Sempty | Scons (_, _) -> d + | Sapp (d1, d2) -> + begin match get_data count d1 with + Scons (a, d11) -> Scons (a, Sapp (d11, d2)) + | Sempty -> get_data count d2 + | _ -> assert false + end + | Sgen {curr = Some None; func = _ } -> Sempty + | Sgen ({curr = Some(Some a); func = f} as g) -> + g.curr <- None; Scons(a, d) + | Sgen g -> + begin match g.func count with + None -> g.curr <- Some(None); Sempty + | Some a -> Scons(a, d) + (* Warning: anyone using g thinks that an item has been read *) + end + | Sbuffio b -> + if b.ind >= b.len then fill_buff b; + if b.len == 0 then Sempty else + let r = Obj.magic (String.unsafe_get b.buff b.ind) in + (* Warning: anyone using g thinks that an item has been read *) + b.ind <- succ b.ind; Scons(r, d) + | Slazy f -> get_data count (Lazy.force f) +;; + +let rec peek s = + (* consult the first item of s *) + match s.data with + Sempty -> None + | Scons (a, _) -> Some a + | Sapp (_, _) -> + begin match get_data s.count s.data with + Scons(a, _) as d -> set_data s d; Some a + | Sempty -> None + | _ -> assert false + end + | Slazy f -> set_data s (Lazy.force f); peek s + | Sgen {curr = Some a} -> a + | Sgen g -> let x = g.func s.count in g.curr <- Some x; x + | Sbuffio b -> + if b.ind >= b.len then fill_buff b; + if b.len == 0 then begin set_data s Sempty; None end + else Some (Obj.magic (String.unsafe_get b.buff b.ind)) +;; + +let rec junk s = + match s.data with + Scons (_, d) -> set_count s (succ s.count); set_data s d + | Sgen ({curr = Some _} as g) -> set_count s (succ s.count); g.curr <- None + | Sbuffio b -> set_count s (succ s.count); b.ind <- succ b.ind + | _ -> + match peek s with + None -> () + | Some _ -> junk s +;; + +let rec nget n s = + if n <= 0 then [], s.data, 0 + else + match peek s with + Some a -> + junk s; + let (al, d, k) = nget (pred n) s in a :: al, Scons (a, d), succ k + | None -> [], s.data, 0 +;; + +let npeek n s = + let (al, d, len) = nget n s in set_count s (s.count - len); set_data s d; al +;; + +let next s = + match peek s with + Some a -> junk s; a + | None -> raise Failure +;; + +let empty s = + match peek s with + Some _ -> raise Failure + | None -> () +;; + +let iter f strm = + let rec do_rec () = + match peek strm with + Some a -> junk strm; ignore(f a); do_rec () + | None -> () + in + do_rec () +;; + +(* Stream building functions *) + +let from f = {count = 0; data = Sgen {curr = None; func = f}};; + +let of_list l = + {count = 0; data = List.fold_right (fun x l -> Scons (x, l)) l Sempty} +;; + +let of_string s = + from (fun c -> if c < String.length s then Some s.[c] else None) +;; + +let of_channel ic = + {count = 0; + data = Sbuffio {ic = ic; buff = String.create 4096; len = 0; ind = 0}} +;; + +(* Stream expressions builders *) + +let iapp i s = {count = 0; data = Sapp (i.data, s.data)};; +let icons i s = {count = 0; data = Scons (i, s.data)};; +let ising i = {count = 0; data = Scons (i, Sempty)};; + +let lapp f s = + {count = 0; data = Slazy (lazy(Sapp ((f ()).data, s.data)))} +;; +let lcons f s = {count = 0; data = Slazy (lazy(Scons (f (), s.data)))};; +let lsing f = {count = 0; data = Slazy (lazy(Scons (f (), Sempty)))};; + +let sempty = {count = 0; data = Sempty};; +let slazy f = {count = 0; data = Slazy (lazy(f ()).data)};; + +(* For debugging use *) + +let rec dump f s = + print_string "{count = "; + print_int s.count; + print_string "; data = "; + dump_data f s.data; + print_string "}"; + print_newline () +and dump_data f = + function + Sempty -> print_string "Sempty" + | Scons (a, d) -> + print_string "Scons ("; + f a; + print_string ", "; + dump_data f d; + print_string ")" + | Sapp (d1, d2) -> + print_string "Sapp ("; + dump_data f d1; + print_string ", "; + dump_data f d2; + print_string ")" + | Slazy _ -> print_string "Slazy" + | Sgen _ -> print_string "Sgen" + | Sbuffio b -> print_string "Sbuffio" +;; diff --git a/stdlib/stream.mli b/stdlib/stream.mli new file mode 100644 index 0000000..14c7e51 --- /dev/null +++ b/stdlib/stream.mli @@ -0,0 +1,106 @@ +(***********************************************************************) +(* *) +(* Ocaml *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stream.mli,v 1.25 2005-10-25 18:34:07 doligez Exp $ *) + +(** Streams and parsers. *) + +type 'a t +(** The type of streams holding values of type ['a]. *) + +exception Failure +(** Raised by parsers when none of the first components of the stream + patterns is accepted. *) + +exception Error of string +(** Raised by parsers when the first component of a stream pattern is + accepted, but one of the following components is rejected. *) + + +(** {6 Stream builders} + + Warning: these functions create streams with fast access; it is illegal + to mix them with streams built with [[< >]]; would raise [Failure] + when accessing such mixed streams. +*) + +val from : (int -> 'a option) -> 'a t +(** [Stream.from f] returns a stream built from the function [f]. + To create a new stream element, the function [f] is called with + the current stream count. The user function [f] must return either + [Some <value>] for a value or [None] to specify the end of the + stream. *) + +val of_list : 'a list -> 'a t +(** Return the stream holding the elements of the list in the same + order. *) + +val of_string : string -> char t +(** Return the stream of the characters of the string parameter. *) + +val of_channel : in_channel -> char t +(** Return the stream of the characters read from the input channel. *) + + +(** {6 Stream iterator} *) + +val iter : ('a -> unit) -> 'a t -> unit +(** [Stream.iter f s] scans the whole stream s, applying function [f] + in turn to each stream element encountered. *) + + +(** {6 Predefined parsers} *) + +val next : 'a t -> 'a +(** Return the first element of the stream and remove it from the + stream. Raise Stream.Failure if the stream is empty. *) + +val empty : 'a t -> unit +(** Return [()] if the stream is empty, else raise [Stream.Failure]. *) + + +(** {6 Useful functions} *) + +val peek : 'a t -> 'a option +(** Return [Some] of "the first element" of the stream, or [None] if + the stream is empty. *) + +val junk : 'a t -> unit +(** Remove the first element of the stream, possibly unfreezing + it before. *) + +val count : 'a t -> int +(** Return the current count of the stream elements, i.e. the number + of the stream elements discarded. *) + +val npeek : int -> 'a t -> 'a list +(** [npeek n] returns the list of the [n] first elements of + the stream, or all its remaining elements if less than [n] + elements are available. *) + +(**/**) + +(** {6 For system use only, not for the casual user} *) + +val iapp : 'a t -> 'a t -> 'a t +val icons : 'a -> 'a t -> 'a t +val ising : 'a -> 'a t + +val lapp : (unit -> 'a t) -> 'a t -> 'a t +val lcons : (unit -> 'a) -> 'a t -> 'a t +val lsing : (unit -> 'a) -> 'a t + +val sempty : 'a t +val slazy : (unit -> 'a t) -> 'a t + +val dump : ('a -> unit) -> 'a t -> unit diff --git a/stdlib/string.ml b/stdlib/string.ml new file mode 100644 index 0000000..f5bc936 --- /dev/null +++ b/stdlib/string.ml @@ -0,0 +1,183 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: string.ml,v 1.30 2008-12-03 18:09:09 doligez Exp $ *) + +(* String operations *) + +external length : string -> int = "%string_length" +external get : string -> int -> char = "%string_safe_get" +external set : string -> int -> char -> unit = "%string_safe_set" +external create : int -> string = "caml_create_string" +external unsafe_get : string -> int -> char = "%string_unsafe_get" +external unsafe_set : string -> int -> char -> unit = "%string_unsafe_set" +external unsafe_blit : string -> int -> string -> int -> int -> unit + = "caml_blit_string" "noalloc" +external unsafe_fill : string -> int -> int -> char -> unit + = "caml_fill_string" "noalloc" + +let make n c = + let s = create n in + unsafe_fill s 0 n c; + s + +let copy s = + let len = length s in + let r = create len in + unsafe_blit s 0 r 0 len; + r + +let sub s ofs len = + if ofs < 0 || len < 0 || ofs > length s - len + then invalid_arg "String.sub" + else begin + let r = create len in + unsafe_blit s ofs r 0 len; + r + end + +let fill s ofs len c = + if ofs < 0 || len < 0 || ofs > length s - len + then invalid_arg "String.fill" + else unsafe_fill s ofs len c + +let blit s1 ofs1 s2 ofs2 len = + if len < 0 || ofs1 < 0 || ofs1 > length s1 - len + || ofs2 < 0 || ofs2 > length s2 - len + then invalid_arg "String.blit" + else unsafe_blit s1 ofs1 s2 ofs2 len + +let iter f a = + for i = 0 to length a - 1 do f(unsafe_get a i) done + +let concat sep l = + match l with + [] -> "" + | hd :: tl -> + let num = ref 0 and len = ref 0 in + List.iter (fun s -> incr num; len := !len + length s) l; + let r = create (!len + length sep * (!num - 1)) in + unsafe_blit hd 0 r 0 (length hd); + let pos = ref(length hd) in + List.iter + (fun s -> + unsafe_blit sep 0 r !pos (length sep); + pos := !pos + length sep; + unsafe_blit s 0 r !pos (length s); + pos := !pos + length s) + tl; + r + +external is_printable: char -> bool = "caml_is_printable" +external char_code: char -> int = "%identity" +external char_chr: int -> char = "%identity" + +let escaped s = + let n = ref 0 in + for i = 0 to length s - 1 do + n := !n + + (match unsafe_get s i with + | '"' | '\\' | '\n' | '\t' | '\r' | '\b' -> 2 + | c -> if is_printable c then 1 else 4) + done; + if !n = length s then s else begin + let s' = create !n in + n := 0; + for i = 0 to length s - 1 do + begin + match unsafe_get s i with + | ('"' | '\\') as c -> + unsafe_set s' !n '\\'; incr n; unsafe_set s' !n c + | '\n' -> + unsafe_set s' !n '\\'; incr n; unsafe_set s' !n 'n' + | '\t' -> + unsafe_set s' !n '\\'; incr n; unsafe_set s' !n 't' + | '\r' -> + unsafe_set s' !n '\\'; incr n; unsafe_set s' !n 'r' + | '\b' -> + unsafe_set s' !n '\\'; incr n; unsafe_set s' !n 'b' + | c -> + if is_printable c then + unsafe_set s' !n c + else begin + let a = char_code c in + unsafe_set s' !n '\\'; + incr n; + unsafe_set s' !n (char_chr (48 + a / 100)); + incr n; + unsafe_set s' !n (char_chr (48 + (a / 10) mod 10)); + incr n; + unsafe_set s' !n (char_chr (48 + a mod 10)) + end + end; + incr n + done; + s' + end + +let map f s = + let l = length s in + if l = 0 then s else begin + let r = create l in + for i = 0 to l - 1 do unsafe_set r i (f(unsafe_get s i)) done; + r + end + +let uppercase s = map Char.uppercase s +let lowercase s = map Char.lowercase s + +let apply1 f s = + if length s = 0 then s else begin + let r = copy s in + unsafe_set r 0 (f(unsafe_get s 0)); + r + end + +let capitalize s = apply1 Char.uppercase s +let uncapitalize s = apply1 Char.lowercase s + +let rec index_rec s lim i c = + if i >= lim then raise Not_found else + if unsafe_get s i = c then i else index_rec s lim (i + 1) c;; + +let index s c = index_rec s (length s) 0 c;; + +let index_from s i c = + let l = length s in + if i < 0 || i > l then invalid_arg "String.index_from" else + index_rec s l i c;; + +let rec rindex_rec s i c = + if i < 0 then raise Not_found else + if unsafe_get s i = c then i else rindex_rec s (i - 1) c;; + +let rindex s c = rindex_rec s (length s - 1) c;; + +let rindex_from s i c = + if i < -1 || i >= length s then invalid_arg "String.rindex_from" else + rindex_rec s i c;; + +let contains_from s i c = + let l = length s in + if i < 0 || i > l then invalid_arg "String.contains_from" else + try ignore (index_rec s l i c); true with Not_found -> false;; + +let contains s c = contains_from s 0 c;; + +let rcontains_from s i c = + if i < 0 || i >= length s then invalid_arg "String.rcontains_from" else + try ignore (rindex_rec s i c); true with Not_found -> false;; + +type t = string + +let compare = Pervasives.compare diff --git a/stdlib/string.mli b/stdlib/string.mli new file mode 100644 index 0000000..54ee81b --- /dev/null +++ b/stdlib/string.mli @@ -0,0 +1,184 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: string.mli,v 1.39 2008-12-03 18:09:09 doligez Exp $ *) + +(** String operations. + Given a string [s] of length [l], we call character number in [s] + the index of a character in [s]. Indexes start at [0], and we will + call a character number valid in [s] if it falls within the range + [[0...l-1]]. A position is the point between two characters or at + the beginning or end of the string. We call a position valid + in [s] if it falls within the range [[0...l]]. Note that character + number [n] is between positions [n] and [n+1]. + + Two parameters [start] and [len] are said to designate a valid + substring of [s] if [len >= 0] and [start] and [start+len] are + valid positions in [s]. + *) + +external length : string -> int = "%string_length" +(** Return the length (number of characters) of the given string. *) + +external get : string -> int -> char = "%string_safe_get" +(** [String.get s n] returns character number [n] in string [s]. + You can also write [s.[n]] instead of [String.get s n]. + + Raise [Invalid_argument] if [n] not a valid character number in [s]. *) + + +external set : string -> int -> char -> unit = "%string_safe_set" +(** [String.set s n c] modifies string [s] in place, + replacing the character number [n] by [c]. + You can also write [s.[n] <- c] instead of [String.set s n c]. + + Raise [Invalid_argument] if [n] is not a valid character number in [s]. *) + +external create : int -> string = "caml_create_string" +(** [String.create n] returns a fresh string of length [n]. + The string initially contains arbitrary characters. + + Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. *) + +val make : int -> char -> string +(** [String.make n c] returns a fresh string of length [n], + filled with the character [c]. + + Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}.*) + +val copy : string -> string +(** Return a copy of the given string. *) + +val sub : string -> int -> int -> string +(** [String.sub s start len] returns a fresh string of length [len], + containing the substring of [s] that starts at position [start] and + has length [len]. + + Raise [Invalid_argument] if [start] and [len] do not + designate a valid substring of [s]. *) + +val fill : string -> int -> int -> char -> unit +(** [String.fill s start len c] modifies string [s] in place, + replacing [len] characters by [c], starting at [start]. + + Raise [Invalid_argument] if [start] and [len] do not + designate a valid substring of [s]. *) + +val blit : string -> int -> string -> int -> int -> unit +(** [String.blit src srcoff dst dstoff len] copies [len] characters + from string [src], starting at character number [srcoff], to + string [dst], starting at character number [dstoff]. It works + correctly even if [src] and [dst] are the same string, + and the source and destination intervals overlap. + + Raise [Invalid_argument] if [srcoff] and [len] do not + designate a valid substring of [src], or if [dstoff] and [len] + do not designate a valid substring of [dst]. *) + +val concat : string -> string list -> string +(** [String.concat sep sl] concatenates the list of strings [sl], + inserting the separator string [sep] between each. *) + +val iter : (char -> unit) -> string -> unit +(** [String.iter f s] applies function [f] in turn to all + the characters of [s]. It is equivalent to + [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. *) + +val escaped : string -> string +(** Return a copy of the argument, with special characters + represented by escape sequences, following the lexical + conventions of Objective Caml. If there is no special + character in the argument, return the original string itself, + not a copy. *) + +val index : string -> char -> int +(** [String.index s c] returns the character number of the first + occurrence of character [c] in string [s]. + + Raise [Not_found] if [c] does not occur in [s]. *) + +val rindex : string -> char -> int +(** [String.rindex s c] returns the character number of the last + occurrence of character [c] in string [s]. + + Raise [Not_found] if [c] does not occur in [s]. *) + +val index_from : string -> int -> char -> int +(** [String.index_from s i c] returns the character number of the + first occurrence of character [c] in string [s] after position [i]. + [String.index s c] is equivalent to [String.index_from s 0 c]. + + Raise [Invalid_argument] if [i] is not a valid position in [s]. + Raise [Not_found] if [c] does not occur in [s] after position [i]. *) + +val rindex_from : string -> int -> char -> int +(** [String.rindex_from s i c] returns the character number of the + last occurrence of character [c] in string [s] before position [i+1]. + [String.rindex s c] is equivalent to + [String.rindex_from s (String.length s - 1) c]. + + Raise [Invalid_argument] if [i+1] is not a valid position in [s]. + Raise [Not_found] if [c] does not occur in [s] before position [i+1]. *) + +val contains : string -> char -> bool +(** [String.contains s c] tests if character [c] + appears in the string [s]. *) + +val contains_from : string -> int -> char -> bool +(** [String.contains_from s start c] tests if character [c] + appears in [s] after position [start]. + [String.contains s c] is equivalent to + [String.contains_from s 0 c]. + + Raise [Invalid_argument] if [start] is not a valid position in [s]. *) + +val rcontains_from : string -> int -> char -> bool +(** [String.rcontains_from s stop c] tests if character [c] + appears in [s] before position [stop+1]. + + Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid + position in [s]. *) + +val uppercase : string -> string +(** Return a copy of the argument, with all lowercase letters + translated to uppercase, including accented letters of the ISO + Latin-1 (8859-1) character set. *) + +val lowercase : string -> string +(** Return a copy of the argument, with all uppercase letters + translated to lowercase, including accented letters of the ISO + Latin-1 (8859-1) character set. *) + +val capitalize : string -> string +(** Return a copy of the argument, with the first character set to uppercase. *) + +val uncapitalize : string -> string +(** Return a copy of the argument, with the first character set to lowercase. *) + +type t = string +(** An alias for the type of strings. *) + +val compare: t -> t -> int +(** The comparison function for strings, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [String] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +external unsafe_get : string -> int -> char = "%string_unsafe_get" +external unsafe_set : string -> int -> char -> unit = "%string_unsafe_set" +external unsafe_blit : + string -> int -> string -> int -> int -> unit = "caml_blit_string" "noalloc" +external unsafe_fill : + string -> int -> int -> char -> unit = "caml_fill_string" "noalloc" diff --git a/stdlib/stringLabels.ml b/stdlib/stringLabels.ml new file mode 100644 index 0000000..d72829a --- /dev/null +++ b/stdlib/stringLabels.ml @@ -0,0 +1,18 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stringLabels.ml,v 1.4 2004-01-03 22:08:38 doligez Exp $ *) + +(* Module [StringLabels]: labelled String module *) + +include String diff --git a/stdlib/stringLabels.mli b/stdlib/stringLabels.mli new file mode 100644 index 0000000..f9d5e2e --- /dev/null +++ b/stdlib/stringLabels.mli @@ -0,0 +1,164 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: stringLabels.mli,v 1.11 2007-01-22 08:06:09 garrigue Exp $ *) + +(** String operations. *) + +external length : string -> int = "%string_length" +(** Return the length (number of characters) of the given string. *) + +external get : string -> int -> char = "%string_safe_get" +(** [String.get s n] returns character number [n] in string [s]. + The first character is character number 0. + The last character is character number [String.length s - 1]. + You can also write [s.[n]] instead of [String.get s n]. + + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [(String.length s - 1)]. *) + + +external set : string -> int -> char -> unit = "%string_safe_set" +(** [String.set s n c] modifies string [s] in place, + replacing the character number [n] by [c]. + You can also write [s.[n] <- c] instead of [String.set s n c]. + Raise [Invalid_argument "index out of bounds"] + if [n] is outside the range 0 to [(String.length s - 1)]. *) + +external create : int -> string = "caml_create_string" +(** [String.create n] returns a fresh string of length [n]. + The string initially contains arbitrary characters. + Raise [Invalid_argument] if [n < 0] or [n > Sys.max_string_length]. +*) + +val make : int -> char -> string +(** [String.make n c] returns a fresh string of length [n], + filled with the character [c]. + Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}.*) + +val copy : string -> string +(** Return a copy of the given string. *) + +val sub : string -> pos:int -> len:int -> string +(** [String.sub s start len] returns a fresh string of length [len], + containing the characters number [start] to [start + len - 1] + of string [s]. + Raise [Invalid_argument] if [start] and [len] do not + designate a valid substring of [s]; that is, if [start < 0], + or [len < 0], or [start + len > ]{!StringLabels.length}[ s]. *) + +val fill : string -> pos:int -> len:int -> char -> unit +(** [String.fill s start len c] modifies string [s] in place, + replacing the characters number [start] to [start + len - 1] + by [c]. + Raise [Invalid_argument] if [start] and [len] do not + designate a valid substring of [s]. *) + +val blit : + src:string -> src_pos:int -> dst:string -> dst_pos:int -> len:int -> unit +(** [String.blit src srcoff dst dstoff len] copies [len] characters + from string [src], starting at character number [srcoff], to + string [dst], starting at character number [dstoff]. It works + correctly even if [src] and [dst] are the same string, + and the source and destination chunks overlap. + Raise [Invalid_argument] if [srcoff] and [len] do not + designate a valid substring of [src], or if [dstoff] and [len] + do not designate a valid substring of [dst]. *) + +val concat : sep:string -> string list -> string +(** [String.concat sep sl] concatenates the list of strings [sl], + inserting the separator string [sep] between each. *) + +val iter : f:(char -> unit) -> string -> unit +(** [String.iter f s] applies function [f] in turn to all + the characters of [s]. It is equivalent to + [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. *) + +val escaped : string -> string +(** Return a copy of the argument, with special characters + represented by escape sequences, following the lexical + conventions of Objective Caml. If there is no special + character in the argument, return the original string itself, + not a copy. *) + +val index : string -> char -> int +(** [String.index s c] returns the position of the leftmost + occurrence of character [c] in string [s]. + Raise [Not_found] if [c] does not occur in [s]. *) + +val rindex : string -> char -> int +(** [String.rindex s c] returns the position of the rightmost + occurrence of character [c] in string [s]. + Raise [Not_found] if [c] does not occur in [s]. *) + +val index_from : string -> int -> char -> int +(** Same as {!StringLabels.index}, but start + searching at the character position given as second argument. + [String.index s c] is equivalent to [String.index_from s 0 c].*) + +val rindex_from : string -> int -> char -> int +(** Same as {!StringLabels.rindex}, but start + searching at the character position given as second argument. + [String.rindex s c] is equivalent to + [String.rindex_from s (String.length s - 1) c]. *) + +val contains : string -> char -> bool +(** [String.contains s c] tests if character [c] + appears in the string [s]. *) + +val contains_from : string -> int -> char -> bool +(** [String.contains_from s start c] tests if character [c] + appears in the substring of [s] starting from [start] to the end + of [s]. + Raise [Invalid_argument] if [start] is not a valid index of [s]. *) + +val rcontains_from : string -> int -> char -> bool +(** [String.rcontains_from s stop c] tests if character [c] + appears in the substring of [s] starting from the beginning + of [s] to index [stop]. + Raise [Invalid_argument] if [stop] is not a valid index of [s]. *) + +val uppercase : string -> string +(** Return a copy of the argument, with all lowercase letters + translated to uppercase, including accented letters of the ISO + Latin-1 (8859-1) character set. *) + +val lowercase : string -> string +(** Return a copy of the argument, with all uppercase letters + translated to lowercase, including accented letters of the ISO + Latin-1 (8859-1) character set. *) + +val capitalize : string -> string +(** Return a copy of the argument, with the first character set to uppercase. *) + +val uncapitalize : string -> string +(** Return a copy of the argument, with the first character set to lowercase. *) + +type t = string +(** An alias for the type of strings. *) + +val compare: t -> t -> int +(** The comparison function for strings, with the same specification as + {!Pervasives.compare}. Along with the type [t], this function [compare] + allows the module [String] to be passed as argument to the functors + {!Set.Make} and {!Map.Make}. *) + +(**/**) + +external unsafe_get : string -> int -> char = "%string_unsafe_get" +external unsafe_set : string -> int -> char -> unit = "%string_unsafe_set" +external unsafe_blit : + src:string -> src_pos:int -> dst:string -> dst_pos:int -> len:int -> + unit = "caml_blit_string" "noalloc" +external unsafe_fill : + string -> pos:int -> len:int -> char -> unit = "caml_fill_string" "noalloc" diff --git a/stdlib/sys.mli b/stdlib/sys.mli new file mode 100644 index 0000000..d770f9e --- /dev/null +++ b/stdlib/sys.mli @@ -0,0 +1,204 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: sys.mli,v 1.49 2007-02-26 14:21:57 xleroy Exp $ *) + +(** System interface. *) + +val argv : string array +(** The command line arguments given to the process. + The first element is the command name used to invoke the program. + The following elements are the command-line arguments + given to the program. *) + +val executable_name : string +(** The name of the file containing the executable currently running. *) + +external file_exists : string -> bool = "caml_sys_file_exists" +(** Test if a file with the given name exists. *) + +external is_directory : string -> bool = "caml_sys_is_directory" +(** Returns [true] if the given name refers to a directory, + [false] if it refers to another kind of file. + Raise [Sys_error] if no file exists with the given name. *) + +external remove : string -> unit = "caml_sys_remove" +(** Remove the given file name from the file system. *) + +external rename : string -> string -> unit = "caml_sys_rename" +(** Rename a file. The first argument is the old name and the + second is the new name. If there is already another file + under the new name, [rename] may replace it, or raise an + exception, depending on your operating system. *) + +external getenv : string -> string = "caml_sys_getenv" +(** Return the value associated to a variable in the process + environment. Raise [Not_found] if the variable is unbound. *) + +external command : string -> int = "caml_sys_system_command" +(** Execute the given shell command and return its exit code. *) + +external time : unit -> float = "caml_sys_time" +(** Return the processor time, in seconds, used by the program + since the beginning of execution. *) + +external chdir : string -> unit = "caml_sys_chdir" +(** Change the current working directory of the process. *) + +external getcwd : unit -> string = "caml_sys_getcwd" +(** Return the current working directory of the process. *) + +external readdir : string -> string array = "caml_sys_read_directory" +(** Return the names of all files present in the given directory. + Names denoting the current directory and the parent directory + (["."] and [".."] in Unix) are not returned. Each string in the + result is a file name rather than a complete path. There is no + guarantee that the name strings in the resulting array will appear + in any specific order; they are not, in particular, guaranteed to + appear in alphabetical order. *) + +val interactive : bool ref +(** This reference is initially set to [false] in standalone + programs and to [true] if the code is being executed under + the interactive toplevel system [ocaml]. *) + +val os_type : string +(** Operating system currently executing the Caml program. One of +- ["Unix"] (for all Unix versions, including Linux and Mac OS X), +- ["Win32"] (for MS-Windows, OCaml compiled with MSVC++ or Mingw), +- ["Cygwin"] (for MS-Windows, OCaml compiled with Cygwin). *) + +val word_size : int +(** Size of one word on the machine currently executing the Caml + program, in bits: 32 or 64. *) + +val max_string_length : int +(** Maximum length of a string. *) + +val max_array_length : int +(** Maximum length of a normal array. The maximum length of a float + array is [max_array_length/2] on 32-bit machines and + [max_array_length] on 64-bit machines. *) + + +(** {6 Signal handling} *) + + +type signal_behavior = + Signal_default + | Signal_ignore + | Signal_handle of (int -> unit) +(** What to do when receiving a signal: + - [Signal_default]: take the default behavior + (usually: abort the program) + - [Signal_ignore]: ignore the signal + - [Signal_handle f]: call function [f], giving it the signal + number as argument. *) + +external signal : + int -> signal_behavior -> signal_behavior = "caml_install_signal_handler" +(** Set the behavior of the system on receipt of a given signal. The + first argument is the signal number. Return the behavior + previously associated with the signal. If the signal number is + invalid (or not available on your system), an [Invalid_argument] + exception is raised. *) + +val set_signal : int -> signal_behavior -> unit +(** Same as {!Sys.signal} but return value is ignored. *) + + +(** {7 Signal numbers for the standard POSIX signals.} *) + +val sigabrt : int +(** Abnormal termination *) + +val sigalrm : int +(** Timeout *) + +val sigfpe : int +(** Arithmetic exception *) + +val sighup : int +(** Hangup on controlling terminal *) + +val sigill : int +(** Invalid hardware instruction *) + +val sigint : int +(** Interactive interrupt (ctrl-C) *) + +val sigkill : int +(** Termination (cannot be ignored) *) + +val sigpipe : int +(** Broken pipe *) + +val sigquit : int +(** Interactive termination *) + +val sigsegv : int +(** Invalid memory reference *) + +val sigterm : int +(** Termination *) + +val sigusr1 : int +(** Application-defined signal 1 *) + +val sigusr2 : int +(** Application-defined signal 2 *) + +val sigchld : int +(** Child process terminated *) + +val sigcont : int +(** Continue *) + +val sigstop : int +(** Stop *) + +val sigtstp : int +(** Interactive stop *) + +val sigttin : int +(** Terminal read from background process *) + +val sigttou : int +(** Terminal write from background process *) + +val sigvtalrm : int +(** Timeout in virtual time *) + +val sigprof : int +(** Profiling interrupt *) + + +exception Break +(** Exception raised on interactive interrupt if {!Sys.catch_break} + is on. *) + + +val catch_break : bool -> unit +(** [catch_break] governs whether interactive interrupt (ctrl-C) + terminates the program or raises the [Break] exception. + Call [catch_break true] to enable raising [Break], + and [catch_break false] to let the system + terminate the program on user interrupt. *) + + +val ocaml_version : string;; +(** [ocaml_version] is the version of Objective Caml. + It is a string of the form ["major.minor[.patchlevel][+additional-info]"], + where [major], [minor], and [patchlevel] are integers, and + [additional-info] is an arbitrary string. The [[.patchlevel]] and + [[+additional-info]] parts may be absent. *) diff --git a/stdlib/sys.mlp b/stdlib/sys.mlp new file mode 100644 index 0000000..07f11fb --- /dev/null +++ b/stdlib/sys.mlp @@ -0,0 +1,86 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: sys.mlp,v 1.2 2007-02-26 14:21:57 xleroy Exp $ *) + +(* WARNING: sys.ml is generated from sys.mlp. DO NOT EDIT sys.ml or + your changes will be lost. +*) + +(* System interface *) + +external get_config: unit -> string * int = "caml_sys_get_config" +external get_argv: unit -> string * string array = "caml_sys_get_argv" + +let (executable_name, argv) = get_argv() +let (os_type, word_size) = get_config() +let max_array_length = (1 lsl (word_size - 10)) - 1;; +let max_string_length = word_size / 8 * max_array_length - 1;; + +external file_exists: string -> bool = "caml_sys_file_exists" +external is_directory : string -> bool = "caml_sys_is_directory" +external remove: string -> unit = "caml_sys_remove" +external rename : string -> string -> unit = "caml_sys_rename" +external getenv: string -> string = "caml_sys_getenv" +external command: string -> int = "caml_sys_system_command" +external time: unit -> float = "caml_sys_time" +external chdir: string -> unit = "caml_sys_chdir" +external getcwd: unit -> string = "caml_sys_getcwd" +external readdir : string -> string array = "caml_sys_read_directory" + +let interactive = ref false + +type signal_behavior = + Signal_default + | Signal_ignore + | Signal_handle of (int -> unit) + +external signal : int -> signal_behavior -> signal_behavior + = "caml_install_signal_handler" + +let set_signal sig_num sig_beh = ignore(signal sig_num sig_beh) + +let sigabrt = -1 +let sigalrm = -2 +let sigfpe = -3 +let sighup = -4 +let sigill = -5 +let sigint = -6 +let sigkill = -7 +let sigpipe = -8 +let sigquit = -9 +let sigsegv = -10 +let sigterm = -11 +let sigusr1 = -12 +let sigusr2 = -13 +let sigchld = -14 +let sigcont = -15 +let sigstop = -16 +let sigtstp = -17 +let sigttin = -18 +let sigttou = -19 +let sigvtalrm = -20 +let sigprof = -21 + +exception Break + +let catch_break on = + if on then + set_signal sigint (Signal_handle(fun _ -> raise Break)) + else + set_signal sigint Signal_default + + +(* The version string is found in file ../VERSION *) + +let ocaml_version = "%%VERSION%%";; diff --git a/stdlib/weak.ml b/stdlib/weak.ml new file mode 100644 index 0000000..d658108 --- /dev/null +++ b/stdlib/weak.ml @@ -0,0 +1,307 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: weak.ml,v 1.17 2008-02-29 14:21:22 doligez Exp $ *) + +(** Weak array operations *) + +type 'a t;; + +external create: int -> 'a t = "caml_weak_create";; + +let length x = Obj.size(Obj.repr x) - 1;; + +external set : 'a t -> int -> 'a option -> unit = "caml_weak_set";; +external get: 'a t -> int -> 'a option = "caml_weak_get";; +external get_copy: 'a t -> int -> 'a option = "caml_weak_get_copy";; +external check: 'a t -> int -> bool = "caml_weak_check";; +external blit: 'a t -> int -> 'a t -> int -> int -> unit = "caml_weak_blit";; +(* blit: src srcoff dst dstoff len *) + +let fill ar ofs len x = + if ofs < 0 || len < 0 || ofs + len > length ar + then raise (Invalid_argument "Weak.fill") + else begin + for i = ofs to (ofs + len - 1) do + set ar i x + done + end +;; + +(** Weak hash tables *) + +module type S = sig + type data + type t + val create : int -> t + val clear : t -> unit + val merge : t -> data -> data + val add : t -> data -> unit + val remove : t -> data -> unit + val find : t -> data -> data + val find_all : t -> data -> data list + val mem : t -> data -> bool + val iter : (data -> unit) -> t -> unit + val fold : (data -> 'a -> 'a) -> t -> 'a -> 'a + val count : t -> int + val stats : t -> int * int * int * int * int * int +end;; + +module Make (H : Hashtbl.HashedType) : (S with type data = H.t) = struct + + type 'a weak_t = 'a t;; + let weak_create = create;; + let emptybucket = weak_create 0;; + + type data = H.t;; + + type t = { + mutable table : data weak_t array; + mutable hashes : int array array; + mutable limit : int; (* bucket size limit *) + mutable oversize : int; (* number of oversize buckets *) + mutable rover : int; (* for internal bookkeeping *) + };; + + let get_index t h = (h land max_int) mod (Array.length t.table);; + + let limit = 7;; + let over_limit = 2;; + + let create sz = + let sz = if sz < 7 then 7 else sz in + let sz = if sz > Sys.max_array_length then Sys.max_array_length else sz in + { + table = Array.create sz emptybucket; + hashes = Array.create sz [| |]; + limit = limit; + oversize = 0; + rover = 0; + };; + + let clear t = + for i = 0 to Array.length t.table - 1 do + t.table.(i) <- emptybucket; + t.hashes.(i) <- [| |]; + done; + t.limit <- limit; + t.oversize <- 0; + ;; + + let fold f t init = + let rec fold_bucket i b accu = + if i >= length b then accu else + match get b i with + | Some v -> fold_bucket (i+1) b (f v accu) + | None -> fold_bucket (i+1) b accu + in + Array.fold_right (fold_bucket 0) t.table init + ;; + + let iter f t = + let rec iter_bucket i b = + if i >= length b then () else + match get b i with + | Some v -> f v; iter_bucket (i+1) b + | None -> iter_bucket (i+1) b + in + Array.iter (iter_bucket 0) t.table + ;; + + let iter_weak f t = + let rec iter_bucket i j b = + if i >= length b then () else + match check b i with + | true -> f b t.hashes.(j) i; iter_bucket (i+1) j b + | false -> iter_bucket (i+1) j b + in + Array.iteri (iter_bucket 0) t.table + ;; + + let rec count_bucket i b accu = + if i >= length b then accu else + count_bucket (i+1) b (accu + (if check b i then 1 else 0)) + ;; + + let count t = + Array.fold_right (count_bucket 0) t.table 0 + ;; + + let next_sz n = min (3 * n / 2 + 3) Sys.max_array_length;; + let prev_sz n = ((n - 3) * 2 + 2) / 3;; + + let test_shrink_bucket t = + let bucket = t.table.(t.rover) in + let hbucket = t.hashes.(t.rover) in + let len = length bucket in + let prev_len = prev_sz len in + let live = count_bucket 0 bucket 0 in + if live <= prev_len then begin + let rec loop i j = + if j >= prev_len then begin + if check bucket i then loop (i + 1) j + else if check bucket j then begin + blit bucket j bucket i 1; + hbucket.(i) <- hbucket.(j); + loop (i + 1) (j - 1); + end else loop i (j - 1); + end; + in + loop 0 (length bucket - 1); + if prev_len = 0 then begin + t.table.(t.rover) <- emptybucket; + t.hashes.(t.rover) <- [| |]; + end else begin + Obj.truncate (Obj.repr bucket) (prev_len + 1); + Obj.truncate (Obj.repr hbucket) prev_len; + end; + if len > t.limit && prev_len <= t.limit then t.oversize <- t.oversize - 1; + end; + t.rover <- (t.rover + 1) mod (Array.length t.table); + ;; + + let rec resize t = + let oldlen = Array.length t.table in + let newlen = next_sz oldlen in + if newlen > oldlen then begin + let newt = create newlen in + let add_weak ob oh oi = + let setter nb ni _ = blit ob oi nb ni 1 in + let h = oh.(oi) in + add_aux newt setter None h (get_index newt h); + in + iter_weak add_weak t; + t.table <- newt.table; + t.hashes <- newt.hashes; + t.limit <- newt.limit; + t.oversize <- newt.oversize; + t.rover <- t.rover mod Array.length newt.table; + end else begin + t.limit <- max_int; (* maximum size already reached *) + t.oversize <- 0; + end + + and add_aux t setter d h index = + let bucket = t.table.(index) in + let hashes = t.hashes.(index) in + let sz = length bucket in + let rec loop i = + if i >= sz then begin + let newsz = min (3 * sz / 2 + 3) (Sys.max_array_length - 1) in + if newsz <= sz then failwith "Weak.Make: hash bucket cannot grow more"; + let newbucket = weak_create newsz in + let newhashes = Array.make newsz 0 in + blit bucket 0 newbucket 0 sz; + Array.blit hashes 0 newhashes 0 sz; + setter newbucket sz d; + newhashes.(sz) <- h; + t.table.(index) <- newbucket; + t.hashes.(index) <- newhashes; + if sz <= t.limit && newsz > t.limit then begin + t.oversize <- t.oversize + 1; + for i = 0 to over_limit do test_shrink_bucket t done; + end; + if t.oversize > Array.length t.table / over_limit then resize t; + end else if check bucket i then begin + loop (i + 1) + end else begin + setter bucket i d; + hashes.(i) <- h; + end; + in + loop 0; + ;; + + let add t d = + let h = H.hash d in + add_aux t set (Some d) h (get_index t h); + ;; + + let find_or t d ifnotfound = + let h = H.hash d in + let index = get_index t h in + let bucket = t.table.(index) in + let hashes = t.hashes.(index) in + let sz = length bucket in + let rec loop i = + if i >= sz then ifnotfound h index + else if h = hashes.(i) then begin + match get_copy bucket i with + | Some v when H.equal v d + -> begin match get bucket i with + | Some v -> v + | None -> loop (i + 1) + end + | _ -> loop (i + 1) + end else loop (i + 1) + in + loop 0 + ;; + + let merge t d = + find_or t d (fun h index -> add_aux t set (Some d) h index; d) + ;; + + let find t d = find_or t d (fun h index -> raise Not_found);; + + let find_shadow t d iffound ifnotfound = + let h = H.hash d in + let index = get_index t h in + let bucket = t.table.(index) in + let hashes = t.hashes.(index) in + let sz = length bucket in + let rec loop i = + if i >= sz then ifnotfound + else if h = hashes.(i) then begin + match get_copy bucket i with + | Some v when H.equal v d -> iffound bucket i + | _ -> loop (i + 1) + end else loop (i + 1) + in + loop 0 + ;; + + let remove t d = find_shadow t d (fun w i -> set w i None) ();; + + let mem t d = find_shadow t d (fun w i -> true) false;; + + let find_all t d = + let h = H.hash d in + let index = get_index t h in + let bucket = t.table.(index) in + let hashes = t.hashes.(index) in + let sz = length bucket in + let rec loop i accu = + if i >= sz then accu + else if h = hashes.(i) then begin + match get_copy bucket i with + | Some v when H.equal v d + -> begin match get bucket i with + | Some v -> loop (i + 1) (v :: accu) + | None -> loop (i + 1) accu + end + | _ -> loop (i + 1) accu + end else loop (i + 1) accu + in + loop 0 [] + ;; + + let stats t = + let len = Array.length t.table in + let lens = Array.map length t.table in + Array.sort compare lens; + let totlen = Array.fold_left ( + ) 0 lens in + (len, count t, totlen, lens.(0), lens.(len/2), lens.(len-1)) + ;; + +end;; diff --git a/stdlib/weak.mli b/stdlib/weak.mli new file mode 100644 index 0000000..f3c4370 --- /dev/null +++ b/stdlib/weak.mli @@ -0,0 +1,159 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: weak.mli,v 1.17 2008-12-03 18:09:09 doligez Exp $ *) + +(** Arrays of weak pointers and hash tables of weak pointers. *) + + +(** {6 Low-level functions} *) + +type 'a t +(** The type of arrays of weak pointers (weak arrays). A weak + pointer is a value that the garbage collector may erase whenever + the value is not used any more (through normal pointers) by the + program. Note that finalisation functions are run after the + weak pointers are erased. + + A weak pointer is said to be full if it points to a value, + empty if the value was erased by the GC. + + Notes: + - Integers are not allocated and cannot be stored in weak arrays. + - Weak arrays cannot be marshaled using {!Pervasives.output_value} + nor the functions of the {!Marshal} module. +*) + + +val create : int -> 'a t +(** [Weak.create n] returns a new weak array of length [n]. + All the pointers are initially empty. Raise [Invalid_argument] + if [n] is negative or greater than {!Sys.max_array_length}[-1].*) + +val length : 'a t -> int +(** [Weak.length ar] returns the length (number of elements) of + [ar].*) + +val set : 'a t -> int -> 'a option -> unit +(** [Weak.set ar n (Some el)] sets the [n]th cell of [ar] to be a + (full) pointer to [el]; [Weak.set ar n None] sets the [n]th + cell of [ar] to empty. + Raise [Invalid_argument "Weak.set"] if [n] is not in the range + 0 to {!Weak.length}[ a - 1].*) + +val get : 'a t -> int -> 'a option +(** [Weak.get ar n] returns None if the [n]th cell of [ar] is + empty, [Some x] (where [x] is the value) if it is full. + Raise [Invalid_argument "Weak.get"] if [n] is not in the range + 0 to {!Weak.length}[ a - 1].*) + +val get_copy : 'a t -> int -> 'a option +(** [Weak.get_copy ar n] returns None if the [n]th cell of [ar] is + empty, [Some x] (where [x] is a (shallow) copy of the value) if + it is full. + In addition to pitfalls with mutable values, the interesting + difference with [get] is that [get_copy] does not prevent + the incremental GC from erasing the value in its current cycle + ([get] may delay the erasure to the next GC cycle). + Raise [Invalid_argument "Weak.get"] if [n] is not in the range + 0 to {!Weak.length}[ a - 1].*) + + +val check : 'a t -> int -> bool +(** [Weak.check ar n] returns [true] if the [n]th cell of [ar] is + full, [false] if it is empty. Note that even if [Weak.check ar n] + returns [true], a subsequent {!Weak.get}[ ar n] can return [None].*) + +val fill : 'a t -> int -> int -> 'a option -> unit +(** [Weak.fill ar ofs len el] sets to [el] all pointers of [ar] from + [ofs] to [ofs + len - 1]. Raise [Invalid_argument "Weak.fill"] + if [ofs] and [len] do not designate a valid subarray of [a].*) + +val blit : 'a t -> int -> 'a t -> int -> int -> unit +(** [Weak.blit ar1 off1 ar2 off2 len] copies [len] weak pointers + from [ar1] (starting at [off1]) to [ar2] (starting at [off2]). + It works correctly even if [ar1] and [ar2] are the same. + Raise [Invalid_argument "Weak.blit"] if [off1] and [len] do + not designate a valid subarray of [ar1], or if [off2] and [len] + do not designate a valid subarray of [ar2].*) + + +(** {6 Weak hash tables} *) + +(** A weak hash table is a hashed set of values. Each value may + magically disappear from the set when it is not used by the + rest of the program any more. This is normally used to share + data structures without inducing memory leaks. + Weak hash tables are defined on values from a {!Hashtbl.HashedType} + module; the [equal] relation and [hash] function are taken from that + module. We will say that [v] is an instance of [x] if [equal x v] + is [true]. + + The [equal] relation must be able to work on a shallow copy of + the values and give the same result as with the values themselves. + *) + +module type S = sig + type data + (** The type of the elements stored in the table. *) + type t + (** The type of tables that contain elements of type [data]. + Note that weak hash tables cannot be marshaled using + {!Pervasives.output_value} or the functions of the {!Marshal} + module. *) + val create : int -> t + (** [create n] creates a new empty weak hash table, of initial + size [n]. The table will grow as needed. *) + val clear : t -> unit + (** Remove all elements from the table. *) + val merge : t -> data -> data + (** [merge t x] returns an instance of [x] found in [t] if any, + or else adds [x] to [t] and return [x]. *) + val add : t -> data -> unit + (** [add t x] adds [x] to [t]. If there is already an instance + of [x] in [t], it is unspecified which one will be + returned by subsequent calls to [find] and [merge]. *) + val remove : t -> data -> unit + (** [remove t x] removes from [t] one instance of [x]. Does + nothing if there is no instance of [x] in [t]. *) + val find : t -> data -> data + (** [find t x] returns an instance of [x] found in [t]. + Raise [Not_found] if there is no such element. *) + val find_all : t -> data -> data list + (** [find_all t x] returns a list of all the instances of [x] + found in [t]. *) + val mem : t -> data -> bool + (** [mem t x] returns [true] if there is at least one instance + of [x] in [t], false otherwise. *) + val iter : (data -> unit) -> t -> unit + (** [iter f t] calls [f] on each element of [t], in some unspecified + order. It is not specified what happens if [f] tries to change + [t] itself. *) + val fold : (data -> 'a -> 'a) -> t -> 'a -> 'a + (** [fold f t init] computes [(f d1 (... (f dN init)))] where + [d1 ... dN] are the elements of [t] in some unspecified order. + It is not specified what happens if [f] tries to change [t] + itself. *) + val count : t -> int + (** Count the number of elements in the table. [count t] gives the + same result as [fold (fun _ n -> n+1) t 0] but does not delay the + deallocation of the dead elements. *) + val stats : t -> int * int * int * int * int * int + (** Return statistics on the table. The numbers are, in order: + table length, number of entries, sum of bucket lengths, + smallest bucket length, median bucket length, biggest bucket length. *) +end;; +(** The output signature of the functor {!Weak.Make}. *) + +module Make (H : Hashtbl.HashedType) : S with type data = H.t;; +(** Functor building an implementation of the weak hash table structure. *) diff --git a/test/.cvsignore b/test/.cvsignore new file mode 100644 index 0000000..66d34d7 --- /dev/null +++ b/test/.cvsignore @@ -0,0 +1,2 @@ +*.byt +*.out diff --git a/test/.depend b/test/.depend new file mode 100644 index 0000000..ac5de61 --- /dev/null +++ b/test/.depend @@ -0,0 +1,28 @@ +KB/equations.cmi: KB/terms.cmi +KB/kb.cmi: KB/equations.cmi KB/terms.cmi +KB/orderings.cmi: KB/terms.cmi +KB/equations.cmo: KB/equations.cmi KB/terms.cmi +KB/equations.cmx: KB/equations.cmi KB/terms.cmx +KB/kb.cmo: KB/kb.cmi KB/equations.cmi KB/terms.cmi +KB/kb.cmx: KB/kb.cmi KB/equations.cmx KB/terms.cmx +KB/kbmain.cmo: KB/kb.cmi KB/orderings.cmi KB/equations.cmi KB/terms.cmi +KB/kbmain.cmx: KB/kb.cmx KB/orderings.cmx KB/equations.cmx KB/terms.cmx +KB/orderings.cmo: KB/orderings.cmi KB/terms.cmi +KB/orderings.cmx: KB/orderings.cmi KB/terms.cmx +KB/terms.cmo: KB/terms.cmi +KB/terms.cmx: KB/terms.cmi +Lex/grammar.cmi: Lex/syntax.cmo +Lex/gram_aux.cmo: Lex/syntax.cmo +Lex/gram_aux.cmx: Lex/syntax.cmx +Lex/grammar.cmo: Lex/grammar.cmi Lex/gram_aux.cmo Lex/syntax.cmo +Lex/grammar.cmx: Lex/grammar.cmi Lex/gram_aux.cmx Lex/syntax.cmx +Lex/lexgen.cmo: Lex/syntax.cmo +Lex/lexgen.cmx: Lex/syntax.cmx +Lex/main.cmo: Lex/lexgen.cmo Lex/output.cmo Lex/grammar.cmi \ + Lex/scanner.cmo Lex/syntax.cmo Lex/scan_aux.cmo +Lex/main.cmx: Lex/lexgen.cmx Lex/output.cmx Lex/grammar.cmx \ + Lex/scanner.cmx Lex/syntax.cmx Lex/scan_aux.cmx +Lex/output.cmo: Lex/syntax.cmo +Lex/output.cmx: Lex/syntax.cmx +Lex/scanner.cmo: Lex/syntax.cmo Lex/scan_aux.cmo Lex/grammar.cmi +Lex/scanner.cmx: Lex/syntax.cmx Lex/scan_aux.cmx Lex/grammar.cmx diff --git a/test/KB/equations.ml b/test/KB/equations.ml new file mode 100644 index 0000000..40625a7 --- /dev/null +++ b/test/KB/equations.ml @@ -0,0 +1,115 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: equations.ml,v 1.5 1999-11-17 18:58:35 xleroy Exp $ *) + +(****************** Equation manipulations *************) + +open Terms + +type rule = + { number: int; + numvars: int; + lhs: term; + rhs: term } + +(* standardizes an equation so its variables are 1,2,... *) + +let mk_rule num m n = + let all_vars = union (vars m) (vars n) in + let counter = ref 0 in + let subst = + List.map (fun v -> incr counter; (v, Var !counter)) (List.rev all_vars) in + { number = num; + numvars = !counter; + lhs = substitute subst m; + rhs = substitute subst n } + + +(* checks that rules are numbered in sequence and returns their number *) + +let check_rules rules = + let counter = ref 0 in + List.iter (fun r -> incr counter; + if r.number <> !counter + then failwith "Rule numbers not in sequence") + rules; + !counter + + +let pretty_rule rule = + print_int rule.number; print_string " : "; + pretty_term rule.lhs; print_string " = "; pretty_term rule.rhs; + print_newline() + + +let pretty_rules rules = List.iter pretty_rule rules + +(****************** Rewriting **************************) + +(* Top-level rewriting. Let eq:L=R be an equation, M be a term such that L<=M. + With sigma = matching L M, we define the image of M by eq as sigma(R) *) +let reduce l m r = + substitute (matching l m) r + +(* Test whether m can be reduced by l, i.e. m contains an instance of l. *) + +let can_match l m = + try let _ = matching l m in true + with Failure _ -> false + +let rec reducible l m = + can_match l m || + (match m with + | Term(_,sons) -> List.exists (reducible l) sons + | _ -> false) + +(* Top-level rewriting with multiple rules. *) + +let rec mreduce rules m = + match rules with + [] -> failwith "mreduce" + | rule::rest -> + try + reduce rule.lhs m rule.rhs + with Failure _ -> + mreduce rest m + + +(* One step of rewriting in leftmost-outermost strategy, + with multiple rules. Fails if no redex is found *) + +let rec mrewrite1 rules m = + try + mreduce rules m + with Failure _ -> + match m with + Var n -> failwith "mrewrite1" + | Term(f, sons) -> Term(f, mrewrite1_sons rules sons) + +and mrewrite1_sons rules = function + [] -> failwith "mrewrite1" + | son::rest -> + try + mrewrite1 rules son :: rest + with Failure _ -> + son :: mrewrite1_sons rules rest + + +(* Iterating rewrite1. Returns a normal form. May loop forever *) + +let rec mrewrite_all rules m = + try + mrewrite_all rules (mrewrite1 rules m) + with Failure _ -> + m + diff --git a/test/KB/equations.mli b/test/KB/equations.mli new file mode 100644 index 0000000..6a4950d --- /dev/null +++ b/test/KB/equations.mli @@ -0,0 +1,32 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: equations.mli,v 1.5 1999-11-17 18:58:35 xleroy Exp $ *) + +open Terms + +type rule = + { number: int; + numvars: int; + lhs: term; + rhs: term } + +val mk_rule: int -> term -> term -> rule +val check_rules: rule list -> int +val pretty_rule: rule -> unit +val pretty_rules: rule list -> unit +val reduce: term -> term -> term -> term +val reducible: term -> term -> bool +val mreduce: rule list -> term -> term +val mrewrite1: rule list -> term -> term +val mrewrite1_sons: rule list -> term list -> term list +val mrewrite_all: rule list -> term -> term diff --git a/test/KB/kb.ml b/test/KB/kb.ml new file mode 100644 index 0000000..92609d2 --- /dev/null +++ b/test/KB/kb.ml @@ -0,0 +1,188 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: kb.ml,v 1.5 1999-11-17 18:58:35 xleroy Exp $ *) + +open Terms +open Equations + +(****************** Critical pairs *********************) + +(* All (u,subst) such that N/u (&var) unifies with M, + with principal unifier subst *) + +let rec super m = function + Term(_,sons) as n -> + let rec collate n = function + [] -> [] + | son::rest -> + List.map (fun (u, subst) -> (n::u, subst)) (super m son) + @ collate (n+1) rest in + let insides = collate 1 sons in + begin try + ([], unify m n) :: insides + with Failure _ -> + insides + end + | _ -> [] + + +(* Ex : +let (m,_) = <<F(A,B)>> +and (n,_) = <<H(F(A,x),F(x,y))>> in super m n +==> [[1],[2,Term ("B",[])]; x <- B + [2],[2,Term ("A",[]); 1,Term ("B",[])]] x <- A y <- B +*) + +(* All (u,subst), u&[], such that n/u unifies with m *) + +let super_strict m = function + Term(_,sons) -> + let rec collate n = function + [] -> [] + | son::rest -> + List.map (fun (u, subst) -> (n::u, subst)) (super m son) + @ collate (n+1) rest in + collate 1 sons + | _ -> [] + + +(* Critical pairs of l1=r1 with l2=r2 *) +(* critical_pairs : term_pair -> term_pair -> term_pair list *) +let critical_pairs (l1,r1) (l2,r2) = + let mk_pair (u,subst) = + substitute subst (replace l2 u r1), substitute subst r2 in + List.map mk_pair (super l1 l2) + +(* Strict critical pairs of l1=r1 with l2=r2 *) +(* strict_critical_pairs : term_pair -> term_pair -> term_pair list *) +let strict_critical_pairs (l1,r1) (l2,r2) = + let mk_pair (u,subst) = + substitute subst (replace l2 u r1), substitute subst r2 in + List.map mk_pair (super_strict l1 l2) + + +(* All critical pairs of eq1 with eq2 *) +let mutual_critical_pairs eq1 eq2 = + (strict_critical_pairs eq1 eq2) @ (critical_pairs eq2 eq1) + +(* Renaming of variables *) + +let rename n (t1,t2) = + let rec ren_rec = function + Var k -> Var(k+n) + | Term(op,sons) -> Term(op, List.map ren_rec sons) in + (ren_rec t1, ren_rec t2) + + +(************************ Completion ******************************) + +let deletion_message rule = + print_string "Rule ";print_int rule.number; print_string " deleted"; + print_newline() + + +(* Generate failure message *) +let non_orientable (m,n) = + pretty_term m; print_string " = "; pretty_term n; print_newline() + + +let rec partition p = function + [] -> ([], []) + | x::l -> let (l1, l2) = partition p l in + if p x then (x::l1, l2) else (l1, x::l2) + + +let rec get_rule n = function + [] -> raise Not_found + | r::l -> if n = r.number then r else get_rule n l + + +(* Improved Knuth-Bendix completion procedure *) + +let kb_completion greater = + let rec kbrec j rules = + let rec process failures (k,l) eqs = +(**** + print_string "***kb_completion "; print_int j; print_newline(); + pretty_rules rules; + List.iter non_orientable failures; + print_int k; print_string " "; print_int l; print_newline(); + List.iter non_orientable eqs; +***) + match eqs with + [] -> + if k<l then next_criticals failures (k+1,l) else + if l<j then next_criticals failures (1,l+1) else + begin match failures with + [] -> rules (* successful completion *) + | _ -> print_string "Non-orientable equations :"; print_newline(); + List.iter non_orientable failures; + failwith "kb_completion" + end + | (m,n)::eqs -> + let m' = mrewrite_all rules m + and n' = mrewrite_all rules n + and enter_rule(left,right) = + let new_rule = mk_rule (j+1) left right in + pretty_rule new_rule; + let left_reducible rule = reducible left rule.lhs in + let (redl,irredl) = partition left_reducible rules in + List.iter deletion_message redl; + let right_reduce rule = + mk_rule rule.number rule.lhs + (mrewrite_all (new_rule::rules) rule.rhs) in + let irreds = List.map right_reduce irredl in + let eqs' = List.map (fun rule -> (rule.lhs, rule.rhs)) redl in + kbrec (j+1) (new_rule::irreds) [] (k,l) (eqs @ eqs' @ failures) in +(*** + print_string "--- Considering "; non_orientable (m', n'); +***) + if m' = n' then process failures (k,l) eqs else + if greater(m',n') then enter_rule(m',n') else + if greater(n',m') then enter_rule(n',m') else + process ((m',n')::failures) (k,l) eqs + + and next_criticals failures (k,l) = +(**** + print_string "***next_criticals "; + print_int k; print_string " "; print_int l ; print_newline(); +****) + try + let rl = get_rule l rules in + let el = (rl.lhs, rl.rhs) in + if k=l then + process failures (k,l) + (strict_critical_pairs el (rename rl.numvars el)) + else + try + let rk = get_rule k rules in + let ek = (rk.lhs, rk.rhs) in + process failures (k,l) + (mutual_critical_pairs el (rename rl.numvars ek)) + with Not_found -> next_criticals failures (k+1,l) + with Not_found -> next_criticals failures (1,l+1) + in process + in kbrec + + +(* complete_rules is assumed locally confluent, and checked Noetherian with + ordering greater, rules is any list of rules *) + +let kb_complete greater complete_rules rules = + let n = check_rules complete_rules + and eqs = List.map (fun rule -> (rule.lhs, rule.rhs)) rules in + let completed_rules = + kb_completion greater n complete_rules [] (n,n) eqs in + print_string "Canonical set found :"; print_newline(); + pretty_rules (List.rev completed_rules) + diff --git a/test/KB/kb.mli b/test/KB/kb.mli new file mode 100644 index 0000000..00ee13d --- /dev/null +++ b/test/KB/kb.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: kb.mli,v 1.4 1999-11-17 18:58:35 xleroy Exp $ *) + +open Terms +open Equations + +val super: term -> term -> (int list * (int * term) list) list +val super_strict: term -> term -> (int list * (int * term) list) list +val critical_pairs: term * term -> term * term -> (term * term) list +val strict_critical_pairs: term * term -> term * term -> (term * term) list +val mutual_critical_pairs: term * term -> term * term -> (term * term) list +val rename: int -> term * term -> term * term +val deletion_message: rule -> unit +val non_orientable: term * term -> unit +val partition: ('a -> bool) -> 'a list -> 'a list * 'a list +val get_rule: int -> rule list -> rule +val kb_completion: (term * term -> bool) -> int -> rule list -> (term * term) list -> int * int -> (term * term) list -> rule list +val kb_complete: (term * term -> bool) -> rule list -> rule list -> unit diff --git a/test/KB/kbmain.ml b/test/KB/kbmain.ml new file mode 100644 index 0000000..e761cc9 --- /dev/null +++ b/test/KB/kbmain.ml @@ -0,0 +1,82 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: kbmain.ml,v 1.6 2005-08-12 09:22:04 xleroy Exp $ *) + +open Terms +open Equations +open Orderings +open Kb + +(**** +let group_rules = [ + { number = 1; numvars = 1; + lhs = Term("*", [Term("U",[]); Var 1]); rhs = Var 1 }; + { number = 2; numvars = 1; + lhs = Term("*", [Term("I",[Var 1]); Var 1]); rhs = Term("U",[]) }; + { number = 3; numvars = 3; + lhs = Term("*", [Term("*", [Var 1; Var 2]); Var 3]); + rhs = Term("*", [Var 1; Term("*", [Var 2; Var 3])]) } +] +****) + +let geom_rules = [ + { number = 1; numvars = 1; + lhs = Term ("*",[(Term ("U",[])); (Var 1)]); + rhs = Var 1 }; + { number = 2; numvars = 1; + lhs = Term ("*",[(Term ("I",[(Var 1)])); (Var 1)]); + rhs = Term ("U",[]) }; + { number = 3; numvars = 3; + lhs = Term ("*",[(Term ("*",[(Var 1); (Var 2)])); (Var 3)]); + rhs = Term ("*",[(Var 1); (Term ("*",[(Var 2); (Var 3)]))]) }; + { number = 4; numvars = 0; + lhs = Term ("*",[(Term ("A",[])); (Term ("B",[]))]); + rhs = Term ("*",[(Term ("B",[])); (Term ("A",[]))]) }; + { number = 5; numvars = 0; + lhs = Term ("*",[(Term ("C",[])); (Term ("C",[]))]); + rhs = Term ("U",[]) }; + { number = 6; numvars = 0; + lhs = Term("*", + [(Term ("C",[])); + (Term ("*",[(Term ("A",[])); (Term ("I",[(Term ("C",[]))]))]))]); + rhs = Term ("I",[(Term ("A",[]))]) }; + { number = 7; numvars = 0; + lhs = Term("*", + [(Term ("C",[])); + (Term ("*",[(Term ("B",[])); (Term ("I",[(Term ("C",[]))]))]))]); + rhs = Term ("B",[]) } +] + +let group_rank = function + "U" -> 0 + | "*" -> 1 + | "I" -> 2 + | "B" -> 3 + | "C" -> 4 + | "A" -> 5 + | _ -> assert false + +let group_precedence op1 op2 = + let r1 = group_rank op1 + and r2 = group_rank op2 in + if r1 = r2 then Equal else + if r1 > r2 then Greater else NotGE + +let group_order = rpo group_precedence lex_ext + +let greater pair = + match group_order pair with Greater -> true | _ -> false + +let _ = + for i = 1 to 20 do kb_complete greater [] geom_rules done + diff --git a/test/KB/orderings.ml b/test/KB/orderings.ml new file mode 100644 index 0000000..fb8d624 --- /dev/null +++ b/test/KB/orderings.ml @@ -0,0 +1,99 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: orderings.ml,v 1.4 1999-11-17 18:58:36 xleroy Exp $ *) + +(*********************** Recursive Path Ordering ****************************) + +open Terms + +type ordering = + Greater + | Equal + | NotGE + +let ge_ord order pair = match order pair with NotGE -> false | _ -> true +and gt_ord order pair = match order pair with Greater -> true | _ -> false +and eq_ord order pair = match order pair with Equal -> true | _ -> false + + +let rec rem_eq equiv x = function + [] -> failwith "rem_eq" + | y::l -> if equiv (x,y) then l else y :: rem_eq equiv x l + + +let diff_eq equiv (x,y) = + let rec diffrec = function + ([],_) as p -> p + | (h::t, y) -> try + diffrec (t, rem_eq equiv h y) + with Failure _ -> + let (x',y') = diffrec (t,y) in (h::x',y') in + if List.length x > List.length y then diffrec(y,x) else diffrec(x,y) + + +(* Multiset extension of order *) + +let mult_ext order = function + Term(_,sons1), Term(_,sons2) -> + begin match diff_eq (eq_ord order) (sons1,sons2) with + ([],[]) -> Equal + | (l1,l2) -> + if List.for_all + (fun n -> List.exists (fun m -> gt_ord order (m,n)) l1) l2 + then Greater else NotGE + end + | _ -> failwith "mult_ext" + + +(* Lexicographic extension of order *) + +let lex_ext order = function + (Term(_,sons1) as m), (Term(_,sons2) as n) -> + let rec lexrec = function + ([] , []) -> Equal + | ([] , _ ) -> NotGE + | ( _ , []) -> Greater + | (x1::l1, x2::l2) -> + match order (x1,x2) with + Greater -> if List.for_all (fun n' -> gt_ord order (m,n')) l2 + then Greater else NotGE + | Equal -> lexrec (l1,l2) + | NotGE -> if List.exists (fun m' -> ge_ord order (m',n)) l1 + then Greater else NotGE in + lexrec (sons1, sons2) + | _ -> failwith "lex_ext" + + +(* Recursive path ordering *) + +let rpo op_order ext = + let rec rporec (m,n) = + if m = n then Equal else + match m with + Var vm -> NotGE + | Term(op1,sons1) -> + match n with + Var vn -> + if occurs vn m then Greater else NotGE + | Term(op2,sons2) -> + match (op_order op1 op2) with + Greater -> + if List.for_all (fun n' -> gt_ord rporec (m,n')) sons2 + then Greater else NotGE + | Equal -> + ext rporec (m,n) + | NotGE -> + if List.exists (fun m' -> ge_ord rporec (m',n)) sons1 + then Greater else NotGE + in rporec + diff --git a/test/KB/orderings.mli b/test/KB/orderings.mli new file mode 100644 index 0000000..2b3adde --- /dev/null +++ b/test/KB/orderings.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: orderings.mli,v 1.4 1999-11-17 18:58:37 xleroy Exp $ *) + +open Terms + +type ordering = + Greater + | Equal + | NotGE + +val ge_ord: ('a -> ordering) -> 'a -> bool +val gt_ord: ('a -> ordering) -> 'a -> bool +val eq_ord: ('a -> ordering) -> 'a -> bool +val rem_eq: ('a * 'b -> bool) -> 'a -> 'b list -> 'b list +val diff_eq: ('a * 'a -> bool) -> 'a list * 'a list -> 'a list * 'a list +val mult_ext: (term * term -> ordering) -> term * term -> ordering +val lex_ext: (term * term -> ordering) -> term * term -> ordering +val rpo: (string -> string -> ordering) -> + ((term * term -> ordering) -> term * term -> ordering) -> + term * term -> ordering diff --git a/test/KB/terms.ml b/test/KB/terms.ml new file mode 100644 index 0000000..73399a3 --- /dev/null +++ b/test/KB/terms.ml @@ -0,0 +1,137 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: terms.ml,v 1.5 1999-11-17 18:58:37 xleroy Exp $ *) + +(****************** Term manipulations *****************) + +type term = + Var of int + | Term of string * term list + +let rec union l1 l2 = + match l1 with + [] -> l2 + | a::r -> if List.mem a l2 then union r l2 else a :: union r l2 + + +let rec vars = function + Var n -> [n] + | Term(_,l) -> vars_of_list l +and vars_of_list = function + [] -> [] + | t::r -> union (vars t) (vars_of_list r) + + +let rec substitute subst = function + Term(oper,sons) -> Term(oper, List.map (substitute subst) sons) + | Var(n) as t -> try List.assoc n subst with Not_found -> t + + +(* Term replacement: replace M u N is M[u<-N]. *) + +let rec replace m u n = + match (u, m) with + [], _ -> n + | i::u, Term(oper, sons) -> Term(oper, replace_nth i sons u n) + | _ -> failwith "replace" + +and replace_nth i sons u n = + match sons with + s::r -> if i = 1 + then replace s u n :: r + else s :: replace_nth (i-1) r u n + | [] -> failwith "replace_nth" + + +(* Term matching. *) + +let matching term1 term2 = + let rec match_rec subst t1 t2 = + match (t1, t2) with + Var v, _ -> + if List.mem_assoc v subst then + if t2 = List.assoc v subst then subst else failwith "matching" + else + (v, t2) :: subst + | Term(op1,sons1), Term(op2,sons2) -> + if op1 = op2 + then List.fold_left2 match_rec subst sons1 sons2 + else failwith "matching" + | _ -> failwith "matching" in + match_rec [] term1 term2 + + +(* A naive unification algorithm. *) + +let compsubst subst1 subst2 = + (List.map (fun (v,t) -> (v, substitute subst1 t)) subst2) @ subst1 + + +let rec occurs n = function + Var m -> m = n + | Term(_,sons) -> List.exists (occurs n) sons + + +let rec unify term1 term2 = + match (term1, term2) with + Var n1, _ -> + if term1 = term2 then [] + else if occurs n1 term2 then failwith "unify" + else [n1, term2] + | term1, Var n2 -> + if occurs n2 term1 then failwith "unify" + else [n2, term1] + | Term(op1,sons1), Term(op2,sons2) -> + if op1 = op2 then + List.fold_left2 (fun s t1 t2 -> compsubst (unify (substitute s t1) + (substitute s t2)) s) + [] sons1 sons2 + else failwith "unify" + + +(* We need to print terms with variables independently from input terms + obtained by parsing. We give arbitrary names v1,v2,... to their variables. +*) + +let infixes = ["+";"*"] + +let rec pretty_term = function + Var n -> + print_string "v"; print_int n + | Term (oper,sons) -> + if List.mem oper infixes then begin + match sons with + [s1;s2] -> + pretty_close s1; print_string oper; pretty_close s2 + | _ -> + failwith "pretty_term : infix arity <> 2" + end else begin + print_string oper; + match sons with + [] -> () + | t::lt -> print_string "("; + pretty_term t; + List.iter (fun t -> print_string ","; pretty_term t) lt; + print_string ")" + end + +and pretty_close = function + Term(oper, _) as m -> + if List.mem oper infixes then begin + print_string "("; pretty_term m; print_string ")" + end else + pretty_term m + | m -> + pretty_term m + + diff --git a/test/KB/terms.mli b/test/KB/terms.mli new file mode 100644 index 0000000..ea190b2 --- /dev/null +++ b/test/KB/terms.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: terms.mli,v 1.4 1999-11-17 18:58:38 xleroy Exp $ *) + +type term = + Var of int + | Term of string * term list + +val union: 'a list -> 'a list -> 'a list +val vars: term -> int list +val vars_of_list: term list -> int list +val substitute: (int * term) list -> term -> term +val replace: term -> int list -> term -> term +val replace_nth: int -> term list -> int list -> term -> term list +val matching: term -> term -> (int * term) list +val compsubst: (int * term) list -> (int * term) list -> (int * term) list +val occurs: int -> term -> bool +val unify: term -> term -> (int * term) list +val infixes: string list +val pretty_term: term -> unit +val pretty_close: term -> unit diff --git a/test/Lex/.cvsignore b/test/Lex/.cvsignore new file mode 100644 index 0000000..ed941f6 --- /dev/null +++ b/test/Lex/.cvsignore @@ -0,0 +1,5 @@ +grammar.ml +grammar.mli +scanner.ml +testscanner.ml +grammar.output diff --git a/test/Lex/gram_aux.ml b/test/Lex/gram_aux.ml new file mode 100644 index 0000000..5e8392e --- /dev/null +++ b/test/Lex/gram_aux.ml @@ -0,0 +1,47 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: gram_aux.ml,v 1.4 1999-11-17 18:58:38 xleroy Exp $ *) + +(* Auxiliaries for the parser. *) + +open Syntax + +let regexp_for_string s = + let l = String.length s in + if l = 0 then + Epsilon + else begin + let re = ref(Characters [String.get s (l - 1)]) in + for i = l - 2 downto 0 do + re := Sequence(Characters [String.get s i], !re) + done; + !re + end + + +let char_class c1 c2 = + let cl = ref [] in + for i = Char.code c2 downto Char.code c1 do + cl := Char.chr i :: !cl + done; + !cl + + +let all_chars = char_class '\001' '\255' + + +let rec subtract l1 l2 = + match l1 with + [] -> [] + | a::l -> if List.mem a l2 then subtract l l2 else a :: subtract l l2 + diff --git a/test/Lex/grammar.mly b/test/Lex/grammar.mly new file mode 100644 index 0000000..390df6c --- /dev/null +++ b/test/Lex/grammar.mly @@ -0,0 +1,114 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: grammar.mly,v 1.4 1999-11-17 18:58:38 xleroy Exp $ */ + +/* The grammar for lexer definitions */ + +%{ +open Syntax +open Gram_aux +%} + +%token <string> Tident +%token <char> Tchar +%token <string> Tstring +%token <Syntax.location> Taction +%token Trule Tparse Tand Tequal Tend Tor Tunderscore Teof Tlbracket Trbracket +%token Tstar Tmaybe Tplus Tlparen Trparen Tcaret Tdash + +%left Tor +%left CONCAT +%nonassoc Tmaybe +%left Tstar +%left Tplus + +%start lexer_definition +%type <Syntax.lexer_definition> lexer_definition + +%% + +lexer_definition: + header Trule definition other_definitions Tend + { Lexdef($1, $3::(List.rev $4)) } +; +header: + Taction + { $1 } + | + { Location(0,0) } +; +other_definitions: + other_definitions Tand definition + { $3::$1 } + | + { [] } +; +definition: + Tident Tequal entry + { ($1,$3) } +; +entry: + Tparse case rest_of_entry + { $2 :: List.rev $3 } +; +rest_of_entry: + rest_of_entry Tor case + { $3::$1 } + | + { [] } +; +case: + regexp Taction + { ($1,$2) } +; +regexp: + Tunderscore + { Characters all_chars } + | Teof + { Characters ['\000'] } + | Tchar + { Characters [$1] } + | Tstring + { regexp_for_string $1 } + | Tlbracket char_class Trbracket + { Characters $2 } + | regexp Tstar + { Repetition $1 } + | regexp Tmaybe + { Alternative($1, Epsilon) } + | regexp Tplus + { Sequence($1, Repetition $1) } + | regexp Tor regexp + { Alternative($1,$3) } + | regexp regexp %prec CONCAT + { Sequence($1,$2) } + | Tlparen regexp Trparen + { $2 } +; +char_class: + Tcaret char_class1 + { subtract all_chars $2 } + | char_class1 + { $1 } +; +char_class1: + Tchar Tdash Tchar + { char_class $1 $3 } + | Tchar + { [$1] } + | char_class char_class %prec CONCAT + { $1 @ $2 } +; + +%% + diff --git a/test/Lex/lexgen.ml b/test/Lex/lexgen.ml new file mode 100644 index 0000000..0d2df46 --- /dev/null +++ b/test/Lex/lexgen.ml @@ -0,0 +1,266 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexgen.ml,v 1.5 2000-12-28 13:06:39 weis Exp $ *) + +(* Compiling a lexer definition *) + +open Syntax + +(* Deep abstract syntax for regular expressions *) + +type regexp = + Empty + | Chars of int + | Action of int + | Seq of regexp * regexp + | Alt of regexp * regexp + | Star of regexp + +(* From shallow to deep syntax *) + +(*** + +let print_char_class c = + let print_interval low high = + prerr_int low; + if high - 1 > low then begin + prerr_char '-'; + prerr_int (high-1) + end; + prerr_char ' ' in + let rec print_class first next = function + [] -> print_interval first next + | c::l -> + if char.code c = next + then print_class first (next+1) l + else begin + print_interval first next; + print_class (char.code c) (char.code c + 1) l + end in + match c with + [] -> prerr_newline() + | c::l -> print_class (char.code c) (char.code c + 1) l; prerr_newline() + + +let rec print_regexp = function + Empty -> prerr_string "Empty" + | Chars n -> prerr_string "Chars "; prerr_int n + | Action n -> prerr_string "Action "; prerr_int n + | Seq(r1,r2) -> print_regexp r1; prerr_string "; "; print_regexp r2 + | Alt(r1,r2) -> prerr_string "("; print_regexp r1; prerr_string " | "; print_regexp r2; prerr_string ")" + | Star r -> prerr_string "("; print_regexp r; prerr_string ")*" + +***) + +let chars = ref ([] : char list list) +let chars_count = ref 0 +let actions = ref ([] : (int * location) list) +let actions_count = ref 0 + +let rec encode_regexp = function + Epsilon -> Empty + | Characters cl -> + let n = !chars_count in +(*** prerr_int n; prerr_char ' '; print_char_class cl; ***) + chars := cl :: !chars; + chars_count := !chars_count + 1; + Chars(n) + | Sequence(r1,r2) -> + Seq(encode_regexp r1, encode_regexp r2) + | Alternative(r1,r2) -> + Alt(encode_regexp r1, encode_regexp r2) + | Repetition r -> + Star (encode_regexp r) + + +let encode_casedef = + List.fold_left + (fun reg (expr,act) -> + let act_num = !actions_count in + actions_count := !actions_count + 1; + actions := (act_num, act) :: !actions; + Alt(reg, Seq(encode_regexp expr, Action act_num))) + Empty + + +let encode_lexdef (Lexdef(_, ld)) = + chars := []; + chars_count := 0; + actions := []; + actions_count := 0; + let name_regexp_list = + List.map (fun (name, casedef) -> (name, encode_casedef casedef)) ld in +(* List.iter print_char_class chars; *) + let chr = Array.of_list (List.rev !chars) + and act = !actions in + chars := []; + actions := []; + (chr, name_regexp_list, act) + + +(* To generate directly a NFA from a regular expression. + Confer Aho-Sethi-Ullman, dragon book, chap. 3 *) + +type transition = + OnChars of int + | ToAction of int + + +let rec merge_trans l1 l2 = + match (l1, l2) with + ([], s2) -> s2 + | (s1, []) -> s1 + | ((OnChars n1 as t1) :: r1 as s1), ((OnChars n2 as t2) :: r2 as s2) -> + if n1 = n2 then t1 :: merge_trans r1 r2 else + if n1 < n2 then t1 :: merge_trans r1 s2 else + t2 :: merge_trans s1 r2 + | ((ToAction n1 as t1) :: r1 as s1), ((ToAction n2 as t2) :: r2 as s2) -> + if n1 = n2 then t1 :: merge_trans r1 r2 else + if n1 < n2 then t1 :: merge_trans r1 s2 else + t2 :: merge_trans s1 r2 + | ((OnChars n1 as t1) :: r1 as s1), ((ToAction n2 as t2) :: r2 as s2) -> + t1 :: merge_trans r1 s2 + | ((ToAction n1 as t1) :: r1 as s1), ((OnChars n2 as t2) :: r2 as s2) -> + t2 :: merge_trans s1 r2 + + +let rec nullable = function + Empty -> true + | Chars _ -> false + | Action _ -> false + | Seq(r1,r2) -> nullable r1 && nullable r2 + | Alt(r1,r2) -> nullable r1 || nullable r2 + | Star r -> true + + +let rec firstpos = function + Empty -> [] + | Chars pos -> [OnChars pos] + | Action act -> [ToAction act] + | Seq(r1,r2) -> if nullable r1 + then merge_trans (firstpos r1) (firstpos r2) + else firstpos r1 + | Alt(r1,r2) -> merge_trans (firstpos r1) (firstpos r2) + | Star r -> firstpos r + + +let rec lastpos = function + Empty -> [] + | Chars pos -> [OnChars pos] + | Action act -> [ToAction act] + | Seq(r1,r2) -> if nullable r2 + then merge_trans (lastpos r1) (lastpos r2) + else lastpos r2 + | Alt(r1,r2) -> merge_trans (lastpos r1) (lastpos r2) + | Star r -> lastpos r + + +let followpos size name_regexp_list = + let v = Array.create size [] in + let fill_pos first = function + OnChars pos -> v.(pos) <- merge_trans first v.(pos); () + | ToAction _ -> () in + let rec fill = function + Seq(r1,r2) -> + fill r1; fill r2; + List.iter (fill_pos (firstpos r2)) (lastpos r1) + | Alt(r1,r2) -> + fill r1; fill r2 + | Star r -> + fill r; + List.iter (fill_pos (firstpos r)) (lastpos r) + | _ -> () in + List.iter (fun (name, regexp) -> fill regexp) name_regexp_list; + v + + +let no_action = 0x3FFFFFFF + +let split_trans_set = + List.fold_left + (fun (act, pos_set as act_pos_set) trans -> + match trans with + OnChars pos -> (act, pos :: pos_set) + | ToAction act1 -> if act1 < act then (act1, pos_set) + else act_pos_set) + (no_action, []) + + +let memory = (Hashtbl.create 131 : (transition list, int) Hashtbl.t) +let todo = ref ([] : (transition list * int) list) +let next = ref 0 + +let get_state st = + try + Hashtbl.find memory st + with Not_found -> + let nbr = !next in + next := !next + 1; + Hashtbl.add memory st nbr; + todo := (st, nbr) :: !todo; + nbr + +let rec map_on_states f = + match !todo with + [] -> [] + | (st,i)::r -> todo := r; let res = f st in (res,i) :: map_on_states f + +let number_of_states () = !next + +let goto_state = function + [] -> Backtrack + | ps -> Goto (get_state ps) + + +let transition_from chars follow pos_set = + let tr = Array.create 256 [] + and shift = Array.create 256 Backtrack in + List.iter + (fun pos -> + List.iter + (fun c -> + tr.(Char.code c) <- + merge_trans tr.(Char.code c) follow.(pos)) + chars.(pos)) + pos_set; + for i = 0 to 255 do + shift.(i) <- goto_state tr.(i) + done; + shift + + +let translate_state chars follow state = + match split_trans_set state with + n, [] -> Perform n + | n, ps -> Shift( (if n = no_action then No_remember else Remember n), + transition_from chars follow ps) + + +let make_dfa lexdef = + let (chars, name_regexp_list, actions) = + encode_lexdef lexdef in +(** + List.iter (fun (name, regexp) -> prerr_string name; prerr_string " = "; print_regexp regexp; prerr_newline()) name_regexp_list; +**) + let follow = + followpos (Array.length chars) name_regexp_list in + let initial_states = + List.map (fun (name, regexp) -> (name, get_state(firstpos regexp))) + name_regexp_list in + let states = + map_on_states (translate_state chars follow) in + let v = + Array.create (number_of_states()) (Perform 0) in + List.iter (fun (auto, i) -> v.(i) <- auto) states; + (initial_states, v, actions) + diff --git a/test/Lex/main.ml b/test/Lex/main.ml new file mode 100644 index 0000000..44a6ac1 --- /dev/null +++ b/test/Lex/main.ml @@ -0,0 +1,118 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.ml,v 1.4 1999-11-17 18:58:39 xleroy Exp $ *) + +(* The lexer generator. Command-line parsing. *) + +open Syntax +open Scanner +open Grammar +open Lexgen +open Output + +let main () = + if Array.length Sys.argv <> 2 then begin + prerr_string "Usage: camllex <input file>\n"; + exit 2 + end; + let source_name = Sys.argv.(1) in + let dest_name = + if Filename.check_suffix source_name ".mll" then + Filename.chop_suffix source_name ".mll" ^ ".ml" + else + source_name ^ ".ml" in + ic := open_in source_name; + oc := open_out dest_name; + let lexbuf = Lexing.from_channel !ic in + let (Lexdef(header,_) as def) = + try + Grammar.lexer_definition Scanner.main lexbuf + with + Parsing.Parse_error -> + prerr_string "Syntax error around char "; + prerr_int (Lexing.lexeme_start lexbuf); + prerr_endline "."; + exit 2 + | Scan_aux.Lexical_error s -> + prerr_string "Lexical error around char "; + prerr_int (Lexing.lexeme_start lexbuf); + prerr_string ": "; + prerr_string s; + prerr_endline "."; + exit 2 in + let ((init, states, acts) as dfa) = make_dfa def in + output_lexdef header dfa; + close_in !ic; + close_out !oc + +let _ = main(); exit 0 + + +(***** +let main () = + ic := stdin; + oc := stdout; + let lexbuf = lexing.from_channel ic in + let (Lexdef(header,_) as def) = + try + grammar.lexer_definition scanner.main lexbuf + with + parsing.Parse_error x -> + prerr_string "Syntax error around char "; + prerr_int (lexing.lexeme_start lexbuf); + prerr_endline "."; + sys.exit 2 + | scan_aux.Lexical_error s -> + prerr_string "Lexical error around char "; + prerr_int (lexing.lexeme_start lexbuf); + prerr_string ": "; + prerr_string s; + prerr_endline "."; + sys.exit 2 in + let ((init, states, acts) as dfa) = make_dfa def in + output_lexdef header dfa + +****) + +(**** +let debug_scanner lexbuf = + let tok = scanner.main lexbuf in + begin match tok with + Tident s -> prerr_string "Tident "; prerr_string s + | Tchar c -> prerr_string "Tchar "; prerr_char c + | Tstring s -> prerr_string "Tstring "; prerr_string s + | Taction(Location(i1,i2)) -> + prerr_string "Taction "; prerr_int i1; prerr_string "-"; + prerr_int i2 + | Trule -> prerr_string "Trule" + | Tparse -> prerr_string "Tparse" + | Tand -> prerr_string "Tand" + | Tequal -> prerr_string "Tequal" + | Tend -> prerr_string "Tend" + | Tor -> prerr_string "Tor" + | Tunderscore -> prerr_string "Tunderscore" + | Teof -> prerr_string "Teof" + | Tlbracket -> prerr_string "Tlbracket" + | Trbracket -> prerr_string "Trbracket" + | Tstar -> prerr_string "Tstar" + | Tmaybe -> prerr_string "Tmaybe" + | Tplus -> prerr_string "Tplus" + | Tlparen -> prerr_string "Tlparen" + | Trparen -> prerr_string "Trparen" + | Tcaret -> prerr_string "Tcaret" + | Tdash -> prerr_string "Tdash" + end; + prerr_newline(); + tok + +****) diff --git a/test/Lex/output.ml b/test/Lex/output.ml new file mode 100644 index 0000000..dbaead7 --- /dev/null +++ b/test/Lex/output.ml @@ -0,0 +1,169 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: output.ml,v 1.5 2000-12-28 13:06:41 weis Exp $ *) + +(* Generating a DFA as a set of mutually recursive functions *) + +open Syntax + +let ic = ref stdin +let oc = ref stdout + +(* 1- Generating the actions *) + +let copy_buffer = String.create 1024 + +let copy_chunk (Location(start,stop)) = + seek_in !ic start; + let tocopy = ref(stop - start) in + while !tocopy > 0 do + let m = + input !ic copy_buffer 0 (min !tocopy (String.length copy_buffer)) in + output !oc copy_buffer 0 m; + tocopy := !tocopy - m + done + + +let output_action (i,act) = + output_string !oc ("action_" ^ string_of_int i ^ " lexbuf = (\n"); + copy_chunk act; + output_string !oc ")\nand " + + +(* 2- Generating the states *) + +let states = ref ([||] : automata array) + +type occurrence = + { mutable pos: int list; + mutable freq: int } + +let enumerate_vect v = + let env = ref [] in + for pos = 0 to Array.length v - 1 do + try + let occ = List.assoc v.(pos) !env in + occ.pos <- pos :: occ.pos; + occ.freq <- occ.freq + 1 + with Not_found -> + env := (v.(pos), {pos = [pos]; freq = 1 }) :: !env + done; + Sort.list (fun (e1, occ1) (e2, occ2) -> occ1.freq >= occ2.freq) !env + + +let output_move = function + Backtrack -> + output_string !oc "lexing.backtrack lexbuf" + | Goto dest -> + match !states.(dest) with + Perform act_num -> + output_string !oc ("action_" ^ string_of_int act_num ^ " lexbuf") + | _ -> + output_string !oc ("state_" ^ string_of_int dest ^ " lexbuf") + + +(* Cannot use standard char_for_read because the characters to escape + are not the same in CL6 and CL1999. *) + +let output_char_lit oc = function + '\'' -> output_string oc "\\'" + | '\\' -> output_string oc "\\\\" + | '\n' -> output_string oc "\\n" + | '\t' -> output_string oc "\\t" + | c -> if Char.code c >= 32 && Char.code c < 128 then + output_char oc c + else begin + let n = Char.code c in + output_char oc '\\'; + output_char oc (Char.chr (48 + n / 100)); + output_char oc (Char.chr (48 + (n / 10) mod 10)); + output_char oc (Char.chr (48 + n mod 10)) + end + +let rec output_chars = function + [] -> + failwith "output_chars" + | [c] -> + output_string !oc "'"; + output_char_lit !oc (Char.chr c); + output_string !oc "'" + | c::cl -> + output_string !oc "'"; + output_char_lit !oc (Char.chr c); + output_string !oc "'|"; + output_chars cl + +let output_one_trans (dest, occ) = + output_chars occ.pos; + output_string !oc " -> "; + output_move dest; + output_string !oc "\n | " + +let output_all_trans trans = + output_string !oc " match lexing.next_char lexbuf with\n "; + match enumerate_vect trans with + [] -> + failwith "output_all_trans" + | (default, _) :: rest -> + List.iter output_one_trans rest; + output_string !oc "_ -> "; + output_move default; + output_string !oc "\nand " + +let output_state state_num = function + Perform i -> + () + | Shift(what_to_do, moves) -> + output_string !oc + ("state_" ^ string_of_int state_num ^ " lexbuf =\n"); + begin match what_to_do with + No_remember -> () + | Remember i -> + output_string !oc + (" Lexing.set_backtrack lexbuf action_" ^ + string_of_int i ^ ";\n") + end; + output_all_trans moves + + +(* 3- Generating the entry points *) + +let rec output_entries = function + [] -> failwith "output_entries" + | (name,state_num) :: rest -> + output_string !oc (name ^ " lexbuf =\n"); + output_string !oc " Lexing.init lexbuf;\n"; + output_string !oc (" state_" ^ string_of_int state_num ^ + " lexbuf\n"); + match rest with + [] -> output_string !oc "\n"; () + | _ -> output_string !oc "\nand "; output_entries rest + + +(* All together *) + +let output_lexdef header (initial_st, st, actions) = + prerr_int (Array.length st); prerr_string " states, "; + prerr_int (List.length actions); prerr_string " actions."; + prerr_newline(); + copy_chunk header; + output_string !oc "\nlet rec "; + states := st; + List.iter output_action actions; + for i = 0 to Array.length st - 1 do + output_state i st.(i) + done; + output_entries initial_st + + + diff --git a/test/Lex/scan_aux.ml b/test/Lex/scan_aux.ml new file mode 100644 index 0000000..bcfd4ea --- /dev/null +++ b/test/Lex/scan_aux.ml @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scan_aux.ml,v 1.4 1999-11-17 18:58:39 xleroy Exp $ *) + +(* Auxiliaries for the lexical analyzer *) + +let brace_depth = ref 0 +let comment_depth = ref 0 + +exception Lexical_error of string + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0 + + +let store_string_char c = + begin + if !string_index >= String.length !string_buff then begin + let new_buff = String.create (String.length !string_buff * 2) in + String.blit new_buff 0 !string_buff 0 (String.length !string_buff); + string_buff := new_buff + end + end; + String.unsafe_set !string_buff !string_index c; + incr string_index + +let get_stored_string () = + let s = String.sub !string_buff 0 !string_index in + string_buff := initial_string_buffer; + s + + +let char_for_backslash = function + 'n' -> '\010' (* '\n' when bootstrapped *) + | 't' -> '\009' (* '\t' *) + | 'b' -> '\008' (* '\b' *) + | 'r' -> '\013' (* '\r' *) + | c -> c + + +let char_for_decimal_code lexbuf i = + Char.chr(100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48)) + diff --git a/test/Lex/scanner.mll b/test/Lex/scanner.mll new file mode 100644 index 0000000..11e2911 --- /dev/null +++ b/test/Lex/scanner.mll @@ -0,0 +1,132 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scanner.mll,v 1.5 1999-11-17 18:58:39 xleroy Exp $ *) + +(* The lexical analyzer for lexer definitions. *) + +{ +open Syntax +open Grammar +open Scan_aux +} + +rule main = parse + [' ' '\010' '\013' '\009' ] + + { main lexbuf } + | "(*" + { comment_depth := 1; + comment lexbuf; + main lexbuf } + | (['A'-'Z' 'a'-'z'] | '_' ['A'-'Z' 'a'-'z' '\'' '0'-'9']) + ( '_' ? ['A'-'Z' 'a'-'z' ''' '0'-'9'] ) * + { match Lexing.lexeme lexbuf with + "rule" -> Trule + | "parse" -> Tparse + | "and" -> Tand + | "eof" -> Teof + | s -> Tident s } + | '"' + { reset_string_buffer(); + string lexbuf; + Tstring(get_stored_string()) } + | "'" + { Tchar(char lexbuf) } + | '{' + { let n1 = Lexing.lexeme_end lexbuf in + brace_depth := 1; + let n2 = action lexbuf in + Taction(Location(n1, n2)) } + | '=' { Tequal } + | ";;" { Tend } + | '|' { Tor } + | '_' { Tunderscore } + | "eof" { Teof } + | '[' { Tlbracket } + | ']' { Trbracket } + | '*' { Tstar } + | '?' { Tmaybe } + | '+' { Tplus } + | '(' { Tlparen } + | ')' { Trparen } + | '^' { Tcaret } + | '-' { Tdash } + | eof + { raise(Lexical_error "unterminated lexer definition") } + | _ + { raise(Lexical_error("illegal character " ^ Lexing.lexeme lexbuf)) } + +and action = parse + '{' + { incr brace_depth; + action lexbuf } + | '}' + { decr brace_depth; + if !brace_depth = 0 then Lexing.lexeme_start lexbuf else action lexbuf } + | '"' + { reset_string_buffer(); + string lexbuf; + reset_string_buffer(); + action lexbuf } + | '\'' + { let _ = char lexbuf in action lexbuf } + | "(*" + { comment_depth := 1; + comment lexbuf; + action lexbuf } + | eof + { raise (Lexical_error "unterminated action") } + | _ + { action lexbuf } + +and string = parse + '"' + { () } + | '\\' [' ' '\010' '\013' '\009' '\026' '\012'] + + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise(Lexical_error "unterminated string") } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } + +and char = parse + [^ '\\'] "'" + { Lexing.lexeme_char lexbuf 0 } + | '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { char_for_backslash (Lexing.lexeme_char lexbuf 1) } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { char_for_decimal_code lexbuf 1 } + | _ + { raise(Lexical_error "bad character constant") } + +and comment = parse + "(*" + { incr comment_depth; comment lexbuf } + | "*)" + { decr comment_depth; + if !comment_depth = 0 then () else comment lexbuf } + | '"' + { reset_string_buffer(); + string lexbuf; + reset_string_buffer(); + comment lexbuf } + | eof + { raise(Lexical_error "unterminated comment") } + | _ + { comment lexbuf } diff --git a/test/Lex/syntax.ml b/test/Lex/syntax.ml new file mode 100644 index 0000000..2b40665 --- /dev/null +++ b/test/Lex/syntax.ml @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: syntax.ml,v 1.4 1999-11-17 18:58:39 xleroy Exp $ *) + +(* The shallow abstract syntax *) + +type location = + Location of int * int + +type regular_expression = + Epsilon + | Characters of char list + | Sequence of regular_expression * regular_expression + | Alternative of regular_expression * regular_expression + | Repetition of regular_expression + +type lexer_definition = + Lexdef of location * (string * (regular_expression * location) list) list + +(* Representation of automata *) + +type automata = + Perform of int + | Shift of automata_trans * automata_move array +and automata_trans = + No_remember + | Remember of int +and automata_move = + Backtrack + | Goto of int diff --git a/test/Lex/testmain.ml b/test/Lex/testmain.ml new file mode 100644 index 0000000..194b25d --- /dev/null +++ b/test/Lex/testmain.ml @@ -0,0 +1,48 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: testmain.ml,v 1.4 1999-11-17 18:58:39 xleroy Exp $ *) + +(* The lexer generator. Command-line parsing. *) + +#open "syntax";; +#open "testscanner";; +#open "grammar";; +#open "lexgen";; +#open "output";; + +let main () = + ic := stdin; + oc := stdout; + let lexbuf = lexing.from_channel ic in + let (Lexdef(header,_) as def) = + try + grammar.lexer_definition testscanner.main lexbuf + with + parsing.Parse_error x -> + prerr_string "Syntax error around char "; + prerr_int (lexing.lexeme_start lexbuf); + prerr_endline "."; + sys.exit 2 + | scan_aux.Lexical_error s -> + prerr_string "Lexical error around char "; + prerr_int (lexing.lexeme_start lexbuf); + prerr_string ": "; + prerr_string s; + prerr_endline "."; + sys.exit 2 in + let ((init, states, acts) as dfa) = make_dfa def in + output_lexdef header dfa +;; + +main(); sys.exit 0 +;; diff --git a/test/Lex/testscanner.mll b/test/Lex/testscanner.mll new file mode 100644 index 0000000..b8ac422 --- /dev/null +++ b/test/Lex/testscanner.mll @@ -0,0 +1,135 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: testscanner.mll,v 1.4 1999-11-17 18:58:39 xleroy Exp $ *) + +(* The lexical analyzer for lexer definitions. *) + +{ +#open "syntax";; +#open "grammar";; +#open "scan_aux";; +} + +rule main = parse + _ * "qwertyuiopasdfghjklzxcvbnm0123456789!@#$%^&*()" + { main lexbuf } + | [' ' '\010' '\013' '\009' ] + + { main lexbuf } + | "(*" + { comment_depth := 1; + comment lexbuf; + main lexbuf } + | (['A'-'Z' 'a'-'z'] | '_' ['A'-'Z' 'a'-'z' '\'' '0'-'9']) + ( '_' ? ['A'-'Z' 'a'-'z' ''' '0'-'9'] ) * + { match lexing.lexeme lexbuf with + "rule" -> Trule + | "parse" -> Tparse + | "and" -> Tand + | "eof" -> Teof + | s -> Tident s } + | '"' + { reset_string_buffer(); + string lexbuf; + Tstring(get_stored_string()) } + | "'" + { Tchar(char lexbuf) } + | '{' + { let n1 = lexing.lexeme_end lexbuf in + brace_depth := 1; + let n2 = action lexbuf in + Taction(Location(n1, n2)) } + | '=' { Tequal } + | ";;" { Tend } + | '|' { Tor } + | '_' { Tunderscore } + | "eof" { Teof } + | '[' { Tlbracket } + | ']' { Trbracket } + | '*' { Tstar } + | '?' { Tmaybe } + | '+' { Tplus } + | '(' { Tlparen } + | ')' { Trparen } + | '^' { Tcaret } + | '-' { Tdash } + | eof + { raise(Lexical_error "unterminated lexer definition") } + | _ + { raise(Lexical_error("illegal character " ^ lexing.lexeme lexbuf)) } + +and action = parse + '{' + { brace_depth := brace_depth + 1; + action lexbuf } + | '}' + { brace_depth := brace_depth - 1; + if brace_depth = 0 then lexing.lexeme_start lexbuf else action lexbuf } + | '"' + { reset_string_buffer(); + string lexbuf; + reset_string_buffer(); + action lexbuf } + | '\'' + { char lexbuf; action lexbuf } + | "(*" + { comment_depth := 1; + comment lexbuf; + action lexbuf } + | eof + { raise (Lexical_error "unterminated action") } + | _ + { action lexbuf } + +and string = parse + '"' + { () } + | '\\' [' ' '\010' '\013' '\009' '\026' '\012'] + + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise(Lexical_error "unterminated string") } + | _ + { store_string_char(lexing.lexeme_char lexbuf 0); + string lexbuf } + +and char = parse + [^ '\\'] "'" + { lexing.lexeme_char lexbuf 0 } + | '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { char_for_backslash (lexing.lexeme_char lexbuf 1) } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { char_for_decimal_code lexbuf 1 } + | _ + { raise(Lexical_error "bad character constant") } + +and comment = parse + "(*" + { comment_depth := comment_depth + 1; comment lexbuf } + | "*)" + { comment_depth := comment_depth - 1; + if comment_depth = 0 then () else comment lexbuf } + | '"' + { reset_string_buffer(); + string lexbuf; + reset_string_buffer(); + comment lexbuf } + | eof + { raise(Lexical_error "unterminated comment") } + | _ + { comment lexbuf } +;; diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..2a5d437 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,194 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.38 2008-07-14 13:00:33 weis Exp $ + +include ../config/Makefile + +CAMLC=../boot/ocamlrun ../ocamlc +CAMLOPT=../boot/ocamlrun ../ocamlopt +COMPFLAGS=-nostdlib -I ../stdlib -I KB -I Lex +OPTFLAGS=-S -g +CAMLYACC=../yacc/ocamlyacc +YACCFLAGS=-v +CAMLLEX=../boot/ocamlrun ../lex/ocamllex +CAMLDEP=../boot/ocamlrun ../tools/ocamldep +CAMLRUN=../byterun/ocamlrun +CODERUNPARAMS=OCAMLRUNPARAM='o=100' + +BYTE_EXE=fib.byt takc.byt taku.byt sieve.byt quicksort.byt quicksort.fast.byt \ + fft.byt fft.fast.byt soli.byt soli.fast.byt boyer.byt kb.byt \ + nucleic.byt bdd.byt hamming.byt sorts.byt \ + almabench.byt almabench.fast.byt weaktest.byt + +CODE_EXE=$(BYTE_EXE:.byt=.out) + +SUB_DIRS=Moretest + +default: all codetest bytetest + +all: $(BYTE_EXE) $(CODE_EXE) + +clean:: + for i in $(SUB_DIRS); do \ + if test -d $$i; then \ + (cd $$i; $(MAKE) clean); \ + fi; \ + done + +# Nucleic + +nucleic.out: nucleic.ml + case $(ARCH) in \ + i386) sed -e '/<HAND_CSE>/,/<\/HAND_CSE>/d' -e '/NO_CSE>/d' \ + nucleic.ml > nucleic.mlt; \ + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) -o nucleic.out nucleic.mlt;\ + rm -f nucleic.mlt;; \ + *) $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) -o nucleic.out nucleic.ml; \ + esac + +# KB + +BYTE_KB=KB/terms.cmo KB/equations.cmo KB/kb.cmo KB/orderings.cmo KB/kbmain.cmo +CODE_KB=$(BYTE_KB:.cmo=.cmx) + +kb.byt: $(BYTE_KB) + $(CAMLC) $(COMPFLAGS) $(BYTE_KB) -o kb.byt +kb.out: $(CODE_KB) + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) $(CODE_KB) -o kb.out + +clean:: + rm -f KB/*.cm[iox] KB/*.[os] + rm -f KB/*~ + +# Genlex + +BYTE_GENLEX=Lex/syntax.cmo Lex/scan_aux.cmo Lex/scanner.cmo Lex/gram_aux.cmo \ + Lex/grammar.cmo Lex/lexgen.cmo Lex/output.cmo Lex/main.cmo +CODE_GENLEX=$(BYTE_GENLEX:.cmo=.cmx) + +genlex.byt: $(BYTE_GENLEX) + $(CAMLC) $(COMPFLAGS) $(BYTE_GENLEX) -o genlex.byt +genlex.out: $(CODE_GENLEX) + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) $(CODE_GENLEX) -o genlex.out + +clean:: + rm -f Lex/*.cm[iox] Lex/*.[os] + rm -f Lex/*~ + rm -f Lex/grammar.output + +Lex/grammar.ml Lex/grammar.mli: Lex/grammar.mly ../yacc/ocamlyacc$(EXE) + $(CAMLYACC) $(YACCFLAGS) Lex/grammar.mly + +clean:: + rm -f Lex/grammar.ml Lex/grammar.mli +beforedepend:: Lex/grammar.ml Lex/grammar.mli + +Lex/scanner.ml: Lex/scanner.mll ../lex/ocamllex + $(CAMLLEX) Lex/scanner.mll + +clean:: + rm -f Lex/scanner.ml +beforedepend:: Lex/scanner.ml + +# Moretest + +clean:: + rm -f Moretest/*.cm* Moretest/*.[os] + rm -f Moretest/*~ + +# Common rules + +.SUFFIXES: +.SUFFIXES: .mli .ml .cmi .cmo .cmx .byt .fast.byt .out .fast.out + +.ml.byt: + $(CAMLC) $(COMPFLAGS) -o $*.byt $< + +.ml.fast.byt: + cp $*.ml $*_fast.ml + $(CAMLC) $(COMPFLAGS) -unsafe -o $*.fast.byt $*_fast.ml + rm -f $*_fast.ml + +.ml.out: + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) -o $*.out $< + +.ml.fast.out: + cp $*.ml $*_fast.ml + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) -unsafe -o $*.fast.out $*_fast.ml + rm -f $*_fast.ml + +.mli.cmi: + $(CAMLC) $(COMPFLAGS) -c $< + +.ml.cmo: + $(CAMLC) $(COMPFLAGS) -c $< + +.ml.cmx: + $(CAMLOPT) $(COMPFLAGS) $(OPTFLAGS) -c $< + +$(BYTE_EXE) $(BYTE_KB) $(BYTE_GENLEX): ../ocamlc +$(BYTE_EXE): ../stdlib/stdlib.cma +$(CODE_EXE) $(CODE_KB) $(CODE_GENLEX): ../ocamlopt +$(CODE_EXE): ../stdlib/stdlib.cmxa ../stdlib/libasmrun.a + +clean:: + rm -f *.byt *.out + rm -f *.cm[iox] *.[os] + rm -f *~ + +# Regression test + +test: codetest + +bytetest: + set -e; \ + for prog in $(BYTE_EXE:.byt=); do \ + echo $$prog; \ + $(CAMLRUN) $$prog.byt | diff -b -q - Results/$$prog.out; \ + done + +codetest: + set -e; \ + for prog in $(CODE_EXE:.out=); do \ + echo $$prog; \ + ./$$prog.out | diff -b -q - Results/$$prog.out; \ + done + +clean:: + rm -f Lex/testscanner.ml + +# Benchmark + +bench: codebench + +bytebench: + set -e; \ + for prog in $(BYTE_EXE:.byt=); do \ + echo "$$prog " | cut -c 1-16 | tr -d '\012'; \ + xtime -mintime 5 -o /dev/null -e /dev/null $(CAMLRUN) $$prog.byt; \ + done + +codebench: + set -e; \ + for prog in $(CODE_EXE:.out=); do \ + echo "$$prog " | cut -c 1-16 | tr -d '\012'; \ + $(CODERUNPARAMS) xtime -mintime 5 -o /dev/null -e /dev/null ./$$prog.out; \ + done + +# Dependencies + +depend: beforedepend + $(CAMLDEP) -I KB -I Lex *.mli *.ml KB/*.mli KB/*.ml Lex/*.mli Lex/*.ml > .depend + +include .depend + diff --git a/test/Moretest/.cvsignore b/test/Moretest/.cvsignore new file mode 100644 index 0000000..38b6b6b --- /dev/null +++ b/test/Moretest/.cvsignore @@ -0,0 +1,3 @@ +tscanf_data +*.byt +*.bin diff --git a/test/Moretest/.depend b/test/Moretest/.depend new file mode 100644 index 0000000..08e672f --- /dev/null +++ b/test/Moretest/.depend @@ -0,0 +1,16 @@ +cmcaml.cmo: callback.cmo +cmcaml.cmx: callback.cmx +multdef.cmo: multdef.cmi +multdef.cmx: multdef.cmi +recmod.cmo: recmod.cmi +recmod.cmx: recmod.cmi +testing.cmo: testing.cmi +testing.cmx: testing.cmi +tscanf.cmo: testing.cmi +tscanf.cmx: testing.cmx +tscanf2_master.cmo: tscanf2_io.cmo +tscanf2_master.cmx: tscanf2_io.cmx +tscanf2_slave.cmo: tscanf2_io.cmo +tscanf2_slave.cmx: tscanf2_io.cmx +usemultdef.cmo: multdef.cmi +usemultdef.cmx: multdef.cmx diff --git a/test/Moretest/Makefile b/test/Moretest/Makefile new file mode 100644 index 0000000..68837d0 --- /dev/null +++ b/test/Moretest/Makefile @@ -0,0 +1,269 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.43 2008-09-09 08:48:24 weis Exp $ + +include ../../config/Makefile + +CAMLC=../../boot/ocamlrun ../../ocamlc -I ../../stdlib +BYTEFLAGS=-g +CAMLOPT=../../boot/ocamlrun ../../ocamlopt -I ../../stdlib +OPTFLAGS=-S -g +CAMLDEP=../../boot/ocamlrun ../../tools/ocamldep +CAMLRUN=../../byterun/ocamlrun +CODERUNPARAMS=OCAMLRUNPARAM='o=100' + +#FORTRANC=g77 +#FORTRANLIB=g2c +FORTRANC=gfortran +FORTRANLIB=gfortran + +OUTS=backtrace2.bin callback.bin manyargs.bin \ +cm.byt cmlinked.bin cm.bin \ +bigarrays.bin bigarrf.bin fftba.bin globroots.bin float.bin intext.bin \ +printf scanf regexp.byt regexp.bin md5.bin recmod.bin + +BROKENS= + +all: $(OUTS:.bin=.byt) $(OUTS) recmods + +callback.byt: tcallback.cmo callbackprim.o + $(CAMLC) -o callback.byt \ + -custom tcallback.cmo callbackprim.o ../../otherlibs/unix/libunix.a +callback.bin: tcallback.cmx callbackprim.o + $(CAMLOPT) -o tcallback.bin tcallback.cmx \ + callbackprim.o ../../otherlibs/unix/libunix.a + +manyargs.byt: manyargs.cmo manyargsprim.o + $(CAMLC) -o manyargs.byt -custom manyargs.cmo manyargsprim.o +manyargs.bin: manyargs.cmx manyargsprim.o + $(CAMLOPT) -inline 0 -o manyargs.bin manyargs.cmx manyargsprim.o + +multdef.byt: multdef.cmo usemultdef.cmo + $(CAMLC) -o multdef.byt multdef.cmo usemultdef.cmo +multdef.bin: multdef.cmx usemultdef.cmx + $(CAMLOPT) -o multdef.bin multdef.cmx usemultdef.cmx + +cm.byt: cmcaml.ml cmstub.c cmmain.c + $(CAMLC) -custom -o cm.byt cmcaml.ml cmstub.c cmmain.c + +cmlinked.bin: cmcaml.ml cmstub.c cmmain.c + $(CAMLC) -output-obj -o cm.o cmcaml.ml + $(BYTECC) -g -o cmlinked.bin cm.o \ + -I../../asmrun -I/usr/local/lib/ocaml \ + -DNO_BYTECODE_FILE cmstub.c cmmain.c \ + ../../byterun/libcamlrun.a $(BYTECCLIBS) +cmlinked.byt: cmcaml.ml cmstub.c cmmain.c + $(CAMLC) -output-obj -o cm.o cmcaml.ml + $(BYTECC) -g -o cmlinked.byt cm.o \ + -I../../byterun -I/usr/local/lib/ocaml \ + -DNO_BYTECODE_FILE cmstub.c cmmain.c \ + ../../byterun/libcamlrun.a $(BYTECCLIBS) + +cm.bin: cmcaml.ml cmstub.c cmmain.c + $(CAMLOPT) -output-obj -o cm.o cmcaml.ml + $(NATIVECC) -g -o cm.bin cm.o -I$(LIBDIR) \ + -DNO_BYTECODE_FILE cmstub.c cmmain.c \ + ../../asmrun/libasmrun.a $(NATIVECCLIBS) + +bigarrays.byt: ../../otherlibs/bigarray/bigarray.cma \ + ../../otherlibs/bigarray/libbigarray.a bigarrays.ml + $(CAMLC) -custom -o bigarrays.byt \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cma bigarray.cma bigarrays.ml + +bigarrays.bin: ../../otherlibs/bigarray/bigarray.cmxa \ + ../../otherlibs/bigarray/libbigarray.a bigarrays.ml + $(CAMLOPT) $(OPTFLAGS) -o bigarrays.bin \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cmxa bigarray.cmxa bigarrays.ml + +bigarrf.byt: bigarrf.o bigarrfstub.o \ + ../../otherlibs/bigarray/bigarray.cma \ + ../../otherlibs/bigarray/libbigarray.a bigarrfml.ml + $(CAMLC) -custom -o bigarrf.byt \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cma bigarray.cma bigarrfml.ml \ + bigarrf.o bigarrfstub.o \ + ../../byterun/libcamlrun.a -cclib -l$(FORTRANLIB) + +bigarrf.bin: bigarrf.o bigarrfstub.o \ + ../../otherlibs/bigarray/bigarray.cma \ + ../../otherlibs/bigarray/libbigarray.a bigarrfml.ml + $(CAMLOPT) $(OPTFLAGS) -o bigarrf.bin \ + -I ../../otherlibs/bigarray \ + -I ../../otherlibs/unix \ + unix.cmxa bigarray.cmxa bigarrfml.ml \ + bigarrf.o bigarrfstub.o \ + ../../asmrun/libasmrun.a -cclib -l$(FORTRANLIB) + +bigarrf.o: bigarrf.f + $(FORTRANC) -c bigarrf.f + +bigarrfstub.o: bigarrfstub.c + $(NATIVECC) $(NATIVECCCOMPOPTS) -I../../byterun \ + -I../../otherlibs/bigarray -c bigarrfstub.c + +fftba.byt: fftba.ml + $(CAMLC) -o fftba.byt -I ../../otherlibs/bigarray \ + bigarray.cma fftba.ml + +fftba.bin: fftba.ml + $(CAMLOPT) $(OPTFLAGS) -o fftba.bin -I ../../otherlibs/bigarray \ + bigarray.cmxa fftba.ml + +globroots.byt: globroots.ml globrootsprim.o + $(CAMLC) -custom -o globroots.byt globroots.ml globrootsprim.o + +globroots.bin: globroots.ml globrootsprim.o + $(CAMLOPT) -o globroots.bin globroots.ml globrootsprim.o + +globrootsprim.o: globrootsprim.c + $(BYTECC) $(BYTECCCOMPOPTS) -I../../byterun -c globrootsprim.c + +float.byt: float.cmo + ${CAMLC} -o float.byt float.cmo +float.bin: float.cmx + ${CAMLOPT} -o float.bin float.cmx + +intext.byt: intext.cmo intextaux.o + ${CAMLC} -o intext.byt -custom intext.cmo intextaux.o +intext.bin: intext.cmx intextaux.o + ${CAMLOPT} -o intext.bin intext.cmx intextaux.o + +tprintf.byt: testing.cmo tprintf.cmo + ${CAMLC} -o tprintf.byt testing.cmo tprintf.cmo +tprintf.bin: testing.cmx tprintf.cmx + ${CAMLOPT} -o tprintf.bin testing.cmx tprintf.cmx + +printf: tprintf.byt tprintf.bin + ./tprintf.byt + ./tprintf.bin + +tbuffer.byt: testing.cmo tbuffer.cmo + ${CAMLC} -o tbuffer.byt testing.cmo tbuffer.cmo +tbuffer.bin: testing.cmx tbuffer.cmx + ${CAMLOPT} -o tbuffer.bin testing.cmx tbuffer.cmx + +buffer: tscanf.byt tscanf.bin + ./tbuffer.byt + ./tbuffer.bin + +tscanf.byt: testing.cmo tscanf.cmo + ${CAMLC} -o tscanf.byt testing.cmo tscanf.cmo +tscanf.bin: testing.cmx tscanf.cmx + ${CAMLOPT} -o tscanf.bin testing.cmx tscanf.cmx + +tscanf2.byt: tscanf2_io.cmo tscanf2_slave.cmo tscanf2_master.cmo + ${CAMLC} -o tscanf2_slave.byt tscanf2_io.cmo tscanf2_slave.cmo + ${CAMLC} -o tscanf2_master.byt unix.cma \ + tscanf2_io.cmo tscanf2_master.cmo +tscanf2.bin: tscanf2_io.cmx tscanf2_slave.cmx tscanf2_master.cmx + ${CAMLOPT} -o tscanf2_slave.bin tscanf2_io.cmx tscanf2_slave.cmx + ${CAMLOPT} -o tscanf2_master.bin unix.cmxa \ + tscanf2_io.cmx tscanf2_master.cmx + +scanf: tscanf.byt tscanf.bin tscanf2.byt tscanf2.bin + ./tscanf.byt + ./tscanf.bin + ./tscanf2_master.byt ./tscanf2_slave.byt + ./tscanf2_master.bin ./tscanf2_slave.bin + +regexp.byt: ../../otherlibs/str/str.cma regexp.ml + $(CAMLC) -custom -I ../../otherlibs/str -o regexp.byt str.cma regexp.ml +regexp.bin: ../../otherlibs/str/str.cmxa regexp.ml + $(CAMLOPT) -I ../../otherlibs/str -o regexp.bin str.cmxa regexp.ml + +md5.bin: md5.ml + $(CAMLOPT) -unsafe -inline 100 -o md5.bin md5.ml + +recmod.byt: recmod.cmo + $(CAMLC) -o recmod.byt recmod.cmo + +recmod.bin: recmod.cmx + $(CAMLOPT) -o recmod.bin recmod.cmx + +recmods: + set -e; \ + for i in recmod/*.ml; do \ + case $$i in \ + *ok.ml) \ + echo "$$i (should succeed)"; \ + $(CAMLC) -c $$i;; \ + *bad.ml) \ + echo "$$i (should fail)"; \ + if $(CAMLC) -c $$i; then exit 2; else :; fi;; \ + esac; \ + done + +clean:: + rm -f recmods/*.cm[io] + +length.cmo: length.cmi +tlength.cmo: length.cmo + +tlength.byt: length.cmo tlength.cmo + $(CAMLC) -g -o tlength.byt length.cmo tlength.cmo + +float_record.cmo: float_record.cmi +tfloat_record.cmo: float_record.cmo +tfloat_record.byt: float_record.cmo tfloat_record.cmo + $(CAMLC) -g -o tfloat_record.byt float_record.cmo tfloat_record.cmo + +# Common rules + +.SUFFIXES: +.SUFFIXES: .mli .ml .cmi .cmo .cmx .byt .fast.byt .bin .fast.bin .c .o + +.ml.byt: + $(CAMLC) $(BYTEFLAGS) -o $*.byt $< + +.ml.fast.byt: + cp $*.ml $*_fast.ml + $(CAMLC) $(BYTEFLAGS) -unsafe -o $*.fast.byt $*_fast.ml + rm -f $*_fast.ml + +.ml.bin: + $(CAMLOPT) $(OPTFLAGS) -o $*.bin $< + +.ml.fast.bin: + cp $*.ml $*_fast.ml + $(CAMLOPT) $(OPTFLAGS) -unsafe -o $*.fast.bin $*_fast.ml + rm -f $*_fast.ml + +.mli.cmi: + $(CAMLC) -c $< + +.ml.cmo: + $(CAMLC) $(BYTEFLAGS) -c -g $< + +.ml.cmx: + $(CAMLOPT) $(OPTFLAGS) -c $< + +.c.o: + $(NATIVECC) $(NATIVECCCOMPOPTS) -I../../byterun -c $< + +clean:: + rm -f *.byt *.bin a.out + rm -f *.cm[iox] *.[os] + rm -f *~ + rm -f intext.data + +# Dependencies + +#depend: +# $(CAMLDEP) *.mli *.ml > .depend + +include .depend diff --git a/test/Moretest/arrays.ml b/test/Moretest/arrays.ml new file mode 100644 index 0000000..bbe8be3 --- /dev/null +++ b/test/Moretest/arrays.ml @@ -0,0 +1,86 @@ +let bigarray n = [| +n+0; n+1; n+2; n+3; n+4; n+5; n+6; n+7; n+8; n+9; n+10; n+11; n+12; +n+13; n+14; n+15; n+16; n+17; n+18; n+19; n+20; n+21; n+22; n+23; +n+24; n+25; n+26; n+27; n+28; n+29; n+30; n+31; n+32; n+33; n+34; +n+35; n+36; n+37; n+38; n+39; n+40; n+41; n+42; n+43; n+44; n+45; +n+46; n+47; n+48; n+49; n+50; n+51; n+52; n+53; n+54; n+55; n+56; +n+57; n+58; n+59; n+60; n+61; n+62; n+63; n+64; n+65; n+66; n+67; +n+68; n+69; n+70; n+71; n+72; n+73; n+74; n+75; n+76; n+77; n+78; +n+79; n+80; n+81; n+82; n+83; n+84; n+85; n+86; n+87; n+88; n+89; +n+90; n+91; n+92; n+93; n+94; n+95; n+96; n+97; n+98; n+99; n+100; +n+101; n+102; n+103; n+104; n+105; n+106; n+107; n+108; n+109; n+110; +n+111; n+112; n+113; n+114; n+115; n+116; n+117; n+118; n+119; n+120; +n+121; n+122; n+123; n+124; n+125; n+126; n+127; n+128; n+129; n+130; +n+131; n+132; n+133; n+134; n+135; n+136; n+137; n+138; n+139; n+140; +n+141; n+142; n+143; n+144; n+145; n+146; n+147; n+148; n+149; n+150; +n+151; n+152; n+153; n+154; n+155; n+156; n+157; n+158; n+159; n+160; +n+161; n+162; n+163; n+164; n+165; n+166; n+167; n+168; n+169; n+170; +n+171; n+172; n+173; n+174; n+175; n+176; n+177; n+178; n+179; n+180; +n+181; n+182; n+183; n+184; n+185; n+186; n+187; n+188; n+189; n+190; +n+191; n+192; n+193; n+194; n+195; n+196; n+197; n+198; n+199; n+200; +n+201; n+202; n+203; n+204; n+205; n+206; n+207; n+208; n+209; n+210; +n+211; n+212; n+213; n+214; n+215; n+216; n+217; n+218; n+219; n+220; +n+221; n+222; n+223; n+224; n+225; n+226; n+227; n+228; n+229; n+230; +n+231; n+232; n+233; n+234; n+235; n+236; n+237; n+238; n+239; n+240; +n+241; n+242; n+243; n+244; n+245; n+246; n+247; n+248; n+249; n+250; +n+251; n+252; n+253; n+254; n+255; n+256; n+257; n+258; n+259; n+260; +n+261; n+262; n+263; n+264; n+265; n+266; n+267; n+268; n+269; n+270; +n+271; n+272; n+273; n+274; n+275; n+276; n+277; n+278; n+279; n+280; +n+281; n+282; n+283; n+284; n+285; n+286; n+287; n+288; n+289; n+290; +n+291; n+292; n+293; n+294; n+295; n+296; n+297; n+298; n+299 +|] + +let test1 () = + let a = bigarray 12345 in + Gc.full_major(); + for i = 0 to Array.length a - 1 do + if a.(i) <> 12345 + i then print_string "Test1: error\n" + done + +let testcopy a = + Array.copy a = a + +let test2 () = + if not (testcopy [|1;2;3;4;5|]) then + print_string "Test2: failed on int array\n"; + if not (testcopy [|1.2;2.3;3.4;4.5|]) then + print_string "Test2: failed on float array\n"; + if not (testcopy [|"un"; "deux"; "trois"|]) then + print_string "Test2: failed on string array\n" + +module AbstractFloat = + (struct + type t = float + let to_float x = x + let from_float x = x + end : + sig + type t + val to_float: t -> float + val from_float: float -> t + end) + +let test3 () = + let t1 = AbstractFloat.from_float 1.0 + and t2 = AbstractFloat.from_float 2.0 + and t3 = AbstractFloat.from_float 3.0 in + let v = [|t1;t2;t3|] in + let w = Array.create 2 t1 in + let u = Array.copy v in + if not (AbstractFloat.to_float v.(0) = 1.0 && + AbstractFloat.to_float v.(1) = 2.0 && + AbstractFloat.to_float v.(2) = 3.0) then + print_string "Test3: failed on v\n"; + if not (AbstractFloat.to_float w.(0) = 1.0 && + AbstractFloat.to_float w.(1) = 1.0) then + print_string "Test3: failed on w\n"; + if not (AbstractFloat.to_float u.(0) = 1.0 && + AbstractFloat.to_float u.(1) = 2.0 && + AbstractFloat.to_float u.(2) = 3.0) then + print_string "Test3: failed on u\n" + +let _ = + test1(); + test2(); + test3(); + exit 0 diff --git a/test/Moretest/backtrace.ml b/test/Moretest/backtrace.ml new file mode 100644 index 0000000..46cb365 --- /dev/null +++ b/test/Moretest/backtrace.ml @@ -0,0 +1,57 @@ +(* A test for stack backtraces *) + +exception Error of string + +let rec f msg n = + if n = 0 then raise(Error msg) else 1 + f msg (n-1) + +let g msg = + try + f msg 5 + with Error "a" -> print_string "a"; print_newline(); 0 + | Error "b" as exn -> print_string "b"; print_newline(); raise exn + | Error "c" -> raise (Error "c") + +let _ = + Printexc.record_backtrace true; + ignore (g Sys.argv.(1)) + +(* Expected results: + +OCAMLRUNPARAM=b=1 ./backtrace.out a +a + +OCAMLRUNPARAM=b=1 ./backtrace.out b +b +Fatal error: exception Backtrace.Error("b") +Raised at file "backtrace.ml", line 6, characters 21-32 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 10, characters 4-11 +Re-raised at file "backtrace.ml", line 12, characters 68-71 +Called from file "backtrace.ml", line 17, characters 9-25 + +OCAMLRUNPARAM=b=1 ./backtrace.out c +Fatal error: exception Backtrace.Error("c") +Raised at file "backtrace.ml", line 13, characters 26-37 +Called from file "backtrace.ml", line 17, characters 9-25 + +OCAMLRUNPARAM=b=1 ./backtrace.out d +Fatal error: exception Backtrace.Error("d") +Raised at file "backtrace.ml", line 6, characters 21-32 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 6, characters 42-53 +Called from file "backtrace.ml", line 10, characters 4-11 +Called from file "backtrace.ml", line 17, characters 9-25 + +OCAMLRUNPARAM=b=1 ./backtrace.out +Fatal error: exception Invalid_argument("index out of bounds") +Raised at file "backtrace.ml", line 17, characters 12-24 + +*) diff --git a/test/Moretest/backtrace2.ml b/test/Moretest/backtrace2.ml new file mode 100644 index 0000000..064e91a --- /dev/null +++ b/test/Moretest/backtrace2.ml @@ -0,0 +1,59 @@ +(* A test for stack backtraces *) + +exception Error of string + +let rec f msg n = + if n = 0 then raise(Error msg) else 1 + f msg (n-1) + +let g msg = + try + f msg 5 + with Error "a" -> print_string "a"; print_newline(); 0 + | Error "b" as exn -> print_string "b"; print_newline(); raise exn + | Error "c" -> raise (Error "c") + +let run args = + try + ignore (g args.(0)); print_string "No exception\n" + with exn -> + Printf.printf "Uncaught exception %s\n" (Printexc.to_string exn); + Printexc.print_backtrace stdout + +let _ = + Printexc.record_backtrace true; + run [| "a" |]; + run [| "b" |]; + run [| "c" |]; + run [| "d" |]; + run [| |] + +(* Expected results: + +a +No exception +b +Uncaught exception Backtrace2.Error("b") +Raised at file "backtrace2.ml", line 6, characters 21-32 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 10, characters 4-11 +Re-raised at file "backtrace2.ml", line 12, characters 68-71 +Called from file "backtrace2.ml", line 17, characters 11-23 +Uncaught exception Backtrace2.Error("c") +Raised at file "backtrace2.ml", line 13, characters 26-37 +Called from file "backtrace2.ml", line 17, characters 11-23 +Uncaught exception Backtrace2.Error("d") +Raised at file "backtrace2.ml", line 6, characters 21-32 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 6, characters 42-53 +Called from file "backtrace2.ml", line 10, characters 4-11 +Called from file "backtrace2.ml", line 17, characters 11-23 +Uncaught exception Invalid_argument("index out of bounds") +Raised by primitive operation at file "backtrace2.ml", line 17, characters 14-22 +*) diff --git a/test/Moretest/bigarrays.ml b/test/Moretest/bigarrays.ml new file mode 100644 index 0000000..8590140 --- /dev/null +++ b/test/Moretest/bigarrays.ml @@ -0,0 +1,775 @@ +open Bigarray +open Printf +open Complex + +(* Test harness *) + +let error_occurred = ref false + +let function_tested = ref "" + +let testing_function s = + function_tested := s; + print_newline(); + print_string s; + print_newline() + +let test test_number answer correct_answer = + flush stdout; + flush stderr; + if answer <> correct_answer then begin + eprintf "*** Bad result (%s, test %d)\n" !function_tested test_number; + flush stderr; + error_occurred := true + end else begin + printf " %d..." test_number + end + +(* One-dimensional arrays *) + +let _ = + testing_function "------ Array1 --------"; + testing_function "create/set/get"; + let test_setget kind vals = + let rec set a i = function + [] -> () + | (v1, v2) :: tl -> a.{i} <- v1; set a (i+1) tl in + let rec test a i = function + [] -> true + | (v1, v2) :: tl -> a.{i} = v2 && test a (i+1) tl in + let ca = Array1.create kind c_layout (List.length vals) in + let fa = Array1.create kind fortran_layout (List.length vals) in + set ca 0 vals; + set fa 1 vals; + test ca 0 vals && test fa 1 vals in + test 1 true + (test_setget int8_signed + [0, 0; + 123, 123; + -123, -123; + 456, -56; + 0x101, 1]); + test 2 true + (test_setget int8_unsigned + [0, 0; + 123, 123; + -123, 133; + 456, 0xc8; + 0x101, 1]); + test 3 true + (test_setget int16_signed + [0, 0; + 123, 123; + -123, -123; + 31456, 31456; + -31456, -31456; + 65432, -104; + 0x10001, 1]); + test 4 true + (test_setget int16_unsigned + [0, 0; + 123, 123; + -123, 65413; + 31456, 31456; + -31456, 34080; + 65432, 65432; + 0x10001, 1]); + test 5 true + (test_setget int + [0, 0; + 123, 123; + -456, -456; + max_int, max_int; + min_int, min_int; + 0x12345678, 0x12345678; + -0x12345678, -0x12345678]); + test 6 true + (test_setget int32 + [Int32.zero, Int32.zero; + Int32.of_int 123, Int32.of_int 123; + Int32.of_int (-456), Int32.of_int (-456); + Int32.max_int, Int32.max_int; + Int32.min_int, Int32.min_int; + Int32.of_string "0x12345678", Int32.of_string "0x12345678"]); + test 7 true + (test_setget int64 + [Int64.zero, Int64.zero; + Int64.of_int 123, Int64.of_int 123; + Int64.of_int (-456), Int64.of_int (-456); + Int64.max_int, Int64.max_int; + Int64.min_int, Int64.min_int; + Int64.of_string "0x123456789ABCDEF0", + Int64.of_string "0x123456789ABCDEF0"]); + test 8 true + (test_setget nativeint + [Nativeint.zero, Nativeint.zero; + Nativeint.of_int 123, Nativeint.of_int 123; + Nativeint.of_int (-456), Nativeint.of_int (-456); + Nativeint.max_int, Nativeint.max_int; + Nativeint.min_int, Nativeint.min_int; + Nativeint.of_string "0x12345678", + Nativeint.of_string "0x12345678"]); + test 9 true + (test_setget float32 + [0.0, 0.0; + 4.0, 4.0; + -0.5, -0.5; + 655360.0, 655360.0]); + test 10 true + (test_setget float64 + [0.0, 0.0; + 4.0, 4.0; + -0.5, -0.5; + 1.2345678, 1.2345678; + 3.1415e10, 3.1415e10]); + test 11 true + (test_setget complex32 + [Complex.zero, Complex.zero; + Complex.one, Complex.one; + Complex.i, Complex.i; + {im = 0.5; re = -2.0}, {im = 0.5; re = -2.0}]); + test 12 true + (test_setget complex64 + [Complex.zero, Complex.zero; + Complex.one, Complex.one; + Complex.i, Complex.i; + {im=0.5;re= -2.0}, {im=0.5;re= -2.0}; + {im=3.1415;re=1.2345678}, {im=3.1415;re=1.2345678}]); + + let from_list kind vals = + let a = Array1.create kind c_layout (List.length vals) in + let rec set i = function + [] -> () + | hd :: tl -> a.{i} <- hd; set (i+1) tl in + set 0 vals; + a in + let from_list_fortran kind vals = + let a = Array1.create kind fortran_layout (List.length vals) in + let rec set i = function + [] -> () + | hd :: tl -> a.{i} <- hd; set (i+1) tl in + set 1 vals; + a in + + testing_function "set/get (specialized)"; + let a = Array1.create int c_layout 3 in + for i = 0 to 2 do a.{i} <- i done; + for i = 0 to 2 do test (i+1) a.{i} i done; + test 4 true (try ignore a.{3}; false with Invalid_argument _ -> true); + test 5 true (try ignore a.{-1}; false with Invalid_argument _ -> true); + + let b = Array1.create float64 fortran_layout 3 in + for i = 1 to 3 do b.{i} <- float i done; + for i = 1 to 3 do test (5 + i) b.{i} (float i) done; + test 8 true (try ignore b.{4}; false with Invalid_argument _ -> true); + test 9 true (try ignore b.{0}; false with Invalid_argument _ -> true); + + let c = Array1.create complex64 c_layout 3 in + for i = 0 to 2 do c.{i} <- {re=float i; im=0.0} done; + for i = 0 to 2 do test (10 + i) c.{i} {re=float i; im=0.0} done; + test 13 true (try ignore c.{3}; false with Invalid_argument _ -> true); + test 14 true (try ignore c.{-1}; false with Invalid_argument _ -> true); + + let d = Array1.create complex32 fortran_layout 3 in + for i = 1 to 3 do d.{i} <- {re=float i; im=0.0} done; + for i = 1 to 3 do test (14 + i) d.{i} {re=float i; im=0.0} done; + test 18 true (try ignore d.{4}; false with Invalid_argument _ -> true); + test 19 true (try ignore d.{0}; false with Invalid_argument _ -> true); + + testing_function "set/get (unsafe, specialized)"; + let a = Array1.create int c_layout 3 in + for i = 0 to 2 do Array1.unsafe_set a i i done; + for i = 0 to 2 do test (i+1) (Array1.unsafe_get a i) i done; + + let b = Array1.create float64 fortran_layout 3 in + for i = 1 to 3 do Array1.unsafe_set b i (float i) done; + for i = 1 to 3 do test (5 + i) (Array1.unsafe_get b i) (float i) done; + + testing_function "comparisons"; + let normalize_comparison n = + if n = 0 then 0 else if n < 0 then -1 else 1 in + test 1 0 (normalize_comparison (compare + (from_list int8_signed [1;2;3;-4;127;-128]) + (from_list int8_signed [1;2;3;-4;127;-128]))); + test 2 (-1) (normalize_comparison (compare + (from_list int8_signed [1;2;3;-4;127;-128]) + (from_list int8_signed [1;2;3;4;127;-128]))); + test 3 1 (normalize_comparison (compare + (from_list int8_signed [1;2;3;-4;127;-128]) + (from_list int8_signed [1;2;3;-4;42;-128]))); + test 4 (-1) (normalize_comparison (compare + (from_list int8_signed [1;2;3;-4]) + (from_list int8_signed [1;2;3;4;127;-128]))); + test 5 1 (normalize_comparison (compare + (from_list int8_signed [1;2;3;4;127;-128]) + (from_list int8_signed [1;2;3;-4]))); + + test 6 0 (normalize_comparison (compare + (from_list int8_unsigned [1;2;3;-4;127;-128]) + (from_list int8_unsigned [1;2;3;-4;127;-128]))); + test 7 1 (normalize_comparison (compare + (from_list int8_unsigned [1;2;3;-4;127;-128]) + (from_list int8_unsigned [1;2;3;4;127;-128]))); + test 8 1 (normalize_comparison (compare + (from_list int8_unsigned [1;2;3;-4;127;-128]) + (from_list int8_unsigned [1;2;3;-4;42;-128]))); + + test 9 0 (normalize_comparison (compare + (from_list int16_signed [1;2;3;-4;127;-128]) + (from_list int16_signed [1;2;3;-4;127;-128]))); + test 10 (-1) (normalize_comparison (compare + (from_list int16_signed [1;2;3;-4;127;-128]) + (from_list int16_signed [1;2;3;4;127;-128]))); + test 11 1 (normalize_comparison (compare + (from_list int16_signed [1;2;3;-4;127;-128]) + (from_list int16_signed [1;2;3;-4;42;-128]))); + + test 12 0 (normalize_comparison (compare + (from_list int16_unsigned [1;2;3;-4;127;-128]) + (from_list int16_unsigned [1;2;3;-4;127;-128]))); + test 13 (-1) (normalize_comparison (compare + (from_list int16_unsigned [1;2;3;4;127;-128]) + (from_list int16_unsigned [1;2;3;0xFFFF;127;-128]))); + test 14 1 (normalize_comparison (compare + (from_list int16_unsigned [1;2;3;-4;127;-128]) + (from_list int16_unsigned [1;2;3;-4;42;-128]))); + + test 15 0 (normalize_comparison (compare + (from_list int [1;2;3;-4;127;-128]) + (from_list int [1;2;3;-4;127;-128]))); + test 16 (-1) (normalize_comparison (compare + (from_list int [1;2;3;-4;127;-128]) + (from_list int [1;2;3;4;127;-128]))); + test 17 1 (normalize_comparison (compare + (from_list int [1;2;3;-4;127;-128]) + (from_list int [1;2;3;-4;42;-128]))); + + test 18 0 (normalize_comparison (compare + (from_list int32 (List.map Int32.of_int [1;2;3;-4;127;-128])) + (from_list int32 (List.map Int32.of_int [1;2;3;-4;127;-128])))); + test 19 (-1) (normalize_comparison (compare + (from_list int32 (List.map Int32.of_int [1;2;3;-4;127;-128])) + (from_list int32 (List.map Int32.of_int [1;2;3;4;127;-128])))); + test 20 1 (normalize_comparison (compare + (from_list int32 (List.map Int32.of_int [1;2;3;-4;127;-128])) + (from_list int32 (List.map Int32.of_int [1;2;3;-4;42;-128])))); + + test 21 0 (normalize_comparison (compare + (from_list int64 (List.map Int64.of_int [1;2;3;-4;127;-128])) + (from_list int64 (List.map Int64.of_int [1;2;3;-4;127;-128])))); + test 22 (-1) (normalize_comparison (compare + (from_list int64 (List.map Int64.of_int [1;2;3;-4;127;-128])) + (from_list int64 (List.map Int64.of_int [1;2;3;4;127;-128])))); + test 23 1 (normalize_comparison (compare + (from_list int64 (List.map Int64.of_int [1;2;3;-4;127;-128])) + (from_list int64 (List.map Int64.of_int [1;2;3;-4;42;-128])))); + + test 24 0 (normalize_comparison (compare + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;127;-128])) + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;127;-128])))); + test 25 (-1) (normalize_comparison (compare + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;127;-128])) + (from_list nativeint (List.map Nativeint.of_int [1;2;3;4;127;-128])))); + test 26 1 (normalize_comparison (compare + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;127;-128])) + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;42;-128])))); + + test 27 0 (normalize_comparison (compare + (from_list float32 [0.0; 0.25; -4.0; 3.141592654]) + (from_list float32 [0.0; 0.25; -4.0; 3.141592654]))); + test 28 (-1) (normalize_comparison (compare + (from_list float32 [0.0; 0.25; -4.0]) + (from_list float32 [0.0; 0.25; 3.14159]))); + test 29 1 (normalize_comparison (compare + (from_list float32 [0.0; 2.718; -4.0]) + (from_list float32 [0.0; 0.25; 3.14159]))); + + test 30 0 (normalize_comparison (compare + (from_list float64 [0.0; 0.25; -4.0; 3.141592654]) + (from_list float64 [0.0; 0.25; -4.0; 3.141592654]))); + test 31 (-1) (normalize_comparison (compare + (from_list float64 [0.0; 0.25; -4.0]) + (from_list float64 [0.0; 0.25; 3.14159]))); + test 32 1 (normalize_comparison (compare + (from_list float64 [0.0; 2.718; -4.0]) + (from_list float64 [0.0; 0.25; 3.14159]))); + + test 44 0 (normalize_comparison (compare + (from_list complex32 [Complex.zero; Complex.one; Complex.i]) + (from_list complex32 [Complex.zero; Complex.one; Complex.i]))); + test 45 (-1) (normalize_comparison (compare + (from_list complex32 [Complex.zero; Complex.one; Complex.i]) + (from_list complex32 [Complex.zero; Complex.one; Complex.one]))); + test 46 1 (normalize_comparison (compare + (from_list complex32 [Complex.zero; Complex.one; Complex.one]) + (from_list complex32 [Complex.zero; Complex.one; Complex.i]))); + + test 47 0 (normalize_comparison (compare + (from_list complex64 [Complex.zero; Complex.one; Complex.i]) + (from_list complex64 [Complex.zero; Complex.one; Complex.i]))); + test 48 (-1) (normalize_comparison (compare + (from_list complex64 [Complex.zero; Complex.one; Complex.i]) + (from_list complex64 [Complex.zero; Complex.one; Complex.one]))); + test 49 1 (normalize_comparison (compare + (from_list complex64 [Complex.zero; Complex.one; Complex.one]) + (from_list complex64 [Complex.zero; Complex.one; Complex.i]))); + + testing_function "dim"; + test 1 (Array1.dim (from_list int [1;2;3;4;5])) 5; + test 2 (Array1.dim (from_list_fortran int [1;2;3])) 3; + + testing_function "kind & layout"; + let a = from_list int [1;2;3] in + test 1 (Array1.kind a) int; + test 2 (Array1.layout a) c_layout; + let a = from_list_fortran float32 [1.0;2.0;3.0] in + test 1 (Array1.kind a) float32; + test 2 (Array1.layout a) fortran_layout; + + testing_function "sub"; + let a = from_list int [1;2;3;4;5;6;7;8] in + test 1 (Array1.sub a 2 5) + (from_list int [3;4;5;6;7]); + test 2 (Array1.sub a 0 2) + (from_list int [1;2]); + test 3 (Array1.sub a 0 8) + (from_list int [1;2;3;4;5;6;7;8]); + let a = from_list float64 [1.0;2.0;3.0;4.0;5.0;6.0;7.0;8.0] in + test 4 (Array1.sub a 2 5) + (from_list float64 [3.0;4.0;5.0;6.0;7.0]); + test 5 (Array1.sub a 0 2) + (from_list float64 [1.0;2.0]); + test 6 (Array1.sub a 0 8) + (from_list float64 [1.0;2.0;3.0;4.0;5.0;6.0;7.0;8.0]); + let a = from_list_fortran float64 [1.0;2.0;3.0;4.0;5.0;6.0;7.0;8.0] in + test 7 (Array1.sub a 2 5) + (from_list_fortran float64 [2.0;3.0;4.0;5.0;6.0]); + test 8 (Array1.sub a 1 2) + (from_list_fortran float64 [1.0;2.0]); + test 9 (Array1.sub a 1 8) + (from_list_fortran float64 [1.0;2.0;3.0;4.0;5.0;6.0;7.0;8.0]); + Gc.full_major(); (* test GC of proxies *) + + testing_function "blit, fill"; + let test_blit_fill kind data initval ofs len = + let a = from_list kind data in + let b = Array1.create kind c_layout (List.length data) in + Array1.blit a b; + (a = b) && + (Array1.fill (Array1.sub b ofs len) initval; + let rec check i = function + [] -> true + | hd :: tl -> b.{i} = (if i >= ofs && i < ofs + len + then initval else hd) + && check (i+1) tl + in check 0 data) in + test 1 true (test_blit_fill int8_signed [1;2;5;8;-100;127] 7 3 2); + test 2 true (test_blit_fill int8_unsigned [1;2;5;8;-100;212] 7 3 2); + test 3 true (test_blit_fill int16_signed [1;2;5;8;-100;212] 7 3 2); + test 4 true (test_blit_fill int16_unsigned [1;2;5;8;-100;212] 7 3 2); + test 5 true (test_blit_fill int [1;2;5;8;-100;212] 7 3 2); + test 6 true (test_blit_fill int32 (List.map Int32.of_int [1;2;5;8;-100;212]) + (Int32.of_int 7) 3 2); + test 7 true (test_blit_fill int64 (List.map Int64.of_int [1;2;5;8;-100;212]) + (Int64.of_int 7) 3 2); + test 8 true (test_blit_fill nativeint + (List.map Nativeint.of_int [1;2;5;8;-100;212]) + (Nativeint.of_int 7) 3 2); + test 9 true (test_blit_fill float32 [1.0;2.0;0.5;0.125;256.0;512.0] + 0.25 3 2); + test 10 true (test_blit_fill float64 [1.0;2.0;5.0;8.123;-100.456;212e19] + 3.1415 3 2); + test 11 true (test_blit_fill complex32 [Complex.zero; Complex.one; Complex.i] + Complex.i 1 1); + test 12 true (test_blit_fill complex64 [Complex.zero; Complex.one; Complex.i] + Complex.i 1 1); + +(* Bi-dimensional arrays *) + + print_newline(); + testing_function "------ Array2 --------"; + testing_function "create/set/get"; + let make_array2 kind layout ind0 dim1 dim2 fromint = + let a = Array2.create kind layout dim1 dim2 in + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + a.{i,j} <- (fromint (i * 1000 + j)) + done + done; + a in + let check_array2 a ind0 dim1 dim2 fromint = + try + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + if a.{i,j} <> (fromint (i * 1000 + j)) then raise Exit + done + done; + true + with Exit -> false in + let id x = x in + test 1 true + (check_array2 (make_array2 int16_signed c_layout 0 10 20 id) 0 10 20 id); + test 2 true + (check_array2 (make_array2 int c_layout 0 10 20 id) 0 10 20 id); + test 3 true + (check_array2 (make_array2 int32 c_layout 0 10 20 Int32.of_int) + 0 10 20 Int32.of_int); + test 4 true + (check_array2 (make_array2 float32 c_layout 0 10 20 float) + 0 10 20 float); + test 5 true + (check_array2 (make_array2 float64 c_layout 0 10 20 float) + 0 10 20 float); + test 6 true + (check_array2 (make_array2 int16_signed fortran_layout 1 10 20 id) 1 10 20 id); + test 7 true + (check_array2 (make_array2 int fortran_layout 1 10 20 id) 1 10 20 id); + test 8 true + (check_array2 (make_array2 int32 fortran_layout 1 10 20 Int32.of_int) + 1 10 20 Int32.of_int); + test 9 true + (check_array2 (make_array2 float32 fortran_layout 1 10 20 float) + 1 10 20 float); + test 10 true + (check_array2 (make_array2 float64 fortran_layout 1 10 20 float) + 1 10 20 float); + let makecomplex i = {re = float i; im = float (-i)} in + test 11 true + (check_array2 (make_array2 complex32 c_layout 0 10 20 makecomplex) + 0 10 20 makecomplex); + test 12 true + (check_array2 (make_array2 complex64 c_layout 0 10 20 makecomplex) + 0 10 20 makecomplex); + test 13 true + (check_array2 (make_array2 complex32 fortran_layout 1 10 20 makecomplex) + 1 10 20 makecomplex); + test 14 true + (check_array2 (make_array2 complex64 fortran_layout 1 10 20 makecomplex) + 1 10 20 makecomplex); + + testing_function "set/get (specialized)"; + let a = Array2.create int16_signed c_layout 3 3 in + for i = 0 to 2 do for j = 0 to 2 do a.{i,j} <- i-j done done; + let ok = ref true in + for i = 0 to 2 do + for j = 0 to 2 do if a.{i,j} <> i-j then ok := false done + done; + test 1 true !ok; + test 2 true (try ignore a.{3,0}; false with Invalid_argument _ -> true); + test 3 true (try ignore a.{-1,0}; false with Invalid_argument _ -> true); + test 4 true (try ignore a.{0,3}; false with Invalid_argument _ -> true); + test 5 true (try ignore a.{0,-1}; false with Invalid_argument _ -> true); + + let b = Array2.create float32 fortran_layout 3 3 in + for i = 1 to 3 do for j = 1 to 3 do b.{i,j} <- float(i-j) done done; + let ok = ref true in + for i = 1 to 3 do + for j = 1 to 3 do if b.{i,j} <> float(i-j) then ok := false done + done; + test 6 true !ok; + test 7 true (try ignore b.{4,1}; false with Invalid_argument _ -> true); + test 8 true (try ignore b.{0,1}; false with Invalid_argument _ -> true); + test 9 true (try ignore b.{1,4}; false with Invalid_argument _ -> true); + test 10 true (try ignore b.{1,0}; false with Invalid_argument _ -> true); + + testing_function "set/get (unsafe, specialized)"; + let a = Array2.create int16_signed c_layout 3 3 in + for i = 0 to 2 do for j = 0 to 2 do Array2.unsafe_set a i j (i-j) done done; + let ok = ref true in + for i = 0 to 2 do + for j = 0 to 2 do if Array2.unsafe_get a i j <> i-j then ok := false done + done; + test 1 true !ok; + + let b = Array2.create float32 fortran_layout 3 3 in + for i = 1 to 3 do for j = 1 to 3 do Array2.unsafe_set b i j (float(i-j)) done done; + let ok = ref true in + for i = 1 to 3 do + for j = 1 to 3 do if Array2.unsafe_get b i j <> float(i-j) then ok := false done + done; + test 2 true !ok; + + testing_function "dim"; + let a = (make_array2 int c_layout 0 4 6 id) in + test 1 (Array2.dim1 a) 4; + test 2 (Array2.dim2 a) 6; + let b = (make_array2 int fortran_layout 1 4 6 id) in + test 3 (Array2.dim1 b) 4; + test 4 (Array2.dim2 b) 6; + + testing_function "sub"; + let a = make_array2 int c_layout 0 5 3 id in + let b = Array2.sub_left a 2 2 in + test 1 true + (b.{0,0} = 2000 && + b.{0,1} = 2001 && + b.{0,2} = 2002 && + b.{1,0} = 3000 && + b.{1,1} = 3001 && + b.{1,2} = 3002); + let a = make_array2 int fortran_layout 1 5 3 id in + let b = Array2.sub_right a 2 2 in + test 2 true + (b.{1,1} = 1002 && + b.{1,2} = 1003 && + b.{2,1} = 2002 && + b.{2,2} = 2003 && + b.{3,1} = 3002 && + b.{3,2} = 3003 && + b.{4,1} = 4002 && + b.{4,2} = 4003 && + b.{5,1} = 5002 && + b.{5,2} = 5003); + + testing_function "slice"; + let a = make_array2 int c_layout 0 5 3 id in + test 1 (Array2.slice_left a 0) (from_list int [0;1;2]); + test 2 (Array2.slice_left a 1) (from_list int [1000;1001;1002]); + test 3 (Array2.slice_left a 2) (from_list int [2000;2001;2002]); + test 4 (Array2.slice_left a 3) (from_list int [3000;3001;3002]); + test 5 (Array2.slice_left a 4) (from_list int [4000;4001;4002]); + let a = make_array2 int fortran_layout 1 5 3 id in + test 6 (Array2.slice_right a 1) (from_list_fortran int [1001;2001;3001;4001;5001]); + test 7 (Array2.slice_right a 2) (from_list_fortran int [1002;2002;3002;4002;5002]); + test 8 (Array2.slice_right a 3) (from_list_fortran int [1003;2003;3003;4003;5003]); + +(* Tri-dimensional arrays *) + + print_newline(); + testing_function "------ Array3 --------"; + testing_function "create/set/get"; + let make_array3 kind layout ind0 dim1 dim2 dim3 fromint = + let a = Array3.create kind layout dim1 dim2 dim3 in + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + for k = ind0 to dim3 - 1 + ind0 do + a.{i, j, k} <- (fromint (i * 100 + j * 10 + k)) + done + done + done; + a in + let check_array3 a ind0 dim1 dim2 dim3 fromint = + try + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + for k = ind0 to dim3 - 1 + ind0 do + if a.{i, j, k} <> (fromint (i * 100 + j * 10 + k)) + then raise Exit + done + done + done; + true + with Exit -> false in + let id x = x in + test 1 true + (check_array3 (make_array3 int16_signed c_layout 0 4 5 6 id) 0 4 5 6 id); + test 2 true + (check_array3 (make_array3 int c_layout 0 4 5 6 id) 0 4 5 6 id); + test 3 true + (check_array3 (make_array3 int32 c_layout 0 4 5 6 Int32.of_int) + 0 4 5 6 Int32.of_int); + test 4 true + (check_array3 (make_array3 float32 c_layout 0 4 5 6 float) + 0 4 5 6 float); + test 5 true + (check_array3 (make_array3 float64 c_layout 0 4 5 6 float) + 0 4 5 6 float); + test 6 true + (check_array3 (make_array3 int16_signed fortran_layout 1 4 5 6 id) 1 4 5 6 id); + test 7 true + (check_array3 (make_array3 int fortran_layout 1 4 5 6 id) 1 4 5 6 id); + test 8 true + (check_array3 (make_array3 int32 fortran_layout 1 4 5 6 Int32.of_int) + 1 4 5 6 Int32.of_int); + test 9 true + (check_array3 (make_array3 float32 fortran_layout 1 4 5 6 float) + 1 4 5 6 float); + test 10 true + (check_array3 (make_array3 float64 fortran_layout 1 4 5 6 float) + 1 4 5 6 float); + test 11 true + (check_array3 (make_array3 complex32 c_layout 0 4 5 6 makecomplex) + 0 4 5 6 makecomplex); + test 12 true + (check_array3 (make_array3 complex64 c_layout 0 4 5 6 makecomplex) + 0 4 5 6 makecomplex); + test 13 true + (check_array3 (make_array3 complex32 fortran_layout 1 4 5 6 makecomplex) + 1 4 5 6 makecomplex); + test 14 true + (check_array3 (make_array3 complex64 fortran_layout 1 4 5 6 makecomplex) + 1 4 5 6 makecomplex); + + + testing_function "set/get (specialized)"; + let a = Array3.create int32 c_layout 2 3 4 in + for i = 0 to 1 do for j = 0 to 2 do for k = 0 to 3 do + a.{i,j,k} <- Int32.of_int((i lsl 4) + (j lsl 2) + k) + done done done; + let ok = ref true in + for i = 0 to 1 do for j = 0 to 2 do for k = 0 to 3 do + if Int32.to_int a.{i,j,k} <> (i lsl 4) + (j lsl 2) + k then ok := false + done done done; + test 1 true !ok; + + let b = Array3.create int64 fortran_layout 2 3 4 in + for i = 1 to 2 do for j = 1 to 3 do for k = 1 to 4 do + b.{i,j,k} <- Int64.of_int((i lsl 4) + (j lsl 2) + k) + done done done; + let ok = ref true in + for i = 1 to 2 do for j = 1 to 3 do for k = 1 to 4 do + if Int64.to_int b.{i,j,k} <> (i lsl 4) + (j lsl 2) + k then ok := false + done done done; + test 2 true !ok; + + testing_function "set/get (unsafe, specialized)"; + let a = Array3.create int32 c_layout 2 3 4 in + for i = 0 to 1 do for j = 0 to 2 do for k = 0 to 3 do + Array3.unsafe_set a i j k (Int32.of_int((i lsl 4) + (j lsl 2) + k)) + done done done; + let ok = ref true in + for i = 0 to 1 do for j = 0 to 2 do for k = 0 to 3 do + if Int32.to_int (Array3.unsafe_get a i j k) <> (i lsl 4) + (j lsl 2) + k then ok := false + done done done; + test 1 true !ok; + + testing_function "dim"; + let a = (make_array3 int c_layout 0 4 5 6 id) in + test 1 (Array3.dim1 a) 4; + test 2 (Array3.dim2 a) 5; + test 3 (Array3.dim3 a) 6; + let b = (make_array3 int fortran_layout 1 4 5 6 id) in + test 4 (Array3.dim1 b) 4; + test 5 (Array3.dim2 b) 5; + test 6 (Array3.dim3 b) 6; + + testing_function "slice1"; + let a = make_array3 int c_layout 0 3 3 3 id in + test 1 (Array3.slice_left_1 a 0 0) (from_list int [0;1;2]); + test 2 (Array3.slice_left_1 a 0 1) (from_list int [10;11;12]); + test 3 (Array3.slice_left_1 a 0 2) (from_list int [20;21;22]); + test 4 (Array3.slice_left_1 a 1 1) (from_list int [110;111;112]); + test 5 (Array3.slice_left_1 a 2 1) (from_list int [210;211;212]); + let a = make_array3 int fortran_layout 1 3 3 3 id in + test 6 (Array3.slice_right_1 a 1 2) (from_list_fortran int [112;212;312]); + test 7 (Array3.slice_right_1 a 3 1) (from_list_fortran int [131;231;331]); + +(* Reshaping *) + print_newline(); + testing_function "------ Reshaping --------"; + testing_function "reshape_1"; + let a = make_array2 int c_layout 0 3 4 id in + let b = make_array2 int fortran_layout 1 3 4 id in + let c = reshape_1 (genarray_of_array2 a) 12 in + test 1 c (from_list int [0;1;2;3;1000;1001;1002;1003;2000;2001;2002;2003]); + let d = reshape_1 (genarray_of_array2 b) 12 in + test 2 d (from_list_fortran int [1001;2001;3001;1002;2002;3002;1003;2003;3003;1004;2004;3004]); + testing_function "reshape_2"; + let c = reshape_2 (genarray_of_array2 a) 4 3 in + test 1 (Array2.slice_left c 0) (from_list int [0;1;2]); + test 2 (Array2.slice_left c 1) (from_list int [3;1000;1001]); + test 3 (Array2.slice_left c 2) (from_list int [1002;1003;2000]); + test 4 (Array2.slice_left c 3) (from_list int [2001;2002;2003]); + let d = reshape_2 (genarray_of_array2 b) 4 3 in + test 5 (Array2.slice_right d 1) (from_list_fortran int [1001;2001;3001;1002]); + test 6 (Array2.slice_right d 2) (from_list_fortran int [2002;3002;1003;2003]); + test 7 (Array2.slice_right d 3) (from_list_fortran int [3003;1004;2004;3004]); + +(* I/O *) + + print_newline(); + testing_function "------ I/O --------"; + testing_function "output_value/input_value"; + let test_structured_io testno value = + let tmp = Filename.temp_file "bigarray" ".data" in + let oc = open_out_bin tmp in + output_value oc value; + close_out oc; + let ic = open_in_bin tmp in + let value' = input_value ic in + close_in ic; + Sys.remove tmp; + test testno value value' in + test_structured_io 1 (from_list int8_signed [1;2;3;-4;127;-128]); + test_structured_io 2 (from_list int16_signed [1;2;3;-4;127;-128]); + test_structured_io 3 (from_list int [1;2;3;-4;127;-128]); + test_structured_io 4 + (from_list int32 (List.map Int32.of_int [1;2;3;-4;127;-128])); + test_structured_io 5 + (from_list int64 (List.map Int64.of_int [1;2;3;-4;127;-128])); + test_structured_io 6 + (from_list nativeint (List.map Nativeint.of_int [1;2;3;-4;127;-128])); + test_structured_io 7 (from_list float32 [0.0; 0.25; -4.0; 3.141592654]); + test_structured_io 8 (from_list float64 [0.0; 0.25; -4.0; 3.141592654]); + test_structured_io 9 (make_array2 int c_layout 0 100 100 id); + test_structured_io 10 (make_array2 float64 fortran_layout 1 200 200 float); + test_structured_io 11 (make_array3 int32 c_layout 0 20 30 40 Int32.of_int); + test_structured_io 12 (make_array3 float32 fortran_layout 1 10 50 100 float); + test_structured_io 13 (make_array2 complex32 c_layout 0 100 100 makecomplex); + test_structured_io 14 (make_array3 complex64 fortran_layout 1 10 20 30 makecomplex); + + testing_function "map_file"; + let mapped_file = Filename.temp_file "bigarray" ".data" in + begin + let fd = + Unix.openfile mapped_file + [Unix.O_RDWR; Unix.O_TRUNC; Unix.O_CREAT] 0o666 in + let a = Array1.map_file fd float64 c_layout true 10000 in + Unix.close fd; + for i = 0 to 9999 do a.{i} <- float i done; + let fd = Unix.openfile mapped_file [Unix.O_RDONLY] 0 in + let b = Array2.map_file fd float64 fortran_layout false 100 (-1) in + Unix.close fd; + let ok = ref true in + for i = 0 to 99 do + for j = 0 to 99 do + if b.{j+1,i+1} <> float (100 * i + j) then ok := false + done + done; + test 1 !ok true; + b.{50,50} <- (-1.0); + let fd = Unix.openfile mapped_file [Unix.O_RDONLY] 0 in + let c = Array2.map_file fd float64 c_layout false (-1) 100 in + Unix.close fd; + let ok = ref true in + for i = 0 to 99 do + for j = 0 to 99 do + if c.{i,j} <> float (100 * i + j) then ok := false + done + done; + test 2 !ok true; + let fd = Unix.openfile mapped_file [Unix.O_RDONLY] 0 in + let c = Array2.map_file fd ~pos:800L float64 c_layout false (-1) 100 in + Unix.close fd; + let ok = ref true in + for i = 1 to 99 do + for j = 0 to 99 do + if c.{i-1,j} <> float (100 * i + j) then ok := false + done + done; + test 3 !ok true; + let fd = Unix.openfile mapped_file [Unix.O_RDONLY] 0 in + let c = Array2.map_file fd ~pos:79200L float64 c_layout false (-1) 100 in + Unix.close fd; + let ok = ref true in + for j = 0 to 99 do + if c.{0,j} <> float (100 * 99 + j) then ok := false + done; + test 4 !ok true + end; + (* Force garbage collection of the mapped bigarrays above, otherwise + Win32 doesn't let us erase the file. Notice the begin...end above + so that the VM doesn't keep stack references to the mapped bigarrays. *) + Gc.full_major(); + Sys.remove mapped_file; + + () + +(********* End of test *********) + +let _ = + print_newline(); + if !error_occurred then begin + prerr_endline "************* TEST FAILED ****************"; exit 2 + end else + exit 0 diff --git a/test/Moretest/bigarrf.f b/test/Moretest/bigarrf.f new file mode 100644 index 0000000..5c2462c --- /dev/null +++ b/test/Moretest/bigarrf.f @@ -0,0 +1,27 @@ + subroutine filltab() + + integer dimx, dimy + parameter (dimx = 8, dimy = 6) + real ftab(dimx, dimy) + common /ftab/ ftab + integer x, y + + do 100 x = 1, dimx + do 110 y = 1, dimy + ftab(x, y) = x * 100 + y + 110 continue + 100 continue + end + + subroutine printtab(tab, dimx, dimy) + + integer dimx, dimy + real tab(dimx, dimy) + integer x, y + + do 200 x = 1, dimx + print 300, x, (tab(x, y), y = 1, dimy) + 300 format(/1X, I3, 2X, 10F6.1/) + 200 continue + end + diff --git a/test/Moretest/bigarrfml.ml b/test/Moretest/bigarrfml.ml new file mode 100644 index 0000000..c915622 --- /dev/null +++ b/test/Moretest/bigarrfml.ml @@ -0,0 +1,63 @@ +open Bigarray +open Printf + +(* Test harness *) + +let error_occurred = ref false + +let function_tested = ref "" + +let testing_function s = + function_tested := s; + print_newline(); + print_string s; + print_newline() + +let test test_number answer correct_answer = + flush stdout; + flush stderr; + if answer <> correct_answer then begin + eprintf "*** Bad result (%s, test %d)\n" !function_tested test_number; + flush stderr; + error_occurred := true + end else begin + printf " %d..." test_number + end + +(* External C and Fortran functions *) + +external c_filltab : unit -> (float, float64_elt, c_layout) Array2.t = "c_filltab" +external c_printtab : (float, float64_elt, c_layout) Array2.t -> unit = "c_printtab" +external fortran_filltab : unit -> (float, float32_elt, fortran_layout) Array2.t = "fortran_filltab" +external fortran_printtab : (float, float32_elt, fortran_layout) Array2.t -> unit = "fortran_printtab" + +let _ = + + let make_array2 kind layout ind0 dim1 dim2 fromint = + let a = Array2.create kind layout dim1 dim2 in + for i = ind0 to dim1 - 1 + ind0 do + for j = ind0 to dim2 - 1 + ind0 do + a.{i,j} <- (fromint (i * 1000 + j)) + done + done; + a in + + print_newline(); + testing_function "------ Foreign function interface --------"; + testing_function "Passing an array to C"; + c_printtab (make_array2 float64 c_layout 0 6 8 float); + testing_function "Accessing a C array"; + let a = c_filltab () in + test 1 a.{0,0} 0.0; + test 2 a.{1,0} 100.0; + test 3 a.{0,1} 1.0; + test 4 a.{5,4} 504.0; + testing_function "Passing an array to Fortran"; + fortran_printtab (make_array2 float32 fortran_layout 1 5 4 float); + testing_function "Accessing a Fortran array"; + let a = fortran_filltab () in + test 1 a.{1,1} 101.0; + test 2 a.{2,1} 201.0; + test 3 a.{1,2} 102.0; + test 4 a.{5,4} 504.0; + diff --git a/test/Moretest/bigarrfstub.c b/test/Moretest/bigarrfstub.c new file mode 100644 index 0000000..87bd67b --- /dev/null +++ b/test/Moretest/bigarrfstub.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <mlvalues.h> +#include <bigarray.h> + +extern void filltab_(void); +extern void printtab_(float * data, int * dimx, int * dimy); +extern float ftab_[]; + +#define DIMX 6 +#define DIMY 8 + +double ctab[DIMX][DIMY]; + +void filltab(void) +{ + int x, y; + for (x = 0; x < DIMX; x++) + for (y = 0; y < DIMY; y++) + ctab[x][y] = x * 100 + y; +} + +void printtab(double tab[DIMX][DIMY]) +{ + int x, y; + for (x = 0; x < DIMX; x++) { + printf("%3d", x); + for (y = 0; y < DIMY; y++) + printf(" %6.1f", tab[x][y]); + printf("\n"); + } +} + +value c_filltab(value unit) +{ + filltab(); + return alloc_bigarray_dims(BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT, + 2, ctab, DIMX, DIMY); +} + +value c_printtab(value ba) +{ + printtab(Data_bigarray_val(ba)); + return Val_unit; +} + +value fortran_filltab(value unit) +{ + filltab_(); + return alloc_bigarray_dims(BIGARRAY_FLOAT32 | BIGARRAY_FORTRAN_LAYOUT, + 2, ftab_, 8, 6); +} + +value fortran_printtab(value ba) +{ + int dimx = Bigarray_val(ba)->dim[0]; + int dimy = Bigarray_val(ba)->dim[1]; + printtab_(Data_bigarray_val(ba), &dimx, &dimy); + return Val_unit; +} + diff --git a/test/Moretest/bigints.ml b/test/Moretest/bigints.ml new file mode 100644 index 0000000..0b101ff --- /dev/null +++ b/test/Moretest/bigints.ml @@ -0,0 +1,12 @@ +let _ = + print_int 1000000000; print_newline(); + print_int 10000000000; print_newline(); + print_int 100000000000; print_newline(); + print_int 1000000000000; print_newline(); + print_int 10000000000000; print_newline(); + print_int 100000000000000; print_newline(); + print_int 1000000000000000; print_newline(); + print_int 10000000000000000; print_newline(); + print_int 100000000000000000; print_newline(); + print_int 1000000000000000000; print_newline() + diff --git a/test/Moretest/bounds.ml b/test/Moretest/bounds.ml new file mode 100644 index 0000000..a785c3c --- /dev/null +++ b/test/Moretest/bounds.ml @@ -0,0 +1,28 @@ +(* Test bound checks with ocamlopt *) + +let a = [| 0; 1; 2 |] + +let trail = ref [] + +let test n = + let result = + try + trail := n :: !trail; a.(n); "doesn't fail" + with Invalid_argument s -> + (* Check well-formedness of s *) + if String.length s = 19 + && s = "index out of bounds" + then "fails" + else "bad Invalid_argument" + | _ -> "bad exception" + in + print_int n; print_string ": "; print_string result; print_newline() + +let _ = + test 0; test 1; test 2; test 3; test 4; test (-1); + Gc.full_major(); + print_string "Trail:"; + List.iter (fun n -> print_string " "; print_int n) !trail; + print_newline() + + diff --git a/test/Moretest/boxedints.ml b/test/Moretest/boxedints.ml new file mode 100644 index 0000000..ed97513 --- /dev/null +++ b/test/Moretest/boxedints.ml @@ -0,0 +1,568 @@ +(* Test the types nativeint, int32, int64 *) + +open Printf + +let error_occurred = ref false + +let function_tested = ref "" + +let testing_function s = + function_tested := s; + print_newline(); + print_string s; + print_newline() + +let test test_number answer correct_answer = + flush stdout; + flush stderr; + if answer <> correct_answer then begin + eprintf "*** Bad result (%s, test %d)\n" !function_tested test_number; + flush stderr; + error_occurred := true + end else begin + printf " %d..." test_number + end + +(***** Tests on 32 bit arithmetic *****) + +module type TESTSIG = sig + type t + module Ops : sig + val neg: t -> t + val add: t -> t -> t + val sub: t -> t -> t + val mul: t -> t -> t + val div: t -> t -> t + val rem: t -> t -> t + val logand: t -> t -> t + val logor: t -> t -> t + val logxor: t -> t -> t + val shift_left: t -> int -> t + val shift_right: t -> int -> t + val shift_right_logical: t -> int -> t + val of_int: int -> t + val to_int: t -> int + val of_float: float -> t + val to_float: t -> float + val zero: t + val one: t + val minus_one: t + val min_int: t + val max_int: t + val format : string -> t -> string + val to_string: t -> string + val of_string: string -> t + end + val testcomp: t -> t -> bool*bool*bool*bool*bool*bool*int +end + +module Test32(M: TESTSIG) = +struct + open M + open Ops + + let _ = + testing_function "of_int, to_int"; + test 1 (to_int (of_int 0)) 0; + test 2 (to_int (of_int 123)) 123; + test 3 (to_int (of_int (-456))) (-456); + test 4 (to_int (of_int 0x3FFFFFFF)) 0x3FFFFFFF; + test 5 (to_int (of_int (-0x40000000))) (-0x40000000); + + testing_function "of_string"; + test 1 (of_string "0") (of_int 0); + test 2 (of_string "123") (of_int 123); + test 3 (of_string "-456") (of_int (-456)); + test 4 (of_string "123456789") (of_int 123456789); + test 5 (of_string "0xABCDEF") (of_int 0xABCDEF); + test 6 (of_string "-0o1234567012") (of_int (- 0o1234567012)); + test 7 (of_string "0b01010111111000001100") + (of_int 0b01010111111000001100); + test 8 (of_string "0x7FFFFFFF") max_int; + test 9 (of_string "-0x80000000") min_int; + test 10 (of_string "0x80000000") min_int; + test 11 (of_string "0xFFFFFFFF") minus_one; + + testing_function "to_string, format"; + List.iter (fun (n, s) -> test n (to_string (of_string s)) s) + [1, "0"; 2, "123"; 3, "-456"; 4, "1234567890"; + 5, "2147483647"; 6, "-2147483648"]; + List.iter (fun (n, s) -> test n (format "0x%X" (of_string s)) s) + [7, "0x0"; 8, "0x123"; 9, "0xABCDEF"; 10, "0x12345678"; + 11, "0x7FFFFFFF"; 12, "0x80000000"; 13, "0xFFFFFFFF"]; + test 14 (to_string max_int) "2147483647"; + test 15 (to_string min_int) "-2147483648"; + test 16 (to_string zero) "0"; + test 17 (to_string one) "1"; + test 18 (to_string minus_one) "-1"; + + testing_function "neg"; + test 1 (neg (of_int 0)) (of_int 0); + test 2 (neg (of_int 123)) (of_int (-123)); + test 3 (neg (of_int (-456))) (of_int 456); + test 4 (neg (of_int 123456789)) (of_int (-123456789)); + test 5 (neg max_int) (of_string "-0x7FFFFFFF"); + test 6 (neg min_int) min_int; + + testing_function "add"; + test 1 (add (of_int 0) (of_int 0)) (of_int 0); + test 2 (add (of_int 123) (of_int 0)) (of_int 123); + test 3 (add (of_int 0) (of_int 456)) (of_int 456); + test 4 (add (of_int 123) (of_int 456)) (of_int 579); + test 5 (add (of_int (-123)) (of_int 456)) (of_int 333); + test 6 (add (of_int 123) (of_int (-456))) (of_int (-333)); + test 7 (add (of_int (-123)) (of_int (-456))) (of_int (-579)); + test 8 (add (of_string "0x12345678") (of_string "0x9ABCDEF")) + (of_string "0x1be02467"); + test 9 (add max_int max_int) (of_int (-2)); + test 10 (add min_int min_int) zero; + test 11 (add max_int one) min_int; + test 12 (add min_int minus_one) max_int; + test 13 (add max_int min_int) minus_one; + + testing_function "sub"; + test 1 (sub (of_int 0) (of_int 0)) (of_int 0); + test 2 (sub (of_int 123) (of_int 0)) (of_int 123); + test 3 (sub (of_int 0) (of_int 456)) (of_int (-456)); + test 4 (sub (of_int 123) (of_int 456)) (of_int (-333)); + test 5 (sub (of_int (-123)) (of_int 456)) (of_int (-579)); + test 6 (sub (of_int 123) (of_int (-456))) (of_int 579); + test 7 (sub (of_int (-123)) (of_int (-456))) (of_int 333); + test 8 (sub (of_string "0x12345678") (of_string "0x9ABCDEF")) + (of_string "0x8888889"); + test 9 (sub max_int min_int) minus_one; + test 10 (sub min_int max_int) one; + test 11 (sub min_int one) max_int; + test 12 (sub max_int minus_one) min_int; + + testing_function "mul"; + test 1 (mul (of_int 0) (of_int 0)) (of_int 0); + test 2 (mul (of_int 123) (of_int 0)) (of_int 0); + test 3 (mul (of_int 0) (of_int (-456))) (of_int 0); + test 4 (mul (of_int 123) (of_int 1)) (of_int 123); + test 5 (mul (of_int 1) (of_int (-456))) (of_int (-456)); + test 6 (mul (of_int 123) (of_int (-1))) (of_int (-123)); + test 7 (mul (of_int (-1)) (of_int (-456))) (of_int 456); + test 8 (mul (of_int 123) (of_int 456)) (of_int 56088); + test 9 (mul (of_int (-123)) (of_int 456)) (of_int (-56088)); + test 10 (mul (of_int 123) (of_int (-456))) (of_int (-56088)); + test 11 (mul (of_int (-123)) (of_int (-456))) (of_int 56088); + test 12 (mul (of_string "0x12345678") (of_string "0x9ABCDEF")) + (of_string "0xe242d208"); + test 13 (mul max_int max_int) one; + + testing_function "div"; + List.iter + (fun (n, a, b) -> test n (div (of_int a) (of_int b)) (of_int (a / b))) + [1, 0, 2; + 2, 123, 1; + 3, -123, 1; + 4, 123, -1; + 5, -123, -1; + 6, 127531236, 365; + 7, 16384, 256; + 8, -127531236, 365; + 9, 127531236, -365; + 10, 1234567, 12345678; + 11, 1234567, -12345678]; + + testing_function "mod"; + List.iter + (fun (n, a, b) -> test n (rem (of_int a) (of_int b)) (of_int (a mod b))) + [1, 0, 2; + 2, 123, 1; + 3, -123, 1; + 4, 123, -1; + 5, -123, -1; + 6, 127531236, 365; + 7, 16384, 256; + 8, -127531236, 365; + 9, 127531236, -365; + 10, 1234567, 12345678; + 11, 1234567, -12345678]; + + testing_function "and"; + List.iter + (fun (n, a, b, c) -> test n (logand (of_string a) (of_string b)) + (of_string c)) + [1, "0x12345678", "0x9abcdef0", "0x12345670"; + 2, "0x12345678", "0x0fedcba9", "0x2244228"; + 3, "0xFFFFFFFF", "0x12345678", "0x12345678"; + 4, "0", "0x12345678", "0"; + 5, "0x55555555", "0xAAAAAAAA", "0"]; + + testing_function "or"; + List.iter + (fun (n, a, b, c) -> test n (logor (of_string a) (of_string b)) + (of_string c)) + [1, "0x12345678", "0x9abcdef0", "0x9abcdef8"; + 2, "0x12345678", "0x0fedcba9", "0x1ffddff9"; + 3, "0xFFFFFFFF", "0x12345678", "0xFFFFFFFF"; + 4, "0", "0x12345678", "0x12345678"; + 5, "0x55555555", "0xAAAAAAAA", "0xFFFFFFFF"]; + + testing_function "xor"; + List.iter + (fun (n, a, b, c) -> test n (logxor (of_string a) (of_string b)) + (of_string c)) + [1, "0x12345678", "0x9abcdef0", "0x88888888"; + 2, "0x12345678", "0x0fedcba9", "0x1dd99dd1"; + 3, "0xFFFFFFFF", "0x12345678", "0xedcba987"; + 4, "0", "0x12345678", "0x12345678"; + 5, "0x55555555", "0xAAAAAAAA", "0xFFFFFFFF"]; + + testing_function "shift_left"; + List.iter + (fun (n, a, b, c) -> test n (shift_left (of_string a) b) (of_string c)) + [1, "1", 1, "2"; + 2, "1", 2, "4"; + 3, "1", 4, "0x10"; + 4, "1", 30, "0x40000000"; + 5, "1", 31, "0x80000000"; + 6, "0x16236", 7, "0xb11b00"; + 7, "0x10", 27, "0x80000000"; + 8, "0x10", 28, "0"]; + + testing_function "shift_right"; + List.iter + (fun (n, a, b, c) -> test n (shift_right (of_string a) b) (of_string c)) + [1, "2", 1, "1"; + 2, "4", 2, "1"; + 3, "0x10", 4, "1"; + 4, "0x40000000", 10, "0x100000"; + 5, "0x80000000", 31, "-1"; + 6, "0xb11b00", 7, "0x16236"; + 7, "-0xb11b00", 7, "-90678"]; + + testing_function "shift_right_logical"; + List.iter + (fun (n, a, b, c) -> test n (shift_right_logical (of_string a) b) + (of_string c)) + [1, "2", 1, "1"; + 2, "4", 2, "1"; + 3, "0x10", 4, "1"; + 4, "0x40000000", 10, "0x100000"; + 5, "0x80000000", 31, "1"; + 6, "0xb11b00", 7, "0x16236"; + 7, "-0xb11b00", 7, "0x1fe9dca"]; + + testing_function "of_float"; + test 1 (of_float 0.0) (of_int 0); + test 2 (of_float 123.0) (of_int 123); + test 3 (of_float 123.456) (of_int 123); + test 4 (of_float 123.999) (of_int 123); + test 5 (of_float (-456.0)) (of_int (-456)); + test 6 (of_float (-456.123)) (of_int (-456)); + test 7 (of_float (-456.789)) (of_int (-456)); + + testing_function "to_float"; + test 1 (to_float (of_int 0)) 0.0; + test 2 (to_float (of_int 123)) 123.0; + test 3 (to_float (of_int (-456))) (-456.0); + test 4 (to_float (of_int 0x3FFFFFFF)) 1073741823.0; + test 5 (to_float (of_int (-0x40000000))) (-1073741824.0); + + testing_function "Comparisons"; + test 1 (testcomp (of_int 0) (of_int 0)) + (true,false,false,false,true,true,0); + test 2 (testcomp (of_int 1234567) (of_int 1234567)) + (true,false,false,false,true,true,0); + test 3 (testcomp (of_int 0) (of_int 1)) + (false,true,true,false,true,false,-1); + test 4 (testcomp (of_int (-1)) (of_int 0)) + (false,true,true,false,true,false,-1); + test 5 (testcomp (of_int 1) (of_int 0)) + (false,true,false,true,false,true,1); + test 6 (testcomp (of_int 0) (of_int (-1))) + (false,true,false,true,false,true,1); + test 7 (testcomp max_int min_int) + (false,true,false,true,false,true,1); + + () +end + +(********* Tests on 64-bit arithmetic ***********) + +module Test64(M: TESTSIG) = +struct + open M + open Ops + + let _ = + testing_function "of_int, to_int"; + test 1 (to_int (of_int 0)) 0; + test 2 (to_int (of_int 123)) 123; + test 3 (to_int (of_int (-456))) (-456); + test 4 (to_int (of_int 0x3FFFFFFF)) 0x3FFFFFFF; + test 5 (to_int (of_int (-0x40000000))) (-0x40000000); + + testing_function "of_string"; + test 1 (of_string "0") (of_int 0); + test 2 (of_string "123") (of_int 123); + test 3 (of_string "-456") (of_int (-456)); + test 4 (of_string "123456789") (of_int 123456789); + test 5 (of_string "0xABCDEF") (of_int 0xABCDEF); + test 6 (of_string "-0o1234567012") (of_int (- 0o1234567012)); + test 7 (of_string "0b01010111111000001100") + (of_int 0b01010111111000001100); + test 8 (of_string "0x7FFFFFFFFFFFFFFF") max_int; + test 9 (of_string "-0x8000000000000000") min_int; + test 10 (of_string "0x8000000000000000") min_int; + test 11 (of_string "0xFFFFFFFFFFFFFFFF") minus_one; + + testing_function "to_string, format"; + List.iter (fun (n, s) -> test n (to_string (of_string s)) s) + [1, "0"; 2, "123"; 3, "-456"; 4, "1234567890"; + 5, "1234567890123456789"; + 6, "9223372036854775807"; + 7, "-9223372036854775808"]; + List.iter (fun (n, s) -> test n ("0x" ^ format "%X" (of_string s)) s) + [7, "0x0"; 8, "0x123"; 9, "0xABCDEF"; 10, "0x1234567812345678"; + 11, "0x7FFFFFFFFFFFFFFF"; 12, "0x8000000000000000"; + 13, "0xFFFFFFFFFFFFFFFF"]; + test 14 (to_string max_int) "9223372036854775807"; + test 15 (to_string min_int) "-9223372036854775808"; + test 16 (to_string zero) "0"; + test 17 (to_string one) "1"; + test 18 (to_string minus_one) "-1"; + + testing_function "neg"; + test 1 (neg (of_int 0)) (of_int 0); + test 2 (neg (of_int 123)) (of_int (-123)); + test 3 (neg (of_int (-456))) (of_int 456); + test 4 (neg (of_int 123456789)) (of_int (-123456789)); + test 5 (neg max_int) (of_string "-0x7FFFFFFFFFFFFFFF"); + test 6 (neg min_int) min_int; + + testing_function "add"; + test 1 (add (of_int 0) (of_int 0)) (of_int 0); + test 2 (add (of_int 123) (of_int 0)) (of_int 123); + test 3 (add (of_int 0) (of_int 456)) (of_int 456); + test 4 (add (of_int 123) (of_int 456)) (of_int 579); + test 5 (add (of_int (-123)) (of_int 456)) (of_int 333); + test 6 (add (of_int 123) (of_int (-456))) (of_int (-333)); + test 7 (add (of_int (-123)) (of_int (-456))) (of_int (-579)); + test 8 (add (of_string "0x1234567812345678") + (of_string "0x9ABCDEF09ABCDEF")) + (of_string "0x1be024671be02467"); + test 9 (add max_int max_int) (of_int (-2)); + test 10 (add min_int min_int) zero; + test 11 (add max_int one) min_int; + test 12 (add min_int minus_one) max_int; + test 13 (add max_int min_int) minus_one; + + testing_function "sub"; + test 1 (sub (of_int 0) (of_int 0)) (of_int 0); + test 2 (sub (of_int 123) (of_int 0)) (of_int 123); + test 3 (sub (of_int 0) (of_int 456)) (of_int (-456)); + test 4 (sub (of_int 123) (of_int 456)) (of_int (-333)); + test 5 (sub (of_int (-123)) (of_int 456)) (of_int (-579)); + test 6 (sub (of_int 123) (of_int (-456))) (of_int 579); + test 7 (sub (of_int (-123)) (of_int (-456))) (of_int 333); + test 8 (sub (of_string "0x1234567812345678") + (of_string "0x9ABCDEF09ABCDEF")) + (of_string "0x888888908888889"); + test 9 (sub max_int min_int) minus_one; + test 10 (sub min_int max_int) one; + test 11 (sub min_int one) max_int; + test 12 (sub max_int minus_one) min_int; + + testing_function "mul"; + test 1 (mul (of_int 0) (of_int 0)) (of_int 0); + test 2 (mul (of_int 123) (of_int 0)) (of_int 0); + test 3 (mul (of_int 0) (of_int (-456))) (of_int 0); + test 4 (mul (of_int 123) (of_int 1)) (of_int 123); + test 5 (mul (of_int 1) (of_int (-456))) (of_int (-456)); + test 6 (mul (of_int 123) (of_int (-1))) (of_int (-123)); + test 7 (mul (of_int (-1)) (of_int (-456))) (of_int 456); + test 8 (mul (of_int 123) (of_int 456)) (of_int 56088); + test 9 (mul (of_int (-123)) (of_int 456)) (of_int (-56088)); + test 10 (mul (of_int 123) (of_int (-456))) (of_int (-56088)); + test 11 (mul (of_int (-123)) (of_int (-456))) (of_int 56088); + test 12 (mul (of_string "0x12345678") (of_string "0x9ABCDEF")) + (of_string "0xb00ea4e242d208"); + test 13 (mul max_int max_int) one; + + testing_function "div"; + List.iter + (fun (n, a, b) -> test n (div (of_int a) (of_int b)) (of_int (a / b))) + [1, 0, 2; + 2, 123, 1; + 3, -123, 1; + 4, 123, -1; + 5, -123, -1; + 6, 127531236, 365; + 7, 16384, 256; + 8, -127531236, 365; + 9, 127531236, -365; + 10, 1234567, 12345678; + 11, 1234567, -12345678]; + + testing_function "mod"; + List.iter + (fun (n, a, b) -> test n (rem (of_int a) (of_int b)) (of_int (a mod b))) + [1, 0, 2; + 2, 123, 1; + 3, -123, 1; + 4, 123, -1; + 5, -123, -1; + 6, 127531236, 365; + 7, 16384, 256; + 8, -127531236, 365; + 9, 127531236, -365; + 10, 1234567, 12345678; + 11, 1234567, -12345678]; + + testing_function "and"; + List.iter + (fun (n, a, b, c) -> test n (logand (of_string a) (of_string b)) + (of_string c)) + [1, "0x1234567812345678", "0x9abcdef09abcdef0", "0x1234567012345670"; + 2, "0x1234567812345678", "0x0fedcba90fedcba9", "0x224422802244228"; + 3, "0xFFFFFFFFFFFFFFFF", "0x1234000012345678", "0x1234000012345678"; + 4, "0", "0x1234567812345678", "0"; + 5, "0x5555555555555555", "0xAAAAAAAAAAAAAAAA", "0"]; + + testing_function "or"; + List.iter + (fun (n, a, b, c) -> test n (logor (of_string a) (of_string b)) + (of_string c)) + [1, "0x1234567812345678", "0x9abcdef09abcdef0", "0x9abcdef89abcdef8"; + 2, "0x1234567812345678", "0x0fedcba90fedcba9", "0x1ffddff91ffddff9"; + 3, "0xFFFFFFFFFFFFFFFF", "0x12345678", "0xFFFFFFFFFFFFFFFF"; + 4, "0", "0x1234567812340000", "0x1234567812340000"; + 5, "0x5555555555555555", "0xAAAAAAAAAAAAAAAA", "0xFFFFFFFFFFFFFFFF"]; + + testing_function "xor"; + List.iter + (fun (n, a, b, c) -> test n (logxor (of_string a) (of_string b)) + (of_string c)) + [1, "0x1234567812345678", "0x9abcdef09abcdef0", "0x8888888888888888"; + 2, "0x1234567812345678", "0x0fedcba90fedcba9", "0x1dd99dd11dd99dd1"; + 3, "0xFFFFFFFFFFFFFFFF", "0x123456789ABCDEF", "0xfedcba9876543210"; + 4, "0", "0x1234567812340000", "0x1234567812340000"; + 5, "0x5555555555555555", "0xAAAAAAAAAAAAAAAA", "0xFFFFFFFFFFFFFFFF"]; + + testing_function "shift_left"; + List.iter + (fun (n, a, b, c) -> test n (shift_left (of_string a) b) (of_string c)) + [1, "1", 1, "2"; + 2, "1", 2, "4"; + 3, "1", 4, "0x10"; + 4, "1", 62, "0x4000000000000000"; + 5, "1", 63, "0x8000000000000000"; + 6, "0x16236ABD45673", 7, "0xb11b55ea2b3980"; + 7, "0x10", 59, "0x8000000000000000"; + 8, "0x10", 60, "0"]; + + testing_function "shift_right"; + List.iter + (fun (n, a, b, c) -> test n (shift_right (of_string a) b) (of_string c)) + [1, "2", 1, "1"; + 2, "4", 2, "1"; + 3, "0x10", 4, "1"; + 4, "0x40000000", 10, "0x100000"; + 5, "0x8000000000000000", 63, "-1"; + 6, "0xb11b55ea2b3980", 7, "0x16236ABD45673"; + 7, "-0xb11b55ea2b3980", 7, "-389461927286387"]; + + testing_function "shift_right_logical"; + List.iter + (fun (n, a, b, c) -> test n (shift_right_logical (of_string a) b) + (of_string c)) + [1, "2", 1, "1"; + 2, "4", 2, "1"; + 3, "0x10", 4, "1"; + 4, "0x40000000", 10, "0x100000"; + 5, "0x8000000000000000", 63, "1"; + 6, "0xb11b55ea2b3980", 7, "0x16236ABD45673"; + 7, "-0xb11b55ea2b3980", 7, "0x1fe9dc9542ba98d"]; + + testing_function "Comparisons"; + test 1 (testcomp (of_int 0) (of_int 0)) + (true,false,false,false,true,true,0); + test 2 (testcomp (of_int 1234567) (of_int 1234567)) + (true,false,false,false,true,true,0); + test 3 (testcomp (of_int 0) (of_int 1)) + (false,true,true,false,true,false,-1); + test 4 (testcomp (of_int (-1)) (of_int 0)) + (false,true,true,false,true,false,-1); + test 5 (testcomp (of_int 1) (of_int 0)) + (false,true,false,true,false,true,1); + test 6 (testcomp (of_int 0) (of_int (-1))) + (false,true,false,true,false,true,1); + test 7 (testcomp max_int min_int) + (false,true,false,true,false,true,1); + + () +end + +(******** The test proper **********) + +let testcomp_int32 (a : int32) (b : int32) = + (a = b, a <> b, a < b, a > b, a <= b, a >= b, compare a b) +let testcomp_int64 (a : int64) (b : int64) = + (a = b, a <> b, a < b, a > b, a <= b, a >= b, compare a b) +let testcomp_nativeint (a : nativeint) (b : nativeint) = + (a = b, a <> b, a < b, a > b, a <= b, a >= b, compare a b) + +let _ = + testing_function "-------- Int32 --------"; + let module A = Test32(struct type t = int32 + module Ops = Int32 + let testcomp = testcomp_int32 end) in + print_newline(); testing_function "-------- Int64 --------"; + let module B = Test64(struct type t = int64 + module Ops = Int64 + let testcomp = testcomp_int64 end) in + print_newline(); testing_function "-------- Nativeint --------"; + begin match Sys.word_size with + 32 -> + let module C = + Test32(struct type t = nativeint + module Ops = Nativeint + let testcomp = testcomp_nativeint end) + in () + | 64 -> + let module C = + Test64(struct type t = nativeint + module Ops = Nativeint + let testcomp = testcomp_nativeint end) + in () + | _ -> + assert false + end; + print_newline(); testing_function "--------- Conversions -----------"; + testing_function "nativeint of/to int32"; + test 1 (Nativeint.of_int32 (Int32.of_string "0x12345678")) + (Nativeint.of_string "0x12345678"); + test 2 (Nativeint.to_int32 (Nativeint.of_string "0x12345678")) + (Int32.of_string "0x12345678"); + if Sys.word_size = 64 then + test 3 (Nativeint.to_int32 (Nativeint.of_string "0x123456789ABCDEF0")) + (Int32.of_string "0x9ABCDEF0"); + testing_function "int64 of/to int32"; + test 1 (Int64.of_int32 (Int32.of_string "-0x12345678")) + (Int64.of_string "-0x12345678"); + test 2 (Int64.to_int32 (Int64.of_string "-0x12345678")) + (Int32.of_string "-0x12345678"); + test 3 (Int64.to_int32 (Int64.of_string "0x123456789ABCDEF0")) + (Int32.of_string "0x9ABCDEF0"); + testing_function "int64 of/to nativeint"; + test 1 (Int64.of_nativeint (Nativeint.of_string "0x12345678")) + (Int64.of_string "0x12345678"); + test 2 (Int64.to_nativeint (Int64.of_string "-0x12345678")) + (Nativeint.of_string "-0x12345678"); + test 3 (Int64.to_nativeint (Int64.of_string "0x123456789ABCDEF0")) + (if Sys.word_size = 64 + then Nativeint.of_string "0x123456789ABCDEF0" + else Nativeint.of_string "0x9ABCDEF0") + +(********* End of test *********) + +let _ = + print_newline(); + if !error_occurred then begin + prerr_endline "************* TEST FAILED ****************"; exit 2 + end else + exit 0 diff --git a/test/Moretest/callbackprim.c b/test/Moretest/callbackprim.c new file mode 100644 index 0000000..f1a4ccf --- /dev/null +++ b/test/Moretest/callbackprim.c @@ -0,0 +1,54 @@ +#include "mlvalues.h" +#include "memory.h" +#include "callback.h" + +value mycallback1(value fun, value arg) +{ + value res; + res = callback(fun, arg); + return res; +} + +value mycallback2(value fun, value arg1, value arg2) +{ + value res; + res = callback2(fun, arg1, arg2); + return res; +} + +value mycallback3(value fun, value arg1, value arg2, value arg3) +{ + value res; + res = callback3(fun, arg1, arg2, arg3); + return res; +} + +value mycallback4(value fun, value arg1, value arg2, value arg3, value arg4) +{ + value args[4]; + value res; + args[0] = arg1; + args[1] = arg2; + args[2] = arg3; + args[3] = arg4; + res = callbackN(fun, 4, args); + return res; +} + +value mypushroot(value v, value fun, value arg) +{ + Begin_root(v) + callback(fun, arg); + End_roots(); + return v; +} + +value mycamlparam (value v, value fun, value arg) +{ + CAMLparam3 (v, fun, arg); + CAMLlocal2 (x, y); + x = v; + y = callback (fun, arg); + v = x; + CAMLreturn (v); +} diff --git a/test/Moretest/cmcaml.ml b/test/Moretest/cmcaml.ml new file mode 100644 index 0000000..4ebed1e --- /dev/null +++ b/test/Moretest/cmcaml.ml @@ -0,0 +1,16 @@ +(* Caml part of the code *) + +let rec fib n = + if n < 2 then 1 else fib(n-1) + fib(n-2) + +let format_result n = + let r = "Result = " ^ string_of_int n in + (* Allocate gratuitously to test GC *) + for i = 1 to 1500 do ignore (String.create 256) done; + r + +(* Registration *) + +let _ = + Callback.register "fib" fib; + Callback.register "format_result" format_result diff --git a/test/Moretest/cmmain.c b/test/Moretest/cmmain.c new file mode 100644 index 0000000..87647ac --- /dev/null +++ b/test/Moretest/cmmain.c @@ -0,0 +1,22 @@ +/* Main program -- in C */ + +#include <stdlib.h> +#include <stdio.h> +#include <caml/callback.h> + +extern int fib(int n); +extern char * format_result(int n); + +int main(int argc, char ** argv) +{ + printf("Initializing Caml code...\n"); +#ifdef NO_BYTECODE_FILE + caml_startup(argv); +#else + caml_main(argv); +#endif + printf("Back in C code...\n"); + printf("Computing fib(20)...\n"); + printf("%s\n", format_result(fib(20))); + return 0; +} diff --git a/test/Moretest/cmstub.c b/test/Moretest/cmstub.c new file mode 100644 index 0000000..56cd694 --- /dev/null +++ b/test/Moretest/cmstub.c @@ -0,0 +1,17 @@ +#include <string.h> +#include <caml/mlvalues.h> +#include <caml/callback.h> + +/* Functions callable directly from C */ + +int fib(int n) +{ + value * fib_closure = caml_named_value("fib"); + return Int_val(callback(*fib_closure, Val_int(n))); +} + +char * format_result(int n) +{ + value * format_result_closure = caml_named_value("format_result"); + return strdup(String_val(callback(*format_result_closure, Val_int(n)))); +} diff --git a/test/Moretest/equality.ml b/test/Moretest/equality.ml new file mode 100644 index 0000000..ad6cb5f --- /dev/null +++ b/test/Moretest/equality.ml @@ -0,0 +1,80 @@ +let test n check res = + prerr_string "Test "; prerr_int n; + if check res then prerr_string " passed.\n" else prerr_string " FAILED.\n"; + flush stderr + +let eq0 = function 0 -> true | _ -> false +let eqm1 = function -1 -> true | _ -> false +let eq1 = function 1 -> true | _ -> false +let eqtrue (b:bool) = b +let eqftffff = + function (false,true,false,false,false,false) -> true | _ -> false + +let x = [1;2;3] + +let f x = 1 :: 2 :: 3 :: x + +let mklist len = + let l = ref [] in + for i = 1 to len do l := i :: !l done; + !l + +type tree = Dummy | Leaf | Node of tree * tree + +let rec mktree depth = + if depth <= 0 then Leaf else Node(mktree(depth - 1), mktree(depth - 1)) + +type 'a leftlist = Nil | Cons of 'a leftlist * 'a + +let mkleftlist len = + let l = ref Nil in + for i = 1 to len do l := Cons(!l, i) done; + !l + +let _ = + test 1 eq0 (compare 0 0); + test 2 eqm1 (compare 0 1); + test 3 eq1 (compare 1 0); + test 4 eq0 (compare max_int max_int); + test 5 eqm1 (compare min_int max_int); + test 6 eq1 (compare max_int min_int); + test 7 eq0 (compare "foo" "foo"); + test 8 eqm1 (compare "foo" "zorglub"); + test 9 eqm1 (compare "abcdef" "foo"); + test 10 eqm1 (compare "abcdefghij" "abcdefghijkl"); + test 11 eq1 (compare "abcdefghij" "abcdefghi"); + test 12 eq0 (compare (0,1) (0,1)); + test 13 eqm1 (compare (0,1) (0,2)); + test 14 eqm1 (compare (0,1) (1,0)); + test 15 eq1 (compare (0,1) (0,0)); + test 16 eq1 (compare (1,0) (0,1)); + test 17 eq0 (compare 0.0 0.0); + test 18 eqm1 (compare 0.0 1.0); + test 19 eqm1 (compare (-1.0) 0.0); + test 20 eq0 (compare [| 0.0; 1.0; 2.0 |] [| 0.0; 1.0; 2.0 |]); + test 21 eqm1 (compare [| 0.0; 1.0; 2.0 |] [| 0.0; 1.0; 3.0 |]); + test 22 eq1 (compare [| 0.0; 5.0; 2.0 |] [| 0.0; 1.0; 2.0 |]); + test 23 eq0 (compare [1;2;3;4] [1;2;3;4]); + test 24 eqm1 (compare [1;2;3;4] [1;2;5;6]); + test 25 eqm1 (compare [1;2;3;4] [1;2;3;4;5]); + test 26 eq1 (compare [1;2;3;4] [1;2;3]); + test 27 eq1 (compare [1;2;3;4] [1;2;0;4]); + test 28 eq0 (compare (mklist 1000) (mklist 1000)); + test 29 eq0 (compare (mkleftlist 1000) (mkleftlist 1000)); + test 30 eq0 (compare (mktree 12) (mktree 12)); + test 31 eqtrue (x = f []); + test 32 eqtrue (stdout <> stderr); + test 33 eqm1 (compare nan 0.0); + test 34 eqm1 (compare nan neg_infinity); + test 35 eq0 (compare nan nan); + test 36 eqm1 (compare (0.0, nan) (0.0, 0.0)); + test 37 eqm1 (compare (0.0, nan) (0.0, neg_infinity)); + test 38 eq0 (compare (nan, 0.0) (nan, 0.0)); + let cmpgen x y = (x=y, x<>y, x<y, x<=y, x>y, x>=y) in + let cmpfloat (x:float) (y:float) = (x=y, x<>y, x<y, x<=y, x>y, x>=y) in + test 39 eqftffff (cmpgen nan nan); + test 40 eqftffff (cmpgen nan 0.0); + test 41 eqftffff (cmpfloat nan nan); + test 42 eqftffff (cmpfloat nan 0.0); + test 43 eqtrue ([||] = [||]) + diff --git a/test/Moretest/fftba.ml b/test/Moretest/fftba.ml new file mode 100644 index 0000000..8543d81 --- /dev/null +++ b/test/Moretest/fftba.ml @@ -0,0 +1,191 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: fftba.ml,v 1.1 2000-03-10 14:54:41 xleroy Exp $ *) + +open Bigarray + +let pi = 3.14159265358979323846 + +let tpi = 2.0 *. pi + +let fft (px : (float, float64_elt, c_layout) Array1.t) + (py : (float, float64_elt, c_layout) Array1.t) np = + let i = ref 2 in + let m = ref 1 in + + while (!i < np) do + i := !i + !i; + m := !m + 1 + done; + + let n = !i in + + if n <> np then begin + for i = np+1 to n do + px.{i} <- 0.0; + py.{i} <- 0.0 + done; + print_string "Use "; print_int n; + print_string " point fft"; print_newline() + end; + + let n2 = ref(n+n) in + for k = 1 to !m-1 do + n2 := !n2 / 2; + let n4 = !n2 / 4 in + let e = tpi /. float !n2 in + + for j = 1 to n4 do + let a = e *. float(j - 1) in + let a3 = 3.0 *. a in + let cc1 = cos(a) in + let ss1 = sin(a) in + let cc3 = cos(a3) in + let ss3 = sin(a3) in + let is = ref j in + let id = ref(2 * !n2) in + + while !is < n do + let i0r = ref !is in + while !i0r < n do + let i0 = !i0r in + let i1 = i0 + n4 in + let i2 = i1 + n4 in + let i3 = i2 + n4 in + let r1 = px.{i0} -. px.{i2} in + px.{i0} <- px.{i0} +. px.{i2}; + let r2 = px.{i1} -. px.{i3} in + px.{i1} <- px.{i1} +. px.{i3}; + let s1 = py.{i0} -. py.{i2} in + py.{i0} <- py.{i0} +. py.{i2}; + let s2 = py.{i1} -. py.{i3} in + py.{i1} <- py.{i1} +. py.{i3}; + let s3 = r1 -. s2 in + let r1 = r1 +. s2 in + let s2 = r2 -. s1 in + let r2 = r2 +. s1 in + px.{i2} <- r1*.cc1 -. s2*.ss1; + py.{i2} <- -.s2*.cc1 -. r1*.ss1; + px.{i3} <- s3*.cc3 +. r2*.ss3; + py.{i3} <- r2*.cc3 -. s3*.ss3; + i0r := i0 + !id + done; + is := 2 * !id - !n2 + j; + id := 4 * !id + done + done + done; + +(************************************) +(* Last stage, length=2 butterfly *) +(************************************) + + let is = ref 1 in + let id = ref 4 in + + while !is < n do + let i0r = ref !is in + while !i0r <= n do + let i0 = !i0r in + let i1 = i0 + 1 in + let r1 = px.{i0} in + px.{i0} <- r1 +. px.{i1}; + px.{i1} <- r1 -. px.{i1}; + let r1 = py.{i0} in + py.{i0} <- r1 +. py.{i1}; + py.{i1} <- r1 -. py.{i1}; + i0r := i0 + !id + done; + is := 2 * !id - 1; + id := 4 * !id + done; + +(*************************) +(* Bit reverse counter *) +(*************************) + + let j = ref 1 in + + for i = 1 to n - 1 do + if i < !j then begin + let xt = px.{!j} in + px.{!j} <- px.{i}; + px.{i} <- xt; + let xt = py.{!j} in + py.{!j} <- py.{i}; + py.{i} <- xt + end; + let k = ref(n / 2) in + while !k < !j do + j := !j - !k; + k := !k / 2 + done; + j := !j + !k + done; + + n + + +let test np = + print_int np; print_string "... "; flush stdout; + let enp = float np in + let npm = np / 2 - 1 in + let pxr = Array1.create float64 c_layout (np+2) + and pxi = Array1.create float64 c_layout (np+2) in + let t = pi /. enp in + pxr.{1} <- (enp -. 1.0) *. 0.5; + pxi.{1} <- 0.0; + let n2 = np / 2 in + pxr.{n2+1} <- -0.5; + pxi.{n2+1} <- 0.0; + + for i = 1 to npm do + let j = np - i in + pxr.{i+1} <- -0.5; + pxr.{j+1} <- -0.5; + let z = t *. float i in + let y = -0.5 *. (cos(z)/.sin(z)) in + pxi.{i+1} <- y; + pxi.{j+1} <- -.y + done; +(** + print_newline(); + for i=0 to 15 do Printf.printf "%d %f %f\n" i pxr.{i+1} pxi.{i+1} done; +**) + let _ = fft pxr pxi np in +(** + for i=0 to 15 do Printf.printf "%d %f %f\n" i pxr.{i+1} pxi.{i+1} done; +**) + let zr = ref 0.0 in + let zi = ref 0.0 in + let kr = ref 0 in + let ki = ref 0 in + for i = 0 to np-1 do + let a = abs_float(pxr.{i+1} -. float i) in + if !zr < a then begin + zr := a; + kr := i + end; + let a = abs_float(pxi.{i+1}) in + if !zi < a then begin + zi := a; + ki := i + end + done; + let zm = if abs_float !zr < abs_float !zi then !zi else !zr in + print_float zm; print_newline() + + +let _ = + let np = ref 16 in for i = 1 to 13 do test !np; np := !np*2 done + diff --git a/test/Moretest/float.ml b/test/Moretest/float.ml new file mode 100644 index 0000000..9ebabbc --- /dev/null +++ b/test/Moretest/float.ml @@ -0,0 +1 @@ +Printf.printf "1./.0. = %f\n" (1.0 /. 0.0);; diff --git a/test/Moretest/float_record.ml b/test/Moretest/float_record.ml new file mode 100644 index 0000000..98d5323 --- /dev/null +++ b/test/Moretest/float_record.ml @@ -0,0 +1,7 @@ +type t = float;; + +let make f = f;; + +let from t = t;; + +type s = {f : t};; diff --git a/test/Moretest/float_record.mli b/test/Moretest/float_record.mli new file mode 100644 index 0000000..4e5970e --- /dev/null +++ b/test/Moretest/float_record.mli @@ -0,0 +1,6 @@ +type t = private float;; + +val make : float -> t;; +val from : t -> float;; + +type s = {f : t};; diff --git a/test/Moretest/globroots.ml b/test/Moretest/globroots.ml new file mode 100644 index 0000000..6d1948d --- /dev/null +++ b/test/Moretest/globroots.ml @@ -0,0 +1,80 @@ +module type GLOBREF = sig + type t + val register: string -> t + val get: t -> string + val set: t -> string -> unit + val remove: t -> unit +end + +module Classic : GLOBREF = struct + type t + external register: string -> t = "gb_classic_register" + external get: t -> string = "gb_get" + external set: t -> string -> unit = "gb_classic_set" + external remove: t -> unit = "gb_classic_remove" +end + +module Generational : GLOBREF = struct + type t + external register: string -> t = "gb_generational_register" + external get: t -> string = "gb_get" + external set: t -> string -> unit = "gb_generational_set" + external remove: t -> unit = "gb_generational_remove" +end + +module Test(G: GLOBREF) = struct + + let size = 1024 + + let vals = Array.init size string_of_int + + let a = Array.init size (fun i -> G.register (string_of_int i)) + + let check () = + for i = 0 to size - 1 do + if G.get a.(i) <> vals.(i) then begin + print_string "Error on "; print_int i; print_string ": "; + print_string (String.escaped (G.get a.(i))); print_newline() + end + done + + let change () = + match Random.int 37 with + | 0 -> + Gc.full_major() + | 1|2|3|4 -> + Gc.minor() + | 5|6|7|8|9|10|11|12 -> (* update with young value *) + let i = Random.int size in + G.set a.(i) (string_of_int i) + | 13|14|15|16|17|18|19|20 -> (* update with old value *) + let i = Random.int size in + G.set a.(i) vals.(i) + | 21|22|23|24|25|26|27|28 -> (* re-register young value *) + let i = Random.int size in + G.remove a.(i); + a.(i) <- G.register (string_of_int i) + | (*29|30|31|32|33|34|35|36*) _ -> (* re-register old value *) + let i = Random.int size in + G.remove a.(i); + a.(i) <- G.register vals.(i) + + let test n = + for i = 1 to n do + change(); + print_string "."; flush stdout + done +end + +module TestClassic = Test(Classic) +module TestGenerational = Test(Generational) + +let _ = + let n = + if Array.length Sys.argv < 2 then 10000 else int_of_string Sys.argv.(1) in + print_string "Non-generational API\n"; + TestClassic.test n; + print_newline(); + print_string "Generational API\n"; + TestGenerational.test n; + print_newline() diff --git a/test/Moretest/globrootsprim.c b/test/Moretest/globrootsprim.c new file mode 100644 index 0000000..f58fff1 --- /dev/null +++ b/test/Moretest/globrootsprim.c @@ -0,0 +1,56 @@ +/* For testing global root registration */ + +#include "mlvalues.h" +#include "memory.h" +#include "alloc.h" + +struct block { value v; }; + +#define Block_val(v) ((struct block *) (v)) + +value gb_get(value vblock) +{ + return Block_val(vblock)->v; +} + +value gb_classic_register(value v) +{ + struct block * b = stat_alloc(sizeof(struct block)); + b->v = v; + caml_register_global_root(&(b->v)); + return (value) b; +} + +value gb_classic_set(value vblock, value newval) +{ + Block_val(vblock)->v = newval; + return Val_unit; +} + +value gb_classic_remove(value vblock) +{ + caml_remove_global_root(&(Block_val(vblock)->v)); + return Val_unit; +} + +value gb_generational_register(value v) +{ + struct block * b = stat_alloc(sizeof(struct block)); + b->v = v; + caml_register_generational_global_root(&(b->v)); + return (value) b; +} + +value gb_generational_set(value vblock, value newval) +{ + caml_modify_generational_global_root(&(Block_val(vblock)->v), newval); + return Val_unit; +} + +value gb_generational_remove(value vblock) +{ + caml_remove_generational_global_root(&(Block_val(vblock)->v)); + return Val_unit; +} + + diff --git a/test/Moretest/graph_example.ml b/test/Moretest/graph_example.ml new file mode 100644 index 0000000..6fbe988 --- /dev/null +++ b/test/Moretest/graph_example.ml @@ -0,0 +1,131 @@ +(* To run this example: + ******************** + 1. Select all the text in this window. + 2. Drag it to the toplevel window. + 3. Watch the colors. + 4. Drag the mouse over the graphics window and click here and there. + 5. Type any key to the graphics window to stop the program. +*) + +open Graphics;; +open_graph " 480x270";; + +let xr = size_x () / 2 - 30 +and yr = size_y () / 2 - 26 +and xg = size_x () / 2 + 30 +and yg = size_y () / 2 - 26 +and xb = size_x () / 2 +and yb = size_y () / 2 + 26 +;; + +let point x y = + let dr = (x-xr)*(x-xr) + (y-yr)*(y-yr) + and dg = (x-xg)*(x-xg) + (y-yg)*(y-yg) + and db = (x-xb)*(x-xb) + (y-yb)*(y-yb) + in + if dr > dg && dr > db then set_color (rgb 255 (255*dg/dr) (255*db/dr)) + else if dg > db then set_color (rgb (255*dr/dg) 255 (255*db/dg)) + else set_color (rgb (255*dr/db) (255*dg/db) 255); + fill_rect x y 2 2; +;; + +for y = (size_y () - 1) / 2 downto 0 do + for x = 0 to (size_x () - 1) / 2 do + point (2*x) (2*y); + done +done +;; + +let n = 0x000000 +and w = 0xFFFFFF +and b = 0xFFCC99 +and y = 0xFFFF00 +and o = 0xCC9966 +and v = 0x00BB00 +and g = 0x888888 +and c = 0xDDDDDD +and t = transp +;; + +let caml = make_image [| + [|t;t;t;t;t;t;t;t;t;t;t;n;n;n;n;n;n;t;t;t;t;t;t;t;t;t;t;t;t;t;t;t;|]; + [|t;t;t;t;t;t;t;t;t;t;n;n;n;n;n;n;n;n;n;t;t;t;t;t;t;t;t;t;t;t;t;t;|]; + [|t;t;t;t;t;t;t;t;n;n;n;n;n;n;n;n;n;n;n;n;t;t;t;t;t;t;t;t;t;t;t;t;|]; + [|n;n;n;n;n;n;t;n;n;n;n;n;b;b;b;b;b;b;b;n;n;t;t;t;t;t;n;n;n;n;n;t;|]; + [|n;o;o;o;o;o;n;n;n;n;b;b;b;b;b;b;b;b;b;b;b;n;n;n;n;n;n;n;n;n;n;t;|]; + [|n;o;o;o;o;o;o;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;t;|]; + [|n;o;o;o;o;o;o;o;n;n;n;g;g;g;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;t;t;|]; + [|n;n;o;o;o;o;o;o;o;n;n;n;c;c;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;t;t;|]; + [|t;n;n;o;o;o;o;o;o;o;n;n;n;c;n;n;n;n;n;n;n;b;b;n;n;n;n;n;n;t;t;t;|]; + [|t;t;n;n;n;o;o;o;o;o;o;n;n;n;n;n;n;n;n;n;b;b;b;b;n;n;n;n;t;t;t;t;|]; + [|t;t;t;t;n;n;o;o;o;o;o;o;n;n;n;n;n;n;n;n;b;b;b;b;b;b;n;n;t;t;t;t;|]; + [|t;t;t;t;t;n;n;o;o;o;o;o;o;n;n;n;n;n;n;o;o;b;b;b;b;b;b;n;n;t;t;t;|]; + [|t;t;t;t;t;n;n;o;o;o;o;o;o;b;b;b;b;b;n;n;o;o;b;b;b;b;b;b;n;n;t;t;|]; + [|t;t;t;t;n;n;n;o;o;o;o;o;b;b;b;b;b;b;b;n;n;o;o;b;b;b;b;b;b;n;n;t;|]; + [|t;t;t;t;n;n;n;o;o;o;o;b;b;b;b;b;b;b;b;b;n;n;o;o;b;b;b;b;b;b;n;n;|]; + [|t;t;t;t;n;n;n;o;o;o;o;b;b;b;b;b;n;n;b;b;b;n;n;o;o;b;b;b;b;b;n;n;|]; + [|t;t;t;t;n;n;n;o;o;o;o;b;b;b;b;b;n;n;b;b;b;b;n;n;o;o;b;o;b;b;n;n;|]; + [|t;t;t;t;n;n;n;o;o;o;o;b;b;b;b;b;n;n;b;b;b;b;b;n;n;o;o;o;o;o;n;n;|]; + [|t;t;t;t;n;n;n;o;o;o;o;b;b;b;b;b;n;n;b;b;b;b;b;b;n;n;o;o;o;o;n;n;|]; + [|t;t;t;t;n;n;n;o;o;o;o;o;b;b;b;b;n;n;b;b;b;b;b;b;b;n;n;o;o;n;n;n;|]; + [|t;t;t;t;n;n;n;n;o;o;o;o;o;b;b;b;n;n;n;b;b;b;b;b;b;b;n;n;o;n;b;n;|]; + [|t;t;t;t;t;n;n;n;o;o;o;o;o;o;b;b;n;n;n;b;b;b;b;b;b;b;b;n;n;n;b;n;|]; + [|t;t;t;t;t;t;n;n;o;o;o;o;o;o;o;y;v;y;n;b;b;b;b;b;b;b;b;n;n;b;b;n;|]; + [|t;t;t;t;t;t;t;n;o;o;o;o;o;v;y;o;o;n;n;n;b;b;b;b;b;b;b;n;n;b;b;n;|]; + [|t;t;t;t;t;t;t;n;o;o;o;y;v;o;o;o;o;n;n;n;n;b;b;b;b;b;b;n;n;b;b;n;|]; + [|t;t;t;t;t;t;n;n;o;v;y;o;y;o;o;o;o;o;o;n;n;n;b;b;b;b;b;n;n;b;b;n;|]; + [|t;t;t;t;t;t;n;o;y;y;o;o;v;o;o;o;o;o;o;o;n;n;n;b;b;b;n;n;n;b;n;t;|]; + [|t;t;t;t;t;n;n;v;o;v;o;o;o;o;o;o;o;o;o;o;o;n;n;n;b;n;n;n;n;b;n;t;|]; + [|t;t;t;t;t;n;v;o;o;v;o;o;o;o;o;o;o;o;o;o;o;o;n;n;n;n;n;n;n;n;t;t;|]; + [|t;t;t;t;n;n;o;o;o;o;o;o;o;o;o;o;o;o;o;o;o;n;n;n;n;n;n;t;t;t;t;t;|]; + [|t;t;t;t;n;o;o;o;o;o;o;o;o;o;o;o;o;o;o;o;n;n;t;t;t;t;t;t;t;t;t;t;|]; + [|t;t;t;t;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;n;t;t;t;t;t;t;t;t;t;t;t;|]; +|];; + +(* +let x = ref 0 and y = ref 0;; +let bg = get_image !x !y 32 32;; +while true do + let st = wait_next_event [Mouse_motion; Button_down] in + if not st.button then draw_image bg !x !y; + x := st.mouse_x; + y := st.mouse_y; + blit_image bg !x !y; + draw_image caml !x !y; +done;; +*) +set_color (rgb 0 0 0); +remember_mode false; +try while true do + let st = wait_next_event [Mouse_motion; Button_down; Key_pressed] in + synchronize (); + if st.keypressed then raise Exit; + if st.button then begin + remember_mode true; + draw_image caml st.mouse_x st.mouse_y; + remember_mode false; + end; + let x = st.mouse_x + 16 and y = st.mouse_y + 16 in + + moveto 0 y; + lineto (x - 25) y; + moveto 10000 y; + lineto (x + 25) y; + + moveto x 0; + lineto x (y - 25); + moveto x 10000; + lineto x (y + 25); + + draw_image caml st.mouse_x st.mouse_y; +done with Exit -> () +;; + +(* To run this example: + ******************** + 1. Select all the text in this window. + 2. Drag it to the toplevel window. + 3. Watch the colors. + 4. Drag the mouse over the graphics window and click here and there. + 5. Type any key to the graphics window to stop the program. +*) diff --git a/test/Moretest/graph_test.ml b/test/Moretest/graph_test.ml new file mode 100644 index 0000000..cd4c081 --- /dev/null +++ b/test/Moretest/graph_test.ml @@ -0,0 +1,288 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../../LICENSE. *) +(* *) +(***********************************************************************) + +(* graph_test.ml : tests various drawing and filling primitives of the + Graphics library. *) + +(* To run this example just load this file into a suitable toplevel. + Alternatively execute + ocamlc graphics.cma graph_test.ml *) + +open Graphics;; + +auto_synchronize false;; +display_mode false;; +remember_mode true;; + +let sz = 450;; + +open_graph (Printf.sprintf " %ix%i" sz sz);; + +(* To be defined for older versions of O'Caml + Lineto, moveto and draw_rect. + +let rlineto x y = + let xc, yc = current_point () in + lineto (x + xc) (y + yc);; + +let rmoveto x y = + let xc, yc = current_point () in + moveto (x + xc) (y + yc);; + +let draw_rect x y w h = + let x0, y0 = current_point () in + moveto x y; + rlineto w 0; + rlineto 0 h; + rlineto (- w) 0; + rlineto 0 (-h); + moveto x0 y0;; +*) + +(* A set of points. *) + +set_color foreground;; + +let dashes y = + for i = 1 to 100 do + plot y (2 * i); + plot y (3 * i); + plot y (4 * i); + done;; + +dashes 3;; + +set_line_width 20;; +dashes (sz - 20);; + +(* Drawing chars *) + +draw_char 'C'; +draw_char 'a'; +draw_char 'm'; +draw_char 'l';; + +(* More and more red enlarging squares *) +moveto 10 10;; +set_line_width 5;; + +let carre c = + rlineto 0 c; + rlineto c 0; + rlineto 0 (- c); + rlineto (- c) 0;; + +for i = 1 to 10 do + moveto (10 * i) (10 * i); + set_color (rgb (155 + 10 * i) 0 0); + carre (10 * i) +done;; + +(* Blue squares in arithmetic progression *) +moveto 10 210;; +set_color blue;; +set_line_width 1;; + +for i = 1 to 10 do + carre (10 * i) +done;; + +(* Tiny circles filled or not *) +rmoveto 0 120;; +(* Must not change the current point *) +fill_circle 20 190 10;; +set_color green;; +rlineto 0 10;; +rmoveto 50 10;; +let x, y = current_point () in +(* Must not change the current point *) +draw_circle x y 20;; +set_color black;; +rlineto 0 20;; + +(* Cyan rectangles as a kind of graphical representation *) +set_color cyan;; + +let lw = 15;; +set_line_width lw;; +let go_caption l = moveto 210 (130 - lw + l);; +let go_legend () = go_caption (- 3 * lw);; + +go_caption 0;; +fill_rect 210 130 5 10;; +fill_rect 220 130 10 20;; +fill_rect 235 130 15 40;; +fill_rect 255 130 20 80;; +fill_rect 280 130 25 160;; +(* A green rectangle below the graph. *) +set_color green;; +rlineto 50 0;; + +(* A black frame for each of our rectangles *) +set_color black;; +set_line_width (lw / 4);; + +draw_rect 210 130 5 10;; +draw_rect 220 130 10 20;; +draw_rect 235 130 15 40;; +draw_rect 255 130 20 80;; +draw_rect 280 130 25 160;; + +(* A black rectangle after the green one, below the graph. *) +set_line_width lw;; +rlineto 50 0;; + +(* Write a text in yellow on a blue background. *) +(* x = 210, y = 70 *) +go_legend ();; +set_text_size 10;; +set_color (rgb 150 100 250);; +let x,y = current_point () in +fill_rect x (y - 5) (8 * 20) 25;; +set_color yellow;; +go_legend ();; +draw_string "Graphics (Caml)";; + +(* Pie parts in different colors. *) +let draw_green_string s = set_color green; draw_string s;; +let draw_red_string s = set_color red; draw_string s;; + +moveto 120 210;; +set_color red;; +fill_arc 150 260 25 25 60 300; +draw_green_string "A "; +draw_red_string "red"; +draw_green_string " pie."; + +set_text_size 5; +moveto 180 240; +draw_red_string "A "; draw_green_string "green"; draw_red_string " slice.";; +set_color green; +fill_arc 200 260 25 25 0 60; +set_color black; +set_line_width 2; +draw_arc 200 260 27 27 0 60;; + +(* Should do nothing since this is a line *) +set_color red;; +fill_poly [| (40, 10); (150, 70); (150, 10); (40, 10) |];; +set_color blue;; + +(* Drawing polygones. *) +(* Redefining the draw_poly primitive for the usual library. *) +let draw_poly v = + let l = Array.length v in + if l > 0 then begin + let x0, y0 = current_point () in + let p0 = v.(0) in + let x, y = p0 in moveto x y; + for i = 1 to l - 1 do + let x, y = v.(i) in lineto x y + done; + lineto x y; + moveto x0 y0 + end;; + +draw_poly [| (150, 10); (150, 70); (260, 10); (150, 10) |];; + +(* Filling polygones. *) +(* Two equilateral triangles, one red and one blue, and their inside + filled in black. *) +let equi x y l = + [| (x - l / 2, y); + (x, y + int_of_float (float_of_int l *. (sqrt 3.0 /. 2.0))); + (x + l / 2, y) |];; + +set_color black;; +fill_poly (Array.append (equi 300 20 40) (equi 300 44 (- 40)));; + +set_line_width 1;; +set_color cyan;; +draw_poly (equi 300 20 40);; +set_color red;; +draw_poly (equi 300 44 (- 40));; + +(* Drawing and filling ellipses. *) +let x, y = current_point () in +rlineto 10 10; moveto x y; + +moveto 395 100;; + +let x, y = current_point () in +fill_ellipse x y 25 15;; + +set_color (rgb 0xFF 0x00 0xFF);; +rmoveto 0 (- 50);; + +let x, y = current_point () in +fill_ellipse x y 15 30;; + +rmoveto (- 45) 0;; +let x, y = current_point () in +draw_ellipse x y 25 10;; + +(* Drawing and filling arcs. *) + +let draw_arc_ellipse x y r1 r2 = + set_color green; + draw_arc x y r1 r2 60 120; + set_color black; + draw_arc x y r1 r2 120 420;; + +set_line_width 3;; + +let draw_arc_ellipses x y r1 r2 = + let step = 5 in + for i = 0 to (r1 - step) / (2 * step) do + for j = 0 to (r2 - step) / (2 * step) do + draw_arc_ellipse x y (3 * i * step) (3 * j * step) + done + done;; + +draw_arc_ellipses 20 128 15 50;; + +let fill_arc_ellipse x y r1 r2 c1 c2 = + set_color c1; + fill_arc x y r1 r2 60 120; + set_color c2; + fill_arc x y r1 r2 120 420;; + +let fill_arc_ellipses x y r1 r2 = + let step = 3 in + let c1 = ref black + and c2 = ref yellow in + let exchange r1 r2 = let tmp = !r1 in r1 := !r2; r2 := tmp in + for i = r1 / (2 * step) downto 10 do + for j = r2 / (2 * step) downto 30 do + exchange c1 c2; + fill_arc_ellipse x y (3 * i) (3 * j) !c1 !c2 + done + done;; + +fill_arc_ellipses 400 240 150 200;; + + +synchronize ();; + +(* transparent color drawing *) +set_color transp;; +draw_circle 400 240 50;; +draw_circle 400 240 40;; +draw_circle 400 240 30;; +(* try to go back a normal color *) +set_color red;; +draw_circle 400 240 20;; + +synchronize ();; + +input_line stdin;; diff --git a/test/Moretest/includestruct.ml b/test/Moretest/includestruct.ml new file mode 100644 index 0000000..182272c --- /dev/null +++ b/test/Moretest/includestruct.ml @@ -0,0 +1,92 @@ +(* Test for "include <module-expr>" inside structures *) + +module A = + struct + type t = int + let x = (1 : t) + let y = (2 : t) + let f (z : t) = (x + z : t) + end + +module B = + struct + include A + type u = t * t + let p = ((x, y) : u) + let g ((x, y) : u) = ((f x, f y) : u) + end + +let _ = + let print_pair (x,y) = + print_int x; print_string ", "; print_int y; print_newline() in + print_pair B.p; + print_pair (B.g B.p); + print_pair (B.g (123, 456)) + +module H = + struct + include A + let f (z : t) = (x - 1 : t) + end + +let _ = + print_int (H.f H.x); print_newline() + +module C = + struct + include (A : sig type t val f : t -> int val x : t end) + let z = f x + end + +let _ = + print_int C.z; print_newline(); + print_int (C.f C.x); print_newline() + +(* Toplevel inclusion *) + +include A + +let _ = + print_int x; print_newline(); + print_int (f y); print_newline() + +(* With a functor *) + +module F(X: sig end) = + struct + let _ = print_string "F is called"; print_newline() + type t = A | B of int + let print_t = function A -> print_string "A" + | B x -> print_int x + end + +module D = + struct + include F(struct end) + let test() = print_t A; print_newline(); print_t (B 42); print_newline() + end + +let _ = + D.test(); + D.print_t D.A; print_newline(); D.print_t (D.B 42); print_newline() + +(* Exceptions and classes *) + +module E = + struct + exception Exn of string + class c = object method m = 1 end + end + +module G = + struct + include E + let _ = + begin try raise (Exn "foo") with Exn s -> print_string s end; + print_int ((new c)#m); print_newline() + end + +let _ = + begin try raise (G.Exn "foo") with G.Exn s -> print_string s end; + print_int ((new G.c)#m); print_newline() + diff --git a/test/Moretest/intext.ml b/test/Moretest/intext.ml new file mode 100644 index 0000000..035f645 --- /dev/null +++ b/test/Moretest/intext.ml @@ -0,0 +1,459 @@ +(* Test for output_value / input_value *) + +type t = A | B of int | C of float | D of string | E of char + | F of t | G of t * t | H of int * t | I of t * float | J + +let longstring = +"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +let verylongstring = +"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + +let bigint = Int64.to_int 0x123456789ABCDEF0L + +let rec fib n = + if n < 2 then 1 else fib(n-1) + fib(n-2) + +let test_out filename = + let oc = open_out_bin filename in + output_value oc 1; + output_value oc (-1); + output_value oc 258; + output_value oc 20000; + output_value oc 0x12345678; + output_value oc bigint; + output_value oc "foobargeebuz"; + output_value oc longstring; + output_value oc verylongstring; + output_value oc 3.141592654; + output_value oc (); + output_value oc A; + output_value oc (B 1); + output_value oc (C 2.718); + output_value oc (D "hello, world!"); + output_value oc (E 'l'); + output_value oc (F(B 1)); + output_value oc (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))); + output_value oc (H(1, A)); + output_value oc (I(B 2, 1e-6)); + let x = D "sharing" in + let y = G(x, x) in + let z = G(y, G(x, y)) in + output_value oc z; + output_value oc [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|]; + let rec big n = if n <= 0 then A else H(n, big(n-1)) in + output_value oc (big 1000); + Marshal.to_channel oc y [Marshal.No_sharing]; + Marshal.to_channel oc fib [Marshal.Closures]; + output_value oc (Int32.of_string "0"); + output_value oc (Int32.of_string "123456"); + output_value oc (Int32.of_string "-123456"); + output_value oc (Int64.of_string "0"); + output_value oc (Int64.of_string "123456789123456"); + output_value oc (Int64.of_string "-123456789123456"); + output_value oc (Nativeint.of_string "0"); + output_value oc (Nativeint.of_string "123456"); + output_value oc (Nativeint.of_string "-123456"); + output_value oc (Nativeint.shift_left (Nativeint.of_string "123456789") 32); + output_value oc (Nativeint.shift_left (Nativeint.of_string "-123456789") 32); + let i = Int64.of_string "123456789123456" in output_value oc (i,i); + close_out oc + + +let test n b = + prerr_string "Test "; prerr_int n; + if b then prerr_string " passed.\n" else prerr_string " FAILED.\n"; + flush stderr + +let test_in filename = + let ic = open_in_bin filename in + test 1 (input_value ic = 1); + test 2 (input_value ic = (-1)); + test 3 (input_value ic = 258); + test 4 (input_value ic = 20000); + test 5 (input_value ic = 0x12345678); + test 6 (input_value ic = bigint); + test 7 (input_value ic = "foobargeebuz"); + test 8 (input_value ic = longstring); + test 9 (input_value ic = verylongstring); + test 10 (input_value ic = 3.141592654); + test 11 (input_value ic = ()); + test 12 (match input_value ic with + A -> true + | _ -> false); + test 13 (match input_value ic with + (B 1) -> true + | _ -> false); + test 14 (match input_value ic with + (C f) -> f = 2.718 + | _ -> false); + test 15 (match input_value ic with + (D "hello, world!") -> true + | _ -> false); + test 16 (match input_value ic with + (E 'l') -> true + | _ -> false); + test 17 (match input_value ic with + (F(B 1)) -> true + | _ -> false); + test 18 (match input_value ic with + (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) -> true + | _ -> false); + test 19 (match input_value ic with + (H(1, A)) -> true + | _ -> false); + test 20 (match input_value ic with + (I(B 2, 1e-6)) -> true + | _ -> false); + test 21 (match input_value ic with + G((G((D "sharing" as t1), t2) as t3), G(t4, t5)) -> + t1 == t2 && t3 == t5 && t4 == t1 + | _ -> false); + test 22 (input_value ic = [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|]); + let rec check_big n t = + if n <= 0 then + test 23 (match t with A -> true | _ -> false) + else + match t with H(m, s) -> if m = n then check_big (n-1) s + else test 23 false + | _ -> test 23 false + in + check_big 1000 (input_value ic); + test 24 (match input_value ic with + G((D "sharing" as t1), (D "sharing" as t2)) -> t1 != t2 + | _ -> false); + test 25 (let fib = (input_value ic : int -> int) in fib 5 = 8 && fib 10 = 89); + test 26 (input_value ic = Int32.of_string "0"); + test 27 (input_value ic = Int32.of_string "123456"); + test 28 (input_value ic = Int32.of_string "-123456"); + test 29 (input_value ic = Int64.of_string "0"); + test 30 (input_value ic = Int64.of_string "123456789123456"); + test 31 (input_value ic = Int64.of_string "-123456789123456"); + test 32 (input_value ic = Nativeint.of_string "0"); + test 33 (input_value ic = Nativeint.of_string "123456"); + test 34 (input_value ic = Nativeint.of_string "-123456"); + test 35 (input_value ic = + Nativeint.shift_left (Nativeint.of_string "123456789") 32); + test 36 (input_value ic = + Nativeint.shift_left (Nativeint.of_string "-123456789") 32); + let ((i, j) : int64 * int64) = input_value ic in + test 37 (i = Int64.of_string "123456789123456"); + test 38 (j = Int64.of_string "123456789123456"); + test 39 (i == j); + close_in ic + +let test_string () = + let s = Marshal.to_string 1 [] in + test 101 (Marshal.from_string s 0 = 1); + let s = Marshal.to_string (-1) [] in + test 102 (Marshal.from_string s 0 = (-1)); + let s = Marshal.to_string 258 [] in + test 103 (Marshal.from_string s 0 = 258); + let s = Marshal.to_string 20000 [] in + test 104 (Marshal.from_string s 0 = 20000); + let s = Marshal.to_string 0x12345678 [] in + test 105 (Marshal.from_string s 0 = 0x12345678); + let s = Marshal.to_string bigint [] in + test 106 (Marshal.from_string s 0 = bigint); + let s = Marshal.to_string "foobargeebuz" [] in + test 107 (Marshal.from_string s 0 = "foobargeebuz"); + let s = Marshal.to_string longstring [] in + test 108 (Marshal.from_string s 0 = longstring); + let s = Marshal.to_string verylongstring [] in + test 109 (Marshal.from_string s 0 = verylongstring); + let s = Marshal.to_string 3.141592654 [] in + test 110 (Marshal.from_string s 0 = 3.141592654); + let s = Marshal.to_string () [] in + test 111 (Marshal.from_string s 0 = ()); + let s = Marshal.to_string A [] in + test 112 (match Marshal.from_string s 0 with + A -> true + | _ -> false); + let s = Marshal.to_string (B 1) [] in + test 113 (match Marshal.from_string s 0 with + (B 1) -> true + | _ -> false); + let s = Marshal.to_string (C 2.718) [] in + test 114 (match Marshal.from_string s 0 with + (C f) -> f = 2.718 + | _ -> false); + let s = Marshal.to_string (D "hello, world!") [] in + test 115 (match Marshal.from_string s 0 with + (D "hello, world!") -> true + | _ -> false); + let s = Marshal.to_string (E 'l') [] in + test 116 (match Marshal.from_string s 0 with + (E 'l') -> true + | _ -> false); + let s = Marshal.to_string (F(B 1)) [] in + test 117 (match Marshal.from_string s 0 with + (F(B 1)) -> true + | _ -> false); + let s = Marshal.to_string (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) [] in + test 118 (match Marshal.from_string s 0 with + (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) -> true + | _ -> false); + let s = Marshal.to_string (H(1, A)) [] in + test 119 (match Marshal.from_string s 0 with + (H(1, A)) -> true + | _ -> false); + let s = Marshal.to_string (I(B 2, 1e-6)) [] in + test 120 (match Marshal.from_string s 0 with + (I(B 2, 1e-6)) -> true + | _ -> false); + let x = D "sharing" in + let y = G(x, x) in + let z = G(y, G(x, y)) in + let s = Marshal.to_string z [] in + test 121 (match Marshal.from_string s 0 with + G((G((D "sharing" as t1), t2) as t3), G(t4, t5)) -> + t1 == t2 && t3 == t5 && t4 == t1 + | _ -> false); + let s = Marshal.to_string [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|] [] in + test 122 (Marshal.from_string s 0 = [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|]); + let rec big n = if n <= 0 then A else H(n, big(n-1)) in + let s = Marshal.to_string (big 1000) [] in + let rec check_big n t = + if n <= 0 then + test 123 (match t with A -> true | _ -> false) + else + match t with H(m, s) -> if m = n then check_big (n-1) s + else test 123 false + | _ -> test 123 false + in + check_big 1000 (Marshal.from_string s 0) + +let marshal_to_buffer s start len v flags = + ignore (Marshal.to_buffer s start len v flags) +;; + +let test_buffer () = + let s = String.create 512 in + marshal_to_buffer s 0 512 1 []; + test 201 (Marshal.from_string s 0 = 1); + marshal_to_buffer s 0 512 (-1) []; + test 202 (Marshal.from_string s 0 = (-1)); + marshal_to_buffer s 0 512 258 []; + test 203 (Marshal.from_string s 0 = 258); + marshal_to_buffer s 0 512 20000 []; + test 204 (Marshal.from_string s 0 = 20000); + marshal_to_buffer s 0 512 0x12345678 []; + test 205 (Marshal.from_string s 0 = 0x12345678); + marshal_to_buffer s 0 512 bigint []; + test 206 (Marshal.from_string s 0 = bigint); + marshal_to_buffer s 0 512 "foobargeebuz" []; + test 207 (Marshal.from_string s 0 = "foobargeebuz"); + marshal_to_buffer s 0 512 longstring []; + test 208 (Marshal.from_string s 0 = longstring); + test 209 + (try marshal_to_buffer s 0 512 verylongstring []; false + with Failure "Marshal.to_buffer: buffer overflow" -> true); + marshal_to_buffer s 0 512 3.141592654 []; + test 210 (Marshal.from_string s 0 = 3.141592654); + marshal_to_buffer s 0 512 () []; + test 211 (Marshal.from_string s 0 = ()); + marshal_to_buffer s 0 512 A []; + test 212 (match Marshal.from_string s 0 with + A -> true + | _ -> false); + marshal_to_buffer s 0 512 (B 1) []; + test 213 (match Marshal.from_string s 0 with + (B 1) -> true + | _ -> false); + marshal_to_buffer s 0 512 (C 2.718) []; + test 214 (match Marshal.from_string s 0 with + (C f) -> f = 2.718 + | _ -> false); + marshal_to_buffer s 0 512 (D "hello, world!") []; + test 215 (match Marshal.from_string s 0 with + (D "hello, world!") -> true + | _ -> false); + marshal_to_buffer s 0 512 (E 'l') []; + test 216 (match Marshal.from_string s 0 with + (E 'l') -> true + | _ -> false); + marshal_to_buffer s 0 512 (F(B 1)) []; + test 217 (match Marshal.from_string s 0 with + (F(B 1)) -> true + | _ -> false); + marshal_to_buffer s 0 512 (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) []; + test 218 (match Marshal.from_string s 0 with + (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) -> true + | _ -> false); + marshal_to_buffer s 0 512 (H(1, A)) []; + test 219 (match Marshal.from_string s 0 with + (H(1, A)) -> true + | _ -> false); + marshal_to_buffer s 0 512 (I(B 2, 1e-6)) []; + test 220 (match Marshal.from_string s 0 with + (I(B 2, 1e-6)) -> true + | _ -> false); + let x = D "sharing" in + let y = G(x, x) in + let z = G(y, G(x, y)) in + marshal_to_buffer s 0 512 z []; + test 221 (match Marshal.from_string s 0 with + G((G((D "sharing" as t1), t2) as t3), G(t4, t5)) -> + t1 == t2 && t3 == t5 && t4 == t1 + | _ -> false); + marshal_to_buffer s 0 512 [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|] []; + test 222 (Marshal.from_string s 0 = [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|]); + let rec big n = if n <= 0 then A else H(n, big(n-1)) in + test 223 + (try marshal_to_buffer s 0 512 (big 1000) []; false + with Failure "Marshal.to_buffer: buffer overflow" -> true) + +let test_size() = + let s = Marshal.to_string (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) [] in + test 300 (Marshal.header_size + Marshal.data_size s 0 = String.length s) + +external marshal_to_block + : string -> int -> 'a -> Marshal.extern_flags list -> unit + = "marshal_to_block" +external marshal_from_block : string -> int -> 'a = "marshal_from_block" +external static_alloc : int -> string = "caml_static_alloc" + +let test_block () = + let s = static_alloc 512 in + marshal_to_block s 512 1 []; + test 401 (marshal_from_block s 512 = 1); + marshal_to_block s 512 (-1) []; + test 402 (marshal_from_block s 512 = (-1)); + marshal_to_block s 512 258 []; + test 403 (marshal_from_block s 512 = 258); + marshal_to_block s 512 20000 []; + test 404 (marshal_from_block s 512 = 20000); + marshal_to_block s 512 0x12345678 []; + test 405 (marshal_from_block s 512 = 0x12345678); + marshal_to_block s 512 bigint []; + test 406 (marshal_from_block s 512 = bigint); + marshal_to_block s 512 "foobargeebuz" []; + test 407 (marshal_from_block s 512 = "foobargeebuz"); + marshal_to_block s 512 longstring []; + test 408 (marshal_from_block s 512 = longstring); + test 409 + (try marshal_to_block s 512 verylongstring []; false + with Failure "Marshal.to_buffer: buffer overflow" -> true); + marshal_to_block s 512 3.141592654 []; + test 410 (marshal_from_block s 512 = 3.141592654); + marshal_to_block s 512 () []; + test 411 (marshal_from_block s 512 = ()); + marshal_to_block s 512 A []; + test 412 (match marshal_from_block s 512 with + A -> true + | _ -> false); + marshal_to_block s 512 (B 1) []; + test 413 (match marshal_from_block s 512 with + (B 1) -> true + | _ -> false); + marshal_to_block s 512 (C 2.718) []; + test 414 (match marshal_from_block s 512 with + (C f) -> f = 2.718 + | _ -> false); + marshal_to_block s 512 (D "hello, world!") []; + test 415 (match marshal_from_block s 512 with + (D "hello, world!") -> true + | _ -> false); + marshal_to_block s 512 (E 'l') []; + test 416 (match marshal_from_block s 512 with + (E 'l') -> true + | _ -> false); + marshal_to_block s 512 (F(B 1)) []; + test 417 (match marshal_from_block s 512 with + (F(B 1)) -> true + | _ -> false); + marshal_to_block s 512 (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) []; + test 418 (match marshal_from_block s 512 with + (G(A, G(B 2, G(C 3.14, G(D "glop", E 'e'))))) -> true + | _ -> false); + marshal_to_block s 512 (H(1, A)) []; + test 419 (match marshal_from_block s 512 with + (H(1, A)) -> true + | _ -> false); + marshal_to_block s 512 (I(B 2, 1e-6)) []; + test 420 (match marshal_from_block s 512 with + (I(B 2, 1e-6)) -> true + | _ -> false); + let x = D "sharing" in + let y = G(x, x) in + let z = G(y, G(x, y)) in + marshal_to_block s 512 z []; + test 421 (match marshal_from_block s 512 with + G((G((D "sharing" as t1), t2) as t3), G(t4, t5)) -> + t1 == t2 && t3 == t5 && t4 == t1 + | _ -> false); + marshal_to_block s 512 [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|] []; + test 422 (marshal_from_block s 512 = + [|1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16|]); + let rec big n = if n <= 0 then A else H(n, big(n-1)) in + test 423 + (try marshal_to_block s 512 (big 1000) []; false + with Failure _ -> true); + test 424 + (try marshal_to_block s 512 "Hello, world!" []; + ignore (marshal_from_block s 8); + false + with Failure _ -> true) + +(* Test for really big objects *) + +let counter = ref 0 + +let rec make_big n = + if n <= 0 then begin + incr counter; B !counter + end else begin + let l = make_big (n-1) in + let r = make_big (n-1) in + G(l, r) + end + +let rec check_big n x = + if n <= 0 then begin + match x with + B k -> incr counter; k = !counter + | _ -> false + end else begin + match x with + G(l, r) -> check_big (n-1) l && check_big (n-1) r + | _ -> false + end + +let main() = + if Array.length Sys.argv <= 2 then begin + test_out "intext.data"; test_in "intext.data"; + test_out "intext.data"; test_in "intext.data"; + Sys.remove "intext.data"; + test_string(); + test_buffer(); + test_size(); + test_block() + end else + if Sys.argv.(1) = "make" then begin + let n = int_of_string Sys.argv.(2) in + let oc = open_out_bin "intext.data" in + counter := 0; + output_value oc (make_big n); + close_out oc + end else + if Sys.argv.(1) = "test" then begin + let n = int_of_string Sys.argv.(2) in + let ic = open_in_bin "intext.data" in + let b = (input_value ic : t) in + Gc.full_major(); + close_in ic; + counter := 0; + if check_big n b then + Printf.printf "Test big %d passed" n + else + Printf.printf "Test big %d FAILED" n; + print_newline() + end + +let _ = Printexc.catch main (); exit 0 diff --git a/test/Moretest/intextaux.c b/test/Moretest/intextaux.c new file mode 100644 index 0000000..9225b90 --- /dev/null +++ b/test/Moretest/intextaux.c @@ -0,0 +1,13 @@ +#include <mlvalues.h> +#include <intext.h> + +value marshal_to_block(value vbuf, value vlen, value v, value vflags) +{ + return Val_long(output_value_to_block(v, vflags, + (char *) vbuf, Long_val(vlen))); +} + +value marshal_from_block(value vbuf, value vlen) +{ + return input_value_from_block((char *) vbuf, Long_val(vlen)); +} diff --git a/test/Moretest/io.ml b/test/Moretest/io.ml new file mode 100644 index 0000000..f843e70 --- /dev/null +++ b/test/Moretest/io.ml @@ -0,0 +1,103 @@ +(* Test a file copy function *) + +let test msg funct f1 f2 = + print_string msg; print_newline(); + funct f1 f2; + if Sys.command ("cmp " ^ f1 ^ " " ^ f2) = 0 + then print_string "passed" + else print_string "FAILED"; + print_newline() + +(* File copy with constant-sized chunks *) + +let copy_file sz infile ofile = + let ic = open_in infile in + let oc = open_out ofile in + let buffer = String.create sz in + let rec copy () = + let n = input ic buffer 0 sz in + if n = 0 then () else begin + output oc buffer 0 n; + copy () + end in + copy(); + close_in ic; + close_out oc + +(* File copy with random-sized chunks *) + +let copy_random sz infile ofile = + let ic = open_in infile in + let oc = open_out ofile in + let buffer = String.create sz in + let rec copy () = + let s = 1 + Random.int sz in + let n = input ic buffer 0 s in + if n = 0 then () else begin + output oc buffer 0 n; + copy () + end in + copy(); + close_in ic; + close_out oc + +(* File copy line per line *) + +let copy_line infile ofile = + let ic = open_in infile in + let oc = open_out ofile in + try + while true do + output_string oc (input_line ic); output_char oc '\n' + done + with End_of_file -> + close_in ic; + close_out oc + +(* Backward copy, with lots of seeks *) + +let copy_seek chunksize infile ofile = + let ic = open_in_bin infile in + let oc = open_out_bin ofile in + let size = in_channel_length ic in + let buffer = String.create chunksize in + for i = (size - 1) / chunksize downto 0 do + seek_in ic (i * chunksize); + seek_out oc (i * chunksize); + let n = input ic buffer 0 chunksize in + output oc buffer 0 n + done; + close_in ic; + close_out oc + +(* Create long lines of text *) + +let make_lines ofile = + let oc = open_out ofile in + for i = 1 to 256 do + output_string oc (String.make (i*64) '.'); output_char oc '\n' + done; + close_out oc + +(* The test *) + +let _ = + let src = Sys.argv.(1) in + let testio = Filename.temp_file "testio" "" in + let lines = Filename.temp_file "lines" "" in + test "16-byte chunks" (copy_file 16) src testio; + test "256-byte chunks" (copy_file 256) src testio; + test "4096-byte chunks" (copy_file 4096) src testio; + test "65536-byte chunks" (copy_file 65536) src testio; + test "19-byte chunks" (copy_file 19) src testio; + test "263-byte chunks" (copy_file 263) src testio; + test "4011-byte chunks" (copy_file 4011) src testio; + test "0...8192 byte chunks" (copy_random 8192) src testio; + test "line per line, short lines" copy_line "/etc/hosts" testio; + make_lines lines; + test "line per line, short and long lines" copy_line lines testio; + test "backwards, 4096-byte chunks" (copy_seek 4096) src testio; + test "backwards, 64-byte chunks" (copy_seek 64) src testio; + Sys.remove lines; + Sys.remove testio; + exit 0 diff --git a/test/Moretest/length.ml b/test/Moretest/length.ml new file mode 100644 index 0000000..bb09074 --- /dev/null +++ b/test/Moretest/length.ml @@ -0,0 +1,16 @@ +(* $Id: length.ml,v 1.1 2007-11-06 21:06:18 weis Exp $ + +A testbed file for private type abbreviation definitions. + +We define a Length module to implement positive integers. + +*) + +type t = int;; + +let make x = + if x >= 0 then x else + failwith (Printf.sprintf "cannot build negative length : %i" x) +;; + +external from : t -> int = "%identity";; diff --git a/test/Moretest/length.mli b/test/Moretest/length.mli new file mode 100644 index 0000000..0ad6ba3 --- /dev/null +++ b/test/Moretest/length.mli @@ -0,0 +1,13 @@ +(* $Id: length.mli,v 1.1 2007-11-06 21:06:18 weis Exp $ + +A testbed file for private type abbreviation definitions. + +We define a Length module to implement positive integers. + +*) + +type t = private int;; + +val make : int -> t;; + +external from : t -> int = "%identity";; diff --git a/test/Moretest/manyargs.ml b/test/Moretest/manyargs.ml new file mode 100644 index 0000000..70c8662 --- /dev/null +++ b/test/Moretest/manyargs.ml @@ -0,0 +1,42 @@ +let manyargs a b c d e f g h i j k l m n o = + print_string "a = "; print_int a; print_newline(); + print_string "b = "; print_int b; print_newline(); + print_string "c = "; print_int c; print_newline(); + print_string "d = "; print_int d; print_newline(); + print_string "e = "; print_int e; print_newline(); + print_string "f = "; print_int f; print_newline(); + print_string "g = "; print_int g; print_newline(); + print_string "h = "; print_int h; print_newline(); + print_string "i = "; print_int i; print_newline(); + print_string "j = "; print_int j; print_newline(); + print_string "k = "; print_int k; print_newline(); + print_string "l = "; print_int l; print_newline(); + print_string "m = "; print_int m; print_newline(); + print_string "n = "; print_int n; print_newline(); + print_string "o = "; print_int o; print_newline(); + print_string "---"; print_newline() + +let manyargs_tail1 a b c d e f g h i j k l m n o = + print_string "tail1:\n"; + manyargs a b c d e f g h i j k l m n o + +let manyargs_tail2 a b = + print_string "tail2:\n"; + manyargs a b a b a b a b a b a b a b a + +let manyargs_tail3 a b c d e f g h i j k l m n o = + print_string "tail3:\n"; + print_string "o = "; print_int o; print_newline(); + print_string "---"; print_newline() + +let _ = + manyargs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; + manyargs_tail1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; + manyargs_tail2 0 1; + manyargs_tail3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + +external manyargs_ext: int -> int -> int -> int -> int -> int -> int -> int -> int -> int -> int -> int = "manyargs_argv" "manyargs" + +let _ = + print_string "external:\n"; flush stdout; + manyargs_ext 1 2 3 4 5 6 7 8 9 10 11 diff --git a/test/Moretest/manyargsprim.c b/test/Moretest/manyargsprim.c new file mode 100644 index 0000000..fb715c6 --- /dev/null +++ b/test/Moretest/manyargsprim.c @@ -0,0 +1,25 @@ +#include "mlvalues.h" +#include "stdio.h" + +value manyargs(value a, value b, value c, value d, value e, value f, + value g, value h, value i, value j, value k) +{ + printf("a = %d\n", Int_val(a)); + printf("b = %d\n", Int_val(b)); + printf("c = %d\n", Int_val(c)); + printf("d = %d\n", Int_val(d)); + printf("e = %d\n", Int_val(e)); + printf("f = %d\n", Int_val(f)); + printf("g = %d\n", Int_val(g)); + printf("h = %d\n", Int_val(h)); + printf("i = %d\n", Int_val(i)); + printf("j = %d\n", Int_val(j)); + printf("k = %d\n", Int_val(k)); + return Val_unit; +} + +value manyargs_argv(value *argv, int argc) +{ + return manyargs(argv[0], argv[1], argv[2], argv[3], argv[4], + argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); +} diff --git a/test/Moretest/md5.ml b/test/Moretest/md5.ml new file mode 100644 index 0000000..46d8a10 --- /dev/null +++ b/test/Moretest/md5.ml @@ -0,0 +1,219 @@ +(* Test int32 arithmetic and optimizations using the MD5 algorithm *) + +open Printf + +type context = + { buf: string; + mutable pos: int; + mutable a: int32; + mutable b: int32; + mutable c: int32; + mutable d: int32; + mutable bits: int64 } + +let step1 w x y z data s = + let w = + Int32.add (Int32.add w data) + (Int32.logxor z (Int32.logand x (Int32.logxor y z))) in + Int32.add x + (Int32.logor (Int32.shift_left w s) (Int32.shift_right_logical w (32-s))) + +let step2 w x y z data s = + let w = + Int32.add (Int32.add w data) + (Int32.logxor y (Int32.logand z (Int32.logxor x y))) in + Int32.add x + (Int32.logor (Int32.shift_left w s) (Int32.shift_right_logical w (32-s))) + +let step3 w x y z data s = + let w = + Int32.add (Int32.add w data) + (Int32.logxor x (Int32.logxor y z)) in + Int32.add x + (Int32.logor (Int32.shift_left w s) (Int32.shift_right_logical w (32-s))) + +let step4 w x y z data s = + let w = + Int32.add (Int32.add w data) + (Int32.logxor y (Int32.logor x (Int32.logxor z (-1l)))) in + Int32.add x + (Int32.logor (Int32.shift_left w s) (Int32.shift_right_logical w (32-s))) + +let transform ctx data = + let a = ctx.a and b = ctx.b and c = ctx.c and d = ctx.d in + + let a = step1 a b c d (Int32.add data.(0) 0xd76aa478l) 7 in + let d = step1 d a b c (Int32.add data.(1) 0xe8c7b756l) 12 in + let c = step1 c d a b (Int32.add data.(2) 0x242070dbl) 17 in + let b = step1 b c d a (Int32.add data.(3) 0xc1bdceeel) 22 in + let a = step1 a b c d (Int32.add data.(4) 0xf57c0fafl) 7 in + let d = step1 d a b c (Int32.add data.(5) 0x4787c62al) 12 in + let c = step1 c d a b (Int32.add data.(6) 0xa8304613l) 17 in + let b = step1 b c d a (Int32.add data.(7) 0xfd469501l) 22 in + let a = step1 a b c d (Int32.add data.(8) 0x698098d8l) 7 in + let d = step1 d a b c (Int32.add data.(9) 0x8b44f7afl) 12 in + let c = step1 c d a b (Int32.add data.(10) 0xffff5bb1l) 17 in + let b = step1 b c d a (Int32.add data.(11) 0x895cd7bel) 22 in + let a = step1 a b c d (Int32.add data.(12) 0x6b901122l) 7 in + let d = step1 d a b c (Int32.add data.(13) 0xfd987193l) 12 in + let c = step1 c d a b (Int32.add data.(14) 0xa679438el) 17 in + let b = step1 b c d a (Int32.add data.(15) 0x49b40821l) 22 in + + let a = step2 a b c d (Int32.add data.(1) 0xf61e2562l) 5 in + let d = step2 d a b c (Int32.add data.(6) 0xc040b340l) 9 in + let c = step2 c d a b (Int32.add data.(11) 0x265e5a51l) 14 in + let b = step2 b c d a (Int32.add data.(0) 0xe9b6c7aal) 20 in + let a = step2 a b c d (Int32.add data.(5) 0xd62f105dl) 5 in + let d = step2 d a b c (Int32.add data.(10) 0x02441453l) 9 in + let c = step2 c d a b (Int32.add data.(15) 0xd8a1e681l) 14 in + let b = step2 b c d a (Int32.add data.(4) 0xe7d3fbc8l) 20 in + let a = step2 a b c d (Int32.add data.(9) 0x21e1cde6l) 5 in + let d = step2 d a b c (Int32.add data.(14) 0xc33707d6l) 9 in + let c = step2 c d a b (Int32.add data.(3) 0xf4d50d87l) 14 in + let b = step2 b c d a (Int32.add data.(8) 0x455a14edl) 20 in + let a = step2 a b c d (Int32.add data.(13) 0xa9e3e905l) 5 in + let d = step2 d a b c (Int32.add data.(2) 0xfcefa3f8l) 9 in + let c = step2 c d a b (Int32.add data.(7) 0x676f02d9l) 14 in + let b = step2 b c d a (Int32.add data.(12) 0x8d2a4c8al) 20 in + + let a = step3 a b c d (Int32.add data.(5) 0xfffa3942l) 4 in + let d = step3 d a b c (Int32.add data.(8) 0x8771f681l) 11 in + let c = step3 c d a b (Int32.add data.(11) 0x6d9d6122l) 16 in + let b = step3 b c d a (Int32.add data.(14) 0xfde5380cl) 23 in + let a = step3 a b c d (Int32.add data.(1) 0xa4beea44l) 4 in + let d = step3 d a b c (Int32.add data.(4) 0x4bdecfa9l) 11 in + let c = step3 c d a b (Int32.add data.(7) 0xf6bb4b60l) 16 in + let b = step3 b c d a (Int32.add data.(10) 0xbebfbc70l) 23 in + let a = step3 a b c d (Int32.add data.(13) 0x289b7ec6l) 4 in + let d = step3 d a b c (Int32.add data.(0) 0xeaa127fal) 11 in + let c = step3 c d a b (Int32.add data.(3) 0xd4ef3085l) 16 in + let b = step3 b c d a (Int32.add data.(6) 0x04881d05l) 23 in + let a = step3 a b c d (Int32.add data.(9) 0xd9d4d039l) 4 in + let d = step3 d a b c (Int32.add data.(12) 0xe6db99e5l) 11 in + let c = step3 c d a b (Int32.add data.(15) 0x1fa27cf8l) 16 in + let b = step3 b c d a (Int32.add data.(2) 0xc4ac5665l) 23 in + + let a = step4 a b c d (Int32.add data.(0) 0xf4292244l) 6 in + let d = step4 d a b c (Int32.add data.(7) 0x432aff97l) 10 in + let c = step4 c d a b (Int32.add data.(14) 0xab9423a7l) 15 in + let b = step4 b c d a (Int32.add data.(5) 0xfc93a039l) 21 in + let a = step4 a b c d (Int32.add data.(12) 0x655b59c3l) 6 in + let d = step4 d a b c (Int32.add data.(3) 0x8f0ccc92l) 10 in + let c = step4 c d a b (Int32.add data.(10) 0xffeff47dl) 15 in + let b = step4 b c d a (Int32.add data.(1) 0x85845dd1l) 21 in + let a = step4 a b c d (Int32.add data.(8) 0x6fa87e4fl) 6 in + let d = step4 d a b c (Int32.add data.(15) 0xfe2ce6e0l) 10 in + let c = step4 c d a b (Int32.add data.(6) 0xa3014314l) 15 in + let b = step4 b c d a (Int32.add data.(13) 0x4e0811a1l) 21 in + let a = step4 a b c d (Int32.add data.(4) 0xf7537e82l) 6 in + let d = step4 d a b c (Int32.add data.(11) 0xbd3af235l) 10 in + let c = step4 c d a b (Int32.add data.(2) 0x2ad7d2bbl) 15 in + let b = step4 b c d a (Int32.add data.(9) 0xeb86d391l) 21 in + + ctx.a <- Int32.add ctx.a a; + ctx.b <- Int32.add ctx.b b; + ctx.c <- Int32.add ctx.c c; + ctx.d <- Int32.add ctx.d d + +let string_to_data s = + let data = Array.make 16 0l in + for i = 0 to 15 do + let j = i lsl 2 in + data.(i) <- + Int32.logor (Int32.shift_left (Int32.of_int (Char.code s.[j+3])) 24) + (Int32.logor (Int32.shift_left (Int32.of_int (Char.code s.[j+2])) 16) + (Int32.logor (Int32.shift_left (Int32.of_int (Char.code s.[j+1])) 8) + (Int32.of_int (Char.code s.[j])))) + done; + data + +let int32_to_string n s i = + s.[i+3] <- Char.chr (Int32.to_int (Int32.shift_right n 24) land 0xFF); + s.[i+2] <- Char.chr (Int32.to_int (Int32.shift_right n 16) land 0xFF); + s.[i+1] <- Char.chr (Int32.to_int (Int32.shift_right n 8) land 0xFF); + s.[i] <- Char.chr (Int32.to_int n land 0xFF) + +let init () = + { buf = String.create 64; + pos = 0; + a = 0x67452301l; + b = 0xefcdab89l; + c = 0x98badcfel; + d = 0x10325476l; + bits = 0L } + +let update ctx input ofs len = + let rec upd ofs len = + if len <= 0 then () else + if ctx.pos + len < 64 then begin + (* Just buffer the data *) + String.blit input ofs ctx.buf ctx.pos len; + ctx.pos <- ctx.pos + len + end else begin + (* Fill the buffer *) + let len' = 64 - ctx.pos in + if len' > 0 then String.blit input ofs ctx.buf ctx.pos len'; + (* Transform 64 bytes *) + transform ctx (string_to_data ctx.buf); + ctx.pos <- 0; + upd (ofs + len') (len - len') + end in + upd ofs len; + ctx.bits <- Int64.add ctx.bits (Int64.of_int (len lsl 3)) + + +let finish ctx = + let padding = String.make 64 '\000' in + padding.[0] <- '\x80'; + let numbits = ctx.bits in + if ctx.pos < 56 then begin + update ctx padding 0 (56 - ctx.pos) + end else begin + update ctx padding 0 (64 + 56 - ctx.pos) + end; + assert (ctx.pos = 56); + let data = string_to_data ctx.buf in + data.(14) <- (Int64.to_int32 numbits); + data.(15) <- (Int64.to_int32 (Int64.shift_right_logical numbits 32)); + transform ctx data; + let res = String.create 16 in + int32_to_string ctx.a res 0; + int32_to_string ctx.b res 4; + int32_to_string ctx.c res 8; + int32_to_string ctx.d res 12; + res + +let test s = + let ctx = init() in + update ctx s 0 (String.length s); + let res = finish ctx in + let exp = Digest.string s in + let ok = (res = exp) in + if not ok then Printf.printf "Failure for '%s'\n" s; + ok + +let time msg iter fn = + let start = Sys.time() in + for i = 1 to iter do fn () done; + let stop = Sys.time() in + printf "%s: %.2f s\n" msg (stop -. start) + +let _ = + (* Test *) + if test "" + && test "a" + && test "abc" + && test "message digest" + && test "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + then printf "Test vectors passed.\n"; + flush stdout; + (* Benchmark *) + let s = String.make 50000 'a' in + let num_iter = 1000 in + time "Caml implementation" num_iter + (fun () -> + let ctx = init() in + update ctx s 0 (String.length s); + ignore (finish ctx)); + time "C implementation" num_iter + (fun () -> ignore (Digest.string s)) diff --git a/test/Moretest/morematch.ml b/test/Moretest/morematch.ml new file mode 100644 index 0000000..d15a221 --- /dev/null +++ b/test/Moretest/morematch.ml @@ -0,0 +1,1169 @@ +(**************************************************************) +(* This suite tests the pattern-matching compiler *) +(* it should just compile and run. *) +(* While compiling the following messages are normal: *) +(**************************************************************) + +(* +File "morematch.ml", line 38, characters 10-93: +Warning: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +0 +File "morematch.ml", line 376, characters 2-15: +Warning: this match case is unused. +File "morematch.ml", line 443, characters 2-7: +Warning: this match case is unused. +*) + +let test msg f arg r = + if f arg <> r then begin + prerr_endline msg ; + failwith "Malaise" + end +;; + +type t = A | B | C | D | E | F + ;; + +let f x = match x with +| A | B | C -> 1 +| D | E -> 2 +| F -> 3;; + +test "un" f C 1 ; +test "un" f D 2 ; +test "un" f F 3 ; () +;; + +let g x = match x with + 1 -> 1 +| 2 -> 2 +| 3 -> 3 +| 4 | 5 -> 4 +| 6 -> 5 +| 7 | 8 -> 6 +| 9 -> 7 +;; + +test "deux" g 5 4 ; +test "deux" g 6 5 ; +test "deux" g 9 7 ; () +;; + + +let g x = match x with + 1 -> 1 +| 2 -> 2 +| 3 -> 3 +| 4 | 5 -> 4 +| 6 -> 5 +| 7 | 8 -> 6 +| 9 -> 7 +| _ -> 8;; + +test "trois" g 10 8 +;; + +let g x= match x with + 1 -> 1 +| 2 -> 2 +| 3 -> 3 +| 4 | 5 -> 4 +| 6 -> 5 +| 4|5|7 -> 100 +| 7 | 8 -> 6 +| 9 -> 7 +| _ -> 8;; +test "quatre" g 4 4 ; +test "quatre" g 7 100 ; () +;; + +(* +File "morematch.ml", line 73, characters 2-5: +Warning U: this sub-pattern is unused. +File "morematch.ml", line 74, characters 2-3: +Warning U: this sub-pattern is unused. +*) + +let h x = + match x with + (1,1) -> 1 +| (2|3), 1 -> 2 +| 2,(2|3) -> 3 +| (4,4) -> 5 +| _ -> 100 +;; + +test "cinq" h (2,2) 3 ; +test "cinq" h (2,1) 2 ; +test "cinq" h (2,4) 100 ; () +;; + +(* idem hh (2,5) *) + +let hh x = match x with +| 1,1 -> 1 +| 2,1 -> 2 +| (2|3),(1|2|3|4) -> 3 +| 2,5 -> 4 +| (4,4) -> 5 +| _ -> 100 +;; + +let hhh x = match x with +| 1,1 -> 1 +| (2|3),1 -> 2 +| 2,2 -> 3 +| _ -> 100 +;; + +let h x = + match x with + (1,1) -> 1 +| 3,1 -> 2 +| 2,(2|3) -> 3 +| (4,4) -> 5 +| _ -> 100 +;; + +let h x = match x with + 1 -> 1 +| 2|3 -> 2 +| 4 -> 4 +| 5 -> 5 +| 6|7 -> 6 +| 8 -> 8 +| _ -> 100 +;; +let f x = match x with +| ((1|2),(3|4))|((3|4),(1|2)) -> 1 +| (3,(5|6)) -> 2 +| _ -> 3 +;; + +test "six" f (1,3) 1 ; +test "six" f (3,2) 1 ; +test "six" f (3,5) 2 ; +test "six" f (3,7) 3 ; () +;; + +type tt = {a : bool list ; b : bool} + +let f = function + | {a=([]|[true])} -> 1 + | {a=false::_}|{b=(true|false)} -> 2 +;; + +test "sept" f {a=[] ; b = true} 1 ; +test "sept" f {a=[true] ; b = false} 1 ; +test "sept" f {a=[false ; true] ; b = true} 2 ; +test "sept" f {a=[false] ; b = false} 2 ; () +;; + +let f = function + | (([]|[true]),_) -> 1 + | (false::_,_)|(_,(true|false)) -> 2 +;; + +test "huit" f ([],true) 1 ; +test "huit" f ([true],false) 1 ; +test "huit" f ([false ; true], true) 2 ; +test "huit" f ([false], false) 2 ; () +;; + + +let split_cases = function + | `Nil | `Cons _ as x -> `A x + | `Snoc _ as x -> `B x +;; + +test "oubli" split_cases `Nil (`A `Nil); +test "oubli" split_cases (`Cons 1) (`A (`Cons 1)); +test "oubli" split_cases (`Snoc 1) (`B (`Snoc 1)) ; () +;; + +type t1 = A of int | B of int +let f1 = function + | (A x | B x) -> x +;; + +test "neuf" f1 (A 1) 1 ; +test "neuf" f1 (B 1) 1 ; +;; + +type coucou = A of int | B of int * int | C +;; + + +let g = function + | (A x | B (_,x)) -> x + | C -> 0 +;; + + +test "dix" g (A 1) 1 ; +test "dix" g (B (1,2)) 2 ; +;; + + + +let h = function + | ([x]|[1 ; x ]|[1 ; 2 ; x]) -> x + | _ -> 0 +;; + +test "encore" h [1] 1 ; +test "encore" h [1;2] 2 ; +test "encore" h [1;2;3] 3 ; +test "encore" h [0 ; 0] 0 ; () +;; + +let f = function +| (x,(0 as y)) | (y,x) -> y-x +;; + +test "foo1" f (1,0) (-1); +test "foo1" f (1,2) (-1) +;; + + +let f = function (([]|[_]) as x)|(_::([] as x))|(_::_::x) -> x +;; + +test "zob" f [] [] ; +test "zob" f [1] [1] ; +test "zob" f [1;2;3] [3] +;; + + +type zob = A | B | C | D of zob * int | E of zob * zob + +let rec f = function + | (A | B | C) -> A + | D (x,i) -> D (f x,i) + | E (x,_) -> D (f x,0) +;; + + +test "fin" f B A ; +test "fin" f (D (C,1)) (D (A,1)) ; +test "fin" f (E (C,A)) (D (A,0)) ; () +;; + +type length = + Char of int | Pixel of int | Percent of int | No of string | Default + +let length = function + | Char n -> n | Pixel n -> n + | _ -> 0 +;; + +test "length" length (Char 10) 10 ; +test "length" length (Pixel 20) 20 ; +test "length" length Default 0 ; +test "length" length (Percent 100) 0 ; () +;; + +let length2 = function + | Char n -> n | Percent n -> n + | _ -> 0 +;; + +test "length2" length2 (Char 10) 10 ; +test "length2" length2 (Pixel 20) 0 ; +test "length2" length2 Default 0 ; +test "length2" length2(Percent 100) 100 ; () +;; + +let length3 = function + | Char _ | No _ -> true + | _ -> false +;; + +test "length3" length3 (Char 10) true ; +test "length3" length3 (No "") true ; +test "length3" length3 (Pixel 20) false ; +test "length3" length3 Default false ; +test "length3" length3(Percent 100) false ; () +;; + +type hevea = A | B | C + +let h x = match x with +| A -> 1 +| B|C -> 2 +;; + +test "hevea" h A 1 ; +test "hevea" h B 2 ; +test "hevea" h B 2 ; () +;; +type lambda = + Lvar of int + | Lconst of int + | Lapply of lambda * lambda list + | Lfunction of bool * int list * lambda + | Llet of bool * int * lambda * lambda + | Lletrec of (int * lambda) list * lambda + | Lprim of string * lambda list + | Lswitch of lambda * lambda_switch + | Lstaticfail + | Lcatch of lambda * lambda + | Lstaticraise of int * lambda list + | Lstaticcatch of lambda * (int * int list) * lambda + | Ltrywith of lambda * int * lambda + | Lifthenelse of lambda * lambda * lambda + | Lsequence of lambda * lambda + | Lwhile of lambda * lambda + | Lfor of int * lambda * lambda * bool * lambda + | Lassign of int * lambda + | Lsend of lambda * lambda * lambda list + | Levent of lambda * lambda_event + | Lifused of int * lambda +and lambda_switch = + { sw_numconsts: int; (* Number of integer cases *) + sw_consts: (int * lambda) list; (* Integer cases *) + sw_numblocks: int; (* Number of tag block cases *) + sw_blocks: (int * lambda) list; (* Tag block cases *) + sw_checked: bool ; (* True if bound checks needed *) + sw_nofail: bool} (* True if should not fail *) +and lambda_event = + { lev_loc: int; + lev_kind: bool ; + lev_repr: int ref option; + lev_env: int list } + +let rec approx_present v l = true + +let rec lower_bind v arg lam = match lam with +| Lifthenelse (cond, ifso, ifnot) -> 1 +| Lswitch (ls,({sw_consts=[i,act] ; sw_blocks = []} as _sw)) + when not (approx_present v ls) -> 2 +| Lswitch (ls,({sw_consts=[] ; sw_blocks = [i,act]} as _sw)) + when not (approx_present v ls) -> 3 +| Llet (true , vv, lv, l) -> 4 +| _ -> 5 +;; + +test "lower_bind" (lower_bind 0 0) (Llet (true,0, Lvar 1, Lvar 2)) 4 ; +test "lower_bind" (lower_bind 0 0) (Lvar 0) 5 ; +test "lower_bind" (lower_bind 0 0) (Lifthenelse (Lvar 0, Lvar 1, Lvar 2)) 1 +;; + + +type field_kind = + Fvar of field_kind option ref + | Fpresent + | Fabsent + +let unify_kind (k1, k2) = match k1, k2 with + (Fvar r, (Fvar _ | Fpresent)) -> 1 + | (Fpresent, Fvar r) -> 2 + | (Fpresent, Fpresent) -> 3 + | _ -> 4 + + +let r = ref (Some Fpresent) +;; + +test "unify" unify_kind (Fvar r, Fpresent) 1 ; +test "unify" unify_kind (Fvar r, Fvar r) 1 ; +test "unify" unify_kind (Fvar r, Fabsent) 4 ; +test "unify" unify_kind (Fpresent, Fvar r) 2 ; +test "unify" unify_kind (Fpresent, Fpresent) 3 ; +test "unify" unify_kind (Fabsent, Fpresent) 4 ; () +;; + + +type youyou = A | B | C | D of youyou + +let foo (k1, k2) = match k1,k2 with +| D _, (A|D _) -> 1 +| (A|B),D _ -> 2 +| C,_ -> 3 +| _, (A|B|C) -> 4 +;; + +test "foo2" foo (D A,A) 1 ; +test "foo2" foo (D A,B) 4 ; +test "foo2" foo (A,A) 4 ; () +;; + +type yaya = A | B +;; + +let yaya = function +| A,_,_ -> 1 +| _,A,_ -> 2 +| B,B,_ -> 3 +| A,_,(100|103) -> 5 +;; + +test "yaya" yaya (A,A,0) 1 ; +test "yaya" yaya (B,A,0) 2 ; +test "yaya" yaya (B,B,100) 3 ; () +;; + +(* +let yoyo = function +| [],_,_ -> 1 +| _,[],_ -> 2 +| _::_,_::_,_ -> 3 +| [],_,(100|103|104) -> 5 +| [],_,(100|103) -> 6 +| [],_,(1000|1001|1002|20000) -> 7 +;; + +test "yoyo" yoyo ([],[],0) 1 ; +test "yoyo" yoyo ([1],[],0) 2 ; +test "yoyo" yoyo ([1],[1],100) 3 ; () +;; + +let youyou = function + | (100|103|104) -> 1 + | (100|103|101) -> 2 + | (1000|1001|1002|20000) -> 3 + | _ -> -1 +;; + +test "youyou" youyou 100 1 ; +test "youyou" youyou 101 2 ; +test "youyou" youyou 1000 3 +;; +*) +type autre = + | C | D | E of autre | F of autre * autre | H of autre | I | J | K of string + +let rec autre = function +| C,_,_ -> 1 +| _,C,_ -> 2 +| D,D,_ -> 3 +| (D|F (_,_)|H _|K _),_,_ -> 4 +| (_, (D|I|E _|F (_, _)|H _|K _), _) -> 8 +| (J,J,((C|D) as x |E x|F (_,x))) | (J,_,((C|J) as x)) -> autre (x,x,x) +| (J, J, (I|H _|K _)) -> 9 +| I,_,_ -> 6 +| E _,_,_ -> 7 +;; +(* +File "morematch.ml", line 437, characters 43-44: +Warning U: this sub-pattern is unused. +*) +test "autre" autre (J,J,F (D,D)) 3 ; +test "autre" autre (J,J,D) 3 ; +test "autre" autre (J,J,I) 9 ; +test "autre" autre (H I,I,I) 4 ; +test "autre" autre (J,J,H I) 9 ; () +;; + + +type youpi = YA | YB | YC +and hola = X | Y | Z | T of hola | U of hola | V of hola + +let xyz = function +| YA,_,_ -> 1 +| _,YA,_ -> 2 +| YB,YB,_ -> 3 +| ((YB|YC), (YB|YC), (X|Y|Z|V _|T _)) -> 6 +| _,_,(X|U _) -> 8 +| _,_,Y -> 5 +;; +(* +File "morematch.ml", line 459, characters 7-8: +Warning U: this sub-pattern is unused. +File "morematch.ml", line 460, characters 2-7: +Warning U: this match case is unused. +*) +test "xyz" xyz (YC,YC,X) 6 ; +test "xyz" xyz (YC,YB,U X) 8 ; +test "xyz" xyz (YB,YC,X) 6 ; () +;; + + +(* Ce test est pour le compilo lui-meme *) +let eq (x,y) = x=y +;; + +test "eq" eq ("coucou", "coucou") true ; () +;; + +(* Test des gardes, non trivial *) + +let is_none = function + | None -> true + | _ -> false + +let garde x = match x with +| (Some _, _) when is_none (snd x) -> 1 +| (Some (pc, _), Some pc') when pc = pc' -> 2 +| _ -> 3 +;; + +test "garde" garde (Some (1,1),None) 1 ; +test "garde" garde (Some (1,1),Some 1) 2 ; +test "garde" garde (Some (2,1),Some 1) 3 ; () +;; + +let orstring = function + | ("A"|"B"|"C") -> 2 + | "D" -> 3 + | _ -> 4 +;; + +test "orstring" orstring "A" 2 ; +test "orstring" orstring "B" 2 ; +test "orstring" orstring "C" 2 ; +test "orstring" orstring "D" 3 ; +test "orstring" orstring "E" 4 ; () +;; + +type var_t = [`Variant of [ `Some of string | `None | `Foo] ] + +let crash (pat:var_t) = + match pat with + | `Variant (`Some tag) -> tag + | `Variant (`None) -> "none" + | _ -> "foo" + +;; + +test "crash" crash (`Variant `None) "none" ; +test "crash" crash (`Variant (`Some "coucou")) "coucou" ; +test "crash" crash (`Variant (`Foo)) "foo" ; () +;; + +let flatgarde c = +let x,y = c in +match x,y with +| (1,2)|(2,3) when y=2 -> 1 +| (1,_)|(_,3) -> 2 +| _ -> 3 +;; + +test "flatgarde" flatgarde (1,2) 1 ; +test "flatgarde" flatgarde (1,3) 2 ; +test "flatgarde" flatgarde (2,3) 2 ; +test "flatgarde" flatgarde (2,4) 3 ; () +;; + + +(* Les bugs de jerome *) +type f = + | ABSENT + | FILE + | SYMLINK + | DIRECTORY + +type r = + | Unchanged + | Deleted + | Modified + | PropsChanged + | Created + +let replicaContent2shortString rc = + let (typ, status) = rc in + match typ, status with + _, Unchanged -> " " + | ABSENT, Deleted -> "deleted " + | FILE, Created -> "new file" + | FILE, Modified -> "changed " + | FILE, PropsChanged -> "props " + | SYMLINK, Created -> "new link" + | SYMLINK, Modified -> "chgd lnk" + | DIRECTORY, Created -> "new dir " + | DIRECTORY, Modified -> "chgd dir" + | DIRECTORY, PropsChanged -> "props " + (* Cases that can't happen... *) + + | ABSENT, (Created | Modified | PropsChanged) + | SYMLINK, PropsChanged + | (FILE|SYMLINK|DIRECTORY), Deleted + -> "assert false" +;; + + +test "jerome_constr" + replicaContent2shortString (ABSENT, Unchanged) " " ; +test "jerome_constr" + replicaContent2shortString (ABSENT, Deleted) "deleted " ; +test "jerome_constr" + replicaContent2shortString (FILE, Modified) "changed " ; +test "jerome_constr" + replicaContent2shortString (DIRECTORY, PropsChanged) "props " ; +test "jerome_constr" + replicaContent2shortString (FILE, Deleted) "assert false" ; +test "jerome_constr" + replicaContent2shortString (SYMLINK, Deleted) "assert false" ; +test "jerome_constr" + replicaContent2shortString (SYMLINK, PropsChanged) "assert false" ; +test "jerome_constr" + replicaContent2shortString (DIRECTORY, Deleted) "assert false" ; +test "jerome_constr" + replicaContent2shortString (ABSENT, Created) "assert false" ; +test "jerome_constr" + replicaContent2shortString (ABSENT, Modified) "assert false" ; +test "jerome_constr" + replicaContent2shortString (ABSENT, PropsChanged) "assert false" ; +;; + + +let replicaContent2shortString rc = + let (typ, status) = rc in + match typ, status with + _, `Unchanged -> " " + | `ABSENT, `Deleted -> "deleted " + | `FILE, `Created -> "new file" + | `FILE, `Modified -> "changed " + | `FILE, `PropsChanged -> "props " + | `SYMLINK, `Created -> "new link" + | `SYMLINK, `Modified -> "chgd lnk" + | `DIRECTORY, `Created -> "new dir " + | `DIRECTORY, `Modified -> "chgd dir" + | `DIRECTORY, `PropsChanged -> "props " + (* Cases that can't happen... *) + + | `ABSENT, (`Created | `Modified | `PropsChanged) + | `SYMLINK, `PropsChanged + | (`FILE|`SYMLINK|`DIRECTORY), `Deleted + -> "assert false" +;; + + +test "jerome_variant" + replicaContent2shortString (`ABSENT, `Unchanged) " " ; +test "jerome_variant" + replicaContent2shortString (`ABSENT, `Deleted) "deleted " ; +test "jerome_variant" + replicaContent2shortString (`FILE, `Modified) "changed " ; +test "jerome_variant" + replicaContent2shortString (`DIRECTORY, `PropsChanged) "props " ; +test "jerome_variant" + replicaContent2shortString (`FILE, `Deleted) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`SYMLINK, `Deleted) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`SYMLINK, `PropsChanged) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`DIRECTORY, `Deleted) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`ABSENT, `Created) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`ABSENT, `Modified) "assert false" ; +test "jerome_variant" + replicaContent2shortString (`ABSENT, `PropsChanged) "assert false" ; +;; + +(* bug 319 *) + +type ab = A of int | B of int +type cd = C | D + +let ohl = function + | (A (p) | B (p)), C -> p + | (A (p) | B (p)), D -> p +;; + +test "ohl" ohl (A 0,C) 0 ; +test "ohl" ohl (B 0,D) 0 ; () +;; + +(* bug 324 *) +type pottier = + | A + | B +;; + +let pottier x = + match x with + | (( (A, 1) | (B, 2)),A) -> false + | _ -> true +;; + +test "pottier" pottier ((B,2),A) false ; +test "pottier" pottier ((B,2),B) true ; +test "pottier" pottier ((A,2),A) true ; () +;; + +(* bug 325 in bytecode compiler *) +let coquery q = match q with +| y,0,([modu;defs]| [defs;modu;_]) -> y+defs-modu +| _ -> 0 +;; + +test "coquery" coquery (1,0,[1 ; 2 ; 3]) 0 ; +test "coquery" coquery (1,0,[1 ; 2]) 2 ; () +;; + +(* + Two other variable in or-pat tests +*) +type vars = A of int | B of (int * int) | C +;; + + +let vars1 = function + | (A x | B (_,x)) -> x + | C -> 0 +;; + +test "vars1" vars1 (A 1) 1 ; +test "vars1" vars1 (B (1,2)) 2 ; () +;; + +let vars2 = function + | ([x]|[1 ; x ]|[1 ; 2 ; x]) -> x + | _ -> 0 +;; + +test"vars2" vars2 [1] 1 ; +test"vars2" vars2 [1;2] 2 ; +test"vars2" vars2 [1;2;3] 3 ; +test"vars2" vars2 [0 ; 0] 0 ; () +;; + +(* Bug 342 *) +type eber = {x:int; y: int; z:bool} + +let eber = function + | {x=a; z=true} + | {y=a; z=false} -> a +;; + +test "eber" eber {x=0 ; y=1 ; z=true} 0 ; +test "eber" eber {x=1 ; y=0 ; z=false} 0 ; () +;; + + +(* Enchainement des test d'intervalle *) + +let escaped = function + | '"' | '\\' | '\n' | '\t' -> 2 + | c -> 1 +;; + +test "escaped" escaped '"' 2 ; +test "escaped" escaped '\\' 2 ; +test "escaped" escaped '\n' 2 ; +test "escaped" escaped '\t' 2 ; +test "escaped" escaped '\000' 1 ; +test "escaped" escaped ' ' 1 ; +test "escaped" escaped '\000' 1 ; +test "escaped" escaped '[' 1 ; +test "escaped" escaped ']' 1 ; +test "escaped" escaped '!' 1 ; +test "escaped" escaped '#' 1 ; +() +;; + +(* For compilation speed (due to J. Garigue) *) +exception Unknown_Reply of int + +type command_reply = + RPL_TRYAGAIN + | RPL_TRACEEND + | RPL_TRACELOG + | RPL_ADMINEMAIL + | RPL_ADMINLOC2 + | RPL_ADMINLOC1 + | RPL_ADMINME + | RPL_LUSERME + | RPL_LUSERCHANNELS + | RPL_LUSERUNKNOWN + | RPL_LUSEROP + | RPL_LUSERCLIENT + | RPL_STATSDLINE + | RPL_STATSDEBUG + | RPL_STATSDEFINE + | RPL_STATSBLINE + | RPL_STATSPING + | RPL_STATSSLINE + | RPL_STATSHLINE + | RPL_STATSOLINE + | RPL_STATSUPTIME + | RPL_STATSLLINE + | RPL_STATSVLINE + | RPL_SERVLISTEND + | RPL_SERVLIST + | RPL_SERVICE + | RPL_ENDOFSERVICES + | RPL_SERVICEINFO + | RPL_UMODEIS + | RPL_ENDOFSTATS + | RPL_STATSYLINE + | RPL_STATSQLINE + | RPL_STATSKLINE + | RPL_STATSILINE + | RPL_STATSNLINE + | RPL_STATSCLINE + | RPL_STATSCOMMANDS + | RPL_STATSLINKINFO + | RPL_TRACERECONNECT + | RPL_TRACECLASS + | RPL_TRACENEWTYPE + | RPL_TRACESERVICE + | RPL_TRACESERVER + | RPL_TRACEUSER + | RPL_TRACEOPERATOR + | RPL_TRACEUNKNOWN + | RPL_TRACEHANDSHAKE + | RPL_TRACECONNECTING + | RPL_TRACELINK + | RPL_NOUSERS + | RPL_ENDOFUSERS + | RPL_USERS + | RPL_USERSSTART + | RPL_TIME + | RPL_NOTOPERANYMORE + | RPL_MYPORTIS + | RPL_YOURESERVICE + | RPL_REHASHING + | RPL_YOUREOPER + | RPL_ENDOFMOTD + | RPL_MOTDSTART + | RPL_ENDOFINFO + | RPL_INFOSTART + | RPL_MOTD + | RPL_INFO + | RPL_ENDOFBANLIST + | RPL_BANLIST + | RPL_ENDOFLINKS + | RPL_LINKS + | RPL_CLOSEEND + | RPL_CLOSING + | RPL_KILLDONE + | RPL_ENDOFNAMES + | RPL_NAMREPLY + | RPL_ENDOFWHO + | RPL_WHOREPLY + | RPL_VERSION + | RPL_SUMMONING + | RPL_INVITING + | RPL_TOPIC + | RPL_NOTOPIC + | RPL_CHANNELMODEIS + | RPL_LISTEND + | RPL_LIST + | RPL_LISTSTART + | RPL_WHOISCHANNELS + | RPL_ENDOFWHOIS + | RPL_WHOISIDLE + | RPL_WHOISCHANOP + | RPL_ENDOFWHOWAS + | RPL_WHOWASUSER + | RPL_WHOISOPERATOR + | RPL_WHOISSERVER + | RPL_WHOISUSER + | RPL_NOWAWAY + | RPL_UNAWAY + | RPL_TEXT + | RPL_ISON + | RPL_USERHOST + | RPL_AWAY + | RPL_NONE + +let get_command_reply n = +match n with + 263 -> RPL_TRYAGAIN + | 319 -> RPL_WHOISCHANNELS + | 318 -> RPL_ENDOFWHOIS + | 317 -> RPL_WHOISIDLE + | 316 -> RPL_WHOISCHANOP + | 369 -> RPL_ENDOFWHOWAS + | 314 -> RPL_WHOWASUSER + | 313 -> RPL_WHOISOPERATOR + | 312 -> RPL_WHOISSERVER + | 311 -> RPL_WHOISUSER + | 262 -> RPL_TRACEEND + | 261 -> RPL_TRACELOG + | 259 -> RPL_ADMINEMAIL + | 258 -> RPL_ADMINLOC2 + | 257 -> RPL_ADMINLOC1 + | 256 -> RPL_ADMINME + | 255 -> RPL_LUSERME + | 254 -> RPL_LUSERCHANNELS + | 253 -> RPL_LUSERUNKNOWN + | 252 -> RPL_LUSEROP + | 251 -> RPL_LUSERCLIENT + | 250 -> RPL_STATSDLINE + | 249 -> RPL_STATSDEBUG + | 248 -> RPL_STATSDEFINE + | 247 -> RPL_STATSBLINE + | 246 -> RPL_STATSPING + | 245 -> RPL_STATSSLINE + | 244 -> RPL_STATSHLINE + | 243 -> RPL_STATSOLINE + | 242 -> RPL_STATSUPTIME + | 241 -> RPL_STATSLLINE + | 240 -> RPL_STATSVLINE + | 235 -> RPL_SERVLISTEND + | 234 -> RPL_SERVLIST + | 233 -> RPL_SERVICE + | 232 -> RPL_ENDOFSERVICES + | 231 -> RPL_SERVICEINFO + | 221 -> RPL_UMODEIS + | 219 -> RPL_ENDOFSTATS + | 218 -> RPL_STATSYLINE + | 217 -> RPL_STATSQLINE + | 216 -> RPL_STATSKLINE + | 215 -> RPL_STATSILINE + | 214 -> RPL_STATSNLINE + | 213 -> RPL_STATSCLINE + | 212 -> RPL_STATSCOMMANDS + | 211 -> RPL_STATSLINKINFO + | 210 -> RPL_TRACERECONNECT + | 209 -> RPL_TRACECLASS + | 208 -> RPL_TRACENEWTYPE + | 207 -> RPL_TRACESERVICE + | 206 -> RPL_TRACESERVER + | 205 -> RPL_TRACEUSER + | 204 -> RPL_TRACEOPERATOR + | 203 -> RPL_TRACEUNKNOWN + | 202 -> RPL_TRACEHANDSHAKE + | 201 -> RPL_TRACECONNECTING + | 200 -> RPL_TRACELINK + | 395 -> RPL_NOUSERS + | 394 -> RPL_ENDOFUSERS + | 393 -> RPL_USERS + | 392 -> RPL_USERSSTART + | 391 -> RPL_TIME + | 385 -> RPL_NOTOPERANYMORE + | 384 -> RPL_MYPORTIS + | 383 -> RPL_YOURESERVICE + | 382 -> RPL_REHASHING + | 381 -> RPL_YOUREOPER + | 376 -> RPL_ENDOFMOTD + | 375 -> RPL_MOTDSTART + | 374 -> RPL_ENDOFINFO + | 373 -> RPL_INFOSTART + | 372 -> RPL_MOTD + | 371 -> RPL_INFO + | 368 -> RPL_ENDOFBANLIST + | 367 -> RPL_BANLIST + | 365 -> RPL_ENDOFLINKS + | 364 -> RPL_LINKS + | 363 -> RPL_CLOSEEND + | 362 -> RPL_CLOSING + | 361 -> RPL_KILLDONE + | 366 -> RPL_ENDOFNAMES + | 353 -> RPL_NAMREPLY + | 315 -> RPL_ENDOFWHO + | 352 -> RPL_WHOREPLY + | 351 -> RPL_VERSION + | 342 -> RPL_SUMMONING + | 341 -> RPL_INVITING + | 332 -> RPL_TOPIC + | 331 -> RPL_NOTOPIC + | 324 -> RPL_CHANNELMODEIS + | 323 -> RPL_LISTEND + | 322 -> RPL_LIST + | 321 -> RPL_LISTSTART + | 306 -> RPL_NOWAWAY + | 305 -> RPL_UNAWAY + | 304 -> RPL_TEXT + | 303 -> RPL_ISON + | 302 -> RPL_USERHOST + | 301 -> RPL_AWAY + | 300 -> RPL_NONE + | _ -> raise (Unknown_Reply n) + +(* Bug 454 *) +type habert_a= + | A of habert_c + | B of habert_c + +and habert_c= {lvar:int; lassoc: habert_c;lnb:int} + + +let habert=function + | (A {lnb=i}|B {lnb=i}) when i=0 -> 1 + | A {lassoc=({lnb=j});lnb=i} -> 2 + | _ -> 3 +;; + +let rec ex0 = {lvar=0 ; lnb=0 ; lassoc=ex1} +and ex1 = {lvar=1 ; lnb=1 ; lassoc=ex0} in + +test "habert" habert (A ex0) 1 ; +test "habert" habert (B ex0) 1 ; +test "habert" habert (A ex1) 2 ; +test "habert" habert (B ex1) 3 ; + +(* Problems with interval test in arithmetic mod 2^31, bug #359 *) +(* From manuel Fahndrich *) + +type type_expr = [ + | `TTuple of type_expr list + | `TConstr of type_expr list + | `TVar of string + | `TVariant of string list + | `TBlock of int + | `TCopy of type_expr + ] + +and recurs_type_expr = [ + | `TTuple of type_expr list + | `TConstr of type_expr list + | `TVariant of string list + ] + + +let rec maf te = + match te with + | `TCopy te -> 1 + | `TVar _ -> 2 + | `TBlock _ -> 2 + | #recurs_type_expr as desc -> + + let te = + (match desc with + `TTuple tl -> + 4 + | `TConstr tl -> + 5 + | `TVariant (row) -> + 6 + ) + in + + te +;; + +let base = `TBlock 0 +;; + +test "maf" maf (`TCopy base) 1 ; +test "maf" maf (`TVar "test") 2 ; +test "maf" maf (`TBlock 0) 2 ; +test "maf" maf (`TTuple []) 4 ; +test "maf" maf (`TConstr []) 5 ; +test "maf" maf (`TVariant []) 6 +;; + +(* PR#1310 + Using ``get_args'' in place or an ad-hoc ``matcher'' function for tuples. + Has made the compiler [3.05] to fail. +*) +type t_seb = Uin | Uout +;; + +let rec seb = function + | ((i, Uin) | (i, Uout)), Uout -> 1 + | ((j, Uin) | (j, Uout)), Uin -> 2 +;; + +test "seb" seb ((0,Uin),Uout) 1 ; +test "seb" seb ((0,Uout),Uin) 2 ; +() +;; + +(* Talk with Jacques + - type 'b is still open ?? + - better case generation, accept intervals of size 1 when ok_inter is + false (in Switch) +*) + +(* +File "morematch.ml", line 1060, characters 8-65: +Warning: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +A `D +*) +type ('a, 'b) t_j = A of 'a | B of 'b * 'a | C + +let f = function + | A (`A|`C) -> 0 + | B (`B,`D) -> 1 + | C -> 2 + +let g x = try f x with Match_failure _ -> 3 + +let _ = + test "jacques" g (A `A) 0 ; + test "jacques" g (A `C) 0 ; + test "jacques" g (B (`B,`D)) 1 ; + test "jacaues" g C 2 ; +(* test "jacques" g (B (`A,`D)) 3 ; (* type incorrect expected behavior ? *)*) + () + +(* + Compilation bug, segfault, because of incorrect compilation + of unused match case .. -> "11" +*) + +type t_l = A | B + +let f = function + | _, _, _, _, _, _, _, _, _, _, _, _, _, B, _, _ -> "0" + | _, _, _, B, A, _, _, _, _, _, _, _, _, _, _, _ -> "1" + | _, _, _, B, _, A, _, _, A, _, _, _, _, _, _, _ -> "2" + | _, _, _, _, _, _, _, _, _, _, B, A, _, A, _, _ -> "3" + | _, _, _, _, _, _, _, B, _, _, _, _, B, _, A, A -> "4" + | A, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ -> "5" + | _, _, _, _, _, _, _, B, _, B, _, _, _, _, _, _ -> "6" + | _, B, _, _, _, _, _, _, _, _, _, _, _, _, _, _ -> "7" + | _, A, A, _, A, _, B, _, _, _, _, _, _, _, _, B -> "8" + | _, _, _, _, B, _, _, _, _, _, _, _, _, _, B, _ -> "9" + | _, _, _, _, _, _, _, _, _, _, _, B, _, _, _, _ -> "10" + | _, _, _, _, _, A, _, _, _, _, B, _, _, _, _, _ -> "11" + | B, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ -> "12" + | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ -> "13" + +(* +File "morematch.ml", line 1094, characters 5-51: +Warning: this match case is unused. +File "morematch.ml", line 1096, characters 5-51: +Warning: this match case is unused. +*) +let _ = + test "luc" f (B, A, A, A, A, A, A, A, A, A, A, B, A, A, A, A) "10" ; + test "luc" f (B, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A) "12" ; + () + +(* + By Gilles Peskine, compilation raised some assert false i make_failactionneg +*) + +type bg = [ + | `False + | `True + ] + +type vg = [ + | `A + | `B + | `U of int + | `V of int + ] + +type tg = { + v : vg; + x : bg; + } + +let predg x = true + +let rec gilles o = match o with + | {v = (`U data | `V data); x = `False} when predg o -> 1 + | {v = (`A|`B) ; x = `False} + | {v = (`U _ | `V _); x = `False} + | {v = _ ; x = `True} + -> 2 + +(* + Match in trywith should always have a default case +*) + +exception Found of string * int +exception Error of string + + +let lucexn e = + try + try raise e with Error msg -> msg + with Found (s,r) -> s^string_of_int r + +let () = + test "lucexn1" lucexn (Error "coucou") "coucou" ; + test "lucexn2" lucexn (Found ("int: ",0)) "int: 0" ; + () diff --git a/test/Moretest/multdef.ml b/test/Moretest/multdef.ml new file mode 100644 index 0000000..46869c4 --- /dev/null +++ b/test/Moretest/multdef.ml @@ -0,0 +1,2 @@ +let f x = x + 1 +external g : string -> int = "caml_int_of_string" diff --git a/test/Moretest/multdef.mli b/test/Moretest/multdef.mli new file mode 100644 index 0000000..8d67a54 --- /dev/null +++ b/test/Moretest/multdef.mli @@ -0,0 +1,3 @@ +val f : int -> int +val f : int -> int +val g : string -> int diff --git a/test/Moretest/patmatch.ml b/test/Moretest/patmatch.ml new file mode 100644 index 0000000..0077e77 --- /dev/null +++ b/test/Moretest/patmatch.ml @@ -0,0 +1,78 @@ +(* Tests for matchings on integers and characters *) + +(* Dense integer switch *) + +let f = function 1 -> 1 | 2 -> 2 | 3 -> 3 | 4 -> 4 | 5 -> 5 | 6 -> 6 | _ -> 0 + +(* Sparse integer switch *) + +let g = function 303 -> 1 | 401 -> 2 | _ -> 0 + +(* Very sparse integer switch *) + +let iszero = function 0 -> true | _ -> false + +(* Simple matching on characters *) + +let h = function + 'a' -> "a" + | 'e' -> "e" + | 'i' -> "i" + | 'o' -> "o" + | 'u' -> "u" + | _ -> "?" + +(* Matching with orpats *) + +let k = function + ' ' | '\t' | '\n' | '\r' -> "blk" + | 'A'..'Z' | 'a'..'z' | '\192'..'\255' -> "letr" + | '0'..'9' -> "dig" + | '!'|'%'|'&'|'$'|'#'|'+'|'/'|':'|'<'|'='|'>'|'?'|'@'|'\\'| + '~'|'^'|'|'|'*' -> "oper" + | _ -> "othr" + +(* Matching on arrays *) + +let p = function [| x |] -> x | _ -> assert false + +let q = function [| x |] -> x | _ -> 0 + +let r = function [| x |] -> x | _ -> 0.0 + +let l = function + [||] -> 0 + | [|x|] -> x + 1 + | [|x;y|] -> x + y + | [|x;y;z|] -> x + y + z + +(* The test *) + +open Printf + +let _ = + for i = -5 to 10 do printf "f(%d) = %d\n" i (f i) done; + List.iter (fun i -> printf "g(%d) = %d\n" i (g i)) + [0;300;303;305;400;401;402;999]; + for i = -2 to 2 do printf "iszero(%d) = %B\n" i (iszero i) done; + for i = 97 to 126 do + let c = Char.chr i in + printf "h(%c) = %s\n" c (h c) + done; + for i = 0 to 255 do + let c = Char.chr i in + printf "k(%s) = %s\t" (Char.escaped c) (k c) + done; + printf "\n"; + printf "p([|\"hello\"|]) = %s\n" (p [|"hello"|]); + printf "p([|1.0|]) = %f\n" (p [|1.0|]); + printf "q([|2|]) = %d\n" (q [|2|]); + printf "r([|3.0|]) = %f\n" (r [|3.0|]); + printf "l([||]) = %d\n" (l [||]); + printf "l([|1|]) = %d\n" (l [|1|]); + printf "l([|2;3|]) = %d\n" (l [|2;3|]); + printf "l([|4;5;6|]) = %d\n" (l [|4;5;6|]); + exit 0 + + + diff --git a/test/Moretest/recmod.ml b/test/Moretest/recmod.ml new file mode 100644 index 0000000..0aa63af --- /dev/null +++ b/test/Moretest/recmod.ml @@ -0,0 +1,511 @@ +(* Tests for recursive modules *) + +let test number result expected = + if result = expected + then Printf.printf "Test %d passed.\n" number + else Printf.printf "Test %d FAILED.\n" number; + flush stdout + +(* Tree of sets *) + +module rec A + : sig + type t = Leaf of int | Node of ASet.t + val compare: t -> t -> int + end + = struct + type t = Leaf of int | Node of ASet.t + let compare x y = + match (x,y) with + (Leaf i, Leaf j) -> Pervasives.compare i j + | (Leaf i, Node t) -> -1 + | (Node s, Leaf j) -> 1 + | (Node s, Node t) -> ASet.compare s t + end + +and ASet : Set.S with type elt = A.t = Set.Make(A) +;; + +let _ = + let x = A.Node (ASet.add (A.Leaf 3) (ASet.singleton (A.Leaf 2))) in + let y = A.Node (ASet.add (A.Leaf 1) (ASet.singleton x)) in + test 10 (A.compare x x) 0; + test 11 (A.compare x (A.Leaf 3)) 1; + test 12 (A.compare (A.Leaf 0) x) (-1); + test 13 (A.compare y y) 0; + test 14 (A.compare x y) 1 +;; + +(* Simple value recursion *) + +module rec Fib + : sig val f : int -> int end + = struct let f x = if x < 2 then 1 else Fib.f(x-1) + Fib.f(x-2) end +;; + +let _ = + test 20 (Fib.f 10) 89 +;; + +(* Update function by infix *) + +module rec Fib2 + : sig val f : int -> int end + = struct let rec g x = Fib2.f(x-1) + Fib2.f(x-2) + and f x = if x < 2 then 1 else g x + end +;; + +let _ = + test 21 (Fib2.f 10) 89 +;; + +(* Early application *) + +let _ = + let res = + try + let module A = + struct + module rec Bad + : sig val f : int -> int end + = struct let f = let y = Bad.f 5 in fun x -> x+y end + end in + false + with Undefined_recursive_module _ -> + true in + test 30 res true +;; + +(* Early strict evaluation *) + +(* +module rec Cyclic + : sig val x : int end + = struct let x = Cyclic.x + 1 end +;; +*) + +(* Reordering of evaluation based on dependencies *) + +module rec After + : sig val x : int end + = struct let x = Before.x + 1 end +and Before + : sig val x : int end + = struct let x = 3 end +;; + +let _ = + test 40 After.x 4 +;; + +(* Type identity between A.t and t within A's definition *) + +module rec Strengthen + : sig type t val f : t -> t end + = struct + type t = A | B + let _ = (A : Strengthen.t) + let f x = if true then A else Strengthen.f B + end +;; + +module rec Strengthen2 + : sig type t + val f : t -> t + module M : sig type u end + module R : sig type v end + end + = struct + type t = A | B + let _ = (A : Strengthen2.t) + let f x = if true then A else Strengthen2.f B + module M = + struct + type u = C + let _ = (C: Strengthen2.M.u) + end + module rec R : sig type v = Strengthen2.R.v end = + struct + type v = D + let _ = (D : R.v) + let _ = (D : Strengthen2.R.v) + end + end +;; + +(* Polymorphic recursion *) + +module rec PolyRec + : sig + type 'a t = Leaf of 'a | Node of 'a list t * 'a list t + val depth: 'a t -> int + end + = struct + type 'a t = Leaf of 'a | Node of 'a list t * 'a list t + let x = (PolyRec.Leaf 1 : int t) + let depth = function + Leaf x -> 0 + | Node(l,r) -> 1 + max (PolyRec.depth l) (PolyRec.depth r) + end +;; + +(* Wrong LHS signatures (PR#4336) *) + +(* +module type ASig = sig type a val a:a val print:a -> unit end +module type BSig = sig type b val b:b val print:b -> unit end + +module A = struct type a = int let a = 0 let print = print_int end +module B = struct type b = float let b = 0.0 let print = print_float end + +module MakeA (Empty:sig end) : ASig = A +module MakeB (Empty:sig end) : BSig = B + +module + rec NewA : ASig = MakeA (struct end) + and NewB : BSig with type b = NewA.a = MakeB (struct end);; + +*) + +(* Expressions and bindings *) + +module StringSet = Set.Make(String);; + +module rec Expr + : sig + type t = + Var of string + | Const of int + | Add of t * t + | Binding of Binding.t * t + val make_let: string -> t -> t -> t + val fv: t -> StringSet.t + val simpl: t -> t + end + = struct + type t = + Var of string + | Const of int + | Add of t * t + | Binding of Binding.t * t + let make_let id e1 e2 = Binding([id, e1], e2) + let rec fv = function + Var s -> StringSet.singleton s + | Const n -> StringSet.empty + | Add(t1,t2) -> StringSet.union (fv t1) (fv t2) + | Binding(b,t) -> + StringSet.union (Binding.fv b) + (StringSet.diff (fv t) (Binding.bv b)) + let rec simpl = function + Var s -> Var s + | Const n -> Const n + | Add(Const i, Const j) -> Const (i+j) + | Add(Const 0, t) -> simpl t + | Add(t, Const 0) -> simpl t + | Add(t1,t2) -> Add(simpl t1, simpl t2) + | Binding(b, t) -> Binding(Binding.simpl b, simpl t) + end + +and Binding + : sig + type t = (string * Expr.t) list + val fv: t -> StringSet.t + val bv: t -> StringSet.t + val simpl: t -> t + end + = struct + type t = (string * Expr.t) list + let fv b = + List.fold_left (fun v (id,e) -> StringSet.union v (Expr.fv e)) + StringSet.empty b + let bv b = + List.fold_left (fun v (id,e) -> StringSet.add id v) + StringSet.empty b + let simpl b = + List.map (fun (id,e) -> (id, Expr.simpl e)) b + end +;; + +let _ = + let e = Expr.make_let "x" (Expr.Add (Expr.Var "y", Expr.Const 0)) + (Expr.Var "x") in + let e' = Expr.make_let "x" (Expr.Var "y") (Expr.Var "x") in + test 50 (StringSet.elements (Expr.fv e)) ["y"]; + test 51 (Expr.simpl e) e' +;; + +(* Okasaki's bootstrapping *) + +module type ORDERED = + sig + type t + val eq: t -> t -> bool + val lt: t -> t -> bool + val leq: t -> t -> bool + end + +module type HEAP = + sig + module Elem: ORDERED + type heap + val empty: heap + val isEmpty: heap -> bool + val insert: Elem.t -> heap -> heap + val merge: heap -> heap -> heap + val findMin: heap -> Elem.t + val deleteMin: heap -> heap + end + +module Bootstrap (MakeH: functor (Element:ORDERED) -> + HEAP with module Elem = Element) + (Element: ORDERED) : HEAP with module Elem = Element = + struct + module Elem = Element + module rec BE + : sig type t = E | H of Elem.t * PrimH.heap + val eq: t -> t -> bool + val lt: t -> t -> bool + val leq: t -> t -> bool + end + = struct + type t = E | H of Elem.t * PrimH.heap + let leq t1 t2 = + match t1, t2 with + | (H(x, _)), (H(y, _)) -> Elem.leq x y + | H _, E -> false + | E, H _ -> true + | E, E -> true + let eq t1 t2 = + match t1, t2 with + | (H(x, _)), (H(y, _)) -> Elem.eq x y + | H _, E -> false + | E, H _ -> false + | E, E -> true + let lt t1 t2 = + match t1, t2 with + | (H(x, _)), (H(y, _)) -> Elem.lt x y + | H _, E -> false + | E, H _ -> true + | E, E -> false + end + and PrimH + : HEAP with type Elem.t = BE.t + = MakeH(BE) + type heap = BE.t + let empty = BE.E + let isEmpty = function BE.E -> true | _ -> false + let rec merge x y = + match (x,y) with + (BE.E, _) -> y + | (_, BE.E) -> x + | (BE.H(e1,p1) as h1), (BE.H(e2,p2) as h2) -> + if Elem.leq e1 e2 + then BE.H(e1, PrimH.insert h2 p1) + else BE.H(e2, PrimH.insert h1 p2) + let insert x h = + merge (BE.H(x, PrimH.empty)) h + let findMin = function + BE.E -> raise Not_found + | BE.H(x, _) -> x + let deleteMin = function + BE.E -> raise Not_found + | BE.H(x, p) -> + if PrimH.isEmpty p then BE.E else begin + match PrimH.findMin p with + | (BE.H(y, p1)) -> + let p2 = PrimH.deleteMin p in + BE.H(y, PrimH.merge p1 p2) + | BE.E -> assert false + end + end +;; + +module LeftistHeap(Element: ORDERED): HEAP with module Elem = Element = + struct + module Elem = Element + type heap = E | T of int * Elem.t * heap * heap + let rank = function E -> 0 | T(r,_,_,_) -> r + let make x a b = + if rank a >= rank b + then T(rank b + 1, x, a, b) + else T(rank a + 1, x, b, a) + let empty = E + let isEmpty = function E -> true | _ -> false + let rec merge h1 h2 = + match (h1, h2) with + (_, E) -> h1 + | (E, _) -> h2 + | (T(_, x1, a1, b1), T(_, x2, a2, b2)) -> + if Elem.leq x1 x2 + then make x1 a1 (merge b1 h2) + else make x2 a2 (merge h1 b2) + let insert x h = merge (T(1, x, E, E)) h + let findMin = function + E -> raise Not_found + | T(_, x, _, _) -> x + let deleteMin = function + E -> raise Not_found + | T(_, x, a, b) -> merge a b + end +;; + +module Ints = + struct + type t = int + let eq = (=) + let lt = (<) + let leq = (<=) + end +;; + +module C = Bootstrap(LeftistHeap)(Ints);; + +let _ = + let h = List.fold_right C.insert [6;4;8;7;3;1] C.empty in + test 60 (C.findMin h) 1; + test 61 (C.findMin (C.deleteMin h)) 3; + test 62 (C.findMin (C.deleteMin (C.deleteMin h))) 4 +;; + +(* Classes *) + +module rec Class1 + : sig + class c : object method m : int -> int end + end + = struct + class c = + object + method m x = if x <= 0 then x else (new Class2.d)#m x + end + end +and Class2 + : sig + class d : object method m : int -> int end + end + = struct + class d = + object(self) + inherit Class1.c as super + method m (x:int) = super#m 0 + end + end +;; + +let _ = + test 70 ((new Class1.c)#m 7) 0 +;; + +let _ = + try + let module A = struct + module rec BadClass1 + : sig + class c : object method m : int end + end + = struct + class c = object method m = 123 end + end + and BadClass2 + : sig + val x: int + end + = struct + let x = (new BadClass1.c)#m + end + end in + test 71 true false + with Undefined_recursive_module _ -> + test 71 true true +;; + +(* Coercions *) + +module rec Coerce1 + : sig + val g: int -> int + val f: int -> int + end + = struct + module A = (Coerce1: sig val f: int -> int end) + let g x = x + let f x = if x <= 0 then 1 else A.f (x-1) * x + end +;; + +let _ = + test 80 (Coerce1.f 10) 3628800 +;; + +module CoerceF(S: sig end) = struct + let f1 () = 1 + let f2 () = 2 + let f3 () = 3 + let f4 () = 4 + let f5 () = 5 +end + +module rec Coerce2: sig val f1: unit -> int end = CoerceF(Coerce3) + and Coerce3: sig end = struct end +;; + +let _ = + test 81 (Coerce2.f1 ()) 1 +;; + +module Coerce4(A : sig val f : int -> int end) = struct + let x = 0 + let at a = A.f a +end + +module rec Coerce5 + : sig val blabla: int -> int val f: int -> int end + = struct let blabla x = 0 let f x = 5 end +and Coerce6 + : sig val at: int -> int end + = Coerce4(Coerce5) + +let _ = + test 82 (Coerce6.at 100) 5 +;; + +(* Miscellaneous bug reports *) + +module rec F + : sig type t = X of int | Y of int + val f: t -> bool + end + = struct + type t = X of int | Y of int + let f = function + | X _ -> false + | _ -> true + end;; + +let _ = + test 100 (F.f (F.X 1)) false; + test 101 (F.f (F.Y 2)) true + +(* PR#4316 *) +module G(S : sig val x : int Lazy.t end) = struct include S end + +module M1 = struct let x = lazy 3 end + +let _ = Lazy.force M1.x + +module rec M2 : sig val x : int Lazy.t end = G(M1) + +let _ = + test 102 (Lazy.force M2.x) 3 + +let _ = Gc.full_major() (* will shortcut forwarding in M1.x *) + +module rec M3 : sig val x : int Lazy.t end = G(M1) + +let _ = + test 103 (Lazy.force M3.x) 3 + + +(** Pure type-checking tests: see recmod/*.ml *) diff --git a/test/Moretest/recmod.mli b/test/Moretest/recmod.mli new file mode 100644 index 0000000..6c1fad3 --- /dev/null +++ b/test/Moretest/recmod.mli @@ -0,0 +1,134 @@ +module rec A : + sig type t = Leaf of int | Node of ASet.t val compare : t -> t -> int end +and ASet : Set.S with type elt = A.t +module Fib : sig val f : int -> int end +module After : sig val x : int end +module Before : sig val x : int end +module Strengthen : sig type t val f : t -> t end +module Strengthen2 : + sig + type t + val f : t -> t + module M : sig type u end + module R : sig type v end + end +module PolyRec : + sig + type 'a t = Leaf of 'a | Node of 'a list t * 'a list t + val depth : 'a t -> int + end +module StringSet : Set.S with type elt = string +module rec Expr : + sig + type t = + Var of string + | Const of int + | Add of t * t + | Binding of Binding.t * t + val make_let : string -> t -> t -> t + val fv : t -> StringSet.t + val simpl : t -> t + end +and Binding : + sig + type t = (string * Expr.t) list + val fv : t -> StringSet.t + val bv : t -> StringSet.t + val simpl : t -> t + end +module type ORDERED = + sig + type t + val eq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + end +module type HEAP = + sig + module Elem : ORDERED + type heap + val empty : heap + val isEmpty : heap -> bool + val insert : Elem.t -> heap -> heap + val merge : heap -> heap -> heap + val findMin : heap -> Elem.t + val deleteMin : heap -> heap + end +module Bootstrap : + functor + (MakeH : functor (Element : ORDERED) -> + sig + module Elem : + sig + type t = Element.t + val eq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + end + type heap + val empty : heap + val isEmpty : heap -> bool + val insert : Elem.t -> heap -> heap + val merge : heap -> heap -> heap + val findMin : heap -> Elem.t + val deleteMin : heap -> heap + end) -> + functor (Element : ORDERED) -> + sig + module Elem : + sig + type t = Element.t + val eq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + end + type heap + val empty : heap + val isEmpty : heap -> bool + val insert : Elem.t -> heap -> heap + val merge : heap -> heap -> heap + val findMin : heap -> Elem.t + val deleteMin : heap -> heap + end +module LeftistHeap : + functor (Element : ORDERED) -> + sig + module Elem : + sig + type t = Element.t + val eq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + end + type heap + val empty : heap + val isEmpty : heap -> bool + val insert : Elem.t -> heap -> heap + val merge : heap -> heap -> heap + val findMin : heap -> Elem.t + val deleteMin : heap -> heap + end +module Ints : + sig + type t = int + val eq : 'a -> 'a -> bool + val lt : 'a -> 'a -> bool + val leq : 'a -> 'a -> bool + end +module C : + sig + module Elem : + sig + type t = Ints.t + val eq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + end + type heap = Bootstrap(LeftistHeap)(Ints).heap + val empty : heap + val isEmpty : heap -> bool + val insert : Elem.t -> heap -> heap + val merge : heap -> heap -> heap + val findMin : heap -> Elem.t + val deleteMin : heap -> heap + end diff --git a/test/Moretest/recmod/01bad.ml b/test/Moretest/recmod/01bad.ml new file mode 100644 index 0000000..8a471e0 --- /dev/null +++ b/test/Moretest/recmod/01bad.ml @@ -0,0 +1,2 @@ +(* Bad (t = t) *) +module rec A : sig type t = A.t end = struct type t = A.t end;; diff --git a/test/Moretest/recmod/02bad.ml b/test/Moretest/recmod/02bad.ml new file mode 100644 index 0000000..ac9d639 --- /dev/null +++ b/test/Moretest/recmod/02bad.ml @@ -0,0 +1,4 @@ +(* Bad (t = t) *) +module rec A : sig type t = B.t end = struct type t = B.t end + and B : sig type t = A.t end = struct type t = A.t end;; + diff --git a/test/Moretest/recmod/03ok.ml b/test/Moretest/recmod/03ok.ml new file mode 100644 index 0000000..577ea20 --- /dev/null +++ b/test/Moretest/recmod/03ok.ml @@ -0,0 +1,3 @@ +(* OK (t = int) *) +module rec A : sig type t = B.t end = struct type t = B.t end + and B : sig type t = int end = struct type t = int end;; diff --git a/test/Moretest/recmod/04bad.ml b/test/Moretest/recmod/04bad.ml new file mode 100644 index 0000000..ad3f985 --- /dev/null +++ b/test/Moretest/recmod/04bad.ml @@ -0,0 +1,2 @@ +(* Bad (t = int * t) *) +module rec A : sig type t = int * A.t end = struct type t = int * A.t end;; diff --git a/test/Moretest/recmod/05bad.ml b/test/Moretest/recmod/05bad.ml new file mode 100644 index 0000000..08fe60f --- /dev/null +++ b/test/Moretest/recmod/05bad.ml @@ -0,0 +1,3 @@ +(* Bad (t = t -> int) *) +module rec A : sig type t = B.t -> int end = struct type t = B.t -> int end + and B : sig type t = A.t end = struct type t = A.t end;; diff --git a/test/Moretest/recmod/06ok.ml b/test/Moretest/recmod/06ok.ml new file mode 100644 index 0000000..a220a8e --- /dev/null +++ b/test/Moretest/recmod/06ok.ml @@ -0,0 +1,3 @@ +(* OK (t = <m:t>) *) +module rec A : sig type t = <m:B.t> end = struct type t = <m:B.t> end + and B : sig type t = A.t end = struct type t = A.t end;; diff --git a/test/Moretest/recmod/07bad.ml b/test/Moretest/recmod/07bad.ml new file mode 100644 index 0000000..ec24ea4 --- /dev/null +++ b/test/Moretest/recmod/07bad.ml @@ -0,0 +1,3 @@ +(* Bad (not regular) *) +module rec A : sig type 'a t = <m: 'a list A.t> end + = struct type 'a t = <m: 'a list A.t> end;; diff --git a/test/Moretest/recmod/08bad.ml b/test/Moretest/recmod/08bad.ml new file mode 100644 index 0000000..7df3d47 --- /dev/null +++ b/test/Moretest/recmod/08bad.ml @@ -0,0 +1,5 @@ +(* Bad (not regular) *) +module rec A : sig type 'a t = <m: 'a list B.t; n: 'a array B.t> end + = struct type 'a t = <m: 'a list B.t; n: 'a array B.t> end + and B : sig type 'a t = 'a A.t end = struct type 'a t = 'a A.t end;; + diff --git a/test/Moretest/recmod/09bad.ml b/test/Moretest/recmod/09bad.ml new file mode 100644 index 0000000..ade5bcb --- /dev/null +++ b/test/Moretest/recmod/09bad.ml @@ -0,0 +1,5 @@ +(* Bad (not regular) *) +module rec A : sig type 'a t = 'a B.t end + = struct type 'a t = 'a B.t end + and B : sig type 'a t = <m: 'a list A.t; n: 'a array A.t> end + = struct type 'a t = <m: 'a list A.t; n: 'a array A.t> end;; diff --git a/test/Moretest/recmod/10ok.ml b/test/Moretest/recmod/10ok.ml new file mode 100644 index 0000000..3094a42 --- /dev/null +++ b/test/Moretest/recmod/10ok.ml @@ -0,0 +1,5 @@ +(* OK *) +module rec A : sig type 'a t = 'a array B.t * 'a list B.t end + = struct type 'a t = 'a array B.t * 'a list B.t end + and B : sig type 'a t = <m: 'a B.t> end + = struct type 'a t = <m: 'a B.t> end;; diff --git a/test/Moretest/recmod/11bad.ml b/test/Moretest/recmod/11bad.ml new file mode 100644 index 0000000..e18339a --- /dev/null +++ b/test/Moretest/recmod/11bad.ml @@ -0,0 +1,5 @@ +(* Bad (not regular) *) +module rec A : sig type 'a t = 'a list B.t end + = struct type 'a t = 'a list B.t end + and B : sig type 'a t = <m: 'a array B.t> end + = struct type 'a t = <m: 'a array B.t> end;; diff --git a/test/Moretest/recmod/12bad.ml b/test/Moretest/recmod/12bad.ml new file mode 100644 index 0000000..71100e6 --- /dev/null +++ b/test/Moretest/recmod/12bad.ml @@ -0,0 +1,13 @@ +(* Bad (not regular) *) +module rec M : + sig + class ['a] c : 'a -> object + method map : ('a -> 'b) -> 'b M.c + end + end + = struct + class ['a] c (x : 'a) = object + method map : 'b. ('a -> 'b) -> 'b M.c + = fun f -> new M.c (f x) + end + end;; diff --git a/test/Moretest/recmod/13ok.ml b/test/Moretest/recmod/13ok.ml new file mode 100644 index 0000000..729afd5 --- /dev/null +++ b/test/Moretest/recmod/13ok.ml @@ -0,0 +1,5 @@ +(* OK *) +class type [ 'node ] extension = object method node : 'node end +class type [ 'ext ] node = object constraint 'ext = 'ext node #extension end +class x = object method node : x node = assert false end +type t = x node;; diff --git a/test/Moretest/recmod/14bad.ml b/test/Moretest/recmod/14bad.ml new file mode 100644 index 0000000..5c66536 --- /dev/null +++ b/test/Moretest/recmod/14bad.ml @@ -0,0 +1,17 @@ +(* Bad - PR 4261 *) + +module PR_4261 = struct + module type S = + sig + type t + end + + module type T = + sig + module D : S + type t = D.t + end + + module rec U : T with module D = U' = U + and U' : S with type t = U'.t = U +end;; diff --git a/test/Moretest/recmod/15bad.ml b/test/Moretest/recmod/15bad.ml new file mode 100644 index 0000000..b387ae5 --- /dev/null +++ b/test/Moretest/recmod/15bad.ml @@ -0,0 +1,3 @@ +(* Bad - PR 4512 *) +module type S' = sig type t = int end +module rec M : S' with type t = M.t = struct type t = M.t end;; diff --git a/test/Moretest/recmod/16ok.ml b/test/Moretest/recmod/16ok.ml new file mode 100644 index 0000000..f42de7b --- /dev/null +++ b/test/Moretest/recmod/16ok.ml @@ -0,0 +1,31 @@ +(* PR#4450 *) + +module PR_4450_1 = struct + module type MyT = sig type 'a t = Succ of 'a t end + module MyMap(X : MyT) = X + module rec MyList : MyT = MyMap(MyList) +end;; + +module PR_4450_2 = struct + module type MyT = sig + type 'a wrap = My of 'a t + and 'a t = private < map : 'b. ('a -> 'b) ->'b wrap; .. > + val create : 'a list -> 'a t + end + module MyMap(X : MyT) = struct + include X + class ['a] c l = object (self) + method map : 'b. ('a -> 'b) -> 'b wrap = + fun f -> My (create (List.map f l)) + end + end + module rec MyList : sig + type 'a wrap = My of 'a t + and 'a t = < map : 'b. ('a -> 'b) ->'b wrap > + val create : 'a list -> 'a t + end = struct + include MyMap(MyList) + let create l = new c l + end +end;; + diff --git a/test/Moretest/recmod/17ok.ml b/test/Moretest/recmod/17ok.ml new file mode 100644 index 0000000..a2ea895 --- /dev/null +++ b/test/Moretest/recmod/17ok.ml @@ -0,0 +1,42 @@ +(* A synthetic example of bootstrapped data structure + (suggested by J-C Filliatre) *) + +module type ORD = sig + type t + val compare : t -> t -> int +end + +module type SET = sig + type elt + type t + val iter : (elt -> unit) -> t -> unit +end + +type 'a tree = E | N of 'a tree * 'a * 'a tree + +module Bootstrap2 + (MakeDiet : functor (X: ORD) -> SET with type t = X.t tree and type elt = X.t) + : SET with type elt = int = +struct + + type elt = int + + module rec Elt : sig + type t = I of int * int | D of int * Diet.t * int + val compare : t -> t -> int + val iter : (int -> unit) -> t -> unit + end = + struct + type t = I of int * int | D of int * Diet.t * int + let compare x1 x2 = 0 + let rec iter f = function + | I (l, r) -> for i = l to r do f i done + | D (_, d, _) -> Diet.iter (iter f) d + end + + and Diet : SET with type t = Elt.t tree and type elt = Elt.t = MakeDiet(Elt) + + type t = Diet.t + let iter f = Diet.iter (Elt.iter f) +end + diff --git a/test/Moretest/recmod/18ok.ml b/test/Moretest/recmod/18ok.ml new file mode 100644 index 0000000..4f5814d --- /dev/null +++ b/test/Moretest/recmod/18ok.ml @@ -0,0 +1,26 @@ +(* PR 4470: simplified from OMake's sources *) + +module rec DirElt + : sig + type t = DirRoot | DirSub of DirHash.t + end + = struct + type t = DirRoot | DirSub of DirHash.t + end + +and DirCompare + : sig + type t = DirElt.t + end + = struct + type t = DirElt.t + end + +and DirHash + : sig + type t = DirElt.t list + end + = struct + type t = DirCompare.t list + end + diff --git a/test/Moretest/recmod/19ok.ml b/test/Moretest/recmod/19ok.ml new file mode 100644 index 0000000..cd2dde8 --- /dev/null +++ b/test/Moretest/recmod/19ok.ml @@ -0,0 +1,13 @@ +(* PR 4758, PR 4266 *) + +module PR_4758 = struct + module type S = sig end + module type Mod = sig + module Other : S + end + module rec A : S = struct + end and C : sig include Mod with module Other = A end = struct + module Other = A + end +end + diff --git a/test/Moretest/recmod/20ok.ml b/test/Moretest/recmod/20ok.ml new file mode 100644 index 0000000..fec78c1 --- /dev/null +++ b/test/Moretest/recmod/20ok.ml @@ -0,0 +1,30 @@ +(* PR 4557 *) +module PR_4557 = struct + module F ( X : Set.OrderedType ) = struct + module rec Mod : sig + module XSet : + sig + type elt = X.t + type t = Set.Make( X ).t + end + module XMap : + sig + type key = X.t + type 'a t = 'a Map.Make(X).t + end + type elt = X.t + type t = XSet.t XMap.t + val compare: t -> t -> int + end + = + struct + module XSet = Set.Make( X ) + module XMap = Map.Make( X ) + + type elt = X.t + type t = XSet.t XMap.t + let compare = (fun x y -> 0) + end + and ModSet : Set.S with type elt = Mod.t = Set.Make( Mod ) + end +end diff --git a/test/Moretest/recmod/21ok.ml b/test/Moretest/recmod/21ok.ml new file mode 100644 index 0000000..0415fe4 --- /dev/null +++ b/test/Moretest/recmod/21ok.ml @@ -0,0 +1,27 @@ +module F ( X : Set.OrderedType ) = struct + module rec Mod : sig + module XSet : + sig + type elt = X.t + type t = Set.Make( X ).t + end + module XMap : + sig + type key = X.t + type 'a t = 'a Map.Make(X).t + end + type elt = X.t + type t = XSet.t XMap.t + val compare: t -> t -> int + end + = + struct + module XSet = Set.Make( X ) + module XMap = Map.Make( X ) + + type elt = X.t + type t = XSet.t XMap.t + let compare = (fun x y -> 0) + end + and ModSet : Set.S with type elt = Mod.t = Set.Make( Mod ) +end diff --git a/test/Moretest/recvalues.ml b/test/Moretest/recvalues.ml new file mode 100644 index 0000000..c00ced8 --- /dev/null +++ b/test/Moretest/recvalues.ml @@ -0,0 +1,38 @@ +(* Recursive value definitions *) + +let _ = + let rec x = 1 :: x in + if match x with + 1 :: x' -> x == x' + | _ -> false + then print_string "Test 1: passed\n" + else print_string "Test 1: FAILED\n"; + let one = 1 in + let rec y = (one, one+1) :: y in + if match y with + (1,2) :: y' -> y == y' + | _ -> false + then print_string "Test 2: passed\n" + else print_string "Test 2: FAILED\n"; + let rec z = (Gc.minor(); (one, one+1)) :: z in + (* Trash the minor generation *) + for i = 0 to 50000 do ignore (ref 0) done; + if match z with + (1,2) :: z' -> z == z' + | _ -> false + then print_string "Test 3: passed\n" + else print_string "Test 3: FAILED\n"; +;; + +let rec s = "bar" +and idx = 1 +and x1 = let f x = Printf.printf "%s\n" x in f "foo"; s, x4 +and x2 = [| x1; x1 |] +and x3 = (fun () -> fst (x2.(idx))) :: x3 +and x4 = {contents = x3} +;; + +Gc.minor ();; +if (List.hd (!(snd (x2.(0))))) () == s +then print_string "Test 4: passed\n" +else print_string "Test 4: FAILED\n" diff --git a/test/Moretest/regexp.ml b/test/Moretest/regexp.ml new file mode 100644 index 0000000..7cb75b8 --- /dev/null +++ b/test/Moretest/regexp.ml @@ -0,0 +1,993 @@ +open Printf + +let build_result ngroups input = + let res = Array.make (ngroups + 1) "~" in + for i = 0 to ngroups do + try + res.(i) <- Str.matched_group i input + with Not_found -> () + done; + res + +let search_forward re ng input start = + try + ignore(Str.search_forward re input start); + build_result ng input + with Not_found -> + [||] + +let search_backward re ng input start = + try + ignore(Str.search_backward re input start); + build_result ng input + with Not_found -> + [||] + +let partial_match re ng input start = + if Str.string_partial_match re input start + then build_result ng input + else [||] + +let start_test msg = + print_newline(); printf "%s\n " msg + +let num_failures = ref 0 + +let test res1 res2 = + if res1 = res2 + then print_char '.' + else begin print_string " FAIL "; incr num_failures end + +let test_search_forward r ng s exp = + test (search_forward r ng s 0) exp + +let test_search_backward r ng s exp = + test (search_backward r ng s (String.length s)) exp + +let test_partial_match r ng s exp = + test (partial_match r ng s 0) exp + +let end_test () = + print_newline(); + if !num_failures = 0 then + printf "All tests passed\n" + else begin + printf "TEST FAILED: %d failure(s)\n" !num_failures; + exit 2 + end + +let automated_test() = + + (** Forward searches *) + start_test "Search for /the quick brown fox/"; + let r = Str.regexp "the quick brown fox" in + let n = 0 in + test_search_forward r n "the quick brown fox" + [|"the quick brown fox"|]; + test_search_forward r n "What do you know about the quick brown fox?" + [|"the quick brown fox"|]; + test_search_forward r n "The quick brown FOX" + [||]; + test_search_forward r n "What do you know about THE QUICK BROWN FOX?" + [||]; + + start_test "Search for /the quick brown fox/ (case-insensitive)"; + let r = Str.regexp_case_fold "the quick brown fox" in + let n = 0 in + test_search_forward r n "the quick brown fox" + [|"the quick brown fox"|]; + test_search_forward r n "What do you know about the quick brown fox?" + [|"the quick brown fox"|]; + test_search_forward r n "The quick brown FOX" + [|"The quick brown FOX"|]; + test_search_forward r n "What do you know about THE QUICK BROWN FOX?" + [|"THE QUICK BROWN FOX"|]; + test_search_forward r n "The slow white snail" + [||]; + + start_test "Search for /a*abc?xyz+pqrrrabbb*xyyyyy?pq?q?q?q?q?q?AB*zz/"; + let r = Str.regexp "a*abc?xyz+pqrrrabbb*xyyyyy?pq?q?q?q?q?q?AB*zz" in + let n = 0 in + test_search_forward r n "abxyzpqrrrabbxyyyypqAzz" + [|"abxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "abxyzpqrrrabbxyyyypqAzz" + [|"abxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aabxyzpqrrrabbxyyyypqAzz" + [|"aabxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaabxyzpqrrrabbxyyyypqAzz" + [|"aaabxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaaabxyzpqrrrabbxyyyypqAzz" + [|"aaaabxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "abcxyzpqrrrabbxyyyypqAzz" + [|"abcxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aabcxyzpqrrrabbxyyyypqAzz" + [|"aabcxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypAzz" + [|"aaabcxyzpqrrrabbxyyyypAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqAzz" + [|"aaabcxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqAzz" + [|"aaabcxyzpqrrrabbxyyyypqqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqqAzz" + [|"aaabcxyzpqrrrabbxyyyypqqqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqqqAzz" + [|"aaabcxyzpqrrrabbxyyyypqqqqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqqqqAzz" + [|"aaabcxyzpqrrrabbxyyyypqqqqqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqqqqqAzz" + [|"aaabcxyzpqrrrabbxyyyypqqqqqqAzz"|]; + test_search_forward r n "aaaabcxyzpqrrrabbxyyyypqAzz" + [|"aaaabcxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "abxyzzpqrrrabbxyyyypqAzz" + [|"abxyzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aabxyzzzpqrrrabbxyyyypqAzz" + [|"aabxyzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaabxyzzzzpqrrrabbxyyyypqAzz" + [|"aaabxyzzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaaabxyzzzzpqrrrabbxyyyypqAzz" + [|"aaaabxyzzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "abcxyzzpqrrrabbxyyyypqAzz" + [|"abcxyzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aabcxyzzzpqrrrabbxyyyypqAzz" + [|"aabcxyzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaabcxyzzzzpqrrrabbxyyyypqAzz" + [|"aaabcxyzzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaaabcxyzzzzpqrrrabbxyyyypqAzz" + [|"aaaabcxyzzzzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "aaaabcxyzzzzpqrrrabbbxyyyypqAzz" + [|"aaaabcxyzzzzpqrrrabbbxyyyypqAzz"|]; + test_search_forward r n "aaaabcxyzzzzpqrrrabbbxyyyyypqAzz" + [|"aaaabcxyzzzzpqrrrabbbxyyyyypqAzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypABzz" + [|"aaabcxyzpqrrrabbxyyyypABzz"|]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypABBzz" + [|"aaabcxyzpqrrrabbxyyyypABBzz"|]; + test_search_forward r n ">>>aaabxyzpqrrrabbxyyyypqAzz" + [|"aaabxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n ">aaaabxyzpqrrrabbxyyyypqAzz" + [|"aaaabxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n ">>>>abcxyzpqrrrabbxyyyypqAzz" + [|"abcxyzpqrrrabbxyyyypqAzz"|]; + test_search_forward r n "abxyzpqrrabbxyyyypqAzz" + [||]; + test_search_forward r n "abxyzpqrrrrabbxyyyypqAzz" + [||]; + test_search_forward r n "abxyzpqrrrabxyyyypqAzz" + [||]; + test_search_forward r n "aaaabcxyzzzzpqrrrabbbxyyyyyypqAzz" + [||]; + test_search_forward r n "aaaabcxyzzzzpqrrrabbbxyyypqAzz" + [||]; + test_search_forward r n "aaabcxyzpqrrrabbxyyyypqqqqqqqAzz" + [||]; + + start_test "Search for /^abc\\(abc\\)?zz/"; + let r = Str.regexp "^abc\\(abc\\)?zz" in + let n = 1 in + test_search_forward r n "abczz" + [|"abczz"; "~"|]; + test_search_forward r n "abcabczz" + [|"abcabczz"; "abc"|]; + test_search_forward r n "zz" + [||]; + test_search_forward r n "abcabcabczz" + [||]; + test_search_forward r n ">>abczz" + [||]; + + start_test "Search for /^\\(b+\\|a\\)\\(b+\\|a\\)?c/"; + let r = Str.regexp "^\\(b+\\|a\\)\\(b+\\|a\\)?c" in + let n = 2 in + test_search_forward r n "bc" + [|"bc"; "b"; "~"|]; + test_search_forward r n "bbc" + [|"bbc"; "bb"; "~"|]; + test_search_forward r n "bbbc" + [|"bbbc"; "bbb"; "~"|]; + test_search_forward r n "bac" + [|"bac"; "b"; "a"|]; + test_search_forward r n "bbac" + [|"bbac"; "bb"; "a"|]; + test_search_forward r n "aac" + [|"aac"; "a"; "a"|]; + test_search_forward r n "abbbbbbbbbbbc" + [|"abbbbbbbbbbbc"; "a"; "bbbbbbbbbbb"|]; + test_search_forward r n "bbbbbbbbbbbac" + [|"bbbbbbbbbbbac"; "bbbbbbbbbbb"; "a"|]; + test_search_forward r n "aaac" + [||]; + test_search_forward r n "abbbbbbbbbbbac" + [||]; + + start_test "Search for /r\\(\\(g*\\|k\\)y?\\)*A/"; + let r = Str.regexp "r\\(\\(g*\\|k\\)y?\\)*A" in + let n = 2 in + test_search_forward r n "ArA" + [|"rA"; "~"; "~"|]; + test_search_forward r n "ArkA" + [|"rkA"; "k"; "k"|]; + test_search_forward r n "AryA" + [|"ryA"; "y"; ""|]; + test_search_forward r n "ArgggkyggkA" + [|"rgggkyggkA"; "k"; "k"|]; + + start_test "Search for /A\\(\\(t\\|v\\)\\(q?\\|n\\)\\)*A/"; + let r = Str.regexp "A\\(\\(t\\|v\\)\\(q?\\|n\\)\\)*A" in + let n = 3 in + test_search_forward r n "AvA" + [|"AvA"; "v"; "v"; ""|]; + + start_test "Search for /A\\(\\(b\\(\\(d\\|l*\\)?\\|w\\)\\)*a\\)A/"; + let r = Str.regexp "A\\(\\(b\\(\\(d\\|l*\\)?\\|w\\)\\)*a\\)A" in + let n = 4 in + test_search_forward r n "AbbaA" + [|"AbbaA"; "bba"; "b"; ""; ""|]; + + start_test "Search for /\\(\\|f\\)*x/"; + let r = Str.regexp "\\(\\|f\\)*x" in + let n = 1 in + test_search_forward r n "abcd" + [||]; + test_search_forward r n "fffff" + [||]; + test_search_forward r n "fffxab" + [|"fffx"; "f"|]; + test_search_forward r n "zzzxab" + [|"x"; "~"|]; + + start_test "Search for /\\(\\|f\\)+x/"; + let r = Str.regexp "\\(\\|f\\)+x" in + let n = 1 in + test_search_forward r n "abcd" + [||]; + test_search_forward r n "fffff" + [||]; + test_search_forward r n "fffxab" + [|"fffx"; "f"|]; + test_search_forward r n "zzzxab" + [|"x"; ""|]; + + start_test "Search for /A\\(.?\\)*A/"; + let r = Str.regexp "A\\(.?\\)*A" in + let n = 1 in + test_search_forward r n "AA" + [|"AA"; "~"|]; + test_search_forward r n "AAA" + [|"AAA"; "A"|]; + test_search_forward r n "AbA" + [|"AbA"; "b"|]; + test_search_forward r n "A" + [||]; + + start_test "Search for /\\([ab]*\\)\\1+c/"; + let r = Str.regexp "\\([ab]*\\)\\1+c" in + let n = 1 in + test_search_forward r n "abababc" + [| "abababc"; "ab" |]; + test_search_forward r n "abbc" + [| "bbc"; "b" |]; + test_search_forward r n "abc" + [| "c"; "" |]; + + start_test "Search for /^\\(\\(b+\\|a\\)\\(b+\\|a\\)?\\)?bc/"; + let r = Str.regexp "^\\(\\(b+\\|a\\)\\(b+\\|a\\)?\\)?bc" in + let n = 3 in + test_search_forward r n "bbc" + [|"bbc"; "b"; "b"; "~"|]; + + start_test "Search for /^\\(\\(b*\\|ba\\)\\(b*\\|ba\\)?\\)?bc/"; + let r = Str.regexp "^\\(\\(b*\\|ba\\)\\(b*\\|ba\\)?\\)?bc" in + let n = 3 in + test_search_forward r n "babc" + [|"babc"; "ba"; ""; "ba"|]; + test_search_forward r n "bbabc" + [|"bbabc"; "bba"; "b"; "ba"|]; + test_search_forward r n "bababc" + [|"bababc"; "baba"; "ba"; "ba"|]; + test_search_forward r n "bababbc" + [||]; + test_search_forward r n "babababc" + [||]; + + start_test "Search for /^[]abcde]/"; + let r = Str.regexp "^[]abcde]" in + let n = 0 in + test_search_forward r n "athing" + [|"a"|]; + test_search_forward r n "bthing" + [|"b"|]; + test_search_forward r n "]thing" + [|"]"|]; + test_search_forward r n "cthing" + [|"c"|]; + test_search_forward r n "dthing" + [|"d"|]; + test_search_forward r n "ething" + [|"e"|]; + test_search_forward r n "fthing" + [||]; + test_search_forward r n "[thing" + [||]; + test_search_forward r n "\\\\thing" + [||]; + + start_test "Search for /^[]cde]/"; + let r = Str.regexp "^[]cde]" in + let n = 0 in + test_search_forward r n "]thing" + [|"]"|]; + test_search_forward r n "cthing" + [|"c"|]; + test_search_forward r n "dthing" + [|"d"|]; + test_search_forward r n "ething" + [|"e"|]; + test_search_forward r n "athing" + [||]; + test_search_forward r n "fthing" + [||]; + + start_test "Search for /^[^]abcde]/"; + let r = Str.regexp "^[^]abcde]" in + let n = 0 in + test_search_forward r n "fthing" + [|"f"|]; + test_search_forward r n "[thing" + [|"["|]; + test_search_forward r n "\\\\thing" + [|"\\"|]; + test_search_forward r n "athing" + [||]; + test_search_forward r n "bthing" + [||]; + test_search_forward r n "]thing" + [||]; + test_search_forward r n "cthing" + [||]; + test_search_forward r n "dthing" + [||]; + test_search_forward r n "ething" + [||]; + + start_test "Search for /^[^]cde]/"; + let r = Str.regexp "^[^]cde]" in + let n = 0 in + test_search_forward r n "athing" + [|"a"|]; + test_search_forward r n "fthing" + [|"f"|]; + test_search_forward r n "]thing" + [||]; + test_search_forward r n "cthing" + [||]; + test_search_forward r n "dthing" + [||]; + test_search_forward r n "ething" + [||]; + + start_test "Search for /^ÿ/"; + let r = Str.regexp "^ÿ" in + let n = 0 in + test_search_forward r n "ÿ" + [|"ÿ"|]; + + start_test "Search for /^[0-9]+$/"; + let r = Str.regexp "^[0-9]+$" in + let n = 0 in + test_search_forward r n "0" + [|"0"|]; + test_search_forward r n "1" + [|"1"|]; + test_search_forward r n "2" + [|"2"|]; + test_search_forward r n "3" + [|"3"|]; + test_search_forward r n "4" + [|"4"|]; + test_search_forward r n "5" + [|"5"|]; + test_search_forward r n "6" + [|"6"|]; + test_search_forward r n "7" + [|"7"|]; + test_search_forward r n "8" + [|"8"|]; + test_search_forward r n "9" + [|"9"|]; + test_search_forward r n "10" + [|"10"|]; + test_search_forward r n "100" + [|"100"|]; + test_search_forward r n "abc" + [||]; + + start_test "Search for /^.*nter/"; + let r = Str.regexp "^.*nter" in + let n = 0 in + test_search_forward r n "enter" + [|"enter"|]; + test_search_forward r n "inter" + [|"inter"|]; + test_search_forward r n "uponter" + [|"uponter"|]; + + start_test "Search for /^xxx[0-9]+$/"; + let r = Str.regexp "^xxx[0-9]+$" in + let n = 0 in + test_search_forward r n "xxx0" + [|"xxx0"|]; + test_search_forward r n "xxx1234" + [|"xxx1234"|]; + test_search_forward r n "xxx" + [||]; + + start_test "Search for /^.+[0-9][0-9][0-9]$/"; + let r = Str.regexp "^.+[0-9][0-9][0-9]$" in + let n = 0 in + test_search_forward r n "x123" + [|"x123"|]; + test_search_forward r n "xx123" + [|"xx123"|]; + test_search_forward r n "123456" + [|"123456"|]; + test_search_forward r n "123" + [||]; + test_search_forward r n "x123x" + [||]; + + start_test "Search for /^\\([^!]+\\)!\\(.+\\)=apquxz\\.ixr\\.zzz\\.ac\\.uk$/"; + let r = Str.regexp "^\\([^!]+\\)!\\(.+\\)=apquxz\\.ixr\\.zzz\\.ac\\.uk$" in + let n = 2 in + test_search_forward r n "abc!pqr=apquxz.ixr.zzz.ac.uk" + [|"abc!pqr=apquxz.ixr.zzz.ac.uk"; "abc"; "pqr"|]; + test_search_forward r n "!pqr=apquxz.ixr.zzz.ac.uk" + [||]; + test_search_forward r n "abc!=apquxz.ixr.zzz.ac.uk" + [||]; + test_search_forward r n "abc!pqr=apquxz:ixr.zzz.ac.uk" + [||]; + test_search_forward r n "abc!pqr=apquxz.ixr.zzz.ac.ukk" + [||]; + + start_test "Search for /\\([0-9a-f:]+\\)$/"; + let r = Str.regexp_case_fold "\\([0-9a-f:]+\\)$" in + let n = 1 in + test_search_forward r n "0abc" + [|"0abc"; "0abc"|]; + test_search_forward r n "abc" + [|"abc"; "abc"|]; + test_search_forward r n "fed" + [|"fed"; "fed"|]; + test_search_forward r n "E" + [|"E"; "E"|]; + test_search_forward r n "::" + [|"::"; "::"|]; + test_search_forward r n "5f03:12C0::932e" + [|"5f03:12C0::932e"; "5f03:12C0::932e"|]; + test_search_forward r n "fed def" + [|"def"; "def"|]; + test_search_forward r n "Any old stuff" + [|"ff"; "ff"|]; + test_search_forward r n "0zzz" + [||]; + test_search_forward r n "gzzz" + [||]; + test_search_forward r n "fed " + [||]; + test_search_forward r n "Any old rubbish" + [||]; + + start_test "Search for /^[a-z0-9][a-z0-9-]*\\(\\.[a-z0-9][A-Z0-9-]*\\)*\\.$/"; + let r = Str.regexp_case_fold "^[a-z0-9][a-z0-9-]*\\(\\.[a-z0-9][A-Z0-9-]*\\)*\\.$" in + let n = 1 in + test_search_forward r n "a." + [|"a."; "~"|]; + test_search_forward r n "Z." + [|"Z."; "~"|]; + test_search_forward r n "2." + [|"2."; "~"|]; + test_search_forward r n "ab-c." + [|"ab-c."; "~"|]; + test_search_forward r n "ab-c.pq-r." + [|"ab-c.pq-r."; ".pq-r"|]; + test_search_forward r n "sxk.zzz.ac.uk." + [|"sxk.zzz.ac.uk."; ".uk"|]; + test_search_forward r n "sxk.ZZZ.ac.UK." + [|"sxk.ZZZ.ac.UK."; ".UK"|]; + test_search_forward r n "x-.y-." + [|"x-.y-."; ".y-"|]; + test_search_forward r n "-abc.peq." + [||]; + + start_test "Search for /^\\*\\.[a-z]\\([a-z0-9-]*[a-z0-9]+\\)?\\(\\.[a-z]\\([a-z0-9-]*[a-z0-9]+\\)?\\)*$/"; + let r = Str.regexp "^\\*\\.[a-z]\\([a-z0-9-]*[a-z0-9]+\\)?\\(\\.[a-z]\\([a-z0-9-]*[a-z0-9]+\\)?\\)*$" in + let n = 3 in + test_search_forward r n "*.a" + [|"*.a"; "~"; "~"; "~"|]; + test_search_forward r n "*.b0-a" + [|"*.b0-a"; "0-a"; "~"; "~"|]; + test_search_forward r n "*.c3-b.c" + [|"*.c3-b.c"; "3-b"; ".c"; "~"|]; + test_search_forward r n "*.c-a.b-c" + [|"*.c-a.b-c"; "-a"; ".b-c"; "-c"|]; + test_search_forward r n "*.0" + [||]; + test_search_forward r n "*.a-" + [||]; + test_search_forward r n "*.a-b.c-" + [||]; + test_search_forward r n "*.c-a.0-c" + [||]; + + start_test "Search for /^[0-9a-fA-F]\\(\\.[0-9a-fA-F]\\)*$/"; + let r = Str.regexp "^[0-9a-fA-F]\\(\\.[0-9a-fA-F]\\)*$" in + let n = 1 in + test_search_forward r n "a.b.c.d" + [|"a.b.c.d"; ".d"|]; + test_search_forward r n "A.B.C.D" + [|"A.B.C.D"; ".D"|]; + test_search_forward r n "a.b.c.1.2.3.C" + [|"a.b.c.1.2.3.C"; ".C"|]; + test_search_forward r n "a.b.c.dz" + [||]; + test_search_forward r n "za" + [||]; + + start_test "Search for /^\\\".*\\\" *\\(;.*\\)?$/"; + let r = Str.regexp "^\\\".*\\\" *\\(;.*\\)?$" in + let n = 1 in + test_search_forward r n "\"1234\"" + [|"\"1234\""; "~"|]; + test_search_forward r n "\"abcd\" ;" + [|"\"abcd\" ;"; ";"|]; + test_search_forward r n "\"\" ; rhubarb" + [|"\"\" ; rhubarb"; "; rhubarb"|]; + test_search_forward r n "\"1234\" : things" + [||]; + + start_test "Search for /^\\(a\\(b\\(c\\)\\)\\)\\(d\\(e\\(f\\)\\)\\)\\(h\\(i\\(j\\)\\)\\)$/"; + let r = Str.regexp "^\\(a\\(b\\(c\\)\\)\\)\\(d\\(e\\(f\\)\\)\\)\\(h\\(i\\(j\\)\\)\\)$" in + let n = 9 in + test_search_forward r n "abcdefhij" + [|"abcdefhij"; "abc"; "bc"; "c"; "def"; "ef"; "f"; "hij"; "ij"; "j"|]; + + start_test "Search for /^[.^$|()*+?{,}]+/"; + let r = Str.regexp "^[.^$|()*+?{,}]+" in + let n = 0 in + test_search_forward r n ".^$*(+)|{?,?}" + [|".^$*(+)|{?,?}"|]; + + start_test "Search for /\\(cat\\(a\\(ract\\|tonic\\)\\|erpillar\\)\\) \\1\\(\\)2\\(3\\)/"; + let r = Str.regexp "\\(cat\\(a\\(ract\\|tonic\\)\\|erpillar\\)\\) \\1\\(\\)2\\(3\\)" in + let n = 5 in + test_search_forward r n "cataract cataract23" + [|"cataract cataract23"; "cataract"; "aract"; "ract"; ""; "3"|]; + test_search_forward r n "catatonic catatonic23" + [|"catatonic catatonic23"; "catatonic"; "atonic"; "tonic"; ""; "3"|]; + test_search_forward r n "caterpillar caterpillar23" + [|"caterpillar caterpillar23"; "caterpillar"; "erpillar"; "~"; ""; "3"|]; + + start_test "Search for /^From +\\([^ ]+\\) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/"; + let r = Str.regexp "^From +\\([^ ]+\\) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]" in + let n = 1 in + test_search_forward r n "From abcd Mon Sep 01 12:33:02 1997" + [|"From abcd Mon Sep 01 12:33"; "abcd"|]; + + start_test "Search for /\\ba/"; + let r = Str.regexp "\\ba" in + let n = 0 in + test_search_forward r n "abcd" + [|"a"|]; + test_search_forward r n "the a" + [|"a"|]; + test_search_forward r n ".ab" + [|"a"|]; + test_search_forward r n "bad" + [||]; + test_search_forward r n "the ba" + [||]; + test_search_forward r n "ba." + [||]; + + start_test "Search for /a\\b/"; + let r = Str.regexp "a\\b" in + let n = 0 in + test_search_forward r n "a" + [|"a"|]; + test_search_forward r n "bcda" + [|"a"|]; + test_search_forward r n "a foo" + [|"a"|]; + test_search_forward r n "a." + [|"a"|]; + test_search_forward r n "bad" + [||]; + test_search_forward r n "ab" + [||]; + + start_test "Search for /\\([a-z]*\\)b/"; + let r = Str.regexp "\\([a-z]*\\)b" in + let n = 1 in + test_search_forward r n "abbb" + [|"abbb"; "abb"|]; + + start_test "Search for /\\([a-z]+\\)b/"; + let r = Str.regexp "\\([a-z]+\\)b" in + let n = 1 in + test_search_forward r n "abbb" + [|"abbb"; "abb"|]; + + start_test "Search for /\\([a-z]?\\)b/"; + let r = Str.regexp "\\([a-z]?\\)b" in + let n = 1 in + test_search_forward r n "bbbb" + [|"bb"; "b"|]; + + start_test "Search for /^a/"; + let r = Str.regexp "^a" in + let n = 0 in + test_search_forward r n "abcdef" + [|"a"|]; + test_search_forward r n "zzzz\nabcdef" + [|"a"|]; + + start_test "Search for /a$/"; + let r = Str.regexp "a$" in + let n = 0 in + test_search_forward r n "xyza" + [|"a"|]; + test_search_forward r n "xyza\nbcdef" + [|"a"|]; + + start_test "Null characters in regexps"; + let r = Str.regexp "ab\000cd" in + let n = 0 in + test_search_forward r n "qerpoiuab\000cdwerltkh" + [| "ab\000cd" |]; + let r = Str.regexp "\000cd" in + let n = 0 in + test_search_forward r n "qerpoiuab\000cdwerltkh" + [| "\000cd" |]; + + (** Backward searches *) + start_test "Backward search for /the quick/"; + let r = Str.regexp "the quick" in + let n = 0 in + test_search_backward r n "the quick brown fox" + [|"the quick"|]; + test_search_backward r n "What do you know about the quick brown fox?" + [|"the quick"|]; + test_search_backward r n "The quick brown FOX" + [||]; + test_search_backward r n "What do you know about THE QUICK BROWN FOX?" + [||]; + + start_test "Backward search for /a\\([0-9]+\\)/"; + let r = Str.regexp "a\\([0-9]+\\)" in + let n = 1 in + test_search_backward r n "a123 a456zzzz" + [|"a456"; "456"|]; + test_search_backward r n "ab123" + [||]; + + (** Partial match searches *) + + start_test "Partial match for /partial match/"; + let r = Str.regexp "partial match" in + let n = 0 in + test_partial_match r n "" + [|""|]; + test_partial_match r n "partial matching" + [|"partial match"|]; + test_partial_match r n "partial m" + [|"partial m"|]; + + start_test "Partial match for /\\(partial\\)\\|\\(match\\)/"; + let r = Str.regexp "\\(partial\\)\\|\\(match\\)" in + let n = 2 in + test_partial_match r n "" + [|""; "~"; "~"|]; + test_partial_match r n "part" + [|"part"; "~"; "~"|]; + test_partial_match r n "partial" + [|"partial"; "partial"; "~"|]; + test_partial_match r n "matching" + [|"match"; "~"; "match"|]; + test_partial_match r n "mat" + [|"mat"; "~"; "~"|]; + test_partial_match r n "zorglub" + [||]; + + (** Replacement *) + start_test "Global replacement"; + test (Str.global_replace (Str.regexp "[aeiou]") ".." + "abcdefghijklmnopqrstuvwxyz") + "..bcd..fgh..jklmn..pqrst..vwxyz"; + test (Str.global_replace (Str.regexp "[0-9]\\([0-9]*\\)") "-\\0-\\1-" + "abc012def3ghi45") + "abc-012-12-def-3--ghi-45-5-"; + test (Str.global_replace (Str.regexp "[0-9]?") "." + "abc012def3ghi45") + ".a.b.c....d.e.f..g.h.i..."; + + start_test "First replacement"; + test (Str.replace_first (Str.regexp "[eiou]") ".." + "abcdefghijklmnopqrstuvwxyz") + "abcd..fghijklmnopqrstuvwxyz"; + test (Str.replace_first (Str.regexp "[0-9]\\([0-9]*\\)") "-\\0-\\1-" + "abc012def3ghi45") + "abc-012-12-def3ghi45"; + + (** Splitting *) + start_test "Splitting"; + test (Str.split (Str.regexp "[ \t]+") "si non e vero") + ["si"; "non"; "e"; "vero"]; + test (Str.split (Str.regexp "[ \t]+") " si non\te vero\t") + ["si"; "non"; "e"; "vero"]; + test (Str.bounded_split (Str.regexp "[ \t]+") " si non e vero " 3) + ["si"; "non"; "e vero "]; + test (Str.split (Str.regexp "[ \t]*") "si non e vero") + ["s"; "i"; "n"; "o"; "n"; "e"; "v"; "e"; "r"; "o"]; + test (Str.split_delim (Str.regexp "[ \t]+") " si non e vero\t") + [""; "si"; "non"; "e"; "vero"; ""]; + test (Str.full_split (Str.regexp "[ \t]+") " si non\te vero\t") + [Str.Delim " "; Str.Text "si"; + Str.Delim " "; Str.Text "non"; + Str.Delim "\t"; Str.Text "e"; + Str.Delim " "; Str.Text "vero"; Str.Delim "\t"]; + + (** XML tokenization *) + (* See "REX: XML Shallow Parsing with Regular Expressions", + Robert D. Cameron, Simon Fraser University, CMPT TR 1998-17. *) + start_test "XML tokenization"; + begin + let _TextSE = "[^<]+" in + let _UntilHyphen = "[^-]*-" in + let _Until2Hyphens = _UntilHyphen ^ "\\([^-]" ^ _UntilHyphen ^ "\\)*-" in + let _CommentCE = _Until2Hyphens ^ ">?" in + let _UntilRSBs = "[^]]*]\\([^]]+]\\)*]+" in + let _CDATA_CE = _UntilRSBs ^ "\\([^]>]" ^ _UntilRSBs ^ "\\)*>" in + let _S = "[ \n\t\r]+" in + let _NameStrt = "[A-Za-z_:]\\|[^\x00-\x7F]" in + let _NameChar = "[A-Za-z0-9_:.-]\\|[^\x00-\x7F]" in + let _Name = "\\(" ^ _NameStrt ^ "\\)\\(" ^ _NameChar ^ "\\)*" in + let _QuoteSE = "\"[^\"]*\"\\|'[^']*'" in + let _DT_IdentSE = _S ^ _Name ^ "\\(" ^ _S ^ "\\(" ^ _Name ^ "\\|" ^ _QuoteSE ^ "\\)\\)*" in + let _MarkupDeclCE = "\\([^]\"'><]\\|" ^ _QuoteSE ^ "\\)*>" in + let _S1 = "[\n\r\t ]" in + let _UntilQMs = "[^?]*\\?+" in + let _PI_Tail = "\\?>\\|" ^ _S1 ^ _UntilQMs ^ "\\([^>?]" ^ _UntilQMs ^ "\\)*>" in + let _DT_ItemSE = "<\\(!\\(--" ^ _Until2Hyphens ^ ">\\|[^-]" ^ _MarkupDeclCE ^ "\\)\\|\\?" ^ _Name ^ "\\(" ^ _PI_Tail ^ "\\)\\)\\|%" ^ _Name ^ ";\\|" ^ _S1 in + let _DocTypeCE = _DT_IdentSE ^ "\\(" ^ _S ^ "\\)?\\(\\[\\(" ^ _DT_ItemSE ^ "\\)*]\\(" ^ _S ^ "\\)?\\)?>?" in + let _DeclCE = "--\\(" ^ _CommentCE ^ "\\)?\\|\\[_CDATA\\[\\(" ^ _CDATA_CE ^ "\\)?\\|_DOCTYPE\\(" ^ _DocTypeCE ^ "\\)?" in + let _PI_CE = _Name ^ "\\(" ^ _PI_Tail ^ "\\)?" in + let _EndTagCE = _Name ^ "\\(" ^ _S ^ "\\)?>?" in + let _AttValSE = "\"[^<\"]*\"\\|'[^<']*'" in + let _ElemTagCE = _Name ^ "\\(" ^ _S ^ _Name ^ "\\(" ^ _S ^ "\\)?=\\(" ^ _S ^ "\\)?\\(" ^ _AttValSE ^ "\\)\\)*\\(" ^ _S ^ "\\)?/?>?" in + let _MarkupSPE = "<\\(!\\(" ^ _DeclCE ^ "\\)?\\|\\?\\(" ^ _PI_CE ^ "\\)?\\|/\\(" ^ _EndTagCE ^ "\\)?\\|\\(" ^ _ElemTagCE ^ "\\)?\\)" in + let _XML_SPE = _TextSE ^ "\\|" ^ _MarkupSPE in + let input = "\ +<?xml version=\"1.0\"?> +<?xml-stylesheet type=\"text/css\" href=\"nutrition.css\"?> +<!DOCTYPE root [ + <!ELEMENT root (stem)> + <!ELEMENT stem EMPTY> +]> +<!ELEMENT name (#PCDATA)> +<![CDATA[my +escaped text]]> +<nutrition> +<daily-values> + <total-fat units=\"g\">65</total-fat> + <saturated-fat units=\"g\">20</saturated-fat> + <cholesterol units=\"mg\">300</cholesterol> + <sodium units=\"mg\">2400</sodium> + <carb units=\"g\">300</carb> + <fiber units=\"g\">25</fiber> + <protein units=\"g\">50</protein> +</daily-values> +<food> + <name>Avocado Dip</name> + <mfr>Sunnydale</mfr> + <serving units=\"g\">29</serving> + <calories total=\"110\" fat=\"100\"/> + <total-fat>11</total-fat> + <saturated-fat>3</saturated-fat> + <cholesterol>5</cholesterol> + <sodium>210</sodium> + <carb>2</carb> + <fiber>0</fiber> + <protein>1</protein> + <vitamins> + <a>0</a> + <c>0</c> + </vitamins> + <minerals> + <ca>0</ca> + <fe>0</fe> + </minerals> +</food> +<!-- +<food> + <name></name> + <mfr></mfr> + <serving units=\"g\"></serving> + <calories total=\"\" fat=\"\"/> + <total-fat></total-fat> + <saturated-fat></saturated-fat> + <cholesterol></cholesterol> + <sodium></sodium> + <carb></carb> + <fiber></fiber> + <protein></protein> + <vitamins> + <a></a> + <c></c> + </vitamins> + <minerals> + <ca></ca> + <fe></fe> + </minerals> +</food> +--> +" in + let result = [ + "<?xml version=\"1.0\"?>"; + "\n"; + "<?xml-stylesheet type=\"text/css\" href=\"nutrition.css\"?>"; + "\n"; + "<!"; + "DOCTYPE root [\n "; + "<!"; + "ELEMENT root (stem)>\n "; + "<!"; + "ELEMENT stem EMPTY>\n]>\n"; + "<!"; + "ELEMENT name (#PCDATA)>\n"; + "<!"; + "[CDATA[my\nescaped text]]> \n"; + "<nutrition>"; + "\n"; + "<daily-values>"; + "\n\t"; + "<total-fat units=\"g\">"; + "65"; + "</total-fat>"; + "\n\t"; + "<saturated-fat units=\"g\">"; + "20"; + "</saturated-fat>"; + "\n\t"; + "<cholesterol units=\"mg\">"; + "300"; + "</cholesterol>"; + "\n\t"; + "<sodium units=\"mg\">"; + "2400"; + "</sodium>"; + "\n\t"; + "<carb units=\"g\">"; + "300"; + "</carb>"; + "\n\t"; + "<fiber units=\"g\">"; + "25"; + "</fiber>"; + "\n\t"; + "<protein units=\"g\">"; + "50"; + "</protein>"; + "\n"; + "</daily-values>"; + "\n"; + "<food>"; + "\n\t"; + "<name>"; + "Avocado Dip"; + "</name>"; + "\n\t"; + "<mfr>"; + "Sunnydale"; + "</mfr>"; + "\n\t"; + "<serving units=\"g\">"; + "29"; + "</serving>"; + "\n\t"; + "<calories total=\"110\" fat=\"100\"/>"; + "\n\t"; + "<total-fat>"; + "11"; + "</total-fat>"; + "\n\t"; + "<saturated-fat>"; + "3"; + "</saturated-fat>"; + "\n\t"; + "<cholesterol>"; + "5"; + "</cholesterol>"; + "\n\t"; + "<sodium>"; + "210"; + "</sodium>"; + "\n\t"; + "<carb>"; + "2"; + "</carb>"; + "\n\t"; + "<fiber>"; + "0"; + "</fiber>"; + "\n\t"; + "<protein>"; + "1"; + "</protein>"; + "\n\t"; + "<vitamins>"; + "\n\t\t"; + "<a>"; + "0"; + "</a>"; + "\n\t\t"; + "<c>"; + "0"; + "</c>"; + "\n\t"; + "</vitamins>"; + "\n\t"; + "<minerals>"; + "\n\t\t"; + "<ca>"; + "0"; + "</ca>"; + "\n\t\t"; + "<fe>"; + "0"; + "</fe>"; + "\n\t"; + "</minerals>"; + "\n"; + "</food>"; + "\n"; + "<!--\n<food>\n\t<name></name>\n\t<mfr></mfr>\n\t<serving units=\"g\"></serving>\n\t<calories total=\"\" fat=\"\"/>\n\t<total-fat></total-fat>\n\t<saturated-fat></saturated-fat>\n\t<cholesterol></cholesterol>\n\t<sodium></sodium>\n\t<carb></carb>\n\t<fiber></fiber>\n\t<protein></protein>\n\t<vitamins>\n\t\t<a></a>\n\t\t<c></c>\n\t</vitamins>\n\t<minerals>\n\t\t<ca></ca>\n\t\t<fe></fe>\n\t</minerals>\n</food>\n-->"; + "\n"] in + let re = Str.regexp _XML_SPE in + let rec process i l = + let j = try Str.search_forward re input i with Not_found -> (-1) in + if j < 0 then begin + test l [] + end else begin + match l with + [] -> test 0 1 (* failure *) + | hd :: tl -> + test (Str.matched_string input) hd; process (Str.match_end()) tl + end in + process 0 result + end; + + end_test() + +let manual_test regexp text = + try + ignore (Str.search_forward (Str.regexp regexp) text 0); + printf "Matched,"; + begin try + for i = 0 to 31 do + try + let s = Str.matched_group i text in + printf " \\%d=%s" i s + with Not_found -> + () + done + with Invalid_argument "Str.matched_group" -> (*yuck*) + () + end; + print_newline() + with Not_found -> + printf "Not matched\n" + +let _ = + if Array.length Sys.argv >= 3 + then manual_test Sys.argv.(1) Sys.argv.(2) + else automated_test() diff --git a/test/Moretest/sets.ml b/test/Moretest/sets.ml new file mode 100644 index 0000000..f67e96d --- /dev/null +++ b/test/Moretest/sets.ml @@ -0,0 +1,39 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: sets.ml,v 1.4 2002-10-16 09:06:39 weis Exp $ *) + +module IntSet = Set.Make(struct type t = int let compare x y = x-y end) + +let even = List.fold_right IntSet.add [0; -2; 2; 4; 6; -10] IntSet.empty + +let odd = List.fold_right IntSet.add [9; -7; 5; 1; -3] IntSet.empty + +let _ = + for i = -10 to 10 do + Printf.printf "%d %B %B\n" i (IntSet.mem i even) (IntSet.mem i odd) + done + +module PowerSet(BaseSet: Set.S) + (SetOrd: functor(S: Set.S) -> Set.OrderedType) = + Set.Make(SetOrd(BaseSet)) + +module IntSetSet = PowerSet(IntSet)(functor (S: Set.S) -> S) + +let setofset = List.fold_right IntSetSet.add [even; odd] IntSetSet.empty + +let _ = + List.iter + (fun s -> Printf.printf "%B\n" (IntSetSet.mem s setofset)) + [IntSet.empty; even; odd; IntSet.union even odd] + +let _ = exit 0 diff --git a/test/Moretest/signals.ml b/test/Moretest/signals.ml new file mode 100644 index 0000000..ce93a27 --- /dev/null +++ b/test/Moretest/signals.ml @@ -0,0 +1,32 @@ +let rec tak (x, y, z as tuple) = + if x > y then tak(tak (x-1, y, z), tak (y-1, z, x), tak (z-1, x, y)) + else z + +let break_handler _ = + print_string "Thank you for pressing ctrl-C."; print_newline(); + print_string "Allocating a bit..."; flush stdout; + tak(18,12,6); print_string "done."; print_newline() + +let stop_handler _ = + print_string "Thank you for pressing ctrl-Z."; print_newline(); + print_string "Now raising an exception..."; print_newline(); + raise Exit + +let _ = + Sys.signal Sys.sigint (Sys.Signal_handle break_handler); + Sys.signal Sys.sigtstp (Sys.Signal_handle stop_handler); + begin try + print_string "Computing like crazy..."; print_newline(); + for i = 1 to 1000 do tak(18,12,6) done; + print_string "Reading on input..."; print_newline(); + for i = 1 to 5 do + try + let s = read_line () in + print_string ">> "; print_string s; print_newline() + with Exit -> + print_string "Got Exit, continuing."; print_newline() + done + with Exit -> + print_string "Got Exit, exiting."; print_newline() + end; + exit 0 diff --git a/test/Moretest/stackoverflow.ml b/test/Moretest/stackoverflow.ml new file mode 100644 index 0000000..4d211bc --- /dev/null +++ b/test/Moretest/stackoverflow.ml @@ -0,0 +1,15 @@ +let rec f x = + if x land 0xFFFF <> 0 + then 1 + f (x + 1) + else + try + 1 + f (x + 1) + with Stack_overflow -> + print_string "x = "; print_int x; print_newline(); + raise Stack_overflow + +let _ = + try + ignore(f 0) + with Stack_overflow -> + print_string "Stack overflow caught"; print_newline() diff --git a/test/Moretest/syserror.ml b/test/Moretest/syserror.ml new file mode 100644 index 0000000..46f62ea --- /dev/null +++ b/test/Moretest/syserror.ml @@ -0,0 +1 @@ +let channel = open_out "titi:/toto" diff --git a/test/Moretest/tailcalls.ml b/test/Moretest/tailcalls.ml new file mode 100644 index 0000000..23b7353 --- /dev/null +++ b/test/Moretest/tailcalls.ml @@ -0,0 +1,28 @@ +let rec tailcall4 a b c d = + if a < 0 + then b + else tailcall4 (a-1) (b+1) (c+2) (d+3) + +let rec tailcall8 a b c d e f g h = + if a < 0 + then b + else tailcall8 (a-1) (b+1) (c+2) (d+3) (e+4) (f+5) (g+6) (h+7) + +let rec tailcall16 a b c d e f g h i j k l m n o p = + if a < 0 + then b + else tailcall16 (a-1) (b+1) (c+2) (d+3) (e+4) (f+5) (g+6) (h+7) + (i+8) (j+9) (k+10) (l+11) (m+12) (n+13) (o+14) (p+15) + +let indtailcall8 fn a b c d e f g h = + fn a b c d e f g h + +let indtailcall16 fn a b c d e f g h i j k l m n o p = + fn a b c d e f g h i j k l m n o p + +let _ = + print_int (tailcall4 10000000 0 0 0); print_newline(); + print_int (tailcall8 10000000 0 0 0 0 0 0 0); print_newline(); + print_int (tailcall16 10000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); print_newline(); + print_int (indtailcall8 tailcall8 10 0 0 0 0 0 0 0); print_newline(); + print_int (indtailcall16 tailcall16 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); print_newline() diff --git a/test/Moretest/tbuffer.ml b/test/Moretest/tbuffer.ml new file mode 100644 index 0000000..d48268d --- /dev/null +++ b/test/Moretest/tbuffer.ml @@ -0,0 +1,27 @@ +(* Dummy substitute function. *) + +open Testing;; +open Buffer;; + +let identity s = s;; + +let b = Buffer.create 100;; + +(* Pattern with a '\\' character in it. *) +let pat0 = "\\\\a" in +let n0 = String.length pat0 in + +Buffer.add_substitute b identity pat0; + +test (String.length (Buffer.contents b) = n0) +;; + +(* Pattern with a '\\' character at the end. *) +let pat1 = "b\\" in +let n1 = String.length pat1 in + +Buffer.clear b; +Buffer.add_substitute b identity pat1; +test (String.length (Buffer.contents b) = n1) +;; + diff --git a/test/Moretest/tcallback.ml b/test/Moretest/tcallback.ml new file mode 100644 index 0000000..3291411 --- /dev/null +++ b/test/Moretest/tcallback.ml @@ -0,0 +1,68 @@ +external mycallback1 : ('a -> 'b) -> 'a -> 'b = "mycallback1" +external mycallback2 : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = "mycallback2" +external mycallback3 : ('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> 'd = "mycallback3" +external mycallback4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a -> 'b -> 'c -> 'd -> 'e = "mycallback4" + +let rec tak (x, y, z as _tuple) = + if x > y then tak(tak (x-1, y, z), tak (y-1, z, x), tak (z-1, x, y)) + else z + +let tak2 x (y, z) = tak (x, y, z) + +let tak3 x y z = tak (x, y, z) + +let tak4 x y z u = tak (x, y, z + u) + +let raise_exit () = (raise Exit : unit) + +let trapexit () = + begin try + mycallback1 raise_exit () + with Exit -> + () + end; + tak (18, 12, 6) + +external mypushroot : 'a -> ('b -> 'c) -> 'b -> 'a = "mypushroot" +external mycamlparam : 'a -> ('b -> 'c) -> 'b -> 'a = "mycamlparam" + +let tripwire f = + let s = String.make 5 'a' in + f s trapexit () + +(* Test callbacks performed to handle signals *) + +let sighandler signo = +(* + print_string "Got signal, triggering garbage collection..."; + print_newline(); +*) + (* Thoroughly wipe the minor heap *) + ignore (tak (18, 12, 6)) + +external unix_getpid : unit -> int = "unix_getpid" "noalloc" +external unix_kill : int -> int -> unit = "unix_kill" "noalloc" + +let callbacksig () = + let pid = unix_getpid() in + (* Allocate a block in the minor heap *) + let s = String.make 5 'b' in + (* Send a signal to self. We want s to remain in a register and + not be spilled on the stack, hence we declare unix_kill + "noalloc". *) + unix_kill pid Sys.sigusr1; + (* Allocate some more so that the signal will be tested *) + let u = (s, s) in + fst u + +let _ = + print_int(mycallback1 tak (18, 12, 6)); print_newline(); + print_int(mycallback2 tak2 18 (12, 6)); print_newline(); + print_int(mycallback3 tak3 18 12 6); print_newline(); + print_int(mycallback4 tak4 18 12 3 3); print_newline(); + print_int(trapexit ()); print_newline(); + print_string(tripwire mypushroot); print_newline(); + print_string(tripwire mycamlparam); print_newline(); + Sys.set_signal Sys.sigusr1 (Sys.Signal_handle sighandler); + print_string(callbacksig ()); print_newline() + diff --git a/test/Moretest/testing.ml b/test/Moretest/testing.ml new file mode 100644 index 0000000..48e8320 --- /dev/null +++ b/test/Moretest/testing.ml @@ -0,0 +1,96 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: testing.ml,v 1.1 2006-01-12 12:52:14 weis Exp $ *) + +(* Testing auxilliaries. *) + +open Scanf;; + +let all_tests_ok = ref true;; + +let finish () = + match !all_tests_ok with + | true -> + prerr_endline "\nAll tests succeeded." + | _ -> + prerr_endline "\n\n********* Test suit failed. ***********\n";; + +at_exit finish;; + +let test_num = ref (-1);; + +let print_test_number () = + print_int !test_num; print_string " "; flush stdout;; + +let next_test () = + incr test_num; + print_test_number ();; + +let print_test_fail () = + all_tests_ok := false; + print_string + (Printf.sprintf "\n********* Test number %i failed ***********\n" + !test_num);; + +let print_failure_test_fail () = + all_tests_ok := false; + print_string + (Printf.sprintf + "\n********* Failure Test number %i incorrectly failed ***********\n" + !test_num);; + +let print_failure_test_succeed () = + all_tests_ok := false; + print_string + (Printf.sprintf + "\n********* Failure Test number %i failed to fail ***********\n" + !test_num);; + +let test b = + next_test (); + if not b then print_test_fail ();; + +(* Applies f to x and checks that the evaluation indeed + raises an exception that verifies the predicate [pred]. *) +let test_raises_exc_p pred f x = + next_test (); + try + ignore (f x); + print_failure_test_succeed (); + false + with + | x -> + pred x || (print_failure_test_fail (); false);; + +(* Applies f to x and checks that the evaluation indeed + raises some exception. *) +let test_raises_some_exc f = test_raises_exc_p (fun _ -> true) f;; +let test_raises_this_exc exc = test_raises_exc_p (fun x -> x = exc);; + +(* Applies f to x and checks that the evaluation indeed + raises exception Failure s. *) + +let test_raises_this_failure s f x = + test_raises_exc_p (fun x -> x = Failure s) f x;; + +(* Applies f to x and checks that the evaluation indeed + raises the exception Failure. *) +let test_raises_some_failure f x = + test_raises_exc_p (function Failure _ -> true | _ -> false) f x;; + +let failure_test f x s = test_raises_this_failure s f x;; +let any_failure_test = test_raises_some_failure;; + +let scan_failure_test f x = + test_raises_exc_p (function Scan_failure _ -> true | _ -> false) f x;; + diff --git a/test/Moretest/testing.mli b/test/Moretest/testing.mli new file mode 100644 index 0000000..a0793d2 --- /dev/null +++ b/test/Moretest/testing.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2006 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: testing.mli,v 1.1 2006-01-12 12:52:14 weis Exp $ *) + +(* Testing auxilliaries. *) + +val test : bool -> unit;; +(** [test e] tests that [e] evaluates to [true]. *) +val failure_test : ('a -> 'b) -> 'a -> string -> bool;; +(** [failure_test f x s] tests that [f x] raises the exception [Failure s]. *) + +val test_raises_some_exc : ('a -> 'b) -> 'a -> bool;; +(** [test_raises_some_exc f x] tests that [f x] raises an exception. *) + +val test_raises_this_exc : exn -> ('a -> 'b) -> 'a -> bool;; +(** [test_raises_this_exc exc f x] tests that [f x] + raises the exception [exc]. *) + +val test_raises_exc_p : (exn -> bool) -> ('a -> 'b) -> 'a -> bool;; +(** [test_raises_exc_p p f x] tests that [f x] raises an exception that + verifies predicate [p]. *) + +val scan_failure_test : ('a -> 'b) -> 'a -> bool;; +(** [scan_failure_test f x] tests that [f x] raises [Scanf.Scan_failure]. *) diff --git a/test/Moretest/testrandom.ml b/test/Moretest/testrandom.ml new file mode 100644 index 0000000..150d408 --- /dev/null +++ b/test/Moretest/testrandom.ml @@ -0,0 +1,13 @@ +open Random + +let _ = + for i = 0 to 20 do + print_float (float 1000.); print_char ' ' + done; + print_newline (); print_newline (); + for i = 0 to 20 do + print_int (int 1000); print_char ' ' + done + +let _ = exit 0 + diff --git a/test/Moretest/tfloat_record.ml b/test/Moretest/tfloat_record.ml new file mode 100644 index 0000000..4d197f5 --- /dev/null +++ b/test/Moretest/tfloat_record.ml @@ -0,0 +1,5 @@ +let s = { Float_record.f = Float_record.make 1.0 };; + +print_float (Float_record.from s.Float_record.f);; +print_newline ();; + diff --git a/test/Moretest/tlength.ml b/test/Moretest/tlength.ml new file mode 100644 index 0000000..b4b56da --- /dev/null +++ b/test/Moretest/tlength.ml @@ -0,0 +1,23 @@ +(* $Id: tlength.ml,v 1.1 2007-11-06 21:06:18 weis Exp $ + +A testbed file for private type abbreviation definitions. + +We test the Length module that implements positive integers. + +*) + +(* We can build a null length. *) +let l = Length.make 0;; + + +(* We cannot build a negative length. *) +try ignore (Length.make (-1)); assert false with +| Failure _ -> () +;; + + +(* We can build a positive length. *) +let l3 = Length.make 3 in + +(* and use the associated injection and projection functions. *) +Length.make (Length.from l3 + Length.from l3);; diff --git a/test/Moretest/tprintf.ml b/test/Moretest/tprintf.ml new file mode 100644 index 0000000..518859d --- /dev/null +++ b/test/Moretest/tprintf.ml @@ -0,0 +1,72 @@ +open Testing;; + +open Printf;; + +(* Padding floating point numbers. + Testing * width specifications. *) +let test0 () = + sprintf "%.0f" 1.0 = "1" && + sprintf "%.0f." 1.7 = "2." && + sprintf "%.1f." 1.0 = "1.0." && + sprintf "%0.1f." 12.0 = "12.0." && + sprintf "%3.1f." 12.0 = "12.0." && + sprintf "%5.1f." 12.0 = " 12.0." && + sprintf "%10.1f." 12.0 = " 12.0." && + sprintf "%010.1f." 12.0 = "00000012.0." && + sprintf "% 10.1f." 12.0 = " 12.0." && + sprintf "%+10.1f." 12.0 = " +12.0." && + sprintf "%+10.1f." (-12.0) = " -12.0." && + + sprintf "%010.5f." 12.0 = "0012.00000." && + sprintf "%010.0f." 12.0 = "0000000012." && + sprintf "% 10.0f." 12.0 = " 12." && + + sprintf "%0.1f." 12.0 = "12.0." && + sprintf "%10.1f." 1.001 = " 1.0." && + sprintf "%05.1f." 1.001 = "001.0." +;; + +test (test0 ());; + +(* Padding integers (cf bug 3955). + Testing * width specifications. *) +let test1 () = + sprintf "%d\n" 1 = "1\n" && + sprintf "%05d\n" 1 = "00001\n" && + sprintf "%*d\n" 5 1 = " 1\n" && + sprintf "%0*d\n" 5 1 = "00001\n";; + +test (test1 ());; + +(* FIXME: when positional specification will be OK. *) +let test2 () = true +(* sprintf "%1$d\n" 5 1 = " 1\n" && + sprintf "%01$d\n" 5 1 = "00001\n" *);; + +test (test2 ());; + +(* Testing meta format string printing. *) +let test3 () = +sprintf "%{toto %s titi.\n%}" "Bonjour %s." = "%s" && +sprintf "%{%d%s%}" "kk%dkk%s\n" = "%i%s";; +test (test3 ());; + +(* Testing meta format string arguments. *) +let test4 () = + sprintf "%(%s%)" "Bonjour %s" "toto" = "Bonjour toto" && + sprintf "%(%s%)" "Bonjour %s." "vous" = "Bonjour vous." && + sprintf "%(%s%)" "Hello %s." "you" = "Hello you." +;; + +test (test4 ());; + +let test5 () = + sprintf "%(toto %s titi.\n%)" + "Bonjour %s." "vous" = "Bonjour vous." && + sprintf "%(toto %s titi.\n%).\n" + "Bonjour %s" "toto" = "Bonjour toto.\n" && + sprintf "%(toto %s titi.\n%)%s\n" + "Bonjour %s." "toto" " Ça va?" = "Bonjour toto. Ça va?\n" +;; + +test (test5 ());; diff --git a/test/Moretest/tscanf.ml b/test/Moretest/tscanf.ml new file mode 100644 index 0000000..815adce --- /dev/null +++ b/test/Moretest/tscanf.ml @@ -0,0 +1,1177 @@ +(* $Id: tscanf.ml,v 1.22 2008-09-09 06:39:26 weis Exp $ + +A testbed file for module Scanf. + + *) + +open Testing;; + +open Scanf;; + +(* The ``continuation'' that returns the scanned value. *) +let id x = x;; + +(* Testing space scanning. *) +let test0 () = + (sscanf "" "" id) 1 + + (sscanf "" " " id) 2 + + (sscanf " " " " id) 3 + + (sscanf "\t" " " id) 4 + + (sscanf "\n" " " id) 5 + + (sscanf "\n\t 6" " %d" id) +;; + +test (test0 () = 21) +;; + +(* Testing integer scanning %i and %d. *) +let test1 () = + sscanf "1" "%d" id + + sscanf " 2" " %d" id + + sscanf " -2" " %d" id + + sscanf " +2" " %d" id + + sscanf " 2a " " %da" id +;; + +test (test1 () = 5) +;; + +let test2 () = + sscanf "123" "%2i" id + + sscanf "245" "%d" id + + sscanf " 2a " " %1da" id +;; + +test (test2 () = 259) +;; + +let test3 () = + sscanf "0xff" "%3i" id + + sscanf "0XEF" "%3i" id + + sscanf "x=-245" " x = %d" id + + sscanf " 2a " " %1da" id +;; + +test (test3 () = -214) +;; + +(* Testing float scanning. *) +(* f style. *) +let test4 () = + bscanf (Scanning.from_string "1") + "%f" (fun b0 -> b0 = 1.0) && + bscanf (Scanning.from_string "-1") + "%f" (fun b0 -> b0 = -1.0) && + bscanf (Scanning.from_string "+1") + "%f" (fun b0 -> b0 = 1.0) && + bscanf (Scanning.from_string "1.") + "%f" (fun b0 -> b0 = 1.0) && + bscanf (Scanning.from_string ".1") + "%f" (fun b0 -> b0 = 0.1) && + bscanf (Scanning.from_string "-.1") + "%f" (fun b0 -> b0 = -0.1) && + bscanf (Scanning.from_string "+.1") + "%f" (fun b0 -> b0 = 0.1) && + bscanf (Scanning.from_string "+1.") + "%f" (fun b0 -> b0 = 1.0) && + bscanf (Scanning.from_string "-1.") + "%f" (fun b0 -> b0 = -1.0) && + bscanf (Scanning.from_string "0 1. 1.3") + "%f %f %f" (fun b0 b1 b2 -> b0 = 0.0 && b1 = 1.0 && b2 = 1.3) && + bscanf (Scanning.from_string "0.113") + "%4f" (fun b0 -> b0 = 0.11) && + bscanf (Scanning.from_string "0.113") + "%5f" (fun b0 -> b0 = 0.113) && + bscanf (Scanning.from_string "000.113") + "%15f" (fun b0 -> b0 = 0.113) && + bscanf (Scanning.from_string "+000.113") + "%15f" (fun b0 -> b0 = 0.113) && + bscanf (Scanning.from_string "-000.113") + "%15f" (fun b0 -> b0 = -0.113) +;; +test (test4 ()) +;; + +(* e style. *) +let test5 () = + bscanf (Scanning.from_string "1e1") + "%e" (fun b -> b = 10.0) && + bscanf (Scanning.from_string "1e+1") + "%e" (fun b -> b = 10.0) && + bscanf (Scanning.from_string "10e-1") + "%e" (fun b -> b = 1.0) && + bscanf (Scanning.from_string "10.e-1") + "%e" (fun b -> b = 1.0) && + bscanf (Scanning.from_string "1e1 1.e+1 1.3e-1") + "%e %e %e" (fun b1 b2 b3 -> b1 = 10.0 && b2 = b1 && b3 = 0.13) && + +(* g style. *) + bscanf (Scanning.from_string "1 1.1 0e+1 1.3e-1") + "%g %g %g %g" + (fun b1 b2 b3 b4 -> + b1 = 1.0 && b2 = 1.1 && b3 = 0.0 && b4 = 0.13) +;; + +test (test5 ()) +;; + +(* Testing boolean scanning. *) +let test6 () = + bscanf (Scanning.from_string "truetrue") "%B%B" + (fun b1 b2 -> (b1, b2) = (true, true)) && + bscanf (Scanning.from_string "truefalse") "%B%B" + (fun b1 b2 -> (b1, b2) = (true, false)) && + bscanf (Scanning.from_string "falsetrue") "%B%B" + (fun b1 b2 -> (b1, b2) = (false, true)) && + bscanf (Scanning.from_string "falsefalse") "%B%B" + (fun b1 b2 -> (b1, b2) = (false, false)) && + bscanf (Scanning.from_string "true false") "%B %B" + (fun b1 b2 -> (b1, b2) = (true, false)) +;; + +test (test6 ()) +;; + +(* Testing char scanning. *) + +let test7 () = + bscanf (Scanning.from_string "'a' '\n' '\t' '\000' '\032'") + "%C %C %C %C %C" + (fun c1 c2 c3 c4 c5 -> + c1 = 'a' && c2 = '\n' && c3 = '\t' && c4 = '\000' && c5 = '\032') && + +(* Here \n, \t, and \032 are skipped due to the space semantics of scanf. *) + bscanf (Scanning.from_string "a \n \t \000 \032b") + "%c %c %c " + (fun c1 c2 c3 -> + c1 = 'a' && c2 = '\000' && c3 = 'b') +;; + +test (test7 ()) +;; + +let verify_read c = + let s = Printf.sprintf "%C" c in + let ib = Scanning.from_string s in + assert (bscanf ib "%C" id = c) +;; + +let verify_scan_Chars () = + for i = 0 to 255 do verify_read (char_of_int i) done +;; + +let test8 () = verify_scan_Chars () = ();; + +test (test8 ()) +;; + +(* Testing string scanning. *) + +(* %S and %s styles. *) +let unit fmt s = + let ib = Scanning.from_string (Printf.sprintf "%S" s) in + Scanf.bscanf ib fmt id +;; + +let test_fmt fmt s = unit fmt s = s;; + +let test_S = test_fmt "%S";; +let test9 () = + test_S "poi" && + test_S "a\"b" && + test_S "a\nb" && + test_S "a\010b" && + test_S "a\\\n\ + b \\\n\ + c\010\\\n\ + b" && + test_S "a\\\n\ + \\\n\ + \\\n\ + b \\\n\ + c\010\\\n\ + b" +;; + +test (test9 ()) +;; + +let test10 () = + let res = + sscanf "Une chaîne: \"celle-ci\" et \"celle-là\"!" + "%s %s %S %s %S %s" + (fun s1 s2 s3 s4 s5 s6 -> s1 ^ s2 ^ s3 ^ s4 ^ s5 ^ s6) in + res = "Unechaîne:celle-cietcelle-là!" +;; + +test (test10 ()) +;; + +(* %[] style *) +let test11 () = + sscanf "Pierre Weis 70" "%s %s %s" + (fun prenom nom poids -> + prenom = "Pierre" && nom = "Weis" && int_of_string poids = 70) + && + sscanf "Jean-Luc de Léage 68" "%[^ ] %[^ ] %d" + (fun prenom nom poids -> + prenom = "Jean-Luc" && nom = "de Léage" && poids = 68) + && + sscanf "Daniel de Rauglaudre 66" "%s@\t %s@\t %d" + (fun prenom nom poids -> + prenom = "Daniel" && nom = "de Rauglaudre" && poids = 66) +;; + +(* Empty string (end of input) testing. *) +let test110 () = + sscanf "" " " (fun x -> x) "" = "" && + sscanf "" "%s" (fun x -> x = "") && + sscanf "" "%s%s" (fun x y -> x = "" && y = "") && + sscanf "" "%s " (fun x -> x = "") && + sscanf "" " %s" (fun x -> x = "") && + sscanf "" " %s " (fun x -> x = "") && + sscanf "" "%[^\n]" (fun x -> x = "") && + sscanf "" "%[^\n] " (fun x -> x = "") && + sscanf " " "%s" (fun x -> x = "") && + sscanf " " "%s%s" (fun x y -> x = "" && y = "") && + sscanf " " " %s " (fun x -> x = "") && + sscanf " " " %s %s" (fun x y -> x = "" && x = y) && + sscanf " " " %s@ %s" (fun x y -> x = "" && x = y) && + sscanf " poi !" " %s@ %s@." (fun x y -> x = "poi" && y = "!") && + sscanf " poi !" "%s@ %s@." (fun x y -> x = "" && y = "poi !") +;; + +let test111 () = sscanf "" "%[^\n]@\n" (fun x -> x = "");; + +test (test11 () && test110 () && test111 ()) +;; + +(* Scanning lists. *) +let ib () = Scanning.from_string "[1;2;3;4; ]";; + +(* Statically known lists can be scanned directly. *) +let f ib = + bscanf ib " [" (); + bscanf ib " %i;" (fun i -> + bscanf ib " %i;" (fun j -> + bscanf ib " %i;" (fun k -> + bscanf ib " %i;" (fun l -> + bscanf ib " ]" (); + [i; j; k; l]))));; + +let test12 () = f (ib ()) = [1; 2; 3; 4];; + +test (test12 ()) +;; + +(* A general list scanner that always fails to succeed. *) +let rec scan_elems ib accu = + try bscanf ib " %i;" (fun i -> scan_elems ib (i :: accu)) with + | _ -> accu +;; + +let g ib = bscanf ib "[ " (); List.rev (scan_elems ib []);; + +let test13 () = g (ib ()) = [1; 2; 3; 4];; + +test (test13 ()) +;; + +(* A general int list scanner. *) +let rec scan_int_list ib = + bscanf ib "[ " (); + let accu = scan_elems ib [] in + bscanf ib " ]" (); + List.rev accu +;; + +let test14 () = scan_int_list (ib ()) = [1; 2; 3; 4];; + +test (test14 ()) +;; + +(* A general list scanner that always succeeds. *) +let rec scan_elems ib accu = + bscanf ib " %i %c" + (fun i -> function + | ';' -> scan_elems ib (i :: accu) + | ']' -> List.rev (i :: accu) + | c -> failwith "scan_elems") +;; + +let rec scan_int_list ib = + bscanf ib "[ " (); + scan_elems ib [] +;; + +let test15 () = + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1; 2; 3; 4];; + +test (test15 ()) +;; + +let rec scan_elems ib accu = + try + bscanf ib "%c %i" + (fun c i -> + match c with + | ';' -> scan_elems ib (i :: accu) + | ']' -> List.rev (i :: accu) + | '[' when accu = [] -> scan_elems ib (i :: accu) + | c -> prerr_endline (String.make 1 c); failwith "scan_elems") + with + | Scan_failure _ -> bscanf ib "]" (); accu + | End_of_file -> accu +;; + +let scan_int_list ib = scan_elems ib [];; + +let test16 () = + scan_int_list (Scanning.from_string "[]") = List.rev [] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = List.rev [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4; ]") = List.rev [1;2;3;4] && + (* Should fail but succeeds! *) + scan_int_list (Scanning.from_string "[1;2;3;4") = List.rev [1;2;3;4];; + +test (test16 ()) +;; + +let rec scan_elems ib accu = + bscanf ib " %i%[]; \t\n\r]" + (fun i s -> + match s with + | ";" -> scan_elems ib (i :: accu) + | "]" -> List.rev (i :: accu) + | s -> List.rev (i :: accu)) +;; + +let scan_int_list ib = + bscanf ib " [" (); + scan_elems ib [] +;; + +let test17 () = + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4; ]") = [1;2;3;4] && + (* Should fail but succeeds! *) + scan_int_list (Scanning.from_string "[1;2;3;4 5]") = [1;2;3;4];; + +test (test17 ()) +;; + +let rec scan_elems ib accu = + bscanf ib " %c " (fun c -> + match c with + | '[' when accu = [] -> + (* begginning of list: could find either + - an int, if the list is not empty, + - the char ], if the list is empty. *) + bscanf ib "%[]]" + (function + | "]" -> accu + | _ -> + bscanf ib " %i " (fun i -> + scan_rest ib (i :: accu))) + | _ -> failwith "scan_elems") + +and scan_rest ib accu = + bscanf ib " %c " (fun c -> + match c with + | ';' -> + bscanf ib "%[]]" + (function + | "]" -> accu + | _ -> + bscanf ib " %i " (fun i -> + scan_rest ib (i :: accu))) + | ']' -> accu + | _ -> failwith "scan_rest") +;; + +let scan_int_list ib = List.rev (scan_elems ib []);; + +let test18 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4; ]") = [1;2;3;4];; + +test (test18 ()) +;; + +(* Those properly fail *) + +let test19 () = + failure_test + scan_int_list (Scanning.from_string "[1;2;3;4 5]") + "scan_rest" +;; + +(test19 ()) +;; + +let test20 () = + scan_failure_test + scan_int_list (Scanning.from_string "[1;2;3;4;; 5]");; + +(test20 ()) +;; + +let test21 () = + scan_failure_test + scan_int_list (Scanning.from_string "[1;2;3;4;;");; + +(test21 ()) +;; + +let rec scan_elems ib accu = + bscanf ib "%1[];]" (function + | "]" -> accu + | ";" -> scan_rest ib accu + | _ -> + failwith + (Printf.sprintf "scan_int_list" (* + "scan_int_list: char %i waiting for ']' or ';' but found %c" + (Scanning.char_count ib) (Scanning.peek_char ib)*))) + +and scan_rest ib accu = + bscanf ib "%[]]" (function + | "]" -> accu + | _ -> scan_elem ib accu) + +and scan_elem ib accu = + bscanf ib " %i " (fun i -> scan_elems ib (i :: accu)) +;; + +let scan_int_list ib = + bscanf ib " [ " (); + List.rev (scan_rest ib []) +;; + +let test22 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[1]") = [1] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4;]") = [1;2;3;4];; + +test (test22 ()) +;; + +(* Should work and does not with this version of scan_int_list! +scan_int_list (Scanning.from_string "[1;2;3;4; ]");; +(* Should lead to a bad input error. *) +scan_int_list (Scanning.from_string "[1;2;3;4 5]");; +scan_int_list (Scanning.from_string "[1;2;3;4;;");; +scan_int_list (Scanning.from_string "[1;2;3;4;; 5]");; +scan_int_list (Scanning.from_string "[1;2;3;4;; 23]");; +*) + +let rec scan_elems ib accu = + try bscanf ib " %i %1[;]" (fun i s -> + if s = "" then i :: accu else scan_elems ib (i :: accu)) with + | Scan_failure _ -> accu +;; + +(* The general int list scanner. *) +let rec scan_int_list ib = + bscanf ib "[ " (); + let accu = scan_elems ib [] in + bscanf ib " ]" (); + List.rev accu +;; + +(* The general HO list scanner. *) +let rec scan_elems ib scan_elem accu = + try scan_elem ib (fun i s -> + let accu = i :: accu in + if s = "" then accu else scan_elems ib scan_elem accu) with + | Scan_failure _ -> accu +;; + +let scan_list scan_elem ib = + bscanf ib "[ " (); + let accu = scan_elems ib scan_elem [] in + bscanf ib " ]" (); + List.rev accu +;; + +(* Deriving particular list scanners from the HO list scanner. *) +let scan_int_elem ib = bscanf ib " %i %1[;]";; +let scan_int_list = scan_list scan_int_elem;; + +let test23 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[1]") = [1] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4;]") = [1;2;3;4];; + +test (test23 ()) +;; + +let test24 () = + scan_failure_test scan_int_list (Scanning.from_string "[1;2;3;4 5]") +and test25 () = + scan_failure_test scan_int_list (Scanning.from_string "[1;2;3;4;;") +and test26 () = + scan_failure_test scan_int_list (Scanning.from_string "[1;2;3;4;; 5]") +and test27 () = + scan_failure_test scan_int_list (Scanning.from_string "[1;2;3;4;; 23]");; + + (test24 ()) && + (test25 ()) && + (test26 ()) && + (test27 ()) +;; + +(* To scan a Caml string: + the format is "\"%s@\"". + A better way would be to add a %S (String.escaped), a %C (Char.escaped). + This is now available. *) +let scan_string_elem ib = bscanf ib " \"%s@\" %1[;]";; +let scan_string_list = scan_list scan_string_elem;; + +let scan_String_elem ib = bscanf ib " %S %1[;]";; +let scan_String_list = scan_list scan_String_elem;; + +let test28 () = + scan_string_list (Scanning.from_string "[]") = [] && + scan_string_list (Scanning.from_string "[\"Le\"]") = ["Le"] && + scan_string_list + (Scanning.from_string "[\"Le\";\"langage\";\"Objective\";\"Caml\"]") = + ["Le"; "langage"; "Objective"; "Caml"] && + scan_string_list + (Scanning.from_string "[\"Le\";\"langage\";\"Objective\";\"Caml\"; ]") = + ["Le"; "langage"; "Objective"; "Caml"] && + + scan_String_list (Scanning.from_string "[]") = [] && + scan_String_list (Scanning.from_string "[\"Le\"]") = ["Le"] && + scan_String_list + (Scanning.from_string "[\"Le\";\"langage\";\"Objective\";\"Caml\"]") = + ["Le"; "langage"; "Objective"; "Caml"] && + scan_String_list + (Scanning.from_string "[\"Le\";\"langage\";\"Objective\";\"Caml\"; ]") = + ["Le"; "langage"; "Objective"; "Caml"];; + +test (test28 ()) +;; + +(* The general HO list scanner with continuations. *) +let rec scan_elems ib scan_elem accu = + scan_elem ib + (fun i s -> + let accu = i :: accu in + if s = "" then accu else scan_elems ib scan_elem accu) + (fun ib exc -> accu) +;; + +let scan_list scan_elem ib = + bscanf ib "[ " (); + let accu = scan_elems ib scan_elem [] in + bscanf ib " ]" (); + List.rev accu +;; + +(* Deriving particular list scanners from the HO list scanner. *) +let scan_int_elem ib f ek = kscanf ib ek " %i %1[;]" f;; +let scan_int_list = scan_list scan_int_elem;; + +let test29 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[1]") = [1] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4;]") = [1;2;3;4];; + +test (test29 ()) +;; + +let scan_string_elem ib f ek = kscanf ib ek " %S %1[;]" f;; +let scan_string_list = scan_list scan_string_elem;; + +let test30 () = + scan_string_list (Scanning.from_string "[]") = [] && + scan_string_list (Scanning.from_string "[ ]") = [] && + scan_string_list (Scanning.from_string "[ \"1\" ]") = ["1"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\"]") = + ["1"; "2"; "3"; "4"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\";]") = + ["1"; "2"; "3"; "4"];; + +test (test30 ()) +;; + +(* A generic scan_elem, *) +let scan_elem fmt ib f ek = kscanf ib ek fmt f;; + +(* Derivation of list scanners from the generic polymorphic scanners. *) +let scan_int_list = scan_list (scan_elem " %i %1[;]");; +let scan_string_list = scan_list (scan_elem " %S %1[;]");; +let scan_bool_list = scan_list (scan_elem " %B %1[;]");; +let scan_char_list = scan_list (scan_elem " %C %1[;]");; +let scan_float_list = scan_list (scan_elem " %f %1[;]");; + +let rec scan_elems ib scan_elem accu = + scan_elem ib + (fun i -> + let accu = i :: accu in + kscanf ib + (fun ib exc -> accu) + " %1[;]" + (fun s -> if s = "" then accu else scan_elems ib scan_elem accu)) + (fun ib exc -> accu) +;; + +let scan_list scan_elem ib = + bscanf ib "[ " (); + let accu = scan_elems ib scan_elem [] in + bscanf ib " ]" (); + List.rev accu +;; + +let scan_int_list = scan_list (scan_elem " %i");; +let scan_string_list = scan_list (scan_elem " %S");; +let scan_bool_list = scan_list (scan_elem " %B");; +let scan_char_list = scan_list (scan_elem " %C");; +let scan_float_list = scan_list (scan_elem " %f");; + +let test31 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[1]") = [1] && + scan_int_list (Scanning.from_string "[1;2;3;4]") = [1;2;3;4] && + scan_int_list (Scanning.from_string "[1;2;3;4;]") = [1;2;3;4];; + +test (test31 ()) +;; + +let test32 () = + scan_string_list (Scanning.from_string "[]") = [] && + scan_string_list (Scanning.from_string "[ ]") = [] && + scan_string_list (Scanning.from_string "[ \"1\" ]") = ["1"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\"]") = + ["1"; "2"; "3"; "4"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\";]") = + ["1"; "2"; "3"; "4"];; + +test (test32 ()) +;; + +(* Using kscanf only. + Using formats as ``functional'' specifications to scan elements of + lists. *) +let rec scan_elems ib scan_elem_fmt accu = + kscanf ib (fun ib exc -> accu) + scan_elem_fmt + (fun i -> + let accu = i :: accu in + kscanf ib (fun ib exc -> accu) + " %1[;] " + (function + | "" -> accu + | _ -> scan_elems ib scan_elem_fmt accu) + ) +;; + +let scan_list scan_elem_fmt ib = + bscanf ib "[ " (); + let accu = scan_elems ib scan_elem_fmt [] in + bscanf ib " ]" (); + List.rev accu +;; + +let scan_int_list = scan_list "%i";; +let scan_string_list = scan_list "%S";; +let scan_bool_list = scan_list "%B";; +let scan_char_list = scan_list "%C";; +let scan_float_list = scan_list "%f";; + +let test33 () = + scan_int_list (Scanning.from_string "[]") = [] && + scan_int_list (Scanning.from_string "[ ]") = [] && + scan_int_list (Scanning.from_string "[ 1 ]") = [1] && + scan_int_list (Scanning.from_string "[ 1; 2; 3; 4 ]") = [1; 2; 3; 4] && + scan_int_list (Scanning.from_string "[1;2;3;4;]") = [1; 2; 3; 4];; + +test (test33 ()) +;; + +let test34 () = + scan_string_list (Scanning.from_string "[]") = [] && + scan_string_list (Scanning.from_string "[ ]") = [] && + scan_string_list (Scanning.from_string "[ \"1\" ]") = ["1"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\"]") = + ["1"; "2"; "3"; "4"] && + scan_string_list + (Scanning.from_string "[\"1\"; \"2\"; \"3\"; \"4\";]") = + ["1"; "2"; "3"; "4"];; + +(* Using kscanf only. + Using functions to scan elements of lists. *) +let rec scan_elems ib scan_elem accu = + scan_elem ib + (fun elem -> + let accu = elem :: accu in + kscanf ib (fun ib exc -> accu) + " %1[;] " + (function + | "" -> accu + | _ -> scan_elems ib scan_elem accu)) +;; + +let scan_list scan_elem ib = + bscanf ib "[ " (); + let accu = scan_elems ib scan_elem [] in + bscanf ib " ]" (); + List.rev accu +;; + +let scan_float ib = Scanf.bscanf ib "%f";; + +let scan_int_list = scan_list (fun ib -> Scanf.bscanf ib "%i");; +let scan_string_list = scan_list (fun ib -> Scanf.bscanf ib "%S");; +let scan_bool_list = scan_list (fun ib -> Scanf.bscanf ib "%B");; +let scan_char_list = scan_list (fun ib -> Scanf.bscanf ib "%C");; +let scan_float_list = scan_list scan_float;; + +(* Scanning list of lists of floats. *) +let scan_float_list_list = + scan_list + (fun ib k -> k (scan_list (fun ib -> Scanf.bscanf ib "%f") ib)) +;; + +let scan_float_list_list = + scan_list + (fun ib k -> k (scan_list scan_float ib)) +;; + +let scan_float_list_list = + scan_list + (fun ib k -> k (scan_float_list ib)) +;; + +(* A general scan_list_list functional. *) +let scan_list_list scan_elems ib = + scan_list + (fun ib k -> k (scan_elems ib)) ib +;; + +let scan_float_list_list = scan_list_list scan_float_list;; + +(* Programming with continuations :) *) +let scan_float_item ib k = k (scan_float ib (fun x -> x));; +let scan_float_list ib k = k (scan_list scan_float_item ib);; +let scan_float_list_list ib k = k (scan_list scan_float_list ib);; + +test (test34 ()) +;; + +(* Testing the %N format. *) +let test35 () = + sscanf "" "%N" (fun x -> x) = 0 && + sscanf "456" "%N" (fun x -> x) = 0 && + sscanf "456" "%d%N" (fun x y -> x, y) = (456, 1) && + sscanf " " "%N%s%N" (fun x s y -> x, s, y) = (0, "", 1) +;; + +test (test35 ()) +;; + +(* Testing the %n format. *) +let test36 () = + sscanf "" "%n" (fun x -> x) = 0 && + sscanf "456" "%n" (fun x -> x) = 0 && + sscanf "456" "%d%n" (fun x y -> x, y) = (456, 3) && + sscanf " " "%n%s%n" (fun x s y -> x, s, y) = (0, "", 0) +;; + +test (test36 ()) +;; + +(* Weird tests to empty strings or formats. *) +let test37 () = + sscanf "" "" true && + sscanf "" "" (fun x -> x) 1 = 1 && + sscanf "123" "" (fun x -> x) 1 = 1 +;; + +test (test37 ()) +;; + +(* Testing end of input condition. *) +let test38 () = + sscanf "a" "a%!" true && + sscanf "a" "a%!%!" true && + sscanf " a" " a%!" true && + sscanf "a " "a %!" true && + sscanf "" "%!" true && + sscanf " " " %!" true && + sscanf "" " %!" true && + sscanf "" " %!%!" true +;; + +test (test38 ()) +;; + +(* Weird tests on empty buffers. *) +let test39 () = + let is_empty_buff ib = + Scanning.beginning_of_input ib && + Scanning.end_of_input ib in + + let ib = Scanning.from_string "" in + is_empty_buff ib && + (* Do it twice since testing empty buff could incorrectly + thraw an exception or wrongly change the beginning_of_input condition. *) + is_empty_buff ib +;; + +test (test39 ()) +;; + +(* Testing ranges. *) +let test40 () = + let s = "cba" in + let ib = Scanning.from_string s in + bscanf ib "%[^ab]%s%!" (fun s1 s2 -> s1 = "c" && s2 = "ba") +;; + +test (test40 ()) +;; + +let test41 () = + let s = "cba" in + let ib = Scanning.from_string s in + bscanf ib "%[^abc]%[cba]%!" (fun s1 s2 -> s1 = "" && s2 = "cba") +;; + +test (test41 ()) +;; + +let test42 () = + let s = "defcbaaghi" in + let ib = Scanning.from_string s in + bscanf ib "%[^abc]%[abc]%s%!" (fun s1 s2 s3 -> + s1 = "def" && s2 = "cbaa" && s3 = "ghi") && + let ib = Scanning.from_string s in + bscanf ib "%s@\t" (fun s -> s = "defcbaaghi") +;; + +test (test42 ()) +;; + +(* Testing end of file condition (bug found). *) +let test43, test44 = + let s = "" in + let ib = Scanning.from_string s in + (fun () -> bscanf ib "%i%!" (fun i -> i)), + (fun () -> bscanf ib "%!%i" (fun i -> i)) +;; + +test_raises_this_exc End_of_file test43 () && +test_raises_this_exc End_of_file test44 () +;; + +(* Testing small range scanning (bug found once). *) +let test45 () = + let s = "12.2" in + let ib = Scanning.from_string s in + bscanf ib "%[0-9].%[0-9]%s%!" (fun s1 s2 s3 -> + s1 = "12" && s2 = "2" && s3 = "") +;; + +test (test45 ()) +;; + +(* Testing printing of meta formats. *) + +let test46, test47 = + (fun () -> + Printf.sprintf "%i %(%s%)." + 1 "spells one, %s" "in english"), + (fun () -> + Printf.sprintf "%i ,%{%s%}, %s." + 1 "spells one %s" "in english") +;; + +test (test46 () = "1 spells one, in english.") +;; +test (test47 () = "1 ,%s, in english.") +;; + +(* Testing scanning of meta formats. *) +let test48 () = + (* Testing format_from_string. *) + let test_meta_read s fmt efmt = format_from_string s fmt = efmt in + (* Test if format %i is indeed read as %i. *) + let s, fmt = "%i", format_of_string "%i" in + test_meta_read s fmt fmt && + (* Test if format %i is compatible with %d and indeed read as %i. *) + let s, fmt = "%i", format_of_string "%d" in + test_meta_read s fmt "%i" && + (* Complex test of scanning a meta format specified in the scanner input + format string and extraction of its specification from a string. *) + sscanf "12 \"%i\"89 " "%i %{%d%}%s %!" + (fun i f s -> i = 12 && f = "%i" && s = "89") +;; + +test (test48 ()) +;; + +(* Testing stoppers after ranges. *) +let test49 () = + sscanf "as" "%[\\]" (fun s -> s = "") && + sscanf "as" "%[\\]%s" (fun s t -> s = "" && t = "as") && + sscanf "as" "%[\\]%s%!" (fun s t -> s = "" && t = "as") && + sscanf "as" "%[a..z]" (fun s -> s = "a") && + sscanf "as" "%[a-z]" (fun s -> s = "as") && + sscanf "as" "%[a..z]%s" (fun s t -> s = "a" && t = "s") && + sscanf "as" "%[a-z]%s" (fun s t -> s = "as" && t = "") && + sscanf "-as" "%[-a-z]" (fun s -> s = "-as") && + sscanf "-as" "%[-a-z]@s" (fun s -> s = "-a") && + sscanf "-as" "-%[a]@s" (fun s -> s = "a") && + sscanf "-asb" "-%[a]@sb%!" (fun s -> s = "a") && + sscanf "-asb" "-%[a]@s%s" (fun s t -> s = "a" && t = "b") +;; + +test (test49 ()) +;; + +(* Testing buffers defined via functions + + co-routines that read and write from the same buffers + + range chars and proper handling of \n + + the end of file condition. *) +let next_char ob () = + let s = Buffer.contents ob in + let len = String.length s in + if len = 0 then raise End_of_file else + let c = s.[0] in + Buffer.clear ob; + Buffer.add_string ob (String.sub s 1 (len - 1)); + c +;; + +let send_string ob s = + Buffer.add_string ob s; Buffer.add_char ob '\n';; +let send_int ob i = send_string ob (string_of_int i);; + +let rec reader = + let count = ref 0 in + (fun ib ob -> + if Scanf.Scanning.beginning_of_input ib then begin + count := 0; send_string ob "start"; writer ib ob end else + Scanf.bscanf ib "%[^\n]\n" (function + | "stop" -> send_string ob "stop"; writer ib ob + | s -> + let l = String.length s in + count := l + !count; + if !count >= 100 then begin + send_string ob "stop"; + send_int ob !count + end else + send_int ob l; + writer ib ob)) + +and writer ib ob = + Scanf.bscanf ib "%s\n" (function + | "start" -> send_string ob "Hello World!"; reader ib ob + | "stop" -> Scanf.bscanf ib "%i" (function i -> i) + | s -> send_int ob (int_of_string s); reader ib ob);; + +let go () = + let ob = Buffer.create 17 in + let ib = Scanf.Scanning.from_function (next_char ob) in + reader ib ob +;; + +let test50 () = go () = 100;; + +test (test50 ()) +;; + +(* Simple tests may also fail! *) +let test51 () = + sscanf "Hello" "%s" id = "Hello" && + sscanf "Hello\n" "%s\n" id = "Hello" && + sscanf "Hello\n" "%s%s\n" (fun s1 s2 -> + s1 = "Hello" && s2 = "") && + sscanf "Hello\nWorld" "%s\n%s%!" (fun s1 s2 -> + s1 = "Hello" && s2 = "World") && + sscanf "Hello\nWorld!" "%s\n%s" (fun s1 s2 -> + s1 = "Hello" && s2 = "World!") && + sscanf "Hello\n" "%s@\n%s" (fun s1 s2 -> + s1 = "Hello" && s2 = "") && + sscanf "Hello \n" "%s@\n%s" (fun s1 s2 -> + s1 = "Hello " && s2 = "") +;; + +test (test51 ()) +;; + +(* Tests that indeed %s@c format works properly. + Also tests the difference between \n and @\n. + In particular, tests that if no c character can be found in the + input, then the token obtained for %s@c spreads to the end of + input. *) +let test52 () = + sscanf "Hello\n" "%s@\n" id = "Hello" && + sscanf "Hello" "%s@\n" id = "Hello" && + sscanf "Hello" "%s%s@\n" (fun s1 s2 -> + s1 = "Hello" && s2 = "") && + sscanf "Hello\nWorld" "%s@\n%s%!" (fun s1 s2 -> + s1 = "Hello" && s2 = "World") && + sscanf "Hello\nWorld!" "%s@\n%s@\n" (fun s1 s2 -> + s1 = "Hello" && s2 = "World!") && + sscanf "Hello\n" "%s@\n%s" (fun s1 s2 -> + s1 = "Hello" && s2 = "") && + sscanf "Hello \n" "%s%s@\n" (fun s1 s2 -> + s1 = "Hello" && s2 = " ") +;; + +test (test52 ()) +;; + +(* Reading native, int32 and int64 numbers. *) +let test53 () = + sscanf "123" "%nd" id = 123n && + sscanf "124" "%nd" (fun i -> Nativeint.pred i = 123n) && + + sscanf "123" "%ld" id = 123l && + sscanf "124" "%ld" (fun i -> Int32.succ i = 125l) && + + sscanf "123" "%Ld" id = 123L && + sscanf "124" "%Ld" (fun i -> Int64.pred i = 123L) +;; + +test (test53 ()) +;; + +(* Routines to create the file that tscanf uses as a testbed case. *) +let create_tscanf_data ob lines = + let add_line (p, e) = + Buffer.add_string ob (Printf.sprintf "%S" p); + Buffer.add_string ob " -> "; + Buffer.add_string ob (Printf.sprintf "%S" e); + Buffer.add_string ob ";\n" in + List.iter add_line lines +;; + +let write_tscanf_data_file fname lines = + let oc = open_out fname in + let ob = Buffer.create 42 in + create_tscanf_data ob lines; + Buffer.output_buffer oc ob; + close_out oc +;; + +(* The tscanf testbed case file name. *) +let tscanf_data_file = "tscanf_data";; +(* The contents of the tscanf testbed case file. *) +let tscanf_data_file_lines = [ + "Objective", "Caml"; +] +;; +(* We write the tscanf testbed case file. *) +write_tscanf_data_file tscanf_data_file tscanf_data_file_lines +;; + +(* Then we verify that its contents is indeed correct. *) + +(* Reading back tscanf_data_file_lines (hence testing data file reading). *) +let get_lines fname = + let ib = Scanf.Scanning.from_file fname in + let l = ref [] in + try + while not (Scanf.Scanning.end_of_input ib) do + Scanf.bscanf ib " %S -> %S; " (fun x y -> + l := (x, y) :: !l) + done; + List.rev !l + with + | Scanf.Scan_failure s -> + failwith (Printf.sprintf "in file %s, %s" fname s) + | End_of_file -> + failwith (Printf.sprintf "in file %s, unexpected end of file" fname) +;; + +let test54 () = + get_lines tscanf_data_file = tscanf_data_file_lines +;; + +test (test54 ()) +;; + +(* Creating digests for files. *) +let add_digest_ib ob ib = + let digest s = String.uppercase (Digest.to_hex (Digest.string s)) in + let scan_line ib f = Scanf.bscanf ib "%[^\n\r]\n" f in + let output_line_digest s = + Buffer.add_string ob s; + Buffer.add_char ob '#'; Buffer.add_string ob (digest s); + Buffer.add_char ob '\n' in + try + while true do scan_line ib output_line_digest done; + with End_of_file -> () +;; + +let digest_file fname = + let ib = Scanf.Scanning.from_file fname in + let ob = Buffer.create 42 in + add_digest_ib ob ib; + Buffer.contents ob +;; + +let test55 () = + let ob = Buffer.create 42 in + let ib = + create_tscanf_data ob tscanf_data_file_lines; + let s = Buffer.contents ob in + Buffer.clear ob; + Scanning.from_string s in + let tscanf_data_file_lines_digest = add_digest_ib ob ib; Buffer.contents ob in + digest_file tscanf_data_file = tscanf_data_file_lines_digest +;; + +test (test55 ()) +;; + +(* Testing the number of characters read. *) +let test56 () = + let g s = Scanf.sscanf s "%d%n" (fun i n -> (i, n)) in + g "99" = (99, 2) && + g "99 syntaxes all in a row" = (99, 2) && + g "-20 degrees Celsius" = (-20, 3) +;; + +test (test56 ()) +;; + +(* To be continued ... +(* Trying to scan records. *) +let rec scan_fields ib scan_field accu = + kscanf ib (fun ib exc -> accu) + scan_field + (fun i -> + let accu = i :: accu in + kscanf ib (fun ib exc -> accu) + " %1[;] " + (fun s -> + if s = "" then accu else scan_fields ib scan_field accu)) +;; + +let scan_record scan_field ib = + bscanf ib "{ " (); + let accu = scan_fields ib scan_field [] in + bscanf ib " }" (); + List.rev accu +;; + +let scan_field ib = + bscanf ib "%s = %[^;]" (fun finame ficont -> finame, ficont);; +*) diff --git a/test/Moretest/tscanf2_io.ml b/test/Moretest/tscanf2_io.ml new file mode 100644 index 0000000..11c503d --- /dev/null +++ b/test/Moretest/tscanf2_io.ml @@ -0,0 +1,18 @@ +(* A very simple communication module using buffers. It should help detecting + advanced character reading by Scanf when using stdin. *) + +let send_flush send ob oc t = + send ob t; + Buffer.output_buffer oc ob; + Buffer.clear ob; + flush oc;; + +(* The correct sending format for the test should be "%S\n", + but to avoid problems when Scanf ask too early for the next character, + "%S\n\n" is fine. *) +let send_string = send_flush (fun ob -> Printf.bprintf ob "%S\n");; + +(* The correct reading format for the test should be "%S\n", + but to avoid problems when Scanf ask too early for the next character, + " %S\n" is fine. *) +let receive_string ib = Scanf.bscanf ib "%S\n" (fun s -> s);; diff --git a/test/Moretest/tscanf2_master.ml b/test/Moretest/tscanf2_master.ml new file mode 100644 index 0000000..8ff5ef8 --- /dev/null +++ b/test/Moretest/tscanf2_master.ml @@ -0,0 +1,40 @@ +(* A very simple master: + - first launch a slave process, + - then repeat a random number of times: + + print the string " Ping" on stderr, + + send it to the slave, + + and wait for its answer "-pong", + - finally send the string "stop" to the slave + and wait for its answer "OK, bye!" + and die. + + Use the communication module Test_scanf_io. + + Usage: test_master <slave_name> *) + +open Tscanf2_io;; + +let slave = Sys.argv.(1);; +let ic, oc = Unix.open_process slave;; +let ib = Scanf.Scanning.from_channel ic;; +let ob = Buffer.create 1024;; + +let send_string_ping ob = send_string ob oc " Ping";; +let send_string_stop ob = send_string ob oc "stop";; + +let interact i = + Printf.eprintf " Ping"; flush stderr; + send_string_ping ob; + let s = receive_string ib in + if s <> "-pong" then failwith ("Master: unbound string " ^ s);; + +Random.self_init (); +let n = max (Random.int 8) 1 in +let rec loop i = + if i > 0 then (interact i; loop (i - 1)) in +loop n;; + +send_string_stop ob; +let ack = receive_string ib in +if ack = "OK, bye!" then (prerr_endline "Test OK."; exit 0) else +(prerr_endline "Test Failed!"; exit 2);; diff --git a/test/Moretest/tscanf2_slave.ml b/test/Moretest/tscanf2_slave.ml new file mode 100644 index 0000000..5d6b413 --- /dev/null +++ b/test/Moretest/tscanf2_slave.ml @@ -0,0 +1,27 @@ +(* A very simple slave: + - read the string " Ping" on stdin, + - then print the string "-pong" on stderr, + - and send it back on stdout + - until reading the string "stop" on stdin, + - then print the string "!\n" on stderr, + - send back the string "OK, bye!" on stdout, + - and die. + + Use the communication module Test_scanf_io. *) + +open Tscanf2_io;; + +let ib = Scanf.Scanning.from_channel stdin;; +let ob = Buffer.create 1024 +and oc = stdout;; + +let send_string_pong ob = send_string ob oc "-pong";; +let send_string_okbye ob = send_string ob oc "OK, bye!";; + +while true do + let s = receive_string ib in + match s with + | " Ping" -> Printf.eprintf "-pong"; flush stderr; send_string_pong ob + | "stop" -> Printf.eprintf "!\n"; flush stderr; send_string_okbye ob; exit 0 + | s -> failwith ("Slave: unbound string " ^ s) +done;; diff --git a/test/Moretest/usemultdef.ml b/test/Moretest/usemultdef.ml new file mode 100644 index 0000000..2bccabb --- /dev/null +++ b/test/Moretest/usemultdef.ml @@ -0,0 +1 @@ +let _ = print_int(Multdef.f 1); print_newline(); exit 0 diff --git a/test/Moretest/warnings.ml b/test/Moretest/warnings.ml new file mode 100644 index 0000000..08e2f29 --- /dev/null +++ b/test/Moretest/warnings.ml @@ -0,0 +1,44 @@ + +(* C *) + +let foo = ( *);; + + +(* F *) + +let f x y = x;; +f 1; f 1;; + + +(* M *) + +(* duh *) + + +(* P *) + +let 1 = 1;; + + +(* S *) + +1; 1;; + + +(* U *) + +match 1 with +| 1 -> () +| 1 -> () +| _ -> () +;; + + +(* V *) + +(* re-duh *) + + +(* X *) + +(* re-re *) diff --git a/test/Moretest/wc.ml b/test/Moretest/wc.ml new file mode 100644 index 0000000..dbe46d9 --- /dev/null +++ b/test/Moretest/wc.ml @@ -0,0 +1,54 @@ +(* Counts characters, lines and words in one or several files. *) + +let chars = ref 0 +and words = ref 0 +and lines = ref 0 + +type state = Inside_word | Outside_word + +let count_channel in_channel = + let rec count status = + let c = input_char in_channel in + incr chars; + match c with + '\n' -> + incr lines; count Outside_word + | ' ' | '\t' -> + count Outside_word + | _ -> + if status = Outside_word then begin incr words; () end; + count Inside_word + in + try + count Outside_word + with End_of_file -> + () + +let count_file name = + let ic = open_in name in + count_channel ic; + close_in ic + +let print_result () = + print_int !chars; print_string " characters, "; + print_int !words; print_string " words, "; + print_int !lines; print_string " lines"; + print_newline() + +let count name = + count_file name; + print_result () + +let _ = +try + if Array.length Sys.argv <= 1 then + count_channel stdin (* No command-line arguments *) + else + for i = 1 to Array.length Sys.argv - 1 do + count_file Sys.argv.(i) + done; + print_result () +with Sys_error s -> + print_string "I/O error: "; + print_string s; + print_newline() diff --git a/test/Results/almabench.fast.out b/test/Results/almabench.fast.out new file mode 100644 index 0000000..5c1d8b8 --- /dev/null +++ b/test/Results/almabench.fast.out @@ -0,0 +1,8 @@ +0 17.00 -26.06 +1 12.34 1.29 +2 6.83 22.95 +3 0.04 -1.26 +4 2.30 12.54 +5 2.93 14.35 +6 21.27 -16.57 +7 20.41 -19.04 diff --git a/test/Results/almabench.out b/test/Results/almabench.out new file mode 100644 index 0000000..5c1d8b8 --- /dev/null +++ b/test/Results/almabench.out @@ -0,0 +1,8 @@ +0 17.00 -26.06 +1 12.34 1.29 +2 6.83 22.95 +3 0.04 -1.26 +4 2.30 12.54 +5 2.93 14.35 +6 21.27 -16.57 +7 20.41 -19.04 diff --git a/test/Results/bdd.out b/test/Results/bdd.out new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/test/Results/bdd.out @@ -0,0 +1 @@ +OK diff --git a/test/Results/boyer.out b/test/Results/boyer.out new file mode 100644 index 0000000..f38e326 --- /dev/null +++ b/test/Results/boyer.out @@ -0,0 +1 @@ +Proved! diff --git a/test/Results/fft.fast.out b/test/Results/fft.fast.out new file mode 100644 index 0000000..b0f1238 --- /dev/null +++ b/test/Results/fft.fast.out @@ -0,0 +1,16 @@ +16... ok +32... ok +64... ok +128... ok +256... ok +512... ok +1024... ok +2048... ok +4096... ok +8192... ok +16384... ok +32768... ok +65536... ok +131072... ok +262144... ok +524288... ok diff --git a/test/Results/fft.out b/test/Results/fft.out new file mode 100644 index 0000000..b0f1238 --- /dev/null +++ b/test/Results/fft.out @@ -0,0 +1,16 @@ +16... ok +32... ok +64... ok +128... ok +256... ok +512... ok +1024... ok +2048... ok +4096... ok +8192... ok +16384... ok +32768... ok +65536... ok +131072... ok +262144... ok +524288... ok diff --git a/test/Results/fib.out b/test/Results/fib.out new file mode 100644 index 0000000..1d7ca9c --- /dev/null +++ b/test/Results/fib.out @@ -0,0 +1 @@ +165580141 diff --git a/test/Results/hamming.out b/test/Results/hamming.out new file mode 100644 index 0000000..af1339e --- /dev/null +++ b/test/Results/hamming.out @@ -0,0 +1,100 @@ +6726050156250000000000000000000000000 +6729216728661136606575523242669244416 +6730293634611118019721084375000000000 +6731430439413948088320000000000000000 +6733644878411293029785156250000000000 +6736815026358904613608094481682268160 +6739031236724077363200000000000000000 +6743282904874568941599068856042651648 +6744421903677486140423997176256921600 +6746640616477458432000000000000000000 +6750000000000000000000000000000000000 +6750897085400702945836103937453588480 +6752037370304563380023474956271616000 +6754258588364960445000000000000000000 +6755399441055744000000000000000000000 +6757621765136718750000000000000000000 +6758519863481752323552044362431792300 +6759661435938757375539248533340160000 +6761885162088395001166534423828125000 +6763027302973440000000000000000000000 +6765252136392518877983093261718750000 +6767294110289640371843415775641600000 +6768437164792816653010961694720000000 +6770663777894400000000000000000000000 +6774935403077748181101173538816000000 +6776079748261363229431903027200000000 +6778308875544000000000000000000000000 +6782585324034592562287109312160000000 +6783730961356018699387011072000000000 +6785962605658597412109375000000000000 +6789341568946838378906250000000000000 +6791390813820928754681118720000000000 +6794772480000000000000000000000000000 +6799059315411241693033267200000000000 +6800207735332289107722240000000000000 +6802444800000000000000000000000000000 +6806736475893120841673472000000000000 +6807886192552970708582400000000000000 +6810125783203125000000000000000000000 +6814422305043756994967597929687500000 +6815573319906622439424000000000000000 +6817815439391434192657470703125000000 +6821025214188390921278195662703296512 +6821210263296961784362792968750000000 +6823269127183128330240000000000000000 +6828727177473454717179297140960133120 +6830973624183426662400000000000000000 +6834375000000000000000000000000000000 +6835283298968211732659055236671758336 +6836437837433370422273768393225011200 +6838686820719522450562500000000000000 +6839841934068940800000000000000000000 +6842092037200927734375000000000000000 +6844157203887991842733489140006912000 +6845313241232438768082197309030400000 +6847565144260608000000000000000000000 +6849817788097425363957881927490234375 +6851885286668260876491458472837120000 +6853042629352726861173598715904000000 +6855297075118080000000000000000000000 +6859622095616220033364938208051200000 +6860780745114630269799801815040000000 +6863037736488300000000000000000000000 +6866455078125000000000000000000000000 +6867367640585024969315698178562000000 +6868527598372968933129348710400000000 +6870787138229329879760742187500000000 +6871947673600000000000000000000000000 +6874208338558673858642578125000000000 +6876283198993690364114632704000000000 +6879707136000000000000000000000000000 +6884047556853882214196183040000000000 +6885210332023942721568768000000000000 +6887475360000000000000000000000000000 +6891820681841784852194390400000000000 +6892984769959882842439680000000000000 +6895252355493164062500000000000000000 +6899602583856803957404692903808593750 +6900767986405455219916800000000000000 +6903038132383827120065689086914062500 +6906475391588173806667327880859375000 +6908559991272917434368000000000000000 +6912000000000000000000000000000000000 +6914086267191872901144038355222134784 +6916360794485719495680000000000000000 +6917529027641081856000000000000000000 +6919804687500000000000000000000000000 +6921893310401287552552190498140323840 +6924170405978516481194531250000000000 +6925339958244802560000000000000000000 +6927618187665939331054687500000000000 +6929709168936591740767657754256998400 +6930879656747844252683224775393280000 +6933159708563865600000000000000000000 +6937533852751614137447601703747584000 +6938705662219635946938268699852800000 +6940988288557056000000000000000000000 +6945367371811422783781999935651840000 +6946540504428563148172299337728000000 +6948825708194403750000000000000000000 diff --git a/test/Results/kb.out b/test/Results/kb.out new file mode 100644 index 0000000..2789a66 --- /dev/null +++ b/test/Results/kb.out @@ -0,0 +1,5460 @@ +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*I(C)) +7 : C*(B*I(C)) = B +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +11 : C*(A*(I(C)*A)) = U +12 : C*(B*(I(C)*v1)) = B*v1 +13 : I(U)*v1 = v1 +14 : I(I(v1))*U = v1 +15 : I(v3*v2)*(v3*(v2*v1)) = v1 +16 : C*(A*(I(C)*(B*A))) = B +17 : I(C)*U = C +18 : C*(A*(I(C)*(A*v1))) = v1 +19 : I(C)*B = B*I(C) +20 : I(I(v2))*v1 = v2*v1 +Rule 14 deleted +21 : v1*U = v1 +Rule 17 deleted +22 : I(C) = C +Rule 19 deleted +Rule 18 deleted +Rule 16 deleted +Rule 12 deleted +Rule 11 deleted +Rule 7 deleted +23 : C*B = B*C +24 : C*(A*(C*(A*v1))) = v1 +25 : C*(A*(C*(B*A))) = B +26 : C*(B*(C*v1)) = B*v1 +27 : C*(A*(C*A)) = U +28 : C*(B*C) = B +29 : C*(A*(C*(B*(A*v1)))) = B*v1 +30 : I(I(v2*v1)*v2) = v1 +31 : I(v2*I(v1))*v2 = v1 +32 : I(v4*(v3*v2))*(v4*(v3*(v2*v1))) = v1 +33 : I(v1*A)*(v1*(B*A)) = B +34 : I(v1*C)*v1 = C +35 : I(v3*I(v2))*(v3*v1) = v2*v1 +36 : I(v2*A)*(v2*(B*(A*v1))) = B*v1 +37 : I(v2*C)*(v2*v1) = C*v1 +38 : v1*I(v1) = U +39 : I(C*(A*C))*v1 = A*v1 +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +Rule 13 deleted +42 : I(I(v1)) = v1 +Rule 20 deleted +43 : C*(B*v1) = B*(C*v1) +Rule 29 deleted +Rule 28 deleted +Rule 26 deleted +Rule 25 deleted +44 : A*(C*(A*v1)) = C*v1 +Rule 24 deleted +45 : A*(C*A) = C +Rule 27 deleted +46 : v2*(I(v1*v2)*v1) = U +47 : I(I(v3*(v2*v1))*(v3*v2)) = v1 +48 : I(I(B*A)*A) = B +49 : v3*(I(v2*v3)*(v2*v1)) = v1 +50 : I(I(v1)*I(v2)) = v2*v1 +51 : I(I(B*(A*v1))*A) = B*v1 +52 : I(I(v1)*C) = C*v1 +53 : I(v2*I(v1*v2)) = v1 +54 : I(v3*(v2*I(v1)))*(v3*v2) = v1 +55 : I(v1*(C*(A*C)))*v1 = A +56 : v2*I(I(v1)*v2) = v1 +57 : I(v2*(I(v3*v1)*v3))*v2 = v1 +58 : I(v5*(v4*(v3*v2)))*(v5*(v4*(v3*(v2*v1)))) = v1 +59 : I(v2*(v1*A))*(v2*(v1*(B*A))) = B +60 : I(v2*(v1*C))*(v2*v1) = C +61 : I(v4*(v3*I(v2)))*(v4*(v3*v1)) = v2*v1 +62 : I(v3*(v2*A))*(v3*(v2*(B*(A*v1)))) = B*v1 +63 : I(v3*(v2*C))*(v3*(v2*v1)) = C*v1 +64 : I(v3*(I(v4*v2)*v4))*(v3*v1) = v2*v1 +65 : v4*(I(v3*(v2*v4))*(v3*(v2*v1))) = v1 +66 : I(I(B)*A)*A = B +67 : I(A*A)*(B*(A*A)) = B +68 : v1*(I(A*v1)*(B*A)) = B +69 : I(I(v1*A)*(v1*B))*B = A +70 : v1*I(C*v1) = C +71 : I(A*I(v1))*(B*A) = v1*B +72 : I(C*I(v1)) = v1*C +73 : I(v2*(C*(A*C)))*(v2*v1) = A*v1 +74 : I(A*I(v2))*(B*(A*v1)) = v2*(B*v1) +75 : v3*(I(I(v2)*v3)*v1) = v2*v1 +76 : I(I(B*I(v1))*A)*(v1*A) = B +77 : I(v1*A)*(v1*(B*(B*A))) = B*B +78 : I(I(B)*A)*(A*v1) = B*v1 +79 : I(A*A)*(B*(A*(A*v1))) = B*v1 +80 : I(v2*A)*(v2*(B*(B*(A*v1)))) = B*(B*v1) +81 : v2*(I(A*v2)*(B*(A*v1))) = B*v1 +82 : I(I(v2*A)*(v2*B))*(B*v1) = A*v1 +83 : I(I(B*I(v2))*A)*(v2*(A*v1)) = B*v1 +84 : I(A*C)*(B*A) = B*C +85 : I(A*C)*(B*(A*v1)) = B*(C*v1) +86 : v2*(I(C*v2)*v1) = C*v1 +87 : I(I(B*C)*A)*(C*A) = B +88 : I(I(B*C)*A)*(C*(A*v1)) = B*v1 +89 : v2*(v1*I(v2*v1)) = U +90 : B*(A*I(B)) = A +91 : I(v2*v1)*v2 = I(v1) +Rule 64 deleted +Rule 57 deleted +Rule 55 deleted +Rule 46 deleted +Rule 34 deleted +Rule 31 deleted +Rule 30 deleted +92 : I(C*(A*C)) = A +Rule 39 deleted +93 : I(v3*(v2*v1))*(v3*v2) = I(v1) +Rule 60 deleted +Rule 54 deleted +Rule 47 deleted +94 : I(v1*I(v2)) = v2*I(v1) +Rule 83 deleted +Rule 76 deleted +Rule 74 deleted +Rule 72 deleted +Rule 71 deleted +Rule 53 deleted +Rule 50 deleted +Rule 35 deleted +95 : I(v2*(I(B)*A))*(v2*(A*v1)) = B*v1 +96 : I(v1*(I(B)*A))*(v1*A) = B +97 : I(v1*A)*(v1*B) = B*(C*(A*C)) +Rule 82 deleted +Rule 69 deleted +98 : I(v1*C) = C*I(v1) +Rule 88 deleted +Rule 87 deleted +Rule 85 deleted +Rule 84 deleted +Rule 52 deleted +Rule 37 deleted +99 : v3*(v2*(I(v3*v2)*v1)) = v1 +100 : B*(A*(I(B)*v1)) = A*v1 +101 : I(v3*v2)*(v3*v1) = I(v2)*v1 +Rule 97 deleted +Rule 96 deleted +Rule 95 deleted +Rule 93 deleted +Rule 80 deleted +Rule 77 deleted +Rule 73 deleted +Rule 65 deleted +Rule 63 deleted +Rule 62 deleted +Rule 61 deleted +Rule 59 deleted +Rule 58 deleted +Rule 49 deleted +Rule 36 deleted +Rule 33 deleted +Rule 32 deleted +Rule 15 deleted +102 : B*(C*I(B)) = C +103 : B*(C*(I(B)*v1)) = C*v1 +104 : B*(I(B*A)*A) = U +105 : B*(I(B*A)*(A*v1)) = v1 +106 : I(B*A)*A = I(B) +Rule 104 deleted +Rule 48 deleted +107 : B*(v1*(I(B*(A*v1))*A)) = U +108 : I(I(B*(B*A))*A) = B*B +109 : B*(v2*(I(B*(A*v2))*(A*v1))) = v1 +110 : I(I(B*(B*(A*v1)))*A) = B*(B*v1) +111 : I(I(B)*A) = B*(C*(A*C)) +Rule 78 deleted +Rule 66 deleted +112 : I(I(B*v1)*A) = B*(C*(A*(C*v1))) +Rule 110 deleted +Rule 108 deleted +Rule 51 deleted +113 : v3*(v2*I(I(v1)*(v3*v2))) = v1 +114 : v1*I(C*(A*(C*v1))) = A +115 : I(I(v1)*v2) = I(v2)*v1 +Rule 113 deleted +Rule 112 deleted +Rule 111 deleted +Rule 75 deleted +Rule 56 deleted +116 : v2*(v1*(I(A*(v2*v1))*(B*A))) = B +117 : I(A*v1)*(B*A) = I(v1)*B +Rule 116 deleted +Rule 68 deleted +118 : v2*(v1*I(C*(v2*v1))) = C +119 : I(C*v1) = I(v1)*C +Rule 118 deleted +Rule 114 deleted +Rule 92 deleted +Rule 86 deleted +Rule 70 deleted +120 : v1*(I(A*(C*v1))*C) = A +121 : I(A*A)*(B*(B*(A*A))) = B*B +122 : I(A*A)*(B*(B*(A*(A*v1)))) = B*(B*v1) +123 : I(A*A)*(B*(A*v1)) = B*(C*(A*(C*v1))) +Rule 79 deleted +Rule 67 deleted +124 : v3*(v2*(I(A*(v3*v2))*(B*(A*v1)))) = B*v1 +125 : v1*(I(A*v1)*(B*(B*A))) = B*B +126 : I(A*v2)*(B*(A*v1)) = I(v2)*(B*v1) +Rule 124 deleted +Rule 123 deleted +Rule 81 deleted +127 : v3*(v2*(v1*I(v3*(v2*v1)))) = U +128 : v2*I(v1*v2) = I(v1) +Rule 89 deleted +129 : A*I(B) = I(B)*A +Rule 90 deleted +130 : I(v1*v2) = I(v2)*I(v1) +Rule 128 deleted +Rule 127 deleted +Rule 126 deleted +Rule 125 deleted +Rule 122 deleted +Rule 121 deleted +Rule 120 deleted +Rule 119 deleted +Rule 117 deleted +Rule 115 deleted +Rule 109 deleted +Rule 107 deleted +Rule 106 deleted +Rule 105 deleted +Rule 101 deleted +Rule 99 deleted +Rule 98 deleted +Rule 94 deleted +Rule 91 deleted +131 : B*(C*(A*(C*(I(B)*(A*v1))))) = v1 +132 : B*(C*(A*(C*(I(B)*A)))) = U +133 : C*(A*(C*(I(B)*A))) = I(B) +Rule 132 deleted +134 : A*(I(B)*v1) = I(B)*(A*v1) +Rule 100 deleted +135 : C*I(B) = I(B)*C +Rule 102 deleted +136 : C*(I(B)*v1) = I(B)*(C*v1) +Rule 133 deleted +Rule 131 deleted +Rule 103 deleted +Canonical set found : +1 : U*v1 = v1 +2 : I(v1)*v1 = U +3 : (v3*v2)*v1 = v3*(v2*v1) +4 : A*B = B*A +5 : C*C = U +6 : I(A) = C*(A*C) +8 : I(v2)*(v2*v1) = v1 +9 : A*(B*v1) = B*(A*v1) +10 : C*(C*v1) = v1 +21 : v1*U = v1 +22 : I(C) = C +23 : C*B = B*C +38 : v1*I(v1) = U +40 : v2*(I(v2)*v1) = v1 +41 : I(U) = U +42 : I(I(v1)) = v1 +43 : C*(B*v1) = B*(C*v1) +44 : A*(C*(A*v1)) = C*v1 +45 : A*(C*A) = C +129 : A*I(B) = I(B)*A +130 : I(v1*v2) = I(v2)*I(v1) +134 : A*(I(B)*v1) = I(B)*(A*v1) +135 : C*I(B) = I(B)*C +136 : C*(I(B)*v1) = I(B)*(C*v1) diff --git a/test/Results/nucleic.out b/test/Results/nucleic.out new file mode 100644 index 0000000..14689cd --- /dev/null +++ b/test/Results/nucleic.out @@ -0,0 +1 @@ +33.7976 diff --git a/test/Results/quicksort.fast.out b/test/Results/quicksort.fast.out new file mode 100644 index 0000000..2c94e48 --- /dev/null +++ b/test/Results/quicksort.fast.out @@ -0,0 +1,2 @@ +OK +OK diff --git a/test/Results/quicksort.out b/test/Results/quicksort.out new file mode 100644 index 0000000..2c94e48 --- /dev/null +++ b/test/Results/quicksort.out @@ -0,0 +1,2 @@ +OK +OK diff --git a/test/Results/sieve.out b/test/Results/sieve.out new file mode 100644 index 0000000..eb96be0 --- /dev/null +++ b/test/Results/sieve.out @@ -0,0 +1 @@ +2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999 5003 5009 5011 5021 5023 5039 5051 5059 5077 5081 5087 5099 5101 5107 5113 5119 5147 5153 5167 5171 5179 5189 5197 5209 5227 5231 5233 5237 5261 5273 5279 5281 5297 5303 5309 5323 5333 5347 5351 5381 5387 5393 5399 5407 5413 5417 5419 5431 5437 5441 5443 5449 5471 5477 5479 5483 5501 5503 5507 5519 5521 5527 5531 5557 5563 5569 5573 5581 5591 5623 5639 5641 5647 5651 5653 5657 5659 5669 5683 5689 5693 5701 5711 5717 5737 5741 5743 5749 5779 5783 5791 5801 5807 5813 5821 5827 5839 5843 5849 5851 5857 5861 5867 5869 5879 5881 5897 5903 5923 5927 5939 5953 5981 5987 6007 6011 6029 6037 6043 6047 6053 6067 6073 6079 6089 6091 6101 6113 6121 6131 6133 6143 6151 6163 6173 6197 6199 6203 6211 6217 6221 6229 6247 6257 6263 6269 6271 6277 6287 6299 6301 6311 6317 6323 6329 6337 6343 6353 6359 6361 6367 6373 6379 6389 6397 6421 6427 6449 6451 6469 6473 6481 6491 6521 6529 6547 6551 6553 6563 6569 6571 6577 6581 6599 6607 6619 6637 6653 6659 6661 6673 6679 6689 6691 6701 6703 6709 6719 6733 6737 6761 6763 6779 6781 6791 6793 6803 6823 6827 6829 6833 6841 6857 6863 6869 6871 6883 6899 6907 6911 6917 6947 6949 6959 6961 6967 6971 6977 6983 6991 6997 7001 7013 7019 7027 7039 7043 7057 7069 7079 7103 7109 7121 7127 7129 7151 7159 7177 7187 7193 7207 7211 7213 7219 7229 7237 7243 7247 7253 7283 7297 7307 7309 7321 7331 7333 7349 7351 7369 7393 7411 7417 7433 7451 7457 7459 7477 7481 7487 7489 7499 7507 7517 7523 7529 7537 7541 7547 7549 7559 7561 7573 7577 7583 7589 7591 7603 7607 7621 7639 7643 7649 7669 7673 7681 7687 7691 7699 7703 7717 7723 7727 7741 7753 7757 7759 7789 7793 7817 7823 7829 7841 7853 7867 7873 7877 7879 7883 7901 7907 7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081 8087 8089 8093 8101 8111 8117 8123 8147 8161 8167 8171 8179 8191 8209 8219 8221 8231 8233 8237 8243 8263 8269 8273 8287 8291 8293 8297 8311 8317 8329 8353 8363 8369 8377 8387 8389 8419 8423 8429 8431 8443 8447 8461 8467 8501 8513 8521 8527 8537 8539 8543 8563 8573 8581 8597 8599 8609 8623 8627 8629 8641 8647 8663 8669 8677 8681 8689 8693 8699 8707 8713 8719 8731 8737 8741 8747 8753 8761 8779 8783 8803 8807 8819 8821 8831 8837 8839 8849 8861 8863 8867 8887 8893 8923 8929 8933 8941 8951 8963 8969 8971 8999 9001 9007 9011 9013 9029 9041 9043 9049 9059 9067 9091 9103 9109 9127 9133 9137 9151 9157 9161 9173 9181 9187 9199 9203 9209 9221 9227 9239 9241 9257 9277 9281 9283 9293 9311 9319 9323 9337 9341 9343 9349 9371 9377 9391 9397 9403 9413 9419 9421 9431 9433 9437 9439 9461 9463 9467 9473 9479 9491 9497 9511 9521 9533 9539 9547 9551 9587 9601 9613 9619 9623 9629 9631 9643 9649 9661 9677 9679 9689 9697 9719 9721 9733 9739 9743 9749 9767 9769 9781 9787 9791 9803 9811 9817 9829 9833 9839 9851 9857 9859 9871 9883 9887 9901 9907 9923 9929 9931 9941 9949 9967 9973 10007 10009 10037 10039 10061 10067 10069 10079 10091 10093 10099 10103 10111 10133 10139 10141 10151 10159 10163 10169 10177 10181 10193 10211 10223 10243 10247 10253 10259 10267 10271 10273 10289 10301 10303 10313 10321 10331 10333 10337 10343 10357 10369 10391 10399 10427 10429 10433 10453 10457 10459 10463 10477 10487 10499 10501 10513 10529 10531 10559 10567 10589 10597 10601 10607 10613 10627 10631 10639 10651 10657 10663 10667 10687 10691 10709 10711 10723 10729 10733 10739 10753 10771 10781 10789 10799 10831 10837 10847 10853 10859 10861 10867 10883 10889 10891 10903 10909 10937 10939 10949 10957 10973 10979 10987 10993 11003 11027 11047 11057 11059 11069 11071 11083 11087 11093 11113 11117 11119 11131 11149 11159 11161 11171 11173 11177 11197 11213 11239 11243 11251 11257 11261 11273 11279 11287 11299 11311 11317 11321 11329 11351 11353 11369 11383 11393 11399 11411 11423 11437 11443 11447 11467 11471 11483 11489 11491 11497 11503 11519 11527 11549 11551 11579 11587 11593 11597 11617 11621 11633 11657 11677 11681 11689 11699 11701 11717 11719 11731 11743 11777 11779 11783 11789 11801 11807 11813 11821 11827 11831 11833 11839 11863 11867 11887 11897 11903 11909 11923 11927 11933 11939 11941 11953 11959 11969 11971 11981 11987 12007 12011 12037 12041 12043 12049 12071 12073 12097 12101 12107 12109 12113 12119 12143 12149 12157 12161 12163 12197 12203 12211 12227 12239 12241 12251 12253 12263 12269 12277 12281 12289 12301 12323 12329 12343 12347 12373 12377 12379 12391 12401 12409 12413 12421 12433 12437 12451 12457 12473 12479 12487 12491 12497 12503 12511 12517 12527 12539 12541 12547 12553 12569 12577 12583 12589 12601 12611 12613 12619 12637 12641 12647 12653 12659 12671 12689 12697 12703 12713 12721 12739 12743 12757 12763 12781 12791 12799 12809 12821 12823 12829 12841 12853 12889 12893 12899 12907 12911 12917 12919 12923 12941 12953 12959 12967 12973 12979 12983 13001 13003 13007 13009 13033 13037 13043 13049 13063 13093 13099 13103 13109 13121 13127 13147 13151 13159 13163 13171 13177 13183 13187 13217 13219 13229 13241 13249 13259 13267 13291 13297 13309 13313 13327 13331 13337 13339 13367 13381 13397 13399 13411 13417 13421 13441 13451 13457 13463 13469 13477 13487 13499 13513 13523 13537 13553 13567 13577 13591 13597 13613 13619 13627 13633 13649 13669 13679 13681 13687 13691 13693 13697 13709 13711 13721 13723 13729 13751 13757 13759 13763 13781 13789 13799 13807 13829 13831 13841 13859 13873 13877 13879 13883 13901 13903 13907 13913 13921 13931 13933 13963 13967 13997 13999 14009 14011 14029 14033 14051 14057 14071 14081 14083 14087 14107 14143 14149 14153 14159 14173 14177 14197 14207 14221 14243 14249 14251 14281 14293 14303 14321 14323 14327 14341 14347 14369 14387 14389 14401 14407 14411 14419 14423 14431 14437 14447 14449 14461 14479 14489 14503 14519 14533 14537 14543 14549 14551 14557 14561 14563 14591 14593 14621 14627 14629 14633 14639 14653 14657 14669 14683 14699 14713 14717 14723 14731 14737 14741 14747 14753 14759 14767 14771 14779 14783 14797 14813 14821 14827 14831 14843 14851 14867 14869 14879 14887 14891 14897 14923 14929 14939 14947 14951 14957 14969 14983 15013 15017 15031 15053 15061 15073 15077 15083 15091 15101 15107 15121 15131 15137 15139 15149 15161 15173 15187 15193 15199 15217 15227 15233 15241 15259 15263 15269 15271 15277 15287 15289 15299 15307 15313 15319 15329 15331 15349 15359 15361 15373 15377 15383 15391 15401 15413 15427 15439 15443 15451 15461 15467 15473 15493 15497 15511 15527 15541 15551 15559 15569 15581 15583 15601 15607 15619 15629 15641 15643 15647 15649 15661 15667 15671 15679 15683 15727 15731 15733 15737 15739 15749 15761 15767 15773 15787 15791 15797 15803 15809 15817 15823 15859 15877 15881 15887 15889 15901 15907 15913 15919 15923 15937 15959 15971 15973 15991 16001 16007 16033 16057 16061 16063 16067 16069 16073 16087 16091 16097 16103 16111 16127 16139 16141 16183 16187 16189 16193 16217 16223 16229 16231 16249 16253 16267 16273 16301 16319 16333 16339 16349 16361 16363 16369 16381 16411 16417 16421 16427 16433 16447 16451 16453 16477 16481 16487 16493 16519 16529 16547 16553 16561 16567 16573 16603 16607 16619 16631 16633 16649 16651 16657 16661 16673 16691 16693 16699 16703 16729 16741 16747 16759 16763 16787 16811 16823 16829 16831 16843 16871 16879 16883 16889 16901 16903 16921 16927 16931 16937 16943 16963 16979 16981 16987 16993 17011 17021 17027 17029 17033 17041 17047 17053 17077 17093 17099 17107 17117 17123 17137 17159 17167 17183 17189 17191 17203 17207 17209 17231 17239 17257 17291 17293 17299 17317 17321 17327 17333 17341 17351 17359 17377 17383 17387 17389 17393 17401 17417 17419 17431 17443 17449 17467 17471 17477 17483 17489 17491 17497 17509 17519 17539 17551 17569 17573 17579 17581 17597 17599 17609 17623 17627 17657 17659 17669 17681 17683 17707 17713 17729 17737 17747 17749 17761 17783 17789 17791 17807 17827 17837 17839 17851 17863 17881 17891 17903 17909 17911 17921 17923 17929 17939 17957 17959 17971 17977 17981 17987 17989 18013 18041 18043 18047 18049 18059 18061 18077 18089 18097 18119 18121 18127 18131 18133 18143 18149 18169 18181 18191 18199 18211 18217 18223 18229 18233 18251 18253 18257 18269 18287 18289 18301 18307 18311 18313 18329 18341 18353 18367 18371 18379 18397 18401 18413 18427 18433 18439 18443 18451 18457 18461 18481 18493 18503 18517 18521 18523 18539 18541 18553 18583 18587 18593 18617 18637 18661 18671 18679 18691 18701 18713 18719 18731 18743 18749 18757 18773 18787 18793 18797 18803 18839 18859 18869 18899 18911 18913 18917 18919 18947 18959 18973 18979 19001 19009 19013 19031 19037 19051 19069 19073 19079 19081 19087 19121 19139 19141 19157 19163 19181 19183 19207 19211 19213 19219 19231 19237 19249 19259 19267 19273 19289 19301 19309 19319 19333 19373 19379 19381 19387 19391 19403 19417 19421 19423 19427 19429 19433 19441 19447 19457 19463 19469 19471 19477 19483 19489 19501 19507 19531 19541 19543 19553 19559 19571 19577 19583 19597 19603 19609 19661 19681 19687 19697 19699 19709 19717 19727 19739 19751 19753 19759 19763 19777 19793 19801 19813 19819 19841 19843 19853 19861 19867 19889 19891 19913 19919 19927 19937 19949 19961 19963 19973 19979 19991 19993 19997 20011 20021 20023 20029 20047 20051 20063 20071 20089 20101 20107 20113 20117 20123 20129 20143 20147 20149 20161 20173 20177 20183 20201 20219 20231 20233 20249 20261 20269 20287 20297 20323 20327 20333 20341 20347 20353 20357 20359 20369 20389 20393 20399 20407 20411 20431 20441 20443 20477 20479 20483 20507 20509 20521 20533 20543 20549 20551 20563 20593 20599 20611 20627 20639 20641 20663 20681 20693 20707 20717 20719 20731 20743 20747 20749 20753 20759 20771 20773 20789 20807 20809 20849 20857 20873 20879 20887 20897 20899 20903 20921 20929 20939 20947 20959 20963 20981 20983 21001 21011 21013 21017 21019 21023 21031 21059 21061 21067 21089 21101 21107 21121 21139 21143 21149 21157 21163 21169 21179 21187 21191 21193 21211 21221 21227 21247 21269 21277 21283 21313 21317 21319 21323 21341 21347 21377 21379 21383 21391 21397 21401 21407 21419 21433 21467 21481 21487 21491 21493 21499 21503 21517 21521 21523 21529 21557 21559 21563 21569 21577 21587 21589 21599 21601 21611 21613 21617 21647 21649 21661 21673 21683 21701 21713 21727 21737 21739 21751 21757 21767 21773 21787 21799 21803 21817 21821 21839 21841 21851 21859 21863 21871 21881 21893 21911 21929 21937 21943 21961 21977 21991 21997 22003 22013 22027 22031 22037 22039 22051 22063 22067 22073 22079 22091 22093 22109 22111 22123 22129 22133 22147 22153 22157 22159 22171 22189 22193 22229 22247 22259 22271 22273 22277 22279 22283 22291 22303 22307 22343 22349 22367 22369 22381 22391 22397 22409 22433 22441 22447 22453 22469 22481 22483 22501 22511 22531 22541 22543 22549 22567 22571 22573 22613 22619 22621 22637 22639 22643 22651 22669 22679 22691 22697 22699 22709 22717 22721 22727 22739 22741 22751 22769 22777 22783 22787 22807 22811 22817 22853 22859 22861 22871 22877 22901 22907 22921 22937 22943 22961 22963 22973 22993 23003 23011 23017 23021 23027 23029 23039 23041 23053 23057 23059 23063 23071 23081 23087 23099 23117 23131 23143 23159 23167 23173 23189 23197 23201 23203 23209 23227 23251 23269 23279 23291 23293 23297 23311 23321 23327 23333 23339 23357 23369 23371 23399 23417 23431 23447 23459 23473 23497 23509 23531 23537 23539 23549 23557 23561 23563 23567 23581 23593 23599 23603 23609 23623 23627 23629 23633 23663 23669 23671 23677 23687 23689 23719 23741 23743 23747 23753 23761 23767 23773 23789 23801 23813 23819 23827 23831 23833 23857 23869 23873 23879 23887 23893 23899 23909 23911 23917 23929 23957 23971 23977 23981 23993 24001 24007 24019 24023 24029 24043 24049 24061 24071 24077 24083 24091 24097 24103 24107 24109 24113 24121 24133 24137 24151 24169 24179 24181 24197 24203 24223 24229 24239 24247 24251 24281 24317 24329 24337 24359 24371 24373 24379 24391 24407 24413 24419 24421 24439 24443 24469 24473 24481 24499 24509 24517 24527 24533 24547 24551 24571 24593 24611 24623 24631 24659 24671 24677 24683 24691 24697 24709 24733 24749 24763 24767 24781 24793 24799 24809 24821 24841 24847 24851 24859 24877 24889 24907 24917 24919 24923 24943 24953 24967 24971 24977 24979 24989 25013 25031 25033 25037 25057 25073 25087 25097 25111 25117 25121 25127 25147 25153 25163 25169 25171 25183 25189 25219 25229 25237 25243 25247 25253 25261 25301 25303 25307 25309 25321 25339 25343 25349 25357 25367 25373 25391 25409 25411 25423 25439 25447 25453 25457 25463 25469 25471 25523 25537 25541 25561 25577 25579 25583 25589 25601 25603 25609 25621 25633 25639 25643 25657 25667 25673 25679 25693 25703 25717 25733 25741 25747 25759 25763 25771 25793 25799 25801 25819 25841 25847 25849 25867 25873 25889 25903 25913 25919 25931 25933 25939 25943 25951 25969 25981 25997 25999 26003 26017 26021 26029 26041 26053 26083 26099 26107 26111 26113 26119 26141 26153 26161 26171 26177 26183 26189 26203 26209 26227 26237 26249 26251 26261 26263 26267 26293 26297 26309 26317 26321 26339 26347 26357 26371 26387 26393 26399 26407 26417 26423 26431 26437 26449 26459 26479 26489 26497 26501 26513 26539 26557 26561 26573 26591 26597 26627 26633 26641 26647 26669 26681 26683 26687 26693 26699 26701 26711 26713 26717 26723 26729 26731 26737 26759 26777 26783 26801 26813 26821 26833 26839 26849 26861 26863 26879 26881 26891 26893 26903 26921 26927 26947 26951 26953 26959 26981 26987 26993 27011 27017 27031 27043 27059 27061 27067 27073 27077 27091 27103 27107 27109 27127 27143 27179 27191 27197 27211 27239 27241 27253 27259 27271 27277 27281 27283 27299 27329 27337 27361 27367 27397 27407 27409 27427 27431 27437 27449 27457 27479 27481 27487 27509 27527 27529 27539 27541 27551 27581 27583 27611 27617 27631 27647 27653 27673 27689 27691 27697 27701 27733 27737 27739 27743 27749 27751 27763 27767 27773 27779 27791 27793 27799 27803 27809 27817 27823 27827 27847 27851 27883 27893 27901 27917 27919 27941 27943 27947 27953 27961 27967 27983 27997 28001 28019 28027 28031 28051 28057 28069 28081 28087 28097 28099 28109 28111 28123 28151 28163 28181 28183 28201 28211 28219 28229 28277 28279 28283 28289 28297 28307 28309 28319 28349 28351 28387 28393 28403 28409 28411 28429 28433 28439 28447 28463 28477 28493 28499 28513 28517 28537 28541 28547 28549 28559 28571 28573 28579 28591 28597 28603 28607 28619 28621 28627 28631 28643 28649 28657 28661 28663 28669 28687 28697 28703 28711 28723 28729 28751 28753 28759 28771 28789 28793 28807 28813 28817 28837 28843 28859 28867 28871 28879 28901 28909 28921 28927 28933 28949 28961 28979 29009 29017 29021 29023 29027 29033 29059 29063 29077 29101 29123 29129 29131 29137 29147 29153 29167 29173 29179 29191 29201 29207 29209 29221 29231 29243 29251 29269 29287 29297 29303 29311 29327 29333 29339 29347 29363 29383 29387 29389 29399 29401 29411 29423 29429 29437 29443 29453 29473 29483 29501 29527 29531 29537 29567 29569 29573 29581 29587 29599 29611 29629 29633 29641 29663 29669 29671 29683 29717 29723 29741 29753 29759 29761 29789 29803 29819 29833 29837 29851 29863 29867 29873 29879 29881 29917 29921 29927 29947 29959 29983 29989 30011 30013 30029 30047 30059 30071 30089 30091 30097 30103 30109 30113 30119 30133 30137 30139 30161 30169 30181 30187 30197 30203 30211 30223 30241 30253 30259 30269 30271 30293 30307 30313 30319 30323 30341 30347 30367 30389 30391 30403 30427 30431 30449 30467 30469 30491 30493 30497 30509 30517 30529 30539 30553 30557 30559 30577 30593 30631 30637 30643 30649 30661 30671 30677 30689 30697 30703 30707 30713 30727 30757 30763 30773 30781 30803 30809 30817 30829 30839 30841 30851 30853 30859 30869 30871 30881 30893 30911 30931 30937 30941 30949 30971 30977 30983 31013 31019 31033 31039 31051 31063 31069 31079 31081 31091 31121 31123 31139 31147 31151 31153 31159 31177 31181 31183 31189 31193 31219 31223 31231 31237 31247 31249 31253 31259 31267 31271 31277 31307 31319 31321 31327 31333 31337 31357 31379 31387 31391 31393 31397 31469 31477 31481 31489 31511 31513 31517 31531 31541 31543 31547 31567 31573 31583 31601 31607 31627 31643 31649 31657 31663 31667 31687 31699 31721 31723 31727 31729 31741 31751 31769 31771 31793 31799 31817 31847 31849 31859 31873 31883 31891 31907 31957 31963 31973 31981 31991 32003 32009 32027 32029 32051 32057 32059 32063 32069 32077 32083 32089 32099 32117 32119 32141 32143 32159 32173 32183 32189 32191 32203 32213 32233 32237 32251 32257 32261 32297 32299 32303 32309 32321 32323 32327 32341 32353 32359 32363 32369 32371 32377 32381 32401 32411 32413 32423 32429 32441 32443 32467 32479 32491 32497 32503 32507 32531 32533 32537 32561 32563 32569 32573 32579 32587 32603 32609 32611 32621 32633 32647 32653 32687 32693 32707 32713 32717 32719 32749 32771 32779 32783 32789 32797 32801 32803 32831 32833 32839 32843 32869 32887 32909 32911 32917 32933 32939 32941 32957 32969 32971 32983 32987 32993 32999 33013 33023 33029 33037 33049 33053 33071 33073 33083 33091 33107 33113 33119 33149 33151 33161 33179 33181 33191 33199 33203 33211 33223 33247 33287 33289 33301 33311 33317 33329 33331 33343 33347 33349 33353 33359 33377 33391 33403 33409 33413 33427 33457 33461 33469 33479 33487 33493 33503 33521 33529 33533 33547 33563 33569 33577 33581 33587 33589 33599 33601 33613 33617 33619 33623 33629 33637 33641 33647 33679 33703 33713 33721 33739 33749 33751 33757 33767 33769 33773 33791 33797 33809 33811 33827 33829 33851 33857 33863 33871 33889 33893 33911 33923 33931 33937 33941 33961 33967 33997 34019 34031 34033 34039 34057 34061 34123 34127 34129 34141 34147 34157 34159 34171 34183 34211 34213 34217 34231 34253 34259 34261 34267 34273 34283 34297 34301 34303 34313 34319 34327 34337 34351 34361 34367 34369 34381 34403 34421 34429 34439 34457 34469 34471 34483 34487 34499 34501 34511 34513 34519 34537 34543 34549 34583 34589 34591 34603 34607 34613 34631 34649 34651 34667 34673 34679 34687 34693 34703 34721 34729 34739 34747 34757 34759 34763 34781 34807 34819 34841 34843 34847 34849 34871 34877 34883 34897 34913 34919 34939 34949 34961 34963 34981 35023 35027 35051 35053 35059 35069 35081 35083 35089 35099 35107 35111 35117 35129 35141 35149 35153 35159 35171 35201 35221 35227 35251 35257 35267 35279 35281 35291 35311 35317 35323 35327 35339 35353 35363 35381 35393 35401 35407 35419 35423 35437 35447 35449 35461 35491 35507 35509 35521 35527 35531 35533 35537 35543 35569 35573 35591 35593 35597 35603 35617 35671 35677 35729 35731 35747 35753 35759 35771 35797 35801 35803 35809 35831 35837 35839 35851 35863 35869 35879 35897 35899 35911 35923 35933 35951 35963 35969 35977 35983 35993 35999 36007 36011 36013 36017 36037 36061 36067 36073 36083 36097 36107 36109 36131 36137 36151 36161 36187 36191 36209 36217 36229 36241 36251 36263 36269 36277 36293 36299 36307 36313 36319 36341 36343 36353 36373 36383 36389 36433 36451 36457 36467 36469 36473 36479 36493 36497 36523 36527 36529 36541 36551 36559 36563 36571 36583 36587 36599 36607 36629 36637 36643 36653 36671 36677 36683 36691 36697 36709 36713 36721 36739 36749 36761 36767 36779 36781 36787 36791 36793 36809 36821 36833 36847 36857 36871 36877 36887 36899 36901 36913 36919 36923 36929 36931 36943 36947 36973 36979 36997 37003 37013 37019 37021 37039 37049 37057 37061 37087 37097 37117 37123 37139 37159 37171 37181 37189 37199 37201 37217 37223 37243 37253 37273 37277 37307 37309 37313 37321 37337 37339 37357 37361 37363 37369 37379 37397 37409 37423 37441 37447 37463 37483 37489 37493 37501 37507 37511 37517 37529 37537 37547 37549 37561 37567 37571 37573 37579 37589 37591 37607 37619 37633 37643 37649 37657 37663 37691 37693 37699 37717 37747 37781 37783 37799 37811 37813 37831 37847 37853 37861 37871 37879 37889 37897 37907 37951 37957 37963 37967 37987 37991 37993 37997 38011 38039 38047 38053 38069 38083 38113 38119 38149 38153 38167 38177 38183 38189 38197 38201 38219 38231 38237 38239 38261 38273 38281 38287 38299 38303 38317 38321 38327 38329 38333 38351 38371 38377 38393 38431 38447 38449 38453 38459 38461 38501 38543 38557 38561 38567 38569 38593 38603 38609 38611 38629 38639 38651 38653 38669 38671 38677 38693 38699 38707 38711 38713 38723 38729 38737 38747 38749 38767 38783 38791 38803 38821 38833 38839 38851 38861 38867 38873 38891 38903 38917 38921 38923 38933 38953 38959 38971 38977 38993 39019 39023 39041 39043 39047 39079 39089 39097 39103 39107 39113 39119 39133 39139 39157 39161 39163 39181 39191 39199 39209 39217 39227 39229 39233 39239 39241 39251 39293 39301 39313 39317 39323 39341 39343 39359 39367 39371 39373 39383 39397 39409 39419 39439 39443 39451 39461 39499 39503 39509 39511 39521 39541 39551 39563 39569 39581 39607 39619 39623 39631 39659 39667 39671 39679 39703 39709 39719 39727 39733 39749 39761 39769 39779 39791 39799 39821 39827 39829 39839 39841 39847 39857 39863 39869 39877 39883 39887 39901 39929 39937 39953 39971 39979 39983 39989 40009 40013 40031 40037 40039 40063 40087 40093 40099 40111 40123 40127 40129 40151 40153 40163 40169 40177 40189 40193 40213 40231 40237 40241 40253 40277 40283 40289 40343 40351 40357 40361 40387 40423 40427 40429 40433 40459 40471 40483 40487 40493 40499 40507 40519 40529 40531 40543 40559 40577 40583 40591 40597 40609 40627 40637 40639 40693 40697 40699 40709 40739 40751 40759 40763 40771 40787 40801 40813 40819 40823 40829 40841 40847 40849 40853 40867 40879 40883 40897 40903 40927 40933 40939 40949 40961 40973 40993 41011 41017 41023 41039 41047 41051 41057 41077 41081 41113 41117 41131 41141 41143 41149 41161 41177 41179 41183 41189 41201 41203 41213 41221 41227 41231 41233 41243 41257 41263 41269 41281 41299 41333 41341 41351 41357 41381 41387 41389 41399 41411 41413 41443 41453 41467 41479 41491 41507 41513 41519 41521 41539 41543 41549 41579 41593 41597 41603 41609 41611 41617 41621 41627 41641 41647 41651 41659 41669 41681 41687 41719 41729 41737 41759 41761 41771 41777 41801 41809 41813 41843 41849 41851 41863 41879 41887 41893 41897 41903 41911 41927 41941 41947 41953 41957 41959 41969 41981 41983 41999 42013 42017 42019 42023 42043 42061 42071 42073 42083 42089 42101 42131 42139 42157 42169 42179 42181 42187 42193 42197 42209 42221 42223 42227 42239 42257 42281 42283 42293 42299 42307 42323 42331 42337 42349 42359 42373 42379 42391 42397 42403 42407 42409 42433 42437 42443 42451 42457 42461 42463 42467 42473 42487 42491 42499 42509 42533 42557 42569 42571 42577 42589 42611 42641 42643 42649 42667 42677 42683 42689 42697 42701 42703 42709 42719 42727 42737 42743 42751 42767 42773 42787 42793 42797 42821 42829 42839 42841 42853 42859 42863 42899 42901 42923 42929 42937 42943 42953 42961 42967 42979 42989 43003 43013 43019 43037 43049 43051 43063 43067 43093 43103 43117 43133 43151 43159 43177 43189 43201 43207 43223 43237 43261 43271 43283 43291 43313 43319 43321 43331 43391 43397 43399 43403 43411 43427 43441 43451 43457 43481 43487 43499 43517 43541 43543 43573 43577 43579 43591 43597 43607 43609 43613 43627 43633 43649 43651 43661 43669 43691 43711 43717 43721 43753 43759 43777 43781 43783 43787 43789 43793 43801 43853 43867 43889 43891 43913 43933 43943 43951 43961 43963 43969 43973 43987 43991 43997 44017 44021 44027 44029 44041 44053 44059 44071 44087 44089 44101 44111 44119 44123 44129 44131 44159 44171 44179 44189 44201 44203 44207 44221 44249 44257 44263 44267 44269 44273 44279 44281 44293 44351 44357 44371 44381 44383 44389 44417 44449 44453 44483 44491 44497 44501 44507 44519 44531 44533 44537 44543 44549 44563 44579 44587 44617 44621 44623 44633 44641 44647 44651 44657 44683 44687 44699 44701 44711 44729 44741 44753 44771 44773 44777 44789 44797 44809 44819 44839 44843 44851 44867 44879 44887 44893 44909 44917 44927 44939 44953 44959 44963 44971 44983 44987 45007 45013 45053 45061 45077 45083 45119 45121 45127 45131 45137 45139 45161 45179 45181 45191 45197 45233 45247 45259 45263 45281 45289 45293 45307 45317 45319 45329 45337 45341 45343 45361 45377 45389 45403 45413 45427 45433 45439 45481 45491 45497 45503 45523 45533 45541 45553 45557 45569 45587 45589 45599 45613 45631 45641 45659 45667 45673 45677 45691 45697 45707 45737 45751 45757 45763 45767 45779 45817 45821 45823 45827 45833 45841 45853 45863 45869 45887 45893 45943 45949 45953 45959 45971 45979 45989 46021 46027 46049 46051 46061 46073 46091 46093 46099 46103 46133 46141 46147 46153 46171 46181 46183 46187 46199 46219 46229 46237 46261 46271 46273 46279 46301 46307 46309 46327 46337 46349 46351 46381 46399 46411 46439 46441 46447 46451 46457 46471 46477 46489 46499 46507 46511 46523 46549 46559 46567 46573 46589 46591 46601 46619 46633 46639 46643 46649 46663 46679 46681 46687 46691 46703 46723 46727 46747 46751 46757 46769 46771 46807 46811 46817 46819 46829 46831 46853 46861 46867 46877 46889 46901 46919 46933 46957 46993 46997 47017 47041 47051 47057 47059 47087 47093 47111 47119 47123 47129 47137 47143 47147 47149 47161 47189 47207 47221 47237 47251 47269 47279 47287 47293 47297 47303 47309 47317 47339 47351 47353 47363 47381 47387 47389 47407 47417 47419 47431 47441 47459 47491 47497 47501 47507 47513 47521 47527 47533 47543 47563 47569 47581 47591 47599 47609 47623 47629 47639 47653 47657 47659 47681 47699 47701 47711 47713 47717 47737 47741 47743 47777 47779 47791 47797 47807 47809 47819 47837 47843 47857 47869 47881 47903 47911 47917 47933 47939 47947 47951 47963 47969 47977 47981 48017 48023 48029 48049 48073 48079 48091 48109 48119 48121 48131 48157 48163 48179 48187 48193 48197 48221 48239 48247 48259 48271 48281 48299 48311 48313 48337 48341 48353 48371 48383 48397 48407 48409 48413 48437 48449 48463 48473 48479 48481 48487 48491 48497 48523 48527 48533 48539 48541 48563 48571 48589 48593 48611 48619 48623 48647 48649 48661 48673 48677 48679 48731 48733 48751 48757 48761 48767 48779 48781 48787 48799 48809 48817 48821 48823 48847 48857 48859 48869 48871 48883 48889 48907 48947 48953 48973 48989 48991 49003 49009 49019 49031 49033 49037 49043 49057 49069 49081 49103 49109 49117 49121 49123 49139 49157 49169 49171 49177 49193 49199 49201 49207 49211 49223 49253 49261 49277 49279 49297 49307 49331 49333 49339 49363 49367 49369 49391 49393 49409 49411 49417 49429 49433 49451 49459 49463 49477 49481 49499 49523 49529 49531 49537 49547 49549 49559 49597 49603 49613 49627 49633 49639 49663 49667 49669 49681 49697 49711 49727 49739 49741 49747 49757 49783 49787 49789 49801 49807 49811 49823 49831 49843 49853 49871 49877 49891 49919 49921 49927 49937 49939 49943 49957 49991 49993 49999 diff --git a/test/Results/soli.fast.out b/test/Results/soli.fast.out new file mode 100644 index 0000000..b94045c --- /dev/null +++ b/test/Results/soli.fast.out @@ -0,0 +1,50 @@ +500 +1000 +1500 +2000 +2500 +3000 +3500 +4000 +4500 +5000 +5500 +6000 +6500 +7000 +7500 +8000 +8500 +9000 +9500 +10000 +10500 +11000 +11500 +12000 +12500 +13000 +13500 +14000 +14500 +15000 +15500 +16000 +16500 +17000 +17500 +18000 +18500 +19000 +19500 +20000 + +......... +... ... +... ... +. . +. $ . +. . +... ... +... ... +......... diff --git a/test/Results/soli.out b/test/Results/soli.out new file mode 100644 index 0000000..b94045c --- /dev/null +++ b/test/Results/soli.out @@ -0,0 +1,50 @@ +500 +1000 +1500 +2000 +2500 +3000 +3500 +4000 +4500 +5000 +5500 +6000 +6500 +7000 +7500 +8000 +8500 +9000 +9500 +10000 +10500 +11000 +11500 +12000 +12500 +13000 +13500 +14000 +14500 +15000 +15500 +16000 +16500 +17000 +17500 +18000 +18500 +19000 +19500 +20000 + +......... +... ... +... ... +. . +. $ . +. . +... ... +... ... +......... diff --git a/test/Results/sorts.out b/test/Results/sorts.out new file mode 100644 index 0000000..fa0cc04 --- /dev/null +++ b/test/Results/sorts.out @@ -0,0 +1,198 @@ +Command line arguments are: +Testing List.sort... + List.sort with constant ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with reverse-sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with random ints (many dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with random ints (few dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with records (str) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with records (int[1]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with records (int[10]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with records (int[100]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.sort with records (int[1000]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. +Testing List.stable_sort... + List.stable_sort with constant ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with reverse-sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with random ints (many dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with random ints (few dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (str) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[1]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[10]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[100]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[1000]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[1]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[10]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[100]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + List.stable_sort with records (int[1000]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. +Testing Array.sort... + Array.sort with constant ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with reverse-sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with random ints (many dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with random ints (few dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with records (str) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with records (int[1]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with records (int[10]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with records (int[100]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.sort with records (int[1000]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. +Testing Array.stable_sort... + Array.stable_sort with constant ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with reverse-sorted ints + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with random ints (many dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with random ints (few dups) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (str) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[1]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[10]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[100]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[1000]) + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[1]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[10]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[100]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. + Array.stable_sort with records (int[1000]) [stable] + 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. + 12. 13. 28. 100. 127. 128. 129. 191. 192. 193. 506. 1000. + 1023. 1024. 1025. 1535. 1536. 1537. 2323. 4000. 4094. 4096. 4098. 5123. +Number of tests failed: 0 diff --git a/test/Results/takc.out b/test/Results/takc.out new file mode 100644 index 0000000..bfed819 --- /dev/null +++ b/test/Results/takc.out @@ -0,0 +1 @@ +14000 diff --git a/test/Results/taku.out b/test/Results/taku.out new file mode 100644 index 0000000..bfed819 --- /dev/null +++ b/test/Results/taku.out @@ -0,0 +1 @@ +14000 diff --git a/test/Results/weaktest.out b/test/Results/weaktest.out new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/test/Results/weaktest.out @@ -0,0 +1 @@ +pass diff --git a/test/alloc.ml b/test/alloc.ml new file mode 100644 index 0000000..ed533af --- /dev/null +++ b/test/alloc.ml @@ -0,0 +1,51 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Para, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: alloc.ml,v 1.2 1999-11-17 18:58:33 xleroy Exp $ *) + +(* Random allocation test *) + +(* + Allocate arrays of strings, of random sizes in [0..1000[, and put them + into an array of 32768. Replace a randomly-selected array with a new + random-length array. Reiterate ad infinitum. +*) + +let l = 32768;; +let m = 1000;; + +let ar = Array.create l "";; + +Random.init 1234;; + +let compact_flag = ref false;; + +let main () = + while true do + for i = 1 to 100000 do + ar.(Random.int l) <- String.create (Random.int m); + done; + if !compact_flag then Gc.compact () else Gc.full_major (); + print_newline (); + Gc.print_stat stdout; + flush stdout; + done +;; + +let argspecs = [ + "-c", Arg.Set compact_flag, "do heap compactions"; +];; + +Arg.parse argspecs (fun _ -> ()) "Usage: alloc [-c]";; + +main ();; + diff --git a/test/almabench.ml b/test/almabench.ml new file mode 100644 index 0000000..f1dd10c --- /dev/null +++ b/test/almabench.ml @@ -0,0 +1,324 @@ +(* + * ALMABENCH 1.0.1 + * Objective Caml version + * + * A number-crunching benchmark designed for cross-language and vendor + * comparisons. + * + * Written by Shawn Wagner, from Scott Robert Ladd's versions for + * C++ and java. + * + * No rights reserved. This is public domain software, for use by anyone. + * + * This program calculates the daily ephemeris (at noon) for the years + * 2000-2099 using an algorithm developed by J.L. Simon, P. Bretagnon, J. + * Chapront, M. Chapront-Touze, G. Francou and J. Laskar of the Bureau des + * Longitudes, Paris, France), as detailed in Astronomy & Astrophysics + * 282, 663 (1994) + * + * Note that the code herein is design for the purpose of testing + * computational performance; error handling and other such "niceties" + * is virtually non-existent. + * + * Actual (and oft-updated) benchmark results can be found at: + * http://www.coyotegulch.com + * + * Please do not use this information or algorithm in any way that might + * upset the balance of the universe or otherwise cause planets to impact + * upon one another. + *) + +let pic = 3.14159265358979323846 +and j2000 = 2451545.0 +and jcentury = 36525.0 +and jmillenia = 365250.0 + +let twopi = 2.0 *. pic +and a2r = pic /. 648000.0 +and r2h = 12.0 /. pic +and r2d = 180.0 /. pic +and gaussk = 0.01720209895 + +(* number of days to include in test *) +let test_loops = 5 (* was: 20 *) +and test_length = 36525 + +(* sin and cos of j2000 mean obliquity (iau 1976) *) +and sineps = 0.3977771559319137 +and coseps = 0.9174820620691818 + +and amas = [| 6023600.0; 408523.5; 328900.5; 3098710.0; 1047.355; 3498.5; 22869.0; 19314.0 |] + +(* + * tables giving the mean keplerian elements, limited to t**2 terms: + * a semi-major axis (au) + * dlm mean longitude (degree and arcsecond) + * e eccentricity + * pi longitude of the perihelion (degree and arcsecond) + * dinc inclination (degree and arcsecond) + * omega longitude of the ascending node (degree and arcsecond) + *) +and a = [| + [| 0.3870983098; 0.0; 0.0 |]; + [| 0.7233298200; 0.0; 0.0 |]; + [| 1.0000010178; 0.0; 0.0 |]; + [| 1.5236793419; 3e-10; 0.0 |]; + [| 5.2026032092; 19132e-10; -39e-10 |]; + [| 9.5549091915; -0.0000213896; 444e-10 |]; + [| 19.2184460618; -3716e-10; 979e-10 |]; + [| 30.1103868694; -16635e-10; 686e-10 |] |] + +and dlm = + [| [| 252.25090552; 5381016286.88982; -1.92789 |]; + [| 181.97980085; 2106641364.33548; 0.59381 |]; + [| 100.46645683; 1295977422.83429; -2.04411 |]; + [| 355.43299958; 689050774.93988; 0.94264 |]; + [| 34.35151874; 109256603.77991; -30.60378 |]; + [| 50.07744430; 43996098.55732; 75.61614 |]; + [| 314.05500511; 15424811.93933; -1.75083 |]; + [| 304.34866548; 7865503.20744; 0.21103 |] |] + +and e = + [| [| 0.2056317526; 0.0002040653; -28349e-10 |]; + [| 0.0067719164; -0.0004776521; 98127e-10 |]; + [| 0.0167086342; -0.0004203654; -0.0000126734 |]; + [| 0.0934006477; 0.0009048438; -80641e-10 |]; + [| 0.0484979255; 0.0016322542; -0.0000471366 |]; + [| 0.0555481426; -0.0034664062; -0.0000643639 |]; + [| 0.0463812221; -0.0002729293; 0.0000078913 |]; + [| 0.0094557470; 0.0000603263; 0.0 |] |] + +and pi = + [| [| 77.45611904; 5719.11590; -4.83016 |]; + [| 131.56370300; 175.48640; -498.48184 |]; + [| 102.93734808; 11612.35290; 53.27577 |]; + [| 336.06023395; 15980.45908; -62.32800 |]; + [| 14.33120687; 7758.75163; 259.95938 |]; + [| 93.05723748; 20395.49439; 190.25952 |]; + [| 173.00529106; 3215.56238; -34.09288 |]; + [| 48.12027554; 1050.71912; 27.39717 |] |] +and dinc = + [| [| 7.00498625; -214.25629; 0.28977 |]; + [| 3.39466189; -30.84437; -11.67836 |]; + [| 0.0; 469.97289; -3.35053 |]; + [| 1.84972648; -293.31722; -8.11830 |]; + [| 1.30326698; -71.55890; 11.95297 |]; + [| 2.48887878; 91.85195; -17.66225 |]; + [| 0.77319689; -60.72723; 1.25759 |]; + [| 1.76995259; 8.12333; 0.08135 |] |] + +and omega = + [| [| 48.33089304; -4515.21727; -31.79892 |]; + [| 76.67992019; -10008.48154; -51.32614 |]; + [| 174.87317577; -8679.27034; 15.34191 |]; + [| 49.55809321; -10620.90088; -230.57416 |]; + [| 100.46440702; 6362.03561; 326.52178 |]; + [| 113.66550252; -9240.19942; -66.23743 |]; + [| 74.00595701; 2669.15033; 145.93964 |]; + [| 131.78405702; -221.94322; -0.78728 |] |] + +(* tables for trigonometric terms to be added to the mean elements + of the semi-major axes. *) +and kp = + [| [| 69613.0; 75645.0; 88306.0; 59899.0; 15746.0; 71087.0; 142173.0; 3086.0; 0.0 |]; + [| 21863.0; 32794.0; 26934.0; 10931.0; 26250.0; 43725.0; 53867.0; 28939.0; 0.0 |]; + [| 16002.0; 21863.0; 32004.0; 10931.0; 14529.0; 16368.0; 15318.0; 32794.0; 0.0 |]; + [| 6345.0; 7818.0; 15636.0; 7077.0; 8184.0; 14163.0; 1107.0; 4872.0; 0.0 |]; + [| 1760.0; 1454.0; 1167.0; 880.0; 287.0; 2640.0; 19.0; 2047.0; 1454.0 |]; + [| 574.0; 0.0; 880.0; 287.0; 19.0; 1760.0; 1167.0; 306.0; 574.0 |]; + [| 204.0; 0.0; 177.0; 1265.0; 4.0; 385.0; 200.0; 208.0; 204.0 |]; + [| 0.0; 102.0; 106.0; 4.0; 98.0; 1367.0; 487.0; 204.0; 0.0 |] |] + +and ca = + [| [| 4.0; -13.0; 11.0; -9.0; -9.0; -3.0; -1.0; 4.0; 0.0 |]; + [| -156.0; 59.0; -42.0; 6.0; 19.0; -20.0; -10.0; -12.0; 0.0 |]; + [| 64.0; -152.0; 62.0; -8.0; 32.0; -41.0; 19.0; -11.0; 0.0 |]; + [| 124.0; 621.0; -145.0; 208.0; 54.0; -57.0; 30.0; 15.0; 0.0 |]; + [| -23437.0; -2634.0; 6601.0; 6259.0; -1507.0; -1821.0; 2620.0; -2115.0;-1489.0 |]; + [| 62911.0;-119919.0; 79336.0; 17814.0;-24241.0; 12068.0; 8306.0; -4893.0; 8902.0 |]; + [| 389061.0;-262125.0;-44088.0; 8387.0;-22976.0; -2093.0; -615.0; -9720.0; 6633.0 |]; + [| -412235.0;-157046.0;-31430.0; 37817.0; -9740.0; -13.0; -7449.0; 9644.0; 0.0 |] |] + +and sa = + [| [| -29.0; -1.0; 9.0; 6.0; -6.0; 5.0; 4.0; 0.0; 0.0 |]; + [| -48.0; -125.0; -26.0; -37.0; 18.0; -13.0; -20.0; -2.0; 0.0 |]; + [| -150.0; -46.0; 68.0; 54.0; 14.0; 24.0; -28.0; 22.0; 0.0 |]; + [| -621.0; 532.0; -694.0; -20.0; 192.0; -94.0; 71.0; -73.0; 0.0 |]; + [| -14614.0;-19828.0; -5869.0; 1881.0; -4372.0; -2255.0; 782.0; 930.0; 913.0 |]; + [| 139737.0; 0.0; 24667.0; 51123.0; -5102.0; 7429.0; -4095.0; -1976.0;-9566.0 |]; + [| -138081.0; 0.0; 37205.0;-49039.0;-41901.0;-33872.0;-27037.0;-12474.0;18797.0 |]; + [| 0.0; 28492.0;133236.0; 69654.0; 52322.0;-49577.0;-26430.0; -3593.0; 0.0 |] |] + +(* tables giving the trigonometric terms to be added to the mean elements of + the mean longitudes . *) +and kq = + [| [| 3086.0; 15746.0; 69613.0; 59899.0; 75645.0; 88306.0; 12661.0; 2658.0; 0.0; 0.0 |]; + [| 21863.0; 32794.0; 10931.0; 73.0; 4387.0; 26934.0; 1473.0; 2157.0; 0.0; 0.0 |]; + [| 10.0; 16002.0; 21863.0; 10931.0; 1473.0; 32004.0; 4387.0; 73.0; 0.0; 0.0 |]; + [| 10.0; 6345.0; 7818.0; 1107.0; 15636.0; 7077.0; 8184.0; 532.0; 10.0; 0.0 |]; + [| 19.0; 1760.0; 1454.0; 287.0; 1167.0; 880.0; 574.0; 2640.0; 19.0;1454.0 |]; + [| 19.0; 574.0; 287.0; 306.0; 1760.0; 12.0; 31.0; 38.0; 19.0; 574.0 |]; + [| 4.0; 204.0; 177.0; 8.0; 31.0; 200.0; 1265.0; 102.0; 4.0; 204.0 |]; + [| 4.0; 102.0; 106.0; 8.0; 98.0; 1367.0; 487.0; 204.0; 4.0; 102.0 |] |] + +and cl = + [| [| 21.0; -95.0; -157.0; 41.0; -5.0; 42.0; 23.0; 30.0; 0.0; 0.0 |]; + [| -160.0; -313.0; -235.0; 60.0; -74.0; -76.0; -27.0; 34.0; 0.0; 0.0 |]; + [| -325.0; -322.0; -79.0; 232.0; -52.0; 97.0; 55.0; -41.0; 0.0; 0.0 |]; + [| 2268.0; -979.0; 802.0; 602.0; -668.0; -33.0; 345.0; 201.0; -55.0; 0.0 |]; + [| 7610.0; -4997.0;-7689.0;-5841.0;-2617.0; 1115.0; -748.0; -607.0; 6074.0; 354.0 |]; + [| -18549.0; 30125.0;20012.0; -730.0; 824.0; 23.0; 1289.0; -352.0;-14767.0;-2062.0 |]; + [| -135245.0;-14594.0; 4197.0;-4030.0;-5630.0;-2898.0; 2540.0; -306.0; 2939.0; 1986.0 |]; + [| 89948.0; 2103.0; 8963.0; 2695.0; 3682.0; 1648.0; 866.0; -154.0; -1963.0; -283.0 |] |] + +and sl = + [| [| -342.0; 136.0; -23.0; 62.0; 66.0; -52.0; -33.0; 17.0; 0.0; 0.0 |]; + [| 524.0; -149.0; -35.0; 117.0; 151.0; 122.0; -71.0; -62.0; 0.0; 0.0 |]; + [| -105.0; -137.0; 258.0; 35.0; -116.0; -88.0; -112.0; -80.0; 0.0; 0.0 |]; + [| 854.0; -205.0; -936.0; -240.0; 140.0; -341.0; -97.0; -232.0; 536.0; 0.0 |]; + [| -56980.0; 8016.0; 1012.0; 1448.0;-3024.0;-3710.0; 318.0; 503.0; 3767.0; 577.0 |]; + [| 138606.0;-13478.0;-4964.0; 1441.0;-1319.0;-1482.0; 427.0; 1236.0; -9167.0;-1918.0 |]; + [| 71234.0;-41116.0; 5334.0;-4935.0;-1848.0; 66.0; 434.0;-1748.0; 3780.0; -701.0 |]; + [| -47645.0; 11647.0; 2166.0; 3194.0; 679.0; 0.0; -244.0; -419.0; -2531.0; 48.0 |] |] + + +(* Normalize angle into the range -pi <= A < +pi. *) +let anpm a = + let w = mod_float a twopi in + if abs_float w >= pic then begin + if a < 0.0 then + w +. twopi + else + w -. twopi + end else + w + +(* The reference frame is equatorial and is with respect to the + * mean equator and equinox of epoch j2000. *) +let planetpv epoch np pv = + (* time: julian millennia since j2000. *) + let t = ((epoch.(0) -. j2000) +. epoch.(1)) /. jmillenia in + (* compute the mean elements. *) + let da = ref (a.(np).(0) +. (a.(np).(1) +. a.(np).(2) *. t ) *. t) + and dl = ref ((3600.0 *. dlm.(np).(0) +. (dlm.(np).(1) +. dlm.(np).(2) *. t ) *. t) *. a2r) + and de = e.(np).(0) +. (e.(np).(1) +. e.(np).(2) *. t ) *. t + and dp = anpm ((3600.0 *. pi.(np).(0) +. (pi.(np).(1) +. pi.(np).(2) *. t ) *. t ) *. a2r ) + and di = (3600.0 *. dinc.(np).(0) +. (dinc.(np).(1) +. dinc.(np).(2) *. t ) *. t ) *. a2r + and doh = anpm ((3600.0 *. omega.(np).(0) +. (omega.(np).(1) +. omega.(np).(2) *. t ) *. t ) *. a2r ) + (* apply the trigonometric terms. *) + and dmu = 0.35953620 *. t in + + (* loop invariant *) + let kp = kp.(np) and kq = kq.(np) and ca = ca.(np) and sa = sa.(np) + and cl = cl.(np) and sl = sl.(np) in + for k = 0 to 7 do + let arga = kp.(k) *. dmu + and argl = kq.(k) *. dmu in + da := !da +. (ca.(k) *. cos arga +. sa.(k) *. sin arga) *. 0.0000001; + dl := !dl +. (cl.(k) *. cos argl +. sl.(k) *. sin argl) *. 0.0000001 + done; + begin let arga = kp.(8) *. dmu in + da := !da +. t *. (ca.(8) *. cos arga +. sa.(8) *. sin arga ) *. 0.0000001; + for k = 8 to 9 do + let argl = kq.(k) *. dmu in + dl := !dl +. t *. ( cl.(k) *. cos argl +. sl.(k) *. sin argl ) *. 0.0000001 + done; + end; + + + dl := mod_float !dl twopi; + + (* iterative solution of kepler's equation to get eccentric anomaly. *) + let am = !dl -. dp in + let ae = ref (am +. de *. sin am) + and k = ref 0 in + let dae = ref ((am -. !ae +. de *. sin !ae) /. (1.0 -. de *. cos !ae)) in + ae := !ae +. !dae; + incr k; + while !k < 10 or abs_float !dae >= 1e-12 do + dae := (am -. !ae +. de *. sin !ae) /. (1.0 -. de *. cos !ae); + ae := !ae +. !dae; + incr k + done; + + (* true anomaly. *) + let ae2 = !ae /. 2.0 in + let at = 2.0 *. atan2 (sqrt ((1.0 +. de) /. (1.0 -. de)) *. sin ae2) (cos ae2) + (* distance (au) and speed (radians per day). *) + and r = !da *. (1.0 -. de *. cos !ae) + and v = gaussk *. sqrt ((1.0 +. 1.0 /. amas.(np) ) /. (!da *. !da *. !da)) + and si2 = sin (di /. 2.0) in + let xq = si2 *. cos doh + and xp = si2 *. sin doh + and tl = at +. dp in + let xsw = sin tl + and xcw = cos tl in + let xm2 = 2.0 *. (xp *. xcw -. xq *. xsw ) + and xf = !da /. sqrt (1.0 -. de *. de) + and ci2 = cos (di /. 2.0) in + let xms = (de *. sin dp +. xsw) *. xf + and xmc = (de *. cos dp +. xcw) *. xf + and xpxq2 = 2.0 *. xp *. xq in + + (* position (j2000 ecliptic x,y,z in au). *) + let x = r *. (xcw -. xm2 *. xp) + and y = r *. (xsw +. xm2 *. xq) + and z = r *. (-.xm2 *. ci2) in + + (* rotate to equatorial. *) + pv.(0).(0) <- x; + pv.(0).(1) <- y *. coseps -. z *. sineps; + pv.(0).(2) <- y *. sineps +. z *. coseps; + + (* velocity (j2000 ecliptic xdot,ydot,zdot in au/d). *) + let x = v *. ((-1.0 +. 2.0 *. xp *. xp) *. xms +. xpxq2 *. xmc) + and y = v *. (( 1.0 -. 2.0 *. xq *. xq ) *. xmc -. xpxq2 *. xms) + and z = v *. (2.0 *. ci2 *. (xp *. xms +. xq *. xmc)) in + + (* rotate to equatorial *) + pv.(1).(0) <- x; + pv.(1).(1) <- y *. coseps -. z *. sineps; + pv.(1).(2) <- y *. sineps +. z *. coseps + + +(* Computes RA, Declination, and distance from a state vector returned by + * planetpv. *) +let radecdist state rdd = + (* Distance *) + rdd.(2) <- sqrt (state.(0).(0) *. state.(0).(0) + +. state.(0).(1) *. state.(0).(1) + +. state.(0).(2) *. state.(0).(2)); + (* RA *) + rdd.(0) <- atan2 state.(0).(1) state.(0).(0) *. r2h; + if rdd.(0) < 0.0 then rdd.(0) <- rdd.(0) +. 24.0; + + (* Declination *) + rdd.(1) <- asin (state.(0).(2) /. rdd.(2)) *. r2d + + + +(* Entry point. Calculate RA and Dec for noon on every day in 1900-2100 *) +let _ = + let jd = [| 0.0; 0.0 |] + and pv = [| [| 0.0; 0.0; 0.0 |]; [| 0.0; 0.0; 0.0 |] |] + and position = [| 0.0; 0.0; 0.0 |] in + (* Test *) + jd.(0) <- j2000; + jd.(1) <- 1.0; + for p = 0 to 7 do + planetpv jd p pv; + radecdist pv position; + Printf.printf "%d %.2f %.2f\n" p position.(0) position.(1) + done; + (* Benchmark *) + for i = 0 to test_loops - 1 do + jd.(0) <- j2000; + jd.(1) <- 0.0; + for n = 0 to test_length - 1 do + jd.(0) <- jd.(0) +. 1.0; + for p = 0 to 7 do + planetpv jd p pv; + radecdist pv position; + done + done + done diff --git a/test/bdd.ml b/test/bdd.ml new file mode 100644 index 0000000..6b0e7ff --- /dev/null +++ b/test/bdd.ml @@ -0,0 +1,231 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: bdd.ml,v 1.9 2005-08-12 09:22:04 xleroy Exp $ *) + +(* Translated to Caml by Xavier Leroy *) +(* Original code written in SML by ... *) + +type bdd = One | Zero | Node of bdd * int * int * bdd + +let rec eval bdd vars = + match bdd with + Zero -> false + | One -> true + | Node(l, v, _, h) -> + if vars.(v) then eval h vars else eval l vars + +let getId bdd = + match bdd with + Node(_,_,id,_) -> id + | Zero -> 0 + | One -> 1 + +let initSize_1 = 8*1024 - 1 +let nodeC = ref 1 +let sz_1 = ref initSize_1 +let htab = ref(Array.create (!sz_1+1) []) +let n_items = ref 0 +let hashVal x y v = x lsl 1 + y + v lsl 2 + +let resize newSize = + let arr = !htab in + let newSz_1 = newSize-1 in + let newArr = Array.create newSize [] in + let rec copyBucket bucket = + match bucket with + [] -> () + | n :: ns -> + match n with + | Node(l,v,_,h) -> + let ind = hashVal (getId l) (getId h) v land newSz_1 + in + newArr.(ind) <- (n :: newArr.(ind)); + copyBucket ns + | _ -> assert false + in + for n = 0 to !sz_1 do + copyBucket(arr.(n)) + done; + htab := newArr; + sz_1 := newSz_1 + + +let rec insert idl idh v ind bucket newNode = + if !n_items <= !sz_1 + then ( (!htab).(ind) <- (newNode :: bucket); + incr n_items ) + else ( resize(!sz_1 + !sz_1 + 2); + let ind = hashVal idl idh v land (!sz_1) + in + (!htab).(ind) <- newNode :: (!htab).(ind) + ) + + +let resetUnique () = ( + sz_1 := initSize_1; + htab := Array.create (!sz_1+1) []; + n_items := 0; + nodeC := 1 + ) + +let mkNode low v high = + let idl = getId low in + let idh = getId high + in + if idl = idh + then low + else let ind = hashVal idl idh v land (!sz_1) in + let bucket = (!htab).(ind) in + let rec lookup b = + match b with + [] -> let n = Node(low, v, (incr nodeC; !nodeC), high) + in + insert (getId low) (getId high) v ind bucket n; n + | n :: ns -> + match n with + | Node(l,v',id,h) -> + if v = v' && idl = getId l && idh = getId h + then n else lookup ns + | _ -> assert false + in + lookup bucket + + +type ordering = LESS | EQUAL | GREATER + +let cmpVar (x : int) (y : int) = + if x<y then LESS else if x>y then GREATER else EQUAL + +let zero = Zero +let one = One + +let mkVar x = mkNode zero x one + + +let cacheSize = 1999 +let andslot1 = Array.create cacheSize 0 +let andslot2 = Array.create cacheSize 0 +let andslot3 = Array.create cacheSize zero +let xorslot1 = Array.create cacheSize 0 +let xorslot2 = Array.create cacheSize 0 +let xorslot3 = Array.create cacheSize zero +let notslot1 = Array.create cacheSize 0 +let notslot2 = Array.create cacheSize one +let hash x y = ((x lsl 1)+y) mod cacheSize + +let rec not n = +match n with + Zero -> One +| One -> Zero +| Node(l, v, id, r) -> let h = id mod cacheSize + in + if id=notslot1.(h) then notslot2.(h) + else let f = mkNode (not l) v (not r) + in + notslot1.(h) <- id; notslot2.(h) <- f; f + +let rec and2 n1 n2 = +match n1 with + Node(l1, v1, i1, r1) + -> (match n2 with + Node(l2, v2, i2, r2) + -> let h = hash i1 i2 + in + if i1=andslot1.(h) && i2=andslot2.(h) then andslot3.(h) + else let f = match cmpVar v1 v2 with + EQUAL -> mkNode (and2 l1 l2) v1 (and2 r1 r2) + | LESS -> mkNode (and2 l1 n2) v1 (and2 r1 n2) + | GREATER -> mkNode (and2 n1 l2) v2 (and2 n1 r2) + in + andslot1.(h) <- i1; + andslot2.(h) <- i2; + andslot3.(h) <- f; + f + | Zero -> Zero + | One -> n1) +| Zero -> Zero +| One -> n2 + + +let rec xor n1 n2 = +match n1 with + Node(l1, v1, i1, r1) + -> (match n2 with + Node(l2, v2, i2, r2) + -> let h = hash i1 i2 + in + if i1=andslot1.(h) && i2=andslot2.(h) then andslot3.(h) + else let f = match cmpVar v1 v2 with + EQUAL -> mkNode (xor l1 l2) v1 (xor r1 r2) + | LESS -> mkNode (xor l1 n2) v1 (xor r1 n2) + | GREATER -> mkNode (xor n1 l2) v2 (xor n1 r2) + in + andslot1.(h) <- i1; + andslot2.(h) <- i2; + andslot3.(h) <- f; + f + | Zero -> n1 + | One -> not n1) +| Zero -> n2 +| One -> not n2 + +let hwb n = + let rec h i j = if i=j + then mkVar i + else xor (and2 (not(mkVar j)) (h i (j-1))) + (and2 (mkVar j) (g i (j-1))) + and g i j = if i=j + then mkVar i + else xor (and2 (not(mkVar i)) (h (i+1) j)) + (and2 (mkVar i) (g (i+1) j)) + in + h 0 (n-1) + +(* Testing *) +let seed = ref 0 + +let random() = + seed := !seed * 25173 + 17431; !seed land 1 > 0 + +let random_vars n = + let vars = Array.create n false in + for i = 0 to n - 1 do vars.(i) <- random() done; + vars + +let test_hwb bdd vars = + (* We should have + eval bdd vars = vars.(n-1) if n > 0 + eval bdd vars = false if n = 0 + where n is the number of "true" elements in vars. *) + let ntrue = ref 0 in + for i = 0 to Array.length vars - 1 do + if vars.(i) then incr ntrue + done; + eval bdd vars = (if !ntrue > 0 then vars.(!ntrue-1) else false) + +let main () = + let n = + if Array.length Sys.argv >= 2 then int_of_string Sys.argv.(1) else 22 in + let ntests = + if Array.length Sys.argv >= 3 then int_of_string Sys.argv.(2) else 100 in + let bdd = hwb n in + let succeeded = ref true in + for i = 1 to ntests do + succeeded := !succeeded && test_hwb bdd (random_vars n) + done; + if !succeeded + then print_string "OK\n" + else print_string "FAILED\n"; + exit 0 + +let _ = main() diff --git a/test/boyer.ml b/test/boyer.ml new file mode 100644 index 0000000..8257492 --- /dev/null +++ b/test/boyer.ml @@ -0,0 +1,911 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: boyer.ml,v 1.9 2005-08-12 09:22:04 xleroy Exp $ *) + +(* Manipulations over terms *) + +type term = + Var of int + | Prop of head * term list +and head = + { name: string; + mutable props: (term * term) list } + +let rec print_term = function + Var v -> + print_string "v"; print_int v + | Prop (head,argl) -> + print_string "("; + print_string head.name; + List.iter (fun t -> print_string " "; print_term t) argl; + print_string ")" + +let lemmas = ref ([] : head list) + +(* Replacement for property lists *) + +let get name = + let rec get_rec = function + hd1::hdl -> + if hd1.name = name then hd1 else get_rec hdl + | [] -> + let entry = {name = name; props = []} in + lemmas := entry :: !lemmas; + entry + in get_rec !lemmas + +let add_lemma = function + | Prop(_, [(Prop(headl,_) as left); right]) -> + headl.props <- (left, right) :: headl.props + | _ -> assert false + +(* Substitutions *) + +type subst = Bind of int * term + +let get_binding v list = + let rec get_rec = function + [] -> failwith "unbound" + | Bind(w,t)::rest -> if v = w then t else get_rec rest + in get_rec list + +let apply_subst alist term = + let rec as_rec = function + Var v -> begin try get_binding v alist with Failure _ -> term end + | Prop (head,argl) -> Prop (head, List.map as_rec argl) + in as_rec term + +exception Unify + +let rec unify term1 term2 = + unify1 term1 term2 [] + +and unify1 term1 term2 unify_subst = + match term2 with + Var v -> + begin try + if get_binding v unify_subst = term1 + then unify_subst + else raise Unify + with Failure _ -> + Bind(v,term1) :: unify_subst + end + | Prop (head2, argl2) -> + match term1 with + Var _ -> raise Unify + | Prop (head1,argl1) -> + if head1 == head2 + then unify1_lst argl1 argl2 unify_subst + else raise Unify + +and unify1_lst l1 l2 unify_subst = + match (l1, l2) with + ([], []) -> unify_subst + | (h1::r1, h2::r2) -> unify1_lst r1 r2 (unify1 h1 h2 unify_subst) + | _ -> raise Unify + + +let rec rewrite = function + Var _ as term -> term + | Prop (head, argl) -> + rewrite_with_lemmas (Prop (head, List.map rewrite argl)) head.props +and rewrite_with_lemmas term lemmas = + match lemmas with + [] -> + term + | (t1,t2)::rest -> + try + rewrite (apply_subst (unify term t1) t2) + with Unify -> + rewrite_with_lemmas term rest + +type cterm = CVar of int | CProp of string * cterm list + +let rec cterm_to_term = function + CVar v -> Var v + | CProp(p, l) -> Prop(get p, List.map cterm_to_term l) + +let add t = add_lemma (cterm_to_term t) + +let _ = +add (CProp +("equal", + [CProp ("compile",[CVar 5]); + CProp + ("reverse", + [CProp ("codegen",[CProp ("optimize",[CVar 5]); CProp ("nil",[])])])])); +add (CProp +("equal", + [CProp ("eqp",[CVar 23; CVar 24]); + CProp ("equal",[CProp ("fix",[CVar 23]); CProp ("fix",[CVar 24])])])); +add (CProp +("equal", + [CProp ("gt",[CVar 23; CVar 24]); CProp ("lt",[CVar 24; CVar 23])])); +add (CProp +("equal", + [CProp ("le",[CVar 23; CVar 24]); CProp ("ge",[CVar 24; CVar 23])])); +add (CProp +("equal", + [CProp ("ge",[CVar 23; CVar 24]); CProp ("le",[CVar 24; CVar 23])])); +add (CProp +("equal", + [CProp ("boolean",[CVar 23]); + CProp + ("or", + [CProp ("equal",[CVar 23; CProp ("true",[])]); + CProp ("equal",[CVar 23; CProp ("false",[])])])])); +add (CProp +("equal", + [CProp ("iff",[CVar 23; CVar 24]); + CProp + ("and", + [CProp ("implies",[CVar 23; CVar 24]); + CProp ("implies",[CVar 24; CVar 23])])])); +add (CProp +("equal", + [CProp ("even1",[CVar 23]); + CProp + ("if", + [CProp ("zerop",[CVar 23]); CProp ("true",[]); + CProp ("odd",[CProp ("sub1",[CVar 23])])])])); +add (CProp +("equal", + [CProp ("countps_",[CVar 11; CVar 15]); + CProp ("countps_loop",[CVar 11; CVar 15; CProp ("zero",[])])])); +add (CProp +("equal", + [CProp ("fact_",[CVar 8]); + CProp ("fact_loop",[CVar 8; CProp ("one",[])])])); +add (CProp +("equal", + [CProp ("reverse_",[CVar 23]); + CProp ("reverse_loop",[CVar 23; CProp ("nil",[])])])); +add (CProp +("equal", + [CProp ("divides",[CVar 23; CVar 24]); + CProp ("zerop",[CProp ("remainder",[CVar 24; CVar 23])])])); +add (CProp +("equal", + [CProp ("assume_true",[CVar 21; CVar 0]); + CProp ("cons",[CProp ("cons",[CVar 21; CProp ("true",[])]); CVar 0])])); +add (CProp +("equal", + [CProp ("assume_false",[CVar 21; CVar 0]); + CProp ("cons",[CProp ("cons",[CVar 21; CProp ("false",[])]); CVar 0])])); +add (CProp +("equal", + [CProp ("tautology_checker",[CVar 23]); + CProp ("tautologyp",[CProp ("normalize",[CVar 23]); CProp ("nil",[])])])); +add (CProp +("equal", + [CProp ("falsify",[CVar 23]); + CProp ("falsify1",[CProp ("normalize",[CVar 23]); CProp ("nil",[])])])); +add (CProp +("equal", + [CProp ("prime",[CVar 23]); + CProp + ("and", + [CProp ("not",[CProp ("zerop",[CVar 23])]); + CProp + ("not", + [CProp ("equal",[CVar 23; CProp ("add1",[CProp ("zero",[])])])]); + CProp ("prime1",[CVar 23; CProp ("sub1",[CVar 23])])])])); +add (CProp +("equal", + [CProp ("and",[CVar 15; CVar 16]); + CProp + ("if", + [CVar 15; + CProp ("if",[CVar 16; CProp ("true",[]); CProp ("false",[])]); + CProp ("false",[])])])); +add (CProp +("equal", + [CProp ("or",[CVar 15; CVar 16]); + CProp + ("if", + [CVar 15; CProp ("true",[]); + CProp ("if",[CVar 16; CProp ("true",[]); CProp ("false",[])]); + CProp ("false",[])])])); +add (CProp +("equal", + [CProp ("not",[CVar 15]); + CProp ("if",[CVar 15; CProp ("false",[]); CProp ("true",[])])])); +add (CProp +("equal", + [CProp ("implies",[CVar 15; CVar 16]); + CProp + ("if", + [CVar 15; + CProp ("if",[CVar 16; CProp ("true",[]); CProp ("false",[])]); + CProp ("true",[])])])); +add (CProp +("equal", + [CProp ("fix",[CVar 23]); + CProp ("if",[CProp ("numberp",[CVar 23]); CVar 23; CProp ("zero",[])])])); +add (CProp +("equal", + [CProp ("if",[CProp ("if",[CVar 0; CVar 1; CVar 2]); CVar 3; CVar 4]); + CProp + ("if", + [CVar 0; CProp ("if",[CVar 1; CVar 3; CVar 4]); + CProp ("if",[CVar 2; CVar 3; CVar 4])])])); +add (CProp +("equal", + [CProp ("zerop",[CVar 23]); + CProp + ("or", + [CProp ("equal",[CVar 23; CProp ("zero",[])]); + CProp ("not",[CProp ("numberp",[CVar 23])])])])); +add (CProp +("equal", + [CProp ("plus",[CProp ("plus",[CVar 23; CVar 24]); CVar 25]); + CProp ("plus",[CVar 23; CProp ("plus",[CVar 24; CVar 25])])])); +add (CProp +("equal", + [CProp ("equal",[CProp ("plus",[CVar 0; CVar 1]); CProp ("zero",[])]); + CProp ("and",[CProp ("zerop",[CVar 0]); CProp ("zerop",[CVar 1])])])); +add (CProp +("equal",[CProp ("difference",[CVar 23; CVar 23]); CProp ("zero",[])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("plus",[CVar 0; CVar 1]); CProp ("plus",[CVar 0; CVar 2])]); + CProp ("equal",[CProp ("fix",[CVar 1]); CProp ("fix",[CVar 2])])])); +add (CProp +("equal", + [CProp + ("equal",[CProp ("zero",[]); CProp ("difference",[CVar 23; CVar 24])]); + CProp ("not",[CProp ("gt",[CVar 24; CVar 23])])])); +add (CProp +("equal", + [CProp ("equal",[CVar 23; CProp ("difference",[CVar 23; CVar 24])]); + CProp + ("and", + [CProp ("numberp",[CVar 23]); + CProp + ("or", + [CProp ("equal",[CVar 23; CProp ("zero",[])]); + CProp ("zerop",[CVar 24])])])])); +add (CProp +("equal", + [CProp + ("meaning", + [CProp ("plus_tree",[CProp ("append",[CVar 23; CVar 24])]); CVar 0]); + CProp + ("plus", + [CProp ("meaning",[CProp ("plus_tree",[CVar 23]); CVar 0]); + CProp ("meaning",[CProp ("plus_tree",[CVar 24]); CVar 0])])])); +add (CProp +("equal", + [CProp + ("meaning", + [CProp ("plus_tree",[CProp ("plus_fringe",[CVar 23])]); CVar 0]); + CProp ("fix",[CProp ("meaning",[CVar 23; CVar 0])])])); +add (CProp +("equal", + [CProp ("append",[CProp ("append",[CVar 23; CVar 24]); CVar 25]); + CProp ("append",[CVar 23; CProp ("append",[CVar 24; CVar 25])])])); +add (CProp +("equal", + [CProp ("reverse",[CProp ("append",[CVar 0; CVar 1])]); + CProp + ("append",[CProp ("reverse",[CVar 1]); CProp ("reverse",[CVar 0])])])); +add (CProp +("equal", + [CProp ("times",[CVar 23; CProp ("plus",[CVar 24; CVar 25])]); + CProp + ("plus", + [CProp ("times",[CVar 23; CVar 24]); + CProp ("times",[CVar 23; CVar 25])])])); +add (CProp +("equal", + [CProp ("times",[CProp ("times",[CVar 23; CVar 24]); CVar 25]); + CProp ("times",[CVar 23; CProp ("times",[CVar 24; CVar 25])])])); +add (CProp +("equal", + [CProp + ("equal",[CProp ("times",[CVar 23; CVar 24]); CProp ("zero",[])]); + CProp ("or",[CProp ("zerop",[CVar 23]); CProp ("zerop",[CVar 24])])])); +add (CProp +("equal", + [CProp ("exec",[CProp ("append",[CVar 23; CVar 24]); CVar 15; CVar 4]); + CProp + ("exec",[CVar 24; CProp ("exec",[CVar 23; CVar 15; CVar 4]); CVar 4])])); +add (CProp +("equal", + [CProp ("mc_flatten",[CVar 23; CVar 24]); + CProp ("append",[CProp ("flatten",[CVar 23]); CVar 24])])); +add (CProp +("equal", + [CProp ("member",[CVar 23; CProp ("append",[CVar 0; CVar 1])]); + CProp + ("or", + [CProp ("member",[CVar 23; CVar 0]); + CProp ("member",[CVar 23; CVar 1])])])); +add (CProp +("equal", + [CProp ("member",[CVar 23; CProp ("reverse",[CVar 24])]); + CProp ("member",[CVar 23; CVar 24])])); +add (CProp +("equal", + [CProp ("length",[CProp ("reverse",[CVar 23])]); + CProp ("length",[CVar 23])])); +add (CProp +("equal", + [CProp ("member",[CVar 0; CProp ("intersect",[CVar 1; CVar 2])]); + CProp + ("and", + [CProp ("member",[CVar 0; CVar 1]); CProp ("member",[CVar 0; CVar 2])])])); +add (CProp +("equal",[CProp ("nth",[CProp ("zero",[]); CVar 8]); CProp ("zero",[])])); +add (CProp +("equal", + [CProp ("exp",[CVar 8; CProp ("plus",[CVar 9; CVar 10])]); + CProp + ("times", + [CProp ("exp",[CVar 8; CVar 9]); CProp ("exp",[CVar 8; CVar 10])])])); +add (CProp +("equal", + [CProp ("exp",[CVar 8; CProp ("times",[CVar 9; CVar 10])]); + CProp ("exp",[CProp ("exp",[CVar 8; CVar 9]); CVar 10])])); +add (CProp +("equal", + [CProp ("reverse_loop",[CVar 23; CVar 24]); + CProp ("append",[CProp ("reverse",[CVar 23]); CVar 24])])); +add (CProp +("equal", + [CProp ("reverse_loop",[CVar 23; CProp ("nil",[])]); + CProp ("reverse",[CVar 23])])); +add (CProp +("equal", + [CProp ("count_list",[CVar 25; CProp ("sort_lp",[CVar 23; CVar 24])]); + CProp + ("plus", + [CProp ("count_list",[CVar 25; CVar 23]); + CProp ("count_list",[CVar 25; CVar 24])])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("append",[CVar 0; CVar 1]); CProp ("append",[CVar 0; CVar 2])]); + CProp ("equal",[CVar 1; CVar 2])])); +add (CProp +("equal", + [CProp + ("plus", + [CProp ("remainder",[CVar 23; CVar 24]); + CProp ("times",[CVar 24; CProp ("quotient",[CVar 23; CVar 24])])]); + CProp ("fix",[CVar 23])])); +add (CProp +("equal", + [CProp + ("power_eval",[CProp ("big_plus",[CVar 11; CVar 8; CVar 1]); CVar 1]); + CProp ("plus",[CProp ("power_eval",[CVar 11; CVar 1]); CVar 8])])); +add (CProp +("equal", + [CProp + ("power_eval", + [CProp ("big_plus",[CVar 23; CVar 24; CVar 8; CVar 1]); CVar 1]); + CProp + ("plus", + [CVar 8; + CProp + ("plus", + [CProp ("power_eval",[CVar 23; CVar 1]); + CProp ("power_eval",[CVar 24; CVar 1])])])])); +add (CProp +("equal", + [CProp ("remainder",[CVar 24; CProp ("one",[])]); CProp ("zero",[])])); +add (CProp +("equal", + [CProp ("lt",[CProp ("remainder",[CVar 23; CVar 24]); CVar 24]); + CProp ("not",[CProp ("zerop",[CVar 24])])])); +add (CProp +("equal",[CProp ("remainder",[CVar 23; CVar 23]); CProp ("zero",[])])); +add (CProp +("equal", + [CProp ("lt",[CProp ("quotient",[CVar 8; CVar 9]); CVar 8]); + CProp + ("and", + [CProp ("not",[CProp ("zerop",[CVar 8])]); + CProp + ("or", + [CProp ("zerop",[CVar 9]); + CProp ("not",[CProp ("equal",[CVar 9; CProp ("one",[])])])])])])); +add (CProp +("equal", + [CProp ("lt",[CProp ("remainder",[CVar 23; CVar 24]); CVar 23]); + CProp + ("and", + [CProp ("not",[CProp ("zerop",[CVar 24])]); + CProp ("not",[CProp ("zerop",[CVar 23])]); + CProp ("not",[CProp ("lt",[CVar 23; CVar 24])])])])); +add (CProp +("equal", + [CProp ("power_eval",[CProp ("power_rep",[CVar 8; CVar 1]); CVar 1]); + CProp ("fix",[CVar 8])])); +add (CProp +("equal", + [CProp + ("power_eval", + [CProp + ("big_plus", + [CProp ("power_rep",[CVar 8; CVar 1]); + CProp ("power_rep",[CVar 9; CVar 1]); CProp ("zero",[]); + CVar 1]); + CVar 1]); + CProp ("plus",[CVar 8; CVar 9])])); +add (CProp +("equal", + [CProp ("gcd",[CVar 23; CVar 24]); CProp ("gcd",[CVar 24; CVar 23])])); +add (CProp +("equal", + [CProp ("nth",[CProp ("append",[CVar 0; CVar 1]); CVar 8]); + CProp + ("append", + [CProp ("nth",[CVar 0; CVar 8]); + CProp + ("nth", + [CVar 1; CProp ("difference",[CVar 8; CProp ("length",[CVar 0])])])])])); +add (CProp +("equal", + [CProp ("difference",[CProp ("plus",[CVar 23; CVar 24]); CVar 23]); + CProp ("fix",[CVar 24])])); +add (CProp +("equal", + [CProp ("difference",[CProp ("plus",[CVar 24; CVar 23]); CVar 23]); + CProp ("fix",[CVar 24])])); +add (CProp +("equal", + [CProp + ("difference", + [CProp ("plus",[CVar 23; CVar 24]); CProp ("plus",[CVar 23; CVar 25])]); + CProp ("difference",[CVar 24; CVar 25])])); +add (CProp +("equal", + [CProp ("times",[CVar 23; CProp ("difference",[CVar 2; CVar 22])]); + CProp + ("difference", + [CProp ("times",[CVar 2; CVar 23]); + CProp ("times",[CVar 22; CVar 23])])])); +add (CProp +("equal", + [CProp ("remainder",[CProp ("times",[CVar 23; CVar 25]); CVar 25]); + CProp ("zero",[])])); +add (CProp +("equal", + [CProp + ("difference", + [CProp ("plus",[CVar 1; CProp ("plus",[CVar 0; CVar 2])]); CVar 0]); + CProp ("plus",[CVar 1; CVar 2])])); +add (CProp +("equal", + [CProp + ("difference", + [CProp ("add1",[CProp ("plus",[CVar 24; CVar 25])]); CVar 25]); + CProp ("add1",[CVar 24])])); +add (CProp +("equal", + [CProp + ("lt", + [CProp ("plus",[CVar 23; CVar 24]); CProp ("plus",[CVar 23; CVar 25])]); + CProp ("lt",[CVar 24; CVar 25])])); +add (CProp +("equal", + [CProp + ("lt", + [CProp ("times",[CVar 23; CVar 25]); + CProp ("times",[CVar 24; CVar 25])]); + CProp + ("and", + [CProp ("not",[CProp ("zerop",[CVar 25])]); + CProp ("lt",[CVar 23; CVar 24])])])); +add (CProp +("equal", + [CProp ("lt",[CVar 24; CProp ("plus",[CVar 23; CVar 24])]); + CProp ("not",[CProp ("zerop",[CVar 23])])])); +add (CProp +("equal", + [CProp + ("gcd", + [CProp ("times",[CVar 23; CVar 25]); + CProp ("times",[CVar 24; CVar 25])]); + CProp ("times",[CVar 25; CProp ("gcd",[CVar 23; CVar 24])])])); +add (CProp +("equal", + [CProp ("value",[CProp ("normalize",[CVar 23]); CVar 0]); + CProp ("value",[CVar 23; CVar 0])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("flatten",[CVar 23]); + CProp ("cons",[CVar 24; CProp ("nil",[])])]); + CProp + ("and", + [CProp ("nlistp",[CVar 23]); CProp ("equal",[CVar 23; CVar 24])])])); +add (CProp +("equal", + [CProp ("listp",[CProp ("gother",[CVar 23])]); + CProp ("listp",[CVar 23])])); +add (CProp +("equal", + [CProp ("samefringe",[CVar 23; CVar 24]); + CProp + ("equal",[CProp ("flatten",[CVar 23]); CProp ("flatten",[CVar 24])])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("greatest_factor",[CVar 23; CVar 24]); CProp ("zero",[])]); + CProp + ("and", + [CProp + ("or", + [CProp ("zerop",[CVar 24]); + CProp ("equal",[CVar 24; CProp ("one",[])])]); + CProp ("equal",[CVar 23; CProp ("zero",[])])])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("greatest_factor",[CVar 23; CVar 24]); CProp ("one",[])]); + CProp ("equal",[CVar 23; CProp ("one",[])])])); +add (CProp +("equal", + [CProp ("numberp",[CProp ("greatest_factor",[CVar 23; CVar 24])]); + CProp + ("not", + [CProp + ("and", + [CProp + ("or", + [CProp ("zerop",[CVar 24]); + CProp ("equal",[CVar 24; CProp ("one",[])])]); + CProp ("not",[CProp ("numberp",[CVar 23])])])])])); +add (CProp +("equal", + [CProp ("times_list",[CProp ("append",[CVar 23; CVar 24])]); + CProp + ("times", + [CProp ("times_list",[CVar 23]); CProp ("times_list",[CVar 24])])])); +add (CProp +("equal", + [CProp ("prime_list",[CProp ("append",[CVar 23; CVar 24])]); + CProp + ("and", + [CProp ("prime_list",[CVar 23]); CProp ("prime_list",[CVar 24])])])); +add (CProp +("equal", + [CProp ("equal",[CVar 25; CProp ("times",[CVar 22; CVar 25])]); + CProp + ("and", + [CProp ("numberp",[CVar 25]); + CProp + ("or", + [CProp ("equal",[CVar 25; CProp ("zero",[])]); + CProp ("equal",[CVar 22; CProp ("one",[])])])])])); +add (CProp +("equal", + [CProp ("ge",[CVar 23; CVar 24]); + CProp ("not",[CProp ("lt",[CVar 23; CVar 24])])])); +add (CProp +("equal", + [CProp ("equal",[CVar 23; CProp ("times",[CVar 23; CVar 24])]); + CProp + ("or", + [CProp ("equal",[CVar 23; CProp ("zero",[])]); + CProp + ("and", + [CProp ("numberp",[CVar 23]); + CProp ("equal",[CVar 24; CProp ("one",[])])])])])); +add (CProp +("equal", + [CProp ("remainder",[CProp ("times",[CVar 24; CVar 23]); CVar 24]); + CProp ("zero",[])])); +add (CProp +("equal", + [CProp ("equal",[CProp ("times",[CVar 0; CVar 1]); CProp ("one",[])]); + CProp + ("and", + [CProp ("not",[CProp ("equal",[CVar 0; CProp ("zero",[])])]); + CProp ("not",[CProp ("equal",[CVar 1; CProp ("zero",[])])]); + CProp ("numberp",[CVar 0]); CProp ("numberp",[CVar 1]); + CProp ("equal",[CProp ("sub1",[CVar 0]); CProp ("zero",[])]); + CProp ("equal",[CProp ("sub1",[CVar 1]); CProp ("zero",[])])])])); +add (CProp +("equal", + [CProp + ("lt", + [CProp ("length",[CProp ("delete",[CVar 23; CVar 11])]); + CProp ("length",[CVar 11])]); + CProp ("member",[CVar 23; CVar 11])])); +add (CProp +("equal", + [CProp ("sort2",[CProp ("delete",[CVar 23; CVar 11])]); + CProp ("delete",[CVar 23; CProp ("sort2",[CVar 11])])])); +add (CProp ("equal",[CProp ("dsort",[CVar 23]); CProp ("sort2",[CVar 23])])); +add (CProp +("equal", + [CProp + ("length", + [CProp + ("cons", + [CVar 0; + CProp + ("cons", + [CVar 1; + CProp + ("cons", + [CVar 2; + CProp + ("cons", + [CVar 3; + CProp ("cons",[CVar 4; CProp ("cons",[CVar 5; CVar 6])])])])])])]) + ; CProp ("plus",[CProp ("six",[]); CProp ("length",[CVar 6])])])); +add (CProp +("equal", + [CProp + ("difference", + [CProp ("add1",[CProp ("add1",[CVar 23])]); CProp ("two",[])]); + CProp ("fix",[CVar 23])])); +add (CProp +("equal", + [CProp + ("quotient", + [CProp ("plus",[CVar 23; CProp ("plus",[CVar 23; CVar 24])]); + CProp ("two",[])]); + CProp + ("plus",[CVar 23; CProp ("quotient",[CVar 24; CProp ("two",[])])])])); +add (CProp +("equal", + [CProp ("sigma",[CProp ("zero",[]); CVar 8]); + CProp + ("quotient", + [CProp ("times",[CVar 8; CProp ("add1",[CVar 8])]); CProp ("two",[])])])); +add (CProp +("equal", + [CProp ("plus",[CVar 23; CProp ("add1",[CVar 24])]); + CProp + ("if", + [CProp ("numberp",[CVar 24]); + CProp ("add1",[CProp ("plus",[CVar 23; CVar 24])]); + CProp ("add1",[CVar 23])])])); +add (CProp +("equal", + [CProp + ("equal", + [CProp ("difference",[CVar 23; CVar 24]); + CProp ("difference",[CVar 25; CVar 24])]); + CProp + ("if", + [CProp ("lt",[CVar 23; CVar 24]); + CProp ("not",[CProp ("lt",[CVar 24; CVar 25])]); + CProp + ("if", + [CProp ("lt",[CVar 25; CVar 24]); + CProp ("not",[CProp ("lt",[CVar 24; CVar 23])]); + CProp ("equal",[CProp ("fix",[CVar 23]); CProp ("fix",[CVar 25])])])])]) +); +add (CProp +("equal", + [CProp + ("meaning", + [CProp ("plus_tree",[CProp ("delete",[CVar 23; CVar 24])]); CVar 0]); + CProp + ("if", + [CProp ("member",[CVar 23; CVar 24]); + CProp + ("difference", + [CProp ("meaning",[CProp ("plus_tree",[CVar 24]); CVar 0]); + CProp ("meaning",[CVar 23; CVar 0])]); + CProp ("meaning",[CProp ("plus_tree",[CVar 24]); CVar 0])])])); +add (CProp +("equal", + [CProp ("times",[CVar 23; CProp ("add1",[CVar 24])]); + CProp + ("if", + [CProp ("numberp",[CVar 24]); + CProp + ("plus", + [CVar 23; CProp ("times",[CVar 23; CVar 24]); + CProp ("fix",[CVar 23])])])])); +add (CProp +("equal", + [CProp ("nth",[CProp ("nil",[]); CVar 8]); + CProp + ("if",[CProp ("zerop",[CVar 8]); CProp ("nil",[]); CProp ("zero",[])])])); +add (CProp +("equal", + [CProp ("last",[CProp ("append",[CVar 0; CVar 1])]); + CProp + ("if", + [CProp ("listp",[CVar 1]); CProp ("last",[CVar 1]); + CProp + ("if", + [CProp ("listp",[CVar 0]); + CProp ("cons",[CProp ("car",[CProp ("last",[CVar 0])]); CVar 1]); + CVar 1])])])); +add (CProp +("equal", + [CProp ("equal",[CProp ("lt",[CVar 23; CVar 24]); CVar 25]); + CProp + ("if", + [CProp ("lt",[CVar 23; CVar 24]); + CProp ("equal",[CProp ("true",[]); CVar 25]); + CProp ("equal",[CProp ("false",[]); CVar 25])])])); +add (CProp +("equal", + [CProp ("assignment",[CVar 23; CProp ("append",[CVar 0; CVar 1])]); + CProp + ("if", + [CProp ("assignedp",[CVar 23; CVar 0]); + CProp ("assignment",[CVar 23; CVar 0]); + CProp ("assignment",[CVar 23; CVar 1])])])); +add (CProp +("equal", + [CProp ("car",[CProp ("gother",[CVar 23])]); + CProp + ("if", + [CProp ("listp",[CVar 23]); + CProp ("car",[CProp ("flatten",[CVar 23])]); CProp ("zero",[])])])); +add (CProp +("equal", + [CProp ("flatten",[CProp ("cdr",[CProp ("gother",[CVar 23])])]); + CProp + ("if", + [CProp ("listp",[CVar 23]); + CProp ("cdr",[CProp ("flatten",[CVar 23])]); + CProp ("cons",[CProp ("zero",[]); CProp ("nil",[])])])])); +add (CProp +("equal", + [CProp ("quotient",[CProp ("times",[CVar 24; CVar 23]); CVar 24]); + CProp + ("if", + [CProp ("zerop",[CVar 24]); CProp ("zero",[]); + CProp ("fix",[CVar 23])])])); +add (CProp +("equal", + [CProp ("get",[CVar 9; CProp ("set",[CVar 8; CVar 21; CVar 12])]); + CProp + ("if", + [CProp ("eqp",[CVar 9; CVar 8]); CVar 21; + CProp ("get",[CVar 9; CVar 12])])])) + +(* Tautology checker *) + +let truep x lst = + match x with + Prop(head, _) -> + head.name = "true" || List.mem x lst + | _ -> + List.mem x lst + +and falsep x lst = + match x with + Prop(head, _) -> + head.name = "false" || List.mem x lst + | _ -> + List.mem x lst + + +let rec tautologyp x true_lst false_lst = + if truep x true_lst then true else + if falsep x false_lst then false else begin +(* + print_term x; print_newline(); +*) + match x with + Var _ -> false + | Prop (head,[test; yes; no]) as p -> + if head.name = "if" then + if truep test true_lst then + tautologyp yes true_lst false_lst + else if falsep test false_lst then + tautologyp no true_lst false_lst + else tautologyp yes (test::true_lst) false_lst && + tautologyp no true_lst (test::false_lst) + else + false + | _ -> assert false + end + + +let tautp x = +(* print_term x; print_string"\n"; *) + let y = rewrite x in +(* print_term y; print_string "\n"; *) + tautologyp y [] [] + +(* the benchmark *) + +let subst = +[Bind(23, cterm_to_term( + CProp + ("f", + [CProp + ("plus", + [CProp ("plus",[CVar 0; CVar 1]); + CProp ("plus",[CVar 2; CProp ("zero",[])])])]))); + Bind(24, cterm_to_term( + CProp + ("f", + [CProp + ("times", + [CProp ("times",[CVar 0; CVar 1]); + CProp ("plus",[CVar 2; CVar 3])])]))); + Bind(25, cterm_to_term( + CProp + ("f", + [CProp + ("reverse", + [CProp + ("append", + [CProp ("append",[CVar 0; CVar 1]); + CProp ("nil",[])])])]))); + Bind(20, cterm_to_term( + CProp + ("equal", + [CProp ("plus",[CVar 0; CVar 1]); + CProp ("difference",[CVar 23; CVar 24])]))); + Bind(22, cterm_to_term( + CProp + ("lt", + [CProp ("remainder",[CVar 0; CVar 1]); + CProp ("member",[CVar 0; CProp ("length",[CVar 1])])])))] + +let term = cterm_to_term( + CProp + ("implies", + [CProp + ("and", + [CProp ("implies",[CVar 23; CVar 24]); + CProp + ("and", + [CProp ("implies",[CVar 24; CVar 25]); + CProp + ("and", + [CProp ("implies",[CVar 25; CVar 20]); + CProp ("implies",[CVar 20; CVar 22])])])]); + CProp ("implies",[CVar 23; CVar 22])])) + +let _ = + let ok = ref true in + for i = 1 to 50 do + if not (tautp (apply_subst subst term)) then ok := false + done; + if !ok then + print_string "Proved!\n" + else + print_string "Cannot prove!\n"; + exit 0 + +(********* +with + failure s -> + print_string "Exception failure("; print_string s; print_string ")\n" + | Unify -> + print_string "Exception Unify\n" + | match_failure(file,start,stop) -> + print_string "Exception match_failure("; + print_string file; + print_string ","; + print_int start; + print_string ","; + print_int stop; + print_string ")\n" + | _ -> + print_string "Exception ?\n" + +**********) diff --git a/test/dynlink/Makefile b/test/dynlink/Makefile new file mode 100644 index 0000000..a4c396c --- /dev/null +++ b/test/dynlink/Makefile @@ -0,0 +1,54 @@ +include ../../config/Makefile + +OCAMLRUN=$(BINDIR)/ocamlrun.exe +OCAMLC=$(OCAMLRUN) $(BINDIR)/ocamlc +OCAMLMKLIB=$(OCAMLRUN) $(BINDIR)/ocamlmklib + +all: demo + +stub1.$(O): stub1.c + $(OCAMLC) -c stub1.c + +libplug1.$(A): stub1.$(O) + $(OCAMLMKLIB) -o plug1 stub1.$(O) + +plug1.cmo: plug1.ml + $(OCAMLC) -c plug1.ml + +plug1.cma: plug1.cmo libplug1.$(A) + $(OCAMLMKLIB) -o plug1 plug1.cmo + +stub2.$(O): stub2.c + $(OCAMLC) -c stub2.c + +libplug2.$(A): stub2.$(O) + $(OCAMLMKLIB) -o plug2 stub2.$(O) + +plug2.cmo: plug2.ml + $(OCAMLC) -c plug2.ml + +plug2.cma: plug2.cmo libplug2.$(A) + $(OCAMLMKLIB) -o plug2 plug2.cmo + +main.cmo: main.ml + $(OCAMLC) -c main.ml + +main.exe: main.cmo + $(OCAMLC) -o main.exe dynlink.cma main.cmo + +static.exe: plug1.cma plug2.cma + $(OCAMLC) -o static.exe -linkall plug1.cma plug2.cma -use-runtime $(OCAMLRUN) + +custom.exe: plug2.cma plug1.cma + $(OCAMLC) -o custom.exe -custom -linkall plug2.cma plug1.cma + +demo: main.exe plug1.cma plug2.cma static.exe custom.exe + @echo "********** Dynamic" + -$(OCAMLRUN) ./main.exe plug1.cma plug2.cma + @echo "********** Static" + -$(OCAMLRUN) ./static.exe + @echo "********** Custom" + -./custom.exe + +clean: + rm -f *.lib *.obj *.o *.a *.dll *.manifest *.exe *.cmo *.cmi *~ *.exp *.cma *.so \ No newline at end of file diff --git a/test/dynlink/main.ml b/test/dynlink/main.ml new file mode 100644 index 0000000..bd980f1 --- /dev/null +++ b/test/dynlink/main.ml @@ -0,0 +1,17 @@ + Dynlink.init (); + Dynlink.allow_unsafe_modules true; + for i = 1 to Array.length Sys.argv - 1 do + let name = Sys.argv.(i) in + Printf.printf "Loading %s\n" name; flush stdout; + try + if name.[0] = '-' + then Dynlink.loadfile_private + (String.sub name 1 (String.length name - 1)) + else Dynlink.loadfile name + with + | Dynlink.Error err -> + Printf.printf "Dynlink error: %s\n" + (Dynlink.error_message err) + | exn -> + Printf.printf "Error: %s\n" (Printexc.to_string exn) + done diff --git a/test/dynlink/plug1.ml b/test/dynlink/plug1.ml new file mode 100644 index 0000000..3246045 --- /dev/null +++ b/test/dynlink/plug1.ml @@ -0,0 +1,4 @@ +external stub1: unit -> string = "stub1" + + +let () = print_endline (stub1 ()) diff --git a/test/dynlink/plug2.ml b/test/dynlink/plug2.ml new file mode 100644 index 0000000..05f4fda --- /dev/null +++ b/test/dynlink/plug2.ml @@ -0,0 +1,4 @@ +external stub2: unit -> unit = "stub2" + + +let () = stub2 () diff --git a/test/dynlink/stub1.c b/test/dynlink/stub1.c new file mode 100644 index 0000000..18ddf3f --- /dev/null +++ b/test/dynlink/stub1.c @@ -0,0 +1,11 @@ +#include "caml/mlvalues.h" +#include "caml/memory.h" +#include "caml/alloc.h" +#include <stdio.h> + +value stub1() { + CAMLlocal1(x); + printf("This is stub1!\n"); + x = caml_copy_string("ABCDEF"); + return x; +} diff --git a/test/dynlink/stub2.c b/test/dynlink/stub2.c new file mode 100644 index 0000000..a118673 --- /dev/null +++ b/test/dynlink/stub2.c @@ -0,0 +1,13 @@ +#include "caml/mlvalues.h" +#include "caml/memory.h" +#include "caml/alloc.h" +#include <stdio.h> + +extern value stub1(); + +value stub2() { + printf("This is stub2, calling stub1:\n"); + stub1(); + printf("Ok!\n"); + return Val_unit; +} diff --git a/test/fft.ml b/test/fft.ml new file mode 100644 index 0000000..d484cbf --- /dev/null +++ b/test/fft.ml @@ -0,0 +1,189 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: fft.ml,v 1.9 2005-08-12 09:22:04 xleroy Exp $ *) + +let pi = 3.14159265358979323846 + +let tpi = 2.0 *. pi + +let fft px py np = + let i = ref 2 in + let m = ref 1 in + + while (!i < np) do + i := !i + !i; + m := !m + 1 + done; + + let n = !i in + + if n <> np then begin + for i = np+1 to n do + px.(i) <- 0.0; + py.(i) <- 0.0 + done; + print_string "Use "; print_int n; + print_string " point fft"; print_newline() + end; + + let n2 = ref(n+n) in + for k = 1 to !m-1 do + n2 := !n2 / 2; + let n4 = !n2 / 4 in + let e = tpi /. float !n2 in + + for j = 1 to n4 do + let a = e *. float(j - 1) in + let a3 = 3.0 *. a in + let cc1 = cos(a) in + let ss1 = sin(a) in + let cc3 = cos(a3) in + let ss3 = sin(a3) in + let is = ref j in + let id = ref(2 * !n2) in + + while !is < n do + let i0r = ref !is in + while !i0r < n do + let i0 = !i0r in + let i1 = i0 + n4 in + let i2 = i1 + n4 in + let i3 = i2 + n4 in + let r1 = px.(i0) -. px.(i2) in + px.(i0) <- px.(i0) +. px.(i2); + let r2 = px.(i1) -. px.(i3) in + px.(i1) <- px.(i1) +. px.(i3); + let s1 = py.(i0) -. py.(i2) in + py.(i0) <- py.(i0) +. py.(i2); + let s2 = py.(i1) -. py.(i3) in + py.(i1) <- py.(i1) +. py.(i3); + let s3 = r1 -. s2 in + let r1 = r1 +. s2 in + let s2 = r2 -. s1 in + let r2 = r2 +. s1 in + px.(i2) <- r1*.cc1 -. s2*.ss1; + py.(i2) <- -.s2*.cc1 -. r1*.ss1; + px.(i3) <- s3*.cc3 +. r2*.ss3; + py.(i3) <- r2*.cc3 -. s3*.ss3; + i0r := i0 + !id + done; + is := 2 * !id - !n2 + j; + id := 4 * !id + done + done + done; + +(************************************) +(* Last stage, length=2 butterfly *) +(************************************) + + let is = ref 1 in + let id = ref 4 in + + while !is < n do + let i0r = ref !is in + while !i0r <= n do + let i0 = !i0r in + let i1 = i0 + 1 in + let r1 = px.(i0) in + px.(i0) <- r1 +. px.(i1); + px.(i1) <- r1 -. px.(i1); + let r1 = py.(i0) in + py.(i0) <- r1 +. py.(i1); + py.(i1) <- r1 -. py.(i1); + i0r := i0 + !id + done; + is := 2 * !id - 1; + id := 4 * !id + done; + +(*************************) +(* Bit reverse counter *) +(*************************) + + let j = ref 1 in + + for i = 1 to n - 1 do + if i < !j then begin + let xt = px.(!j) in + px.(!j) <- px.(i); + px.(i) <- xt; + let xt = py.(!j) in + py.(!j) <- py.(i); + py.(i) <- xt + end; + let k = ref(n / 2) in + while !k < !j do + j := !j - !k; + k := !k / 2 + done; + j := !j + !k + done; + + n + + +let test np = + print_int np; print_string "... "; flush stdout; + let enp = float np in + let npm = np / 2 - 1 in + let pxr = Array.create (np+2) 0.0 + and pxi = Array.create (np+2) 0.0 in + let t = pi /. enp in + pxr.(1) <- (enp -. 1.0) *. 0.5; + pxi.(1) <- 0.0; + let n2 = np / 2 in + pxr.(n2+1) <- -0.5; + pxi.(n2+1) <- 0.0; + + for i = 1 to npm do + let j = np - i in + pxr.(i+1) <- -0.5; + pxr.(j+1) <- -0.5; + let z = t *. float i in + let y = -0.5*.(cos(z)/.sin(z)) in + pxi.(i+1) <- y; + pxi.(j+1) <- -.y + done; +(** + print_newline(); + for i=0 to 15 do Printf.printf "%d %f %f\n" i pxr.(i+1) pxi.(i+1) done; +**) + let _ = fft pxr pxi np in +(** + for i=0 to 15 do Printf.printf "%d %f %f\n" i pxr.(i+1) pxi.(i+1) done; +**) + let zr = ref 0.0 in + let zi = ref 0.0 in + let kr = ref 0 in + let ki = ref 0 in + for i = 0 to np-1 do + let a = abs_float(pxr.(i+1) -. float i) in + if !zr < a then begin + zr := a; + kr := i + end; + let a = abs_float(pxi.(i+1)) in + if !zi < a then begin + zi := a; + ki := i + end + done; + if abs_float !zr <= 1e-9 && abs_float !zi <= 1e-9 + then print_string "ok" + else print_string "ERROR"; + print_newline() + +let _ = + let np = ref 16 in for i = 1 to 16 do test !np; np := !np*2 done + diff --git a/test/fib.ml b/test/fib.ml new file mode 100644 index 0000000..b32501a --- /dev/null +++ b/test/fib.ml @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: fib.ml,v 1.5 2005-08-12 09:22:04 xleroy Exp $ *) + +let rec fib n = + if n < 2 then 1 else fib(n-1) + fib(n-2) + +let _ = + let n = + if Array.length Sys.argv >= 2 + then int_of_string Sys.argv.(1) + else 40 in + print_int(fib n); print_newline(); exit 0 + diff --git a/test/hamming.ml b/test/hamming.ml new file mode 100644 index 0000000..eb12900 --- /dev/null +++ b/test/hamming.ml @@ -0,0 +1,105 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: hamming.ml,v 1.1 2002-01-23 17:50:19 doligez Exp $ *) + +(* We cannot use bignums because we don't do custom runtimes, but + int64 is a bit short, so we roll our own 37-digit numbers... +*) + +let n0 = Int64.of_int 0;; +let n1 = Int64.of_int 1;; +let n2 = Int64.of_int 2;; +let n3 = Int64.of_int 3;; +let n5 = Int64.of_int 5;; + +let ( % ) = Int64.rem;; +let ( * ) = Int64.mul;; +let ( / ) = Int64.div;; +let ( + ) = Int64.add;; +let digit = Int64.of_string "1000000000000000000";; + +let mul n (pl, ph) = ((n * pl) % digit, n * ph + (n * pl) / digit);; +let cmp (nl, nh) (pl, ph) = + if nh < ph then -1 + else if nh > ph then 1 + else if nl < pl then -1 + else if nl > pl then 1 + else 0 +;; + +let x2 = fun p -> mul n2 p;; +let x3 = fun p -> mul n3 p;; +let x5 = fun p -> mul n5 p;; + +let nn1 = (n1, n0);; + +let pr (nl, nh) = + if compare nh n0 = 0 + then Printf.printf "%Ld\n" nl + else Printf.printf "%Ld%018Ld\n" nh nl +;; + +(* + (* bignum version *) +open Num;; +let nn1 = num_of_int 1;; +let x2 = fun p -> (num_of_int 2) */ p;; +let x3 = fun p -> (num_of_int 3) */ p;; +let x5 = fun p -> (num_of_int 5) */ p;; +let cmp n p = sign_num (n -/ p);; +let pr n = Printf.printf "%s\n" (string_of_num n);; +*) + + +(* This is where the interesting stuff begins. *) + +open Lazy;; + +type 'a lcons = Cons of 'a * 'a lcons Lazy.t;; +type 'a llist = 'a lcons Lazy.t;; + +let rec map f l = + lazy ( + match force l with + | Cons (x, ll) -> Cons (f x, map f ll) + ) +;; + +let rec merge cmp l1 l2 = + lazy ( + match force l1, force l2 with + | Cons (x1, ll1), Cons (x2, ll2) + -> let c = cmp x1 x2 in + if c = 0 + then Cons (x1, merge cmp ll1 ll2) + else if c < 0 + then Cons (x1, merge cmp ll1 l2) + else Cons (x2, merge cmp l1 ll2) + ) +;; + +let rec iter_interval f l (start, stop) = + if stop = 0 then () + else match force l with + | Cons (x, ll) + -> if start <= 0 then f x; + iter_interval f ll (start-1, stop-1) +;; + +let rec hamming = lazy (Cons (nn1, merge cmp ham2 (merge cmp ham3 ham5))) + and ham2 = lazy (force (map x2 hamming)) + and ham3 = lazy (force (map x3 hamming)) + and ham5 = lazy (force (map x5 hamming)) +;; + +iter_interval pr hamming (88000, 88100);; diff --git a/test/natdynlink/Makefile b/test/natdynlink/Makefile new file mode 100644 index 0000000..025ca5b --- /dev/null +++ b/test/natdynlink/Makefile @@ -0,0 +1,88 @@ +include ../../config/Makefile + +CAMLOPT=../../boot/ocamlrun ../../ocamlopt -thread +SUBCAMLOPT=../../../boot/ocamlrun ../../../ocamlopt +COMPFLAGS= +#SHARED=-shared -closed -S -dstartup +#SHARED=-shared + +PLUGINS=plugin.so plugin2.so sub/plugin.so sub/plugin3.so plugin4.so mypack.so packed1.so packed1_client.so pack_client.so plugin_ref.so plugin_high_arity.so plugin_ext.so plugin_simple.so bug.so plugin_thread.so plugin4_unix.so a.so b.so c.so + +all: $(PLUGINS) main mylib.so + +clean: + rm -f *.so *.o *.cm* main main_ext *.exe *.s *.asm *.obj + rm -f *.a *.lib + rm -f sub/*.so sub/*.o sub/*.cm* sub/*.s sub/*.asm sub/*.obj + +main: api.cmx main.cmx + $(CAMLOPT) -o main -linkall unix.cmxa threads.cmxa dynlink.cmxa api.cmx main.cmx $(PTHREAD_LINK) + +main_ext: api.cmx main.cmx factorial.$(O) + $(CAMLOPT) -o main_ext dynlink.cmxa api.cmx main.cmx factorial.$(O) + +sub/plugin3.cmx: sub/api.cmi sub/api.cmx sub/plugin3.ml + (cd sub; mv api.cmx api.cmx.bak; $(SUBCAMLOPT) -c $(COMPFLAGS) plugin3.ml; mv api.cmx.bak api.cmx) + +plugin2.cmx: api.cmx plugin.cmi plugin.cmx + (mv plugin.cmx plugin.cmx.bak; $(CAMLOPT) -c $(COMPFLAGS) plugin2.ml; mv plugin.cmx.bak plugin.cmx) + +sub/api.so: sub/api.cmi sub/api.ml + (cd sub; $(SUBCAMLOPT) -c $(COMPFLAGS) $(SHARED) api.ml) + +sub/api.cmi: sub/api.mli + (cd sub; $(SUBCAMLOPT) -c $(COMPFLAGS) api.mli) + +sub/api.cmx: sub/api.cmi sub/api.ml + (cd sub; $(SUBCAMLOPT) -c $(COMPFLAGS) api.ml) + +plugin.cmx: api.cmx plugin.cmi +sub/plugin.cmx: api.cmx +plugin4.cmx: api.cmx +main.cmx: api.cmx +plugin_ext.cmx: api.cmx plugin_ext.ml + $(CAMLOPT) -c $(COMPFLAGS) plugin_ext.ml + +plugin_ext.so: factorial.$(O) plugin_ext.cmx + $(CAMLOPT) $(COMPFLAGS) -shared -o plugin_ext.so factorial.$(O) plugin_ext.cmx + +plugin4_unix.so: plugin4.cmx + $(CAMLOPT) -shared -o plugin4_unix.so unix.cmxa plugin4.cmx + +packed1_client.cmx: packed1.cmx + +pack_client.cmx: mypack.cmx + +packed1.cmx: api.cmx packed1.ml + $(CAMLOPT) -c $(COMPFLAGS) -for-pack Mypack packed1.ml + +mypack.cmx: packed1.cmx + $(CAMLOPT) $(COMPFLAGS) -S -pack -o mypack.cmx packed1.cmx + +mylib.cmxa: plugin.cmx plugin2.cmx + $(CAMLOPT) $(COMPFLAGS) -a -o mylib.cmxa plugin.cmx plugin2.cmx + +.SUFFIXES: .ml .mli .cmo .cmi .cmx .so .cmxa + +.mli.cmi: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) -c $(COMPFLAGS) $< + +.cmx.so: + $(CAMLOPT) -o $@ -shared $(COMPFLAGS) $< + +.cmxa.so: + $(CAMLOPT) -o $@ -shared -linkall $(COMPFLAGS) $< + +factorial.$(O): factorial.c + $(CAMLOPT) -c -ccopt "$(SHAREDCCCOMPOPTS)" factorial.c + +demo: all + ./main plugin_thread.so + +test_private: + $(CAMLOPT) -shared -o b.so a.ml b.ml + $(CAMLOPT) -shared -o c.so a.ml c.ml + ./main -b.so c.so diff --git a/test/natdynlink/a.ml b/test/natdynlink/a.ml new file mode 100755 index 0000000..b791582 --- /dev/null +++ b/test/natdynlink/a.ml @@ -0,0 +1,5 @@ +let x = ref 0 +let u = Random.int 1000 + +let () = + Printf.printf "A is running (%i)\n%!" u diff --git a/test/natdynlink/api.ml b/test/natdynlink/api.ml new file mode 100644 index 0000000..843a1c7 --- /dev/null +++ b/test/natdynlink/api.ml @@ -0,0 +1,18 @@ +let mods = ref [] + +let reg_mod name = + if List.mem name !mods then + Printf.printf "Reloading module %s\n" name + else ( + mods := name :: !mods; + Printf.printf "Registering module %s\n" name + ) + + +let cbs = ref [] + +let add_cb f = cbs := f :: !cbs +let runall () = List.iter (fun f -> f ()) !cbs + +let () = + at_exit runall diff --git a/test/natdynlink/b.ml b/test/natdynlink/b.ml new file mode 100755 index 0000000..58149e2 --- /dev/null +++ b/test/natdynlink/b.ml @@ -0,0 +1,5 @@ +let () = + print_endline "B is running"; + incr A.x; + Printf.printf "A.x = %i\n" !A.x + diff --git a/test/natdynlink/bug.ml b/test/natdynlink/bug.ml new file mode 100644 index 0000000..0282837 --- /dev/null +++ b/test/natdynlink/bug.ml @@ -0,0 +1,2 @@ +let () = try raise (Invalid_argument "X") with Invalid_argument s -> + raise (Invalid_argument (s ^ s)) diff --git a/test/natdynlink/c.ml b/test/natdynlink/c.ml new file mode 100755 index 0000000..d4de70f --- /dev/null +++ b/test/natdynlink/c.ml @@ -0,0 +1,4 @@ +let () = + print_endline "C is running"; + incr A.x; + Printf.printf "A.x = %i\n" !A.x diff --git a/test/natdynlink/factorial.c b/test/natdynlink/factorial.c new file mode 100644 index 0000000..c662333 --- /dev/null +++ b/test/natdynlink/factorial.c @@ -0,0 +1,18 @@ +#include "caml/mlvalues.h" +#include "caml/memory.h" +#include "caml/alloc.h" +#include <stdio.h> + +value factorial(value n){ + CAMLparam1(n); + CAMLlocal1(s); + + static char buf[256]; + int x = 1; + int i; + int m = Int_val(n); + for (i = 1; i <= m; i++) x *= i; + sprintf(buf,"%i",x); + s = copy_string(buf); + CAMLreturn (s); +} diff --git a/test/natdynlink/main.ml b/test/natdynlink/main.ml new file mode 100644 index 0000000..b21253f --- /dev/null +++ b/test/natdynlink/main.ml @@ -0,0 +1,20 @@ +let () = + Dynlink.init (); + Dynlink.allow_unsafe_modules true; + for i = 1 to Array.length Sys.argv - 1 do + let name = Sys.argv.(i) in + Printf.printf "Loading %s\n" name; flush stdout; + try + if name.[0] = '-' + then Dynlink.loadfile_private + (String.sub name 1 (String.length name - 1)) + else Dynlink.loadfile name + with + | Dynlink.Error err -> + Printf.printf "Dynlink error: %s\n" + (Dynlink.error_message err) + | exn -> + Printf.printf "Error: %s\n" (Printexc.to_string exn) + done + + diff --git a/test/natdynlink/pack_client.ml b/test/natdynlink/pack_client.ml new file mode 100644 index 0000000..9022988 --- /dev/null +++ b/test/natdynlink/pack_client.ml @@ -0,0 +1,2 @@ +let () = + print_endline Mypack.Packed1.mykey diff --git a/test/natdynlink/packed1.ml b/test/natdynlink/packed1.ml new file mode 100644 index 0000000..8f00e39 --- /dev/null +++ b/test/natdynlink/packed1.ml @@ -0,0 +1,6 @@ +let () = + Api.reg_mod "Packed1" + +let bla = Sys.argv.(0) ^ "XXX" +let mykey = Sys.argv.(0) + diff --git a/test/natdynlink/packed1_client.ml b/test/natdynlink/packed1_client.ml new file mode 100644 index 0000000..c62534f --- /dev/null +++ b/test/natdynlink/packed1_client.ml @@ -0,0 +1,3 @@ +let () = + Api.reg_mod "Packed1_client"; + print_endline Packed1.mykey diff --git a/test/natdynlink/plugin.ml b/test/natdynlink/plugin.ml new file mode 100644 index 0000000..501f1bf --- /dev/null +++ b/test/natdynlink/plugin.ml @@ -0,0 +1,10 @@ +let rec f x = ignore ([x]); f x + +let rec fact n = if n = 0 then 1 else n * fact (n - 1) + +let facts = [ fact 1; fact 2; fact 3; fact (Random.int 4) ] + +let () = + Api.reg_mod "Plugin"; + print_endline "COUCOU"; + () diff --git a/test/natdynlink/plugin.mli b/test/natdynlink/plugin.mli new file mode 100644 index 0000000..3e659d9 --- /dev/null +++ b/test/natdynlink/plugin.mli @@ -0,0 +1 @@ +val facts: int list diff --git a/test/natdynlink/plugin2.ml b/test/natdynlink/plugin2.ml new file mode 100644 index 0000000..daecace --- /dev/null +++ b/test/natdynlink/plugin2.ml @@ -0,0 +1,8 @@ +(*external ex: int -> int = "caml_ex"*) + +let () = + Api.reg_mod "Plugin2"; +(* let i = ex 3 in*) + List.iter (fun i -> Printf.printf "%i\n" i) Plugin.facts; + Printf.printf "XXX\n"; + raise Exit diff --git a/test/natdynlink/plugin4.ml b/test/natdynlink/plugin4.ml new file mode 100644 index 0000000..ccf4642 --- /dev/null +++ b/test/natdynlink/plugin4.ml @@ -0,0 +1,5 @@ +let () = + Printf.printf "time = %f\n" (Unix.time ()); + Api.reg_mod "Plugin" + + diff --git a/test/natdynlink/plugin_ext.ml b/test/natdynlink/plugin_ext.ml new file mode 100644 index 0000000..9906769 --- /dev/null +++ b/test/natdynlink/plugin_ext.ml @@ -0,0 +1,5 @@ +external fact: int -> string = "factorial" + +let () = + Api.reg_mod "plugin_ext"; + Printf.printf "fact 10 = %s\n" (fact 10) diff --git a/test/natdynlink/plugin_high_arity.ml b/test/natdynlink/plugin_high_arity.ml new file mode 100644 index 0000000..8c58aa1 --- /dev/null +++ b/test/natdynlink/plugin_high_arity.ml @@ -0,0 +1,6 @@ +let f x x x x x x x x x x x x x = () + +let g x = f x x x x x x x x + +let () = + Api.reg_mod "HA" diff --git a/test/natdynlink/plugin_ref.ml b/test/natdynlink/plugin_ref.ml new file mode 100644 index 0000000..0600124 --- /dev/null +++ b/test/natdynlink/plugin_ref.ml @@ -0,0 +1,11 @@ +let x = ref 0 + +let () = + Api.reg_mod "Plugin_ref"; + + Api.add_cb + (fun () -> + Printf.printf "current value for ref = %i\n" !x; + incr x + ) + diff --git a/test/natdynlink/plugin_simple.ml b/test/natdynlink/plugin_simple.ml new file mode 100644 index 0000000..dd7d022 --- /dev/null +++ b/test/natdynlink/plugin_simple.ml @@ -0,0 +1,3 @@ +let facts = [ (Random.int 4) ] + +let () = print_endline "COUCOU"; print_char '\n' diff --git a/test/natdynlink/plugin_thread.ml b/test/natdynlink/plugin_thread.ml new file mode 100644 index 0000000..5635054 --- /dev/null +++ b/test/natdynlink/plugin_thread.ml @@ -0,0 +1,21 @@ +let () = + Api.reg_mod "Plugin_thread"; + let _t = + Thread.create + (fun () -> + for i = 1 to 5 do + print_endline "Thread 1"; flush stdout; + Thread.delay 1.; + done + ) () + in + for i = 1 to 10 do + print_endline "Thread 2"; flush stdout; + Thread.delay 0.50; + done + + + + + + diff --git a/test/natdynlink/sub/api.ml b/test/natdynlink/sub/api.ml new file mode 100644 index 0000000..4a60586 --- /dev/null +++ b/test/natdynlink/sub/api.ml @@ -0,0 +1,3 @@ +let f i = + Printf.printf "Sub/api: f called with %i\n" i; + i + 1 diff --git a/test/natdynlink/sub/api.mli b/test/natdynlink/sub/api.mli new file mode 100644 index 0000000..da5e52f --- /dev/null +++ b/test/natdynlink/sub/api.mli @@ -0,0 +1 @@ +val f : int -> int diff --git a/test/natdynlink/sub/plugin.ml b/test/natdynlink/sub/plugin.ml new file mode 100644 index 0000000..2a41493 --- /dev/null +++ b/test/natdynlink/sub/plugin.ml @@ -0,0 +1,7 @@ +let rec fact n = if n = 0 then 1 else n * fact (n - 1) + +let facts = [ fact 1; fact 2; fact 3; fact 4; fact 5 ] + +let () = + Api.reg_mod "Plugin'" + diff --git a/test/natdynlink/sub/plugin3.ml b/test/natdynlink/sub/plugin3.ml new file mode 100644 index 0000000..7b0b099 --- /dev/null +++ b/test/natdynlink/sub/plugin3.ml @@ -0,0 +1,3 @@ +let () = + ignore (Api.f 10) + diff --git a/test/nucleic.ml b/test/nucleic.ml new file mode 100644 index 0000000..d0228d1 --- /dev/null +++ b/test/nucleic.ml @@ -0,0 +1,3238 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: nucleic.ml,v 1.11 2005-08-12 09:22:04 xleroy Exp $ *) + +(* Use floating-point arithmetic *) + +external (+) : float -> float -> float = "%addfloat" +external (-) : float -> float -> float = "%subfloat" +external ( * ) : float -> float -> float = "%mulfloat" +external (/) : float -> float -> float = "%divfloat" + +(* -- MATH UTILITIES --------------------------------------------------------*) + +let constant_pi = 3.14159265358979323846 +let constant_minus_pi = -3.14159265358979323846 +let constant_pi2 = 1.57079632679489661923 +let constant_minus_pi2 = -1.57079632679489661923 + +(* -- POINTS ----------------------------------------------------------------*) + +type pt = { x : float; y : float; z : float } + +let +pt_sub p1 p2 + = { x = p1.x - p2.x; y = p1.y - p2.y; z = p1.z - p2.z } + +let +pt_dist p1 p2 + = let dx = p1.x - p2.x + and dy = p1.y - p2.y + and dz = p1.z - p2.z + in + sqrt ((dx * dx) + (dy * dy) + (dz * dz)) + +let +pt_phi p + = let b = atan2 p.x p.z + in + atan2 ((cos b) * p.z + (sin b) * p.x) p.y + +let +pt_theta p + = atan2 p.x p.z + +(* -- COORDINATE TRANSFORMATIONS --------------------------------------------*) + +(* + The notation for the transformations follows "Paul, R.P. (1981) Robot + Manipulators. MIT Press." with the exception that our transformation + matrices don't have the perspective terms and are the transpose of + Paul's one. See also "M\"antyl\"a, M. (1985) An Introduction to + Solid Modeling, Computer Science Press" Appendix A. + + The components of a transformation matrix are named like this: + + a b c + d e f + g h i + tx ty tz + + The components tx, ty, and tz are the translation vector. +*) + +type tfo = + {a: float; b: float; c: float; + d: float; e: float; f: float; + g: float; h: float; i: float; + tx: float; ty: float; tz: float} + +let tfo_id = + {a=1.0; b=0.0; c=0.0; + d=0.0; e=1.0; f=0.0; + g=0.0; h=0.0; i=1.0; + tx=0.0; ty=0.0; tz=0.0} + +(* + The function "tfo-apply" multiplies a transformation matrix, tfo, by a + point vector, p. The result is a new point. +*) + +let +tfo_apply t p + = { x = ((p.x * t.a) + (p.y * t.d) + (p.z * t.g) + t.tx); + y = ((p.x * t.b) + (p.y * t.e) + (p.z * t.h) + t.ty); + z = ((p.x * t.c) + (p.y * t.f) + (p.z * t.i) + t.tz) } + +(* + The function "tfo-combine" multiplies two transformation matrices A and B. + The result is a new matrix which cumulates the transformations described + by A and B. +*) + +let +tfo_combine a b = +(* <HAND_CSE> *) + (* Hand elimination of common subexpressions. + Assumes lots of float registers (32 is perfect, 16 still OK). + Loses on the I386, of course. *) + let a_a = a.a and a_b = a.b and a_c = a.c and a_d = a.d + and a_e = a.e and a_f = a.f and a_g = a.g and a_h = a.h + and a_i = a.i and a_tx = a.tx and a_ty = a.ty and a_tz = a.tz + and b_a = b.a and b_b = b.b and b_c = b.c and b_d = b.d + and b_e = b.e and b_f = b.f and b_g = b.g and b_h = b.h + and b_i = b.i and b_tx = b.tx and b_ty = b.ty and b_tz = b.tz in + { a = ((a_a * b_a) + (a_b * b_d) + (a_c * b_g)); + b = ((a_a * b_b) + (a_b * b_e) + (a_c * b_h)); + c = ((a_a * b_c) + (a_b * b_f) + (a_c * b_i)); + d = ((a_d * b_a) + (a_e * b_d) + (a_f * b_g)); + e = ((a_d * b_b) + (a_e * b_e) + (a_f * b_h)); + f = ((a_d * b_c) + (a_e * b_f) + (a_f * b_i)); + g = ((a_g * b_a) + (a_h * b_d) + (a_i * b_g)); + h = ((a_g * b_b) + (a_h * b_e) + (a_i * b_h)); + i = ((a_g * b_c) + (a_h * b_f) + (a_i * b_i)); + tx = ((a_tx * b_a) + (a_ty * b_d) + (a_tz * b_g) + b_tx); + ty = ((a_tx * b_b) + (a_ty * b_e) + (a_tz * b_h) + b_ty); + tz = ((a_tx * b_c) + (a_ty * b_f) + (a_tz * b_i) + b_tz) + } +(* </HAND_CSE> *) + (* Original without CSE *) +(* <NO_CSE> *) (*** + { a = ((a.a * b.a) + (a.b * b.d) + (a.c * b.g)); + b = ((a.a * b.b) + (a.b * b.e) + (a.c * b.h)); + c = ((a.a * b.c) + (a.b * b.f) + (a.c * b.i)); + d = ((a.d * b.a) + (a.e * b.d) + (a.f * b.g)); + e = ((a.d * b.b) + (a.e * b.e) + (a.f * b.h)); + f = ((a.d * b.c) + (a.e * b.f) + (a.f * b.i)); + g = ((a.g * b.a) + (a.h * b.d) + (a.i * b.g)); + h = ((a.g * b.b) + (a.h * b.e) + (a.i * b.h)); + i = ((a.g * b.c) + (a.h * b.f) + (a.i * b.i)); + tx = ((a.tx * b.a) + (a.ty * b.d) + (a.tz * b.g) + b.tx); + ty = ((a.tx * b.b) + (a.ty * b.e) + (a.tz * b.h) + b.ty); + tz = ((a.tx * b.c) + (a.ty * b.f) + (a.tz * b.i) + b.tz) + } + ***) (* </NO_CSE> *) + +(* + The function "tfo-inv-ortho" computes the inverse of a homogeneous + transformation matrix. +*) + +let +tfo_inv_ortho t = + { a = t.a; b = t.d; c = t.g; + d = t.b; e = t.e; f = t.h; + g = t.c; h = t.f; i = t.i; + tx = (-.((t.a * t.tx) + (t.b * t.ty) + (t.c * t.tz))); + ty = (-.((t.d * t.tx) + (t.e * t.ty) + (t.f * t.tz))); + tz = (-.((t.g * t.tx) + (t.h * t.ty) + (t.i * t.tz))) + } + +(* + Given three points p1, p2, and p3, the function "tfo-align" computes + a transformation matrix such that point p1 gets mapped to (0,0,0), p2 gets + mapped to the Y axis and p3 gets mapped to the YZ plane. +*) + +let +tfo_align p1 p2 p3 + = let x31 = p3.x - p1.x in + let y31 = p3.y - p1.y in + let z31 = p3.z - p1.z in + let rotpy = pt_sub p2 p1 in + let phi = pt_phi rotpy in + let theta = pt_theta rotpy in + let sinp = sin phi in + let sint = sin theta in + let cosp = cos phi in + let cost = cos theta in + let sinpsint = sinp * sint in + let sinpcost = sinp * cost in + let cospsint = cosp * sint in + let cospcost = cosp * cost in + let rotpz = + { x = ((cost * x31) - (sint * z31)); + y = ((sinpsint * x31) + (cosp * y31) + (sinpcost * z31)); + z = ((cospsint * x31) + (-.(sinp * y31)) + (cospcost * z31)) } in + let rho = pt_theta rotpz in + let cosr = cos rho in + let sinr = sin rho in + let x = (-.(p1.x * cost)) + (p1.z * sint) in + let y = ((-.(p1.x * sinpsint)) - (p1.y * cosp)) - (p1.z * sinpcost) in + let z = ((-.(p1.x * cospsint) + (p1.y * sinp))) - (p1.z * cospcost) in + { a = ((cost * cosr) - (cospsint * sinr)); + b = sinpsint; + c = ((cost * sinr) + (cospsint * cosr)); + d = (sinp * sinr); + e = cosp; + f = (-.(sinp * cosr)); + g = ((-.(sint * cosr)) - (cospcost * sinr)); + h = sinpcost; + i = ((-.(sint * sinr) + (cospcost * cosr))); + tx = ((x * cosr) - (z * sinr)); + ty = y; + tz = ((x * sinr + (z * cosr))) + } + +(* -- NUCLEIC ACID CONFORMATIONS DATA BASE ----------------------------------*) + +(* + Numbering of atoms follows the paper: + + IUPAC-IUB Joint Commission on Biochemical Nomenclature (JCBN) + (1983) Abbreviations and Symbols for the Description of + Conformations of Polynucleotide Chains. Eur. J. Biochem 131, + 9-15. +*) + +(* Define remaining atoms for each nucleotide type. *) + +type nuc_specific = + A of pt*pt*pt*pt*pt*pt*pt*pt +| C of pt*pt*pt*pt*pt*pt +| G of pt*pt*pt*pt*pt*pt*pt*pt*pt +| U of pt*pt*pt*pt*pt + +(* + A n6 n7 n9 c8 h2 h61 h62 h8 + C n4 o2 h41 h42 h5 h6 + G n2 n7 n9 c8 o6 h1 h21 h22 h8 + U o2 o4 h3 h5 h6 +*) + +(* Define part common to all 4 nucleotide types. *) + +type nuc = + N of tfo*tfo*tfo*tfo* + pt*pt*pt*pt*pt*pt*pt*pt*pt*pt*pt*pt* + pt*pt*pt*pt*pt*pt*pt*pt*pt*pt*pt*pt* + pt*nuc_specific + +(* + dgf_base_tfo ; defines the standard position for wc and wc_dumas + p_o3'_275_tfo ; defines the standard position for the connect function + p_o3'_180_tfo + p_o3'_60_tfo + p o1p o2p o5' c5' h5' h5'' c4' h4' o4' c1' h1' c2' h2'' o2' h2' c3' + h3' o3' n1 n3 c2 c4 c5 c6 +*) + +let is_A = function + N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,A(_,_,_,_,_,_,_,_)) -> true + | _ -> false + +let is_C = function + N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,C(_,_,_,_,_,_)) -> true + | _ -> false + +let is_G = function + N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,G(_,_,_,_,_,_,_,_,_)) -> true + | _ -> false + +let +nuc_C1' +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = c1' + +let +nuc_C2 +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = c2 + +let +nuc_C3' +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = c3' + +let +nuc_C4 +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = c4 + +let +nuc_C4' +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = c4' + +let +nuc_N1 +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = n1 + +let +nuc_O3' +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = o3' + +let +nuc_P +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = p + +let +nuc_dgf_base_tfo +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = dgf_base_tfo + +let +nuc_p_o3'_180_tfo +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = p_o3'_180_tfo + +let +nuc_p_o3'_275_tfo +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = p_o3'_275_tfo + +let +nuc_p_o3'_60_tfo +(N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,_)) + = p_o3'_60_tfo + +let +rA_N9 = function +| (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,A (n6,n7,n9,c8,h2,h61,h62,h8))) -> n9 +| _ -> assert false + + +let +rG_N9 = function +| (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6,G (n2,n7,n9,c8,o6,h1,h21,h22,h8))) -> n9 +| _ -> assert false + +(* Database of nucleotide conformations: *) + +let rA + = N( + { a= -0.0018; b= -0.8207; c=0.5714; (* dgf_base_tfo *) + d=0.2679; e= -0.5509; f= -0.7904; + g=0.9634; h=0.1517; i=0.2209; + tx=0.0073; ty=8.4030; tz=0.6232 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4550; y = 8.2120; z = -2.8810 }, (* C5' *) + { x = 5.4546; y = 8.8508; z = -1.9978 }, (* H5' *) + { x = 5.7588; y = 8.6625; z = -3.8259 }, (* H5'' *) + { x = 6.4970; y = 7.1480; z = -2.5980 }, (* C4' *) + { x = 7.4896; y = 7.5919; z = -2.5214 }, (* H4' *) + { x = 6.1630; y = 6.4860; z = -1.3440 }, (* O4' *) + { x = 6.5400; y = 5.1200; z = -1.4190 }, (* C1' *) + { x = 7.2763; y = 4.9681; z = -0.6297 }, (* H1' *) + { x = 7.1940; y = 4.8830; z = -2.7770 }, (* C2' *) + { x = 6.8667; y = 3.9183; z = -3.1647 }, (* H2'' *) + { x = 8.5860; y = 5.0910; z = -2.6140 }, (* O2' *) + { x = 8.9510; y = 4.7626; z = -1.7890 }, (* H2' *) + { x = 6.5720; y = 6.0040; z = -3.6090 }, (* C3' *) + { x = 5.5636; y = 5.7066; z = -3.8966 }, (* H3' *) + { x = 7.3801; y = 6.3562; z = -4.7350 }, (* O3' *) + { x = 4.7150; y = 0.4910; z = -0.1360 }, (* N1 *) + { x = 6.3490; y = 2.1730; z = -0.6020 }, (* N3 *) + { x = 5.9530; y = 0.9650; z = -0.2670 }, (* C2 *) + { x = 5.2900; y = 2.9790; z = -0.8260 }, (* C4 *) + { x = 3.9720; y = 2.6390; z = -0.7330 }, (* C5 *) + { x = 3.6770; y = 1.3160; z = -0.3660 }, (* C6 *) + (A ( + { x = 2.4280; y = 0.8450; z = -0.2360 }, (* N6 *) + { x = 3.1660; y = 3.7290; z = -1.0360 }, (* N7 *) + { x = 5.3170; y = 4.2990; z = -1.1930 }, (* N9 *) + { x = 4.0100; y = 4.6780; z = -1.2990 }, (* C8 *) + { x = 6.6890; y = 0.1903; z = -0.0518 }, (* H2 *) + { x = 1.6470; y = 1.4460; z = -0.4040 }, (* H61 *) + { x = 2.2780; y = -0.1080; z = -0.0280 }, (* H62 *) + { x = 3.4421; y = 5.5744; z = -1.5482 }) (* H8 *) + ) + ) + +let rA01 + = N( + { a= -0.0043; b= -0.8175; c=0.5759; (* dgf_base_tfo *) + d=0.2617; e= -0.5567; f= -0.7884; + g=0.9651; h=0.1473; i=0.2164; + tx=0.0359; ty=8.3929; tz=0.5532 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4352; y = 8.2183; z = -2.7757 }, (* C5' *) + { x = 5.3830; y = 8.7883; z = -1.8481 }, (* H5' *) + { x = 5.7729; y = 8.7436; z = -3.6691 }, (* H5'' *) + { x = 6.4830; y = 7.1518; z = -2.5252 }, (* C4' *) + { x = 7.4749; y = 7.5972; z = -2.4482 }, (* H4' *) + { x = 6.1626; y = 6.4620; z = -1.2827 }, (* O4' *) + { x = 6.5431; y = 5.0992; z = -1.3905 }, (* C1' *) + { x = 7.2871; y = 4.9328; z = -0.6114 }, (* H1' *) + { x = 7.1852; y = 4.8935; z = -2.7592 }, (* C2' *) + { x = 6.8573; y = 3.9363; z = -3.1645 }, (* H2'' *) + { x = 8.5780; y = 5.1025; z = -2.6046 }, (* O2' *) + { x = 8.9516; y = 4.7577; z = -1.7902 }, (* H2' *) + { x = 6.5522; y = 6.0300; z = -3.5612 }, (* C3' *) + { x = 5.5420; y = 5.7356; z = -3.8459 }, (* H3' *) + { x = 7.3487; y = 6.4089; z = -4.6867 }, (* O3' *) + { x = 4.7442; y = 0.4514; z = -0.1390 }, (* N1 *) + { x = 6.3687; y = 2.1459; z = -0.5926 }, (* N3 *) + { x = 5.9795; y = 0.9335; z = -0.2657 }, (* C2 *) + { x = 5.3052; y = 2.9471; z = -0.8125 }, (* C4 *) + { x = 3.9891; y = 2.5987; z = -0.7230 }, (* C5 *) + { x = 3.7016; y = 1.2717; z = -0.3647 }, (* C6 *) + (A ( + { x = 2.4553; y = 0.7925; z = -0.2390 }, (* N6 *) + { x = 3.1770; y = 3.6859; z = -1.0198 }, (* N7 *) + { x = 5.3247; y = 4.2695; z = -1.1710 }, (* N9 *) + { x = 4.0156; y = 4.6415; z = -1.2759 }, (* C8 *) + { x = 6.7198; y = 0.1618; z = -0.0547 }, (* H2 *) + { x = 1.6709; y = 1.3900; z = -0.4039 }, (* H61 *) + { x = 2.3107; y = -0.1627; z = -0.0373 }, (* H62 *) + { x = 3.4426; y = 5.5361; z = -1.5199 }) (* H8 *) + ) + ) + +let rA02 + = N( + { a=0.5566; b=0.0449; c=0.8296; (* dgf_base_tfo *) + d=0.5125; e=0.7673; f= -0.3854; + g= -0.6538; h=0.6397; i=0.4041; + tx= -9.1161; ty= -3.7679; tz= -2.9968 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.5778; y = 6.6594; z = -4.0364 }, (* C5' *) + { x = 4.9220; y = 7.1963; z = -4.9204 }, (* H5' *) + { x = 3.7996; y = 5.9091; z = -4.1764 }, (* H5'' *) + { x = 5.7873; y = 5.8869; z = -3.5482 }, (* C4' *) + { x = 6.0405; y = 5.0875; z = -4.2446 }, (* H4' *) + { x = 6.9135; y = 6.8036; z = -3.4310 }, (* O4' *) + { x = 7.7293; y = 6.4084; z = -2.3392 }, (* C1' *) + { x = 8.7078; y = 6.1815; z = -2.7624 }, (* H1' *) + { x = 7.1305; y = 5.1418; z = -1.7347 }, (* C2' *) + { x = 7.2040; y = 5.1982; z = -0.6486 }, (* H2'' *) + { x = 7.7417; y = 4.0392; z = -2.3813 }, (* O2' *) + { x = 8.6785; y = 4.1443; z = -2.5630 }, (* H2' *) + { x = 5.6666; y = 5.2728; z = -2.1536 }, (* C3' *) + { x = 5.1747; y = 5.9805; z = -1.4863 }, (* H3' *) + { x = 4.9997; y = 4.0086; z = -2.1973 }, (* O3' *) + { x = 10.3245; y = 8.5459; z = 1.5467 }, (* N1 *) + { x = 9.8051; y = 6.9432; z = -0.1497 }, (* N3 *) + { x = 10.5175; y = 7.4328; z = 0.8408 }, (* C2 *) + { x = 8.7523; y = 7.7422; z = -0.4228 }, (* C4 *) + { x = 8.4257; y = 8.9060; z = 0.2099 }, (* C5 *) + { x = 9.2665; y = 9.3242; z = 1.2540 }, (* C6 *) + (A ( + { x = 9.0664; y = 10.4462; z = 1.9610 }, (* N6 *) + { x = 7.2750; y = 9.4537; z = -0.3428 }, (* N7 *) + { x = 7.7962; y = 7.5519; z = -1.3859 }, (* N9 *) + { x = 6.9479; y = 8.6157; z = -1.2771 }, (* C8 *) + { x = 11.4063; y = 6.9047; z = 1.1859 }, (* H2 *) + { x = 8.2845; y = 11.0341; z = 1.7552 }, (* H61 *) + { x = 9.6584; y = 10.6647; z = 2.7198 }, (* H62 *) + { x = 6.0430; y = 8.9853; z = -1.7594 }) (* H8 *) + ) + ) +let rA03 + = N( + { a= -0.5021; b=0.0731; c=0.8617; (* dgf_base_tfo *) + d= -0.8112; e=0.3054; f= -0.4986; + g= -0.2996; h= -0.9494; i= -0.0940; + tx=6.4273; ty= -5.1944; tz= -3.7807 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.1214; y = 6.7116; z = -1.9049 }, (* C5' *) + { x = 3.3465; y = 5.9610; z = -2.0607 }, (* H5' *) + { x = 4.0789; y = 7.2928; z = -0.9837 }, (* H5'' *) + { x = 5.4170; y = 5.9293; z = -1.8186 }, (* C4' *) + { x = 5.4506; y = 5.3400; z = -0.9023 }, (* H4' *) + { x = 5.5067; y = 5.0417; z = -2.9703 }, (* O4' *) + { x = 6.8650; y = 4.9152; z = -3.3612 }, (* C1' *) + { x = 7.1090; y = 3.8577; z = -3.2603 }, (* H1' *) + { x = 7.7152; y = 5.7282; z = -2.3894 }, (* C2' *) + { x = 8.5029; y = 6.2356; z = -2.9463 }, (* H2'' *) + { x = 8.1036; y = 4.8568; z = -1.3419 }, (* O2' *) + { x = 8.3270; y = 3.9651; z = -1.6184 }, (* H2' *) + { x = 6.7003; y = 6.7565; z = -1.8911 }, (* C3' *) + { x = 6.5898; y = 7.5329; z = -2.6482 }, (* H3' *) + { x = 7.0505; y = 7.2878; z = -0.6105 }, (* O3' *) + { x = 9.6740; y = 4.7656; z = -7.6614 }, (* N1 *) + { x = 9.0739; y = 4.3013; z = -5.3941 }, (* N3 *) + { x = 9.8416; y = 4.2192; z = -6.4581 }, (* C2 *) + { x = 7.9885; y = 5.0632; z = -5.6446 }, (* C4 *) + { x = 7.6822; y = 5.6856; z = -6.8194 }, (* C5 *) + { x = 8.5831; y = 5.5215; z = -7.8840 }, (* C6 *) + (A ( + { x = 8.4084; y = 6.0747; z = -9.0933 }, (* N6 *) + { x = 6.4857; y = 6.3816; z = -6.7035 }, (* N7 *) + { x = 6.9740; y = 5.3703; z = -4.7760 }, (* N9 *) + { x = 6.1133; y = 6.1613; z = -5.4808 }, (* C8 *) + { x = 10.7627; y = 3.6375; z = -6.4220 }, (* H2 *) + { x = 7.6031; y = 6.6390; z = -9.2733 }, (* H61 *) + { x = 9.1004; y = 5.9708; z = -9.7893 }, (* H62 *) + { x = 5.1705; y = 6.6830; z = -5.3167 }) (* H8 *) + ) + ) + +let rA04 + = N( + { a= -0.5426; b= -0.8175; c=0.1929; (* dgf_base_tfo *) + d=0.8304; e= -0.5567; f= -0.0237; + g=0.1267; h=0.1473; i=0.9809; + tx= -0.5075; ty=8.3929; tz=0.2229 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4352; y = 8.2183; z = -2.7757 }, (* C5' *) + { x = 5.3830; y = 8.7883; z = -1.8481 }, (* H5' *) + { x = 5.7729; y = 8.7436; z = -3.6691 }, (* H5'' *) + { x = 6.4830; y = 7.1518; z = -2.5252 }, (* C4' *) + { x = 7.4749; y = 7.5972; z = -2.4482 }, (* H4' *) + { x = 6.1626; y = 6.4620; z = -1.2827 }, (* O4' *) + { x = 6.5431; y = 5.0992; z = -1.3905 }, (* C1' *) + { x = 7.2871; y = 4.9328; z = -0.6114 }, (* H1' *) + { x = 7.1852; y = 4.8935; z = -2.7592 }, (* C2' *) + { x = 6.8573; y = 3.9363; z = -3.1645 }, (* H2'' *) + { x = 8.5780; y = 5.1025; z = -2.6046 }, (* O2' *) + { x = 8.9516; y = 4.7577; z = -1.7902 }, (* H2' *) + { x = 6.5522; y = 6.0300; z = -3.5612 }, (* C3' *) + { x = 5.5420; y = 5.7356; z = -3.8459 }, (* H3' *) + { x = 7.3487; y = 6.4089; z = -4.6867 }, (* O3' *) + { x = 3.6343; y = 2.6680; z = 2.0783 }, (* N1 *) + { x = 5.4505; y = 3.9805; z = 1.2446 }, (* N3 *) + { x = 4.7540; y = 3.3816; z = 2.1851 }, (* C2 *) + { x = 4.8805; y = 3.7951; z = 0.0354 }, (* C4 *) + { x = 3.7416; y = 3.0925; z = -0.2305 }, (* C5 *) + { x = 3.0873; y = 2.4980; z = 0.8606 }, (* C6 *) + (A ( + { x = 1.9600; y = 1.7805; z = 0.7462 }, (* N6 *) + { x = 3.4605; y = 3.1184; z = -1.5906 }, (* N7 *) + { x = 5.3247; y = 4.2695; z = -1.1710 }, (* N9 *) + { x = 4.4244; y = 3.8244; z = -2.0953 }, (* C8 *) + { x = 5.0814; y = 3.4352; z = 3.2234 }, (* H2 *) + { x = 1.5423; y = 1.6454; z = -0.1520 }, (* H61 *) + { x = 1.5716; y = 1.3398; z = 1.5392 }, (* H62 *) + { x = 4.2675; y = 3.8876; z = -3.1721 }) (* H8 *) + ) + ) + +let rA05 + = N( + { a= -0.5891; b=0.0449; c=0.8068; (* dgf_base_tfo *) + d=0.5375; e=0.7673; f=0.3498; + g= -0.6034; h=0.6397; i= -0.4762; + tx= -0.3019; ty= -3.7679; tz= -9.5913 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.5778; y = 6.6594; z = -4.0364 }, (* C5' *) + { x = 4.9220; y = 7.1963; z = -4.9204 }, (* H5' *) + { x = 3.7996; y = 5.9091; z = -4.1764 }, (* H5'' *) + { x = 5.7873; y = 5.8869; z = -3.5482 }, (* C4' *) + { x = 6.0405; y = 5.0875; z = -4.2446 }, (* H4' *) + { x = 6.9135; y = 6.8036; z = -3.4310 }, (* O4' *) + { x = 7.7293; y = 6.4084; z = -2.3392 }, (* C1' *) + { x = 8.7078; y = 6.1815; z = -2.7624 }, (* H1' *) + { x = 7.1305; y = 5.1418; z = -1.7347 }, (* C2' *) + { x = 7.2040; y = 5.1982; z = -0.6486 }, (* H2'' *) + { x = 7.7417; y = 4.0392; z = -2.3813 }, (* O2' *) + { x = 8.6785; y = 4.1443; z = -2.5630 }, (* H2' *) + { x = 5.6666; y = 5.2728; z = -2.1536 }, (* C3' *) + { x = 5.1747; y = 5.9805; z = -1.4863 }, (* H3' *) + { x = 4.9997; y = 4.0086; z = -2.1973 }, (* O3' *) + { x = 10.2594; y = 10.6774; z = -1.0056 }, (* N1 *) + { x = 9.7528; y = 8.7080; z = -2.2631 }, (* N3 *) + { x = 10.4471; y = 9.7876; z = -1.9791 }, (* C2 *) + { x = 8.7271; y = 8.5575; z = -1.3991 }, (* C4 *) + { x = 8.4100; y = 9.3803; z = -0.3580 }, (* C5 *) + { x = 9.2294; y = 10.5030; z = -0.1574 }, (* C6 *) + (A ( + { x = 9.0349; y = 11.3951; z = 0.8250 }, (* N6 *) + { x = 7.2891; y = 8.9068; z = 0.3121 }, (* N7 *) + { x = 7.7962; y = 7.5519; z = -1.3859 }, (* N9 *) + { x = 6.9702; y = 7.8292; z = -0.3353 }, (* C8 *) + { x = 11.3132; y = 10.0537; z = -2.5851 }, (* H2 *) + { x = 8.2741; y = 11.2784; z = 1.4629 }, (* H61 *) + { x = 9.6733; y = 12.1368; z = 0.9529 }, (* H62 *) + { x = 6.0888; y = 7.3990; z = 0.1403 }) (* H8 *) + ) + ) + +let rA06 + = N( + { a= -0.9815; b=0.0731; c= -0.1772; (* dgf_base_tfo *) + d=0.1912; e=0.3054; f= -0.9328; + g= -0.0141; h= -0.9494; i= -0.3137; + tx=5.7506; ty= -5.1944; tz=4.7470 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.1214; y = 6.7116; z = -1.9049 }, (* C5' *) + { x = 3.3465; y = 5.9610; z = -2.0607 }, (* H5' *) + { x = 4.0789; y = 7.2928; z = -0.9837 }, (* H5'' *) + { x = 5.4170; y = 5.9293; z = -1.8186 }, (* C4' *) + { x = 5.4506; y = 5.3400; z = -0.9023 }, (* H4' *) + { x = 5.5067; y = 5.0417; z = -2.9703 }, (* O4' *) + { x = 6.8650; y = 4.9152; z = -3.3612 }, (* C1' *) + { x = 7.1090; y = 3.8577; z = -3.2603 }, (* H1' *) + { x = 7.7152; y = 5.7282; z = -2.3894 }, (* C2' *) + { x = 8.5029; y = 6.2356; z = -2.9463 }, (* H2'' *) + { x = 8.1036; y = 4.8568; z = -1.3419 }, (* O2' *) + { x = 8.3270; y = 3.9651; z = -1.6184 }, (* H2' *) + { x = 6.7003; y = 6.7565; z = -1.8911 }, (* C3' *) + { x = 6.5898; y = 7.5329; z = -2.6482 }, (* H3' *) + { x = 7.0505; y = 7.2878; z = -0.6105 }, (* O3' *) + { x = 6.6624; y = 3.5061; z = -8.2986 }, (* N1 *) + { x = 6.5810; y = 3.2570; z = -5.9221 }, (* N3 *) + { x = 6.5151; y = 2.8263; z = -7.1625 }, (* C2 *) + { x = 6.8364; y = 4.5817; z = -5.8882 }, (* C4 *) + { x = 7.0116; y = 5.4064; z = -6.9609 }, (* C5 *) + { x = 6.9173; y = 4.8260; z = -8.2361 }, (* C6 *) + (A ( + { x = 7.0668; y = 5.5163; z = -9.3763 }, (* N6 *) + { x = 7.2573; y = 6.7070; z = -6.5394 }, (* N7 *) + { x = 6.9740; y = 5.3703; z = -4.7760 }, (* N9 *) + { x = 7.2238; y = 6.6275; z = -5.2453 }, (* C8 *) + { x = 6.3146; y = 1.7741; z = -7.3641 }, (* H2 *) + { x = 7.2568; y = 6.4972; z = -9.3456 }, (* H61 *) + { x = 7.0437; y = 5.0478; z = -10.2446 }, (* H62 *) + { x = 7.4108; y = 7.6227; z = -4.8418 }) (* H8 *) + ) + ) + +let rA07 + = N( + { a=0.2379; b=0.1310; c= -0.9624; (* dgf_base_tfo *) + d= -0.5876; e= -0.7696; f= -0.2499; + g= -0.7734; h=0.6249; i= -0.1061; + tx=30.9870; ty= -26.9344; tz=42.6416 }, + { a=0.7529; b=0.1548; c=0.6397; (* P_O3'_275_tfo *) + d=0.2952; e= -0.9481; f= -0.1180; + g=0.5882; h=0.2777; i= -0.7595; + tx= -58.8919; ty= -11.3095; tz=6.0866 }, + { a= -0.0239; b=0.9667; c= -0.2546; (* P_O3'_180_tfo *) + d=0.9731; e= -0.0359; f= -0.2275; + g= -0.2290; h= -0.2532; i= -0.9399; + tx=3.5401; ty= -29.7913; tz=52.2796 }, + { a= -0.8912; b= -0.4531; c=0.0242; (* P_O3'_60_tfo *) + d= -0.1183; e=0.1805; f= -0.9764; + g=0.4380; h= -0.8730; i= -0.2145; + tx=19.9023; ty=54.8054; tz=15.2799 }, + { x = 41.8210; y = 8.3880; z = 43.5890 }, (* P *) + { x = 42.5400; y = 8.0450; z = 44.8330 }, (* O1P *) + { x = 42.2470; y = 9.6920; z = 42.9910 }, (* O2P *) + { x = 40.2550; y = 8.2030; z = 43.7340 }, (* O5' *) + { x = 39.3505; y = 8.4697; z = 42.6565 }, (* C5' *) + { x = 39.1377; y = 7.5433; z = 42.1230 }, (* H5' *) + { x = 39.7203; y = 9.3119; z = 42.0717 }, (* H5'' *) + { x = 38.0405; y = 8.9195; z = 43.2869 }, (* C4' *) + { x = 37.3687; y = 9.3036; z = 42.5193 }, (* H4' *) + { x = 37.4319; y = 7.8146; z = 43.9387 }, (* O4' *) + { x = 37.1959; y = 8.1354; z = 45.3237 }, (* C1' *) + { x = 36.1788; y = 8.5202; z = 45.3970 }, (* H1' *) + { x = 38.1721; y = 9.2328; z = 45.6504 }, (* C2' *) + { x = 39.1555; y = 8.7939; z = 45.8188 }, (* H2'' *) + { x = 37.7862; y = 10.0617; z = 46.7013 }, (* O2' *) + { x = 37.3087; y = 9.6229; z = 47.4092 }, (* H2' *) + { x = 38.1844; y = 10.0268; z = 44.3367 }, (* C3' *) + { x = 39.1578; y = 10.5054; z = 44.2289 }, (* H3' *) + { x = 37.0547; y = 10.9127; z = 44.3441 }, (* O3' *) + { x = 34.8811; y = 4.2072; z = 47.5784 }, (* N1 *) + { x = 35.1084; y = 6.1336; z = 46.1818 }, (* N3 *) + { x = 34.4108; y = 5.1360; z = 46.7207 }, (* C2 *) + { x = 36.3908; y = 6.1224; z = 46.6053 }, (* C4 *) + { x = 36.9819; y = 5.2334; z = 47.4697 }, (* C5 *) + { x = 36.1786; y = 4.1985; z = 48.0035 }, (* C6 *) + (A ( + { x = 36.6103; y = 3.2749; z = 48.8452 }, (* N6 *) + { x = 38.3236; y = 5.5522; z = 47.6595 }, (* N7 *) + { x = 37.3887; y = 7.0024; z = 46.2437 }, (* N9 *) + { x = 38.5055; y = 6.6096; z = 46.9057 }, (* C8 *) + { x = 33.3553; y = 5.0152; z = 46.4771 }, (* H2 *) + { x = 37.5730; y = 3.2804; z = 49.1507 }, (* H61 *) + { x = 35.9775; y = 2.5638; z = 49.1828 }, (* H62 *) + { x = 39.5461; y = 6.9184; z = 47.0041 }) (* H8 *) + ) + ) + +let rA08 + = N( + { a=0.1084; b= -0.0895; c= -0.9901; (* dgf_base_tfo *) + d=0.9789; e= -0.1638; f=0.1220; + g= -0.1731; h= -0.9824; i=0.0698; + tx= -2.9039; ty=47.2655; tz=33.0094 }, + { a=0.7529; b=0.1548; c=0.6397; (* P_O3'_275_tfo *) + d=0.2952; e= -0.9481; f= -0.1180; + g=0.5882; h=0.2777; i= -0.7595; + tx= -58.8919; ty= -11.3095; tz=6.0866 }, + { a= -0.0239; b=0.9667; c= -0.2546; (* P_O3'_180_tfo *) + d=0.9731; e= -0.0359; f= -0.2275; + g= -0.2290; h= -0.2532; i= -0.9399; + tx=3.5401; ty= -29.7913; tz=52.2796 }, + { a= -0.8912; b= -0.4531; c=0.0242; (* P_O3'_60_tfo *) + d= -0.1183; e=0.1805; f= -0.9764; + g=0.4380; h= -0.8730; i= -0.2145; + tx=19.9023; ty=54.8054; tz=15.2799 }, + { x = 41.8210; y = 8.3880; z = 43.5890 }, (* P *) + { x = 42.5400; y = 8.0450; z = 44.8330 }, (* O1P *) + { x = 42.2470; y = 9.6920; z = 42.9910 }, (* O2P *) + { x = 40.2550; y = 8.2030; z = 43.7340 }, (* O5' *) + { x = 39.4850; y = 8.9301; z = 44.6977 }, (* C5' *) + { x = 39.0638; y = 9.8199; z = 44.2296 }, (* H5' *) + { x = 40.0757; y = 9.0713; z = 45.6029 }, (* H5'' *) + { x = 38.3102; y = 8.0414; z = 45.0789 }, (* C4' *) + { x = 37.7842; y = 8.4637; z = 45.9351 }, (* H4' *) + { x = 37.4200; y = 7.9453; z = 43.9769 }, (* O4' *) + { x = 37.2249; y = 6.5609; z = 43.6273 }, (* C1' *) + { x = 36.3360; y = 6.2168; z = 44.1561 }, (* H1' *) + { x = 38.4347; y = 5.8414; z = 44.1590 }, (* C2' *) + { x = 39.2688; y = 5.9974; z = 43.4749 }, (* H2'' *) + { x = 38.2344; y = 4.4907; z = 44.4348 }, (* O2' *) + { x = 37.6374; y = 4.0386; z = 43.8341 }, (* H2' *) + { x = 38.6926; y = 6.6079; z = 45.4637 }, (* C3' *) + { x = 39.7585; y = 6.5640; z = 45.6877 }, (* H3' *) + { x = 37.8238; y = 6.0705; z = 46.4723 }, (* O3' *) + { x = 33.9162; y = 6.2598; z = 39.7758 }, (* N1 *) + { x = 34.6709; y = 6.5759; z = 42.0215 }, (* N3 *) + { x = 33.7257; y = 6.5186; z = 41.0858 }, (* C2 *) + { x = 35.8935; y = 6.3324; z = 41.5018 }, (* C4 *) + { x = 36.2105; y = 6.0601; z = 40.1932 }, (* C5 *) + { x = 35.1538; y = 6.0151; z = 39.2537 }, (* C6 *) + (A ( + { x = 35.3088; y = 5.7642; z = 37.9649 }, (* N6 *) + { x = 37.5818; y = 5.8677; z = 40.0507 }, (* N7 *) + { x = 37.0932; y = 6.3197; z = 42.1810 }, (* N9 *) + { x = 38.0509; y = 6.0354; z = 41.2635 }, (* C8 *) + { x = 32.6830; y = 6.6898; z = 41.3532 }, (* H2 *) + { x = 36.2305; y = 5.5855; z = 37.5925 }, (* H61 *) + { x = 34.5056; y = 5.7512; z = 37.3528 }, (* H62 *) + { x = 39.1318; y = 5.8993; z = 41.2285 }) (* H8 *) + ) + ) + +let rA09 + = N( + { a=0.8467; b=0.4166; c= -0.3311; (* dgf_base_tfo *) + d= -0.3962; e=0.9089; f=0.1303; + g=0.3552; h=0.0209; i=0.9346; + tx= -42.7319; ty= -26.6223; tz= -29.8163 }, + { a=0.7529; b=0.1548; c=0.6397; (* P_O3'_275_tfo *) + d=0.2952; e= -0.9481; f= -0.1180; + g=0.5882; h=0.2777; i= -0.7595; + tx= -58.8919; ty= -11.3095; tz=6.0866 }, + { a= -0.0239; b=0.9667; c= -0.2546; (* P_O3'_180_tfo *) + d=0.9731; e= -0.0359; f= -0.2275; + g= -0.2290; h= -0.2532; i= -0.9399; + tx=3.5401; ty= -29.7913; tz=52.2796 }, + { a= -0.8912; b= -0.4531; c=0.0242; (* P_O3'_60_tfo *) + d= -0.1183; e=0.1805; f= -0.9764; + g=0.4380; h= -0.8730; i= -0.2145; + tx=19.9023; ty=54.8054; tz=15.2799 }, + { x = 41.8210; y = 8.3880; z = 43.5890 }, (* P *) + { x = 42.5400; y = 8.0450; z = 44.8330 }, (* O1P *) + { x = 42.2470; y = 9.6920; z = 42.9910 }, (* O2P *) + { x = 40.2550; y = 8.2030; z = 43.7340 }, (* O5' *) + { x = 39.3505; y = 8.4697; z = 42.6565 }, (* C5' *) + { x = 39.1377; y = 7.5433; z = 42.1230 }, (* H5' *) + { x = 39.7203; y = 9.3119; z = 42.0717 }, (* H5'' *) + { x = 38.0405; y = 8.9195; z = 43.2869 }, (* C4' *) + { x = 37.6479; y = 8.1347; z = 43.9335 }, (* H4' *) + { x = 38.2691; y = 10.0933; z = 44.0524 }, (* O4' *) + { x = 37.3999; y = 11.1488; z = 43.5973 }, (* C1' *) + { x = 36.5061; y = 11.1221; z = 44.2206 }, (* H1' *) + { x = 37.0364; y = 10.7838; z = 42.1836 }, (* C2' *) + { x = 37.8636; y = 11.0489; z = 41.5252 }, (* H2'' *) + { x = 35.8275; y = 11.3133; z = 41.7379 }, (* O2' *) + { x = 35.6214; y = 12.1896; z = 42.0714 }, (* H2' *) + { x = 36.9316; y = 9.2556; z = 42.2837 }, (* C3' *) + { x = 37.1778; y = 8.8260; z = 41.3127 }, (* H3' *) + { x = 35.6285; y = 8.9334; z = 42.7926 }, (* O3' *) + { x = 38.1482; y = 15.2833; z = 46.4641 }, (* N1 *) + { x = 37.3641; y = 13.0968; z = 45.9007 }, (* N3 *) + { x = 37.5032; y = 14.1288; z = 46.7300 }, (* C2 *) + { x = 37.9570; y = 13.3377; z = 44.7113 }, (* C4 *) + { x = 38.6397; y = 14.4660; z = 44.3267 }, (* C5 *) + { x = 38.7473; y = 15.5229; z = 45.2609 }, (* C6 *) + (A ( + { x = 39.3720; y = 16.6649; z = 45.0297 }, (* N6 *) + { x = 39.1079; y = 14.3351; z = 43.0223 }, (* N7 *) + { x = 38.0132; y = 12.4868; z = 43.6280 }, (* N9 *) + { x = 38.7058; y = 13.1402; z = 42.6620 }, (* C8 *) + { x = 37.0731; y = 14.0857; z = 47.7306 }, (* H2 *) + { x = 39.8113; y = 16.8281; z = 44.1350 }, (* H61 *) + { x = 39.4100; y = 17.3741; z = 45.7478 }, (* H62 *) + { x = 39.0412; y = 12.9660; z = 41.6397 }) (* H8 *) + ) + ) + +let rA10 + = N( + { a=0.7063; b=0.6317; c= -0.3196; (* dgf_base_tfo *) + d= -0.0403; e= -0.4149; f= -0.9090; + g= -0.7068; h=0.6549; i= -0.2676; + tx=6.4402; ty= -52.1496; tz=30.8246 }, + { a=0.7529; b=0.1548; c=0.6397; (* P_O3'_275_tfo *) + d=0.2952; e= -0.9481; f= -0.1180; + g=0.5882; h=0.2777; i= -0.7595; + tx= -58.8919; ty= -11.3095; tz=6.0866 }, + { a= -0.0239; b=0.9667; c= -0.2546; (* P_O3'_180_tfo *) + d=0.9731; e= -0.0359; f= -0.2275; + g= -0.2290; h= -0.2532; i= -0.9399; + tx=3.5401; ty= -29.7913; tz=52.2796 }, + { a= -0.8912; b= -0.4531; c=0.0242; (* P_O3'_60_tfo *) + d= -0.1183; e=0.1805; f= -0.9764; + g=0.4380; h= -0.8730; i= -0.2145; + tx=19.9023; ty=54.8054; tz=15.2799 }, + { x = 41.8210; y = 8.3880; z = 43.5890 }, (* P *) + { x = 42.5400; y = 8.0450; z = 44.8330 }, (* O1P *) + { x = 42.2470; y = 9.6920; z = 42.9910 }, (* O2P *) + { x = 40.2550; y = 8.2030; z = 43.7340 }, (* O5' *) + { x = 39.4850; y = 8.9301; z = 44.6977 }, (* C5' *) + { x = 39.0638; y = 9.8199; z = 44.2296 }, (* H5' *) + { x = 40.0757; y = 9.0713; z = 45.6029 }, (* H5'' *) + { x = 38.3102; y = 8.0414; z = 45.0789 }, (* C4' *) + { x = 37.7099; y = 7.8166; z = 44.1973 }, (* H4' *) + { x = 38.8012; y = 6.8321; z = 45.6380 }, (* O4' *) + { x = 38.2431; y = 6.6413; z = 46.9529 }, (* C1' *) + { x = 37.3505; y = 6.0262; z = 46.8385 }, (* H1' *) + { x = 37.8484; y = 8.0156; z = 47.4214 }, (* C2' *) + { x = 38.7381; y = 8.5406; z = 47.7690 }, (* H2'' *) + { x = 36.8286; y = 8.0368; z = 48.3701 }, (* O2' *) + { x = 36.8392; y = 7.3063; z = 48.9929 }, (* H2' *) + { x = 37.3576; y = 8.6512; z = 46.1132 }, (* C3' *) + { x = 37.5207; y = 9.7275; z = 46.1671 }, (* H3' *) + { x = 35.9985; y = 8.2392; z = 45.9032 }, (* O3' *) + { x = 39.9117; y = 2.2278; z = 48.8527 }, (* N1 *) + { x = 38.6207; y = 3.6941; z = 47.4757 }, (* N3 *) + { x = 38.9872; y = 2.4888; z = 47.9057 }, (* C2 *) + { x = 39.2961; y = 4.6720; z = 48.1174 }, (* C4 *) + { x = 40.2546; y = 4.5307; z = 49.0912 }, (* C5 *) + { x = 40.5932; y = 3.2189; z = 49.4985 }, (* C6 *) + (A ( + { x = 41.4938; y = 2.9317; z = 50.4229 }, (* N6 *) + { x = 40.7195; y = 5.7755; z = 49.5060 }, (* N7 *) + { x = 39.1730; y = 6.0305; z = 47.9170 }, (* N9 *) + { x = 40.0413; y = 6.6250; z = 48.7728 }, (* C8 *) + { x = 38.5257; y = 1.5960; z = 47.4838 }, (* H2 *) + { x = 41.9907; y = 3.6753; z = 50.8921 }, (* H61 *) + { x = 41.6848; y = 1.9687; z = 50.6599 }, (* H62 *) + { x = 40.3571; y = 7.6321; z = 49.0452 }) (* H8 *) + ) + ) + +let rAs = [rA01;rA02;rA03;rA04;rA05;rA06;rA07;rA08;rA09;rA10] + +let rC + = N( + { a= -0.0359; b= -0.8071; c=0.5894; (* dgf_base_tfo *) + d= -0.2669; e=0.5761; f=0.7726; + g= -0.9631; h= -0.1296; i= -0.2361; + tx=0.1584; ty=8.3434; tz=0.5434 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2430; y = -8.2420; z = 2.8260 }, (* C5' *) + { x = 5.1974; y = -8.8497; z = 1.9223 }, (* H5' *) + { x = 5.5548; y = -8.7348; z = 3.7469 }, (* H5'' *) + { x = 6.3140; y = -7.2060; z = 2.5510 }, (* C4' *) + { x = 7.2954; y = -7.6762; z = 2.4898 }, (* H4' *) + { x = 6.0140; y = -6.5420; z = 1.2890 }, (* O4' *) + { x = 6.4190; y = -5.1840; z = 1.3620 }, (* C1' *) + { x = 7.1608; y = -5.0495; z = 0.5747 }, (* H1' *) + { x = 7.0760; y = -4.9560; z = 2.7270 }, (* C2' *) + { x = 6.7770; y = -3.9803; z = 3.1099 }, (* H2'' *) + { x = 8.4500; y = -5.1930; z = 2.5810 }, (* O2' *) + { x = 8.8309; y = -4.8755; z = 1.7590 }, (* H2' *) + { x = 6.4060; y = -6.0590; z = 3.5580 }, (* C3' *) + { x = 5.4021; y = -5.7313; z = 3.8281 }, (* H3' *) + { x = 7.1570; y = -6.4240; z = 4.7070 }, (* O3' *) + { x = 5.2170; y = -4.3260; z = 1.1690 }, (* N1 *) + { x = 4.2960; y = -2.2560; z = 0.6290 }, (* N3 *) + { x = 5.4330; y = -3.0200; z = 0.7990 }, (* C2 *) + { x = 2.9930; y = -2.6780; z = 0.7940 }, (* C4 *) + { x = 2.8670; y = -4.0630; z = 1.1830 }, (* C5 *) + { x = 3.9570; y = -4.8300; z = 1.3550 }, (* C6 *) + (C ( + { x = 2.0187; y = -1.8047; z = 0.5874 }, (* N4 *) + { x = 6.5470; y = -2.5560; z = 0.6290 }, (* O2 *) + { x = 1.0684; y = -2.1236; z = 0.7109 }, (* H41 *) + { x = 2.2344; y = -0.8560; z = 0.3162 }, (* H42 *) + { x = 1.8797; y = -4.4972; z = 1.3404 }, (* H5 *) + { x = 3.8479; y = -5.8742; z = 1.6480 }) (* H6 *) + ) + ) + +let rC01 + = N( + { a= -0.0137; b= -0.8012; c=0.5983; (* dgf_base_tfo *) + d= -0.2523; e=0.5817; f=0.7733; + g= -0.9675; h= -0.1404; i= -0.2101; + tx=0.2031; ty=8.3874; tz=0.4228 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2416; y = -8.2422; z = 2.8181 }, (* C5' *) + { x = 5.2050; y = -8.8128; z = 1.8901 }, (* H5' *) + { x = 5.5368; y = -8.7738; z = 3.7227 }, (* H5'' *) + { x = 6.3232; y = -7.2037; z = 2.6002 }, (* C4' *) + { x = 7.3048; y = -7.6757; z = 2.5577 }, (* H4' *) + { x = 6.0635; y = -6.5092; z = 1.3456 }, (* O4' *) + { x = 6.4697; y = -5.1547; z = 1.4629 }, (* C1' *) + { x = 7.2354; y = -5.0043; z = 0.7018 }, (* H1' *) + { x = 7.0856; y = -4.9610; z = 2.8521 }, (* C2' *) + { x = 6.7777; y = -3.9935; z = 3.2487 }, (* H2'' *) + { x = 8.4627; y = -5.1992; z = 2.7423 }, (* O2' *) + { x = 8.8693; y = -4.8638; z = 1.9399 }, (* H2' *) + { x = 6.3877; y = -6.0809; z = 3.6362 }, (* C3' *) + { x = 5.3770; y = -5.7562; z = 3.8834 }, (* H3' *) + { x = 7.1024; y = -6.4754; z = 4.7985 }, (* O3' *) + { x = 5.2764; y = -4.2883; z = 1.2538 }, (* N1 *) + { x = 4.3777; y = -2.2062; z = 0.7229 }, (* N3 *) + { x = 5.5069; y = -2.9779; z = 0.9088 }, (* C2 *) + { x = 3.0693; y = -2.6246; z = 0.8500 }, (* C4 *) + { x = 2.9279; y = -4.0146; z = 1.2149 }, (* C5 *) + { x = 4.0101; y = -4.7892; z = 1.4017 }, (* C6 *) + (C ( + { x = 2.1040; y = -1.7437; z = 0.6331 }, (* N4 *) + { x = 6.6267; y = -2.5166; z = 0.7728 }, (* O2 *) + { x = 1.1496; y = -2.0600; z = 0.7287 }, (* H41 *) + { x = 2.3303; y = -0.7921; z = 0.3815 }, (* H42 *) + { x = 1.9353; y = -4.4465; z = 1.3419 }, (* H5 *) + { x = 3.8895; y = -5.8371; z = 1.6762 }) (* H6 *) + ) + ) + +let rC02 + = N( + { a=0.5141; b=0.0246; c=0.8574; (* dgf_base_tfo *) + d= -0.5547; e= -0.7529; f=0.3542; + g=0.6542; h= -0.6577; i= -0.3734; + tx= -9.1111; ty= -3.4598; tz= -3.2939 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 4.3825; y = -6.6585; z = 4.0489 }, (* C5' *) + { x = 4.6841; y = -7.2019; z = 4.9443 }, (* H5' *) + { x = 3.6189; y = -5.8889; z = 4.1625 }, (* H5'' *) + { x = 5.6255; y = -5.9175; z = 3.5998 }, (* C4' *) + { x = 5.8732; y = -5.1228; z = 4.3034 }, (* H4' *) + { x = 6.7337; y = -6.8605; z = 3.5222 }, (* O4' *) + { x = 7.5932; y = -6.4923; z = 2.4548 }, (* C1' *) + { x = 8.5661; y = -6.2983; z = 2.9064 }, (* H1' *) + { x = 7.0527; y = -5.2012; z = 1.8322 }, (* C2' *) + { x = 7.1627; y = -5.2525; z = 0.7490 }, (* H2'' *) + { x = 7.6666; y = -4.1249; z = 2.4880 }, (* O2' *) + { x = 8.5944; y = -4.2543; z = 2.6981 }, (* H2' *) + { x = 5.5661; y = -5.3029; z = 2.2009 }, (* C3' *) + { x = 5.0841; y = -6.0018; z = 1.5172 }, (* H3' *) + { x = 4.9062; y = -4.0452; z = 2.2042 }, (* O3' *) + { x = 7.6298; y = -7.6136; z = 1.4752 }, (* N1 *) + { x = 8.6945; y = -8.7046; z = -0.2857 }, (* N3 *) + { x = 8.6943; y = -7.6514; z = 0.6066 }, (* C2 *) + { x = 7.7426; y = -9.6987; z = -0.3801 }, (* C4 *) + { x = 6.6642; y = -9.5742; z = 0.5722 }, (* C5 *) + { x = 6.6391; y = -8.5592; z = 1.4526 }, (* C6 *) + (C ( + { x = 7.9033; y = -10.6371; z = -1.3010 }, (* N4 *) + { x = 9.5840; y = -6.8186; z = 0.6136 }, (* O2 *) + { x = 7.2009; y = -11.3604; z = -1.3619 }, (* H41 *) + { x = 8.7058; y = -10.6168; z = -1.9140 }, (* H42 *) + { x = 5.8585; y = -10.3083; z = 0.5822 }, (* H5 *) + { x = 5.8197; y = -8.4773; z = 2.1667 }) (* H6 *) + ) + ) + +let rC03 + = N( + { a= -0.4993; b=0.0476; c=0.8651; (* dgf_base_tfo *) + d=0.8078; e= -0.3353; f=0.4847; + g=0.3132; h=0.9409; i=0.1290; + tx=6.2989; ty= -5.2303; tz= -3.8577 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 3.9938; y = -6.7042; z = 1.9023 }, (* C5' *) + { x = 3.2332; y = -5.9343; z = 2.0319 }, (* H5' *) + { x = 3.9666; y = -7.2863; z = 0.9812 }, (* H5'' *) + { x = 5.3098; y = -5.9546; z = 1.8564 }, (* C4' *) + { x = 5.3863; y = -5.3702; z = 0.9395 }, (* H4' *) + { x = 5.3851; y = -5.0642; z = 3.0076 }, (* O4' *) + { x = 6.7315; y = -4.9724; z = 3.4462 }, (* C1' *) + { x = 7.0033; y = -3.9202; z = 3.3619 }, (* H1' *) + { x = 7.5997; y = -5.8018; z = 2.4948 }, (* C2' *) + { x = 8.3627; y = -6.3254; z = 3.0707 }, (* H2'' *) + { x = 8.0410; y = -4.9501; z = 1.4724 }, (* O2' *) + { x = 8.2781; y = -4.0644; z = 1.7570 }, (* H2' *) + { x = 6.5701; y = -6.8129; z = 1.9714 }, (* C3' *) + { x = 6.4186; y = -7.5809; z = 2.7299 }, (* H3' *) + { x = 6.9357; y = -7.3841; z = 0.7235 }, (* O3' *) + { x = 6.8024; y = -5.4718; z = 4.8475 }, (* N1 *) + { x = 7.9218; y = -5.5700; z = 6.8877 }, (* N3 *) + { x = 7.8908; y = -5.0886; z = 5.5944 }, (* C2 *) + { x = 6.9789; y = -6.3827; z = 7.4823 }, (* C4 *) + { x = 5.8742; y = -6.7319; z = 6.6202 }, (* C5 *) + { x = 5.8182; y = -6.2769; z = 5.3570 }, (* C6 *) + (C ( + { x = 7.1702; y = -6.7511; z = 8.7402 }, (* N4 *) + { x = 8.7747; y = -4.3728; z = 5.1568 }, (* O2 *) + { x = 6.4741; y = -7.3461; z = 9.1662 }, (* H41 *) + { x = 7.9889; y = -6.4396; z = 9.2429 }, (* H42 *) + { x = 5.0736; y = -7.3713; z = 6.9922 }, (* H5 *) + { x = 4.9784; y = -6.5473; z = 4.7170 }) (* H6 *) + ) + ) + +let rC04 + = N( + { a= -0.5669; b= -0.8012; c=0.1918; (* dgf_base_tfo *) + d= -0.8129; e=0.5817; f=0.0273; + g= -0.1334; h= -0.1404; i= -0.9811; + tx= -0.3279; ty=8.3874; tz=0.3355 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2416; y = -8.2422; z = 2.8181 }, (* C5' *) + { x = 5.2050; y = -8.8128; z = 1.8901 }, (* H5' *) + { x = 5.5368; y = -8.7738; z = 3.7227 }, (* H5'' *) + { x = 6.3232; y = -7.2037; z = 2.6002 }, (* C4' *) + { x = 7.3048; y = -7.6757; z = 2.5577 }, (* H4' *) + { x = 6.0635; y = -6.5092; z = 1.3456 }, (* O4' *) + { x = 6.4697; y = -5.1547; z = 1.4629 }, (* C1' *) + { x = 7.2354; y = -5.0043; z = 0.7018 }, (* H1' *) + { x = 7.0856; y = -4.9610; z = 2.8521 }, (* C2' *) + { x = 6.7777; y = -3.9935; z = 3.2487 }, (* H2'' *) + { x = 8.4627; y = -5.1992; z = 2.7423 }, (* O2' *) + { x = 8.8693; y = -4.8638; z = 1.9399 }, (* H2' *) + { x = 6.3877; y = -6.0809; z = 3.6362 }, (* C3' *) + { x = 5.3770; y = -5.7562; z = 3.8834 }, (* H3' *) + { x = 7.1024; y = -6.4754; z = 4.7985 }, (* O3' *) + { x = 5.2764; y = -4.2883; z = 1.2538 }, (* N1 *) + { x = 3.8961; y = -3.0896; z = -0.1893 }, (* N3 *) + { x = 5.0095; y = -3.8907; z = -0.0346 }, (* C2 *) + { x = 3.0480; y = -2.6632; z = 0.8116 }, (* C4 *) + { x = 3.4093; y = -3.1310; z = 2.1292 }, (* C5 *) + { x = 4.4878; y = -3.9124; z = 2.3088 }, (* C6 *) + (C ( + { x = 2.0216; y = -1.8941; z = 0.4804 }, (* N4 *) + { x = 5.7005; y = -4.2164; z = -0.9842 }, (* O2 *) + { x = 1.4067; y = -1.5873; z = 1.2205 }, (* H41 *) + { x = 1.8721; y = -1.6319; z = -0.4835 }, (* H42 *) + { x = 2.8048; y = -2.8507; z = 2.9918 }, (* H5 *) + { x = 4.7491; y = -4.2593; z = 3.3085 }) (* H6 *) + ) + ) + +let rC05 + = N( + { a= -0.6298; b=0.0246; c=0.7763; (* dgf_base_tfo *) + d= -0.5226; e= -0.7529; f= -0.4001; + g=0.5746; h= -0.6577; i=0.4870; + tx= -0.0208; ty= -3.4598; tz= -9.6882 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 4.3825; y = -6.6585; z = 4.0489 }, (* C5' *) + { x = 4.6841; y = -7.2019; z = 4.9443 }, (* H5' *) + { x = 3.6189; y = -5.8889; z = 4.1625 }, (* H5'' *) + { x = 5.6255; y = -5.9175; z = 3.5998 }, (* C4' *) + { x = 5.8732; y = -5.1228; z = 4.3034 }, (* H4' *) + { x = 6.7337; y = -6.8605; z = 3.5222 }, (* O4' *) + { x = 7.5932; y = -6.4923; z = 2.4548 }, (* C1' *) + { x = 8.5661; y = -6.2983; z = 2.9064 }, (* H1' *) + { x = 7.0527; y = -5.2012; z = 1.8322 }, (* C2' *) + { x = 7.1627; y = -5.2525; z = 0.7490 }, (* H2'' *) + { x = 7.6666; y = -4.1249; z = 2.4880 }, (* O2' *) + { x = 8.5944; y = -4.2543; z = 2.6981 }, (* H2' *) + { x = 5.5661; y = -5.3029; z = 2.2009 }, (* C3' *) + { x = 5.0841; y = -6.0018; z = 1.5172 }, (* H3' *) + { x = 4.9062; y = -4.0452; z = 2.2042 }, (* O3' *) + { x = 7.6298; y = -7.6136; z = 1.4752 }, (* N1 *) + { x = 8.5977; y = -9.5977; z = 0.7329 }, (* N3 *) + { x = 8.5951; y = -8.5745; z = 1.6594 }, (* C2 *) + { x = 7.7372; y = -9.7371; z = -0.3364 }, (* C4 *) + { x = 6.7596; y = -8.6801; z = -0.4476 }, (* C5 *) + { x = 6.7338; y = -7.6721; z = 0.4408 }, (* C6 *) + (C ( + { x = 7.8849; y = -10.7881; z = -1.1289 }, (* N4 *) + { x = 9.3993; y = -8.5377; z = 2.5743 }, (* O2 *) + { x = 7.2499; y = -10.8809; z = -1.9088 }, (* H41 *) + { x = 8.6122; y = -11.4649; z = -0.9468 }, (* H42 *) + { x = 6.0317; y = -8.6941; z = -1.2588 }, (* H5 *) + { x = 5.9901; y = -6.8809; z = 0.3459 }) (* H6 *) + ) + ) + +let rC06 + = N( + { a= -0.9837; b=0.0476; c= -0.1733; (* dgf_base_tfo *) + d= -0.1792; e= -0.3353; f=0.9249; + g= -0.0141; h=0.9409; i=0.3384; + tx=5.7793; ty= -5.2303; tz=4.5997 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 3.9938; y = -6.7042; z = 1.9023 }, (* C5' *) + { x = 3.2332; y = -5.9343; z = 2.0319 }, (* H5' *) + { x = 3.9666; y = -7.2863; z = 0.9812 }, (* H5'' *) + { x = 5.3098; y = -5.9546; z = 1.8564 }, (* C4' *) + { x = 5.3863; y = -5.3702; z = 0.9395 }, (* H4' *) + { x = 5.3851; y = -5.0642; z = 3.0076 }, (* O4' *) + { x = 6.7315; y = -4.9724; z = 3.4462 }, (* C1' *) + { x = 7.0033; y = -3.9202; z = 3.3619 }, (* H1' *) + { x = 7.5997; y = -5.8018; z = 2.4948 }, (* C2' *) + { x = 8.3627; y = -6.3254; z = 3.0707 }, (* H2'' *) + { x = 8.0410; y = -4.9501; z = 1.4724 }, (* O2' *) + { x = 8.2781; y = -4.0644; z = 1.7570 }, (* H2' *) + { x = 6.5701; y = -6.8129; z = 1.9714 }, (* C3' *) + { x = 6.4186; y = -7.5809; z = 2.7299 }, (* H3' *) + { x = 6.9357; y = -7.3841; z = 0.7235 }, (* O3' *) + { x = 6.8024; y = -5.4718; z = 4.8475 }, (* N1 *) + { x = 6.6920; y = -5.0495; z = 7.1354 }, (* N3 *) + { x = 6.6201; y = -4.5500; z = 5.8506 }, (* C2 *) + { x = 6.9254; y = -6.3614; z = 7.4926 }, (* C4 *) + { x = 7.1046; y = -7.2543; z = 6.3718 }, (* C5 *) + { x = 7.0391; y = -6.7951; z = 5.1106 }, (* C6 *) + (C ( + { x = 6.9614; y = -6.6648; z = 8.7815 }, (* N4 *) + { x = 6.4083; y = -3.3696; z = 5.6340 }, (* O2 *) + { x = 7.1329; y = -7.6280; z = 9.0324 }, (* H41 *) + { x = 6.8204; y = -5.9469; z = 9.4777 }, (* H42 *) + { x = 7.2954; y = -8.3135; z = 6.5440 }, (* H5 *) + { x = 7.1753; y = -7.4798; z = 4.2735 }) (* H6 *) + ) + ) + +let rC07 + = N( + { a=0.0033; b=0.2720; c= -0.9623; (* dgf_base_tfo *) + d=0.3013; e= -0.9179; f= -0.2584; + g= -0.9535; h= -0.2891; i= -0.0850; + tx=43.0403; ty=13.7233; tz=34.5710 }, + { a=0.9187; b=0.2887; c=0.2694; (* P_O3'_275_tfo *) + d=0.0302; e= -0.7316; f=0.6811; + g=0.3938; h= -0.6176; i= -0.6808; + tx= -48.4330; ty=26.3254; tz=13.6383 }, + { a= -0.1504; b=0.7744; c= -0.6145; (* P_O3'_180_tfo *) + d=0.7581; e=0.4893; f=0.4311; + g=0.6345; h= -0.4010; i= -0.6607; + tx= -31.9784; ty= -13.4285; tz=44.9650 }, + { a= -0.6236; b= -0.7810; c= -0.0337; (* P_O3'_60_tfo *) + d= -0.6890; e=0.5694; f= -0.4484; + g=0.3694; h= -0.2564; i= -0.8932; + tx=12.1105; ty=30.8774; tz=46.0946 }, + { x = 33.3400; y = 11.0980; z = 46.1750 }, (* P *) + { x = 34.5130; y = 10.2320; z = 46.4660 }, (* O1P *) + { x = 33.4130; y = 12.3960; z = 46.9340 }, (* O2P *) + { x = 31.9810; y = 10.3390; z = 46.4820 }, (* O5' *) + { x = 30.8152; y = 11.1619; z = 46.2003 }, (* C5' *) + { x = 30.4519; y = 10.9454; z = 45.1957 }, (* H5' *) + { x = 31.0379; y = 12.2016; z = 46.4400 }, (* H5'' *) + { x = 29.7081; y = 10.7448; z = 47.1428 }, (* C4' *) + { x = 28.8710; y = 11.4416; z = 47.0982 }, (* H4' *) + { x = 29.2550; y = 9.4394; z = 46.8162 }, (* O4' *) + { x = 29.3907; y = 8.5625; z = 47.9460 }, (* C1' *) + { x = 28.4416; y = 8.5669; z = 48.4819 }, (* H1' *) + { x = 30.4468; y = 9.2031; z = 48.7952 }, (* C2' *) + { x = 31.4222; y = 8.9651; z = 48.3709 }, (* H2'' *) + { x = 30.3701; y = 8.9157; z = 50.1624 }, (* O2' *) + { x = 30.0652; y = 8.0304; z = 50.3740 }, (* H2' *) + { x = 30.1622; y = 10.6879; z = 48.6120 }, (* C3' *) + { x = 31.0952; y = 11.2399; z = 48.7254 }, (* H3' *) + { x = 29.1076; y = 11.1535; z = 49.4702 }, (* O3' *) + { x = 29.7883; y = 7.2209; z = 47.5235 }, (* N1 *) + { x = 29.1825; y = 5.0438; z = 46.8275 }, (* N3 *) + { x = 28.8008; y = 6.2912; z = 47.2263 }, (* C2 *) + { x = 30.4888; y = 4.6890; z = 46.7186 }, (* C4 *) + { x = 31.5034; y = 5.6405; z = 47.0249 }, (* C5 *) + { x = 31.1091; y = 6.8691; z = 47.4156 }, (* C6 *) + (C ( + { x = 30.8109; y = 3.4584; z = 46.3336 }, (* N4 *) + { x = 27.6171; y = 6.5989; z = 47.3189 }, (* O2 *) + { x = 31.7923; y = 3.2301; z = 46.2638 }, (* H41 *) + { x = 30.0880; y = 2.7857; z = 46.1215 }, (* H42 *) + { x = 32.5542; y = 5.3634; z = 46.9395 }, (* H5 *) + { x = 31.8523; y = 7.6279; z = 47.6603 }) (* H6 *) + ) + ) + +let rC08 + = N( + { a=0.0797; b= -0.6026; c= -0.7941; (* dgf_base_tfo *) + d=0.7939; e=0.5201; f= -0.3150; + g=0.6028; h= -0.6054; i=0.5198; + tx= -36.8341; ty=41.5293; tz=1.6628 }, + { a=0.9187; b=0.2887; c=0.2694; (* P_O3'_275_tfo *) + d=0.0302; e= -0.7316; f=0.6811; + g=0.3938; h= -0.6176; i= -0.6808; + tx= -48.4330; ty=26.3254; tz=13.6383 }, + { a= -0.1504; b=0.7744; c= -0.6145; (* P_O3'_180_tfo *) + d=0.7581; e=0.4893; f=0.4311; + g=0.6345; h= -0.4010; i= -0.6607; + tx= -31.9784; ty= -13.4285; tz=44.9650 }, + { a= -0.6236; b= -0.7810; c= -0.0337; (* P_O3'_60_tfo *) + d= -0.6890; e=0.5694; f= -0.4484; + g=0.3694; h= -0.2564; i= -0.8932; + tx=12.1105; ty=30.8774; tz=46.0946 }, + { x = 33.3400; y = 11.0980; z = 46.1750 }, (* P *) + { x = 34.5130; y = 10.2320; z = 46.4660 }, (* O1P *) + { x = 33.4130; y = 12.3960; z = 46.9340 }, (* O2P *) + { x = 31.9810; y = 10.3390; z = 46.4820 }, (* O5' *) + { x = 31.8779; y = 9.9369; z = 47.8760 }, (* C5' *) + { x = 31.3239; y = 10.6931; z = 48.4322 }, (* H5' *) + { x = 32.8647; y = 9.6624; z = 48.2489 }, (* H5'' *) + { x = 31.0429; y = 8.6773; z = 47.9401 }, (* C4' *) + { x = 31.0779; y = 8.2331; z = 48.9349 }, (* H4' *) + { x = 29.6956; y = 8.9669; z = 47.5983 }, (* O4' *) + { x = 29.2784; y = 8.1700; z = 46.4782 }, (* C1' *) + { x = 28.8006; y = 7.2731; z = 46.8722 }, (* H1' *) + { x = 30.5544; y = 7.7940; z = 45.7875 }, (* C2' *) + { x = 30.8837; y = 8.6410; z = 45.1856 }, (* H2'' *) + { x = 30.5100; y = 6.6007; z = 45.0582 }, (* O2' *) + { x = 29.6694; y = 6.4168; z = 44.6326 }, (* H2' *) + { x = 31.5146; y = 7.5954; z = 46.9527 }, (* C3' *) + { x = 32.5255; y = 7.8261; z = 46.6166 }, (* H3' *) + { x = 31.3876; y = 6.2951; z = 47.5516 }, (* O3' *) + { x = 28.3976; y = 8.9302; z = 45.5933 }, (* N1 *) + { x = 26.2155; y = 9.6135; z = 44.9910 }, (* N3 *) + { x = 27.0281; y = 8.8961; z = 45.8192 }, (* C2 *) + { x = 26.7044; y = 10.3489; z = 43.9595 }, (* C4 *) + { x = 28.1088; y = 10.3837; z = 43.7247 }, (* C5 *) + { x = 28.8978; y = 9.6708; z = 44.5535 }, (* C6 *) + (C ( + { x = 25.8715; y = 11.0249; z = 43.1749 }, (* N4 *) + { x = 26.5733; y = 8.2371; z = 46.7484 }, (* O2 *) + { x = 26.2707; y = 11.5609; z = 42.4177 }, (* H41 *) + { x = 24.8760; y = 10.9939; z = 43.3427 }, (* H42 *) + { x = 28.5089; y = 10.9722; z = 42.8990 }, (* H5 *) + { x = 29.9782; y = 9.6687; z = 44.4097 }) (* H6 *) + ) + ) + +let rC09 + = N( + { a=0.8727; b=0.4760; c= -0.1091; (* dgf_base_tfo *) + d= -0.4188; e=0.6148; f= -0.6682; + g= -0.2510; h=0.6289; i=0.7359; + tx= -8.1687; ty= -52.0761; tz= -25.0726 }, + { a=0.9187; b=0.2887; c=0.2694; (* P_O3'_275_tfo *) + d=0.0302; e= -0.7316; f=0.6811; + g=0.3938; h= -0.6176; i= -0.6808; + tx= -48.4330; ty=26.3254; tz=13.6383 }, + { a= -0.1504; b=0.7744; c= -0.6145; (* P_O3'_180_tfo *) + d=0.7581; e=0.4893; f=0.4311; + g=0.6345; h= -0.4010; i= -0.6607; + tx= -31.9784; ty= -13.4285; tz=44.9650 }, + { a= -0.6236; b= -0.7810; c= -0.0337; (* P_O3'_60_tfo *) + d= -0.6890; e=0.5694; f= -0.4484; + g=0.3694; h= -0.2564; i= -0.8932; + tx=12.1105; ty=30.8774; tz=46.0946 }, + { x = 33.3400; y = 11.0980; z = 46.1750 }, (* P *) + { x = 34.5130; y = 10.2320; z = 46.4660 }, (* O1P *) + { x = 33.4130; y = 12.3960; z = 46.9340 }, (* O2P *) + { x = 31.9810; y = 10.3390; z = 46.4820 }, (* O5' *) + { x = 30.8152; y = 11.1619; z = 46.2003 }, (* C5' *) + { x = 30.4519; y = 10.9454; z = 45.1957 }, (* H5' *) + { x = 31.0379; y = 12.2016; z = 46.4400 }, (* H5'' *) + { x = 29.7081; y = 10.7448; z = 47.1428 }, (* C4' *) + { x = 29.4506; y = 9.6945; z = 47.0059 }, (* H4' *) + { x = 30.1045; y = 10.9634; z = 48.4885 }, (* O4' *) + { x = 29.1794; y = 11.8418; z = 49.1490 }, (* C1' *) + { x = 28.4388; y = 11.2210; z = 49.6533 }, (* H1' *) + { x = 28.5211; y = 12.6008; z = 48.0367 }, (* C2' *) + { x = 29.1947; y = 13.3949; z = 47.7147 }, (* H2'' *) + { x = 27.2316; y = 13.0683; z = 48.3134 }, (* O2' *) + { x = 27.0851; y = 13.3391; z = 49.2227 }, (* H2' *) + { x = 28.4131; y = 11.5507; z = 46.9391 }, (* C3' *) + { x = 28.4451; y = 12.0512; z = 45.9713 }, (* H3' *) + { x = 27.2707; y = 10.6955; z = 47.1097 }, (* O3' *) + { x = 29.8751; y = 12.7405; z = 50.0682 }, (* N1 *) + { x = 30.7172; y = 13.1841; z = 52.2328 }, (* N3 *) + { x = 30.0617; y = 12.3404; z = 51.3847 }, (* C2 *) + { x = 31.1834; y = 14.3941; z = 51.8297 }, (* C4 *) + { x = 30.9913; y = 14.8074; z = 50.4803 }, (* C5 *) + { x = 30.3434; y = 13.9610; z = 49.6548 }, (* C6 *) + (C ( + { x = 31.8090; y = 15.1847; z = 52.6957 }, (* N4 *) + { x = 29.6470; y = 11.2494; z = 51.7616 }, (* O2 *) + { x = 32.1422; y = 16.0774; z = 52.3606 }, (* H41 *) + { x = 31.9392; y = 14.8893; z = 53.6527 }, (* H42 *) + { x = 31.3632; y = 15.7771; z = 50.1491 }, (* H5 *) + { x = 30.1742; y = 14.2374; z = 48.6141 }) (* H6 *) + ) + ) + +let rC10 + = N( + { a=0.1549; b=0.8710; c= -0.4663; (* dgf_base_tfo *) + d=0.6768; e= -0.4374; f= -0.5921; + g= -0.7197; h= -0.2239; i= -0.6572; + tx=25.2447; ty= -14.1920; tz=50.3201 }, + { a=0.9187; b=0.2887; c=0.2694; (* P_O3'_275_tfo *) + d=0.0302; e= -0.7316; f=0.6811; + g=0.3938; h= -0.6176; i= -0.6808; + tx= -48.4330; ty=26.3254; tz=13.6383 }, + { a= -0.1504; b=0.7744; c= -0.6145; (* P_O3'_180_tfo *) + d=0.7581; e=0.4893; f=0.4311; + g=0.6345; h= -0.4010; i= -0.6607; + tx= -31.9784; ty= -13.4285; tz=44.9650 }, + { a= -0.6236; b= -0.7810; c= -0.0337; (* P_O3'_60_tfo *) + d= -0.6890; e=0.5694; f= -0.4484; + g=0.3694; h= -0.2564; i= -0.8932; + tx=12.1105; ty=30.8774; tz=46.0946 }, + { x = 33.3400; y = 11.0980; z = 46.1750 }, (* P *) + { x = 34.5130; y = 10.2320; z = 46.4660 }, (* O1P *) + { x = 33.4130; y = 12.3960; z = 46.9340 }, (* O2P *) + { x = 31.9810; y = 10.3390; z = 46.4820 }, (* O5' *) + { x = 31.8779; y = 9.9369; z = 47.8760 }, (* C5' *) + { x = 31.3239; y = 10.6931; z = 48.4322 }, (* H5' *) + { x = 32.8647; y = 9.6624; z = 48.2489 }, (* H5'' *) + { x = 31.0429; y = 8.6773; z = 47.9401 }, (* C4' *) + { x = 30.0440; y = 8.8473; z = 47.5383 }, (* H4' *) + { x = 31.6749; y = 7.6351; z = 47.2119 }, (* O4' *) + { x = 31.9159; y = 6.5022; z = 48.0616 }, (* C1' *) + { x = 31.0691; y = 5.8243; z = 47.9544 }, (* H1' *) + { x = 31.9300; y = 7.0685; z = 49.4493 }, (* C2' *) + { x = 32.9024; y = 7.5288; z = 49.6245 }, (* H2'' *) + { x = 31.5672; y = 6.1750; z = 50.4632 }, (* O2' *) + { x = 31.8416; y = 5.2663; z = 50.3200 }, (* H2' *) + { x = 30.8618; y = 8.1514; z = 49.3749 }, (* C3' *) + { x = 31.1122; y = 8.9396; z = 50.0850 }, (* H3' *) + { x = 29.5351; y = 7.6245; z = 49.5409 }, (* O3' *) + { x = 33.1890; y = 5.8629; z = 47.7343 }, (* N1 *) + { x = 34.4004; y = 4.2636; z = 46.4828 }, (* N3 *) + { x = 33.2062; y = 4.8497; z = 46.7851 }, (* C2 *) + { x = 35.5600; y = 4.6374; z = 47.0822 }, (* C4 *) + { x = 35.5444; y = 5.6751; z = 48.0577 }, (* C5 *) + { x = 34.3565; y = 6.2450; z = 48.3432 }, (* C6 *) + (C ( + { x = 36.6977; y = 4.0305; z = 46.7598 }, (* N4 *) + { x = 32.1661; y = 4.5034; z = 46.2348 }, (* O2 *) + { x = 37.5405; y = 4.3347; z = 47.2259 }, (* H41 *) + { x = 36.7033; y = 3.2923; z = 46.0706 }, (* H42 *) + { x = 36.4713; y = 5.9811; z = 48.5428 }, (* H5 *) + { x = 34.2986; y = 7.0426; z = 49.0839 }) (* H6 *) + ) + ) + +let rCs = [rC01;rC02;rC03;rC04;rC05;rC06;rC07;rC08;rC09;rC10] + +let rG + = N( + { a= -0.0018; b= -0.8207; c=0.5714; (* dgf_base_tfo *) + d=0.2679; e= -0.5509; f= -0.7904; + g=0.9634; h=0.1517; i=0.2209; + tx=0.0073; ty=8.4030; tz=0.6232 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4550; y = 8.2120; z = -2.8810 }, (* C5' *) + { x = 5.4546; y = 8.8508; z = -1.9978 }, (* H5' *) + { x = 5.7588; y = 8.6625; z = -3.8259 }, (* H5'' *) + { x = 6.4970; y = 7.1480; z = -2.5980 }, (* C4' *) + { x = 7.4896; y = 7.5919; z = -2.5214 }, (* H4' *) + { x = 6.1630; y = 6.4860; z = -1.3440 }, (* O4' *) + { x = 6.5400; y = 5.1200; z = -1.4190 }, (* C1' *) + { x = 7.2763; y = 4.9681; z = -0.6297 }, (* H1' *) + { x = 7.1940; y = 4.8830; z = -2.7770 }, (* C2' *) + { x = 6.8667; y = 3.9183; z = -3.1647 }, (* H2'' *) + { x = 8.5860; y = 5.0910; z = -2.6140 }, (* O2' *) + { x = 8.9510; y = 4.7626; z = -1.7890 }, (* H2' *) + { x = 6.5720; y = 6.0040; z = -3.6090 }, (* C3' *) + { x = 5.5636; y = 5.7066; z = -3.8966 }, (* H3' *) + { x = 7.3801; y = 6.3562; z = -4.7350 }, (* O3' *) + { x = 4.7150; y = 0.4910; z = -0.1360 }, (* N1 *) + { x = 6.3490; y = 2.1730; z = -0.6020 }, (* N3 *) + { x = 5.9530; y = 0.9650; z = -0.2670 }, (* C2 *) + { x = 5.2900; y = 2.9790; z = -0.8260 }, (* C4 *) + { x = 3.9720; y = 2.6390; z = -0.7330 }, (* C5 *) + { x = 3.6770; y = 1.3160; z = -0.3660 }, (* C6 *) + (G ( + { x = 6.8426; y = 0.0056; z = -0.0019 }, (* N2 *) + { x = 3.1660; y = 3.7290; z = -1.0360 }, (* N7 *) + { x = 5.3170; y = 4.2990; z = -1.1930 }, (* N9 *) + { x = 4.0100; y = 4.6780; z = -1.2990 }, (* C8 *) + { x = 2.4280; y = 0.8450; z = -0.2360 }, (* O6 *) + { x = 4.6151; y = -0.4677; z = 0.1305 }, (* H1 *) + { x = 6.6463; y = -0.9463; z = 0.2729 }, (* H21 *) + { x = 7.8170; y = 0.2642; z = -0.0640 }, (* H22 *) + { x = 3.4421; y = 5.5744; z = -1.5482 }) (* H8 *) + ) + ) + +let rG01 + = N( + { a= -0.0043; b= -0.8175; c=0.5759; (* dgf_base_tfo *) + d=0.2617; e= -0.5567; f= -0.7884; + g=0.9651; h=0.1473; i=0.2164; + tx=0.0359; ty=8.3929; tz=0.5532 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4352; y = 8.2183; z = -2.7757 }, (* C5' *) + { x = 5.3830; y = 8.7883; z = -1.8481 }, (* H5' *) + { x = 5.7729; y = 8.7436; z = -3.6691 }, (* H5'' *) + { x = 6.4830; y = 7.1518; z = -2.5252 }, (* C4' *) + { x = 7.4749; y = 7.5972; z = -2.4482 }, (* H4' *) + { x = 6.1626; y = 6.4620; z = -1.2827 }, (* O4' *) + { x = 6.5431; y = 5.0992; z = -1.3905 }, (* C1' *) + { x = 7.2871; y = 4.9328; z = -0.6114 }, (* H1' *) + { x = 7.1852; y = 4.8935; z = -2.7592 }, (* C2' *) + { x = 6.8573; y = 3.9363; z = -3.1645 }, (* H2'' *) + { x = 8.5780; y = 5.1025; z = -2.6046 }, (* O2' *) + { x = 8.9516; y = 4.7577; z = -1.7902 }, (* H2' *) + { x = 6.5522; y = 6.0300; z = -3.5612 }, (* C3' *) + { x = 5.5420; y = 5.7356; z = -3.8459 }, (* H3' *) + { x = 7.3487; y = 6.4089; z = -4.6867 }, (* O3' *) + { x = 4.7442; y = 0.4514; z = -0.1390 }, (* N1 *) + { x = 6.3687; y = 2.1459; z = -0.5926 }, (* N3 *) + { x = 5.9795; y = 0.9335; z = -0.2657 }, (* C2 *) + { x = 5.3052; y = 2.9471; z = -0.8125 }, (* C4 *) + { x = 3.9891; y = 2.5987; z = -0.7230 }, (* C5 *) + { x = 3.7016; y = 1.2717; z = -0.3647 }, (* C6 *) + (G ( + { x = 6.8745; y = -0.0224; z = -0.0058 }, (* N2 *) + { x = 3.1770; y = 3.6859; z = -1.0198 }, (* N7 *) + { x = 5.3247; y = 4.2695; z = -1.1710 }, (* N9 *) + { x = 4.0156; y = 4.6415; z = -1.2759 }, (* C8 *) + { x = 2.4553; y = 0.7925; z = -0.2390 }, (* O6 *) + { x = 4.6497; y = -0.5095; z = 0.1212 }, (* H1 *) + { x = 6.6836; y = -0.9771; z = 0.2627 }, (* H21 *) + { x = 7.8474; y = 0.2424; z = -0.0653 }, (* H22 *) + { x = 3.4426; y = 5.5361; z = -1.5199 }) (* H8 *) + ) + ) + +let rG02 + = N( + { a=0.5566; b=0.0449; c=0.8296; (* dgf_base_tfo *) + d=0.5125; e=0.7673; f= -0.3854; + g= -0.6538; h=0.6397; i=0.4041; + tx= -9.1161; ty= -3.7679; tz= -2.9968 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.5778; y = 6.6594; z = -4.0364 }, (* C5' *) + { x = 4.9220; y = 7.1963; z = -4.9204 }, (* H5' *) + { x = 3.7996; y = 5.9091; z = -4.1764 }, (* H5'' *) + { x = 5.7873; y = 5.8869; z = -3.5482 }, (* C4' *) + { x = 6.0405; y = 5.0875; z = -4.2446 }, (* H4' *) + { x = 6.9135; y = 6.8036; z = -3.4310 }, (* O4' *) + { x = 7.7293; y = 6.4084; z = -2.3392 }, (* C1' *) + { x = 8.7078; y = 6.1815; z = -2.7624 }, (* H1' *) + { x = 7.1305; y = 5.1418; z = -1.7347 }, (* C2' *) + { x = 7.2040; y = 5.1982; z = -0.6486 }, (* H2'' *) + { x = 7.7417; y = 4.0392; z = -2.3813 }, (* O2' *) + { x = 8.6785; y = 4.1443; z = -2.5630 }, (* H2' *) + { x = 5.6666; y = 5.2728; z = -2.1536 }, (* C3' *) + { x = 5.1747; y = 5.9805; z = -1.4863 }, (* H3' *) + { x = 4.9997; y = 4.0086; z = -2.1973 }, (* O3' *) + { x = 10.3245; y = 8.5459; z = 1.5467 }, (* N1 *) + { x = 9.8051; y = 6.9432; z = -0.1497 }, (* N3 *) + { x = 10.5175; y = 7.4328; z = 0.8408 }, (* C2 *) + { x = 8.7523; y = 7.7422; z = -0.4228 }, (* C4 *) + { x = 8.4257; y = 8.9060; z = 0.2099 }, (* C5 *) + { x = 9.2665; y = 9.3242; z = 1.2540 }, (* C6 *) + (G ( + { x = 11.6077; y = 6.7966; z = 1.2752 }, (* N2 *) + { x = 7.2750; y = 9.4537; z = -0.3428 }, (* N7 *) + { x = 7.7962; y = 7.5519; z = -1.3859 }, (* N9 *) + { x = 6.9479; y = 8.6157; z = -1.2771 }, (* C8 *) + { x = 9.0664; y = 10.4462; z = 1.9610 }, (* O6 *) + { x = 10.9838; y = 8.7524; z = 2.2697 }, (* H1 *) + { x = 12.2274; y = 7.0896; z = 2.0170 }, (* H21 *) + { x = 11.8502; y = 5.9398; z = 0.7984 }, (* H22 *) + { x = 6.0430; y = 8.9853; z = -1.7594 }) (* H8 *) + ) + ) + +let rG03 + = N( + { a= -0.5021; b=0.0731; c=0.8617; (* dgf_base_tfo *) + d= -0.8112; e=0.3054; f= -0.4986; + g= -0.2996; h= -0.9494; i= -0.0940; + tx=6.4273; ty= -5.1944; tz= -3.7807 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.1214; y = 6.7116; z = -1.9049 }, (* C5' *) + { x = 3.3465; y = 5.9610; z = -2.0607 }, (* H5' *) + { x = 4.0789; y = 7.2928; z = -0.9837 }, (* H5'' *) + { x = 5.4170; y = 5.9293; z = -1.8186 }, (* C4' *) + { x = 5.4506; y = 5.3400; z = -0.9023 }, (* H4' *) + { x = 5.5067; y = 5.0417; z = -2.9703 }, (* O4' *) + { x = 6.8650; y = 4.9152; z = -3.3612 }, (* C1' *) + { x = 7.1090; y = 3.8577; z = -3.2603 }, (* H1' *) + { x = 7.7152; y = 5.7282; z = -2.3894 }, (* C2' *) + { x = 8.5029; y = 6.2356; z = -2.9463 }, (* H2'' *) + { x = 8.1036; y = 4.8568; z = -1.3419 }, (* O2' *) + { x = 8.3270; y = 3.9651; z = -1.6184 }, (* H2' *) + { x = 6.7003; y = 6.7565; z = -1.8911 }, (* C3' *) + { x = 6.5898; y = 7.5329; z = -2.6482 }, (* H3' *) + { x = 7.0505; y = 7.2878; z = -0.6105 }, (* O3' *) + { x = 9.6740; y = 4.7656; z = -7.6614 }, (* N1 *) + { x = 9.0739; y = 4.3013; z = -5.3941 }, (* N3 *) + { x = 9.8416; y = 4.2192; z = -6.4581 }, (* C2 *) + { x = 7.9885; y = 5.0632; z = -5.6446 }, (* C4 *) + { x = 7.6822; y = 5.6856; z = -6.8194 }, (* C5 *) + { x = 8.5831; y = 5.5215; z = -7.8840 }, (* C6 *) + (G ( + { x = 10.9733; y = 3.5117; z = -6.4286 }, (* N2 *) + { x = 6.4857; y = 6.3816; z = -6.7035 }, (* N7 *) + { x = 6.9740; y = 5.3703; z = -4.7760 }, (* N9 *) + { x = 6.1133; y = 6.1613; z = -5.4808 }, (* C8 *) + { x = 8.4084; y = 6.0747; z = -9.0933 }, (* O6 *) + { x = 10.3759; y = 4.5855; z = -8.3504 }, (* H1 *) + { x = 11.6254; y = 3.3761; z = -7.1879 }, (* H21 *) + { x = 11.1917; y = 3.0460; z = -5.5593 }, (* H22 *) + { x = 5.1705; y = 6.6830; z = -5.3167 }) (* H8 *) + ) + ) + +let rG04 + = N( + { a= -0.5426; b= -0.8175; c=0.1929; (* dgf_base_tfo *) + d=0.8304; e= -0.5567; f= -0.0237; + g=0.1267; h=0.1473; i=0.9809; + tx= -0.5075; ty=8.3929; tz=0.2229 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 5.4352; y = 8.2183; z = -2.7757 }, (* C5' *) + { x = 5.3830; y = 8.7883; z = -1.8481 }, (* H5' *) + { x = 5.7729; y = 8.7436; z = -3.6691 }, (* H5'' *) + { x = 6.4830; y = 7.1518; z = -2.5252 }, (* C4' *) + { x = 7.4749; y = 7.5972; z = -2.4482 }, (* H4' *) + { x = 6.1626; y = 6.4620; z = -1.2827 }, (* O4' *) + { x = 6.5431; y = 5.0992; z = -1.3905 }, (* C1' *) + { x = 7.2871; y = 4.9328; z = -0.6114 }, (* H1' *) + { x = 7.1852; y = 4.8935; z = -2.7592 }, (* C2' *) + { x = 6.8573; y = 3.9363; z = -3.1645 }, (* H2'' *) + { x = 8.5780; y = 5.1025; z = -2.6046 }, (* O2' *) + { x = 8.9516; y = 4.7577; z = -1.7902 }, (* H2' *) + { x = 6.5522; y = 6.0300; z = -3.5612 }, (* C3' *) + { x = 5.5420; y = 5.7356; z = -3.8459 }, (* H3' *) + { x = 7.3487; y = 6.4089; z = -4.6867 }, (* O3' *) + { x = 3.6343; y = 2.6680; z = 2.0783 }, (* N1 *) + { x = 5.4505; y = 3.9805; z = 1.2446 }, (* N3 *) + { x = 4.7540; y = 3.3816; z = 2.1851 }, (* C2 *) + { x = 4.8805; y = 3.7951; z = 0.0354 }, (* C4 *) + { x = 3.7416; y = 3.0925; z = -0.2305 }, (* C5 *) + { x = 3.0873; y = 2.4980; z = 0.8606 }, (* C6 *) + (G ( + { x = 5.1433; y = 3.4373; z = 3.4609 }, (* N2 *) + { x = 3.4605; y = 3.1184; z = -1.5906 }, (* N7 *) + { x = 5.3247; y = 4.2695; z = -1.1710 }, (* N9 *) + { x = 4.4244; y = 3.8244; z = -2.0953 }, (* C8 *) + { x = 1.9600; y = 1.7805; z = 0.7462 }, (* O6 *) + { x = 3.2489; y = 2.2879; z = 2.9191 }, (* H1 *) + { x = 4.6785; y = 3.0243; z = 4.2568 }, (* H21 *) + { x = 5.9823; y = 3.9654; z = 3.6539 }, (* H22 *) + { x = 4.2675; y = 3.8876; z = -3.1721 }) (* H8 *) + ) + ) + +let rG05 + = N( + { a= -0.5891; b=0.0449; c=0.8068; (* dgf_base_tfo *) + d=0.5375; e=0.7673; f=0.3498; + g= -0.6034; h=0.6397; i= -0.4762; + tx= -0.3019; ty= -3.7679; tz= -9.5913 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.5778; y = 6.6594; z = -4.0364 }, (* C5' *) + { x = 4.9220; y = 7.1963; z = -4.9204 }, (* H5' *) + { x = 3.7996; y = 5.9091; z = -4.1764 }, (* H5'' *) + { x = 5.7873; y = 5.8869; z = -3.5482 }, (* C4' *) + { x = 6.0405; y = 5.0875; z = -4.2446 }, (* H4' *) + { x = 6.9135; y = 6.8036; z = -3.4310 }, (* O4' *) + { x = 7.7293; y = 6.4084; z = -2.3392 }, (* C1' *) + { x = 8.7078; y = 6.1815; z = -2.7624 }, (* H1' *) + { x = 7.1305; y = 5.1418; z = -1.7347 }, (* C2' *) + { x = 7.2040; y = 5.1982; z = -0.6486 }, (* H2'' *) + { x = 7.7417; y = 4.0392; z = -2.3813 }, (* O2' *) + { x = 8.6785; y = 4.1443; z = -2.5630 }, (* H2' *) + { x = 5.6666; y = 5.2728; z = -2.1536 }, (* C3' *) + { x = 5.1747; y = 5.9805; z = -1.4863 }, (* H3' *) + { x = 4.9997; y = 4.0086; z = -2.1973 }, (* O3' *) + { x = 10.2594; y = 10.6774; z = -1.0056 }, (* N1 *) + { x = 9.7528; y = 8.7080; z = -2.2631 }, (* N3 *) + { x = 10.4471; y = 9.7876; z = -1.9791 }, (* C2 *) + { x = 8.7271; y = 8.5575; z = -1.3991 }, (* C4 *) + { x = 8.4100; y = 9.3803; z = -0.3580 }, (* C5 *) + { x = 9.2294; y = 10.5030; z = -0.1574 }, (* C6 *) + (G ( + { x = 11.5110; y = 10.1256; z = -2.7114 }, (* N2 *) + { x = 7.2891; y = 8.9068; z = 0.3121 }, (* N7 *) + { x = 7.7962; y = 7.5519; z = -1.3859 }, (* N9 *) + { x = 6.9702; y = 7.8292; z = -0.3353 }, (* C8 *) + { x = 9.0349; y = 11.3951; z = 0.8250 }, (* O6 *) + { x = 10.9013; y = 11.4422; z = -0.9512 }, (* H1 *) + { x = 12.1031; y = 10.9341; z = -2.5861 }, (* H21 *) + { x = 11.7369; y = 9.5180; z = -3.4859 }, (* H22 *) + { x = 6.0888; y = 7.3990; z = 0.1403 }) (* H8 *) + ) + ) + +let rG06 + = N( + { a= -0.9815; b=0.0731; c= -0.1772; (* dgf_base_tfo *) + d=0.1912; e=0.3054; f= -0.9328; + g= -0.0141; h= -0.9494; i= -0.3137; + tx=5.7506; ty= -5.1944; tz=4.7470 }, + { a= -0.8143; b= -0.5091; c= -0.2788; (* P_O3'_275_tfo *) + d= -0.0433; e= -0.4257; f=0.9038; + g= -0.5788; h=0.7480; i=0.3246; + tx=1.5227; ty=6.9114; tz= -7.0765 }, + { a=0.3822; b= -0.7477; c=0.5430; (* P_O3'_180_tfo *) + d=0.4552; e=0.6637; f=0.5935; + g= -0.8042; h=0.0203; i=0.5941; + tx= -6.9472; ty= -4.1186; tz= -5.9108 }, + { a=0.5640; b=0.8007; c= -0.2022; (* P_O3'_60_tfo *) + d= -0.8247; e=0.5587; f= -0.0878; + g=0.0426; h=0.2162; i=0.9754; + tx=6.2694; ty= -7.0540; tz=3.3316 }, + { x = 2.8930; y = 8.5380; z = -3.3280 }, (* P *) + { x = 1.6980; y = 7.6960; z = -3.5570 }, (* O1P *) + { x = 3.2260; y = 9.5010; z = -4.4020 }, (* O2P *) + { x = 4.1590; y = 7.6040; z = -3.0340 }, (* O5' *) + { x = 4.1214; y = 6.7116; z = -1.9049 }, (* C5' *) + { x = 3.3465; y = 5.9610; z = -2.0607 }, (* H5' *) + { x = 4.0789; y = 7.2928; z = -0.9837 }, (* H5'' *) + { x = 5.4170; y = 5.9293; z = -1.8186 }, (* C4' *) + { x = 5.4506; y = 5.3400; z = -0.9023 }, (* H4' *) + { x = 5.5067; y = 5.0417; z = -2.9703 }, (* O4' *) + { x = 6.8650; y = 4.9152; z = -3.3612 }, (* C1' *) + { x = 7.1090; y = 3.8577; z = -3.2603 }, (* H1' *) + { x = 7.7152; y = 5.7282; z = -2.3894 }, (* C2' *) + { x = 8.5029; y = 6.2356; z = -2.9463 }, (* H2'' *) + { x = 8.1036; y = 4.8568; z = -1.3419 }, (* O2' *) + { x = 8.3270; y = 3.9651; z = -1.6184 }, (* H2' *) + { x = 6.7003; y = 6.7565; z = -1.8911 }, (* C3' *) + { x = 6.5898; y = 7.5329; z = -2.6482 }, (* H3' *) + { x = 7.0505; y = 7.2878; z = -0.6105 }, (* O3' *) + { x = 6.6624; y = 3.5061; z = -8.2986 }, (* N1 *) + { x = 6.5810; y = 3.2570; z = -5.9221 }, (* N3 *) + { x = 6.5151; y = 2.8263; z = -7.1625 }, (* C2 *) + { x = 6.8364; y = 4.5817; z = -5.8882 }, (* C4 *) + { x = 7.0116; y = 5.4064; z = -6.9609 }, (* C5 *) + { x = 6.9173; y = 4.8260; z = -8.2361 }, (* C6 *) + (G ( + { x = 6.2717; y = 1.5402; z = -7.4250 }, (* N2 *) + { x = 7.2573; y = 6.7070; z = -6.5394 }, (* N7 *) + { x = 6.9740; y = 5.3703; z = -4.7760 }, (* N9 *) + { x = 7.2238; y = 6.6275; z = -5.2453 }, (* C8 *) + { x = 7.0668; y = 5.5163; z = -9.3763 }, (* O6 *) + { x = 6.5754; y = 2.9964; z = -9.1545 }, (* H1 *) + { x = 6.1908; y = 1.1105; z = -8.3354 }, (* H21 *) + { x = 6.1346; y = 0.9352; z = -6.6280 }, (* H22 *) + { x = 7.4108; y = 7.6227; z = -4.8418 }) (* H8 *) + ) + ) + +let rG07 + = N( + { a=0.0894; b= -0.6059; c=0.7905; (* dgf_base_tfo *) + d= -0.6810; e=0.5420; f=0.4924; + g= -0.7268; h= -0.5824; i= -0.3642; + tx=34.1424; ty=45.9610; tz= -11.8600 }, + { a= -0.8644; b= -0.4956; c= -0.0851; (* P_O3'_275_tfo *) + d= -0.0427; e=0.2409; f= -0.9696; + g=0.5010; h= -0.8345; i= -0.2294; + tx=4.0167; ty=54.5377; tz=12.4779 }, + { a=0.3706; b= -0.6167; c=0.6945; (* P_O3'_180_tfo *) + d= -0.2867; e= -0.7872; f= -0.5460; + g=0.8834; h=0.0032; i= -0.4686; + tx= -52.9020; ty=18.6313; tz= -0.6709 }, + { a=0.4155; b=0.9025; c= -0.1137; (* P_O3'_60_tfo *) + d=0.9040; e= -0.4236; f= -0.0582; + g= -0.1007; h= -0.0786; i= -0.9918; + tx= -7.6624; ty= -25.2080; tz=49.5181 }, + { x = 31.3810; y = 0.1400; z = 47.5810 }, (* P *) + { x = 29.9860; y = 0.6630; z = 47.6290 }, (* O1P *) + { x = 31.7210; y = -0.6460; z = 48.8090 }, (* O2P *) + { x = 32.4940; y = 1.2540; z = 47.2740 }, (* O5' *) + { x = 33.8709; y = 0.7918; z = 47.2113 }, (* C5' *) + { x = 34.1386; y = 0.5870; z = 46.1747 }, (* H5' *) + { x = 34.0186; y = -0.0095; z = 47.9353 }, (* H5'' *) + { x = 34.7297; y = 1.9687; z = 47.6685 }, (* C4' *) + { x = 35.7723; y = 1.6845; z = 47.8113 }, (* H4' *) + { x = 34.6455; y = 2.9768; z = 46.6660 }, (* O4' *) + { x = 34.1690; y = 4.1829; z = 47.2627 }, (* C1' *) + { x = 35.0437; y = 4.7633; z = 47.5560 }, (* H1' *) + { x = 33.4145; y = 3.7532; z = 48.4954 }, (* C2' *) + { x = 32.4340; y = 3.3797; z = 48.2001 }, (* H2'' *) + { x = 33.3209; y = 4.6953; z = 49.5217 }, (* O2' *) + { x = 33.2374; y = 5.6059; z = 49.2295 }, (* H2' *) + { x = 34.2724; y = 2.5970; z = 48.9773 }, (* C3' *) + { x = 33.6373; y = 1.8935; z = 49.5157 }, (* H3' *) + { x = 35.3453; y = 3.1884; z = 49.7285 }, (* O3' *) + { x = 34.0511; y = 7.8930; z = 43.7791 }, (* N1 *) + { x = 34.9937; y = 6.3369; z = 45.3199 }, (* N3 *) + { x = 35.0882; y = 7.3126; z = 44.4200 }, (* C2 *) + { x = 33.7190; y = 5.9650; z = 45.5374 }, (* C4 *) + { x = 32.5845; y = 6.4770; z = 44.9458 }, (* C5 *) + { x = 32.7430; y = 7.5179; z = 43.9914 }, (* C6 *) + (G ( + { x = 36.3030; y = 7.7827; z = 44.1036 }, (* N2 *) + { x = 31.4499; y = 5.8335; z = 45.4368 }, (* N7 *) + { x = 33.2760; y = 4.9817; z = 46.4043 }, (* N9 *) + { x = 31.9235; y = 4.9639; z = 46.2934 }, (* C8 *) + { x = 31.8602; y = 8.1000; z = 43.3695 }, (* O6 *) + { x = 34.2623; y = 8.6223; z = 43.1283 }, (* H1 *) + { x = 36.5188; y = 8.5081; z = 43.4347 }, (* H21 *) + { x = 37.0888; y = 7.3524; z = 44.5699 }, (* H22 *) + { x = 31.0815; y = 4.4201; z = 46.7218 }) (* H8 *) + ) + ) + +let rG08 + = N( + { a=0.2224; b=0.6335; c=0.7411; (* dgf_base_tfo *) + d= -0.3644; e= -0.6510; f=0.6659; + g=0.9043; h= -0.4181; i=0.0861; + tx= -47.6824; ty= -0.5823; tz= -31.7554 }, + { a= -0.8644; b= -0.4956; c= -0.0851; (* P_O3'_275_tfo *) + d= -0.0427; e=0.2409; f= -0.9696; + g=0.5010; h= -0.8345; i= -0.2294; + tx=4.0167; ty=54.5377; tz=12.4779 }, + { a=0.3706; b= -0.6167; c=0.6945; (* P_O3'_180_tfo *) + d= -0.2867; e= -0.7872; f= -0.5460; + g=0.8834; h=0.0032; i= -0.4686; + tx= -52.9020; ty=18.6313; tz= -0.6709 }, + { a=0.4155; b=0.9025; c= -0.1137; (* P_O3'_60_tfo *) + d=0.9040; e= -0.4236; f= -0.0582; + g= -0.1007; h= -0.0786; i= -0.9918; + tx= -7.6624; ty= -25.2080; tz=49.5181 }, + { x = 31.3810; y = 0.1400; z = 47.5810 }, (* P *) + { x = 29.9860; y = 0.6630; z = 47.6290 }, (* O1P *) + { x = 31.7210; y = -0.6460; z = 48.8090 }, (* O2P *) + { x = 32.4940; y = 1.2540; z = 47.2740 }, (* O5' *) + { x = 32.5924; y = 2.3488; z = 48.2255 }, (* C5' *) + { x = 33.3674; y = 2.1246; z = 48.9584 }, (* H5' *) + { x = 31.5994; y = 2.5917; z = 48.6037 }, (* H5'' *) + { x = 33.0722; y = 3.5577; z = 47.4258 }, (* C4' *) + { x = 33.0310; y = 4.4778; z = 48.0089 }, (* H4' *) + { x = 34.4173; y = 3.3055; z = 47.0316 }, (* O4' *) + { x = 34.5056; y = 3.3910; z = 45.6094 }, (* C1' *) + { x = 34.7881; y = 4.4152; z = 45.3663 }, (* H1' *) + { x = 33.1122; y = 3.1198; z = 45.1010 }, (* C2' *) + { x = 32.9230; y = 2.0469; z = 45.1369 }, (* H2'' *) + { x = 32.7946; y = 3.6590; z = 43.8529 }, (* O2' *) + { x = 33.5170; y = 3.6707; z = 43.2207 }, (* H2' *) + { x = 32.2730; y = 3.8173; z = 46.1566 }, (* C3' *) + { x = 31.3094; y = 3.3123; z = 46.2244 }, (* H3' *) + { x = 32.2391; y = 5.2039; z = 45.7807 }, (* O3' *) + { x = 39.3337; y = 2.7157; z = 44.1441 }, (* N1 *) + { x = 37.4430; y = 3.8242; z = 45.0824 }, (* N3 *) + { x = 38.7276; y = 3.7646; z = 44.7403 }, (* C2 *) + { x = 36.7791; y = 2.6963; z = 44.7704 }, (* C4 *) + { x = 37.2860; y = 1.5653; z = 44.1678 }, (* C5 *) + { x = 38.6647; y = 1.5552; z = 43.8235 }, (* C6 *) + (G ( + { x = 39.5123; y = 4.8216; z = 44.9936 }, (* N2 *) + { x = 36.2829; y = 0.6110; z = 44.0078 }, (* N7 *) + { x = 35.4394; y = 2.4314; z = 44.9931 }, (* N9 *) + { x = 35.2180; y = 1.1815; z = 44.5128 }, (* C8 *) + { x = 39.2907; y = 0.6514; z = 43.2796 }, (* O6 *) + { x = 40.3076; y = 2.8048; z = 43.9352 }, (* H1 *) + { x = 40.4994; y = 4.9066; z = 44.7977 }, (* H21 *) + { x = 39.0738; y = 5.6108; z = 45.4464 }, (* H22 *) + { x = 34.3856; y = 0.4842; z = 44.4185 }) (* H8 *) + ) + ) + +let rG09 + = N( + { a= -0.9699; b= -0.1688; c= -0.1753; (* dgf_base_tfo *) + d= -0.1050; e= -0.3598; f=0.9271; + g= -0.2196; h=0.9176; i=0.3312; + tx=45.6217; ty= -38.9484; tz= -12.3208 }, + { a= -0.8644; b= -0.4956; c= -0.0851; (* P_O3'_275_tfo *) + d= -0.0427; e=0.2409; f= -0.9696; + g=0.5010; h= -0.8345; i= -0.2294; + tx=4.0167; ty=54.5377; tz=12.4779 }, + { a=0.3706; b= -0.6167; c=0.6945; (* P_O3'_180_tfo *) + d= -0.2867; e= -0.7872; f= -0.5460; + g=0.8834; h=0.0032; i= -0.4686; + tx= -52.9020; ty=18.6313; tz= -0.6709 }, + { a=0.4155; b=0.9025; c= -0.1137; (* P_O3'_60_tfo *) + d=0.9040; e= -0.4236; f= -0.0582; + g= -0.1007; h= -0.0786; i= -0.9918; + tx= -7.6624; ty= -25.2080; tz=49.5181 }, + { x = 31.3810; y = 0.1400; z = 47.5810 }, (* P *) + { x = 29.9860; y = 0.6630; z = 47.6290 }, (* O1P *) + { x = 31.7210; y = -0.6460; z = 48.8090 }, (* O2P *) + { x = 32.4940; y = 1.2540; z = 47.2740 }, (* O5' *) + { x = 33.8709; y = 0.7918; z = 47.2113 }, (* C5' *) + { x = 34.1386; y = 0.5870; z = 46.1747 }, (* H5' *) + { x = 34.0186; y = -0.0095; z = 47.9353 }, (* H5'' *) + { x = 34.7297; y = 1.9687; z = 47.6685 }, (* C4' *) + { x = 34.5880; y = 2.8482; z = 47.0404 }, (* H4' *) + { x = 34.3575; y = 2.2770; z = 49.0081 }, (* O4' *) + { x = 35.5157; y = 2.1993; z = 49.8389 }, (* C1' *) + { x = 35.9424; y = 3.2010; z = 49.8893 }, (* H1' *) + { x = 36.4701; y = 1.2820; z = 49.1169 }, (* C2' *) + { x = 36.1545; y = 0.2498; z = 49.2683 }, (* H2'' *) + { x = 37.8262; y = 1.4547; z = 49.4008 }, (* O2' *) + { x = 38.0227; y = 1.6945; z = 50.3094 }, (* H2' *) + { x = 36.2242; y = 1.6797; z = 47.6725 }, (* C3' *) + { x = 36.4297; y = 0.8197; z = 47.0351 }, (* H3' *) + { x = 37.0289; y = 2.8480; z = 47.4426 }, (* O3' *) + { x = 34.3005; y = 3.5042; z = 54.6070 }, (* N1 *) + { x = 34.7693; y = 3.7936; z = 52.2874 }, (* N3 *) + { x = 34.4484; y = 4.2541; z = 53.4939 }, (* C2 *) + { x = 34.9354; y = 2.4584; z = 52.2785 }, (* C4 *) + { x = 34.8092; y = 1.5915; z = 53.3422 }, (* C5 *) + { x = 34.4646; y = 2.1367; z = 54.6085 }, (* C6 *) + (G ( + { x = 34.2514; y = 5.5708; z = 53.6503 }, (* N2 *) + { x = 35.0641; y = 0.2835; z = 52.9337 }, (* N7 *) + { x = 35.2669; y = 1.6690; z = 51.1915 }, (* N9 *) + { x = 35.3288; y = 0.3954; z = 51.6563 }, (* C8 *) + { x = 34.3151; y = 1.5317; z = 55.6650 }, (* O6 *) + { x = 34.0623; y = 3.9797; z = 55.4539 }, (* H1 *) + { x = 33.9950; y = 6.0502; z = 54.5016 }, (* H21 *) + { x = 34.3512; y = 6.1432; z = 52.8242 }, (* H22 *) + { x = 35.5414; y = -0.6006; z = 51.2679 }) (* H8 *) + ) + ) + +let rG10 + = N( + { a= -0.0980; b= -0.9723; c=0.2122; (* dgf_base_tfo *) + d= -0.9731; e=0.1383; f=0.1841; + g= -0.2083; h= -0.1885; i= -0.9597; + tx=17.8469; ty=38.8265; tz=37.0475 }, + { a= -0.8644; b= -0.4956; c= -0.0851; (* P_O3'_275_tfo *) + d= -0.0427; e=0.2409; f= -0.9696; + g=0.5010; h= -0.8345; i= -0.2294; + tx=4.0167; ty=54.5377; tz=12.4779 }, + { a=0.3706; b= -0.6167; c=0.6945; (* P_O3'_180_tfo *) + d= -0.2867; e= -0.7872; f= -0.5460; + g=0.8834; h=0.0032; i= -0.4686; + tx= -52.9020; ty=18.6313; tz= -0.6709 }, + { a=0.4155; b=0.9025; c= -0.1137; (* P_O3'_60_tfo *) + d=0.9040; e= -0.4236; f= -0.0582; + g= -0.1007; h= -0.0786; i= -0.9918; + tx= -7.6624; ty= -25.2080; tz=49.5181 }, + { x = 31.3810; y = 0.1400; z = 47.5810 }, (* P *) + { x = 29.9860; y = 0.6630; z = 47.6290 }, (* O1P *) + { x = 31.7210; y = -0.6460; z = 48.8090 }, (* O2P *) + { x = 32.4940; y = 1.2540; z = 47.2740 }, (* O5' *) + { x = 32.5924; y = 2.3488; z = 48.2255 }, (* C5' *) + { x = 33.3674; y = 2.1246; z = 48.9584 }, (* H5' *) + { x = 31.5994; y = 2.5917; z = 48.6037 }, (* H5'' *) + { x = 33.0722; y = 3.5577; z = 47.4258 }, (* C4' *) + { x = 34.0333; y = 3.3761; z = 46.9447 }, (* H4' *) + { x = 32.0890; y = 3.8338; z = 46.4332 }, (* O4' *) + { x = 31.6377; y = 5.1787; z = 46.5914 }, (* C1' *) + { x = 32.2499; y = 5.8016; z = 45.9392 }, (* H1' *) + { x = 31.9167; y = 5.5319; z = 48.0305 }, (* C2' *) + { x = 31.1507; y = 5.0820; z = 48.6621 }, (* H2'' *) + { x = 32.0865; y = 6.8890; z = 48.3114 }, (* O2' *) + { x = 31.5363; y = 7.4819; z = 47.7942 }, (* H2' *) + { x = 33.2398; y = 4.8224; z = 48.2563 }, (* C3' *) + { x = 33.3166; y = 4.5570; z = 49.3108 }, (* H3' *) + { x = 34.2528; y = 5.7056; z = 47.7476 }, (* O3' *) + { x = 28.2782; y = 6.3049; z = 42.9364 }, (* N1 *) + { x = 30.4001; y = 5.8547; z = 43.9258 }, (* N3 *) + { x = 29.6195; y = 6.1568; z = 42.8913 }, (* C2 *) + { x = 29.7005; y = 5.7006; z = 45.0649 }, (* C4 *) + { x = 28.3383; y = 5.8221; z = 45.2343 }, (* C5 *) + { x = 27.5519; y = 6.1461; z = 44.0958 }, (* C6 *) + (G ( + { x = 30.1838; y = 6.3385; z = 41.6890 }, (* N2 *) + { x = 27.9936; y = 5.5926; z = 46.5651 }, (* N7 *) + { x = 30.2046; y = 5.3825; z = 46.3136 }, (* N9 *) + { x = 29.1371; y = 5.3398; z = 47.1506 }, (* C8 *) + { x = 26.3361; y = 6.3024; z = 44.0495 }, (* O6 *) + { x = 27.8122; y = 6.5394; z = 42.0833 }, (* H1 *) + { x = 29.7125; y = 6.5595; z = 40.8235 }, (* H21 *) + { x = 31.1859; y = 6.2231; z = 41.6389 }, (* H22 *) + { x = 28.9406; y = 5.1504; z = 48.2059 }) (* H8 *) + ) + ) + +let rGs = [rG01;rG02;rG03;rG04;rG05;rG06;rG07;rG08;rG09;rG10] + +let rU + = N( + { a= -0.0359; b= -0.8071; c=0.5894; (* dgf_base_tfo *) + d= -0.2669; e=0.5761; f=0.7726; + g= -0.9631; h= -0.1296; i= -0.2361; + tx=0.1584; ty=8.3434; tz=0.5434 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2430; y = -8.2420; z = 2.8260 }, (* C5' *) + { x = 5.1974; y = -8.8497; z = 1.9223 }, (* H5' *) + { x = 5.5548; y = -8.7348; z = 3.7469 }, (* H5'' *) + { x = 6.3140; y = -7.2060; z = 2.5510 }, (* C4' *) + { x = 7.2954; y = -7.6762; z = 2.4898 }, (* H4' *) + { x = 6.0140; y = -6.5420; z = 1.2890 }, (* O4' *) + { x = 6.4190; y = -5.1840; z = 1.3620 }, (* C1' *) + { x = 7.1608; y = -5.0495; z = 0.5747 }, (* H1' *) + { x = 7.0760; y = -4.9560; z = 2.7270 }, (* C2' *) + { x = 6.7770; y = -3.9803; z = 3.1099 }, (* H2'' *) + { x = 8.4500; y = -5.1930; z = 2.5810 }, (* O2' *) + { x = 8.8309; y = -4.8755; z = 1.7590 }, (* H2' *) + { x = 6.4060; y = -6.0590; z = 3.5580 }, (* C3' *) + { x = 5.4021; y = -5.7313; z = 3.8281 }, (* H3' *) + { x = 7.1570; y = -6.4240; z = 4.7070 }, (* O3' *) + { x = 5.2170; y = -4.3260; z = 1.1690 }, (* N1 *) + { x = 4.2960; y = -2.2560; z = 0.6290 }, (* N3 *) + { x = 5.4330; y = -3.0200; z = 0.7990 }, (* C2 *) + { x = 2.9930; y = -2.6780; z = 0.7940 }, (* C4 *) + { x = 2.8670; y = -4.0630; z = 1.1830 }, (* C5 *) + { x = 3.9570; y = -4.8300; z = 1.3550 }, (* C6 *) + (U ( + { x = 6.5470; y = -2.5560; z = 0.6290 }, (* O2 *) + { x = 2.0540; y = -1.9000; z = 0.6130 }, (* O4 *) + { x = 4.4300; y = -1.3020; z = 0.3600 }, (* H3 *) + { x = 1.9590; y = -4.4570; z = 1.3250 }, (* H5 *) + { x = 3.8460; y = -5.7860; z = 1.6240 }) (* H6 *) + ) + ) + +let rU01 + = N( + { a= -0.0137; b= -0.8012; c=0.5983; (* dgf_base_tfo *) + d= -0.2523; e=0.5817; f=0.7733; + g= -0.9675; h= -0.1404; i= -0.2101; + tx=0.2031; ty=8.3874; tz=0.4228 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2416; y = -8.2422; z = 2.8181 }, (* C5' *) + { x = 5.2050; y = -8.8128; z = 1.8901 }, (* H5' *) + { x = 5.5368; y = -8.7738; z = 3.7227 }, (* H5'' *) + { x = 6.3232; y = -7.2037; z = 2.6002 }, (* C4' *) + { x = 7.3048; y = -7.6757; z = 2.5577 }, (* H4' *) + { x = 6.0635; y = -6.5092; z = 1.3456 }, (* O4' *) + { x = 6.4697; y = -5.1547; z = 1.4629 }, (* C1' *) + { x = 7.2354; y = -5.0043; z = 0.7018 }, (* H1' *) + { x = 7.0856; y = -4.9610; z = 2.8521 }, (* C2' *) + { x = 6.7777; y = -3.9935; z = 3.2487 }, (* H2'' *) + { x = 8.4627; y = -5.1992; z = 2.7423 }, (* O2' *) + { x = 8.8693; y = -4.8638; z = 1.9399 }, (* H2' *) + { x = 6.3877; y = -6.0809; z = 3.6362 }, (* C3' *) + { x = 5.3770; y = -5.7562; z = 3.8834 }, (* H3' *) + { x = 7.1024; y = -6.4754; z = 4.7985 }, (* O3' *) + { x = 5.2764; y = -4.2883; z = 1.2538 }, (* N1 *) + { x = 4.3777; y = -2.2062; z = 0.7229 }, (* N3 *) + { x = 5.5069; y = -2.9779; z = 0.9088 }, (* C2 *) + { x = 3.0693; y = -2.6246; z = 0.8500 }, (* C4 *) + { x = 2.9279; y = -4.0146; z = 1.2149 }, (* C5 *) + { x = 4.0101; y = -4.7892; z = 1.4017 }, (* C6 *) + (U ( + { x = 6.6267; y = -2.5166; z = 0.7728 }, (* O2 *) + { x = 2.1383; y = -1.8396; z = 0.6581 }, (* O4 *) + { x = 4.5223; y = -1.2489; z = 0.4716 }, (* H3 *) + { x = 2.0151; y = -4.4065; z = 1.3290 }, (* H5 *) + { x = 3.8886; y = -5.7486; z = 1.6535 }) (* H6 *) + ) + ) + +let rU02 + = N( + { a=0.5141; b=0.0246; c=0.8574; (* dgf_base_tfo *) + d= -0.5547; e= -0.7529; f=0.3542; + g=0.6542; h= -0.6577; i= -0.3734; + tx= -9.1111; ty= -3.4598; tz= -3.2939 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 4.3825; y = -6.6585; z = 4.0489 }, (* C5' *) + { x = 4.6841; y = -7.2019; z = 4.9443 }, (* H5' *) + { x = 3.6189; y = -5.8889; z = 4.1625 }, (* H5'' *) + { x = 5.6255; y = -5.9175; z = 3.5998 }, (* C4' *) + { x = 5.8732; y = -5.1228; z = 4.3034 }, (* H4' *) + { x = 6.7337; y = -6.8605; z = 3.5222 }, (* O4' *) + { x = 7.5932; y = -6.4923; z = 2.4548 }, (* C1' *) + { x = 8.5661; y = -6.2983; z = 2.9064 }, (* H1' *) + { x = 7.0527; y = -5.2012; z = 1.8322 }, (* C2' *) + { x = 7.1627; y = -5.2525; z = 0.7490 }, (* H2'' *) + { x = 7.6666; y = -4.1249; z = 2.4880 }, (* O2' *) + { x = 8.5944; y = -4.2543; z = 2.6981 }, (* H2' *) + { x = 5.5661; y = -5.3029; z = 2.2009 }, (* C3' *) + { x = 5.0841; y = -6.0018; z = 1.5172 }, (* H3' *) + { x = 4.9062; y = -4.0452; z = 2.2042 }, (* O3' *) + { x = 7.6298; y = -7.6136; z = 1.4752 }, (* N1 *) + { x = 8.6945; y = -8.7046; z = -0.2857 }, (* N3 *) + { x = 8.6943; y = -7.6514; z = 0.6066 }, (* C2 *) + { x = 7.7426; y = -9.6987; z = -0.3801 }, (* C4 *) + { x = 6.6642; y = -9.5742; z = 0.5722 }, (* C5 *) + { x = 6.6391; y = -8.5592; z = 1.4526 }, (* C6 *) + (U ( + { x = 9.5840; y = -6.8186; z = 0.6136 }, (* O2 *) + { x = 7.8505; y = -10.5925; z = -1.2223 }, (* O4 *) + { x = 9.4601; y = -8.7514; z = -0.9277 }, (* H3 *) + { x = 5.9281; y = -10.2509; z = 0.5782 }, (* H5 *) + { x = 5.8831; y = -8.4931; z = 2.1028 }) (* H6 *) + ) + ) + +let rU03 + = N( + { a= -0.4993; b=0.0476; c=0.8651; (* dgf_base_tfo *) + d=0.8078; e= -0.3353; f=0.4847; + g=0.3132; h=0.9409; i=0.1290; + tx=6.2989; ty= -5.2303; tz= -3.8577 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 3.9938; y = -6.7042; z = 1.9023 }, (* C5' *) + { x = 3.2332; y = -5.9343; z = 2.0319 }, (* H5' *) + { x = 3.9666; y = -7.2863; z = 0.9812 }, (* H5'' *) + { x = 5.3098; y = -5.9546; z = 1.8564 }, (* C4' *) + { x = 5.3863; y = -5.3702; z = 0.9395 }, (* H4' *) + { x = 5.3851; y = -5.0642; z = 3.0076 }, (* O4' *) + { x = 6.7315; y = -4.9724; z = 3.4462 }, (* C1' *) + { x = 7.0033; y = -3.9202; z = 3.3619 }, (* H1' *) + { x = 7.5997; y = -5.8018; z = 2.4948 }, (* C2' *) + { x = 8.3627; y = -6.3254; z = 3.0707 }, (* H2'' *) + { x = 8.0410; y = -4.9501; z = 1.4724 }, (* O2' *) + { x = 8.2781; y = -4.0644; z = 1.7570 }, (* H2' *) + { x = 6.5701; y = -6.8129; z = 1.9714 }, (* C3' *) + { x = 6.4186; y = -7.5809; z = 2.7299 }, (* H3' *) + { x = 6.9357; y = -7.3841; z = 0.7235 }, (* O3' *) + { x = 6.8024; y = -5.4718; z = 4.8475 }, (* N1 *) + { x = 7.9218; y = -5.5700; z = 6.8877 }, (* N3 *) + { x = 7.8908; y = -5.0886; z = 5.5944 }, (* C2 *) + { x = 6.9789; y = -6.3827; z = 7.4823 }, (* C4 *) + { x = 5.8742; y = -6.7319; z = 6.6202 }, (* C5 *) + { x = 5.8182; y = -6.2769; z = 5.3570 }, (* C6 *) + (U ( + { x = 8.7747; y = -4.3728; z = 5.1568 }, (* O2 *) + { x = 7.1154; y = -6.7509; z = 8.6509 }, (* O4 *) + { x = 8.7055; y = -5.3037; z = 7.4491 }, (* H3 *) + { x = 5.1416; y = -7.3178; z = 6.9665 }, (* H5 *) + { x = 5.0441; y = -6.5310; z = 4.7784 }) (* H6 *) + ) + ) + +let rU04 + = N( + { a= -0.5669; b= -0.8012; c=0.1918; (* dgf_base_tfo *) + d= -0.8129; e=0.5817; f=0.0273; + g= -0.1334; h= -0.1404; i= -0.9811; + tx= -0.3279; ty=8.3874; tz=0.3355 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2416; y = -8.2422; z = 2.8181 }, (* C5' *) + { x = 5.2050; y = -8.8128; z = 1.8901 }, (* H5' *) + { x = 5.5368; y = -8.7738; z = 3.7227 }, (* H5'' *) + { x = 6.3232; y = -7.2037; z = 2.6002 }, (* C4' *) + { x = 7.3048; y = -7.6757; z = 2.5577 }, (* H4' *) + { x = 6.0635; y = -6.5092; z = 1.3456 }, (* O4' *) + { x = 6.4697; y = -5.1547; z = 1.4629 }, (* C1' *) + { x = 7.2354; y = -5.0043; z = 0.7018 }, (* H1' *) + { x = 7.0856; y = -4.9610; z = 2.8521 }, (* C2' *) + { x = 6.7777; y = -3.9935; z = 3.2487 }, (* H2'' *) + { x = 8.4627; y = -5.1992; z = 2.7423 }, (* O2' *) + { x = 8.8693; y = -4.8638; z = 1.9399 }, (* H2' *) + { x = 6.3877; y = -6.0809; z = 3.6362 }, (* C3' *) + { x = 5.3770; y = -5.7562; z = 3.8834 }, (* H3' *) + { x = 7.1024; y = -6.4754; z = 4.7985 }, (* O3' *) + { x = 5.2764; y = -4.2883; z = 1.2538 }, (* N1 *) + { x = 3.8961; y = -3.0896; z = -0.1893 }, (* N3 *) + { x = 5.0095; y = -3.8907; z = -0.0346 }, (* C2 *) + { x = 3.0480; y = -2.6632; z = 0.8116 }, (* C4 *) + { x = 3.4093; y = -3.1310; z = 2.1292 }, (* C5 *) + { x = 4.4878; y = -3.9124; z = 2.3088 }, (* C6 *) + (U ( + { x = 5.7005; y = -4.2164; z = -0.9842 }, (* O2 *) + { x = 2.0800; y = -1.9458; z = 0.5503 }, (* O4 *) + { x = 3.6834; y = -2.7882; z = -1.1190 }, (* H3 *) + { x = 2.8508; y = -2.8721; z = 2.9172 }, (* H5 *) + { x = 4.7188; y = -4.2247; z = 3.2295 }) (* H6 *) + ) + ) + +let rU05 + = N( + { a= -0.6298; b=0.0246; c=0.7763; (* dgf_base_tfo *) + d= -0.5226; e= -0.7529; f= -0.4001; + g=0.5746; h= -0.6577; i=0.4870; + tx= -0.0208; ty= -3.4598; tz= -9.6882 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 4.3825; y = -6.6585; z = 4.0489 }, (* C5' *) + { x = 4.6841; y = -7.2019; z = 4.9443 }, (* H5' *) + { x = 3.6189; y = -5.8889; z = 4.1625 }, (* H5'' *) + { x = 5.6255; y = -5.9175; z = 3.5998 }, (* C4' *) + { x = 5.8732; y = -5.1228; z = 4.3034 }, (* H4' *) + { x = 6.7337; y = -6.8605; z = 3.5222 }, (* O4' *) + { x = 7.5932; y = -6.4923; z = 2.4548 }, (* C1' *) + { x = 8.5661; y = -6.2983; z = 2.9064 }, (* H1' *) + { x = 7.0527; y = -5.2012; z = 1.8322 }, (* C2' *) + { x = 7.1627; y = -5.2525; z = 0.7490 }, (* H2'' *) + { x = 7.6666; y = -4.1249; z = 2.4880 }, (* O2' *) + { x = 8.5944; y = -4.2543; z = 2.6981 }, (* H2' *) + { x = 5.5661; y = -5.3029; z = 2.2009 }, (* C3' *) + { x = 5.0841; y = -6.0018; z = 1.5172 }, (* H3' *) + { x = 4.9062; y = -4.0452; z = 2.2042 }, (* O3' *) + { x = 7.6298; y = -7.6136; z = 1.4752 }, (* N1 *) + { x = 8.5977; y = -9.5977; z = 0.7329 }, (* N3 *) + { x = 8.5951; y = -8.5745; z = 1.6594 }, (* C2 *) + { x = 7.7372; y = -9.7371; z = -0.3364 }, (* C4 *) + { x = 6.7596; y = -8.6801; z = -0.4476 }, (* C5 *) + { x = 6.7338; y = -7.6721; z = 0.4408 }, (* C6 *) + (U ( + { x = 9.3993; y = -8.5377; z = 2.5743 }, (* O2 *) + { x = 7.8374; y = -10.6990; z = -1.1008 }, (* O4 *) + { x = 9.2924; y = -10.3081; z = 0.8477 }, (* H3 *) + { x = 6.0932; y = -8.6982; z = -1.1929 }, (* H5 *) + { x = 6.0481; y = -6.9515; z = 0.3446 }) (* H6 *) + ) + ) + +let rU06 + = N( + { a= -0.9837; b=0.0476; c= -0.1733; (* dgf_base_tfo *) + d= -0.1792; e= -0.3353; f=0.9249; + g= -0.0141; h=0.9409; i=0.3384; + tx=5.7793; ty= -5.2303; tz=4.5997 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 3.9938; y = -6.7042; z = 1.9023 }, (* C5' *) + { x = 3.2332; y = -5.9343; z = 2.0319 }, (* H5' *) + { x = 3.9666; y = -7.2863; z = 0.9812 }, (* H5'' *) + { x = 5.3098; y = -5.9546; z = 1.8564 }, (* C4' *) + { x = 5.3863; y = -5.3702; z = 0.9395 }, (* H4' *) + { x = 5.3851; y = -5.0642; z = 3.0076 }, (* O4' *) + { x = 6.7315; y = -4.9724; z = 3.4462 }, (* C1' *) + { x = 7.0033; y = -3.9202; z = 3.3619 }, (* H1' *) + { x = 7.5997; y = -5.8018; z = 2.4948 }, (* C2' *) + { x = 8.3627; y = -6.3254; z = 3.0707 }, (* H2'' *) + { x = 8.0410; y = -4.9501; z = 1.4724 }, (* O2' *) + { x = 8.2781; y = -4.0644; z = 1.7570 }, (* H2' *) + { x = 6.5701; y = -6.8129; z = 1.9714 }, (* C3' *) + { x = 6.4186; y = -7.5809; z = 2.7299 }, (* H3' *) + { x = 6.9357; y = -7.3841; z = 0.7235 }, (* O3' *) + { x = 6.8024; y = -5.4718; z = 4.8475 }, (* N1 *) + { x = 6.6920; y = -5.0495; z = 7.1354 }, (* N3 *) + { x = 6.6201; y = -4.5500; z = 5.8506 }, (* C2 *) + { x = 6.9254; y = -6.3614; z = 7.4926 }, (* C4 *) + { x = 7.1046; y = -7.2543; z = 6.3718 }, (* C5 *) + { x = 7.0391; y = -6.7951; z = 5.1106 }, (* C6 *) + (U ( + { x = 6.4083; y = -3.3696; z = 5.6340 }, (* O2 *) + { x = 6.9679; y = -6.6901; z = 8.6800 }, (* O4 *) + { x = 6.5626; y = -4.3957; z = 7.8812 }, (* H3 *) + { x = 7.2781; y = -8.2254; z = 6.5350 }, (* H5 *) + { x = 7.1657; y = -7.4312; z = 4.3503 }) (* H6 *) + ) + ) + +let rU07 + = N( + { a= -0.9434; b=0.3172; c=0.0971; (* dgf_base_tfo *) + d=0.2294; e=0.4125; f=0.8816; + g=0.2396; h=0.8539; i= -0.4619; + tx=8.3625; ty= -52.7147; tz=1.3745 }, + { a=0.2765; b= -0.1121; c= -0.9545; (* P_O3'_275_tfo *) + d= -0.8297; e=0.4733; f= -0.2959; + g=0.4850; h=0.8737; i=0.0379; + tx= -14.7774; ty= -45.2464; tz=21.9088 }, + { a=0.1063; b= -0.6334; c= -0.7665; (* P_O3'_180_tfo *) + d= -0.5932; e= -0.6591; f=0.4624; + g= -0.7980; h=0.4055; i= -0.4458; + tx=43.7634; ty=4.3296; tz=28.4890 }, + { a=0.7136; b= -0.5032; c= -0.4873; (* P_O3'_60_tfo *) + d=0.6803; e=0.3317; f=0.6536; + g= -0.1673; h= -0.7979; i=0.5791; + tx= -17.1858; ty=41.4390; tz= -27.0751 }, + { x = 21.3880; y = 15.0780; z = 45.5770 }, (* P *) + { x = 21.9980; y = 14.5500; z = 46.8210 }, (* O1P *) + { x = 21.1450; y = 14.0270; z = 44.5420 }, (* O2P *) + { x = 22.1250; y = 16.3600; z = 44.9460 }, (* O5' *) + { x = 21.5037; y = 16.8594; z = 43.7323 }, (* C5' *) + { x = 20.8147; y = 17.6663; z = 43.9823 }, (* H5' *) + { x = 21.1086; y = 16.0230; z = 43.1557 }, (* H5'' *) + { x = 22.5654; y = 17.4874; z = 42.8616 }, (* C4' *) + { x = 22.1584; y = 17.7243; z = 41.8785 }, (* H4' *) + { x = 23.0557; y = 18.6826; z = 43.4751 }, (* O4' *) + { x = 24.4788; y = 18.6151; z = 43.6455 }, (* C1' *) + { x = 24.9355; y = 19.0840; z = 42.7739 }, (* H1' *) + { x = 24.7958; y = 17.1427; z = 43.6474 }, (* C2' *) + { x = 24.5652; y = 16.7400; z = 44.6336 }, (* H2'' *) + { x = 26.1041; y = 16.8773; z = 43.2455 }, (* O2' *) + { x = 26.7516; y = 17.5328; z = 43.5149 }, (* H2' *) + { x = 23.8109; y = 16.5979; z = 42.6377 }, (* C3' *) + { x = 23.5756; y = 15.5686; z = 42.9084 }, (* H3' *) + { x = 24.2890; y = 16.7447; z = 41.2729 }, (* O3' *) + { x = 24.9420; y = 19.2174; z = 44.8923 }, (* N1 *) + { x = 25.2655; y = 20.5636; z = 44.8883 }, (* N3 *) + { x = 25.1663; y = 21.2219; z = 43.8561 }, (* C2 *) + { x = 25.6911; y = 21.1219; z = 46.0494 }, (* C4 *) + { x = 25.8051; y = 20.4068; z = 47.2048 }, (* C5 *) + { x = 26.2093; y = 20.9962; z = 48.2534 }, (* C6 *) + (U ( + { x = 25.4692; y = 19.0221; z = 47.2053 }, (* O2 *) + { x = 25.0502; y = 18.4827; z = 46.0370 }, (* O4 *) + { x = 25.9599; y = 22.1772; z = 46.0966 }, (* H3 *) + { x = 25.5545; y = 18.4409; z = 48.1234 }, (* H5 *) + { x = 24.7854; y = 17.4265; z = 45.9883 }) (* H6 *) + ) + ) + +let rU08 + = N( + { a= -0.0080; b= -0.7928; c=0.6094; (* dgf_base_tfo *) + d= -0.7512; e=0.4071; f=0.5197; + g= -0.6601; h= -0.4536; i= -0.5988; + tx=44.1482; ty=30.7036; tz=2.1088 }, + { a=0.2765; b= -0.1121; c= -0.9545; (* P_O3'_275_tfo *) + d= -0.8297; e=0.4733; f= -0.2959; + g=0.4850; h=0.8737; i=0.0379; + tx= -14.7774; ty= -45.2464; tz=21.9088 }, + { a=0.1063; b= -0.6334; c= -0.7665; (* P_O3'_180_tfo *) + d= -0.5932; e= -0.6591; f=0.4624; + g= -0.7980; h=0.4055; i= -0.4458; + tx=43.7634; ty=4.3296; tz=28.4890 }, + { a=0.7136; b= -0.5032; c= -0.4873; (* P_O3'_60_tfo *) + d=0.6803; e=0.3317; f=0.6536; + g= -0.1673; h= -0.7979; i=0.5791; + tx= -17.1858; ty=41.4390; tz= -27.0751 }, + { x = 21.3880; y = 15.0780; z = 45.5770 }, (* P *) + { x = 21.9980; y = 14.5500; z = 46.8210 }, (* O1P *) + { x = 21.1450; y = 14.0270; z = 44.5420 }, (* O2P *) + { x = 22.1250; y = 16.3600; z = 44.9460 }, (* O5' *) + { x = 23.5096; y = 16.1227; z = 44.5783 }, (* C5' *) + { x = 23.5649; y = 15.8588; z = 43.5222 }, (* H5' *) + { x = 23.9621; y = 15.4341; z = 45.2919 }, (* H5'' *) + { x = 24.2805; y = 17.4138; z = 44.7151 }, (* C4' *) + { x = 25.3492; y = 17.2309; z = 44.6030 }, (* H4' *) + { x = 23.8497; y = 18.3471; z = 43.7208 }, (* O4' *) + { x = 23.4090; y = 19.5681; z = 44.3321 }, (* C1' *) + { x = 24.2595; y = 20.2496; z = 44.3524 }, (* H1' *) + { x = 23.0418; y = 19.1813; z = 45.7407 }, (* C2' *) + { x = 22.0532; y = 18.7224; z = 45.7273 }, (* H2'' *) + { x = 23.1307; y = 20.2521; z = 46.6291 }, (* O2' *) + { x = 22.8888; y = 21.1051; z = 46.2611 }, (* H2' *) + { x = 24.0799; y = 18.1326; z = 46.0700 }, (* C3' *) + { x = 23.6490; y = 17.4370; z = 46.7900 }, (* H3' *) + { x = 25.3329; y = 18.7227; z = 46.5109 }, (* O3' *) + { x = 22.2515; y = 20.1624; z = 43.6698 }, (* N1 *) + { x = 22.4760; y = 21.0609; z = 42.6406 }, (* N3 *) + { x = 23.6229; y = 21.3462; z = 42.3061 }, (* C2 *) + { x = 21.3986; y = 21.6081; z = 42.0236 }, (* C4 *) + { x = 20.1189; y = 21.3012; z = 42.3804 }, (* C5 *) + { x = 19.1599; y = 21.8516; z = 41.7578 }, (* C6 *) + (U ( + { x = 19.8919; y = 20.3745; z = 43.4387 }, (* O2 *) + { x = 20.9790; y = 19.8423; z = 44.0440 }, (* O4 *) + { x = 21.5235; y = 22.3222; z = 41.2097 }, (* H3 *) + { x = 18.8732; y = 20.1200; z = 43.7312 }, (* H5 *) + { x = 20.8545; y = 19.1313; z = 44.8608 }) (* H6 *) + ) + ) + +let rU09 + = N( + { a= -0.0317; b=0.1374; c=0.9900; (* dgf_base_tfo *) + d= -0.3422; e= -0.9321; f=0.1184; + g=0.9391; h= -0.3351; i=0.0765; + tx= -32.1929; ty=25.8198; tz= -28.5088 }, + { a=0.2765; b= -0.1121; c= -0.9545; (* P_O3'_275_tfo *) + d= -0.8297; e=0.4733; f= -0.2959; + g=0.4850; h=0.8737; i=0.0379; + tx= -14.7774; ty= -45.2464; tz=21.9088 }, + { a=0.1063; b= -0.6334; c= -0.7665; (* P_O3'_180_tfo *) + d= -0.5932; e= -0.6591; f=0.4624; + g= -0.7980; h=0.4055; i= -0.4458; + tx=43.7634; ty=4.3296; tz=28.4890 }, + { a=0.7136; b= -0.5032; c= -0.4873; (* P_O3'_60_tfo *) + d=0.6803; e=0.3317; f=0.6536; + g= -0.1673; h= -0.7979; i=0.5791; + tx= -17.1858; ty=41.4390; tz= -27.0751 }, + { x = 21.3880; y = 15.0780; z = 45.5770 }, (* P *) + { x = 21.9980; y = 14.5500; z = 46.8210 }, (* O1P *) + { x = 21.1450; y = 14.0270; z = 44.5420 }, (* O2P *) + { x = 22.1250; y = 16.3600; z = 44.9460 }, (* O5' *) + { x = 21.5037; y = 16.8594; z = 43.7323 }, (* C5' *) + { x = 20.8147; y = 17.6663; z = 43.9823 }, (* H5' *) + { x = 21.1086; y = 16.0230; z = 43.1557 }, (* H5'' *) + { x = 22.5654; y = 17.4874; z = 42.8616 }, (* C4' *) + { x = 23.0565; y = 18.3036; z = 43.3915 }, (* H4' *) + { x = 23.5375; y = 16.5054; z = 42.4925 }, (* O4' *) + { x = 23.6574; y = 16.4257; z = 41.0649 }, (* C1' *) + { x = 24.4701; y = 17.0882; z = 40.7671 }, (* H1' *) + { x = 22.3525; y = 16.9643; z = 40.5396 }, (* C2' *) + { x = 21.5993; y = 16.1799; z = 40.6133 }, (* H2'' *) + { x = 22.4693; y = 17.4849; z = 39.2515 }, (* O2' *) + { x = 23.0899; y = 17.0235; z = 38.6827 }, (* H2' *) + { x = 22.0341; y = 18.0633; z = 41.5279 }, (* C3' *) + { x = 20.9509; y = 18.1709; z = 41.5846 }, (* H3' *) + { x = 22.7249; y = 19.3020; z = 41.2100 }, (* O3' *) + { x = 23.8580; y = 15.0648; z = 40.5757 }, (* N1 *) + { x = 25.1556; y = 14.5982; z = 40.4523 }, (* N3 *) + { x = 26.1047; y = 15.3210; z = 40.7448 }, (* C2 *) + { x = 25.3391; y = 13.3315; z = 40.0020 }, (* C4 *) + { x = 24.2974; y = 12.5148; z = 39.6749 }, (* C5 *) + { x = 24.5450; y = 11.3410; z = 39.2610 }, (* C6 *) + (U ( + { x = 22.9633; y = 12.9979; z = 39.8053 }, (* O2 *) + { x = 22.8009; y = 14.2648; z = 40.2524 }, (* O4 *) + { x = 26.3414; y = 12.9194; z = 39.8855 }, (* H3 *) + { x = 22.1227; y = 12.3533; z = 39.5486 }, (* H5 *) + { x = 21.7989; y = 14.6788; z = 40.3650 }) (* H6 *) + ) + ) + +let rU10 + = N( + { a= -0.9674; b=0.1021; c= -0.2318; (* dgf_base_tfo *) + d= -0.2514; e= -0.2766; f=0.9275; + g=0.0306; h=0.9555; i=0.2933; + tx=27.8571; ty= -42.1305; tz= -24.4563 }, + { a=0.2765; b= -0.1121; c= -0.9545; (* P_O3'_275_tfo *) + d= -0.8297; e=0.4733; f= -0.2959; + g=0.4850; h=0.8737; i=0.0379; + tx= -14.7774; ty= -45.2464; tz=21.9088 }, + { a=0.1063; b= -0.6334; c= -0.7665; (* P_O3'_180_tfo *) + d= -0.5932; e= -0.6591; f=0.4624; + g= -0.7980; h=0.4055; i= -0.4458; + tx=43.7634; ty=4.3296; tz=28.4890 }, + { a=0.7136; b= -0.5032; c= -0.4873; (* P_O3'_60_tfo *) + d=0.6803; e=0.3317; f=0.6536; + g= -0.1673; h= -0.7979; i=0.5791; + tx= -17.1858; ty=41.4390; tz= -27.0751 }, + { x = 21.3880; y = 15.0780; z = 45.5770 }, (* P *) + { x = 21.9980; y = 14.5500; z = 46.8210 }, (* O1P *) + { x = 21.1450; y = 14.0270; z = 44.5420 }, (* O2P *) + { x = 22.1250; y = 16.3600; z = 44.9460 }, (* O5' *) + { x = 23.5096; y = 16.1227; z = 44.5783 }, (* C5' *) + { x = 23.5649; y = 15.8588; z = 43.5222 }, (* H5' *) + { x = 23.9621; y = 15.4341; z = 45.2919 }, (* H5'' *) + { x = 24.2805; y = 17.4138; z = 44.7151 }, (* C4' *) + { x = 23.8509; y = 18.1819; z = 44.0720 }, (* H4' *) + { x = 24.2506; y = 17.8583; z = 46.0741 }, (* O4' *) + { x = 25.5830; y = 18.0320; z = 46.5775 }, (* C1' *) + { x = 25.8569; y = 19.0761; z = 46.4256 }, (* H1' *) + { x = 26.4410; y = 17.1555; z = 45.7033 }, (* C2' *) + { x = 26.3459; y = 16.1253; z = 46.0462 }, (* H2'' *) + { x = 27.7649; y = 17.5888; z = 45.6478 }, (* O2' *) + { x = 28.1004; y = 17.9719; z = 46.4616 }, (* H2' *) + { x = 25.7796; y = 17.2997; z = 44.3513 }, (* C3' *) + { x = 25.9478; y = 16.3824; z = 43.7871 }, (* H3' *) + { x = 26.2154; y = 18.4984; z = 43.6541 }, (* O3' *) + { x = 25.7321; y = 17.6281; z = 47.9726 }, (* N1 *) + { x = 25.5136; y = 18.5779; z = 48.9560 }, (* N3 *) + { x = 25.2079; y = 19.7276; z = 48.6503 }, (* C2 *) + { x = 25.6482; y = 18.1987; z = 50.2518 }, (* C4 *) + { x = 25.9847; y = 16.9266; z = 50.6092 }, (* C5 *) + { x = 26.0918; y = 16.6439; z = 51.8416 }, (* C6 *) + (U ( + { x = 26.2067; y = 15.9515; z = 49.5943 }, (* O2 *) + { x = 26.0713; y = 16.3497; z = 48.3080 }, (* O4 *) + { x = 25.4890; y = 18.9105; z = 51.0618 }, (* H3 *) + { x = 26.4742; y = 14.9310; z = 49.8682 }, (* H5 *) + { x = 26.2346; y = 15.6394; z = 47.4975 }) (* H6 *) + ) + ) + +let rUs = [rU01;rU02;rU03;rU04;rU05;rU06;rU07;rU08;rU09;rU10] + +let rG' + = N( + { a= -0.2067; b= -0.0264; c=0.9780; (* dgf_base_tfo *) + d=0.9770; e= -0.0586; f=0.2049; + g=0.0519; h=0.9979; i=0.0379; + tx=1.0331; ty= -46.8078; tz= -36.4742 }, + { a= -0.8644; b= -0.4956; c= -0.0851; (* P_O3'_275_tfo *) + d= -0.0427; e=0.2409; f= -0.9696; + g=0.5010; h= -0.8345; i= -0.2294; + tx=4.0167; ty=54.5377; tz=12.4779 }, + { a=0.3706; b= -0.6167; c=0.6945; (* P_O3'_180_tfo *) + d= -0.2867; e= -0.7872; f= -0.5460; + g=0.8834; h=0.0032; i= -0.4686; + tx= -52.9020; ty=18.6313; tz= -0.6709 }, + { a=0.4155; b=0.9025; c= -0.1137; (* P_O3'_60_tfo *) + d=0.9040; e= -0.4236; f= -0.0582; + g= -0.1007; h= -0.0786; i= -0.9918; + tx= -7.6624; ty= -25.2080; tz=49.5181 }, + { x = 31.3810; y = 0.1400; z = 47.5810 }, (* P *) + { x = 29.9860; y = 0.6630; z = 47.6290 }, (* O1P *) + { x = 31.7210; y = -0.6460; z = 48.8090 }, (* O2P *) + { x = 32.4940; y = 1.2540; z = 47.2740 }, (* O5' *) + { x = 32.1610; y = 2.2370; z = 46.2560 }, (* C5' *) + { x = 31.2986; y = 2.8190; z = 46.5812 }, (* H5' *) + { x = 32.0980; y = 1.7468; z = 45.2845 }, (* H5'' *) + { x = 33.3476; y = 3.1959; z = 46.1947 }, (* C4' *) + { x = 33.2668; y = 3.8958; z = 45.3630 }, (* H4' *) + { x = 33.3799; y = 3.9183; z = 47.4216 }, (* O4' *) + { x = 34.6515; y = 3.7222; z = 48.0398 }, (* C1' *) + { x = 35.2947; y = 4.5412; z = 47.7180 }, (* H1' *) + { x = 35.1756; y = 2.4228; z = 47.4827 }, (* C2' *) + { x = 34.6778; y = 1.5937; z = 47.9856 }, (* H2'' *) + { x = 36.5631; y = 2.2672; z = 47.4798 }, (* O2' *) + { x = 37.0163; y = 2.6579; z = 48.2305 }, (* H2' *) + { x = 34.6953; y = 2.5043; z = 46.0448 }, (* C3' *) + { x = 34.5444; y = 1.4917; z = 45.6706 }, (* H3' *) + { x = 35.6679; y = 3.3009; z = 45.3487 }, (* O3' *) + { x = 37.4804; y = 4.0914; z = 52.2559 }, (* N1 *) + { x = 36.9670; y = 4.1312; z = 49.9281 }, (* N3 *) + { x = 37.8045; y = 4.2519; z = 50.9550 }, (* C2 *) + { x = 35.7171; y = 3.8264; z = 50.3222 }, (* C4 *) + { x = 35.2668; y = 3.6420; z = 51.6115 }, (* C5 *) + { x = 36.2037; y = 3.7829; z = 52.6706 }, (* C6 *) + (G ( + { x = 39.0869; y = 4.5552; z = 50.7092 }, (* N2 *) + { x = 33.9075; y = 3.3338; z = 51.6102 }, (* N7 *) + { x = 34.6126; y = 3.6358; z = 49.5108 }, (* N9 *) + { x = 33.5805; y = 3.3442; z = 50.3425 }, (* C8 *) + { x = 35.9958; y = 3.6512; z = 53.8724 }, (* O6 *) + { x = 38.2106; y = 4.2053; z = 52.9295 }, (* H1 *) + { x = 39.8218; y = 4.6863; z = 51.3896 }, (* H21 *) + { x = 39.3420; y = 4.6857; z = 49.7407 }, (* H22 *) + { x = 32.5194; y = 3.1070; z = 50.2664 }) (* H8 *) + ) + ) + +let rU' + = N( + { a= -0.0109; b=0.5907; c=0.8068; (* dgf_base_tfo *) + d=0.2217; e= -0.7853; f=0.5780; + g=0.9751; h=0.1852; i= -0.1224; + tx= -1.4225; ty= -11.0956; tz= -2.5217 }, + { a= -0.8313; b= -0.4738; c= -0.2906; (* P_O3'_275_tfo *) + d=0.0649; e=0.4366; f= -0.8973; + g=0.5521; h= -0.7648; i= -0.3322; + tx=1.6833; ty=6.8060; tz= -7.0011 }, + { a=0.3445; b= -0.7630; c=0.5470; (* P_O3'_180_tfo *) + d= -0.4628; e= -0.6450; f= -0.6082; + g=0.8168; h= -0.0436; i= -0.5753; + tx= -6.8179; ty= -3.9778; tz= -5.9887 }, + { a=0.5855; b=0.7931; c= -0.1682; (* P_O3'_60_tfo *) + d=0.8103; e= -0.5790; f=0.0906; + g= -0.0255; h= -0.1894; i= -0.9816; + tx=6.1203; ty= -7.1051; tz=3.1984 }, + { x = 2.6760; y = -8.4960; z = 3.2880 }, (* P *) + { x = 1.4950; y = -7.6230; z = 3.4770 }, (* O1P *) + { x = 2.9490; y = -9.4640; z = 4.3740 }, (* O2P *) + { x = 3.9730; y = -7.5950; z = 3.0340 }, (* O5' *) + { x = 5.2430; y = -8.2420; z = 2.8260 }, (* C5' *) + { x = 5.1974; y = -8.8497; z = 1.9223 }, (* H5' *) + { x = 5.5548; y = -8.7348; z = 3.7469 }, (* H5'' *) + { x = 6.3140; y = -7.2060; z = 2.5510 }, (* C4' *) + { x = 5.8744; y = -6.2116; z = 2.4731 }, (* H4' *) + { x = 7.2798; y = -7.2260; z = 3.6420 }, (* O4' *) + { x = 8.5733; y = -6.9410; z = 3.1329 }, (* C1' *) + { x = 8.9047; y = -6.0374; z = 3.6446 }, (* H1' *) + { x = 8.4429; y = -6.6596; z = 1.6327 }, (* C2' *) + { x = 9.2880; y = -7.1071; z = 1.1096 }, (* H2'' *) + { x = 8.2502; y = -5.2799; z = 1.4754 }, (* O2' *) + { x = 8.7676; y = -4.7284; z = 2.0667 }, (* H2' *) + { x = 7.1642; y = -7.4416; z = 1.3021 }, (* C3' *) + { x = 7.4125; y = -8.5002; z = 1.2260 }, (* H3' *) + { x = 6.5160; y = -6.9772; z = 0.1267 }, (* O3' *) + { x = 9.4531; y = -8.1107; z = 3.4087 }, (* N1 *) + { x = 11.5931; y = -9.0015; z = 3.6357 }, (* N3 *) + { x = 10.8101; y = -7.8950; z = 3.3748 }, (* C2 *) + { x = 11.1439; y = -10.2744; z = 3.9206 }, (* C4 *) + { x = 9.7056; y = -10.4026; z = 3.9332 }, (* C5 *) + { x = 8.9192; y = -9.3419; z = 3.6833 }, (* C6 *) + (U ( + { x = 11.3013; y = -6.8063; z = 3.1326 }, (* O2 *) + { x = 11.9431; y = -11.1876; z = 4.1375 }, (* O4 *) + { x = 12.5840; y = -8.8673; z = 3.6158 }, (* H3 *) + { x = 9.2891; y = -11.2898; z = 4.1313 }, (* H5 *) + { x = 7.9263; y = -9.4537; z = 3.6977 }) (* H6 *) + ) + ) + +(* -- PARTIAL INSTANTIATIONS ------------------------------------------------*) + +type variable = + { id : int; + t : tfo; + n : nuc } + +let mk_var i t n = { id = i; t = t; n = n } + +let absolute_pos v p = tfo_apply v.t p + +let atom_pos atom v = absolute_pos v (atom v.n) + +let rec get_var id = function + | (v::lst) -> if id = v.id then v else get_var id lst + | _ -> assert false + +(* -- SEARCH ----------------------------------------------------------------*) + +(* Sequential backtracking algorithm *) + +let rec search (partial_inst : variable list) l constr = + match l with + [] -> [partial_inst] + | (h::t) -> + let rec try_assignments = function + [] -> [] + | v::vs -> + if constr v partial_inst then + (search (v::partial_inst) t constr) @ (try_assignments vs) + else + try_assignments vs + in + try_assignments (h partial_inst) + + +(* -- DOMAINS ---------------------------------------------------------------*) + +(* Primary structure: strand A CUGCCACGUCUG, strand B CAGACGUGGCAG + + Secondary structure: strand A CUGCCACGUCUG + |||||||||||| + GACGGUGCAGAC strand B + + Tertiary structure: + + 5' end of strand A C1----G12 3' end of strand B + U2-------A11 + G3-------C10 + C4-----G9 + C5---G8 + A6 + G6-C7 + C5----G8 + A4-------U9 + G3--------C10 + A2-------U11 + 5' end of strand B C1----G12 3' end of strand A + + "helix", "stacked" and "connected" describe the spatial relationship + between two consecutive nucleotides. E.g. the nucleotides C1 and U2 + from the strand A. + + "wc" (stands for Watson-Crick and is a type of base-pairing), + and "wc-dumas" describe the spatial relationship between + nucleotides from two chains that are growing in opposite directions. + E.g. the nucleotides C1 from strand A and G12 from strand B. +*) + +(* Dynamic Domains *) + +(* Given, + "refnuc" a nucleotide which is already positioned, + "nucl" the nucleotide to be placed, + and "tfo" a transformation matrix which expresses the desired + relationship between "refnuc" and "nucl", + the function "dgf-base" computes the transformation matrix that + places the nucleotide "nucl" in the given relationship to "refnuc". +*) + +let +dgf_base tfo v nucl + = let x = if is_A v.n then + tfo_align (atom_pos nuc_C1' v) + (atom_pos rA_N9 v) + (atom_pos nuc_C4 v) + else if is_C v.n then + tfo_align (atom_pos nuc_C1' v) + (atom_pos nuc_N1 v) + (atom_pos nuc_C2 v) + else if is_G v.n then + tfo_align (atom_pos nuc_C1' v) + (atom_pos rG_N9 v) + (atom_pos nuc_C4 v) + else + tfo_align (atom_pos nuc_C1' v) + (atom_pos nuc_N1 v) + (atom_pos nuc_C2 v) + in + tfo_combine (nuc_dgf_base_tfo nucl) + (tfo_combine tfo (tfo_inv_ortho x)) + +(* Placement of first nucleotide. *) + +let +reference n i partial_inst = [ mk_var i tfo_id n ] + +(* The transformation matrix for wc is from: + + Chandrasekaran R. et al (1989) A Re-Examination of the Crystal + Structure of A-DNA Using Fiber Diffraction Data. J. Biomol. + Struct. & Dynamics 6(6):1189-1202. +*) + +let wc_tfo + = ( + { a= -1.0000; b=0.0028; c= -0.0019; + d=0.0028; e=0.3468; f= -0.9379; + g= -0.0019; h= -0.9379; i= -0.3468; + tx= -0.0080; ty=6.0730; tz=8.7208 } + ) + +let +wc nucl i j partial_inst + = [ mk_var i (dgf_base wc_tfo (get_var j partial_inst) nucl) nucl ] + +let wc_dumas_tfo + = ( + { a= -0.9737; b= -0.1834; c=0.1352; + d= -0.1779; e=0.2417; f= -0.9539; + g=0.1422; h= -0.9529; i= -0.2679; + tx=0.4837; ty=6.2649; tz=8.0285 } + ) + +let +wc_dumas nucl i j partial_inst + = [ mk_var i (dgf_base wc_dumas_tfo (get_var j partial_inst) nucl) nucl ] + +let helix5'_tfo + = ( + { a=0.9886; b= -0.0961; c=0.1156; + d=0.1424; e=0.8452; f= -0.5152; + g= -0.0482; h=0.5258; i=0.8492; + tx= -3.8737; ty=0.5480; tz=3.8024 } + ) + +let +helix5' nucl i j partial_inst + = [ mk_var i (dgf_base helix5'_tfo (get_var j partial_inst) nucl) nucl ] + +let helix3'_tfo + = ( + { a=0.9886; b=0.1424; c= -0.0482; + d= -0.0961; e=0.8452; f=0.5258; + g=0.1156; h= -0.5152; i=0.8492; + tx=3.4426; ty=2.0474; tz= -3.7042 } + ) + +let +helix3' nucl i j partial_inst + = [ mk_var i (dgf_base helix3'_tfo (get_var j partial_inst) nucl) nucl ] + +let g37_a38_tfo + = ( + { a=0.9991; b=0.0164; c= -0.0387; + d= -0.0375; e=0.7616; f= -0.6470; + g=0.0189; h=0.6478; i=0.7615; + tx= -3.3018; ty=0.9975; tz=2.5585 } + ) + +let +g37_a38 nucl i j partial_inst + = mk_var i (dgf_base g37_a38_tfo (get_var j partial_inst) nucl) nucl + +let +stacked5' nucl i j partial_inst + = (g37_a38 nucl i j partial_inst) :: (helix5' nucl i j partial_inst) + +let a38_g37_tfo + = ( + { a=0.9991; b= -0.0375; c=0.0189; + d=0.0164; e=0.7616; f=0.6478; + g= -0.0387; h= -0.6470; i=0.7615; + tx=3.3819; ty=0.7718; tz= -2.5321 } + ) + +let +a38_g37 nucl i j partial_inst + = mk_var i (dgf_base a38_g37_tfo (get_var j partial_inst) nucl) nucl + +let +stacked3' nucl i j partial_inst + = (a38_g37 nucl i j partial_inst) :: (helix3' nucl i j partial_inst) + +let +p_o3' nucls i j partial_inst + = let refnuc = get_var j partial_inst in + let align = tfo_inv_ortho + (tfo_align (atom_pos nuc_O3' refnuc) + (atom_pos nuc_C3' refnuc) + (atom_pos nuc_C4' refnuc)) in + let rec generate domains = function + [] -> domains + | n::ns -> + generate + ((mk_var i (tfo_combine (nuc_p_o3'_60_tfo n) align) n):: + (mk_var i (tfo_combine (nuc_p_o3'_180_tfo n) align) n):: + (mk_var i (tfo_combine (nuc_p_o3'_275_tfo n) align) n)::domains) + ns + in + generate [] nucls + +(* -- PROBLEM STATEMENT -----------------------------------------------------*) + +(* Define anticodon problem -- Science 253:1255 Figure 3a, 3b and 3c *) + +let +anticodon_domains + = [ + reference rC 27; + helix5' rC 28 27; + helix5' rA 29 28; + helix5' rG 30 29; + helix5' rA 31 30; + wc rU 39 31; + helix5' rC 40 39; + helix5' rU 41 40; + helix5' rG 42 41; + helix5' rG 43 42; + stacked3' rA 38 39; + stacked3' rG 37 38; + stacked3' rA 36 37; + stacked3' rA 35 36; + stacked3' rG 34 35; (* <-. Distance *) + p_o3' rCs 32 31; (* | Constraint *) + p_o3' rUs 33 32 (* <-' 3.0 Angstroms *) + ] + +(* Anticodon constraint *) + +let +anticodon_constraint v partial_inst = + let rec dist j = let p = atom_pos nuc_P (get_var j partial_inst) in + let o3' = atom_pos nuc_O3' v in + pt_dist p o3' + in + if v.id = 33 then + (dist 34) <= 3.0 + else + true + +let +anticodon () = search [] anticodon_domains anticodon_constraint + +(* Define pseudoknot problem -- Science 253:1255 Figure 4a and 4b *) + +let +pseudoknot_domains + = [ + reference rA 23; + wc_dumas rU 8 23; + helix3' rG 22 23; + wc_dumas rC 9 22; + helix3' rG 21 22; + wc_dumas rC 10 21; + helix3' rC 20 21; + wc_dumas rG 11 20; + helix3' rU' 19 20; (* <-. *) + wc_dumas rA 12 19; (* | Distance *) +(* | Constraint *) +(* Helix 1 | 4.0 Angstroms *) + helix3' rC 3 19; (* | *) + wc_dumas rG 13 3; (* | *) + helix3' rC 2 3; (* | *) + wc_dumas rG 14 2; (* | *) + helix3' rC 1 2; (* | *) + wc_dumas rG' 15 1; (* | *) +(* | *) +(* L2 LOOP | *) + p_o3' rUs 16 15; (* | *) + p_o3' rCs 17 16; (* | *) + p_o3' rAs 18 17; (* <-' *) +(* *) +(* L1 LOOP *) + helix3' rU 7 8; (* <-. *) + p_o3' rCs 4 3; (* | Constraint *) + stacked5' rU 5 4; (* | 4.5 Angstroms *) + stacked5' rC 6 5 (* <-' *) + ] + +(* Pseudoknot constraint *) + +let +pseudoknot_constraint v partial_inst = + let rec dist j = + let p = atom_pos nuc_P (get_var j partial_inst) in + let o3' = atom_pos nuc_O3' v in + pt_dist p o3' + in + if v.id = 18 then + (dist 19) <= 4.0 + else if v.id = 6 then + (dist 7) <= 4.5 + else + true + +let +pseudoknot () = search [] pseudoknot_domains pseudoknot_constraint + +(* -- TESTING ---------------------------------------------------------------*) + +let list_of_atoms = function + (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6, + A (n6,n7,n9,c8,h2,h61,h62,h8))) + -> [|p;o1p;o2p;o5';c5';h5';h5'';c4';h4';o4';c1';h1';c2';h2'';o2';h2';c3'; + h3';o3';n1;n3;c2;c4;c5;c6;n6;n7;n9;c8;h2;h61;h62;h8|] + +| (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6, + C (n4,o2,h41,h42,h5,h6))) + -> [|p;o1p;o2p;o5';c5';h5';h5'';c4';h4';o4';c1';h1';c2';h2'';o2';h2';c3'; + h3';o3';n1;n3;c2;c4;c5;c6;n4;o2;h41;h42;h5;h6|] + +| (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6, + G (n2,n7,n9,c8,o6,h1,h21,h22,h8))) + -> [|p;o1p;o2p;o5';c5';h5';h5'';c4';h4';o4';c1';h1';c2';h2'';o2';h2';c3'; + h3';o3';n1;n3;c2;c4;c5;c6;n2;n7;n9;c8;o6;h1;h21;h22;h8|] + +| (N(dgf_base_tfo,p_o3'_275_tfo,p_o3'_180_tfo,p_o3'_60_tfo, + p,o1p,o2p,o5',c5',h5',h5'',c4',h4',o4',c1',h1',c2',h2'',o2',h2', + c3',h3',o3',n1,n3,c2,c4,c5,c6, + U (o2,o4,h3,h5,h6))) + -> [|p;o1p;o2p;o5';c5';h5';h5'';c4';h4';o4';c1';h1';c2';h2'';o2';h2';c3'; + h3';o3';n1;n3;c2;c4;c5;c6;o2;o4;h3;h5;h6|] + +let maximum = function + | x::xs -> + let rec iter m = function + [] -> m + | (a::b) -> iter (if a > m then a else m) b + in + iter x xs + | _ -> assert false + +let +var_most_distant_atom v = + let atoms = list_of_atoms v.n in + let max_dist = ref 0.0 in + for i = 0 to pred (Array.length atoms) do + let p = atoms.(i) in + let distance = + let pos = absolute_pos v p + in sqrt ((pos.x * pos.x) + (pos.y * pos.y) + (pos.z * pos.z)) in + if distance > !max_dist then max_dist := distance + done; + !max_dist + +let +sol_most_distant_atom s = maximum (List.map var_most_distant_atom s) + +let +most_distant_atom sols = maximum (List.map sol_most_distant_atom sols) + +let +check () = List.length (pseudoknot ()) + +let +run () = most_distant_atom (pseudoknot ()) + +let main () = + for i = 1 to 50 do ignore(run()) done; + Printf.printf "%.4f" (run ()); print_newline() + +let _ = main () diff --git a/test/ocamldoc/Makefile b/test/ocamldoc/Makefile new file mode 100644 index 0000000..e6f3533 --- /dev/null +++ b/test/ocamldoc/Makefile @@ -0,0 +1,40 @@ +######################################################################### +# # +# Objective Caml # +# # +# Maxence Guesdon, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 2004 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.1 2004-02-20 16:02:03 guesdon Exp $ + +ROOT=../.. +include $(ROOT)/config/Makefile + +CAMLC=$(ROOT)/boot/ocamlrun $(ROOT)/ocamlc +CAMLOPT=$(ROOT)/boot/ocamlrun $(ROOT)/ocamlopt +COMPFLAGS=-nostdlib -I $(ROOT)/stdlib -I KB -I Lex +OPTFLAGS=-S +CAMLYACC=$(ROOT)/yacc/ocamlyacc +YACCFLAGS=-v +CAMLLEX=$(ROOT)/boot/ocamlrun $(ROOT)/lex/ocamllex +CAMLDEP=$(ROOT)/boot/ocamlrun $(ROOT)/tools/ocamldep +CAMLRUN=$(ROOT)/byterun/ocamlrun +OCAMLDOC=$(ROOT)/boot/ocamlrun $(ROOT)/ocamldoc/ocamldoc +OCAMLDOC_TEST=$(OCAMLDOC) -g $(ROOT)/ocamldoc/odoc_test.cmo -warn-error + + +all: + for i in *.ml; do $(MAKE) TARGET=`basename $$i .ml` test_one; done + +test_one: results/$(TARGET).txt + +results/$(TARGET).txt : $(TARGET).ml + $(OCAMLDOC_TEST) -o $@ $< 2> results/$(TARGET).stderr + +clean: + rm -f results/*.txt results/*.stderr \ No newline at end of file diff --git a/test/ocamldoc/t1.ml b/test/ocamldoc/t1.ml new file mode 100644 index 0000000..6caf3d7 --- /dev/null +++ b/test/ocamldoc/t1.ml @@ -0,0 +1,19 @@ +(** Testing display of types. + + @test_types_display + *) + +let x = 1 + + +module M = struct + let y = 2 + +end + +module type MT = sig + type t = string -> int -> string -> (string * string * string) -> + (string * string * string) -> + (string * string * string) -> unit + val y : int +end diff --git a/test/outputobj/Makefile b/test/outputobj/Makefile new file mode 100755 index 0000000..40c81d1 --- /dev/null +++ b/test/outputobj/Makefile @@ -0,0 +1,33 @@ +include ../../config/Makefile + +OCAMLC = ../../ocamlc +OCAMLOPT = ../../ocamlopt + +test: + $(OCAMLC) -c plugin.ml + $(OCAMLC) -output-obj -o main_obj.$(O) dynlink.cma entry.c main.ml + $(MKDLL) -maindll -o main.dll main_obj.$(O) entry.$(O) ../../byterun/libcamlrun.$(A) $(BYTECCLIBS) -v + csc /out:main.exe main.cs + ./main.exe + +test2: + $(OCAMLC) -c plugin.ml + $(OCAMLC) -output-obj -o main.dll dynlink.cma main.ml entry.c + csc /out:main.exe main.cs + ./main.exe + +testopt: + $(OCAMLOPT) -o plugin.cmxs -shared plugin.ml + $(OCAMLOPT) -output-obj -o main_obj.$(O) dynlink.cmxa entry.c main.ml + $(MKDLL) -maindll -o main.dll main_obj.$(O) entry.$(O) ../../asmrun/libasmrun.lib -v + csc /out:main.exe main.cs + ./main.exe + +testopt2: + $(OCAMLOPT) -o plugin.cmxs -shared plugin.ml + $(OCAMLOPT) -output-obj -o main.dll dynlink.cmxa entry.c main.ml + csc /out:main.exe main.cs + ./main.exe + +clean: + rm -f *.exe *~ *.cm* *.obj *.o *.dll diff --git a/test/outputobj/entry.c b/test/outputobj/entry.c new file mode 100755 index 0000000..13ecd73 --- /dev/null +++ b/test/outputobj/entry.c @@ -0,0 +1,13 @@ +#include <caml/memory.h> +#include <caml/alloc.h> +#include <caml/mlvalues.h> +#include <caml/callback.h> +#include <caml/custom.h> +#include <caml/fail.h> + +__declspec(dllexport) void __stdcall start_caml_engine() { + char * argv[2]; + argv[0] = "--"; + argv[1] = NULL; + caml_startup(argv); +} diff --git a/test/outputobj/main.cs b/test/outputobj/main.cs new file mode 100755 index 0000000..a03bfd6 --- /dev/null +++ b/test/outputobj/main.cs @@ -0,0 +1,11 @@ +using System.Runtime.InteropServices; + +public class M { + [DllImport("main.dll")] + public static extern void start_caml_engine(); + + public static void Main() { + System.Console.WriteLine("Now starting the Caml engine."); + start_caml_engine(); + } +} diff --git a/test/outputobj/main.ml b/test/outputobj/main.ml new file mode 100755 index 0000000..82130fd --- /dev/null +++ b/test/outputobj/main.ml @@ -0,0 +1,23 @@ +let load s = + Printf.printf "Loading %s\n%!" s; + try + Dynlink.loadfile s + with Dynlink.Error e -> + print_endline (Dynlink.error_message e) + +let () = + print_endline "Main is running."; + Dynlink.init (); + Dynlink.allow_unsafe_modules true; + let s1,s2 = + if Dynlink.is_native then + "../../otherlibs/bigarray/bigarray.cmxs", + "plugin.cmxs" + else + "../../otherlibs/bigarray/bigarray.cma", + "plugin.cmo" + in + load s1; + load s2; + print_endline "OK." + diff --git a/test/outputobj/plugin.ml b/test/outputobj/plugin.ml new file mode 100755 index 0000000..39c46f3 --- /dev/null +++ b/test/outputobj/plugin.ml @@ -0,0 +1,4 @@ +let f x = x.{2} + +let () = + print_endline "I'm the plugin." diff --git a/test/quicksort.ml b/test/quicksort.ml new file mode 100644 index 0000000..96b6aae --- /dev/null +++ b/test/quicksort.ml @@ -0,0 +1,92 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: quicksort.ml,v 1.7 2005-08-12 09:22:04 xleroy Exp $ *) + +(* Good test for loops. Best compiled with -unsafe. *) + +let rec qsort lo hi (a : int array) = + if lo < hi then begin + let i = ref lo in + let j = ref hi in + let pivot = a.(hi) in + while !i < !j do + while !i < hi && a.(!i) <= pivot do incr i done; + while !j > lo && a.(!j) >= pivot do decr j done; + if !i < !j then begin + let temp = a.(!i) in a.(!i) <- a.(!j); a.(!j) <- temp + end + done; + let temp = a.(!i) in a.(!i) <- a.(hi); a.(hi) <- temp; + qsort lo (!i-1) a; + qsort (!i+1) hi a + end + + +(* Same but abstract over the comparison to force spilling *) + +let cmp i j = i - j + +let rec qsort2 lo hi (a : int array) = + if lo < hi then begin + let i = ref lo in + let j = ref hi in + let pivot = a.(hi) in + while !i < !j do + while !i < hi && cmp a.(!i) pivot <= 0 do incr i done; + while !j > lo && cmp a.(!j) pivot >= 0 do decr j done; + if !i < !j then begin + let temp = a.(!i) in a.(!i) <- a.(!j); a.(!j) <- temp + end + done; + let temp = a.(!i) in a.(!i) <- a.(hi); a.(hi) <- temp; + qsort2 lo (!i-1) a; + qsort2 (!i+1) hi a + end + + +(* Test *) + +let seed = ref 0 + +let random() = + seed := !seed * 25173 + 17431; !seed land 0xFFF + + +exception Failed + +let test_sort sort_fun size = + let a = Array.create size 0 in + let check = Array.create 4096 0 in + for i = 0 to size-1 do + let n = random() in a.(i) <- n; check.(n) <- check.(n)+1 + done; + sort_fun 0 (size-1) a; + try + check.(a.(0)) <- check.(a.(0)) - 1; + for i = 1 to size-1 do + if a.(i-1) > a.(i) then raise Failed; + check.(a.(i)) <- check.(a.(i)) - 1 + done; + for i = 0 to 4095 do + if check.(i) <> 0 then raise Failed + done; + print_string "OK"; print_newline() + with Failed -> + print_string "failed"; print_newline() + + +let main () = + test_sort qsort 500000; + test_sort qsort2 500000 + +let _ = main(); exit 0 diff --git a/test/sieve.ml b/test/sieve.ml new file mode 100644 index 0000000..5bc4167 --- /dev/null +++ b/test/sieve.ml @@ -0,0 +1,56 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: sieve.ml,v 1.5 2005-08-12 09:22:04 xleroy Exp $ *) + +(* Eratosthene's sieve *) + +(* interval min max = [min; min+1; ...; max-1; max] *) + +let rec interval min max = + if min > max then [] else min :: interval (min + 1) max + + +(* filter p L returns the list of the elements in list L + that satisfy predicate p *) + +let rec filter p = function + [] -> [] + | a::r -> if p a then a :: filter p r else filter p r + + +(* Application: removing all numbers multiple of n from a list of integers *) + +let remove_multiples_of n = + filter (fun m -> m mod n <> 0) + + +(* The sieve itself *) + +let sieve max = + let rec filter_again = function + [] -> [] + | n::r as l -> + if n*n > max then l else n :: filter_again (remove_multiples_of n r) + in + filter_again (interval 2 max) + + +let rec do_list f = function + [] -> () + | a::l -> f a; do_list f l + + +let _ = + do_list (fun n -> print_int n; print_string " ") (sieve 50000); + print_newline(); + exit 0 diff --git a/test/soli.ml b/test/soli.ml new file mode 100644 index 0000000..cff5864 --- /dev/null +++ b/test/soli.ml @@ -0,0 +1,111 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: soli.ml,v 1.4 1999-11-17 18:58:34 xleroy Exp $ *) + + +type peg = Out | Empty | Peg + +let board = [| + [| Out; Out; Out; Out; Out; Out; Out; Out; Out|]; + [| Out; Out; Out; Peg; Peg; Peg; Out; Out; Out|]; + [| Out; Out; Out; Peg; Peg; Peg; Out; Out; Out|]; + [| Out; Peg; Peg; Peg; Peg; Peg; Peg; Peg; Out|]; + [| Out; Peg; Peg; Peg; Empty; Peg; Peg; Peg; Out|]; + [| Out; Peg; Peg; Peg; Peg; Peg; Peg; Peg; Out|]; + [| Out; Out; Out; Peg; Peg; Peg; Out; Out; Out|]; + [| Out; Out; Out; Peg; Peg; Peg; Out; Out; Out|]; + [| Out; Out; Out; Out; Out; Out; Out; Out; Out|] +|] + + +let print_peg = function + Out -> print_string "." + | Empty -> print_string " " + | Peg -> print_string "$" + + +let print_board board = + for i=0 to 8 do + for j=0 to 8 do + print_peg board.(i).(j) + done; + print_newline() + done + + +type direction = { dx: int; dy: int } + +let dir = [| {dx = 0; dy = 1}; {dx = 1; dy = 0}; + {dx = 0; dy = -1}; {dx = -1; dy = 0} |] + +type move = { x1: int; y1: int; x2: int; y2: int } + +let moves = Array.create 31 {x1=0;y1=0;x2=0;y2=0} + +let counter = ref 0 + +exception Found + +let rec solve m = + counter := !counter + 1; + if m = 31 then + begin match board.(4).(4) with Peg -> true | _ -> false end + else + try + if !counter mod 500 = 0 then begin + print_int !counter; print_newline() + end; + for i=1 to 7 do + for j=1 to 7 do + match board.(i).(j) with + Peg -> + for k=0 to 3 do + let d1 = dir.(k).dx in + let d2 = dir.(k).dy in + let i1 = i+d1 in + let i2 = i1+d1 in + let j1 = j+d2 in + let j2 = j1+d2 in + match board.(i1).(j1) with + Peg -> + begin match board.(i2).(j2) with + Empty -> +(* + print_int i; print_string ", "; + print_int j; print_string ") dir "; + print_int k; print_string "\n"; +*) + board.(i).(j) <- Empty; + board.(i1).(j1) <- Empty; + board.(i2).(j2) <- Peg; + if solve(m+1) then begin + moves.(m) <- { x1=i; y1=j; x2=i2; y2=j2 }; + raise Found + end; + board.(i).(j) <- Peg; + board.(i1).(j1) <- Peg; + board.(i2).(j2) <- Empty + | _ -> () + end + | _ -> () + done + | _ -> + () + done + done; + false + with Found -> + true + + +let _ = if solve 0 then (print_string "\n"; print_board board) diff --git a/test/sorts.ml b/test/sorts.ml new file mode 100644 index 0000000..04ff00c --- /dev/null +++ b/test/sorts.ml @@ -0,0 +1,4477 @@ +(* Test bench for sorting algorithms. *) + + +(* + ocamlopt -noassert sorts.ml -cclib -lunix +*) + +open Printf;; + +(* + Criteres: + 0. overhead en pile: doit etre logn au maximum. + 1. stable ou non. + 2. overhead en espace. + 3. vitesse. +*) + +(************************************************************************) +(* auxiliary functions *) + +let rec exp2 n = if n <= 0 then 1 else 2 * exp2 (n-1);; +let id x = x;; +let postl x y = Array.of_list y;; +let posta x y = x;; + +let mkconst n = Array.make n 0;; +let chkconst _ n a = (a = mkconst n);; + +let mksorted n = + let a = Array.make n 0 in + for i = 0 to n - 1 do + a.(i) <- i; + done; + a +;; +let chksorted _ n a = (a = mksorted n);; + +let mkrev n = + let a = Array.make n 0 in + for i = 0 to n - 1 do + a.(i) <- n - 1 - i; + done; + a +;; +let chkrev _ n a = (a = mksorted n);; + +let seed = ref 0;; +let random_reinit () = Random.init !seed;; + +let random_get_state () = + let a = Array.make 55 0 in + for i = 0 to 54 do a.(i) <- Random.bits (); done; + Random.full_init a; + a +;; +let random_set_state a = Random.full_init a;; + +let chkgen mke cmp rstate n a = + let marks = Array.make n (-1) in + let skipmarks l = + if marks.(l) = -1 then l else begin + let m = ref marks.(l) in + while marks.(!m) <> -1 do incr m; done; + marks.(l) <- !m; + !m + end + in + let linear e l = + let l = skipmarks l in + let rec loop l = + if cmp a.(l) e > 0 then raise Exit + else if e = a.(l) then marks.(l) <- l+1 + else loop (l+1) + in loop l + in + let rec dicho e l r = + if l = r then linear e l + else begin + assert (l < r); + let m = (l + r) / 2 in + if cmp a.(m) e >= 0 then dicho e l m else dicho e (m + 1) r + end + in + try + for i = 0 to n-2 do if cmp a.(i) a.(i+1) > 0 then raise Exit; done; + random_set_state rstate; + for i = 0 to n-1 do dicho (mke i) 0 (Array.length a - 1); done; + true + with Exit | Invalid_argument _ -> false; +;; + +let mkrand_dup n = + let a = Array.make n 0 in + for i = 0 to (n-1) do a.(i) <- Random.int n; done; + a +;; + +let chkrand_dup rstate n a = + chkgen (fun i -> Random.int n) compare rstate n a +;; + +let mkrand_nodup n = + let a = Array.make n 0 in + for i = 0 to (n-1) do a.(i) <- Random.bits (); done; + a +;; + +let chkrand_nodup rstate n a = + chkgen (fun i -> Random.bits ()) compare rstate n a +;; + +let mkfloats n = + let a = Array.make n 0.0 in + for i = 0 to (n-1) do a.(i) <- Random.float 1.0; done; + a +;; + +let chkfloats rstate n a = + chkgen (fun i -> Random.float 1.0) compare rstate n a +;; + +type record = { + s1 : string; + s2 : string; + i1 : int; + i2 : int; +};; + +let rand_string () = + let len = Random.int 10 in + let s = String.create len in + for i = 0 to len-1 do + s.[i] <- Char.chr (Random.int 256); + done; + s +;; + +let mkrec1 b i = { + s1 = rand_string (); + s2 = rand_string (); + i1 = Random.int b; + i2 = i; +};; + +let mkrecs b n = Array.init n (mkrec1 b);; + +let mkrec1_rev b i = { + s1 = rand_string (); + s2 = rand_string (); + i1 = - i; + i2 = i; +};; + +let mkrecs_rev n = Array.init n (mkrec1_rev 0);; + +let cmpstr r1 r2 = + let c1 = compare r1.s1 r2.s1 in + if c1 = 0 then compare r1.s2 r2.s2 else c1 +;; +let lestr r1 r2 = + let c1 = compare r1.s1 r2.s1 in + if c1 = 0 then r1.s2 <= r2.s2 else (c1 < 0) +;; +let chkstr b rstate n a = chkgen (mkrec1 b) cmpstr rstate n a;; + +let cmpint r1 r2 = compare r1.i1 r2.i1;; +let leint r1 r2 = r1.i1 <= r2.i1;; +let chkint b rstate n a = chkgen (mkrec1 b) cmpint rstate n a;; + +let cmplex r1 r2 = + let c1 = compare r1.i1 r2.i1 in + if c1 = 0 then compare r1.i2 r2.i2 else c1 +;; +let lelex r1 r2 = + let c1 = compare r1.i1 r2.i1 in + if c1 = 0 then r1.i2 <= r2.i2 else (c1 < 0) +;; +let chklex b rstate n a = chkgen (mkrec1 b) cmplex rstate n a;; + +(************************************************************************) + +let lens = [ + 0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 28; + 100; 127; 128; 129; 191; 192; 193; 506; + 1000; 1023; 1024; 1025; 1535; 1536; 1537; 2323; + 4000; 4094; 4096; 4098; 5123; +];; + +type ('a, 'b, 'c, 'd) aux = { + prepf : ('a -> 'a -> int) -> ('a -> 'a -> bool) -> 'b; + prepd : 'a array -> 'c; + postd : 'a array -> 'd -> 'a array; +};; + +let ll = { prepf = (fun x y -> y); prepd = Array.to_list; postd = postl };; +let lc = { prepf = (fun x y -> x); prepd = Array.to_list; postd = postl };; +let al = { prepf = (fun x y -> y); prepd = id; postd = posta };; +let ac = { prepf = (fun x y -> x); prepd = id; postd = posta };; + +type 'a outcome = Value of 'a | Exception of exn;; + +let numfailed = ref 0;; + +let test1 name f prepdata postdata cmp desc mk chk = + random_reinit (); + printf " %s with %s" name desc; + let i = ref 0 in + List.iter (fun n -> + if !i = 0 then printf "\n "; incr i; if !i > 11 then i := 0; + printf "%5d" n; flush stdout; + let rstate = random_get_state () in + let a = mk n in + let input = prepdata a in + let output = try Value (f cmp input) with e -> Exception e in + printf "."; flush stdout; + begin match output with + | Value v -> + if not (chk rstate n (postdata a v)) + then (incr numfailed; printf "\n*** FAIL\n") + | Exception e -> + incr numfailed; printf "\n*** %s\n" (Printexc.to_string e) + end; + flush stdout; + ) lens; + printf "\n"; +;; + +let test name stable f1 f2 aux1 aux2 = + printf "Testing %s...\n" name; + let t a b c d = test1 name f1 aux1.prepd aux1.postd a b c d in + let cmp = aux1.prepf compare (<=) in + t cmp "constant ints" mkconst chkconst; + t cmp "sorted ints" mksorted chksorted; + t cmp "reverse-sorted ints" mkrev chkrev; + t cmp "random ints (many dups)" mkrand_dup chkrand_dup; + t cmp "random ints (few dups)" mkrand_nodup chkrand_nodup; +(* + let t a b c d = test1 name f3 aux3.prepd aux3.postd a b c d in + t cmp "random floats" mkfloats chkfloats; +*) + let t a b c d = test1 name f2 aux2.prepd aux2.postd a b c d in + let cmp = aux2.prepf cmpstr lestr in + t cmp "records (str)" (mkrecs 1) (chkstr 1); + let cmp = aux2.prepf cmpint leint in + List.iter (fun m -> t cmp (sprintf "records (int[%d])" m) (mkrecs m) + (chkint m) + ) [1; 10; 100; 1000]; + if stable then + List.iter (fun m -> t cmp (sprintf "records (int[%d]) [stable]" m) + (mkrecs m) (chklex m) + ) [1; 10; 100; 1000]; +;; + +(************************************************************************) + +(* Warning: rpt_timer cannot be used for the array sorts because + the sorting functions have effects. +*) + +let rpt_timer1 repeat f x = + Gc.compact (); + ignore (f x); + let st = Sys.time () in + for i = 1 to repeat do ignore (f x); done; + let en = Sys.time () in + en -. st +;; + +let rpt_timer f x = + let repeat = ref 1 in + let t = ref (rpt_timer1 !repeat f x) in + while !t < 0.2 do + repeat := 10 * !repeat; + t := rpt_timer1 !repeat f x; + done; + if !t < 2.0 then begin + repeat := (int_of_float (10. *. (float !repeat) /. !t) + 1); + t := rpt_timer1 !repeat f x; + end; + !t /. (float !repeat) +;; + +let timer f x = + let st = Sys.time () in + ignore (f x); + let en = Sys.time () in + (en -. st) +;; + +let table1 limit f mkarg = + printf " %10s %9s %9s %9s %9s %9s\n" "n" "t1" "t2" "t3" "t4" "t5"; + let sz = ref 49151 in + while !sz < int_of_float (2. ** float limit) do + begin try + printf " %10d " !sz; flush stdout; + for i = 0 to 4 do + let arg = mkarg !sz in + let t = timer f arg in + printf " %.2e " t; flush stdout; + done; + printf "\n"; + with e -> printf "*** %s\n" (Printexc.to_string e); + end; + flush stdout; + sz := 2 * !sz + 1; + done; +;; + +let table2 limit f mkarg = + printf " %10s %9s %9s %9s %9s %9s\n" + " n" "t" "t/n" "t/nlogn" "t/nlog^2n" "t/n^2"; + let sz = ref 49151 in + while float !sz < 2. ** float limit do + begin try + printf " %10d " !sz; flush stdout; + Gc.compact (); + let arg = mkarg !sz in + let t = timer f arg in + let n = float !sz in + let logn = log (float !sz) /. log 2. in + printf "%.2e %.2e %.2e %.2e %.2e\n" + t (t/.n) (t/.n/.logn) (t/.n/.logn/.logn) (t/.n/.n); + with e -> printf "*** %s\n" (Printexc.to_string e); + end; + flush stdout; + sz := 2 * !sz + 1; + done; +;; + +let table3 limit f mkarg = + printf " %10s %9s %9s %9s %9s %9s\n" "n" "t1" "t2" "t3" "t4" "t5"; + let sz = ref 2 in + while float !sz < 2. ** float limit do + begin try + printf " %10d " !sz; flush stdout; + for i = 0 to 4 do + let arg = mkarg !sz in + let t = rpt_timer f arg in + printf " %.2e " t; flush stdout; + done; + printf "\n"; + with e -> printf "*** %s\n" (Printexc.to_string e); + end; + flush stdout; + sz := 2 * !sz + 1; + done; +;; + +(************************************************************************) + +(* benchmarks: + 1a. random records, sorted with two keys + 1b. random integers + 1c. random floats + + 2a. integers, constant + 2b. integers, already sorted + 2c. integers, reverse sorted + + only for short lists: + 3a. random records, sorted with two keys + 3b. random integers + 3c. random floats +*) +let bench1a limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random records [10]:\n" name; + let cmp = aux.prepf cmplex lelex in + table1 limit (f cmp) (fun n -> aux.prepd (mkrecs 10 n)); +;; + +let bench1b limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random integers:\n" name; + let cmp = aux.prepf (-) (<=) in + table1 limit (f cmp) (fun n -> aux.prepd (mkrand_nodup n)); +;; + +let bench1c limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random floats:\n" name; + let cmp = aux.prepf compare (<=) in + table1 limit (f cmp) (fun n -> aux.prepd (mkfloats n)); +;; + +let bench2 limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + printf "\n%s with constant integers:\n" name; + let cmp = aux.prepf compare (<=) in + table2 limit (f cmp) (fun n -> aux.prepd (mkconst n)); + + printf "\n%s with sorted integers:\n" name; + let cmp = aux.prepf compare (<=) in + table2 limit (f cmp) (fun n -> aux.prepd (mksorted n)); + + printf "\n%s with reverse-sorted integers:\n" name; + let cmp = aux.prepf compare (<=) in + table2 limit (f cmp) (fun n -> aux.prepd (mkrev n)); +;; + +let bench3a limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random records [10]:\n" name; + let cmp = aux.prepf cmplex lelex in + table3 limit (f cmp) (fun n -> aux.prepd (mkrecs 10 n)); +;; + +let bench3b limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random integers:\n" name; + let cmp = aux.prepf (-) (<=) in + table3 limit (f cmp) (fun n -> aux.prepd (mkrand_nodup n)); +;; + +let bench3c limit name f aux = + + (* Don't do benchmarks with assertions enabled. *) + assert (not true); + + random_reinit (); + + printf "\n%s with random floats:\n" name; + let cmp = aux.prepf compare (<=) in + table3 limit (f cmp) (fun n -> aux.prepd (mkfloats n)); +;; + +(************************************************************************) +(* merge sort on lists *) + +(* FIXME to do: cutoff + to do: cascader les pattern-matchings (enlever les paires) + to do: fermeture intermediaire pour merge +*) +let (@@) = List.rev_append;; + +let lmerge_1a cmp l = + let rec init accu = function + | [] -> accu + | e::rest -> init ([e] :: accu) rest + in + let rec merge rest accu2 accu l1 l2 = (* l1,l2,rest are forward; + accu,accu2 are rev *) + match l1, l2 with + | [] , _ -> mergepairs ((l2 @@ accu)::accu2) rest + | _ , [] -> mergepairs ((l1 @@ accu)::accu2) rest + | h1::t1, h2::t2 -> if cmp h1 h2 <= 0 + then merge rest accu2 (h1::accu) t1 l2 + else merge rest accu2 (h2::accu) l1 t2 + and merge_rev rest accu2 accu l1 l2 = (* accu, accu2 are forward; + l1,l2,rest are rev *) + match l1, l2 with + | [] , _ -> mergepairs_rev ((l2 @@ accu)::accu2) rest + | _ , [] -> mergepairs_rev ((l1 @@ accu)::accu2) rest + | h1::t1, h2::t2 -> if cmp h2 h1 <= 0 + then merge_rev rest accu2 (h1::accu) t1 l2 + else merge_rev rest accu2 (h2::accu) l1 t2 + and mergepairs accu = function (* accu is rev, arg is forward *) + | [] -> mergeall_rev accu + | [l] -> mergeall_rev ((List.rev l)::accu) + | l1::l2::rest -> merge rest accu [] l1 l2 + and mergepairs_rev accu = function (* accu is forward, arg is rev *) + | [] -> mergeall accu + | [l] -> mergeall ((List.rev l)::accu) + | l1::l2::rest -> merge_rev rest accu [] l1 l2 + and mergeall = function (* arg is forward *) + | [] -> [] + | [l] -> l + | llist -> mergepairs [] llist + and mergeall_rev = function (* arg is rev *) + | [] -> [] + | [l] -> List.rev l + | llist -> mergepairs_rev [] llist + in + mergeall_rev (init [] l) +;; + +let lmerge_1b cmp l = + let rec init accu = function + | [] -> accu + | [e] -> [e] :: accu + | e1::e2::rest -> + init ((if cmp e1 e2 <= 0 then [e2;e1] else [e1;e2])::accu) rest + in + let rec merge rest accu2 accu l1 l2 = (* l1,l2,rest are forward; + accu,accu2 are rev *) + match l1, l2 with + | [] , _ -> mergepairs ((l2 @@ accu)::accu2) rest + | _ , [] -> mergepairs ((l1 @@ accu)::accu2) rest + | h1::t1, h2::t2 -> if cmp h1 h2 <= 0 + then merge rest accu2 (h1::accu) t1 l2 + else merge rest accu2 (h2::accu) l1 t2 + and merge_rev rest accu2 accu l1 l2 = (* accu, accu2 are forward; + l1,l2,rest are rev *) + match l1, l2 with + | [] , _ -> mergepairs_rev ((l2 @@ accu)::accu2) rest + | _ , [] -> mergepairs_rev ((l1 @@ accu)::accu2) rest + | h1::t1, h2::t2 -> if cmp h2 h1 <= 0 + then merge_rev rest accu2 (h1::accu) t1 l2 + else merge_rev rest accu2 (h2::accu) l1 t2 + and mergepairs accu = function (* accu is rev, arg is forward *) + | [] -> mergeall_rev accu + | [l] -> mergeall_rev ((List.rev l)::accu) + | l1::l2::rest -> merge rest accu [] l1 l2 + and mergepairs_rev accu = function (* accu is forward, arg is rev *) + | [] -> mergeall accu + | [l] -> mergeall ((List.rev l)::accu) + | l1::l2::rest -> merge_rev rest accu [] l1 l2 + and mergeall = function (* arg is forward *) + | [] -> [] + | [l] -> l + | llist -> mergepairs [] llist + and mergeall_rev = function (* arg is rev *) + | [] -> [] + | [l] -> List.rev l + | llist -> mergepairs_rev [] llist + in + mergeall_rev (init [] l) +;; + +let lmerge_1c cmp l = + let rec init accu = function + | [] -> accu + | [e] -> [e] :: accu + | e1::e2::rest -> + init ((if cmp e1 e2 <= 0 then [e2;e1] else [e1;e2])::accu) rest + in + let rec merge rest accu2 accu l1 l2 = (* l1,l2,rest are forward; + accu,accu2 are rev *) + match l1 with + | [] -> mergepairs ((l2 @@ accu)::accu2) rest + | h1::t1 -> + match l2 with + | [] -> mergepairs ((l1 @@ accu)::accu2) rest + | h2::t2 -> if cmp h1 h2 <= 0 + then merge rest accu2 (h1::accu) t1 l2 + else merge rest accu2 (h2::accu) l1 t2 + and merge_rev rest accu2 accu l1 l2 = (* accu, accu2 are forward; + l1,l2,rest are rev *) + match l1 with + | [] -> mergepairs_rev ((l2 @@ accu)::accu2) rest + | h1::t1 -> + match l2 with + | [] -> mergepairs_rev ((l1 @@ accu)::accu2) rest + | h2::t2 -> if cmp h2 h1 <= 0 + then merge_rev rest accu2 (h1::accu) t1 l2 + else merge_rev rest accu2 (h2::accu) l1 t2 + and mergepairs accu = function (* accu is rev, arg is forward *) + | [] -> mergeall_rev accu + | [l] -> mergeall_rev ((List.rev l)::accu) + | l1::l2::rest -> merge rest accu [] l1 l2 + and mergepairs_rev accu = function (* accu is forward, arg is rev *) + | [] -> mergeall accu + | [l] -> mergeall ((List.rev l)::accu) + | l1::l2::rest -> merge_rev rest accu [] l1 l2 + and mergeall = function (* arg is forward *) + | [] -> [] + | [l] -> l + | llist -> mergepairs [] llist + and mergeall_rev = function (* arg is rev *) + | [] -> [] + | [l] -> List.rev l + | llist -> mergepairs_rev [] llist + in + mergeall_rev (init [] l) +;; + +let lmerge_1d cmp l = + let rec init accu = function + | [] -> accu + | [e] -> [e] :: accu + | e1::e2::rest -> + init ((if cmp e1 e2 <= 0 then [e2;e1] else [e1;e2])::accu) rest + in + let rec merge rest accu2 accu l1 l2 = (* l1,l2,rest are forward; + accu,accu2 are rev *) + let merge_rest_accu2 accu l1 l2 = + match l1 with + | [] -> mergepairs ((l2 @@ accu)::accu2) rest + | h1::t1 -> + match l2 with + | [] -> mergepairs ((l1 @@ accu)::accu2) rest + | h2::t2 -> if cmp h1 h2 <= 0 + then merge rest accu2 (h1::accu) t1 l2 + else merge rest accu2 (h2::accu) l1 t2 + in merge_rest_accu2 accu l1 l2 + and merge_rev rest accu2 accu l1 l2 = (* accu, accu2 are forward; + l1,l2,rest are rev *) + let merge_rev_rest_accu2 accu l1 l2 = + match l1 with + | [] -> mergepairs_rev ((l2 @@ accu)::accu2) rest + | h1::t1 -> + match l2 with + | [] -> mergepairs_rev ((l1 @@ accu)::accu2) rest + | h2::t2 -> if cmp h2 h1 <= 0 + then merge_rev rest accu2 (h1::accu) t1 l2 + else merge_rev rest accu2 (h2::accu) l1 t2 + in merge_rev_rest_accu2 accu l1 l2 + and mergepairs accu = function (* accu is rev, arg is forward *) + | [] -> mergeall_rev accu + | [l] -> mergeall_rev ((List.rev l)::accu) + | l1::l2::rest -> merge rest accu [] l1 l2 + and mergepairs_rev accu = function (* accu is forward, arg is rev *) + | [] -> mergeall accu + | [l] -> mergeall ((List.rev l)::accu) + | l1::l2::rest -> merge_rev rest accu [] l1 l2 + and mergeall = function (* arg is forward *) + | [] -> [] + | [l] -> l + | llist -> mergepairs [] llist + and mergeall_rev = function (* arg is rev *) + | [] -> [] + | [l] -> List.rev l + | llist -> mergepairs_rev [] llist + in + mergeall_rev (init [] l) +;; + +(************************************************************************) +(* merge sort on lists, user-contributed (NOT STABLE) *) + +(* BEGIN code contributed by Yann Coscoy *) + + let rec rev_merge_append order l1 l2 acc = + match l1 with + [] -> List.rev_append l2 acc + | h1 :: t1 -> + match l2 with + [] -> List.rev_append l1 acc + | h2 :: t2 -> + if order h1 h2 + then rev_merge_append order t1 l2 (h1::acc) + else rev_merge_append order l1 t2 (h2::acc) + + let rev_merge order l1 l2 = rev_merge_append order l1 l2 [] + + let rec rev_merge_append' order l1 l2 acc = + match l1 with + | [] -> List.rev_append l2 acc + | h1 :: t1 -> + match l2 with + | [] -> List.rev_append l1 acc + | h2 :: t2 -> + if order h2 h1 + then rev_merge_append' order t1 l2 (h1::acc) + else rev_merge_append' order l1 t2 (h2::acc) + + let rev_merge' order l1 l2 = rev_merge_append' order l1 l2 [] + + let lmerge_3 order l = + let rec initlist l acc = match l with + | e1::e2::rest -> + initlist rest + ((if order e1 e2 then [e1;e2] else [e2;e1])::acc) + | [e] -> [e]::acc + | [] -> acc + in + let rec merge2 ll acc = match ll with + | [] -> acc + | [l] -> [List.rev l]@acc + | l1::l2::rest -> + merge2 rest (rev_merge order l1 l2::acc) + in + let rec merge2' ll acc = match ll with + | [] -> acc + | [l] -> [List.rev l]@acc + | l1::l2::rest -> + merge2' rest (rev_merge' order l1 l2::acc) + in + let rec mergeall rev = function + | [] -> [] + | [l] -> if rev then List.rev l else l + | llist -> + mergeall + (not rev) ((if rev then merge2' else merge2) llist []) + in + mergeall false (initlist l []) + +(* END code contributed by Yann Coscoy *) + +(************************************************************************) +(* merge sort on short lists, Francois Pottier *) + +(* BEGIN code contributed by Francois Pottier *) + + (* [chop k l] returns the list [l] deprived of its [k] first + elements. The length of the list [l] must be [k] at least. *) + + let rec chop k l = + match k, l with + | 0, _ -> l + | _, x :: l -> chop (k-1) l + | _, _ -> assert false + ;; + + let rec merge order l1 l2 = + match l1 with + [] -> l2 + | h1 :: t1 -> + match l2 with + [] -> l1 + | h2 :: t2 -> + if order h1 h2 + then h1 :: merge order t1 l2 + else h2 :: merge order l1 t2 + ;; + + let rec lmerge_4a order l = + match l with + | [] + | [ _ ] -> l + | _ -> + let rec sort k l = (* k > 1 *) + match k, l with + | 2, x1 :: x2 :: _ -> + if order x1 x2 then [ x1; x2 ] else [ x2; x1 ] + | 3, x1 :: x2 :: x3 :: _ -> + if order x1 x2 then + if order x2 x3 then + [ x1 ; x2 ; x3 ] + else + if order x1 x3 then [ x1 ; x3 ; x2 ] else [ x3; x1; x2 ] + else + if order x1 x3 then + [ x2; x1; x3 ] + else + if order x2 x3 then [ x2; x3; x1 ] else [ x3; x2; x1 ] + | _, _ -> + let k1 = k / 2 in + let k2 = k - k1 in + merge order (sort k1 l) (sort k2 (chop k1 l)) + in + sort (List.length l) l + ;; +(* END code contributed by Francois Pottier *) + +(************************************************************************) +(* merge sort on short lists, Francois Pottier, + adapted to new-style interface *) + +(* BEGIN code contributed by Francois Pottier *) + + (* [chop k l] returns the list [l] deprived of its [k] first + elements. The length of the list [l] must be [k] at least. *) + + let rec chop k l = + match k, l with + | 0, _ -> l + | _, x :: l -> chop (k-1) l + | _, _ -> assert false + ;; + + let rec merge order l1 l2 = + match l1 with + [] -> l2 + | h1 :: t1 -> + match l2 with + [] -> l1 + | h2 :: t2 -> + if order h1 h2 <= 0 + then h1 :: merge order t1 l2 + else h2 :: merge order l1 t2 + ;; + + let rec lmerge_4b order l = + match l with + | [] + | [ _ ] -> l + | _ -> + let rec sort k l = (* k > 1 *) + match k, l with + | 2, x1 :: x2 :: _ -> + if order x1 x2 <= 0 then [ x1; x2 ] else [ x2; x1 ] + | 3, x1 :: x2 :: x3 :: _ -> + if order x1 x2 <= 0 then + if order x2 x3 <= 0 then + [ x1 ; x2 ; x3 ] + else + if order x1 x3 <= 0 then [ x1 ; x3 ; x2 ] else [ x3; x1; x2 ] + else + if order x1 x3 <= 0 then + [ x2; x1; x3 ] + else + if order x2 x3 <= 0 then [ x2; x3; x1 ] else [ x3; x2; x1 ] + | _, _ -> + let k1 = k / 2 in + let k2 = k - k1 in + merge order (sort k1 l) (sort k2 (chop k1 l)) + in + sort (List.length l) l + ;; +(* END code contributed by Francois Pottier *) + +(************************************************************************) +(* merge sort on short lists a la Pottier, modified merge *) + +let rec chop k l = + if k = 0 then l else begin + match l with + | x::t -> chop (k-1) t + | _ -> assert false + end +;; + +let lmerge_4c cmp l = + let rec merge1 h1 t1 l2 = + match l2 with + | [] -> h1 :: t1 + | h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: (merge2 t1 h2 t2) + else h2 :: (merge1 h1 t1 t2) + and merge2 l1 h2 t2 = + match l1 with + | [] -> h2 :: t2 + | h1 :: t1 -> + if cmp h1 h2 <= 0 + then h1 :: (merge2 t1 h2 t2) + else h2 :: (merge1 h1 t1 t2) + in + let merge l1 = function + | [] -> l1 + | h2 :: t2 -> merge2 l1 h2 t2 + in + let rec sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 <= 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 <= 0 then begin + if cmp x2 x3 <= 0 then [x1; x2; x3] + else if cmp x1 x3 <= 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 <= 0 then [x2; x1; x3] + else if cmp x2 x3 <= 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + merge (sort n1 l) (sort n2 (chop n1 l)) + in + let len = List.length l in + if len < 2 then l else sort len l +;; + +(************************************************************************) +(* merge sort on short lists a la Pottier, logarithmic stack space *) + +let rec chop k l = + if k = 0 then l else begin + match l with + | x::t -> chop (k-1) t + | _ -> assert false + end +;; + +let lmerge_4d cmp l = + let rec rev_merge l1 l2 accu = + match l1, l2 with + | [], l2 -> l2 @@ accu + | l1, [] -> l1 @@ accu + | h1::t1, h2::t2 -> + if cmp h1 h2 <= 0 + then rev_merge t1 l2 (h1::accu) + else rev_merge l1 t2 (h2::accu) + in + let rec rev_merge_rev l1 l2 accu = + match l1, l2 with + | [], l2 -> l2 @@ accu + | l1, [] -> l1 @@ accu + | h1::t1, h2::t2 -> + if cmp h1 h2 > 0 + then rev_merge_rev t1 l2 (h1::accu) + else rev_merge_rev l1 t2 (h2::accu) + in + let rec sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 <= 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 <= 0 then begin + if cmp x2 x3 <= 0 then [x1; x2; x3] + else if cmp x1 x3 <= 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 <= 0 then [x2; x1; x3] + else if cmp x2 x3 <= 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + rev_merge_rev (rev_sort n1 l) (rev_sort n2 (chop n1 l)) [] + and rev_sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 > 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 > 0 then begin + if cmp x2 x3 > 0 then [x1; x2; x3] + else if cmp x1 x3 > 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 > 0 then [x2; x1; x3] + else if cmp x2 x3 > 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + rev_merge (sort n1 l) (sort n2 (chop n1 l)) [] + in + let len = List.length l in + if len < 2 then l else sort len l +;; + + +(************************************************************************) +(* merge sort on short lists a la Pottier, logarithmic stack space, + in place: input list is freed as the output is being computed. *) + +let rec chop k l = + if k = 0 then l else begin + match l with + | x::t -> chop (k-1) t + | _ -> assert false + end +;; + +let lmerge_4e cmp l = + let rec rev_merge l1 l2 accu = + match l1, l2 with + | [], l2 -> l2 @@ accu + | l1, [] -> l1 @@ accu + | h1::t1, h2::t2 -> + if cmp h1 h2 <= 0 + then rev_merge t1 l2 (h1::accu) + else rev_merge l1 t2 (h2::accu) + in + let rec rev_merge_rev l1 l2 accu = + match l1, l2 with + | [], l2 -> l2 @@ accu + | l1, [] -> l1 @@ accu + | h1::t1, h2::t2 -> + if cmp h1 h2 > 0 + then rev_merge_rev t1 l2 (h1::accu) + else rev_merge_rev l1 t2 (h2::accu) + in + let rec sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 <= 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 <= 0 then begin + if cmp x2 x3 <= 0 then [x1; x2; x3] + else if cmp x1 x3 <= 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 <= 0 then [x2; x1; x3] + else if cmp x2 x3 <= 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + let l2 = chop n1 l in + let s1 = rev_sort n1 l in + let s2 = rev_sort n2 l2 in + rev_merge_rev s1 s2 [] + and rev_sort n l = + match n, l with + | 2, x1 :: x2 :: _ -> + if cmp x1 x2 > 0 then [x1; x2] else [x2; x1] + | 3, x1 :: x2 :: x3 :: _ -> + if cmp x1 x2 > 0 then begin + if cmp x2 x3 > 0 then [x1; x2; x3] + else if cmp x1 x3 > 0 then [x1; x3; x2] + else [x3; x1; x2] + end else begin + if cmp x1 x3 > 0 then [x2; x1; x3] + else if cmp x2 x3 > 0 then [x2; x3; x1] + else [x3; x2; x1] + end + | n, l -> + let n1 = n asr 1 in + let n2 = n - n1 in + let l2 = chop n1 l in + let s1 = sort n1 l in + let s2 = sort n2 l2 in + rev_merge s1 s2 [] + in + let len = List.length l in + if len < 2 then l else sort len l +;; + +(************************************************************************) +(* chop-free version of Pottier's code, binary version *) + +let rec merge cmp l1 l2 = + match l1, l2 with + | [], l2 -> l2 + | l1, [] -> l1 + | h1 :: t1, h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: merge cmp t1 l2 + else h2 :: merge cmp l1 t2 +;; + +let lmerge_5a cmp l = + let rem = ref l in + let rec sort_prefix n = + if n <= 1 then begin + match !rem with + | [] -> [] + | [x] as l -> rem := []; l + | x::y::t -> rem := t; if cmp x y <= 0 then [x;y] else [y;x] + end else if !rem = [] then [] + else begin + let l1 = sort_prefix (n-1) in + let l2 = sort_prefix (n-1) in + merge cmp l1 l2 + end + in + let len = ref (List.length l) in + let i = ref 0 in + while !len > 0 do incr i; len := !len lsr 1; done; + sort_prefix !i +;; + +(************************************************************************) +(* chop-free version of Pottier's code, dichotomic version, + ground cases 1 & 2 *) + +let rec merge cmp l1 l2 = + match l1, l2 with + | [], l2 -> l2 + | l1, [] -> l1 + | h1 :: t1, h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: merge cmp t1 l2 + else h2 :: merge cmp l1 t2 +;; + +let lmerge_5b cmp l = + let rem = ref l in + let rec sort_prefix n = + match n, !rem with + | 1, x::t -> rem := t; [x] + | 2, x::y::t -> rem := t; if cmp x y <= 0 then [x;y] else [y;x] + | n, _ -> + let n1 = n/2 in + let n2 = n - n1 in + let l1 = sort_prefix n1 in + let l2 = sort_prefix n2 in + merge cmp l1 l2 + in + let len = List.length l in + if len <= 1 then l else sort_prefix len +;; + +(************************************************************************) +(* chop-free version of Pottier's code, dichotomic version, + ground cases 2 & 3 *) + +let rec merge cmp l1 l2 = + match l1, l2 with + | [], l2 -> l2 + | l1, [] -> l1 + | h1 :: t1, h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: merge cmp t1 l2 + else h2 :: merge cmp l1 t2 +;; + +let lmerge_5c cmp l = + let rem = ref l in + let rec sort_prefix n = + match n, !rem with + | 2, x::y::t -> rem := t; if cmp x y <= 0 then [x;y] else [y;x] + | 3, x::y::z::t -> + rem := t; + if cmp x y <= 0 then + if cmp y z <= 0 then [x; y; z] + else if cmp x z <= 0 then [x; z; y] + else [z; x; y] + else + if cmp x z <= 0 then [y; x; z] + else if cmp y z <= 0 then [y; z; x] + else [z; y; x] + | n, _ -> + let n1 = n/2 in + let n2 = n - n1 in + let l1 = sort_prefix n1 in + let l2 = sort_prefix n2 in + merge cmp l1 l2 + in + let len = List.length l in + if len <= 1 then l else sort_prefix len +;; + +(************************************************************************) +(* chop-free, ref-free version of Pottier's code, dichotomic version, + ground cases 2 & 3, modified merge *) + +let lmerge_5d cmp l = + let rec merge1 h1 t1 l2 = + match l2 with + | [] -> h1::t1 + | h2 :: t2 -> + if cmp h1 h2 <= 0 + then h1 :: merge2 t1 h2 t2 + else h2 :: merge1 h1 t1 t2 + and merge2 l1 h2 t2 = + match l1 with + | [] -> h2::t2 + | h1 :: t1 -> + if cmp h1 h2 <= 0 + then h1 :: merge2 t1 h2 t2 + else h2 :: merge1 h1 t1 t2 + in + let rec sort_prefix n l = + match n, l with + | 2, x::y::t -> ((if cmp x y <= 0 then [x;y] else [y;x]), t) + | 3, x::y::z::t -> + ((if cmp x y <= 0 then + if cmp y z <= 0 then [x; y; z] + else if cmp x z <= 0 then [x; z; y] + else [z; x; y] + else + if cmp x z <= 0 then [y; x; z] + else if cmp y z <= 0 then [y; z; x] + else [z; y; x]), + t) + | n, _ -> + let n1 = n/2 in + let n2 = n - n1 in + let (l1, rest1) = sort_prefix n1 l in + match sort_prefix n2 rest1 with + | (h2::t2, rest2) -> ((merge2 l1 h2 t2), rest2) + | _ -> assert false + in + let len = List.length l in + if len <= 1 then l else fst (sort_prefix len l) +;; + +(************************************************************************) +(* merge sort on arrays, merge with tail-rec function *) + +let amerge_1a cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let rec sortto srcofs dst dstofs len = + assert (len > 0); + if len = 1 then dst.(dstofs) <- a.(srcofs) + else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= 1 then () + else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let amerge_1b cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let rec sortto srcofs dst dstofs len = + assert (len > 0); + if len = 1 then dst.(dstofs) <- a.(srcofs) + else if len = 2 then begin + if cmp a.(srcofs) a.(srcofs+1) <= 0 then begin + dst.(dstofs) <- a.(srcofs); + dst.(dstofs+1) <- a.(srcofs+1); + end else begin + dst.(dstofs) <- a.(srcofs+1); + dst.(dstofs+1) <- a.(srcofs); + end; + end else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= 1 then () + else if l = 2 then begin + if cmp a.(0) a.(1) > 0 then begin + let e = a.(0) in + a.(0) <- a.(1); + a.(1) <- e; + end; + end else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 3;; +let amerge_1c cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 4;; +let amerge_1d cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 5;; +let amerge_1e cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 6;; +let amerge_1f cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 7;; +let amerge_1g cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 8;; +let amerge_1h cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 9;; +let amerge_1i cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 10;; +let amerge_1j cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let src1r = src1ofs + src1len and src2r = src2ofs + src2len in + let rec loop i1 s1 i2 s2 d = + if cmp s1 s2 <= 0 then begin + dst.(d) <- s1; + let i1 = i1 + 1 in + if i1 < src1r then + loop i1 a.(i1) i2 s2 (d + 1) + else + Array.blit src2 i2 dst (d + 1) (src2r - i2) + end else begin + dst.(d) <- s2; + let i2 = i2 + 1 in + if i2 < src2r then + loop i1 s1 i2 src2.(i2) (d + 1) + else + Array.blit a i1 dst (d + 1) (src1r - i1) + end + in loop src1ofs a.(src1ofs) src2ofs src2.(src2ofs) dstofs; + in + let isortto srcofs dst dstofs len = + for i = 0 to len - 1 do + let e = a.(srcofs + i) in + let j = ref (dstofs + i - 1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs + l1) dst (dstofs + l1) l2; + sortto srcofs a (srcofs + l2) l1; + merge (srcofs + l2) l1 dst (dstofs + l1) l2 dst dstofs; + end; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +(* FIXME a essayer: *) +(* list->array->list direct et array->list->array direct *) +(* overhead = 1/3, 1/4, etc. *) +(* overhead = sqrt (n) *) +(* overhead = n/3 jusqu'a 30k, 30k jusqu'a 900M, sqrt (n) au-dela *) + +(************************************************************************) +(* merge sort on arrays, merge with loop *) + +(* cutoff = 1 *) +let amerge_3a cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let rec sortto srcofs dst dstofs len = + assert (len > 0); + if len = 1 then dst.(dstofs) <- a.(srcofs) else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= 1 then () else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let amerge_3b cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let rec sortto srcofs dst dstofs len = + assert (len > 0); + if len = 1 then dst.(dstofs) <- a.(srcofs) + else if len = 2 then begin + if cmp a.(srcofs) a.(srcofs+1) <= 0 then begin + dst.(dstofs) <- a.(srcofs); + dst.(dstofs+1) <- a.(srcofs+1); + end else begin + dst.(dstofs) <- a.(srcofs+1); + dst.(dstofs+1) <- a.(srcofs); + end + end else begin + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + end + in + let l = Array.length a in + if l <= 1 then () + else if l = 2 then begin + if cmp a.(0) a.(1) > 0 then begin + let e = a.(0) in + a.(0) <- a.(1); + a.(1) <- e; + end; + end else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 3;; +let amerge_3c cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 4;; +let amerge_3d cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 5;; +let amerge_3e cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 6;; +let amerge_3f cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 7;; +let amerge_3g cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 8;; +let amerge_3h cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 9;; +let amerge_3i cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +let cutoff = 10;; +let amerge_3j cmp a = + let merge src1ofs src1len src2 src2ofs src2len dst dstofs = + let i1 = ref src1ofs + and i2 = ref src2ofs + and d = ref dstofs + and src1r = src1ofs + src1len + and src2r = src2ofs + src2len + in + while !i1 < src1r && !i2 < src2r do + let s1 = a.(!i1) and s2 = src2.(!i2) in + if cmp s1 s2 <= 0 then begin + dst.(!d) <- s1; + incr i1; + end else begin + dst.(!d) <- s2; + incr i2; + end; + incr d; + done; + if !i1 < src1r then + Array.blit a !i1 dst !d (src1r - !i1) + else + Array.blit src2 !i2 dst !d (src2r - !i2) + in + let isortto srcofs dst dstofs len = + for i = 0 to len-1 do + let e = a.(srcofs+i) in + let j = ref (dstofs+i-1) in + while (!j >= dstofs && cmp dst.(!j) e > 0) do + dst.(!j + 1) <- dst.(!j); + decr j; + done; + dst.(!j + 1) <- e; + done; + in + let rec sortto srcofs dst dstofs len = + if len <= cutoff then isortto srcofs dst dstofs len else + let l1 = len / 2 in + let l2 = len - l1 in + sortto (srcofs+l1) dst (dstofs+l1) l2; + sortto srcofs a (srcofs+l2) l1; + merge (srcofs+l2) l1 dst (dstofs+l1) l2 dst dstofs; + in + let l = Array.length a in + if l <= cutoff then isortto 0 a 0 l else begin + let l1 = l / 2 in + let l2 = l - l1 in + let t = Array.make l2 a.(0) in + sortto l1 t 0 l2; + sortto 0 a l2 l1; + merge l2 l1 t 0 l2 a 0; + end; +;; + +(* FIXME essayer bottom-up merge on arrays ? *) + +(************************************************************************) +(* Shell sort on arrays *) + +let ashell_1 cmp a = + let l = Array.length a in + let step = ref 1 in + while !step < l do step := !step * 3 + 1; done; + step := !step / 3; + while !step > 0 do + for j = !step to l-1 do + let e = a.(j) in + let k = ref (j - !step) in + let k1 = ref j in + while !k >= 0 && cmp a.(!k) e > 0 do + a.(!k1) <- a.(!k); + k1 := !k; + k := !k - !step; + done; + a.(!k1) <- e; + done; + step := !step / 3; + done; +;; + +let ashell_2 cmp a = + let l = Array.length a in + let step = ref 1 in + while !step < l do step := !step * 3 + 1; done; + step := !step / 3; + while !step > 0 do + for j = !step to l-1 do + let e = a.(j) in + let k = ref (j - !step) in + while !k >= 0 && cmp a.(!k) e > 0 do + a.(!k + !step) <- a.(!k); + k := !k - !step; + done; + a.(!k + !step) <- e; + done; + step := !step / 3; + done; +;; + +let ashell_3 cmp a = + let l = Array.length a in + let step = ref 1 in + while !step < l do step := !step * 3 + 1; done; + step := !step / 3; + while !step > 0 do + for i = 0 to !step - 1 do + let j = ref (i + !step) in + while !j < l do + let e = ref a.(!j) in + let k = ref (!j - !step) in + if cmp !e a.(i) < 0 then begin + let x = !e in e := a.(i); a.(i) <- x; + end; + while cmp a.(!k) !e > 0 do + a.(!k + !step) <- a.(!k); + k := !k - !step; + done; + a.(!k + !step) <- !e; + j := !j + !step; + done; + done; + step := !step / 3; + done; +;; + +let force = Lazy.force;; + +type iilist = Cons of int * iilist Lazy.t;; + +let rec mult n (Cons (x,l)) = Cons (n*x, lazy (mult n (force l))) + +let rec merge (Cons (x1, t1) as l1) (Cons (x2, t2) as l2) = + if x1 = x2 then Cons (x1, lazy (merge (force t1) (force t2))) + else if x1 < x2 then Cons (x1, lazy (merge (force t1) l2)) + else Cons (x2, lazy (merge l1 (force t2))) +;; + +let rec scale = Cons (1, lazy (merge (mult 2 scale) (mult 3 scale)));; + +let ashell_4 cmp a = + let l = Array.length a in + let rec loop1 accu (Cons (x, t)) = + if x > l then accu else loop1 (x::accu) (force t) + in + let sc = loop1 [] scale in + let rec loop2 = function + | [] -> () + | step::t -> + for i = 0 to step - 1 do + let j = ref (i + step) in + while !j < l do + let e = a.(!j) in + let k = ref (!j - step) in + while !k >= 0 && cmp a.(!k) e > 0 do + a.(!k + step) <- a.(!k); + k := !k - step; + done; + a.(!k + step) <- e; + j := !j + step; + done; + done; + loop2 t; + in + loop2 sc; +;; + +(************************************************************************) +(* Quicksort on arrays *) +let cutoff = 1;; +let aquick_1a cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 2;; +let aquick_1b cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 3;; +let aquick_1c cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 4;; +let aquick_1d cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 5;; +let aquick_1e cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 6;; +let aquick_1f cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 7;; +let aquick_1g cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref (r - 1) in + while !p2 <= !p3 do + let e = a.(!p3) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + end else if c < 0 then begin + a.(!p3) <- a.(!p2); + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + a.(!p3) <- a.(!p2); + a.(!p2) <- e; + incr p2; + end; + done; + incr p3; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 1 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 1;; +let aquick_2a cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 2;; +let aquick_2b cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 3;; +let aquick_2c cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 4;; +let aquick_2d cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 5;; +let aquick_2e cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 6;; +let aquick_2f cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 7;; +let aquick_2g cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end else begin + incr p2; + end; + done; + let len1 = !p1 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p1; qsort !p3 r) + else (qsort !p3 r; qsort l !p1) + end else qsort l !p1 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 1;; +let aquick_3a cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 2;; +let aquick_3b cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 3;; +let aquick_3c cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 4;; +let aquick_3d cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 5;; +let aquick_3e cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 6;; +let aquick_3f cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 7;; +let aquick_3g cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 8;; +let aquick_3h cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 9;; +let aquick_3i cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +let cutoff = 10;; +let aquick_3j cmp a = + let rec qsort l r = (* ASSUMES r - l >= 2 *) + let m = (l + r) / 2 in + let al = a.(l) and am = a.(m) and ar = a.(r - 1) in + let pivot = if cmp al am <= 0 then + if cmp am ar <= 0 then am + else if cmp al ar <= 0 then ar + else al + else + if cmp al ar <= 0 then al + else if cmp am ar <= 0 then ar + else am + in + let p1 = ref l and p2 = ref l and p3 = ref r in + while !p2 < !p3 do + let e = a.(!p2) in + let c = cmp e pivot in + if c > 0 then begin + decr p3; + a.(!p2) <- a.(!p3); + a.(!p3) <- e; + end else if c < 0 then begin + incr p2; + end else begin + a.(!p2) <- a.(!p1); + a.(!p1) <- e; + incr p1; + incr p2; + end + done; + while !p1 > l do + decr p1; + decr p2; + let e = a.(!p1) in a.(!p1) <- a.(!p2); a.(!p2) <- e; + done; + let len1 = !p2 - l and len2 = r - !p3 in + if len1 > cutoff then + if len2 > cutoff then begin + if len1 < len2 + then (qsort l !p2; qsort !p3 r) + else (qsort !p3 r; qsort l !p2) + end else qsort l !p2 + else if len2 > cutoff then qsort !p3 r; + in + let l = Array.length a in + if l > 1 then begin + qsort 0 l; + let mini = ref 0 in + for i = 0 to (min l cutoff) - 1 do + if cmp a.(i) a.(!mini) < 0 then mini := i; + done; + let e = a.(0) in a.(0) <- a.(!mini); a.(!mini) <- e; + for i = 1 to l - 1 do + let e = a.(i) in + let j = ref (i - 1) in + while cmp a.(!j) e > 0 do + a.(!j + 1) <- a.(!j); + decr j; + done; + a.(!j + 1) <- e; + done; + end; +;; + +(************************************************************************) +(* Heap sort on arrays (top-down, ternary) *) + +let aheap_1 cmp a = + let l = ref (Array.length a) in + let l3 = ref ((!l + 1) / 3) in (* l3 is the first element without sons *) + let maxson i = (* ASSUMES i < !l3 *) + let i31 = i+i+i+1 in + let x = ref i31 in + if i31+2 < !l then begin + if cmp a.(i31) a.(i31+1) < 0 then x := i31+1; + if cmp a.(!x) a.(i31+2) < 0 then x := i31+2; + !x + end else begin + if i31+1 < !l && cmp a.(i31) a.(i31+1) < 0 + then i31+1 + else i31 + end + in + let rec trickledown i e = (* ASSUMES i < !l3 *) + let j = maxson i in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + if j < !l3 then trickledown j e else a.(j) <- e; + end else begin + a.(i) <- e; + end; + in + for i = !l3 - 1 downto 0 do trickledown i a.(i); done; + let m = ref (!l + 1 - 3 * !l3) in + while !l > 2 do + decr l; + if !m = 0 then (m := 2; decr l3) else decr m; + let e = a.(!l) in + a.(!l) <- a.(0); + trickledown 0 e; + done; + if !l > 1 then begin let e = a.(1) in a.(1) <- a.(0); a.(0) <- e; end; +;; + +(************************************************************************) +(* Heap sort on arrays (top-down, binary) *) + +(* FIXME essayer application partielle de trickledown (merge avec down) *) +(* FIXME essayer expanser maxson dans trickledown; supprimer l'exception. *) + +let aheap_2 cmp a = + let maxson l i e = + let i21 = i + i + 1 in + if i21 + 1 < l && cmp a.(i21) a.(i21+1) < 0 + then i21 + 1 + else if i21 < l then i21 else (a.(i) <- e; raise Exit) + in + let rec trickledown l i e = + let j = maxson l i e in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + trickledown l j e; + end else begin + a.(i) <- e; + end; + in + let down l i e = try trickledown l i e with Exit -> () in + let l = Array.length a in + for i = l / 2 -1 downto 0 do down l i a.(i); done; + for i = l - 1 downto 1 do + let e = a.(i) in + a.(i) <- a.(0); + down i 0 e; + done; +;; + +(************************************************************************) +(* Heap sort on arrays (bottom-up, ternary) *) + +exception Bottom of int;; + +let aheap_3 cmp a = + let maxson l i = + let i31 = i+i+i+1 in + let x = ref i31 in + if i31+2 < l then begin + if cmp a.(i31) a.(i31+1) < 0 then x := i31+1; + if cmp a.(!x) a.(i31+2) < 0 then x := i31+2; + !x + end else + if i31+1 < l && cmp a.(i31) a.(i31+1) < 0 + then i31+1 + else if i31 < l then i31 else raise (Bottom i) + in + let rec trickledown l i e = + let j = maxson l i in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + trickledown l j e; + end else begin + a.(i) <- e; + end; + in + let rec trickle l i e = try trickledown l i e with Bottom i -> a.(i) <- e in + let rec bubbledown l i = + let j = maxson l i in + a.(i) <- a.(j); + bubbledown l j; + in + let bubble l i = try bubbledown l i with Bottom i -> i in + let rec trickleup i e = + let father = (i - 1) / 3 in + assert (i <> father); + if cmp a.(father) e < 0 then begin + a.(i) <- a.(father); + if father > 0 then trickleup father e else a.(0) <- e; + end else begin + a.(i) <- e; + end; + in + let l = Array.length a in + for i = (l + 1) / 3 - 1 downto 0 do trickle l i a.(i); done; + for i = l - 1 downto 2 do + let e = a.(i) in + a.(i) <- a.(0); + trickleup (bubble i 0) e; + done; + if l > 1 then (let e = a.(1) in a.(1) <- a.(0); a.(0) <- e); +;; + +(************************************************************************) +(* Heap sort on arrays (bottom-up, binary) *) + +let aheap_4 cmp a = + let maxson l i = + let i21 = i + i + 1 in + if i21 + 1 < l && cmp a.(i21) a.(i21 + 1) < 0 + then i21 + 1 + else if i21 < l then i21 else raise (Bottom i) + in + let rec trickledown l i e = + let j = maxson l i in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + trickledown l j e; + end else begin + a.(i) <- e; + end; + in + let trickle l i e = try trickledown l i e with Bottom i -> a.(i) <- e in + let rec bubbledown l i = + let j = maxson l i in + a.(i) <- a.(j); + bubbledown l j; + in + let bubble l i = try bubbledown l i with Bottom i -> i in + let rec trickleup i e = + let father = (i - 1) / 2 in + assert (i <> father); + if cmp a.(father) e < 0 then begin + a.(i) <- a.(father); + if father > 0 then trickleup father e else a.(0) <- e; + end else begin + a.(i) <- e; + end; + in + let l = Array.length a in + for i = l / 2 - 1 downto 0 do trickle l i a.(i); done; + for i = l - 1 downto 2 do + let e = a.(i) in + a.(i) <- a.(0); + trickleup (bubble i 0) e; + done; + if l > 1 then (let e = a.(1) in a.(1) <- a.(0); a.(0) <- e); +;; + +(************************************************************************) +(* heap sort, top-down, ternary, recursive final loop *) + +let aheap_5 cmp a = + let maxson l i = (* ASSUMES i < (l+1)/3 *) + let i31 = i+i+i+1 in + let x = ref i31 in + if i31+2 < l then begin + if cmp a.(i31) a.(i31+1) < 0 then x := i31+1; + if cmp a.(!x) a.(i31+2) < 0 then x := i31+2; + !x + end else begin + if i31+1 < l && cmp a.(i31) a.(i31+1) < 0 + then i31+1 + else i31 + end + in + let rec trickledown l l3 i e = (* ASSUMES i < l3 *) + let j = maxson l i in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + if j < l3 then trickledown l l3 j e else a.(j) <- e; + end else begin + a.(i) <- e; + end; + in + let l = Array.length a in + let l3 = (l + 1) / 3 in + for i = l3 - 1 downto 0 do trickledown l l3 i a.(i); done; + let rec loop0 l l3 = + let e = a.(l) in + a.(l) <- a.(0); + trickledown l l3 0 e; + loop2 (l-1) (l3-1); + and loop1 l l3 = + let e = a.(l) in + a.(l) <- a.(0); + trickledown l l3 0 e; + loop0 (l-1) l3; + and loop2 l l3 = + if l > 1 then begin + let e = a.(l) in + a.(l) <- a.(0); + trickledown l l3 0 e; + loop1 (l-1) l3; + end else begin + let e = a.(1) in a.(1) <- a.(0); a.(0) <- e; + end; + in + if l > 1 then + match l + 1 - 3 * l3 with + | 0 -> loop2 (l-1) (l3-1); + | 1 -> loop0 (l-1) l3; + | 2 -> loop1 (l-1) l3; + | _ -> assert false; +;; + +(************************************************************************) +(* heap sort, top-down, ternary, with exception *) + +let aheap_6 cmp a = + let maxson e l i = + let i31 = i + i + i + 1 in + let x = ref i31 in + if i31+2 < l then begin + if cmp a.(i31) a.(i31+1) < 0 then x := i31+1; + if cmp a.(!x) a.(i31+2) < 0 then x := i31+2; + !x + end else begin + if i31+1 < l && cmp a.(i31) a.(i31+1) < 0 + then i31+1 + else if i31 < l then i31 else (a.(i) <- e; raise Exit) + end + in + let rec trickledown e l i = + let j = maxson e l i in + if cmp a.(j) e > 0 then begin + a.(i) <- a.(j); + trickledown e l j; + end else begin + a.(i) <- e; + end; + in + let down e l i = try trickledown e l i with Exit -> (); in + let l = Array.length a in + for i = (l + 1) / 3 - 1 downto 0 do down a.(i) l i; done; + for i = l - 1 downto 2 do + let e = a.(i) in + a.(i) <- a.(0); + down e i 0; + done; + if l > 1 then (let e = a.(1) in a.(1) <- a.(0); a.(0) <- e); +;; + +(* FIXME essayer cutoff pour heapsort *) + +(************************************************************************) +(* Insertion sort with dichotomic search *) + +let ainsertion_1 cmp a = + let rec dicho l r e = + if l = r then l else begin + let m = (l + r) / 2 in + if cmp a.(m) e <= 0 + then dicho (m+1) r e + else dicho l m e + end + in + for i = 1 to Array.length a - 1 do + let e = a.(i) in + let j = dicho 0 i e in + Array.blit a j a (j + 1) (i - j); + a.(j) <- e; + done; +;; + +(************************************************************************) +(* merge sort on lists via arrays *) + +let array_to_list_in_place a = + let l = Array.length a in + let rec loop accu n p = + if p <= 0 then accu else begin + if p = n then begin + Obj.truncate (Obj.repr a) p; + loop (a.(p-1) :: accu) (n-1000) (p-1) + end else begin + loop (a.(p-1) :: accu) n (p-1) + end + end + in + loop [] l l +;; + +let array_of_list l len = + match l with + | [] -> [| |] + | h::t -> + let a = Array.make len h in + let rec loop i l = + match l with + | [] -> () + | h::t -> a.(i) <- h; loop (i+1) t + in + loop 1 t; + a +;; + +let lmerge_0a cmp l = + let a = Array.of_list l in + amerge_1e cmp a; + array_to_list_in_place a +;; + +let lmerge_0b cmp l = + let len = List.length l in + if len > 256 then Gc.minor (); + let a = array_of_list l len in + amerge_1e cmp a; + array_to_list_in_place a +;; + +let lshell_0 cmp l = + let a = Array.of_list l in + ashell_2 cmp a; + array_to_list_in_place a +;; + +let lquick_0 cmp l = + let a = Array.of_list l in + aquick_3f cmp a; + array_to_list_in_place a +;; + +(************************************************************************) +(* merge sort on arrays via lists *) + +let amerge_0 cmp a = (* cutoff is not yet used *) + let l = lmerge_4e cmp (Array.to_list a) in + let rec loop i = function + | [] -> () + | h::t -> a.(i) <- h; loop (i + 1) t + in + loop 0 l +;; + +(************************************************************************) + +let lold = [ + "Sort.list", Sort.list, true; + "lmerge_3", lmerge_3, false; + "lmerge_4a", lmerge_4a, true; +];; + +let lnew = [ + "List.stable_sort", List.stable_sort, true; + + "lmerge_0a", lmerge_0a, true; + "lmerge_0b", lmerge_0b, true; + "lshell_0", lshell_0, false; + "lquick_0", lquick_0, false; + + "lmerge_1a", lmerge_1a, true; + "lmerge_1b", lmerge_1b, true; + "lmerge_1c", lmerge_1c, true; + "lmerge_1d", lmerge_1d, true; + + "lmerge_4b", lmerge_4b, true; + "lmerge_4c", lmerge_4c, true; + "lmerge_4d", lmerge_4d, true; + "lmerge_4e", lmerge_4e, true; + + "lmerge_5a", lmerge_5a, true; + "lmerge_5b", lmerge_5b, true; + "lmerge_5c", lmerge_5c, true; + "lmerge_5d", lmerge_5d, true; +];; +let anew = [ + "Array.stable_sort", Array.stable_sort, true; + "Array.sort", Array.sort, false; + + "amerge_0", amerge_0, true; + + "amerge_1a", amerge_1a, true; + "amerge_1b", amerge_1b, true; + "amerge_1c", amerge_1c, true; + "amerge_1d", amerge_1d, true; + "amerge_1e", amerge_1e, true; + "amerge_1f", amerge_1f, true; + "amerge_1g", amerge_1g, true; + "amerge_1h", amerge_1h, true; + "amerge_1i", amerge_1i, true; + "amerge_1j", amerge_1j, true; + + "amerge_3a", amerge_3a, true; + "amerge_3b", amerge_3b, true; + "amerge_3c", amerge_3c, true; + "amerge_3d", amerge_3d, true; + "amerge_3e", amerge_3e, true; + "amerge_3f", amerge_3f, true; + "amerge_3g", amerge_3g, true; + "amerge_3h", amerge_3h, true; + "amerge_3i", amerge_3i, true; + "amerge_3j", amerge_3j, true; + + "ashell_1", ashell_1, false; + "ashell_2", ashell_2, false; + "ashell_3", ashell_3, false; + "ashell_4", ashell_4, false; + + "aquick_1a", aquick_1a, false; + "aquick_1b", aquick_1b, false; + "aquick_1c", aquick_1c, false; + "aquick_1d", aquick_1d, false; + "aquick_1e", aquick_1e, false; + "aquick_1f", aquick_1f, false; + "aquick_1g", aquick_1g, false; + + "aquick_2a", aquick_2a, false; + "aquick_2b", aquick_2b, false; + "aquick_2c", aquick_2c, false; + "aquick_2d", aquick_2d, false; + "aquick_2e", aquick_2e, false; + "aquick_2f", aquick_2f, false; + "aquick_2g", aquick_2g, false; + + "aquick_3a", aquick_3a, false; + "aquick_3b", aquick_3b, false; + "aquick_3c", aquick_3c, false; + "aquick_3d", aquick_3d, false; + "aquick_3e", aquick_3e, false; + "aquick_3f", aquick_3f, false; + "aquick_3g", aquick_3g, false; + "aquick_3h", aquick_3h, false; + "aquick_3i", aquick_3i, false; + "aquick_3j", aquick_3j, false; + + "aheap_1", aheap_1, false; + "aheap_2", aheap_2, false; + "aheap_3", aheap_3, false; + "aheap_4", aheap_4, false; + "aheap_5", aheap_5, false; + "aheap_6", aheap_6, false; + + "ainsertion_1", ainsertion_1, true; +];; + +(************************************************************************) +(* main program *) + +type mode = Test_std | Test | Bench1 | Bench2 | Bench3;; + +let size = ref 22 +and mem = ref 0 +and mode = ref Test_std +and only = ref [] +;; + +let usage = "Usage: sorts [-size <table size>] [-mem <memory size>]\n\ + \032 [-seed <random seed>] [-test|-bench]" +;; + +let options = [ + "-size", Arg.Int ((:=) size), " Maximum size for benchmarks (default 22)"; + "-meg",Arg.Int ((:=) mem)," How many megabytes to preallocate (default 0)"; + "-seed", Arg.Int ((:=) seed), " PRNG seed (default 0)"; + "-teststd", Arg.Unit (fun () -> mode := Test_std), " Test stdlib (default)"; + "-test", Arg.Unit (fun () -> mode := Test), " Select test mode"; + "-bench1", Arg.Unit (fun () -> mode := Bench1), " Select bench mode 1"; + "-bench2", Arg.Unit (fun () -> mode := Bench2), " Select bench mode 2"; + "-bench3", Arg.Unit (fun () -> mode := Bench3), " Select bench mode 3"; + "-fn", Arg.String (fun x -> only := x :: !only), + " <function> Test/Bench this function (default all)"; +];; +let anonymous x = raise (Arg.Bad ("unrecognised option "^x));; + +let main () = + Arg.parse options anonymous usage; + + Printf.printf "Command line arguments are:"; + for i = 1 to Array.length Sys.argv - 1 do + Printf.printf " %s" Sys.argv.(i); + done; + Printf.printf "\n"; + + ignore (String.create (1048576 * !mem)); + Gc.full_major (); + let a2l = Array.to_list in + let l2ak x y = Array.of_list x in + let id = fun x -> x in + let fst x y = x in + let snd x y = y in + let benchonly f x y z t = + match !only with + | [] -> f x y z t + | l -> if List.mem y l then f x y z t + in + let testonly x1 x2 x3 x4 x5 x6 = + match !only with + | [] -> test x1 x2 x3 x4 x5 x6 + | l -> if List.mem x1 l then test x1 x2 x3 x4 x5 x6 + in + + match !mode with + | Test_std -> begin + testonly "List.sort" false List.sort List.sort lc lc; + testonly "List.stable_sort" true List.stable_sort List.stable_sort lc lc; + testonly "Array.sort" false Array.sort Array.sort ac ac; + testonly "Array.stable_sort" true Array.stable_sort Array.stable_sort + ac ac; + printf "Number of tests failed: %d\n" !numfailed; + end; + | Test -> begin + for i = 0 to List.length lold - 1 do + let (name, f1, stable) = List.nth lold i in + let (_, f2, _) = List.nth lold i in + testonly name stable f1 f2 ll ll; + done; + testonly "Sort.array" false Sort.array Sort.array al al; + for i = 0 to List.length lnew - 1 do + let (name, f1, stable) = List.nth lnew i in + let (_, f2, _) = List.nth lnew i in + testonly name stable f1 f2 lc lc; + done; + for i = 0 to List.length anew - 1 do + let (name, f1, stable) = List.nth anew i in + let (_, f2, _) = List.nth anew i in + testonly name stable f1 f2 ac ac; + done; + printf "Number of tests failed: %d\n" !numfailed; + end; + | Bench1 -> begin + let ba = fun x y z -> benchonly bench1a !size x y z + and bb = fun x y z -> benchonly bench1b !size x y z + and bc = fun x y z -> benchonly bench1c !size x y z + in + for i = 0 to List.length lold - 1 do + let (name, f, stable) = List.nth lold i in ba name f ll; + let (name, f, stable) = List.nth lold i in bb name f ll; + let (name, f, stable) = List.nth lold i in bc name f ll; + done; + ba "Sort.array" Sort.array al; + bb "Sort.array" Sort.array al; + bc "Sort.array" Sort.array al; + for i = 0 to List.length lnew - 1 do + let (name, f, stable) = List.nth lnew i in ba name f lc; + let (name, f, stable) = List.nth lnew i in bb name f lc; + let (name, f, stable) = List.nth lnew i in bc name f lc; + done; + for i = 0 to List.length anew - 1 do + let (name, f, stable) = List.nth anew i in ba name f ac; + let (name, f, stable) = List.nth anew i in bb name f ac; + let (name, f, stable) = List.nth anew i in bc name f ac; + done; + end; + | Bench2 -> begin + let b = fun x y z -> benchonly bench2 !size x y z in + for i = 0 to List.length lold - 1 do + let (name, f, stable) = List.nth lold i in b name f ll; + done; + b "Sort.array" Sort.array al; + for i = 0 to List.length lnew - 1 do + let (name, f, stable) = List.nth lnew i in b name f lc; + done; + for i = 0 to List.length anew - 1 do + let (name, f, stable) = List.nth anew i in b name f ac; + done; + end; + | Bench3 -> begin + let ba = fun x y z -> benchonly bench3a !size x y z + and bb = fun x y z -> benchonly bench3b !size x y z + and bc = fun x y z -> benchonly bench3c !size x y z + in + for i = 0 to List.length lold - 1 do + let (name, f, stable) = List.nth lold i in ba name f ll; + let (name, f, stable) = List.nth lold i in bb name f ll; + let (name, f, stable) = List.nth lold i in bc name f ll; + done; + for i = 0 to List.length lnew - 1 do + let (name, f, stable) = List.nth lnew i in ba name f lc; + let (name, f, stable) = List.nth lnew i in bb name f lc; + let (name, f, stable) = List.nth lnew i in bc name f lc; + done; + end; +;; + +if not !Sys.interactive then Printexc.catch main ();; + +(* $Id: sorts.ml,v 1.1 2002-06-26 14:55:36 doligez Exp $ *) diff --git a/test/takc.ml b/test/takc.ml new file mode 100644 index 0000000..55aa26f --- /dev/null +++ b/test/takc.ml @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: takc.ml,v 1.5 2005-08-12 09:22:04 xleroy Exp $ *) + +let rec tak x y z = + if x > y then tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y) + else z + +let rec repeat n = + if n <= 0 then 0 else tak 18 12 6 + repeat(n-1) + +let _ = print_int (repeat 2000); print_newline(); exit 0 + diff --git a/test/taku.ml b/test/taku.ml new file mode 100644 index 0000000..23687d6 --- /dev/null +++ b/test/taku.ml @@ -0,0 +1,22 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: taku.ml,v 1.5 2005-08-12 09:22:04 xleroy Exp $ *) + +let rec tak (x, y, z) = + if x > y then tak(tak (x-1, y, z), tak (y-1, z, x), tak (z-1, x, y)) + else z + +let rec repeat n = + if n <= 0 then 0 else tak(18,12,6) + repeat(n-1) + +let _ = print_int (repeat 2000); print_newline(); exit 0 diff --git a/test/testinterp/.cvsignore b/test/testinterp/.cvsignore new file mode 100644 index 0000000..fdffd0f --- /dev/null +++ b/test/testinterp/.cvsignore @@ -0,0 +1,3 @@ +a.out +ocamlrun.68k +ocamlrun.ppc diff --git a/test/testinterp/coverage b/test/testinterp/coverage new file mode 100644 index 0000000..30a3243 --- /dev/null +++ b/test/testinterp/coverage @@ -0,0 +1,133 @@ +ACC0: 090 +ACC1: 090 +ACC2: 090 +ACC3: 090 +ACC4: 090 +ACC5: 090 +ACC6: 090 +ACC7: 090 +ACC: 091 +PUSH: 150 +PUSHACC0: 092 +PUSHACC1: 092 +PUSHACC2: 092 +PUSHACC3: 092 +PUSHACC4: 092 +PUSHACC5: 092 +PUSHACC6: 092 +PUSHACC7: 092 +PUSHACC: 093 +POP: 020 +ASSIGN: 220 +ENVACC1: 170 +ENVACC2: 170 +ENVACC3: 170 +ENVACC4: 170 +ENVACC: 171 +PUSHENVACC1: 172 +PUSHENVACC2: 172 +PUSHENVACC3: 172 +PUSHENVACC4: 172 +PUSHENVACC: 173 +PUSH_RETADDR: 270 +APPLY: 165 +APPLY1: 161 +APPLY2: 164 +APPLY3: 164 +APPTERM: 181 +APPTERM1: 180 +APPTERM2: 180 +APPTERM3: 180 +RETURN: 162 +RESTART: 163 +GRAB: 163 +CLOSURE: 160 +CLOSUREREC: 250 +OFFSETCLOSUREM2: 253 +OFFSETCLOSURE0: 253 +OFFSETCLOSURE2: 253 +OFFSETCLOSURE: 254 +PUSHOFFSETCLOSUREM2: 251 +PUSHOFFSETCLOSURE0: 251 +PUSHOFFSETCLOSURE2: 251 +PUSHOFFSETCLOSURE: 252 +GETGLOBAL: 050 +PUSHGETGLOBAL: 050 +GETGLOBALFIELD: 051 +PUSHGETGLOBALFIELD: 051 +SETGLOBAL: 000 +ATOM0: 000 +ATOM: +PUSHATOM0: +PUSHATOM: +MAKEBLOCK: 041 +MAKEBLOCK1: 040 +MAKEBLOCK2: 040 +MAKEBLOCK3: 040 +MAKEFLOATBLOCK: 190 +GETFIELD0: 200 +GETFIELD1: 200 +GETFIELD2: 200 +GETFIELD3: 200 +GETFIELD: 201 +GETFLOATFIELD: 192 +SETFIELD0: 210 +SETFIELD1: 210 +SETFIELD2: 210 +SETFIELD3: 210 +SETFIELD: 211 +SETFLOATFIELD: 193 +VECTLENGTH: 130,191 +GETVECTITEM: 130 +SETVECTITEM: 131 +GETSTRINGCHAR: 120 +SETSTRINGCHAR: 121 +BRANCH: 070 +BRANCHIF: 070 +BRANCHIFNOT: 070 +SWITCH: 140,141,142 +BOOLNOT: 071 +PUSHTRAP: 100 +POPTRAP: 101 +RAISE: 060 +CHECK_SIGNALS: 230 +C_CALL1: 240 +C_CALL2: 240 +C_CALL3: 240 +C_CALL4: 240 +C_CALL5: 240 +C_CALLN: +CONST0: 010 +CONST1: 010 +CONST2: 010 +CONST3: 010 +CONSTINT: 011 +PUSHCONST0: 020 +PUSHCONST1: 021 +PUSHCONST2: 021 +PUSHCONST3: 021 +PUSHCONSTINT: 022 +NEGINT: 110 +ADDINT: 110 +SUBINT: 110 +MULINT: 110 +DIVINT: 110 +MODINT: 110 +ANDINT: 110 +ORINT: 110 +XORINT: 110 +LSLINT: 110 +LSRINT: 110 +ASRINT: 110 +EQ: 080 +NEQ: 080 +LTINT: 080 +LEINT: 080 +GTINT: 080 +GEINT: 080 +OFFSETINT: 110 +OFFSETREF: 260 +GETMETHOD: 300 +STOP: 000 +EVENT: +BREAK: diff --git a/test/testinterp/lib.ml b/test/testinterp/lib.ml new file mode 100644 index 0000000..7cea0eb --- /dev/null +++ b/test/testinterp/lib.ml @@ -0,0 +1,46 @@ +(* file $Id: lib.ml,v 1.2 2004-04-06 09:11:45 starynke Exp $ *) + +external raise : exn -> 'a = "%raise" + +external not : bool -> bool = "%boolnot" + +external (=) : 'a -> 'a -> bool = "%equal" +external (<>) : 'a -> 'a -> bool = "%notequal" +external (<) : 'a -> 'a -> bool = "%lessthan" +external (>) : 'a -> 'a -> bool = "%greaterthan" +external (<=) : 'a -> 'a -> bool = "%lessequal" +external (>=) : 'a -> 'a -> bool = "%greaterequal" + +external (~-) : int -> int = "%negint" +external (+) : int -> int -> int = "%addint" +external (-) : int -> int -> int = "%subint" +external ( * ) : int -> int -> int = "%mulint" +external (/) : int -> int -> int = "%divint" +external (mod) : int -> int -> int = "%modint" + +external (land) : int -> int -> int = "%andint" +external (lor) : int -> int -> int = "%orint" +external (lxor) : int -> int -> int = "%xorint" +external (lsl) : int -> int -> int = "%lslint" +external (lsr) : int -> int -> int = "%lsrint" +external (asr) : int -> int -> int = "%asrint" + +external ignore : 'a -> unit = "%ignore" + +type 'a ref = { mutable contents: 'a } +external ref : 'a -> 'a ref = "%makemutable" +external (!) : 'a ref -> 'a = "%field0" +external (:=) : 'a ref -> 'a -> unit = "%setfield0" +external incr : int ref -> unit = "%incr" +external decr : int ref -> unit = "%decr" + +type 'a option = None | Some of 'a + +type 'a weak_t;; +external weak_create: int -> 'a weak_t = "caml_weak_create";; +external weak_set : 'a weak_t -> int -> 'a option -> unit = "caml_weak_set";; +external weak_get: 'a weak_t -> int -> 'a option = "caml_weak_get";; + +let x = 42;; + +(* eof $Id: lib.ml,v 1.2 2004-04-06 09:11:45 starynke Exp $ *) diff --git a/test/testinterp/no68k.rez b/test/testinterp/no68k.rez new file mode 100644 index 0000000..a6353ea --- /dev/null +++ b/test/testinterp/no68k.rez @@ -0,0 +1 @@ +data 'CODE' (0) { }; diff --git a/test/testinterp/noppc.rez b/test/testinterp/noppc.rez new file mode 100644 index 0000000..ecb9655 --- /dev/null +++ b/test/testinterp/noppc.rez @@ -0,0 +1 @@ +data 'cfrg' (0) { }; diff --git a/test/testinterp/t000.ml b/test/testinterp/t000.ml new file mode 100644 index 0000000..fafa1c8 --- /dev/null +++ b/test/testinterp/t000.ml @@ -0,0 +1,7 @@ +(* empty file *) + +(** + 0 ATOM0 + 1 SETGLOBAL T000 + 3 STOP +**) diff --git a/test/testinterp/t010-const0.ml b/test/testinterp/t010-const0.ml new file mode 100644 index 0000000..73ecbb1 --- /dev/null +++ b/test/testinterp/t010-const0.ml @@ -0,0 +1,8 @@ +0;; + +(** + 0 CONST0 + 1 ATOM0 + 2 SETGLOBAL T010-const0 + 4 STOP +**) diff --git a/test/testinterp/t010-const1.ml b/test/testinterp/t010-const1.ml new file mode 100644 index 0000000..75a00d5 --- /dev/null +++ b/test/testinterp/t010-const1.ml @@ -0,0 +1,8 @@ +1;; + +(** + 0 CONST1 + 1 ATOM0 + 2 SETGLOBAL T010-const1 + 4 STOP +**) diff --git a/test/testinterp/t010-const2.ml b/test/testinterp/t010-const2.ml new file mode 100644 index 0000000..f0ed8e7 --- /dev/null +++ b/test/testinterp/t010-const2.ml @@ -0,0 +1,8 @@ +2;; + +(** + 0 CONST2 + 1 ATOM0 + 2 SETGLOBAL T010-const2 + 4 STOP +**) diff --git a/test/testinterp/t010-const3.ml b/test/testinterp/t010-const3.ml new file mode 100644 index 0000000..4f034c4 --- /dev/null +++ b/test/testinterp/t010-const3.ml @@ -0,0 +1,8 @@ +3;; + +(** + 0 CONST3 + 1 ATOM0 + 2 SETGLOBAL T010-const3 + 4 STOP +**) diff --git a/test/testinterp/t011-constint.ml b/test/testinterp/t011-constint.ml new file mode 100644 index 0000000..9ece6c5 --- /dev/null +++ b/test/testinterp/t011-constint.ml @@ -0,0 +1,8 @@ +4;; + +(** + 0 CONSTINT 4 + 2 ATOM0 + 3 SETGLOBAL T011-constint + 5 STOP +**) diff --git a/test/testinterp/t020.ml b/test/testinterp/t020.ml new file mode 100644 index 0000000..5d6a3cf --- /dev/null +++ b/test/testinterp/t020.ml @@ -0,0 +1,10 @@ +let _ = () in ();; + +(** + 0 CONST0 + 1 PUSHCONST0 + 2 POP 1 + 4 ATOM0 + 5 SETGLOBAL T020 + 7 STOP +**) diff --git a/test/testinterp/t021-pushconst1.ml b/test/testinterp/t021-pushconst1.ml new file mode 100644 index 0000000..075997a --- /dev/null +++ b/test/testinterp/t021-pushconst1.ml @@ -0,0 +1,10 @@ +let _ = () in 1;; + +(** + 0 CONST0 + 1 PUSHCONST1 + 2 POP 1 + 4 ATOM0 + 5 SETGLOBAL T021-pushconst1 + 7 STOP +**) diff --git a/test/testinterp/t021-pushconst2.ml b/test/testinterp/t021-pushconst2.ml new file mode 100644 index 0000000..17adb50 --- /dev/null +++ b/test/testinterp/t021-pushconst2.ml @@ -0,0 +1,10 @@ +let _ = () in 2;; + +(** + 0 CONST0 + 1 PUSHCONST2 + 2 POP 1 + 4 ATOM0 + 5 SETGLOBAL T021-pushconst2 + 7 STOP +**) diff --git a/test/testinterp/t021-pushconst3.ml b/test/testinterp/t021-pushconst3.ml new file mode 100644 index 0000000..563c609 --- /dev/null +++ b/test/testinterp/t021-pushconst3.ml @@ -0,0 +1,10 @@ +let _ = () in 3;; + +(** + 0 CONST0 + 1 PUSHCONST3 + 2 POP 1 + 4 ATOM0 + 5 SETGLOBAL T021-pushconst3 + 7 STOP +**) diff --git a/test/testinterp/t022-pushconstint.ml b/test/testinterp/t022-pushconstint.ml new file mode 100644 index 0000000..1b766a5 --- /dev/null +++ b/test/testinterp/t022-pushconstint.ml @@ -0,0 +1,10 @@ +let _ = () in -1;; + +(** + 0 CONST0 + 1 PUSHCONSTINT -1 + 3 POP 1 + 5 ATOM0 + 6 SETGLOBAL T022-pushconstint + 8 STOP +**) diff --git a/test/testinterp/t040-makeblock1.ml b/test/testinterp/t040-makeblock1.ml new file mode 100644 index 0000000..7151660 --- /dev/null +++ b/test/testinterp/t040-makeblock1.ml @@ -0,0 +1,13 @@ +type t = { + mutable a : int; +};; + +{ a = 0 };; + +(** + 0 CONST0 + 1 MAKEBLOCK1 0 + 3 ATOM0 + 4 SETGLOBAL T040-makeblock1 + 6 STOP +**) diff --git a/test/testinterp/t040-makeblock2.ml b/test/testinterp/t040-makeblock2.ml new file mode 100644 index 0000000..e7c745b --- /dev/null +++ b/test/testinterp/t040-makeblock2.ml @@ -0,0 +1,15 @@ +type t = { + mutable a : int; + mutable b : int; +};; + +{ a = 0; b = 0 };; + +(** + 0 CONST0 + 1 PUSHCONST0 + 2 MAKEBLOCK2 0 + 4 ATOM0 + 5 SETGLOBAL T040-makeblock2 + 7 STOP +**) diff --git a/test/testinterp/t040-makeblock3.ml b/test/testinterp/t040-makeblock3.ml new file mode 100644 index 0000000..8fb5605 --- /dev/null +++ b/test/testinterp/t040-makeblock3.ml @@ -0,0 +1,17 @@ +type t = { + mutable a : int; + mutable b : int; + mutable c : int; +};; + +{ a = 0; b = 0; c = 0 };; + +(** + 0 CONST0 + 1 PUSHCONST0 + 2 PUSHCONST0 + 3 MAKEBLOCK3 0 + 5 ATOM0 + 6 SETGLOBAL T040-makeblock3 + 8 STOP +**) diff --git a/test/testinterp/t041-makeblock.ml b/test/testinterp/t041-makeblock.ml new file mode 100644 index 0000000..5ae255d --- /dev/null +++ b/test/testinterp/t041-makeblock.ml @@ -0,0 +1,19 @@ +type t = { + mutable a : int; + mutable b : int; + mutable c : int; + mutable d : int; +};; + +{ a = 0; b = 0; c = 0; d = 0 };; + +(** + 0 CONST0 + 1 PUSHCONST0 + 2 PUSHCONST0 + 3 PUSHCONST0 + 4 MAKEBLOCK 4, 0 + 7 ATOM0 + 8 SETGLOBAL T041-makeblock + 10 STOP +**) diff --git a/test/testinterp/t050-getglobal.ml b/test/testinterp/t050-getglobal.ml new file mode 100644 index 0000000..f10393c --- /dev/null +++ b/test/testinterp/t050-getglobal.ml @@ -0,0 +1,8 @@ +[1];; + +(** + 0 GETGLOBAL <0>(1, 0) + 2 ATOM0 + 3 SETGLOBAL T050-getglobal + 5 STOP +**) diff --git a/test/testinterp/t050-pushgetglobal.ml b/test/testinterp/t050-pushgetglobal.ml new file mode 100644 index 0000000..e1172cc --- /dev/null +++ b/test/testinterp/t050-pushgetglobal.ml @@ -0,0 +1,10 @@ +let _ = () in 0.01;; + +(** + 0 CONST0 + 1 PUSHGETGLOBAL 0.01 + 3 POP 1 + 5 ATOM0 + 6 SETGLOBAL T050-pushgetglobal + 8 STOP +**) diff --git a/test/testinterp/t051-getglobalfield.ml b/test/testinterp/t051-getglobalfield.ml new file mode 100644 index 0000000..45d9cce --- /dev/null +++ b/test/testinterp/t051-getglobalfield.ml @@ -0,0 +1,13 @@ +Lib.x;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBALFIELD Lib, 0 + 12 ATOM0 + 13 SETGLOBAL T051-getglobalfield + 15 STOP +**) diff --git a/test/testinterp/t051-pushgetglobalfield.ml b/test/testinterp/t051-pushgetglobalfield.ml new file mode 100644 index 0000000..2012a25 --- /dev/null +++ b/test/testinterp/t051-pushgetglobalfield.ml @@ -0,0 +1,15 @@ +let _ = () in Lib.x;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHGETGLOBALFIELD Lib, 0 + 13 POP 1 + 15 ATOM0 + 16 SETGLOBAL T051-pushgetglobalfield + 18 STOP +**) diff --git a/test/testinterp/t060-raise.ml b/test/testinterp/t060-raise.ml new file mode 100644 index 0000000..1aa4846 --- /dev/null +++ b/test/testinterp/t060-raise.ml @@ -0,0 +1,15 @@ +open Lib;; +raise End_of_file;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL End_of_file + 11 MAKEBLOCK1 0 + 13 RAISE + 14 SETGLOBAL T060-raise + 16 STOP +**) diff --git a/test/testinterp/t070-branch.ml b/test/testinterp/t070-branch.ml new file mode 100644 index 0000000..4fc52d4 --- /dev/null +++ b/test/testinterp/t070-branch.ml @@ -0,0 +1,20 @@ +open Lib;; +if true then 0 else raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 BRANCHIFNOT 15 + 12 CONST0 + 13 BRANCH 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 ATOM0 + 21 SETGLOBAL T070-branch + 23 STOP +**) diff --git a/test/testinterp/t070-branchif.ml b/test/testinterp/t070-branchif.ml new file mode 100644 index 0000000..c256248 --- /dev/null +++ b/test/testinterp/t070-branchif.ml @@ -0,0 +1,20 @@ +open Lib;; +if not false then 0 else raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 BRANCHIF 15 + 12 CONST0 + 13 BRANCH 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 ATOM0 + 21 SETGLOBAL T070-branchif + 23 STOP +**) diff --git a/test/testinterp/t070-branchifnot.ml b/test/testinterp/t070-branchifnot.ml new file mode 100644 index 0000000..9e6e4e8 --- /dev/null +++ b/test/testinterp/t070-branchifnot.ml @@ -0,0 +1,18 @@ +open Lib;; +if false then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 BRANCHIFNOT 17 + 12 GETGLOBAL Not_found + 14 MAKEBLOCK1 0 + 16 RAISE + 17 ATOM0 + 18 SETGLOBAL T070-branchifnot + 20 STOP +**) diff --git a/test/testinterp/t071-boolnot.ml b/test/testinterp/t071-boolnot.ml new file mode 100644 index 0000000..b4a8194 --- /dev/null +++ b/test/testinterp/t071-boolnot.ml @@ -0,0 +1,19 @@ +open Lib;; +if not true then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 BOOLNOT + 11 BRANCHIFNOT 18 + 13 GETGLOBAL Not_found + 15 MAKEBLOCK1 0 + 17 RAISE + 18 ATOM0 + 19 SETGLOBAL T071-boolnot + 21 STOP +**) diff --git a/test/testinterp/t080-eq.ml b/test/testinterp/t080-eq.ml new file mode 100644 index 0000000..3ee735f --- /dev/null +++ b/test/testinterp/t080-eq.ml @@ -0,0 +1,21 @@ +open Lib;; +if not (0 = 0) then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 EQ + 12 BOOLNOT + 13 BRANCHIFNOT 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 ATOM0 + 21 SETGLOBAL T080-eq + 23 STOP +**) diff --git a/test/testinterp/t080-geint.ml b/test/testinterp/t080-geint.ml new file mode 100644 index 0000000..a220b7e --- /dev/null +++ b/test/testinterp/t080-geint.ml @@ -0,0 +1,21 @@ +open Lib;; +if not (0 >= 0) then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 GEINT + 12 BOOLNOT + 13 BRANCHIFNOT 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 ATOM0 + 21 SETGLOBAL T080-geint + 23 STOP +**) diff --git a/test/testinterp/t080-gtint.ml b/test/testinterp/t080-gtint.ml new file mode 100644 index 0000000..32d5732 --- /dev/null +++ b/test/testinterp/t080-gtint.ml @@ -0,0 +1,20 @@ +open Lib;; +if 0 > 0 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 GTINT + 12 BRANCHIFNOT 19 + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 ATOM0 + 20 SETGLOBAL T080-gtint + 22 STOP +**) diff --git a/test/testinterp/t080-leint.ml b/test/testinterp/t080-leint.ml new file mode 100644 index 0000000..cc983a0 --- /dev/null +++ b/test/testinterp/t080-leint.ml @@ -0,0 +1,21 @@ +open Lib;; +if not (0 <= 0) then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 LEINT + 12 BOOLNOT + 13 BRANCHIFNOT 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 ATOM0 + 21 SETGLOBAL T080-leint + 23 STOP +**) diff --git a/test/testinterp/t080-ltint.ml b/test/testinterp/t080-ltint.ml new file mode 100644 index 0000000..ae7d240 --- /dev/null +++ b/test/testinterp/t080-ltint.ml @@ -0,0 +1,20 @@ +open Lib;; +if 0 < 0 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 LTINT + 12 BRANCHIFNOT 19 + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 ATOM0 + 20 SETGLOBAL T080-ltint + 22 STOP +**) diff --git a/test/testinterp/t080-neq.ml b/test/testinterp/t080-neq.ml new file mode 100644 index 0000000..5066e9c --- /dev/null +++ b/test/testinterp/t080-neq.ml @@ -0,0 +1,20 @@ +open Lib;; +if 0 <> 0 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 NEQ + 12 BRANCHIFNOT 19 + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 ATOM0 + 20 SETGLOBAL T080-neq + 22 STOP +**) diff --git a/test/testinterp/t090-acc0.ml b/test/testinterp/t090-acc0.ml new file mode 100644 index 0000000..74accec --- /dev/null +++ b/test/testinterp/t090-acc0.ml @@ -0,0 +1,25 @@ +open Lib;; +let x = true in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 ACC0 + 12 BOOLNOT + 13 BRANCHIFNOT 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 POP 1 + 22 ATOM0 + 23 SETGLOBAL T090-acc0 + 25 STOP +**) diff --git a/test/testinterp/t090-acc1.ml b/test/testinterp/t090-acc1.ml new file mode 100644 index 0000000..fc9b025 --- /dev/null +++ b/test/testinterp/t090-acc1.ml @@ -0,0 +1,27 @@ +open Lib;; +let x = true in +let y = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 ACC1 + 13 BOOLNOT + 14 BRANCHIFNOT 21 + 16 GETGLOBAL Not_found + 18 MAKEBLOCK1 0 + 20 RAISE + 21 POP 2 + 23 ATOM0 + 24 SETGLOBAL T090-acc1 + 26 STOP +**) diff --git a/test/testinterp/t090-acc2.ml b/test/testinterp/t090-acc2.ml new file mode 100644 index 0000000..4865944 --- /dev/null +++ b/test/testinterp/t090-acc2.ml @@ -0,0 +1,29 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 ACC2 + 14 BOOLNOT + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 POP 3 + 24 ATOM0 + 25 SETGLOBAL T090-acc2 + 27 STOP +**) diff --git a/test/testinterp/t090-acc3.ml b/test/testinterp/t090-acc3.ml new file mode 100644 index 0000000..9622456 --- /dev/null +++ b/test/testinterp/t090-acc3.ml @@ -0,0 +1,31 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 ACC3 + 15 BOOLNOT + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 POP 4 + 25 ATOM0 + 26 SETGLOBAL T090-acc3 + 28 STOP +**) diff --git a/test/testinterp/t090-acc4.ml b/test/testinterp/t090-acc4.ml new file mode 100644 index 0000000..992559b --- /dev/null +++ b/test/testinterp/t090-acc4.ml @@ -0,0 +1,33 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +let b = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 ACC4 + 16 BOOLNOT + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 POP 5 + 26 ATOM0 + 27 SETGLOBAL T090-acc4 + 29 STOP +**) diff --git a/test/testinterp/t090-acc5.ml b/test/testinterp/t090-acc5.ml new file mode 100644 index 0000000..57f7453 --- /dev/null +++ b/test/testinterp/t090-acc5.ml @@ -0,0 +1,35 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +let b = false in +let c = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 PUSHCONST0 + 16 ACC5 + 17 BOOLNOT + 18 BRANCHIFNOT 25 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 POP 6 + 27 ATOM0 + 28 SETGLOBAL T090-acc5 + 30 STOP +**) diff --git a/test/testinterp/t090-acc6.ml b/test/testinterp/t090-acc6.ml new file mode 100644 index 0000000..f940028 --- /dev/null +++ b/test/testinterp/t090-acc6.ml @@ -0,0 +1,37 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +let b = false in +let c = false in +let d = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 PUSHCONST0 + 16 PUSHCONST0 + 17 ACC6 + 18 BOOLNOT + 19 BRANCHIFNOT 26 + 21 GETGLOBAL Not_found + 23 MAKEBLOCK1 0 + 25 RAISE + 26 POP 7 + 28 ATOM0 + 29 SETGLOBAL T090-acc6 + 31 STOP +**) diff --git a/test/testinterp/t090-acc7.ml b/test/testinterp/t090-acc7.ml new file mode 100644 index 0000000..366191b --- /dev/null +++ b/test/testinterp/t090-acc7.ml @@ -0,0 +1,39 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +let b = false in +let c = false in +let d = false in +let e = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 PUSHCONST0 + 16 PUSHCONST0 + 17 PUSHCONST0 + 18 ACC7 + 19 BOOLNOT + 20 BRANCHIFNOT 27 + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 POP 8 + 29 ATOM0 + 30 SETGLOBAL T090-acc7 + 32 STOP +**) diff --git a/test/testinterp/t091-acc.ml b/test/testinterp/t091-acc.ml new file mode 100644 index 0000000..26b003f --- /dev/null +++ b/test/testinterp/t091-acc.ml @@ -0,0 +1,41 @@ +open Lib;; +let x = true in +let y = false in +let z = false in +let a = false in +let b = false in +let c = false in +let d = false in +let e = false in +let f = false in +(); +if not x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHCONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 PUSHCONST0 + 16 PUSHCONST0 + 17 PUSHCONST0 + 18 PUSHCONST0 + 19 ACC 8 + 21 BOOLNOT + 22 BRANCHIFNOT 29 + 24 GETGLOBAL Not_found + 26 MAKEBLOCK1 0 + 28 RAISE + 29 POP 9 + 31 ATOM0 + 32 SETGLOBAL T091-acc + 34 STOP +**) diff --git a/test/testinterp/t092-pushacc.ml b/test/testinterp/t092-pushacc.ml new file mode 100644 index 0000000..c21561e --- /dev/null +++ b/test/testinterp/t092-pushacc.ml @@ -0,0 +1,38 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +let c = true in +let d = true in +let e = true in +let f = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHCONST1 + 15 PUSHCONST1 + 16 PUSHCONST1 + 17 PUSHCONST1 + 18 PUSHACC 8 + 20 BRANCHIFNOT 27 + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 POP 9 + 29 ATOM0 + 30 SETGLOBAL T092-pushacc + 32 STOP +**) diff --git a/test/testinterp/t092-pushacc0.ml b/test/testinterp/t092-pushacc0.ml new file mode 100644 index 0000000..ffdc3b0 --- /dev/null +++ b/test/testinterp/t092-pushacc0.ml @@ -0,0 +1,22 @@ +open Lib;; +let x = false in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHACC0 + 11 BRANCHIFNOT 18 + 13 GETGLOBAL Not_found + 15 MAKEBLOCK1 0 + 17 RAISE + 18 POP 1 + 20 ATOM0 + 21 SETGLOBAL T092-pushacc0 + 23 STOP +**) diff --git a/test/testinterp/t092-pushacc1.ml b/test/testinterp/t092-pushacc1.ml new file mode 100644 index 0000000..b923f4f --- /dev/null +++ b/test/testinterp/t092-pushacc1.ml @@ -0,0 +1,24 @@ +open Lib;; +let x = false in +let y = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHACC1 + 12 BRANCHIFNOT 19 + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 POP 2 + 21 ATOM0 + 22 SETGLOBAL T092-pushacc1 + 24 STOP +**) diff --git a/test/testinterp/t092-pushacc2.ml b/test/testinterp/t092-pushacc2.ml new file mode 100644 index 0000000..f624978 --- /dev/null +++ b/test/testinterp/t092-pushacc2.ml @@ -0,0 +1,26 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHACC2 + 13 BRANCHIFNOT 20 + 15 GETGLOBAL Not_found + 17 MAKEBLOCK1 0 + 19 RAISE + 20 POP 3 + 22 ATOM0 + 23 SETGLOBAL T092-pushacc2 + 25 STOP +**) diff --git a/test/testinterp/t092-pushacc3.ml b/test/testinterp/t092-pushacc3.ml new file mode 100644 index 0000000..5984fec --- /dev/null +++ b/test/testinterp/t092-pushacc3.ml @@ -0,0 +1,28 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHACC3 + 14 BRANCHIFNOT 21 + 16 GETGLOBAL Not_found + 18 MAKEBLOCK1 0 + 20 RAISE + 21 POP 4 + 23 ATOM0 + 24 SETGLOBAL T092-pushacc3 + 26 STOP +**) diff --git a/test/testinterp/t092-pushacc4.ml b/test/testinterp/t092-pushacc4.ml new file mode 100644 index 0000000..ce20e0b --- /dev/null +++ b/test/testinterp/t092-pushacc4.ml @@ -0,0 +1,30 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHACC4 + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 POP 5 + 24 ATOM0 + 25 SETGLOBAL T092-pushacc4 + 27 STOP +**) diff --git a/test/testinterp/t092-pushacc5.ml b/test/testinterp/t092-pushacc5.ml new file mode 100644 index 0000000..030f3f0 --- /dev/null +++ b/test/testinterp/t092-pushacc5.ml @@ -0,0 +1,32 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +let c = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHCONST1 + 15 PUSHACC5 + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 POP 6 + 25 ATOM0 + 26 SETGLOBAL T092-pushacc5 + 28 STOP +**) diff --git a/test/testinterp/t092-pushacc6.ml b/test/testinterp/t092-pushacc6.ml new file mode 100644 index 0000000..9c67b80 --- /dev/null +++ b/test/testinterp/t092-pushacc6.ml @@ -0,0 +1,34 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +let c = true in +let d = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHCONST1 + 15 PUSHCONST1 + 16 PUSHACC6 + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 POP 7 + 26 ATOM0 + 27 SETGLOBAL T092-pushacc6 + 29 STOP +**) diff --git a/test/testinterp/t092-pushacc7.ml b/test/testinterp/t092-pushacc7.ml new file mode 100644 index 0000000..09fbbca --- /dev/null +++ b/test/testinterp/t092-pushacc7.ml @@ -0,0 +1,36 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +let c = true in +let d = true in +let e = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHCONST1 + 15 PUSHCONST1 + 16 PUSHCONST1 + 17 PUSHACC7 + 18 BRANCHIFNOT 25 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 POP 8 + 27 ATOM0 + 28 SETGLOBAL T092-pushacc7 + 30 STOP +**) diff --git a/test/testinterp/t093-pushacc.ml b/test/testinterp/t093-pushacc.ml new file mode 100644 index 0000000..00a969a --- /dev/null +++ b/test/testinterp/t093-pushacc.ml @@ -0,0 +1,38 @@ +open Lib;; +let x = false in +let y = true in +let z = true in +let a = true in +let b = true in +let c = true in +let d = true in +let e = true in +let f = true in +if x then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST1 + 11 PUSHCONST1 + 12 PUSHCONST1 + 13 PUSHCONST1 + 14 PUSHCONST1 + 15 PUSHCONST1 + 16 PUSHCONST1 + 17 PUSHCONST1 + 18 PUSHACC 8 + 20 BRANCHIFNOT 27 + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 POP 9 + 29 ATOM0 + 30 SETGLOBAL T093-pushacc + 32 STOP +**) diff --git a/test/testinterp/t100-pushtrap.ml b/test/testinterp/t100-pushtrap.ml new file mode 100644 index 0000000..7b02a86 --- /dev/null +++ b/test/testinterp/t100-pushtrap.ml @@ -0,0 +1,21 @@ +open Lib;; +try raise Not_found +with _ -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 PUSHTRAP 16 + 11 GETGLOBAL Not_found + 13 MAKEBLOCK1 0 + 15 RAISE + 16 PUSHCONST0 + 17 POP 1 + 19 ATOM0 + 20 SETGLOBAL T100-pushtrap + 22 STOP +**) diff --git a/test/testinterp/t101-poptrap.ml b/test/testinterp/t101-poptrap.ml new file mode 100644 index 0000000..3a754a0 --- /dev/null +++ b/test/testinterp/t101-poptrap.ml @@ -0,0 +1,21 @@ +open Lib;; +try () +with _ -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 PUSHTRAP 15 + 11 CONST0 + 12 POPTRAP + 13 BRANCH 18 + 15 PUSHCONST0 + 16 POP 1 + 18 ATOM0 + 19 SETGLOBAL T101-poptrap + 21 STOP +**) diff --git a/test/testinterp/t110-addint.ml b/test/testinterp/t110-addint.ml new file mode 100644 index 0000000..5d683c5 --- /dev/null +++ b/test/testinterp/t110-addint.ml @@ -0,0 +1,26 @@ +open Lib;; +let x = 1 in +if 1 + x <> 2 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST2 + 11 PUSHACC1 + 12 PUSHCONST1 + 13 ADDINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 POP 1 + 24 ATOM0 + 25 SETGLOBAL T110-addint + 27 STOP +**) diff --git a/test/testinterp/t110-andint.ml b/test/testinterp/t110-andint.ml new file mode 100644 index 0000000..016dc3c --- /dev/null +++ b/test/testinterp/t110-andint.ml @@ -0,0 +1,22 @@ +open Lib;; +if (3 land 6) <> 2 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHCONSTINT 6 + 12 PUSHCONST3 + 13 ANDINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-andint + 25 STOP +**) diff --git a/test/testinterp/t110-asrint-1.ml b/test/testinterp/t110-asrint-1.ml new file mode 100644 index 0000000..173bdca --- /dev/null +++ b/test/testinterp/t110-asrint-1.ml @@ -0,0 +1,22 @@ +open Lib;; +if (-2 asr 1) <> -1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT -1 + 11 PUSHCONST1 + 12 PUSHCONSTINT -2 + 14 ASRINT + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T110-asrint-1 + 26 STOP +**) diff --git a/test/testinterp/t110-asrint-2.ml b/test/testinterp/t110-asrint-2.ml new file mode 100644 index 0000000..386fc64 --- /dev/null +++ b/test/testinterp/t110-asrint-2.ml @@ -0,0 +1,22 @@ +open Lib;; +if (3 asr 1) <> 1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST1 + 11 PUSHCONST3 + 12 ASRINT + 13 NEQ + 14 BRANCHIFNOT 21 + 16 GETGLOBAL Not_found + 18 MAKEBLOCK1 0 + 20 RAISE + 21 ATOM0 + 22 SETGLOBAL T110-asrint-2 + 24 STOP +**) diff --git a/test/testinterp/t110-divint-1.ml b/test/testinterp/t110-divint-1.ml new file mode 100644 index 0000000..5cde135 --- /dev/null +++ b/test/testinterp/t110-divint-1.ml @@ -0,0 +1,22 @@ +open Lib;; +if 2 / 2 <> 1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST2 + 11 PUSHCONST2 + 12 DIVINT + 13 NEQ + 14 BRANCHIFNOT 21 + 16 GETGLOBAL Not_found + 18 MAKEBLOCK1 0 + 20 RAISE + 21 ATOM0 + 22 SETGLOBAL T110-divint-1 + 24 STOP +**) diff --git a/test/testinterp/t110-divint-2.ml b/test/testinterp/t110-divint-2.ml new file mode 100644 index 0000000..34f5b00 --- /dev/null +++ b/test/testinterp/t110-divint-2.ml @@ -0,0 +1,22 @@ +open Lib;; +if 3 / 2 <> 1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST2 + 11 PUSHCONST3 + 12 DIVINT + 13 NEQ + 14 BRANCHIFNOT 21 + 16 GETGLOBAL Not_found + 18 MAKEBLOCK1 0 + 20 RAISE + 21 ATOM0 + 22 SETGLOBAL T110-divint-2 + 24 STOP +**) diff --git a/test/testinterp/t110-divint-3.ml b/test/testinterp/t110-divint-3.ml new file mode 100644 index 0000000..cbb2bff --- /dev/null +++ b/test/testinterp/t110-divint-3.ml @@ -0,0 +1,33 @@ +open Lib;; +try + ignore (3 / 0); + raise Not_found; +with Division_by_zero -> () + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 PUSHTRAP 19 + 11 CONST0 + 12 PUSHCONST3 + 13 DIVINT + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 PUSHGETGLOBAL Division_by_zero + 21 PUSHACC1 + 22 GETFIELD0 + 23 EQ + 24 BRANCHIFNOT 29 + 26 CONST0 + 27 BRANCH 31 + 29 ACC0 + 30 RAISE + 31 POP 1 + 33 ATOM0 + 34 SETGLOBAL T110-divint-3 + 36 STOP +**) diff --git a/test/testinterp/t110-lslint.ml b/test/testinterp/t110-lslint.ml new file mode 100644 index 0000000..9dd197b --- /dev/null +++ b/test/testinterp/t110-lslint.ml @@ -0,0 +1,22 @@ +open Lib;; +if (3 lsl 2) <> 12 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 12 + 11 PUSHCONST2 + 12 PUSHCONST3 + 13 LSLINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-lslint + 25 STOP +**) diff --git a/test/testinterp/t110-lsrint.ml b/test/testinterp/t110-lsrint.ml new file mode 100644 index 0000000..9777815 --- /dev/null +++ b/test/testinterp/t110-lsrint.ml @@ -0,0 +1,22 @@ +open Lib;; +if (14 lsr 2) <> 3 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST3 + 10 PUSHCONST2 + 11 PUSHCONSTINT 14 + 13 LSRINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-lsrint + 25 STOP +**) diff --git a/test/testinterp/t110-modint-1.ml b/test/testinterp/t110-modint-1.ml new file mode 100644 index 0000000..2a690c0 --- /dev/null +++ b/test/testinterp/t110-modint-1.ml @@ -0,0 +1,22 @@ +open Lib;; +if 20 mod 3 <> 2 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHCONST3 + 11 PUSHCONSTINT 20 + 13 MODINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-modint-1 + 25 STOP +**) diff --git a/test/testinterp/t110-modint-2.ml b/test/testinterp/t110-modint-2.ml new file mode 100644 index 0000000..0bc3be0 --- /dev/null +++ b/test/testinterp/t110-modint-2.ml @@ -0,0 +1,34 @@ +open Lib;; +try + ignore (2 mod 0); + raise Not_found; +with Division_by_zero -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 PUSHTRAP 19 + 11 CONST0 + 12 PUSHCONST2 + 13 MODINT + 14 GETGLOBAL Not_found + 16 MAKEBLOCK1 0 + 18 RAISE + 19 PUSHGETGLOBAL Division_by_zero + 21 PUSHACC1 + 22 GETFIELD0 + 23 EQ + 24 BRANCHIFNOT 29 + 26 CONST0 + 27 BRANCH 31 + 29 ACC0 + 30 RAISE + 31 POP 1 + 33 ATOM0 + 34 SETGLOBAL T110-modint-2 + 36 STOP +**) diff --git a/test/testinterp/t110-mulint.ml b/test/testinterp/t110-mulint.ml new file mode 100644 index 0000000..97c1cf1 --- /dev/null +++ b/test/testinterp/t110-mulint.ml @@ -0,0 +1,22 @@ +open Lib;; +if 2 * 2 <> 4 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 4 + 11 PUSHCONST2 + 12 PUSHCONST2 + 13 MULINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-mulint + 25 STOP +**) diff --git a/test/testinterp/t110-negint.ml b/test/testinterp/t110-negint.ml new file mode 100644 index 0000000..069a34b --- /dev/null +++ b/test/testinterp/t110-negint.ml @@ -0,0 +1,25 @@ +open Lib;; +let x = 1 in +if -x <> -1 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONSTINT -1 + 12 PUSHACC1 + 13 NEGINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 POP 1 + 24 ATOM0 + 25 SETGLOBAL T110-negint + 27 STOP +**) diff --git a/test/testinterp/t110-offsetint.ml b/test/testinterp/t110-offsetint.ml new file mode 100644 index 0000000..925159e --- /dev/null +++ b/test/testinterp/t110-offsetint.ml @@ -0,0 +1,21 @@ +open Lib;; +if 2 + 2 <> 4 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 4 + 11 PUSHCONST2 + 12 OFFSETINT 2 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T110-offsetint + 25 STOP +**) diff --git a/test/testinterp/t110-orint.ml b/test/testinterp/t110-orint.ml new file mode 100644 index 0000000..56b63d8 --- /dev/null +++ b/test/testinterp/t110-orint.ml @@ -0,0 +1,22 @@ +open Lib;; +if (3 lor 6) <> 7 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 7 + 11 PUSHCONSTINT 6 + 13 PUSHCONST3 + 14 ORINT + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T110-orint + 26 STOP +**) diff --git a/test/testinterp/t110-subint.ml b/test/testinterp/t110-subint.ml new file mode 100644 index 0000000..f626cd0 --- /dev/null +++ b/test/testinterp/t110-subint.ml @@ -0,0 +1,26 @@ +open Lib;; +let x = 1 in +if 1 - x <> 0 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST0 + 11 PUSHACC1 + 12 PUSHCONST1 + 13 SUBINT + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 POP 1 + 24 ATOM0 + 25 SETGLOBAL T110-subint + 27 STOP +**) diff --git a/test/testinterp/t110-xorint.ml b/test/testinterp/t110-xorint.ml new file mode 100644 index 0000000..dfb278b --- /dev/null +++ b/test/testinterp/t110-xorint.ml @@ -0,0 +1,22 @@ +open Lib;; +if (3 lxor 6) <> 5 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 5 + 11 PUSHCONSTINT 6 + 13 PUSHCONST3 + 14 XORINT + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T110-xorint + 26 STOP +**) diff --git a/test/testinterp/t120-getstringchar.ml b/test/testinterp/t120-getstringchar.ml new file mode 100644 index 0000000..aaff202 --- /dev/null +++ b/test/testinterp/t120-getstringchar.ml @@ -0,0 +1,22 @@ +open Lib;; +if "foo".[2] <> 'o' then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 111 + 11 PUSHCONST2 + 12 PUSHGETGLOBAL "foo" + 14 GETSTRINGCHAR + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T120-getstringchar + 26 STOP +**) diff --git a/test/testinterp/t121-setstringchar.ml b/test/testinterp/t121-setstringchar.ml new file mode 100644 index 0000000..882d6e0 --- /dev/null +++ b/test/testinterp/t121-setstringchar.ml @@ -0,0 +1,31 @@ +open Lib;; +let x = "foo" in +x.[2] <- 'x'; +if x.[2] <> 'x' then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL "foo" + 11 PUSHCONSTINT 120 + 13 PUSHCONST2 + 14 PUSHACC2 + 15 SETSTRINGCHAR + 16 CONSTINT 120 + 18 PUSHCONST2 + 19 PUSHACC2 + 20 GETSTRINGCHAR + 21 NEQ + 22 BRANCHIFNOT 29 + 24 GETGLOBAL Not_found + 26 MAKEBLOCK1 0 + 28 RAISE + 29 POP 1 + 31 ATOM0 + 32 SETGLOBAL T121-setstringchar + 34 STOP +**) diff --git a/test/testinterp/t130-getvectitem.ml b/test/testinterp/t130-getvectitem.ml new file mode 100644 index 0000000..d290379 --- /dev/null +++ b/test/testinterp/t130-getvectitem.ml @@ -0,0 +1,24 @@ +open Lib;; +if [| 1; 2 |].(1) <> 2 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHCONST1 + 11 PUSHCONST2 + 12 PUSHCONST1 + 13 MAKEBLOCK2 0 + 15 GETVECTITEM + 16 NEQ + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 ATOM0 + 25 SETGLOBAL T130-getvectitem + 27 STOP +**) diff --git a/test/testinterp/t130-vectlength.ml b/test/testinterp/t130-vectlength.ml new file mode 100644 index 0000000..ce0da0e --- /dev/null +++ b/test/testinterp/t130-vectlength.ml @@ -0,0 +1,23 @@ +open Lib;; +if Array.length [| 1; 2 |] <> 2 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHCONST2 + 11 PUSHCONST1 + 12 MAKEBLOCK2 0 + 14 VECTLENGTH + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T130-vectlength + 26 STOP +**) diff --git a/test/testinterp/t131-setvectitem.ml b/test/testinterp/t131-setvectitem.ml new file mode 100644 index 0000000..f544a3e --- /dev/null +++ b/test/testinterp/t131-setvectitem.ml @@ -0,0 +1,33 @@ +open Lib;; +let x = [| 1; 2 |] in +x.(0) <- 3; +if x.(0) <> 3 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHCONST1 + 11 MAKEBLOCK2 0 + 13 PUSHCONST3 + 14 PUSHCONST0 + 15 PUSHACC2 + 16 SETVECTITEM + 17 CONST3 + 18 PUSHCONST0 + 19 PUSHACC2 + 20 GETVECTITEM + 21 NEQ + 22 BRANCHIFNOT 29 + 24 GETGLOBAL Not_found + 26 MAKEBLOCK1 0 + 28 RAISE + 29 POP 1 + 31 ATOM0 + 32 SETGLOBAL T131-setvectitem + 34 STOP +**) diff --git a/test/testinterp/t140-switch-1.ml b/test/testinterp/t140-switch-1.ml new file mode 100644 index 0000000..b2d7352 --- /dev/null +++ b/test/testinterp/t140-switch-1.ml @@ -0,0 +1,32 @@ +open Lib;; +match 0 with +| 0 -> () +| 1 -> raise Not_found +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHACC0 + 11 SWITCH + int 0 -> 17 + int 1 -> 20 + 15 BRANCH 25 + 17 CONST0 + 18 BRANCH 30 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 GETGLOBAL Not_found + 27 MAKEBLOCK1 0 + 29 RAISE + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T140-switch-1 + 35 STOP +**) diff --git a/test/testinterp/t140-switch-2.ml b/test/testinterp/t140-switch-2.ml new file mode 100644 index 0000000..9004fa6 --- /dev/null +++ b/test/testinterp/t140-switch-2.ml @@ -0,0 +1,32 @@ +open Lib;; +match 1 with +| 0 -> raise Not_found +| 1 -> () +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHACC0 + 11 SWITCH + int 0 -> 17 + int 1 -> 22 + 15 BRANCH 25 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 CONST0 + 23 BRANCH 30 + 25 GETGLOBAL Not_found + 27 MAKEBLOCK1 0 + 29 RAISE + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T140-switch-2 + 35 STOP +**) diff --git a/test/testinterp/t140-switch-3.ml b/test/testinterp/t140-switch-3.ml new file mode 100644 index 0000000..b0c4bc8 --- /dev/null +++ b/test/testinterp/t140-switch-3.ml @@ -0,0 +1,31 @@ +open Lib;; +match 2 with +| 0 -> raise Not_found +| 1 -> raise Not_found +| _ -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST2 + 10 PUSHACC0 + 11 SWITCH + int 0 -> 17 + int 1 -> 22 + 15 BRANCH 27 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 CONST0 + 28 POP 1 + 30 ATOM0 + 31 SETGLOBAL T140-switch-3 + 33 STOP +**) diff --git a/test/testinterp/t140-switch-4.ml b/test/testinterp/t140-switch-4.ml new file mode 100644 index 0000000..1826b09 --- /dev/null +++ b/test/testinterp/t140-switch-4.ml @@ -0,0 +1,31 @@ +open Lib;; +match -1 with +| 0 -> raise Not_found +| 1 -> raise Not_found +| _ -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT -1 + 11 PUSHACC0 + 12 SWITCH + int 0 -> 18 + int 1 -> 23 + 16 BRANCH 28 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 GETGLOBAL Not_found + 25 MAKEBLOCK1 0 + 27 RAISE + 28 CONST0 + 29 POP 1 + 31 ATOM0 + 32 SETGLOBAL T140-switch-4 + 34 STOP +**) diff --git a/test/testinterp/t141-switch-5.ml b/test/testinterp/t141-switch-5.ml new file mode 100644 index 0000000..ca44849 --- /dev/null +++ b/test/testinterp/t141-switch-5.ml @@ -0,0 +1,38 @@ +open Lib;; +type t = + | A of int + | B of int + | C of int +;; + +match A 0 with +| A _ -> () +| B _ -> raise Not_found +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL <0>(0) + 11 PUSHACC0 + 12 SWITCH + tag 0 -> 17 + tag 1 -> 20 + tag 2 -> 25 + 17 CONST0 + 18 BRANCH 30 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 GETGLOBAL Not_found + 27 MAKEBLOCK1 0 + 29 RAISE + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T141-switch-5 + 35 STOP +**) diff --git a/test/testinterp/t141-switch-6.ml b/test/testinterp/t141-switch-6.ml new file mode 100644 index 0000000..c48e80b --- /dev/null +++ b/test/testinterp/t141-switch-6.ml @@ -0,0 +1,38 @@ +open Lib;; +type t = + | A of int + | B of int + | C of int +;; + +match B 0 with +| A _ -> raise Not_found +| B _ -> () +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL <1>(0) + 11 PUSHACC0 + 12 SWITCH + tag 0 -> 17 + tag 1 -> 22 + tag 2 -> 25 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 CONST0 + 23 BRANCH 30 + 25 GETGLOBAL Not_found + 27 MAKEBLOCK1 0 + 29 RAISE + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T141-switch-6 + 35 STOP +**) diff --git a/test/testinterp/t141-switch-7.ml b/test/testinterp/t141-switch-7.ml new file mode 100644 index 0000000..00f4873 --- /dev/null +++ b/test/testinterp/t141-switch-7.ml @@ -0,0 +1,37 @@ +open Lib;; +type t = + | A of int + | B of int + | C of int +;; + +match C 0 with +| A _ -> raise Not_found +| B _ -> raise Not_found +| _ -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL <2>(0) + 11 PUSHACC0 + 12 SWITCH + tag 0 -> 17 + tag 1 -> 22 + tag 2 -> 27 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 CONST0 + 28 POP 1 + 30 ATOM0 + 31 SETGLOBAL T141-switch-7 + 33 STOP +**) diff --git a/test/testinterp/t142-switch-8.ml b/test/testinterp/t142-switch-8.ml new file mode 100644 index 0000000..5145913 --- /dev/null +++ b/test/testinterp/t142-switch-8.ml @@ -0,0 +1,34 @@ +open Lib;; +type t = + | A + | B of int + | C of int +;; + +match A with +| A -> () +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHACC0 + 11 SWITCH + int 0 -> 16 + tag 0 -> 19 + tag 1 -> 19 + 16 CONST0 + 17 BRANCH 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 POP 1 + 26 ATOM0 + 27 SETGLOBAL T142-switch-8 + 29 STOP +**) diff --git a/test/testinterp/t142-switch-9.ml b/test/testinterp/t142-switch-9.ml new file mode 100644 index 0000000..a0e43d3 --- /dev/null +++ b/test/testinterp/t142-switch-9.ml @@ -0,0 +1,34 @@ +open Lib;; +type t = + | A + | B of int + | C of int +;; + +match B 0 with +| B _ -> () +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL <0>(0) + 11 PUSHACC0 + 12 SWITCH + int 0 -> 20 + tag 0 -> 17 + tag 1 -> 20 + 17 CONST0 + 18 BRANCH 25 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 POP 1 + 27 ATOM0 + 28 SETGLOBAL T142-switch-9 + 30 STOP +**) diff --git a/test/testinterp/t142-switch-A.ml b/test/testinterp/t142-switch-A.ml new file mode 100644 index 0000000..4f66aec --- /dev/null +++ b/test/testinterp/t142-switch-A.ml @@ -0,0 +1,34 @@ +open Lib;; +type t = + | A + | B of int + | C of int +;; + +match C 0 with +| C _ -> () +| _ -> raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL <1>(0) + 11 PUSHACC0 + 12 SWITCH + int 0 -> 20 + tag 0 -> 20 + tag 1 -> 17 + 17 CONST0 + 18 BRANCH 25 + 20 GETGLOBAL Not_found + 22 MAKEBLOCK1 0 + 24 RAISE + 25 POP 1 + 27 ATOM0 + 28 SETGLOBAL T142-switch-A + 30 STOP +**) diff --git a/test/testinterp/t150-push-1.ml b/test/testinterp/t150-push-1.ml new file mode 100644 index 0000000..9264927 --- /dev/null +++ b/test/testinterp/t150-push-1.ml @@ -0,0 +1,24 @@ +open Lib;; +let _ = 0 in +try 0 with _ -> 0 +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSH + 11 PUSHTRAP 17 + 13 CONST0 + 14 POPTRAP + 15 BRANCH 20 + 17 PUSHCONST0 + 18 POP 1 + 20 POP 1 + 22 ATOM0 + 23 SETGLOBAL T150-push-1 + 25 STOP +**) diff --git a/test/testinterp/t150-push-2.ml b/test/testinterp/t150-push-2.ml new file mode 100644 index 0000000..d6f5107 --- /dev/null +++ b/test/testinterp/t150-push-2.ml @@ -0,0 +1,39 @@ +open Lib;; +let x = 1 in +try if x <> 1 then raise Not_found +with End_of_file -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSH + 11 PUSHTRAP 26 + 13 CONST1 + 14 PUSHACC5 + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 POPTRAP + 24 BRANCH 40 + 26 PUSHGETGLOBAL End_of_file + 28 PUSHACC1 + 29 GETFIELD0 + 30 EQ + 31 BRANCHIFNOT 36 + 33 CONST0 + 34 BRANCH 38 + 36 ACC0 + 37 RAISE + 38 POP 1 + 40 POP 1 + 42 ATOM0 + 43 SETGLOBAL T150-push-2 + 45 STOP +**) diff --git a/test/testinterp/t160-closure.ml b/test/testinterp/t160-closure.ml new file mode 100644 index 0000000..5eb6128 --- /dev/null +++ b/test/testinterp/t160-closure.ml @@ -0,0 +1,19 @@ +open Lib;; +let f () = ();; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 14 + 11 CONST0 + 12 RETURN 1 + 14 CLOSURE 0, 11 + 17 PUSHACC0 + 18 MAKEBLOCK1 0 + 20 POP 1 + 22 SETGLOBAL T160-closure + 24 STOP +**) diff --git a/test/testinterp/t161-apply1.ml b/test/testinterp/t161-apply1.ml new file mode 100644 index 0000000..5138c5f --- /dev/null +++ b/test/testinterp/t161-apply1.ml @@ -0,0 +1,42 @@ +open Lib;; +let f _ = raise End_of_file in +try + f 0; + raise Not_found; +with End_of_file -> 0 +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 16 + 11 GETGLOBAL End_of_file + 13 MAKEBLOCK1 0 + 15 RAISE + 16 CLOSURE 0, 11 + 19 PUSH + 20 PUSHTRAP 30 + 22 CONST0 + 23 PUSHACC5 + 24 APPLY1 + 25 GETGLOBAL Not_found + 27 MAKEBLOCK1 0 + 29 RAISE + 30 PUSHGETGLOBAL End_of_file + 32 PUSHACC1 + 33 GETFIELD0 + 34 EQ + 35 BRANCHIFNOT 40 + 37 CONST0 + 38 BRANCH 42 + 40 ACC0 + 41 RAISE + 42 POP 1 + 44 POP 1 + 46 ATOM0 + 47 SETGLOBAL T161-apply1 + 49 STOP +**) diff --git a/test/testinterp/t162-return.ml b/test/testinterp/t162-return.ml new file mode 100644 index 0000000..1059c9f --- /dev/null +++ b/test/testinterp/t162-return.ml @@ -0,0 +1,21 @@ +open Lib;; +let f _ = 0 in f 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 14 + 11 CONST0 + 12 RETURN 1 + 14 CLOSURE 0, 11 + 17 PUSHCONST0 + 18 PUSHACC1 + 19 APPLY1 + 20 POP 1 + 22 ATOM0 + 23 SETGLOBAL T162-return + 25 STOP +**) diff --git a/test/testinterp/t163.ml b/test/testinterp/t163.ml new file mode 100644 index 0000000..9ec7790 --- /dev/null +++ b/test/testinterp/t163.ml @@ -0,0 +1,23 @@ +open Lib;; +let f _ _ = 0 in f 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 17 + 11 RESTART + 12 GRAB 1 + 14 CONST0 + 15 RETURN 2 + 17 CLOSURE 0, 12 + 20 PUSHCONST0 + 21 PUSHACC1 + 22 APPLY1 + 23 POP 1 + 25 ATOM0 + 26 SETGLOBAL T163 + 28 STOP +**) diff --git a/test/testinterp/t164-apply2.ml b/test/testinterp/t164-apply2.ml new file mode 100644 index 0000000..7fbe7d9 --- /dev/null +++ b/test/testinterp/t164-apply2.ml @@ -0,0 +1,24 @@ +open Lib;; +let f _ _ = 0 in f 0 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 17 + 11 RESTART + 12 GRAB 1 + 14 CONST0 + 15 RETURN 2 + 17 CLOSURE 0, 12 + 20 PUSHCONST0 + 21 PUSHCONST0 + 22 PUSHACC2 + 23 APPLY2 + 24 POP 1 + 26 ATOM0 + 27 SETGLOBAL T164-apply2 + 29 STOP +**) diff --git a/test/testinterp/t164-apply3.ml b/test/testinterp/t164-apply3.ml new file mode 100644 index 0000000..e7ebc3a --- /dev/null +++ b/test/testinterp/t164-apply3.ml @@ -0,0 +1,25 @@ +open Lib;; +let f _ _ _ = 0 in f 0 0 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 17 + 11 RESTART + 12 GRAB 2 + 14 CONST0 + 15 RETURN 3 + 17 CLOSURE 0, 12 + 20 PUSHCONST0 + 21 PUSHCONST0 + 22 PUSHCONST0 + 23 PUSHACC3 + 24 APPLY3 + 25 POP 1 + 27 ATOM0 + 28 SETGLOBAL T164-apply3 + 30 STOP +**) diff --git a/test/testinterp/t165-apply.ml b/test/testinterp/t165-apply.ml new file mode 100644 index 0000000..9d66855 --- /dev/null +++ b/test/testinterp/t165-apply.ml @@ -0,0 +1,28 @@ +open Lib;; +let f _ _ _ _ = 0 in f 0 0 0 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 17 + 11 RESTART + 12 GRAB 3 + 14 CONST0 + 15 RETURN 4 + 17 CLOSURE 0, 12 + 20 PUSH + 21 PUSH_RETADDR 30 + 23 CONST0 + 24 PUSHCONST0 + 25 PUSHCONST0 + 26 PUSHCONST0 + 27 PUSHACC7 + 28 APPLY 4 + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T165-apply + 35 STOP +**) diff --git a/test/testinterp/t170-envacc2.ml b/test/testinterp/t170-envacc2.ml new file mode 100644 index 0000000..3a37366 --- /dev/null +++ b/test/testinterp/t170-envacc2.ml @@ -0,0 +1,37 @@ +open Lib;; +let x = 5 in +let y = 2 in +let f _ = ignore x; y in +if f 0 <> 2 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 16 + 11 ENVACC1 + 12 CONST0 + 13 ENVACC2 + 14 RETURN 1 + 16 CONSTINT 5 + 18 PUSHCONST2 + 19 PUSHACC0 + 20 PUSHACC2 + 21 CLOSURE 2, 11 + 24 PUSHCONST2 + 25 PUSHCONST0 + 26 PUSHACC2 + 27 APPLY1 + 28 NEQ + 29 BRANCHIFNOT 36 + 31 GETGLOBAL Not_found + 33 MAKEBLOCK1 0 + 35 RAISE + 36 POP 3 + 38 ATOM0 + 39 SETGLOBAL T170-envacc2 + 41 STOP +**) diff --git a/test/testinterp/t170-envacc3.ml b/test/testinterp/t170-envacc3.ml new file mode 100644 index 0000000..9a2b8b5 --- /dev/null +++ b/test/testinterp/t170-envacc3.ml @@ -0,0 +1,42 @@ +open Lib;; +let x = 5 in +let y = 2 in +let z = 1 in +let f _ = ignore x; ignore y; z in +if f 0 <> 1 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 18 + 11 ENVACC1 + 12 CONST0 + 13 ENVACC2 + 14 CONST0 + 15 ENVACC3 + 16 RETURN 1 + 18 CONSTINT 5 + 20 PUSHCONST2 + 21 PUSHCONST1 + 22 PUSHACC0 + 23 PUSHACC2 + 24 PUSHACC4 + 25 CLOSURE 3, 11 + 28 PUSHCONST1 + 29 PUSHCONST0 + 30 PUSHACC2 + 31 APPLY1 + 32 NEQ + 33 BRANCHIFNOT 40 + 35 GETGLOBAL Not_found + 37 MAKEBLOCK1 0 + 39 RAISE + 40 POP 4 + 42 ATOM0 + 43 SETGLOBAL T170-envacc3 + 45 STOP +**) diff --git a/test/testinterp/t170-envacc4.ml b/test/testinterp/t170-envacc4.ml new file mode 100644 index 0000000..215e322 --- /dev/null +++ b/test/testinterp/t170-envacc4.ml @@ -0,0 +1,47 @@ +open Lib;; +let x = 5 in +let y = 2 in +let z = 1 in +let a = 4 in +let f _ = ignore x; ignore y; ignore z; a in +if f 0 <> 4 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 20 + 11 ENVACC1 + 12 CONST0 + 13 ENVACC2 + 14 CONST0 + 15 ENVACC3 + 16 CONST0 + 17 ENVACC4 + 18 RETURN 1 + 20 CONSTINT 5 + 22 PUSHCONST2 + 23 PUSHCONST1 + 24 PUSHCONSTINT 4 + 26 PUSHACC0 + 27 PUSHACC2 + 28 PUSHACC4 + 29 PUSHACC6 + 30 CLOSURE 4, 11 + 33 PUSHCONSTINT 4 + 35 PUSHCONST0 + 36 PUSHACC2 + 37 APPLY1 + 38 NEQ + 39 BRANCHIFNOT 46 + 41 GETGLOBAL Not_found + 43 MAKEBLOCK1 0 + 45 RAISE + 46 POP 5 + 48 ATOM0 + 49 SETGLOBAL T170-envacc4 + 51 STOP +**) diff --git a/test/testinterp/t171-envacc.ml b/test/testinterp/t171-envacc.ml new file mode 100644 index 0000000..4c4a3df --- /dev/null +++ b/test/testinterp/t171-envacc.ml @@ -0,0 +1,52 @@ +open Lib;; +let x = 5 in +let y = 2 in +let z = 1 in +let a = 4 in +let b = 3 in +let f _ = ignore x; ignore y; ignore z; ignore a; b in +if f 0 <> 3 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 23 + 11 ENVACC1 + 12 CONST0 + 13 ENVACC2 + 14 CONST0 + 15 ENVACC3 + 16 CONST0 + 17 ENVACC4 + 18 CONST0 + 19 ENVACC 5 + 21 RETURN 1 + 23 CONSTINT 5 + 25 PUSHCONST2 + 26 PUSHCONST1 + 27 PUSHCONSTINT 4 + 29 PUSHCONST3 + 30 PUSHACC0 + 31 PUSHACC2 + 32 PUSHACC4 + 33 PUSHACC6 + 34 PUSHACC 8 + 36 CLOSURE 5, 11 + 39 PUSHCONST3 + 40 PUSHCONST0 + 41 PUSHACC2 + 42 APPLY1 + 43 NEQ + 44 BRANCHIFNOT 51 + 46 GETGLOBAL Not_found + 48 MAKEBLOCK1 0 + 50 RAISE + 51 POP 6 + 53 ATOM0 + 54 SETGLOBAL T171-envacc + 56 STOP +**) diff --git a/test/testinterp/t172-pushenvacc1.ml b/test/testinterp/t172-pushenvacc1.ml new file mode 100644 index 0000000..06c4011 --- /dev/null +++ b/test/testinterp/t172-pushenvacc1.ml @@ -0,0 +1,34 @@ +open Lib;; +let x = 5 in +let f _ = x + x in +if f 0 <> 10 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 16 + 11 ENVACC1 + 12 PUSHENVACC1 + 13 ADDINT + 14 RETURN 1 + 16 CONSTINT 5 + 18 PUSHACC0 + 19 CLOSURE 1, 11 + 22 PUSHCONSTINT 10 + 24 PUSHCONST0 + 25 PUSHACC2 + 26 APPLY1 + 27 NEQ + 28 BRANCHIFNOT 35 + 30 GETGLOBAL Not_found + 32 MAKEBLOCK1 0 + 34 RAISE + 35 POP 2 + 37 ATOM0 + 38 SETGLOBAL T172-pushenvacc1 + 40 STOP +**) diff --git a/test/testinterp/t172-pushenvacc2.ml b/test/testinterp/t172-pushenvacc2.ml new file mode 100644 index 0000000..c25e40a --- /dev/null +++ b/test/testinterp/t172-pushenvacc2.ml @@ -0,0 +1,37 @@ +open Lib;; +let x = 5 in +let y = 4 in +let f _ = y + x in +if f 0 <> 9 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 16 + 11 ENVACC1 + 12 PUSHENVACC2 + 13 ADDINT + 14 RETURN 1 + 16 CONSTINT 5 + 18 PUSHCONSTINT 4 + 20 PUSHACC0 + 21 PUSHACC2 + 22 CLOSURE 2, 11 + 25 PUSHCONSTINT 9 + 27 PUSHCONST0 + 28 PUSHACC2 + 29 APPLY1 + 30 NEQ + 31 BRANCHIFNOT 38 + 33 GETGLOBAL Not_found + 35 MAKEBLOCK1 0 + 37 RAISE + 38 POP 3 + 40 ATOM0 + 41 SETGLOBAL T172-pushenvacc2 + 43 STOP +**) diff --git a/test/testinterp/t172-pushenvacc3.ml b/test/testinterp/t172-pushenvacc3.ml new file mode 100644 index 0000000..093f7f1 --- /dev/null +++ b/test/testinterp/t172-pushenvacc3.ml @@ -0,0 +1,42 @@ +open Lib;; +let x = 5 in +let y = 4 in +let z = 3 in +let f _ = z + y + x in +if f 0 <> 12 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 18 + 11 ENVACC1 + 12 PUSHENVACC2 + 13 PUSHENVACC3 + 14 ADDINT + 15 ADDINT + 16 RETURN 1 + 18 CONSTINT 5 + 20 PUSHCONSTINT 4 + 22 PUSHCONST3 + 23 PUSHACC0 + 24 PUSHACC2 + 25 PUSHACC4 + 26 CLOSURE 3, 11 + 29 PUSHCONSTINT 12 + 31 PUSHCONST0 + 32 PUSHACC2 + 33 APPLY1 + 34 NEQ + 35 BRANCHIFNOT 42 + 37 GETGLOBAL Not_found + 39 MAKEBLOCK1 0 + 41 RAISE + 42 POP 4 + 44 ATOM0 + 45 SETGLOBAL T172-pushenvacc3 + 47 STOP +**) diff --git a/test/testinterp/t172-pushenvacc4.ml b/test/testinterp/t172-pushenvacc4.ml new file mode 100644 index 0000000..154c4a4 --- /dev/null +++ b/test/testinterp/t172-pushenvacc4.ml @@ -0,0 +1,47 @@ +open Lib;; +let x = 5 in +let y = 4 in +let z = 3 in +let a = 2 in +let f _ = a + z + y + x in +if f 0 <> 14 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 21 + 11 ENVACC1 + 12 PUSHENVACC2 + 13 PUSHENVACC3 + 14 PUSHENVACC 4 + 16 ADDINT + 17 ADDINT + 18 ADDINT + 19 RETURN 1 + 21 CONSTINT 5 + 23 PUSHCONSTINT 4 + 25 PUSHCONST3 + 26 PUSHCONST2 + 27 PUSHACC0 + 28 PUSHACC2 + 29 PUSHACC4 + 30 PUSHACC6 + 31 CLOSURE 4, 11 + 34 PUSHCONSTINT 14 + 36 PUSHCONST0 + 37 PUSHACC2 + 38 APPLY1 + 39 NEQ + 40 BRANCHIFNOT 47 + 42 GETGLOBAL Not_found + 44 MAKEBLOCK1 0 + 46 RAISE + 47 POP 5 + 49 ATOM0 + 50 SETGLOBAL T172-pushenvacc4 + 52 STOP +**) diff --git a/test/testinterp/t173-pushenvacc.ml b/test/testinterp/t173-pushenvacc.ml new file mode 100644 index 0000000..0d858b4 --- /dev/null +++ b/test/testinterp/t173-pushenvacc.ml @@ -0,0 +1,52 @@ +open Lib;; +let x = 5 in +let y = 4 in +let z = 3 in +let a = 2 in +let b = 1 in +let f _ = b + a + z + y + x in +if f 0 <> 15 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 24 + 11 ENVACC1 + 12 PUSHENVACC2 + 13 PUSHENVACC3 + 14 PUSHENVACC 4 + 16 PUSHENVACC 5 + 18 ADDINT + 19 ADDINT + 20 ADDINT + 21 ADDINT + 22 RETURN 1 + 24 CONSTINT 5 + 26 PUSHCONSTINT 4 + 28 PUSHCONST3 + 29 PUSHCONST2 + 30 PUSHCONST1 + 31 PUSHACC0 + 32 PUSHACC2 + 33 PUSHACC4 + 34 PUSHACC6 + 35 PUSHACC 8 + 37 CLOSURE 5, 11 + 40 PUSHCONSTINT 15 + 42 PUSHCONST0 + 43 PUSHACC2 + 44 APPLY1 + 45 NEQ + 46 BRANCHIFNOT 53 + 48 GETGLOBAL Not_found + 50 MAKEBLOCK1 0 + 52 RAISE + 53 POP 6 + 55 ATOM0 + 56 SETGLOBAL T173-pushenvacc + 58 STOP +**) diff --git a/test/testinterp/t180-appterm1.ml b/test/testinterp/t180-appterm1.ml new file mode 100644 index 0000000..6b82f51 --- /dev/null +++ b/test/testinterp/t180-appterm1.ml @@ -0,0 +1,35 @@ +open Lib;; +let f _ = 12 in +let g _ = f 0 in +if g 0 <> 12 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 19 + 11 CONST0 + 12 PUSHENVACC1 + 13 APPTERM1 2 + 15 CONSTINT 12 + 17 RETURN 1 + 19 CLOSURE 0, 15 + 22 PUSHACC0 + 23 CLOSURE 1, 11 + 26 PUSHCONSTINT 12 + 28 PUSHCONST0 + 29 PUSHACC2 + 30 APPLY1 + 31 NEQ + 32 BRANCHIFNOT 39 + 34 GETGLOBAL Not_found + 36 MAKEBLOCK1 0 + 38 RAISE + 39 POP 2 + 41 ATOM0 + 42 SETGLOBAL T180-appterm1 + 44 STOP +**) diff --git a/test/testinterp/t180-appterm2.ml b/test/testinterp/t180-appterm2.ml new file mode 100644 index 0000000..28f32a9 --- /dev/null +++ b/test/testinterp/t180-appterm2.ml @@ -0,0 +1,38 @@ +open Lib;; +let f _ _ = 12 in +let g _ = f 0 0 in +if g 0 <> 12 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 23 + 11 CONST0 + 12 PUSHCONST0 + 13 PUSHENVACC1 + 14 APPTERM2 3 + 16 RESTART + 17 GRAB 1 + 19 CONSTINT 12 + 21 RETURN 2 + 23 CLOSURE 0, 17 + 26 PUSHACC0 + 27 CLOSURE 1, 11 + 30 PUSHCONSTINT 12 + 32 PUSHCONST0 + 33 PUSHACC2 + 34 APPLY1 + 35 NEQ + 36 BRANCHIFNOT 43 + 38 GETGLOBAL Not_found + 40 MAKEBLOCK1 0 + 42 RAISE + 43 POP 2 + 45 ATOM0 + 46 SETGLOBAL T180-appterm2 + 48 STOP +**) diff --git a/test/testinterp/t180-appterm3.ml b/test/testinterp/t180-appterm3.ml new file mode 100644 index 0000000..fe8a0bd --- /dev/null +++ b/test/testinterp/t180-appterm3.ml @@ -0,0 +1,39 @@ +open Lib;; +let f _ _ _ = 13 in +let g _ = f 0 0 0 in +if g 0 <> 13 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 24 + 11 CONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHENVACC1 + 15 APPTERM3 4 + 17 RESTART + 18 GRAB 2 + 20 CONSTINT 13 + 22 RETURN 3 + 24 CLOSURE 0, 18 + 27 PUSHACC0 + 28 CLOSURE 1, 11 + 31 PUSHCONSTINT 13 + 33 PUSHCONST0 + 34 PUSHACC2 + 35 APPLY1 + 36 NEQ + 37 BRANCHIFNOT 44 + 39 GETGLOBAL Not_found + 41 MAKEBLOCK1 0 + 43 RAISE + 44 POP 2 + 46 ATOM0 + 47 SETGLOBAL T180-appterm3 + 49 STOP +**) diff --git a/test/testinterp/t181-appterm.ml b/test/testinterp/t181-appterm.ml new file mode 100644 index 0000000..03127bc --- /dev/null +++ b/test/testinterp/t181-appterm.ml @@ -0,0 +1,40 @@ +open Lib;; +let f _ _ _ _ = -10 in +let g _ = f 0 0 0 0 in +if g 0 <> -10 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 26 + 11 CONST0 + 12 PUSHCONST0 + 13 PUSHCONST0 + 14 PUSHCONST0 + 15 PUSHENVACC1 + 16 APPTERM 4, 5 + 19 RESTART + 20 GRAB 3 + 22 CONSTINT -10 + 24 RETURN 4 + 26 CLOSURE 0, 20 + 29 PUSHACC0 + 30 CLOSURE 1, 11 + 33 PUSHCONSTINT -10 + 35 PUSHCONST0 + 36 PUSHACC2 + 37 APPLY1 + 38 NEQ + 39 BRANCHIFNOT 46 + 41 GETGLOBAL Not_found + 43 MAKEBLOCK1 0 + 45 RAISE + 46 POP 2 + 48 ATOM0 + 49 SETGLOBAL T181-appterm + 51 STOP +**) diff --git a/test/testinterp/t190-makefloatblock-1.ml b/test/testinterp/t190-makefloatblock-1.ml new file mode 100644 index 0000000..f63c6cd --- /dev/null +++ b/test/testinterp/t190-makefloatblock-1.ml @@ -0,0 +1,17 @@ +open Lib;; +let x = 0.0 in [| x |];; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0 + 11 PUSHACC0 + 12 MAKEFLOATBLOCK 1 + 14 POP 1 + 16 ATOM0 + 17 SETGLOBAL T190-makefloatblock-1 + 19 STOP +**) diff --git a/test/testinterp/t190-makefloatblock-2.ml b/test/testinterp/t190-makefloatblock-2.ml new file mode 100644 index 0000000..53b97f5 --- /dev/null +++ b/test/testinterp/t190-makefloatblock-2.ml @@ -0,0 +1,18 @@ +open Lib;; +let x = 0.0 in [| x; x |];; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0 + 11 PUSHACC0 + 12 PUSHACC1 + 13 MAKEFLOATBLOCK 2 + 15 POP 1 + 17 ATOM0 + 18 SETGLOBAL T190-makefloatblock-2 + 20 STOP +**) diff --git a/test/testinterp/t190-makefloatblock-3.ml b/test/testinterp/t190-makefloatblock-3.ml new file mode 100644 index 0000000..cebccaa --- /dev/null +++ b/test/testinterp/t190-makefloatblock-3.ml @@ -0,0 +1,19 @@ +open Lib;; +let x = 0.0 in [| x; x; x |];; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0 + 11 PUSHACC0 + 12 PUSHACC1 + 13 PUSHACC2 + 14 MAKEFLOATBLOCK 3 + 16 POP 1 + 18 ATOM0 + 19 SETGLOBAL T190-makefloatblock-3 + 21 STOP +**) diff --git a/test/testinterp/t191-vectlength.ml b/test/testinterp/t191-vectlength.ml new file mode 100644 index 0000000..16f7d78 --- /dev/null +++ b/test/testinterp/t191-vectlength.ml @@ -0,0 +1,26 @@ +open Lib;; +let x = 0.0 in +if Array.length [| x |] <> 1 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0 + 11 PUSHCONST1 + 12 PUSHACC1 + 13 MAKEFLOATBLOCK 1 + 15 VECTLENGTH + 16 NEQ + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 POP 1 + 26 ATOM0 + 27 SETGLOBAL T191-vectlength + 29 STOP +**) diff --git a/test/testinterp/t192-getfloatfield-1.ml b/test/testinterp/t192-getfloatfield-1.ml new file mode 100644 index 0000000..ba002b2 --- /dev/null +++ b/test/testinterp/t192-getfloatfield-1.ml @@ -0,0 +1,23 @@ +open Lib;; +type t = { a : float; b : float };; + +if { a = 0.1; b = 0.2 }.a <> 0.1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0.1 + 11 PUSHGETGLOBAL [|0.1, 0.2|] + 13 GETFLOATFIELD 0 + 15 C_CALL2 neq_float + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 ATOM0 + 25 SETGLOBAL T192-getfloatfield-1 + 27 STOP +**) diff --git a/test/testinterp/t192-getfloatfield-2.ml b/test/testinterp/t192-getfloatfield-2.ml new file mode 100644 index 0000000..89230da --- /dev/null +++ b/test/testinterp/t192-getfloatfield-2.ml @@ -0,0 +1,23 @@ +open Lib;; +type t = { a : float; b : float };; + +if { a = 0.1; b = 0.2 }.b <> 0.2 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0.2 + 11 PUSHGETGLOBAL [|0.1, 0.2|] + 13 GETFLOATFIELD 1 + 15 C_CALL2 neq_float + 17 BRANCHIFNOT 24 + 19 GETGLOBAL Not_found + 21 MAKEBLOCK1 0 + 23 RAISE + 24 ATOM0 + 25 SETGLOBAL T192-getfloatfield-2 + 27 STOP +**) diff --git a/test/testinterp/t193-setfloatfield-1.ml b/test/testinterp/t193-setfloatfield-1.ml new file mode 100644 index 0000000..b488e7d --- /dev/null +++ b/test/testinterp/t193-setfloatfield-1.ml @@ -0,0 +1,36 @@ +open Lib;; +type t = { + mutable a : float; + mutable b : float; +};; + +let x = { a = 0.1; b = 0.2 } in +x.a <- 0.3; +if x.a <> 0.3 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0.2 + 11 PUSHGETGLOBAL 0.1 + 13 MAKEFLOATBLOCK 2 + 15 PUSHGETGLOBAL 0.3 + 17 PUSHACC1 + 18 SETFLOATFIELD 0 + 20 GETGLOBAL 0.3 + 22 PUSHACC1 + 23 GETFLOATFIELD 0 + 25 C_CALL2 neq_float + 27 BRANCHIFNOT 34 + 29 GETGLOBAL Not_found + 31 MAKEBLOCK1 0 + 33 RAISE + 34 POP 1 + 36 ATOM0 + 37 SETGLOBAL T193-setfloatfield-1 + 39 STOP +**) diff --git a/test/testinterp/t193-setfloatfield-2.ml b/test/testinterp/t193-setfloatfield-2.ml new file mode 100644 index 0000000..7dde0a2 --- /dev/null +++ b/test/testinterp/t193-setfloatfield-2.ml @@ -0,0 +1,36 @@ +open Lib;; +type t = { + mutable a : float; + mutable b : float; +};; + +let x = { a = 0.1; b = 0.2 } in +x.b <- 0.3; +if x.b <> 0.3 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL 0.2 + 11 PUSHGETGLOBAL 0.1 + 13 MAKEFLOATBLOCK 2 + 15 PUSHGETGLOBAL 0.3 + 17 PUSHACC1 + 18 SETFLOATFIELD 1 + 20 GETGLOBAL 0.3 + 22 PUSHACC1 + 23 GETFLOATFIELD 1 + 25 C_CALL2 neq_float + 27 BRANCHIFNOT 34 + 29 GETGLOBAL Not_found + 31 MAKEBLOCK1 0 + 33 RAISE + 34 POP 1 + 36 ATOM0 + 37 SETGLOBAL T193-setfloatfield-2 + 39 STOP +**) diff --git a/test/testinterp/t200-getfield0.ml b/test/testinterp/t200-getfield0.ml new file mode 100644 index 0000000..14ce1d5 --- /dev/null +++ b/test/testinterp/t200-getfield0.ml @@ -0,0 +1,25 @@ +open Lib;; +type t = { + a : int; +};; + +if { a = 7 }.a <> 7 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 7 + 11 PUSHGETGLOBAL <0>(7) + 13 GETFIELD0 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T200-getfield0 + 25 STOP +**) diff --git a/test/testinterp/t200-getfield1.ml b/test/testinterp/t200-getfield1.ml new file mode 100644 index 0000000..f4e2e01 --- /dev/null +++ b/test/testinterp/t200-getfield1.ml @@ -0,0 +1,26 @@ +open Lib;; +type t = { + a : int; + b : int; +};; + +if { a = 7; b = 6 }.b <> 6 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 6 + 11 PUSHGETGLOBAL <0>(7, 6) + 13 GETFIELD1 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T200-getfield1 + 25 STOP +**) diff --git a/test/testinterp/t200-getfield2.ml b/test/testinterp/t200-getfield2.ml new file mode 100644 index 0000000..df5c717 --- /dev/null +++ b/test/testinterp/t200-getfield2.ml @@ -0,0 +1,27 @@ +open Lib;; +type t = { + a : int; + b : int; + c : int; +};; + +if { a = 7; b = 6; c = 5 }.c <> 5 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 5 + 11 PUSHGETGLOBAL <0>(7, 6, 5) + 13 GETFIELD2 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T200-getfield2 + 25 STOP +**) diff --git a/test/testinterp/t200-getfield3.ml b/test/testinterp/t200-getfield3.ml new file mode 100644 index 0000000..a0376a1 --- /dev/null +++ b/test/testinterp/t200-getfield3.ml @@ -0,0 +1,28 @@ +open Lib;; +type t = { + a : int; + b : int; + c : int; + d : int; +};; + +if { a = 7; b = 6; c = 5; d = 4 }.d <> 4 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 4 + 11 PUSHGETGLOBAL <0>(7, 6, 5, 4) + 13 GETFIELD3 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T200-getfield3 + 25 STOP +**) diff --git a/test/testinterp/t201-getfield.ml b/test/testinterp/t201-getfield.ml new file mode 100644 index 0000000..0fbbc63 --- /dev/null +++ b/test/testinterp/t201-getfield.ml @@ -0,0 +1,29 @@ +open Lib;; +type t = { + a : int; + b : int; + c : int; + d : int; + e : int; +};; + +if { a = 7; b = 6; c = 5; d = 4; e = 3 }.e <> 3 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST3 + 10 PUSHGETGLOBAL <0>(7, 6, 5, 4, 3) + 12 GETFIELD 4 + 14 NEQ + 15 BRANCHIFNOT 22 + 17 GETGLOBAL Not_found + 19 MAKEBLOCK1 0 + 21 RAISE + 22 ATOM0 + 23 SETGLOBAL T201-getfield + 25 STOP +**) diff --git a/test/testinterp/t210-setfield0.ml b/test/testinterp/t210-setfield0.ml new file mode 100644 index 0000000..aa31d41 --- /dev/null +++ b/test/testinterp/t210-setfield0.ml @@ -0,0 +1,36 @@ +open Lib;; +type t = { + mutable a : int; +};; + +let x = {a = 7} in +x.a <- 11; +if x.a <> 11 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 7 + 11 MAKEBLOCK1 0 + 13 PUSHCONSTINT 11 + 15 PUSHACC1 + 16 SETFIELD0 + 17 CONSTINT 11 + 19 PUSHACC1 + 20 GETFIELD0 + 21 NEQ + 22 BRANCHIFNOT 29 + 24 GETGLOBAL Not_found + 26 MAKEBLOCK1 0 + 28 RAISE + 29 ACC0 + 30 POP 1 + 32 ATOM0 + 33 SETGLOBAL T210-setfield0 + 35 STOP +**) diff --git a/test/testinterp/t210-setfield1.ml b/test/testinterp/t210-setfield1.ml new file mode 100644 index 0000000..0d8e167 --- /dev/null +++ b/test/testinterp/t210-setfield1.ml @@ -0,0 +1,38 @@ +open Lib;; +type t = { + mutable a : int; + mutable b : int; +};; + +let x = {a = 7; b = 6} in +x.b <- 11; +if x.b <> 11 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 6 + 11 PUSHCONSTINT 7 + 13 MAKEBLOCK2 0 + 15 PUSHCONSTINT 11 + 17 PUSHACC1 + 18 SETFIELD1 + 19 CONSTINT 11 + 21 PUSHACC1 + 22 GETFIELD1 + 23 NEQ + 24 BRANCHIFNOT 31 + 26 GETGLOBAL Not_found + 28 MAKEBLOCK1 0 + 30 RAISE + 31 ACC0 + 32 POP 1 + 34 ATOM0 + 35 SETGLOBAL T210-setfield1 + 37 STOP +**) diff --git a/test/testinterp/t210-setfield2.ml b/test/testinterp/t210-setfield2.ml new file mode 100644 index 0000000..727691d --- /dev/null +++ b/test/testinterp/t210-setfield2.ml @@ -0,0 +1,40 @@ +open Lib;; +type t = { + mutable a : int; + mutable b : int; + mutable c : int; +};; + +let x = {a = 7; b = 6; c = 5} in +x.c <- 11; +if x.c <> 11 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 5 + 11 PUSHCONSTINT 6 + 13 PUSHCONSTINT 7 + 15 MAKEBLOCK3 0 + 17 PUSHCONSTINT 11 + 19 PUSHACC1 + 20 SETFIELD2 + 21 CONSTINT 11 + 23 PUSHACC1 + 24 GETFIELD2 + 25 NEQ + 26 BRANCHIFNOT 33 + 28 GETGLOBAL Not_found + 30 MAKEBLOCK1 0 + 32 RAISE + 33 ACC0 + 34 POP 1 + 36 ATOM0 + 37 SETGLOBAL T210-setfield2 + 39 STOP +**) diff --git a/test/testinterp/t210-setfield3.ml b/test/testinterp/t210-setfield3.ml new file mode 100644 index 0000000..d50d2c2 --- /dev/null +++ b/test/testinterp/t210-setfield3.ml @@ -0,0 +1,42 @@ +open Lib;; +type t = { + mutable a : int; + mutable b : int; + mutable c : int; + mutable d : int; +};; + +let x = {a = 7; b = 6; c = 5; d = 4} in +x.d <- 11; +if x.d <> 11 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 4 + 11 PUSHCONSTINT 5 + 13 PUSHCONSTINT 6 + 15 PUSHCONSTINT 7 + 17 MAKEBLOCK 4, 0 + 20 PUSHCONSTINT 11 + 22 PUSHACC1 + 23 SETFIELD3 + 24 CONSTINT 11 + 26 PUSHACC1 + 27 GETFIELD3 + 28 NEQ + 29 BRANCHIFNOT 36 + 31 GETGLOBAL Not_found + 33 MAKEBLOCK1 0 + 35 RAISE + 36 ACC0 + 37 POP 1 + 39 ATOM0 + 40 SETGLOBAL T210-setfield3 + 42 STOP +**) diff --git a/test/testinterp/t211-setfield.ml b/test/testinterp/t211-setfield.ml new file mode 100644 index 0000000..69c445e --- /dev/null +++ b/test/testinterp/t211-setfield.ml @@ -0,0 +1,44 @@ +open Lib;; +type t = { + mutable a : int; + mutable b : int; + mutable c : int; + mutable d : int; + mutable e : int; +};; + +let x = {a = 7; b = 6; c = 5; d = 4; e = 5} in +x.e <- 11; +if x.e <> 11 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 5 + 11 PUSHCONSTINT 4 + 13 PUSHCONSTINT 5 + 15 PUSHCONSTINT 6 + 17 PUSHCONSTINT 7 + 19 MAKEBLOCK 5, 0 + 22 PUSHCONSTINT 11 + 24 PUSHACC1 + 25 SETFIELD 4 + 27 CONSTINT 11 + 29 PUSHACC1 + 30 GETFIELD 4 + 32 NEQ + 33 BRANCHIFNOT 40 + 35 GETGLOBAL Not_found + 37 MAKEBLOCK1 0 + 39 RAISE + 40 ACC0 + 41 POP 1 + 43 ATOM0 + 44 SETGLOBAL T211-setfield + 46 STOP +**) diff --git a/test/testinterp/t220-assign.ml b/test/testinterp/t220-assign.ml new file mode 100644 index 0000000..769f8fb --- /dev/null +++ b/test/testinterp/t220-assign.ml @@ -0,0 +1,27 @@ +open Lib;; +let x = ref 1 in +x := 3; +if !x <> 3 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST1 + 10 PUSHCONST3 + 11 ASSIGN 0 + 13 CONST3 + 14 PUSHACC1 + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 POP 1 + 25 ATOM0 + 26 SETGLOBAL T220-assign + 28 STOP +**) diff --git a/test/testinterp/t230-check_signals.ml b/test/testinterp/t230-check_signals.ml new file mode 100644 index 0000000..2c2b5d7 --- /dev/null +++ b/test/testinterp/t230-check_signals.ml @@ -0,0 +1,28 @@ +open Lib;; +for i = 0 to 0 do () done;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 PUSHCONST0 + 11 PUSH + 12 BRANCH 21 + 14 CHECK_SIGNALS + 15 CONST0 + 16 ACC1 + 17 OFFSETINT 1 + 19 ASSIGN 1 + 21 ACC0 + 22 PUSHACC2 + 23 LEINT + 24 BRANCHIF 14 + 26 CONST0 + 27 POP 2 + 29 ATOM0 + 30 SETGLOBAL T230-check_signals + 32 STOP +**) diff --git a/test/testinterp/t240-c_call1.ml b/test/testinterp/t240-c_call1.ml new file mode 100644 index 0000000..3c7508c --- /dev/null +++ b/test/testinterp/t240-c_call1.ml @@ -0,0 +1,21 @@ +open Lib;; +if Pervasives.int_of_string "123" <> 123 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 123 + 11 PUSHGETGLOBAL "123" + 13 C_CALL1 int_of_string + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T240-c_call1 + 26 STOP +**) diff --git a/test/testinterp/t240-c_call2.ml b/test/testinterp/t240-c_call2.ml new file mode 100644 index 0000000..23c9843 --- /dev/null +++ b/test/testinterp/t240-c_call2.ml @@ -0,0 +1,22 @@ +open Lib;; +if Pervasives.compare 1 2 <> -1 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT -1 + 11 PUSHCONST2 + 12 PUSHCONST1 + 13 C_CALL2 compare + 15 NEQ + 16 BRANCHIFNOT 23 + 18 GETGLOBAL Not_found + 20 MAKEBLOCK1 0 + 22 RAISE + 23 ATOM0 + 24 SETGLOBAL T240-c_call2 + 26 STOP +**) diff --git a/test/testinterp/t240-c_call3.ml b/test/testinterp/t240-c_call3.ml new file mode 100644 index 0000000..707bc7e --- /dev/null +++ b/test/testinterp/t240-c_call3.ml @@ -0,0 +1,23 @@ +open Lib;; +if Hashtbl.hash_param 5 6 [1;2;3] <> 196799 then raise Not_found;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 196799 + 11 PUSHGETGLOBAL <0>(1, <0>(2, <0>(3, 0))) + 13 PUSHCONSTINT 6 + 15 PUSHCONSTINT 5 + 17 C_CALL3 hash_univ_param + 19 NEQ + 20 BRANCHIFNOT 27 + 22 GETGLOBAL Not_found + 24 MAKEBLOCK1 0 + 26 RAISE + 27 ATOM0 + 28 SETGLOBAL T240-c_call3 + 30 STOP +**) diff --git a/test/testinterp/t240-c_call4.ml b/test/testinterp/t240-c_call4.ml new file mode 100644 index 0000000..2ab62d8 --- /dev/null +++ b/test/testinterp/t240-c_call4.ml @@ -0,0 +1,32 @@ +open Lib;; +let s = "abcdefgh" in +String.unsafe_fill s 0 6 'x'; +if s.[5] <> 'x' then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL "abcdefgh" + 11 PUSHCONSTINT 120 + 13 PUSHCONSTINT 6 + 15 PUSHCONST0 + 16 PUSHACC3 + 17 C_CALL4 fill_string + 19 CONSTINT 120 + 21 PUSHCONSTINT 5 + 23 PUSHACC2 + 24 GETSTRINGCHAR + 25 NEQ + 26 BRANCHIFNOT 33 + 28 GETGLOBAL Not_found + 30 MAKEBLOCK1 0 + 32 RAISE + 33 POP 1 + 35 ATOM0 + 36 SETGLOBAL T240-c_call4 + 38 STOP +**) diff --git a/test/testinterp/t240-c_call5.ml b/test/testinterp/t240-c_call5.ml new file mode 100644 index 0000000..e817d55 --- /dev/null +++ b/test/testinterp/t240-c_call5.ml @@ -0,0 +1,33 @@ +open Lib;; +let s = "abcdefgh" in +String.unsafe_blit s 3 s 0 3; +if s.[0] <> 'd' then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 GETGLOBAL "abcdefgh" + 11 PUSHCONST3 + 12 PUSHCONST0 + 13 PUSHACC2 + 14 PUSHCONST3 + 15 PUSHACC4 + 16 C_CALL5 blit_string + 18 CONSTINT 100 + 20 PUSHCONST0 + 21 PUSHACC2 + 22 GETSTRINGCHAR + 23 NEQ + 24 BRANCHIFNOT 31 + 26 GETGLOBAL Not_found + 28 MAKEBLOCK1 0 + 30 RAISE + 31 POP 1 + 33 ATOM0 + 34 SETGLOBAL T240-c_call5 + 36 STOP +**) diff --git a/test/testinterp/t250-closurerec-1.ml b/test/testinterp/t250-closurerec-1.ml new file mode 100644 index 0000000..ded5036 --- /dev/null +++ b/test/testinterp/t250-closurerec-1.ml @@ -0,0 +1,19 @@ +open Lib;; +let rec f _ = 0;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 14 + 11 CONST0 + 12 RETURN 1 + 14 CLOSUREREC 0, 11 + 18 ACC0 + 19 MAKEBLOCK1 0 + 21 POP 1 + 23 SETGLOBAL T250-closurerec-1 + 25 STOP +**) diff --git a/test/testinterp/t250-closurerec-2.ml b/test/testinterp/t250-closurerec-2.ml new file mode 100644 index 0000000..97eac0c --- /dev/null +++ b/test/testinterp/t250-closurerec-2.ml @@ -0,0 +1,29 @@ +open Lib;; +let rec f _ = 23 in +if f 0 <> 23 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 15 + 11 CONSTINT 23 + 13 RETURN 1 + 15 CLOSUREREC 0, 11 + 19 CONSTINT 23 + 21 PUSHCONST0 + 22 PUSHACC2 + 23 APPLY1 + 24 NEQ + 25 BRANCHIFNOT 32 + 27 GETGLOBAL Not_found + 29 MAKEBLOCK1 0 + 31 RAISE + 32 POP 1 + 34 ATOM0 + 35 SETGLOBAL T250-closurerec-2 + 37 STOP +**) diff --git a/test/testinterp/t251-pushoffsetclosure0.ml b/test/testinterp/t251-pushoffsetclosure0.ml new file mode 100644 index 0000000..b1c2555 --- /dev/null +++ b/test/testinterp/t251-pushoffsetclosure0.ml @@ -0,0 +1,39 @@ +open Lib;; +let rec f = function + | 0 -> 13 + | n -> f 0 +in +if f 5 <> 13 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 24 + 11 CONST0 + 12 PUSHACC1 + 13 EQ + 14 BRANCHIFNOT 20 + 16 CONSTINT 13 + 18 RETURN 1 + 20 CONST0 + 21 PUSHOFFSETCLOSURE0 + 22 APPTERM1 2 + 24 CLOSUREREC 0, 11 + 28 CONSTINT 13 + 30 PUSHCONSTINT 5 + 32 PUSHACC2 + 33 APPLY1 + 34 NEQ + 35 BRANCHIFNOT 42 + 37 GETGLOBAL Not_found + 39 MAKEBLOCK1 0 + 41 RAISE + 42 POP 1 + 44 ATOM0 + 45 SETGLOBAL T251-pushoffsetclosure0 + 47 STOP +**) diff --git a/test/testinterp/t251-pushoffsetclosure2.ml b/test/testinterp/t251-pushoffsetclosure2.ml new file mode 100644 index 0000000..0fbdd6e --- /dev/null +++ b/test/testinterp/t251-pushoffsetclosure2.ml @@ -0,0 +1,34 @@ +open Lib;; +let rec f _ = g 0 + and g _ = 4 +in +if f 5 <> 4 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 19 + 11 CONST0 + 12 PUSHOFFSETCLOSURE2 + 13 APPTERM1 2 + 15 CONSTINT 4 + 17 RETURN 1 + 19 CLOSUREREC 0, 11, 15 + 24 CONSTINT 4 + 26 PUSHCONSTINT 5 + 28 PUSHACC3 + 29 APPLY1 + 30 NEQ + 31 BRANCHIFNOT 38 + 33 GETGLOBAL Not_found + 35 MAKEBLOCK1 0 + 37 RAISE + 38 POP 2 + 40 ATOM0 + 41 SETGLOBAL T251-pushoffsetclosure2 + 43 STOP +**) diff --git a/test/testinterp/t251-pushoffsetclosurem2.ml b/test/testinterp/t251-pushoffsetclosurem2.ml new file mode 100644 index 0000000..41ec196 --- /dev/null +++ b/test/testinterp/t251-pushoffsetclosurem2.ml @@ -0,0 +1,34 @@ +open Lib;; +let rec f _ = 4 + and g _ = f 2 +in +if g 5 <> 4 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 19 + 11 CONSTINT 4 + 13 RETURN 1 + 15 CONST2 + 16 PUSHOFFSETCLOSUREM2 + 17 APPTERM1 2 + 19 CLOSUREREC 0, 11, 15 + 24 CONSTINT 4 + 26 PUSHCONSTINT 5 + 28 PUSHACC2 + 29 APPLY1 + 30 NEQ + 31 BRANCHIFNOT 38 + 33 GETGLOBAL Not_found + 35 MAKEBLOCK1 0 + 37 RAISE + 38 POP 2 + 40 ATOM0 + 41 SETGLOBAL T251-pushoffsetclosurem2 + 43 STOP +**) diff --git a/test/testinterp/t252-pushoffsetclosure.ml b/test/testinterp/t252-pushoffsetclosure.ml new file mode 100644 index 0000000..1887133 --- /dev/null +++ b/test/testinterp/t252-pushoffsetclosure.ml @@ -0,0 +1,38 @@ +open Lib;; +let rec f x = x + and g _ = f 4 + and h _ = f 6 +in +if h 1 <> 6 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 25 + 11 ACC0 + 12 RETURN 1 + 14 CONSTINT 4 + 16 PUSHOFFSETCLOSUREM2 + 17 APPTERM1 2 + 19 CONSTINT 6 + 21 PUSHOFFSETCLOSURE -4 + 23 APPTERM1 2 + 25 CLOSUREREC 0, 11, 14, 19 + 31 CONSTINT 6 + 33 PUSHCONST1 + 34 PUSHACC2 + 35 APPLY1 + 36 NEQ + 37 BRANCHIFNOT 44 + 39 GETGLOBAL Not_found + 41 MAKEBLOCK1 0 + 43 RAISE + 44 POP 3 + 46 ATOM0 + 47 SETGLOBAL T252-pushoffsetclosure + 49 STOP +**) diff --git a/test/testinterp/t253-offsetclosure0.ml b/test/testinterp/t253-offsetclosure0.ml new file mode 100644 index 0000000..f6d12c6 --- /dev/null +++ b/test/testinterp/t253-offsetclosure0.ml @@ -0,0 +1,34 @@ +open Lib;; +let rec f _ = g f + and g _ = 10 +in +if f 3 <> 10 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 19 + 11 OFFSETCLOSURE0 + 12 PUSHOFFSETCLOSURE2 + 13 APPTERM1 2 + 15 CONSTINT 10 + 17 RETURN 1 + 19 CLOSUREREC 0, 11, 15 + 24 CONSTINT 10 + 26 PUSHCONST3 + 27 PUSHACC3 + 28 APPLY1 + 29 NEQ + 30 BRANCHIFNOT 37 + 32 GETGLOBAL Not_found + 34 MAKEBLOCK1 0 + 36 RAISE + 37 POP 2 + 39 ATOM0 + 40 SETGLOBAL T253-offsetclosure0 + 42 STOP +**) diff --git a/test/testinterp/t253-offsetclosure2.ml b/test/testinterp/t253-offsetclosure2.ml new file mode 100644 index 0000000..be94061 --- /dev/null +++ b/test/testinterp/t253-offsetclosure2.ml @@ -0,0 +1,34 @@ +open Lib;; +let rec f _ = g + and g _ = 10 +in +if f 3 4 <> 10 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 18 + 11 OFFSETCLOSURE2 + 12 RETURN 1 + 14 CONSTINT 10 + 16 RETURN 1 + 18 CLOSUREREC 0, 11, 14 + 23 CONSTINT 10 + 25 PUSHCONSTINT 4 + 27 PUSHCONST3 + 28 PUSHACC4 + 29 APPLY2 + 30 NEQ + 31 BRANCHIFNOT 38 + 33 GETGLOBAL Not_found + 35 MAKEBLOCK1 0 + 37 RAISE + 38 POP 2 + 40 ATOM0 + 41 SETGLOBAL T253-offsetclosure2 + 43 STOP +**) diff --git a/test/testinterp/t253-offsetclosurem2.ml b/test/testinterp/t253-offsetclosurem2.ml new file mode 100644 index 0000000..cec3793 --- /dev/null +++ b/test/testinterp/t253-offsetclosurem2.ml @@ -0,0 +1,34 @@ +open Lib;; +let rec f _ = 11 + and g _ = f +in +if g 3 4 <> 11 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 18 + 11 CONSTINT 11 + 13 RETURN 1 + 15 OFFSETCLOSUREM2 + 16 RETURN 1 + 18 CLOSUREREC 0, 11, 15 + 23 CONSTINT 11 + 25 PUSHCONSTINT 4 + 27 PUSHCONST3 + 28 PUSHACC3 + 29 APPLY2 + 30 NEQ + 31 BRANCHIFNOT 38 + 33 GETGLOBAL Not_found + 35 MAKEBLOCK1 0 + 37 RAISE + 38 POP 2 + 40 ATOM0 + 41 SETGLOBAL T253-offsetclosurem2 + 43 STOP +**) diff --git a/test/testinterp/t254-offsetclosure.ml b/test/testinterp/t254-offsetclosure.ml new file mode 100644 index 0000000..6da8c28 --- /dev/null +++ b/test/testinterp/t254-offsetclosure.ml @@ -0,0 +1,37 @@ +open Lib;; +let rec f _ = 11 + and g _ = 0 + and h _ = f +in +if h 3 4 <> 11 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 22 + 11 CONSTINT 11 + 13 RETURN 1 + 15 CONST0 + 16 RETURN 1 + 18 OFFSETCLOSURE -4 + 20 RETURN 1 + 22 CLOSUREREC 0, 11, 15, 18 + 28 CONSTINT 11 + 30 PUSHCONSTINT 4 + 32 PUSHCONST3 + 33 PUSHACC3 + 34 APPLY2 + 35 NEQ + 36 BRANCHIFNOT 43 + 38 GETGLOBAL Not_found + 40 MAKEBLOCK1 0 + 42 RAISE + 43 POP 3 + 45 ATOM0 + 46 SETGLOBAL T254-offsetclosure + 48 STOP +**) diff --git a/test/testinterp/t260-offsetref.ml b/test/testinterp/t260-offsetref.ml new file mode 100644 index 0000000..968892e --- /dev/null +++ b/test/testinterp/t260-offsetref.ml @@ -0,0 +1,31 @@ +open Lib;; +let x = ref 32 in +incr x; +if !x <> 33 then raise Not_found; +x +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONSTINT 32 + 11 MAKEBLOCK1 0 + 13 PUSHACC0 + 14 OFFSETREF 1 + 16 CONSTINT 33 + 18 PUSHACC1 + 19 GETFIELD0 + 20 NEQ + 21 BRANCHIFNOT 28 + 23 GETGLOBAL Not_found + 25 MAKEBLOCK1 0 + 27 RAISE + 28 ACC0 + 29 POP 1 + 31 ATOM0 + 32 SETGLOBAL T260-offsetref + 34 STOP +**) diff --git a/test/testinterp/t270-push_retaddr.ml b/test/testinterp/t270-push_retaddr.ml new file mode 100644 index 0000000..0c7fb36 --- /dev/null +++ b/test/testinterp/t270-push_retaddr.ml @@ -0,0 +1,36 @@ +open Lib;; +let f a b c d = 123 in +if f 0 1 2 3 <> 123 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 18 + 11 RESTART + 12 GRAB 3 + 14 CONSTINT 123 + 16 RETURN 4 + 18 CLOSURE 0, 12 + 21 PUSHCONSTINT 123 + 23 PUSH + 24 PUSH_RETADDR 34 + 26 CONST3 + 27 PUSHCONST2 + 28 PUSHCONST1 + 29 PUSHCONST0 + 30 PUSHACC 8 + 32 APPLY 4 + 34 NEQ + 35 BRANCHIFNOT 42 + 37 GETGLOBAL Not_found + 39 MAKEBLOCK1 0 + 41 RAISE + 42 POP 1 + 44 ATOM0 + 45 SETGLOBAL T270-push_retaddr + 47 STOP +**) diff --git a/test/testinterp/t300-getmethod.ml b/test/testinterp/t300-getmethod.ml new file mode 100644 index 0000000..e789473 --- /dev/null +++ b/test/testinterp/t300-getmethod.ml @@ -0,0 +1,5885 @@ +open Lib;; + +class c = object + method m = 23 +end;; + +let o = new c in +if o#m <> 23 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 3341 + 2406 RESTART + 2407 GRAB 2 + 2409 ACC2 + 2410 PUSHACC2 + 2411 VECTLENGTH + 2412 OFFSETINT -1 + 2414 PUSHCONST0 + 2415 PUSH + 2416 BRANCH 2433 + 2418 CHECK_SIGNALS + 2419 ACC2 + 2420 PUSHACC2 + 2421 PUSHACC6 + 2422 C_CALL2 array_unsafe_get + 2424 PUSHACC5 + 2425 APPLY2 + 2426 ASSIGN 2 + 2428 ACC1 + 2429 OFFSETINT -1 + 2431 ASSIGN 1 + 2433 ACC0 + 2434 PUSHACC2 + 2435 GEINT + 2436 BRANCHIF 2418 + 2438 CONST0 + 2439 POP 2 + 2441 ACC0 + 2442 RETURN 4 + 2444 RESTART + 2445 GRAB 2 + 2447 ACC1 + 2448 PUSHCONST0 + 2449 PUSHACC4 + 2450 VECTLENGTH + 2451 OFFSETINT -1 + 2453 PUSH + 2454 BRANCH 2471 + 2456 CHECK_SIGNALS + 2457 ACC1 + 2458 PUSHACC6 + 2459 C_CALL2 array_unsafe_get + 2461 PUSHACC3 + 2462 PUSHACC5 + 2463 APPLY2 + 2464 ASSIGN 2 + 2466 ACC1 + 2467 OFFSETINT 1 + 2469 ASSIGN 1 + 2471 ACC0 + 2472 PUSHACC2 + 2473 LEINT + 2474 BRANCHIF 2456 + 2476 CONST0 + 2477 POP 2 + 2479 ACC0 + 2480 RETURN 4 + 2482 RESTART + 2483 GRAB 1 + 2485 ACC1 + 2486 BRANCHIFNOT 2502 + 2488 ACC1 + 2489 GETFIELD0 + 2490 PUSHACC1 + 2491 PUSHENVACC1 + 2492 C_CALL3 array_unsafe_set + 2494 ACC1 + 2495 GETFIELD1 + 2496 PUSHACC1 + 2497 OFFSETINT 1 + 2499 PUSHOFFSETCLOSURE0 + 2500 APPTERM2 4 + 2502 ENVACC1 + 2503 RETURN 2 + 2505 ACC0 + 2506 BRANCHIFNOT 2531 + 2508 ACC0 + 2509 GETFIELD1 + 2510 PUSHACC1 + 2511 GETFIELD0 + 2512 PUSHACC1 + 2513 PUSHGETGLOBALFIELD List, 0 + 2516 APPLY1 + 2517 OFFSETINT 1 + 2519 C_CALL2 make_vect + 2521 PUSHACC0 + 2522 CLOSUREREC 1, 2483 + 2526 ACC2 + 2527 PUSHCONST1 + 2528 PUSHACC2 + 2529 APPTERM2 6 + 2531 ATOM0 + 2532 RETURN 1 + 2534 RESTART + 2535 GRAB 1 + 2537 CONST0 + 2538 PUSHACC1 + 2539 LTINT + 2540 BRANCHIFNOT 2545 + 2542 ACC1 + 2543 RETURN 2 + 2545 ACC1 + 2546 PUSHACC1 + 2547 PUSHENVACC1 + 2548 C_CALL2 array_unsafe_get + 2550 MAKEBLOCK2 0 + 2552 PUSHACC1 + 2553 OFFSETINT -1 + 2555 PUSHOFFSETCLOSURE0 + 2556 APPTERM2 4 + 2558 ACC0 + 2559 CLOSUREREC 1, 2535 + 2563 CONST0 + 2564 PUSHACC2 + 2565 VECTLENGTH + 2566 OFFSETINT -1 + 2568 PUSHACC2 + 2569 APPTERM2 4 + 2571 RESTART + 2572 GRAB 1 + 2574 ACC1 + 2575 VECTLENGTH + 2576 PUSHCONST0 + 2577 PUSHACC1 + 2578 EQ + 2579 BRANCHIFNOT 2584 + 2581 ATOM0 + 2582 RETURN 3 + 2584 CONST0 + 2585 PUSHACC3 + 2586 C_CALL2 array_unsafe_get + 2588 PUSHCONST0 + 2589 PUSHACC3 + 2590 APPLY2 + 2591 PUSHACC1 + 2592 C_CALL2 make_vect + 2594 PUSHCONST1 + 2595 PUSHACC2 + 2596 OFFSETINT -1 + 2598 PUSH + 2599 BRANCH 2618 + 2601 CHECK_SIGNALS + 2602 ACC1 + 2603 PUSHACC6 + 2604 C_CALL2 array_unsafe_get + 2606 PUSHACC2 + 2607 PUSHACC6 + 2608 APPLY2 + 2609 PUSHACC2 + 2610 PUSHACC4 + 2611 C_CALL3 array_unsafe_set + 2613 ACC1 + 2614 OFFSETINT 1 + 2616 ASSIGN 1 + 2618 ACC0 + 2619 PUSHACC2 + 2620 LEINT + 2621 BRANCHIF 2601 + 2623 CONST0 + 2624 POP 2 + 2626 ACC0 + 2627 RETURN 4 + 2629 RESTART + 2630 GRAB 1 + 2632 CONST0 + 2633 PUSHACC2 + 2634 VECTLENGTH + 2635 OFFSETINT -1 + 2637 PUSH + 2638 BRANCH 2653 + 2640 CHECK_SIGNALS + 2641 ACC1 + 2642 PUSHACC4 + 2643 C_CALL2 array_unsafe_get + 2645 PUSHACC2 + 2646 PUSHACC4 + 2647 APPLY2 + 2648 ACC1 + 2649 OFFSETINT 1 + 2651 ASSIGN 1 + 2653 ACC0 + 2654 PUSHACC2 + 2655 LEINT + 2656 BRANCHIF 2640 + 2658 CONST0 + 2659 RETURN 4 + 2661 RESTART + 2662 GRAB 1 + 2664 ACC1 + 2665 VECTLENGTH + 2666 PUSHCONST0 + 2667 PUSHACC1 + 2668 EQ + 2669 BRANCHIFNOT 2674 + 2671 ATOM0 + 2672 RETURN 3 + 2674 CONST0 + 2675 PUSHACC3 + 2676 C_CALL2 array_unsafe_get + 2678 PUSHACC2 + 2679 APPLY1 + 2680 PUSHACC1 + 2681 C_CALL2 make_vect + 2683 PUSHCONST1 + 2684 PUSHACC2 + 2685 OFFSETINT -1 + 2687 PUSH + 2688 BRANCH 2706 + 2690 CHECK_SIGNALS + 2691 ACC1 + 2692 PUSHACC6 + 2693 C_CALL2 array_unsafe_get + 2695 PUSHACC5 + 2696 APPLY1 + 2697 PUSHACC2 + 2698 PUSHACC4 + 2699 C_CALL3 array_unsafe_set + 2701 ACC1 + 2702 OFFSETINT 1 + 2704 ASSIGN 1 + 2706 ACC0 + 2707 PUSHACC2 + 2708 LEINT + 2709 BRANCHIF 2690 + 2711 CONST0 + 2712 POP 2 + 2714 ACC0 + 2715 RETURN 4 + 2717 RESTART + 2718 GRAB 1 + 2720 CONST0 + 2721 PUSHACC2 + 2722 VECTLENGTH + 2723 OFFSETINT -1 + 2725 PUSH + 2726 BRANCH 2740 + 2728 CHECK_SIGNALS + 2729 ACC1 + 2730 PUSHACC4 + 2731 C_CALL2 array_unsafe_get + 2733 PUSHACC3 + 2734 APPLY1 + 2735 ACC1 + 2736 OFFSETINT 1 + 2738 ASSIGN 1 + 2740 ACC0 + 2741 PUSHACC2 + 2742 LEINT + 2743 BRANCHIF 2728 + 2745 CONST0 + 2746 RETURN 4 + 2748 RESTART + 2749 GRAB 4 + 2751 CONST0 + 2752 PUSHACC5 + 2753 LTINT + 2754 BRANCHIF 2782 + 2756 CONST0 + 2757 PUSHACC2 + 2758 LTINT + 2759 BRANCHIF 2782 + 2761 ACC0 + 2762 VECTLENGTH + 2763 PUSHACC5 + 2764 PUSHACC3 + 2765 ADDINT + 2766 GTINT + 2767 BRANCHIF 2782 + 2769 CONST0 + 2770 PUSHACC4 + 2771 LTINT + 2772 BRANCHIF 2782 + 2774 ACC2 + 2775 VECTLENGTH + 2776 PUSHACC5 + 2777 PUSHACC5 + 2778 ADDINT + 2779 GTINT + 2780 BRANCHIFNOT 2789 + 2782 GETGLOBAL "Array.blit" + 2784 PUSHGETGLOBALFIELD Pervasives, 2 + 2787 APPTERM1 6 + 2789 ACC3 + 2790 PUSHACC2 + 2791 LTINT + 2792 BRANCHIFNOT 2827 + 2794 ACC4 + 2795 OFFSETINT -1 + 2797 PUSHCONST0 + 2798 PUSH + 2799 BRANCH 2819 + 2801 CHECK_SIGNALS + 2802 ACC1 + 2803 PUSHACC4 + 2804 ADDINT + 2805 PUSHACC3 + 2806 C_CALL2 array_unsafe_get + 2808 PUSHACC2 + 2809 PUSHACC7 + 2810 ADDINT + 2811 PUSHACC6 + 2812 C_CALL3 array_unsafe_set + 2814 ACC1 + 2815 OFFSETINT -1 + 2817 ASSIGN 1 + 2819 ACC0 + 2820 PUSHACC2 + 2821 GEINT + 2822 BRANCHIF 2801 + 2824 CONST0 + 2825 RETURN 7 + 2827 CONST0 + 2828 PUSHACC5 + 2829 OFFSETINT -1 + 2831 PUSH + 2832 BRANCH 2852 + 2834 CHECK_SIGNALS + 2835 ACC1 + 2836 PUSHACC4 + 2837 ADDINT + 2838 PUSHACC3 + 2839 C_CALL2 array_unsafe_get + 2841 PUSHACC2 + 2842 PUSHACC7 + 2843 ADDINT + 2844 PUSHACC6 + 2845 C_CALL3 array_unsafe_set + 2847 ACC1 + 2848 OFFSETINT 1 + 2850 ASSIGN 1 + 2852 ACC0 + 2853 PUSHACC2 + 2854 LEINT + 2855 BRANCHIF 2834 + 2857 CONST0 + 2858 RETURN 7 + 2860 RESTART + 2861 GRAB 3 + 2863 CONST0 + 2864 PUSHACC2 + 2865 LTINT + 2866 BRANCHIF 2881 + 2868 CONST0 + 2869 PUSHACC3 + 2870 LTINT + 2871 BRANCHIF 2881 + 2873 ACC0 + 2874 VECTLENGTH + 2875 PUSHACC3 + 2876 PUSHACC3 + 2877 ADDINT + 2878 GTINT + 2879 BRANCHIFNOT 2888 + 2881 GETGLOBAL "Array.fill" + 2883 PUSHGETGLOBALFIELD Pervasives, 2 + 2886 APPTERM1 5 + 2888 ACC1 + 2889 PUSHACC3 + 2890 PUSHACC3 + 2891 ADDINT + 2892 OFFSETINT -1 + 2894 PUSH + 2895 BRANCH 2908 + 2897 CHECK_SIGNALS + 2898 ACC5 + 2899 PUSHACC2 + 2900 PUSHACC4 + 2901 C_CALL3 array_unsafe_set + 2903 ACC1 + 2904 OFFSETINT 1 + 2906 ASSIGN 1 + 2908 ACC0 + 2909 PUSHACC2 + 2910 LEINT + 2911 BRANCHIF 2897 + 2913 CONST0 + 2914 RETURN 6 + 2916 RESTART + 2917 GRAB 2 + 2919 CONST0 + 2920 PUSHACC2 + 2921 LTINT + 2922 BRANCHIF 2937 + 2924 CONST0 + 2925 PUSHACC3 + 2926 LTINT + 2927 BRANCHIF 2937 + 2929 ACC0 + 2930 VECTLENGTH + 2931 PUSHACC3 + 2932 PUSHACC3 + 2933 ADDINT + 2934 GTINT + 2935 BRANCHIFNOT 2944 + 2937 GETGLOBAL "Array.sub" + 2939 PUSHGETGLOBALFIELD Pervasives, 2 + 2942 APPTERM1 4 + 2944 CONST0 + 2945 PUSHACC3 + 2946 EQ + 2947 BRANCHIFNOT 2952 + 2949 ATOM0 + 2950 RETURN 3 + 2952 ACC1 + 2953 PUSHACC1 + 2954 C_CALL2 array_unsafe_get + 2956 PUSHACC3 + 2957 C_CALL2 make_vect + 2959 PUSHCONST1 + 2960 PUSHACC4 + 2961 OFFSETINT -1 + 2963 PUSH + 2964 BRANCH 2982 + 2966 CHECK_SIGNALS + 2967 ACC1 + 2968 PUSHACC5 + 2969 ADDINT + 2970 PUSHACC4 + 2971 C_CALL2 array_unsafe_get + 2973 PUSHACC2 + 2974 PUSHACC4 + 2975 C_CALL3 array_unsafe_set + 2977 ACC1 + 2978 OFFSETINT 1 + 2980 ASSIGN 1 + 2982 ACC0 + 2983 PUSHACC2 + 2984 LEINT + 2985 BRANCHIF 2966 + 2987 CONST0 + 2988 POP 2 + 2990 ACC0 + 2991 RETURN 4 + 2993 ACC0 + 2994 BRANCHIFNOT 3017 + 2996 ACC0 + 2997 GETFIELD0 + 2998 PUSHCONST0 + 2999 PUSHACC1 + 3000 VECTLENGTH + 3001 GTINT + 3002 BRANCHIFNOT 3012 + 3004 ENVACC2 + 3005 PUSHCONST0 + 3006 PUSHACC2 + 3007 C_CALL2 array_unsafe_get + 3009 PUSHENVACC1 + 3010 APPTERM2 4 + 3012 ACC1 + 3013 GETFIELD1 + 3014 PUSHOFFSETCLOSURE0 + 3015 APPTERM1 3 + 3017 ATOM0 + 3018 RETURN 1 + 3020 ACC0 + 3021 PUSHENVACC1 + 3022 CLOSUREREC 2, 2993 + 3026 ACC1 + 3027 PUSHACC1 + 3028 APPTERM1 3 + 3030 CONST0 + 3031 PUSHACC1 + 3032 VECTLENGTH + 3033 OFFSETINT -1 + 3035 PUSH + 3036 BRANCH 3056 + 3038 CHECK_SIGNALS + 3039 ACC1 + 3040 PUSHACC3 + 3041 C_CALL2 array_unsafe_get + 3043 PUSHENVACC2 + 3044 GETFIELD0 + 3045 PUSHENVACC1 + 3046 C_CALL3 array_unsafe_set + 3048 ENVACC2 + 3049 OFFSETREF 1 + 3051 ACC1 + 3052 OFFSETINT 1 + 3054 ASSIGN 1 + 3056 ACC0 + 3057 PUSHACC2 + 3058 LEINT + 3059 BRANCHIF 3038 + 3061 CONST0 + 3062 RETURN 3 + 3064 RESTART + 3065 GRAB 1 + 3067 ACC1 + 3068 VECTLENGTH + 3069 PUSHACC1 + 3070 ADDINT + 3071 RETURN 2 + 3073 RESTART + 3074 GRAB 1 + 3076 ACC1 + 3077 PUSHCONST0 + 3078 PUSH + 3079 CLOSURE 0, 3065 + 3082 PUSHGETGLOBALFIELD List, 12 + 3085 APPLY3 + 3086 PUSHACC1 + 3087 PUSHACC1 + 3088 C_CALL2 make_vect + 3090 PUSHCONST0 + 3091 MAKEBLOCK1 0 + 3093 PUSHACC4 + 3094 PUSHACC1 + 3095 PUSHACC3 + 3096 CLOSURE 2, 3030 + 3099 PUSHGETGLOBALFIELD List, 9 + 3102 APPLY2 + 3103 ACC1 + 3104 RETURN 5 + 3106 RESTART + 3107 GRAB 1 + 3109 ACC0 + 3110 VECTLENGTH + 3111 PUSHACC2 + 3112 VECTLENGTH + 3113 PUSHCONST0 + 3114 PUSHACC2 + 3115 EQ + 3116 BRANCHIFNOT 3126 + 3118 CONST0 + 3119 PUSHACC1 + 3120 EQ + 3121 BRANCHIFNOT 3126 + 3123 ATOM0 + 3124 RETURN 4 + 3126 CONST0 + 3127 PUSHCONST0 + 3128 PUSHACC3 + 3129 GTINT + 3130 BRANCHIFNOT 3135 + 3132 ACC3 + 3133 BRANCH 3136 + 3135 ACC4 + 3136 C_CALL2 array_unsafe_get + 3138 PUSHACC1 + 3139 PUSHACC3 + 3140 ADDINT + 3141 C_CALL2 make_vect + 3143 PUSHCONST0 + 3144 PUSHACC3 + 3145 OFFSETINT -1 + 3147 PUSH + 3148 BRANCH 3164 + 3150 CHECK_SIGNALS + 3151 ACC1 + 3152 PUSHACC6 + 3153 C_CALL2 array_unsafe_get + 3155 PUSHACC2 + 3156 PUSHACC4 + 3157 C_CALL3 array_unsafe_set + 3159 ACC1 + 3160 OFFSETINT 1 + 3162 ASSIGN 1 + 3164 ACC0 + 3165 PUSHACC2 + 3166 LEINT + 3167 BRANCHIF 3150 + 3169 CONST0 + 3170 POP 2 + 3172 CONST0 + 3173 PUSHACC2 + 3174 OFFSETINT -1 + 3176 PUSH + 3177 BRANCH 3195 + 3179 CHECK_SIGNALS + 3180 ACC1 + 3181 PUSHACC7 + 3182 C_CALL2 array_unsafe_get + 3184 PUSHACC5 + 3185 PUSHACC3 + 3186 ADDINT + 3187 PUSHACC4 + 3188 C_CALL3 array_unsafe_set + 3190 ACC1 + 3191 OFFSETINT 1 + 3193 ASSIGN 1 + 3195 ACC0 + 3196 PUSHACC2 + 3197 LEINT + 3198 BRANCHIF 3179 + 3200 CONST0 + 3201 POP 2 + 3203 ACC0 + 3204 RETURN 5 + 3206 ACC0 + 3207 VECTLENGTH + 3208 PUSHCONST0 + 3209 PUSHACC1 + 3210 EQ + 3211 BRANCHIFNOT 3216 + 3213 ATOM0 + 3214 RETURN 2 + 3216 CONST0 + 3217 PUSHACC2 + 3218 C_CALL2 array_unsafe_get + 3220 PUSHACC1 + 3221 C_CALL2 make_vect + 3223 PUSHCONST1 + 3224 PUSHACC2 + 3225 OFFSETINT -1 + 3227 PUSH + 3228 BRANCH 3244 + 3230 CHECK_SIGNALS + 3231 ACC1 + 3232 PUSHACC5 + 3233 C_CALL2 array_unsafe_get + 3235 PUSHACC2 + 3236 PUSHACC4 + 3237 C_CALL3 array_unsafe_set + 3239 ACC1 + 3240 OFFSETINT 1 + 3242 ASSIGN 1 + 3244 ACC0 + 3245 PUSHACC2 + 3246 LEINT + 3247 BRANCHIF 3230 + 3249 CONST0 + 3250 POP 2 + 3252 ACC0 + 3253 RETURN 3 + 3255 RESTART + 3256 GRAB 2 + 3258 ATOM0 + 3259 PUSHACC1 + 3260 C_CALL2 make_vect + 3262 PUSHCONST0 + 3263 PUSHACC2 + 3264 OFFSETINT -1 + 3266 PUSH + 3267 BRANCH 3282 + 3269 CHECK_SIGNALS + 3270 ACC5 + 3271 PUSHACC5 + 3272 C_CALL2 make_vect + 3274 PUSHACC2 + 3275 PUSHACC4 + 3276 SETVECTITEM + 3277 ACC1 + 3278 OFFSETINT 1 + 3280 ASSIGN 1 + 3282 ACC0 + 3283 PUSHACC2 + 3284 LEINT + 3285 BRANCHIF 3269 + 3287 CONST0 + 3288 POP 2 + 3290 ACC0 + 3291 RETURN 4 + 3293 RESTART + 3294 GRAB 1 + 3296 CONST0 + 3297 PUSHACC1 + 3298 EQ + 3299 BRANCHIFNOT 3304 + 3301 ATOM0 + 3302 RETURN 2 + 3304 CONST0 + 3305 PUSHACC2 + 3306 APPLY1 + 3307 PUSHACC1 + 3308 C_CALL2 make_vect + 3310 PUSHCONST1 + 3311 PUSHACC2 + 3312 OFFSETINT -1 + 3314 PUSH + 3315 BRANCH 3330 + 3317 CHECK_SIGNALS + 3318 ACC1 + 3319 PUSHACC5 + 3320 APPLY1 + 3321 PUSHACC2 + 3322 PUSHACC4 + 3323 C_CALL3 array_unsafe_set + 3325 ACC1 + 3326 OFFSETINT 1 + 3328 ASSIGN 1 + 3330 ACC0 + 3331 PUSHACC2 + 3332 LEINT + 3333 BRANCHIF 3317 + 3335 CONST0 + 3336 POP 2 + 3338 ACC0 + 3339 RETURN 3 + 3341 CLOSURE 0, 3294 + 3344 PUSH + 3345 CLOSURE 0, 3256 + 3348 PUSH + 3349 CLOSURE 0, 3206 + 3352 PUSH + 3353 CLOSURE 0, 3107 + 3356 PUSH + 3357 CLOSURE 0, 3074 + 3360 PUSHACC0 + 3361 CLOSURE 1, 3020 + 3364 PUSH + 3365 CLOSURE 0, 2917 + 3368 PUSH + 3369 CLOSURE 0, 2861 + 3372 PUSH + 3373 CLOSURE 0, 2749 + 3376 PUSH + 3377 CLOSURE 0, 2718 + 3380 PUSH + 3381 CLOSURE 0, 2662 + 3384 PUSH + 3385 CLOSURE 0, 2630 + 3388 PUSH + 3389 CLOSURE 0, 2572 + 3392 PUSH + 3393 CLOSURE 0, 2558 + 3396 PUSH + 3397 CLOSURE 0, 2505 + 3400 PUSH + 3401 CLOSURE 0, 2445 + 3404 PUSH + 3405 CLOSURE 0, 2407 + 3408 PUSHACC0 + 3409 PUSHACC2 + 3410 PUSHACC6 + 3411 PUSHACC 8 + 3413 PUSHACC 10 + 3415 PUSHACC 12 + 3417 PUSHACC 8 + 3419 PUSHACC 10 + 3421 PUSHACC 16 + 3423 PUSHACC 18 + 3425 PUSHACC 24 + 3427 PUSHACC 21 + 3429 PUSHACC 23 + 3431 PUSHACC 26 + 3433 PUSHACC 29 + 3435 PUSHACC 30 + 3437 PUSHACC 32 + 3439 MAKEBLOCK 17, 0 + 3442 POP 17 + 3444 SETGLOBAL Array + 3446 BRANCH 3480 + 3448 ENVACC1 + 3449 MAKEBLOCK1 0 + 3451 RAISE + 3452 ACC0 + 3453 BRANCHIFNOT 3465 + 3455 ENVACC3 + 3456 CLOSURE 1, 3448 + 3459 MAKEBLOCK1 0 + 3461 PUSHENVACC2 + 3462 PUSHENVACC1 + 3463 APPTERM2 3 + 3465 CONST0 + 3466 PUSHENVACC2 + 3467 PUSHENVACC1 + 3468 APPTERM2 3 + 3470 RESTART + 3471 GRAB 1 + 3473 ACC1 + 3474 PUSHACC1 + 3475 C_CALL2 install_signal_handler + 3477 CONST0 + 3478 RETURN 2 + 3480 CONST0 + 3481 C_CALL1 sys_get_argv + 3483 PUSHCONST0 + 3484 C_CALL1 sys_get_config + 3486 PUSHACC0 + 3487 GETFIELD1 + 3488 PUSHACC0 + 3489 OFFSETINT -10 + 3491 PUSHCONST1 + 3492 LSLINT + 3493 OFFSETINT -1 + 3495 PUSHACC0 + 3496 PUSHCONSTINT 8 + 3498 PUSHACC3 + 3499 DIVINT + 3500 MULINT + 3501 OFFSETINT -1 + 3503 PUSHCONST0 + 3504 MAKEBLOCK1 0 + 3506 PUSH + 3507 CLOSURE 0, 3471 + 3510 PUSHCONSTINT -1 + 3512 PUSHCONSTINT -2 + 3514 PUSHCONSTINT -3 + 3516 PUSHCONSTINT -4 + 3518 PUSHCONSTINT -5 + 3520 PUSHCONSTINT -6 + 3522 PUSHCONSTINT -7 + 3524 PUSHCONSTINT -8 + 3526 PUSHCONSTINT -9 + 3528 PUSHCONSTINT -10 + 3530 PUSHCONSTINT -11 + 3532 PUSHCONSTINT -12 + 3534 PUSHCONSTINT -13 + 3536 PUSHCONSTINT -14 + 3538 PUSHCONSTINT -15 + 3540 PUSHCONSTINT -16 + 3542 PUSHCONSTINT -17 + 3544 PUSHCONSTINT -18 + 3546 PUSHCONSTINT -19 + 3548 PUSHCONSTINT -20 + 3550 PUSHCONSTINT -21 + 3552 PUSHGETGLOBAL "Sys.Break" + 3554 MAKEBLOCK1 0 + 3556 PUSHACC0 + 3557 PUSHACC 17 + 3559 PUSHACC 24 + 3561 CLOSURE 3, 3452 + 3564 PUSHACC0 + 3565 PUSHACC2 + 3566 PUSHACC4 + 3567 PUSHACC6 + 3568 PUSHACC 8 + 3570 PUSHACC 10 + 3572 PUSHACC 12 + 3574 PUSHACC 14 + 3576 PUSHACC 16 + 3578 PUSHACC 18 + 3580 PUSHACC 20 + 3582 PUSHACC 22 + 3584 PUSHACC 24 + 3586 PUSHACC 26 + 3588 PUSHACC 28 + 3590 PUSHACC 30 + 3592 PUSHACC 32 + 3594 PUSHACC 34 + 3596 PUSHACC 36 + 3598 PUSHACC 38 + 3600 PUSHACC 40 + 3602 PUSHACC 42 + 3604 PUSHACC 44 + 3606 PUSHACC 46 + 3608 PUSHACC 50 + 3610 PUSHACC 50 + 3612 PUSHACC 53 + 3614 PUSHACC 55 + 3616 GETFIELD0 + 3617 PUSHACC 52 + 3619 PUSHACC 58 + 3621 MAKEBLOCK 30, 0 + 3624 POP 30 + 3626 SETGLOBAL Sys + 3628 BRANCH 4510 + 3630 RESTART + 3631 GRAB 1 + 3633 CONST0 + 3634 PUSHACC1 + 3635 LTINT + 3636 BRANCHIFNOT 3641 + 3638 CONST1 + 3639 RETURN 2 + 3641 ACC1 + 3642 BRANCHIFNOT 3652 + 3644 ACC1 + 3645 GETFIELD2 + 3646 PUSHACC1 + 3647 OFFSETINT -1 + 3649 PUSHOFFSETCLOSURE0 + 3650 APPTERM2 4 + 3652 RETURN 2 + 3654 ACC0 + 3655 BRANCHIFNOT 3670 + 3657 ENVACC2 + 3658 PUSHACC1 + 3659 GETFIELD0 + 3660 PUSHENVACC1 + 3661 GETFIELD0 + 3662 APPLY2 + 3663 BRANCHIF 3670 + 3665 ACC0 + 3666 GETFIELD2 + 3667 PUSHOFFSETCLOSURE0 + 3668 APPTERM1 2 + 3670 RETURN 1 + 3672 RESTART + 3673 GRAB 1 + 3675 ACC1 + 3676 PUSHENVACC1 + 3677 CLOSUREREC 2, 3654 + 3681 ACC1 + 3682 GETFIELD1 + 3683 VECTLENGTH + 3684 PUSHACC3 + 3685 PUSHENVACC1 + 3686 GETFIELD1 + 3687 APPLY1 + 3688 MODINT + 3689 PUSHACC2 + 3690 GETFIELD1 + 3691 C_CALL2 array_get_addr + 3693 PUSHACC1 + 3694 APPTERM1 4 + 3696 ACC0 + 3697 BRANCHIFNOT 3722 + 3699 ACC0 + 3700 GETFIELD2 + 3701 PUSHENVACC2 + 3702 PUSHACC2 + 3703 GETFIELD0 + 3704 PUSHENVACC1 + 3705 GETFIELD0 + 3706 APPLY2 + 3707 BRANCHIFNOT 3718 + 3709 ACC0 + 3710 PUSHOFFSETCLOSURE0 + 3711 APPLY1 + 3712 PUSHACC2 + 3713 GETFIELD1 + 3714 MAKEBLOCK2 0 + 3716 RETURN 2 + 3718 ACC0 + 3719 PUSHOFFSETCLOSURE0 + 3720 APPTERM1 3 + 3722 RETURN 1 + 3724 RESTART + 3725 GRAB 1 + 3727 ACC1 + 3728 PUSHENVACC1 + 3729 CLOSUREREC 2, 3696 + 3733 ACC1 + 3734 GETFIELD1 + 3735 VECTLENGTH + 3736 PUSHACC3 + 3737 PUSHENVACC1 + 3738 GETFIELD1 + 3739 APPLY1 + 3740 MODINT + 3741 PUSHACC2 + 3742 GETFIELD1 + 3743 C_CALL2 array_get_addr + 3745 PUSHACC1 + 3746 APPTERM1 4 + 3748 ACC0 + 3749 BRANCHIFNOT 3768 + 3751 ACC0 + 3752 GETFIELD0 + 3753 PUSHENVACC2 + 3754 PUSHENVACC1 + 3755 GETFIELD0 + 3756 APPLY2 + 3757 BRANCHIFNOT 3763 + 3759 ACC0 + 3760 GETFIELD1 + 3761 RETURN 1 + 3763 ACC0 + 3764 GETFIELD2 + 3765 PUSHOFFSETCLOSURE0 + 3766 APPTERM1 2 + 3768 GETGLOBAL Not_found + 3770 MAKEBLOCK1 0 + 3772 RAISE + 3773 RESTART + 3774 GRAB 1 + 3776 ACC0 + 3777 GETFIELD1 + 3778 VECTLENGTH + 3779 PUSHACC2 + 3780 PUSHENVACC1 + 3781 GETFIELD1 + 3782 APPLY1 + 3783 MODINT + 3784 PUSHACC1 + 3785 GETFIELD1 + 3786 C_CALL2 array_get_addr + 3788 PUSHACC0 + 3789 BRANCHIFNOT 3858 + 3791 ACC0 + 3792 GETFIELD2 + 3793 PUSHACC1 + 3794 GETFIELD0 + 3795 PUSHACC4 + 3796 PUSHENVACC1 + 3797 GETFIELD0 + 3798 APPLY2 + 3799 BRANCHIFNOT 3805 + 3801 ACC1 + 3802 GETFIELD1 + 3803 RETURN 4 + 3805 ACC0 + 3806 BRANCHIFNOT 3853 + 3808 ACC0 + 3809 GETFIELD2 + 3810 PUSHACC1 + 3811 GETFIELD0 + 3812 PUSHACC5 + 3813 PUSHENVACC1 + 3814 GETFIELD0 + 3815 APPLY2 + 3816 BRANCHIFNOT 3822 + 3818 ACC1 + 3819 GETFIELD1 + 3820 RETURN 5 + 3822 ACC0 + 3823 BRANCHIFNOT 3848 + 3825 ACC0 + 3826 GETFIELD0 + 3827 PUSHACC5 + 3828 PUSHENVACC1 + 3829 GETFIELD0 + 3830 APPLY2 + 3831 BRANCHIFNOT 3837 + 3833 ACC0 + 3834 GETFIELD1 + 3835 RETURN 5 + 3837 ACC4 + 3838 PUSHENVACC1 + 3839 CLOSUREREC 2, 3748 + 3843 ACC1 + 3844 GETFIELD2 + 3845 PUSHACC1 + 3846 APPTERM1 7 + 3848 GETGLOBAL Not_found + 3850 MAKEBLOCK1 0 + 3852 RAISE + 3853 GETGLOBAL Not_found + 3855 MAKEBLOCK1 0 + 3857 RAISE + 3858 GETGLOBAL Not_found + 3860 MAKEBLOCK1 0 + 3862 RAISE + 3863 ACC0 + 3864 BRANCHIFNOT 3890 + 3866 ACC0 + 3867 GETFIELD0 + 3868 PUSHACC1 + 3869 GETFIELD2 + 3870 PUSHENVACC2 + 3871 PUSHACC2 + 3872 PUSHENVACC1 + 3873 GETFIELD0 + 3874 APPLY2 + 3875 BRANCHIFNOT 3880 + 3877 ACC0 + 3878 RETURN 3 + 3880 ACC0 + 3881 PUSHOFFSETCLOSURE0 + 3882 APPLY1 + 3883 PUSHACC3 + 3884 GETFIELD1 + 3885 PUSHACC3 + 3886 MAKEBLOCK3 0 + 3888 POP 2 + 3890 RETURN 1 + 3892 RESTART + 3893 GRAB 1 + 3895 ACC1 + 3896 PUSHENVACC1 + 3897 CLOSUREREC 2, 3863 + 3901 ACC1 + 3902 GETFIELD1 + 3903 VECTLENGTH + 3904 PUSHACC3 + 3905 PUSHENVACC1 + 3906 GETFIELD1 + 3907 APPLY1 + 3908 MODINT + 3909 PUSHACC0 + 3910 PUSHACC3 + 3911 GETFIELD1 + 3912 C_CALL2 array_get_addr + 3914 PUSHACC2 + 3915 APPLY1 + 3916 PUSHACC1 + 3917 PUSHACC4 + 3918 GETFIELD1 + 3919 C_CALL3 array_set_addr + 3921 RETURN 4 + 3923 RESTART + 3924 GRAB 2 + 3926 ACC0 + 3927 GETFIELD1 + 3928 VECTLENGTH + 3929 PUSHACC2 + 3930 PUSHENVACC3 + 3931 GETFIELD1 + 3932 APPLY1 + 3933 MODINT + 3934 PUSHACC0 + 3935 PUSHACC2 + 3936 GETFIELD1 + 3937 C_CALL2 array_get_addr + 3939 PUSHACC4 + 3940 PUSHACC4 + 3941 MAKEBLOCK3 0 + 3943 PUSHACC0 + 3944 PUSHACC2 + 3945 PUSHACC4 + 3946 GETFIELD1 + 3947 C_CALL3 array_set_addr + 3949 ACC0 + 3950 PUSHACC3 + 3951 GETFIELD0 + 3952 PUSHENVACC2 + 3953 APPLY2 + 3954 BRANCHIFNOT 3962 + 3956 ACC2 + 3957 PUSHENVACC3 + 3958 GETFIELD1 + 3959 PUSHENVACC1 + 3960 APPTERM2 7 + 3962 RETURN 5 + 3964 ACC0 + 3965 PUSHENVACC 4 + 3967 PUSHENVACC3 + 3968 CLOSURE 3, 3924 + 3971 PUSHACC1 + 3972 CLOSURE 1, 3893 + 3975 PUSHACC2 + 3976 CLOSURE 1, 3774 + 3979 PUSHACC3 + 3980 CLOSURE 1, 3725 + 3983 PUSHACC4 + 3984 CLOSURE 1, 3673 + 3987 PUSHENVACC 5 + 3989 PUSHACC1 + 3990 PUSHACC3 + 3991 PUSHACC5 + 3992 PUSHACC7 + 3993 PUSHACC 9 + 3995 PUSHENVACC2 + 3996 PUSHENVACC1 + 3997 MAKEBLOCK 8, 0 + 4000 RETURN 6 + 4002 ACC0 + 4003 BRANCHIFNOT 4016 + 4005 ACC0 + 4006 GETFIELD1 + 4007 PUSHACC1 + 4008 GETFIELD0 + 4009 PUSHENVACC1 + 4010 APPLY2 + 4011 ACC0 + 4012 GETFIELD2 + 4013 PUSHOFFSETCLOSURE0 + 4014 APPTERM1 2 + 4016 RETURN 1 + 4018 RESTART + 4019 GRAB 1 + 4021 ACC0 + 4022 CLOSUREREC 1, 4002 + 4026 ACC2 + 4027 GETFIELD1 + 4028 PUSHCONST0 + 4029 PUSHACC1 + 4030 VECTLENGTH + 4031 OFFSETINT -1 + 4033 PUSH + 4034 BRANCH 4048 + 4036 CHECK_SIGNALS + 4037 ACC1 + 4038 PUSHACC3 + 4039 C_CALL2 array_get_addr + 4041 PUSHACC4 + 4042 APPLY1 + 4043 ACC1 + 4044 OFFSETINT 1 + 4046 ASSIGN 1 + 4048 ACC0 + 4049 PUSHACC2 + 4050 LEINT + 4051 BRANCHIF 4036 + 4053 CONST0 + 4054 RETURN 6 + 4056 ACC0 + 4057 BRANCHIFNOT 4071 + 4059 ENVACC1 + 4060 PUSHACC1 + 4061 GETFIELD0 + 4062 C_CALL2 equal + 4064 BRANCHIF 4071 + 4066 ACC0 + 4067 GETFIELD2 + 4068 PUSHOFFSETCLOSURE0 + 4069 APPTERM1 2 + 4071 RETURN 1 + 4073 RESTART + 4074 GRAB 1 + 4076 ACC1 + 4077 CLOSUREREC 1, 4056 + 4081 ACC1 + 4082 GETFIELD1 + 4083 VECTLENGTH + 4084 PUSHACC3 + 4085 PUSHENVACC1 + 4086 APPLY1 + 4087 MODINT + 4088 PUSHACC2 + 4089 GETFIELD1 + 4090 C_CALL2 array_get_addr + 4092 PUSHACC1 + 4093 APPTERM1 4 + 4095 ACC0 + 4096 BRANCHIFNOT 4120 + 4098 ACC0 + 4099 GETFIELD2 + 4100 PUSHENVACC1 + 4101 PUSHACC2 + 4102 GETFIELD0 + 4103 C_CALL2 equal + 4105 BRANCHIFNOT 4116 + 4107 ACC0 + 4108 PUSHOFFSETCLOSURE0 + 4109 APPLY1 + 4110 PUSHACC2 + 4111 GETFIELD1 + 4112 MAKEBLOCK2 0 + 4114 RETURN 2 + 4116 ACC0 + 4117 PUSHOFFSETCLOSURE0 + 4118 APPTERM1 3 + 4120 RETURN 1 + 4122 RESTART + 4123 GRAB 1 + 4125 ACC1 + 4126 CLOSUREREC 1, 4095 + 4130 ACC1 + 4131 GETFIELD1 + 4132 VECTLENGTH + 4133 PUSHACC3 + 4134 PUSHENVACC1 + 4135 APPLY1 + 4136 MODINT + 4137 PUSHACC2 + 4138 GETFIELD1 + 4139 C_CALL2 array_get_addr + 4141 PUSHACC1 + 4142 APPTERM1 4 + 4144 ACC0 + 4145 BRANCHIFNOT 4163 + 4147 ACC0 + 4148 GETFIELD0 + 4149 PUSHENVACC1 + 4150 C_CALL2 equal + 4152 BRANCHIFNOT 4158 + 4154 ACC0 + 4155 GETFIELD1 + 4156 RETURN 1 + 4158 ACC0 + 4159 GETFIELD2 + 4160 PUSHOFFSETCLOSURE0 + 4161 APPTERM1 2 + 4163 GETGLOBAL Not_found + 4165 MAKEBLOCK1 0 + 4167 RAISE + 4168 RESTART + 4169 GRAB 1 + 4171 ACC0 + 4172 GETFIELD1 + 4173 VECTLENGTH + 4174 PUSHACC2 + 4175 PUSHENVACC1 + 4176 APPLY1 + 4177 MODINT + 4178 PUSHACC1 + 4179 GETFIELD1 + 4180 C_CALL2 array_get_addr + 4182 PUSHACC0 + 4183 BRANCHIFNOT 4248 + 4185 ACC0 + 4186 GETFIELD2 + 4187 PUSHACC1 + 4188 GETFIELD0 + 4189 PUSHACC4 + 4190 C_CALL2 equal + 4192 BRANCHIFNOT 4198 + 4194 ACC1 + 4195 GETFIELD1 + 4196 RETURN 4 + 4198 ACC0 + 4199 BRANCHIFNOT 4243 + 4201 ACC0 + 4202 GETFIELD2 + 4203 PUSHACC1 + 4204 GETFIELD0 + 4205 PUSHACC5 + 4206 C_CALL2 equal + 4208 BRANCHIFNOT 4214 + 4210 ACC1 + 4211 GETFIELD1 + 4212 RETURN 5 + 4214 ACC0 + 4215 BRANCHIFNOT 4238 + 4217 ACC0 + 4218 GETFIELD0 + 4219 PUSHACC5 + 4220 C_CALL2 equal + 4222 BRANCHIFNOT 4228 + 4224 ACC0 + 4225 GETFIELD1 + 4226 RETURN 5 + 4228 ACC4 + 4229 CLOSUREREC 1, 4144 + 4233 ACC1 + 4234 GETFIELD2 + 4235 PUSHACC1 + 4236 APPTERM1 7 + 4238 GETGLOBAL Not_found + 4240 MAKEBLOCK1 0 + 4242 RAISE + 4243 GETGLOBAL Not_found + 4245 MAKEBLOCK1 0 + 4247 RAISE + 4248 GETGLOBAL Not_found + 4250 MAKEBLOCK1 0 + 4252 RAISE + 4253 ACC0 + 4254 BRANCHIFNOT 4279 + 4256 ACC0 + 4257 GETFIELD0 + 4258 PUSHACC1 + 4259 GETFIELD2 + 4260 PUSHENVACC1 + 4261 PUSHACC2 + 4262 C_CALL2 equal + 4264 BRANCHIFNOT 4269 + 4266 ACC0 + 4267 RETURN 3 + 4269 ACC0 + 4270 PUSHOFFSETCLOSURE0 + 4271 APPLY1 + 4272 PUSHACC3 + 4273 GETFIELD1 + 4274 PUSHACC3 + 4275 MAKEBLOCK3 0 + 4277 POP 2 + 4279 RETURN 1 + 4281 RESTART + 4282 GRAB 1 + 4284 ACC1 + 4285 CLOSUREREC 1, 4253 + 4289 ACC1 + 4290 GETFIELD1 + 4291 VECTLENGTH + 4292 PUSHACC3 + 4293 PUSHENVACC1 + 4294 APPLY1 + 4295 MODINT + 4296 PUSHACC0 + 4297 PUSHACC3 + 4298 GETFIELD1 + 4299 C_CALL2 array_get_addr + 4301 PUSHACC2 + 4302 APPLY1 + 4303 PUSHACC1 + 4304 PUSHACC4 + 4305 GETFIELD1 + 4306 C_CALL3 array_set_addr + 4308 RETURN 4 + 4310 RESTART + 4311 GRAB 2 + 4313 ACC0 + 4314 GETFIELD1 + 4315 VECTLENGTH + 4316 PUSHACC2 + 4317 PUSHENVACC1 + 4318 APPLY1 + 4319 MODINT + 4320 PUSHACC0 + 4321 PUSHACC2 + 4322 GETFIELD1 + 4323 C_CALL2 array_get_addr + 4325 PUSHACC4 + 4326 PUSHACC4 + 4327 MAKEBLOCK3 0 + 4329 PUSHACC0 + 4330 PUSHACC2 + 4331 PUSHACC4 + 4332 GETFIELD1 + 4333 C_CALL3 array_set_addr + 4335 ACC0 + 4336 PUSHACC3 + 4337 GETFIELD0 + 4338 PUSHENVACC3 + 4339 APPLY2 + 4340 BRANCHIFNOT 4347 + 4342 ACC2 + 4343 PUSHENVACC1 + 4344 PUSHENVACC2 + 4345 APPTERM2 7 + 4347 RETURN 5 + 4349 ACC0 + 4350 BRANCHIFNOT 4378 + 4352 ACC0 + 4353 GETFIELD0 + 4354 PUSHACC1 + 4355 GETFIELD2 + 4356 PUSHOFFSETCLOSURE0 + 4357 APPLY1 + 4358 ENVACC2 + 4359 PUSHACC1 + 4360 PUSHENVACC1 + 4361 APPLY1 + 4362 MODINT + 4363 PUSHACC0 + 4364 PUSHENVACC3 + 4365 C_CALL2 array_get_addr + 4367 PUSHACC3 + 4368 GETFIELD1 + 4369 PUSHACC3 + 4370 MAKEBLOCK3 0 + 4372 PUSHACC1 + 4373 PUSHENVACC3 + 4374 C_CALL3 array_set_addr + 4376 POP 2 + 4378 RETURN 1 + 4380 RESTART + 4381 GRAB 1 + 4383 ACC1 + 4384 GETFIELD1 + 4385 PUSHACC0 + 4386 VECTLENGTH + 4387 PUSHACC0 + 4388 PUSHCONST2 + 4389 MULINT + 4390 OFFSETINT 1 + 4392 PUSHCONST0 + 4393 PUSHACC1 + 4394 C_CALL2 make_vect + 4396 PUSHACC0 + 4397 PUSHACC2 + 4398 PUSHACC6 + 4399 CLOSUREREC 3, 4349 + 4403 CONST0 + 4404 PUSHACC4 + 4405 OFFSETINT -1 + 4407 PUSH + 4408 BRANCH 4422 + 4410 CHECK_SIGNALS + 4411 ACC1 + 4412 PUSHACC7 + 4413 C_CALL2 array_get_addr + 4415 PUSHACC3 + 4416 APPLY1 + 4417 ACC1 + 4418 OFFSETINT 1 + 4420 ASSIGN 1 + 4422 ACC0 + 4423 PUSHACC2 + 4424 LEINT + 4425 BRANCHIF 4410 + 4427 CONST0 + 4428 POP 2 + 4430 ACC1 + 4431 PUSHACC7 + 4432 SETFIELD1 + 4433 ACC6 + 4434 GETFIELD0 + 4435 PUSHCONST2 + 4436 MULINT + 4437 PUSHACC7 + 4438 SETFIELD0 + 4439 RETURN 7 + 4441 CONST0 + 4442 PUSHACC1 + 4443 GETFIELD1 + 4444 VECTLENGTH + 4445 OFFSETINT -1 + 4447 PUSH + 4448 BRANCH 4462 + 4450 CHECK_SIGNALS + 4451 CONST0 + 4452 PUSHACC2 + 4453 PUSHACC4 + 4454 GETFIELD1 + 4455 C_CALL3 array_set_addr + 4457 ACC1 + 4458 OFFSETINT 1 + 4460 ASSIGN 1 + 4462 ACC0 + 4463 PUSHACC2 + 4464 LEINT + 4465 BRANCHIF 4450 + 4467 CONST0 + 4468 RETURN 3 + 4470 CONST1 + 4471 PUSHACC1 + 4472 LTINT + 4473 BRANCHIFNOT 4478 + 4475 CONST1 + 4476 BRANCH 4479 + 4478 ACC0 + 4479 PUSHGETGLOBALFIELD Sys, 5 + 4482 PUSHACC1 + 4483 GTINT + 4484 BRANCHIFNOT 4491 + 4486 GETGLOBALFIELD Sys, 5 + 4489 BRANCH 4492 + 4491 ACC0 + 4492 PUSHCONST0 + 4493 PUSHACC1 + 4494 C_CALL2 make_vect + 4496 PUSHCONST3 + 4497 MAKEBLOCK2 0 + 4499 RETURN 3 + 4501 ACC0 + 4502 PUSHCONSTINT 100 + 4504 PUSHCONSTINT 10 + 4506 C_CALL3 hash_univ_param + 4508 RETURN 1 + 4510 CLOSURE 0, 4501 + 4513 PUSH + 4514 CLOSURE 0, 4470 + 4517 PUSH + 4518 CLOSURE 0, 4441 + 4521 PUSH + 4522 CLOSURE 0, 4381 + 4525 PUSH + 4526 CLOSUREREC 0, 3631 + 4530 ACC0 + 4531 PUSHACC2 + 4532 PUSHACC6 + 4533 CLOSURE 3, 4311 + 4536 PUSHACC5 + 4537 CLOSURE 1, 4282 + 4540 PUSHACC6 + 4541 CLOSURE 1, 4169 + 4544 PUSHACC7 + 4545 CLOSURE 1, 4123 + 4548 PUSHACC 8 + 4550 CLOSURE 1, 4074 + 4553 PUSH + 4554 CLOSURE 0, 4019 + 4557 PUSHACC0 + 4558 PUSHACC7 + 4559 PUSHACC 9 + 4561 PUSHACC 11 + 4563 PUSHACC 13 + 4565 CLOSURE 5, 3964 + 4568 PUSHACC 11 + 4570 PUSHACC1 + 4571 PUSHACC3 + 4572 PUSHACC 8 + 4574 PUSHACC6 + 4575 PUSHACC 8 + 4577 PUSHACC 10 + 4579 PUSHACC 13 + 4581 PUSHACC 17 + 4583 PUSHACC 19 + 4585 MAKEBLOCK 10, 0 + 4588 POP 12 + 4590 SETGLOBAL Hashtbl + 4592 BRANCH 5073 + 4594 RESTART + 4595 GRAB 2 + 4597 ACC1 + 4598 BRANCHIFNOT 4638 + 4600 ACC1 + 4601 GETFIELD0 + 4602 PUSHACC3 + 4603 BRANCHIFNOT 4635 + 4605 ACC3 + 4606 GETFIELD0 + 4607 PUSHACC0 + 4608 PUSHACC2 + 4609 PUSHACC4 + 4610 APPLY2 + 4611 BRANCHIFNOT 4624 + 4613 ACC4 + 4614 PUSHACC4 + 4615 GETFIELD1 + 4616 PUSHACC4 + 4617 PUSHOFFSETCLOSURE0 + 4618 APPLY3 + 4619 PUSHACC2 + 4620 MAKEBLOCK2 0 + 4622 RETURN 5 + 4624 ACC4 + 4625 GETFIELD1 + 4626 PUSHACC4 + 4627 PUSHACC4 + 4628 PUSHOFFSETCLOSURE0 + 4629 APPLY3 + 4630 PUSHACC1 + 4631 MAKEBLOCK2 0 + 4633 RETURN 5 + 4635 ACC2 + 4636 RETURN 4 + 4638 ACC2 + 4639 RETURN 3 + 4641 RESTART + 4642 GRAB 1 + 4644 CONSTINT 6 + 4646 PUSHACC1 + 4647 PUSHACC3 + 4648 SUBINT + 4649 GEINT + 4650 BRANCHIFNOT 4809 + 4652 CONST1 + 4653 PUSHACC2 + 4654 PUSHACC2 + 4655 ADDINT + 4656 LSRINT + 4657 PUSHACC1 + 4658 PUSHENVACC3 + 4659 C_CALL2 array_unsafe_get + 4661 PUSHACC1 + 4662 PUSHENVACC3 + 4663 C_CALL2 array_unsafe_get + 4665 PUSHENVACC2 + 4666 APPLY2 + 4667 BRANCHIFNOT 4674 + 4669 ACC1 + 4670 PUSHACC1 + 4671 PUSHENVACC3 + 4672 PUSHENVACC1 + 4673 APPLY3 + 4674 ACC0 + 4675 PUSHENVACC3 + 4676 C_CALL2 array_unsafe_get + 4678 PUSHACC3 + 4679 PUSHENVACC3 + 4680 C_CALL2 array_unsafe_get + 4682 PUSHENVACC2 + 4683 APPLY2 + 4684 BRANCHIFNOT 4708 + 4686 ACC2 + 4687 PUSHACC1 + 4688 PUSHENVACC3 + 4689 PUSHENVACC1 + 4690 APPLY3 + 4691 ACC1 + 4692 PUSHENVACC3 + 4693 C_CALL2 array_unsafe_get + 4695 PUSHACC1 + 4696 PUSHENVACC3 + 4697 C_CALL2 array_unsafe_get + 4699 PUSHENVACC2 + 4700 APPLY2 + 4701 BRANCHIFNOT 4708 + 4703 ACC1 + 4704 PUSHACC1 + 4705 PUSHENVACC3 + 4706 PUSHENVACC1 + 4707 APPLY3 + 4708 ACC0 + 4709 PUSHENVACC3 + 4710 C_CALL2 array_unsafe_get + 4712 PUSHACC2 + 4713 OFFSETINT 1 + 4715 PUSHACC4 + 4716 OFFSETINT -1 + 4718 PUSH + 4719 BRANCH 4777 + 4721 CHECK_SIGNALS + 4722 BRANCH 4730 + 4724 CHECK_SIGNALS + 4725 ACC1 + 4726 OFFSETINT 1 + 4728 ASSIGN 1 + 4730 ACC1 + 4731 PUSHENVACC3 + 4732 C_CALL2 array_unsafe_get + 4734 PUSHACC3 + 4735 PUSHENVACC2 + 4736 APPLY2 + 4737 BRANCHIFNOT 4724 + 4739 CONST0 + 4740 BRANCH 4748 + 4742 CHECK_SIGNALS + 4743 ACC0 + 4744 OFFSETINT -1 + 4746 ASSIGN 0 + 4748 ACC2 + 4749 PUSHACC1 + 4750 PUSHENVACC3 + 4751 C_CALL2 array_unsafe_get + 4753 PUSHENVACC2 + 4754 APPLY2 + 4755 BRANCHIFNOT 4742 + 4757 ACC0 + 4758 PUSHACC2 + 4759 LTINT + 4760 BRANCHIFNOT 4767 + 4762 ACC0 + 4763 PUSHACC2 + 4764 PUSHENVACC3 + 4765 PUSHENVACC1 + 4766 APPLY3 + 4767 ACC1 + 4768 OFFSETINT 1 + 4770 ASSIGN 1 + 4772 ACC0 + 4773 OFFSETINT -1 + 4775 ASSIGN 0 + 4777 ACC0 + 4778 PUSHACC2 + 4779 LTINT + 4780 BRANCHIF 4721 + 4782 ACC1 + 4783 PUSHACC6 + 4784 SUBINT + 4785 PUSHACC5 + 4786 PUSHACC2 + 4787 SUBINT + 4788 LEINT + 4789 BRANCHIFNOT 4800 + 4791 ACC0 + 4792 PUSHACC5 + 4793 PUSHOFFSETCLOSURE0 + 4794 APPLY2 + 4795 ACC5 + 4796 PUSHACC2 + 4797 PUSHOFFSETCLOSURE0 + 4798 APPTERM2 8 + 4800 ACC5 + 4801 PUSHACC2 + 4802 PUSHOFFSETCLOSURE0 + 4803 APPLY2 + 4804 ACC0 + 4805 PUSHACC5 + 4806 PUSHOFFSETCLOSURE0 + 4807 APPTERM2 8 + 4809 RETURN 2 + 4811 RESTART + 4812 GRAB 1 + 4814 ACC1 + 4815 PUSHACC1 + 4816 PUSHENVACC1 + 4817 CLOSUREREC 3, 4642 + 4821 ACC2 + 4822 VECTLENGTH + 4823 OFFSETINT -1 + 4825 PUSHCONST0 + 4826 PUSHACC2 + 4827 APPLY2 + 4828 CONST1 + 4829 PUSHACC3 + 4830 VECTLENGTH + 4831 OFFSETINT -1 + 4833 PUSH + 4834 BRANCH 4918 + 4836 CHECK_SIGNALS + 4837 ACC1 + 4838 PUSHACC5 + 4839 C_CALL2 array_unsafe_get + 4841 PUSHACC0 + 4842 PUSHACC3 + 4843 OFFSETINT -1 + 4845 PUSHACC7 + 4846 C_CALL2 array_unsafe_get + 4848 PUSHACC6 + 4849 APPLY2 + 4850 BOOLNOT + 4851 BRANCHIFNOT 4911 + 4853 ACC2 + 4854 OFFSETINT -1 + 4856 PUSHACC6 + 4857 C_CALL2 array_unsafe_get + 4859 PUSHACC3 + 4860 PUSHACC7 + 4861 C_CALL3 array_unsafe_set + 4863 ACC2 + 4864 OFFSETINT -1 + 4866 PUSH + 4867 BRANCH 4886 + 4869 CHECK_SIGNALS + 4870 ACC0 + 4871 OFFSETINT -1 + 4873 PUSHACC7 + 4874 C_CALL2 array_unsafe_get + 4876 PUSHACC1 + 4877 PUSHACC 8 + 4879 C_CALL3 array_unsafe_set + 4881 ACC0 + 4882 OFFSETINT -1 + 4884 ASSIGN 0 + 4886 CONST1 + 4887 PUSHACC1 + 4888 GEINT + 4889 BRANCHIFNOT 4903 + 4891 ACC1 + 4892 PUSHACC1 + 4893 OFFSETINT -1 + 4895 PUSHACC 8 + 4897 C_CALL2 array_unsafe_get + 4899 PUSHACC7 + 4900 APPLY2 + 4901 BRANCHIFNOT 4869 + 4903 ACC1 + 4904 PUSHACC1 + 4905 PUSHACC 8 + 4907 C_CALL3 array_unsafe_set + 4909 POP 1 + 4911 POP 1 + 4913 ACC1 + 4914 OFFSETINT 1 + 4916 ASSIGN 1 + 4918 ACC0 + 4919 PUSHACC2 + 4920 LEINT + 4921 BRANCHIF 4836 + 4923 CONST0 + 4924 RETURN 5 + 4926 RESTART + 4927 GRAB 2 + 4929 ACC1 + 4930 PUSHACC1 + 4931 C_CALL2 array_unsafe_get + 4933 PUSHACC3 + 4934 PUSHACC2 + 4935 C_CALL2 array_unsafe_get + 4937 PUSHACC3 + 4938 PUSHACC3 + 4939 C_CALL3 array_unsafe_set + 4941 ACC0 + 4942 PUSHACC4 + 4943 PUSHACC3 + 4944 C_CALL3 array_unsafe_set + 4946 RETURN 4 + 4948 ACC0 + 4949 BRANCHIFNOT 4999 + 4951 ACC0 + 4952 GETFIELD0 + 4953 PUSHACC1 + 4954 GETFIELD1 + 4955 PUSHACC0 + 4956 BRANCHIFNOT 4990 + 4958 ACC0 + 4959 GETFIELD0 + 4960 PUSHACC1 + 4961 GETFIELD1 + 4962 PUSHOFFSETCLOSURE0 + 4963 APPLY1 + 4964 PUSHACC1 + 4965 PUSHACC4 + 4966 PUSHENVACC1 + 4967 APPLY2 + 4968 BRANCHIFNOT 4979 + 4970 CONST0 + 4971 PUSHACC2 + 4972 MAKEBLOCK2 0 + 4974 PUSHACC4 + 4975 MAKEBLOCK2 0 + 4977 BRANCH 4986 + 4979 CONST0 + 4980 PUSHACC4 + 4981 MAKEBLOCK2 0 + 4983 PUSHACC2 + 4984 MAKEBLOCK2 0 + 4986 MAKEBLOCK2 0 + 4988 RETURN 4 + 4990 CONST0 + 4991 PUSHCONST0 + 4992 PUSHACC3 + 4993 MAKEBLOCK2 0 + 4995 MAKEBLOCK2 0 + 4997 POP 2 + 4999 RETURN 1 + 5001 ACC0 + 5002 BRANCHIFNOT 5028 + 5004 ACC0 + 5005 GETFIELD1 + 5006 PUSHACC0 + 5007 BRANCHIFNOT 5024 + 5009 ACC0 + 5010 GETFIELD1 + 5011 PUSHOFFSETCLOSURE0 + 5012 APPLY1 + 5013 PUSHACC1 + 5014 GETFIELD0 + 5015 PUSHACC3 + 5016 GETFIELD0 + 5017 PUSHENVACC2 + 5018 PUSHENVACC1 + 5019 APPLY3 + 5020 MAKEBLOCK2 0 + 5022 RETURN 2 + 5024 POP 1 + 5026 BRANCH 5028 + 5028 ACC0 + 5029 RETURN 1 + 5031 ACC0 + 5032 BRANCHIFNOT 5040 + 5034 ACC0 + 5035 GETFIELD1 + 5036 BRANCHIF 5042 + 5038 ACC0 + 5039 GETFIELD0 + 5040 RETURN 1 + 5042 ACC0 + 5043 PUSHENVACC1 + 5044 APPLY1 + 5045 PUSHOFFSETCLOSURE0 + 5046 APPTERM1 2 + 5048 RESTART + 5049 GRAB 1 + 5051 ACC0 + 5052 CLOSUREREC 1, 4948 + 5056 ACC1 + 5057 PUSHENVACC1 + 5058 CLOSUREREC 2, 5001 + 5062 ACC0 + 5063 CLOSUREREC 1, 5031 + 5067 ACC4 + 5068 PUSHACC3 + 5069 APPLY1 + 5070 PUSHACC1 + 5071 APPTERM1 6 + 5073 CLOSUREREC 0, 4595 + 5077 ACC0 + 5078 CLOSURE 1, 5049 + 5081 PUSH + 5082 CLOSURE 0, 4927 + 5085 PUSHACC0 + 5086 CLOSURE 1, 4812 + 5089 PUSHACC3 + 5090 PUSHACC1 + 5091 PUSHACC4 + 5092 MAKEBLOCK3 0 + 5094 POP 4 + 5096 SETGLOBAL Sort + 5098 BRANCH 5847 + 5100 ACC0 + 5101 PUSHENVACC1 + 5102 APPLY1 + 5103 PUSHACC0 + 5104 GETFIELD 11 + 5106 PUSHACC1 + 5107 GETFIELD 10 + 5109 PUSHACC2 + 5110 GETFIELD 9 + 5112 PUSHACC3 + 5113 GETFIELD 6 + 5115 PUSHACC4 + 5116 GETFIELD 8 + 5118 PUSHACC5 + 5119 GETFIELD 5 + 5121 PUSHACC6 + 5122 GETFIELD 4 + 5124 PUSHACC7 + 5125 GETFIELD0 + 5126 MAKEBLOCK 8, 0 + 5129 RETURN 2 + 5131 RESTART + 5132 GRAB 2 + 5134 ACC2 + 5135 BRANCHIFNOT 5201 + 5137 ACC2 + 5138 GETFIELD0 + 5139 PUSHACC3 + 5140 GETFIELD1 + 5141 PUSHACC4 + 5142 GETFIELD2 + 5143 PUSHACC5 + 5144 GETFIELD3 + 5145 PUSHACC2 + 5146 PUSHACC5 + 5147 PUSHENVACC1 + 5148 GETFIELD0 + 5149 APPLY2 + 5150 PUSHCONST0 + 5151 PUSHACC1 + 5152 EQ + 5153 BRANCHIFNOT 5170 + 5155 ACC7 + 5156 GETFIELD 4 + 5158 PUSHACC2 + 5159 PUSHACC 8 + 5161 PUSHACC 8 + 5163 PUSHACC 8 + 5165 MAKEBLOCK 5, 0 + 5168 RETURN 8 + 5170 CONST0 + 5171 PUSHACC1 + 5172 LTINT + 5173 BRANCHIFNOT 5189 + 5175 ACC1 + 5176 PUSHACC3 + 5177 PUSHACC5 + 5178 PUSHACC7 + 5179 PUSHACC 10 + 5181 PUSHACC 10 + 5183 PUSHOFFSETCLOSURE0 + 5184 APPLY3 + 5185 PUSHENVACC2 + 5186 APPTERM 4, 12 + 5189 ACC1 + 5190 PUSHACC7 + 5191 PUSHACC7 + 5192 PUSHOFFSETCLOSURE0 + 5193 APPLY3 + 5194 PUSHACC3 + 5195 PUSHACC5 + 5196 PUSHACC7 + 5197 PUSHENVACC2 + 5198 APPTERM 4, 12 + 5201 CONST1 + 5202 PUSHCONST0 + 5203 PUSHACC3 + 5204 PUSHACC3 + 5205 PUSHCONST0 + 5206 MAKEBLOCK 5, 0 + 5209 RETURN 3 + 5211 RESTART + 5212 GRAB 1 + 5214 ACC1 + 5215 BRANCHIFNOT 5247 + 5217 ACC1 + 5218 GETFIELD1 + 5219 PUSHACC1 + 5220 PUSHENVACC1 + 5221 GETFIELD0 + 5222 APPLY2 + 5223 PUSHCONST0 + 5224 PUSHACC1 + 5225 EQ + 5226 BRANCHIFNOT 5232 + 5228 ACC2 + 5229 GETFIELD2 + 5230 RETURN 3 + 5232 CONST0 + 5233 PUSHACC1 + 5234 LTINT + 5235 BRANCHIFNOT 5241 + 5237 ACC2 + 5238 GETFIELD0 + 5239 BRANCH 5243 + 5241 ACC2 + 5242 GETFIELD3 + 5243 PUSHACC2 + 5244 PUSHOFFSETCLOSURE0 + 5245 APPTERM2 5 + 5247 GETGLOBAL Not_found + 5249 MAKEBLOCK1 0 + 5251 RAISE + 5252 RESTART + 5253 GRAB 1 + 5255 ACC1 + 5256 BRANCHIFNOT 5286 + 5258 ACC1 + 5259 GETFIELD1 + 5260 PUSHACC1 + 5261 PUSHENVACC1 + 5262 GETFIELD0 + 5263 APPLY2 + 5264 PUSHCONST0 + 5265 PUSHACC1 + 5266 EQ + 5267 BRANCHIF 5284 + 5269 CONST0 + 5270 PUSHACC1 + 5271 LTINT + 5272 BRANCHIFNOT 5278 + 5274 ACC2 + 5275 GETFIELD0 + 5276 BRANCH 5280 + 5278 ACC2 + 5279 GETFIELD3 + 5280 PUSHACC2 + 5281 PUSHOFFSETCLOSURE0 + 5282 APPTERM2 5 + 5284 POP 1 + 5286 RETURN 2 + 5288 RESTART + 5289 GRAB 1 + 5291 ACC0 + 5292 BRANCHIF 5297 + 5294 ACC1 + 5295 RETURN 2 + 5297 ACC1 + 5298 BRANCHIF 5303 + 5300 ACC0 + 5301 RETURN 2 + 5303 ACC0 + 5304 BRANCHIFNOT 5336 + 5306 ACC1 + 5307 BRANCHIFNOT 5336 + 5309 PUSH_RETADDR 5326 + 5311 ACC4 + 5312 GETFIELD3 + 5313 PUSHACC5 + 5314 GETFIELD2 + 5315 PUSHACC6 + 5316 GETFIELD1 + 5317 PUSHACC7 + 5318 GETFIELD0 + 5319 PUSHACC7 + 5320 GETFIELD3 + 5321 PUSHOFFSETCLOSURE0 + 5322 APPLY2 + 5323 PUSHENVACC1 + 5324 APPLY 4 + 5326 PUSHACC1 + 5327 GETFIELD2 + 5328 PUSHACC2 + 5329 GETFIELD1 + 5330 PUSHACC3 + 5331 GETFIELD0 + 5332 PUSHENVACC1 + 5333 APPTERM 4, 6 + 5336 GETGLOBAL <0>("map.ml", 3614, 3797) + 5338 PUSHGETGLOBAL Match_failure + 5340 MAKEBLOCK2 0 + 5342 RAISE + 5343 RESTART + 5344 GRAB 1 + 5346 ACC1 + 5347 BRANCHIFNOT 5400 + 5349 ACC1 + 5350 GETFIELD0 + 5351 PUSHACC2 + 5352 GETFIELD1 + 5353 PUSHACC3 + 5354 GETFIELD2 + 5355 PUSHACC4 + 5356 GETFIELD3 + 5357 PUSHACC2 + 5358 PUSHACC5 + 5359 PUSHENVACC1 + 5360 GETFIELD0 + 5361 APPLY2 + 5362 PUSHCONST0 + 5363 PUSHACC1 + 5364 EQ + 5365 BRANCHIFNOT 5372 + 5367 ACC1 + 5368 PUSHACC5 + 5369 PUSHENVACC3 + 5370 APPTERM2 9 + 5372 CONST0 + 5373 PUSHACC1 + 5374 LTINT + 5375 BRANCHIFNOT 5389 + 5377 ACC1 + 5378 PUSHACC3 + 5379 PUSHACC5 + 5380 PUSHACC7 + 5381 PUSHACC 9 + 5383 PUSHOFFSETCLOSURE0 + 5384 APPLY2 + 5385 PUSHENVACC2 + 5386 APPTERM 4, 11 + 5389 ACC1 + 5390 PUSHACC6 + 5391 PUSHOFFSETCLOSURE0 + 5392 APPLY2 + 5393 PUSHACC3 + 5394 PUSHACC5 + 5395 PUSHACC7 + 5396 PUSHENVACC2 + 5397 APPTERM 4, 11 + 5400 RETURN 2 + 5402 RESTART + 5403 GRAB 1 + 5405 ACC1 + 5406 BRANCHIFNOT 5425 + 5408 ACC1 + 5409 GETFIELD0 + 5410 PUSHACC1 + 5411 PUSHOFFSETCLOSURE0 + 5412 APPLY2 + 5413 ACC1 + 5414 GETFIELD2 + 5415 PUSHACC2 + 5416 GETFIELD1 + 5417 PUSHACC2 + 5418 APPLY2 + 5419 ACC1 + 5420 GETFIELD3 + 5421 PUSHACC1 + 5422 PUSHOFFSETCLOSURE0 + 5423 APPTERM2 4 + 5425 RETURN 2 + 5427 RESTART + 5428 GRAB 1 + 5430 ACC1 + 5431 BRANCHIFNOT 5455 + 5433 ACC1 + 5434 GETFIELD 4 + 5436 PUSHACC2 + 5437 GETFIELD3 + 5438 PUSHACC2 + 5439 PUSHOFFSETCLOSURE0 + 5440 APPLY2 + 5441 PUSHACC3 + 5442 GETFIELD2 + 5443 PUSHACC3 + 5444 APPLY1 + 5445 PUSHACC4 + 5446 GETFIELD1 + 5447 PUSHACC5 + 5448 GETFIELD0 + 5449 PUSHACC5 + 5450 PUSHOFFSETCLOSURE0 + 5451 APPLY2 + 5452 MAKEBLOCK 5, 0 + 5455 RETURN 2 + 5457 RESTART + 5458 GRAB 2 + 5460 ACC1 + 5461 BRANCHIFNOT 5481 + 5463 ACC2 + 5464 PUSHACC2 + 5465 GETFIELD3 + 5466 PUSHACC2 + 5467 PUSHOFFSETCLOSURE0 + 5468 APPLY3 + 5469 PUSHACC2 + 5470 GETFIELD2 + 5471 PUSHACC3 + 5472 GETFIELD1 + 5473 PUSHACC3 + 5474 APPLY3 + 5475 PUSHACC2 + 5476 GETFIELD0 + 5477 PUSHACC2 + 5478 PUSHOFFSETCLOSURE0 + 5479 APPTERM3 6 + 5481 ACC2 + 5482 RETURN 3 + 5484 RESTART + 5485 GRAB 3 + 5487 ACC0 + 5488 BRANCHIFNOT 5495 + 5490 ACC0 + 5491 GETFIELD 4 + 5493 BRANCH 5496 + 5495 CONST0 + 5496 PUSHACC4 + 5497 BRANCHIFNOT 5504 + 5499 ACC4 + 5500 GETFIELD 4 + 5502 BRANCH 5505 + 5504 CONST0 + 5505 PUSHACC0 + 5506 OFFSETINT 2 + 5508 PUSHACC2 + 5509 GTINT + 5510 BRANCHIFNOT 5603 + 5512 ACC2 + 5513 BRANCHIFNOT 5596 + 5515 ACC2 + 5516 GETFIELD0 + 5517 PUSHACC3 + 5518 GETFIELD1 + 5519 PUSHACC4 + 5520 GETFIELD2 + 5521 PUSHACC5 + 5522 GETFIELD3 + 5523 PUSHACC0 + 5524 PUSHENVACC1 + 5525 APPLY1 + 5526 PUSHACC4 + 5527 PUSHENVACC1 + 5528 APPLY1 + 5529 GEINT + 5530 BRANCHIFNOT 5551 + 5532 PUSH_RETADDR 5544 + 5534 ACC 12 + 5536 PUSHACC 12 + 5538 PUSHACC 12 + 5540 PUSHACC6 + 5541 PUSHENVACC2 + 5542 APPLY 4 + 5544 PUSHACC2 + 5545 PUSHACC4 + 5546 PUSHACC6 + 5547 PUSHENVACC2 + 5548 APPTERM 4, 14 + 5551 ACC0 + 5552 BRANCHIFNOT 5589 + 5554 PUSH_RETADDR 5567 + 5556 ACC 12 + 5558 PUSHACC 12 + 5560 PUSHACC 12 + 5562 PUSHACC6 + 5563 GETFIELD3 + 5564 PUSHENVACC2 + 5565 APPLY 4 + 5567 PUSHACC1 + 5568 GETFIELD2 + 5569 PUSHACC2 + 5570 GETFIELD1 + 5571 PUSH + 5572 PUSH_RETADDR 5585 + 5574 ACC6 + 5575 GETFIELD0 + 5576 PUSHACC 8 + 5578 PUSHACC 10 + 5580 PUSHACC 12 + 5582 PUSHENVACC2 + 5583 APPLY 4 + 5585 PUSHENVACC2 + 5586 APPTERM 4, 14 + 5589 GETGLOBAL "Map.bal" + 5591 PUSHGETGLOBALFIELD Pervasives, 2 + 5594 APPTERM1 11 + 5596 GETGLOBAL "Map.bal" + 5598 PUSHGETGLOBALFIELD Pervasives, 2 + 5601 APPTERM1 7 + 5603 ACC1 + 5604 OFFSETINT 2 + 5606 PUSHACC1 + 5607 GTINT + 5608 BRANCHIFNOT 5703 + 5610 ACC5 + 5611 BRANCHIFNOT 5696 + 5613 ACC5 + 5614 GETFIELD0 + 5615 PUSHACC6 + 5616 GETFIELD1 + 5617 PUSHACC7 + 5618 GETFIELD2 + 5619 PUSHACC 8 + 5621 GETFIELD3 + 5622 PUSHACC3 + 5623 PUSHENVACC1 + 5624 APPLY1 + 5625 PUSHACC1 + 5626 PUSHENVACC1 + 5627 APPLY1 + 5628 GEINT + 5629 BRANCHIFNOT 5652 + 5631 ACC0 + 5632 PUSHACC2 + 5633 PUSHACC4 + 5634 PUSH + 5635 PUSH_RETADDR 5648 + 5637 ACC 9 + 5639 PUSHACC 15 + 5641 PUSHACC 15 + 5643 PUSHACC 15 + 5645 PUSHENVACC2 + 5646 APPLY 4 + 5648 PUSHENVACC2 + 5649 APPTERM 4, 14 + 5652 ACC3 + 5653 BRANCHIFNOT 5689 + 5655 PUSH_RETADDR 5666 + 5657 ACC3 + 5658 PUSHACC5 + 5659 PUSHACC7 + 5660 PUSHACC 9 + 5662 GETFIELD3 + 5663 PUSHENVACC2 + 5664 APPLY 4 + 5666 PUSHACC4 + 5667 GETFIELD2 + 5668 PUSHACC5 + 5669 GETFIELD1 + 5670 PUSH + 5671 PUSH_RETADDR 5685 + 5673 ACC 9 + 5675 GETFIELD0 + 5676 PUSHACC 15 + 5678 PUSHACC 15 + 5680 PUSHACC 15 + 5682 PUSHENVACC2 + 5683 APPLY 4 + 5685 PUSHENVACC2 + 5686 APPTERM 4, 14 + 5689 GETGLOBAL "Map.bal" + 5691 PUSHGETGLOBALFIELD Pervasives, 2 + 5694 APPTERM1 11 + 5696 GETGLOBAL "Map.bal" + 5698 PUSHGETGLOBALFIELD Pervasives, 2 + 5701 APPTERM1 7 + 5703 ACC0 + 5704 PUSHACC2 + 5705 GEINT + 5706 BRANCHIFNOT 5713 + 5708 ACC1 + 5709 OFFSETINT 1 + 5711 BRANCH 5716 + 5713 ACC0 + 5714 OFFSETINT 1 + 5716 PUSHACC6 + 5717 PUSHACC6 + 5718 PUSHACC6 + 5719 PUSHACC6 + 5720 MAKEBLOCK 5, 0 + 5723 RETURN 6 + 5725 RESTART + 5726 GRAB 3 + 5728 ACC0 + 5729 PUSHENVACC1 + 5730 APPLY1 + 5731 PUSHACC4 + 5732 PUSHENVACC1 + 5733 APPLY1 + 5734 PUSHACC0 + 5735 PUSHACC2 + 5736 GEINT + 5737 BRANCHIFNOT 5744 + 5739 ACC1 + 5740 OFFSETINT 1 + 5742 BRANCH 5747 + 5744 ACC0 + 5745 OFFSETINT 1 + 5747 PUSHACC6 + 5748 PUSHACC6 + 5749 PUSHACC6 + 5750 PUSHACC6 + 5751 MAKEBLOCK 5, 0 + 5754 RETURN 6 + 5756 ACC0 + 5757 BRANCHIFNOT 5764 + 5759 ACC0 + 5760 GETFIELD 4 + 5762 RETURN 1 + 5764 CONST0 + 5765 RETURN 1 + 5767 CONST0 + 5768 PUSH + 5769 CLOSURE 0, 5756 + 5772 PUSHACC0 + 5773 CLOSURE 1, 5726 + 5776 PUSHACC0 + 5777 PUSHACC2 + 5778 CLOSURE 2, 5485 + 5781 PUSHACC0 + 5782 PUSHACC5 + 5783 CLOSUREREC 2, 5132 + 5787 ACC5 + 5788 CLOSUREREC 1, 5212 + 5792 ACC6 + 5793 CLOSUREREC 1, 5253 + 5797 ACC3 + 5798 CLOSUREREC 1, 5289 + 5802 ACC0 + 5803 PUSHACC5 + 5804 PUSHACC 10 + 5806 CLOSUREREC 3, 5344 + 5810 CLOSUREREC 0, 5403 + 5814 CLOSUREREC 0, 5428 + 5818 CLOSUREREC 0, 5458 + 5822 ACC0 + 5823 PUSHACC2 + 5824 PUSHACC4 + 5825 PUSHACC6 + 5826 PUSHACC 8 + 5828 PUSHACC 10 + 5830 PUSHACC 12 + 5832 PUSHACC 14 + 5834 PUSHACC 16 + 5836 PUSHACC 18 + 5838 PUSHACC 20 + 5840 PUSHACC 22 + 5842 MAKEBLOCK 12, 0 + 5845 RETURN 13 + 5847 CLOSURE 0, 5767 + 5850 PUSHACC0 + 5851 CLOSURE 1, 5100 + 5854 MAKEBLOCK1 0 + 5856 POP 1 + 5858 SETGLOBAL Map + 5860 BRANCH 5957 + 5862 CONSTINT 16 + 5864 C_CALL1 create_string + 5866 PUSH + 5867 PUSH_RETADDR 5879 + 5869 CONSTINT 16 + 5871 PUSHCONST0 + 5872 PUSHACC5 + 5873 PUSHACC7 + 5874 PUSHGETGLOBALFIELD Pervasives, 56 + 5877 APPLY 4 + 5879 ACC0 + 5880 RETURN 2 + 5882 RESTART + 5883 GRAB 1 + 5885 CONSTINT 16 + 5887 PUSHCONST0 + 5888 PUSHACC3 + 5889 PUSHACC3 + 5890 PUSHGETGLOBALFIELD Pervasives, 41 + 5893 APPTERM 4, 6 + 5896 ACC0 + 5897 PUSHGETGLOBALFIELD Pervasives, 51 + 5900 APPLY1 + 5901 PUSHACC0 + 5902 PUSHGETGLOBALFIELD Pervasives, 62 + 5905 APPLY1 + 5906 PUSHACC1 + 5907 C_CALL2 md5_chan + 5909 PUSHACC1 + 5910 PUSHGETGLOBALFIELD Pervasives, 63 + 5913 APPLY1 + 5914 ACC0 + 5915 RETURN 3 + 5917 RESTART + 5918 GRAB 2 + 5920 CONST0 + 5921 PUSHACC2 + 5922 LTINT + 5923 BRANCHIF 5934 + 5925 ACC0 + 5926 C_CALL1 ml_string_length + 5928 PUSHACC3 + 5929 PUSHACC3 + 5930 ADDINT + 5931 GTINT + 5932 BRANCHIFNOT 5941 + 5934 GETGLOBAL "Digest.substring" + 5936 PUSHGETGLOBALFIELD Pervasives, 2 + 5939 APPTERM1 4 + 5941 ACC2 + 5942 PUSHACC2 + 5943 PUSHACC2 + 5944 C_CALL3 md5_string + 5946 RETURN 3 + 5948 ACC0 + 5949 C_CALL1 ml_string_length + 5951 PUSHCONST0 + 5952 PUSHACC2 + 5953 C_CALL3 md5_string + 5955 RETURN 1 + 5957 CLOSURE 0, 5948 + 5960 PUSH + 5961 CLOSURE 0, 5918 + 5964 PUSH + 5965 CLOSURE 0, 5896 + 5968 PUSH + 5969 CLOSURE 0, 5883 + 5972 PUSH + 5973 CLOSURE 0, 5862 + 5976 PUSHACC0 + 5977 PUSHACC2 + 5978 PUSHACC4 + 5979 PUSHACC6 + 5980 PUSHACC 8 + 5982 MAKEBLOCK 5, 0 + 5985 POP 5 + 5987 SETGLOBAL Digest + 5989 BRANCH 6245 + 5991 CONST0 + 5992 PUSHENVACC1 + 5993 APPLY1 + 5994 PUSHACC1 + 5995 PUSHACC1 + 5996 GEINT + 5997 BRANCHIFNOT 6003 + 5999 ACC1 + 6000 PUSHOFFSETCLOSURE0 + 6001 APPTERM1 3 + 6003 ACC0 + 6004 RETURN 2 + 6006 CONST0 + 6007 C_CALL1 sys_random_seed + 6009 PUSHENVACC1 + 6010 APPTERM1 2 + 6012 CONSTINT 27182818 + 6014 PUSHENVACC2 + 6015 APPLY1 + 6016 CONST0 + 6017 PUSHACC1 + 6018 VECTLENGTH + 6019 OFFSETINT -1 + 6021 PUSH + 6022 BRANCH 6046 + 6024 CHECK_SIGNALS + 6025 CONSTINT 55 + 6027 PUSHACC2 + 6028 MODINT + 6029 PUSHACC2 + 6030 PUSHACC4 + 6031 GETVECTITEM + 6032 PUSHACC1 + 6033 PUSHENVACC1 + 6034 GETVECTITEM + 6035 ADDINT + 6036 PUSHACC1 + 6037 PUSHENVACC1 + 6038 SETVECTITEM + 6039 POP 1 + 6041 ACC1 + 6042 OFFSETINT 1 + 6044 ASSIGN 1 + 6046 ACC0 + 6047 PUSHACC2 + 6048 LEINT + 6049 BRANCHIF 6024 + 6051 CONST0 + 6052 RETURN 3 + 6054 ENVACC1 + 6055 GETFIELD0 + 6056 OFFSETINT 1 + 6058 PUSHENVACC1 + 6059 SETFIELD0 + 6060 ENVACC1 + 6061 GETFIELD0 + 6062 PUSHGETGLOBALFIELD Pervasives, 14 + 6065 APPLY1 + 6066 PUSHGETGLOBALFIELD Digest, 0 + 6069 APPLY1 + 6070 PUSHCONSTINT 22 + 6072 PUSHCONST3 + 6073 PUSHACC2 + 6074 C_CALL2 string_get + 6076 LSLINT + 6077 PUSHCONSTINT 16 + 6079 PUSHCONST2 + 6080 PUSHACC3 + 6081 C_CALL2 string_get + 6083 LSLINT + 6084 PUSHCONSTINT 8 + 6086 PUSHCONST1 + 6087 PUSHACC4 + 6088 C_CALL2 string_get + 6090 LSLINT + 6091 PUSHCONST0 + 6092 PUSHACC4 + 6093 C_CALL2 string_get + 6095 ADDINT + 6096 ADDINT + 6097 XORINT + 6098 RETURN 2 + 6100 ACC0 + 6101 MAKEBLOCK1 0 + 6103 PUSHACC0 + 6104 CLOSURE 1, 6054 + 6107 PUSHCONST0 + 6108 PUSHCONSTINT 54 + 6110 PUSH + 6111 BRANCH 6125 + 6113 CHECK_SIGNALS + 6114 CONST0 + 6115 PUSHACC3 + 6116 APPLY1 + 6117 PUSHACC2 + 6118 PUSHENVACC1 + 6119 SETVECTITEM + 6120 ACC1 + 6121 OFFSETINT 1 + 6123 ASSIGN 1 + 6125 ACC0 + 6126 PUSHACC2 + 6127 LEINT + 6128 BRANCHIF 6113 + 6130 CONST0 + 6131 POP 2 + 6133 CONST0 + 6134 PUSHENVACC2 + 6135 SETFIELD0 + 6136 RETURN 3 + 6138 ACC0 + 6139 PUSHCONST0 + 6140 PUSHENVACC1 + 6141 APPLY1 + 6142 C_CALL2 mul_float + 6144 RETURN 1 + 6146 CONSTINT 1073741823 + 6148 PUSHACC1 + 6149 GTINT + 6150 BRANCHIF 6157 + 6152 CONST0 + 6153 PUSHACC1 + 6154 LEINT + 6155 BRANCHIFNOT 6164 + 6157 GETGLOBAL "Random.int" + 6159 PUSHGETGLOBALFIELD Pervasives, 2 + 6162 APPTERM1 2 + 6164 ACC0 + 6165 PUSHACC1 + 6166 PUSHACC2 + 6167 PUSHCONSTINT 1073741823 + 6169 DIVINT + 6170 MULINT + 6171 PUSHENVACC1 + 6172 APPLY1 + 6173 MODINT + 6174 RETURN 1 + 6176 GETGLOBAL 1073741824 + 6178 PUSHCONST0 + 6179 PUSHENVACC1 + 6180 APPLY1 + 6181 C_CALL1 float_of_int + 6183 PUSHCONST0 + 6184 PUSHENVACC1 + 6185 APPLY1 + 6186 C_CALL1 float_of_int + 6188 PUSHCONST0 + 6189 PUSHENVACC1 + 6190 APPLY1 + 6191 C_CALL1 float_of_int + 6193 PUSHACC3 + 6194 PUSHACC1 + 6195 PUSHACC5 + 6196 PUSHACC4 + 6197 PUSHACC7 + 6198 PUSHACC7 + 6199 C_CALL2 div_float + 6201 C_CALL2 add_float + 6203 C_CALL2 div_float + 6205 C_CALL2 add_float + 6207 C_CALL2 div_float + 6209 RETURN 5 + 6211 CONSTINT 55 + 6213 PUSHENVACC2 + 6214 GETFIELD0 + 6215 OFFSETINT 1 + 6217 MODINT + 6218 PUSHENVACC2 + 6219 SETFIELD0 + 6220 ENVACC2 + 6221 GETFIELD0 + 6222 PUSHENVACC1 + 6223 GETVECTITEM + 6224 PUSHCONSTINT 55 + 6226 PUSHENVACC2 + 6227 GETFIELD0 + 6228 OFFSETINT 24 + 6230 MODINT + 6231 PUSHENVACC1 + 6232 GETVECTITEM + 6233 ADDINT + 6234 PUSHACC0 + 6235 PUSHENVACC2 + 6236 GETFIELD0 + 6237 PUSHENVACC1 + 6238 SETVECTITEM + 6239 CONSTINT 1073741823 + 6241 PUSHACC1 + 6242 ANDINT + 6243 RETURN 2 + 6245 CONSTINT 440266690 + 6247 PUSHCONSTINT 124177607 + 6249 PUSHCONSTINT 414576093 + 6251 PUSHCONSTINT 180326017 + 6253 PUSHCONSTINT 33747835 + 6255 PUSHCONSTINT 896816596 + 6257 PUSHCONSTINT 21528564 + 6259 PUSHCONSTINT 414383108 + 6261 PUSHCONSTINT 514922558 + 6263 PUSHCONSTINT 979459837 + 6265 PUSHCONSTINT 146577263 + 6267 PUSHCONSTINT 714526560 + 6269 PUSHCONSTINT 187230644 + 6271 PUSHCONSTINT 22990936 + 6273 PUSHCONSTINT 310632349 + 6275 PUSHCONSTINT 781847598 + 6277 PUSHCONSTINT 854580894 + 6279 PUSHCONSTINT 804670393 + 6281 PUSHCONSTINT 268309077 + 6283 PUSHCONSTINT 4136554 + 6285 PUSHCONSTINT 567327260 + 6287 PUSHCONSTINT 768795410 + 6289 PUSHCONSTINT 868098973 + 6291 PUSHCONSTINT 462134267 + 6293 PUSHCONSTINT 32881167 + 6295 PUSHCONSTINT 708896334 + 6297 PUSHCONSTINT 572927557 + 6299 PUSHCONSTINT 933858406 + 6301 PUSHCONSTINT 965168955 + 6303 PUSHCONSTINT 233350272 + 6305 PUSHCONSTINT 878960411 + 6307 PUSHCONSTINT 971004788 + 6309 PUSHCONSTINT 762624501 + 6311 PUSHCONSTINT 796925167 + 6313 PUSHCONSTINT 206134737 + 6315 PUSHCONSTINT 281896889 + 6317 PUSHCONSTINT 814302728 + 6319 PUSHCONSTINT 477485839 + 6321 PUSHCONSTINT 998499212 + 6323 PUSHCONSTINT 473370118 + 6325 PUSHCONSTINT 66770770 + 6327 PUSHCONSTINT 337696531 + 6329 PUSHCONSTINT 848741663 + 6331 PUSHCONSTINT 71648846 + 6333 PUSHCONSTINT 869261341 + 6335 PUSHCONSTINT 951240904 + 6337 PUSHCONSTINT 147054819 + 6339 PUSHCONSTINT 486882977 + 6341 PUSHCONSTINT 552627506 + 6343 PUSHCONSTINT 615350359 + 6345 PUSHCONSTINT 1023641486 + 6347 PUSHCONSTINT 9858203 + 6349 PUSHCONSTINT 764306064 + 6351 PUSHCONSTINT 1051173471 + 6353 PUSHCONSTINT 561073064 + 6355 MAKEBLOCK 55, 0 + 6358 PUSHCONST0 + 6359 MAKEBLOCK1 0 + 6361 PUSHACC0 + 6362 PUSHACC2 + 6363 CLOSURE 2, 6211 + 6366 PUSHACC0 + 6367 CLOSURE 1, 6176 + 6370 PUSHACC1 + 6371 CLOSUREREC 1, 5991 + 6375 ACC0 + 6376 CLOSURE 1, 6146 + 6379 PUSHACC2 + 6380 CLOSURE 1, 6138 + 6383 PUSHACC5 + 6384 PUSHACC7 + 6385 CLOSURE 2, 6100 + 6388 PUSHACC0 + 6389 PUSHACC 8 + 6391 CLOSURE 2, 6012 + 6394 PUSHACC1 + 6395 CLOSURE 1, 6006 + 6398 PUSHACC3 + 6399 PUSHACC5 + 6400 PUSHACC 9 + 6402 PUSHACC3 + 6403 PUSHACC5 + 6404 PUSHACC7 + 6405 MAKEBLOCK 6, 0 + 6408 POP 10 + 6410 SETGLOBAL Random + 6412 BRANCH 8038 + 6414 RESTART + 6415 GRAB 1 + 6417 ACC1 + 6418 BRANCHIFNOT 6441 + 6420 ACC1 + 6421 GETFIELD0 + 6422 PUSHACC2 + 6423 GETFIELD1 + 6424 PUSHACC1 + 6425 PUSHACC3 + 6426 EQ + 6427 BRANCHIFNOT 6432 + 6429 ACC0 + 6430 RETURN 4 + 6432 ACC0 + 6433 PUSHACC3 + 6434 PUSHOFFSETCLOSURE0 + 6435 APPLY2 + 6436 PUSHACC2 + 6437 MAKEBLOCK2 0 + 6439 POP 2 + 6441 RETURN 2 + 6443 RESTART + 6444 GRAB 1 + 6446 CONST0 + 6447 PUSHACC2 + 6448 GTINT + 6449 BRANCHIFNOT 6512 + 6451 CONST0 + 6452 PUSHENVACC2 + 6453 GETFIELD0 + 6454 GTINT + 6455 BRANCHIFNOT 6512 + 6457 ENVACC2 + 6458 GETFIELD0 + 6459 PUSHGETGLOBALFIELD Random, 4 + 6462 APPLY1 + 6463 PUSHACC0 + 6464 PUSHENVACC1 + 6465 GETFIELD0 + 6466 C_CALL2 array_get_addr + 6468 PUSHENVACC 5 + 6470 APPLY1 + 6471 BRANCHIF 6482 + 6473 ACC0 + 6474 PUSHENVACC 4 + 6476 APPLY1 + 6477 ACC2 + 6478 PUSHACC2 + 6479 PUSHOFFSETCLOSURE0 + 6480 APPTERM2 5 + 6482 PUSHTRAP 6496 + 6484 ACC5 + 6485 PUSHACC5 + 6486 PUSHENVACC1 + 6487 GETFIELD0 + 6488 C_CALL2 array_get_addr + 6490 PUSHENVACC 7 + 6492 APPLY2 + 6493 POPTRAP + 6494 RETURN 3 + 6496 PUSHENVACC 6 + 6498 PUSHACC1 + 6499 GETFIELD0 + 6500 EQ + 6501 BRANCHIFNOT 6510 + 6503 ACC3 + 6504 OFFSETINT -1 + 6506 PUSHACC3 + 6507 PUSHOFFSETCLOSURE0 + 6508 APPTERM2 6 + 6510 ACC0 + 6511 RAISE + 6512 ACC0 + 6513 PUSHENVACC3 + 6514 APPLY1 + 6515 ACC0 + 6516 RETURN 2 + 6518 RESTART + 6519 GRAB 1 + 6521 ACC1 + 6522 BRANCHIFNOT 6534 + 6524 ACC0 + 6525 PUSHACC2 + 6526 GETFIELD0 + 6527 APPLY1 + 6528 ACC1 + 6529 GETFIELD1 + 6530 PUSHACC1 + 6531 PUSHOFFSETCLOSURE0 + 6532 APPTERM2 4 + 6534 RETURN 2 + 6536 CONST0 + 6537 PUSHENVACC1 + 6538 OFFSETINT -1 + 6540 PUSH + 6541 BRANCH 6567 + 6543 CHECK_SIGNALS + 6544 ENVACC2 + 6545 PUSHACC2 + 6546 PUSHACC4 + 6547 C_CALL2 array_get + 6549 EQ + 6550 BRANCHIFNOT 6556 + 6552 CONSTINT 46 + 6554 BRANCH 6558 + 6556 CONSTINT 42 + 6558 PUSHGETGLOBALFIELD Pervasives, 20 + 6561 APPLY1 + 6562 ACC1 + 6563 OFFSETINT 1 + 6565 ASSIGN 1 + 6567 ACC0 + 6568 PUSHACC2 + 6569 LEINT + 6570 BRANCHIF 6543 + 6572 CONST0 + 6573 POP 2 + 6575 CONST0 + 6576 PUSHGETGLOBALFIELD Pervasives, 25 + 6579 APPTERM1 2 + 6581 ENVACC3 + 6582 GETFIELD0 + 6583 PUSHENVACC 4 + 6585 APPLY1 + 6586 PUSHENVACC2 + 6587 PUSHENVACC1 + 6588 CLOSURE 2, 6536 + 6591 PUSHGETGLOBALFIELD List, 9 + 6594 APPTERM2 3 + 6596 ACC0 + 6597 GETFIELD1 + 6598 RETURN 1 + 6600 RESTART + 6601 GRAB 1 + 6603 ACC1 + 6604 GETFIELD0 + 6605 PUSHACC1 + 6606 GETFIELD0 + 6607 LEINT + 6608 RETURN 2 + 6610 ACC0 + 6611 PUSHACC1 + 6612 PUSHENVACC1 + 6613 APPLY1 + 6614 MAKEBLOCK2 0 + 6616 RETURN 1 + 6618 ACC0 + 6619 PUSHENVACC1 + 6620 CLOSURE 1, 6610 + 6623 PUSHGETGLOBALFIELD List, 10 + 6626 APPLY2 + 6627 PUSH + 6628 CLOSURE 0, 6601 + 6631 PUSHGETGLOBALFIELD Sort, 0 + 6634 APPLY2 + 6635 PUSH + 6636 CLOSURE 0, 6596 + 6639 PUSHGETGLOBALFIELD List, 10 + 6642 APPTERM2 3 + 6644 ENVACC3 + 6645 GETFIELD0 + 6646 VECTLENGTH + 6647 PUSHENVACC 4 + 6649 GETFIELD0 + 6650 PUSHCONST0 + 6651 PUSHENVACC 8 + 6653 APPLY1 + 6654 PUSHENVACC2 + 6655 GETFIELD0 + 6656 PUSHGETGLOBALFIELD List, 0 + 6659 APPLY1 + 6660 PUSHENVACC 7 + 6662 GETFIELD0 + 6663 PUSHENVACC 6 + 6665 GETFIELD0 + 6666 PUSHENVACC1 + 6667 GETFIELD0 + 6668 PUSHENVACC 5 + 6670 GETFIELD0 + 6671 MAKEBLOCK 8, 0 + 6674 RETURN 1 + 6676 ACC0 + 6677 PUSHENVACC1 + 6678 APPLY1 + 6679 PUSHACC0 + 6680 OFFSETINT -1 + 6682 PUSHENVACC2 + 6683 C_CALL2 array_get_addr + 6685 OFFSETINT 1 + 6687 PUSHACC1 + 6688 OFFSETINT -1 + 6690 PUSHENVACC2 + 6691 C_CALL3 array_set_addr + 6693 RETURN 2 + 6695 CONST0 + 6696 PUSHCONSTINT 32 + 6698 C_CALL2 make_vect + 6700 PUSHENVACC1 + 6701 GETFIELD0 + 6702 PUSHACC1 + 6703 PUSHENVACC2 + 6704 CLOSURE 2, 6676 + 6707 PUSHGETGLOBALFIELD List, 9 + 6710 APPLY2 + 6711 ACC0 + 6712 RETURN 2 + 6714 RESTART + 6715 GRAB 1 + 6717 ACC1 + 6718 PUSHENVACC1 + 6719 APPLY1 + 6720 PUSHACC1 + 6721 PUSHACC1 + 6722 GETFIELD1 + 6723 PUSHACC2 + 6724 GETFIELD0 + 6725 PUSHCONST0 + 6726 PUSHACC5 + 6727 C_CALL2 array_get_addr + 6729 C_CALL2 array_get_addr + 6731 C_CALL2 array_get_addr + 6733 APPTERM1 4 + 6735 ACC0 + 6736 GETFIELD0 + 6737 C_CALL1 obj_dup + 6739 PUSHENVACC1 + 6740 PUSHACC1 + 6741 PUSHENVACC2 + 6742 APPLY2 + 6743 ACC1 + 6744 GETFIELD2 + 6745 PUSHACC1 + 6746 PUSHENVACC3 + 6747 APPLY2 + 6748 ACC0 + 6749 RETURN 2 + 6751 RESTART + 6752 GRAB 1 + 6754 ACC1 + 6755 GETFIELD 7 + 6757 PUSHCONST0 + 6758 PUSHACC1 + 6759 NEQ + 6760 BRANCHIFNOT 6767 + 6762 ACC0 + 6763 PUSHACC2 + 6764 PUSHENVACC1 + 6765 APPTERM2 5 + 6767 RETURN 3 + 6769 ACC0 + 6770 GETFIELD0 + 6771 PUSHENVACC1 + 6772 C_CALL2 obj_block + 6774 PUSHACC1 + 6775 GETFIELD1 + 6776 PUSHCONST0 + 6777 PUSHACC2 + 6778 C_CALL3 array_unsafe_set + 6780 ENVACC2 + 6781 PUSHACC1 + 6782 PUSHENVACC3 + 6783 APPLY2 + 6784 ACC0 + 6785 RETURN 2 + 6787 ACC0 + 6788 GETFIELD0 + 6789 PUSHENVACC3 + 6790 GETFIELD0 + 6791 ADDINT + 6792 OFFSETINT -1 + 6794 PUSHENVACC3 + 6795 SETFIELD0 + 6796 ENVACC1 + 6797 GETFIELD0 + 6798 BRANCHIFNOT 6804 + 6800 ACC0 + 6801 GETFIELD1 + 6802 PUSHENVACC2 + 6803 APPLY1 + 6804 ACC0 + 6805 GETFIELD 7 + 6807 PUSHGETGLOBALFIELD List, 4 + 6810 APPLY1 + 6811 PUSHACC1 + 6812 SETFIELD 7 + 6814 RETURN 1 + 6816 ACC0 + 6817 PUSHENVACC1 + 6818 APPLY1 + 6819 PUSHENVACC 4 + 6821 GETFIELD2 + 6822 PUSHACC1 + 6823 PUSHACC3 + 6824 PUSHENVACC2 + 6825 GETFIELD1 + 6826 APPLY3 + 6827 PUSHENVACC 4 + 6829 SETFIELD2 + 6830 ENVACC4 + 6831 GETFIELD3 + 6832 PUSHCONST1 + 6833 PUSHACC2 + 6834 PUSHENVACC3 + 6835 GETFIELD1 + 6836 APPLY3 + 6837 PUSHENVACC 4 + 6839 SETFIELD3 + 6840 RETURN 2 + 6842 CONST0 + 6843 PUSHENVACC 4 + 6845 APPLY1 + 6846 PUSHACC1 + 6847 PUSHACC1 + 6848 PUSHENVACC3 + 6849 PUSHENVACC2 + 6850 PUSHENVACC1 + 6851 CLOSURE 4, 6816 + 6854 PUSHGETGLOBALFIELD List, 9 + 6857 APPLY2 + 6858 ACC0 + 6859 RETURN 2 + 6861 RESTART + 6862 GRAB 1 + 6864 ACC0 + 6865 GETFIELD 7 + 6867 PUSHACC2 + 6868 MAKEBLOCK2 0 + 6870 PUSHACC1 + 6871 SETFIELD 7 + 6873 RETURN 2 + 6875 ENVACC1 + 6876 PUSHENVACC3 + 6877 PUSH + 6878 BRANCH 6895 + 6880 CHECK_SIGNALS + 6881 ACC1 + 6882 PUSHENVACC2 + 6883 GETVECTITEM + 6884 PUSHENVACC 4 + 6886 PUSHACC3 + 6887 ADDINT + 6888 PUSHACC4 + 6889 SETVECTITEM + 6890 ACC1 + 6891 OFFSETINT 1 + 6893 ASSIGN 1 + 6895 ACC0 + 6896 PUSHACC2 + 6897 LEINT + 6898 BRANCHIF 6880 + 6900 CONST0 + 6901 RETURN 3 + 6903 ENVACC2 + 6904 GETFIELD0 + 6905 PUSHENVACC2 + 6906 GETFIELD2 + 6907 GETFIELD0 + 6908 OFFSETINT -1 + 6910 PUSHENVACC3 + 6911 GETFIELD0 + 6912 OFFSETINT -1 + 6914 PUSHACC1 + 6915 PUSHACC1 + 6916 SUBINT + 6917 PUSHACC0 + 6918 PUSHACC3 + 6919 PUSHACC5 + 6920 PUSHENVACC1 + 6921 CLOSURE 4, 6875 + 6924 RETURN 5 + 6926 RESTART + 6927 GRAB 1 + 6929 CONST0 + 6930 ACC1 + 6931 PUSHACC1 + 6932 PUSHENVACC1 + 6933 CLOSURE 3, 6903 + 6936 RETURN 2 + 6938 RESTART + 6939 GRAB 1 + 6941 ACC0 + 6942 GETFIELD 6 + 6944 PUSHACC2 + 6945 PUSHENVACC1 + 6946 GETFIELD2 + 6947 APPTERM2 4 + 6949 RESTART + 6950 GRAB 1 + 6952 ACC0 + 6953 PUSHENVACC2 + 6954 APPLY1 + 6955 PUSHACC1 + 6956 GETFIELD 6 + 6958 PUSHACC1 + 6959 PUSHACC4 + 6960 PUSHENVACC1 + 6961 GETFIELD1 + 6962 APPLY3 + 6963 PUSHACC2 + 6964 SETFIELD 6 + 6966 ACC0 + 6967 RETURN 3 + 6969 ACC0 + 6970 GETFIELD0 + 6971 PUSHACC0 + 6972 OFFSETINT 1 + 6974 PUSHACC2 + 6975 SETFIELD0 + 6976 ACC0 + 6977 RETURN 2 + 6979 RESTART + 6980 GRAB 1 + 6982 CONST0 + 6983 PUSHACC1 + 6984 PUSHACC3 + 6985 GETFIELD1 + 6986 APPTERM2 4 + 6988 RESTART + 6989 GRAB 1 + 6991 ENVACC1 + 6992 GETFIELD 4 + 6994 PUSHACC1 + 6995 GETFIELD0 + 6996 PUSHGETGLOBALFIELD List, 23 + 6999 APPLY2 + 7000 BRANCHIFNOT 7005 + 7002 ACC1 + 7003 RETURN 2 + 7005 ACC1 + 7006 PUSHACC1 + 7007 MAKEBLOCK2 0 + 7009 RETURN 2 + 7011 RESTART + 7012 GRAB 1 + 7014 ACC0 + 7015 PUSHENVACC2 + 7016 GETFIELD 6 + 7018 PUSHACC3 + 7019 PUSHENVACC1 + 7020 GETFIELD2 + 7021 APPLY2 + 7022 PUSHACC3 + 7023 PUSHENVACC1 + 7024 GETFIELD1 + 7025 APPTERM3 5 + 7027 ACC0 + 7028 GETFIELD 4 + 7030 PUSHGETGLOBALFIELD List, 1 + 7033 APPLY1 + 7034 PUSHACC1 + 7035 GETFIELD 4 + 7037 PUSHGETGLOBALFIELD List, 2 + 7040 APPLY1 + 7041 PUSHACC2 + 7042 SETFIELD 4 + 7044 ACC0 + 7045 GETFIELD 5 + 7047 PUSHACC1 + 7048 GETFIELD3 + 7049 PUSHACC3 + 7050 PUSHENVACC1 + 7051 CLOSURE 2, 7012 + 7054 PUSHGETGLOBALFIELD List, 12 + 7057 APPLY3 + 7058 PUSHACC2 + 7059 SETFIELD 6 + 7061 ACC0 + 7062 GETFIELD0 + 7063 PUSHACC2 + 7064 SETFIELD2 + 7065 ACC0 + 7066 GETFIELD1 + 7067 PUSHACC2 + 7068 SETFIELD3 + 7069 ACC0 + 7070 GETFIELD2 + 7071 PUSHACC2 + 7072 GETFIELD 5 + 7074 PUSHACC2 + 7075 CLOSURE 1, 6989 + 7078 PUSHGETGLOBALFIELD List, 13 + 7081 APPLY3 + 7082 PUSHACC2 + 7083 SETFIELD 5 + 7085 RETURN 2 + 7087 RESTART + 7088 GRAB 1 + 7090 ENVACC1 + 7091 PUSHACC1 + 7092 GETFIELD0 + 7093 PUSHGETGLOBALFIELD List, 23 + 7096 APPLY2 + 7097 BRANCHIFNOT 7102 + 7099 ACC1 + 7100 RETURN 2 + 7102 ACC1 + 7103 PUSHACC1 + 7104 MAKEBLOCK2 0 + 7106 RETURN 2 + 7108 RESTART + 7109 GRAB 1 + 7111 ENVACC3 + 7112 GETFIELD0 + 7113 PUSHACC2 + 7114 PUSHACC2 + 7115 PUSHENVACC1 + 7116 GETFIELD1 + 7117 APPLY3 + 7118 PUSHENVACC3 + 7119 SETFIELD0 + 7120 ENVACC4 + 7121 GETFIELD0 + 7122 PUSHCONST0 + 7123 PUSHACC3 + 7124 PUSHENVACC2 + 7125 GETFIELD1 + 7126 APPLY3 + 7127 PUSHENVACC 4 + 7129 SETFIELD0 + 7130 RETURN 2 + 7132 ACC0 + 7133 PUSHENVACC 4 + 7135 PUSHENVACC3 + 7136 APPLY2 + 7137 PUSHENVACC 5 + 7139 GETFIELD0 + 7140 PUSHACC1 + 7141 PUSHACC3 + 7142 PUSHENVACC1 + 7143 GETFIELD1 + 7144 APPLY3 + 7145 PUSHENVACC 5 + 7147 SETFIELD0 + 7148 ENVACC 6 + 7150 GETFIELD0 + 7151 PUSH + 7152 PUSHTRAP 7163 + 7154 ENVACC4 + 7155 GETFIELD3 + 7156 PUSHACC6 + 7157 PUSHENVACC2 + 7158 GETFIELD2 + 7159 APPLY2 + 7160 POPTRAP + 7161 BRANCH 7177 + 7163 PUSHGETGLOBAL Not_found + 7165 PUSHACC1 + 7166 GETFIELD0 + 7167 EQ + 7168 BRANCHIFNOT 7173 + 7170 CONST1 + 7171 BRANCH 7175 + 7173 ACC0 + 7174 RAISE + 7175 POP 1 + 7177 PUSHACC2 + 7178 PUSHENVACC2 + 7179 GETFIELD1 + 7180 APPLY3 + 7181 PUSHENVACC 6 + 7183 SETFIELD0 + 7184 RETURN 2 + 7186 RESTART + 7187 GRAB 3 + 7189 ACC2 + 7190 PUSHACC1 + 7191 PUSHENVACC 4 + 7193 APPLY1 + 7194 PUSHGETGLOBALFIELD List, 10 + 7197 APPLY2 + 7198 PUSHACC1 + 7199 GETFIELD 4 + 7201 PUSHACC3 + 7202 PUSHACC2 + 7203 PUSHACC4 + 7204 GETFIELD 6 + 7206 PUSHACC5 + 7207 GETFIELD 5 + 7209 PUSHACC6 + 7210 GETFIELD3 + 7211 PUSHACC7 + 7212 GETFIELD2 + 7213 MAKEBLOCK 6, 0 + 7216 MAKEBLOCK2 0 + 7218 PUSHACC2 + 7219 SETFIELD 4 + 7221 ENVACC1 + 7222 GETFIELD0 + 7223 PUSHACC2 + 7224 SETFIELD 6 + 7226 ENVACC2 + 7227 GETFIELD0 + 7228 MAKEBLOCK1 0 + 7230 PUSHENVACC3 + 7231 GETFIELD0 + 7232 MAKEBLOCK1 0 + 7234 PUSHACC6 + 7235 PUSHACC1 + 7236 PUSHACC3 + 7237 PUSHACC6 + 7238 PUSHENVACC 4 + 7240 PUSHENVACC3 + 7241 PUSHENVACC2 + 7242 CLOSURE 6, 7132 + 7245 PUSHGETGLOBALFIELD List, 9 + 7248 APPLY2 + 7249 ACC2 + 7250 PUSHACC6 + 7251 PUSHACC2 + 7252 PUSHACC4 + 7253 PUSHENVACC3 + 7254 PUSHENVACC2 + 7255 CLOSURE 4, 7109 + 7258 PUSHGETGLOBALFIELD List, 14 + 7261 APPLY3 + 7262 ACC1 + 7263 GETFIELD0 + 7264 PUSHACC4 + 7265 SETFIELD2 + 7266 ACC0 + 7267 GETFIELD0 + 7268 PUSHACC4 + 7269 SETFIELD3 + 7270 CONST0 + 7271 PUSHACC4 + 7272 GETFIELD 5 + 7274 PUSHACC4 + 7275 CLOSURE 1, 7088 + 7278 PUSHGETGLOBALFIELD List, 13 + 7281 APPLY3 + 7282 PUSHACC4 + 7283 SETFIELD 5 + 7285 RETURN 7 + 7287 RESTART + 7288 GRAB 1 + 7290 PUSHTRAP 7303 + 7292 ACC4 + 7293 GETFIELD 5 + 7295 PUSHACC6 + 7296 PUSHGETGLOBALFIELD List, 29 + 7299 APPLY2 + 7300 POPTRAP + 7301 RETURN 2 + 7303 PUSHGETGLOBAL Not_found + 7305 PUSHACC1 + 7306 GETFIELD0 + 7307 EQ + 7308 BRANCHIFNOT 7325 + 7310 ACC2 + 7311 PUSHENVACC1 + 7312 APPLY1 + 7313 PUSHACC0 + 7314 GETFIELD1 + 7315 PUSHACC1 + 7316 GETFIELD0 + 7317 PUSHACC4 + 7318 GETFIELD1 + 7319 C_CALL2 array_get_addr + 7321 C_CALL2 array_get + 7323 RETURN 4 + 7325 ACC0 + 7326 RAISE + 7327 RESTART + 7328 GRAB 2 + 7330 ENVACC3 + 7331 OFFSETREF 1 + 7333 ACC0 + 7334 GETFIELD3 + 7335 PUSHACC2 + 7336 PUSHENVACC1 + 7337 GETFIELD2 + 7338 APPLY2 + 7339 BRANCHIFNOT 7347 + 7341 ACC2 + 7342 PUSHACC2 + 7343 PUSHACC2 + 7344 PUSHENVACC2 + 7345 APPTERM3 6 + 7347 ACC0 + 7348 GETFIELD 5 + 7350 PUSHACC3 + 7351 PUSHACC3 + 7352 MAKEBLOCK2 0 + 7354 MAKEBLOCK2 0 + 7356 PUSHACC1 + 7357 SETFIELD 5 + 7359 RETURN 3 + 7361 RESTART + 7362 GRAB 1 + 7364 PUSHTRAP 7375 + 7366 ACC4 + 7367 GETFIELD2 + 7368 PUSHACC6 + 7369 PUSHENVACC2 + 7370 GETFIELD2 + 7371 APPLY2 + 7372 POPTRAP + 7373 RETURN 2 + 7375 PUSHGETGLOBAL Not_found + 7377 PUSHACC1 + 7378 GETFIELD0 + 7379 EQ + 7380 BRANCHIFNOT 7406 + 7382 CONST0 + 7383 PUSHENVACC1 + 7384 APPLY1 + 7385 PUSHACC2 + 7386 GETFIELD2 + 7387 PUSHACC1 + 7388 PUSHACC5 + 7389 PUSHENVACC2 + 7390 GETFIELD1 + 7391 APPLY3 + 7392 PUSHACC3 + 7393 SETFIELD2 + 7394 ACC2 + 7395 GETFIELD3 + 7396 PUSHCONST1 + 7397 PUSHACC2 + 7398 PUSHENVACC3 + 7399 GETFIELD1 + 7400 APPLY3 + 7401 PUSHACC3 + 7402 SETFIELD3 + 7403 ACC0 + 7404 RETURN 4 + 7406 ACC0 + 7407 RAISE + 7408 RESTART + 7409 GRAB 2 + 7411 ACC1 + 7412 PUSHENVACC1 + 7413 APPLY1 + 7414 PUSHACC0 + 7415 GETFIELD0 + 7416 PUSHACC0 + 7417 OFFSETINT 1 + 7419 PUSHACC3 + 7420 PUSHENVACC 4 + 7422 APPLY2 + 7423 ACC0 + 7424 PUSHACC3 + 7425 GETFIELD1 + 7426 C_CALL2 array_get_addr + 7428 PUSHENVACC2 + 7429 PUSHACC1 + 7430 EQ + 7431 BRANCHIFNOT 7444 + 7433 CONST0 + 7434 PUSHENVACC3 + 7435 APPLY1 + 7436 ASSIGN 0 + 7438 ACC0 + 7439 PUSHACC2 + 7440 PUSHACC5 + 7441 GETFIELD1 + 7442 C_CALL3 array_set_addr + 7444 ACC5 + 7445 PUSHACC3 + 7446 GETFIELD1 + 7447 PUSHACC2 + 7448 C_CALL3 array_set + 7450 RETURN 6 + 7452 RESTART + 7453 GRAB 1 + 7455 ACC0 + 7456 GETFIELD1 + 7457 VECTLENGTH + 7458 PUSHACC0 + 7459 PUSHACC3 + 7460 GTINT + 7461 BRANCHIFNOT 7487 + 7463 ENVACC1 + 7464 PUSHACC3 + 7465 C_CALL2 make_vect + 7467 PUSH + 7468 PUSH_RETADDR 7482 + 7470 ACC4 + 7471 PUSHCONST0 + 7472 PUSHACC5 + 7473 PUSHCONST0 + 7474 PUSHACC 9 + 7476 GETFIELD1 + 7477 PUSHGETGLOBALFIELD Array, 8 + 7480 APPLY 5 + 7482 ACC0 + 7483 PUSHACC3 + 7484 SETFIELD1 + 7485 POP 1 + 7487 RETURN 3 + 7489 ENVACC 5 + 7491 OFFSETREF 1 + 7493 CONST0 + 7494 PUSHENVACC2 + 7495 GETFIELD0 + 7496 PUSHCONST0 + 7497 PUSHCONST0 + 7498 PUSHENVACC 4 + 7500 GETFIELD0 + 7501 PUSHENVACC3 + 7502 GETFIELD0 + 7503 PUSH + 7504 ATOM0 + 7505 PUSHENVACC1 + 7506 MAKEBLOCK 8, 0 + 7509 RETURN 1 + 7511 RESTART + 7512 GRAB 1 + 7514 ACC1 + 7515 PUSHACC1 + 7516 C_CALL2 compare + 7518 RETURN 2 + 7520 RESTART + 7521 GRAB 1 + 7523 ACC1 + 7524 PUSHACC1 + 7525 C_CALL2 compare + 7527 RETURN 2 + 7529 RESTART + 7530 GRAB 1 + 7532 ACC1 + 7533 PUSHACC1 + 7534 C_CALL2 compare + 7536 RETURN 2 + 7538 PUSHTRAP 7549 + 7540 ACC4 + 7541 PUSHENVACC1 + 7542 PUSHGETGLOBALFIELD Hashtbl, 3 + 7545 APPLY2 + 7546 POPTRAP + 7547 RETURN 1 + 7549 PUSHGETGLOBAL Not_found + 7551 PUSHACC1 + 7552 GETFIELD0 + 7553 EQ + 7554 BRANCHIFNOT 7569 + 7556 CONST0 + 7557 PUSHENVACC2 + 7558 APPLY1 + 7559 PUSHACC0 + 7560 PUSHACC3 + 7561 PUSHENVACC1 + 7562 PUSHGETGLOBALFIELD Hashtbl, 2 + 7565 APPLY3 + 7566 ACC0 + 7567 RETURN 3 + 7569 ACC0 + 7570 RAISE + 7571 ENVACC2 + 7572 GETFIELD0 + 7573 PUSHENVACC2 + 7574 GETFIELD0 + 7575 PUSHENVACC1 + 7576 APPLY1 + 7577 PUSHENVACC2 + 7578 SETFIELD0 + 7579 ACC0 + 7580 RETURN 2 + 7582 ENVACC1 + 7583 PUSHACC1 + 7584 VECTLENGTH + 7585 OFFSETINT -1 + 7587 PUSH + 7588 BRANCH 7606 + 7590 CHECK_SIGNALS + 7591 ACC1 + 7592 PUSHACC3 + 7593 C_CALL2 array_get_addr + 7595 PUSHENVACC2 + 7596 APPLY1 + 7597 PUSHACC2 + 7598 PUSHACC4 + 7599 C_CALL3 array_set_addr + 7601 ACC1 + 7602 OFFSETINT 1 + 7604 ASSIGN 1 + 7606 ACC0 + 7607 PUSHACC2 + 7608 LEINT + 7609 BRANCHIF 7590 + 7611 CONST0 + 7612 RETURN 3 + 7614 ENVACC4 + 7615 PUSHACC1 + 7616 NEQ + 7617 BRANCHIFNOT 7640 + 7619 ENVACC2 + 7620 GETFIELD0 + 7621 PUSHACC1 + 7622 PUSHENVACC3 + 7623 APPLY1 + 7624 EQ + 7625 BRANCHIFNOT 7640 + 7627 ACC0 + 7628 PUSHENVACC 5 + 7630 APPLY1 + 7631 BRANCHIFNOT 7640 + 7633 ENVACC1 + 7634 GETFIELD3 + 7635 PUSHACC1 + 7636 PUSHENVACC 6 + 7638 APPTERM2 3 + 7640 ACC0 + 7641 RETURN 1 + 7643 RESTART + 7644 GRAB 1 + 7646 CONST0 + 7647 PUSHENVACC1 + 7648 OFFSETINT -1 + 7650 PUSH + 7651 BRANCH 7690 + 7653 CHECK_SIGNALS + 7654 ENVACC2 + 7655 PUSHACC2 + 7656 PUSHACC5 + 7657 C_CALL2 array_get + 7659 NEQ + 7660 BRANCHIFNOT 7679 + 7662 ENVACC2 + 7663 PUSHACC2 + 7664 PUSHACC4 + 7665 C_CALL2 array_get + 7667 NEQ + 7668 BRANCHIFNOT 7679 + 7670 ACC1 + 7671 PUSHACC3 + 7672 C_CALL2 array_get + 7674 PUSHACC2 + 7675 PUSHACC5 + 7676 C_CALL2 array_get + 7678 NEQ + 7679 BRANCHIFNOT 7685 + 7681 ENVACC4 + 7682 MAKEBLOCK1 0 + 7684 RAISE + 7685 ACC1 + 7686 OFFSETINT 1 + 7688 ASSIGN 1 + 7690 ACC0 + 7691 PUSHACC2 + 7692 LEINT + 7693 BRANCHIF 7653 + 7695 CONST0 + 7696 POP 2 + 7698 CONST0 + 7699 PUSHENVACC1 + 7700 OFFSETINT -1 + 7702 PUSH + 7703 BRANCH 7727 + 7705 CHECK_SIGNALS + 7706 ENVACC2 + 7707 PUSHACC2 + 7708 PUSHACC5 + 7709 C_CALL2 array_get + 7711 NEQ + 7712 BRANCHIFNOT 7722 + 7714 ACC1 + 7715 PUSHACC4 + 7716 C_CALL2 array_get + 7718 PUSHACC2 + 7719 PUSHACC4 + 7720 C_CALL3 array_set + 7722 ACC1 + 7723 OFFSETINT 1 + 7725 ASSIGN 1 + 7727 ACC0 + 7728 PUSHACC2 + 7729 LEINT + 7730 BRANCHIF 7705 + 7732 CONST0 + 7733 POP 2 + 7735 ENVACC3 + 7736 GETFIELD0 + 7737 PUSHACC2 + 7738 PUSHENVACC 5 + 7740 APPLY2 + 7741 PUSHENVACC3 + 7742 SETFIELD0 + 7743 ACC0 + 7744 RETURN 2 + 7746 ENVACC1 + 7747 GETFIELD 4 + 7749 PUSHACC1 + 7750 PUSHENVACC2 + 7751 APPLY1 + 7752 LEINT + 7753 RETURN 1 + 7755 CONST0 + 7756 PUSHCONST0 + 7757 PUSHENVACC1 + 7758 OFFSETINT -1 + 7760 PUSH + 7761 BRANCH 7782 + 7763 CHECK_SIGNALS + 7764 ENVACC2 + 7765 PUSHACC2 + 7766 PUSHACC5 + 7767 C_CALL2 array_get + 7769 NEQ + 7770 BRANCHIFNOT 7777 + 7772 ACC2 + 7773 OFFSETINT 1 + 7775 ASSIGN 2 + 7777 ACC1 + 7778 OFFSETINT 1 + 7780 ASSIGN 1 + 7782 ACC0 + 7783 PUSHACC2 + 7784 LEINT + 7785 BRANCHIF 7763 + 7787 CONST0 + 7788 POP 2 + 7790 ACC0 + 7791 RETURN 2 + 7793 ENVACC2 + 7794 GETFIELD0 + 7795 OFFSETINT -1 + 7797 PUSHENVACC1 + 7798 GETFIELD0 + 7799 C_CALL2 array_get_addr + 7801 PUSHACC1 + 7802 PUSHENVACC1 + 7803 GETFIELD0 + 7804 C_CALL3 array_set_addr + 7806 ENVACC2 + 7807 OFFSETREF -1 + 7809 RETURN 1 + 7811 ENVACC1 + 7812 GETFIELD0 + 7813 VECTLENGTH + 7814 PUSHACC0 + 7815 PUSHENVACC2 + 7816 GETFIELD0 + 7817 GEINT + 7818 BRANCHIFNOT 7845 + 7820 ATOM0 + 7821 PUSHACC1 + 7822 PUSHCONST2 + 7823 MULINT + 7824 C_CALL2 make_vect + 7826 PUSH + 7827 PUSH_RETADDR 7840 + 7829 ACC4 + 7830 PUSHCONST0 + 7831 PUSHACC5 + 7832 PUSHCONST0 + 7833 PUSHENVACC1 + 7834 GETFIELD0 + 7835 PUSHGETGLOBALFIELD Array, 8 + 7838 APPLY 5 + 7840 ACC0 + 7841 PUSHENVACC1 + 7842 SETFIELD0 + 7843 POP 1 + 7845 ACC1 + 7846 PUSHENVACC2 + 7847 GETFIELD0 + 7848 PUSHENVACC1 + 7849 GETFIELD0 + 7850 C_CALL3 array_set_addr + 7852 ENVACC2 + 7853 OFFSETREF 1 + 7855 RETURN 2 + 7857 ACC0 + 7858 GETFIELD0 + 7859 PUSHENVACC1 + 7860 APPLY1 + 7861 PUSHENVACC2 + 7862 PUSHACC1 + 7863 GETFIELD0 + 7864 EQ + 7865 BRANCHIFNOT 7874 + 7867 ACC1 + 7868 GETFIELD1 + 7869 PUSHACC1 + 7870 GETFIELD1 + 7871 PUSHENVACC3 + 7872 C_CALL3 array_set + 7874 RETURN 2 + 7876 RESTART + 7877 GRAB 1 + 7879 CONST0 + 7880 PUSHENVACC2 + 7881 APPLY1 + 7882 PUSHACC2 + 7883 PUSHGETGLOBALFIELD List, 4 + 7886 APPLY1 + 7887 PUSHACC1 + 7888 PUSHACC3 + 7889 PUSHENVACC1 + 7890 CLOSURE 3, 7857 + 7893 PUSHGETGLOBALFIELD List, 9 + 7896 APPLY2 + 7897 ACC0 + 7898 RETURN 3 + 7900 ACC0 + 7901 PUSHGETGLOBALFIELD Array, 6 + 7904 APPLY1 + 7905 PUSHACC0 + 7906 PUSHENVACC3 + 7907 APPLY1 + 7908 ENVACC2 + 7909 GETFIELD0 + 7910 PUSHENVACC1 + 7911 PUSHACC2 + 7912 C_CALL3 array_set + 7914 ENVACC4 + 7915 GETFIELD0 + 7916 PUSHACC1 + 7917 MAKEBLOCK2 0 + 7919 PUSHENVACC 4 + 7921 SETFIELD0 + 7922 ACC0 + 7923 RETURN 2 + 7925 ENVACC2 + 7926 PUSHENVACC1 + 7927 OFFSETINT 1 + 7929 C_CALL2 make_vect + 7931 PUSHACC0 + 7932 PUSHENVACC3 + 7933 APPLY1 + 7934 ENVACC4 + 7935 GETFIELD0 + 7936 PUSHACC1 + 7937 MAKEBLOCK2 0 + 7939 PUSHENVACC 4 + 7941 SETFIELD0 + 7942 ACC0 + 7943 RETURN 2 + 7945 ENVACC1 + 7946 PUSHACC1 + 7947 C_CALL2 array_get + 7949 RETURN 1 + 7951 ENVACC2 + 7952 GETFIELD0 + 7953 PUSHENVACC1 + 7954 PUSHACC2 + 7955 C_CALL3 array_set + 7957 RETURN 1 + 7959 ENVACC1 + 7960 PUSHENVACC2 + 7961 PUSHENVACC1 + 7962 MULINT + 7963 PUSHACC2 + 7964 MODINT + 7965 DIVINT + 7966 PUSHENVACC1 + 7967 PUSHCONSTINT 65536 + 7969 PUSHACC3 + 7970 DIVINT + 7971 DIVINT + 7972 MAKEBLOCK2 0 + 7974 RETURN 1 + 7976 ENVACC3 + 7977 OFFSETREF 1 + 7979 ENVACC1 + 7980 PUSHACC1 + 7981 ADDINT + 7982 PUSHCONST0 + 7983 PUSHENVACC2 + 7984 PUSHENVACC1 + 7985 MULINT + 7986 PUSHACC2 + 7987 MODINT + 7988 EQ + 7989 BRANCHIFNOT 8001 + 7991 ENVACC2 + 7992 PUSHCONSTINT 65536 + 7994 SUBINT + 7995 PUSHENVACC1 + 7996 MULINT + 7997 PUSHACC1 + 7998 ADDINT + 7999 RETURN 2 + 8001 ACC0 + 8002 RETURN 2 + 8004 ACC0 + 8005 C_CALL1 obj_dup + 8007 PUSHENVACC1 + 8008 PUSHACC1 + 8009 PUSHENVACC2 + 8010 APPLY2 + 8011 ACC0 + 8012 RETURN 2 + 8014 RESTART + 8015 GRAB 1 + 8017 ACC1 + 8018 GETFIELD0 + 8019 PUSHACC0 + 8020 PUSHCONST1 + 8021 PUSHACC3 + 8022 SETVECTITEM + 8023 ACC0 + 8024 OFFSETINT 1 + 8026 PUSHACC3 + 8027 SETFIELD0 + 8028 RETURN 3 + 8030 ENVACC1 + 8031 GETFIELD0 + 8032 PUSHENVACC1 + 8033 OFFSETREF 1 + 8035 ACC0 + 8036 RETURN 2 + 8038 CONSTINT 248 + 8040 PUSHCONST0 + 8041 MAKEBLOCK1 0 + 8043 PUSHACC0 + 8044 CLOSURE 1, 8030 + 8047 PUSH + 8048 CLOSURE 0, 8015 + 8051 PUSHACC0 + 8052 PUSHACC3 + 8053 CLOSURE 2, 8004 + 8056 PUSHCONSTINT 16 + 8058 PUSHCONST3 + 8059 PUSHCONST1 + 8060 PUSHCONST1 + 8061 PUSHCONST1 + 8062 MAKEBLOCK 5, 0 + 8065 PUSHCONSTINT 16 + 8067 PUSHGETGLOBALFIELD Sys, 3 + 8070 DIVINT + 8071 PUSHCONST0 + 8072 PUSHCONSTINT 32 + 8074 PUSHCONST2 + 8075 PUSHCONST0 + 8076 MAKEBLOCK1 0 + 8078 PUSHACC0 + 8079 PUSHACC3 + 8080 PUSHACC6 + 8081 CLOSURE 3, 7976 + 8084 PUSHACC3 + 8085 PUSHACC6 + 8086 CLOSURE 2, 7959 + 8089 PUSHCONST0 + 8090 PUSHCONST0 + 8091 MAKEBLOCK1 0 + 8093 PUSHACC0 + 8094 PUSHACC7 + 8095 CLOSURE 2, 7951 + 8098 PUSHACC7 + 8099 CLOSURE 1, 7945 + 8102 PUSHCONST0 + 8103 MAKEBLOCK1 0 + 8105 PUSH + 8106 ATOM0 + 8107 PUSHACC1 + 8108 PUSHACC4 + 8109 PUSHACC7 + 8110 PUSHACC 13 + 8112 CLOSURE 4, 7925 + 8115 PUSHACC2 + 8116 PUSHACC5 + 8117 PUSHACC7 + 8118 PUSHACC 14 + 8120 CLOSURE 4, 7900 + 8123 PUSHACC1 + 8124 PUSHACC 9 + 8126 CLOSURE 2, 7877 + 8129 PUSH + 8130 ATOM0 + 8131 PUSHCONSTINT 10 + 8133 C_CALL2 make_vect + 8135 MAKEBLOCK1 0 + 8137 PUSHCONST0 + 8138 MAKEBLOCK1 0 + 8140 PUSHACC0 + 8141 PUSHACC2 + 8142 CLOSURE 2, 7811 + 8145 PUSHACC1 + 8146 PUSHACC3 + 8147 CLOSURE 2, 7793 + 8150 PUSHACC 12 + 8152 PUSHACC 18 + 8154 CLOSURE 2, 7755 + 8157 PUSHACC0 + 8158 PUSHACC 22 + 8160 CLOSURE 2, 7746 + 8163 PUSHGETGLOBAL "Oo.Failed" + 8165 MAKEBLOCK1 0 + 8167 PUSH + 8168 CLOSUREREC 0, 6415 + 8172 ACC0 + 8173 PUSHACC2 + 8174 PUSHACC 14 + 8176 PUSHACC 19 + 8178 PUSHACC 25 + 8180 CLOSURE 5, 7644 + 8183 PUSHACC0 + 8184 PUSHACC3 + 8185 PUSHACC5 + 8186 PUSHACC 8 + 8188 PUSHACC 10 + 8190 PUSHACC 12 + 8192 PUSHACC 14 + 8194 CLOSUREREC 7, 6444 + 8198 ACC0 + 8199 PUSHACC5 + 8200 PUSHACC 15 + 8202 PUSHACC 18 + 8204 PUSHACC 21 + 8206 PUSHACC 31 + 8208 CLOSURE 6, 7614 + 8211 PUSHACC0 + 8212 PUSHACC 26 + 8214 CLOSURE 2, 7582 + 8217 PUSHACC 27 + 8219 PUSHCONSTINT 65536 + 8221 PUSHACC 28 + 8223 MULINT + 8224 MULINT + 8225 PUSHACC0 + 8226 MAKEBLOCK1 0 + 8228 PUSHCONSTINT 101 + 8230 PUSHGETGLOBALFIELD Hashtbl, 0 + 8233 APPLY1 + 8234 PUSHACC1 + 8235 PUSHACC 26 + 8237 CLOSURE 2, 7571 + 8240 PUSHACC0 + 8241 PUSHACC2 + 8242 CLOSURE 2, 7538 + 8245 PUSH + 8246 CLOSURE 0, 7530 + 8249 PUSHACC0 + 8250 MAKEBLOCK1 0 + 8252 POP 1 + 8254 PUSHGETGLOBALFIELD Map, 0 + 8257 APPLY1 + 8258 PUSH + 8259 CLOSURE 0, 7521 + 8262 PUSHACC0 + 8263 MAKEBLOCK1 0 + 8265 POP 1 + 8267 PUSHGETGLOBALFIELD Map, 0 + 8270 APPLY1 + 8271 PUSH + 8272 CLOSURE 0, 7512 + 8275 PUSHACC0 + 8276 MAKEBLOCK1 0 + 8278 POP 1 + 8280 PUSHGETGLOBALFIELD Map, 0 + 8283 APPLY1 + 8284 PUSHCONST0 + 8285 MAKEBLOCK1 0 + 8287 PUSHACC0 + 8288 PUSHACC2 + 8289 PUSHACC4 + 8290 PUSHACC6 + 8291 PUSHACC 37 + 8293 CLOSURE 5, 7489 + 8296 PUSHACC 25 + 8298 CLOSURE 1, 7453 + 8301 PUSHACC0 + 8302 PUSHACC 26 + 8304 PUSHACC 28 + 8306 PUSHACC 35 + 8308 CLOSURE 4, 7409 + 8311 PUSHCONST0 + 8312 MAKEBLOCK1 0 + 8314 PUSHCONST0 + 8315 MAKEBLOCK1 0 + 8317 PUSHACC6 + 8318 PUSHACC 8 + 8320 PUSHACC 12 + 8322 CLOSURE 3, 7362 + 8325 PUSHACC2 + 8326 PUSHACC4 + 8327 PUSHACC 9 + 8329 CLOSURE 3, 7328 + 8332 PUSHACC 37 + 8334 CLOSURE 1, 7288 + 8337 PUSHACC2 + 8338 PUSHACC 10 + 8340 PUSHACC 12 + 8342 PUSHACC 14 + 8344 CLOSURE 4, 7187 + 8347 PUSHACC 12 + 8349 CLOSURE 1, 7027 + 8352 PUSH + 8353 CLOSURE 0, 6980 + 8356 PUSH + 8357 CLOSURE 0, 6969 + 8360 PUSHACC0 + 8361 PUSHACC 16 + 8363 CLOSURE 2, 6950 + 8366 PUSHACC 16 + 8368 CLOSURE 1, 6939 + 8371 PUSHACC 47 + 8373 CLOSURE 1, 6927 + 8376 PUSH + 8377 CLOSURE 0, 6862 + 8380 PUSHACC 15 + 8382 PUSHACC 18 + 8384 PUSHACC 20 + 8386 PUSHACC 23 + 8388 CLOSURE 4, 6842 + 8391 PUSHACC 12 + 8393 PUSHACC 27 + 8395 PUSHACC 56 + 8397 CLOSURE 3, 6787 + 8400 PUSHACC 57 + 8402 PUSHACC 60 + 8404 PUSHACC 62 + 8406 CLOSURE 3, 6769 + 8409 PUSH + 8410 CLOSUREREC 0, 6519 + 8414 ACC0 + 8415 CLOSURE 1, 6752 + 8418 PUSHACC0 + 8419 PUSHACC 61 + 8421 PUSHACC 64 + 8423 CLOSURE 3, 6735 + 8426 PUSHACC 52 + 8428 CLOSURE 1, 6715 + 8431 PUSHACC 39 + 8433 PUSHACC 49 + 8435 CLOSURE 2, 6695 + 8438 PUSHACC0 + 8439 PUSHACC 20 + 8441 PUSHACC 22 + 8443 PUSHACC 27 + 8445 PUSHACC 47 + 8447 PUSHACC 49 + 8449 PUSHACC 55 + 8451 PUSHACC 63 + 8453 CLOSURE 8, 6644 + 8456 PUSHACC 41 + 8458 CLOSURE 1, 6618 + 8461 PUSHACC0 + 8462 PUSHACC 52 + 8464 PUSHACC 57 + 8466 PUSHACC 63 + 8468 CLOSURE 4, 6581 + 8471 PUSHACC0 + 8472 PUSHACC3 + 8473 PUSHACC 66 + 8475 PUSHACC7 + 8476 PUSHACC 9 + 8478 PUSHACC 11 + 8480 PUSHACC 14 + 8482 PUSHACC 16 + 8484 PUSHACC 18 + 8486 PUSHACC 20 + 8488 PUSHACC 27 + 8490 PUSHACC 29 + 8492 PUSHACC 32 + 8494 PUSHACC 32 + 8496 PUSHACC 35 + 8498 PUSHACC 27 + 8500 PUSHACC 29 + 8502 PUSHACC 31 + 8504 PUSHACC 34 + 8506 PUSHACC 50 + 8508 PUSHACC 85 + 8510 MAKEBLOCK 21, 0 + 8513 POP 70 + 8515 SETGLOBAL Oo + 8517 BRANCH 8568 + 8519 ACC0 + 8520 BRANCHIFNOT 8525 + 8522 ACC0 + 8523 BRANCH 8530 + 8525 ENVACC1 + 8526 PUSHGETGLOBALFIELD Oo, 14 + 8529 APPLY1 + 8530 PUSHCONST0 + 8531 ACC1 + 8532 BRANCHIFNOT 8537 + 8534 CONST0 + 8535 BRANCH 8543 + 8537 ENVACC1 + 8538 PUSHACC1 + 8539 PUSHGETGLOBALFIELD Oo, 15 + 8542 APPLY2 + 8543 ACC0 + 8544 RETURN 2 + 8546 CONSTINT 23 + 8548 RETURN 1 + 8550 CLOSURE 0, 8546 + 8553 PUSHACC0 + 8554 POP 1 + 8556 PUSHENVACC1 + 8557 PUSHACC2 + 8558 PUSHGETGLOBALFIELD Oo, 8 + 8561 APPLY3 + 8562 ACC0 + 8563 CLOSURE 1, 8519 + 8566 RETURN 1 + 8568 GETGLOBALFIELD Oo, 1 + 8571 PUSHGETGLOBAL "m" + 8573 PUSHACC1 + 8574 APPLY1 + 8575 PUSHCONST3 + 8576 C_CALL1 alloc_dummy + 8578 PUSHGETGLOBAL <0>("m", 0) + 8580 PUSHGETGLOBALFIELD Oo, 12 + 8583 APPLY1 + 8584 PUSHACC2 + 8585 CLOSURE 1, 8550 + 8588 PUSHACC1 + 8589 PUSHACC1 + 8590 APPLY1 + 8591 PUSHACC2 + 8592 PUSHGETGLOBALFIELD Oo, 13 + 8595 APPLY1 + 8596 ACC2 + 8597 PUSHACC2 + 8598 PUSHACC2 + 8599 MAKEBLOCK3 0 + 8601 POP 3 + 8603 PUSHACC1 + 8604 C_CALL2 update_dummy + 8606 CONST0 + 8607 PUSHACC1 + 8608 GETFIELD0 + 8609 APPLY1 + 8610 PUSHCONSTINT 23 + 8612 PUSHACC1 + 8613 PUSHACC4 + 8614 GETMETHOD + 8615 APPLY1 + 8616 NEQ + 8617 BRANCHIFNOT 8624 + 8619 GETGLOBAL Not_found + 8621 MAKEBLOCK1 0 + 8623 RAISE + 8624 POP 1 + 8626 ACC0 + 8627 MAKEBLOCK1 0 + 8629 POP 3 + 8631 SETGLOBAL T300-getmethod + 8633 STOP +**) diff --git a/test/testinterp/t301-object.ml b/test/testinterp/t301-object.ml new file mode 100644 index 0000000..572b807 --- /dev/null +++ b/test/testinterp/t301-object.ml @@ -0,0 +1,29 @@ +(**** file testinterp/t301-object.ml + suggested by Jacques Garrigue to Basile Starynkevitch + + compilable with +ocamlc -nostdlib -I ../../stdlib \ + ../../stdlib/pervasives.cmo ../../stdlib/camlinternalOO.cmo \ + t301-object.ml -o t301-object.byte + +***) +(* $Id: t301-object.ml,v 1.2 2004-06-02 09:42:01 basile Exp $ *) + + +class c = object (self) + method pubmet = 1 + method privmet = self#pubmet + 1 + val o = object method a = 3 method m = 4 end + method dynmet = o#m +end;; + +let f () = + let c = new c in + (c#pubmet, c#privmet, c#dynmet);; + +let (x,y,z) = f () in + if x <> 1 then raise Not_found; + if y <> 2 then raise Not_found; + if z <> 4 then raise Not_found;; + +(**** eof $Id: t301-object.ml,v 1.2 2004-06-02 09:42:01 basile Exp $ *) diff --git a/test/testinterp/t310-alloc-1.ml b/test/testinterp/t310-alloc-1.ml new file mode 100644 index 0000000..c438cc9 --- /dev/null +++ b/test/testinterp/t310-alloc-1.ml @@ -0,0 +1,1587 @@ +open Lib;; +let rec f a n = + if n <= 0 then a + else f (1::a) (n-1) +in +let l = f [] 30000 in +if List.fold_left (+) 0 l <> 30000 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2435 + 2406 RESTART + 2407 GRAB 1 + 2409 CONST0 + 2410 PUSHACC2 + 2411 LEINT + 2412 BRANCHIFNOT 2417 + 2414 ACC0 + 2415 RETURN 2 + 2417 ACC1 + 2418 OFFSETINT -1 + 2420 PUSHACC1 + 2421 PUSHCONST1 + 2422 MAKEBLOCK2 0 + 2424 PUSHOFFSETCLOSURE0 + 2425 APPTERM2 4 + 2427 RESTART + 2428 GRAB 1 + 2430 ACC1 + 2431 PUSHACC1 + 2432 ADDINT + 2433 RETURN 2 + 2435 CLOSUREREC 0, 2407 + 2439 CONSTINT 30000 + 2441 PUSHCONST0 + 2442 PUSHACC2 + 2443 APPLY2 + 2444 PUSHCONSTINT 30000 + 2446 PUSHACC1 + 2447 PUSHCONST0 + 2448 PUSH + 2449 CLOSURE 0, 2428 + 2452 PUSHGETGLOBALFIELD List, 12 + 2455 APPLY3 + 2456 NEQ + 2457 BRANCHIFNOT 2464 + 2459 GETGLOBAL Not_found + 2461 MAKEBLOCK1 0 + 2463 RAISE + 2464 POP 2 + 2466 ATOM0 + 2467 SETGLOBAL T310-alloc-1 + 2469 STOP +**) diff --git a/test/testinterp/t310-alloc-2.ml b/test/testinterp/t310-alloc-2.ml new file mode 100644 index 0000000..81034e7 --- /dev/null +++ b/test/testinterp/t310-alloc-2.ml @@ -0,0 +1,2313 @@ +open Lib;; +let v = Array.make 200000 2 in +let t = ref 0 in +Array.iter (fun x -> t := !t + x) v; +if !t <> 400000 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 3341 + 2406 RESTART + 2407 GRAB 2 + 2409 ACC2 + 2410 PUSHACC2 + 2411 VECTLENGTH + 2412 OFFSETINT -1 + 2414 PUSHCONST0 + 2415 PUSH + 2416 BRANCH 2433 + 2418 CHECK_SIGNALS + 2419 ACC2 + 2420 PUSHACC2 + 2421 PUSHACC6 + 2422 C_CALL2 array_unsafe_get + 2424 PUSHACC5 + 2425 APPLY2 + 2426 ASSIGN 2 + 2428 ACC1 + 2429 OFFSETINT -1 + 2431 ASSIGN 1 + 2433 ACC0 + 2434 PUSHACC2 + 2435 GEINT + 2436 BRANCHIF 2418 + 2438 CONST0 + 2439 POP 2 + 2441 ACC0 + 2442 RETURN 4 + 2444 RESTART + 2445 GRAB 2 + 2447 ACC1 + 2448 PUSHCONST0 + 2449 PUSHACC4 + 2450 VECTLENGTH + 2451 OFFSETINT -1 + 2453 PUSH + 2454 BRANCH 2471 + 2456 CHECK_SIGNALS + 2457 ACC1 + 2458 PUSHACC6 + 2459 C_CALL2 array_unsafe_get + 2461 PUSHACC3 + 2462 PUSHACC5 + 2463 APPLY2 + 2464 ASSIGN 2 + 2466 ACC1 + 2467 OFFSETINT 1 + 2469 ASSIGN 1 + 2471 ACC0 + 2472 PUSHACC2 + 2473 LEINT + 2474 BRANCHIF 2456 + 2476 CONST0 + 2477 POP 2 + 2479 ACC0 + 2480 RETURN 4 + 2482 RESTART + 2483 GRAB 1 + 2485 ACC1 + 2486 BRANCHIFNOT 2502 + 2488 ACC1 + 2489 GETFIELD0 + 2490 PUSHACC1 + 2491 PUSHENVACC1 + 2492 C_CALL3 array_unsafe_set + 2494 ACC1 + 2495 GETFIELD1 + 2496 PUSHACC1 + 2497 OFFSETINT 1 + 2499 PUSHOFFSETCLOSURE0 + 2500 APPTERM2 4 + 2502 ENVACC1 + 2503 RETURN 2 + 2505 ACC0 + 2506 BRANCHIFNOT 2531 + 2508 ACC0 + 2509 GETFIELD1 + 2510 PUSHACC1 + 2511 GETFIELD0 + 2512 PUSHACC1 + 2513 PUSHGETGLOBALFIELD List, 0 + 2516 APPLY1 + 2517 OFFSETINT 1 + 2519 C_CALL2 make_vect + 2521 PUSHACC0 + 2522 CLOSUREREC 1, 2483 + 2526 ACC2 + 2527 PUSHCONST1 + 2528 PUSHACC2 + 2529 APPTERM2 6 + 2531 ATOM0 + 2532 RETURN 1 + 2534 RESTART + 2535 GRAB 1 + 2537 CONST0 + 2538 PUSHACC1 + 2539 LTINT + 2540 BRANCHIFNOT 2545 + 2542 ACC1 + 2543 RETURN 2 + 2545 ACC1 + 2546 PUSHACC1 + 2547 PUSHENVACC1 + 2548 C_CALL2 array_unsafe_get + 2550 MAKEBLOCK2 0 + 2552 PUSHACC1 + 2553 OFFSETINT -1 + 2555 PUSHOFFSETCLOSURE0 + 2556 APPTERM2 4 + 2558 ACC0 + 2559 CLOSUREREC 1, 2535 + 2563 CONST0 + 2564 PUSHACC2 + 2565 VECTLENGTH + 2566 OFFSETINT -1 + 2568 PUSHACC2 + 2569 APPTERM2 4 + 2571 RESTART + 2572 GRAB 1 + 2574 ACC1 + 2575 VECTLENGTH + 2576 PUSHCONST0 + 2577 PUSHACC1 + 2578 EQ + 2579 BRANCHIFNOT 2584 + 2581 ATOM0 + 2582 RETURN 3 + 2584 CONST0 + 2585 PUSHACC3 + 2586 C_CALL2 array_unsafe_get + 2588 PUSHCONST0 + 2589 PUSHACC3 + 2590 APPLY2 + 2591 PUSHACC1 + 2592 C_CALL2 make_vect + 2594 PUSHCONST1 + 2595 PUSHACC2 + 2596 OFFSETINT -1 + 2598 PUSH + 2599 BRANCH 2618 + 2601 CHECK_SIGNALS + 2602 ACC1 + 2603 PUSHACC6 + 2604 C_CALL2 array_unsafe_get + 2606 PUSHACC2 + 2607 PUSHACC6 + 2608 APPLY2 + 2609 PUSHACC2 + 2610 PUSHACC4 + 2611 C_CALL3 array_unsafe_set + 2613 ACC1 + 2614 OFFSETINT 1 + 2616 ASSIGN 1 + 2618 ACC0 + 2619 PUSHACC2 + 2620 LEINT + 2621 BRANCHIF 2601 + 2623 CONST0 + 2624 POP 2 + 2626 ACC0 + 2627 RETURN 4 + 2629 RESTART + 2630 GRAB 1 + 2632 CONST0 + 2633 PUSHACC2 + 2634 VECTLENGTH + 2635 OFFSETINT -1 + 2637 PUSH + 2638 BRANCH 2653 + 2640 CHECK_SIGNALS + 2641 ACC1 + 2642 PUSHACC4 + 2643 C_CALL2 array_unsafe_get + 2645 PUSHACC2 + 2646 PUSHACC4 + 2647 APPLY2 + 2648 ACC1 + 2649 OFFSETINT 1 + 2651 ASSIGN 1 + 2653 ACC0 + 2654 PUSHACC2 + 2655 LEINT + 2656 BRANCHIF 2640 + 2658 CONST0 + 2659 RETURN 4 + 2661 RESTART + 2662 GRAB 1 + 2664 ACC1 + 2665 VECTLENGTH + 2666 PUSHCONST0 + 2667 PUSHACC1 + 2668 EQ + 2669 BRANCHIFNOT 2674 + 2671 ATOM0 + 2672 RETURN 3 + 2674 CONST0 + 2675 PUSHACC3 + 2676 C_CALL2 array_unsafe_get + 2678 PUSHACC2 + 2679 APPLY1 + 2680 PUSHACC1 + 2681 C_CALL2 make_vect + 2683 PUSHCONST1 + 2684 PUSHACC2 + 2685 OFFSETINT -1 + 2687 PUSH + 2688 BRANCH 2706 + 2690 CHECK_SIGNALS + 2691 ACC1 + 2692 PUSHACC6 + 2693 C_CALL2 array_unsafe_get + 2695 PUSHACC5 + 2696 APPLY1 + 2697 PUSHACC2 + 2698 PUSHACC4 + 2699 C_CALL3 array_unsafe_set + 2701 ACC1 + 2702 OFFSETINT 1 + 2704 ASSIGN 1 + 2706 ACC0 + 2707 PUSHACC2 + 2708 LEINT + 2709 BRANCHIF 2690 + 2711 CONST0 + 2712 POP 2 + 2714 ACC0 + 2715 RETURN 4 + 2717 RESTART + 2718 GRAB 1 + 2720 CONST0 + 2721 PUSHACC2 + 2722 VECTLENGTH + 2723 OFFSETINT -1 + 2725 PUSH + 2726 BRANCH 2740 + 2728 CHECK_SIGNALS + 2729 ACC1 + 2730 PUSHACC4 + 2731 C_CALL2 array_unsafe_get + 2733 PUSHACC3 + 2734 APPLY1 + 2735 ACC1 + 2736 OFFSETINT 1 + 2738 ASSIGN 1 + 2740 ACC0 + 2741 PUSHACC2 + 2742 LEINT + 2743 BRANCHIF 2728 + 2745 CONST0 + 2746 RETURN 4 + 2748 RESTART + 2749 GRAB 4 + 2751 CONST0 + 2752 PUSHACC5 + 2753 LTINT + 2754 BRANCHIF 2782 + 2756 CONST0 + 2757 PUSHACC2 + 2758 LTINT + 2759 BRANCHIF 2782 + 2761 ACC0 + 2762 VECTLENGTH + 2763 PUSHACC5 + 2764 PUSHACC3 + 2765 ADDINT + 2766 GTINT + 2767 BRANCHIF 2782 + 2769 CONST0 + 2770 PUSHACC4 + 2771 LTINT + 2772 BRANCHIF 2782 + 2774 ACC2 + 2775 VECTLENGTH + 2776 PUSHACC5 + 2777 PUSHACC5 + 2778 ADDINT + 2779 GTINT + 2780 BRANCHIFNOT 2789 + 2782 GETGLOBAL "Array.blit" + 2784 PUSHGETGLOBALFIELD Pervasives, 2 + 2787 APPTERM1 6 + 2789 ACC3 + 2790 PUSHACC2 + 2791 LTINT + 2792 BRANCHIFNOT 2827 + 2794 ACC4 + 2795 OFFSETINT -1 + 2797 PUSHCONST0 + 2798 PUSH + 2799 BRANCH 2819 + 2801 CHECK_SIGNALS + 2802 ACC1 + 2803 PUSHACC4 + 2804 ADDINT + 2805 PUSHACC3 + 2806 C_CALL2 array_unsafe_get + 2808 PUSHACC2 + 2809 PUSHACC7 + 2810 ADDINT + 2811 PUSHACC6 + 2812 C_CALL3 array_unsafe_set + 2814 ACC1 + 2815 OFFSETINT -1 + 2817 ASSIGN 1 + 2819 ACC0 + 2820 PUSHACC2 + 2821 GEINT + 2822 BRANCHIF 2801 + 2824 CONST0 + 2825 RETURN 7 + 2827 CONST0 + 2828 PUSHACC5 + 2829 OFFSETINT -1 + 2831 PUSH + 2832 BRANCH 2852 + 2834 CHECK_SIGNALS + 2835 ACC1 + 2836 PUSHACC4 + 2837 ADDINT + 2838 PUSHACC3 + 2839 C_CALL2 array_unsafe_get + 2841 PUSHACC2 + 2842 PUSHACC7 + 2843 ADDINT + 2844 PUSHACC6 + 2845 C_CALL3 array_unsafe_set + 2847 ACC1 + 2848 OFFSETINT 1 + 2850 ASSIGN 1 + 2852 ACC0 + 2853 PUSHACC2 + 2854 LEINT + 2855 BRANCHIF 2834 + 2857 CONST0 + 2858 RETURN 7 + 2860 RESTART + 2861 GRAB 3 + 2863 CONST0 + 2864 PUSHACC2 + 2865 LTINT + 2866 BRANCHIF 2881 + 2868 CONST0 + 2869 PUSHACC3 + 2870 LTINT + 2871 BRANCHIF 2881 + 2873 ACC0 + 2874 VECTLENGTH + 2875 PUSHACC3 + 2876 PUSHACC3 + 2877 ADDINT + 2878 GTINT + 2879 BRANCHIFNOT 2888 + 2881 GETGLOBAL "Array.fill" + 2883 PUSHGETGLOBALFIELD Pervasives, 2 + 2886 APPTERM1 5 + 2888 ACC1 + 2889 PUSHACC3 + 2890 PUSHACC3 + 2891 ADDINT + 2892 OFFSETINT -1 + 2894 PUSH + 2895 BRANCH 2908 + 2897 CHECK_SIGNALS + 2898 ACC5 + 2899 PUSHACC2 + 2900 PUSHACC4 + 2901 C_CALL3 array_unsafe_set + 2903 ACC1 + 2904 OFFSETINT 1 + 2906 ASSIGN 1 + 2908 ACC0 + 2909 PUSHACC2 + 2910 LEINT + 2911 BRANCHIF 2897 + 2913 CONST0 + 2914 RETURN 6 + 2916 RESTART + 2917 GRAB 2 + 2919 CONST0 + 2920 PUSHACC2 + 2921 LTINT + 2922 BRANCHIF 2937 + 2924 CONST0 + 2925 PUSHACC3 + 2926 LTINT + 2927 BRANCHIF 2937 + 2929 ACC0 + 2930 VECTLENGTH + 2931 PUSHACC3 + 2932 PUSHACC3 + 2933 ADDINT + 2934 GTINT + 2935 BRANCHIFNOT 2944 + 2937 GETGLOBAL "Array.sub" + 2939 PUSHGETGLOBALFIELD Pervasives, 2 + 2942 APPTERM1 4 + 2944 CONST0 + 2945 PUSHACC3 + 2946 EQ + 2947 BRANCHIFNOT 2952 + 2949 ATOM0 + 2950 RETURN 3 + 2952 ACC1 + 2953 PUSHACC1 + 2954 C_CALL2 array_unsafe_get + 2956 PUSHACC3 + 2957 C_CALL2 make_vect + 2959 PUSHCONST1 + 2960 PUSHACC4 + 2961 OFFSETINT -1 + 2963 PUSH + 2964 BRANCH 2982 + 2966 CHECK_SIGNALS + 2967 ACC1 + 2968 PUSHACC5 + 2969 ADDINT + 2970 PUSHACC4 + 2971 C_CALL2 array_unsafe_get + 2973 PUSHACC2 + 2974 PUSHACC4 + 2975 C_CALL3 array_unsafe_set + 2977 ACC1 + 2978 OFFSETINT 1 + 2980 ASSIGN 1 + 2982 ACC0 + 2983 PUSHACC2 + 2984 LEINT + 2985 BRANCHIF 2966 + 2987 CONST0 + 2988 POP 2 + 2990 ACC0 + 2991 RETURN 4 + 2993 ACC0 + 2994 BRANCHIFNOT 3017 + 2996 ACC0 + 2997 GETFIELD0 + 2998 PUSHCONST0 + 2999 PUSHACC1 + 3000 VECTLENGTH + 3001 GTINT + 3002 BRANCHIFNOT 3012 + 3004 ENVACC2 + 3005 PUSHCONST0 + 3006 PUSHACC2 + 3007 C_CALL2 array_unsafe_get + 3009 PUSHENVACC1 + 3010 APPTERM2 4 + 3012 ACC1 + 3013 GETFIELD1 + 3014 PUSHOFFSETCLOSURE0 + 3015 APPTERM1 3 + 3017 ATOM0 + 3018 RETURN 1 + 3020 ACC0 + 3021 PUSHENVACC1 + 3022 CLOSUREREC 2, 2993 + 3026 ACC1 + 3027 PUSHACC1 + 3028 APPTERM1 3 + 3030 CONST0 + 3031 PUSHACC1 + 3032 VECTLENGTH + 3033 OFFSETINT -1 + 3035 PUSH + 3036 BRANCH 3056 + 3038 CHECK_SIGNALS + 3039 ACC1 + 3040 PUSHACC3 + 3041 C_CALL2 array_unsafe_get + 3043 PUSHENVACC2 + 3044 GETFIELD0 + 3045 PUSHENVACC1 + 3046 C_CALL3 array_unsafe_set + 3048 ENVACC2 + 3049 OFFSETREF 1 + 3051 ACC1 + 3052 OFFSETINT 1 + 3054 ASSIGN 1 + 3056 ACC0 + 3057 PUSHACC2 + 3058 LEINT + 3059 BRANCHIF 3038 + 3061 CONST0 + 3062 RETURN 3 + 3064 RESTART + 3065 GRAB 1 + 3067 ACC1 + 3068 VECTLENGTH + 3069 PUSHACC1 + 3070 ADDINT + 3071 RETURN 2 + 3073 RESTART + 3074 GRAB 1 + 3076 ACC1 + 3077 PUSHCONST0 + 3078 PUSH + 3079 CLOSURE 0, 3065 + 3082 PUSHGETGLOBALFIELD List, 12 + 3085 APPLY3 + 3086 PUSHACC1 + 3087 PUSHACC1 + 3088 C_CALL2 make_vect + 3090 PUSHCONST0 + 3091 MAKEBLOCK1 0 + 3093 PUSHACC4 + 3094 PUSHACC1 + 3095 PUSHACC3 + 3096 CLOSURE 2, 3030 + 3099 PUSHGETGLOBALFIELD List, 9 + 3102 APPLY2 + 3103 ACC1 + 3104 RETURN 5 + 3106 RESTART + 3107 GRAB 1 + 3109 ACC0 + 3110 VECTLENGTH + 3111 PUSHACC2 + 3112 VECTLENGTH + 3113 PUSHCONST0 + 3114 PUSHACC2 + 3115 EQ + 3116 BRANCHIFNOT 3126 + 3118 CONST0 + 3119 PUSHACC1 + 3120 EQ + 3121 BRANCHIFNOT 3126 + 3123 ATOM0 + 3124 RETURN 4 + 3126 CONST0 + 3127 PUSHCONST0 + 3128 PUSHACC3 + 3129 GTINT + 3130 BRANCHIFNOT 3135 + 3132 ACC3 + 3133 BRANCH 3136 + 3135 ACC4 + 3136 C_CALL2 array_unsafe_get + 3138 PUSHACC1 + 3139 PUSHACC3 + 3140 ADDINT + 3141 C_CALL2 make_vect + 3143 PUSHCONST0 + 3144 PUSHACC3 + 3145 OFFSETINT -1 + 3147 PUSH + 3148 BRANCH 3164 + 3150 CHECK_SIGNALS + 3151 ACC1 + 3152 PUSHACC6 + 3153 C_CALL2 array_unsafe_get + 3155 PUSHACC2 + 3156 PUSHACC4 + 3157 C_CALL3 array_unsafe_set + 3159 ACC1 + 3160 OFFSETINT 1 + 3162 ASSIGN 1 + 3164 ACC0 + 3165 PUSHACC2 + 3166 LEINT + 3167 BRANCHIF 3150 + 3169 CONST0 + 3170 POP 2 + 3172 CONST0 + 3173 PUSHACC2 + 3174 OFFSETINT -1 + 3176 PUSH + 3177 BRANCH 3195 + 3179 CHECK_SIGNALS + 3180 ACC1 + 3181 PUSHACC7 + 3182 C_CALL2 array_unsafe_get + 3184 PUSHACC5 + 3185 PUSHACC3 + 3186 ADDINT + 3187 PUSHACC4 + 3188 C_CALL3 array_unsafe_set + 3190 ACC1 + 3191 OFFSETINT 1 + 3193 ASSIGN 1 + 3195 ACC0 + 3196 PUSHACC2 + 3197 LEINT + 3198 BRANCHIF 3179 + 3200 CONST0 + 3201 POP 2 + 3203 ACC0 + 3204 RETURN 5 + 3206 ACC0 + 3207 VECTLENGTH + 3208 PUSHCONST0 + 3209 PUSHACC1 + 3210 EQ + 3211 BRANCHIFNOT 3216 + 3213 ATOM0 + 3214 RETURN 2 + 3216 CONST0 + 3217 PUSHACC2 + 3218 C_CALL2 array_unsafe_get + 3220 PUSHACC1 + 3221 C_CALL2 make_vect + 3223 PUSHCONST1 + 3224 PUSHACC2 + 3225 OFFSETINT -1 + 3227 PUSH + 3228 BRANCH 3244 + 3230 CHECK_SIGNALS + 3231 ACC1 + 3232 PUSHACC5 + 3233 C_CALL2 array_unsafe_get + 3235 PUSHACC2 + 3236 PUSHACC4 + 3237 C_CALL3 array_unsafe_set + 3239 ACC1 + 3240 OFFSETINT 1 + 3242 ASSIGN 1 + 3244 ACC0 + 3245 PUSHACC2 + 3246 LEINT + 3247 BRANCHIF 3230 + 3249 CONST0 + 3250 POP 2 + 3252 ACC0 + 3253 RETURN 3 + 3255 RESTART + 3256 GRAB 2 + 3258 ATOM0 + 3259 PUSHACC1 + 3260 C_CALL2 make_vect + 3262 PUSHCONST0 + 3263 PUSHACC2 + 3264 OFFSETINT -1 + 3266 PUSH + 3267 BRANCH 3282 + 3269 CHECK_SIGNALS + 3270 ACC5 + 3271 PUSHACC5 + 3272 C_CALL2 make_vect + 3274 PUSHACC2 + 3275 PUSHACC4 + 3276 SETVECTITEM + 3277 ACC1 + 3278 OFFSETINT 1 + 3280 ASSIGN 1 + 3282 ACC0 + 3283 PUSHACC2 + 3284 LEINT + 3285 BRANCHIF 3269 + 3287 CONST0 + 3288 POP 2 + 3290 ACC0 + 3291 RETURN 4 + 3293 RESTART + 3294 GRAB 1 + 3296 CONST0 + 3297 PUSHACC1 + 3298 EQ + 3299 BRANCHIFNOT 3304 + 3301 ATOM0 + 3302 RETURN 2 + 3304 CONST0 + 3305 PUSHACC2 + 3306 APPLY1 + 3307 PUSHACC1 + 3308 C_CALL2 make_vect + 3310 PUSHCONST1 + 3311 PUSHACC2 + 3312 OFFSETINT -1 + 3314 PUSH + 3315 BRANCH 3330 + 3317 CHECK_SIGNALS + 3318 ACC1 + 3319 PUSHACC5 + 3320 APPLY1 + 3321 PUSHACC2 + 3322 PUSHACC4 + 3323 C_CALL3 array_unsafe_set + 3325 ACC1 + 3326 OFFSETINT 1 + 3328 ASSIGN 1 + 3330 ACC0 + 3331 PUSHACC2 + 3332 LEINT + 3333 BRANCHIF 3317 + 3335 CONST0 + 3336 POP 2 + 3338 ACC0 + 3339 RETURN 3 + 3341 CLOSURE 0, 3294 + 3344 PUSH + 3345 CLOSURE 0, 3256 + 3348 PUSH + 3349 CLOSURE 0, 3206 + 3352 PUSH + 3353 CLOSURE 0, 3107 + 3356 PUSH + 3357 CLOSURE 0, 3074 + 3360 PUSHACC0 + 3361 CLOSURE 1, 3020 + 3364 PUSH + 3365 CLOSURE 0, 2917 + 3368 PUSH + 3369 CLOSURE 0, 2861 + 3372 PUSH + 3373 CLOSURE 0, 2749 + 3376 PUSH + 3377 CLOSURE 0, 2718 + 3380 PUSH + 3381 CLOSURE 0, 2662 + 3384 PUSH + 3385 CLOSURE 0, 2630 + 3388 PUSH + 3389 CLOSURE 0, 2572 + 3392 PUSH + 3393 CLOSURE 0, 2558 + 3396 PUSH + 3397 CLOSURE 0, 2505 + 3400 PUSH + 3401 CLOSURE 0, 2445 + 3404 PUSH + 3405 CLOSURE 0, 2407 + 3408 PUSHACC0 + 3409 PUSHACC2 + 3410 PUSHACC6 + 3411 PUSHACC 8 + 3413 PUSHACC 10 + 3415 PUSHACC 12 + 3417 PUSHACC 8 + 3419 PUSHACC 10 + 3421 PUSHACC 16 + 3423 PUSHACC 18 + 3425 PUSHACC 24 + 3427 PUSHACC 21 + 3429 PUSHACC 23 + 3431 PUSHACC 26 + 3433 PUSHACC 29 + 3435 PUSHACC 30 + 3437 PUSHACC 32 + 3439 MAKEBLOCK 17, 0 + 3442 POP 17 + 3444 SETGLOBAL Array + 3446 BRANCH 3456 + 3448 ACC0 + 3449 PUSHENVACC1 + 3450 GETFIELD0 + 3451 ADDINT + 3452 PUSHENVACC1 + 3453 SETFIELD0 + 3454 RETURN 1 + 3456 CONST2 + 3457 PUSHCONSTINT 200000 + 3459 C_CALL2 make_vect + 3461 PUSHCONST0 + 3462 MAKEBLOCK1 0 + 3464 PUSHACC1 + 3465 PUSHACC1 + 3466 CLOSURE 1, 3448 + 3469 PUSHGETGLOBALFIELD Array, 11 + 3472 APPLY2 + 3473 CONSTINT 400000 + 3475 PUSHACC1 + 3476 GETFIELD0 + 3477 NEQ + 3478 BRANCHIFNOT 3485 + 3480 GETGLOBAL Not_found + 3482 MAKEBLOCK1 0 + 3484 RAISE + 3485 POP 2 + 3487 ATOM0 + 3488 SETGLOBAL T310-alloc-2 + 3490 STOP +**) diff --git a/test/testinterp/t320-gc-1.ml b/test/testinterp/t320-gc-1.ml new file mode 100644 index 0000000..4d5d6d9 --- /dev/null +++ b/test/testinterp/t320-gc-1.ml @@ -0,0 +1,1589 @@ +open Lib;; +let rec f n = + if n <= 0 then [] + else n :: f (n-1) +in +let l = f 300 in +Gc.minor (); +if List.fold_left (+) 0 l <> 301 * 150 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2432 + 2406 CONST0 + 2407 PUSHACC1 + 2408 LEINT + 2409 BRANCHIFNOT 2414 + 2411 CONST0 + 2412 RETURN 1 + 2414 ACC0 + 2415 OFFSETINT -1 + 2417 PUSHOFFSETCLOSURE0 + 2418 APPLY1 + 2419 PUSHACC1 + 2420 MAKEBLOCK2 0 + 2422 RETURN 1 + 2424 RESTART + 2425 GRAB 1 + 2427 ACC1 + 2428 PUSHACC1 + 2429 ADDINT + 2430 RETURN 2 + 2432 CLOSUREREC 0, 2406 + 2436 CONSTINT 300 + 2438 PUSHACC1 + 2439 APPLY1 + 2440 PUSHCONST0 + 2441 C_CALL1 gc_minor + 2443 CONSTINT 150 + 2445 PUSHCONSTINT 301 + 2447 MULINT + 2448 PUSHACC1 + 2449 PUSHCONST0 + 2450 PUSH + 2451 CLOSURE 0, 2425 + 2454 PUSHGETGLOBALFIELD List, 12 + 2457 APPLY3 + 2458 NEQ + 2459 BRANCHIFNOT 2466 + 2461 GETGLOBAL Not_found + 2463 MAKEBLOCK1 0 + 2465 RAISE + 2466 POP 2 + 2468 ATOM0 + 2469 SETGLOBAL T320-gc-1 + 2471 STOP +**) diff --git a/test/testinterp/t320-gc-2.ml b/test/testinterp/t320-gc-2.ml new file mode 100644 index 0000000..f607f65 --- /dev/null +++ b/test/testinterp/t320-gc-2.ml @@ -0,0 +1,1589 @@ +open Lib;; +let rec f n = + if n <= 0 then [] + else n :: f (n-1) +in +let l = f 300 in +Gc.major (); +if List.fold_left (+) 0 l <> 301 * 150 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2432 + 2406 CONST0 + 2407 PUSHACC1 + 2408 LEINT + 2409 BRANCHIFNOT 2414 + 2411 CONST0 + 2412 RETURN 1 + 2414 ACC0 + 2415 OFFSETINT -1 + 2417 PUSHOFFSETCLOSURE0 + 2418 APPLY1 + 2419 PUSHACC1 + 2420 MAKEBLOCK2 0 + 2422 RETURN 1 + 2424 RESTART + 2425 GRAB 1 + 2427 ACC1 + 2428 PUSHACC1 + 2429 ADDINT + 2430 RETURN 2 + 2432 CLOSUREREC 0, 2406 + 2436 CONSTINT 300 + 2438 PUSHACC1 + 2439 APPLY1 + 2440 PUSHCONST0 + 2441 C_CALL1 gc_major + 2443 CONSTINT 150 + 2445 PUSHCONSTINT 301 + 2447 MULINT + 2448 PUSHACC1 + 2449 PUSHCONST0 + 2450 PUSH + 2451 CLOSURE 0, 2425 + 2454 PUSHGETGLOBALFIELD List, 12 + 2457 APPLY3 + 2458 NEQ + 2459 BRANCHIFNOT 2466 + 2461 GETGLOBAL Not_found + 2463 MAKEBLOCK1 0 + 2465 RAISE + 2466 POP 2 + 2468 ATOM0 + 2469 SETGLOBAL T320-gc-2 + 2471 STOP +**) diff --git a/test/testinterp/t320-gc-3.ml b/test/testinterp/t320-gc-3.ml new file mode 100644 index 0000000..7c33d2f --- /dev/null +++ b/test/testinterp/t320-gc-3.ml @@ -0,0 +1,1589 @@ +open Lib;; +let rec f n = + if n <= 0 then [] + else n :: f (n-1) +in +let l = f 300 in +Gc.full_major (); +if List.fold_left (+) 0 l <> 301 * 150 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2432 + 2406 CONST0 + 2407 PUSHACC1 + 2408 LEINT + 2409 BRANCHIFNOT 2414 + 2411 CONST0 + 2412 RETURN 1 + 2414 ACC0 + 2415 OFFSETINT -1 + 2417 PUSHOFFSETCLOSURE0 + 2418 APPLY1 + 2419 PUSHACC1 + 2420 MAKEBLOCK2 0 + 2422 RETURN 1 + 2424 RESTART + 2425 GRAB 1 + 2427 ACC1 + 2428 PUSHACC1 + 2429 ADDINT + 2430 RETURN 2 + 2432 CLOSUREREC 0, 2406 + 2436 CONSTINT 300 + 2438 PUSHACC1 + 2439 APPLY1 + 2440 PUSHCONST0 + 2441 C_CALL1 gc_full_major + 2443 CONSTINT 150 + 2445 PUSHCONSTINT 301 + 2447 MULINT + 2448 PUSHACC1 + 2449 PUSHCONST0 + 2450 PUSH + 2451 CLOSURE 0, 2425 + 2454 PUSHGETGLOBALFIELD List, 12 + 2457 APPLY3 + 2458 NEQ + 2459 BRANCHIFNOT 2466 + 2461 GETGLOBAL Not_found + 2463 MAKEBLOCK1 0 + 2465 RAISE + 2466 POP 2 + 2468 ATOM0 + 2469 SETGLOBAL T320-gc-3 + 2471 STOP +**) diff --git a/test/testinterp/t330-compact-1.ml b/test/testinterp/t330-compact-1.ml new file mode 100644 index 0000000..efa958f --- /dev/null +++ b/test/testinterp/t330-compact-1.ml @@ -0,0 +1,15 @@ +open Lib;; +Gc.compact ();; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 CONST0 + 10 C_CALL1 gc_compaction + 12 ATOM0 + 13 SETGLOBAL T330-compact-1 + 15 STOP +**) diff --git a/test/testinterp/t330-compact-2.ml b/test/testinterp/t330-compact-2.ml new file mode 100644 index 0000000..62ab014 --- /dev/null +++ b/test/testinterp/t330-compact-2.ml @@ -0,0 +1,755 @@ +open Lib;; +Gc.compact ();; +let _ = Pervasives.do_at_exit();; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 CONST0 + 1198 C_CALL1 gc_compaction + 1200 CONST0 + 1201 PUSHGETGLOBALFIELD Pervasives, 68 + 1204 APPLY1 + 1205 ATOM0 + 1206 SETGLOBAL T330-compact-2 + 1208 STOP +**) diff --git a/test/testinterp/t330-compact-3.ml b/test/testinterp/t330-compact-3.ml new file mode 100644 index 0000000..f25c64e --- /dev/null +++ b/test/testinterp/t330-compact-3.ml @@ -0,0 +1,1589 @@ +open Lib;; +let rec f n = + if n <= 0 then [] + else n :: f (n-1) +in +let l = f 300 in +Gc.compact (); +if List.fold_left (+) 0 l <> 301 * 150 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2432 + 2406 CONST0 + 2407 PUSHACC1 + 2408 LEINT + 2409 BRANCHIFNOT 2414 + 2411 CONST0 + 2412 RETURN 1 + 2414 ACC0 + 2415 OFFSETINT -1 + 2417 PUSHOFFSETCLOSURE0 + 2418 APPLY1 + 2419 PUSHACC1 + 2420 MAKEBLOCK2 0 + 2422 RETURN 1 + 2424 RESTART + 2425 GRAB 1 + 2427 ACC1 + 2428 PUSHACC1 + 2429 ADDINT + 2430 RETURN 2 + 2432 CLOSUREREC 0, 2406 + 2436 CONSTINT 300 + 2438 PUSHACC1 + 2439 APPLY1 + 2440 PUSHCONST0 + 2441 C_CALL1 gc_compaction + 2443 CONSTINT 150 + 2445 PUSHCONSTINT 301 + 2447 MULINT + 2448 PUSHACC1 + 2449 PUSHCONST0 + 2450 PUSH + 2451 CLOSURE 0, 2425 + 2454 PUSHGETGLOBALFIELD List, 12 + 2457 APPLY3 + 2458 NEQ + 2459 BRANCHIFNOT 2466 + 2461 GETGLOBAL Not_found + 2463 MAKEBLOCK1 0 + 2465 RAISE + 2466 POP 2 + 2468 ATOM0 + 2469 SETGLOBAL T330-compact-3 + 2471 STOP +**) diff --git a/test/testinterp/t330-compact-4.ml b/test/testinterp/t330-compact-4.ml new file mode 100644 index 0000000..1c190f7 --- /dev/null +++ b/test/testinterp/t330-compact-4.ml @@ -0,0 +1,1589 @@ +open Lib;; +let rec f n = + if n <= 0 then [] + else n :: f (n-1) +in +Gc.compact (); +let l = f 300 in +if List.fold_left (+) 0 l <> 301 * 150 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2432 + 2406 CONST0 + 2407 PUSHACC1 + 2408 LEINT + 2409 BRANCHIFNOT 2414 + 2411 CONST0 + 2412 RETURN 1 + 2414 ACC0 + 2415 OFFSETINT -1 + 2417 PUSHOFFSETCLOSURE0 + 2418 APPLY1 + 2419 PUSHACC1 + 2420 MAKEBLOCK2 0 + 2422 RETURN 1 + 2424 RESTART + 2425 GRAB 1 + 2427 ACC1 + 2428 PUSHACC1 + 2429 ADDINT + 2430 RETURN 2 + 2432 CLOSUREREC 0, 2406 + 2436 CONST0 + 2437 C_CALL1 gc_compaction + 2439 CONSTINT 300 + 2441 PUSHACC1 + 2442 APPLY1 + 2443 PUSHCONSTINT 150 + 2445 PUSHCONSTINT 301 + 2447 MULINT + 2448 PUSHACC1 + 2449 PUSHCONST0 + 2450 PUSH + 2451 CLOSURE 0, 2425 + 2454 PUSHGETGLOBALFIELD List, 12 + 2457 APPLY3 + 2458 NEQ + 2459 BRANCHIFNOT 2466 + 2461 GETGLOBAL Not_found + 2463 MAKEBLOCK1 0 + 2465 RAISE + 2466 POP 2 + 2468 ATOM0 + 2469 SETGLOBAL T330-compact-4 + 2471 STOP +**) diff --git a/test/testinterp/t340-weak.ml b/test/testinterp/t340-weak.ml new file mode 100644 index 0000000..e36dbab --- /dev/null +++ b/test/testinterp/t340-weak.ml @@ -0,0 +1,2551 @@ +open Lib;; +let x = Array.make 20 "" in +let w = weak_create 20 in +for i = 0 to 19 do + x.(i) <- String.make 20 's'; + weak_set w i (Some x.(i)); +done; +Gc.full_major (); +for i = 0 to 19 do + match weak_get w i with + | None -> raise Not_found + | _ -> () +done; +for i = 0 to 19 do + if i mod 2 = 0 then x.(i) <- "" +done; +Gc.full_major (); +for i = 0 to 19 do + match weak_get w i with + | None when i mod 2 = 0 -> () + | Some s when i mod 2 = 1 -> if s.[5] <> 's' then raise Not_found + | _ -> raise Not_found +done +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2622 + 2406 CONSTINT 97 + 2408 PUSHACC1 + 2409 GEINT + 2410 BRANCHIFNOT 2418 + 2412 CONSTINT 122 + 2414 PUSHACC1 + 2415 LEINT + 2416 BRANCHIF 2442 + 2418 CONSTINT 224 + 2420 PUSHACC1 + 2421 GEINT + 2422 BRANCHIFNOT 2430 + 2424 CONSTINT 246 + 2426 PUSHACC1 + 2427 LEINT + 2428 BRANCHIF 2442 + 2430 CONSTINT 248 + 2432 PUSHACC1 + 2433 GEINT + 2434 BRANCHIFNOT 2447 + 2436 CONSTINT 254 + 2438 PUSHACC1 + 2439 LEINT + 2440 BRANCHIFNOT 2447 + 2442 ACC0 + 2443 OFFSETINT -32 + 2445 RETURN 1 + 2447 ACC0 + 2448 RETURN 1 + 2450 CONSTINT 65 + 2452 PUSHACC1 + 2453 GEINT + 2454 BRANCHIFNOT 2462 + 2456 CONSTINT 90 + 2458 PUSHACC1 + 2459 LEINT + 2460 BRANCHIF 2486 + 2462 CONSTINT 192 + 2464 PUSHACC1 + 2465 GEINT + 2466 BRANCHIFNOT 2474 + 2468 CONSTINT 214 + 2470 PUSHACC1 + 2471 LEINT + 2472 BRANCHIF 2486 + 2474 CONSTINT 216 + 2476 PUSHACC1 + 2477 GEINT + 2478 BRANCHIFNOT 2491 + 2480 CONSTINT 222 + 2482 PUSHACC1 + 2483 LEINT + 2484 BRANCHIFNOT 2491 + 2486 ACC0 + 2487 OFFSETINT 32 + 2489 RETURN 1 + 2491 ACC0 + 2492 RETURN 1 + 2494 CONSTINT 39 + 2496 PUSHACC1 + 2497 LTINT + 2498 BRANCHIFNOT 2520 + 2500 CONSTINT 9 + 2502 PUSHACC1 + 2503 EQ + 2504 BRANCHIFNOT 2510 + 2506 GETGLOBAL "\\t" + 2508 RETURN 1 + 2510 CONSTINT 13 + 2512 PUSHACC1 + 2513 EQ + 2514 BRANCHIFNOT 2540 + 2516 GETGLOBAL "\\n" + 2518 RETURN 1 + 2520 CONSTINT 39 + 2522 PUSHACC1 + 2523 EQ + 2524 BRANCHIFNOT 2530 + 2526 GETGLOBAL "\\'" + 2528 RETURN 1 + 2530 CONSTINT 92 + 2532 PUSHACC1 + 2533 EQ + 2534 BRANCHIFNOT 2540 + 2536 GETGLOBAL "\\\\" + 2538 RETURN 1 + 2540 ACC0 + 2541 C_CALL1 is_printable + 2543 BRANCHIFNOT 2555 + 2545 CONST1 + 2546 C_CALL1 create_string + 2548 PUSHACC1 + 2549 PUSHCONST0 + 2550 PUSHACC2 + 2551 SETSTRINGCHAR + 2552 ACC0 + 2553 RETURN 2 + 2555 ACC0 + 2556 PUSHCONSTINT 4 + 2558 C_CALL1 create_string + 2560 PUSHCONSTINT 92 + 2562 PUSHCONST0 + 2563 PUSHACC2 + 2564 SETSTRINGCHAR + 2565 CONSTINT 100 + 2567 PUSHACC2 + 2568 DIVINT + 2569 PUSHCONSTINT 48 + 2571 ADDINT + 2572 PUSHCONST1 + 2573 PUSHACC2 + 2574 SETSTRINGCHAR + 2575 CONSTINT 10 + 2577 PUSHCONSTINT 10 + 2579 PUSHACC3 + 2580 DIVINT + 2581 MODINT + 2582 PUSHCONSTINT 48 + 2584 ADDINT + 2585 PUSHCONST2 + 2586 PUSHACC2 + 2587 SETSTRINGCHAR + 2588 CONSTINT 10 + 2590 PUSHACC2 + 2591 MODINT + 2592 PUSHCONSTINT 48 + 2594 ADDINT + 2595 PUSHCONST3 + 2596 PUSHACC2 + 2597 SETSTRINGCHAR + 2598 ACC0 + 2599 RETURN 3 + 2601 CONST0 + 2602 PUSHACC1 + 2603 LTINT + 2604 BRANCHIF 2612 + 2606 CONSTINT 255 + 2608 PUSHACC1 + 2609 GTINT + 2610 BRANCHIFNOT 2619 + 2612 GETGLOBAL "Char.chr" + 2614 PUSHGETGLOBALFIELD Pervasives, 2 + 2617 APPTERM1 2 + 2619 ACC0 + 2620 RETURN 1 + 2622 CLOSURE 0, 2601 + 2625 PUSH + 2626 CLOSURE 0, 2494 + 2629 PUSH + 2630 CLOSURE 0, 2450 + 2633 PUSH + 2634 CLOSURE 0, 2406 + 2637 PUSHACC0 + 2638 PUSHACC2 + 2639 PUSHACC4 + 2640 PUSHACC6 + 2641 MAKEBLOCK 4, 0 + 2644 POP 4 + 2646 SETGLOBAL Char + 2648 BRANCH 3540 + 2650 RESTART + 2651 GRAB 3 + 2653 ACC1 + 2654 PUSHACC3 + 2655 GEINT + 2656 BRANCHIFNOT 2663 + 2658 GETGLOBAL Not_found + 2660 MAKEBLOCK1 0 + 2662 RAISE + 2663 ACC3 + 2664 PUSHACC3 + 2665 PUSHACC2 + 2666 GETSTRINGCHAR + 2667 EQ + 2668 BRANCHIFNOT 2673 + 2670 ACC2 + 2671 RETURN 4 + 2673 ACC3 + 2674 PUSHACC3 + 2675 OFFSETINT 1 + 2677 PUSHACC3 + 2678 PUSHACC3 + 2679 PUSHOFFSETCLOSURE0 + 2680 APPTERM 4, 8 + 2683 RESTART + 2684 GRAB 2 + 2686 CONST0 + 2687 PUSHACC2 + 2688 LTINT + 2689 BRANCHIFNOT 2696 + 2691 GETGLOBAL Not_found + 2693 MAKEBLOCK1 0 + 2695 RAISE + 2696 ACC2 + 2697 PUSHACC2 + 2698 PUSHACC2 + 2699 GETSTRINGCHAR + 2700 EQ + 2701 BRANCHIFNOT 2706 + 2703 ACC1 + 2704 RETURN 3 + 2706 ACC2 + 2707 PUSHACC2 + 2708 OFFSETINT -1 + 2710 PUSHACC2 + 2711 PUSHOFFSETCLOSURE0 + 2712 APPTERM3 6 + 2714 RESTART + 2715 GRAB 1 + 2717 ACC1 + 2718 PUSHCONST0 + 2719 PUSHACC2 + 2720 PUSHENVACC1 + 2721 APPTERM3 5 + 2723 RESTART + 2724 GRAB 2 + 2726 CONST0 + 2727 PUSHACC2 + 2728 LTINT + 2729 BRANCHIF 2738 + 2731 ACC0 + 2732 C_CALL1 ml_string_length + 2734 PUSHACC2 + 2735 GEINT + 2736 BRANCHIFNOT 2745 + 2738 GETGLOBAL "String.rcontains_from" + 2740 PUSHGETGLOBALFIELD Pervasives, 2 + 2743 APPTERM1 4 + 2745 PUSHTRAP 2756 + 2747 ACC6 + 2748 PUSHACC6 + 2749 PUSHACC6 + 2750 PUSHENVACC1 + 2751 APPLY3 + 2752 CONST1 + 2753 POPTRAP + 2754 RETURN 3 + 2756 PUSHGETGLOBAL Not_found + 2758 PUSHACC1 + 2759 GETFIELD0 + 2760 EQ + 2761 BRANCHIFNOT 2766 + 2763 CONST0 + 2764 RETURN 4 + 2766 ACC0 + 2767 RAISE + 2768 RESTART + 2769 GRAB 2 + 2771 CONST0 + 2772 PUSHACC2 + 2773 LTINT + 2774 BRANCHIF 2783 + 2776 ACC0 + 2777 C_CALL1 ml_string_length + 2779 PUSHACC2 + 2780 GTINT + 2781 BRANCHIFNOT 2790 + 2783 GETGLOBAL "String.contains_from" + 2785 PUSHGETGLOBALFIELD Pervasives, 2 + 2788 APPTERM1 4 + 2790 PUSHTRAP 2811 + 2792 PUSH_RETADDR 2807 + 2794 ACC 9 + 2796 PUSHACC 9 + 2798 PUSHACC 9 + 2800 C_CALL1 ml_string_length + 2802 PUSHACC 10 + 2804 PUSHENVACC1 + 2805 APPLY 4 + 2807 CONST1 + 2808 POPTRAP + 2809 RETURN 3 + 2811 PUSHGETGLOBAL Not_found + 2813 PUSHACC1 + 2814 GETFIELD0 + 2815 EQ + 2816 BRANCHIFNOT 2821 + 2818 CONST0 + 2819 RETURN 4 + 2821 ACC0 + 2822 RAISE + 2823 RESTART + 2824 GRAB 2 + 2826 CONST0 + 2827 PUSHACC2 + 2828 LTINT + 2829 BRANCHIF 2838 + 2831 ACC0 + 2832 C_CALL1 ml_string_length + 2834 PUSHACC2 + 2835 GEINT + 2836 BRANCHIFNOT 2845 + 2838 GETGLOBAL "String.rindex_from" + 2840 PUSHGETGLOBALFIELD Pervasives, 2 + 2843 APPTERM1 4 + 2845 ACC2 + 2846 PUSHACC2 + 2847 PUSHACC2 + 2848 PUSHENVACC1 + 2849 APPTERM3 6 + 2851 RESTART + 2852 GRAB 1 + 2854 ACC1 + 2855 PUSHACC1 + 2856 C_CALL1 ml_string_length + 2858 OFFSETINT -1 + 2860 PUSHACC2 + 2861 PUSHENVACC1 + 2862 APPTERM3 5 + 2864 RESTART + 2865 GRAB 2 + 2867 CONST0 + 2868 PUSHACC2 + 2869 LTINT + 2870 BRANCHIF 2879 + 2872 ACC0 + 2873 C_CALL1 ml_string_length + 2875 PUSHACC2 + 2876 GTINT + 2877 BRANCHIFNOT 2886 + 2879 GETGLOBAL "String.index_from" + 2881 PUSHGETGLOBALFIELD Pervasives, 2 + 2884 APPTERM1 4 + 2886 ACC2 + 2887 PUSHACC2 + 2888 PUSHACC2 + 2889 C_CALL1 ml_string_length + 2891 PUSHACC3 + 2892 PUSHENVACC1 + 2893 APPTERM 4, 7 + 2896 RESTART + 2897 GRAB 1 + 2899 ACC1 + 2900 PUSHCONST0 + 2901 PUSHACC2 + 2902 C_CALL1 ml_string_length + 2904 PUSHACC3 + 2905 PUSHENVACC1 + 2906 APPTERM 4, 6 + 2909 ACC0 + 2910 PUSHGETGLOBALFIELD Char, 2 + 2913 PUSHENVACC1 + 2914 APPTERM2 3 + 2916 ACC0 + 2917 PUSHGETGLOBALFIELD Char, 3 + 2920 PUSHENVACC1 + 2921 APPTERM2 3 + 2923 RESTART + 2924 GRAB 1 + 2926 CONST0 + 2927 PUSHACC2 + 2928 C_CALL1 ml_string_length + 2930 EQ + 2931 BRANCHIFNOT 2936 + 2933 ACC1 + 2934 RETURN 2 + 2936 ACC1 + 2937 PUSHENVACC1 + 2938 APPLY1 + 2939 PUSHCONST0 + 2940 PUSHACC3 + 2941 GETSTRINGCHAR + 2942 PUSHACC2 + 2943 APPLY1 + 2944 PUSHCONST0 + 2945 PUSHACC2 + 2946 SETSTRINGCHAR + 2947 ACC0 + 2948 RETURN 3 + 2950 ACC0 + 2951 PUSHGETGLOBALFIELD Char, 2 + 2954 PUSHENVACC1 + 2955 APPTERM2 3 + 2957 ACC0 + 2958 PUSHGETGLOBALFIELD Char, 3 + 2961 PUSHENVACC1 + 2962 APPTERM2 3 + 2964 RESTART + 2965 GRAB 1 + 2967 ACC1 + 2968 C_CALL1 ml_string_length + 2970 PUSHCONST0 + 2971 PUSHACC1 + 2972 EQ + 2973 BRANCHIFNOT 2978 + 2975 ACC2 + 2976 RETURN 3 + 2978 ACC0 + 2979 C_CALL1 create_string + 2981 PUSHCONST0 + 2982 PUSHACC2 + 2983 OFFSETINT -1 + 2985 PUSH + 2986 BRANCH 3002 + 2988 CHECK_SIGNALS + 2989 ACC1 + 2990 PUSHACC6 + 2991 GETSTRINGCHAR + 2992 PUSHACC5 + 2993 APPLY1 + 2994 PUSHACC2 + 2995 PUSHACC4 + 2996 SETSTRINGCHAR + 2997 ACC1 + 2998 OFFSETINT 1 + 3000 ASSIGN 1 + 3002 ACC0 + 3003 PUSHACC2 + 3004 LEINT + 3005 BRANCHIF 2988 + 3007 CONST0 + 3008 POP 2 + 3010 ACC0 + 3011 RETURN 4 + 3013 CONST0 + 3014 PUSHCONST0 + 3015 PUSHACC2 + 3016 C_CALL1 ml_string_length + 3018 OFFSETINT -1 + 3020 PUSH + 3021 BRANCH 3059 + 3023 CHECK_SIGNALS + 3024 ACC1 + 3025 PUSHACC4 + 3026 GETSTRINGCHAR + 3027 PUSHACC0 + 3028 PUSHGETGLOBAL "\000\"\000\000\004\000\000\000\000\000\000\016\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + 3030 C_CALL2 bitvect_test + 3032 BRANCHIFNOT 3038 + 3034 CONST0 + 3035 CONST2 + 3036 BRANCH 3048 + 3038 ACC0 + 3039 C_CALL1 is_printable + 3041 BRANCHIFNOT 3046 + 3043 CONST1 + 3044 BRANCH 3048 + 3046 CONSTINT 4 + 3048 POP 1 + 3050 PUSHACC3 + 3051 ADDINT + 3052 ASSIGN 2 + 3054 ACC1 + 3055 OFFSETINT 1 + 3057 ASSIGN 1 + 3059 ACC0 + 3060 PUSHACC2 + 3061 LEINT + 3062 BRANCHIF 3023 + 3064 CONST0 + 3065 POP 2 + 3067 ACC1 + 3068 C_CALL1 ml_string_length + 3070 PUSHACC1 + 3071 EQ + 3072 BRANCHIFNOT 3077 + 3074 ACC1 + 3075 RETURN 2 + 3077 ACC0 + 3078 C_CALL1 create_string + 3080 PUSHCONST0 + 3081 ASSIGN 1 + 3083 CONST0 + 3084 PUSHACC3 + 3085 C_CALL1 ml_string_length + 3087 OFFSETINT -1 + 3089 PUSH + 3090 BRANCH 3245 + 3092 CHECK_SIGNALS + 3093 ACC1 + 3094 PUSHACC5 + 3095 GETSTRINGCHAR + 3096 PUSHACC0 + 3097 PUSHGETGLOBAL "\000\000\000\000\004\000\000\000\000\000\000\016\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + 3099 C_CALL2 bitvect_test + 3101 BRANCHIFNOT 3120 + 3103 CONST0 + 3104 CONSTINT 92 + 3106 PUSHACC5 + 3107 PUSHACC5 + 3108 SETSTRINGCHAR + 3109 ACC4 + 3110 OFFSETINT 1 + 3112 ASSIGN 4 + 3114 ACC0 + 3115 PUSHACC5 + 3116 PUSHACC5 + 3117 SETSTRINGCHAR + 3118 BRANCH 3233 + 3120 CONSTINT 9 + 3122 PUSHACC1 + 3123 EQ + 3124 BRANCHIFNOT 3143 + 3126 CONSTINT 92 + 3128 PUSHACC5 + 3129 PUSHACC5 + 3130 SETSTRINGCHAR + 3131 ACC4 + 3132 OFFSETINT 1 + 3134 ASSIGN 4 + 3136 CONSTINT 116 + 3138 PUSHACC5 + 3139 PUSHACC5 + 3140 SETSTRINGCHAR + 3141 BRANCH 3233 + 3143 CONSTINT 13 + 3145 PUSHACC1 + 3146 EQ + 3147 BRANCHIFNOT 3166 + 3149 CONSTINT 92 + 3151 PUSHACC5 + 3152 PUSHACC5 + 3153 SETSTRINGCHAR + 3154 ACC4 + 3155 OFFSETINT 1 + 3157 ASSIGN 4 + 3159 CONSTINT 110 + 3161 PUSHACC5 + 3162 PUSHACC5 + 3163 SETSTRINGCHAR + 3164 BRANCH 3233 + 3166 ACC0 + 3167 C_CALL1 is_printable + 3169 BRANCHIFNOT 3177 + 3171 ACC0 + 3172 PUSHACC5 + 3173 PUSHACC5 + 3174 SETSTRINGCHAR + 3175 BRANCH 3233 + 3177 ACC0 + 3178 PUSHCONSTINT 92 + 3180 PUSHACC6 + 3181 PUSHACC6 + 3182 SETSTRINGCHAR + 3183 ACC5 + 3184 OFFSETINT 1 + 3186 ASSIGN 5 + 3188 CONSTINT 100 + 3190 PUSHACC1 + 3191 DIVINT + 3192 PUSHCONSTINT 48 + 3194 ADDINT + 3195 PUSHACC6 + 3196 PUSHACC6 + 3197 SETSTRINGCHAR + 3198 ACC5 + 3199 OFFSETINT 1 + 3201 ASSIGN 5 + 3203 CONSTINT 10 + 3205 PUSHCONSTINT 10 + 3207 PUSHACC2 + 3208 DIVINT + 3209 MODINT + 3210 PUSHCONSTINT 48 + 3212 ADDINT + 3213 PUSHACC6 + 3214 PUSHACC6 + 3215 SETSTRINGCHAR + 3216 ACC5 + 3217 OFFSETINT 1 + 3219 ASSIGN 5 + 3221 CONSTINT 10 + 3223 PUSHACC1 + 3224 MODINT + 3225 PUSHCONSTINT 48 + 3227 ADDINT + 3228 PUSHACC6 + 3229 PUSHACC6 + 3230 SETSTRINGCHAR + 3231 POP 1 + 3233 POP 1 + 3235 ACC3 + 3236 OFFSETINT 1 + 3238 ASSIGN 3 + 3240 ACC1 + 3241 OFFSETINT 1 + 3243 ASSIGN 1 + 3245 ACC0 + 3246 PUSHACC2 + 3247 LEINT + 3248 BRANCHIF 3092 + 3250 CONST0 + 3251 POP 2 + 3253 ACC0 + 3254 RETURN 3 + 3256 ENVACC1 + 3257 C_CALL1 ml_string_length + 3259 PUSHENVACC3 + 3260 GETFIELD0 + 3261 PUSHENVACC2 + 3262 PUSHCONST0 + 3263 PUSHENVACC1 + 3264 C_CALL5 blit_string + 3266 ENVACC1 + 3267 C_CALL1 ml_string_length + 3269 PUSHENVACC3 + 3270 GETFIELD0 + 3271 ADDINT + 3272 PUSHENVACC3 + 3273 SETFIELD0 + 3274 ACC0 + 3275 C_CALL1 ml_string_length + 3277 PUSHENVACC3 + 3278 GETFIELD0 + 3279 PUSHENVACC2 + 3280 PUSHCONST0 + 3281 PUSHACC4 + 3282 C_CALL5 blit_string + 3284 ACC0 + 3285 C_CALL1 ml_string_length + 3287 PUSHENVACC3 + 3288 GETFIELD0 + 3289 ADDINT + 3290 PUSHENVACC3 + 3291 SETFIELD0 + 3292 RETURN 1 + 3294 ENVACC1 + 3295 OFFSETREF 1 + 3297 ACC0 + 3298 C_CALL1 ml_string_length + 3300 PUSHENVACC2 + 3301 GETFIELD0 + 3302 ADDINT + 3303 PUSHENVACC2 + 3304 SETFIELD0 + 3305 RETURN 1 + 3307 RESTART + 3308 GRAB 1 + 3310 ACC1 + 3311 BRANCHIFNOT 3374 + 3313 ACC1 + 3314 GETFIELD0 + 3315 PUSHCONST0 + 3316 MAKEBLOCK1 0 + 3318 PUSHCONST0 + 3319 MAKEBLOCK1 0 + 3321 PUSHACC4 + 3322 PUSHACC1 + 3323 PUSHACC3 + 3324 CLOSURE 2, 3294 + 3327 PUSHGETGLOBALFIELD List, 9 + 3330 APPLY2 + 3331 ACC1 + 3332 GETFIELD0 + 3333 OFFSETINT -1 + 3335 PUSHACC4 + 3336 C_CALL1 ml_string_length + 3338 MULINT + 3339 PUSHACC1 + 3340 GETFIELD0 + 3341 ADDINT + 3342 C_CALL1 create_string + 3344 PUSHACC3 + 3345 C_CALL1 ml_string_length + 3347 PUSHCONST0 + 3348 PUSHACC2 + 3349 PUSHCONST0 + 3350 PUSHACC7 + 3351 C_CALL5 blit_string + 3353 ACC3 + 3354 C_CALL1 ml_string_length + 3356 MAKEBLOCK1 0 + 3358 PUSHACC6 + 3359 GETFIELD1 + 3360 PUSHACC1 + 3361 PUSHACC3 + 3362 PUSHACC 8 + 3364 CLOSURE 3, 3256 + 3367 PUSHGETGLOBALFIELD List, 9 + 3370 APPLY2 + 3371 ACC1 + 3372 RETURN 7 + 3374 GETGLOBAL "" + 3376 RETURN 2 + 3378 RESTART + 3379 GRAB 4 + 3381 CONST0 + 3382 PUSHACC5 + 3383 LTINT + 3384 BRANCHIF 3414 + 3386 CONST0 + 3387 PUSHACC2 + 3388 LTINT + 3389 BRANCHIF 3414 + 3391 ACC0 + 3392 C_CALL1 ml_string_length + 3394 PUSHACC5 + 3395 PUSHACC3 + 3396 ADDINT + 3397 GTINT + 3398 BRANCHIF 3414 + 3400 CONST0 + 3401 PUSHACC4 + 3402 LTINT + 3403 BRANCHIF 3414 + 3405 ACC2 + 3406 C_CALL1 ml_string_length + 3408 PUSHACC5 + 3409 PUSHACC5 + 3410 ADDINT + 3411 GTINT + 3412 BRANCHIFNOT 3421 + 3414 GETGLOBAL "String.blit" + 3416 PUSHGETGLOBALFIELD Pervasives, 2 + 3419 APPTERM1 6 + 3421 ACC4 + 3422 PUSHACC4 + 3423 PUSHACC4 + 3424 PUSHACC4 + 3425 PUSHACC4 + 3426 C_CALL5 blit_string + 3428 RETURN 5 + 3430 RESTART + 3431 GRAB 3 + 3433 CONST0 + 3434 PUSHACC2 + 3435 LTINT + 3436 BRANCHIF 3452 + 3438 CONST0 + 3439 PUSHACC3 + 3440 LTINT + 3441 BRANCHIF 3452 + 3443 ACC0 + 3444 C_CALL1 ml_string_length + 3446 PUSHACC3 + 3447 PUSHACC3 + 3448 ADDINT + 3449 GTINT + 3450 BRANCHIFNOT 3459 + 3452 GETGLOBAL "String.fill" + 3454 PUSHGETGLOBALFIELD Pervasives, 2 + 3457 APPTERM1 5 + 3459 ACC3 + 3460 PUSHACC3 + 3461 PUSHACC3 + 3462 PUSHACC3 + 3463 C_CALL4 fill_string + 3465 RETURN 4 + 3467 RESTART + 3468 GRAB 2 + 3470 CONST0 + 3471 PUSHACC2 + 3472 LTINT + 3473 BRANCHIF 3489 + 3475 CONST0 + 3476 PUSHACC3 + 3477 LTINT + 3478 BRANCHIF 3489 + 3480 ACC0 + 3481 C_CALL1 ml_string_length + 3483 PUSHACC3 + 3484 PUSHACC3 + 3485 ADDINT + 3486 GTINT + 3487 BRANCHIFNOT 3496 + 3489 GETGLOBAL "String.sub" + 3491 PUSHGETGLOBALFIELD Pervasives, 2 + 3494 APPTERM1 4 + 3496 ACC2 + 3497 C_CALL1 create_string + 3499 PUSHACC3 + 3500 PUSHCONST0 + 3501 PUSHACC2 + 3502 PUSHACC5 + 3503 PUSHACC5 + 3504 C_CALL5 blit_string + 3506 ACC0 + 3507 RETURN 4 + 3509 ACC0 + 3510 C_CALL1 ml_string_length + 3512 PUSHACC0 + 3513 C_CALL1 create_string + 3515 PUSHACC1 + 3516 PUSHCONST0 + 3517 PUSHACC2 + 3518 PUSHCONST0 + 3519 PUSHACC6 + 3520 C_CALL5 blit_string + 3522 ACC0 + 3523 RETURN 3 + 3525 RESTART + 3526 GRAB 1 + 3528 ACC0 + 3529 C_CALL1 create_string + 3531 PUSHACC2 + 3532 PUSHACC2 + 3533 PUSHCONST0 + 3534 PUSHACC3 + 3535 C_CALL4 fill_string + 3537 ACC0 + 3538 RETURN 3 + 3540 CLOSURE 0, 3526 + 3543 PUSH + 3544 CLOSURE 0, 3509 + 3547 PUSH + 3548 CLOSURE 0, 3468 + 3551 PUSH + 3552 CLOSURE 0, 3431 + 3555 PUSH + 3556 CLOSURE 0, 3379 + 3559 PUSH + 3560 CLOSURE 0, 3308 + 3563 PUSH + 3564 CLOSURE 0, 3013 + 3567 PUSH + 3568 CLOSURE 0, 2965 + 3571 PUSHACC0 + 3572 CLOSURE 1, 2957 + 3575 PUSHACC1 + 3576 CLOSURE 1, 2950 + 3579 PUSHACC 8 + 3581 CLOSURE 1, 2924 + 3584 PUSHACC0 + 3585 CLOSURE 1, 2916 + 3588 PUSHACC1 + 3589 CLOSURE 1, 2909 + 3592 PUSH + 3593 CLOSUREREC 0, 2651 + 3597 ACC0 + 3598 CLOSURE 1, 2897 + 3601 PUSHACC1 + 3602 CLOSURE 1, 2865 + 3605 PUSH + 3606 CLOSUREREC 0, 2684 + 3610 ACC0 + 3611 CLOSURE 1, 2852 + 3614 PUSHACC1 + 3615 CLOSURE 1, 2824 + 3618 PUSHACC5 + 3619 CLOSURE 1, 2769 + 3622 PUSHACC3 + 3623 CLOSURE 1, 2724 + 3626 PUSHACC1 + 3627 CLOSURE 1, 2715 + 3630 PUSHACC 9 + 3632 PUSHACC 11 + 3634 PUSHACC 14 + 3636 PUSHACC 16 + 3638 PUSHACC5 + 3639 PUSHACC7 + 3640 PUSHACC6 + 3641 PUSHACC 10 + 3643 PUSHACC 14 + 3645 PUSHACC 13 + 3647 PUSHACC 17 + 3649 PUSHACC 26 + 3651 PUSHACC 28 + 3653 PUSHACC 30 + 3655 PUSHACC 32 + 3657 PUSHACC 34 + 3659 PUSHACC 36 + 3661 PUSHACC 38 + 3663 MAKEBLOCK 18, 0 + 3666 POP 22 + 3668 SETGLOBAL String + 3670 GETGLOBAL "" + 3672 PUSHCONSTINT 20 + 3674 C_CALL2 make_vect + 3676 PUSHCONSTINT 20 + 3678 C_CALL1 weak_create + 3680 PUSHCONST0 + 3681 PUSHCONSTINT 19 + 3683 PUSH + 3684 BRANCH 3712 + 3686 CHECK_SIGNALS + 3687 CONSTINT 115 + 3689 PUSHCONSTINT 20 + 3691 PUSHGETGLOBALFIELD String, 0 + 3694 APPLY2 + 3695 PUSHACC2 + 3696 PUSHACC5 + 3697 SETVECTITEM + 3698 ACC1 + 3699 PUSHACC4 + 3700 GETVECTITEM + 3701 MAKEBLOCK1 0 + 3703 PUSHACC2 + 3704 PUSHACC4 + 3705 C_CALL3 weak_set + 3707 ACC1 + 3708 OFFSETINT 1 + 3710 ASSIGN 1 + 3712 ACC0 + 3713 PUSHACC2 + 3714 LEINT + 3715 BRANCHIF 3686 + 3717 CONST0 + 3718 POP 2 + 3720 CONST0 + 3721 C_CALL1 gc_full_major + 3723 CONST0 + 3724 PUSHCONSTINT 19 + 3726 PUSH + 3727 BRANCH 3750 + 3729 CHECK_SIGNALS + 3730 ACC1 + 3731 PUSHACC3 + 3732 C_CALL2 weak_get + 3734 PUSHACC0 + 3735 BRANCHIF 3742 + 3737 GETGLOBAL Not_found + 3739 MAKEBLOCK1 0 + 3741 RAISE + 3742 CONST0 + 3743 POP 1 + 3745 ACC1 + 3746 OFFSETINT 1 + 3748 ASSIGN 1 + 3750 ACC0 + 3751 PUSHACC2 + 3752 LEINT + 3753 BRANCHIF 3729 + 3755 CONST0 + 3756 POP 2 + 3758 CONST0 + 3759 PUSHCONSTINT 19 + 3761 PUSH + 3762 BRANCH 3782 + 3764 CHECK_SIGNALS + 3765 CONST0 + 3766 PUSHCONST2 + 3767 PUSHACC3 + 3768 MODINT + 3769 EQ + 3770 BRANCHIFNOT 3777 + 3772 GETGLOBAL "" + 3774 PUSHACC2 + 3775 PUSHACC5 + 3776 SETVECTITEM + 3777 ACC1 + 3778 OFFSETINT 1 + 3780 ASSIGN 1 + 3782 ACC0 + 3783 PUSHACC2 + 3784 LEINT + 3785 BRANCHIF 3764 + 3787 CONST0 + 3788 POP 2 + 3790 CONST0 + 3791 C_CALL1 gc_full_major + 3793 CONST0 + 3794 PUSHCONSTINT 19 + 3796 PUSH + 3797 BRANCH 3851 + 3799 CHECK_SIGNALS + 3800 ACC1 + 3801 PUSHACC3 + 3802 C_CALL2 weak_get + 3804 PUSHACC0 + 3805 BRANCHIFNOT 3829 + 3807 CONST1 + 3808 PUSHCONST2 + 3809 PUSHACC4 + 3810 MODINT + 3811 EQ + 3812 BRANCHIFNOT 3839 + 3814 CONSTINT 115 + 3816 PUSHCONSTINT 5 + 3818 PUSHACC2 + 3819 GETFIELD0 + 3820 GETSTRINGCHAR + 3821 NEQ + 3822 BRANCHIFNOT 3844 + 3824 GETGLOBAL Not_found + 3826 MAKEBLOCK1 0 + 3828 RAISE + 3829 CONST0 + 3830 PUSHCONST2 + 3831 PUSHACC4 + 3832 MODINT + 3833 EQ + 3834 BRANCHIFNOT 3839 + 3836 CONST0 + 3837 BRANCH 3844 + 3839 GETGLOBAL Not_found + 3841 MAKEBLOCK1 0 + 3843 RAISE + 3844 POP 1 + 3846 ACC1 + 3847 OFFSETINT 1 + 3849 ASSIGN 1 + 3851 ACC0 + 3852 PUSHACC2 + 3853 LEINT + 3854 BRANCHIF 3799 + 3856 CONST0 + 3857 POP 4 + 3859 ATOM0 + 3860 SETGLOBAL T340-weak + 3862 STOP +**) diff --git a/test/testinterp/t350-heapcheck.ml b/test/testinterp/t350-heapcheck.ml new file mode 100644 index 0000000..ef4557c --- /dev/null +++ b/test/testinterp/t350-heapcheck.ml @@ -0,0 +1,2554 @@ +open Lib;; +ignore (Gc.stat ()); +let x = Array.make 20 "" in +let w = weak_create 20 in +for i = 0 to 19 do + x.(i) <- String.make 20 's'; + weak_set w i (Some x.(i)); +done; +Gc.full_major (); +for i = 0 to 19 do + match weak_get w i with + | None -> raise Not_found + | _ -> () +done; +for i = 0 to 19 do + if i mod 2 = 0 then x.(i) <- "" +done; +Gc.full_major (); +for i = 0 to 19 do + match weak_get w i with + | None when i mod 2 = 0 -> () + | Some s when i mod 2 = 1 -> if s.[5] <> 's' then raise Not_found + | _ -> raise Not_found +done +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 746 + 11 RESTART + 12 GRAB 1 + 14 ACC0 + 15 BRANCHIFNOT 28 + 17 ACC1 + 18 PUSHACC1 + 19 GETFIELD1 + 20 PUSHOFFSETCLOSURE0 + 21 APPLY2 + 22 PUSHACC1 + 23 GETFIELD0 + 24 MAKEBLOCK2 0 + 26 RETURN 2 + 28 ACC1 + 29 RETURN 2 + 31 RESTART + 32 GRAB 3 + 34 CONST0 + 35 PUSHACC4 + 36 LEINT + 37 BRANCHIFNOT 42 + 39 CONST0 + 40 RETURN 4 + 42 ACC3 + 43 PUSHACC3 + 44 PUSHACC3 + 45 PUSHACC3 + 46 C_CALL4 caml_input + 48 PUSHCONST0 + 49 PUSHACC1 + 50 EQ + 51 BRANCHIFNOT 58 + 53 GETGLOBAL End_of_file + 55 MAKEBLOCK1 0 + 57 RAISE + 58 ACC0 + 59 PUSHACC5 + 60 SUBINT + 61 PUSHACC1 + 62 PUSHACC5 + 63 ADDINT + 64 PUSHACC4 + 65 PUSHACC4 + 66 PUSHOFFSETCLOSURE0 + 67 APPTERM 4, 9 + 70 ACC0 + 71 C_CALL1 caml_input_scan_line + 73 PUSHCONST0 + 74 PUSHACC1 + 75 EQ + 76 BRANCHIFNOT 83 + 78 GETGLOBAL End_of_file + 80 MAKEBLOCK1 0 + 82 RAISE + 83 CONST0 + 84 PUSHACC1 + 85 GTINT + 86 BRANCHIFNOT 107 + 88 ACC0 + 89 OFFSETINT -1 + 91 C_CALL1 create_string + 93 PUSHACC1 + 94 OFFSETINT -1 + 96 PUSHCONST0 + 97 PUSHACC2 + 98 PUSHACC5 + 99 C_CALL4 caml_input + 101 ACC2 + 102 C_CALL1 caml_input_char + 104 ACC0 + 105 RETURN 3 + 107 ACC0 + 108 NEGINT + 109 C_CALL1 create_string + 111 PUSHACC1 + 112 NEGINT + 113 PUSHCONST0 + 114 PUSHACC2 + 115 PUSHACC5 + 116 C_CALL4 caml_input + 118 CONST0 + 119 PUSHTRAP 130 + 121 ACC6 + 122 PUSHOFFSETCLOSURE0 + 123 APPLY1 + 124 PUSHACC5 + 125 PUSHENVACC1 + 126 APPLY2 + 127 POPTRAP + 128 RETURN 3 + 130 PUSHGETGLOBAL End_of_file + 132 PUSHACC1 + 133 GETFIELD0 + 134 EQ + 135 BRANCHIFNOT 140 + 137 ACC1 + 138 RETURN 4 + 140 ACC0 + 141 RAISE + 142 ACC0 + 143 C_CALL1 caml_flush + 145 RETURN 1 + 147 RESTART + 148 GRAB 1 + 150 ACC1 + 151 PUSHACC1 + 152 C_CALL2 caml_output_char + 154 RETURN 2 + 156 RESTART + 157 GRAB 1 + 159 ACC1 + 160 PUSHACC1 + 161 C_CALL2 caml_output_char + 163 RETURN 2 + 165 RESTART + 166 GRAB 1 + 168 ACC1 + 169 PUSHACC1 + 170 C_CALL2 caml_output_int + 172 RETURN 2 + 174 RESTART + 175 GRAB 1 + 177 ACC1 + 178 PUSHACC1 + 179 C_CALL2 caml_seek_out + 181 RETURN 2 + 183 ACC0 + 184 C_CALL1 caml_pos_out + 186 RETURN 1 + 188 ACC0 + 189 C_CALL1 caml_channel_size + 191 RETURN 1 + 193 RESTART + 194 GRAB 1 + 196 ACC1 + 197 PUSHACC1 + 198 C_CALL2 caml_set_binary_mode + 200 RETURN 2 + 202 ACC0 + 203 C_CALL1 caml_input_char + 205 RETURN 1 + 207 ACC0 + 208 C_CALL1 caml_input_char + 210 RETURN 1 + 212 ACC0 + 213 C_CALL1 caml_input_int + 215 RETURN 1 + 217 ACC0 + 218 C_CALL1 input_value + 220 RETURN 1 + 222 RESTART + 223 GRAB 1 + 225 ACC1 + 226 PUSHACC1 + 227 C_CALL2 caml_seek_in + 229 RETURN 2 + 231 ACC0 + 232 C_CALL1 caml_pos_in + 234 RETURN 1 + 236 ACC0 + 237 C_CALL1 caml_channel_size + 239 RETURN 1 + 241 ACC0 + 242 C_CALL1 caml_close_channel + 244 RETURN 1 + 246 RESTART + 247 GRAB 1 + 249 ACC1 + 250 PUSHACC1 + 251 C_CALL2 caml_set_binary_mode + 253 RETURN 2 + 255 CONST0 + 256 PUSHENVACC1 + 257 APPLY1 + 258 ACC0 + 259 C_CALL1 sys_exit + 261 RETURN 1 + 263 CONST0 + 264 PUSHENVACC1 + 265 GETFIELD0 + 266 APPTERM1 2 + 268 CONST0 + 269 PUSHENVACC1 + 270 APPLY1 + 271 CONST0 + 272 PUSHENVACC2 + 273 APPTERM1 2 + 275 ENVACC1 + 276 GETFIELD0 + 277 PUSHACC0 + 278 PUSHACC2 + 279 CLOSURE 2, 268 + 282 PUSHENVACC1 + 283 SETFIELD0 + 284 RETURN 2 + 286 ENVACC1 + 287 C_CALL1 caml_flush + 289 ENVACC2 + 290 C_CALL1 caml_flush + 292 RETURN 1 + 294 CONST0 + 295 PUSHENVACC1 + 296 APPLY1 + 297 C_CALL1 float_of_string + 299 RETURN 1 + 301 CONST0 + 302 PUSHENVACC1 + 303 APPLY1 + 304 C_CALL1 int_of_string + 306 RETURN 1 + 308 ENVACC2 + 309 C_CALL1 caml_flush + 311 ENVACC1 + 312 PUSHENVACC3 + 313 APPTERM1 2 + 315 CONSTINT 13 + 317 PUSHENVACC1 + 318 C_CALL2 caml_output_char + 320 ENVACC1 + 321 C_CALL1 caml_flush + 323 RETURN 1 + 325 ACC0 + 326 PUSHENVACC1 + 327 PUSHENVACC2 + 328 APPLY2 + 329 CONSTINT 13 + 331 PUSHENVACC1 + 332 C_CALL2 caml_output_char + 334 ENVACC1 + 335 C_CALL1 caml_flush + 337 RETURN 1 + 339 ACC0 + 340 PUSHENVACC1 + 341 APPLY1 + 342 PUSHENVACC2 + 343 PUSHENVACC3 + 344 APPTERM2 3 + 346 ACC0 + 347 PUSHENVACC1 + 348 APPLY1 + 349 PUSHENVACC2 + 350 PUSHENVACC3 + 351 APPTERM2 3 + 353 ACC0 + 354 PUSHENVACC1 + 355 PUSHENVACC2 + 356 APPTERM2 3 + 358 ACC0 + 359 PUSHENVACC1 + 360 C_CALL2 caml_output_char + 362 RETURN 1 + 364 CONSTINT 13 + 366 PUSHENVACC1 + 367 C_CALL2 caml_output_char + 369 ENVACC1 + 370 C_CALL1 caml_flush + 372 RETURN 1 + 374 ACC0 + 375 PUSHENVACC1 + 376 PUSHENVACC2 + 377 APPLY2 + 378 CONSTINT 13 + 380 PUSHENVACC1 + 381 C_CALL2 caml_output_char + 383 RETURN 1 + 385 ACC0 + 386 PUSHENVACC1 + 387 APPLY1 + 388 PUSHENVACC2 + 389 PUSHENVACC3 + 390 APPTERM2 3 + 392 ACC0 + 393 PUSHENVACC1 + 394 APPLY1 + 395 PUSHENVACC2 + 396 PUSHENVACC3 + 397 APPTERM2 3 + 399 ACC0 + 400 PUSHENVACC1 + 401 PUSHENVACC2 + 402 APPTERM2 3 + 404 ACC0 + 405 PUSHENVACC1 + 406 C_CALL2 caml_output_char + 408 RETURN 1 + 410 RESTART + 411 GRAB 3 + 413 CONST0 + 414 PUSHACC3 + 415 LTINT + 416 BRANCHIF 427 + 418 ACC1 + 419 C_CALL1 ml_string_length + 421 PUSHACC4 + 422 PUSHACC4 + 423 ADDINT + 424 GTINT + 425 BRANCHIFNOT 432 + 427 GETGLOBAL "really_input" + 429 PUSHENVACC1 + 430 APPTERM1 5 + 432 ACC3 + 433 PUSHACC3 + 434 PUSHACC3 + 435 PUSHACC3 + 436 PUSHENVACC2 + 437 APPTERM 4, 8 + 440 RESTART + 441 GRAB 3 + 443 CONST0 + 444 PUSHACC3 + 445 LTINT + 446 BRANCHIF 457 + 448 ACC1 + 449 C_CALL1 ml_string_length + 451 PUSHACC4 + 452 PUSHACC4 + 453 ADDINT + 454 GTINT + 455 BRANCHIFNOT 462 + 457 GETGLOBAL "input" + 459 PUSHENVACC1 + 460 APPTERM1 5 + 462 ACC3 + 463 PUSHACC3 + 464 PUSHACC3 + 465 PUSHACC3 + 466 C_CALL4 caml_input + 468 RETURN 4 + 470 ACC0 + 471 PUSHCONST0 + 472 PUSHGETGLOBAL <0>(0, <0>(6, 0)) + 474 PUSHENVACC1 + 475 APPTERM3 4 + 477 ACC0 + 478 PUSHCONST0 + 479 PUSHGETGLOBAL <0>(0, <0>(7, 0)) + 481 PUSHENVACC1 + 482 APPTERM3 4 + 484 RESTART + 485 GRAB 2 + 487 ACC1 + 488 PUSHACC1 + 489 PUSHACC4 + 490 C_CALL3 sys_open + 492 C_CALL1 caml_open_descriptor + 494 RETURN 3 + 496 ACC0 + 497 C_CALL1 caml_flush + 499 ACC0 + 500 C_CALL1 caml_close_channel + 502 RETURN 1 + 504 RESTART + 505 GRAB 1 + 507 CONST0 + 508 PUSHACC2 + 509 PUSHACC2 + 510 C_CALL3 output_value + 512 RETURN 2 + 514 RESTART + 515 GRAB 3 + 517 CONST0 + 518 PUSHACC3 + 519 LTINT + 520 BRANCHIF 531 + 522 ACC1 + 523 C_CALL1 ml_string_length + 525 PUSHACC4 + 526 PUSHACC4 + 527 ADDINT + 528 GTINT + 529 BRANCHIFNOT 536 + 531 GETGLOBAL "output" + 533 PUSHENVACC1 + 534 APPTERM1 5 + 536 ACC3 + 537 PUSHACC3 + 538 PUSHACC3 + 539 PUSHACC3 + 540 C_CALL4 caml_output + 542 RETURN 4 + 544 RESTART + 545 GRAB 1 + 547 ACC1 + 548 C_CALL1 ml_string_length + 550 PUSHCONST0 + 551 PUSHACC3 + 552 PUSHACC3 + 553 C_CALL4 caml_output + 555 RETURN 2 + 557 ACC0 + 558 PUSHCONSTINT 438 + 560 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(6, 0)))) + 562 PUSHENVACC1 + 563 APPTERM3 4 + 565 ACC0 + 566 PUSHCONSTINT 438 + 568 PUSHGETGLOBAL <0>(1, <0>(3, <0>(4, <0>(7, 0)))) + 570 PUSHENVACC1 + 571 APPTERM3 4 + 573 RESTART + 574 GRAB 2 + 576 ACC1 + 577 PUSHACC1 + 578 PUSHACC4 + 579 C_CALL3 sys_open + 581 C_CALL1 caml_open_descriptor + 583 RETURN 3 + 585 ACC0 + 586 PUSHGETGLOBAL "%.12g" + 588 C_CALL2 format_float + 590 RETURN 1 + 592 ACC0 + 593 PUSHGETGLOBAL "%d" + 595 C_CALL2 format_int + 597 RETURN 1 + 599 GETGLOBAL "false" + 601 PUSHACC1 + 602 C_CALL2 string_equal + 604 BRANCHIFNOT 609 + 606 CONST0 + 607 RETURN 1 + 609 GETGLOBAL "true" + 611 PUSHACC1 + 612 C_CALL2 string_equal + 614 BRANCHIFNOT 619 + 616 CONST1 + 617 RETURN 1 + 619 GETGLOBAL "bool_of_string" + 621 PUSHENVACC1 + 622 APPTERM1 2 + 624 ACC0 + 625 BRANCHIFNOT 631 + 627 GETGLOBAL "true" + 629 RETURN 1 + 631 GETGLOBAL "false" + 633 RETURN 1 + 635 CONST0 + 636 PUSHACC1 + 637 LTINT + 638 BRANCHIF 646 + 640 CONSTINT 255 + 642 PUSHACC1 + 643 GTINT + 644 BRANCHIFNOT 651 + 646 GETGLOBAL "char_of_int" + 648 PUSHENVACC1 + 649 APPTERM1 2 + 651 ACC0 + 652 RETURN 1 + 654 RESTART + 655 GRAB 1 + 657 ACC0 + 658 C_CALL1 ml_string_length + 660 PUSHACC2 + 661 C_CALL1 ml_string_length + 663 PUSHACC0 + 664 PUSHACC2 + 665 ADDINT + 666 C_CALL1 create_string + 668 PUSHACC2 + 669 PUSHCONST0 + 670 PUSHACC2 + 671 PUSHCONST0 + 672 PUSHACC7 + 673 C_CALL5 blit_string + 675 ACC1 + 676 PUSHACC3 + 677 PUSHACC2 + 678 PUSHCONST0 + 679 PUSHACC 8 + 681 C_CALL5 blit_string + 683 ACC0 + 684 RETURN 5 + 686 CONSTINT -1 + 688 PUSHACC1 + 689 XORINT + 690 RETURN 1 + 692 CONST0 + 693 PUSHACC1 + 694 GEINT + 695 BRANCHIFNOT 700 + 697 ACC0 + 698 RETURN 1 + 700 ACC0 + 701 NEGINT + 702 RETURN 1 + 704 RESTART + 705 GRAB 1 + 707 ACC1 + 708 PUSHACC1 + 709 C_CALL2 greaterequal + 711 BRANCHIFNOT 716 + 713 ACC0 + 714 RETURN 2 + 716 ACC1 + 717 RETURN 2 + 719 RESTART + 720 GRAB 1 + 722 ACC1 + 723 PUSHACC1 + 724 C_CALL2 lessequal + 726 BRANCHIFNOT 731 + 728 ACC0 + 729 RETURN 2 + 731 ACC1 + 732 RETURN 2 + 734 ACC0 + 735 PUSHGETGLOBAL Invalid_argument + 737 MAKEBLOCK2 0 + 739 RAISE + 740 ACC0 + 741 PUSHGETGLOBAL Failure + 743 MAKEBLOCK2 0 + 745 RAISE + 746 CLOSURE 0, 740 + 749 PUSH + 750 CLOSURE 0, 734 + 753 PUSHGETGLOBAL "Pervasives.Exit" + 755 MAKEBLOCK1 0 + 757 PUSHGETGLOBAL "Pervasives.Assert_failure" + 759 MAKEBLOCK1 0 + 761 PUSH + 762 CLOSURE 0, 720 + 765 PUSH + 766 CLOSURE 0, 705 + 769 PUSH + 770 CLOSURE 0, 692 + 773 PUSH + 774 CLOSURE 0, 686 + 777 PUSHCONST0 + 778 PUSHCONSTINT 31 + 780 PUSHCONST1 + 781 LSLINT + 782 EQ + 783 BRANCHIFNOT 789 + 785 CONSTINT 30 + 787 BRANCH 791 + 789 CONSTINT 62 + 791 PUSHCONST1 + 792 LSLINT + 793 PUSHACC0 + 794 OFFSETINT -1 + 796 PUSH + 797 CLOSURE 0, 655 + 800 PUSHACC 9 + 802 CLOSURE 1, 635 + 805 PUSH + 806 CLOSURE 0, 624 + 809 PUSHACC 11 + 811 CLOSURE 1, 599 + 814 PUSH + 815 CLOSURE 0, 592 + 818 PUSH + 819 CLOSURE 0, 585 + 822 PUSH + 823 CLOSUREREC 0, 12 + 827 CONST0 + 828 C_CALL1 caml_open_descriptor + 830 PUSHCONST1 + 831 C_CALL1 caml_open_descriptor + 833 PUSHCONST2 + 834 C_CALL1 caml_open_descriptor + 836 PUSH + 837 CLOSURE 0, 574 + 840 PUSHACC0 + 841 CLOSURE 1, 565 + 844 PUSHACC1 + 845 CLOSURE 1, 557 + 848 PUSH + 849 CLOSURE 0, 545 + 852 PUSHACC 22 + 854 CLOSURE 1, 515 + 857 PUSH + 858 CLOSURE 0, 505 + 861 PUSH + 862 CLOSURE 0, 496 + 865 PUSH + 866 CLOSURE 0, 485 + 869 PUSHACC0 + 870 CLOSURE 1, 477 + 873 PUSHACC1 + 874 CLOSURE 1, 470 + 877 PUSHACC 28 + 879 CLOSURE 1, 441 + 882 PUSH + 883 CLOSUREREC 0, 32 + 887 ACC0 + 888 PUSHACC 31 + 890 CLOSURE 2, 411 + 893 PUSHACC 22 + 895 CLOSUREREC 1, 70 + 899 ACC 15 + 901 CLOSURE 1, 404 + 904 PUSHACC 11 + 906 PUSHACC 17 + 908 CLOSURE 2, 399 + 911 PUSHACC 12 + 913 PUSHACC 18 + 915 PUSHACC 23 + 917 CLOSURE 3, 392 + 920 PUSHACC 13 + 922 PUSHACC 19 + 924 PUSHACC 23 + 926 CLOSURE 3, 385 + 929 PUSHACC 14 + 931 PUSHACC 20 + 933 CLOSURE 2, 374 + 936 PUSHACC 20 + 938 CLOSURE 1, 364 + 941 PUSHACC 20 + 943 CLOSURE 1, 358 + 946 PUSHACC 17 + 948 PUSHACC 22 + 950 CLOSURE 2, 353 + 953 PUSHACC 18 + 955 PUSHACC 23 + 957 PUSHACC 29 + 959 CLOSURE 3, 346 + 962 PUSHACC 19 + 964 PUSHACC 24 + 966 PUSHACC 29 + 968 CLOSURE 3, 339 + 971 PUSHACC 20 + 973 PUSHACC 25 + 975 CLOSURE 2, 325 + 978 PUSHACC 25 + 980 CLOSURE 1, 315 + 983 PUSHACC 12 + 985 PUSHACC 28 + 987 PUSHACC 30 + 989 CLOSURE 3, 308 + 992 PUSHACC0 + 993 CLOSURE 1, 301 + 996 PUSHACC1 + 997 CLOSURE 1, 294 + 1000 PUSHACC 29 + 1002 PUSHACC 31 + 1004 CLOSURE 2, 286 + 1007 MAKEBLOCK1 0 + 1009 PUSHACC0 + 1010 CLOSURE 1, 275 + 1013 PUSHACC1 + 1014 CLOSURE 1, 263 + 1017 PUSHACC0 + 1018 CLOSURE 1, 255 + 1021 PUSHACC1 + 1022 PUSHACC 22 + 1024 PUSHACC4 + 1025 PUSHACC3 + 1026 PUSH + 1027 CLOSURE 0, 247 + 1030 PUSH + 1031 CLOSURE 0, 241 + 1034 PUSH + 1035 CLOSURE 0, 236 + 1038 PUSH + 1039 CLOSURE 0, 231 + 1042 PUSH + 1043 CLOSURE 0, 223 + 1046 PUSH + 1047 CLOSURE 0, 217 + 1050 PUSH + 1051 CLOSURE 0, 212 + 1054 PUSH + 1055 CLOSURE 0, 207 + 1058 PUSHACC 32 + 1060 PUSHACC 35 + 1062 PUSHACC 33 + 1064 PUSH + 1065 CLOSURE 0, 202 + 1068 PUSHACC 41 + 1070 PUSHACC 40 + 1072 PUSHACC 42 + 1074 PUSH + 1075 CLOSURE 0, 194 + 1078 PUSHACC 46 + 1080 PUSH + 1081 CLOSURE 0, 188 + 1084 PUSH + 1085 CLOSURE 0, 183 + 1088 PUSH + 1089 CLOSURE 0, 175 + 1092 PUSHACC 51 + 1094 PUSH + 1095 CLOSURE 0, 166 + 1098 PUSH + 1099 CLOSURE 0, 157 + 1102 PUSHACC 55 + 1104 PUSHACC 57 + 1106 PUSH + 1107 CLOSURE 0, 148 + 1110 PUSH + 1111 CLOSURE 0, 142 + 1114 PUSHACC 63 + 1116 PUSHACC 62 + 1118 PUSHACC 64 + 1120 PUSHACC 38 + 1122 PUSHACC 40 + 1124 PUSHACC 42 + 1126 PUSHACC 44 + 1128 PUSHACC 46 + 1130 PUSHACC 48 + 1132 PUSHACC 50 + 1134 PUSHACC 52 + 1136 PUSHACC 54 + 1138 PUSHACC 56 + 1140 PUSHACC 58 + 1142 PUSHACC 60 + 1144 PUSHACC 62 + 1146 PUSHACC 64 + 1148 PUSHACC 66 + 1150 PUSHACC 82 + 1152 PUSHACC 84 + 1154 PUSHACC 86 + 1156 PUSHACC 88 + 1158 PUSHACC 90 + 1160 PUSHACC 92 + 1162 PUSHACC 94 + 1164 PUSHACC 96 + 1166 PUSHACC 98 + 1168 PUSHACC 100 + 1170 PUSHACC 104 + 1172 PUSHACC 104 + 1174 PUSHACC 104 + 1176 PUSHACC 108 + 1178 PUSHACC 110 + 1180 PUSHACC 112 + 1182 PUSHACC 117 + 1184 PUSHACC 117 + 1186 PUSHACC 117 + 1188 PUSHACC 117 + 1190 MAKEBLOCK 69, 0 + 1193 POP 53 + 1195 SETGLOBAL Pervasives + 1197 BRANCH 2177 + 1199 RESTART + 1200 GRAB 1 + 1202 ACC1 + 1203 BRANCHIFNOT 1213 + 1205 ACC1 + 1206 GETFIELD1 + 1207 PUSHACC1 + 1208 OFFSETINT 1 + 1210 PUSHOFFSETCLOSURE0 + 1211 APPTERM2 4 + 1213 ACC0 + 1214 RETURN 2 + 1216 RESTART + 1217 GRAB 1 + 1219 ACC0 + 1220 BRANCHIFNOT 1251 + 1222 CONST0 + 1223 PUSHACC2 + 1224 EQ + 1225 BRANCHIFNOT 1231 + 1227 ACC0 + 1228 GETFIELD0 + 1229 RETURN 2 + 1231 CONST0 + 1232 PUSHACC2 + 1233 GTINT + 1234 BRANCHIFNOT 1244 + 1236 ACC1 + 1237 OFFSETINT -1 + 1239 PUSHACC1 + 1240 GETFIELD1 + 1241 PUSHOFFSETCLOSURE0 + 1242 APPTERM2 4 + 1244 GETGLOBAL "List.nth" + 1246 PUSHGETGLOBALFIELD Pervasives, 2 + 1249 APPTERM1 3 + 1251 GETGLOBAL "nth" + 1253 PUSHGETGLOBALFIELD Pervasives, 3 + 1256 APPTERM1 3 + 1258 RESTART + 1259 GRAB 1 + 1261 ACC0 + 1262 BRANCHIFNOT 1274 + 1264 ACC1 + 1265 PUSHACC1 + 1266 GETFIELD0 + 1267 MAKEBLOCK2 0 + 1269 PUSHACC1 + 1270 GETFIELD1 + 1271 PUSHOFFSETCLOSURE0 + 1272 APPTERM2 4 + 1274 ACC1 + 1275 RETURN 2 + 1277 ACC0 + 1278 BRANCHIFNOT 1291 + 1280 ACC0 + 1281 GETFIELD1 + 1282 PUSHOFFSETCLOSURE0 + 1283 APPLY1 + 1284 PUSHACC1 + 1285 GETFIELD0 + 1286 PUSHGETGLOBALFIELD Pervasives, 16 + 1289 APPTERM2 3 + 1291 RETURN 1 + 1293 RESTART + 1294 GRAB 1 + 1296 ACC1 + 1297 BRANCHIFNOT 1313 + 1299 ACC1 + 1300 GETFIELD0 + 1301 PUSHACC1 + 1302 APPLY1 + 1303 PUSHACC2 + 1304 GETFIELD1 + 1305 PUSHACC2 + 1306 PUSHOFFSETCLOSURE0 + 1307 APPLY2 + 1308 PUSHACC1 + 1309 MAKEBLOCK2 0 + 1311 POP 1 + 1313 RETURN 2 + 1315 RESTART + 1316 GRAB 1 + 1318 ACC1 + 1319 BRANCHIFNOT 1331 + 1321 ACC1 + 1322 GETFIELD0 + 1323 PUSHACC1 + 1324 APPLY1 + 1325 ACC1 + 1326 GETFIELD1 + 1327 PUSHACC1 + 1328 PUSHOFFSETCLOSURE0 + 1329 APPTERM2 4 + 1331 RETURN 2 + 1333 RESTART + 1334 GRAB 2 + 1336 ACC2 + 1337 BRANCHIFNOT 1350 + 1339 ACC2 + 1340 GETFIELD1 + 1341 PUSHACC3 + 1342 GETFIELD0 + 1343 PUSHACC3 + 1344 PUSHACC3 + 1345 APPLY2 + 1346 PUSHACC2 + 1347 PUSHOFFSETCLOSURE0 + 1348 APPTERM3 6 + 1350 ACC1 + 1351 RETURN 3 + 1353 RESTART + 1354 GRAB 2 + 1356 ACC1 + 1357 BRANCHIFNOT 1370 + 1359 ACC2 + 1360 PUSHACC2 + 1361 GETFIELD1 + 1362 PUSHACC2 + 1363 PUSHOFFSETCLOSURE0 + 1364 APPLY3 + 1365 PUSHACC2 + 1366 GETFIELD0 + 1367 PUSHACC2 + 1368 APPTERM2 5 + 1370 ACC2 + 1371 RETURN 3 + 1373 RESTART + 1374 GRAB 2 + 1376 ACC1 + 1377 BRANCHIFNOT 1400 + 1379 ACC2 + 1380 BRANCHIFNOT 1407 + 1382 ACC2 + 1383 GETFIELD0 + 1384 PUSHACC2 + 1385 GETFIELD0 + 1386 PUSHACC2 + 1387 APPLY2 + 1388 PUSHACC3 + 1389 GETFIELD1 + 1390 PUSHACC3 + 1391 GETFIELD1 + 1392 PUSHACC3 + 1393 PUSHOFFSETCLOSURE0 + 1394 APPLY3 + 1395 PUSHACC1 + 1396 MAKEBLOCK2 0 + 1398 RETURN 4 + 1400 ACC2 + 1401 BRANCHIFNOT 1405 + 1403 BRANCH 1407 + 1405 RETURN 3 + 1407 GETGLOBAL "List.map2" + 1409 PUSHGETGLOBALFIELD Pervasives, 2 + 1412 APPTERM1 4 + 1414 RESTART + 1415 GRAB 2 + 1417 ACC1 + 1418 BRANCHIFNOT 1437 + 1420 ACC2 + 1421 BRANCHIFNOT 1444 + 1423 ACC2 + 1424 GETFIELD0 + 1425 PUSHACC2 + 1426 GETFIELD0 + 1427 PUSHACC2 + 1428 APPLY2 + 1429 ACC2 + 1430 GETFIELD1 + 1431 PUSHACC2 + 1432 GETFIELD1 + 1433 PUSHACC2 + 1434 PUSHOFFSETCLOSURE0 + 1435 APPTERM3 6 + 1437 ACC2 + 1438 BRANCHIFNOT 1442 + 1440 BRANCH 1444 + 1442 RETURN 3 + 1444 GETGLOBAL "List.iter2" + 1446 PUSHGETGLOBALFIELD Pervasives, 2 + 1449 APPTERM1 4 + 1451 RESTART + 1452 GRAB 3 + 1454 ACC2 + 1455 BRANCHIFNOT 1476 + 1457 ACC3 + 1458 BRANCHIFNOT 1482 + 1460 ACC3 + 1461 GETFIELD1 + 1462 PUSHACC3 + 1463 GETFIELD1 + 1464 PUSHACC5 + 1465 GETFIELD0 + 1466 PUSHACC5 + 1467 GETFIELD0 + 1468 PUSHACC5 + 1469 PUSHACC5 + 1470 APPLY3 + 1471 PUSHACC3 + 1472 PUSHOFFSETCLOSURE0 + 1473 APPTERM 4, 8 + 1476 ACC3 + 1477 BRANCHIF 1482 + 1479 ACC1 + 1480 RETURN 4 + 1482 GETGLOBAL "List.fold_left2" + 1484 PUSHGETGLOBALFIELD Pervasives, 2 + 1487 APPTERM1 5 + 1489 RESTART + 1490 GRAB 3 + 1492 ACC1 + 1493 BRANCHIFNOT 1516 + 1495 ACC2 + 1496 BRANCHIFNOT 1522 + 1498 PUSH_RETADDR 1509 + 1500 ACC6 + 1501 PUSHACC6 + 1502 GETFIELD1 + 1503 PUSHACC6 + 1504 GETFIELD1 + 1505 PUSHACC6 + 1506 PUSHOFFSETCLOSURE0 + 1507 APPLY 4 + 1509 PUSHACC3 + 1510 GETFIELD0 + 1511 PUSHACC3 + 1512 GETFIELD0 + 1513 PUSHACC3 + 1514 APPTERM3 7 + 1516 ACC2 + 1517 BRANCHIF 1522 + 1519 ACC3 + 1520 RETURN 4 + 1522 GETGLOBAL "List.fold_right2" + 1524 PUSHGETGLOBALFIELD Pervasives, 2 + 1527 APPTERM1 5 + 1529 RESTART + 1530 GRAB 1 + 1532 ACC1 + 1533 BRANCHIFNOT 1549 + 1535 ACC1 + 1536 GETFIELD0 + 1537 PUSHACC1 + 1538 APPLY1 + 1539 BRANCHIFNOT 1547 + 1541 ACC1 + 1542 GETFIELD1 + 1543 PUSHACC1 + 1544 PUSHOFFSETCLOSURE0 + 1545 APPTERM2 4 + 1547 RETURN 2 + 1549 CONST1 + 1550 RETURN 2 + 1552 RESTART + 1553 GRAB 1 + 1555 ACC1 + 1556 BRANCHIFNOT 1570 + 1558 ACC1 + 1559 GETFIELD0 + 1560 PUSHACC1 + 1561 APPLY1 + 1562 BRANCHIF 1570 + 1564 ACC1 + 1565 GETFIELD1 + 1566 PUSHACC1 + 1567 PUSHOFFSETCLOSURE0 + 1568 APPTERM2 4 + 1570 RETURN 2 + 1572 RESTART + 1573 GRAB 2 + 1575 ACC1 + 1576 BRANCHIFNOT 1599 + 1578 ACC2 + 1579 BRANCHIFNOT 1605 + 1581 ACC2 + 1582 GETFIELD0 + 1583 PUSHACC2 + 1584 GETFIELD0 + 1585 PUSHACC2 + 1586 APPLY2 + 1587 BRANCHIFNOT 1597 + 1589 ACC2 + 1590 GETFIELD1 + 1591 PUSHACC2 + 1592 GETFIELD1 + 1593 PUSHACC2 + 1594 PUSHOFFSETCLOSURE0 + 1595 APPTERM3 6 + 1597 RETURN 3 + 1599 ACC2 + 1600 BRANCHIF 1605 + 1602 CONST1 + 1603 RETURN 3 + 1605 GETGLOBAL "List.for_all2" + 1607 PUSHGETGLOBALFIELD Pervasives, 2 + 1610 APPTERM1 4 + 1612 RESTART + 1613 GRAB 2 + 1615 ACC1 + 1616 BRANCHIFNOT 1639 + 1618 ACC2 + 1619 BRANCHIFNOT 1646 + 1621 ACC2 + 1622 GETFIELD0 + 1623 PUSHACC2 + 1624 GETFIELD0 + 1625 PUSHACC2 + 1626 APPLY2 + 1627 BRANCHIF 1637 + 1629 ACC2 + 1630 GETFIELD1 + 1631 PUSHACC2 + 1632 GETFIELD1 + 1633 PUSHACC2 + 1634 PUSHOFFSETCLOSURE0 + 1635 APPTERM3 6 + 1637 RETURN 3 + 1639 ACC2 + 1640 BRANCHIFNOT 1644 + 1642 BRANCH 1646 + 1644 RETURN 3 + 1646 GETGLOBAL "List.exists2" + 1648 PUSHGETGLOBALFIELD Pervasives, 2 + 1651 APPTERM1 4 + 1653 RESTART + 1654 GRAB 1 + 1656 ACC1 + 1657 BRANCHIFNOT 1672 + 1659 ACC0 + 1660 PUSHACC2 + 1661 GETFIELD0 + 1662 C_CALL2 equal + 1664 BRANCHIF 1672 + 1666 ACC1 + 1667 GETFIELD1 + 1668 PUSHACC1 + 1669 PUSHOFFSETCLOSURE0 + 1670 APPTERM2 4 + 1672 RETURN 2 + 1674 RESTART + 1675 GRAB 1 + 1677 ACC1 + 1678 BRANCHIFNOT 1692 + 1680 ACC0 + 1681 PUSHACC2 + 1682 GETFIELD0 + 1683 EQ + 1684 BRANCHIF 1692 + 1686 ACC1 + 1687 GETFIELD1 + 1688 PUSHACC1 + 1689 PUSHOFFSETCLOSURE0 + 1690 APPTERM2 4 + 1692 RETURN 2 + 1694 RESTART + 1695 GRAB 1 + 1697 ACC1 + 1698 BRANCHIFNOT 1719 + 1700 ACC1 + 1701 GETFIELD0 + 1702 PUSHACC1 + 1703 PUSHACC1 + 1704 GETFIELD0 + 1705 C_CALL2 equal + 1707 BRANCHIFNOT 1713 + 1709 ACC0 + 1710 GETFIELD1 + 1711 RETURN 3 + 1713 ACC2 + 1714 GETFIELD1 + 1715 PUSHACC2 + 1716 PUSHOFFSETCLOSURE0 + 1717 APPTERM2 5 + 1719 GETGLOBAL Not_found + 1721 MAKEBLOCK1 0 + 1723 RAISE + 1724 RESTART + 1725 GRAB 1 + 1727 ACC1 + 1728 BRANCHIFNOT 1748 + 1730 ACC1 + 1731 GETFIELD0 + 1732 PUSHACC1 + 1733 PUSHACC1 + 1734 GETFIELD0 + 1735 EQ + 1736 BRANCHIFNOT 1742 + 1738 ACC0 + 1739 GETFIELD1 + 1740 RETURN 3 + 1742 ACC2 + 1743 GETFIELD1 + 1744 PUSHACC2 + 1745 PUSHOFFSETCLOSURE0 + 1746 APPTERM2 5 + 1748 GETGLOBAL Not_found + 1750 MAKEBLOCK1 0 + 1752 RAISE + 1753 RESTART + 1754 GRAB 1 + 1756 ACC1 + 1757 BRANCHIFNOT 1773 + 1759 ACC0 + 1760 PUSHACC2 + 1761 GETFIELD0 + 1762 GETFIELD0 + 1763 C_CALL2 equal + 1765 BRANCHIF 1773 + 1767 ACC1 + 1768 GETFIELD1 + 1769 PUSHACC1 + 1770 PUSHOFFSETCLOSURE0 + 1771 APPTERM2 4 + 1773 RETURN 2 + 1775 RESTART + 1776 GRAB 1 + 1778 ACC1 + 1779 BRANCHIFNOT 1794 + 1781 ACC0 + 1782 PUSHACC2 + 1783 GETFIELD0 + 1784 GETFIELD0 + 1785 EQ + 1786 BRANCHIF 1794 + 1788 ACC1 + 1789 GETFIELD1 + 1790 PUSHACC1 + 1791 PUSHOFFSETCLOSURE0 + 1792 APPTERM2 4 + 1794 RETURN 2 + 1796 RESTART + 1797 GRAB 1 + 1799 ACC1 + 1800 BRANCHIFNOT 1825 + 1802 ACC1 + 1803 GETFIELD0 + 1804 PUSHACC2 + 1805 GETFIELD1 + 1806 PUSHACC2 + 1807 PUSHACC2 + 1808 GETFIELD0 + 1809 C_CALL2 equal + 1811 BRANCHIFNOT 1816 + 1813 ACC0 + 1814 RETURN 4 + 1816 ACC0 + 1817 PUSHACC3 + 1818 PUSHOFFSETCLOSURE0 + 1819 APPLY2 + 1820 PUSHACC2 + 1821 MAKEBLOCK2 0 + 1823 POP 2 + 1825 RETURN 2 + 1827 RESTART + 1828 GRAB 1 + 1830 ACC1 + 1831 BRANCHIFNOT 1855 + 1833 ACC1 + 1834 GETFIELD0 + 1835 PUSHACC2 + 1836 GETFIELD1 + 1837 PUSHACC2 + 1838 PUSHACC2 + 1839 GETFIELD0 + 1840 EQ + 1841 BRANCHIFNOT 1846 + 1843 ACC0 + 1844 RETURN 4 + 1846 ACC0 + 1847 PUSHACC3 + 1848 PUSHOFFSETCLOSURE0 + 1849 APPLY2 + 1850 PUSHACC2 + 1851 MAKEBLOCK2 0 + 1853 POP 2 + 1855 RETURN 2 + 1857 RESTART + 1858 GRAB 1 + 1860 ACC1 + 1861 BRANCHIFNOT 1879 + 1863 ACC1 + 1864 GETFIELD0 + 1865 PUSHACC0 + 1866 PUSHACC2 + 1867 APPLY1 + 1868 BRANCHIFNOT 1873 + 1870 ACC0 + 1871 RETURN 3 + 1873 ACC2 + 1874 GETFIELD1 + 1875 PUSHACC2 + 1876 PUSHOFFSETCLOSURE0 + 1877 APPTERM2 5 + 1879 GETGLOBAL Not_found + 1881 MAKEBLOCK1 0 + 1883 RAISE + 1884 RESTART + 1885 GRAB 2 + 1887 ACC2 + 1888 BRANCHIFNOT 1917 + 1890 ACC2 + 1891 GETFIELD0 + 1892 PUSHACC3 + 1893 GETFIELD1 + 1894 PUSHACC1 + 1895 PUSHENVACC2 + 1896 APPLY1 + 1897 BRANCHIFNOT 1908 + 1899 ACC0 + 1900 PUSHACC4 + 1901 PUSHACC4 + 1902 PUSHACC4 + 1903 MAKEBLOCK2 0 + 1905 PUSHOFFSETCLOSURE0 + 1906 APPTERM3 8 + 1908 ACC0 + 1909 PUSHACC4 + 1910 PUSHACC3 + 1911 MAKEBLOCK2 0 + 1913 PUSHACC4 + 1914 PUSHOFFSETCLOSURE0 + 1915 APPTERM3 8 + 1917 ACC1 + 1918 PUSHENVACC1 + 1919 APPLY1 + 1920 PUSHACC1 + 1921 PUSHENVACC1 + 1922 APPLY1 + 1923 MAKEBLOCK2 0 + 1925 RETURN 3 + 1927 RESTART + 1928 GRAB 1 + 1930 ACC0 + 1931 PUSHENVACC1 + 1932 CLOSUREREC 2, 1885 + 1936 ACC2 + 1937 PUSHCONST0 + 1938 PUSHCONST0 + 1939 PUSHACC3 + 1940 APPTERM3 6 + 1942 ACC0 + 1943 BRANCHIFNOT 1967 + 1945 ACC0 + 1946 GETFIELD0 + 1947 PUSHACC1 + 1948 GETFIELD1 + 1949 PUSHOFFSETCLOSURE0 + 1950 APPLY1 + 1951 PUSHACC0 + 1952 GETFIELD1 + 1953 PUSHACC2 + 1954 GETFIELD1 + 1955 MAKEBLOCK2 0 + 1957 PUSHACC1 + 1958 GETFIELD0 + 1959 PUSHACC3 + 1960 GETFIELD0 + 1961 MAKEBLOCK2 0 + 1963 MAKEBLOCK2 0 + 1965 RETURN 3 + 1967 GETGLOBAL <0>(0, 0) + 1969 RETURN 1 + 1971 RESTART + 1972 GRAB 1 + 1974 ACC0 + 1975 BRANCHIFNOT 1996 + 1977 ACC1 + 1978 BRANCHIFNOT 2003 + 1980 ACC1 + 1981 GETFIELD1 + 1982 PUSHACC1 + 1983 GETFIELD1 + 1984 PUSHOFFSETCLOSURE0 + 1985 APPLY2 + 1986 PUSHACC2 + 1987 GETFIELD0 + 1988 PUSHACC2 + 1989 GETFIELD0 + 1990 MAKEBLOCK2 0 + 1992 MAKEBLOCK2 0 + 1994 RETURN 2 + 1996 ACC1 + 1997 BRANCHIFNOT 2001 + 1999 BRANCH 2003 + 2001 RETURN 2 + 2003 GETGLOBAL "List.combine" + 2005 PUSHGETGLOBALFIELD Pervasives, 2 + 2008 APPTERM1 3 + 2010 RESTART + 2011 GRAB 1 + 2013 ACC1 + 2014 BRANCHIFNOT 2038 + 2016 ACC1 + 2017 GETFIELD0 + 2018 PUSHACC2 + 2019 GETFIELD1 + 2020 PUSHACC1 + 2021 PUSHENVACC2 + 2022 APPLY1 + 2023 BRANCHIFNOT 2033 + 2025 ACC0 + 2026 PUSHACC3 + 2027 PUSHACC3 + 2028 MAKEBLOCK2 0 + 2030 PUSHOFFSETCLOSURE0 + 2031 APPTERM2 6 + 2033 ACC0 + 2034 PUSHACC3 + 2035 PUSHOFFSETCLOSURE0 + 2036 APPTERM2 6 + 2038 ACC0 + 2039 PUSHENVACC1 + 2040 APPTERM1 3 + 2042 ACC0 + 2043 PUSHENVACC1 + 2044 CLOSUREREC 2, 2011 + 2048 CONST0 + 2049 PUSHACC1 + 2050 APPTERM1 3 + 2052 RESTART + 2053 GRAB 2 + 2055 ACC1 + 2056 BRANCHIFNOT 2077 + 2058 ACC2 + 2059 BRANCHIFNOT 2084 + 2061 ACC2 + 2062 GETFIELD1 + 2063 PUSHACC2 + 2064 GETFIELD1 + 2065 PUSHACC2 + 2066 PUSHACC5 + 2067 GETFIELD0 + 2068 PUSHACC5 + 2069 GETFIELD0 + 2070 PUSHENVACC1 + 2071 APPLY2 + 2072 MAKEBLOCK2 0 + 2074 PUSHOFFSETCLOSURE0 + 2075 APPTERM3 6 + 2077 ACC2 + 2078 BRANCHIFNOT 2082 + 2080 BRANCH 2084 + 2082 RETURN 3 + 2084 GETGLOBAL "List.rev_map2" + 2086 PUSHGETGLOBALFIELD Pervasives, 2 + 2089 APPTERM1 4 + 2091 RESTART + 2092 GRAB 2 + 2094 ACC0 + 2095 CLOSUREREC 1, 2053 + 2099 ACC3 + 2100 PUSHACC3 + 2101 PUSHCONST0 + 2102 PUSHACC3 + 2103 APPTERM3 7 + 2105 RESTART + 2106 GRAB 1 + 2108 ACC1 + 2109 BRANCHIFNOT 2123 + 2111 ACC1 + 2112 GETFIELD1 + 2113 PUSHACC1 + 2114 PUSHACC3 + 2115 GETFIELD0 + 2116 PUSHENVACC1 + 2117 APPLY1 + 2118 MAKEBLOCK2 0 + 2120 PUSHOFFSETCLOSURE0 + 2121 APPTERM2 4 + 2123 ACC0 + 2124 RETURN 2 + 2126 RESTART + 2127 GRAB 1 + 2129 ACC0 + 2130 CLOSUREREC 1, 2106 + 2134 ACC2 + 2135 PUSHCONST0 + 2136 PUSHACC2 + 2137 APPTERM2 5 + 2139 CONST0 + 2140 PUSHACC1 + 2141 PUSHENVACC1 + 2142 APPTERM2 3 + 2144 ACC0 + 2145 BRANCHIFNOT 2151 + 2147 ACC0 + 2148 GETFIELD1 + 2149 RETURN 1 + 2151 GETGLOBAL "tl" + 2153 PUSHGETGLOBALFIELD Pervasives, 3 + 2156 APPTERM1 2 + 2158 ACC0 + 2159 BRANCHIFNOT 2165 + 2161 ACC0 + 2162 GETFIELD0 + 2163 RETURN 1 + 2165 GETGLOBAL "hd" + 2167 PUSHGETGLOBALFIELD Pervasives, 3 + 2170 APPTERM1 2 + 2172 ACC0 + 2173 PUSHCONST0 + 2174 PUSHENVACC1 + 2175 APPTERM2 3 + 2177 CLOSUREREC 0, 1200 + 2181 ACC0 + 2182 CLOSURE 1, 2172 + 2185 PUSH + 2186 CLOSURE 0, 2158 + 2189 PUSH + 2190 CLOSURE 0, 2144 + 2193 PUSH + 2194 CLOSUREREC 0, 1217 + 2198 GETGLOBALFIELD Pervasives, 16 + 2201 PUSH + 2202 CLOSUREREC 0, 1259 + 2206 ACC0 + 2207 CLOSURE 1, 2139 + 2210 PUSH + 2211 CLOSUREREC 0, 1277 + 2215 CLOSUREREC 0, 1294 + 2219 CLOSURE 0, 2127 + 2222 PUSH + 2223 CLOSUREREC 0, 1316 + 2227 CLOSUREREC 0, 1334 + 2231 CLOSUREREC 0, 1354 + 2235 CLOSUREREC 0, 1374 + 2239 CLOSURE 0, 2092 + 2242 PUSH + 2243 CLOSUREREC 0, 1415 + 2247 CLOSUREREC 0, 1452 + 2251 CLOSUREREC 0, 1490 + 2255 CLOSUREREC 0, 1530 + 2259 CLOSUREREC 0, 1553 + 2263 CLOSUREREC 0, 1573 + 2267 CLOSUREREC 0, 1613 + 2271 CLOSUREREC 0, 1654 + 2275 CLOSUREREC 0, 1675 + 2279 CLOSUREREC 0, 1695 + 2283 CLOSUREREC 0, 1725 + 2287 CLOSUREREC 0, 1754 + 2291 CLOSUREREC 0, 1776 + 2295 CLOSUREREC 0, 1797 + 2299 CLOSUREREC 0, 1828 + 2303 CLOSUREREC 0, 1858 + 2307 ACC 24 + 2309 CLOSURE 1, 2042 + 2312 PUSHACC 25 + 2314 CLOSUREREC 1, 1928 + 2318 CLOSUREREC 0, 1942 + 2322 CLOSUREREC 0, 1972 + 2326 ACC0 + 2327 PUSHACC2 + 2328 PUSHACC7 + 2329 PUSHACC 9 + 2331 PUSHACC 11 + 2333 PUSHACC 13 + 2335 PUSHACC 15 + 2337 PUSHACC 17 + 2339 PUSHACC 10 + 2341 PUSHACC 12 + 2343 PUSHACC 13 + 2345 PUSHACC 15 + 2347 PUSHACC 23 + 2349 PUSHACC 25 + 2351 PUSHACC 27 + 2353 PUSHACC 29 + 2355 PUSHACC 31 + 2357 PUSHACC 33 + 2359 PUSHACC 35 + 2361 PUSHACC 37 + 2363 PUSHACC 40 + 2365 PUSHACC 42 + 2367 PUSHACC 41 + 2369 PUSHACC 45 + 2371 PUSHACC 47 + 2373 PUSHACC 50 + 2375 PUSHACC 52 + 2377 PUSHACC 51 + 2379 PUSHACC 55 + 2381 PUSHACC 56 + 2383 PUSHACC 59 + 2385 PUSHACC 61 + 2387 PUSHACC 60 + 2389 PUSHACC 64 + 2391 PUSHACC 66 + 2393 PUSHACC 68 + 2395 PUSHACC 70 + 2397 MAKEBLOCK 37, 0 + 2400 POP 36 + 2402 SETGLOBAL List + 2404 BRANCH 2622 + 2406 CONSTINT 97 + 2408 PUSHACC1 + 2409 GEINT + 2410 BRANCHIFNOT 2418 + 2412 CONSTINT 122 + 2414 PUSHACC1 + 2415 LEINT + 2416 BRANCHIF 2442 + 2418 CONSTINT 224 + 2420 PUSHACC1 + 2421 GEINT + 2422 BRANCHIFNOT 2430 + 2424 CONSTINT 246 + 2426 PUSHACC1 + 2427 LEINT + 2428 BRANCHIF 2442 + 2430 CONSTINT 248 + 2432 PUSHACC1 + 2433 GEINT + 2434 BRANCHIFNOT 2447 + 2436 CONSTINT 254 + 2438 PUSHACC1 + 2439 LEINT + 2440 BRANCHIFNOT 2447 + 2442 ACC0 + 2443 OFFSETINT -32 + 2445 RETURN 1 + 2447 ACC0 + 2448 RETURN 1 + 2450 CONSTINT 65 + 2452 PUSHACC1 + 2453 GEINT + 2454 BRANCHIFNOT 2462 + 2456 CONSTINT 90 + 2458 PUSHACC1 + 2459 LEINT + 2460 BRANCHIF 2486 + 2462 CONSTINT 192 + 2464 PUSHACC1 + 2465 GEINT + 2466 BRANCHIFNOT 2474 + 2468 CONSTINT 214 + 2470 PUSHACC1 + 2471 LEINT + 2472 BRANCHIF 2486 + 2474 CONSTINT 216 + 2476 PUSHACC1 + 2477 GEINT + 2478 BRANCHIFNOT 2491 + 2480 CONSTINT 222 + 2482 PUSHACC1 + 2483 LEINT + 2484 BRANCHIFNOT 2491 + 2486 ACC0 + 2487 OFFSETINT 32 + 2489 RETURN 1 + 2491 ACC0 + 2492 RETURN 1 + 2494 CONSTINT 39 + 2496 PUSHACC1 + 2497 LTINT + 2498 BRANCHIFNOT 2520 + 2500 CONSTINT 9 + 2502 PUSHACC1 + 2503 EQ + 2504 BRANCHIFNOT 2510 + 2506 GETGLOBAL "\\t" + 2508 RETURN 1 + 2510 CONSTINT 13 + 2512 PUSHACC1 + 2513 EQ + 2514 BRANCHIFNOT 2540 + 2516 GETGLOBAL "\\n" + 2518 RETURN 1 + 2520 CONSTINT 39 + 2522 PUSHACC1 + 2523 EQ + 2524 BRANCHIFNOT 2530 + 2526 GETGLOBAL "\\'" + 2528 RETURN 1 + 2530 CONSTINT 92 + 2532 PUSHACC1 + 2533 EQ + 2534 BRANCHIFNOT 2540 + 2536 GETGLOBAL "\\\\" + 2538 RETURN 1 + 2540 ACC0 + 2541 C_CALL1 is_printable + 2543 BRANCHIFNOT 2555 + 2545 CONST1 + 2546 C_CALL1 create_string + 2548 PUSHACC1 + 2549 PUSHCONST0 + 2550 PUSHACC2 + 2551 SETSTRINGCHAR + 2552 ACC0 + 2553 RETURN 2 + 2555 ACC0 + 2556 PUSHCONSTINT 4 + 2558 C_CALL1 create_string + 2560 PUSHCONSTINT 92 + 2562 PUSHCONST0 + 2563 PUSHACC2 + 2564 SETSTRINGCHAR + 2565 CONSTINT 100 + 2567 PUSHACC2 + 2568 DIVINT + 2569 PUSHCONSTINT 48 + 2571 ADDINT + 2572 PUSHCONST1 + 2573 PUSHACC2 + 2574 SETSTRINGCHAR + 2575 CONSTINT 10 + 2577 PUSHCONSTINT 10 + 2579 PUSHACC3 + 2580 DIVINT + 2581 MODINT + 2582 PUSHCONSTINT 48 + 2584 ADDINT + 2585 PUSHCONST2 + 2586 PUSHACC2 + 2587 SETSTRINGCHAR + 2588 CONSTINT 10 + 2590 PUSHACC2 + 2591 MODINT + 2592 PUSHCONSTINT 48 + 2594 ADDINT + 2595 PUSHCONST3 + 2596 PUSHACC2 + 2597 SETSTRINGCHAR + 2598 ACC0 + 2599 RETURN 3 + 2601 CONST0 + 2602 PUSHACC1 + 2603 LTINT + 2604 BRANCHIF 2612 + 2606 CONSTINT 255 + 2608 PUSHACC1 + 2609 GTINT + 2610 BRANCHIFNOT 2619 + 2612 GETGLOBAL "Char.chr" + 2614 PUSHGETGLOBALFIELD Pervasives, 2 + 2617 APPTERM1 2 + 2619 ACC0 + 2620 RETURN 1 + 2622 CLOSURE 0, 2601 + 2625 PUSH + 2626 CLOSURE 0, 2494 + 2629 PUSH + 2630 CLOSURE 0, 2450 + 2633 PUSH + 2634 CLOSURE 0, 2406 + 2637 PUSHACC0 + 2638 PUSHACC2 + 2639 PUSHACC4 + 2640 PUSHACC6 + 2641 MAKEBLOCK 4, 0 + 2644 POP 4 + 2646 SETGLOBAL Char + 2648 BRANCH 3540 + 2650 RESTART + 2651 GRAB 3 + 2653 ACC1 + 2654 PUSHACC3 + 2655 GEINT + 2656 BRANCHIFNOT 2663 + 2658 GETGLOBAL Not_found + 2660 MAKEBLOCK1 0 + 2662 RAISE + 2663 ACC3 + 2664 PUSHACC3 + 2665 PUSHACC2 + 2666 GETSTRINGCHAR + 2667 EQ + 2668 BRANCHIFNOT 2673 + 2670 ACC2 + 2671 RETURN 4 + 2673 ACC3 + 2674 PUSHACC3 + 2675 OFFSETINT 1 + 2677 PUSHACC3 + 2678 PUSHACC3 + 2679 PUSHOFFSETCLOSURE0 + 2680 APPTERM 4, 8 + 2683 RESTART + 2684 GRAB 2 + 2686 CONST0 + 2687 PUSHACC2 + 2688 LTINT + 2689 BRANCHIFNOT 2696 + 2691 GETGLOBAL Not_found + 2693 MAKEBLOCK1 0 + 2695 RAISE + 2696 ACC2 + 2697 PUSHACC2 + 2698 PUSHACC2 + 2699 GETSTRINGCHAR + 2700 EQ + 2701 BRANCHIFNOT 2706 + 2703 ACC1 + 2704 RETURN 3 + 2706 ACC2 + 2707 PUSHACC2 + 2708 OFFSETINT -1 + 2710 PUSHACC2 + 2711 PUSHOFFSETCLOSURE0 + 2712 APPTERM3 6 + 2714 RESTART + 2715 GRAB 1 + 2717 ACC1 + 2718 PUSHCONST0 + 2719 PUSHACC2 + 2720 PUSHENVACC1 + 2721 APPTERM3 5 + 2723 RESTART + 2724 GRAB 2 + 2726 CONST0 + 2727 PUSHACC2 + 2728 LTINT + 2729 BRANCHIF 2738 + 2731 ACC0 + 2732 C_CALL1 ml_string_length + 2734 PUSHACC2 + 2735 GEINT + 2736 BRANCHIFNOT 2745 + 2738 GETGLOBAL "String.rcontains_from" + 2740 PUSHGETGLOBALFIELD Pervasives, 2 + 2743 APPTERM1 4 + 2745 PUSHTRAP 2756 + 2747 ACC6 + 2748 PUSHACC6 + 2749 PUSHACC6 + 2750 PUSHENVACC1 + 2751 APPLY3 + 2752 CONST1 + 2753 POPTRAP + 2754 RETURN 3 + 2756 PUSHGETGLOBAL Not_found + 2758 PUSHACC1 + 2759 GETFIELD0 + 2760 EQ + 2761 BRANCHIFNOT 2766 + 2763 CONST0 + 2764 RETURN 4 + 2766 ACC0 + 2767 RAISE + 2768 RESTART + 2769 GRAB 2 + 2771 CONST0 + 2772 PUSHACC2 + 2773 LTINT + 2774 BRANCHIF 2783 + 2776 ACC0 + 2777 C_CALL1 ml_string_length + 2779 PUSHACC2 + 2780 GTINT + 2781 BRANCHIFNOT 2790 + 2783 GETGLOBAL "String.contains_from" + 2785 PUSHGETGLOBALFIELD Pervasives, 2 + 2788 APPTERM1 4 + 2790 PUSHTRAP 2811 + 2792 PUSH_RETADDR 2807 + 2794 ACC 9 + 2796 PUSHACC 9 + 2798 PUSHACC 9 + 2800 C_CALL1 ml_string_length + 2802 PUSHACC 10 + 2804 PUSHENVACC1 + 2805 APPLY 4 + 2807 CONST1 + 2808 POPTRAP + 2809 RETURN 3 + 2811 PUSHGETGLOBAL Not_found + 2813 PUSHACC1 + 2814 GETFIELD0 + 2815 EQ + 2816 BRANCHIFNOT 2821 + 2818 CONST0 + 2819 RETURN 4 + 2821 ACC0 + 2822 RAISE + 2823 RESTART + 2824 GRAB 2 + 2826 CONST0 + 2827 PUSHACC2 + 2828 LTINT + 2829 BRANCHIF 2838 + 2831 ACC0 + 2832 C_CALL1 ml_string_length + 2834 PUSHACC2 + 2835 GEINT + 2836 BRANCHIFNOT 2845 + 2838 GETGLOBAL "String.rindex_from" + 2840 PUSHGETGLOBALFIELD Pervasives, 2 + 2843 APPTERM1 4 + 2845 ACC2 + 2846 PUSHACC2 + 2847 PUSHACC2 + 2848 PUSHENVACC1 + 2849 APPTERM3 6 + 2851 RESTART + 2852 GRAB 1 + 2854 ACC1 + 2855 PUSHACC1 + 2856 C_CALL1 ml_string_length + 2858 OFFSETINT -1 + 2860 PUSHACC2 + 2861 PUSHENVACC1 + 2862 APPTERM3 5 + 2864 RESTART + 2865 GRAB 2 + 2867 CONST0 + 2868 PUSHACC2 + 2869 LTINT + 2870 BRANCHIF 2879 + 2872 ACC0 + 2873 C_CALL1 ml_string_length + 2875 PUSHACC2 + 2876 GTINT + 2877 BRANCHIFNOT 2886 + 2879 GETGLOBAL "String.index_from" + 2881 PUSHGETGLOBALFIELD Pervasives, 2 + 2884 APPTERM1 4 + 2886 ACC2 + 2887 PUSHACC2 + 2888 PUSHACC2 + 2889 C_CALL1 ml_string_length + 2891 PUSHACC3 + 2892 PUSHENVACC1 + 2893 APPTERM 4, 7 + 2896 RESTART + 2897 GRAB 1 + 2899 ACC1 + 2900 PUSHCONST0 + 2901 PUSHACC2 + 2902 C_CALL1 ml_string_length + 2904 PUSHACC3 + 2905 PUSHENVACC1 + 2906 APPTERM 4, 6 + 2909 ACC0 + 2910 PUSHGETGLOBALFIELD Char, 2 + 2913 PUSHENVACC1 + 2914 APPTERM2 3 + 2916 ACC0 + 2917 PUSHGETGLOBALFIELD Char, 3 + 2920 PUSHENVACC1 + 2921 APPTERM2 3 + 2923 RESTART + 2924 GRAB 1 + 2926 CONST0 + 2927 PUSHACC2 + 2928 C_CALL1 ml_string_length + 2930 EQ + 2931 BRANCHIFNOT 2936 + 2933 ACC1 + 2934 RETURN 2 + 2936 ACC1 + 2937 PUSHENVACC1 + 2938 APPLY1 + 2939 PUSHCONST0 + 2940 PUSHACC3 + 2941 GETSTRINGCHAR + 2942 PUSHACC2 + 2943 APPLY1 + 2944 PUSHCONST0 + 2945 PUSHACC2 + 2946 SETSTRINGCHAR + 2947 ACC0 + 2948 RETURN 3 + 2950 ACC0 + 2951 PUSHGETGLOBALFIELD Char, 2 + 2954 PUSHENVACC1 + 2955 APPTERM2 3 + 2957 ACC0 + 2958 PUSHGETGLOBALFIELD Char, 3 + 2961 PUSHENVACC1 + 2962 APPTERM2 3 + 2964 RESTART + 2965 GRAB 1 + 2967 ACC1 + 2968 C_CALL1 ml_string_length + 2970 PUSHCONST0 + 2971 PUSHACC1 + 2972 EQ + 2973 BRANCHIFNOT 2978 + 2975 ACC2 + 2976 RETURN 3 + 2978 ACC0 + 2979 C_CALL1 create_string + 2981 PUSHCONST0 + 2982 PUSHACC2 + 2983 OFFSETINT -1 + 2985 PUSH + 2986 BRANCH 3002 + 2988 CHECK_SIGNALS + 2989 ACC1 + 2990 PUSHACC6 + 2991 GETSTRINGCHAR + 2992 PUSHACC5 + 2993 APPLY1 + 2994 PUSHACC2 + 2995 PUSHACC4 + 2996 SETSTRINGCHAR + 2997 ACC1 + 2998 OFFSETINT 1 + 3000 ASSIGN 1 + 3002 ACC0 + 3003 PUSHACC2 + 3004 LEINT + 3005 BRANCHIF 2988 + 3007 CONST0 + 3008 POP 2 + 3010 ACC0 + 3011 RETURN 4 + 3013 CONST0 + 3014 PUSHCONST0 + 3015 PUSHACC2 + 3016 C_CALL1 ml_string_length + 3018 OFFSETINT -1 + 3020 PUSH + 3021 BRANCH 3059 + 3023 CHECK_SIGNALS + 3024 ACC1 + 3025 PUSHACC4 + 3026 GETSTRINGCHAR + 3027 PUSHACC0 + 3028 PUSHGETGLOBAL "\000\"\000\000\004\000\000\000\000\000\000\016\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + 3030 C_CALL2 bitvect_test + 3032 BRANCHIFNOT 3038 + 3034 CONST0 + 3035 CONST2 + 3036 BRANCH 3048 + 3038 ACC0 + 3039 C_CALL1 is_printable + 3041 BRANCHIFNOT 3046 + 3043 CONST1 + 3044 BRANCH 3048 + 3046 CONSTINT 4 + 3048 POP 1 + 3050 PUSHACC3 + 3051 ADDINT + 3052 ASSIGN 2 + 3054 ACC1 + 3055 OFFSETINT 1 + 3057 ASSIGN 1 + 3059 ACC0 + 3060 PUSHACC2 + 3061 LEINT + 3062 BRANCHIF 3023 + 3064 CONST0 + 3065 POP 2 + 3067 ACC1 + 3068 C_CALL1 ml_string_length + 3070 PUSHACC1 + 3071 EQ + 3072 BRANCHIFNOT 3077 + 3074 ACC1 + 3075 RETURN 2 + 3077 ACC0 + 3078 C_CALL1 create_string + 3080 PUSHCONST0 + 3081 ASSIGN 1 + 3083 CONST0 + 3084 PUSHACC3 + 3085 C_CALL1 ml_string_length + 3087 OFFSETINT -1 + 3089 PUSH + 3090 BRANCH 3245 + 3092 CHECK_SIGNALS + 3093 ACC1 + 3094 PUSHACC5 + 3095 GETSTRINGCHAR + 3096 PUSHACC0 + 3097 PUSHGETGLOBAL "\000\000\000\000\004\000\000\000\000\000\000\016\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + 3099 C_CALL2 bitvect_test + 3101 BRANCHIFNOT 3120 + 3103 CONST0 + 3104 CONSTINT 92 + 3106 PUSHACC5 + 3107 PUSHACC5 + 3108 SETSTRINGCHAR + 3109 ACC4 + 3110 OFFSETINT 1 + 3112 ASSIGN 4 + 3114 ACC0 + 3115 PUSHACC5 + 3116 PUSHACC5 + 3117 SETSTRINGCHAR + 3118 BRANCH 3233 + 3120 CONSTINT 9 + 3122 PUSHACC1 + 3123 EQ + 3124 BRANCHIFNOT 3143 + 3126 CONSTINT 92 + 3128 PUSHACC5 + 3129 PUSHACC5 + 3130 SETSTRINGCHAR + 3131 ACC4 + 3132 OFFSETINT 1 + 3134 ASSIGN 4 + 3136 CONSTINT 116 + 3138 PUSHACC5 + 3139 PUSHACC5 + 3140 SETSTRINGCHAR + 3141 BRANCH 3233 + 3143 CONSTINT 13 + 3145 PUSHACC1 + 3146 EQ + 3147 BRANCHIFNOT 3166 + 3149 CONSTINT 92 + 3151 PUSHACC5 + 3152 PUSHACC5 + 3153 SETSTRINGCHAR + 3154 ACC4 + 3155 OFFSETINT 1 + 3157 ASSIGN 4 + 3159 CONSTINT 110 + 3161 PUSHACC5 + 3162 PUSHACC5 + 3163 SETSTRINGCHAR + 3164 BRANCH 3233 + 3166 ACC0 + 3167 C_CALL1 is_printable + 3169 BRANCHIFNOT 3177 + 3171 ACC0 + 3172 PUSHACC5 + 3173 PUSHACC5 + 3174 SETSTRINGCHAR + 3175 BRANCH 3233 + 3177 ACC0 + 3178 PUSHCONSTINT 92 + 3180 PUSHACC6 + 3181 PUSHACC6 + 3182 SETSTRINGCHAR + 3183 ACC5 + 3184 OFFSETINT 1 + 3186 ASSIGN 5 + 3188 CONSTINT 100 + 3190 PUSHACC1 + 3191 DIVINT + 3192 PUSHCONSTINT 48 + 3194 ADDINT + 3195 PUSHACC6 + 3196 PUSHACC6 + 3197 SETSTRINGCHAR + 3198 ACC5 + 3199 OFFSETINT 1 + 3201 ASSIGN 5 + 3203 CONSTINT 10 + 3205 PUSHCONSTINT 10 + 3207 PUSHACC2 + 3208 DIVINT + 3209 MODINT + 3210 PUSHCONSTINT 48 + 3212 ADDINT + 3213 PUSHACC6 + 3214 PUSHACC6 + 3215 SETSTRINGCHAR + 3216 ACC5 + 3217 OFFSETINT 1 + 3219 ASSIGN 5 + 3221 CONSTINT 10 + 3223 PUSHACC1 + 3224 MODINT + 3225 PUSHCONSTINT 48 + 3227 ADDINT + 3228 PUSHACC6 + 3229 PUSHACC6 + 3230 SETSTRINGCHAR + 3231 POP 1 + 3233 POP 1 + 3235 ACC3 + 3236 OFFSETINT 1 + 3238 ASSIGN 3 + 3240 ACC1 + 3241 OFFSETINT 1 + 3243 ASSIGN 1 + 3245 ACC0 + 3246 PUSHACC2 + 3247 LEINT + 3248 BRANCHIF 3092 + 3250 CONST0 + 3251 POP 2 + 3253 ACC0 + 3254 RETURN 3 + 3256 ENVACC1 + 3257 C_CALL1 ml_string_length + 3259 PUSHENVACC3 + 3260 GETFIELD0 + 3261 PUSHENVACC2 + 3262 PUSHCONST0 + 3263 PUSHENVACC1 + 3264 C_CALL5 blit_string + 3266 ENVACC1 + 3267 C_CALL1 ml_string_length + 3269 PUSHENVACC3 + 3270 GETFIELD0 + 3271 ADDINT + 3272 PUSHENVACC3 + 3273 SETFIELD0 + 3274 ACC0 + 3275 C_CALL1 ml_string_length + 3277 PUSHENVACC3 + 3278 GETFIELD0 + 3279 PUSHENVACC2 + 3280 PUSHCONST0 + 3281 PUSHACC4 + 3282 C_CALL5 blit_string + 3284 ACC0 + 3285 C_CALL1 ml_string_length + 3287 PUSHENVACC3 + 3288 GETFIELD0 + 3289 ADDINT + 3290 PUSHENVACC3 + 3291 SETFIELD0 + 3292 RETURN 1 + 3294 ENVACC1 + 3295 OFFSETREF 1 + 3297 ACC0 + 3298 C_CALL1 ml_string_length + 3300 PUSHENVACC2 + 3301 GETFIELD0 + 3302 ADDINT + 3303 PUSHENVACC2 + 3304 SETFIELD0 + 3305 RETURN 1 + 3307 RESTART + 3308 GRAB 1 + 3310 ACC1 + 3311 BRANCHIFNOT 3374 + 3313 ACC1 + 3314 GETFIELD0 + 3315 PUSHCONST0 + 3316 MAKEBLOCK1 0 + 3318 PUSHCONST0 + 3319 MAKEBLOCK1 0 + 3321 PUSHACC4 + 3322 PUSHACC1 + 3323 PUSHACC3 + 3324 CLOSURE 2, 3294 + 3327 PUSHGETGLOBALFIELD List, 9 + 3330 APPLY2 + 3331 ACC1 + 3332 GETFIELD0 + 3333 OFFSETINT -1 + 3335 PUSHACC4 + 3336 C_CALL1 ml_string_length + 3338 MULINT + 3339 PUSHACC1 + 3340 GETFIELD0 + 3341 ADDINT + 3342 C_CALL1 create_string + 3344 PUSHACC3 + 3345 C_CALL1 ml_string_length + 3347 PUSHCONST0 + 3348 PUSHACC2 + 3349 PUSHCONST0 + 3350 PUSHACC7 + 3351 C_CALL5 blit_string + 3353 ACC3 + 3354 C_CALL1 ml_string_length + 3356 MAKEBLOCK1 0 + 3358 PUSHACC6 + 3359 GETFIELD1 + 3360 PUSHACC1 + 3361 PUSHACC3 + 3362 PUSHACC 8 + 3364 CLOSURE 3, 3256 + 3367 PUSHGETGLOBALFIELD List, 9 + 3370 APPLY2 + 3371 ACC1 + 3372 RETURN 7 + 3374 GETGLOBAL "" + 3376 RETURN 2 + 3378 RESTART + 3379 GRAB 4 + 3381 CONST0 + 3382 PUSHACC5 + 3383 LTINT + 3384 BRANCHIF 3414 + 3386 CONST0 + 3387 PUSHACC2 + 3388 LTINT + 3389 BRANCHIF 3414 + 3391 ACC0 + 3392 C_CALL1 ml_string_length + 3394 PUSHACC5 + 3395 PUSHACC3 + 3396 ADDINT + 3397 GTINT + 3398 BRANCHIF 3414 + 3400 CONST0 + 3401 PUSHACC4 + 3402 LTINT + 3403 BRANCHIF 3414 + 3405 ACC2 + 3406 C_CALL1 ml_string_length + 3408 PUSHACC5 + 3409 PUSHACC5 + 3410 ADDINT + 3411 GTINT + 3412 BRANCHIFNOT 3421 + 3414 GETGLOBAL "String.blit" + 3416 PUSHGETGLOBALFIELD Pervasives, 2 + 3419 APPTERM1 6 + 3421 ACC4 + 3422 PUSHACC4 + 3423 PUSHACC4 + 3424 PUSHACC4 + 3425 PUSHACC4 + 3426 C_CALL5 blit_string + 3428 RETURN 5 + 3430 RESTART + 3431 GRAB 3 + 3433 CONST0 + 3434 PUSHACC2 + 3435 LTINT + 3436 BRANCHIF 3452 + 3438 CONST0 + 3439 PUSHACC3 + 3440 LTINT + 3441 BRANCHIF 3452 + 3443 ACC0 + 3444 C_CALL1 ml_string_length + 3446 PUSHACC3 + 3447 PUSHACC3 + 3448 ADDINT + 3449 GTINT + 3450 BRANCHIFNOT 3459 + 3452 GETGLOBAL "String.fill" + 3454 PUSHGETGLOBALFIELD Pervasives, 2 + 3457 APPTERM1 5 + 3459 ACC3 + 3460 PUSHACC3 + 3461 PUSHACC3 + 3462 PUSHACC3 + 3463 C_CALL4 fill_string + 3465 RETURN 4 + 3467 RESTART + 3468 GRAB 2 + 3470 CONST0 + 3471 PUSHACC2 + 3472 LTINT + 3473 BRANCHIF 3489 + 3475 CONST0 + 3476 PUSHACC3 + 3477 LTINT + 3478 BRANCHIF 3489 + 3480 ACC0 + 3481 C_CALL1 ml_string_length + 3483 PUSHACC3 + 3484 PUSHACC3 + 3485 ADDINT + 3486 GTINT + 3487 BRANCHIFNOT 3496 + 3489 GETGLOBAL "String.sub" + 3491 PUSHGETGLOBALFIELD Pervasives, 2 + 3494 APPTERM1 4 + 3496 ACC2 + 3497 C_CALL1 create_string + 3499 PUSHACC3 + 3500 PUSHCONST0 + 3501 PUSHACC2 + 3502 PUSHACC5 + 3503 PUSHACC5 + 3504 C_CALL5 blit_string + 3506 ACC0 + 3507 RETURN 4 + 3509 ACC0 + 3510 C_CALL1 ml_string_length + 3512 PUSHACC0 + 3513 C_CALL1 create_string + 3515 PUSHACC1 + 3516 PUSHCONST0 + 3517 PUSHACC2 + 3518 PUSHCONST0 + 3519 PUSHACC6 + 3520 C_CALL5 blit_string + 3522 ACC0 + 3523 RETURN 3 + 3525 RESTART + 3526 GRAB 1 + 3528 ACC0 + 3529 C_CALL1 create_string + 3531 PUSHACC2 + 3532 PUSHACC2 + 3533 PUSHCONST0 + 3534 PUSHACC3 + 3535 C_CALL4 fill_string + 3537 ACC0 + 3538 RETURN 3 + 3540 CLOSURE 0, 3526 + 3543 PUSH + 3544 CLOSURE 0, 3509 + 3547 PUSH + 3548 CLOSURE 0, 3468 + 3551 PUSH + 3552 CLOSURE 0, 3431 + 3555 PUSH + 3556 CLOSURE 0, 3379 + 3559 PUSH + 3560 CLOSURE 0, 3308 + 3563 PUSH + 3564 CLOSURE 0, 3013 + 3567 PUSH + 3568 CLOSURE 0, 2965 + 3571 PUSHACC0 + 3572 CLOSURE 1, 2957 + 3575 PUSHACC1 + 3576 CLOSURE 1, 2950 + 3579 PUSHACC 8 + 3581 CLOSURE 1, 2924 + 3584 PUSHACC0 + 3585 CLOSURE 1, 2916 + 3588 PUSHACC1 + 3589 CLOSURE 1, 2909 + 3592 PUSH + 3593 CLOSUREREC 0, 2651 + 3597 ACC0 + 3598 CLOSURE 1, 2897 + 3601 PUSHACC1 + 3602 CLOSURE 1, 2865 + 3605 PUSH + 3606 CLOSUREREC 0, 2684 + 3610 ACC0 + 3611 CLOSURE 1, 2852 + 3614 PUSHACC1 + 3615 CLOSURE 1, 2824 + 3618 PUSHACC5 + 3619 CLOSURE 1, 2769 + 3622 PUSHACC3 + 3623 CLOSURE 1, 2724 + 3626 PUSHACC1 + 3627 CLOSURE 1, 2715 + 3630 PUSHACC 9 + 3632 PUSHACC 11 + 3634 PUSHACC 14 + 3636 PUSHACC 16 + 3638 PUSHACC5 + 3639 PUSHACC7 + 3640 PUSHACC6 + 3641 PUSHACC 10 + 3643 PUSHACC 14 + 3645 PUSHACC 13 + 3647 PUSHACC 17 + 3649 PUSHACC 26 + 3651 PUSHACC 28 + 3653 PUSHACC 30 + 3655 PUSHACC 32 + 3657 PUSHACC 34 + 3659 PUSHACC 36 + 3661 PUSHACC 38 + 3663 MAKEBLOCK 18, 0 + 3666 POP 22 + 3668 SETGLOBAL String + 3670 CONST0 + 3671 C_CALL1 gc_stat + 3673 GETGLOBAL "" + 3675 PUSHCONSTINT 20 + 3677 C_CALL2 make_vect + 3679 PUSHCONSTINT 20 + 3681 C_CALL1 weak_create + 3683 PUSHCONST0 + 3684 PUSHCONSTINT 19 + 3686 PUSH + 3687 BRANCH 3715 + 3689 CHECK_SIGNALS + 3690 CONSTINT 115 + 3692 PUSHCONSTINT 20 + 3694 PUSHGETGLOBALFIELD String, 0 + 3697 APPLY2 + 3698 PUSHACC2 + 3699 PUSHACC5 + 3700 SETVECTITEM + 3701 ACC1 + 3702 PUSHACC4 + 3703 GETVECTITEM + 3704 MAKEBLOCK1 0 + 3706 PUSHACC2 + 3707 PUSHACC4 + 3708 C_CALL3 weak_set + 3710 ACC1 + 3711 OFFSETINT 1 + 3713 ASSIGN 1 + 3715 ACC0 + 3716 PUSHACC2 + 3717 LEINT + 3718 BRANCHIF 3689 + 3720 CONST0 + 3721 POP 2 + 3723 CONST0 + 3724 C_CALL1 gc_full_major + 3726 CONST0 + 3727 PUSHCONSTINT 19 + 3729 PUSH + 3730 BRANCH 3753 + 3732 CHECK_SIGNALS + 3733 ACC1 + 3734 PUSHACC3 + 3735 C_CALL2 weak_get + 3737 PUSHACC0 + 3738 BRANCHIF 3745 + 3740 GETGLOBAL Not_found + 3742 MAKEBLOCK1 0 + 3744 RAISE + 3745 CONST0 + 3746 POP 1 + 3748 ACC1 + 3749 OFFSETINT 1 + 3751 ASSIGN 1 + 3753 ACC0 + 3754 PUSHACC2 + 3755 LEINT + 3756 BRANCHIF 3732 + 3758 CONST0 + 3759 POP 2 + 3761 CONST0 + 3762 PUSHCONSTINT 19 + 3764 PUSH + 3765 BRANCH 3785 + 3767 CHECK_SIGNALS + 3768 CONST0 + 3769 PUSHCONST2 + 3770 PUSHACC3 + 3771 MODINT + 3772 EQ + 3773 BRANCHIFNOT 3780 + 3775 GETGLOBAL "" + 3777 PUSHACC2 + 3778 PUSHACC5 + 3779 SETVECTITEM + 3780 ACC1 + 3781 OFFSETINT 1 + 3783 ASSIGN 1 + 3785 ACC0 + 3786 PUSHACC2 + 3787 LEINT + 3788 BRANCHIF 3767 + 3790 CONST0 + 3791 POP 2 + 3793 CONST0 + 3794 C_CALL1 gc_full_major + 3796 CONST0 + 3797 PUSHCONSTINT 19 + 3799 PUSH + 3800 BRANCH 3854 + 3802 CHECK_SIGNALS + 3803 ACC1 + 3804 PUSHACC3 + 3805 C_CALL2 weak_get + 3807 PUSHACC0 + 3808 BRANCHIFNOT 3832 + 3810 CONST1 + 3811 PUSHCONST2 + 3812 PUSHACC4 + 3813 MODINT + 3814 EQ + 3815 BRANCHIFNOT 3842 + 3817 CONSTINT 115 + 3819 PUSHCONSTINT 5 + 3821 PUSHACC2 + 3822 GETFIELD0 + 3823 GETSTRINGCHAR + 3824 NEQ + 3825 BRANCHIFNOT 3847 + 3827 GETGLOBAL Not_found + 3829 MAKEBLOCK1 0 + 3831 RAISE + 3832 CONST0 + 3833 PUSHCONST2 + 3834 PUSHACC4 + 3835 MODINT + 3836 EQ + 3837 BRANCHIFNOT 3842 + 3839 CONST0 + 3840 BRANCH 3847 + 3842 GETGLOBAL Not_found + 3844 MAKEBLOCK1 0 + 3846 RAISE + 3847 POP 1 + 3849 ACC1 + 3850 OFFSETINT 1 + 3852 ASSIGN 1 + 3854 ACC0 + 3855 PUSHACC2 + 3856 LEINT + 3857 BRANCHIF 3802 + 3859 CONST0 + 3860 POP 4 + 3862 ATOM0 + 3863 SETGLOBAL T350-heapcheck + 3865 STOP +**) diff --git a/test/testinterp/t360-stacks-1.ml b/test/testinterp/t360-stacks-1.ml new file mode 100644 index 0000000..100fbab --- /dev/null +++ b/test/testinterp/t360-stacks-1.ml @@ -0,0 +1,43 @@ +open Lib;; +let rec f n = + if n <= 0 then 12 + else 1 + f (n-1) +in +if f 30000 <> 30012 then raise Not_found +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 29 + 11 CONST0 + 12 PUSHACC1 + 13 LEINT + 14 BRANCHIFNOT 20 + 16 CONSTINT 12 + 18 RETURN 1 + 20 ACC0 + 21 OFFSETINT -1 + 23 PUSHOFFSETCLOSURE0 + 24 APPLY1 + 25 PUSHCONST1 + 26 ADDINT + 27 RETURN 1 + 29 CLOSUREREC 0, 11 + 33 CONSTINT 30012 + 35 PUSHCONSTINT 30000 + 37 PUSHACC2 + 38 APPLY1 + 39 NEQ + 40 BRANCHIFNOT 47 + 42 GETGLOBAL Not_found + 44 MAKEBLOCK1 0 + 46 RAISE + 47 POP 1 + 49 ATOM0 + 50 SETGLOBAL T360-stacks-1 + 52 STOP +**) diff --git a/test/testinterp/t360-stacks-2.ml b/test/testinterp/t360-stacks-2.ml new file mode 100644 index 0000000..8d13c7d --- /dev/null +++ b/test/testinterp/t360-stacks-2.ml @@ -0,0 +1,54 @@ +open Lib;; +let rec f n = + if n <= 0 then 12 + else 1 + f (n-1) +in +try + ignore (f 3000000); + raise Not_found +with Stack_overflow -> () +;; + +(** + 0 CONSTINT 42 + 2 PUSHACC0 + 3 MAKEBLOCK1 0 + 5 POP 1 + 7 SETGLOBAL Lib + 9 BRANCH 29 + 11 CONST0 + 12 PUSHACC1 + 13 LEINT + 14 BRANCHIFNOT 20 + 16 CONSTINT 12 + 18 RETURN 1 + 20 ACC0 + 21 OFFSETINT -1 + 23 PUSHOFFSETCLOSURE0 + 24 APPLY1 + 25 PUSHCONST1 + 26 ADDINT + 27 RETURN 1 + 29 CLOSUREREC 0, 11 + 33 PUSHTRAP 44 + 35 CONSTINT 3000000 + 37 PUSHACC5 + 38 APPLY1 + 39 GETGLOBAL Not_found + 41 MAKEBLOCK1 0 + 43 RAISE + 44 PUSHGETGLOBAL Stack_overflow + 46 PUSHACC1 + 47 GETFIELD0 + 48 EQ + 49 BRANCHIFNOT 54 + 51 CONST0 + 52 BRANCH 56 + 54 ACC0 + 55 RAISE + 56 POP 1 + 58 POP 1 + 60 ATOM0 + 61 SETGLOBAL T360-stacks-2 + 63 STOP +**) diff --git a/test/weaktest.ml b/test/weaktest.ml new file mode 100644 index 0000000..6012911 --- /dev/null +++ b/test/weaktest.ml @@ -0,0 +1,73 @@ +(* $Id: weaktest.ml,v 1.2 2008-01-11 11:55:36 doligez Exp $ *) + +let debug = false;; + +open Printf;; + +module Hashed = struct + type t = string list;; + let equal x y = + eprintf "equal: %s / %s\n" (List.hd x) (List.hd y); + x = y + ;; + let hash x = Hashtbl.hash (List.hd x);; +end;; + +module HT = Weak.Make (Hashed);; + +let tbl = HT.create 7;; + +let r = ref [];; + +let bunch = + if Array.length Sys.argv < 2 + then 10000 + else int_of_string Sys.argv.(1) +;; + +Random.init 314;; + +let random_string n = + let result = String.create n in + for i = 0 to n - 1 do + result.[i] <- Char.chr (32 + Random.int 95); + done; + result +;; + +let added = ref 0;; +let mistakes = ref 0;; + +let print_status () = + let (len, entries, sumbuck, buckmin, buckmed, buckmax) = HT.stats tbl in + if entries > bunch * (!added + 1) then begin + if debug then begin + printf "\n===================\n"; + printf "len = %d\n" len; + printf "entries = %d\n" entries; + printf "sum of bucket sizes = %d\n" sumbuck; + printf "min bucket = %d\n" buckmin; + printf "med bucket = %d\n" buckmed; + printf "max bucket = %d\n" buckmax; + printf "GC count = %d\n" (Gc.quick_stat ()).Gc.major_collections; + flush stdout; + end; + incr mistakes; + end; + added := 0; +;; + +Gc.create_alarm print_status;; + +for j = 0 to 99 do + r := []; + incr added; + + for i = 1 to bunch do + let c = random_string 7 in + r := c :: !r; + HT.add tbl !r; + done; +done;; + +if !mistakes < 5 then printf "pass\n" else printf "fail\n";; diff --git a/testasmcomp/.cvsignore b/testasmcomp/.cvsignore new file mode 100644 index 0000000..76174b5 --- /dev/null +++ b/testasmcomp/.cvsignore @@ -0,0 +1,5 @@ +codegen +parsecmm.ml +parsecmm.mli +lexcmm.ml +*.out diff --git a/testasmcomp/.depend b/testasmcomp/.depend new file mode 100644 index 0000000..282114b --- /dev/null +++ b/testasmcomp/.depend @@ -0,0 +1,17 @@ +lexcmm.cmi: parsecmm.cmi +parsecmm.cmi: ../asmcomp/cmm.cmi +parsecmmaux.cmi: ../typing/ident.cmi +lexcmm.cmo: ../utils/misc.cmi parsecmm.cmi lexcmm.cmi +lexcmm.cmx: ../utils/misc.cmx parsecmm.cmx lexcmm.cmi +main.cmo: ../asmcomp/asmgen.cmi ../utils/clflags.cmo ../asmcomp/compilenv.cmi \ + ../asmcomp/emit.cmi lexcmm.cmi parsecmm.cmi parsecmmaux.cmi \ + ../asmcomp/printmach.cmi +main.cmx: ../asmcomp/asmgen.cmx ../utils/clflags.cmx ../asmcomp/compilenv.cmx \ + ../asmcomp/emit.cmx lexcmm.cmx parsecmm.cmx parsecmmaux.cmx \ + ../asmcomp/printmach.cmx +parsecmm.cmo: ../asmcomp/arch.cmo ../asmcomp/cmm.cmi ../utils/misc.cmi \ + parsecmmaux.cmi parsecmm.cmi +parsecmm.cmx: ../asmcomp/arch.cmx ../asmcomp/cmm.cmx ../utils/misc.cmx \ + parsecmmaux.cmx parsecmm.cmi +parsecmmaux.cmo: ../typing/ident.cmi parsecmmaux.cmi +parsecmmaux.cmx: ../typing/ident.cmx parsecmmaux.cmi diff --git a/testasmcomp/Makefile b/testasmcomp/Makefile new file mode 100644 index 0000000..9af0aa2 --- /dev/null +++ b/testasmcomp/Makefile @@ -0,0 +1,159 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.33 2003-06-30 08:28:46 xleroy Exp $ + +include ../config/Makefile + +CAMLC=../boot/ocamlrun ../boot/ocamlc -I ../boot +COMPFLAGS=$(INCLUDES) -g +LINKFLAGS=-g +CAMLYACC=../boot/ocamlyacc +YACCFLAGS= +CAMLLEX=../boot/ocamlrun ../boot/ocamllex +CAMLDEP=../boot/ocamlrun ../tools/ocamldep +DEPFLAGS=$(INCLUDES) +CAMLRUN=../boot/ocamlrun + +CODEGEN=./codegen +CC=$(NATIVECC) +CFLAGS=$(NATIVECCCOMPOPTS) -g + +PROGS=fib.out tak.out quicksort.out quicksort2.out soli.out integr.out \ + arith.out checkbound.out + +all: codegen $(PROGS) + +INCLUDES=-I ../utils -I ../typing -I ../asmcomp + +OTHEROBJS=../utils/misc.cmo ../utils/config.cmo ../utils/tbl.cmo \ + ../utils/clflags.cmo ../utils/ccomp.cmo \ + ../utils/config.cmo ../utils/clflags.cmo ../utils/warnings.cmo \ + ../utils/consistbl.cmo \ + ../parsing/linenum.cmo ../parsing/location.cmo \ + ../typing/ident.cmo ../typing/path.cmo ../typing/types.cmo \ + ../typing/btype.cmo ../typing/subst.cmo ../typing/primitive.cmo \ + ../typing/predef.cmo ../typing/datarepr.cmo ../typing/env.cmo \ + ../bytecomp/lambda.cmo ../bytecomp/switch.cmo \ + ../asmcomp/arch.cmo ../asmcomp/cmm.cmo ../asmcomp/printcmm.cmo \ + ../asmcomp/clambda.cmo ../asmcomp/compilenv.cmo \ + ../asmcomp/reg.cmo ../asmcomp/mach.cmo ../asmcomp/proc.cmo \ + ../asmcomp/closure.cmo ../asmcomp/cmmgen.cmo \ + ../asmcomp/printmach.cmo \ + ../asmcomp/selectgen.cmo ../asmcomp/selection.cmo ../asmcomp/comballoc.cmo \ + ../asmcomp/liveness.cmo ../asmcomp/spill.cmo ../asmcomp/split.cmo \ + ../asmcomp/interf.cmo ../asmcomp/coloring.cmo \ + ../asmcomp/reloadgen.cmo ../asmcomp/reload.cmo \ + ../asmcomp/linearize.cmo ../asmcomp/schedgen.cmo ../asmcomp/scheduling.cmo \ + ../asmcomp/printlinear.cmo ../asmcomp/emitaux.cmo \ + ../asmcomp/emit.cmo ../asmcomp/asmgen.cmo + +OBJS=parsecmmaux.cmo parsecmm.cmo lexcmm.cmo main.cmo + +codegen: $(OTHEROBJS) $(OBJS) + $(CAMLC) $(LINKFLAGS) -o codegen $(OTHEROBJS) $(OBJS) +clean:: + rm -f codegen + +# The parser + +parsecmm.mli parsecmm.ml: parsecmm.mly + $(CAMLYACC) $(YACCFLAGS) parsecmm.mly + +clean:: + rm -f parsecmm.mli parsecmm.ml parsecmm.output + +beforedepend:: parsecmm.mli parsecmm.ml + +# The lexer + +lexcmm.ml: lexcmm.mll + $(CAMLLEX) lexcmm.mll + +clean:: + rm -f lexcmm.ml + +beforedepend:: lexcmm.ml + +# The test programs + +$(PROGS:.out=.o): codegen + +fib.out: main.c fib.o $(ARCH).o + $(CC) $(CFLAGS) -o fib.out -DINT_INT -DFUN=fib main.c fib.o $(ARCH).o + +tak.out: main.c tak.o $(ARCH).o + $(CC) $(CFLAGS) -o tak.out -DUNIT_INT -DFUN=takmain main.c tak.o $(ARCH).o + +quicksort.out: main.c quicksort.o $(ARCH).o + $(CC) $(CFLAGS) -o quicksort.out -DSORT -DFUN=quicksort main.c quicksort.o $(ARCH).o + +quicksort2.out: main.c quicksort2.o $(ARCH).o + $(CC) $(CFLAGS) -o quicksort2.out -DSORT -DFUN=quicksort main.c quicksort2.o $(ARCH).o + +soli.out: main.c soli.o $(ARCH).o + $(CC) $(CFLAGS) -o soli.out -DUNIT_INT -DFUN=solitaire main.c soli.o $(ARCH).o + +integr.out: main.c integr.o $(ARCH).o + $(CC) $(CFLAGS) -o integr.out -DINT_FLOAT -DFUN=test main.c integr.o $(ARCH).o + +tagged-fib.out: main.c tagged-fib.o $(ARCH).o + $(CC) $(CFLAGS) -o tagged-fib.out -DINT_INT -DFUN=fib main.c tagged-fib.o $(ARCH).o + +tagged-tak.out: main.c tagged-tak.o $(ARCH).o + $(CC) $(CFLAGS) -o tagged-tak.out -DUNIT_INT -DFUN=takmain main.c tagged-tak.o $(ARCH).o + +tagged-quicksort.out: main.c tagged-quicksort.o $(ARCH).o + $(CC) $(CFLAGS) -o tagged-quicksort.out -DSORT -DFUN=quicksort main.c tagged-quicksort.o $(ARCH).o + +tagged-integr.out: main.c tagged-integr.o $(ARCH).o + $(CC) $(CFLAGS) -o tagged-integr.out -DINT_FLOAT -DFUN=test main.c tagged-integr.o $(ARCH).o + +arith.out: mainarith.c arith.o $(ARCH).o + $(CC) $(CFLAGS) -o arith.out mainarith.c arith.o $(ARCH).o + +checkbound.out: main.c checkbound.o $(ARCH).o + $(CC) $(CFLAGS) -o checkbound.out -DCHECKBOUND main.c checkbound.o $(ARCH).o + +# The runtime environment + +power.o: power-$(SYSTEM).o + cp power-$(SYSTEM).o power.o + +.SUFFIXES: +.SUFFIXES: .cmm .c .o .S .ml .mli .cmo .cmi .s + +.ml.cmo: + $(CAMLC) $(COMPFLAGS) -c $< + +.mli.cmi: + $(CAMLC) $(COMPFLAGS) -c $< + +.cmm.o: + $(CAMLRUN) $(CODEGEN) $*.cmm > $*.s + $(AS) $(ASFLAGS) -o $*.o $*.s + +.S.o: + $(ASPP) $(ASPPFLAGS) -o $*.o $*.S + +.s.o: + $(ASPP) $(ASPPFLAGS) -o $*.o $*.s + +clean:: + rm -f *.out *.cm[io] *.s *.o *~ + +$(PROGS:.out=.o): $(CODEGEN) + +depend: beforedepend + $(CAMLDEP) $(DEPFLAGS) *.mli *.ml > .depend + +include .depend diff --git a/testasmcomp/alpha.S b/testasmcomp/alpha.S new file mode 100644 index 0000000..46833e3 --- /dev/null +++ b/testasmcomp/alpha.S @@ -0,0 +1,62 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: alpha.S,v 1.4 1999-11-29 19:04:18 doligez Exp $ */ + + .globl call_gen_code + .ent call_gen_code + +call_gen_code: + lda $sp, -80($sp) + stq $26, 0($sp) + stq $9, 8($sp) + stq $10, 16($sp) + stq $11, 24($sp) + stq $12, 32($sp) + stt $f2, 40($sp) + stt $f3, 48($sp) + stt $f4, 56($sp) + stt $f5, 64($sp) + mov $16, $27 + mov $17, $16 + mov $18, $17 + mov $19, $18 + mov $20, $19 + jsr ($27) + ldq $26, 0($sp) + ldq $9, 8($sp) + ldq $10, 16($sp) + ldq $11, 24($sp) + ldq $12, 32($sp) + ldt $f2, 40($sp) + ldt $f3, 48($sp) + ldt $f4, 56($sp) + ldt $f5, 64($sp) + lda $sp, 80($sp) + ret ($26) + + .end call_gen_code + + .globl caml_c_call + .ent caml_c_call +caml_c_call: + lda $sp, -16($sp) + stq $26, 0($sp) + stq $gp, 8($sp) + mov $25, $27 + jsr ($25) + ldq $26, 0($sp) + ldq $gp, 8($sp) + lda $sp, 16($sp) + ret ($26) + + .end caml_c_call diff --git a/testasmcomp/amd64.S b/testasmcomp/amd64.S new file mode 100644 index 0000000..46290c6 --- /dev/null +++ b/testasmcomp/amd64.S @@ -0,0 +1,53 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 2000 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: amd64.S,v 1.1 2003-06-30 08:28:46 xleroy Exp $ */ + + .globl call_gen_code + .align 16 +call_gen_code: + pushq %rbx + pushq %rbp + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + movq %rdi, %r10 + movq %rsi, %rax + movq %rdx, %rbx + movq %rcx, %rdi + movq %r8, %rsi + call *%r10 + popq %r15 + popq %r14 + popq %r13 + popq %r12 + popq %rbp + popq %rbx + ret + + .globl caml_c_call + .align 16 +caml_c_call: + jmp *%rax + + .section .rodata.cst8,"aM",@progbits,8 + .globl caml_negf_mask + .align 16 +caml_negf_mask: + .quad 0x8000000000000000, 0 + .globl caml_absf_mask + .align 16 +caml_absf_mask: + .quad 0x7FFFFFFFFFFFFFFF, 0 + + .comm young_limit, 8 diff --git a/testasmcomp/arith.cmm b/testasmcomp/arith.cmm new file mode 100644 index 0000000..28505b0 --- /dev/null +++ b/testasmcomp/arith.cmm @@ -0,0 +1,222 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: arith.cmm,v 1.9 2000-06-29 11:45:23 xleroy Exp $ *) + +(* Regression test for arithmetic instructions *) + +(function "testarith" () + (let r "R" + (let d "D" + (let x (load int "X") + (let y (load int "Y") + (let f (load float "F") + (let g (load float "G") + (addraset r 0 0) + (addraset r 1 1) + (addraset r 2 -1) + (addraset r 3 256) + (addraset r 4 65536) + (addraset r 5 16777216) + (addraset r 6 -256) + (addraset r 7 -65536) + (addraset r 8 -16777216) + + (addraset r 9 (+ x y)) + (addraset r 10 (+ x 1)) + (addraset r 11 (+ x -1)) + + (addraset r 12 (+a "R" 8)) + (addraset r 13 (+a "R" y)) + + (addraset r 14 (- x y)) + (addraset r 15 (- x 1)) + (addraset r 16 (- x -1)) + + (addraset r 17 (-a "R" 8)) + (addraset r 18 (-a "R" y)) + + (addraset r 19 ( * x 2)) + (addraset r 20 ( * 2 x)) + (addraset r 21 ( * x 16)) + (addraset r 22 ( * 16 x)) + (addraset r 23 ( * x 12345)) + (addraset r 24 ( * 12345 x)) + (addraset r 25 ( * x y)) + + (addraset r 26 (/ x 2)) + (addraset r 27 (/ x 16)) + (addraset r 28 (/ x 7)) + (addraset r 29 (if (!= y 0) (/ x y) 0)) + + (addraset r 30 (mod x 2)) + (addraset r 31 (mod x 16)) + (addraset r 32 (if (!= y 0) (mod x y) 0)) + + (addraset r 33 (and x y)) + (addraset r 34 (and x 3)) + (addraset r 35 (and 3 x)) + + (addraset r 36 (or x y)) + (addraset r 37 (or x 3)) + (addraset r 38 (or 3 x)) + + (addraset r 39 (xor x y)) + (addraset r 40 (xor x 3)) + (addraset r 41 (xor 3 x)) + + (addraset r 42 (<< x y)) + (addraset r 43 (<< x 1)) + (addraset r 44 (<< x 8)) + + (addraset r 45 (>>u x y)) + (addraset r 46 (>>u x 1)) + (addraset r 47 (>>u x 8)) + + (addraset r 48 (>>s x y)) + (addraset r 49 (>>s x 1)) + (addraset r 50 (>>s x 8)) + + (addraset r 51 (== x y)) + (addraset r 52 (!= x y)) + (addraset r 53 (< x y)) + (addraset r 54 (> x y)) + (addraset r 55 (<= x y)) + (addraset r 56 (>= x y)) + (addraset r 57 (== x 1)) + (addraset r 58 (!= x 1)) + (addraset r 59 (< x 1)) + (addraset r 60 (> x 1)) + (addraset r 61 (<= x 1)) + (addraset r 62 (>= x 1)) + + (addraset r 63 (==a x y)) + (addraset r 64 (!=a x y)) + (addraset r 65 (<a x y)) + (addraset r 66 (>a x y)) + (addraset r 67 (<=a x y)) + (addraset r 68 (>=a x y)) + (addraset r 69 (==a x 1)) + (addraset r 70 (!=a x 1)) + (addraset r 71 (<a x 1)) + (addraset r 72 (>a x 1)) + (addraset r 73 (<=a x 1)) + (addraset r 74 (>=a x 1)) + + (addraset r 75 (+ x (<< y 1))) + (addraset r 76 (+ x (<< y 2))) + (addraset r 77 (+ x (<< y 3))) + (addraset r 78 (- x (<< y 1))) + (addraset r 79 (- x (<< y 2))) + (addraset r 80 (- x (<< y 3))) + + (floataset d 0 0.0) + (floataset d 1 1.0) + (floataset d 2 -1.0) + (floataset d 3 (+f f g)) + (floataset d 4 (-f f g)) + (floataset d 5 ( *f f g)) + (floataset d 6 (/f f g)) + + (floataset d 7 (+f f (+f g 1.0))) + (floataset d 8 (-f f (+f g 1.0))) + (floataset d 9 ( *f f (+f g 1.0))) + (floataset d 10 (/f f (+f g 1.0))) + + (floataset d 11 (+f (+f f 1.0) g)) + (floataset d 12 (-f (+f f 1.0) g)) + (floataset d 13 ( *f (+f f 1.0) g)) + (floataset d 14 (/f (+f f 1.0) g)) + + (floataset d 15 (+f (+f f 1.0) (+f g 1.0))) + (floataset d 16 (-f (+f f 1.0) (+f g 1.0))) + (floataset d 17 ( *f (+f f 1.0) (+f g 1.0))) + (floataset d 18 (/f (+f f 1.0) (+f g 1.0))) + + (addraset r 81 (==f f g)) + (addraset r 82 (!=f f g)) + (addraset r 83 (<f f g)) + (addraset r 84 (>f f g)) + (addraset r 85 (<=f f g)) + (addraset r 86 (>=f f g)) + + (floataset d 19 (floatofint x)) + (addraset r 87 (intoffloat f)) + + (if (and (>= x 0) (< x y)) + (seq (checkbound y x) (addraset r 88 1)) + (addraset r 88 0)) + + (if (< 0 y) + (seq (checkbound y 0) (addraset r 89 1)) + (addraset r 89 0)) + + (if (< 5 y) + (seq (checkbound y 5) (addraset r 90 1)) + (addraset r 90 0)) + + (addraset r 91 (let res 1 (if (==f f g) [] (assign res 0)) res)) + (addraset r 92 (let res 1 (if (!=f f g) [] (assign res 0)) res)) + (addraset r 93 (let res 1 (if (<f f g) [] (assign res 0)) res)) + (addraset r 94 (let res 1 (if (>f f g) [] (assign res 0)) res)) + (addraset r 95 (let res 1 (if (<=f f g) [] (assign res 0)) res)) + (addraset r 96 (let res 1 (if (>=f f g) [] (assign res 0)) res)) + + (addraset r 97 (==f (+f f 1.0) (+f g 1.0))) + (addraset r 98 (!=f (+f f 1.0) (+f g 1.0))) + (addraset r 99 (<f (+f f 1.0) (+f g 1.0))) + (addraset r 100 (>f (+f f 1.0) (+f g 1.0))) + (addraset r 101 (<=f (+f f 1.0) (+f g 1.0))) + (addraset r 102 (>=f (+f f 1.0) (+f g 1.0))) + + (addraset r 103 (==f f (+f g 1.0))) + (addraset r 104 (!=f f (+f g 1.0))) + (addraset r 105 (<f f (+f g 1.0))) + (addraset r 106 (>f f (+f g 1.0))) + (addraset r 107 (<=f f (+f g 1.0))) + (addraset r 108 (>=f f (+f g 1.0))) + + (addraset r 109 (==f (+f f 1.0) g)) + (addraset r 110 (!=f (+f f 1.0) g)) + (addraset r 111 (<f (+f f 1.0) g)) + (addraset r 112 (>f (+f f 1.0) g)) + (addraset r 113 (<=f (+f f 1.0) g)) + (addraset r 114 (>=f (+f f 1.0) g)) + + (floataset d 20 (+f (floatofint x) 1.0)) + (addraset r 115 (intoffloat (+f f 1.0))) + + (floataset d 21 (+f f (load float "G"))) + (floataset d 22 (+f (load float "G") f)) + (floataset d 23 (-f f (load float "G"))) + (floataset d 24 (-f (load float "G") f)) + (floataset d 25 ( *f f (load float "G"))) + (floataset d 26 ( *f (load float "G") f)) + (floataset d 27 (/f f (load float "G"))) + (floataset d 28 (/f (load float "G") f)) + + (floataset d 29 (+f ( *f f 2.0) (load float "G"))) + (floataset d 30 (+f (load float "G") ( *f f 2.0))) + (floataset d 31 (-f ( *f f 2.0) (load float "G"))) + (floataset d 32 (-f (load float "G") ( *f f 2.0))) + (floataset d 33 ( *f ( +f f 2.0) (load float "G"))) + (floataset d 34 ( *f (load float "G") ( +f f 2.0))) + (floataset d 35 (/f ( *f f 2.0) (load float "G"))) + (floataset d 36 (/f (load float "G") ( *f f 2.0))) + + (floataset d 37 (-f f)) + (floataset d 38 (absf f)) + +))))))) + + + diff --git a/testasmcomp/arm.S b/testasmcomp/arm.S new file mode 100644 index 0000000..43255b7 --- /dev/null +++ b/testasmcomp/arm.S @@ -0,0 +1,45 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1998 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: arm.S,v 1.3 2000-01-07 16:44:17 doligez Exp $ */ + +fp .req r11 +ip .req r12 +sp .req r13 +lr .req r14 +pc .req r15 + + .text + + .global call_gen_code + .type call_gen_code, %function + .align 0 +call_gen_code: + mov ip, sp + stmfd sp!, {r4, r5, r6, r7, r8, r9, fp, ip, lr, pc} + sub fp, ip, #4 + @ r0 is function to call + @ r1, r2, r3 are arguments 1, 2, 3 + mov r4, r0 + mov r0, r1 + mov r1, r2 + mov r2, r3 + mov lr, pc + mov pc, r4 + ldmea fp, {r4, r5, r6, r7, r8, r9, fp, sp, pc} + + .global caml_c_call + .type caml_c_call, %function + .align 0 +caml_c_call: + @ function to call is in r10 + mov pc, r10 diff --git a/testasmcomp/checkbound.cmm b/testasmcomp/checkbound.cmm new file mode 100644 index 0000000..eb4db58 --- /dev/null +++ b/testasmcomp/checkbound.cmm @@ -0,0 +1,21 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: checkbound.cmm,v 1.3 1999-11-17 18:58:41 xleroy Exp $ *) + +(function "checkbound2" (x: int y: int) + (checkbound x y)) + +(function "checkbound1" (x: int) + (checkbound x 2)) + + diff --git a/testasmcomp/fib.cmm b/testasmcomp/fib.cmm new file mode 100644 index 0000000..4c443ea --- /dev/null +++ b/testasmcomp/fib.cmm @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: fib.cmm,v 1.4 1999-11-17 18:58:41 xleroy Exp $ *) + +(function "fib" (n: int) + (if (< n 2) + 1 + (+ (app "fib" (- n 1) int) + (app "fib" (- n 2) int)))) diff --git a/testasmcomp/hppa.S b/testasmcomp/hppa.S new file mode 100644 index 0000000..cd99eb3 --- /dev/null +++ b/testasmcomp/hppa.S @@ -0,0 +1,162 @@ +;********************************************************************* +;* * +;* Objective Caml * +;* * +;* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +;* * +;* Copyright 1996 Institut National de Recherche en Informatique et * +;* en Automatique. All rights reserved. This file is distributed * +;* under the terms of the Q Public License version 1.0. * +;* * +;********************************************************************* + +; $Id: hppa.S,v 1.3 1999-11-17 18:58:41 xleroy Exp $ +; Must be preprocessed by cpp + +#ifdef SYS_hpux +#define G(x) x +#define CODESPACE .code +#define CODE_ALIGN 4 +#define EXPORT_CODE(x) .export x, entry, priv_lev=3 +#define STARTPROC .proc ! .callinfo frame=0, no_calls ! .entry +#define ENDPROC .exit ! .procend +#endif + +#ifdef SYS_nextstep +#define G(x) _##x +#define CODESPACE .text +#define CODE_ALIGN 2 +#define EXPORT_CODE(x) .globl x +#define STARTPROC +#define ENDPROC +#endif + +#ifdef SYS_hpux + .space $PRIVATE$ + .subspa $DATA$,quad=1,align=8,access=31 + .subspa $BSS$,quad=1,align=8,access=31,zero,sort=82 + .space $TEXT$ + .subspa $LIT$,quad=0,align=8,access=44 + .subspa $CODE$,quad=0,align=8,access=44,code_only + .import $global$, data + .import $$dyncall, millicode +#endif + + CODESPACE + .align CODE_ALIGN + EXPORT_CODE(G(call_gen_code)) +G(call_gen_code): + STARTPROC + stw %r2,-20(%r30) + ldo 256(%r30), %r30 +; Save the callee-save registers + ldo -32(%r30), %r1 + stws,ma %r3, -4(%r1) + stws,ma %r4, -4(%r1) + stws,ma %r5, -4(%r1) + stws,ma %r6, -4(%r1) + stws,ma %r7, -4(%r1) + stws,ma %r8, -4(%r1) + stws,ma %r9, -4(%r1) + stws,ma %r10, -4(%r1) + stws,ma %r11, -4(%r1) + stws,ma %r12, -4(%r1) + stws,ma %r13, -4(%r1) + stws,ma %r14, -4(%r1) + stws,ma %r15, -4(%r1) + stws,ma %r16, -4(%r1) + stws,ma %r17, -4(%r1) + stws,ma %r18, -4(%r1) + fstds,ma %fr12, -8(%r1) + fstds,ma %fr13, -8(%r1) + fstds,ma %fr14, -8(%r1) + fstds,ma %fr15, -8(%r1) + fstds,ma %fr16, -8(%r1) + fstds,ma %fr17, -8(%r1) + fstds,ma %fr18, -8(%r1) + fstds,ma %fr19, -8(%r1) + fstds,ma %fr20, -8(%r1) + fstds,ma %fr21, -8(%r1) + fstds,ma %fr22, -8(%r1) + fstds,ma %fr23, -8(%r1) + fstds,ma %fr24, -8(%r1) + fstds,ma %fr25, -8(%r1) + fstds,ma %fr26, -8(%r1) + fstds,ma %fr27, -8(%r1) + fstds,ma %fr28, -8(%r1) + fstds,ma %fr29, -8(%r1) + fstds,ma %fr30, -8(%r1) + fstds,ma %fr31, -8(%r1) + +; Shuffle the arguments and call + copy %r26, %r22 + copy %r25, %r26 + copy %r24, %r25 + copy %r23, %r24 + fcpy,dbl %fr5, %fr4 +#ifdef SYS_hpux + bl $$dyncall, %r2 + nop +#else + ble 0(4, %r22) + copy %r31, %r2 +#endif +; Shuffle the results + copy %r26, %r28 +; Restore the callee-save registers + ldo -32(%r30), %r1 + ldws,ma -4(%r1), %r3 + ldws,ma -4(%r1), %r4 + ldws,ma -4(%r1), %r5 + ldws,ma -4(%r1), %r6 + ldws,ma -4(%r1), %r7 + ldws,ma -4(%r1), %r8 + ldws,ma -4(%r1), %r9 + ldws,ma -4(%r1), %r10 + ldws,ma -4(%r1), %r11 + ldws,ma -4(%r1), %r12 + ldws,ma -4(%r1), %r13 + ldws,ma -4(%r1), %r14 + ldws,ma -4(%r1), %r15 + ldws,ma -4(%r1), %r16 + ldws,ma -4(%r1), %r17 + ldws,ma -4(%r1), %r18 + fldds,ma -8(%r1), %fr12 + fldds,ma -8(%r1), %fr13 + fldds,ma -8(%r1), %fr14 + fldds,ma -8(%r1), %fr15 + fldds,ma -8(%r1), %fr16 + fldds,ma -8(%r1), %fr17 + fldds,ma -8(%r1), %fr18 + fldds,ma -8(%r1), %fr19 + fldds,ma -8(%r1), %fr20 + fldds,ma -8(%r1), %fr21 + fldds,ma -8(%r1), %fr22 + fldds,ma -8(%r1), %fr23 + fldds,ma -8(%r1), %fr24 + fldds,ma -8(%r1), %fr25 + fldds,ma -8(%r1), %fr26 + fldds,ma -8(%r1), %fr27 + fldds,ma -8(%r1), %fr28 + fldds,ma -8(%r1), %fr29 + fldds,ma -8(%r1), %fr30 + fldds,ma -8(%r1), %fr31 + + ldo -256(%r30), %r30 + ldw -20(%r30), %r2 + bv 0(%r2) + nop + ENDPROC + + .align CODE_ALIGN + EXPORT_CODE(caml_c_call) +G(caml_c_call): + STARTPROC +#ifdef SYS_hpux + bl $$dyncall, %r0 + nop +#else + bv 0(%r22) + nop +#endif + ENDPROC diff --git a/testasmcomp/i386.S b/testasmcomp/i386.S new file mode 100644 index 0000000..0efd5f8 --- /dev/null +++ b/testasmcomp/i386.S @@ -0,0 +1,56 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: i386.S,v 1.5 1999-11-17 18:58:41 xleroy Exp $ */ + +/* Linux with ELF binaries does not prefix identifiers with _. + Linux with a.out binaries, FreeBSD, and NextStep do. */ + +#ifdef SYS_linux_elf +#define G(x) x +#define FUNCTION_ALIGN 16 +#else +#define G(x) _##x +#define FUNCTION_ALIGN 4 +#endif + + .globl G(call_gen_code) + .align FUNCTION_ALIGN +G(call_gen_code): + pushl %ebp + movl %esp,%ebp + pushl %ebx + pushl %esi + pushl %edi + movl 12(%ebp),%eax + movl 16(%ebp),%ebx + movl 20(%ebp),%ecx + movl 24(%ebp),%edx + call *8(%ebp) + popl %edi + popl %esi + popl %ebx + popl %ebp + ret + + .globl G(caml_c_call) + .align FUNCTION_ALIGN +G(caml_c_call): + ffree %st(0) + ffree %st(1) + ffree %st(2) + ffree %st(3) + jmp *%eax + + .comm G(caml_exception_pointer), 4 + .comm G(young_ptr), 4 + .comm G(young_start), 4 diff --git a/testasmcomp/i386nt.asm b/testasmcomp/i386nt.asm new file mode 100644 index 0000000..e173b7a --- /dev/null +++ b/testasmcomp/i386nt.asm @@ -0,0 +1,67 @@ +;********************************************************************* +; +; Objective Caml +; +; Xavier Leroy, projet Cristal, INRIA Rocquencourt +; +; Copyright 1996 Institut National de Recherche en Informatique et +; en Automatique. All rights reserved. This file is distributed +; under the terms of the Q Public License version 1.0. +; +;********************************************************************* + +; $Id: i386nt.asm,v 1.3 1999-11-17 18:58:42 xleroy Exp $ + + .386 + .MODEL FLAT + + .CODE + PUBLIC _call_gen_code + ALIGN 4 +_call_gen_code: + push ebp + mov ebp, esp + push ebx + push esi + push edi + mov eax, [ebp+12] + mov ebx, [ebp+16] + mov ecx, [ebp+20] + mov edx, [ebp+24] + call DWORD PTR [ebp+8] + pop edi + pop esi + pop ebx + pop ebp + ret + + PUBLIC _caml_c_call + ALIGN 4 +_caml_c_call: + ffree st(0) + ffree st(1) + ffree st(2) + ffree st(3) + jmp eax + + PUBLIC _caml_call_gc + PUBLIC _caml_alloc + PUBLIC _caml_alloc1 + PUBLIC _caml_alloc2 + PUBLIC _caml_alloc3 +_caml_call_gc: +_caml_alloc: +_caml_alloc1: +_caml_alloc2: +_caml_alloc3: + int 3 + + .DATA + PUBLIC _caml_exception_pointer +_caml_exception_pointer dword 0 + PUBLIC _young_ptr +_young_ptr dword 0 + PUBLIC _young_limit +_young_limit dword 0 + + END diff --git a/testasmcomp/ia64.S b/testasmcomp/ia64.S new file mode 100644 index 0000000..7fd7085 --- /dev/null +++ b/testasmcomp/ia64.S @@ -0,0 +1,118 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: ia64.S,v 1.5 2001-07-12 12:54:24 doligez Exp $ */ + +#define ST8OFF(a,b,d) st8 [a] = b, d +#define LD8OFF(a,b,d) ld8 a = [b], d +#define STFDOFF(a,b,d) stfd [a] = b, d +#define LDFDOFF(a,b,d) ldfd a = [b], d +#define STFSPILLOFF(a,b,d) stf.spill [a] = b, d +#define LDFFILLOFF(a,b,d) ldf.fill a = [b], d + + .text + .align 16 + + .global call_gen_code# + .proc call_gen_code# + +call_gen_code: + /* Allocate 64 "out" registers (for the Caml code) and no locals */ + alloc r3 = ar.pfs, 0, 0, 64, 0 + + /* Save PFS, return address and GP on stack */ + add sp = -368, sp ;; + add r2 = 16, sp ;; + ST8OFF(r2,r3,8) ;; + mov r3 = b0 ;; + ST8OFF(r2,r3,8) ;; + ST8OFF(r2,gp,8) ;; + + /* Save predicates on stack */ + mov r3 = pr ;; + st8 [r2] = r3 + + /* Save callee-save floating-point registers on stack */ + add r2 = 48, sp + add r3 = 64, sp ;; + STFSPILLOFF(r2,f2,16) ;; + STFSPILLOFF(r3,f3,16) ;; + STFSPILLOFF(r2,f4,16) ;; + STFSPILLOFF(r3,f5,16) ;; + STFSPILLOFF(r2,f16,16) ;; + STFSPILLOFF(r3,f17,16) ;; + STFSPILLOFF(r2,f18,16) ;; + STFSPILLOFF(r3,f19,16) ;; + STFSPILLOFF(r2,f20,16) ;; + STFSPILLOFF(r3,f21,16) ;; + STFSPILLOFF(r2,f22,16) ;; + STFSPILLOFF(r3,f23,16) ;; + STFSPILLOFF(r2,f24,16) ;; + STFSPILLOFF(r3,f25,16) ;; + STFSPILLOFF(r2,f26,16) ;; + STFSPILLOFF(r3,f27,16) ;; + STFSPILLOFF(r2,f28,16) ;; + STFSPILLOFF(r3,f29,16) ;; + STFSPILLOFF(r2,f30,16) ;; + STFSPILLOFF(r3,f31,16) ;; + + /* Recover entry point and gp from the function pointer in in0 */ + LD8OFF(r2,r32,8) ;; + ld8 r3 = [r32] ;; + mov b6 = r2 + mov gp = r3 ;; + + /* Shift arguments r33 ... r35 to r32 ... r34 */ + mov r32 = r33 + mov r33 = r34 + mov r34 = r35 + + /* Do the call */ + br.call.sptk b0 = b6 ;; + + /* Restore the saved floating-point registers */ + add r2 = 48, sp + add r3 = 64, sp ;; + LDFFILLOFF(f2,r2,16) ;; + LDFFILLOFF(f3,r3,16) ;; + LDFFILLOFF(f4,r2,16) ;; + LDFFILLOFF(f5,r3,16) ;; + LDFFILLOFF(f16,r2,16) ;; + LDFFILLOFF(f17,r3,16) ;; + LDFFILLOFF(f18,r2,16) ;; + LDFFILLOFF(f19,r3,16) ;; + LDFFILLOFF(f20,r2,16) ;; + LDFFILLOFF(f21,r3,16) ;; + LDFFILLOFF(f22,r2,16) ;; + LDFFILLOFF(f23,r3,16) ;; + LDFFILLOFF(f24,r2,16) ;; + LDFFILLOFF(f25,r3,16) ;; + LDFFILLOFF(f26,r2,16) ;; + LDFFILLOFF(f27,r3,16) ;; + LDFFILLOFF(f28,r2,16) ;; + LDFFILLOFF(f29,r3,16) ;; + LDFFILLOFF(f30,r2,16) ;; + LDFFILLOFF(f31,r3,16) ;; + + /* Restore gp, predicates and return */ + add r2 = 16, sp ;; + LD8OFF(r3,r2,8) ;; + mov ar.pfs = r3 + LD8OFF(r3,r2,8) ;; + mov b0 = r3 + LD8OFF(gp,r2,8) ;; + LD8OFF(r3,r2,8) ;; + mov pr = r3, -1 + + br.ret.sptk.many b0 ;; + + .endp call_gen_code# diff --git a/testasmcomp/integr.cmm b/testasmcomp/integr.cmm new file mode 100644 index 0000000..d2ec7b5 --- /dev/null +++ b/testasmcomp/integr.cmm @@ -0,0 +1,30 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: integr.cmm,v 1.5 2000-06-29 11:45:23 xleroy Exp $ *) + +(function "square" (x: float) + ( *f x x)) + +(function "integr" (f: addr low: float high: float n: int) + (let (h (/f (-f high low) (floatofint n)) + x low + s 0.0 + i n) + (while (> i 0) + (assign s (+f s (app f x float))) + (assign x (+f x h)) + (assign i (- i 1))) + ( *f s h))) + +(function "test" (n: int) + (app "integr" "square" 0.0 1.0 n float)) diff --git a/testasmcomp/lexcmm.mli b/testasmcomp/lexcmm.mli new file mode 100644 index 0000000..6877313 --- /dev/null +++ b/testasmcomp/lexcmm.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexcmm.mli,v 1.4 1999-11-17 18:58:42 xleroy Exp $ *) + +val token: Lexing.lexbuf -> Parsecmm.token + +type error = + Illegal_character + | Unterminated_comment + | Unterminated_string + +exception Error of error + +val report_error: Lexing.lexbuf -> error -> unit diff --git a/testasmcomp/lexcmm.mll b/testasmcomp/lexcmm.mll new file mode 100644 index 0000000..084dc89 --- /dev/null +++ b/testasmcomp/lexcmm.mll @@ -0,0 +1,228 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexcmm.mll,v 1.8 2000-06-25 19:54:50 xleroy Exp $ *) + +{ +open Parsecmm + +type error = + Illegal_character + | Unterminated_comment + | Unterminated_string + +exception Error of error + +(* For nested comments *) + +let comment_depth = ref 0 + +(* The table of keywords *) + +let keyword_table = + Misc.create_hashtable 149 [ + "absf", ABSF; + "addr", ADDR; + "align", ALIGN; + "alloc", ALLOC; + "and", AND; + "app", APPLY; + "assign", ASSIGN; + "byte", BYTE; + "case", CASE; + "catch", CATCH; + "checkbound", CHECKBOUND; + "exit", EXIT; + "extcall", EXTCALL; + "float", FLOAT; + "float32", FLOAT32; + "float64", FLOAT64; + "floatofint", FLOATOFINT; + "function", FUNCTION; + "half", HALF; + "if", IF; + "int", INT; + "int32", INT32; + "intoffloat", INTOFFLOAT; + "string", KSTRING; + "let", LET; + "load", LOAD; + "mod", MODI; + "or", OR; + "proj", PROJ; + "raise", RAISE; + "seq", SEQ; + "signed", SIGNED; + "skip", SKIP; + "store", STORE; + "switch", SWITCH; + "try", TRY; + "unit", UNIT; + "unsigned", UNSIGNED; + "while", WHILE; + "with", WITH; + "xor", XOR; + "addraref", ADDRAREF; + "intaref", INTAREF; + "floataref", FLOATAREF; + "addraset", ADDRASET; + "intaset", INTASET; + "floataset", FLOATASET +] + +(* To buffer string literals *) + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0 + +let store_string_char c = + if !string_index >= String.length (!string_buff) then begin + let new_buff = String.create (String.length (!string_buff) * 2) in + String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff)); + string_buff := new_buff + end; + String.unsafe_set (!string_buff) (!string_index) c; + incr string_index + +let get_stored_string () = + let s = String.sub (!string_buff) 0 (!string_index) in + string_buff := initial_string_buffer; + s + +(* To translate escape sequences *) + +let char_for_backslash = function + 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + Char.chr(100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48)) + +(* Error report *) + +let report_error lexbuf msg = + prerr_string "Lexical error around character "; + prerr_int (Lexing.lexeme_start lexbuf); + match msg with + Illegal_character -> + prerr_string ": illegal character" + | Unterminated_comment -> + prerr_string ": unterminated comment" + | Unterminated_string -> + prerr_string ": unterminated string" + +} + +rule token = parse + [' ' '\010' '\013' '\009' '\012'] + + { token lexbuf } + | "+a" { ADDA } + | "+f" { ADDF } + | "+" { ADDI } + | ">>s" { ASR } + | ":" { COLON } + | "/f" { DIVF } + | "/" { DIVI } + | eof { EOF } + | "==a" { EQA } + | "==f" { EQF } + | "==" { EQI } + | ">=a" { GEA } + | ">=f" { GEF } + | ">=" { GEI } + | ">a" { GTA } + | ">f" { GTF } + | ">" { GTI } + | "[" { LBRACKET } + | "<=a" { LEA } + | "<=f" { LEF } + | "<=" { LEI } + | "(" { LPAREN } + | "<<" { LSL } + | ">>u" { LSR } + | "<a" { LTA } + | "<f" { LTF } + | "<" { LTI } + | "*f" { MULF } + | "*" { MULI } + | "!=a" { NEA } + | "!=f" { NEF } + | "!=" { NEI } + | "]" { RBRACKET } + | ")" { RPAREN } + | "*" { STAR } + | "-a" { SUBA } + | "-f" { SUBF } + | "-" { SUBI } + | '-'? (['0'-'9']+ | "0x" ['0'-'9' 'a'-'f' 'A'-'F']+ + | "0o" ['0'-'7']+ | "0b" ['0'-'1']+) + { INTCONST(int_of_string(Lexing.lexeme lexbuf)) } + | '-'? ['0'-'9']+ 'a' + { let s = Lexing.lexeme lexbuf in + POINTER(int_of_string(String.sub s 0 (String.length s - 1))) } + | '-'? ['0'-'9']+ ('.' ['0'-'9']*)? (['e' 'E'] ['+' '-']? ['0'-'9']+)? + { FLOATCONST(Lexing.lexeme lexbuf) } + | ['A'-'Z' 'a'-'z' '\223'-'\246' '\248'-'\255' ] + (['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' + '\'' '0'-'9' ]) * + { let s = Lexing.lexeme lexbuf in + try + Hashtbl.find keyword_table s + with Not_found -> + IDENT s } + | "\"" + { reset_string_buffer(); + string lexbuf; + STRING (get_stored_string()) } + | "(*" + { comment_depth := 1; + comment lexbuf; + token lexbuf } + | _ { raise(Error(Illegal_character)) } + +and comment = parse + "(*" + { comment_depth := succ !comment_depth; comment lexbuf } + | "*)" + { comment_depth := pred !comment_depth; + if !comment_depth > 0 then comment lexbuf } + | eof + { raise (Error(Unterminated_comment)) } + | _ + { comment lexbuf } + +and string = parse + '"' + { () } + | '\\' [' ' '\010' '\013' '\009' '\026' '\012'] + + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise (Error(Unterminated_string)) } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } diff --git a/testasmcomp/m68k.S b/testasmcomp/m68k.S new file mode 100644 index 0000000..3bb6aec --- /dev/null +++ b/testasmcomp/m68k.S @@ -0,0 +1,59 @@ +|*********************************************************************** +|* * +|* Objective Caml * +|* * +|* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +|* * +|* Copyright 1996 Institut National de Recherche en Informatique et * +|* en Automatique. All rights reserved. This file is distributed * +|* under the terms of the Q Public License version 1.0. * +|* * +|*********************************************************************** + +| $Id: m68k.S,v 1.2 1999-11-17 18:58:42 xleroy Exp $ + +| call_gen_code is used with the following types: +| unit -> int +| int -> int +| int -> double +| int * int * address -> void +| int * int -> void +| unit -> unit +| Hence arg1 -> d0, arg2 -> d1, arg3 -> a0, +| and we need a special case for int -> double + + .text + .globl _call_gen_code +_call_gen_code: + link a6, #0 + movem d2-d7/a2-a6, a7@- + fmovem fp2-fp7, a7@- + movel a6@(8), a1 + movel a6@(12), d0 + movel a6@(16), d1 + movel a6@(20), a0 + jsr a1@ + fmovem a7@+, fp2-fp7 + movem a7@+, d2-d7/a2-a6 + unlk a6 + rts + + .globl _call_gen_code_float +_call_gen_code_float: + link a6, #0 + moveml d2-d7/a2-a6, a7@- + fmovem fp2-fp7, a7@- + movel a6@(8), a1 + movel a6@(12), d0 + jsr a1@ + fmoved fp0, a7@- + movel a7@+, d0 + movel a7@+, d1 + fmovem a7@+, fp2-fp7 + moveml a7@+, d2-d7/a2-a6 + unlk a6 + rts + + .globl _caml_c_call +_caml_c_call: + jmp a0@ diff --git a/testasmcomp/main.c b/testasmcomp/main.c new file mode 100644 index 0000000..2737e7c --- /dev/null +++ b/testasmcomp/main.c @@ -0,0 +1,126 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: main.c,v 1.12 2003-06-30 08:28:46 xleroy Exp $ */ + +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +void caml_array_bound_error(void) +{ + fprintf(stderr, "Fatal error: out-of-bound access in array or string\n"); + exit(2); +} + +void print_string(char * s) +{ + fputs(s, stdout); +} + +void printf_int(char * fmt, int arg) +{ + printf(fmt, arg); +} + +#ifdef SORT + +int cmpint(const void * i, const void * j) +{ + long vi = *((long *) i); + long vj = *((long *) j); + if (vi == vj) return 0; + if (vi < vj) return -1; + return 1; +} + +#endif + +int main(int argc, char **argv) +{ +#ifdef UNIT_INT + { extern int FUN(); + extern int call_gen_code(); + printf("%d\n", call_gen_code(FUN)); + } +#else + if (argc < 2) { + fprintf(stderr, "Usage: %s [int arg]\n", argv[0]); + exit(2); + } +#ifdef INT_INT + { extern int FUN(); + extern int call_gen_code(); + printf("%d\n", call_gen_code(FUN, atoi(argv[1]))); + } +#endif +#ifdef INT_FLOAT + { extern double FUN(); +#ifdef __mc68020__ +#define call_gen_code call_gen_code_float +#endif + extern double call_gen_code(); + printf("%f\n", call_gen_code(FUN, atoi(argv[1]))); + } +#endif +#ifdef SORT + { extern void FUN(); + extern void call_gen_code(); + long n; + long * a, * b; + long i; + + srand(argc >= 3 ? atoi(argv[2]) : time((char *) 0)); + n = atoi(argv[1]); + a = (long *) malloc(n * sizeof(long)); + for (i = 0 ; i < n; i++) a[i] = rand() & 0xFFF; +#ifdef DEBUG + for (i = 0; i < n; i++) printf("%ld ", a[i]); printf("\n"); +#endif + b = (long *) malloc(n * sizeof(long)); + for (i = 0; i < n; i++) b[i] = a[i]; + call_gen_code(FUN, 0, n-1, a); +#ifdef DEBUG + for (i = 0; i < n; i++) printf("%ld ", a[i]); printf("\n"); +#endif + qsort(b, n, sizeof(long), cmpint); + for (i = 0; i < n; i++) { + if (a[i] != b[i]) { printf("Bug!\n"); return 2; } + } + printf("OK\n"); + } +#endif +#endif +#ifdef CHECKBOUND + { extern void checkbound1(), checkbound2(); + extern void call_gen_code(); + long x, y; + x = atoi(argv[1]); + if (argc >= 3) { + y = atoi(argv[2]); + if ((unsigned long) x < (unsigned long) y) + printf("Should not trap\n"); + else + printf("Should trap\n"); + call_gen_code(checkbound2, y, x); + } else { + if (2 < (unsigned long) x) + printf("Should not trap\n"); + else + printf("Should trap\n"); + call_gen_code(checkbound1, x); + } + printf("OK\n"); + } +#endif + return 0; +} diff --git a/testasmcomp/main.ml b/testasmcomp/main.ml new file mode 100644 index 0000000..10f0ea5 --- /dev/null +++ b/testasmcomp/main.ml @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: main.ml,v 1.12 2000-07-07 14:09:23 xleroy Exp $ *) + +open Clflags + +let compile_file filename = + Compilenv.reset "test"; + Emit.begin_assembly(); + let ic = open_in filename in + let lb = Lexing.from_channel ic in + try + while true do + Asmgen.compile_phrase Format.std_formatter (Parsecmm.phrase Lexcmm.token lb) + done + with + End_of_file -> + close_in ic; Emit.end_assembly() + | Lexcmm.Error msg -> + close_in ic; Lexcmm.report_error lb msg + | Parsing.Parse_error -> + close_in ic; + prerr_string "Syntax error near character "; + prerr_int (Lexing.lexeme_start lb); + prerr_newline() + | Parsecmmaux.Error msg -> + close_in ic; Parsecmmaux.report_error msg + | x -> + close_in ic; raise x + +let usage = "Usage: codegen <options> <files>\noptions are:" + +let main() = + Arg.parse [ + "-dcmm", Arg.Set dump_cmm, ""; + "-dsel", Arg.Set dump_selection, ""; + "-dlive", Arg.Unit(fun () -> dump_live := true; + Printmach.print_live := true), ""; + "-dspill", Arg.Set dump_spill, ""; + "-dsplit", Arg.Set dump_split, ""; + "-dinterf", Arg.Set dump_interf, ""; + "-dprefer", Arg.Set dump_prefer, ""; + "-dalloc", Arg.Set dump_regalloc, ""; + "-dreload", Arg.Set dump_reload, ""; + "-dscheduling", Arg.Set dump_scheduling, ""; + "-dlinear", Arg.Set dump_linear, "" + ] compile_file usage + +let _ = (*Printexc.catch*) main (); exit 0 + diff --git a/testasmcomp/mainarith.c b/testasmcomp/mainarith.c new file mode 100644 index 0000000..a6438d1 --- /dev/null +++ b/testasmcomp/mainarith.c @@ -0,0 +1,304 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: mainarith.c,v 1.20 2000-07-21 08:09:05 xleroy Exp $ */ + +#include <stdio.h> +#include <math.h> + +void caml_array_bound_error(void) +{ + fprintf(stderr, "Fatal error: out-of-bound access in array or string\n"); + exit(2); +} + +long R[200]; +double D[40]; +long X, Y; +double F, G; + +#define INTTEST(arg,res) \ + { long result = (res); \ + if (arg != result) \ + printf("Failed test \"%s == %s\" for X=%ld and Y=%ld: result %ld, expected %ld\n", \ + #arg, #res, X, Y, arg, result); \ + } +#define INTFLOATTEST(arg,res) \ + { long result = (res); \ + if (arg != result) \ + printf("Failed test \"%s == %s\" for F=%.15g and G=%.15g: result %ld, expected %ld\n", \ + #arg, #res, F, G, arg, result); \ + } +#define FLOATTEST(arg,res) \ + { double result = (res); \ + if (arg < result || arg > result) \ + printf("Failed test \"%s == %s\" for F=%.15g and G=%.15g: result %.15g, expected %.15g\n", \ + #arg, #res, F, G, arg, result); \ + } +#define FLOATINTTEST(arg,res) \ + { double result = (res); \ + if (arg < result || arg > result) \ + printf("Failed test \"%s == %s\" for X=%ld and Y=%ld: result %.15g, expected %.15g\n", \ + #arg, #res, X, Y, arg, result); \ + } + +extern void call_gen_code(); +extern void testarith(); + +void do_test(void) +{ + call_gen_code(testarith); + + INTTEST(R[0], 0); + INTTEST(R[1], 1); + INTTEST(R[2], -1); + INTTEST(R[3], 256); + INTTEST(R[4], 65536); + INTTEST(R[5], 16777216); + INTTEST(R[6], -256); + INTTEST(R[7], -65536); + INTTEST(R[8], -16777216); + + INTTEST(R[9], (X + Y)); + INTTEST(R[10], (X + 1)); + INTTEST(R[11], (X + -1)); + + INTTEST(R[12], ((long) ((char *)R + 8))); + INTTEST(R[13], ((long) ((char *)R + Y))); + + INTTEST(R[14], (X - Y)); + INTTEST(R[15], (X - 1)); + INTTEST(R[16], (X - -1)); + + INTTEST(R[17], ((long) ((char *)R - 8))); + INTTEST(R[18], ((long) ((char *)R - Y))); + + INTTEST(R[19], (X * 2)); + INTTEST(R[20], (2 * X)); + INTTEST(R[21], (X * 16)); + INTTEST(R[22], (16 * X)); + INTTEST(R[23], (X * 12345)); + INTTEST(R[24], (12345 * X)); + INTTEST(R[25], (X * Y)); + + INTTEST(R[26], (X / 2)); + INTTEST(R[27], (X / 16)); + INTTEST(R[28], (X / 7)); + INTTEST(R[29], (Y != 0 ? X / Y : 0)); + + INTTEST(R[30], (X % 2)); + INTTEST(R[31], (X % 16)); + INTTEST(R[32], (Y != 0 ? X % Y : 0)); + + INTTEST(R[33], (X & Y)); + INTTEST(R[34], (X & 3)); + INTTEST(R[35], (3 & X)); + + INTTEST(R[36], (X | Y)); + INTTEST(R[37], (X | 3)); + INTTEST(R[38], (3 | X)); + + INTTEST(R[39], (X ^ Y)); + INTTEST(R[40], (X ^ 3)); + INTTEST(R[41], (3 ^ X)); + + INTTEST(R[42], (X << Y)); + INTTEST(R[43], (X << 1)); + INTTEST(R[44], (X << 8)); + + INTTEST(R[45], ((unsigned long) X >> Y)); + INTTEST(R[46], ((unsigned long) X >> 1)); + INTTEST(R[47], ((unsigned long) X >> 8)); + + INTTEST(R[48], (X >> Y)); + INTTEST(R[49], (X >> 1)); + INTTEST(R[50], (X >> 8)); + + INTTEST(R[51], (X == Y)); + INTTEST(R[52], (X != Y)); + INTTEST(R[53], (X < Y)); + INTTEST(R[54], (X > Y)); + INTTEST(R[55], (X <= Y)); + INTTEST(R[56], (X >= Y)); + INTTEST(R[57], (X == 1)); + INTTEST(R[58], (X != 1)); + INTTEST(R[59], (X < 1)); + INTTEST(R[60], (X > 1)); + INTTEST(R[61], (X <= 1)); + INTTEST(R[62], (X >= 1)); + + INTTEST(R[63], ((char *)X == (char *)Y)); + INTTEST(R[64], ((char *)X != (char *)Y)); + INTTEST(R[65], ((char *)X < (char *)Y)); + INTTEST(R[66], ((char *)X > (char *)Y)); + INTTEST(R[67], ((char *)X <= (char *)Y)); + INTTEST(R[68], ((char *)X >= (char *)Y)); + INTTEST(R[69], ((char *)X == (char *)1)); + INTTEST(R[70], ((char *)X != (char *)1)); + INTTEST(R[71], ((char *)X < (char *)1)); + INTTEST(R[72], ((char *)X > (char *)1)); + INTTEST(R[73], ((char *)X <= (char *)1)); + INTTEST(R[74], ((char *)X >= (char *)1)); + + INTTEST(R[75], (X + (Y << 1))); + INTTEST(R[76], (X + (Y << 2))); + INTTEST(R[77], (X + (Y << 3))); + INTTEST(R[78], (X - (Y << 1))); + INTTEST(R[79], (X - (Y << 2))); + INTTEST(R[80], (X - (Y << 3))); + + FLOATTEST(D[0], 0.0); + FLOATTEST(D[1], 1.0); + FLOATTEST(D[2], -1.0); + FLOATTEST(D[3], (F + G)); + FLOATTEST(D[4], (F - G)); + FLOATTEST(D[5], (F * G)); + FLOATTEST(D[6], F / G); + + FLOATTEST(D[7], (F + (G + 1.0))); + FLOATTEST(D[8], (F - (G + 1.0))); + FLOATTEST(D[9], (F * (G + 1.0))); + FLOATTEST(D[10], F / (G + 1.0)); + + FLOATTEST(D[11], ((F + 1.0) + G)); + FLOATTEST(D[12], ((F + 1.0) - G)); + FLOATTEST(D[13], ((F + 1.0) * G)); + FLOATTEST(D[14], (F + 1.0) / G); + + FLOATTEST(D[15], ((F + 1.0) + (G + 1.0))); + FLOATTEST(D[16], ((F + 1.0) - (G + 1.0))); + FLOATTEST(D[17], ((F + 1.0) * (G + 1.0))); + FLOATTEST(D[18], (F + 1.0) / (G + 1.0)); + + INTFLOATTEST(R[81], (F == G)); + INTFLOATTEST(R[82], (F != G)); + INTFLOATTEST(R[83], (F < G)); + INTFLOATTEST(R[84], (F > G)); + INTFLOATTEST(R[85], (F <= G)); + INTFLOATTEST(R[86], (F >= G)); + + FLOATINTTEST(D[19], (double) X); + INTFLOATTEST(R[87], (long) F); + + INTTEST(R[88], (X >= 0) && (X < Y)); + INTTEST(R[89], (0 < Y)); + INTTEST(R[90], (5 < Y)); + + INTFLOATTEST(R[91], (F == G)); + INTFLOATTEST(R[92], (F != G)); + INTFLOATTEST(R[93], (F < G)); + INTFLOATTEST(R[94], (F > G)); + INTFLOATTEST(R[95], (F <= G)); + INTFLOATTEST(R[96], (F >= G)); + + INTFLOATTEST(R[97], (F + 1.0 == G + 1.0)); + INTFLOATTEST(R[98], (F + 1.0 != G + 1.0)); + INTFLOATTEST(R[99], (F + 1.0 < G + 1.0)); + INTFLOATTEST(R[100], (F + 1.0 > G + 1.0)); + INTFLOATTEST(R[101], (F + 1.0 <= G + 1.0)); + INTFLOATTEST(R[102], (F + 1.0 >= G + 1.0)); + + INTFLOATTEST(R[103], (F == G + 1.0)); + INTFLOATTEST(R[104], (F != G + 1.0)); + INTFLOATTEST(R[105], (F < G + 1.0)); + INTFLOATTEST(R[106], (F > G + 1.0)); + INTFLOATTEST(R[107], (F <= G + 1.0)); + INTFLOATTEST(R[108], (F >= G + 1.0)); + + INTFLOATTEST(R[109], (F + 1.0 == G)); + INTFLOATTEST(R[110], (F + 1.0 != G)); + INTFLOATTEST(R[111], (F + 1.0 < G)); + INTFLOATTEST(R[112], (F + 1.0 > G)); + INTFLOATTEST(R[113], (F + 1.0 <= G)); + INTFLOATTEST(R[114], (F + 1.0 >= G)); + + FLOATINTTEST(D[20], ((double) X) + 1.0); + INTFLOATTEST(R[115], (long)(F + 1.0)); + + FLOATTEST(D[21], F + G); + FLOATTEST(D[22], G + F); + FLOATTEST(D[23], F - G); + FLOATTEST(D[24], G - F); + FLOATTEST(D[25], F * G); + FLOATTEST(D[26], G * F); + FLOATTEST(D[27], F / G); + FLOATTEST(D[28], G / F); + + FLOATTEST(D[29], (F * 2.0) + G); + FLOATTEST(D[30], G + (F * 2.0)); + FLOATTEST(D[31], (F * 2.0) - G); + FLOATTEST(D[32], G - (F * 2.0)); + FLOATTEST(D[33], (F + 2.0) * G); + FLOATTEST(D[34], G * (F + 2.0)); + FLOATTEST(D[35], (F * 2.0) / G); + FLOATTEST(D[36], G / (F * 2.0)); + + FLOATTEST(D[37], - F); + FLOATTEST(D[38], fabs(F)); +} + +#ifdef __i386__ +#ifdef __FreeBSD__ +#include <floatingpoint.h> +#endif +#endif + +void init_ieee_floats(void) +{ +#ifdef __i386__ +#ifdef __FreeBSD__ + fpsetmask(0); +#endif +#endif +} + +int main(int argc, char **argv) +{ + double weird[4]; + + init_ieee_floats(); + + if (argc >= 5) { + X = atoi(argv[1]); + Y = atoi(argv[2]); + sscanf(argv[3], "%lf", &F); + sscanf(argv[4], "%lf", &G); + do_test(); + return 0; + } + for(Y = -2; Y <= 2; Y++) { + for (X = -2; X <= 2; X++) { + F = X; G = Y; do_test(); + } + } + if (!(argc >= 2 && strcmp(argv[1], "noinf"))) { + weird[0] = 0.0; + weird[1] = 1.0 / weird[0]; /* +infty */ + weird[2] = -1.0 / weird[0]; /* -infty */ + weird[3] = 0.0 / weird[0]; /* NaN */ + for (X = 0; X < 4; X++) { + for (Y = 0; Y < 4; Y++) { + F = weird[X]; G = weird[Y]; do_test(); + } + } + } + while(1) { + X = (rand() & 0x1FFFFFFF) - 0x10000000; + Y = (rand() & 0x1FFFFFFF) - 0x10000000; + F = X / 1e3; + G = Y / 1e3; + do_test(); + printf("."); fflush(stdout); + } + return 0; +} + diff --git a/testasmcomp/mips.s b/testasmcomp/mips.s new file mode 100644 index 0000000..70c055d --- /dev/null +++ b/testasmcomp/mips.s @@ -0,0 +1,71 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: mips.s,v 1.3 1999-11-29 19:04:19 doligez Exp $ */ + + .globl call_gen_code + .ent call_gen_code +call_gen_code: + subu $sp, $sp, 0x90 + sd $31, 0x88($sp) + /* Save all callee-save registers */ + sd $16, 0x0($sp) + sd $17, 0x8($sp) + sd $18, 0x10($sp) + sd $19, 0x18($sp) + sd $20, 0x20($sp) + sd $21, 0x28($sp) + sd $22, 0x30($sp) + sd $23, 0x38($sp) + sd $30, 0x40($sp) + s.d $f20, 0x48($sp) + s.d $f22, 0x50($sp) + s.d $f24, 0x58($sp) + s.d $f26, 0x60($sp) + s.d $f28, 0x68($sp) + s.d $f30, 0x70($sp) + /* Shuffle arguments */ + move $8, $5 + move $9, $6 + move $10, $7 + move $25, $4 + jal $4 + /* Restore registers */ + ld $31, 0x88($sp) + ld $16, 0x0($sp) + ld $17, 0x8($sp) + ld $18, 0x10($sp) + ld $19, 0x18($sp) + ld $20, 0x20($sp) + ld $21, 0x28($sp) + ld $22, 0x30($sp) + ld $23, 0x38($sp) + ld $30, 0x40($sp) + l.d $f20, 0x48($sp) + l.d $f22, 0x50($sp) + l.d $f24, 0x58($sp) + l.d $f26, 0x60($sp) + l.d $f28, 0x68($sp) + l.d $f30, 0x70($sp) + addu $sp, $sp, 0x90 + j $31 + + .end call_gen_code + +/* Call a C function */ + + .globl caml_c_call + .ent caml_c_call +caml_c_call: + move $25, $24 + j $24 + .end caml_c_call diff --git a/testasmcomp/parsecmm.mly b/testasmcomp/parsecmm.mly new file mode 100644 index 0000000..a3bbc53 --- /dev/null +++ b/testasmcomp/parsecmm.mly @@ -0,0 +1,325 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: parsecmm.mly,v 1.11 2003-06-30 08:28:48 xleroy Exp $ */ + +/* A simple parser for C-- */ + +%{ +open Cmm +open Parsecmmaux + +let rec make_letdef def body = + match def with + [] -> body + | (id, def) :: rem -> + unbind_ident id; + Clet(id, def, make_letdef rem body) + +let make_switch n selector caselist = + let index = Array.create n 0 in + let casev = Array.of_list caselist in + let actv = Array.create (Array.length casev) (Cexit(0,[])) in + for i = 0 to Array.length casev - 1 do + let (posl, e) = casev.(i) in + List.iter (fun pos -> index.(pos) <- i) posl; + actv.(i) <- e + done; + Cswitch(selector, index, actv) + +let access_array base numelt size = + match numelt with + Cconst_int 0 -> base + | Cconst_int n -> Cop(Cadda, [base; Cconst_int(n * size)]) + | _ -> Cop(Cadda, [base; + Cop(Clsl, [numelt; Cconst_int(Misc.log2 size)])]) + +%} + +%token ABSF +%token ADDA +%token ADDF +%token ADDI +%token ADDR +%token ALIGN +%token ALLOC +%token AND +%token APPLY +%token ASR +%token ASSIGN +%token BYTE +%token CASE +%token CATCH +%token CHECKBOUND +%token COLON +%token DIVF +%token DIVI +%token EOF +%token EQA +%token EQF +%token EQI +%token EXIT +%token EXTCALL +%token FLOAT +%token FLOAT32 +%token FLOAT64 +%token <string> FLOATCONST +%token FLOATOFINT +%token FUNCTION +%token GEA +%token GEF +%token GEI +%token GTA +%token GTF +%token GTI +%token HALF +%token <string> IDENT +%token IF +%token INT +%token INT32 +%token <int> INTCONST +%token INTOFFLOAT +%token KSTRING +%token LBRACKET +%token LEA +%token LEF +%token LEI +%token LET +%token LOAD +%token LPAREN +%token LSL +%token LSR +%token LTA +%token LTF +%token LTI +%token MODI +%token MULF +%token MULI +%token NEA +%token NEF +%token NEI +%token OR +%token <int> POINTER +%token PROJ +%token RAISE +%token RBRACKET +%token RPAREN +%token SEQ +%token SIGNED +%token SKIP +%token STAR +%token STORE +%token <string> STRING +%token SUBA +%token SUBF +%token SUBI +%token SWITCH +%token TRY +%token UNIT +%token UNSIGNED +%token WHILE +%token WITH +%token XOR +%token ADDRAREF +%token INTAREF +%token FLOATAREF +%token ADDRASET +%token INTASET +%token FLOATASET + +%start phrase +%type <Cmm.phrase> phrase + +%% + +phrase: + fundecl { Cfunction $1 } + | datadecl { Cdata $1 } + | EOF { raise End_of_file } +; +fundecl: + LPAREN FUNCTION STRING LPAREN params RPAREN sequence RPAREN + { List.iter (fun (id, ty) -> unbind_ident id) $5; + {fun_name = $3; fun_args = $5; fun_body = $7; fun_fast = true} } +; +params: + oneparam params { $1 :: $2 } + | /**/ { [] } +; +oneparam: + IDENT COLON machtype { (bind_ident $1, $3) } +; +machtype: + UNIT { [||] } + | componentlist { Array.of_list(List.rev $1) } +; +component: + ADDR { Addr } + | INT { Int } + | FLOAT { Float } +; +componentlist: + component { [$1] } + | componentlist STAR component { $3 :: $1 } +; +expr: + INTCONST { Cconst_int $1 } + | FLOATCONST { Cconst_float $1 } + | STRING { Cconst_symbol $1 } + | POINTER { Cconst_pointer $1 } + | IDENT { Cvar(find_ident $1) } + | LBRACKET RBRACKET { Ctuple [] } + | LPAREN LET letdef sequence RPAREN { make_letdef $3 $4 } + | LPAREN ASSIGN IDENT expr RPAREN { Cassign(find_ident $3, $4) } + | LPAREN APPLY expr exprlist machtype RPAREN { Cop(Capply $5, $3 :: List.rev $4) } + | LPAREN EXTCALL STRING exprlist machtype RPAREN { Cop(Cextcall($3, $5, false), List.rev $4) } + | LPAREN SUBF expr RPAREN { Cop(Cnegf, [$3]) } + | LPAREN SUBF expr expr RPAREN { Cop(Csubf, [$3; $4]) } + | LPAREN unaryop expr RPAREN { Cop($2, [$3]) } + | LPAREN binaryop expr expr RPAREN { Cop($2, [$3; $4]) } + | LPAREN SEQ sequence RPAREN { $3 } + | LPAREN IF expr expr expr RPAREN { Cifthenelse($3, $4, $5) } + | LPAREN SWITCH INTCONST expr caselist RPAREN { make_switch $3 $4 $5 } + | LPAREN WHILE expr sequence RPAREN + { let body = + match $3 with + Cconst_int x when x <> 0 -> $4 + | _ -> Cifthenelse($3, $4, (Cexit(0,[]))) in + Ccatch(0, [], Cloop body, Ctuple []) } + | LPAREN CATCH sequence WITH sequence RPAREN { Ccatch(0, [], $3, $5) } + | EXIT { Cexit(0,[]) } + | LPAREN TRY sequence WITH bind_ident sequence RPAREN + { unbind_ident $5; Ctrywith($3, $5, $6) } + | LPAREN ADDRAREF expr expr RPAREN + { Cop(Cload Word, [access_array $3 $4 Arch.size_addr]) } + | LPAREN INTAREF expr expr RPAREN + { Cop(Cload Word, [access_array $3 $4 Arch.size_int]) } + | LPAREN FLOATAREF expr expr RPAREN + { Cop(Cload Double_u, [access_array $3 $4 Arch.size_float]) } + | LPAREN ADDRASET expr expr expr RPAREN + { Cop(Cstore Word, [access_array $3 $4 Arch.size_addr; $5]) } + | LPAREN INTASET expr expr expr RPAREN + { Cop(Cstore Word, [access_array $3 $4 Arch.size_int; $5]) } + | LPAREN FLOATASET expr expr expr RPAREN + { Cop(Cstore Double_u, [access_array $3 $4 Arch.size_float; $5]) } +; +exprlist: + exprlist expr { $2 :: $1 } + | /**/ { [] } +; +letdef: + oneletdef { [$1] } + | LPAREN letdefmult RPAREN { $2 } +; +letdefmult: + /**/ { [] } + | oneletdef letdefmult { $1 :: $2 } +; +oneletdef: + IDENT expr { (bind_ident $1, $2) } +; +chunk: + UNSIGNED BYTE { Byte_unsigned } + | SIGNED BYTE { Byte_signed } + | UNSIGNED HALF { Sixteen_unsigned } + | SIGNED HALF { Sixteen_signed } + | UNSIGNED INT32 { Thirtytwo_unsigned } + | SIGNED INT32 { Thirtytwo_signed } + | INT { Word } + | ADDR { Word } + | FLOAT32 { Single } + | FLOAT64 { Double } + | FLOAT { Double_u } + +; +unaryop: + LOAD chunk { Cload $2 } + | ALLOC { Calloc } + | FLOATOFINT { Cfloatofint } + | INTOFFLOAT { Cintoffloat } + | RAISE { Craise } + | ABSF { Cabsf } +; +binaryop: + STORE chunk { Cstore $2 } + | ADDI { Caddi } + | SUBI { Csubi } + | MULI { Cmuli } + | DIVI { Cdivi } + | MODI { Cmodi } + | AND { Cand } + | OR { Cor } + | XOR { Cxor } + | LSL { Clsl } + | LSR { Clsr } + | ASR { Casr } + | EQI { Ccmpi Ceq } + | NEI { Ccmpi Cne } + | LTI { Ccmpi Clt } + | LEI { Ccmpi Cle } + | GTI { Ccmpi Cgt } + | GEI { Ccmpi Cge } + | ADDA { Cadda } + | SUBA { Csuba } + | EQA { Ccmpa Ceq } + | NEA { Ccmpa Cne } + | LTA { Ccmpa Clt } + | LEA { Ccmpa Cle } + | GTA { Ccmpa Cgt } + | GEA { Ccmpa Cge } + | ADDF { Caddf } + | MULF { Cmulf } + | DIVF { Cdivf } + | EQF { Ccmpf Ceq } + | NEF { Ccmpf Cne } + | LTF { Ccmpf Clt } + | LEF { Ccmpf Cle } + | GTF { Ccmpf Cgt } + | GEF { Ccmpf Cge } + | CHECKBOUND { Ccheckbound } +; +sequence: + expr sequence { Csequence($1, $2) } + | expr { $1 } +; +caselist: + onecase sequence caselist { ($1, $2) :: $3 } + | /**/ { [] } +; +onecase: + CASE INTCONST COLON onecase { $2 :: $4 } + | CASE INTCONST COLON { [$2] } +; +bind_ident: + IDENT { bind_ident $1 } +; +datadecl: + LPAREN datalist RPAREN { List.rev $2 } +; +datalist: + datalist dataitem { $2 :: $1 } + | /**/ { [] } +; +dataitem: + STRING COLON { Cdefine_symbol $1 } + | INTCONST COLON { Cdefine_label $1 } + | BYTE INTCONST { Cint8 $2 } + | HALF INTCONST { Cint16 $2 } + | INT INTCONST { Cint(Nativeint.of_int $2) } + | FLOAT FLOATCONST { Cdouble $2 } + | ADDR STRING { Csymbol_address $2 } + | ADDR INTCONST { Clabel_address $2 } + | KSTRING STRING { Cstring $2 } + | SKIP INTCONST { Cskip $2 } + | ALIGN INTCONST { Calign $2 } +; + diff --git a/testasmcomp/parsecmmaux.ml b/testasmcomp/parsecmmaux.ml new file mode 100644 index 0000000..7f5180a --- /dev/null +++ b/testasmcomp/parsecmmaux.ml @@ -0,0 +1,40 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parsecmmaux.ml,v 1.4 1999-11-17 18:58:43 xleroy Exp $ *) + +(* Auxiliary functions for parsing *) + +type error = + Unbound of string + +exception Error of error + +let tbl_ident = (Hashtbl.create 57 : (string, Ident.t) Hashtbl.t) + +let bind_ident s = + let id = Ident.create s in + Hashtbl.add tbl_ident s id; + id + +let find_ident s = + try + Hashtbl.find tbl_ident s + with Not_found -> + raise(Error(Unbound s)) + +let unbind_ident id = + Hashtbl.remove tbl_ident (Ident.name id) + +let report_error = function + Unbound s -> + prerr_string "Unbound identifier "; prerr_string s; prerr_endline "." diff --git a/testasmcomp/parsecmmaux.mli b/testasmcomp/parsecmmaux.mli new file mode 100644 index 0000000..88f7c4d --- /dev/null +++ b/testasmcomp/parsecmmaux.mli @@ -0,0 +1,26 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parsecmmaux.mli,v 1.4 1999-11-17 18:58:43 xleroy Exp $ *) + +(* Auxiliary functions for parsing *) + +val bind_ident: string -> Ident.t +val find_ident: string -> Ident.t +val unbind_ident: Ident.t -> unit + +type error = + Unbound of string + +exception Error of error + +val report_error: error -> unit diff --git a/testasmcomp/power-aix.S b/testasmcomp/power-aix.S new file mode 100644 index 0000000..7bac40a --- /dev/null +++ b/testasmcomp/power-aix.S @@ -0,0 +1,152 @@ +#********************************************************************* +#* * +#* Objective Caml * +#* * +#* Xavier Leroy, projet Cristal, INRIA Rocquencourt * +#* * +#* Copyright 1996 Institut National de Recherche en Informatique et * +#* en Automatique. All rights reserved. This file is distributed * +#* under the terms of the Q Public License version 1.0. * +#* * +#********************************************************************* + +# $Id: power-aix.S,v 1.3 2000-04-05 18:30:22 doligez Exp $ + + .csect .text[PR] + + .globl .call_gen_code +.call_gen_code: +# Save return address + mflr 0 + stw 0, 8(1) +# Save all callee-save registers + stw 13,-76(1) + stw 14,-72(1) + stw 15,-68(1) + stw 16,-64(1) + stw 17,-60(1) + stw 18,-56(1) + stw 19,-52(1) + stw 20,-48(1) + stw 21,-44(1) + stw 22,-40(1) + stw 23,-36(1) + stw 24,-32(1) + stw 25,-28(1) + stw 26,-24(1) + stw 27,-20(1) + stw 28,-16(1) + stw 29,-12(1) + stw 30,-8(1) + stw 31,-4(1) + stfd 14, -224(1) + stfd 15, -216(1) + stfd 16, -208(1) + stfd 17, -200(1) + stfd 18, -192(1) + stfd 19, -184(1) + stfd 20, -176(1) + stfd 21, -168(1) + stfd 22, -160(1) + stfd 23, -152(1) + stfd 24, -144(1) + stfd 25, -136(1) + stfd 26, -128(1) + stfd 27, -120(1) + stfd 28, -112(1) + stfd 29, -104(1) + stfd 30, -96(1) + stfd 31, -88(1) +# Allocate and link stack frame + stwu 1, -280(1) +# Save global pointer + stw 2, 20(1) +# Load code to call + lwz 0, 0(3) + lwz 2, 4(3) + mtlr 0 +# Shuffle arguments + mr 3, 4 + mr 4, 5 + mr 5, 6 + mr 6, 7 +# Call the function + blrl +# Restore global pointer + lwz 2, 20(1) +# Deallocate stack frame + addic 1, 1, 280 +# Restore callee-save registers + lwz 13,-76(1) + lwz 14,-72(1) + lwz 15,-68(1) + lwz 16,-64(1) + lwz 17,-60(1) + lwz 18,-56(1) + lwz 19,-52(1) + lwz 20,-48(1) + lwz 21,-44(1) + lwz 22,-40(1) + lwz 23,-36(1) + lwz 24,-32(1) + lwz 25,-28(1) + lwz 26,-24(1) + lwz 27,-20(1) + lwz 28,-16(1) + lwz 29,-12(1) + lwz 30,-8(1) + lwz 31,-4(1) + lfd 14, -224(1) + lfd 15, -216(1) + lfd 16, -208(1) + lfd 17, -200(1) + lfd 18, -192(1) + lfd 19, -184(1) + lfd 20, -176(1) + lfd 21, -168(1) + lfd 22, -160(1) + lfd 23, -152(1) + lfd 24, -144(1) + lfd 25, -136(1) + lfd 26, -128(1) + lfd 27, -120(1) + lfd 28, -112(1) + lfd 29, -104(1) + lfd 30, -96(1) + lfd 31, -88(1) +# Reload return address + lwz 0, 8(1) + mtlr 0 +# Return + blr + + .globl .caml_c_call +.caml_c_call: +# Preserve RTOC and return address in callee-save registers +# The C function will preserve them, and the Caml code does not +# expect them to be preserved +# Return address is in 25, RTOC is in 26 + mflr 25 + mr 26, 2 +# Call desired function (descriptor in r11) + lwz 0, 0(11) + lwz 2, 4(11) + mtlr 0 + blrl +# Restore return address and RTOC + mtlr 25 + mr 2, 26 +# Return to caller + blr + +# Function closures + + .globl call_gen_code + .csect call_gen_code[DS] +call_gen_code: + .long .call_gen_code, TOC[tc0], 0 + + .globl caml_c_call + .csect caml_c_call[DS] +caml_c_call: + .long .caml_c_call, TOC[tc0], 0 diff --git a/testasmcomp/power-elf.S b/testasmcomp/power-elf.S new file mode 100644 index 0000000..797a91e --- /dev/null +++ b/testasmcomp/power-elf.S @@ -0,0 +1,131 @@ +/*********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/*********************************************************************/ + +/* $Id: power-elf.S,v 1.3 1999-11-17 18:58:43 xleroy Exp $ */ + +/* Save and restore all callee-save registers */ +/* GPR 14 at sp+16 ... GPR 31 at sp+84 + FPR 14 at sp+92 ... FPR 31 at sp+228 */ + +#define Save_callee_save \ + addic 11, 1, 16-4; \ + stwu 14, 4(11); \ + stwu 15, 4(11); \ + stwu 16, 4(11); \ + stwu 17, 4(11); \ + stwu 18, 4(11); \ + stwu 19, 4(11); \ + stwu 20, 4(11); \ + stwu 21, 4(11); \ + stwu 22, 4(11); \ + stwu 23, 4(11); \ + stwu 24, 4(11); \ + stwu 25, 4(11); \ + stwu 26, 4(11); \ + stwu 27, 4(11); \ + stwu 28, 4(11); \ + stwu 29, 4(11); \ + stwu 30, 4(11); \ + stwu 31, 4(11); \ + stfdu 14, 8(11); \ + stfdu 15, 8(11); \ + stfdu 16, 8(11); \ + stfdu 17, 8(11); \ + stfdu 18, 8(11); \ + stfdu 19, 8(11); \ + stfdu 20, 8(11); \ + stfdu 21, 8(11); \ + stfdu 22, 8(11); \ + stfdu 23, 8(11); \ + stfdu 24, 8(11); \ + stfdu 25, 8(11); \ + stfdu 26, 8(11); \ + stfdu 27, 8(11); \ + stfdu 28, 8(11); \ + stfdu 29, 8(11); \ + stfdu 30, 8(11); \ + stfdu 31, 8(11) + +#define Restore_callee_save \ + addic 11, 1, 16-4; \ + lwzu 14, 4(11); \ + lwzu 15, 4(11); \ + lwzu 16, 4(11); \ + lwzu 17, 4(11); \ + lwzu 18, 4(11); \ + lwzu 19, 4(11); \ + lwzu 20, 4(11); \ + lwzu 21, 4(11); \ + lwzu 22, 4(11); \ + lwzu 23, 4(11); \ + lwzu 24, 4(11); \ + lwzu 25, 4(11); \ + lwzu 26, 4(11); \ + lwzu 27, 4(11); \ + lwzu 28, 4(11); \ + lwzu 29, 4(11); \ + lwzu 30, 4(11); \ + lwzu 31, 4(11); \ + lfdu 14, 8(11); \ + lfdu 15, 8(11); \ + lfdu 16, 8(11); \ + lfdu 17, 8(11); \ + lfdu 18, 8(11); \ + lfdu 19, 8(11); \ + lfdu 20, 8(11); \ + lfdu 21, 8(11); \ + lfdu 22, 8(11); \ + lfdu 23, 8(11); \ + lfdu 24, 8(11); \ + lfdu 25, 8(11); \ + lfdu 26, 8(11); \ + lfdu 27, 8(11); \ + lfdu 28, 8(11); \ + lfdu 29, 8(11); \ + lfdu 30, 8(11); \ + lfdu 31, 8(11) + + .section ".text" + + .globl call_gen_code + .type call_gen_code, @function +call_gen_code: + /* Allocate and link stack frame */ + stwu 1, -256(1) + /* Save return address */ + mflr 0 + stw 0, 256+4(1) + /* Save all callee-save registers */ + Save_callee_save + /* Shuffle arguments */ + mtlr 3 + mr 3, 4 + mr 4, 5 + mr 5, 6 + mr 6, 7 + /* Call the function */ + blrl + /* Restore callee-save registers */ + Restore_callee_save + /* Reload return address */ + lwz 0, 256+4(1) + mtlr 0 + /* Return */ + addi 1, 1, 256 + blr + + .globl caml_c_call + .type caml_c_call, @function +caml_c_call: + /* Jump to C function (address in 11) */ + mtctr 11 + bctr diff --git a/testasmcomp/power-rhapsody.S b/testasmcomp/power-rhapsody.S new file mode 100644 index 0000000..c4541e8 --- /dev/null +++ b/testasmcomp/power-rhapsody.S @@ -0,0 +1,129 @@ +/*********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/*********************************************************************/ + +/* $Id: power-rhapsody.S,v 1.3 1999-11-17 18:58:44 xleroy Exp $ */ + +/* Save and restore all callee-save registers */ +/* GPR 14 at sp+16 ... GPR 31 at sp+84 + FPR 14 at sp+92 ... FPR 31 at sp+228 */ + +#define Save_callee_save \ + addic r11, r1, 16-4; \ + stwu r14, 4(r11); \ + stwu r15, 4(r11); \ + stwu r16, 4(r11); \ + stwu r17, 4(r11); \ + stwu r18, 4(r11); \ + stwu r19, 4(r11); \ + stwu r20, 4(r11); \ + stwu r21, 4(r11); \ + stwu r22, 4(r11); \ + stwu r23, 4(r11); \ + stwu r24, 4(r11); \ + stwu r25, 4(r11); \ + stwu r26, 4(r11); \ + stwu r27, 4(r11); \ + stwu r28, 4(r11); \ + stwu r29, 4(r11); \ + stwu r30, 4(r11); \ + stwu r31, 4(r11); \ + stfdu f14, 8(r11); \ + stfdu f15, 8(r11); \ + stfdu f16, 8(r11); \ + stfdu f17, 8(r11); \ + stfdu f18, 8(r11); \ + stfdu f19, 8(r11); \ + stfdu f20, 8(r11); \ + stfdu f21, 8(r11); \ + stfdu f22, 8(r11); \ + stfdu f23, 8(r11); \ + stfdu f24, 8(r11); \ + stfdu f25, 8(r11); \ + stfdu f26, 8(r11); \ + stfdu f27, 8(r11); \ + stfdu f28, 8(r11); \ + stfdu f29, 8(r11); \ + stfdu f30, 8(r11); \ + stfdu f31, 8(r11) + +#define Restore_callee_save \ + addic r11, r1, 16-4; \ + lwzu r14, 4(r11); \ + lwzu r15, 4(r11); \ + lwzu r16, 4(r11); \ + lwzu r17, 4(r11); \ + lwzu r18, 4(r11); \ + lwzu r19, 4(r11); \ + lwzu r20, 4(r11); \ + lwzu r21, 4(r11); \ + lwzu r22, 4(r11); \ + lwzu r23, 4(r11); \ + lwzu r24, 4(r11); \ + lwzu r25, 4(r11); \ + lwzu r26, 4(r11); \ + lwzu r27, 4(r11); \ + lwzu r28, 4(r11); \ + lwzu r29, 4(r11); \ + lwzu r30, 4(r11); \ + lwzu r31, 4(r11); \ + lfdu f14, 8(r11); \ + lfdu f15, 8(r11); \ + lfdu f16, 8(r11); \ + lfdu f17, 8(r11); \ + lfdu f18, 8(r11); \ + lfdu f19, 8(r11); \ + lfdu f20, 8(r11); \ + lfdu f21, 8(r11); \ + lfdu f22, 8(r11); \ + lfdu f23, 8(r11); \ + lfdu f24, 8(r11); \ + lfdu f25, 8(r11); \ + lfdu f26, 8(r11); \ + lfdu f27, 8(r11); \ + lfdu f28, 8(r11); \ + lfdu f29, 8(r11); \ + lfdu f30, 8(r11); \ + lfdu f31, 8(r11) + + .text + + .globl _call_gen_code +_call_gen_code: + /* Allocate and link stack frame */ + stwu r1, -256(r1) + /* Save return address */ + mflr r0 + stw r0, 256+4(r1) + /* Save all callee-save registers */ + Save_callee_save + /* Shuffle arguments */ + mtlr r3 + mr r3, r4 + mr r4, r5 + mr r5, r6 + mr r6, r7 + /* Call the function */ + blrl + /* Restore callee-save registers */ + Restore_callee_save + /* Reload return address */ + lwz r0, 256+4(r1) + mtlr r0 + /* Return */ + addi r1, r1, 256 + blr + + .globl _caml_c_call +_caml_c_call: + /* Jump to C function (address in 11) */ + mtctr r11 + bctr diff --git a/testasmcomp/quicksort.cmm b/testasmcomp/quicksort.cmm new file mode 100644 index 0000000..7489bca --- /dev/null +++ b/testasmcomp/quicksort.cmm @@ -0,0 +1,43 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: quicksort.cmm,v 1.6 2000-06-25 19:54:50 xleroy Exp $ *) + +(function "quicksort" (lo: int hi: int a: addr) + (if (< lo hi) + (let (i lo + j hi + pivot (addraref a hi)) + (while (< i j) + (catch + (while 1 + (if (>= i hi) exit []) + (if (> (addraref a i) pivot) exit []) + (assign i (+ i 1))) + with []) + (catch + (while 1 + (if (<= j lo) exit []) + (if (< (addraref a j) pivot) exit []) + (assign j (- j 1))) + with []) + (if (< i j) + (let temp (addraref a i) + (addraset a i (addraref a j)) + (addraset a j temp)) + [])) + (let temp (addraref a i) + (addraset a i (addraref a hi)) + (addraset a hi temp)) + (app "quicksort" lo (- i 1) a unit) + (app "quicksort" (+ i 1) hi a unit)) + [])) diff --git a/testasmcomp/quicksort2.cmm b/testasmcomp/quicksort2.cmm new file mode 100644 index 0000000..7a7aa45 --- /dev/null +++ b/testasmcomp/quicksort2.cmm @@ -0,0 +1,49 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: quicksort2.cmm,v 1.8 2000-06-29 11:45:23 xleroy Exp $ *) + +(function "cmp" (i: int j: int) + (- i j)) + +(function "quick" (lo: int hi: int a: addr cmp: addr) + (if (< lo hi) + (let (i lo + j hi + pivot (intaref a hi)) + (while (< i j) + (catch + (while 1 + (if (>= i hi) exit []) + (if (> (app cmp (intaref a i) pivot int) 0) exit []) + (assign i (+ i 1))) + with []) + (catch + (while 1 + (if (<= j lo) exit []) + (if (< (app cmp (intaref a j) pivot int) 0) exit []) + (assign j (- j 1))) + with []) + (if (< i j) + (let temp (intaref a i) + (intaset a i (intaref a j)) + (intaset a j temp)) + [])) + (let temp (intaref a i) + (intaset a i (intaref a hi)) + (intaset a hi temp)) + (app "quick" lo (- i 1) a cmp unit) + (app "quick" (+ i 1) hi a cmp unit)) + [])) + +(function "quicksort" (lo: int hi: int a: addr) + (app "quick" lo hi a "cmp" unit)) diff --git a/testasmcomp/soli.cmm b/testasmcomp/soli.cmm new file mode 100644 index 0000000..295fb8e --- /dev/null +++ b/testasmcomp/soli.cmm @@ -0,0 +1,109 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: soli.cmm,v 1.7 2003-06-30 08:28:48 xleroy Exp $ *) + +("d1": int 0 int 1 + "d2": int 1 int 0 + "d3": int 0 int -1 + "d4": int -1 int 0 + "dir": addr "d1" addr "d2" addr "d3" addr "d4") + +("counter": int 0) + +(* Out = 0 Empty = 1 Peg = 2 *) + +("line0": int 0 int 0 int 0 int 0 int 0 int 0 int 0 int 0 int 0 + "line1": int 0 int 0 int 0 int 2 int 2 int 2 int 0 int 0 int 0 + "line2": int 0 int 0 int 0 int 2 int 2 int 2 int 0 int 0 int 0 + "line3": int 0 int 2 int 2 int 2 int 2 int 2 int 2 int 2 int 0 + "line4": int 0 int 2 int 2 int 2 int 1 int 2 int 2 int 2 int 0 + "line5": int 0 int 2 int 2 int 2 int 2 int 2 int 2 int 2 int 0 + "line6": int 0 int 0 int 0 int 2 int 2 int 2 int 0 int 0 int 0 + "line7": int 0 int 0 int 0 int 2 int 2 int 2 int 0 int 0 int 0 + "line8": int 0 int 0 int 0 int 0 int 0 int 0 int 0 int 0 int 0 + "board": addr "line0" addr "line1" addr "line2" addr "line3" + addr "line4" addr "line5" addr "line6" addr "line7" addr "line8") + +("format": string "%d\n\000") + +(function "solve" (m: int) + (store int "counter" (+ (load int "counter") 1)) + (if (== m 31) + (== (intaref (addraref "board" 4) 4) 2) + (try + (if (== (mod (load int "counter") 500) 0) + (extcall "printf_int" "format" (load int "counter") unit) + []) + (let i 1 + (while (<= i 7) + (let j 1 + (while (<= j 7) + (if (== (intaref (addraref "board" i) j) 2) + (seq + (let k 0 + (while (<= k 3) + (let (d1 (intaref (addraref "dir" k) 0) + d2 (intaref (addraref "dir" k) 1) + i1 (+ i d1) + i2 (+ i1 d1) + j1 (+ j d2) + j2 (+ j1 d2)) + (if (== (intaref (addraref "board" i1) j1) 2) + (if (== (intaref (addraref "board" i2) j2) 1) + (seq + (intaset (addraref "board" i) j 1) + (intaset (addraref "board" i1) j1 1) + (intaset (addraref "board" i2) j2 2) + (if (app "solve" (+ m 1) int) + (raise 0a) + []) + (intaset (addraref "board" i) j 2) + (intaset (addraref "board" i1) j1 2) + (intaset (addraref "board" i2) j2 1)) + []) + [])) + (assign k (+ k 1))))) + []) + (assign j (+ j 1)))) + (assign i (+ i 1)))) + 0 + with bucket + 1))) + +("format_out": string ".\000") +("format_empty": string " \000") +("format_peg": string "$\000") +("format_newline": string "\n\000") + +(function "print_board" () + (let i 0 + (while (< i 9) + (let j 0 + (while (< j 9) + (switch 3 (intaref (addraref "board" i) j) + case 0: + (extcall "print_string" "format_out" unit) + case 1: + (extcall "print_string" "format_empty" unit) + case 2: + (extcall "print_string" "format_peg" unit)) + (assign j (+ j 1)))) + (extcall "print_string" "format_newline" unit) + (assign i (+ i 1))))) + +(function "solitaire" () + (seq + (if (app "solve" 0 int) + (app "print_board" [] unit) + []) + 0)) diff --git a/testasmcomp/sparc.S b/testasmcomp/sparc.S new file mode 100644 index 0000000..7623177 --- /dev/null +++ b/testasmcomp/sparc.S @@ -0,0 +1,41 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* $Id: sparc.S,v 1.2 1999-11-17 18:58:44 xleroy Exp $ */ + +#ifndef SYS_solaris +#define Call_gen_code _call_gen_code +#define Caml_c_call _caml_c_call +#else +#define Call_gen_code call_gen_code +#define Caml_c_call caml_c_call +#endif + + .global Call_gen_code +Call_gen_code: + save %sp, -96, %sp + mov %i0, %l0 + mov %i1, %i0 + mov %i2, %i1 + mov %i3, %i2 + mov %i4, %i3 + mov %i5, %i4 + call %l0 + nop + mov %o0, %i0 + ret + restore + + .global Caml_c_call +Caml_c_call: + jmp %g4 + nop diff --git a/testasmcomp/tagged-fib.cmm b/testasmcomp/tagged-fib.cmm new file mode 100644 index 0000000..7abef34 --- /dev/null +++ b/testasmcomp/tagged-fib.cmm @@ -0,0 +1,19 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tagged-fib.cmm,v 1.4 1999-11-17 18:58:44 xleroy Exp $ *) + +(function "fib" (n: int) + (if (< n 5) + 3 + (- (+ (app "fib" (- n 2) int) (app "fib" (- n 4) int)) 1))) + diff --git a/testasmcomp/tagged-integr.cmm b/testasmcomp/tagged-integr.cmm new file mode 100644 index 0000000..82844e8 --- /dev/null +++ b/testasmcomp/tagged-integr.cmm @@ -0,0 +1,45 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tagged-integr.cmm,v 1.5 2000-07-07 14:09:23 xleroy Exp $ *) + +("res_square": skip 8) +("h": skip 8) +("x": skip 8) +("s": skip 8) +("res_integr": skip 8) + +(function "square" (x: addr) + (let r "res_square" + (store float r ( *f (load float x) (load float x))) + r)) + +(function "integr" (f: addr low: addr high: addr n: int) + (let (h "h" x "x" s "s" i n) + (store float h (/f (-f (load float high) (load float low)) (floatofint n))) + (store float x (load float low)) + (store float s 0.0) + (while (> i 0) + (store float s (+f (load float s) (load float (app f x addr)))) + (store float x (+f (load float x) (load float h))) + (assign i (- i 1))) + (store float "res_integr" ( *f (load float s) (load float h))) + "res_integr")) + +("low": skip 8) +("hi": skip 8) + +(function "test" (n: int) + (store float "low" 0.0) + (store float "hi" 1.0) + (load float (app "integr" "square" "low" "hi" n addr))) + diff --git a/testasmcomp/tagged-quicksort.cmm b/testasmcomp/tagged-quicksort.cmm new file mode 100644 index 0000000..c413cd1 --- /dev/null +++ b/testasmcomp/tagged-quicksort.cmm @@ -0,0 +1,46 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tagged-quicksort.cmm,v 1.5 2000-06-29 11:45:24 xleroy Exp $ *) + +(function "quick" (lo: int hi: int a: addr) + (if (< lo hi) + (let (i lo + j hi + pivot (addraref a (>>s hi 1))) + (while (< i j) + (catch + (while 1 + (if (>= i hi) exit []) + (if (> (addraref a (>>s i 1)) pivot) exit []) + (assign i (+ i 2))) + with []) + (catch + (while 1 + (if (<= j lo) exit []) + (if (< (addraref a (>>s j 1)) pivot) exit []) + (assign j (- j 2))) + with []) + (if (< i j) + (let temp (addraref a (>>s i 1)) + (addraset a (>>s i 1) (addraref a (>>s j 1))) + (addraset a (>>s j 1) temp)) + [])) + (let temp (addraref a (>>s i 1)) + (addraset a (>>s i 1) (addraref a (>>s hi 1))) + (addraset a (>>s hi 1) temp)) + (app "quick" lo (- i 2) a unit) + (app "quick" (+ i 2) hi a unit)) + [])) + +(function "quicksort" (lo: int hi: int a: addr) + (app "quick" (+ (<< lo 1) 1) (+ (<< hi 1) 1) a unit)) diff --git a/testasmcomp/tagged-tak.cmm b/testasmcomp/tagged-tak.cmm new file mode 100644 index 0000000..f27e8e5 --- /dev/null +++ b/testasmcomp/tagged-tak.cmm @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tagged-tak.cmm,v 1.6 2000-07-07 14:09:23 xleroy Exp $ *) + +(function "tak" (x:int y:int z:int) + (if (> x y) + (app "tak" (app "tak" (- x 2) y z int) + (app "tak" (- y 2) z x int) + (app "tak" (- z 2) x y int) int) + z)) + +(function "takmain" (dummy: int) + (app "tak" 37 25 13 int)) diff --git a/testasmcomp/tak.cmm b/testasmcomp/tak.cmm new file mode 100644 index 0000000..9f83a96 --- /dev/null +++ b/testasmcomp/tak.cmm @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tak.cmm,v 1.5 2000-06-25 19:54:50 xleroy Exp $ *) + +(function "tak" (x:int y:int z:int) + (if (> x y) + (app "tak" (app "tak" (- x 1) y z int) + (app "tak" (- y 1) z x int) + (app "tak" (- z 1) x y int) int) + z)) + +(function "takmain" (dummy: int) + (app "tak" 18 12 6 int)) diff --git a/testlabl/.cvsignore b/testlabl/.cvsignore new file mode 100644 index 0000000..4c57147 --- /dev/null +++ b/testlabl/.cvsignore @@ -0,0 +1 @@ +*.out *.out2 \ No newline at end of file diff --git a/testlabl/Makefile b/testlabl/Makefile new file mode 100644 index 0000000..a1e9c0f --- /dev/null +++ b/testlabl/Makefile @@ -0,0 +1,17 @@ +# $Id: Makefile,v 1.3 2002-06-18 10:47:22 garrigue Exp $ +# Test extensions + +CAMLTOP=../boot/ocamlrun ../ocaml -I ../stdlib + +test: test-poly + +test-poly: + TERM=norepeat $(CAMLTOP) < poly.ml > poly.out 2>&1 + TERM=norepeat $(CAMLTOP) -principal < poly.ml > poly.out2 2>&1 + @diff poly.exp poly.out && echo ocaml OK || echo ocaml changed + @diff poly.exp2 poly.out2 && echo ocaml -principal OK \ + || echo ocaml -principal changed + +promote: + mv poly.out poly.exp + mv poly.out2 poly.exp2 diff --git a/testlabl/bugs/pr3918a.mli b/testlabl/bugs/pr3918a.mli new file mode 100644 index 0000000..b0afbbe --- /dev/null +++ b/testlabl/bugs/pr3918a.mli @@ -0,0 +1 @@ +type 'a voption = [ `None | `Some of 'a] diff --git a/testlabl/bugs/pr3918b.mli b/testlabl/bugs/pr3918b.mli new file mode 100644 index 0000000..3513ff9 --- /dev/null +++ b/testlabl/bugs/pr3918b.mli @@ -0,0 +1 @@ +type 'a vlist = ('a * 'b) Pr3918a.voption as 'b diff --git a/testlabl/bugs/pr3918c.ml b/testlabl/bugs/pr3918c.ml new file mode 100644 index 0000000..c49ed6e --- /dev/null +++ b/testlabl/bugs/pr3918c.ml @@ -0,0 +1,10 @@ +(* + ocamlc -c pr3918a.mli pr3918b.mli + rm -f pr3918a.cmi + ocamlc -c pr3918c.ml +*) + +open Pr3918b + +let f x = (x : 'a vlist :> 'b vlist) +let f (x : 'a vlist) = (x : 'b vlist) diff --git a/testlabl/bugs/pr3968.ml b/testlabl/bugs/pr3968.ml new file mode 100644 index 0000000..3d39312 --- /dev/null +++ b/testlabl/bugs/pr3968.ml @@ -0,0 +1,21 @@ +type expr = + [ `Abs of string * expr + | `App of expr * expr + ] + +class type exp = +object + method eval : (string, exp) Hashtbl.t -> expr +end;; + +class app e1 e2 : exp = +object + val l = e1 + val r = e2 + method eval env = + match l with + | `Abs(var,body) -> + Hashtbl.add env var r; + body + | _ -> `App(l,r); +end diff --git a/testlabl/bugs/pr4018.ml b/testlabl/bugs/pr4018.ml new file mode 100644 index 0000000..90ee787 --- /dev/null +++ b/testlabl/bugs/pr4018.ml @@ -0,0 +1,46 @@ + +class virtual ['subject, 'event] observer = + object + method virtual notify : 'subject -> 'event -> unit + end + +class ['event] subject = + object (self : 'subject) + val mutable observers = ([]: (('subject, 'event) observer) list) + method add_observer obs = observers <- (obs :: observers) + method notify_observers (e : 'event) = + List.iter (fun x -> x#notify self e) observers + end + +type id = int + +class entity (id : id) = + object + val ent_destroy_subject = new subject + method destroy_subject : (id) subject = ent_destroy_subject + + method entity_id = id + end + +class ['entity] entity_container = + object (self) + inherit ['entity, id] observer as observer + + method add_entity (e : 'entity) = + e#destroy_subject#add_observer (self) + + method notify _ id = () + end + +let f (x : entity entity_container) = () + +(* +class world = + object + val entity_container : entity entity_container = new entity_container + + method add_entity (s : entity) = + entity_container#add_entity (s :> entity) + + end +*) diff --git a/testlabl/bugs/pr4435.ml b/testlabl/bugs/pr4435.ml new file mode 100644 index 0000000..c9e1d49 --- /dev/null +++ b/testlabl/bugs/pr4435.ml @@ -0,0 +1,11 @@ +(* Two v's in the same class *) +class c v = object initializer print_endline v val v = 42 end;; +new c "42";; + +(* Two hidden v's in the same class! *) +class c (v : int) = + object + method v0 = v + inherit ((fun v -> object method v : string = v end) "42") + end;; +(new c 42)#v0;; diff --git a/testlabl/bugs/privrows-abate.ml b/testlabl/bugs/privrows-abate.ml new file mode 100644 index 0000000..4e31243 --- /dev/null +++ b/testlabl/bugs/privrows-abate.ml @@ -0,0 +1,53 @@ +type 'a termpc = + [`And of 'a * 'a + |`Or of 'a * 'a + |`Not of 'a + |`Atom of string + ] + +type 'a termk = + [`Dia of 'a + |`Box of 'a + |'a termpc + ] + +module type T = sig + type term + val map : (term -> term) -> term -> term + val nnf : term -> term + val nnf_not : term -> term +end + +module Fpc(X : T with type term = private [> 'a termpc] as 'a) = + struct + type term = X.term termpc + let nnf = function + |`Not(`Atom _) as x -> x + |`Not x -> X.nnf_not x + | x -> X.map X.nnf x + let map f : term -> X.term = function + |`Not x -> `Not (f x) + |`And(x,y) -> `And (f x, f y) + |`Or (x,y) -> `Or (f x, f y) + |`Atom _ as x -> x + let nnf_not : term -> _ = function + |`Not x -> X.nnf x + |`And(x,y) -> `Or (X.nnf_not x, X.nnf_not y) + |`Or (x,y) -> `And (X.nnf_not x, X.nnf_not y) + |`Atom _ as x -> `Not x + end + +module Fk(X : T with type term = private [> 'a termk] as 'a) = + struct + type term = X.term termk + module Pc = Fpc(X) + let map f : term -> _ = function + |`Dia x -> `Dia (f x) + |`Box x -> `Box (f x) + |#termpc as x -> Pc.map f x + let nnf = Pc.nnf + let nnf_not : term -> _ = function + |`Dia x -> `Box (X.nnf_not x) + |`Box x -> `Dia (X.nnf_not x) + |#termpc as x -> Pc.nnf_not x + end diff --git a/testlabl/bugs/woodyatt.ml b/testlabl/bugs/woodyatt.ml new file mode 100644 index 0000000..627158b --- /dev/null +++ b/testlabl/bugs/woodyatt.ml @@ -0,0 +1,14 @@ +(* test.ml *) +class alfa = object(_:'self) + method x: 'a. ('a, out_channel, unit) format -> 'a = Printf.printf +end + +class bravo a = object + val y = (a :> alfa) + initializer y#x "bravo initialized" +end + +class charlie a = object + inherit bravo a + initializer y#x "charlie initialized" +end diff --git a/testlabl/bugs/yamagata021012.ml b/testlabl/bugs/yamagata021012.ml new file mode 100644 index 0000000..212a168 --- /dev/null +++ b/testlabl/bugs/yamagata021012.ml @@ -0,0 +1,193 @@ +(* The module begins *) +exception Out_of_range + +class type ['a] cursor = + object + method get : 'a + method incr : unit -> unit + method is_last : bool + end + +class type ['a] storage = + object ('self) + method first : 'a cursor + method len : int + method nth : int -> 'a cursor + method copy : 'self + method sub : int -> int -> 'self + method concat : 'a storage -> 'self + method fold : 'b. ('a -> int -> 'b -> 'b) -> 'b -> 'b + method iter : ('a -> unit) -> unit + end + +class virtual ['a, 'cursor] storage_base = + object (self : 'self) + constraint 'cursor = 'a #cursor + method virtual first : 'cursor + method virtual len : int + method virtual copy : 'self + method virtual sub : int -> int -> 'self + method virtual concat : 'a storage -> 'self + method fold : 'b. ('a -> int -> 'b -> 'b) -> 'b -> 'b = fun f a0 -> + let cur = self#first in + let rec loop count a = + if count >= self#len then a else + let a' = f cur#get count a in + cur#incr (); loop (count + 1) a' + in + loop 0 a0 + method iter proc = + let p = self#first in + for i = 0 to self#len - 2 do proc p#get; p#incr () done; + if self#len > 0 then proc p#get else () + end + +class type ['a] obj_input_channel = + object + method get : unit -> 'a + method close : unit -> unit + end + +class type ['a] obj_output_channel = + object + method put : 'a -> unit + method flush : unit -> unit + method close : unit -> unit + end + +module UChar = +struct + + type t = int + + let highest_bit = 1 lsl 30 + let lower_bits = highest_bit - 1 + + let char_of c = + try Char.chr c with Invalid_argument _ -> raise Out_of_range + + let of_char = Char.code + + let code c = + if c lsr 30 = 0 + then c + else raise Out_of_range + + let chr n = + if n >= 0 && (n lsr 31 = 0) then n else raise Out_of_range + + let uint_code c = c + let chr_of_uint n = n + +end + +type uchar = UChar.t + +let int_of_uchar u = UChar.uint_code u +let uchar_of_int n = UChar.chr_of_uint n + +class type ucursor = [uchar] cursor + +class type ustorage = [uchar] storage + +class virtual ['ucursor] ustorage_base = [uchar, 'ucursor] storage_base + +module UText = +struct + +(* the internal representation is UCS4 with big endian*) +(* The most significant digit appears first. *) +let get_buf s i = + let n = Char.code s.[i] in + let n = (n lsl 8) lor (Char.code s.[i + 1]) in + let n = (n lsl 8) lor (Char.code s.[i + 2]) in + let n = (n lsl 8) lor (Char.code s.[i + 3]) in + UChar.chr_of_uint n + +let set_buf s i u = + let n = UChar.uint_code u in + begin + s.[i] <- Char.chr (n lsr 24); + s.[i + 1] <- Char.chr (n lsr 16 lor 0xff); + s.[i + 2] <- Char.chr (n lsr 8 lor 0xff); + s.[i + 3] <- Char.chr (n lor 0xff); + end + +let init_buf buf pos init = + if init#len = 0 then () else + let cur = init#first in + for i = 0 to init#len - 2 do + set_buf buf (pos + i lsl 2) (cur#get); cur#incr () + done; + set_buf buf (pos + (init#len - 1) lsl 2) (cur#get) + +let make_buf init = + let s = String.create (init#len lsl 2) in + init_buf s 0 init; s + +class text_raw buf = + object (self : 'self) + inherit [cursor] ustorage_base + val contents = buf + method first = new cursor (self :> text_raw) 0 + method len = (String.length contents) / 4 + method get i = get_buf contents (4 * i) + method nth i = new cursor (self :> text_raw) i + method copy = {< contents = String.copy contents >} + method sub pos len = + {< contents = String.sub contents (pos * 4) (len * 4) >} + method concat (text : ustorage) = + let buf = String.create (String.length contents + 4 * text#len) in + String.blit contents 0 buf 0 (String.length contents); + init_buf buf (String.length contents) text; + {< contents = buf >} + end +and cursor text i = + object + val contents = text + val mutable pos = i + method get = contents#get pos + method incr () = pos <- pos + 1 + method is_last = (pos + 1 >= contents#len) + end + +class string_raw buf = + object + inherit text_raw buf + method set i u = set_buf contents (4 * i) u + end + +class text init = text_raw (make_buf init) +class string init = string_raw (make_buf init) + +let of_string s = + let buf = String.make (4 * String.length s) '\000' in + for i = 0 to String.length s - 1 do + buf.[4 * i] <- s.[i] + done; + new text_raw buf + +let make len u = + let s = String.create (4 * len) in + for i = 0 to len - 1 do set_buf s (4 * i) u done; + new string_raw s + +let create len = make len (UChar.chr 0) + +let copy s = s#copy + +let sub s start len = s#sub start len + +let fill s start len u = + for i = start to start + len - 1 do s#set i u done + +let blit src srcoff dst dstoff len = + for i = 0 to len - 1 do + let u = src#get (srcoff + i) in + dst#set (dstoff + i) u + done + +let concat s1 s2 = s1#concat (s2 (* : #ustorage *) :> uchar storage) + +let iter proc s = s#iter proc +end diff --git a/testlabl/coerce.diffs b/testlabl/coerce.diffs new file mode 100644 index 0000000..e90e1fc --- /dev/null +++ b/testlabl/coerce.diffs @@ -0,0 +1,93 @@ +Index: typing/ctype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.ml,v +retrieving revision 1.201 +diff -u -r1.201 ctype.ml +--- typing/ctype.ml 5 Apr 2006 02:28:13 -0000 1.201 ++++ typing/ctype.ml 17 May 2006 23:48:22 -0000 +@@ -490,6 +490,31 @@ + unmark_class_signature sign; + Some reason + ++(* Variant for checking principality *) ++ ++let rec free_nodes_rec ty = ++ let ty = repr ty in ++ if ty.level >= lowest_level then begin ++ if ty.level <= !current_level then raise Exit; ++ ty.level <- pivot_level - ty.level; ++ begin match ty.desc with ++ Tvar -> ++ raise Exit ++ | Tobject (ty, _) -> ++ free_nodes_rec ty ++ | Tfield (_, _, ty1, ty2) -> ++ free_nodes_rec ty1; free_nodes_rec ty2 ++ | Tvariant row -> ++ let row = row_repr row in ++ iter_row free_nodes_rec {row with row_bound = []}; ++ if not (static_row row) then free_nodes_rec row.row_more ++ | _ -> ++ iter_type_expr free_nodes_rec ty ++ end; ++ end ++ ++let has_free_nodes ty = ++ try free_nodes_rec ty; false with Exit -> true + + (**********************) + (* Type duplication *) +Index: typing/ctype.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.mli,v +retrieving revision 1.54 +diff -u -r1.54 ctype.mli +--- typing/ctype.mli 5 Apr 2006 02:28:13 -0000 1.54 ++++ typing/ctype.mli 17 May 2006 23:48:22 -0000 +@@ -228,6 +228,9 @@ + val closed_class: + type_expr list -> class_signature -> closed_class_failure option + (* Check whether all type variables are bound *) ++val has_free_nodes: type_expr -> bool ++ (* Check whether there are free type variables, or nodes with ++ level lower or equal to !current_level *) + + val unalias: type_expr -> type_expr + val signature_of_class_type: class_type -> class_signature +Index: typing/typecore.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typecore.ml,v +retrieving revision 1.181 +diff -u -r1.181 typecore.ml +--- typing/typecore.ml 16 Apr 2006 23:28:22 -0000 1.181 ++++ typing/typecore.ml 17 May 2006 23:48:22 -0000 +@@ -1183,12 +1183,29 @@ + let (ty', force) = + Typetexp.transl_simple_type_delayed env sty' + in ++ if !Clflags.principal then begin_def (); + let arg = type_exp env sarg in ++ let has_fv = ++ if !Clflags.principal then begin ++ end_def (); ++ let b = has_free_nodes arg.exp_type in ++ Ctype.unify env arg.exp_type (newvar ()); ++ b ++ end else ++ free_variables arg.exp_type <> [] ++ in + begin match arg.exp_desc, !self_coercion, (repr ty').desc with + Texp_ident(_, {val_kind=Val_self _}), (path,r) :: _, + Tconstr(path',_,_) when Path.same path path' -> + r := sexp.pexp_loc :: !r; + force () ++ | _ when not has_fv -> ++ begin try ++ let force' = subtype env arg.exp_type ty' in ++ force (); force' () ++ with Subtype (tr1, tr2) -> ++ raise(Error(sexp.pexp_loc, Not_subtype(tr1, tr2))) ++ end + | _ -> + let ty, b = enlarge_type env ty' in + force (); diff --git a/testlabl/dirs_multimatch b/testlabl/dirs_multimatch new file mode 100644 index 0000000..b449514 --- /dev/null +++ b/testlabl/dirs_multimatch @@ -0,0 +1 @@ +parsing typing bytecomp driver toplevel \ No newline at end of file diff --git a/testlabl/dirs_poly b/testlabl/dirs_poly new file mode 100644 index 0000000..3aec606 --- /dev/null +++ b/testlabl/dirs_poly @@ -0,0 +1 @@ +bytecomp byterun driver parsing stdlib tools toplevel typing utils otherlibs/labltk/browser/searchpos.ml diff --git a/testlabl/fixedtypes.ml b/testlabl/fixedtypes.ml new file mode 100644 index 0000000..a7d7ca4 --- /dev/null +++ b/testlabl/fixedtypes.ml @@ -0,0 +1,77 @@ +(* cvs update -r fixedtypes parsing typing *) + +(* recursive types *) +class c = object (self) method m = 1 method s = self end +module type S = sig type t = private #c end;; + +module M : S = struct type t = c end +module type S' = S with type t = c;; + +class d = object inherit c method n = 2 end +module type S2 = S with type t = private #d;; +module M2 : S = struct type t = d end;; +module M3 : S = struct type t = private #d end;; + +module T1 = struct + type ('a,'b) a = [`A of 'a | `B of 'b] + type ('a,'b) b = [`Z | ('a,'b) a] +end +module type T2 = sig + type a and b + val evala : a -> int + val evalb : b -> int +end +module type T3 = sig + type a0 = private [> (a0,b0) T1.a] + and b0 = private [> (a0,b0) T1.b] +end +module type T4 = sig + include T3 + include T2 with type a = a0 and type b = b0 +end +module F(X:T4) = struct + type a = X.a and b = X.b + let a = X.evala (`B `Z) + let b = X.evalb (`A(`B `Z)) + let a2b (x : a) : b = `A x + let b2a (x : b) : a = `B x +end +module M4 = struct + type a = [`A of a | `B of b | `ZA] + and b = [`A of a | `B of b | `Z] + type a0 = a + type b0 = b + let rec eval0 = function + `A a -> evala a + | `B b -> evalb b + and evala : a -> int = function + #T1.a as x -> 1 + eval0 x + | `ZA -> 3 + and evalb : b -> int = function + #T1.a as x -> 1 + eval0 x + | `Z -> 7 +end +module M5 = F(M4) + +module M6 : sig + class ci : int -> + object + val x : int + method x : int + method move : int -> unit + end + type c = private #ci + val create : int -> c +end = struct + class ci x = object + val mutable x : int = x + method x = x + method move d = x <- x+d + end + type c = ci + let create = new ci +end +let f (x : M6.c) = x#move 3; x#x;; + +module M : sig type t = private [> `A of bool] end = + struct type t = [`A of int] end diff --git a/testlabl/marshal_objects.diffs b/testlabl/marshal_objects.diffs new file mode 100644 index 0000000..bb9b4dd --- /dev/null +++ b/testlabl/marshal_objects.diffs @@ -0,0 +1,800 @@ +? bytecomp/alpha_eq.ml +Index: bytecomp/lambda.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/lambda.ml,v +retrieving revision 1.44 +diff -u -r1.44 lambda.ml +--- bytecomp/lambda.ml 25 Aug 2005 15:35:16 -0000 1.44 ++++ bytecomp/lambda.ml 2 Feb 2006 05:08:56 -0000 +@@ -287,9 +287,10 @@ + let compare = compare + end) + +-let free_ids get l = ++let free_ids get used l = + let fv = ref IdentSet.empty in + let rec free l = ++ let old = !fv in + iter free l; + fv := List.fold_right IdentSet.add (get l) !fv; + match l with +@@ -307,17 +308,20 @@ + fv := IdentSet.remove v !fv + | Lassign(id, e) -> + fv := IdentSet.add id !fv ++ | Lifused(id, e) -> ++ if used && not (IdentSet.mem id old) then fv := IdentSet.remove id !fv + | Lvar _ | Lconst _ | Lapply _ + | Lprim _ | Lswitch _ | Lstaticraise _ + | Lifthenelse _ | Lsequence _ | Lwhile _ +- | Lsend _ | Levent _ | Lifused _ -> () ++ | Lsend _ | Levent _ -> () + in free l; !fv + +-let free_variables l = +- free_ids (function Lvar id -> [id] | _ -> []) l ++let free_variables ?(ifused=false) l = ++ free_ids (function Lvar id -> [id] | _ -> []) ifused l + + let free_methods l = +- free_ids (function Lsend(Self, Lvar meth, obj, _) -> [meth] | _ -> []) l ++ free_ids (function Lsend(Self, Lvar meth, obj, _) -> [meth] | _ -> []) ++ false l + + (* Check if an action has a "when" guard *) + let raise_count = ref 0 +Index: bytecomp/lambda.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/lambda.mli,v +retrieving revision 1.42 +diff -u -r1.42 lambda.mli +--- bytecomp/lambda.mli 25 Aug 2005 15:35:16 -0000 1.42 ++++ bytecomp/lambda.mli 2 Feb 2006 05:08:56 -0000 +@@ -177,7 +177,7 @@ + + val iter: (lambda -> unit) -> lambda -> unit + module IdentSet: Set.S with type elt = Ident.t +-val free_variables: lambda -> IdentSet.t ++val free_variables: ?ifused:bool -> lambda -> IdentSet.t + val free_methods: lambda -> IdentSet.t + + val transl_path: Path.t -> lambda +Index: bytecomp/translclass.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translclass.ml,v +retrieving revision 1.38 +diff -u -r1.38 translclass.ml +--- bytecomp/translclass.ml 13 Aug 2005 20:59:37 -0000 1.38 ++++ bytecomp/translclass.ml 2 Feb 2006 05:08:56 -0000 +@@ -46,6 +46,10 @@ + + let lfield v i = Lprim(Pfield i, [Lvar v]) + ++let ltuple l = Lprim(Pmakeblock(0,Immutable), l) ++ ++let lprim name args = Lapply(oo_prim name, args) ++ + let transl_label l = share (Const_immstring l) + + let rec transl_meth_list lst = +@@ -68,8 +72,8 @@ + Lvar offset])])])) + + let transl_val tbl create name = +- Lapply (oo_prim (if create then "new_variable" else "get_variable"), +- [Lvar tbl; transl_label name]) ++ lprim (if create then "new_variable" else "get_variable") ++ [Lvar tbl; transl_label name] + + let transl_vals tbl create vals rem = + List.fold_right +@@ -82,7 +86,7 @@ + (fun (nm, id) rem -> + try + (nm, id, +- Lapply(oo_prim "get_method", [Lvar tbl; Lvar (Meths.find nm meths)])) ++ lprim "get_method" [Lvar tbl; Lvar (Meths.find nm meths)]) + :: rem + with Not_found -> rem) + inh_meths [] +@@ -97,17 +101,15 @@ + let (inh_init, obj_init, has_init) = init obj' in + if obj_init = lambda_unit then + (inh_init, +- Lapply (oo_prim (if has_init then "create_object_and_run_initializers" +- else"create_object_opt"), +- [obj; Lvar cl])) ++ lprim (if has_init then "create_object_and_run_initializers" ++ else"create_object_opt") ++ [obj; Lvar cl]) + else begin + (inh_init, +- Llet(Strict, obj', +- Lapply (oo_prim "create_object_opt", [obj; Lvar cl]), ++ Llet(Strict, obj', lprim "create_object_opt" [obj; Lvar cl], + Lsequence(obj_init, + if not has_init then Lvar obj' else +- Lapply (oo_prim "run_initializers_opt", +- [obj; Lvar obj'; Lvar cl])))) ++ lprim "run_initializers_opt" [obj; Lvar obj'; Lvar cl]))) + end + + let rec build_object_init cl_table obj params inh_init obj_init cl = +@@ -203,14 +205,13 @@ + + + let bind_method tbl lab id cl_init = +- Llet(StrictOpt, id, Lapply (oo_prim "get_method_label", +- [Lvar tbl; transl_label lab]), ++ Llet(StrictOpt, id, lprim "get_method_label" [Lvar tbl; transl_label lab], + cl_init) + +-let bind_methods tbl meths vals cl_init = +- let methl = Meths.fold (fun lab id tl -> (lab,id) :: tl) meths [] in ++let bind_methods tbl methl vals cl_init = + let len = List.length methl and nvals = List.length vals in +- if len < 2 && nvals = 0 then Meths.fold (bind_method tbl) meths cl_init else ++ if len < 2 && nvals = 0 then ++ List.fold_right (fun (n,i) -> bind_method tbl n i) methl cl_init else + if len = 0 && nvals < 2 then transl_vals tbl true vals cl_init else + let ids = Ident.create "ids" in + let i = ref len in +@@ -229,21 +230,19 @@ + vals' cl_init) + in + Llet(StrictOpt, ids, +- Lapply (oo_prim getter, +- [Lvar tbl; transl_meth_list (List.map fst methl)] @ names), ++ lprim getter ++ ([Lvar tbl; transl_meth_list (List.map fst methl)] @ names), + List.fold_right +- (fun (lab,id) lam -> decr i; Llet(StrictOpt, id, lfield ids !i, lam)) ++ (fun (lab,id) lam -> decr i; Llet(Alias, id, lfield ids !i, lam)) + methl cl_init) + + let output_methods tbl methods lam = + match methods with + [] -> lam + | [lab; code] -> +- lsequence (Lapply(oo_prim "set_method", [Lvar tbl; lab; code])) lam ++ lsequence (lprim "set_method" [Lvar tbl; lab; code]) lam + | _ -> +- lsequence (Lapply(oo_prim "set_methods", +- [Lvar tbl; Lprim(Pmakeblock(0,Immutable), methods)])) +- lam ++ lsequence (lprim "set_methods" [Lvar tbl; ltuple methods]) lam + + let rec ignore_cstrs cl = + match cl.cl_desc with +@@ -266,7 +265,8 @@ + Llet (Strict, obj_init, + Lapply(Lprim(Pfield 1, [lpath]), Lvar cla :: + if top then [Lprim(Pfield 3, [lpath])] else []), +- bind_super cla super cl_init)) ++ bind_super cla super cl_init), ++ [], []) + | _ -> + assert false + end +@@ -278,10 +278,11 @@ + match field with + Cf_inher (cl, vals, meths) -> + let cl_init = output_methods cla methods cl_init in +- let inh_init, cl_init = ++ let (inh_init, cl_init, meths', vals') = + build_class_init cla false + (vals, meths_super cla str.cl_meths meths) + inh_init cl_init msubst top cl in ++ let cl_init = bind_methods cla meths' vals' cl_init in + (inh_init, cl_init, [], values) + | Cf_val (name, id, exp) -> + (inh_init, cl_init, methods, (name, id)::values) +@@ -304,29 +305,37 @@ + (inh_init, cl_init, methods, vals @ values) + | Cf_init exp -> + (inh_init, +- Lsequence(Lapply (oo_prim "add_initializer", +- Lvar cla :: msubst false (transl_exp exp)), ++ Lsequence(lprim "add_initializer" ++ (Lvar cla :: msubst false (transl_exp exp)), + cl_init), + methods, values)) + str.cl_field + (inh_init, cl_init, [], []) + in + let cl_init = output_methods cla methods cl_init in +- (inh_init, bind_methods cla str.cl_meths values cl_init) ++ (* inh_init, bind_methods cla str.cl_meths values cl_init *) ++ let methods = Meths.fold (fun n i l -> (n,i)::l) str.cl_meths [] in ++ (inh_init, cl_init, methods, values) + | Tclass_fun (pat, vals, cl, _) -> +- let (inh_init, cl_init) = ++ let (inh_init, cl_init, methods, values) = + build_class_init cla cstr super inh_init cl_init msubst top cl + in ++ let fv = free_variables ~ifused:true cl_init in ++ let vals = List.filter (fun (id,_) -> IdentSet.mem id fv) vals in + let vals = List.map (function (id, _) -> (Ident.name id, id)) vals in +- (inh_init, transl_vals cla true vals cl_init) ++ (* inh_init, transl_vals cla true vals cl_init *) ++ (inh_init, cl_init, methods, vals @ values) + | Tclass_apply (cl, exprs) -> + build_class_init cla cstr super inh_init cl_init msubst top cl + | Tclass_let (rec_flag, defs, vals, cl) -> +- let (inh_init, cl_init) = ++ let (inh_init, cl_init, methods, values) = + build_class_init cla cstr super inh_init cl_init msubst top cl + in ++ let fv = free_variables ~ifused:true cl_init in ++ let vals = List.filter (fun (id,_) -> IdentSet.mem id fv) vals in + let vals = List.map (function (id, _) -> (Ident.name id, id)) vals in +- (inh_init, transl_vals cla true vals cl_init) ++ (* inh_init, transl_vals cla true vals cl_init *) ++ (inh_init, cl_init, methods, vals @ values) + | Tclass_constraint (cl, vals, meths, concr_meths) -> + let virt_meths = + List.filter (fun lab -> not (Concr.mem lab concr_meths)) meths in +@@ -358,23 +367,34 @@ + cl_init valids in + (inh_init, + Llet (Strict, inh, +- Lapply(oo_prim "inherits", narrow_args @ +- [lpath; Lconst(Const_pointer(if top then 1 else 0))]), ++ lprim "inherits" ++ (narrow_args @ ++ [lpath; Lconst(Const_pointer(if top then 1 else 0))]), + Llet(StrictOpt, obj_init, lfield inh 0, + Llet(Alias, inh_vals, lfield inh 1, +- Llet(Alias, inh_meths, lfield inh 2, cl_init))))) ++ Llet(Alias, inh_meths, lfield inh 2, cl_init)))), ++ [], []) + | _ -> + let core cl_init = + build_class_init cla true super inh_init cl_init msubst top cl + in + if cstr then core cl_init else +- let (inh_init, cl_init) = +- core (Lsequence (Lapply (oo_prim "widen", [Lvar cla]), cl_init)) ++ let (inh_init, cl_init, methods, values) = ++ core (Lsequence (lprim "widen" [Lvar cla], cl_init)) + in +- (inh_init, +- Lsequence(Lapply (oo_prim "narrow", narrow_args), cl_init)) ++ let cl_init = bind_methods cla methods values cl_init in ++ (inh_init, Lsequence(lprim "narrow" narrow_args, cl_init), [], []) + end + ++let build_class_init cla env inh_init obj_init msubst top cl = ++ let inh_init = List.rev inh_init in ++ let (inh_init, cl_init, methods, values) = ++ build_class_init cla true ([],[]) inh_init obj_init msubst top cl in ++ assert (inh_init = []); ++ if IdentSet.mem env (free_variables ~ifused:true cl_init) ++ then bind_methods cla methods (("", env) :: values) cl_init ++ else Llet(Alias, env, lambda_unit, bind_methods cla methods values cl_init) ++ + let rec build_class_lets cl = + match cl.cl_desc with + Tclass_let (rec_flag, defs, vals, cl) -> +@@ -459,16 +479,16 @@ + Strict, new_init, lfunction [obj_init] obj_init', + Llet( + Alias, cla, transl_path path, +- Lprim(Pmakeblock(0, Immutable), +- [Lapply(Lvar new_init, [lfield cla 0]); +- lfunction [table] +- (Llet(Strict, env_init, +- Lapply(lfield cla 1, [Lvar table]), +- lfunction [envs] +- (Lapply(Lvar new_init, +- [Lapply(Lvar env_init, [Lvar envs])])))); +- lfield cla 2; +- lfield cla 3]))) ++ ltuple ++ [Lapply(Lvar new_init, [lfield cla 0]); ++ lfunction [table] ++ (Llet(Strict, env_init, ++ Lapply(lfield cla 1, [Lvar table]), ++ lfunction [envs] ++ (Lapply(Lvar new_init, ++ [Lapply(Lvar env_init, [Lvar envs])])))); ++ lfield cla 2; ++ lfield cla 3])) + with Exit -> + lambda_unit + +@@ -541,7 +561,7 @@ + open CamlinternalOO + let builtin_meths arr self env env2 body = + let builtin, args = builtin_meths self env env2 body in +- if not arr then [Lapply(oo_prim builtin, args)] else ++ if not arr then [lprim builtin args] else + let tag = match builtin with + "get_const" -> GetConst + | "get_var" -> GetVar +@@ -599,7 +619,8 @@ + + (* Prepare for heavy environment handling *) + let tables = Ident.create (Ident.name cl_id ^ "_tables") in +- let (top_env, req) = oo_add_class tables in ++ let table_init = ref None in ++ let (top_env, req) = oo_add_class tables table_init in + let top = not req in + let cl_env, llets = build_class_lets cl in + let new_ids = if top then [] else Env.diff top_env cl_env in +@@ -633,6 +654,7 @@ + begin try + (* Doesn't seem to improve size for bytecode *) + (* if not !Clflags.native_code then raise Not_found; *) ++ if !Clflags.debug then raise Not_found; + builtin_meths arr [self] env env2 (lfunction args body') + with Not_found -> + [lfunction (self :: args) +@@ -665,15 +687,8 @@ + build_object_init_0 cla [] cl copy_env subst_env top ids in + if not (Translcore.check_recursive_lambda ids obj_init) then + raise(Error(cl.cl_loc, Illegal_class_expr)); +- let inh_init' = List.rev inh_init in +- let (inh_init', cl_init) = +- build_class_init cla true ([],[]) inh_init' obj_init msubst top cl +- in +- assert (inh_init' = []); +- let table = Ident.create "table" +- and class_init = Ident.create (Ident.name cl_id ^ "_init") +- and env_init = Ident.create "env_init" +- and obj_init = Ident.create "obj_init" in ++ let cl_init = build_class_init cla env2 inh_init obj_init msubst top cl in ++ let obj_init = Ident.create "obj_init" in + let pub_meths = + List.sort + (fun s s' -> compare (Btype.hash_variant s) (Btype.hash_variant s')) +@@ -685,42 +700,44 @@ + let name' = List.assoc tag rev_map in + if name' <> name then raise(Error(cl.cl_loc, Tags(name, name')))) + tags pub_meths; ++ let pos = cl.cl_loc.Location.loc_end in ++ let filepos = [transl_label pos.Lexing.pos_fname; ++ Lconst(Const_base(Const_int pos.Lexing.pos_cnum))] in + let ltable table lam = +- Llet(Strict, table, +- Lapply (oo_prim "create_table", [transl_meth_list pub_meths]), lam) ++ Llet(Strict, table, lprim "create_table" [transl_meth_list pub_meths], lam) + and ldirect obj_init = + Llet(Strict, obj_init, cl_init, +- Lsequence(Lapply (oo_prim "init_class", [Lvar cla]), ++ Lsequence(lprim "init_class_shared" (Lvar cla :: filepos), + Lapply(Lvar obj_init, [lambda_unit]))) + in + (* Simplest case: an object defined at toplevel (ids=[]) *) + if top && ids = [] then llets (ltable cla (ldirect obj_init)) else + ++ let table = Ident.create "table" ++ and class_init = Ident.create (Ident.name cl_id ^ "_init") ++ and env_init = Ident.create (Ident.name cl_id ^ "_env_init") in ++ let cl_init_fun = Lfunction(Curried, [cla], cl_init) in + let concrete = + ids = [] || + Typeclass.virtual_methods (Ctype.signature_of_class_type cl.cl_type) = [] +- and lclass lam = +- let cl_init = llets (Lfunction(Curried, [cla], cl_init)) in ++ and lclass cl_init lam = + Llet(Strict, class_init, cl_init, lam (free_variables cl_init)) + and lbody fv = + if List.for_all (fun id -> not (IdentSet.mem id fv)) ids then +- Lapply (oo_prim "make_class",[transl_meth_list pub_meths; +- Lvar class_init]) ++ lprim "make_class" ++ (transl_meth_list pub_meths :: Lvar class_init :: filepos) + else + ltable table ( + Llet( + Strict, env_init, Lapply(Lvar class_init, [Lvar table]), +- Lsequence( +- Lapply (oo_prim "init_class", [Lvar table]), +- Lprim(Pmakeblock(0, Immutable), +- [Lapply(Lvar env_init, [lambda_unit]); +- Lvar class_init; Lvar env_init; lambda_unit])))) ++ Lsequence(lprim "init_class_shared" (Lvar table :: filepos), ++ ltuple [Lapply(Lvar env_init, [lambda_unit]); ++ Lvar class_init; Lvar env_init; lambda_unit]))) + and lbody_virt lenvs = +- Lprim(Pmakeblock(0, Immutable), +- [lambda_unit; Lfunction(Curried,[cla], cl_init); lambda_unit; lenvs]) ++ ltuple [lambda_unit; cl_init_fun; lambda_unit; lenvs] + in + (* Still easy: a class defined at toplevel *) +- if top && concrete then lclass lbody else ++ if top && concrete then lclass (llets cl_init_fun) lbody else + if top then llets (lbody_virt lambda_unit) else + + (* Now for the hard stuff: prepare for table cacheing *) +@@ -733,23 +750,16 @@ + let lenv = + let menv = + if !new_ids_meths = [] then lambda_unit else +- Lprim(Pmakeblock(0, Immutable), +- List.map (fun id -> Lvar id) !new_ids_meths) in ++ ltuple (List.map (fun id -> Lvar id) !new_ids_meths) in + if !new_ids_init = [] then menv else +- Lprim(Pmakeblock(0, Immutable), +- menv :: List.map (fun id -> Lvar id) !new_ids_init) ++ ltuple (menv :: List.map (fun id -> Lvar id) !new_ids_init) + and linh_envs = + List.map (fun (_, p) -> Lprim(Pfield 3, [transl_path p])) + (List.rev inh_init) + in + let make_envs lam = + Llet(StrictOpt, envs, +- (if linh_envs = [] then lenv else +- Lprim(Pmakeblock(0, Immutable), lenv :: linh_envs)), +- lam) +- and def_ids cla lam = +- Llet(StrictOpt, env2, +- Lapply (oo_prim "new_variable", [Lvar cla; transl_label ""]), ++ (if linh_envs = [] then lenv else ltuple (lenv :: linh_envs)), + lam) + in + let inh_paths = +@@ -757,46 +767,53 @@ + (fun (_,path) -> List.mem (Path.head path) new_ids) inh_init in + let inh_keys = + List.map (fun (_,p) -> Lprim(Pfield 1, [transl_path p])) inh_paths in +- let lclass lam = +- Llet(Strict, class_init, +- Lfunction(Curried, [cla], def_ids cla cl_init), lam) ++ let lclass_init lam = ++ Llet(Strict, class_init, cl_init_fun, lam) + and lcache lam = + if inh_keys = [] then Llet(Alias, cached, Lvar tables, lam) else +- Llet(Strict, cached, +- Lapply(oo_prim "lookup_tables", +- [Lvar tables; Lprim(Pmakeblock(0, Immutable), inh_keys)]), ++ Llet(Strict, cached, lprim "lookup_tables" [Lvar tables; ltuple inh_keys], + lam) + and lset cached i lam = + Lprim(Psetfield(i, true), [Lvar cached; lam]) + in +- let ldirect () = +- ltable cla +- (Llet(Strict, env_init, def_ids cla cl_init, +- Lsequence(Lapply (oo_prim "init_class", [Lvar cla]), +- lset cached 0 (Lvar env_init)))) +- and lclass_virt () = +- lset cached 0 (Lfunction(Curried, [cla], def_ids cla cl_init)) ++ let ldirect prim pos = ++ ltable cla ( ++ Llet(Strict, env_init, cl_init, ++ Lsequence(lprim prim (Lvar cla :: pos), Lvar env_init))) ++ and lclass_concrete cached = ++ ltuple [Lapply (lfield cached 0, [lenvs]); ++ lfield cached 1; lfield cached 0; lenvs] + in ++ + llets ( +- lcache ( +- Lsequence( +- Lifthenelse(lfield cached 0, lambda_unit, +- if ids = [] then ldirect () else +- if not concrete then lclass_virt () else +- lclass ( +- Lapply (oo_prim "make_class_store", +- [transl_meth_list pub_meths; +- Lvar class_init; Lvar cached]))), + make_envs ( +- if ids = [] then Lapply(lfield cached 0, [lenvs]) else +- Lprim(Pmakeblock(0, Immutable), +- if concrete then +- [Lapply(lfield cached 0, [lenvs]); +- lfield cached 1; +- lfield cached 0; +- lenvs] +- else [lambda_unit; lfield cached 0; lambda_unit; lenvs] +- ))))) ++ if inh_paths = [] && concrete then ++ if ids = [] then begin ++ table_init := Some (ldirect "init_class_shared" filepos); ++ Lapply (Lvar tables, [lenvs]) ++ end else begin ++ let init = ++ lclass cl_init_fun (fun _ -> ++ lprim "make_class_env" ++ (transl_meth_list pub_meths :: Lvar class_init :: filepos)) ++ in table_init := Some init; ++ lclass_concrete tables ++ end ++ else begin ++ lcache ( ++ Lsequence( ++ Lifthenelse(lfield cached 0, lambda_unit, ++ if ids = [] then lset cached 0 (ldirect "init_class" []) else ++ if not concrete then lset cached 0 cl_init_fun else ++ lclass_init ( ++ lprim "make_class_store" ++ [transl_meth_list pub_meths; Lvar class_init; Lvar cached])), ++ llets ( ++ make_envs ( ++ if ids = [] then Lapply(lfield cached 0, [lenvs]) else ++ if concrete then lclass_concrete cached else ++ ltuple [lambda_unit; lfield cached 0; lambda_unit; lenvs])))) ++ end)) + + (* Wrapper for class compilation *) + +Index: bytecomp/translobj.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translobj.ml,v +retrieving revision 1.9 +diff -u -r1.9 translobj.ml +--- bytecomp/translobj.ml 26 May 2004 11:10:51 -0000 1.9 ++++ bytecomp/translobj.ml 2 Feb 2006 05:08:56 -0000 +@@ -88,7 +88,6 @@ + + (* Insert labels *) + +-let string s = Lconst (Const_base (Const_string s)) + let int n = Lconst (Const_base (Const_int n)) + + let prim_makearray = +@@ -124,8 +123,8 @@ + let top_env = ref Env.empty + let classes = ref [] + +-let oo_add_class id = +- classes := id :: !classes; ++let oo_add_class id init = ++ classes := (id, init) :: !classes; + (!top_env, !cache_required) + + let oo_wrap env req f x = +@@ -141,10 +140,12 @@ + let lambda = f x in + let lambda = + List.fold_left +- (fun lambda id -> ++ (fun lambda (id, init) -> + Llet(StrictOpt, id, +- Lprim(Pmakeblock(0, Mutable), +- [lambda_unit; lambda_unit; lambda_unit]), ++ (match !init with ++ Some lam -> lam ++ | None -> Lprim(Pmakeblock(0, Mutable), ++ [lambda_unit; lambda_unit; lambda_unit])), + lambda)) + lambda !classes + in +Index: bytecomp/translobj.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translobj.mli,v +retrieving revision 1.6 +diff -u -r1.6 translobj.mli +--- bytecomp/translobj.mli 26 May 2004 11:10:51 -0000 1.6 ++++ bytecomp/translobj.mli 2 Feb 2006 05:08:56 -0000 +@@ -25,4 +25,4 @@ + Ident.t -> int -> ('a -> lambda) -> 'a -> int * lambda + + val oo_wrap: Env.t -> bool -> ('a -> lambda) -> 'a -> lambda +-val oo_add_class: Ident.t -> Env.t * bool ++val oo_add_class: Ident.t -> Lambda.lambda option ref -> Env.t * bool +Index: byterun/compare.h +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/byterun/compare.h,v +retrieving revision 1.2 +diff -u -r1.2 compare.h +--- byterun/compare.h 31 Dec 2003 14:20:35 -0000 1.2 ++++ byterun/compare.h 2 Feb 2006 05:08:56 -0000 +@@ -17,5 +17,6 @@ + #define CAML_COMPARE_H + + CAMLextern int caml_compare_unordered; ++CAMLextern value caml_compare(value, value); + + #endif /* CAML_COMPARE_H */ +Index: byterun/extern.c +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/byterun/extern.c,v +retrieving revision 1.59 +diff -u -r1.59 extern.c +--- byterun/extern.c 4 Jan 2006 16:55:49 -0000 1.59 ++++ byterun/extern.c 2 Feb 2006 05:08:56 -0000 +@@ -411,6 +411,22 @@ + extern_record_location(v); + break; + } ++ case Object_tag: { ++ value field0; ++ mlsize_t i; ++ i = Wosize_val(Field(v, 0)) - 1; ++ field0 = Field(Field(v, 0),i); ++ if (Wosize_val(field0) > 0) { ++ writecode32(CODE_OBJECT, Wosize_hd (hd)); ++ extern_record_location(v); ++ extern_rec(field0); ++ for (i = 1; i < sz - 1; i++) extern_rec(Field(v, i)); ++ v = Field(v, i); ++ goto tailcall; ++ } ++ if (!extern_closures) ++ extern_invalid_argument("output_value: dynamic class"); ++ } /* may fall through */ + default: { + value field0; + mlsize_t i; +Index: byterun/intern.c +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/byterun/intern.c,v +retrieving revision 1.60 +diff -u -r1.60 intern.c +--- byterun/intern.c 22 Sep 2005 14:21:50 -0000 1.60 ++++ byterun/intern.c 2 Feb 2006 05:08:56 -0000 +@@ -28,6 +28,8 @@ + #include "mlvalues.h" + #include "misc.h" + #include "reverse.h" ++#include "callback.h" ++#include "compare.h" + + static unsigned char * intern_src; + /* Reading pointer in block holding input data. */ +@@ -98,6 +100,25 @@ + #define readblock(dest,len) \ + (memmove((dest), intern_src, (len)), intern_src += (len)) + ++static value get_method_table (value key) ++{ ++ static value *classes = NULL; ++ value current; ++ if (classes == NULL) { ++ classes = caml_named_value("caml_oo_classes"); ++ if (classes == NULL) return 0; ++ caml_register_global_root(classes); ++ } ++ for (current = Field(*classes, 0); Is_block(current); ++ current = Field(current, 1)) ++ { ++ value head = Field(current, 0); ++ if (caml_compare(key, Field(head, 0)) == Val_int(0)) ++ return Field(head, 1); ++ } ++ return 0; ++} ++ + static void intern_cleanup(void) + { + if (intern_input_malloced) caml_stat_free(intern_input); +@@ -315,6 +336,24 @@ + Custom_ops_val(v) = ops; + intern_dest += 1 + size; + break; ++ case CODE_OBJECT: ++ size = read32u(); ++ v = Val_hp(intern_dest); ++ *dest = v; ++ if (intern_obj_table != NULL) intern_obj_table[obj_counter++] = v; ++ dest = (value *) (intern_dest + 1); ++ *intern_dest = Make_header(size, Object_tag, intern_color); ++ intern_dest += 1 + size; ++ intern_rec(dest); ++ *dest = get_method_table(*dest); ++ if (*dest == 0) { ++ intern_cleanup(); ++ caml_failwith("input_value: unknown class"); ++ } ++ for(size--, dest++; size > 1; size--, dest++) ++ intern_rec(dest); ++ goto tailcall; ++ + default: + intern_cleanup(); + caml_failwith("input_value: ill-formed message"); +Index: byterun/intext.h +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/byterun/intext.h,v +retrieving revision 1.32 +diff -u -r1.32 intext.h +--- byterun/intext.h 22 Sep 2005 14:21:50 -0000 1.32 ++++ byterun/intext.h 2 Feb 2006 05:08:56 -0000 +@@ -56,6 +56,7 @@ + #define CODE_CODEPOINTER 0x10 + #define CODE_INFIXPOINTER 0x11 + #define CODE_CUSTOM 0x12 ++#define CODE_OBJECT 0x14 + + #if ARCH_FLOAT_ENDIANNESS == 0x76543210 + #define CODE_DOUBLE_NATIVE CODE_DOUBLE_BIG +Index: stdlib/camlinternalOO.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/stdlib/camlinternalOO.ml,v +retrieving revision 1.14 +diff -u -r1.14 camlinternalOO.ml +--- stdlib/camlinternalOO.ml 25 Oct 2005 18:34:07 -0000 1.14 ++++ stdlib/camlinternalOO.ml 2 Feb 2006 05:08:56 -0000 +@@ -305,10 +305,38 @@ + public_methods; + table + ++(* ++let create_table_variables pub_meths priv_meths vars = ++ let tbl = create_table pub_meths in ++ let pub_meths = to_array pub_meths ++ and priv_meths = to_array priv_meths ++ and vars = to_array vars in ++ let len = 2 + Array.length pub_meths + Array.length priv_meths in ++ let res = Array.create len tbl in ++ let mv = new_methods_variables tbl pub_meths vars in ++ Array.blit mv 0 res 1; ++ res ++*) ++ + let init_class table = + inst_var_count := !inst_var_count + table.size - 1; + table.initializers <- List.rev table.initializers; +- resize table (3 + magic table.methods.(1) * 16 / Sys.word_size) ++ let len = 3 + magic table.methods.(1) * 16 / Sys.word_size in ++ (* keep 1 more for extra info *) ++ let len = if len > Array.length table.methods then len else len+1 in ++ resize table len ++ ++let classes = ref [] ++let () = Callback.register "caml_oo_classes" classes ++ ++let init_class_shared table (file : string) (pos : int) = ++ init_class table; ++ let rec unique_pos pos = ++ if List.mem_assoc (file, pos) !classes then unique_pos (pos + 0x100000) ++ else pos in ++ let pos = unique_pos pos in ++ table.methods.(Array.length table.methods - 1) <- Obj.magic (file, pos); ++ classes := ((file, pos), table.methods) :: !classes + + let inherits cla vals virt_meths concr_meths (_, super, _, env) top = + narrow cla vals virt_meths concr_meths; +@@ -319,12 +347,18 @@ + Array.map (fun nm -> get_method cla (get_method_label cla nm)) + (to_array concr_meths)) + +-let make_class pub_meths class_init = ++let make_class pub_meths class_init file pos = + let table = create_table pub_meths in + let env_init = class_init table in +- init_class table; ++ init_class_shared table file pos; + (env_init (Obj.repr 0), class_init, env_init, Obj.repr 0) + ++let make_class_env pub_meths class_init file pos = ++ let table = create_table pub_meths in ++ let env_init = class_init table in ++ init_class_shared table file pos; ++ (env_init, class_init) ++ + type init_table = { mutable env_init: t; mutable class_init: table -> t } + + let make_class_store pub_meths class_init init_table = +Index: stdlib/camlinternalOO.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/stdlib/camlinternalOO.mli,v +retrieving revision 1.9 +diff -u -r1.9 camlinternalOO.mli +--- stdlib/camlinternalOO.mli 25 Oct 2005 18:34:07 -0000 1.9 ++++ stdlib/camlinternalOO.mli 2 Feb 2006 05:08:56 -0000 +@@ -43,14 +43,20 @@ + val add_initializer : table -> (obj -> unit) -> unit + val dummy_table : table + val create_table : string array -> table ++(* val create_table_variables : ++ string array -> string array -> string array -> table *) + val init_class : table -> unit ++val init_class_shared : table -> string -> int -> unit + val inherits : + table -> string array -> string array -> string array -> + (t * (table -> obj -> Obj.t) * t * obj) -> bool -> + (Obj.t * int array * closure array) + val make_class : +- string array -> (table -> Obj.t -> t) -> ++ string array -> (table -> Obj.t -> t) -> string -> int -> + (t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t) ++val make_class_env : ++ string array -> (table -> Obj.t -> t) -> string -> int -> ++ (Obj.t -> t) * (table -> Obj.t -> t) + type init_table + val make_class_store : + string array -> (table -> t) -> init_table -> unit diff --git a/testlabl/mixin.ml b/testlabl/mixin.ml new file mode 100644 index 0000000..05535c3 --- /dev/null +++ b/testlabl/mixin.ml @@ -0,0 +1,146 @@ +(* $Id: mixin.ml,v 1.3 2003-11-19 02:36:57 garrigue Exp $ *) + +open StdLabels +open MoreLabels + +(* Use maps for substitutions and sets for free variables *) + +module Subst = Map.Make(struct type t = string let compare = compare end) +module Names = Set.Make(struct type t = string let compare = compare end) + + +(* Variables are common to lambda and expr *) + +type var = [`Var of string] + +let subst_var ~subst : var -> _ = + function `Var s as x -> + try Subst.find s subst + with Not_found -> x + +let free_var : var -> _ = function `Var s -> Names.singleton s + + +(* The lambda language: free variables, substitutions, and evaluation *) + +type 'a lambda = [`Var of string | `Abs of string * 'a | `App of 'a * 'a] + +let free_lambda ~free_rec : _ lambda -> _ = function + #var as x -> free_var x + | `Abs (s, t) -> Names.remove s (free_rec t) + | `App (t1, t2) -> Names.union (free_rec t1) (free_rec t2) + +let map_lambda ~map_rec : _ lambda -> _ = function + #var as x -> x + | `Abs (s, t) as l -> + let t' = map_rec t in + if t == t' then l else `Abs(s, t') + | `App (t1, t2) as l -> + let t'1 = map_rec t1 and t'2 = map_rec t2 in + if t'1 == t1 && t'2 == t2 then l else `App (t'1, t'2) + +let next_id = + let current = ref 3 in + fun () -> incr current; !current + +let subst_lambda ~subst_rec ~free ~subst : _ lambda -> _ = function + #var as x -> subst_var ~subst x + | `Abs(s, t) as l -> + let used = free t in + let used_expr = + Subst.fold subst ~init:[] + ~f:(fun ~key ~data acc -> + if Names.mem s used then data::acc else acc) in + if List.exists used_expr ~f:(fun t -> Names.mem s (free t)) then + let name = s ^ string_of_int (next_id ()) in + `Abs(name, + subst_rec ~subst:(Subst.add ~key:s ~data:(`Var name) subst) t) + else + map_lambda ~map_rec:(subst_rec ~subst:(Subst.remove s subst)) l + | `App _ as l -> + map_lambda ~map_rec:(subst_rec ~subst) l + +let eval_lambda ~eval_rec ~subst l = + match map_lambda ~map_rec:eval_rec l with + `App(`Abs(s,t1), t2) -> + eval_rec (subst ~subst:(Subst.add ~key:s ~data:t2 Subst.empty) t1) + | t -> t + +(* Specialized versions to use on lambda *) + +let rec free1 x = free_lambda ~free_rec:free1 x +let rec subst1 ~subst = subst_lambda ~subst_rec:subst1 ~free:free1 ~subst +let rec eval1 x = eval_lambda ~eval_rec:eval1 ~subst:subst1 x + + +(* The expr language of arithmetic expressions *) + +type 'a expr = + [`Var of string | `Num of int | `Add of 'a * 'a + | `Neg of 'a | `Mult of 'a * 'a] + +let free_expr ~free_rec : _ expr -> _ = function + #var as x -> free_var x + | `Num _ -> Names.empty + | `Add(x, y) -> Names.union (free_rec x) (free_rec y) + | `Neg x -> free_rec x + | `Mult(x, y) -> Names.union (free_rec x) (free_rec y) + +(* Here map_expr helps a lot *) +let map_expr ~map_rec : _ expr -> _ = function + #var as x -> x + | `Num _ as x -> x + | `Add(x, y) as e -> + let x' = map_rec x and y' = map_rec y in + if x == x' && y == y' then e + else `Add(x', y') + | `Neg x as e -> + let x' = map_rec x in + if x == x' then e else `Neg x' + | `Mult(x, y) as e -> + let x' = map_rec x and y' = map_rec y in + if x == x' && y == y' then e + else `Mult(x', y') + +let subst_expr ~subst_rec ~subst : _ expr -> _ = function + #var as x -> subst_var ~subst x + | #expr as e -> map_expr ~map_rec:(subst_rec ~subst) e + +let eval_expr ~eval_rec e = + match map_expr ~map_rec:eval_rec e with + `Add(`Num m, `Num n) -> `Num (m+n) + | `Neg(`Num n) -> `Num (-n) + | `Mult(`Num m, `Num n) -> `Num (m*n) + | #expr as e -> e + +(* Specialized versions *) + +let rec free2 x = free_expr ~free_rec:free2 x +let rec subst2 ~subst = subst_expr ~subst_rec:subst2 ~subst +let rec eval2 x = eval_expr ~eval_rec:eval2 x + + +(* The lexpr language, reunion of lambda and expr *) + +type lexpr = + [ `Var of string | `Abs of string * lexpr | `App of lexpr * lexpr + | `Num of int | `Add of lexpr * lexpr | `Neg of lexpr + | `Mult of lexpr * lexpr ] + +let rec free : lexpr -> _ = function + #lambda as x -> free_lambda ~free_rec:free x + | #expr as x -> free_expr ~free_rec:free x + +let rec subst ~subst:s : lexpr -> _ = function + #lambda as x -> subst_lambda ~subst_rec:subst ~subst:s ~free x + | #expr as x -> subst_expr ~subst_rec:subst ~subst:s x + +let rec eval : lexpr -> _ = function + #lambda as x -> eval_lambda ~eval_rec:eval ~subst x + | #expr as x -> eval_expr ~eval_rec:eval x + +(* A few examples: +eval1 (`App(`Abs("x",`Var"x"), `Var"y"));; +eval2 (`Add(`Mult(`Num 3,`Neg(`Num 2)), `Var"x"));; +eval (`Add(`App(`Abs("x",`Mult(`Var"x",`Var"x")),`Num 2), `Num 5));; +*) diff --git a/testlabl/mixin2.ml b/testlabl/mixin2.ml new file mode 100644 index 0000000..01a51f4 --- /dev/null +++ b/testlabl/mixin2.ml @@ -0,0 +1,179 @@ +(* $Id: mixin2.ml,v 1.1 2003-11-19 02:36:57 garrigue Exp $ *) + +(* Full fledge version, using objects to structure code *) + +open StdLabels +open MoreLabels + +(* Use maps for substitutions and sets for free variables *) + +module Subst = Map.Make(struct type t = string let compare = compare end) +module Names = Set.Make(struct type t = string let compare = compare end) + +(* To build recursive objects *) + +let lazy_fix make = + let rec obj () = make (lazy (obj ()) : _ Lazy.t) in + obj () + +let (!!) = Lazy.force + +(* The basic operations *) + +class type ['a, 'b] ops = + object + method free : 'b -> Names.t + method subst : sub:'a Subst.t -> 'b -> 'a + method eval : 'b -> 'a + end + +(* Variables are common to lambda and expr *) + +type var = [`Var of string] + +class ['a] var_ops = object (self : ('a, var) #ops) + constraint 'a = [> var] + method subst ~sub (`Var s as x) = + try Subst.find s sub with Not_found -> x + method free (`Var s) = + Names.singleton s + method eval (#var as v) = v +end + +(* The lambda language: free variables, substitutions, and evaluation *) + +type 'a lambda = [`Var of string | `Abs of string * 'a | `App of 'a * 'a] + +let next_id = + let current = ref 3 in + fun () -> incr current; !current + +class ['a] lambda_ops (ops : ('a,'a) #ops Lazy.t) = + let var : 'a var_ops = new var_ops + and free = lazy !!ops#free + and subst = lazy !!ops#subst + and eval = lazy !!ops#eval in + object (self : ('a, 'a lambda) #ops) + constraint 'a = [> 'a lambda] + method free = function + #var as x -> var#free x + | `Abs (s, t) -> Names.remove s (!!free t) + | `App (t1, t2) -> Names.union (!!free t1) (!!free t2) + + method map ~f = function + #var as x -> x + | `Abs (s, t) as l -> + let t' = f t in + if t == t' then l else `Abs(s, t') + | `App (t1, t2) as l -> + let t'1 = f t1 and t'2 = f t2 in + if t'1 == t1 && t'2 == t2 then l else `App (t'1, t'2) + + method subst ~sub = function + #var as x -> var#subst ~sub x + | `Abs(s, t) as l -> + let used = !!free t in + let used_expr = + Subst.fold sub ~init:[] + ~f:(fun ~key ~data acc -> + if Names.mem s used then data::acc else acc) in + if List.exists used_expr ~f:(fun t -> Names.mem s (!!free t)) then + let name = s ^ string_of_int (next_id ()) in + `Abs(name, + !!subst ~sub:(Subst.add ~key:s ~data:(`Var name) sub) t) + else + self#map ~f:(!!subst ~sub:(Subst.remove s sub)) l + | `App _ as l -> + self#map ~f:(!!subst ~sub) l + + method eval l = + match self#map ~f:!!eval l with + `App(`Abs(s,t1), t2) -> + !!eval (!!subst ~sub:(Subst.add ~key:s ~data:t2 Subst.empty) t1) + | t -> t +end + +(* Operations specialized to lambda *) + +let lambda = lazy_fix (new lambda_ops) + +(* The expr language of arithmetic expressions *) + +type 'a expr = + [ `Var of string | `Num of int | `Add of 'a * 'a + | `Neg of 'a | `Mult of 'a * 'a] + +class ['a] expr_ops (ops : ('a,'a) #ops Lazy.t) = + let var : 'a var_ops = new var_ops + and free = lazy !!ops#free + and subst = lazy !!ops#subst + and eval = lazy !!ops#eval in + object (self : ('a, 'a expr) #ops) + constraint 'a = [> 'a expr] + method free = function + #var as x -> var#free x + | `Num _ -> Names.empty + | `Add(x, y) -> Names.union (!!free x) (!!free y) + | `Neg x -> !!free x + | `Mult(x, y) -> Names.union (!!free x) (!!free y) + + method map ~f = function + #var as x -> x + | `Num _ as x -> x + | `Add(x, y) as e -> + let x' = f x and y' = f y in + if x == x' && y == y' then e + else `Add(x', y') + | `Neg x as e -> + let x' = f x in + if x == x' then e else `Neg x' + | `Mult(x, y) as e -> + let x' = f x and y' = f y in + if x == x' && y == y' then e + else `Mult(x', y') + + method subst ~sub = function + #var as x -> var#subst ~sub x + | #expr as e -> self#map ~f:(!!subst ~sub) e + + method eval (#expr as e) = + match self#map ~f:!!eval e with + `Add(`Num m, `Num n) -> `Num (m+n) + | `Neg(`Num n) -> `Num (-n) + | `Mult(`Num m, `Num n) -> `Num (m*n) + | e -> e + end + +(* Specialized versions *) + +let expr = lazy_fix (new expr_ops) + +(* The lexpr language, reunion of lambda and expr *) + +type 'a lexpr = [ 'a lambda | 'a expr ] + +class ['a] lexpr_ops (ops : ('a,'a) #ops Lazy.t) = + let lambda = new lambda_ops ops in + let expr = new expr_ops ops in + object (self : ('a, 'a lexpr) #ops) + constraint 'a = [> 'a lexpr] + method free = function + #lambda as x -> lambda#free x + | #expr as x -> expr#free x + + method subst ~sub = function + #lambda as x -> lambda#subst ~sub x + | #expr as x -> expr#subst ~sub x + + method eval = function + #lambda as x -> lambda#eval x + | #expr as x -> expr#eval x +end + +let lexpr = lazy_fix (new lexpr_ops) + +(* A few examples: +lambda#eval (`App(`Abs("x",`Var"x"), `Var"y"));; +expr#eval (`Add(`Mult(`Num 3,`Neg(`Num 2)), `Var"x"));; +lexpr#eval (`Add(`App(`Abs("x",`Mult(`Var"x",`Var"x")),`Num 2), `Num 5));; +*) diff --git a/testlabl/mixin3.ml b/testlabl/mixin3.ml new file mode 100644 index 0000000..9276950 --- /dev/null +++ b/testlabl/mixin3.ml @@ -0,0 +1,173 @@ +(* $Id: mixin3.ml,v 1.1 2003-11-19 02:36:57 garrigue Exp $ *) + +(* Full fledge version, using objects to structure code *) + +open StdLabels +open MoreLabels + +(* Use maps for substitutions and sets for free variables *) + +module Subst = Map.Make(struct type t = string let compare = compare end) +module Names = Set.Make(struct type t = string let compare = compare end) + +(* To build recursive objects *) + +let lazy_fix make = + let rec obj () = make (lazy (obj ()) : _ Lazy.t) in + obj () + +let (!!) = Lazy.force + +(* The basic operations *) + +class type ['a, 'b] ops = + object + method free : 'b -> Names.t + method subst : sub:'a Subst.t -> 'b -> 'a + method eval : 'b -> 'a + end + +(* Variables are common to lambda and expr *) + +type var = [`Var of string] + +let var = object (self : ([>var], var) #ops) + method subst ~sub (`Var s as x) = + try Subst.find s sub with Not_found -> x + method free (`Var s) = + Names.singleton s + method eval (#var as v) = v +end + +(* The lambda language: free variables, substitutions, and evaluation *) + +type 'a lambda = [`Var of string | `Abs of string * 'a | `App of 'a * 'a] + +let next_id = + let current = ref 3 in + fun () -> incr current; !current + +let lambda_ops (ops : ('a,'a) #ops Lazy.t) = + let free = lazy !!ops#free + and subst = lazy !!ops#subst + and eval = lazy !!ops#eval in + object (self : ([> 'a lambda], 'a lambda) #ops) + method free = function + #var as x -> var#free x + | `Abs (s, t) -> Names.remove s (!!free t) + | `App (t1, t2) -> Names.union (!!free t1) (!!free t2) + + method private map ~f = function + #var as x -> x + | `Abs (s, t) as l -> + let t' = f t in + if t == t' then l else `Abs(s, t') + | `App (t1, t2) as l -> + let t'1 = f t1 and t'2 = f t2 in + if t'1 == t1 && t'2 == t2 then l else `App (t'1, t'2) + + method subst ~sub = function + #var as x -> var#subst ~sub x + | `Abs(s, t) as l -> + let used = !!free t in + let used_expr = + Subst.fold sub ~init:[] + ~f:(fun ~key ~data acc -> + if Names.mem s used then data::acc else acc) in + if List.exists used_expr ~f:(fun t -> Names.mem s (!!free t)) then + let name = s ^ string_of_int (next_id ()) in + `Abs(name, + !!subst ~sub:(Subst.add ~key:s ~data:(`Var name) sub) t) + else + self#map ~f:(!!subst ~sub:(Subst.remove s sub)) l + | `App _ as l -> + self#map ~f:(!!subst ~sub) l + + method eval l = + match self#map ~f:!!eval l with + `App(`Abs(s,t1), t2) -> + !!eval (!!subst ~sub:(Subst.add ~key:s ~data:t2 Subst.empty) t1) + | t -> t +end + +(* Operations specialized to lambda *) + +let lambda = lazy_fix lambda_ops + +(* The expr language of arithmetic expressions *) + +type 'a expr = + [ `Var of string | `Num of int | `Add of 'a * 'a + | `Neg of 'a | `Mult of 'a * 'a] + +let expr_ops (ops : ('a,'a) #ops Lazy.t) = + let free = lazy !!ops#free + and subst = lazy !!ops#subst + and eval = lazy !!ops#eval in + object (self : ([> 'a expr], 'a expr) #ops) + method free = function + #var as x -> var#free x + | `Num _ -> Names.empty + | `Add(x, y) -> Names.union (!!free x) (!!free y) + | `Neg x -> !!free x + | `Mult(x, y) -> Names.union (!!free x) (!!free y) + + method private map ~f = function + #var as x -> x + | `Num _ as x -> x + | `Add(x, y) as e -> + let x' = f x and y' = f y in + if x == x' && y == y' then e + else `Add(x', y') + | `Neg x as e -> + let x' = f x in + if x == x' then e else `Neg x' + | `Mult(x, y) as e -> + let x' = f x and y' = f y in + if x == x' && y == y' then e + else `Mult(x', y') + + method subst ~sub = function + #var as x -> var#subst ~sub x + | #expr as e -> self#map ~f:(!!subst ~sub) e + + method eval (#expr as e) = + match self#map ~f:!!eval e with + `Add(`Num m, `Num n) -> `Num (m+n) + | `Neg(`Num n) -> `Num (-n) + | `Mult(`Num m, `Num n) -> `Num (m*n) + | e -> e + end + +(* Specialized versions *) + +let expr = lazy_fix expr_ops + +(* The lexpr language, reunion of lambda and expr *) + +type 'a lexpr = [ 'a lambda | 'a expr ] + +let lexpr_ops (ops : ('a,'a) #ops Lazy.t) = + let lambda = lambda_ops ops in + let expr = expr_ops ops in + object (self : ([> 'a lexpr], 'a lexpr) #ops) + method free = function + #lambda as x -> lambda#free x + | #expr as x -> expr#free x + + method subst ~sub = function + #lambda as x -> lambda#subst ~sub x + | #expr as x -> expr#subst ~sub x + + method eval = function + #lambda as x -> lambda#eval x + | #expr as x -> expr#eval x +end + +let lexpr = lazy_fix lexpr_ops + +(* A few examples: +lambda#eval (`App(`Abs("x",`Var"x"), `Var"y"));; +expr#eval (`Add(`Mult(`Num 3,`Neg(`Num 2)), `Var"x"));; +lexpr#eval (`Add(`App(`Abs("x",`Mult(`Var"x",`Var"x")),`Num 2), `Num 5));; +*) diff --git a/testlabl/multimatch.diffs b/testlabl/multimatch.diffs new file mode 100644 index 0000000..6eb34b7 --- /dev/null +++ b/testlabl/multimatch.diffs @@ -0,0 +1,1418 @@ +Index: parsing/lexer.mll +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/lexer.mll,v +retrieving revision 1.73 +diff -u -r1.73 lexer.mll +--- parsing/lexer.mll 11 Apr 2005 16:44:26 -0000 1.73 ++++ parsing/lexer.mll 2 Feb 2006 06:28:32 -0000 +@@ -63,6 +63,8 @@ + "match", MATCH; + "method", METHOD; + "module", MODULE; ++ "multifun", MULTIFUN; ++ "multimatch", MULTIMATCH; + "mutable", MUTABLE; + "new", NEW; + "object", OBJECT; +Index: parsing/parser.mly +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/parser.mly,v +retrieving revision 1.123 +diff -u -r1.123 parser.mly +--- parsing/parser.mly 23 Mar 2005 03:08:37 -0000 1.123 ++++ parsing/parser.mly 2 Feb 2006 06:28:32 -0000 +@@ -257,6 +257,8 @@ + %token MINUSDOT + %token MINUSGREATER + %token MODULE ++%token MULTIFUN ++%token MULTIMATCH + %token MUTABLE + %token <nativeint> NATIVEINT + %token NEW +@@ -325,7 +327,7 @@ + %nonassoc SEMI /* below EQUAL ({lbl=...; lbl=...}) */ + %nonassoc LET /* above SEMI ( ...; let ... in ...) */ + %nonassoc below_WITH +-%nonassoc FUNCTION WITH /* below BAR (match ... with ...) */ ++%nonassoc FUNCTION WITH MULTIFUN /* below BAR (match ... with ...) */ + %nonassoc AND /* above WITH (module rec A: SIG with ... and ...) */ + %nonassoc THEN /* below ELSE (if ... then ...) */ + %nonassoc ELSE /* (if ... then ... else ...) */ +@@ -804,8 +806,12 @@ + { mkexp(Pexp_function("", None, List.rev $3)) } + | FUN labeled_simple_pattern fun_def + { let (l,o,p) = $2 in mkexp(Pexp_function(l, o, [p, $3])) } ++ | MULTIFUN opt_bar match_cases ++ { mkexp(Pexp_multifun(List.rev $3)) } + | MATCH seq_expr WITH opt_bar match_cases +- { mkexp(Pexp_match($2, List.rev $5)) } ++ { mkexp(Pexp_match($2, List.rev $5, false)) } ++ | MULTIMATCH seq_expr WITH opt_bar match_cases ++ { mkexp(Pexp_match($2, List.rev $5, true)) } + | TRY seq_expr WITH opt_bar match_cases + { mkexp(Pexp_try($2, List.rev $5)) } + | TRY seq_expr WITH error +@@ -1318,10 +1324,10 @@ + | simple_core_type2 { Rinherit $1 } + ; + tag_field: +- name_tag OF opt_ampersand amper_type_list +- { Rtag ($1, $3, List.rev $4) } +- | name_tag +- { Rtag ($1, true, []) } ++ name_tag OF opt_ampersand amper_type_list amper_type_pair_list ++ { Rtag ($1, $3, List.rev $4, $5) } ++ | name_tag amper_type_pair_list ++ { Rtag ($1, true, [], $2) } + ; + opt_ampersand: + AMPERSAND { true } +@@ -1331,6 +1337,11 @@ + core_type { [$1] } + | amper_type_list AMPERSAND core_type { $3 :: $1 } + ; ++amper_type_pair_list: ++ AMPERSAND core_type EQUAL core_type amper_type_pair_list ++ { ($2, $4) :: $5 } ++ | /* empty */ ++ { [] } + opt_present: + LBRACKETGREATER name_tag_list RBRACKET { List.rev $2 } + | /* empty */ { [] } +Index: parsing/parsetree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/parsetree.mli,v +retrieving revision 1.42 +diff -u -r1.42 parsetree.mli +--- parsing/parsetree.mli 23 Mar 2005 03:08:37 -0000 1.42 ++++ parsing/parsetree.mli 2 Feb 2006 06:28:32 -0000 +@@ -43,7 +43,7 @@ + | Pfield_var + + and row_field = +- Rtag of label * bool * core_type list ++ Rtag of label * bool * core_type list * (core_type * core_type) list + | Rinherit of core_type + + (* XXX Type expressions for the class language *) +@@ -86,7 +86,7 @@ + | Pexp_let of rec_flag * (pattern * expression) list * expression + | Pexp_function of label * expression option * (pattern * expression) list + | Pexp_apply of expression * (label * expression) list +- | Pexp_match of expression * (pattern * expression) list ++ | Pexp_match of expression * (pattern * expression) list * bool + | Pexp_try of expression * (pattern * expression) list + | Pexp_tuple of expression list + | Pexp_construct of Longident.t * expression option * bool +@@ -111,6 +111,7 @@ + | Pexp_lazy of expression + | Pexp_poly of expression * core_type option + | Pexp_object of class_structure ++ | Pexp_multifun of (pattern * expression) list + + (* Value descriptions *) + +Index: parsing/printast.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/printast.ml,v +retrieving revision 1.29 +diff -u -r1.29 printast.ml +--- parsing/printast.ml 4 Jan 2006 16:55:50 -0000 1.29 ++++ parsing/printast.ml 2 Feb 2006 06:28:32 -0000 +@@ -205,10 +205,14 @@ + line i ppf "Pexp_apply\n"; + expression i ppf e; + list i label_x_expression ppf l; +- | Pexp_match (e, l) -> ++ | Pexp_match (e, l, b) -> + line i ppf "Pexp_match\n"; + expression i ppf e; + list i pattern_x_expression_case ppf l; ++ bool i ppf b ++ | Pexp_multifun l -> ++ line i ppf "Pexp_multifun\n"; ++ list i pattern_x_expression_case ppf l; + | Pexp_try (e, l) -> + line i ppf "Pexp_try\n"; + expression i ppf e; +@@ -653,7 +657,7 @@ + + and label_x_bool_x_core_type_list i ppf x = + match x with +- Rtag (l, b, ctl) -> ++ Rtag (l, b, ctl, cstr) -> + line i ppf "Rtag \"%s\" %s\n" l (string_of_bool b); + list (i+1) core_type ppf ctl + | Rinherit (ct) -> +Index: typing/btype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/btype.ml,v +retrieving revision 1.38 +diff -u -r1.38 btype.ml +--- typing/btype.ml 4 Jan 2006 16:55:50 -0000 1.38 ++++ typing/btype.ml 2 Feb 2006 06:28:32 -0000 +@@ -66,16 +66,16 @@ + Clink r when !r <> Cunknown -> commu_repr !r + | c -> c + +-let rec row_field_repr_aux tl = function +- Reither(_, tl', _, {contents = Some fi}) -> +- row_field_repr_aux (tl@tl') fi +- | Reither(c, tl', m, r) -> +- Reither(c, tl@tl', m, r) ++let rec row_field_repr_aux tl tl2 = function ++ Reither(_, tl', _, tl2', {contents = Some fi}) -> ++ row_field_repr_aux (tl@tl') (tl2@tl2') fi ++ | Reither(c, tl', m, tl2', r) -> ++ Reither(c, tl@tl', m, tl2@tl2', r) + | Rpresent (Some _) when tl <> [] -> + Rpresent (Some (List.hd tl)) + | fi -> fi + +-let row_field_repr fi = row_field_repr_aux [] fi ++let row_field_repr fi = row_field_repr_aux [] [] fi + + let rec rev_concat l ll = + match ll with +@@ -170,7 +170,8 @@ + (fun (_, fi) -> + match row_field_repr fi with + | Rpresent(Some ty) -> f ty +- | Reither(_, tl, _, _) -> List.iter f tl ++ | Reither(_, tl, _, tl2, _) -> ++ List.iter f tl; List.iter (fun (t1,t2) -> f t1; f t2) tl2 + | _ -> ()) + row.row_fields; + match (repr row.row_more).desc with +@@ -208,15 +209,17 @@ + (fun (l, fi) -> l, + match row_field_repr fi with + | Rpresent(Some ty) -> Rpresent(Some(f ty)) +- | Reither(c, tl, m, e) -> ++ | Reither(c, tl, m, tpl, e) -> + let e = if keep then e else ref None in + let m = if row.row_fixed then fixed else m in + let tl = List.map f tl in ++ let tl1 = List.map (fun (t1,_) -> repr (f t1)) tpl ++ and tl2 = List.map (fun (_,t2) -> repr (f t2)) tpl in + bound := List.filter + (function {desc=Tconstr(_,[],_)} -> false | _ -> true) +- (List.map repr tl) ++ (List.map repr tl @ tl1 @ tl2) + @ !bound; +- Reither(c, tl, m, e) ++ Reither(c, tl, m, List.combine tl1 tl2, e) + | _ -> fi) + row.row_fields in + let name = +Index: typing/ctype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.ml,v +retrieving revision 1.200 +diff -u -r1.200 ctype.ml +--- typing/ctype.ml 6 Jan 2006 02:16:24 -0000 1.200 ++++ typing/ctype.ml 2 Feb 2006 06:28:32 -0000 +@@ -340,7 +340,7 @@ + let fi = filter_row_fields erase fi in + match row_field_repr f with + Rabsent -> fi +- | Reither(_,_,false,e) when erase -> set_row_field e Rabsent; fi ++ | Reither(_,_,false,_,e) when erase -> set_row_field e Rabsent; fi + | _ -> p :: fi + + (**************************************) +@@ -1286,6 +1286,10 @@ + + module TypeMap = Map.Make (TypeOps) + ++ ++(* A list of univars which may appear free in a type, but only if generic *) ++let allowed_univars = ref TypeSet.empty ++ + (* Test the occurence of free univars in a type *) + (* that's way too expansive. Must do some kind of cacheing *) + let occur_univar env ty = +@@ -1307,7 +1311,12 @@ + then + match ty.desc with + Tunivar -> +- if not (TypeSet.mem ty bound) then raise (Unify [ty, newgenvar()]) ++ if TypeSet.mem ty bound then () else ++ if TypeSet.mem ty !allowed_univars && ++ (ty.level = generic_level || ++ ty.level = pivot_level - generic_level) ++ then () ++ else raise (Unify [ty, newgenvar()]) + | Tpoly (ty, tyl) -> + let bound = List.fold_right TypeSet.add (List.map repr tyl) bound in + occur_rec bound ty +@@ -1393,6 +1402,7 @@ + with exn -> univar_pairs := old_univars; raise exn + + let univar_pairs = ref [] ++let delayed_conditionals = ref [] + + + (*****************) +@@ -1691,9 +1701,11 @@ + with Not_found -> (h,l)::hl) + (List.map (fun (l,_) -> (hash_variant l, l)) row1.row_fields) + (List.map fst r2)); ++ let fixed1 = row1.row_fixed || rm1.desc <> Tvar ++ and fixed2 = row2.row_fixed || rm2.desc <> Tvar in + let more = +- if row1.row_fixed then rm1 else +- if row2.row_fixed then rm2 else ++ if fixed1 then rm1 else ++ if fixed2 then rm2 else + newgenvar () + in update_level env (min rm1.level rm2.level) more; + let fixed = row1.row_fixed || row2.row_fixed +@@ -1726,18 +1738,18 @@ + let bound = row1.row_bound @ row2.row_bound in + let row0 = {row_fields = []; row_more = more; row_bound = bound; + row_closed = closed; row_fixed = fixed; row_name = name} in +- let set_more row rest = ++ let set_more row row_fixed rest = + let rest = + if closed then + filter_row_fields row.row_closed rest + else rest in +- if rest <> [] && (row.row_closed || row.row_fixed) +- || closed && row.row_fixed && not row.row_closed then begin ++ if rest <> [] && (row.row_closed || row_fixed) ++ || closed && row_fixed && not row.row_closed then begin + let t1 = mkvariant [] true and t2 = mkvariant rest false in + raise (Unify [if row == row1 then (t1,t2) else (t2,t1)]) + end; + let rm = row_more row in +- if row.row_fixed then ++ if row_fixed then + if row0.row_more == rm then () else + if rm.desc = Tvar then link_type rm row0.row_more else + unify env rm row0.row_more +@@ -1748,11 +1760,11 @@ + in + let md1 = rm1.desc and md2 = rm2.desc in + begin try +- set_more row1 r2; +- set_more row2 r1; ++ set_more row1 fixed1 r2; ++ set_more row2 fixed2 r1; + List.iter + (fun (l,f1,f2) -> +- try unify_row_field env row1.row_fixed row2.row_fixed l f1 f2 ++ try unify_row_field env fixed1 fixed2 row1 row2 l f1 f2 + with Unify trace -> + raise (Unify ((mkvariant [l,f1] true, + mkvariant [l,f2] true) :: trace))) +@@ -1761,13 +1773,13 @@ + log_type rm1; rm1.desc <- md1; log_type rm2; rm2.desc <- md2; raise exn + end + +-and unify_row_field env fixed1 fixed2 l f1 f2 = ++and unify_row_field env fixed1 fixed2 row1 row2 l f1 f2 = + let f1 = row_field_repr f1 and f2 = row_field_repr f2 in + if f1 == f2 then () else + match f1, f2 with + Rpresent(Some t1), Rpresent(Some t2) -> unify env t1 t2 + | Rpresent None, Rpresent None -> () +- | Reither(c1, tl1, m1, e1), Reither(c2, tl2, m2, e2) -> ++ | Reither(c1, tl1, m1, tp1, e1), Reither(c2, tl2, m2, tp2, e2) -> + if e1 == e2 then () else + let redo = + (m1 || m2) && +@@ -1777,32 +1789,70 @@ + List.iter (unify env t1) tl; + !e1 <> None || !e2 <> None + end in +- if redo then unify_row_field env fixed1 fixed2 l f1 f2 else ++ let redo = ++ redo || begin ++ if tp1 = [] && fixed1 then unify_pairs env tp2; ++ if tp2 = [] && fixed2 then unify_pairs env tp1; ++ !e1 <> None || !e2 <> None ++ end ++ in ++ if redo then unify_row_field env fixed1 fixed2 row1 row2 l f1 f2 else + let tl1 = List.map repr tl1 and tl2 = List.map repr tl2 in + let rec remq tl = function [] -> [] + | ty :: tl' -> + if List.memq ty tl then remq tl tl' else ty :: remq tl tl' + in + let tl2' = remq tl2 tl1 and tl1' = remq tl1 tl2 in ++ let repr_pairs = List.map (fun (t1,t2) -> repr t1, repr t2) in ++ let tp1 = repr_pairs tp1 and tp2 = repr_pairs tp2 in ++ let rec rempq tp = function [] -> [] ++ | (t1,t2 as p) :: tp' -> ++ if List.exists (fun (t1',t2') -> t1==t1' && t2==t2') (tp@tp') then ++ rempq tp tp' ++ else p :: rempq tp tp' ++ in ++ let tp1' = ++ if fixed2 then begin ++ delayed_conditionals := ++ (!univar_pairs, tp1, l, row2) :: !delayed_conditionals; ++ [] ++ end else rempq tp2 tp1 ++ and tp2' = ++ if fixed1 then begin ++ delayed_conditionals := ++ (!univar_pairs, tp2, l, row1) :: !delayed_conditionals; ++ [] ++ end else rempq tp1 tp2 ++ in + let e = ref None in +- let f1' = Reither(c1 || c2, tl1', m1 || m2, e) +- and f2' = Reither(c1 || c2, tl2', m1 || m2, e) in +- set_row_field e1 f1'; set_row_field e2 f2'; +- | Reither(_, _, false, e1), Rabsent -> set_row_field e1 f2 +- | Rabsent, Reither(_, _, false, e2) -> set_row_field e2 f1 ++ let f1' = Reither(c1 || c2, tl1', m1 || m2, tp2', e) ++ and f2' = Reither(c1 || c2, tl2', m1 || m2, tp1', e) in ++ set_row_field e1 f1'; set_row_field e2 f2' ++ | Reither(_, _, false, _, e1), Rabsent -> set_row_field e1 f2 ++ | Rabsent, Reither(_, _, false, _, e2) -> set_row_field e2 f1 + | Rabsent, Rabsent -> () +- | Reither(false, tl, _, e1), Rpresent(Some t2) when not fixed1 -> ++ | Reither(false, tl, _, tp, e1), Rpresent(Some t2) when not fixed1 -> + set_row_field e1 f2; +- (try List.iter (fun t1 -> unify env t1 t2) tl ++ begin try ++ List.iter (fun t1 -> unify env t1 t2) tl; ++ List.iter (fun (t1,t2) -> unify env t1 t2) tp ++ with exn -> e1 := None; raise exn ++ end ++ | Rpresent(Some t1), Reither(false, tl, _, tp, e2) when not fixed2 -> ++ set_row_field e2 f1; ++ begin try ++ List.iter (unify env t1) tl; ++ List.iter (fun (t1,t2) -> unify env t1 t2) tp ++ with exn -> e2 := None; raise exn ++ end ++ | Reither(true, [], _, tpl, e1), Rpresent None when not fixed1 -> ++ set_row_field e1 f2; ++ (try List.iter (fun (t1,t2) -> unify env t1 t2) tpl + with exn -> e1 := None; raise exn) +- | Rpresent(Some t1), Reither(false, tl, _, e2) when not fixed2 -> ++ | Rpresent None, Reither(true, [], _, tpl, e2) when not fixed2 -> + set_row_field e2 f1; +- (try List.iter (unify env t1) tl ++ (try List.iter (fun (t1,t2) -> unify env t1 t2) tpl + with exn -> e2 := None; raise exn) +- | Reither(true, [], _, e1), Rpresent None when not fixed1 -> +- set_row_field e1 f2 +- | Rpresent None, Reither(true, [], _, e2) when not fixed2 -> +- set_row_field e2 f1 + | _ -> raise (Unify []) + + +@@ -1920,6 +1970,166 @@ + (* Matching between type schemes *) + (***********************************) + ++(* Forward declaration (order should be reversed...) *) ++let equal' = ref (fun _ -> failwith "Ctype.equal'") ++ ++let make_generics_univars tyl = ++ let polyvars = ref TypeSet.empty in ++ let rec make_rec ty = ++ let ty = repr ty in ++ if ty.level = generic_level then begin ++ if ty.desc = Tvar then begin ++ log_type ty; ++ ty.desc <- Tunivar; ++ polyvars := TypeSet.add ty !polyvars ++ end ++ else if ty.desc = Tunivar then set_level ty (generic_level - 1); ++ ty.level <- pivot_level - generic_level; ++ iter_type_expr make_rec ty ++ end ++ in ++ List.iter make_rec tyl; ++ List.iter unmark_type tyl; ++ !polyvars ++ ++(* New version of moregeneral, using unification *) ++ ++let copy_cond (p,tpl,l,row) = ++ let row = ++ match repr (copy (newgenty (Tvariant row))) with ++ {desc=Tvariant row} -> row ++ | _ -> assert false ++ and pairs = ++ List.map (fun (t1,t2) -> copy t1, copy t2) tpl in ++ (p, pairs, l, row) ++ ++let get_row_field l row = ++ try row_field_repr (List.assoc l (row_repr row).row_fields) ++ with Not_found -> Rabsent ++ ++let rec check_conditional_list env cdtls pattvars tpls = ++ match cdtls with ++ [] -> ++ let finished = ++ List.for_all (fun (_,t1,t2) -> !equal' env false [t1] [t2]) tpls in ++ if not finished then begin ++ let polyvars = make_generics_univars pattvars in ++ delayed_conditionals := []; ++ allowed_univars := polyvars; ++ List.iter (fun (pairs, ty1, ty2) -> unify_pairs env ty1 ty2 pairs) ++ tpls; ++ check_conditionals env polyvars !delayed_conditionals ++ end ++ | (pairs, tpl1, l, row2 as cond) :: cdtls -> ++ let cont = check_conditional_list env cdtls pattvars in ++ let tpl1 = ++ List.filter (fun (t1,t2) -> not (!equal' env false [t1] [t2])) tpl1 in ++ let included = ++ List.for_all ++ (fun (t1,t2) -> ++ List.exists ++ (fun (_,t1',t2') -> !equal' env false [t1;t2] [t1';t2']) ++ tpls) ++ tpl1 in ++ if included then cont tpls else ++ match get_row_field l row2 with ++ Rpresent _ -> ++ cont (List.map (fun (t1,t2) -> (pairs,t1,t2)) tpl1 @ tpls) ++ | Rabsent -> cont tpls ++ | Reither (c, tl2, _, _, _) -> ++ cont tpls; ++ if c && tl2 <> [] then () (* cannot succeed *) else ++ let (pairs, tpl1, l, row2) = copy_cond cond ++ and tpls = List.map (fun (p,t1,t2) -> p, copy t1, copy t2) tpls ++ and pattvars = List.map copy pattvars ++ and cdtls = List.map copy_cond cdtls in ++ cleanup_types (); ++ let tl2, tpl2, e2 = ++ match get_row_field l row2 with ++ Reither (c, tl2, _, tpl2, e2) -> tl2, tpl2, e2 ++ | _ -> assert false ++ in ++ let snap = Btype.snapshot () in ++ let ok = ++ try ++ begin match tl2 with ++ [] -> ++ set_row_field e2 (Rpresent None) ++ | t::tl -> ++ set_row_field e2 (Rpresent (Some t)); ++ List.iter (unify env t) tl ++ end; ++ List.iter (fun (t1,t2) -> unify_pairs env t1 t2 pairs) tpl2; ++ true ++ with exn -> ++ Btype.backtrack snap; ++ false ++ in ++ (* This is not [cont] : types have been copied *) ++ if ok then ++ check_conditional_list env cdtls pattvars ++ (List.map (fun (t1,t2) -> (pairs,t1,t2)) tpl1 @ tpls) ++ ++and check_conditionals env polyvars cdtls = ++ let cdtls = List.map copy_cond cdtls in ++ let pattvars = ref [] in ++ TypeSet.iter ++ (fun ty -> ++ let ty = repr ty in ++ match ty.desc with ++ Tsubst ty -> ++ let ty = repr ty in ++ begin match ty.desc with ++ Tunivar -> ++ log_type ty; ++ ty.desc <- Tvar; ++ pattvars := ty :: !pattvars ++ | Ttuple [tv;_] -> ++ if tv.desc = Tunivar then ++ (log_type tv; tv.desc <- Tvar; pattvars := ty :: !pattvars) ++ else if tv.desc <> Tvar then assert false ++ | Tvar -> () ++ | _ -> assert false ++ end ++ | _ -> ()) ++ polyvars; ++ cleanup_types (); ++ check_conditional_list env cdtls !pattvars [] ++ ++ ++(* Must empty univar_pairs first *) ++let unify_poly env polyvars subj patt = ++ let old_level = !current_level in ++ current_level := generic_level; ++ delayed_conditionals := []; ++ allowed_univars := polyvars; ++ try ++ unify env subj patt; ++ check_conditionals env polyvars !delayed_conditionals; ++ current_level := old_level; ++ allowed_univars := TypeSet.empty; ++ delayed_conditionals := [] ++ with exn -> ++ current_level := old_level; ++ allowed_univars := TypeSet.empty; ++ delayed_conditionals := []; ++ raise exn ++ ++let moregeneral env _ subj patt = ++ let old_level = !current_level in ++ current_level := generic_level; ++ let subj = instance subj ++ and patt = instance patt in ++ let polyvars = make_generics_univars [patt] in ++ current_level := old_level; ++ let snap = Btype.snapshot () in ++ try ++ unify_poly env polyvars subj patt; ++ true ++ with Unify _ -> ++ Btype.backtrack snap; ++ false ++ + (* + Update the level of [ty]. First check that the levels of generic + variables from the subject are not lowered. +@@ -2072,35 +2282,101 @@ + Rpresent(Some t1), Rpresent(Some t2) -> + moregen inst_nongen type_pairs env t1 t2 + | Rpresent None, Rpresent None -> () +- | Reither(false, tl1, _, e1), Rpresent(Some t2) when not univ -> ++ | Reither(false, tl1, _, [], e1), Rpresent(Some t2) when not univ -> + set_row_field e1 f2; + List.iter (fun t1 -> moregen inst_nongen type_pairs env t1 t2) tl1 +- | Reither(c1, tl1, _, e1), Reither(c2, tl2, m2, e2) -> ++ | Reither(c1, tl1, _, tpl1, e1), Reither(c2, tl2, m2, tpl2, e2) -> + if e1 != e2 then begin + if c1 && not c2 then raise(Unify []); +- set_row_field e1 (Reither (c2, [], m2, e2)); +- if List.length tl1 = List.length tl2 then +- List.iter2 (moregen inst_nongen type_pairs env) tl1 tl2 +- else match tl2 with +- t2 :: _ -> ++ let tpl' = if tpl1 = [] then tpl2 else [] in ++ set_row_field e1 (Reither (c2, [], m2, tpl', e2)); ++ begin match tl2 with ++ [t2] -> + List.iter (fun t1 -> moregen inst_nongen type_pairs env t1 t2) + tl1 +- | [] -> +- if tl1 <> [] then raise (Unify []) ++ | _ -> ++ if List.length tl1 <> List.length tl2 then raise (Unify []); ++ List.iter2 (moregen inst_nongen type_pairs env) tl1 tl2 ++ end; ++ if tpl1 <> [] then ++ delayed_conditionals := ++ (!univar_pairs, tpl1, l, row2) :: !delayed_conditionals + end +- | Reither(true, [], _, e1), Rpresent None when not univ -> ++ | Reither(true, [], _, [], e1), Rpresent None when not univ -> + set_row_field e1 f2 +- | Reither(_, _, _, e1), Rabsent when not univ -> ++ | Reither(_, _, _, [], e1), Rabsent when not univ -> + set_row_field e1 f2 + | Rabsent, Rabsent -> () + | _ -> raise (Unify [])) + pairs + ++let check_conditional env (pairs, tpl1, l, row2) tpls cont = ++ let tpl1 = ++ List.filter (fun (t1,t2) -> not (!equal' env false [t1] [t2])) tpl1 in ++ let included = ++ List.for_all ++ (fun (t1,t2) -> ++ List.exists (fun (t1',t2') -> !equal' env false [t1;t2] [t1';t2']) ++ tpls) ++ tpl1 in ++ if tpl1 = [] || included then cont tpls else ++ match get_row_field l row2 with ++ Rpresent _ -> cont (tpl1 @ tpls) ++ | Rabsent -> cont tpls ++ | Reither (c, tl2, _, tpl2, e2) -> ++ if not c || tl2 = [] then begin ++ let snap = Btype.snapshot () in ++ let ok = ++ try ++ begin match tl2 with ++ [] -> ++ set_row_field e2 (Rpresent None) ++ | t::tl -> ++ set_row_field e2 (Rpresent (Some t)); ++ List.iter (unify env t) tl ++ end; ++ List.iter (fun (t1,t2) -> unify_pairs env t1 t2 pairs) tpl2; ++ true ++ with Unify _ -> false ++ in ++ if ok then cont (tpl1 @ tpls); ++ Btype.backtrack snap ++ end; ++ cont tpls ++ ++let rec check_conditionals inst_nongen env cdtls tpls = ++ match cdtls with ++ [] -> ++ let tpls = ++ List.filter (fun (t1,t2) -> not (!equal' env false [t1] [t2])) tpls in ++ if tpls = [] then () else begin ++ delayed_conditionals := []; ++ let tl1, tl2 = List.split tpls in ++ let type_pairs = TypePairs.create 13 in ++ List.iter2 (moregen false type_pairs env) tl2 tl1; ++ check_conditionals inst_nongen env !delayed_conditionals [] ++ end ++ | cdtl :: cdtls -> ++ check_conditional env cdtl tpls ++ (check_conditionals inst_nongen env cdtls) ++ ++ + (* Must empty univar_pairs first *) + let moregen inst_nongen type_pairs env patt subj = + univar_pairs := []; +- moregen inst_nongen type_pairs env patt subj ++ delayed_conditionals := []; ++ try ++ moregen inst_nongen type_pairs env patt subj; ++ check_conditionals inst_nongen env !delayed_conditionals []; ++ univar_pairs := []; ++ delayed_conditionals := [] ++ with exn -> ++ univar_pairs := []; ++ delayed_conditionals := []; ++ raise exn ++ + ++(* old implementation + (* + Non-generic variable can be instanciated only if [inst_nongen] is + true. So, [inst_nongen] should be set to false if the subject might +@@ -2128,6 +2404,7 @@ + in + current_level := old_level; + res ++*) + + + (* Alternative approach: "rigidify" a type scheme, +@@ -2296,30 +2573,36 @@ + {desc=Tvariant row2} -> eqtype_row rename type_pairs subst env row1 row2 + | _ -> raise Cannot_expand + with Cannot_expand -> ++ let eqtype_rec = eqtype rename type_pairs subst env in + let row1 = row_repr row1 and row2 = row_repr row2 in + let r1, r2, pairs = merge_row_fields row1.row_fields row2.row_fields in + if row1.row_closed <> row2.row_closed + || not row1.row_closed && (r1 <> [] || r2 <> []) + || filter_row_fields false (r1 @ r2) <> [] + then raise (Unify []); +- if not (static_row row1) then +- eqtype rename type_pairs subst env row1.row_more row2.row_more; ++ if not (static_row row1) then eqtype_rec row1.row_more row2.row_more; + List.iter + (fun (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent(Some t1), Rpresent(Some t2) -> +- eqtype rename type_pairs subst env t1 t2 +- | Reither(true, [], _, _), Reither(true, [], _, _) -> +- () +- | Reither(false, t1::tl1, _, _), Reither(false, t2::tl2, _, _) -> +- eqtype rename type_pairs subst env t1 t2; ++ eqtype_rec t1 t2 ++ | Reither(true, [], _, tp1, _), Reither(true, [], _, tp2, _) -> ++ List.iter2 ++ (fun (t1,t1') (t2,t2') -> eqtype_rec t1 t2; eqtype_rec t1' t2') ++ tp1 tp2 ++ | Reither(false, t1::tl1, _, tpl1, _), ++ Reither(false, t2::tl2, _, tpl2, _) -> ++ eqtype_rec t1 t2; ++ List.iter2 ++ (fun (t1,t1') (t2,t2') -> eqtype_rec t1 t2; eqtype_rec t1' t2') ++ tpl1 tpl2; + if List.length tl1 = List.length tl2 then + (* if same length allow different types (meaning?) *) +- List.iter2 (eqtype rename type_pairs subst env) tl1 tl2 ++ List.iter2 eqtype_rec tl1 tl2 + else begin + (* otherwise everything must be equal *) +- List.iter (eqtype rename type_pairs subst env t1) tl2; +- List.iter (fun t1 -> eqtype rename type_pairs subst env t1 t2) tl1 ++ List.iter (eqtype_rec t1) tl2; ++ List.iter (fun t1 -> eqtype_rec t1 t2) tl1 + end + | Rpresent None, Rpresent None -> () + | Rabsent, Rabsent -> () +@@ -2334,6 +2617,8 @@ + with + Unify _ -> false + ++let () = equal' := equal ++ + (* Must empty univar_pairs first *) + let eqtype rename type_pairs subst env t1 t2 = + univar_pairs := []; +@@ -2770,14 +3055,14 @@ + (fun (l,f as orig) -> match row_field_repr f with + Rpresent None -> + if posi then +- (l, Reither(true, [], false, ref None)), Unchanged ++ (l, Reither(true, [], false, [], ref None)), Unchanged + else + orig, Unchanged + | Rpresent(Some t) -> + let (t', c) = build_subtype env visited loops posi level' t in + if posi && level > 0 then begin + bound := t' :: !bound; +- (l, Reither(false, [t'], false, ref None)), c ++ (l, Reither(false, [t'], false, [], ref None)), c + end else + (l, Rpresent(Some t')), c + | _ -> assert false) +@@ -2960,11 +3245,11 @@ + List.fold_left + (fun cstrs (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with +- (Rpresent None|Reither(true,_,_,_)), Rpresent None -> ++ (Rpresent None|Reither(true,_,_,[],_)), Rpresent None -> + cstrs + | Rpresent(Some t1), Rpresent(Some t2) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs +- | Reither(false, t1::_, _, _), Rpresent(Some t2) -> ++ | Reither(false, t1::_, _, [], _), Rpresent(Some t2) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + | Rabsent, _ -> cstrs + | _ -> raise Exit) +@@ -2977,11 +3262,11 @@ + (fun cstrs (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent None, Rpresent None +- | Reither(true,[],_,_), Reither(true,[],_,_) ++ | Reither(true,[],_,[],_), Reither(true,[],_,[],_) + | Rabsent, Rabsent -> + cstrs + | Rpresent(Some t1), Rpresent(Some t2) +- | Reither(false,[t1],_,_), Reither(false,[t2],_,_) -> ++ | Reither(false,[t1],_,[],_), Reither(false,[t2],_,[],_) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + | _ -> raise Exit) + cstrs pairs +@@ -3079,16 +3364,26 @@ + let fields = List.map + (fun (l,f) -> + let f = row_field_repr f in l, +- match f with Reither(b, ty::(_::_ as tyl), m, e) -> +- let tyl' = +- List.fold_left +- (fun tyl ty -> +- if List.exists (fun ty' -> equal env false [ty] [ty']) tyl +- then tyl else ty::tyl) +- [ty] tyl ++ match f with Reither(b, tyl, m, tp, e) -> ++ let rem_dbl eq l = ++ List.rev ++ (List.fold_left ++ (fun xs x -> if List.exists (eq x) xs then xs else x::xs) ++ [] l) ++ in ++ let tyl' = rem_dbl (fun t1 t2 -> equal env false [t1] [t2]) tyl ++ and tp' = ++ List.filter ++ (fun (ty1,ty2) -> not (equal env false [ty1] [ty2])) tp ++ in ++ let tp' = ++ rem_dbl ++ (fun (t1,t2) (t1',t2') -> equal env false [t1;t2] [t1';t2']) ++ tp' + in +- if List.length tyl' <= List.length tyl then +- let f = Reither(b, List.rev tyl', m, ref None) in ++ if List.length tyl' < List.length tyl ++ || List.length tp' < List.length tp then ++ let f = Reither(b, tyl', m, tp', ref None) in + set_row_field e f; + f + else f +@@ -3344,9 +3639,9 @@ + List.iter + (fun (l,fi) -> + match row_field_repr fi with +- Reither (c, t1::(_::_ as tl), m, e) -> ++ Reither (c, t1::(_::_ as tl), m, tp, e) -> + List.iter (unify env t1) tl; +- set_row_field e (Reither (c, [t1], m, ref None)) ++ set_row_field e (Reither (c, [t1], m, tp, ref None)) + | _ -> + ()) + row.row_fields; +Index: typing/includecore.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/includecore.ml,v +retrieving revision 1.32 +diff -u -r1.32 includecore.ml +--- typing/includecore.ml 8 Aug 2005 05:40:52 -0000 1.32 ++++ typing/includecore.ml 2 Feb 2006 06:28:32 -0000 +@@ -71,10 +71,10 @@ + (fun (_, f1, f2) -> + match Btype.row_field_repr f1, Btype.row_field_repr f2 with + Rpresent(Some t1), +- (Rpresent(Some t2) | Reither(false, [t2], _, _)) -> ++ (Rpresent(Some t2) | Reither(false,[t2],_,[],_)) -> + to_equal := (t1,t2) :: !to_equal; true +- | Rpresent None, (Rpresent None | Reither(true, [], _, _)) -> true +- | Reither(c1,tl1,_,_), Reither(c2,tl2,_,_) ++ | Rpresent None, (Rpresent None | Reither(true,[],_,[],_)) -> true ++ | Reither(c1,tl1,_,[],_), Reither(c2,tl2,_,[],_) + when List.length tl1 = List.length tl2 && c1 = c2 -> + to_equal := List.combine tl1 tl2 @ !to_equal; true + | Rabsent, (Reither _ | Rabsent) -> true +Index: typing/oprint.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/oprint.ml,v +retrieving revision 1.22 +diff -u -r1.22 oprint.ml +--- typing/oprint.ml 23 Mar 2005 03:08:37 -0000 1.22 ++++ typing/oprint.ml 2 Feb 2006 06:28:33 -0000 +@@ -223,14 +223,18 @@ + print_fields rest ppf [] + | (s, t) :: l -> + fprintf ppf "%s : %a;@ %a" s print_out_type t (print_fields rest) l +-and print_row_field ppf (l, opt_amp, tyl) = ++and print_row_field ppf (l, opt_amp, tyl, tpl) = + let pr_of ppf = + if opt_amp then fprintf ppf " of@ &@ " + else if tyl <> [] then fprintf ppf " of@ " +- else fprintf ppf "" +- in +- fprintf ppf "@[<hv 2>`%s%t%a@]" l pr_of (print_typlist print_out_type " &") +- tyl ++ and pr_tp ppf (t1,t2) = ++ fprintf ppf "@[<hv 2>%a =@ %a@]" ++ print_out_type t1 ++ print_out_type t2 ++ in ++ fprintf ppf "@[<hv 2>`%s%t%a%a@]" l pr_of ++ (print_typlist print_out_type " &") tyl ++ (print_list_init pr_tp (fun ppf -> fprintf ppf " &@ ")) tpl + and print_typlist print_elem sep ppf = + function + [] -> () +Index: typing/outcometree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/outcometree.mli,v +retrieving revision 1.14 +diff -u -r1.14 outcometree.mli +--- typing/outcometree.mli 23 Mar 2005 03:08:37 -0000 1.14 ++++ typing/outcometree.mli 2 Feb 2006 06:28:33 -0000 +@@ -61,7 +61,8 @@ + bool * out_variant * bool * (string list) option + | Otyp_poly of string list * out_type + and out_variant = +- | Ovar_fields of (string * bool * out_type list) list ++ | Ovar_fields of ++ (string * bool * out_type list * (out_type * out_type) list ) list + | Ovar_name of out_ident * out_type list + + type out_class_type = +Index: typing/parmatch.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/parmatch.ml,v +retrieving revision 1.70 +diff -u -r1.70 parmatch.ml +--- typing/parmatch.ml 24 Mar 2005 17:20:54 -0000 1.70 ++++ typing/parmatch.ml 2 Feb 2006 06:28:33 -0000 +@@ -568,11 +568,11 @@ + List.fold_left + (fun nm (tag,f) -> + match Btype.row_field_repr f with +- | Reither(_, _, false, e) -> ++ | Reither(_, _, false, _, e) -> + (* m=false means that this tag is not explicitly matched *) + Btype.set_row_field e Rabsent; + None +- | Rabsent | Reither (_, _, true, _) | Rpresent _ -> nm) ++ | Rabsent | Reither (_, _, true, _, _) | Rpresent _ -> nm) + row.row_name row.row_fields in + if not row.row_closed || nm != row.row_name then begin + (* this unification cannot fail *) +@@ -605,8 +605,8 @@ + List.for_all + (fun (tag,f) -> + match Btype.row_field_repr f with +- Rabsent | Reither(_, _, false, _) -> true +- | Reither (_, _, true, _) ++ Rabsent | Reither(_, _, false, _, _) -> true ++ | Reither (_, _, true, _, _) + (* m=true, do not discard matched tags, rather warn *) + | Rpresent _ -> List.mem tag fields) + row.row_fields +@@ -739,7 +739,7 @@ + match Btype.row_field_repr f with + Rabsent (* | Reither _ *) -> others + (* This one is called after erasing pattern info *) +- | Reither (c, _, _, _) -> make_other_pat tag c :: others ++ | Reither (c, _, _, _, _) -> make_other_pat tag c :: others + | Rpresent arg -> make_other_pat tag (arg = None) :: others) + [] row.row_fields + with +Index: typing/printtyp.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/printtyp.ml,v +retrieving revision 1.140 +diff -u -r1.140 printtyp.ml +--- typing/printtyp.ml 4 Jan 2006 16:55:50 -0000 1.140 ++++ typing/printtyp.ml 2 Feb 2006 06:28:33 -0000 +@@ -157,9 +157,12 @@ + and raw_field ppf = function + Rpresent None -> fprintf ppf "Rpresent None" + | Rpresent (Some t) -> fprintf ppf "@[<1>Rpresent(Some@,%a)@]" raw_type t +- | Reither (c,tl,m,e) -> +- fprintf ppf "@[<hov1>Reither(%b,@,%a,@,%b,@,@[<1>ref%t@])@]" c +- raw_type_list tl m ++ | Reither (c,tl,m,tpl,e) -> ++ fprintf ppf "@[<hov1>Reither(%b,@,%a,@,%b,@,%a,@,@[<1>ref%t@])@]" ++ c raw_type_list tl m ++ (raw_list ++ (fun ppf (t1,t2) -> ++ fprintf ppf "@[%a,@,%a@]" raw_type t1 raw_type t2)) tpl + (fun ppf -> + match !e with None -> fprintf ppf " None" + | Some f -> fprintf ppf "@,@[<1>(%a)@]" raw_field f) +@@ -219,8 +222,9 @@ + List.for_all + (fun (_, f) -> + match row_field_repr f with +- | Reither(c, l, _, _) -> +- row.row_closed && if c then l = [] else List.length l = 1 ++ | Reither(c, l, _, pl, _) -> ++ row.row_closed && pl = [] && ++ if c then l = [] else List.length l = 1 + | _ -> true) + row.row_fields + +@@ -392,13 +396,16 @@ + + and tree_of_row_field sch (l, f) = + match row_field_repr f with +- | Rpresent None | Reither(true, [], _, _) -> (l, false, []) +- | Rpresent(Some ty) -> (l, false, [tree_of_typexp sch ty]) +- | Reither(c, tyl, _, _) -> +- if c (* contradiction: un constructeur constant qui a un argument *) +- then (l, true, tree_of_typlist sch tyl) +- else (l, false, tree_of_typlist sch tyl) +- | Rabsent -> (l, false, [] (* une erreur, en fait *)) ++ | Rpresent None | Reither(true, [], _, [], _) -> (l, false, [], []) ++ | Rpresent(Some ty) -> (l, false, [tree_of_typexp sch ty], []) ++ | Reither(c, tyl, _, tpl, _) -> ++ let ttpl = ++ List.map ++ (fun (t1,t2) -> tree_of_typexp sch t1, tree_of_typexp sch t2) ++ tpl ++ in ++ (l, c && tpl = [], tree_of_typlist sch tyl, ttpl) ++ | Rabsent -> (l, false, [], [] (* une erreur, en fait *)) + + and tree_of_typlist sch tyl = + List.map (tree_of_typexp sch) tyl +Index: typing/typeclass.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typeclass.ml,v +retrieving revision 1.85 +diff -u -r1.85 typeclass.ml +--- typing/typeclass.ml 22 Jul 2005 06:42:36 -0000 1.85 ++++ typing/typeclass.ml 2 Feb 2006 06:28:33 -0000 +@@ -727,7 +727,7 @@ + {pexp_loc = loc; pexp_desc = + Pexp_match({pexp_loc = loc; pexp_desc = + Pexp_ident(Longident.Lident"*opt*")}, +- scases)} in ++ scases, false)} in + let sfun = + {pcl_loc = scl.pcl_loc; pcl_desc = + Pcl_fun(l, None, {ppat_loc = loc; ppat_desc = Ppat_var"*opt*"}, +Index: typing/typecore.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typecore.ml,v +retrieving revision 1.178 +diff -u -r1.178 typecore.ml +--- typing/typecore.ml 6 Jan 2006 02:25:37 -0000 1.178 ++++ typing/typecore.ml 2 Feb 2006 06:28:33 -0000 +@@ -156,15 +156,21 @@ + let field = row_field tag row in + begin match field with + | Rabsent -> assert false +- | Reither (true, [], _, e) when not row.row_closed -> +- set_row_field e (Rpresent None) +- | Reither (false, ty::tl, _, e) when not row.row_closed -> ++ | Reither (true, [], _, tpl, e) when not row.row_closed -> ++ set_row_field e (Rpresent None); ++ List.iter ++ (fun (t1,t2) -> unify_pat pat.pat_env {pat with pat_type=t1} t2) ++ tpl ++ | Reither (false, ty::tl, _, tpl, e) when not row.row_closed -> + set_row_field e (Rpresent (Some ty)); ++ List.iter ++ (fun (t1,t2) -> unify_pat pat.pat_env {pat with pat_type=t1} t2) ++ tpl; + begin match opat with None -> assert false + | Some pat -> List.iter (unify_pat pat.pat_env pat) (ty::tl) + end +- | Reither (c, l, true, e) when not row.row_fixed -> +- set_row_field e (Reither (c, [], false, ref None)) ++ | Reither (c, l, true, tpl, e) when not row.row_fixed -> ++ set_row_field e (Reither (c, [], false, [], ref None)) + | _ -> () + end; + (* Force check of well-formedness *) +@@ -307,13 +313,13 @@ + match row_field_repr f with + Rpresent None -> + (l,None) :: pats, +- (l, Reither(true,[], true, ref None)) :: fields ++ (l, Reither(true,[], true, [], ref None)) :: fields + | Rpresent (Some ty) -> + bound := ty :: !bound; + (l, Some {pat_desc=Tpat_any; pat_loc=Location.none; pat_env=env; + pat_type=ty}) + :: pats, +- (l, Reither(false, [ty], true, ref None)) :: fields ++ (l, Reither(false, [ty], true, [], ref None)) :: fields + | _ -> pats, fields) + ([],[]) fields in + let row = +@@ -337,6 +343,18 @@ + pat pats in + rp { r with pat_loc = loc } + ++let rec flatten_or_pat pat = ++ match pat.pat_desc with ++ Tpat_or (p1, p2, _) -> ++ flatten_or_pat p1 @ flatten_or_pat p2 ++ | _ -> ++ [pat] ++ ++let all_variants pat = ++ List.for_all ++ (function {pat_desc=Tpat_variant _} -> true | _ -> false) ++ (flatten_or_pat pat) ++ + let rec find_record_qual = function + | [] -> None + | (Longident.Ldot (modname, _), _) :: _ -> Some modname +@@ -423,7 +441,7 @@ + let arg = may_map (type_pat env) sarg in + let arg_type = match arg with None -> [] | Some arg -> [arg.pat_type] in + let row = { row_fields = +- [l, Reither(arg = None, arg_type, true, ref None)]; ++ [l, Reither(arg = None, arg_type, true, [], ref None)]; + row_bound = arg_type; + row_closed = false; + row_more = newvar (); +@@ -788,7 +806,7 @@ + newty (Tarrow(p, type_option (newvar ()), type_approx env e, Cok)) + | Pexp_function (p,_,(_,e)::_) -> + newty (Tarrow(p, newvar (), type_approx env e, Cok)) +- | Pexp_match (_, (_,e)::_) -> type_approx env e ++ | Pexp_match (_, (_,e)::_, false) -> type_approx env e + | Pexp_try (e, _) -> type_approx env e + | Pexp_tuple l -> newty (Ttuple(List.map (type_approx env) l)) + | Pexp_ifthenelse (_,e,_) -> type_approx env e +@@ -939,17 +957,26 @@ + exp_loc = sexp.pexp_loc; + exp_type = ty_res; + exp_env = env } +- | Pexp_match(sarg, caselist) -> ++ | Pexp_match(sarg, caselist, multi) -> + let arg = type_exp env sarg in + let ty_res = newvar() in + let cases, partial = +- type_cases env arg.exp_type ty_res (Some sexp.pexp_loc) caselist ++ type_cases env arg.exp_type ty_res (Some sexp.pexp_loc) caselist ~multi + in + re { + exp_desc = Texp_match(arg, cases, partial); + exp_loc = sexp.pexp_loc; + exp_type = ty_res; + exp_env = env } ++ | Pexp_multifun caselist -> ++ let ty_arg = newvar() and ty_res = newvar() in ++ let cases, partial = ++ type_cases env ty_arg ty_res (Some sexp.pexp_loc) caselist ~multi:true ++ in ++ { exp_desc = Texp_function (cases, partial); ++ exp_loc = sexp.pexp_loc; ++ exp_type = newty (Tarrow ("", ty_arg, ty_res, Cok)); ++ exp_env = env } + | Pexp_try(sbody, caselist) -> + let body = type_exp env sbody in + let cases, _ = +@@ -1758,7 +1785,7 @@ + {pexp_loc = loc; pexp_desc = + Pexp_match({pexp_loc = loc; pexp_desc = + Pexp_ident(Longident.Lident"*opt*")}, +- scases)} in ++ scases, false)} in + let sfun = + {pexp_loc = sexp.pexp_loc; pexp_desc = + Pexp_function(l, None,[{ppat_loc = loc; ppat_desc = Ppat_var"*opt*"}, +@@ -1864,7 +1891,8 @@ + + (* Typing of match cases *) + +-and type_cases ?in_function env ty_arg ty_res partial_loc caselist = ++and type_cases ?in_function ?(multi=false) ++ env ty_arg ty_res partial_loc caselist = + let ty_arg' = newvar () in + let pattern_force = ref [] in + let pat_env_list = +@@ -1898,10 +1926,64 @@ + let cases = + List.map2 + (fun (pat, ext_env) (spat, sexp) -> +- let exp = type_expect ?in_function ext_env sexp ty_res in +- (pat, exp)) +- pat_env_list caselist +- in ++ let add_variant_case lab row ty_res ty_res' = ++ let fi = List.assoc lab (row_repr row).row_fields in ++ begin match row_field_repr fi with ++ Reither (c, _, m, _, e) -> ++ let row' = ++ { row_fields = ++ [lab, Reither(c,[],false,[ty_res,ty_res'], ref None)]; ++ row_more = newvar (); row_bound = [ty_res; ty_res']; ++ row_closed = false; row_fixed = false; row_name = None } ++ in ++ unify_pat ext_env {pat with pat_type= newty (Tvariant row)} ++ (newty (Tvariant row')) ++ | _ -> ++ unify_exp ext_env ++ { exp_desc = Texp_tuple []; exp_type = ty_res; ++ exp_env = ext_env; exp_loc = sexp.pexp_loc } ++ ty_res' ++ end ++ in ++ pat, ++ match pat.pat_desc with ++ _ when multi && all_variants pat -> ++ let ty_res' = newvar () in ++ List.iter ++ (function {pat_desc=Tpat_variant(lab,_,row)} -> ++ add_variant_case lab row ty_res ty_res' ++ | _ -> assert false) ++ (flatten_or_pat pat); ++ type_expect ?in_function ext_env sexp ty_res' ++ | Tpat_alias (p, id) when multi && all_variants p -> ++ let vd = Env.find_value (Path.Pident id) ext_env in ++ let row' = ++ match repr vd.val_type with ++ {desc=Tvariant row'} -> row' ++ | _ -> assert false ++ in ++ begin_def (); ++ let tv = newvar () in ++ let env = Env.add_value id {vd with val_type=tv} ext_env in ++ let exp = type_exp env sexp in ++ end_def (); ++ generalize exp.exp_type; ++ generalize tv; ++ List.iter ++ (function {pat_desc=Tpat_variant(lab,_,row)}, [tv'; ty'] -> ++ let fi' = List.assoc lab (row_repr row').row_fields in ++ let row' = ++ {row' with row_fields=[lab,fi']; row_more=newvar()} in ++ unify_pat ext_env {pat with pat_type=tv'} ++ (newty (Tvariant row')); ++ add_variant_case lab row ty_res ty' ++ | _ -> assert false) ++ (List.map (fun p -> p, instance_list [tv; exp.exp_type]) ++ (flatten_or_pat p)); ++ {exp with exp_type = instance exp.exp_type} ++ | _ -> ++ type_expect ?in_function ext_env sexp ty_res) ++ pat_env_list caselist in + let partial = + match partial_loc with None -> Partial + | Some loc -> Parmatch.check_partial loc cases +Index: typing/typedecl.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typedecl.ml,v +retrieving revision 1.75 +diff -u -r1.75 typedecl.ml +--- typing/typedecl.ml 16 Aug 2005 00:48:56 -0000 1.75 ++++ typing/typedecl.ml 2 Feb 2006 06:28:33 -0000 +@@ -432,8 +432,10 @@ + match Btype.row_field_repr f with + Rpresent (Some ty) -> + compute_same ty +- | Reither (_, tyl, _, _) -> +- List.iter compute_same tyl ++ | Reither (_, tyl, _, tpl, _) -> ++ List.iter compute_same tyl; ++ List.iter (compute_variance_rec true true true) ++ (List.map fst tpl @ List.map snd tpl) + | _ -> ()) + row.row_fields; + compute_same row.row_more +@@ -856,8 +858,8 @@ + explain row.row_fields + (fun (l,f) -> match Btype.row_field_repr f with + Rpresent (Some t) -> t +- | Reither (_,[t],_,_) -> t +- | Reither (_,tl,_,_) -> Btype.newgenty (Ttuple tl) ++ | Reither (_,[t],_,_,_) -> t ++ | Reither (_,tl,_,_,_) -> Btype.newgenty (Ttuple tl) + | _ -> Btype.newgenty (Ttuple[])) + "case" (fun (lab,_) -> "`" ^ lab ^ " of ") + | _ -> trivial ty' +Index: typing/types.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.ml,v +retrieving revision 1.25 +diff -u -r1.25 types.ml +--- typing/types.ml 9 Dec 2004 12:40:53 -0000 1.25 ++++ typing/types.ml 2 Feb 2006 06:28:33 -0000 +@@ -48,7 +48,9 @@ + + and row_field = + Rpresent of type_expr option +- | Reither of bool * type_expr list * bool * row_field option ref ++ | Reither of ++ bool * type_expr list * bool * ++ (type_expr * type_expr) list * row_field option ref + | Rabsent + + and abbrev_memo = +Index: typing/types.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.mli,v +retrieving revision 1.25 +diff -u -r1.25 types.mli +--- typing/types.mli 9 Dec 2004 12:40:53 -0000 1.25 ++++ typing/types.mli 2 Feb 2006 06:28:33 -0000 +@@ -47,7 +47,9 @@ + + and row_field = + Rpresent of type_expr option +- | Reither of bool * type_expr list * bool * row_field option ref ++ | Reither of ++ bool * type_expr list * bool * ++ (type_expr * type_expr) list * row_field option ref + (* 1st true denotes a constant constructor *) + (* 2nd true denotes a tag in a pattern matching, and + is erased later *) +Index: typing/typetexp.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typetexp.ml,v +retrieving revision 1.54 +diff -u -r1.54 typetexp.ml +--- typing/typetexp.ml 22 Jul 2005 06:42:36 -0000 1.54 ++++ typing/typetexp.ml 2 Feb 2006 06:28:33 -0000 +@@ -207,9 +207,9 @@ + match Btype.row_field_repr f with + | Rpresent (Some ty) -> + bound := ty :: !bound; +- Reither(false, [ty], false, ref None) ++ Reither(false, [ty], false, [], ref None) + | Rpresent None -> +- Reither (true, [], false, ref None) ++ Reither (true, [], false, [], ref None) + | _ -> f) + row.row_fields + in +@@ -273,13 +273,16 @@ + (l, f) :: fields + in + let rec add_field fields = function +- Rtag (l, c, stl) -> ++ Rtag (l, c, stl, stpl) -> + name := None; + let f = match present with + Some present when not (List.mem l present) -> +- let tl = List.map (transl_type env policy) stl in +- bound := tl @ !bound; +- Reither(c, tl, false, ref None) ++ let transl_list = List.map (transl_type env policy) in ++ let tl = transl_list stl in ++ let stpl1, stpl2 = List.split stpl in ++ let tpl1 = transl_list stpl1 and tpl2 = transl_list stpl2 in ++ bound := tl @ tpl1 @ tpl2 @ !bound; ++ Reither(c, tl, false, List.combine tpl1 tpl2, ref None) + | _ -> + if List.length stl > 1 || c && stl <> [] then + raise(Error(styp.ptyp_loc, Present_has_conjunction l)); +@@ -311,9 +314,9 @@ + begin match f with + Rpresent(Some ty) -> + bound := ty :: !bound; +- Reither(false, [ty], false, ref None) ++ Reither(false, [ty], false, [], ref None) + | Rpresent None -> +- Reither(true, [], false, ref None) ++ Reither(true, [], false, [], ref None) + | _ -> + assert false + end +@@ -406,7 +409,8 @@ + {row with row_fixed=true; + row_fields = List.map + (fun (s,f as p) -> match Btype.row_field_repr f with +- Reither (c, tl, m, r) -> s, Reither (c, tl, true, r) ++ Reither (c, tl, m, tpl, r) -> ++ s, Reither (c, tl, true, tpl, r) + | _ -> p) + row.row_fields}; + Btype.iter_row make_fixed_univars row +Index: typing/unused_var.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/unused_var.ml,v +retrieving revision 1.5 +diff -u -r1.5 unused_var.ml +--- typing/unused_var.ml 4 Jan 2006 16:55:50 -0000 1.5 ++++ typing/unused_var.ml 2 Feb 2006 06:28:33 -0000 +@@ -122,9 +122,11 @@ + | Pexp_apply (e, lel) -> + expression ppf tbl e; + List.iter (fun (_, e) -> expression ppf tbl e) lel; +- | Pexp_match (e, pel) -> ++ | Pexp_match (e, pel, _) -> + expression ppf tbl e; + match_pel ppf tbl pel; ++ | Pexp_multifun pel -> ++ match_pel ppf tbl pel; + | Pexp_try (e, pel) -> + expression ppf tbl e; + match_pel ppf tbl pel; +Index: bytecomp/matching.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/matching.ml,v +retrieving revision 1.67 +diff -u -r1.67 matching.ml +--- bytecomp/matching.ml 7 Sep 2005 16:07:48 -0000 1.67 ++++ bytecomp/matching.ml 2 Feb 2006 06:28:33 -0000 +@@ -1991,7 +1991,7 @@ + List.iter + (fun (_, f) -> + match Btype.row_field_repr f with +- Rabsent | Reither(true, _::_, _, _) -> () ++ Rabsent | Reither(true, _::_, _, _, _) -> () + | _ -> incr num_constr) + row.row_fields + else +Index: toplevel/genprintval.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/toplevel/genprintval.ml,v +retrieving revision 1.38 +diff -u -r1.38 genprintval.ml +--- toplevel/genprintval.ml 13 Jun 2005 04:55:53 -0000 1.38 ++++ toplevel/genprintval.ml 2 Feb 2006 06:28:33 -0000 +@@ -293,7 +293,7 @@ + | (l, f) :: fields -> + if Btype.hash_variant l = tag then + match Btype.row_field_repr f with +- | Rpresent(Some ty) | Reither(_,[ty],_,_) -> ++ | Rpresent(Some ty) | Reither(_,[ty],_,_,_) -> + let args = + tree_of_val (depth - 1) (O.field obj 1) ty in + Oval_variant (l, Some args) diff --git a/testlabl/multimatch.ml b/testlabl/multimatch.ml new file mode 100644 index 0000000..7c9aa73 --- /dev/null +++ b/testlabl/multimatch.ml @@ -0,0 +1,158 @@ +(* Simple example *) +let f x = + (multimatch x with `A -> 1 | `B -> true), + (multimatch x with `A -> 1. | `B -> "1");; + +(* OK *) +module M : sig + val f : + [< `A & 'a = int & 'b = float | `B & 'b =string & 'a = bool] -> 'a * 'b +end = struct let f = f end;; + +(* Bad *) +module M : sig + val f : + [< `A & 'a = int & 'b = float | `B & 'b =string & 'a = int] -> 'a * 'b +end = struct let f = f end;; + +(* Should be good! *) +module M : sig + val f : + [< `A & 'a = int * float | `B & 'a = bool * string] -> 'a +end = struct let f = f end;; + +let f = multifun `A|`B as x -> f x;; + +(* Two-level example *) +let f = multifun + `A -> (multifun `C -> 1 | `D -> 1.) + | `B -> (multifun `C -> true | `D -> "1");; + +(* OK *) +module M : sig + val f : + [< `A & 'b = [< `C & 'a = int | `D & 'a = float & 'c = bool] -> 'a + | `B & 'b = [< `C & 'c = bool | `D & 'c = string] -> 'c] -> 'b +end = struct let f = f end;; + +(* Bad *) +module M : sig + val f : + [< `A & 'b = [< `C & 'a = int | `D & 'a = bool] -> 'a + | `B & 'b = [< `C & 'c = bool | `D & 'c = string] -> 'c] -> 'b +end = struct let f = f end;; + +module M : sig + val f : + [< `A & 'b = [< `C & 'a = int | `D] -> 'a + | `B & 'b = [< `C & 'c = bool | `D & 'c = string] -> 'c] -> 'b +end = struct let f = f end;; + + +(* Examples with hidden sharing *) +let r = ref [] +let f = multifun `A -> 1 | `B -> true +let g x = r := [f x];; + +(* Bad! *) +module M : sig + val g : [< `A & 'a = int | `B & 'a = bool] -> unit +end = struct let g = g end;; + +let r = ref [] +let f = multifun `A -> r | `B -> ref [];; +(* Now OK *) +module M : sig + val f : [< `A & 'b = int list ref | `B & 'b = 'c list ref] -> 'b +end = struct let f = f end;; +(* Still OK *) +let l : int list ref = r;; +module M : sig + val f : [< `A & 'b = int list ref | `B & 'b = 'c list ref] -> 'b +end = struct let f = f end;; + + +(* Examples that would need unification *) +let f = multifun `A -> (1, []) | `B -> (true, []) +let g x = fst (f x);; +(* Didn't work, now Ok *) +module M : sig + val g : [< `A & 'a * 'b = int * bool | `B & 'a * 'b = bool * int] -> 'a +end = struct let g = g end;; +let g = multifun (`A|`B) as x -> g x;; + +(* Other examples *) + +let f x = + let a = multimatch x with `A -> 1 | `B -> "1" in + (multifun `A -> print_int | `B -> print_string) x a +;; + +let f = multifun (`A|`B) as x -> f x;; + +type unit_op = [`Set of int | `Move of int] +type int_op = [`Get] + +let op r = + multifun + `Get -> !r + | `Set x -> r := x + | `Move dx -> r := !r + dx +;; + +let rec trace r = function + [] -> [] + | op1 :: ops -> + multimatch op1 with + #int_op as op1 -> + let x = op r op1 in + x :: trace r ops + | #unit_op as op1 -> + op r op1; + trace r ops +;; + +class point x = object + val mutable x : int = x + method get = x + method set y = x <- y + method move dx = x <- x + dx +end;; + +let poly sort coeffs x = + let add, mul, zero = + multimatch sort with + `Int -> (+), ( * ), 0 + | `Float -> (+.), ( *. ), 0. + in + let rec compute = function + [] -> zero + | c :: cs -> add c (mul x (compute cs)) + in + compute coeffs +;; + +module M : sig + val poly : [< `Int & 'a = int | `Float & 'a = float] -> 'a list -> 'a -> 'a +end = struct let poly = poly end;; + +type ('a,'b) num_sort = + 'b constraint 'b = [< `Int & 'a = int | `Float & 'a = float] +module M : sig + val poly : ('a,_) num_sort -> 'a list -> 'a -> 'a +end = struct let poly = poly end;; + + +(* type dispatch *) + +type num = [ `Int | `Float ] +let print0 = multifun + `Int -> print_int + | `Float -> print_float +;; +let print1 = multifun + #num as x -> print0 x + | `List t -> List.iter (print0 t) + | `Pair(t1,t2) -> (fun (x,y) -> print0 t1 x; print0 t2 y) +;; +print1 (`Pair(`Int,`Float)) (1,1.0);; diff --git a/testlabl/newlabels.ps b/testlabl/newlabels.ps new file mode 100644 index 0000000..01eac19 --- /dev/null +++ b/testlabl/newlabels.ps @@ -0,0 +1,1458 @@ +%!PS-Adobe-2.0 +%%Creator: dvipsk 5.78 p1.4 Copyright 1996-98 ASCII Corp.(www-ptex@ascii.co.jp) +%%dvipsk 5.78 Copyright 1998 Radical Eye Software (www.radicaleye.com) +%%Title: newlabels.dvi +%%Pages: 2 0 +%%PageOrder: Ascend +%%BoundingBox: 0 0 596 842 +%%EndComments +%%BeginProcSet: PStoPS 1 15 +userdict begin +[/showpage/erasepage/copypage]{dup where{pop dup load + type/operatortype eq{1 array cvx dup 0 3 index cvx put + bind def}{pop}ifelse}{pop}ifelse}forall +[/letter/legal/executivepage/a4/a4small/b5/com10envelope + /monarchenvelope/c5envelope/dlenvelope/lettersmall/note + /folio/quarto/a5]{dup where{dup wcheck{exch{}put} + {pop{}def}ifelse}{pop}ifelse}forall +/setpagedevice {pop}bind 1 index where{dup wcheck{3 1 roll put} + {pop def}ifelse}{def}ifelse +/PStoPSmatrix matrix currentmatrix def +/PStoPSxform matrix def/PStoPSclip{clippath}def +/defaultmatrix{PStoPSmatrix exch PStoPSxform exch concatmatrix}bind def +/initmatrix{matrix defaultmatrix setmatrix}bind def +/initclip[{matrix currentmatrix PStoPSmatrix setmatrix + [{currentpoint}stopped{$error/newerror false put{newpath}} + {/newpath cvx 3 1 roll/moveto cvx 4 array astore cvx}ifelse] + {[/newpath cvx{/moveto cvx}{/lineto cvx} + {/curveto cvx}{/closepath cvx}pathforall]cvx exch pop} + stopped{$error/errorname get/invalidaccess eq{cleartomark + $error/newerror false put cvx exec}{stop}ifelse}if}bind aload pop + /initclip dup load dup type dup/operatortype eq{pop exch pop} + {dup/arraytype eq exch/packedarraytype eq or + {dup xcheck{exch pop aload pop}{pop cvx}ifelse} + {pop cvx}ifelse}ifelse + {newpath PStoPSclip clip newpath exec setmatrix} bind aload pop]cvx def +/initgraphics{initmatrix newpath initclip 1 setlinewidth + 0 setlinecap 0 setlinejoin []0 setdash 0 setgray + 10 setmiterlimit}bind def +end +%%EndProcSet +%DVIPSCommandLine: dvips -f newlabels +%DVIPSParameters: dpi=300 +%DVIPSSource: TeX output 1999.10.26:1616 +%%BeginProcSet: tex.pro +%! +/TeXDict 300 dict def TeXDict begin /N{def}def /B{bind def}N /S{exch}N +/X{S N}B /TR{translate}N /isls false N /vsize 11 72 mul N /hsize 8.5 72 +mul N /landplus90{false}def /@rigin{isls{[0 landplus90{1 -1}{-1 1} +ifelse 0 0 0]concat}if 72 Resolution div 72 VResolution div neg scale +isls{landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div +hsize mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul +TR[matrix currentmatrix{dup dup round sub abs 0.00001 lt{round}if} +forall round exch round exch]setmatrix}N /@landscape{/isls true N}B +/@manualfeed{statusdict /manualfeed true put}B /@copies{/#copies X}B +/FMat[1 0 0 -1 0 0]N /FBB[0 0 0 0]N /nn 0 N /IE 0 N /ctr 0 N /df-tail{ +/nn 8 dict N nn begin /FontType 3 N /FontMatrix fntrx N /FontBBox FBB N +string /base X array /BitMaps X /BuildChar{CharBuilder}N /Encoding IE N +end dup{/foo setfont}2 array copy cvx N load 0 nn put /ctr 0 N[}B /df{ +/sf 1 N /fntrx FMat N df-tail}B /dfs{div /sf X /fntrx[sf 0 0 sf neg 0 0] +N df-tail}B /E{pop nn dup definefont setfont}B /ch-width{ch-data dup +length 5 sub get}B /ch-height{ch-data dup length 4 sub get}B /ch-xoff{ +128 ch-data dup length 3 sub get sub}B /ch-yoff{ch-data dup length 2 sub +get 127 sub}B /ch-dx{ch-data dup length 1 sub get}B /ch-image{ch-data +dup type /stringtype ne{ctr get /ctr ctr 1 add N}if}B /id 0 N /rw 0 N +/rc 0 N /gp 0 N /cp 0 N /G 0 N /sf 0 N /CharBuilder{save 3 1 roll S dup +/base get 2 index get S /BitMaps get S get /ch-data X pop /ctr 0 N ch-dx +0 ch-xoff ch-yoff ch-height sub ch-xoff ch-width add ch-yoff +setcachedevice ch-width ch-height true[1 0 0 -1 -.1 ch-xoff sub ch-yoff +.1 sub]{ch-image}imagemask restore}B /D{/cc X dup type /stringtype ne{]} +if nn /base get cc ctr put nn /BitMaps get S ctr S sf 1 ne{dup dup +length 1 sub dup 2 index S get sf div put}if put /ctr ctr 1 add N}B /I{ +cc 1 add D}B /bop{userdict /bop-hook known{bop-hook}if /SI save N @rigin +0 0 moveto /V matrix currentmatrix dup 1 get dup mul exch 0 get dup mul +add .99 lt{/QV}{/RV}ifelse load def pop pop}N /eop{SI restore userdict +/eop-hook known{eop-hook}if showpage}N /@start{userdict /start-hook +known{start-hook}if pop /VResolution X /Resolution X 1000 div /DVImag X +/IE 256 array N 2 string 0 1 255{IE S dup 360 add 36 4 index cvrs cvn +put}for pop 65781.76 div /vsize X 65781.76 div /hsize X}N /p{show}N +/RMat[1 0 0 -1 0 0]N /BDot 260 string N /rulex 0 N /ruley 0 N /v{/ruley +X /rulex X V}B /V{}B /RV statusdict begin /product where{pop false[ +(Display)(NeXT)(LaserWriter 16/600)]{dup length product length le{dup +length product exch 0 exch getinterval eq{pop true exit}if}{pop}ifelse} +forall}{false}ifelse end{{gsave TR -.1 .1 TR 1 1 scale rulex ruley false +RMat{BDot}imagemask grestore}}{{gsave TR -.1 .1 TR rulex ruley scale 1 1 +false RMat{BDot}imagemask grestore}}ifelse B /QV{gsave newpath transform +round exch round exch itransform moveto rulex 0 rlineto 0 ruley neg +rlineto rulex neg 0 rlineto fill grestore}B /a{moveto}B /delta 0 N /tail +{dup /delta X 0 rmoveto}B /M{S p delta add tail}B /b{S p tail}B /c{-4 M} +B /d{-3 M}B /e{-2 M}B /f{-1 M}B /g{0 M}B /h{1 M}B /i{2 M}B /j{3 M}B /k{ +4 M}B /w{0 rmoveto}B /l{p -4 w}B /m{p -3 w}B /n{p -2 w}B /o{p -1 w}B /q{ +p 1 w}B /r{p 2 w}B /s{p 3 w}B /t{p 4 w}B /x{0 S rmoveto}B /y{3 2 roll p +a}B /bos{/SS save N}B /eos{SS restore}B end + +%%EndProcSet +TeXDict begin 39158280 55380996 1000 300 300 (newlabels.dvi) +@start +%DVIPSBitmapFont: Fa cmr6 6 2 +/Fa 2 51 df<187898181818181818181818181818FF08107D8F0F> 49 +D<1F00618040C08060C0600060006000C00180030006000C00102020207FC0FFC00B107F +8F0F> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fb cmmi8 8 4 +/Fb 4 111 df<FFC0FF1C00181C00101C00101C00103800203800203800203800207000 +40700040700040700040E00080E00080E00080E00080E00100E00200E004006008003830 +000FC00018177E9618> 85 D<0300038003000000000000000000000000001C00240046 +0046008C000C0018001800180031003100320032001C0009177F960C> 105 +D<383C1E0044C6630047028100460301008E0703000C0603000C0603000C060300180C06 +00180C0620180C0C20180C0C40301804C0301807001B0E7F8D1F> 109 +D<383C0044C6004702004602008E06000C06000C06000C0600180C00180C401818401818 +80300980300E00120E7F8D15> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fc cmbx8 8 4 +/Fc 4 111 df<01800780FF80FF80078007800780078007800780078007800780078007 +800780078007800780FFF8FFF80D157D9414> 49 D<387C7C7C3800000000FCFC3C3C3C +3C3C3C3C3C3C3C3CFFFF08187F970B> 105 D<FC7E0FC0FD8730E03E07C0F03E07C0F03C +0780F03C0780F03C0780F03C0780F03C0780F03C0780F03C0780F03C0780F03C0780F0FF +1FE3FCFF1FE3FC1E0F7E8E23> 109 D<FC7C00FD8E003E0F003E0F003C0F003C0F003C0F +003C0F003C0F003C0F003C0F003C0F003C0F00FF3FC0FF3FC0120F7E8E17> I +E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fd cmsy8 8 3 +/Fd 3 93 df<FFFFF0FFFFF014027D881B> 0 D<020002000200C218F2783AE00F800F80 +3AE0F278C2180200020002000D0E7E8E12> 3 D<03F8001FFF003C07806000C0C00060C0 +0060C00060C00060C00060C00060C00060C00060C00060C00060C00060C00060C00060C0 +006040002013137E9218> 92 D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fe cmtt12 12 43 +/Fe 43 125 df<01818003C3C003C3C003C3C003C3C003C3C003C3C07FFFF0FFFFF8FFFF +F87FFFF00787800787800787800F8F800F0F000F0F000F0F000F0F007FFFF0FFFFF8FFFF +F87FFFF01E1E001E1E001E1E001E1E001E1E001E1E000C0C00151E7E9D1A> 35 +D<00E00003F00007F8000738000E1C000E1C000E1C000E1C000E38000E39FC0E71FC07F1 +FC07E1C007C1C00781C00783800F83801FC3803DC70078E70070EE00E07E00E07E00E03C +08E03C1CE07E1C70FF1C7FE7F83FC3F80F00E0161E7F9D1A> 38 +D<0038007800F001E003C007800F000E001C001C0038003800700070007000E000E000E0 +00E000E000E000E000E000E000E000700070007000380038001C001C000E000F00078003 +C001E000F8007800380D2878A21A> 40 D<6000F00078003C001E000F000780038001C0 +01C000E000E0007000700070003800380038003800380038003800380038003800700070 +007000E000E001C001C0038007800F001E003C007800F00060000D287CA21A> I<7FFFC0 +FFFFE0FFFFE07FFFC013047D901A> 45 D<00C001C001C003C007C00FC07FC0FDC071C0 +01C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C0 +7FFF7FFF7FFF101E7B9D1A> 49 D<03F8000FFE001FFF803C07C07801E07000E0E00070 +F00070F000706000700000700000700000E00000E00001C00003C0000780000F00001E00 +003C0000780000F00003E00007C0000F00001E00703C00707FFFF0FFFFF07FFFF0141E7D +9D1A> I<03FC000FFF003FFFC03C03E07800E07800707800700000700000700000E00001 +E00007C003FF8003FF0003FFC00003E00000E0000070000078000038000038600038F000 +38F00078E000707000E07E03E03FFFC00FFF0001FC00151E7E9D1A> I<01FC0007FF001F +FFC01F07C03C01E07800F07000707000707000707800F03800E01E03C00FFF8003FE0007 +FF001F8FC03C01E07800F0700070E00038E00038E00038E00038F000787000707800F03E +03E01FFFC007FF0001FC00151E7E9D1A> 56 D<01F00007FC001FFE003E0F0038078070 +03807001C0E001C0E001C0E001E0E000E0E000E0E001E07001E07803E03C0FE01FFFE00F +FCE003F0E00001C00001C00001C0000380600380F00700F00F00F03E007FFC003FF0000F +C000131E7D9D1A> I<3078FCFC78300000000000000000003078FCFC7830061576941A> +I<183C7E7E3C18000000000000000000183C7E7E3E1E0E0E1C3CF8F060071C77941A> I< +0000C00003E00007E0000FC0003F80007E0000FC0003F80007E0000FC0003F80007E0000 +FC0000FC00007E00003F80000FC00007E00003F80000FC00007E00003F80000FC00007E0 +0003E00000C0131A7D9B1A> I<7FFFF0FFFFF8FFFFF87FFFF00000000000000000000000 +007FFFF0FFFFF8FFFFF87FFFF0150C7E941A> I<600000F80000FC00007E00003F80000F +C00007E00003F80000FC00007E00003F80000FC00007E00007E0000FC0003F80007E0000 +FC0003F80007E0000FC0003F80007E0000FC0000F80000600000131A7D9B1A> I<007C38 +01FF3807FFF80F83F81E00F81C0078380078380038700038700038700000E00000E00000 +E00000E00000E00000E00000E00000E000007000007000387000383800383800381C0070 +1E00F00F83E007FFC001FF80007C00151E7E9D1A> 67 D<FE03FEFF03FEFF03FE1D8070 +1D80701DC0701CC0701CC0701CE0701CE0701C60701C70701C70701C30701C38701C3870 +1C18701C1C701C1C701C0C701C0E701C0E701C06701C06701C07701C03701C0370FF81F0 +FF81F0FF80F0171E7F9D1A> 78 D<03F8E00FFEE01FFFE03C07E07801E0F001E0E000E0 +E000E0E000E0E000007000007800003F80001FF80007FF00007FC00007E00000F0000070 +000038000038600038E00038E00038E00070F000F0FE01E0FFFFC0EFFF80E1FE00151E7E +9D1A> 83 D<7FFFFEFFFFFEFFFFFEE0380EE0380EE0380EE0380E003800003800003800 +003800003800003800003800003800003800003800003800003800003800003800003800 +00380000380000380000380000380003FF8003FF8003FF80171E7F9D1A> I<FFFCFFFCFF +FCE000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E0 +00E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000FFFCFFFCFF +FC0E2776A21A> 91 D<FFFCFFFCFFFC001C001C001C001C001C001C001C001C001C001C +001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C001C +001C001C001C001C001CFFFCFFFCFFFC0E277FA21A> 93 D<1FF0003FFC007FFE00780F +00300700000380000380007F8007FF801FFF803F8380780380700380E00380E00380E003 +80700780780F803FFFFC1FFDFC07F0FC16157D941A> 97 D<7E0000FE00007E00000E00 +000E00000E00000E00000E00000E00000E3E000EFF800FFFE00FC1F00F80700F00380E00 +380E001C0E001C0E001C0E001C0E001C0E001C0E001C0F00380F00780F80F00FC1E00FFF +C00EFF80063E00161E7F9D1A> I<00FF8003FFC00FFFE01F01E03C00C078000070000070 +0000E00000E00000E00000E00000E000007000007000007800703C00701F01F00FFFE003 +FFC000FE0014157D941A> I<000FC0001FC0000FC00001C00001C00001C00001C00001C0 +0001C001F1C007FDC00FFFC01E0FC03C07C07803C07001C0E001C0E001C0E001C0E001C0 +E001C0E001C0E001C07003C07003C03807C03E0FC01FFFF807FDFC01F1F8161E7E9D1A> +I<01F80007FF000FFF801E07C03C01C07800E07000E0E00070E00070FFFFF0FFFFF0FFFF +F0E000007000007000007800703C00701F01F00FFFE003FF8000FE0014157D941A> I<00 +07E0001FF0003FF800787800F03000E00000E00000E00000E0007FFFF0FFFFF0FFFFF000 +E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000 +E00000E00000E0003FFF807FFFC03FFF80151E7F9D1A> I<7E0000FE00007E00000E0000 +0E00000E00000E00000E00000E00000E3E000EFF800FFFC00FC1C00F80E00F00E00E00E0 +0E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E07FC3FC +FFE7FE7FC3FC171E7F9D1A> 104 D<00C00001E00001E00000C000000000000000000000 +0000000000000000007FE0007FE0007FE00000E00000E00000E00000E00000E00000E000 +00E00000E00000E00000E00000E00000E00000E00000E00000E0007FFF80FFFFC07FFF80 +121F7C9E1A> I<7FE000FFE0007FE00000E00000E00000E00000E00000E00000E00000E0 +0000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E0 +0000E00000E00000E00000E00000E0007FFFC0FFFFE07FFFC0131E7D9D1A> 108 +D<7CE0E000FFFBF8007FFFF8001F1F1C001E1E1C001E1E1C001C1C1C001C1C1C001C1C1C +001C1C1C001C1C1C001C1C1C001C1C1C001C1C1C001C1C1C001C1C1C001C1C1C001C1C1C +007F1F1F00FFBFBF807F1F1F00191580941A> I<7E3E00FEFF807FFFC00FC1C00F80E00F +00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E +00E07FC3FCFFE7FE7FC3FC17157F941A> I<01F00007FC001FFF003E0F803C07807803C0 +7001C0E000E0E000E0E000E0E000E0E000E0E000E0F001E07001C07803C03C07803E0F80 +1FFF0007FC0001F00013157D941A> I<7E3E00FEFF807FFFE00FC1F00F80700F00380E00 +380E001C0E001C0E001C0E001C0E001C0E001C0E001C0F00380F00780F80F00FC1E00FFF +C00EFF800E3E000E00000E00000E00000E00000E00000E00000E00000E00007FC000FFE0 +007FC00016207F941A> I<7F81F8FF8FFC7F9FFE03FE1E03F80C03E00003E00003C00003 +80000380000380000380000380000380000380000380000380000380007FFF00FFFF007F +FF0017157F941A> 114 D<07FB801FFF807FFF80780780E00380E00380E003807800007F +C0001FFC0007FE00003F800007806001C0E001C0E001C0F003C0FC0780FFFF00EFFE00E3 +F80012157C941A> I<0180000380000380000380000380000380000380007FFFE0FFFFE0 +FFFFE0038000038000038000038000038000038000038000038000038000038000038070 +03807003807003807001C1E001FFE000FF80003F00141C7F9B1A> I<7E07E0FE0FE07E07 +E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00 +E00E00E00E01E00F03E007FFFC03FFFE00FCFC17157F941A> I<7F83FCFFC7FE7F83FC0E +00E00E00E00E00E00701C00701C00701C003838003838003838001C70001C70001C70000 +EE0000EE0000EE00007C00007C0000380017157F941A> I<FF83FEFF83FEFF83FE380038 +3800381C00701C00701C00701C38701C7C701C7C700C6C600EEEE00EEEE00EEEE00EEEE0 +0EC6E006C6C007C7C00783C00783C017157F941A> I<7FC7F87FCFFC7FC7F80703C00383 +8003C70001EF0000FE00007C00007800003800007C0000EE0001EE0001C7000383800783 +C00F01C07FC7FCFFC7FE7FC7FC17157F941A> I<7F83FCFFC7FE7F83FC0E00E00E00E007 +00E00701C00701C00381C003838003C38001C38001C70000E70000E70000E60000660000 +6E00003C00003C00003C0000380000380000380000700000700030F00078E00071E0007F +C0003F80001E000017207F941A> I<60F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0 +F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F060042775A21A> 124 D +E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Ff cmr8 8 3 +/Ff 3 51 df<003000003000003000003000003000003000003000003000003000003000 +003000FFFFFCFFFFFC003000003000003000003000003000003000003000003000003000 +00300000300016187E931B> 43 D<06000E00FE000E000E000E000E000E000E000E000E +000E000E000E000E000E000E000E000E000E00FFE00B157D9412> 49 +D<0F8030E040708030C038E0384038003800700070006000C00180030006000C08080810 +183FF07FF0FFF00D157E9412> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fg cmmi12 12 13 +/Fg 13 121 df<0FFFF81FFFFC3FFFF870200040200080200080600000600000600000C0 +0000C00000C00000C00001C0000180000180000380000380000380000700000300001615 +7E9415> 28 D<0000100000002000000020000000200000002000000040000000400000 +004000000040000000800000008000000080000000800000010000000FE00000711C0001 +C10600030203000E0203801C020180180201C0380401C0700401C0700401C0700401C0E0 +080380E0080380E00807006008070070100E0030101C00301038001C10E0000623800001 +FE0000002000000020000000400000004000000040000000400000008000000080000000 +800000008000001A2D7EA21D> 30 D<70F8F8F87005057C840E> 58 +D<70F8FCFC7404040404080810102040060F7C840E> I<00008000018000018000030000 +0300000300000600000600000600000C00000C00000C0000180000180000180000300000 +300000300000600000600000600000C00000C00000C00001800001800001800001800003 +00000300000300000600000600000600000C00000C00000C000018000018000018000030 +0000300000300000600000600000600000C00000C00000C0000011317DA418> 61 +D<00FFFC00000F8000000F0000000F0000001E0000001E0000001E0000001E0000003C00 +00003C0000003C0000003C00000078000000780000007800000078000000F0000000F000 +0000F0000000F0000001E0000001E0000001E0002001E0002003C0004003C0004003C000 +8003C0008007800180078001000780030007800F000F803E00FFFFFE001B227DA121> 76 +D<1FFFFFFE1E01E00E1801E0063001E0062003C0062003C0064003C0044003C004400780 +04800780048007800400078000000F0000000F0000000F0000000F0000001E0000001E00 +00001E0000001E0000003C0000003C0000003C0000003C00000078000000780000007800 +000078000000F0000000F0000000F0000000F0000001F000007FFFC0001F227EA11D> 84 +D<3FFE01FF8003C0003C0003C000300003C0001000078000200007800020000780002000 +07800020000F000040000F000040000F000040000F000040001E000080001E000080001E +000080001E000080003C000100003C000100003C000100003C0001000078000200007800 +020000780002000078000200007000040000F000040000F0000800007000080000700010 +00007000200000380040000038008000001C01000000060600000001F800000021237DA1 +21> I<007E000381000700800E00801C0080380080780100700600FFF800F00000F00000 +E00000E00000E00000E00000E00080E000807003003004001838000FC00011157D9417> +101 D<01E00FC001C001C001C0038003800380038007000700070007000E000E000E000E +001C001C001C001C0038003800380038007000700070007080E100E100E100620062003C +000B237EA20F> 108 D<03C0F004631C04740E08780E08700708700708700F00E00F00E0 +0F00E00F00E00F01C01E01C01E01C01E01C03C03803803803803C07003C0E0072180071E +000700000700000E00000E00000E00000E00001C00001C00001C0000FF8000181F819418 +> 112 D<3C0F004630C04741C08783C08783C08701808700000E00000E00000E00000E00 +001C00001C00001C00001C000038000038000038000038000070000030000012157E9416 +> 114 D<01E0F006310C081A1C101A3C201C3C201C18201C000038000038000038000038 +0000700000700000700000700860E010F0E010F0E020E170404230803C1F0016157E941C +> 120 D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fh cmti12 12 22 +/Fh 22 122 df<FFF0FFF0FFE00C037C8B11> 45 D<70F8F8F0E005057A840F> I<00F8 +C00185C00705C00E03800E03801C03803C0380380700780700780700780700F00E00F00E +00F00E00F00E10F01C20701C20703C20305C40308C400F078014157B9419> 97 +D<03C01F8003800380038007000700070007000E000E000E000E001C001CF81D0C1E0E3C +0638073807380F700F700F700F700FE01EE01EE01EE03CE038E038607060E031C01F0010 +237BA216> I<007E0001C1000301800703800E07801C07803C0000380000780000780000 +780000F00000F00000F00000F00000F00100700100700200300C001830000FC00011157B +9416> I<00003C0003F80000380000380000380000700000700000700000700000E00000 +E00000E00000E00001C000F9C00185C00705C00E03800E03801C03803C03803807007807 +00780700780700F00E00F00E00F00E00F00E10F01C20701C20703C20305C40308C400F07 +8016237BA219> I<00F803840E021C023C0238027804F018FFE0F000F000E000E000E000 +E000E002E0026004701830600F800F157A9416> I<00003E0000470000CF00018F000186 +000380000380000380000700000700000700000700000700000E0000FFF0000E00000E00 +000E00001C00001C00001C00001C00001C00003800003800003800003800003800007000 +00700000700000700000700000E00000E00000E00000E00000C00001C00001C000718000 +F18000F300006200003C0000182D82A20F> I<001F180030B800E0B801C07001C0700380 +700780700700E00F00E00F00E00F00E01E01C01E01C01E01C01E01C01E03800E03800E07 +80060B8006170001E700000700000700000E00000E00000E00701C00F01800F0300060E0 +003F8000151F7E9416> I<00C001E001C001C0000000000000000000000000000000001E +002300430043008700870087000E000E001C001C001C0038003800384070807080708071 +0032001C000B217BA00F> 105 D<00F00007E00000E00000E00000E00001C00001C00001 +C00001C0000380000380000380000380000700000701E00702100704700E08F00E10F00E +20600E40001D80001E00001FC0001C7000383800383800381C00381C2070384070384070 +3840701880E01880600F0014237DA216> 107 D<01E00FC001C001C001C0038003800380 +038007000700070007000E000E000E000E001C001C001C001C0038003800380038007000 +700070007100E200E200E200E200640038000B237CA20C> I<1C0F80F8002610C10C0047 +6066060087807807008780780700870070070087007007000E00E00E000E00E00E000E00 +E00E000E00E00E001C01C01C001C01C01C001C01C01C001C01C038203803803840380380 +70403803807080380380308070070031003003001E0023157B9428> I<380F804C30C04E +40608E80708F00708E00708E00701C00E01C00E01C00E01C00E03801C03801C03801C038 +0384700388700308700708700310E003106001E016157B941B> I<007E0001C300038180 +0701C00E01C01C01E03C01E03801E07801E07801E07801E0F003C0F003C0F00380F00780 +700700700E00700C0030180018700007C00013157B9419> I<01C1F002621804741C0878 +0C08700E08700E08701E00E01E00E01E00E01E00E01E01C03C01C03C01C03C01C0780380 +7003807003C0E003C1C0072380071E000700000700000E00000E00000E00000E00001C00 +001C00001C0000FFC000171F7F9419> I<1C1F002620804741C08783C08703C087018087 +00000E00000E00000E00000E00001C00001C00001C00001C000038000038000038000038 +000070000030000012157B9415> 114 D<00FC000183000200800401800C03800C03000C +00000F00000FF00007FC0003FE00003E00000F00000700700700F00600F00600E0040040 +08002030001FC00011157D9414> I<00C001C001C001C001C003800380038003800700FF +F8070007000E000E000E000E001C001C001C001C00380038003800381070207020704070 +8031001E000D1F7C9E10> I<1E0060E02300E0F04380E1F04381C0F08381C0708701C030 +8701C030070380200E0380200E0380200E0380201C0700401C0700401C0700401C070080 +1C0700801C0701001C0F01000C0B02000613840003E0F8001C157B9420> 119 +D<03C1E0046210083470103CF02038F020386020380000700000700000700000700000E0 +0000E00000E00000E02061C040F1C040F1C080E2C100446200383C0014157D9416> I<1E +00302300704380704380E08380E08700E08700E00701C00E01C00E01C00E01C01C03801C +03801C03801C03801C07001C07001C07001C0F000C3E0003CE00000E00000E00001C0060 +1C00F03800F03000E0600080C0004380003E0000141F7B9418> I +E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fi cmbx12 12 20 +/Fi 20 122 df<FFFFFF8000FFFFFFF00007F003FC0007F0007E0007F0003F0007F0001F +8007F0000FC007F00007E007F00007E007F00007F007F00003F007F00003F007F00003F0 +07F00003F807F00003F807F00003F807F00003F807F00003F807F00003F807F00003F807 +F00003F807F00003F807F00003F007F00003F007F00003F007F00007E007F00007E007F0 +000FC007F0001F8007F0003F0007F0007E0007F003FC00FFFFFFF000FFFFFF800025227E +A12B> 68 D<01FE0207FF861F01FE3C007E7C001E78000E78000EF80006F80006FC0006 +FC0000FF0000FFE0007FFF007FFFC03FFFF01FFFF80FFFFC03FFFE003FFE0003FE00007F +00003F00003FC0001FC0001FC0001FE0001EE0001EF0003CFC003CFF00F8C7FFE080FF80 +18227DA11F> 83 D<7FFFFFFF807FFFFFFF807E03F80F807803F807807003F803806003 +F80180E003F801C0E003F801C0C003F800C0C003F800C0C003F800C0C003F800C00003F8 +00000003F800000003F800000003F800000003F800000003F800000003F800000003F800 +000003F800000003F800000003F800000003F800000003F800000003F800000003F80000 +0003F800000003F800000003F800000003F800000003F8000001FFFFF00001FFFFF00022 +227EA127> I<0FFC003FFF807E07C07E03E07E01E07E01F03C01F00001F00001F0003FF0 +03FDF01FC1F03F01F07E01F0FC01F0FC01F0FC01F0FC01F07E02F07E0CF81FF87F07E03F +18167E951B> 97 D<FF000000FF0000001F0000001F0000001F0000001F0000001F0000 +001F0000001F0000001F0000001F0000001F0000001F0000001F0FE0001F3FF8001FE07C +001F803E001F001F001F000F801F000F801F000FC01F000FC01F000FC01F000FC01F000F +C01F000FC01F000FC01F000FC01F000F801F001F801F801F001FC03E001EE07C001C3FF8 +00180FC0001A237EA21F> I<00FF8007FFE00F83F01F03F03E03F07E03F07C01E07C0000 +FC0000FC0000FC0000FC0000FC0000FC00007C00007E00007E00003E00181F00300FC060 +07FFC000FF0015167E9519> I<00FE0007FF800F87C01E01E03E01F07C00F07C00F8FC00 +F8FC00F8FFFFF8FFFFF8FC0000FC0000FC00007C00007C00007E00003E00181F00300FC0 +7003FFC000FF0015167E951A> 101 D<001FC0007FE000F1F001E3F003E3F007C3F007C1 +E007C00007C00007C00007C00007C00007C000FFFE00FFFE0007C00007C00007C00007C0 +0007C00007C00007C00007C00007C00007C00007C00007C00007C00007C00007C00007C0 +0007C00007C0003FFC003FFC00142380A211> I<01FE0F0007FFBF800F87C7801F03E780 +1E01E0003E01F0003E01F0003E01F0003E01F0003E01F0001E01E0001F03E0000F87C000 +0FFF800009FE000018000000180000001C0000001FFFE0000FFFF80007FFFE001FFFFF00 +3C003F0078000F80F0000780F0000780F0000780F000078078000F003C001E001F007C00 +0FFFF80001FFC00019217F951C> I<1C003E007F007F007F003E001C0000000000000000 +00000000000000FF00FF001F001F001F001F001F001F001F001F001F001F001F001F001F +001F001F001F001F001F00FFE0FFE00B247EA310> 105 D<FF00FF001F001F001F001F00 +1F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F00 +1F001F001F001F001F001F001F001F001F00FFE0FFE00B237EA210> 108 +D<FF07F007F000FF1FFC1FFC001F303E303E001F403E403E001F801F801F001F801F801F +001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F +001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F001F +001F001F001F001F001F001F00FFE0FFE0FFE0FFE0FFE0FFE02B167E9530> I<FF07E000 +FF1FF8001F307C001F403C001F803E001F803E001F003E001F003E001F003E001F003E00 +1F003E001F003E001F003E001F003E001F003E001F003E001F003E001F003E001F003E00 +1F003E00FFE1FFC0FFE1FFC01A167E951F> I<00FE0007FFC00F83E01E00F03E00F87C00 +7C7C007C7C007CFC007EFC007EFC007EFC007EFC007EFC007EFC007E7C007C7C007C3E00 +F81F01F00F83E007FFC000FE0017167E951C> I<FF0FE000FF3FF8001FE07C001F803E00 +1F001F001F001F801F001F801F000FC01F000FC01F000FC01F000FC01F000FC01F000FC0 +1F000FC01F000FC01F001F801F001F801F803F001FC03E001FE0FC001F3FF8001F0FC000 +1F0000001F0000001F0000001F0000001F0000001F0000001F0000001F000000FFE00000 +FFE000001A207E951F> I<0FF3003FFF00781F00600700E00300E00300F00300FC00007F +E0007FF8003FFE000FFF0001FF00000F80C00780C00380E00380E00380F00700FC0E00EF +FC00C7F00011167E9516> 115 D<01800001800001800001800003800003800007800007 +80000F80003F8000FFFF00FFFF000F80000F80000F80000F80000F80000F80000F80000F +80000F80000F80000F80000F81800F81800F81800F81800F81800F830007C30003FE0000 +F80011207F9F16> I<FF01FE00FF01FE001F003E001F003E001F003E001F003E001F003E +001F003E001F003E001F003E001F003E001F003E001F003E001F003E001F003E001F003E +001F003E001F007E001F00FE000F81BE0007FF3FC001FC3FC01A167E951F> I<FFE07FC0 +FFE07FC00F801C0007C0380003E0700003F0600001F8C00000F98000007F8000003F0000 +001F0000001F8000003FC0000037C0000063E00000C1F00001C0F8000380FC0007007E00 +0E003E00FF80FFE0FF80FFE01B167F951E> 120 D<FFE01FE0FFE01FE01F8007000F8006 +000FC00E0007C00C0007E00C0003E0180003E0180001F0300001F0300000F8600000F860 +00007CC000007CC000007FC000003F8000003F8000001F0000001F0000000E0000000E00 +00000C0000000C00000018000078180000FC380000FC300000FC60000069C000007F8000 +001F0000001B207F951E> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fj cmsy10 12 15 +/Fj 15 107 df<FFFFFFFCFFFFFFFC1E027C8C27> 0 D<03F0000FFC001FFE003FFF007F +FF807FFF80FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC07FFF807FFF803F +FF001FFE000FFC0003F00012147D9519> 15 D<000FFFFC007FFFFC01F0000003800000 +060000000C0000001800000030000000300000006000000060000000C0000000C0000000 +C0000000C0000000C0000000C0000000C0000000C0000000600000006000000030000000 +30000000180000000C000000060000000380000001E00000007FFFFC001FFFFC1E1E7C9A +27> 26 D<00000001800000000001800000000001800000000001800000000000C00000 +000000C000000000006000000000003000000000003000000000001C00000000000E0000 +0000000700FFFFFFFFFFE0FFFFFFFFFFE0000000000700000000000E00000000001C0000 +000000300000000000300000000000600000000000C00000000000C00000000001800000 +00000180000000000180000000000180002B1A7D9832> 33 D<001FFF007FFF01E00003 +80000600000C0000180000300000300000600000600000600000C00000C00000FFFFFFFF +FFFFC00000C000006000006000006000003000003000001800000C000006000003800001 +E000007FFF001FFF181E7C9A21> 50 D<00000300000300000600000600000C00000C00 +00180000180000300000300000600000600000C00000C00000C000018000018000030000 +0300000600000600000C00000C0000180000180000300000300000600000600000C00000 +C0000180000180000300000300000300000600000600000C00000C000018000018000030 +0000300000600000600000C00000400000183079A300> 54 D<C0C0C0C0C0C0C0C0E0E0 +C0C0C0C0C0C0C0C003127D9400> I<00008000018001F980070F000C0300180380180780 +3006C03006C0700CE0600C60600C60600C60E01870E01870E01870E03070E03070E03070 +E06070E06070E06070E06070E0C070E0C070E0C070E18070E180706180606300607300E0 +7300E03300C03600C01E01801E01800C03000F0E000DF800180000180000180000142A7E +A519> 59 D<000100000003000000030000000300000003000000030000000300000003 +000000030000000300000003000000030000000300000003000000030000000300000003 +000000030000000300000003000000030000000300000003000000030000000300000003 +000000030000000300000003000000030000FFFFFFFEFFFFFFFE1F207C9F27> 63 +D<40000040C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000 +C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000 +C0C00000C0C00000C0C00000C0C00000C0C00000C0600001806000018030000300180006 +000E001C000780780001FFE000007F80001A1F7D9D21> 91 D<007F800001FFE0000780 +78000E001C0018000600300003006000018060000180C00000C0C00000C0C00000C0C000 +00C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C000 +00C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C000 +00C0400000401A1F7D9D21> I<000C0000000C0000001E0000001E0000001E0000003300 +0000330000006180000061800000C0C00000C0C00000C0C0000180600001806000030030 +00030030000300300006001800060018000C000C000C000C000C000C0018000600180006 +003000030030000300600001806000018060000180C00000C0C00000401A1F7D9D21> 94 +D<0003C0001E0000380000700000E00000E00000E00000E00000E00000E00000E00000E0 +0000E00000E00000E00000E00000E00000E00000E00000E00000E00001C0000380000F00 +00F800000F000003800001C00000E00000E00000E00000E00000E00000E00000E00000E0 +0000E00000E00000E00000E00000E00000E00000E00000E00000E000007000003800001E +000003C012317DA419> 102 D<F800000F000003800001C00000E00000E00000E00000E0 +0000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E0 +0000E000007000003800001E000003C0001E0000380000700000E00000E00000E00000E0 +0000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E00000E0 +0000E00001C0000380000F0000F8000012317DA419> I<C0C0C0C0C0C0C0C0C0C0C0C0C0 +C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0 +02317AA40E> 106 D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fk cmr12 12 65 +/Fk 65 125 df<001FC1F00070371800C03E3C01807C3C0380783C070038000700380007 +003800070038000700380007003800070038000700380007003800FFFFFFC00700380007 +003800070038000700380007003800070038000700380007003800070038000700380007 +0038000700380007003800070038000700380007003800070038000700380007003C007F +E1FFC01E2380A21C> 11 D<001FC0000070200000C01000018038000380780007007800 +0700300007000000070000000700000007000000070000000700000007000000FFFFF800 +070078000700380007003800070038000700380007003800070038000700380007003800 +070038000700380007003800070038000700380007003800070038000700380007003800 +070038007FE1FF80192380A21B> I<001FD8000070380000C07800018078000380780007 +0038000700380007003800070038000700380007003800070038000700380007003800FF +FFF800070038000700380007003800070038000700380007003800070038000700380007 +003800070038000700380007003800070038000700380007003800070038000700380007 +003800070038007FF3FF80192380A21B> I<000FC07F00007031C08000E00B004001801E +00E003803E01E007003C01E007001C00C007001C000007001C000007001C000007001C00 +0007001C000007001C000007001C0000FFFFFFFFE007001C01E007001C00E007001C00E0 +07001C00E007001C00E007001C00E007001C00E007001C00E007001C00E007001C00E007 +001C00E007001C00E007001C00E007001C00E007001C00E007001C00E007001C00E00700 +1C00E007001C00E07FF1FFCFFE272380A229> I<70F8FCFC740404040408081010204006 +0F7CA20E> 39 D<00200040008001000300060004000C000C0018001800300030003000 +7000600060006000E000E000E000E000E000E000E000E000E000E000E000E000E000E000 +6000600060007000300030003000180018000C000C000400060003000100008000400020 +0B327CA413> I<800040002000100018000C000400060006000300030001800180018001 +C000C000C000C000E000E000E000E000E000E000E000E000E000E000E000E000E000E000 +C000C000C001C0018001800180030003000600060004000C00180010002000400080000B +327DA413> I<70F8FCFC7404040404080810102040060F7C840E> 44 +D<FFF8FFF80D02808B10> I<70F8F8F87005057C840E> I<01F000071C000C0600180300 +3803803803807001C07001C07001C07001C0F001E0F001E0F001E0F001E0F001E0F001E0 +F001E0F001E0F001E0F001E0F001E0F001E0F001E0F001E07001C07001C07001C07803C0 +3803803803801C07000C0600071C0001F00013227EA018> 48 D<008003800F80F38003 +800380038003800380038003800380038003800380038003800380038003800380038003 +800380038003800380038003800380038007C0FFFE0F217CA018> I<03F0000C1C001007 +002007804003C04003C08003E0F003E0F801E0F801E0F801E02003E00003E00003C00003 +C0000780000700000E00001C0000180000300000600000C0000180000100000200200400 +200800201800603000403FFFC07FFFC0FFFFC013217EA018> I<03F8000C1E00100F0020 +07804007C07807C07803C07807C03807C0000780000780000700000F00000C0000380003 +F000001C00000F000007800007800003C00003C00003E02003E07003E0F803E0F803E0F0 +03C04003C0400780200780100F000C1C0003F00013227EA018> I<000300000300000700 +000700000F00001700001700002700006700004700008700018700010700020700060700 +040700080700080700100700200700200700400700C00700FFFFF8000700000700000700 +000700000700000700000700000F80007FF015217FA018> I<70F8F8F870000000000000 +000000000070F8F8F87005157C940E> 58 D<FFFFFFFEFFFFFFFE000000000000000000 +0000000000000000000000000000000000000000000000FFFFFFFEFFFFFFFE1F0C7D9126 +> 61 D<07E01838201C400E800FF00FF00FF00F000F000E001C00380030006000C000C0 +00800080018001000100010001000100010000000000000000000000038007C007C007C0 +038010237DA217> 63 D<0001800000018000000180000003C0000003C0000003C00000 +05E0000005E0000009F0000008F0000008F00000107800001078000010780000203C0000 +203C0000203C0000401E0000401E0000C01F0000800F0000800F0001FFFF800100078001 +000780020003C0020003C0020003C0040001E0040001E0040001E0080000F01C0000F03E +0001F8FF800FFF20237EA225> 65 D<FFFFF8000F800E0007800780078003C0078003E0 +078001E0078001F0078001F0078001F0078001F0078001F0078001E0078003E0078007C0 +07800F8007803E0007FFFE0007800780078003C0078001E0078001F0078000F0078000F8 +078000F8078000F8078000F8078000F8078000F8078001F0078001F0078003E0078007C0 +0F800F00FFFFFC001D227EA123> I<0007E0100038183000E0063001C00170038000F007 +0000F00E0000701E0000701C0000303C0000303C0000307C0000107800001078000010F8 +000000F8000000F8000000F8000000F8000000F8000000F8000000F80000007800000078 +0000107C0000103C0000103C0000101C0000201E0000200E000040070000400380008001 +C0010000E0020000381C000007E0001C247DA223> I<FFFFF0000F801E00078007000780 +0380078001C0078000E0078000F007800078078000780780007C0780003C0780003C0780 +003C0780003E0780003E0780003E0780003E0780003E0780003E0780003E0780003E0780 +003E0780003C0780003C0780007C0780007807800078078000F0078000E0078001E00780 +03C0078007000F801E00FFFFF0001F227EA125> I<FFFFFFC00F8007C0078001C0078000 +C00780004007800040078000600780002007800020078000200780202007802000078020 +0007802000078060000780E00007FFE0000780E000078060000780200007802000078020 +000780200007800000078000000780000007800000078000000780000007800000078000 +00078000000FC00000FFFE00001B227EA120> 70 D<0007F008003C0C1800E0021801C0 +01B8038000F8070000780F0000381E0000381E0000183C0000183C0000187C0000087800 +000878000008F8000000F8000000F8000000F8000000F8000000F8000000F8000000F800 +1FFF780000F8780000787C0000783C0000783C0000781E0000781E0000780F0000780700 +0078038000B801C000B800E00318003C0C080007F00020247DA226> I<FFFC3FFF0FC003 +F0078001E0078001E0078001E0078001E0078001E0078001E0078001E0078001E0078001 +E0078001E0078001E0078001E0078001E0078001E007FFFFE0078001E0078001E0078001 +E0078001E0078001E0078001E0078001E0078001E0078001E0078001E0078001E0078001 +E0078001E0078001E0078001E00FC003F0FFFC3FFF20227EA125> I<FFFC0FC007800780 +078007800780078007800780078007800780078007800780078007800780078007800780 +07800780078007800780078007800780078007800FC0FFFC0E227EA112> I<FFFC00FF80 +0FC0007C0007800030000780002000078000400007800080000780010000078002000007 +80040000078008000007801000000780200000078040000007808000000781C000000783 +E000000785E000000788F000000790F0000007A078000007C03C000007803C000007801E +000007800F000007800F00000780078000078007C000078003C000078001E000078001E0 +00078000F000078000F8000FC000FC00FFFC07FF8021227EA126> 75 +D<FFFC001F80000F00000F00000F00000F00000F00000F00000F00000F00000F00000F00 +000F00000F00000F00000F00000F00000F00000F00000F00000F00000F00000F00010F00 +010F00010F00010F00030F00030F00020F00060F00060F001E1F007EFFFFFE18227DA11E +> I<FF8007FF07C000F807C0007005E0002004F0002004F0002004780020047C0020043C +0020041E0020041F0020040F002004078020040780200403C0200401E0200401E0200400 +F0200400F8200400782004003C2004003E2004001E2004000F2004000F20040007A00400 +03E0040003E0040001E0040001E0040000E00E0000601F000060FFE0002020227EA125> +78 D<000FE00000783C0000E00E0003C00780078003C00F0001E00E0000E01E0000F03C +0000783C0000787C00007C7C00007C7800003C7800003CF800003EF800003EF800003EF8 +00003EF800003EF800003EF800003EF800003EF800003E7800003C7C00007C7C00007C3C +0000783E0000F81E0000F00F0001E00F0001E0078003C003C0078000E00E0000783C0000 +0FE0001F247DA226> I<FFFFF0000F803C0007800F0007800780078007C0078003C00780 +03E0078003E0078003E0078003E0078003E0078003E0078003C0078007C0078007800780 +0F0007803C0007FFF0000780000007800000078000000780000007800000078000000780 +0000078000000780000007800000078000000780000007800000078000000FC00000FFFC +00001B227EA121> I<FFFFE000000F803C000007800E00000780078000078007C0000780 +03C000078003E000078003E000078003E000078003E000078003E000078003C000078007 +C000078007800007800E000007803C000007FFE000000780700000078038000007801C00 +0007801E000007800E000007800F000007800F000007800F000007800F000007800F8000 +07800F800007800F800007800F808007800FC080078007C0800FC003C100FFFC01E20000 +00007C0021237EA124> 82 D<03F0200C0C601802603001E07000E0600060E00060E000 +60E00020E00020E00020F00000F000007800007F00003FF0001FFE000FFF0003FF80003F +C00007E00001E00000F00000F0000070800070800070800070800070C00060C00060E000 +C0F000C0C80180C6070081FC0014247DA21B> I<7FFFFFF8780780786007801840078008 +4007800840078008C007800C800780048007800480078004800780040007800000078000 +000780000007800000078000000780000007800000078000000780000007800000078000 +000780000007800000078000000780000007800000078000000780000007800000078000 +00078000000FC00001FFFE001E227EA123> I<FFF0007FC01F80001F000F00000C000F80 +000C000780000800078000080003C000100003C000100003C000100001E000200001E000 +200001F000600000F000400000F000400000780080000078008000007C008000003C0100 +00003C010000001E020000001E020000001E020000000F040000000F040000000F8C0000 +000788000000078800000003D000000003D000000003F000000001E000000001E0000000 +00C000000000C000000000C0000022237FA125> 86 D<FFF03FFC03FE1F8007E000F80F +0003C000700F0003C000200F0001E00020078001E00040078001E00040078003F0004003 +C002F0008003C002F0008003C002F0008003E00478018001E00478010001E00478010001 +E0083C010000F0083C020000F0083C020000F0101E02000078101E04000078101E040000 +78200F0400003C200F0800003C200F0800003C600F8800001E40079000001E4007900000 +1E4007D000001F8003F000000F8003E000000F8003E000000F0001E00000070001C00000 +070001C00000060000C0000002000080002F237FA132> I<FEFEC0C0C0C0C0C0C0C0C0C0 +C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0FE +FE07317BA40E> 91 D<FEFE060606060606060606060606060606060606060606060606 +060606060606060606060606060606060606060606FEFE07317FA40E> 93 +D<1FE000303800780C00780E0030070000070000070000070000FF0007C7001E07003C07 +00780700700700F00708F00708F00708F00F087817083C23900FC1E015157E9418> 97 +D<0E0000FE00001E00000E00000E00000E00000E00000E00000E00000E00000E00000E00 +000E00000E00000E1F000E61C00E80600F00300E00380E003C0E001C0E001E0E001E0E00 +1E0E001E0E001E0E001E0E001E0E001C0E003C0E00380F00700C80600C41C0083F001723 +7FA21B> I<01FE000703000C07801C0780380300780000700000F00000F00000F00000F0 +0000F00000F00000F000007000007800403800401C00800C010007060001F80012157E94 +16> I<0000E0000FE00001E00000E00000E00000E00000E00000E00000E00000E00000E0 +0000E00000E00000E001F8E00704E00C02E01C01E03800E07800E07000E0F000E0F000E0 +F000E0F000E0F000E0F000E0F000E07000E07800E03800E01801E00C02E0070CF001F0FE +17237EA21B> I<01FC000707000C03801C01C03801C07801E07000E0F000E0FFFFE0F000 +00F00000F00000F00000F000007000007800203800201C00400E008007030000FC001315 +7F9416> I<003E0000E30001C78003878003078007000007000007000007000007000007 +0000070000070000070000FFF80007000007000007000007000007000007000007000007 +00000700000700000700000700000700000700000700000700000700000700000780007F +F000112380A20F> I<00007003F1980E1E181C0E18380700380700780780780780780780 +7807803807003807001C0E001E1C0033F0002000002000003000003800003FFE001FFFC0 +0FFFE03000F0600030C00018C00018C00018C000186000306000303800E00E038003FE00 +15217F9518> I<0E0000FE00001E00000E00000E00000E00000E00000E00000E00000E00 +000E00000E00000E00000E00000E1F800E60C00E80E00F00700F00700E00700E00700E00 +700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00 +70FFE7FF18237FA21B> I<1C003E003E003E001C00000000000000000000000000000000 +000E007E001E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E +000E000E00FFC00A227FA10E> I<00E001F001F001F000E0000000000000000000000000 +00000000007007F000F00070007000700070007000700070007000700070007000700070 +00700070007000700070007000700070007000706070F0E0F0C061803F000C2C83A10F> +I<0E0000FE00001E00000E00000E00000E00000E00000E00000E00000E00000E00000E00 +000E00000E00000E03FC0E01F00E01C00E01800E02000E04000E08000E10000E38000EF8 +000F1C000E1E000E0E000E07000E07800E03C00E01C00E01E00E00F00E00F8FFE3FE1723 +7FA21A> I<0E00FE001E000E000E000E000E000E000E000E000E000E000E000E000E000E +000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E000E +00FFE00B237FA20E> I<0E1FC07F00FE60E183801E807201C00F003C00E00F003C00E00E +003800E00E003800E00E003800E00E003800E00E003800E00E003800E00E003800E00E00 +3800E00E003800E00E003800E00E003800E00E003800E00E003800E00E003800E00E0038 +00E0FFE3FF8FFE27157F942A> I<0E1F80FE60C01E80E00F00700F00700E00700E00700E +00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E +0070FFE7FF18157F941B> I<01FC000707000C01801800C03800E0700070700070F00078 +F00078F00078F00078F00078F00078F000787000707800F03800E01C01C00E0380070700 +01FC0015157F9418> I<0E1F00FE61C00E80600F00700E00380E003C0E003C0E001E0E00 +1E0E001E0E001E0E001E0E001E0E001E0E003C0E003C0E00380F00700E80E00E41C00E3F +000E00000E00000E00000E00000E00000E00000E00000E00000E0000FFE000171F7F941B +> I<01F8200704600E02601C01603801E07800E07800E0F000E0F000E0F000E0F000E0F0 +00E0F000E0F000E07800E07800E03801E01C01E00C02E0070CE001F0E00000E00000E000 +00E00000E00000E00000E00000E00000E00000E0000FFE171F7E941A> I<0E3CFE461E8F +0F0F0F060F000E000E000E000E000E000E000E000E000E000E000E000E000E000F00FFF0 +10157F9413> I<0F8830786018C018C008C008E008F0007F003FE00FF001F8003C801C80 +0C800CC00CC008E018D0308FC00E157E9413> I<02000200020002000600060006000E00 +1E003E00FFFC0E000E000E000E000E000E000E000E000E000E000E000E040E040E040E04 +0E040E040708030801F00E1F7F9E13> I<0E0070FE07F01E00F00E00700E00700E00700E +00700E00700E00700E00700E00700E00700E00700E00700E00700E00700E00F00E00F006 +017003827800FC7F18157F941B> I<FF80FE1E00781E00300E00200E0020070040070040 +0780C003808003808001C10001C10000E20000E20000E200007400007400003800003800 +00380000100017157F941A> I<FF8FF87F3E01E03C1C01C0181C01E0180E01E0100E0260 +100E027010070270200704302007043820038438400388184003881C4001C81C8001D00C +8001D00E8000F00F0000E0070000E00700006006000040020020157F9423> I<FF83FE1F +00F00E00C007008007810003830001C20000E400007800007800003800003C00004E0000 +8F000187000103800201C00401E00C00E03E01F0FF03FE17157F941A> I<FF80FE1E0078 +1E00300E00200E00200700400700400780C003808003808001C10001C10000E20000E200 +00E200007400007400003800003800003800001000001000002000002000002000004000 +F04000F08000F180004300003C0000171F7F941A> I<3FFFC0380380300780200700600E +00401C00403C0040380000700000E00001E00001C0000380400700400F00400E00C01C00 +80380080780180700780FFFF8012157F9416> I<FFFFFFFFFFFF3001808C31> 124 +D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fl cmbx12 14.4 19 +/Fl 19 118 df<00007FE0030007FFFC07001FFFFF0F007FF00F9F00FF0001FF01FC0000 +FF03F800007F07F000003F0FE000001F1FC000001F1FC000000F3F8000000F3F80000007 +7F800000077F800000077F00000000FF00000000FF00000000FF00000000FF00000000FF +00000000FF00000000FF00000000FF00000000FF000000007F000000007F800000007F80 +0000073F800000073F800000071FC00000071FC000000E0FE000000E07F000001C03F800 +003C01FC00007800FF0001F0007FF007C0001FFFFF800007FFFE0000007FF00028297CA8 +31> 67 D<FFFFFC0000FFFFFC0000FFFFFC000003FC00000003FC00000003FC00000003 +FC00000003FC00000003FC00000003FC00000003FC00000003FC00000003FC00000003FC +00000003FC00000003FC00000003FC00000003FC00000003FC00000003FC00000003FC00 +000003FC00000003FC00000003FC00000003FC0001C003FC0001C003FC0001C003FC0001 +C003FC0003C003FC00038003FC00038003FC00078003FC00078003FC000F8003FC000F80 +03FC001F8003FC007F8003FC01FF00FFFFFFFF00FFFFFFFF00FFFFFFFF0022297EA828> +76 D<0000FFC00000000FFFFC0000003F807F000000FE001FC00001F80007E00003F000 +03F00007E00001F8000FE00001FC001FC00000FE001FC00000FE003F8000007F003F8000 +007F007F8000007F807F0000003F807F0000003F807F0000003F80FF0000003FC0FF0000 +003FC0FF0000003FC0FF0000003FC0FF0000003FC0FF0000003FC0FF0000003FC0FF0000 +003FC0FF0000003FC0FF0000003FC07F0000003F807F8000007F807F8000007F803F8000 +007F003F8000007F001FC00000FE001FC00000FE000FE00001FC0007F00003F80003F800 +07F00001FC000FE00000FE001FC000003FC0FF0000000FFFFC00000000FFC000002A297C +A833> 79 D<FFFFF0007FFFFFFFF0007FFFFFFFF0007FFF03FE000001C001FE00000380 +01FE0000038001FF0000078000FF0000070000FF80000F00007F80000E00007FC0000E00 +003FC0001C00003FC0001C00003FE0003C00001FE0003800001FF0007800000FF0007000 +000FF80070000007F800E0000007F800E0000003FC01C0000003FC01C0000003FE03C000 +0001FE0380000001FF0780000000FF0700000000FF87000000007F8E000000007F8E0000 +00007FDE000000003FDC000000003FFC000000001FF8000000001FF8000000000FF00000 +00000FF0000000000FF00000000007E00000000007E00000000003C00000000003C00000 +30297FA833> 86 D<03FF80000FFFF0001F01FC003F80FE003F807F003F803F003F803F +801F003F8000003F8000003F8000003F8000003F80003FFF8001FC3F800FE03F801F803F +803F003F807E003F80FC003F80FC003F80FC003F80FC003F80FC005F807E00DF803F839F +FC1FFE0FFC03FC03FC1E1B7E9A21> 97 D<FFE00000FFE00000FFE000000FE000000FE0 +00000FE000000FE000000FE000000FE000000FE000000FE000000FE000000FE000000FE0 +00000FE000000FE1FE000FEFFF800FFE07E00FF803F00FF001F80FE000FC0FE000FC0FE0 +007E0FE0007E0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0 +007F0FE0007E0FE0007E0FE0007E0FE000FC0FE000FC0FF001F80FF803F00F9C0FE00F0F +FF800E01FC00202A7EA925> I<00007FF000007FF000007FF0000007F0000007F0000007 +F0000007F0000007F0000007F0000007F0000007F0000007F0000007F0000007F0000007 +F0003F87F001FFF7F007F03FF00FC00FF01F8007F03F0007F03F0007F07E0007F07E0007 +F07E0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007 +F07E0007F07E0007F03F0007F03F0007F01F800FF00FC01FF007E07FFF01FFE7FF007F87 +FF202A7EA925> 100 D<003FC00001FFF00003E07C000F803E001F801F001F001F003F00 +0F807E000F807E000FC07E000FC0FE0007C0FE0007C0FFFFFFC0FFFFFFC0FE000000FE00 +0000FE0000007E0000007E0000007F0000003F0001C01F0001C00F80038007C0070003F0 +1E0000FFFC00003FE0001A1B7E9A1F> I<0007F8003FFC007E3E01FC7F03F87F03F07F07 +F07F07F03E07F00007F00007F00007F00007F00007F00007F000FFFFC0FFFFC0FFFFC007 +F00007F00007F00007F00007F00007F00007F00007F00007F00007F00007F00007F00007 +F00007F00007F00007F00007F00007F00007F00007F00007F0007FFF807FFF807FFF8018 +2A7EA915> I<FFE00000FFE00000FFE000000FE000000FE000000FE000000FE000000FE0 +00000FE000000FE000000FE000000FE000000FE000000FE000000FE000000FE07E000FE1 +FF800FE30FC00FE40FE00FE807E00FF807F00FF007F00FF007F00FE007F00FE007F00FE0 +07F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE0 +07F00FE007F00FE007F00FE007F00FE007F0FFFE3FFFFFFE3FFFFFFE3FFF202A7DA925> +104 D<07000F801FC03FE03FE03FE01FC00F8007000000000000000000000000000000FF +E0FFE0FFE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00F +E00FE00FE00FE00FE00FE0FFFEFFFEFFFE0F2B7EAA12> I<FFE0FFE0FFE00FE00FE00FE0 +0FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE0 +0FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE00FE0FFFEFFFEFFFE +0F2A7EA912> 108 D<FFC07E00FFC1FF80FFC30FC00FC40FE00FC807E00FD807F00FD007 +F00FD007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007 +F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F0FFFE3F +FFFFFE3FFFFFFE3FFF201B7D9A25> 110 D<003FE00001FFFC0003F07E000FC01F801F80 +0FC03F0007E03F0007E07E0003F07E0003F07E0003F0FE0003F8FE0003F8FE0003F8FE00 +03F8FE0003F8FE0003F8FE0003F8FE0003F87E0003F07E0003F03F0007E03F0007E01F80 +0FC00FC01F8007F07F0001FFFC00003FE0001D1B7E9A22> I<FFE1FE00FFEFFF80FFFE0F +E00FF803F00FF001F80FE001FC0FE000FC0FE000FE0FE000FE0FE0007F0FE0007F0FE000 +7F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007F0FE0007E0FE000FE0FE000FE0FE000 +FC0FE001FC0FF001F80FF807F00FFC0FE00FEFFF800FE1FC000FE000000FE000000FE000 +000FE000000FE000000FE000000FE000000FE000000FE00000FFFE0000FFFE0000FFFE00 +0020277E9A25> I<FFC1F0FFC7FCFFC63E0FCC7F0FD87F0FD07F0FD07F0FF03E0FE0000F +E0000FE0000FE0000FE0000FE0000FE0000FE0000FE0000FE0000FE0000FE0000FE0000F +E0000FE0000FE000FFFF00FFFF00FFFF00181B7F9A1B> 114 D<03FE300FFFF03E03F078 +00F07000F0F00070F00070F80070FE0000FFE0007FFF007FFFC03FFFE01FFFF007FFF800 +FFF80007FC0000FCE0007CE0003CF0003CF00038F80038FC0070FF01E0E7FFC0C1FF0016 +1B7E9A1B> I<00E00000E00000E00000E00001E00001E00001E00003E00003E00007E000 +0FE0001FFFE0FFFFE0FFFFE00FE0000FE0000FE0000FE0000FE0000FE0000FE0000FE000 +0FE0000FE0000FE0000FE0000FE0000FE0700FE0700FE0700FE0700FE0700FE0700FE070 +07F0E003F0C001FF80007F0014267FA51A> I<FFE07FF0FFE07FF0FFE07FF00FE007F00F +E007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00F +E007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE007F00FE00FF00F +E00FF007E017F003F067FF01FFC7FF007F87FF201B7D9A25> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fm cmr12 14.4 20 +/Fm 20 118 df<78FCFCFEFE7A02020202040404080810204007127B8510> 44 +D<00200000E00001E0000FE000FFE000F1E00001E00001E00001E00001E00001E00001E0 +0001E00001E00001E00001E00001E00001E00001E00001E00001E00001E00001E00001E0 +0001E00001E00001E00001E00001E00001E00001E00001E00001E00001E00001E00001E0 +0001E00003F000FFFFC0FFFFC012287BA71D> 49 D<01FC0007FF000C0FC01803E02001 +F06001F04000F84000F8F800FCFC00FCFC007CFC007CFC007C7800FC0000FC0000F80000 +F80001F00001F00003E00003C0000780000700000E00001C0000380000300000600000C0 +000180000300040200040400080800081000082000183FFFF87FFFF0FFFFF0FFFFF01628 +7DA71D> I<000FC0003FF000F01801C01803803C07007C0F007C0E00381E00003C00003C +00003C0000780000780000780000F83F00F8C1C0F900E0FA0070FA0038FC003CFC001EFC +001EF8001EF8001FF8001FF8001FF8001F78001F78001F78001F78001F3C001E3C001E1C +003C1E003C0E007807007003C1E001FFC0007E0018297EA71D> 54 +D<007E0001FF800781C00F00E01E00703C00383C003878003C78003CF8001EF8001EF800 +1EF8001EF8001FF8001FF8001FF8001F78001F78003F78003F3C003F1C005F0E005F0700 +9F03831F00FC1F00001E00001E00001E00003E00003C00003C0000381C00783E00703E00 +E03C01C01803801C0F000FFE0003F80018297EA71D> 57 D<0000FF00100007FFE03000 +1FC07830003E000C7000F80006F001F00003F003E00001F007C00000F00F800000700F80 +0000701F000000303F000000303E000000303E000000107E000000107E000000107C0000 +0000FC00000000FC00000000FC00000000FC00000000FC00000000FC00000000FC000000 +00FC00000000FC0000FFFF7C0000FFFF7E000003F07E000001F03E000001F03E000001F0 +3F000001F01F000001F00F800001F00F800001F007C00001F003E00001F001F00002F000 +F80002F0003E000C70001FC038300007FFE0100000FF8000282B7DA92E> 71 +D<01FFFE01FFFE0007E00003E00003E00003E00003E00003E00003E00003E00003E00003 +E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003 +E00003E00003E00003E00003E00003E00003E00003E03003E07803E0FC03E0FC03E0FC03 +C0F807C0400780200F00300E000C3C0003F000172A7DA81E> 74 +D<0001FF0000000F01E000003C0078000078003C0000E0000E0001E0000F0003C0000780 +07800003C00F800003E01F000001F01F000001F03E000000F83E000000F87E000000FC7E +000000FC7C0000007C7C0000007CFC0000007EFC0000007EFC0000007EFC0000007EFC00 +00007EFC0000007EFC0000007EFC0000007EFC0000007E7C0000007C7E000000FC7E0000 +00FC7E000000FC3E000000F83F000001F81F000001F01F000001F00F800003E007800003 +C007C00007C003E0000F8000F0001E000078003C00003C007800000F01E0000001FF0000 +272B7DA92E> 79 D<03FC00000C070000100380003C01C0003E01E0003E00F0001C00F0 +000800F0000000F0000000F0000000F000007FF00003E0F0000F80F0001E00F0003C00F0 +007C00F0007800F040F800F040F800F040F800F040F801F0407C01F0403C0278801E0C7F +8007F01E001A1A7E991D> 97 D<0F000000FF000000FF0000001F0000000F0000000F00 +00000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F0000000F00 +00000F0000000F07E0000F1838000F600E000F8007000F8007800F0003C00F0003C00F00 +01E00F0001E00F0001F00F0001F00F0001F00F0001F00F0001F00F0001F00F0001F00F00 +01E00F0001E00F0003E00F0003C00F0003800F8007800E800F000E401C000C303800080F +C0001C2A7EA921> I<007F0001C0E00700100E00781E00F83C00F83C00707C0020780000 +F80000F80000F80000F80000F80000F80000F80000F800007800007C00003C00083C0008 +1E00100E002007006001C180007E00151A7E991A> I<00FC000387800701C00E01E01C00 +E03C00F03C00F0780078780078F80078F80078FFFFF8F80000F80000F80000F80000F800 +007800007800003C00083C00081E00100E002007004001C180007E00151A7E991A> 101 +D<00000F0001FC3080070743800E03C3801E03C1003C01E0003C01E0007C01F0007C01F0 +007C01F0007C01F0007C01F0003C01E0003C01E0001E03C0000E0380001707000011FC00 +0030000000300000003000000030000000180000001FFF80000FFFF00007FFF80018007C +0030001E0070000E0060000700E0000700E0000700E0000700E000070070000E0070000E +0038001C001C0038000781E00000FF000019287E9A1D> 103 D<1E003F003F003F003F00 +1E000000000000000000000000000000000000000F00FF00FF001F000F000F000F000F00 +0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00FFF0FFF0 +0C297EA811> 105 D<007E0003C3C00700E00E00701C00383C003C3C003C78001E78001E +F8001FF8001FF8001FF8001FF8001FF8001FF8001FF8001F78001E78001E3C003C3C003C +1C00380E00700700E003C3C0007E00181A7E991D> 111 D<003F010001E0830003804300 +0F0027001E0017001E001F003C000F007C000F007C000F0078000F00F8000F00F8000F00 +F8000F00F8000F00F8000F00F8000F00F8000F007C000F007C000F003C000F003E001F00 +1E001F000F002F0007804F0001C18F00007E0F0000000F0000000F0000000F0000000F00 +00000F0000000F0000000F0000000F0000000F0000000F000000FFF00000FFF01C267E99 +1F> 113 D<0F0F80FF11C0FF23E01F43E00F83E00F81C00F80000F00000F00000F00000F +00000F00000F00000F00000F00000F00000F00000F00000F00000F00000F00000F00000F +00000F8000FFFC00FFFC00131A7E9917> I<07F0801C0D80300380600180E00180E00080 +E00080F00080F800007E00007FE0003FFC001FFE0007FF00003F800007808003C08003C0 +8001C0C001C0C001C0E00180E00380F00300CC0E0083F800121A7E9917> I<0080000080 +000080000080000180000180000180000380000380000780000F80001FFF80FFFF800780 +000780000780000780000780000780000780000780000780000780000780000780000780 +0007804007804007804007804007804007804007804003C08001C08000E100003E001225 +7FA417> I<0F000F00FF00FF00FF00FF001F001F000F000F000F000F000F000F000F000F +000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F +000F000F000F000F000F000F000F001F000F001F0007002F0003804F8001C08FF0007F0F +F01C1A7E9921> I E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fn cmr17 20.74 18 +/Fn 18 119 df<000001FF00008000001FFFE0018000007F007801800001F8000E038000 +03E000070780000FC000018780001F000000CF80003E0000006F80007C0000003F8000F8 +0000003F8001F00000001F8003F00000000F8007E00000000F8007C000000007800FC000 +000007800FC000000007801F8000000003801F8000000003803F8000000003803F000000 +0001803F0000000001807F0000000001807F0000000001807E0000000000007E00000000 +0000FE000000000000FE000000000000FE000000000000FE000000000000FE0000000000 +00FE000000000000FE000000000000FE000000000000FE000000000000FE000000000000 +FE0000000000007E0000000000007E0000000000007F0000000000007F0000000001803F +0000000001803F0000000001803F8000000001801F8000000001801F8000000003000FC0 +00000003000FC0000000030007E0000000060007E0000000060003F0000000060001F000 +00000C0000F80000001800007C0000001800003E0000003000001F0000006000000FC000 +01C0000003E0000380000001F8000E000000007F007C000000001FFFF00000000001FF00 +0000313D7CBB39> 67 D<FFFFFC000000FFFFFC00000003FE0000000001F80000000001 +F80000000001F80000000001F80000000001F80000000001F80000000001F80000000001 +F80000000001F80000000001F80000000001F80000000001F80000000001F80000000001 +F80000000001F80000000001F80000000001F80000000001F80000000001F80000000001 +F80000000001F80000000001F80000000001F80000000001F80000000001F80000000001 +F80000000001F80000000001F80000000001F80000000001F80000000001F80000000001 +F80000000001F80000000001F80000000001F80000006001F80000006001F80000006001 +F80000006001F80000006001F8000000E001F8000000C001F8000000C001F8000000C001 +F8000000C001F8000001C001F8000001C001F8000001C001F8000003C001F8000007C001 +F8000007C001F800000FC001F800003F8001F80000FF8003FC0007FF80FFFFFFFFFF80FF +FFFFFFFF802B3B7CBA32> 76 D<000003FF00000000001E01E000000000F0003C000000 +03C0000F000000078000078000000F000003C000003E000001F000007C000000F80000F8 +0000007C0001F00000003E0001F00000003E0003E00000001F0007E00000001F8007C000 +00000F800FC00000000FC00F8000000007C01F8000000007E01F8000000007E03F000000 +0003F03F0000000003F03F0000000003F07F0000000003F87E0000000001F87E00000000 +01F87E0000000001F8FE0000000001FCFE0000000001FCFE0000000001FCFE0000000001 +FCFE0000000001FCFE0000000001FCFE0000000001FCFE0000000001FCFE0000000001FC +FE0000000001FCFE0000000001FC7E0000000001F87F0000000003F87F0000000003F87F +0000000003F87F0000000003F83F0000000003F03F8000000007F01F8000000007E01F80 +00000007E01FC00000000FE00FC00000000FC007C00000000F8007E00000001F8003E000 +00001F0001F00000003E0001F80000007E0000F80000007C00007C000000F800003E0000 +01F000000F000003C000000780000780000003E0001F00000000F8007C000000001E01E0 +0000000003FF000000363D7CBB3E> 79 D<003F80000001C0F0000003003C000004001E +00000C000F000018000780001C0007C0003E0003C0003F0003E0003F0003E0003F0003E0 +001E0003E000000003E000000003E000000003E00000003FE000000FF3E000007E03E000 +01F803E00003E003E0000FC003E0001F8003E0003F0003E0003E0003E0007E0003E0007E +0003E060FC0003E060FC0003E060FC0003E060FC0007E060FC0007E0607C000BE0607E00 +0BE0603E0011F0C01F0060F0C007C1807F8000FE003E0023257CA427> 97 +D<03E0000000FFE0000000FFE000000007E000000003E000000003E000000003E0000000 +03E000000003E000000003E000000003E000000003E000000003E000000003E000000003 +E000000003E000000003E000000003E000000003E000000003E000000003E000000003E0 +00000003E000000003E03FC00003E0E0780003E3001C0003E6000F0003E800078003F800 +03C003F00001E003E00001F003E00000F003E00000F803E00000F803E00000FC03E00000 +7C03E000007C03E000007E03E000007E03E000007E03E000007E03E000007E03E000007E +03E000007E03E000007E03E000007E03E000007C03E000007C03E00000FC03E00000F803 +E00000F803E00001F003E00001E003F00003E003D80003C003C80007800384000E000383 +001C000381C0F00003003F8000273C7EBB2C> I<0007F800003C0E0000F0018001E000C0 +03C00060078000300F0000701F0000F81F0001F83E0001F83E0001F87E0000F07C000000 +7C000000FC000000FC000000FC000000FC000000FC000000FC000000FC000000FC000000 +FC0000007C0000007C0000007E0000003E0000003E00000C1F00000C1F0000180F800018 +0780003003C0006001E000C000F00180003C0E000007F8001E257DA423> I<0007F80000 +3C1E0000F0078001C003C003C001E0078000F00F0000F81F0000781E00007C3E00007C3E +00007C7E00003E7C00003E7C00003EFC00003EFC00003EFFFFFFFEFC000000FC000000FC +000000FC000000FC000000FC0000007C0000007C0000007E0000003E0000003E0000061F +0000060F00000C0F80000C0780001803C0003000E00060007000C0001E07000003FC001F +257EA423> 101 D<0000FC0000078300000E0380001C07C0003C0FC000780FC000F80FC0 +00F8078000F0000001F0000001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0000001F0000001F00000FFFFFC00FFFFFC00 +01F0000001F0000001F0000001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0000003F800007FFFE0007FFFE0001A3C7FBB +18> I<07000F801FC01FC01FC00F80070000000000000000000000000000000000000000 +0000000000000007C0FFC0FFC00FC007C007C007C007C007C007C007C007C007C007C007 +C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007 +C007C00FE0FFFEFFFE0F397DB815> 105 D<0003800007C0000FE0000FE0000FE00007C0 +000380000000000000000000000000000000000000000000000000000000000000000000 +0000000000000007E000FFE000FFE0000FE00003E00003E00003E00003E00003E00003E0 +0003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E0 +0003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E0 +0003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E00003E0 +7803C0FC07C0FC0780FC0780FC0F00780E00381C000FE000134A82B818> I<07C0FFC0FF +C00FC007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007 +C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007 +C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007C007 +C00FE0FFFEFFFE0F3C7DBB15> 108 D<03E01FE0003FC000FFE0607C00C0F800FFE0801E +01003C0007E3000F06001E0003E4000F88001F0003E4000F88001F0003E8000790000F00 +03E80007D0000F8003F00007E0000F8003F00007E0000F8003E00007C0000F8003E00007 +C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F80 +03E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007 +C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F80 +03E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007 +C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F8003E00007C0000F80 +07F0000FE0001FC0FFFF81FFFF03FFFEFFFF81FFFF03FFFE3F257EA443> I<03E01FE000 +FFE0607C00FFE0801E0007E3000F0003E4000F8003E4000F8003E800078003E80007C003 +F00007C003F00007C003E00007C003E00007C003E00007C003E00007C003E00007C003E0 +0007C003E00007C003E00007C003E00007C003E00007C003E00007C003E00007C003E000 +07C003E00007C003E00007C003E00007C003E00007C003E00007C003E00007C003E00007 +C003E00007C003E00007C003E00007C003E00007C007F0000FE0FFFF81FFFFFFFF81FFFF +28257EA42C> I<0007FC0000001C070000007001C00001E000F00003C00078000780003C +000F00001E001F00001F001E00000F003E00000F803E00000F807C000007C07C000007C0 +7C000007C0FC000007E0FC000007E0FC000007E0FC000007E0FC000007E0FC000007E0FC +000007E0FC000007E0FC000007E07C000007C07C000007C07E00000FC03E00000F803E00 +000F801E00000F001F00001F000F00001E000780003C0003C000780001E000F000007001 +C000001C0700000007FC000023257EA427> I<03E03E00FFE0C300FFE1078007E20FC003 +E40FC003E80FC003E8078003E8030003F0000003F0000003F0000003E0000003E0000003 +E0000003E0000003E0000003E0000003E0000003E0000003E0000003E0000003E0000003 +E0000003E0000003E0000003E0000003E0000003E0000003E0000003E0000003E0000003 +E0000003E0000003E0000007F00000FFFFC000FFFFC0001A257EA41E> 114 +D<00FF02000700C6000C002E0010001E0030001E0060000E0060000E00E0000600E00006 +00E0000600F0000600F8000600FC0000007F0000003FF000003FFF80000FFFE00007FFF0 +0001FFFC00003FFE000001FE0000003F00C0001F00C0000F80C0000780E0000380E00003 +80E0000380E0000380F0000300F0000300F8000700F8000600E4000C00E2001800C18070 +00807F800019257DA41F> I<003000000030000000300000003000000030000000300000 +0070000000700000007000000070000000F0000000F0000001F0000001F0000003F00000 +07F000001FFFFE00FFFFFE0001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0000001F0000001F0000001F0000001F00000 +01F0000001F0000001F0000001F0000001F0018001F0018001F0018001F0018001F00180 +01F0018001F0018001F0018001F0018000F0010000F8030000F8030000780200003C0400 +000E08000003F00019357FB41E> I<FFFE000FFFFFFE000FFF07F00007F803E00003E003 +E00001C001F00001C001F000018001F800018000F800030000F8000300007C000600007C +000600007E000600003E000C00003E000C00003F001C00001F001800001F001800000F80 +3000000F803000000FC070000007C060000007C060000003E0C0000003E0C0000003F1C0 +000001F180000001F180000000FB00000000FB00000000FF000000007E000000007E0000 +00003C000000003C000000003C0000000018000028257FA42A> 118 +D E +%EndDVIPSBitmapFont +end +%%EndProlog +%%BeginSetup +%%Feature: *Resolution 300dpi +TeXDict begin +%%PaperSize: a4 + +userdict/PStoPSxform PStoPSmatrix matrix currentmatrix + matrix invertmatrix matrix concatmatrix + matrix invertmatrix put +%%EndSetup +%%Page: (0,1) 1 +userdict/PStoPSsaved save put +PStoPSmatrix setmatrix +595.000000 0.271378 translate +90 rotate +0.706651 dup scale +userdict/PStoPSmatrix matrix currentmatrix put +userdict/PStoPSclip{0 0 moveto + 595.000000 0 rlineto 0 842.000000 rlineto -595.000000 0 rlineto + closepath}put initclip +/showpage{}def/copypage{}def/erasepage{}def +PStoPSxform concat +1 0 bop Fn 281 370 a(Cleaner) p 570 370 a(seman) n(tics) p +927 370 a(for) p 1047 370 a(Ob) t(jectiv) n(e) p 1404 +370 a(Lab) r(el) p Fm 717 518 a(Jacques) p 934 518 a(Garrigue) 719 +634 y(Octob) r(er) p 945 634 a(26,) p 1040 634 a(1999) p +Fl 11 836 a(Credits) p Fk 11 929 a(This) p 122 929 a(prop) q(osal) p +319 929 a(con) o(tains) p 510 929 a(ideas) p 632 929 +a(from) p 747 929 a(Damien) p 928 929 a(Doligez) p 1101 +929 a(and) p 1196 929 a(Pierre) p 1340 929 a(W) l(eis.) p +Fl 11 1073 a(Lab) r(els) p 221 1073 a(and) p 351 1073 +a(optionals) p Fk 11 1165 a(Lab) q(els) p 165 1165 a(and) p +259 1165 a(optional) p 449 1165 a(argumen) o(ts) p 687 +1165 a(had) p 781 1165 a(t) o(w) o(o) p 873 1165 a(problems) p +1082 1165 a(in) p 1139 1165 a(Ob) s(jectiv) o(e) p 1360 +1165 a(Lab) q(el.) p Fj 83 1280 a(\017) p Fk 133 1280 +a(They) p 259 1280 a(w) o(ere) p 372 1280 a(not) p 459 +1280 a(fully) p 570 1280 a(coheren) o(t) p 767 1280 a(with) p +878 1280 a(the) p 963 1280 a(original) p 1139 1280 a(call-b) o(y-v) m +(alue) p 1423 1280 a(seman) o(tics) p 1644 1280 a(of) p +1700 1280 a(the) p 1784 1280 a(lan-) 133 1340 y(guage.) p +303 1340 a(In) p 368 1340 a(some) p 495 1340 a(\(subtle\)) p +681 1340 a(cases,) p 823 1340 a(a) p 868 1340 a(side-e\013ect) p +1099 1340 a(migh) o(t) p 1243 1340 a(get) p 1329 1340 +a(dela) o(y) o(ed) p 1508 1340 a(more) p 1635 1340 a(than) p +1753 1340 a(in) p 1814 1340 a(an) 133 1400 y(un) o(t) o(yp) q(ed) p +322 1400 a(seman) o(tics.) p Fj 83 1502 a(\017) p Fk +133 1502 a(F) l(or) p 220 1502 a(optional) p 410 1502 +a(argumen) o(ts,) p 660 1502 a(no) p 728 1502 a(un) o(t) o(yp) q(ed) p +918 1502 a(seman) o(tics) p 1139 1502 a(existed.) 84 +1616 y(This) p 195 1616 a(new) p 295 1616 a(prop) q(osal) p +492 1616 a(corrects) p 674 1616 a(these) p 799 1616 a(t) o(w) o(o) p +891 1616 a(\015a) o(ws.) p Fi 11 1746 a(Syn) n(tax) p +Fk 11 1838 a(W) l(e) p 95 1838 a(k) o(eep) p 206 1838 +a(Ob) s(jectiv) o(e) p 426 1838 a(Lab) q(el's) p 594 +1838 a(syn) o(tax,) p 764 1838 a(except) p 917 1838 a(for) p +991 1838 a(default) p 1155 1838 a(v) m(alues) p 1301 +1838 a(in) p 1357 1838 a(optional) p 1547 1838 a(argumen) o(ts.) p +Fh 329 1944 a(typ) n(expr) p Fk 528 1944 a(::=) p Fg +634 1944 a(:) p 656 1944 a(:) p 678 1944 a(:) p Fj 579 +2004 a(j) p Fh 634 2004 a(typ) n(expr) p Fj 806 2004 +a(!) p Fh 870 2004 a(typ) n(expr) p Fj 579 2064 a(j) p +Fk 634 2064 a([?]) p Fi(lab) r(el) p Fk 801 2064 a(:) p +Fh(typ) n(expr) p Fj 987 2064 a(!) p Fh 1050 2064 a(typ) n(expr) 391 +2124 y(expr) p Fk 528 2124 a(::=) p Fg 634 2124 a(:) p +656 2124 a(:) p 678 2124 a(:) p Fj 579 2185 a(j) p Fh +634 2185 a(expr) p 746 2185 a(lab) n(ele) n(d-expr) p +Ff 991 2163 a(+) p Fj 579 2245 a(j) p Fe 634 2245 a(fun) p +Fj 728 2245 a(f) p Fh(lab) n(ele) n(d-simple-p) n(attern) p +Fj 1209 2245 a(g) p Ff 1234 2227 a(+) p Fk 1280 2245 +a([) p Fe(when) p Fh 1412 2245 a(expr) p Fk 1507 2245 +a(]) p Fj 1535 2245 a(!) p Fh 1599 2245 a(expr) p Fj +579 2305 a(j) p Fe 634 2305 a(function) p Fh 856 2305 +a(lab) n(ele) n(d-p) n(attern) p Fk 1177 2305 a([) p +Fe(when) p Fh 1309 2305 a(expr) p Fk 1404 2305 a(]) p +Fj 1432 2305 a(!) p Fh 1496 2305 a(expr) p Fj 785 2365 +a(f) p Fe(|) p Fh 851 2365 a(lab) n(ele) n(d-p) n(attern) p +Fk 1172 2365 a([) p Fe(when) p Fg 1305 2365 a(expr) p +Fk 1403 2365 a(]) p Fj 1430 2365 a(!) p Fh 1494 2365 +a(expr) p Fj 1589 2365 a(g) p Fd 1614 2347 a(\003) p +Fh 242 2425 a(lab) n(ele) n(d-expr) p Fk 528 2425 a(::=) p +634 2425 a([?]) p Fh(expr) p Fj 579 2486 a(j) p Fk 634 +2486 a([?]) p Fi(lab) r(el) p Fk 801 2486 a(:) p Fh(expr) 182 +2546 y(lab) n(ele) n(d-p) n(attern) p Fk 528 2546 a(::=) p +Fh 634 2546 a(p) n(attern) p Fj 579 2606 a(j) p Fi 634 +2606 a(lab) r(el) p Fk 751 2606 a(:) p Fh(p) n(attern) p +Fj 579 2666 a(j) p Fk 634 2666 a(?[) p Fe(\() p Fh(expr) p +Fe(\)) p Fk(]) p Fi(lab) r(el) p Fk 943 2666 a(:) p Fh +956 2666 a(p) n(attern) p Fk 926 2937 a(1) p eop +PStoPSsaved restore +userdict/PStoPSsaved save put +PStoPSmatrix setmatrix +595.000000 421.271378 translate +90 rotate +0.706651 dup scale +userdict/PStoPSmatrix matrix currentmatrix put +userdict/PStoPSclip{0 0 moveto + 595.000000 0 rlineto 0 842.000000 rlineto -595.000000 0 rlineto + closepath}put initclip +PStoPSxform concat +2 1 bop Fi 11 168 a(Dynamic) p 247 168 a(seman) n(tics) p +Fj 11 261 a(;) p Fk 52 261 a(is) p 101 261 a(a) p 141 +261 a(notation) p 337 261 a(for) p 411 261 a(the) p 495 +261 a(empt) o(y) p 644 261 a(lab) q(el.) 86 366 y(\() p +Fe(fun) p Fi 198 366 a(l) p Fc 214 373 a(i) p Fk 227 +366 a(:) p Fg(x) p Fj 282 366 a(!) p Fg 346 366 a(e) p +Fk(\)) p Fi 404 366 a(l) p Fc 420 373 a(1) p Fk 442 366 +a(:) p Fg 455 366 a(e) p Ff 478 373 a(1) p Fg 506 366 +a(:) p 528 366 a(:) p 550 366 a(:) p Fi 571 366 a(l) p +Fc 587 373 a(n) p Fk 612 366 a(:) p Fg 625 366 a(e) p +Fb 648 373 a(n) p Fj 515 427 a(!) p Fk 579 427 a(\() p +Fg(e) p Fk([) p Fg(e) p Fb 658 434 a(i) p Fg 671 427 +a(=x) p Fk(]) p Fi 752 427 a(l) p Fc 768 434 a(1) p Fk +790 427 a(:) p Fg(e) p Ff 827 434 a(1) p Fg 855 427 a(:) p +877 427 a(:) p 899 427 a(:) p Fi 920 427 a(l) p Fc 936 +434 a(i) p Fd(\000) p Fc(1) p Fk 997 427 a(:) p Fg 1010 +427 a(e) p Fb 1033 434 a(i) p Fd(\000) p Ff(1) p Fi 1108 +427 a(l) p Fc 1124 434 a(i) p Ff(+) p Fc(1) p Fk 1185 +427 a(:) p Fg(e) p Fb 1222 434 a(i) p Ff(+1) p Fg 1289 +427 a(:) p 1311 427 a(:) p 1333 427 a(:) p Fi 1354 427 +a(l) p Fc 1370 434 a(n) p Fk 1395 427 a(:) p Fg 1408 +427 a(e) p Fb 1431 434 a(n) p Fk 86 487 a(\() p Fe(fun) p +Fk 198 487 a(?) p Fi(l) p Fc 237 494 a(i) p Fk 250 487 +a(:) p Fg(x) p Fj 305 487 a(!) p Fg 369 487 a(e) p Fk(\)) p +Fi 427 487 a(l) p Fc 443 494 a(1) p Fk 465 487 a(:) p +Fg 478 487 a(e) p Ff 501 494 a(1) p Fg 529 487 a(:) p +551 487 a(:) p 573 487 a(:) p Fi 594 487 a(l) p Fc 610 +494 a(n) p Fk 635 487 a(:) p Fg 648 487 a(e) p Fb 671 +494 a(n) p Fj 515 547 a(!) p Fg 579 547 a(e) p Fk([) p +Fe(Some) p Fk 717 547 a(\() p Fg(e) p Fb 759 554 a(i) p +Fk 773 547 a(\)) p Fg(=x) p Fk(]) p Fi 874 547 a(l) p +Fc 890 554 a(1) p Fk 912 547 a(:) p Fg 925 547 a(e) p +Ff 948 554 a(1) p Fg 976 547 a(:) p 998 547 a(:) p 1020 +547 a(:) p Fi 1042 547 a(l) p Fc 1058 554 a(i) p Fd(\000) p +Fc(1) p Fk 1118 547 a(:) p Fg(e) p Fb 1155 554 a(i) p +Fd(\000) p Ff(1) p Fi 1230 547 a(l) p Fc 1246 554 a(i) p +Ff(+) p Fc(1) p Fk 1307 547 a(:) p Fg 1320 547 a(e) p +Fb 1343 554 a(i) p Ff(+1) p Fg 1410 547 a(:) p 1432 547 +a(:) p 1454 547 a(:) p Fi 1476 547 a(l) p Fc 1492 554 +a(n) p Fk 1516 547 a(:) p Fg(e) p Fb 1553 554 a(n) p +Fk 86 607 a(\() p Fe(fun) p Fk 198 607 a(?) p Fi(l) p +Fk(:) p Fg 250 607 a(x) p Fj 292 607 a(!) p Fg 356 607 +a(e) p Fk(\)) p Fi 413 607 a(l) p Fc 429 614 a(1) p Fk +451 607 a(:) p Fg(e) p Ff 488 614 a(1) p Fg 516 607 a(:) p +538 607 a(:) p 560 607 a(:) p Fi 581 607 a(l) p Fc 597 +614 a(n) p Fk 621 607 a(:) p Fg(e) p Fb 658 614 a(n) p +Fk 1154 607 a(when) p Fi 1281 607 a(l) p Fc 1297 614 +a(i) p Fk 1324 607 a(=) p Fj 1376 607 a(;) p Fk 1417 +607 a(and) p Fg 1512 607 a(l) p Fj 1541 607 a(62) p 1588 +607 a(f) p Fi(l) p Fc 1629 614 a(1) p Fg 1660 607 a(:) p +1682 607 a(:) p 1704 607 a(:) p Fi 1725 607 a(l) p Fc +1741 614 a(n) p Fj 1765 607 a(g) 515 667 y(!) p Fg 579 +667 a(e) p Fk([) p Fe(None) p Fg 717 667 a(=x) p Fk(]) p +Fi 799 667 a(l) p Fc 815 674 a(1) p Fk 837 667 a(:) p +Fg(e) p Ff 874 674 a(1) p Fg 901 667 a(:) p 923 667 a(:) p +945 667 a(:) p Fi 967 667 a(l) p Fc 983 674 a(n) p Fk +1007 667 a(:) p Fg(e) p Fb 1044 674 a(n) p Fk 86 728 +a(\(\() p Fe(fun) p Fi 217 728 a(l) p Fk(:) p Fg 246 +728 a(x) p Fj 288 728 a(!) p Fg 352 728 a(e) p Fk(\)) p +Fi 409 728 a(l) p Fc 425 735 a(1) p Fk 447 728 a(:) p +Fg(e) p Ff 484 735 a(1) p Fg 511 728 a(:) p 533 728 a(:) p +555 728 a(:) p Fi 577 728 a(l) p Fc 593 735 a(m) p Fk +629 728 a(:) p Fg 642 728 a(e) p Fb 665 735 a(m) p Fk +698 728 a(\)) p Fi 733 728 a(l) p Fc 749 735 a(m) p Ff(+) p +Fc(1) p Fk 833 728 a(:) p Fg 846 728 a(e) p Fb 869 735 +a(m) p Ff(+1) p Fg 955 728 a(:) p 977 728 a(:) p 999 +728 a(:) p Fi 1021 728 a(l) p Fc 1037 735 a(n) p Fk 1061 +728 a(:) p Fg(e) p Fb 1098 735 a(n) p Fk 1373 728 a(when) p +Fi 1501 728 a(l) p Fj 1530 728 a(62) p 1577 728 a(f) p +Fi(l) p Fc 1618 735 a(1) p Fg 1648 728 a(:) p 1670 728 +a(:) p 1692 728 a(:) p Fi 1714 728 a(l) p Fc 1730 735 +a(m) p Fj 1765 728 a(g) 515 788 y(!) p Fk 579 788 a(\() p +Fe(fun) p Fi 691 788 a(l) p Fk(:) p Fg 720 788 a(x) p +Fj 761 788 a(!) p Fg 825 788 a(e) p Fk(\)) p Fi 883 788 +a(l) p Fc 899 795 a(1) p Fk 921 788 a(:) p Fg 934 788 +a(e) p Ff 957 795 a(1) p Fg 985 788 a(:) p 1007 788 a(:) p +1029 788 a(:) p Fi 1051 788 a(l) p Fc 1067 795 a(n) p +Fk 1091 788 a(:) p Fg 1104 788 a(e) p Fb 1127 795 a(n) p +Fk 86 848 a(\(\() p Fe(fun) p Fk 217 848 a(?) p Fi(l) p +Fk(:) p Fg 269 848 a(x) p Fj 311 848 a(!) p Fg 375 848 +a(e) p Fk(\)) p Fi 432 848 a(l) p Fc 448 855 a(1) p Fk +470 848 a(:) p Fg(e) p Ff 507 855 a(1) p Fg 535 848 a(:) p +557 848 a(:) p 579 848 a(:) p Fi 600 848 a(l) p Fc 616 +855 a(m) p Fk 652 848 a(:) p Fg 665 848 a(e) p Fb 688 +855 a(m) p Fk 721 848 a(\)) p Fi 756 848 a(l) p Fc 772 +855 a(m) p Ff(+) p Fc(1) p Fk 856 848 a(:) p Fg 869 848 +a(e) p Fb 892 855 a(m) p Ff(+1) p Fg 978 848 a(:) p 1000 +848 a(:) p 1022 848 a(:) p Fi 1044 848 a(l) p Fc 1060 +855 a(n) p Fk 1084 848 a(:) p Fg(e) p Fb 1121 855 a(n) p +Fk 1261 848 a(when) p Fj 1388 848 a(f) p Fi(l) p Fg(;) p +Fj 1451 848 a(;g) p 1530 848 a(6) m(\\) p 1577 848 a(f) p +Fi(l) p Fc 1618 855 a(1) p Fg 1648 848 a(:) p 1670 848 +a(:) p 1692 848 a(:) p Fi 1714 848 a(l) p Fc 1730 855 +a(m) p Fj 1765 848 a(g) 515 908 y(!) p Fk 579 908 a(\() p +Fe(fun) p Fk 691 908 a(?) p Fi(l) p Fk(:) p Fg 743 908 +a(x) p Fj 785 908 a(!) p Fg 848 908 a(e) p Fk(\)) p Fi +906 908 a(l) p Fc 922 915 a(1) p Fk 944 908 a(:) p Fg(e) p +Ff 981 915 a(1) p Fg 1008 908 a(:) p 1030 908 a(:) p +1052 908 a(:) p Fi 1074 908 a(l) p Fc 1090 915 a(n) p +Fk 1114 908 a(:) p Fg 1127 908 a(e) p Fb 1150 915 a(n) p +Fi 11 1035 a(T) n(yping) p Fk 11 1127 a(Seman) o(tics) p +240 1127 a(are) p 321 1127 a(k) o(ept) p 430 1127 a(throughout) p +685 1127 a(compilation) p 950 1127 a(b) o(y) p 1018 1127 +a(disallo) o(wing) p 1269 1127 a(lab) q(el) p 1387 1127 +a(comm) o(utation) p 1684 1127 a(for) p 1759 1127 a(func-) 11 +1187 y(tion) p 116 1187 a(t) o(yp) q(es.) p 278 1187 +a(Ho) o(w) o(ev) o(er,) p 494 1187 a(the) p 583 1187 +a(original) p 764 1187 a(comfort) p 949 1187 a(of) p +1009 1187 a(out-of-order) p 1283 1187 a(application) p +1540 1187 a(is) p 1594 1187 a(reco) o(v) o(ered) p 1814 +1187 a(b) o(y) 11 1247 y(allo) o(wing) p 207 1247 a(argumen) o(t) p +431 1247 a(reordering) p 670 1247 a(in) p 732 1247 a(application,) p +1005 1247 a(when) p 1138 1247 a(the) p 1227 1247 a(function's) p +1457 1247 a(t) o(yp) q(e) p 1572 1247 a(is) p Fh 1626 +1247 a(wel) r(l) p 1731 1247 a(known) p Fk 11 1308 a(\() p +Fh(c.f.) p Fk 118 1308 a(p) q(olymorphic) p 400 1308 +a(metho) q(ds\).) p Fl 11 1452 a(V) p 56 1452 a(arian) n(ts) p +Fk 11 1544 a(V) l(arian) o(t) p 187 1544 a(t) o(yping,) p +355 1544 a(as) p 417 1544 a(it) p 468 1544 a(is) p 519 +1544 a(presen) o(ted) p 739 1544 a(in) p 798 1544 a(the) p +884 1544 a(user's) p 1022 1544 a(man) o(ual,) p 1210 +1544 a(is) p 1261 1544 a(not) p 1350 1544 a(principal:) p +1576 1544 a(in) p 1635 1544 a(some) p 1760 1544 a(cases) 11 +1605 y(t) o(ypabilit) o(y) p 239 1605 a(of) p 301 1605 +a(an) p 375 1605 a(expression) p 616 1605 a(ma) o(y) p +728 1605 a(dep) q(end) p 904 1605 a(on) p 978 1605 a(the) p +1069 1605 a(order) p 1202 1605 a(in) p 1265 1605 a(whic) o(h) p +1411 1605 a(the) p 1502 1605 a(t) o(yping) p 1660 1605 +a(algorithm) 11 1665 y(pro) q(ceeds.) p Fe 133 1779 a(#) p +184 1779 a(let) p 286 1779 a(f1) p 363 1779 a(\(x) p +440 1779 a(:) p 491 1779 a([<) p 568 1779 a(a) p 620 +1779 a(b\(int\)]\)) p 850 1779 a(=) p 902 1779 a(\(\)) 184 +1839 y(let) p 286 1839 a(f2) p 363 1839 a(\(x) p 440 +1839 a(:) p 491 1839 a([<) p 568 1839 a(a]\)) p 671 1839 +a(=) p 722 1839 a(\(\)) 184 1899 y(let) p 286 1899 a(f3) p +363 1899 a(\(x) p 440 1899 a(:) p 491 1899 a([<) p 568 +1899 a(a) p 620 1899 a(b\(bool\)]\)) p 876 1899 a(=) p +927 1899 a(\(\);;) 133 1960 y(val) p 235 1960 a(f1) p +312 1960 a(:) p 363 1960 a([<) p 440 1960 a(a) p 491 +1960 a(b\(int\)]) p 696 1960 a(->) p 773 1960 a(unit) p +902 1960 a(=) p 953 1960 a(<fun>) 133 2020 y(val) p 235 +2020 a(f2) p 312 2020 a(:) p 363 2020 a([<) p 440 2020 +a(a]) p 517 2020 a(->) p 594 2020 a(unit) p 722 2020 +a(=) p 773 2020 a(<fun>) 133 2080 y(val) p 235 2080 a(f3) p +312 2080 a(:) p 363 2080 a([<) p 440 2080 a(a) p 491 +2080 a(b\(bool\)]) p 722 2080 a(->) p 799 2080 a(unit) p +927 2080 a(=) p 978 2080 a(<fun>) 133 2140 y(#) p 184 +2140 a(fun) p 286 2140 a(x) p 338 2140 a(->) p 414 2140 +a(f1) p 491 2140 a(x;) p 568 2140 a(f2) p 645 2140 a(x;) p +722 2140 a(f3) p 799 2140 a(x;;) 133 2200 y(-) p 184 +2200 a(:) p 235 2200 a([<) p 312 2200 a(a]) p 389 2200 +a(->) p 466 2200 a(unit) p 594 2200 a(=) p 645 2200 a(<fun>) 133 +2260 y(#) p 184 2260 a(fun) p 286 2260 a(x) p 338 2260 +a(->) p 414 2260 a(f1) p 491 2260 a(x;) p 568 2260 a(f3) p +645 2260 a(x;;) 133 2321 y(Character) o(s) p 414 2321 +a(18-19:) 133 2381 y(This) p 261 2381 a(expressio) o(n) p +543 2381 a(has) p 645 2381 a(type) p 773 2381 a([<) p +850 2381 a(a) p 902 2381 a(b\(int\)]) p 1107 2381 a(but) p +1209 2381 a(is) p 1286 2381 a(here) p 1414 2381 a(used) p +1542 2381 a(with) p 1670 2381 a(type) 184 2441 y([<) p +261 2441 a(a) p 312 2441 a(b\(bool\)]) p Fk 84 2555 a(Here) p +204 2555 a(the) p 292 2555 a(constrain) o(t) p 526 2555 +a(in) o(tro) q(duced) p 775 2555 a(b) o(y) p Fe 848 2555 +a(f2) p Fk 920 2555 a(hides) p 1049 2555 a(the) p 1138 +2555 a(constructor) p Fe 1401 2555 a(b) p Fk(,) p 1462 +2555 a(and) p 1562 2555 a(a) o(v) o(oids) p 1714 2555 +a(a) p 1760 2555 a(clash) 11 2615 y(b) q(et) o(w) o(een) p +Fe 199 2615 a(int) p Fk 292 2615 a(and) p Fe 387 2615 +a(bool) p Fk(.) 84 2676 y(An) p 163 2676 a(easy) p 270 +2676 a(w) o(a) o(y) p 369 2676 a(to) p 428 2676 a(solv) o(e) p +547 2676 a(this) p 642 2676 a(w) o(ould) p 784 2676 a(b) q(e) p +850 2676 a(to) p 909 2676 a(restrict) p 1077 2676 a(hiding) p +1226 2676 a(absen) o(t) p 1379 2676 a(lab) q(els) p 1515 +2676 a(to) p 1575 2676 a(generic) p 1739 2676 a(t) o(yp) q(es.) 11 +2736 y(This) p 124 2736 a(w) o(a) o(y) p 224 2736 a(the) p +310 2736 a(second) p 469 2736 a(case) p 574 2736 a(w) o(ould) p +718 2736 a(still) p 814 2736 a(fail,) p 913 2736 a(since) p +Fe 1034 2736 a(x) p Fk 1077 2736 a(has) p 1166 2736 a(a) p +1208 2736 a(monorphic) p 1451 2736 a(t) o(yp) q(e.) p +1584 2736 a(This) p 1697 2736 a(solution) 11 2796 y(w) o(ould) p +153 2796 a(b) q(e) p 219 2796 a(correct) p 382 2796 a(and) p +477 2796 a(principal.) 926 2937 y(2) p eop +PStoPSsaved restore +%%Page: (2,3) 2 +userdict/PStoPSsaved save put +PStoPSmatrix setmatrix +595.000000 0.271378 translate +90 rotate +0.706651 dup scale +userdict/PStoPSmatrix matrix currentmatrix put +userdict/PStoPSclip{0 0 moveto + 595.000000 0 rlineto 0 842.000000 rlineto -595.000000 0 rlineto + closepath}put initclip +/showpage{}def/copypage{}def/erasepage{}def +PStoPSxform concat +3 2 bop Fk 84 168 a(Ho) o(w) o(ev) o(er,) p 293 168 a(one) p +382 168 a(can) p 472 168 a(easily) p 606 168 a(see) p +684 168 a(that) p 789 168 a(this) p 884 168 a(solution) p +1068 168 a(is) p 1117 168 a(coun) o(ter-in) o(tuitiv) o(e.) p +1504 168 a(F) l(or) p 1591 168 a(the) p 1675 168 a(user,) p +Fe 1791 168 a(b) p Fk 1833 168 a(is) 11 229 y(already) p +183 229 a(an) p 250 229 a(imp) q(ossible) p 488 229 a(constructor,) p +759 229 a(and) p 854 229 a(ha) o(ving) p 1011 229 a(a) p +1052 229 a(clash) p 1174 229 a(on) p 1242 229 a(it) p +1291 229 a(is) p 1340 229 a(hard) p 1453 229 a(to) p +1513 229 a(understand.) 84 289 y(Another) p 277 289 a(solution) p +463 289 a(is) p 514 289 a(to) p 575 289 a(go) p 642 289 +a(the) p 728 289 a(opp) q(osite) p 924 289 a(w) o(a) o(y) l(.) p +1044 289 a(T) l(o) p 1117 289 a(accept) p 1271 289 a(more) p +1395 289 a(programs.) p 1634 289 a(This) p 1747 289 a(is) p +1798 289 a(the) 11 349 y(w) o(a) o(y) p 109 349 a(w) o(e) p +181 349 a(explore) p 351 349 a(here,) p 470 349 a(with) p +581 349 a(an) p 649 349 a(unc) o(hanged) p 891 349 a(syn) o(tax.) p +Fi 11 479 a(T) n(yping) p Fk 11 571 a(The) p 114 571 +a(idea) p 220 571 a(is) p 273 571 a(to) p 336 571 a(dela) o(y) p +466 571 a(uni\014cation) p 711 571 a(on) p 782 571 a(constructor) p +1043 571 a(un) o(til) p 1161 571 a(they) p 1274 571 a(are) p +1359 571 a(explicitely) p 1595 571 a(kno) o(wn) p 1753 +571 a(to) p 1816 571 a(b) q(e) 11 631 y(presen) o(t.) p +199 631 a(W) l(e) p 280 631 a(k) o(eep) p 390 631 a(the) p +472 631 a(\() p Fg(T) t(;) p 546 631 a(U;) p 601 631 +a(L) p Fk(\)) p 666 631 a(represen) o(tation) p 983 631 +a(of) p 1036 631 a(v) m(arian) o(t) p 1200 631 a(t) o(yp) q(es,) p +1341 631 a(but) p Fg 1428 631 a(T) p Fk 1478 631 a(is) p +1525 631 a(no) p 1591 631 a(longer) p 1735 631 a(a) p +1774 631 a(map) 11 692 y(from) p 126 692 a(constructors) p +403 692 a(to) p 462 692 a(t) o(yp) q(es,) p 605 692 a(but) p +694 692 a(from) p 809 692 a(constructors) p 1086 692 +a(to) p 1146 692 a(sets) p 1241 692 a(of) p 1297 692 +a(t) o(yp) q(es.) 84 752 y(When) p 230 752 a(w) o(e) p +307 752 a(unify) p 436 752 a(t) o(w) o(o) p 532 752 a(v) m(arian) o(t) p +702 752 a(t) o(yp) q(es,) p 850 752 a(the) p 938 752 +a(\014rst) p 1043 752 a(step) p 1150 752 a(is) p 1204 +752 a(just) p 1305 752 a(to) p 1369 752 a(tak) o(e) p +1479 752 a(the) p 1567 752 a(union) p 1707 752 a(of) p +1767 752 a(b) q(oth) 11 812 y(t) o(yping) p 162 812 a(en) o(vironmen) o +(ts,) p 476 812 a(dropping) p 682 812 a(unnecessary) p +952 812 a(t) o(yp) q(es.) 204 932 y(\() p Fg(T) p Ff +252 939 a(1) p Fg 272 932 a(;) p 294 932 a(U) p Ff 327 +939 a(1) p Fg 346 932 a(;) p 368 932 a(L) p Ff 401 939 +a(1) p Fk 421 932 a(\)) p Fj 451 932 a(^) p Fk 495 932 +a(\() p Fg(T) p Ff 543 939 a(2) p Fg 563 932 a(;) p 585 +932 a(U) p Ff 618 939 a(2) p Fg 637 932 a(;) p 659 932 +a(L) p Ff 692 939 a(2) p Fk 712 932 a(\)) p 745 932 a(=) p +797 932 a(\(\() p Fg(T) p Ff 864 939 a(1) p Fj 883 932 +a(j) p Fb 897 939 a(U) p Fa 921 944 a(1) p Fd 938 939 +a(\\) p Fb(U) p Fa 986 944 a(2) p Fk 1005 932 a(\)) p +Fj 1035 932 a([) p Fk 1079 932 a(\() p Fg(T) p Ff 1127 +939 a(2) p Fj 1146 932 a(j) p Fb 1160 939 a(U) p Fa 1184 +944 a(1) p Fd 1201 939 a(\\) p Fb(U) p Fa 1249 944 a(2) p +Fk 1268 932 a(\)) p Fg(;) p 1309 932 a(U) p Ff 1342 939 +a(1) p Fj 1373 932 a(\\) p Fg 1417 932 a(U) p Ff 1450 +939 a(2) p Fg 1470 932 a(;) p 1492 932 a(L) p Ff 1525 +939 a(1) p Fj 1556 932 a([) p Fg 1600 932 a(L) p Ff 1633 +939 a(2) p Fk 1653 932 a(\)) 84 1042 y(Here) p 203 1042 +a(the) p 291 1042 a(union) p 431 1042 a(of) p 490 1042 +a(t) o(w) o(o) p 587 1042 a(t) o(yping) p 742 1042 a(en) o(vironmen) o +(ts) p 1046 1042 a(is) p 1099 1042 a(the) p 1187 1042 +a(p) q(oin) o(t) o(wise) p 1407 1042 a(union) p 1547 +1042 a(of) p 1606 1042 a(their) p 1727 1042 a(sets) p +1826 1042 a(of) 11 1102 y(t) o(yp) q(es) p 140 1102 a(for) p +214 1102 a(eac) o(h) p 324 1102 a(constructor.) 84 1162 +y(This) p 195 1162 a(\014rst) p 296 1162 a(step) p 399 +1162 a(nev) o(er) p 529 1162 a(fails.) 84 1222 y(In) p +145 1222 a(a) p 186 1222 a(second) p 343 1222 a(step,) p +460 1222 a(structural) p 685 1222 a(constrain) o(ts) p +934 1222 a(are) p 1015 1222 a(enforced) p 1209 1222 a(on) p +1277 1222 a(the) p 1361 1222 a(resulting) p 1562 1222 +a(t) o(yp) q(e) p 1672 1222 a(\() p Fg(T) t(;) p 1746 +1222 a(U;) p 1801 1222 a(L) p Fk(\).) 11 1282 y(First,) p +Fg 144 1282 a(L) p Fk 195 1282 a(should) p 351 1282 a(b) q(e) p +418 1282 a(included) p 614 1282 a(in) p Fg 672 1282 a(U) p +Fk 710 1282 a(.) p 749 1282 a(Then,) p 892 1282 a(for) p +967 1282 a(all) p 1036 1282 a(constructors) p 1314 1282 +a(app) q(earing) p 1542 1282 a(in) p Fg 1600 1282 a(L) p +Fk(,) p 1664 1282 a(the) p 1749 1282 a(set) p 1826 1282 +a(of) 11 1343 y(t) o(yp) q(es) p 136 1343 a(asso) q(ciated) p +365 1343 a(with) p 472 1343 a(eac) o(h) p 578 1343 a(constructor) p +833 1343 a(is) p 878 1343 a(collapsed) p 1084 1343 a(b) o(y) p +1148 1343 a(uni\014cation.) p 1407 1343 a(This) p 1515 +1343 a(can) p 1600 1343 a(b) q(e) p 1663 1343 a(expressed) 11 +1403 y(b) o(y) p 78 1403 a(rewriting) p 287 1403 a(rules,) p +417 1403 a(where) p Fg 558 1403 a(e) p Fk 597 1403 a(is) p +646 1403 a(a) p 687 1403 a(m) o(ulti-equation) p 1015 +1403 a(and) p Fg 1109 1403 a(\036) p Fk 1155 1403 a(a) p +1195 1403 a(set) p 1271 1403 a(of) p 1327 1403 a(m) o(ultiequations) 249 +1509 y(if) p Fg 294 1509 a(L) p Fj 341 1509 a(6\032) p +Fg 393 1509 a(U) p Fk 448 1509 a(then) p 559 1509 a(\() p +Fg(T) t(;) p 633 1509 a(U;) p 688 1509 a(L) p Fk(\)) p +753 1509 a(=) p Fg 805 1509 a(e) p Fj 839 1509 a(^) p +Fg 883 1509 a(\036) p Fj 926 1509 a(\000) p 956 1509 +a(!) p 1020 1509 a(?) p Fk 249 1629 a(if) p Fg 294 1629 +a(l) p Fj 323 1629 a(2) p Fg 370 1629 a(L) p Fk 420 1629 +a(and) p Fg 515 1629 a(T) p Fk 551 1629 a(\() p Fg(l) p +Fk 586 1629 a(\)) p 617 1629 a(=) p Fj 669 1629 a(f) p +Fg(\034) p Ff 715 1636 a(1) p Fg 735 1629 a(;) p 757 +1629 a(:) p 779 1629 a(:) p 801 1629 a(:) p 822 1629 +a(;) p 844 1629 a(\034) p Fb 865 1636 a(n) p Fj 889 1629 +a(g) p Fk 930 1629 a(then) 298 1689 y(\() p Fg(T) t(;) p +372 1689 a(U;) p 427 1689 a(L) p Fk(\)) p 492 1689 a(=) p +Fg 544 1689 a(e) p Fj 577 1689 a(^) p Fg 622 1689 a(\036) p +Fj 664 1689 a(\000) p 695 1689 a(!) p Fk 759 1689 a(\() p +Fg(T) p Fj 814 1689 a(f) p Fg(l) p Fj 867 1689 a(7!) p +Fg 931 1689 a(\034) p Ff 952 1696 a(1) p Fj 972 1689 +a(g) p Fg(;) p 1019 1689 a(U;) p 1074 1689 a(L) p Fk(\)) p +1139 1689 a(=) p Fg 1191 1689 a(e) p Fj 1225 1689 a(^) p +Fg 1269 1689 a(\034) p Ff 1290 1696 a(1) p Fk 1324 1689 +a(=) p Fg 1376 1689 a(:) p 1398 1689 a(:) p 1420 1689 +a(:) p Fk 1447 1689 a(=) p Fg 1498 1689 a(\034) p Fb +1519 1696 a(n) p Fj 1554 1689 a(^) p Fg 1598 1689 a(\036) p +Fk 84 1796 a(Optionally) p 331 1796 a(one) p 425 1796 +a(can) p 519 1796 a(add) p 619 1796 a(rules) p 740 1796 +a(that) p 850 1796 a(remo) o(v) o(e) p 1022 1796 a(a) p +1067 1796 a(constructor) p Fg 1329 1796 a(l) p Fk 1366 +1796 a(from) p Fg 1486 1796 a(U) p Fk 1545 1796 a(if) p +1594 1796 a(the) p 1683 1796 a(equation) 11 1856 y(obtained) p +211 1856 a(from) p Fg 326 1856 a(T) p Fk 362 1856 a(\() p +Fg(l) p Fk 397 1856 a(\)) p 431 1856 a(has) p 518 1856 +a(no) p 586 1856 a(solution.) p 790 1856 a(Suc) o(h) p +908 1856 a(rules) p 1024 1856 a(w) o(ould) p 1167 1856 +a(b) q(e) p 1233 1856 a(sound) p 1374 1856 a(and) p 1469 +1856 a(complete.) p Fi 11 1986 a(Syn) n(tax) p 198 1986 +a(of) p 262 1986 a(t) n(yp) r(es) p Fk 11 2078 a(Thanks) p +188 2078 a(to) p 250 2078 a(the) p 336 2078 a(go) q(o) q(d) p +458 2078 a(prop) q(erties) p 689 2078 a(of) p 747 2078 +a(these) p 874 2078 a(constrain) o(ts,) p 1139 2078 a(the) p +1226 2078 a(surface) p 1392 2078 a(syn) o(tax) p 1551 +2078 a(of) p 1608 2078 a(t) o(yp) q(es) p 1740 2078 a(w) o(ould) 11 +2138 y(only) p 118 2138 a(ha) o(v) o(e) p 230 2138 a(to) p +290 2138 a(b) q(e) p 356 2138 a(sligh) o(tly) p 527 2138 +a(extended.) p Fh 590 2244 a(tag-typ) n(e) p Fk 798 2244 +a(::=) p Fh 904 2244 a(ident) p Fj 849 2304 a(j) p Fh +904 2304 a(ident) p Fe 1031 2304 a(\() p Fh(typ) n(expr-list) p +Fe(\)) p Fh 523 2365 a(typ) n(expr-list) p Fk 798 2365 +a(::=) p Fh 904 2365 a(typ) n(expr) p Fj 849 2425 a(j) p +Fh 904 2425 a(typ) n(expr) p Fe 1078 2425 a(&) p Fh 1120 +2425 a(typ) n(expr-list) p Fk 84 2531 a(Notice) p 234 +2531 a(that) p 336 2531 a(a) p 373 2531 a(0-ary) p 496 +2531 a(constructor) p 751 2531 a(and) p 842 2531 a(an) p +907 2531 a(1-ary) p 1030 2531 a(construtor) p 1262 2531 +a(are) p 1340 2531 a(con) o(tradictory) l(,) p 1648 2531 +a(and) p 1740 2531 a(w) o(ould) 11 2592 y(result) p 146 +2592 a(in) p 203 2592 a(the) p 287 2592 a(absence) p +466 2592 a(of) p 522 2592 a(this) p 617 2592 a(constructor.) 926 +2937 y(3) p eop +PStoPSsaved restore +userdict/PStoPSsaved save put +PStoPSmatrix setmatrix +595.000000 421.271378 translate +90 rotate +0.706651 dup scale +userdict/PStoPSmatrix matrix currentmatrix put +userdict/PStoPSclip{0 0 moveto + 595.000000 0 rlineto 0 842.000000 rlineto -595.000000 0 rlineto + closepath}put initclip +PStoPSxform concat +4 3 bop Fi 11 168 a(Discussion) p Fk 11 261 a(Suc) o(h) p +133 261 a(a) p 179 261 a(c) o(hange) p 345 261 a(has) p +436 261 a(the) p 525 261 a(ma) s(jor) p 672 261 a(adv) m(an) o(tage) p +907 261 a(of) p 967 261 a(b) q(oth) p 1087 261 a(reco) o(v) o(ering) p +1324 261 a(principalit) o(y) p 1589 261 a(and) p 1688 +261 a(a) o(v) o(oiding) 11 321 y(unin) o(tuitiv) o(e) p +266 321 a(error) p 392 321 a(messages.) p 640 321 a(Constrain) o(ts) p +909 321 a(created) p 1087 321 a(in) p 1152 321 a(suc) o(h) p +1269 321 a(a) p 1317 321 a(w) o(a) o(y) p 1423 321 a(are) p +1512 321 a(v) o(ery) p 1626 321 a(ligh) o(t:) p 1772 +321 a(they) 11 381 y(alw) o(a) o(ys) p 165 381 a(app) q(ear) p +325 381 a(inside) p 463 381 a(a) p 502 381 a(v) m(arian) o(t) p +666 381 a(t) o(yp) q(e,) p 788 381 a(and) p 882 381 a(if) p +926 381 a(the) p 1008 381 a(v) m(arian) o(t) p 1172 381 +a(t) o(yp) q(e) p 1281 381 a(do) q(es) p 1390 381 a(not) p +1475 381 a(app) q(ear) p 1635 381 a(in) p 1691 381 a(the) p +1774 381 a(\014nal) 11 441 y(t) o(yp) q(e) p 120 441 +a(sc) o(heme,) p 301 441 a(then) p 412 441 a(the) p 496 +441 a(constrain) o(t) p 725 441 a(can) p 815 441 a(b) q(e) p +881 441 a(discarded) p 1098 441 a(safely) l(.) 84 501 +y(On) p 165 501 a(the) p 249 501 a(other) p 376 501 a(hand,) p +512 501 a(there) p 637 501 a(are) p 718 501 a(t) o(w) o(o) p +810 501 a(dra) o(wbac) o(ks.) p Fj 83 616 a(\017) p Fk +133 616 a(Some) p 259 616 a(errors) p 393 616 a(will) p +482 616 a(b) q(e) p 544 616 a(dela) o(y) o(ed) p 715 +616 a(longer) p 858 616 a(than) p 968 616 a(no) o(w,) p +1080 616 a(un) o(til) p 1191 616 a(a) p 1228 616 a(construtor) p +1460 616 a(is) p 1505 616 a(actually) p 1687 616 a(included) 133 +676 y(in) p Fg 189 676 a(L) p Fk(.) p 258 676 a(It) p +311 676 a(is) p 360 676 a(not) p 446 676 a(clear) p 563 +676 a(ho) o(w) p 665 676 a(damageable) p 930 676 a(it) p +979 676 a(is.) p Fj 83 777 a(\017) p Fk 133 777 a(While) p +272 777 a(t) o(yp) q(e) p 378 777 a(inference) p 579 +777 a(is) p 625 777 a(simple) p 774 777 a(and) p 865 +777 a(costless) p 1036 777 a(for) p 1108 777 a(this) p +1200 777 a(extension,) p 1426 777 a(simpli\014cation) p +1724 777 a(of) p 1776 777 a(con-) 133 838 y(strain) o(ts) p +310 838 a(|marking) p 551 838 a(constructors) p 830 838 +a(with) p 943 838 a(unsolv) m(able) p 1182 838 a(constrain) o(ts) p +1432 838 a(as) p 1494 838 a(absen) o(t,) p 1663 838 a(and) p +1760 838 a(elim-) 133 898 y(inating) p 300 898 a(redundan) o(t) p +536 898 a(t) o(yp) q(es) p 667 898 a(in) p 726 898 a(constrain) o(ts|) p +1025 898 a(is) p 1076 898 a(a) p 1119 898 a(bit) p 1197 +898 a(more) p 1320 898 a(exp) q(ensiv) o(e.) p 1565 898 +a(Also,) p 1691 898 a(allo) o(wing) 133 958 y(suc) o(h) p +244 958 a(constrained) p 506 958 a(t) o(yp) q(es) p 637 +958 a(inside) p 777 958 a(signatures) p 1010 958 a(w) o(ould) p +1154 958 a(mean) p 1286 958 a(ha) o(ving) p 1444 958 +a(to) p 1506 958 a(solv) o(e) p 1627 958 a(a) p 1669 +958 a(matc) o(hing) 133 1018 y(problem,) p 333 1018 a(whic) o(h) p +469 1018 a(is) p 514 1018 a(exp) q(onen) o(tial) p 772 +1018 a(in) p 825 1018 a(the) p 906 1018 a(n) o(um) o(b) q(er) p +1080 1018 a(of) p 1132 1018 a(connected) p 1356 1018 +a(constrain) o(ts) p 1600 1018 a(inside) p 1735 1018 +a(a) p 1772 1018 a(t) o(yp) q(e) 133 1078 y(sc) o(heme.) 84 +1193 y(Reasonably) p 340 1193 a(e\016cien) o(t) p 516 +1193 a(algorithms) p 754 1193 a(exist) p 866 1193 a(to) p +922 1193 a(solv) o(e) p 1038 1193 a(these) p 1159 1193 +a(problems,) p 1379 1193 a(so) p 1435 1193 a(the) p 1515 +1193 a(di\016cult) o(y) p 1715 1193 a(is) p 1760 1193 +a(more) 11 1253 y(in) p 67 1253 a(the) p 151 1253 a(increased) p +363 1253 a(complexit) o(y) p 611 1253 a(of) p 667 1253 +a(the) p 751 1253 a(t) o(yp) q(e-c) o(hec) o(k) o(er) p +1031 1253 a(than) p 1145 1253 a(in) p 1202 1253 a(run-time) p +1402 1253 a(cost.) p Fl 11 1397 a(Other) p 205 1397 a(features) p +Fk 11 1490 a(Ob) s(jectiv) o(e) p 238 1490 a(Lab) q(el) p +380 1490 a(con) o(tains) p 579 1490 a(t) o(w) o(o) p +678 1490 a(other) p 812 1490 a(features:) p 1029 1490 +a(p) q(olymorphic) p 1318 1490 a(metho) q(ds) p 1521 +1490 a(and) p 1623 1490 a(t) o(yp) q(e-driv) o(en) 11 +1550 y(access) p 153 1550 a(of) p 208 1550 a(records.) p +394 1550 a(Both) p 514 1550 a(of) p 568 1550 a(them) p +692 1550 a(use) p 775 1550 a(the) p 857 1550 a(same) p +978 1550 a(metho) q(d) p 1154 1550 a(of) p 1209 1550 +a(enforcing) p 1417 1550 a(principalit) o(y) p 1676 1550 +a(of) p 1730 1550 a(t) o(yping) 11 1610 y(through) p +191 1610 a(tracing) p 351 1610 a(user) p 450 1610 a(pro) o(vided) p +647 1610 a(t) o(yp) q(e) p 752 1610 a(information.) p +1034 1610 a(With) p 1155 1610 a(this) p 1246 1610 a(tracing,) p +1422 1610 a(their) p 1534 1610 a(implem) o(en) n(tation) 11 +1670 y(is) p 60 1670 a(v) o(ery) p 167 1670 a(easy) l(,) p +283 1670 a(but) p 373 1670 a(without) p 554 1670 a(it) p +603 1670 a(they) p 713 1670 a(lo) q(ose) p 834 1670 a(principalit) o(y) +l(.) 84 1730 y(While) p 229 1730 a(these) p 357 1730 +a(features) p 543 1730 a(pro) o(vide) p 720 1730 a(some) p +845 1730 a(comfort) p 1029 1730 a(in) p 1089 1730 a(writing) p +1260 1730 a(user) p 1366 1730 a(programs,) p 1598 1730 +a(they) p 1711 1730 a(are) p 1795 1730 a(not) 11 1791 +y(strictly) p 182 1791 a(necessary) p 403 1791 a(for) p +482 1791 a(the) p 571 1791 a(v) m(arious) p 742 1791 +a(libraries) p 934 1791 a(coming) p 1107 1791 a(with) p +1223 1791 a(O'Labl) p 1391 1791 a(\(LablTk,) p 1602 1791 +a(LablGL) p 1787 1791 a(and) 11 1851 y(LablGTK\).) 926 +2937 y(4) p eop +PStoPSsaved restore +%%Trailer +end +userdict /end-hook known{end-hook}if +%%EOF diff --git a/testlabl/objvariant.diffs b/testlabl/objvariant.diffs new file mode 100644 index 0000000..75deb24 --- /dev/null +++ b/testlabl/objvariant.diffs @@ -0,0 +1,354 @@ +? objvariants-3.09.1.diffs +? objvariants.diffs +Index: btype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/btype.ml,v +retrieving revision 1.37.4.1 +diff -u -r1.37.4.1 btype.ml +--- btype.ml 5 Dec 2005 13:18:42 -0000 1.37.4.1 ++++ btype.ml 16 Jan 2006 02:23:14 -0000 +@@ -177,7 +177,8 @@ + Tvariant row -> iter_row f row + | Tvar | Tunivar | Tsubst _ | Tconstr _ -> + Misc.may (fun (_,l) -> List.iter f l) row.row_name; +- List.iter f row.row_bound ++ List.iter f row.row_bound; ++ List.iter (fun (s,k,t) -> f t) row.row_object + | _ -> assert false + + let iter_type_expr f ty = +@@ -224,7 +225,9 @@ + | Some (path, tl) -> Some (path, List.map f tl) in + { row_fields = fields; row_more = more; + row_bound = !bound; row_fixed = row.row_fixed && fixed; +- row_closed = row.row_closed; row_name = name; } ++ row_closed = row.row_closed; row_name = name; ++ row_object = List.map (fun (s,k,t) -> (s,k,f t)) row.row_object; ++ } + + let rec copy_kind = function + Fvar{contents = Some k} -> copy_kind k +Index: ctype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.ml,v +retrieving revision 1.197.2.6 +diff -u -r1.197.2.6 ctype.ml +--- ctype.ml 15 Dec 2005 02:28:38 -0000 1.197.2.6 ++++ ctype.ml 16 Jan 2006 02:23:15 -0000 +@@ -1421,7 +1421,7 @@ + newgenty + (Tvariant + {row_fields = fields; row_closed = closed; row_more = newvar(); +- row_bound = []; row_fixed = false; row_name = None }) ++ row_bound = []; row_fixed = false; row_name = None; row_object=[]}) + + (**** Unification ****) + +@@ -1724,8 +1724,11 @@ + else None + in + let bound = row1.row_bound @ row2.row_bound in ++ let opairs, _, miss2 = associate_fields row1.row_object row2.row_object in ++ let row_object = row1.row_object @ miss2 in + let row0 = {row_fields = []; row_more = more; row_bound = bound; +- row_closed = closed; row_fixed = fixed; row_name = name} in ++ row_closed = closed; row_fixed = fixed; row_name = name; ++ row_object = row_object } in + let set_more row rest = + let rest = + if closed then +@@ -1758,6 +1761,18 @@ + raise (Unify ((mkvariant [l,f1] true, + mkvariant [l,f2] true) :: trace))) + pairs; ++ List.iter (fun (s,_,ty1,_,ty2) -> unify env ty1 ty2) opairs; ++ if row_object <> [] then begin ++ List.iter ++ (fun (l,f) -> ++ match row_field_repr f with ++ Rpresent (Some ty) -> ++ let fi = build_fields generic_level row_object (newgenvar()) in ++ unify env (newgenty (Tobject (fi, ref None))) ty ++ | Rpresent None -> raise (Unify []) ++ | _ -> ()) ++ (row_repr row1).row_fields ++ end; + with exn -> + log_type rm1; rm1.desc <- md1; log_type rm2; rm2.desc <- md2; raise exn + end +@@ -2789,7 +2804,8 @@ + let row = + { row_fields = List.map fst fields; row_more = newvar(); + row_bound = !bound; row_closed = posi; row_fixed = false; +- row_name = if c > Unchanged then None else row.row_name } ++ row_name = if c > Unchanged then None else row.row_name; ++ row_object = [] } + in + (newty (Tvariant row), Changed) + | Tobject (t1, _) -> +Index: oprint.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/oprint.ml,v +retrieving revision 1.22 +diff -u -r1.22 oprint.ml +--- oprint.ml 23 Mar 2005 03:08:37 -0000 1.22 ++++ oprint.ml 16 Jan 2006 02:23:15 -0000 +@@ -185,7 +185,7 @@ + fprintf ppf "@[<2>< %a >@]" (print_fields rest) fields + | Otyp_stuff s -> fprintf ppf "%s" s + | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s +- | Otyp_variant (non_gen, row_fields, closed, tags) -> ++ | Otyp_variant (non_gen, row_fields, closed, tags, obj) -> + let print_present ppf = + function + None | Some [] -> () +@@ -198,12 +198,17 @@ + ppf fields + | Ovar_name (id, tyl) -> + fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id ++ and print_object ppf obj = ++ if obj <> [] then ++ fprintf ppf "@ as @[<2>< %a >@]" (print_fields (Some false)) obj + in +- fprintf ppf "%s[%s@[<hv>@[<hv>%a@]%a ]@]" (if non_gen then "_" else "") ++ fprintf ppf "%s[%s@[<hv>@[<hv>%a@]%a%a ]@]" ++ (if non_gen then "_" else "") + (if closed then if tags = None then " " else "< " + else if tags = None then "> " else "? ") + print_fields row_fields + print_present tags ++ print_object obj + | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty -> + fprintf ppf "@[<1>(%a)@]" print_out_type ty + | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> () +Index: outcometree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/outcometree.mli,v +retrieving revision 1.14 +diff -u -r1.14 outcometree.mli +--- outcometree.mli 23 Mar 2005 03:08:37 -0000 1.14 ++++ outcometree.mli 16 Jan 2006 02:23:15 -0000 +@@ -59,6 +59,7 @@ + | Otyp_var of bool * string + | Otyp_variant of + bool * out_variant * bool * (string list) option ++ * (string * out_type) list + | Otyp_poly of string list * out_type + and out_variant = + | Ovar_fields of (string * bool * out_type list) list +Index: printtyp.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/printtyp.ml,v +retrieving revision 1.139.2.2 +diff -u -r1.139.2.2 printtyp.ml +--- printtyp.ml 7 Dec 2005 23:37:27 -0000 1.139.2.2 ++++ printtyp.ml 16 Jan 2006 02:23:15 -0000 +@@ -244,7 +244,10 @@ + visited_objects := px :: !visited_objects; + match row.row_name with + | Some(p, tyl) when namable_row row -> +- List.iter (mark_loops_rec visited) tyl ++ List.iter (mark_loops_rec visited) tyl; ++ if not (static_row row) then ++ List.iter (fun (s,k,t) -> mark_loops_rec visited t) ++ row.row_object + | _ -> + iter_row (mark_loops_rec visited) {row with row_bound = []} + end +@@ -343,25 +346,27 @@ + | _ -> false) + fields in + let all_present = List.length present = List.length fields in ++ let static = row.row_closed && all_present in ++ let obj = ++ if static then [] else ++ List.map (fun (s,k,t) -> (s, tree_of_typexp sch t)) row.row_object ++ in ++ let tags = if all_present then None else Some (List.map fst present) in + begin match row.row_name with + | Some(p, tyl) when namable_row row -> + let id = tree_of_path p in + let args = tree_of_typlist sch tyl in +- if row.row_closed && all_present then ++ if static then + Otyp_constr (id, args) + else + let non_gen = is_non_gen sch px in +- let tags = +- if all_present then None else Some (List.map fst present) in + Otyp_variant (non_gen, Ovar_name(tree_of_path p, args), +- row.row_closed, tags) ++ row.row_closed, tags, obj) + | _ -> +- let non_gen = +- not (row.row_closed && all_present) && is_non_gen sch px in ++ let non_gen = not static && is_non_gen sch px in + let fields = List.map (tree_of_row_field sch) fields in +- let tags = +- if all_present then None else Some (List.map fst present) in +- Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, tags) ++ Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, ++ tags, obj) + end + | Tobject (fi, nm) -> + tree_of_typobject sch fi nm +Index: typecore.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typecore.ml,v +retrieving revision 1.176.2.2 +diff -u -r1.176.2.2 typecore.ml +--- typecore.ml 11 Dec 2005 09:56:33 -0000 1.176.2.2 ++++ typecore.ml 16 Jan 2006 02:23:15 -0000 +@@ -170,7 +170,8 @@ + (* Force check of well-formedness *) + unify_pat pat.pat_env pat + (newty(Tvariant{row_fields=[]; row_more=newvar(); row_closed=false; +- row_bound=[]; row_fixed=false; row_name=None})); ++ row_bound=[]; row_fixed=false; row_name=None; ++ row_object=[]})); + | _ -> () + + let rec iter_pattern f p = +@@ -251,7 +252,7 @@ + let ty = may_map (build_as_type env) p' in + newty (Tvariant{row_fields=[l, Rpresent ty]; row_more=newvar(); + row_bound=[]; row_name=None; +- row_fixed=false; row_closed=false}) ++ row_fixed=false; row_closed=false; row_object=[]}) + | Tpat_record lpl -> + let lbl = fst(List.hd lpl) in + if lbl.lbl_private = Private then p.pat_type else +@@ -318,7 +319,8 @@ + ([],[]) fields in + let row = + { row_fields = List.rev fields; row_more = newvar(); row_bound = !bound; +- row_closed = false; row_fixed = false; row_name = Some (path, tyl) } ++ row_closed = false; row_fixed = false; row_name = Some (path, tyl); ++ row_object = [] } + in + let ty = newty (Tvariant row) in + let gloc = {loc with Location.loc_ghost=true} in +@@ -428,7 +430,8 @@ + row_closed = false; + row_more = newvar (); + row_fixed = false; +- row_name = None } in ++ row_name = None; ++ row_object = [] } in + rp { + pat_desc = Tpat_variant(l, arg, row); + pat_loc = sp.ppat_loc; +@@ -976,7 +979,8 @@ + row_bound = []; + row_closed = false; + row_fixed = false; +- row_name = None}); ++ row_name = None; ++ row_object = []}); + exp_env = env } + | Pexp_record(lid_sexp_list, opt_sexp) -> + let ty = newvar() in +@@ -1261,8 +1265,30 @@ + assert false + end + | _ -> +- (Texp_send(obj, Tmeth_name met), +- filter_method env met Public obj.exp_type) ++ let obj, met_ty = ++ match expand_head env obj.exp_type with ++ {desc = Tvariant _} -> ++ let exp_ty = newvar () in ++ let met_ty = filter_method env met Public exp_ty in ++ let row = ++ {row_fields=[]; row_more=newvar(); ++ row_bound=[]; row_closed=false; ++ row_fixed=false; row_name=None; ++ row_object=[met, Fpresent, met_ty]} in ++ unify_exp env obj (newty (Tvariant row)); ++ let prim = Primitive.parse_declaration 1 ["%field1"] in ++ let ty = newty(Tarrow("", obj.exp_type, exp_ty, Cok)) in ++ let vd = {val_type = ty; val_kind = Val_prim prim} in ++ let esnd = ++ {exp_desc=Texp_ident(Path.Pident(Ident.create"snd"), vd); ++ exp_loc = Location.none; exp_type = ty; exp_env = env} ++ in ++ ({obj with exp_type = exp_ty; ++ exp_desc = Texp_apply(esnd,[Some obj, Required])}, ++ met_ty) ++ | _ -> (obj, filter_method env met Public obj.exp_type) ++ in ++ (Texp_send(obj, Tmeth_name met), met_ty) + in + if !Clflags.principal then begin + end_def (); +Index: types.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.ml,v +retrieving revision 1.25 +diff -u -r1.25 types.ml +--- types.ml 9 Dec 2004 12:40:53 -0000 1.25 ++++ types.ml 16 Jan 2006 02:23:15 -0000 +@@ -44,7 +44,9 @@ + row_bound: type_expr list; + row_closed: bool; + row_fixed: bool; +- row_name: (Path.t * type_expr list) option } ++ row_name: (Path.t * type_expr list) option; ++ row_object: (string * field_kind * type_expr) list; ++ } + + and row_field = + Rpresent of type_expr option +Index: types.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.mli,v +retrieving revision 1.25 +diff -u -r1.25 types.mli +--- types.mli 9 Dec 2004 12:40:53 -0000 1.25 ++++ types.mli 16 Jan 2006 02:23:15 -0000 +@@ -43,7 +43,9 @@ + row_bound: type_expr list; + row_closed: bool; + row_fixed: bool; +- row_name: (Path.t * type_expr list) option } ++ row_name: (Path.t * type_expr list) option; ++ row_object: (string * field_kind * type_expr) list; ++ } + + and row_field = + Rpresent of type_expr option +Index: typetexp.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typetexp.ml,v +retrieving revision 1.54 +diff -u -r1.54 typetexp.ml +--- typetexp.ml 22 Jul 2005 06:42:36 -0000 1.54 ++++ typetexp.ml 16 Jan 2006 02:23:15 -0000 +@@ -215,7 +215,8 @@ + in + let row = { row_closed = true; row_fields = fields; + row_bound = !bound; row_name = Some (path, args); +- row_fixed = false; row_more = newvar () } in ++ row_fixed = false; row_more = newvar (); ++ row_object = [] } in + let static = Btype.static_row row in + let row = + if static then row else +@@ -262,7 +263,7 @@ + let mkfield l f = + newty (Tvariant {row_fields=[l,f]; row_more=newvar(); + row_bound=[]; row_closed=true; +- row_fixed=false; row_name=None}) in ++ row_fixed=false; row_name=None; row_object=[]}) in + let add_typed_field loc l f fields = + try + let f' = List.assoc l fields in +@@ -345,7 +346,7 @@ + let row = + { row_fields = List.rev fields; row_more = newvar (); + row_bound = !bound; row_closed = closed; +- row_fixed = false; row_name = !name } in ++ row_fixed = false; row_name = !name; row_object = [] } in + let static = Btype.static_row row in + let row = + if static then row else diff --git a/testlabl/objvariant.ml b/testlabl/objvariant.ml new file mode 100644 index 0000000..3233e03 --- /dev/null +++ b/testlabl/objvariant.ml @@ -0,0 +1,42 @@ +(* use with [cvs update -r objvariants typing] *) + +let f (x : [> ]) = x#m 3;; +let o = object method m x = x+2 end;; +f (`A o);; +let l = [`A o; `B(object method m x = x -2 method y = 3 end)];; +List.map f l;; +let g = function `A x -> x#m 3 | `B x -> x#y;; +List.map g l;; +fun x -> ignore (x=f); List.map x l;; +fun (x : [< `A of _ | `B of _] -> int) -> ignore (x=f); List.map x l;; + + +class cvar name = + object + method name = name + method print ppf = Format.pp_print_string ppf name + end + +type var = [`Var of cvar] + +class cint n = + object + method n = n + method print ppf = Format.pp_print_int ppf n + end + +class ['a] cadd (e1 : 'a) (e2 : 'a) = + object + constraint 'a = [> ] + method e1 = e1 + method e2 = e2 + method print ppf = Format.fprintf ppf "(%t, %t)" e1#print e2#print + end + +type 'a expr = [var | `Int of cint | `Add of 'a cadd] + +type expr1 = expr1 expr + +let print = Format.printf "%t@." + +let e1 : expr1 = `Add (new cadd (`Var (new cvar "x")) (`Int (new cint 2))) diff --git a/testlabl/poly.exp b/testlabl/poly.exp new file mode 100644 index 0000000..497cfc6 --- /dev/null +++ b/testlabl/poly.exp @@ -0,0 +1,446 @@ + Objective Caml version 3.11.0+beta1 + +# * * * # type 'a t = { t : 'a; } +# type 'a fold = { fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b; } +# val f : 'a list -> 'a fold = <fun> +# - : int = 6 +# class ['a] ilist : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class virtual ['a] vlist : + object ('b) + method virtual add : 'a -> 'b + method virtual fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ilist2 : + int list -> + object ('a) + val l : int list + method add : int -> 'a + method fold : f:('b -> int -> 'b) -> init:'b -> 'b + end +# val ilist2 : 'a list -> 'a vlist = <fun> +# class ['a] ilist3 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ['a] ilist4 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ['a] ilist5 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd + end +# class ['a] ilist6 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd + end +# class virtual ['a] olist : + object method virtual fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end +# class ['a] onil : + object method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end +# class ['a] ocons : + hd:'a -> + tl:'a olist -> + object + val hd : 'a + val tl : 'a olist + method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b + end +# class ['a] ostream : + hd:'a -> + tl:'a ostream -> + object + val hd : 'a + val tl : 'a ostream + method empty : bool + method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b + end +# class ['a] ostream1 : + hd:'a -> + tl:'b -> + object ('b) + val hd : 'a + val tl : 'b + method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c + method hd : 'a + method tl : 'b + end +# class vari : object method m : [< `A | `B | `C ] -> int end +# class vari : object method m : [< `A | `B | `C ] -> int end +# module V : sig type v = [ `A | `B | `C ] val m : [< v ] -> int end +# class varj : object method m : [< V.v ] -> int end +# module type T = + sig class vari : object method m : [< `A | `B | `C ] -> int end end +# module M0 : + sig class vari : object method m : [< `A | `B | `C ] -> int end end +# module M : T +# val v : M.vari = <obj> +# - : int = 1 +# class point : + x:int -> + y:int -> object val x : int val y : int method x : int method y : int end +# class color_point : + x:int -> + y:int -> + color:string -> + object + val color : string + val x : int + val y : int + method color : string + method x : int + method y : int + end +# class circle : + #point -> + r:int -> + object val p : point val r : int method distance : #point -> float end +# val p0 : point = <obj> +val p1 : point = <obj> +val cp : color_point = <obj> +val c : circle = <obj> +val d : float = 11.4536240470737098 +# val f : < m : 'a. 'a -> 'a > -> < m : 'a. 'a -> 'a > = <fun> +# Characters 41-42: +Error: This expression has type < m : 'a. 'a -> 'a list > + but is here used with type < m : 'a. 'a -> 'b > + The universal variable 'a would escape its scope +# class id : object method id : 'a -> 'a end +# class type id_spec = object method id : 'a -> 'a end +# class id_impl : object method id : 'a -> 'a end +# class a : object method m : bool end +and b : object method id : 'a -> 'a end +# Characters 72-77: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a +# Characters 75-80: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a +# Characters 80-85: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b +# Characters 92-159: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b +# class c : object method m : 'a -> 'b -> 'a end +# val f1 : id -> int * bool = <fun> +# val f2 : id -> int * bool = <fun> +# Characters 24-28: +Error: This expression has type bool but is here used with type int +# val f4 : id -> int * bool = <fun> +# class c : object method m : #id -> int * bool end +# class id2 : object method id : 'a -> 'a method mono : int -> int end +# val app : int * bool = (1, true) +# Characters 4-25: +Error: The type abbreviation foo is cyclic +# class ['a] bar : 'a -> object end +# type 'a foo = 'a foo bar +# - : (< m : 'b. 'b * 'a > as 'a) -> 'c * 'a = <fun> +# - : (< m : 'b. 'a * 'b list > as 'a) -> 'a * 'c list = <fun> +# val f : + (< m : 'b. 'a * (< n : 'b; .. > as 'b) > as 'a) -> + 'a * (< n : 'c; .. > as 'c) = <fun> +# - : (< p : 'b. < m : 'b; n : 'a; .. > as 'b > as 'a) -> + (< m : 'c; n : 'a; .. > as 'c) += <fun> +# - : (< m : 'b. 'b * < p : 'd. 'd * 'c * 'a > as 'c > as 'a) -> + ('f * < p : 'g. 'g * 'e * 'a > as 'e) += <fun> +# - : < m : 'a. < p : 'a; .. > as 'b > -> 'b = <fun> +# type sum = T of < id : 'a. 'a -> 'a > +# - : sum -> 'a -> 'a = <fun> +# type record = { r : < id : 'a. 'a -> 'a >; } +# - : record -> 'a -> 'a = <fun> +# - : record -> 'a -> 'a = <fun> +# class myself : object ('a) method self : 'b -> 'a end +# class number : + object ('a) + val num : int + method num : int + method prev : 'a + method succ : 'a + method switch : zero:(unit -> 'b) -> prev:('a -> 'b) -> 'b + end +# val id : 'a -> 'a = <fun> +# class c : object method id : 'a -> 'a end +# class c' : object method id : 'a -> 'a end +# class d : + object + val mutable count : int + method count : int + method id : 'a -> 'a + method old : 'b -> 'b + end +# class ['a] olist : + 'a list -> + object ('b) + val l : 'a list + method cons : 'a -> 'b + method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c + end +# val sum : int #olist -> int = <fun> +# val count : 'a #olist -> int = <fun> +# val append : 'a #olist -> ('a #olist as 'b) -> 'b = <fun> +# type 'a t = unit +# class o : object method x : [> `A ] t -> unit end +# class c : object method m : d end +and d : ?x:int -> unit -> object end +# class d : ?x:int -> unit -> object end +and c : object method m : d end +# class type numeral = object method fold : ('a -> 'a) -> 'a -> 'a end +class zero : object method fold : ('a -> 'a) -> 'a -> 'a end +class next : #numeral -> object method fold : ('a -> 'a) -> 'a -> 'a end +# class type node_type = object method as_variant : [> `Node of node_type ] end +# class node : node_type +# class node : object method as_variant : [> `Node of node_type ] end +# type bad = { bad : 'a. 'a option ref; } +# Characters 17-25: +Error: This field value has type 'a option ref which is less general than + 'b. 'b option ref +# type bad2 = { mutable bad2 : 'a. 'a option ref option; } +# val bad2 : bad2 = {bad2 = None} +# Characters 13-28: +Error: This field value has type 'a option ref option + which is less general than 'b. 'b option ref option +# val f : < m : 'a. < p : 'a * 'b > as 'b > -> 'c -> unit = <fun> +# val f : < m : 'a. 'a * (< p : int * 'b > as 'b) > -> 'b -> unit = <fun> +# type 'a t = [ `A of 'a ] +# class c : object method m : ([> 'a t ] as 'a) -> unit end +# class c : object method m : ([> 'a t ] as 'a) -> unit end +# class c : object method m : ([> 'a t ] as 'a) -> 'a end +# class c : object method m : ([> `A ] as 'a) option -> 'a end +# Characters 145-166: +Error: This type scheme cannot quantify 'a : +it escapes this scope. +# type ('a, 'b) list_visitor = < caseCons : 'b -> 'b list -> 'a; caseNil : 'a > +type 'a alist = < visit : 'b. ('b, 'a) list_visitor -> 'b > +class type ct = object ('a) method fold : ('b -> 'a -> 'b) -> 'b -> 'b end +type t = { f : 'a 'b. ('b -> (#ct as 'a) -> 'b) -> 'b; } +# Characters 19-25: +Error: The type abbreviation t is cyclic +# class ['a] a : object constraint 'a = [> `A of 'a a ] end +type t = [ `A of t a ] +# Characters 71-80: +Error: Constraints are not satisfied in this type. +Type ('a, 'b) t should be an instance of ('c, 'c) t +# type 'a t = 'a +and u = int t +# type 'a t constraint 'a = int +# Characters 26-32: +Error: Constraints are not satisfied in this type. +Type 'a u t should be an instance of int t +# type 'a u = 'a constraint 'a = int +and 'a v = 'a u t constraint 'a = int +# type g = int +# type 'a t = unit constraint 'a = g +# Characters 26-32: +Error: Constraints are not satisfied in this type. +Type 'a u t should be an instance of g t +# type 'a u = 'a constraint 'a = g +and 'a v = 'a u t constraint 'a = int +# Characters 38-58: +Error: In the definition of v, type 'a list u should be 'a u +# type 'a t = 'a +type 'a u = A of 'a t +# type 'a t = < a : 'a > +# - : ('a t as 'a) -> 'a t = <fun> +# type u = 'a t as 'a +# type t = A | B +# - : [> `A ] * t -> int = <fun> +# - : [> `A ] * t -> int = <fun> +# - : [> `A ] option * t -> int = <fun> +# - : [> `A ] option * t -> int = <fun> +# - : t * [< `A | `B ] -> int = <fun> +# - : [< `A | `B ] * t -> int = <fun> +# Characters 0-41: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(`AnyExtraTag, `AnyExtraTag) +- : [> `A | `B ] * [> `A | `B ] -> int = <fun> +# Characters 0-29: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(_, 0) +Characters 21-24: +Warning U: this match case is unused. +- : [< `B ] * int -> int = <fun> +# Characters 0-29: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(0, _) +Characters 21-24: +Warning U: this match case is unused. +- : int * [< `B ] -> int = <fun> +# Characters 69-135: +Error: Constraints are not satisfied in this type. +Type +([> `B of 'a ], 'a) b as 'a +should be an instance of +(('b, [> `A of 'b ] as 'c) a as 'b, 'c) b +# class type ['a, 'b] a = + object + constraint 'a = ('a, 'b) #a + constraint 'b = ('a, 'b) #b + method as_a : ('a, 'b) a + method b : 'b + end +and ['a, 'b] b = + object + constraint 'a = ('a, 'b) #a + constraint 'b = ('a, 'b) #b + method a : 'a + method as_b : ('a, 'b) b + end +class type ['a] ca = + object ('b) + constraint 'a = ('b, 'a) #b + method as_a : ('b, 'a) a + method b : 'a + end +class type ['a] cb = + object ('b) + constraint 'a = ('a, 'b) #a + method a : 'a + method as_b : ('a, 'b) b + end +type bt = 'a ca cb as 'a +# class c : object method m : int end +# val f : unit -> c = <fun> +# val f : unit -> c = <fun> +# Characters 11-60: +Warning X: the following private methods were made public implicitly: + n. +val f : unit -> < m : int; n : int > = <fun> +# Characters 11-56: +Error: This object is expected to have type c but has actually type + < m : int; n : 'a > + The first object type has no method n +# Characters 11-69: +Error: This object is expected to have type < n : int > but has actually type + < m : 'a > + The second object type has no method n +# Characters 66-124: +Error: This object is expected to have type < x : int; .. > + but has actually type < x : int > + Self type cannot be unified with a closed object type +# val o : < x : int > = <obj> +# Characters 76-77: +Error: This expression has type < m : 'b. 'b * < m : 'b * 'a > > as 'a + but is here used with type + < m : 'b. 'b * (< m : 'b * < m : 'd. 'd * 'c > > as 'c) > + Types for method m are incompatible +# Characters 176-177: +Error: This expression has type foo' = < m : 'a. 'a * 'a foo > + but is here used with type bar' = < m : 'a. 'a * 'a bar > + Type 'a foo = < m : 'a * 'a foo > is not compatible with type + 'a bar = < m : 'a * < m : 'b. 'b * 'a bar > > + Type 'a foo = < m : 'a * 'a foo > is not compatible with type + < m : 'b. 'b * 'a bar > + Types for method m are incompatible +# Characters 67-68: +Error: This expression has type + < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > + but is here used with type + < m : 'a. 'a * ('a * < m : 'c. 'c * ('c * 'd) >) > as 'd + Types for method m are incompatible +# Characters 66-67: +Error: This expression has type + < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > + but is here used with type + < m : 'a. 'a * ('a * < m : 'c. 'c * ('a * 'd) >) > as 'd + Types for method m are incompatible +# Characters 51-52: +Error: This expression has type < m : 'b. 'b * ('b * 'a) > as 'a + but is here used with type + < m : 'b. 'b * ('b * < m : 'd. 'd * 'c > as 'c) > + Types for method m are incompatible +# Characters 14-115: +Error: Type < m : 'a. 'a -> ('a * (< m : 'd. 'd -> 'b as 'e > as 'c) as 'b) > + is not a subtype of type < m : 'a. 'a -> ('a * 'f as 'h) as 'g > as 'f +# Characters 88-150: +Error: Signature mismatch: + Modules do not match: + sig val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit end + is not included in + sig + val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit + end + Values do not match: + val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit + is not included in + val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit +# Characters 78-132: +Error: Signature mismatch: + Modules do not match: + sig type t = < m : 'b. 'b * ('b * 'a) > as 'a end + is not included in + sig type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > end + Type declarations do not match: + type t = < m : 'b. 'b * ('b * 'a) > as 'a + is not included in + type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > +# module M : sig type 'a t type u = < m : 'a. 'a t > end +# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end +# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end +# val f : + (< m : 'b. 'b -> (< m : 'b. 'b -> 'c * < > > as 'c) * < .. >; .. > as 'a) -> + 'a -> bool = <fun> +# type t = [ `A | `B ] +# type v = private [> t ] +# - : t -> v = <fun> +# type u = private [< t ] +# - : u -> v = <fun> +# Characters 9-21: +Error: Type v = [> `A | `B ] is not a subtype of type u = [< `A | `B ] +# type v = private [< t ] +# Characters 9-21: +Error: Type u = [< `A | `B ] is not a subtype of type v = [< `A | `B ] +# type p = < x : p > +# type q = private < x : p; .. > +# - : q -> p = <fun> +# Characters 9-21: +Error: Type p = < x : p > is not a subtype of type q = < x : p; .. > +# Characters 14-100: +Error: Type < m : 'a. (< p : int; .. > as 'a) -> int > + is not a subtype of type + < m : 'b. (< p : int; q : int; .. > as 'b) -> int > +# val f2 : + < m : 'a. (< p : < a : int >; .. > as 'a) -> int > -> + < m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int > = <fun> +# Characters 13-107: +Error: Type < m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int > + is not a subtype of type + < m : 'a. (< p : < a : int >; .. > as 'a) -> int > +# Characters 11-55: +Error: Type < p : < a : int; b : int >; .. > is not a subtype of type + < p : < a : int >; .. > +The second object type has no method b +# val f5 : + < m : 'a. [< `A of < p : int > ] as 'a > -> + < m : 'a. [< `A of < > ] as 'a > = <fun> +# Characters 13-83: +Error: Type < m : 'a. [< `A of < > ] as 'a > is not a subtype of type + < m : 'a. [< `A of < p : int > ] as 'a > +# class c : object method id : 'a -> 'a end +# type u = c option +# val just : 'a option -> 'a = <fun> +# val f : c -> 'a -> 'a = <fun> +# val g : c -> 'a -> 'a = <fun> +# val h : < id : 'a; .. > -> 'a = <fun> +# * * * * * * * * * * * * * * * * * * * diff --git a/testlabl/poly.exp2 b/testlabl/poly.exp2 new file mode 100644 index 0000000..5b31128 --- /dev/null +++ b/testlabl/poly.exp2 @@ -0,0 +1,459 @@ + Objective Caml version 3.11.0+beta1 + +# * * * # type 'a t = { t : 'a; } +# type 'a fold = { fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b; } +# val f : 'a list -> 'a fold = <fun> +# - : int = 6 +# class ['a] ilist : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class virtual ['a] vlist : + object ('b) + method virtual add : 'a -> 'b + method virtual fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ilist2 : + int list -> + object ('a) + val l : int list + method add : int -> 'a + method fold : f:('b -> int -> 'b) -> init:'b -> 'b + end +# val ilist2 : 'a list -> 'a vlist = <fun> +# class ['a] ilist3 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ['a] ilist4 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + end +# class ['a] ilist5 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd + end +# class ['a] ilist6 : + 'a list -> + object ('b) + val l : 'a list + method add : 'a -> 'b + method fold : f:('c -> 'a -> 'c) -> init:'c -> 'c + method fold2 : f:('d -> 'a -> 'd) -> init:'d -> 'd + end +# class virtual ['a] olist : + object method virtual fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end +# class ['a] onil : + object method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b end +# class ['a] ocons : + hd:'a -> + tl:'a olist -> + object + val hd : 'a + val tl : 'a olist + method fold : f:('a -> 'b -> 'b) -> init:'b -> 'b + end +# class ['a] ostream : + hd:'a -> + tl:'a ostream -> + object + val hd : 'a + val tl : < empty : bool; fold : 'b. f:('a -> 'b -> 'b) -> init:'b -> 'b > + method empty : bool + method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c + end +# class ['a] ostream1 : + hd:'a -> + tl:'b -> + object ('b) + val hd : 'a + val tl : 'b + method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c + method hd : 'a + method tl : 'b + end +# class vari : object method m : [< `A | `B | `C ] -> int end +# class vari : object method m : [< `A | `B | `C ] -> int end +# module V : sig type v = [ `A | `B | `C ] val m : [< v ] -> int end +# class varj : object method m : [< V.v ] -> int end +# module type T = + sig class vari : object method m : [< `A | `B | `C ] -> int end end +# module M0 : + sig class vari : object method m : [< `A | `B | `C ] -> int end end +# module M : T +# val v : M.vari = <obj> +# - : int = 1 +# class point : + x:int -> + y:int -> object val x : int val y : int method x : int method y : int end +# class color_point : + x:int -> + y:int -> + color:string -> + object + val color : string + val x : int + val y : int + method color : string + method x : int + method y : int + end +# class circle : + #point -> + r:int -> + object val p : point val r : int method distance : #point -> float end +# val p0 : point = <obj> +val p1 : point = <obj> +val cp : color_point = <obj> +val c : circle = <obj> +val d : float = 11.4536240470737098 +# val f : < m : 'a. 'a -> 'a > -> < m : 'b. 'b -> 'b > = <fun> +# Characters 41-42: +Error: This expression has type < m : 'a. 'a -> 'a list > + but is here used with type < m : 'a. 'a -> 'b > + The universal variable 'a would escape its scope +# class id : object method id : 'a -> 'a end +# class type id_spec = object method id : 'a -> 'a end +# class id_impl : object method id : 'a -> 'a end +# class a : object method m : bool end +and b : object method id : 'a -> 'a end +# Characters 72-77: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a +# Characters 75-80: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'a +# Characters 80-85: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b +# Characters 92-159: +Error: This method has type 'a -> 'a which is less general than 'b. 'b -> 'b +# class c : object method m : 'a -> 'b -> 'a end +# val f1 : id -> int * bool = <fun> +# val f2 : id -> int * bool = <fun> +# Characters 24-28: +Error: This expression has type bool but is here used with type int +# Characters 27-31: +Warning X: this use of a polymorphic method is not principal. +Characters 35-39: +Warning X: this use of a polymorphic method is not principal. +val f4 : id -> int * bool = <fun> +# class c : object method m : #id -> int * bool end +# class id2 : object method id : 'a -> 'a method mono : int -> int end +# val app : int * bool = (1, true) +# Characters 4-25: +Error: The type abbreviation foo is cyclic +# class ['a] bar : 'a -> object end +# type 'a foo = 'a foo bar +# - : (< m : 'b. 'b * 'a > as 'a) -> 'c * (< m : 'e. 'e * 'd > as 'd) = <fun> +# - : (< m : 'b. 'a * 'b list > as 'a) -> + (< m : 'd. 'c * 'd list > as 'c) * 'e list += <fun> +# val f : + (< m : 'b. 'a * (< n : 'b; .. > as 'b) > as 'a) -> + (< m : 'd. 'c * (< n : 'd; .. > as 'd) > as 'c) * (< n : 'e; .. > as 'e) = + <fun> +# - : (< p : 'b. < m : 'b; n : 'a; .. > as 'b > as 'a) -> + (< m : 'c; n : < p : 'e. < m : 'e; n : 'd; .. > as 'e > as 'd; .. > as 'c) += <fun> +# - : (< m : 'b. 'b * < p : 'd. 'd * 'c * 'a > as 'c > as 'a) -> + ('f * + < p : 'g. + 'g * 'e * + (< m : 'i. 'i * < p : 'k. 'k * 'j * 'h > as 'j > as 'h) > + as 'e) += <fun> +# - : < m : 'a. < p : 'a; .. > as 'b > -> 'b = <fun> +# type sum = T of < id : 'a. 'a -> 'a > +# - : sum -> 'a -> 'a = <fun> +# type record = { r : < id : 'a. 'a -> 'a >; } +# - : record -> 'a -> 'a = <fun> +# - : record -> 'a -> 'a = <fun> +# class myself : object ('a) method self : 'b -> 'a end +# class number : + object ('a) + val num : int + method num : int + method prev : 'a + method succ : 'a + method switch : zero:(unit -> 'b) -> prev:('a -> 'b) -> 'b + end +# val id : 'a -> 'a = <fun> +# class c : object method id : 'a -> 'a end +# class c' : object method id : 'a -> 'a end +# class d : + object + val mutable count : int + method count : int + method id : 'a -> 'a + method old : 'b -> 'b + end +# class ['a] olist : + 'a list -> + object ('b) + val l : 'a list + method cons : 'a -> 'b + method fold : f:('a -> 'c -> 'c) -> init:'c -> 'c + end +# val sum : int #olist -> int = <fun> +# val count : 'a #olist -> int = <fun> +# val append : 'a #olist -> ('a #olist as 'b) -> 'b = <fun> +# type 'a t = unit +# class o : object method x : [> `A ] t -> unit end +# class c : object method m : d end +and d : ?x:int -> unit -> object end +# class d : ?x:int -> unit -> object end +and c : object method m : d end +# class type numeral = object method fold : ('a -> 'a) -> 'a -> 'a end +class zero : object method fold : ('a -> 'a) -> 'a -> 'a end +class next : #numeral -> object method fold : ('a -> 'a) -> 'a -> 'a end +# class type node_type = object method as_variant : [> `Node of node_type ] end +# class node : node_type +# class node : object method as_variant : [> `Node of node_type ] end +# type bad = { bad : 'a. 'a option ref; } +# Characters 17-25: +Error: This field value has type 'a option ref which is less general than + 'b. 'b option ref +# type bad2 = { mutable bad2 : 'a. 'a option ref option; } +# val bad2 : bad2 = {bad2 = None} +# Characters 13-28: +Error: This field value has type 'a option ref option + which is less general than 'b. 'b option ref option +# val f : < m : 'a. < p : 'a * 'b > as 'b > -> 'c -> unit = <fun> +# val f : + < m : 'a. 'a * (< p : int * 'b > as 'b) > -> + (< p : int * 'c > as 'c) -> unit = <fun> +# type 'a t = [ `A of 'a ] +# class c : object method m : ([> 'a t ] as 'a) -> unit end +# class c : object method m : ([> 'a t ] as 'a) -> unit end +# class c : object method m : ([> 'a t ] as 'a) -> 'a end +# class c : object method m : ([> `A ] as 'a) option -> 'a end +# Characters 145-166: +Error: This type scheme cannot quantify 'a : +it escapes this scope. +# type ('a, 'b) list_visitor = < caseCons : 'b -> 'b list -> 'a; caseNil : 'a > +type 'a alist = < visit : 'b. ('b, 'a) list_visitor -> 'b > +class type ct = object ('a) method fold : ('b -> 'a -> 'b) -> 'b -> 'b end +type t = { f : 'a 'b. ('b -> (#ct as 'a) -> 'b) -> 'b; } +# Characters 19-25: +Error: The type abbreviation t is cyclic +# class ['a] a : object constraint 'a = [> `A of 'a a ] end +type t = [ `A of t a ] +# Characters 71-80: +Error: Constraints are not satisfied in this type. +Type ('a, 'b) t should be an instance of ('c, 'c) t +# type 'a t = 'a +and u = int t +# type 'a t constraint 'a = int +# Characters 26-32: +Error: Constraints are not satisfied in this type. +Type 'a u t should be an instance of int t +# type 'a u = 'a constraint 'a = int +and 'a v = 'a u t constraint 'a = int +# type g = int +# type 'a t = unit constraint 'a = g +# Characters 26-32: +Error: Constraints are not satisfied in this type. +Type 'a u t should be an instance of g t +# type 'a u = 'a constraint 'a = g +and 'a v = 'a u t constraint 'a = int +# Characters 38-58: +Error: In the definition of v, type 'a list u should be 'a u +# type 'a t = 'a +type 'a u = A of 'a t +# type 'a t = < a : 'a > +# - : ('a t as 'a) -> ('b t as 'b) t = <fun> +# type u = 'a t as 'a +# type t = A | B +# - : [> `A ] * t -> int = <fun> +# - : [> `A ] * t -> int = <fun> +# - : [> `A ] option * t -> int = <fun> +# - : [> `A ] option * t -> int = <fun> +# - : t * [< `A | `B ] -> int = <fun> +# - : [< `A | `B ] * t -> int = <fun> +# Characters 0-41: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(`AnyExtraTag, `AnyExtraTag) +- : [> `A | `B ] * [> `A | `B ] -> int = <fun> +# Characters 0-29: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(_, 0) +Characters 21-24: +Warning U: this match case is unused. +- : [< `B ] * int -> int = <fun> +# Characters 0-29: +Warning P: this pattern-matching is not exhaustive. +Here is an example of a value that is not matched: +(0, _) +Characters 21-24: +Warning U: this match case is unused. +- : int * [< `B ] -> int = <fun> +# Characters 69-135: +Error: Constraints are not satisfied in this type. +Type +([> `B of 'a ], 'a) b as 'a +should be an instance of +(('b, [> `A of ('d, 'c) a as 'd ] as 'c) a as 'b, 'c) b +# class type ['a, 'b] a = + object + constraint 'a = ('a, 'b) #a + constraint 'b = ('a, 'b) #b + method as_a : ('a, 'b) a + method b : 'b + end +and ['a, 'b] b = + object + constraint 'a = ('a, 'b) #a + constraint 'b = ('a, 'b) #b + method a : 'a + method as_b : ('a, 'b) b + end +class type ['a] ca = + object ('b) + constraint 'a = ('b, 'a) #b + method as_a : ('b, 'a) a + method b : 'a + end +class type ['a] cb = + object ('b) + constraint 'a = ('a, 'b) #a + method a : 'a + method as_b : ('a, 'b) b + end +type bt = 'a ca cb as 'a +# class c : object method m : int end +# val f : unit -> c = <fun> +# val f : unit -> c = <fun> +# Characters 11-60: +Warning X: the following private methods were made public implicitly: + n. +val f : unit -> < m : int; n : int > = <fun> +# Characters 11-56: +Error: This object is expected to have type c but has actually type + < m : int; n : 'a > + The first object type has no method n +# Characters 11-69: +Error: This object is expected to have type < n : int > but has actually type + < m : 'a > + The second object type has no method n +# Characters 66-124: +Error: This object is expected to have type < x : int; .. > + but has actually type < x : int > + Self type cannot be unified with a closed object type +# val o : < x : int > = <obj> +# Characters 76-77: +Error: This expression has type < m : 'b. 'b * < m : 'b * 'a > > as 'a + but is here used with type + < m : 'b. 'b * (< m : 'b * < m : 'd. 'd * 'c > > as 'c) > + Types for method m are incompatible +# Characters 176-177: +Error: This expression has type foo' = < m : 'a. 'a * 'a foo > + but is here used with type bar' = < m : 'a. 'a * 'a bar > + Type 'a foo = < m : 'a * 'a foo > is not compatible with type + 'a bar = < m : 'a * < m : 'b. 'b * 'a bar > > + Type 'a foo = < m : 'a * 'a foo > is not compatible with type + < m : 'b. 'b * 'a bar > + Types for method m are incompatible +# Characters 67-68: +Error: This expression has type + < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > + but is here used with type + < m : 'a. 'a * ('a * < m : 'c. 'c * ('c * 'd) >) > as 'd + Types for method m are incompatible +# Characters 66-67: +Error: This expression has type + < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > + but is here used with type + < m : 'a. 'a * ('a * < m : 'c. 'c * ('a * 'd) >) > as 'd + Types for method m are incompatible +# Characters 51-52: +Error: This expression has type < m : 'b. 'b * ('b * 'a) > as 'a + but is here used with type + < m : 'b. 'b * ('b * < m : 'd. 'd * 'c > as 'c) > + Types for method m are incompatible +# Characters 14-115: +Error: Type < m : 'a. 'a -> ('a * (< m : 'd. 'd -> 'b as 'e > as 'c) as 'b) > + is not a subtype of type < m : 'a. 'a -> ('a * 'f as 'h) as 'g > as 'f +# Characters 88-150: +Error: Signature mismatch: + Modules do not match: + sig val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit end + is not included in + sig + val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit + end + Values do not match: + val f : (< m : 'b. 'b * ('b * 'a) > as 'a) -> unit + is not included in + val f : < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > -> unit +# Characters 78-132: +Error: Signature mismatch: + Modules do not match: + sig type t = < m : 'b. 'b * ('b * 'a) > as 'a end + is not included in + sig type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > end + Type declarations do not match: + type t = < m : 'b. 'b * ('b * 'a) > as 'a + is not included in + type t = < m : 'a. 'a * ('a * < m : 'c. 'c * 'b > as 'b) > +# module M : sig type 'a t type u = < m : 'a. 'a t > end +# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end +# module M : sig type 'a t val f : < m : 'a. 'a t > -> int end +# val f : + (< m : 'b. 'b -> (< m : 'b. 'b -> 'c * < > > as 'c) * < .. >; .. > as 'a) -> + 'a -> bool = <fun> +# type t = [ `A | `B ] +# type v = private [> t ] +# - : t -> v = <fun> +# type u = private [< t ] +# - : u -> v = <fun> +# Characters 9-21: +Error: Type v = [> `A | `B ] is not a subtype of type u = [< `A | `B ] +# type v = private [< t ] +# Characters 9-21: +Error: Type u = [< `A | `B ] is not a subtype of type v = [< `A | `B ] +# type p = < x : p > +# type q = private < x : p; .. > +# - : q -> p = <fun> +# Characters 9-21: +Error: Type p = < x : p > is not a subtype of type q = < x : p; .. > +# Characters 14-100: +Error: Type < m : 'a. (< p : int; .. > as 'a) -> int > + is not a subtype of type + < m : 'b. (< p : int; q : int; .. > as 'b) -> int > +# val f2 : + < m : 'a. (< p : < a : int >; .. > as 'a) -> int > -> + < m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int > = <fun> +# Characters 13-107: +Error: Type < m : 'a. (< p : < a : int; b : int >; .. > as 'a) -> int > + is not a subtype of type + < m : 'a. (< p : < a : int >; .. > as 'a) -> int > +# Characters 11-55: +Error: Type < p : < a : int; b : int >; .. > is not a subtype of type + < p : < a : int >; .. > +The second object type has no method b +# val f5 : + < m : 'a. [< `A of < p : int > ] as 'a > -> + < m : 'a. [< `A of < > ] as 'a > = <fun> +# Characters 13-83: +Error: Type < m : 'a. [< `A of < > ] as 'a > is not a subtype of type + < m : 'a. [< `A of < p : int > ] as 'a > +# class c : object method id : 'a -> 'a end +# type u = c option +# val just : 'a option -> 'a = <fun> +# val f : c -> 'a -> 'a = <fun> +# val g : c -> 'a -> 'a = <fun> +# val h : < id : 'a; .. > -> 'a = <fun> +# * * * * * * * * * * * * * * * * * * * diff --git a/testlabl/poly.ml b/testlabl/poly.ml new file mode 100644 index 0000000..99c8ee0 --- /dev/null +++ b/testlabl/poly.ml @@ -0,0 +1,590 @@ +(* $Id: poly.ml,v 1.39 2006-11-21 02:31:53 garrigue Exp $ *) +(* + Polymorphic methods are now available in the main branch. + Enjoy. +*) + +(* Tests for explicit polymorphism *) +open StdLabels;; + +type 'a t = { t : 'a };; +type 'a fold = { fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b };; +let f l = { fold = List.fold_left l };; +(f [1;2;3]).fold ~f:(+) ~init:0;; + +class ['b] ilist l = object + val l = l + method add x = {< l = x :: l >} + method fold : 'a. f:('a -> 'b -> 'a) -> init:'a -> 'a = + List.fold_left l +end +;; +class virtual ['a] vlist = object (_ : 'self) + method virtual add : 'a -> 'self + method virtual fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b +end +;; +class ilist2 l = object + inherit [int] vlist + val l = l + method add x = {< l = x :: l >} + method fold = List.fold_left l +end +;; +let ilist2 l = object + inherit [_] vlist + val l = l + method add x = {< l = x :: l >} + method fold = List.fold_left l +end +;; +class ['a] ilist3 l = object + inherit ['a] vlist + val l = l + method add x = {< l = x :: l >} + method fold = List.fold_left l +end +;; +class ['a] ilist4 (l : 'a list) = object + val l = l + method virtual add : _ + method add x = {< l = x :: l >} + method virtual fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b + method fold = List.fold_left l +end +;; +class ['a] ilist5 (l : 'a list) = object (self) + val l = l + method add x = {< l = x :: l >} + method virtual fold : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b + method virtual fold2 : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b + method fold2 ~f ~init = self#fold ~f ~init:(self#fold ~f ~init) + method fold = List.fold_left l +end +;; +class ['a] ilist6 l = object (self) + inherit ['a] vlist + val l = l + method add x = {< l = x :: l >} + method virtual fold2 : 'b. f:('b -> 'a -> 'b) -> init:'b -> 'b + method fold2 ~f ~init = self#fold ~f ~init:(self#fold ~f ~init) + method fold = List.fold_left l +end +;; +class virtual ['a] olist = object + method virtual fold : 'c. f:('a -> 'c -> 'c) -> init:'c -> 'c +end +;; +class ['a] onil = object + inherit ['a] olist + method fold ~f ~init = init +end +;; +class ['a] ocons ~hd ~tl = object (_ : 'b) + inherit ['a] olist + val hd : 'a = hd + val tl : 'a olist = tl + method fold ~f ~init = f hd (tl#fold ~f ~init) +end +;; +class ['a] ostream ~hd ~tl = object (_ : 'b) + inherit ['a] olist + val hd : 'a = hd + val tl : _ #olist = (tl : 'a ostream) + method fold ~f ~init = f hd (tl#fold ~f ~init) + method empty = false +end +;; +class ['a] ostream1 ~hd ~tl = object (self : 'b) + inherit ['a] olist + val hd = hd + val tl : 'b = tl + method hd = hd + method tl = tl + method fold ~f ~init = + self#tl#fold ~f ~init:(f self#hd init) +end +;; + +class vari = object + method virtual m : 'a. ([< `A|`B|`C] as 'a) -> int + method m = function `A -> 1 | `B|`C -> 0 +end +;; +class vari = object + method m : 'a. ([< `A|`B|`C] as 'a) -> int = function `A -> 1 | `B|`C -> 0 +end +;; +module V = + struct + type v = [`A | `B | `C] + let m : [< v] -> int = function `A -> 1 | #v -> 0 + end +;; +class varj = object + method virtual m : 'a. ([< V.v] as 'a) -> int + method m = V.m +end +;; + +module type T = sig + class vari : object method m : 'a. ([< `A | `B | `C] as 'a) -> int end +end +;; +module M0 = struct + class vari = object + method virtual m : 'a. ([< `A|`B|`C] as 'a) -> int + method m = function `A -> 1 | `B|`C -> 0 + end +end +;; +module M : T = M0 +;; +let v = new M.vari;; +v#m `A;; + +class point ~x ~y = object + val x : int = x + val y : int = y + method x = x + method y = y +end +;; +class color_point ~x ~y ~color = object + inherit point ~x ~y + val color : string = color + method color = color +end +;; +class circle (p : #point) ~r = object + val p = (p :> point) + val r = r + method virtual distance : 'a. (#point as 'a) -> float + method distance p' = + let dx = p#x - p'#x and dy = p#y - p'#y in + let d = sqrt (float (dx * dx + dy * dy)) -. float r in + if d < 0. then 0. else d +end +;; +let p0 = new point ~x:3 ~y:5 +let p1 = new point ~x:10 ~y:13 +let cp = new color_point ~x:12 ~y:(-5) ~color:"green" +let c = new circle p0 ~r:2 +let d = c#distance cp +;; +let f (x : < m : 'a. 'a -> 'a >) = (x : < m : 'b. 'b -> 'b >) +;; +let f (x : < m : 'a. 'a -> 'a list >) = (x : < m : 'b. 'b -> 'c >) +;; + +class id = object + method virtual id : 'a. 'a -> 'a + method id x = x +end +;; + +class type id_spec = object + method id : 'a -> 'a +end +;; +class id_impl = object (_ : #id_spec) + method id x = x +end +;; + +class a = object + method m = (new b : id_spec)#id true +end +and b = object (_ : #id_spec) + method id x = x +end +;; + +class ['a] id1 = object + method virtual id : 'b. 'b -> 'a + method id x = x +end +;; +class id2 (x : 'a) = object + method virtual id : 'b. 'b -> 'a + method id x = x +end +;; +class id3 x = object + val x = x + method virtual id : 'a. 'a -> 'a + method id _ = x +end +;; +class id4 () = object + val mutable r = None + method virtual id : 'a. 'a -> 'a + method id x = + match r with + None -> r <- Some x; x + | Some y -> y +end +;; +class c = object + method virtual m : 'a 'b. 'a -> 'b -> 'a + method m x y = x +end +;; + +let f1 (f : id) = f#id 1, f#id true +;; +let f2 f = (f : id)#id 1, (f : id)#id true +;; +let f3 f = f#id 1, f#id true +;; +let f4 f = ignore(f : id); f#id 1, f#id true +;; + +class c = object + method virtual m : 'a. (#id as 'a) -> int * bool + method m (f : #id) = f#id 1, f#id true +end +;; + +class id2 = object (_ : 'b) + method virtual id : 'a. 'a -> 'a + method id x = x + method mono (x : int) = x +end +;; +let app = new c #m (new id2) +;; +type 'a foo = 'a foo list +;; + +class ['a] bar (x : 'a) = object end +;; +type 'a foo = 'a foo bar +;; + +fun x -> (x : < m : 'a. 'a * 'b > as 'b)#m;; +fun x -> (x : < m : 'a. 'b * 'a list> as 'b)#m;; +let f x = (x : < m : 'a. 'b * (< n : 'a; .. > as 'a) > as 'b)#m;; +fun (x : < p : 'a. < m : 'a ; n : 'b ; .. > as 'a > as 'b) -> x#p;; +fun (x : <m:'a. 'a * <p:'b. 'b * 'c * 'd> as 'c> as 'd) -> x#m;; +(* printer is wrong on the next (no official syntax) *) +fun (x : <m:'a.<p:'a;..> >) -> x#m;; + +type sum = T of < id: 'a. 'a -> 'a > ;; +fun (T x) -> x#id;; + +type record = { r: < id: 'a. 'a -> 'a > } ;; +fun x -> x.r#id;; +fun {r=x} -> x#id;; + +class myself = object (self) + method self : 'a. 'a -> 'b = fun _ -> self +end;; + +class number = object (self : 'self) + val num = 0 + method num = num + method succ = {< num = num + 1 >} + method prev = + self#switch ~zero:(fun () -> failwith "zero") ~prev:(fun x -> x) + method switch : 'a. zero:(unit -> 'a) -> prev:('self -> 'a) -> 'a = + fun ~zero ~prev -> + if num = 0 then zero () else prev {< num = num - 1 >} +end +;; + +let id x = x +;; +class c = object + method id : 'a. 'a -> 'a = id +end +;; +class c' = object + inherit c + method id = id +end +;; +class d = object + inherit c as c + val mutable count = 0 + method id x = count <- count+1; x + method count = count + method old : 'a. 'a -> 'a = c#id +end +;; +class ['a] olist l = object + val l = l + method fold : 'b. f:('a -> 'b -> 'b) -> init:'b -> 'b + = List.fold_right l + method cons a = {< l = a :: l >} +end +;; +let sum (l : 'a #olist) = l#fold ~f:(fun x acc -> x+acc) ~init:0 +;; +let count (l : 'a #olist) = l#fold ~f:(fun _ acc -> acc+1) ~init:0 +;; +let append (l : 'a #olist) (l' : 'b #olist) = + l#fold ~init:l' ~f:(fun x acc -> acc#cons x) +;; + +type 'a t = unit +;; +class o = object method x : 'a. ([> `A] as 'a) t -> unit = fun _ -> () end +;; + +class c = object method m = new d () end and d ?(x=0) () = object end;; +class d ?(x=0) () = object end and c = object method m = new d () end;; + +class type numeral = object method fold : ('a -> 'a) -> 'a -> 'a end +class zero = object (_ : #numeral) method fold f x = x end +class next (n : #numeral) = + object (_ : #numeral) method fold f x = n#fold f (f x) end +;; + +class type node_type = object + method as_variant : [> `Node of node_type] +end;; +class node : node_type = object (self) + method as_variant : 'a. [> `Node of node_type] as 'a + = `Node (self :> node_type) +end;; +class node = object (self : #node_type) + method as_variant = `Node (self :> node_type) +end;; + +type bad = {bad : 'a. 'a option ref};; +let bad = {bad = ref None};; +type bad2 = {mutable bad2 : 'a. 'a option ref option};; +let bad2 = {bad2 = None};; +bad2.bad2 <- Some (ref None);; + +(* Type variable scope *) + +let f (x: <m:'a.<p: 'a * 'b> as 'b>) (y : 'b) = ();; +let f (x: <m:'a. 'a * (<p:int*'b> as 'b)>) (y : 'b) = ();; + +(* PR#1374 *) + +type 'a t= [`A of 'a];; +class c = object (self) + method m : 'a. ([> 'a t] as 'a) -> unit + = fun x -> self#m x +end;; +class c = object (self) + method m : 'a. ([> 'a t] as 'a) -> unit = function + | `A x' -> self#m x' + | _ -> failwith "c#m" +end;; +class c = object (self) + method m : 'a. ([> 'a t] as 'a) -> 'a = fun x -> self#m x +end;; + +(* usage avant instance *) +class c = object method m : 'a. 'a option -> ([> `A] as 'a) = fun x -> `A end;; + +(* various old bugs *) +class virtual ['a] visitor = +object method virtual caseNil : 'a end +and virtual int_list = +object method virtual visit : 'a.('a visitor -> 'a) end;; + +type ('a,'b) list_visitor = < caseNil : 'a; caseCons : 'b -> 'b list -> 'a > +type 'b alist = < visit : 'a. ('a,'b) list_visitor -> 'a > + +(* PR#1607 *) +class type ct = object ('s) + method fold : ('b -> 's -> 'b) -> 'b -> 'b +end +type t = {f : 'a 'b. ('b -> (#ct as 'a) -> 'b) -> 'b};; + +(* PR#1663 *) +type t = u and u = t;; + +(* PR#1731 *) +class ['t] a = object constraint 't = [> `A of 't a] end +type t = [ `A of t a ];; + +(* Wrong in 3.06 *) +type ('a,'b) t constraint 'a = 'b and ('a,'b) u = ('a,'b) t;; + +(* Full polymorphism if we do not expand *) +type 'a t = 'a and u = int t;; + +(* Loose polymorphism if we expand *) +type 'a t constraint 'a = int;; +type 'a u = 'a and 'a v = 'a u t;; +type 'a u = 'a and 'a v = 'a u t constraint 'a = int;; + +(* Behaviour is unstable *) +type g = int;; +type 'a t = unit constraint 'a = g;; +type 'a u = 'a and 'a v = 'a u t;; +type 'a u = 'a and 'a v = 'a u t constraint 'a = int;; + +(* Example of wrong expansion *) +type 'a u = < m : 'a v > and 'a v = 'a list u;; + +(* PR#1744: Ctype.matches *) +type 'a t = 'a +type 'a u = A of 'a t;; + +(* Unification of cyclic terms *) +type 'a t = < a : 'a >;; +fun (x : 'a t as 'a) -> (x : 'b t);; +type u = 'a t as 'a;; + + +(* Variant tests *) +type t = A | B;; +function `A,_ -> 1 | _,A -> 2 | _,B -> 3;; +function `A,_ -> 1 | _,(A|B) -> 2;; +function Some `A, _ -> 1 | Some _, A -> 2 | None, A -> 3 | _, B -> 4;; +function Some `A, A -> 1 | Some `A, B -> 1 + | Some _, A -> 2 | None, A -> 3 | _, B -> 4;; +function A, `A -> 1 | A, `B -> 2 | B, _ -> 3;; +function `A, A -> 1 | `B, A -> 2 | _, B -> 3;; +function (`A|`B), _ -> 0 | _,(`A|`B) -> 1;; +function `B,1 -> 1 | _,1 -> 2;; +function 1,`B -> 1 | 1,_ -> 2;; + +(* pass typetexp, but fails during Typedecl.check_recursion *) +type ('a, 'b) a = 'a -> unit constraint 'a = [> `B of ('a, 'b) b as 'b] +and ('a, 'b) b = 'b -> unit constraint 'b = [> `A of ('a, 'b) a as 'a];; + +(* PR#1917: expanding may change original in Ctype.unify2 *) +class type ['a, 'b] a = object + method b: ('a, 'b) #b as 'b + method as_a: ('a, 'b) a +end and ['a, 'b] b = object + method a: ('a, 'b) #a as 'a + method as_b: ('a, 'b) b +end + +class type ['b] ca = object ('s) inherit ['s, 'b] a end +class type ['a] cb = object ('s) inherit ['a, 's] b end + +type bt = 'b ca cb as 'b +;; + +(* final classes, etc... *) +class c = object method m = 1 end;; +let f () = object (self:c) method m = 1 end;; +let f () = object (self:c) method private n = 1 method m = self#n end;; +let f () = object method private n = 1 method m = {<>}#n end;; +let f () = object (self:c) method n = 1 method m = 2 end;; +let f () = object (_:'s) constraint 's = < n : int > method m = 1 end;; +class c = object (_ : 's) + method x = 1 + method private m = + object (self: 's) method x = 3 method private m = self end +end;; +let o = object (_ : 's) + method x = 1 + method private m = + object (self: 's) method x = 3 method private m = self end +end;; + + +(* Unsound! *) +fun (x : <m : 'a. 'a * <m: 'b. 'a * 'foo> > as 'foo) -> + (x : <m : 'a. 'a * (<m:'b. 'a * <m:'c. 'c * 'bar> > as 'bar) >);; +type 'a foo = <m: 'b. 'a * 'a foo> +type foo' = <m: 'a. 'a * 'a foo> +type 'a bar = <m: 'b. 'a * <m: 'c. 'c * 'a bar> > +type bar' = <m: 'a. 'a * 'a bar > +let f (x : foo') = (x : bar');; + +fun (x : <m : 'a. 'a * ('a * <m : 'a. 'a * 'foo> as 'foo)>) -> + (x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('c * 'bar)>)> as 'bar);; +fun (x : <m : 'a. 'a * ('a * <m : 'a. 'a * 'foo> as 'foo)>) -> + (x : <m : 'b. 'b * ('b * <m : 'c. 'c * ('b * 'bar)>)> as 'bar);; +fun (x : <m : 'a. 'a * ('a * 'foo)> as 'foo) -> + (x : <m : 'b. 'b * ('b * <m:'c. 'c * 'bar> as 'bar)>);; +let f x = + (x : <m : 'a. 'a -> ('a * <m:'c. 'c -> 'bar> as 'bar)> + :> <m : 'a. 'a -> ('a * 'foo)> as 'foo);; + +module M +: sig val f : (<m : 'b. 'b * ('b * <m:'c. 'c * 'bar> as 'bar)>) -> unit end += struct let f (x : <m : 'a. 'a * ('a * 'foo)> as 'foo) = () end;; +module M +: sig type t = <m : 'b. 'b * ('b * <m:'c. 'c * 'bar> as 'bar)> end += struct type t = <m : 'a. 'a * ('a * 'foo)> as 'foo end;; + +module M : sig type 'a t type u = <m: 'a. 'a t> end += struct type 'a t = int type u = <m: int> end;; +module M : sig type 'a t val f : <m: 'a. 'a t> -> int end += struct type 'a t = int let f (x : <m:int>) = x#m end;; +(* The following should be accepted too! *) +module M : sig type 'a t val f : <m: 'a. 'a t> -> int end += struct type 'a t = int let f x = x#m end;; + +let f x y = + ignore (x :> <m:'a.'a -> 'c * < > > as 'c); + ignore (y :> <m:'b.'b -> 'd * < > > as 'd); + x = y;; + + +(* Subtyping *) + +type t = [`A|`B];; +type v = private [> t];; +fun x -> (x : t :> v);; +type u = private [< t];; +fun x -> (x : u :> v);; +fun x -> (x : v :> u);; +type v = private [< t];; +fun x -> (x : u :> v);; +type p = <x:p>;; +type q = private <x:p; ..>;; +fun x -> (x : q :> p);; +fun x -> (x : p :> q);; + +let f1 x = + (x : <m:'a. (<p:int;..> as 'a) -> int> + :> <m:'b. (<p:int;q:int;..> as 'b) -> int>);; +let f2 x = + (x : <m:'a. (<p:<a:int>;..> as 'a) -> int> + :> <m:'b. (<p:<a:int;b:int>;..> as 'b) -> int>);; +let f3 x = + (x : <m:'a. (<p:<a:int;b:int>;..> as 'a) -> int> + :> <m:'b. (<p:<a:int>;..> as 'b) -> int>);; +let f4 x = (x : <p:<a:int;b:int>;..> :> <p:<a:int>;..>);; +let f5 x = + (x : <m:'a. [< `A of <p:int> ] as 'a> :> <m:'a. [< `A of < > ] as 'a>);; +let f6 x = + (x : <m:'a. [< `A of < > ] as 'a> :> <m:'a. [< `A of <p:int> ] as 'a>);; + +(* Not really principal? *) +class c = object method id : 'a. 'a -> 'a = fun x -> x end;; +type u = c option;; +let just = function None -> failwith "just" | Some x -> x;; +let f x = let l = [Some x; (None : u)] in (just(List.hd l))#id;; +let g x = + let none = match None with y -> ignore [y;(None:u)]; y in + let x = List.hd [Some x; none] in (just x)#id;; +let h x = + let none = let y = None in ignore [y;(None:u)]; y in + let x = List.hd [Some x; none] in (just x)#id;; + +(* polymorphic recursion *) +(* +let rec 'a. f : 'a -> _ = fun x -> 1 and g x = f x;; +type 'a t = Leaf of 'a | Node of ('a * 'a) t;; +let rec 'a. depth : 'a t -> _ = + function Leaf _ -> 1 | Node x -> 1 + d x +and d x = depth x;; +let rec 'a. depth : 'a t -> _ = + function Leaf _ -> 1 | Node x -> 1 + depth x;; +let rec 'a. depth : 'a t -> _ = + function Leaf x -> x | Node x -> 1 + depth x;; +let rec 'a. depth : 'a t -> _ = + function Leaf x -> x | Node x -> depth x;; +let rec 'a 'b. depth : 'a t -> 'b = + function Leaf x -> x | Node x -> depth x;; +let rec 'a. r : 'a list * 'b list ref = [], ref [] +and q () = r;; +let rec 'a. f : _ -> _ = fun x -> x;; +let 'a as [> `Int of int | `B of 'b] 'b. zero : 'a = `Int 0;; +let 'a as [< `Int of int]. zero : 'a = `Int 0;; +*) diff --git a/testlabl/printers.ml b/testlabl/printers.ml new file mode 100644 index 0000000..5937858 --- /dev/null +++ b/testlabl/printers.ml @@ -0,0 +1,11 @@ +(* $Id: printers.ml,v 1.1 2003-04-03 02:16:20 garrigue Exp $ *) + +open Types + +let ignore_abbrevs ppf ab = + let s = match ab with + Mnil -> "Mnil" + | Mlink _ -> "Mlink _" + | Mcons _ -> "Mcons _" + in + Format.pp_print_string ppf s diff --git a/testlabl/private.ml b/testlabl/private.ml new file mode 100644 index 0000000..f865163 --- /dev/null +++ b/testlabl/private.ml @@ -0,0 +1,31 @@ +module Foobar : sig + type t = private int +end = struct + type t = int +end;; + +module F0 : sig type t = private int end = Foobar;; + +let f (x : F0.t) = (x : Foobar.t);; (* fails *) + +module F = Foobar;; + +let f (x : F.t) = (x : Foobar.t);; + +module M = struct type t = <m:int> end;; +module M1 : sig type t = private <m:int; ..> end = M;; +module M2 : sig type t = private <m:int; ..> end = M1;; +fun (x : M1.t) -> (x : M2.t);; (* fails *) + +module M3 : sig type t = private M1.t end = M1;; +fun x -> (x : M3.t :> M1.t);; +fun x -> (x : M3.t :> M.t);; +module M4 : sig type t = private M3.t end = M2;; (* fails *) +module M4 : sig type t = private M3.t end = M;; (* fails *) +module M4 : sig type t = private M3.t end = M1;; (* might be ok *) +module M5 : sig type t = private M1.t end = M3;; +module M6 : sig type t = private < n:int; .. > end = M1;; (* fails *) + +module Bar : sig type t = private Foobar.t val f : int -> t end = + struct type t = int let f (x : int) = (x : t) end;; (* must fail *) + diff --git a/testlabl/tests.ml b/testlabl/tests.ml new file mode 100644 index 0000000..2a9406b --- /dev/null +++ b/testlabl/tests.ml @@ -0,0 +1,22 @@ +(* $Id: tests.ml,v 1.3 2000-01-07 16:44:44 doligez Exp $ *) + +let f1 = function `a x -> x=1 | `b -> true +let f2 = function `a x -> x | `b -> true +let f3 = function `b -> true +let f x = f1 x && f2 x + +let sub s ?:pos{=0} ?:len{=String.length s - pos} () = + String.sub s pos len + +let cCAMLtoTKpack_options w = function + `After v1 -> "-after" + | `Anchor v1 -> "-anchor" + | `Before v1 -> "-before" + | `Expand v1 -> "-expand" + | `Fill v1 -> "-fill" + | `In v1 -> "-in" + | `Ipadx v1 -> "-ipadx" + | `Ipady v1 -> "-ipady" + | `Padx v1 -> "-padx" + | `Pady v1 -> "-pady" + | `Side v1 -> "-side" diff --git a/testlabl/valvirt.diffs b/testlabl/valvirt.diffs new file mode 100644 index 0000000..b8b17ef --- /dev/null +++ b/testlabl/valvirt.diffs @@ -0,0 +1,2349 @@ +Index: utils/warnings.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/utils/warnings.ml,v +retrieving revision 1.23 +diff -u -r1.23 warnings.ml +--- utils/warnings.ml 15 Sep 2005 03:09:26 -0000 1.23 ++++ utils/warnings.ml 5 Apr 2006 02:25:59 -0000 +@@ -26,7 +26,7 @@ + | Statement_type (* S *) + | Unused_match (* U *) + | Unused_pat +- | Hide_instance_variable of string (* V *) ++ | Instance_variable_override of string (* V *) + | Illegal_backslash (* X *) + | Implicit_public_methods of string list + | Unerasable_optional_argument +@@ -54,7 +54,7 @@ + | Statement_type -> 's' + | Unused_match + | Unused_pat -> 'u' +- | Hide_instance_variable _ -> 'v' ++ | Instance_variable_override _ -> 'v' + | Illegal_backslash + | Implicit_public_methods _ + | Unerasable_optional_argument +@@ -126,9 +126,9 @@ + String.concat " " + ("the following methods are overriden \ + by the inherited class:\n " :: slist) +- | Hide_instance_variable lab -> +- "this definition of an instance variable " ^ lab ^ +- " hides a previously\ndefined instance variable of the same name." ++ | Instance_variable_override lab -> ++ "the instance variable " ^ lab ^ " is overriden.\n" ^ ++ "The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)" + | Partial_application -> + "this function application is partial,\n\ + maybe some arguments are missing." +Index: utils/warnings.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/utils/warnings.mli,v +retrieving revision 1.16 +diff -u -r1.16 warnings.mli +--- utils/warnings.mli 15 Sep 2005 03:09:26 -0000 1.16 ++++ utils/warnings.mli 5 Apr 2006 02:25:59 -0000 +@@ -26,7 +26,7 @@ + | Statement_type (* S *) + | Unused_match (* U *) + | Unused_pat +- | Hide_instance_variable of string (* V *) ++ | Instance_variable_override of string (* V *) + | Illegal_backslash (* X *) + | Implicit_public_methods of string list + | Unerasable_optional_argument +Index: parsing/parser.mly +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/parser.mly,v +retrieving revision 1.123 +diff -u -r1.123 parser.mly +--- parsing/parser.mly 23 Mar 2005 03:08:37 -0000 1.123 ++++ parsing/parser.mly 5 Apr 2006 02:25:59 -0000 +@@ -623,6 +623,8 @@ + { [] } + | class_fields INHERIT class_expr parent_binder + { Pcf_inher ($3, $4) :: $1 } ++ | class_fields VAL virtual_value ++ { Pcf_valvirt $3 :: $1 } + | class_fields VAL value + { Pcf_val $3 :: $1 } + | class_fields virtual_method +@@ -638,14 +640,20 @@ + AS LIDENT + { Some $2 } + | /* empty */ +- {None} ++ { None } ++; ++virtual_value: ++ MUTABLE VIRTUAL label COLON core_type ++ { $3, Mutable, $5, symbol_rloc () } ++ | VIRTUAL mutable_flag label COLON core_type ++ { $3, $2, $5, symbol_rloc () } + ; + value: +- mutable_flag label EQUAL seq_expr +- { $2, $1, $4, symbol_rloc () } +- | mutable_flag label type_constraint EQUAL seq_expr +- { $2, $1, (let (t, t') = $3 in ghexp(Pexp_constraint($5, t, t'))), +- symbol_rloc () } ++ mutable_flag label EQUAL seq_expr ++ { $2, $1, $4, symbol_rloc () } ++ | mutable_flag label type_constraint EQUAL seq_expr ++ { $2, $1, (let (t, t') = $3 in ghexp(Pexp_constraint($5, t, t'))), ++ symbol_rloc () } + ; + virtual_method: + METHOD PRIVATE VIRTUAL label COLON poly_type +@@ -711,8 +719,12 @@ + | class_sig_fields CONSTRAINT constrain { Pctf_cstr $3 :: $1 } + ; + value_type: +- mutable_flag label COLON core_type +- { $2, $1, Some $4, symbol_rloc () } ++ VIRTUAL mutable_flag label COLON core_type ++ { $3, $2, Virtual, $5, symbol_rloc () } ++ | MUTABLE virtual_flag label COLON core_type ++ { $3, Mutable, $2, $5, symbol_rloc () } ++ | label COLON core_type ++ { $1, Immutable, Concrete, $3, symbol_rloc () } + ; + method_type: + METHOD private_flag label COLON poly_type +Index: parsing/parsetree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/parsetree.mli,v +retrieving revision 1.42 +diff -u -r1.42 parsetree.mli +--- parsing/parsetree.mli 23 Mar 2005 03:08:37 -0000 1.42 ++++ parsing/parsetree.mli 5 Apr 2006 02:25:59 -0000 +@@ -152,7 +152,7 @@ + + and class_type_field = + Pctf_inher of class_type +- | Pctf_val of (string * mutable_flag * core_type option * Location.t) ++ | Pctf_val of (string * mutable_flag * virtual_flag * core_type * Location.t) + | Pctf_virt of (string * private_flag * core_type * Location.t) + | Pctf_meth of (string * private_flag * core_type * Location.t) + | Pctf_cstr of (core_type * core_type * Location.t) +@@ -179,6 +179,7 @@ + + and class_field = + Pcf_inher of class_expr * string option ++ | Pcf_valvirt of (string * mutable_flag * core_type * Location.t) + | Pcf_val of (string * mutable_flag * expression * Location.t) + | Pcf_virt of (string * private_flag * core_type * Location.t) + | Pcf_meth of (string * private_flag * expression * Location.t) +Index: parsing/printast.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/parsing/printast.ml,v +retrieving revision 1.29 +diff -u -r1.29 printast.ml +--- parsing/printast.ml 4 Jan 2006 16:55:50 -0000 1.29 ++++ parsing/printast.ml 5 Apr 2006 02:25:59 -0000 +@@ -353,10 +353,11 @@ + | Pctf_inher (ct) -> + line i ppf "Pctf_inher\n"; + class_type i ppf ct; +- | Pctf_val (s, mf, cto, loc) -> ++ | Pctf_val (s, mf, vf, ct, loc) -> + line i ppf +- "Pctf_val \"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; +- option i core_type ppf cto; ++ "Pctf_val \"%s\" %a %a %a\n" s ++ fmt_mutable_flag mf fmt_virtual_flag vf fmt_location loc; ++ core_type (i+1) ppf ct; + | Pctf_virt (s, pf, ct, loc) -> + line i ppf + "Pctf_virt \"%s\" %a %a\n" s fmt_private_flag pf fmt_location loc; +@@ -428,6 +429,10 @@ + line i ppf "Pcf_inher\n"; + class_expr (i+1) ppf ce; + option (i+1) string ppf so; ++ | Pcf_valvirt (s, mf, ct, loc) -> ++ line i ppf ++ "Pcf_valvirt \"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; ++ core_type (i+1) ppf ct; + | Pcf_val (s, mf, e, loc) -> + line i ppf + "Pcf_val \"%s\" %a %a\n" s fmt_mutable_flag mf fmt_location loc; +Index: typing/btype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/btype.ml,v +retrieving revision 1.38 +diff -u -r1.38 btype.ml +--- typing/btype.ml 4 Jan 2006 16:55:50 -0000 1.38 ++++ typing/btype.ml 5 Apr 2006 02:25:59 -0000 +@@ -330,7 +330,7 @@ + + let unmark_class_signature sign = + unmark_type sign.cty_self; +- Vars.iter (fun l (m, t) -> unmark_type t) sign.cty_vars ++ Vars.iter (fun l (m, v, t) -> unmark_type t) sign.cty_vars + + let rec unmark_class_type = + function +Index: typing/ctype.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.ml,v +retrieving revision 1.200 +diff -u -r1.200 ctype.ml +--- typing/ctype.ml 6 Jan 2006 02:16:24 -0000 1.200 ++++ typing/ctype.ml 5 Apr 2006 02:25:59 -0000 +@@ -857,7 +857,7 @@ + Tcty_signature + {cty_self = copy sign.cty_self; + cty_vars = +- Vars.map (function (mut, ty) -> (mut, copy ty)) sign.cty_vars; ++ Vars.map (function (m, v, ty) -> (m, v, copy ty)) sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = + List.map (fun (p,tl) -> (p, List.map copy tl)) sign.cty_inher} +@@ -2354,10 +2354,11 @@ + | CM_Val_type_mismatch of string * (type_expr * type_expr) list + | CM_Meth_type_mismatch of string * (type_expr * type_expr) list + | CM_Non_mutable_value of string ++ | CM_Non_concrete_value of string + | CM_Missing_value of string + | CM_Missing_method of string + | CM_Hide_public of string +- | CM_Hide_virtual of string ++ | CM_Hide_virtual of string * string + | CM_Public_method of string + | CM_Private_method of string + | CM_Virtual_method of string +@@ -2390,8 +2391,8 @@ + end) + pairs; + Vars.iter +- (fun lab (mut, ty) -> +- let (mut', ty') = Vars.find lab sign1.cty_vars in ++ (fun lab (mut, v, ty) -> ++ let (mut', v', ty') = Vars.find lab sign1.cty_vars in + try moregen true type_pairs env ty' ty with Unify trace -> + raise (Failure [CM_Val_type_mismatch + (lab, expand_trace env trace)])) +@@ -2437,7 +2438,7 @@ + end + in + if Concr.mem lab sign1.cty_concr then err +- else CM_Hide_virtual lab::err) ++ else CM_Hide_virtual ("method", lab) :: err) + miss1 [] + in + let missing_method = List.map (fun (m, _, _) -> m) miss2 in +@@ -2455,11 +2456,13 @@ + in + let error = + Vars.fold +- (fun lab (mut, ty) err -> ++ (fun lab (mut, vr, ty) err -> + try +- let (mut', ty') = Vars.find lab sign1.cty_vars in ++ let (mut', vr', ty') = Vars.find lab sign1.cty_vars in + if mut = Mutable && mut' <> Mutable then + CM_Non_mutable_value lab::err ++ else if vr = Concrete && vr' <> Concrete then ++ CM_Non_concrete_value lab::err + else + err + with Not_found -> +@@ -2467,6 +2470,14 @@ + sign2.cty_vars error + in + let error = ++ Vars.fold ++ (fun lab (_,vr,_) err -> ++ if vr = Virtual && not (Vars.mem lab sign2.cty_vars) then ++ CM_Hide_virtual ("instance variable", lab) :: err ++ else err) ++ sign1.cty_vars error ++ in ++ let error = + List.fold_right + (fun e l -> + if List.mem e missing_method then l else CM_Virtual_method e::l) +@@ -2516,8 +2527,8 @@ + end) + pairs; + Vars.iter +- (fun lab (mut, ty) -> +- let (mut', ty') = Vars.find lab sign1.cty_vars in ++ (fun lab (_, _, ty) -> ++ let (_, _, ty') = Vars.find lab sign1.cty_vars in + try eqtype true type_pairs subst env ty ty' with Unify trace -> + raise (Failure [CM_Val_type_mismatch + (lab, expand_trace env trace)])) +@@ -2554,7 +2565,7 @@ + end + in + if Concr.mem lab sign1.cty_concr then err +- else CM_Hide_virtual lab::err) ++ else CM_Hide_virtual ("method", lab) :: err) + miss1 [] + in + let missing_method = List.map (fun (m, _, _) -> m) miss2 in +@@ -2578,11 +2589,13 @@ + in + let error = + Vars.fold +- (fun lab (mut, ty) err -> ++ (fun lab (mut, vr, ty) err -> + try +- let (mut', ty') = Vars.find lab sign1.cty_vars in ++ let (mut', vr', ty') = Vars.find lab sign1.cty_vars in + if mut = Mutable && mut' <> Mutable then + CM_Non_mutable_value lab::err ++ else if vr = Concrete && vr' <> Concrete then ++ CM_Non_concrete_value lab::err + else + err + with Not_found -> +@@ -2590,6 +2603,14 @@ + sign2.cty_vars error + in + let error = ++ Vars.fold ++ (fun lab (_,vr,_) err -> ++ if vr = Virtual && not (Vars.mem lab sign2.cty_vars) then ++ CM_Hide_virtual ("instance variable", lab) :: err ++ else err) ++ sign1.cty_vars error ++ in ++ let error = + List.fold_right + (fun e l -> + if List.mem e missing_method then l else CM_Virtual_method e::l) +@@ -3279,7 +3300,7 @@ + let nondep_class_signature env id sign = + { cty_self = nondep_type_rec env id sign.cty_self; + cty_vars = +- Vars.map (function (m, t) -> (m, nondep_type_rec env id t)) ++ Vars.map (function (m, v, t) -> (m, v, nondep_type_rec env id t)) + sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = +Index: typing/ctype.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/ctype.mli,v +retrieving revision 1.53 +diff -u -r1.53 ctype.mli +--- typing/ctype.mli 9 Dec 2004 12:40:53 -0000 1.53 ++++ typing/ctype.mli 5 Apr 2006 02:25:59 -0000 +@@ -170,10 +170,11 @@ + | CM_Val_type_mismatch of string * (type_expr * type_expr) list + | CM_Meth_type_mismatch of string * (type_expr * type_expr) list + | CM_Non_mutable_value of string ++ | CM_Non_concrete_value of string + | CM_Missing_value of string + | CM_Missing_method of string + | CM_Hide_public of string +- | CM_Hide_virtual of string ++ | CM_Hide_virtual of string * string + | CM_Public_method of string + | CM_Private_method of string + | CM_Virtual_method of string +Index: typing/includeclass.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/includeclass.ml,v +retrieving revision 1.7 +diff -u -r1.7 includeclass.ml +--- typing/includeclass.ml 6 Mar 2000 22:11:57 -0000 1.7 ++++ typing/includeclass.ml 5 Apr 2006 02:25:59 -0000 +@@ -78,14 +78,17 @@ + | CM_Non_mutable_value lab -> + fprintf ppf + "@[The non-mutable instance variable %s cannot become mutable@]" lab ++ | CM_Non_concrete_value lab -> ++ fprintf ppf ++ "@[The virtual instance variable %s cannot become concrete@]" lab + | CM_Missing_value lab -> + fprintf ppf "@[The first class type has no instance variable %s@]" lab + | CM_Missing_method lab -> + fprintf ppf "@[The first class type has no method %s@]" lab + | CM_Hide_public lab -> + fprintf ppf "@[The public method %s cannot be hidden@]" lab +- | CM_Hide_virtual lab -> +- fprintf ppf "@[The virtual method %s cannot be hidden@]" lab ++ | CM_Hide_virtual (k, lab) -> ++ fprintf ppf "@[The virtual %s %s cannot be hidden@]" k lab + | CM_Public_method lab -> + fprintf ppf "@[The public method %s cannot become private" lab + | CM_Virtual_method lab -> +Index: typing/oprint.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/oprint.ml,v +retrieving revision 1.22 +diff -u -r1.22 oprint.ml +--- typing/oprint.ml 23 Mar 2005 03:08:37 -0000 1.22 ++++ typing/oprint.ml 5 Apr 2006 02:25:59 -0000 +@@ -291,8 +291,10 @@ + fprintf ppf "@[<2>method %s%s%s :@ %a@]" + (if priv then "private " else "") (if virt then "virtual " else "") + name !out_type ty +- | Ocsg_value (name, mut, ty) -> +- fprintf ppf "@[<2>val %s%s :@ %a@]" (if mut then "mutable " else "") ++ | Ocsg_value (name, mut, vr, ty) -> ++ fprintf ppf "@[<2>val %s%s%s :@ %a@]" ++ (if mut then "mutable " else "") ++ (if vr then "virtual " else "") + name !out_type ty + + let out_class_type = ref print_out_class_type +Index: typing/outcometree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/outcometree.mli,v +retrieving revision 1.14 +diff -u -r1.14 outcometree.mli +--- typing/outcometree.mli 23 Mar 2005 03:08:37 -0000 1.14 ++++ typing/outcometree.mli 5 Apr 2006 02:25:59 -0000 +@@ -71,7 +71,7 @@ + and out_class_sig_item = + | Ocsg_constraint of out_type * out_type + | Ocsg_method of string * bool * bool * out_type +- | Ocsg_value of string * bool * out_type ++ | Ocsg_value of string * bool * bool * out_type + + type out_module_type = + | Omty_abstract +Index: typing/printtyp.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/printtyp.ml,v +retrieving revision 1.140 +diff -u -r1.140 printtyp.ml +--- typing/printtyp.ml 4 Jan 2006 16:55:50 -0000 1.140 ++++ typing/printtyp.ml 5 Apr 2006 02:26:00 -0000 +@@ -650,7 +650,7 @@ + Ctype.flatten_fields (Ctype.object_fields sign.cty_self) + in + List.iter (fun met -> mark_loops (method_type met)) fields; +- Vars.iter (fun _ (_, ty) -> mark_loops ty) sign.cty_vars ++ Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.cty_vars + | Tcty_fun (_, ty, cty) -> + mark_loops ty; + prepare_class_type params cty +@@ -682,13 +682,15 @@ + csil (tree_of_constraints params) + in + let all_vars = +- Vars.fold (fun l (m, t) all -> (l, m, t) :: all) sign.cty_vars [] in ++ Vars.fold (fun l (m, v, t) all -> (l, m, v, t) :: all) sign.cty_vars [] ++ in + (* Consequence of PR#3607: order of Map.fold has changed! *) + let all_vars = List.rev all_vars in + let csil = + List.fold_left +- (fun csil (l, m, t) -> +- Ocsg_value (l, m = Mutable, tree_of_typexp sch t) :: csil) ++ (fun csil (l, m, v, t) -> ++ Ocsg_value (l, m = Mutable, v = Virtual, tree_of_typexp sch t) ++ :: csil) + csil all_vars + in + let csil = +@@ -763,7 +765,9 @@ + List.exists + (fun (lab, _, ty) -> + not (lab = dummy_method || Concr.mem lab sign.cty_concr)) +- fields in ++ fields ++ || Vars.fold (fun _ (_,vr,_) b -> vr = Virtual || b) sign.cty_vars false ++ in + + Osig_class_type + (virt, Ident.name id, +Index: typing/subst.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/subst.ml,v +retrieving revision 1.49 +diff -u -r1.49 subst.ml +--- typing/subst.ml 4 Jan 2006 16:55:50 -0000 1.49 ++++ typing/subst.ml 5 Apr 2006 02:26:00 -0000 +@@ -178,7 +178,8 @@ + + let class_signature s sign = + { cty_self = typexp s sign.cty_self; +- cty_vars = Vars.map (function (m, t) -> (m, typexp s t)) sign.cty_vars; ++ cty_vars = ++ Vars.map (function (m, v, t) -> (m, v, typexp s t)) sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = + List.map (fun (p, tl) -> (type_path s p, List.map (typexp s) tl)) +Index: typing/typeclass.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typeclass.ml,v +retrieving revision 1.85 +diff -u -r1.85 typeclass.ml +--- typing/typeclass.ml 22 Jul 2005 06:42:36 -0000 1.85 ++++ typing/typeclass.ml 5 Apr 2006 02:26:00 -0000 +@@ -24,7 +24,7 @@ + + type error = + Unconsistent_constraint of (type_expr * type_expr) list +- | Method_type_mismatch of string * (type_expr * type_expr) list ++ | Field_type_mismatch of string * string * (type_expr * type_expr) list + | Structure_expected of class_type + | Cannot_apply of class_type + | Apply_wrong_label of label +@@ -36,7 +36,7 @@ + | Unbound_class_type_2 of Longident.t + | Abbrev_type_clash of type_expr * type_expr * type_expr + | Constructor_type_mismatch of string * (type_expr * type_expr) list +- | Virtual_class of bool * string list ++ | Virtual_class of bool * string list * string list + | Parameter_arity_mismatch of Longident.t * int * int + | Parameter_mismatch of (type_expr * type_expr) list + | Bad_parameters of Ident.t * type_expr * type_expr +@@ -49,6 +49,7 @@ + | Non_collapsable_conjunction of + Ident.t * Types.class_declaration * (type_expr * type_expr) list + | Final_self_clash of (type_expr * type_expr) list ++ | Mutability_mismatch of string * mutable_flag + + exception Error of Location.t * error + +@@ -90,7 +91,7 @@ + generalize_class_type cty + | Tcty_signature {cty_self = sty; cty_vars = vars; cty_inher = inher} -> + Ctype.generalize sty; +- Vars.iter (fun _ (_, ty) -> Ctype.generalize ty) vars; ++ Vars.iter (fun _ (_, _, ty) -> Ctype.generalize ty) vars; + List.iter (fun (_,tl) -> List.iter Ctype.generalize tl) inher + | Tcty_fun (_, ty, cty) -> + Ctype.generalize ty; +@@ -152,7 +153,7 @@ + | Tcty_signature sign -> + Ctype.closed_schema sign.cty_self + && +- Vars.fold (fun _ (_, ty) cc -> Ctype.closed_schema ty && cc) ++ Vars.fold (fun _ (_, _, ty) cc -> Ctype.closed_schema ty && cc) + sign.cty_vars + true + | Tcty_fun (_, ty, cty) -> +@@ -172,7 +173,7 @@ + limited_generalize rv cty + | Tcty_signature sign -> + Ctype.limited_generalize rv sign.cty_self; +- Vars.iter (fun _ (_, ty) -> Ctype.limited_generalize rv ty) ++ Vars.iter (fun _ (_, _, ty) -> Ctype.limited_generalize rv ty) + sign.cty_vars; + List.iter (fun (_, tl) -> List.iter (Ctype.limited_generalize rv) tl) + sign.cty_inher +@@ -201,11 +202,25 @@ + Env.add_value id {val_type = ty; val_kind = Val_unbound} par_env) + + (* Enter an instance variable in the environment *) +-let enter_val cl_num vars lab mut ty val_env met_env par_env = +- let (id, val_env, met_env, par_env) as result = +- enter_met_env lab (Val_ivar (mut, cl_num)) ty val_env met_env par_env ++let enter_val cl_num vars inh lab mut virt ty val_env met_env par_env loc = ++ let (id, virt) = ++ try ++ let (id, mut', virt', ty') = Vars.find lab !vars in ++ if mut' <> mut then raise (Error(loc, Mutability_mismatch(lab, mut))); ++ Ctype.unify val_env (Ctype.instance ty) (Ctype.instance ty'); ++ (if not inh then Some id else None), ++ (if virt' = Concrete then virt' else virt) ++ with ++ Ctype.Unify tr -> ++ raise (Error(loc, Field_type_mismatch("instance variable", lab, tr))) ++ | Not_found -> None, virt ++ in ++ let (id, _, _, _) as result = ++ match id with Some id -> (id, val_env, met_env, par_env) ++ | None -> ++ enter_met_env lab (Val_ivar (mut, cl_num)) ty val_env met_env par_env + in +- vars := Vars.add lab (id, mut, ty) !vars; ++ vars := Vars.add lab (id, mut, virt, ty) !vars; + result + + let inheritance self_type env concr_meths warn_meths loc parent = +@@ -218,7 +233,7 @@ + with Ctype.Unify trace -> + match trace with + _::_::_::({desc = Tfield(n, _, _, _)}, _)::rem -> +- raise(Error(loc, Method_type_mismatch (n, rem))) ++ raise(Error(loc, Field_type_mismatch ("method", n, rem))) + | _ -> + assert false + end; +@@ -243,7 +258,7 @@ + in + let ty = transl_simple_type val_env false sty in + try Ctype.unify val_env ty ty' with Ctype.Unify trace -> +- raise(Error(loc, Method_type_mismatch (lab, trace))) ++ raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + + let delayed_meth_specs = ref [] + +@@ -253,7 +268,7 @@ + in + let unif ty = + try Ctype.unify val_env ty ty' with Ctype.Unify trace -> +- raise(Error(loc, Method_type_mismatch (lab, trace))) ++ raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + in + match sty.ptyp_desc, priv with + Ptyp_poly ([],sty), Public -> +@@ -279,6 +294,15 @@ + + (*******************************) + ++let add_val env loc lab (mut, virt, ty) val_sig = ++ let virt = ++ try ++ let (mut', virt', ty') = Vars.find lab val_sig in ++ if virt' = Concrete then virt' else virt ++ with Not_found -> virt ++ in ++ Vars.add lab (mut, virt, ty) val_sig ++ + let rec class_type_field env self_type meths (val_sig, concr_meths, inher) = + function + Pctf_inher sparent -> +@@ -293,25 +317,12 @@ + parent + in + let val_sig = +- Vars.fold +- (fun lab (mut, ty) val_sig -> Vars.add lab (mut, ty) val_sig) +- cl_sig.cty_vars val_sig +- in ++ Vars.fold (add_val env sparent.pcty_loc) cl_sig.cty_vars val_sig in + (val_sig, concr_meths, inher) + +- | Pctf_val (lab, mut, sty_opt, loc) -> +- let (mut, ty) = +- match sty_opt with +- None -> +- let (mut', ty) = +- try Vars.find lab val_sig with Not_found -> +- raise(Error(loc, Unbound_val lab)) +- in +- (if mut = Mutable then mut' else Immutable), ty +- | Some sty -> +- mut, transl_simple_type env false sty +- in +- (Vars.add lab (mut, ty) val_sig, concr_meths, inher) ++ | Pctf_val (lab, mut, virt, sty, loc) -> ++ let ty = transl_simple_type env false sty in ++ (add_val env loc lab (mut, virt, ty) val_sig, concr_meths, inher) + + | Pctf_virt (lab, priv, sty, loc) -> + declare_method env meths self_type lab priv sty loc; +@@ -397,7 +408,7 @@ + + let rec class_field cl_num self_type meths vars + (val_env, met_env, par_env, fields, concr_meths, warn_meths, +- inh_vals, inher) = ++ warn_vals, inher) = + function + Pcf_inher (sparent, super) -> + let parent = class_expr cl_num val_env par_env sparent in +@@ -411,18 +422,23 @@ + parent.cl_type + in + (* Variables *) +- let (val_env, met_env, par_env, inh_vars, inh_vals) = ++ let (val_env, met_env, par_env, inh_vars, warn_vals) = + Vars.fold +- (fun lab (mut, ty) (val_env, met_env, par_env, inh_vars, inh_vals) -> ++ (fun lab info (val_env, met_env, par_env, inh_vars, warn_vals) -> ++ let mut, vr, ty = info in + let (id, val_env, met_env, par_env) = +- enter_val cl_num vars lab mut ty val_env met_env par_env ++ enter_val cl_num vars true lab mut vr ty val_env met_env par_env ++ sparent.pcl_loc + in +- if StringSet.mem lab inh_vals then +- Location.prerr_warning sparent.pcl_loc +- (Warnings.Hide_instance_variable lab); +- (val_env, met_env, par_env, (lab, id) :: inh_vars, +- StringSet.add lab inh_vals)) +- cl_sig.cty_vars (val_env, met_env, par_env, [], inh_vals) ++ let warn_vals = ++ if vr = Virtual then warn_vals else ++ if StringSet.mem lab warn_vals then ++ (Location.prerr_warning sparent.pcl_loc ++ (Warnings.Instance_variable_override lab); warn_vals) ++ else StringSet.add lab warn_vals ++ in ++ (val_env, met_env, par_env, (lab, id) :: inh_vars, warn_vals)) ++ cl_sig.cty_vars (val_env, met_env, par_env, [], warn_vals) + in + (* Inherited concrete methods *) + let inh_meths = +@@ -443,11 +459,26 @@ + in + (val_env, met_env, par_env, + lazy(Cf_inher (parent, inh_vars, inh_meths))::fields, +- concr_meths, warn_meths, inh_vals, inher) ++ concr_meths, warn_meths, warn_vals, inher) ++ ++ | Pcf_valvirt (lab, mut, styp, loc) -> ++ if !Clflags.principal then Ctype.begin_def (); ++ let ty = Typetexp.transl_simple_type val_env false styp in ++ if !Clflags.principal then begin ++ Ctype.end_def (); ++ Ctype.generalize_structure ty ++ end; ++ let (id, val_env, met_env', par_env) = ++ enter_val cl_num vars false lab mut Virtual ty ++ val_env met_env par_env loc ++ in ++ (val_env, met_env', par_env, ++ lazy(Cf_val (lab, id, None, met_env' == met_env)) :: fields, ++ concr_meths, warn_meths, StringSet.remove lab warn_vals, inher) + + | Pcf_val (lab, mut, sexp, loc) -> +- if StringSet.mem lab inh_vals then +- Location.prerr_warning loc (Warnings.Hide_instance_variable lab); ++ if StringSet.mem lab warn_vals then ++ Location.prerr_warning loc (Warnings.Instance_variable_override lab); + if !Clflags.principal then Ctype.begin_def (); + let exp = + try type_exp val_env sexp with Ctype.Unify [(ty, _)] -> +@@ -457,17 +488,19 @@ + Ctype.end_def (); + Ctype.generalize_structure exp.exp_type + end; +- let (id, val_env, met_env, par_env) = +- enter_val cl_num vars lab mut exp.exp_type val_env met_env par_env +- in +- (val_env, met_env, par_env, lazy(Cf_val (lab, id, exp)) :: fields, +- concr_meths, warn_meths, inh_vals, inher) ++ let (id, val_env, met_env', par_env) = ++ enter_val cl_num vars false lab mut Concrete exp.exp_type ++ val_env met_env par_env loc ++ in ++ (val_env, met_env', par_env, ++ lazy(Cf_val (lab, id, Some exp, met_env' == met_env)) :: fields, ++ concr_meths, warn_meths, StringSet.add lab warn_vals, inher) + + | Pcf_virt (lab, priv, sty, loc) -> + virtual_method val_env meths self_type lab priv sty loc; + let warn_meths = Concr.remove lab warn_meths in + (val_env, met_env, par_env, fields, concr_meths, warn_meths, +- inh_vals, inher) ++ warn_vals, inher) + + | Pcf_meth (lab, priv, expr, loc) -> + let (_, ty) = +@@ -493,7 +526,7 @@ + end + | _ -> assert false + with Ctype.Unify trace -> +- raise(Error(loc, Method_type_mismatch (lab, trace))) ++ raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + end; + let meth_expr = make_method cl_num expr in + (* backup variables for Pexp_override *) +@@ -510,12 +543,12 @@ + Cf_meth (lab, texp) + end in + (val_env, met_env, par_env, field::fields, +- Concr.add lab concr_meths, Concr.add lab warn_meths, inh_vals, inher) ++ Concr.add lab concr_meths, Concr.add lab warn_meths, warn_vals, inher) + + | Pcf_cstr (sty, sty', loc) -> + type_constraint val_env sty sty' loc; + (val_env, met_env, par_env, fields, concr_meths, warn_meths, +- inh_vals, inher) ++ warn_vals, inher) + + | Pcf_let (rec_flag, sdefs, loc) -> + let (defs, val_env) = +@@ -545,7 +578,7 @@ + ([], met_env, par_env) + in + (val_env, met_env, par_env, lazy(Cf_let(rec_flag, defs, vals))::fields, +- concr_meths, warn_meths, inh_vals, inher) ++ concr_meths, warn_meths, warn_vals, inher) + + | Pcf_init expr -> + let expr = make_method cl_num expr in +@@ -562,7 +595,7 @@ + Cf_init texp + end in + (val_env, met_env, par_env, field::fields, +- concr_meths, warn_meths, inh_vals, inher) ++ concr_meths, warn_meths, warn_vals, inher) + + and class_structure cl_num final val_env met_env loc (spat, str) = + (* Environment for substructures *) +@@ -616,7 +649,7 @@ + Ctype.unify val_env self_type (Ctype.newvar ()); + let sign = + {cty_self = public_self; +- cty_vars = Vars.map (function (id, mut, ty) -> (mut, ty)) !vars; ++ cty_vars = Vars.map (fun (id, mut, vr, ty) -> (mut, vr, ty)) !vars; + cty_concr = concr_meths; + cty_inher = inher} in + let methods = get_methods self_type in +@@ -628,7 +661,11 @@ + be modified after this point *) + Ctype.close_object self_type; + let mets = virtual_methods {sign with cty_self = self_type} in +- if mets <> [] then raise(Error(loc, Virtual_class(true, mets))); ++ let vals = ++ Vars.fold ++ (fun name (mut, vr, ty) l -> if vr = Virtual then name :: l else l) ++ sign.cty_vars [] in ++ if mets <> [] then raise(Error(loc, Virtual_class(true, mets, vals))); + let self_methods = + List.fold_right + (fun (lab,kind,ty) rem -> +@@ -1135,9 +1172,14 @@ + in + + if cl.pci_virt = Concrete then begin +- match virtual_methods (Ctype.signature_of_class_type typ) with +- [] -> () +- | mets -> raise(Error(cl.pci_loc, Virtual_class(define_class, mets))) ++ let sign = Ctype.signature_of_class_type typ in ++ let mets = virtual_methods sign in ++ let vals = ++ Vars.fold ++ (fun name (mut, vr, ty) l -> if vr = Virtual then name :: l else l) ++ sign.cty_vars [] in ++ if mets <> [] || vals <> [] then ++ raise(Error(cl.pci_loc, Virtual_class(true, mets, vals))); + end; + + (* Misc. *) +@@ -1400,10 +1442,10 @@ + Printtyp.report_unification_error ppf trace + (fun ppf -> fprintf ppf "Type") + (fun ppf -> fprintf ppf "is not compatible with type") +- | Method_type_mismatch (m, trace) -> ++ | Field_type_mismatch (k, m, trace) -> + Printtyp.report_unification_error ppf trace + (function ppf -> +- fprintf ppf "The method %s@ has type" m) ++ fprintf ppf "The %s %s@ has type" k m) + (function ppf -> + fprintf ppf "but is expected to have type") + | Structure_expected clty -> +@@ -1451,15 +1493,20 @@ + fprintf ppf "The expression \"new %s\" has type" c) + (function ppf -> + fprintf ppf "but is used with type") +- | Virtual_class (cl, mets) -> ++ | Virtual_class (cl, mets, vals) -> + let print_mets ppf mets = + List.iter (function met -> fprintf ppf "@ %s" met) mets in + let cl_mark = if cl then "" else " type" in ++ let missings = ++ match mets, vals with ++ [], _ -> "variables" ++ | _, [] -> "methods" ++ | _ -> "methods and variables" ++ in + fprintf ppf +- "@[This class%s should be virtual@ \ +- @[<2>The following methods are undefined :%a@] +- @]" +- cl_mark print_mets mets ++ "@[This class%s should be virtual.@ \ ++ @[<2>The following %s are undefined :%a@]@]" ++ cl_mark missings print_mets (mets @ vals) + | Parameter_arity_mismatch(lid, expected, provided) -> + fprintf ppf + "@[The class constructor %a@ expects %i type argument(s),@ \ +@@ -1532,3 +1579,10 @@ + fprintf ppf "This object is expected to have type") + (function ppf -> + fprintf ppf "but has actually type") ++ | Mutability_mismatch (lab, mut) -> ++ let mut1, mut2 = ++ if mut = Immutable then "mutable", "immutable" ++ else "immutable", "mutable" in ++ fprintf ppf ++ "@[The instance variable is %s,@ it cannot be redefined as %s@]" ++ mut1 mut2 +Index: typing/typeclass.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typeclass.mli,v +retrieving revision 1.18 +diff -u -r1.18 typeclass.mli +--- typing/typeclass.mli 1 Dec 2003 00:32:11 -0000 1.18 ++++ typing/typeclass.mli 5 Apr 2006 02:26:00 -0000 +@@ -49,7 +49,7 @@ + + type error = + Unconsistent_constraint of (type_expr * type_expr) list +- | Method_type_mismatch of string * (type_expr * type_expr) list ++ | Field_type_mismatch of string * string * (type_expr * type_expr) list + | Structure_expected of class_type + | Cannot_apply of class_type + | Apply_wrong_label of label +@@ -61,7 +61,7 @@ + | Unbound_class_type_2 of Longident.t + | Abbrev_type_clash of type_expr * type_expr * type_expr + | Constructor_type_mismatch of string * (type_expr * type_expr) list +- | Virtual_class of bool * string list ++ | Virtual_class of bool * string list * string list + | Parameter_arity_mismatch of Longident.t * int * int + | Parameter_mismatch of (type_expr * type_expr) list + | Bad_parameters of Ident.t * type_expr * type_expr +@@ -74,6 +74,7 @@ + | Non_collapsable_conjunction of + Ident.t * Types.class_declaration * (type_expr * type_expr) list + | Final_self_clash of (type_expr * type_expr) list ++ | Mutability_mismatch of string * mutable_flag + + exception Error of Location.t * error + +Index: typing/typecore.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typecore.ml,v +retrieving revision 1.178 +diff -u -r1.178 typecore.ml +--- typing/typecore.ml 6 Jan 2006 02:25:37 -0000 1.178 ++++ typing/typecore.ml 5 Apr 2006 02:26:00 -0000 +@@ -611,11 +611,11 @@ + List.for_all + (function + Cf_meth _ -> true +- | Cf_val (_,_,e) -> incr count; is_nonexpansive e ++ | Cf_val (_,_,e,_) -> incr count; is_nonexpansive_opt e + | Cf_init e -> is_nonexpansive e + | Cf_inher _ | Cf_let _ -> false) + fields && +- Vars.fold (fun _ (mut,_) b -> decr count; b && mut = Immutable) ++ Vars.fold (fun _ (mut,_,_) b -> decr count; b && mut = Immutable) + vars true && + !count = 0 + | _ -> false +@@ -1356,7 +1356,7 @@ + (path_self, _) -> + let type_override (lab, snewval) = + begin try +- let (id, _, ty) = Vars.find lab !vars in ++ let (id, _, _, ty) = Vars.find lab !vars in + (Path.Pident id, type_expect env snewval (instance ty)) + with + Not_found -> +Index: typing/typecore.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typecore.mli,v +retrieving revision 1.37 +diff -u -r1.37 typecore.mli +--- typing/typecore.mli 4 Mar 2005 14:51:31 -0000 1.37 ++++ typing/typecore.mli 5 Apr 2006 02:26:00 -0000 +@@ -38,7 +38,8 @@ + string -> type_expr -> Env.t -> Env.t -> Env.t -> Parsetree.pattern -> + Typedtree.pattern * + (Ident.t * type_expr) Meths.t ref * +- (Ident.t * Asttypes.mutable_flag * type_expr) Vars.t ref * ++ (Ident.t * Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) ++ Vars.t ref * + Env.t * Env.t * Env.t + val type_expect: + ?in_function:(Location.t * type_expr) -> +Index: typing/typedtree.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typedtree.ml,v +retrieving revision 1.36 +diff -u -r1.36 typedtree.ml +--- typing/typedtree.ml 25 Nov 2003 09:20:43 -0000 1.36 ++++ typing/typedtree.ml 5 Apr 2006 02:26:00 -0000 +@@ -106,7 +106,7 @@ + + and class_field = + Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list +- | Cf_val of string * Ident.t * expression ++ | Cf_val of string * Ident.t * expression option * bool + | Cf_meth of string * expression + | Cf_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list +@@ -140,7 +140,8 @@ + | Tstr_recmodule of (Ident.t * module_expr) list + | Tstr_modtype of Ident.t * module_type + | Tstr_open of Path.t +- | Tstr_class of (Ident.t * int * string list * class_expr) list ++ | Tstr_class of ++ (Ident.t * int * string list * class_expr * virtual_flag) list + | Tstr_cltype of (Ident.t * cltype_declaration) list + | Tstr_include of module_expr * Ident.t list + +Index: typing/typedtree.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typedtree.mli,v +retrieving revision 1.34 +diff -u -r1.34 typedtree.mli +--- typing/typedtree.mli 25 Nov 2003 09:20:43 -0000 1.34 ++++ typing/typedtree.mli 5 Apr 2006 02:26:00 -0000 +@@ -107,7 +107,8 @@ + and class_field = + Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list + (* Inherited instance variables and concrete methods *) +- | Cf_val of string * Ident.t * expression ++ | Cf_val of string * Ident.t * expression option * bool ++ (* None = virtual, true = override *) + | Cf_meth of string * expression + | Cf_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list +@@ -141,7 +142,8 @@ + | Tstr_recmodule of (Ident.t * module_expr) list + | Tstr_modtype of Ident.t * module_type + | Tstr_open of Path.t +- | Tstr_class of (Ident.t * int * string list * class_expr) list ++ | Tstr_class of ++ (Ident.t * int * string list * class_expr * virtual_flag) list + | Tstr_cltype of (Ident.t * cltype_declaration) list + | Tstr_include of module_expr * Ident.t list + +Index: typing/typemod.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/typemod.ml,v +retrieving revision 1.73 +diff -u -r1.73 typemod.ml +--- typing/typemod.ml 8 Aug 2005 09:41:51 -0000 1.73 ++++ typing/typemod.ml 5 Apr 2006 02:26:00 -0000 +@@ -17,6 +17,7 @@ + open Misc + open Longident + open Path ++open Asttypes + open Parsetree + open Types + open Typedtree +@@ -667,8 +668,9 @@ + let (classes, new_env) = Typeclass.class_declarations env cl in + let (str_rem, sig_rem, final_env) = type_struct new_env srem in + (Tstr_class +- (List.map (fun (i, _,_,_,_,_,_,_, s, m, c) -> +- (i, s, m, c)) classes) :: ++ (List.map (fun (i, d, _,_,_,_,_,_, s, m, c) -> ++ let vf = if d.cty_new = None then Virtual else Concrete in ++ (i, s, m, c, vf)) classes) :: + Tstr_cltype + (List.map (fun (_,_, i, d, _,_,_,_,_,_,_) -> (i, d)) classes) :: + Tstr_type +Index: typing/types.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.ml,v +retrieving revision 1.25 +diff -u -r1.25 types.ml +--- typing/types.ml 9 Dec 2004 12:40:53 -0000 1.25 ++++ typing/types.ml 5 Apr 2006 02:26:00 -0000 +@@ -90,7 +90,8 @@ + | Val_prim of Primitive.description (* Primitive *) + | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *) + | Val_self of (Ident.t * type_expr) Meths.t ref * +- (Ident.t * Asttypes.mutable_flag * type_expr) Vars.t ref * ++ (Ident.t * Asttypes.mutable_flag * ++ Asttypes.virtual_flag * type_expr) Vars.t ref * + string * type_expr + (* Self *) + | Val_anc of (string * Ident.t) list * string +@@ -156,7 +157,8 @@ + + and class_signature = + { cty_self: type_expr; +- cty_vars: (Asttypes.mutable_flag * type_expr) Vars.t; ++ cty_vars: ++ (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; + cty_concr: Concr.t; + cty_inher: (Path.t * type_expr list) list } + +Index: typing/types.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/types.mli,v +retrieving revision 1.25 +diff -u -r1.25 types.mli +--- typing/types.mli 9 Dec 2004 12:40:53 -0000 1.25 ++++ typing/types.mli 5 Apr 2006 02:26:00 -0000 +@@ -91,7 +91,8 @@ + | Val_prim of Primitive.description (* Primitive *) + | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *) + | Val_self of (Ident.t * type_expr) Meths.t ref * +- (Ident.t * Asttypes.mutable_flag * type_expr) Vars.t ref * ++ (Ident.t * Asttypes.mutable_flag * ++ Asttypes.virtual_flag * type_expr) Vars.t ref * + string * type_expr + (* Self *) + | Val_anc of (string * Ident.t) list * string +@@ -158,7 +159,8 @@ + + and class_signature = + { cty_self: type_expr; +- cty_vars: (Asttypes.mutable_flag * type_expr) Vars.t; ++ cty_vars: ++ (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; + cty_concr: Concr.t; + cty_inher: (Path.t * type_expr list) list } + +Index: typing/unused_var.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/typing/unused_var.ml,v +retrieving revision 1.5 +diff -u -r1.5 unused_var.ml +--- typing/unused_var.ml 4 Jan 2006 16:55:50 -0000 1.5 ++++ typing/unused_var.ml 5 Apr 2006 02:26:00 -0000 +@@ -245,7 +245,7 @@ + match cf with + | Pcf_inher (ce, _) -> class_expr ppf tbl ce; + | Pcf_val (_, _, e, _) -> expression ppf tbl e; +- | Pcf_virt _ -> () ++ | Pcf_virt _ | Pcf_valvirt _ -> () + | Pcf_meth (_, _, e, _) -> expression ppf tbl e; + | Pcf_cstr _ -> () + | Pcf_let (recflag, pel, _) -> let_pel ppf tbl recflag pel None; +Index: bytecomp/translclass.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translclass.ml,v +retrieving revision 1.38 +diff -u -r1.38 translclass.ml +--- bytecomp/translclass.ml 13 Aug 2005 20:59:37 -0000 1.38 ++++ bytecomp/translclass.ml 5 Apr 2006 02:26:00 -0000 +@@ -133,10 +133,10 @@ + (fun _ -> lambda_unit) cl + in + (inh_init, lsequence obj_init' obj_init, true) +- | Cf_val (_, id, exp) -> ++ | Cf_val (_, id, Some exp, _) -> + (inh_init, lsequence (set_inst_var obj id exp) obj_init, + has_init) +- | Cf_meth _ -> ++ | Cf_meth _ | Cf_val _ -> + (inh_init, obj_init, has_init) + | Cf_init _ -> + (inh_init, obj_init, true) +@@ -213,27 +213,17 @@ + if len < 2 && nvals = 0 then Meths.fold (bind_method tbl) meths cl_init else + if len = 0 && nvals < 2 then transl_vals tbl true vals cl_init else + let ids = Ident.create "ids" in +- let i = ref len in +- let getter, names, cl_init = +- match vals with [] -> "get_method_labels", [], cl_init +- | (_,id0)::vals' -> +- incr i; +- let i = ref (List.length vals) in +- "new_methods_variables", +- [transl_meth_list (List.map fst vals)], +- Llet(Strict, id0, lfield ids 0, +- List.fold_right +- (fun (name,id) rem -> +- decr i; +- Llet(Alias, id, Lprim(Poffsetint !i, [Lvar id0]), rem)) +- vals' cl_init) ++ let i = ref (len + nvals) in ++ let getter, names = ++ if nvals = 0 then "get_method_labels", [] else ++ "new_methods_variables", [transl_meth_list (List.map fst vals)] + in + Llet(StrictOpt, ids, + Lapply (oo_prim getter, + [Lvar tbl; transl_meth_list (List.map fst methl)] @ names), + List.fold_right + (fun (lab,id) lam -> decr i; Llet(StrictOpt, id, lfield ids !i, lam)) +- methl cl_init) ++ (methl @ vals) cl_init) + + let output_methods tbl methods lam = + match methods with +@@ -283,8 +273,9 @@ + (vals, meths_super cla str.cl_meths meths) + inh_init cl_init msubst top cl in + (inh_init, cl_init, [], values) +- | Cf_val (name, id, exp) -> +- (inh_init, cl_init, methods, (name, id)::values) ++ | Cf_val (name, id, exp, over) -> ++ let values = if over then values else (name, id) :: values in ++ (inh_init, cl_init, methods, values) + | Cf_meth (name, exp) -> + let met_code = msubst true (transl_exp exp) in + let met_code = +@@ -342,27 +333,24 @@ + assert (Path.same path path'); + let lpath = transl_path path in + let inh = Ident.create "inh" +- and inh_vals = Ident.create "vals" +- and inh_meths = Ident.create "meths" ++ and ofs = List.length vals + 1 + and valids, methids = super in + let cl_init = + List.fold_left + (fun init (nm, id, _) -> +- Llet(StrictOpt, id, lfield inh_meths (index nm concr_meths), ++ Llet(StrictOpt, id, lfield inh (index nm concr_meths + ofs), + init)) + cl_init methids in + let cl_init = + List.fold_left + (fun init (nm, id) -> +- Llet(StrictOpt, id, lfield inh_vals (index nm vals), init)) ++ Llet(StrictOpt, id, lfield inh (index nm vals + 1), init)) + cl_init valids in + (inh_init, + Llet (Strict, inh, + Lapply(oo_prim "inherits", narrow_args @ + [lpath; Lconst(Const_pointer(if top then 1 else 0))]), +- Llet(StrictOpt, obj_init, lfield inh 0, +- Llet(Alias, inh_vals, lfield inh 1, +- Llet(Alias, inh_meths, lfield inh 2, cl_init))))) ++ Llet(StrictOpt, obj_init, lfield inh 0, cl_init))) + | _ -> + let core cl_init = + build_class_init cla true super inh_init cl_init msubst top cl +@@ -397,12 +385,16 @@ + XXX Il devrait etre peu couteux d'ecrire des classes : + class c x y = d e f + *) +-let rec transl_class_rebind obj_init cl = ++let rec transl_class_rebind obj_init cl vf = + match cl.cl_desc with + Tclass_ident path -> ++ if vf = Concrete then begin ++ try if (Env.find_class path cl.cl_env).cty_new = None then raise Exit ++ with Not_found -> raise Exit ++ end; + (path, obj_init) + | Tclass_fun (pat, _, cl, partial) -> +- let path, obj_init = transl_class_rebind obj_init cl in ++ let path, obj_init = transl_class_rebind obj_init cl vf in + let build params rem = + let param = name_pattern "param" [pat, ()] in + Lfunction (Curried, param::params, +@@ -414,14 +406,14 @@ + Lfunction (Curried, params, rem) -> build params rem + | rem -> build [] rem) + | Tclass_apply (cl, oexprs) -> +- let path, obj_init = transl_class_rebind obj_init cl in ++ let path, obj_init = transl_class_rebind obj_init cl vf in + (path, transl_apply obj_init oexprs) + | Tclass_let (rec_flag, defs, vals, cl) -> +- let path, obj_init = transl_class_rebind obj_init cl in ++ let path, obj_init = transl_class_rebind obj_init cl vf in + (path, Translcore.transl_let rec_flag defs obj_init) + | Tclass_structure _ -> raise Exit + | Tclass_constraint (cl', _, _, _) -> +- let path, obj_init = transl_class_rebind obj_init cl' in ++ let path, obj_init = transl_class_rebind obj_init cl' vf in + let rec check_constraint = function + Tcty_constr(path', _, _) when Path.same path path' -> () + | Tcty_fun (_, _, cty) -> check_constraint cty +@@ -430,21 +422,21 @@ + check_constraint cl.cl_type; + (path, obj_init) + +-let rec transl_class_rebind_0 self obj_init cl = ++let rec transl_class_rebind_0 self obj_init cl vf = + match cl.cl_desc with + Tclass_let (rec_flag, defs, vals, cl) -> +- let path, obj_init = transl_class_rebind_0 self obj_init cl in ++ let path, obj_init = transl_class_rebind_0 self obj_init cl vf in + (path, Translcore.transl_let rec_flag defs obj_init) + | _ -> +- let path, obj_init = transl_class_rebind obj_init cl in ++ let path, obj_init = transl_class_rebind obj_init cl vf in + (path, lfunction [self] obj_init) + +-let transl_class_rebind ids cl = ++let transl_class_rebind ids cl vf = + try + let obj_init = Ident.create "obj_init" + and self = Ident.create "self" in + let obj_init0 = lapply (Lvar obj_init) [Lvar self] in +- let path, obj_init' = transl_class_rebind_0 self obj_init0 cl in ++ let path, obj_init' = transl_class_rebind_0 self obj_init0 cl vf in + if not (Translcore.check_recursive_lambda ids obj_init') then + raise(Error(cl.cl_loc, Illegal_class_expr)); + let id = (obj_init' = lfunction [self] obj_init0) in +@@ -592,9 +584,9 @@ + *) + + +-let transl_class ids cl_id arity pub_meths cl = ++let transl_class ids cl_id arity pub_meths cl vflag = + (* First check if it is not only a rebind *) +- let rebind = transl_class_rebind ids cl in ++ let rebind = transl_class_rebind ids cl vflag in + if rebind <> lambda_unit then rebind else + + (* Prepare for heavy environment handling *) +@@ -696,9 +688,7 @@ + (* Simplest case: an object defined at toplevel (ids=[]) *) + if top && ids = [] then llets (ltable cla (ldirect obj_init)) else + +- let concrete = +- ids = [] || +- Typeclass.virtual_methods (Ctype.signature_of_class_type cl.cl_type) = [] ++ let concrete = (vflag = Concrete) + and lclass lam = + let cl_init = llets (Lfunction(Curried, [cla], cl_init)) in + Llet(Strict, class_init, cl_init, lam (free_variables cl_init)) +@@ -800,11 +790,11 @@ + + (* Wrapper for class compilation *) + +-let transl_class ids cl_id arity pub_meths cl = +- oo_wrap cl.cl_env false (transl_class ids cl_id arity pub_meths) cl ++let transl_class ids cl_id arity pub_meths cl vf = ++ oo_wrap cl.cl_env false (transl_class ids cl_id arity pub_meths cl) vf + + let () = +- transl_object := (fun id meths cl -> transl_class [] id 0 meths cl) ++ transl_object := (fun id meths cl -> transl_class [] id 0 meths cl Concrete) + + (* Error report *) + +Index: bytecomp/translclass.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translclass.mli,v +retrieving revision 1.11 +diff -u -r1.11 translclass.mli +--- bytecomp/translclass.mli 12 Aug 2004 12:55:11 -0000 1.11 ++++ bytecomp/translclass.mli 5 Apr 2006 02:26:00 -0000 +@@ -16,7 +16,8 @@ + open Lambda + + val transl_class : +- Ident.t list -> Ident.t -> int -> string list -> class_expr -> lambda;; ++ Ident.t list -> Ident.t -> ++ int -> string list -> class_expr -> Asttypes.virtual_flag -> lambda;; + + type error = Illegal_class_expr | Tags of string * string + +Index: bytecomp/translmod.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/bytecomp/translmod.ml,v +retrieving revision 1.51 +diff -u -r1.51 translmod.ml +--- bytecomp/translmod.ml 12 Aug 2004 12:55:11 -0000 1.51 ++++ bytecomp/translmod.ml 5 Apr 2006 02:26:00 -0000 +@@ -317,10 +317,10 @@ + | Tstr_open path :: rem -> + transl_structure fields cc rootpath rem + | Tstr_class cl_list :: rem -> +- let ids = List.map (fun (i, _, _, _) -> i) cl_list in ++ let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + Lletrec(List.map +- (fun (id, arity, meths, cl) -> +- (id, transl_class ids id arity meths cl)) ++ (fun (id, arity, meths, cl, vf) -> ++ (id, transl_class ids id arity meths cl vf)) + cl_list, + transl_structure (List.rev ids @ fields) cc rootpath rem) + | Tstr_cltype cl_list :: rem -> +@@ -414,11 +414,11 @@ + | Tstr_open path :: rem -> + transl_store subst rem + | Tstr_class cl_list :: rem -> +- let ids = List.map (fun (i, _, _, _) -> i) cl_list in ++ let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + let lam = + Lletrec(List.map +- (fun (id, arity, meths, cl) -> +- (id, transl_class ids id arity meths cl)) ++ (fun (id, arity, meths, cl, vf) -> ++ (id, transl_class ids id arity meths cl vf)) + cl_list, + store_idents ids) in + Lsequence(subst_lambda subst lam, +@@ -485,7 +485,7 @@ + | Tstr_modtype(id, decl) :: rem -> defined_idents rem + | Tstr_open path :: rem -> defined_idents rem + | Tstr_class cl_list :: rem -> +- List.map (fun (i, _, _, _) -> i) cl_list @ defined_idents rem ++ List.map (fun (i, _, _, _, _) -> i) cl_list @ defined_idents rem + | Tstr_cltype cl_list :: rem -> defined_idents rem + | Tstr_include(modl, ids) :: rem -> ids @ defined_idents rem + +@@ -603,14 +603,14 @@ + | Tstr_class cl_list -> + (* we need to use unique names for the classes because there might + be a value named identically *) +- let ids = List.map (fun (i, _, _, _) -> i) cl_list in ++ let ids = List.map (fun (i, _, _, _, _) -> i) cl_list in + List.iter set_toplevel_unique_name ids; + Lletrec(List.map +- (fun (id, arity, meths, cl) -> +- (id, transl_class ids id arity meths cl)) ++ (fun (id, arity, meths, cl, vf) -> ++ (id, transl_class ids id arity meths cl vf)) + cl_list, + make_sequence +- (fun (id, _, _, _) -> toploop_setvalue_id id) ++ (fun (id, _, _, _, _) -> toploop_setvalue_id id) + cl_list) + | Tstr_cltype cl_list -> + lambda_unit +Index: driver/main_args.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/driver/main_args.ml,v +retrieving revision 1.48 +diff -u -r1.48 main_args.ml +--- driver/main_args.ml 4 Jan 2006 16:55:49 -0000 1.48 ++++ driver/main_args.ml 5 Apr 2006 02:26:00 -0000 +@@ -136,11 +136,11 @@ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ +- \032 M/m enable/disable overriden method\n\ ++ \032 M/m enable/disable overriden methods\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ +- \032 V/v enable/disable hidden instance variable\n\ ++ \032 V/v enable/disable overriden instance variables\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ +Index: driver/optmain.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/driver/optmain.ml,v +retrieving revision 1.87 +diff -u -r1.87 optmain.ml +--- driver/optmain.ml 4 Jan 2006 16:55:49 -0000 1.87 ++++ driver/optmain.ml 5 Apr 2006 02:26:00 -0000 +@@ -173,7 +173,7 @@ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ +- \032 V/v enable/disable hidden instance variables\n\ ++ \032 V/v enable/disable overriden instance variables\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ +Index: stdlib/camlinternalOO.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/stdlib/camlinternalOO.ml,v +retrieving revision 1.14 +diff -u -r1.14 camlinternalOO.ml +--- stdlib/camlinternalOO.ml 25 Oct 2005 18:34:07 -0000 1.14 ++++ stdlib/camlinternalOO.ml 5 Apr 2006 02:26:00 -0000 +@@ -206,7 +206,11 @@ + (table.methods_by_name, table.methods_by_label, table.hidden_meths, + table.vars, virt_meth_labs, vars) + :: table.previous_states; +- table.vars <- Vars.empty; ++ table.vars <- ++ Vars.fold ++ (fun lab info tvars -> ++ if List.mem lab vars then Vars.add lab info tvars else tvars) ++ table.vars Vars.empty; + let by_name = ref Meths.empty in + let by_label = ref Labs.empty in + List.iter2 +@@ -255,9 +259,11 @@ + index + + let new_variable table name = +- let index = new_slot table in +- table.vars <- Vars.add name index table.vars; +- index ++ try Vars.find name table.vars ++ with Not_found -> ++ let index = new_slot table in ++ table.vars <- Vars.add name index table.vars; ++ index + + let to_array arr = + if arr = Obj.magic 0 then [||] else arr +@@ -265,16 +271,17 @@ + let new_methods_variables table meths vals = + let meths = to_array meths in + let nmeths = Array.length meths and nvals = Array.length vals in +- let index = new_variable table vals.(0) in +- let res = Array.create (nmeths + 1) index in +- for i = 1 to nvals - 1 do ignore (new_variable table vals.(i)) done; ++ let res = Array.create (nmeths + nvals) 0 in + for i = 0 to nmeths - 1 do +- res.(i+1) <- get_method_label table meths.(i) ++ res.(i) <- get_method_label table meths.(i) ++ done; ++ for i = 0 to nvals - 1 do ++ res.(i+nmeths) <- new_variable table vals.(i) + done; + res + + let get_variable table name = +- Vars.find name table.vars ++ try Vars.find name table.vars with Not_found -> assert false + + let get_variables table names = + Array.map (get_variable table) names +@@ -315,9 +322,12 @@ + let init = + if top then super cla env else Obj.repr (super cla) in + widen cla; +- (init, Array.map (get_variable cla) (to_array vals), +- Array.map (fun nm -> get_method cla (get_method_label cla nm)) +- (to_array concr_meths)) ++ Array.concat ++ [[| repr init |]; ++ magic (Array.map (get_variable cla) (to_array vals) : int array); ++ Array.map ++ (fun nm -> repr (get_method cla (get_method_label cla nm) : closure)) ++ (to_array concr_meths) ] + + let make_class pub_meths class_init = + let table = create_table pub_meths in +Index: stdlib/camlinternalOO.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/stdlib/camlinternalOO.mli,v +retrieving revision 1.9 +diff -u -r1.9 camlinternalOO.mli +--- stdlib/camlinternalOO.mli 25 Oct 2005 18:34:07 -0000 1.9 ++++ stdlib/camlinternalOO.mli 5 Apr 2006 02:26:00 -0000 +@@ -46,8 +46,7 @@ + val init_class : table -> unit + val inherits : + table -> string array -> string array -> string array -> +- (t * (table -> obj -> Obj.t) * t * obj) -> bool -> +- (Obj.t * int array * closure array) ++ (t * (table -> obj -> Obj.t) * t * obj) -> bool -> Obj.t array + val make_class : + string array -> (table -> Obj.t -> t) -> + (t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t) +@@ -79,6 +78,7 @@ + + (** {6 Builtins to reduce code size} *) + ++(* + val get_const : t -> closure + val get_var : int -> closure + val get_env : int -> int -> closure +@@ -103,6 +103,7 @@ + val send_var : tag -> int -> int -> closure + val send_env : tag -> int -> int -> int -> closure + val send_meth : tag -> label -> int -> closure ++*) + + type impl = + GetConst +Index: stdlib/sys.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/stdlib/sys.ml,v +retrieving revision 1.142 +diff -u -r1.142 sys.ml +--- stdlib/sys.ml 22 Mar 2006 12:39:39 -0000 1.142 ++++ stdlib/sys.ml 5 Apr 2006 02:26:00 -0000 +@@ -78,4 +78,4 @@ + + (* OCaml version string, must be in the format described in sys.mli. *) + +-let ocaml_version = "3.10+dev4 (2006-03-22)";; ++let ocaml_version = "3.10+dev5 (2006-04-05)";; +Index: tools/depend.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/tools/depend.ml,v +retrieving revision 1.9 +diff -u -r1.9 depend.ml +--- tools/depend.ml 23 Mar 2005 03:08:37 -0000 1.9 ++++ tools/depend.ml 5 Apr 2006 02:26:00 -0000 +@@ -87,7 +87,7 @@ + + and add_class_type_field bv = function + Pctf_inher cty -> add_class_type bv cty +- | Pctf_val(_, _, oty, _) -> add_opt add_type bv oty ++ | Pctf_val(_, _, _, ty, _) -> add_type bv ty + | Pctf_virt(_, _, ty, _) -> add_type bv ty + | Pctf_meth(_, _, ty, _) -> add_type bv ty + | Pctf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 +@@ -280,6 +280,7 @@ + and add_class_field bv = function + Pcf_inher(ce, _) -> add_class_expr bv ce + | Pcf_val(_, _, e, _) -> add_expr bv e ++ | Pcf_valvirt(_, _, ty, _) + | Pcf_virt(_, _, ty, _) -> add_type bv ty + | Pcf_meth(_, _, e, _) -> add_expr bv e + | Pcf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 +Index: tools/ocamlprof.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/tools/ocamlprof.ml,v +retrieving revision 1.38 +diff -u -r1.38 ocamlprof.ml +--- tools/ocamlprof.ml 24 Mar 2005 17:20:54 -0000 1.38 ++++ tools/ocamlprof.ml 5 Apr 2006 02:26:00 -0000 +@@ -328,7 +328,7 @@ + rewrite_patexp_list iflag spat_sexp_list + | Pcf_init sexp -> + rewrite_exp iflag sexp +- | Pcf_virt _ | Pcf_cstr _ -> () ++ | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> () + + and rewrite_class_expr iflag cexpr = + match cexpr.pcl_desc with +Index: otherlibs/labltk/browser/searchpos.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/otherlibs/labltk/browser/searchpos.ml,v +retrieving revision 1.48 +diff -u -r1.48 searchpos.ml +--- otherlibs/labltk/browser/searchpos.ml 23 Mar 2005 03:08:37 -0000 1.48 ++++ otherlibs/labltk/browser/searchpos.ml 5 Apr 2006 02:26:01 -0000 +@@ -141,9 +141,8 @@ + List.iter cfl ~f: + begin function + Pctf_inher cty -> search_pos_class_type cty ~pos ~env +- | Pctf_val (_, _, Some ty, loc) -> ++ | Pctf_val (_, _, _, ty, loc) -> + if in_loc loc ~pos then search_pos_type ty ~pos ~env +- | Pctf_val _ -> () + | Pctf_virt (_, _, ty, loc) -> + if in_loc loc ~pos then search_pos_type ty ~pos ~env + | Pctf_meth (_, _, ty, loc) -> +@@ -675,7 +674,7 @@ + | Tstr_modtype _ -> () + | Tstr_open _ -> () + | Tstr_class l -> +- List.iter l ~f:(fun (id, _, _, cl) -> search_pos_class_expr cl ~pos) ++ List.iter l ~f:(fun (id, _, _, cl, _) -> search_pos_class_expr cl ~pos) + | Tstr_cltype _ -> () + | Tstr_include (m, _) -> search_pos_module_expr m ~pos + end +@@ -685,7 +684,8 @@ + begin function + Cf_inher (cl, _, _) -> + search_pos_class_expr cl ~pos +- | Cf_val (_, _, exp) -> search_pos_expr exp ~pos ++ | Cf_val (_, _, Some exp, _) -> search_pos_expr exp ~pos ++ | Cf_val _ -> () + | Cf_meth (_, exp) -> search_pos_expr exp ~pos + | Cf_let (_, pel, iel) -> + List.iter pel ~f: +Index: ocamldoc/Makefile +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/ocamldoc/Makefile,v +retrieving revision 1.61 +diff -u -r1.61 Makefile +--- ocamldoc/Makefile 4 Jan 2006 16:55:49 -0000 1.61 ++++ ocamldoc/Makefile 5 Apr 2006 02:26:01 -0000 +@@ -31,7 +31,7 @@ + MKDIR=mkdir -p + CP=cp -f + OCAMLDOC=ocamldoc +-OCAMLDOC_RUN=sh ./runocamldoc $(SUPPORTS_SHARED_LIBRARIES) ++OCAMLDOC_RUN=./ocamldoc.opt #sh ./runocamldoc $(SUPPORTS_SHARED_LIBRARIES) + OCAMLDOC_OPT=$(OCAMLDOC).opt + OCAMLDOC_LIBCMA=odoc_info.cma + OCAMLDOC_LIBCMI=odoc_info.cmi +@@ -188,12 +188,12 @@ + ../otherlibs/num/num.mli + + all: exe lib +- $(MAKE) manpages + + exe: $(OCAMLDOC) + lib: $(OCAMLDOC_LIBCMA) $(OCAMLDOC_LIBCMI) $(ODOC_TEST) + + opt.opt: exeopt libopt ++ $(MAKE) manpages + exeopt: $(OCAMLDOC_OPT) + libopt: $(OCAMLDOC_LIBCMXA) $(OCAMLDOC_LIBCMI) + debug: +Index: ocamldoc/odoc_ast.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/ocamldoc/odoc_ast.ml,v +retrieving revision 1.27 +diff -u -r1.27 odoc_ast.ml +--- ocamldoc/odoc_ast.ml 4 Jan 2006 16:55:49 -0000 1.27 ++++ ocamldoc/odoc_ast.ml 5 Apr 2006 02:26:01 -0000 +@@ -88,7 +88,7 @@ + ident_type_decl_list + | Typedtree.Tstr_class info_list -> + List.iter +- (fun ((id,_,_,_) as ci) -> ++ (fun ((id,_,_,_,_) as ci) -> + Hashtbl.add table (C (Name.from_ident id)) + (Typedtree.Tstr_class [ci])) + info_list +@@ -146,7 +146,7 @@ + + let search_class_exp table name = + match Hashtbl.find table (C name) with +- | (Typedtree.Tstr_class [(_,_,_,ce)]) -> ++ | (Typedtree.Tstr_class [(_,_,_,ce,_)]) -> + ( + try + let type_decl = search_type_declaration table name in +@@ -184,7 +184,7 @@ + let rec iter = function + | [] -> + raise Not_found +- | Typedtree.Cf_val (_, ident, exp) :: q ++ | Typedtree.Cf_val (_, ident, Some exp, _) :: q + when Name.from_ident ident = name -> + exp.Typedtree.exp_type + | _ :: q -> +@@ -523,7 +523,8 @@ + p_clexp.Parsetree.pcl_loc.Location.loc_end.Lexing.pos_cnum + q + +- | (Parsetree.Pcf_val (label, mutable_flag, expression, loc)) :: q -> ++ | (Parsetree.Pcf_val (label, mutable_flag, _, loc) | ++ Parsetree.Pcf_valvirt (label, mutable_flag, _, loc)) :: q -> + let complete_name = Name.concat current_class_name label in + let (info_opt, ele_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let type_exp = +Index: ocamldoc/odoc_sig.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/ocamldoc/odoc_sig.ml,v +retrieving revision 1.37 +diff -u -r1.37 odoc_sig.ml +--- ocamldoc/odoc_sig.ml 4 Jan 2006 16:55:50 -0000 1.37 ++++ ocamldoc/odoc_sig.ml 5 Apr 2006 02:26:01 -0000 +@@ -107,7 +107,7 @@ + | _ -> assert false + + let search_attribute_type name class_sig = +- let (_, type_expr) = Types.Vars.find name class_sig.Types.cty_vars in ++ let (_, _, type_expr) = Types.Vars.find name class_sig.Types.cty_vars in + type_expr + + let search_method_type name class_sig = +@@ -269,7 +269,7 @@ + [] -> pos_limit + | ele2 :: _ -> + match ele2 with +- Parsetree.Pctf_val (_, _, _, loc) ++ Parsetree.Pctf_val (_, _, _, _, loc) + | Parsetree.Pctf_virt (_, _, _, loc) + | Parsetree.Pctf_meth (_, _, _, loc) + | Parsetree.Pctf_cstr (_, _, loc) -> loc.Location.loc_start.Lexing.pos_cnum +@@ -330,7 +330,7 @@ + in + ([], ele_comments) + +- | Parsetree.Pctf_val (name, mutable_flag, _, loc) :: q -> ++ | Parsetree.Pctf_val (name, mutable_flag, _, _, loc) :: q -> + (* of (string * mutable_flag * core_type option * Location.t)*) + let (comment_opt, eles_comments) = get_comments_in_class last_pos loc.Location.loc_start.Lexing.pos_cnum in + let complete_name = Name.concat current_class_name name in +Index: camlp4/camlp4/ast2pt.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/camlp4/ast2pt.ml,v +retrieving revision 1.36 +diff -u -r1.36 ast2pt.ml +--- camlp4/camlp4/ast2pt.ml 29 Jun 2005 04:11:26 -0000 1.36 ++++ camlp4/camlp4/ast2pt.ml 5 Apr 2006 02:26:01 -0000 +@@ -244,6 +244,7 @@ + ; + value mkmutable m = if m then Mutable else Immutable; + value mkprivate m = if m then Private else Public; ++value mkvirtual m = if m then Virtual else Concrete; + value mktrecord (loc, n, m, t) = + (n, mkmutable m, ctyp (mkpolytype t), mkloc loc); + value mkvariant (loc, c, tl) = (c, List.map ctyp tl, mkloc loc); +@@ -862,8 +863,8 @@ + | CgInh loc ct -> [Pctf_inher (class_type ct) :: l] + | CgMth loc s pf t -> + [Pctf_meth (s, mkprivate pf, ctyp (mkpolytype t), mkloc loc) :: l] +- | CgVal loc s b t -> +- [Pctf_val (s, mkmutable b, Some (ctyp t), mkloc loc) :: l] ++ | CgVal loc s b v t -> ++ [Pctf_val (s, mkmutable b, mkvirtual v, ctyp t, mkloc loc) :: l] + | CgVir loc s b t -> + [Pctf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l] ] + and class_expr = +@@ -907,7 +908,9 @@ + [Pcf_meth (s, mkprivate b, e, mkloc loc) :: l] + | CrVal loc s b e -> [Pcf_val (s, mkmutable b, expr e, mkloc loc) :: l] + | CrVir loc s b t -> +- [Pcf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l] ] ++ [Pcf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l] ++ | CrVvr loc s b t -> ++ [Pcf_valvirt (s, mkmutable b, ctyp t, mkloc loc) :: l] ] + ; + + value interf ast = List.fold_right sig_item ast []; +Index: camlp4/camlp4/mLast.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/camlp4/mLast.mli,v +retrieving revision 1.18 +diff -u -r1.18 mLast.mli +--- camlp4/camlp4/mLast.mli 29 Jun 2005 04:11:26 -0000 1.18 ++++ camlp4/camlp4/mLast.mli 5 Apr 2006 02:26:01 -0000 +@@ -180,7 +180,7 @@ + | CgDcl of loc and list class_sig_item + | CgInh of loc and class_type + | CgMth of loc and string and bool and ctyp +- | CgVal of loc and string and bool and ctyp ++ | CgVal of loc and string and bool and bool and ctyp + | CgVir of loc and string and bool and ctyp ] + and class_expr = + [ CeApp of loc and class_expr and expr +@@ -196,7 +196,8 @@ + | CrIni of loc and expr + | CrMth of loc and string and bool and expr and option ctyp + | CrVal of loc and string and bool and expr +- | CrVir of loc and string and bool and ctyp ] ++ | CrVir of loc and string and bool and ctyp ++ | CrVvr of loc and string and bool and ctyp ] + ; + + external loc_of_ctyp : ctyp -> loc = "%field0"; +Index: camlp4/camlp4/reloc.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/camlp4/reloc.ml,v +retrieving revision 1.18 +diff -u -r1.18 reloc.ml +--- camlp4/camlp4/reloc.ml 29 Jun 2005 04:11:26 -0000 1.18 ++++ camlp4/camlp4/reloc.ml 5 Apr 2006 02:26:01 -0000 +@@ -350,7 +350,7 @@ + | CgDcl loc x1 -> let nloc = floc loc in CgDcl nloc (List.map (class_sig_item floc sh) x1) + | CgInh loc x1 -> let nloc = floc loc in CgInh nloc (class_type floc sh x1) + | CgMth loc x1 x2 x3 -> let nloc = floc loc in CgMth nloc x1 x2 (ctyp floc sh x3) +- | CgVal loc x1 x2 x3 -> let nloc = floc loc in CgVal nloc x1 x2 (ctyp floc sh x3) ++ | CgVal loc x1 x2 x3 x4 -> let nloc = floc loc in CgVal nloc x1 x2 x3 (ctyp floc sh x4) + | CgVir loc x1 x2 x3 -> let nloc = floc loc in CgVir nloc x1 x2 (ctyp floc sh x3) ] + and class_expr floc sh = + self where rec self = +@@ -377,5 +377,6 @@ + | CrMth loc x1 x2 x3 x4 -> + let nloc = floc loc in CrMth nloc x1 x2 (expr floc sh x3) (option_map (ctyp floc sh) x4) + | CrVal loc x1 x2 x3 -> let nloc = floc loc in CrVal nloc x1 x2 (expr floc sh x3) +- | CrVir loc x1 x2 x3 -> let nloc = floc loc in CrVir nloc x1 x2 (ctyp floc sh x3) ] ++ | CrVir loc x1 x2 x3 -> let nloc = floc loc in CrVir nloc x1 x2 (ctyp floc sh x3) ++ | CrVvr loc x1 x2 x3 -> let nloc = floc loc in CrVvr nloc x1 x2 (ctyp floc sh x3) ] + ; +Index: camlp4/etc/pa_o.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/etc/pa_o.ml,v +retrieving revision 1.66 +diff -u -r1.66 pa_o.ml +--- camlp4/etc/pa_o.ml 29 Jun 2005 04:11:26 -0000 1.66 ++++ camlp4/etc/pa_o.ml 5 Apr 2006 02:26:01 -0000 +@@ -1037,8 +1037,14 @@ + class_str_item: + [ [ "inherit"; ce = class_expr; pb = OPT [ "as"; i = LIDENT -> i ] -> + <:class_str_item< inherit $ce$ $opt:pb$ >> +- | "val"; mf = OPT "mutable"; lab = label; e = cvalue_binding -> +- <:class_str_item< value $opt:o2b mf$ $lab$ = $e$ >> ++ | "val"; "mutable"; lab = label; e = cvalue_binding -> ++ <:class_str_item< value mutable $lab$ = $e$ >> ++ | "val"; lab = label; e = cvalue_binding -> ++ <:class_str_item< value $lab$ = $e$ >> ++ | "val"; "mutable"; "virtual"; lab = label; ":"; t = ctyp -> ++ <:class_str_item< value virtual mutable $lab$ : $t$ >> ++ | "val"; "virtual"; mf = OPT "mutable"; lab = label; ":"; t = ctyp -> ++ <:class_str_item< value virtual $opt:o2b mf$ $lab$ : $t$ >> + | "method"; "private"; "virtual"; l = label; ":"; t = poly_type -> + <:class_str_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; "private"; l = label; ":"; t = poly_type -> +@@ -1087,8 +1093,9 @@ + ; + class_sig_item: + [ [ "inherit"; cs = class_signature -> <:class_sig_item< inherit $cs$ >> +- | "val"; mf = OPT "mutable"; l = label; ":"; t = ctyp -> +- <:class_sig_item< value $opt:o2b mf$ $l$ : $t$ >> ++ | "val"; mf = OPT "mutable"; vf = OPT "virtual"; ++ l = label; ":"; t = ctyp -> ++ <:class_sig_item< value $opt:o2b mf$ $opt:o2b vf$ $l$ : $t$ >> + | "method"; "private"; "virtual"; l = label; ":"; t = poly_type -> + <:class_sig_item< method virtual private $l$ : $t$ >> + | "method"; "virtual"; "private"; l = label; ":"; t = poly_type -> +Index: camlp4/etc/pr_o.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/etc/pr_o.ml,v +retrieving revision 1.51 +diff -u -r1.51 pr_o.ml +--- camlp4/etc/pr_o.ml 5 Jan 2006 10:44:29 -0000 1.51 ++++ camlp4/etc/pr_o.ml 5 Apr 2006 02:26:01 -0000 +@@ -1768,10 +1768,11 @@ + [: `S LR "method"; private_flag pf; `label lab; + `S LR ":" :]; + `ctyp t "" k :] +- | MLast.CgVal _ lab mf t -> ++ | MLast.CgVal _ lab mf vf t -> + fun curr next dg k -> + [: `HVbox +- [: `S LR "val"; mutable_flag mf; `label lab; `S LR ":" :]; ++ [: `S LR "val"; mutable_flag mf; virtual_flag vf; ++ `label lab; `S LR ":" :]; + `ctyp t "" k :] + | MLast.CgVir _ lab pf t -> + fun curr next dg k -> +Index: camlp4/meta/pa_r.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/meta/pa_r.ml,v +retrieving revision 1.64 +diff -u -r1.64 pa_r.ml +--- camlp4/meta/pa_r.ml 29 Jun 2005 04:11:26 -0000 1.64 ++++ camlp4/meta/pa_r.ml 5 Apr 2006 02:26:01 -0000 +@@ -658,7 +658,9 @@ + | "inherit"; ce = class_expr; pb = OPT as_lident -> + <:class_str_item< inherit $ce$ $opt:pb$ >> + | "value"; mf = OPT "mutable"; lab = label; e = cvalue_binding -> +- <:class_str_item< value $opt:o2b mf$ $lab$ = $e$ >> ++ <:class_str_item< value $opt:o2b mf$ $lab$ = $e$ >> ++ | "value"; "virtual"; mf = OPT "mutable"; l = label; ":"; t = ctyp -> ++ <:class_str_item< value virtual $opt:o2b mf$ $l$ : $t$ >> + | "method"; "virtual"; pf = OPT "private"; l = label; ":"; t = ctyp -> + <:class_str_item< method virtual $opt:o2b pf$ $l$ : $t$ >> + | "method"; pf = OPT "private"; l = label; topt = OPT polyt; +@@ -701,8 +703,9 @@ + [ [ "declare"; st = LIST0 [ s = class_sig_item; ";" -> s ]; "end" -> + <:class_sig_item< declare $list:st$ end >> + | "inherit"; cs = class_type -> <:class_sig_item< inherit $cs$ >> +- | "value"; mf = OPT "mutable"; l = label; ":"; t = ctyp -> +- <:class_sig_item< value $opt:o2b mf$ $l$ : $t$ >> ++ | "value"; mf = OPT "mutable"; vf = OPT "virtual"; ++ l = label; ":"; t = ctyp -> ++ <:class_sig_item< value $opt:o2b mf$ $opt:o2b vf$ $l$ : $t$ >> + | "method"; "virtual"; pf = OPT "private"; l = label; ":"; t = ctyp -> + <:class_sig_item< method virtual $opt:o2b pf$ $l$ : $t$ >> + | "method"; pf = OPT "private"; l = label; ":"; t = ctyp -> +Index: camlp4/meta/q_MLast.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/meta/q_MLast.ml,v +retrieving revision 1.60 +diff -u -r1.60 q_MLast.ml +--- camlp4/meta/q_MLast.ml 29 Jun 2005 04:11:26 -0000 1.60 ++++ camlp4/meta/q_MLast.ml 5 Apr 2006 02:26:01 -0000 +@@ -947,6 +947,8 @@ + Qast.Node "CrDcl" [Qast.Loc; st] + | "inherit"; ce = class_expr; pb = SOPT as_lident -> + Qast.Node "CrInh" [Qast.Loc; ce; pb] ++ | "value"; "virtual"; mf = SOPT "mutable"; l = label; ":"; t = ctyp -> ++ Qast.Node "CrVvr" [Qast.Loc; l; o2b mf; t] + | "value"; mf = SOPT "mutable"; lab = label; e = cvalue_binding -> + Qast.Node "CrVal" [Qast.Loc; lab; o2b mf; e] + | "method"; "virtual"; pf = SOPT "private"; l = label; ":"; t = ctyp -> +@@ -992,8 +994,9 @@ + [ [ "declare"; st = SLIST0 [ s = class_sig_item; ";" -> s ]; "end" -> + Qast.Node "CgDcl" [Qast.Loc; st] + | "inherit"; cs = class_type -> Qast.Node "CgInh" [Qast.Loc; cs] +- | "value"; mf = SOPT "mutable"; l = label; ":"; t = ctyp -> +- Qast.Node "CgVal" [Qast.Loc; l; o2b mf; t] ++ | "value"; mf = SOPT "mutable"; vf = SOPT "virtual"; ++ l = label; ":"; t = ctyp -> ++ Qast.Node "CgVal" [Qast.Loc; l; o2b mf; o2b vf; t] + | "method"; "virtual"; pf = SOPT "private"; l = label; ":"; t = ctyp -> + Qast.Node "CgVir" [Qast.Loc; l; o2b pf; t] + | "method"; pf = SOPT "private"; l = label; ":"; t = ctyp -> +Index: camlp4/ocaml_src/camlp4/ast2pt.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/ocaml_src/camlp4/ast2pt.ml,v +retrieving revision 1.36 +diff -u -r1.36 ast2pt.ml +--- camlp4/ocaml_src/camlp4/ast2pt.ml 29 Jun 2005 04:11:26 -0000 1.36 ++++ camlp4/ocaml_src/camlp4/ast2pt.ml 5 Apr 2006 02:26:01 -0000 +@@ -227,6 +227,7 @@ + ;; + let mkmutable m = if m then Mutable else Immutable;; + let mkprivate m = if m then Private else Public;; ++let mkvirtual m = if m then Virtual else Concrete;; + let mktrecord (loc, n, m, t) = + n, mkmutable m, ctyp (mkpolytype t), mkloc loc + ;; +@@ -878,8 +879,8 @@ + | CgInh (loc, ct) -> Pctf_inher (class_type ct) :: l + | CgMth (loc, s, pf, t) -> + Pctf_meth (s, mkprivate pf, ctyp (mkpolytype t), mkloc loc) :: l +- | CgVal (loc, s, b, t) -> +- Pctf_val (s, mkmutable b, Some (ctyp t), mkloc loc) :: l ++ | CgVal (loc, s, b, v, t) -> ++ Pctf_val (s, mkmutable b, mkvirtual v, ctyp t, mkloc loc) :: l + | CgVir (loc, s, b, t) -> + Pctf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l + and class_expr = +@@ -923,6 +924,8 @@ + | CrVal (loc, s, b, e) -> Pcf_val (s, mkmutable b, expr e, mkloc loc) :: l + | CrVir (loc, s, b, t) -> + Pcf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l ++ | CrVvr (loc, s, b, t) -> ++ Pcf_valvirt (s, mkmutable b, ctyp t, mkloc loc) :: l + ;; + + let interf ast = List.fold_right sig_item ast [];; +Index: camlp4/ocaml_src/camlp4/mLast.mli +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/ocaml_src/camlp4/mLast.mli,v +retrieving revision 1.20 +diff -u -r1.20 mLast.mli +--- camlp4/ocaml_src/camlp4/mLast.mli 29 Jun 2005 04:11:26 -0000 1.20 ++++ camlp4/ocaml_src/camlp4/mLast.mli 5 Apr 2006 02:26:01 -0000 +@@ -180,7 +180,7 @@ + | CgDcl of loc * class_sig_item list + | CgInh of loc * class_type + | CgMth of loc * string * bool * ctyp +- | CgVal of loc * string * bool * ctyp ++ | CgVal of loc * string * bool * bool * ctyp + | CgVir of loc * string * bool * ctyp + and class_expr = + CeApp of loc * class_expr * expr +@@ -197,6 +197,7 @@ + | CrMth of loc * string * bool * expr * ctyp option + | CrVal of loc * string * bool * expr + | CrVir of loc * string * bool * ctyp ++ | CrVvr of loc * string * bool * ctyp + ;; + + external loc_of_ctyp : ctyp -> loc = "%field0";; +Index: camlp4/ocaml_src/camlp4/reloc.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/ocaml_src/camlp4/reloc.ml,v +retrieving revision 1.20 +diff -u -r1.20 reloc.ml +--- camlp4/ocaml_src/camlp4/reloc.ml 29 Jun 2005 04:11:26 -0000 1.20 ++++ camlp4/ocaml_src/camlp4/reloc.ml 5 Apr 2006 02:26:01 -0000 +@@ -430,8 +430,8 @@ + let nloc = floc loc in CgInh (nloc, class_type floc sh x1) + | CgMth (loc, x1, x2, x3) -> + let nloc = floc loc in CgMth (nloc, x1, x2, ctyp floc sh x3) +- | CgVal (loc, x1, x2, x3) -> +- let nloc = floc loc in CgVal (nloc, x1, x2, ctyp floc sh x3) ++ | CgVal (loc, x1, x2, x3, x4) -> ++ let nloc = floc loc in CgVal (nloc, x1, x2, x3, ctyp floc sh x4) + | CgVir (loc, x1, x2, x3) -> + let nloc = floc loc in CgVir (nloc, x1, x2, ctyp floc sh x3) + in +@@ -478,6 +478,8 @@ + let nloc = floc loc in CrVal (nloc, x1, x2, expr floc sh x3) + | CrVir (loc, x1, x2, x3) -> + let nloc = floc loc in CrVir (nloc, x1, x2, ctyp floc sh x3) ++ | CrVvr (loc, x1, x2, x3) -> ++ let nloc = floc loc in CrVvr (nloc, x1, x2, ctyp floc sh x3) + in + self + ;; +Index: camlp4/ocaml_src/meta/pa_r.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/ocaml_src/meta/pa_r.ml,v +retrieving revision 1.59 +diff -u -r1.59 pa_r.ml +--- camlp4/ocaml_src/meta/pa_r.ml 29 Jun 2005 04:11:26 -0000 1.59 ++++ camlp4/ocaml_src/meta/pa_r.ml 5 Apr 2006 02:26:01 -0000 +@@ -2161,6 +2161,15 @@ + (fun (t : 'ctyp) _ (l : 'label) (pf : string option) _ _ + (_loc : Lexing.position * Lexing.position) -> + (MLast.CrVir (_loc, l, o2b pf, t) : 'class_str_item)); ++ [Gramext.Stoken ("", "value"); Gramext.Stoken ("", "virtual"); ++ Gramext.Sopt (Gramext.Stoken ("", "mutable")); ++ Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); ++ Gramext.Stoken ("", ":"); ++ Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e))], ++ Gramext.action ++ (fun (t : 'ctyp) _ (l : 'label) (mf : string option) _ _ ++ (_loc : Lexing.position * Lexing.position) -> ++ (MLast.CrVvr (_loc, l, o2b mf, t) : 'class_str_item)); + [Gramext.Stoken ("", "value"); + Gramext.Sopt (Gramext.Stoken ("", "mutable")); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); +@@ -2338,13 +2347,15 @@ + (MLast.CgVir (_loc, l, o2b pf, t) : 'class_sig_item)); + [Gramext.Stoken ("", "value"); + Gramext.Sopt (Gramext.Stoken ("", "mutable")); ++ Gramext.Sopt (Gramext.Stoken ("", "virtual")); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e))], + Gramext.action +- (fun (t : 'ctyp) _ (l : 'label) (mf : string option) _ ++ (fun (t : 'ctyp) _ (l : 'label) (vf : string option) ++ (mf : string option) _ + (_loc : Lexing.position * Lexing.position) -> +- (MLast.CgVal (_loc, l, o2b mf, t) : 'class_sig_item)); ++ (MLast.CgVal (_loc, l, o2b mf, o2b vf, t) : 'class_sig_item)); + [Gramext.Stoken ("", "inherit"); + Gramext.Snterm + (Grammar.Entry.obj (class_type : 'class_type Grammar.Entry.e))], +Index: camlp4/ocaml_src/meta/q_MLast.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/ocaml_src/meta/q_MLast.ml,v +retrieving revision 1.65 +diff -u -r1.65 q_MLast.ml +--- camlp4/ocaml_src/meta/q_MLast.ml 12 Jan 2006 08:54:21 -0000 1.65 ++++ camlp4/ocaml_src/meta/q_MLast.ml 5 Apr 2006 02:26:01 -0000 +@@ -3152,9 +3152,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__17))])], ++ (Qast.Str x : 'e__18))])], + Gramext.action +- (fun (a : 'e__17 option) ++ (fun (a : 'e__18 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3191,9 +3191,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__16))])], ++ (Qast.Str x : 'e__17))])], + Gramext.action +- (fun (a : 'e__16 option) ++ (fun (a : 'e__17 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3216,9 +3216,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__15))])], ++ (Qast.Str x : 'e__16))])], + Gramext.action +- (fun (a : 'e__15 option) ++ (fun (a : 'e__16 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3235,6 +3235,31 @@ + (_loc : Lexing.position * Lexing.position) -> + (Qast.Node ("CrVal", [Qast.Loc; lab; o2b mf; e]) : + 'class_str_item)); ++ [Gramext.Stoken ("", "value"); Gramext.Stoken ("", "virtual"); ++ Gramext.srules ++ [[Gramext.Sopt ++ (Gramext.srules ++ [[Gramext.Stoken ("", "mutable")], ++ Gramext.action ++ (fun (x : string) ++ (_loc : Lexing.position * Lexing.position) -> ++ (Qast.Str x : 'e__15))])], ++ Gramext.action ++ (fun (a : 'e__15 option) ++ (_loc : Lexing.position * Lexing.position) -> ++ (Qast.Option a : 'a_opt)); ++ [Gramext.Snterm ++ (Grammar.Entry.obj (a_opt : 'a_opt Grammar.Entry.e))], ++ Gramext.action ++ (fun (a : 'a_opt) (_loc : Lexing.position * Lexing.position) -> ++ (a : 'a_opt))]; ++ Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); ++ Gramext.Stoken ("", ":"); ++ Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e))], ++ Gramext.action ++ (fun (t : 'ctyp) _ (l : 'label) (mf : 'a_opt) _ _ ++ (_loc : Lexing.position * Lexing.position) -> ++ (Qast.Node ("CrVvr", [Qast.Loc; l; o2b mf; t]) : 'class_str_item)); + [Gramext.Stoken ("", "inherit"); + Gramext.Snterm + (Grammar.Entry.obj (class_expr : 'class_expr Grammar.Entry.e)); +@@ -3366,9 +3391,9 @@ + Gramext.action + (fun _ (csf : 'class_sig_item) + (_loc : Lexing.position * Lexing.position) -> +- (csf : 'e__18))])], ++ (csf : 'e__19))])], + Gramext.action +- (fun (a : 'e__18 list) ++ (fun (a : 'e__19 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -3446,9 +3471,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__22))])], ++ (Qast.Str x : 'e__24))])], + Gramext.action +- (fun (a : 'e__22 option) ++ (fun (a : 'e__24 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3471,9 +3496,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__21))])], ++ (Qast.Str x : 'e__23))])], + Gramext.action +- (fun (a : 'e__21 option) ++ (fun (a : 'e__23 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3496,9 +3521,26 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__20))])], ++ (Qast.Str x : 'e__21))])], + Gramext.action +- (fun (a : 'e__20 option) ++ (fun (a : 'e__21 option) ++ (_loc : Lexing.position * Lexing.position) -> ++ (Qast.Option a : 'a_opt)); ++ [Gramext.Snterm ++ (Grammar.Entry.obj (a_opt : 'a_opt Grammar.Entry.e))], ++ Gramext.action ++ (fun (a : 'a_opt) (_loc : Lexing.position * Lexing.position) -> ++ (a : 'a_opt))]; ++ Gramext.srules ++ [[Gramext.Sopt ++ (Gramext.srules ++ [[Gramext.Stoken ("", "virtual")], ++ Gramext.action ++ (fun (x : string) ++ (_loc : Lexing.position * Lexing.position) -> ++ (Qast.Str x : 'e__22))])], ++ Gramext.action ++ (fun (a : 'e__22 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3510,9 +3552,10 @@ + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e))], + Gramext.action +- (fun (t : 'ctyp) _ (l : 'label) (mf : 'a_opt) _ ++ (fun (t : 'ctyp) _ (l : 'label) (vf : 'a_opt) (mf : 'a_opt) _ + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Node ("CgVal", [Qast.Loc; l; o2b mf; t]) : 'class_sig_item)); ++ (Qast.Node ("CgVal", [Qast.Loc; l; o2b mf; o2b vf; t]) : ++ 'class_sig_item)); + [Gramext.Stoken ("", "inherit"); + Gramext.Snterm + (Grammar.Entry.obj (class_type : 'class_type Grammar.Entry.e))], +@@ -3531,9 +3574,9 @@ + Gramext.action + (fun _ (s : 'class_sig_item) + (_loc : Lexing.position * Lexing.position) -> +- (s : 'e__19))])], ++ (s : 'e__20))])], + Gramext.action +- (fun (a : 'e__19 list) ++ (fun (a : 'e__20 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -3556,9 +3599,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__23))])], ++ (Qast.Str x : 'e__25))])], + Gramext.action +- (fun (a : 'e__23 option) ++ (fun (a : 'e__25 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3593,9 +3636,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__24))])], ++ (Qast.Str x : 'e__26))])], + Gramext.action +- (fun (a : 'e__24 option) ++ (fun (a : 'e__26 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3713,9 +3756,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__25))])], ++ (Qast.Str x : 'e__27))])], + Gramext.action +- (fun (a : 'e__25 option) ++ (fun (a : 'e__27 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -3922,9 +3965,9 @@ + Gramext.action + (fun (x : string) + (_loc : Lexing.position * Lexing.position) -> +- (Qast.Str x : 'e__26))])], ++ (Qast.Str x : 'e__28))])], + Gramext.action +- (fun (a : 'e__26 option) ++ (fun (a : 'e__28 option) + (_loc : Lexing.position * Lexing.position) -> + (Qast.Option a : 'a_opt)); + [Gramext.Snterm +@@ -4390,9 +4433,9 @@ + Gramext.action + (fun _ (e : 'expr) + (_loc : Lexing.position * Lexing.position) -> +- (e : 'e__29))])], ++ (e : 'e__31))])], + Gramext.action +- (fun (a : 'e__29 list) ++ (fun (a : 'e__31 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -4425,9 +4468,9 @@ + Gramext.action + (fun _ (e : 'expr) + (_loc : Lexing.position * Lexing.position) -> +- (e : 'e__28))])], ++ (e : 'e__30))])], + Gramext.action +- (fun (a : 'e__28 list) ++ (fun (a : 'e__30 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -4454,9 +4497,9 @@ + Gramext.action + (fun _ (e : 'expr) + (_loc : Lexing.position * Lexing.position) -> +- (e : 'e__27))])], ++ (e : 'e__29))])], + Gramext.action +- (fun (a : 'e__27 list) ++ (fun (a : 'e__29 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -4547,9 +4590,9 @@ + Gramext.action + (fun _ (cf : 'class_str_item) + (_loc : Lexing.position * Lexing.position) -> +- (cf : 'e__30))])], ++ (cf : 'e__32))])], + Gramext.action +- (fun (a : 'e__30 list) ++ (fun (a : 'e__32 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -4592,9 +4635,9 @@ + Gramext.action + (fun _ (csf : 'class_sig_item) + (_loc : Lexing.position * Lexing.position) -> +- (csf : 'e__32))])], ++ (csf : 'e__34))])], + Gramext.action +- (fun (a : 'e__32 list) ++ (fun (a : 'e__34 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +@@ -4623,9 +4666,9 @@ + Gramext.action + (fun _ (csf : 'class_sig_item) + (_loc : Lexing.position * Lexing.position) -> +- (csf : 'e__31))])], ++ (csf : 'e__33))])], + Gramext.action +- (fun (a : 'e__31 list) ++ (fun (a : 'e__33 list) + (_loc : Lexing.position * Lexing.position) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm +Index: camlp4/top/rprint.ml +=================================================================== +RCS file: /net/yquem/devel/caml/repository/csl/camlp4/top/rprint.ml,v +retrieving revision 1.18 +diff -u -r1.18 rprint.ml +--- camlp4/top/rprint.ml 29 Jun 2005 04:11:26 -0000 1.18 ++++ camlp4/top/rprint.ml 5 Apr 2006 02:26:01 -0000 +@@ -288,8 +288,9 @@ + fprintf ppf "@[<2>method %s%s%s :@ %a;@]" + (if priv then "private " else "") (if virt then "virtual " else "") + name Toploop.print_out_type.val ty +- | Ocsg_value name mut ty -> +- fprintf ppf "@[<2>value %s%s :@ %a;@]" (if mut then "mutable " else "") ++ | Ocsg_value name mut virt ty -> ++ fprintf ppf "@[<2>value %s%s%s :@ %a;@]" ++ (if mut then "mutable " else "") (if virt then "virtual " else "") + name Toploop.print_out_type.val ty ] + ; + diff --git a/testlabl/varunion.ml b/testlabl/varunion.ml new file mode 100644 index 0000000..30a410f --- /dev/null +++ b/testlabl/varunion.ml @@ -0,0 +1,435 @@ +(* cvs update -r varunion parsing typing bytecomp toplevel *) + +type t = private [> ];; +type u = private [> ] ~ [t];; +type v = [t | u];; +let f x = (x : t :> v);; + +(* bad *) +module Mix(X: sig type t = private [> ] end) + (Y: sig type t = private [> ] end) = + struct type t = [X.t | Y.t] end;; + +(* bad *) +module Mix(X: sig type t = private [> `A of int ] end) + (Y: sig type t = private [> `A of bool] ~ [X.t] end) = + struct type t = [X.t | Y.t] end;; + +(* ok *) +module Mix(X: sig type t = private [> `A of int ] end) + (Y: sig type t = private [> `A of int] ~ [X.t] end) = + struct type t = [X.t | Y.t] end;; + +(* bad *) +module Mix(X: sig type t = private [> `A of int ] end) + (Y: sig type t = private [> `B of bool] ~ [X.t] end) = + struct type t = [X.t | Y.t] end;; + +type 'a t = private [> `L of 'a] ~ [`L];; + +(* ok *) +module Mix(X: sig type t = private [> `A of int ] ~ [`B] end) + (Y: sig type t = private [> `B of bool] ~ [X.t] end) = + struct type t = [X.t | Y.t] let is_t = function #t -> true | _ -> false end;; + +module Mix(X: sig type t = private [> `A of int ] ~ [`B] end) + (Y: sig type t = private [> `B of bool] ~ [X.t] end) = + struct + type t = [X.t | Y.t] + let which = function #X.t -> `X | #Y.t -> `Y + end;; + +module Mix(I: sig type t = private [> ] ~ [`A;`B] end) + (X: sig type t = private [> I.t | `A of int ] ~ [`B] end) + (Y: sig type t = private [> I.t | `B of bool] ~ [X.t] end) = + struct + type t = [X.t | Y.t] + let which = function #X.t -> `X | #Y.t -> `Y + end;; + +(* ok *) +module M = + Mix(struct type t = [`C of char] end) + (struct type t = [`A of int | `C of char] end) + (struct type t = [`B of bool | `C of char] end);; + +(* bad *) +module M = + Mix(struct type t = [`B of bool] end) + (struct type t = [`A of int | `B of bool] end) + (struct type t = [`B of bool | `C of char] end);; + +(* ok *) +module M1 = struct type t = [`A of int | `C of char] end +module M2 = struct type t = [`B of bool | `C of char] end +module I = struct type t = [`C of char] end +module M = Mix(I)(M1)(M2) ;; + +let c = (`C 'c' : M.t) ;; + +module M(X : sig type t = private [> `A] end) = + struct let f (#X.t as x) = x end;; + +(* code generation *) +type t = private [> `A ] ~ [`B];; +match `B with #t -> 1 | `B -> 2;; + +module M : sig type t = private [> `A of int | `B] ~ [`C] end = + struct type t = [`A of int | `B | `D of bool] end;; +let f = function (`C | #M.t) -> 1+1 ;; +let f = function (`A _ | `B #M.t) -> 1+1 ;; + +(* expression *) +module Mix(X:sig type t = private [> ] val show: t -> string end) + (Y:sig type t = private [> ] ~ [X.t] val show: t -> string end) = + struct + type t = [X.t | Y.t] + let show : t -> string = function + #X.t as x -> X.show x + | #Y.t as y -> Y.show y + end;; + +module EStr = struct + type t = [`Str of string] + let show (`Str s) = s +end +module EInt = struct + type t = [`Int of int] + let show (`Int i) = string_of_int i +end +module M = Mix(EStr)(EInt);; + +module type T = sig type t = private [> ] val show: t -> string end +module Mix(X:T)(Y:T with type t = private [> ] ~ [X.t]) : + T with type t = [X.t | Y.t] = + struct + type t = [X.t | Y.t] + let show = function + #X.t as x -> X.show x + | #Y.t as y -> Y.show y + end;; +module M = Mix(EStr)(EInt);; + +(* deep *) +module M : sig type t = private [> `A] end = struct type t = [`A] end +module M' : sig type t = private [> ] end = struct type t = [M.t | `A] end;; + +(* bad *) +type t = private [> ] +type u = private [> `A of int] ~ [t] ;; + +(* ok *) +type t = private [> `A of int] +type u = private [> `A of int] ~ [t] ;; + +module F(X: sig + type t = private [> ] ~ [`A;`B;`C;`D] + type u = private [> `A|`B|`C] ~ [t; `D] +end) : sig type v = private [< X.t | X.u | `D] end = struct + open X + let f = function #u -> 1 | #t -> 2 | `D -> 3 + let g = function #u|#t|`D -> 2 + type v = [t|u|`D] +end + +(* ok *) +module M = struct type t = private [> `A] end;; +module M' : sig type t = private [> ] ~ [`A] end = M;; + +(* ok *) +module type T = sig type t = private [> ] ~ [`A] end;; +module type T' = T with type t = private [> `A];; + +(* ok *) +type t = private [> ] ~ [`A] +let f = function `A x -> x | #t -> 0 +type t' = private [< `A of int | t];; + +(* should be ok *) +module F(X:sig end) : + sig type t = private [> ] type u = private [> ] ~ [t] end = + struct type t = [ `A] type u = [`B] end +module M = F(String) +let f = function #M.t -> 1 | #M.u -> 2 +let f = function #M.t -> 1 | _ -> 2 +type t = [M.t | M.u] +let f = function #t -> 1 | _ -> 2;; +module G(X : sig type t = private [> ] type u = private [> ] ~ [t] end) = + struct let f = function #X.t -> 1 | _ -> 2 end;; +module M1 = G(struct module N = F(String) type t = N.t type u = N.u end) ;; +module M1 = G(struct type t = M.t type u = M.u end) ;; +(* bad *) +let f = function #F(String).t -> 1 | _ -> 2;; +type t = [F(String).t | M.u] +let f = function #t -> 1 | _ -> 2;; +module N : sig type t = private [> ] end = + struct type t = [F(String).t | M.u] end;; + +(* compatibility improvement *) +type a = [`A of int | `B] +type b = [`A of bool | `B] +type c = private [> ] ~ [a;b] +let f = function #c -> 1 | `A x -> truncate x +type d = private [> ] ~ [a] +let g = function #d -> 1 | `A x -> truncate x;; + + +(* Expression Problem: functorial form *) + +type num = [ `Num of int ] + +module type Exp = sig + type t = private [> num] + val eval : t -> t + val show : t -> string +end + +module Num(X : Exp) = struct + type t = num + let eval (`Num _ as x) : X.t = x + let show (`Num n) = string_of_int n +end + +type 'a add = [ `Add of 'a * 'a ] + +module Add(X : Exp with type t = private [> num | 'a add] as 'a) = struct + type t = X.t add + let show (`Add(e1, e2) : t) = "("^ X.show e1 ^"+"^ X.show e2 ^")" + let eval (`Add(e1, e2) : t) = + let e1 = X.eval e1 and e2 = X.eval e2 in + match e1, e2 with + `Num n1, `Num n2 -> `Num (n1+n2) + | `Num 0, e | e, `Num 0 -> e + | e12 -> `Add e12 +end + +type 'a mul = [`Mul of 'a * 'a] + +module Mul(X : Exp with type t = private [> num | 'a mul] as 'a) = struct + type t = X.t mul + let show (`Mul(e1, e2) : t) = "("^ X.show e1 ^"*"^ X.show e2 ^")" + let eval (`Mul(e1, e2) : t) = + let e1 = X.eval e1 and e2 = X.eval e2 in + match e1, e2 with + `Num n1, `Num n2 -> `Num (n1*n2) + | `Num 0, e | e, `Num 0 -> `Num 0 + | `Num 1, e | e, `Num 1 -> e + | e12 -> `Mul e12 +end + +module Ext(X : sig type t = private [> ] end)(Y : sig type t end) = struct + module type S = + sig + type t = private [> ] ~ [ X.t ] + val eval : t -> Y.t + val show : t -> string + end +end + +module Dummy = struct type t = [`Dummy] end + +module Mix(E : Exp)(E1 : Ext(Dummy)(E).S)(E2 : Ext(E1)(E).S) = + struct + type t = [E1.t | E2.t] + let eval = function + #E1.t as x -> E1.eval x + | #E2.t as x -> E2.eval x + let show = function + #E1.t as x -> E1.show x + | #E2.t as x -> E2.show x + end + +module rec EAdd : (Exp with type t = [num | EAdd.t add]) = + Mix(EAdd)(Num(EAdd))(Add(EAdd)) + +(* A bit heavy: one must pass E to everybody *) +module rec E : Exp with type t = [num | E.t add | E.t mul] = + Mix(E)(Mix(E)(Num(E))(Add(E)))(Mul(E)) + +let e = E.eval (`Add(`Mul(`Num 2,`Num 3),`Num 1)) + +(* Alternatives *) +(* Direct approach, no need of Mix *) +module rec E : (Exp with type t = [num | E.t add | E.t mul]) = + struct + module E1 = Num(E) + module E2 = Add(E) + module E3 = Mul(E) + type t = E.t + let show = function + | #num as x -> E1.show x + | #add as x -> E2.show x + | #mul as x -> E3.show x + let eval = function + | #num as x -> E1.eval x + | #add as x -> E2.eval x + | #mul as x -> E3.eval x + end + +(* Do functor applications in Mix *) +module type T = sig type t = private [> ] end +module type Tnum = sig type t = private [> num] end + +module Ext(E : Tnum) = struct + module type S = functor (Y : Exp with type t = E.t) -> + sig + type t = private [> num] + val eval : t -> Y.t + val show : t -> string + end +end + +module Ext'(E : Tnum)(X : T) = struct + module type S = functor (Y : Exp with type t = E.t) -> + sig + type t = private [> ] ~ [ X.t ] + val eval : t -> Y.t + val show : t -> string + end +end + +module Mix(E : Exp)(F1 : Ext(E).S)(F2 : Ext'(E)(F1(E)).S) = + struct + module E1 = F1(E) + module E2 = F2(E) + type t = [E1.t | E2.t] + let eval = function + #E1.t as x -> E1.eval x + | #E2.t as x -> E2.eval x + let show = function + #E1.t as x -> E1.show x + | #E2.t as x -> E2.show x + end + +module Join(E : Exp)(F1 : Ext(E).S)(F2 : Ext'(E)(F1(E)).S) + (E' : Exp with type t = E.t) = + Mix(E)(F1)(F2) + +module rec EAdd : (Exp with type t = [num | EAdd.t add]) = + Mix(EAdd)(Num)(Add) + +module rec EMul : (Exp with type t = [num | EMul.t mul]) = + Mix(EMul)(Num)(Mul) + +module rec E : (Exp with type t = [num | E.t add | E.t mul]) = + Mix(E)(Join(E)(Num)(Add))(Mul) + +(* Linear extension by the end: not so nice *) +module LExt(X : T) = struct + module type S = + sig + type t + val eval : t -> X.t + val show : t -> string + end +end +module LNum(E: Exp)(X : LExt(E).S with type t = private [> ] ~ [num]) = + struct + type t = [num | X.t] + let show = function + `Num n -> string_of_int n + | #X.t as x -> X.show x + let eval = function + #num as x -> x + | #X.t as x -> X.eval x + end +module LAdd(E : Exp with type t = private [> num | 'a add] as 'a) + (X : LExt(E).S with type t = private [> ] ~ [add]) = + struct + type t = [E.t add | X.t] + let show = function + `Add(e1,e2) -> "("^ E.show e1 ^"+"^ E.show e2 ^")" + | #X.t as x -> X.show x + let eval = function + `Add(e1,e2) -> + let e1 = E.eval e1 and e2 = E.eval e2 in + begin match e1, e2 with + `Num n1, `Num n2 -> `Num (n1+n2) + | `Num 0, e | e, `Num 0 -> e + | e12 -> `Add e12 + end + | #X.t as x -> X.eval x + end +module LEnd = struct + type t = [`Dummy] + let show `Dummy = "" + let eval `Dummy = `Dummy +end +module rec L : Exp with type t = [num | L.t add | `Dummy] = + LAdd(L)(LNum(L)(LEnd)) + +(* Back to first form, but add map *) + +module Num(X : Exp) = struct + type t = num + let map f x = x + let eval1 (`Num _ as x) : X.t = x + let show (`Num n) = string_of_int n +end + +module Add(X : Exp with type t = private [> num | 'a add] as 'a) = struct + type t = X.t add + let show (`Add(e1, e2) : t) = "("^ X.show e1 ^"+"^ X.show e2 ^")" + let map f (`Add(e1, e2) : t) = `Add(f e1, f e2) + let eval1 (`Add(e1, e2) as e : t) = + match e1, e2 with + `Num n1, `Num n2 -> `Num (n1+n2) + | `Num 0, e | e, `Num 0 -> e + | _ -> e +end + +module Mul(X : Exp with type t = private [> num | 'a mul] as 'a) = struct + type t = X.t mul + let show (`Mul(e1, e2) : t) = "("^ X.show e1 ^"*"^ X.show e2 ^")" + let map f (`Mul(e1, e2) : t) = `Mul(f e1, f e2) + let eval1 (`Mul(e1, e2) as e : t) = + match e1, e2 with + `Num n1, `Num n2 -> `Num (n1*n2) + | `Num 0, e | e, `Num 0 -> `Num 0 + | `Num 1, e | e, `Num 1 -> e + | _ -> e +end + +module Ext(X : sig type t = private [> ] end)(Y : sig type t end) = struct + module type S = + sig + type t = private [> ] ~ [ X.t ] + val map : (Y.t -> Y.t) -> t -> t + val eval1 : t -> Y.t + val show : t -> string + end +end + +module Mix(E : Exp)(E1 : Ext(Dummy)(E).S)(E2 : Ext(E1)(E).S) = + struct + type t = [E1.t | E2.t] + let map f = function + #E1.t as x -> (E1.map f x : E1.t :> t) + | #E2.t as x -> (E2.map f x : E2.t :> t) + let eval1 = function + #E1.t as x -> E1.eval1 x + | #E2.t as x -> E2.eval1 x + let show = function + #E1.t as x -> E1.show x + | #E2.t as x -> E2.show x + end + +module type ET = sig + type t + val map : (t -> t) -> t -> t + val eval1 : t -> t + val show : t -> string +end + +module Fin(E : ET) = struct + include E + let rec eval e = eval1 (map eval e) +end + +module rec EAdd : (Exp with type t = [num | EAdd.t add]) = + Fin(Mix(EAdd)(Num(EAdd))(Add(EAdd))) + +module rec E : Exp with type t = [num | E.t add | E.t mul] = + Fin(Mix(E)(Mix(E)(Num(E))(Add(E)))(Mul(E))) + +let e = E.eval (`Add(`Mul(`Num 2,`Num 3),`Num 1)) diff --git a/testobjects/.cvsignore b/testobjects/.cvsignore new file mode 100644 index 0000000..9c92a72 --- /dev/null +++ b/testobjects/.cvsignore @@ -0,0 +1 @@ +*.proc diff --git a/testobjects/Exemples.exp b/testobjects/Exemples.exp new file mode 100644 index 0000000..5d55e08 --- /dev/null +++ b/testobjects/Exemples.exp @@ -0,0 +1,301 @@ +# class point (int) = + val mutable x : int + method get_x : int + method move : int -> unit +end +# val p : point = <obj> +# - : int = 7 +# - : unit = () +# - : int = 10 +# val q : point = <obj> +# - : int * int = 10, 17 +# class color_point (int) (string) = + val c : string + val mutable x : int + method color : string + method get_x : int + method move : int -> unit +end +# val p' : color_point = <obj> +# - : int * string = 5, "red" +# val l : point list = [<obj>; <obj>] +# val get_x : < get_x : 'a; .. > -> 'a = <fun> +# val set_x : < set_x : 'a; .. > -> 'a = <fun> +# - : int list = [10; 5] +# Characters 6-86: +The type variable 'a is not bound in implicit type definition + ref = < get : 'a; set : 'a -> unit > +It should be captured by a class type parameter +# class ref (int) = + val mutable x : int + method get : int + method set : int -> unit +end +# class 'a ref ('a) = + val mutable x : 'a + method get : 'a + method set : 'a -> unit +end +# - : int = 2 +# class 'a circle ('a) = + constraint 'a = < move : int -> unit; .. > + val mutable center : 'a + method center : 'a + method move : int -> unit + method set_center : 'a -> unit +end +# class 'a circle ('a) = + constraint 'a = #point + val mutable center : 'a + method center : 'a + method move : int -> unit + method set_center : 'a -> unit +end +# val c : point circle = <obj> +val c' : color_point circle = <obj> +# class 'a color_circle ('a) = + constraint 'a = #color_point + val mutable center : 'a + method center : 'a + method color : string + method move : int -> unit + method set_center : 'a -> unit +end +# Characters 28-29: +This expression has type point = < get_x : int; move : int -> unit > +but is here used with type + #color_point = < get_x : int; move : int -> unit; color : string; .. > +# val c'' : color_point color_circle = <obj> +# - : color_point circle = <obj> +# Characters 1-4: +This expression cannot be coerced to type + point circle = + < center : point; set_center : point -> unit; move : int -> unit >; +it has type + color_point color_circle = + < center : color_point; set_center : color_point -> unit; + move : int -> unit; color : string > +but is here used with type + < center : color_point; set_center : point -> unit; move : int -> unit; + color : string > +Type color_point = < get_x : int; move : int -> unit; color : string > +is not compatible with type point = < get_x : int; move : int -> unit > +# Characters 9-55: +Type + color_point color_circle = + < center : color_point; set_center : color_point -> unit; + move : int -> unit; color : string > +is not a subtype of type + point circle = + < center : point; set_center : point -> unit; move : int -> unit > +Type color_point -> unit is not a subtype of type point -> unit +Type point = < get_x : int; move : int -> unit > is not a subtype of type + color_point = < get_x : int; move : int -> unit; color : string > +# class printable_point (int) = + val mutable x : int + method get_x : int + method move : int -> unit + method print : unit +end +# val p : printable_point = <obj> +# 7- : unit = () +# class printable_color_point (int) (string) = + val c : string + val mutable x : int + method color : string + method get_x : int + method move : int -> unit + method print : unit +end +# val p' : printable_color_point = <obj> +# (7, red)- : unit = () +# class functional_point (int) : 'a = + val x : int + method get_x : int + method move : int -> 'a +end +# val p : functional_point = <obj> +# - : int = 7 +# - : int = 10 +# - : int = 7 +# - : (< get_x : int; move : int -> 'a; .. > as 'a) -> functional_point = <fun> +# class virtual 'a lst (unit) = + virtual hd : 'a + method iter : ('a -> unit) -> unit + method map : ('a -> 'a) -> 'a lst + virtual null : bool + method print : ('a -> unit) -> unit + virtual tl : 'a lst +end +class 'a nil (unit) = + method hd : 'a + method iter : ('a -> unit) -> unit + method map : ('a -> 'a) -> 'a lst + method null : bool + method print : ('a -> unit) -> unit + method tl : 'a lst +end +class 'a cons ('a) ('a lst) = + val h : 'a + val t : 'a lst + method hd : 'a + method iter : ('a -> unit) -> unit + method map : ('a -> 'a) -> 'a lst + method null : bool + method print : ('a -> unit) -> unit + method tl : 'a lst +end +# val l1 : int cons = <obj> +# (3::10::[])- : unit = () +# val l2 : int lst = <obj> +# (4::11::[])- : unit = () +# val map_list : ('a -> 'b) -> 'a lst -> 'b lst = <fun> +# val p1 : printable_color_point lst = <obj> +# ((3, red)::(10, red)::[])- : unit = () +# class virtual comparable (unit) : 'a = virtual leq : 'a -> bool end +# class int_comparable (int) : 'a = + val x : int + method leq : 'a -> bool + method x : int +end +# class int_comparable2 (int) : 'a = + method leq : 'a -> bool + method set_x : int -> unit + method x : int +end +# class 'a sorted_list (unit) = + constraint 'a = #comparable + val mutable l : 'a list + method add : 'a -> unit + method hd : 'a +end +# val l : _#comparable sorted_list = <obj> +# val c : int_comparable = <obj> +# - : unit = () +# val c2 : int_comparable2 = <obj> +# Characters 7-9: +This expression cannot be coerced to type + int_comparable = < leq : int_comparable -> bool; x : int >; +it has type + int_comparable2 = + < leq : int_comparable2 -> bool; x : int; set_x : int -> unit > +but is here used with type + < leq : int_comparable -> bool; x : int; set_x : int -> unit > +Type + int_comparable2 = + < leq : int_comparable2 -> bool; x : int; set_x : int -> unit > +is not compatible with type + int_comparable = < leq : int_comparable -> bool; x : int > +# - : unit = () +# class int_comparable3 (int) = + val mutable x : int + method leq : int_comparable -> bool + method setx : int -> unit + method x : int +end +# val c3 : int_comparable3 = <obj> +# - : unit = () +# Characters 25-27: +This expression has type + int_comparable3 = + < leq : int_comparable -> bool; x : int; setx : int -> unit > +but is here used with type + < leq : 'a -> bool; setx : int -> unit; x : int > as 'a +Type int_comparable = < leq : int_comparable -> bool; x : int > +is not compatible with type + int_comparable3 = + < leq : int_comparable -> bool; x : int; setx : int -> unit > +# val sort : (#comparable as 'a) list -> 'a list = <fun> +# val pr : < x : int; .. > list -> unit = <fun> +# val l : int_comparable list = [<obj>; <obj>; <obj>] +# 5 2 4 +- : unit = () +# 2 4 5 +- : unit = () +# val l : int_comparable2 list = [<obj>; <obj>] +# 2 0 +- : unit = () +# 0 2 +- : unit = () +# val min : (#comparable as 'a) -> 'a -> 'a = <fun> +# - : int = 7 +# - : int = 3 +# class 'a link ('a) : 'b = + val mutable next : 'b option + val mutable x : 'a + method append : 'b option -> unit + method next : 'b option + method set_next : 'b option -> unit + method set_x : 'a -> unit + method x : 'a +end +# class 'a double_link ('a) : 'b = + val mutable next : 'b option + val mutable prev : 'b option + val mutable x : 'a + method append : 'b option -> unit + method next : 'b option + method prev : 'b option + method set_next : 'b option -> unit + method set_prev : 'b option -> unit + method set_x : 'a -> unit + method x : 'a +end +# val fold_right : ('a -> 'b -> 'b) -> 'a #link option -> 'b -> 'b = <fun> +# class calculator (unit) : 'a = + val mutable acc : float + val mutable arg : float + val mutable equals : 'a -> float + method acc : float + method add : 'a + method arg : float + method enter : float -> 'a + method equals : float + method sub : 'a +end +# - : float = 5 +# - : float = 1.5 +# - : float = 15 +# class calculator (unit) : 'a = + val mutable acc : float + val mutable arg : float + val mutable equals : 'a -> float + method acc : float + method add : 'a + method arg : float + method enter : float -> 'a + method equals : float + method sub : 'a +end +# - : float = 5 +# - : float = 1.5 +# - : float = 15 +# class calculator (float) (float) = + val acc : float + val arg : float + method add : calculator_add + method enter : float -> calculator + method equals : float + method sub : calculator_sub +end +class calculator_add (float) (float) = + val acc : float + val arg : float + method add : calculator_add + method enter : float -> calculator + method equals : float + method sub : calculator_sub +end +class calculator_sub (float) (float) = + val acc : float + val arg : float + method add : calculator_add + method enter : float -> calculator + method equals : float + method sub : calculator_sub +end +# val calculator : calculator = <obj> +# - : float = 5 +# - : float = 1.5 +# - : float = 15 +# diff --git a/testobjects/Exemples.ml b/testobjects/Exemples.ml new file mode 100644 index 0000000..30db53a --- /dev/null +++ b/testobjects/Exemples.ml @@ -0,0 +1,333 @@ + +class point x_init = + val mutable x = x_init + method get_x = x + method move d = x <- x + d +end;; + +let p = new point 7;; + +p#get_x;; +p#move 3;; +p#get_x;; + +let q = Oo.copy p;; + +q#move 7; p#get_x, q#get_x;; + +class color_point x (c : string) = + inherit point x + val c = c + method color = c +end;; + +let p' = new color_point 5 "red";; + +p'#get_x, p'#color;; + +let l = [p; (p' :> point)];; + +let get_x p = p#get_x;; +let set_x p = p#set_x;; +List.map get_x l;; + +class ref x_init = + val mutable x = x_init + method get = x + method set y = x <- y +end;; + +class ref (x_init:int) = + val mutable x = x_init + method get = x + method set y = x <- y +end;; + +class 'a ref x_init = + val mutable x = (x_init : 'a) + method get = x + method set y = x <- y +end;; + +let r = new ref 1 in r#set 2; (r#get);; + +class 'a circle (c : 'a) = + val mutable center = c + method center = center + method set_center c = center <- c + method move = (center#move : int -> unit) +end;; + +class 'a circle (c : 'a) = + constraint 'a = #point + val mutable center = c + method center = center + method set_center c = center <- c + method move = center#move +end;; + +let (c, c') = (new circle p, new circle p');; + +class 'a color_circle c = + constraint 'a = #color_point + inherit ('a) circle c + method color = center#color +end;; + +let c'' = new color_circle p;; +let c'' = new color_circle p';; + +(c'' :> color_point circle);; +(c'' :> point circle);; (* Echec *) +fun x -> (x : color_point color_circle :> point circle);; + +class printable_point y as s = + inherit point y + method print = print_int s#get_x +end;; + +let p = new printable_point 7;; +p#print;; + +class printable_color_point y c as self = + inherit color_point y c + inherit printable_point y as super + method print = + print_string "("; + super#print; + print_string ", "; + print_string (self#color); + print_string ")" +end;; + +let p' = new printable_color_point 7 "red";; +p'#print;; + +class functional_point y = + val x = y + method get_x = x + method move d = {< x = x + d >} +end;; + +let p = new functional_point 7;; + +p#get_x;; +(p#move 3)#get_x;; +p#get_x;; + +fun x -> (x :> functional_point);; + +(*******************************************************************) + +class virtual 'a lst () as self = + virtual null : bool + virtual hd : 'a + virtual tl : 'a lst + method map f = + (if self#null then + new nil () + else + new cons (f self#hd) (self#tl#map f) + : 'a lst) + method iter (f : 'a -> unit) = + if self#null then () + else begin + f self#hd; + self#tl#iter f + end + method print (f : 'a -> unit) = + print_string "("; + self#iter (fun x -> f x; print_string "::"); + print_string "[]"; + print_string ")" +and 'a nil () = + inherit ('a) lst () + method null = true + method hd = failwith "hd" + method tl = failwith "tl" +and 'a cons h t = + inherit ('a) lst () + val h = h val t = t + method null = false + method hd = h + method tl = t +end;; + +let l1 = new cons 3 (new cons 10 (new nil ()));; + +l1#print print_int;; + +let l2 = l1#map (fun x -> x + 1);; +l2#print print_int;; + +let rec map_list f (x:'a lst) = + if x#null then new nil() + else new cons (f x#hd) (map_list f x#tl);; + +let p1 = (map_list (fun x -> new printable_color_point x "red") l1);; +p1#print (fun x -> x#print);; + +(*******************************************************************) + +class virtual comparable () : 'a = + virtual leq : 'a -> bool + end;; + +class int_comparable (x : int) = + inherit comparable () + val x = x + method x = x + method leq p = x <= p#x +end;; + +class int_comparable2 x = + inherit int_comparable x + val private mutable x + method set_x y = x <- y +end;; + +class 'a sorted_list () = + constraint 'a = #comparable + val mutable l = ([] : 'a list) + method add x = + let rec insert = + function + [] -> [x] + | a::l as l' -> if a#leq x then a::(insert l) else x::l' + in + l <- insert l + method hd = List.hd l +end;; + +let l = new sorted_list ();; +let c = new int_comparable 10;; +l#add c;; + +let c2 = new int_comparable2 15;; +l#add (c2 :> int_comparable);; (* Echec : 'a comp2 n'est un sous-type *) +(new sorted_list ())#add c2;; + +class int_comparable3 (x : int) = + val mutable x = x + method leq (y : int_comparable) = x < y#x + method x = x + method setx y = x <- y +end;; + +let c3 = new int_comparable3 15;; +l#add (c3 :> int_comparable);; +(new sorted_list ())#add c3;; (* Echec : leq n'est pas binaire *) + +let sort (l : #comparable list) = Sort.list (fun x -> x#leq) l;; +let pr l = + List.map (fun c -> print_int c#x; print_string " ") l; + print_newline ();; +let l = [new int_comparable 5; (new int_comparable3 2 :> int_comparable); + new int_comparable 4];; +pr l;; +pr (sort l);; +let l = [new int_comparable2 2; new int_comparable2 0];; +pr l;; +pr (sort l);; + +let min (x : #comparable) y = + if x#leq y then x else y;; + +(min (new int_comparable 7) (new int_comparable 11))#x;; +(min (new int_comparable2 5) (new int_comparable2 3))#x;; + +(*******************************************************************) + +class 'a link (x : 'a) as self : 'b = + val mutable x = x + val mutable next = (None : 'b option) + method x = x + method next = next + method set_x y = x <- y + method set_next l = next <- l + method append l = + match next with + None -> + self#set_next l + | Some l' -> + l'#append l +end;; + +class 'a double_link x as self = + inherit ('a) link x + val mutable prev = None + method prev = prev + method set_next l = + next <- l; + match l with Some l -> l#set_prev (Some self) | None -> () + method set_prev l = prev <- l +end;; + +let rec fold_right f (l : 'a #link option) accu = + match l with + None -> accu + | Some l -> + f l#x (fold_right f l#next accu);; + +(*******************************************************************) + +class calculator () as self = + val mutable arg = 0. + val mutable acc = 0. + val mutable equals = function s -> s#arg + method arg = arg + method acc = acc + method enter n = arg <- n; self + method add = + acc <- equals self; + equals <- (function s -> s#acc +. s#arg); + self + method sub = + acc <- equals self; + equals <- (function s -> s#acc -. s#arg); + self + method equals = equals self +end;; + +((new calculator ())#enter 5.)#equals;; +(((new calculator ())#enter 5.)#sub#enter 3.5)#equals;; +((new calculator ())#enter 5.)#add#add#equals;; + +class calculator () as self = + val mutable arg = 0. + val mutable acc = 0. + val mutable equals = function s -> s#arg + method arg = arg + method acc = acc + method enter n = arg <- n; self + method add = {< acc = equals self; equals = function s -> s#acc +. s#arg >} + method sub = {< acc = equals self; equals = function s -> s#acc -. s#arg >} + method equals = equals self +end;; + +((new calculator ())#enter 5.)#equals;; +(((new calculator ())#enter 5.)#sub#enter 3.5)#equals;; +((new calculator ())#enter 5.)#add#add#equals;; + +class calculator arg acc as self = + val arg = arg + val acc = acc + method enter n = new calculator n acc + method add = new calculator_add arg self#equals + method sub = new calculator_sub arg self#equals + method equals = arg +and calculator_add arg acc = + inherit calculator arg acc + method enter n = new calculator_add n acc + method equals = acc +. arg +and calculator_sub arg acc = + inherit calculator arg acc + method enter n = new calculator_sub n acc + method equals = acc -. arg +end;; + +let calculator = new calculator 0. 0.;; + +(calculator#enter 5.)#equals;; +((calculator#enter 5.)#sub#enter 3.5)#equals;; +(calculator#enter 5.)#add#add#equals;; diff --git a/testobjects/Makefile b/testobjects/Makefile new file mode 100644 index 0000000..380203f --- /dev/null +++ b/testobjects/Makefile @@ -0,0 +1,25 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.3 1999-11-17 18:58:45 xleroy Exp $ + +# ocaml must be installed... + +test: Tests Exemples + +Tests: + TERM=dumb ../ocaml < Tests.ml | tail +3 > Tests.proc + - diff Tests.exp Tests.proc + +Exemples: + TERM=dumb ../ocaml < Exemples.ml | tail +3 > Exemples.proc + - diff Exemples.exp Exemples.proc diff --git a/testobjects/Tests.exp b/testobjects/Tests.exp new file mode 100644 index 0000000..c28ef5a --- /dev/null +++ b/testobjects/Tests.exp @@ -0,0 +1,228 @@ +# - : < x : int > -> + < x : int > -> < x : int > -> < x : int > * < x : int > * < x : int > += <fun> +# class 'a c (unit) = constraint 'a = int method f : 'a c end +class 'a d (unit) = method f : int c end +# Characters 185-212: +The type variable 'a is not bound in implicit type definition + d = < f : 'a -> unit > +It should be captured by a class type parameter +# class virtual closed c ('a) : 'a = virtual f : int end +class virtual closed d ('a) : 'a = virtual f : int end +# class virtual closed e ('a) : 'a = virtual f : int end +# class virtual closed c (c) = end +# class virtual c (unit) = end +class 'a d (unit) = constraint 'a = < x : int; .. > method f : 'a -> int end +# class 'a c (unit) = constraint 'a = int end +class 'a d (unit) = constraint 'a = int #c end +# class closed 'a c ('a) : 'a = + constraint 'a = < f : 'a c > + method f : 'a c +end +# - : (< f : 'a c > as 'a) c -> (< f : 'b c > as 'b) c = <fun> +# Characters 118-143: +The class x should be virtual: its method f is undefined +# Characters 184-187: +The class d inherits from the closed class c which has no method g +# Characters 37-97: +The abbreviation c is used with parameters bool c +wich are incompatible with constraints int c +# class ('a, 'b) c (unit) = + constraint 'a = int -> 'c + constraint 'b = 'a * < x : 'b > * 'c * 'd + method f : 'a -> 'b -> unit +end +# class ('a, 'b) d (unit) = + constraint 'a = int -> 'c + constraint 'b = 'a * < x : 'b > * 'c * 'd + method f : 'a -> 'b -> unit +end +# val x : '_a list ref = {contents=[]} +# Characters 5-37: +The type parameters of this class contains type variables that cannot be +generalized: '_a list ref c +# type 'a c = < f : 'a c; g : 'a d > constraint 'a = int +type 'a d = < f : 'a c > constraint 'a = int +# type 'a c = < f : 'a c; g : 'a d > +type 'a d = < f : 'a c > +# type 'a c = < f : 'a c > constraint 'a = int +type 'a d = < f : int c > +# type 'a u = < x : 'a > constraint 'a = 'b t +type 'a t = 'a t u +# Characters 19-32: +The type abbreviation t is cyclic +# type 'a u = 'a +# Characters 4-18: +The type abbreviation t is cyclic +# type t = < x : t > +# type 'a u = 'a +# - : t -> t u -> bool = <fun> +# - : t -> t u -> bool = <fun> +# module M : + sig + class ('a, 'b) c ('c) ('b) = + constraint 'a = int -> bool + val x : 'd list + val y : 'b + method f : 'a -> unit + method g : 'b + end + end +# module M' : + sig + class virtual ('a, 'b) c (int) ('b) = + constraint 'a = int -> bool + val x : float list + val y : 'b + method f : 'a -> unit + method g : 'b + end + end +# class ('a, 'b) d (unit) ('b) = + constraint 'a = int -> bool + val x : 'c list + val y : 'b + method f : 'a -> unit + method g : 'b +end +# class ('a, 'b) e (unit) ('b) = + constraint 'a = int -> bool + val x : float list + val y : 'b + method f : 'a -> unit + method g : 'b +end +# - : string = "a" +# Characters 1-9: +One cannot create instances of the virtual class M'.c +# - : int = 10 +# - : float = 7.1 +# # - : bool = true +# module M : sig class closed 'a c (unit) = method f : 'a -> unit end end +# module M' : sig class closed 'a c (unit) = method f : 'a -> unit end end +# - : < f : 'a -> unit; .. > -> 'a M.c = <fun> +# - : < f : 'a -> unit; .. > -> 'a M'.c = <fun> +# class 'a c ('b #c) = end +# class closed 'a c ('a c) = end +# class c (unit) = method f : int end +class d (unit) = method f : int end +# class e (unit) = method f : int end +# - : int = 2 +# Characters 23-27: +This expression has type bool but is here used with type int +# class c (unit) = method f : int method g : int method h : int end +# class d (unit) = method h : int method i : int method j : int end +# class e (unit) = + method f : int + method g : int + method h : int + method i : int + method j : int +end +# val e : e = <obj> +# - : int * int * int * int * int = 1, 3, 2, 2, 3 +# class c ('a) = val a : 'a val x : int val y : int val z : int end +# class d ('a) = val b : 'a val t : int val u : int val z : int end +# class e (unit) = + val a : int + val b : int + val t : int + val u : int + val x : int + val y : int + val z : int + method a : int + method b : int + method t : int + method u : int + method x : int + method y : int + method z : int +end +# val e : e = <obj> +# - : int * int * int * int * int * int * int = 1, 3, 2, 2, 3, 5, 7 +# class c (int) (int) = + val x : int + val y : int + method x : int + method y : int +end +# class d (int) (int) = + val x : int + val y : int + method x : int + method y : int +end +# - : int * int = 1, 2 +# - : int * int = 1, 2 +# class 'a c ('a) = end +# - : 'a -> 'a c = <fun> +# module type M = + sig class c (unit) = val x : int end class d (unit) = val x : bool end end +# class c (int) = method get : int method set : int -> unit end +# val c : c = <obj> +# - : int = 5 +# - : int = 7 +# class c (unit) = val x : int val y : int method c : int end +# class d (unit) = val y : int method c : int method d : int end +# class e (unit) = + val x : int + val y : int + method c : int + method d : int + method x : int + method y : int +end +# - : int * int * int * int = 2, 1, 1, 1 +# module M : sig class c (unit) = method xc : int end end +# class d (unit) = val x : int method xc : int method xd : int end +# - : int * int = 1, 2 +# Characters 7-143: +The type variable 'a is not bound in implicit type definition + 'b matrix = < add : 'b matrix -> 'b; m : 'a > +It should be captured by a class type parameter +# class c (unit) = method m : c end +# - : c = <obj> +# module M : sig class c (unit) = method m : c end end +# - : M.c = <obj> +# type uu = | A of int | B of (< leq : 'a > as 'a) +# class virtual c (unit) : 'a = virtual m : 'a end +# module S : sig val f : (#c as 'a) -> 'a end +# Characters 12-43: +Signature mismatch: +Modules do not match: + sig val f : (#c as 'a) -> 'a end +is not included in + sig val f : #c -> #c end +Values do not match: + val f : (#c as 'a) -> 'a +is not included in + val f : #c -> #c +# Characters 32-48: +Multiple definition of the type name t. +Names must be unique in a given structure. +# - : (< m : (< m : 'b -> 'b > as 'b) -> 'a; .. > as 'a) -> + (< m : 'c -> 'c > as 'c) += <fun> +# Characters 10-39: +Type int -> bool is not a subtype of type int -> int +Type bool is not a subtype of type int +# Characters 9-40: +Type int -> bool is not a subtype of type int -> int +Type bool is not a subtype of type int +# - : < > -> < > = <fun> +# - : < .. > -> < > = <fun> +# val x : '_a list ref = {contents=[]} +# module F : functor(X : sig end) -> sig type t = int end +# - : < m : int > list ref = {contents=[]} +# type 'a t +# - : ('a t as 'a) -> unit = <fun> +# - : ('a t as 'a) -> unit = <fun> +# type 'a t = < x : 'a > +# - : (< x : 'a > as 'a) t -> unit = <fun> +# - : (< x : 'a > as 'a) t -> unit = <fun> +# class c (unit) = private method m : int method n : int end +# class d (unit) = private method m : int method n : int method o : int end +# - : int * int = 1, 1 +# class c (unit) = method m : int end +# diff --git a/testobjects/Tests.ml b/testobjects/Tests.ml new file mode 100644 index 0000000..29051fa --- /dev/null +++ b/testobjects/Tests.ml @@ -0,0 +1,316 @@ +(* Le sous-typage est "syntaxique" *) +fun (x : < x : int >) y z -> (y :> 'a), (x :> 'a), (z :> 'a);; +(* - : (< x : int > as 'a) -> 'a -> 'a * 'a = <fun> *) + +(* Bizarrerie du typage des classes *) +class 'a c () = + method f = (new c (): int c) +and 'a d () = + inherit ('a) c () +end;; +(* class 'a c (unit) = constraint 'a = int method f : 'a c end *) +(* class 'a d (unit) method f : int c end *) + +(* 'a libre dans classe d *) +class 'a c () = + method f (x : 'a) = () +and d () = + inherit ('a) c () +end;; + +(* Ferme self ! *) +(* Pas vraiment moyen de garder l'abbreviation en parametre *) +class virtual closed c ((x : 'a): < f : int >) : 'a = +and virtual closed d ((x : 'a): < f : int >) : 'a = + inherit c x +end;; +class virtual closed e x = + inherit d x +end;; +(* class virtual closed c (< f : int >) = virtual f : int end *) +(* class virtual closed d (< f : int >) = virtual f : int end *) +(* class virtual closed e (< f : int >) = virtual f : int end *) + +(* Self unifie avec une abreviation *) +class virtual closed c ((x : 'a) : c) : 'a = end;; + +(* Instancie #c *) +class virtual c () = +and 'a d () = + constraint 'a = #c + method f (x : #c) = (x#x : int) +end;; +(* class virtual c (unit) = end + class 'a d (unit) = constraint 'a = < x: int; .. > method f : 'a -> int end *) + +class 'a c () = + constraint 'a = int +and 'a d () = + constraint 'a = 'b #c +end;; +(* class 'a c (unit) = constraint 'a = int end + class 'a d (unit) = constraint 'a = int #c end *) + +(* Self en parametre *) +class closed 'a c (x : 'a) as self : 'b = + constraint 'a = 'b + method f = self +end;; +new c;; +(* class 'a c ('a) :'b = constraint 'a = 'a c method f : 'a end *) +(* - : ('a c as 'a) -> 'b c as 'b = <fun> *) + +class x () = + virtual f : int +end;; +(* The class x should be virtual: its methods f is undefined *) + +(* Methode g en trop *) +class virtual closed c ((x : 'a): < f : int >) : 'a = +and virtual closed d x : 'a = + inherit c x + method g = true +end;; + +(* Contrainte non respectee *) +class 'a c () = + constraint 'a = int + method f x = (x : bool c) +end;; + +(* Differentes contraintes *) +class ('a, 'b) c () = + constraint 'a = int -> 'c + constraint 'b = 'a * <x : 'b> * 'c * 'd + method f (x : 'a) (y : 'b) = () +end;; +class ('a, 'b) d () = + inherit ('a, 'b) c () +end;; + +(* Contrainte non generique *) +let x = ref [];; +class 'a c () = + method f = (x : 'a) +end;; + +(* Abreviations *) +type 'a c = <f : 'a c; g : 'a d> +and 'a d = <f : int c>;; +type 'a c = <f : 'a c; g : 'a d> +and 'a d = <f : 'a c>;; +type 'a c = <f : 'a c> +and 'a d = <f : int c>;; +type 'a u = < x : 'a> +and 'a t = 'a t u;; +type 'a u = 'a +and 'a t = 'a t u;; +type 'a u = 'a;; +type t = t u * t u;; + +type t = <x : 'a> as 'a;; +type 'a u = 'a;; +fun (x : t) (y : 'a u) -> x = y;; +fun (x : t) (y : 'a u) -> y = x;; +(* - : t -> t u -> bool = <fun> *) + +(* Modules *) +module M = + struct + class ('a, 'b) c x (y: 'b) = + constraint 'a = int -> bool + val x = [] + val y = y + method f (x : 'a) = () + method g = y + end + end;; +module M' = (M : + sig + class virtual ('a, 'b) c (int) ('b) = + constraint 'a = int -> bool + val x : float list + val y : 'b + method f : 'a -> unit + method g : 'b + end + end);; +class ('a, 'b) d () y = inherit ('a, 'b) M.c () y end;; +class ('a, 'b) e () y = inherit ('a, 'b) M'.c 1 y end;; +(new M.c () "a")#g;; +(new M'.c 1)#g;; +(new d () 10)#g;; +(new e () 7.1)#g;; +open M;; +(new c () true)#g;; + +(* #cl quand cl est fermee *) +module M = struct class closed 'a c () = method f (x : 'a) = () end end;; +module M' = + (M : sig class closed 'a c (unit) = method f : 'a -> unit end end);; +fun x -> (x :> 'a #M.c);; +fun x -> (x :> 'a #M'.c);; +class 'a c (x : 'b #c) = end;; +class closed 'a c (x : 'b #c) = end;; + +(* Ordre de calcul *) +class c () = method f = 1 and d () = method f = 2 end;; +class e () = inherit c () inherit d () end;; +(new e ())#f;; +class c () = val x = - true val y = -. () end;; + +class c () = method f = 1 method g = 1 method h = 1 end;; +class d () = method h = 2 method i = 2 method j = 2 end;; +class e () = + method f = 3 + inherit c () + method g = 3 + method i = 3 + inherit d () + method j = 3 +end;; +let e = new e ();; +e#f, e#g, e#h, e#i, e#j;; + +class c a = val x = 1 val y = 1 val z = 1 val a = a end;; +class d b = val z = 2 val t = 2 val u = 2 val b = b end;; +class e () = + val x = 3 + inherit c 5 + val y = 3 + val t = 3 + inherit d 7 + val u = 3 + method x = x + method y = y + method z = z + method t = t + method u = u + method a = a + method b = b +end;; +let e = new e ();; +e#x, e#y, e#z, e#t, e#u, e#a, e#b;; + +class c (x : int) (y : int) = + val x = x + val y = y + method x = x + method y = y +end;; +class d x y = inherit c x y end;; +let c = new c 1 2 in c#x, c#y;; +let d = new d 1 2 in d#x, d#y;; + +(* Parametres n'apparaissant pas dans le type de l'objet *) +class 'a c (x : 'a) = end;; +new c;; + +(* Variables privees *) +module type M = sig + class c (unit) = val x : int end + class d (unit) = inherit c val private x : int val x : bool end +end;; +class c (x : int) = + val private mutable x = x + method get = x + method set y = x <- y +end;; +let c = new c 5;; +c#get;; +c#set 7; c#get;; + +class c () = val x = 1 val y = 1 method c = x end;; +class d () = inherit c () val private x method d = x end;; +class e () = + val x = 2 val y = 2 inherit d () method x = x method y = y +end;; +let e = new e () in e#x, e#y, e#c, e#d;; + +(* Oubli de variables dans l'interface *) +module M : + sig + class c (unit) = + method xc : int + end + end = + struct + class c () = + val x = 1 + method xc = x + end + end;; +class d () = + val x = 2 + method xd = x + inherit M.c () +end;; +let d = new d () in d#xc, d#xd;; + +class virtual 'a matrix (sz, init : int * 'a) = + val m = Array.create_matrix sz sz init + method add (mtx : 'a matrix) = (mtx#m.(0).(0) : 'a) +end;; + +class c () = method m = new c () end;; +(new c ())#m;; +module M = struct class c () = method m = new c () end end;; +(new M.c ())#m;; + +type uu = A of int | B of (<leq: 'a> as 'a);; + +class virtual c () : 'a = virtual m : 'a end;; +module S = (struct + let f (x : #c) = x +end : sig + val f : #c as 'a -> 'a +end);; +module S = (struct + let f (x : #c) = x +end : sig + val f : #c -> #c +end);; + +module M = struct type t = int class t () = end end;; + +fun x -> (x :> < m : 'a -> 'a > as 'a);; + +fun x -> (x : int -> bool :> 'a -> 'a);; +fun x -> (x : int -> bool :> int -> int);; +fun x -> (x : < > :> < .. >);; +fun x -> (x : < .. > :> < >);; + +let x = ref [];; +module F(X : sig end) = + struct type t = int let _ = (x : < m : t> list ref) end;; +x;; + +type 'a t;; +fun (x : 'a t as 'a) -> ();; +fun (x : 'a t) -> (x : 'a); ();; +type 'a t = < x : 'a >;; +fun (x : 'a t as 'a) -> ();; +fun (x : 'a t) -> (x : 'a); ();; + +class 'a c () = + constraint 'a = < .. > -> unit + method m = (fun x -> () : 'a) +end;; +class 'a c () = + constraint 'a = unit -> < .. > + method m (f : 'a) = f () +end;; + +class c () as self = + private method m = 1 + method n = self#m +end;; + +class d () as self = + inherit c () + method o = self#m +end;; + +let x = new d () in x#n, x#o;; + +class c () = virtual m : int private method m = 1 end;; diff --git a/tools/.cvsignore b/tools/.cvsignore new file mode 100644 index 0000000..da394be --- /dev/null +++ b/tools/.cvsignore @@ -0,0 +1,22 @@ +ocamldep +ocamldep.opt +ocamlprof +opnames.ml +dumpobj +dumpapprox +objinfo +cvt_emit +cvt_emit.ml +ocamlcp +ocamlmktop +primreq +ocamldumpobj +keywords +lexer299.ml +ocaml299to3 +ocamlmklib +ocamlmklib.ml +lexer301.ml +scrapelabels +addlabels +myocamlbuild_config.ml diff --git a/tools/.depend b/tools/.depend new file mode 100644 index 0000000..b51459b --- /dev/null +++ b/tools/.depend @@ -0,0 +1,64 @@ +depend.cmi: ../parsing/parsetree.cmi +profiling.cmi: +addlabels.cmo: ../parsing/parsetree.cmi ../parsing/parse.cmi \ + ../parsing/longident.cmi ../parsing/location.cmi ../parsing/asttypes.cmi +addlabels.cmx: ../parsing/parsetree.cmi ../parsing/parse.cmx \ + ../parsing/longident.cmx ../parsing/location.cmx ../parsing/asttypes.cmi +cvt_emit.cmo: +cvt_emit.cmx: +depend.cmo: ../parsing/parsetree.cmi ../parsing/longident.cmi \ + ../parsing/location.cmi depend.cmi +depend.cmx: ../parsing/parsetree.cmi ../parsing/longident.cmx \ + ../parsing/location.cmx depend.cmi +dumpapprox.cmo: ../utils/config.cmi ../asmcomp/compilenv.cmi \ + ../asmcomp/clambda.cmi +dumpapprox.cmx: ../utils/config.cmx ../asmcomp/compilenv.cmx \ + ../asmcomp/clambda.cmx +dumpobj.cmo: ../utils/tbl.cmi opnames.cmo ../bytecomp/opcodes.cmo \ + ../parsing/location.cmi ../bytecomp/lambda.cmi ../bytecomp/instruct.cmi \ + ../typing/ident.cmi ../bytecomp/emitcode.cmi ../utils/config.cmi \ + ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmi \ + ../parsing/asttypes.cmi +dumpobj.cmx: ../utils/tbl.cmx opnames.cmx ../bytecomp/opcodes.cmx \ + ../parsing/location.cmx ../bytecomp/lambda.cmx ../bytecomp/instruct.cmx \ + ../typing/ident.cmx ../bytecomp/emitcode.cmx ../utils/config.cmx \ + ../bytecomp/cmo_format.cmi ../bytecomp/bytesections.cmx \ + ../parsing/asttypes.cmi +lexer301.cmo: ../utils/warnings.cmi ../utils/misc.cmi ../parsing/location.cmi +lexer301.cmx: ../utils/warnings.cmx ../utils/misc.cmx ../parsing/location.cmx +myocamlbuild_config.cmo: +myocamlbuild_config.cmx: +objinfo.cmo: ../utils/config.cmi ../bytecomp/cmo_format.cmi +objinfo.cmx: ../utils/config.cmx ../bytecomp/cmo_format.cmi +ocaml299to3.cmo: +ocaml299to3.cmx: +ocamlcp.cmo: ../driver/main_args.cmi +ocamlcp.cmx: ../driver/main_args.cmx +ocamldep.cmo: ../parsing/syntaxerr.cmi ../parsing/parsetree.cmi \ + ../parsing/parse.cmi ../utils/misc.cmi ../parsing/longident.cmi \ + ../parsing/location.cmi ../parsing/lexer.cmi depend.cmi \ + ../utils/config.cmi ../utils/clflags.cmi +ocamldep.cmx: ../parsing/syntaxerr.cmx ../parsing/parsetree.cmi \ + ../parsing/parse.cmx ../utils/misc.cmx ../parsing/longident.cmx \ + ../parsing/location.cmx ../parsing/lexer.cmx depend.cmx \ + ../utils/config.cmx ../utils/clflags.cmx +ocamlmklib.cmo: myocamlbuild_config.cmo +ocamlmklib.cmx: myocamlbuild_config.cmx +ocamlmktop.cmo: ../utils/ccomp.cmi +ocamlmktop.cmx: ../utils/ccomp.cmx +ocamlprof.cmo: ../utils/warnings.cmi ../parsing/syntaxerr.cmi \ + ../parsing/parsetree.cmi ../parsing/parse.cmi ../utils/misc.cmi \ + ../parsing/location.cmi ../parsing/lexer.cmi ../utils/config.cmi \ + ../utils/clflags.cmi +ocamlprof.cmx: ../utils/warnings.cmx ../parsing/syntaxerr.cmx \ + ../parsing/parsetree.cmi ../parsing/parse.cmx ../utils/misc.cmx \ + ../parsing/location.cmx ../parsing/lexer.cmx ../utils/config.cmx \ + ../utils/clflags.cmx +opnames.cmo: +opnames.cmx: +primreq.cmo: ../utils/config.cmi ../bytecomp/cmo_format.cmi +primreq.cmx: ../utils/config.cmx ../bytecomp/cmo_format.cmi +profiling.cmo: profiling.cmi +profiling.cmx: profiling.cmi +scrapelabels.cmo: lexer301.cmo +scrapelabels.cmx: lexer301.cmx diff --git a/tools/Characters b/tools/Characters new file mode 100644 index 0000000..ed76fba --- /dev/null +++ b/tools/Characters @@ -0,0 +1,16 @@ +# Characters + +# $Id: Characters,v 1.3 1999-11-29 19:04:21 doligez Exp $ + +# Usage: +# Characters n1 to n2 +# +# Select the characters in the given interval, counting from the first +# character of the current line, in the active window. +# +# Typical use is an error message of the form: +# File fff; Line lll; Characters yyy to zzz + +exit 1 if {#} ­ 3 + +Find Ƥ!{1}:¤!`evaluate {3} - {1}` "{active}" diff --git a/tools/DoMake b/tools/DoMake new file mode 100644 index 0000000..a2d1632 --- /dev/null +++ b/tools/DoMake @@ -0,0 +1,61 @@ +# DoMake + +# $Id: DoMake,v 1.5 1999-11-29 19:04:23 doligez Exp $ + +# Execute the output of "Make -f Makefile.Mac -f Makefile.Mac.depend" +# or "Make -f Makefile -f Makefile.depend" if "Makefile.Mac" does not exist +# or "Make -f <file>" if the "-f" option is given. + +# usage: domake [-quiet] [-f <file>]É <make arguments> + +set echo 0 + +set domake_quiet 0 +set domake_files "" + +loop + if "{1}" == "-quiet" + set domake_quiet 1 + shift + else if "{1}" == "-f" + set domake_files "{domake_files} -f `quote "{2}"`" + shift 2 + else + break + end +end + +set tempfile "{TempFolder}temp-domake-`Date -n`" +if "`exists "{tempfile}"`" + set i 0 + loop + break if ! "`exists "{tempfile}.{i}"`" + evaluate i += 1 + end + set tempfile "{tempfile}.{i}" +end + +if "{domake_files}" == "" + if "`exists Makefile.Mac`" != "" + set domake_main "Makefile.Mac" + else + set domake_main "Makefile" + end + + if "`exists "{domake_main}".depend`" != "" + set domake_files "-f {domake_main} -f {domake_main}.depend" + else + set domake_files "-f {domake_main}" + end +end + +if {domake_quiet} + echo >"{tempfile}" +else + echo 'set echo 1' >"{tempfile}" +end +make {domake_files} {"Parameters"} >>"{tempfile}" + +"{tempfile}" + +Delete -i "{tempfile}" diff --git a/tools/MakeDepend b/tools/MakeDepend new file mode 100644 index 0000000..c676fc8 --- /dev/null +++ b/tools/MakeDepend @@ -0,0 +1,17 @@ +# MakeDepend + +# $Id: MakeDepend,v 1.3 1999-11-29 19:04:25 doligez Exp $ + + +# Usage: MakeDepend fileÉ + +# Generate the Make dependency rules for a set of C files. +# The rules are printed on standard output. + +set echo 0 +set exit 0 + +for i in {"parameters"} + mrc -c -w off -make dev:stdout "{i}" ³ dev:null ¶ + | streamedit -e '/¶"(Å)¨0.c.o¶"/ replace // "¶""¨0".c.o¶" ¶""¨0".c.x¶""' +end diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..5b36fd6 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,21 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.66 2007-11-22 22:14:43 doligez Exp $ + +include Makefile.shared + +# To make custom toplevels + +ocamlmktop: ocamlmktop.tpl ../config/Makefile + sed -e 's|%%BINDIR%%|$(BINDIR)|' ocamlmktop.tpl > ocamlmktop + chmod +x ocamlmktop diff --git a/tools/Makefile.nt b/tools/Makefile.nt new file mode 100644 index 0000000..7f87763 --- /dev/null +++ b/tools/Makefile.nt @@ -0,0 +1,23 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.26 2007-11-07 10:14:21 frisch Exp $ + +include Makefile.shared + +# To make custom toplevels + +OCAMLMKTOP=ocamlmktop.cmo +OCAMLMKTOP_IMPORTS=misc.cmo config.cmo clflags.cmo ccomp.cmo + +ocamlmktop: $(OCAMLMKTOP) + $(CAMLC) $(LINKFLAGS) -o ocamlmktop $(OCAMLMKTOP_IMPORTS) $(OCAMLMKTOP) diff --git a/tools/Makefile.shared b/tools/Makefile.shared new file mode 100644 index 0000000..a5f15e6 --- /dev/null +++ b/tools/Makefile.shared @@ -0,0 +1,276 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.shared,v 1.5 2007-11-22 22:14:43 doligez Exp $ + +include ../config/Makefile + +CAMLRUN=../boot/ocamlrun +CAMLC=$(CAMLRUN) ../boot/ocamlc -nostdlib -I ../boot +CAMLOPT=$(CAMLRUN) ../ocamlopt -nostdlib -I ../stdlib +CAMLLEX=$(CAMLRUN) ../boot/ocamllex +INCLUDES=-I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../asmcomp \ + -I ../driver +COMPFLAGS= -warn-error A $(INCLUDES) +LINKFLAGS=$(INCLUDES) + +all: ocamldep ocamlprof ocamlcp ocamlmktop ocamlmklib scrapelabels addlabels \ + dumpobj +.PHONY: all + +opt.opt: ocamldep.opt +.PHONY: opt.opt + +# The dependency generator + +CAMLDEP_OBJ=depend.cmo ocamldep.cmo +CAMLDEP_IMPORTS=misc.cmo config.cmo clflags.cmo terminfo.cmo \ + linenum.cmo warnings.cmo location.cmo longident.cmo \ + syntaxerr.cmo parser.cmo lexer.cmo parse.cmo + +ocamldep: depend.cmi $(CAMLDEP_OBJ) + $(CAMLC) $(LINKFLAGS) -o ocamldep $(CAMLDEP_IMPORTS) $(CAMLDEP_OBJ) + +ocamldep.opt: depend.cmi $(CAMLDEP_OBJ:.cmo=.cmx) + $(CAMLOPT) $(LINKFLAGS) -o ocamldep.opt $(CAMLDEP_IMPORTS:.cmo=.cmx) \ + $(CAMLDEP_OBJ:.cmo=.cmx) + +# ocamldep is precious: sometimes we are stuck in the middle of a +# bootstrap and we need to remake the dependencies +clean:: + if test -f ocamldep; then mv -f ocamldep ocamldep.bak; else :; fi + rm -f ocamldep.opt + +install:: + cp ocamldep $(BINDIR)/ocamldep$(EXE) + if test -f ocamldep.opt; \ + then cp ocamldep.opt $(BINDIR)/ocamldep.opt$(EXE); else :; fi + +# The profiler + +CSLPROF=ocamlprof.cmo +CSLPROF_IMPORTS=misc.cmo config.cmo clflags.cmo terminfo.cmo \ + linenum.cmo warnings.cmo location.cmo longident.cmo \ + syntaxerr.cmo parser.cmo lexer.cmo parse.cmo + +ocamlprof: $(CSLPROF) profiling.cmo + $(CAMLC) $(LINKFLAGS) -o ocamlprof $(CSLPROF_IMPORTS) $(CSLPROF) + +ocamlcp: ocamlcp.cmo + $(CAMLC) $(LINKFLAGS) -o ocamlcp main_args.cmo ocamlcp.cmo + +install:: + cp ocamlprof $(BINDIR)/ocamlprof$(EXE) + cp ocamlcp $(BINDIR)/ocamlcp$(EXE) + cp profiling.cmi profiling.cmo $(LIBDIR) + +clean:: + rm -f ocamlprof ocamlcp + +install:: + cp ocamlmktop $(BINDIR)/ocamlmktop$(EXE) + +clean:: + rm -f ocamlmktop + +# To help building mixed-mode libraries (Caml + C) + +ocamlmklib: myocamlbuild_config.cmo ocamlmklib.cmo + $(CAMLC) $(LINKFLAGS) -o ocamlmklib myocamlbuild_config.cmo \ + ocamlmklib.cmo + +ocamlmklib.cmo: myocamlbuild_config.cmi + +myocamlbuild_config.cmi: myocamlbuild_config.cmo + +myocamlbuild_config.ml: ../config/Makefile ../build/mkmyocamlbuild_config.sh + ../build/mkmyocamlbuild_config.sh + cp ../myocamlbuild_config.ml . + +install:: + cp ocamlmklib $(BINDIR)/ocamlmklib$(EXE) + +clean:: + rm -f ocamlmklib + +ocamlmklib.ml: ocamlmklib.mlp ../config/Makefile + echo '(* THIS FILE IS GENERATED FROM ocamlmklib.mlp *)' >ocamlmklib.ml + sed -e "s|%%BINDIR%%|$(BINDIR)|" \ + -e "s|%%SUPPORTS_SHARED_LIBRARIES%%|$(SUPPORTS_SHARED_LIBRARIES)|" \ + -e "s|%%MKSHAREDLIB%%|$(MKSHAREDLIB)|" \ + -e "s|%%BYTECCRPATH%%|$(BYTECCRPATH)|" \ + -e "s|%%NATIVECCRPATH%%|$(NATIVECCRPATH)|" \ + -e "s|%%MKSHAREDLIBRPATH%%|$(MKSHAREDLIBRPATH)|" \ + -e "s|%%RANLIB%%|$(RANLIB)|" \ + ocamlmklib.mlp >> ocamlmklib.ml + +beforedepend:: ocamlmklib.ml + +clean:: + rm -f ocamlmklib.ml + +# To make custom toplevels (see Makefile/Makefile.nt) + +install:: + cp ocamlmktop $(BINDIR)/ocamlmktop$(EXE) + +clean:: + rm -f ocamlmktop + + +# Converter olabl/ocaml 2.99 to ocaml 3 + +OCAML299TO3= lexer299.cmo ocaml299to3.cmo +LIBRARY3= misc.cmo warnings.cmo linenum.cmo location.cmo + +ocaml299to3: $(OCAML299TO3) + $(CAMLC) $(LINKFLAGS) -o ocaml299to3 $(LIBRARY3) $(OCAML299TO3) + +lexer299.ml: lexer299.mll + $(CAMLLEX) lexer299.mll + +#install:: +# cp ocaml299to3 $(BINDIR)/ocaml299to3$(EXE) + +clean:: + rm -f ocaml299to3 lexer299.ml + +# Label remover for interface files (upgrade 3.02 to 3.03) + +SCRAPELABELS= lexer301.cmo scrapelabels.cmo + +scrapelabels: $(SCRAPELABELS) + $(CAMLC) $(LINKFLAGS) -o scrapelabels $(LIBRARY3) $(SCRAPELABELS) + +lexer301.ml: lexer301.mll + $(CAMLLEX) lexer301.mll + +install:: + cp scrapelabels $(LIBDIR) + +clean:: + rm -f scrapelabels lexer301.ml + +# Insert labels following an interface file (upgrade 3.02 to 3.03) + +ADDLABELS_IMPORTS=misc.cmo config.cmo clflags.cmo terminfo.cmo \ + linenum.cmo warnings.cmo location.cmo longident.cmo \ + syntaxerr.cmo parser.cmo lexer.cmo parse.cmo + +addlabels: addlabels.ml + $(CAMLC) $(LINKFLAGS) -w sl -o addlabels \ + $(ADDLABELS_IMPORTS) addlabels.ml + +install:: + cp addlabels $(LIBDIR) + +clean:: + rm -f addlabels + +# The preprocessor for asm generators + +CVT_EMIT=cvt_emit.cmo + +cvt_emit: $(CVT_EMIT) + $(CAMLC) $(LINKFLAGS) -o cvt_emit $(CVT_EMIT) + +# cvt_emit is precious: sometimes we are stuck in the middle of a +# bootstrap and we need to remake the dependencies +clean:: + if test -f cvt_emit; then mv -f cvt_emit cvt_emit.bak; else :; fi + +cvt_emit.ml: cvt_emit.mll + $(CAMLLEX) cvt_emit.mll + +clean:: + rm -f cvt_emit.ml + +beforedepend:: cvt_emit.ml + +# The bytecode disassembler + +DUMPOBJ=opnames.cmo dumpobj.cmo + +dumpobj: $(DUMPOBJ) + $(CAMLC) $(LINKFLAGS) -o dumpobj \ + misc.cmo tbl.cmo config.cmo ident.cmo \ + opcodes.cmo bytesections.cmo $(DUMPOBJ) + +clean:: + rm -f dumpobj + +opnames.ml: ../byterun/instruct.h + unset LC_ALL || : ; \ + unset LC_CTYPE || : ; \ + unset LC_COLLATE LANG || : ; \ + sed -e '/\/\*/d' \ + -e '/^#/d' \ + -e 's/enum \(.*\) {/let names_of_\1 = [|/' \ + -e 's/};$$/ |]/' \ + -e 's/\([A-Z][A-Z_0-9a-z]*\)/"\1"/g' \ + -e 's/,/;/g' \ + ../byterun/instruct.h > opnames.ml + +clean:: + rm -f opnames.ml + +beforedepend:: opnames.ml + +# Dump .cmx files + +dumpapprox: dumpapprox.cmo + $(CAMLC) $(LINKFLAGS) -o dumpapprox config.cmo dumpapprox.cmo + +clean:: + rm -f dumpapprox + +# Print imported interfaces for .cmo files + +objinfo: objinfo.cmo + $(CAMLC) $(LINKFLAGS) -o objinfo config.cmo objinfo.cmo + +clean:: + rm -f objinfo + +# Scan object files for required primitives + +PRIMREQ=primreq.cmo + +primreq: $(PRIMREQ) + $(CAMLC) $(LINKFLAGS) -o primreq config.cmo $(PRIMREQ) + +clean:: + rm -f primreq + +# Common stuff + +.SUFFIXES: +.SUFFIXES: .ml .cmo .mli .cmi .cmx + +.ml.cmo: + $(CAMLC) -c $(COMPFLAGS) $< + +.mli.cmi: + $(CAMLC) -c $(COMPFLAGS) $< + +.ml.cmx: + $(CAMLOPT) $(COMPFLAGS) -c $< + +clean:: + rm -f *.cmo *.cmi + +depend: beforedepend + $(CAMLRUN) ./ocamldep $(INCLUDES) *.mli *.ml > .depend + +.PHONY: clean install beforedepend depend + +include .depend diff --git a/tools/OCamlc-custom b/tools/OCamlc-custom new file mode 100644 index 0000000..c389974 --- /dev/null +++ b/tools/OCamlc-custom @@ -0,0 +1,10 @@ +# OCamlc with option -custom +# Macintosh version + +set echo 0 +set -e ocamlcommands "{tempfolder}"OCaml.temp."`date -n`" +echo >"{ocamlcommands}" +ocamlc -custom {"parameters"} +execute "{ocamlcommands}" + +delete -y "{ocamlcommands}" diff --git a/tools/Time b/tools/Time new file mode 100644 index 0000000..0a82674 --- /dev/null +++ b/tools/Time @@ -0,0 +1,10 @@ +# Time # Measure execution time +# Usage: Time command argumentsÉ + +set echo 0 + +set startdate `date -n` +{parameters} +set enddate `date -n` + +echo "# Time: `evaluate {enddate} - {startdate}` s" > dev:stderr diff --git a/tools/addlabels.ml b/tools/addlabels.ml new file mode 100644 index 0000000..f8b87d1 --- /dev/null +++ b/tools/addlabels.ml @@ -0,0 +1,452 @@ +(* $Id: addlabels.ml,v 1.12 2008-07-09 13:03:37 mauny Exp $ *) + +open StdLabels +open Asttypes +open Parsetree + +let norec = ref false + +let input_file file = + let ic = try open_in file with _ -> failwith ("input_file : " ^ file) in + let b = Buffer.create 1024 in + let buf = String.create 1024 and len = ref 0 in + while len := input ic buf 0 1024; !len > 0 do + Buffer.add_substring b buf 0 !len + done; + close_in ic; + Buffer.contents b + +module SMap = struct + include Map.Make(struct type t = string let compare = compare end) + let rec removes l m = + match l with [] -> m + | k::l -> + let m = try remove k m with Not_found -> m in + removes l m +end + +let rec labels_of_sty sty = + match sty.ptyp_desc with + Ptyp_arrow (lab, _, rem) -> lab :: labels_of_sty rem + | Ptyp_alias (rem, _) -> labels_of_sty rem + | _ -> [] + +let rec labels_of_cty cty = + match cty.pcty_desc with + Pcty_fun (lab, _, rem) -> + let (labs, meths) = labels_of_cty rem in + (lab :: labs, meths) + | Pcty_signature (_, fields) -> + ([], + List.fold_left fields ~init:[] ~f: + begin fun meths -> function + Pctf_meth (s, _, sty, _) -> (s, labels_of_sty sty)::meths + | _ -> meths + end) + | _ -> + ([],[]) + +let rec pattern_vars pat = + match pat.ppat_desc with + Ppat_var s -> [s] + | Ppat_alias (pat, s) -> + s :: pattern_vars pat + | Ppat_tuple l + | Ppat_array l -> + List.concat (List.map pattern_vars l) + | Ppat_construct (_, Some pat, _) + | Ppat_variant (_, Some pat) + | Ppat_constraint (pat, _) -> + pattern_vars pat + | Ppat_record l -> + List.concat (List.map l ~f:(fun (_,p) -> pattern_vars p)) + | Ppat_or (pat1, pat2) -> + pattern_vars pat1 @ pattern_vars pat2 + | Ppat_lazy pat -> pattern_vars pat + | Ppat_any | Ppat_constant _ | Ppat_construct _ | Ppat_variant _ + | Ppat_type _ -> + [] + +let pattern_name pat = + match pat.ppat_desc with + Ppat_var s -> Some s + | Ppat_constraint ({ppat_desc = Ppat_var s}, _) -> Some s + | _ -> None + +let insertions = ref [] +let add_insertion pos s = insertions := (pos,s) :: !insertions +let sort_insertions () = + List.sort !insertions ~cmp:(fun (pos1,_) (pos2,_) -> pos1 - pos2) + +let is_space = function ' '|'\t'|'\n'|'\r' -> true | _ -> false +let is_alphanum = function 'A'..'Z'|'a'..'z'|'_'|'\192'..'\214'|'\216'..'\246' + | '\248'..'\255'|'\''|'0'..'9' -> true + | _ -> false + +(* Remove "(" or "begin" before a pattern *) +let rec insertion_point pos ~text = + let pos' = ref (pos-1) in + while is_space text.[!pos'] do decr pos' done; + if text.[!pos'] = '(' then insertion_point !pos' ~text else + if !pos' >= 5 && String.sub text ~pos:(!pos'-4) ~len:5 = "begin" + && not (is_alphanum text.[!pos'-5]) then insertion_point (!pos'-4) ~text + else pos + +(* Search "=" or "->" before "function" *) +let rec insertion_point2 pos ~text = + let pos' = ref (pos-1) in + while is_space text.[!pos'] do decr pos' done; + if text.[!pos'] = '(' then insertion_point2 !pos' ~text else + if !pos' >= 5 && String.sub text ~pos:(!pos'-4) ~len:5 = "begin" + && not (is_alphanum text.[!pos'-5]) then insertion_point2 (!pos'-4) ~text + else if text.[!pos'] = '=' then Some !pos' else + if !pos' >= 1 && text.[!pos'-1] = '-' && text.[!pos'] = '>' + then Some (!pos' - 1) + else None + +let rec insert_labels ~labels ~text expr = + match labels, expr.pexp_desc with + l::labels, Pexp_function(l', _, [pat, rem]) -> + if l <> "" && l.[0] <> '?' && l' = "" then begin + let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in + let pos = insertion_point start_c ~text in + match pattern_name pat with + | Some name when l = name -> add_insertion pos "~" + | _ -> add_insertion pos ("~" ^ l ^ ":") + end; + insert_labels ~labels ~text rem + | l::labels, Pexp_function(l', _, lst) -> + let pos = expr.pexp_loc.Location.loc_start.Lexing.pos_cnum in + if l <> "" && l.[0] <> '?' && l' = "" + && String.sub text ~pos ~len:8 = "function" then begin + String.blit ~src:"match th" ~src_pos:0 ~dst:text + ~dst_pos:pos ~len:8; + add_insertion (pos+6) (l ^ " wi"); + match insertion_point2 pos ~text with + Some pos' -> + add_insertion pos' ("~" ^ l ^ " ") + | None -> + add_insertion pos ("fun ~" ^ l ^ " -> ") + end; + List.iter lst ~f:(fun (p,e) -> insert_labels ~labels ~text e) + | _, Pexp_match( _, lst) -> + List.iter lst ~f:(fun (p,e) -> insert_labels ~labels ~text e) + | _, Pexp_try(expr, lst) -> + insert_labels ~labels ~text expr; + List.iter lst ~f:(fun (p,e) -> insert_labels ~labels ~text e) + | _, ( Pexp_let(_,_,e) | Pexp_sequence(_,e) | Pexp_when(_,e) + | Pexp_constraint(e,_,_) | Pexp_letmodule(_,_,e) + | Pexp_ifthenelse(_,e,None) ) -> + insert_labels ~labels ~text e + | _, Pexp_ifthenelse (_, e1, Some e2) -> + insert_labels ~labels ~text e1; + insert_labels ~labels ~text e2 + | _ -> + () + +let rec insert_labels_class ~labels ~text expr = + match labels, expr.pcl_desc with + l::labels, Pcl_fun(l', _, pat, rem) -> + if l <> "" && l.[0] <> '?' && l' = "" then begin + let start_c = pat.ppat_loc.Location.loc_start.Lexing.pos_cnum in + let pos = insertion_point start_c ~text in + match pattern_name pat with + | Some name when l = name -> add_insertion pos "~" + | _ -> add_insertion pos ("~" ^ l ^ ":") + end; + insert_labels_class ~labels ~text rem + | labels, (Pcl_constraint (expr, _) | Pcl_let (_, _, expr)) -> + insert_labels_class ~labels ~text expr + | _ -> + () + +let rec insert_labels_type ~labels ~text ty = + match labels, ty.ptyp_desc with + l::labels, Ptyp_arrow(l', _, rem) -> + if l <> "" && l.[0] <> '?' && l' = "" then begin + let start_c = ty.ptyp_loc.Location.loc_start.Lexing.pos_cnum in + let pos = insertion_point start_c ~text in + add_insertion pos (l ^ ":") + end; + insert_labels_type ~labels ~text rem + | _ -> + () + +let rec insert_labels_app ~labels ~text args = + match labels, args with + l::labels, (l',arg)::args -> + if l <> "" && l.[0] <> '?' && l' = "" then begin + let pos0 = arg.pexp_loc.Location.loc_start.Lexing.pos_cnum in + let pos = insertion_point pos0 ~text in + match arg.pexp_desc with + | Pexp_ident(Longident.Lident name) when l = name && pos = pos0 -> + add_insertion pos "~" + | _ -> add_insertion pos ("~" ^ l ^ ":") + end; + insert_labels_app ~labels ~text args + | _ -> + () + +let insert_labels_app ~labels ~text args = + let labels, opt_labels = + List.partition labels ~f:(fun l -> l = "" || l.[0] <> '?') in + let nopt_labels = + List.map opt_labels + ~f:(fun l -> String.sub l ~pos:1 ~len:(String.length l - 1)) in + (* avoid ambiguous labels *) + if List.exists labels ~f:(List.mem ~set:nopt_labels) then () else + let aopt_labels = opt_labels @ nopt_labels in + let args, lab_args = List.partition args ~f:(fun (l,_) -> l = "") in + (* only optional arguments are labeled *) + if List.for_all lab_args ~f:(fun (l,_) -> List.mem l ~set:aopt_labels) + then insert_labels_app ~labels ~text args + +let rec add_labels_expr ~text ~values ~classes expr = + let add_labels_rec ?(values=values) expr = + add_labels_expr ~text ~values ~classes expr in + match expr.pexp_desc with + Pexp_apply ({pexp_desc=Pexp_ident(Longident.Lident s)}, args) -> + begin try + let labels = SMap.find s values in + insert_labels_app ~labels ~text args + with Not_found -> () + end; + List.iter args ~f:(fun (_,e) -> add_labels_rec e) + | Pexp_apply ({pexp_desc=Pexp_send + ({pexp_desc=Pexp_ident(Longident.Lident s)},meth)}, args) -> + begin try + if SMap.find s values = ["<object>"] then + let labels = SMap.find (s ^ "#" ^ meth) values in + insert_labels_app ~labels ~text args + with Not_found -> () + end + | Pexp_apply ({pexp_desc=Pexp_new (Longident.Lident s)}, args) -> + begin try + let labels = SMap.find s classes in + insert_labels_app ~labels ~text args + with Not_found -> () + end + | Pexp_let (recp, lst, expr) -> + let vars = List.concat (List.map lst ~f:(fun (p,_) -> pattern_vars p)) in + let vals = SMap.removes vars values in + List.iter lst ~f: + begin fun (_,e) -> + add_labels_rec e ~values:(if recp = Recursive then vals else values) + end; + add_labels_rec expr ~values:vals + | Pexp_function (_, None, lst) -> + List.iter lst ~f: + (fun (p,e) -> + add_labels_rec e ~values:(SMap.removes (pattern_vars p) values)) + | Pexp_function (_, Some e, lst) + | Pexp_match (e, lst) + | Pexp_try (e, lst) -> + add_labels_rec e; + List.iter lst ~f: + (fun (p,e) -> + add_labels_rec e ~values:(SMap.removes (pattern_vars p) values)) + | Pexp_apply (e, args) -> + List.iter add_labels_rec (e :: List.map snd args) + | Pexp_tuple l | Pexp_array l -> + List.iter add_labels_rec l + | Pexp_construct (_, Some e, _) + | Pexp_variant (_, Some e) + | Pexp_field (e, _) + | Pexp_constraint (e, _, _) + | Pexp_send (e, _) + | Pexp_setinstvar (_, e) + | Pexp_letmodule (_, _, e) + | Pexp_assert e + | Pexp_lazy e + | Pexp_poly (e, _) -> + add_labels_rec e + | Pexp_record (lst, opt) -> + List.iter lst ~f:(fun (_,e) -> add_labels_rec e); + begin match opt with Some e -> add_labels_rec e | None -> () end + | Pexp_setfield (e1, _, e2) + | Pexp_ifthenelse (e1, e2, None) + | Pexp_sequence (e1, e2) + | Pexp_while (e1, e2) + | Pexp_when (e1, e2) -> + add_labels_rec e1; add_labels_rec e2 + | Pexp_ifthenelse (e1, e2, Some e3) -> + add_labels_rec e1; add_labels_rec e2; add_labels_rec e3 + | Pexp_for (s, e1, e2, _, e3) -> + add_labels_rec e1; add_labels_rec e2; + add_labels_rec e3 ~values:(SMap.removes [s] values) + | Pexp_override lst -> + List.iter lst ~f:(fun (_,e) -> add_labels_rec e) + | Pexp_ident _ | Pexp_constant _ | Pexp_construct _ | Pexp_variant _ + | Pexp_new _ | Pexp_assertfalse | Pexp_object _ -> + () + +let rec add_labels_class ~text ~classes ~values ~methods cl = + match cl.pcl_desc with + Pcl_constr _ -> () + | Pcl_structure (p, l) -> + let values = SMap.removes (pattern_vars p) values in + let values = + match pattern_name p with None -> values + | Some s -> + List.fold_left methods + ~init:(SMap.add s ["<object>"] values) + ~f:(fun m (k,l) -> SMap.add (s^"#"^k) l m) + in + List.fold_left l ~init:values ~f: + begin fun values -> function + | Pcf_val (s, _, e, _) -> + add_labels_expr ~text ~classes ~values e; + SMap.removes [s] values + | Pcf_meth (s, _, e, _) -> + begin try + let labels = List.assoc s methods in + insert_labels ~labels ~text e + with Not_found -> () + end; + add_labels_expr ~text ~classes ~values e; + values + | Pcf_init e -> + add_labels_expr ~text ~classes ~values e; + values + | Pcf_inher _ | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> values + | Pcf_let _ -> values (* not in the grammar *) + end; + () + | Pcl_fun (_, opt, pat, cl) -> + begin match opt with None -> () + | Some e -> add_labels_expr ~text ~classes ~values e + end; + let values = SMap.removes (pattern_vars pat) values in + add_labels_class ~text ~classes ~values ~methods cl + | Pcl_apply (cl, args) -> + List.map args ~f:(fun (_,e) -> add_labels_expr ~text ~classes ~values e); + add_labels_class ~text ~classes ~values ~methods cl + | Pcl_let (recp, lst, cl) -> + let vars = List.concat (List.map lst ~f:(fun (p,_) -> pattern_vars p)) in + let vals = SMap.removes vars values in + List.iter lst ~f: + begin fun (_,e) -> + add_labels_expr e ~text ~classes + ~values:(if recp = Recursive then vals else values) + end; + add_labels_class cl ~text ~classes ~values:vals ~methods + | Pcl_constraint (cl, _) -> + add_labels_class ~text ~classes ~values ~methods cl + +let add_labels ~intf ~impl ~file = + insertions := []; + let values, classes = + List.fold_left intf ~init:(SMap.empty, SMap.empty) ~f: + begin fun (values, classes as acc) item -> + match item.psig_desc with + Psig_value (name, {pval_type = sty}) -> + (SMap.add name (labels_of_sty sty) values, classes) + | Psig_class l -> + (values, + List.fold_left l ~init:classes ~f: + begin fun classes {pci_name=name; pci_expr=cty} -> + SMap.add name (labels_of_cty cty) classes + end) + | _ -> + acc + end + in + let text = input_file file in + List.fold_right impl ~init:(values, classes) ~f: + begin fun item (values, classes as acc) -> + match item.pstr_desc with + Pstr_value (recp, l) -> + let names = + List.concat (List.map l ~f:(fun (p,_) -> pattern_vars p)) in + List.iter l ~f: + begin fun (pat, expr) -> + begin match pattern_name pat with + | Some s -> + begin try + let labels = SMap.find s values in + insert_labels ~labels ~text expr; + if !norec then () else + let values = + SMap.fold + (fun s l m -> + if List.mem s names then SMap.add s l m else m) + values SMap.empty in + add_labels_expr expr ~text ~values ~classes:SMap.empty + with Not_found -> () + end + | None -> () + end; + end; + (SMap.removes names values, classes) + | Pstr_primitive (s, {pval_type=sty}) -> + begin try + let labels = SMap.find s values in + insert_labels_type ~labels ~text sty; + (SMap.removes [s] values, classes) + with Not_found -> acc + end + | Pstr_class l -> + let names = List.map l ~f:(fun pci -> pci.pci_name) in + List.iter l ~f: + begin fun {pci_name=name; pci_expr=expr} -> + try + let (labels, methods) = SMap.find name classes in + insert_labels_class ~labels ~text expr; + if !norec then () else + let classes = + SMap.fold + (fun s (l,_) m -> + if List.mem s names then SMap.add s l m else m) + classes SMap.empty in + add_labels_class expr ~text ~classes ~methods + ~values:SMap.empty + with Not_found -> () + end; + (values, SMap.removes names classes) + | _ -> + acc + end; + if !insertions <> [] then begin + let backup = file ^ ".bak" in + if Sys.file_exists backup then Sys.remove file + else Sys.rename file backup; + let oc = open_out file in + let last_pos = + List.fold_left (sort_insertions ()) ~init:0 ~f: + begin fun pos (pos', s) -> + output oc text pos (pos'-pos); + output_string oc s; + pos' + end in + if last_pos < String.length text then + output oc text last_pos (String.length text - last_pos); + close_out oc + end + else prerr_endline ("No labels to insert in " ^ file) + +let process_file file = + prerr_endline ("Processing " ^ file); + if Filename.check_suffix file ".ml" then + let intf = Filename.chop_suffix file ".ml" ^ ".mli" in + let ic = open_in intf in + let lexbuf = Lexing.from_channel ic in + Location.init lexbuf intf; + let intf = Parse.interface lexbuf in + close_in ic; + let ic = open_in file in + let lexbuf = Lexing.from_channel ic in + Location.init lexbuf file; + let impl = Parse.implementation lexbuf in + close_in ic; + add_labels ~intf ~impl ~file + else prerr_endline (file ^ " is not an implementation") + +let main () = + let files = ref [] in + Arg.parse ["-norec", Arg.Set norec, "do not labelize recursive calls"] + (fun f -> files := f :: !files) + "addlabels [-norec] <files>"; + let files = List.rev !files in + List.iter files ~f:process_file + +let () = main () diff --git a/tools/checkstack.c b/tools/checkstack.c new file mode 100644 index 0000000..20b2439 --- /dev/null +++ b/tools/checkstack.c @@ -0,0 +1,42 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Moscova, INRIA Rocquencourt */ +/* */ +/* Copyright 2002 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: checkstack.c,v 1.3 2006-04-16 23:28:21 doligez Exp $ */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> + +#define MINSTACKBYTES (384 * 1024 * sizeof (long)) + +int main(int argc, char ** argv) +{ + struct rlimit limit; + int rc; + + rc = getrlimit (RLIMIT_STACK, &limit); + if (rc != 0) exit (0); + if (limit.rlim_cur < MINSTACKBYTES){ + fprintf (stderr, + "\nThe current stack size limit is too low (%luk)\n" + "You must increase it with one of the following commands:\n" + "Under sh, bash, zsh: ulimit -s %lu\n" + "Under csh, tcsh: limit stacksize %lu\n\n", + (unsigned long) (limit.rlim_cur / 1024), + MINSTACKBYTES / 1024, MINSTACKBYTES / 1024); + exit (3); + } + exit (0); +} diff --git a/tools/cleanup-header b/tools/cleanup-header new file mode 100644 index 0000000..9c21475 --- /dev/null +++ b/tools/cleanup-header @@ -0,0 +1,15 @@ +#!/bin/sed -f +# Remove private parts from runtime include files, before installation +# in /usr/local/lib/ocaml/caml + +/\/\* <include \.\.\/config\/m\.h> \*\// { + r ../config/m.h + d +} +/\/\* <include \.\.\/config\/s\.h> \*\// { + r ../config/s.h + d +} +/\/\* <private> \*\//,/\/\* <\/private> \*\//d + + diff --git a/tools/cvt_emit.mll b/tools/cvt_emit.mll new file mode 100644 index 0000000..5307787 --- /dev/null +++ b/tools/cvt_emit.mll @@ -0,0 +1,84 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: cvt_emit.mll,v 1.4 2000-10-02 14:17:55 maranget Exp $ *) + +{ +let first_item = ref false +let command_beginning = ref 0 + +let add_semicolon () = + if !first_item + then first_item := false + else print_string "; " + +let print_unescaped_string s = + let l = String.length s in + let i = ref 0 in + while !i < l do + if s.[!i] = '\\' + && !i+1 < l + && (let c = s.[!i+1] in c = '{' || c = '`') (* ` *) + then i := !i+1; + print_char s.[!i]; + i := !i + 1 + done +} + +rule main = parse + "`" { command_beginning := Lexing.lexeme_start lexbuf; + first_item := true; + print_char '('; + command lexbuf; + print_char ')'; + main lexbuf } + | "\\`" + { print_string "`"; main lexbuf } + | eof { () } + | _ { print_char(Lexing.lexeme_char lexbuf 0); main lexbuf } + +and command = parse + "`" { () } + | eof { prerr_string "Unterminated `...` at character "; + prerr_int !command_beginning; + prerr_newline(); + exit 2 } + | "{" [^ '}'] * "}" + { let s = Lexing.lexeme lexbuf in + add_semicolon(); + print_string (String.sub s 1 (String.length s - 2)); + command lexbuf } + | ( [^ '`' '{' '\\'] | + '\\' ['\\' '"' 'n' 't' 'b' 'r' '`' '{' ] | + '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] ) + + { let s = Lexing.lexeme lexbuf in + add_semicolon(); + (* Optimise one-character strings *) + if String.length s = 1 && s.[0] <> '\\' && s.[0] <> '\'' + || String.length s = 2 && s.[0] = '\\' && s.[1] <> '`' && s.[1]<>'{' + (* ` *) + then begin + print_string "emit_char '"; + print_unescaped_string s; + print_string "'" + end else begin + print_string "emit_string \""; + print_unescaped_string s; + print_string "\"" + end; + command lexbuf } + +{ +let _ = main(Lexing.from_channel stdin) + +let _ = exit (0) +} diff --git a/tools/depend.ml b/tools/depend.ml new file mode 100644 index 0000000..b166f2b --- /dev/null +++ b/tools/depend.ml @@ -0,0 +1,293 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: depend.ml,v 1.13 2008-07-09 13:03:37 mauny Exp $ *) + +open Format +open Location +open Longident +open Parsetree + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +(* Collect free module identifiers in the a.s.t. *) + +let free_structure_names = ref StringSet.empty + +let rec addmodule bv lid = + match lid with + Lident s -> + if not (StringSet.mem s bv) + then free_structure_names := StringSet.add s !free_structure_names + | Ldot(l, s) -> addmodule bv l + | Lapply(l1, l2) -> addmodule bv l1; addmodule bv l2 + +let add bv lid = + match lid with + Ldot(l, s) -> addmodule bv l + | _ -> () + +let rec add_type bv ty = + match ty.ptyp_desc with + Ptyp_any -> () + | Ptyp_var v -> () + | Ptyp_arrow(_, t1, t2) -> add_type bv t1; add_type bv t2 + | Ptyp_tuple tl -> List.iter (add_type bv) tl + | Ptyp_constr(c, tl) -> add bv c; List.iter (add_type bv) tl + | Ptyp_object fl -> List.iter (add_field_type bv) fl + | Ptyp_class(c, tl, _) -> add bv c; List.iter (add_type bv) tl + | Ptyp_alias(t, s) -> add_type bv t + | Ptyp_variant(fl, _, _) -> + List.iter + (function Rtag(_,_,stl) -> List.iter (add_type bv) stl + | Rinherit sty -> add_type bv sty) + fl + | Ptyp_poly(_, t) -> add_type bv t + +and add_field_type bv ft = + match ft.pfield_desc with + Pfield(name, ty) -> add_type bv ty + | Pfield_var -> () + +let add_opt add_fn bv = function + None -> () + | Some x -> add_fn bv x + +let add_type_declaration bv td = + List.iter + (fun (ty1, ty2, _) -> add_type bv ty1; add_type bv ty2) + td.ptype_cstrs; + add_opt add_type bv td.ptype_manifest; + let rec add_tkind = function + Ptype_abstract -> () + | Ptype_variant cstrs -> + List.iter (fun (c, args, _) -> List.iter (add_type bv) args) cstrs + | Ptype_record lbls -> + List.iter (fun (l, mut, ty, _) -> add_type bv ty) lbls in + add_tkind td.ptype_kind + +let rec add_class_type bv cty = + match cty.pcty_desc with + Pcty_constr(l, tyl) -> + add bv l; List.iter (add_type bv) tyl + | Pcty_signature (ty, fieldl) -> + add_type bv ty; + List.iter (add_class_type_field bv) fieldl + | Pcty_fun(_, ty1, cty2) -> + add_type bv ty1; add_class_type bv cty2 + +and add_class_type_field bv = function + Pctf_inher cty -> add_class_type bv cty + | Pctf_val(_, _, _, ty, _) -> add_type bv ty + | Pctf_virt(_, _, ty, _) -> add_type bv ty + | Pctf_meth(_, _, ty, _) -> add_type bv ty + | Pctf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 + +let add_class_description bv infos = + add_class_type bv infos.pci_expr + +let add_class_type_declaration = add_class_description + +let rec add_pattern bv pat = + match pat.ppat_desc with + Ppat_any -> () + | Ppat_var _ -> () + | Ppat_alias(p, _) -> add_pattern bv p + | Ppat_constant _ -> () + | Ppat_tuple pl -> List.iter (add_pattern bv) pl + | Ppat_construct(c, op, _) -> add bv c; add_opt add_pattern bv op + | Ppat_record pl -> + List.iter (fun (lbl, p) -> add bv lbl; add_pattern bv p) pl + | Ppat_array pl -> List.iter (add_pattern bv) pl + | Ppat_or(p1, p2) -> add_pattern bv p1; add_pattern bv p2 + | Ppat_constraint(p, ty) -> add_pattern bv p; add_type bv ty + | Ppat_variant(_, op) -> add_opt add_pattern bv op + | Ppat_type (li) -> add bv li + | Ppat_lazy p -> add_pattern bv p + +let rec add_expr bv exp = + match exp.pexp_desc with + Pexp_ident l -> add bv l + | Pexp_constant _ -> () + | Pexp_let(_, pel, e) -> add_pat_expr_list bv pel; add_expr bv e + | Pexp_function (_, opte, pel) -> + add_opt add_expr bv opte; add_pat_expr_list bv pel + | Pexp_apply(e, el) -> + add_expr bv e; List.iter (fun (_,e) -> add_expr bv e) el + | Pexp_match(e, pel) -> add_expr bv e; add_pat_expr_list bv pel + | Pexp_try(e, pel) -> add_expr bv e; add_pat_expr_list bv pel + | Pexp_tuple el -> List.iter (add_expr bv) el + | Pexp_construct(c, opte, _) -> add bv c; add_opt add_expr bv opte + | Pexp_variant(_, opte) -> add_opt add_expr bv opte + | Pexp_record(lblel, opte) -> + List.iter (fun (lbl, e) -> add bv lbl; add_expr bv e) lblel; + add_opt add_expr bv opte + | Pexp_field(e, fld) -> add_expr bv e; add bv fld + | Pexp_setfield(e1, fld, e2) -> add_expr bv e1; add bv fld; add_expr bv e2 + | Pexp_array el -> List.iter (add_expr bv) el + | Pexp_ifthenelse(e1, e2, opte3) -> + add_expr bv e1; add_expr bv e2; add_opt add_expr bv opte3 + | Pexp_sequence(e1, e2) -> add_expr bv e1; add_expr bv e2 + | Pexp_while(e1, e2) -> add_expr bv e1; add_expr bv e2 + | Pexp_for(_, e1, e2, _, e3) -> + add_expr bv e1; add_expr bv e2; add_expr bv e3 + | Pexp_constraint(e1, oty2, oty3) -> + add_expr bv e1; + add_opt add_type bv oty2; + add_opt add_type bv oty3 + | Pexp_when(e1, e2) -> add_expr bv e1; add_expr bv e2 + | Pexp_send(e, m) -> add_expr bv e + | Pexp_new l -> add bv l + | Pexp_setinstvar(v, e) -> add_expr bv e + | Pexp_override sel -> List.iter (fun (s, e) -> add_expr bv e) sel + | Pexp_letmodule(id, m, e) -> + add_module bv m; add_expr (StringSet.add id bv) e + | Pexp_assert (e) -> add_expr bv e + | Pexp_assertfalse -> () + | Pexp_lazy (e) -> add_expr bv e + | Pexp_poly (e, t) -> add_expr bv e; add_opt add_type bv t + | Pexp_object (pat, fieldl) -> + add_pattern bv pat; List.iter (add_class_field bv) fieldl +and add_pat_expr_list bv pel = + List.iter (fun (p, e) -> add_pattern bv p; add_expr bv e) pel + +and add_modtype bv mty = + match mty.pmty_desc with + Pmty_ident l -> add bv l + | Pmty_signature s -> add_signature bv s + | Pmty_functor(id, mty1, mty2) -> + add_modtype bv mty1; add_modtype (StringSet.add id bv) mty2 + | Pmty_with(mty, cstrl) -> + add_modtype bv mty; + List.iter + (function (_, Pwith_type td) -> add_type_declaration bv td + | (_, Pwith_module lid) -> addmodule bv lid) + cstrl + +and add_signature bv = function + [] -> () + | item :: rem -> add_signature (add_sig_item bv item) rem + +and add_sig_item bv item = + match item.psig_desc with + Psig_value(id, vd) -> + add_type bv vd.pval_type; bv + | Psig_type dcls -> + List.iter (fun (id, td) -> add_type_declaration bv td) dcls; bv + | Psig_exception(id, args) -> + List.iter (add_type bv) args; bv + | Psig_module(id, mty) -> + add_modtype bv mty; StringSet.add id bv + | Psig_recmodule decls -> + let bv' = List.fold_right StringSet.add (List.map fst decls) bv in + List.iter (fun (id, mty) -> add_modtype bv' mty) decls; + bv' + | Psig_modtype(id, mtyd) -> + begin match mtyd with + Pmodtype_abstract -> () + | Pmodtype_manifest mty -> add_modtype bv mty + end; + bv + | Psig_open lid -> + addmodule bv lid; bv + | Psig_include mty -> + add_modtype bv mty; bv + | Psig_class cdl -> + List.iter (add_class_description bv) cdl; bv + | Psig_class_type cdtl -> + List.iter (add_class_type_declaration bv) cdtl; bv + +and add_module bv modl = + match modl.pmod_desc with + Pmod_ident l -> addmodule bv l + | Pmod_structure s -> ignore (add_structure bv s) + | Pmod_functor(id, mty, modl) -> + add_modtype bv mty; + add_module (StringSet.add id bv) modl + | Pmod_apply(mod1, mod2) -> + add_module bv mod1; add_module bv mod2 + | Pmod_constraint(modl, mty) -> + add_module bv modl; add_modtype bv mty + +and add_structure bv item_list = + List.fold_left add_struct_item bv item_list + +and add_struct_item bv item = + match item.pstr_desc with + Pstr_eval e -> + add_expr bv e; bv + | Pstr_value(id, pel) -> + add_pat_expr_list bv pel; bv + | Pstr_primitive(id, vd) -> + add_type bv vd.pval_type; bv + | Pstr_type dcls -> + List.iter (fun (id, td) -> add_type_declaration bv td) dcls; bv + | Pstr_exception(id, args) -> + List.iter (add_type bv) args; bv + | Pstr_exn_rebind(id, l) -> + add bv l; bv + | Pstr_module(id, modl) -> + add_module bv modl; StringSet.add id bv + | Pstr_recmodule bindings -> + let bv' = + List.fold_right StringSet.add + (List.map (fun (id,_,_) -> id) bindings) bv in + List.iter + (fun (id, mty, modl) -> add_modtype bv' mty; add_module bv' modl) + bindings; + bv' + | Pstr_modtype(id, mty) -> + add_modtype bv mty; bv + | Pstr_open l -> + addmodule bv l; bv + | Pstr_class cdl -> + List.iter (add_class_declaration bv) cdl; bv + | Pstr_class_type cdtl -> + List.iter (add_class_type_declaration bv) cdtl; bv + | Pstr_include modl -> + add_module bv modl; bv + +and add_use_file bv top_phrs = + ignore (List.fold_left add_top_phrase bv top_phrs) + +and add_top_phrase bv = function + | Ptop_def str -> add_structure bv str + | Ptop_dir (_, _) -> bv + +and add_class_expr bv ce = + match ce.pcl_desc with + Pcl_constr(l, tyl) -> + add bv l; List.iter (add_type bv) tyl + | Pcl_structure(pat, fieldl) -> + add_pattern bv pat; List.iter (add_class_field bv) fieldl + | Pcl_fun(_, opte, pat, ce) -> + add_opt add_expr bv opte; add_pattern bv pat; add_class_expr bv ce + | Pcl_apply(ce, exprl) -> + add_class_expr bv ce; List.iter (fun (_,e) -> add_expr bv e) exprl + | Pcl_let(_, pel, ce) -> + add_pat_expr_list bv pel; add_class_expr bv ce + | Pcl_constraint(ce, ct) -> + add_class_expr bv ce; add_class_type bv ct + +and add_class_field bv = function + Pcf_inher(ce, _) -> add_class_expr bv ce + | Pcf_val(_, _, e, _) -> add_expr bv e + | Pcf_valvirt(_, _, ty, _) + | Pcf_virt(_, _, ty, _) -> add_type bv ty + | Pcf_meth(_, _, e, _) -> add_expr bv e + | Pcf_cstr(ty1, ty2, _) -> add_type bv ty1; add_type bv ty2 + | Pcf_let(_, pel, _) -> add_pat_expr_list bv pel + | Pcf_init e -> add_expr bv e + +and add_class_declaration bv decl = + add_class_expr bv decl.pci_expr + diff --git a/tools/depend.mli b/tools/depend.mli new file mode 100644 index 0000000..7fca97c --- /dev/null +++ b/tools/depend.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: depend.mli,v 1.2 2002-04-18 07:27:43 garrigue Exp $ *) + +(** Module dependencies. *) + +module StringSet : Set.S with type elt = string + +val free_structure_names : StringSet.t ref + +val add_use_file : StringSet.t -> Parsetree.toplevel_phrase list -> unit + +val add_signature : StringSet.t -> Parsetree.signature -> unit diff --git a/tools/dumpapprox.ml b/tools/dumpapprox.ml new file mode 100644 index 0000000..7547f5b --- /dev/null +++ b/tools/dumpapprox.ml @@ -0,0 +1,100 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: dumpapprox.ml,v 1.15 2003-03-06 16:00:16 xleroy Exp $ *) + +(* Dump a .cmx file *) + +open Config +open Format +open Clambda +open Compilenv + +let print_digest ppf d = + for i = 0 to String.length d - 1 do + print_string(Printf.sprintf "%02x" (Char.code d.[i])) + done + +let rec print_approx ppf = function + Value_closure(fundesc, approx) -> + printf "@[<2>function %s@ arity %i" fundesc.fun_label fundesc.fun_arity; + if fundesc.fun_closed then begin + printf "@ (closed)" + end; + if fundesc.fun_inline <> None then begin + printf "@ (inline)" + end; + printf "@ -> @ %a@]" print_approx approx + | Value_tuple approx -> + let tuple ppf approx = + for i = 0 to Array.length approx - 1 do + if i > 0 then printf ";@ "; + printf "%i: %a" i print_approx approx.(i) + done in + printf "@[<hov 1>(%a)@]" tuple approx + | Value_unknown -> + print_string "_" + | Value_integer n -> + print_int n + | Value_constptr n -> + print_int n; print_string "p" + +let print_name_crc (name, crc) = + printf "@ %s (%a)" name print_digest crc + +let print_infos (ui, crc) = + printf "Name: %s@." ui.ui_name; + printf "CRC of implementation: %a@." print_digest crc; + printf "@[<hov 2>Globals defined:"; + List.iter (fun s -> printf "@ %s" s) ui.ui_defines; + printf "@]@."; + let pr_imports ppf imps = List.iter print_name_crc imps in + printf "@[<v 2>Interfaces imported:%a@]@." pr_imports ui.ui_imports_cmi; + printf "@[<v 2>Implementations imported:%a@]@." pr_imports ui.ui_imports_cmx; + printf "@[<v 2>Approximation:@ %a@]@." print_approx ui.ui_approx; + let pr_funs ppf fns = + List.iter (fun arity -> printf "@ %i" arity) fns in + printf "@[<2>Currying functions:%a@]@." pr_funs ui.ui_curry_fun; + printf "@[<2>Apply functions:%a@]@." pr_funs ui.ui_apply_fun + +let print_unit_info filename = + let ic = open_in_bin filename in + try + let buffer = String.create (String.length cmx_magic_number) in + really_input ic buffer 0 (String.length cmx_magic_number); + if buffer = cmx_magic_number then begin + let ui = (input_value ic : unit_infos) in + let crc = Digest.input ic in + close_in ic; + print_infos (ui, crc) + end else if buffer = cmxa_magic_number then begin + let li = (input_value ic : library_infos) in + close_in ic; + List.iter print_infos li.lib_units + end else begin + close_in ic; + prerr_endline "Wrong magic number"; + exit 2 + end + with End_of_file | Failure _ -> + close_in ic; + prerr_endline "Error reading file"; + exit 2 + +let main () = + print_unit_info Sys.argv.(1); + exit 0 + +let _ = main () + + + diff --git a/tools/dumpobj.ml b/tools/dumpobj.ml new file mode 100644 index 0000000..687d8ca --- /dev/null +++ b/tools/dumpobj.ml @@ -0,0 +1,560 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: dumpobj.ml,v 1.38 2008-09-10 12:53:05 doligez Exp $ *) + +(* Disassembler for executable and .cmo object files *) + +open Asttypes +open Config +open Emitcode +open Instruct +open Lambda +open Location +open Obj +open Opcodes +open Opnames +open Cmo_format +open Printf + +(* Read signed and unsigned integers *) + +let inputu ic = + let b1 = input_byte ic in + let b2 = input_byte ic in + let b3 = input_byte ic in + let b4 = input_byte ic in + (b4 lsl 24) + (b3 lsl 16) + (b2 lsl 8) + b1 + +let inputs ic = + let b1 = input_byte ic in + let b2 = input_byte ic in + let b3 = input_byte ic in + let b4 = input_byte ic in + let b4' = if b4 >= 128 then b4-256 else b4 in + (b4' lsl 24) + (b3 lsl 16) + (b2 lsl 8) + b1 + +(* Global variables *) + +type global_table_entry = + Empty + | Global of Ident.t + | Constant of Obj.t + +let start = ref 0 (* Position of beg. of code *) +let reloc = ref ([] : (reloc_info * int) list) (* Relocation table *) +let globals = ref ([||] : global_table_entry array) (* Global map *) +let primitives = ref ([||] : string array) (* Table of primitives *) +let objfile = ref false (* true if dumping a .cmo *) + +(* Events (indexed by PC) *) + +let event_table = (Hashtbl.create 253 : (int, debug_event) Hashtbl.t) + +let relocate_event orig ev = + ev.ev_pos <- orig + ev.ev_pos; + match ev.ev_repr with + Event_parent repr -> repr := ev.ev_pos + | _ -> () + +let record_events orig evl = + List.iter + (fun ev -> + relocate_event orig ev; + Hashtbl.add event_table ev.ev_pos ev) + evl + +(* Print a structured constant *) + +let print_float f = + if String.contains f '.' + then printf "%s" f + else printf "%s." f +;; + +let rec print_struct_const = function + Const_base(Const_int i) -> printf "%d" i + | Const_base(Const_float f) -> print_float f + | Const_base(Const_string s) -> printf "%S" s + | Const_immstring s -> printf "%S" s + | Const_base(Const_char c) -> printf "%C" c + | Const_base(Const_int32 i) -> printf "%ldl" i + | Const_base(Const_nativeint i) -> printf "%ndn" i + | Const_base(Const_int64 i) -> printf "%LdL" i + | Const_pointer n -> printf "%da" n + | Const_block(tag, args) -> + printf "<%d>" tag; + begin match args with + [] -> () + | [a1] -> + printf "("; print_struct_const a1; printf ")" + | a1::al -> + printf "("; print_struct_const a1; + List.iter (fun a -> printf ", "; print_struct_const a) al; + printf ")" + end + | Const_float_array a -> + printf "[|"; + List.iter (fun f -> print_float f; printf "; ") a; + printf "|]" + +(* Print an obj *) + +let same_custom x y = + Obj.field x 0 = Obj.field (Obj.repr y) 0 + +let rec print_obj x = + if Obj.is_block x then begin + let tag = Obj.tag x in + if tag = Obj.string_tag then + printf "%S" (Obj.magic x : string) + else if tag = Obj.double_tag then + printf "%.12g" (Obj.magic x : float) + else if tag = Obj.double_array_tag then begin + let a = (Obj.magic x : float array) in + printf "[|"; + for i = 0 to Array.length a - 1 do + if i > 0 then printf ", "; + printf "%.12g" a.(i) + done; + printf "|]" + end else if tag = Obj.custom_tag && same_custom x 0l then + printf "%ldl" (Obj.magic x : int32) + else if tag = Obj.custom_tag && same_custom x 0n then + printf "%ndn" (Obj.magic x : nativeint) + else if tag = Obj.custom_tag && same_custom x 0L then + printf "%LdL" (Obj.magic x : int64) + else if tag < Obj.no_scan_tag then begin + printf "<%d>" (Obj.tag x); + match Obj.size x with + 0 -> () + | 1 -> + printf "("; print_obj (Obj.field x 0); printf ")" + | n -> + printf "("; print_obj (Obj.field x 0); + for i = 1 to n - 1 do + printf ", "; print_obj (Obj.field x i) + done; + printf ")" + end else + printf "<tag %d>" tag + end else + printf "%d" (Obj.magic x : int) + +(* Current position in input file *) + +let currpos ic = + pos_in ic - !start + +(* Access in the relocation table *) + +let rec rassoc key = function + [] -> raise Not_found + | (a,b) :: l -> if b = key then a else rassoc key l + +let find_reloc ic = + rassoc (pos_in ic - !start) !reloc + +(* Symbolic printing of global names, etc *) + +let print_getglobal_name ic = + if !objfile then begin + begin try + match find_reloc ic with + Reloc_getglobal id -> print_string (Ident.name id) + | Reloc_literal sc -> print_struct_const sc + | _ -> print_string "<wrong reloc>" + with Not_found -> + print_string "<no reloc>" + end; + ignore (inputu ic); + end + else begin + let n = inputu ic in + if n >= Array.length !globals || n < 0 + then print_string "<global table overflow>" + else match !globals.(n) with + Global id -> print_string(Ident.name id) + | Constant obj -> print_obj obj + | _ -> print_string "???" + end + +let print_setglobal_name ic = + if !objfile then begin + begin try + match find_reloc ic with + Reloc_setglobal id -> print_string (Ident.name id) + | _ -> print_string "<wrong reloc>" + with Not_found -> + print_string "<no reloc>" + end; + ignore (inputu ic); + end + else begin + let n = inputu ic in + if n >= Array.length !globals || n < 0 + then print_string "<global table overflow>" + else match !globals.(n) with + Global id -> print_string(Ident.name id) + | _ -> print_string "???" + end + +let print_primitive ic = + if !objfile then begin + begin try + match find_reloc ic with + Reloc_primitive s -> print_string s + | _ -> print_string "<wrong reloc>" + with Not_found -> + print_string "<no reloc>" + end; + ignore (inputu ic); + end + else begin + let n = inputu ic in + if n >= Array.length !primitives || n < 0 + then print_int n + else print_string !primitives.(n) + end + +(* Disassemble one instruction *) + +let currpc ic = + currpos ic / 4 + +type shape = + | Nothing + | Uint + | Sint + | Uint_Uint + | Disp + | Uint_Disp + | Sint_Disp + | Getglobal + | Getglobal_Uint + | Setglobal + | Primitive + | Uint_Primitive + | Switch + | Closurerec + | Pubmet +;; + +let op_shapes = [ + opACC0, Nothing; + opACC1, Nothing; + opACC2, Nothing; + opACC3, Nothing; + opACC4, Nothing; + opACC5, Nothing; + opACC6, Nothing; + opACC7, Nothing; + opACC, Uint; + opPUSH, Nothing; + opPUSHACC0, Nothing; + opPUSHACC1, Nothing; + opPUSHACC2, Nothing; + opPUSHACC3, Nothing; + opPUSHACC4, Nothing; + opPUSHACC5, Nothing; + opPUSHACC6, Nothing; + opPUSHACC7, Nothing; + opPUSHACC, Uint; + opPOP, Uint; + opASSIGN, Uint; + opENVACC1, Nothing; + opENVACC2, Nothing; + opENVACC3, Nothing; + opENVACC4, Nothing; + opENVACC, Uint; + opPUSHENVACC1, Nothing; + opPUSHENVACC2, Nothing; + opPUSHENVACC3, Nothing; + opPUSHENVACC4, Nothing; + opPUSHENVACC, Uint; + opPUSH_RETADDR, Disp; + opAPPLY, Uint; + opAPPLY1, Nothing; + opAPPLY2, Nothing; + opAPPLY3, Nothing; + opAPPTERM, Uint_Uint; + opAPPTERM1, Uint; + opAPPTERM2, Uint; + opAPPTERM3, Uint; + opRETURN, Uint; + opRESTART, Nothing; + opGRAB, Uint; + opCLOSURE, Uint_Disp; + opCLOSUREREC, Closurerec; + opOFFSETCLOSUREM2, Nothing; + opOFFSETCLOSURE0, Nothing; + opOFFSETCLOSURE2, Nothing; + opOFFSETCLOSURE, Sint; (* was Uint *) + opPUSHOFFSETCLOSUREM2, Nothing; + opPUSHOFFSETCLOSURE0, Nothing; + opPUSHOFFSETCLOSURE2, Nothing; + opPUSHOFFSETCLOSURE, Sint; (* was Nothing *) + opGETGLOBAL, Getglobal; + opPUSHGETGLOBAL, Getglobal; + opGETGLOBALFIELD, Getglobal_Uint; + opPUSHGETGLOBALFIELD, Getglobal_Uint; + opSETGLOBAL, Setglobal; + opATOM0, Nothing; + opATOM, Uint; + opPUSHATOM0, Nothing; + opPUSHATOM, Uint; + opMAKEBLOCK, Uint_Uint; + opMAKEBLOCK1, Uint; + opMAKEBLOCK2, Uint; + opMAKEBLOCK3, Uint; + opMAKEFLOATBLOCK, Uint; + opGETFIELD0, Nothing; + opGETFIELD1, Nothing; + opGETFIELD2, Nothing; + opGETFIELD3, Nothing; + opGETFIELD, Uint; + opGETFLOATFIELD, Uint; + opSETFIELD0, Nothing; + opSETFIELD1, Nothing; + opSETFIELD2, Nothing; + opSETFIELD3, Nothing; + opSETFIELD, Uint; + opSETFLOATFIELD, Uint; + opVECTLENGTH, Nothing; + opGETVECTITEM, Nothing; + opSETVECTITEM, Nothing; + opGETSTRINGCHAR, Nothing; + opSETSTRINGCHAR, Nothing; + opBRANCH, Disp; + opBRANCHIF, Disp; + opBRANCHIFNOT, Disp; + opSWITCH, Switch; + opBOOLNOT, Nothing; + opPUSHTRAP, Disp; + opPOPTRAP, Nothing; + opRAISE, Nothing; + opCHECK_SIGNALS, Nothing; + opC_CALL1, Primitive; + opC_CALL2, Primitive; + opC_CALL3, Primitive; + opC_CALL4, Primitive; + opC_CALL5, Primitive; + opC_CALLN, Uint_Primitive; + opCONST0, Nothing; + opCONST1, Nothing; + opCONST2, Nothing; + opCONST3, Nothing; + opCONSTINT, Sint; + opPUSHCONST0, Nothing; + opPUSHCONST1, Nothing; + opPUSHCONST2, Nothing; + opPUSHCONST3, Nothing; + opPUSHCONSTINT, Sint; + opNEGINT, Nothing; + opADDINT, Nothing; + opSUBINT, Nothing; + opMULINT, Nothing; + opDIVINT, Nothing; + opMODINT, Nothing; + opANDINT, Nothing; + opORINT, Nothing; + opXORINT, Nothing; + opLSLINT, Nothing; + opLSRINT, Nothing; + opASRINT, Nothing; + opEQ, Nothing; + opNEQ, Nothing; + opLTINT, Nothing; + opLEINT, Nothing; + opGTINT, Nothing; + opGEINT, Nothing; + opOFFSETINT, Sint; + opOFFSETREF, Sint; + opISINT, Nothing; + opGETMETHOD, Nothing; + opGETDYNMET, Nothing; + opGETPUBMET, Pubmet; + opBEQ, Sint_Disp; + opBNEQ, Sint_Disp; + opBLTINT, Sint_Disp; + opBLEINT, Sint_Disp; + opBGTINT, Sint_Disp; + opBGEINT, Sint_Disp; + opULTINT, Nothing; + opUGEINT, Nothing; + opBULTINT, Uint_Disp; + opBUGEINT, Uint_Disp; + opSTOP, Nothing; + opEVENT, Nothing; + opBREAK, Nothing; +];; + +let print_event ev = + let ls = ev.ev_loc.loc_start in + let le = ev.ev_loc.loc_end in + printf "File \"%s\", line %d, characters %d-%d:\n" ls.Lexing.pos_fname + ls.Lexing.pos_lnum (ls.Lexing.pos_cnum - ls.Lexing.pos_bol) + (le.Lexing.pos_cnum - ls.Lexing.pos_bol) + +let print_instr ic = + let pos = currpos ic in + List.iter print_event (Hashtbl.find_all event_table pos); + printf "%8d " (pos / 4); + let op = inputu ic in + if op >= Array.length names_of_instructions || op < 0 + then (print_string "*** unknown opcode : "; print_int op) + else print_string names_of_instructions.(op); + print_string " "; + begin try match List.assoc op op_shapes with + | Uint -> print_int (inputu ic) + | Sint -> print_int (inputs ic) + | Uint_Uint + -> print_int (inputu ic); print_string ", "; print_int (inputu ic) + | Disp -> let p = currpc ic in print_int (p + inputs ic) + | Uint_Disp + -> print_int (inputu ic); print_string ", "; + let p = currpc ic in print_int (p + inputs ic) + | Sint_Disp + -> print_int (inputs ic); print_string ", "; + let p = currpc ic in print_int (p + inputs ic) + | Getglobal -> print_getglobal_name ic + | Getglobal_Uint + -> print_getglobal_name ic; print_string ", "; print_int (inputu ic) + | Setglobal -> print_setglobal_name ic + | Primitive -> print_primitive ic + | Uint_Primitive + -> print_int(inputu ic); print_string ", "; print_primitive ic + | Switch + -> let n = inputu ic in + let orig = currpc ic in + for i = 0 to (n land 0xFFFF) - 1 do + print_string "\n int "; print_int i; print_string " -> "; + print_int(orig + inputs ic); + done; + for i = 0 to (n lsr 16) - 1 do + print_string "\n tag "; print_int i; print_string " -> "; + print_int(orig + inputs ic); + done; + | Closurerec + -> let nfuncs = inputu ic in + let nvars = inputu ic in + let orig = currpc ic in + print_int nvars; + for i = 0 to nfuncs - 1 do + print_string ", "; + print_int (orig + inputs ic); + done; + | Pubmet + -> let tag = inputs ic in + let _cache = inputu ic in + print_int tag + | Nothing -> () + with Not_found -> print_string "(unknown arguments)" + end; + print_string "\n"; +;; + +(* Disassemble a block of code *) + +let print_code ic len = + start := pos_in ic; + let stop = !start + len in + while pos_in ic < stop do print_instr ic done + +(* Dump relocation info *) + +let print_reloc (info, pos) = + printf " %d (%d) " pos (pos/4); + match info with + Reloc_literal sc -> print_struct_const sc; printf "\n" + | Reloc_getglobal id -> printf "require %s\n" (Ident.name id) + | Reloc_setglobal id -> printf "provide %s\n" (Ident.name id) + | Reloc_primitive s -> printf "prim %s\n" s + +(* Print a .cmo file *) + +let dump_obj filename ic = + let buffer = String.create (String.length cmo_magic_number) in + really_input ic buffer 0 (String.length cmo_magic_number); + if buffer <> cmo_magic_number then begin + prerr_endline "Not an object file"; exit 2 + end; + let cu_pos = input_binary_int ic in + seek_in ic cu_pos; + let cu = (input_value ic : compilation_unit) in + reloc := cu.cu_reloc; + if cu.cu_debug > 0 then begin + seek_in ic cu.cu_debug; + let evl = (input_value ic : debug_event list) in + record_events 0 evl + end; + seek_in ic cu.cu_pos; + print_code ic cu.cu_codesize + +(* Read the primitive table from an executable *) + +let read_primitive_table ic len = + let p = String.create len in + really_input ic p 0 len; + let rec split beg cur = + if cur >= len then [] + else if p.[cur] = '\000' then + String.sub p beg (cur - beg) :: split (cur + 1) (cur + 1) + else + split beg (cur + 1) in + Array.of_list(split 0 0) + +(* Print an executable file *) + +let dump_exe ic = + Bytesections.read_toc ic; + let prim_size = Bytesections.seek_section ic "PRIM" in + primitives := read_primitive_table ic prim_size; + ignore(Bytesections.seek_section ic "DATA"); + let init_data = (input_value ic : Obj.t array) in + globals := Array.create (Array.length init_data) Empty; + for i = 0 to Array.length init_data - 1 do + !globals.(i) <- Constant (init_data.(i)) + done; + ignore(Bytesections.seek_section ic "SYMB"); + let (_, sym_table) = (input_value ic : int * (Ident.t, int) Tbl.t) in + Tbl.iter (fun id pos -> !globals.(pos) <- Global id) sym_table; + begin try + ignore (Bytesections.seek_section ic "DBUG"); + let num_eventlists = input_binary_int ic in + for i = 1 to num_eventlists do + let orig = input_binary_int ic in + let evl = (input_value ic : debug_event list) in + record_events orig evl + done + with Not_found -> () + end; + let code_size = Bytesections.seek_section ic "CODE" in + print_code ic code_size + +let main() = + for i = 1 to Array.length Sys.argv - 1 do + let filnam = Sys.argv.(i) in + let ic = open_in_bin filnam in + if i>1 then print_newline (); + printf "## start of ocaml dump of %S\n%!" filnam; + begin try + objfile := false; dump_exe ic + with Bytesections.Bad_magic_number -> + objfile := true; seek_in ic 0; dump_obj (Sys.argv.(i)) ic + end; + close_in ic; + printf "## end of ocaml dump of %S\n%!" filnam; + done; + exit 0 + +let _ = main () diff --git a/tools/keywords.r b/tools/keywords.r new file mode 100644 index 0000000..1037c22 --- /dev/null +++ b/tools/keywords.r @@ -0,0 +1,121 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Damien Doligez, projet Para, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: keywords.r,v 1.3 2001-12-07 13:41:01 xleroy Exp $ */ + +type 'Odds' { + longint; /* resource ID of corresponding 'Sods' */ + longint = $$CountOf (suffixes); + wide array suffixes { pstring; }; +}; + +type 'Sods' { + longint = 0xA5666D66; + pstring; /* default token breaks */ + longint = $$CountOf (keywords); + wide array keywords { + pstring; /* the keyword itself */ + longint /* the keyword type */ + case=0, + caseWord=1, + noCase=2, + noCaseWord=3, + line=4, + mystery=0xB, + opening=0x10000, + closing=0x20000, + openingFill=0x50000, + closingFill=0x60000, + quote=0x80000; + literal longint; /* scoping parameter */ + longint /* color */ + red=0, + blue=1, + bluegreen=2, + bluepurple=3, + grey=4, + darkgreen=7, + black=255; + }; +}; + +resource 'Odds' (26087, "O'Caml") { + 26087, + { ".ml", ".mli", ".mll", ".mly", ".mlp" } +}; + +resource 'Sods' (26087, "O'Caml Keywords") { + "\t\r\n ~!$%^&*()/-+=<>,[]{};", + { + "(*", openingFill, '(**)', red, + "*)", closingFill, '(**)', red, + "\"", quote, 0, grey, +#define KEY caseWord, 0, blue + "and", KEY, + "as", KEY, + "assert", KEY, + "begin", KEY, + "class", KEY, + "constraint", KEY, + "do", KEY, + "done", KEY, + "downto", KEY, + "else", KEY, + "end", KEY, + "exception", KEY, + "external", KEY, + "false", KEY, + "for", KEY, + "fun", KEY, + "function", KEY, + "functor", KEY, + "if", KEY, + "in", KEY, + "include", KEY, + "inherit", KEY, + "initializer", KEY, + "lazy", KEY, + "let", KEY, + "match", KEY, + "method", KEY, + "module", KEY, + "mutable", KEY, + "new", KEY, + "object", KEY, + "of", KEY, + "open", KEY, + "or", KEY, + "parser", KEY, + "private", KEY, + "rec", KEY, + "sig", KEY, + "struct", KEY, + "then", KEY, + "to", KEY, + "true", KEY, + "try", KEY, + "type", KEY, + "val", KEY, + "virtual", KEY, + "when", KEY, + "while", KEY, + "with", KEY, + "mod", KEY, + "land", KEY, + "lor", KEY, + "lxor", KEY, + "lsl", KEY, + "lsr", KEY, + "asr", KEY, + } +}; diff --git a/tools/lexer299.mll b/tools/lexer299.mll new file mode 100644 index 0000000..2bd2bd3 --- /dev/null +++ b/tools/lexer299.mll @@ -0,0 +1,460 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer299.mll,v 1.4 2005-06-22 13:52:36 doligez Exp $ *) + +(* The lexer definition *) + +{ +open Lexing +open Misc + +type token = + AMPERAMPER + | AMPERSAND + | AND + | AS + | ASSERT + | BACKQUOTE + | BAR + | BARBAR + | BARRBRACKET + | BEGIN + | CHAR of (char) + | CLASS + | COLON + | COLONCOLON + | COLONEQUAL + | COLONGREATER + | COMMA + | CONSTRAINT + | DO + | DONE + | DOT + | DOTDOT + | DOWNTO + | ELSE + | END + | EOF + | EQUAL + | EXCEPTION + | EXTERNAL + | FALSE + | FLOAT of (string) + | FOR + | FUN + | FUNCTION + | FUNCTOR + | GREATER + | GREATERRBRACE + | GREATERRBRACKET + | IF + | IN + | INCLUDE + | INFIXOP0 of (string) + | INFIXOP1 of (string) + | INFIXOP2 of (string) + | INFIXOP3 of (string) + | INFIXOP4 of (string) + | INHERIT + | INITIALIZER + | INT of (int) + | LABEL of (string) + | LABELID of (string) + | LAZY + | LBRACE + | LBRACELESS + | LBRACKET + | LBRACKETBAR + | LBRACKETLESS + | LESS + | LESSMINUS + | LET + | LIDENT of (string) + | LPAREN + | MATCH + | METHOD + | MINUSGREATER + | MODULE + | MUTABLE + | NEW + | OBJECT + | OF + | OPEN + | OR + | PARSER + | PREFIXOP of (string) + | PRIVATE + | QUESTION + | QUESTION2 + | QUOTE + | RBRACE + | RBRACKET + | REC + | RPAREN + | SEMI + | SEMISEMI + | SHARP + | SIG + | STAR + | STRING of (string) + | STRUCT + | SUBTRACTIVE of (string) + | THEN + | TO + | TRUE + | TRY + | TYPE + | UIDENT of (string) + | UNDERSCORE + | VAL + | VIRTUAL + | WHEN + | WHILE + | WITH + +type error = + | Illegal_character of char + | Unterminated_comment + | Unterminated_string + | Unterminated_string_in_comment +;; + +exception Error of error * int * int + +(* The table of keywords *) + +let keyword_table = + create_hashtable 149 [ + "and", AND; + "as", AS; + "assert", ASSERT; + "begin", BEGIN; + "class", CLASS; + "constraint", CONSTRAINT; + "do", DO; + "done", DONE; + "downto", DOWNTO; + "else", ELSE; + "end", END; + "exception", EXCEPTION; + "external", EXTERNAL; + "false", FALSE; + "for", FOR; + "fun", FUN; + "function", FUNCTION; + "functor", FUNCTOR; + "if", IF; + "in", IN; + "include", INCLUDE; + "inherit", INHERIT; + "initializer", INITIALIZER; + "lazy", LAZY; + "let", LET; + "match", MATCH; + "method", METHOD; + "module", MODULE; + "mutable", MUTABLE; + "new", NEW; + "object", OBJECT; + "of", OF; + "open", OPEN; + "or", OR; + "parser", PARSER; + "private", PRIVATE; + "rec", REC; + "sig", SIG; + "struct", STRUCT; + "then", THEN; + "to", TO; + "true", TRUE; + "try", TRY; + "type", TYPE; + "val", VAL; + "virtual", VIRTUAL; + "when", WHEN; + "while", WHILE; + "with", WITH; + + "mod", INFIXOP3("mod"); + "land", INFIXOP3("land"); + "lor", INFIXOP3("lor"); + "lxor", INFIXOP3("lxor"); + "lsl", INFIXOP4("lsl"); + "lsr", INFIXOP4("lsr"); + "asr", INFIXOP4("asr") +] + +(* To buffer string literals *) + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0 + +let store_string_char c = + if !string_index >= String.length (!string_buff) then begin + let new_buff = String.create (String.length (!string_buff) * 2) in + String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff)); + string_buff := new_buff + end; + String.unsafe_set (!string_buff) (!string_index) c; + incr string_index + +let get_stored_string () = + let s = String.sub (!string_buff) 0 (!string_index) in + string_buff := initial_string_buffer; + s + +(* To translate escape sequences *) + +let char_for_backslash = function + | 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in + Char.chr(c land 0xFF) + +(* To store the position of the beginning of a string and comment *) +let string_start_pos = ref 0;; +let comment_start_pos = ref [];; + +(* Error report *) + +open Format + +let report_error ppf = function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf "This comment contains an unterminated string literal" +;; + +} + +let blank = [' ' '\010' '\013' '\009' '\012'] +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let symbolchar = + ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] +let symbolchar2 = + ['!' '$' '%' '&' '*' '+' '-' '.' '/' '<' '=' '>' '?' '@' '^' '|' '~'] +(* ['!' '$' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] *) +let decimal_literal = ['0'-'9']+ +let hex_literal = '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']+ +let oct_literal = '0' ['o' 'O'] ['0'-'7']+ +let bin_literal = '0' ['b' 'B'] ['0'-'1']+ +let float_literal = + ['0'-'9']+ ('.' ['0'-'9']* )? (['e' 'E'] ['+' '-']? ['0'-'9']+)? + +rule token = parse + blank + + { token lexbuf } + | "_" + { UNDERSCORE } + | lowercase identchar * ':' [ ^ ':' '=' '>'] + { let s = Lexing.lexeme lexbuf in + lexbuf.lex_curr_pos <- lexbuf.lex_curr_pos - 1; + lexbuf.lex_curr_p <- + {lexbuf.lex_curr_p with pos_cnum = lexbuf.lex_curr_p.pos_cnum - 1}; + LABEL (String.sub s 0 (String.length s - 2)) } +(* + | lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + LABEL (String.sub s 0 (String.length s - 1)) } + | '%' lowercase identchar * +*) + | ':' lowercase identchar * + { let s = Lexing.lexeme lexbuf in + let l = String.length s - 1 in + LABELID (String.sub s 1 l) } + | lowercase identchar * + { let s = Lexing.lexeme lexbuf in + try + Hashtbl.find keyword_table s + with Not_found -> + LIDENT s } + | uppercase identchar * + { UIDENT(Lexing.lexeme lexbuf) } (* No capitalized keywords *) + | decimal_literal | hex_literal | oct_literal | bin_literal + { INT (int_of_string(Lexing.lexeme lexbuf)) } + | float_literal + { FLOAT (Lexing.lexeme lexbuf) } + | "\"" + { reset_string_buffer(); + let string_start = Lexing.lexeme_start lexbuf in + string_start_pos := string_start; + string lexbuf; + lexbuf.Lexing.lex_start_pos <- + string_start - lexbuf.Lexing.lex_abs_pos; + STRING (get_stored_string()) } + | "'" [^ '\\' '\''] "'" + { CHAR(Lexing.lexeme_char lexbuf 1) } + | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { CHAR(char_for_backslash (Lexing.lexeme_char lexbuf 2)) } + | "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { CHAR(char_for_decimal_code lexbuf 2) } + | "(*" + { comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf; + token lexbuf } + | "(*)" + { let loc = { Location.loc_start = Lexing.lexeme_start_p lexbuf; + Location.loc_end = Lexing.lexeme_end_p lexbuf; + Location.loc_ghost = false } + in + Location.prerr_warning loc (Warnings.Comment_start); + comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf; + token lexbuf + } + | "*)" + { let loc = { Location.loc_start = Lexing.lexeme_start_p lexbuf; + Location.loc_end = Lexing.lexeme_end_p lexbuf; + Location.loc_ghost = false } + in + Location.prerr_warning loc Warnings.Comment_not_end; + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + STAR + } + | "#" [' ' '\t']* ['0'-'9']+ [^ '\n' '\r'] * ('\n' | '\r' | "\r\n") + (* # linenum ... *) + { token lexbuf } + | "#" { SHARP } + | "&" { AMPERSAND } + | "&&" { AMPERAMPER } + | "`" { BACKQUOTE } + | "'" { QUOTE } + | "(" { LPAREN } + | ")" { RPAREN } + | "*" { STAR } + | "," { COMMA } + | "?" { QUESTION } + | "??" { QUESTION2 } + | "->" { MINUSGREATER } + | "." { DOT } + | ".." { DOTDOT } + | ":" { COLON } + | "::" { COLONCOLON } + | ":=" { COLONEQUAL } + | ":>" { COLONGREATER } + | ";" { SEMI } + | ";;" { SEMISEMI } + | "<" { LESS } + | "<-" { LESSMINUS } + | "=" { EQUAL } + | "[" { LBRACKET } + | "[|" { LBRACKETBAR } + | "[<" { LBRACKETLESS } + | "]" { RBRACKET } + | "{" { LBRACE } + | "{<" { LBRACELESS } + | "|" { BAR } + | "||" { BARBAR } + | "|]" { BARRBRACKET } + | ">" { GREATER } + | ">]" { GREATERRBRACKET } + | "}" { RBRACE } + | ">}" { GREATERRBRACE } + + | "!=" { INFIXOP0 "!=" } + | "-" { SUBTRACTIVE "-" } + | "-." { SUBTRACTIVE "-." } + + | ['!' '~'] symbolchar * + { PREFIXOP(Lexing.lexeme lexbuf) } + | '?' symbolchar2 * + { PREFIXOP(Lexing.lexeme lexbuf) } + | ['=' '<' '>' '|' '&' '$'] symbolchar * + { INFIXOP0(Lexing.lexeme lexbuf) } + | ['@' '^'] symbolchar * + { INFIXOP1(Lexing.lexeme lexbuf) } + | ['+' '-'] symbolchar * + { INFIXOP2(Lexing.lexeme lexbuf) } + | "**" symbolchar * + { INFIXOP4(Lexing.lexeme lexbuf) } + | ['*' '/' '%'] symbolchar * + { INFIXOP3(Lexing.lexeme lexbuf) } + | eof { EOF } + | _ + { raise (Error(Illegal_character ((Lexing.lexeme lexbuf).[0]), + Lexing.lexeme_start lexbuf, Lexing.lexeme_end lexbuf)) } + +and comment = parse + "(*" + { comment_start_pos := Lexing.lexeme_start lexbuf :: !comment_start_pos; + comment lexbuf; + } + | "*)" + { match !comment_start_pos with + | [] -> assert false + | [x] -> () + | _ :: l -> comment_start_pos := l; + comment lexbuf; + } + | "\"" + { reset_string_buffer(); + string_start_pos := Lexing.lexeme_start lexbuf; + begin try string lexbuf + with Error (Unterminated_string, _, _) -> + let st = List.hd !comment_start_pos in + raise (Error (Unterminated_string_in_comment, st, st + 2)) + end; + string_buff := initial_string_buffer; + comment lexbuf } + | "''" + { comment lexbuf } + | "'" [^ '\\' '\''] "'" + { comment lexbuf } + | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { comment lexbuf } + | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { comment lexbuf } + | eof + { let st = List.hd !comment_start_pos in + raise (Error (Unterminated_comment, st, st + 2)); + } + | _ + { comment lexbuf } + +and string = parse + '"' + { () } + | '\\' ("\010" | "\013" | "\013\010") [' ' '\009'] * + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise (Error (Unterminated_string, + !string_start_pos, !string_start_pos+1)) } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } diff --git a/tools/lexer301.mll b/tools/lexer301.mll new file mode 100644 index 0000000..ccd70f0 --- /dev/null +++ b/tools/lexer301.mll @@ -0,0 +1,461 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: lexer301.mll,v 1.5 2004-11-30 18:57:04 doligez Exp $ *) + +(* The lexer definition *) + +{ +open Misc + +type token = + AMPERAMPER + | AMPERSAND + | AND + | AS + | ASSERT + | BACKQUOTE + | BAR + | BARBAR + | BARRBRACKET + | BEGIN + | CHAR of (char) + | CLASS + | COLON + | COLONCOLON + | COLONEQUAL + | COLONGREATER + | COMMA + | CONSTRAINT + | DO + | DONE + | DOT + | DOTDOT + | DOWNTO + | ELSE + | END + | EOF + | EQUAL + | EXCEPTION + | EXTERNAL + | FALSE + | FLOAT of (string) + | FOR + | FUN + | FUNCTION + | FUNCTOR + | GREATER + | GREATERRBRACE + | GREATERRBRACKET + | IF + | IN + | INCLUDE + | INFIXOP0 of (string) + | INFIXOP1 of (string) + | INFIXOP2 of (string) + | INFIXOP3 of (string) + | INFIXOP4 of (string) + | INHERIT + | INITIALIZER + | INT of (int) + | LABEL of (string) + | LAZY + | LBRACE + | LBRACELESS + | LBRACKET + | LBRACKETBAR + | LBRACKETLESS + | LESS + | LESSMINUS + | LET + | LIDENT of (string) + | LPAREN + | MATCH + | METHOD + | MINUS + | MINUSDOT + | MINUSGREATER + | MODULE + | MUTABLE + | NEW + | OBJECT + | OF + | OPEN + | OPTLABEL of (string) + | OR + | PARSER + | PLUS + | PREFIXOP of (string) + | PRIVATE + | QUESTION + | QUESTION2 + | QUOTE + | RBRACE + | RBRACKET + | REC + | RPAREN + | SEMI + | SEMISEMI + | SHARP + | SIG + | STAR + | STRING of (string) + | STRUCT + | THEN + | TILDE + | TO + | TRUE + | TRY + | TYPE + | UIDENT of (string) + | UNDERSCORE + | VAL + | VIRTUAL + | WHEN + | WHILE + | WITH + +type error = + | Illegal_character of char + | Unterminated_comment + | Unterminated_string + | Unterminated_string_in_comment + | Keyword_as_label of string +;; + +exception Error of error * int * int + +(* The table of keywords *) + +let keyword_table = + create_hashtable 149 [ + "and", AND; + "as", AS; + "assert", ASSERT; + "begin", BEGIN; + "class", CLASS; + "constraint", CONSTRAINT; + "do", DO; + "done", DONE; + "downto", DOWNTO; + "else", ELSE; + "end", END; + "exception", EXCEPTION; + "external", EXTERNAL; + "false", FALSE; + "for", FOR; + "fun", FUN; + "function", FUNCTION; + "functor", FUNCTOR; + "if", IF; + "in", IN; + "include", INCLUDE; + "inherit", INHERIT; + "initializer", INITIALIZER; + "lazy", LAZY; + "let", LET; + "match", MATCH; + "method", METHOD; + "module", MODULE; + "mutable", MUTABLE; + "new", NEW; + "object", OBJECT; + "of", OF; + "open", OPEN; + "or", OR; + "parser", PARSER; + "private", PRIVATE; + "rec", REC; + "sig", SIG; + "struct", STRUCT; + "then", THEN; + "to", TO; + "true", TRUE; + "try", TRY; + "type", TYPE; + "val", VAL; + "virtual", VIRTUAL; + "when", WHEN; + "while", WHILE; + "with", WITH; + + "mod", INFIXOP3("mod"); + "land", INFIXOP3("land"); + "lor", INFIXOP3("lor"); + "lxor", INFIXOP3("lxor"); + "lsl", INFIXOP4("lsl"); + "lsr", INFIXOP4("lsr"); + "asr", INFIXOP4("asr") +] + +(* To buffer string literals *) + +let initial_string_buffer = String.create 256 +let string_buff = ref initial_string_buffer +let string_index = ref 0 + +let reset_string_buffer () = + string_buff := initial_string_buffer; + string_index := 0 + +let store_string_char c = + if !string_index >= String.length (!string_buff) then begin + let new_buff = String.create (String.length (!string_buff) * 2) in + String.blit (!string_buff) 0 new_buff 0 (String.length (!string_buff)); + string_buff := new_buff + end; + String.unsafe_set (!string_buff) (!string_index) c; + incr string_index + +let get_stored_string () = + let s = String.sub (!string_buff) 0 (!string_index) in + string_buff := initial_string_buffer; + s + +(* To translate escape sequences *) + +let char_for_backslash = function + | 'n' -> '\010' + | 'r' -> '\013' + | 'b' -> '\008' + | 't' -> '\009' + | c -> c + +let char_for_decimal_code lexbuf i = + let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) + + 10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) + + (Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in + Char.chr(c land 0xFF) + +(* To store the position of the beginning of a string and comment *) +let string_start_pos = ref 0;; +let comment_start_pos = ref [];; +let in_comment () = !comment_start_pos <> [];; + +(* Error report *) + +open Format + +let report_error ppf = function + | Illegal_character c -> + fprintf ppf "Illegal character (%s)" (Char.escaped c) + | Unterminated_comment -> + fprintf ppf "Comment not terminated" + | Unterminated_string -> + fprintf ppf "String literal not terminated" + | Unterminated_string_in_comment -> + fprintf ppf "This comment contains an unterminated string literal" + | Keyword_as_label kwd -> + fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd +;; + +} + +let blank = [' ' '\010' '\013' '\009' '\012'] +let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_'] +let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222'] +let identchar = + ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9'] +let symbolchar = + ['!' '$' '%' '&' '*' '+' '-' '.' '/' ':' '<' '=' '>' '?' '@' '^' '|' '~'] +let decimal_literal = ['0'-'9']+ +let hex_literal = '0' ['x' 'X'] ['0'-'9' 'A'-'F' 'a'-'f']+ +let oct_literal = '0' ['o' 'O'] ['0'-'7']+ +let bin_literal = '0' ['b' 'B'] ['0'-'1']+ +let float_literal = + ['0'-'9']+ ('.' ['0'-'9']* )? (['e' 'E'] ['+' '-']? ['0'-'9']+)? + +rule token = parse + blank + + { token lexbuf } + | "_" + { UNDERSCORE } + | "~" { TILDE } + | "~" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Lexing.lexeme_start lexbuf, + Lexing.lexeme_end lexbuf)); + LABEL name } + | "?" { QUESTION } + | "?" lowercase identchar * ':' + { let s = Lexing.lexeme lexbuf in + let name = String.sub s 1 (String.length s - 2) in + if Hashtbl.mem keyword_table name then + raise (Error(Keyword_as_label name, Lexing.lexeme_start lexbuf, + Lexing.lexeme_end lexbuf)); + OPTLABEL name } + | lowercase identchar * + { let s = Lexing.lexeme lexbuf in + try + Hashtbl.find keyword_table s + with Not_found -> + LIDENT s } + | uppercase identchar * + { UIDENT(Lexing.lexeme lexbuf) } (* No capitalized keywords *) + | decimal_literal | hex_literal | oct_literal | bin_literal + { INT (int_of_string(Lexing.lexeme lexbuf)) } + | float_literal + { FLOAT (Lexing.lexeme lexbuf) } + | "\"" + { reset_string_buffer(); + let string_start = Lexing.lexeme_start lexbuf in + string_start_pos := string_start; + string lexbuf; + lexbuf.Lexing.lex_start_pos <- + string_start - lexbuf.Lexing.lex_abs_pos; + STRING (get_stored_string()) } + | "'" [^ '\\' '\''] "'" + { CHAR(Lexing.lexeme_char lexbuf 1) } + | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { CHAR(char_for_backslash (Lexing.lexeme_char lexbuf 2)) } + | "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { CHAR(char_for_decimal_code lexbuf 2) } + | "(*" + { comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf; + token lexbuf } + | "(*)" + { let loc = Location.curr lexbuf + and warn = Warnings.Comment_start + in + Location.prerr_warning loc warn; + comment_start_pos := [Lexing.lexeme_start lexbuf]; + comment lexbuf; + token lexbuf + } + | "*)" + { let loc = Location.curr lexbuf + and warn = Warnings.Comment_not_end + in + Location.prerr_warning loc warn; + lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_curr_pos - 1; + STAR + } + | "#" [' ' '\t']* ['0'-'9']+ [^ '\n' '\r'] * ('\n' | '\r' | "\r\n") + (* # linenum ... *) + { token lexbuf } + | "#" { SHARP } + | "&" { AMPERSAND } + | "&&" { AMPERAMPER } + | "`" { BACKQUOTE } + | "'" { QUOTE } + | "(" { LPAREN } + | ")" { RPAREN } + | "*" { STAR } + | "," { COMMA } + | "??" { QUESTION2 } + | "->" { MINUSGREATER } + | "." { DOT } + | ".." { DOTDOT } + | ":" { COLON } + | "::" { COLONCOLON } + | ":=" { COLONEQUAL } + | ":>" { COLONGREATER } + | ";" { SEMI } + | ";;" { SEMISEMI } + | "<" { LESS } + | "<-" { LESSMINUS } + | "=" { EQUAL } + | "[" { LBRACKET } + | "[|" { LBRACKETBAR } + | "[<" { LBRACKETLESS } + | "]" { RBRACKET } + | "{" { LBRACE } + | "{<" { LBRACELESS } + | "|" { BAR } + | "||" { BARBAR } + | "|]" { BARRBRACKET } + | ">" { GREATER } + | ">]" { GREATERRBRACKET } + | "}" { RBRACE } + | ">}" { GREATERRBRACE } + + | "!=" { INFIXOP0 "!=" } + | "+" { PLUS } + | "-" { MINUS } + | "-." { MINUSDOT } + + | "!" symbolchar * + { PREFIXOP(Lexing.lexeme lexbuf) } + | ['~' '?'] symbolchar + + { PREFIXOP(Lexing.lexeme lexbuf) } + | ['=' '<' '>' '|' '&' '$'] symbolchar * + { INFIXOP0(Lexing.lexeme lexbuf) } + | ['@' '^'] symbolchar * + { INFIXOP1(Lexing.lexeme lexbuf) } + | ['+' '-'] symbolchar * + { INFIXOP2(Lexing.lexeme lexbuf) } + | "**" symbolchar * + { INFIXOP4(Lexing.lexeme lexbuf) } + | ['*' '/' '%'] symbolchar * + { INFIXOP3(Lexing.lexeme lexbuf) } + | eof { EOF } + | _ + { raise (Error(Illegal_character ((Lexing.lexeme lexbuf).[0]), + Lexing.lexeme_start lexbuf, Lexing.lexeme_end lexbuf)) } + +and comment = parse + "(*" + { comment_start_pos := Lexing.lexeme_start lexbuf :: !comment_start_pos; + comment lexbuf; + } + | "*)" + { match !comment_start_pos with + | [] -> assert false + | [x] -> comment_start_pos := []; + | _ :: l -> comment_start_pos := l; + comment lexbuf; + } + | "\"" + { reset_string_buffer(); + string_start_pos := Lexing.lexeme_start lexbuf; + begin try string lexbuf + with Error (Unterminated_string, _, _) -> + let st = List.hd !comment_start_pos in + raise (Error (Unterminated_string_in_comment, st, st + 2)) + end; + string_buff := initial_string_buffer; + comment lexbuf } + | "''" + { comment lexbuf } + | "'" [^ '\\' '\''] "'" + { comment lexbuf } + | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'" + { comment lexbuf } + | "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'" + { comment lexbuf } + | eof + { let st = List.hd !comment_start_pos in + raise (Error (Unterminated_comment, st, st + 2)); + } + | _ + { comment lexbuf } + +and string = parse + '"' + { () } + | '\\' ("\010" | "\013" | "\013\010") [' ' '\009'] * + { string lexbuf } + | '\\' ['\\' '"' 'n' 't' 'b' 'r'] + { store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1)); + string lexbuf } + | '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] + { store_string_char(char_for_decimal_code lexbuf 1); + string lexbuf } + | eof + { raise (Error (Unterminated_string, + !string_start_pos, !string_start_pos+1)) } + | _ + { store_string_char(Lexing.lexeme_char lexbuf 0); + string lexbuf } diff --git a/tools/magic b/tools/magic new file mode 100644 index 0000000..7468066 --- /dev/null +++ b/tools/magic @@ -0,0 +1,11 @@ +# Here are some definitions that can be added to the /usr/share/magic +# database so that the file(1) command recognizes OCaml compiled files. +# Contributed by Sven Luther. +0 string Caml1999 Objective Caml +>8 string X bytecode executable +>8 string I interface data (.cmi) +>8 string O bytecode object data (.cmo) +>8 string A bytecode library data (.cma) +>8 string Y native object data (.cmx) +>8 string Z native library data (.cmxa) +>9 string >\0 (Version %3.3s). diff --git a/tools/make-opcodes b/tools/make-opcodes new file mode 100644 index 0000000..c8f573c --- /dev/null +++ b/tools/make-opcodes @@ -0,0 +1,2 @@ +$1=="enum" {n=0; next; } + {for (i = 1; i <= NF; i++) {printf("let op%s = %d\n", $i, n++);}} diff --git a/tools/make-package-macosx b/tools/make-package-macosx new file mode 100755 index 0000000..87c85ca --- /dev/null +++ b/tools/make-package-macosx @@ -0,0 +1,129 @@ +#!/bin/sh + +######################################################################### +# # +# Objective Caml # +# # +# Damien Doligez, projet Moscova, INRIA Rocquencourt # +# # +# Copyright 2003 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: make-package-macosx,v 1.17 2008-12-03 18:09:09 doligez Exp $ + +cd package-macosx +rm -rf ocaml.pkg ocaml-rw.dmg + +VERSION=`head -1 ../VERSION` +VERSION_MAJOR=`sed -n -e '1s/^\([0-9]*\)\..*/\1/p' ../VERSION` +VERSION_MINOR=`sed -n -e '1s/^[0-9]*\.\([0-9]*\)[.+].*/\1/p' ../VERSION` + +cat >Description.plist <<EOF + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>IFPkgDescriptionDeleteWarning</key> + <string></string> + <key>IFPkgDescriptionDescription</key> + <string>The Objective Caml compiler and tools</string> + <key>IFPkgDescriptionTitle</key> + <string>Objective Caml</string> + <key>IFPkgDescriptionVersion</key> + <string>${VERSION}</string> + </dict> + </plist> +EOF + +cat >Info.plist <<EOF +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleGetInfoString</key> + <string>Objective Caml ${VERSION}</string> + <key>CFBundleIdentifier</key> + <string>fr.inria.ocaml</string> + <key>CFBundleName</key> + <string>Objective Caml</string> + <key>CFBundleShortVersionString</key> + <string>${VERSION}</string> + <key>IFMajorVersion</key> + <integer>${VERSION_MAJOR}</integer> + <key>IFMinorVersion</key> + <integer>${VERSION_MINOR}</integer> + <key>IFPkgFlagAllowBackRev</key> + <true/> + <key>IFPkgFlagAuthorizationAction</key> + <string>AdminAuthorization</string> + <key>IFPkgFlagDefaultLocation</key> + <string>/usr/local</string> + <key>IFPkgFlagInstallFat</key> + <false/> + <key>IFPkgFlagIsRequired</key> + <false/> + <key>IFPkgFlagRelocatable</key> + <false/> + <key>IFPkgFlagRestartAction</key> + <string>NoRestart</string> + <key>IFPkgFlagRootVolumeOnly</key> + <true/> + <key>IFPkgFlagUpdateInstalledLanguages</key> + <false/> + <key>IFPkgFormatVersion</key> + <real>0.10000000149011612</real> +</dict> +</plist> +EOF + +mkdir -p resources + +# stop here -> | +cat >resources/ReadMe.txt <<EOF +This package installs Objective Caml version ${VERSION}. +You need Mac OS X 10.5.x (Leopard), with the +XCode tools installed (v3.1.1 or later), and +optionally X11. + +Files will be installed in the following directories: + +/usr/local/bin - command-line executables +/usr/local/lib/ocaml - library and support files +/usr/local/man - manual pages +EOF + +chmod -R g-w root +sudo chown -R root:wheel root + +/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker \ + -build -p "`pwd`/ocaml.pkg" -f "`pwd`/root" -i "`pwd`/Info.plist" \ + -d "`pwd`/Description.plist" -r "`pwd`/resources" + +size=`du -s ocaml.pkg | cut -f 1` +size=`expr $size + 8192` + +hdiutil create -sectors $size ocaml-rw.dmg +name=`hdid -nomount ocaml-rw.dmg | grep Apple_HFS | cut -d ' ' -f 1` +volname="Objective Caml ${VERSION}" +newfs_hfs -v "$volname" $name +hdiutil detach $name + +name=`hdid ocaml-rw.dmg | grep Apple_HFS | cut -d ' ' -f 1` +if test -d "/Volumes/$volname"; then + ditto -rsrcFork ocaml.pkg "/Volumes/$volname/ocaml.pkg" + cp resources/ReadMe.txt "/Volumes/$volname/" +else + echo "Unable to mount the disk image as \"/Volumes/$volname\"" >&2 + exit 3 +fi +open "/Volumes/$volname" +sleep 2 +hdiutil detach $name + +rm -rf "ocaml-${VERSION}.dmg" +hdiutil convert ocaml-rw.dmg -format UDZO -o "ocaml-${VERSION}.dmg" diff --git a/tools/objinfo.ml b/tools/objinfo.ml new file mode 100644 index 0000000..b06d62f --- /dev/null +++ b/tools/objinfo.ml @@ -0,0 +1,99 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: objinfo.ml,v 1.11 2006-07-05 12:09:18 pouillar Exp $ *) + +(* Dump a compilation unit description *) + +open Config +open Cmo_format + +let print_digest d = + for i = 0 to String.length d - 1 do + Printf.printf "%02x" (Char.code d.[i]) + done + +let print_info cu = + print_string " Unit name: "; print_string cu.cu_name; print_newline(); + print_string " Interfaces imported:"; print_newline(); + List.iter + (fun (name, digest) -> + print_string "\t"; print_digest digest; print_string "\t"; + print_string name; print_newline()) + cu.cu_imports; + print_string " Uses unsafe features: "; + begin match cu.cu_primitives with + [] -> print_string "no"; print_newline() + | l -> print_string "YES"; print_newline(); + print_string " Primitives declared in this module:"; + print_newline(); + List.iter + (fun name -> print_string "\t"; print_string name; print_newline()) + l + end + +let print_spaced_string s = print_char ' '; print_string s + +let print_library_info lib = + print_string " Force custom: "; + print_string (if lib.lib_custom then "YES" else "no"); + print_newline(); + print_string " Extra C object files:"; + List.iter print_spaced_string lib.lib_ccobjs; print_newline(); + print_string " Extra C options:"; + List.iter print_spaced_string lib.lib_ccopts; print_newline(); + List.iter print_info lib.lib_units + +let print_intf_info name sign comps crcs = + print_string " Module name: "; print_string name; print_newline(); + print_string " Interfaces imported:"; print_newline(); + List.iter + (fun (name, digest) -> + print_string "\t"; print_digest digest; print_string "\t"; + print_string name; print_newline()) + crcs + +let dump_obj filename = + print_string "File "; print_string filename; print_newline(); + let ic = open_in_bin filename in + let buffer = String.create (String.length cmo_magic_number) in + really_input ic buffer 0 (String.length cmo_magic_number); + if buffer = cmo_magic_number then begin + let cu_pos = input_binary_int ic in + seek_in ic cu_pos; + let cu = (input_value ic : compilation_unit) in + close_in ic; + print_info cu + end else + if buffer = cma_magic_number then begin + let toc_pos = input_binary_int ic in + seek_in ic toc_pos; + let toc = (input_value ic : library) in + close_in ic; + print_library_info toc + end else + if buffer = cmi_magic_number then begin + let (name, sign, comps) = input_value ic in + let crcs = input_value ic in + close_in ic; + print_intf_info name sign comps crcs + end else begin + prerr_endline "Not an object file"; exit 2 + end + +let main() = + for i = 1 to Array.length Sys.argv - 1 do + dump_obj Sys.argv.(i) + done; + exit 0 + +let _ = main () diff --git a/tools/ocaml-objcopy-macosx b/tools/ocaml-objcopy-macosx new file mode 100755 index 0000000..fc57e78 --- /dev/null +++ b/tools/ocaml-objcopy-macosx @@ -0,0 +1,54 @@ +#!/bin/bash + +######################################################################### +# # +# Objective Caml # +# # +# Damien Doligez, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 2005 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: ocaml-objcopy-macosx,v 1.2 2006-01-04 16:55:50 doligez Exp $ + + +TMP="${TMPDIR=/tmp}" +TEMP="${TMP}"/ocaml-objcopy-$$.o +UNDEF="${TMP}"/ocaml-objcopy-$$.sym + +usage () { + echo "usage: objcopy {--redefine-sym <old>=<new>} file.o" >&2 + exit 2 +} + +: > "$UNDEF" + +while : ; do + case $# in + 0) break;; + *) case $1 in + --redefine-sym) + case $2 in + *=*) ALIAS="$ALIAS -i${2#*=}:${2%%=*}" + echo ${2%%=*} >>"$UNDEF" + ;; + *) usage;; + esac + shift 2 + ;; + -*) usage;; + *) case $FILE in + "") FILE=$1; shift;; + *) usage;; + esac;; + esac;; + esac +done + +ld -o "$TEMP" -r $ALIAS "$FILE" +ld -o "$FILE" -r -unexported_symbols_list "$UNDEF" "$TEMP" + +rm -f "$TEMP" "$UNDEF" diff --git a/tools/ocaml299to3.ml b/tools/ocaml299to3.ml new file mode 100644 index 0000000..07a2bd0 --- /dev/null +++ b/tools/ocaml299to3.ml @@ -0,0 +1,139 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocaml299to3.ml,v 1.6 2001-10-03 01:34:05 garrigue Exp $ *) + +open Lexer299 + +let input_buffer = Buffer.create 16383 +let input_function ic buf len = + let len = input ic buf 0 len in + Buffer.add_substring input_buffer buf 0 len; + len + +let output_buffer = Buffer.create 16383 + +let modified = ref false + +let convert buffer = + let input_pos = ref 0 in + let copy_input stop = + Buffer.add_substring output_buffer (Buffer.contents input_buffer) + !input_pos (stop - !input_pos); + input_pos := stop + in + let last = ref (EOF, 0, 0) in + try while true do + let token = Lexer299.token buffer + and start = Lexing.lexeme_start buffer + and stop = Lexing.lexeme_end buffer + and last_token, last_start, last_stop = !last in + begin match token with + | LABEL l0 -> + let l = if l0 = "fun" then "f" else l0 in + begin match last_token with + | PREFIXOP "?(" -> + modified := true; + copy_input last_start; + Buffer.add_char output_buffer '?'; + Buffer.add_string output_buffer l; + Buffer.add_string output_buffer ":("; + input_pos := stop + | QUESTION | LPAREN | LBRACE | SEMI | MINUSGREATER + | EQUAL | COLON | COLONGREATER + | VAL | MUTABLE | EXTERNAL | METHOD | OF -> + if l0 = "fun" then begin + modified := true; + copy_input start; + Buffer.add_string output_buffer l; + Buffer.add_char output_buffer ':'; + input_pos := stop + end + | _ -> + modified := true; + copy_input start; + Buffer.add_char output_buffer '~'; + Buffer.add_string output_buffer l; + Buffer.add_char output_buffer ':'; + input_pos := stop + end + | LABELID l -> + modified := true; + begin match last_token with + | PREFIXOP "?(" -> + copy_input last_start; + Buffer.add_string output_buffer "?("; + Buffer.add_string output_buffer l; + input_pos := stop + | LPAREN -> + copy_input last_start; + Buffer.add_string output_buffer "~("; + Buffer.add_string output_buffer l; + input_pos := stop + | QUESTION -> + copy_input last_stop; + Buffer.add_string output_buffer l; + input_pos := stop + | _ -> + copy_input start; + Buffer.add_char output_buffer '~'; + Buffer.add_string output_buffer l; + input_pos := stop + end + | EOF -> raise End_of_file + | _ -> () + end; + if last_token = QUESTION && token = LPAREN then + last := (PREFIXOP "?(", last_start, stop) + else + last := (token, start, stop) + done with + End_of_file -> + copy_input (Buffer.length input_buffer) + +let convert_file name = + let ic = open_in name in + Buffer.clear input_buffer; + Buffer.clear output_buffer; + modified := false; + begin + try convert (Lexing.from_function (input_function ic)); close_in ic + with exn -> close_in ic; raise exn + end; + if !modified then begin + let backup = name ^ ".bak" in + if Sys.file_exists backup then Sys.remove name + else Sys.rename name backup; + let oc = open_out name in + Buffer.output_buffer oc output_buffer; + close_out oc + end + +let _ = + if Array.length Sys.argv < 2 || Sys.argv.(1) = "-h" || Sys.argv.(1) = "-help" + then begin + print_endline "Usage: ocaml299to3 <source file> ..."; + print_endline "Description:"; + print_endline + "Convert Objective Caml 2.99 O'Labl-style labels in implementation files to"; + print_endline + "a syntax compatible with version 3. Also `fun:' labels are replaced by `f:'."; + print_endline "Other syntactic changes are not handled."; + print_endline "Old files are renamed to <file>.bak."; + print_endline "Interface files do not need label syntax conversion."; + exit 0 + end; + for i = 1 to Array.length Sys.argv - 1 do + let name = Sys.argv.(i) in + prerr_endline ("Converting " ^ name); + Printexc.catch convert_file name + done diff --git a/tools/ocamlcp.ml b/tools/ocamlcp.ml new file mode 100644 index 0000000..c2dbb29 --- /dev/null +++ b/tools/ocamlcp.ml @@ -0,0 +1,133 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocamlcp.ml,v 1.41 2007-05-16 08:21:40 doligez Exp $ *) + +open Printf + +let compargs = ref ([] : string list) +let profargs = ref ([] : string list) +let toremove = ref ([] : string list) + +let option opt () = compargs := opt :: !compargs +let option_with_arg opt arg = + compargs := (Filename.quote arg) :: opt :: !compargs +;; + +let make_archive = ref false;; +let with_impl = ref false;; +let with_intf = ref false;; +let with_mli = ref false;; +let with_ml = ref false;; + +let process_file filename = + if Filename.check_suffix filename ".ml" then with_ml := true; + if Filename.check_suffix filename ".mli" then with_mli := true; + compargs := (Filename.quote filename) :: !compargs +;; + +let usage = "Usage: ocamlcp <options> <files>\noptions are:" + +let incompatible o = + fprintf stderr "ocamlcp: profiling is incompatible with the %s option\n" o; + exit 2 + +module Options = Main_args.Make_options (struct + let _a () = make_archive := true; option "-a" () + let _annot = option "-annot" + let _c = option "-c" + let _cc s = option_with_arg "-cc" s + let _cclib s = option_with_arg "-cclib" s + let _ccopt s = option_with_arg "-ccopt" s + let _config = option "-config" + let _custom = option "-custom" + let _dllib = option_with_arg "-dllib" + let _dllpath = option_with_arg "-dllpath" + let _dtypes = option "-dtypes" + let _g = option "-g" + let _i = option "-i" + let _I s = option_with_arg "-I" s + let _impl s = with_impl := true; option_with_arg "-impl" s + let _intf s = with_intf := true; option_with_arg "-intf" s + let _intf_suffix s = option_with_arg "-intf-suffix" s + let _labels = option "-labels" + let _linkall = option "-linkall" + let _make_runtime = option "-make-runtime" + let _noassert = option "-noassert" + let _nolabels = option "-nolabels" + let _noautolink = option "-noautolink" + let _nostdlib = option "-nostdlib" + let _o s = option_with_arg "-o" s + let _output_obj = option "-output-obj" + let _pack = option "-pack" + let _pp s = incompatible "-pp" + let _principal = option "-principal" + let _rectypes = option "-rectypes" + let _thread () = option "-thread" () + let _vmthread () = option "-vmthread" () + let _unsafe = option "-unsafe" + let _use_prims s = option_with_arg "-use-prims" s + let _use_runtime s = option_with_arg "-use-runtime" s + let _v = option "-v" + let _version = option "-version" + let _verbose = option "-verbose" + let _w = option_with_arg "-w" + let _warn_error = option_with_arg "-warn-error" + let _where = option "-where" + let _nopervasives = option "-nopervasives" + let _dparsetree = option "-dparsetree" + let _drawlambda = option "-drawlambda" + let _dlambda = option "-dlambda" + let _dinstr = option "-dinstr" + let anonymous = process_file +end);; + +let add_profarg s = + profargs := (Filename.quote s) :: "-m" :: !profargs +;; + +let optlist = + ("-p", Arg.String add_profarg, + "[afilmt] Profile constructs specified by argument (default fm):\n\ + \032 a Everything\n\ + \032 f Function calls and method calls\n\ + \032 i if ... then ... else\n\ + \032 l while and for loops\n\ + \032 m match ... with\n\ + \032 t try ... with") + :: Options.list +in +Arg.parse optlist process_file usage; +if !with_impl && !with_intf then begin + fprintf stderr "ocamlcp cannot deal with both \"-impl\" and \"-intf\"\n"; + fprintf stderr "please compile interfaces and implementations separately\n"; + exit 2; +end else if !with_impl && !with_mli then begin + fprintf stderr "ocamlcp cannot deal with both \"-impl\" and .mli files\n"; + fprintf stderr "please compile interfaces and implementations separately\n"; + exit 2; +end else if !with_intf && !with_ml then begin + fprintf stderr "ocamlcp cannot deal with both \"-intf\" and .ml files\n"; + fprintf stderr "please compile interfaces and implementations separately\n"; + exit 2; +end; +if !with_impl then profargs := "-impl" :: !profargs; +if !with_intf then profargs := "-intf" :: !profargs; +let status = + Sys.command + (Printf.sprintf "ocamlc -pp \"ocamlprof -instrument %s\" %s %s" + (String.concat " " (List.rev !profargs)) + (if !make_archive then "" else "profiling.cmo") + (String.concat " " (List.rev !compargs))) +in +exit status +;; diff --git a/tools/ocamldep.ml b/tools/ocamldep.ml new file mode 100644 index 0000000..e688f23 --- /dev/null +++ b/tools/ocamldep.ml @@ -0,0 +1,303 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocamldep.ml,v 1.44 2008-08-01 09:02:55 xleroy Exp $ *) + +open Format +open Location +open Longident +open Parsetree + + +(* Print the dependencies *) + +let load_path = ref ([] : (string * string array) list) +let native_only = ref false +let force_slash = ref false +let error_occurred = ref false +let raw_dependencies = ref false + +(* Fix path to use '/' as directory separator instead of '\'. + Only under Windows. *) + +let fix_slash s = + if Sys.os_type = "Unix" then s else begin + let r = String.copy s in + for i = 0 to String.length r - 1 do + if r.[i] = '\\' then r.[i] <- '/' + done; + r + end + +let add_to_load_path dir = + try + let dir = Misc.expand_directory Config.standard_library dir in + let contents = Sys.readdir dir in + load_path := !load_path @ [dir, contents] + with Sys_error msg -> + fprintf Format.err_formatter "@[Bad -I option: %s@]@." msg; + error_occurred := true + +let find_file name = + let uname = String.uncapitalize name in + let rec find_in_array a pos = + if pos >= Array.length a then None else begin + let s = a.(pos) in + if s = name || s = uname then Some s else find_in_array a (pos + 1) + end in + let rec find_in_path = function + [] -> raise Not_found + | (dir, contents) :: rem -> + match find_in_array contents 0 with + Some truename -> + if dir = "." then truename else Filename.concat dir truename + | None -> find_in_path rem in + find_in_path !load_path + +let find_dependency modname (byt_deps, opt_deps) = + try + let filename = find_file (modname ^ ".mli") in + let basename = Filename.chop_suffix filename ".mli" in + let optname = + if Sys.file_exists (basename ^ ".ml") + then basename ^ ".cmx" + else basename ^ ".cmi" in + ((basename ^ ".cmi") :: byt_deps, optname :: opt_deps) + with Not_found -> + try + let filename = find_file (modname ^ ".ml") in + let basename = Filename.chop_suffix filename ".ml" in + let bytename = + basename ^ (if !native_only then ".cmx" else ".cmo") in + (bytename :: byt_deps, (basename ^ ".cmx") :: opt_deps) + with Not_found -> + (byt_deps, opt_deps) + +let (depends_on, escaped_eol) = (": ", "\\\n ") + +let print_filename s = + let s = if !force_slash then fix_slash s else s in + if not (String.contains s ' ') then begin + print_string s; + end else begin + let rec count n i = + if i >= String.length s then n + else if s.[i] = ' ' then count (n+1) (i+1) + else count n (i+1) + in + let spaces = count 0 0 in + let result = String.create (String.length s + spaces) in + let rec loop i j = + if i >= String.length s then () + else if s.[i] = ' ' then begin + result.[j] <- '\\'; + result.[j+1] <- ' '; + loop (i+1) (j+2); + end else begin + result.[j] <- s.[i]; + loop (i+1) (j+1); + end + in + loop 0 0; + print_string result; + end +;; + +let print_dependencies target_file deps = + print_filename target_file; print_string depends_on; + let rec print_items pos = function + [] -> print_string "\n" + | dep :: rem -> + if pos + String.length dep <= 77 then begin + print_filename dep; print_string " "; + print_items (pos + String.length dep + 1) rem + end else begin + print_string escaped_eol; print_filename dep; print_string " "; + print_items (String.length dep + 5) rem + end in + print_items (String.length target_file + 2) deps + +let print_raw_dependencies source_file deps = + print_filename source_file; print_string ":"; + Depend.StringSet.iter + (fun dep -> print_char ' '; print_string dep) + deps; + print_char '\n' + +(* Optionally preprocess a source file *) + +let preprocessor = ref None + +exception Preprocessing_error + +let preprocess sourcefile = + match !preprocessor with + None -> sourcefile + | Some pp -> + flush stdout; + let tmpfile = Filename.temp_file "camlpp" "" in + let comm = Printf.sprintf "%s %s > %s" pp sourcefile tmpfile in + if Sys.command comm <> 0 then begin + Misc.remove_file tmpfile; + raise Preprocessing_error + end; + tmpfile + +let remove_preprocessed inputfile = + match !preprocessor with + None -> () + | Some _ -> Misc.remove_file inputfile + +(* Parse a file or get a dumped syntax tree in it *) + +let is_ast_file ic ast_magic = + try + let buffer = String.create (String.length ast_magic) in + really_input ic buffer 0 (String.length ast_magic); + if buffer = ast_magic then true + else if String.sub buffer 0 9 = String.sub ast_magic 0 9 then + failwith "Ocaml and preprocessor have incompatible versions" + else false + with End_of_file -> false + +let parse_use_file ic = + if is_ast_file ic Config.ast_impl_magic_number then + let _source_file = input_value ic in + [Ptop_def (input_value ic : Parsetree.structure)] + else begin + seek_in ic 0; + let lb = Lexing.from_channel ic in + Parse.use_file lb + end + +let parse_interface ic = + if is_ast_file ic Config.ast_intf_magic_number then + let _source_file = input_value ic in + (input_value ic : Parsetree.signature) + else begin + seek_in ic 0; + let lb = Lexing.from_channel ic in + Parse.interface lb + end + +(* Process one file *) + +let ml_file_dependencies source_file = + Depend.free_structure_names := Depend.StringSet.empty; + let input_file = preprocess source_file in + let ic = open_in_bin input_file in + try + let ast = parse_use_file ic in + Depend.add_use_file Depend.StringSet.empty ast; + if !raw_dependencies then begin + print_raw_dependencies source_file !Depend.free_structure_names + end else begin + let basename = Filename.chop_extension source_file in + let init_deps = + if Sys.file_exists (basename ^ ".mli") + then let cmi_name = basename ^ ".cmi" in ([cmi_name], [cmi_name]) + else ([], []) in + let (byt_deps, opt_deps) = + Depend.StringSet.fold find_dependency + !Depend.free_structure_names init_deps in + print_dependencies (basename ^ ".cmo") byt_deps; + print_dependencies (basename ^ ".cmx") opt_deps + end; + close_in ic; remove_preprocessed input_file + with x -> + close_in ic; remove_preprocessed input_file; raise x + +let mli_file_dependencies source_file = + Depend.free_structure_names := Depend.StringSet.empty; + let input_file = preprocess source_file in + let ic = open_in_bin input_file in + try + let ast = parse_interface ic in + Depend.add_signature Depend.StringSet.empty ast; + if !raw_dependencies then begin + print_raw_dependencies source_file !Depend.free_structure_names + end else begin + let basename = Filename.chop_extension source_file in + let (byt_deps, opt_deps) = + Depend.StringSet.fold find_dependency + !Depend.free_structure_names ([], []) in + print_dependencies (basename ^ ".cmi") byt_deps + end; + close_in ic; remove_preprocessed input_file + with x -> + close_in ic; remove_preprocessed input_file; raise x + +type file_kind = ML | MLI;; + +let file_dependencies_as kind source_file = + Location.input_name := source_file; + try + if Sys.file_exists source_file then begin + match kind with + | ML -> ml_file_dependencies source_file + | MLI -> mli_file_dependencies source_file + end + with x -> + let report_err = function + | Lexer.Error(err, range) -> + fprintf Format.err_formatter "@[%a%a@]@." + Location.print_error range Lexer.report_error err + | Syntaxerr.Error err -> + fprintf Format.err_formatter "@[%a@]@." + Syntaxerr.report_error err + | Sys_error msg -> + fprintf Format.err_formatter "@[I/O error:@ %s@]@." msg + | Preprocessing_error -> + fprintf Format.err_formatter "@[Preprocessing error on file %s@]@." + source_file + | x -> raise x in + error_occurred := true; + report_err x + +let file_dependencies source_file = + if Filename.check_suffix source_file ".ml" then + file_dependencies_as ML source_file + else if Filename.check_suffix source_file ".mli" then + file_dependencies_as MLI source_file + else () + +(* Entry point *) + +let usage = "Usage: ocamldep [options] <source files>\nOptions are:" + +let print_version () = + printf "ocamldep, version %s@." Sys.ocaml_version; + exit 0; +;; + +let _ = + Clflags.classic := false; + add_to_load_path Filename.current_dir_name; + Arg.parse [ + "-I", Arg.String add_to_load_path, + "<dir> Add <dir> to the list of include directories"; + "-impl", Arg.String (file_dependencies_as ML), + "<f> Process <f> as a .ml file"; + "-intf", Arg.String (file_dependencies_as MLI), + "<f> Process <f> as a .mli file"; + "-modules", Arg.Set raw_dependencies, + " Print module dependencies in raw form (not suitable for make)"; + "-native", Arg.Set native_only, + " Generate dependencies for a pure native-code project (no .cmo files)"; + "-pp", Arg.String(fun s -> preprocessor := Some s), + "<cmd> Pipe sources through preprocessor <cmd>"; + "-slash", Arg.Set force_slash, + " (Windows) Use forward slash / instead of backslash \\ in file paths"; + "-version", Arg.Unit print_version, + " Print version and exit"; + ] file_dependencies usage; + exit (if !error_occurred then 2 else 0) diff --git a/tools/ocamlmklib.mlp b/tools/ocamlmklib.mlp new file mode 100644 index 0000000..fe63ebc --- /dev/null +++ b/tools/ocamlmklib.mlp @@ -0,0 +1,269 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocamlmklib.mlp,v 1.16 2008-01-08 15:39:47 doligez Exp $ *) + +open Printf +open Myocamlbuild_config + +let bytecode_objs = ref [] (* .cmo,.cma,.ml,.mli files to pass to ocamlc *) +and native_objs = ref [] (* .cmx,.cmxa,.ml,.mli files to pass to ocamlopt *) +and c_objs = ref [] (* .o, .a, .obj, .lib, .dll files to pass to mksharedlib and ar *) +and caml_libs = ref [] (* -cclib to pass to ocamlc, ocamlopt *) +and caml_opts = ref [] (* -ccopt to pass to ocamlc, ocamlopt *) +and dynlink = ref supports_shared_libraries +and failsafe = ref false (* whether to fall back on static build only *) +and c_libs = ref [] (* libs to pass to mksharedlib and ocamlc -cclib *) +and c_opts = ref [] (* options to pass to mksharedlib and ocamlc -ccopt *) +and ld_opts = ref [] (* options to pass only to the linker *) +and ocamlc = ref (Filename.concat bindir "ocamlc") +and ocamlopt = ref (Filename.concat bindir "ocamlopt") +and output = ref "a" (* Output name for Caml part of library *) +and output_c = ref "" (* Output name for C part of library *) +and rpath = ref [] (* rpath options *) +and verbose = ref false + +let starts_with s pref = + String.length s >= String.length pref && + String.sub s 0 (String.length pref) = pref +let ends_with = Filename.check_suffix +let chop_prefix s pref = + String.sub s (String.length pref) (String.length s - String.length pref) +let chop_suffix = Filename.chop_suffix + +exception Bad_argument of string + +let print_version () = + printf "ocamlmklib, version %s\n" Sys.ocaml_version; + exit 0; +;; + +let parse_arguments argv = + let i = ref 1 in + let next_arg () = + if !i + 1 >= Array.length argv + then raise (Bad_argument("Option " ^ argv.(!i) ^ " expects one argument")); + incr i; argv.(!i) in + while !i < Array.length argv do + let s = argv.(!i) in + if ends_with s ".cmo" || ends_with s ".cma" then + bytecode_objs := s :: !bytecode_objs + else if ends_with s ".cmx" || ends_with s ".cmxa" then + native_objs := s :: !native_objs + else if ends_with s ".ml" || ends_with s ".mli" then + (bytecode_objs := s :: !bytecode_objs; + native_objs := s :: !native_objs) + else if List.exists (ends_with s) [".o"; ".a"; ".obj"; ".lib"; ".dll"] then + c_objs := s :: !c_objs + else if s = "-cclib" then + caml_libs := next_arg () :: "-cclib" :: !caml_libs + else if s = "-ccopt" then + caml_opts := next_arg () :: "-ccopt" :: !caml_opts + else if s = "-custom" then + dynlink := false + else if s = "-I" then + caml_opts := next_arg () :: "-I" :: !caml_opts + else if s = "-failsafe" then + failsafe := true + else if s = "-h" || s = "-help" || s = "--help" then + raise (Bad_argument "") + else if s = "-ldopt" then + ld_opts := next_arg () :: !ld_opts + else if s = "-linkall" then + caml_opts := s :: !caml_opts + else if starts_with s "-l" then + c_libs := s :: !c_libs + else if starts_with s "-L" then + (c_opts := s :: !c_opts; + let l = chop_prefix s "-L" in + if not (Filename.is_relative l) then rpath := l :: !rpath) + else if s = "-ocamlc" then + ocamlc := next_arg () + else if s = "-ocamlopt" then + ocamlopt := next_arg () + else if s = "-o" then + output := next_arg() + else if s = "-oc" then + output_c := next_arg() + else if s = "-dllpath" || s = "-R" || s = "-rpath" then + rpath := next_arg() :: !rpath + else if starts_with s "-R" then + rpath := chop_prefix s "-R" :: !rpath + else if s = "-Wl,-rpath" then + (let a = next_arg() in + if starts_with a "-Wl," + then rpath := chop_prefix a "-Wl," :: !rpath + else raise (Bad_argument("Option -Wl,-rpath expects a -Wl, argument"))) + else if starts_with s "-Wl,-rpath," then + rpath := chop_prefix s "-Wl,-rpath," :: !rpath + else if starts_with s "-Wl,-R" then + rpath := chop_prefix s "-Wl,-R" :: !rpath + else if s = "-v" || s = "-verbose" then + verbose := true + else if s = "-version" then + print_version () + else if starts_with s "-F" then + c_opts := s :: !c_opts + else if s = "-framework" then + (let a = next_arg() in c_opts := a :: s :: !c_opts) + else if starts_with s "-" then + prerr_endline ("Unknown option " ^ s) + else + raise (Bad_argument("Don't know what to do with " ^ s)); + incr i + done; + List.iter + (fun r -> r := List.rev !r) + [ bytecode_objs; native_objs; c_objs; caml_libs; caml_opts; + c_libs; c_objs; c_opts; ld_opts; rpath ]; + (* On retourne deux fois c_objs ?? -- AF *) + + if !output_c = "" then output_c := !output + +let usage = "\ +Usage: ocamlmklib [options] <.cmo|.cma|.cmx|.cmxa|.ml|.mli|.o|.a|.obj|.lib|.dll files> +Options are: + -cclib <lib> C library passed to ocamlc -a or ocamlopt -a only + -ccopt <opt> C option passed to ocamlc -a or ocamlopt -a only + -custom disable dynamic loading + -dllpath <dir> Add <dir> to the run-time search path for DLLs + -F<dir> Specify a framework directory (MacOSX) + -framework <name> Use framework <name> (MacOSX) + -help Print this help message and exit + --help Same as -help + -h Same as -help + -I <dir> Add <dir> to the path searched for Caml object files + -failsafe fall back to static linking if DLL construction failed + -ldopt <opt> C option passed to the shared linker only + -linkall Build Caml archive with link-all behavior + -l<lib> Specify a dependent C library + -L<dir> Add <dir> to the path searched for C libraries + -ocamlc <cmd> Use <cmd> in place of \"ocamlc\" + -ocamlopt <cmd> Use <cmd> in place of \"ocamlopt\" + -o <name> Generated Caml library is named <name>.cma or <name>.cmxa + -oc <name> Generated C library is named dll<name>.so or lib<name>.a + -rpath <dir> Same as -dllpath <dir> + -R<dir> Same as -rpath + -verbose Print commands before executing them + -v same as -verbose + -version Print version and exit + -Wl,-rpath,<dir> Same as -dllpath <dir> + -Wl,-rpath -Wl,<dir> Same as -dllpath <dir> + -Wl,-R<dir> Same as -dllpath <dir> +" + +let command cmd = + if !verbose then (print_string "+ "; print_string cmd; print_newline()); + Sys.command cmd + +let scommand cmd = + if command cmd <> 0 then exit 2 + +let safe_remove s = + try Sys.remove s with Sys_error _ -> () + +let make_set l = + let rec merge l = function + [] -> List.rev l + | p :: r -> if List.mem p l then merge l r else merge (p::l) r + in + merge [] l + +let make_rpath flag = + if !rpath = [] || flag = "" + then "" + else flag ^ String.concat ":" (make_set !rpath) + +let make_rpath_ccopt flag = + if !rpath = [] || flag = "" + then "" + else "-ccopt " ^ flag ^ String.concat ":" (make_set !rpath) + +let prefix_list pref l = + List.map (fun s -> pref ^ s) l + +let prepostfix pre name post = + let base = Filename.basename name in + let dir = Filename.dirname name in + Filename.concat dir (pre ^ base ^ post) +;; + +let transl_path s = + match Sys.os_type with + | "Win32" -> + let rec aux i = + if i = String.length s || s.[i] = ' ' then s + else (if s.[i] = '/' then s.[i] <- '\\'; aux (i + 1)) + in aux 0 + | _ -> s + +let build_libs () = + if !c_objs <> [] then begin + if !dynlink then begin + let retcode = command + (Printf.sprintf "%s -o %s %s %s %s %s %s" + mkdll + (prepostfix "dll" !output_c ext_dll) + (String.concat " " !c_objs) + (String.concat " " !c_opts) + (String.concat " " !ld_opts) + (make_rpath mksharedlibrpath) + (String.concat " " !c_libs) + ) + in + if retcode <> 0 then if !failsafe then dynlink := false else exit 2 + end; + safe_remove (prepostfix "lib" !output_c ext_lib); + scommand + (mklib (prepostfix "lib" !output_c ext_lib) + (String.concat " " !c_objs) ""); + end; + if !bytecode_objs <> [] then + scommand + (sprintf "%s -a %s -o %s.cma %s %s -dllib -l%s -cclib -l%s %s %s %s %s" + (transl_path !ocamlc) + (if !dynlink then "" else "-custom") + !output + (String.concat " " !caml_opts) + (String.concat " " !bytecode_objs) + (Filename.basename !output_c) + (Filename.basename !output_c) + (String.concat " " (prefix_list "-ccopt " !c_opts)) + (make_rpath_ccopt byteccrpath) + (String.concat " " (prefix_list "-cclib " !c_libs)) + (String.concat " " !caml_libs)); + if !native_objs <> [] then + scommand + (sprintf "%s -a -o %s.cmxa %s %s -cclib -l%s %s %s %s %s" + (transl_path !ocamlopt) + !output + (String.concat " " !caml_opts) + (String.concat " " !native_objs) + (Filename.basename !output_c) + (String.concat " " (prefix_list "-ccopt " !c_opts)) + (make_rpath_ccopt nativeccrpath) + (String.concat " " (prefix_list "-cclib " !c_libs)) + (String.concat " " !caml_libs)) + +let _ = + try + parse_arguments Sys.argv; + build_libs() + with + | Bad_argument "" -> + prerr_string usage; exit 0 + | Bad_argument s -> + prerr_endline s; prerr_string usage; exit 4 + | Sys_error s -> + prerr_string "System error: "; prerr_endline s; exit 4 + | x -> + raise x diff --git a/tools/ocamlmktop.ml b/tools/ocamlmktop.ml new file mode 100644 index 0000000..02cd5c7 --- /dev/null +++ b/tools/ocamlmktop.ml @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocamlmktop.ml,v 1.6 2003-03-24 15:27:01 xleroy Exp $ *) + +let _ = + let args = Ccomp.quote_files (List.tl (Array.to_list Sys.argv)) in + exit(Sys.command("ocamlc -linkall toplevellib.cma " ^ args ^ " topstart.cmo")) diff --git a/tools/ocamlmktop.tpl b/tools/ocamlmktop.tpl new file mode 100644 index 0000000..ce0d796 --- /dev/null +++ b/tools/ocamlmktop.tpl @@ -0,0 +1,16 @@ +#!/bin/sh +######################################################################### +# # +# Objective Caml # +# # +# Damien Doligez, projet Para, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: ocamlmktop.tpl,v 1.5 2004-02-22 14:52:50 xleroy Exp $ + +exec %%BINDIR%%/ocamlc -linkall toplevellib.cma "$@" topstart.cmo diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml new file mode 100644 index 0000000..240e90f --- /dev/null +++ b/tools/ocamlprof.ml @@ -0,0 +1,491 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez and Francois Rouaix, INRIA Rocquencourt *) +(* Ported to Caml Special Light by John Malecki *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ocamlprof.ml,v 1.42 2007-12-04 13:38:58 doligez Exp $ *) + +open Printf + +open Clflags +open Config +open Location +open Misc +open Parsetree + +(* User programs must not use identifiers that start with these prefixes. *) +let idprefix = "__ocaml_prof_";; +let modprefix = "OCAML__prof_";; + +(* Errors specific to the profiler *) +exception Profiler of string + +(* Modes *) +let instr_fun = ref false +and instr_match = ref false +and instr_if = ref false +and instr_loops = ref false +and instr_try = ref false + +let cur_point = ref 0 +and inchan = ref stdin +and outchan = ref stdout + +(* To copy source fragments *) +let copy_buffer = String.create 256 + +let copy_chars_unix nchars = + let n = ref nchars in + while !n > 0 do + let m = input !inchan copy_buffer 0 (min !n 256) in + if m = 0 then raise End_of_file; + output !outchan copy_buffer 0 m; + n := !n - m + done + +let copy_chars_win32 nchars = + for i = 1 to nchars do + let c = input_char !inchan in + if c <> '\r' then output_char !outchan c + done + +let copy_chars = + match Sys.os_type with + "Win32" | "Cygwin" -> copy_chars_win32 + | _ -> copy_chars_unix + +let copy next = + assert (next >= !cur_point); + seek_in !inchan !cur_point; + copy_chars (next - !cur_point); + cur_point := next; +;; + +let prof_counter = ref 0;; + +let instr_mode = ref false + +type insert = Open | Close;; +let to_insert = ref ([] : (insert * int) list);; + +let insert_action st en = + to_insert := (Open, st) :: (Close, en) :: !to_insert +;; + +(* Producing instrumented code *) +let add_incr_counter modul (kind,pos) = + copy pos; + match kind with + | Open -> + fprintf !outchan "(%sProfiling.incr %s%s_cnt %d; " + modprefix idprefix modul !prof_counter; + incr prof_counter; + | Close -> fprintf !outchan ")"; +;; + +let counters = ref (Array.create 0 0) + +(* User defined marker *) +let special_id = ref "" + +(* Producing results of profile run *) +let add_val_counter (kind,pos) = + if kind = Open then begin + copy pos; + fprintf !outchan "(* %s%d *) " !special_id !counters.(!prof_counter); + incr prof_counter; + end +;; + +(* ************* rewrite ************* *) + +let insert_profile rw_exp ex = + let st = ex.pexp_loc.loc_start.Lexing.pos_cnum + and en = ex.pexp_loc.loc_end.Lexing.pos_cnum + and gh = ex.pexp_loc.loc_ghost + in + if gh || st = en then + rw_exp true ex + else begin + insert_action st en; + rw_exp false ex; + end +;; + + +let pos_len = ref 0 + +let init_rewrite modes mod_name = + cur_point := 0; + if !instr_mode then begin + fprintf !outchan "module %sProfiling = Profiling;; " modprefix; + fprintf !outchan "let %s%s_cnt = Array.create 000000000" idprefix mod_name; + pos_len := pos_out !outchan; + fprintf !outchan + " 0;; Profiling.counters := \ + (\"%s\", (\"%s\", %s%s_cnt)) :: !Profiling.counters;; " + mod_name modes idprefix mod_name; + end + +let final_rewrite add_function = + to_insert := Sort.list (fun x y -> snd x < snd y) !to_insert; + prof_counter := 0; + List.iter add_function !to_insert; + copy (in_channel_length !inchan); + if !instr_mode then begin + let len = string_of_int !prof_counter in + if String.length len > 9 then raise (Profiler "too many counters"); + seek_out !outchan (!pos_len - String.length len); + output_string !outchan len + end; + (* Cannot close because outchan is stdout and Format doesn't like + a closed stdout. + close_out !outchan; + *) +;; + +let rec rewrite_patexp_list iflag l = + rewrite_exp_list iflag (List.map snd l) + +and rewrite_patlexp_list iflag l = + rewrite_exp_list iflag (List.map snd l) + +and rewrite_labelexp_list iflag l = + rewrite_exp_list iflag (List.map snd l) + +and rewrite_exp_list iflag l = + List.iter (rewrite_exp iflag) l + +and rewrite_exp iflag sexp = + if iflag then insert_profile rw_exp sexp + else rw_exp false sexp + +and rw_exp iflag sexp = + match sexp.pexp_desc with + Pexp_ident lid -> () + | Pexp_constant cst -> () + + | Pexp_let(_, spat_sexp_list, sbody) -> + rewrite_patexp_list iflag spat_sexp_list; + rewrite_exp iflag sbody + + | Pexp_function (_, _, caselist) -> + if !instr_fun then + rewrite_function iflag caselist + else + rewrite_patlexp_list iflag caselist + + | Pexp_match(sarg, caselist) -> + rewrite_exp iflag sarg; + if !instr_match && not sexp.pexp_loc.loc_ghost then + rewrite_funmatching caselist + else + rewrite_patlexp_list iflag caselist + + | Pexp_try(sbody, caselist) -> + rewrite_exp iflag sbody; + if !instr_try && not sexp.pexp_loc.loc_ghost then + rewrite_trymatching caselist + else + rewrite_patexp_list iflag caselist + + | Pexp_apply(sfunct, sargs) -> + rewrite_exp iflag sfunct; + rewrite_exp_list iflag (List.map snd sargs) + + | Pexp_tuple sexpl -> + rewrite_exp_list iflag sexpl + + | Pexp_construct(_, None, _) -> () + | Pexp_construct(_, Some sarg, _) -> + rewrite_exp iflag sarg + + | Pexp_variant(_, None) -> () + | Pexp_variant(_, Some sarg) -> + rewrite_exp iflag sarg + + | Pexp_record(lid_sexp_list, None) -> + rewrite_labelexp_list iflag lid_sexp_list + | Pexp_record(lid_sexp_list, Some sexp) -> + rewrite_exp iflag sexp; + rewrite_labelexp_list iflag lid_sexp_list + + | Pexp_field(sarg, _) -> + rewrite_exp iflag sarg + + | Pexp_setfield(srecord, _, snewval) -> + rewrite_exp iflag srecord; + rewrite_exp iflag snewval + + | Pexp_array(sargl) -> + rewrite_exp_list iflag sargl + + | Pexp_ifthenelse(scond, sifso, None) -> + rewrite_exp iflag scond; + rewrite_ifbody iflag sexp.pexp_loc.loc_ghost sifso + | Pexp_ifthenelse(scond, sifso, Some sifnot) -> + rewrite_exp iflag scond; + rewrite_ifbody iflag sexp.pexp_loc.loc_ghost sifso; + rewrite_ifbody iflag sexp.pexp_loc.loc_ghost sifnot + + | Pexp_sequence(sexp1, sexp2) -> + rewrite_exp iflag sexp1; + rewrite_exp iflag sexp2 + + | Pexp_while(scond, sbody) -> + rewrite_exp iflag scond; + if !instr_loops && not sexp.pexp_loc.loc_ghost + then insert_profile rw_exp sbody + else rewrite_exp iflag sbody + + | Pexp_for(_, slow, shigh, _, sbody) -> + rewrite_exp iflag slow; + rewrite_exp iflag shigh; + if !instr_loops && not sexp.pexp_loc.loc_ghost + then insert_profile rw_exp sbody + else rewrite_exp iflag sbody + + | Pexp_constraint(sarg, _, _) -> + rewrite_exp iflag sarg + + | Pexp_when(scond, sbody) -> + rewrite_exp iflag scond; + rewrite_exp iflag sbody + + | Pexp_send (sobj, _) -> + rewrite_exp iflag sobj + + | Pexp_new _ -> () + + | Pexp_setinstvar (_, sarg) -> + rewrite_exp iflag sarg + + | Pexp_override l -> + List.iter (fun (_, sexp) -> rewrite_exp iflag sexp) l + + | Pexp_letmodule (_, smod, sexp) -> + rewrite_mod iflag smod; + rewrite_exp iflag sexp + + | Pexp_assert (cond) -> rewrite_exp iflag cond + | Pexp_assertfalse -> () + + | Pexp_lazy (expr) -> rewrite_exp iflag expr + + | Pexp_poly (sexp, _) -> rewrite_exp iflag sexp + + | Pexp_object (_, fieldl) -> + List.iter (rewrite_class_field iflag) fieldl + +and rewrite_ifbody iflag ghost sifbody = + if !instr_if && not ghost then + insert_profile rw_exp sifbody + else + rewrite_exp iflag sifbody + +(* called only when !instr_fun *) +and rewrite_annotate_exp_list l = + List.iter + (function + | {pexp_desc = Pexp_when(scond, sbody)} + -> insert_profile rw_exp scond; + insert_profile rw_exp sbody; + | {pexp_desc = Pexp_constraint(sbody, _, _)} (* let f x : t = e *) + -> insert_profile rw_exp sbody + | sexp -> insert_profile rw_exp sexp) + l + +and rewrite_function iflag = function + | [spat, ({pexp_desc = Pexp_function _} as sexp)] -> rewrite_exp iflag sexp + | l -> rewrite_funmatching l + +and rewrite_funmatching l = + rewrite_annotate_exp_list (List.map snd l) + +and rewrite_trymatching l = + rewrite_annotate_exp_list (List.map snd l) + +(* Rewrite a class definition *) + +and rewrite_class_field iflag = + function + Pcf_inher (cexpr, _) -> rewrite_class_expr iflag cexpr + | Pcf_val (_, _, sexp, _) -> rewrite_exp iflag sexp + | Pcf_meth (_, _, ({pexp_desc = Pexp_function _} as sexp), _) -> + rewrite_exp iflag sexp + | Pcf_meth (_, _, sexp, loc) -> + if !instr_fun && not loc.loc_ghost then insert_profile rw_exp sexp + else rewrite_exp iflag sexp + | Pcf_let(_, spat_sexp_list, _) -> + rewrite_patexp_list iflag spat_sexp_list + | Pcf_init sexp -> + rewrite_exp iflag sexp + | Pcf_valvirt _ | Pcf_virt _ | Pcf_cstr _ -> () + +and rewrite_class_expr iflag cexpr = + match cexpr.pcl_desc with + Pcl_constr _ -> () + | Pcl_structure (_, fields) -> + List.iter (rewrite_class_field iflag) fields + | Pcl_fun (_, _, _, cexpr) -> + rewrite_class_expr iflag cexpr + | Pcl_apply (cexpr, exprs) -> + rewrite_class_expr iflag cexpr; + List.iter (rewrite_exp iflag) (List.map snd exprs) + | Pcl_let (_, spat_sexp_list, cexpr) -> + rewrite_patexp_list iflag spat_sexp_list; + rewrite_class_expr iflag cexpr + | Pcl_constraint (cexpr, _) -> + rewrite_class_expr iflag cexpr + +and rewrite_class_declaration iflag cl = + rewrite_class_expr iflag cl.pci_expr + +(* Rewrite a module expression or structure expression *) + +and rewrite_mod iflag smod = + match smod.pmod_desc with + Pmod_ident lid -> () + | Pmod_structure sstr -> List.iter (rewrite_str_item iflag) sstr + | Pmod_functor(param, smty, sbody) -> rewrite_mod iflag sbody + | Pmod_apply(smod1, smod2) -> rewrite_mod iflag smod1; rewrite_mod iflag smod2 + | Pmod_constraint(smod, smty) -> rewrite_mod iflag smod + +and rewrite_str_item iflag item = + match item.pstr_desc with + Pstr_eval exp -> rewrite_exp iflag exp + | Pstr_value(_, exps) + -> List.iter (function (_,exp) -> rewrite_exp iflag exp) exps + | Pstr_module(name, smod) -> rewrite_mod iflag smod + | Pstr_class classes -> List.iter (rewrite_class_declaration iflag) classes + | _ -> () + +(* Rewrite a .ml file *) +let rewrite_file srcfile add_function = + inchan := open_in_bin srcfile; + let lb = Lexing.from_channel !inchan in + Location.input_name := srcfile; + Location.init lb srcfile; + List.iter (rewrite_str_item false) (Parse.implementation lb); + final_rewrite add_function; + close_in !inchan + +(* Copy a non-.ml file without change *) +let null_rewrite srcfile = + inchan := open_in_bin srcfile; + copy (in_channel_length !inchan); + close_in !inchan +;; + +(* Setting flags from saved config *) +let set_flags s = + for i = 0 to String.length s - 1 do + match String.get s i with + 'f' -> instr_fun := true + | 'm' -> instr_match := true + | 'i' -> instr_if := true + | 'l' -> instr_loops := true + | 't' -> instr_try := true + | 'a' -> instr_fun := true; instr_match := true; + instr_if := true; instr_loops := true; + instr_try := true + | _ -> () + done + +(* Command-line options *) + +let modes = ref "fm" +let dumpfile = ref "ocamlprof.dump" + +(* Process a file *) + +let process_intf_file filename = null_rewrite filename;; + +let process_impl_file filename = + let modname = Filename.basename(Filename.chop_extension filename) in + (* FIXME should let modname = String.capitalize modname *) + if !instr_mode then begin + (* Instrumentation mode *) + set_flags !modes; + init_rewrite !modes modname; + rewrite_file filename (add_incr_counter modname); + end else begin + (* Results mode *) + let ic = open_in_bin !dumpfile in + let allcounters = + (input_value ic : (string * (string * int array)) list) in + close_in ic; + let (modes, cv) = + try + List.assoc modname allcounters + with Not_found -> + raise(Profiler("Module " ^ modname ^ " not used in this profile.")) + in + counters := cv; + set_flags modes; + init_rewrite modes modname; + rewrite_file filename add_val_counter; + end +;; + +let process_anon_file filename = + if Filename.check_suffix filename ".ml" then + process_impl_file filename + else + process_intf_file filename +;; + +(* Main function *) + +open Format + +let usage = "Usage: ocamlprof <options> <files>\noptions are:" + +let print_version () = + printf "ocamlprof, version %s@." Sys.ocaml_version; + exit 0; +;; + +let main () = + try + Warnings.parse_options false "a"; + Arg.parse [ + "-f", Arg.String (fun s -> dumpfile := s), + "<file> Use <file> as dump file (default ocamlprof.dump)"; + "-F", Arg.String (fun s -> special_id := s), + "<s> Insert string <s> with the counts"; + "-impl", Arg.String process_impl_file, + "<file> Process <file> as a .ml file"; + "-instrument", Arg.Set instr_mode, " (undocumented)"; + "-intf", Arg.String process_intf_file, + "<file> Process <file> as a .mli file"; + "-m", Arg.String (fun s -> modes := s), "<flags> (undocumented)"; + "-version", Arg.Unit print_version, + " Print version and exit"; + ] process_anon_file usage; + exit 0 + with x -> + let report_error ppf = function + | Lexer.Error(err, range) -> + fprintf ppf "@[%a%a@]@." + Location.print_error range Lexer.report_error err + | Syntaxerr.Error err -> + fprintf ppf "@[%a@]@." + Syntaxerr.report_error err + | Profiler msg -> + fprintf ppf "@[%s@]@." msg + | Sys_error msg -> + fprintf ppf "@[I/O error:@ %s@]@." msg + | x -> raise x in + report_error Format.err_formatter x; + exit 2 + +let _ = main () diff --git a/tools/ocamlsize b/tools/ocamlsize new file mode 100755 index 0000000..659543d --- /dev/null +++ b/tools/ocamlsize @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +foreach $f (@ARGV) { + open(FILE, $f) || die("Cannot open $f"); + seek(FILE, -16, 2); + $num_sections = do read_int(); + read(FILE, $magic, 12); + seek(FILE, -16 - 8 * $num_sections, 2); + @secname = (); + @seclength = (); + %length = (); + for ($i = 0; $i < $num_sections; $i++) { + read(FILE, $sec, 4); + $secname[$i] = $sec; + $seclength[$i] = do read_int(); + $length{$sec} = $seclength[$i]; + } + print $f, ":\n" if ($#ARGV > 0); + $path = + $length{'RNTM'} > 0 ? + do read_section('RNTM') : + "(default runtime)\n"; + printf ("\tcode: %-7d data: %-7d symbols: %-7d debug: %-7d\n", + $length{'CODE'}, $length{'DATA'}, + $length{'SYMB'}, $length{'DBUG'}); + printf ("\tmagic number: %s runtime system: %s", + $magic, $path); + close(FILE); +} + +sub read_int { + read(FILE, $buff, 4) == 4 || die("Truncated bytecode file $f"); + @int = unpack("C4", $buff); + return ($int[0] << 24) + ($int[1] << 16) + ($int[2] << 8) + $int[3]; +} + +sub read_section { + local ($sec) = @_; + local ($i, $ofs, $data); + for ($i = $num_sections - 1; $i >= 0; $i--) { + $ofs += $seclength[$i]; + if ($secname[$i] eq $sec) { + seek(FILE, -16 - 8 * $num_sections - $ofs, 2); + read(FILE, $data, $seclength[$i]); + return $data; + } + } + return ''; +} diff --git a/tools/primreq.ml b/tools/primreq.ml new file mode 100644 index 0000000..40992df --- /dev/null +++ b/tools/primreq.ml @@ -0,0 +1,90 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1999 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: primreq.ml,v 1.5 2006-07-05 12:09:18 pouillar Exp $ *) + +(* Determine the set of C primitives required by the given .cmo and .cma + files *) + +open Config +open Cmo_format + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +let defined = ref true +let used = ref false +let exclude_file = ref "" + +let primitives = ref StringSet.empty + +let scan_reloc = function + (Reloc_primitive s, _) -> primitives := StringSet.add s !primitives + | _ -> () + +let scan_prim s = + primitives := StringSet.add s !primitives + +let scan_info cu = + if !used then List.iter scan_reloc cu.cu_reloc; + if !defined then List.iter scan_prim cu.cu_primitives + +let scan_obj filename = + let ic = open_in_bin filename in + let buffer = String.create (String.length cmo_magic_number) in + really_input ic buffer 0 (String.length cmo_magic_number); + if buffer = cmo_magic_number then begin + let cu_pos = input_binary_int ic in + seek_in ic cu_pos; + let cu = (input_value ic : compilation_unit) in + close_in ic; + scan_info cu + end else + if buffer = cma_magic_number then begin + let toc_pos = input_binary_int ic in + seek_in ic toc_pos; + let toc = (input_value ic : library) in + close_in ic; + List.iter scan_info toc.lib_units + end else begin + prerr_endline "Not an object file"; exit 2 + end + +let exclude filename = + let ic = open_in filename in + try + while true do + let s = input_line ic in + primitives := StringSet.remove s !primitives + done + with End_of_file -> close_in ic + | x -> close_in ic; raise x + +let main() = + Arg.parse + ["-used", Arg.Unit(fun () -> used := true; defined := false), + "show primitives referenced in the object files"; + "-defined", Arg.Unit(fun () -> defined := true; used := false), + "show primitives defined in the object files (default)"; + "-all", Arg.Unit(fun () -> defined := true; used := true), + "show primitives defined or referenced in the object files"; + "-exclude", Arg.String(fun s -> exclude_file := s), + "<file> don't print the primitives mentioned in <file>"] + scan_obj + "Usage: primreq [options] <.cmo and .cma files>\nOptions are:"; + if String.length !exclude_file > 0 then exclude !exclude_file; + StringSet.iter + (fun s -> + if s.[0] <> '%' then begin print_string s; print_newline() end) + !primitives; + exit 0 + +let _ = main () diff --git a/tools/profiling.ml b/tools/profiling.ml new file mode 100644 index 0000000..7e84c82 --- /dev/null +++ b/tools/profiling.ml @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez and Francois Rouaix, INRIA Rocquencourt *) +(* Ported to Caml Special Light by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: profiling.ml,v 1.8 2006-11-28 15:59:35 doligez Exp $ *) + +(* Run-time library for profiled programs *) + +type profiling_counters = (string * (string * int array)) list + +let counters = ref ([] : profiling_counters);; +let incr a i = a.(i) <- a.(i) + 1;; + +exception Bad_profile + +let dump_counters () = + let dumpfile = + try Sys.getenv "OCAMLPROF_DUMP" with Not_found -> "ocamlprof.dump" + in + begin try + let ic = open_in_bin dumpfile in + let prevl = (input_value ic : profiling_counters) in + close_in ic; + List.iter2 + (fun (curname, (curmodes,curcount)) (prevname, (prevmodes,prevcount)) -> + if curname <> prevname + || curmodes <> prevmodes + || Array.length curcount <> Array.length prevcount + then raise Bad_profile) + !counters prevl; + List.iter2 + (fun (curname, (_,curcount)) (prevname, (_,prevcount)) -> + for i = 0 to Array.length curcount - 1 do + curcount.(i) <- curcount.(i) + prevcount.(i) + done) + !counters prevl + with _ -> () + end; + begin try + let oc = open_out_bin dumpfile in + output_value oc !counters; + close_out oc + with _ -> () + end + +let _ = at_exit dump_counters + diff --git a/tools/profiling.mli b/tools/profiling.mli new file mode 100644 index 0000000..b587934 --- /dev/null +++ b/tools/profiling.mli @@ -0,0 +1,20 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez and Francois Rouaix, INRIA Rocquencourt *) +(* Ported to Objective Caml by John Malecki and Xavier Leroy *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the GNU Library General Public License, with *) +(* the special exception on linking described in file ../LICENSE. *) +(* *) +(***********************************************************************) + +(* $Id: profiling.mli,v 1.6 2005-03-24 17:20:54 doligez Exp $ *) + +(* Run-time library for profiled programs *) + +val counters: (string * (string * int array)) list ref;; +val incr: int array -> int -> unit;; diff --git a/tools/scrapelabels.ml b/tools/scrapelabels.ml new file mode 100644 index 0000000..88edffb --- /dev/null +++ b/tools/scrapelabels.ml @@ -0,0 +1,289 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jacques Garrigue, Kyoto University RIMS *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: scrapelabels.ml,v 1.6 2001-10-04 01:55:02 garrigue Exp $ *) + +open StdLabels +open Lexer301 + +let input_buffer = Buffer.create 16383 +let input_function ic buf len = + let len = input ic buf 0 len in + Buffer.add_substring input_buffer buf 0 len; + len + +let output_buffer = Buffer.create 16383 + +let modified = ref false + +let modules = + ref [ "Arg"; "BigArray"; "Buffer"; "Condition"; "Dbm"; "Digest"; "Dynlink"; + "Event"; "Filename"; "Format"; "Gc"; "Genlex"; "Graphics"; + "Lexing"; "Marshal"; "Mutex"; "Parsing"; "Pervasives"; "Queue"; + "Sort"; "Stack"; "Str"; "Stream"; "Sys"; + "Thread"; "ThreadUnix"; "Weak" ] + +let stdlabels = ["Array"; "List"; "String"] +let morelabels = ["Hashtbl"; "Map"; "Set"] +let alllabels = ref false +let noopen = ref false + +exception Closing of token + +let convert_impl buffer = + let input_pos = ref 0 in + let copy_input stop = + Buffer.add_substring output_buffer (Buffer.contents input_buffer) + !input_pos (stop - !input_pos); + input_pos := stop + in + let next_token () = + let token = Lexer301.token buffer + and start = Lexing.lexeme_start buffer + and stop = Lexing.lexeme_end buffer in + match token with + RPAREN | RBRACKET |BARRBRACKET | GREATERRBRACKET | END + | RBRACE | GREATERRBRACE -> + raise (Closing token) + | EOF -> + raise End_of_file + | _ -> + (token, start, stop) + in + let openunix = ref None and openstd = ref None and openmore = ref None in + let rec may_start (token, s, e) = + match token with + LIDENT _ -> search_start (dropext (next_token ())) + | UIDENT m when List.mem m !modules -> + may_discard (dropext (next_token ())) + | UIDENT m -> + List.iter ~f: + (fun (set,r) -> + if !r = None && List.mem m ~set then r := Some true) + [stdlabels, openstd; ["Unix"], openunix; morelabels, openmore]; + search_start (next_token ()) + | _ -> search_start (token, s, e) + + and dropext (token, s, e) = + match token with + DOT -> + let (token, s, e) = next_token () in + begin match token with + LPAREN | LBRACKET | LBRACE -> + process_paren (token, s, e); + dropext (next_token ()) + | UIDENT _ | LIDENT _ -> + dropext (next_token ()) + | _ -> + prerr_endline ("bad index at position " ^ string_of_int s); + (token, s, e) + end + | _ -> + (token, s, e) + + and may_discard (token, s, e) = + match token with + TILDE | LABEL _ -> + modified := true; + copy_input s; input_pos := e; + may_discard (next_token ()) + | _ when !alllabels -> + may_discard (next_token ()) + | LPAREN | LBRACKET | LBRACKETBAR | LBRACKETLESS | BEGIN + | LBRACE | LBRACELESS | STRUCT | SIG | OBJECT-> + process_paren (token, s, e); + may_discard (next_token ()) + | PREFIXOP _ -> + may_discard (next_token ()) + | LIDENT _ | UIDENT _ -> + may_discard (dropext (next_token ())) + | BACKQUOTE -> + ignore (next_token ()); + may_discard (next_token ()) + | INT _ | CHAR _ | STRING _ | FLOAT _ | FALSE | TRUE -> + may_discard (next_token ()) + | _ -> + search_start (token, s, e) + + and search_start (token, s, e) = + match token with + LPAREN | LBRACKET | LBRACKETBAR | LBRACKETLESS | BEGIN + | LBRACE | LBRACELESS | STRUCT | SIG | OBJECT -> + process_paren (token, s, e); + search_start (next_token ()) + | EQUAL | SEMI | SEMISEMI | MINUSGREATER | LESSMINUS | COMMA + | IF | THEN | ELSE | WHILE | TO | DOWNTO | DO | IN | MATCH | TRY + | INFIXOP0 _ | INFIXOP1 _ | INFIXOP2 _ | INFIXOP3 _ | INFIXOP4 _ + | PLUS | MINUS | MINUSDOT | STAR | LESS | GREATER + | OR | BARBAR | AMPERSAND | AMPERAMPER | COLONEQUAL -> + may_start (next_token ()) + | OPEN -> + begin match next_token () with + | UIDENT m, _, _ -> + List.iter + ~f:(fun (set,r) -> if List.mem m ~set then r := Some false) + [stdlabels, openstd; ["Unix"], openunix; morelabels, openmore] + | _ -> () + end; + search_start (next_token ()) + | _ -> + search_start (next_token ()) + + and process_paren (token, s, e) = + try match token with + LPAREN | LBRACKET | LBRACKETBAR | LBRACKETLESS | BEGIN -> + may_start (next_token ()) + | LBRACE | LBRACELESS | STRUCT | SIG | OBJECT -> + search_start (next_token ()) + | _ -> + assert false + with Closing last -> + match token, last with + LPAREN, RPAREN + | (LBRACKET|LBRACKETBAR|LBRACKETLESS), + (RBRACKET|BARRBRACKET|GREATERRBRACKET) + | (BEGIN|STRUCT|SIG|OBJECT), END + | LBRACE, RBRACE + | LBRACELESS, GREATERRBRACE -> () + | _ -> raise (Closing last) + in + let first = next_token () in + try + if !alllabels then may_discard first else may_start first + with End_of_file -> + copy_input (Buffer.length input_buffer); + if not !alllabels + && List.exists (fun r -> !r = Some true) [openstd; openunix; openmore] + then begin + modified := true; + let text = Buffer.contents output_buffer in + Buffer.clear output_buffer; + let (token, s, _) = first in + Buffer.add_substring output_buffer text 0 s; + List.iter ~f: + (fun (r, s) -> + if !r = Some true then Buffer.add_string output_buffer s) + [ openstd, "open StdLabels\n"; openmore, "open MoreLabels\n"; + openunix, "module Unix = UnixLabels\n" ]; + let sep = + if List.mem token [CLASS; EXTERNAL; EXCEPTION; FUNCTOR; LET; + MODULE; FUNCTOR; TYPE; VAL] + then "\n" + else if token = OPEN then "" else ";;\n\n" + in + Buffer.add_string output_buffer sep; + Buffer.add_substring output_buffer text s (String.length text - s) + end + | Closing _ -> + prerr_endline ("bad closing token at position " ^ + string_of_int (Lexing.lexeme_start buffer)); + modified := false + +type state = Out | Enter | In | Escape + +let convert_intf buffer = + let input_pos = ref 0 in + let copy_input stop = + Buffer.add_substring output_buffer (Buffer.contents input_buffer) + !input_pos (stop - !input_pos); + input_pos := stop + in + let last = ref (EOF, 0, 0) in + let state = ref Out in + try while true do + let token = Lexer301.token buffer + and start = Lexing.lexeme_start buffer + and stop = Lexing.lexeme_end buffer + and last_token, last_start, last_stop = !last in + begin match token with + | EXCEPTION | CONSTRAINT -> + state := In + | VAL | EXTERNAL | CLASS | METHOD | TYPE | AND -> + state := Enter + | EQUAL when !state = Enter -> + state := In + | COLON -> + begin match !state, last_token with + | In, LIDENT _ -> + modified := true; + copy_input last_start; + input_pos := stop + | Enter, _ -> + state := In + | Escape, _ -> + state := In + | _ -> + state := Out + end + | LBRACE | SEMI | QUESTION when !state = In -> + state := Escape + | SEMISEMI | SIG | STRUCT | END | OBJECT | OPEN | INCLUDE | MODULE -> + state := Out + | EOF -> raise End_of_file + | _ -> () + end; + last := (token, start, stop) + done with + End_of_file -> + copy_input (Buffer.length input_buffer) + +let convert_file ~intf name = + let ic = open_in name in + Buffer.clear input_buffer; + Buffer.clear output_buffer; + modified := false; + begin + let convert = if intf then convert_intf else convert_impl in + try convert (Lexing.from_function (input_function ic)); close_in ic + with exn -> close_in ic; raise exn + end; + if !modified then begin + let backup = name ^ ".bak" in + if Sys.file_exists backup then Sys.remove name + else Sys.rename name backup; + let oc = open_out name in + Buffer.output_buffer oc output_buffer; + close_out oc + end + else prerr_endline ("No changes in " ^ name) + +let _ = + let files = ref [] and intf = ref false + and keepstd = ref false and keepmore = ref false in + Arg.parse + [ "-intf", Arg.Set intf, + " remove all non-optional labels from an interface;\n" ^ + " other options are ignored"; + "-all", Arg.Set alllabels, + " remove all labels, possibly including optional ones!"; + "-keepstd", Arg.Set keepstd, + " keep labels for Array, List, String and Unix"; + "-keepmore", Arg.Set keepmore, + " keep also labels for Hashtbl, Map and Set; implies -keepstd"; + "-m", Arg.String (fun s -> modules := s :: !modules), + "<module> remove also labels for <module>"; + "-noopen", Arg.Set noopen, + " do not insert `open' statements for -keepstd/-keepmore" ] + (fun s -> files := s :: !files) + ("Usage: scrapelabels <options> <source files>\n" ^ + " Remove labels from function arguments in standard library modules.\n" ^ + " With -intf option below, can also process interfaces.\n" ^ + " Old files are renamed to <file>.bak if there is no backup yet.\n" ^ + "Options are:"); + if !keepmore then keepstd := true; + if not !keepstd then modules := "Unix" :: stdlabels @ !modules; + if not !keepmore then modules := morelabels @ !modules; + List.iter (List.rev !files) ~f: + begin fun name -> + prerr_endline ("Processing " ^ name); + Printexc.catch (convert_file ~intf:!intf) name + end diff --git a/toplevel/expunge.ml b/toplevel/expunge.ml new file mode 100644 index 0000000..bcca75b --- /dev/null +++ b/toplevel/expunge.ml @@ -0,0 +1,78 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: expunge.ml,v 1.16 2004-01-16 15:24:03 doligez Exp $ *) + +(* "Expunge" a toplevel by removing compiler modules from the global List.map. + Usage: expunge <source file> <dest file> <names of modules to keep> *) + +open Sys +open Misc + +module StringSet = + Set.Make(struct + type t = string + let compare = compare + end) + +let to_keep = ref StringSet.empty + +let expunge_map tbl = + Symtable.filter_global_map + (fun id -> StringSet.mem (Ident.name id) !to_keep) + tbl + +let expunge_crcs tbl = + List.filter (fun (unit, crc) -> StringSet.mem unit !to_keep) tbl + +let main () = + let input_name = Sys.argv.(1) in + let output_name = Sys.argv.(2) in + Array.iter + (fun exn -> to_keep := StringSet.add exn !to_keep) + Runtimedef.builtin_exceptions; + for i = 3 to Array.length Sys.argv - 1 do + to_keep := StringSet.add (String.capitalize Sys.argv.(i)) !to_keep + done; + let ic = open_in_bin input_name in + Bytesections.read_toc ic; + let toc = Bytesections.toc() in + let pos_first_section = Bytesections.pos_first_section ic in + let oc = + open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] 0o777 + output_name in + (* Copy the file up to the symbol section as is *) + seek_in ic 0; + copy_file_chunk ic oc pos_first_section; + (* Copy each section, modifying the symbol section in passing *) + Bytesections.init_record oc; + List.iter + (fun (name, len) -> + begin match name with + "SYMB" -> + let global_map = (input_value ic : Symtable.global_map) in + output_value oc (expunge_map global_map) + | "CRCS" -> + let crcs = (input_value ic : (string * Digest.t) list) in + output_value oc (expunge_crcs crcs) + | _ -> + copy_file_chunk ic oc len + end; + Bytesections.record oc name) + toc; + (* Rewrite the toc and trailer *) + Bytesections.write_toc_and_trailer oc; + (* Done *) + close_in ic; + close_out oc + +let _ = Printexc.catch main (); exit 0 diff --git a/toplevel/genprintval.ml b/toplevel/genprintval.ml new file mode 100644 index 0000000..f67c0e9 --- /dev/null +++ b/toplevel/genprintval.ml @@ -0,0 +1,363 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: genprintval.ml,v 1.39 2007-10-09 10:29:37 weis Exp $ *) + +(* To print values *) + +open Misc +open Format +open Longident +open Path +open Types +open Outcometree + +module type OBJ = + sig + type t + val obj : t -> 'a + val is_block : t -> bool + val tag : t -> int + val size : t -> int + val field : t -> int -> t + end + +module type EVALPATH = + sig + type value + val eval_path: Path.t -> value + exception Error + val same_value: value -> value -> bool + end + +module type S = + sig + type t + val install_printer : + Path.t -> Types.type_expr -> (formatter -> t -> unit) -> unit + val remove_printer : Path.t -> unit + val outval_of_untyped_exception : t -> Outcometree.out_value + val outval_of_value : + int -> int -> + (int -> t -> Types.type_expr -> Outcometree.out_value option) -> + Env.t -> t -> type_expr -> Outcometree.out_value + end + +module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) = struct + + type t = O.t + + (* Given an exception value, we cannot recover its type, + hence we cannot print its arguments in general. + Here, we do a feeble attempt to print + integer, string and float arguments... *) + let outval_of_untyped_exception_args obj start_offset = + if O.size obj > start_offset then begin + let list = ref [] in + for i = start_offset to O.size obj - 1 do + let arg = O.field obj i in + if not (O.is_block arg) then + list := Oval_int (O.obj arg : int) :: !list + (* Note: this could be a char or a constant constructor... *) + else if O.tag arg = Obj.string_tag then + list := + Oval_string (String.escaped (O.obj arg : string)) :: !list + else if O.tag arg = Obj.double_tag then + list := Oval_float (O.obj arg : float) :: !list + else + list := Oval_constr (Oide_ident "_", []) :: !list + done; + List.rev !list + end + else [] + + let outval_of_untyped_exception bucket = + let name = (O.obj(O.field(O.field bucket 0) 0) : string) in + let args = + if (name = "Match_failure" + || name = "Assert_failure" + || name = "Undefined_recursive_module") + && O.size bucket = 2 + && O.tag(O.field bucket 1) = 0 + then outval_of_untyped_exception_args (O.field bucket 1) 0 + else outval_of_untyped_exception_args bucket 1 in + Oval_constr (Oide_ident name, args) + + (* The user-defined printers. Also used for some builtin types. *) + + let printers = ref ([ + Pident(Ident.create "print_int"), Predef.type_int, + (fun x -> Oval_int (O.obj x : int)); + Pident(Ident.create "print_float"), Predef.type_float, + (fun x -> Oval_float (O.obj x : float)); + Pident(Ident.create "print_char"), Predef.type_char, + (fun x -> Oval_char (O.obj x : char)); + Pident(Ident.create "print_string"), Predef.type_string, + (fun x -> Oval_string (O.obj x : string)); + Pident(Ident.create "print_int32"), Predef.type_int32, + (fun x -> Oval_int32 (O.obj x : int32)); + Pident(Ident.create "print_nativeint"), Predef.type_nativeint, + (fun x -> Oval_nativeint (O.obj x : nativeint)); + Pident(Ident.create "print_int64"), Predef.type_int64, + (fun x -> Oval_int64 (O.obj x : int64)) + ] : (Path.t * type_expr * (O.t -> Outcometree.out_value)) list) + + let install_printer path ty fn = + let print_val ppf obj = + try fn ppf obj with + | exn -> + fprintf ppf "<printer %a raised an exception>" Printtyp.path path in + let printer obj = Oval_printer (fun ppf -> print_val ppf obj) in + printers := (path, ty, printer) :: !printers + + let remove_printer path = + let rec remove = function + | [] -> raise Not_found + | (p, ty, fn as printer) :: rem -> + if Path.same p path then rem else printer :: remove rem in + printers := remove !printers + + let find_printer env ty = + let rec find = function + | [] -> raise Not_found + | (name, sch, printer) :: remainder -> + if Ctype.moregeneral env false sch ty + then printer + else find remainder + in find !printers + + (* Print a constructor or label, giving it the same prefix as the type + it comes from. Attempt to omit the prefix if the type comes from + a module that has been opened. *) + + let tree_of_qualified lookup_fun env ty_path name = + match ty_path with + | Pident id -> + Oide_ident name + | Pdot(p, s, pos) -> + if try + match (lookup_fun (Lident name) env).desc with + | Tconstr(ty_path', _, _) -> Path.same ty_path ty_path' + | _ -> false + with Not_found -> false + then Oide_ident name + else Oide_dot (Printtyp.tree_of_path p, name) + | Papply(p1, p2) -> + Printtyp.tree_of_path ty_path + + let tree_of_constr = + tree_of_qualified + (fun lid env -> (Env.lookup_constructor lid env).cstr_res) + + and tree_of_label = + tree_of_qualified (fun lid env -> (Env.lookup_label lid env).lbl_res) + + (* An abstract type *) + + let abstract_type = + Ctype.newty (Tconstr (Pident (Ident.create "abstract"), [], ref Mnil)) + + (* The main printing function *) + + let outval_of_value max_steps max_depth check_depth env obj ty = + + let printer_steps = ref max_steps in + + let rec tree_of_val depth obj ty = + decr printer_steps; + if !printer_steps < 0 || depth < 0 then Oval_ellipsis + else begin + try + find_printer env ty obj + with Not_found -> + match (Ctype.repr ty).desc with + | Tvar -> + Oval_stuff "<poly>" + | Tarrow(_, ty1, ty2, _) -> + Oval_stuff "<fun>" + | Ttuple(ty_list) -> + Oval_tuple (tree_of_val_list 0 depth obj ty_list) + | Tconstr(path, [], _) when Path.same path Predef.path_exn -> + tree_of_exception depth obj + | Tconstr(path, [ty_arg], _) + when Path.same path Predef.path_list -> + if O.is_block obj then + match check_depth depth obj ty with + Some x -> x + | None -> + let rec tree_of_conses tree_list obj = + if !printer_steps < 0 || depth < 0 then + Oval_ellipsis :: tree_list + else if O.is_block obj then + let tree = + tree_of_val (depth - 1) (O.field obj 0) ty_arg in + let next_obj = O.field obj 1 in + tree_of_conses (tree :: tree_list) next_obj + else tree_list + in + Oval_list (List.rev (tree_of_conses [] obj)) + else + Oval_list [] + | Tconstr(path, [ty_arg], _) + when Path.same path Predef.path_array -> + let length = O.size obj in + if length > 0 then + match check_depth depth obj ty with + Some x -> x + | None -> + let rec tree_of_items tree_list i = + if !printer_steps < 0 || depth < 0 then + Oval_ellipsis :: tree_list + else if i < length then + let tree = + tree_of_val (depth - 1) (O.field obj i) ty_arg in + tree_of_items (tree :: tree_list) (i + 1) + else tree_list + in + Oval_array (List.rev (tree_of_items [] 0)) + else + Oval_array [] + | Tconstr (path, [ty_arg], _) + when Path.same path Predef.path_lazy_t -> + if Lazy.lazy_is_val (O.obj obj) + then let v = tree_of_val depth (Lazy.force (O.obj obj)) ty_arg in + Oval_constr (Oide_ident "lazy", [v]) + else Oval_stuff "<lazy>" + | Tconstr(path, ty_list, _) -> + begin try + let decl = Env.find_type path env in + match decl with + | {type_kind = Type_abstract; type_manifest = None} -> + Oval_stuff "<abstr>" + | {type_kind = Type_abstract; type_manifest = Some body} -> + tree_of_val depth obj + (try Ctype.apply env decl.type_params body ty_list with + Ctype.Cannot_apply -> abstract_type) + | {type_kind = Type_variant constr_list} -> + let tag = + if O.is_block obj + then Cstr_block(O.tag obj) + else Cstr_constant(O.obj obj) in + let (constr_name, constr_args) = + Datarepr.find_constr_by_tag tag constr_list in + let ty_args = + List.map + (function ty -> + try Ctype.apply env decl.type_params ty ty_list with + Ctype.Cannot_apply -> abstract_type) + constr_args in + tree_of_constr_with_args (tree_of_constr env path) + constr_name 0 depth obj ty_args + | {type_kind = Type_record(lbl_list, rep)} -> + begin match check_depth depth obj ty with + Some x -> x + | None -> + let rec tree_of_fields pos = function + | [] -> [] + | (lbl_name, _, lbl_arg) :: remainder -> + let ty_arg = + try + Ctype.apply env decl.type_params lbl_arg + ty_list + with + Ctype.Cannot_apply -> abstract_type in + let lid = tree_of_label env path lbl_name in + let v = + tree_of_val (depth - 1) (O.field obj pos) + ty_arg + in + (lid, v) :: tree_of_fields (pos + 1) remainder + in + Oval_record (tree_of_fields 0 lbl_list) + end + with + Not_found -> (* raised by Env.find_type *) + Oval_stuff "<abstr>" + | Datarepr.Constr_not_found -> (* raised by find_constr_by_tag *) + Oval_stuff "<unknown constructor>" + end + | Tvariant row -> + let row = Btype.row_repr row in + if O.is_block obj then + let tag : int = O.obj (O.field obj 0) in + let rec find = function + | (l, f) :: fields -> + if Btype.hash_variant l = tag then + match Btype.row_field_repr f with + | Rpresent(Some ty) | Reither(_,[ty],_,_) -> + let args = + tree_of_val (depth - 1) (O.field obj 1) ty in + Oval_variant (l, Some args) + | _ -> find fields + else find fields + | [] -> Oval_stuff "<variant>" in + find row.row_fields + else + let tag : int = O.obj obj in + let rec find = function + | (l, _) :: fields -> + if Btype.hash_variant l = tag then + Oval_variant (l, None) + else find fields + | [] -> Oval_stuff "<variant>" in + find row.row_fields + | Tobject (_, _) -> + Oval_stuff "<obj>" + | Tsubst ty -> + tree_of_val (depth - 1) obj ty + | Tfield(_, _, _, _) | Tnil | Tlink _ -> + fatal_error "Printval.outval_of_value" + | Tpoly (ty, _) -> + tree_of_val (depth - 1) obj ty + | Tunivar -> + Oval_stuff "<poly>" + end + + and tree_of_val_list start depth obj ty_list = + let rec tree_list i = function + | [] -> [] + | ty :: ty_list -> + let tree = tree_of_val (depth - 1) (O.field obj i) ty in + tree :: tree_list (i + 1) ty_list in + tree_list start ty_list + + and tree_of_constr_with_args + tree_of_cstr cstr_name start depth obj ty_args = + let lid = tree_of_cstr cstr_name in + let args = tree_of_val_list start depth obj ty_args in + Oval_constr (lid, args) + + and tree_of_exception depth bucket = + let name = (O.obj(O.field(O.field bucket 0) 0) : string) in + let lid = Longident.parse name in + try + (* Attempt to recover the constructor description for the exn + from its name *) + let cstr = Env.lookup_constructor lid env in + let path = + match cstr.cstr_tag with + Cstr_exception p -> p | _ -> raise Not_found in + (* Make sure this is the right exception and not an homonym, + by evaluating the exception found and comparing with the + identifier contained in the exception bucket *) + if not (EVP.same_value (O.field bucket 0) (EVP.eval_path path)) + then raise Not_found; + tree_of_constr_with_args + (fun x -> Oide_ident x) name 1 depth bucket cstr.cstr_args + with Not_found | EVP.Error -> + match check_depth depth bucket ty with + Some x -> x + | None -> outval_of_untyped_exception bucket + + in tree_of_val max_depth obj ty + +end diff --git a/toplevel/genprintval.mli b/toplevel/genprintval.mli new file mode 100644 index 0000000..7a7e209 --- /dev/null +++ b/toplevel/genprintval.mli @@ -0,0 +1,52 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: genprintval.mli,v 1.10 2002-04-18 07:27:44 garrigue Exp $ *) + +(* Printing of values *) + +open Types +open Format + +module type OBJ = + sig + type t + val obj : t -> 'a + val is_block : t -> bool + val tag : t -> int + val size : t -> int + val field : t -> int -> t + end + +module type EVALPATH = + sig + type value + val eval_path: Path.t -> value + exception Error + val same_value: value -> value -> bool + end + +module type S = + sig + type t + val install_printer : + Path.t -> Types.type_expr -> (formatter -> t -> unit) -> unit + val remove_printer : Path.t -> unit + val outval_of_untyped_exception : t -> Outcometree.out_value + val outval_of_value : + int -> int -> + (int -> t -> Types.type_expr -> Outcometree.out_value option) -> + Env.t -> t -> type_expr -> Outcometree.out_value + end + +module Make(O : OBJ)(EVP : EVALPATH with type value = O.t) : + (S with type t = O.t) diff --git a/toplevel/opttopdirs.ml b/toplevel/opttopdirs.ml new file mode 100644 index 0000000..9dcdd2d --- /dev/null +++ b/toplevel/opttopdirs.ml @@ -0,0 +1,189 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttopdirs.ml,v 1.2 2007-11-06 15:16:56 frisch Exp $ *) + +(* Toplevel directives *) + +open Format +open Misc +open Longident +open Path +open Types +open Opttoploop + +(* The standard output formatter *) +let std_out = std_formatter + +(* To quit *) + +let dir_quit () = exit 0 + +let _ = Hashtbl.add directive_table "quit" (Directive_none dir_quit) + +(* To add a directory to the load path *) + +let dir_directory s = + let d = expand_directory Config.standard_library s in + Config.load_path := d :: !Config.load_path + +let _ = Hashtbl.add directive_table "directory" (Directive_string dir_directory) +let _ = Hashtbl.add directive_table "show_dirs" + (Directive_none + (fun () -> + List.iter print_endline !Config.load_path + )) + +(* To change the current directory *) + +let dir_cd s = Sys.chdir s + +let _ = Hashtbl.add directive_table "cd" (Directive_string dir_cd) + +(* Load in-core a .cmxs file *) + +let load_file ppf name0 = + let name = + try Some (find_in_path !Config.load_path name0) + with Not_found -> None in + match name with + | None -> fprintf ppf "File not found: %s@." name0; false + | Some name -> + let fn,tmp = + if Filename.check_suffix name ".cmx" || Filename.check_suffix name ".cmxa" + then + let cmxs = Filename.temp_file "caml" ".cmxs" in + Asmlink.link_shared ppf [name] cmxs; + cmxs,true + else + name,false in + + let success = + (* The Dynlink interface does not allow us to distinguish between + a Dynlink.Error exceptions raised in the loaded modules + or a genuine error during dynlink... *) + try Dynlink.loadfile fn; true + with + | Dynlink.Error err -> + fprintf ppf "Error while loading %s: %s.@." + name (Dynlink.error_message err); + false + | exn -> + print_exception_outcome ppf exn; + false + in + if tmp then (try Sys.remove fn with Sys_error _ -> ()); + success + + +let dir_load ppf name = ignore (load_file ppf name) + +let _ = Hashtbl.add directive_table "load" (Directive_string (dir_load std_out)) + +(* Load commands from a file *) + +let dir_use ppf name = ignore(Opttoploop.use_file ppf name) + +let _ = Hashtbl.add directive_table "use" (Directive_string (dir_use std_out)) + +(* Install, remove a printer *) + +type 'a printer_type_new = Format.formatter -> 'a -> unit +type 'a printer_type_old = 'a -> unit + +let match_printer_type ppf desc typename = + let (printer_type, _) = + try + Env.lookup_type (Ldot(Lident "Topdirs", typename)) !toplevel_env + with Not_found -> + fprintf ppf "Cannot find type Topdirs.%s.@." typename; + raise Exit in + Ctype.init_def(Ident.current_time()); + Ctype.begin_def(); + let ty_arg = Ctype.newvar() in + Ctype.unify !toplevel_env + (Ctype.newconstr printer_type [ty_arg]) + (Ctype.instance desc.val_type); + Ctype.end_def(); + Ctype.generalize ty_arg; + ty_arg + +let find_printer_type ppf lid = + try + let (path, desc) = Env.lookup_value lid !toplevel_env in + let (ty_arg, is_old_style) = + try + (match_printer_type ppf desc "printer_type_new", false) + with Ctype.Unify _ -> + (match_printer_type ppf desc "printer_type_old", true) in + (ty_arg, path, is_old_style) + with + | Not_found -> + fprintf ppf "Unbound value %a.@." Printtyp.longident lid; + raise Exit + | Ctype.Unify _ -> + fprintf ppf "%a has a wrong type for a printing function.@." + Printtyp.longident lid; + raise Exit + +let dir_install_printer ppf lid = + try + let (ty_arg, path, is_old_style) = find_printer_type ppf lid in + let v = eval_path path in + let print_function = + if is_old_style then + (fun formatter repr -> Obj.obj v (Obj.obj repr)) + else + (fun formatter repr -> Obj.obj v formatter (Obj.obj repr)) in + install_printer path ty_arg print_function + with Exit -> () + +let dir_remove_printer ppf lid = + try + let (ty_arg, path, is_old_style) = find_printer_type ppf lid in + begin try + remove_printer path + with Not_found -> + fprintf ppf "No printer named %a.@." Printtyp.longident lid + end + with Exit -> () + +let _ = Hashtbl.add directive_table "install_printer" + (Directive_ident (dir_install_printer std_out)) +let _ = Hashtbl.add directive_table "remove_printer" + (Directive_ident (dir_remove_printer std_out)) + +let parse_warnings ppf iserr s = + try Warnings.parse_options iserr s + with Arg.Bad err -> fprintf ppf "%s.@." err + +let _ = +(* Control the printing of values *) + + Hashtbl.add directive_table "print_depth" + (Directive_int(fun n -> max_printer_depth := n)); + Hashtbl.add directive_table "print_length" + (Directive_int(fun n -> max_printer_steps := n)); + +(* Set various compiler flags *) + + Hashtbl.add directive_table "labels" + (Directive_bool(fun b -> Clflags.classic := not b)); + + Hashtbl.add directive_table "principal" + (Directive_bool(fun b -> Clflags.principal := b)); + + Hashtbl.add directive_table "warnings" + (Directive_string (parse_warnings std_out false)); + + Hashtbl.add directive_table "warn_error" + (Directive_string (parse_warnings std_out true)) diff --git a/toplevel/opttopdirs.mli b/toplevel/opttopdirs.mli new file mode 100644 index 0000000..9974699 --- /dev/null +++ b/toplevel/opttopdirs.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttopdirs.mli,v 1.2 2007-11-06 15:16:56 frisch Exp $ *) + +(* The toplevel directives. *) + +open Format + +val dir_quit : unit -> unit +val dir_directory : string -> unit +val dir_cd : string -> unit +val dir_load : formatter -> string -> unit +val dir_use : formatter -> string -> unit +val dir_install_printer : formatter -> Longident.t -> unit +val dir_remove_printer : formatter -> Longident.t -> unit + +type 'a printer_type_new = Format.formatter -> 'a -> unit +type 'a printer_type_old = 'a -> unit + +(* For topmain.ml. Maybe shouldn't be there *) +val load_file : formatter -> string -> bool diff --git a/toplevel/opttoploop.ml b/toplevel/opttoploop.ml new file mode 100644 index 0000000..029ea34 --- /dev/null +++ b/toplevel/opttoploop.ml @@ -0,0 +1,446 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttoploop.ml,v 1.3 2007-12-04 13:38:58 doligez Exp $ *) + +(* The interactive toplevel loop *) + +open Path +open Lexing +open Format +open Config +open Misc +open Parsetree +open Types +open Typedtree +open Outcometree +open Lambda + +type res = Ok of Obj.t | Err of string +type evaluation_outcome = Result of Obj.t | Exception of exn + +external ndl_run_toplevel: string -> string -> res + = "caml_natdynlink_run_toplevel" +external ndl_loadsym: string -> Obj.t = "caml_natdynlink_loadsym" + +let global_symbol id = + let sym = Compilenv.symbol_for_global id in + try ndl_loadsym sym + with _ -> fatal_error ("Opttoploop.global_symbol " ^ (Ident.unique_name id)) + +let need_symbol sym = + try ignore (ndl_loadsym sym); false + with _ -> true + +let dll_run dll entry = + match (try Result (Obj.magic (ndl_run_toplevel dll entry)) with exn -> Exception exn) with + | Exception _ as r -> r + | Result r -> + match Obj.magic r with + | Ok x -> Result x + | Err s -> fatal_error ("Opttoploop.dll_run " ^ s) + + +type directive_fun = + | Directive_none of (unit -> unit) + | Directive_string of (string -> unit) + | Directive_int of (int -> unit) + | Directive_ident of (Longident.t -> unit) + | Directive_bool of (bool -> unit) + + +(* Return the value referred to by a path *) + +let toplevel_value id = + let (glb,pos) = Translmod.nat_toplevel_name id in + (Obj.magic (global_symbol glb)).(pos) + +let rec eval_path = function + | Pident id -> + if Ident.persistent id || Ident.global id + then global_symbol id + else toplevel_value id + | Pdot(p, s, pos) -> + Obj.field (eval_path p) pos + | Papply(p1, p2) -> + fatal_error "Toploop.eval_path" + +(* To print values *) + +module EvalPath = struct + type value = Obj.t + exception Error + let eval_path p = try eval_path p with _ -> raise Error + let same_value v1 v2 = (v1 == v2) +end + +module Printer = Genprintval.Make(Obj)(EvalPath) + +let max_printer_depth = ref 100 +let max_printer_steps = ref 300 + +let print_out_value = Oprint.out_value +let print_out_type = Oprint.out_type +let print_out_class_type = Oprint.out_class_type +let print_out_module_type = Oprint.out_module_type +let print_out_sig_item = Oprint.out_sig_item +let print_out_signature = Oprint.out_signature +let print_out_phrase = Oprint.out_phrase + +let print_untyped_exception ppf obj = + !print_out_value ppf (Printer.outval_of_untyped_exception obj) +let outval_of_value env obj ty = + Printer.outval_of_value !max_printer_steps !max_printer_depth + (fun _ _ _ -> None) env obj ty +let print_value env obj ppf ty = + !print_out_value ppf (outval_of_value env obj ty) + +let install_printer = Printer.install_printer +let remove_printer = Printer.remove_printer + +(* Hooks for parsing functions *) + +let parse_toplevel_phrase = ref Parse.toplevel_phrase +let parse_use_file = ref Parse.use_file +let print_location = Location.print_error (* FIXME change back to print *) +let print_error = Location.print_error +let print_warning = Location.print_warning +let input_name = Location.input_name + +(* Hooks for initialization *) + +let toplevel_startup_hook = ref (fun () -> ()) + +(* Load in-core and execute a lambda term *) + +let phrase_seqid = ref 0 +let phrase_name = ref "TOP" + +open Lambda + +let load_lambda ppf (size, lam) = + if !Clflags.dump_rawlambda then fprintf ppf "%a@." Printlambda.lambda lam; + let slam = Simplif.simplify_lambda lam in + if !Clflags.dump_lambda then fprintf ppf "%a@." Printlambda.lambda slam; + + let dll = + if !Clflags.keep_asm_file then !phrase_name ^ ext_dll + else Filename.temp_file ("caml" ^ !phrase_name) ext_dll + in + let fn = Filename.chop_extension dll in + Asmgen.compile_implementation ~toplevel:need_symbol fn ppf (size, lam); + Asmlink.call_linker_shared [fn ^ ext_obj] dll; + Sys.remove (fn ^ ext_obj); + + let dll = + if Filename.is_implicit dll + then Filename.concat (Sys.getcwd ()) dll + else dll in + let res = dll_run dll !phrase_name in + (try Sys.remove dll with Sys_error _ -> ()); + (* note: under windows, cannot remove a loaded dll + (should remember the handles, close them in at_exit, and then remove + files) *) + res + +(* Print the outcome of an evaluation *) + +let rec pr_item env = function + | Tsig_value(id, decl) :: rem -> + let tree = Printtyp.tree_of_value_description id decl in + let valopt = + match decl.val_kind with + | Val_prim _ -> None + | _ -> + let v = + outval_of_value env (toplevel_value id) + decl.val_type + in + Some v + in + Some (tree, valopt, rem) + | Tsig_type(id, _, _) :: rem when Btype.is_row_name (Ident.name id) -> + pr_item env rem + | Tsig_type(id, decl, rs) :: rem -> + let tree = Printtyp.tree_of_type_declaration id decl rs in + Some (tree, None, rem) + | Tsig_exception(id, decl) :: rem -> + let tree = Printtyp.tree_of_exception_declaration id decl in + Some (tree, None, rem) + | Tsig_module(id, mty, rs) :: rem -> + let tree = Printtyp.tree_of_module id mty rs in + Some (tree, None, rem) + | Tsig_modtype(id, decl) :: rem -> + let tree = Printtyp.tree_of_modtype_declaration id decl in + Some (tree, None, rem) + | Tsig_class(id, decl, rs) :: cltydecl :: tydecl1 :: tydecl2 :: rem -> + let tree = Printtyp.tree_of_class_declaration id decl rs in + Some (tree, None, rem) + | Tsig_cltype(id, decl, rs) :: tydecl1 :: tydecl2 :: rem -> + let tree = Printtyp.tree_of_cltype_declaration id decl rs in + Some (tree, None, rem) + | _ -> None + +let rec item_list env = function + | [] -> [] + | items -> + match pr_item env items with + | None -> [] + | Some (tree, valopt, items) -> (tree, valopt) :: item_list env items + +(* The current typing environment for the toplevel *) + +let toplevel_env = ref Env.empty + +(* Print an exception produced by an evaluation *) + +let print_out_exception ppf exn outv = + !print_out_phrase ppf (Ophr_exception (exn, outv)) + +let print_exception_outcome ppf exn = + if exn = Out_of_memory then Gc.full_major (); + let outv = outval_of_value !toplevel_env (Obj.repr exn) Predef.type_exn in + print_out_exception ppf exn outv + +(* The table of toplevel directives. + Filled by functions from module topdirs. *) + +let directive_table = (Hashtbl.create 13 : (string, directive_fun) Hashtbl.t) + +(* Execute a toplevel phrase *) + +let execute_phrase print_outcome ppf phr = + match phr with + | Ptop_def sstr -> + let oldenv = !toplevel_env in + incr phrase_seqid; + phrase_name := Printf.sprintf "TOP%i" !phrase_seqid; + Compilenv.reset ?packname:None !phrase_name; + let _ = Unused_var.warn ppf sstr in + Typecore.reset_delayed_checks (); + let (str, sg, newenv) = Typemod.type_structure oldenv sstr Location.none + in + Typecore.force_delayed_checks (); + let res = Translmod.transl_store_phrases !phrase_name str in + Warnings.check_fatal (); + begin try + toplevel_env := newenv; + let res = load_lambda ppf res in + let out_phr = + match res with + | Result v -> + Compilenv.record_global_approx_toplevel (); + if print_outcome then + match str with + | [Tstr_eval exp] -> + let outv = outval_of_value newenv v exp.exp_type in + let ty = Printtyp.tree_of_type_scheme exp.exp_type in + Ophr_eval (outv, ty) + | [] -> Ophr_signature [] + | _ -> + Ophr_signature (item_list newenv + (Typemod.simplify_signature sg)) + + else Ophr_signature [] + | Exception exn -> + toplevel_env := oldenv; + if exn = Out_of_memory then Gc.full_major(); + let outv = + outval_of_value !toplevel_env (Obj.repr exn) Predef.type_exn + in + Ophr_exception (exn, outv) + in + !print_out_phrase ppf out_phr; + begin match out_phr with + | Ophr_eval (_, _) | Ophr_signature _ -> true + | Ophr_exception _ -> false + end + with x -> + toplevel_env := oldenv; raise x + end + | Ptop_dir(dir_name, dir_arg) -> + try + match (Hashtbl.find directive_table dir_name, dir_arg) with + | (Directive_none f, Pdir_none) -> f (); true + | (Directive_string f, Pdir_string s) -> f s; true + | (Directive_int f, Pdir_int n) -> f n; true + | (Directive_ident f, Pdir_ident lid) -> f lid; true + | (Directive_bool f, Pdir_bool b) -> f b; true + | (_, _) -> + fprintf ppf "Wrong type of argument for directive `%s'.@." dir_name; + false + with Not_found -> + fprintf ppf "Unknown directive `%s'.@." dir_name; + false + +(* Temporary assignment to a reference *) + +let protect r newval body = + let oldval = !r in + try + r := newval; + let res = body() in + r := oldval; + res + with x -> + r := oldval; + raise x + +(* Read and execute commands from a file *) + +let use_print_results = ref true + +let use_file ppf name = + try + let filename = find_in_path !Config.load_path name in + let ic = open_in_bin filename in + let lb = Lexing.from_channel ic in + Location.init lb filename; + (* Skip initial #! line if any *) + Lexer.skip_sharp_bang lb; + let success = + protect Location.input_name filename (fun () -> + try + List.iter + (fun ph -> + if !Clflags.dump_parsetree then Printast.top_phrase ppf ph; + if not (execute_phrase !use_print_results ppf ph) then raise Exit) + (!parse_use_file lb); + true + with + | Exit -> false + | Sys.Break -> fprintf ppf "Interrupted.@."; false + | x -> Opterrors.report_error ppf x; false) in + close_in ic; + success + with Not_found -> fprintf ppf "Cannot find file %s.@." name; false + +let use_silently ppf name = + protect use_print_results false (fun () -> use_file ppf name) + +(* Reading function for interactive use *) + +let first_line = ref true +let got_eof = ref false;; + +let read_input_default prompt buffer len = + output_string stdout prompt; flush stdout; + let i = ref 0 in + try + while true do + if !i >= len then raise Exit; + let c = input_char stdin in + buffer.[!i] <- c; + incr i; + if c = '\n' then raise Exit; + done; + (!i, false) + with + | End_of_file -> + (!i, true) + | Exit -> + (!i, false) + +let read_interactive_input = ref read_input_default + +let refill_lexbuf buffer len = + if !got_eof then (got_eof := false; 0) else begin + let prompt = + if !Clflags.noprompt then "" + else if !first_line then "# " + else if Lexer.in_comment () then "* " + else " " + in + first_line := false; + let (len, eof) = !read_interactive_input prompt buffer len in + if eof then begin + Location.echo_eof (); + if len > 0 then got_eof := true; + len + end else + len + end + +(* Toplevel initialization. Performed here instead of at the + beginning of loop() so that user code linked in with ocamlmktop + can call directives from Topdirs. *) + +let _ = + Sys.interactive := true; + Dynlink.init (); + Optcompile.init_path(); + Clflags.dlcode := true; + () + +let load_ocamlinit ppf = + match !Clflags.init_file with + | Some f -> if Sys.file_exists f then ignore (use_silently ppf f) + else fprintf ppf "Init file not found: \"%s\".@." f + | None -> + if Sys.file_exists ".ocamlinit" then ignore (use_silently ppf ".ocamlinit") + else try + let home_init = Filename.concat (Sys.getenv "HOME") ".ocamlinit" in + if Sys.file_exists home_init then ignore (use_silently ppf home_init) + with Not_found -> () +;; + +let set_paths () = + (* Add whatever -I options have been specified on the command line, + but keep the directories that user code linked in with ocamlmktop + may have added to load_path. *) + load_path := !load_path @ [Filename.concat Config.standard_library "camlp4"]; + load_path := "" :: (List.rev !Clflags.include_dirs @ !load_path); + () + +let initialize_toplevel_env () = + toplevel_env := Optcompile.initial_env() + +(* The interactive loop *) + +exception PPerror + +let loop ppf = + fprintf ppf " Objective Caml version %s - native toplevel@.@." Config.version; + initialize_toplevel_env (); + let lb = Lexing.from_function refill_lexbuf in + Location.input_name := ""; + Location.input_lexbuf := Some lb; + Sys.catch_break true; + load_ocamlinit ppf; + while true do + let snap = Btype.snapshot () in + try + Lexing.flush_input lb; + Location.reset(); + first_line := true; + let phr = try !parse_toplevel_phrase lb with Exit -> raise PPerror in + if !Clflags.dump_parsetree then Printast.top_phrase ppf phr; + ignore(execute_phrase true ppf phr) + with + | End_of_file -> exit 0 + | Sys.Break -> fprintf ppf "Interrupted.@."; Btype.backtrack snap + | PPerror -> () + | x -> Opterrors.report_error ppf x; Btype.backtrack snap + done + +(* Execute a script *) + +let run_script ppf name args = + let len = Array.length args in + if Array.length Sys.argv < len then invalid_arg "Toploop.run_script"; + Array.blit args 0 Sys.argv 0 len; + Obj.truncate (Obj.repr Sys.argv) len; + Arg.current := 0; + Optcompile.init_path(); + toplevel_env := Optcompile.initial_env(); + Sys.interactive := false; + use_silently ppf name diff --git a/toplevel/opttoploop.mli b/toplevel/opttoploop.mli new file mode 100644 index 0000000..f0275cb --- /dev/null +++ b/toplevel/opttoploop.mli @@ -0,0 +1,102 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttoploop.mli,v 1.3 2007-12-04 13:38:58 doligez Exp $ *) + +open Format + +(* Set the load paths, before running anything *) + +val set_paths : unit -> unit + +(* The interactive toplevel loop *) + +val loop : formatter -> unit + +(* Read and execute a script from the given file *) + +val run_script : formatter -> string -> string array -> bool + (* true if successful, false if error *) + +(* Interface with toplevel directives *) + +type directive_fun = + | Directive_none of (unit -> unit) + | Directive_string of (string -> unit) + | Directive_int of (int -> unit) + | Directive_ident of (Longident.t -> unit) + | Directive_bool of (bool -> unit) + +val directive_table : (string, directive_fun) Hashtbl.t + (* Table of known directives, with their execution function *) +val toplevel_env : Env.t ref + (* Typing environment for the toplevel *) +val initialize_toplevel_env : unit -> unit + (* Initialize the typing environment for the toplevel *) +val print_exception_outcome : formatter -> exn -> unit + (* Print an exception resulting from the evaluation of user code. *) +val execute_phrase : bool -> formatter -> Parsetree.toplevel_phrase -> bool + (* Execute the given toplevel phrase. Return [true] if the + phrase executed with no errors and [false] otherwise. + First bool says whether the values and types of the results + should be printed. Uncaught exceptions are always printed. *) +val use_file : formatter -> string -> bool +val use_silently : formatter -> string -> bool + (* Read and execute commands from a file. + [use_file] prints the types and values of the results. + [use_silently] does not print them. *) +val eval_path: Path.t -> Obj.t + (* Return the toplevel object referred to by the given path *) + +(* Printing of values *) + +val print_value: Env.t -> Obj.t -> formatter -> Types.type_expr -> unit +val print_untyped_exception: formatter -> Obj.t -> unit + +val install_printer : + Path.t -> Types.type_expr -> (formatter -> Obj.t -> unit) -> unit +val remove_printer : Path.t -> unit + +val max_printer_depth: int ref +val max_printer_steps: int ref + +(* Hooks for external parsers and printers *) + +val parse_toplevel_phrase : (Lexing.lexbuf -> Parsetree.toplevel_phrase) ref +val parse_use_file : (Lexing.lexbuf -> Parsetree.toplevel_phrase list) ref +val print_location : formatter -> Location.t -> unit +val print_error : formatter -> Location.t -> unit +val print_warning : Location.t -> formatter -> Warnings.t -> unit +val input_name : string ref + +val print_out_value : + (formatter -> Outcometree.out_value -> unit) ref +val print_out_type : + (formatter -> Outcometree.out_type -> unit) ref +val print_out_class_type : + (formatter -> Outcometree.out_class_type -> unit) ref +val print_out_module_type : + (formatter -> Outcometree.out_module_type -> unit) ref +val print_out_sig_item : + (formatter -> Outcometree.out_sig_item -> unit) ref +val print_out_signature : + (formatter -> Outcometree.out_sig_item list -> unit) ref +val print_out_phrase : + (formatter -> Outcometree.out_phrase -> unit) ref + +(* Hooks for external line editor *) + +val read_interactive_input : (string -> string -> int -> int * bool) ref + +(* Hooks for initialization *) + +val toplevel_startup_hook : (unit -> unit) ref diff --git a/toplevel/opttopmain.ml b/toplevel/opttopmain.ml new file mode 100644 index 0000000..97e2af1 --- /dev/null +++ b/toplevel/opttopmain.ml @@ -0,0 +1,121 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttopmain.ml,v 1.2 2007-11-06 15:16:56 frisch Exp $ *) + +open Clflags + +let usage = "Usage: ocamlnat <options> <object-files> [script-file]\noptions are:" + +let preload_objects = ref [] + +let prepare ppf = + Opttoploop.set_paths (); + try + let res = + List.for_all (Opttopdirs.load_file ppf) (List.rev !preload_objects) + in + !Opttoploop.toplevel_startup_hook (); + res + with x -> + try Opterrors.report_error ppf x; false + with x -> + Format.fprintf ppf "Uncaught exception: %s\n" (Printexc.to_string x); + false + +let file_argument name = + let ppf = Format.err_formatter in + if Filename.check_suffix name ".cmxs" + || Filename.check_suffix name ".cmx" + || Filename.check_suffix name ".cmxa" + then preload_objects := name :: !preload_objects + else + begin + let newargs = Array.sub Sys.argv !Arg.current + (Array.length Sys.argv - !Arg.current) + in + if prepare ppf && Opttoploop.run_script ppf name newargs + then exit 0 + else exit 2 + end + +let print_version () = + Printf.printf "The Objective Caml toplevel, version %s\n" Sys.ocaml_version; + exit 0; +;; + +let main () = + Arg.parse (Arch.command_line_options @ [ + "-compact", Arg.Clear optimize_for_speed, " Optimize code size rather than speed"; + "-inline", Arg.Int(fun n -> inline_threshold := n * 8), + "<n> Set aggressiveness of inlining to <n>"; + "-I", Arg.String(fun dir -> + let dir = Misc.expand_directory Config.standard_library dir in + include_dirs := dir :: !include_dirs), + "<dir> Add <dir> to the list of include directories"; + "-init", Arg.String (fun s -> init_file := Some s), + "<file> Load <file> instead of default init file"; + "-labels", Arg.Clear classic, " Labels commute (default)"; + "-noassert", Arg.Set noassert, " Do not compile assertion checks"; + "-nolabels", Arg.Set classic, " Ignore labels and do not commute"; + "-noprompt", Arg.Set noprompt, " Suppress all prompts"; + "-nostdlib", Arg.Set no_std_include, + " do not add default directory to the list of include directories"; + "-principal", Arg.Set principal, " Check principality of type inference"; + "-rectypes", Arg.Set recursive_types, " Allow arbitrary recursive types"; + "-S", Arg.Set keep_asm_file, " Keep intermediate assembly file"; + "-unsafe", Arg.Set fast, " No bound checking on array and string access"; + "-version", Arg.Unit print_version, " Print version and exit"; + "-w", Arg.String (Warnings.parse_options false), + "<flags> Enable or disable warnings according to <flags>:\n\ + \032 A/a enable/disable all warnings\n\ + \032 C/c enable/disable suspicious comment\n\ + \032 D/d enable/disable deprecated features\n\ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ + \032 M/m enable/disable overriden method\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ + \032 V/v enable/disable hidden instance variable\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ + \032 default setting is \"Aelz\""; + "-warn-error" , Arg.String (Warnings.parse_options true), + "<flags> Treat the warnings of <flags> as errors, if they are enabled.\n\ + \032 (see option -w for the list of flags)\n\ + \032 default setting is a (all warnings are non-fatal)"; + + "-dparsetree", Arg.Set dump_parsetree, " (undocumented)"; + "-drawlambda", Arg.Set dump_rawlambda, " (undocumented)"; + "-dlambda", Arg.Set dump_lambda, " (undocumented)"; + "-dcmm", Arg.Set dump_cmm, " (undocumented)"; + "-dsel", Arg.Set dump_selection, " (undocumented)"; + "-dcombine", Arg.Set dump_combine, " (undocumented)"; + "-dlive", Arg.Unit(fun () -> dump_live := true; + Printmach.print_live := true), + " (undocumented)"; + "-dspill", Arg.Set dump_spill, " (undocumented)"; + "-dsplit", Arg.Set dump_split, " (undocumented)"; + "-dinterf", Arg.Set dump_interf, " (undocumented)"; + "-dprefer", Arg.Set dump_prefer, " (undocumented)"; + "-dalloc", Arg.Set dump_regalloc, " (undocumented)"; + "-dreload", Arg.Set dump_reload, " (undocumented)"; + "-dscheduling", Arg.Set dump_scheduling, " (undocumented)"; + "-dlinear", Arg.Set dump_linear, " (undocumented)"; + "-dstartup", Arg.Set keep_startup_file, " (undocumented)"; + ]) file_argument usage; + if not (prepare Format.err_formatter) then exit 2; + Opttoploop.loop Format.std_formatter + diff --git a/toplevel/opttopmain.mli b/toplevel/opttopmain.mli new file mode 100644 index 0000000..0a420f4 --- /dev/null +++ b/toplevel/opttopmain.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttopmain.mli,v 1.2 2007-11-06 15:16:56 frisch Exp $ *) + +(* Start the [ocaml] toplevel loop *) + +val main: unit -> unit diff --git a/toplevel/opttopstart.ml b/toplevel/opttopstart.ml new file mode 100644 index 0000000..10e4e18 --- /dev/null +++ b/toplevel/opttopstart.ml @@ -0,0 +1,15 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: opttopstart.ml,v 1.2 2007-11-06 15:16:56 frisch Exp $ *) + +let _ = Opttopmain.main() diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml new file mode 100644 index 0000000..7fe1727 --- /dev/null +++ b/toplevel/topdirs.ml @@ -0,0 +1,304 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: topdirs.ml,v 1.67 2008-12-03 18:09:09 doligez Exp $ *) + +(* Toplevel directives *) + +open Format +open Misc +open Longident +open Path +open Types +open Cmo_format +open Trace +open Toploop + +(* The standard output formatter *) +let std_out = std_formatter + +(* To quit *) + +let dir_quit () = exit 0 + +let _ = Hashtbl.add directive_table "quit" (Directive_none dir_quit) + +(* To add a directory to the load path *) + +let dir_directory s = + let d = expand_directory Config.standard_library s in + Config.load_path := d :: !Config.load_path; + Dll.add_path [d] + +let _ = Hashtbl.add directive_table "directory" (Directive_string dir_directory) + +(* To change the current directory *) + +let dir_cd s = Sys.chdir s + +let _ = Hashtbl.add directive_table "cd" (Directive_string dir_cd) + +(* Load in-core a .cmo file *) + +exception Load_failed + +let check_consistency ppf filename cu = + try + List.iter + (fun (name, crc) -> Consistbl.check Env.crc_units name crc filename) + cu.cu_imports + with Consistbl.Inconsistency(name, user, auth) -> + fprintf ppf "@[<hv 0>The files %s@ and %s@ \ + disagree over interface %s@]@." + user auth name; + raise Load_failed + +let load_compunit ic filename ppf compunit = + check_consistency ppf filename compunit; + seek_in ic compunit.cu_pos; + let code_size = compunit.cu_codesize + 8 in + let code = Meta.static_alloc code_size in + unsafe_really_input ic code 0 compunit.cu_codesize; + String.unsafe_set code compunit.cu_codesize (Char.chr Opcodes.opRETURN); + String.unsafe_blit "\000\000\000\001\000\000\000" 0 + code (compunit.cu_codesize + 1) 7; + let initial_symtable = Symtable.current_state() in + Symtable.patch_object code compunit.cu_reloc; + Symtable.update_global_table(); + begin try + may_trace := true; + ignore((Meta.reify_bytecode code code_size) ()); + may_trace := false; + with exn -> + may_trace := false; + Symtable.restore_state initial_symtable; + print_exception_outcome ppf exn; + raise Load_failed + end + +let load_file ppf name = + try + let filename = find_in_path !Config.load_path name in + let ic = open_in_bin filename in + let buffer = String.create (String.length Config.cmo_magic_number) in + really_input ic buffer 0 (String.length Config.cmo_magic_number); + let success = try + if buffer = Config.cmo_magic_number then begin + let compunit_pos = input_binary_int ic in (* Go to descriptor *) + seek_in ic compunit_pos; + load_compunit ic filename ppf (input_value ic : compilation_unit); + true + end else + if buffer = Config.cma_magic_number then begin + let toc_pos = input_binary_int ic in (* Go to table of contents *) + seek_in ic toc_pos; + let lib = (input_value ic : library) in + List.iter + (fun dllib -> + let name = Dll.extract_dll_name dllib in + try Dll.open_dlls Dll.For_execution [name] + with Failure reason -> + fprintf ppf + "Cannot load required shared library %s.@.Reason: %s.@." + name reason; + raise Load_failed) + lib.lib_dllibs; + List.iter (load_compunit ic filename ppf) lib.lib_units; + true + end else begin + fprintf ppf "File %s is not a bytecode object file.@." name; + false + end + with Load_failed -> false in + close_in ic; + success + with Not_found -> fprintf ppf "Cannot find file %s.@." name; false + +let dir_load ppf name = ignore (load_file ppf name) + +let _ = Hashtbl.add directive_table "load" (Directive_string (dir_load std_out)) + +(* Load commands from a file *) + +let dir_use ppf name = ignore(Toploop.use_file ppf name) + +let _ = Hashtbl.add directive_table "use" (Directive_string (dir_use std_out)) + +(* Install, remove a printer *) + +type 'a printer_type_new = Format.formatter -> 'a -> unit +type 'a printer_type_old = 'a -> unit + +let match_printer_type ppf desc typename = + let (printer_type, _) = + try + Env.lookup_type (Ldot(Lident "Topdirs", typename)) !toplevel_env + with Not_found -> + fprintf ppf "Cannot find type Topdirs.%s.@." typename; + raise Exit in + Ctype.init_def(Ident.current_time()); + Ctype.begin_def(); + let ty_arg = Ctype.newvar() in + Ctype.unify !toplevel_env + (Ctype.newconstr printer_type [ty_arg]) + (Ctype.instance desc.val_type); + Ctype.end_def(); + Ctype.generalize ty_arg; + ty_arg + +let find_printer_type ppf lid = + try + let (path, desc) = Env.lookup_value lid !toplevel_env in + let (ty_arg, is_old_style) = + try + (match_printer_type ppf desc "printer_type_new", false) + with Ctype.Unify _ -> + (match_printer_type ppf desc "printer_type_old", true) in + (ty_arg, path, is_old_style) + with + | Not_found -> + fprintf ppf "Unbound value %a.@." Printtyp.longident lid; + raise Exit + | Ctype.Unify _ -> + fprintf ppf "%a has a wrong type for a printing function.@." + Printtyp.longident lid; + raise Exit + +let dir_install_printer ppf lid = + try + let (ty_arg, path, is_old_style) = find_printer_type ppf lid in + let v = eval_path path in + let print_function = + if is_old_style then + (fun formatter repr -> Obj.obj v (Obj.obj repr)) + else + (fun formatter repr -> Obj.obj v formatter (Obj.obj repr)) in + install_printer path ty_arg print_function + with Exit -> () + +let dir_remove_printer ppf lid = + try + let (ty_arg, path, is_old_style) = find_printer_type ppf lid in + begin try + remove_printer path + with Not_found -> + fprintf ppf "No printer named %a.@." Printtyp.longident lid + end + with Exit -> () + +let _ = Hashtbl.add directive_table "install_printer" + (Directive_ident (dir_install_printer std_out)) +let _ = Hashtbl.add directive_table "remove_printer" + (Directive_ident (dir_remove_printer std_out)) + +(* The trace *) + +external current_environment: unit -> Obj.t = "caml_get_current_environment" + +let tracing_function_ptr = + get_code_pointer + (Obj.repr (fun arg -> Trace.print_trace (current_environment()) arg)) + +let dir_trace ppf lid = + try + let (path, desc) = Env.lookup_value lid !toplevel_env in + (* Check if this is a primitive *) + match desc.val_kind with + | Val_prim p -> + fprintf ppf "%a is an external function and cannot be traced.@." + Printtyp.longident lid + | _ -> + let clos = eval_path path in + (* Nothing to do if it's not a closure *) + if Obj.is_block clos + && (Obj.tag clos = Obj.closure_tag || Obj.tag clos = Obj.infix_tag) + then begin + match is_traced clos with + | Some opath -> + fprintf ppf "%a is already traced (under the name %a).@." + Printtyp.path path + Printtyp.path opath + | None -> + (* Instrument the old closure *) + traced_functions := + { path = path; + closure = clos; + actual_code = get_code_pointer clos; + instrumented_fun = + instrument_closure !toplevel_env lid ppf desc.val_type } + :: !traced_functions; + (* Redirect the code field of the closure to point + to the instrumentation function *) + set_code_pointer clos tracing_function_ptr; + fprintf ppf "%a is now traced.@." Printtyp.longident lid + end else fprintf ppf "%a is not a function.@." Printtyp.longident lid + with + | Not_found -> fprintf ppf "Unbound value %a.@." Printtyp.longident lid + +let dir_untrace ppf lid = + try + let (path, desc) = Env.lookup_value lid !toplevel_env in + let rec remove = function + | [] -> + fprintf ppf "%a was not traced.@." Printtyp.longident lid; + [] + | f :: rem -> + if Path.same f.path path then begin + set_code_pointer f.closure f.actual_code; + fprintf ppf "%a is no longer traced.@." Printtyp.longident lid; + rem + end else f :: remove rem in + traced_functions := remove !traced_functions + with + | Not_found -> fprintf ppf "Unbound value %a.@." Printtyp.longident lid + +let dir_untrace_all ppf () = + List.iter + (fun f -> + set_code_pointer f.closure f.actual_code; + fprintf ppf "%a is no longer traced.@." Printtyp.path f.path) + !traced_functions; + traced_functions := [] + +let parse_warnings ppf iserr s = + try Warnings.parse_options iserr s + with Arg.Bad err -> fprintf ppf "%s.@." err + +let _ = + Hashtbl.add directive_table "trace" (Directive_ident (dir_trace std_out)); + Hashtbl.add directive_table "untrace" (Directive_ident (dir_untrace std_out)); + Hashtbl.add directive_table + "untrace_all" (Directive_none (dir_untrace_all std_out)); + +(* Control the printing of values *) + + Hashtbl.add directive_table "print_depth" + (Directive_int(fun n -> max_printer_depth := n)); + Hashtbl.add directive_table "print_length" + (Directive_int(fun n -> max_printer_steps := n)); + +(* Set various compiler flags *) + + Hashtbl.add directive_table "labels" + (Directive_bool(fun b -> Clflags.classic := not b)); + + Hashtbl.add directive_table "principal" + (Directive_bool(fun b -> Clflags.principal := b)); + + Hashtbl.add directive_table "rectypes" + (Directive_none(fun () -> Clflags.recursive_types := true)); + + Hashtbl.add directive_table "warnings" + (Directive_string (parse_warnings std_out false)); + + Hashtbl.add directive_table "warn_error" + (Directive_string (parse_warnings std_out true)) diff --git a/toplevel/topdirs.mli b/toplevel/topdirs.mli new file mode 100644 index 0000000..bb0214f --- /dev/null +++ b/toplevel/topdirs.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: topdirs.mli,v 1.12 2002-04-18 07:27:44 garrigue Exp $ *) + +(* The toplevel directives. *) + +open Format + +val dir_quit : unit -> unit +val dir_directory : string -> unit +val dir_cd : string -> unit +val dir_load : formatter -> string -> unit +val dir_use : formatter -> string -> unit +val dir_install_printer : formatter -> Longident.t -> unit +val dir_remove_printer : formatter -> Longident.t -> unit +val dir_trace : formatter -> Longident.t -> unit +val dir_untrace : formatter -> Longident.t -> unit +val dir_untrace_all : formatter -> unit -> unit + +type 'a printer_type_new = Format.formatter -> 'a -> unit +type 'a printer_type_old = 'a -> unit + +(* For topmain.ml. Maybe shouldn't be there *) +val load_file : formatter -> string -> bool diff --git a/toplevel/toplevellib.mllib b/toplevel/toplevellib.mllib new file mode 100644 index 0000000..906aeb4 --- /dev/null +++ b/toplevel/toplevellib.mllib @@ -0,0 +1,19 @@ +Myocamlbuild_config +Misc Tbl Config Clflags Terminfo Ccomp Warnings Consistbl + +Linenum Location Longident Syntaxerr Parser +Lexer Parse Printast + +Unused_var Ident Path Primitive Types +Btype Oprint Subst Predef Datarepr Env +Typedtree Ctype Printtyp Includeclass Mtype Includecore +Includemod Parmatch Typetexp Stypes Typecore +Typedecl Typeclass Typemod + +Lambda Printlambda Typeopt Switch Matching Translobj Translcore +Translclass Translmod Simplif Runtimedef + +Meta Instruct Bytegen Printinstr Opcodes Emitcode +Bytesections Dll Symtable Bytelink Bytelibrarian Bytepackager + +Pparse Errors Compile Genprintval Toploop Trace Topdirs Topmain diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml new file mode 100644 index 0000000..27835e2 --- /dev/null +++ b/toplevel/toploop.ml @@ -0,0 +1,437 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: toploop.ml,v 1.95 2007-12-04 13:38:58 doligez Exp $ *) + +(* The interactive toplevel loop *) + +open Path +open Lexing +open Format +open Config +open Misc +open Parsetree +open Types +open Typedtree +open Outcometree + +type directive_fun = + | Directive_none of (unit -> unit) + | Directive_string of (string -> unit) + | Directive_int of (int -> unit) + | Directive_ident of (Longident.t -> unit) + | Directive_bool of (bool -> unit) + +(* The table of toplevel value bindings and its accessors *) + +let toplevel_value_bindings = + (Hashtbl.create 37 : (string, Obj.t) Hashtbl.t) + +let getvalue name = + try + Hashtbl.find toplevel_value_bindings name + with Not_found -> + fatal_error (name ^ " unbound at toplevel") + +let setvalue name v = + Hashtbl.replace toplevel_value_bindings name v + +(* Return the value referred to by a path *) + +let rec eval_path = function + | Pident id -> + if Ident.persistent id || Ident.global id then + Symtable.get_global_value id + else begin + let name = Translmod.toplevel_name id in + try + Hashtbl.find toplevel_value_bindings name + with Not_found -> + raise (Symtable.Error(Symtable.Undefined_global name)) + end + | Pdot(p, s, pos) -> + Obj.field (eval_path p) pos + | Papply(p1, p2) -> + fatal_error "Toploop.eval_path" + +(* To print values *) + +module EvalPath = struct + type value = Obj.t + exception Error + let eval_path p = try eval_path p with Symtable.Error _ -> raise Error + let same_value v1 v2 = (v1 == v2) +end + +module Printer = Genprintval.Make(Obj)(EvalPath) + +let max_printer_depth = ref 100 +let max_printer_steps = ref 300 + +let print_out_value = Oprint.out_value +let print_out_type = Oprint.out_type +let print_out_class_type = Oprint.out_class_type +let print_out_module_type = Oprint.out_module_type +let print_out_sig_item = Oprint.out_sig_item +let print_out_signature = Oprint.out_signature +let print_out_phrase = Oprint.out_phrase + +let print_untyped_exception ppf obj = + !print_out_value ppf (Printer.outval_of_untyped_exception obj) +let outval_of_value env obj ty = + Printer.outval_of_value !max_printer_steps !max_printer_depth + (fun _ _ _ -> None) env obj ty +let print_value env obj ppf ty = + !print_out_value ppf (outval_of_value env obj ty) + +let install_printer = Printer.install_printer +let remove_printer = Printer.remove_printer + +(* Hooks for parsing functions *) + +let parse_toplevel_phrase = ref Parse.toplevel_phrase +let parse_use_file = ref Parse.use_file +let print_location = Location.print_error (* FIXME change back to print *) +let print_error = Location.print_error +let print_warning = Location.print_warning +let input_name = Location.input_name + +(* Hooks for initialization *) + +let toplevel_startup_hook = ref (fun () -> ()) + +(* Load in-core and execute a lambda term *) + +let may_trace = ref false (* Global lock on tracing *) +type evaluation_outcome = Result of Obj.t | Exception of exn + +let load_lambda ppf lam = + if !Clflags.dump_rawlambda then fprintf ppf "%a@." Printlambda.lambda lam; + let slam = Simplif.simplify_lambda lam in + if !Clflags.dump_lambda then fprintf ppf "%a@." Printlambda.lambda slam; + let (init_code, fun_code) = Bytegen.compile_phrase slam in + if !Clflags.dump_instr then + fprintf ppf "%a%a@." + Printinstr.instrlist init_code + Printinstr.instrlist fun_code; + let (code, code_size, reloc) = Emitcode.to_memory init_code fun_code in + let can_free = (fun_code = []) in + let initial_symtable = Symtable.current_state() in + Symtable.patch_object code reloc; + Symtable.check_global_initialized reloc; + Symtable.update_global_table(); + try + may_trace := true; + let retval = (Meta.reify_bytecode code code_size) () in + may_trace := false; + if can_free then begin + Meta.static_release_bytecode code code_size; + Meta.static_free code; + end; + Result retval + with x -> + may_trace := false; + if can_free then begin + Meta.static_release_bytecode code code_size; + Meta.static_free code; + end; + Symtable.restore_state initial_symtable; + Exception x + +(* Print the outcome of an evaluation *) + +let rec pr_item env = function + | Tsig_value(id, decl) :: rem -> + let tree = Printtyp.tree_of_value_description id decl in + let valopt = + match decl.val_kind with + | Val_prim _ -> None + | _ -> + let v = + outval_of_value env (getvalue (Translmod.toplevel_name id)) + decl.val_type + in + Some v + in + Some (tree, valopt, rem) + | Tsig_type(id, _, _) :: rem when Btype.is_row_name (Ident.name id) -> + pr_item env rem + | Tsig_type(id, decl, rs) :: rem -> + let tree = Printtyp.tree_of_type_declaration id decl rs in + Some (tree, None, rem) + | Tsig_exception(id, decl) :: rem -> + let tree = Printtyp.tree_of_exception_declaration id decl in + Some (tree, None, rem) + | Tsig_module(id, mty, rs) :: rem -> + let tree = Printtyp.tree_of_module id mty rs in + Some (tree, None, rem) + | Tsig_modtype(id, decl) :: rem -> + let tree = Printtyp.tree_of_modtype_declaration id decl in + Some (tree, None, rem) + | Tsig_class(id, decl, rs) :: cltydecl :: tydecl1 :: tydecl2 :: rem -> + let tree = Printtyp.tree_of_class_declaration id decl rs in + Some (tree, None, rem) + | Tsig_cltype(id, decl, rs) :: tydecl1 :: tydecl2 :: rem -> + let tree = Printtyp.tree_of_cltype_declaration id decl rs in + Some (tree, None, rem) + | _ -> None + +let rec item_list env = function + | [] -> [] + | items -> + match pr_item env items with + | None -> [] + | Some (tree, valopt, items) -> (tree, valopt) :: item_list env items + +(* The current typing environment for the toplevel *) + +let toplevel_env = ref Env.empty + +(* Print an exception produced by an evaluation *) + +let print_out_exception ppf exn outv = + !print_out_phrase ppf (Ophr_exception (exn, outv)) + +let print_exception_outcome ppf exn = + if exn = Out_of_memory then Gc.full_major (); + let outv = outval_of_value !toplevel_env (Obj.repr exn) Predef.type_exn in + print_out_exception ppf exn outv + +(* The table of toplevel directives. + Filled by functions from module topdirs. *) + +let directive_table = (Hashtbl.create 13 : (string, directive_fun) Hashtbl.t) + +(* Execute a toplevel phrase *) + +let execute_phrase print_outcome ppf phr = + match phr with + | Ptop_def sstr -> + let oldenv = !toplevel_env in + let _ = Unused_var.warn ppf sstr in + Typecore.reset_delayed_checks (); + let (str, sg, newenv) = Typemod.type_structure oldenv sstr Location.none + in + Typecore.force_delayed_checks (); + let lam = Translmod.transl_toplevel_definition str in + Warnings.check_fatal (); + begin try + toplevel_env := newenv; + let res = load_lambda ppf lam in + let out_phr = + match res with + | Result v -> + if print_outcome then + match str with + | [Tstr_eval exp] -> + let outv = outval_of_value newenv v exp.exp_type in + let ty = Printtyp.tree_of_type_scheme exp.exp_type in + Ophr_eval (outv, ty) + | [] -> Ophr_signature [] + | _ -> Ophr_signature (item_list newenv + (Typemod.simplify_signature sg)) + else Ophr_signature [] + | Exception exn -> + toplevel_env := oldenv; + if exn = Out_of_memory then Gc.full_major(); + let outv = + outval_of_value !toplevel_env (Obj.repr exn) Predef.type_exn + in + Ophr_exception (exn, outv) + in + !print_out_phrase ppf out_phr; + begin match out_phr with + | Ophr_eval (_, _) | Ophr_signature _ -> true + | Ophr_exception _ -> false + end + with x -> + toplevel_env := oldenv; raise x + end + | Ptop_dir(dir_name, dir_arg) -> + try + match (Hashtbl.find directive_table dir_name, dir_arg) with + | (Directive_none f, Pdir_none) -> f (); true + | (Directive_string f, Pdir_string s) -> f s; true + | (Directive_int f, Pdir_int n) -> f n; true + | (Directive_ident f, Pdir_ident lid) -> f lid; true + | (Directive_bool f, Pdir_bool b) -> f b; true + | (_, _) -> + fprintf ppf "Wrong type of argument for directive `%s'.@." dir_name; + false + with Not_found -> + fprintf ppf "Unknown directive `%s'.@." dir_name; + false + +(* Temporary assignment to a reference *) + +let protect r newval body = + let oldval = !r in + try + r := newval; + let res = body() in + r := oldval; + res + with x -> + r := oldval; + raise x + +(* Read and execute commands from a file *) + +let use_print_results = ref true + +let use_file ppf name = + try + let filename = find_in_path !Config.load_path name in + let ic = open_in_bin filename in + let lb = Lexing.from_channel ic in + Location.init lb filename; + (* Skip initial #! line if any *) + Lexer.skip_sharp_bang lb; + let success = + protect Location.input_name filename (fun () -> + try + List.iter + (fun ph -> + if !Clflags.dump_parsetree then Printast.top_phrase ppf ph; + if not (execute_phrase !use_print_results ppf ph) then raise Exit) + (!parse_use_file lb); + true + with + | Exit -> false + | Sys.Break -> fprintf ppf "Interrupted.@."; false + | x -> Errors.report_error ppf x; false) in + close_in ic; + success + with Not_found -> fprintf ppf "Cannot find file %s.@." name; false + +let use_silently ppf name = + protect use_print_results false (fun () -> use_file ppf name) + +(* Reading function for interactive use *) + +let first_line = ref true +let got_eof = ref false;; + +let read_input_default prompt buffer len = + output_string stdout prompt; flush stdout; + let i = ref 0 in + try + while true do + if !i >= len then raise Exit; + let c = input_char stdin in + buffer.[!i] <- c; + incr i; + if c = '\n' then raise Exit; + done; + (!i, false) + with + | End_of_file -> + (!i, true) + | Exit -> + (!i, false) + +let read_interactive_input = ref read_input_default + +let refill_lexbuf buffer len = + if !got_eof then (got_eof := false; 0) else begin + let prompt = + if !Clflags.noprompt then "" + else if !first_line then "# " + else if Lexer.in_comment () then "* " + else " " + in + first_line := false; + let (len, eof) = !read_interactive_input prompt buffer len in + if eof then begin + Location.echo_eof (); + if len > 0 then got_eof := true; + len + end else + len + end + +(* Toplevel initialization. Performed here instead of at the + beginning of loop() so that user code linked in with ocamlmktop + can call directives from Topdirs. *) + +let _ = + Sys.interactive := true; + let crc_intfs = Symtable.init_toplevel() in + Compile.init_path(); + List.iter + (fun (name, crc) -> + Consistbl.set Env.crc_units name crc Sys.executable_name) + crc_intfs + +let load_ocamlinit ppf = + match !Clflags.init_file with + | Some f -> if Sys.file_exists f then ignore (use_silently ppf f) + else fprintf ppf "Init file not found: \"%s\".@." f + | None -> + if Sys.file_exists ".ocamlinit" then ignore (use_silently ppf ".ocamlinit") + else try + let home_init = Filename.concat (Sys.getenv "HOME") ".ocamlinit" in + if Sys.file_exists home_init then ignore (use_silently ppf home_init) + with Not_found -> () +;; + +let set_paths () = + (* Add whatever -I options have been specified on the command line, + but keep the directories that user code linked in with ocamlmktop + may have added to load_path. *) + load_path := !load_path @ [Filename.concat Config.standard_library "camlp4"]; + load_path := "" :: (List.rev !Clflags.include_dirs @ !load_path); + Dll.add_path !load_path + +let initialize_toplevel_env () = + toplevel_env := Compile.initial_env() + +(* The interactive loop *) + +exception PPerror + +let loop ppf = + fprintf ppf " Objective Caml version %s@.@." Config.version; + initialize_toplevel_env (); + let lb = Lexing.from_function refill_lexbuf in + Location.input_name := ""; + Location.input_lexbuf := Some lb; + Sys.catch_break true; + load_ocamlinit ppf; + while true do + let snap = Btype.snapshot () in + try + Lexing.flush_input lb; + Location.reset(); + first_line := true; + let phr = try !parse_toplevel_phrase lb with Exit -> raise PPerror in + if !Clflags.dump_parsetree then Printast.top_phrase ppf phr; + ignore(execute_phrase true ppf phr) + with + | End_of_file -> exit 0 + | Sys.Break -> fprintf ppf "Interrupted.@."; Btype.backtrack snap + | PPerror -> () + | x -> Errors.report_error ppf x; Btype.backtrack snap + done + +(* Execute a script *) + +let run_script ppf name args = + let len = Array.length args in + if Array.length Sys.argv < len then invalid_arg "Toploop.run_script"; + Array.blit args 0 Sys.argv 0 len; + Obj.truncate (Obj.repr Sys.argv) len; + Arg.current := 0; + Compile.init_path(); + toplevel_env := Compile.initial_env(); + Sys.interactive := false; + use_silently ppf name diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli new file mode 100644 index 0000000..d03b073 --- /dev/null +++ b/toplevel/toploop.mli @@ -0,0 +1,112 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: toploop.mli,v 1.26 2007-12-04 13:38:58 doligez Exp $ *) + +open Format + +(* Accessors for the table of toplevel value bindings. These functions + must appear as first and second exported functions in this module. + (See module Translmod.) *) +val getvalue : string -> Obj.t +val setvalue : string -> Obj.t -> unit + +(* Set the load paths, before running anything *) + +val set_paths : unit -> unit + +(* The interactive toplevel loop *) + +val loop : formatter -> unit + +(* Read and execute a script from the given file *) + +val run_script : formatter -> string -> string array -> bool + (* true if successful, false if error *) + +(* Interface with toplevel directives *) + +type directive_fun = + | Directive_none of (unit -> unit) + | Directive_string of (string -> unit) + | Directive_int of (int -> unit) + | Directive_ident of (Longident.t -> unit) + | Directive_bool of (bool -> unit) + +val directive_table : (string, directive_fun) Hashtbl.t + (* Table of known directives, with their execution function *) +val toplevel_env : Env.t ref + (* Typing environment for the toplevel *) +val initialize_toplevel_env : unit -> unit + (* Initialize the typing environment for the toplevel *) +val print_exception_outcome : formatter -> exn -> unit + (* Print an exception resulting from the evaluation of user code. *) +val execute_phrase : bool -> formatter -> Parsetree.toplevel_phrase -> bool + (* Execute the given toplevel phrase. Return [true] if the + phrase executed with no errors and [false] otherwise. + First bool says whether the values and types of the results + should be printed. Uncaught exceptions are always printed. *) +val use_file : formatter -> string -> bool +val use_silently : formatter -> string -> bool + (* Read and execute commands from a file. + [use_file] prints the types and values of the results. + [use_silently] does not print them. *) +val eval_path: Path.t -> Obj.t + (* Return the toplevel object referred to by the given path *) + +(* Printing of values *) + +val print_value: Env.t -> Obj.t -> formatter -> Types.type_expr -> unit +val print_untyped_exception: formatter -> Obj.t -> unit + +val install_printer : + Path.t -> Types.type_expr -> (formatter -> Obj.t -> unit) -> unit +val remove_printer : Path.t -> unit + +val max_printer_depth: int ref +val max_printer_steps: int ref + +(* Hooks for external parsers and printers *) + +val parse_toplevel_phrase : (Lexing.lexbuf -> Parsetree.toplevel_phrase) ref +val parse_use_file : (Lexing.lexbuf -> Parsetree.toplevel_phrase list) ref +val print_location : formatter -> Location.t -> unit +val print_error : formatter -> Location.t -> unit +val print_warning : Location.t -> formatter -> Warnings.t -> unit +val input_name : string ref + +val print_out_value : + (formatter -> Outcometree.out_value -> unit) ref +val print_out_type : + (formatter -> Outcometree.out_type -> unit) ref +val print_out_class_type : + (formatter -> Outcometree.out_class_type -> unit) ref +val print_out_module_type : + (formatter -> Outcometree.out_module_type -> unit) ref +val print_out_sig_item : + (formatter -> Outcometree.out_sig_item -> unit) ref +val print_out_signature : + (formatter -> Outcometree.out_sig_item list -> unit) ref +val print_out_phrase : + (formatter -> Outcometree.out_phrase -> unit) ref + +(* Hooks for external line editor *) + +val read_interactive_input : (string -> string -> int -> int * bool) ref + +(* Hooks for initialization *) + +val toplevel_startup_hook : (unit -> unit) ref + +(* Used by Trace module *) + +val may_trace : bool ref diff --git a/toplevel/topmain.ml b/toplevel/topmain.ml new file mode 100644 index 0000000..ae0092a --- /dev/null +++ b/toplevel/topmain.ml @@ -0,0 +1,100 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: topmain.ml,v 1.39 2005-01-28 17:52:58 doligez Exp $ *) + +open Clflags + +let usage = "Usage: ocaml <options> <object-files> [script-file]\noptions are:" + +let preload_objects = ref [] + +let prepare ppf = + Toploop.set_paths (); + try + let res = + List.for_all (Topdirs.load_file ppf) (List.rev !preload_objects) in + !Toploop.toplevel_startup_hook (); + res + with x -> + try Errors.report_error ppf x; false + with x -> + Format.fprintf ppf "Uncaught exception: %s\n" (Printexc.to_string x); + false + +let file_argument name = + let ppf = Format.err_formatter in + if Filename.check_suffix name ".cmo" || Filename.check_suffix name ".cma" + then preload_objects := name :: !preload_objects + else + begin + let newargs = Array.sub Sys.argv !Arg.current + (Array.length Sys.argv - !Arg.current) + in + if prepare ppf && Toploop.run_script ppf name newargs + then exit 0 + else exit 2 + end + +let print_version () = + Printf.printf "The Objective Caml toplevel, version %s\n" Sys.ocaml_version; + exit 0; +;; + +let main () = + Arg.parse [ + "-I", Arg.String(fun dir -> + let dir = Misc.expand_directory Config.standard_library dir in + include_dirs := dir :: !include_dirs), + "<dir> Add <dir> to the list of include directories"; + "-init", Arg.String (fun s -> init_file := Some s), + "<file> Load <file> instead of default init file"; + "-labels", Arg.Clear classic, " Labels commute (default)"; + "-noassert", Arg.Set noassert, " Do not compile assertion checks"; + "-nolabels", Arg.Set classic, " Ignore labels and do not commute"; + "-noprompt", Arg.Set noprompt, " Suppress all prompts"; + "-nostdlib", Arg.Set no_std_include, + " do not add default directory to the list of include directories"; + "-principal", Arg.Set principal, " Check principality of type inference"; + "-rectypes", Arg.Set recursive_types, " Allow arbitrary recursive types"; + "-unsafe", Arg.Set fast, " No bound checking on array and string access"; + "-version", Arg.Unit print_version, " Print version and exit"; + "-w", Arg.String (Warnings.parse_options false), + "<flags> Enable or disable warnings according to <flags>:\n\ + \032 A/a enable/disable all warnings\n\ + \032 C/c enable/disable suspicious comment\n\ + \032 D/d enable/disable deprecated features\n\ + \032 E/e enable/disable fragile match\n\ + \032 F/f enable/disable partially applied function\n\ + \032 L/l enable/disable labels omitted in application\n\ + \032 M/m enable/disable overriden method\n\ + \032 P/p enable/disable partial match\n\ + \032 S/s enable/disable non-unit statement\n\ + \032 U/u enable/disable unused match case\n\ + \032 V/v enable/disable hidden instance variable\n\ + \032 Y/y enable/disable suspicious unused variables\n\ + \032 Z/z enable/disable all other unused variables\n\ + \032 X/x enable/disable all other warnings\n\ + \032 default setting is \"Aelz\""; + "-warn-error" , Arg.String (Warnings.parse_options true), + "<flags> Treat the warnings of <flags> as errors, if they are enabled.\n\ + \032 (see option -w for the list of flags)\n\ + \032 default setting is a (all warnings are non-fatal)"; + + "-dparsetree", Arg.Set dump_parsetree, " (undocumented)"; + "-drawlambda", Arg.Set dump_rawlambda, " (undocumented)"; + "-dlambda", Arg.Set dump_lambda, " (undocumented)"; + "-dinstr", Arg.Set dump_instr, " (undocumented)"; + ] file_argument usage; + if not (prepare Format.err_formatter) then exit 2; + Toploop.loop Format.std_formatter + diff --git a/toplevel/topmain.mli b/toplevel/topmain.mli new file mode 100644 index 0000000..a521516 --- /dev/null +++ b/toplevel/topmain.mli @@ -0,0 +1,17 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: topmain.mli,v 1.1 2002-04-24 08:02:51 xleroy Exp $ *) + +(* Start the [ocaml] toplevel loop *) + +val main: unit -> unit diff --git a/toplevel/topstart.ml b/toplevel/topstart.ml new file mode 100644 index 0000000..33a5b8c --- /dev/null +++ b/toplevel/topstart.ml @@ -0,0 +1,15 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: topstart.ml,v 1.1 2002-04-24 08:02:51 xleroy Exp $ *) + +let _ = Topmain.main() diff --git a/toplevel/trace.ml b/toplevel/trace.ml new file mode 100644 index 0000000..c1b21fd --- /dev/null +++ b/toplevel/trace.ml @@ -0,0 +1,144 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: trace.ml,v 1.20 2001-04-19 08:34:20 garrigue Exp $ *) + +(* The "trace" facility *) + +open Format +open Misc +open Longident +open Types +open Toploop + +type codeptr = Obj.t + +type traced_function = + { path: Path.t; (* Name under which it is traced *) + closure: Obj.t; (* Its function closure (patched) *) + actual_code: codeptr; (* Its original code pointer *) + instrumented_fun: codeptr -> Obj.t -> Obj.t -> Obj.t } + (* Printing function *) + +let traced_functions = ref ([] : traced_function list) + +(* Check if a function is already traced *) + +let is_traced clos = + let rec is_traced = function + [] -> None + | tf :: rem -> if tf.closure == clos then Some tf.path else is_traced rem + in is_traced !traced_functions + +(* Get or overwrite the code pointer of a closure *) + +let get_code_pointer cls = Obj.field cls 0 + +let set_code_pointer cls ptr = Obj.set_field cls 0 ptr + +(* Call a traced function (use old code pointer, but new closure as + environment so that recursive calls are also traced). + It is necessary to wrap Meta.invoke_traced_function in an ML function + so that the RETURN at the end of the ML wrapper takes us to the + code of the function. *) + +let invoke_traced_function codeptr env arg = + Meta.invoke_traced_function codeptr env arg + +let print_label ppf l = if l <> "" then fprintf ppf "%s:" l + +(* If a function returns a functional value, wrap it into a trace code *) + +let rec instrument_result env name ppf clos_typ = + match (Ctype.repr(Ctype.expand_head env clos_typ)).desc with + | Tarrow(l, t1, t2, _) -> + let starred_name = + match name with + | Lident s -> Lident(s ^ "*") + | Ldot(lid, s) -> Ldot(lid, s ^ "*") + | Lapply(l1, l2) -> fatal_error "Trace.instrument_result" in + let trace_res = instrument_result env starred_name ppf t2 in + (fun clos_val -> + Obj.repr (fun arg -> + if not !may_trace then + (Obj.magic clos_val : Obj.t -> Obj.t) arg + else begin + may_trace := false; + try + fprintf ppf "@[<2>%a <--@ %a%a@]@." + Printtyp.longident starred_name + print_label l + (print_value !toplevel_env arg) t1; + may_trace := true; + let res = (Obj.magic clos_val : Obj.t -> Obj.t) arg in + may_trace := false; + fprintf ppf "@[<2>%a -->@ %a@]@." + Printtyp.longident starred_name + (print_value !toplevel_env res) t2; + may_trace := true; + trace_res res + with exn -> + may_trace := false; + fprintf ppf "@[<2>%a raises@ %a@]@." + Printtyp.longident starred_name + (print_value !toplevel_env (Obj.repr exn)) Predef.type_exn; + may_trace := true; + raise exn + end)) + | _ -> (fun v -> v) + +(* Same as instrument_result, but for a toplevel closure (modified in place) *) + +let instrument_closure env name ppf clos_typ = + match (Ctype.repr(Ctype.expand_head env clos_typ)).desc with + | Tarrow(l, t1, t2, _) -> + let trace_res = instrument_result env name ppf t2 in + (fun actual_code closure arg -> + if not !may_trace then begin + let res = invoke_traced_function actual_code closure arg + in res (* do not remove let, prevents tail-call to invoke_traced_ *) + end else begin + may_trace := false; + try + fprintf ppf "@[<2>%a <--@ %a%a@]@." + Printtyp.longident name + print_label l + (print_value !toplevel_env arg) t1; + may_trace := true; + let res = invoke_traced_function actual_code closure arg in + may_trace := false; + fprintf ppf "@[<2>%a -->@ %a@]@." + Printtyp.longident name + (print_value !toplevel_env res) t2; + may_trace := true; + trace_res res + with exn -> + may_trace := false; + fprintf ppf "@[<2>%a raises@ %a@]@." + Printtyp.longident name + (print_value !toplevel_env (Obj.repr exn)) Predef.type_exn; + may_trace := true; + raise exn + end) + | _ -> assert false + +(* Given the address of a closure, find its tracing info *) + +let rec find_traced_closure clos = function + | [] -> fatal_error "Trace.find_traced_closure" + | f :: rem -> if f.closure == clos then f else find_traced_closure clos rem + +(* Trace the application of an (instrumented) closure to an argument *) + +let print_trace clos arg = + let f = find_traced_closure clos !traced_functions in + f.instrumented_fun f.actual_code clos arg diff --git a/toplevel/trace.mli b/toplevel/trace.mli new file mode 100644 index 0000000..bd1004a --- /dev/null +++ b/toplevel/trace.mli @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: trace.mli,v 1.9 2000-03-06 22:11:55 weis Exp $ *) + +(* The "trace" facility *) + +open Format + +type codeptr + +type traced_function = + { path: Path.t; (* Name under which it is traced *) + closure: Obj.t; (* Its function closure (patched) *) + actual_code: codeptr; (* Its original code pointer *) + instrumented_fun: codeptr -> Obj.t -> Obj.t -> Obj.t } + (* Printing function *) + +val traced_functions: traced_function list ref +val is_traced: Obj.t -> Path.t option +val get_code_pointer: Obj.t -> codeptr +val set_code_pointer: Obj.t -> codeptr -> unit +val instrument_closure: + Env.t -> Longident.t -> formatter -> Types.type_expr -> + codeptr -> Obj.t -> Obj.t -> Obj.t +val print_trace: Obj.t -> Obj.t -> Obj.t diff --git a/typing/annot.mli b/typing/annot.mli new file mode 100644 index 0000000..72deed5 --- /dev/null +++ b/typing/annot.mli @@ -0,0 +1,23 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Gallium, INRIA Rocquencourt *) +(* *) +(* Copyright 2007 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: annot.mli,v 1.2 2008-07-29 15:42:44 doligez Exp $ *) + +(* Data types for annotations (Stypes.ml) *) + +type call = Tail | Stack | Inline;; + +type ident = + | Iref_internal of Location.t (* defining occurrence *) + | Iref_external + | Idef of Location.t (* scope *) +;; diff --git a/typing/btype.ml b/typing/btype.ml new file mode 100644 index 0000000..e53330b --- /dev/null +++ b/typing/btype.ml @@ -0,0 +1,511 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: btype.ml,v 1.42 2008-07-19 02:13:09 garrigue Exp $ *) + +(* Basic operations on core types *) + +open Types + +(**** Type level management ****) + +let generic_level = 100000000 + +(* Used to mark a type during a traversal. *) +let lowest_level = 0 +let pivot_level = 2 * lowest_level - 1 + (* pivot_level - lowest_level < lowest_level *) + +(**** Some type creators ****) + +let new_id = ref (-1) + +let newty2 level desc = + incr new_id; { desc = desc; level = level; id = !new_id } +let newgenty desc = newty2 generic_level desc +let newgenvar () = newgenty Tvar +(* +let newmarkedvar level = + incr new_id; { desc = Tvar; level = pivot_level - level; id = !new_id } +let newmarkedgenvar () = + incr new_id; + { desc = Tvar; level = pivot_level - generic_level; id = !new_id } +*) + +(**** Representative of a type ****) + +let rec field_kind_repr = + function + Fvar {contents = Some kind} -> field_kind_repr kind + | kind -> kind + +let rec repr = + function + {desc = Tlink t'} -> + (* + We do no path compression. Path compression does not seem to + improve notably efficiency, and it prevents from changing a + [Tlink] into another type (for instance, for undoing a + unification). + *) + repr t' + | {desc = Tfield (_, k, _, t')} when field_kind_repr k = Fabsent -> + repr t' + | t -> t + +let rec commu_repr = function + Clink r when !r <> Cunknown -> commu_repr !r + | c -> c + +let rec row_field_repr_aux tl = function + Reither(_, tl', _, {contents = Some fi}) -> + row_field_repr_aux (tl@tl') fi + | Reither(c, tl', m, r) -> + Reither(c, tl@tl', m, r) + | Rpresent (Some _) when tl <> [] -> + Rpresent (Some (List.hd tl)) + | fi -> fi + +let row_field_repr fi = row_field_repr_aux [] fi + +let rec rev_concat l ll = + match ll with + [] -> l + | l'::ll -> rev_concat (l'@l) ll + +let rec row_repr_aux ll row = + match (repr row.row_more).desc with + | Tvariant row' -> + let f = row.row_fields in + row_repr_aux (if f = [] then ll else f::ll) row' + | _ -> + if ll = [] then row else + {row with row_fields = rev_concat row.row_fields ll} + +let row_repr row = row_repr_aux [] row + +let rec row_field tag row = + let rec find = function + | (tag',f) :: fields -> + if tag = tag' then row_field_repr f else find fields + | [] -> + match repr row.row_more with + | {desc=Tvariant row'} -> row_field tag row' + | _ -> Rabsent + in find row.row_fields + +let rec row_more row = + match repr row.row_more with + | {desc=Tvariant row'} -> row_more row' + | ty -> ty + +let static_row row = + let row = row_repr row in + row.row_closed && + List.for_all + (fun (_,f) -> match row_field_repr f with Reither _ -> false | _ -> true) + row.row_fields + +let hash_variant s = + let accu = ref 0 in + for i = 0 to String.length s - 1 do + accu := 223 * !accu + Char.code s.[i] + done; + (* reduce to 31 bits *) + accu := !accu land (1 lsl 31 - 1); + (* make it signed for 64 bits architectures *) + if !accu > 0x3FFFFFFF then !accu - (1 lsl 31) else !accu + +let proxy ty = + let ty0 = repr ty in + match ty0.desc with + | Tvariant row when not (static_row row) -> + row_more row + | Tobject (ty, _) -> + let rec proxy_obj ty = + match ty.desc with + Tfield (_, _, _, ty) | Tlink ty -> proxy_obj ty + | Tvar | Tunivar | Tconstr _ -> ty + | Tnil -> ty0 + | _ -> assert false + in proxy_obj ty + | _ -> ty0 + +(**** Utilities for fixed row private types ****) + +let has_constr_row t = + match (repr t).desc with + Tobject(t,_) -> + let rec check_row t = + match (repr t).desc with + Tfield(_,_,_,t) -> check_row t + | Tconstr _ -> true + | _ -> false + in check_row t + | Tvariant row -> + (match row_more row with {desc=Tconstr _} -> true | _ -> false) + | _ -> + false + +let is_row_name s = + let l = String.length s in + if l < 4 then false else String.sub s (l-4) 4 = "#row" + + + (**********************************) + (* Utilities for type traversal *) + (**********************************) + +let rec iter_row f row = + List.iter + (fun (_, fi) -> + match row_field_repr fi with + | Rpresent(Some ty) -> f ty + | Reither(_, tl, _, _) -> List.iter f tl + | _ -> ()) + row.row_fields; + match (repr row.row_more).desc with + Tvariant row -> iter_row f row + | Tvar | Tunivar | Tsubst _ | Tconstr _ -> + Misc.may (fun (_,l) -> List.iter f l) row.row_name + | _ -> assert false + +let iter_type_expr f ty = + match ty.desc with + Tvar -> () + | Tarrow (_, ty1, ty2, _) -> f ty1; f ty2 + | Ttuple l -> List.iter f l + | Tconstr (_, l, _) -> List.iter f l + | Tobject(ty, {contents = Some (_, p)}) + -> f ty; List.iter f p + | Tobject (ty, _) -> f ty + | Tvariant row -> iter_row f row; f (row_more row) + | Tfield (_, _, ty1, ty2) -> f ty1; f ty2 + | Tnil -> () + | Tlink ty -> f ty + | Tsubst ty -> f ty + | Tunivar -> () + | Tpoly (ty, tyl) -> f ty; List.iter f tyl + +let rec iter_abbrev f = function + Mnil -> () + | Mcons(_, _, ty, ty', rem) -> f ty; f ty'; iter_abbrev f rem + | Mlink rem -> iter_abbrev f !rem + +let copy_row f fixed row keep more = + let fields = List.map + (fun (l, fi) -> l, + match row_field_repr fi with + | Rpresent(Some ty) -> Rpresent(Some(f ty)) + | Reither(c, tl, m, e) -> + let e = if keep then e else ref None in + let m = if row.row_fixed then fixed else m in + let tl = List.map f tl in + Reither(c, tl, m, e) + | _ -> fi) + row.row_fields in + let name = + match row.row_name with None -> None + | Some (path, tl) -> Some (path, List.map f tl) in + { row_fields = fields; row_more = more; + row_bound = (); row_fixed = row.row_fixed && fixed; + row_closed = row.row_closed; row_name = name; } + +let rec copy_kind = function + Fvar{contents = Some k} -> copy_kind k + | Fvar _ -> Fvar (ref None) + | Fpresent -> Fpresent + | Fabsent -> assert false + +let copy_commu c = + if commu_repr c = Cok then Cok else Clink (ref Cunknown) + +(* Since univars may be used as row variables, we need to do some + encoding during substitution *) +let rec norm_univar ty = + match ty.desc with + Tunivar | Tsubst _ -> ty + | Tlink ty -> norm_univar ty + | Ttuple (ty :: _) -> norm_univar ty + | _ -> assert false + +let rec copy_type_desc f = function + Tvar -> Tvar + | Tarrow (p, ty1, ty2, c)-> Tarrow (p, f ty1, f ty2, copy_commu c) + | Ttuple l -> Ttuple (List.map f l) + | Tconstr (p, l, _) -> Tconstr (p, List.map f l, ref Mnil) + | Tobject(ty, {contents = Some (p, tl)}) + -> Tobject (f ty, ref (Some(p, List.map f tl))) + | Tobject (ty, _) -> Tobject (f ty, ref None) + | Tvariant row -> assert false (* too ambiguous *) + | Tfield (p, k, ty1, ty2) -> (* the kind is kept shared *) + Tfield (p, field_kind_repr k, f ty1, f ty2) + | Tnil -> Tnil + | Tlink ty -> copy_type_desc f ty.desc + | Tsubst ty -> assert false + | Tunivar -> Tunivar + | Tpoly (ty, tyl) -> + let tyl = List.map (fun x -> norm_univar (f x)) tyl in + Tpoly (f ty, tyl) + + +(* Utilities for copying *) + +let saved_desc = ref [] + (* Saved association of generic nodes with their description. *) + +let save_desc ty desc = + saved_desc := (ty, desc)::!saved_desc + +let saved_kinds = ref [] (* duplicated kind variables *) +let new_kinds = ref [] (* new kind variables *) +let dup_kind r = + (match !r with None -> () | Some _ -> assert false); + if not (List.memq r !new_kinds) then begin + saved_kinds := r :: !saved_kinds; + let r' = ref None in + new_kinds := r' :: !new_kinds; + r := Some (Fvar r') + end + +(* Restored type descriptions. *) +let cleanup_types () = + List.iter (fun (ty, desc) -> ty.desc <- desc) !saved_desc; + List.iter (fun r -> r := None) !saved_kinds; + saved_desc := []; saved_kinds := []; new_kinds := [] + +(* Mark a type. *) +let rec mark_type ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + ty.level <- pivot_level - ty.level; + iter_type_expr mark_type ty + end + +let mark_type_node ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + ty.level <- pivot_level - ty.level; + end + +let mark_type_params ty = + iter_type_expr mark_type ty + +(* Remove marks from a type. *) +let rec unmark_type ty = + let ty = repr ty in + if ty.level < lowest_level then begin + ty.level <- pivot_level - ty.level; + iter_type_expr unmark_type ty + end + +let unmark_type_decl decl = + List.iter unmark_type decl.type_params; + begin match decl.type_kind with + Type_abstract -> () + | Type_variant cstrs -> + List.iter (fun (c, tl) -> List.iter unmark_type tl) cstrs + | Type_record(lbls, rep) -> + List.iter (fun (c, mut, t) -> unmark_type t) lbls + end; + begin match decl.type_manifest with + None -> () + | Some ty -> unmark_type ty + end + +let unmark_class_signature sign = + unmark_type sign.cty_self; + Vars.iter (fun l (m, v, t) -> unmark_type t) sign.cty_vars + +let rec unmark_class_type = + function + Tcty_constr (p, tyl, cty) -> + List.iter unmark_type tyl; unmark_class_type cty + | Tcty_signature sign -> + unmark_class_signature sign + | Tcty_fun (_, ty, cty) -> + unmark_type ty; unmark_class_type cty + + + (*******************************************) + (* Memorization of abbreviation expansion *) + (*******************************************) + +(* Search whether the expansion has been memorized. *) +let rec find_expans priv p1 = function + Mnil -> None + | Mcons (priv', p2, ty0, ty, _) + when priv' >= priv && Path.same p1 p2 -> Some ty + | Mcons (_, _, _, _, rem) -> find_expans priv p1 rem + | Mlink {contents = rem} -> find_expans priv p1 rem + +(* debug: check for cycles in abbreviation. only works with -principal +let rec check_expans visited ty = + let ty = repr ty in + assert (not (List.memq ty visited)); + match ty.desc with + Tconstr (path, args, abbrev) -> + begin match find_expans path !abbrev with + Some ty' -> check_expans (ty :: visited) ty' + | None -> () + end + | _ -> () +*) + +let memo = ref [] + (* Contains the list of saved abbreviation expansions. *) + +let cleanup_abbrev () = + (* Remove all memorized abbreviation expansions. *) + List.iter (fun abbr -> abbr := Mnil) !memo; + memo := [] + +let memorize_abbrev mem priv path v v' = + (* Memorize the expansion of an abbreviation. *) + mem := Mcons (priv, path, v, v', !mem); + (* check_expans [] v; *) + memo := mem :: !memo + +let rec forget_abbrev_rec mem path = + match mem with + Mnil -> + assert false + | Mcons (_, path', _, _, rem) when Path.same path path' -> + rem + | Mcons (priv, path', v, v', rem) -> + Mcons (priv, path', v, v', forget_abbrev_rec rem path) + | Mlink mem' -> + mem' := forget_abbrev_rec !mem' path; + raise Exit + +let forget_abbrev mem path = + try mem := forget_abbrev_rec !mem path with Exit -> () + +(* debug: check for invalid abbreviations +let rec check_abbrev_rec = function + Mnil -> true + | Mcons (_, ty1, ty2, rem) -> + repr ty1 != repr ty2 + | Mlink mem' -> + check_abbrev_rec !mem' + +let check_memorized_abbrevs () = + List.for_all (fun mem -> check_abbrev_rec !mem) !memo +*) + + (**********************************) + (* Utilities for labels *) + (**********************************) + +let is_optional l = + String.length l > 0 && l.[0] = '?' + +let label_name l = + if is_optional l then String.sub l 1 (String.length l - 1) + else l + +let rec extract_label_aux hd l = function + [] -> raise Not_found + | (l',t as p) :: ls -> + if label_name l' = l then (l', t, List.rev hd, ls) + else extract_label_aux (p::hd) l ls + +let extract_label l ls = extract_label_aux [] l ls + + + (**********************************) + (* Utilities for backtracking *) + (**********************************) + +type change = + Ctype of type_expr * type_desc + | Clevel of type_expr * int + | Cname of + (Path.t * type_expr list) option ref * (Path.t * type_expr list) option + | Crow of row_field option ref * row_field option + | Ckind of field_kind option ref * field_kind option + | Ccommu of commutable ref * commutable + | Cuniv of type_expr option ref * type_expr option + +let undo_change = function + Ctype (ty, desc) -> ty.desc <- desc + | Clevel (ty, level) -> ty.level <- level + | Cname (r, v) -> r := v + | Crow (r, v) -> r := v + | Ckind (r, v) -> r := v + | Ccommu (r, v) -> r := v + | Cuniv (r, v) -> r := v + +type changes = + Change of change * changes ref + | Unchanged + | Invalid + +type snapshot = changes ref * int + +let trail = Weak.create 1 +let last_snapshot = ref 0 + +let log_change ch = + match Weak.get trail 0 with None -> () + | Some r -> + let r' = ref Unchanged in + r := Change (ch, r'); + Weak.set trail 0 (Some r') + +let log_type ty = + if ty.id <= !last_snapshot then log_change (Ctype (ty, ty.desc)) +let link_type ty ty' = log_type ty; ty.desc <- Tlink ty' + (* ; assert (check_memorized_abbrevs ()) *) + (* ; check_expans [] ty' *) +let set_level ty level = + if ty.id <= !last_snapshot then log_change (Clevel (ty, ty.level)); + ty.level <- level +let set_univar rty ty = + log_change (Cuniv (rty, !rty)); rty := Some ty +let set_name nm v = + log_change (Cname (nm, !nm)); nm := v +let set_row_field e v = + log_change (Crow (e, !e)); e := Some v +let set_kind rk k = + log_change (Ckind (rk, !rk)); rk := Some k +let set_commu rc c = + log_change (Ccommu (rc, !rc)); rc := c + +let snapshot () = + let old = !last_snapshot in + last_snapshot := !new_id; + match Weak.get trail 0 with Some r -> (r, old) + | None -> + let r = ref Unchanged in + Weak.set trail 0 (Some r); + (r, old) + +let rec rev_log accu = function + Unchanged -> accu + | Invalid -> assert false + | Change (ch, next) -> + let d = !next in + next := Invalid; + rev_log (ch::accu) d + +let backtrack (changes, old) = + match !changes with + Unchanged -> last_snapshot := old + | Invalid -> failwith "Btype.backtrack" + | Change _ as change -> + cleanup_abbrev (); + let backlog = rev_log [] change in + List.iter undo_change backlog; + changes := Unchanged; + last_snapshot := old; + Weak.set trail 0 (Some changes) diff --git a/typing/btype.mli b/typing/btype.mli new file mode 100644 index 0000000..3090395 --- /dev/null +++ b/typing/btype.mli @@ -0,0 +1,155 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: btype.mli,v 1.20 2008-07-19 02:13:09 garrigue Exp $ *) + +(* Basic operations on core types *) + +open Asttypes +open Types + +val generic_level: int + +val newty2: int -> type_desc -> type_expr + (* Create a type *) +val newgenty: type_desc -> type_expr + (* Create a generic type *) +val newgenvar: unit -> type_expr + (* Return a fresh generic variable *) + +(* Use Tsubst instead +val newmarkedvar: int -> type_expr + (* Return a fresh marked variable *) +val newmarkedgenvar: unit -> type_expr + (* Return a fresh marked generic variable *) +*) + +val repr: type_expr -> type_expr + (* Return the canonical representative of a type. *) + +val field_kind_repr: field_kind -> field_kind + (* Return the canonical representative of an object field + kind. *) + +val commu_repr: commutable -> commutable + (* Return the canonical representative of a commutation lock *) + +val row_repr: row_desc -> row_desc + (* Return the canonical representative of a row description *) +val row_field_repr: row_field -> row_field +val row_field: label -> row_desc -> row_field + (* Return the canonical representative of a row field *) +val row_more: row_desc -> type_expr + (* Return the extension variable of the row *) +val static_row: row_desc -> bool + (* Return whether the row is static or not *) +val hash_variant: label -> int + (* Hash function for variant tags *) + +val proxy: type_expr -> type_expr + (* Return the proxy representative of the type: either itself + or a row variable *) + +(**** Utilities for private abbreviations with fixed rows ****) +val has_constr_row: type_expr -> bool +val is_row_name: string -> bool + +(**** Utilities for type traversal ****) + +val iter_type_expr: (type_expr -> unit) -> type_expr -> unit + (* Iteration on types *) +val iter_row: (type_expr -> unit) -> row_desc -> unit + (* Iteration on types in a row *) +val iter_abbrev: (type_expr -> unit) -> abbrev_memo -> unit + (* Iteration on types in an abbreviation list *) + +val copy_type_desc: (type_expr -> type_expr) -> type_desc -> type_desc + (* Copy on types *) +val copy_row: + (type_expr -> type_expr) -> + bool -> row_desc -> bool -> type_expr -> row_desc +val copy_kind: field_kind -> field_kind + +val save_desc: type_expr -> type_desc -> unit + (* Save a type description *) +val dup_kind: field_kind option ref -> unit + (* Save a None field_kind, and make it point to a fresh Fvar *) +val cleanup_types: unit -> unit + (* Restore type descriptions *) + +val lowest_level: int + (* Marked type: ty.level < lowest_level *) +val pivot_level: int + (* Type marking: ty.level <- pivot_level - ty.level *) +val mark_type: type_expr -> unit + (* Mark a type *) +val mark_type_node: type_expr -> unit + (* Mark a type node (but not its sons) *) +val mark_type_params: type_expr -> unit + (* Mark the sons of a type node *) +val unmark_type: type_expr -> unit +val unmark_type_decl: type_declaration -> unit +val unmark_class_type: class_type -> unit +val unmark_class_signature: class_signature -> unit + (* Remove marks from a type *) + +(**** Memorization of abbreviation expansion ****) + +val find_expans: private_flag -> Path.t -> abbrev_memo -> type_expr option + (* Look up a memorized abbreviation *) +val cleanup_abbrev: unit -> unit + (* Flush the cache of abbreviation expansions. + When some types are saved (using [output_value]), this + function MUST be called just before. *) +val memorize_abbrev: + abbrev_memo ref -> + private_flag -> Path.t -> type_expr -> type_expr -> unit + (* Add an expansion in the cache *) +val forget_abbrev: + abbrev_memo ref -> Path.t -> unit + (* Remove an abbreviation from the cache *) + +(**** Utilities for labels ****) + +val is_optional : label -> bool +val label_name : label -> label +val extract_label : + label -> (label * 'a) list -> + label * 'a * (label * 'a) list * (label * 'a) list + (* actual label, value, before list, after list *) + +(**** Utilities for backtracking ****) + +type snapshot + (* A snapshot for backtracking *) +val snapshot: unit -> snapshot + (* Make a snapshot for later backtracking. Costs nothing *) +val backtrack: snapshot -> unit + (* Backtrack to a given snapshot. Only possible if you have + not already backtracked to a previous snapshot. + Calls [cleanup_abbrev] internally *) + +(* Functions to use when modifying a type (only Ctype?) *) +val link_type: type_expr -> type_expr -> unit + (* Set the desc field of [t1] to [Tlink t2], logging the old + value if there is an active snapshot *) +val set_level: type_expr -> int -> unit +val set_name: + (Path.t * type_expr list) option ref -> + (Path.t * type_expr list) option -> unit +val set_row_field: row_field option ref -> row_field -> unit +val set_univar: type_expr option ref -> type_expr -> unit +val set_kind: field_kind option ref -> field_kind -> unit +val set_commu: commutable ref -> commutable -> unit + (* Set references, logging the old value *) +val log_type: type_expr -> unit + (* Log the old value of a type, before modifying it by hand *) diff --git a/typing/ctype.ml b/typing/ctype.ml new file mode 100644 index 0000000..e79b45e --- /dev/null +++ b/typing/ctype.ml @@ -0,0 +1,3456 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ctype.ml,v 1.218 2008-12-03 18:09:09 doligez Exp $ *) + +(* Operations on core types *) + +open Misc +open Asttypes +open Types +open Btype + +(* + Type manipulation after type inference + ====================================== + If one wants to manipulate a type after type inference (for + instance, during code generation or in the debugger), one must + first make sure that the type levels are correct, using the + function [correct_levels]. Then, this type can be correctely + manipulated by [apply], [expand_head] and [moregeneral]. +*) + +(* + General notes + ============= + - As much sharing as possible should be kept : it makes types + smaller and better abbreviated. + When necessary, some sharing can be lost. Types will still be + printed correctly (+++ TO DO...), and abbreviations defined by a + class do not depend on sharing thanks to constrained + abbreviations. (Of course, even if some sharing is lost, typing + will still be correct.) + - All nodes of a type have a level : that way, one know whether a + node need to be duplicated or not when instantiating a type. + - Levels of a type are decreasing (generic level being considered + as greatest). + - The level of a type constructor is superior to the binding + time of its path. + - Recursive types without limitation should be handled (even if + there is still an occur check). This avoid treating specially the + case for objects, for instance. Furthermore, the occur check + policy can then be easily changed. +*) + +(* + A faire + ======= + - Revoir affichage des types. + - Etendre la portee d'un alias [... as 'a] a tout le type englobant. + - #-type implementes comme de vraies abreviations. + - Niveaux plus fins pour les identificateurs : + Champ [global] renomme en [level]; + Niveau -1 : global + 0 : module toplevel + 1 : module contenu dans module toplevel + ... + En fait, incrementer le niveau a chaque fois que l'on rentre dans + un module. + + 3 4 6 + \ / / + 1 2 5 + \|/ + 0 + + [Subst] doit ecreter les niveaux (pour qu'un variable non + generalisable dans un module de niveau 2 ne se retrouve pas + generalisable lorsque l'on l'utilise au niveau 0). + + - Traitement de la trace de l'unification separe de la fonction + [unify]. +*) + +(**** Errors ****) + +exception Unify of (type_expr * type_expr) list + +exception Tags of label * label + +exception Subtype of + (type_expr * type_expr) list * (type_expr * type_expr) list + +exception Cannot_expand + +exception Cannot_apply + +exception Recursive_abbrev + +(**** Type level management ****) + +let current_level = ref 0 +let nongen_level = ref 0 +let global_level = ref 1 +let saved_level = ref [] + +let init_def level = current_level := level; nongen_level := level +let begin_def () = + saved_level := (!current_level, !nongen_level) :: !saved_level; + incr current_level; nongen_level := !current_level +let begin_class_def () = + saved_level := (!current_level, !nongen_level) :: !saved_level; + incr current_level +let raise_nongen_level () = + saved_level := (!current_level, !nongen_level) :: !saved_level; + nongen_level := !current_level +let end_def () = + let (cl, nl) = List.hd !saved_level in + saved_level := List.tl !saved_level; + current_level := cl; nongen_level := nl + +let reset_global_level () = + global_level := !current_level + 1 +let increase_global_level () = + let gl = !global_level in + global_level := !current_level; + gl +let restore_global_level gl = + global_level := gl + +(* Abbreviations without parameters *) +(* Shall reset after generalizing *) +let simple_abbrevs = ref Mnil +let proper_abbrevs path tl abbrev = + if !Clflags.principal || tl <> [] then abbrev else + let name = match path with Path.Pident id -> Ident.name id + | Path.Pdot(_, s,_) -> s + | Path.Papply _ -> assert false in + if name.[0] <> '#' then simple_abbrevs else abbrev + +(**** Some type creators ****) + +(* Re-export generic type creators *) + +let newty2 = Btype.newty2 +let newty desc = newty2 !current_level desc +let new_global_ty desc = newty2 !global_level desc + +let newvar () = newty2 !current_level Tvar +let newvar2 level = newty2 level Tvar +let new_global_var () = newty2 !global_level Tvar + +let newobj fields = newty (Tobject (fields, ref None)) + +let newconstr path tyl = newty (Tconstr (path, tyl, ref Mnil)) + +let none = newty (Ttuple []) (* Clearly ill-formed type *) + +(**** Representative of a type ****) + +(* Re-export repr *) +let repr = repr + +(**** Type maps ****) + +module TypePairs = + Hashtbl.Make (struct + type t = type_expr * type_expr + let equal (t1, t1') (t2, t2') = (t1 == t2) && (t1' == t2') + let hash (t, t') = t.id + 93 * t'.id + end) + + (**********************************************) + (* Miscellaneous operations on object types *) + (**********************************************) + + +(**** Object field manipulation. ****) + +let dummy_method = "*dummy method*" + +let object_fields ty = + match (repr ty).desc with + Tobject (fields, _) -> fields + | _ -> assert false + +let flatten_fields ty = + let rec flatten l ty = + let ty = repr ty in + match ty.desc with + Tfield(s, k, ty1, ty2) -> + flatten ((s, k, ty1)::l) ty2 + | _ -> + (l, ty) + in + let (l, r) = flatten [] ty in + (Sort.list (fun (n, _, _) (n', _, _) -> n < n') l, r) + +let build_fields level = + List.fold_right + (fun (s, k, ty1) ty2 -> newty2 level (Tfield(s, k, ty1, ty2))) + +let associate_fields fields1 fields2 = + let rec associate p s s' = + function + (l, []) -> + (List.rev p, (List.rev s) @ l, List.rev s') + | ([], l') -> + (List.rev p, List.rev s, (List.rev s') @ l') + | ((n, k, t)::r, (n', k', t')::r') when n = n' -> + associate ((n, k, t, k', t')::p) s s' (r, r') + | ((n, k, t)::r, ((n', k', t')::_ as l')) when n < n' -> + associate p ((n, k, t)::s) s' (r, l') + | (((n, k, t)::r as l), (n', k', t')::r') (* when n > n' *) -> + associate p s ((n', k', t')::s') (l, r') + in + associate [] [] [] (fields1, fields2) + +(**** Check whether an object is open ****) + +(* +++ Il faudra penser a eventuellement expanser l'abreviation *) +let rec object_row ty = + let ty = repr ty in + match ty.desc with + Tobject (t, _) -> object_row t + | Tfield(_, _, _, t) -> object_row t + | _ -> ty + +let opened_object ty = + match (object_row ty).desc with + | Tvar -> true + | Tunivar -> true + | Tconstr _ -> true + | _ -> false + +(**** Close an object ****) + +let close_object ty = + let rec close ty = + let ty = repr ty in + match ty.desc with + Tvar -> + link_type ty (newty2 ty.level Tnil) + | Tfield(_, _, _, ty') -> close ty' + | _ -> assert false + in + match (repr ty).desc with + Tobject (ty, _) -> close ty + | _ -> assert false + +(**** Row variable of an object type ****) + +let row_variable ty = + let rec find ty = + let ty = repr ty in + match ty.desc with + Tfield (_, _, _, ty) -> find ty + | Tvar -> ty + | _ -> assert false + in + match (repr ty).desc with + Tobject (fi, _) -> find fi + | _ -> assert false + +(**** Object name manipulation ****) +(* +++ Bientot obsolete *) + +let set_object_name id rv params ty = + match (repr ty).desc with + Tobject (fi, nm) -> + set_name nm (Some (Path.Pident id, rv::params)) + | _ -> + assert false + +let remove_object_name ty = + match (repr ty).desc with + Tobject (_, nm) -> set_name nm None + | Tconstr (_, _, _) -> () + | _ -> fatal_error "Ctype.remove_object_name" + +(**** Hiding of private methods ****) + +let hide_private_methods ty = + match (repr ty).desc with + Tobject (fi, nm) -> + nm := None; + let (fl, _) = flatten_fields fi in + List.iter + (function (_, k, _) -> + match field_kind_repr k with + Fvar r -> set_kind r Fabsent + | _ -> ()) + fl + | _ -> + assert false + + + (*******************************) + (* Operations on class types *) + (*******************************) + + +let rec signature_of_class_type = + function + Tcty_constr (_, _, cty) -> signature_of_class_type cty + | Tcty_signature sign -> sign + | Tcty_fun (_, ty, cty) -> signature_of_class_type cty + +let self_type cty = + repr (signature_of_class_type cty).cty_self + +let rec class_type_arity = + function + Tcty_constr (_, _, cty) -> class_type_arity cty + | Tcty_signature _ -> 0 + | Tcty_fun (_, _, cty) -> 1 + class_type_arity cty + + + (*******************************************) + (* Miscellaneous operations on row types *) + (*******************************************) + +let sort_row_fields = Sort.list (fun (p,_) (q,_) -> p < q) + +let rec merge_rf r1 r2 pairs fi1 fi2 = + match fi1, fi2 with + (l1,f1 as p1)::fi1', (l2,f2 as p2)::fi2' -> + if l1 = l2 then merge_rf r1 r2 ((l1,f1,f2)::pairs) fi1' fi2' else + if l1 < l2 then merge_rf (p1::r1) r2 pairs fi1' fi2 else + merge_rf r1 (p2::r2) pairs fi1 fi2' + | [], _ -> (List.rev r1, List.rev_append r2 fi2, pairs) + | _, [] -> (List.rev_append r1 fi1, List.rev r2, pairs) + +let merge_row_fields fi1 fi2 = + match fi1, fi2 with + [], _ | _, [] -> (fi1, fi2, []) + | [p1], _ when not (List.mem_assoc (fst p1) fi2) -> (fi1, fi2, []) + | _, [p2] when not (List.mem_assoc (fst p2) fi1) -> (fi1, fi2, []) + | _ -> merge_rf [] [] [] (sort_row_fields fi1) (sort_row_fields fi2) + +let rec filter_row_fields erase = function + [] -> [] + | (l,f as p)::fi -> + let fi = filter_row_fields erase fi in + match row_field_repr f with + Rabsent -> fi + | Reither(_,_,false,e) when erase -> set_row_field e Rabsent; fi + | _ -> p :: fi + + (**************************************) + (* Check genericity of type schemes *) + (**************************************) + + +exception Non_closed + +let rec closed_schema_rec ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + let level = ty.level in + ty.level <- pivot_level - level; + match ty.desc with + Tvar when level <> generic_level -> + raise Non_closed + | Tfield(_, kind, t1, t2) -> + if field_kind_repr kind = Fpresent then + closed_schema_rec t1; + closed_schema_rec t2 + | Tvariant row -> + let row = row_repr row in + iter_row closed_schema_rec row; + if not (static_row row) then closed_schema_rec row.row_more + | _ -> + iter_type_expr closed_schema_rec ty + end + +(* Return whether all variables of type [ty] are generic. *) +let closed_schema ty = + try + closed_schema_rec ty; + unmark_type ty; + true + with Non_closed -> + unmark_type ty; + false + +exception Non_closed of type_expr * bool + +let free_variables = ref [] + +let rec free_vars_rec real ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + ty.level <- pivot_level - ty.level; + begin match ty.desc with + Tvar -> + free_variables := (ty, real) :: !free_variables +(* Do not count "virtual" free variables + | Tobject(ty, {contents = Some (_, p)}) -> + free_vars_rec false ty; List.iter (free_vars_rec true) p +*) + | Tobject (ty, _) -> + free_vars_rec false ty + | Tfield (_, _, ty1, ty2) -> + free_vars_rec true ty1; free_vars_rec false ty2 + | Tvariant row -> + let row = row_repr row in + iter_row (free_vars_rec true) row; + if not (static_row row) then free_vars_rec false row.row_more + | _ -> + iter_type_expr (free_vars_rec true) ty + end; + end + +let free_vars ty = + free_variables := []; + free_vars_rec true ty; + let res = !free_variables in + free_variables := []; + res + +let free_variables ty = + let tl = List.map fst (free_vars ty) in + unmark_type ty; + tl + +let rec closed_type ty = + match free_vars ty with + [] -> () + | (v, real) :: _ -> raise (Non_closed (v, real)) + +let closed_parameterized_type params ty = + List.iter mark_type params; + let ok = + try closed_type ty; true with Non_closed _ -> false in + List.iter unmark_type params; + unmark_type ty; + ok + +let closed_type_decl decl = + try + List.iter mark_type decl.type_params; + begin match decl.type_kind with + Type_abstract -> + () + | Type_variant v -> + List.iter (fun (_, tyl) -> List.iter closed_type tyl) v + | Type_record(r, rep) -> + List.iter (fun (_, _, ty) -> closed_type ty) r + end; + begin match decl.type_manifest with + None -> () + | Some ty -> closed_type ty + end; + unmark_type_decl decl; + None + with Non_closed (ty, _) -> + unmark_type_decl decl; + Some ty + +type closed_class_failure = + CC_Method of type_expr * bool * string * type_expr + | CC_Value of type_expr * bool * string * type_expr + +exception Failure of closed_class_failure + +let closed_class params sign = + let ty = object_fields (repr sign.cty_self) in + let (fields, rest) = flatten_fields ty in + List.iter mark_type params; + mark_type rest; + List.iter + (fun (lab, _, ty) -> if lab = dummy_method then mark_type ty) + fields; + try + mark_type_node (repr sign.cty_self); + List.iter + (fun (lab, kind, ty) -> + if field_kind_repr kind = Fpresent then + try closed_type ty with Non_closed (ty0, real) -> + raise (Failure (CC_Method (ty0, real, lab, ty)))) + fields; + mark_type_params (repr sign.cty_self); + List.iter unmark_type params; + unmark_class_signature sign; + None + with Failure reason -> + mark_type_params (repr sign.cty_self); + List.iter unmark_type params; + unmark_class_signature sign; + Some reason + + + (**********************) + (* Type duplication *) + (**********************) + + +(* Duplicate a type, preserving only type variables *) +let duplicate_type ty = + Subst.type_expr Subst.identity ty + +(* Same, for class types *) +let duplicate_class_type ty = + Subst.class_type Subst.identity ty + + + (*****************************) + (* Type level manipulation *) + (*****************************) + +(* + It would be a bit more efficient to remove abbreviation expansions + rather than generalizing them: these expansions will usually not be + used anymore. However, this is not possible in the general case, as + [expand_abbrev] (via [subst]) requires these expansions to be + preserved. Does it worth duplicating this code ? +*) +let rec iter_generalize tyl ty = + let ty = repr ty in + if (ty.level > !current_level) && (ty.level <> generic_level) then begin + set_level ty generic_level; + begin match ty.desc with + Tconstr (_, _, abbrev) -> + iter_abbrev (iter_generalize tyl) !abbrev + | _ -> () + end; + iter_type_expr (iter_generalize tyl) ty + end else + tyl := ty :: !tyl + +let iter_generalize tyl ty = + simple_abbrevs := Mnil; + iter_generalize tyl ty + +let generalize ty = + iter_generalize (ref []) ty + +(* Efficient repeated generalisation of the same type *) +let iterative_generalization min_level tyl = + let tyl' = ref [] in + List.iter (iter_generalize tyl') tyl; + List.fold_right (fun ty l -> if ty.level <= min_level then l else ty::l) + !tyl' [] + +(* Generalize the structure and lower the variables *) + +let rec generalize_structure var_level ty = + let ty = repr ty in + if ty.level <> generic_level then begin + if ty.desc = Tvar && ty.level > var_level then + set_level ty var_level + else if ty.level > !current_level then begin + set_level ty generic_level; + begin match ty.desc with + Tconstr (_, _, abbrev) -> abbrev := Mnil + | _ -> () + end; + iter_type_expr (generalize_structure var_level) ty + end + end + +let generalize_structure var_level ty = + simple_abbrevs := Mnil; + generalize_structure var_level ty + +(* let generalize_expansive ty = generalize_structure !nongen_level ty *) +let generalize_global ty = generalize_structure !global_level ty +let generalize_structure ty = generalize_structure !current_level ty + +(* Generalize the spine of a function, if the level >= !current_level *) + +let rec generalize_spine ty = + let ty = repr ty in + if ty.level < !current_level || ty.level = generic_level then () else + match ty.desc with + Tarrow (_, _, ty', _) | Tpoly (ty', _) -> + set_level ty generic_level; + generalize_spine ty' + | _ -> () + +let forward_try_expand_once = (* Forward declaration *) + ref (fun env ty -> raise Cannot_expand) + +(* + Lower the levels of a type (assume [level] is not + [generic_level]). +*) +(* + The level of a type constructor must be greater than its binding + time. That way, a type constructor cannot escape the scope of its + definition, as would be the case in + let x = ref [] + module M = struct type t let _ = (x : t list ref) end + (without this constraint, the type system would actually be unsound.) +*) +let rec update_level env level ty = + let ty = repr ty in + if ty.level > level then begin + begin match ty.desc with + Tconstr(p, tl, abbrev) when level < Path.binding_time p -> + (* Try first to replace an abbreviation by its expansion. *) + begin try + link_type ty (!forward_try_expand_once env ty); + update_level env level ty + with Cannot_expand -> + (* +++ Levels should be restored... *) + raise (Unify [(ty, newvar2 level)]) + end + | Tobject(_, ({contents=Some(p, tl)} as nm)) + when level < Path.binding_time p -> + set_name nm None; + update_level env level ty + | Tvariant row -> + let row = row_repr row in + begin match row.row_name with + | Some (p, tl) when level < Path.binding_time p -> + log_type ty; + ty.desc <- Tvariant {row with row_name = None} + | _ -> () + end; + set_level ty level; + iter_type_expr (update_level env level) ty + | Tfield(lab, _, _, _) when lab = dummy_method -> + raise (Unify [(ty, newvar2 level)]) + | _ -> + set_level ty level; + (* XXX what about abbreviations in Tconstr ? *) + iter_type_expr (update_level env level) ty + end + end + +(* Generalize and lower levels of contravariant branches simultaneously *) + +let rec generalize_expansive env var_level ty = + let ty = repr ty in + if ty.level <> generic_level then begin + if ty.level > var_level then begin + set_level ty generic_level; + match ty.desc with + Tconstr (path, tyl, abbrev) -> + let variance = + try (Env.find_type path env).type_variance + with Not_found -> List.map (fun _ -> (true,true,true)) tyl in + abbrev := Mnil; + List.iter2 + (fun (co,cn,ct) t -> + if ct then update_level env var_level t + else generalize_expansive env var_level t) + variance tyl + | Tarrow (_, t1, t2, _) -> + update_level env var_level t1; + generalize_expansive env var_level t2 + | _ -> + iter_type_expr (generalize_expansive env var_level) ty + end + end + +let generalize_expansive env ty = + simple_abbrevs := Mnil; + try + generalize_expansive env !nongen_level ty + with Unify [_, ty'] -> + raise (Unify [ty, ty']) + +(* Correct the levels of type [ty]. *) +let correct_levels ty = + duplicate_type ty + +(* Only generalize the type ty0 in ty *) +let limited_generalize ty0 ty = + let ty0 = repr ty0 in + + let graph = Hashtbl.create 17 in + let idx = ref lowest_level in + let roots = ref [] in + + let rec inverse pty ty = + let ty = repr ty in + if (ty.level > !current_level) || (ty.level = generic_level) then begin + decr idx; + Hashtbl.add graph !idx (ty, ref pty); + if (ty.level = generic_level) || (ty == ty0) then + roots := ty :: !roots; + set_level ty !idx; + iter_type_expr (inverse [ty]) ty + end else if ty.level < lowest_level then begin + let (_, parents) = Hashtbl.find graph ty.level in + parents := pty @ !parents + end + + and generalize_parents ty = + let idx = ty.level in + if idx <> generic_level then begin + set_level ty generic_level; + List.iter generalize_parents !(snd (Hashtbl.find graph idx)); + (* Special case for rows: must generalize the row variable *) + match ty.desc with + Tvariant row -> + let more = row_more row in + let lv = more.level in + if (lv < lowest_level || lv > !current_level) + && lv <> generic_level then set_level more generic_level + | _ -> () + end + in + + inverse [] ty; + if ty0.level < lowest_level then + iter_type_expr (inverse []) ty0; + List.iter generalize_parents !roots; + Hashtbl.iter + (fun _ (ty, _) -> + if ty.level <> generic_level then set_level ty !current_level) + graph + + + (*******************) + (* Instantiation *) + (*******************) + + +let rec find_repr p1 = + function + Mnil -> + None + | Mcons (Public, p2, ty, _, _) when Path.same p1 p2 -> + Some ty + | Mcons (_, _, _, _, rem) -> + find_repr p1 rem + | Mlink {contents = rem} -> + find_repr p1 rem + +(* + Generic nodes are duplicated, while non-generic nodes are left + as-is. + During instantiation, the description of a generic node is first + replaced by a link to a stub ([Tsubst (newvar ())]). Once the + copy is made, it replaces the stub. + After instantiation, the description of generic node, which was + stored by [save_desc], must be put back, using [cleanup_types]. +*) + +let abbreviations = ref (ref Mnil) + (* Abbreviation memorized. *) + +let rec copy ty = + let ty = repr ty in + match ty.desc with + Tsubst ty -> ty + | _ -> + if ty.level <> generic_level then ty else + let desc = ty.desc in + save_desc ty desc; + let t = newvar() in (* Stub *) + ty.desc <- Tsubst t; + t.desc <- + begin match desc with + | Tconstr (p, tl, _) -> + let abbrevs = proper_abbrevs p tl !abbreviations in + begin match find_repr p !abbrevs with + Some ty when repr ty != t -> (* XXX Commentaire... *) + Tlink ty + | _ -> + (* + One must allocate a new reference, so that abbrevia- + tions belonging to different branches of a type are + independent. + Moreover, a reference containing a [Mcons] must be + shared, so that the memorized expansion of an abbrevi- + ation can be released by changing the content of just + one reference. + *) + Tconstr (p, List.map copy tl, + ref (match !(!abbreviations) with + Mcons _ -> Mlink !abbreviations + | abbrev -> abbrev)) + end + | Tvariant row0 -> + let row = row_repr row0 in + let more = repr row.row_more in + (* We must substitute in a subtle way *) + (* Tsubst takes a tuple containing the row var and the variant *) + begin match more.desc with + Tsubst {desc = Ttuple [_;ty2]} -> + (* This variant type has been already copied *) + ty.desc <- Tsubst ty2; (* avoid Tlink in the new type *) + Tlink ty2 + | _ -> + (* If the row variable is not generic, we must keep it *) + let keep = more.level <> generic_level in + let more' = + match more.desc with + Tsubst ty -> ty + | Tconstr _ -> + if keep then save_desc more more.desc; + copy more + | Tvar | Tunivar -> + save_desc more more.desc; + if keep then more else newty more.desc + | _ -> assert false + in + (* Register new type first for recursion *) + more.desc <- Tsubst(newgenty(Ttuple[more';t])); + (* Return a new copy *) + Tvariant (copy_row copy true row keep more') + end + | Tfield (p, k, ty1, ty2) -> + begin match field_kind_repr k with + Fabsent -> Tlink (copy ty2) + | Fpresent -> copy_type_desc copy desc + | Fvar r -> + dup_kind r; + copy_type_desc copy desc + end + | _ -> copy_type_desc copy desc + end; + t + +(**** Variants of instantiations ****) + +let instance sch = + let ty = copy sch in + cleanup_types (); + ty + +let instance_list schl = + let tyl = List.map copy schl in + cleanup_types (); + tyl + +let instance_constructor cstr = + let ty_res = copy cstr.cstr_res in + let ty_args = List.map copy cstr.cstr_args in + cleanup_types (); + (ty_args, ty_res) + +let instance_parameterized_type sch_args sch = + let ty_args = List.map copy sch_args in + let ty = copy sch in + cleanup_types (); + (ty_args, ty) + +let instance_parameterized_type_2 sch_args sch_lst sch = + let ty_args = List.map copy sch_args in + let ty_lst = List.map copy sch_lst in + let ty = copy sch in + cleanup_types (); + (ty_args, ty_lst, ty) + +let instance_class params cty = + let rec copy_class_type = + function + Tcty_constr (path, tyl, cty) -> + Tcty_constr (path, List.map copy tyl, copy_class_type cty) + | Tcty_signature sign -> + Tcty_signature + {cty_self = copy sign.cty_self; + cty_vars = + Vars.map (function (m, v, ty) -> (m, v, copy ty)) sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = + List.map (fun (p,tl) -> (p, List.map copy tl)) sign.cty_inher} + | Tcty_fun (l, ty, cty) -> + Tcty_fun (l, copy ty, copy_class_type cty) + in + let params' = List.map copy params in + let cty' = copy_class_type cty in + cleanup_types (); + (params', cty') + +(**** Instanciation for types with free universal variables ****) + +module TypeHash = Hashtbl.Make(TypeOps) +module TypeSet = Set.Make(TypeOps) + +type inv_type_expr = + { inv_type : type_expr; + mutable inv_parents : inv_type_expr list } + +let rec inv_type hash pty ty = + let ty = repr ty in + try + let inv = TypeHash.find hash ty in + inv.inv_parents <- pty @ inv.inv_parents + with Not_found -> + let inv = { inv_type = ty; inv_parents = pty } in + TypeHash.add hash ty inv; + iter_type_expr (inv_type hash [inv]) ty + +let compute_univars ty = + let inverted = TypeHash.create 17 in + inv_type inverted [] ty; + let node_univars = TypeHash.create 17 in + let rec add_univar univ inv = + match inv.inv_type.desc with + Tpoly (ty, tl) when List.memq univ (List.map repr tl) -> () + | _ -> + try + let univs = TypeHash.find node_univars inv.inv_type in + if not (TypeSet.mem univ !univs) then begin + univs := TypeSet.add univ !univs; + List.iter (add_univar univ) inv.inv_parents + end + with Not_found -> + TypeHash.add node_univars inv.inv_type (ref(TypeSet.singleton univ)); + List.iter (add_univar univ) inv.inv_parents + in + TypeHash.iter (fun ty inv -> if ty.desc = Tunivar then add_univar ty inv) + inverted; + fun ty -> + try !(TypeHash.find node_univars ty) with Not_found -> TypeSet.empty + +let rec diff_list l1 l2 = + if l1 == l2 then [] else + match l1 with [] -> invalid_arg "Ctype.diff_list" + | a :: l1 -> a :: diff_list l1 l2 + +let conflicts free bound = + let bound = List.map repr bound in + TypeSet.exists (fun t -> List.memq (repr t) bound) free + +let delayed_copy = ref [] + (* copying to do later *) + +(* Copy without sharing until there are no free univars left *) +(* all free univars must be included in [visited] *) +let rec copy_sep fixed free bound visited ty = + let ty = repr ty in + let univars = free ty in + if TypeSet.is_empty univars then + if ty.level <> generic_level then ty else + let t = newvar () in + delayed_copy := + lazy (t.desc <- Tlink (copy ty)) + :: !delayed_copy; + t + else try + let t, bound_t = List.assq ty visited in + let dl = if ty.desc = Tunivar then [] else diff_list bound bound_t in + if dl <> [] && conflicts univars dl then raise Not_found; + t + with Not_found -> begin + let t = newvar() in (* Stub *) + let visited = + match ty.desc with + Tarrow _ | Ttuple _ | Tvariant _ | Tconstr _ | Tobject _ -> + (ty,(t,bound)) :: visited + | _ -> visited in + let copy_rec = copy_sep fixed free bound visited in + t.desc <- + begin match ty.desc with + | Tvariant row0 -> + let row = row_repr row0 in + let more = repr row.row_more in + (* We shall really check the level on the row variable *) + let keep = more.desc = Tvar && more.level <> generic_level in + let more' = copy_rec more in + let fixed' = fixed && (repr more').desc = Tvar in + let row = copy_row copy_rec fixed' row keep more' in + Tvariant row + | Tpoly (t1, tl) -> + let tl = List.map repr tl in + let tl' = List.map (fun t -> newty Tunivar) tl in + let bound = tl @ bound in + let visited = + List.map2 (fun ty t -> ty,(t,bound)) tl tl' @ visited in + Tpoly (copy_sep fixed free bound visited t1, tl') + | _ -> copy_type_desc copy_rec ty.desc + end; + t + end + +let instance_poly fixed univars sch = + let vars = List.map (fun _ -> newvar ()) univars in + let pairs = List.map2 (fun u v -> repr u, (v, [])) univars vars in + delayed_copy := []; + let ty = copy_sep fixed (compute_univars sch) [] pairs sch in + List.iter Lazy.force !delayed_copy; + delayed_copy := []; + cleanup_types (); + vars, ty + +let instance_label fixed lbl = + let ty_res = copy lbl.lbl_res in + let vars, ty_arg = + match repr lbl.lbl_arg with + {desc = Tpoly (ty, tl)} -> + instance_poly fixed tl ty + | ty -> + [], copy lbl.lbl_arg + in + cleanup_types (); + (vars, ty_arg, ty_res) + +(**** Instantiation with parameter substitution ****) + +let unify' = (* Forward declaration *) + ref (fun env ty1 ty2 -> raise (Unify [])) + +let rec subst env level priv abbrev ty params args body = + if List.length params <> List.length args then raise (Unify []); + let old_level = !current_level in + current_level := level; + try + let body0 = newvar () in (* Stub *) + begin match ty with + None -> () + | Some ({desc = Tconstr (path, tl, _)} as ty) -> + let abbrev = proper_abbrevs path tl abbrev in + memorize_abbrev abbrev priv path ty body0 + | _ -> + assert false + end; + abbreviations := abbrev; + let (params', body') = instance_parameterized_type params body in + abbreviations := ref Mnil; + !unify' env body0 body'; + List.iter2 (!unify' env) params' args; + current_level := old_level; + body' + with Unify _ as exn -> + current_level := old_level; + raise exn + +(* + Only the shape of the type matters, not whether is is generic or + not. [generic_level] might be somewhat slower, but it ensures + invariants on types are enforced (decreasing levels.), and we don't + care about efficiency here. +*) +let apply env params body args = + try + subst env generic_level Public (ref Mnil) None params args body + with + Unify _ -> raise Cannot_apply + + + (****************************) + (* Abbreviation expansion *) + (****************************) + +(* + If the environnement has changed, memorized expansions might not + be correct anymore, and so we flush the cache. This is safe but + quite pessimistic: it would be enough to flush the cache when a + type or module definition is overriden in the environnement. +*) +let previous_env = ref Env.empty +let string_of_kind = function Public -> "public" | Private -> "private" +let check_abbrev_env env = + if env != !previous_env then begin + (* prerr_endline "cleanup expansion cache"; *) + cleanup_abbrev (); + previous_env := env + end + +(* Expand an abbreviation. The expansion is memorized. *) +(* + Assume the level is greater than the path binding time of the + expanded abbreviation. +*) +(* + An abbreviation expansion will fail in either of these cases: + 1. The type constructor does not correspond to a manifest type. + 2. The type constructor is defined in an external file, and this + file is not in the path (missing -I options). + 3. The type constructor is not in the "local" environment. This can + happens when a non-generic type variable has been instantiated + afterwards to the not yet defined type constructor. (Actually, + this cannot happen at the moment due to the strong constraints + between type levels and constructor binding time.) + 4. The expansion requires the expansion of another abbreviation, + and this other expansion fails. +*) +let expand_abbrev_gen kind find_type_expansion env ty = + check_abbrev_env env; + match ty with + {desc = Tconstr (path, args, abbrev); level = level} -> + let lookup_abbrev = proper_abbrevs path args abbrev in + begin match find_expans kind path !lookup_abbrev with + Some ty -> + (* prerr_endline + ("found a "^string_of_kind kind^" expansion for "^Path.name path);*) + if level <> generic_level then + begin try + update_level env level ty + with Unify _ -> + (* XXX This should not happen. + However, levels are not correctly restored after a + typing error *) + () + end; + ty + | None -> + let (params, body) = + try find_type_expansion path env with Not_found -> + raise Cannot_expand + in + (* prerr_endline + ("add a "^string_of_kind kind^" expansion for "^Path.name path);*) + let ty' = subst env level kind abbrev (Some ty) params args body in + (* Hack to name the variant type *) + begin match repr ty' with + {desc=Tvariant row} as ty when static_row row -> + ty.desc <- Tvariant { row with row_name = Some (path, args) } + | _ -> () + end; + ty' + end + | _ -> + assert false + +let expand_abbrev = expand_abbrev_gen Public Env.find_type_expansion + +let safe_abbrev env ty = + let snap = Btype.snapshot () in + try ignore (expand_abbrev env ty); true + with Cannot_expand | Unify _ -> + Btype.backtrack snap; + false + +let try_expand_once env ty = + let ty = repr ty in + match ty.desc with + Tconstr _ -> repr (expand_abbrev env ty) + | _ -> raise Cannot_expand + +let _ = forward_try_expand_once := try_expand_once + +(* Fully expand the head of a type. + Raise Cannot_expand if the type cannot be expanded. + May raise Unify, if a recursion was hidden in the type. *) +let rec try_expand_head env ty = + let ty' = try_expand_once env ty in + begin try + try_expand_head env ty' + with Cannot_expand -> + ty' + end + +(* Expand once the head of a type *) +let expand_head_once env ty = + try expand_abbrev env (repr ty) with Cannot_expand -> assert false + +(* Fully expand the head of a type. *) +let expand_head_unif env ty = + try try_expand_head env ty with Cannot_expand -> repr ty + +let expand_head env ty = + let snap = Btype.snapshot () in + try try_expand_head env ty + with Cannot_expand | Unify _ -> (* expand_head shall never fail *) + Btype.backtrack snap; + repr ty + +(* Implementing function [expand_head_opt], the compiler's own version of + [expand_head] used for type-based optimisations. + [expand_head_opt] uses [Env.find_type_expansion_opt] to access the + manifest type information of private abstract data types which is + normally hidden to the type-checker out of the implementation module of + the private abbreviation. *) + +let expand_abbrev_opt = expand_abbrev_gen Private Env.find_type_expansion_opt + +let try_expand_once_opt env ty = + let ty = repr ty in + match ty.desc with + Tconstr _ -> repr (expand_abbrev_opt env ty) + | _ -> raise Cannot_expand + +let rec try_expand_head_opt env ty = + let ty' = try_expand_once_opt env ty in + begin try + try_expand_head_opt env ty' + with Cannot_expand -> + ty' + end + +let expand_head_opt env ty = + let snap = Btype.snapshot () in + try try_expand_head_opt env ty + with Cannot_expand | Unify _ -> (* expand_head shall never fail *) + Btype.backtrack snap; + repr ty + +(* Make sure that the type parameters of the type constructor [ty] + respect the type constraints *) +let enforce_constraints env ty = + match ty with + {desc = Tconstr (path, args, abbrev); level = level} -> + let decl = Env.find_type path env in + ignore + (subst env level Public (ref Mnil) None decl.type_params args + (newvar2 level)) + | _ -> + assert false + +(* Recursively expand the head of a type. + Also expand #-types. *) +let rec full_expand env ty = + let ty = repr (expand_head env ty) in + match ty.desc with + Tobject (fi, {contents = Some (_, v::_)}) when (repr v).desc = Tvar -> + newty2 ty.level (Tobject (fi, ref None)) + | _ -> + ty + +(* + Check whether the abbreviation expands to a well-defined type. + During the typing of a class, abbreviations for correspondings + types expand to non-generic types. +*) +let generic_abbrev env path = + try + let (_, body) = Env.find_type_expansion path env in + (repr body).level = generic_level + with + Not_found -> + false + + + (*****************) + (* Occur check *) + (*****************) + + +exception Occur + +(* The marks are already used by [expand_abbrev]... *) +let visited = ref [] + +let rec non_recursive_abbrev env ty0 ty = + let ty = repr ty in + if ty == repr ty0 then raise Recursive_abbrev; + if not (List.memq ty !visited) then begin + visited := ty :: !visited; + match ty.desc with + Tconstr(p, args, abbrev) -> + begin try + non_recursive_abbrev env ty0 (try_expand_once env ty) + with Cannot_expand -> + if !Clflags.recursive_types then () else + iter_type_expr (non_recursive_abbrev env ty0) ty + end + | Tobject _ | Tvariant _ -> + () + | _ -> + if !Clflags.recursive_types then () else + iter_type_expr (non_recursive_abbrev env ty0) ty + end + +let correct_abbrev env path params ty = + check_abbrev_env env; + let ty0 = newgenvar () in + visited := []; + let abbrev = Mcons (Public, path, ty0, ty0, Mnil) in + simple_abbrevs := abbrev; + try + non_recursive_abbrev env ty0 + (subst env generic_level Public (ref abbrev) None [] [] ty); + simple_abbrevs := Mnil; + visited := [] + with exn -> + simple_abbrevs := Mnil; + visited := []; + raise exn + +let rec occur_rec env visited ty0 ty = + if ty == ty0 then raise Occur; + match ty.desc with + Tconstr(p, tl, abbrev) -> + begin try + if List.memq ty visited || !Clflags.recursive_types then raise Occur; + iter_type_expr (occur_rec env (ty::visited) ty0) ty + with Occur -> try + let ty' = try_expand_head env ty in + (* Maybe we could simply make a recursive call here, + but it seems it could make the occur check loop + (see change in rev. 1.58) *) + if ty' == ty0 || List.memq ty' visited then raise Occur; + match ty'.desc with + Tobject _ | Tvariant _ -> () + | _ -> + if not !Clflags.recursive_types then + iter_type_expr (occur_rec env (ty'::visited) ty0) ty' + with Cannot_expand -> + if not !Clflags.recursive_types then raise Occur + end + | Tobject _ | Tvariant _ -> + () + | _ -> + if not !Clflags.recursive_types then + iter_type_expr (occur_rec env visited ty0) ty + +let type_changed = ref false (* trace possible changes to the studied type *) + +let merge r b = if b then r := true + +let occur env ty0 ty = + let old = !type_changed in + try + while type_changed := false; occur_rec env [] ty0 ty; !type_changed + do () (* prerr_endline "changed" *) done; + merge type_changed old + with exn -> + merge type_changed old; + raise (match exn with Occur -> Unify [] | _ -> exn) + + + (*****************************) + (* Polymorphic Unification *) + (*****************************) + +(* Since we cannot duplicate universal variables, unification must + be done at meta-level, using bindings in univar_pairs *) +let rec unify_univar t1 t2 = function + (cl1, cl2) :: rem -> + let find_univ t cl = + try + let (_, r) = List.find (fun (t',_) -> t == repr t') cl in + Some r + with Not_found -> None + in + begin match find_univ t1 cl1, find_univ t2 cl2 with + Some {contents=Some t'2}, Some _ when t2 == repr t'2 -> + () + | Some({contents=None} as r1), Some({contents=None} as r2) -> + set_univar r1 t2; set_univar r2 t1 + | None, None -> + unify_univar t1 t2 rem + | _ -> + raise (Unify []) + end + | [] -> raise (Unify []) + +module TypeMap = Map.Make (TypeOps) + +(* Test the occurence of free univars in a type *) +(* that's way too expansive. Must do some kind of cacheing *) +let occur_univar env ty = + let visited = ref TypeMap.empty in + let rec occur_rec bound ty = + let ty = repr ty in + if ty.level >= lowest_level && + if TypeSet.is_empty bound then + (ty.level <- pivot_level - ty.level; true) + else try + let bound' = TypeMap.find ty !visited in + if TypeSet.exists (fun x -> not (TypeSet.mem x bound)) bound' then + (visited := TypeMap.add ty (TypeSet.inter bound bound') !visited; + true) + else false + with Not_found -> + visited := TypeMap.add ty bound !visited; + true + then + match ty.desc with + Tunivar -> + if not (TypeSet.mem ty bound) then raise (Unify [ty, newgenvar()]) + | Tpoly (ty, tyl) -> + let bound = List.fold_right TypeSet.add (List.map repr tyl) bound in + occur_rec bound ty + | Tconstr (_, [], _) -> () + | Tconstr (p, tl, _) -> + begin try + let td = Env.find_type p env in + List.iter2 + (fun t (pos,neg,_) -> if pos || neg then occur_rec bound t) + tl td.type_variance + with Not_found -> + List.iter (occur_rec bound) tl + end + | _ -> iter_type_expr (occur_rec bound) ty + in + try + occur_rec TypeSet.empty ty; unmark_type ty + with exn -> + unmark_type ty; raise exn + +(* Grouping univars by families according to their binders *) +let add_univars = + List.fold_left (fun s (t,_) -> TypeSet.add (repr t) s) + +let get_univar_family univar_pairs univars = + if univars = [] then TypeSet.empty else + let rec insert s = function + cl1, (_::_ as cl2) -> + if List.exists (fun (t1,_) -> TypeSet.mem (repr t1) s) cl1 then + add_univars s cl2 + else s + | _ -> s + in + let s = List.fold_right TypeSet.add univars TypeSet.empty in + List.fold_left insert s univar_pairs + +(* Whether a family of univars escapes from a type *) +let univars_escape env univar_pairs vl ty = + let family = get_univar_family univar_pairs vl in + let visited = ref TypeSet.empty in + let rec occur t = + let t = repr t in + if TypeSet.mem t !visited then () else begin + visited := TypeSet.add t !visited; + match t.desc with + Tpoly (t, tl) -> + if List.exists (fun t -> TypeSet.mem (repr t) family) tl then () + else occur t + | Tunivar -> + if TypeSet.mem t family then raise Occur + | Tconstr (_, [], _) -> () + | Tconstr (p, tl, _) -> + begin try + let td = Env.find_type p env in + List.iter2 (fun t (pos,neg,_) -> if pos || neg then occur t) + tl td.type_variance + with Not_found -> + List.iter occur tl + end + | _ -> + iter_type_expr occur t + end + in + try occur ty; false with Occur -> true + +(* Wrapper checking that no variable escapes and updating univar_pairs *) +let enter_poly env univar_pairs t1 tl1 t2 tl2 f = + let old_univars = !univar_pairs in + let known_univars = + List.fold_left (fun s (cl,_) -> add_univars s cl) + TypeSet.empty old_univars + in + let tl1 = List.map repr tl1 and tl2 = List.map repr tl2 in + if List.exists (fun t -> TypeSet.mem t known_univars) tl1 && + univars_escape env old_univars tl1 (newty(Tpoly(t2,tl2))) + || List.exists (fun t -> TypeSet.mem t known_univars) tl2 && + univars_escape env old_univars tl2 (newty(Tpoly(t1,tl1))) + then raise (Unify []); + let cl1 = List.map (fun t -> t, ref None) tl1 + and cl2 = List.map (fun t -> t, ref None) tl2 in + univar_pairs := (cl1,cl2) :: (cl2,cl1) :: old_univars; + try let res = f t1 t2 in univar_pairs := old_univars; res + with exn -> univar_pairs := old_univars; raise exn + +let univar_pairs = ref [] + + + (*****************) + (* Unification *) + (*****************) + + + +let rec has_cached_expansion p abbrev = + match abbrev with + Mnil -> false + | Mcons(_, p', _, _, rem) -> Path.same p p' || has_cached_expansion p rem + | Mlink rem -> has_cached_expansion p !rem + +(**** Transform error trace ****) +(* +++ Move it to some other place ? *) + +let expand_trace env trace = + List.fold_right + (fun (t1, t2) rem -> + (repr t1, full_expand env t1)::(repr t2, full_expand env t2)::rem) + trace [] + +(* build a dummy variant type *) +let mkvariant fields closed = + newgenty + (Tvariant + {row_fields = fields; row_closed = closed; row_more = newvar(); + row_bound = (); row_fixed = false; row_name = None }) + +(* force unification in Reither when one side has as non-conjunctive type *) +let rigid_variants = ref false + +(**** Unification ****) + +(* Return whether [t0] occurs in [ty]. Objects are also traversed. *) +let deep_occur t0 ty = + let rec occur_rec ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + if ty == t0 then raise Occur; + ty.level <- pivot_level - ty.level; + iter_type_expr occur_rec ty + end + in + try + occur_rec ty; unmark_type ty; false + with Occur -> + unmark_type ty; true + +(* + 1. When unifying two non-abbreviated types, one type is made a link + to the other. When unifying an abbreviated type with a + non-abbreviated type, the non-abbreviated type is made a link to + the other one. When unifying to abbreviated types, these two + types are kept distincts, but they are made to (temporally) + expand to the same type. + 2. Abbreviations with at least one parameter are systematically + expanded. The overhead does not seem to high, and that way + abbreviations where some parameters does not appear in the + expansion, such as ['a t = int], are correctly handled. In + particular, for this example, unifying ['a t] with ['b t] keeps + ['a] and ['b] distincts. (Is it really important ?) + 3. Unifying an abbreviation ['a t = 'a] with ['a] should not yield + ['a t as 'a]. Indeed, the type variable would otherwise be lost. + This problem occurs for abbreviations expanding to a type + variable, but also to many other constrained abbreviations (for + instance, [(< x : 'a > -> unit) t = <x : 'a>]). The solution is + that, if an abbreviation is unified with some subpart of its + parameters, then the parameter actually does not get + abbreviated. It would be possible to check whether some + information is indeed lost, but it probably does not worth it. +*) +let rec unify env t1 t2 = + (* First step: special cases (optimizations) *) + if t1 == t2 then () else + let t1 = repr t1 in + let t2 = repr t2 in + if t1 == t2 then () else + + try + type_changed := true; + match (t1.desc, t2.desc) with + (Tvar, Tconstr _) when deep_occur t1 t2 -> + unify2 env t1 t2 + | (Tconstr _, Tvar) when deep_occur t2 t1 -> + unify2 env t1 t2 + | (Tvar, _) -> + occur env t1 t2; occur_univar env t2; + update_level env t1.level t2; + link_type t1 t2 + | (_, Tvar) -> + occur env t2 t1; occur_univar env t1; + update_level env t2.level t1; + link_type t2 t1 + | (Tunivar, Tunivar) -> + unify_univar t1 t2 !univar_pairs; + update_level env t1.level t2; + link_type t1 t2 + | (Tconstr (p1, [], a1), Tconstr (p2, [], a2)) + when Path.same p1 p2 + (* This optimization assumes that t1 does not expand to t2 + (and conversely), so we fall back to the general case + when any of the types has a cached expansion. *) + && not (has_cached_expansion p1 !a1 + || has_cached_expansion p2 !a2) -> + update_level env t1.level t2; + link_type t1 t2 + | _ -> + unify2 env t1 t2 + with Unify trace -> + raise (Unify ((t1, t2)::trace)) + +and unify2 env t1 t2 = + (* Second step: expansion of abbreviations *) + let rec expand_both t1'' t2'' = + let t1' = expand_head_unif env t1 in + let t2' = expand_head_unif env t2 in + (* Expansion may have changed the representative of the types... *) + if t1' == t1'' && t2' == t2'' then (t1',t2') else + expand_both t1' t2' + in + let t1', t2' = expand_both t1 t2 in + if t1' == t2' then () else + + let t1 = repr t1 and t2 = repr t2 in + if (t1 == t1') || (t2 != t2') then + unify3 env t1 t1' t2 t2' + else + try unify3 env t2 t2' t1 t1' with Unify trace -> + raise (Unify (List.map (fun (x, y) -> (y, x)) trace)) + +and unify3 env t1 t1' t2 t2' = + (* Third step: truly unification *) + (* Assumes either [t1 == t1'] or [t2 != t2'] *) + let d1 = t1'.desc and d2 = t2'.desc in + + let create_recursion = (t2 != t2') && (deep_occur t1' t2) in + occur env t1' t2; + update_level env t1'.level t2; + link_type t1' t2; + + try + begin match (d1, d2) with + (Tvar, _) -> + occur_univar env t2 + | (_, Tvar) -> + let td1 = newgenty d1 in + occur env t2' td1; + occur_univar env td1; + if t1 == t1' then begin + (* The variable must be instantiated... *) + let ty = newty2 t1'.level d1 in + update_level env t2'.level ty; + link_type t2' ty + end else begin + log_type t1'; + t1'.desc <- d1; + update_level env t2'.level t1; + link_type t2' t1 + end + | (Tarrow (l1, t1, u1, c1), Tarrow (l2, t2, u2, c2)) when l1 = l2 + || !Clflags.classic && not (is_optional l1 || is_optional l2) -> + unify env t1 t2; unify env u1 u2; + begin match commu_repr c1, commu_repr c2 with + Clink r, c2 -> set_commu r c2 + | c1, Clink r -> set_commu r c1 + | _ -> () + end + | (Ttuple tl1, Ttuple tl2) -> + unify_list env tl1 tl2 + | (Tconstr (p1, tl1, _), Tconstr (p2, tl2, _)) when Path.same p1 p2 -> + unify_list env tl1 tl2 + | (Tobject (fi1, nm1), Tobject (fi2, _)) -> + unify_fields env fi1 fi2; + (* Type [t2'] may have been instantiated by [unify_fields] *) + (* XXX One should do some kind of unification... *) + begin match (repr t2').desc with + Tobject (_, {contents = Some (_, va::_)}) + when let va = repr va in List.mem va.desc [Tvar; Tunivar; Tnil] -> + () + | Tobject (_, nm2) -> + set_name nm2 !nm1 + | _ -> + () + end + | (Tvariant row1, Tvariant row2) -> + unify_row env row1 row2 + | (Tfield _, Tfield _) -> (* Actually unused *) + unify_fields env t1' t2' + | (Tfield(f,kind,_,rem), Tnil) | (Tnil, Tfield(f,kind,_,rem)) -> + begin match field_kind_repr kind with + Fvar r when f <> dummy_method -> set_kind r Fabsent + | _ -> raise (Unify []) + end + | (Tnil, Tnil) -> + () + | (Tpoly (t1, []), Tpoly (t2, [])) -> + unify env t1 t2 + | (Tpoly (t1, tl1), Tpoly (t2, tl2)) -> + enter_poly env univar_pairs t1 tl1 t2 tl2 (unify env) + | (_, _) -> + raise (Unify []) + end; + +(* XXX Commentaires + changer "create_recursion" *) + if create_recursion then begin + match t2.desc with + Tconstr (p, tl, abbrev) -> + forget_abbrev abbrev p; + let t2'' = expand_head_unif env t2 in + if not (closed_parameterized_type tl t2'') then + link_type (repr t2) (repr t2') + | _ -> + () (* t2 has already been expanded by update_level *) + end + +(* + (* + Can only be done afterwards, once the row variable has + (possibly) been instantiated. + *) + if t1 != t1' (* && t2 != t2' *) then begin + match (t1.desc, t2.desc) with + (Tconstr (p, ty::_, _), _) + when ((repr ty).desc <> Tvar) + && weak_abbrev p + && not (deep_occur t1 t2) -> + update_level env t1.level t2; + link_type t1 t2 + | (_, Tconstr (p, ty::_, _)) + when ((repr ty).desc <> Tvar) + && weak_abbrev p + && not (deep_occur t2 t1) -> + update_level env t2.level t1; + link_type t2 t1; + link_type t1' t2' + | _ -> + () + end +*) + with Unify trace -> + t1'.desc <- d1; + raise (Unify trace) + +and unify_list env tl1 tl2 = + if List.length tl1 <> List.length tl2 then + raise (Unify []); + List.iter2 (unify env) tl1 tl2 + +and unify_fields env ty1 ty2 = (* Optimization *) + let (fields1, rest1) = flatten_fields ty1 + and (fields2, rest2) = flatten_fields ty2 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + let l1 = (repr ty1).level and l2 = (repr ty2).level in + let va = + if miss1 = [] then rest2 + else if miss2 = [] then rest1 + else newty2 (min l1 l2) Tvar + in + let d1 = rest1.desc and d2 = rest2.desc in + try + unify env (build_fields l1 miss1 va) rest2; + unify env rest1 (build_fields l2 miss2 va); + List.iter + (fun (n, k1, t1, k2, t2) -> + unify_kind k1 k2; + try unify env t1 t2 with Unify trace -> + raise (Unify ((newty (Tfield(n, k1, t1, va)), + newty (Tfield(n, k2, t2, va)))::trace))) + pairs + with exn -> + log_type rest1; rest1.desc <- d1; + log_type rest2; rest2.desc <- d2; + raise exn + +and unify_kind k1 k2 = + let k1 = field_kind_repr k1 in + let k2 = field_kind_repr k2 in + if k1 == k2 then () else + match k1, k2 with + (Fvar r, (Fvar _ | Fpresent)) -> set_kind r k2 + | (Fpresent, Fvar r) -> set_kind r k1 + | (Fpresent, Fpresent) -> () + | _ -> assert false + +and unify_pairs env tpl = + List.iter (fun (t1, t2) -> unify env t1 t2) tpl + +and unify_row env row1 row2 = + let row1 = row_repr row1 and row2 = row_repr row2 in + let rm1 = row_more row1 and rm2 = row_more row2 in + if rm1 == rm2 then () else + let r1, r2, pairs = merge_row_fields row1.row_fields row2.row_fields in + if r1 <> [] && r2 <> [] then begin + let ht = Hashtbl.create (List.length r1) in + List.iter (fun (l,_) -> Hashtbl.add ht (hash_variant l) l) r1; + List.iter + (fun (l,_) -> + try raise (Tags(l, Hashtbl.find ht (hash_variant l))) + with Not_found -> ()) + r2 + end; + let more = + if row1.row_fixed then rm1 else + if row2.row_fixed then rm2 else + newgenvar () + in update_level env (min rm1.level rm2.level) more; + let fixed = row1.row_fixed || row2.row_fixed + and closed = row1.row_closed || row2.row_closed in + let keep switch = + List.for_all + (fun (_,f1,f2) -> + let f1, f2 = switch f1 f2 in + row_field_repr f1 = Rabsent || row_field_repr f2 <> Rabsent) + pairs + in + let empty fields = + List.for_all (fun (_,f) -> row_field_repr f = Rabsent) fields in + (* Check whether we are going to build an empty type *) + if closed && (empty r1 || row2.row_closed) && (empty r2 || row1.row_closed) + && List.for_all + (fun (_,f1,f2) -> + row_field_repr f1 = Rabsent || row_field_repr f2 = Rabsent) + pairs + then raise (Unify [mkvariant [] true, mkvariant [] true]); + let name = + if row1.row_name <> None && (row1.row_closed || empty r2) && + (not row2.row_closed || keep (fun f1 f2 -> f1, f2) && empty r1) + then row1.row_name + else if row2.row_name <> None && (row2.row_closed || empty r1) && + (not row1.row_closed || keep (fun f1 f2 -> f2, f1) && empty r2) + then row2.row_name + else None + in + let row0 = {row_fields = []; row_more = more; row_bound = (); + row_closed = closed; row_fixed = fixed; row_name = name} in + let set_more row rest = + let rest = + if closed then + filter_row_fields row.row_closed rest + else rest in + if rest <> [] && (row.row_closed || row.row_fixed) + || closed && row.row_fixed && not row.row_closed then begin + let t1 = mkvariant [] true and t2 = mkvariant rest false in + raise (Unify [if row == row1 then (t1,t2) else (t2,t1)]) + end; + let rm = row_more row in + if row.row_fixed then + if row0.row_more == rm then () else + if rm.desc = Tvar then link_type rm row0.row_more else + unify env rm row0.row_more + else + let ty = newty2 generic_level (Tvariant {row0 with row_fields = rest}) in + update_level env rm.level ty; + link_type rm ty + in + let md1 = rm1.desc and md2 = rm2.desc in + begin try + set_more row2 r1; + set_more row1 r2; + List.iter + (fun (l,f1,f2) -> + try unify_row_field env row1.row_fixed row2.row_fixed l f1 f2 + with Unify trace -> + raise (Unify ((mkvariant [l,f1] true, + mkvariant [l,f2] true) :: trace))) + pairs; + with exn -> + log_type rm1; rm1.desc <- md1; log_type rm2; rm2.desc <- md2; raise exn + end + +and unify_row_field env fixed1 fixed2 l f1 f2 = + let f1 = row_field_repr f1 and f2 = row_field_repr f2 in + if f1 == f2 then () else + match f1, f2 with + Rpresent(Some t1), Rpresent(Some t2) -> unify env t1 t2 + | Rpresent None, Rpresent None -> () + | Reither(c1, tl1, m1, e1), Reither(c2, tl2, m2, e2) -> + if e1 == e2 then () else + let redo = + (m1 || m2 || + !rigid_variants && (List.length tl1 = 1 || List.length tl2 = 1)) && + begin match tl1 @ tl2 with [] -> false + | t1 :: tl -> + if c1 || c2 then raise (Unify []); + List.iter (unify env t1) tl; + !e1 <> None || !e2 <> None + end in + if redo then unify_row_field env fixed1 fixed2 l f1 f2 else + let tl1 = List.map repr tl1 and tl2 = List.map repr tl2 in + let rec remq tl = function [] -> [] + | ty :: tl' -> + if List.memq ty tl then remq tl tl' else ty :: remq tl tl' + in + let tl2' = remq tl2 tl1 and tl1' = remq tl1 tl2 in + let e = ref None in + let f1' = Reither(c1 || c2, tl1', m1 || m2, e) + and f2' = Reither(c1 || c2, tl2', m1 || m2, e) in + set_row_field e1 f1'; set_row_field e2 f2'; + | Reither(_, _, false, e1), Rabsent -> set_row_field e1 f2 + | Rabsent, Reither(_, _, false, e2) -> set_row_field e2 f1 + | Rabsent, Rabsent -> () + | Reither(false, tl, _, e1), Rpresent(Some t2) when not fixed1 -> + set_row_field e1 f2; + (try List.iter (fun t1 -> unify env t1 t2) tl + with exn -> e1 := None; raise exn) + | Rpresent(Some t1), Reither(false, tl, _, e2) when not fixed2 -> + set_row_field e2 f1; + (try List.iter (unify env t1) tl + with exn -> e2 := None; raise exn) + | Reither(true, [], _, e1), Rpresent None when not fixed1 -> + set_row_field e1 f2 + | Rpresent None, Reither(true, [], _, e2) when not fixed2 -> + set_row_field e2 f1 + | _ -> raise (Unify []) + + +let unify env ty1 ty2 = + try + unify env ty1 ty2 + with Unify trace -> + raise (Unify (expand_trace env trace)) + +let unify_var env t1 t2 = + let t1 = repr t1 and t2 = repr t2 in + if t1 == t2 then () else + match t1.desc with + Tvar -> + begin try + occur env t1 t2; + update_level env t1.level t2; + link_type t1 t2 + with Unify trace -> + raise (Unify (expand_trace env ((t1,t2)::trace))) + end + | _ -> + unify env t1 t2 + +let _ = unify' := unify_var + +let unify_pairs env ty1 ty2 pairs = + univar_pairs := pairs; + unify env ty1 ty2 + +let unify env ty1 ty2 = + univar_pairs := []; + unify env ty1 ty2 + + +(**** Special cases of unification ****) + +(* + Unify [t] and [l:'a -> 'b]. Return ['a] and ['b]. + In label mode, label mismatch is accepted when + (1) the requested label is "" + (2) the original label is not optional +*) +let rec filter_arrow env t l = + let t = expand_head_unif env t in + match t.desc with + Tvar -> + let t1 = newvar () and t2 = newvar () in + let t' = newty (Tarrow (l, t1, t2, Cok)) in + update_level env t.level t'; + link_type t t'; + (t1, t2) + | Tarrow(l', t1, t2, _) + when l = l' || !Clflags.classic && l = "" && not (is_optional l') -> + (t1, t2) + | _ -> + raise (Unify []) + +(* Used by [filter_method]. *) +let rec filter_method_field env name priv ty = + let ty = repr ty in + match ty.desc with + Tvar -> + let level = ty.level in + let ty1 = newvar2 level and ty2 = newvar2 level in + let ty' = newty2 level (Tfield (name, + begin match priv with + Private -> Fvar (ref None) + | Public -> Fpresent + end, + ty1, ty2)) + in + link_type ty ty'; + ty1 + | Tfield(n, kind, ty1, ty2) -> + let kind = field_kind_repr kind in + if (n = name) && (kind <> Fabsent) then begin + if priv = Public then + unify_kind kind Fpresent; + ty1 + end else + filter_method_field env name priv ty2 + | _ -> + raise (Unify []) + +(* Unify [ty] and [< name : 'a; .. >]. Return ['a]. *) +let rec filter_method env name priv ty = + let ty = expand_head_unif env ty in + match ty.desc with + Tvar -> + let ty1 = newvar () in + let ty' = newobj ty1 in + update_level env ty.level ty'; + link_type ty ty'; + filter_method_field env name priv ty1 + | Tobject(f, _) -> + filter_method_field env name priv f + | _ -> + raise (Unify []) + +let check_filter_method env name priv ty = + ignore(filter_method env name priv ty) + +let filter_self_method env lab priv meths ty = + let ty' = filter_method env lab priv ty in + try + Meths.find lab !meths + with Not_found -> + let pair = (Ident.create lab, ty') in + meths := Meths.add lab pair !meths; + pair + + + (***********************************) + (* Matching between type schemes *) + (***********************************) + +(* + Update the level of [ty]. First check that the levels of generic + variables from the subject are not lowered. +*) +let moregen_occur env level ty = + let rec occur ty = + let ty = repr ty in + if ty.level > level then begin + if ty.desc = Tvar && ty.level >= generic_level - 1 then raise Occur; + ty.level <- pivot_level - ty.level; + match ty.desc with + Tvariant row when static_row row -> + iter_row occur row + | _ -> + iter_type_expr occur ty + end + in + begin try + occur ty; unmark_type ty + with Occur -> + unmark_type ty; raise (Unify []) + end; + (* also check for free univars *) + occur_univar env ty; + update_level env level ty + +let may_instantiate inst_nongen t1 = + if inst_nongen then t1.level <> generic_level - 1 + else t1.level = generic_level + +let rec moregen inst_nongen type_pairs env t1 t2 = + if t1 == t2 then () else + let t1 = repr t1 in + let t2 = repr t2 in + if t1 == t2 then () else + + try + match (t1.desc, t2.desc) with + (Tunivar, Tunivar) -> + unify_univar t1 t2 !univar_pairs + | (Tvar, _) when may_instantiate inst_nongen t1 -> + moregen_occur env t1.level t2; + occur env t1 t2; + link_type t1 t2 + | (Tconstr (p1, [], _), Tconstr (p2, [], _)) when Path.same p1 p2 -> + () + | _ -> + let t1' = expand_head_unif env t1 in + let t2' = expand_head_unif env t2 in + (* Expansion may have changed the representative of the types... *) + let t1' = repr t1' and t2' = repr t2' in + if t1' == t2' then () else + begin try + TypePairs.find type_pairs (t1', t2') + with Not_found -> + TypePairs.add type_pairs (t1', t2') (); + match (t1'.desc, t2'.desc) with + (Tvar, _) when may_instantiate inst_nongen t1 -> + moregen_occur env t1'.level t2; + link_type t1' t2 + | (Tarrow (l1, t1, u1, _), Tarrow (l2, t2, u2, _)) when l1 = l2 + || !Clflags.classic && not (is_optional l1 || is_optional l2) -> + moregen inst_nongen type_pairs env t1 t2; + moregen inst_nongen type_pairs env u1 u2 + | (Ttuple tl1, Ttuple tl2) -> + moregen_list inst_nongen type_pairs env tl1 tl2 + | (Tconstr (p1, tl1, _), Tconstr (p2, tl2, _)) + when Path.same p1 p2 -> + moregen_list inst_nongen type_pairs env tl1 tl2 + | (Tvariant row1, Tvariant row2) -> + moregen_row inst_nongen type_pairs env row1 row2 + | (Tobject (fi1, nm1), Tobject (fi2, nm2)) -> + moregen_fields inst_nongen type_pairs env fi1 fi2 + | (Tfield _, Tfield _) -> (* Actually unused *) + moregen_fields inst_nongen type_pairs env t1' t2' + | (Tnil, Tnil) -> + () + | (Tpoly (t1, []), Tpoly (t2, [])) -> + moregen inst_nongen type_pairs env t1 t2 + | (Tpoly (t1, tl1), Tpoly (t2, tl2)) -> + enter_poly env univar_pairs t1 tl1 t2 tl2 + (moregen inst_nongen type_pairs env) + | (_, _) -> + raise (Unify []) + end + with Unify trace -> + raise (Unify ((t1, t2)::trace)) + +and moregen_list inst_nongen type_pairs env tl1 tl2 = + if List.length tl1 <> List.length tl2 then + raise (Unify []); + List.iter2 (moregen inst_nongen type_pairs env) tl1 tl2 + +and moregen_fields inst_nongen type_pairs env ty1 ty2 = + let (fields1, rest1) = flatten_fields ty1 + and (fields2, rest2) = flatten_fields ty2 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + if miss1 <> [] then raise (Unify []); + moregen inst_nongen type_pairs env rest1 + (build_fields (repr ty2).level miss2 rest2); + List.iter + (fun (n, k1, t1, k2, t2) -> + moregen_kind k1 k2; + try moregen inst_nongen type_pairs env t1 t2 with Unify trace -> + raise (Unify ((newty (Tfield(n, k1, t1, rest2)), + newty (Tfield(n, k2, t2, rest2)))::trace))) + pairs + +and moregen_kind k1 k2 = + let k1 = field_kind_repr k1 in + let k2 = field_kind_repr k2 in + if k1 == k2 then () else + match k1, k2 with + (Fvar r, (Fvar _ | Fpresent)) -> set_kind r k2 + | (Fpresent, Fpresent) -> () + | _ -> raise (Unify []) + +and moregen_row inst_nongen type_pairs env row1 row2 = + let row1 = row_repr row1 and row2 = row_repr row2 in + let rm1 = repr row1.row_more and rm2 = repr row2.row_more in + if rm1 == rm2 then () else + let may_inst = rm1.desc = Tvar && may_instantiate inst_nongen rm1 in + let r1, r2, pairs = merge_row_fields row1.row_fields row2.row_fields in + let r1, r2 = + if row2.row_closed then + filter_row_fields may_inst r1, filter_row_fields false r2 + else r1, r2 + in + if r1 <> [] || row1.row_closed && (not row2.row_closed || r2 <> []) + then raise (Unify []); + begin match rm1.desc, rm2.desc with + Tunivar, Tunivar -> + unify_univar rm1 rm2 !univar_pairs + | Tunivar, _ | _, Tunivar -> + raise (Unify []) + | _ when static_row row1 -> () + | _ when may_inst -> + if not (static_row row2) then moregen_occur env rm1.level rm2; + let ext = + if r2 = [] then rm2 else + let row_ext = {row2 with row_fields = r2} in + iter_row (moregen_occur env rm1.level) row_ext; + newty2 rm1.level (Tvariant row_ext) + in + link_type rm1 ext + | Tconstr _, Tconstr _ -> + moregen inst_nongen type_pairs env rm1 rm2 + | _ -> raise (Unify []) + end; + List.iter + (fun (l,f1,f2) -> + let f1 = row_field_repr f1 and f2 = row_field_repr f2 in + if f1 == f2 then () else + match f1, f2 with + Rpresent(Some t1), Rpresent(Some t2) -> + moregen inst_nongen type_pairs env t1 t2 + | Rpresent None, Rpresent None -> () + | Reither(false, tl1, _, e1), Rpresent(Some t2) when may_inst -> + set_row_field e1 f2; + List.iter (fun t1 -> moregen inst_nongen type_pairs env t1 t2) tl1 + | Reither(c1, tl1, _, e1), Reither(c2, tl2, m2, e2) -> + if e1 != e2 then begin + if c1 && not c2 then raise(Unify []); + set_row_field e1 (Reither (c2, [], m2, e2)); + if List.length tl1 = List.length tl2 then + List.iter2 (moregen inst_nongen type_pairs env) tl1 tl2 + else match tl2 with + t2 :: _ -> + List.iter (fun t1 -> moregen inst_nongen type_pairs env t1 t2) + tl1 + | [] -> + if tl1 <> [] then raise (Unify []) + end + | Reither(true, [], _, e1), Rpresent None when may_inst -> + set_row_field e1 f2 + | Reither(_, _, _, e1), Rabsent when may_inst -> + set_row_field e1 f2 + | Rabsent, Rabsent -> () + | _ -> raise (Unify [])) + pairs + +(* Must empty univar_pairs first *) +let moregen inst_nongen type_pairs env patt subj = + univar_pairs := []; + moregen inst_nongen type_pairs env patt subj + +(* + Non-generic variable can be instanciated only if [inst_nongen] is + true. So, [inst_nongen] should be set to false if the subject might + contain non-generic variables (and we do not want them to be + instanciated). + Usually, the subject is given by the user, and the pattern + is unimportant. So, no need to propagate abbreviations. +*) +let moregeneral env inst_nongen pat_sch subj_sch = + let old_level = !current_level in + current_level := generic_level - 1; + (* + Generic variables are first duplicated with [instance]. So, + their levels are lowered to [generic_level - 1]. The subject is + then copied with [duplicate_type]. That way, its levels won't be + changed. + *) + let subj = duplicate_type (instance subj_sch) in + current_level := generic_level; + (* Duplicate generic variables *) + let patt = instance pat_sch in + let res = + try moregen inst_nongen (TypePairs.create 13) env patt subj; true with + Unify _ -> false + in + current_level := old_level; + res + + +(* Alternative approach: "rigidify" a type scheme, + and check validity after unification *) +(* Simpler, no? *) + +let rec rigidify_rec vars ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + ty.level <- pivot_level - ty.level; + match ty.desc with + | Tvar -> + if not (List.memq ty !vars) then vars := ty :: !vars + | Tvariant row -> + let row = row_repr row in + let more = repr row.row_more in + if more.desc = Tvar && not row.row_fixed then begin + let more' = newty2 more.level Tvar in + let row' = {row with row_fixed=true; row_fields=[]; row_more=more'} + in link_type more (newty2 ty.level (Tvariant row')) + end; + iter_row (rigidify_rec vars) row; + (* only consider the row variable if the variant is not static *) + if not (static_row row) then rigidify_rec vars (row_more row) + | _ -> + iter_type_expr (rigidify_rec vars) ty + end + +let rigidify ty = + let vars = ref [] in + rigidify_rec vars ty; + unmark_type ty; + !vars + +let all_distinct_vars env vars = + let tyl = ref [] in + List.for_all + (fun ty -> + let ty = expand_head env ty in + if List.memq ty !tyl then false else + (tyl := ty :: !tyl; ty.desc = Tvar)) + vars + +let matches env ty ty' = + let snap = snapshot () in + let vars = rigidify ty in + cleanup_abbrev (); + let ok = + try unify env ty ty'; all_distinct_vars env vars + with Unify _ -> false + in + backtrack snap; + ok + + + (*********************************************) + (* Equivalence between parameterized types *) + (*********************************************) + +let expand_head_rigid env ty = + let old = !rigid_variants in + rigid_variants := true; + let ty' = expand_head_unif env ty in + rigid_variants := old; ty' + +let normalize_subst subst = + if List.exists + (function {desc=Tlink _}, _ | _, {desc=Tlink _} -> true | _ -> false) + !subst + then subst := List.map (fun (t1,t2) -> repr t1, repr t2) !subst + +let rec eqtype rename type_pairs subst env t1 t2 = + if t1 == t2 then () else + let t1 = repr t1 in + let t2 = repr t2 in + if t1 == t2 then () else + + try + match (t1.desc, t2.desc) with + (Tvar, Tvar) when rename -> + begin try + normalize_subst subst; + if List.assq t1 !subst != t2 then raise (Unify []) + with Not_found -> + subst := (t1, t2) :: !subst + end + | (Tconstr (p1, [], _), Tconstr (p2, [], _)) when Path.same p1 p2 -> + () + | _ -> + let t1' = expand_head_rigid env t1 in + let t2' = expand_head_rigid env t2 in + (* Expansion may have changed the representative of the types... *) + let t1' = repr t1' and t2' = repr t2' in + if t1' == t2' then () else + begin try + TypePairs.find type_pairs (t1', t2') + with Not_found -> + TypePairs.add type_pairs (t1', t2') (); + match (t1'.desc, t2'.desc) with + (Tvar, Tvar) when rename -> + begin try + normalize_subst subst; + if List.assq t1' !subst != t2' then raise (Unify []) + with Not_found -> + subst := (t1', t2') :: !subst + end + | (Tarrow (l1, t1, u1, _), Tarrow (l2, t2, u2, _)) when l1 = l2 + || !Clflags.classic && not (is_optional l1 || is_optional l2) -> + eqtype rename type_pairs subst env t1 t2; + eqtype rename type_pairs subst env u1 u2; + | (Ttuple tl1, Ttuple tl2) -> + eqtype_list rename type_pairs subst env tl1 tl2 + | (Tconstr (p1, tl1, _), Tconstr (p2, tl2, _)) + when Path.same p1 p2 -> + eqtype_list rename type_pairs subst env tl1 tl2 + | (Tvariant row1, Tvariant row2) -> + eqtype_row rename type_pairs subst env row1 row2 + | (Tobject (fi1, nm1), Tobject (fi2, nm2)) -> + eqtype_fields rename type_pairs subst env fi1 fi2 + | (Tfield _, Tfield _) -> (* Actually unused *) + eqtype_fields rename type_pairs subst env t1' t2' + | (Tnil, Tnil) -> + () + | (Tpoly (t1, []), Tpoly (t2, [])) -> + eqtype rename type_pairs subst env t1 t2 + | (Tpoly (t1, tl1), Tpoly (t2, tl2)) -> + enter_poly env univar_pairs t1 tl1 t2 tl2 + (eqtype rename type_pairs subst env) + | (Tunivar, Tunivar) -> + unify_univar t1' t2' !univar_pairs + | (_, _) -> + raise (Unify []) + end + with Unify trace -> + raise (Unify ((t1, t2)::trace)) + +and eqtype_list rename type_pairs subst env tl1 tl2 = + if List.length tl1 <> List.length tl2 then + raise (Unify []); + List.iter2 (eqtype rename type_pairs subst env) tl1 tl2 + +and eqtype_fields rename type_pairs subst env ty1 ty2 = + let (fields2, rest2) = flatten_fields ty2 in + (* Try expansion, needed when called from Includecore.type_manifest *) + match expand_head_rigid env rest2 with + {desc=Tobject(ty2,_)} -> eqtype_fields rename type_pairs subst env ty1 ty2 + | _ -> + let (fields1, rest1) = flatten_fields ty1 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + eqtype rename type_pairs subst env rest1 rest2; + if (miss1 <> []) || (miss2 <> []) then raise (Unify []); + List.iter + (function (n, k1, t1, k2, t2) -> + eqtype_kind k1 k2; + try eqtype rename type_pairs subst env t1 t2 with Unify trace -> + raise (Unify ((newty (Tfield(n, k1, t1, rest2)), + newty (Tfield(n, k2, t2, rest2)))::trace))) + pairs + +and eqtype_kind k1 k2 = + let k1 = field_kind_repr k1 in + let k2 = field_kind_repr k2 in + match k1, k2 with + (Fvar _, Fvar _) + | (Fpresent, Fpresent) -> () + | _ -> raise (Unify []) + +and eqtype_row rename type_pairs subst env row1 row2 = + (* Try expansion, needed when called from Includecore.type_manifest *) + match expand_head_rigid env (row_more row2) with + {desc=Tvariant row2} -> eqtype_row rename type_pairs subst env row1 row2 + | _ -> + let row1 = row_repr row1 and row2 = row_repr row2 in + let r1, r2, pairs = merge_row_fields row1.row_fields row2.row_fields in + if row1.row_closed <> row2.row_closed + || not row1.row_closed && (r1 <> [] || r2 <> []) + || filter_row_fields false (r1 @ r2) <> [] + then raise (Unify []); + if not (static_row row1) then + eqtype rename type_pairs subst env row1.row_more row2.row_more; + List.iter + (fun (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent(Some t1), Rpresent(Some t2) -> + eqtype rename type_pairs subst env t1 t2 + | Reither(true, [], _, _), Reither(true, [], _, _) -> + () + | Reither(false, t1::tl1, _, _), Reither(false, t2::tl2, _, _) -> + eqtype rename type_pairs subst env t1 t2; + if List.length tl1 = List.length tl2 then + (* if same length allow different types (meaning?) *) + List.iter2 (eqtype rename type_pairs subst env) tl1 tl2 + else begin + (* otherwise everything must be equal *) + List.iter (eqtype rename type_pairs subst env t1) tl2; + List.iter (fun t1 -> eqtype rename type_pairs subst env t1 t2) tl1 + end + | Rpresent None, Rpresent None -> () + | Rabsent, Rabsent -> () + | _ -> raise (Unify [])) + pairs + +(* Two modes: with or without renaming of variables *) +let equal env rename tyl1 tyl2 = + try + univar_pairs := []; + eqtype_list rename (TypePairs.create 11) (ref []) env tyl1 tyl2; true + with + Unify _ -> false + +(* Must empty univar_pairs first *) +let eqtype rename type_pairs subst env t1 t2 = + univar_pairs := []; + eqtype rename type_pairs subst env t1 t2 + + + (*************************) + (* Class type matching *) + (*************************) + + +type class_match_failure = + CM_Virtual_class + | CM_Parameter_arity_mismatch of int * int + | CM_Type_parameter_mismatch of (type_expr * type_expr) list + | CM_Class_type_mismatch of class_type * class_type + | CM_Parameter_mismatch of (type_expr * type_expr) list + | CM_Val_type_mismatch of string * (type_expr * type_expr) list + | CM_Meth_type_mismatch of string * (type_expr * type_expr) list + | CM_Non_mutable_value of string + | CM_Non_concrete_value of string + | CM_Missing_value of string + | CM_Missing_method of string + | CM_Hide_public of string + | CM_Hide_virtual of string * string + | CM_Public_method of string + | CM_Private_method of string + | CM_Virtual_method of string + +exception Failure of class_match_failure list + +let rec moregen_clty trace type_pairs env cty1 cty2 = + try + match cty1, cty2 with + Tcty_constr (_, _, cty1), _ -> + moregen_clty true type_pairs env cty1 cty2 + | _, Tcty_constr (_, _, cty2) -> + moregen_clty true type_pairs env cty1 cty2 + | Tcty_fun (l1, ty1, cty1'), Tcty_fun (l2, ty2, cty2') when l1 = l2 -> + begin try moregen true type_pairs env ty1 ty2 with Unify trace -> + raise (Failure [CM_Parameter_mismatch (expand_trace env trace)]) + end; + moregen_clty false type_pairs env cty1' cty2' + | Tcty_signature sign1, Tcty_signature sign2 -> + let ty1 = object_fields (repr sign1.cty_self) in + let ty2 = object_fields (repr sign2.cty_self) in + let (fields1, rest1) = flatten_fields ty1 + and (fields2, rest2) = flatten_fields ty2 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + List.iter + (fun (lab, k1, t1, k2, t2) -> + begin try moregen true type_pairs env t1 t2 with Unify trace -> + raise (Failure [CM_Meth_type_mismatch + (lab, expand_trace env trace)]) + end) + pairs; + Vars.iter + (fun lab (mut, v, ty) -> + let (mut', v', ty') = Vars.find lab sign1.cty_vars in + try moregen true type_pairs env ty' ty with Unify trace -> + raise (Failure [CM_Val_type_mismatch + (lab, expand_trace env trace)])) + sign2.cty_vars + | _ -> + raise (Failure []) + with + Failure error when trace -> + raise (Failure (CM_Class_type_mismatch (cty1, cty2)::error)) + +let match_class_types env pat_sch subj_sch = + let type_pairs = TypePairs.create 53 in + let old_level = !current_level in + current_level := generic_level - 1; + (* + Generic variables are first duplicated with [instance]. So, + their levels are lowered to [generic_level - 1]. The subject is + then copied with [duplicate_type]. That way, its levels won't be + changed. + *) + let (_, subj_inst) = instance_class [] subj_sch in + let subj = duplicate_class_type subj_inst in + current_level := generic_level; + (* Duplicate generic variables *) + let (_, patt) = instance_class [] pat_sch in + let res = + let sign1 = signature_of_class_type patt in + let sign2 = signature_of_class_type subj in + let t1 = repr sign1.cty_self in + let t2 = repr sign2.cty_self in + TypePairs.add type_pairs (t1, t2) (); + let (fields1, rest1) = flatten_fields (object_fields t1) + and (fields2, rest2) = flatten_fields (object_fields t2) in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + let error = + List.fold_right + (fun (lab, k, _) err -> + let err = + let k = field_kind_repr k in + begin match k with + Fvar r -> set_kind r Fabsent; err + | _ -> CM_Hide_public lab::err + end + in + if Concr.mem lab sign1.cty_concr then err + else CM_Hide_virtual ("method", lab) :: err) + miss1 [] + in + let missing_method = List.map (fun (m, _, _) -> m) miss2 in + let error = + (List.map (fun m -> CM_Missing_method m) missing_method) @ error + in + (* Always succeeds *) + moregen true type_pairs env rest1 rest2; + let error = + List.fold_right + (fun (lab, k1, t1, k2, t2) err -> + try moregen_kind k1 k2; err with + Unify _ -> CM_Public_method lab::err) + pairs error + in + let error = + Vars.fold + (fun lab (mut, vr, ty) err -> + try + let (mut', vr', ty') = Vars.find lab sign1.cty_vars in + if mut = Mutable && mut' <> Mutable then + CM_Non_mutable_value lab::err + else if vr = Concrete && vr' <> Concrete then + CM_Non_concrete_value lab::err + else + err + with Not_found -> + CM_Missing_value lab::err) + sign2.cty_vars error + in + let error = + Vars.fold + (fun lab (_,vr,_) err -> + if vr = Virtual && not (Vars.mem lab sign2.cty_vars) then + CM_Hide_virtual ("instance variable", lab) :: err + else err) + sign1.cty_vars error + in + let error = + List.fold_right + (fun e l -> + if List.mem e missing_method then l else CM_Virtual_method e::l) + (Concr.elements (Concr.diff sign2.cty_concr sign1.cty_concr)) + error + in + match error with + [] -> + begin try + moregen_clty true type_pairs env patt subj; + [] + with + Failure r -> r + end + | error -> + CM_Class_type_mismatch (patt, subj)::error + in + current_level := old_level; + res + +let rec equal_clty trace type_pairs subst env cty1 cty2 = + try + match cty1, cty2 with + Tcty_constr (_, _, cty1), Tcty_constr (_, _, cty2) -> + equal_clty true type_pairs subst env cty1 cty2 + | Tcty_constr (_, _, cty1), _ -> + equal_clty true type_pairs subst env cty1 cty2 + | _, Tcty_constr (_, _, cty2) -> + equal_clty true type_pairs subst env cty1 cty2 + | Tcty_fun (l1, ty1, cty1'), Tcty_fun (l2, ty2, cty2') when l1 = l2 -> + begin try eqtype true type_pairs subst env ty1 ty2 with Unify trace -> + raise (Failure [CM_Parameter_mismatch (expand_trace env trace)]) + end; + equal_clty false type_pairs subst env cty1' cty2' + | Tcty_signature sign1, Tcty_signature sign2 -> + let ty1 = object_fields (repr sign1.cty_self) in + let ty2 = object_fields (repr sign2.cty_self) in + let (fields1, rest1) = flatten_fields ty1 + and (fields2, rest2) = flatten_fields ty2 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + List.iter + (fun (lab, k1, t1, k2, t2) -> + begin try eqtype true type_pairs subst env t1 t2 with + Unify trace -> + raise (Failure [CM_Meth_type_mismatch + (lab, expand_trace env trace)]) + end) + pairs; + Vars.iter + (fun lab (_, _, ty) -> + let (_, _, ty') = Vars.find lab sign1.cty_vars in + try eqtype true type_pairs subst env ty ty' with Unify trace -> + raise (Failure [CM_Val_type_mismatch + (lab, expand_trace env trace)])) + sign2.cty_vars + | _ -> + raise + (Failure (if trace then [] + else [CM_Class_type_mismatch (cty1, cty2)])) + with + Failure error when trace -> + raise (Failure (CM_Class_type_mismatch (cty1, cty2)::error)) + +(* XXX On pourrait autoriser l'instantiation du type des parametres... *) +(* XXX Correct ? (variables de type dans parametres et corps de classe *) +let match_class_declarations env patt_params patt_type subj_params subj_type = + let type_pairs = TypePairs.create 53 in + let subst = ref [] in + let sign1 = signature_of_class_type patt_type in + let sign2 = signature_of_class_type subj_type in + let t1 = repr sign1.cty_self in + let t2 = repr sign2.cty_self in + TypePairs.add type_pairs (t1, t2) (); + let (fields1, rest1) = flatten_fields (object_fields t1) + and (fields2, rest2) = flatten_fields (object_fields t2) in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + let error = + List.fold_right + (fun (lab, k, _) err -> + let err = + let k = field_kind_repr k in + begin match k with + Fvar r -> err + | _ -> CM_Hide_public lab::err + end + in + if Concr.mem lab sign1.cty_concr then err + else CM_Hide_virtual ("method", lab) :: err) + miss1 [] + in + let missing_method = List.map (fun (m, _, _) -> m) miss2 in + let error = + (List.map (fun m -> CM_Missing_method m) missing_method) @ error + in + (* Always succeeds *) + eqtype true type_pairs subst env rest1 rest2; + let error = + List.fold_right + (fun (lab, k1, t1, k2, t2) err -> + let k1 = field_kind_repr k1 in + let k2 = field_kind_repr k2 in + match k1, k2 with + (Fvar _, Fvar _) + | (Fpresent, Fpresent) -> err + | (Fvar _, Fpresent) -> CM_Private_method lab::err + | (Fpresent, Fvar _) -> CM_Public_method lab::err + | _ -> assert false) + pairs error + in + let error = + Vars.fold + (fun lab (mut, vr, ty) err -> + try + let (mut', vr', ty') = Vars.find lab sign1.cty_vars in + if mut = Mutable && mut' <> Mutable then + CM_Non_mutable_value lab::err + else if vr = Concrete && vr' <> Concrete then + CM_Non_concrete_value lab::err + else + err + with Not_found -> + CM_Missing_value lab::err) + sign2.cty_vars error + in + let error = + Vars.fold + (fun lab (_,vr,_) err -> + if vr = Virtual && not (Vars.mem lab sign2.cty_vars) then + CM_Hide_virtual ("instance variable", lab) :: err + else err) + sign1.cty_vars error + in + let error = + List.fold_right + (fun e l -> + if List.mem e missing_method then l else CM_Virtual_method e::l) + (Concr.elements (Concr.diff sign2.cty_concr sign1.cty_concr)) + error + in + match error with + [] -> + begin try + let lp = List.length patt_params in + let ls = List.length subj_params in + if lp <> ls then + raise (Failure [CM_Parameter_arity_mismatch (lp, ls)]); + List.iter2 (fun p s -> + try eqtype true type_pairs subst env p s with Unify trace -> + raise (Failure [CM_Type_parameter_mismatch + (expand_trace env trace)])) + patt_params subj_params; + equal_clty false type_pairs subst env patt_type subj_type; + [] + with + Failure r -> r + end + | error -> + error + + + (***************) + (* Subtyping *) + (***************) + + +(**** Build a subtype of a given type. ****) + +(* build_subtype: + [visited] traces traversed object and variant types + [loops] is a mapping from variables to variables, to reproduce + positive loops in a class type + [posi] true if the current variance is positive + [level] number of expansions/enlargement allowed on this branch *) + +let warn = ref false (* whether double coercion might do better *) +let pred_expand n = if n mod 2 = 0 && n > 0 then pred n else n +let pred_enlarge n = if n mod 2 = 1 then pred n else n + +type change = Unchanged | Equiv | Changed +let collect l = List.fold_left (fun c1 (_, c2) -> max c1 c2) Unchanged l + +let rec filter_visited = function + [] -> [] + | {desc=Tobject _|Tvariant _} :: _ as l -> l + | _ :: l -> filter_visited l + +let memq_warn t visited = + if List.memq t visited then (warn := true; true) else false + +let rec lid_of_path sharp = function + Path.Pident id -> + Longident.Lident (sharp ^ Ident.name id) + | Path.Pdot (p1, s, _) -> + Longident.Ldot (lid_of_path "" p1, sharp ^ s) + | Path.Papply (p1, p2) -> + Longident.Lapply (lid_of_path sharp p1, lid_of_path "" p2) + +let find_cltype_for_path env p = + let path, cl_abbr = Env.lookup_type (lid_of_path "#" p) env in + match cl_abbr.type_manifest with + Some ty -> + begin match (repr ty).desc with + Tobject(_,{contents=Some(p',_)}) when Path.same p p' -> cl_abbr, ty + | _ -> raise Not_found + end + | None -> assert false + +let has_constr_row' env t = + has_constr_row (expand_abbrev env t) + +let rec build_subtype env visited loops posi level t = + let t = repr t in + match t.desc with + Tvar -> + if posi then + try + let t' = List.assq t loops in + warn := true; + (t', Equiv) + with Not_found -> + (t, Unchanged) + else + (t, Unchanged) + | Tarrow(l, t1, t2, _) -> + if memq_warn t visited then (t, Unchanged) else + let visited = t :: visited in + let (t1', c1) = build_subtype env visited loops (not posi) level t1 in + let (t2', c2) = build_subtype env visited loops posi level t2 in + let c = max c1 c2 in + if c > Unchanged then (newty (Tarrow(l, t1', t2', Cok)), c) + else (t, Unchanged) + | Ttuple tlist -> + if memq_warn t visited then (t, Unchanged) else + let visited = t :: visited in + let tlist' = + List.map (build_subtype env visited loops posi level) tlist + in + let c = collect tlist' in + if c > Unchanged then (newty (Ttuple (List.map fst tlist')), c) + else (t, Unchanged) + | Tconstr(p, tl, abbrev) + when level > 0 && generic_abbrev env p && safe_abbrev env t + && not (has_constr_row' env t) -> + let t' = repr (expand_abbrev env t) in + let level' = pred_expand level in + begin try match t'.desc with + Tobject _ when posi && not (opened_object t') -> + let cl_abbr, body = find_cltype_for_path env p in + let ty = + subst env !current_level Public abbrev None + cl_abbr.type_params tl body in + let ty = repr ty in + let ty1, tl1 = + match ty.desc with + Tobject(ty1,{contents=Some(p',tl1)}) when Path.same p p' -> + ty1, tl1 + | _ -> raise Not_found + in + (* Fix PR4505: do not set ty to Tvar when it appears in tl1, + as this occurence might break the occur check. + XXX not clear whether this correct anyway... *) + if List.exists (deep_occur ty) tl1 then raise Not_found; + ty.desc <- Tvar; + let t'' = newvar () in + let loops = (ty, t'') :: loops in + (* May discard [visited] as level is going down *) + let (ty1', c) = + build_subtype env [t'] loops posi (pred_enlarge level') ty1 in + assert (t''.desc = Tvar); + let nm = + if c > Equiv || deep_occur ty ty1' then None else Some(p,tl1) in + t''.desc <- Tobject (ty1', ref nm); + (try unify_var env ty t with Unify _ -> assert false); + (t'', Changed) + | _ -> raise Not_found + with Not_found -> + let (t'',c) = build_subtype env visited loops posi level' t' in + if c > Unchanged then (t'',c) + else (t, Unchanged) + end + | Tconstr(p, tl, abbrev) -> + (* Must check recursion on constructors, since we do not always + expand them *) + if memq_warn t visited then (t, Unchanged) else + let visited = t :: visited in + begin try + let decl = Env.find_type p env in + if level = 0 && generic_abbrev env p && safe_abbrev env t + && not (has_constr_row' env t) + then warn := true; + let tl' = + List.map2 + (fun (co,cn,_) t -> + if cn then + if co then (t, Unchanged) + else build_subtype env visited loops (not posi) level t + else + if co then build_subtype env visited loops posi level t + else (newvar(), Changed)) + decl.type_variance tl + in + let c = collect tl' in + if c > Unchanged then (newconstr p (List.map fst tl'), c) + else (t, Unchanged) + with Not_found -> + (t, Unchanged) + end + | Tvariant row -> + let row = row_repr row in + if memq_warn t visited || not (static_row row) then (t, Unchanged) else + let level' = pred_enlarge level in + let visited = + t :: if level' < level then [] else filter_visited visited in + let fields = filter_row_fields false row.row_fields in + let fields = + List.map + (fun (l,f as orig) -> match row_field_repr f with + Rpresent None -> + if posi then + (l, Reither(true, [], false, ref None)), Unchanged + else + orig, Unchanged + | Rpresent(Some t) -> + let (t', c) = build_subtype env visited loops posi level' t in + let f = + if posi && level > 0 + then Reither(false, [t'], false, ref None) + else Rpresent(Some t') + in (l, f), c + | _ -> assert false) + fields + in + let c = collect fields in + let row = + { row_fields = List.map fst fields; row_more = newvar(); + row_bound = (); row_closed = posi; row_fixed = false; + row_name = if c > Unchanged then None else row.row_name } + in + (newty (Tvariant row), Changed) + | Tobject (t1, _) -> + if memq_warn t visited || opened_object t1 then (t, Unchanged) else + let level' = pred_enlarge level in + let visited = + t :: if level' < level then [] else filter_visited visited in + let (t1', c) = build_subtype env visited loops posi level' t1 in + if c > Unchanged then (newty (Tobject (t1', ref None)), c) + else (t, Unchanged) + | Tfield(s, _, t1, t2) (* Always present *) -> + let (t1', c1) = build_subtype env visited loops posi level t1 in + let (t2', c2) = build_subtype env visited loops posi level t2 in + let c = max c1 c2 in + if c > Unchanged then (newty (Tfield(s, Fpresent, t1', t2')), c) + else (t, Unchanged) + | Tnil -> + if posi then + let v = newvar () in + (v, Changed) + else begin + warn := true; + (t, Unchanged) + end + | Tsubst _ | Tlink _ -> + assert false + | Tpoly(t1, tl) -> + let (t1', c) = build_subtype env visited loops posi level t1 in + if c > Unchanged then (newty (Tpoly(t1', tl)), c) + else (t, Unchanged) + | Tunivar -> + (t, Unchanged) + +let enlarge_type env ty = + warn := false; + (* [level = 4] allows 2 expansions involving objects/variants *) + let (ty', _) = build_subtype env [] [] true 4 ty in + (ty', !warn) + +(**** Check whether a type is a subtype of another type. ****) + +(* + During the traversal, a trace of visited types is maintained. It + is printed in case of error. + Constraints (pairs of types that must be equals) are accumulated + rather than being enforced straight. Indeed, the result would + otherwise depend on the order in which these constraints are + enforced. + A function enforcing these constraints is returned. That way, type + variables can be bound to their actual values before this function + is called (see Typecore). + Only well-defined abbreviations are expanded (hence the tests + [generic_abbrev ...]). +*) + +let subtypes = TypePairs.create 17 + +let subtype_error env trace = + raise (Subtype (expand_trace env (List.rev trace), [])) + +let private_abbrev env path = + try + let decl = Env.find_type path env in + decl.type_private = Private && decl.type_manifest <> None + with Not_found -> false + +let rec subtype_rec env trace t1 t2 cstrs = + let t1 = repr t1 in + let t2 = repr t2 in + if t1 == t2 then cstrs else + + begin try + TypePairs.find subtypes (t1, t2); + cstrs + with Not_found -> + TypePairs.add subtypes (t1, t2) (); + match (t1.desc, t2.desc) with + (Tvar, _) | (_, Tvar) -> + (trace, t1, t2, !univar_pairs)::cstrs + | (Tarrow(l1, t1, u1, _), Tarrow(l2, t2, u2, _)) when l1 = l2 + || !Clflags.classic && not (is_optional l1 || is_optional l2) -> + let cstrs = subtype_rec env ((t2, t1)::trace) t2 t1 cstrs in + subtype_rec env ((u1, u2)::trace) u1 u2 cstrs + | (Ttuple tl1, Ttuple tl2) -> + subtype_list env trace tl1 tl2 cstrs + | (Tconstr(p1, [], _), Tconstr(p2, [], _)) when Path.same p1 p2 -> + cstrs + | (Tconstr(p1, tl1, abbrev1), _) + when generic_abbrev env p1 && safe_abbrev env t1 -> + subtype_rec env trace (expand_abbrev env t1) t2 cstrs + | (_, Tconstr(p2, tl2, abbrev2)) + when generic_abbrev env p2 && safe_abbrev env t2 -> + subtype_rec env trace t1 (expand_abbrev env t2) cstrs + | (Tconstr(p1, tl1, _), Tconstr(p2, tl2, _)) when Path.same p1 p2 -> + begin try + let decl = Env.find_type p1 env in + List.fold_left2 + (fun cstrs (co, cn, _) (t1, t2) -> + if co then + if cn then + (trace, newty2 t1.level (Ttuple[t1]), + newty2 t2.level (Ttuple[t2]), !univar_pairs) :: cstrs + else subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + else + if cn then subtype_rec env ((t2, t1)::trace) t2 t1 cstrs + else cstrs) + cstrs decl.type_variance (List.combine tl1 tl2) + with Not_found -> + (trace, t1, t2, !univar_pairs)::cstrs + end + | (Tconstr(p1, tl1, _), _) when private_abbrev env p1 -> + subtype_rec env trace (expand_abbrev_opt env t1) t2 cstrs + | (Tobject (f1, _), Tobject (f2, _)) + when (object_row f1).desc = Tvar && (object_row f2).desc = Tvar -> + (* Same row variable implies same object. *) + (trace, t1, t2, !univar_pairs)::cstrs + | (Tobject (f1, _), Tobject (f2, _)) -> + subtype_fields env trace f1 f2 cstrs + | (Tvariant row1, Tvariant row2) -> + begin try + subtype_row env trace row1 row2 cstrs + with Exit -> + (trace, t1, t2, !univar_pairs)::cstrs + end + | (Tpoly (u1, []), Tpoly (u2, [])) -> + subtype_rec env trace u1 u2 cstrs + | (Tpoly (u1, tl1), Tpoly (u2, [])) -> + let _, u1' = instance_poly false tl1 u1 in + subtype_rec env trace u1' u2 cstrs + | (Tpoly (u1, tl1), Tpoly (u2,tl2)) -> + begin try + enter_poly env univar_pairs u1 tl1 u2 tl2 + (fun t1 t2 -> subtype_rec env trace t1 t2 cstrs) + with Unify _ -> + (trace, t1, t2, !univar_pairs)::cstrs + end + | (_, _) -> + (trace, t1, t2, !univar_pairs)::cstrs + end + +and subtype_list env trace tl1 tl2 cstrs = + if List.length tl1 <> List.length tl2 then + subtype_error env trace; + List.fold_left2 + (fun cstrs t1 t2 -> subtype_rec env ((t1, t2)::trace) t1 t2 cstrs) + cstrs tl1 tl2 + +and subtype_fields env trace ty1 ty2 cstrs = + (* Assume that either rest1 or rest2 is not Tvar *) + let (fields1, rest1) = flatten_fields ty1 in + let (fields2, rest2) = flatten_fields ty2 in + let (pairs, miss1, miss2) = associate_fields fields1 fields2 in + let cstrs = + if rest2.desc = Tnil then cstrs else + if miss1 = [] then + subtype_rec env ((rest1, rest2)::trace) rest1 rest2 cstrs + else + (trace, build_fields (repr ty1).level miss1 rest1, rest2, + !univar_pairs) :: cstrs + in + let cstrs = + if miss2 = [] then cstrs else + (trace, rest1, build_fields (repr ty2).level miss2 (newvar ()), + !univar_pairs) :: cstrs + in + List.fold_left + (fun cstrs (_, k1, t1, k2, t2) -> + (* Theses fields are always present *) + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs) + cstrs pairs + +and subtype_row env trace row1 row2 cstrs = + let row1 = row_repr row1 and row2 = row_repr row2 in + let r1, r2, pairs = + merge_row_fields row1.row_fields row2.row_fields in + let more1 = repr row1.row_more + and more2 = repr row2.row_more in + match more1.desc, more2.desc with + Tconstr(p1,_,_), Tconstr(p2,_,_) when Path.same p1 p2 -> + subtype_rec env ((more1,more2)::trace) more1 more2 cstrs + | (Tvar|Tconstr _), (Tvar|Tconstr _) + when row1.row_closed && r1 = [] -> + List.fold_left + (fun cstrs (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + (Rpresent None|Reither(true,_,_,_)), Rpresent None -> + cstrs + | Rpresent(Some t1), Rpresent(Some t2) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + | Reither(false, t1::_, _, _), Rpresent(Some t2) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + | Rabsent, _ -> cstrs + | _ -> raise Exit) + cstrs pairs + | Tunivar, Tunivar + when row1.row_closed = row2.row_closed && r1 = [] && r2 = [] -> + let cstrs = + subtype_rec env ((more1,more2)::trace) more1 more2 cstrs in + List.fold_left + (fun cstrs (_,f1,f2) -> + match row_field_repr f1, row_field_repr f2 with + Rpresent None, Rpresent None + | Reither(true,[],_,_), Reither(true,[],_,_) + | Rabsent, Rabsent -> + cstrs + | Rpresent(Some t1), Rpresent(Some t2) + | Reither(false,[t1],_,_), Reither(false,[t2],_,_) -> + subtype_rec env ((t1, t2)::trace) t1 t2 cstrs + | _ -> raise Exit) + cstrs pairs + | _ -> + raise Exit + +let subtype env ty1 ty2 = + TypePairs.clear subtypes; + univar_pairs := []; + (* Build constraint set. *) + let cstrs = subtype_rec env [(ty1, ty2)] ty1 ty2 [] in + TypePairs.clear subtypes; + (* Enforce constraints. *) + function () -> + List.iter + (function (trace0, t1, t2, pairs) -> + try unify_pairs env t1 t2 pairs with Unify trace -> + raise (Subtype (expand_trace env (List.rev trace0), + List.tl (List.tl trace)))) + (List.rev cstrs) + + (*******************) + (* Miscellaneous *) + (*******************) + +(* Utility for printing. The resulting type is not used in computation. *) +let rec unalias_object ty = + let ty = repr ty in + match ty.desc with + Tfield (s, k, t1, t2) -> + newty2 ty.level (Tfield (s, k, t1, unalias_object t2)) + | Tvar | Tnil -> + newty2 ty.level ty.desc + | Tunivar -> + ty + | Tconstr _ -> + newty2 ty.level Tvar + | _ -> + assert false + +let unalias ty = + let ty = repr ty in + match ty.desc with + Tvar | Tunivar -> + ty + | Tvariant row -> + let row = row_repr row in + let more = row.row_more in + newty2 ty.level + (Tvariant {row with row_more = newty2 more.level more.desc}) + | Tobject (ty, nm) -> + newty2 ty.level (Tobject (unalias_object ty, nm)) + | _ -> + newty2 ty.level ty.desc + +let unroll_abbrev id tl ty = + let ty = repr ty in + if (ty.desc = Tvar) || (List.exists (deep_occur ty) tl) then + ty + else + let ty' = newty2 ty.level ty.desc in + link_type ty (newty2 ty.level (Tconstr (Path.Pident id, tl, ref Mnil))); + ty' + +(* Return the arity (as for curried functions) of the given type. *) +let rec arity ty = + match (repr ty).desc with + Tarrow(_, t1, t2, _) -> 1 + arity t2 + | _ -> 0 + +(* Check whether an abbreviation expands to itself. *) +let cyclic_abbrev env id ty = + let rec check_cycle seen ty = + let ty = repr ty in + match ty.desc with + Tconstr (p, tl, abbrev) -> + p = Path.Pident id || List.memq ty seen || + begin try + check_cycle (ty :: seen) (expand_abbrev env ty) + with + Cannot_expand -> false + | Unify _ -> true + end + | _ -> + false + in check_cycle [] ty + +(* Normalize a type before printing, saving... *) +let rec normalize_type_rec env ty = + let ty = repr ty in + if ty.level >= lowest_level then begin + mark_type_node ty; + begin match ty.desc with + | Tvariant row -> + let row = row_repr row in + let fields = List.map + (fun (l,f0) -> + let f = row_field_repr f0 in l, + match f with Reither(b, ty::(_::_ as tyl), m, e) -> + let tyl' = + List.fold_left + (fun tyl ty -> + if List.exists (fun ty' -> equal env false [ty] [ty']) tyl + then tyl else ty::tyl) + [ty] tyl + in + if f != f0 || List.length tyl' < List.length tyl then + Reither(b, List.rev tyl', m, e) + else f + | _ -> f) + row.row_fields in + let fields = + List.sort (fun (p,_) (q,_) -> compare p q) + (List.filter (fun (_,fi) -> fi <> Rabsent) fields) in + log_type ty; + ty.desc <- Tvariant {row with row_fields = fields} + | Tobject (fi, nm) -> + begin match !nm with + | None -> () + | Some (n, v :: l) -> + let v' = repr v in + begin match v'.desc with + | Tvar|Tunivar -> + if v' != v then set_name nm (Some (n, v' :: l)) + | Tnil -> log_type ty; ty.desc <- Tconstr (n, l, ref Mnil) + | _ -> set_name nm None + end + | _ -> + fatal_error "Ctype.normalize_type_rec" + end; + let fi = repr fi in + if fi.level < lowest_level then () else + let fields, row = flatten_fields fi in + let fi' = build_fields fi.level fields row in + log_type ty; fi.desc <- fi'.desc + | _ -> () + end; + iter_type_expr (normalize_type_rec env) ty + end + +let normalize_type env ty = + normalize_type_rec env ty; + unmark_type ty + + + (*************************) + (* Remove dependencies *) + (*************************) + + +(* + Variables are left unchanged. Other type nodes are duplicated, with + levels set to generic level. + During copying, the description of a (non-variable) node is first + replaced by a link to a stub ([Tsubst (newgenvar ())]). + Once the copy is made, it replaces the stub. + After copying, the description of node, which was stored by + [save_desc], must be put back, using [cleanup_types]. +*) + +let rec nondep_type_rec env id ty = + let ty = repr ty in + match ty.desc with + Tvar | Tunivar -> ty + | Tsubst ty -> ty + | _ -> + let desc = ty.desc in + save_desc ty desc; + let ty' = newgenvar () in (* Stub *) + ty.desc <- Tsubst ty'; + ty'.desc <- + begin match desc with + | Tconstr(p, tl, abbrev) -> + if Path.isfree id p then + begin try + Tlink (nondep_type_rec env id + (expand_abbrev env (newty2 ty.level desc))) + (* + The [Tlink] is important. The expanded type may be a + variable, or may not be completely copied yet + (recursive type), so one cannot just take its + description. + *) + with Cannot_expand -> + raise Not_found + end + else + Tconstr(p, List.map (nondep_type_rec env id) tl, ref Mnil) + | Tobject (t1, name) -> + Tobject (nondep_type_rec env id t1, + ref (match !name with + None -> None + | Some (p, tl) -> + if Path.isfree id p then None + else Some (p, List.map (nondep_type_rec env id) tl))) + | Tvariant row -> + let row = row_repr row in + let more = repr row.row_more in + (* We must substitute in a subtle way *) + (* Tsubst denotes the variant itself, as the row var is unchanged *) + begin match more.desc with + Tsubst ty2 -> + (* This variant type has been already copied *) + ty.desc <- Tsubst ty2; (* avoid Tlink in the new type *) + Tlink ty2 + | _ -> + let static = static_row row in + (* Register new type first for recursion *) + save_desc more more.desc; + more.desc <- ty.desc; + let more' = if static then newgenvar () else more in + (* Return a new copy *) + let row = + copy_row (nondep_type_rec env id) true row true more' in + match row.row_name with + Some (p, tl) when Path.isfree id p -> + Tvariant {row with row_name = None} + | _ -> Tvariant row + end + | _ -> copy_type_desc (nondep_type_rec env id) desc + end; + ty' + +let nondep_type env id ty = + try + let ty' = nondep_type_rec env id ty in + cleanup_types (); + unmark_type ty'; + ty' + with Not_found -> + cleanup_types (); + raise Not_found + +(* Preserve sharing inside type declarations. *) +let nondep_type_decl env mid id is_covariant decl = + try + let params = List.map (nondep_type_rec env mid) decl.type_params in + let decl = + { type_params = params; + type_arity = decl.type_arity; + type_kind = + begin try + match decl.type_kind with + Type_abstract -> + Type_abstract + | Type_variant cstrs -> + Type_variant(List.map + (fun (c, tl) -> (c, List.map (nondep_type_rec env mid) tl)) + cstrs) + | Type_record(lbls, rep) -> + Type_record( + List.map + (fun (c, mut, t) -> (c, mut, nondep_type_rec env mid t)) + lbls, + rep) + with Not_found when is_covariant -> + Type_abstract + end; + type_manifest = + begin try + match decl.type_manifest with + None -> None + | Some ty -> + Some (unroll_abbrev id params (nondep_type_rec env mid ty)) + with Not_found when is_covariant -> + None + end; + type_private = decl.type_private; + type_variance = decl.type_variance; + } + in + cleanup_types (); + List.iter unmark_type decl.type_params; + begin match decl.type_kind with + Type_abstract -> () + | Type_variant cstrs -> + List.iter (fun (c, tl) -> List.iter unmark_type tl) cstrs + | Type_record(lbls, rep) -> + List.iter (fun (c, mut, t) -> unmark_type t) lbls + end; + begin match decl.type_manifest with + None -> () + | Some ty -> unmark_type ty + end; + decl + with Not_found -> + cleanup_types (); + raise Not_found + +(* Preserve sharing inside class types. *) +let nondep_class_signature env id sign = + { cty_self = nondep_type_rec env id sign.cty_self; + cty_vars = + Vars.map (function (m, v, t) -> (m, v, nondep_type_rec env id t)) + sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = + List.map (fun (p,tl) -> (p, List.map (nondep_type_rec env id) tl)) + sign.cty_inher } + +let rec nondep_class_type env id = + function + Tcty_constr (p, _, cty) when Path.isfree id p -> + nondep_class_type env id cty + | Tcty_constr (p, tyl, cty) -> + Tcty_constr (p, List.map (nondep_type_rec env id) tyl, + nondep_class_type env id cty) + | Tcty_signature sign -> + Tcty_signature (nondep_class_signature env id sign) + | Tcty_fun (l, ty, cty) -> + Tcty_fun (l, nondep_type_rec env id ty, nondep_class_type env id cty) + +let nondep_class_declaration env id decl = + assert (not (Path.isfree id decl.cty_path)); + let decl = + { cty_params = List.map (nondep_type_rec env id) decl.cty_params; + cty_variance = decl.cty_variance; + cty_type = nondep_class_type env id decl.cty_type; + cty_path = decl.cty_path; + cty_new = + begin match decl.cty_new with + None -> None + | Some ty -> Some (nondep_type_rec env id ty) + end } + in + cleanup_types (); + List.iter unmark_type decl.cty_params; + unmark_class_type decl.cty_type; + begin match decl.cty_new with + None -> () + | Some ty -> unmark_type ty + end; + decl + +let nondep_cltype_declaration env id decl = + assert (not (Path.isfree id decl.clty_path)); + let decl = + { clty_params = List.map (nondep_type_rec env id) decl.clty_params; + clty_variance = decl.clty_variance; + clty_type = nondep_class_type env id decl.clty_type; + clty_path = decl.clty_path } + in + cleanup_types (); + List.iter unmark_type decl.clty_params; + unmark_class_type decl.clty_type; + decl + +(* collapse conjonctive types in class parameters *) +let rec collapse_conj env visited ty = + let ty = repr ty in + if List.memq ty visited then () else + let visited = ty :: visited in + match ty.desc with + Tvariant row -> + let row = row_repr row in + List.iter + (fun (l,fi) -> + match row_field_repr fi with + Reither (c, t1::(_::_ as tl), m, e) -> + List.iter (unify env t1) tl; + set_row_field e (Reither (c, [t1], m, ref None)) + | _ -> + ()) + row.row_fields; + iter_row (collapse_conj env visited) row + | _ -> + iter_type_expr (collapse_conj env visited) ty + +let collapse_conj_params env params = + List.iter (collapse_conj env []) params diff --git a/typing/ctype.mli b/typing/ctype.mli new file mode 100644 index 0000000..b0eca94 --- /dev/null +++ b/typing/ctype.mli @@ -0,0 +1,244 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ctype.mli,v 1.56 2008-12-03 18:09:09 doligez Exp $ *) + +(* Operations on core types *) + +open Asttypes +open Types + +exception Unify of (type_expr * type_expr) list +exception Tags of label * label +exception Subtype of + (type_expr * type_expr) list * (type_expr * type_expr) list +exception Cannot_expand +exception Cannot_apply +exception Recursive_abbrev + +val init_def: int -> unit + (* Set the initial variable level *) +val begin_def: unit -> unit + (* Raise the variable level by one at the beginning of a definition. *) +val end_def: unit -> unit + (* Lower the variable level by one at the end of a definition *) +val begin_class_def: unit -> unit +val raise_nongen_level: unit -> unit +val reset_global_level: unit -> unit + (* Reset the global level before typing an expression *) +val increase_global_level: unit -> int +val restore_global_level: int -> unit + (* This pair of functions is only used in Typetexp *) + +val newty: type_desc -> type_expr +val newvar: unit -> type_expr + (* Return a fresh variable *) +val new_global_var: unit -> type_expr + (* Return a fresh variable, bound at toplevel + (as type variables ['a] in type constraints). *) +val newobj: type_expr -> type_expr +val newconstr: Path.t -> type_expr list -> type_expr +val none: type_expr + (* A dummy type expression *) + +val repr: type_expr -> type_expr + (* Return the canonical representative of a type. *) + +val dummy_method: label +val object_fields: type_expr -> type_expr +val flatten_fields: + type_expr -> (string * field_kind * type_expr) list * type_expr + (* Transform a field type into a list of pairs label-type *) + (* The fields are sorted *) +val associate_fields: + (string * field_kind * type_expr) list -> + (string * field_kind * type_expr) list -> + (string * field_kind * type_expr * field_kind * type_expr) list * + (string * field_kind * type_expr) list * + (string * field_kind * type_expr) list +val opened_object: type_expr -> bool +val close_object: type_expr -> unit +val row_variable: type_expr -> type_expr + (* Return the row variable of an open object type *) +val set_object_name: + Ident.t -> type_expr -> type_expr list -> type_expr -> unit +val remove_object_name: type_expr -> unit +val hide_private_methods: type_expr -> unit +val find_cltype_for_path: Env.t -> Path.t -> type_declaration * type_expr + +val sort_row_fields: (label * row_field) list -> (label * row_field) list +val merge_row_fields: + (label * row_field) list -> (label * row_field) list -> + (label * row_field) list * (label * row_field) list * + (label * row_field * row_field) list +val filter_row_fields: + bool -> (label * row_field) list -> (label * row_field) list + +val generalize: type_expr -> unit + (* Generalize in-place the given type *) +val iterative_generalization: int -> type_expr list -> type_expr list + (* Efficient repeated generalization of a type *) +val generalize_expansive: Env.t -> type_expr -> unit + (* Generalize the covariant part of a type, making + contravariant branches non-generalizable *) +val generalize_global: type_expr -> unit + (* Generalize the structure of a type, lowering variables + to !global_level *) +val generalize_structure: type_expr -> unit + (* Same, but variables are only lowered to !current_level *) +val generalize_spine: type_expr -> unit + (* Special function to generalize a method during inference *) +val correct_levels: type_expr -> type_expr + (* Returns a copy with decreasing levels *) +val limited_generalize: type_expr -> type_expr -> unit + (* Only generalize some part of the type + Make the remaining of the type non-generalizable *) + +val instance: type_expr -> type_expr + (* Take an instance of a type scheme *) +val instance_list: type_expr list -> type_expr list + (* Take an instance of a list of type schemes *) +val instance_constructor: + constructor_description -> type_expr list * type_expr + (* Same, for a constructor *) +val instance_parameterized_type: + type_expr list -> type_expr -> type_expr list * type_expr +val instance_parameterized_type_2: + type_expr list -> type_expr list -> type_expr -> + type_expr list * type_expr list * type_expr +val instance_class: + type_expr list -> class_type -> type_expr list * class_type +val instance_poly: + bool -> type_expr list -> type_expr -> type_expr list * type_expr + (* Take an instance of a type scheme containing free univars *) +val instance_label: + bool -> label_description -> type_expr list * type_expr * type_expr + (* Same, for a label *) +val apply: + Env.t -> type_expr list -> type_expr -> type_expr list -> type_expr + (* [apply [p1...pN] t [a1...aN]] match the arguments [ai] to + the parameters [pi] and returns the corresponding instance of + [t]. Exception [Cannot_apply] is raised in case of failure. *) + +val expand_head_once: Env.t -> type_expr -> type_expr +val expand_head: Env.t -> type_expr -> type_expr +val try_expand_once_opt: Env.t -> type_expr -> type_expr +val expand_head_opt: Env.t -> type_expr -> type_expr +(** The compiler's own version of [expand_head] necessary for type-based + optimisations. *) +val full_expand: Env.t -> type_expr -> type_expr + +val enforce_constraints: Env.t -> type_expr -> unit + +val unify: Env.t -> type_expr -> type_expr -> unit + (* Unify the two types given. Raise [Unify] if not possible. *) +val unify_var: Env.t -> type_expr -> type_expr -> unit + (* Same as [unify], but allow free univars when first type + is a variable. *) +val filter_arrow: Env.t -> type_expr -> label -> type_expr * type_expr + (* A special case of unification (with l:'a -> 'b). *) +val filter_method: Env.t -> string -> private_flag -> type_expr -> type_expr + (* A special case of unification (with {m : 'a; 'b}). *) +val check_filter_method: Env.t -> string -> private_flag -> type_expr -> unit + (* A special case of unification (with {m : 'a; 'b}), returning unit. *) +val deep_occur: type_expr -> type_expr -> bool +val filter_self_method: + Env.t -> string -> private_flag -> (Ident.t * type_expr) Meths.t ref -> + type_expr -> Ident.t * type_expr +val moregeneral: Env.t -> bool -> type_expr -> type_expr -> bool + (* Check if the first type scheme is more general than the second. *) + +val rigidify: type_expr -> type_expr list + (* "Rigidify" a type and return its type variable *) +val all_distinct_vars: Env.t -> type_expr list -> bool + (* Check those types are all distinct type variables *) +val matches : Env.t -> type_expr -> type_expr -> bool + (* Same as [moregeneral false], implemented using the two above + functions and backtracking. Ignore levels *) + +type class_match_failure = + CM_Virtual_class + | CM_Parameter_arity_mismatch of int * int + | CM_Type_parameter_mismatch of (type_expr * type_expr) list + | CM_Class_type_mismatch of class_type * class_type + | CM_Parameter_mismatch of (type_expr * type_expr) list + | CM_Val_type_mismatch of string * (type_expr * type_expr) list + | CM_Meth_type_mismatch of string * (type_expr * type_expr) list + | CM_Non_mutable_value of string + | CM_Non_concrete_value of string + | CM_Missing_value of string + | CM_Missing_method of string + | CM_Hide_public of string + | CM_Hide_virtual of string * string + | CM_Public_method of string + | CM_Private_method of string + | CM_Virtual_method of string +val match_class_types: + Env.t -> class_type -> class_type -> class_match_failure list + (* Check if the first class type is more general than the second. *) +val equal: Env.t -> bool -> type_expr list -> type_expr list -> bool + (* [equal env [x1...xn] tau [y1...yn] sigma] + checks whether the parameterized types + [/\x1.../\xn.tau] and [/\y1.../\yn.sigma] are equivalent. *) +val match_class_declarations: + Env.t -> type_expr list -> class_type -> type_expr list -> + class_type -> class_match_failure list + (* Check if the first class type is more general than the second. *) + +val enlarge_type: Env.t -> type_expr -> type_expr * bool + (* Make a type larger, flag is true if some pruning had to be done *) +val subtype: Env.t -> type_expr -> type_expr -> unit -> unit + (* [subtype env t1 t2] checks that [t1] is a subtype of [t2]. + It accumulates the constraints the type variables must + enforce and returns a function that inforce this + constraints. *) + +val nondep_type: Env.t -> Ident.t -> type_expr -> type_expr + (* Return a type equivalent to the given type but without + references to the given module identifier. Raise [Not_found] + if no such type exists. *) +val nondep_type_decl: + Env.t -> Ident.t -> Ident.t -> bool -> type_declaration -> + type_declaration + (* Same for type declarations. *) +val nondep_class_declaration: + Env.t -> Ident.t -> class_declaration -> class_declaration + (* Same for class declarations. *) +val nondep_cltype_declaration: + Env.t -> Ident.t -> cltype_declaration -> cltype_declaration + (* Same for class type declarations. *) +val correct_abbrev: Env.t -> Path.t -> type_expr list -> type_expr -> unit +val cyclic_abbrev: Env.t -> Ident.t -> type_expr -> bool +val normalize_type: Env.t -> type_expr -> unit + +val closed_schema: type_expr -> bool + (* Check whether the given type scheme contains no non-generic + type variables *) + +val free_variables: type_expr -> type_expr list +val closed_type_decl: type_declaration -> type_expr option +type closed_class_failure = + CC_Method of type_expr * bool * string * type_expr + | CC_Value of type_expr * bool * string * type_expr +val closed_class: + type_expr list -> class_signature -> closed_class_failure option + (* Check whether all type variables are bound *) + +val unalias: type_expr -> type_expr +val signature_of_class_type: class_type -> class_signature +val self_type: class_type -> type_expr +val class_type_arity: class_type -> int +val arity: type_expr -> int + (* Return the arity (as for curried functions) of the given type. *) + +val collapse_conj_params: Env.t -> type_expr list -> unit + (* Collapse conjunctive types in class parameters *) diff --git a/typing/datarepr.ml b/typing/datarepr.ml new file mode 100644 index 0000000..2d93fac --- /dev/null +++ b/typing/datarepr.ml @@ -0,0 +1,96 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: datarepr.ml,v 1.13 2003-07-02 09:14:32 xleroy Exp $ *) + +(* Compute constructor and label descriptions from type declarations, + determining their representation. *) + +open Misc +open Asttypes +open Types + +let constructor_descrs ty_res cstrs priv = + let num_consts = ref 0 and num_nonconsts = ref 0 in + List.iter + (function (name, []) -> incr num_consts + | (name, _) -> incr num_nonconsts) + cstrs; + let rec describe_constructors idx_const idx_nonconst = function + [] -> [] + | (name, ty_args) :: rem -> + let (tag, descr_rem) = + match ty_args with + [] -> (Cstr_constant idx_const, + describe_constructors (idx_const+1) idx_nonconst rem) + | _ -> (Cstr_block idx_nonconst, + describe_constructors idx_const (idx_nonconst+1) rem) in + let cstr = + { cstr_res = ty_res; + cstr_args = ty_args; + cstr_arity = List.length ty_args; + cstr_tag = tag; + cstr_consts = !num_consts; + cstr_nonconsts = !num_nonconsts; + cstr_private = priv } in + (name, cstr) :: descr_rem in + describe_constructors 0 0 cstrs + +let exception_descr path_exc decl = + { cstr_res = Predef.type_exn; + cstr_args = decl; + cstr_arity = List.length decl; + cstr_tag = Cstr_exception path_exc; + cstr_consts = -1; + cstr_nonconsts = -1; + cstr_private = Public } + +let none = {desc = Ttuple []; level = -1; id = -1} + (* Clearly ill-formed type *) +let dummy_label = + { lbl_res = none; lbl_arg = none; lbl_mut = Immutable; + lbl_pos = (-1); lbl_all = [||]; lbl_repres = Record_regular; + lbl_private = Public } + +let label_descrs ty_res lbls repres priv = + let all_labels = Array.create (List.length lbls) dummy_label in + let rec describe_labels num = function + [] -> [] + | (name, mut_flag, ty_arg) :: rest -> + let lbl = + { lbl_res = ty_res; + lbl_arg = ty_arg; + lbl_mut = mut_flag; + lbl_pos = num; + lbl_all = all_labels; + lbl_repres = repres; + lbl_private = priv } in + all_labels.(num) <- lbl; + (name, lbl) :: describe_labels (num+1) rest in + describe_labels 0 lbls + +exception Constr_not_found + +let rec find_constr tag num_const num_nonconst = function + [] -> + raise Constr_not_found + | (name, [] as cstr) :: rem -> + if tag = Cstr_constant num_const + then cstr + else find_constr tag (num_const + 1) num_nonconst rem + | (name, _ as cstr) :: rem -> + if tag = Cstr_block num_nonconst + then cstr + else find_constr tag num_const (num_nonconst + 1) rem + +let find_constr_by_tag tag cstrlist = + find_constr tag 0 0 cstrlist diff --git a/typing/datarepr.mli b/typing/datarepr.mli new file mode 100644 index 0000000..d383dc5 --- /dev/null +++ b/typing/datarepr.mli @@ -0,0 +1,34 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: datarepr.mli,v 1.9 2003-07-02 09:14:32 xleroy Exp $ *) + +(* Compute constructor and label descriptions from type declarations, + determining their representation. *) + +open Asttypes +open Types + +val constructor_descrs: + type_expr -> (string * type_expr list) list -> private_flag -> + (string * constructor_description) list +val exception_descr: + Path.t -> type_expr list -> constructor_description +val label_descrs: + type_expr -> (string * mutable_flag * type_expr) list -> + record_representation -> private_flag -> + (string * label_description) list + +exception Constr_not_found + +val find_constr_by_tag: + constructor_tag -> (string * type_expr list) list -> string * type_expr list diff --git a/typing/env.ml b/typing/env.ml new file mode 100644 index 0000000..b0f4742 --- /dev/null +++ b/typing/env.ml @@ -0,0 +1,862 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: env.ml,v 1.66 2008-10-06 13:53:54 doligez Exp $ *) + +(* Environment handling *) + +open Config +open Misc +open Asttypes +open Longident +open Path +open Types + + +type error = + Not_an_interface of string + | Corrupted_interface of string + | Illegal_renaming of string * string + | Inconsistent_import of string * string * string + | Need_recursive_types of string * string + +exception Error of error + +type summary = + Env_empty + | Env_value of summary * Ident.t * value_description + | Env_type of summary * Ident.t * type_declaration + | Env_exception of summary * Ident.t * exception_declaration + | Env_module of summary * Ident.t * module_type + | Env_modtype of summary * Ident.t * modtype_declaration + | Env_class of summary * Ident.t * class_declaration + | Env_cltype of summary * Ident.t * cltype_declaration + | Env_open of summary * Path.t + +type t = { + values: (Path.t * value_description) Ident.tbl; + annotations: (Path.t * Annot.ident) Ident.tbl; + constrs: constructor_description Ident.tbl; + labels: label_description Ident.tbl; + types: (Path.t * type_declaration) Ident.tbl; + modules: (Path.t * module_type) Ident.tbl; + modtypes: (Path.t * modtype_declaration) Ident.tbl; + components: (Path.t * module_components) Ident.tbl; + classes: (Path.t * class_declaration) Ident.tbl; + cltypes: (Path.t * cltype_declaration) Ident.tbl; + summary: summary +} + +and module_components = module_components_repr Lazy.t + +and module_components_repr = + Structure_comps of structure_components + | Functor_comps of functor_components + +and structure_components = { + mutable comp_values: (string, (value_description * int)) Tbl.t; + mutable comp_annotations: (string, (Annot.ident * int)) Tbl.t; + mutable comp_constrs: (string, (constructor_description * int)) Tbl.t; + mutable comp_labels: (string, (label_description * int)) Tbl.t; + mutable comp_types: (string, (type_declaration * int)) Tbl.t; + mutable comp_modules: (string, (module_type Lazy.t * int)) Tbl.t; + mutable comp_modtypes: (string, (modtype_declaration * int)) Tbl.t; + mutable comp_components: (string, (module_components * int)) Tbl.t; + mutable comp_classes: (string, (class_declaration * int)) Tbl.t; + mutable comp_cltypes: (string, (cltype_declaration * int)) Tbl.t +} + +and functor_components = { + fcomp_param: Ident.t; (* Formal parameter *) + fcomp_arg: module_type; (* Argument signature *) + fcomp_res: module_type; (* Result signature *) + fcomp_env: t; (* Environment in which the result signature makes sense *) + fcomp_subst: Subst.t; (* Prefixing substitution for the result signature *) + fcomp_cache: (Path.t, module_components) Hashtbl.t (* For memoization *) +} + +let empty = { + values = Ident.empty; annotations = Ident.empty; constrs = Ident.empty; + labels = Ident.empty; types = Ident.empty; + modules = Ident.empty; modtypes = Ident.empty; + components = Ident.empty; classes = Ident.empty; + cltypes = Ident.empty; + summary = Env_empty } + +let diff_keys tbl1 tbl2 = + let keys2 = Ident.keys tbl2 in + List.filter + (fun id -> + match Ident.find_same id tbl2 with Pident _, _ -> + (try ignore (Ident.find_same id tbl1); false with Not_found -> true) + | _ -> false) + keys2 + +let diff env1 env2 = + diff_keys env1.values env2.values @ + diff_keys env1.modules env2.modules @ + diff_keys env1.classes env2.classes + +(* Forward declarations *) + +let components_of_module' = + ref ((fun env sub path mty -> assert false) : + t -> Subst.t -> Path.t -> module_type -> module_components) +let components_of_functor_appl' = + ref ((fun f p1 p2 -> assert false) : + functor_components -> Path.t -> Path.t -> module_components) +let check_modtype_inclusion = + (* to be filled with Includemod.check_modtype_inclusion *) + ref ((fun env mty1 path1 mty2 -> assert false) : + t -> module_type -> Path.t -> module_type -> unit) + +(* The name of the compilation unit currently compiled. + "" if outside a compilation unit. *) + +let current_unit = ref "" + +(* Persistent structure descriptions *) + +type pers_flags = Rectypes + +type pers_struct = + { ps_name: string; + ps_sig: signature; + ps_comps: module_components; + ps_crcs: (string * Digest.t) list; + ps_filename: string; + ps_flags: pers_flags list } + +let persistent_structures = + (Hashtbl.create 17 : (string, pers_struct) Hashtbl.t) + +(* Consistency between persistent structures *) + +let crc_units = Consistbl.create() + +let check_consistency filename crcs = + try + List.iter + (fun (name, crc) -> Consistbl.check crc_units name crc filename) + crcs + with Consistbl.Inconsistency(name, source, auth) -> + raise(Error(Inconsistent_import(name, auth, source))) + +(* Reading persistent structures from .cmi files *) + +let read_pers_struct modname filename = + let ic = open_in_bin filename in + try + let buffer = String.create (String.length cmi_magic_number) in + really_input ic buffer 0 (String.length cmi_magic_number); + if buffer <> cmi_magic_number then begin + close_in ic; + raise(Error(Not_an_interface filename)) + end; + let (name, sign) = input_value ic in + let crcs = input_value ic in + let flags = input_value ic in + close_in ic; + let comps = + !components_of_module' empty Subst.identity + (Pident(Ident.create_persistent name)) + (Tmty_signature sign) in + let ps = { ps_name = name; + ps_sig = sign; + ps_comps = comps; + ps_crcs = crcs; + ps_filename = filename; + ps_flags = flags } in + if ps.ps_name <> modname then + raise(Error(Illegal_renaming(ps.ps_name, filename))); + check_consistency filename ps.ps_crcs; + List.iter + (function Rectypes -> + if not !Clflags.recursive_types then + raise(Error(Need_recursive_types(ps.ps_name, !current_unit)))) + ps.ps_flags; + Hashtbl.add persistent_structures modname ps; + ps + with End_of_file | Failure _ -> + close_in ic; + raise(Error(Corrupted_interface(filename))) + +let find_pers_struct name = + try + Hashtbl.find persistent_structures name + with Not_found -> + read_pers_struct name (find_in_path_uncap !load_path (name ^ ".cmi")) + +let reset_cache () = + current_unit := ""; + Hashtbl.clear persistent_structures; + Consistbl.clear crc_units + +let set_unit_name name = + current_unit := name + +(* Lookup by identifier *) + +let rec find_module_descr path env = + match path with + Pident id -> + begin try + let (p, desc) = Ident.find_same id env.components + in desc + with Not_found -> + if Ident.persistent id + then (find_pers_struct (Ident.name id)).ps_comps + else raise Not_found + end + | Pdot(p, s, pos) -> + begin match Lazy.force(find_module_descr p env) with + Structure_comps c -> + let (descr, pos) = Tbl.find s c.comp_components in + descr + | Functor_comps f -> + raise Not_found + end + | Papply(p1, p2) -> + begin match Lazy.force(find_module_descr p1 env) with + Functor_comps f -> + !components_of_functor_appl' f p1 p2 + | Structure_comps c -> + raise Not_found + end + +let find proj1 proj2 path env = + match path with + Pident id -> + let (p, data) = Ident.find_same id (proj1 env) + in data + | Pdot(p, s, pos) -> + begin match Lazy.force(find_module_descr p env) with + Structure_comps c -> + let (data, pos) = Tbl.find s (proj2 c) in data + | Functor_comps f -> + raise Not_found + end + | Papply(p1, p2) -> + raise Not_found + +let find_value = + find (fun env -> env.values) (fun sc -> sc.comp_values) +and find_type = + find (fun env -> env.types) (fun sc -> sc.comp_types) +and find_modtype = + find (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) +and find_class = + find (fun env -> env.classes) (fun sc -> sc.comp_classes) +and find_cltype = + find (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) + +(* Find the manifest type associated to a type when appropriate: + - the type should be public or should have a private row, + - the type should have an associated manifest type. *) +let find_type_expansion path env = + let decl = find_type path env in + match decl.type_manifest with + | Some body when decl.type_private = Public + || decl.type_kind <> Type_abstract + || Btype.has_constr_row body -> (decl.type_params, body) + (* The manifest type of Private abstract data types without + private row are still considered unknown to the type system. + Hence, this case is caught by the following clause that also handles + purely abstract data types without manifest type definition. *) + | _ -> raise Not_found + +(* Find the manifest type information associated to a type, i.e. + the necessary information for the compiler's type-based optimisations. + In particular, the manifest type associated to a private abstract type + is revealed for the sake of compiler's type-based optimisations. *) +let find_type_expansion_opt path env = + let decl = find_type path env in + match decl.type_manifest with + (* The manifest type of Private abstract data types can still get + an approximation using their manifest type. *) + | Some body -> (decl.type_params, body) + | _ -> raise Not_found + +let find_modtype_expansion path env = + match find_modtype path env with + Tmodtype_abstract -> raise Not_found + | Tmodtype_manifest mty -> mty + +let find_module path env = + match path with + Pident id -> + begin try + let (p, data) = Ident.find_same id env.modules + in data + with Not_found -> + if Ident.persistent id then + let ps = find_pers_struct (Ident.name id) in + Tmty_signature(ps.ps_sig) + else raise Not_found + end + | Pdot(p, s, pos) -> + begin match Lazy.force (find_module_descr p env) with + Structure_comps c -> + let (data, pos) = Tbl.find s c.comp_modules in Lazy.force data + | Functor_comps f -> + raise Not_found + end + | Papply(p1, p2) -> + raise Not_found (* not right *) + +(* Lookup by name *) + +let rec lookup_module_descr lid env = + match lid with + Lident s -> + begin try + Ident.find_name s env.components + with Not_found -> + if s = !current_unit then raise Not_found; + let ps = find_pers_struct s in + (Pident(Ident.create_persistent s), ps.ps_comps) + end + | Ldot(l, s) -> + let (p, descr) = lookup_module_descr l env in + begin match Lazy.force descr with + Structure_comps c -> + let (descr, pos) = Tbl.find s c.comp_components in + (Pdot(p, s, pos), descr) + | Functor_comps f -> + raise Not_found + end + | Lapply(l1, l2) -> + let (p1, desc1) = lookup_module_descr l1 env in + let (p2, mty2) = lookup_module l2 env in + begin match Lazy.force desc1 with + Functor_comps f -> + !check_modtype_inclusion env mty2 p2 f.fcomp_arg; + (Papply(p1, p2), !components_of_functor_appl' f p1 p2) + | Structure_comps c -> + raise Not_found + end + +and lookup_module lid env = + match lid with + Lident s -> + begin try + Ident.find_name s env.modules + with Not_found -> + if s = !current_unit then raise Not_found; + let ps = find_pers_struct s in + (Pident(Ident.create_persistent s), Tmty_signature ps.ps_sig) + end + | Ldot(l, s) -> + let (p, descr) = lookup_module_descr l env in + begin match Lazy.force descr with + Structure_comps c -> + let (data, pos) = Tbl.find s c.comp_modules in + (Pdot(p, s, pos), Lazy.force data) + | Functor_comps f -> + raise Not_found + end + | Lapply(l1, l2) -> + let (p1, desc1) = lookup_module_descr l1 env in + let (p2, mty2) = lookup_module l2 env in + let p = Papply(p1, p2) in + begin match Lazy.force desc1 with + Functor_comps f -> + !check_modtype_inclusion env mty2 p2 f.fcomp_arg; + (p, Subst.modtype (Subst.add_module f.fcomp_param p2 f.fcomp_subst) + f.fcomp_res) + | Structure_comps c -> + raise Not_found + end + +let lookup proj1 proj2 lid env = + match lid with + Lident s -> + Ident.find_name s (proj1 env) + | Ldot(l, s) -> + let (p, desc) = lookup_module_descr l env in + begin match Lazy.force desc with + Structure_comps c -> + let (data, pos) = Tbl.find s (proj2 c) in + (Pdot(p, s, pos), data) + | Functor_comps f -> + raise Not_found + end + | Lapply(l1, l2) -> + raise Not_found + +let lookup_simple proj1 proj2 lid env = + match lid with + Lident s -> + Ident.find_name s (proj1 env) + | Ldot(l, s) -> + let (p, desc) = lookup_module_descr l env in + begin match Lazy.force desc with + Structure_comps c -> + let (data, pos) = Tbl.find s (proj2 c) in + data + | Functor_comps f -> + raise Not_found + end + | Lapply(l1, l2) -> + raise Not_found + +let lookup_value = + lookup (fun env -> env.values) (fun sc -> sc.comp_values) +let lookup_annot id e = + lookup (fun env -> env.annotations) (fun sc -> sc.comp_annotations) id e +and lookup_constructor = + lookup_simple (fun env -> env.constrs) (fun sc -> sc.comp_constrs) +and lookup_label = + lookup_simple (fun env -> env.labels) (fun sc -> sc.comp_labels) +and lookup_type = + lookup (fun env -> env.types) (fun sc -> sc.comp_types) +and lookup_modtype = + lookup (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) +and lookup_class = + lookup (fun env -> env.classes) (fun sc -> sc.comp_classes) +and lookup_cltype = + lookup (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) + +(* Expand manifest module type names at the top of the given module type *) + +let rec scrape_modtype mty env = + match mty with + Tmty_ident path -> + begin try + scrape_modtype (find_modtype_expansion path env) env + with Not_found -> + mty + end + | _ -> mty + +(* Compute constructor descriptions *) + +let constructors_of_type ty_path decl = + match decl.type_kind with + Type_variant cstrs -> + Datarepr.constructor_descrs + (Btype.newgenty (Tconstr(ty_path, decl.type_params, ref Mnil))) + cstrs decl.type_private + | Type_record _ | Type_abstract -> [] + +(* Compute label descriptions *) + +let labels_of_type ty_path decl = + match decl.type_kind with + Type_record(labels, rep) -> + Datarepr.label_descrs + (Btype.newgenty (Tconstr(ty_path, decl.type_params, ref Mnil))) + labels rep decl.type_private + | Type_variant _ | Type_abstract -> [] + +(* Given a signature and a root path, prefix all idents in the signature + by the root path and build the corresponding substitution. *) + +let rec prefix_idents root pos sub = function + [] -> ([], sub) + | Tsig_value(id, decl) :: rem -> + let p = Pdot(root, Ident.name id, pos) in + let nextpos = match decl.val_kind with Val_prim _ -> pos | _ -> pos+1 in + let (pl, final_sub) = prefix_idents root nextpos sub rem in + (p::pl, final_sub) + | Tsig_type(id, decl, _) :: rem -> + let p = Pdot(root, Ident.name id, nopos) in + let (pl, final_sub) = + prefix_idents root pos (Subst.add_type id p sub) rem in + (p::pl, final_sub) + | Tsig_exception(id, decl) :: rem -> + let p = Pdot(root, Ident.name id, pos) in + let (pl, final_sub) = prefix_idents root (pos+1) sub rem in + (p::pl, final_sub) + | Tsig_module(id, mty, _) :: rem -> + let p = Pdot(root, Ident.name id, pos) in + let (pl, final_sub) = + prefix_idents root (pos+1) (Subst.add_module id p sub) rem in + (p::pl, final_sub) + | Tsig_modtype(id, decl) :: rem -> + let p = Pdot(root, Ident.name id, nopos) in + let (pl, final_sub) = + prefix_idents root pos + (Subst.add_modtype id (Tmty_ident p) sub) rem in + (p::pl, final_sub) + | Tsig_class(id, decl, _) :: rem -> + let p = Pdot(root, Ident.name id, pos) in + let (pl, final_sub) = prefix_idents root (pos + 1) sub rem in + (p::pl, final_sub) + | Tsig_cltype(id, decl, _) :: rem -> + let p = Pdot(root, Ident.name id, nopos) in + let (pl, final_sub) = prefix_idents root pos sub rem in + (p::pl, final_sub) + +(* Compute structure descriptions *) + +let rec components_of_module env sub path mty = + lazy(match scrape_modtype mty env with + Tmty_signature sg -> + let c = + { comp_values = Tbl.empty; comp_annotations = Tbl.empty; + comp_constrs = Tbl.empty; + comp_labels = Tbl.empty; comp_types = Tbl.empty; + comp_modules = Tbl.empty; comp_modtypes = Tbl.empty; + comp_components = Tbl.empty; comp_classes = Tbl.empty; + comp_cltypes = Tbl.empty } in + let (pl, sub) = prefix_idents path 0 sub sg in + let env = ref env in + let pos = ref 0 in + List.iter2 (fun item path -> + match item with + Tsig_value(id, decl) -> + let decl' = Subst.value_description sub decl in + c.comp_values <- + Tbl.add (Ident.name id) (decl', !pos) c.comp_values; + if !Clflags.annotations then begin + c.comp_annotations <- + Tbl.add (Ident.name id) (Annot.Iref_external, !pos) + c.comp_annotations; + end; + begin match decl.val_kind with + Val_prim _ -> () | _ -> incr pos + end + | Tsig_type(id, decl, _) -> + let decl' = Subst.type_declaration sub decl in + c.comp_types <- + Tbl.add (Ident.name id) (decl', nopos) c.comp_types; + List.iter + (fun (name, descr) -> + c.comp_constrs <- Tbl.add name (descr, nopos) c.comp_constrs) + (constructors_of_type path decl'); + List.iter + (fun (name, descr) -> + c.comp_labels <- Tbl.add name (descr, nopos) c.comp_labels) + (labels_of_type path decl'); + env := store_type_infos id path decl !env + | Tsig_exception(id, decl) -> + let decl' = Subst.exception_declaration sub decl in + let cstr = Datarepr.exception_descr path decl' in + c.comp_constrs <- + Tbl.add (Ident.name id) (cstr, !pos) c.comp_constrs; + incr pos + | Tsig_module(id, mty, _) -> + let mty' = lazy (Subst.modtype sub mty) in + c.comp_modules <- + Tbl.add (Ident.name id) (mty', !pos) c.comp_modules; + let comps = components_of_module !env sub path mty in + c.comp_components <- + Tbl.add (Ident.name id) (comps, !pos) c.comp_components; + env := store_module id path mty !env; + incr pos + | Tsig_modtype(id, decl) -> + let decl' = Subst.modtype_declaration sub decl in + c.comp_modtypes <- + Tbl.add (Ident.name id) (decl', nopos) c.comp_modtypes; + env := store_modtype id path decl !env + | Tsig_class(id, decl, _) -> + let decl' = Subst.class_declaration sub decl in + c.comp_classes <- + Tbl.add (Ident.name id) (decl', !pos) c.comp_classes; + incr pos + | Tsig_cltype(id, decl, _) -> + let decl' = Subst.cltype_declaration sub decl in + c.comp_cltypes <- + Tbl.add (Ident.name id) (decl', !pos) c.comp_cltypes) + sg pl; + Structure_comps c + | Tmty_functor(param, ty_arg, ty_res) -> + Functor_comps { + fcomp_param = param; + (* fcomp_arg must be prefixed eagerly, because it is interpreted + in the outer environment, not in env *) + fcomp_arg = Subst.modtype sub ty_arg; + (* fcomp_res is prefixed lazily, because it is interpreted in env *) + fcomp_res = ty_res; + fcomp_env = env; + fcomp_subst = sub; + fcomp_cache = Hashtbl.create 17 } + | Tmty_ident p -> + Structure_comps { + comp_values = Tbl.empty; comp_annotations = Tbl.empty; + comp_constrs = Tbl.empty; + comp_labels = Tbl.empty; comp_types = Tbl.empty; + comp_modules = Tbl.empty; comp_modtypes = Tbl.empty; + comp_components = Tbl.empty; comp_classes = Tbl.empty; + comp_cltypes = Tbl.empty }) + +(* Insertion of bindings by identifier + path *) + +and store_value id path decl env = + { env with + values = Ident.add id (path, decl) env.values; + summary = Env_value(env.summary, id, decl) } + +and store_annot id path annot env = + if !Clflags.annotations then + { env with + annotations = Ident.add id (path, annot) env.annotations } + else env + +and store_type id path info env = + { env with + constrs = + List.fold_right + (fun (name, descr) constrs -> + Ident.add (Ident.create name) descr constrs) + (constructors_of_type path info) + env.constrs; + labels = + List.fold_right + (fun (name, descr) labels -> + Ident.add (Ident.create name) descr labels) + (labels_of_type path info) + env.labels; + types = Ident.add id (path, info) env.types; + summary = Env_type(env.summary, id, info) } + +and store_type_infos id path info env = + (* Simplified version of store_type that doesn't compute and store + constructor and label infos, but simply record the arity and + manifest-ness of the type. Used in components_of_module to + keep track of type abbreviations (e.g. type t = float) in the + computation of label representations. *) + { env with + types = Ident.add id (path, info) env.types; + summary = Env_type(env.summary, id, info) } + +and store_exception id path decl env = + { env with + constrs = Ident.add id (Datarepr.exception_descr path decl) env.constrs; + summary = Env_exception(env.summary, id, decl) } + +and store_module id path mty env = + { env with + modules = Ident.add id (path, mty) env.modules; + components = + Ident.add id (path, components_of_module env Subst.identity path mty) + env.components; + summary = Env_module(env.summary, id, mty) } + +and store_modtype id path info env = + { env with + modtypes = Ident.add id (path, info) env.modtypes; + summary = Env_modtype(env.summary, id, info) } + +and store_class id path desc env = + { env with + classes = Ident.add id (path, desc) env.classes; + summary = Env_class(env.summary, id, desc) } + +and store_cltype id path desc env = + { env with + cltypes = Ident.add id (path, desc) env.cltypes; + summary = Env_cltype(env.summary, id, desc) } + +(* Compute the components of a functor application in a path. *) + +let components_of_functor_appl f p1 p2 = + try + Hashtbl.find f.fcomp_cache p2 + with Not_found -> + let p = Papply(p1, p2) in + let mty = + Subst.modtype (Subst.add_module f.fcomp_param p2 Subst.identity) + f.fcomp_res in + let comps = components_of_module f.fcomp_env f.fcomp_subst p mty in + Hashtbl.add f.fcomp_cache p2 comps; + comps + +(* Define forward functions *) + +let _ = + components_of_module' := components_of_module; + components_of_functor_appl' := components_of_functor_appl + +(* Insertion of bindings by identifier *) + +let add_value id desc env = + store_value id (Pident id) desc env + +let add_annot id annot env = + store_annot id (Pident id) annot env + +and add_type id info env = + store_type id (Pident id) info env + +and add_exception id decl env = + store_exception id (Pident id) decl env + +and add_module id mty env = + store_module id (Pident id) mty env + +and add_modtype id info env = + store_modtype id (Pident id) info env + +and add_class id ty env = + store_class id (Pident id) ty env + +and add_cltype id ty env = + store_cltype id (Pident id) ty env + +(* Insertion of bindings by name *) + +let enter store_fun name data env = + let id = Ident.create name in (id, store_fun id (Pident id) data env) + +let enter_value = enter store_value +and enter_type = enter store_type +and enter_exception = enter store_exception +and enter_module = enter store_module +and enter_modtype = enter store_modtype +and enter_class = enter store_class +and enter_cltype = enter store_cltype + +(* Insertion of all components of a signature *) + +let add_item comp env = + match comp with + Tsig_value(id, decl) -> add_value id decl env + | Tsig_type(id, decl, _) -> add_type id decl env + | Tsig_exception(id, decl) -> add_exception id decl env + | Tsig_module(id, mty, _) -> add_module id mty env + | Tsig_modtype(id, decl) -> add_modtype id decl env + | Tsig_class(id, decl, _) -> add_class id decl env + | Tsig_cltype(id, decl, _) -> add_cltype id decl env + +let rec add_signature sg env = + match sg with + [] -> env + | comp :: rem -> add_signature rem (add_item comp env) + +(* Open a signature path *) + +let open_signature root sg env = + (* First build the paths and substitution *) + let (pl, sub) = prefix_idents root 0 Subst.identity sg in + (* Then enter the components in the environment after substitution *) + let newenv = + List.fold_left2 + (fun env item p -> + match item with + Tsig_value(id, decl) -> + let e1 = store_value (Ident.hide id) p + (Subst.value_description sub decl) env + in store_annot (Ident.hide id) p (Annot.Iref_external) e1 + | Tsig_type(id, decl, _) -> + store_type (Ident.hide id) p + (Subst.type_declaration sub decl) env + | Tsig_exception(id, decl) -> + store_exception (Ident.hide id) p + (Subst.exception_declaration sub decl) env + | Tsig_module(id, mty, _) -> + store_module (Ident.hide id) p (Subst.modtype sub mty) env + | Tsig_modtype(id, decl) -> + store_modtype (Ident.hide id) p + (Subst.modtype_declaration sub decl) env + | Tsig_class(id, decl, _) -> + store_class (Ident.hide id) p + (Subst.class_declaration sub decl) env + | Tsig_cltype(id, decl, _) -> + store_cltype (Ident.hide id) p + (Subst.cltype_declaration sub decl) env) + env sg pl in + { newenv with summary = Env_open(env.summary, root) } + +(* Open a signature from a file *) + +let open_pers_signature name env = + let ps = find_pers_struct name in + open_signature (Pident(Ident.create_persistent name)) ps.ps_sig env + +(* Read a signature from a file *) + +let read_signature modname filename = + let ps = read_pers_struct modname filename in ps.ps_sig + +(* Return the CRC of the interface of the given compilation unit *) + +let crc_of_unit name = + let ps = find_pers_struct name in + try + List.assoc name ps.ps_crcs + with Not_found -> + assert false + +(* Return the list of imported interfaces with their CRCs *) + +let imported_units() = + Consistbl.extract crc_units + +(* Save a signature to a file *) + +let save_signature_with_imports sg modname filename imports = + Btype.cleanup_abbrev (); + Subst.reset_for_saving (); + let sg = Subst.signature (Subst.for_saving Subst.identity) sg in + let oc = open_out_bin filename in + try + output_string oc cmi_magic_number; + output_value oc (modname, sg); + flush oc; + let crc = Digest.file filename in + let crcs = (modname, crc) :: imports in + output_value oc crcs; + let flags = if !Clflags.recursive_types then [Rectypes] else [] in + output_value oc flags; + close_out oc; + (* Enter signature in persistent table so that imported_unit() + will also return its crc *) + let comps = + components_of_module empty Subst.identity + (Pident(Ident.create_persistent modname)) (Tmty_signature sg) in + let ps = + { ps_name = modname; + ps_sig = sg; + ps_comps = comps; + ps_crcs = crcs; + ps_filename = filename; + ps_flags = flags } in + Hashtbl.add persistent_structures modname ps; + Consistbl.set crc_units modname crc filename + with exn -> + close_out oc; + remove_file filename; + raise exn + +let save_signature sg modname filename = + save_signature_with_imports sg modname filename (imported_units()) + +(* Make the initial environment *) + +let initial = Predef.build_initial_env add_type add_exception empty + +(* Return the environment summary *) + +let summary env = env.summary + +(* Error report *) + +open Format + +let report_error ppf = function + | Not_an_interface filename -> fprintf ppf + "%s@ is not a compiled interface" filename + | Corrupted_interface filename -> fprintf ppf + "Corrupted compiled interface@ %s" filename + | Illegal_renaming(modname, filename) -> fprintf ppf + "Wrong file naming: %s@ contains the compiled interface for@ %s" + filename modname + | Inconsistent_import(name, source1, source2) -> fprintf ppf + "@[<hov>The files %s@ and %s@ \ + make inconsistent assumptions@ over interface %s@]" + source1 source2 name + | Need_recursive_types(import, export) -> + fprintf ppf + "@[<hov>Unit %s imports from %s, which uses recursive types.@ %s@]" + import export "The compilation flag -rectypes is required" diff --git a/typing/env.mli b/typing/env.mli new file mode 100644 index 0000000..b5653ea --- /dev/null +++ b/typing/env.mli @@ -0,0 +1,146 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: env.mli,v 1.35 2008-10-06 13:53:54 doligez Exp $ *) + +(* Environment handling *) + +open Types + +type t + +val empty: t +val initial: t +val diff: t -> t -> Ident.t list + +(* Lookup by paths *) + +val find_value: Path.t -> t -> value_description +val find_type: Path.t -> t -> type_declaration +val find_module: Path.t -> t -> module_type +val find_modtype: Path.t -> t -> modtype_declaration +val find_class: Path.t -> t -> class_declaration +val find_cltype: Path.t -> t -> cltype_declaration + +val find_type_expansion: Path.t -> t -> type_expr list * type_expr +val find_type_expansion_opt: Path.t -> t -> type_expr list * type_expr +(* Find the manifest type information associated to a type for the sake + of the compiler's type-based optimisations. *) +val find_modtype_expansion: Path.t -> t -> Types.module_type + +(* Lookup by long identifiers *) + +val lookup_value: Longident.t -> t -> Path.t * value_description +val lookup_annot: Longident.t -> t -> Path.t * Annot.ident +val lookup_constructor: Longident.t -> t -> constructor_description +val lookup_label: Longident.t -> t -> label_description +val lookup_type: Longident.t -> t -> Path.t * type_declaration +val lookup_module: Longident.t -> t -> Path.t * module_type +val lookup_modtype: Longident.t -> t -> Path.t * modtype_declaration +val lookup_class: Longident.t -> t -> Path.t * class_declaration +val lookup_cltype: Longident.t -> t -> Path.t * cltype_declaration + +(* Insertion by identifier *) + +val add_value: Ident.t -> value_description -> t -> t +val add_annot: Ident.t -> Annot.ident -> t -> t +val add_type: Ident.t -> type_declaration -> t -> t +val add_exception: Ident.t -> exception_declaration -> t -> t +val add_module: Ident.t -> module_type -> t -> t +val add_modtype: Ident.t -> modtype_declaration -> t -> t +val add_class: Ident.t -> class_declaration -> t -> t +val add_cltype: Ident.t -> cltype_declaration -> t -> t + +(* Insertion of all fields of a signature. *) + +val add_item: signature_item -> t -> t +val add_signature: signature -> t -> t + +(* Insertion of all fields of a signature, relative to the given path. + Used to implement open. *) + +val open_signature: Path.t -> signature -> t -> t +val open_pers_signature: string -> t -> t + +(* Insertion by name *) + +val enter_value: string -> value_description -> t -> Ident.t * t +val enter_type: string -> type_declaration -> t -> Ident.t * t +val enter_exception: string -> exception_declaration -> t -> Ident.t * t +val enter_module: string -> module_type -> t -> Ident.t * t +val enter_modtype: string -> modtype_declaration -> t -> Ident.t * t +val enter_class: string -> class_declaration -> t -> Ident.t * t +val enter_cltype: string -> cltype_declaration -> t -> Ident.t * t + +(* Initialize the cache of in-core module interfaces. *) +val reset_cache: unit -> unit + +(* Remember the name of the current compilation unit. *) +val set_unit_name: string -> unit + +(* Read, save a signature to/from a file *) + +val read_signature: string -> string -> signature + (* Arguments: module name, file name. Results: signature. *) +val save_signature: signature -> string -> string -> unit + (* Arguments: signature, module name, file name. *) +val save_signature_with_imports: + signature -> string -> string -> (string * Digest.t) list -> unit + (* Arguments: signature, module name, file name, + imported units with their CRCs. *) + +(* Return the CRC of the interface of the given compilation unit *) + +val crc_of_unit: string -> Digest.t + +(* Return the set of compilation units imported, with their CRC *) + +val imported_units: unit -> (string * Digest.t) list + +(* Direct access to the table of imported compilation units with their CRC *) + +val crc_units: Consistbl.t + +(* Summaries -- compact representation of an environment, to be + exported in debugging information. *) + +type summary = + Env_empty + | Env_value of summary * Ident.t * value_description + | Env_type of summary * Ident.t * type_declaration + | Env_exception of summary * Ident.t * exception_declaration + | Env_module of summary * Ident.t * module_type + | Env_modtype of summary * Ident.t * modtype_declaration + | Env_class of summary * Ident.t * class_declaration + | Env_cltype of summary * Ident.t * cltype_declaration + | Env_open of summary * Path.t + +val summary: t -> summary + +(* Error report *) + +type error = + Not_an_interface of string + | Corrupted_interface of string + | Illegal_renaming of string * string + | Inconsistent_import of string * string * string + | Need_recursive_types of string * string + +exception Error of error + +open Format + +val report_error: formatter -> error -> unit + +(* Forward declaration to break mutual recursion with Includemod. *) +val check_modtype_inclusion: + (t -> module_type -> Path.t -> module_type -> unit) ref diff --git a/typing/ident.ml b/typing/ident.ml new file mode 100644 index 0000000..9c7e5b0 --- /dev/null +++ b/typing/ident.ml @@ -0,0 +1,184 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ident.ml,v 1.23 2004-01-04 14:32:34 doligez Exp $ *) + +open Format + +type t = { stamp: int; name: string; mutable flags: int } + +let global_flag = 1 +let predef_exn_flag = 2 + +(* A stamp of 0 denotes a persistent identifier *) + +let currentstamp = ref 0 + +let create s = + incr currentstamp; + { name = s; stamp = !currentstamp; flags = 0 } + +let create_predef_exn s = + incr currentstamp; + { name = s; stamp = !currentstamp; flags = predef_exn_flag } + +let create_persistent s = + { name = s; stamp = 0; flags = global_flag } + +let rename i = + incr currentstamp; + { i with stamp = !currentstamp } + +let name i = i.name + +let stamp i = i.stamp + +let unique_name i = i.name ^ "_" ^ string_of_int i.stamp + +let unique_toplevel_name i = i.name ^ "/" ^ string_of_int i.stamp + +let persistent i = (i.stamp = 0) + +let equal i1 i2 = i1.name = i2.name + +let same i1 i2 = i1 = i2 + (* Possibly more efficient version (with a real compiler, at least): + if i1.stamp <> 0 + then i1.stamp = i2.stamp + else i2.stamp = 0 && i1.name = i2.name *) + +let binding_time i = i.stamp + +let current_time() = !currentstamp +let set_current_time t = currentstamp := max !currentstamp t + +let reinit_level = ref (-1) + +let reinit () = + if !reinit_level < 0 + then reinit_level := !currentstamp + else currentstamp := !reinit_level + +let hide i = + { i with stamp = -1 } + +let make_global i = + i.flags <- i.flags lor global_flag + +let global i = + (i.flags land global_flag) <> 0 + +let is_predef_exn i = + (i.flags land predef_exn_flag) <> 0 + +let print ppf i = + match i.stamp with + | 0 -> fprintf ppf "%s!" i.name + | -1 -> fprintf ppf "%s#" i.name + | n -> fprintf ppf "%s/%i%s" i.name n (if global i then "g" else "") + +type 'a tbl = + Empty + | Node of 'a tbl * 'a data * 'a tbl * int + +and 'a data = + { ident: t; + data: 'a; + previous: 'a data option } + +let empty = Empty + +(* Inline expansion of height for better speed + * let height = function + * Empty -> 0 + * | Node(_,_,_,h) -> h + *) + +let mknode l d r = + let hl = match l with Empty -> 0 | Node(_,_,_,h) -> h + and hr = match r with Empty -> 0 | Node(_,_,_,h) -> h in + Node(l, d, r, (if hl >= hr then hl + 1 else hr + 1)) + +let balance l d r = + let hl = match l with Empty -> 0 | Node(_,_,_,h) -> h + and hr = match r with Empty -> 0 | Node(_,_,_,h) -> h in + if hl > hr + 1 then + match l with + | Node (ll, ld, lr, _) + when (match ll with Empty -> 0 | Node(_,_,_,h) -> h) >= + (match lr with Empty -> 0 | Node(_,_,_,h) -> h) -> + mknode ll ld (mknode lr d r) + | Node (ll, ld, Node(lrl, lrd, lrr, _), _) -> + mknode (mknode ll ld lrl) lrd (mknode lrr d r) + | _ -> assert false + else if hr > hl + 1 then + match r with + | Node (rl, rd, rr, _) + when (match rr with Empty -> 0 | Node(_,_,_,h) -> h) >= + (match rl with Empty -> 0 | Node(_,_,_,h) -> h) -> + mknode (mknode l d rl) rd rr + | Node (Node (rll, rld, rlr, _), rd, rr, _) -> + mknode (mknode l d rll) rld (mknode rlr rd rr) + | _ -> assert false + else + mknode l d r + +let rec add id data = function + Empty -> + Node(Empty, {ident = id; data = data; previous = None}, Empty, 1) + | Node(l, k, r, h) -> + let c = compare id.name k.ident.name in + if c = 0 then + Node(l, {ident = id; data = data; previous = Some k}, r, h) + else if c < 0 then + balance (add id data l) k r + else + balance l k (add id data r) + +let rec find_stamp s = function + None -> + raise Not_found + | Some k -> + if k.ident.stamp = s then k.data else find_stamp s k.previous + +let rec find_same id = function + Empty -> + raise Not_found + | Node(l, k, r, _) -> + let c = compare id.name k.ident.name in + if c = 0 then + if id.stamp = k.ident.stamp + then k.data + else find_stamp id.stamp k.previous + else + find_same id (if c < 0 then l else r) + +let rec find_name name = function + Empty -> + raise Not_found + | Node(l, k, r, _) -> + let c = compare name k.ident.name in + if c = 0 then + k.data + else + find_name name (if c < 0 then l else r) + +let rec keys_aux stack accu = function + Empty -> + begin match stack with + [] -> accu + | a :: l -> keys_aux l accu a + end + | Node(l, k, r, _) -> + keys_aux (l :: stack) (k.ident :: accu) r + +let keys tbl = keys_aux [] [] tbl diff --git a/typing/ident.mli b/typing/ident.mli new file mode 100644 index 0000000..cbed46d --- /dev/null +++ b/typing/ident.mli @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ident.mli,v 1.17 2004-01-04 14:32:34 doligez Exp $ *) + +(* Identifiers (unique names) *) + +type t + +val create: string -> t +val create_persistent: string -> t +val create_predef_exn: string -> t +val rename: t -> t +val name: t -> string +val unique_name: t -> string +val unique_toplevel_name: t -> string +val persistent: t -> bool +val equal: t -> t -> bool + (* Compare identifiers by name. *) +val same: t -> t -> bool + (* Compare identifiers by binding location. + Two identifiers are the same either if they are both + non-persistent and have been created by the same call to + [new], or if they are both persistent and have the same + name. *) +val hide: t -> t + (* Return an identifier with same name as the given identifier, + but stamp different from any stamp returned by new. + When put in a 'a tbl, this identifier can only be looked + up by name. *) + +val make_global: t -> unit +val global: t -> bool +val is_predef_exn: t -> bool + +val binding_time: t -> int +val current_time: unit -> int +val set_current_time: int -> unit +val reinit: unit -> unit + +val print: Format.formatter -> t -> unit + +type 'a tbl + (* Association tables from identifiers to type 'a. *) + +val empty: 'a tbl +val add: t -> 'a -> 'a tbl -> 'a tbl +val find_same: t -> 'a tbl -> 'a +val find_name: string -> 'a tbl -> 'a +val keys: 'a tbl -> t list diff --git a/typing/includeclass.ml b/typing/includeclass.ml new file mode 100644 index 0000000..bbea483 --- /dev/null +++ b/typing/includeclass.ml @@ -0,0 +1,107 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includeclass.ml,v 1.8 2006-04-05 02:28:13 garrigue Exp $ *) + +(* Inclusion checks for the class language *) + +open Types + +let class_types env cty1 cty2 = + Ctype.match_class_types env cty1 cty2 + +let class_type_declarations env cty1 cty2 = + Ctype.match_class_declarations env + cty1.clty_params cty1.clty_type + cty2.clty_params cty2.clty_type + +let class_declarations env cty1 cty2 = + match cty1.cty_new, cty2.cty_new with + None, Some _ -> + [Ctype.CM_Virtual_class] + | _ -> + Ctype.match_class_declarations env + cty1.cty_params cty1.cty_type + cty2.cty_params cty2.cty_type + +open Format +open Ctype + +let include_err ppf = + function + | CM_Virtual_class -> + fprintf ppf "A class cannot be changed from virtual to concrete" + | CM_Parameter_arity_mismatch (ls, lp) -> + fprintf ppf + "The classes do not have the same number of type parameters" + | CM_Type_parameter_mismatch trace -> + fprintf ppf "@[%a@]" + (Printtyp.unification_error false trace + (function ppf -> + fprintf ppf "One type parameter has type")) + (function ppf -> + fprintf ppf "but is expected to have type") + | CM_Class_type_mismatch (cty1, cty2) -> + fprintf ppf + "@[The class type@;<1 2>%a@ is not matched by the class type@;<1 2>%a@]" + Printtyp.class_type cty1 Printtyp.class_type cty2 + | CM_Parameter_mismatch trace -> + fprintf ppf "@[%a@]" + (Printtyp.unification_error false trace + (function ppf -> + fprintf ppf "One parameter has type")) + (function ppf -> + fprintf ppf "but is expected to have type") + | CM_Val_type_mismatch (lab, trace) -> + fprintf ppf "@[%a@]" + (Printtyp.unification_error false trace + (function ppf -> + fprintf ppf "The instance variable %s@ has type" lab)) + (function ppf -> + fprintf ppf "but is expected to have type") + | CM_Meth_type_mismatch (lab, trace) -> + fprintf ppf "@[%a@]" + (Printtyp.unification_error false trace + (function ppf -> + fprintf ppf "The method %s@ has type" lab)) + (function ppf -> + fprintf ppf "but is expected to have type") + | CM_Non_mutable_value lab -> + fprintf ppf + "@[The non-mutable instance variable %s cannot become mutable@]" lab + | CM_Non_concrete_value lab -> + fprintf ppf + "@[The virtual instance variable %s cannot become concrete@]" lab + | CM_Missing_value lab -> + fprintf ppf "@[The first class type has no instance variable %s@]" lab + | CM_Missing_method lab -> + fprintf ppf "@[The first class type has no method %s@]" lab + | CM_Hide_public lab -> + fprintf ppf "@[The public method %s cannot be hidden@]" lab + | CM_Hide_virtual (k, lab) -> + fprintf ppf "@[The virtual %s %s cannot be hidden@]" k lab + | CM_Public_method lab -> + fprintf ppf "@[The public method %s cannot become private" lab + | CM_Virtual_method lab -> + fprintf ppf "@[The virtual method %s cannot become concrete" lab + | CM_Private_method lab -> + fprintf ppf "The private method %s cannot become public" lab + +let report_error ppf = function + | [] -> () + | err :: errs -> + let print_errs ppf errs = + List.iter (fun err -> fprintf ppf "@ %a" include_err err) errs in + fprintf ppf "@[<v>%a%a@]" include_err err print_errs errs + + + diff --git a/typing/includeclass.mli b/typing/includeclass.mli new file mode 100644 index 0000000..ecf884a --- /dev/null +++ b/typing/includeclass.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1997 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includeclass.mli,v 1.3 2000-03-06 22:11:58 weis Exp $ *) + +(* Inclusion checks for the class language *) + +open Types +open Typedtree +open Ctype +open Format + +val class_types: + Env.t -> class_type -> class_type -> class_match_failure list +val class_type_declarations: + Env.t -> cltype_declaration -> cltype_declaration -> + class_match_failure list +val class_declarations: + Env.t -> class_declaration -> class_declaration -> + class_match_failure list + +val report_error: formatter -> class_match_failure list -> unit diff --git a/typing/includecore.ml b/typing/includecore.ml new file mode 100644 index 0000000..31198ba --- /dev/null +++ b/typing/includecore.ml @@ -0,0 +1,193 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includecore.ml,v 1.36 2008-12-03 18:09:09 doligez Exp $ *) + +(* Inclusion checks for the core language *) + +open Misc +open Asttypes +open Path +open Types +open Typedtree + +(* Inclusion between value descriptions *) + +exception Dont_match + +let value_descriptions env vd1 vd2 = + if Ctype.moregeneral env true vd1.val_type vd2.val_type then begin + match (vd1.val_kind, vd2.val_kind) with + (Val_prim p1, Val_prim p2) -> + if p1 = p2 then Tcoerce_none else raise Dont_match + | (Val_prim p, _) -> Tcoerce_primitive p + | (_, Val_prim p) -> raise Dont_match + | (_, _) -> Tcoerce_none + end else + raise Dont_match + +(* Inclusion between "private" annotations *) + +let private_flags decl1 decl2 = + match decl1.type_private, decl2.type_private with + | Private, Public -> + decl2.type_kind = Type_abstract && decl2.type_manifest = None + | _, _ -> true + +(* Inclusion between manifest types (particularly for private row types) *) + +let is_absrow env ty = + match ty.desc with + Tconstr(Pident id, _, _) -> + begin match Ctype.expand_head env ty with + {desc=Tobject _|Tvariant _} -> true + | _ -> false + end + | _ -> false + +let type_manifest env ty1 params1 ty2 params2 priv2 = + let ty1' = Ctype.expand_head env ty1 and ty2' = Ctype.expand_head env ty2 in + match ty1'.desc, ty2'.desc with + Tvariant row1, Tvariant row2 when is_absrow env (Btype.row_more row2) -> + let row1 = Btype.row_repr row1 and row2 = Btype.row_repr row2 in + Ctype.equal env true (ty1::params1) (row2.row_more::params2) && + (match row1.row_more with {desc=Tvar|Tconstr _} -> true | _ -> false) && + let r1, r2, pairs = + Ctype.merge_row_fields row1.row_fields row2.row_fields in + (not row2.row_closed || + row1.row_closed && Ctype.filter_row_fields false r1 = []) && + List.for_all + (fun (_,f) -> match Btype.row_field_repr f with + Rabsent | Reither _ -> true | Rpresent _ -> false) + r2 && + let to_equal = ref (List.combine params1 params2) in + List.for_all + (fun (_, f1, f2) -> + match Btype.row_field_repr f1, Btype.row_field_repr f2 with + Rpresent(Some t1), + (Rpresent(Some t2) | Reither(false, [t2], _, _)) -> + to_equal := (t1,t2) :: !to_equal; true + | Rpresent None, (Rpresent None | Reither(true, [], _, _)) -> true + | Reither(c1,tl1,_,_), Reither(c2,tl2,_,_) + when List.length tl1 = List.length tl2 && c1 = c2 -> + to_equal := List.combine tl1 tl2 @ !to_equal; true + | Rabsent, (Reither _ | Rabsent) -> true + | _ -> false) + pairs && + let tl1, tl2 = List.split !to_equal in + Ctype.equal env true tl1 tl2 + | Tobject (fi1, _), Tobject (fi2, _) + when is_absrow env (snd(Ctype.flatten_fields fi2)) -> + let (fields2,rest2) = Ctype.flatten_fields fi2 in + Ctype.equal env true (ty1::params1) (rest2::params2) && + let (fields1,rest1) = Ctype.flatten_fields fi1 in + (match rest1 with {desc=Tnil|Tvar|Tconstr _} -> true | _ -> false) && + let pairs, miss1, miss2 = Ctype.associate_fields fields1 fields2 in + miss2 = [] && + let tl1, tl2 = + List.split (List.map (fun (_,_,t1,_,t2) -> t1, t2) pairs) in + Ctype.equal env true (params1 @ tl1) (params2 @ tl2) + | _ -> + let rec check_super ty1 = + Ctype.equal env true (ty1 :: params1) (ty2 :: params2) || + priv2 = Private && + try check_super + (Ctype.try_expand_once_opt env (Ctype.expand_head env ty1)) + with Ctype.Cannot_expand -> false + in check_super ty1 + +(* Inclusion between type declarations *) + +let type_declarations env id decl1 decl2 = + decl1.type_arity = decl2.type_arity && + private_flags decl1 decl2 && + begin match (decl1.type_kind, decl2.type_kind) with + (_, Type_abstract) -> true + | (Type_variant cstrs1, Type_variant cstrs2) -> + Misc.for_all2 + (fun (cstr1, arg1) (cstr2, arg2) -> + cstr1 = cstr2 && + Misc.for_all2 + (fun ty1 ty2 -> + Ctype.equal env true (ty1::decl1.type_params) + (ty2::decl2.type_params)) + arg1 arg2) + cstrs1 cstrs2 + | (Type_record(labels1,rep1), Type_record(labels2,rep2)) -> + rep1 = rep2 && + Misc.for_all2 + (fun (lbl1, mut1, ty1) (lbl2, mut2, ty2) -> + lbl1 = lbl2 && mut1 = mut2 && + Ctype.equal env true (ty1::decl1.type_params) + (ty2::decl2.type_params)) + labels1 labels2 + | (_, _) -> false + end && + begin match (decl1.type_manifest, decl2.type_manifest) with + (_, None) -> + Ctype.equal env true decl1.type_params decl2.type_params + | (Some ty1, Some ty2) -> + type_manifest env ty1 decl1.type_params ty2 decl2.type_params + decl2.type_private + | (None, Some ty2) -> + let ty1 = + Btype.newgenty (Tconstr(Pident id, decl2.type_params, ref Mnil)) + in + Ctype.equal env true decl1.type_params decl2.type_params && + Ctype.equal env false [ty1] [ty2] + end && + if match decl2.type_kind with + | Type_record (_,_) | Type_variant _ -> decl2.type_private = Private + | Type_abstract -> + match decl2.type_manifest with + | None -> true + | Some ty -> Btype.has_constr_row (Ctype.expand_head env ty) + then + List.for_all2 + (fun (co1,cn1,ct1) (co2,cn2,ct2) -> (not co1 || co2) && (not cn1 || cn2)) + decl1.type_variance decl2.type_variance + else true + +(* Inclusion between exception declarations *) + +let exception_declarations env ed1 ed2 = + Misc.for_all2 (fun ty1 ty2 -> Ctype.equal env false [ty1] [ty2]) ed1 ed2 + +(* Inclusion between class types *) +let encode_val (mut, ty) rem = + begin match mut with + Asttypes.Mutable -> Predef.type_unit + | Asttypes.Immutable -> Btype.newgenty Tvar + end + ::ty::rem + +let meths meths1 meths2 = + Meths.fold + (fun nam t2 (ml1, ml2) -> + (begin try + Meths.find nam meths1 :: ml1 + with Not_found -> + ml1 + end, + t2 :: ml2)) + meths2 ([], []) + +let vars vars1 vars2 = + Vars.fold + (fun lab v2 (vl1, vl2) -> + (begin try + encode_val (Vars.find lab vars1) vl1 + with Not_found -> + vl1 + end, + encode_val v2 vl2)) + vars2 ([], []) diff --git a/typing/includecore.mli b/typing/includecore.mli new file mode 100644 index 0000000..b8d7445 --- /dev/null +++ b/typing/includecore.mli @@ -0,0 +1,31 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includecore.mli,v 1.10 1999-11-17 18:58:54 xleroy Exp $ *) + +(* Inclusion checks for the core language *) + +open Types +open Typedtree + +exception Dont_match + +val value_descriptions: + Env.t -> value_description -> value_description -> module_coercion +val type_declarations: + Env.t -> Ident.t -> type_declaration -> type_declaration -> bool +val exception_declarations: + Env.t -> exception_declaration -> exception_declaration -> bool +(* +val class_types: + Env.t -> class_type -> class_type -> bool +*) diff --git a/typing/includemod.ml b/typing/includemod.ml new file mode 100644 index 0000000..7b3f3f6 --- /dev/null +++ b/typing/includemod.ml @@ -0,0 +1,390 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includemod.ml,v 1.39 2008-01-11 16:13:16 doligez Exp $ *) + +(* Inclusion checks for the module language *) + +open Misc +open Path +open Types +open Typedtree + +type error = + Missing_field of Ident.t + | Value_descriptions of Ident.t * value_description * value_description + | Type_declarations of Ident.t * type_declaration * type_declaration + | Exception_declarations of + Ident.t * exception_declaration * exception_declaration + | Module_types of module_type * module_type + | Modtype_infos of Ident.t * modtype_declaration * modtype_declaration + | Modtype_permutation + | Interface_mismatch of string * string + | Class_type_declarations of + Ident.t * cltype_declaration * cltype_declaration * + Ctype.class_match_failure list + | Class_declarations of + Ident.t * class_declaration * class_declaration * + Ctype.class_match_failure list + | Unbound_modtype_path of Path.t + +exception Error of error list + +(* All functions "blah env x1 x2" check that x1 is included in x2, + i.e. that x1 is the type of an implementation that fulfills the + specification x2. If not, Error is raised with a backtrace of the error. *) + +(* Inclusion between value descriptions *) + +let value_descriptions env subst id vd1 vd2 = + let vd2 = Subst.value_description subst vd2 in + try + Includecore.value_descriptions env vd1 vd2 + with Includecore.Dont_match -> + raise(Error[Value_descriptions(id, vd1, vd2)]) + +(* Inclusion between type declarations *) + +let type_declarations env subst id decl1 decl2 = + let decl2 = Subst.type_declaration subst decl2 in + if Includecore.type_declarations env id decl1 decl2 + then () + else raise(Error[Type_declarations(id, decl1, decl2)]) + +(* Inclusion between exception declarations *) + +let exception_declarations env subst id decl1 decl2 = + let decl2 = Subst.exception_declaration subst decl2 in + if Includecore.exception_declarations env decl1 decl2 + then () + else raise(Error[Exception_declarations(id, decl1, decl2)]) + +(* Inclusion between class declarations *) + +let class_type_declarations env subst id decl1 decl2 = + let decl2 = Subst.cltype_declaration subst decl2 in + match Includeclass.class_type_declarations env decl1 decl2 with + [] -> () + | reason -> raise(Error[Class_type_declarations(id, decl1, decl2, reason)]) + +let class_declarations env subst id decl1 decl2 = + let decl2 = Subst.class_declaration subst decl2 in + match Includeclass.class_declarations env decl1 decl2 with + [] -> () + | reason -> raise(Error[Class_declarations(id, decl1, decl2, reason)]) + +(* Expand a module type identifier when possible *) + +exception Dont_match + +let expand_module_path env path = + try + Env.find_modtype_expansion path env + with Not_found -> + raise(Error[Unbound_modtype_path path]) + +(* Extract name, kind and ident from a signature item *) + +type field_desc = + Field_value of string + | Field_type of string + | Field_exception of string + | Field_module of string + | Field_modtype of string + | Field_class of string + | Field_classtype of string + +let item_ident_name = function + Tsig_value(id, _) -> (id, Field_value(Ident.name id)) + | Tsig_type(id, _, _) -> (id, Field_type(Ident.name id)) + | Tsig_exception(id, _) -> (id, Field_exception(Ident.name id)) + | Tsig_module(id, _, _) -> (id, Field_module(Ident.name id)) + | Tsig_modtype(id, _) -> (id, Field_modtype(Ident.name id)) + | Tsig_class(id, _, _) -> (id, Field_class(Ident.name id)) + | Tsig_cltype(id, _, _) -> (id, Field_classtype(Ident.name id)) + +(* Simplify a structure coercion *) + +let simplify_structure_coercion cc = + let rec is_identity_coercion pos = function + | [] -> + true + | (n, c) :: rem -> + n = pos && c = Tcoerce_none && is_identity_coercion (pos + 1) rem in + if is_identity_coercion 0 cc + then Tcoerce_none + else Tcoerce_structure cc + +(* Inclusion between module types. + Return the restriction that transforms a value of the smaller type + into a value of the bigger type. *) + +let rec modtypes env subst mty1 mty2 = + try + try_modtypes env subst mty1 mty2 + with + Dont_match -> + raise(Error[Module_types(mty1, Subst.modtype subst mty2)]) + | Error reasons -> + raise(Error(Module_types(mty1, Subst.modtype subst mty2) :: reasons)) + +and try_modtypes env subst mty1 mty2 = + match (mty1, mty2) with + (_, Tmty_ident p2) -> + try_modtypes2 env mty1 (Subst.modtype subst mty2) + | (Tmty_ident p1, _) -> + try_modtypes env subst (expand_module_path env p1) mty2 + | (Tmty_signature sig1, Tmty_signature sig2) -> + signatures env subst sig1 sig2 + | (Tmty_functor(param1, arg1, res1), Tmty_functor(param2, arg2, res2)) -> + let arg2' = Subst.modtype subst arg2 in + let cc_arg = modtypes env Subst.identity arg2' arg1 in + let cc_res = + modtypes (Env.add_module param1 arg2' env) + (Subst.add_module param2 (Pident param1) subst) res1 res2 in + begin match (cc_arg, cc_res) with + (Tcoerce_none, Tcoerce_none) -> Tcoerce_none + | _ -> Tcoerce_functor(cc_arg, cc_res) + end + | (_, _) -> + raise Dont_match + +and try_modtypes2 env mty1 mty2 = + (* mty2 is an identifier *) + match (mty1, mty2) with + (Tmty_ident p1, Tmty_ident p2) when Path.same p1 p2 -> + Tcoerce_none + | (_, Tmty_ident p2) -> + try_modtypes env Subst.identity mty1 (expand_module_path env p2) + | (_, _) -> + assert false + +(* Inclusion between signatures *) + +and signatures env subst sig1 sig2 = + (* Environment used to check inclusion of components *) + let new_env = + Env.add_signature sig1 env in + (* Build a table of the components of sig1, along with their positions. + The table is indexed by kind and name of component *) + let rec build_component_table pos tbl = function + [] -> tbl + | item :: rem -> + let (id, name) = item_ident_name item in + let nextpos = + match item with + Tsig_value(_,{val_kind = Val_prim _}) + | Tsig_type(_,_,_) + | Tsig_modtype(_,_) + | Tsig_cltype(_,_,_) -> pos + | Tsig_value(_,_) + | Tsig_exception(_,_) + | Tsig_module(_,_,_) + | Tsig_class(_, _,_) -> pos+1 in + build_component_table nextpos + (Tbl.add name (id, item, pos) tbl) rem in + let comps1 = + build_component_table 0 Tbl.empty sig1 in + (* Pair each component of sig2 with a component of sig1, + identifying the names along the way. + Return a coercion list indicating, for all run-time components + of sig2, the position of the matching run-time components of sig1 + and the coercion to be applied to it. *) + let rec pair_components subst paired unpaired = function + [] -> + begin match unpaired with + [] -> signature_components new_env subst (List.rev paired) + | _ -> raise(Error unpaired) + end + | item2 :: rem -> + let (id2, name2) = item_ident_name item2 in + let name2, report = + match item2, name2 with + Tsig_type (_, {type_manifest=None}, _), Field_type s + when let l = String.length s in + l >= 4 && String.sub s (l-4) 4 = "#row" -> + (* Do not report in case of failure, + as the main type will generate an error *) + Field_type (String.sub s 0 (String.length s - 4)), false + | _ -> name2, true + in + begin try + let (id1, item1, pos1) = Tbl.find name2 comps1 in + let new_subst = + match item2 with + Tsig_type _ -> + Subst.add_type id2 (Pident id1) subst + | Tsig_module _ -> + Subst.add_module id2 (Pident id1) subst + | Tsig_modtype _ -> + Subst.add_modtype id2 (Tmty_ident (Pident id1)) subst + | Tsig_value _ | Tsig_exception _ | Tsig_class _ | Tsig_cltype _ -> + subst + in + pair_components new_subst + ((item1, item2, pos1) :: paired) unpaired rem + with Not_found -> + let unpaired = + if report then Missing_field id2 :: unpaired else unpaired in + pair_components subst paired unpaired rem + end in + (* Do the pairing and checking, and return the final coercion *) + simplify_structure_coercion (pair_components subst [] [] sig2) + +(* Inclusion between signature components *) + +and signature_components env subst = function + [] -> [] + | (Tsig_value(id1, valdecl1), Tsig_value(id2, valdecl2), pos) :: rem -> + let cc = value_descriptions env subst id1 valdecl1 valdecl2 in + begin match valdecl2.val_kind with + Val_prim p -> signature_components env subst rem + | _ -> (pos, cc) :: signature_components env subst rem + end + | (Tsig_type(id1, tydecl1, _), Tsig_type(id2, tydecl2, _), pos) :: rem -> + type_declarations env subst id1 tydecl1 tydecl2; + signature_components env subst rem + | (Tsig_exception(id1, excdecl1), Tsig_exception(id2, excdecl2), pos) + :: rem -> + exception_declarations env subst id1 excdecl1 excdecl2; + (pos, Tcoerce_none) :: signature_components env subst rem + | (Tsig_module(id1, mty1, _), Tsig_module(id2, mty2, _), pos) :: rem -> + let cc = + modtypes env subst (Mtype.strengthen env mty1 (Pident id1)) mty2 in + (pos, cc) :: signature_components env subst rem + | (Tsig_modtype(id1, info1), Tsig_modtype(id2, info2), pos) :: rem -> + modtype_infos env subst id1 info1 info2; + signature_components env subst rem + | (Tsig_class(id1, decl1, _), Tsig_class(id2, decl2, _), pos) :: rem -> + class_declarations env subst id1 decl1 decl2; + (pos, Tcoerce_none) :: signature_components env subst rem + | (Tsig_cltype(id1, info1, _), Tsig_cltype(id2, info2, _), pos) :: rem -> + class_type_declarations env subst id1 info1 info2; + signature_components env subst rem + | _ -> + assert false + +(* Inclusion between module type specifications *) + +and modtype_infos env subst id info1 info2 = + let info2 = Subst.modtype_declaration subst info2 in + try + match (info1, info2) with + (Tmodtype_abstract, Tmodtype_abstract) -> () + | (Tmodtype_manifest mty1, Tmodtype_abstract) -> () + | (Tmodtype_manifest mty1, Tmodtype_manifest mty2) -> + check_modtype_equiv env mty1 mty2 + | (Tmodtype_abstract, Tmodtype_manifest mty2) -> + check_modtype_equiv env (Tmty_ident(Pident id)) mty2 + with Error reasons -> + raise(Error(Modtype_infos(id, info1, info2) :: reasons)) + +and check_modtype_equiv env mty1 mty2 = + match + (modtypes env Subst.identity mty1 mty2, + modtypes env Subst.identity mty2 mty1) + with + (Tcoerce_none, Tcoerce_none) -> () + | (_, _) -> raise(Error [Modtype_permutation]) + +(* Simplified inclusion check between module types (for Env) *) + +let check_modtype_inclusion env mty1 path1 mty2 = + try + ignore(modtypes env Subst.identity + (Mtype.strengthen env mty1 path1) mty2) + with Error reasons -> + raise Not_found + +let _ = Env.check_modtype_inclusion := check_modtype_inclusion + +(* Check that an implementation of a compilation unit meets its + interface. *) + +let compunit impl_name impl_sig intf_name intf_sig = + try + signatures Env.initial Subst.identity impl_sig intf_sig + with Error reasons -> + raise(Error(Interface_mismatch(impl_name, intf_name) :: reasons)) + +(* Hide the substitution parameter to the outside world *) + +let modtypes env mty1 mty2 = modtypes env Subst.identity mty1 mty2 +let signatures env sig1 sig2 = signatures env Subst.identity sig1 sig2 +let type_declarations env id decl1 decl2 = + type_declarations env Subst.identity id decl1 decl2 + +(* Error report *) + +open Format +open Printtyp + +let include_err ppf = function + | Missing_field id -> + fprintf ppf "The field `%a' is required but not provided" ident id + | Value_descriptions(id, d1, d2) -> + fprintf ppf + "@[<hv 2>Values do not match:@ \ + %a@;<1 -2>is not included in@ %a@]" + (value_description id) d1 (value_description id) d2 + | Type_declarations(id, d1, d2) -> + fprintf ppf + "@[<hv 2>Type declarations do not match:@ \ + %a@;<1 -2>is not included in@ %a@]" + (type_declaration id) d1 + (type_declaration id) d2 + | Exception_declarations(id, d1, d2) -> + fprintf ppf + "@[<hv 2>Exception declarations do not match:@ \ + %a@;<1 -2>is not included in@ %a@]" + (exception_declaration id) d1 + (exception_declaration id) d2 + | Module_types(mty1, mty2)-> + fprintf ppf + "@[<hv 2>Modules do not match:@ \ + %a@;<1 -2>is not included in@ %a@]" + modtype mty1 + modtype mty2 + | Modtype_infos(id, d1, d2) -> + fprintf ppf + "@[<hv 2>Module type declarations do not match:@ \ + %a@;<1 -2>does not match@ %a@]" + (modtype_declaration id) d1 + (modtype_declaration id) d2 + | Modtype_permutation -> + fprintf ppf "Illegal permutation of structure fields" + | Interface_mismatch(impl_name, intf_name) -> + fprintf ppf "@[The implementation %s@ does not match the interface %s:" + impl_name intf_name + | Class_type_declarations(id, d1, d2, reason) -> + fprintf ppf + "@[<hv 2>Class type declarations do not match:@ \ + %a@;<1 -2>does not match@ %a@]@ %a" + (Printtyp.cltype_declaration id) d1 + (Printtyp.cltype_declaration id) d2 + Includeclass.report_error reason + | Class_declarations(id, d1, d2, reason) -> + fprintf ppf + "@[<hv 2>Class declarations do not match:@ \ + %a@;<1 -2>does not match@ %a@]@ %a" + (Printtyp.class_declaration id) d1 + (Printtyp.class_declaration id) d2 + Includeclass.report_error reason + | Unbound_modtype_path path -> + fprintf ppf "Unbound module type %a" Printtyp.path path + +let report_error ppf = function + | [] -> () + | err :: errs -> + let print_errs ppf errs = + List.iter (fun err -> fprintf ppf "@ %a" include_err err) errs in + fprintf ppf "@[<v>%a%a@]" include_err err print_errs errs diff --git a/typing/includemod.mli b/typing/includemod.mli new file mode 100644 index 0000000..f49056f --- /dev/null +++ b/typing/includemod.mli @@ -0,0 +1,47 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: includemod.mli,v 1.13 2006-09-20 11:14:37 doligez Exp $ *) + +(* Inclusion checks for the module language *) + +open Types +open Typedtree +open Format + +val modtypes: Env.t -> module_type -> module_type -> module_coercion +val signatures: Env.t -> signature -> signature -> module_coercion +val compunit: string -> signature -> string -> signature -> module_coercion +val type_declarations: + Env.t -> Ident.t -> type_declaration -> type_declaration -> unit + +type error = + Missing_field of Ident.t + | Value_descriptions of Ident.t * value_description * value_description + | Type_declarations of Ident.t * type_declaration * type_declaration + | Exception_declarations of + Ident.t * exception_declaration * exception_declaration + | Module_types of module_type * module_type + | Modtype_infos of Ident.t * modtype_declaration * modtype_declaration + | Modtype_permutation + | Interface_mismatch of string * string + | Class_type_declarations of + Ident.t * cltype_declaration * cltype_declaration * + Ctype.class_match_failure list + | Class_declarations of + Ident.t * class_declaration * class_declaration * + Ctype.class_match_failure list + | Unbound_modtype_path of Path.t + +exception Error of error list + +val report_error: formatter -> error list -> unit diff --git a/typing/mtype.ml b/typing/mtype.ml new file mode 100644 index 0000000..abf0e6b --- /dev/null +++ b/typing/mtype.ml @@ -0,0 +1,213 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: mtype.ml,v 1.28 2007-10-19 13:25:21 garrigue Exp $ *) + +(* Operations on module types *) + +open Asttypes +open Path +open Types + + +let rec scrape env mty = + match mty with + Tmty_ident p -> + begin try + scrape env (Env.find_modtype_expansion p env) + with Not_found -> + mty + end + | _ -> mty + +let freshen mty = + Subst.modtype Subst.identity mty + +let rec strengthen env mty p = + match scrape env mty with + Tmty_signature sg -> + Tmty_signature(strengthen_sig env sg p) + | Tmty_functor(param, arg, res) -> + Tmty_functor(param, arg, strengthen env res (Papply(p, Pident param))) + | mty -> + mty + +and strengthen_sig env sg p = + match sg with + [] -> [] + | (Tsig_value(id, desc) as sigelt) :: rem -> + sigelt :: strengthen_sig env rem p + | Tsig_type(id, decl, rs) :: rem -> + let newdecl = + match decl.type_manifest with + Some ty when decl.type_private = Public -> decl + | _ -> + { decl with + type_private = Public; + type_manifest = + Some(Btype.newgenty(Tconstr(Pdot(p, Ident.name id, nopos), + decl.type_params, ref Mnil))) } + in + Tsig_type(id, newdecl, rs) :: strengthen_sig env rem p + | (Tsig_exception(id, d) as sigelt) :: rem -> + sigelt :: strengthen_sig env rem p + | Tsig_module(id, mty, rs) :: rem -> + Tsig_module(id, strengthen env mty (Pdot(p, Ident.name id, nopos)), rs) + :: strengthen_sig (Env.add_module id mty env) rem p + (* Need to add the module in case it defines manifest module types *) + | Tsig_modtype(id, decl) :: rem -> + let newdecl = + match decl with + Tmodtype_abstract -> + Tmodtype_manifest(Tmty_ident(Pdot(p, Ident.name id, nopos))) + | Tmodtype_manifest _ -> + decl in + Tsig_modtype(id, newdecl) :: + strengthen_sig (Env.add_modtype id decl env) rem p + (* Need to add the module type in case it is manifest *) + | (Tsig_class(id, decl, rs) as sigelt) :: rem -> + sigelt :: strengthen_sig env rem p + | (Tsig_cltype(id, decl, rs) as sigelt) :: rem -> + sigelt :: strengthen_sig env rem p + +(* In nondep_supertype, env is only used for the type it assigns to id. + Hence there is no need to keep env up-to-date by adding the bindings + traversed. *) + +type variance = Co | Contra | Strict + +let nondep_supertype env mid mty = + + let rec nondep_mty va mty = + match mty with + Tmty_ident p -> + if Path.isfree mid p then + nondep_mty va (Env.find_modtype_expansion p env) + else mty + | Tmty_signature sg -> + Tmty_signature(nondep_sig va sg) + | Tmty_functor(param, arg, res) -> + let var_inv = + match va with Co -> Contra | Contra -> Co | Strict -> Strict in + Tmty_functor(param, nondep_mty var_inv arg, nondep_mty va res) + + and nondep_sig va = function + [] -> [] + | item :: rem -> + let rem' = nondep_sig va rem in + match item with + Tsig_value(id, d) -> + Tsig_value(id, {val_type = Ctype.nondep_type env mid d.val_type; + val_kind = d.val_kind}) :: rem' + | Tsig_type(id, d, rs) -> + Tsig_type(id, Ctype.nondep_type_decl env mid id (va = Co) d, rs) + :: rem' + | Tsig_exception(id, d) -> + Tsig_exception(id, List.map (Ctype.nondep_type env mid) d) :: rem' + | Tsig_module(id, mty, rs) -> + Tsig_module(id, nondep_mty va mty, rs) :: rem' + | Tsig_modtype(id, d) -> + begin try + Tsig_modtype(id, nondep_modtype_decl d) :: rem' + with Not_found -> + match va with + Co -> Tsig_modtype(id, Tmodtype_abstract) :: rem' + | _ -> raise Not_found + end + | Tsig_class(id, d, rs) -> + Tsig_class(id, Ctype.nondep_class_declaration env mid d, rs) + :: rem' + | Tsig_cltype(id, d, rs) -> + Tsig_cltype(id, Ctype.nondep_cltype_declaration env mid d, rs) + :: rem' + + and nondep_modtype_decl = function + Tmodtype_abstract -> Tmodtype_abstract + | Tmodtype_manifest mty -> Tmodtype_manifest(nondep_mty Strict mty) + + in + nondep_mty Co mty + +let enrich_typedecl env p decl = + match decl.type_manifest with + Some ty -> decl + | None -> + try + let orig_decl = Env.find_type p env in + if orig_decl.type_arity <> decl.type_arity + then decl + else {decl with type_manifest = + Some(Btype.newgenty(Tconstr(p, decl.type_params, ref Mnil)))} + with Not_found -> + decl + +let rec enrich_modtype env p mty = + match mty with + Tmty_signature sg -> + Tmty_signature(List.map (enrich_item env p) sg) + | _ -> + mty + +and enrich_item env p = function + Tsig_type(id, decl, rs) -> + Tsig_type(id, + enrich_typedecl env (Pdot(p, Ident.name id, nopos)) decl, rs) + | Tsig_module(id, mty, rs) -> + Tsig_module(id, + enrich_modtype env (Pdot(p, Ident.name id, nopos)) mty, rs) + | item -> item + +let rec type_paths env p mty = + match scrape env mty with + Tmty_ident p -> [] + | Tmty_signature sg -> type_paths_sig env p 0 sg + | Tmty_functor(param, arg, res) -> [] + +and type_paths_sig env p pos sg = + match sg with + [] -> [] + | Tsig_value(id, decl) :: rem -> + let pos' = match decl.val_kind with Val_prim _ -> pos | _ -> pos + 1 in + type_paths_sig env p pos' rem + | Tsig_type(id, decl, _) :: rem -> + Pdot(p, Ident.name id, nopos) :: type_paths_sig env p pos rem + | Tsig_module(id, mty, _) :: rem -> + type_paths env (Pdot(p, Ident.name id, pos)) mty @ + type_paths_sig (Env.add_module id mty env) p (pos+1) rem + | Tsig_modtype(id, decl) :: rem -> + type_paths_sig (Env.add_modtype id decl env) p pos rem + | (Tsig_exception _ | Tsig_class _) :: rem -> + type_paths_sig env p (pos+1) rem + | (Tsig_cltype _) :: rem -> + type_paths_sig env p pos rem + +let rec no_code_needed env mty = + match scrape env mty with + Tmty_ident p -> false + | Tmty_signature sg -> no_code_needed_sig env sg + | Tmty_functor(_, _, _) -> false + +and no_code_needed_sig env sg = + match sg with + [] -> true + | Tsig_value(id, decl) :: rem -> + begin match decl.val_kind with + | Val_prim _ -> no_code_needed_sig env rem + | _ -> false + end + | Tsig_module(id, mty, _) :: rem -> + no_code_needed env mty && + no_code_needed_sig (Env.add_module id mty env) rem + | (Tsig_type _ | Tsig_modtype _ | Tsig_cltype _) :: rem -> + no_code_needed_sig env rem + | (Tsig_exception _ | Tsig_class _) :: rem -> + false diff --git a/typing/mtype.mli b/typing/mtype.mli new file mode 100644 index 0000000..9e177cf --- /dev/null +++ b/typing/mtype.mli @@ -0,0 +1,39 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: mtype.mli,v 1.10 2004-04-09 13:32:28 xleroy Exp $ *) + +(* Operations on module types *) + +open Types + +val scrape: Env.t -> module_type -> module_type + (* Expand toplevel module type abbreviations + till hitting a "hard" module type (signature, functor, + or abstract module type ident. *) +val freshen: module_type -> module_type + (* Return an alpha-equivalent copy of the given module type + where bound identifiers are fresh. *) +val strengthen: Env.t -> module_type -> Path.t -> module_type + (* Strengthen abstract type components relative to the + given path. *) +val nondep_supertype: Env.t -> Ident.t -> module_type -> module_type + (* Return the smallest supertype of the given type + in which the given ident does not appear. + Raise [Not_found] if no such type exists. *) +val no_code_needed: Env.t -> module_type -> bool +val no_code_needed_sig: Env.t -> signature -> bool + (* Determine whether a module needs no implementation code, + i.e. consists only of type definitions. *) +val enrich_modtype: Env.t -> Path.t -> module_type -> module_type +val enrich_typedecl: Env.t -> Path.t -> type_declaration -> type_declaration +val type_paths: Env.t -> Path.t -> module_type -> Path.t list diff --git a/typing/oprint.ml b/typing/oprint.ml new file mode 100644 index 0000000..d12a0ef --- /dev/null +++ b/typing/oprint.ml @@ -0,0 +1,461 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: oprint.ml,v 1.28 2008-12-03 18:09:09 doligez Exp $ *) + +open Format +open Outcometree + +exception Ellipsis + +let cautious f ppf arg = + try f ppf arg with + Ellipsis -> fprintf ppf "..." + +let rec print_ident ppf = + function + Oide_ident s -> fprintf ppf "%s" s + | Oide_dot (id, s) -> fprintf ppf "%a.%s" print_ident id s + | Oide_apply (id1, id2) -> + fprintf ppf "%a(%a)" print_ident id1 print_ident id2 + +let value_ident ppf name = + if List.mem name + ["or"; "mod"; "land"; "lor"; "lxor"; "lsl"; "lsr"; "asr"] then + fprintf ppf "( %s )" name + else + match name.[0] with + 'a'..'z' | '\223'..'\246' | '\248'..'\255' | '_' -> + fprintf ppf "%s" name + | _ -> fprintf ppf "( %s )" name + +(* Values *) + +let valid_float_lexeme s = + let l = String.length s in + let rec loop i = + if i >= l then s ^ "." else + match s.[i] with + | '0' .. '9' | '-' -> loop (i+1) + | _ -> s + in loop 0 + +let float_repres f = + match classify_float f with + FP_nan -> "nan" + | FP_infinite -> + if f < 0.0 then "neg_infinity" else "infinity" + | _ -> + let float_val = + let s1 = Printf.sprintf "%.12g" f in + if f = float_of_string s1 then s1 else + let s2 = Printf.sprintf "%.15g" f in + if f = float_of_string s2 then s2 else + Printf.sprintf "%.18g" f + in valid_float_lexeme float_val + +let parenthesize_if_neg ppf fmt v isneg = + if isneg then pp_print_char ppf '('; + fprintf ppf fmt v; + if isneg then pp_print_char ppf ')' + +let print_out_value ppf tree = + let rec print_tree_1 ppf = + function + | Oval_constr (name, [param]) -> + fprintf ppf "@[<1>%a@ %a@]" print_ident name print_constr_param param + | Oval_constr (name, (_ :: _ as params)) -> + fprintf ppf "@[<1>%a@ (%a)@]" print_ident name + (print_tree_list print_tree_1 ",") params + | Oval_variant (name, Some param) -> + fprintf ppf "@[<2>`%s@ %a@]" name print_constr_param param + | tree -> print_simple_tree ppf tree + and print_constr_param ppf = function + | Oval_int i -> parenthesize_if_neg ppf "%i" i (i < 0) + | Oval_int32 i -> parenthesize_if_neg ppf "%lil" i (i < 0l) + | Oval_int64 i -> parenthesize_if_neg ppf "%LiL" i (i < 0L) + | Oval_nativeint i -> parenthesize_if_neg ppf "%nin" i (i < 0n) + | Oval_float f -> parenthesize_if_neg ppf "%s" (float_repres f) (f < 0.0) + | tree -> print_simple_tree ppf tree + and print_simple_tree ppf = + function + Oval_int i -> fprintf ppf "%i" i + | Oval_int32 i -> fprintf ppf "%lil" i + | Oval_int64 i -> fprintf ppf "%LiL" i + | Oval_nativeint i -> fprintf ppf "%nin" i + | Oval_float f -> fprintf ppf "%s" (float_repres f) + | Oval_char c -> fprintf ppf "%C" c + | Oval_string s -> + begin try fprintf ppf "%S" s with + Invalid_argument "String.create" -> fprintf ppf "<huge string>" + end + | Oval_list tl -> + fprintf ppf "@[<1>[%a]@]" (print_tree_list print_tree_1 ";") tl + | Oval_array tl -> + fprintf ppf "@[<2>[|%a|]@]" (print_tree_list print_tree_1 ";") tl + | Oval_constr (name, []) -> print_ident ppf name + | Oval_variant (name, None) -> fprintf ppf "`%s" name + | Oval_stuff s -> fprintf ppf "%s" s + | Oval_record fel -> + fprintf ppf "@[<1>{%a}@]" (cautious (print_fields true)) fel + | Oval_ellipsis -> raise Ellipsis + | Oval_printer f -> f ppf + | Oval_tuple tree_list -> + fprintf ppf "@[<1>(%a)@]" (print_tree_list print_tree_1 ",") tree_list + | tree -> fprintf ppf "@[<1>(%a)@]" (cautious print_tree_1) tree + and print_fields first ppf = + function + [] -> () + | (name, tree) :: fields -> + if not first then fprintf ppf ";@ "; + fprintf ppf "@[<1>%a@ =@ %a@]" print_ident name (cautious print_tree_1) + tree; + print_fields false ppf fields + and print_tree_list print_item sep ppf tree_list = + let rec print_list first ppf = + function + [] -> () + | tree :: tree_list -> + if not first then fprintf ppf "%s@ " sep; + print_item ppf tree; + print_list false ppf tree_list + in + cautious (print_list true) ppf tree_list + in + cautious print_tree_1 ppf tree + +let out_value = ref print_out_value + +(* Types *) + +let rec print_list_init pr sep ppf = + function + [] -> () + | a :: l -> sep ppf; pr ppf a; print_list_init pr sep ppf l + +let rec print_list pr sep ppf = + function + [] -> () + | [a] -> pr ppf a + | a :: l -> pr ppf a; sep ppf; print_list pr sep ppf l + +let pr_present = + print_list (fun ppf s -> fprintf ppf "`%s" s) (fun ppf -> fprintf ppf "@ ") + +let pr_vars = + print_list (fun ppf s -> fprintf ppf "'%s" s) (fun ppf -> fprintf ppf "@ ") + +let rec print_out_type ppf = + function + | Otyp_alias (ty, s) -> + fprintf ppf "@[%a@ as '%s@]" print_out_type ty s + | Otyp_poly (sl, ty) -> + fprintf ppf "@[<hov 2>%a.@ %a@]" + pr_vars sl + print_out_type ty + | ty -> + print_out_type_1 ppf ty + +and print_out_type_1 ppf = + function + Otyp_arrow (lab, ty1, ty2) -> + fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "") + print_out_type_2 ty1 print_out_type_1 ty2 + | ty -> print_out_type_2 ppf ty +and print_out_type_2 ppf = + function + Otyp_tuple tyl -> + fprintf ppf "@[<0>%a@]" (print_typlist print_simple_out_type " *") tyl + | ty -> print_simple_out_type ppf ty +and print_simple_out_type ppf = + function + Otyp_class (ng, id, tyl) -> + fprintf ppf "@[%a%s#%a@]" print_typargs tyl (if ng then "_" else "") + print_ident id + | Otyp_constr (id, tyl) -> + fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id + | Otyp_object (fields, rest) -> + fprintf ppf "@[<2>< %a >@]" (print_fields rest) fields + | Otyp_stuff s -> fprintf ppf "%s" s + | Otyp_var (ng, s) -> fprintf ppf "'%s%s" (if ng then "_" else "") s + | Otyp_variant (non_gen, row_fields, closed, tags) -> + let print_present ppf = + function + None | Some [] -> () + | Some l -> fprintf ppf "@;<1 -2>> @[<hov>%a@]" pr_present l + in + let print_fields ppf = + function + Ovar_fields fields -> + print_list print_row_field (fun ppf -> fprintf ppf "@;<1 -2>| ") + ppf fields + | Ovar_name (id, tyl) -> + fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id + in + fprintf ppf "%s[%s@[<hv>@[<hv>%a@]%a ]@]" (if non_gen then "_" else "") + (if closed then if tags = None then " " else "< " + else if tags = None then "> " else "? ") + print_fields row_fields + print_present tags + | Otyp_alias _ | Otyp_poly _ | Otyp_arrow _ | Otyp_tuple _ as ty -> + fprintf ppf "@[<1>(%a)@]" print_out_type ty + | Otyp_abstract | Otyp_sum _ | Otyp_record _ | Otyp_manifest (_, _) -> () +and print_fields rest ppf = + function + [] -> + begin match rest with + Some non_gen -> fprintf ppf "%s.." (if non_gen then "_" else "") + | None -> () + end + | [s, t] -> + fprintf ppf "%s : %a" s print_out_type t; + begin match rest with + Some _ -> fprintf ppf ";@ " + | None -> () + end; + print_fields rest ppf [] + | (s, t) :: l -> + fprintf ppf "%s : %a;@ %a" s print_out_type t (print_fields rest) l +and print_row_field ppf (l, opt_amp, tyl) = + let pr_of ppf = + if opt_amp then fprintf ppf " of@ &@ " + else if tyl <> [] then fprintf ppf " of@ " + else fprintf ppf "" + in + fprintf ppf "@[<hv 2>`%s%t%a@]" l pr_of (print_typlist print_out_type " &") + tyl +and print_typlist print_elem sep ppf = + function + [] -> () + | [ty] -> print_elem ppf ty + | ty :: tyl -> + fprintf ppf "%a%s@ %a" print_elem ty sep (print_typlist print_elem sep) + tyl +and print_typargs ppf = + function + [] -> () + | [ty1] -> fprintf ppf "%a@ " print_simple_out_type ty1 + | tyl -> fprintf ppf "@[<1>(%a)@]@ " (print_typlist print_out_type ",") tyl + +let out_type = ref print_out_type + +(* Class types *) + +let type_parameter ppf (ty, (co, cn)) = + fprintf ppf "%s'%s" (if not cn then "+" else if not co then "-" else "") + (*if co then if cn then "!" else "+" else if cn then "-" else "?"*) + ty + +let print_out_class_params ppf = + function + [] -> () + | tyl -> + fprintf ppf "@[<1>[%a]@]@ " + (print_list type_parameter (fun ppf -> fprintf ppf ", ")) + tyl + +let rec print_out_class_type ppf = + function + Octy_constr (id, tyl) -> + let pr_tyl ppf = + function + [] -> () + | tyl -> + fprintf ppf "@[<1>[%a]@]@ " (print_typlist !out_type ",") tyl + in + fprintf ppf "@[%a%a@]" pr_tyl tyl print_ident id + | Octy_fun (lab, ty, cty) -> + fprintf ppf "@[%s%a ->@ %a@]" (if lab <> "" then lab ^ ":" else "") + print_out_type_2 ty print_out_class_type cty + | Octy_signature (self_ty, csil) -> + let pr_param ppf = + function + Some ty -> fprintf ppf "@ @[(%a)@]" !out_type ty + | None -> () + in + fprintf ppf "@[<hv 2>@[<2>object%a@]@ %a@;<1 -2>end@]" pr_param self_ty + (print_list print_out_class_sig_item (fun ppf -> fprintf ppf "@ ")) + csil +and print_out_class_sig_item ppf = + function + Ocsg_constraint (ty1, ty2) -> + fprintf ppf "@[<2>constraint %a =@ %a@]" !out_type ty1 + !out_type ty2 + | Ocsg_method (name, priv, virt, ty) -> + fprintf ppf "@[<2>method %s%s%s :@ %a@]" + (if priv then "private " else "") (if virt then "virtual " else "") + name !out_type ty + | Ocsg_value (name, mut, vr, ty) -> + fprintf ppf "@[<2>val %s%s%s :@ %a@]" + (if mut then "mutable " else "") + (if vr then "virtual " else "") + name !out_type ty + +let out_class_type = ref print_out_class_type + +(* Signature *) + +let out_module_type = ref (fun _ -> failwith "Oprint.out_module_type") +let out_sig_item = ref (fun _ -> failwith "Oprint.out_sig_item") +let out_signature = ref (fun _ -> failwith "Oprint.out_signature") + +let rec print_out_module_type ppf = + function + Omty_abstract -> () + | Omty_functor (name, mty_arg, mty_res) -> + fprintf ppf "@[<2>functor@ (%s : %a) ->@ %a@]" name + print_out_module_type mty_arg print_out_module_type mty_res + | Omty_ident id -> fprintf ppf "%a" print_ident id + | Omty_signature sg -> + fprintf ppf "@[<hv 2>sig@ %a@;<1 -2>end@]" !out_signature sg +and print_out_signature ppf = + function + [] -> () + | [item] -> !out_sig_item ppf item + | item :: items -> + fprintf ppf "%a@ %a" !out_sig_item item print_out_signature items +and print_out_sig_item ppf = + function + Osig_class (vir_flag, name, params, clt, rs) -> + fprintf ppf "@[<2>%s%s@ %a%s@ :@ %a@]" + (if rs = Orec_next then "and" else "class") + (if vir_flag then " virtual" else "") print_out_class_params params + name !out_class_type clt + | Osig_class_type (vir_flag, name, params, clt, rs) -> + fprintf ppf "@[<2>%s%s@ %a%s@ =@ %a@]" + (if rs = Orec_next then "and" else "class type") + (if vir_flag then " virtual" else "") print_out_class_params params + name !out_class_type clt + | Osig_exception (id, tyl) -> + fprintf ppf "@[<2>exception %a@]" print_out_constr (id, tyl) + | Osig_modtype (name, Omty_abstract) -> + fprintf ppf "@[<2>module type %s@]" name + | Osig_modtype (name, mty) -> + fprintf ppf "@[<2>module type %s =@ %a@]" name !out_module_type mty + | Osig_module (name, mty, rs) -> + fprintf ppf "@[<2>%s %s :@ %a@]" + (match rs with Orec_not -> "module" + | Orec_first -> "module rec" + | Orec_next -> "and") + name !out_module_type mty + | Osig_type(td, rs) -> + print_out_type_decl + (if rs = Orec_next then "and" else "type") + ppf td + | Osig_value (name, ty, prims) -> + let kwd = if prims = [] then "val" else "external" in + let pr_prims ppf = + function + [] -> () + | s :: sl -> + fprintf ppf "@ = \"%s\"" s; + List.iter (fun s -> fprintf ppf "@ \"%s\"" s) sl + in + fprintf ppf "@[<2>%s %a :@ %a%a@]" kwd value_ident name !out_type + ty pr_prims prims + +and print_out_type_decl kwd ppf (name, args, ty, priv, constraints) = + let print_constraints ppf params = + List.iter + (fun (ty1, ty2) -> + fprintf ppf "@ @[<2>constraint %a =@ %a@]" !out_type ty1 + !out_type ty2) + params + in + let type_defined ppf = + match args with + [] -> fprintf ppf "%s" name + | [arg] -> fprintf ppf "@[%a@ %s@]" type_parameter arg name + | _ -> + fprintf ppf "@[(@[%a)@]@ %s@]" + (print_list type_parameter (fun ppf -> fprintf ppf ",@ ")) args name + in + let print_manifest ppf = + function + Otyp_manifest (ty, _) -> fprintf ppf " =@ %a" !out_type ty + | _ -> () + in + let print_name_args ppf = + fprintf ppf "%s %t%a" kwd type_defined print_manifest ty + in + let ty = + match ty with + Otyp_manifest (_, ty) -> ty + | _ -> ty + in + let print_private ppf = function + Asttypes.Private -> fprintf ppf " private" + | Asttypes.Public -> () in + let rec print_out_tkind ppf = function + | Otyp_abstract -> () + | Otyp_record lbls -> + fprintf ppf " =%a {%a@;<1 -2>}" + print_private priv + (print_list_init print_out_label (fun ppf -> fprintf ppf "@ ")) lbls + | Otyp_sum constrs -> + fprintf ppf " =%a@;<1 2>%a" + print_private priv + (print_list print_out_constr (fun ppf -> fprintf ppf "@ | ")) constrs + | ty -> + fprintf ppf " =%a@;<1 2>%a" + print_private priv + !out_type ty + in + fprintf ppf "@[<2>@[<hv 2>%t%a@]%a@]" + print_name_args + print_out_tkind ty + print_constraints constraints +and print_out_constr ppf (name, tyl) = + match tyl with + [] -> fprintf ppf "%s" name + | _ -> + fprintf ppf "@[<2>%s of@ %a@]" name + (print_typlist print_simple_out_type " *") tyl +and print_out_label ppf (name, mut, arg) = + fprintf ppf "@[<2>%s%s :@ %a@];" (if mut then "mutable " else "") name + !out_type arg + +let _ = out_module_type := print_out_module_type +let _ = out_signature := print_out_signature +let _ = out_sig_item := print_out_sig_item + +(* Phrases *) + +let print_out_exception ppf exn outv = + match exn with + Sys.Break -> fprintf ppf "Interrupted.@." + | Out_of_memory -> fprintf ppf "Out of memory during evaluation.@." + | Stack_overflow -> + fprintf ppf "Stack overflow during evaluation (looping recursion?).@." + | _ -> fprintf ppf "@[Exception:@ %a.@]@." !out_value outv + +let rec print_items ppf = + function + [] -> () + | (tree, valopt) :: items -> + begin match valopt with + Some v -> + fprintf ppf "@[<2>%a =@ %a@]" !out_sig_item tree + !out_value v + | None -> fprintf ppf "@[%a@]" !out_sig_item tree + end; + if items <> [] then fprintf ppf "@ %a" print_items items + +let print_out_phrase ppf = + function + Ophr_eval (outv, ty) -> + fprintf ppf "@[- : %a@ =@ %a@]@." !out_type ty !out_value outv + | Ophr_signature [] -> () + | Ophr_signature items -> fprintf ppf "@[<v>%a@]@." print_items items + | Ophr_exception (exn, outv) -> print_out_exception ppf exn outv + +let out_phrase = ref print_out_phrase diff --git a/typing/oprint.mli b/typing/oprint.mli new file mode 100644 index 0000000..63ae8f9 --- /dev/null +++ b/typing/oprint.mli @@ -0,0 +1,24 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: oprint.mli,v 1.2 2002-04-18 07:27:45 garrigue Exp $ *) + +open Format +open Outcometree + +val out_value : (formatter -> out_value -> unit) ref +val out_type : (formatter -> out_type -> unit) ref +val out_class_type : (formatter -> out_class_type -> unit) ref +val out_module_type : (formatter -> out_module_type -> unit) ref +val out_sig_item : (formatter -> out_sig_item -> unit) ref +val out_signature : (formatter -> out_sig_item list -> unit) ref +val out_phrase : (formatter -> out_phrase -> unit) ref diff --git a/typing/outcometree.mli b/typing/outcometree.mli new file mode 100644 index 0000000..08ebcbf --- /dev/null +++ b/typing/outcometree.mli @@ -0,0 +1,104 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: outcometree.mli,v 1.15 2006-04-05 02:28:13 garrigue Exp $ *) + +(* Module [Outcometree]: results displayed by the toplevel *) + +(* These types represent messages that the toplevel displays as normal + results or errors. The real displaying is customisable using the hooks: + [Toploop.print_out_value] + [Toploop.print_out_type] + [Toploop.print_out_sig_item] + [Toploop.print_out_phrase] *) + +type out_ident = + | Oide_apply of out_ident * out_ident + | Oide_dot of out_ident * string + | Oide_ident of string + +type out_value = + | Oval_array of out_value list + | Oval_char of char + | Oval_constr of out_ident * out_value list + | Oval_ellipsis + | Oval_float of float + | Oval_int of int + | Oval_int32 of int32 + | Oval_int64 of int64 + | Oval_nativeint of nativeint + | Oval_list of out_value list + | Oval_printer of (Format.formatter -> unit) + | Oval_record of (out_ident * out_value) list + | Oval_string of string + | Oval_stuff of string + | Oval_tuple of out_value list + | Oval_variant of string * out_value option + +type out_type = + | Otyp_abstract + | Otyp_alias of out_type * string + | Otyp_arrow of string * out_type * out_type + | Otyp_class of bool * out_ident * out_type list + | Otyp_constr of out_ident * out_type list + | Otyp_manifest of out_type * out_type + | Otyp_object of (string * out_type) list * bool option + | Otyp_record of (string * bool * out_type) list + | Otyp_stuff of string + | Otyp_sum of (string * out_type list) list + | Otyp_tuple of out_type list + | Otyp_var of bool * string + | Otyp_variant of + bool * out_variant * bool * (string list) option + | Otyp_poly of string list * out_type +and out_variant = + | Ovar_fields of (string * bool * out_type list) list + | Ovar_name of out_ident * out_type list + +type out_class_type = + | Octy_constr of out_ident * out_type list + | Octy_fun of string * out_type * out_class_type + | Octy_signature of out_type option * out_class_sig_item list +and out_class_sig_item = + | Ocsg_constraint of out_type * out_type + | Ocsg_method of string * bool * bool * out_type + | Ocsg_value of string * bool * bool * out_type + +type out_module_type = + | Omty_abstract + | Omty_functor of string * out_module_type * out_module_type + | Omty_ident of out_ident + | Omty_signature of out_sig_item list +and out_sig_item = + | Osig_class of + bool * string * (string * (bool * bool)) list * out_class_type * + out_rec_status + | Osig_class_type of + bool * string * (string * (bool * bool)) list * out_class_type * + out_rec_status + | Osig_exception of string * out_type list + | Osig_modtype of string * out_module_type + | Osig_module of string * out_module_type * out_rec_status + | Osig_type of out_type_decl * out_rec_status + | Osig_value of string * out_type * string list +and out_type_decl = + string * (string * (bool * bool)) list * out_type * Asttypes.private_flag * + (out_type * out_type) list +and out_rec_status = + | Orec_not + | Orec_first + | Orec_next + +type out_phrase = + | Ophr_eval of out_value * out_type + | Ophr_signature of (out_sig_item * out_value option) list + | Ophr_exception of (exn * out_value) diff --git a/typing/parmatch.ml b/typing/parmatch.ml new file mode 100644 index 0000000..9bce923 --- /dev/null +++ b/typing/parmatch.ml @@ -0,0 +1,1712 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parmatch.ml,v 1.76 2008-07-15 18:11:46 mauny Exp $ *) + +(* Detection of partial matches and unused match cases. *) + +open Misc +open Asttypes +open Types +open Typedtree + +(*************************************) +(* Utilities for building patterns *) +(*************************************) + +let make_pat desc ty tenv = + {pat_desc = desc; pat_loc = Location.none; + pat_type = ty ; pat_env = tenv } + +let omega = make_pat Tpat_any Ctype.none Env.empty + +let extra_pat = + make_pat (Tpat_var (Ident.create "+")) Ctype.none Env.empty + +let rec omegas i = + if i <= 0 then [] else omega :: omegas (i-1) + +let omega_list l = List.map (fun _ -> omega) l + +let zero = make_pat (Tpat_constant (Const_int 0)) Ctype.none Env.empty + +(***********************) +(* Compatibility check *) +(***********************) + +(* p and q compatible means, there exists V that matches both *) + +let is_absent tag row = Btype.row_field tag !row = Rabsent + +let is_absent_pat p = match p.pat_desc with +| Tpat_variant (tag, _, row) -> is_absent tag row +| _ -> false + +let sort_fields args = + Sort.list + (fun (lbl1,_) (lbl2,_) -> lbl1.lbl_pos <= lbl2.lbl_pos) + args + +let records_args l1 l2 = + let l1 = sort_fields l1 + and l2 = sort_fields l2 in + let rec combine r1 r2 l1 l2 = match l1,l2 with + | [],[] -> r1,r2 + | [],(_,p2)::rem2 -> combine (omega::r1) (p2::r2) [] rem2 + | (_,p1)::rem1,[] -> combine (p1::r1) (omega::r2) rem1 [] + | (lbl1,p1)::rem1, (lbl2,p2)::rem2 -> + if lbl1.lbl_pos < lbl2.lbl_pos then + combine (p1::r1) (omega::r2) rem1 l2 + else if lbl1.lbl_pos > lbl2.lbl_pos then + combine (omega::r1) (p2::r2) l1 rem2 + else (* same label on both sides *) + combine (p1::r1) (p2::r2) rem1 rem2 in + combine [] [] l1 l2 + + +let rec compat p q = + match p.pat_desc,q.pat_desc with + | Tpat_alias (p,_),_ -> compat p q + | _,Tpat_alias (q,_) -> compat p q + | (Tpat_any|Tpat_var _),_ -> true + | _,(Tpat_any|Tpat_var _) -> true + | Tpat_or (p1,p2,_),_ -> compat p1 q || compat p2 q + | _,Tpat_or (q1,q2,_) -> compat p q1 || compat p q2 + | Tpat_constant c1, Tpat_constant c2 -> c1=c2 + | Tpat_tuple ps, Tpat_tuple qs -> compats ps qs + | Tpat_lazy p, Tpat_lazy q -> compat p q + | Tpat_construct (c1,ps1), Tpat_construct (c2,ps2) -> + c1.cstr_tag = c2.cstr_tag && compats ps1 ps2 + | Tpat_variant(l1,Some p1, r1), Tpat_variant(l2,Some p2,_) -> + l1=l2 && compat p1 p2 + | Tpat_variant (l1,None,r1), Tpat_variant(l2,None,_) -> + l1 = l2 + | Tpat_variant (_, None, _), Tpat_variant (_,Some _, _) -> false + | Tpat_variant (_, Some _, _), Tpat_variant (_, None, _) -> false + | Tpat_record l1,Tpat_record l2 -> + let ps,qs = records_args l1 l2 in + compats ps qs + | Tpat_array ps, Tpat_array qs -> + List.length ps = List.length qs && + compats ps qs + | _,_ -> + assert false + +and compats ps qs = match ps,qs with +| [], [] -> true +| p::ps, q::qs -> compat p q && compats ps qs +| _,_ -> assert false + +(****************************************) +(* Utilities for retrieving constructor *) +(* and record label names *) +(****************************************) + +exception Empty (* Empty pattern *) + +let get_type_path ty tenv = + let ty = Ctype.repr (Ctype.expand_head tenv ty) in + match ty.desc with + | Tconstr (path,_,_) -> path + | _ -> fatal_error "Parmatch.get_type_path" + +let get_type_descr ty tenv = + match (Ctype.repr ty).desc with + | Tconstr (path,_,_) -> Env.find_type path tenv + | _ -> fatal_error "Parmatch.get_type_descr" + +let rec get_constr tag ty tenv = + match get_type_descr ty tenv with + | {type_kind=Type_variant constr_list} -> + Datarepr.find_constr_by_tag tag constr_list + | {type_manifest = Some _} -> + get_constr tag (Ctype.expand_head_once tenv ty) tenv + | _ -> fatal_error "Parmatch.get_constr" + +let find_label lbl lbls = + try + let name,_,_ = List.nth lbls lbl.lbl_pos in + name + with Failure "nth" -> "*Unkown label*" + +let rec get_record_labels ty tenv = + match get_type_descr ty tenv with + | {type_kind = Type_record(lbls, rep)} -> lbls + | {type_manifest = Some _} -> + get_record_labels (Ctype.expand_head_once tenv ty) tenv + | _ -> fatal_error "Parmatch.get_record_labels" + + +(*************************************) +(* Values as patterns pretty printer *) +(*************************************) + +open Format +;; + +let get_constr_name tag ty tenv = match tag with +| Cstr_exception path -> Path.name path +| _ -> + try + let name,_ = get_constr tag ty tenv in name + with + | Datarepr.Constr_not_found -> "*Unknown constructor*" + +let is_cons tag v = match get_constr_name tag v.pat_type v.pat_env with +| "::" -> true +| _ -> false + + +let rec pretty_val ppf v = match v.pat_desc with + | Tpat_any -> fprintf ppf "_" + | Tpat_var x -> Ident.print ppf x + | Tpat_constant (Const_int i) -> fprintf ppf "%d" i + | Tpat_constant (Const_char c) -> fprintf ppf "%C" c + | Tpat_constant (Const_string s) -> fprintf ppf "%S" s + | Tpat_constant (Const_float f) -> fprintf ppf "%s" f + | Tpat_constant (Const_int32 i) -> fprintf ppf "%ldl" i + | Tpat_constant (Const_int64 i) -> fprintf ppf "%LdL" i + | Tpat_constant (Const_nativeint i) -> fprintf ppf "%ndn" i + | Tpat_tuple vs -> + fprintf ppf "@[(%a)@]" (pretty_vals ",") vs + | Tpat_construct ({cstr_tag=tag},[]) -> + let name = get_constr_name tag v.pat_type v.pat_env in + fprintf ppf "%s" name + | Tpat_construct ({cstr_tag=tag},[w]) -> + let name = get_constr_name tag v.pat_type v.pat_env in + fprintf ppf "@[<2>%s@ %a@]" name pretty_arg w + | Tpat_construct ({cstr_tag=tag},vs) -> + let name = get_constr_name tag v.pat_type v.pat_env in + begin match (name, vs) with + ("::", [v1;v2]) -> + fprintf ppf "@[%a::@,%a@]" pretty_car v1 pretty_cdr v2 + | _ -> + fprintf ppf "@[<2>%s@ @[(%a)@]@]" name (pretty_vals ",") vs + end + | Tpat_variant (l, None, _) -> + fprintf ppf "`%s" l + | Tpat_variant (l, Some w, _) -> + fprintf ppf "@[<2>`%s@ %a@]" l pretty_arg w + | Tpat_record lvs -> + fprintf ppf "@[{%a}@]" + (pretty_lvals (get_record_labels v.pat_type v.pat_env)) + (List.filter + (function + | (_,{pat_desc=Tpat_any}) -> false (* do not show lbl=_ *) + | _ -> true) lvs) + | Tpat_array vs -> + fprintf ppf "@[[| %a |]@]" (pretty_vals " ;") vs + | Tpat_lazy v -> + fprintf ppf "@[<2>lazy@ %a@]" pretty_arg v + | Tpat_alias (v,x) -> + fprintf ppf "@[(%a@ as %a)@]" pretty_val v Ident.print x + | Tpat_or (v,w,_) -> + fprintf ppf "@[(%a|@,%a)@]" pretty_or v pretty_or w + +and pretty_car ppf v = match v.pat_desc with +| Tpat_construct ({cstr_tag=tag}, [_ ; _]) + when is_cons tag v -> + fprintf ppf "(%a)" pretty_val v +| _ -> pretty_val ppf v + +and pretty_cdr ppf v = match v.pat_desc with +| Tpat_construct ({cstr_tag=tag}, [v1 ; v2]) + when is_cons tag v -> + fprintf ppf "%a::@,%a" pretty_car v1 pretty_cdr v2 +| _ -> pretty_val ppf v + +and pretty_arg ppf v = match v.pat_desc with +| Tpat_construct (_,_::_) -> fprintf ppf "(%a)" pretty_val v +| _ -> pretty_val ppf v + +and pretty_or ppf v = match v.pat_desc with +| Tpat_or (v,w,_) -> + fprintf ppf "%a|@,%a" pretty_or v pretty_or w +| _ -> pretty_val ppf v + +and pretty_vals sep ppf = function + | [] -> () + | [v] -> pretty_val ppf v + | v::vs -> + fprintf ppf "%a%s@ %a" pretty_val v sep (pretty_vals sep) vs + +and pretty_lvals lbls ppf = function + | [] -> () + | [lbl,v] -> + let name = find_label lbl lbls in + fprintf ppf "%s=%a" name pretty_val v + | (lbl,v)::rest -> + let name = find_label lbl lbls in + fprintf ppf "%s=%a;@ %a" name pretty_val v (pretty_lvals lbls) rest + +let top_pretty ppf v = + fprintf ppf "@[%a@]@?" pretty_val v + + +let prerr_pat v = + top_pretty str_formatter v ; + prerr_string (flush_str_formatter ()) + + +(****************************) +(* Utilities for matching *) +(****************************) + +(* Check top matching *) +let simple_match p1 p2 = + match p1.pat_desc, p2.pat_desc with + | Tpat_construct(c1, _), Tpat_construct(c2, _) -> + c1.cstr_tag = c2.cstr_tag + | Tpat_variant(l1, _, _), Tpat_variant(l2, _, _) -> + l1 = l2 + | Tpat_constant(Const_float s1), Tpat_constant(Const_float s2) -> + float_of_string s1 = float_of_string s2 + | Tpat_constant(c1), Tpat_constant(c2) -> c1 = c2 + | Tpat_tuple _, Tpat_tuple _ -> true + | Tpat_lazy _, Tpat_lazy _ -> true + | Tpat_record _ , Tpat_record _ -> true + | Tpat_array p1s, Tpat_array p2s -> List.length p1s = List.length p2s + | _, (Tpat_any | Tpat_var(_)) -> true + | _, _ -> false + + + + +(* extract record fields as a whole *) +let record_arg p = match p.pat_desc with +| Tpat_any -> [] +| Tpat_record args -> args +| _ -> fatal_error "Parmatch.as_record" + + +(* Raise Not_found when pos is not present in arg *) + + +let get_field pos arg = + let _,p = List.find (fun (lbl,_) -> pos = lbl.lbl_pos) arg in + p + + +let extract_fields omegas arg = + List.map + (fun (lbl,_) -> + try + get_field lbl.lbl_pos arg + with Not_found -> omega) + omegas + + + +let sort_record p = match p.pat_desc with +| Tpat_record args -> + make_pat + (Tpat_record (sort_fields args)) + p.pat_type p.pat_env +| _ -> p + +let all_record_args lbls = match lbls with +| ({lbl_all=lbl_all},_)::_ -> + let t = + Array.map + (fun lbl -> lbl,omega) lbl_all in + List.iter + (fun ((lbl,_) as x) -> t.(lbl.lbl_pos) <- x) + lbls ; + Array.to_list t +| _ -> fatal_error "Parmatch.all_record_args" + + +(* Build argument list when p2 >= p1, where p1 is a simple pattern *) +let rec simple_match_args p1 p2 = match p2.pat_desc with +| Tpat_alias (p2,_) -> simple_match_args p1 p2 +| Tpat_construct(cstr, args) -> args +| Tpat_variant(lab, Some arg, _) -> [arg] +| Tpat_tuple(args) -> args +| Tpat_record(args) -> extract_fields (record_arg p1) args +| Tpat_array(args) -> args +| Tpat_lazy arg -> [arg] +| (Tpat_any | Tpat_var(_)) -> + begin match p1.pat_desc with + Tpat_construct(_, args) -> omega_list args + | Tpat_variant(_, Some _, _) -> [omega] + | Tpat_tuple(args) -> omega_list args + | Tpat_record(args) -> omega_list args + | Tpat_array(args) -> omega_list args + | Tpat_lazy _ -> [omega] + | _ -> [] + end +| _ -> [] + +(* + Normalize a pattern -> + all arguments are omega (simple pattern) and no more variables +*) + +let rec normalize_pat q = match q.pat_desc with + | Tpat_any | Tpat_constant _ -> q + | Tpat_var _ -> make_pat Tpat_any q.pat_type q.pat_env + | Tpat_alias (p,_) -> normalize_pat p + | Tpat_tuple (args) -> + make_pat (Tpat_tuple (omega_list args)) q.pat_type q.pat_env + | Tpat_construct (c,args) -> + make_pat (Tpat_construct (c,omega_list args)) q.pat_type q.pat_env + | Tpat_variant (l, arg, row) -> + make_pat (Tpat_variant (l, may_map (fun _ -> omega) arg, row)) + q.pat_type q.pat_env + | Tpat_array (args) -> + make_pat (Tpat_array (omega_list args)) q.pat_type q.pat_env + | Tpat_record (largs) -> + make_pat (Tpat_record (List.map (fun (lbl,_) -> lbl,omega) largs)) + q.pat_type q.pat_env + | Tpat_lazy _ -> + make_pat (Tpat_lazy omega) q.pat_type q.pat_env + | Tpat_or _ -> fatal_error "Parmatch.normalize_pat" + + +(* + Build normalized (cf. supra) discriminating pattern, + in the non-data type case +*) + +let discr_pat q pss = + + let rec acc_pat acc pss = match pss with + ({pat_desc = Tpat_alias (p,_)}::ps)::pss -> + acc_pat acc ((p::ps)::pss) + | ({pat_desc = Tpat_or (p1,p2,_)}::ps)::pss -> + acc_pat acc ((p1::ps)::(p2::ps)::pss) + | ({pat_desc = (Tpat_any | Tpat_var _)}::_)::pss -> + acc_pat acc pss + | (({pat_desc = Tpat_tuple _} as p)::_)::_ -> normalize_pat p + | (({pat_desc = Tpat_lazy _} as p)::_)::_ -> normalize_pat p + | (({pat_desc = Tpat_record largs} as p)::_)::pss -> + let new_omegas = + List.fold_left + (fun r (lbl,_) -> + try + let _ = get_field lbl.lbl_pos r in + r + with Not_found -> + (lbl,omega)::r) + (record_arg acc) + largs in + acc_pat + (make_pat (Tpat_record new_omegas) p.pat_type p.pat_env) + pss + | _ -> acc in + + match normalize_pat q with + | {pat_desc= (Tpat_any | Tpat_record _)} as q -> + sort_record (acc_pat q pss) + | q -> q + +(* + In case a matching value is found, set actual arguments + of the matching pattern. +*) + +let rec read_args xs r = match xs,r with +| [],_ -> [],r +| _::xs, arg::rest -> + let args,rest = read_args xs rest in + arg::args,rest +| _,_ -> + fatal_error "Parmatch.read_args" + +let do_set_args erase_mutable q r = match q with +| {pat_desc = Tpat_tuple omegas} -> + let args,rest = read_args omegas r in + make_pat (Tpat_tuple args) q.pat_type q.pat_env::rest +| {pat_desc = Tpat_record omegas} -> + let args,rest = read_args omegas r in + make_pat + (Tpat_record + (List.map2 (fun (lbl,_) arg -> + if + erase_mutable && + (match lbl.lbl_mut with + | Mutable -> true | Immutable -> false) + then + lbl, omega + else + lbl,arg) + omegas args)) + q.pat_type q.pat_env:: + rest +| {pat_desc = Tpat_construct (c,omegas)} -> + let args,rest = read_args omegas r in + make_pat + (Tpat_construct (c,args)) q.pat_type q.pat_env:: + rest +| {pat_desc = Tpat_variant (l, omega, row)} -> + let arg, rest = + match omega, r with + Some _, a::r -> Some a, r + | None, r -> None, r + | _ -> assert false + in + make_pat + (Tpat_variant (l, arg, row)) q.pat_type q.pat_env:: + rest +| {pat_desc = Tpat_lazy omega} -> + begin match r with + arg::rest -> + make_pat (Tpat_lazy arg) q.pat_type q.pat_env::rest + | _ -> fatal_error "Parmatch.do_set_args (lazy)" + end +| {pat_desc = Tpat_array omegas} -> + let args,rest = read_args omegas r in + make_pat + (Tpat_array args) q.pat_type q.pat_env:: + rest +| {pat_desc=Tpat_constant _|Tpat_any} -> + q::r (* case any is used in matching.ml *) +| _ -> fatal_error "Parmatch.set_args" + +let set_args q r = do_set_args false q r +and set_args_erase_mutable q r = do_set_args true q r + +(* filter pss acording to pattern q *) +let filter_one q pss = + let rec filter_rec = function + ({pat_desc = Tpat_alias(p,_)}::ps)::pss -> + filter_rec ((p::ps)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss -> + filter_rec ((p1::ps)::(p2::ps)::pss) + | (p::ps)::pss -> + if simple_match q p + then (simple_match_args q p @ ps) :: filter_rec pss + else filter_rec pss + | _ -> [] in + filter_rec pss + +(* + Filter pss in the ``extra case''. This applies : + - According to an extra constructor (datatype case, non-complete signature). + - Acordinng to anything (all-variables case). +*) +let filter_extra pss = + let rec filter_rec = function + ({pat_desc = Tpat_alias(p,_)}::ps)::pss -> + filter_rec ((p::ps)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss -> + filter_rec ((p1::ps)::(p2::ps)::pss) + | ({pat_desc = (Tpat_any | Tpat_var(_))} :: qs) :: pss -> + qs :: filter_rec pss + | _::pss -> filter_rec pss + | [] -> [] in + filter_rec pss + +(* + Pattern p0 is the discriminating pattern, + returns [(q0,pss0) ; ... ; (qn,pssn)] + where the qi's are simple patterns and the pssi's are + matched matrices. + + NOTES + * (qi,[]) is impossible. + * In the case when matching is useless (all-variable case), + returns [] +*) + +let filter_all pat0 pss = + + let rec insert q qs env = + match env with + [] -> + let q0 = normalize_pat q in + [q0, [simple_match_args q0 q @ qs]] + | ((q0,pss) as c)::env -> + if simple_match q0 q + then (q0, ((simple_match_args q0 q @ qs) :: pss)) :: env + else c :: insert q qs env in + + let rec filter_rec env = function + ({pat_desc = Tpat_alias(p,_)}::ps)::pss -> + filter_rec env ((p::ps)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss -> + filter_rec env ((p1::ps)::(p2::ps)::pss) + | ({pat_desc = (Tpat_any | Tpat_var(_))}::_)::pss -> + filter_rec env pss + | (p::ps)::pss -> + filter_rec (insert p ps env) pss + | _ -> env + + and filter_omega env = function + ({pat_desc = Tpat_alias(p,_)}::ps)::pss -> + filter_omega env ((p::ps)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss -> + filter_omega env ((p1::ps)::(p2::ps)::pss) + | ({pat_desc = (Tpat_any | Tpat_var(_))}::ps)::pss -> + filter_omega + (List.map (fun (q,qss) -> (q,(simple_match_args q omega @ ps) :: qss)) env) + pss + | _::pss -> filter_omega env pss + | [] -> env in + + filter_omega + (filter_rec + (match pat0.pat_desc with + (Tpat_record(_) | Tpat_tuple(_) | Tpat_lazy(_)) -> [pat0,[]] + | _ -> []) + pss) + pss + +(* Variant related functions *) + +let rec set_last a = function + [] -> [] + | [_] -> [a] + | x::l -> x :: set_last a l + +(* mark constructor lines for failure when they are incomplete *) +let rec mark_partial = function + ({pat_desc = Tpat_alias(p,_)}::ps)::pss -> + mark_partial ((p::ps)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps)::pss -> + mark_partial ((p1::ps)::(p2::ps)::pss) + | ({pat_desc = (Tpat_any | Tpat_var(_))} :: _ as ps) :: pss -> + ps :: mark_partial pss + | ps::pss -> + (set_last zero ps) :: mark_partial pss + | [] -> [] + +let close_variant env row = + let row = Btype.row_repr row in + let nm = + List.fold_left + (fun nm (tag,f) -> + match Btype.row_field_repr f with + | Reither(_, _, false, e) -> + (* m=false means that this tag is not explicitly matched *) + Btype.set_row_field e Rabsent; + None + | Rabsent | Reither (_, _, true, _) | Rpresent _ -> nm) + row.row_name row.row_fields in + if not row.row_closed || nm != row.row_name then begin + (* this unification cannot fail *) + Ctype.unify env row.row_more + (Btype.newgenty + (Tvariant {row with row_fields = []; row_more = Btype.newgenvar(); + row_closed = true; row_name = nm})) + end + +let row_of_pat pat = + match Ctype.expand_head pat.pat_env pat.pat_type with + {desc = Tvariant row} -> Btype.row_repr row + | _ -> assert false + +(* + Check whether the first column of env makes up a complete signature or + not. +*) + +let full_match closing env = match env with +| ({pat_desc = Tpat_construct ({cstr_tag=Cstr_exception _},_)},_)::_ -> + false +| ({pat_desc = Tpat_construct(c,_)},_) :: _ -> + List.length env = c.cstr_consts + c.cstr_nonconsts +| ({pat_desc = Tpat_variant _} as p,_) :: _ -> + let fields = + List.map + (function ({pat_desc = Tpat_variant (tag, _, _)}, _) -> tag + | _ -> assert false) + env + in + let row = row_of_pat p in + if closing && not row.row_fixed then + (* closing=true, we are considering the variant as closed *) + List.for_all + (fun (tag,f) -> + match Btype.row_field_repr f with + Rabsent | Reither(_, _, false, _) -> true + | Reither (_, _, true, _) + (* m=true, do not discard matched tags, rather warn *) + | Rpresent _ -> List.mem tag fields) + row.row_fields + else + row.row_closed && + List.for_all + (fun (tag,f) -> + Btype.row_field_repr f = Rabsent || List.mem tag fields) + row.row_fields +| ({pat_desc = Tpat_constant(Const_char _)},_) :: _ -> + List.length env = 256 +| ({pat_desc = Tpat_constant(_)},_) :: _ -> false +| ({pat_desc = Tpat_tuple(_)},_) :: _ -> true +| ({pat_desc = Tpat_record(_)},_) :: _ -> true +| ({pat_desc = Tpat_array(_)},_) :: _ -> false +| ({pat_desc = Tpat_lazy(_)},_) :: _ -> true +| _ -> fatal_error "Parmatch.full_match" + +let extendable_match env = match env with +| ({pat_desc = Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},_)} as p,_) :: _ -> + let path = get_type_path p.pat_type p.pat_env in + not + (Path.same path Predef.path_bool || + Path.same path Predef.path_list || + Path.same path Predef.path_option) +| _ -> false + + +let should_extend ext env = match ext with +| None -> false +| Some ext -> match env with + | ({pat_desc = + Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},_)} as p,_) + :: _ -> + let path = get_type_path p.pat_type p.pat_env in + Path.same path ext + | _ -> false + +(* complement constructor tags *) +let complete_tags nconsts nconstrs tags = + let seen_const = Array.create nconsts false + and seen_constr = Array.create nconstrs false in + List.iter + (function + | Cstr_constant i -> seen_const.(i) <- true + | Cstr_block i -> seen_constr.(i) <- true + | _ -> assert false) + tags ; + let r = ref [] in + for i = 0 to nconsts-1 do + if not seen_const.(i) then + r := Cstr_constant i :: !r + done ; + for i = 0 to nconstrs-1 do + if not seen_constr.(i) then + r := Cstr_block i :: !r + done ; + !r + +(* build a pattern from a constructor list *) +let pat_of_constr ex_pat cstr = + {ex_pat with pat_desc = Tpat_construct (cstr,omegas cstr.cstr_arity)} + +let rec pat_of_constrs ex_pat = function +| [] -> raise Empty +| [cstr] -> pat_of_constr ex_pat cstr +| cstr::rem -> + {ex_pat with + pat_desc= + Tpat_or + (pat_of_constr ex_pat cstr, + pat_of_constrs ex_pat rem, None)} + +(* Sends back a pattern that complements constructor tags all_tag *) +let complete_constrs p all_tags = match p.pat_desc with +| Tpat_construct (c,_) -> + begin try + let not_tags = complete_tags c.cstr_consts c.cstr_nonconsts all_tags in + List.map + (fun tag -> + let _,targs = get_constr tag p.pat_type p.pat_env in + {c with + cstr_tag = tag ; + cstr_args = targs ; + cstr_arity = List.length targs}) + not_tags +with +| Datarepr.Constr_not_found -> + fatal_error "Parmatch.complete_constr: constr_not_found" + end +| _ -> fatal_error "Parmatch.complete_constr" + + +(* Auxiliary for build_other *) + +let build_other_constant proj make first next p env = + let all = List.map (fun (p, _) -> proj p.pat_desc) env in + let rec try_const i = + if List.mem i all + then try_const (next i) + else make_pat (make i) p.pat_type p.pat_env + in try_const first + +(* + Builds a pattern that is incompatible with all patterns in + in the first column of env +*) + +let build_other ext env = match env with +| ({pat_desc = Tpat_construct ({cstr_tag=Cstr_exception _} as c,_)},_) + ::_ -> + make_pat + (Tpat_construct + ({c with + cstr_tag=(Cstr_exception + (Path.Pident (Ident.create "*exception*")))}, + [])) + Ctype.none Env.empty +| ({pat_desc = Tpat_construct (_,_)} as p,_) :: _ -> + begin match ext with + | Some ext when Path.same ext (get_type_path p.pat_type p.pat_env) -> + extra_pat + | _ -> + let get_tag = function + | {pat_desc = Tpat_construct (c,_)} -> c.cstr_tag + | _ -> fatal_error "Parmatch.get_tag" in + let all_tags = List.map (fun (p,_) -> get_tag p) env in + pat_of_constrs p (complete_constrs p all_tags) + end +| ({pat_desc = Tpat_variant (_,_,r)} as p,_) :: _ -> + let tags = + List.map + (function ({pat_desc = Tpat_variant (tag, _, _)}, _) -> tag + | _ -> assert false) + env + in + let row = row_of_pat p in + let make_other_pat tag const = + let arg = if const then None else Some omega in + make_pat (Tpat_variant(tag, arg, r)) p.pat_type p.pat_env in + begin match + List.fold_left + (fun others (tag,f) -> + if List.mem tag tags then others else + match Btype.row_field_repr f with + Rabsent (* | Reither _ *) -> others + (* This one is called after erasing pattern info *) + | Reither (c, _, _, _) -> make_other_pat tag c :: others + | Rpresent arg -> make_other_pat tag (arg = None) :: others) + [] row.row_fields + with + [] -> + make_other_pat "AnyExtraTag" true + | pat::other_pats -> + List.fold_left + (fun p_res pat -> + make_pat (Tpat_or (pat, p_res, None)) p.pat_type p.pat_env) + pat other_pats + end +| ({pat_desc = Tpat_constant(Const_char _)} as p,_) :: _ -> + let all_chars = + List.map + (fun (p,_) -> match p.pat_desc with + | Tpat_constant (Const_char c) -> c + | _ -> assert false) + env in + + let rec find_other i imax = + if i > imax then raise Not_found + else + let ci = Char.chr i in + if List.mem ci all_chars then + find_other (i+1) imax + else + make_pat (Tpat_constant (Const_char ci)) p.pat_type p.pat_env in + let rec try_chars = function + | [] -> omega + | (c1,c2) :: rest -> + try + find_other (Char.code c1) (Char.code c2) + with + | Not_found -> try_chars rest in + + try_chars + [ 'a', 'z' ; 'A', 'Z' ; '0', '9' ; + ' ', '~' ; Char.chr 0 , Char.chr 255] + +| ({pat_desc=(Tpat_constant (Const_int _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_int i) -> i | _ -> assert false) + (function i -> Tpat_constant(Const_int i)) + 0 succ p env +| ({pat_desc=(Tpat_constant (Const_int32 _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_int32 i) -> i | _ -> assert false) + (function i -> Tpat_constant(Const_int32 i)) + 0l Int32.succ p env +| ({pat_desc=(Tpat_constant (Const_int64 _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_int64 i) -> i | _ -> assert false) + (function i -> Tpat_constant(Const_int64 i)) + 0L Int64.succ p env +| ({pat_desc=(Tpat_constant (Const_nativeint _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_nativeint i) -> i | _ -> assert false) + (function i -> Tpat_constant(Const_nativeint i)) + 0n Nativeint.succ p env +| ({pat_desc=(Tpat_constant (Const_string _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_string s) -> String.length s + | _ -> assert false) + (function i -> Tpat_constant(Const_string(String.make i '*'))) + 0 succ p env +| ({pat_desc=(Tpat_constant (Const_float _))} as p,_) :: _ -> + build_other_constant + (function Tpat_constant(Const_float f) -> float_of_string f + | _ -> assert false) + (function f -> Tpat_constant(Const_float (string_of_float f))) + 0.0 (fun f -> f +. 1.0) p env + +| ({pat_desc = Tpat_array args} as p,_)::_ -> + let all_lengths = + List.map + (fun (p,_) -> match p.pat_desc with + | Tpat_array args -> List.length args + | _ -> assert false) + env in + let rec try_arrays l = + if List.mem l all_lengths then try_arrays (l+1) + else + make_pat + (Tpat_array (omegas l)) + p.pat_type p.pat_env in + try_arrays 0 +| [] -> omega +| _ -> omega + +(* + Core function : + Is the last row of pattern matrix pss + qs satisfiable ? + That is : + Does there exists at least one value vector, es such that : + 1- for all ps in pss ps # es (ps and es are not compatible) + 2- qs <= es (es matches qs) +*) + +let rec has_instance p = match p.pat_desc with + | Tpat_variant (l,_,r) when is_absent l r -> false + | Tpat_any | Tpat_var _ | Tpat_constant _ | Tpat_variant (_,None,_) -> true + | Tpat_alias (p,_) | Tpat_variant (_,Some p,_) -> has_instance p + | Tpat_or (p1,p2,_) -> has_instance p1 || has_instance p2 + | Tpat_construct (_,ps) | Tpat_tuple ps | Tpat_array ps -> has_instances ps + | Tpat_record lps -> has_instances (List.map snd lps) + | Tpat_lazy p -> has_instance p + +and has_instances = function + | [] -> true + | q::rem -> has_instance q && has_instances rem + +let rec satisfiable pss qs = match pss with +| [] -> has_instances qs +| _ -> + match qs with + | [] -> false + | {pat_desc = Tpat_or(q1,q2,_)}::qs -> + satisfiable pss (q1::qs) || satisfiable pss (q2::qs) + | {pat_desc = Tpat_alias(q,_)}::qs -> + satisfiable pss (q::qs) + | {pat_desc = (Tpat_any | Tpat_var(_))}::qs -> + let q0 = discr_pat omega pss in + begin match filter_all q0 pss with + (* first column of pss is made of variables only *) + | [] -> satisfiable (filter_extra pss) qs + | constrs -> + if full_match false constrs then + List.exists + (fun (p,pss) -> + not (is_absent_pat p) && + satisfiable pss (simple_match_args p omega @ qs)) + constrs + else + satisfiable (filter_extra pss) qs + end + | {pat_desc=Tpat_variant (l,_,r)}::_ when is_absent l r -> false + | q::qs -> + let q0 = discr_pat q pss in + satisfiable (filter_one q0 pss) (simple_match_args q0 q @ qs) + +(* + Now another satisfiable function that additionally + supplies an example of a matching value. + + This function should be called for exhaustiveness check only. +*) + +type 'a result = + | Rnone (* No matching value *) + | Rsome of 'a (* This matching value *) + +let rec try_many f = function + | [] -> Rnone + | x::rest -> + begin match f x with + | Rnone -> try_many f rest + | r -> r + end + +let rec exhaust ext pss n = match pss with +| [] -> Rsome (omegas n) +| []::_ -> Rnone +| pss -> + let q0 = discr_pat omega pss in + begin match filter_all q0 pss with + (* first column of pss is made of variables only *) + | [] -> + begin match exhaust ext (filter_extra pss) (n-1) with + | Rsome r -> Rsome (q0::r) + | r -> r + end + | constrs -> + let try_non_omega (p,pss) = + if is_absent_pat p then + Rnone + else + match + exhaust + ext pss (List.length (simple_match_args p omega) + n - 1) + with + | Rsome r -> Rsome (set_args p r) + | r -> r in + if + full_match false constrs && not (should_extend ext constrs) + then + try_many try_non_omega constrs + else + (* + D = filter_extra pss is the default matrix + as it is included in pss, one can avoid + recursive calls on specialized matrices, + Essentially : + * D exhaustive => pss exhaustive + * D non-exhaustive => we have a non-filtered value + *) + let r = exhaust ext (filter_extra pss) (n-1) in + match r with + | Rnone -> Rnone + | Rsome r -> + try + Rsome (build_other ext constrs::r) + with + (* cannot occur, since constructors don't make a full signature *) + | Empty -> fatal_error "Parmatch.exhaust" + end + +(* + Another exhaustiveness check, enforcing variant typing. + Note that it does not check exact exhaustiveness, but whether a + matching could be made exhaustive by closing all variant types. + When this is true of all other columns, the current column is left + open (even if it means that the whole matching is not exhaustive as + a result). + When this is false for the matrix minus the current column, and the + current column is composed of variant tags, we close the variant + (even if it doesn't help in making the matching exhaustive). +*) + +let rec pressure_variants tdefs = function + | [] -> false + | []::_ -> true + | pss -> + let q0 = discr_pat omega pss in + begin match filter_all q0 pss with + [] -> pressure_variants tdefs (filter_extra pss) + | constrs -> + let rec try_non_omega = function + (p,pss) :: rem -> + let ok = pressure_variants tdefs pss in + try_non_omega rem && ok + | [] -> true + in + if full_match (tdefs=None) constrs then + try_non_omega constrs + else if tdefs = None then + pressure_variants None (filter_extra pss) + else + let full = full_match true constrs in + let ok = + if full then try_non_omega constrs + else try_non_omega (filter_all q0 (mark_partial pss)) + in + begin match constrs, tdefs with + ({pat_desc=Tpat_variant _} as p,_):: _, Some env -> + let row = row_of_pat p in + if row.row_fixed + || pressure_variants None (filter_extra pss) then () + else close_variant env row + | _ -> () + end; + ok + end + + +(* Yet another satisfiable fonction *) + +(* + This time every_satisfiable pss qs checks the + utility of every expansion of qs. + Expansion means expansion of or-patterns inside qs +*) + +type answer = + | Used (* Useful pattern *) + | Unused (* Useless pattern *) + | Upartial of Typedtree.pattern list (* Neither, with list of useless pattern *) + + +let pretty_pat p = + top_pretty Format.str_formatter p ; + prerr_string (Format.flush_str_formatter ()) + +type matrix = pattern list list + +let pretty_line ps = + List.iter + (fun p -> + top_pretty Format.str_formatter p ; + prerr_string " <" ; + prerr_string (Format.flush_str_formatter ()) ; + prerr_string ">") + ps + +let pretty_matrix pss = + prerr_endline "begin matrix" ; + List.iter + (fun ps -> + pretty_line ps ; + prerr_endline "") + pss ; + prerr_endline "end matrix" + +(* this row type enable column processing inside the matrix + - left -> elements not to be processed, + - right -> elements to be processed +*) +type 'a row = {no_ors : 'a list ; ors : 'a list ; active : 'a list} + + +let pretty_row {ors=ors ; no_ors=no_ors; active=active} = + pretty_line ors ; prerr_string " *" ; + pretty_line no_ors ; prerr_string " *" ; + pretty_line active + +let pretty_rows rs = + prerr_endline "begin matrix" ; + List.iter + (fun r -> + pretty_row r ; + prerr_endline "") + rs ; + prerr_endline "end matrix" + +(* Initial build *) +let make_row ps = {ors=[] ; no_ors=[]; active=ps} + +let make_rows pss = List.map make_row pss + + +(* Useful to detect and expand or pats inside as pats *) +let rec unalias p = match p.pat_desc with +| Tpat_alias (p,_) -> unalias p +| _ -> p + + +let is_var p = match (unalias p).pat_desc with +| Tpat_any|Tpat_var _ -> true +| _ -> false + +let is_var_column rs = + List.for_all + (fun r -> match r.active with + | p::_ -> is_var p + | [] -> assert false) + rs + +(* Standard or-args for left-to-right matching *) +let rec or_args p = match p.pat_desc with +| Tpat_or (p1,p2,_) -> p1,p2 +| Tpat_alias (p,_) -> or_args p +| _ -> assert false + +(* Just remove current column *) +let remove r = match r.active with +| _::rem -> {r with active=rem} +| [] -> assert false + +let remove_column rs = List.map remove rs + +(* Current column has been processed *) +let push_no_or r = match r.active with +| p::rem -> { r with no_ors = p::r.no_ors ; active=rem} +| [] -> assert false + +let push_or r = match r.active with +| p::rem -> { r with ors = p::r.ors ; active=rem} +| [] -> assert false + +let push_or_column rs = List.map push_or rs +and push_no_or_column rs = List.map push_no_or rs + +(* Those are adaptations of the previous homonymous functions that + work on the current column, instead of the first column +*) + +let discr_pat q rs = + discr_pat q (List.map (fun r -> r.active) rs) + +let filter_one q rs = + let rec filter_rec rs = match rs with + | [] -> [] + | r::rem -> + match r.active with + | [] -> assert false + | {pat_desc = Tpat_alias(p,_)}::ps -> + filter_rec ({r with active = p::ps}::rem) + | {pat_desc = Tpat_or(p1,p2,_)}::ps -> + filter_rec + ({r with active = p1::ps}:: + {r with active = p2::ps}:: + rem) + | p::ps -> + if simple_match q p then + {r with active=simple_match_args q p @ ps} :: filter_rec rem + else + filter_rec rem in + filter_rec rs + + +(* Back to normal matrices *) +let make_vector r = r.no_ors + +let make_matrix rs = List.map make_vector rs + + +(* Standard union on answers *) +let union_res r1 r2 = match r1, r2 with +| (Unused,_) +| (_, Unused) -> Unused +| Used,_ -> r2 +| _, Used -> r1 +| Upartial u1, Upartial u2 -> Upartial (u1@u2) + +(* propose or pats for expansion *) +let extract_elements qs = + let rec do_rec seen = function + | [] -> [] + | q::rem -> + {no_ors= List.rev_append seen rem @ qs.no_ors ; + ors=[] ; + active = [q]}:: + do_rec (q::seen) rem in + do_rec [] qs.ors + +(* idem for matrices *) +let transpose rs = match rs with +| [] -> assert false +| r::rem -> + let i = List.map (fun x -> [x]) r in + List.fold_left + (List.map2 (fun r x -> x::r)) + i rem + +let extract_columns pss qs = match pss with +| [] -> List.map (fun _ -> []) qs.ors +| _ -> + let rows = List.map extract_elements pss in + transpose rows + +(* Core function + The idea is to first look for or patterns (recursive case), then + check or-patterns argument usefulness (terminal case) +*) + +let rec every_satisfiables pss qs = match qs.active with +| [] -> + (* qs is now partitionned, check usefulness *) + begin match qs.ors with + | [] -> (* no or-patterns *) + if satisfiable (make_matrix pss) (make_vector qs) then + Used + else + Unused + | _ -> (* n or-patterns -> 2n expansions *) + List.fold_right2 + (fun pss qs r -> match r with + | Unused -> Unused + | _ -> + match qs.active with + | [q] -> + let q1,q2 = or_args q in + let r_loc = every_both pss qs q1 q2 in + union_res r r_loc + | _ -> assert false) + (extract_columns pss qs) (extract_elements qs) + Used + end +| q::rem -> + let uq = unalias q in + begin match uq.pat_desc with + | Tpat_any | Tpat_var _ -> + if is_var_column pss then +(* forget about ``all-variable'' columns now *) + every_satisfiables (remove_column pss) (remove qs) + else +(* otherwise this is direct food for satisfiable *) + every_satisfiables (push_no_or_column pss) (push_no_or qs) + | Tpat_or (q1,q2,_) -> + if + q1.pat_loc.Location.loc_ghost && + q2.pat_loc.Location.loc_ghost + then +(* syntactically generated or-pats should not be expanded *) + every_satisfiables (push_no_or_column pss) (push_no_or qs) + else +(* this is a real or-pattern *) + every_satisfiables (push_or_column pss) (push_or qs) + | Tpat_variant (l,_,r) when is_absent l r -> (* Ah Jacques... *) + Unused + | _ -> +(* standard case, filter matrix *) + let q0 = discr_pat q pss in + every_satisfiables + (filter_one q0 pss) + {qs with active=simple_match_args q0 q @ rem} + end + +(* + This function ``every_both'' performs the usefulness check + of or-pat q1|q2. + The trick is to call every_satisfied twice with + current active columns restricted to q1 and q2, + That way, + - others orpats in qs.ors will not get expanded. + - all matching work performed on qs.no_ors is not performed again. + *) +and every_both pss qs q1 q2 = + let qs1 = {qs with active=[q1]} + and qs2 = {qs with active=[q2]} in + let r1 = every_satisfiables pss qs1 + and r2 = every_satisfiables (if compat q1 q2 then qs1::pss else pss) qs2 in + match r1 with + | Unused -> + begin match r2 with + | Unused -> Unused + | Used -> Upartial [q1] + | Upartial u2 -> Upartial (q1::u2) + end + | Used -> + begin match r2 with + | Unused -> Upartial [q2] + | _ -> r2 + end + | Upartial u1 -> + begin match r2 with + | Unused -> Upartial (u1@[q2]) + | Used -> r1 + | Upartial u2 -> Upartial (u1 @ u2) + end + + + + +(* le_pat p q means, forall V, V matches q implies V matches p *) +let rec le_pat p q = + match (p.pat_desc, q.pat_desc) with + | (Tpat_var _|Tpat_any),_ -> true + | Tpat_alias(p,_), _ -> le_pat p q + | _, Tpat_alias(q,_) -> le_pat p q + | Tpat_constant(c1), Tpat_constant(c2) -> c1 = c2 + | Tpat_construct(c1,ps), Tpat_construct(c2,qs) -> + c1.cstr_tag = c2.cstr_tag && le_pats ps qs + | Tpat_variant(l1,Some p1,_), Tpat_variant(l2,Some p2,_) -> + (l1 = l2 && le_pat p1 p2) + | Tpat_variant(l1,None,r1), Tpat_variant(l2,None,_) -> + l1 = l2 + | Tpat_variant(_,_,_), Tpat_variant(_,_,_) -> false + | Tpat_tuple(ps), Tpat_tuple(qs) -> le_pats ps qs + | Tpat_lazy p, Tpat_lazy q -> le_pat p q + | Tpat_record l1, Tpat_record l2 -> + let ps,qs = records_args l1 l2 in + le_pats ps qs + | Tpat_array(ps), Tpat_array(qs) -> + List.length ps = List.length qs && le_pats ps qs +(* In all other cases, enumeration is performed *) + | _,_ -> not (satisfiable [[p]] [q]) + +and le_pats ps qs = + match ps,qs with + p::ps, q::qs -> le_pat p q && le_pats ps qs + | _, _ -> true + +let get_mins le ps = + let rec select_rec r = function + [] -> r + | p::ps -> + if List.exists (fun p0 -> le p0 p) ps + then select_rec r ps + else select_rec (p::r) ps in + select_rec [] (select_rec [] ps) + +(* + lub p q is a pattern that matches all values matched by p and q + may raise Empty, when p and q and not compatible +*) + +let rec lub p q = match p.pat_desc,q.pat_desc with +| Tpat_alias (p,_),_ -> lub p q +| _,Tpat_alias (q,_) -> lub p q +| (Tpat_any|Tpat_var _),_ -> q +| _,(Tpat_any|Tpat_var _) -> p +| Tpat_or (p1,p2,_),_ -> orlub p1 p2 q +| _,Tpat_or (q1,q2,_) -> orlub q1 q2 p (* Thanks god, lub is commutative *) +| Tpat_constant c1, Tpat_constant c2 when c1=c2 -> p +| Tpat_tuple ps, Tpat_tuple qs -> + let rs = lubs ps qs in + make_pat (Tpat_tuple rs) p.pat_type p.pat_env +| Tpat_lazy p, Tpat_lazy q -> + let r = lub p q in + make_pat (Tpat_lazy r) p.pat_type p.pat_env +| Tpat_construct (c1,ps1), Tpat_construct (c2,ps2) + when c1.cstr_tag = c2.cstr_tag -> + let rs = lubs ps1 ps2 in + make_pat (Tpat_construct (c1,rs)) p.pat_type p.pat_env +| Tpat_variant(l1,Some p1,row), Tpat_variant(l2,Some p2,_) + when l1=l2 -> + let r=lub p1 p2 in + make_pat (Tpat_variant (l1,Some r,row)) p.pat_type p.pat_env +| Tpat_variant (l1,None,row), Tpat_variant(l2,None,_) + when l1 = l2 -> p +| Tpat_record l1,Tpat_record l2 -> + let rs = record_lubs l1 l2 in + make_pat (Tpat_record rs) p.pat_type p.pat_env +| Tpat_array ps, Tpat_array qs + when List.length ps = List.length qs -> + let rs = lubs ps qs in + make_pat (Tpat_array rs) p.pat_type p.pat_env +| _,_ -> + raise Empty + +and orlub p1 p2 q = + try + let r1 = lub p1 q in + try + {q with pat_desc=(Tpat_or (r1,lub p2 q,None))} + with + | Empty -> r1 +with +| Empty -> lub p2 q + +and record_lubs l1 l2 = + let l1 = sort_fields l1 and l2 = sort_fields l2 in + let rec lub_rec l1 l2 = match l1,l2 with + | [],_ -> l2 + | _,[] -> l1 + | (lbl1,p1)::rem1, (lbl2,p2)::rem2 -> + if lbl1.lbl_pos < lbl2.lbl_pos then + (lbl1,p1)::lub_rec rem1 l2 + else if lbl2.lbl_pos < lbl1.lbl_pos then + (lbl2,p2)::lub_rec l1 rem2 + else + (lbl1,lub p1 p2)::lub_rec rem1 rem2 in + lub_rec l1 l2 + +and lubs ps qs = match ps,qs with +| p::ps, q::qs -> lub p q :: lubs ps qs +| _,_ -> [] + + +(******************************) +(* Exported variant closing *) +(******************************) + +(* Apply pressure to variants *) + +let pressure_variants tdefs patl = + let pss = List.map (fun p -> [p;omega]) patl in + ignore (pressure_variants (Some tdefs) pss) + +(*****************************) +(* Utilities for diagnostics *) +(*****************************) + +(* + Build up a working pattern matrix by forgetting + about guarded patterns +*) + +let has_guard act = match act.exp_desc with +| Texp_when(_, _) -> true +| _ -> false + + +let rec initial_matrix = function + [] -> [] + | (pat, act) :: rem -> + if has_guard act + then + initial_matrix rem + else + [pat] :: initial_matrix rem + +(******************************************) +(* Look for a row that matches some value *) +(******************************************) + +(* + Useful for seeing if the example of + non-matched value can indeed be matched + (by a guarded clause) +*) + + + +exception NoGuard + +let rec initial_all no_guard = function + | [] -> + if no_guard then + raise NoGuard + else + [] + | (pat, act) :: rem -> + ([pat], pat.pat_loc) :: initial_all (no_guard && not (has_guard act)) rem + + +let rec do_filter_var = function + | (_::ps,loc)::rem -> (ps,loc)::do_filter_var rem + | _ -> [] + +let do_filter_one q pss = + let rec filter_rec = function + | ({pat_desc = Tpat_alias(p,_)}::ps,loc)::pss -> + filter_rec ((p::ps,loc)::pss) + | ({pat_desc = Tpat_or(p1,p2,_)}::ps,loc)::pss -> + filter_rec ((p1::ps,loc)::(p2::ps,loc)::pss) + | (p::ps,loc)::pss -> + if simple_match q p + then (simple_match_args q p @ ps, loc) :: filter_rec pss + else filter_rec pss + | _ -> [] in + filter_rec pss + +let rec do_match pss qs = match qs with +| [] -> + begin match pss with + | ([],loc)::_ -> Some loc + | _ -> None + end +| q::qs -> match q with + | {pat_desc = Tpat_or (q1,q2,_)} -> + begin match do_match pss (q1::qs) with + | None -> do_match pss (q2::qs) + | r -> r + end + | {pat_desc = Tpat_any} -> + do_match (do_filter_var pss) qs + | _ -> + let q0 = normalize_pat q in + do_match (do_filter_one q0 pss) (simple_match_args q0 q @ qs) + + +let check_partial_all v casel = + try + let pss = initial_all true casel in + do_match pss [v] + with + | NoGuard -> None + +(************************) +(* Exhaustiveness check *) +(************************) + +let do_check_partial loc casel pss = match pss with +| [] -> + (* + This can occur + - For empty matches generated by ocamlp4 (no warning) + - when all patterns have guards (then, casel <> []) + (specific warning) + Then match MUST be considered non-exhaustive, + otherwise compilation of PM is broken. + *) + begin match casel with + | [] -> () + | _ -> Location.prerr_warning loc Warnings.All_clauses_guarded + end ; + Partial +| ps::_ -> + begin match exhaust None pss (List.length ps) with + | Rnone -> Total + | Rsome [v] -> + let errmsg = + try + let buf = Buffer.create 16 in + let fmt = formatter_of_buffer buf in + top_pretty fmt v; + begin match check_partial_all v casel with + | None -> () + | Some _ -> + (* This is 'Some loc', where loc is the location of + a possibly matching clause. + Forget about loc, because printing two locations + is a pain in the top-level *) + Buffer.add_string buf + "\n(However, some guarded clause may match this value.)" + end ; + Buffer.contents buf + with _ -> + "" in + Location.prerr_warning loc (Warnings.Partial_match errmsg) ; + Partial + | _ -> + fatal_error "Parmatch.check_partial" + end + + +(*****************) +(* Fragile check *) +(*****************) + +(* Collect all data types in a pattern *) + +let rec add_path path = function + | [] -> [path] + | x::rem as paths -> + if Path.same path x then paths + else x::add_path path rem + +let extendable_path path = + not + (Path.same path Predef.path_bool || + Path.same path Predef.path_list || + Path.same path Predef.path_option) + +let rec collect_paths_from_pat r p = match p.pat_desc with +| Tpat_construct({cstr_tag=(Cstr_constant _|Cstr_block _)},ps) -> + let path = get_type_path p.pat_type p.pat_env in + List.fold_left + collect_paths_from_pat + (if extendable_path path then add_path path r else r) + ps +| Tpat_any|Tpat_var _|Tpat_constant _| Tpat_variant (_,None,_) -> r +| Tpat_tuple ps | Tpat_array ps +| Tpat_construct ({cstr_tag=Cstr_exception _}, ps)-> + List.fold_left collect_paths_from_pat r ps +| Tpat_record lps -> + List.fold_left + (fun r (_,p) -> collect_paths_from_pat r p) + r lps +| Tpat_variant (_, Some p, _) | Tpat_alias (p,_) -> collect_paths_from_pat r p +| Tpat_or (p1,p2,_) -> + collect_paths_from_pat (collect_paths_from_pat r p1) p2 +| Tpat_lazy p -> + collect_paths_from_pat r p + + +(* + Actual fragile check + 1. Collect data types in the patterns of the match. + 2. One exhautivity check per datatype, considering that + the type is extended. +*) + +let do_check_fragile loc casel pss = + let exts = + List.fold_left + (fun r (p,_) -> collect_paths_from_pat r p) + [] casel in + match exts with + | [] -> () + | _ -> match pss with + | [] -> () + | ps::_ -> + List.iter + (fun ext -> + match exhaust (Some ext) pss (List.length ps) with + | Rnone -> + Location.prerr_warning + loc + (Warnings.Fragile_match (Path.name ext)) + | Rsome _ -> ()) + exts + + +(********************************) +(* Exported exhustiveness check *) +(********************************) + +(* + Fragile check is performed when required and + on exhaustive matches only. +*) + +let check_partial loc casel = + if Warnings.is_active (Warnings.Partial_match "") then begin + let pss = initial_matrix casel in + let pss = get_mins le_pats pss in + let total = do_check_partial loc casel pss in + if + total = Total && Warnings.is_active (Warnings.Fragile_match "") + then begin + do_check_fragile loc casel pss + end ; + total + end else + Partial + + +(********************************) +(* Exported unused clause check *) +(********************************) + +let check_unused tdefs casel = + if Warnings.is_active Warnings.Unused_match then + let rec do_rec pref = function + | [] -> () + | (q,act)::rem -> + let qs = [q] in + begin try + let pss = + get_mins le_pats (List.filter (compats qs) pref) in + let r = every_satisfiables (make_rows pss) (make_row qs) in + match r with + | Unused -> + Location.prerr_warning + q.pat_loc Warnings.Unused_match + | Upartial ps -> + List.iter + (fun p -> + Location.prerr_warning + p.pat_loc Warnings.Unused_pat) + ps + | Used -> () + with e -> assert false + end ; + + if has_guard act then + do_rec pref rem + else + do_rec ([q]::pref) rem in + + do_rec [] casel + +(*********************************) +(* Exported irrefutability tests *) +(*********************************) + +let irrefutable pat = le_pat pat omega + +(* An inactive pattern is a pattern whose matching needs only + trivial computations (tag/equality tests). + Patterns containing (lazy _) subpatterns are active. *) + +let rec inactive pat = match pat with +| Tpat_lazy _ -> + false +| Tpat_any | Tpat_var _ | Tpat_constant _ | Tpat_variant (_, None, _) -> + true +| Tpat_tuple ps | Tpat_construct (_, ps) | Tpat_array ps -> + List.for_all (fun p -> inactive p.pat_desc) ps +| Tpat_alias (p,_) | Tpat_variant (_, Some p, _) -> + inactive p.pat_desc +| Tpat_record ldps -> + List.exists (fun (_, p) -> inactive p.pat_desc) ldps +| Tpat_or (p,q,_) -> + inactive p.pat_desc && inactive q.pat_desc + + +(* A `fluid' pattern is both irrefutable and inactive *) + +let fluid pat = irrefutable pat && inactive pat.pat_desc diff --git a/typing/parmatch.mli b/typing/parmatch.mli new file mode 100644 index 0000000..9f18eca --- /dev/null +++ b/typing/parmatch.mli @@ -0,0 +1,59 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: parmatch.mli,v 1.12 2008-07-09 13:03:37 mauny Exp $ *) + +(* Detection of partial matches and unused match cases. *) +open Types +open Typedtree + +val top_pretty : Format.formatter -> pattern -> unit +val pretty_pat : pattern -> unit +val pretty_line : pattern list -> unit +val pretty_matrix : pattern list list -> unit + +val omega : pattern +val omegas : int -> pattern list +val omega_list : 'a list -> pattern list +val normalize_pat : pattern -> pattern +val all_record_args : + (label_description * pattern) list -> (label_description * pattern) list + +val le_pat : pattern -> pattern -> bool +val le_pats : pattern list -> pattern list -> bool +val compat : pattern -> pattern -> bool +val compats : pattern list -> pattern list -> bool +exception Empty +val lub : pattern -> pattern -> pattern +val lubs : pattern list -> pattern list -> pattern list + +val get_mins : ('a -> 'a -> bool) -> 'a list -> 'a list + +(* Those to functions recombine one pattern and its arguments: + For instance: + (_,_)::p1::p2::rem -> (p1, p2)::rem + The second one will replace mutable arguments by '_' +*) +val set_args : pattern -> pattern list -> pattern list +val set_args_erase_mutable : pattern -> pattern list -> pattern list + +val pat_of_constr : pattern -> constructor_description -> pattern +val complete_constrs : + pattern -> constructor_tag list -> constructor_description list + +val pressure_variants: Env.t -> pattern list -> unit +val check_partial: Location.t -> (pattern * expression) list -> partial +val check_unused: Env.t -> (pattern * expression) list -> unit + +(* Irrefutability tests *) +val irrefutable : pattern -> bool +val fluid : pattern -> bool diff --git a/typing/path.ml b/typing/path.ml new file mode 100644 index 0000000..3d0ddd6 --- /dev/null +++ b/typing/path.ml @@ -0,0 +1,49 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: path.ml,v 1.9 2003-07-01 13:05:43 xleroy Exp $ *) + +type t = + Pident of Ident.t + | Pdot of t * string * int + | Papply of t * t + +let nopos = -1 + +let rec same p1 p2 = + match (p1, p2) with + (Pident id1, Pident id2) -> Ident.same id1 id2 + | (Pdot(p1, s1, pos1), Pdot(p2, s2, pos2)) -> s1 = s2 && same p1 p2 + | (Papply(fun1, arg1), Papply(fun2, arg2)) -> + same fun1 fun2 && same arg1 arg2 + | (_, _) -> false + +let rec isfree id = function + Pident id' -> Ident.same id id' + | Pdot(p, s, pos) -> isfree id p + | Papply(p1, p2) -> isfree id p1 || isfree id p2 + +let rec binding_time = function + Pident id -> Ident.binding_time id + | Pdot(p, s, pos) -> binding_time p + | Papply(p1, p2) -> max (binding_time p1) (binding_time p2) + +let rec name = function + Pident id -> Ident.name id + | Pdot(p, s, pos) -> name p ^ "." ^ s + | Papply(p1, p2) -> name p1 ^ "(" ^ name p2 ^ ")" + +let rec head = function + Pident id -> id + | Pdot(p, s, pos) -> head p + | Papply(p1, p2) -> assert false + diff --git a/typing/path.mli b/typing/path.mli new file mode 100644 index 0000000..68736e8 --- /dev/null +++ b/typing/path.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: path.mli,v 1.8 2003-07-01 13:05:43 xleroy Exp $ *) + +(* Access paths *) + +type t = + Pident of Ident.t + | Pdot of t * string * int + | Papply of t * t + +val same: t -> t -> bool +val isfree: Ident.t -> t -> bool +val binding_time: t -> int + +val nopos: int + +val name: t -> string +val head: t -> Ident.t diff --git a/typing/predef.ml b/typing/predef.ml new file mode 100644 index 0000000..44408ec --- /dev/null +++ b/typing/predef.ml @@ -0,0 +1,203 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: predef.ml,v 1.32 2007-10-09 10:29:37 weis Exp $ *) + +(* Predefined type constructors (with special typing rules in typecore) *) + +open Asttypes +open Path +open Types +open Btype + +let ident_int = Ident.create "int" +and ident_char = Ident.create "char" +and ident_string = Ident.create "string" +and ident_float = Ident.create "float" +and ident_bool = Ident.create "bool" +and ident_unit = Ident.create "unit" +and ident_exn = Ident.create "exn" +and ident_array = Ident.create "array" +and ident_list = Ident.create "list" +and ident_format6 = Ident.create "format6" +and ident_option = Ident.create "option" +and ident_nativeint = Ident.create "nativeint" +and ident_int32 = Ident.create "int32" +and ident_int64 = Ident.create "int64" +and ident_lazy_t = Ident.create "lazy_t" + +let path_int = Pident ident_int +and path_char = Pident ident_char +and path_string = Pident ident_string +and path_float = Pident ident_float +and path_bool = Pident ident_bool +and path_unit = Pident ident_unit +and path_exn = Pident ident_exn +and path_array = Pident ident_array +and path_list = Pident ident_list +and path_format6 = Pident ident_format6 +and path_option = Pident ident_option +and path_nativeint = Pident ident_nativeint +and path_int32 = Pident ident_int32 +and path_int64 = Pident ident_int64 +and path_lazy_t = Pident ident_lazy_t + +let type_int = newgenty (Tconstr(path_int, [], ref Mnil)) +and type_char = newgenty (Tconstr(path_char, [], ref Mnil)) +and type_string = newgenty (Tconstr(path_string, [], ref Mnil)) +and type_float = newgenty (Tconstr(path_float, [], ref Mnil)) +and type_bool = newgenty (Tconstr(path_bool, [], ref Mnil)) +and type_unit = newgenty (Tconstr(path_unit, [], ref Mnil)) +and type_exn = newgenty (Tconstr(path_exn, [], ref Mnil)) +and type_array t = newgenty (Tconstr(path_array, [t], ref Mnil)) +and type_list t = newgenty (Tconstr(path_list, [t], ref Mnil)) +and type_option t = newgenty (Tconstr(path_option, [t], ref Mnil)) +and type_nativeint = newgenty (Tconstr(path_nativeint, [], ref Mnil)) +and type_int32 = newgenty (Tconstr(path_int32, [], ref Mnil)) +and type_int64 = newgenty (Tconstr(path_int64, [], ref Mnil)) +and type_lazy_t t = newgenty (Tconstr(path_lazy_t, [t], ref Mnil)) + +let ident_match_failure = Ident.create_predef_exn "Match_failure" +and ident_out_of_memory = Ident.create_predef_exn "Out_of_memory" +and ident_invalid_argument = Ident.create_predef_exn "Invalid_argument" +and ident_failure = Ident.create_predef_exn "Failure" +and ident_not_found = Ident.create_predef_exn "Not_found" +and ident_sys_error = Ident.create_predef_exn "Sys_error" +and ident_end_of_file = Ident.create_predef_exn "End_of_file" +and ident_division_by_zero = Ident.create_predef_exn "Division_by_zero" +and ident_stack_overflow = Ident.create_predef_exn "Stack_overflow" +and ident_sys_blocked_io = Ident.create_predef_exn "Sys_blocked_io" +and ident_assert_failure = Ident.create_predef_exn "Assert_failure" +and ident_undefined_recursive_module = + Ident.create_predef_exn "Undefined_recursive_module" + +let path_match_failure = Pident ident_match_failure +and path_assert_failure = Pident ident_assert_failure +and path_undefined_recursive_module = Pident ident_undefined_recursive_module + +let build_initial_env add_type add_exception empty_env = + let decl_abstr = + {type_params = []; + type_arity = 0; + type_kind = Type_abstract; + type_private = Public; + type_manifest = None; + type_variance = []} + and decl_bool = + {type_params = []; + type_arity = 0; + type_kind = Type_variant(["false", []; "true", []]); + type_private = Public; + type_manifest = None; + type_variance = []} + and decl_unit = + {type_params = []; + type_arity = 0; + type_kind = Type_variant(["()", []]); + type_private = Public; + type_manifest = None; + type_variance = []} + and decl_exn = + {type_params = []; + type_arity = 0; + type_kind = Type_variant []; + type_private = Public; + type_manifest = None; + type_variance = []} + and decl_array = + let tvar = newgenvar() in + {type_params = [tvar]; + type_arity = 1; + type_kind = Type_abstract; + type_private = Public; + type_manifest = None; + type_variance = [true, true, true]} + and decl_list = + let tvar = newgenvar() in + {type_params = [tvar]; + type_arity = 1; + type_kind = + Type_variant(["[]", []; "::", [tvar; type_list tvar]]); + type_private = Public; + type_manifest = None; + type_variance = [true, false, false]} + and decl_format6 = + {type_params = [ + newgenvar(); newgenvar(); newgenvar(); + newgenvar(); newgenvar(); newgenvar(); + ]; + type_arity = 6; + type_kind = Type_abstract; + type_private = Public; + type_manifest = None; + type_variance = [ + true, true, true; true, true, true; + true, true, true; true, true, true; + true, true, true; true, true, true; + ]} + and decl_option = + let tvar = newgenvar() in + {type_params = [tvar]; + type_arity = 1; + type_kind = Type_variant(["None", []; "Some", [tvar]]); + type_private = Public; + type_manifest = None; + type_variance = [true, false, false]} + and decl_lazy_t = + let tvar = newgenvar() in + {type_params = [tvar]; + type_arity = 1; + type_kind = Type_abstract; + type_private = Public; + type_manifest = None; + type_variance = [true, false, false]} + in + + add_exception ident_match_failure + [newgenty (Ttuple[type_string; type_int; type_int])] ( + add_exception ident_out_of_memory [] ( + add_exception ident_stack_overflow [] ( + add_exception ident_invalid_argument [type_string] ( + add_exception ident_failure [type_string] ( + add_exception ident_not_found [] ( + add_exception ident_sys_blocked_io [] ( + add_exception ident_sys_error [type_string] ( + add_exception ident_end_of_file [] ( + add_exception ident_division_by_zero [] ( + add_exception ident_assert_failure + [newgenty (Ttuple[type_string; type_int; type_int])] ( + add_exception ident_undefined_recursive_module + [newgenty (Ttuple[type_string; type_int; type_int])] ( + add_type ident_int64 decl_abstr ( + add_type ident_int32 decl_abstr ( + add_type ident_nativeint decl_abstr ( + add_type ident_lazy_t decl_lazy_t ( + add_type ident_option decl_option ( + add_type ident_format6 decl_format6 ( + add_type ident_list decl_list ( + add_type ident_array decl_array ( + add_type ident_exn decl_exn ( + add_type ident_unit decl_unit ( + add_type ident_bool decl_bool ( + add_type ident_float decl_abstr ( + add_type ident_string decl_abstr ( + add_type ident_char decl_abstr ( + add_type ident_int decl_abstr ( + empty_env))))))))))))))))))))))))))) + +let builtin_values = + List.map (fun id -> Ident.make_global id; (Ident.name id, id)) + [ident_match_failure; ident_out_of_memory; ident_stack_overflow; + ident_invalid_argument; + ident_failure; ident_not_found; ident_sys_error; ident_end_of_file; + ident_division_by_zero; ident_sys_blocked_io; + ident_assert_failure; ident_undefined_recursive_module ] diff --git a/typing/predef.mli b/typing/predef.mli new file mode 100644 index 0000000..db61ab1 --- /dev/null +++ b/typing/predef.mli @@ -0,0 +1,65 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: predef.mli,v 1.16 2006-10-24 20:54:58 weis Exp $ *) + +(* Predefined type constructors (with special typing rules in typecore) *) + +open Types + +val type_int: type_expr +val type_char: type_expr +val type_string: type_expr +val type_float: type_expr +val type_bool: type_expr +val type_unit: type_expr +val type_exn: type_expr +val type_array: type_expr -> type_expr +val type_list: type_expr -> type_expr +val type_option: type_expr -> type_expr +val type_nativeint: type_expr +val type_int32: type_expr +val type_int64: type_expr +val type_lazy_t: type_expr -> type_expr + +val path_int: Path.t +val path_char: Path.t +val path_string: Path.t +val path_float: Path.t +val path_bool: Path.t +val path_unit: Path.t +val path_exn: Path.t +val path_array: Path.t +val path_list: Path.t +val path_format6: Path.t +val path_option: Path.t +val path_nativeint: Path.t +val path_int32: Path.t +val path_int64: Path.t +val path_lazy_t: Path.t + +val path_match_failure: Path.t +val path_assert_failure : Path.t +val path_undefined_recursive_module : Path.t + +(* To build the initial environment. Since there is a nasty mutual + recursion between predef and env, we break it by parameterizing + over Env.t, Env.add_type and Env.add_exception. *) + +val build_initial_env: + (Ident.t -> type_declaration -> 'a -> 'a) -> + (Ident.t -> exception_declaration -> 'a -> 'a) -> + 'a -> 'a + +(* To initialize linker tables *) + +val builtin_values: (string * Ident.t) list diff --git a/typing/primitive.ml b/typing/primitive.ml new file mode 100644 index 0000000..41965f0 --- /dev/null +++ b/typing/primitive.ml @@ -0,0 +1,64 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: primitive.ml,v 1.9 2008-07-24 05:35:22 frisch Exp $ *) + +(* Description of primitive functions *) + +open Misc + +type description = + { prim_name: string; (* Name of primitive or C function *) + prim_arity: int; (* Number of arguments *) + prim_alloc: bool; (* Does it allocates or raise? *) + prim_native_name: string; (* Name of C function for the nat. code gen. *) + prim_native_float: bool } (* Does the above operate on unboxed floats? *) + +let parse_declaration arity decl = + match decl with + | name :: "noalloc" :: name2 :: "float" :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = false; + prim_native_name = name2; prim_native_float = true} + | name :: "noalloc" :: name2 :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = false; + prim_native_name = name2; prim_native_float = false} + | name :: name2 :: "float" :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = true; + prim_native_name = name2; prim_native_float = true} + | name :: "noalloc" :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = false; + prim_native_name = ""; prim_native_float = false} + | name :: name2 :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = true; + prim_native_name = name2; prim_native_float = false} + | name :: _ -> + {prim_name = name; prim_arity = arity; prim_alloc = true; + prim_native_name = ""; prim_native_float = false} + | [] -> + fatal_error "Primitive.parse_declaration" + +let description_list p = + let list = [p.prim_name] in + let list = if not p.prim_alloc then "noalloc" :: list else list in + let list = + if p.prim_native_name <> "" then p.prim_native_name :: list else list + in + let list = if p.prim_native_float then "float" :: list else list in + List.rev list + +let native_name p = + if p.prim_native_name <> "" + then p.prim_native_name + else p.prim_name + +let byte_name p = + p.prim_name diff --git a/typing/primitive.mli b/typing/primitive.mli new file mode 100644 index 0000000..2929130 --- /dev/null +++ b/typing/primitive.mli @@ -0,0 +1,29 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: primitive.mli,v 1.8 2008-07-24 05:35:22 frisch Exp $ *) + +(* Description of primitive functions *) + +type description = + { prim_name: string; (* Name of primitive or C function *) + prim_arity: int; (* Number of arguments *) + prim_alloc: bool; (* Does it allocates or raise? *) + prim_native_name: string; (* Name of C function for the nat. code gen. *) + prim_native_float: bool } (* Does the above operate on unboxed floats? *) + +val parse_declaration: int -> string list -> description + +val description_list: description -> string list + +val native_name: description -> string +val byte_name: description -> string diff --git a/typing/printtyp.ml b/typing/printtyp.ml new file mode 100644 index 0000000..345ecc7 --- /dev/null +++ b/typing/printtyp.ml @@ -0,0 +1,1012 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printtyp.ml,v 1.147 2008-07-19 02:13:09 garrigue Exp $ *) + +(* Printing functions *) + +open Misc +open Ctype +open Format +open Longident +open Path +open Asttypes +open Types +open Btype +open Outcometree + +(* Print a long identifier *) + +let rec longident ppf = function + | Lident s -> fprintf ppf "%s" s + | Ldot(p, s) -> fprintf ppf "%a.%s" longident p s + | Lapply(p1, p2) -> fprintf ppf "%a(%a)" longident p1 longident p2 + +(* Print an identifier *) + +let ident ppf id = fprintf ppf "%s" (Ident.name id) + +(* Print a path *) + +let ident_pervasive = Ident.create_persistent "Pervasives" + +let rec tree_of_path = function + | Pident id -> + Oide_ident (Ident.name id) + | Pdot(Pident id, s, pos) when Ident.same id ident_pervasive -> + Oide_ident s + | Pdot(p, s, pos) -> + Oide_dot (tree_of_path p, s) + | Papply(p1, p2) -> + Oide_apply (tree_of_path p1, tree_of_path p2) + +let rec path ppf = function + | Pident id -> + ident ppf id + | Pdot(Pident id, s, pos) when Ident.same id ident_pervasive -> + fprintf ppf "%s" s + | Pdot(p, s, pos) -> + fprintf ppf "%a.%s" path p s + | Papply(p1, p2) -> + fprintf ppf "%a(%a)" path p1 path p2 + +(* Print a recursive annotation *) + +let tree_of_rec = function + | Trec_not -> Orec_not + | Trec_first -> Orec_first + | Trec_next -> Orec_next + +(* Print a raw type expression, with sharing *) + +let raw_list pr ppf = function + [] -> fprintf ppf "[]" + | a :: l -> + fprintf ppf "@[<1>[%a%t]@]" pr a + (fun ppf -> List.iter (fun x -> fprintf ppf ";@,%a" pr x) l) + +let rec safe_kind_repr v = function + Fvar {contents=Some k} -> + if List.memq k v then "Fvar loop" else + safe_kind_repr (k::v) k + | Fvar _ -> "Fvar None" + | Fpresent -> "Fpresent" + | Fabsent -> "Fabsent" + +let rec safe_commu_repr v = function + Cok -> "Cok" + | Cunknown -> "Cunknown" + | Clink r -> + if List.memq r v then "Clink loop" else + safe_commu_repr (r::v) !r + +let rec safe_repr v = function + {desc = Tlink t} when not (List.memq t v) -> + safe_repr (t::v) t + | t -> t + +let rec list_of_memo = function + Mnil -> [] + | Mcons (priv, p, t1, t2, rem) -> p :: list_of_memo rem + | Mlink rem -> list_of_memo !rem + +let visited = ref [] +let rec raw_type ppf ty = + let ty = safe_repr [] ty in + if List.memq ty !visited then fprintf ppf "{id=%d}" ty.id else begin + visited := ty :: !visited; + fprintf ppf "@[<1>{id=%d;level=%d;desc=@,%a}@]" ty.id ty.level + raw_type_desc ty.desc + end +and raw_type_list tl = raw_list raw_type tl +and raw_type_desc ppf = function + Tvar -> fprintf ppf "Tvar" + | Tarrow(l,t1,t2,c) -> + fprintf ppf "@[<hov1>Tarrow(%s,@,%a,@,%a,@,%s)@]" + l raw_type t1 raw_type t2 + (safe_commu_repr [] c) + | Ttuple tl -> + fprintf ppf "@[<1>Ttuple@,%a@]" raw_type_list tl + | Tconstr (p, tl, abbrev) -> + fprintf ppf "@[<hov1>Tconstr(@,%a,@,%a,@,%a)@]" path p + raw_type_list tl + (raw_list path) (list_of_memo !abbrev) + | Tobject (t, nm) -> + fprintf ppf "@[<hov1>Tobject(@,%a,@,@[<1>ref%t@])@]" raw_type t + (fun ppf -> + match !nm with None -> fprintf ppf " None" + | Some(p,tl) -> + fprintf ppf "(Some(@,%a,@,%a))" path p raw_type_list tl) + | Tfield (f, k, t1, t2) -> + fprintf ppf "@[<hov1>Tfield(@,%s,@,%s,@,%a,@;<0 -1>%a)@]" f + (safe_kind_repr [] k) + raw_type t1 raw_type t2 + | Tnil -> fprintf ppf "Tnil" + | Tlink t -> fprintf ppf "@[<1>Tlink@,%a@]" raw_type t + | Tsubst t -> fprintf ppf "@[<1>Tsubst@,%a@]" raw_type t + | Tunivar -> fprintf ppf "Tunivar" + | Tpoly (t, tl) -> + fprintf ppf "@[<hov1>Tpoly(@,%a,@,%a)@]" + raw_type t + raw_type_list tl + | Tvariant row -> + fprintf ppf + "@[<hov1>{@[%s@,%a;@]@ @[%s@,%a;@]@ %s%b;@ %s%b;@ @[<1>%s%t@]}@]" + "row_fields=" + (raw_list (fun ppf (l, f) -> + fprintf ppf "@[%s,@ %a@]" l raw_field f)) + row.row_fields + "row_more=" raw_type row.row_more + "row_closed=" row.row_closed + "row_fixed=" row.row_fixed + "row_name=" + (fun ppf -> + match row.row_name with None -> fprintf ppf "None" + | Some(p,tl) -> + fprintf ppf "Some(@,%a,@,%a)" path p raw_type_list tl) + +and raw_field ppf = function + Rpresent None -> fprintf ppf "Rpresent None" + | Rpresent (Some t) -> fprintf ppf "@[<1>Rpresent(Some@,%a)@]" raw_type t + | Reither (c,tl,m,e) -> + fprintf ppf "@[<hov1>Reither(%b,@,%a,@,%b,@,@[<1>ref%t@])@]" c + raw_type_list tl m + (fun ppf -> + match !e with None -> fprintf ppf " None" + | Some f -> fprintf ppf "@,@[<1>(%a)@]" raw_field f) + | Rabsent -> fprintf ppf "Rabsent" + +let raw_type_expr ppf t = + visited := []; + raw_type ppf t; + visited := [] + +(* Print a type expression *) + +let names = ref ([] : (type_expr * string) list) +let name_counter = ref 0 + +let reset_names () = names := []; name_counter := 0 + +let new_name () = + let name = + if !name_counter < 26 + then String.make 1 (Char.chr(97 + !name_counter)) + else String.make 1 (Char.chr(97 + !name_counter mod 26)) ^ + string_of_int(!name_counter / 26) in + incr name_counter; + name + +let name_of_type t = + try List.assq t !names with Not_found -> + let name = new_name () in + names := (t, name) :: !names; + name + +let check_name_of_type t = ignore(name_of_type t) + +let non_gen_mark sch ty = + if sch && ty.desc = Tvar && ty.level <> generic_level then "_" else "" + +let print_name_of_type sch ppf t = + fprintf ppf "'%s%s" (non_gen_mark sch t) (name_of_type t) + +let visited_objects = ref ([] : type_expr list) +let aliased = ref ([] : type_expr list) +let delayed = ref ([] : type_expr list) + +let add_delayed t = + if not (List.memq t !delayed) then delayed := t :: !delayed + +let is_aliased ty = List.memq (proxy ty) !aliased +let add_alias ty = + let px = proxy ty in + if not (is_aliased px) then aliased := px :: !aliased +let aliasable ty = + match ty.desc with Tvar | Tunivar | Tpoly _ -> false | _ -> true + +let namable_row row = + row.row_name <> None && + List.for_all + (fun (_, f) -> + match row_field_repr f with + | Reither(c, l, _, _) -> + row.row_closed && if c then l = [] else List.length l = 1 + | _ -> true) + row.row_fields + +let rec mark_loops_rec visited ty = + let ty = repr ty in + let px = proxy ty in + if List.memq px visited && aliasable ty then add_alias px else + let visited = px :: visited in + match ty.desc with + | Tvar -> () + | Tarrow(_, ty1, ty2, _) -> + mark_loops_rec visited ty1; mark_loops_rec visited ty2 + | Ttuple tyl -> List.iter (mark_loops_rec visited) tyl + | Tconstr(_, tyl, _) -> + List.iter (mark_loops_rec visited) tyl + | Tvariant row -> + if List.memq px !visited_objects then add_alias px else + begin + let row = row_repr row in + if not (static_row row) then + visited_objects := px :: !visited_objects; + match row.row_name with + | Some(p, tyl) when namable_row row -> + List.iter (mark_loops_rec visited) tyl + | _ -> + iter_row (mark_loops_rec visited) row + end + | Tobject (fi, nm) -> + if List.memq px !visited_objects then add_alias px else + begin + if opened_object ty then + visited_objects := px :: !visited_objects; + begin match !nm with + | None -> + let fields, _ = flatten_fields fi in + List.iter + (fun (_, kind, ty) -> + if field_kind_repr kind = Fpresent then + mark_loops_rec visited ty) + fields + | Some (_, l) -> + List.iter (mark_loops_rec visited) (List.tl l) + end + end + | Tfield(_, kind, ty1, ty2) when field_kind_repr kind = Fpresent -> + mark_loops_rec visited ty1; mark_loops_rec visited ty2 + | Tfield(_, _, _, ty2) -> + mark_loops_rec visited ty2 + | Tnil -> () + | Tsubst ty -> mark_loops_rec visited ty + | Tlink _ -> fatal_error "Printtyp.mark_loops_rec (2)" + | Tpoly (ty, tyl) -> + List.iter (fun t -> add_alias t) tyl; + mark_loops_rec visited ty + | Tunivar -> () + +let mark_loops ty = + normalize_type Env.empty ty; + mark_loops_rec [] ty;; + +let reset_loop_marks () = + visited_objects := []; aliased := []; delayed := [] + +let reset () = + reset_names (); reset_loop_marks () + +let reset_and_mark_loops ty = + reset (); mark_loops ty + +let reset_and_mark_loops_list tyl = + reset (); List.iter mark_loops tyl + +(* Disabled in classic mode when printing an unification error *) +let print_labels = ref true +let print_label ppf l = + if !print_labels && l <> "" || is_optional l then fprintf ppf "%s:" l + +let rec tree_of_typexp sch ty = + let ty = repr ty in + let px = proxy ty in + if List.mem_assq px !names && not (List.memq px !delayed) then + let mark = is_non_gen sch ty in + Otyp_var (mark, name_of_type px) else + + let pr_typ () = + match ty.desc with + | Tvar -> + Otyp_var (is_non_gen sch ty, name_of_type ty) + | Tarrow(l, ty1, ty2, _) -> + let pr_arrow l ty1 ty2 = + let lab = + if !print_labels && l <> "" || is_optional l then l else "" + in + let t1 = + if is_optional l then + match (repr ty1).desc with + | Tconstr(path, [ty], _) + when Path.same path Predef.path_option -> + tree_of_typexp sch ty + | _ -> Otyp_stuff "<hidden>" + else tree_of_typexp sch ty1 in + Otyp_arrow (lab, t1, tree_of_typexp sch ty2) in + pr_arrow l ty1 ty2 + | Ttuple tyl -> + Otyp_tuple (tree_of_typlist sch tyl) + | Tconstr(p, tyl, abbrev) -> + Otyp_constr (tree_of_path p, tree_of_typlist sch tyl) + | Tvariant row -> + let row = row_repr row in + let fields = + if row.row_closed then + List.filter (fun (_, f) -> row_field_repr f <> Rabsent) + row.row_fields + else row.row_fields in + let present = + List.filter + (fun (_, f) -> + match row_field_repr f with + | Rpresent _ -> true + | _ -> false) + fields in + let all_present = List.length present = List.length fields in + begin match row.row_name with + | Some(p, tyl) when namable_row row -> + let id = tree_of_path p in + let args = tree_of_typlist sch tyl in + if row.row_closed && all_present then + Otyp_constr (id, args) + else + let non_gen = is_non_gen sch px in + let tags = + if all_present then None else Some (List.map fst present) in + Otyp_variant (non_gen, Ovar_name(tree_of_path p, args), + row.row_closed, tags) + | _ -> + let non_gen = + not (row.row_closed && all_present) && is_non_gen sch px in + let fields = List.map (tree_of_row_field sch) fields in + let tags = + if all_present then None else Some (List.map fst present) in + Otyp_variant (non_gen, Ovar_fields fields, row.row_closed, tags) + end + | Tobject (fi, nm) -> + tree_of_typobject sch fi nm + | Tsubst ty -> + tree_of_typexp sch ty + | Tlink _ | Tnil | Tfield _ -> + fatal_error "Printtyp.tree_of_typexp" + | Tpoly (ty, []) -> + tree_of_typexp sch ty + | Tpoly (ty, tyl) -> + let tyl = List.map repr tyl in + (* let tyl = List.filter is_aliased tyl in *) + if tyl = [] then tree_of_typexp sch ty else begin + let old_delayed = !delayed in + List.iter add_delayed tyl; + let tl = List.map name_of_type tyl in + let tr = Otyp_poly (tl, tree_of_typexp sch ty) in + delayed := old_delayed; tr + end + | Tunivar -> + Otyp_var (false, name_of_type ty) + in + if List.memq px !delayed then delayed := List.filter ((!=) px) !delayed; + if is_aliased px && aliasable ty then begin + check_name_of_type px; + Otyp_alias (pr_typ (), name_of_type px) end + else pr_typ () + +and tree_of_row_field sch (l, f) = + match row_field_repr f with + | Rpresent None | Reither(true, [], _, _) -> (l, false, []) + | Rpresent(Some ty) -> (l, false, [tree_of_typexp sch ty]) + | Reither(c, tyl, _, _) -> + if c (* contradiction: un constructeur constant qui a un argument *) + then (l, true, tree_of_typlist sch tyl) + else (l, false, tree_of_typlist sch tyl) + | Rabsent -> (l, false, [] (* une erreur, en fait *)) + +and tree_of_typlist sch tyl = + List.map (tree_of_typexp sch) tyl + +and tree_of_typobject sch fi nm = + begin match !nm with + | None -> + let pr_fields fi = + let (fields, rest) = flatten_fields fi in + let present_fields = + List.fold_right + (fun (n, k, t) l -> + match field_kind_repr k with + | Fpresent -> (n, t) :: l + | _ -> l) + fields [] in + let sorted_fields = + Sort.list (fun (n, _) (n', _) -> n <= n') present_fields in + tree_of_typfields sch rest sorted_fields in + let (fields, rest) = pr_fields fi in + Otyp_object (fields, rest) + | Some (p, ty :: tyl) -> + let non_gen = is_non_gen sch (repr ty) in + let args = tree_of_typlist sch tyl in + Otyp_class (non_gen, tree_of_path p, args) + | _ -> + fatal_error "Printtyp.tree_of_typobject" + end + +and is_non_gen sch ty = + sch && ty.desc = Tvar && ty.level <> generic_level + +and tree_of_typfields sch rest = function + | [] -> + let rest = + match rest.desc with + | Tvar | Tunivar -> Some (is_non_gen sch rest) + | Tconstr _ -> Some false + | Tnil -> None + | _ -> fatal_error "typfields (1)" + in + ([], rest) + | (s, t) :: l -> + let field = (s, tree_of_typexp sch t) in + let (fields, rest) = tree_of_typfields sch rest l in + (field :: fields, rest) + +let typexp sch prio ppf ty = + !Oprint.out_type ppf (tree_of_typexp sch ty) + +let type_expr ppf ty = typexp false 0 ppf ty + +and type_sch ppf ty = typexp true 0 ppf ty + +and type_scheme ppf ty = reset_and_mark_loops ty; typexp true 0 ppf ty + +(* Maxence *) +let type_scheme_max ?(b_reset_names=true) ppf ty = + if b_reset_names then reset_names () ; + typexp true 0 ppf ty +(* Fin Maxence *) + +let tree_of_type_scheme ty = reset_and_mark_loops ty; tree_of_typexp true ty + +(* Print one type declaration *) + +let tree_of_constraints params = + List.fold_right + (fun ty list -> + let ty' = unalias ty in + if proxy ty != proxy ty' then + let tr = tree_of_typexp true ty in + (tr, tree_of_typexp true ty') :: list + else list) + params [] + +let filter_params tyl = + let params = + List.fold_left + (fun tyl ty -> + let ty = repr ty in + if List.memq ty tyl then Btype.newgenty (Tsubst ty) :: tyl + else ty :: tyl) + [] tyl + in List.rev params + +let string_of_mutable = function + | Immutable -> "" + | Mutable -> "mutable " + +let rec tree_of_type_decl id decl = + + reset(); + + let params = filter_params decl.type_params in + + List.iter add_alias params; + List.iter mark_loops params; + List.iter check_name_of_type (List.map proxy params); + let ty_manifest = + match decl.type_manifest with + | None -> None + | Some ty -> + let ty = + (* Special hack to hide variant name *) + match repr ty with {desc=Tvariant row} -> + let row = row_repr row in + begin match row.row_name with + Some (Pident id', _) when Ident.same id id' -> + newgenty (Tvariant {row with row_name = None}) + | _ -> ty + end + | _ -> ty + in + mark_loops ty; + Some ty + in + begin match decl.type_kind with + | Type_abstract -> () + | Type_variant [] -> () + | Type_variant cstrs -> + List.iter (fun (_, args) -> List.iter mark_loops args) cstrs + | Type_record(l, rep) -> + List.iter (fun (_, _, ty) -> mark_loops ty) l + end; + + let type_param = + function + | Otyp_var (_, id) -> id + | _ -> "?" + in + let type_defined decl = + let abstr = + match decl.type_kind with + Type_abstract -> + begin match decl.type_manifest with + None -> true + | Some ty -> has_constr_row ty + end + | Type_variant _ | Type_record(_,_) -> + decl.type_private = Private + in + let vari = + List.map2 + (fun ty (co,cn,ct) -> + if abstr || (repr ty).desc <> Tvar then (co,cn) else (true,true)) + decl.type_params decl.type_variance + in + (Ident.name id, + List.map2 (fun ty cocn -> type_param (tree_of_typexp false ty), cocn) + params vari) + in + let tree_of_manifest ty1 = + match ty_manifest with + | None -> ty1 + | Some ty -> Otyp_manifest (tree_of_typexp false ty, ty1) + in + let (name, args) = type_defined decl in + let constraints = tree_of_constraints params in + let ty, priv = + match decl.type_kind with + | Type_abstract -> + begin match ty_manifest with + | None -> (Otyp_abstract, Public) + | Some ty -> + tree_of_typexp false ty, decl.type_private + end + | Type_variant cstrs -> + tree_of_manifest (Otyp_sum (List.map tree_of_constructor cstrs)), + decl.type_private + | Type_record(lbls, rep) -> + tree_of_manifest (Otyp_record (List.map tree_of_label lbls)), + decl.type_private + in + (name, args, ty, priv, constraints) + +and tree_of_constructor (name, args) = + (name, tree_of_typlist false args) + +and tree_of_label (name, mut, arg) = + (name, mut = Mutable, tree_of_typexp false arg) + +let tree_of_type_declaration id decl rs = + Osig_type (tree_of_type_decl id decl, tree_of_rec rs) + +let type_declaration id ppf decl = + !Oprint.out_sig_item ppf (tree_of_type_declaration id decl Trec_first) + +(* Print an exception declaration *) + +let tree_of_exception_declaration id decl = + reset_and_mark_loops_list decl; + let tyl = tree_of_typlist false decl in + Osig_exception (Ident.name id, tyl) + +let exception_declaration id ppf decl = + !Oprint.out_sig_item ppf (tree_of_exception_declaration id decl) + +(* Print a value declaration *) + +let tree_of_value_description id decl = + let id = Ident.name id in + let ty = tree_of_type_scheme decl.val_type in + let prims = + match decl.val_kind with + | Val_prim p -> Primitive.description_list p + | _ -> [] + in + Osig_value (id, ty, prims) + +let value_description id ppf decl = + !Oprint.out_sig_item ppf (tree_of_value_description id decl) + +(* Print a class type *) + +let class_var sch ppf l (m, t) = + fprintf ppf + "@ @[<2>val %s%s :@ %a@]" (string_of_mutable m) l (typexp sch 0) t + +let method_type (_, kind, ty) = + match field_kind_repr kind, repr ty with + Fpresent, {desc=Tpoly(ty, _)} -> ty + | _ , ty -> ty + +let tree_of_metho sch concrete csil (lab, kind, ty) = + if lab <> dummy_method then begin + let kind = field_kind_repr kind in + let priv = kind <> Fpresent in + let virt = not (Concr.mem lab concrete) in + let ty = method_type (lab, kind, ty) in + Ocsg_method (lab, priv, virt, tree_of_typexp sch ty) :: csil + end + else csil + +let rec prepare_class_type params = function + | Tcty_constr (p, tyl, cty) -> + let sty = Ctype.self_type cty in + if List.memq (proxy sty) !visited_objects + || List.exists (fun ty -> (repr ty).desc <> Tvar) params + || List.exists (deep_occur sty) tyl + then prepare_class_type params cty + else List.iter mark_loops tyl + | Tcty_signature sign -> + let sty = repr sign.cty_self in + (* Self may have a name *) + let px = proxy sty in + if List.memq px !visited_objects then add_alias sty + else visited_objects := px :: !visited_objects; + let (fields, _) = + Ctype.flatten_fields (Ctype.object_fields sign.cty_self) + in + List.iter (fun met -> mark_loops (method_type met)) fields; + Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.cty_vars + | Tcty_fun (_, ty, cty) -> + mark_loops ty; + prepare_class_type params cty + +let rec tree_of_class_type sch params = + function + | Tcty_constr (p', tyl, cty) -> + let sty = Ctype.self_type cty in + if List.memq (proxy sty) !visited_objects + || List.exists (fun ty -> (repr ty).desc <> Tvar) params + then + tree_of_class_type sch params cty + else + Octy_constr (tree_of_path p', tree_of_typlist true tyl) + | Tcty_signature sign -> + let sty = repr sign.cty_self in + let self_ty = + if is_aliased sty then + Some (Otyp_var (false, name_of_type (proxy sty))) + else None + in + let (fields, _) = + Ctype.flatten_fields (Ctype.object_fields sign.cty_self) + in + let csil = [] in + let csil = + List.fold_left + (fun csil (ty1, ty2) -> Ocsg_constraint (ty1, ty2) :: csil) + csil (tree_of_constraints params) + in + let all_vars = + Vars.fold (fun l (m, v, t) all -> (l, m, v, t) :: all) sign.cty_vars [] + in + (* Consequence of PR#3607: order of Map.fold has changed! *) + let all_vars = List.rev all_vars in + let csil = + List.fold_left + (fun csil (l, m, v, t) -> + Ocsg_value (l, m = Mutable, v = Virtual, tree_of_typexp sch t) + :: csil) + csil all_vars + in + let csil = + List.fold_left (tree_of_metho sch sign.cty_concr) csil fields + in + Octy_signature (self_ty, List.rev csil) + | Tcty_fun (l, ty, cty) -> + let lab = if !print_labels && l <> "" || is_optional l then l else "" in + let ty = + if is_optional l then + match (repr ty).desc with + | Tconstr(path, [ty], _) when Path.same path Predef.path_option -> ty + | _ -> newconstr (Path.Pident(Ident.create "<hidden>")) [] + else ty in + let tr = tree_of_typexp sch ty in + Octy_fun (lab, tr, tree_of_class_type sch params cty) + +let class_type ppf cty = + reset (); + prepare_class_type [] cty; + !Oprint.out_class_type ppf (tree_of_class_type false [] cty) + +let tree_of_class_param param variance = + (match tree_of_typexp true param with + Otyp_var (_, s) -> s + | _ -> "?"), + if (repr param).desc = Tvar then (true, true) else variance + +let tree_of_class_params params = + let tyl = tree_of_typlist true params in + List.map (function Otyp_var (_, s) -> s | _ -> "?") tyl + +let tree_of_class_declaration id cl rs = + let params = filter_params cl.cty_params in + + reset (); + List.iter add_alias params; + prepare_class_type params cl.cty_type; + let sty = self_type cl.cty_type in + List.iter mark_loops params; + + List.iter check_name_of_type (List.map proxy params); + if is_aliased sty then check_name_of_type (proxy sty); + + let vir_flag = cl.cty_new = None in + Osig_class + (vir_flag, Ident.name id, + List.map2 tree_of_class_param params cl.cty_variance, + tree_of_class_type true params cl.cty_type, + tree_of_rec rs) + +let class_declaration id ppf cl = + !Oprint.out_sig_item ppf (tree_of_class_declaration id cl Trec_first) + +let tree_of_cltype_declaration id cl rs = + let params = List.map repr cl.clty_params in + + reset (); + List.iter add_alias params; + prepare_class_type params cl.clty_type; + let sty = self_type cl.clty_type in + List.iter mark_loops params; + + List.iter check_name_of_type (List.map proxy params); + if is_aliased sty then check_name_of_type (proxy sty); + + let sign = Ctype.signature_of_class_type cl.clty_type in + + let virt = + let (fields, _) = + Ctype.flatten_fields (Ctype.object_fields sign.cty_self) in + List.exists + (fun (lab, _, ty) -> + not (lab = dummy_method || Concr.mem lab sign.cty_concr)) + fields + || Vars.fold (fun _ (_,vr,_) b -> vr = Virtual || b) sign.cty_vars false + in + + Osig_class_type + (virt, Ident.name id, + List.map2 tree_of_class_param params cl.clty_variance, + tree_of_class_type true params cl.clty_type, + tree_of_rec rs) + +let cltype_declaration id ppf cl = + !Oprint.out_sig_item ppf (tree_of_cltype_declaration id cl Trec_first) + +(* Print a module type *) + +let rec tree_of_modtype = function + | Tmty_ident p -> + Omty_ident (tree_of_path p) + | Tmty_signature sg -> + Omty_signature (tree_of_signature sg) + | Tmty_functor(param, ty_arg, ty_res) -> + Omty_functor + (Ident.name param, tree_of_modtype ty_arg, tree_of_modtype ty_res) + +and tree_of_signature = function + | [] -> [] + | Tsig_value(id, decl) :: rem -> + tree_of_value_description id decl :: tree_of_signature rem + | Tsig_type(id, _, _) :: rem when is_row_name (Ident.name id) -> + tree_of_signature rem + | Tsig_type(id, decl, rs) :: rem -> + Osig_type(tree_of_type_decl id decl, tree_of_rec rs) :: + tree_of_signature rem + | Tsig_exception(id, decl) :: rem -> + tree_of_exception_declaration id decl :: tree_of_signature rem + | Tsig_module(id, mty, rs) :: rem -> + Osig_module (Ident.name id, tree_of_modtype mty, tree_of_rec rs) :: + tree_of_signature rem + | Tsig_modtype(id, decl) :: rem -> + tree_of_modtype_declaration id decl :: tree_of_signature rem + | Tsig_class(id, decl, rs) :: ctydecl :: tydecl1 :: tydecl2 :: rem -> + tree_of_class_declaration id decl rs :: tree_of_signature rem + | Tsig_cltype(id, decl, rs) :: tydecl1 :: tydecl2 :: rem -> + tree_of_cltype_declaration id decl rs :: tree_of_signature rem + | _ -> + assert false + +and tree_of_modtype_declaration id decl = + let mty = + match decl with + | Tmodtype_abstract -> Omty_abstract + | Tmodtype_manifest mty -> tree_of_modtype mty + in + Osig_modtype (Ident.name id, mty) + +let tree_of_module id mty rs = + Osig_module (Ident.name id, tree_of_modtype mty, tree_of_rec rs) + +let modtype ppf mty = !Oprint.out_module_type ppf (tree_of_modtype mty) +let modtype_declaration id ppf decl = + !Oprint.out_sig_item ppf (tree_of_modtype_declaration id decl) + +(* Print a signature body (used by -i when compiling a .ml) *) + +let print_signature ppf tree = + fprintf ppf "@[<v>%a@]" !Oprint.out_signature tree + +let signature ppf sg = + fprintf ppf "%a" print_signature (tree_of_signature sg) + +(* Print an unification error *) + +let type_expansion t ppf t' = + if t == t' then type_expr ppf t else + let t' = if proxy t == proxy t' then unalias t' else t' in + fprintf ppf "@[<2>%a@ =@ %a@]" type_expr t type_expr t' + +let rec trace fst txt ppf = function + | (t1, t1') :: (t2, t2') :: rem -> + if not fst then fprintf ppf "@,"; + fprintf ppf "@[Type@;<1 2>%a@ %s@;<1 2>%a@] %a" + (type_expansion t1) t1' txt (type_expansion t2) t2' + (trace false txt) rem + | _ -> () + +let rec filter_trace = function + | (t1, t1') :: (t2, t2') :: rem -> + let rem' = filter_trace rem in + if t1 == t1' && t2 == t2' + then rem' + else (t1, t1') :: (t2, t2') :: rem' + | _ -> [] + +(* Hide variant name and var, to force printing the expanded type *) +let hide_variant_name t = + match repr t with + | {desc = Tvariant row} as t when (row_repr row).row_name <> None -> + newty2 t.level + (Tvariant {(row_repr row) with row_name = None; + row_more = newty2 (row_more row).level Tvar}) + | _ -> t + +let prepare_expansion (t, t') = + let t' = hide_variant_name t' in + mark_loops t; if t != t' then mark_loops t'; + (t, t') + +let may_prepare_expansion compact (t, t') = + match (repr t').desc with + Tvariant _ | Tobject _ when compact -> + mark_loops t; (t, t) + | _ -> prepare_expansion (t, t') + +let print_tags ppf fields = + match fields with [] -> () + | (t, _) :: fields -> + fprintf ppf "`%s" t; + List.iter (fun (t, _) -> fprintf ppf ",@ `%s" t) fields + +let has_explanation unif t3 t4 = + match t3.desc, t4.desc with + Tfield _, _ | _, Tfield _ + | Tunivar, Tvar | Tvar, Tunivar + | Tvariant _, Tvariant _ -> true + | Tconstr (p, _, _), Tvar | Tvar, Tconstr (p, _, _) -> + unif && min t3.level t4.level < Path.binding_time p + | _ -> false + +let rec mismatch unif = function + (_, t) :: (_, t') :: rem -> + begin match mismatch unif rem with + Some _ as m -> m + | None -> + if has_explanation unif t t' then Some(t,t') else None + end + | [] -> None + | _ -> assert false + +let explanation unif t3 t4 ppf = + match t3.desc, t4.desc with + | Tfield _, Tvar | Tvar, Tfield _ -> + fprintf ppf "@,Self type cannot escape its class" + | Tconstr (p, _, _), Tvar + when unif && t4.level < Path.binding_time p -> + fprintf ppf + "@,@[The type constructor@;<1 2>%a@ would escape its scope@]" + path p + | Tvar, Tconstr (p, _, _) + when unif && t3.level < Path.binding_time p -> + fprintf ppf + "@,@[The type constructor@;<1 2>%a@ would escape its scope@]" + path p + | Tvar, Tunivar | Tunivar, Tvar -> + fprintf ppf "@,The universal variable %a would escape its scope" + type_expr (if t3.desc = Tunivar then t3 else t4) + | Tfield (lab, _, _, _), _ + | _, Tfield (lab, _, _, _) when lab = dummy_method -> + fprintf ppf + "@,Self type cannot be unified with a closed object type" + | Tfield (l, _, _, _), Tfield (l', _, _, _) when l = l' -> + fprintf ppf "@,Types for method %s are incompatible" l + | _, Tfield (l, _, _, _) -> + fprintf ppf + "@,@[The first object type has no method %s@]" l + | Tfield (l, _, _, _), _ -> + fprintf ppf + "@,@[The second object type has no method %s@]" l + | Tvariant row1, Tvariant row2 -> + let row1 = row_repr row1 and row2 = row_repr row2 in + begin match + row1.row_fields, row1.row_closed, row2.row_fields, row2.row_closed with + | [], true, [], true -> + fprintf ppf "@,These two variant types have no intersection" + | [], true, fields, _ -> + fprintf ppf + "@,@[The first variant type does not allow tag(s)@ @[<hov>%a@]@]" + print_tags fields + | fields, _, [], true -> + fprintf ppf + "@,@[The second variant type does not allow tag(s)@ @[<hov>%a@]@]" + print_tags fields + | [l1,_], true, [l2,_], true when l1 = l2 -> + fprintf ppf "@,Types for tag `%s are incompatible" l1 + | _ -> () + end + | _ -> () + +let explanation unif mis ppf = + match mis with + None -> () + | Some (t3, t4) -> explanation unif t3 t4 ppf + +let unification_error unif tr txt1 ppf txt2 = + reset (); + let tr = List.map (fun (t, t') -> (t, hide_variant_name t')) tr in + let mis = mismatch unif tr in + match tr with + | [] | _ :: [] -> assert false + | t1 :: t2 :: tr -> + try + let tr = filter_trace tr in + let t1, t1' = may_prepare_expansion (tr = []) t1 + and t2, t2' = may_prepare_expansion (tr = []) t2 in + print_labels := not !Clflags.classic; + let tr = List.map prepare_expansion tr in + fprintf ppf + "@[<v>\ + @[%t@;<1 2>%a@ \ + %t@;<1 2>%a\ + @]%a%t\ + @]" + txt1 (type_expansion t1) t1' + txt2 (type_expansion t2) t2' + (trace false "is not compatible with type") tr + (explanation unif mis); + print_labels := true + with exn -> + print_labels := true; + raise exn + +let report_unification_error ppf tr txt1 txt2 = + unification_error true tr txt1 ppf txt2;; + +let trace fst txt ppf tr = + print_labels := not !Clflags.classic; + try match tr with + t1 :: t2 :: tr' -> + if fst then trace fst txt ppf (t1 :: t2 :: filter_trace tr') + else trace fst txt ppf (filter_trace tr); + print_labels := true + | _ -> () + with exn -> + print_labels := true; + raise exn + +let report_subtyping_error ppf tr1 txt1 tr2 = + reset (); + let tr1 = List.map prepare_expansion tr1 + and tr2 = List.map prepare_expansion tr2 in + trace true txt1 ppf tr1; + if tr2 = [] then () else + let mis = mismatch true tr2 in + trace false "is not compatible with type" ppf tr2; + explanation true mis ppf diff --git a/typing/printtyp.mli b/typing/printtyp.mli new file mode 100644 index 0000000..306981d --- /dev/null +++ b/typing/printtyp.mli @@ -0,0 +1,68 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: printtyp.mli,v 1.27 2006-04-16 23:28:22 doligez Exp $ *) + +(* Printing functions *) + +open Format +open Types +open Outcometree + +val longident: formatter -> Longident.t -> unit +val ident: formatter -> Ident.t -> unit +val tree_of_path: Path.t -> out_ident +val path: formatter -> Path.t -> unit +val raw_type_expr: formatter -> type_expr -> unit +val reset: unit -> unit +val mark_loops: type_expr -> unit +val reset_and_mark_loops: type_expr -> unit +val reset_and_mark_loops_list: type_expr list -> unit +val type_expr: formatter -> type_expr -> unit +val tree_of_type_scheme: type_expr -> out_type +val type_sch : formatter -> type_expr -> unit +val type_scheme: formatter -> type_expr -> unit +(* Maxence *) +val reset_names: unit -> unit +val type_scheme_max: ?b_reset_names: bool -> + formatter -> type_expr -> unit +(* Fin Maxence *) +val tree_of_value_description: Ident.t -> value_description -> out_sig_item +val value_description: Ident.t -> formatter -> value_description -> unit +val tree_of_type_declaration: Ident.t -> type_declaration -> rec_status -> out_sig_item +val type_declaration: Ident.t -> formatter -> type_declaration -> unit +val tree_of_exception_declaration: Ident.t -> exception_declaration -> out_sig_item +val exception_declaration: Ident.t -> formatter -> exception_declaration -> unit +val tree_of_module: Ident.t -> module_type -> rec_status -> out_sig_item +val modtype: formatter -> module_type -> unit +val signature: formatter -> signature -> unit +val tree_of_modtype_declaration: Ident.t -> modtype_declaration -> out_sig_item +val modtype_declaration: Ident.t -> formatter -> modtype_declaration -> unit +val class_type: formatter -> class_type -> unit +val tree_of_class_declaration: Ident.t -> class_declaration -> rec_status -> out_sig_item +val class_declaration: Ident.t -> formatter -> class_declaration -> unit +val tree_of_cltype_declaration: Ident.t -> cltype_declaration -> rec_status -> out_sig_item +val cltype_declaration: Ident.t -> formatter -> cltype_declaration -> unit +val type_expansion: type_expr -> Format.formatter -> type_expr -> unit +val prepare_expansion: type_expr * type_expr -> type_expr * type_expr +val trace: bool -> string -> formatter -> (type_expr * type_expr) list -> unit +val unification_error: + bool -> (type_expr * type_expr) list -> + (formatter -> unit) -> formatter -> (formatter -> unit) -> + unit +val report_unification_error: + formatter -> (type_expr * type_expr) list -> + (formatter -> unit) -> (formatter -> unit) -> + unit +val report_subtyping_error: + formatter -> (type_expr * type_expr) list -> + string -> (type_expr * type_expr) list -> unit diff --git a/typing/stypes.ml b/typing/stypes.ml new file mode 100644 index 0000000..9f25e29 --- /dev/null +++ b/typing/stypes.ml @@ -0,0 +1,167 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2003 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: stypes.ml,v 1.11 2008-07-29 15:42:44 doligez Exp $ *) + +(* Recording and dumping (partial) type information *) + +(* + We record all types in a list as they are created. + This means we can dump type information even if type inference fails, + which is extremely important, since type information is most + interesting in case of errors. +*) + +open Annot;; +open Format;; +open Lexing;; +open Location;; +open Typedtree;; + +type annotation = + | Ti_pat of pattern + | Ti_expr of expression + | Ti_class of class_expr + | Ti_mod of module_expr + | An_call of Location.t * Annot.call + | An_ident of Location.t * string * Annot.ident +;; + +let get_location ti = + match ti with + Ti_pat p -> p.pat_loc + | Ti_expr e -> e.exp_loc + | Ti_class c -> c.cl_loc + | Ti_mod m -> m.mod_loc + | An_call (l, k) -> l + | An_ident (l, s, k) -> l +;; + +let annotations = ref ([] : annotation list);; +let phrases = ref ([] : Location.t list);; + +let record ti = + if !Clflags.annotations && not (get_location ti).Location.loc_ghost then + annotations := ti :: !annotations +;; + +let record_phrase loc = + if !Clflags.annotations then phrases := loc :: !phrases; +;; + +(* comparison order: + the intervals are sorted by order of increasing upper bound + same upper bound -> sorted by decreasing lower bound +*) +let cmp_loc_inner_first loc1 loc2 = + match compare loc1.loc_end.pos_cnum loc2.loc_end.pos_cnum with + | 0 -> compare loc2.loc_start.pos_cnum loc1.loc_start.pos_cnum + | x -> x +;; +let cmp_ti_inner_first ti1 ti2 = + cmp_loc_inner_first (get_location ti1) (get_location ti2) +;; + +let print_position pp pos = + if pos = dummy_pos then + fprintf pp "--" + else + fprintf pp "%S %d %d %d" pos.pos_fname pos.pos_lnum pos.pos_bol + pos.pos_cnum; +;; + +let print_location pp loc = + print_position pp loc.loc_start; + fprintf pp " "; + print_position pp loc.loc_end; +;; + +let sort_filter_phrases () = + let ph = List.sort (fun x y -> cmp_loc_inner_first y x) !phrases in + let rec loop accu cur l = + match l with + | [] -> accu + | loc :: t -> + if cur.loc_start.pos_cnum <= loc.loc_start.pos_cnum + && cur.loc_end.pos_cnum >= loc.loc_end.pos_cnum + then loop accu cur t + else loop (loc :: accu) loc t + in + phrases := loop [] Location.none ph; +;; + +let rec printtyp_reset_maybe loc = + match !phrases with + | cur :: t when cur.loc_start.pos_cnum <= loc.loc_start.pos_cnum -> + Printtyp.reset (); + phrases := t; + printtyp_reset_maybe loc; + | _ -> () +;; + +let call_kind_string k = + match k with + | Tail -> "tail" + | Stack -> "stack" + | Inline -> "inline" +;; + +let print_ident_annot pp str k = + match k with + | Idef l -> fprintf pp "def %s %a@." str print_location l; + | Iref_internal l -> fprintf pp "int_ref %s %a@." str print_location l; + | Iref_external -> fprintf pp "ext_ref %s@." str; +;; + +(* The format of the annotation file is documented in emacs/caml-types.el. *) + +let print_info pp prev_loc ti = + match ti with + | Ti_class _ | Ti_mod _ -> prev_loc + | Ti_pat {pat_loc = loc; pat_type = typ} + | Ti_expr {exp_loc = loc; exp_type = typ} -> + if loc <> prev_loc then fprintf pp "%a@." print_location loc; + fprintf pp "type(@. "; + printtyp_reset_maybe loc; + Printtyp.mark_loops typ; + Printtyp.type_sch pp typ; + fprintf pp "@.)@."; + loc + | An_call (loc, k) -> + if loc <> prev_loc then fprintf pp "%a@." print_location loc; + fprintf pp "call(@. %s@.)@." (call_kind_string k); + loc + | An_ident (loc, str, k) -> + if loc <> prev_loc then fprintf pp "%a@." print_location loc; + fprintf pp "ident(@. "; + print_ident_annot pp str k; + fprintf pp ")@."; + loc +;; + +let get_info () = + let info = List.fast_sort cmp_ti_inner_first !annotations in + annotations := []; + info +;; + +let dump filename = + if !Clflags.annotations then begin + let info = get_info () in + let pp = formatter_of_out_channel (open_out filename) in + sort_filter_phrases (); + ignore (List.fold_left (print_info pp) Location.none info); + phrases := []; + end else begin + annotations := []; + end; +;; diff --git a/typing/stypes.mli b/typing/stypes.mli new file mode 100644 index 0000000..b4e056f --- /dev/null +++ b/typing/stypes.mli @@ -0,0 +1,35 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) +(* *) +(* Copyright 2003 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: stypes.mli,v 1.5 2008-07-29 15:42:44 doligez Exp $ *) + +(* Recording and dumping (partial) type information *) + +(* Clflags.save_types must be true *) + +open Typedtree;; + +type annotation = + | Ti_pat of pattern + | Ti_expr of expression + | Ti_class of class_expr + | Ti_mod of module_expr + | An_call of Location.t * Annot.call + | An_ident of Location.t * string * Annot.ident +;; + +val record : annotation -> unit;; +val record_phrase : Location.t -> unit;; +val dump : string -> unit;; + +val get_location : annotation -> Location.t;; +val get_info : unit -> annotation list;; diff --git a/typing/subst.ml b/typing/subst.ml new file mode 100644 index 0000000..5ac8d8e --- /dev/null +++ b/typing/subst.ml @@ -0,0 +1,296 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: subst.ml,v 1.52 2008-01-11 16:13:16 doligez Exp $ *) + +(* Substitutions *) + +open Misc +open Path +open Types +open Btype + +type t = + { types: (Ident.t, Path.t) Tbl.t; + modules: (Ident.t, Path.t) Tbl.t; + modtypes: (Ident.t, module_type) Tbl.t; + for_saving: bool } + +let identity = + { types = Tbl.empty; modules = Tbl.empty; modtypes = Tbl.empty; + for_saving = false } + +let add_type id p s = { s with types = Tbl.add id p s.types } + +let add_module id p s = { s with modules = Tbl.add id p s.modules } + +let add_modtype id ty s = { s with modtypes = Tbl.add id ty s.modtypes } + +let for_saving s = { s with for_saving = true } + +let rec module_path s = function + Pident id as p -> + begin try Tbl.find id s.modules with Not_found -> p end + | Pdot(p, n, pos) -> + Pdot(module_path s p, n, pos) + | Papply(p1, p2) -> + Papply(module_path s p1, module_path s p2) + +let type_path s = function + Pident id as p -> + begin try Tbl.find id s.types with Not_found -> p end + | Pdot(p, n, pos) -> + Pdot(module_path s p, n, pos) + | Papply(p1, p2) -> + fatal_error "Subst.type_path" + +(* Special type ids for saved signatures *) + +let new_id = ref (-1) +let reset_for_saving () = new_id := -1 + +let newpersty desc = + decr new_id; { desc = desc; level = generic_level; id = !new_id } + +(* Similar to [Ctype.nondep_type_rec]. *) +let rec typexp s ty = + let ty = repr ty in + match ty.desc with + Tvar | Tunivar -> + if s.for_saving || ty.id < 0 then + let ty' = + if s.for_saving then newpersty ty.desc else newty2 ty.level ty.desc + in + save_desc ty ty.desc; ty.desc <- Tsubst ty'; ty' + else ty + | Tsubst ty -> + ty +(* cannot do it, since it would omit subsitution + | Tvariant row when not (static_row row) -> + ty +*) + | _ -> + let desc = ty.desc in + save_desc ty desc; + (* Make a stub *) + let ty' = if s.for_saving then newpersty Tvar else newgenvar () in + ty.desc <- Tsubst ty'; + ty'.desc <- + begin match desc with + | Tconstr(p, tl, abbrev) -> + Tconstr(type_path s p, List.map (typexp s) tl, ref Mnil) + | Tobject (t1, name) -> + Tobject (typexp s t1, + ref (match !name with + None -> None + | Some (p, tl) -> + Some (type_path s p, List.map (typexp s) tl))) + | Tvariant row -> + let row = row_repr row in + let more = repr row.row_more in + (* We must substitute in a subtle way *) + (* Tsubst takes a tuple containing the row var and the variant *) + begin match more.desc with + Tsubst {desc = Ttuple [_;ty2]} -> + (* This variant type has been already copied *) + ty.desc <- Tsubst ty2; (* avoid Tlink in the new type *) + Tlink ty2 + | _ -> + let dup = + s.for_saving || more.level = generic_level || static_row row || + match more.desc with Tconstr _ -> true | _ -> false in + (* Various cases for the row variable *) + let more' = + match more.desc with + Tsubst ty -> ty + | Tconstr _ -> typexp s more + | Tunivar | Tvar -> + save_desc more more.desc; + if s.for_saving then newpersty more.desc else + if dup && more.desc <> Tunivar then newgenvar () else more + | _ -> assert false + in + (* Register new type first for recursion *) + more.desc <- Tsubst(newgenty(Ttuple[more';ty'])); + (* Return a new copy *) + let row = + copy_row (typexp s) true row (not dup) more' in + match row.row_name with + Some (p, tl) -> + Tvariant {row with row_name = Some (type_path s p, tl)} + | None -> + Tvariant row + end + | Tfield(label, kind, t1, t2) when field_kind_repr kind = Fabsent -> + Tlink (typexp s t2) + | _ -> copy_type_desc (typexp s) desc + end; + ty' + +(* + Always make a copy of the type. If this is not done, type levels + might not be correct. +*) +let type_expr s ty = + let ty' = typexp s ty in + cleanup_types (); + ty' + +let type_declaration s decl = + let decl = + { type_params = List.map (typexp s) decl.type_params; + type_arity = decl.type_arity; + type_kind = + begin match decl.type_kind with + Type_abstract -> Type_abstract + | Type_variant cstrs -> + Type_variant( + List.map (fun (n, args) -> (n, List.map (typexp s) args)) + cstrs) + | Type_record(lbls, rep) -> + Type_record( + List.map (fun (n, mut, arg) -> (n, mut, typexp s arg)) + lbls, + rep) + end; + type_manifest = + begin match decl.type_manifest with + None -> None + | Some ty -> Some(typexp s ty) + end; + type_private = decl.type_private; + type_variance = decl.type_variance; + } + in + cleanup_types (); + decl + +let class_signature s sign = + { cty_self = typexp s sign.cty_self; + cty_vars = + Vars.map (function (m, v, t) -> (m, v, typexp s t)) sign.cty_vars; + cty_concr = sign.cty_concr; + cty_inher = + List.map (fun (p, tl) -> (type_path s p, List.map (typexp s) tl)) + sign.cty_inher + } + +let rec class_type s = + function + Tcty_constr (p, tyl, cty) -> + Tcty_constr (type_path s p, List.map (typexp s) tyl, class_type s cty) + | Tcty_signature sign -> + Tcty_signature (class_signature s sign) + | Tcty_fun (l, ty, cty) -> + Tcty_fun (l, typexp s ty, class_type s cty) + +let class_declaration s decl = + let decl = + { cty_params = List.map (typexp s) decl.cty_params; + cty_variance = decl.cty_variance; + cty_type = class_type s decl.cty_type; + cty_path = type_path s decl.cty_path; + cty_new = + begin match decl.cty_new with + None -> None + | Some ty -> Some (typexp s ty) + end } + in + (* Do not clean up if saving: next is cltype_declaration *) + if not s.for_saving then cleanup_types (); + decl + +let cltype_declaration s decl = + let decl = + { clty_params = List.map (typexp s) decl.clty_params; + clty_variance = decl.clty_variance; + clty_type = class_type s decl.clty_type; + clty_path = type_path s decl.clty_path } + in + (* Do clean up even if saving: type_declaration may be recursive *) + cleanup_types (); + decl + +let class_type s cty = + let cty = class_type s cty in + cleanup_types (); + cty + +let value_description s descr = + { val_type = type_expr s descr.val_type; + val_kind = descr.val_kind } + +let exception_declaration s tyl = + List.map (type_expr s) tyl + +let rec rename_bound_idents s idents = function + [] -> (List.rev idents, s) + | Tsig_type(id, d, _) :: sg -> + let id' = Ident.rename id in + rename_bound_idents (add_type id (Pident id') s) (id' :: idents) sg + | Tsig_module(id, mty, _) :: sg -> + let id' = Ident.rename id in + rename_bound_idents (add_module id (Pident id') s) (id' :: idents) sg + | Tsig_modtype(id, d) :: sg -> + let id' = Ident.rename id in + rename_bound_idents (add_modtype id (Tmty_ident(Pident id')) s) + (id' :: idents) sg + | (Tsig_value(id, _) | Tsig_exception(id, _) | + Tsig_class(id, _, _) | Tsig_cltype(id, _, _)) :: sg -> + let id' = Ident.rename id in + rename_bound_idents s (id' :: idents) sg + +let rec modtype s = function + Tmty_ident p as mty -> + begin match p with + Pident id -> + begin try Tbl.find id s.modtypes with Not_found -> mty end + | Pdot(p, n, pos) -> + Tmty_ident(Pdot(module_path s p, n, pos)) + | Papply(p1, p2) -> + fatal_error "Subst.modtype" + end + | Tmty_signature sg -> + Tmty_signature(signature s sg) + | Tmty_functor(id, arg, res) -> + let id' = Ident.rename id in + Tmty_functor(id', modtype s arg, + modtype (add_module id (Pident id') s) res) + +and signature s sg = + (* Components of signature may be mutually recursive (e.g. type declarations + or class and type declarations), so first build global renaming + substitution... *) + let (new_idents, s') = rename_bound_idents s [] sg in + (* ... then apply it to each signature component in turn *) + List.map2 (signature_component s') sg new_idents + +and signature_component s comp newid = + match comp with + Tsig_value(id, d) -> + Tsig_value(newid, value_description s d) + | Tsig_type(id, d, rs) -> + Tsig_type(newid, type_declaration s d, rs) + | Tsig_exception(id, d) -> + Tsig_exception(newid, exception_declaration s d) + | Tsig_module(id, mty, rs) -> + Tsig_module(newid, modtype s mty, rs) + | Tsig_modtype(id, d) -> + Tsig_modtype(newid, modtype_declaration s d) + | Tsig_class(id, d, rs) -> + Tsig_class(newid, class_declaration s d, rs) + | Tsig_cltype(id, d, rs) -> + Tsig_cltype(newid, cltype_declaration s d, rs) + +and modtype_declaration s = function + Tmodtype_abstract -> Tmodtype_abstract + | Tmodtype_manifest mty -> Tmodtype_manifest(modtype s mty) diff --git a/typing/subst.mli b/typing/subst.mli new file mode 100644 index 0000000..e4da2a7 --- /dev/null +++ b/typing/subst.mli @@ -0,0 +1,54 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: subst.mli,v 1.13 2008-01-11 16:13:16 doligez Exp $ *) + +(* Substitutions *) + +open Types + +type t + +(* + Substitutions are used to translate a type from one context to + another. This requires substituing paths for identifiers, and + possibly also lowering the level of non-generic variables so that + it be inferior to the maximum level of the new context. + + Substitutions can also be used to create a "clean" copy of a type. + Indeed, non-variable node of a type are duplicated, with their + levels set to generic level. That way, the resulting type is + well-formed (decreasing levels), even if the original one was not. +*) + +val identity: t + +val add_type: Ident.t -> Path.t -> t -> t +val add_module: Ident.t -> Path.t -> t -> t +val add_modtype: Ident.t -> module_type -> t -> t +val for_saving: t -> t +val reset_for_saving: unit -> unit + +val module_path: t -> Path.t -> Path.t +val type_path: t -> Path.t -> Path.t + +val type_expr: t -> type_expr -> type_expr +val class_type: t -> class_type -> class_type +val value_description: t -> value_description -> value_description +val type_declaration: t -> type_declaration -> type_declaration +val exception_declaration: + t -> exception_declaration -> exception_declaration +val class_declaration: t -> class_declaration -> class_declaration +val cltype_declaration: t -> cltype_declaration -> cltype_declaration +val modtype: t -> module_type -> module_type +val signature: t -> signature -> signature +val modtype_declaration: t -> modtype_declaration -> modtype_declaration diff --git a/typing/typeclass.ml b/typing/typeclass.ml new file mode 100644 index 0000000..f00b938 --- /dev/null +++ b/typing/typeclass.ml @@ -0,0 +1,1599 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typeclass.ml,v 1.93 2008-02-29 14:21:22 doligez Exp $ *) + +open Misc +open Parsetree +open Asttypes +open Path +open Types +open Typedtree +open Typecore +open Typetexp +open Format + +type error = + Unconsistent_constraint of (type_expr * type_expr) list + | Field_type_mismatch of string * string * (type_expr * type_expr) list + | Structure_expected of class_type + | Cannot_apply of class_type + | Apply_wrong_label of label + | Pattern_type_clash of type_expr + | Repeated_parameter + | Unbound_class of Longident.t + | Unbound_class_2 of Longident.t + | Unbound_class_type of Longident.t + | Unbound_class_type_2 of Longident.t + | Abbrev_type_clash of type_expr * type_expr * type_expr + | Constructor_type_mismatch of string * (type_expr * type_expr) list + | Virtual_class of bool * string list * string list + | Parameter_arity_mismatch of Longident.t * int * int + | Parameter_mismatch of (type_expr * type_expr) list + | Bad_parameters of Ident.t * type_expr * type_expr + | Class_match_failure of Ctype.class_match_failure list + | Unbound_val of string + | Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure + | Make_nongen_seltype of type_expr + | Non_generalizable_class of Ident.t * Types.class_declaration + | Cannot_coerce_self of type_expr + | Non_collapsable_conjunction of + Ident.t * Types.class_declaration * (type_expr * type_expr) list + | Final_self_clash of (type_expr * type_expr) list + | Mutability_mismatch of string * mutable_flag + +exception Error of Location.t * error + + + (**********************) + (* Useful constants *) + (**********************) + + +(* + Self type have a dummy private method, thus preventing it to become + closed. +*) +let dummy_method = Ctype.dummy_method + +(* + Path associated to the temporary class type of a class being typed + (its constructor is not available). +*) +let unbound_class = Path.Pident (Ident.create "") + + + (************************************) + (* Some operations on class types *) + (************************************) + + +(* Fully expand the head of a class type *) +let rec scrape_class_type = + function + Tcty_constr (_, _, cty) -> scrape_class_type cty + | cty -> cty + +(* Generalize a class type *) +let rec generalize_class_type = + function + Tcty_constr (_, params, cty) -> + List.iter Ctype.generalize params; + generalize_class_type cty + | Tcty_signature {cty_self = sty; cty_vars = vars; cty_inher = inher} -> + Ctype.generalize sty; + Vars.iter (fun _ (_, _, ty) -> Ctype.generalize ty) vars; + List.iter (fun (_,tl) -> List.iter Ctype.generalize tl) inher + | Tcty_fun (_, ty, cty) -> + Ctype.generalize ty; + generalize_class_type cty + +(* Return the virtual methods of a class type *) +let virtual_methods sign = + let (fields, _) = Ctype.flatten_fields (Ctype.object_fields sign.cty_self) in + List.fold_left + (fun virt (lab, _, _) -> + if lab = dummy_method then virt else + if Concr.mem lab sign.cty_concr then virt else + lab::virt) + [] fields + +(* Return the constructor type associated to a class type *) +let rec constructor_type constr cty = + match cty with + Tcty_constr (_, _, cty) -> + constructor_type constr cty + | Tcty_signature sign -> + constr + | Tcty_fun (l, ty, cty) -> + Ctype.newty (Tarrow (l, ty, constructor_type constr cty, Cok)) + +let rec class_body cty = + match cty with + Tcty_constr (_, _, cty') -> + cty (* Only class bodies can be abbreviated *) + | Tcty_signature sign -> + cty + | Tcty_fun (_, ty, cty) -> + class_body cty + +let rec extract_constraints cty = + let sign = Ctype.signature_of_class_type cty in + (Vars.fold (fun lab _ vars -> lab :: vars) sign.cty_vars [], + begin let (fields, _) = + Ctype.flatten_fields (Ctype.object_fields sign.cty_self) + in + List.fold_left + (fun meths (lab, _, _) -> + if lab = dummy_method then meths else lab::meths) + [] fields + end, + sign.cty_concr) + +let rec abbreviate_class_type path params cty = + match cty with + Tcty_constr (_, _, _) | Tcty_signature _ -> + Tcty_constr (path, params, cty) + | Tcty_fun (l, ty, cty) -> + Tcty_fun (l, ty, abbreviate_class_type path params cty) + +let rec closed_class_type = + function + Tcty_constr (_, params, _) -> + List.for_all Ctype.closed_schema params + | Tcty_signature sign -> + Ctype.closed_schema sign.cty_self + && + Vars.fold (fun _ (_, _, ty) cc -> Ctype.closed_schema ty && cc) + sign.cty_vars + true + | Tcty_fun (_, ty, cty) -> + Ctype.closed_schema ty + && + closed_class_type cty + +let closed_class cty = + List.for_all Ctype.closed_schema cty.cty_params + && + closed_class_type cty.cty_type + +let rec limited_generalize rv = + function + Tcty_constr (path, params, cty) -> + List.iter (Ctype.limited_generalize rv) params; + limited_generalize rv cty + | Tcty_signature sign -> + Ctype.limited_generalize rv sign.cty_self; + Vars.iter (fun _ (_, _, ty) -> Ctype.limited_generalize rv ty) + sign.cty_vars; + List.iter (fun (_, tl) -> List.iter (Ctype.limited_generalize rv) tl) + sign.cty_inher + | Tcty_fun (_, ty, cty) -> + Ctype.limited_generalize rv ty; + limited_generalize rv cty + +(* Record a class type *) +let rc node = + Stypes.record (Stypes.Ti_class node); + node + + + (***********************************) + (* Primitives for typing classes *) + (***********************************) + + +(* Enter a value in the method environment only *) +let enter_met_env lab kind ty val_env met_env par_env = + let (id, val_env) = + Env.enter_value lab {val_type = ty; val_kind = Val_unbound} val_env + in + (id, val_env, + Env.add_value id {val_type = ty; val_kind = kind} met_env, + Env.add_value id {val_type = ty; val_kind = Val_unbound} par_env) + +(* Enter an instance variable in the environment *) +let enter_val cl_num vars inh lab mut virt ty val_env met_env par_env loc = + let (id, virt) = + try + let (id, mut', virt', ty') = Vars.find lab !vars in + if mut' <> mut then raise (Error(loc, Mutability_mismatch(lab, mut))); + Ctype.unify val_env (Ctype.instance ty) (Ctype.instance ty'); + (if not inh then Some id else None), + (if virt' = Concrete then virt' else virt) + with + Ctype.Unify tr -> + raise (Error(loc, Field_type_mismatch("instance variable", lab, tr))) + | Not_found -> None, virt + in + let (id, _, _, _) as result = + match id with Some id -> (id, val_env, met_env, par_env) + | None -> + enter_met_env lab (Val_ivar (mut, cl_num)) ty val_env met_env par_env + in + vars := Vars.add lab (id, mut, virt, ty) !vars; + result + +let inheritance self_type env concr_meths warn_meths loc parent = + match scrape_class_type parent with + Tcty_signature cl_sig -> + + (* Methods *) + begin try + Ctype.unify env self_type cl_sig.cty_self + with Ctype.Unify trace -> + match trace with + _::_::_::({desc = Tfield(n, _, _, _)}, _)::rem -> + raise(Error(loc, Field_type_mismatch ("method", n, rem))) + | _ -> + assert false + end; + + let overridings = Concr.inter cl_sig.cty_concr warn_meths in + if not (Concr.is_empty overridings) then begin + let cname = + match parent with + Tcty_constr (p, _, _) -> Path.name p + | _ -> "inherited" + in + Location.prerr_warning loc + (Warnings.Method_override (cname :: Concr.elements overridings)) + end; + + let concr_meths = Concr.union cl_sig.cty_concr concr_meths in + (* No need to warn about overriding of inherited methods! *) + (* let warn_meths = Concr.union cl_sig.cty_concr warn_meths in *) + + (cl_sig, concr_meths, warn_meths) + + | _ -> + raise(Error(loc, Structure_expected parent)) + +let virtual_method val_env meths self_type lab priv sty loc = + let (_, ty') = + Ctype.filter_self_method val_env lab priv meths self_type + in + let ty = transl_simple_type val_env false sty in + try Ctype.unify val_env ty ty' with Ctype.Unify trace -> + raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + +let delayed_meth_specs = ref [] + +let declare_method val_env meths self_type lab priv sty loc = + let (_, ty') = + Ctype.filter_self_method val_env lab priv meths self_type + in + let unif ty = + try Ctype.unify val_env ty ty' with Ctype.Unify trace -> + raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + in + match sty.ptyp_desc, priv with + Ptyp_poly ([],sty), Public -> + delayed_meth_specs := + lazy (unif (transl_simple_type_univars val_env sty)) :: + !delayed_meth_specs + | _ -> unif (transl_simple_type val_env false sty) + +let type_constraint val_env sty sty' loc = + let ty = transl_simple_type val_env false sty in + let ty' = transl_simple_type val_env false sty' in + try Ctype.unify val_env ty ty' with Ctype.Unify trace -> + raise(Error(loc, Unconsistent_constraint trace)) + +let mkpat d = { ppat_desc = d; ppat_loc = Location.none } +let make_method cl_num expr = + { pexp_desc = + Pexp_function ("", None, + [mkpat (Ppat_alias (mkpat(Ppat_var "self-*"), + "self-" ^ cl_num)), + expr]); + pexp_loc = expr.pexp_loc } + +(*******************************) + +let add_val env loc lab (mut, virt, ty) val_sig = + let virt = + try + let (mut', virt', ty') = Vars.find lab val_sig in + if virt' = Concrete then virt' else virt + with Not_found -> virt + in + Vars.add lab (mut, virt, ty) val_sig + +let rec class_type_field env self_type meths (val_sig, concr_meths, inher) = + function + Pctf_inher sparent -> + let parent = class_type env sparent in + let inher = + match parent with + Tcty_constr (p, tl, _) -> (p, tl) :: inher + | _ -> inher + in + let (cl_sig, concr_meths, _) = + inheritance self_type env concr_meths Concr.empty sparent.pcty_loc + parent + in + let val_sig = + Vars.fold (add_val env sparent.pcty_loc) cl_sig.cty_vars val_sig in + (val_sig, concr_meths, inher) + + | Pctf_val (lab, mut, virt, sty, loc) -> + let ty = transl_simple_type env false sty in + (add_val env loc lab (mut, virt, ty) val_sig, concr_meths, inher) + + | Pctf_virt (lab, priv, sty, loc) -> + declare_method env meths self_type lab priv sty loc; + (val_sig, concr_meths, inher) + + | Pctf_meth (lab, priv, sty, loc) -> + declare_method env meths self_type lab priv sty loc; + (val_sig, Concr.add lab concr_meths, inher) + + | Pctf_cstr (sty, sty', loc) -> + type_constraint env sty sty' loc; + (val_sig, concr_meths, inher) + +and class_signature env sty sign = + let meths = ref Meths.empty in + let self_type = transl_simple_type env false sty in + + (* Check that the binder is a correct type, and introduce a dummy + method preventing self type from being closed. *) + let dummy_obj = Ctype.newvar () in + Ctype.unify env (Ctype.filter_method env dummy_method Private dummy_obj) + (Ctype.newty (Ttuple [])); + begin try + Ctype.unify env self_type dummy_obj + with Ctype.Unify _ -> + raise(Error(sty.ptyp_loc, Pattern_type_clash self_type)) + end; + + (* Class type fields *) + let (val_sig, concr_meths, inher) = + List.fold_left (class_type_field env self_type meths) + (Vars.empty, Concr.empty, []) + sign + in + + {cty_self = self_type; + cty_vars = val_sig; + cty_concr = concr_meths; + cty_inher = inher} + +and class_type env scty = + match scty.pcty_desc with + Pcty_constr (lid, styl) -> + let (path, decl) = + try Env.lookup_cltype lid env with Not_found -> + raise(Error(scty.pcty_loc, Unbound_class_type lid)) + in + if Path.same decl.clty_path unbound_class then + raise(Error(scty.pcty_loc, Unbound_class_type_2 lid)); + let (params, clty) = + Ctype.instance_class decl.clty_params decl.clty_type + in + if List.length params <> List.length styl then + raise(Error(scty.pcty_loc, + Parameter_arity_mismatch (lid, List.length params, + List.length styl))); + List.iter2 + (fun sty ty -> + let ty' = transl_simple_type env false sty in + try Ctype.unify env ty' ty with Ctype.Unify trace -> + raise(Error(sty.ptyp_loc, Parameter_mismatch trace))) + styl params; + Tcty_constr (path, params, clty) + + | Pcty_signature (sty, sign) -> + Tcty_signature (class_signature env sty sign) + + | Pcty_fun (l, sty, scty) -> + let ty = transl_simple_type env false sty in + let cty = class_type env scty in + Tcty_fun (l, ty, cty) + +let class_type env scty = + delayed_meth_specs := []; + let cty = class_type env scty in + List.iter Lazy.force (List.rev !delayed_meth_specs); + delayed_meth_specs := []; + cty + +(*******************************) + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +let rec class_field cl_num self_type meths vars + (val_env, met_env, par_env, fields, concr_meths, warn_meths, + warn_vals, inher) = + function + Pcf_inher (sparent, super) -> + let parent = class_expr cl_num val_env par_env sparent in + let inher = + match parent.cl_type with + Tcty_constr (p, tl, _) -> (p, tl) :: inher + | _ -> inher + in + let (cl_sig, concr_meths, warn_meths) = + inheritance self_type val_env concr_meths warn_meths sparent.pcl_loc + parent.cl_type + in + (* Variables *) + let (val_env, met_env, par_env, inh_vars, warn_vals) = + Vars.fold + (fun lab info (val_env, met_env, par_env, inh_vars, warn_vals) -> + let mut, vr, ty = info in + let (id, val_env, met_env, par_env) = + enter_val cl_num vars true lab mut vr ty val_env met_env par_env + sparent.pcl_loc + in + let warn_vals = + if vr = Virtual then warn_vals else + if StringSet.mem lab warn_vals then + (Location.prerr_warning sparent.pcl_loc + (Warnings.Instance_variable_override lab); warn_vals) + else StringSet.add lab warn_vals + in + (val_env, met_env, par_env, (lab, id) :: inh_vars, warn_vals)) + cl_sig.cty_vars (val_env, met_env, par_env, [], warn_vals) + in + (* Inherited concrete methods *) + let inh_meths = + Concr.fold (fun lab rem -> (lab, Ident.create lab)::rem) + cl_sig.cty_concr [] + in + (* Super *) + let (val_env, met_env, par_env) = + match super with + None -> + (val_env, met_env, par_env) + | Some name -> + let (id, val_env, met_env, par_env) = + enter_met_env name (Val_anc (inh_meths, cl_num)) self_type + val_env met_env par_env + in + (val_env, met_env, par_env) + in + (val_env, met_env, par_env, + lazy(Cf_inher (parent, inh_vars, inh_meths))::fields, + concr_meths, warn_meths, warn_vals, inher) + + | Pcf_valvirt (lab, mut, styp, loc) -> + if !Clflags.principal then Ctype.begin_def (); + let ty = Typetexp.transl_simple_type val_env false styp in + if !Clflags.principal then begin + Ctype.end_def (); + Ctype.generalize_structure ty + end; + let (id, val_env, met_env', par_env) = + enter_val cl_num vars false lab mut Virtual ty + val_env met_env par_env loc + in + (val_env, met_env', par_env, + lazy(Cf_val (lab, id, None, met_env' == met_env)) :: fields, + concr_meths, warn_meths, StringSet.remove lab warn_vals, inher) + + | Pcf_val (lab, mut, sexp, loc) -> + if StringSet.mem lab warn_vals then + Location.prerr_warning loc (Warnings.Instance_variable_override lab); + if !Clflags.principal then Ctype.begin_def (); + let exp = + try type_exp val_env sexp with Ctype.Unify [(ty, _)] -> + raise(Error(loc, Make_nongen_seltype ty)) + in + if !Clflags.principal then begin + Ctype.end_def (); + Ctype.generalize_structure exp.exp_type + end; + let (id, val_env, met_env', par_env) = + enter_val cl_num vars false lab mut Concrete exp.exp_type + val_env met_env par_env loc + in + (val_env, met_env', par_env, + lazy(Cf_val (lab, id, Some exp, met_env' == met_env)) :: fields, + concr_meths, warn_meths, StringSet.add lab warn_vals, inher) + + | Pcf_virt (lab, priv, sty, loc) -> + virtual_method val_env meths self_type lab priv sty loc; + let warn_meths = Concr.remove lab warn_meths in + (val_env, met_env, par_env, fields, concr_meths, warn_meths, + warn_vals, inher) + + | Pcf_meth (lab, priv, expr, loc) -> + if Concr.mem lab warn_meths then + Location.prerr_warning loc (Warnings.Method_override [lab]); + let (_, ty) = + Ctype.filter_self_method val_env lab priv meths self_type + in + begin try match expr.pexp_desc with + Pexp_poly (sbody, sty) -> + begin match sty with None -> () + | Some sty -> + Ctype.unify val_env + (Typetexp.transl_simple_type val_env false sty) ty + end; + begin match (Ctype.repr ty).desc with + Tvar -> + let ty' = Ctype.newvar () in + Ctype.unify val_env (Ctype.newty (Tpoly (ty', []))) ty; + Ctype.unify val_env (type_approx val_env sbody) ty' + | Tpoly (ty1, tl) -> + let _, ty1' = Ctype.instance_poly false tl ty1 in + let ty2 = type_approx val_env sbody in + Ctype.unify val_env ty2 ty1' + | _ -> assert false + end + | _ -> assert false + with Ctype.Unify trace -> + raise(Error(loc, Field_type_mismatch ("method", lab, trace))) + end; + let meth_expr = make_method cl_num expr in + (* backup variables for Pexp_override *) + let vars_local = !vars in + + let field = + lazy begin + let meth_type = + Ctype.newty (Tarrow("", self_type, Ctype.instance ty, Cok)) in + Ctype.raise_nongen_level (); + vars := vars_local; + let texp = type_expect met_env meth_expr meth_type in + Ctype.end_def (); + Cf_meth (lab, texp) + end in + (val_env, met_env, par_env, field::fields, + Concr.add lab concr_meths, Concr.add lab warn_meths, warn_vals, inher) + + | Pcf_cstr (sty, sty', loc) -> + type_constraint val_env sty sty' loc; + (val_env, met_env, par_env, fields, concr_meths, warn_meths, + warn_vals, inher) + + | Pcf_let (rec_flag, sdefs, loc) -> + let (defs, val_env) = + try + Typecore.type_let val_env rec_flag sdefs None + with Ctype.Unify [(ty, _)] -> + raise(Error(loc, Make_nongen_seltype ty)) + in + let (vals, met_env, par_env) = + List.fold_right + (fun id (vals, met_env, par_env) -> + let expr = + Typecore.type_exp val_env + {pexp_desc = Pexp_ident (Longident.Lident (Ident.name id)); + pexp_loc = Location.none} + in + let desc = + {val_type = expr.exp_type; + val_kind = Val_ivar (Immutable, cl_num)} + in + let id' = Ident.create (Ident.name id) in + ((id', expr) + :: vals, + Env.add_value id' desc met_env, + Env.add_value id' desc par_env)) + (let_bound_idents defs) + ([], met_env, par_env) + in + (val_env, met_env, par_env, lazy(Cf_let(rec_flag, defs, vals))::fields, + concr_meths, warn_meths, warn_vals, inher) + + | Pcf_init expr -> + let expr = make_method cl_num expr in + let vars_local = !vars in + let field = + lazy begin + Ctype.raise_nongen_level (); + let meth_type = + Ctype.newty + (Tarrow ("", self_type, Ctype.instance Predef.type_unit, Cok)) in + vars := vars_local; + let texp = type_expect met_env expr meth_type in + Ctype.end_def (); + Cf_init texp + end in + (val_env, met_env, par_env, field::fields, + concr_meths, warn_meths, warn_vals, inher) + +and class_structure cl_num final val_env met_env loc (spat, str) = + (* Environment for substructures *) + let par_env = met_env in + + (* Self type, with a dummy method preventing it from being closed/escaped. *) + let self_type = Ctype.newvar () in + Ctype.unify val_env + (Ctype.filter_method val_env dummy_method Private self_type) + (Ctype.newty (Ttuple [])); + + (* Private self is used for private method calls *) + let private_self = if final then Ctype.newvar () else self_type in + + (* Self binder *) + let (pat, meths, vars, val_env, meth_env, par_env) = + type_self_pattern cl_num private_self val_env met_env par_env spat + in + let public_self = pat.pat_type in + + (* Check that the binder has a correct type *) + let ty = + if final then Ctype.newty (Tobject (Ctype.newvar(), ref None)) + else self_type in + begin try Ctype.unify val_env public_self ty with + Ctype.Unify _ -> + raise(Error(spat.ppat_loc, Pattern_type_clash public_self)) + end; + let get_methods ty = + (fst (Ctype.flatten_fields + (Ctype.object_fields (Ctype.expand_head val_env ty)))) in + if final then begin + (* Copy known information to still empty self_type *) + List.iter + (fun (lab,kind,ty) -> + let k = + if Btype.field_kind_repr kind = Fpresent then Public else Private in + try Ctype.unify val_env ty + (Ctype.filter_method val_env lab k self_type) + with _ -> assert false) + (get_methods public_self) + end; + + (* Typing of class fields *) + let (_, _, _, fields, concr_meths, _, _, inher) = + List.fold_left (class_field cl_num self_type meths vars) + (val_env, meth_env, par_env, [], Concr.empty, Concr.empty, + StringSet.empty, []) + str + in + Ctype.unify val_env self_type (Ctype.newvar ()); + let sign = + {cty_self = public_self; + cty_vars = Vars.map (fun (id, mut, vr, ty) -> (mut, vr, ty)) !vars; + cty_concr = concr_meths; + cty_inher = inher} in + let methods = get_methods self_type in + let priv_meths = + List.filter (fun (_,kind,_) -> Btype.field_kind_repr kind <> Fpresent) + methods in + if final then begin + (* Unify private_self and a copy of self_type. self_type will not + be modified after this point *) + Ctype.close_object self_type; + let mets = virtual_methods {sign with cty_self = self_type} in + let vals = + Vars.fold + (fun name (mut, vr, ty) l -> if vr = Virtual then name :: l else l) + sign.cty_vars [] in + if mets <> [] || vals <> [] then + raise(Error(loc, Virtual_class(true, mets, vals))); + let self_methods = + List.fold_right + (fun (lab,kind,ty) rem -> + if lab = dummy_method then + (* allow public self and private self to be unified *) + match Btype.field_kind_repr kind with + Fvar r -> Btype.set_kind r Fabsent; rem + | _ -> rem + else + Ctype.newty(Tfield(lab, Btype.copy_kind kind, ty, rem))) + methods (Ctype.newty Tnil) in + begin try + Ctype.unify val_env private_self + (Ctype.newty (Tobject(self_methods, ref None))); + Ctype.unify val_env public_self self_type + with Ctype.Unify trace -> raise(Error(loc, Final_self_clash trace)) + end; + end; + + (* Typing of method bodies *) + if !Clflags.principal then + List.iter (fun (_,_,ty) -> Ctype.generalize_spine ty) methods; + let fields = List.map Lazy.force (List.rev fields) in + if !Clflags.principal then + List.iter (fun (_,_,ty) -> Ctype.unify val_env ty (Ctype.newvar ())) + methods; + let meths = Meths.map (function (id, ty) -> id) !meths in + + (* Check for private methods made public *) + let pub_meths' = + List.filter (fun (_,kind,_) -> Btype.field_kind_repr kind = Fpresent) + (get_methods public_self) in + let names = List.map (fun (x,_,_) -> x) in + let l1 = names priv_meths and l2 = names pub_meths' in + let added = List.filter (fun x -> List.mem x l1) l2 in + if added <> [] then + Location.prerr_warning loc (Warnings.Implicit_public_methods added); + {cl_field = fields; cl_meths = meths}, sign + +and class_expr cl_num val_env met_env scl = + match scl.pcl_desc with + Pcl_constr (lid, styl) -> + let (path, decl) = + try Env.lookup_class lid val_env with Not_found -> + raise(Error(scl.pcl_loc, Unbound_class lid)) + in + if Path.same decl.cty_path unbound_class then + raise(Error(scl.pcl_loc, Unbound_class_2 lid)); + let tyl = List.map + (fun sty -> transl_simple_type val_env false sty, sty.ptyp_loc) + styl + in + let (params, clty) = + Ctype.instance_class decl.cty_params decl.cty_type + in + let clty' = abbreviate_class_type path params clty in + if List.length params <> List.length tyl then + raise(Error(scl.pcl_loc, + Parameter_arity_mismatch (lid, List.length params, + List.length tyl))); + List.iter2 + (fun (ty',loc) ty -> + try Ctype.unify val_env ty' ty with Ctype.Unify trace -> + raise(Error(loc, Parameter_mismatch trace))) + tyl params; + let cl = + rc {cl_desc = Tclass_ident path; + cl_loc = scl.pcl_loc; + cl_type = clty'; + cl_env = val_env} + in + let (vals, meths, concrs) = extract_constraints clty in + rc {cl_desc = Tclass_constraint (cl, vals, meths, concrs); + cl_loc = scl.pcl_loc; + cl_type = clty'; + cl_env = val_env} + | Pcl_structure cl_str -> + let (desc, ty) = + class_structure cl_num false val_env met_env scl.pcl_loc cl_str in + rc {cl_desc = Tclass_structure desc; + cl_loc = scl.pcl_loc; + cl_type = Tcty_signature ty; + cl_env = val_env} + | Pcl_fun (l, Some default, spat, sbody) -> + let loc = default.pexp_loc in + let scases = + [{ppat_loc = loc; ppat_desc = + Ppat_construct(Longident.Lident"Some", + Some{ppat_loc = loc; ppat_desc = Ppat_var"*sth*"}, + false)}, + {pexp_loc = loc; pexp_desc = Pexp_ident(Longident.Lident"*sth*")}; + {ppat_loc = loc; ppat_desc = + Ppat_construct(Longident.Lident"None", None, false)}, + default] in + let smatch = + {pexp_loc = loc; pexp_desc = + Pexp_match({pexp_loc = loc; pexp_desc = + Pexp_ident(Longident.Lident"*opt*")}, + scases)} in + let sfun = + {pcl_loc = scl.pcl_loc; pcl_desc = + Pcl_fun(l, None, {ppat_loc = loc; ppat_desc = Ppat_var"*opt*"}, + {pcl_loc = scl.pcl_loc; pcl_desc = + Pcl_let(Default, [spat, smatch], sbody)})} + in + class_expr cl_num val_env met_env sfun + | Pcl_fun (l, None, spat, scl') -> + if !Clflags.principal then Ctype.begin_def (); + let (pat, pv, val_env', met_env) = + Typecore.type_class_arg_pattern cl_num val_env met_env l spat + in + if !Clflags.principal then begin + Ctype.end_def (); + iter_pattern (fun {pat_type=ty} -> Ctype.generalize_structure ty) pat + end; + let pv = + List.map + (function (id, id', ty) -> + (id, + Typecore.type_exp val_env' + {pexp_desc = Pexp_ident (Longident.Lident (Ident.name id)); + pexp_loc = Location.none})) + pv + in + let rec not_function = function + Tcty_fun _ -> false + | _ -> true + in + let partial = + Parmatch.check_partial pat.pat_loc + [pat, (* Dummy expression *) + {exp_desc = Texp_constant (Asttypes.Const_int 1); + exp_loc = Location.none; + exp_type = Ctype.none; + exp_env = Env.empty }] in + Ctype.raise_nongen_level (); + let cl = class_expr cl_num val_env' met_env scl' in + Ctype.end_def (); + if Btype.is_optional l && not_function cl.cl_type then + Location.prerr_warning pat.pat_loc + Warnings.Unerasable_optional_argument; + rc {cl_desc = Tclass_fun (pat, pv, cl, partial); + cl_loc = scl.pcl_loc; + cl_type = Tcty_fun (l, Ctype.instance pat.pat_type, cl.cl_type); + cl_env = val_env} + | Pcl_apply (scl', sargs) -> + let cl = class_expr cl_num val_env met_env scl' in + let rec nonopt_labels ls ty_fun = + match ty_fun with + | Tcty_fun (l, _, ty_res) -> + if Btype.is_optional l then nonopt_labels ls ty_res + else nonopt_labels (l::ls) ty_res + | _ -> ls + in + let ignore_labels = + !Clflags.classic || + let labels = nonopt_labels [] cl.cl_type in + List.length labels = List.length sargs && + List.for_all (fun (l,_) -> l = "") sargs && + List.exists (fun l -> l <> "") labels && + begin + Location.prerr_warning cl.cl_loc Warnings.Labels_omitted; + true + end + in + let rec type_args args omitted ty_fun sargs more_sargs = + match ty_fun with + | Tcty_fun (l, ty, ty_fun) when sargs <> [] || more_sargs <> [] -> + let name = Btype.label_name l + and optional = + if Btype.is_optional l then Optional else Required in + let sargs, more_sargs, arg = + if ignore_labels && not (Btype.is_optional l) then begin + match sargs, more_sargs with + (l', sarg0)::_, _ -> + raise(Error(sarg0.pexp_loc, Apply_wrong_label(l'))) + | _, (l', sarg0)::more_sargs -> + if l <> l' && l' <> "" then + raise(Error(sarg0.pexp_loc, Apply_wrong_label l')) + else ([], more_sargs, Some(type_argument val_env sarg0 ty)) + | _ -> + assert false + end else try + let (l', sarg0, sargs, more_sargs) = + try + let (l', sarg0, sargs1, sargs2) = + Btype.extract_label name sargs + in (l', sarg0, sargs1 @ sargs2, more_sargs) + with Not_found -> + let (l', sarg0, sargs1, sargs2) = + Btype.extract_label name more_sargs + in (l', sarg0, sargs @ sargs1, sargs2) + in + sargs, more_sargs, + if Btype.is_optional l' || not (Btype.is_optional l) then + Some (type_argument val_env sarg0 ty) + else + let arg = type_argument val_env + sarg0 (extract_option_type val_env ty) in + Some (option_some arg) + with Not_found -> + sargs, more_sargs, + if Btype.is_optional l && + (List.mem_assoc "" sargs || List.mem_assoc "" more_sargs) + then + Some (option_none ty Location.none) + else None + in + let omitted = if arg = None then (l,ty) :: omitted else omitted in + type_args ((arg,optional)::args) omitted ty_fun sargs more_sargs + | _ -> + match sargs @ more_sargs with + (l, sarg0)::_ -> + if omitted <> [] then + raise(Error(sarg0.pexp_loc, Apply_wrong_label l)) + else + raise(Error(cl.cl_loc, Cannot_apply cl.cl_type)) + | [] -> + (List.rev args, + List.fold_left + (fun ty_fun (l,ty) -> Tcty_fun(l,ty,ty_fun)) + ty_fun omitted) + in + let (args, cty) = + if ignore_labels then + type_args [] [] cl.cl_type [] sargs + else + type_args [] [] cl.cl_type sargs [] + in + rc {cl_desc = Tclass_apply (cl, args); + cl_loc = scl.pcl_loc; + cl_type = cty; + cl_env = val_env} + | Pcl_let (rec_flag, sdefs, scl') -> + let (defs, val_env) = + try + Typecore.type_let val_env rec_flag sdefs None + with Ctype.Unify [(ty, _)] -> + raise(Error(scl.pcl_loc, Make_nongen_seltype ty)) + in + let (vals, met_env) = + List.fold_right + (fun id (vals, met_env) -> + Ctype.begin_def (); + let expr = + Typecore.type_exp val_env + {pexp_desc = Pexp_ident (Longident.Lident (Ident.name id)); + pexp_loc = Location.none} + in + Ctype.end_def (); + Ctype.generalize expr.exp_type; + let desc = + {val_type = expr.exp_type; val_kind = Val_ivar (Immutable, + cl_num)} + in + let id' = Ident.create (Ident.name id) in + ((id', expr) + :: vals, + Env.add_value id' desc met_env)) + (let_bound_idents defs) + ([], met_env) + in + let cl = class_expr cl_num val_env met_env scl' in + rc {cl_desc = Tclass_let (rec_flag, defs, vals, cl); + cl_loc = scl.pcl_loc; + cl_type = cl.cl_type; + cl_env = val_env} + | Pcl_constraint (scl', scty) -> + Ctype.begin_class_def (); + let context = Typetexp.narrow () in + let cl = class_expr cl_num val_env met_env scl' in + Typetexp.widen context; + let context = Typetexp.narrow () in + let clty = class_type val_env scty in + Typetexp.widen context; + Ctype.end_def (); + + limited_generalize (Ctype.row_variable (Ctype.self_type cl.cl_type)) + cl.cl_type; + limited_generalize (Ctype.row_variable (Ctype.self_type clty)) clty; + + begin match Includeclass.class_types val_env cl.cl_type clty with + [] -> () + | error -> raise(Error(cl.cl_loc, Class_match_failure error)) + end; + let (vals, meths, concrs) = extract_constraints clty in + rc {cl_desc = Tclass_constraint (cl, vals, meths, concrs); + cl_loc = scl.pcl_loc; + cl_type = snd (Ctype.instance_class [] clty); + cl_env = val_env} + +(*******************************) + +(* Approximate the type of the constructor to allow recursive use *) +(* of optional parameters *) + +let var_option = Predef.type_option (Btype.newgenvar ()) + +let rec approx_declaration cl = + match cl.pcl_desc with + Pcl_fun (l, _, _, cl) -> + let arg = + if Btype.is_optional l then Ctype.instance var_option + else Ctype.newvar () in + Ctype.newty (Tarrow (l, arg, approx_declaration cl, Cok)) + | Pcl_let (_, _, cl) -> + approx_declaration cl + | Pcl_constraint (cl, _) -> + approx_declaration cl + | _ -> Ctype.newvar () + +let rec approx_description ct = + match ct.pcty_desc with + Pcty_fun (l, _, ct) -> + let arg = + if Btype.is_optional l then Ctype.instance var_option + else Ctype.newvar () in + Ctype.newty (Tarrow (l, arg, approx_description ct, Cok)) + | _ -> Ctype.newvar () + +(*******************************) + +let temp_abbrev env id arity = + let params = ref [] in + for i = 1 to arity do + params := Ctype.newvar () :: !params + done; + let ty = Ctype.newobj (Ctype.newvar ()) in + let env = + Env.add_type id + {type_params = !params; + type_arity = arity; + type_kind = Type_abstract; + type_private = Public; + type_manifest = Some ty; + type_variance = List.map (fun _ -> true, true, true) !params} + env + in + (!params, ty, env) + +let rec initial_env define_class approx + (res, env) (cl, id, ty_id, obj_id, cl_id) = + (* Temporary abbreviations *) + let arity = List.length (fst cl.pci_params) in + let (obj_params, obj_ty, env) = temp_abbrev env obj_id arity in + let (cl_params, cl_ty, env) = temp_abbrev env cl_id arity in + + (* Temporary type for the class constructor *) + let constr_type = approx cl.pci_expr in + if !Clflags.principal then Ctype.generalize_spine constr_type; + let dummy_cty = + Tcty_signature + { cty_self = Ctype.newvar (); + cty_vars = Vars.empty; + cty_concr = Concr.empty; + cty_inher = [] } + in + let dummy_class = + {cty_params = []; (* Dummy value *) + cty_variance = []; + cty_type = dummy_cty; (* Dummy value *) + cty_path = unbound_class; + cty_new = + match cl.pci_virt with + Virtual -> None + | Concrete -> Some constr_type} + in + let env = + Env.add_cltype ty_id + {clty_params = []; (* Dummy value *) + clty_variance = []; + clty_type = dummy_cty; (* Dummy value *) + clty_path = unbound_class} ( + if define_class then + Env.add_class id dummy_class env + else + env) + in + ((cl, id, ty_id, + obj_id, obj_params, obj_ty, + cl_id, cl_params, cl_ty, + constr_type, dummy_class)::res, + env) + +let class_infos define_class kind + (cl, id, ty_id, + obj_id, obj_params, obj_ty, + cl_id, cl_params, cl_ty, + constr_type, dummy_class) + (res, env) = + + reset_type_variables (); + Ctype.begin_class_def (); + + (* Introduce class parameters *) + let params = + try + let params, loc = cl.pci_params in + List.map (enter_type_variable true loc) params + with Already_bound -> + raise(Error(snd cl.pci_params, Repeated_parameter)) + in + + (* Allow self coercions (only for class declarations) *) + let coercion_locs = ref [] in + + (* Type the class expression *) + let (expr, typ) = + try + Typecore.self_coercion := + (Path.Pident obj_id, coercion_locs) :: !Typecore.self_coercion; + let res = kind env cl.pci_expr in + Typecore.self_coercion := List.tl !Typecore.self_coercion; + res + with exn -> + Typecore.self_coercion := []; raise exn + in + + Ctype.end_def (); + + let sty = Ctype.self_type typ in + + (* Generalize the row variable *) + let rv = Ctype.row_variable sty in + List.iter (Ctype.limited_generalize rv) params; + limited_generalize rv typ; + + (* Check the abbreviation for the object type *) + let (obj_params', obj_type) = Ctype.instance_class params typ in + let constr = Ctype.newconstr (Path.Pident obj_id) obj_params in + begin + let ty = Ctype.self_type obj_type in + Ctype.hide_private_methods ty; + Ctype.close_object ty; + begin try + List.iter2 (Ctype.unify env) obj_params obj_params' + with Ctype.Unify _ -> + raise(Error(cl.pci_loc, + Bad_parameters (obj_id, constr, + Ctype.newconstr (Path.Pident obj_id) + obj_params'))) + end; + begin try + Ctype.unify env ty constr + with Ctype.Unify _ -> + raise(Error(cl.pci_loc, + Abbrev_type_clash (constr, ty, Ctype.expand_head env constr))) + end + end; + + (* Check the other temporary abbreviation (#-type) *) + begin + let (cl_params', cl_type) = Ctype.instance_class params typ in + let ty = Ctype.self_type cl_type in + Ctype.hide_private_methods ty; + Ctype.set_object_name obj_id (Ctype.row_variable ty) cl_params ty; + begin try + List.iter2 (Ctype.unify env) cl_params cl_params' + with Ctype.Unify _ -> + raise(Error(cl.pci_loc, + Bad_parameters (cl_id, + Ctype.newconstr (Path.Pident cl_id) + cl_params, + Ctype.newconstr (Path.Pident cl_id) + cl_params'))) + end; + begin try + Ctype.unify env ty cl_ty + with Ctype.Unify _ -> + let constr = Ctype.newconstr (Path.Pident cl_id) params in + raise(Error(cl.pci_loc, Abbrev_type_clash (constr, ty, cl_ty))) + end + end; + + (* Type of the class constructor *) + begin try + Ctype.unify env + (constructor_type constr obj_type) + (Ctype.instance constr_type) + with Ctype.Unify trace -> + raise(Error(cl.pci_loc, + Constructor_type_mismatch (cl.pci_name, trace))) + end; + + (* Class and class type temporary definitions *) + let cty_variance = List.map (fun _ -> true, true) params in + let cltydef = + {clty_params = params; clty_type = class_body typ; + clty_variance = cty_variance; + clty_path = Path.Pident obj_id} + and clty = + {cty_params = params; cty_type = typ; + cty_variance = cty_variance; + cty_path = Path.Pident obj_id; + cty_new = + match cl.pci_virt with + Virtual -> None + | Concrete -> Some constr_type} + in + dummy_class.cty_type <- typ; + let env = + Env.add_cltype ty_id cltydef ( + if define_class then Env.add_class id clty env else env) + in + + if cl.pci_virt = Concrete then begin + let sign = Ctype.signature_of_class_type typ in + let mets = virtual_methods sign in + let vals = + Vars.fold + (fun name (mut, vr, ty) l -> if vr = Virtual then name :: l else l) + sign.cty_vars [] in + if mets <> [] || vals <> [] then + raise(Error(cl.pci_loc, Virtual_class(true, mets, vals))); + end; + + (* Misc. *) + let arity = Ctype.class_type_arity typ in + let pub_meths = + let (fields, _) = + Ctype.flatten_fields (Ctype.object_fields (Ctype.expand_head env obj_ty)) + in + List.map (function (lab, _, _) -> lab) fields + in + + (* Final definitions *) + let (params', typ') = Ctype.instance_class params typ in + let cltydef = + {clty_params = params'; clty_type = class_body typ'; + clty_variance = cty_variance; + clty_path = Path.Pident obj_id} + and clty = + {cty_params = params'; cty_type = typ'; + cty_variance = cty_variance; + cty_path = Path.Pident obj_id; + cty_new = + match cl.pci_virt with + Virtual -> None + | Concrete -> Some (Ctype.instance constr_type)} + in + let obj_abbr = + {type_params = obj_params; + type_arity = List.length obj_params; + type_kind = Type_abstract; + type_private = Public; + type_manifest = Some obj_ty; + type_variance = List.map (fun _ -> true, true, true) obj_params} + in + let (cl_params, cl_ty) = + Ctype.instance_parameterized_type params (Ctype.self_type typ) + in + Ctype.hide_private_methods cl_ty; + Ctype.set_object_name obj_id (Ctype.row_variable cl_ty) cl_params cl_ty; + let cl_abbr = + {type_params = cl_params; + type_arity = List.length cl_params; + type_kind = Type_abstract; + type_private = Public; + type_manifest = Some cl_ty; + type_variance = List.map (fun _ -> true, true, true) cl_params} + in + ((cl, id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, List.rev !coercion_locs, expr) :: res, + env) + +let final_decl env define_class + (cl, id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coe, expr) = + + begin try Ctype.collapse_conj_params env clty.cty_params + with Ctype.Unify trace -> + raise(Error(cl.pci_loc, Non_collapsable_conjunction (id, clty, trace))) + end; + + List.iter Ctype.generalize clty.cty_params; + generalize_class_type clty.cty_type; + begin match clty.cty_new with + None -> () + | Some ty -> Ctype.generalize ty + end; + List.iter Ctype.generalize obj_abbr.type_params; + begin match obj_abbr.type_manifest with + None -> () + | Some ty -> Ctype.generalize ty + end; + List.iter Ctype.generalize cl_abbr.type_params; + begin match cl_abbr.type_manifest with + None -> () + | Some ty -> Ctype.generalize ty + end; + + if not (closed_class clty) then + raise(Error(cl.pci_loc, Non_generalizable_class (id, clty))); + + begin match + Ctype.closed_class clty.cty_params + (Ctype.signature_of_class_type clty.cty_type) + with + None -> () + | Some reason -> + let printer = + if define_class + then function ppf -> Printtyp.class_declaration id ppf clty + else function ppf -> Printtyp.cltype_declaration id ppf cltydef + in + raise(Error(cl.pci_loc, Unbound_type_var(printer, reason))) + end; + + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coe, expr, (cl.pci_variance, cl.pci_loc)) + +let extract_type_decls + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coe, expr, required) decls = + (obj_id, obj_abbr, cl_abbr, clty, cltydef, required) :: decls + +let merge_type_decls + (id, _clty, ty_id, _cltydef, obj_id, _obj_abbr, cl_id, _cl_abbr, + arity, pub_meths, coe, expr, req) (obj_abbr, cl_abbr, clty, cltydef) = + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coe, expr) + +let final_env define_class env + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coe, expr) = + (* Add definitions after cleaning them *) + Env.add_type obj_id (Subst.type_declaration Subst.identity obj_abbr) ( + Env.add_type cl_id (Subst.type_declaration Subst.identity cl_abbr) ( + Env.add_cltype ty_id (Subst.cltype_declaration Subst.identity cltydef) ( + if define_class then + Env.add_class id (Subst.class_declaration Subst.identity clty) env + else env))) + +(* Check that #c is coercible to c if there is a self-coercion *) +let check_coercions env + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, coercion_locs, expr) = + begin match coercion_locs with [] -> () + | loc :: _ -> + let cl_ty, obj_ty = + match cl_abbr.type_manifest, obj_abbr.type_manifest with + Some cl_ab, Some obj_ab -> + let cl_params, cl_ty = + Ctype.instance_parameterized_type cl_abbr.type_params cl_ab + and obj_params, obj_ty = + Ctype.instance_parameterized_type obj_abbr.type_params obj_ab + in + List.iter2 (Ctype.unify env) cl_params obj_params; + cl_ty, obj_ty + | _ -> assert false + in + begin try Ctype.subtype env cl_ty obj_ty () + with Ctype.Subtype (tr1, tr2) -> + raise(Typecore.Error(loc, Typecore.Not_subtype(tr1, tr2))) + end; + if not (Ctype.opened_object cl_ty) then + raise(Error(loc, Cannot_coerce_self obj_ty)) + end; + (id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, + arity, pub_meths, expr) + +(*******************************) + +let type_classes define_class approx kind env cls = + let cls = + List.map + (function cl -> + (cl, + Ident.create cl.pci_name, Ident.create cl.pci_name, + Ident.create cl.pci_name, Ident.create ("#" ^ cl.pci_name))) + cls + in + Ctype.init_def (Ident.current_time ()); + Ctype.begin_class_def (); + let (res, env) = + List.fold_left (initial_env define_class approx) ([], env) cls + in + let (res, env) = + List.fold_right (class_infos define_class kind) res ([], env) + in + Ctype.end_def (); + let res = List.rev_map (final_decl env define_class) res in + let decls = List.fold_right extract_type_decls res [] in + let decls = Typedecl.compute_variance_decls env decls in + let res = List.map2 merge_type_decls res decls in + let env = List.fold_left (final_env define_class) env res in + let res = List.map (check_coercions env) res in + (res, env) + +let class_num = ref 0 +let class_declaration env sexpr = + incr class_num; + let expr = class_expr (string_of_int !class_num) env env sexpr in + (expr, expr.cl_type) + +let class_description env sexpr = + let expr = class_type env sexpr in + (expr, expr) + +let class_declarations env cls = + type_classes true approx_declaration class_declaration env cls + +let class_descriptions env cls = + type_classes true approx_description class_description env cls + +let class_type_declarations env cls = + let (decl, env) = + type_classes false approx_description class_description env cls + in + (List.map + (function + (_, _, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, _, _, _) -> + (ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr)) + decl, + env) + +let rec unify_parents env ty cl = + match cl.cl_desc with + Tclass_ident p -> + begin try + let decl = Env.find_class p env in + let _, body = Ctype.find_cltype_for_path env decl.cty_path in + Ctype.unify env ty (Ctype.instance body) + with exn -> assert (exn = Not_found) + end + | Tclass_structure st -> unify_parents_struct env ty st + | Tclass_fun (_, _, cl, _) + | Tclass_apply (cl, _) + | Tclass_let (_, _, _, cl) + | Tclass_constraint (cl, _, _, _) -> unify_parents env ty cl +and unify_parents_struct env ty st = + List.iter + (function Cf_inher (cl, _, _) -> unify_parents env ty cl + | _ -> ()) + st.cl_field + +let type_object env loc s = + incr class_num; + let (desc, sign) = + class_structure (string_of_int !class_num) true env env loc s in + let sty = Ctype.expand_head env sign.cty_self in + Ctype.hide_private_methods sty; + let (fields, _) = Ctype.flatten_fields (Ctype.object_fields sty) in + let meths = List.map (fun (s,_,_) -> s) fields in + unify_parents_struct env sign.cty_self desc; + (desc, sign, meths) + +let () = + Typecore.type_object := type_object + +(*******************************) + +(* Approximate the class declaration as class ['params] id = object end *) +let approx_class sdecl = + let self' = + { ptyp_desc = Ptyp_any; ptyp_loc = Location.none } in + let clty' = + { pcty_desc = Pcty_signature(self', []); + pcty_loc = sdecl.pci_expr.pcty_loc } in + { sdecl with pci_expr = clty' } + +let approx_class_declarations env sdecls = + fst (class_type_declarations env (List.map approx_class sdecls)) + +(*******************************) + +(* Error report *) + +open Format + +let report_error ppf = function + | Repeated_parameter -> + fprintf ppf "A type parameter occurs several times" + | Unconsistent_constraint trace -> + fprintf ppf "The class constraints are not consistent.@."; + Printtyp.report_unification_error ppf trace + (fun ppf -> fprintf ppf "Type") + (fun ppf -> fprintf ppf "is not compatible with type") + | Field_type_mismatch (k, m, trace) -> + Printtyp.report_unification_error ppf trace + (function ppf -> + fprintf ppf "The %s %s@ has type" k m) + (function ppf -> + fprintf ppf "but is expected to have type") + | Structure_expected clty -> + fprintf ppf + "@[This class expression is not a class structure; it has type@ %a@]" + Printtyp.class_type clty + | Cannot_apply clty -> + fprintf ppf + "This class expression is not a class function, it cannot be applied" + | Apply_wrong_label l -> + let mark_label = function + | "" -> "out label" + | l -> sprintf " label ~%s" l in + fprintf ppf "This argument cannot be applied with%s" (mark_label l) + | Pattern_type_clash ty -> + (* XXX Trace *) + (* XXX Revoir message d'erreur *) + Printtyp.reset_and_mark_loops ty; + fprintf ppf "@[%s@ %a@]" + "This pattern cannot match self: it only matches values of type" + Printtyp.type_expr ty + | Unbound_class cl -> + fprintf ppf "@[Unbound class@ %a@]" + Printtyp.longident cl + | Unbound_class_2 cl -> + fprintf ppf "@[The class@ %a@ is not yet completely defined@]" + Printtyp.longident cl + | Unbound_class_type cl -> + fprintf ppf "@[Unbound class type@ %a@]" + Printtyp.longident cl + | Unbound_class_type_2 cl -> + fprintf ppf "@[The class type@ %a@ is not yet completely defined@]" + Printtyp.longident cl + | Abbrev_type_clash (abbrev, actual, expected) -> + (* XXX Afficher une trace ? *) + Printtyp.reset_and_mark_loops_list [abbrev; actual; expected]; + fprintf ppf "@[The abbreviation@ %a@ expands to type@ %a@ \ + but is used with type@ %a@]" + Printtyp.type_expr abbrev + Printtyp.type_expr actual + Printtyp.type_expr expected + | Constructor_type_mismatch (c, trace) -> + Printtyp.report_unification_error ppf trace + (function ppf -> + fprintf ppf "The expression \"new %s\" has type" c) + (function ppf -> + fprintf ppf "but is used with type") + | Virtual_class (cl, mets, vals) -> + let print_mets ppf mets = + List.iter (function met -> fprintf ppf "@ %s" met) mets in + let cl_mark = if cl then "" else " type" in + let missings = + match mets, vals with + [], _ -> "variables" + | _, [] -> "methods" + | _ -> "methods and variables" + in + fprintf ppf + "@[This class%s should be virtual.@ \ + @[<2>The following %s are undefined :%a@]@]" + cl_mark missings print_mets (mets @ vals) + | Parameter_arity_mismatch(lid, expected, provided) -> + fprintf ppf + "@[The class constructor %a@ expects %i type argument(s),@ \ + but is here applied to %i type argument(s)@]" + Printtyp.longident lid expected provided + | Parameter_mismatch trace -> + Printtyp.report_unification_error ppf trace + (function ppf -> + fprintf ppf "The type parameter") + (function ppf -> + fprintf ppf "does not meet its constraint: it should be") + | Bad_parameters (id, params, cstrs) -> + Printtyp.reset_and_mark_loops_list [params; cstrs]; + fprintf ppf + "@[The abbreviation %a@ is used with parameters@ %a@ \ + wich are incompatible with constraints@ %a@]" + Printtyp.ident id Printtyp.type_expr params Printtyp.type_expr cstrs + | Class_match_failure error -> + Includeclass.report_error ppf error + | Unbound_val lab -> + fprintf ppf "Unbound instance variable %s" lab + | Unbound_type_var (printer, reason) -> + let print_common ppf kind ty0 real lab ty = + let ty1 = + if real then ty0 else Btype.newgenty(Tobject(ty0, ref None)) in + Printtyp.mark_loops ty1; + fprintf ppf + "The %s %s@ has type@;<1 2>%a@ where@ %a@ is unbound" + kind lab Printtyp.type_expr ty Printtyp.type_expr ty0 + in + let print_reason ppf = function + | Ctype.CC_Method (ty0, real, lab, ty) -> + print_common ppf "method" ty0 real lab ty + | Ctype.CC_Value (ty0, real, lab, ty) -> + print_common ppf "instance variable" ty0 real lab ty + in + Printtyp.reset (); + fprintf ppf + "@[<v>@[Some type variables are unbound in this type:@;<1 2>%t@]@ \ + @[%a@]@]" + printer print_reason reason + | Make_nongen_seltype ty -> + fprintf ppf + "@[<v>@[Self type should not occur in the non-generic type@;<1 2>\ + %a@]@,\ + It would escape the scope of its class@]" + Printtyp.type_scheme ty + | Non_generalizable_class (id, clty) -> + fprintf ppf + "@[The type of this class,@ %a,@ \ + contains type variables that cannot be generalized@]" + (Printtyp.class_declaration id) clty + | Cannot_coerce_self ty -> + fprintf ppf + "@[The type of self cannot be coerced to@ \ + the type of the current class:@ %a.@.\ + Some occurences are contravariant@]" + Printtyp.type_scheme ty + | Non_collapsable_conjunction (id, clty, trace) -> + fprintf ppf + "@[The type of this class,@ %a,@ \ + contains non-collapsable conjunctive types in constraints@]" + (Printtyp.class_declaration id) clty; + Printtyp.report_unification_error ppf trace + (fun ppf -> fprintf ppf "Type") + (fun ppf -> fprintf ppf "is not compatible with type") + | Final_self_clash trace -> + Printtyp.report_unification_error ppf trace + (function ppf -> + fprintf ppf "This object is expected to have type") + (function ppf -> + fprintf ppf "but has actually type") + | Mutability_mismatch (lab, mut) -> + let mut1, mut2 = + if mut = Immutable then "mutable", "immutable" + else "immutable", "mutable" in + fprintf ppf + "@[The instance variable is %s,@ it cannot be redefined as %s@]" + mut1 mut2 diff --git a/typing/typeclass.mli b/typing/typeclass.mli new file mode 100644 index 0000000..b9ad032 --- /dev/null +++ b/typing/typeclass.mli @@ -0,0 +1,81 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typeclass.mli,v 1.19 2006-04-05 02:28:13 garrigue Exp $ *) + +open Asttypes +open Types +open Typedtree +open Format + +val class_declarations: + Env.t -> Parsetree.class_declaration list -> + (Ident.t * class_declaration * + Ident.t * cltype_declaration * + Ident.t * type_declaration * + Ident.t * type_declaration * + int * string list * class_expr) list * Env.t + +val class_descriptions: + Env.t -> Parsetree.class_description list -> + (Ident.t * class_declaration * + Ident.t * cltype_declaration * + Ident.t * type_declaration * + Ident.t * type_declaration * + int * string list * class_type) list * Env.t + +val class_type_declarations: + Env.t -> Parsetree.class_description list -> + (Ident.t * cltype_declaration * + Ident.t * type_declaration * + Ident.t * type_declaration) list * Env.t + +val approx_class_declarations: + Env.t -> Parsetree.class_description list -> + (Ident.t * cltype_declaration * + Ident.t * type_declaration * + Ident.t * type_declaration) list + +val virtual_methods: Types.class_signature -> label list + +type error = + Unconsistent_constraint of (type_expr * type_expr) list + | Field_type_mismatch of string * string * (type_expr * type_expr) list + | Structure_expected of class_type + | Cannot_apply of class_type + | Apply_wrong_label of label + | Pattern_type_clash of type_expr + | Repeated_parameter + | Unbound_class of Longident.t + | Unbound_class_2 of Longident.t + | Unbound_class_type of Longident.t + | Unbound_class_type_2 of Longident.t + | Abbrev_type_clash of type_expr * type_expr * type_expr + | Constructor_type_mismatch of string * (type_expr * type_expr) list + | Virtual_class of bool * string list * string list + | Parameter_arity_mismatch of Longident.t * int * int + | Parameter_mismatch of (type_expr * type_expr) list + | Bad_parameters of Ident.t * type_expr * type_expr + | Class_match_failure of Ctype.class_match_failure list + | Unbound_val of string + | Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure + | Make_nongen_seltype of type_expr + | Non_generalizable_class of Ident.t * Types.class_declaration + | Cannot_coerce_self of type_expr + | Non_collapsable_conjunction of + Ident.t * Types.class_declaration * (type_expr * type_expr) list + | Final_self_clash of (type_expr * type_expr) list + | Mutability_mismatch of string * mutable_flag + +exception Error of Location.t * error + +val report_error : formatter -> error -> unit diff --git a/typing/typecore.ml b/typing/typecore.ml new file mode 100644 index 0000000..4c0c501 --- /dev/null +++ b/typing/typecore.ml @@ -0,0 +1,2247 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typecore.ml,v 1.199 2008-07-29 15:42:44 doligez Exp $ *) + +(* Typechecking for the core language *) + +open Misc +open Asttypes +open Parsetree +open Types +open Typedtree +open Btype +open Ctype + +type error = + Unbound_value of Longident.t + | Unbound_constructor of Longident.t + | Unbound_label of Longident.t + | Polymorphic_label of Longident.t + | Constructor_arity_mismatch of Longident.t * int * int + | Label_mismatch of Longident.t * (type_expr * type_expr) list + | Pattern_type_clash of (type_expr * type_expr) list + | Multiply_bound_variable of string + | Orpat_vars of Ident.t + | Expr_type_clash of (type_expr * type_expr) list + | Apply_non_function of type_expr + | Apply_wrong_label of label * type_expr + | Label_multiply_defined of Longident.t + | Label_missing of string list + | Label_not_mutable of Longident.t + | Incomplete_format of string + | Bad_conversion of string * int * char + | Undefined_method of type_expr * string + | Undefined_inherited_method of string + | Unbound_class of Longident.t + | Virtual_class of Longident.t + | Private_type of type_expr + | Private_label of Longident.t * type_expr + | Unbound_instance_variable of string + | Instance_variable_not_mutable of string + | Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list + | Outside_class + | Value_multiply_overridden of string + | Coercion_failure of + type_expr * type_expr * (type_expr * type_expr) list * bool + | Too_many_arguments of bool * type_expr + | Abstract_wrong_label of label * type_expr + | Scoping_let_module of string * type_expr + | Masked_instance_variable of Longident.t + | Not_a_variant_type of Longident.t + | Incoherent_label_order + | Less_general of string * (type_expr * type_expr) list + +exception Error of Location.t * error + +(* Forward declaration, to be filled in by Typemod.type_module *) + +let type_module = + ref ((fun env md -> assert false) : + Env.t -> Parsetree.module_expr -> Typedtree.module_expr) + +(* Forward declaration, to be filled in by Typeclass.class_structure *) +let type_object = + ref (fun env s -> assert false : + Env.t -> Location.t -> Parsetree.class_structure -> + class_structure * class_signature * string list) + +(* + Saving and outputting type information. + We keep these function names short, because they have to be + called each time we create a record of type [Typedtree.expression] + or [Typedtree.pattern] that will end up in the typed AST. +*) +let re node = + Stypes.record (Stypes.Ti_expr node); + node +;; +let rp node = + Stypes.record (Stypes.Ti_pat node); + node +;; + + +(* Typing of constants *) + +let type_constant = function + Const_int _ -> instance Predef.type_int + | Const_char _ -> instance Predef.type_char + | Const_string _ -> instance Predef.type_string + | Const_float _ -> instance Predef.type_float + | Const_int32 _ -> instance Predef.type_int32 + | Const_int64 _ -> instance Predef.type_int64 + | Const_nativeint _ -> instance Predef.type_nativeint + +(* Specific version of type_option, using newty rather than newgenty *) + +let type_option ty = + newty (Tconstr(Predef.path_option,[ty], ref Mnil)) + +let option_none ty loc = + let cnone = Env.lookup_constructor (Longident.Lident "None") Env.initial in + { exp_desc = Texp_construct(cnone, []); + exp_type = ty; exp_loc = loc; exp_env = Env.initial } + +let option_some texp = + let csome = Env.lookup_constructor (Longident.Lident "Some") Env.initial in + { exp_desc = Texp_construct(csome, [texp]); exp_loc = texp.exp_loc; + exp_type = type_option texp.exp_type; exp_env = texp.exp_env } + +let extract_option_type env ty = + match expand_head env ty with {desc = Tconstr(path, [ty], _)} + when Path.same path Predef.path_option -> ty + | _ -> assert false + +let rec extract_label_names sexp env ty = + let ty = repr ty in + match ty.desc with + | Tconstr (path, _, _) -> + let td = Env.find_type path env in + begin match td.type_kind with + | Type_record (fields, _) -> + List.map (fun (name, _, _) -> name) fields + | Type_abstract when td.type_manifest <> None -> + extract_label_names sexp env (expand_head env ty) + | _ -> assert false + end + | _ -> + assert false + +(* Typing of patterns *) + +(* Creating new conjunctive types is not allowed when typing patterns *) +let unify_pat env pat expected_ty = + try + unify env pat.pat_type expected_ty + with + Unify trace -> + raise(Error(pat.pat_loc, Pattern_type_clash(trace))) + | Tags(l1,l2) -> + raise(Typetexp.Error(pat.pat_loc, Typetexp.Variant_tags (l1, l2))) + +(* make all Reither present in open variants *) +let finalize_variant pat = + match pat.pat_desc with + Tpat_variant(tag, opat, r) -> + let row = + match expand_head pat.pat_env pat.pat_type with + {desc = Tvariant row} -> r := row; row_repr row + | _ -> assert false + in + begin match row_field tag row with + | Rabsent -> assert false + | Reither (true, [], _, e) when not row.row_closed -> + set_row_field e (Rpresent None) + | Reither (false, ty::tl, _, e) when not row.row_closed -> + set_row_field e (Rpresent (Some ty)); + begin match opat with None -> assert false + | Some pat -> List.iter (unify_pat pat.pat_env pat) (ty::tl) + end + | Reither (c, l, true, e) when not row.row_fixed -> + set_row_field e (Reither (c, [], false, ref None)) + | _ -> () + end; + (* Force check of well-formedness WHY? *) + (* unify_pat pat.pat_env pat + (newty(Tvariant{row_fields=[]; row_more=newvar(); row_closed=false; + row_bound=(); row_fixed=false; row_name=None})); *) + | _ -> () + +let rec iter_pattern f p = + f p; + iter_pattern_desc (iter_pattern f) p.pat_desc + +let has_variants p = + try + iter_pattern (function {pat_desc=Tpat_variant _} -> raise Exit | _ -> ()) + p; + false + with Exit -> + true + + +(* pattern environment *) +let pattern_variables = ref ([]: (Ident.t * type_expr * Location.t) list) +let pattern_force = ref ([] : (unit -> unit) list) +let pattern_scope = ref (None : Annot.ident option);; +let reset_pattern scope = + pattern_variables := []; + pattern_force := []; + pattern_scope := scope; +;; + +let enter_variable loc name ty = + if List.exists (fun (id, _, _) -> Ident.name id = name) !pattern_variables + then raise(Error(loc, Multiply_bound_variable name)); + let id = Ident.create name in + pattern_variables := (id, ty, loc) :: !pattern_variables; + begin match !pattern_scope with + | None -> () + | Some s -> Stypes.record (Stypes.An_ident (loc, name, s)); + end; + id + +let sort_pattern_variables vs = + List.sort + (fun (x,_,_) (y,_,_) -> Pervasives.compare (Ident.name x) (Ident.name y)) + vs + +let enter_orpat_variables loc env p1_vs p2_vs = + (* unify_vars operate on sorted lists *) + + let p1_vs = sort_pattern_variables p1_vs + and p2_vs = sort_pattern_variables p2_vs in + + let rec unify_vars p1_vs p2_vs = match p1_vs, p2_vs with + | (x1,t1,l1)::rem1, (x2,t2,l2)::rem2 when Ident.equal x1 x2 -> + if x1==x2 then + unify_vars rem1 rem2 + else begin + begin try + unify env t1 t2 + with + | Unify trace -> + raise(Error(loc, Pattern_type_clash(trace))) + end ; + (x2,x1)::unify_vars rem1 rem2 + end + | [],[] -> [] + | (x,_,_)::_, [] -> raise (Error (loc, Orpat_vars x)) + | [],(x,_,_)::_ -> raise (Error (loc, Orpat_vars x)) + | (x,_,_)::_, (y,_,_)::_ -> + let min_var = + if Ident.name x < Ident.name y then x + else y in + raise (Error (loc, Orpat_vars min_var)) in + unify_vars p1_vs p2_vs + +let rec build_as_type env p = + match p.pat_desc with + Tpat_alias(p1, _) -> build_as_type env p1 + | Tpat_tuple pl -> + let tyl = List.map (build_as_type env) pl in + newty (Ttuple tyl) + | Tpat_construct(cstr, pl) -> + if cstr.cstr_private = Private then p.pat_type else + let tyl = List.map (build_as_type env) pl in + let ty_args, ty_res = instance_constructor cstr in + List.iter2 (fun (p,ty) -> unify_pat env {p with pat_type = ty}) + (List.combine pl tyl) ty_args; + ty_res + | Tpat_variant(l, p', _) -> + let ty = may_map (build_as_type env) p' in + newty (Tvariant{row_fields=[l, Rpresent ty]; row_more=newvar(); + row_bound=(); row_name=None; + row_fixed=false; row_closed=false}) + | Tpat_record lpl -> + let lbl = fst(List.hd lpl) in + if lbl.lbl_private = Private then p.pat_type else + let ty = newvar () in + let ppl = List.map (fun (l,p) -> l.lbl_pos, p) lpl in + let do_label lbl = + let _, ty_arg, ty_res = instance_label false lbl in + unify_pat env {p with pat_type = ty} ty_res; + let refinable = + lbl.lbl_mut = Immutable && List.mem_assoc lbl.lbl_pos ppl && + match (repr lbl.lbl_arg).desc with Tpoly _ -> false | _ -> true in + if refinable then begin + let arg = List.assoc lbl.lbl_pos ppl in + unify_pat env {arg with pat_type = build_as_type env arg} ty_arg + end else begin + let _, ty_arg', ty_res' = instance_label false lbl in + unify env ty_arg ty_arg'; + unify_pat env p ty_res' + end in + Array.iter do_label lbl.lbl_all; + ty + | Tpat_or(p1, p2, row) -> + begin match row with + None -> + let ty1 = build_as_type env p1 and ty2 = build_as_type env p2 in + unify_pat env {p2 with pat_type = ty2} ty1; + ty1 + | Some row -> + let row = row_repr row in + newty (Tvariant{row with row_closed=false; row_more=newvar()}) + end + | Tpat_any | Tpat_var _ | Tpat_constant _ + | Tpat_array _ | Tpat_lazy _ -> p.pat_type + +let build_or_pat env loc lid = + let path, decl = + try Env.lookup_type lid env + with Not_found -> + raise(Typetexp.Error(loc, Typetexp.Unbound_type_constructor lid)) + in + let tyl = List.map (fun _ -> newvar()) decl.type_params in + let row0 = + let ty = expand_head env (newty(Tconstr(path, tyl, ref Mnil))) in + match ty.desc with + Tvariant row when static_row row -> row + | _ -> raise(Error(loc, Not_a_variant_type lid)) + in + let pats, fields = + List.fold_left + (fun (pats,fields) (l,f) -> + match row_field_repr f with + Rpresent None -> + (l,None) :: pats, + (l, Reither(true,[], true, ref None)) :: fields + | Rpresent (Some ty) -> + (l, Some {pat_desc=Tpat_any; pat_loc=Location.none; pat_env=env; + pat_type=ty}) + :: pats, + (l, Reither(false, [ty], true, ref None)) :: fields + | _ -> pats, fields) + ([],[]) (row_repr row0).row_fields in + let row = + { row_fields = List.rev fields; row_more = newvar(); row_bound = (); + row_closed = false; row_fixed = false; row_name = Some (path, tyl) } + in + let ty = newty (Tvariant row) in + let gloc = {loc with Location.loc_ghost=true} in + let row' = ref {row with row_more=newvar()} in + let pats = + List.map (fun (l,p) -> {pat_desc=Tpat_variant(l,p,row'); pat_loc=gloc; + pat_env=env; pat_type=ty}) + pats + in + match pats with + [] -> raise(Error(loc, Not_a_variant_type lid)) + | pat :: pats -> + let r = + List.fold_left + (fun pat pat0 -> {pat_desc=Tpat_or(pat0,pat,Some row0); + pat_loc=gloc; pat_env=env; pat_type=ty}) + pat pats in + rp { r with pat_loc = loc } + +let rec find_record_qual = function + | [] -> None + | (Longident.Ldot (modname, _), _) :: _ -> Some modname + | _ :: rest -> find_record_qual rest + +let type_label_a_list type_lid_a lid_a_list = + match find_record_qual lid_a_list with + | None -> List.map type_lid_a lid_a_list + | Some modname -> + List.map + (function + | (Longident.Lident id), sarg -> + type_lid_a (Longident.Ldot (modname, id), sarg) + | lid_a -> type_lid_a lid_a) + lid_a_list + +let rec type_pat env sp = + match sp.ppat_desc with + Ppat_any -> + rp { + pat_desc = Tpat_any; + pat_loc = sp.ppat_loc; + pat_type = newvar(); + pat_env = env } + | Ppat_var name -> + let ty = newvar() in + let id = enter_variable sp.ppat_loc name ty in + rp { + pat_desc = Tpat_var id; + pat_loc = sp.ppat_loc; + pat_type = ty; + pat_env = env } + | Ppat_alias(sq, name) -> + let q = type_pat env sq in + begin_def (); + let ty_var = build_as_type env q in + end_def (); + generalize ty_var; + let id = enter_variable sp.ppat_loc name ty_var in + rp { + pat_desc = Tpat_alias(q, id); + pat_loc = sp.ppat_loc; + pat_type = q.pat_type; + pat_env = env } + | Ppat_constant cst -> + rp { + pat_desc = Tpat_constant cst; + pat_loc = sp.ppat_loc; + pat_type = type_constant cst; + pat_env = env } + | Ppat_tuple spl -> + let pl = List.map (type_pat env) spl in + rp { + pat_desc = Tpat_tuple pl; + pat_loc = sp.ppat_loc; + pat_type = newty (Ttuple(List.map (fun p -> p.pat_type) pl)); + pat_env = env } + | Ppat_construct(lid, sarg, explicit_arity) -> + let constr = + try + Env.lookup_constructor lid env + with Not_found -> + raise(Error(sp.ppat_loc, Unbound_constructor lid)) in + let sargs = + match sarg with + None -> [] + | Some {ppat_desc = Ppat_tuple spl} when explicit_arity -> spl + | Some {ppat_desc = Ppat_tuple spl} when constr.cstr_arity > 1 -> spl + | Some({ppat_desc = Ppat_any} as sp) when constr.cstr_arity <> 1 -> + replicate_list sp constr.cstr_arity + | Some sp -> [sp] in + if List.length sargs <> constr.cstr_arity then + raise(Error(sp.ppat_loc, Constructor_arity_mismatch(lid, + constr.cstr_arity, List.length sargs))); + let args = List.map (type_pat env) sargs in + let (ty_args, ty_res) = instance_constructor constr in + List.iter2 (unify_pat env) args ty_args; + rp { + pat_desc = Tpat_construct(constr, args); + pat_loc = sp.ppat_loc; + pat_type = ty_res; + pat_env = env } + | Ppat_variant(l, sarg) -> + let arg = may_map (type_pat env) sarg in + let arg_type = match arg with None -> [] | Some arg -> [arg.pat_type] in + let row = { row_fields = + [l, Reither(arg = None, arg_type, true, ref None)]; + row_bound = (); + row_closed = false; + row_more = newvar (); + row_fixed = false; + row_name = None } in + rp { + pat_desc = Tpat_variant(l, arg, ref {row with row_more = newvar()}); + pat_loc = sp.ppat_loc; + pat_type = newty (Tvariant row); + pat_env = env } + | Ppat_record lid_sp_list -> + let rec check_duplicates = function + [] -> () + | (lid, sarg) :: remainder -> + if List.mem_assoc lid remainder + then raise(Error(sp.ppat_loc, Label_multiply_defined lid)) + else check_duplicates remainder in + check_duplicates lid_sp_list; + let ty = newvar() in + let type_label_pat (lid, sarg) = + let label = + try + Env.lookup_label lid env + with Not_found -> + raise(Error(sp.ppat_loc, Unbound_label lid)) in + begin_def (); + let (vars, ty_arg, ty_res) = instance_label false label in + if vars = [] then end_def (); + begin try + unify env ty_res ty + with Unify trace -> + raise(Error(sp.ppat_loc, Label_mismatch(lid, trace))) + end; + let arg = type_pat env sarg in + unify_pat env arg ty_arg; + if vars <> [] then begin + end_def (); + generalize ty_arg; + List.iter generalize vars; + let instantiated tv = + let tv = expand_head env tv in + tv.desc <> Tvar || tv.level <> generic_level in + if List.exists instantiated vars then + raise (Error(sp.ppat_loc, Polymorphic_label lid)) + end; + (label, arg) + in + rp { + pat_desc = Tpat_record(type_label_a_list type_label_pat lid_sp_list); + pat_loc = sp.ppat_loc; + pat_type = ty; + pat_env = env } + | Ppat_array spl -> + let pl = List.map (type_pat env) spl in + let ty_elt = newvar() in + List.iter (fun p -> unify_pat env p ty_elt) pl; + rp { + pat_desc = Tpat_array pl; + pat_loc = sp.ppat_loc; + pat_type = instance (Predef.type_array ty_elt); + pat_env = env } + | Ppat_or(sp1, sp2) -> + let initial_pattern_variables = !pattern_variables in + let p1 = type_pat env sp1 in + let p1_variables = !pattern_variables in + pattern_variables := initial_pattern_variables ; + let p2 = type_pat env sp2 in + let p2_variables = !pattern_variables in + unify_pat env p2 p1.pat_type; + let alpha_env = + enter_orpat_variables sp.ppat_loc env p1_variables p2_variables in + pattern_variables := p1_variables ; + rp { + pat_desc = Tpat_or(p1, alpha_pat alpha_env p2, None); + pat_loc = sp.ppat_loc; + pat_type = p1.pat_type; + pat_env = env } + | Ppat_lazy sp1 -> + let p1 = type_pat env sp1 in + rp { + pat_desc = Tpat_lazy p1; + pat_loc = sp.ppat_loc; + pat_type = instance (Predef.type_lazy_t p1.pat_type); + pat_env = env } + | Ppat_constraint(sp, sty) -> + let p = type_pat env sp in + let ty, force = Typetexp.transl_simple_type_delayed env sty in + unify_pat env p ty; + pattern_force := force :: !pattern_force; + p + | Ppat_type lid -> + build_or_pat env sp.ppat_loc lid + +let get_ref r = + let v = !r in r := []; v + +let add_pattern_variables env = + let pv = get_ref pattern_variables in + List.fold_right + (fun (id, ty, loc) env -> + let e1 = Env.add_value id {val_type = ty; val_kind = Val_reg} env in + Env.add_annot id (Annot.Iref_internal loc) e1; + ) + pv env + +let type_pattern env spat scope = + reset_pattern scope; + let pat = type_pat env spat in + let new_env = add_pattern_variables env in + (pat, new_env, get_ref pattern_force) + +let type_pattern_list env spatl scope = + reset_pattern scope; + let patl = List.map (type_pat env) spatl in + let new_env = add_pattern_variables env in + (patl, new_env, get_ref pattern_force) + +let type_class_arg_pattern cl_num val_env met_env l spat = + reset_pattern None; + let pat = type_pat val_env spat in + if has_variants pat then begin + Parmatch.pressure_variants val_env [pat]; + iter_pattern finalize_variant pat + end; + List.iter (fun f -> f()) (get_ref pattern_force); + if is_optional l then unify_pat val_env pat (type_option (newvar ())); + let (pv, met_env) = + List.fold_right + (fun (id, ty, loc) (pv, env) -> + let id' = Ident.create (Ident.name id) in + ((id', id, ty)::pv, + Env.add_value id' {val_type = ty; + val_kind = Val_ivar (Immutable, cl_num)} + env)) + !pattern_variables ([], met_env) + in + let val_env = add_pattern_variables val_env in + (pat, pv, val_env, met_env) + +let mkpat d = { ppat_desc = d; ppat_loc = Location.none } + +let type_self_pattern cl_num privty val_env met_env par_env spat = + let spat = + mkpat (Ppat_alias (mkpat(Ppat_alias (spat, "selfpat-*")), + "selfpat-" ^ cl_num)) + in + reset_pattern None; + let pat = type_pat val_env spat in + List.iter (fun f -> f()) (get_ref pattern_force); + let meths = ref Meths.empty in + let vars = ref Vars.empty in + let pv = !pattern_variables in + pattern_variables := []; + let (val_env, met_env, par_env) = + List.fold_right + (fun (id, ty, loc) (val_env, met_env, par_env) -> + (Env.add_value id {val_type = ty; val_kind = Val_unbound} val_env, + Env.add_value id {val_type = ty; + val_kind = Val_self (meths, vars, cl_num, privty)} + met_env, + Env.add_value id {val_type = ty; val_kind = Val_unbound} par_env)) + pv (val_env, met_env, par_env) + in + (pat, meths, vars, val_env, met_env, par_env) + +let delayed_checks = ref [] +let reset_delayed_checks () = delayed_checks := [] +let add_delayed_check f = delayed_checks := f :: !delayed_checks +let force_delayed_checks () = + (* checks may change type levels *) + let snap = Btype.snapshot () in + List.iter (fun f -> f ()) (List.rev !delayed_checks); + reset_delayed_checks (); + Btype.backtrack snap + + +(* Generalization criterion for expressions *) + +let rec is_nonexpansive exp = + match exp.exp_desc with + Texp_ident(_,_) -> true + | Texp_constant _ -> true + | Texp_let(rec_flag, pat_exp_list, body) -> + List.for_all (fun (pat, exp) -> is_nonexpansive exp) pat_exp_list && + is_nonexpansive body + | Texp_function _ -> true + | Texp_apply(e, (None,_)::el) -> + is_nonexpansive e && List.for_all is_nonexpansive_opt (List.map fst el) + | Texp_tuple el -> + List.for_all is_nonexpansive el + | Texp_construct(_, el) -> + List.for_all is_nonexpansive el + | Texp_variant(_, arg) -> is_nonexpansive_opt arg + | Texp_record(lbl_exp_list, opt_init_exp) -> + List.for_all + (fun (lbl, exp) -> lbl.lbl_mut = Immutable && is_nonexpansive exp) + lbl_exp_list + && is_nonexpansive_opt opt_init_exp + | Texp_field(exp, lbl) -> is_nonexpansive exp + | Texp_array [] -> true + | Texp_ifthenelse(cond, ifso, ifnot) -> + is_nonexpansive ifso && is_nonexpansive_opt ifnot + | Texp_sequence (e1, e2) -> is_nonexpansive e2 (* PR#4354 *) + | Texp_new (_, cl_decl) when Ctype.class_type_arity cl_decl.cty_type > 0 -> + true + (* Note: nonexpansive only means no _observable_ side effects *) + | Texp_lazy e -> is_nonexpansive e + | Texp_object ({cl_field=fields}, {cty_vars=vars}, _) -> + let count = ref 0 in + List.for_all + (function + Cf_meth _ -> true + | Cf_val (_,_,e,_) -> incr count; is_nonexpansive_opt e + | Cf_init e -> is_nonexpansive e + | Cf_inher _ | Cf_let _ -> false) + fields && + Vars.fold (fun _ (mut,_,_) b -> decr count; b && mut = Immutable) + vars true && + !count = 0 + | _ -> false + +and is_nonexpansive_opt = function + None -> true + | Some e -> is_nonexpansive e + +(* Typing of printf formats. + (Handling of * modifiers contributed by Thorsten Ohl.) *) + +external string_to_format : + string -> ('a, 'b, 'c, 'd, 'e, 'f) format6 = "%identity" +external format_to_string : + ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string = "%identity" + +let type_format loc fmt = + + let ty_arrow gty ty = newty (Tarrow ("", instance gty, ty, Cok)) in + + let bad_conversion fmt i c = + raise (Error (loc, Bad_conversion (fmt, i, c))) in + let incomplete_format fmt = + raise (Error (loc, Incomplete_format fmt)) in + + let range_closing_index fmt i = + + let len = String.length fmt in + let find_closing j = + if j >= len then incomplete_format fmt else + try String.index_from fmt j ']' with + | Not_found -> incomplete_format fmt in + let skip_pos j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | ']' -> find_closing (j + 1) + | c -> find_closing j in + let rec skip_neg j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '^' -> skip_pos (j + 1) + | c -> skip_pos j in + find_closing (skip_neg (i + 1)) in + + let rec type_in_format fmt = + + let len = String.length fmt in + + let ty_input = newvar () + and ty_result = newvar () + and ty_aresult = newvar () + and ty_uresult = newvar () in + + let meta = ref 0 in + + let rec scan_format i = + if i >= len then + if !meta = 0 + then ty_uresult, ty_result + else incomplete_format fmt else + match fmt.[i] with + | '%' -> scan_opts i (i + 1) + | _ -> scan_format (i + 1) + and scan_opts i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '_' -> scan_rest true i (j + 1) + | _ -> scan_rest false i j + and scan_rest skip i j = + let rec scan_flags i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '#' | '0' | '-' | ' ' | '+' -> scan_flags i (j + 1) + | _ -> scan_width i j + and scan_width i j = scan_width_or_prec_value scan_precision i j + and scan_decimal_string scan i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '0' .. '9' -> scan_decimal_string scan i (j + 1) + | _ -> scan i j + and scan_width_or_prec_value scan i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '*' -> + let ty_uresult, ty_result = scan i (j + 1) in + ty_uresult, ty_arrow Predef.type_int ty_result + | '-' | '+' -> scan_decimal_string scan i (j + 1) + | _ -> scan_decimal_string scan i j + and scan_precision i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '.' -> scan_width_or_prec_value scan_conversion i (j + 1) + | _ -> scan_conversion i j + + and conversion j ty_arg = + let ty_uresult, ty_result = scan_format (j + 1) in + ty_uresult, + if skip then ty_result else ty_arrow ty_arg ty_result + + and scan_conversion i j = + if j >= len then incomplete_format fmt else + match fmt.[j] with + | '%' | '!' -> scan_format (j + 1) + | 's' | 'S' -> conversion j Predef.type_string + | '[' -> + let j = range_closing_index fmt j in + conversion j Predef.type_string + | 'c' | 'C' -> conversion j Predef.type_char + | 'd' | 'i' | 'o' | 'x' | 'X' | 'u' | 'N' -> + conversion j Predef.type_int + | 'f' | 'e' | 'E' | 'g' | 'G' | 'F' -> conversion j Predef.type_float + | 'B' | 'b' -> conversion j Predef.type_bool + | 'a' -> + let ty_arg = newvar () in + let ty_a = ty_arrow ty_input (ty_arrow ty_arg ty_aresult) in + let ty_uresult, ty_result = conversion j ty_arg in + ty_uresult, ty_arrow ty_a ty_result + | 'r' -> + let ty_arg = newvar () in + let ty_r = ty_arrow ty_input ty_arg in + let ty_uresult, ty_result = conversion j ty_arg in + ty_arrow ty_r ty_uresult, ty_result + | 't' -> conversion j (ty_arrow ty_input ty_aresult) + | 'l' | 'n' | 'L' as c -> + let j = j + 1 in + if j >= len then conversion (j - 1) Predef.type_int else begin + match fmt.[j] with + | 'd' | 'i' | 'o' | 'x' | 'X' | 'u' -> + let ty_arg = + match c with + | 'l' -> Predef.type_int32 + | 'n' -> Predef.type_nativeint + | _ -> Predef.type_int64 in + conversion j ty_arg + | c -> conversion (j - 1) Predef.type_int + end + | '{' | '(' as c -> + let j = j + 1 in + if j >= len then incomplete_format fmt else + let sj = + Printf.CamlinternalPr.Tformat.sub_format + (fun fmt -> incomplete_format (format_to_string fmt)) + (fun fmt -> bad_conversion (format_to_string fmt)) + c (string_to_format fmt) j in + let sfmt = String.sub fmt j (sj - 2 - j) in + let ty_sfmt = type_in_format sfmt in + begin match c with + | '{' -> conversion (sj - 1) ty_sfmt + | _ -> incr meta; conversion (j - 1) ty_sfmt end + | ')' when !meta > 0 -> decr meta; scan_format (j + 1) + | c -> bad_conversion fmt i c in + scan_flags i j in + + let ty_ureader, ty_args = scan_format 0 in + newty + (Tconstr + (Predef.path_format6, + [ty_args; ty_input; ty_aresult; ty_ureader; ty_uresult; ty_result], + ref Mnil)) in + + type_in_format fmt + +(* Approximate the type of an expression, for better recursion *) + +let rec approx_type env sty = + match sty.ptyp_desc with + Ptyp_arrow (p, _, sty) -> + let ty1 = if is_optional p then type_option (newvar ()) else newvar () in + newty (Tarrow (p, ty1, approx_type env sty, Cok)) + | Ptyp_tuple args -> + newty (Ttuple (List.map (approx_type env) args)) + | Ptyp_constr (lid, ctl) -> + begin try + let (path, decl) = Env.lookup_type lid env in + if List.length ctl <> decl.type_arity then raise Not_found; + let tyl = List.map (approx_type env) ctl in + newconstr path tyl + with Not_found -> newvar () + end + | _ -> newvar () + +let rec type_approx env sexp = + match sexp.pexp_desc with + Pexp_let (_, _, e) -> type_approx env e + | Pexp_function (p,_,(_,e)::_) when is_optional p -> + newty (Tarrow(p, type_option (newvar ()), type_approx env e, Cok)) + | Pexp_function (p,_,(_,e)::_) -> + newty (Tarrow(p, newvar (), type_approx env e, Cok)) + | Pexp_match (_, (_,e)::_) -> type_approx env e + | Pexp_try (e, _) -> type_approx env e + | Pexp_tuple l -> newty (Ttuple(List.map (type_approx env) l)) + | Pexp_ifthenelse (_,e,_) -> type_approx env e + | Pexp_sequence (_,e) -> type_approx env e + | Pexp_constraint (e, sty1, sty2) -> + let approx_ty_opt = function + | None -> newvar () + | Some sty -> approx_type env sty + in + let ty = type_approx env e + and ty1 = approx_ty_opt sty1 + and ty2 = approx_ty_opt sty2 in + begin try unify env ty ty1 with Unify trace -> + raise(Error(sexp.pexp_loc, Expr_type_clash trace)) + end; + if sty2 = None then ty1 else ty2 + | _ -> newvar () + +(* List labels in a function type, and whether return type is a variable *) +let rec list_labels_aux env visited ls ty_fun = + let ty = expand_head env ty_fun in + if List.memq ty visited then + List.rev ls, false + else match ty.desc with + Tarrow (l, _, ty_res, _) -> + list_labels_aux env (ty::visited) (l::ls) ty_res + | _ -> + List.rev ls, ty.desc = Tvar + +let list_labels env ty = list_labels_aux env [] [] ty + +(* Check that all univars are safe in a type *) +let check_univars env kind exp ty_expected vars = + (* need to expand twice? cf. Ctype.unify2 *) + let vars = List.map (expand_head env) vars in + let vars = List.map (expand_head env) vars in + let vars' = + List.filter + (fun t -> + let t = repr t in + generalize t; + if t.desc = Tvar && t.level = generic_level then + (log_type t; t.desc <- Tunivar; true) + else false) + vars in + if List.length vars = List.length vars' then () else + let ty = newgenty (Tpoly(repr exp.exp_type, vars')) + and ty_expected = repr ty_expected in + raise (Error (exp.exp_loc, + Less_general(kind, [ty, ty; ty_expected, ty_expected]))) + +(* Check that a type is not a function *) +let check_application_result env statement exp = + match (expand_head env exp.exp_type).desc with + | Tarrow _ -> + Location.prerr_warning exp.exp_loc Warnings.Partial_application + | Tvar -> () + | Tconstr (p, _, _) when Path.same p Predef.path_unit -> () + | _ -> + if statement then + Location.prerr_warning exp.exp_loc Warnings.Statement_type + +(* Check that a type is generalizable at some level *) +let generalizable level ty = + let rec check ty = + let ty = repr ty in + if ty.level < lowest_level then () else + if ty.level <= level then raise Exit else + (mark_type_node ty; iter_type_expr check ty) + in + try check ty; unmark_type ty; true + with Exit -> unmark_type ty; false + +(* Hack to allow coercion of self. Will clean-up later. *) +let self_coercion = ref ([] : (Path.t * Location.t list ref) list) + +(* Typing of expressions *) + +let unify_exp env exp expected_ty = + (* Format.eprintf "@[%a@ %a@]@." Printtyp.raw_type_expr exp.exp_type + Printtyp.raw_type_expr expected_ty; *) + try + unify env exp.exp_type expected_ty + with + Unify trace -> + raise(Error(exp.exp_loc, Expr_type_clash(trace))) + | Tags(l1,l2) -> + raise(Typetexp.Error(exp.exp_loc, Typetexp.Variant_tags (l1, l2))) + +let rec type_exp env sexp = + match sexp.pexp_desc with + Pexp_ident lid -> + begin try + if !Clflags.annotations then begin + try let (path, annot) = Env.lookup_annot lid env in + Stypes.record (Stypes.An_ident (sexp.pexp_loc, Path.name path, + annot)); + with _ -> () + end; + let (path, desc) = Env.lookup_value lid env in + re { + exp_desc = + begin match desc.val_kind with + Val_ivar (_, cl_num) -> + let (self_path, _) = + Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env + in + Texp_instvar(self_path, path) + | Val_self (_, _, cl_num, _) -> + let (path, _) = + Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env + in + Texp_ident(path, desc) + | Val_unbound -> + raise(Error(sexp.pexp_loc, Masked_instance_variable lid)) + | _ -> + Texp_ident(path, desc) + end; + exp_loc = sexp.pexp_loc; + exp_type = instance desc.val_type; + exp_env = env } + with Not_found -> + raise(Error(sexp.pexp_loc, Unbound_value lid)) + end + | Pexp_constant cst -> + re { + exp_desc = Texp_constant cst; + exp_loc = sexp.pexp_loc; + exp_type = type_constant cst; + exp_env = env } + | Pexp_let(rec_flag, spat_sexp_list, sbody) -> + let scp = + match rec_flag with + | Recursive -> Some (Annot.Idef sexp.pexp_loc) + | Nonrecursive -> Some (Annot.Idef sbody.pexp_loc) + | Default -> None + in + let (pat_exp_list, new_env) = type_let env rec_flag spat_sexp_list scp in + let body = type_exp new_env sbody in + re { + exp_desc = Texp_let(rec_flag, pat_exp_list, body); + exp_loc = sexp.pexp_loc; + exp_type = body.exp_type; + exp_env = env } + | Pexp_function _ -> (* defined in type_expect *) + type_expect env sexp (newvar()) + | Pexp_apply(sfunct, sargs) -> + begin_def (); (* one more level for non-returning functions *) + if !Clflags.principal then begin_def (); + let funct = type_exp env sfunct in + if !Clflags.principal then begin + end_def (); + generalize_structure funct.exp_type + end; + let rec lower_args seen ty_fun = + let ty = expand_head env ty_fun in + if List.memq ty seen then () else + match ty.desc with + Tarrow (l, ty_arg, ty_fun, com) -> + unify_var env (newvar()) ty_arg; + lower_args (ty::seen) ty_fun + | _ -> () + in + let ty = instance funct.exp_type in + end_def (); + lower_args [] ty; + begin_def (); + let (args, ty_res) = type_application env funct sargs in + end_def (); + unify_var env (newvar()) funct.exp_type; + re { + exp_desc = Texp_apply(funct, args); + exp_loc = sexp.pexp_loc; + exp_type = ty_res; + exp_env = env } + | Pexp_match(sarg, caselist) -> + let arg = type_exp env sarg in + let ty_res = newvar() in + let cases, partial = + type_cases env arg.exp_type ty_res (Some sexp.pexp_loc) caselist + in + re { + exp_desc = Texp_match(arg, cases, partial); + exp_loc = sexp.pexp_loc; + exp_type = ty_res; + exp_env = env } + | Pexp_try(sbody, caselist) -> + let body = type_exp env sbody in + let cases, _ = + type_cases env (instance Predef.type_exn) body.exp_type None + caselist in + re { + exp_desc = Texp_try(body, cases); + exp_loc = sexp.pexp_loc; + exp_type = body.exp_type; + exp_env = env } + | Pexp_tuple sexpl -> + let expl = List.map (type_exp env) sexpl in + re { + exp_desc = Texp_tuple expl; + exp_loc = sexp.pexp_loc; + exp_type = newty (Ttuple(List.map (fun exp -> exp.exp_type) expl)); + exp_env = env } + | Pexp_construct(lid, sarg, explicit_arity) -> + type_construct env sexp.pexp_loc lid sarg explicit_arity (newvar ()) + | Pexp_variant(l, sarg) -> + let arg = may_map (type_exp env) sarg in + let arg_type = may_map (fun arg -> arg.exp_type) arg in + re { + exp_desc = Texp_variant(l, arg); + exp_loc = sexp.pexp_loc; + exp_type= newty (Tvariant{row_fields = [l, Rpresent arg_type]; + row_more = newvar (); + row_bound = (); + row_closed = false; + row_fixed = false; + row_name = None}); + exp_env = env } + | Pexp_record(lid_sexp_list, opt_sexp) -> + let ty = newvar() in + let num_fields = ref 0 in + let type_label_exp (lid, sarg) = + let label = + try + Env.lookup_label lid env + with Not_found -> + raise(Error(sexp.pexp_loc, Unbound_label lid)) in + begin_def (); + if !Clflags.principal then begin_def (); + let (vars, ty_arg, ty_res) = instance_label true label in + if !Clflags.principal then begin + end_def (); + generalize_structure ty_arg; + generalize_structure ty_res + end; + begin try + unify env (instance ty_res) ty + with Unify trace -> + raise(Error(sexp.pexp_loc, Label_mismatch(lid, trace))) + end; + let arg = type_argument env sarg ty_arg in + end_def (); + if vars <> [] && not (is_nonexpansive arg) then + generalize_expansive env arg.exp_type; + check_univars env "field value" arg label.lbl_arg vars; + num_fields := Array.length label.lbl_all; + if label.lbl_private = Private then + raise(Error(sexp.pexp_loc, Private_type ty)); + (label, {arg with exp_type = instance arg.exp_type}) in + let lbl_exp_list = type_label_a_list type_label_exp lid_sexp_list in + let rec check_duplicates seen_pos lid_sexp lbl_exp = + match (lid_sexp, lbl_exp) with + ((lid, _) :: rem1, (lbl, _) :: rem2) -> + if List.mem lbl.lbl_pos seen_pos + then raise(Error(sexp.pexp_loc, Label_multiply_defined lid)) + else check_duplicates (lbl.lbl_pos :: seen_pos) rem1 rem2 + | (_, _) -> () in + check_duplicates [] lid_sexp_list lbl_exp_list; + let opt_exp = + match opt_sexp, lbl_exp_list with + None, _ -> None + | Some sexp, (lbl, _) :: _ -> + let ty_exp = newvar () in + let unify_kept lbl = + if List.for_all (fun (lbl',_) -> lbl'.lbl_pos <> lbl.lbl_pos) + lbl_exp_list + then begin + let _, ty_arg1, ty_res1 = instance_label false lbl + and _, ty_arg2, ty_res2 = instance_label false lbl in + unify env ty_exp ty_res1; + unify env ty ty_res2; + unify env ty_arg1 ty_arg2 + end in + Array.iter unify_kept lbl.lbl_all; + Some(type_expect env sexp ty_exp) + | _ -> assert false + in + if opt_sexp = None && List.length lid_sexp_list <> !num_fields then begin + let present_indices = + List.map (fun (lbl, _) -> lbl.lbl_pos) lbl_exp_list in + let label_names = extract_label_names sexp env ty in + let rec missing_labels n = function + [] -> [] + | lbl :: rem -> + if List.mem n present_indices then missing_labels (n + 1) rem + else lbl :: missing_labels (n + 1) rem + in + let missing = missing_labels 0 label_names in + raise(Error(sexp.pexp_loc, Label_missing missing)) + end + else if opt_sexp <> None && List.length lid_sexp_list = !num_fields then + Location.prerr_warning sexp.pexp_loc Warnings.Useless_record_with; + re { + exp_desc = Texp_record(lbl_exp_list, opt_exp); + exp_loc = sexp.pexp_loc; + exp_type = ty; + exp_env = env } + | Pexp_field(sarg, lid) -> + let arg = type_exp env sarg in + let label = + try + Env.lookup_label lid env + with Not_found -> + raise(Error(sexp.pexp_loc, Unbound_label lid)) in + let (_, ty_arg, ty_res) = instance_label false label in + unify_exp env arg ty_res; + re { + exp_desc = Texp_field(arg, label); + exp_loc = sexp.pexp_loc; + exp_type = ty_arg; + exp_env = env } + | Pexp_setfield(srecord, lid, snewval) -> + let record = type_exp env srecord in + let label = + try + Env.lookup_label lid env + with Not_found -> + raise(Error(sexp.pexp_loc, Unbound_label lid)) in + if label.lbl_mut = Immutable then + raise(Error(sexp.pexp_loc, Label_not_mutable lid)); + begin_def (); + let (vars, ty_arg, ty_res) = instance_label true label in + unify_exp env record ty_res; + let newval = type_expect env snewval ty_arg in + end_def (); + if vars <> [] && not (is_nonexpansive newval) then + generalize_expansive env newval.exp_type; + check_univars env "field value" newval label.lbl_arg vars; + if label.lbl_private = Private then + raise(Error(sexp.pexp_loc, Private_label(lid, ty_res))); + re { + exp_desc = Texp_setfield(record, label, newval); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env } + | Pexp_array(sargl) -> + let ty = newvar() in + let argl = List.map (fun sarg -> type_expect env sarg ty) sargl in + re { + exp_desc = Texp_array argl; + exp_loc = sexp.pexp_loc; + exp_type = instance (Predef.type_array ty); + exp_env = env } + | Pexp_ifthenelse(scond, sifso, sifnot) -> + let cond = type_expect env scond (instance Predef.type_bool) in + begin match sifnot with + None -> + let ifso = type_expect env sifso (instance Predef.type_unit) in + re { + exp_desc = Texp_ifthenelse(cond, ifso, None); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env } + | Some sifnot -> + let ifso = type_exp env sifso in + let ifnot = type_expect env sifnot ifso.exp_type in + re { + exp_desc = Texp_ifthenelse(cond, ifso, Some ifnot); + exp_loc = sexp.pexp_loc; + exp_type = ifso.exp_type; + exp_env = env } + end + | Pexp_sequence(sexp1, sexp2) -> + let exp1 = type_statement env sexp1 in + let exp2 = type_exp env sexp2 in + re { + exp_desc = Texp_sequence(exp1, exp2); + exp_loc = sexp.pexp_loc; + exp_type = exp2.exp_type; + exp_env = env } + | Pexp_while(scond, sbody) -> + let cond = type_expect env scond (instance Predef.type_bool) in + let body = type_statement env sbody in + re { + exp_desc = Texp_while(cond, body); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env } + | Pexp_for(param, slow, shigh, dir, sbody) -> + let low = type_expect env slow (instance Predef.type_int) in + let high = type_expect env shigh (instance Predef.type_int) in + let (id, new_env) = + Env.enter_value param {val_type = instance Predef.type_int; + val_kind = Val_reg} env in + let body = type_statement new_env sbody in + re { + exp_desc = Texp_for(id, low, high, dir, body); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env } + | Pexp_constraint(sarg, sty, sty') -> + let (arg, ty') = + match (sty, sty') with + (None, None) -> (* Case actually unused *) + let arg = type_exp env sarg in + (arg, arg.exp_type) + | (Some sty, None) -> + if !Clflags.principal then begin_def (); + let ty = Typetexp.transl_simple_type env false sty in + if !Clflags.principal then begin + end_def (); + generalize_structure ty; + let ty1 = instance ty and ty2 = instance ty in + (type_expect env sarg ty1, ty2) + end else + (type_expect env sarg ty, ty) + | (None, Some sty') -> + let (ty', force) = + Typetexp.transl_simple_type_delayed env sty' + in + if !Clflags.principal then begin_def (); + let arg = type_exp env sarg in + let gen = + if !Clflags.principal then begin + end_def (); + let tv = newvar () in + let gen = generalizable tv.level arg.exp_type in + unify_var env tv arg.exp_type; + gen + end else true + in + begin match arg.exp_desc, !self_coercion, (repr ty').desc with + Texp_ident(_, {val_kind=Val_self _}), (path,r) :: _, + Tconstr(path',_,_) when Path.same path path' -> + r := sexp.pexp_loc :: !r; + force () + | _ when free_variables arg.exp_type = [] + && free_variables ty' = [] -> + if not gen && (* first try a single coercion *) + let snap = snapshot () in + let ty, b = enlarge_type env ty' in + try + force (); Ctype.unify env arg.exp_type ty; true + with Unify _ -> + backtrack snap; false + then () + else begin try + let force' = subtype env arg.exp_type ty' in + force (); force' (); + if not gen then + Location.prerr_warning sexp.pexp_loc + (Warnings.Not_principal "this ground coercion"); + with Subtype (tr1, tr2) -> + raise(Error(sexp.pexp_loc, Not_subtype(tr1, tr2))) + end; + | _ -> + let ty, b = enlarge_type env ty' in + force (); + begin try Ctype.unify env arg.exp_type ty with Unify trace -> + raise(Error(sarg.pexp_loc, + Coercion_failure(ty', full_expand env ty', trace, b))) + end + end; + (arg, ty') + | (Some sty, Some sty') -> + let (ty, force) = + Typetexp.transl_simple_type_delayed env sty + and (ty', force') = + Typetexp.transl_simple_type_delayed env sty' + in + begin try + let force'' = subtype env ty ty' in + force (); force' (); force'' () + with Subtype (tr1, tr2) -> + raise(Error(sexp.pexp_loc, Not_subtype(tr1, tr2))) + end; + (type_expect env sarg ty, ty') + in + re { + exp_desc = arg.exp_desc; + exp_loc = arg.exp_loc; + exp_type = ty'; + exp_env = env } + | Pexp_when(scond, sbody) -> + let cond = type_expect env scond (instance Predef.type_bool) in + let body = type_exp env sbody in + re { + exp_desc = Texp_when(cond, body); + exp_loc = sexp.pexp_loc; + exp_type = body.exp_type; + exp_env = env } + | Pexp_send (e, met) -> + if !Clflags.principal then begin_def (); + let obj = type_exp env e in + begin try + let (exp, typ) = + match obj.exp_desc with + Texp_ident(path, {val_kind = Val_self (meths, _, _, privty)}) -> + let (id, typ) = + filter_self_method env met Private meths privty + in + if (repr typ).desc = Tvar then + Location.prerr_warning sexp.pexp_loc + (Warnings.Undeclared_virtual_method met); + (Texp_send(obj, Tmeth_val id), typ) + | Texp_ident(path, {val_kind = Val_anc (methods, cl_num)}) -> + let method_id = + begin try List.assoc met methods with Not_found -> + raise(Error(e.pexp_loc, Undefined_inherited_method met)) + end + in + begin match + Env.lookup_value (Longident.Lident ("selfpat-" ^ cl_num)) env, + Env.lookup_value (Longident.Lident ("self-" ^cl_num)) env + with + (_, ({val_kind = Val_self (meths, _, _, privty)} as desc)), + (path, _) -> + let (_, typ) = + filter_self_method env met Private meths privty + in + let method_type = newvar () in + let (obj_ty, res_ty) = filter_arrow env method_type "" in + unify env obj_ty desc.val_type; + unify env res_ty (instance typ); + (Texp_apply({ exp_desc = Texp_ident(Path.Pident method_id, + {val_type = method_type; + val_kind = Val_reg}); + exp_loc = sexp.pexp_loc; + exp_type = method_type; + exp_env = env }, + [Some {exp_desc = Texp_ident(path, desc); + exp_loc = obj.exp_loc; + exp_type = desc.val_type; + exp_env = env }, + Required]), + typ) + | _ -> + assert false + end + | _ -> + (Texp_send(obj, Tmeth_name met), + filter_method env met Public obj.exp_type) + in + if !Clflags.principal then begin + end_def (); + generalize_structure typ; + end; + let typ = + match repr typ with + {desc = Tpoly (ty, [])} -> + instance ty + | {desc = Tpoly (ty, tl); level = l} -> + if !Clflags.principal && l <> generic_level then + Location.prerr_warning sexp.pexp_loc + (Warnings.Not_principal "this use of a polymorphic method"); + snd (instance_poly false tl ty) + | {desc = Tvar} as ty -> + let ty' = newvar () in + unify env (instance ty) (newty(Tpoly(ty',[]))); + (* if not !Clflags.nolabels then + Location.prerr_warning loc (Warnings.Unknown_method met); *) + ty' + | _ -> + assert false + in + re { + exp_desc = exp; + exp_loc = sexp.pexp_loc; + exp_type = typ; + exp_env = env } + with Unify _ -> + raise(Error(e.pexp_loc, Undefined_method (obj.exp_type, met))) + end + | Pexp_new cl -> + let (cl_path, cl_decl) = + try Env.lookup_class cl env with Not_found -> + raise(Error(sexp.pexp_loc, Unbound_class cl)) + in + begin match cl_decl.cty_new with + None -> + raise(Error(sexp.pexp_loc, Virtual_class cl)) + | Some ty -> + re { + exp_desc = Texp_new (cl_path, cl_decl); + exp_loc = sexp.pexp_loc; + exp_type = instance ty; + exp_env = env } + end + | Pexp_setinstvar (lab, snewval) -> + begin try + let (path, desc) = Env.lookup_value (Longident.Lident lab) env in + match desc.val_kind with + Val_ivar (Mutable, cl_num) -> + let newval = type_expect env snewval (instance desc.val_type) in + let (path_self, _) = + Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env + in + re { + exp_desc = Texp_setinstvar(path_self, path, newval); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env } + | Val_ivar _ -> + raise(Error(sexp.pexp_loc, Instance_variable_not_mutable lab)) + | _ -> + raise(Error(sexp.pexp_loc, Unbound_instance_variable lab)) + with + Not_found -> + raise(Error(sexp.pexp_loc, Unbound_instance_variable lab)) + end + | Pexp_override lst -> + let _ = + List.fold_right + (fun (lab, _) l -> + if List.exists ((=) lab) l then + raise(Error(sexp.pexp_loc, + Value_multiply_overridden lab)); + lab::l) + lst + [] in + begin match + try + Env.lookup_value (Longident.Lident "selfpat-*") env, + Env.lookup_value (Longident.Lident "self-*") env + with Not_found -> + raise(Error(sexp.pexp_loc, Outside_class)) + with + (_, {val_type = self_ty; val_kind = Val_self (_, vars, _, _)}), + (path_self, _) -> + let type_override (lab, snewval) = + begin try + let (id, _, _, ty) = Vars.find lab !vars in + (Path.Pident id, type_expect env snewval (instance ty)) + with + Not_found -> + raise(Error(sexp.pexp_loc, Unbound_instance_variable lab)) + end + in + let modifs = List.map type_override lst in + re { + exp_desc = Texp_override(path_self, modifs); + exp_loc = sexp.pexp_loc; + exp_type = self_ty; + exp_env = env } + | _ -> + assert false + end + | Pexp_letmodule(name, smodl, sbody) -> + let ty = newvar() in + Ident.set_current_time ty.level; + let context = Typetexp.narrow () in + let modl = !type_module env smodl in + let (id, new_env) = Env.enter_module name modl.mod_type env in + Ctype.init_def(Ident.current_time()); + Typetexp.widen context; + let body = type_exp new_env sbody in + (* Unification of body.exp_type with the fresh variable ty + fails if and only if the prefix condition is violated, + i.e. if generative types rooted at id show up in the + type body.exp_type. Thus, this unification enforces the + scoping condition on "let module". *) + begin try + Ctype.unify new_env body.exp_type ty + with Unify _ -> + raise(Error(sexp.pexp_loc, Scoping_let_module(name, body.exp_type))) + end; + re { + exp_desc = Texp_letmodule(id, modl, body); + exp_loc = sexp.pexp_loc; + exp_type = ty; + exp_env = env } + | Pexp_assert (e) -> + let cond = type_expect env e (instance Predef.type_bool) in + re { + exp_desc = Texp_assert (cond); + exp_loc = sexp.pexp_loc; + exp_type = instance Predef.type_unit; + exp_env = env; + } + | Pexp_assertfalse -> + re { + exp_desc = Texp_assertfalse; + exp_loc = sexp.pexp_loc; + exp_type = newvar (); + exp_env = env; + } + | Pexp_lazy e -> + let arg = type_exp env e in + re { + exp_desc = Texp_lazy arg; + exp_loc = sexp.pexp_loc; + exp_type = instance (Predef.type_lazy_t arg.exp_type); + exp_env = env; + } + | Pexp_object s -> + let desc, sign, meths = !type_object env sexp.pexp_loc s in + re { + exp_desc = Texp_object (desc, sign, meths); + exp_loc = sexp.pexp_loc; + exp_type = sign.cty_self; + exp_env = env; + } + | Pexp_poly _ -> + assert false + +and type_argument env sarg ty_expected' = + (* ty_expected' may be generic *) + let no_labels ty = + let ls, tvar = list_labels env ty in + not tvar && List.for_all ((=) "") ls + in + let ty_expected = instance ty_expected' in + match expand_head env ty_expected', sarg with + | _, {pexp_desc = Pexp_function(l,_,_)} when not (is_optional l) -> + type_expect env sarg ty_expected + | {desc = Tarrow("",ty_arg,ty_res,_); level = lv}, _ -> + (* apply optional arguments when expected type is "" *) + (* we must be very careful about not breaking the semantics *) + if !Clflags.principal then begin_def (); + let texp = type_exp env sarg in + if !Clflags.principal then begin + end_def (); + generalize_structure texp.exp_type + end; + let rec make_args args ty_fun = + match (expand_head env ty_fun).desc with + | Tarrow (l,ty_arg,ty_fun,_) when is_optional l -> + make_args + ((Some(option_none (instance ty_arg) sarg.pexp_loc), Optional) + :: args) + ty_fun + | Tarrow (l,_,ty_res',_) when l = "" || !Clflags.classic -> + args, ty_fun, no_labels ty_res' + | Tvar -> args, ty_fun, false + | _ -> [], texp.exp_type, false + in + let args, ty_fun', simple_res = make_args [] texp.exp_type in + let warn = !Clflags.principal && + (lv <> generic_level || (repr ty_fun').level <> generic_level) + and texp = {texp with exp_type = instance texp.exp_type} + and ty_fun = instance ty_fun' in + if not (simple_res || no_labels ty_res) then begin + unify_exp env texp ty_expected; + texp + end else begin + unify_exp env {texp with exp_type = ty_fun} ty_expected; + if args = [] then texp else + (* eta-expand to avoid side effects *) + let var_pair name ty = + let id = Ident.create name in + {pat_desc = Tpat_var id; pat_type = ty; + pat_loc = Location.none; pat_env = env}, + {exp_type = ty; exp_loc = Location.none; exp_env = env; exp_desc = + Texp_ident(Path.Pident id,{val_type = ty; val_kind = Val_reg})} + in + let eta_pat, eta_var = var_pair "eta" ty_arg in + let func texp = + { texp with exp_type = ty_fun; exp_desc = + Texp_function([eta_pat, {texp with exp_type = ty_res; exp_desc = + Texp_apply (texp, args@ + [Some eta_var, Required])}], + Total) } in + if warn then Location.prerr_warning texp.exp_loc + (Warnings.Without_principality "eliminated optional argument"); + if is_nonexpansive texp then func texp else + (* let-expand to have side effects *) + let let_pat, let_var = var_pair "let" texp.exp_type in + re { texp with exp_type = ty_fun; exp_desc = + Texp_let (Nonrecursive, [let_pat, texp], func let_var) } + end + | _ -> + type_expect env sarg ty_expected + +and type_application env funct sargs = + (* funct.exp_type may be generic *) + let result_type omitted ty_fun = + List.fold_left + (fun ty_fun (l,ty,lv) -> newty2 lv (Tarrow(l,ty,ty_fun,Cok))) + ty_fun omitted + in + let has_label l ty_fun = + let ls, tvar = list_labels env ty_fun in + tvar || List.mem l ls + in + let ignored = ref [] in + let rec type_unknown_args args omitted ty_fun = function + [] -> + (List.map + (function None, x -> None, x | Some f, x -> Some (f ()), x) + (List.rev args), + instance (result_type omitted ty_fun)) + | (l1, sarg1) :: sargl -> + let (ty1, ty2) = + let ty_fun = expand_head env ty_fun in + match ty_fun.desc with + Tvar -> + let t1 = newvar () and t2 = newvar () in + let not_identity = function + Texp_ident(_,{val_kind=Val_prim + {Primitive.prim_name="%identity"}}) -> + false + | _ -> true + in + if ty_fun.level >= t1.level && not_identity funct.exp_desc then + Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument; + unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown)))); + (t1, t2) + | Tarrow (l,t1,t2,_) when l = l1 + || !Clflags.classic && l1 = "" && not (is_optional l) -> + (t1, t2) + | td -> + let ty_fun = + match td with Tarrow _ -> newty td | _ -> ty_fun in + let ty_res = result_type (omitted @ !ignored) ty_fun in + match ty_res.desc with + Tarrow _ -> + if (!Clflags.classic || not (has_label l1 ty_fun)) then + raise(Error(sarg1.pexp_loc, Apply_wrong_label(l1, ty_res))) + else + raise(Error(funct.exp_loc, Incoherent_label_order)) + | _ -> + raise(Error(funct.exp_loc, Apply_non_function + (expand_head env funct.exp_type))) + in + let optional = if is_optional l1 then Optional else Required in + let arg1 () = + let arg1 = type_expect env sarg1 ty1 in + if optional = Optional then + unify_exp env arg1 (type_option(newvar())); + arg1 + in + type_unknown_args ((Some arg1, optional) :: args) omitted ty2 sargl + in + let ignore_labels = + !Clflags.classic || + begin + let ls, tvar = list_labels env funct.exp_type in + not tvar && + let labels = List.filter (fun l -> not (is_optional l)) ls in + List.length labels = List.length sargs && + List.for_all (fun (l,_) -> l = "") sargs && + List.exists (fun l -> l <> "") labels && + (Location.prerr_warning funct.exp_loc Warnings.Labels_omitted; + true) + end + in + let warned = ref false in + let rec type_args args omitted ty_fun ty_old sargs more_sargs = + match expand_head env ty_fun with + {desc=Tarrow (l, ty, ty_fun, com); level=lv} as ty_fun' + when (sargs <> [] || more_sargs <> []) && commu_repr com = Cok -> + let may_warn loc w = + if not !warned && !Clflags.principal && lv <> generic_level + then begin + warned := true; + Location.prerr_warning loc w + end + in + let name = label_name l + and optional = if is_optional l then Optional else Required in + let sargs, more_sargs, arg = + if ignore_labels && not (is_optional l) then begin + (* In classic mode, omitted = [] *) + match sargs, more_sargs with + (l', sarg0) :: _, _ -> + raise(Error(sarg0.pexp_loc, Apply_wrong_label(l', ty_old))) + | _, (l', sarg0) :: more_sargs -> + if l <> l' && l' <> "" then + raise(Error(sarg0.pexp_loc, Apply_wrong_label(l', ty_fun'))) + else + ([], more_sargs, Some (fun () -> type_argument env sarg0 ty)) + | _ -> + assert false + end else try + let (l', sarg0, sargs, more_sargs) = + try + let (l', sarg0, sargs1, sargs2) = extract_label name sargs in + if sargs1 <> [] then + may_warn sarg0.pexp_loc + (Warnings.Not_principal "commuting this argument"); + (l', sarg0, sargs1 @ sargs2, more_sargs) + with Not_found -> + let (l', sarg0, sargs1, sargs2) = + extract_label name more_sargs in + if sargs1 <> [] || sargs <> [] then + may_warn sarg0.pexp_loc + (Warnings.Not_principal "commuting this argument"); + (l', sarg0, sargs @ sargs1, sargs2) + in + sargs, more_sargs, + if optional = Required || is_optional l' then + Some (fun () -> type_argument env sarg0 ty) + else begin + may_warn sarg0.pexp_loc + (Warnings.Not_principal "using an optional argument here"); + Some (fun () -> option_some (type_argument env sarg0 + (extract_option_type env ty))) + end + with Not_found -> + sargs, more_sargs, + if optional = Optional && + (List.mem_assoc "" sargs || List.mem_assoc "" more_sargs) + then begin + may_warn funct.exp_loc + (Warnings.Without_principality "eliminated optional argument"); + ignored := (l,ty,lv) :: !ignored; + Some (fun () -> option_none (instance ty) Location.none) + end else begin + may_warn funct.exp_loc + (Warnings.Without_principality "commuted an argument"); + None + end + in + let omitted = + if arg = None then (l,ty,lv) :: omitted else omitted in + let ty_old = if sargs = [] then ty_fun else ty_old in + type_args ((arg,optional)::args) omitted ty_fun ty_old sargs more_sargs + | _ -> + match sargs with + (l, sarg0) :: _ when ignore_labels -> + raise(Error(sarg0.pexp_loc, Apply_wrong_label(l, ty_old))) + | _ -> + type_unknown_args args omitted (instance ty_fun) + (sargs @ more_sargs) + in + match funct.exp_desc, sargs with + (* Special case for ignore: avoid discarding warning *) + Texp_ident (_, {val_kind=Val_prim{Primitive.prim_name="%ignore"}}), + ["", sarg] -> + let ty_arg, ty_res = filter_arrow env (instance funct.exp_type) "" in + let exp = type_expect env sarg ty_arg in + begin match (expand_head env exp.exp_type).desc with + | Tarrow _ -> + Location.prerr_warning exp.exp_loc Warnings.Partial_application + | Tvar -> + add_delayed_check (fun () -> check_application_result env false exp) + | _ -> () + end; + ([Some exp, Required], ty_res) + | _ -> + let ty = funct.exp_type in + if ignore_labels then + type_args [] [] ty ty [] sargs + else + type_args [] [] ty ty sargs [] + +and type_construct env loc lid sarg explicit_arity ty_expected = + let constr = + try + Env.lookup_constructor lid env + with Not_found -> + raise(Error(loc, Unbound_constructor lid)) in + let sargs = + match sarg with + None -> [] + | Some {pexp_desc = Pexp_tuple sel} when explicit_arity -> sel + | Some {pexp_desc = Pexp_tuple sel} when constr.cstr_arity > 1 -> sel + | Some se -> [se] in + if List.length sargs <> constr.cstr_arity then + raise(Error(loc, Constructor_arity_mismatch + (lid, constr.cstr_arity, List.length sargs))); + if !Clflags.principal then begin_def (); + let (ty_args, ty_res) = instance_constructor constr in + if !Clflags.principal then begin + end_def (); + List.iter generalize_structure ty_args; + generalize_structure ty_res + end; + let texp = + re { + exp_desc = Texp_construct(constr, []); + exp_loc = loc; + exp_type = instance ty_res; + exp_env = env } in + unify_exp env texp ty_expected; + let args = List.map2 (type_argument env) sargs ty_args in + if constr.cstr_private = Private then + raise(Error(loc, Private_type ty_res)); + { texp with exp_desc = Texp_construct(constr, args) } + +(* Typing of an expression with an expected type. + Some constructs are treated specially to provide better error messages. *) + +and type_expect ?in_function env sexp ty_expected = + match sexp.pexp_desc with + Pexp_constant(Const_string s as cst) -> + let exp = + re { + exp_desc = Texp_constant cst; + exp_loc = sexp.pexp_loc; + exp_type = + (* Terrible hack for format strings *) + begin match (repr (expand_head env ty_expected)).desc with + Tconstr(path, _, _) when Path.same path Predef.path_format6 -> + type_format sexp.pexp_loc s + | _ -> instance Predef.type_string + end; + exp_env = env } in + unify_exp env exp ty_expected; + exp + | Pexp_construct(lid, sarg, explicit_arity) -> + type_construct env sexp.pexp_loc lid sarg explicit_arity ty_expected + | Pexp_let(rec_flag, spat_sexp_list, sbody) -> + let (pat_exp_list, new_env) = type_let env rec_flag spat_sexp_list None in + let body = type_expect new_env sbody ty_expected in + re { + exp_desc = Texp_let(rec_flag, pat_exp_list, body); + exp_loc = sexp.pexp_loc; + exp_type = body.exp_type; + exp_env = env } + | Pexp_sequence(sexp1, sexp2) -> + let exp1 = type_statement env sexp1 in + let exp2 = type_expect env sexp2 ty_expected in + re { + exp_desc = Texp_sequence(exp1, exp2); + exp_loc = sexp.pexp_loc; + exp_type = exp2.exp_type; + exp_env = env } + | Pexp_function (l, Some default, [spat, sbody]) -> + let loc = default.pexp_loc in + let scases = + [{ppat_loc = loc; ppat_desc = + Ppat_construct(Longident.Lident"Some", + Some{ppat_loc = loc; ppat_desc = Ppat_var"*sth*"}, + false)}, + {pexp_loc = loc; pexp_desc = Pexp_ident(Longident.Lident"*sth*")}; + {ppat_loc = loc; ppat_desc = + Ppat_construct(Longident.Lident"None", None, false)}, + default] in + let smatch = + {pexp_loc = loc; pexp_desc = + Pexp_match({pexp_loc = loc; pexp_desc = + Pexp_ident(Longident.Lident"*opt*")}, + scases)} in + let sfun = + {pexp_loc = sexp.pexp_loc; pexp_desc = + Pexp_function(l, None,[{ppat_loc = loc; ppat_desc = Ppat_var"*opt*"}, + {pexp_loc = sexp.pexp_loc; pexp_desc = + Pexp_let(Default, [spat, smatch], sbody)}])} + in + type_expect ?in_function env sfun ty_expected + | Pexp_function (l, _, caselist) -> + let (loc, ty_fun) = + match in_function with Some p -> p + | None -> (sexp.pexp_loc, ty_expected) + in + let (ty_arg, ty_res) = + try filter_arrow env ty_expected l + with Unify _ -> + match expand_head env ty_expected with + {desc = Tarrow _} as ty -> + raise(Error(sexp.pexp_loc, Abstract_wrong_label(l, ty))) + | _ -> + raise(Error(loc, + Too_many_arguments (in_function <> None, ty_fun))) + in + let ty_arg = + if is_optional l then + let tv = newvar() in + begin + try unify env ty_arg (type_option tv) + with Unify _ -> assert false + end; + type_option tv + else ty_arg + in + let cases, partial = + type_cases ~in_function:(loc,ty_fun) env ty_arg ty_res + (Some sexp.pexp_loc) caselist in + let not_function ty = + let ls, tvar = list_labels env ty in + ls = [] && not tvar + in + if is_optional l && not_function ty_res then + Location.prerr_warning (fst (List.hd cases)).pat_loc + Warnings.Unerasable_optional_argument; + re { + exp_desc = Texp_function(cases, partial); + exp_loc = sexp.pexp_loc; + exp_type = newty (Tarrow(l, ty_arg, ty_res, Cok)); + exp_env = env } + | Pexp_when(scond, sbody) -> + let cond = type_expect env scond (instance Predef.type_bool) in + let body = type_expect env sbody ty_expected in + re { + exp_desc = Texp_when(cond, body); + exp_loc = sexp.pexp_loc; + exp_type = body.exp_type; + exp_env = env } + | Pexp_poly(sbody, sty) -> + let ty = + match sty with None -> repr ty_expected + | Some sty -> + let ty = Typetexp.transl_simple_type env false sty in + repr ty + in + let set_type ty = + unify_exp env + { exp_desc = Texp_tuple []; exp_loc = sexp.pexp_loc; + exp_type = ty; exp_env = env } ty_expected in + begin + match ty.desc with + Tpoly (ty', []) -> + if sty <> None then set_type ty; + let exp = type_expect env sbody ty' in + re { exp with exp_type = ty } + | Tpoly (ty', tl) -> + if sty <> None then set_type ty; + (* One more level to generalize locally *) + begin_def (); + let vars, ty'' = instance_poly true tl ty' in + let exp = type_expect env sbody ty'' in + end_def (); + check_univars env "method" exp ty_expected vars; + re { exp with exp_type = ty } + | _ -> assert false + end + | _ -> + let exp = type_exp env sexp in + unify_exp env exp ty_expected; + exp + +(* Typing of statements (expressions whose values are discarded) *) + +and type_statement env sexp = + begin_def(); + let exp = type_exp env sexp in + end_def(); + let ty = expand_head env exp.exp_type and tv = newvar() in + begin match ty.desc with + | Tarrow _ -> + Location.prerr_warning sexp.pexp_loc Warnings.Partial_application + | Tconstr (p, _, _) when Path.same p Predef.path_unit -> () + | Tvar when ty.level > tv.level -> + Location.prerr_warning sexp.pexp_loc Warnings.Nonreturning_statement + | Tvar -> + add_delayed_check (fun () -> check_application_result env true exp) + | _ -> + Location.prerr_warning sexp.pexp_loc Warnings.Statement_type + end; + unify_var env tv ty; + exp + +(* Typing of match cases *) + +and type_cases ?in_function env ty_arg ty_res partial_loc caselist = + let ty_arg' = newvar () in + let pattern_force = ref [] in + let pat_env_list = + List.map + (fun (spat, sexp) -> + if !Clflags.principal then begin_def (); + let scope = Some (Annot.Idef sexp.pexp_loc) in + let (pat, ext_env, force) = type_pattern env spat scope in + pattern_force := force @ !pattern_force; + let pat = + if !Clflags.principal then begin + end_def (); + iter_pattern (fun {pat_type=t} -> generalize_structure t) pat; + { pat with pat_type = instance pat.pat_type } + end else pat + in + unify_pat env pat ty_arg'; + (pat, ext_env)) + caselist in + (* Check for polymorphic variants to close *) + let patl = List.map fst pat_env_list in + if List.exists has_variants patl then begin + Parmatch.pressure_variants env patl; + List.iter (iter_pattern finalize_variant) patl + end; + (* `Contaminating' unifications start here *) + List.iter (fun f -> f()) !pattern_force; + begin match pat_env_list with [] -> () + | (pat, _) :: _ -> unify_pat env pat ty_arg + end; + let in_function = if List.length caselist = 1 then in_function else None in + let cases = + List.map2 + (fun (pat, ext_env) (spat, sexp) -> + let exp = type_expect ?in_function ext_env sexp ty_res in + (pat, exp)) + pat_env_list caselist + in + let partial = + match partial_loc with None -> Partial + | Some loc -> Parmatch.check_partial loc cases + in + add_delayed_check (fun () -> Parmatch.check_unused env cases); + cases, partial + +(* Typing of let bindings *) + +and type_let env rec_flag spat_sexp_list scope = + begin_def(); + if !Clflags.principal then begin_def (); + let spatl = List.map (fun (spat, sexp) -> spat) spat_sexp_list in + let (pat_list, new_env, force) = type_pattern_list env spatl scope in + if rec_flag = Recursive then + List.iter2 + (fun pat (_, sexp) -> unify_pat env pat (type_approx env sexp)) + pat_list spat_sexp_list; + let pat_list = + if !Clflags.principal then begin + end_def (); + List.map + (fun pat -> + iter_pattern (fun pat -> generalize_structure pat.pat_type) pat; + {pat with pat_type = instance pat.pat_type}) + pat_list + end else pat_list in + (* Polymoprhic variant processing *) + List.iter + (fun pat -> + if has_variants pat then begin + Parmatch.pressure_variants env [pat]; + iter_pattern finalize_variant pat + end) + pat_list; + (* Only bind pattern variables after generalizing *) + List.iter (fun f -> f()) force; + let exp_env = + match rec_flag with Nonrecursive | Default -> env | Recursive -> new_env in + let exp_list = + List.map2 + (fun (spat, sexp) pat -> type_expect exp_env sexp pat.pat_type) + spat_sexp_list pat_list in + List.iter2 + (fun pat exp -> ignore(Parmatch.check_partial pat.pat_loc [pat, exp])) + pat_list exp_list; + end_def(); + List.iter2 + (fun pat exp -> + if not (is_nonexpansive exp) then + iter_pattern (fun pat -> generalize_expansive env pat.pat_type) pat) + pat_list exp_list; + List.iter + (fun pat -> iter_pattern (fun pat -> generalize pat.pat_type) pat) + pat_list; + (List.combine pat_list exp_list, new_env) + +(* Typing of toplevel bindings *) + +let type_binding env rec_flag spat_sexp_list scope = + Typetexp.reset_type_variables(); + type_let env rec_flag spat_sexp_list scope + +(* Typing of toplevel expressions *) + +let type_expression env sexp = + Typetexp.reset_type_variables(); + begin_def(); + let exp = type_exp env sexp in + end_def(); + if is_nonexpansive exp then generalize exp.exp_type + else generalize_expansive env exp.exp_type; + exp + +(* Error report *) + +open Format +open Printtyp + +let report_error ppf = function + | Unbound_value lid -> + fprintf ppf "Unbound value %a" longident lid + | Unbound_constructor lid -> + fprintf ppf "Unbound constructor %a" longident lid + | Unbound_label lid -> + fprintf ppf "Unbound record field label %a" longident lid + | Polymorphic_label lid -> + fprintf ppf "@[The record field label %a is polymorphic.@ %s@]" + longident lid "You cannot instantiate it in a pattern." + | Constructor_arity_mismatch(lid, expected, provided) -> + fprintf ppf + "@[The constructor %a@ expects %i argument(s),@ \ + but is here applied to %i argument(s)@]" + longident lid expected provided + | Label_mismatch(lid, trace) -> + report_unification_error ppf trace + (function ppf -> + fprintf ppf "The record field label %a@ belongs to the type" + longident lid) + (function ppf -> + fprintf ppf "but is here mixed with labels of type") + | Pattern_type_clash trace -> + report_unification_error ppf trace + (function ppf -> + fprintf ppf "This pattern matches values of type") + (function ppf -> + fprintf ppf "but is here used to match values of type") + | Multiply_bound_variable name -> + fprintf ppf "Variable %s is bound several times in this matching" name + | Orpat_vars id -> + fprintf ppf "Variable %s must occur on both sides of this | pattern" + (Ident.name id) + | Expr_type_clash trace -> + report_unification_error ppf trace + (function ppf -> + fprintf ppf "This expression has type") + (function ppf -> + fprintf ppf "but is here used with type") + | Apply_non_function typ -> + begin match (repr typ).desc with + Tarrow _ -> + fprintf ppf "This function is applied to too many arguments,@ "; + fprintf ppf "maybe you forgot a `;'" + | _ -> + fprintf ppf + "This expression is not a function, it cannot be applied" + end + | Apply_wrong_label (l, ty) -> + let print_label ppf = function + | "" -> fprintf ppf "without label" + | l -> + fprintf ppf "with label %s%s" (if is_optional l then "" else "~") l + in + reset_and_mark_loops ty; + fprintf ppf + "@[<v>@[<2>Expecting function has type@ %a@]@.\ + This argument cannot be applied %a@]" + type_expr ty print_label l + | Label_multiply_defined lid -> + fprintf ppf "The record field label %a is defined several times" + longident lid + | Label_missing labels -> + let print_labels ppf = List.iter (fun lbl -> fprintf ppf "@ %s" lbl) in + fprintf ppf "@[<hov>Some record field labels are undefined:%a@]" + print_labels labels + | Label_not_mutable lid -> + fprintf ppf "The record field label %a is not mutable" longident lid + | Incomplete_format s -> + fprintf ppf "Premature end of format string ``%S''" s + | Bad_conversion (fmt, i, c) -> + fprintf ppf + "Bad conversion %%%c, at char number %d \ + in format string ``%s''" c i fmt + | Undefined_method (ty, me) -> + reset_and_mark_loops ty; + fprintf ppf + "@[<v>@[This expression has type@;<1 2>%a@]@,\ + It has no method %s@]" type_expr ty me + | Undefined_inherited_method me -> + fprintf ppf "This expression has no method %s" me + | Unbound_class cl -> + fprintf ppf "Unbound class %a" longident cl + | Virtual_class cl -> + fprintf ppf "One cannot create instances of the virtual class %a" + longident cl + | Unbound_instance_variable v -> + fprintf ppf "Unbound instance variable %s" v + | Instance_variable_not_mutable v -> + fprintf ppf "The instance variable %s is not mutable" v + | Not_subtype(tr1, tr2) -> + report_subtyping_error ppf tr1 "is not a subtype of type" tr2 + | Outside_class -> + fprintf ppf "This object duplication occurs outside a method definition" + | Value_multiply_overridden v -> + fprintf ppf "The instance variable %s is overridden several times" v + | Coercion_failure (ty, ty', trace, b) -> + report_unification_error ppf trace + (function ppf -> + let ty, ty' = prepare_expansion (ty, ty') in + fprintf ppf + "This expression cannot be coerced to type@;<1 2>%a;@ it has type" + (type_expansion ty) ty') + (function ppf -> + fprintf ppf "but is here used with type"); + if b then + fprintf ppf ".@.@[<hov>%s@ %s@]" + "This simple coercion was not fully general." + "Consider using a double coercion." + | Too_many_arguments (in_function, ty) -> + reset_and_mark_loops ty; + if in_function then begin + fprintf ppf "This function expects too many arguments,@ "; + fprintf ppf "it should have type@ %a" + type_expr ty + end else begin + fprintf ppf "This expression should not be a function,@ "; + fprintf ppf "the expected type is@ %a" + type_expr ty + end + | Abstract_wrong_label (l, ty) -> + let label_mark = function + | "" -> "but its first argument is not labeled" + | l -> sprintf "but its first argument is labeled ~%s" l in + reset_and_mark_loops ty; + fprintf ppf "@[<v>@[<2>This function should have type@ %a@]@,%s@]" + type_expr ty (label_mark l) + | Scoping_let_module(id, ty) -> + reset_and_mark_loops ty; + fprintf ppf + "This `let module' expression has type@ %a@ " type_expr ty; + fprintf ppf + "In this type, the locally bound module name %s escapes its scope" id + | Masked_instance_variable lid -> + fprintf ppf + "The instance variable %a@ \ + cannot be accessed from the definition of another instance variable" + longident lid + | Private_type ty -> + fprintf ppf "Cannot create values of the private type %a" type_expr ty + | Private_label (lid, ty) -> + fprintf ppf "Cannot assign field %a of the private type %a" + longident lid type_expr ty + | Not_a_variant_type lid -> + fprintf ppf "The type %a@ is not a variant type" longident lid + | Incoherent_label_order -> + fprintf ppf "This function is applied to arguments@ "; + fprintf ppf "in an order different from other calls.@ "; + fprintf ppf "This is only allowed when the real type is known." + | Less_general (kind, trace) -> + report_unification_error ppf trace + (fun ppf -> fprintf ppf "This %s has type" kind) + (fun ppf -> fprintf ppf "which is less general than") diff --git a/typing/typecore.mli b/typing/typecore.mli new file mode 100644 index 0000000..8fb90dc --- /dev/null +++ b/typing/typecore.mli @@ -0,0 +1,113 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typecore.mli,v 1.41 2008-01-11 16:13:16 doligez Exp $ *) + +(* Type inference for the core language *) + +open Asttypes +open Types +open Format + +val is_nonexpansive: Typedtree.expression -> bool + +val type_binding: + Env.t -> rec_flag -> + (Parsetree.pattern * Parsetree.expression) list -> + Annot.ident option -> + (Typedtree.pattern * Typedtree.expression) list * Env.t +val type_let: + Env.t -> rec_flag -> + (Parsetree.pattern * Parsetree.expression) list -> + Annot.ident option -> + (Typedtree.pattern * Typedtree.expression) list * Env.t +val type_expression: + Env.t -> Parsetree.expression -> Typedtree.expression +val type_class_arg_pattern: + string -> Env.t -> Env.t -> label -> Parsetree.pattern -> + Typedtree.pattern * (Ident.t * Ident.t * type_expr) list * + Env.t * Env.t +val type_self_pattern: + string -> type_expr -> Env.t -> Env.t -> Env.t -> Parsetree.pattern -> + Typedtree.pattern * + (Ident.t * type_expr) Meths.t ref * + (Ident.t * Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) + Vars.t ref * + Env.t * Env.t * Env.t +val type_expect: + ?in_function:(Location.t * type_expr) -> + Env.t -> Parsetree.expression -> type_expr -> Typedtree.expression +val type_exp: + Env.t -> Parsetree.expression -> Typedtree.expression +val type_approx: + Env.t -> Parsetree.expression -> type_expr +val type_argument: + Env.t -> Parsetree.expression -> type_expr -> Typedtree.expression + +val option_some: Typedtree.expression -> Typedtree.expression +val option_none: type_expr -> Location.t -> Typedtree.expression +val extract_option_type: Env.t -> type_expr -> type_expr +val iter_pattern: (Typedtree.pattern -> unit) -> Typedtree.pattern -> unit +val reset_delayed_checks: unit -> unit +val force_delayed_checks: unit -> unit + +val self_coercion : (Path.t * Location.t list ref) list ref + +type error = + Unbound_value of Longident.t + | Unbound_constructor of Longident.t + | Unbound_label of Longident.t + | Polymorphic_label of Longident.t + | Constructor_arity_mismatch of Longident.t * int * int + | Label_mismatch of Longident.t * (type_expr * type_expr) list + | Pattern_type_clash of (type_expr * type_expr) list + | Multiply_bound_variable of string + | Orpat_vars of Ident.t + | Expr_type_clash of (type_expr * type_expr) list + | Apply_non_function of type_expr + | Apply_wrong_label of label * type_expr + | Label_multiply_defined of Longident.t + | Label_missing of string list + | Label_not_mutable of Longident.t + | Incomplete_format of string + | Bad_conversion of string * int * char + | Undefined_method of type_expr * string + | Undefined_inherited_method of string + | Unbound_class of Longident.t + | Virtual_class of Longident.t + | Private_type of type_expr + | Private_label of Longident.t * type_expr + | Unbound_instance_variable of string + | Instance_variable_not_mutable of string + | Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list + | Outside_class + | Value_multiply_overridden of string + | Coercion_failure of + type_expr * type_expr * (type_expr * type_expr) list * bool + | Too_many_arguments of bool * type_expr + | Abstract_wrong_label of label * type_expr + | Scoping_let_module of string * type_expr + | Masked_instance_variable of Longident.t + | Not_a_variant_type of Longident.t + | Incoherent_label_order + | Less_general of string * (type_expr * type_expr) list + +exception Error of Location.t * error + +val report_error: formatter -> error -> unit + +(* Forward declaration, to be filled in by Typemod.type_module *) +val type_module: (Env.t -> Parsetree.module_expr -> Typedtree.module_expr) ref +(* Forward declaration, to be filled in by Typeclass.class_structure *) +val type_object: + (Env.t -> Location.t -> Parsetree.class_structure -> + Typedtree.class_structure * class_signature * string list) ref diff --git a/typing/typedecl.ml b/typing/typedecl.ml new file mode 100644 index 0000000..8a651ec --- /dev/null +++ b/typing/typedecl.ml @@ -0,0 +1,928 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy and Jerome Vouillon, projet Cristal, INRIA Rocquencourt*) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typedecl.ml,v 1.82 2008-08-07 09:29:22 xleroy Exp $ *) + +(**** Typing of type definitions ****) + +open Misc +open Asttypes +open Parsetree +open Primitive +open Types +open Typedtree +open Typetexp + +type error = + Repeated_parameter + | Duplicate_constructor of string + | Too_many_constructors + | Duplicate_label of string + | Recursive_abbrev of string + | Definition_mismatch of type_expr + | Constraint_failed of type_expr * type_expr + | Unconsistent_constraint of (type_expr * type_expr) list + | Type_clash of (type_expr * type_expr) list + | Parameters_differ of Path.t * type_expr * type_expr + | Null_arity_external + | Missing_native_external + | Unbound_type_var of type_expr * type_declaration + | Unbound_exception of Longident.t + | Not_an_exception of Longident.t + | Bad_variance of int * (bool * bool) * (bool * bool) + | Unavailable_type_constructor of Path.t + | Bad_fixed_type of string + +exception Error of Location.t * error + +(* Enter all declared types in the environment as abstract types *) + +let enter_type env (name, sdecl) id = + let decl = + { type_params = + List.map (fun _ -> Btype.newgenvar ()) sdecl.ptype_params; + type_arity = List.length sdecl.ptype_params; + type_kind = Type_abstract; + type_private = sdecl.ptype_private; + type_manifest = + begin match sdecl.ptype_manifest with None -> None + | Some _ -> Some(Ctype.newvar ()) end; + type_variance = List.map (fun _ -> true, true, true) sdecl.ptype_params; + } + in + Env.add_type id decl env + +let update_type temp_env env id loc = + let path = Path.Pident id in + let decl = Env.find_type path temp_env in + match decl.type_manifest with None -> () + | Some ty -> + let params = List.map (fun _ -> Ctype.newvar ()) decl.type_params in + try Ctype.unify env (Ctype.newconstr path params) ty + with Ctype.Unify trace -> + raise (Error(loc, Type_clash trace)) + +(* Determine if a type is (an abbreviation for) the type "float" *) +(* We use the Ctype.expand_head_opt version of expand_head to get access + to the manifest type of private abbreviations. *) +let is_float env ty = + match Ctype.repr (Ctype.expand_head_opt env ty) with + {desc = Tconstr(p, _, _)} -> Path.same p Predef.path_float + | _ -> false + +(* Determine if a type definition defines a fixed type. (PW) *) +let is_fixed_type sd = + (match sd.ptype_manifest with + | Some { ptyp_desc = + (Ptyp_variant _|Ptyp_object _|Ptyp_class _|Ptyp_alias + ({ptyp_desc = Ptyp_variant _|Ptyp_object _|Ptyp_class _},_)) } -> true + | _ -> false) && + sd.ptype_kind = Ptype_abstract && + sd.ptype_private = Private + +(* Set the row variable in a fixed type *) +let set_fixed_row env loc p decl = + let tm = + match decl.type_manifest with + None -> assert false + | Some t -> Ctype.expand_head env t + in + let rv = + match tm.desc with + Tvariant row -> + let row = Btype.row_repr row in + tm.desc <- Tvariant {row with row_fixed = true}; + if Btype.static_row row then Btype.newgenty Tnil + else row.row_more + | Tobject (ty, _) -> + snd (Ctype.flatten_fields ty) + | _ -> + raise (Error (loc, Bad_fixed_type "is not an object or variant")) + in + if rv.desc <> Tvar then + raise (Error (loc, Bad_fixed_type "has no row variable")); + rv.desc <- Tconstr (p, decl.type_params, ref Mnil) + +(* Translate one type declaration *) + +module StringSet = + Set.Make(struct + type t = string + let compare = compare + end) + +let transl_declaration env (name, sdecl) id = + (* Bind type parameters *) + reset_type_variables(); + Ctype.begin_def (); + let params = + try List.map (enter_type_variable true sdecl.ptype_loc) sdecl.ptype_params + with Already_bound -> + raise(Error(sdecl.ptype_loc, Repeated_parameter)) + in + let cstrs = List.map + (fun (sty, sty', loc) -> + transl_simple_type env false sty, + transl_simple_type env false sty', loc) + sdecl.ptype_cstrs + in + let decl = + { type_params = params; + type_arity = List.length params; + type_kind = + begin match sdecl.ptype_kind with + Ptype_abstract -> Type_abstract + | Ptype_variant cstrs -> + let all_constrs = ref StringSet.empty in + List.iter + (fun (name, args, loc) -> + if StringSet.mem name !all_constrs then + raise(Error(sdecl.ptype_loc, Duplicate_constructor name)); + all_constrs := StringSet.add name !all_constrs) + cstrs; + if List.length (List.filter (fun (_, args, _) -> args <> []) cstrs) + > (Config.max_tag + 1) then + raise(Error(sdecl.ptype_loc, Too_many_constructors)); + Type_variant + (List.map + (fun (name, args, loc) -> + (name, List.map (transl_simple_type env true) args)) + cstrs) + | Ptype_record lbls -> + let all_labels = ref StringSet.empty in + List.iter + (fun (name, mut, arg, loc) -> + if StringSet.mem name !all_labels then + raise(Error(sdecl.ptype_loc, Duplicate_label name)); + all_labels := StringSet.add name !all_labels) + lbls; + let lbls' = + List.map + (fun (name, mut, arg, loc) -> + let ty = transl_simple_type env true arg in + name, mut, match ty.desc with Tpoly(t,[]) -> t | _ -> ty) + lbls in + let rep = + if List.for_all (fun (name, mut, arg) -> is_float env arg) lbls' + then Record_float + else Record_regular in + Type_record(lbls', rep) + end; + type_private = sdecl.ptype_private; + type_manifest = + begin match sdecl.ptype_manifest with + None -> None + | Some sty -> + let no_row = not (is_fixed_type sdecl) in + let ty = + transl_simple_type env no_row sty in + if Ctype.cyclic_abbrev env id ty then + raise(Error(sdecl.ptype_loc, Recursive_abbrev name)); + Some ty + end; + type_variance = List.map (fun _ -> true, true, true) params; + } in + + (* Check constraints *) + List.iter + (fun (ty, ty', loc) -> + try Ctype.unify env ty ty' with Ctype.Unify tr -> + raise(Error(loc, Unconsistent_constraint tr))) + cstrs; + Ctype.end_def (); + if is_fixed_type sdecl then begin + let (p, _) = + try Env.lookup_type (Longident.Lident(Ident.name id ^ "#row")) env + with Not_found -> assert false in + set_fixed_row env sdecl.ptype_loc p decl + end; + (id, decl) + +(* Generalize a type declaration *) + +let generalize_decl decl = + List.iter Ctype.generalize decl.type_params; + begin match decl.type_kind with + Type_abstract -> + () + | Type_variant v -> + List.iter (fun (_, tyl) -> List.iter Ctype.generalize tyl) v + | Type_record(r, rep) -> + List.iter (fun (_, _, ty) -> Ctype.generalize ty) r + end; + begin match decl.type_manifest with + | None -> () + | Some ty -> Ctype.generalize ty + end + +(* Check that all constraints are enforced *) + +module TypeSet = + Set.Make + (struct + type t = type_expr + let compare t1 t2 = t1.id - t2.id + end) + +let rec check_constraints_rec env loc visited ty = + let ty = Ctype.repr ty in + if TypeSet.mem ty !visited then () else begin + visited := TypeSet.add ty !visited; + match ty.desc with + | Tconstr (path, args, _) -> + let args' = List.map (fun _ -> Ctype.newvar ()) args in + let ty' = Ctype.newconstr path args' in + begin try Ctype.enforce_constraints env ty' + with Ctype.Unify _ -> assert false + | Not_found -> raise (Error(loc, Unavailable_type_constructor path)) + end; + if not (Ctype.matches env ty ty') then + raise (Error(loc, Constraint_failed (ty, ty'))); + List.iter (check_constraints_rec env loc visited) args + | Tpoly (ty, tl) -> + let _, ty = Ctype.instance_poly false tl ty in + check_constraints_rec env loc visited ty + | _ -> + Btype.iter_type_expr (check_constraints_rec env loc visited) ty + end + +let check_constraints env (_, sdecl) (_, decl) = + let visited = ref TypeSet.empty in + begin match decl.type_kind with + | Type_abstract -> () + | Type_variant l -> + let rec find_pl = function + Ptype_variant pl -> pl + | Ptype_record _ | Ptype_abstract -> assert false + in + let pl = find_pl sdecl.ptype_kind in + List.iter + (fun (name, tyl) -> + let styl = + try let (_,sty,_) = List.find (fun (n,_,_) -> n = name) pl in sty + with Not_found -> assert false in + List.iter2 + (fun sty ty -> + check_constraints_rec env sty.ptyp_loc visited ty) + styl tyl) + l + | Type_record (l, _) -> + let rec find_pl = function + Ptype_record pl -> pl + | Ptype_variant _ | Ptype_abstract -> assert false + in + let pl = find_pl sdecl.ptype_kind in + let rec get_loc name = function + [] -> assert false + | (name', _, sty, _) :: tl -> + if name = name' then sty.ptyp_loc else get_loc name tl + in + List.iter + (fun (name, _, ty) -> + check_constraints_rec env (get_loc name pl) visited ty) + l + end; + begin match decl.type_manifest with + | None -> () + | Some ty -> + let sty = + match sdecl.ptype_manifest with Some sty -> sty | _ -> assert false + in + check_constraints_rec env sty.ptyp_loc visited ty + end + +(* + If both a variant/record definition and a type equation are given, + need to check that the equation refers to a type of the same kind + with the same constructors and labels. +*) +let check_abbrev env (_, sdecl) (id, decl) = + match decl with + {type_kind = (Type_variant _ | Type_record _); type_manifest = Some ty} -> + begin match (Ctype.repr ty).desc with + Tconstr(path, args, _) -> + begin try + let decl' = Env.find_type path env in + if List.length args = List.length decl.type_params + && Ctype.equal env false args decl.type_params + && Includecore.type_declarations env id + decl' + (Subst.type_declaration (Subst.add_type id path Subst.identity) + decl) + then () + else raise(Error(sdecl.ptype_loc, Definition_mismatch ty)) + with Not_found -> + raise(Error(sdecl.ptype_loc, Unavailable_type_constructor path)) + end + | _ -> raise(Error(sdecl.ptype_loc, Definition_mismatch ty)) + end + | _ -> () + +(* Check for ill-defined abbrevs *) + +let check_recursion env loc path decl to_check = + (* to_check is true for potentially mutually recursive paths. + (path, decl) is the type declaration to be checked. *) + + let visited = ref [] in + + let rec check_regular cpath args prev_exp ty = + let ty = Ctype.repr ty in + if not (List.memq ty !visited) then begin + visited := ty :: !visited; + match ty.desc with + | Tconstr(path', args', _) -> + if Path.same path path' then begin + if not (Ctype.equal env false args args') then + raise (Error(loc, + Parameters_differ(cpath, ty, Ctype.newconstr path args))) + end + (* Attempt to expand a type abbreviation if: + 1- [to_check path'] holds + (otherwise the expansion cannot involve [path]); + 2- we haven't expanded this type constructor before + (otherwise we could loop if [path'] is itself + a non-regular abbreviation). *) + else if to_check path' && not (List.mem path' prev_exp) then begin + try + (* Attempt expansion *) + let (params0, body0) = Env.find_type_expansion path' env in + let (params, body) = + Ctype.instance_parameterized_type params0 body0 in + begin + try List.iter2 (Ctype.unify env) params args' + with Ctype.Unify _ -> + raise (Error(loc, Constraint_failed + (ty, Ctype.newconstr path' params0))); + end; + check_regular path' args (path' :: prev_exp) body + with Not_found -> () + end; + List.iter (check_regular cpath args prev_exp) args' + | Tpoly (ty, tl) -> + let (_, ty) = Ctype.instance_poly false tl ty in + check_regular cpath args prev_exp ty + | _ -> + Btype.iter_type_expr (check_regular cpath args prev_exp) ty + end in + + match decl.type_manifest with + | None -> () + | Some body -> + (* Check that recursion is well-founded *) + begin try + Ctype.correct_abbrev env path decl.type_params body + with Ctype.Recursive_abbrev -> + raise(Error(loc, Recursive_abbrev (Path.name path))) + | Ctype.Unify trace -> raise(Error(loc, Type_clash trace)) + end; + (* Check that recursion is regular *) + if decl.type_params = [] then () else + let (args, body) = + Ctype.instance_parameterized_type decl.type_params body in + check_regular path args [] body + +let check_abbrev_recursion env id_loc_list (id, decl) = + check_recursion env (List.assoc id id_loc_list) (Path.Pident id) decl + (function Path.Pident id -> List.mem_assoc id id_loc_list | _ -> false) + +(* Compute variance *) + +let compute_variance env tvl nega posi cntr ty = + let pvisited = ref TypeSet.empty + and nvisited = ref TypeSet.empty + and cvisited = ref TypeSet.empty in + let rec compute_variance_rec posi nega cntr ty = + let ty = Ctype.repr ty in + if (not posi || TypeSet.mem ty !pvisited) + && (not nega || TypeSet.mem ty !nvisited) + && (not cntr || TypeSet.mem ty !cvisited) then + () + else begin + if posi then pvisited := TypeSet.add ty !pvisited; + if nega then nvisited := TypeSet.add ty !nvisited; + if cntr then cvisited := TypeSet.add ty !cvisited; + let compute_same = compute_variance_rec posi nega cntr in + match ty.desc with + Tarrow (_, ty1, ty2, _) -> + compute_variance_rec nega posi true ty1; + compute_same ty2 + | Ttuple tl -> + List.iter compute_same tl + | Tconstr (path, tl, _) -> + if tl = [] then () else begin + try + let decl = Env.find_type path env in + List.iter2 + (fun ty (co,cn,ct) -> + compute_variance_rec + (posi && co || nega && cn) + (posi && cn || nega && co) + (cntr || ct) + ty) + tl decl.type_variance + with Not_found -> + List.iter (compute_variance_rec true true true) tl + end + | Tobject (ty, _) -> + compute_same ty + | Tfield (_, _, ty1, ty2) -> + compute_same ty1; + compute_same ty2 + | Tsubst ty -> + compute_same ty + | Tvariant row -> + let row = Btype.row_repr row in + List.iter + (fun (_,f) -> + match Btype.row_field_repr f with + Rpresent (Some ty) -> + compute_same ty + | Reither (_, tyl, _, _) -> + List.iter compute_same tyl + | _ -> ()) + row.row_fields; + compute_same row.row_more + | Tpoly (ty, _) -> + compute_same ty + | Tvar | Tnil | Tlink _ | Tunivar -> () + end + in + compute_variance_rec nega posi cntr ty; + List.iter + (fun (ty, covar, convar, ctvar) -> + if TypeSet.mem ty !pvisited then covar := true; + if TypeSet.mem ty !nvisited then convar := true; + if TypeSet.mem ty !cvisited then ctvar := true) + tvl + +let make_variance ty = (ty, ref false, ref false, ref false) +let whole_type decl = + match decl.type_kind with + Type_variant tll -> + Btype.newgenty + (Ttuple (List.map (fun (_, tl) -> Btype.newgenty (Ttuple tl)) tll)) + | Type_record (ftl, _) -> + Btype.newgenty + (Ttuple (List.map (fun (_, _, ty) -> ty) ftl)) + | Type_abstract -> + match decl.type_manifest with + Some ty -> ty + | _ -> Btype.newgenty (Ttuple []) + +let compute_variance_decl env check decl (required, loc) = + if decl.type_kind = Type_abstract && decl.type_manifest = None then + List.map (fun (c, n) -> if c || n then (c, n, n) else (true, true, true)) + required + else + let params = List.map Btype.repr decl.type_params in + let tvl0 = List.map make_variance params in + let fvl = if check then Ctype.free_variables (whole_type decl) else [] in + let fvl = List.filter (fun v -> not (List.memq v params)) fvl in + let tvl1 = List.map make_variance fvl in + let tvl2 = List.map make_variance fvl in + let tvl = tvl0 @ tvl1 in + begin match decl.type_kind with + Type_abstract -> + begin match decl.type_manifest with + None -> assert false + | Some ty -> compute_variance env tvl true false false ty + end + | Type_variant tll -> + List.iter + (fun (_,tl) -> + List.iter (compute_variance env tvl true false false) tl) + tll + | Type_record (ftl, _) -> + List.iter + (fun (_, mut, ty) -> + let cn = (mut = Mutable) in + compute_variance env tvl true cn cn ty) + ftl + end; + let priv = decl.type_private + and required = + List.map (fun (c,n as r) -> if c || n then r else (true,true)) + required + in + List.iter2 + (fun (ty, co, cn, ct) (c, n) -> + if ty.desc <> Tvar || priv = Private then begin + co := c; cn := n; ct := n; + compute_variance env tvl2 c n n ty + end) + tvl0 required; + List.iter2 + (fun (ty, c1, n1, t1) (_, c2, n2, t2) -> + if !c1 && not !c2 || !n1 && not !n2 + (* || !t1 && not !t2 && decl.type_kind = Type_abstract *) + then raise (Error(loc, + if not (!c2 || !n2) then Unbound_type_var (ty, decl) + else Bad_variance (0, (!c1,!n1), (!c2,!n2))))) + tvl1 tvl2; + let pos = ref 0 in + List.map2 + (fun (_, co, cn, ct) (c, n) -> + incr pos; + if !co && not c || !cn && not n + then raise (Error(loc, Bad_variance (!pos, (!co,!cn), (c,n)))); + let ct = if decl.type_kind = Type_abstract then ct else cn in + (!co, !cn, !ct)) + tvl0 required + +let is_sharp id = + let s = Ident.name id in + String.length s > 0 && s.[0] = '#' + +let rec compute_variance_fixpoint env decls required variances = + let new_decls = + List.map2 + (fun (id, decl) variance -> id, {decl with type_variance = variance}) + decls variances + in + let new_env = + List.fold_right (fun (id, decl) env -> Env.add_type id decl env) + new_decls env + in + let new_variances = + List.map2 + (fun (id, decl) -> compute_variance_decl new_env false decl) + new_decls required + in + let new_variances = + List.map2 + (List.map2 (fun (c1,n1,t1) (c2,n2,t2) -> c1||c2, n1||n2, t1||t2)) + new_variances variances in + if new_variances <> variances then + compute_variance_fixpoint env decls required new_variances + else begin + List.iter2 + (fun (id, decl) req -> if not (is_sharp id) then + ignore (compute_variance_decl new_env true decl req)) + new_decls required; + new_decls, new_env + end + +let init_variance (id, decl) = + List.map (fun _ -> (false, false, false)) decl.type_params + +(* for typeclass.ml *) +let compute_variance_decls env cldecls = + let decls, required = + List.fold_right + (fun (obj_id, obj_abbr, cl_abbr, clty, cltydef, required) (decls, req) -> + (obj_id, obj_abbr) :: decls, required :: req) + cldecls ([],[]) + in + let variances = List.map init_variance decls in + let (decls, _) = compute_variance_fixpoint env decls required variances in + List.map2 + (fun (_,decl) (_, _, cl_abbr, clty, cltydef, _) -> + let variance = List.map (fun (c,n,t) -> (c,n)) decl.type_variance in + (decl, {cl_abbr with type_variance = decl.type_variance}, + {clty with cty_variance = variance}, + {cltydef with clty_variance = variance})) + decls cldecls + +(* Force recursion to go through id for private types*) +let name_recursion sdecl id decl = + match decl with + | { type_kind = Type_abstract; + type_manifest = Some ty; + type_private = Private; } when is_fixed_type sdecl -> + let ty = Ctype.repr ty in + let ty' = Btype.newty2 ty.level ty.desc in + if Ctype.deep_occur ty ty' then + let td = Tconstr(Path.Pident id, decl.type_params, ref Mnil) in + Btype.link_type ty (Btype.newty2 ty.level td); + {decl with type_manifest = Some ty'} + else decl + | _ -> decl + +(* Translate a set of mutually recursive type declarations *) +let transl_type_decl env name_sdecl_list = + (* Add dummy types for fixed rows *) + let fixed_types = + List.filter (fun (_, sd) -> is_fixed_type sd) name_sdecl_list + in + let name_sdecl_list = + List.map + (fun (name,sdecl) -> + name^"#row", + {sdecl with ptype_kind = Ptype_abstract; ptype_manifest = None}) + fixed_types + @ name_sdecl_list + in + (* Create identifiers. *) + let id_list = + List.map (fun (name, _) -> Ident.create name) name_sdecl_list + in + (* + Since we've introduced fresh idents, make sure the definition + level is at least the binding time of these events. Otherwise, + passing one of the recursively-defined type constrs as argument + to an abbreviation may fail. + *) + Ctype.init_def(Ident.current_time()); + Ctype.begin_def(); + (* Enter types. *) + let temp_env = List.fold_left2 enter_type env name_sdecl_list id_list in + (* Translate each declaration. *) + let decls = + List.map2 (transl_declaration temp_env) name_sdecl_list id_list in + (* Build the final env. *) + let newenv = + List.fold_right + (fun (id, decl) env -> Env.add_type id decl env) + decls env + in + (* Update stubs *) + List.iter2 + (fun id (_, sdecl) -> update_type temp_env newenv id sdecl.ptype_loc) + id_list name_sdecl_list; + (* Generalize type declarations. *) + Ctype.end_def(); + List.iter (fun (_, decl) -> generalize_decl decl) decls; + (* Check for ill-formed abbrevs *) + let id_loc_list = + List.map2 (fun id (_,sdecl) -> (id, sdecl.ptype_loc)) + id_list name_sdecl_list + in + List.iter (check_abbrev_recursion newenv id_loc_list) decls; + (* Check that all type variable are closed *) + List.iter2 + (fun (_, sdecl) (id, decl) -> + match Ctype.closed_type_decl decl with + Some ty -> raise(Error(sdecl.ptype_loc, Unbound_type_var(ty,decl))) + | None -> ()) + name_sdecl_list decls; + (* Check re-exportation *) + List.iter2 (check_abbrev newenv) name_sdecl_list decls; + (* Check that constraints are enforced *) + List.iter2 (check_constraints newenv) name_sdecl_list decls; + (* Name recursion *) + let decls = + List.map2 (fun (_, sdecl) (id, decl) -> id, name_recursion sdecl id decl) + name_sdecl_list decls + in + (* Add variances to the environment *) + let required = + List.map (fun (_, sdecl) -> sdecl.ptype_variance, sdecl.ptype_loc) + name_sdecl_list + in + let final_decls, final_env = + compute_variance_fixpoint env decls required (List.map init_variance decls) + in + (* Done *) + (final_decls, final_env) + +(* Translate an exception declaration *) +let transl_exception env excdecl = + reset_type_variables(); + Ctype.begin_def(); + let types = List.map (transl_simple_type env true) excdecl in + Ctype.end_def(); + List.iter Ctype.generalize types; + types + +(* Translate an exception rebinding *) +let transl_exn_rebind env loc lid = + let cdescr = + try + Env.lookup_constructor lid env + with Not_found -> + raise(Error(loc, Unbound_exception lid)) in + match cdescr.cstr_tag with + Cstr_exception path -> (path, cdescr.cstr_args) + | _ -> raise(Error(loc, Not_an_exception lid)) + +(* Translate a value declaration *) +let transl_value_decl env valdecl = + let ty = Typetexp.transl_type_scheme env valdecl.pval_type in + match valdecl.pval_prim with + [] -> + { val_type = ty; val_kind = Val_reg } + | decl -> + let arity = Ctype.arity ty in + if arity = 0 then + raise(Error(valdecl.pval_type.ptyp_loc, Null_arity_external)); + let prim = Primitive.parse_declaration arity decl in + if !Clflags.native_code + && prim.prim_arity > 5 + && prim.prim_native_name = "" + then raise(Error(valdecl.pval_type.ptyp_loc, Missing_native_external)); + { val_type = ty; val_kind = Val_prim prim } + +(* Translate a "with" constraint -- much simplified version of + transl_type_decl. *) +let transl_with_constraint env id row_path sdecl = + reset_type_variables(); + Ctype.begin_def(); + let params = + try + List.map (enter_type_variable true sdecl.ptype_loc) sdecl.ptype_params + with Already_bound -> + raise(Error(sdecl.ptype_loc, Repeated_parameter)) in + List.iter + (function (ty, ty', loc) -> + try + Ctype.unify env (transl_simple_type env false ty) + (transl_simple_type env false ty') + with Ctype.Unify tr -> + raise(Error(loc, Unconsistent_constraint tr))) + sdecl.ptype_cstrs; + let no_row = not (is_fixed_type sdecl) in + let decl = + { type_params = params; + type_arity = List.length params; + type_kind = Type_abstract; + type_private = sdecl.ptype_private; + type_manifest = + begin match sdecl.ptype_manifest with + None -> None + | Some sty -> + Some(transl_simple_type env no_row sty) + end; + type_variance = []; + } + in + begin match row_path with None -> () + | Some p -> set_fixed_row env sdecl.ptype_loc p decl + end; + begin match Ctype.closed_type_decl decl with None -> () + | Some ty -> raise(Error(sdecl.ptype_loc, Unbound_type_var(ty,decl))) + end; + let decl = name_recursion sdecl id decl in + let decl = + {decl with type_variance = + compute_variance_decl env false decl + (sdecl.ptype_variance, sdecl.ptype_loc)} in + Ctype.end_def(); + generalize_decl decl; + decl + +(* Approximate a type declaration: just make all types abstract *) + +let abstract_type_decl arity = + let rec make_params n = + if n <= 0 then [] else Ctype.newvar() :: make_params (n-1) in + Ctype.begin_def(); + let decl = + { type_params = make_params arity; + type_arity = arity; + type_kind = Type_abstract; + type_private = Public; + type_manifest = None; + type_variance = replicate_list (true, true, true) arity } in + Ctype.end_def(); + generalize_decl decl; + decl + +let approx_type_decl env name_sdecl_list = + List.map + (fun (name, sdecl) -> + (Ident.create name, + abstract_type_decl (List.length sdecl.ptype_params))) + name_sdecl_list + +(* Variant of check_abbrev_recursion to check the well-formedness + conditions on type abbreviations defined within recursive modules. *) + +let check_recmod_typedecl env loc recmod_ids path decl = + (* recmod_ids is the list of recursively-defined module idents. + (path, decl) is the type declaration to be checked. *) + check_recursion env loc path decl + (fun path -> List.exists (fun id -> Path.isfree id path) recmod_ids) + + +(**** Error report ****) + +open Format + +let report_error ppf = function + | Repeated_parameter -> + fprintf ppf "A type parameter occurs several times" + | Duplicate_constructor s -> + fprintf ppf "Two constructors are named %s" s + | Too_many_constructors -> + fprintf ppf "Too many non-constant constructors -- \ + maximum is %i non-constant constructors" + (Config.max_tag + 1) + | Duplicate_label s -> + fprintf ppf "Two labels are named %s" s + | Recursive_abbrev s -> + fprintf ppf "The type abbreviation %s is cyclic" s + | Definition_mismatch ty -> + Printtyp.reset_and_mark_loops ty; + fprintf ppf + "The variant or record definition does not match that of type@ %a" + Printtyp.type_expr ty + | Constraint_failed (ty, ty') -> + fprintf ppf "Constraints are not satisfied in this type.@."; + Printtyp.reset_and_mark_loops ty; + Printtyp.mark_loops ty'; + fprintf ppf "@[<hv>Type@ %a@ should be an instance of@ %a@]" + Printtyp.type_expr ty Printtyp.type_expr ty' + | Parameters_differ (path, ty, ty') -> + Printtyp.reset_and_mark_loops ty; + Printtyp.mark_loops ty'; + fprintf ppf + "@[<hv>In the definition of %s, type@ %a@ should be@ %a@]" + (Path.name path) Printtyp.type_expr ty Printtyp.type_expr ty' + | Unconsistent_constraint trace -> + fprintf ppf "The type constraints are not consistent.@."; + Printtyp.report_unification_error ppf trace + (fun ppf -> fprintf ppf "Type") + (fun ppf -> fprintf ppf "is not compatible with type") + | Type_clash trace -> + Printtyp.report_unification_error ppf trace + (function ppf -> + fprintf ppf "This type constructor expands to type") + (function ppf -> + fprintf ppf "but is here used with type") + | Null_arity_external -> + fprintf ppf "External identifiers must be functions" + | Missing_native_external -> + fprintf ppf "@[<hv>An external function with more than 5 arguments \ + requires second stub function@ \ + for native-code compilation@]" + | Unbound_type_var (ty, decl) -> + fprintf ppf "A type variable is unbound in this type declaration"; + let ty = Ctype.repr ty in + let explain tl typ kwd lab = + let ti = List.find (fun ti -> Ctype.deep_occur ty (typ ti)) tl in + let ty0 = (* Hack to force aliasing when needed *) + Btype.newgenty (Tobject(ty, ref None)) in + Printtyp.reset_and_mark_loops_list [typ ti; ty0]; + fprintf ppf + ".@.@[<hov2>In %s@ %s%a@;<1 -2>the variable %a is unbound@]" + kwd (lab ti) Printtyp.type_expr (typ ti) Printtyp.type_expr ty + in + begin try match decl.type_kind, decl.type_manifest with + Type_variant tl, _ -> + explain tl (fun (_,tl) -> Btype.newgenty (Ttuple tl)) + "case" (fun (lab,_) -> lab ^ " of ") + | Type_record (tl, _), _ -> + explain tl (fun (_,_,t) -> t) + "field" (fun (lab,_,_) -> lab ^ ": ") + | Type_abstract, Some ty' -> + let trivial ty = + explain [ty] (fun t -> t) "definition" (fun _ -> "") in + begin match (Ctype.repr ty').desc with + Tobject(fi,_) -> + let (tl, rv) = Ctype.flatten_fields fi in + if rv == ty then trivial ty' else + explain tl (fun (_,_,t) -> t) + "method" (fun (lab,_,_) -> lab ^ ": ") + | Tvariant row -> + let row = Btype.row_repr row in + if row.row_more == ty then trivial ty' else + explain row.row_fields + (fun (l,f) -> match Btype.row_field_repr f with + Rpresent (Some t) -> t + | Reither (_,[t],_,_) -> t + | Reither (_,tl,_,_) -> Btype.newgenty (Ttuple tl) + | _ -> Btype.newgenty (Ttuple[])) + "case" (fun (lab,_) -> "`" ^ lab ^ " of ") + | _ -> trivial ty' + end + | _ -> () + with Not_found -> () + end + | Unbound_exception lid -> + fprintf ppf "Unbound exception constructor@ %a" Printtyp.longident lid + | Not_an_exception lid -> + fprintf ppf "The constructor@ %a@ is not an exception" + Printtyp.longident lid + | Bad_variance (n, v1, v2) -> + let variance = function + (true, true) -> "invariant" + | (true, false) -> "covariant" + | (false,true) -> "contravariant" + | (false,false) -> "unrestricted" + in + if n < 1 then + fprintf ppf "%s@ %s@ %s" + "In this definition, a type variable" + "has a variance that is not reflected" + "by its occurence in type parameters." + else + fprintf ppf "%s@ %s@ %s %d%s %s %s,@ %s %s" + "In this definition, expected parameter" + "variances are not satisfied." + "The" n (match n with 1 -> "st" | 2 -> "nd" | 3 -> "rd" | _ -> "th") + "type parameter was expected to be" (variance v2) + "but it is" (variance v1) + | Unavailable_type_constructor p -> + fprintf ppf "The definition of type %a@ is unavailable" Printtyp.path p + | Bad_fixed_type r -> + fprintf ppf "This fixed type %s" r diff --git a/typing/typedecl.mli b/typing/typedecl.mli new file mode 100644 index 0000000..316b5f0 --- /dev/null +++ b/typing/typedecl.mli @@ -0,0 +1,76 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typedecl.mli,v 1.31 2007-10-09 10:29:37 weis Exp $ *) + +(* Typing of type definitions and primitive definitions *) + +open Types +open Format + +val transl_type_decl: + Env.t -> (string * Parsetree.type_declaration) list -> + (Ident.t * type_declaration) list * Env.t +val transl_exception: + Env.t -> Parsetree.exception_declaration -> exception_declaration + +val transl_exn_rebind: + Env.t -> Location.t -> Longident.t -> Path.t * exception_declaration + +val transl_value_decl: + Env.t -> Parsetree.value_description -> value_description + +val transl_with_constraint: + Env.t -> Ident.t -> Path.t option -> + Parsetree.type_declaration -> type_declaration + +val abstract_type_decl: int -> type_declaration +val approx_type_decl: + Env.t -> (string * Parsetree.type_declaration) list -> + (Ident.t * type_declaration) list +val check_recmod_typedecl: + Env.t -> Location.t -> Ident.t list -> Path.t -> type_declaration -> unit + +(* for fixed types *) +val is_fixed_type : Parsetree.type_declaration -> bool + +(* for typeclass.ml *) +val compute_variance_decls: + Env.t -> + (Ident.t * type_declaration * type_declaration * class_declaration * + cltype_declaration * ((bool * bool) list * Location.t)) list -> + (type_declaration * type_declaration * class_declaration * + cltype_declaration) list + +type error = + Repeated_parameter + | Duplicate_constructor of string + | Too_many_constructors + | Duplicate_label of string + | Recursive_abbrev of string + | Definition_mismatch of type_expr + | Constraint_failed of type_expr * type_expr + | Unconsistent_constraint of (type_expr * type_expr) list + | Type_clash of (type_expr * type_expr) list + | Parameters_differ of Path.t * type_expr * type_expr + | Null_arity_external + | Missing_native_external + | Unbound_type_var of type_expr * type_declaration + | Unbound_exception of Longident.t + | Not_an_exception of Longident.t + | Bad_variance of int * (bool*bool) * (bool*bool) + | Unavailable_type_constructor of Path.t + | Bad_fixed_type of string + +exception Error of Location.t * error + +val report_error: formatter -> error -> unit diff --git a/typing/typedtree.ml b/typing/typedtree.ml new file mode 100644 index 0000000..60a78b4 --- /dev/null +++ b/typing/typedtree.ml @@ -0,0 +1,232 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typedtree.ml,v 1.39 2008-07-09 13:03:38 mauny Exp $ *) + +(* Abstract syntax tree after typing *) + +open Misc +open Asttypes +open Types + +(* Value expressions for the core language *) + +type pattern = + { pat_desc: pattern_desc; + pat_loc: Location.t; + pat_type: type_expr; + pat_env: Env.t } + +and pattern_desc = + Tpat_any + | Tpat_var of Ident.t + | Tpat_alias of pattern * Ident.t + | Tpat_constant of constant + | Tpat_tuple of pattern list + | Tpat_construct of constructor_description * pattern list + | Tpat_variant of label * pattern option * row_desc ref + | Tpat_record of (label_description * pattern) list + | Tpat_array of pattern list + | Tpat_or of pattern * pattern * row_desc option + | Tpat_lazy of pattern + +type partial = Partial | Total +type optional = Required | Optional + +type expression = + { exp_desc: expression_desc; + exp_loc: Location.t; + exp_type: type_expr; + exp_env: Env.t } + +and expression_desc = + Texp_ident of Path.t * value_description + | Texp_constant of constant + | Texp_let of rec_flag * (pattern * expression) list * expression + | Texp_function of (pattern * expression) list * partial + | Texp_apply of expression * (expression option * optional) list + | Texp_match of expression * (pattern * expression) list * partial + | Texp_try of expression * (pattern * expression) list + | Texp_tuple of expression list + | Texp_construct of constructor_description * expression list + | Texp_variant of label * expression option + | Texp_record of (label_description * expression) list * expression option + | Texp_field of expression * label_description + | Texp_setfield of expression * label_description * expression + | Texp_array of expression list + | Texp_ifthenelse of expression * expression * expression option + | Texp_sequence of expression * expression + | Texp_while of expression * expression + | Texp_for of + Ident.t * expression * expression * direction_flag * expression + | Texp_when of expression * expression + | Texp_send of expression * meth + | Texp_new of Path.t * class_declaration + | Texp_instvar of Path.t * Path.t + | Texp_setinstvar of Path.t * Path.t * expression + | Texp_override of Path.t * (Path.t * expression) list + | Texp_letmodule of Ident.t * module_expr * expression + | Texp_assert of expression + | Texp_assertfalse + | Texp_lazy of expression + | Texp_object of class_structure * class_signature * string list + +and meth = + Tmeth_name of string + | Tmeth_val of Ident.t + +(* Value expressions for the class language *) + +and class_expr = + { cl_desc: class_expr_desc; + cl_loc: Location.t; + cl_type: class_type; + cl_env: Env.t } + +and class_expr_desc = + Tclass_ident of Path.t + | Tclass_structure of class_structure + | Tclass_fun of pattern * (Ident.t * expression) list * class_expr * partial + | Tclass_apply of class_expr * (expression option * optional) list + | Tclass_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list * class_expr + | Tclass_constraint of class_expr * string list * string list * Concr.t + +and class_structure = + { cl_field: class_field list; + cl_meths: Ident.t Meths.t } + +and class_field = + Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list + | Cf_val of string * Ident.t * expression option * bool + | Cf_meth of string * expression + | Cf_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list + | Cf_init of expression + +(* Value expressions for the module language *) + +and module_expr = + { mod_desc: module_expr_desc; + mod_loc: Location.t; + mod_type: module_type; + mod_env: Env.t } + +and module_expr_desc = + Tmod_ident of Path.t + | Tmod_structure of structure + | Tmod_functor of Ident.t * module_type * module_expr + | Tmod_apply of module_expr * module_expr * module_coercion + | Tmod_constraint of module_expr * module_type * module_coercion + +and structure = structure_item list + +and structure_item = + Tstr_eval of expression + | Tstr_value of rec_flag * (pattern * expression) list + | Tstr_primitive of Ident.t * value_description + | Tstr_type of (Ident.t * type_declaration) list + | Tstr_exception of Ident.t * exception_declaration + | Tstr_exn_rebind of Ident.t * Path.t + | Tstr_module of Ident.t * module_expr + | Tstr_recmodule of (Ident.t * module_expr) list + | Tstr_modtype of Ident.t * module_type + | Tstr_open of Path.t + | Tstr_class of + (Ident.t * int * string list * class_expr * virtual_flag) list + | Tstr_cltype of (Ident.t * cltype_declaration) list + | Tstr_include of module_expr * Ident.t list + +and module_coercion = + Tcoerce_none + | Tcoerce_structure of (int * module_coercion) list + | Tcoerce_functor of module_coercion * module_coercion + | Tcoerce_primitive of Primitive.description + +(* Auxiliary functions over the a.s.t. *) + +let iter_pattern_desc f = function + | Tpat_alias(p, id) -> f p + | Tpat_tuple patl -> List.iter f patl + | Tpat_construct(cstr, patl) -> List.iter f patl + | Tpat_variant(_, pat, _) -> may f pat + | Tpat_record lbl_pat_list -> + List.iter (fun (lbl, pat) -> f pat) lbl_pat_list + | Tpat_array patl -> List.iter f patl + | Tpat_or(p1, p2, _) -> f p1; f p2 + | Tpat_lazy p -> f p + | Tpat_any + | Tpat_var _ + | Tpat_constant _ -> () + +let map_pattern_desc f d = + match d with + | Tpat_alias (p1, id) -> + Tpat_alias (f p1, id) + | Tpat_tuple pats -> + Tpat_tuple (List.map f pats) + | Tpat_record lpats -> + Tpat_record (List.map (fun (l,p) -> l, f p) lpats) + | Tpat_construct (c,pats) -> + Tpat_construct (c, List.map f pats) + | Tpat_array pats -> + Tpat_array (List.map f pats) + | Tpat_lazy p1 -> Tpat_lazy (f p1) + | Tpat_variant (x1, Some p1, x2) -> + Tpat_variant (x1, Some (f p1), x2) + | Tpat_or (p1,p2,path) -> + Tpat_or (f p1, f p2, path) + | Tpat_var _ + | Tpat_constant _ + | Tpat_any + | Tpat_variant (_,None,_) -> d + +(* List the identifiers bound by a pattern or a let *) + +let idents = ref([]: Ident.t list) + +let rec bound_idents pat = + match pat.pat_desc with + | Tpat_var id -> idents := id :: !idents + | Tpat_alias(p, id) -> bound_idents p; idents := id :: !idents + | Tpat_or(p1, _, _) -> + (* Invariant : both arguments binds the same variables *) + bound_idents p1 + | d -> iter_pattern_desc bound_idents d + +let pat_bound_idents pat = + idents := []; bound_idents pat; let res = !idents in idents := []; res + +let rev_let_bound_idents pat_expr_list = + idents := []; + List.iter (fun (pat, expr) -> bound_idents pat) pat_expr_list; + let res = !idents in idents := []; res + +let let_bound_idents pat_expr_list = + List.rev(rev_let_bound_idents pat_expr_list) + +let alpha_var env id = List.assoc id env + +let rec alpha_pat env p = match p.pat_desc with +| Tpat_var id -> (* note the ``Not_found'' case *) + {p with pat_desc = + try Tpat_var (alpha_var env id) with + | Not_found -> Tpat_any} +| Tpat_alias (p1, id) -> + let new_p = alpha_pat env p1 in + begin try + {p with pat_desc = Tpat_alias (new_p, alpha_var env id)} + with + | Not_found -> new_p + end +| d -> + {p with pat_desc = map_pattern_desc (alpha_pat env) d} diff --git a/typing/typedtree.mli b/typing/typedtree.mli new file mode 100644 index 0000000..384777e --- /dev/null +++ b/typing/typedtree.mli @@ -0,0 +1,167 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typedtree.mli,v 1.37 2008-07-09 13:03:38 mauny Exp $ *) + +(* Abstract syntax tree after typing *) + +open Asttypes +open Types + +(* Value expressions for the core language *) + +type pattern = + { pat_desc: pattern_desc; + pat_loc: Location.t; + pat_type: type_expr; + pat_env: Env.t } + +and pattern_desc = + Tpat_any + | Tpat_var of Ident.t + | Tpat_alias of pattern * Ident.t + | Tpat_constant of constant + | Tpat_tuple of pattern list + | Tpat_construct of constructor_description * pattern list + | Tpat_variant of label * pattern option * row_desc ref + | Tpat_record of (label_description * pattern) list + | Tpat_array of pattern list + | Tpat_or of pattern * pattern * row_desc option + | Tpat_lazy of pattern + +type partial = Partial | Total +type optional = Required | Optional + +type expression = + { exp_desc: expression_desc; + exp_loc: Location.t; + exp_type: type_expr; + exp_env: Env.t } + +and expression_desc = + Texp_ident of Path.t * value_description + | Texp_constant of constant + | Texp_let of rec_flag * (pattern * expression) list * expression + | Texp_function of (pattern * expression) list * partial + | Texp_apply of expression * (expression option * optional) list + | Texp_match of expression * (pattern * expression) list * partial + | Texp_try of expression * (pattern * expression) list + | Texp_tuple of expression list + | Texp_construct of constructor_description * expression list + | Texp_variant of label * expression option + | Texp_record of (label_description * expression) list * expression option + | Texp_field of expression * label_description + | Texp_setfield of expression * label_description * expression + | Texp_array of expression list + | Texp_ifthenelse of expression * expression * expression option + | Texp_sequence of expression * expression + | Texp_while of expression * expression + | Texp_for of + Ident.t * expression * expression * direction_flag * expression + | Texp_when of expression * expression + | Texp_send of expression * meth + | Texp_new of Path.t * class_declaration + | Texp_instvar of Path.t * Path.t + | Texp_setinstvar of Path.t * Path.t * expression + | Texp_override of Path.t * (Path.t * expression) list + | Texp_letmodule of Ident.t * module_expr * expression + | Texp_assert of expression + | Texp_assertfalse + | Texp_lazy of expression + | Texp_object of class_structure * class_signature * string list + +and meth = + Tmeth_name of string + | Tmeth_val of Ident.t + +(* Value expressions for the class language *) + +and class_expr = + { cl_desc: class_expr_desc; + cl_loc: Location.t; + cl_type: class_type; + cl_env: Env.t } + +and class_expr_desc = + Tclass_ident of Path.t + | Tclass_structure of class_structure + | Tclass_fun of pattern * (Ident.t * expression) list * class_expr * partial + | Tclass_apply of class_expr * (expression option * optional) list + | Tclass_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list * class_expr + | Tclass_constraint of class_expr * string list * string list * Concr.t + (* Visible instance variables, methods and concretes methods *) + +and class_structure = + { cl_field: class_field list; + cl_meths: Ident.t Meths.t } + +and class_field = + Cf_inher of class_expr * (string * Ident.t) list * (string * Ident.t) list + (* Inherited instance variables and concrete methods *) + | Cf_val of string * Ident.t * expression option * bool + (* None = virtual, true = override *) + | Cf_meth of string * expression + | Cf_let of rec_flag * (pattern * expression) list * + (Ident.t * expression) list + | Cf_init of expression + +(* Value expressions for the module language *) + +and module_expr = + { mod_desc: module_expr_desc; + mod_loc: Location.t; + mod_type: module_type; + mod_env: Env.t } + +and module_expr_desc = + Tmod_ident of Path.t + | Tmod_structure of structure + | Tmod_functor of Ident.t * module_type * module_expr + | Tmod_apply of module_expr * module_expr * module_coercion + | Tmod_constraint of module_expr * module_type * module_coercion + +and structure = structure_item list + +and structure_item = + Tstr_eval of expression + | Tstr_value of rec_flag * (pattern * expression) list + | Tstr_primitive of Ident.t * value_description + | Tstr_type of (Ident.t * type_declaration) list + | Tstr_exception of Ident.t * exception_declaration + | Tstr_exn_rebind of Ident.t * Path.t + | Tstr_module of Ident.t * module_expr + | Tstr_recmodule of (Ident.t * module_expr) list + | Tstr_modtype of Ident.t * module_type + | Tstr_open of Path.t + | Tstr_class of + (Ident.t * int * string list * class_expr * virtual_flag) list + | Tstr_cltype of (Ident.t * cltype_declaration) list + | Tstr_include of module_expr * Ident.t list + +and module_coercion = + Tcoerce_none + | Tcoerce_structure of (int * module_coercion) list + | Tcoerce_functor of module_coercion * module_coercion + | Tcoerce_primitive of Primitive.description + +(* Auxiliary functions over the a.s.t. *) + +val iter_pattern_desc : (pattern -> unit) -> pattern_desc -> unit +val map_pattern_desc : (pattern -> pattern) -> pattern_desc -> pattern_desc + +val let_bound_idents: (pattern * expression) list -> Ident.t list +val rev_let_bound_idents: (pattern * expression) list -> Ident.t list + +(* Alpha conversion of patterns *) +val alpha_pat : (Ident.t * Ident.t) list -> pattern -> pattern + diff --git a/typing/typemod.ml b/typing/typemod.ml new file mode 100644 index 0000000..9929173 --- /dev/null +++ b/typing/typemod.ml @@ -0,0 +1,1007 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typemod.ml,v 1.88 2008-12-03 18:09:09 doligez Exp $ *) + +(* Type-checking of the module language *) + +open Misc +open Longident +open Path +open Asttypes +open Parsetree +open Types +open Typedtree +open Format + +type error = + Unbound_module of Longident.t + | Unbound_modtype of Longident.t + | Cannot_apply of module_type + | Not_included of Includemod.error list + | Cannot_eliminate_dependency of module_type + | Signature_expected + | Structure_expected of module_type + | With_no_component of Longident.t + | With_mismatch of Longident.t * Includemod.error list + | Repeated_name of string * string + | Non_generalizable of type_expr + | Non_generalizable_class of Ident.t * class_declaration + | Non_generalizable_module of module_type + | Implementation_is_required of string + | Interface_not_compiled of string + +exception Error of Location.t * error + +(* Extract a signature from a module type *) + +let extract_sig env loc mty = + match Mtype.scrape env mty with + Tmty_signature sg -> sg + | _ -> raise(Error(loc, Signature_expected)) + +let extract_sig_open env loc mty = + match Mtype.scrape env mty with + Tmty_signature sg -> sg + | _ -> raise(Error(loc, Structure_expected mty)) + +(* Lookup the type of a module path *) + +let type_module_path env loc lid = + try + Env.lookup_module lid env + with Not_found -> + raise(Error(loc, Unbound_module lid)) + +(* Record a module type *) +let rm node = + Stypes.record (Stypes.Ti_mod node); + node + +(* Merge one "with" constraint in a signature *) + +let rec add_rec_types env = function + Tsig_type(id, decl, Trec_next) :: rem -> + add_rec_types (Env.add_type id decl env) rem + | _ -> env + +let check_type_decl env id row_id newdecl decl rs rem = + let env = Env.add_type id newdecl env in + let env = + match row_id with None -> env | Some id -> Env.add_type id newdecl env in + let env = if rs = Trec_not then env else add_rec_types env rem in + Includemod.type_declarations env id newdecl decl + +let merge_constraint initial_env loc sg lid constr = + let rec merge env sg namelist row_id = + match (sg, namelist, constr) with + ([], _, _) -> + raise(Error(loc, With_no_component lid)) + | (Tsig_type(id, decl, rs) :: rem, [s], + Pwith_type ({ptype_kind = Ptype_abstract} as sdecl)) + when Ident.name id = s && Typedecl.is_fixed_type sdecl -> + let decl_row = + { type_params = + List.map (fun _ -> Btype.newgenvar()) sdecl.ptype_params; + type_arity = List.length sdecl.ptype_params; + type_kind = Type_abstract; + type_private = Private; + type_manifest = None; + type_variance = + List.map (fun (c,n) -> (not n, not c, not c)) + sdecl.ptype_variance } + and id_row = Ident.create (s^"#row") in + let initial_env = Env.add_type id_row decl_row initial_env in + let newdecl = Typedecl.transl_with_constraint + initial_env id (Some(Pident id_row)) sdecl in + check_type_decl env id row_id newdecl decl rs rem; + let decl_row = {decl_row with type_params = newdecl.type_params} in + let rs' = if rs = Trec_first then Trec_not else rs in + Tsig_type(id_row, decl_row, rs') :: Tsig_type(id, newdecl, rs) :: rem + | (Tsig_type(id, decl, rs) :: rem, [s], Pwith_type sdecl) + when Ident.name id = s -> + let newdecl = + Typedecl.transl_with_constraint initial_env id None sdecl in + check_type_decl env id row_id newdecl decl rs rem; + Tsig_type(id, newdecl, rs) :: rem + | (Tsig_type(id, decl, rs) :: rem, [s], Pwith_type sdecl) + when Ident.name id = s ^ "#row" -> + merge env rem namelist (Some id) + | (Tsig_module(id, mty, rs) :: rem, [s], Pwith_module lid) + when Ident.name id = s -> + let (path, mty') = type_module_path initial_env loc lid in + let newmty = Mtype.strengthen env mty' path in + ignore(Includemod.modtypes env newmty mty); + Tsig_module(id, newmty, rs) :: rem + | (Tsig_module(id, mty, rs) :: rem, s :: namelist, _) + when Ident.name id = s -> + let newsg = merge env (extract_sig env loc mty) namelist None in + Tsig_module(id, Tmty_signature newsg, rs) :: rem + | (item :: rem, _, _) -> + item :: merge (Env.add_item item env) rem namelist row_id in + try + merge initial_env sg (Longident.flatten lid) None + with Includemod.Error explanation -> + raise(Error(loc, With_mismatch(lid, explanation))) + +(* Add recursion flags on declarations arising from a mutually recursive + block. *) + +let map_rec fn decls rem = + match decls with + | [] -> rem + | d1 :: dl -> fn Trec_first d1 :: map_end (fn Trec_next) dl rem + +let rec map_rec' fn decls rem = + match decls with + | (id,_ as d1) :: dl when Btype.is_row_name (Ident.name id) -> + fn Trec_not d1 :: map_rec' fn dl rem + | _ -> map_rec fn decls rem + +(* Auxiliary for translating recursively-defined module types. + Return a module type that approximates the shape of the given module + type AST. Retain only module, type, and module type + components of signatures. For types, retain only their arity, + making them abstract otherwise. *) + +let rec approx_modtype env smty = + match smty.pmty_desc with + Pmty_ident lid -> + begin try + let (path, info) = Env.lookup_modtype lid env in + Tmty_ident path + with Not_found -> + raise(Error(smty.pmty_loc, Unbound_modtype lid)) + end + | Pmty_signature ssg -> + Tmty_signature(approx_sig env ssg) + | Pmty_functor(param, sarg, sres) -> + let arg = approx_modtype env sarg in + let (id, newenv) = Env.enter_module param arg env in + let res = approx_modtype newenv sres in + Tmty_functor(id, arg, res) + | Pmty_with(sbody, constraints) -> + approx_modtype env sbody + +and approx_sig env ssg = + match ssg with + [] -> [] + | item :: srem -> + match item.psig_desc with + | Psig_type sdecls -> + let decls = Typedecl.approx_type_decl env sdecls in + let rem = approx_sig env srem in + map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem + | Psig_module(name, smty) -> + let mty = approx_modtype env smty in + let (id, newenv) = Env.enter_module name mty env in + Tsig_module(id, mty, Trec_not) :: approx_sig newenv srem + | Psig_recmodule sdecls -> + let decls = + List.map + (fun (name, smty) -> + (Ident.create name, approx_modtype env smty)) + sdecls in + let newenv = + List.fold_left (fun env (id, mty) -> Env.add_module id mty env) + env decls in + map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls + (approx_sig newenv srem) + | Psig_modtype(name, sinfo) -> + let info = approx_modtype_info env sinfo in + let (id, newenv) = Env.enter_modtype name info env in + Tsig_modtype(id, info) :: approx_sig newenv srem + | Psig_open lid -> + let (path, mty) = type_module_path env item.psig_loc lid in + let sg = extract_sig_open env item.psig_loc mty in + let newenv = Env.open_signature path sg env in + approx_sig newenv srem + | Psig_include smty -> + let mty = approx_modtype env smty in + let sg = Subst.signature Subst.identity + (extract_sig env smty.pmty_loc mty) in + let newenv = Env.add_signature sg env in + sg @ approx_sig newenv srem + | Psig_class sdecls | Psig_class_type sdecls -> + let decls = Typeclass.approx_class_declarations env sdecls in + let rem = approx_sig env srem in + List.flatten + (map_rec + (fun rs (i1, d1, i2, d2, i3, d3) -> + [Tsig_cltype(i1, d1, rs); + Tsig_type(i2, d2, rs); + Tsig_type(i3, d3, rs)]) + decls [rem]) + | _ -> + approx_sig env srem + +and approx_modtype_info env sinfo = + match sinfo with + Pmodtype_abstract -> + Tmodtype_abstract + | Pmodtype_manifest smty -> + Tmodtype_manifest(approx_modtype env smty) + +(* Additional validity checks on type definitions arising from + recursive modules *) + +let check_recmod_typedecls env sdecls decls = + let recmod_ids = List.map fst decls in + List.iter2 + (fun (_, smty) (id, mty) -> + List.iter + (fun path -> + Typedecl.check_recmod_typedecl env smty.pmty_loc recmod_ids + path (Env.find_type path env)) + (Mtype.type_paths env (Pident id) mty)) + sdecls decls + +(* Auxiliaries for checking uniqueness of names in signatures and structures *) + +module StringSet = Set.Make(struct type t = string let compare = compare end) + +let check cl loc set_ref name = + if StringSet.mem name !set_ref + then raise(Error(loc, Repeated_name(cl, name))) + else set_ref := StringSet.add name !set_ref + +let check_sig_item type_names module_names modtype_names loc = function + Tsig_type(id, _, _) -> + check "type" loc type_names (Ident.name id) + | Tsig_module(id, _, _) -> + check "module" loc module_names (Ident.name id) + | Tsig_modtype(id, _) -> + check "module type" loc modtype_names (Ident.name id) + | _ -> () + +(* Check and translate a module type expression *) + +let rec transl_modtype env smty = + match smty.pmty_desc with + Pmty_ident lid -> + begin try + let (path, info) = Env.lookup_modtype lid env in + Tmty_ident path + with Not_found -> + raise(Error(smty.pmty_loc, Unbound_modtype lid)) + end + | Pmty_signature ssg -> + Tmty_signature(transl_signature env ssg) + | Pmty_functor(param, sarg, sres) -> + let arg = transl_modtype env sarg in + let (id, newenv) = Env.enter_module param arg env in + let res = transl_modtype newenv sres in + Tmty_functor(id, arg, res) + | Pmty_with(sbody, constraints) -> + let body = transl_modtype env sbody in + let init_sg = extract_sig env sbody.pmty_loc body in + let final_sg = + List.fold_left + (fun sg (lid, sdecl) -> + merge_constraint env smty.pmty_loc sg lid sdecl) + init_sg constraints in + Mtype.freshen (Tmty_signature final_sg) + +and transl_signature env sg = + let type_names = ref StringSet.empty + and module_names = ref StringSet.empty + and modtype_names = ref StringSet.empty in + let rec transl_sig env sg = + Ctype.init_def(Ident.current_time()); + match sg with + [] -> [] + | item :: srem -> + match item.psig_desc with + | Psig_value(name, sdesc) -> + let desc = Typedecl.transl_value_decl env sdesc in + let (id, newenv) = Env.enter_value name desc env in + let rem = transl_sig newenv srem in + Tsig_value(id, desc) :: rem + | Psig_type sdecls -> + List.iter + (fun (name, decl) -> check "type" item.psig_loc type_names name) + sdecls; + let (decls, newenv) = Typedecl.transl_type_decl env sdecls in + let rem = transl_sig newenv srem in + map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls rem + | Psig_exception(name, sarg) -> + let arg = Typedecl.transl_exception env sarg in + let (id, newenv) = Env.enter_exception name arg env in + let rem = transl_sig newenv srem in + Tsig_exception(id, arg) :: rem + | Psig_module(name, smty) -> + check "module" item.psig_loc module_names name; + let mty = transl_modtype env smty in + let (id, newenv) = Env.enter_module name mty env in + let rem = transl_sig newenv srem in + Tsig_module(id, mty, Trec_not) :: rem + | Psig_recmodule sdecls -> + List.iter + (fun (name, smty) -> + check "module" item.psig_loc module_names name) + sdecls; + let (decls, newenv) = + transl_recmodule_modtypes item.psig_loc env sdecls in + let rem = transl_sig newenv srem in + map_rec (fun rs (id, mty) -> Tsig_module(id, mty, rs)) decls rem + | Psig_modtype(name, sinfo) -> + check "module type" item.psig_loc modtype_names name; + let info = transl_modtype_info env sinfo in + let (id, newenv) = Env.enter_modtype name info env in + let rem = transl_sig newenv srem in + Tsig_modtype(id, info) :: rem + | Psig_open lid -> + let (path, mty) = type_module_path env item.psig_loc lid in + let sg = extract_sig_open env item.psig_loc mty in + let newenv = Env.open_signature path sg env in + transl_sig newenv srem + | Psig_include smty -> + let mty = transl_modtype env smty in + let sg = Subst.signature Subst.identity + (extract_sig env smty.pmty_loc mty) in + List.iter + (check_sig_item type_names module_names modtype_names + item.psig_loc) + sg; + let newenv = Env.add_signature sg env in + let rem = transl_sig newenv srem in + sg @ rem + | Psig_class cl -> + List.iter + (fun {pci_name = name} -> + check "type" item.psig_loc type_names name) + cl; + let (classes, newenv) = Typeclass.class_descriptions env cl in + let rem = transl_sig newenv srem in + List.flatten + (map_rec + (fun rs (i, d, i', d', i'', d'', i''', d''', _, _, _) -> + [Tsig_class(i, d, rs); + Tsig_cltype(i', d', rs); + Tsig_type(i'', d'', rs); + Tsig_type(i''', d''', rs)]) + classes [rem]) + | Psig_class_type cl -> + List.iter + (fun {pci_name = name} -> + check "type" item.psig_loc type_names name) + cl; + let (classes, newenv) = Typeclass.class_type_declarations env cl in + let rem = transl_sig newenv srem in + List.flatten + (map_rec + (fun rs (i, d, i', d', i'', d'') -> + [Tsig_cltype(i, d, rs); + Tsig_type(i', d', rs); + Tsig_type(i'', d'', rs)]) + classes [rem]) + in transl_sig env sg + +and transl_modtype_info env sinfo = + match sinfo with + Pmodtype_abstract -> + Tmodtype_abstract + | Pmodtype_manifest smty -> + Tmodtype_manifest(transl_modtype env smty) + +and transl_recmodule_modtypes loc env sdecls = + let make_env curr = + List.fold_left + (fun env (id, mty) -> Env.add_module id mty env) + env curr in + let transition env_c curr = + List.map2 + (fun (_, smty) (id, mty) -> (id, transl_modtype env_c smty)) + sdecls curr in + let init = + List.map + (fun (name, smty) -> + (Ident.create name, approx_modtype env smty)) + sdecls in + let env0 = make_env init in + let dcl1 = transition env0 init in + let env1 = make_env dcl1 in + check_recmod_typedecls env1 sdecls dcl1; + let dcl2 = transition env1 dcl1 in +(* + List.iter + (fun (id, mty) -> + Format.printf "%a: %a@." Printtyp.ident id Printtyp.modtype mty) + dcl2; +*) + let env2 = make_env dcl2 in + check_recmod_typedecls env2 sdecls dcl2; + (dcl2, env2) + +(* Try to convert a module expression to a module path. *) + +exception Not_a_path + +let rec path_of_module mexp = + match mexp.mod_desc with + Tmod_ident p -> p + | Tmod_apply(funct, arg, coercion) -> + Papply(path_of_module funct, path_of_module arg) + | _ -> raise Not_a_path + +(* Check that all core type schemes in a structure are closed *) + +let rec closed_modtype = function + Tmty_ident p -> true + | Tmty_signature sg -> List.for_all closed_signature_item sg + | Tmty_functor(id, param, body) -> closed_modtype body + +and closed_signature_item = function + Tsig_value(id, desc) -> Ctype.closed_schema desc.val_type + | Tsig_module(id, mty, _) -> closed_modtype mty + | _ -> true + +let check_nongen_scheme env = function + Tstr_value(rec_flag, pat_exp_list) -> + List.iter + (fun (pat, exp) -> + if not (Ctype.closed_schema exp.exp_type) then + raise(Error(exp.exp_loc, Non_generalizable exp.exp_type))) + pat_exp_list + | Tstr_module(id, md) -> + if not (closed_modtype md.mod_type) then + raise(Error(md.mod_loc, Non_generalizable_module md.mod_type)) + | _ -> () + +let check_nongen_schemes env str = + List.iter (check_nongen_scheme env) str + +(* Extract the list of "value" identifiers bound by a signature. + "Value" identifiers are identifiers for signature components that + correspond to a run-time value: values, exceptions, modules, classes. + Note: manifest primitives do not correspond to a run-time value! *) + +let rec bound_value_identifiers = function + [] -> [] + | Tsig_value(id, {val_kind = Val_reg}) :: rem -> + id :: bound_value_identifiers rem + | Tsig_exception(id, decl) :: rem -> id :: bound_value_identifiers rem + | Tsig_module(id, mty, _) :: rem -> id :: bound_value_identifiers rem + | Tsig_class(id, decl, _) :: rem -> id :: bound_value_identifiers rem + | _ :: rem -> bound_value_identifiers rem + +(* Helpers for typing recursive modules *) + +let anchor_submodule name anchor = + match anchor with None -> None | Some p -> Some(Pdot(p, name, nopos)) +let anchor_recmodule id anchor = + Some (Pident id) + +let enrich_type_decls anchor decls oldenv newenv = + match anchor with + None -> newenv + | Some p -> + List.fold_left + (fun e (id, info) -> + let info' = + Mtype.enrich_typedecl oldenv (Pdot(p, Ident.name id, nopos)) info + in + Env.add_type id info' e) + oldenv decls + +let enrich_module_type anchor name mty env = + match anchor with + None -> mty + | Some p -> Mtype.enrich_modtype env (Pdot(p, name, nopos)) mty + +let check_recmodule_inclusion env bindings = + (* PR#4450, PR#4470: consider + module rec X : DECL = MOD where MOD has inferred type ACTUAL + The "natural" typing condition + E, X: ACTUAL |- ACTUAL <: DECL + leads to circularities through manifest types. + Instead, we "unroll away" the potential circularities a finite number + of times. The (weaker) condition we implement is: + E, X: DECL, + X1: ACTUAL, + X2: ACTUAL{X <- X1}/X1 + ... + Xn: ACTUAL{X <- X(n-1)}/X(n-1) + |- ACTUAL{X <- Xn}/Xn <: DECL{X <- Xn} + so that manifest types rooted at X(n+1) are expanded in terms of X(n), + avoiding circularities. The strengthenings ensure that + Xn.t = X(n-1).t = ... = X2.t = X1.t. + N can be chosen arbitrarily; larger values of N result in more + recursive definitions being accepted. A good choice appears to be + the number of mutually recursive declarations. *) + + let subst_and_strengthen env s id mty = + Mtype.strengthen env (Subst.modtype s mty) + (Subst.module_path s (Pident id)) in + + let rec check_incl first_time n env s = + if n > 0 then begin + (* Generate fresh names Y_i for the rec. bound module idents X_i *) + let bindings1 = + List.map + (fun (id, mty_decl, modl, mty_actual) -> + (id, Ident.rename id, mty_actual)) + bindings in + (* Enter the Y_i in the environment with their actual types substituted + by the input substitution s *) + let env' = + List.fold_left + (fun env (id, id', mty_actual) -> + let mty_actual' = + if first_time + then mty_actual + else subst_and_strengthen env s id mty_actual in + Env.add_module id' mty_actual' env) + env bindings1 in + (* Build the output substitution Y_i <- X_i *) + let s' = + List.fold_left + (fun s (id, id', mty_actual) -> + Subst.add_module id (Pident id') s) + Subst.identity bindings1 in + (* Recurse with env' and s' *) + check_incl false (n-1) env' s' + end else begin + (* Base case: check inclusion of s(mty_actual) in s(mty_decl) + and insert coercion if needed *) + let check_inclusion (id, mty_decl, modl, mty_actual) = + let mty_decl' = Subst.modtype s mty_decl + and mty_actual' = subst_and_strengthen env s id mty_actual in + let coercion = + try + Includemod.modtypes env mty_actual' mty_decl' + with Includemod.Error msg -> + raise(Error(modl.mod_loc, Not_included msg)) in + let modl' = + { mod_desc = Tmod_constraint(modl, mty_decl, coercion); + mod_type = mty_decl; + mod_env = env; + mod_loc = modl.mod_loc } in + (id, modl') in + List.map check_inclusion bindings + end + in check_incl true (List.length bindings) env Subst.identity + +(* Type a module value expression *) + +let rec type_module anchor env smod = + match smod.pmod_desc with + Pmod_ident lid -> + let (path, mty) = type_module_path env smod.pmod_loc lid in + rm { mod_desc = Tmod_ident path; + mod_type = Mtype.strengthen env mty path; + mod_env = env; + mod_loc = smod.pmod_loc } + | Pmod_structure sstr -> + let (str, sg, finalenv) = type_structure anchor env sstr smod.pmod_loc in + rm { mod_desc = Tmod_structure str; + mod_type = Tmty_signature sg; + mod_env = env; + mod_loc = smod.pmod_loc } + | Pmod_functor(name, smty, sbody) -> + let mty = transl_modtype env smty in + let (id, newenv) = Env.enter_module name mty env in + let body = type_module None newenv sbody in + rm { mod_desc = Tmod_functor(id, mty, body); + mod_type = Tmty_functor(id, mty, body.mod_type); + mod_env = env; + mod_loc = smod.pmod_loc } + | Pmod_apply(sfunct, sarg) -> + let funct = type_module None env sfunct in + let arg = type_module None env sarg in + begin match Mtype.scrape env funct.mod_type with + Tmty_functor(param, mty_param, mty_res) as mty_functor -> + let coercion = + try + Includemod.modtypes env arg.mod_type mty_param + with Includemod.Error msg -> + raise(Error(sarg.pmod_loc, Not_included msg)) in + let mty_appl = + try + let path = path_of_module arg in + Subst.modtype (Subst.add_module param path Subst.identity) + mty_res + with Not_a_path -> + try + Mtype.nondep_supertype + (Env.add_module param arg.mod_type env) param mty_res + with Not_found -> + raise(Error(smod.pmod_loc, + Cannot_eliminate_dependency mty_functor)) in + rm { mod_desc = Tmod_apply(funct, arg, coercion); + mod_type = mty_appl; + mod_env = env; + mod_loc = smod.pmod_loc } + | _ -> + raise(Error(sfunct.pmod_loc, Cannot_apply funct.mod_type)) + end + | Pmod_constraint(sarg, smty) -> + let arg = type_module anchor env sarg in + let mty = transl_modtype env smty in + let coercion = + try + Includemod.modtypes env arg.mod_type mty + with Includemod.Error msg -> + raise(Error(sarg.pmod_loc, Not_included msg)) in + rm { mod_desc = Tmod_constraint(arg, mty, coercion); + mod_type = mty; + mod_env = env; + mod_loc = smod.pmod_loc } + +and type_structure anchor env sstr scope = + let type_names = ref StringSet.empty + and module_names = ref StringSet.empty + and modtype_names = ref StringSet.empty in + let rec type_struct env sstr = + Ctype.init_def(Ident.current_time()); + match sstr with + [] -> + ([], [], env) + | {pstr_desc = Pstr_eval sexpr} :: srem -> + let expr = Typecore.type_expression env sexpr in + let (str_rem, sig_rem, final_env) = type_struct env srem in + (Tstr_eval expr :: str_rem, sig_rem, final_env) + | {pstr_desc = Pstr_value(rec_flag, sdefs); pstr_loc = loc} :: srem -> + let scope = + match rec_flag with + | Recursive -> Some (Annot.Idef {scope with + Location.loc_start = loc.Location.loc_start}) + | Nonrecursive -> + let start = match srem with + | [] -> loc.Location.loc_end + | {pstr_loc = loc2} :: _ -> loc2.Location.loc_start + in Some (Annot.Idef {scope with Location.loc_start = start}) + | Default -> None + in + let (defs, newenv) = + Typecore.type_binding env rec_flag sdefs scope in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + let bound_idents = let_bound_idents defs in + let make_sig_value id = + Tsig_value(id, Env.find_value (Pident id) newenv) in + (Tstr_value(rec_flag, defs) :: str_rem, + map_end make_sig_value bound_idents sig_rem, + final_env) + | {pstr_desc = Pstr_primitive(name, sdesc)} :: srem -> + let desc = Typedecl.transl_value_decl env sdesc in + let (id, newenv) = Env.enter_value name desc env in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_primitive(id, desc) :: str_rem, + Tsig_value(id, desc) :: sig_rem, + final_env) + | {pstr_desc = Pstr_type sdecls; pstr_loc = loc} :: srem -> + List.iter + (fun (name, decl) -> check "type" loc type_names name) + sdecls; + let (decls, newenv) = Typedecl.transl_type_decl env sdecls in + let newenv' = + enrich_type_decls anchor decls env newenv in + let (str_rem, sig_rem, final_env) = type_struct newenv' srem in + (Tstr_type decls :: str_rem, + map_rec' (fun rs (id, info) -> Tsig_type(id, info, rs)) decls sig_rem, + final_env) + | {pstr_desc = Pstr_exception(name, sarg)} :: srem -> + let arg = Typedecl.transl_exception env sarg in + let (id, newenv) = Env.enter_exception name arg env in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_exception(id, arg) :: str_rem, + Tsig_exception(id, arg) :: sig_rem, + final_env) + | {pstr_desc = Pstr_exn_rebind(name, longid); pstr_loc = loc} :: srem -> + let (path, arg) = Typedecl.transl_exn_rebind env loc longid in + let (id, newenv) = Env.enter_exception name arg env in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_exn_rebind(id, path) :: str_rem, + Tsig_exception(id, arg) :: sig_rem, + final_env) + | {pstr_desc = Pstr_module(name, smodl); pstr_loc = loc} :: srem -> + check "module" loc module_names name; + let modl = type_module (anchor_submodule name anchor) env smodl in + let mty = enrich_module_type anchor name modl.mod_type env in + let (id, newenv) = Env.enter_module name mty env in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_module(id, modl) :: str_rem, + Tsig_module(id, modl.mod_type, Trec_not) :: sig_rem, + final_env) + | {pstr_desc = Pstr_recmodule sbind; pstr_loc = loc} :: srem -> + List.iter + (fun (name, _, _) -> check "module" loc module_names name) + sbind; + let (decls, newenv) = + transl_recmodule_modtypes loc env + (List.map (fun (name, smty, smodl) -> (name, smty)) sbind) in + let bindings1 = + List.map2 + (fun (id, mty) (name, smty, smodl) -> + let modl = + type_module (anchor_recmodule id anchor) newenv smodl in + let mty' = + enrich_module_type anchor (Ident.name id) modl.mod_type newenv in + (id, mty, modl, mty')) + decls sbind in + let bindings2 = + check_recmodule_inclusion newenv bindings1 in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_recmodule bindings2 :: str_rem, + map_rec (fun rs (id, modl) -> Tsig_module(id, modl.mod_type, rs)) + bindings2 sig_rem, + final_env) + | {pstr_desc = Pstr_modtype(name, smty); pstr_loc = loc} :: srem -> + check "module type" loc modtype_names name; + let mty = transl_modtype env smty in + let (id, newenv) = Env.enter_modtype name (Tmodtype_manifest mty) env in + let (str_rem, sig_rem, final_env) = type_struct newenv srem in + (Tstr_modtype(id, mty) :: str_rem, + Tsig_modtype(id, Tmodtype_manifest mty) :: sig_rem, + final_env) + | {pstr_desc = Pstr_open lid; pstr_loc = loc} :: srem -> + let (path, mty) = type_module_path env loc lid in + let sg = extract_sig_open env loc mty in + type_struct (Env.open_signature path sg env) srem + | {pstr_desc = Pstr_class cl; pstr_loc = loc} :: srem -> + List.iter + (fun {pci_name = name} -> check "type" loc type_names name) + cl; + let (classes, new_env) = Typeclass.class_declarations env cl in + let (str_rem, sig_rem, final_env) = type_struct new_env srem in + (Tstr_class + (List.map (fun (i, d, _,_,_,_,_,_, s, m, c) -> + let vf = if d.cty_new = None then Virtual else Concrete in + (i, s, m, c, vf)) classes) :: + Tstr_cltype + (List.map (fun (_,_, i, d, _,_,_,_,_,_,_) -> (i, d)) classes) :: + Tstr_type + (List.map (fun (_,_,_,_, i, d, _,_,_,_,_) -> (i, d)) classes) :: + Tstr_type + (List.map (fun (_,_,_,_,_,_, i, d, _,_,_) -> (i, d)) classes) :: + str_rem, + List.flatten + (map_rec + (fun rs (i, d, i', d', i'', d'', i''', d''', _, _, _) -> + [Tsig_class(i, d, rs); + Tsig_cltype(i', d', rs); + Tsig_type(i'', d'', rs); + Tsig_type(i''', d''', rs)]) + classes [sig_rem]), + final_env) + | {pstr_desc = Pstr_class_type cl; pstr_loc = loc} :: srem -> + List.iter + (fun {pci_name = name} -> check "type" loc type_names name) + cl; + let (classes, new_env) = Typeclass.class_type_declarations env cl in + let (str_rem, sig_rem, final_env) = type_struct new_env srem in + (Tstr_cltype + (List.map (fun (i, d, _, _, _, _) -> (i, d)) classes) :: + Tstr_type + (List.map (fun (_, _, i, d, _, _) -> (i, d)) classes) :: + Tstr_type + (List.map (fun (_, _, _, _, i, d) -> (i, d)) classes) :: + str_rem, + List.flatten + (map_rec + (fun rs (i, d, i', d', i'', d'') -> + [Tsig_cltype(i, d, rs); + Tsig_type(i', d', rs); + Tsig_type(i'', d'', rs)]) + classes [sig_rem]), + final_env) + | {pstr_desc = Pstr_include smodl; pstr_loc = loc} :: srem -> + let modl = type_module None env smodl in + (* Rename all identifiers bound by this signature to avoid clashes *) + let sg = Subst.signature Subst.identity + (extract_sig_open env smodl.pmod_loc modl.mod_type) in + List.iter + (check_sig_item type_names module_names modtype_names loc) sg; + let new_env = Env.add_signature sg env in + let (str_rem, sig_rem, final_env) = type_struct new_env srem in + (Tstr_include (modl, bound_value_identifiers sg) :: str_rem, + sg @ sig_rem, + final_env) + in + if !Clflags.annotations + then List.iter (function {pstr_loc = l} -> Stypes.record_phrase l) sstr; + type_struct env sstr + +let type_module = type_module None +let type_structure = type_structure None + +(* Fill in the forward declaration *) +let _ = + Typecore.type_module := type_module + +(* Normalize types in a signature *) + +let rec normalize_modtype env = function + Tmty_ident p -> () + | Tmty_signature sg -> normalize_signature env sg + | Tmty_functor(id, param, body) -> normalize_modtype env body + +and normalize_signature env = List.iter (normalize_signature_item env) + +and normalize_signature_item env = function + Tsig_value(id, desc) -> Ctype.normalize_type env desc.val_type + | Tsig_module(id, mty, _) -> normalize_modtype env mty + | _ -> () + +(* Simplify multiple specifications of a value or an exception in a signature. + (Other signature components, e.g. types, modules, etc, are checked for + name uniqueness.) If multiple specifications with the same name, + keep only the last (rightmost) one. *) + +let rec simplify_modtype mty = + match mty with + Tmty_ident path -> mty + | Tmty_functor(id, arg, res) -> Tmty_functor(id, arg, simplify_modtype res) + | Tmty_signature sg -> Tmty_signature(simplify_signature sg) + +and simplify_signature sg = + let rec simplif val_names exn_names res = function + [] -> res + | (Tsig_value(id, descr) as component) :: sg -> + let name = Ident.name id in + simplif (StringSet.add name val_names) exn_names + (if StringSet.mem name val_names then res else component :: res) + sg + | (Tsig_exception(id, decl) as component) :: sg -> + let name = Ident.name id in + simplif val_names (StringSet.add name exn_names) + (if StringSet.mem name exn_names then res else component :: res) + sg + | Tsig_module(id, mty, rs) :: sg -> + simplif val_names exn_names + (Tsig_module(id, simplify_modtype mty, rs) :: res) sg + | component :: sg -> + simplif val_names exn_names (component :: res) sg + in + simplif StringSet.empty StringSet.empty [] (List.rev sg) + +(* Typecheck an implementation file *) + +let type_implementation sourcefile outputprefix modulename initial_env ast = + Typecore.reset_delayed_checks (); + let (str, sg, finalenv) = type_structure initial_env ast Location.none in + let simple_sg = simplify_signature sg in + Typecore.force_delayed_checks (); + if !Clflags.print_types then begin + fprintf std_formatter "%a@." Printtyp.signature simple_sg; + (str, Tcoerce_none) (* result is ignored by Compile.implementation *) + end else begin + let sourceintf = + Misc.chop_extension_if_any sourcefile ^ !Config.interface_suffix in + if Sys.file_exists sourceintf then begin + let intf_file = + try + find_in_path_uncap !Config.load_path (modulename ^ ".cmi") + with Not_found -> + raise(Error(Location.none, Interface_not_compiled sourceintf)) in + let dclsig = Env.read_signature modulename intf_file in + let coercion = Includemod.compunit sourcefile sg intf_file dclsig in + (str, coercion) + end else begin + check_nongen_schemes finalenv str; + normalize_signature finalenv simple_sg; + let coercion = + Includemod.compunit sourcefile sg + "(inferred signature)" simple_sg in + if not !Clflags.dont_write_files then + Env.save_signature simple_sg modulename (outputprefix ^ ".cmi"); + (str, coercion) + end + end + +(* "Packaging" of several compilation units into one unit + having them as sub-modules. *) + +let rec package_signatures subst = function + [] -> [] + | (name, sg) :: rem -> + let sg' = Subst.signature subst sg in + let oldid = Ident.create_persistent name + and newid = Ident.create name in + Tsig_module(newid, Tmty_signature sg', Trec_not) :: + package_signatures (Subst.add_module oldid (Pident newid) subst) rem + +let package_units objfiles cmifile modulename = + (* Read the signatures of the units *) + let units = + List.map + (fun f -> + let pref = chop_extensions f in + let modname = String.capitalize(Filename.basename pref) in + let sg = Env.read_signature modname (pref ^ ".cmi") in + if Filename.check_suffix f ".cmi" && + not(Mtype.no_code_needed_sig Env.initial sg) + then raise(Error(Location.none, Implementation_is_required f)); + (modname, Env.read_signature modname (pref ^ ".cmi"))) + objfiles in + (* Compute signature of packaged unit *) + Ident.reinit(); + let sg = package_signatures Subst.identity units in + (* See if explicit interface is provided *) + let mlifile = + chop_extension_if_any cmifile ^ !Config.interface_suffix in + if Sys.file_exists mlifile then begin + if not (Sys.file_exists cmifile) then begin + raise(Error(Location.in_file mlifile, Interface_not_compiled mlifile)) + end; + let dclsig = Env.read_signature modulename cmifile in + Includemod.compunit "(obtained by packing)" sg mlifile dclsig + end else begin + (* Determine imports *) + let unit_names = List.map fst units in + let imports = + List.filter + (fun (name, crc) -> not (List.mem name unit_names)) + (Env.imported_units()) in + (* Write packaged signature *) + Env.save_signature_with_imports sg modulename cmifile imports; + Tcoerce_none + end + +(* Error report *) + +open Printtyp + +let report_error ppf = function + | Unbound_module lid -> fprintf ppf "Unbound module %a" longident lid + | Unbound_modtype lid -> fprintf ppf "Unbound module type %a" longident lid + | Cannot_apply mty -> + fprintf ppf + "@[This module is not a functor; it has type@ %a@]" modtype mty + | Not_included errs -> + fprintf ppf + "@[<v>Signature mismatch:@ %a@]" Includemod.report_error errs + | Cannot_eliminate_dependency mty -> + fprintf ppf + "@[This functor has type@ %a@ \ + The parameter cannot be eliminated in the result type.@ \ + Please bind the argument to a module identifier.@]" modtype mty + | Signature_expected -> fprintf ppf "This module type is not a signature" + | Structure_expected mty -> + fprintf ppf + "@[This module is not a structure; it has type@ %a" modtype mty + | With_no_component lid -> + fprintf ppf + "@[The signature constrained by `with' has no component named %a@]" + longident lid + | With_mismatch(lid, explanation) -> + fprintf ppf + "@[<v>\ + @[In this `with' constraint, the new definition of %a@ \ + does not match its original definition@ \ + in the constrained signature:@]@ \ + %a@]" + longident lid Includemod.report_error explanation + | Repeated_name(kind, name) -> + fprintf ppf + "@[Multiple definition of the %s name %s.@ \ + Names must be unique in a given structure or signature.@]" kind name + | Non_generalizable typ -> + fprintf ppf + "@[The type of this expression,@ %a,@ \ + contains type variables that cannot be generalized@]" type_scheme typ + | Non_generalizable_class (id, desc) -> + fprintf ppf + "@[The type of this class,@ %a,@ \ + contains type variables that cannot be generalized@]" + (class_declaration id) desc + | Non_generalizable_module mty -> + fprintf ppf + "@[The type of this module,@ %a,@ \ + contains type variables that cannot be generalized@]" modtype mty + | Implementation_is_required intf_name -> + fprintf ppf + "@[The interface %s@ declares values, not just types.@ \ + An implementation must be provided.@]" intf_name + | Interface_not_compiled intf_name -> + fprintf ppf + "@[Could not find the .cmi file for interface@ %s.@]" intf_name diff --git a/typing/typemod.mli b/typing/typemod.mli new file mode 100644 index 0000000..bf8fe2a --- /dev/null +++ b/typing/typemod.mli @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typemod.mli,v 1.27 2007-05-16 08:21:40 doligez Exp $ *) + +(* Type-checking of the module language *) + +open Types +open Format + +val type_module: + Env.t -> Parsetree.module_expr -> Typedtree.module_expr +val type_structure: + Env.t -> Parsetree.structure -> Location.t -> + Typedtree.structure * signature * Env.t +val type_implementation: + string -> string -> string -> Env.t -> Parsetree.structure -> + Typedtree.structure * Typedtree.module_coercion +val transl_signature: + Env.t -> Parsetree.signature -> signature +val check_nongen_schemes: + Env.t -> Typedtree.structure -> unit + +val simplify_signature: signature -> signature + +val package_units: + string list -> string -> string -> Typedtree.module_coercion + +type error = + Unbound_module of Longident.t + | Unbound_modtype of Longident.t + | Cannot_apply of module_type + | Not_included of Includemod.error list + | Cannot_eliminate_dependency of module_type + | Signature_expected + | Structure_expected of module_type + | With_no_component of Longident.t + | With_mismatch of Longident.t * Includemod.error list + | Repeated_name of string * string + | Non_generalizable of type_expr + | Non_generalizable_class of Ident.t * class_declaration + | Non_generalizable_module of module_type + | Implementation_is_required of string + | Interface_not_compiled of string + +exception Error of Location.t * error + +val report_error: formatter -> error -> unit diff --git a/typing/types.ml b/typing/types.ml new file mode 100644 index 0000000..4cfd0d2 --- /dev/null +++ b/typing/types.ml @@ -0,0 +1,208 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: types.ml,v 1.29 2008-07-19 02:13:09 garrigue Exp $ *) + +(* Representation of types and declarations *) + +open Misc +open Asttypes + +(* Type expressions for the core language *) + +type type_expr = + { mutable desc: type_desc; + mutable level: int; + mutable id: int } + +and type_desc = + Tvar + | Tarrow of label * type_expr * type_expr * commutable + | Ttuple of type_expr list + | Tconstr of Path.t * type_expr list * abbrev_memo ref + | Tobject of type_expr * (Path.t * type_expr list) option ref + | Tfield of string * field_kind * type_expr * type_expr + | Tnil + | Tlink of type_expr + | Tsubst of type_expr (* for copying *) + | Tvariant of row_desc + | Tunivar + | Tpoly of type_expr * type_expr list + +and row_desc = + { row_fields: (label * row_field) list; + row_more: type_expr; + row_bound: unit; + row_closed: bool; + row_fixed: bool; + row_name: (Path.t * type_expr list) option } + +and row_field = + Rpresent of type_expr option + | Reither of bool * type_expr list * bool * row_field option ref + (* 1st true denotes a constant constructor *) + (* 2nd true denotes a tag in a pattern matching, and + is erased later *) + | Rabsent + +and abbrev_memo = + Mnil + | Mcons of private_flag * Path.t * type_expr * type_expr * abbrev_memo + | Mlink of abbrev_memo ref + +and field_kind = + Fvar of field_kind option ref + | Fpresent + | Fabsent + +and commutable = + Cok + | Cunknown + | Clink of commutable ref + +module TypeOps = struct + type t = type_expr + let compare t1 t2 = t1.id - t2.id + let hash t = t.id + let equal t1 t2 = t1 == t2 +end + +(* Maps of methods and instance variables *) + +module OrderedString = struct type t = string let compare = compare end +module Meths = Map.Make(OrderedString) +module Vars = Meths + +(* Value descriptions *) + +type value_description = + { val_type: type_expr; (* Type of the value *) + val_kind: value_kind } + +and value_kind = + Val_reg (* Regular value *) + | Val_prim of Primitive.description (* Primitive *) + | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *) + | Val_self of (Ident.t * type_expr) Meths.t ref * + (Ident.t * Asttypes.mutable_flag * + Asttypes.virtual_flag * type_expr) Vars.t ref * + string * type_expr + (* Self *) + | Val_anc of (string * Ident.t) list * string + (* Ancestor *) + | Val_unbound (* Unbound variable *) + +(* Constructor descriptions *) + +type constructor_description = + { cstr_res: type_expr; (* Type of the result *) + cstr_args: type_expr list; (* Type of the arguments *) + cstr_arity: int; (* Number of arguments *) + cstr_tag: constructor_tag; (* Tag for heap blocks *) + cstr_consts: int; (* Number of constant constructors *) + cstr_nonconsts: int; (* Number of non-const constructors *) + cstr_private: private_flag } (* Read-only constructor? *) + +and constructor_tag = + Cstr_constant of int (* Constant constructor (an int) *) + | Cstr_block of int (* Regular constructor (a block) *) + | Cstr_exception of Path.t (* Exception constructor *) + +(* Record label descriptions *) + +type label_description = + { lbl_res: type_expr; (* Type of the result *) + lbl_arg: type_expr; (* Type of the argument *) + lbl_mut: mutable_flag; (* Is this a mutable field? *) + lbl_pos: int; (* Position in block *) + lbl_all: label_description array; (* All the labels in this type *) + lbl_repres: record_representation; (* Representation for this record *) + lbl_private: private_flag } (* Read-only field? *) + +and record_representation = + Record_regular (* All fields are boxed / tagged *) + | Record_float (* All fields are floats *) + +(* Type definitions *) + +type type_declaration = + { type_params: type_expr list; + type_arity: int; + type_kind: type_kind; + type_private: private_flag; + type_manifest: type_expr option; + type_variance: (bool * bool * bool) list } + (* covariant, contravariant, weakly contravariant *) + +and type_kind = + Type_abstract + | Type_variant of (string * type_expr list) list + | Type_record of + (string * mutable_flag * type_expr) list * record_representation + +type exception_declaration = type_expr list + +(* Type expressions for the class language *) + +module Concr = Set.Make(OrderedString) + +type class_type = + Tcty_constr of Path.t * type_expr list * class_type + | Tcty_signature of class_signature + | Tcty_fun of label * type_expr * class_type + +and class_signature = + { cty_self: type_expr; + cty_vars: + (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; + cty_concr: Concr.t; + cty_inher: (Path.t * type_expr list) list } + +type class_declaration = + { cty_params: type_expr list; + mutable cty_type: class_type; + cty_path: Path.t; + cty_new: type_expr option; + cty_variance: (bool * bool) list } + +type cltype_declaration = + { clty_params: type_expr list; + clty_type: class_type; + clty_path: Path.t; + clty_variance: (bool * bool) list } + +(* Type expressions for the module language *) + +type module_type = + Tmty_ident of Path.t + | Tmty_signature of signature + | Tmty_functor of Ident.t * module_type * module_type + +and signature = signature_item list + +and signature_item = + Tsig_value of Ident.t * value_description + | Tsig_type of Ident.t * type_declaration * rec_status + | Tsig_exception of Ident.t * exception_declaration + | Tsig_module of Ident.t * module_type * rec_status + | Tsig_modtype of Ident.t * modtype_declaration + | Tsig_class of Ident.t * class_declaration * rec_status + | Tsig_cltype of Ident.t * cltype_declaration * rec_status + +and modtype_declaration = + Tmodtype_abstract + | Tmodtype_manifest of module_type + +and rec_status = + Trec_not (* not recursive *) + | Trec_first (* first in a recursive group *) + | Trec_next (* not first in a recursive group *) diff --git a/typing/types.mli b/typing/types.mli new file mode 100644 index 0000000..d9ec1fd --- /dev/null +++ b/typing/types.mli @@ -0,0 +1,206 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: types.mli,v 1.29 2008-07-19 02:13:09 garrigue Exp $ *) + +(* Representation of types and declarations *) + +open Asttypes + +(* Type expressions for the core language *) + +type type_expr = + { mutable desc: type_desc; + mutable level: int; + mutable id: int } + +and type_desc = + Tvar + | Tarrow of label * type_expr * type_expr * commutable + | Ttuple of type_expr list + | Tconstr of Path.t * type_expr list * abbrev_memo ref + | Tobject of type_expr * (Path.t * type_expr list) option ref + | Tfield of string * field_kind * type_expr * type_expr + | Tnil + | Tlink of type_expr + | Tsubst of type_expr (* for copying *) + | Tvariant of row_desc + | Tunivar + | Tpoly of type_expr * type_expr list + +and row_desc = + { row_fields: (label * row_field) list; + row_more: type_expr; + row_bound: unit; (* kept for compatibility *) + row_closed: bool; + row_fixed: bool; + row_name: (Path.t * type_expr list) option } + +and row_field = + Rpresent of type_expr option + | Reither of bool * type_expr list * bool * row_field option ref + (* 1st true denotes a constant constructor *) + (* 2nd true denotes a tag in a pattern matching, and + is erased later *) + | Rabsent + +and abbrev_memo = + Mnil + | Mcons of private_flag * Path.t * type_expr * type_expr * abbrev_memo + | Mlink of abbrev_memo ref + +and field_kind = + Fvar of field_kind option ref + | Fpresent + | Fabsent + +and commutable = + Cok + | Cunknown + | Clink of commutable ref + +module TypeOps : sig + type t = type_expr + val compare : t -> t -> int + val equal : t -> t -> bool + val hash : t -> int +end + +(* Maps of methods and instance variables *) + +module Meths : Map.S with type key = string +module Vars : Map.S with type key = string + +(* Value descriptions *) + +type value_description = + { val_type: type_expr; (* Type of the value *) + val_kind: value_kind } + +and value_kind = + Val_reg (* Regular value *) + | Val_prim of Primitive.description (* Primitive *) + | Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *) + | Val_self of (Ident.t * type_expr) Meths.t ref * + (Ident.t * Asttypes.mutable_flag * + Asttypes.virtual_flag * type_expr) Vars.t ref * + string * type_expr + (* Self *) + | Val_anc of (string * Ident.t) list * string + (* Ancestor *) + | Val_unbound (* Unbound variable *) + +(* Constructor descriptions *) + +type constructor_description = + { cstr_res: type_expr; (* Type of the result *) + cstr_args: type_expr list; (* Type of the arguments *) + cstr_arity: int; (* Number of arguments *) + cstr_tag: constructor_tag; (* Tag for heap blocks *) + cstr_consts: int; (* Number of constant constructors *) + cstr_nonconsts: int; (* Number of non-const constructors *) + cstr_private: private_flag } (* Read-only constructor? *) + +and constructor_tag = + Cstr_constant of int (* Constant constructor (an int) *) + | Cstr_block of int (* Regular constructor (a block) *) + | Cstr_exception of Path.t (* Exception constructor *) + +(* Record label descriptions *) + +type label_description = + { lbl_res: type_expr; (* Type of the result *) + lbl_arg: type_expr; (* Type of the argument *) + lbl_mut: mutable_flag; (* Is this a mutable field? *) + lbl_pos: int; (* Position in block *) + lbl_all: label_description array; (* All the labels in this type *) + lbl_repres: record_representation; (* Representation for this record *) + lbl_private: private_flag } (* Read-only field? *) + +and record_representation = + Record_regular (* All fields are boxed / tagged *) + | Record_float (* All fields are floats *) + +(* Type definitions *) + +type type_declaration = + { type_params: type_expr list; + type_arity: int; + type_kind: type_kind; + type_private: private_flag; + type_manifest: type_expr option; + type_variance: (bool * bool * bool) list } + (* covariant, contravariant, weakly contravariant *) + +and type_kind = + Type_abstract + | Type_variant of (string * type_expr list) list + | Type_record of + (string * mutable_flag * type_expr) list * record_representation + +type exception_declaration = type_expr list + +(* Type expressions for the class language *) + +module Concr : Set.S with type elt = string + +type class_type = + Tcty_constr of Path.t * type_expr list * class_type + | Tcty_signature of class_signature + | Tcty_fun of label * type_expr * class_type + +and class_signature = + { cty_self: type_expr; + cty_vars: + (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; + cty_concr: Concr.t; + cty_inher: (Path.t * type_expr list) list } + +type class_declaration = + { cty_params: type_expr list; + mutable cty_type: class_type; + cty_path: Path.t; + cty_new: type_expr option; + cty_variance: (bool * bool) list } + +type cltype_declaration = + { clty_params: type_expr list; + clty_type: class_type; + clty_path: Path.t; + clty_variance: (bool * bool) list } + +(* Type expressions for the module language *) + +type module_type = + Tmty_ident of Path.t + | Tmty_signature of signature + | Tmty_functor of Ident.t * module_type * module_type + +and signature = signature_item list + +and signature_item = + Tsig_value of Ident.t * value_description + | Tsig_type of Ident.t * type_declaration * rec_status + | Tsig_exception of Ident.t * exception_declaration + | Tsig_module of Ident.t * module_type * rec_status + | Tsig_modtype of Ident.t * modtype_declaration + | Tsig_class of Ident.t * class_declaration * rec_status + | Tsig_cltype of Ident.t * cltype_declaration * rec_status + +and modtype_declaration = + Tmodtype_abstract + | Tmodtype_manifest of module_type + +and rec_status = + Trec_not (* not recursive *) + | Trec_first (* first in a recursive group *) + | Trec_next (* not first in a recursive group *) diff --git a/typing/typetexp.ml b/typing/typetexp.ml new file mode 100644 index 0000000..fa3f0c8 --- /dev/null +++ b/typing/typetexp.ml @@ -0,0 +1,567 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* typetexp.ml,v 1.34.4.9 2002/01/07 08:39:16 garrigue Exp *) + +(* Typechecking of type expressions for the core language *) + +open Misc +open Parsetree +open Types +open Ctype + +exception Already_bound + +type error = + Unbound_type_variable of string + | Unbound_type_constructor of Longident.t + | Unbound_type_constructor_2 of Path.t + | Type_arity_mismatch of Longident.t * int * int + | Bound_type_variable of string + | Recursive_type + | Unbound_class of Longident.t + | Unbound_row_variable of Longident.t + | Type_mismatch of (type_expr * type_expr) list + | Alias_type_mismatch of (type_expr * type_expr) list + | Present_has_conjunction of string + | Present_has_no_type of string + | Constructor_mismatch of type_expr * type_expr + | Not_a_variant of type_expr + | Variant_tags of string * string + | Invalid_variable_name of string + | Cannot_quantify of string * type_expr + +exception Error of Location.t * error + +type variable_context = int * (string, type_expr) Tbl.t + +(* Translation of type expressions *) + +let type_variables = ref (Tbl.empty : (string, type_expr) Tbl.t) +let univars = ref ([] : (string * type_expr) list) +let pre_univars = ref ([] : type_expr list) +let used_variables = ref (Tbl.empty : (string, type_expr * Location.t) Tbl.t) + +let reset_type_variables () = + reset_global_level (); + type_variables := Tbl.empty + +let narrow () = + (increase_global_level (), !type_variables) + +let widen (gl, tv) = + restore_global_level gl; + type_variables := tv + +let enter_type_variable strict loc name = + try + if name <> "" && name.[0] = '_' then + raise (Error (loc, Invalid_variable_name ("'" ^ name))); + let v = Tbl.find name !type_variables in + if strict then raise Already_bound; + v + with Not_found -> + let v = new_global_var() in + type_variables := Tbl.add name v !type_variables; + v + +let type_variable loc name = + try + Tbl.find name !type_variables + with Not_found -> + raise(Error(loc, Unbound_type_variable ("'" ^ name))) + +let wrap_method ty = + match (Ctype.repr ty).desc with + Tpoly _ -> ty + | _ -> Ctype.newty (Tpoly (ty, [])) + +let new_pre_univar () = + let v = newvar () in pre_univars := v :: !pre_univars; v + +let rec swap_list = function + x :: y :: l -> y :: x :: swap_list l + | l -> l + +type policy = Fixed | Extensible | Univars + +let rec transl_type env policy styp = + match styp.ptyp_desc with + Ptyp_any -> + if policy = Univars then new_pre_univar () else + if policy = Fixed then + raise (Error (styp.ptyp_loc, Unbound_type_variable "_")) + else newvar () + | Ptyp_var name -> + if name <> "" && name.[0] = '_' then + raise (Error (styp.ptyp_loc, Invalid_variable_name ("'" ^ name))); + begin try + instance (List.assoc name !univars) + with Not_found -> try + instance (fst(Tbl.find name !used_variables)) + with Not_found -> + let v = + if policy = Univars then new_pre_univar () else newvar () in + used_variables := Tbl.add name (v, styp.ptyp_loc) !used_variables; + v + end + | Ptyp_arrow(l, st1, st2) -> + let ty1 = transl_type env policy st1 in + let ty2 = transl_type env policy st2 in + newty (Tarrow(l, ty1, ty2, Cok)) + | Ptyp_tuple stl -> + newty (Ttuple(List.map (transl_type env policy) stl)) + | Ptyp_constr(lid, stl) -> + let (path, decl) = + let lid, env = + match lid with + | Longident.Ldot (Longident.Lident "*predef*", lid) -> + Longident.Lident lid, Env.initial + | _ -> lid, env + in + try + Env.lookup_type lid env + with Not_found -> + raise(Error(styp.ptyp_loc, Unbound_type_constructor lid)) in + if List.length stl <> decl.type_arity then + raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid, decl.type_arity, + List.length stl))); + let args = List.map (transl_type env policy) stl in + let params = Ctype.instance_list decl.type_params in + let unify_param = + match decl.type_manifest with + None -> unify_var + | Some ty -> + if (repr ty).level = Btype.generic_level then unify_var else unify + in + List.iter2 + (fun (sty, ty) ty' -> + try unify_param env ty' ty with Unify trace -> + raise (Error(sty.ptyp_loc, Type_mismatch (swap_list trace)))) + (List.combine stl args) params; + let constr = newconstr path args in + begin try + Ctype.enforce_constraints env constr + with Unify trace -> + raise (Error(styp.ptyp_loc, Type_mismatch trace)) + end; + constr + | Ptyp_object fields -> + newobj (transl_fields env policy fields) + | Ptyp_class(lid, stl, present) -> + let (path, decl, is_variant) = + try + let (path, decl) = Env.lookup_type lid env in + let rec check decl = + match decl.type_manifest with + None -> raise Not_found + | Some ty -> + match (repr ty).desc with + Tvariant row when Btype.static_row row -> () + | Tconstr (path, _, _) -> + check (Env.find_type path env) + | _ -> raise Not_found + in check decl; + Location.prerr_warning styp.ptyp_loc Warnings.Deprecated; + (path, decl,true) + with Not_found -> try + if present <> [] then raise Not_found; + let lid2 = + match lid with + Longident.Lident s -> Longident.Lident ("#" ^ s) + | Longident.Ldot(r, s) -> Longident.Ldot (r, "#" ^ s) + | Longident.Lapply(_, _) -> fatal_error "Typetexp.transl_type" + in + let (path, decl) = Env.lookup_type lid2 env in + (path, decl, false) + with Not_found -> + raise(Error(styp.ptyp_loc, Unbound_class lid)) + in + if List.length stl <> decl.type_arity then + raise(Error(styp.ptyp_loc, Type_arity_mismatch(lid, decl.type_arity, + List.length stl))); + let args = List.map (transl_type env policy) stl in + let params = Ctype.instance_list decl.type_params in + List.iter2 + (fun (sty, ty) ty' -> + try unify_var env ty' ty with Unify trace -> + raise (Error(sty.ptyp_loc, Type_mismatch (swap_list trace)))) + (List.combine stl args) params; + let ty = + try Ctype.expand_head env (newconstr path args) + with Unify trace -> + raise (Error(styp.ptyp_loc, Type_mismatch trace)) + in + begin match ty.desc with + Tvariant row -> + let row = Btype.row_repr row in + List.iter + (fun l -> if not (List.mem_assoc l row.row_fields) then + raise(Error(styp.ptyp_loc, Present_has_no_type l))) + present; + let fields = + List.map + (fun (l,f) -> l, + if List.mem l present then f else + match Btype.row_field_repr f with + | Rpresent (Some ty) -> + Reither(false, [ty], false, ref None) + | Rpresent None -> + Reither (true, [], false, ref None) + | _ -> f) + row.row_fields + in + let row = { row_closed = true; row_fields = fields; + row_bound = (); row_name = Some (path, args); + row_fixed = false; row_more = newvar () } in + let static = Btype.static_row row in + let row = + if static || policy <> Univars then row + else { row with row_more = new_pre_univar () } + in + newty (Tvariant row) + | Tobject (fi, _) -> + let _, tv = flatten_fields fi in + if policy = Univars then pre_univars := tv :: !pre_univars; + ty + | _ -> + assert false + end + | Ptyp_alias(st, alias) -> + begin + try + let t = + try List.assoc alias !univars + with Not_found -> + instance (fst(Tbl.find alias !used_variables)) + in + let ty = transl_type env policy st in + begin try unify_var env t ty with Unify trace -> + let trace = swap_list trace in + raise(Error(styp.ptyp_loc, Alias_type_mismatch trace)) + end; + ty + with Not_found -> + if !Clflags.principal then begin_def (); + let t = newvar () in + used_variables := Tbl.add alias (t, styp.ptyp_loc) !used_variables; + let ty = transl_type env policy st in + begin try unify_var env t ty with Unify trace -> + let trace = swap_list trace in + raise(Error(styp.ptyp_loc, Alias_type_mismatch trace)) + end; + if !Clflags.principal then begin + end_def (); + generalize_structure t; + end; + instance t + end + | Ptyp_variant(fields, closed, present) -> + let name = ref None in + let mkfield l f = + newty (Tvariant {row_fields=[l,f]; row_more=newvar(); + row_bound=(); row_closed=true; + row_fixed=false; row_name=None}) in + let hfields = Hashtbl.create 17 in + let add_typed_field loc l f = + let h = Btype.hash_variant l in + try + let (l',f') = Hashtbl.find hfields h in + (* Check for tag conflicts *) + if l <> l' then raise(Error(styp.ptyp_loc, Variant_tags(l, l'))); + let ty = mkfield l f and ty' = mkfield l f' in + if equal env false [ty] [ty'] then () else + try unify env ty ty' + with Unify trace -> raise(Error(loc, Constructor_mismatch (ty,ty'))) + with Not_found -> + Hashtbl.add hfields h (l,f) + in + let rec add_field = function + Rtag (l, c, stl) -> + name := None; + let f = match present with + Some present when not (List.mem l present) -> + let tl = List.map (transl_type env policy) stl in + Reither(c, tl, false, ref None) + | _ -> + if List.length stl > 1 || c && stl <> [] then + raise(Error(styp.ptyp_loc, Present_has_conjunction l)); + match stl with [] -> Rpresent None + | st :: _ -> Rpresent (Some(transl_type env policy st)) + in + add_typed_field styp.ptyp_loc l f + | Rinherit sty -> + let ty = transl_type env policy sty in + let nm = + match repr ty with + {desc=Tconstr(p, tl, _)} -> Some(p, tl) + | _ -> None + in + begin try + (* Set name if there are no fields yet *) + Hashtbl.iter (fun _ _ -> raise Exit) hfields; + name := nm + with Exit -> + (* Unset it otherwise *) + name := None + end; + let fl = match expand_head env ty, nm with + {desc=Tvariant row}, _ when Btype.static_row row -> + let row = Btype.row_repr row in + row.row_fields + | {desc=Tvar}, Some(p, _) -> + raise(Error(sty.ptyp_loc, Unbound_type_constructor_2 p)) + | _ -> + raise(Error(sty.ptyp_loc, Not_a_variant ty)) + in + List.iter + (fun (l, f) -> + let f = match present with + Some present when not (List.mem l present) -> + begin match f with + Rpresent(Some ty) -> + Reither(false, [ty], false, ref None) + | Rpresent None -> + Reither(true, [], false, ref None) + | _ -> + assert false + end + | _ -> f + in + add_typed_field sty.ptyp_loc l f) + fl + in + List.iter add_field fields; + let fields = Hashtbl.fold (fun _ p l -> p :: l) hfields [] in + begin match present with None -> () + | Some present -> + List.iter + (fun l -> if not (List.mem_assoc l fields) then + raise(Error(styp.ptyp_loc, Present_has_no_type l))) + present + end; + let row = + { row_fields = List.rev fields; row_more = newvar (); + row_bound = (); row_closed = closed; + row_fixed = false; row_name = !name } in + let static = Btype.static_row row in + let row = + if static then row else + match policy with + Fixed -> + raise (Error (styp.ptyp_loc, Unbound_type_variable "..")) + | Extensible -> row + | Univars -> { row with row_more = new_pre_univar () } + in + newty (Tvariant row) + | Ptyp_poly(vars, st) -> + begin_def(); + let new_univars = List.map (fun name -> name, newvar()) vars in + let old_univars = !univars in + univars := new_univars @ !univars; + let ty = transl_type env policy st in + univars := old_univars; + end_def(); + generalize ty; + let ty_list = + List.fold_left + (fun tyl (name, ty1) -> + let v = Btype.proxy ty1 in + if deep_occur v ty then begin + if v.level <> Btype.generic_level || v.desc <> Tvar then + raise (Error (styp.ptyp_loc, Cannot_quantify (name, v))); + v.desc <- Tunivar; + v :: tyl + end else tyl) + [] new_univars + in + let ty' = Btype.newgenty (Tpoly(ty, List.rev ty_list)) in + unify_var env (newvar()) ty'; + ty' + +and transl_fields env policy = + function + [] -> + newty Tnil + | ({pfield_desc = Pfield_var} as pf)::_ -> + begin match policy with + Fixed -> raise (Error (pf.pfield_loc, Unbound_type_variable "..")) + | Extensible -> newvar () + | Univars -> new_pre_univar () + end + | {pfield_desc = Pfield(s, e)}::l -> + let ty1 = transl_type env policy e in + let ty2 = transl_fields env policy l in + newty (Tfield (s, Fpresent, ty1, ty2)) + + +(* Make the rows "fixed" in this type, to make universal check easier *) +let rec make_fixed_univars ty = + let ty = repr ty in + if ty.level >= Btype.lowest_level then begin + Btype.mark_type_node ty; + match ty.desc with + | Tvariant row -> + let row = Btype.row_repr row in + if (Btype.row_more row).desc = Tunivar then + ty.desc <- Tvariant + {row with row_fixed=true; + row_fields = List.map + (fun (s,f as p) -> match Btype.row_field_repr f with + Reither (c, tl, m, r) -> s, Reither (c, tl, true, r) + | _ -> p) + row.row_fields}; + Btype.iter_row make_fixed_univars row + | _ -> + Btype.iter_type_expr make_fixed_univars ty + end + +let make_fixed_univars ty = + make_fixed_univars ty; + Btype.unmark_type ty + +let globalize_used_variables env fixed = + let r = ref [] in + Tbl.iter + (fun name (ty, loc) -> + let v = new_global_var () in + let snap = Btype.snapshot () in + if try unify env v ty; true with _ -> Btype.backtrack snap; false + then try + r := (loc, v, Tbl.find name !type_variables) :: !r + with Not_found -> + if fixed && (repr ty).desc = Tvar then + raise(Error(loc, Unbound_type_variable ("'"^name))); + let v2 = new_global_var () in + r := (loc, v, v2) :: !r; + type_variables := Tbl.add name v2 !type_variables) + !used_variables; + used_variables := Tbl.empty; + fun () -> + List.iter + (function (loc, t1, t2) -> + try unify env t1 t2 with Unify trace -> + raise (Error(loc, Type_mismatch trace))) + !r + +let transl_simple_type env fixed styp = + univars := []; used_variables := Tbl.empty; + let typ = transl_type env (if fixed then Fixed else Extensible) styp in + globalize_used_variables env fixed (); + make_fixed_univars typ; + typ + +let transl_simple_type_univars env styp = + univars := []; used_variables := Tbl.empty; pre_univars := []; + begin_def (); + let typ = transl_type env Univars styp in + (* Only keep already global variables in used_variables *) + let new_variables = !used_variables in + used_variables := Tbl.empty; + Tbl.iter + (fun name p -> + if Tbl.mem name !type_variables then + used_variables := Tbl.add name p !used_variables) + new_variables; + globalize_used_variables env false (); + end_def (); + generalize typ; + let univs = + List.fold_left + (fun acc v -> + let v = repr v in + if v.level <> Btype.generic_level || v.desc <> Tvar then acc + else (v.desc <- Tunivar ; v :: acc)) + [] !pre_univars + in + make_fixed_univars typ; + instance (Btype.newgenty (Tpoly (typ, univs))) + +let transl_simple_type_delayed env styp = + univars := []; used_variables := Tbl.empty; + let typ = transl_type env Extensible styp in + (typ, globalize_used_variables env false) + +let transl_type_scheme env styp = + reset_type_variables(); + begin_def(); + let typ = transl_simple_type env false styp in + end_def(); + generalize typ; + typ + +(* Error report *) + +open Format +open Printtyp + +let report_error ppf = function + | Unbound_type_variable name -> + fprintf ppf "Unbound type parameter %s" name + | Unbound_type_constructor lid -> + fprintf ppf "Unbound type constructor %a" longident lid + | Unbound_type_constructor_2 p -> + fprintf ppf "The type constructor@ %a@ is not yet completely defined" + path p + | Type_arity_mismatch(lid, expected, provided) -> + fprintf ppf + "@[The type constructor %a@ expects %i argument(s),@ \ + but is here applied to %i argument(s)@]" + longident lid expected provided + | Bound_type_variable name -> + fprintf ppf "Already bound type parameter '%s" name + | Recursive_type -> + fprintf ppf "This type is recursive" + | Unbound_class lid -> + fprintf ppf "Unbound class %a" longident lid + | Unbound_row_variable lid -> + fprintf ppf "Unbound row variable in #%a" longident lid + | Type_mismatch trace -> + Printtyp.unification_error true trace + (function ppf -> + fprintf ppf "This type") + ppf + (function ppf -> + fprintf ppf "should be an instance of type") + | Alias_type_mismatch trace -> + Printtyp.unification_error true trace + (function ppf -> + fprintf ppf "This alias is bound to type") + ppf + (function ppf -> + fprintf ppf "but is used as an instance of type") + | Present_has_conjunction l -> + fprintf ppf "The present constructor %s has a conjunctive type" l + | Present_has_no_type l -> + fprintf ppf "The present constructor %s has no type" l + | Constructor_mismatch (ty, ty') -> + Printtyp.reset_and_mark_loops_list [ty; ty']; + fprintf ppf "@[<hov>%s %a@ %s@ %a@]" + "This variant type contains a constructor" + Printtyp.type_expr ty + "which should be" + Printtyp.type_expr ty' + | Not_a_variant ty -> + Printtyp.reset_and_mark_loops ty; + fprintf ppf "@[The type %a@ is not a polymorphic variant type@]" + Printtyp.type_expr ty + | Variant_tags (lab1, lab2) -> + fprintf ppf + "Variant tags `%s@ and `%s have same hash value.@ Change one of them." + lab1 lab2 + | Invalid_variable_name name -> + fprintf ppf "The type variable name %s is not allowed in programs" name + | Cannot_quantify (name, v) -> + fprintf ppf "This type scheme cannot quantify '%s :@ %s." name + (if v.desc = Tvar then "it escapes this scope" else + if v.desc = Tunivar then "it is aliased to another variable" + else "it is not a variable") diff --git a/typing/typetexp.mli b/typing/typetexp.mli new file mode 100644 index 0000000..cfae61e --- /dev/null +++ b/typing/typetexp.mli @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: typetexp.mli,v 1.19 2003-05-19 09:21:17 garrigue Exp $ *) + +(* Typechecking of type expressions for the core language *) + +open Format;; + +val transl_simple_type: + Env.t -> bool -> Parsetree.core_type -> Types.type_expr +val transl_simple_type_univars: + Env.t -> Parsetree.core_type -> Types.type_expr +val transl_simple_type_delayed: + Env.t -> Parsetree.core_type -> Types.type_expr * (unit -> unit) + (* Translate a type, but leave type variables unbound. Returns + the type and a function that binds the type variable. *) +val transl_type_scheme: + Env.t -> Parsetree.core_type -> Types.type_expr +val reset_type_variables: unit -> unit +val enter_type_variable: bool -> Location.t -> string -> Types.type_expr +val type_variable: Location.t -> string -> Types.type_expr + +type variable_context +val narrow: unit -> variable_context +val widen: variable_context -> unit + +exception Already_bound + +type error = + Unbound_type_variable of string + | Unbound_type_constructor of Longident.t + | Unbound_type_constructor_2 of Path.t + | Type_arity_mismatch of Longident.t * int * int + | Bound_type_variable of string + | Recursive_type + | Unbound_class of Longident.t + | Unbound_row_variable of Longident.t + | Type_mismatch of (Types.type_expr * Types.type_expr) list + | Alias_type_mismatch of (Types.type_expr * Types.type_expr) list + | Present_has_conjunction of string + | Present_has_no_type of string + | Constructor_mismatch of Types.type_expr * Types.type_expr + | Not_a_variant of Types.type_expr + | Variant_tags of string * string + | Invalid_variable_name of string + | Cannot_quantify of string * Types.type_expr + +exception Error of Location.t * error + +val report_error: formatter -> error -> unit diff --git a/typing/unused_var.ml b/typing/unused_var.ml new file mode 100644 index 0000000..910bd9a --- /dev/null +++ b/typing/unused_var.ml @@ -0,0 +1,263 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: unused_var.ml,v 1.7 2008-07-09 13:03:38 mauny Exp $ *) + +open Parsetree + +let silent v = String.length v > 0 && v.[0] = '_';; + +let add_vars tbl (vll1, vll2) = + let add_var (v, _loc, used) = Hashtbl.add tbl v used in + List.iter add_var vll1; + List.iter add_var vll2; +;; + +let rm_vars tbl (vll1, vll2) = + let rm_var (v, _, _) = Hashtbl.remove tbl v in + List.iter rm_var vll1; + List.iter rm_var vll2; +;; + +let w_suspicious x = Warnings.Unused_var x;; +let w_strict x = Warnings.Unused_var_strict x;; + +let check_rm_vars ppf tbl (vlul_pat, vlul_as) = + let check_rm_var kind (v, loc, used) = + if not !used && not (silent v) + then Location.print_warning loc ppf (kind v); + Hashtbl.remove tbl v; + in + List.iter (check_rm_var w_strict) vlul_pat; + List.iter (check_rm_var w_suspicious) vlul_as; +;; + +let check_rm_let ppf tbl vlulpl = + let check_rm_one flag (v, loc, used) = + Hashtbl.remove tbl v; + flag && (silent v || not !used) + in + let warn_var w_kind (v, loc, used) = + if not (silent v) && not !used + then Location.print_warning loc ppf (w_kind v) + in + let check_rm_pat (def, def_as) = + let def_unused = List.fold_left check_rm_one true def in + let all_unused = List.fold_left check_rm_one def_unused def_as in + List.iter (warn_var (if all_unused then w_suspicious else w_strict)) def; + List.iter (warn_var w_suspicious) def_as; + in + List.iter check_rm_pat vlulpl; +;; + +let rec get_vars ((vacc, asacc) as acc) p = + match p.ppat_desc with + | Ppat_any -> acc + | Ppat_var v -> ((v, p.ppat_loc, ref false) :: vacc, asacc) + | Ppat_alias (pp, v) -> + get_vars (vacc, ((v, p.ppat_loc, ref false) :: asacc)) pp + | Ppat_constant _ -> acc + | Ppat_tuple pl -> List.fold_left get_vars acc pl + | Ppat_construct (_, po, _) -> get_vars_option acc po + | Ppat_variant (_, po) -> get_vars_option acc po + | Ppat_record ipl -> + List.fold_left (fun a (_, p) -> get_vars a p) acc ipl + | Ppat_array pl -> List.fold_left get_vars acc pl + | Ppat_or (p1, _p2) -> get_vars acc p1 + | Ppat_lazy p -> get_vars acc p + | Ppat_constraint (pp, _) -> get_vars acc pp + | Ppat_type _ -> acc + +and get_vars_option acc po = + match po with + | Some p -> get_vars acc p + | None -> acc +;; + +let get_pel_vars pel = + List.map (fun (p, _) -> get_vars ([], []) p) pel +;; + +let rec structure ppf tbl l = + List.iter (structure_item ppf tbl) l + +and structure_item ppf tbl s = + match s.pstr_desc with + | Pstr_eval e -> expression ppf tbl e; + | Pstr_value (recflag, pel) -> let_pel ppf tbl recflag pel None; + | Pstr_primitive _ -> () + | Pstr_type _ -> () + | Pstr_exception _ -> () + | Pstr_exn_rebind _ -> () + | Pstr_module (_, me) -> module_expr ppf tbl me; + | Pstr_recmodule stml -> + List.iter (fun (_, _, me) -> module_expr ppf tbl me) stml; + | Pstr_modtype _ -> () + | Pstr_open _ -> () + | Pstr_class cdl -> List.iter (class_declaration ppf tbl) cdl; + | Pstr_class_type _ -> () + | Pstr_include _ -> () + +and expression ppf tbl e = + match e.pexp_desc with + | Pexp_ident (Longident.Lident id) -> + begin try (Hashtbl.find tbl id) := true; + with Not_found -> () + end; + | Pexp_ident _ -> () + | Pexp_constant _ -> () + | Pexp_let (recflag, pel, e) -> + let_pel ppf tbl recflag pel (Some (fun ppf tbl -> expression ppf tbl e)); + | Pexp_function (_, eo, pel) -> + expression_option ppf tbl eo; + match_pel ppf tbl pel; + | Pexp_apply (e, lel) -> + expression ppf tbl e; + List.iter (fun (_, e) -> expression ppf tbl e) lel; + | Pexp_match (e, pel) -> + expression ppf tbl e; + match_pel ppf tbl pel; + | Pexp_try (e, pel) -> + expression ppf tbl e; + match_pel ppf tbl pel; + | Pexp_tuple el -> List.iter (expression ppf tbl) el; + | Pexp_construct (_, eo, _) -> expression_option ppf tbl eo; + | Pexp_variant (_, eo) -> expression_option ppf tbl eo; + | Pexp_record (iel, eo) -> + List.iter (fun (_, e) -> expression ppf tbl e) iel; + expression_option ppf tbl eo; + | Pexp_field (e, _) -> expression ppf tbl e; + | Pexp_setfield (e1, _, e2) -> + expression ppf tbl e1; + expression ppf tbl e2; + | Pexp_array el -> List.iter (expression ppf tbl) el; + | Pexp_ifthenelse (e1, e2, eo) -> + expression ppf tbl e1; + expression ppf tbl e2; + expression_option ppf tbl eo; + | Pexp_sequence (e1, e2) -> + expression ppf tbl e1; + expression ppf tbl e2; + | Pexp_while (e1, e2) -> + expression ppf tbl e1; + expression ppf tbl e2; + | Pexp_for (id, e1, e2, _, e3) -> + expression ppf tbl e1; + expression ppf tbl e2; + let defined = ([ (id, e.pexp_loc, ref true) ], []) in + add_vars tbl defined; + expression ppf tbl e3; + check_rm_vars ppf tbl defined; + | Pexp_constraint (e, _, _) -> expression ppf tbl e; + | Pexp_when (e1, e2) -> + expression ppf tbl e1; + expression ppf tbl e2; + | Pexp_send (e, _) -> expression ppf tbl e; + | Pexp_new _ -> () + | Pexp_setinstvar (_, e) -> expression ppf tbl e; + | Pexp_override sel -> List.iter (fun (_, e) -> expression ppf tbl e) sel; + | Pexp_letmodule (_, me, e) -> + module_expr ppf tbl me; + expression ppf tbl e; + | Pexp_assert e -> expression ppf tbl e; + | Pexp_assertfalse -> () + | Pexp_lazy e -> expression ppf tbl e; + | Pexp_poly (e, _) -> expression ppf tbl e; + | Pexp_object cs -> class_structure ppf tbl cs; + +and expression_option ppf tbl eo = + match eo with + | Some e -> expression ppf tbl e; + | None -> () + +and let_pel ppf tbl recflag pel body = + match recflag with + | Asttypes.Recursive -> + let defined = get_pel_vars pel in + List.iter (add_vars tbl) defined; + List.iter (fun (_, e) -> expression ppf tbl e) pel; + begin match body with + | None -> + List.iter (rm_vars tbl) defined; + | Some f -> + f ppf tbl; + check_rm_let ppf tbl defined; + end; + | _ -> + List.iter (fun (_, e) -> expression ppf tbl e) pel; + begin match body with + | None -> () + | Some f -> + let defined = get_pel_vars pel in + List.iter (add_vars tbl) defined; + f ppf tbl; + check_rm_let ppf tbl defined; + end; + +and match_pel ppf tbl pel = + List.iter (match_pe ppf tbl) pel + +and match_pe ppf tbl (p, e) = + let defined = get_vars ([], []) p in + add_vars tbl defined; + expression ppf tbl e; + check_rm_vars ppf tbl defined; + +and module_expr ppf tbl me = + match me.pmod_desc with + | Pmod_ident _ -> () + | Pmod_structure s -> structure ppf tbl s + | Pmod_functor (_, _, me) -> module_expr ppf tbl me + | Pmod_apply (me1, me2) -> + module_expr ppf tbl me1; + module_expr ppf tbl me2; + | Pmod_constraint (me, _) -> module_expr ppf tbl me + +and class_declaration ppf tbl cd = class_expr ppf tbl cd.pci_expr + +and class_expr ppf tbl ce = + match ce.pcl_desc with + | Pcl_constr _ -> () + | Pcl_structure cs -> class_structure ppf tbl cs; + | Pcl_fun (_, _, _, ce) -> class_expr ppf tbl ce; + | Pcl_apply (ce, lel) -> + class_expr ppf tbl ce; + List.iter (fun (_, e) -> expression ppf tbl e) lel; + | Pcl_let (recflag, pel, ce) -> + let_pel ppf tbl recflag pel (Some (fun ppf tbl -> class_expr ppf tbl ce)); + | Pcl_constraint (ce, _) -> class_expr ppf tbl ce; + +and class_structure ppf tbl (p, cfl) = + let defined = get_vars ([], []) p in + add_vars tbl defined; + List.iter (class_field ppf tbl) cfl; + check_rm_vars ppf tbl defined; + +and class_field ppf tbl cf = + match cf with + | Pcf_inher (ce, _) -> class_expr ppf tbl ce; + | Pcf_val (_, _, e, _) -> expression ppf tbl e; + | Pcf_virt _ | Pcf_valvirt _ -> () + | Pcf_meth (_, _, e, _) -> expression ppf tbl e; + | Pcf_cstr _ -> () + | Pcf_let (recflag, pel, _) -> let_pel ppf tbl recflag pel None; + | Pcf_init e -> expression ppf tbl e; +;; + +let warn ppf ast = + if Warnings.is_active (w_suspicious "") || Warnings.is_active (w_strict "") + then begin + let tbl = Hashtbl.create 97 in + structure ppf tbl ast; + end; + ast +;; diff --git a/typing/unused_var.mli b/typing/unused_var.mli new file mode 100644 index 0000000..bf7901e --- /dev/null +++ b/typing/unused_var.mli @@ -0,0 +1,16 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Damien Doligez, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2004 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: unused_var.mli,v 1.2 2006-01-04 16:55:50 doligez Exp $ *) + +val warn : Format.formatter -> Parsetree.structure -> Parsetree.structure;; +(* Warn on unused variables; return the second argument. *) diff --git a/utils/.cvsignore b/utils/.cvsignore new file mode 100644 index 0000000..25b6d3b --- /dev/null +++ b/utils/.cvsignore @@ -0,0 +1 @@ +config.ml diff --git a/utils/ccomp.ml b/utils/ccomp.ml new file mode 100644 index 0000000..13ee9c2 --- /dev/null +++ b/utils/ccomp.ml @@ -0,0 +1,127 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ccomp.ml,v 1.29 2008-12-03 18:09:09 doligez Exp $ *) + +(* Compiling C files and building C libraries *) + +let command cmdline = + if !Clflags.verbose then begin + prerr_string "+ "; + prerr_string cmdline; + prerr_newline() + end; + Sys.command cmdline + +let run_command cmdline = ignore(command cmdline) + +(* Build @responsefile to work around Windows limitations on + command-line length *) +let build_diversion lst = + let (responsefile, oc) = Filename.open_temp_file "camlresp" "" in + List.iter (fun f -> Printf.fprintf oc "%s\n" f) lst; + close_out oc; + at_exit (fun () -> Misc.remove_file responsefile); + "@" ^ responsefile + +let quote_files lst = + let lst = List.filter (fun f -> f <> "") lst in + let quoted = List.map Filename.quote lst in + let s = String.concat " " quoted in + if String.length s >= 4096 && Sys.os_type = "Win32" + then build_diversion quoted + else s + +let quote_prefixed pr lst = + let lst = List.filter (fun f -> f <> "") lst in + let lst = List.map (fun f -> pr ^ f) lst in + quote_files lst + +let quote_optfile = function + | None -> "" + | Some f -> Filename.quote f + +let compile_file name = + command + (Printf.sprintf + "%s -c %s %s %s %s" + (match !Clflags.c_compiler with + | Some cc -> cc + | None -> + if !Clflags.native_code + then Config.native_c_compiler + else Config.bytecomp_c_compiler) + (String.concat " " (List.rev !Clflags.ccopts)) + (quote_prefixed "-I" (List.rev !Clflags.include_dirs)) + (Clflags.std_include_flag "-I") + (Filename.quote name)) + +let create_archive archive file_list = + Misc.remove_file archive; + let quoted_archive = Filename.quote archive in + match Config.ccomp_type with + "msvc" -> + command(Printf.sprintf "link /lib /nologo /out:%s %s" + quoted_archive (quote_files file_list)) + | _ -> + let r1 = + command(Printf.sprintf "ar rc %s %s" + quoted_archive (quote_files file_list)) in + if r1 <> 0 || String.length Config.ranlib = 0 + then r1 + else command(Config.ranlib ^ " " ^ quoted_archive) + +let expand_libname name = + if String.length name < 2 || String.sub name 0 2 <> "-l" + then name + else begin + let libname = + "lib" ^ String.sub name 2 (String.length name - 2) ^ Config.ext_lib in + try + Misc.find_in_path !Config.load_path libname + with Not_found -> + libname + end + +type link_mode = + | Exe + | Dll + | MainDll + | Partial + +let call_linker mode output_name files extra = + let files = quote_files files in + let cmd = + if mode = Partial then + Printf.sprintf "%s%s %s %s" + Config.native_pack_linker + (Filename.quote output_name) + files + extra + else + Printf.sprintf "%s -o %s %s %s %s %s %s %s" + (match !Clflags.c_compiler, mode with + | Some cc, _ -> cc + | None, Exe -> Config.mkexe + | None, Dll -> Config.mkdll + | None, MainDll -> Config.mkmaindll + | None, Partial -> assert false + ) + (Filename.quote output_name) + (if !Clflags.gprofile then Config.cc_profile else "") + "" (*(Clflags.std_include_flag "-I")*) + (quote_prefixed "-L" !Config.load_path) + files + extra + (String.concat " " (List.rev !Clflags.ccopts)) + in + command cmd = 0 diff --git a/utils/ccomp.mli b/utils/ccomp.mli new file mode 100644 index 0000000..e8fab71 --- /dev/null +++ b/utils/ccomp.mli @@ -0,0 +1,32 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: ccomp.mli,v 1.16 2008-01-11 16:13:18 doligez Exp $ *) + +(* Compiling C files and building C libraries *) + +val command: string -> int +val run_command: string -> unit +val compile_file: string -> int +val create_archive: string -> string list -> int +val expand_libname: string -> string +val quote_files: string list -> string +val quote_optfile: string option -> string +(*val make_link_options: string list -> string*) + +type link_mode = + | Exe + | Dll + | MainDll + | Partial + +val call_linker: link_mode -> string -> string list -> string -> bool diff --git a/utils/clflags.ml b/utils/clflags.ml new file mode 100644 index 0000000..a72028c --- /dev/null +++ b/utils/clflags.ml @@ -0,0 +1,92 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: clflags.ml,v 1.54 2008-12-03 18:09:09 doligez Exp $ *) + +(* Command-line parameters *) + +let objfiles = ref ([] : string list) (* .cmo and .cma files *) +and ccobjs = ref ([] : string list) (* .o, .a, .so and -cclib -lxxx *) +and dllibs = ref ([] : string list) (* .so and -dllib -lxxx *) + +let compile_only = ref false (* -c *) +and output_name = ref (None : string option) (* -o *) +and include_dirs = ref ([] : string list)(* -I *) +and no_std_include = ref false (* -nostdlib *) +and print_types = ref false (* -i *) +and make_archive = ref false (* -a *) +and debug = ref false (* -g *) +and fast = ref false (* -unsafe *) +and link_everything = ref false (* -linkall *) +and custom_runtime = ref false (* -custom *) +and output_c_object = ref false (* -output-obj *) +and ccopts = ref ([] : string list) (* -ccopt *) +and classic = ref false (* -nolabels *) +and nopervasives = ref false (* -nopervasives *) +and preprocessor = ref(None : string option) (* -pp *) +let annotations = ref false (* -annot *) +and use_threads = ref false (* -thread *) +and use_vmthreads = ref false (* -vmthread *) +and noassert = ref false (* -noassert *) +and verbose = ref false (* -verbose *) +and noprompt = ref false (* -noprompt *) +and init_file = ref (None : string option) (* -init *) +and use_prims = ref "" (* -use-prims ... *) +and use_runtime = ref "" (* -use-runtime ... *) +and principal = ref false (* -principal *) +and recursive_types = ref false (* -rectypes *) +and make_runtime = ref false (* -make_runtime *) +and gprofile = ref false (* -p *) +and c_compiler = ref (None: string option) (* -cc *) +and no_auto_link = ref false (* -noautolink *) +and dllpaths = ref ([] : string list) (* -dllpath *) +and make_package = ref false (* -pack *) +and for_package = ref (None: string option) (* -for-pack *) +let dump_parsetree = ref false (* -dparsetree *) +and dump_rawlambda = ref false (* -drawlambda *) +and dump_lambda = ref false (* -dlambda *) +and dump_instr = ref false (* -dinstr *) + +let keep_asm_file = ref false (* -S *) +let optimize_for_speed = ref true (* -compact *) + +and dump_cmm = ref false (* -dcmm *) +let dump_selection = ref false (* -dsel *) +let dump_live = ref false (* -dlive *) +let dump_spill = ref false (* -dspill *) +let dump_split = ref false (* -dsplit *) +let dump_scheduling = ref false (* -dscheduling *) +let dump_interf = ref false (* -dinterf *) +let dump_prefer = ref false (* -dprefer *) +let dump_regalloc = ref false (* -dalloc *) +let dump_reload = ref false (* -dreload *) +let dump_scheduling = ref false (* -dscheduling *) +let dump_linear = ref false (* -dlinear *) +let keep_startup_file = ref false (* -dstartup *) +let dump_combine = ref false (* -dcombine *) + +let native_code = ref false (* set to true under ocamlopt *) +let inline_threshold = ref 10 + +let dont_write_files = ref false (* set to true under ocamldoc *) + +let std_include_flag prefix = + if !no_std_include then "" + else (prefix ^ (Filename.quote Config.standard_library)) +;; + +let std_include_dir () = + if !no_std_include then [] else [Config.standard_library] +;; + +let shared = ref false (* -shared *) +let dlcode = ref true (* not -nodynlink *) diff --git a/utils/clflags.mli b/utils/clflags.mli new file mode 100644 index 0000000..6233076 --- /dev/null +++ b/utils/clflags.mli @@ -0,0 +1,76 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2005 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: clflags.mli,v 1.5 2008-12-03 18:09:09 doligez Exp $ *) + +val objfiles : string list ref +val ccobjs : string list ref +val dllibs : string list ref +val compile_only : bool ref +val output_name : string option ref +val include_dirs : string list ref +val no_std_include : bool ref +val print_types : bool ref +val make_archive : bool ref +val debug : bool ref +val fast : bool ref +val link_everything : bool ref +val custom_runtime : bool ref +val output_c_object : bool ref +val ccopts : string list ref +val classic : bool ref +val nopervasives : bool ref +val preprocessor : string option ref +val annotations : bool ref +val use_threads : bool ref +val use_vmthreads : bool ref +val noassert : bool ref +val verbose : bool ref +val noprompt : bool ref +val init_file : string option ref +val use_prims : string ref +val use_runtime : string ref +val principal : bool ref +val recursive_types : bool ref +val make_runtime : bool ref +val gprofile : bool ref +val c_compiler : string option ref +val no_auto_link : bool ref +val dllpaths : string list ref +val make_package : bool ref +val for_package : string option ref +val dump_parsetree : bool ref +val dump_rawlambda : bool ref +val dump_lambda : bool ref +val dump_instr : bool ref +val keep_asm_file : bool ref +val optimize_for_speed : bool ref +val dump_cmm : bool ref +val dump_selection : bool ref +val dump_live : bool ref +val dump_spill : bool ref +val dump_split : bool ref +val dump_interf : bool ref +val dump_prefer : bool ref +val dump_regalloc : bool ref +val dump_reload : bool ref +val dump_scheduling : bool ref +val dump_linear : bool ref +val keep_startup_file : bool ref +val dump_combine : bool ref +val native_code : bool ref +val inline_threshold : int ref +val dont_write_files : bool ref +val std_include_flag : string -> string +val std_include_dir : unit -> string list +val shared : bool ref +val dlcode : bool ref diff --git a/utils/config.mlbuild b/utils/config.mlbuild new file mode 100644 index 0000000..19baa18 --- /dev/null +++ b/utils/config.mlbuild @@ -0,0 +1,125 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: config.mlbuild,v 1.3 2007-11-27 12:22:59 ertai Exp $ *) + +(* The main OCaml version string has moved to ../VERSION *) +let version = Sys.ocaml_version + +module C = Myocamlbuild_config + +let standard_library_default = C.libdir + +let standard_library = + try + Sys.getenv "OCAMLLIB" + with Not_found -> + try + Sys.getenv "CAMLLIB" + with Not_found -> + standard_library_default + +let windows = + match Sys.os_type with + | "Win32" -> true + | _ -> false + +let sf = Printf.sprintf + +let standard_runtime = + if windows then "ocamlrun" + else C.bindir^"/ocamlrun" +let ccomp_type = C.ccomptype +let bytecomp_c_compiler = sf "%s %s %s" C.bytecc C.bytecccompopts C.sharedcccompopts +let bytecomp_c_linker = if windows then "flexlink" else sf "%s %s" C.bytecc C.bytecclinkopts +let bytecomp_c_libraries = C.bytecclibs +let native_c_compiler = sf "%s %s" C.nativecc C.nativecccompopts +let native_c_linker = if windows then "flexlink" else sf "%s %s" C.nativecc C.nativecclinkopts +let native_c_libraries = C.nativecclibs +let native_pack_linker = C.packld +let ranlib = C.ranlibcmd +let cc_profile = C.cc_profile +let mkdll = C.mkdll +let mkexe = C.mkexe +let mkmaindll = C.mkmaindll + +let exec_magic_number = "Caml1999X008" +and cmi_magic_number = "Caml1999I011" +and cmo_magic_number = "Caml1999O006" +and cma_magic_number = "Caml1999A007" +and cmx_magic_number = "Caml1999Y011" +and cmxa_magic_number = "Caml1999Z010" +and ast_impl_magic_number = "Caml1999M012" +and ast_intf_magic_number = "Caml1999N011" + +let load_path = ref ([] : string list) + +let interface_suffix = ref ".mli" + +let max_tag = 245 +(* This is normally the same as in obj.ml, but we have to define it + separately because it can differ when we're in the middle of a + bootstrapping phase. *) +let lazy_tag = 246 + +let max_young_wosize = 256 +let stack_threshold = 256 (* see byterun/config.h *) + +let architecture = C.arch +let model = C.model +let system = C.system + +let asm = C.asm + +let ext_obj = C.ext_obj +let ext_asm = C.ext_asm +let ext_lib = C.ext_lib +let ext_dll = C.ext_dll + +let default_executable_name = + match Sys.os_type with + "Unix" -> "a.out" + | "Win32" | "Cygwin" -> "camlprog.exe" + | _ -> "camlprog" + +let systhread_supported = C.systhread_support;; + +let print_config oc = + let p name valu = Printf.fprintf oc "%s: %s\n" name valu in + let p_bool name valu = Printf.fprintf oc "%s: %B\n" name valu in + p "version" version; + p "standard_library_default" standard_library_default; + p "standard_library" standard_library; + p "standard_runtime" standard_runtime; + p "ccomp_type" ccomp_type; + p "bytecomp_c_compiler" bytecomp_c_compiler; + p "bytecomp_c_linker" bytecomp_c_linker; + p "bytecomp_c_libraries" bytecomp_c_libraries; + p "native_c_compiler" native_c_compiler; + p "native_c_linker" native_c_linker; + p "native_c_libraries" native_c_libraries; + p "native_pack_linker" native_pack_linker; + p "ranlib" ranlib; + p "cc_profile" cc_profile; + p "architecture" architecture; + p "model" model; + p "system" system; + p "asm" asm; + p "ext_obj" ext_obj; + p "ext_asm" ext_asm; + p "ext_lib" ext_lib; + p "ext_dll" ext_dll; + p "os_type" Sys.os_type; + p "default_executable_name" default_executable_name; + p_bool "systhread_supported" systhread_supported; + flush oc; +;; diff --git a/utils/config.mli b/utils/config.mli new file mode 100644 index 0000000..c2013a4 --- /dev/null +++ b/utils/config.mli @@ -0,0 +1,115 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: config.mli,v 1.41 2008-04-16 06:50:31 frisch Exp $ *) + +(* System configuration *) + +val version: string + (* The current version number of the system *) + +val standard_library: string + (* The directory containing the standard libraries *) +val standard_runtime: string + (* The full path to the standard bytecode interpreter ocamlrun *) +val ccomp_type: string + (* The "kind" of the C compiler: one of + "cc" (for Unix-style C compilers) + "msvc" (Microsoft Visual C++) + "mrc" (Macintosh MPW) *) +val bytecomp_c_compiler: string + (* The C compiler to use for compiling C files + with the bytecode compiler *) +val bytecomp_c_libraries: string + (* The C libraries to link with custom runtimes *) +val native_c_compiler: string + (* The C compiler to use for compiling C files + with the native-code compiler *) +val native_c_libraries: string + (* The C libraries to link with native-code programs *) +val native_pack_linker: string + (* The linker to use for packaging (ocamlopt -pack) and for partial links + (ocamlopt -output-obj). *) +val mkdll: string + (* The linker command line to build dynamic libraries. *) +val mkexe: string + (* The linker command line to build executables. *) +val mkmaindll: string + (* The linker command line to build main programs as dlls. *) +val ranlib: string + (* Command to randomize a library, or "" if not needed *) +val cc_profile : string + (* The command line option to the C compiler to enable profiling. *) + +val load_path: string list ref + (* Directories in the search path for .cmi and .cmo files *) + +val interface_suffix: string ref + (* Suffix for interface file names *) + +val exec_magic_number: string + (* Magic number for bytecode executable files *) +val cmi_magic_number: string + (* Magic number for compiled interface files *) +val cmo_magic_number: string + (* Magic number for object bytecode files *) +val cma_magic_number: string + (* Magic number for archive files *) +val cmx_magic_number: string + (* Magic number for compilation unit descriptions *) +val cmxa_magic_number: string + (* Magic number for libraries of compilation unit descriptions *) +val ast_intf_magic_number: string + (* Magic number for file holding an interface syntax tree *) +val ast_impl_magic_number: string + (* Magic number for file holding an implementation syntax tree *) + +val max_tag: int + (* Biggest tag that can be stored in the header of a regular block. *) +val lazy_tag : int + (* Normally the same as Obj.lazy_tag. Separate definition because + of technical reasons for bootstrapping. *) +val max_young_wosize: int + (* Maximal size of arrays that are directly allocated in the + minor heap *) +val stack_threshold: int + (* Size in words of safe area at bottom of VM stack, + see byterun/config.h *) + +val architecture: string + (* Name of processor type for the native-code compiler *) +val model: string + (* Name of processor submodel for the native-code compiler *) +val system: string + (* Name of operating system for the native-code compiler *) + +val asm: string + (* The assembler (and flags) to use for assembling + ocamlopt-generated code. *) + +val ext_obj: string + (* Extension for object files, e.g. [.o] under Unix. *) +val ext_asm: string + (* Extension for assembler files, e.g. [.s] under Unix. *) +val ext_lib: string + (* Extension for library files, e.g. [.a] under Unix. *) +val ext_dll: string + (* Extension for dynamically-loaded libraries, e.g. [.so] under Unix.*) + +val default_executable_name: string + (* Name of executable produced by linking if none is given with -o, + e.g. [a.out] under Unix. *) + +val systhread_supported : bool + (* Whether the system thread library is implemented *) + +val print_config : out_channel -> unit;; diff --git a/utils/config.mlp b/utils/config.mlp new file mode 100644 index 0000000..a30b456 --- /dev/null +++ b/utils/config.mlp @@ -0,0 +1,110 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: config.mlp,v 1.208 2008-04-16 06:50:31 frisch Exp $ *) + +(* The main OCaml version string has moved to ../VERSION *) +let version = Sys.ocaml_version + +let standard_library_default = "%%LIBDIR%%" + +let standard_library = + try + Sys.getenv "OCAMLLIB" + with Not_found -> + try + Sys.getenv "CAMLLIB" + with Not_found -> + standard_library_default + +let standard_runtime = "%%BYTERUN%%" +let ccomp_type = "%%CCOMPTYPE%%" +let bytecomp_c_compiler = "%%BYTECC%%" +let bytecomp_c_libraries = "%%BYTECCLIBS%%" +let native_c_compiler = "%%NATIVECC%%" +let native_c_libraries = "%%NATIVECCLIBS%%" +let native_pack_linker = "%%PACKLD%%" +let ranlib = "%%RANLIBCMD%%" +let cc_profile = "%%CC_PROFILE%%" +let mkdll = "%%MKDLL%%" +let mkexe = "%%MKEXE%%" +let mkmaindll = "%%MKMAINDLL%%" + +let exec_magic_number = "Caml1999X008" +and cmi_magic_number = "Caml1999I011" +and cmo_magic_number = "Caml1999O006" +and cma_magic_number = "Caml1999A007" +and cmx_magic_number = "Caml1999Y011" +and cmxa_magic_number = "Caml1999Z010" +and ast_impl_magic_number = "Caml1999M012" +and ast_intf_magic_number = "Caml1999N011" + +let load_path = ref ([] : string list) + +let interface_suffix = ref ".mli" + +let max_tag = 245 +(* This is normally the same as in obj.ml, but we have to define it + separately because it can differ when we're in the middle of a + bootstrapping phase. *) +let lazy_tag = 246 + +let max_young_wosize = 256 +let stack_threshold = 256 (* see byterun/config.h *) + +let architecture = "%%ARCH%%" +let model = "%%MODEL%%" +let system = "%%SYSTEM%%" + +let asm = "%%ASM%%" + +let ext_obj = "%%EXT_OBJ%%" +let ext_asm = "%%EXT_ASM%%" +let ext_lib = "%%EXT_LIB%%" +let ext_dll = "%%EXT_DLL%%" + +let default_executable_name = + match Sys.os_type with + "Unix" -> "a.out" + | "Win32" | "Cygwin" -> "camlprog.exe" + | _ -> "camlprog" + +let systhread_supported = %%SYSTHREAD_SUPPORT%%;; + +let print_config oc = + let p name valu = Printf.fprintf oc "%s: %s\n" name valu in + let p_bool name valu = Printf.fprintf oc "%s: %B\n" name valu in + p "version" version; + p "standard_library_default" standard_library_default; + p "standard_library" standard_library; + p "standard_runtime" standard_runtime; + p "ccomp_type" ccomp_type; + p "bytecomp_c_compiler" bytecomp_c_compiler; + p "bytecomp_c_libraries" bytecomp_c_libraries; + p "native_c_compiler" native_c_compiler; + p "native_c_libraries" native_c_libraries; + p "native_pack_linker" native_pack_linker; + p "ranlib" ranlib; + p "cc_profile" cc_profile; + p "architecture" architecture; + p "model" model; + p "system" system; + p "asm" asm; + p "ext_obj" ext_obj; + p "ext_asm" ext_asm; + p "ext_lib" ext_lib; + p "ext_dll" ext_dll; + p "os_type" Sys.os_type; + p "default_executable_name" default_executable_name; + p_bool "systhread_supported" systhread_supported; + flush oc; +;; diff --git a/utils/consistbl.ml b/utils/consistbl.ml new file mode 100644 index 0000000..59b0357 --- /dev/null +++ b/utils/consistbl.ml @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: consistbl.ml,v 1.2 2002-11-18 10:41:26 xleroy Exp $ *) + +(* Consistency tables: for checking consistency of module CRCs *) + +type t = (string, Digest.t * string) Hashtbl.t + +let create () = Hashtbl.create 13 + +let clear = Hashtbl.clear + +exception Inconsistency of string * string * string + +exception Not_available of string + +let check tbl name crc source = + try + let (old_crc, old_source) = Hashtbl.find tbl name in + if crc <> old_crc then raise(Inconsistency(name, source, old_source)) + with Not_found -> + Hashtbl.add tbl name (crc, source) + +let check_noadd tbl name crc source = + try + let (old_crc, old_source) = Hashtbl.find tbl name in + if crc <> old_crc then raise(Inconsistency(name, source, old_source)) + with Not_found -> + raise (Not_available name) + +let set tbl name crc source = Hashtbl.add tbl name (crc, source) + +let source tbl name = snd (Hashtbl.find tbl name) + +let extract tbl = + Hashtbl.fold (fun name (crc, auth) accu -> (name, crc) :: accu) tbl [] + +let filter p tbl = + let to_remove = ref [] in + Hashtbl.iter + (fun name (crc, auth) -> + if not (p name) then to_remove := name :: !to_remove) + tbl; + List.iter + (fun name -> + while Hashtbl.mem tbl name do Hashtbl.remove tbl name done) + !to_remove diff --git a/utils/consistbl.mli b/utils/consistbl.mli new file mode 100644 index 0000000..45baaa9 --- /dev/null +++ b/utils/consistbl.mli @@ -0,0 +1,60 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: consistbl.mli,v 1.2 2002-11-18 10:41:26 xleroy Exp $ *) + +(* Consistency tables: for checking consistency of module CRCs *) + +type t + +val create: unit -> t + +val clear: t -> unit + +val check: t -> string -> Digest.t -> string -> unit + (* [check tbl name crc source] + checks consistency of ([name], [crc]) with infos previously + stored in [tbl]. If no CRC was previously associated with + [name], record ([name], [crc]) in [tbl]. + [source] is the name of the file from which the information + comes from. This is used for error reporting. *) + +val check_noadd: t -> string -> Digest.t -> string -> unit + (* Same as [check], but raise [Not_available] if no CRC was previously + associated with [name]. *) + +val set: t -> string -> Digest.t -> string -> unit + (* [set tbl name crc source] forcefully associates [name] with + [crc] in [tbl], even if [name] already had a different CRC + associated with [name] in [tbl]. *) + +val source: t -> string -> string + (* [source tbl name] returns the file name associated with [name] + if the latter has an associated CRC in [tbl]. + Raise [Not_found] otherwise. *) + +val extract: t -> (string * Digest.t) list + (* Return all bindings ([name], [crc]) contained in the given + table. *) + +val filter: (string -> bool) -> t -> unit + (* [filter pred tbl] removes from [tbl] table all (name, CRC) pairs + such that [pred name] is [false]. *) + +exception Inconsistency of string * string * string + (* Raised by [check] when a CRC mismatch is detected. + First string is the name of the compilation unit. + Second string is the source that caused the inconsistency. + Third string is the source that set the CRC. *) + +exception Not_available of string + (* Raised by [check_noadd] when a name doesn't have an associated CRC. *) diff --git a/utils/misc.ml b/utils/misc.ml new file mode 100644 index 0000000..2c06af3 --- /dev/null +++ b/utils/misc.ml @@ -0,0 +1,197 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: misc.ml,v 1.35 2007-02-23 13:44:51 ertai Exp $ *) + +(* Errors *) + +exception Fatal_error + +let fatal_error msg = + prerr_string ">> Fatal error: "; prerr_endline msg; raise Fatal_error + +(* Exceptions *) + +let try_finally f1 f2 = + try + let result = f1 () in + f2 (); + result + with x -> f2 (); raise x +;; + +(* List functions *) + +let rec map_end f l1 l2 = + match l1 with + [] -> l2 + | hd::tl -> f hd :: map_end f tl l2 + +let rec map_left_right f = function + [] -> [] + | hd::tl -> let res = f hd in res :: map_left_right f tl + +let rec for_all2 pred l1 l2 = + match (l1, l2) with + ([], []) -> true + | (hd1::tl1, hd2::tl2) -> pred hd1 hd2 && for_all2 pred tl1 tl2 + | (_, _) -> false + +let rec replicate_list elem n = + if n <= 0 then [] else elem :: replicate_list elem (n-1) + +let rec list_remove x = function + [] -> [] + | hd :: tl -> + if hd = x then tl else hd :: list_remove x tl + +let rec split_last = function + [] -> assert false + | [x] -> ([], x) + | hd :: tl -> + let (lst, last) = split_last tl in + (hd :: lst, last) + +let rec samelist pred l1 l2 = + match (l1, l2) with + | ([], []) -> true + | (hd1 :: tl1, hd2 :: tl2) -> pred hd1 hd2 && samelist pred tl1 tl2 + | (_, _) -> false + +(* Options *) + +let may f = function + Some x -> f x + | None -> () + +let may_map f = function + Some x -> Some (f x) + | None -> None + +(* File functions *) + +let find_in_path path name = + if not (Filename.is_implicit name) then + if Sys.file_exists name then name else raise Not_found + else begin + let rec try_dir = function + [] -> raise Not_found + | dir::rem -> + let fullname = Filename.concat dir name in + if Sys.file_exists fullname then fullname else try_dir rem + in try_dir path + end + +let find_in_path_uncap path name = + let uname = String.uncapitalize name in + let rec try_dir = function + [] -> raise Not_found + | dir::rem -> + let fullname = Filename.concat dir name + and ufullname = Filename.concat dir uname in + if Sys.file_exists ufullname then ufullname + else if Sys.file_exists fullname then fullname + else try_dir rem + in try_dir path + +let remove_file filename = + try + Sys.remove filename + with Sys_error msg -> + () + +(* Expand a -I option: if it starts with +, make it relative to the standard + library directory *) + +let expand_directory alt s = + if String.length s > 0 && s.[0] = '+' + then Filename.concat alt + (String.sub s 1 (String.length s - 1)) + else s + +(* Hashtable functions *) + +let create_hashtable size init = + let tbl = Hashtbl.create size in + List.iter (fun (key, data) -> Hashtbl.add tbl key data) init; + tbl + +(* File copy *) + +let copy_file ic oc = + let buff = String.create 0x1000 in + let rec copy () = + let n = input ic buff 0 0x1000 in + if n = 0 then () else (output oc buff 0 n; copy()) + in copy() + +let copy_file_chunk ic oc len = + let buff = String.create 0x1000 in + let rec copy n = + if n <= 0 then () else begin + let r = input ic buff 0 (min n 0x1000) in + if r = 0 then raise End_of_file else (output oc buff 0 r; copy(n-r)) + end + in copy len + +(* Integer operations *) + +let rec log2 n = + if n <= 1 then 0 else 1 + log2(n asr 1) + +let align n a = + if n >= 0 then (n + a - 1) land (-a) else n land (-a) + +let no_overflow_add a b = (a lxor b) lor (a lxor (lnot (a+b))) < 0 + +let no_overflow_sub a b = (a lxor (lnot b)) lor (b lxor (a-b)) < 0 + +let no_overflow_lsl a = min_int asr 1 <= a && a <= max_int asr 1 + +(* String operations *) + +let chop_extension_if_any fname = + try Filename.chop_extension fname with Invalid_argument _ -> fname + +let chop_extensions file = + let dirname = Filename.dirname file and basename = Filename.basename file in + try + let pos = String.index basename '.' in + let basename = String.sub basename 0 pos in + if Filename.is_implicit file && dirname = Filename.current_dir_name then + basename + else + Filename.concat dirname basename + with Not_found -> file + +let search_substring pat str start = + let rec search i j = + if j >= String.length pat then i + else if i + j >= String.length str then raise Not_found + else if str.[i + j] = pat.[j] then search i (j+1) + else search (i+1) 0 + in search start 0 + +let rev_split_words s = + let rec split1 res i = + if i >= String.length s then res else begin + match s.[i] with + ' ' | '\t' | '\r' | '\n' -> split1 res (i+1) + | _ -> split2 res i (i+1) + end + and split2 res i j = + if j >= String.length s then String.sub s i (j-i) :: res else begin + match s.[j] with + ' ' | '\t' | '\r' | '\n' -> split1 (String.sub s i (j-i) :: res) (j+1) + | _ -> split2 res i (j+1) + end + in split1 [] 0 diff --git a/utils/misc.mli b/utils/misc.mli new file mode 100644 index 0000000..9c09673 --- /dev/null +++ b/utils/misc.mli @@ -0,0 +1,104 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: misc.mli,v 1.26 2007-02-23 13:44:51 ertai Exp $ *) + +(* Miscellaneous useful types and functions *) + +val fatal_error: string -> 'a +exception Fatal_error + +val try_finally : (unit -> 'a) -> (unit -> unit) -> 'a;; + +val map_end: ('a -> 'b) -> 'a list -> 'b list -> 'b list + (* [map_end f l t] is [map f l @ t], just more efficient. *) +val map_left_right: ('a -> 'b) -> 'a list -> 'b list + (* Like [List.map], with guaranteed left-to-right evaluation order *) +val for_all2: ('a -> 'b -> bool) -> 'a list -> 'b list -> bool + (* Same as [List.for_all] but for a binary predicate. + In addition, this [for_all2] never fails: given two lists + with different lengths, it returns false. *) +val replicate_list: 'a -> int -> 'a list + (* [replicate_list elem n] is the list with [n] elements + all identical to [elem]. *) +val list_remove: 'a -> 'a list -> 'a list + (* [list_remove x l] returns a copy of [l] with the first + element equal to [x] removed. *) +val split_last: 'a list -> 'a list * 'a + (* Return the last element and the other elements of the given list. *) +val samelist: ('a -> 'a -> bool) -> 'a list -> 'a list -> bool + (* Like [List.for_all2] but returns [false] if the two + lists have different length. *) + +val may: ('a -> unit) -> 'a option -> unit +val may_map: ('a -> 'b) -> 'a option -> 'b option + +val find_in_path: string list -> string -> string + (* Search a file in a list of directories. *) +val find_in_path_uncap: string list -> string -> string + (* Same, but search also for uncapitalized name, i.e. + if name is Foo.ml, allow /path/Foo.ml and /path/foo.ml + to match. *) +val remove_file: string -> unit + (* Delete the given file if it exists. Never raise an error. *) +val expand_directory: string -> string -> string + (* [expand_directory alt file] eventually expands a [+] at the + beginning of file into [alt] (an alternate root directory) *) + +val create_hashtable: int -> ('a * 'b) list -> ('a, 'b) Hashtbl.t + (* Create a hashtable of the given size and fills it with the + given bindings. *) + +val copy_file: in_channel -> out_channel -> unit + (* [copy_file ic oc] reads the contents of file [ic] and copies + them to [oc]. It stops when encountering EOF on [ic]. *) +val copy_file_chunk: in_channel -> out_channel -> int -> unit + (* [copy_file_chunk ic oc n] reads [n] bytes from [ic] and copies + them to [oc]. It raises [End_of_file] when encountering + EOF on [ic]. *) + +val log2: int -> int + (* [log2 n] returns [s] such that [n = 1 lsl s] + if [n] is a power of 2*) +val align: int -> int -> int + (* [align n a] rounds [n] upwards to a multiple of [a] + (a power of 2). *) +val no_overflow_add: int -> int -> bool + (* [no_overflow_add n1 n2] returns [true] if the computation of + [n1 + n2] does not overflow. *) +val no_overflow_sub: int -> int -> bool + (* [no_overflow_add n1 n2] returns [true] if the computation of + [n1 - n2] does not overflow. *) +val no_overflow_lsl: int -> bool + (* [no_overflow_add n] returns [true] if the computation of + [n lsl 1] does not overflow. *) + +val chop_extension_if_any: string -> string + (* Like Filename.chop_extension but returns the initial file + name if it has no extension *) + +val chop_extensions: string -> string + (* Return the given file name without its extensions. The extensions + is the longest suffix starting with a period and not including + a directory separator, [.xyz.uvw] for instance. + + Return the given name if it does not contain an extension. *) + +val search_substring: string -> string -> int -> int + (* [search_substring pat str start] returns the position of the first + occurrence of string [pat] in string [str]. Search starts + at offset [start] in [str]. Raise [Not_found] if [pat] + does not occur. *) + +val rev_split_words: string -> string list + (* [rev_split_words s] splits [s] in blank-separated words, and return + the list of words in reverse order. *) diff --git a/utils/tbl.ml b/utils/tbl.ml new file mode 100644 index 0000000..5343aa6 --- /dev/null +++ b/utils/tbl.ml @@ -0,0 +1,104 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tbl.ml,v 1.13 2004-11-25 13:28:27 doligez Exp $ *) + +type ('a, 'b) t = + Empty + | Node of ('a, 'b) t * 'a * 'b * ('a, 'b) t * int + +let empty = Empty + +let height = function + Empty -> 0 + | Node(_,_,_,_,h) -> h + +let create l x d r = + let hl = height l and hr = height r in + Node(l, x, d, r, (if hl >= hr then hl + 1 else hr + 1)) + +let bal l x d r = + let hl = height l and hr = height r in + if hl > hr + 1 then + match l with + | Node (ll, lv, ld, lr, _) when height ll >= height lr -> + create ll lv ld (create lr x d r) + | Node (ll, lv, ld, Node (lrl, lrv, lrd, lrr, _), _) -> + create (create ll lv ld lrl) lrv lrd (create lrr x d r) + | _ -> assert false + else if hr > hl + 1 then + match r with + | Node (rl, rv, rd, rr, _) when height rr >= height rl -> + create (create l x d rl) rv rd rr + | Node (Node (rll, rlv, rld, rlr, _), rv, rd, rr, _) -> + create (create l x d rll) rlv rld (create rlr rv rd rr) + | _ -> assert false + else + create l x d r + +let rec add x data = function + Empty -> + Node(Empty, x, data, Empty, 1) + | Node(l, v, d, r, h) -> + let c = compare x v in + if c = 0 then + Node(l, x, data, r, h) + else if c < 0 then + bal (add x data l) v d r + else + bal l v d (add x data r) + +let rec find x = function + Empty -> + raise Not_found + | Node(l, v, d, r, _) -> + let c = compare x v in + if c = 0 then d + else find x (if c < 0 then l else r) + +let rec mem x = function + Empty -> false + | Node(l, v, d, r, _) -> + let c = compare x v in + c = 0 || mem x (if c < 0 then l else r) + +let rec merge t1 t2 = + match (t1, t2) with + (Empty, t) -> t + | (t, Empty) -> t + | (Node(l1, v1, d1, r1, h1), Node(l2, v2, d2, r2, h2)) -> + bal l1 v1 d1 (bal (merge r1 l2) v2 d2 r2) + +let rec remove x = function + Empty -> + Empty + | Node(l, v, d, r, h) -> + let c = compare x v in + if c = 0 then + merge l r + else if c < 0 then + bal (remove x l) v d r + else + bal l v d (remove x r) + +let rec iter f = function + Empty -> () + | Node(l, v, d, r, _) -> + iter f l; f v d; iter f r + +open Format + +let print print_key print_data ppf tbl = + let print_tbl ppf tbl = + iter (fun k d -> fprintf ppf "@[<2>%a ->@ %a;@]@ " print_key k print_data d) + tbl in + fprintf ppf "@[<hv 2>[[%a]]@]" print_tbl tbl diff --git a/utils/tbl.mli b/utils/tbl.mli new file mode 100644 index 0000000..377e1d6 --- /dev/null +++ b/utils/tbl.mli @@ -0,0 +1,30 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: tbl.mli,v 1.7 2000-04-21 08:13:22 weis Exp $ *) + +(* Association tables from any ordered type to any type. + We use the generic ordering to compare keys. *) + +type ('a, 'b) t + +val empty: ('a, 'b) t +val add: 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t +val find: 'a -> ('a, 'b) t -> 'b +val mem: 'a -> ('a, 'b) t -> bool +val remove: 'a -> ('a, 'b) t -> ('a, 'b) t +val iter: ('a -> 'b -> 'c) -> ('a, 'b) t -> unit + +open Format + +val print: (formatter -> 'a -> unit) -> (formatter -> 'b -> unit) -> + formatter -> ('a, 'b) t -> unit diff --git a/utils/terminfo.ml b/utils/terminfo.ml new file mode 100644 index 0000000..7449b25 --- /dev/null +++ b/utils/terminfo.ml @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: terminfo.ml,v 1.6 2004-01-01 16:42:42 doligez Exp $ *) + +(* Basic interface to the terminfo database *) + +type status = + | Uninitialised + | Bad_term + | Good_term of int +;; +external setup : out_channel -> status = "caml_terminfo_setup";; +external backup : int -> unit = "caml_terminfo_backup";; +external standout : bool -> unit = "caml_terminfo_standout";; +external resume : int -> unit = "caml_terminfo_resume";; diff --git a/utils/terminfo.mli b/utils/terminfo.mli new file mode 100644 index 0000000..a252f4c --- /dev/null +++ b/utils/terminfo.mli @@ -0,0 +1,25 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 1996 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: terminfo.mli,v 1.7 2004-01-01 16:42:43 doligez Exp $ *) + +(* Basic interface to the terminfo database *) + +type status = + | Uninitialised + | Bad_term + | Good_term of int (* number of lines of the terminal *) +;; +external setup : out_channel -> status = "caml_terminfo_setup";; +external backup : int -> unit = "caml_terminfo_backup";; +external standout : bool -> unit = "caml_terminfo_standout";; +external resume : int -> unit = "caml_terminfo_resume";; diff --git a/utils/warnings.ml b/utils/warnings.ml new file mode 100644 index 0000000..25b913c --- /dev/null +++ b/utils/warnings.ml @@ -0,0 +1,195 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis && Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: warnings.ml,v 1.28 2008-10-06 13:53:54 doligez Exp $ *) + +(* Please keep them in alphabetical order *) + +type t = (* A is all *) + | Comment_start (* C *) + | Comment_not_end + | Deprecated (* D *) + | Fragile_match of string (* E *) + | Partial_application (* F *) + | Labels_omitted (* L *) + | Method_override of string list (* M *) + | Partial_match of string (* P *) + | Statement_type (* S *) + | Unused_match (* U *) + | Unused_pat + | Instance_variable_override of string (* V *) + | Illegal_backslash (* X *) + | Implicit_public_methods of string list + | Unerasable_optional_argument + | Undeclared_virtual_method of string + | Not_principal of string + | Without_principality of string + | Unused_argument + | Nonreturning_statement + | Camlp4 of string + | All_clauses_guarded + | Useless_record_with + | Bad_module_name of string + | Unused_var of string (* Y *) + | Unused_var_strict of string (* Z *) +;; + +let letter = function (* 'a' is all *) + | Comment_start + | Comment_not_end -> 'c' + | Deprecated -> 'd' + | Fragile_match _ -> 'e' + | Partial_application -> 'f' + | Labels_omitted -> 'l' + | Method_override _ -> 'm' + | Partial_match _ -> 'p' + | Statement_type -> 's' + | Unused_match + | Unused_pat -> 'u' + | Instance_variable_override _ -> 'v' + | Illegal_backslash + | Implicit_public_methods _ + | Unerasable_optional_argument + | Undeclared_virtual_method _ + | Not_principal _ + | Without_principality _ + | Unused_argument + | Nonreturning_statement + | Camlp4 _ + | Useless_record_with + | Bad_module_name _ + | All_clauses_guarded -> 'x' + | Unused_var _ -> 'y' + | Unused_var_strict _ -> 'z' +;; + +let active = Array.create 27 true;; +let error = Array.create 27 false;; + +let translate c = + if c >= 'A' && c <= 'Z' then + (Char.code c - Char.code 'A', true) + else if c >= 'a' && c <= 'z' then + (Char.code c - Char.code 'a', false) + else + (26, false) +;; + +let is_active x = + let (n, _) = translate (letter x) in + active.(n) +;; + +let is_error x = + let (n, _) = translate (letter x) in + error.(n) +;; + +let parse_options iserr s = + let flags = if iserr then error else active in + for i = 0 to String.length s - 1 do + if s.[i] = 'A' then Array.fill flags 0 (Array.length flags) true + else if s.[i] = 'a' then Array.fill flags 0 (Array.length flags) false + else begin + let (n, fl) = translate s.[i] in + flags.(n) <- fl; + end; + done +;; + +let () = parse_options false "elz";; + +let message = function + | Partial_match "" -> "this pattern-matching is not exhaustive." + | Partial_match s -> + "this pattern-matching is not exhaustive.\n\ + Here is an example of a value that is not matched:\n" ^ s + | Unused_match -> "this match case is unused." + | Unused_pat -> "this sub-pattern is unused." + | Fragile_match "" -> + "this pattern-matching is fragile." + | Fragile_match s -> + "this pattern-matching is fragile.\n\ + It will remain exhaustive when constructors are added to type " ^ s ^ "." + | Labels_omitted -> + "labels were omitted in the application of this function." + | Method_override [lab] -> + "the method " ^ lab ^ " is overriden in the same class." + | Method_override (cname :: slist) -> + String.concat " " + ("the following methods are overriden by the class" + :: cname :: ":\n " :: slist) + | Method_override [] -> assert false + | Instance_variable_override lab -> + "the instance variable " ^ lab ^ " is overriden.\n" ^ + "The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)" + | Partial_application -> + "this function application is partial,\n\ + maybe some arguments are missing." + | Statement_type -> + "this expression should have type unit." + | Comment_start -> "this is the start of a comment." + | Comment_not_end -> "this is not the end of a comment." + | Deprecated -> "this syntax is deprecated." + | Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "." + | Illegal_backslash -> "illegal backslash escape in string." + | Implicit_public_methods l -> + "the following private methods were made public implicitly:\n " + ^ String.concat " " l ^ "." + | Unerasable_optional_argument -> "this optional argument cannot be erased." + | Undeclared_virtual_method m -> "the virtual method "^m^" is not declared." + | Not_principal s -> s^" is not principal." + | Without_principality s -> s^" without principality." + | Unused_argument -> "this argument will not be used by the function." + | Nonreturning_statement -> + "this statement never returns (or has an unsound type.)" + | Camlp4 s -> s + | All_clauses_guarded -> + "bad style, all clauses in this pattern-matching are guarded." + | Useless_record_with -> + "this record is defined by a `with' expression,\n\ + but no fields are borrowed from the original." + | Bad_module_name (modname) -> + "bad source file name: \"" ^ modname ^ "\" is not a valid module name." +;; + +let nerrors = ref 0;; + +let print ppf w = + let msg = message w in + let flag = Char.uppercase (letter w) in + let newlines = ref 0 in + for i = 0 to String.length msg - 1 do + if msg.[i] = '\n' then incr newlines; + done; + let (out, flush, newline, space) = + Format.pp_get_all_formatter_output_functions ppf () + in + let countnewline x = incr newlines; newline x in + Format.pp_set_all_formatter_output_functions ppf out flush countnewline space; + Format.fprintf ppf "%c: %s" flag msg; + Format.pp_print_flush ppf (); + Format.pp_set_all_formatter_output_functions ppf out flush newline space; + let (n, _) = translate (letter w) in + if error.(n) then incr nerrors; + !newlines +;; + +exception Errors of int;; + +let check_fatal () = + if !nerrors > 0 then begin + let e = Errors !nerrors in + nerrors := 0; + raise e; + end; +;; diff --git a/utils/warnings.mli b/utils/warnings.mli new file mode 100644 index 0000000..e6d76be --- /dev/null +++ b/utils/warnings.mli @@ -0,0 +1,57 @@ +(***********************************************************************) +(* *) +(* Objective Caml *) +(* *) +(* Pierre Weis && Damien Doligez, INRIA Rocquencourt *) +(* *) +(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(* $Id: warnings.mli,v 1.19 2008-10-06 13:53:54 doligez Exp $ *) + +open Format + +type t = (* A is all *) + | Comment_start (* C *) + | Comment_not_end + | Deprecated (* D *) + | Fragile_match of string (* E *) + | Partial_application (* F *) + | Labels_omitted (* L *) + | Method_override of string list (* M *) + | Partial_match of string (* P *) + | Statement_type (* S *) + | Unused_match (* U *) + | Unused_pat + | Instance_variable_override of string (* V *) + | Illegal_backslash (* X *) + | Implicit_public_methods of string list + | Unerasable_optional_argument + | Undeclared_virtual_method of string + | Not_principal of string + | Without_principality of string + | Unused_argument + | Nonreturning_statement + | Camlp4 of string + | All_clauses_guarded + | Useless_record_with + | Bad_module_name of string + | Unused_var of string (* Y *) + | Unused_var_strict of string (* Z *) +;; + +val parse_options : bool -> string -> unit;; + +val is_active : t -> bool;; +val is_error : t -> bool;; + +val print : formatter -> t -> int;; + (* returns the number of newlines in the printed string *) + + +exception Errors of int;; + +val check_fatal : unit -> unit;; diff --git a/win32caml/Makefile b/win32caml/Makefile new file mode 100644 index 0000000..4af5b1a --- /dev/null +++ b/win32caml/Makefile @@ -0,0 +1,57 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 2001 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the GNU Library General Public License, with # +# the special exception on linking described in file ../LICENSE. # +# # +######################################################################### + +# $Id: Makefile,v 1.12 2007-11-15 13:21:15 frisch Exp $ + +include ../config/Makefile + +CC=$(BYTECC) +CFLAGS=$(BYTECCCOMPOPTS) + +OBJS=startocaml.$(O) ocamlres.$(O) ocaml.$(O) menu.$(O) \ + history.$(O) editbuffer.$(O) + +LIBS=$(call SYSLIB,kernel32) $(call SYSLIB,advapi32) $(call SYSLIB,gdi32) \ + $(call SYSLIB,user32) $(call SYSLIB,comdlg32) $(call SYSLIB,comctl32) + +all: ocamlwin.exe + +ocamlwin.exe: $(OBJS) + $(MKEXE) -o ocamlwin.exe $(OBJS) $(LIBS) $(EXTRALIBS) -subsystem windows + +ocamlres.$(O): ocaml.rc ocaml.ico +ifeq ($(TOOLCHAIN),msvc) + rc ocaml.rc +ifeq ($(ARCH),amd64) + cvtres /nologo /machine:amd64 /out:$@ ocaml.res +else + cvtres /nologo /machine:ix86 /out:$@ ocaml.res +endif + rm -f ocaml.res +endif +ifeq ($(TOOLCHAIN),mingw) + windres -i ocaml.rc -o $@ +endif + +$(OBJS): inria.h inriares.h history.h editbuffer.h + +clean: + rm -f ocamlwin.exe *.$(O) *.pdb ocamlwin.ilk + +install: + cp ocamlwin.exe $(PREFIX)/OCamlWin.exe + +.SUFFIXES: .c .$(O) + +.c.$(O): + $(CC) $(CFLAGS) -c $*.c diff --git a/win32caml/editbuffer.c b/win32caml/editbuffer.c new file mode 100644 index 0000000..480d22d --- /dev/null +++ b/win32caml/editbuffer.c @@ -0,0 +1,514 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia. */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +#include <string.h> +#include <stdlib.h> +#include "inriares.h" +#include "inria.h" + +/*------------------------------------------------------------------------ + Procedure: editbuffer_addline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Adds a line to the current edit buffer + Input: Line of text to append to the end + Output: + Errors: +-------------------------------------------------------------------------- + Edit History: + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list issue +------------------------------------------------------------------------*/ +BOOL editbuffer_addline(EditBuffer* edBuf, char* line) +{ + LineList *tail = NULL; //head of the edit buffer line list + LineList *newline = NULL; + + // sanity check + if(edBuf == NULL) + { + return FALSE; + } + + // perform edit buffer sanity checks + if((edBuf->LineCount < 0) || (edBuf->Lines == NULL)) + { + edBuf->LineCount = 0; + } + + // move to the end of the line list in the edit buffer + if((tail = edBuf->Lines) != NULL) + for( ; tail->Next != NULL; tail = tail->Next); + + // create the new line entry + newline = (LineList*)SafeMalloc(sizeof(LineList)); + newline->Next = NULL; + newline->Prev = tail; + newline->Text = (char*)SafeMalloc(strlen(line)+1); + strncpy(newline->Text, line, strlen(line)+1); + newline->Text[strlen(line)] = '\0'; + + // add it to the list as the head or the tail + if(tail != NULL) + { + tail->Next = newline; + } else { + edBuf->Lines = newline; + } + + // update the number of lines in the buffer + edBuf->LineCount++; + + return TRUE; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_updateline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Updates the edit buffer's internal contents for a line + Input: idx - Line index + line - String to add + Output: if the line was updated or not + Errors: +------------------------------------------------------------------------*/ +BOOL editbuffer_updateline(EditBuffer* edBuf, int idx, char* line) +{ + LineList *update = edBuf->Lines; //head of the edit buffer line list + LineList *newline = NULL; + int i; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if( (edBuf->LineCount == 0) || + (edBuf->Lines == NULL) || + (idx >= edBuf->LineCount) || + (idx < 0) ) { + return FALSE; + } + + // move to the index in the line list + // i left in update != NULL as a sanity check + for(i = 0; ((update != NULL) && (i != idx)); update = update->Next, i++); + + // did things mess up? + if( (update == NULL) || (i != idx) ) + { + return FALSE; + } + + // get rid of the old line + free(update->Text); + + // get the new line updated + update->Text = (char*)SafeMalloc(strlen(line)+1); + strncpy(update->Text, line, strlen(line)+1); + update->Text[strlen(line)] = '\0'; + + return TRUE; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_updateoraddline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Updates the edit buffer's internal contents for a line + Input: idx - Line index + line - String to add + Output: if the line was updated or not + Errors: +------------------------------------------------------------------------*/ +BOOL editbuffer_updateoraddline(EditBuffer* edBuf, int idx, char* line) +{ + LineList *update; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if((idx > edBuf->LineCount) || (idx < 0)) { + return FALSE; + } + + update = edBuf->Lines; //head of the edit buffer line list + + // do we update or add? + if((idx < edBuf->LineCount) && (edBuf->Lines != NULL)) + { //interior line, update + return editbuffer_updateline(edBuf, idx, line); + } else { + //fence line, add + return editbuffer_addline(edBuf, line); + } +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_removeline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Removes a line from the edit buffer + Input: idx - Line index to remove + Output: if the line was removed or not + Errors: +-------------------------------------------------------------------------- + Edit History: + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Added to allow backspace and delete support + - Corrected doubly linked list issue +------------------------------------------------------------------------*/ +BOOL editbuffer_removeline(EditBuffer* edBuf, int idx) +{ + LineList *update = NULL; + int i = 0; + + // sanity checks + if(edBuf == NULL) + { + return FALSE; + } else if( (edBuf->LineCount == 0) || + (edBuf->Lines == NULL) || + (idx >= edBuf->LineCount) || + (idx < 0) ) { + return FALSE; + } + + // move to the index in the line list + // i left in update != NULL as a sanity check + for(i = 0, update = edBuf->Lines; ((update != NULL) && (i != idx)); update = update->Next, i++); + + // remove this line + if(update != NULL) + { + // break links, removing our line + if(update->Prev != NULL) + { + // we're not the first so just break the link + update->Prev->Next = update->Next; + + // fix the prev check + if(update->Next != NULL) + update->Next->Prev = update->Prev; + } else { + // we're the first, attach the next guy to lines + edBuf->Lines = update->Next; + } + + // one less line to worry about + edBuf->LineCount--; + + // get rid of the text + if(update->Text != NULL) + free(update->Text); + + // get rid of us + free(update); + + return TRUE; + } + + return FALSE; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_getasline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Returns the edit buffer as one big line, \n's and \t's + become spaces. + Input: + Output: + Errors: +------------------------------------------------------------------------*/ +char* editbuffer_getasline(EditBuffer* edBuf) +{ + LineList *line = NULL; //head of the edit buffer line list + char* retline = (char*)realloc(NULL, 1); + unsigned int i = 0; + + // fix retline bug + retline[0] = '\0'; + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // get the big line + for(line = edBuf->Lines; line != NULL; line = line->Next) + { + if(line->Text != NULL) + { + retline = (char*)realloc(retline, (strlen(retline) + strlen(line->Text) + (strlen(retline) > 0 ? 2 : 1))); + + if(strlen(retline) > 0) + retline = strcat(retline, " "); + + retline = strcat(retline, line->Text); + + //concat in the hoouuusssseee! + } + } + + // now we have the big line, so lets ditch all \n's \t's and \r's + for(i = 0; i < strlen(retline); i++) + { + switch(retline[i]) + { + case '\n': + case '\t': + case '\r': + retline[i] = ' '; + } + } + + return retline; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_getasbuffer ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Returns the edit buffer as one big line, \n's and \t's + become spaces. + Input: + Output: + Errors: +------------------------------------------------------------------------*/ +char* editbuffer_getasbuffer(EditBuffer* edBuf) +{ + LineList *line = NULL; //head of the edit buffer line list + char* retbuf = (char*)realloc(NULL, 1); + unsigned int i = 0; + + // fix retline bug + retbuf[0] = '\0'; + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // get the big line + for(line = edBuf->Lines; line != NULL; line = line->Next) + { + if(line->Text != NULL) + { + int len = strlen(retbuf); + len += strlen(line->Text) + (len > 0 ? 3 : 1); + + retbuf = (char*)realloc(retbuf, len); + + if(strlen(retbuf) > 0) + retbuf = strcat(retbuf, "\r\n"); + + retbuf = strcat(retbuf, line->Text); + + retbuf[len-1] = '\0'; + + //concat in the hoouuusssseee! + } + } + + return retbuf; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_lastline ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Returns the last line in the edit buffer + Input: + Output: + Errors: +------------------------------------------------------------------------*/ +char* editbuffer_lastline(EditBuffer* edBuf) +{ + LineList *line = NULL; //head of the edit buffer line list + + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return NULL; + } + + // go to the last line + for(line = edBuf->Lines; line->Next != NULL; line = line->Next); + + return line->Text; +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_copy ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Makes an exact copy of an edit buffer + Input: + Output: + Errors: +-------------------------------------------------------------------------- + Edit History: + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Added to make copies of history entries + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list issue + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Added isCorrect flag +------------------------------------------------------------------------*/ +EditBuffer* editbuffer_copy(EditBuffer* edBuf) +{ + // sanity checks + if(edBuf == NULL) + { + return NULL; + } else { + EditBuffer* copy = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + LineList* lines = edBuf->Lines; + LineList* lastLine = NULL; + + // clear its initial values + copy->LineCount = 0; + copy->Lines = NULL; + copy->isCorrect = FALSE; + + // well we don't have to copy much + if((lines == NULL) || (edBuf->LineCount <= 0)) + { + return copy; + } + + // get if its correct + copy->isCorrect = edBuf->isCorrect; + + // go through each line, malloc it and add it + for( ; lines != NULL; lines = lines->Next) + { + LineList* curline = (LineList*)SafeMalloc(sizeof(LineList)); + curline->Next = NULL; + curline->Prev = NULL; + + // if there was a last line, link them to us + if(lastLine != NULL) + { + lastLine->Next = curline; + curline->Prev = lastLine; + } + + // are we the first line? add us to the edit buffer as the first + if(copy->Lines == NULL) + { + copy->Lines = curline; + } + + // check if there is text on the line + if(lines->Text == NULL) + { // no text, make it blankz0r + curline->Text = (char*)SafeMalloc(sizeof(char)); + curline->Text[0] = '\0'; + } else { + // there is text, copy it and null-terminate + curline->Text = (char*)SafeMalloc(strlen(lines->Text) + 1); + strncpy(curline->Text, lines->Text, strlen(lines->Text)); + curline->Text[strlen(lines->Text)] = '\0'; + } + + // up the line count and make us the last line + copy->LineCount++; + lastLine = curline; + } + + // return our new copy + return copy; + } +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_destroy ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Destroys an edit buffer + Input: + Output: + Errors: +------------------------------------------------------------------------*/ +void editbuffer_destroy(EditBuffer* edBuf) +{ + // sanity checks + if(edBuf == NULL) + { // nothing to do + return; + } else if(edBuf->Lines != NULL) { + LineList* lastline = NULL; + + // loop through each line free'ing its text + for( ; edBuf->Lines != NULL; edBuf->Lines = edBuf->Lines->Next) + { + if(edBuf->Lines->Text != NULL) + free(edBuf->Lines->Text); + + // if there was a line before us, free it + if(lastline != NULL) + { + free(lastline); + lastline = NULL; + } + + lastline = edBuf->Lines; + } + + // free the last line + free(lastline); + } + + // free ourself + free(edBuf); +} + +/*------------------------------------------------------------------------ + Procedure: editbuffer_new ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Creates an edit buffer + Input: + Output: + Errors: +-------------------------------------------------------------------------- + Edit History: + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Added isCorrect flag +------------------------------------------------------------------------*/ +EditBuffer* editbuffer_new(void) +{ + // create a new one + EditBuffer *edBuf = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + + // default vals + edBuf->LineCount = 0; + edBuf->Lines = NULL; + edBuf->isCorrect = FALSE; + + // return it + return edBuf; +} diff --git a/win32caml/editbuffer.h b/win32caml/editbuffer.h new file mode 100644 index 0000000..ce8dccf --- /dev/null +++ b/win32caml/editbuffer.h @@ -0,0 +1,47 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jacob Navia, after Xavier Leroy */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +#ifndef _EDITBUFFER_H_ +#define _EDITBUFFER_H_ + +// All the below was added by Chris Watford watford@uiuc.edu + +typedef struct tagLineList { + struct tagLineList *Next; + struct tagLineList *Prev; + char *Text; +} LineList; + +typedef struct tagEditBuffer { + int LineCount; + struct tagLineList *Lines; + BOOL isCorrect; +} EditBuffer; + +BOOL editbuffer_addline (EditBuffer* edBuf, char* line); +BOOL editbuffer_updateline (EditBuffer* edBuf, int idx, char* line); +BOOL editbuffer_updateoraddline (EditBuffer* edBuf, int idx, char* line); +BOOL editbuffer_removeline (EditBuffer* edBuf, int idx); +char* editbuffer_getasline (EditBuffer* edBuf); +char* editbuffer_getasbuffer (EditBuffer* edBuf); +char* editbuffer_lastline (EditBuffer* edBuf); +EditBuffer* editbuffer_copy (EditBuffer* edBuf); +void editbuffer_destroy (EditBuffer* edBuf); +EditBuffer* editbuffer_new (void); + +#endif diff --git a/win32caml/history.c b/win32caml/history.c new file mode 100644 index 0000000..11397ac --- /dev/null +++ b/win32caml/history.c @@ -0,0 +1,98 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jacob Navia, after Xavier Leroy */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +#include "inria.h" +#include "history.h" + +/*------------------------------------------------------------------------ +Procedure: AddToHistory ID:2 +Author: Chris Watford watford@uiuc.edu +Purpose: Adds an edit buffer to the history control +Input: Pointer to the edit buffer to add +Output: +Errors: +-------------------------------------------------------------------------- +Edit History: + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Complete rewrite + - Got it to add the edit buffer to the history + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added doubly link list support +------------------------------------------------------------------------*/ +void AddToHistory(EditBuffer *edBuf) +{ + StatementHistory *newLine; + + // sanity checks + if(edBuf == NULL) + { + return; + } else if (edBuf->LineCount == 0 || edBuf->Lines == NULL) { + // fix any possible errors that may come from this + edBuf->LineCount = 0; + edBuf->Lines = NULL; + return; + } + + // setup newline and add as the front of the linked list + newLine = SafeMalloc(sizeof(StatementHistory)); + newLine->Next = History; + newLine->Prev = NULL; + newLine->Statement = edBuf; + + // setup back linking + if(History != NULL) + History->Prev = newLine; + + // set the history up + History = newLine; + + // search for the new history tail + for(HistoryTail = (HistoryTail != NULL ? HistoryTail : History); HistoryTail->Next != NULL; HistoryTail = HistoryTail->Next); +} + +/*------------------------------------------------------------------------ +Procedure: GetHistoryLine ID:2 +Author: Chris Watford watford@uiuc.edu +Purpose: Returns an entry from the history table +Input: Index of the history entry to return +Output: The history entry as a single line +Errors: +-------------------------------------------------------------------------- +Edit History: + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Complete rewrite + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added doubly link list support +------------------------------------------------------------------------*/ +char *GetHistoryLine(int n) +{ + StatementHistory *histentry = History; + int i; + + // traverse linked list looking for member n + for (i = 0; ((i < n) && (histentry != NULL)); i++, histentry = histentry->Next); + + // figure out what to return + if (histentry != NULL) + { + return editbuffer_getasline(histentry->Statement); + } else { + return ""; + } +} diff --git a/win32caml/history.h b/win32caml/history.h new file mode 100644 index 0000000..a9ba858 --- /dev/null +++ b/win32caml/history.h @@ -0,0 +1,35 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jacob Navia, after Xavier Leroy */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +#ifndef _HISTORY_H_ +#define _HISTORY_H_ + +#include "editbuffer.h" + +// Simple linked list for holding the history lines +typedef struct tagStatementHistory { + struct tagStatementHistory *Next; + struct tagStatementHistory *Prev; + EditBuffer *Statement; +} StatementHistory; + +void AddToHistory (EditBuffer *edBuf); +char *GetHistoryLine (int n); +static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); + +#endif diff --git a/win32caml/inria.h b/win32caml/inria.h new file mode 100644 index 0000000..7530006 --- /dev/null +++ b/win32caml/inria.h @@ -0,0 +1,134 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia. */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: inria.h,v 1.8 2008-12-03 18:09:09 doligez Exp $ */ + +/*------------------------------------------------------------------------ + Module: D:\lcc\inria\inria.h + Author: Jacob + Project: + State: + Creation Date: June 2001 + Description: The user interface works as follows: + 1: At startup it will look for the path to the + ocaml interpreter in the registry using the + key HKEY_CURRENT_USER\SOFTWARE\ocaml. If not + found will prompt the user. + 2: It will start the ocaml interpreter with + its standard output and standard input + connected to two pipes in a dedicated thread. + 3: It will open a window containing an edit + field. The output from the interpreter will be + shown in the edit field, and the input of the + user in the edit field will be sent to the + interpreter when the user types return. + 4: Line editing is provided by moving to the + desired line with the arrows, then pressing + return; If we aren't in the last input line, + the input will be copied to the last line and + sent to the interpreter. + 5: The GUI ensures that when we exit the ocaml + interpreter is stopped by sending the + character string "#quit;;\nCtrl-Z" + 6: A history of all lines sent to the interpreter + is maintained in a simple linked list. The + History dialog box shows that, and allows the + user to choose a given input line. + 7: Memory limits. The edit buffer can be of an + arbitrary length, i.e. maybe 7-8MB or more, + there are no fixed limits. The History list + will always grow too, so memory consumption + could be "high" after several days of + uninterrupted typing at the keyboard. For that + cases it is recommended to stop the GUI and + get some sleep... + 9: The GUI will start a timer, looking 4 times a + second if the interpreter has written + something in the pipe. This is enough for most + applications. +------------------------------------------------------------------------*/ +#ifndef _INRIA_H_ +#define _INRIA_H_ + +#include <windows.h> +#include "editbuffer.h" +#include "history.h" + +#if _MSC_VER <= 1200 && !defined(__MINGW32__) +#define GetWindowLongPtr GetWindowLong +#define SetWindowLongPtr SetWindowLong +#define DWLP_USER DWL_USER +#define GWLP_WNDPROC GWL_WNDPROC +#define LONG_PTR DWORD +#endif + +// In this structure should go eventually all global variables scattered +// through the program. +typedef struct _programParams { + HFONT hFont; // The handle of the current font + COLORREF TextColor; // The text color + char CurrentWorkingDir[MAX_PATH];// The current directory +} PROGRAM_PARAMS; + +//**************** Global variables *********************** +extern PROGRAM_PARAMS ProgramParams; + +extern COLORREF BackColor; // The background color +extern HBRUSH BackgroundBrush; // A brush built with the background color +extern char LibDir[]; // The lib directory +extern char OcamlPath[]; // The Path to ocaml.exe +extern HANDLE hInst; // The instance handle for this application +extern HWND hwndSession; // The current session window handle +extern LOGFONT CurrentFont; // The current font characteristics +extern HWND hwndMain,hwndMDIClient; // Window handles of frame and mdi window + +// ***************** Function prototypes ****************** +int WriteToPipe(char *data); // Writes to the pipe +int ReadFromPipe(char *data,int len);// Reads from the pipe +int AskYesOrNo(char *msg); //Ditto! +int BrowseForFile(char *fname,char *path); +void GotoEOF(void); // Positions the cursor at the end of the text +void ShowDbgMsg(char *msg); // Shows an error message +void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam); +int GetOcamlPath(void); // Finds where ocaml.exe is +void ForceRepaint(void); // Ditto. +void AddLineToControl(char *buf); +void AddStringToControl(char* buf); +char *GetHistoryLine(int n); // Gets the nth history line base 1. +int StartOcaml(void); +void InterruptOcaml(void); +int ResetText(void); +BOOL SendingFullCommand(void); +void RewriteCurrentEditBuffer(void); +void RefreshCurrentEditBuffer(void); + +// **************** User defined window messages ************* +#define WM_NEWLINE (WM_USER+6000) +#define WM_TIMERTICK (WM_USER+6001) +#define WM_QUITOCAML (WM_USER+6002) +#define WM_SYNTAXERROR (WM_USER+6003) +#define WM_UNBOUNDVAL (WM_USER+6004) +#define WM_ILLEGALCHAR (WM_USER+6005) + +// ********************** Structures *********************** +typedef struct tagPosition { + int line; + int col; +} POSITION; + +extern void *SafeMalloc(int); +extern StatementHistory *History; // The root of the history lines +extern StatementHistory *HistoryTail; // The tail of the history lines +extern EditBuffer *CurrentEditBuffer; // current edit buffer + +#define IDEDITCONTROL 15432 +#endif diff --git a/win32caml/inriares.h b/win32caml/inriares.h new file mode 100644 index 0000000..2043a37 --- /dev/null +++ b/win32caml/inriares.h @@ -0,0 +1,48 @@ +/* Weditres generated include file. Do NOT edit */ +#define IDD_ABOUT 100 +#define IDM_NEW 200 +#define IDM_OPEN 210 +#define IDM_SAVE 220 +#define IDM_SAVEAS 230 +#define IDM_CLOSE 240 +#define IDM_PRINT 250 +#define IDM_PRINTSU 260 +#define IDM_PRINTPRE 265 +#define IDM_PAGESETUP 267 +#define IDM_EXIT 270 +#define IDM_HISTORY 281 +#define IDM_GC 282 +#define IDCTRLC 283 +#define IDD_HISTORY 300 +#define IDLIST 301 +#define IDM_EDITUNDO 310 +#define IDM_EDITCUT 320 +#define IDM_EDITCOPY 330 +#define IDM_EDITPASTE 340 +#define IDM_EDITCLEAR 350 +#define IDM_EDITDELETE 360 +#define IDM_EDITREPLACE 370 +#define IDM_EDITREDO 380 +#define IDM_WINDOWTILE 410 +#define IDM_WINDOWCASCADE 420 +#define IDM_WINDOWICONS 430 +#define IDM_WINDOWCLOSEALL 440 +#define IDM_PROPERTIES 450 +#define IDM_ABOUT 500 +#define IDM_HELP 510 +#define IDMAINMENU 600 +#define IDM_FIND 700 +#define IDAPPLICON 710 +#define IDI_CHILDICON 800 +#define IDAPPLCURSOR 810 +#define OCAML_ICON 1000 +#define IDS_FILEMENU 2000 +#define IDS_HELPMENU 2010 +#define IDS_SYSMENU 2030 +#define IDM_STATUSBAR 3000 +#define IDM_WINDOWCHILD 3010 +#define ID_TOOLBAR 5000 +#define IDACCEL 10000 +#define IDM_FONT 40002 +#define IDM_COLORTEXT 40004 +#define IDM_BACKCOLOR 40005 diff --git a/win32caml/libgraph.h b/win32caml/libgraph.h new file mode 100644 index 0000000..85a30f9 --- /dev/null +++ b/win32caml/libgraph.h @@ -0,0 +1,108 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Jacob Navia, after Xavier Leroy */ +/* */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/* $Id: libgraph.h,v 1.3 2002-07-23 14:12:02 doligez Exp $ */ + +#include <stdio.h> +#include <windows.h> + +struct canvas { + int w, h; /* Dimensions of the drawable */ + HWND win; /* The drawable itself */ + HDC gc; /* The associated graphics context */ +}; + +extern HWND grdisplay; /* The display connection */ +//extern int grscreen; /* The screen number */ +//extern Colormap grcolormap; /* The color map */ +//extern struct canvas grwindow; /* The graphics window */ +//extern struct canvas grbstore; /* The pixmap used for backing store */ +//extern int grwhite, grblack; /* Black and white pixels for X */ +//extern int grbackground; /* Background color for X +// (used for CAML color -1) */ +extern COLORREF grbackground; +extern BOOL grdisplay_mode; /* Display-mode flag */ +extern BOOL grremember_mode; /* Remember-mode flag */ +extern int grx, gry; /* Coordinates of the current point */ +extern int grcolor; /* Current *CAML* drawing color (can be -1) */ +extern HFONT * grfont; /* Current font */ + +extern BOOL direct_rgb; +extern int byte_order; +extern int bitmap_unit; +extern int bits_per_pixel; + +#define Wcvt(y) (grwindow.height - 1 - (y)) +#define Bcvt(y) (grwindow.height - 1 - (y)) +#define WtoB(y) ((y) + WindowRect.bottom - grwindow.h) +//#define BtoW(y) ((y) + WindowRect.bottom - grbstore.h) + +#define DEFAULT_SCREEN_WIDTH 1024 +#define DEFAULT_SCREEN_HEIGHT 768 +#define BORDER_WIDTH 2 +#define WINDOW_NAME "Caml graphics" +#define ICON_NAME "Caml graphics" +#define DEFAULT_EVENT_MASK \ + (ExposureMask | KeyPressMask | StructureNotifyMask) +#define DEFAULT_FONT "fixed" +#define SIZE_QUEUE 256 + +/* To handle events asynchronously */ +#ifdef HAS_ASYNC_IO +#define USE_ASYNC_IO +#define EVENT_SIGNAL SIGIO +#else +#ifdef HAS_SETITIMER +#define USE_INTERVAL_TIMER +#define EVENT_SIGNAL SIGALRM +#else +#define USE_ALARM +#define EVENT_SIGNAL SIGALRM +#endif +#endif + +void gr_fail(char *fmt, char *arg); +void gr_check_open(void); +unsigned long gr_pixel_rgb(int rgb); +int gr_rgb_pixel(long unsigned int pixel); +void gr_enqueue_char(unsigned char c); +void gr_init_color_cache(void); + +// Windows specific definitions +extern RECT WindowRect; +extern int grCurrentColor; + +typedef struct tagWindow { + HDC gc; + HDC gcBitmap; + HWND hwnd; + HBRUSH CurrentBrush; + HPEN CurrentPen; + DWORD CurrentColor; + int width; + int height; + int grx; + int gry; + HBITMAP hBitmap; + HFONT CurrentFont; + int CurrentFontSize; + HDC tempDC; // For image operations; +} GR_WINDOW; + +extern GR_WINDOW grwindow; +HFONT CreationFont(char *name); +extern int MouseLbuttonDown,MouseMbuttonDown,MouseRbuttonDown; +extern HANDLE EventHandle; +extern int InspectMessages; +extern MSG msg; + diff --git a/win32caml/menu.c b/win32caml/menu.c new file mode 100644 index 0000000..dd80ee1 --- /dev/null +++ b/win32caml/menu.c @@ -0,0 +1,830 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia. */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +/* $Id: menu.c,v 1.8 2006-05-09 16:03:48 xleroy Exp $ */ + +#include <stdio.h> +#include <windows.h> +#include <Richedit.h> +#include "inria.h" +#include "inriares.h" +#include "history.h" + +LOGFONT CurrentFont; +int CurrentFontFamily = (FIXED_PITCH | FF_MODERN); +int CurrentFontStyle; +char CurrentFontName[64] = "Courier"; + +/*------------------------------------------------------------------------ + Procedure: OpenMlFile ID:1 + Purpose: Opens a file, either a source file (*.ml) or an *.cmo + file. + Input: A buffer where the name will be stored, and its + length + Output: The user's choice will be stored in the buffer. + Errors: None +------------------------------------------------------------------------*/ +int OpenMlFile(char *fname,int lenbuf) +{ + OPENFILENAME ofn; + int r; + char *p,defext[5],tmp[512]; + + memset(&ofn,0,sizeof(OPENFILENAME)); + memset(tmp,0,sizeof(tmp)); + fname[0] = 0; + strcpy(tmp,"ocaml sources|*.ml|bytecode object files|*.cmo|All files|*.*"); + p = tmp; + while (*p) { + if (*p == '|') + *p = 0; + p++; + } + strcpy(defext,"ml"); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hwndMain; + ofn.lpstrFilter = tmp; + ofn.nFilterIndex = 1; + ofn.hInstance = hInst; + ofn.lpstrFile = fname; + ofn.lpstrTitle = "Open file"; + ofn.lpstrInitialDir = LibDir; + ofn.nMaxFile = lenbuf; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_LONGNAMES | + OFN_HIDEREADONLY |OFN_EXPLORER; + r = GetOpenFileName(&ofn); + if (r) { + /* Replace backslashes by forward slashes in file name */ + for (p = fname; *p != 0; p++) + if (*p == '\\') *p = '/'; + } + return r; +} + +/*------------------------------------------------------------------------ + Procedure: GetSaveName ID:1 + Purpose: Get a name to save the current session (Save as menu + item) + Input: A buffer where the name of the file will be stored, + and its length + Output: The name of the file choosen by the user will be + stored in the buffer + Errors: none +------------------------------------------------------------------------*/ +int GetSaveName(char *fname,int lenbuf) +{ + OPENFILENAME ofn; + int r; + char *p,defext[5],tmp[512]; + + memset(&ofn,0,sizeof(OPENFILENAME)); + memset(tmp,0,sizeof(tmp)); + fname[0] = 0; + strcpy(tmp,"Text files|*.txt"); + p = tmp; + while (*p) { + if (*p == '|') + *p = 0; + p++; + } + strcpy(defext,"txt"); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hwndMain; + ofn.lpstrFilter = tmp; + ofn.nFilterIndex = 1; + ofn.hInstance = hInst; + ofn.lpstrFile = fname; + ofn.lpstrTitle = "Save as"; + ofn.lpstrInitialDir = LibDir; + ofn.nMaxFile = lenbuf; + ofn.Flags = OFN_NOCHANGEDIR | OFN_LONGNAMES | + OFN_HIDEREADONLY |OFN_EXPLORER; + r = GetSaveFileName(&ofn); + if (r == 0) + return 0; + else return 1; +} + +/*------------------------------------------------------------------------ + Procedure: GetSaveMLName ID:1 + Purpose: Get a name to save the current OCaml code to (Save as menu + item) + Input: A buffer where the name of the file will be stored, + and its length + Output: The name of the file choosen by the user will be + stored in the buffer + Errors: none +------------------------------------------------------------------------*/ +int GetSaveMLName(char *fname, int lenbuf) +{ + OPENFILENAME ofn; + int r; + char *p,defext[5],tmp[512]; + + memset(&ofn,0,sizeof(OPENFILENAME)); + memset(tmp,0,sizeof(tmp)); + fname[0] = 0; + strcpy(tmp,"OCaml Source Files|*.ml"); + p = tmp; + while (*p) { + if (*p == '|') + *p = 0; + p++; + } + strcpy(defext,"ml"); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hwndMain; + ofn.lpstrFilter = tmp; + ofn.nFilterIndex = 1; + ofn.hInstance = hInst; + ofn.lpstrFile = fname; + ofn.lpstrTitle = "Save as"; + ofn.lpstrInitialDir = LibDir; + ofn.nMaxFile = lenbuf; + ofn.Flags = OFN_NOCHANGEDIR | OFN_LONGNAMES | + OFN_HIDEREADONLY |OFN_EXPLORER; + r = GetSaveFileName(&ofn); + if (r == 0) + return 0; + else return 1; +} + +/*------------------------------------------------------------------------ + Procedure: BrowseForFile ID:1 + Purpose: Let's the user browse for a certain kind of file. + Currently this is only used when browsing for + ocaml.exe. + Input: The name of the file to browse for, and the path + where the user's choice will be stored. + Output: 1 if user choosed a path, zero otherwise + Errors: None +------------------------------------------------------------------------*/ +int BrowseForFile(char *fname,char *path) +{ + OPENFILENAME ofn; + char *p,tmp[512],browsefor[512]; + int r; + + memset(tmp,0,sizeof(tmp)); + strncpy(tmp,fname,sizeof(tmp)-1); + p = tmp; + while (*p) { + if (*p == '|') + *p = 0; + p++; + } + memset(&ofn,0,sizeof(OPENFILENAME)); + ofn.lpstrFilter = tmp; + ofn.nFilterIndex = 1; + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hwndMain; + ofn.hInstance = hInst; + ofn.lpstrFilter = tmp; + ofn.lpstrFile = path; + wsprintf(browsefor,"Open %s",fname); + ofn.lpstrTitle = browsefor; + ofn.lpstrInitialDir = "c:\\"; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_LONGNAMES | + OFN_HIDEREADONLY |OFN_EXPLORER; + r = GetOpenFileName(&ofn); + if (r == 0) + return 0; + else return 1; +} + +/*------------------------------------------------------------------------ + Procedure: CallChangeFont ID:1 + Purpose: Calls the standard windows font change dialog. If the + user validates a font, it will destroy the current + font, and recreate a new font with the given + parameters. + Input: The calling window handle + Output: Zero if the user cancelled, 1 otherwise. + Errors: None +------------------------------------------------------------------------*/ +static int CallChangeFont(HWND hwnd) +{ + LOGFONT lf; + CHOOSEFONT cf; + int r; + HWND hwndChild; + + memset(&cf, 0, sizeof(CHOOSEFONT)); + memcpy(&lf, &CurrentFont, sizeof(LOGFONT)); + cf.lStructSize = sizeof(CHOOSEFONT); + cf.hwndOwner = hwnd; + cf.lpLogFont = &lf; + cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_APPLY | CF_INITTOLOGFONTSTRUCT; + cf.nFontType = SCREEN_FONTTYPE; + r = ChooseFont(&cf); + if (!r) + return (0); + DeleteObject(ProgramParams.hFont); + memcpy(&CurrentFont, &lf, sizeof(LOGFONT)); + ProgramParams.hFont = CreateFontIndirect(&CurrentFont); + strcpy(CurrentFontName, CurrentFont.lfFaceName); + CurrentFontFamily = lf.lfPitchAndFamily; + CurrentFontStyle = lf.lfWeight; + hwndChild = (HWND) GetWindowLongPtr(hwndSession, DWLP_USER); + SendMessage(hwndChild,WM_SETFONT,(WPARAM)ProgramParams.hFont,0); + ForceRepaint(); + return (1); +} + +/*------------------------------------------------------------------------ + Procedure: CallDlgProc ID:1 + Purpose: Calls a dialog box procedure + Input: The function to call, and the numerical ID of the + resource where the dialog box is stored + Output: Returns the result of the dialog box. + Errors: None +------------------------------------------------------------------------*/ +int CallDlgProc(BOOL (CALLBACK *fn)(HWND,UINT,WPARAM,LPARAM), int id) +{ + int result; + + result = DialogBoxParam(hInst, MAKEINTRESOURCE(id), GetActiveWindow(), + fn, 0); + return result; +} + + +/*------------------------------------------------------------------------ + Procedure: CallChangeColor ID:1 + Purpose: Calls the standard color dialog of windows, starting + with the given color reference. The result is the + same as the input if the user cancels, or another + color if the user validates another one. + Input: The starting color + Output: The color the user has choosen. + Errors: None +------------------------------------------------------------------------*/ +static COLORREF CallChangeColor(COLORREF InitialColor) +{ + CHOOSECOLOR CC; + COLORREF CustColors[16]; + int r, g, b, i; + memset(&CC, 0, sizeof(CHOOSECOLOR)); + r = g = b = 0; + for (i = 0; i < 16; i++) { + CustColors[i] = RGB(r, g, b); + if (r < 255) + r += 127; + else if (g < 255) + g += 127; + else if (b < 255) + g += 127; + } + CC.lStructSize = sizeof(CHOOSECOLOR); + CC.hwndOwner = hwndMain; + CC.hInstance = hInst; + CC.rgbResult = InitialColor; + CC.lpCustColors = CustColors; + CC.Flags = CC_RGBINIT; + if (!ChooseColor(&CC)) + return (InitialColor); + return (CC.rgbResult); +} + +/*------------------------------------------------------------------------ + Procedure: CallPrintSetup ID:1 + Purpose: Calls the printer setup dialog. Currently it is not + connected to the rest of the software, since printing + is not done yet + Input: None + Output: 1 if OK, 0, user cancelled + Errors: None +------------------------------------------------------------------------*/ +static int CallPrintSetup(void) +{ + PAGESETUPDLG sd; + int r; + + memset(&sd,0,sizeof(sd)); + sd.lStructSize = sizeof(sd); + sd.Flags = PSD_RETURNDEFAULT; + r = PageSetupDlg(&sd); + if (!r) + return 0; + sd.Flags = 0; + r = PageSetupDlg(&sd); + return r; +} + + +/*------------------------------------------------------------------------ + Procedure: Undo ID:1 + Purpose: Send an UNDO command to the edit field. + Input: The parent window of the control + Output: None + Errors: None +------------------------------------------------------------------------*/ +void Undo(HWND hwnd) +{ + HWND hEdit; + + hEdit = (HWND)GetWindowLongPtr(hwnd,DWLP_USER); + SendMessage(hEdit,EM_UNDO,0,0); +} + +/*------------------------------------------------------------------------ + Procedure: ForceRepaint ID:1 + Purpose: Forces a complete redraw of the edit control of the + current session. + Input: None + Output: None + Errors: None +------------------------------------------------------------------------*/ +void ForceRepaint(void) +{ + HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + InvalidateRect(hwndEdit,NULL,1); +} + +/*------------------------------------------------------------------------ + Procedure: Add_Char_To_Queue ID:1 + Purpose: Puts a character onto the buffer + Input: The char to be added + Output: None + Errors: +------------------------------------------------------------------------*/ +static void Add_Char_To_Queue(int c) +{ + HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + SendMessage(hwndEdit,WM_CHAR,c,1); +} + +/*------------------------------------------------------------------------ + Procedure: AddLineToControl ID:1 + Purpose: It will ad the given text at the end of the edit + control, then it will send a return character to it. + This simulates user input. The history will not be + modified by this procedure. + Input: The text to be added + Output: None + Errors: If the line is empty, nothing will be done +------------------------------------------------------------------------*/ +void AddLineToControl(char *buf) +{ + HWND hEditCtrl; + + if (*buf == 0) + return; + + hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + + GotoEOF(); + + SendMessage(hEditCtrl,EM_REPLACESEL,0,(LPARAM)buf); + SendMessage(hEditCtrl,WM_CHAR,'\r',0); +} + +/*------------------------------------------------------------------------ + Procedure: AddStringToControl ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: It will ad the given text at the end of the edit + control. This simulates user input. The history will not + be modified by this procedure. + Input: The text to be added + Output: None + Errors: If the line is empty, nothing will be done +-------------------------------------------------------------------------- +Edit History: + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Basically this is AddLineToControl, but without appending a + newline +------------------------------------------------------------------------*/ +void AddStringToControl(char* buf) +{ + HWND hEditCtrl; + + if(buf == NULL) + return; + + if((*buf) == 0) + return; + + hEditCtrl = (HWND)GetWindowLongPtr(hwndSession, DWLP_USER); + GotoEOF(); + + SendMessage(hEditCtrl ,EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)buf); +} + +/*------------------------------------------------------------------------ + Procedure: AboutDlgProc ID:1 + Purpose: Shows the "About" dialog box + Input: + Output: + Errors: +------------------------------------------------------------------------*/ +static BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == WM_CLOSE) + EndDialog(hDlg,1); + return 0; +} + +/*------------------------------------------------------------------------ + Procedure: HistoryDlgProc ID:1 + Purpose: Shows the history of the session. Only input lines + are shown. A double click in a line will make this + dialog box procedure return the index of the selected + line (1 based). If the windows is closed (what is + equivalent to cancel), the return value is zero. + Input: Normal windows callback + Output: + Errors: +-------------------------------------------------------------------------- +Edit History: + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Added support for my StatementHistory structure + - Added the ability to export it as its exact entry, rather than + just a 1 liner +------------------------------------------------------------------------*/ +static BOOL CALLBACK HistoryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + StatementHistory *histentry; + int idx; + RECT rc; + + switch (message) { + case WM_INITDIALOG: + SendDlgItemMessage(hDlg,IDLIST,WM_SETFONT,(WPARAM)ProgramParams.hFont,0); + histentry = History; // get our statement history object + idx = 0; + + // loop through each history entry adding it to the dialog + while (histentry != NULL) { + SendDlgItemMessage(hDlg,IDLIST,LB_INSERTSTRING,0,(LPARAM)editbuffer_getasline(histentry->Statement)); + SendDlgItemMessage(hDlg,IDLIST,LB_SETITEMDATA,0,(LPARAM)idx); + histentry = histentry->Next; + idx++; + } + + SendDlgItemMessage(hDlg,IDLIST,LB_SETCURSEL,(LPARAM)idx-1,0); + return 1; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDLIST: + switch(HIWORD(wParam)) { + case LBN_DBLCLK: + idx = SendDlgItemMessage(hDlg,IDLIST,LB_GETCURSEL,0,0); + if (idx == LB_ERR) + break; + idx = SendDlgItemMessage(hDlg,IDLIST,LB_GETITEMDATA,idx,0); + EndDialog(hDlg,idx+1); + return 1; + } + break; + } + break; + case WM_SIZE: + GetClientRect(hDlg,&rc); + MoveWindow(GetDlgItem(hDlg,IDLIST),0,0,rc.right,rc.bottom,1); + break; + + case WM_CLOSE: + EndDialog(hDlg,0); + break; + } + return 0; +} + +/*------------------------------------------------------------------------ + Procedure: SaveText ID:1 + Purpose: Saves the contents of the session transcript. It will + loop for each line and write it to the specified file + Input: The name of the file where the session will be saved + Output: The session is saved + Errors: If it can't open the file for writing it will show an + error box +-------------------------------------------------------------------------- + Edit History: + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Corrected wsprintf error +------------------------------------------------------------------------*/ +static void SaveText(char *fname) +{ + int i,len; + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); + FILE *f; + char *buf = SafeMalloc(8192); + + f = fopen(fname,"wb"); + if (f == NULL) + { + // corrected error using wsprintf + wsprintf(buf, "Impossible to open %s for writing", fname); + + ShowDbgMsg(buf); + return; + } + + for (i = 0; i < linesCount; i++) + { + *(unsigned short *)buf = 8100; + len = SendMessage(hEdit, EM_GETLINE, i, (LPARAM)buf); + buf[len] = '\0'; + fprintf(f, "%s\r\n", buf+1); + //fwrite(buf,1,len+2,f); + } + + fclose(f); + free(buf); +} + +/*------------------------------------------------------------------------ + Procedure: SaveML ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Saves the ML source to a file, commenting out functions + that contained errors + Input: The name of the file where the session will be saved + Output: The session is saved + Errors: If it can't open the file for writing it will show an + error box +------------------------------------------------------------------------*/ +static void SaveML(char *fname) +{ + FILE *f; + char *buf = SafeMalloc(8192); + + f = fopen(fname, "wb"); + + if(f == NULL) + { + wsprintf(buf, "Impossible to open %s for writing", fname); + ShowDbgMsg(buf); + return; + } + + fprintf(f, "(* %s *)\r\n\r\n", fname); + + if(History != NULL) + { + StatementHistory *h = NULL; + EditBuffer *stmt = NULL; + + // get to the end + for(h = History; h->Next != NULL; h = h->Next); + + // go back :( + // this is NOT the fastest method, BUT this is the easiest + // on the subsystem + for(; h != NULL; h = h->Prev) + { + stmt = h->Statement; + + if(stmt != NULL) + { + // comment out incorrect lines + if(stmt->isCorrect) + { + char *buff = editbuffer_getasbuffer(stmt); + fprintf(f, "%s\r\n", buff); + free(buff); + } else { + char *buff = editbuffer_getasbuffer(stmt); + fprintf(f, "(* Syntax Error or Unbound Value\r\n%s\r\n *)\r\n", buff); + free(buff); + } + } + + fprintf(f, "\r\n"); + } + } + + fclose(f); + free(buf); +} + +/*------------------------------------------------------------------------ + Procedure: Add_Clipboard_To_Queue ID:1 + Author: Chris Watford watford@uiuc.edu + Purpose: Adds the clipboard text to the control + Input: + Output: + Errors: +-------------------------------------------------------------------------- + Edit History: + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Added method to update edit buffer with paste contents +------------------------------------------------------------------------*/ +static void Add_Clipboard_To_Queue(void) +{ + if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(hwndMain)) + { + HANDLE hClipData = GetClipboardData(CF_TEXT); + + if (hClipData != NULL) + { + char *str = GlobalLock(hClipData); + + if (str != NULL) + { + while ((*str) != 0) + { + if (*str != '\r') + Add_Char_To_Queue(*str); + + str++; + } + + // added to fix odd errors + RefreshCurrentEditBuffer(); + } + + GlobalUnlock(hClipData); + } + + CloseClipboard(); + } +} + +/*------------------------------------------------------------------------ + Procedure: CopyToClipboard ID:1 + Purpose: Copies text to the clipboard + Input: Window with the edit control + Output: + Errors: +------------------------------------------------------------------------*/ +static void CopyToClipboard(HWND hwnd) +{ + HWND hwndEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + SendMessage(hwndEdit,WM_COPY,0,0); +} + +/*------------------------------------------------------------------------ + Procedure: ResetText ID:1 + Purpose: Resets the text? I'm not really sure + Input: + Output: Always returns 0 + Errors: +------------------------------------------------------------------------*/ +int ResetText(void) +{ + HWND hwndEdit = (HWND) GetWindowLongPtr(hwndSession,DWLP_USER); + TEXTRANGE cr; + int len = SendMessage(hwndEdit,WM_GETTEXTLENGTH,0,0); + char *tmp = malloc(len+10),*p; + + memset(tmp,0,len+10); + cr.chrg.cpMin = 0; + cr.chrg.cpMax = -1; + cr.lpstrText = tmp; + SendMessage(hwndEdit,EM_GETTEXTRANGE,0,(LPARAM)&cr); + p = tmp+len/2; + while (*p && *p != '\r') + p++; + SendMessage(hwndEdit,EM_SETSEL,0,(LPARAM)-1); + SendMessage(hwndEdit,EM_REPLACESEL,0,(LPARAM)p); + InvalidateRect(hwndEdit,0,1); + free(tmp); + return 0; +} + +/*------------------------------------------------------------------------ + Procedure: HandleCommand ID:1 + Purpose: Handles all menu commands. + Input: + Output: + Errors: +-------------------------------------------------------------------------- + Edit History: + 06 Oct 2003 - Chris Watford watford@uiuc.edu + - Removed entries that crashed OCaml + - Removed useless entries + - Added Save ML and Save Transcript +------------------------------------------------------------------------*/ +void HandleCommand(HWND hwnd, WPARAM wParam,LPARAM lParam) +{ + char *fname; + int r; + + switch(LOWORD(wParam)) { + case IDM_OPEN: + fname = SafeMalloc(512); + if (OpenMlFile(fname,512)) { + char *buf = SafeMalloc(512); + char *p = strrchr(fname,'.'); + if (p && !stricmp(p,".ml")) { + wsprintf(buf, "#use \"%s\";;", fname); + AddLineToControl(buf); + } + else if (p && !stricmp(p,".cmo")) { + wsprintf(buf, "#load \"%s\";;", fname); + AddLineToControl(buf); + } + free(buf); + } + free(fname); + break; + case IDM_GC: + AddLineToControl("Gc.full_major();;"); + break; + case IDCTRLC: + InterruptOcaml(); + break; + case IDM_EDITPASTE: + Add_Clipboard_To_Queue(); + break; + case IDM_EDITCOPY: + CopyToClipboard(hwnd); + break; + + // updated to save a transcript + case IDM_SAVEAS: + fname = SafeMalloc(512); + if (GetSaveName(fname,512)) { + SaveText(fname); + } + free(fname); + break; + + // updated to save an ML file + case IDM_SAVE: + fname = SafeMalloc(512); + if (GetSaveMLName(fname,512)) + { + SaveML(fname); + } + free(fname); + break; + + // updated to work with new history system + case IDM_HISTORY: + r = CallDlgProc(HistoryDlgProc,IDD_HISTORY); + + if (r) + { + AddLineToControl(GetHistoryLine(r-1)); + } + break; + + case IDM_PRINTSU: + // Removed by Chris Watford + // seems to die + // CallPrintSetup(); + break; + + case IDM_FONT: + CallChangeFont(hwndMain); + break; + case IDM_COLORTEXT: + ProgramParams.TextColor = CallChangeColor(ProgramParams.TextColor); + ForceRepaint(); + break; + case IDM_BACKCOLOR: + BackColor = CallChangeColor(BackColor); + DeleteObject(BackgroundBrush); + BackgroundBrush = CreateSolidBrush(BackColor); + ForceRepaint(); + break; + case IDM_EDITUNDO: + Undo(hwnd); + break; + + /* Removed, really not very useful in this IDE + case IDM_WINDOWTILE: + SendMessage(hwndMDIClient,WM_MDITILE,0,0); + break; + case IDM_WINDOWCASCADE: + SendMessage(hwndMDIClient,WM_MDICASCADE,0,0); + break; + case IDM_WINDOWICONS: + SendMessage(hwndMDIClient,WM_MDIICONARRANGE,0,0); + break; + */ + + case IDM_EXIT: + PostMessage(hwnd,WM_CLOSE,0,0); + break; + case IDM_ABOUT: + CallDlgProc(AboutDlgProc,IDD_ABOUT); + break; + default: + if (LOWORD(wParam) >= IDEDITCONTROL && LOWORD(wParam) < IDEDITCONTROL+5) { + switch (HIWORD(wParam)) { + case EN_ERRSPACE: + ResetText(); + break; + } + } + break; + } +} diff --git a/win32caml/ocaml.c b/win32caml/ocaml.c new file mode 100644 index 0000000..7419286 --- /dev/null +++ b/win32caml/ocaml.c @@ -0,0 +1,1599 @@ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia. */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +/* $Id: ocaml.c,v 1.9 2006-05-09 16:03:48 xleroy Exp $ */ + +/*@@ Wedit generated application. Written Sat Jun 02 18:22:38 2001 +@@header: D:\lcc\inria\inriares.h +@@resources: D:\lcc\inria\inria.rc +Do not edit outside the indicated areas */ +/*<---------------------------------------------------------------------->*/ + +#include <stdio.h> +#include <windows.h> +#include <windowsx.h> +#include <commctrl.h> +#include <string.h> +#include <direct.h> +#include <Richedit.h> +#include "inriares.h" +#include "inria.h" + +#define VK_BACKSPACE 0x108 + +/*<---------------------------------------------------------------------->*/ +int EditControls = IDEDITCONTROL; +static WNDPROC lpEProc; +static char lineBuffer[1024*32]; +int ReadToLineBuffer(void); +int AddLineBuffer(void); +static int busy; +static DWORD TimerId; +POSITION LastPromptPosition; +char LibDir[512]; +char OcamlPath[512]; +HBRUSH BackgroundBrush; +COLORREF BackColor = RGB(255,255,255); +PROGRAM_PARAMS ProgramParams; +StatementHistory *History = NULL; +StatementHistory *HistoryTail = NULL; +StatementHistory *historyEntry = NULL; +EditBuffer *CurrentEditBuffer = NULL; // current edit buffer + +/*<----------------- global variables --------------------------------------->*/ +HANDLE hInst; // Instance handle +HWND hwndMain; //Main window handle +HWND hwndSession; +HWND hwndMDIClient; //Mdi client window handle +static LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam); +static LRESULT CALLBACK MdiChildWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam); +PROCESS_INFORMATION pi; +HWND hWndStatusbar; + +/*------------------------------------------------------------------------ +Procedure: UpdateStatusBar ID:1 +Purpose: Updates the statusbar control with the appropiate +text +Input: lpszStatusString: Charactar string that will be shown +partNumber: index of the status bar part number. +displayFlags: Decoration flags +Output: none +Errors: none + +------------------------------------------------------------------------*/ +void UpdateStatusBar(LPSTR lpszStatusString, WORD partNumber, WORD displayFlags) +{ + SendMessage(hWndStatusbar, + SB_SETTEXT, + partNumber | displayFlags, + (LPARAM)lpszStatusString); +} + + +/*------------------------------------------------------------------------ +Procedure: MsgMenuSelect ID:1 +Purpose: Shows in the status bar a descriptive explaation of +the purpose of each menu item.The message +WM_MENUSELECT is sent when the user starts browsing +the menu for each menu item where the mouse passes. +Input: Standard windows. +Output: The string from the resources string table is shown +Errors: If the string is not found nothing will be shown. +------------------------------------------------------------------------*/ +LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) +{ + static char szBuffer[256]; + UINT nStringID = 0; + UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff; + UINT uCmd = GET_WM_MENUSELECT_CMD(wparam, lparam); + HMENU hMenu = GET_WM_MENUSELECT_HMENU(wparam, lparam); + + szBuffer[0] = 0; // First reset the buffer + if (fuFlags == 0xffff && hMenu == NULL) // Menu has been closed + nStringID = 0; + + else if (fuFlags & MFT_SEPARATOR) // Ignore separators + nStringID = 0; + + else if (fuFlags & MF_POPUP) // Popup menu + { + if (fuFlags & MF_SYSMENU) // System menu + nStringID = IDS_SYSMENU; + else + // Get string ID for popup menu from idPopup array. + nStringID = 0; + } // for MF_POPUP + else // Must be a command item + nStringID = uCmd; // String ID == Command ID + + // Load the string if we have an ID + if (0 != nStringID) + LoadString(hInst, nStringID, szBuffer, sizeof(szBuffer)); + // Finally... send the string to the status bar + UpdateStatusBar(szBuffer, 0, 0); + return 0; +} + +/*------------------------------------------------------------------------ +Procedure: TimerProc ID:1 +Purpose: This procedure will be called by windows about 4 +times a second. It will just send a message to the +mdi child window to look at the pipe. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +static VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) +{ + SendMessage(hwndSession, WM_TIMERTICK, 0, 0); +} + +/*------------------------------------------------------------------------ +Procedure: InitializeStatusBar ID:1 +Purpose: Initialize the status bar +Input: hwndParent: the parent window +nrOfParts: The status bar can contain more than one +part. What is difficult, is to figure out how this +should be drawn. So, for the time being only one is +being used... +Output: The status bar is created +Errors: +------------------------------------------------------------------------*/ +void InitializeStatusBar(HWND hwndParent,int nrOfParts) +{ + const int cSpaceInBetween = 8; + int ptArray[40]; // Array defining the number of parts/sections + RECT rect; + HDC hDC; + + /* * Fill in the ptArray... */ + + hDC = GetDC(hwndParent); + GetClientRect(hwndParent, &rect); + + ptArray[nrOfParts-1] = rect.right; + //---TODO--- Add code to calculate the size of each part of the status + // bar here. + + ReleaseDC(hwndParent, hDC); + SendMessage(hWndStatusbar, + SB_SETPARTS, + nrOfParts, + (LPARAM)(LPINT)ptArray); + + UpdateStatusBar("Ready", 0, 0); +} + + +/*------------------------------------------------------------------------ +Procedure: CreateSBar ID:1 +Purpose: Calls CreateStatusWindow to create the status bar +Input: hwndParent: the parent window +initial text: the initial contents of the status bar +Output: +Errors: +------------------------------------------------------------------------*/ +static BOOL CreateSBar(HWND hwndParent,char *initialText,int nrOfParts) +{ + hWndStatusbar = CreateStatusWindow(WS_CHILD | WS_VISIBLE | WS_BORDER|SBARS_SIZEGRIP, + initialText, + hwndParent, + IDM_STATUSBAR); + if(hWndStatusbar) + { + InitializeStatusBar(hwndParent,nrOfParts); + return TRUE; + } + + return FALSE; +} +/*------------------------------------------------------------------------ +Procedure: InitApplication ID:1 +Purpose: Registers two window classes: the "inria" window +class with the main window, and the mdi child +window's window class. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +static BOOL InitApplication(void) +{ + WNDCLASS wc; + + memset(&wc,0,sizeof(WNDCLASS)); + wc.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ; + wc.lpfnWndProc = (WNDPROC)MainWndProc; + wc.hInstance = hInst; + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wc.lpszClassName = "inriaWndClass"; + wc.lpszMenuName = MAKEINTRESOURCE(IDMAINMENU); + wc.hCursor = LoadCursor(NULL,IDC_ARROW); + wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(OCAML_ICON)); + if (!RegisterClass(&wc)) + return 0; + wc.style = 0; + wc.lpfnWndProc = (WNDPROC)MdiChildWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 20; + wc.hInstance = hInst; // Owner of this class + wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(OCAML_ICON)); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color + wc.lpszMenuName = NULL; + wc.lpszClassName = "MdiChildWndClass"; + if (!RegisterClass((LPWNDCLASS)&wc)) + return FALSE; + return 1; +} + +/*------------------------------------------------------------------------ +Procedure: CreateinriaWndClassWnd ID:1 +Purpose: Creates the main window +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +HWND CreateinriaWndClassWnd(void) +{ + return CreateWindow("inriaWndClass","OCamlWinPlus v1.9RC4", + WS_MINIMIZEBOX|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_THICKFRAME, + CW_USEDEFAULT,0,CW_USEDEFAULT,0, + NULL, + NULL, + hInst, + NULL); +} + +/*------------------------------------------------------------------------ +Procedure: MDICmdFileNew ID:1 +Purpose: Creates a new session window. Note that multiple +windows with multiple sessions are possible. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +static HWND MDICmdFileNew(char *title, int show) +{ + HWND hwndChild; + char rgch[150]; + static int cUntitled; + MDICREATESTRUCT mcs; + + if (title == NULL) + wsprintf(rgch,"Session%d", cUntitled++); + else { + strncpy(rgch,title,149); + rgch[149] = 0; + } + + // Create the MDI child window + + mcs.szClass = "MdiChildWndClass"; // window class name + mcs.szTitle = rgch; // window title + mcs.hOwner = hInst; // owner + mcs.x = CW_USEDEFAULT; // x position + mcs.y = CW_USEDEFAULT; // y position + mcs.cx = CW_USEDEFAULT; // width + mcs.cy = CW_USEDEFAULT; // height + mcs.style = 0; // window style + mcs.lParam = 0; // lparam + + hwndChild = (HWND) SendMessage(hwndMDIClient, + WM_MDICREATE, + 0, + (LPARAM)(LPMDICREATESTRUCT) &mcs); + + if (hwndChild != NULL && show) + ShowWindow(hwndChild, SW_SHOW); + + return hwndChild; +} +static HWND CreateMdiClient(HWND hwndparent) +{ + CLIENTCREATESTRUCT ccs = {0}; + HWND hwndMDIClient; + int icount = GetMenuItemCount(GetMenu(hwndparent)); + + // Find window menu where children will be listed + ccs.hWindowMenu = GetSubMenu(GetMenu(hwndparent), icount-2); + ccs.idFirstChild = IDM_WINDOWCHILD; + + // Create the MDI client filling the client area + hwndMDIClient = CreateWindow("mdiclient", + NULL, + WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | + WS_HSCROLL, + 0, 0, 0, 0, + hwndparent, + (HMENU)0xCAC, + hInst, + (LPVOID)&ccs); + + ShowWindow(hwndMDIClient, SW_SHOW); + + return hwndMDIClient; +} + +void GotoEOF(void) +{ + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0); + int lastLineLength = SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0); + + lineindex += lastLineLength; + SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); +} + +/*------------------------------------------------------------------------ +Procedure: GotoPrompt ID:1 +Author: Chris Watford watford@uiuc.edu +Purpose: Puts the cursor on the prompt line right after the '# ' +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +void GotoPrompt(void) +{ + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0)+2; + SendMessage(hEdit,EM_SETSEL,lineindex,lineindex); +} + +int GetCurLineIndex(HWND hEdit) +{ + return SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); +} + +int GetNumberOfLines(HWND hEdit) +{ + return SendMessage(hEdit,EM_GETLINECOUNT,0,0); +} + +static int GetWordUnderCursor(HWND hwndEditControl,char *buf,int len) +{ + char *line,*p,*pstart,*pend; + int lineidx,start,end,length,offset,cursorpos,startingChar; + + SendMessage(hwndEditControl,EM_GETSEL,(WPARAM)&start,(LPARAM)&end); + lineidx = SendMessage(hwndEditControl,EM_EXLINEFROMCHAR,0,start); + startingChar = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); + start -= startingChar; + end -= startingChar; + lineidx = SendMessage(hwndEditControl,EM_LINEFROMCHAR,start,0); + length = SendMessage(hwndEditControl,EM_LINELENGTH,lineidx,0); + offset = SendMessage(hwndEditControl,EM_LINEINDEX,lineidx,0); + line = SafeMalloc(length+1); + memset(line,0,length+1); + *(unsigned short *)line = length; + SendMessage(hwndEditControl,EM_GETLINE,lineidx,(LPARAM)line); + cursorpos = start-offset; + p = line + cursorpos; + pstart = p; + while (*pstart + && *pstart != ' ' + && *pstart != '\t' + && *pstart != '(' + && pstart > line) + pstart--; + pend = p; + while (*pend + && *pend != ' ' + && *pend != '\t' + && *pend != '(' + && pend < line + length) + pend++; + if (*pstart == ' ' || *pstart == '\t') + pstart++; + if (*pend == ' ' || *pend == '\t') + pend--; + memcpy(buf,pstart,1+pend-pstart); + buf[pend-pstart] = 0; + free(line); + return 1; +} + +/*------------------------------------------------------------------------ +Procedure: GetLastLine ID:1 +Purpose: Gets the data in the line containing the cursor to + the interpreter. +Input: The edit control window handle +Output: None explicit +Errors: None +------------------------------------------------------------------------*/ +char* GetLastLine(HWND hEdit) +{ + int curline = GetCurLineIndex(hEdit); + char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); + int n; + int linescount = GetNumberOfLines(hEdit); + + *(unsigned short *)linebuffer = 2047; + n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); + + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + + linebuffer[n] = '\0'; + + return linebuffer; +} + +void DoHelp(HWND hwnd) +{ + char word[256]; + GetWordUnderCursor(hwnd,word,sizeof(word)); + MessageBox(NULL,word,"Aide pour:",MB_OK); +} + +/*------------------------------------------------------------------------ +Procedure: RewriteCurrentEditBuffer ID:1 +Purpose: Rewrites what is at the prompt with the current contents of + the edit buffer +Input: None +Output: None explicit +Errors: None +------------------------------------------------------------------------*/ +void RewriteCurrentEditBuffer(void) +{ + // get the editbox's handle + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + + // calculate what to highlight + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0); + int lineindex = SendMessage(hEdit,EM_LINEINDEX,LastPromptPosition.line,0) + 2; + int lastLine = SendMessage(hEdit,EM_LINEINDEX,linesCount-1,0) + SendMessage(hEdit,EM_LINELENGTH,linesCount-1,0) + 100; + + // delete the current text + SendMessage(hEdit, EM_SETSEL, (WPARAM)lineindex, (LPARAM)lastLine); + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)""); + + { + // loop through each line in the edit buffer and add it to the control + LineList* line = CurrentEditBuffer->Lines; + for(; line != NULL; line = line->Next) + { + // if there is a line before me, add a newline + if(line->Prev != NULL) + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)"\r\n"); + + // add the line + SendMessage(hEdit, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)line->Text); + } + } +} + +/*------------------------------------------------------------------------ +Procedure: RefreshCurrentEditBuffer ID:1 +Purpose: Rewrites what is in the CurrentEditBuffer with what is + actually there +Input: None +Output: None explicit +Errors: None +------------------------------------------------------------------------*/ +void RefreshCurrentEditBuffer(void) +{ + // get the editbox's handle + HWND hEdit = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + + // get the last line index + int linesCount = SendMessage(hEdit,EM_GETLINECOUNT,0,0) - 1; + int i = 0, n = 0; + + // where to hold the line we grab + char *linebuffer = (char*)SafeMalloc(2048*sizeof(char)); + *(unsigned short *)linebuffer = 2047; + + editbuffer_destroy(CurrentEditBuffer); + CurrentEditBuffer = editbuffer_new(); + + // loop through each line updating or adding it to the current edit buffer + for( ; (i + LastPromptPosition.line) <= linesCount; i++) + { + n = SendMessage(hEdit, EM_GETLINE, (i + LastPromptPosition.line), (LPARAM)linebuffer); + + if ((n >= 2) && (linebuffer[0] == '#') && (linebuffer[1] == ' ')) { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + + linebuffer[n] = '\0'; + + { // remove line breaks and feeds + char* ln = linebuffer; + + while((*ln) != 0) + { + switch((*ln)) + { + case '\r': + case '\n': + (*ln) = ' '; + } + + ln++; + } + } + + editbuffer_addline(CurrentEditBuffer, linebuffer); + } +} + +/*------------------------------------------------------------------------ +Procedure: NextHistoryEntry ID:1 +Purpose: Scrolls to the next history entry +Input: None +Output: None explicit +Errors: None +-------------------------------------------------------------------------- +Edit History: + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added this as a helper function + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list problems +------------------------------------------------------------------------*/ +void NextHistoryEntry(void) +{ + // out of bounds, put it back into bounds + if(historyEntry == NULL && History == NULL) + { + return; + } else if (historyEntry == NULL && History != NULL) { + historyEntry = History; + } else { + if(historyEntry->Next == NULL) + return; + + historyEntry = historyEntry->Next; + } + + // if its valid + if(historyEntry != NULL) + { + // copy the history entry to a new buffer + EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); + + // destroy the old buffer + editbuffer_destroy(CurrentEditBuffer); + + // setup the current one to the copy + CurrentEditBuffer = newBuf; + + // rewrite the old one and go to the prompt + RewriteCurrentEditBuffer(); + GotoPrompt(); + } +} + +/*------------------------------------------------------------------------ +Procedure: PrevHistoryEntry ID:1 +Purpose: Scrolls to the previous history entry +Input: None +Output: None explicit +Errors: None +-------------------------------------------------------------------------- +Edit History: + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added this as a helper function + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Corrected doubly linked list problems +------------------------------------------------------------------------*/ +void PrevHistoryEntry(void) +{ + // out of bounds, put it back into bounds + if(historyEntry == NULL || History == NULL) + { + return; + } else { + if(historyEntry->Prev == NULL) + return; + + historyEntry = historyEntry->Prev; + } + + // if its valid + if(historyEntry != NULL) + { + // copy the history entry to a new buffer + EditBuffer* newBuf = editbuffer_copy(historyEntry->Statement); + + // destroy the old buffer + editbuffer_destroy(CurrentEditBuffer); + + // setup the current one to the copy + CurrentEditBuffer = newBuf; + + // rewrite the old one and go to the prompt + RewriteCurrentEditBuffer(); + GotoPrompt(); + } +} + +/*------------------------------------------------------------------------ +Procedure: SubClassEdit ID:1 +Purpose: Handles messages to the editbox +Input: +Output: +Errors: +-------------------------------------------------------------------------- +Edit History: + 14 Sept 2003 - Chris Watford watford@uiuc.edu + - Setup handler for up and down arrows + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Setup framework for history on up arrow + - Saves lines you move off of in the edit buffer + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Proper handling of newline message finished + - Fixed ENTER on middle of interior line, moves cursor to the end + and sends the line + - Setup the copying and destroying of the old buffer + - Included buffer rewrite + 17 Sept 2003 - Chris Watford watford@uiuc.edu + - Added C-p/C-n support + - Changed UpArrow to C-UpArrow so as to not confuse users + 18 Sept 2003 - Chris Watford watford@uiuc.edu + - Added Left and Right arrow line saving + - Added backspace and delete line saving and removing + - Fixed history scrolling + 21 Sept 2003 - Chris Watford watford@uiuc.edu + - Fixed pasting errors associated with lines being out of bounds + for the buffer + - Added error handling, possibly able to handle it diff down the + line + - Removed C-Up/C-Dn for history scrolling, buggy at best on my + machine +------------------------------------------------------------------------*/ +static LRESULT CALLBACK SubClassEdit(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) +{ + LRESULT r; + int postit=0,nl; + + if (msg == WM_CHAR && mp1 == '\r') { + if (!busy) { + r = GetCurLineIndex(hwnd); + nl = GetNumberOfLines(hwnd); + + // if we're not the last line + if (r != nl-1) + { + // update or add us, we might not have any lines in the edit buffer + editbuffer_updateoraddline(CurrentEditBuffer, r-LastPromptPosition.line, GetLastLine(hwnd)); + + // scroll to the end, add CrLf then post the newline message + GotoEOF(); + AddStringToControl("\r\n"); + PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); + return 0; + } + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + postit = 1; + } + + } + else if (msg == WM_CHAR && mp1 == (char)0x08) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); + + if(curpoint <= lineindex) + { + return 0; + } else if(nextline != curline) { + // delete the line we're on + + // grab the index + curline -= LastPromptPosition.line; + + // kill it + editbuffer_removeline(CurrentEditBuffer, curline); + } + } + else if (msg == WM_KEYDOWN && mp1 == VK_F1) { + DoHelp(hwnd); + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && mp1 == VK_UP) { + int curline = GetCurLineIndex(hwnd); + + /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) + { // go forward once in history + NextHistoryEntry(); + return 0; + } else */ + if((curline > LastPromptPosition.line) && (curline <= (LastPromptPosition.line + CurrentEditBuffer->LineCount))) + { + // update current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + // we may have to add this line, otherwise update it + editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } else { + return 0; + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_LEFT)) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0); + + if(curpoint <= lineindex) + { // no left arrow to the left of the prompt + return 0; + } else if(nextline != curline) { + // update current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + // we may have to add this line, otherwise update it + editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_HOME,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_HOME,1); + } + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DOWN)) { + int curline = GetCurLineIndex(hwnd); + + /*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000)) + { // go back once in history + PrevHistoryEntry(); + return 0; + } else*/ + if((curline >= LastPromptPosition.line) && (curline < (LastPromptPosition.line + CurrentEditBuffer->LineCount))) + { + // We don't post the newline, but instead update the current line + if (msg == WM_KEYDOWN) + { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } else { + return 0; + } + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_RIGHT)) { + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 1; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); + + if(curpoint <= lineindex) + { // no movement behind the prompt + return 0; + } else if((nextline != curline) && (msg = WM_KEYDOWN)) { + int lineidx = (curline - LastPromptPosition.line); + + CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1); + CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1); + + editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd)); + } + } + else if ((msg == WM_KEYDOWN) && (mp1 == VK_PRIOR) && (GetKeyState(VK_CONTROL) && 0x8000)) { + // C-p + NextHistoryEntry(); + return 0; + } + else if ((msg == WM_KEYDOWN) && (mp1 == VK_NEXT) && (GetKeyState(VK_CONTROL) && 0x8000)) { + // C-n + PrevHistoryEntry(); + return 0; + } + else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DELETE)) { + // see if we're the last char on the line, if so delete the next line + // don't allow deleting left of the prompt + int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0); + int nextline = 0; + int curpoint = 0; + + SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); + nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0); + + if(curpoint < lineindex) + { // no chomping behind the prompt + return 0; + } else if(nextline != curline) { + // deleting + // grab the next line index + curline -= LastPromptPosition.line; + + // kill it + editbuffer_removeline(CurrentEditBuffer, curline+1); + } + } + else if (msg == WM_PASTE) { + // if they paste text, allow it + r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); + + // update the current edit buffer + RefreshCurrentEditBuffer(); + + return r; + } + + // handle errors + switch(msg) + { + case WM_SYNTAXERROR: + case WM_ILLEGALCHAR: + case WM_UNBOUNDVAL: + { // currently I handle them all the same + // get the start of the line + int start = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2; + + // get the statement that error'd + NextHistoryEntry(); + + // tell the history that the last line errored + if(History != NULL) + if(History->Statement != NULL) + History->Statement->isCorrect = FALSE; + + // highlight the offending chars + SendMessage(hwnd,EM_SETSEL,(WPARAM)(start + mp1), (LPARAM)(start + mp2)); + + return 0; + } + } + + r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2); + + if (postit) + PostMessage(GetParent(hwnd),WM_NEWLINE,0,0); + + return r; +} + +static void SubClassEditField(HWND hwnd) +{ + if (lpEProc == NULL) { + lpEProc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); + } + SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) SubClassEdit); +} + +/*------------------------------------------------------------------------ +Procedure: SendLastLine ID:1 +Purpose: Sends the data in the line containing the cursor to +the interpreter. If this is NOT the last line, copy +the line to the end of the text. +Input: The edit control window handle +Output: None explicit +Errors: None + +REMOVED! +------------------------------------------------------------------------*/ +void SendLastLine(HWND hEdit) +{ +/* int curline = GetCurLineIndex(hEdit); + char *p,linebuffer[2048]; + int n; + int linescount = GetNumberOfLines(hEdit); + + *(unsigned short *)linebuffer = sizeof(linebuffer)-1; + if (curline != linescount-1) + n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer); + else + n = SendMessage(hEdit,EM_GETLINE,curline-1,(LPARAM)linebuffer); + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + linebuffer[n] = 0; + + // Record user input! + AddToHistory(linebuffer); + linebuffer[n] = '\n'; + linebuffer[n+1] = 0; + WriteToPipe(linebuffer); + if (curline != linescount-1) { + // Copy the line sent to the end of the text + p = strrchr(linebuffer,'\n'); + if (p) { + *p = 0; + } + busy = 1; + AddLineToControl(linebuffer); + busy = 0; + }*/ +} + +/*------------------------------------------------------------------------ +Procedure: SendLastEditBuffer ID:1 +Author: Chris Watford watford@uiuc.edu +Purpose: Sends an edit buffer to the pipe +Input: +Output: +Errors: +-------------------------------------------------------------------------- +Edit History: + 7 Aug 2004 - Chris Watford christopher.watford@gmail.com + - Fixed error where SendLastEditBuffer sent waaaay too many + newlines which completely broke the underlying connection to the + ocaml.exe pipe + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Sends line to the pipe and adds newline to the end +------------------------------------------------------------------------*/ +void SendLastEditBuffer(HWND hwndChild) +{ + char* line = editbuffer_getasbuffer(CurrentEditBuffer); + int l = strlen(line) - 1; + char* linebuffer = (char*)SafeMalloc(l+2); + + // save current edit buffer to history and create a new blank edit buffer + CurrentEditBuffer->isCorrect = TRUE; + AddToHistory(CurrentEditBuffer); + CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + CurrentEditBuffer->LineCount = 0; + CurrentEditBuffer->Lines = NULL; + + // trim and add the newline to the end + strncpy(linebuffer, line, l+1); + while((linebuffer[l] == '\n' || linebuffer[l] == '\r') && (l >= 0)) + { + linebuffer[l--] = '\0'; + } + + linebuffer[l+1] = '\n'; + linebuffer[l+2] = '\0'; + + // save line to the pipe + WriteToPipe(linebuffer); +} + +/*------------------------------------------------------------------------ +Procedure: SendingFullCommand ID:1 +Author: Chris Watford watford@uiuc.edu +Purpose: Returns if the command being sent +Input: The edit control window handle +Output: None explicit +Errors: None +-------------------------------------------------------------------------- +Edit History: + 7 Aug 2004 - Chris Watford christopher.watford@gmail.com + - Fixed bug #2932 where many carraige returns were sent and it came + back with a null pointer error due to a fault of not checking if + the line returned was NULL + 13 Oct 2003 - Chris Watford watford@uiuc.edu + - Solved the error when you have a malformed comment in the buffer +------------------------------------------------------------------------*/ +BOOL SendingFullCommand(void) +{ + // if there is a ;; on the line, return true + char *line = editbuffer_getasline(CurrentEditBuffer); + char *firstComment, *firstSemiColonSemiColon, *firstQuote; + + if(line == NULL) + { + return FALSE; + } + + firstComment = strstr(line, "(*"); + firstSemiColonSemiColon = strstr(line, ";;"); + firstQuote = strstr(line, "\""); + + // easy case :D + if(firstSemiColonSemiColon == NULL) + { + free(line); + return FALSE; + } + + // if there are no comments + if(firstComment == NULL) + { + // if there are no quotations used + if(firstQuote == NULL) + { + BOOL r = (firstSemiColonSemiColon != NULL); + free(line); + return r; + } else { + // we need to first check if the ;; is before the \", since the \" + // won't matter if its before the semicolonsemicolon + if(firstQuote < firstSemiColonSemiColon) + { + // the quote is before the ;;, we need to make sure its terminated + // also we have to check for escaped quotes, le sigh! + char *c = firstQuote+1; + BOOL in_quote = TRUE; + + // in-quote determiner loop + while(c[0] != '\0') + { + // are we a backslash? + if(c[0] == '\\') + { + // ignore the next character + c++; + } + else + { + // are we a quote? + if(c[0] == '"') + { + in_quote = !in_quote; + } + } + + c++; + } + + free(line); + return !in_quote; + } else { + BOOL r = (firstSemiColonSemiColon != NULL); + free(line); + return r; + } + } + } else { + // we have to search through finding all comments + + // a neat little trick we can do is compare the point at which + // the ;; is and where the first (* can be found, if the ;; is + // before the (* ocaml.exe ignores the comment + if((unsigned int)firstSemiColonSemiColon < (unsigned int)firstComment) + { + free(line); + return TRUE; + } else { + // time to search and find if the endline is inside a comment or not + // start at the first comment, and move forward keeping track of the + // nesting level, if the nest level is 0, i.e. outside a comment + // and we find the ;; return TRUE immediately, otherwise keep searching + // if we end with a nest level >0 return FALSE + + char *c = firstComment+2; // firstComment[0] is the '(', firstComment[1] is the '*' + int nestLevel = 1; // we have a (* + + // in-comment determiner loop + while(c[0] != '\0') + { + // are we an endline + if((c[0] == ';') && (c[1] == ';')) + { + // if we are NOT in a comment, its a full line + if(nestLevel <= 0) + { + free(line); + return TRUE; + } + } + + // are we in a comment? + if((c[0] == '(') && (c[1] == '*')) + { + nestLevel++; + + // watch out we may go past the end + if(c[2] == '\0') + { + free(line); + return FALSE; + } + + // c needs to advance past the *, cause (*) is NOT the start/finish of a comment + c++; + } + + // adjust the nesting down a level + if((c[0] == '*') && (c[1] == ')')) + nestLevel--; + + // next char + c++; + } + + // not a full line + free(line); + return FALSE; + } + } + + // weird case ;) + free(line); + return FALSE; +} + +/*------------------------------------------------------------------------ +Procedure: AppendToEditBuffer ID:1 +Author: Chris Watford watford@uiuc.edu +Purpose: Add a line to the edit buffer +Input: Handle of the edit control +Output: +Errors: +------------------------------------------------------------------------*/ +void AppendToEditBuffer(HWND hEdit) +{ + char *p = NULL, linebuffer[2048]; + int n = 0; + int curline = GetCurLineIndex(hEdit); + int linescount = GetNumberOfLines(hEdit); + + // they are passing the size of the buffer as + // the first 'short' in the array... + *(unsigned short *)linebuffer = sizeof(linebuffer)-1; + + if (curline > (linescount-1)) + { + n = SendMessage(hEdit, EM_GETLINE, curline, (LPARAM)linebuffer); + } else { + n = SendMessage(hEdit, EM_GETLINE, --curline, (LPARAM)linebuffer); + } + + // correct for the prompt line + if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') + { + n -= 2; + memmove(linebuffer, linebuffer+2, n); + } + + linebuffer[n] = '\0'; + + // linebuffer now has the line to add to our edit buffer + editbuffer_updateoraddline(CurrentEditBuffer, (curline - LastPromptPosition.line), linebuffer); +} + +/*------------------------------------------------------------------------ +Procedure: SetLastPrompt ID:1 +Purpose: Record the position of the last prompt ("# ") sent by +the interpreter. This isn't really used yet. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +void SetLastPrompt(HWND hEdit) +{ + DWORD startpos,endpos; + SendMessage(hEdit,EM_GETSEL,(WPARAM)&startpos,(LPARAM)&endpos); + LastPromptPosition.line = SendMessage(hEdit,EM_LINEFROMCHAR,(WPARAM)-1,0); + LastPromptPosition.col = startpos; +} + +/*------------------------------------------------------------------------ +Procedure: MdiChildWndProc ID:1 +Purpose: The edit control is enclosed in a normal MDI window. +This is the window procedure for that window. When it +receives the WM_CREATE message, it will create the +edit control. +Input: +Output: +Errors: +-------------------------------------------------------------------------- +Edit History: + 14 Sept 2003 - Chris Watford watford@uiuc.edu + - Added edit buffer and statement buffer support to the WM_NEWLINE + message. + 15 Sept 2003 - Chris Watford watford@uiuc.edu + - Got it adding to the edit buffer + 16 Sept 2003 - Chris Watford watford@uiuc.edu + - Proper handling of newline message finished + 21 Sept 2003 - Chris Watford watford@uiuc.edu + - Added error detection on return from ocaml interp + 23 Sept 2003 - Chris Watford watford@uiuc.edu + - Fixed prompt detection error as pointed out by Patrick Meredith +------------------------------------------------------------------------*/ +static LRESULT CALLBACK MdiChildWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) +{ + HWND hwndChild; + RECT rc; + HDC hDC; + + switch(msg) { + case WM_CREATE: + GetClientRect(hwnd,&rc); + hwndChild= CreateWindow("EDIT", + NULL, + WS_CHILD | WS_VISIBLE | + ES_MULTILINE | + WS_VSCROLL | WS_HSCROLL | + ES_AUTOHSCROLL | ES_AUTOVSCROLL, + 0, + 0, + (rc.right-rc.left), + (rc.bottom-rc.top), + hwnd, + (HMENU) EditControls++, + hInst, + NULL); + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) hwndChild); + SendMessage(hwndChild, WM_SETFONT, (WPARAM) ProgramParams.hFont, 0L); + SendMessage(hwndChild,EM_LIMITTEXT,0xffffffff,0); + SubClassEditField(hwndChild); + break; + // Resize the edit control + case WM_SIZE: + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + MoveWindow(hwndChild, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE); + break; + // Always set the focus to the edit control. + case WM_SETFOCUS: + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + SetFocus(hwndChild); + break; + // Repainting of the edit control about to happen. + // Set the text color and the background color + case WM_CTLCOLOREDIT: + hDC = (HDC)wparam; + SetTextColor(hDC,ProgramParams.TextColor); + SetBkColor(hDC,BackColor); + return (LRESULT)BackgroundBrush; + // Take care of erasing the background color to avoid flicker + case WM_ERASEBKGND: + GetWindowRect(hwnd,&rc); + hDC = (HDC)wparam; + FillRect(hDC,&rc,BackgroundBrush); + return 1; + // A carriage return has been pressed. Send the data to the interpreted. + // This message is posted by the subclassed edit field. + case WM_COMMAND: + if (LOWORD(wparam) >= IDEDITCONTROL && LOWORD(wparam) < IDEDITCONTROL+5) { + switch (HIWORD(wparam)) { + case EN_ERRSPACE: + case EN_MAXTEXT: + ResetText(); + break; + } + } + break; + case WM_NEWLINE: + if (busy) + break; + + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + + // add what they wrote to the edit buffer + AppendToEditBuffer(hwndChild); + + /** Modified by Chris Watford 14 Sept 2003, 15 Sept 2003, 16 Sept 2003 **/ + // test if this line has an end or if it needs to be in the Edit Buffer + if(SendingFullCommand()) + { + // send the edit buffer to the interpreter + //SendLastLine(hwndChild); + SendLastEditBuffer(hwndChild); + historyEntry = NULL; + } else { + AddStringToControl(" "); + } + /** End Modifications **/ + + break; + // The timer will call us 4 times a second. Look if the interpreter + // has written something in its end of the pipe. + case WM_TIMERTICK: + /** Modified by Chris Watford 21 Sept 2003 **/ + hwndChild = (HWND) GetWindowLongPtr(hwnd, DWLP_USER); + + if (ReadToLineBuffer()) + { + int errMsg = 0; + char *p, *l = lineBuffer; + + // Ok we read something. Display the trimmed version + while(((*l) == ' ') || ((*l) == '\t') || ((*l) == '\n') || ((*l) == '\r') || ((*l) == '*')) + l++; + + SendMessage(hwndChild,EM_REPLACESEL,0,(LPARAM)l); + + // fix bug where it won't find prompt + p = strrchr(l, '\r'); + if((l[0] == '#') || (p != NULL)) + { + if(p != NULL) + { + if(!strcmp(p, "\r\n# ")) + { + SetLastPrompt(hwndChild); + } + // solve the bug Patrick found + } else if((l[0] == '#') && (l[1] == ' ')) { + SetLastPrompt(hwndChild); + } + } + + // detect syntax errors + if(strstr(lineBuffer, "Syntax error")) + { + errMsg = WM_SYNTAXERROR; + } else if(strstr(lineBuffer, "Illegal character")) { + errMsg = WM_ILLEGALCHAR; + } else if(strstr(lineBuffer, "Unbound value")) { + errMsg = WM_UNBOUNDVAL; + } + + // error! error! alert alert! + if(errMsg > 0) + { + int len = strlen(lineBuffer); + char* err = (char*)SafeMalloc(len+1); + char *m = err, *n1 = NULL, *n2 = NULL, *nt = NULL; + + // make a copy of the message + strncpy(err, lineBuffer, len); + err[len] = '\0'; + + // find it + m = strstr(err, "Characters "); + if(m == NULL) + break; + + // got the start char + n1 = m + strlen("Characters "); + + // start looking for the end char + nt = strstr(n1, "-"); + if(nt == NULL) + break; + + // makes n1 a valid string + nt[0] = '\0'; + + // end char is right after this + n2 = nt + 1; + + // find the end of n2 + nt = strstr(n2, ":"); + if(nt == NULL) + break; + + // makes n2 a valid string + nt[0] = '\0'; + + SendMessage(hwndChild, errMsg, (WPARAM)atoi(n1), (LPARAM)atoi(n2)); + } + } + /** End Modifications **/ + + break; + + } + return DefMDIChildProc(hwnd, msg, wparam, lparam); +} + + +/*------------------------------------------------------------------------ +Procedure: MainWndProc ID:1 +Purpose: Window procedure for the frame window, that contains +the menu. The messages handled are: +WM_CREATE: Creates the mdi child window +WM_SIZE: resizes the status bar and the mdi child +window +WM_COMMAND: Sends the command to the dispatcher +WM_CLOSE: If the user confirms, it exists the program +WM_QUITOCAML: Stops the program unconditionally. +Input: Standard windows callback +Output: +Errors: +------------------------------------------------------------------------*/ +static LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch (msg) { + // Create the MDI client invisible window + case WM_CREATE: + hwndMDIClient = CreateMdiClient(hwnd); + TimerId = SetTimer((HWND) 0, 0, 100, (TIMERPROC) TimerProc); + break; + // Move the child windows + case WM_SIZE: + SendMessage(hWndStatusbar,msg,wParam,lParam); + InitializeStatusBar(hWndStatusbar,1); + // Position the MDI client window between the tool and status bars + if (wParam != SIZE_MINIMIZED) { + RECT rc, rcClient; + + GetClientRect(hwnd, &rcClient); + GetWindowRect(hWndStatusbar, &rc); + ScreenToClient(hwnd, (LPPOINT)&rc.left); + rcClient.bottom = rc.top; + MoveWindow(hwndMDIClient,rcClient.left,rcClient.top,rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, TRUE); + } + + return 0; + // Dispatch the menu commands + case WM_COMMAND: + HandleCommand(hwnd, wParam,lParam); + return 0; + // If user confirms close + case WM_CLOSE: + if (!AskYesOrNo("Quit OCamlWinPlus?")) + return 0; + break; + // End application + case WM_DESTROY: + PostQuitMessage(0); + break; + // The interpreter has exited. Force close of the application + case WM_QUITOCAML: + DestroyWindow(hwnd); + return 0; + case WM_USER+1000: + // TestGraphics(); + break; + default: + return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); + } + return DefFrameProc(hwnd,hwndMDIClient,msg,wParam,lParam); +} + +/*------------------------------------------------------------------------ +Procedure: CreationCourier ID:1 +Purpose: Creates the courier font +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +static HFONT CreationCourier(int flag) +{ + LOGFONT CurrentFont; + memset(&CurrentFont, 0, sizeof(LOGFONT)); + CurrentFont.lfCharSet = ANSI_CHARSET; + CurrentFont.lfWeight = FW_NORMAL; + if (flag) + CurrentFont.lfHeight = 18; + else + CurrentFont.lfHeight = 15; + CurrentFont.lfPitchAndFamily = (BYTE) (FIXED_PITCH | FF_MODERN); + strcpy(CurrentFont.lfFaceName, "Courier"); /* Courier */ + return (CreateFontIndirect(&CurrentFont)); +} + +/*------------------------------------------------------------------------ +Procedure: ReadToLineBuffer ID:1 +Purpose: Reads into the line buffer the characters written by +the interpreter +Input: None +Output: The number of characters read +Errors: None +------------------------------------------------------------------------*/ +int ReadToLineBuffer(void) +{ + memset(lineBuffer,0,sizeof(lineBuffer)); + return ReadFromPipe(lineBuffer,sizeof(lineBuffer)); +} + +/*------------------------------------------------------------------------ +Procedure: AddLineBuffer ID:1 +Purpose: Sends the contents of the line buffer to the edit +control +Input: None +Output: +Errors: +------------------------------------------------------------------------*/ +int AddLineBuffer(void) +{ + HWND hEditCtrl; + + hEditCtrl = (HWND)GetWindowLongPtr(hwndSession,DWLP_USER); + return SendMessage(hEditCtrl,EM_REPLACESEL,0,(LPARAM)lineBuffer); + +} + +/*------------------------------------------------------------------------ +Procedure: Setup ID:1 +Purpose: Handles GUI initialization (Fonts, brushes, colors, +etc) +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +static int Setup(HANDLE *phAccelTable) +{ + if (!InitApplication()) + return 0; + ProgramParams.hFont = CreationCourier(1); + ProgramParams.TextColor = RGB(0,0,0); + GetObject(ProgramParams.hFont,sizeof(LOGFONT),&CurrentFont); + BackgroundBrush = CreateSolidBrush(BackColor); + *phAccelTable = LoadAccelerators(hInst,MAKEINTRESOURCE(IDACCEL)); + return 1; +} + + +/*------------------------------------------------------------------------ +Procedure: WinMain ID:1 +Purpose: Entry point for windows programs. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) +{ + MSG msg; + HANDLE hAccelTable; + char consoleTitle[512]; + HWND hwndConsole; + + CurrentEditBuffer = (EditBuffer*)SafeMalloc(sizeof(EditBuffer)); + CurrentEditBuffer->LineCount = 0; + CurrentEditBuffer->Lines = NULL; + + //setup the history index pointer + historyEntry = NULL; + + // Setup the hInst global + hInst = hInstance; + // Do the setup + if (!Setup(&hAccelTable)) + return 0; + // Need to set up a console so that we can send ctrl-break signal + // to inferior Caml + AllocConsole(); + GetConsoleTitle(consoleTitle,sizeof(consoleTitle)); + hwndConsole = FindWindow(NULL,consoleTitle); + ShowWindow(hwndConsole,SW_HIDE); + // Create main window and exit if this fails + if ((hwndMain = CreateinriaWndClassWnd()) == (HWND)0) + return 0; + // Create the status bar + CreateSBar(hwndMain,"Ready",2); + // Show the window + ShowWindow(hwndMain,SW_SHOW); + // Create the session window + hwndSession = MDICmdFileNew("Session transcript",0); + // Get the path to ocaml.exe + GetOcamlPath(); + // Start the interpreter + StartOcaml(); + // Show the session window + ShowWindow(hwndSession, SW_SHOW); + // Maximize it + SendMessage(hwndMDIClient, WM_MDIMAXIMIZE, (WPARAM) hwndSession, 0); + + PostMessage(hwndMain,WM_USER+1000,0,0); + while (GetMessage(&msg,NULL,0,0)) { + if (!TranslateMDISysAccel(hwndMDIClient, &msg)) + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { + TranslateMessage(&msg); // Translates virtual key codes + DispatchMessage(&msg); // Dispatches message to window + } + } + WriteToPipe("#quit;;\r\n\032"); + KillTimer((HWND) 0, TimerId); + return msg.wParam; +} diff --git a/win32caml/ocaml.ico b/win32caml/ocaml.ico new file mode 100644 index 0000000000000000000000000000000000000000..13560db450060a23a987930858b20aca9dd2b4b2 GIT binary patch literal 766 zcmc(cF;2uV5JmqYq(n4JMV*pka3pux(j8XzB9XX2B$^zDGB*hCj~z%s&tx6@`OmjA zv(klU7@p<$dXQe2Ul{}Ajd9T<Zz-ew9T^cN=Q{CbsdZhME$s2rzI(;s@s`;e5m(UB zml~EGYMiA=+2*MwU_;-YDrY5i&gehOOoqC#vZiGzC2Jg0mux8a8SH+!OpE2F`@;JN za^=m;QD)&6{9akv+#`=+@3ZUak%LJ*b0YD~D!1{(skiO$v*gsqUWJ^fZ{rweHaVEy z*ljub<%U*wd>*pd?XsKJz+G}fT^zML!4ci3f=ZS10nAtIakQIZW^A$HyW2lx!FT<H O(Vun%jsq?IXM6(#XZU#l literal 0 HcmV?d00001 diff --git a/win32caml/ocaml.rc b/win32caml/ocaml.rc new file mode 100644 index 0000000..c10ecdb --- /dev/null +++ b/win32caml/ocaml.rc @@ -0,0 +1,255 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#define APSTUDIO_HIDDEN_SYMBOLS +#include "windows.h" +#undef APSTUDIO_HIDDEN_SYMBOLS +#include "inriares.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +1000 ICON "ocaml.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDMAINMENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&Open...", IDM_OPEN + MENUITEM "&Save ML...", IDM_SAVE + MENUITEM "Save &Transcript...", IDM_SAVEAS + MENUITEM SEPARATOR + MENUITEM "&Print", IDM_PRINT, GRAYED + MENUITEM "P&rint Setup...", IDM_PRINTSU, GRAYED + MENUITEM SEPARATOR + MENUITEM "E&xit", IDM_EXIT + END + POPUP "&Edit" + BEGIN + MENUITEM "&Undo\tAlt+BkSp", IDM_EDITUNDO + MENUITEM SEPARATOR + MENUITEM "Cu&t\t Shift+Del", IDM_EDITCUT + MENUITEM "&Copy\tCtrl+Ins", IDM_EDITCOPY + MENUITEM "&Paste\tShift+Ins", IDM_EDITPASTE + END + POPUP "Workspace" + BEGIN + MENUITEM "&Font...", IDM_FONT + MENUITEM "Text &Color...", IDM_COLORTEXT + MENUITEM "&Background Color...", IDM_BACKCOLOR + MENUITEM SEPARATOR + MENUITEM "&History...", IDM_HISTORY + MENUITEM "&Garbage Collect", IDM_GC + MENUITEM "&Interrupt", IDCTRLC + END + POPUP "&Window", GRAYED + BEGIN + MENUITEM "&Tile", IDM_WINDOWTILE, INACTIVE + MENUITEM "&Cascade", IDM_WINDOWCASCADE, INACTIVE + MENUITEM "Arrange &Icons", IDM_WINDOWICONS, INACTIVE + MENUITEM "Close &All", IDM_WINDOWCLOSEALL, INACTIVE + END + POPUP "&Help" + BEGIN + MENUITEM "&About...", IDM_ABOUT + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Accelerator +// + +BARMDI ACCELERATORS +BEGIN + "Q", IDM_EXIT, VIRTKEY, CONTROL +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_ABOUT DIALOGEX 7, 29, 236, 81 +STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_CLIENTEDGE +CAPTION "About OCamlWinPlus" +FONT 8, "MS Sans Serif", 0, 0, 0x1 +BEGIN + LTEXT "Objective Caml for Windows",101,75,7,90,12 + LTEXT "New Windows Interface 1.9RC4",102,68,15,104,12 + CTEXT "Copyright 1996-2001\nUpdated 2003",103,88,25,66,23 + CTEXT "Institut National de Recherche en Informatique et Automatique", + 104,16,46,211,10 + CTEXT "Réalisé par Jacob Navia 2001. Updated by Chris Watford 2003.\nwatford@uiuc.edu", + 105,18,54,207,19 +END + +IDD_HISTORY DIALOGEX 6, 18, 261, 184 +STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU | WS_THICKFRAME +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Session History" +FONT 8, "MS Sans Serif", 0, 0, 0x1 +BEGIN + LISTBOX IDLIST,7,7,247,173,LBS_USETABSTOPS | WS_VSCROLL | + WS_HSCROLL | WS_TABSTOP +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""windows.h""\r\n" + "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""inriares.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + 3010 "Switches to " +END + +STRINGTABLE +BEGIN + 2000 "Create, open, save, or print documents" + 2010 "Get help" +END + +STRINGTABLE +BEGIN + 500 "Displays information about this application" +END + +STRINGTABLE +BEGIN + 440 "Closes all open windows" +END + +STRINGTABLE +BEGIN + 420 "Arranges windows as overlapping tiles" + 430 "Arranges minimized window icons" +END + +STRINGTABLE +BEGIN + 410 "Arranges windows as non-overlapping tiles" +END + +STRINGTABLE +BEGIN + 340 "Inserts the clipboard contents at the insertion point" + 350 "Removes the selection without putting it on the clipboard" +END + +STRINGTABLE +BEGIN + 320 "Cuts the selection and puts it on the clipboard" + 330 "Copies the selection and puts it on the clipboard" +END + +STRINGTABLE +BEGIN + 310 "Reverses the last action" +END + +STRINGTABLE +BEGIN + 260 "Changes the printer selection or configuration" + 270 "Quits this application" +END + +STRINGTABLE +BEGIN + 240 "Closes the active document" + 250 "Prints the active document" +END + +STRINGTABLE +BEGIN + 230 "Saves the active document under a different name" +END + +STRINGTABLE +BEGIN + 210 "Opens an existing document" + 220 "Saves the active document" +END + +STRINGTABLE +BEGIN + 200 "Creates a new session" +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/win32caml/resource.h b/win32caml/resource.h new file mode 100644 index 0000000..27bf5ea --- /dev/null +++ b/win32caml/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by ocaml.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/win32caml/startocaml.c b/win32caml/startocaml.c new file mode 100644 index 0000000..2e3e290 --- /dev/null +++ b/win32caml/startocaml.c @@ -0,0 +1,362 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Developed by Jacob Navia. */ +/* Copyright 2001 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the GNU Library General Public License, with */ +/* the special exception on linking described in file ../LICENSE. */ +/* */ +/***********************************************************************/ + +/***********************************************************************/ +/* Changes made by Chris Watford to enhance the source editor */ +/* Began 14 Sept 2003 - watford@uiuc.edu */ +/***********************************************************************/ + +/* $Id: startocaml.c,v 1.11 2005-03-24 17:20:54 doligez Exp $ */ + +#include <windows.h> +#include <stdio.h> +#include <io.h> +#include <direct.h> +#include "inria.h" + +PROCESS_INFORMATION pi; +#define BUFSIZE 4096 +STARTUPINFO startInfo; + +/*------------------------------------------------------------------------ +Procedure: ShowDbgMsg ID:1 +Purpose: Puts up a dialog box with a message, forcing it to +the foreground. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +void ShowDbgMsg(char *str) +{ + HWND hWnd; + char p[20], message[255]; + hWnd = hwndMain; + if (IsIconic(hWnd)){ + ShowWindow(hWnd,SW_RESTORE); + } + strncpy(message, str, 254); + message[254] = 0; + strcpy(p, "Error"); + MessageBox(hWnd, message, p, MB_OK | MB_ICONHAND|MB_TASKMODAL|MB_SETFOREGROUND); +} + +int AskYesOrNo(char *msg) +{ + HWND hwnd; + int r; + + hwnd = hwndMain; + r = MessageBox(hwnd, msg, "Ocaml", MB_YESNO | MB_SETFOREGROUND); + if (r == IDYES) + return (TRUE); + return (FALSE); +} + + +static DWORD OcamlStatus; + +static int RegistryError(void) +{ + char buf[512]; + + wsprintf(buf,"Error %d writing to the registry",GetLastError()); + ShowDbgMsg(buf); + return 0; +} + +static int ReadRegistry(HKEY hroot, + char * p1, char * p2, char * p3, + char dest[1024]) +{ + HKEY h1, h2; + DWORD dwType; + unsigned long size; + LONG ret; + + if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) + return 0; + if (RegOpenKeyExA(h1, p2, 0, KEY_QUERY_VALUE, &h2) != ERROR_SUCCESS) { + RegCloseKey(h1); + return 0; + } + dwType = REG_SZ; + size = 1024; + ret = RegQueryValueExA(h2, p3, 0, &dwType, dest, &size); + RegCloseKey(h2); + RegCloseKey(h1); + return ret == ERROR_SUCCESS; +} + +static int WriteRegistry(HKEY hroot, + char * p1, char * p2, char * p3, + char data[1024]) +{ + HKEY h1, h2; + DWORD disp; + LONG ret; + + if (RegOpenKeyExA(hroot, p1, 0, KEY_QUERY_VALUE, &h1) != ERROR_SUCCESS) + return 0; + if (RegCreateKeyExA(h1, p2, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &h2, &disp) + != ERROR_SUCCESS) { + RegCloseKey(h1); + return 0; + } + ret = RegSetValueEx(h2, p3, 0, REG_SZ, data, strlen(data) + 1); + RegCloseKey(h2); + RegCloseKey(h1); + return ret == ERROR_SUCCESS; +} + +/*------------------------------------------------------------------------ +Procedure: GetOcamlPath ID:1 +Purpose: Read the registry key +HKEY_LOCAL_MACHINE\Software\Objective Caml +or +HKEY_CURRENT_USER\Software\Objective Caml, +and creates it if it doesn't exists. +If any error occurs, i.e. the +given path doesn't exist, or the key didn't exist, it +will put up a browse dialog box to allow the user to +enter the path. The path will be verified that it +points to a file that exists. If that file is in a +directory called 'bin', it will look for another +directory in the same level called lib' and set the +Lib path to that. +Input: None explicit +Output: 1 means sucess, zero failure +Errors: Almost all system calls will be verified +------------------------------------------------------------------------*/ +int GetOcamlPath(void) +{ + char path[1024], *p; + + while (( !ReadRegistry(HKEY_CURRENT_USER, + "Software", "Objective Caml", + "InterpreterPath", path) + && + !ReadRegistry(HKEY_LOCAL_MACHINE, + "Software", "Objective Caml", + "InterpreterPath", path)) + || _access(path, 0) != 0) { + /* Registry key doesn't exist or contains invalid path */ + /* Ask user */ + if (!BrowseForFile("Ocaml interpreter|ocaml.exe", path)) { + ShowDbgMsg("Impossible to find ocaml.exe. I quit"); + exit(0); + } + WriteRegistry(HKEY_CURRENT_USER, + "Software", "Objective Caml", + "InterpreterPath", path); + /* Iterate to validate again */ + } + strcpy(OcamlPath, path); + p = strrchr(OcamlPath,'\\'); + if (p) { + *p = 0; + strcpy(LibDir,OcamlPath); + *p = '\\'; + p = strrchr(LibDir,'\\'); + if (p && !stricmp(p,"\\bin")) { + *p = 0; + strcat(LibDir,"\\lib"); + } + } + return 1; +} + +static HANDLE hChildStdinRd, hChildStdinWr,hChildStdoutRd, hChildStdoutWr; +/*------------------------------------------------------------------------ +Procedure: IsWindowsNT ID:1 +Purpose: Returns 1 if we are running under windows NT, zero +otherwise. +Input: None +Output: 1 or zero +Errors: +------------------------------------------------------------------------*/ +int IsWindowsNT(void) +{ + OSVERSIONINFO osv; + + osv.dwOSVersionInfoSize = sizeof(osv); + GetVersionEx(&osv); + return(osv.dwPlatformId == VER_PLATFORM_WIN32_NT); +} + +/*------------------------------------------------------------------------ +Procedure: DoStartOcaml ID:1 +Purpose: Starts the ocaml interpreter ocaml.exe. The standard +input of the interpreter will be connected to a pipe, +and the standard output and standard error to another +pipe. The interpreter starts as a hidden process, +showing only in the task list. Since this is in an +own thread, its workings are independent of the rest +of the program. After starting the interpreter, the +thread waits in case the interpreter exits, for +instance if the user or some program types #quit;;. +In this case, the waiting thread awakens and exits +the user interface. +Input: Not used. It uses the OcamlPath global variable, that +is supposed to be correct, no test for its validity +are done here. +Output: None visible +Errors: If any system call for whatever reason fails, the +thread will exit. No error message is shown. +------------------------------------------------------------------------*/ +DWORD WINAPI DoStartOcaml(LPVOID param) +{ + HWND hwndParent = (HWND) param; + char *cmdline; + int processStarted; + LPSECURITY_ATTRIBUTES lpsa=NULL; + SECURITY_ATTRIBUTES sa; + SECURITY_DESCRIPTOR sd; + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + // Under windows NT/2000/Whistler we have to initialize the security descriptors + // This is not necessary under windows 98/95. + if (IsWindowsNT()) { + InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); + SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE); + sa.bInheritHandle = TRUE; + sa.lpSecurityDescriptor = &sd; + lpsa = &sa; + } + memset(&startInfo,0,sizeof(STARTUPINFO)); + startInfo.cb = sizeof(STARTUPINFO); + // Create a pipe for the child process's STDOUT. + if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &sa, 0)) + return 0; + // Create a pipe for the child process's STDIN. + if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &sa, 0)) + return 0; + // Setup the start info structure + startInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; + startInfo.wShowWindow = SW_HIDE; + startInfo.hStdOutput = hChildStdoutWr; + startInfo.hStdError = hChildStdoutWr; + startInfo.hStdInput = hChildStdinRd; + cmdline = OcamlPath; + // Set the OCAMLLIB environment variable + SetEnvironmentVariable("OCAMLLIB", LibDir); + // Let's go: start the ocaml interpreter + processStarted = CreateProcess(NULL,cmdline,lpsa,lpsa,1, + CREATE_NEW_PROCESS_GROUP|NORMAL_PRIORITY_CLASS, + NULL,ProgramParams.CurrentWorkingDir,&startInfo,&pi); + if (processStarted) { + WaitForSingleObject(pi.hProcess,INFINITE); + GetExitCodeProcess(pi.hProcess,(unsigned long *)&OcamlStatus); + CloseHandle(pi.hProcess); + PostMessage(hwndMain,WM_QUITOCAML,0,0); + } + else { + char *msg = malloc(1024); + wsprintf(msg,"Impossible to start ocaml.exe in:\n%s",cmdline); + ShowDbgMsg(msg); + free(msg); + } + return 0; +} + +/*------------------------------------------------------------------------ +Procedure: WriteToPipe ID:1 +Purpose: Writes the given character string to the standard +input of the interpreter +Input: The character string (zero terminated) to be written +Output: The number of characters written or zero if an error +occurs +Errors: None +------------------------------------------------------------------------*/ +int WriteToPipe(char *data) +{ + DWORD dwWritten; + + if (! WriteFile(hChildStdinWr, data, strlen(data), &dwWritten, NULL)) + return 0; + + return dwWritten; + +} + +/*------------------------------------------------------------------------ +Procedure: ReadFromPipe ID:1 +Purpose: Reads from the standard output of the interpreter and +stores the data in the given buffer up to the given +length. This is done in a non-blocking manner, i.e. +it is safe to call this even if there is no data +available. +Input: The buffer to be used and its length. +Output: Returns the number of characters read from the pipe. +Errors: None explicit +------------------------------------------------------------------------*/ +int ReadFromPipe(char *data,int len) +{ + DWORD dwRead; + + PeekNamedPipe(hChildStdoutRd,data,len,NULL,&dwRead,NULL); + if (dwRead == 0) + return 0; + + // Read output from the child process, and write to parent's STDOUT. + if( !ReadFile( hChildStdoutRd, data, len, &dwRead, NULL) || dwRead == 0) + return 0; + + return dwRead; +} + +static DWORD tid; +/*------------------------------------------------------------------------ +Procedure: StartOcaml ID:1 +Purpose: Starts the thread that will call the ocaml.exe +program. +Input: +Output: +Errors: +------------------------------------------------------------------------*/ +int StartOcaml(void) +{ + getcwd(ProgramParams.CurrentWorkingDir,sizeof(ProgramParams.CurrentWorkingDir)); + CreateThread(NULL,0,DoStartOcaml,hwndMain,0,&tid); + return 1; +} + + +void *SafeMalloc(int size) +{ + void *result; + + if (size < 0) { + char message[1024]; + +error: + sprintf(message,"Can't allocate %d bytes",size); + MessageBox(NULL, message, "Ocaml", MB_OK); + exit(-1); + } + result = malloc(size); + + if (result == NULL) + goto error; + + return result; +} + + +void InterruptOcaml(void) +{ + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId)) { + char message[1024]; + sprintf(message, "GenerateConsole failed: %lu\n", GetLastError()); + MessageBox(NULL, message, "Ocaml", MB_OK); + } + WriteToPipe(" "); +} diff --git a/yacc/.cvsignore b/yacc/.cvsignore new file mode 100644 index 0000000..d7fa25c --- /dev/null +++ b/yacc/.cvsignore @@ -0,0 +1,5 @@ +ocamlyacc +*.c.x +ocamlyacc.xcoff +version.h +.gdb_history diff --git a/yacc/Makefile b/yacc/Makefile new file mode 100644 index 0000000..6c9dc78 --- /dev/null +++ b/yacc/Makefile @@ -0,0 +1,49 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile,v 1.10 2007-02-07 14:49:42 doligez Exp $ + +# Makefile for the parser generator. + +include ../config/Makefile + +CC=$(BYTECC) +CFLAGS=-O -DNDEBUG $(BYTECCCOMPOPTS) + +OBJS= closure.o error.o lalr.o lr0.o main.o mkpar.o output.o reader.o \ + skeleton.o symtab.o verbose.o warshall.o + +all: ocamlyacc$(EXE) + +ocamlyacc$(EXE): $(OBJS) + $(CC) $(CFLAGS) $(CCLINKFLAGS) -o ocamlyacc $(OBJS) + +version.h : ../VERSION + echo "#define OCAML_VERSION \"`head -1 ../VERSION`\"" >version.h + +clean: + rm -f *.o ocamlyacc$(EXE) *~ version.h + +depend: + +closure.o: defs.h +error.o: defs.h +lalr.o: defs.h +lr0.o: defs.h +main.o: defs.h version.h +mkpar.o: defs.h +output.o: defs.h +reader.o: defs.h +skeleton.o: defs.h +symtab.o: defs.h +verbose.o: defs.h +warshall.o: defs.h diff --git a/yacc/Makefile.nt b/yacc/Makefile.nt new file mode 100644 index 0000000..4c702a8 --- /dev/null +++ b/yacc/Makefile.nt @@ -0,0 +1,52 @@ +######################################################################### +# # +# Objective Caml # +# # +# Xavier Leroy, projet Cristal, INRIA Rocquencourt # +# # +# Copyright 1999 Institut National de Recherche en Informatique et # +# en Automatique. All rights reserved. This file is distributed # +# under the terms of the Q Public License version 1.0. # +# # +######################################################################### + +# $Id: Makefile.nt,v 1.11 2007-11-15 13:21:15 frisch Exp $ + +# Makefile for the parser generator. + +include ../config/Makefile + +OBJS= closure.$(O) error.$(O) lalr.$(O) lr0.$(O) main.$(O) \ + mkpar.$(O) output.$(O) reader.$(O) \ + skeleton.$(O) symtab.$(O) verbose.$(O) warshall.$(O) + +all: ocamlyacc.exe + +ocamlyacc.exe: $(OBJS) + $(MKEXE) -o ocamlyacc.exe $(OBJS) $(EXTRALIBS) + +version.h : ../VERSION + echo "#define OCAML_VERSION \"`head -1 ../VERSION`\"" >version.h + +clean: + rm -f *.$(O) ocamlyacc.exe *~ version.h + +.SUFFIXES: .c .$(O) + +.c.$(O): + $(BYTECC) -DNDEBUG -DNO_UNIX $(BYTECCCOMPOPTS) -c $< + +depend: + +closure.$(O): defs.h +error.$(O): defs.h +lalr.$(O): defs.h +lr0.$(O): defs.h +main.$(O): defs.h version.h +mkpar.$(O): defs.h +output.$(O): defs.h +reader.$(O): defs.h +skeleton.$(O): defs.h +symtab.$(O): defs.h +verbose.$(O): defs.h +warshall.$(O): defs.h diff --git a/yacc/closure.c b/yacc/closure.c new file mode 100644 index 0000000..97ef206 --- /dev/null +++ b/yacc/closure.c @@ -0,0 +1,283 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: closure.c,v 1.9 2001-07-12 12:54:22 doligez Exp $ */ + +#include "defs.h" + +short *itemset; +short *itemsetend; +unsigned *ruleset; + +static unsigned *first_derives; +static unsigned *EFF; + + + +void print_EFF (); +void print_first_derives (); +void print_closure (); + +void set_EFF(void) +{ + register unsigned *row; + register int symbol; + register short *sp; + register int rowsize; + register int i; + register int rule; + + rowsize = WORDSIZE(nvars); + EFF = NEW2(nvars * rowsize, unsigned); + + row = EFF; + for (i = start_symbol; i < nsyms; i++) + { + sp = derives[i]; + for (rule = *sp; rule > 0; rule = *++sp) + { + symbol = ritem[rrhs[rule]]; + if (ISVAR(symbol)) + { + symbol -= start_symbol; + SETBIT(row, symbol); + } + } + row += rowsize; + } + + reflexive_transitive_closure(EFF, nvars); + +#ifdef DEBUG + print_EFF(); +#endif +} + + +void set_first_derives(void) +{ + register unsigned *rrow; + register unsigned *vrow; + register int j; + register unsigned mask; + register unsigned cword; + register short *rp; + + int rule; + int i; + int rulesetsize; + int varsetsize; + + rulesetsize = WORDSIZE(nrules); + varsetsize = WORDSIZE(nvars); + first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize; + + set_EFF(); + + rrow = first_derives + ntokens * rulesetsize; + for (i = start_symbol; i < nsyms; i++) + { + vrow = EFF + ((i - ntokens) * varsetsize); + cword = *vrow++; + mask = 1; + for (j = start_symbol; j < nsyms; j++) + { + if (cword & mask) + { + rp = derives[j]; + while ((rule = *rp++) >= 0) + { + SETBIT(rrow, rule); + } + } + + mask <<= 1; + if (mask == 0) + { + cword = *vrow++; + mask = 1; + } + } + + vrow += varsetsize; + rrow += rulesetsize; + } + +#ifdef DEBUG + print_first_derives(); +#endif + + FREE(EFF); +} + + +void closure(short int *nucleus, int n) +{ + register int ruleno; + register unsigned word; + register unsigned mask; + register short *csp; + register unsigned *dsp; + register unsigned *rsp; + register int rulesetsize; + + short *csend; + unsigned *rsend; + int symbol; + int itemno; + + rulesetsize = WORDSIZE(nrules); + rsp = ruleset; + rsend = ruleset + rulesetsize; + for (rsp = ruleset; rsp < rsend; rsp++) + *rsp = 0; + + csend = nucleus + n; + for (csp = nucleus; csp < csend; ++csp) + { + symbol = ritem[*csp]; + if (ISVAR(symbol)) + { + dsp = first_derives + symbol * rulesetsize; + rsp = ruleset; + while (rsp < rsend) + *rsp++ |= *dsp++; + } + } + + ruleno = 0; + itemsetend = itemset; + csp = nucleus; + for (rsp = ruleset; rsp < rsend; ++rsp) + { + word = *rsp; + if (word == 0) + ruleno += BITS_PER_WORD; + else + { + mask = 1; + while (mask) + { + if (word & mask) + { + itemno = rrhs[ruleno]; + while (csp < csend && *csp < itemno) + *itemsetend++ = *csp++; + *itemsetend++ = itemno; + while (csp < csend && *csp == itemno) + ++csp; + } + + mask <<= 1; + ++ruleno; + } + } + } + + while (csp < csend) + *itemsetend++ = *csp++; + +#ifdef DEBUG + print_closure(n); +#endif +} + + + +void finalize_closure(void) +{ + FREE(itemset); + FREE(ruleset); + FREE(first_derives + ntokens * WORDSIZE(nrules)); +} + + +#ifdef DEBUG + +void print_closure(int n) +{ + register short *isp; + + printf("\n\nn = %d\n\n", n); + for (isp = itemset; isp < itemsetend; isp++) + printf(" %d\n", *isp); +} + + +void print_EFF(void) +{ + register int i, j; + register unsigned *rowp; + register unsigned word; + register unsigned mask; + + printf("\n\nEpsilon Free Firsts\n"); + + for (i = start_symbol; i < nsyms; i++) + { + printf("\n%s", symbol_name[i]); + rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars)); + word = *rowp++; + + mask = 1; + for (j = 0; j < nvars; j++) + { + if (word & mask) + printf(" %s", symbol_name[start_symbol + j]); + + mask <<= 1; + if (mask == 0) + { + word = *rowp++; + mask = 1; + } + } + } +} + + +void print_first_derives(void) +{ + register int i; + register int j; + register unsigned *rp; + register unsigned cword; + register unsigned mask; + + printf("\n\n\nFirst Derives\n"); + + for (i = start_symbol; i < nsyms; i++) + { + printf("\n%s derives\n", symbol_name[i]); + rp = first_derives + i * WORDSIZE(nrules); + cword = *rp++; + mask = 1; + for (j = 0; j <= nrules; j++) + { + if (cword & mask) + printf(" %d\n", j); + + mask <<= 1; + if (mask == 0) + { + cword = *rp++; + mask = 1; + } + } + } + + fflush(stdout); +} + +#endif diff --git a/yacc/defs.h b/yacc/defs.h new file mode 100644 index 0000000..9279adf --- /dev/null +++ b/yacc/defs.h @@ -0,0 +1,359 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: defs.h,v 1.22 2004-04-21 23:26:05 doligez Exp $ */ + +#include <assert.h> +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include "../config/s.h" + +/* machine-dependent definitions */ +/* the following definitions are for the Tahoe */ +/* they might have to be changed for other machines */ + +/* MAXCHAR is the largest unsigned character value */ +/* MAXSHORT is the largest value of a C short */ +/* MINSHORT is the most negative value of a C short */ +/* MAXTABLE is the maximum table size */ +/* BITS_PER_WORD is the number of bits in a C unsigned */ +/* WORDSIZE computes the number of words needed to */ +/* store n bits */ +/* BIT returns the value of the n-th bit starting */ +/* from r (0-indexed) */ +/* SETBIT sets the n-th bit starting from r */ + +#define MAXCHAR UCHAR_MAX +#define MAXSHORT SHRT_MAX +#define MINSHORT SHRT_MIN +#define MAXTABLE 32500 + +#define BITS_PER_WORD (8*sizeof(unsigned)) +#define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD) +#define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)%BITS_PER_WORD))&1) +#define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=(1<<((n)%BITS_PER_WORD))) + +/* character names */ + +#define NUL '\0' /* the null character */ +#define NEWLINE '\n' /* line feed */ +#define SP ' ' /* space */ +#define BS '\b' /* backspace */ +#define HT '\t' /* horizontal tab */ +#define VT '\013' /* vertical tab */ +#define CR '\r' /* carriage return */ +#define FF '\f' /* form feed */ +#define QUOTE '\'' /* single quote */ +#define DOUBLE_QUOTE '\"' /* double quote */ +#define BACKSLASH '\\' /* backslash */ + + +/* defines for constructing filenames */ + +#define CODE_SUFFIX ".code.c" +#define DEFINES_SUFFIX ".tab.h" +#define OUTPUT_SUFFIX ".ml" +#define VERBOSE_SUFFIX ".output" +#define INTERFACE_SUFFIX ".mli" + +/* keyword codes */ + +#define TOKEN 0 +#define LEFT 1 +#define RIGHT 2 +#define NONASSOC 3 +#define MARK 4 +#define TEXT 5 +#define TYPE 6 +#define START 7 +#define UNION 8 +#define IDENT 9 + +/* symbol classes */ + +#define UNKNOWN 0 +#define TERM 1 +#define NONTERM 2 + + +/* the undefined value */ + +#define UNDEFINED (-1) + + +/* action codes */ + +#define SHIFT 1 +#define REDUCE 2 + + +/* character macros */ + +#define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$') +#define IS_OCTAL(c) ((c) >= '0' && (c) <= '7') +#define NUMERIC_VALUE(c) ((c) - '0') + + +/* symbol macros */ + +#define ISTOKEN(s) ((s) < start_symbol) +#define ISVAR(s) ((s) >= start_symbol) + + +/* storage allocation macros */ + +#define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n))) +#define FREE(x) (free((char*)(x))) +#define MALLOC(n) (malloc((unsigned)(n))) +#define NEW(t) ((t*)allocate(sizeof(t))) +#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) +#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n))) + + +/* the structure of a symbol table entry */ + +typedef struct bucket bucket; +struct bucket +{ + struct bucket *link; + struct bucket *next; + char *name; + char *tag; + short value; + short index; + short prec; + char class; + char assoc; + char entry; + char true_token; +}; + +/* TABLE_SIZE is the number of entries in the symbol table. */ +/* TABLE_SIZE must be a power of two. */ + +#define TABLE_SIZE 4096 + +/* the structure of the LR(0) state machine */ + +typedef struct core core; +struct core +{ + struct core *next; + struct core *link; + short number; + short accessing_symbol; + short nitems; + short items[1]; +}; + + +/* the structure used to record shifts */ + +typedef struct shifts shifts; +struct shifts +{ + struct shifts *next; + short number; + short nshifts; + short shift[1]; +}; + + +/* the structure used to store reductions */ + +typedef struct reductions reductions; +struct reductions +{ + struct reductions *next; + short number; + short nreds; + short rules[1]; +}; + + +/* the structure used to represent parser actions */ + +typedef struct action action; +struct action +{ + struct action *next; + short symbol; + short number; + short prec; + char action_code; + char assoc; + char suppressed; +}; + + +/* global variables */ + +extern char dflag; +extern char lflag; +extern char rflag; +extern char tflag; +extern char vflag; +extern char qflag; +extern char sflag; +extern char big_endian; + +extern char *myname; +extern char *cptr; +extern char *line; +extern int lineno; +extern char *virtual_input_file_name; +extern int outline; + +extern char *action_file_name; +extern char *entry_file_name; +extern char *code_file_name; +extern char *defines_file_name; +extern char *input_file_name; +extern char *output_file_name; +extern char *text_file_name; +extern char *union_file_name; +extern char *verbose_file_name; +extern char *interface_file_name; + +extern FILE *action_file; +extern FILE *entry_file; +extern FILE *code_file; +extern FILE *defines_file; +extern FILE *input_file; +extern FILE *output_file; +extern FILE *text_file; +extern FILE *union_file; +extern FILE *verbose_file; +extern FILE *interface_file; + +extern int nitems; +extern int nrules; +extern int ntotalrules; +extern int nsyms; +extern int ntokens; +extern int nvars; +extern int ntags; + +extern char unionized; +extern char line_format[]; + +extern int start_symbol; +extern char **symbol_name; +extern short *symbol_value; +extern short *symbol_prec; +extern char *symbol_assoc; +extern char **symbol_tag; +extern char *symbol_true_token; + +extern short *ritem; +extern short *rlhs; +extern short *rrhs; +extern short *rprec; +extern char *rassoc; + +extern short **derives; +extern char *nullable; + +extern bucket *first_symbol; +extern bucket *last_symbol; + +extern int nstates; +extern core *first_state; +extern shifts *first_shift; +extern reductions *first_reduction; +extern short *accessing_symbol; +extern core **state_table; +extern shifts **shift_table; +extern reductions **reduction_table; +extern unsigned *LA; +extern short *LAruleno; +extern short *lookaheads; +extern short *goto_map; +extern short *from_state; +extern short *to_state; + +extern action **parser; +extern int SRtotal; +extern int RRtotal; +extern short *SRconflicts; +extern short *RRconflicts; +extern short *defred; +extern short *rules_used; +extern short nunused; +extern short final_state; + +/* global functions */ + +#ifdef __GNUC__ +/* Works only in GCC 2.5 and later */ +#define Noreturn __attribute ((noreturn)) +#else +#define Noreturn +#endif + +extern char *allocate(unsigned int n); +extern bucket *lookup(char *name); +extern bucket *make_bucket(char *name); +extern action *parse_actions(register int stateno); +extern action *get_shifts(int stateno); +extern action *add_reductions(int stateno, register action *actions); +extern action *add_reduce(register action *actions, register int ruleno, register int symbol); +extern void closure (short int *nucleus, int n); +extern void create_symbol_table (void); +extern void default_action_error (void); +extern void done (int k) Noreturn; +extern void entry_without_type (char *s); +extern void fatal (char *msg); +extern void finalize_closure (void); +extern void free_parser (void); +extern void free_symbol_table (void); +extern void free_symbols (void); +extern void illegal_character (char *c_cptr); +extern void illegal_token_ref (int i, char *name); +extern void lalr (void); +extern void lr0 (void); +extern void make_parser (void); +extern void no_grammar (void); +extern void no_space (void); +extern void open_error (char *filename); +extern void output (void); +extern void over_unionized (char *u_cptr); +extern void prec_redeclared (void); +extern void polymorphic_entry_point(char *s); +extern void reader (void); +extern void reflexive_transitive_closure (unsigned int *R, int n); +extern void reprec_warning (char *s); +extern void retyped_warning (char *s); +extern void revalued_warning (char *s); +extern void set_first_derives (void); +extern void syntax_error (int st_lineno, char *st_line, char *st_cptr) Noreturn, terminal_lhs (int s_lineno); +extern void terminal_start (char *s); +extern void tokenized_start (char *s); +extern void too_many_entries (void); +extern void undefined_goal (char *s); +extern void undefined_symbol (char *s); +extern void unexpected_EOF (void); +extern void unknown_rhs (int i); +extern void unterminated_action (int a_lineno, char *a_line, char *a_cptr); +extern void unterminated_comment (int c_lineno, char *c_line, char *c_cptr); +extern void unterminated_string (int s_lineno, char *s_line, char *s_cptr); +extern void unterminated_text (int t_lineno, char *t_line, char *t_cptr); +extern void unterminated_union (int u_lineno, char *u_line, char *u_cptr); +extern void used_reserved (char *s); +extern void verbose (void); +extern void write_section (char **section); + diff --git a/yacc/error.c b/yacc/error.c new file mode 100644 index 0000000..e1880ae --- /dev/null +++ b/yacc/error.c @@ -0,0 +1,314 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: error.c,v 1.15 2004-11-02 10:48:14 doligez Exp $ */ + +/* routines for printing error messages */ + +#include "defs.h" + +void fatal(char *msg) +{ + fprintf(stderr, "%s: f - %s\n", myname, msg); + done(2); +} + + +void no_space(void) +{ + fprintf(stderr, "%s: f - out of space\n", myname); + done(2); +} + + +void open_error(char *filename) +{ + fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename); + done(2); +} + + +void unexpected_EOF(void) +{ + fprintf(stderr, "File \"%s\", line %d: unexpected end-of-file\n", + virtual_input_file_name, lineno); + done(1); +} + + +void print_pos(char *st_line, char *st_cptr) +{ + register char *s; + + if (st_line == 0) return; + for (s = st_line; *s != '\n'; ++s) + { + if (isprint((unsigned char) *s) || *s == '\t') + putc(*s, stderr); + else + putc('?', stderr); + } + putc('\n', stderr); + for (s = st_line; s < st_cptr; ++s) + { + if (*s == '\t') + putc('\t', stderr); + else + putc(' ', stderr); + } + putc('^', stderr); + putc('\n', stderr); +} + + +void syntax_error(int st_lineno, char *st_line, char *st_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: syntax error\n", + virtual_input_file_name, st_lineno); + print_pos(st_line, st_cptr); + done(1); +} + + +void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: unmatched /*\n", + virtual_input_file_name, c_lineno); + print_pos(c_line, c_cptr); + done(1); +} + + +void unterminated_string(int s_lineno, char *s_line, char *s_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: unterminated string\n", + virtual_input_file_name, s_lineno); + print_pos(s_line, s_cptr); + done(1); +} + + +void unterminated_text(int t_lineno, char *t_line, char *t_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: unmatched %%{\n", + virtual_input_file_name, t_lineno); + print_pos(t_line, t_cptr); + done(1); +} + + +void unterminated_union(int u_lineno, char *u_line, char *u_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: unterminated %%union declaration\n", + virtual_input_file_name, u_lineno); + print_pos(u_line, u_cptr); + done(1); +} + + +void over_unionized(char *u_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: too many %%union declarations\n", + virtual_input_file_name, lineno); + print_pos(line, u_cptr); + done(1); +} + + +void illegal_tag(int t_lineno, char *t_line, char *t_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: illegal tag\n", + virtual_input_file_name, t_lineno); + print_pos(t_line, t_cptr); + done(1); +} + + +void illegal_character(char *c_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: illegal character\n", + virtual_input_file_name, lineno); + print_pos(line, c_cptr); + done(1); +} + + +void used_reserved(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: illegal use of reserved symbol \ +`%s'\n", virtual_input_file_name, lineno, s); + done(1); +} + + +void tokenized_start(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: the start symbol `%s' cannot \ +be declared to be a token\n", virtual_input_file_name, lineno, s); + done(1); +} + + +void retyped_warning(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: warning: the type of `%s' has been \ +redeclared\n", virtual_input_file_name, lineno, s); +} + + +void reprec_warning(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: warning: the precedence of `%s' has \ +been redeclared\n", virtual_input_file_name, lineno, s); +} + + +void revalued_warning(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: warning: the value of `%s' has been \ +redeclared\n", virtual_input_file_name, lineno, s); +} + + +void terminal_start(char *s) +{ + fprintf(stderr, "File \"%s\", line %d: the entry point `%s' is a \ +token\n", virtual_input_file_name, lineno, s); + done(1); +} + +void too_many_entries(void) +{ + fprintf(stderr, "File \"%s\", line %d: more than 256 entry points\n", + virtual_input_file_name, lineno); + done(1); +} + + +void no_grammar(void) +{ + fprintf(stderr, "File \"%s\", line %d: no grammar has been specified\n", + virtual_input_file_name, lineno); + done(1); +} + + +void terminal_lhs(int s_lineno) +{ + fprintf(stderr, "File \"%s\", line %d: a token appears on the lhs \ +of a production\n", virtual_input_file_name, s_lineno); + done(1); +} + + +void prec_redeclared(void) +{ + fprintf(stderr, "File \"%s\", line %d: warning: conflicting %%prec \ +specifiers\n", virtual_input_file_name, lineno); +} + + +void unterminated_action(int a_lineno, char *a_line, char *a_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: unterminated action\n", + virtual_input_file_name, a_lineno); + print_pos(a_line, a_cptr); + done(1); +} + + +void dollar_warning(int a_lineno, int i) +{ + fprintf(stderr, "File \"%s\", line %d: warning: $%d references beyond the \ +end of the current rule\n", virtual_input_file_name, a_lineno, i); +} + + +void dollar_error(int a_lineno, char *a_line, char *a_cptr) +{ + fprintf(stderr, "File \"%s\", line %d: illegal $-name\n", + virtual_input_file_name, a_lineno); + print_pos(a_line, a_cptr); + done(1); +} + + +void untyped_lhs(void) +{ + fprintf(stderr, "File \"%s\", line %d: $$ is untyped\n", + virtual_input_file_name, lineno); + done(1); +} + + +void untyped_rhs(int i, char *s) +{ + fprintf(stderr, "File \"%s\", line %d: $%d (%s) is untyped\n", + virtual_input_file_name, lineno, i, s); + done(1); +} + + +void unknown_rhs(int i) +{ + fprintf(stderr, "File \"%s\", line %d: $%d is unbound\n", + virtual_input_file_name, lineno, i); + done(1); +} + +void illegal_token_ref(int i, char *name) +{ + fprintf(stderr, "File \"%s\", line %d: $%d refers to terminal `%s', \ +which has no argument\n", + virtual_input_file_name, lineno, i, name); + done(1); +} + +void default_action_error(void) +{ + fprintf(stderr, "File \"%s\", line %d: no action specified for this \ +production\n", + virtual_input_file_name, lineno); + done(1); +} + + +void undefined_goal(char *s) +{ + fprintf(stderr, "%s: e - the start symbol `%s' is undefined\n", myname, s); + done(1); +} + +void undefined_symbol(char *s) +{ + fprintf(stderr, "%s: e - the symbol `%s' is undefined\n", myname, s); + done(1); +} + + +void entry_without_type(char *s) +{ + fprintf(stderr, + "%s: e - no type has been declared for the start symbol `%s'\n", + myname, s); + done(1); +} + +void polymorphic_entry_point(char *s) +{ + fprintf(stderr, + "%s: e - the start symbol `%s' has a polymorphic type\n", + myname, s); + done(1); +} diff --git a/yacc/lalr.c b/yacc/lalr.c new file mode 100644 index 0000000..03a4f07 --- /dev/null +++ b/yacc/lalr.c @@ -0,0 +1,663 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: lalr.c,v 1.8 2001-07-12 12:54:23 doligez Exp $ */ + +#include "defs.h" + +typedef + struct shorts + { + struct shorts *next; + short value; + } + shorts; + +int tokensetsize; +short *lookaheads; +short *LAruleno; +unsigned *LA; +short *accessing_symbol; +core **state_table; +shifts **shift_table; +reductions **reduction_table; +short *goto_map; +short *from_state; +short *to_state; + +short **transpose(short int **R, int n); + +static int infinity; +static int maxrhs; +static int ngotos; +static unsigned *F; +static short **includes; +static shorts **lookback; +static short **R; +static short *INDEX; +static short *VERTICES; +static int top; + + + +void set_state_table (void); +void set_accessing_symbol (void); +void set_shift_table (void); +void set_reduction_table (void); +void set_maxrhs (void); +void initialize_LA (void); +void set_goto_map (void); +void initialize_F (void); +void build_relations (void); +void compute_FOLLOWS (void); +void compute_lookaheads (void); +void digraph (short int **relation); +void add_lookback_edge (int stateno, int ruleno, int gotono); +void traverse (register int i); + +void lalr(void) +{ + tokensetsize = WORDSIZE(ntokens); + + set_state_table(); + set_accessing_symbol(); + set_shift_table(); + set_reduction_table(); + set_maxrhs(); + initialize_LA(); + set_goto_map(); + initialize_F(); + build_relations(); + compute_FOLLOWS(); + compute_lookaheads(); +} + + + +void set_state_table(void) +{ + register core *sp; + + state_table = NEW2(nstates, core *); + for (sp = first_state; sp; sp = sp->next) + state_table[sp->number] = sp; +} + + + +void set_accessing_symbol(void) +{ + register core *sp; + + accessing_symbol = NEW2(nstates, short); + for (sp = first_state; sp; sp = sp->next) + accessing_symbol[sp->number] = sp->accessing_symbol; +} + + + +void set_shift_table(void) +{ + register shifts *sp; + + shift_table = NEW2(nstates, shifts *); + for (sp = first_shift; sp; sp = sp->next) + shift_table[sp->number] = sp; +} + + + +void set_reduction_table(void) +{ + register reductions *rp; + + reduction_table = NEW2(nstates, reductions *); + for (rp = first_reduction; rp; rp = rp->next) + reduction_table[rp->number] = rp; +} + + + +void set_maxrhs(void) +{ + register short *itemp; + register short *item_end; + register int length; + register int max; + + length = 0; + max = 0; + item_end = ritem + nitems; + for (itemp = ritem; itemp < item_end; itemp++) + { + if (*itemp >= 0) + { + length++; + } + else + { + if (length > max) max = length; + length = 0; + } + } + + maxrhs = max; +} + + + +void initialize_LA(void) +{ + register int i, j, k; + register reductions *rp; + + lookaheads = NEW2(nstates + 1, short); + + k = 0; + for (i = 0; i < nstates; i++) + { + lookaheads[i] = k; + rp = reduction_table[i]; + if (rp) + k += rp->nreds; + } + lookaheads[nstates] = k; + + LA = NEW2(k * tokensetsize, unsigned); + LAruleno = NEW2(k, short); + lookback = NEW2(k, shorts *); + + k = 0; + for (i = 0; i < nstates; i++) + { + rp = reduction_table[i]; + if (rp) + { + for (j = 0; j < rp->nreds; j++) + { + LAruleno[k] = rp->rules[j]; + k++; + } + } + } +} + + +void set_goto_map(void) +{ + register shifts *sp; + register int i; + register int symbol; + register int k; + register short *temp_map; + register int state2; + register int state1; + + goto_map = NEW2(nvars + 1, short) - ntokens; + temp_map = NEW2(nvars + 1, short) - ntokens; + + ngotos = 0; + for (sp = first_shift; sp; sp = sp->next) + { + for (i = sp->nshifts - 1; i >= 0; i--) + { + symbol = accessing_symbol[sp->shift[i]]; + + if (ISTOKEN(symbol)) break; + + if (ngotos == MAXSHORT) + fatal("too many gotos"); + + ngotos++; + goto_map[symbol]++; + } + } + + k = 0; + for (i = ntokens; i < nsyms; i++) + { + temp_map[i] = k; + k += goto_map[i]; + } + + for (i = ntokens; i < nsyms; i++) + goto_map[i] = temp_map[i]; + + goto_map[nsyms] = ngotos; + temp_map[nsyms] = ngotos; + + from_state = NEW2(ngotos, short); + to_state = NEW2(ngotos, short); + + for (sp = first_shift; sp; sp = sp->next) + { + state1 = sp->number; + for (i = sp->nshifts - 1; i >= 0; i--) + { + state2 = sp->shift[i]; + symbol = accessing_symbol[state2]; + + if (ISTOKEN(symbol)) break; + + k = temp_map[symbol]++; + from_state[k] = state1; + to_state[k] = state2; + } + } + + FREE(temp_map + ntokens); +} + + + +/* Map_goto maps a state/symbol pair into its numeric representation. */ + +int +map_goto(int state, int symbol) +{ + register int high; + register int low; + register int middle; + register int s; + + low = goto_map[symbol]; + high = goto_map[symbol + 1]; + + for (;;) + { + assert(low <= high); + middle = (low + high) >> 1; + s = from_state[middle]; + if (s == state) + return (middle); + else if (s < state) + low = middle + 1; + else + high = middle - 1; + } +} + + + +void initialize_F(void) +{ + register int i; + register int j; + register int k; + register shifts *sp; + register short *edge; + register unsigned *rowp; + register short *rp; + register short **reads; + register int nedges; + register int stateno; + register int symbol; + register int nwords; + + nwords = ngotos * tokensetsize; + F = NEW2(nwords, unsigned); + + reads = NEW2(ngotos, short *); + edge = NEW2(ngotos + 1, short); + nedges = 0; + + rowp = F; + for (i = 0; i < ngotos; i++) + { + stateno = to_state[i]; + sp = shift_table[stateno]; + + if (sp) + { + k = sp->nshifts; + + for (j = 0; j < k; j++) + { + symbol = accessing_symbol[sp->shift[j]]; + if (ISVAR(symbol)) + break; + SETBIT(rowp, symbol); + } + + for (; j < k; j++) + { + symbol = accessing_symbol[sp->shift[j]]; + if (nullable[symbol]) + edge[nedges++] = map_goto(stateno, symbol); + } + + if (nedges) + { + reads[i] = rp = NEW2(nedges + 1, short); + + for (j = 0; j < nedges; j++) + rp[j] = edge[j]; + + rp[nedges] = -1; + nedges = 0; + } + } + + rowp += tokensetsize; + } + + SETBIT(F, 0); + digraph(reads); + + for (i = 0; i < ngotos; i++) + { + if (reads[i]) + FREE(reads[i]); + } + + FREE(reads); + FREE(edge); +} + + + +void build_relations(void) +{ + register int i; + register int j; + register int k; + register short *rulep; + register short *rp; + register shifts *sp; + register int length; + register int nedges; + register int done; + register int state1; + register int stateno; + register int symbol1; + register int symbol2; + register short *shortp; + register short *edge; + register short *states; + register short **new_includes; + + includes = NEW2(ngotos, short *); + edge = NEW2(ngotos + 1, short); + states = NEW2(maxrhs + 1, short); + + for (i = 0; i < ngotos; i++) + { + nedges = 0; + state1 = from_state[i]; + symbol1 = accessing_symbol[to_state[i]]; + + for (rulep = derives[symbol1]; *rulep >= 0; rulep++) + { + length = 1; + states[0] = state1; + stateno = state1; + + for (rp = ritem + rrhs[*rulep]; *rp >= 0; rp++) + { + symbol2 = *rp; + sp = shift_table[stateno]; + k = sp->nshifts; + + for (j = 0; j < k; j++) + { + stateno = sp->shift[j]; + if (accessing_symbol[stateno] == symbol2) break; + } + + states[length++] = stateno; + } + + add_lookback_edge(stateno, *rulep, i); + + length--; + done = 0; + while (!done) + { + done = 1; + rp--; + if (ISVAR(*rp)) + { + stateno = states[--length]; + edge[nedges++] = map_goto(stateno, *rp); + if (nullable[*rp] && length > 0) done = 0; + } + } + } + + if (nedges) + { + includes[i] = shortp = NEW2(nedges + 1, short); + for (j = 0; j < nedges; j++) + shortp[j] = edge[j]; + shortp[nedges] = -1; + } + } + + new_includes = transpose(includes, ngotos); + + for (i = 0; i < ngotos; i++) + if (includes[i]) + FREE(includes[i]); + + FREE(includes); + + includes = new_includes; + + FREE(edge); + FREE(states); +} + + +void add_lookback_edge(int stateno, int ruleno, int gotono) +{ + register int i, k; + register int found; + register shorts *sp; + + i = lookaheads[stateno]; + k = lookaheads[stateno + 1]; + found = 0; + while (!found && i < k) + { + if (LAruleno[i] == ruleno) + found = 1; + else + ++i; + } + assert(found); + + sp = NEW(shorts); + sp->next = lookback[i]; + sp->value = gotono; + lookback[i] = sp; +} + + + +short ** +transpose(short int **R, int n) +{ + register short **new_R; + register short **temp_R; + register short *nedges; + register short *sp; + register int i; + register int k; + + nedges = NEW2(n, short); + + for (i = 0; i < n; i++) + { + sp = R[i]; + if (sp) + { + while (*sp >= 0) + nedges[*sp++]++; + } + } + + new_R = NEW2(n, short *); + temp_R = NEW2(n, short *); + + for (i = 0; i < n; i++) + { + k = nedges[i]; + if (k > 0) + { + sp = NEW2(k + 1, short); + new_R[i] = sp; + temp_R[i] = sp; + sp[k] = -1; + } + } + + FREE(nedges); + + for (i = 0; i < n; i++) + { + sp = R[i]; + if (sp) + { + while (*sp >= 0) + *temp_R[*sp++]++ = i; + } + } + + FREE(temp_R); + + return (new_R); +} + + + +void compute_FOLLOWS(void) +{ + digraph(includes); +} + + +void compute_lookaheads(void) +{ + register int i, n; + register unsigned *fp1, *fp2, *fp3; + register shorts *sp, *next; + register unsigned *rowp; + + rowp = LA; + n = lookaheads[nstates]; + for (i = 0; i < n; i++) + { + fp3 = rowp + tokensetsize; + for (sp = lookback[i]; sp; sp = sp->next) + { + fp1 = rowp; + fp2 = F + tokensetsize * sp->value; + while (fp1 < fp3) + *fp1++ |= *fp2++; + } + rowp = fp3; + } + + for (i = 0; i < n; i++) + for (sp = lookback[i]; sp; sp = next) + { + next = sp->next; + FREE(sp); + } + + FREE(lookback); + FREE(F); +} + + +void digraph(short int **relation) +{ + register int i; + + infinity = ngotos + 2; + INDEX = NEW2(ngotos + 1, short); + VERTICES = NEW2(ngotos + 1, short); + top = 0; + + R = relation; + + for (i = 0; i < ngotos; i++) + INDEX[i] = 0; + + for (i = 0; i < ngotos; i++) + { + if (INDEX[i] == 0 && R[i]) + traverse(i); + } + + FREE(INDEX); + FREE(VERTICES); +} + + + +void traverse(register int i) +{ + register unsigned *fp1; + register unsigned *fp2; + register unsigned *fp3; + register int j; + register short *rp; + + int height; + unsigned *base; + + VERTICES[++top] = i; + INDEX[i] = height = top; + + base = F + i * tokensetsize; + fp3 = base + tokensetsize; + + rp = R[i]; + if (rp) + { + while ((j = *rp++) >= 0) + { + if (INDEX[j] == 0) + traverse(j); + + if (INDEX[i] > INDEX[j]) + INDEX[i] = INDEX[j]; + + fp1 = base; + fp2 = F + j * tokensetsize; + + while (fp1 < fp3) + *fp1++ |= *fp2++; + } + } + + if (INDEX[i] == height) + { + for (;;) + { + j = VERTICES[top--]; + INDEX[j] = infinity; + + if (i == j) + break; + + fp1 = base; + fp2 = F + j * tokensetsize; + + while (fp1 < fp3) + *fp2++ = *fp1++; + } + } +} diff --git a/yacc/lr0.c b/yacc/lr0.c new file mode 100644 index 0000000..c9605d5 --- /dev/null +++ b/yacc/lr0.c @@ -0,0 +1,621 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: lr0.c,v 1.8 2001-07-12 12:54:23 doligez Exp $ */ + + +#include "defs.h" + +extern short *itemset; +extern short *itemsetend; +extern unsigned *ruleset; + +int nstates; +core *first_state; +shifts *first_shift; +reductions *first_reduction; + +int get_state(int symbol); +core *new_state(int symbol); + +static core **state_set; +static core *this_state; +static core *last_state; +static shifts *last_shift; +static reductions *last_reduction; + +static int nshifts; +static short *shift_symbol; + +static short *redset; +static short *shiftset; + +static short **kernel_base; +static short **kernel_end; +static short *kernel_items; + + + +void initialize_states (void); +void save_reductions (void); +void new_itemsets (void); +void save_shifts (void); +void print_derives (); +void show_cores (void), show_ritems (void), show_rrhs (void), show_shifts (void); + +void allocate_itemsets(void) +{ + register short *itemp; + register short *item_end; + register int symbol; + register int i; + register int count; + register int max; + register short *symbol_count; + + count = 0; + symbol_count = NEW2(nsyms, short); + + item_end = ritem + nitems; + for (itemp = ritem; itemp < item_end; itemp++) + { + symbol = *itemp; + if (symbol >= 0) + { + count++; + symbol_count[symbol]++; + } + } + + kernel_base = NEW2(nsyms, short *); + kernel_items = NEW2(count, short); + + count = 0; + max = 0; + for (i = 0; i < nsyms; i++) + { + kernel_base[i] = kernel_items + count; + count += symbol_count[i]; + if (max < symbol_count[i]) + max = symbol_count[i]; + } + + shift_symbol = symbol_count; + kernel_end = NEW2(nsyms, short *); +} + + +void allocate_storage(void) +{ + allocate_itemsets(); + shiftset = NEW2(nsyms, short); + redset = NEW2(nrules + 1, short); + state_set = NEW2(nitems, core *); +} + + +void append_states(void) +{ + register int i; + register int j; + register int symbol; + +#ifdef TRACE + fprintf(stderr, "Entering append_states()\n"); +#endif + for (i = 1; i < nshifts; i++) + { + symbol = shift_symbol[i]; + j = i; + while (j > 0 && shift_symbol[j - 1] > symbol) + { + shift_symbol[j] = shift_symbol[j - 1]; + j--; + } + shift_symbol[j] = symbol; + } + + for (i = 0; i < nshifts; i++) + { + symbol = shift_symbol[i]; + shiftset[i] = get_state(symbol); + } +} + + +void free_storage(void) +{ + FREE(shift_symbol); + FREE(redset); + FREE(shiftset); + FREE(kernel_base); + FREE(kernel_end); + FREE(kernel_items); + FREE(state_set); +} + + + +void generate_states(void) +{ + allocate_storage(); + itemset = NEW2(nitems, short); + ruleset = NEW2(WORDSIZE(nrules), unsigned); + set_first_derives(); + initialize_states(); + + while (this_state) + { + closure(this_state->items, this_state->nitems); + save_reductions(); + new_itemsets(); + append_states(); + + if (nshifts > 0) + save_shifts(); + + this_state = this_state->next; + } + + finalize_closure(); + free_storage(); +} + + + +int +get_state(int symbol) +{ + register int key; + register short *isp1; + register short *isp2; + register short *iend; + register core *sp; + register int found; + register int n; + +#ifdef TRACE + fprintf(stderr, "Entering get_state(%d)\n", symbol); +#endif + + isp1 = kernel_base[symbol]; + iend = kernel_end[symbol]; + n = iend - isp1; + + key = *isp1; + assert(0 <= key && key < nitems); + sp = state_set[key]; + if (sp) + { + found = 0; + while (!found) + { + if (sp->nitems == n) + { + found = 1; + isp1 = kernel_base[symbol]; + isp2 = sp->items; + + while (found && isp1 < iend) + { + if (*isp1++ != *isp2++) + found = 0; + } + } + + if (!found) + { + if (sp->link) + { + sp = sp->link; + } + else + { + sp = sp->link = new_state(symbol); + found = 1; + } + } + } + } + else + { + state_set[key] = sp = new_state(symbol); + } + + return (sp->number); +} + + + +void initialize_states(void) +{ + register int i; + register short *start_derives; + register core *p; + + start_derives = derives[start_symbol]; + for (i = 0; start_derives[i] >= 0; ++i) + continue; + + p = (core *) MALLOC(sizeof(core) + i*sizeof(short)); + if (p == 0) no_space(); + + p->next = 0; + p->link = 0; + p->number = 0; + p->accessing_symbol = 0; + p->nitems = i; + + for (i = 0; start_derives[i] >= 0; ++i) + p->items[i] = rrhs[start_derives[i]]; + + first_state = last_state = this_state = p; + nstates = 1; +} + + +void new_itemsets(void) +{ + register int i; + register int shiftcount; + register short *isp; + register short *ksp; + register int symbol; + + for (i = 0; i < nsyms; i++) + kernel_end[i] = 0; + + shiftcount = 0; + isp = itemset; + while (isp < itemsetend) + { + i = *isp++; + symbol = ritem[i]; + if (symbol > 0) + { + ksp = kernel_end[symbol]; + if (!ksp) + { + shift_symbol[shiftcount++] = symbol; + ksp = kernel_base[symbol]; + } + + *ksp++ = i + 1; + kernel_end[symbol] = ksp; + } + } + + nshifts = shiftcount; +} + + + +core * +new_state(int symbol) +{ + register int n; + register core *p; + register short *isp1; + register short *isp2; + register short *iend; + +#ifdef TRACE + fprintf(stderr, "Entering new_state(%d)\n", symbol); +#endif + + if (nstates >= MAXSHORT) + fatal("too many states"); + + isp1 = kernel_base[symbol]; + iend = kernel_end[symbol]; + n = iend - isp1; + + p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short))); + p->accessing_symbol = symbol; + p->number = nstates; + p->nitems = n; + + isp2 = p->items; + while (isp1 < iend) + *isp2++ = *isp1++; + + last_state->next = p; + last_state = p; + + nstates++; + + return (p); +} + + +/* show_cores is used for debugging */ + +void show_cores(void) +{ + core *p; + int i, j, k, n; + int itemno; + + k = 0; + for (p = first_state; p; ++k, p = p->next) + { + if (k) printf("\n"); + printf("state %d, number = %d, accessing symbol = %s\n", + k, p->number, symbol_name[p->accessing_symbol]); + n = p->nitems; + for (i = 0; i < n; ++i) + { + itemno = p->items[i]; + printf("%4d ", itemno); + j = itemno; + while (ritem[j] >= 0) ++j; + printf("%s :", symbol_name[rlhs[-ritem[j]]]); + j = rrhs[-ritem[j]]; + while (j < itemno) + printf(" %s", symbol_name[ritem[j++]]); + printf(" ."); + while (ritem[j] >= 0) + printf(" %s", symbol_name[ritem[j++]]); + printf("\n"); + fflush(stdout); + } + } +} + + +/* show_ritems is used for debugging */ + +void show_ritems(void) +{ + int i; + + for (i = 0; i < nitems; ++i) + printf("ritem[%d] = %d\n", i, ritem[i]); +} + + +/* show_rrhs is used for debugging */ + +void show_rrhs(void) +{ + int i; + + for (i = 0; i < nrules; ++i) + printf("rrhs[%d] = %d\n", i, rrhs[i]); +} + + +/* show_shifts is used for debugging */ + +void show_shifts(void) +{ + shifts *p; + int i, j, k; + + k = 0; + for (p = first_shift; p; ++k, p = p->next) + { + if (k) printf("\n"); + printf("shift %d, number = %d, nshifts = %d\n", k, p->number, + p->nshifts); + j = p->nshifts; + for (i = 0; i < j; ++i) + printf("\t%d\n", p->shift[i]); + } +} + + +void save_shifts(void) +{ + register shifts *p; + register short *sp1; + register short *sp2; + register short *send; + + p = (shifts *) allocate((unsigned) (sizeof(shifts) + + (nshifts - 1) * sizeof(short))); + + p->number = this_state->number; + p->nshifts = nshifts; + + sp1 = shiftset; + sp2 = p->shift; + send = shiftset + nshifts; + + while (sp1 < send) + *sp2++ = *sp1++; + + if (last_shift) + { + last_shift->next = p; + last_shift = p; + } + else + { + first_shift = p; + last_shift = p; + } +} + + + +void save_reductions(void) +{ + register short *isp; + register short *rp1; + register short *rp2; + register int item; + register int count; + register reductions *p; + register short *rend; + + count = 0; + for (isp = itemset; isp < itemsetend; isp++) + { + item = ritem[*isp]; + if (item < 0) + { + redset[count++] = -item; + } + } + + if (count) + { + p = (reductions *) allocate((unsigned) (sizeof(reductions) + + (count - 1) * sizeof(short))); + + p->number = this_state->number; + p->nreds = count; + + rp1 = redset; + rp2 = p->rules; + rend = rp1 + count; + + while (rp1 < rend) + *rp2++ = *rp1++; + + if (last_reduction) + { + last_reduction->next = p; + last_reduction = p; + } + else + { + first_reduction = p; + last_reduction = p; + } + } +} + + +void set_derives(void) +{ + register int i, k; + register int lhs; + register short *rules; + + derives = NEW2(nsyms, short *); + rules = NEW2(nvars + nrules, short); + + k = 0; + for (lhs = start_symbol; lhs < nsyms; lhs++) + { + derives[lhs] = rules + k; + for (i = 0; i < nrules; i++) + { + if (rlhs[i] == lhs) + { + rules[k] = i; + k++; + } + } + rules[k] = -1; + k++; + } + +#ifdef DEBUG + print_derives(); +#endif +} + +void free_derives(void) +{ + FREE(derives[start_symbol]); + FREE(derives); +} + +#ifdef DEBUG +void print_derives(void) +{ + register int i; + register short *sp; + + printf("\nDERIVES\n\n"); + + for (i = start_symbol; i < nsyms; i++) + { + printf("%s derives ", symbol_name[i]); + for (sp = derives[i]; *sp >= 0; sp++) + { + printf(" %d", *sp); + } + putchar('\n'); + } + + putchar('\n'); +} +#endif + + +void set_nullable(void) +{ + register int i, j; + register int empty; + int done; + + nullable = MALLOC(nsyms); + if (nullable == 0) no_space(); + + for (i = 0; i < nsyms; ++i) + nullable[i] = 0; + + done = 0; + while (!done) + { + done = 1; + for (i = 1; i < nitems; i++) + { + empty = 1; + while ((j = ritem[i]) >= 0) + { + if (!nullable[j]) + empty = 0; + ++i; + } + if (empty) + { + j = rlhs[-j]; + if (!nullable[j]) + { + nullable[j] = 1; + done = 0; + } + } + } + } + +#ifdef DEBUG + for (i = 0; i < nsyms; i++) + { + if (nullable[i]) + printf("%s is nullable\n", symbol_name[i]); + else + printf("%s is not nullable\n", symbol_name[i]); + } +#endif +} + + +void free_nullable(void) +{ + FREE(nullable); +} + + +void lr0(void) +{ + set_derives(); + set_nullable(); + generate_states(); +} diff --git a/yacc/main.c b/yacc/main.c new file mode 100644 index 0000000..2e36b17 --- /dev/null +++ b/yacc/main.c @@ -0,0 +1,412 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: main.c,v 1.20 2006-04-16 23:28:22 doligez Exp $ */ + +#include <signal.h> +#include <string.h> +#include "defs.h" +#ifdef HAS_UNISTD +#include <unistd.h> +#endif + +#include "version.h" + +char dflag; +char lflag; +char rflag; +char tflag; +char vflag; +char qflag; +char sflag; +char big_endian; + +char *file_prefix = 0; +char *myname = "yacc"; +#ifdef NO_UNIX +char temp_form[] = "yacc.X"; +#else +char temp_form[] = "yacc.XXXXXXX"; +#endif + +int lineno; +char *virtual_input_file_name = NULL; +int outline; + +char *action_file_name; +char *entry_file_name; +char *code_file_name; +char *interface_file_name; +char *defines_file_name; +char *input_file_name = ""; +char *output_file_name; +char *text_file_name; +char *union_file_name; +char *verbose_file_name; + +FILE *action_file; /* a temp file, used to save actions associated */ + /* with rules until the parser is written */ +FILE *entry_file; +FILE *code_file; /* y.code.c (used when the -r option is specified) */ +FILE *defines_file; /* y.tab.h */ +FILE *input_file; /* the input file */ +FILE *output_file; /* y.tab.c */ +FILE *text_file; /* a temp file, used to save text until all */ + /* symbols have been defined */ +FILE *union_file; /* a temp file, used to save the union */ + /* definition until all symbol have been */ + /* defined */ +FILE *verbose_file; /* y.output */ +FILE *interface_file; + +int nitems; +int nrules; +int ntotalrules; +int nsyms; +int ntokens; +int nvars; + +int start_symbol; +char **symbol_name; +short *symbol_value; +short *symbol_prec; +char *symbol_assoc; +char **symbol_tag; +char *symbol_true_token; + +short *ritem; +short *rlhs; +short *rrhs; +short *rprec; +char *rassoc; +short **derives; +char *nullable; + +extern char *mktemp(char *); +extern char *getenv(const char *); + + +void done(int k) +{ + if (action_file) { fclose(action_file); unlink(action_file_name); } + if (entry_file) { fclose(entry_file); unlink(entry_file_name); } + if (text_file) { fclose(text_file); unlink(text_file_name); } + if (union_file) { fclose(union_file); unlink(union_file_name); } + if (output_file && k > 0) { + fclose(output_file); unlink(output_file_name); + } + if (interface_file && k > 0) { + fclose(interface_file); unlink(interface_file_name); + } + exit(k); +} + + +void onintr(int dummy) +{ + done(1); +} + + +void set_signals(void) +{ +#ifdef SIGINT + if (signal(SIGINT, SIG_IGN) != SIG_IGN) + signal(SIGINT, onintr); +#endif +#ifdef SIGTERM + if (signal(SIGTERM, SIG_IGN) != SIG_IGN) + signal(SIGTERM, onintr); +#endif +#ifdef SIGHUP + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) + signal(SIGHUP, onintr); +#endif +} + + +void usage(void) +{ + fprintf(stderr, "usage: %s [-v] [-q] [-b file_prefix] filename\n", + myname); + exit(1); +} + +void getargs(int argc, char **argv) +{ + register int i; + register char *s; + + if (argc > 0) myname = argv[0]; + for (i = 1; i < argc; ++i) + { + s = argv[i]; + if (*s != '-') break; + switch (*++s) + { + case '\0': + input_file = stdin; + file_prefix = "stdin"; + if (i + 1 < argc) usage(); + return; + + case '-': + ++i; + goto no_more_options; + + case 'v': + if (!strcmp (argv[i], "-version")){ + printf ("The Objective Caml parser generator, version " + OCAML_VERSION "\n"); + exit (0); + }else{ + vflag = 1; + } + break; + + case 'q': + qflag = 1; + break; + + case 'b': + if (*++s) + file_prefix = s; + else if (++i < argc) + file_prefix = argv[i]; + else + usage(); + continue; + + default: + usage(); + } + + for (;;) + { + switch (*++s) + { + case '\0': + goto end_of_option; + + case 'v': + vflag = 1; + break; + + case 'q': + qflag = 1; + break; + + default: + usage(); + } + } +end_of_option:; + } + +no_more_options:; + if (i + 1 != argc) usage(); + input_file_name = argv[i]; + if (file_prefix == 0) { + int len; + len = strlen(argv[i]); + file_prefix = malloc(len + 1); + if (file_prefix == 0) no_space(); + strcpy(file_prefix, argv[i]); + while (len > 0) { + len--; + if (file_prefix[len] == '.') { + file_prefix[len] = 0; + break; + } + } + } +} + + +char * +allocate(unsigned int n) +{ + register char *p; + + p = NULL; + if (n) + { + p = CALLOC(1, n); + if (!p) no_space(); + } + return (p); +} + + +void create_file_names(void) +{ + int i, len; + char *tmpdir; + +#ifdef NO_UNIX + len = 0; + i = sizeof(temp_form); +#else + tmpdir = getenv("TMPDIR"); + if (tmpdir == 0) tmpdir = "/tmp"; + len = strlen(tmpdir); + i = len + sizeof(temp_form); + if (len && tmpdir[len-1] != '/') + ++i; +#endif + + action_file_name = MALLOC(i); + if (action_file_name == 0) no_space(); + entry_file_name = MALLOC(i); + if (entry_file_name == 0) no_space(); + text_file_name = MALLOC(i); + if (text_file_name == 0) no_space(); + union_file_name = MALLOC(i); + if (union_file_name == 0) no_space(); + +#ifndef NO_UNIX + strcpy(action_file_name, tmpdir); + strcpy(entry_file_name, tmpdir); + strcpy(text_file_name, tmpdir); + strcpy(union_file_name, tmpdir); + + if (len && tmpdir[len - 1] != '/') + { + action_file_name[len] = '/'; + entry_file_name[len] = '/'; + text_file_name[len] = '/'; + union_file_name[len] = '/'; + ++len; + } +#endif + + strcpy(action_file_name + len, temp_form); + strcpy(entry_file_name + len, temp_form); + strcpy(text_file_name + len, temp_form); + strcpy(union_file_name + len, temp_form); + + action_file_name[len + 5] = 'a'; + entry_file_name[len + 5] = 'e'; + text_file_name[len + 5] = 't'; + union_file_name[len + 5] = 'u'; + +#ifndef NO_UNIX + mktemp(action_file_name); + mktemp(entry_file_name); + mktemp(text_file_name); + mktemp(union_file_name); +#endif + + len = strlen(file_prefix); + + output_file_name = MALLOC(len + 7); + if (output_file_name == 0) + no_space(); + strcpy(output_file_name, file_prefix); + strcpy(output_file_name + len, OUTPUT_SUFFIX); + + code_file_name = output_file_name; + + if (vflag) + { + verbose_file_name = MALLOC(len + 8); + if (verbose_file_name == 0) + no_space(); + strcpy(verbose_file_name, file_prefix); + strcpy(verbose_file_name + len, VERBOSE_SUFFIX); + } + + interface_file_name = MALLOC(len + 8); + if (interface_file_name == 0) + no_space(); + strcpy(interface_file_name, file_prefix); + strcpy(interface_file_name + len, INTERFACE_SUFFIX); + +} + + +void open_files(void) +{ + create_file_names(); + + if (input_file == 0) + { + input_file = fopen(input_file_name, "r"); + if (input_file == 0) + open_error(input_file_name); + } + + action_file = fopen(action_file_name, "w"); + if (action_file == 0) + open_error(action_file_name); + + entry_file = fopen(entry_file_name, "w"); + if (entry_file == 0) + open_error(entry_file_name); + + text_file = fopen(text_file_name, "w"); + if (text_file == 0) + open_error(text_file_name); + + if (vflag) + { + verbose_file = fopen(verbose_file_name, "w"); + if (verbose_file == 0) + open_error(verbose_file_name); + } + + if (dflag) + { + defines_file = fopen(defines_file_name, "w"); + if (defines_file == 0) + open_error(defines_file_name); + union_file = fopen(union_file_name, "w"); + if (union_file == 0) + open_error(union_file_name); + } + + output_file = fopen(output_file_name, "w"); + if (output_file == 0) + open_error(output_file_name); + + if (rflag) + { + code_file = fopen(code_file_name, "w"); + if (code_file == 0) + open_error(code_file_name); + } + else + code_file = output_file; + + + interface_file = fopen(interface_file_name, "w"); + if (interface_file == 0) + open_error(interface_file_name); +} + +int main(int argc, char **argv) +{ + set_signals(); + getargs(argc, argv); + open_files(); + reader(); + lr0(); + lalr(); + make_parser(); + verbose(); + output(); + done(0); + /*NOTREACHED*/ + return 0; +} diff --git a/yacc/mkpar.c b/yacc/mkpar.c new file mode 100644 index 0000000..8357163 --- /dev/null +++ b/yacc/mkpar.c @@ -0,0 +1,366 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: mkpar.c,v 1.11 2001-07-12 12:54:23 doligez Exp $ */ + + +#include "defs.h" + +action **parser; +int SRtotal; +int RRtotal; +short *SRconflicts; +short *RRconflicts; +short *defred; +short *rules_used; +short nunused; +short final_state; + +static int SRcount; +static int RRcount; + +void find_final_state (void); +void remove_conflicts (void); +void unused_rules (void); +void total_conflicts (void); +void defreds (void); + +void make_parser(void) +{ + register int i; + + parser = NEW2(nstates, action *); + for (i = 0; i < nstates; i++) + parser[i] = parse_actions(i); + + find_final_state(); + remove_conflicts(); + unused_rules(); + if (SRtotal + RRtotal > 0) total_conflicts(); + defreds(); +} + + +action * +parse_actions(register int stateno) +{ + register action *actions; + + actions = get_shifts(stateno); + actions = add_reductions(stateno, actions); + return (actions); +} + + +action * +get_shifts(int stateno) +{ + register action *actions, *temp; + register shifts *sp; + register short *to_state; + register int i, k; + register int symbol; + + actions = 0; + sp = shift_table[stateno]; + if (sp) + { + to_state = sp->shift; + for (i = sp->nshifts - 1; i >= 0; i--) + { + k = to_state[i]; + symbol = accessing_symbol[k]; + if (ISTOKEN(symbol)) + { + temp = NEW(action); + temp->next = actions; + temp->symbol = symbol; + temp->number = k; + temp->prec = symbol_prec[symbol]; + temp->action_code = SHIFT; + temp->assoc = symbol_assoc[symbol]; + actions = temp; + } + } + } + return (actions); +} + +action * +add_reductions(int stateno, register action *actions) +{ + register int i, j, m, n; + register int ruleno, tokensetsize; + register unsigned *rowp; + + tokensetsize = WORDSIZE(ntokens); + m = lookaheads[stateno]; + n = lookaheads[stateno + 1]; + for (i = m; i < n; i++) + { + ruleno = LAruleno[i]; + rowp = LA + i * tokensetsize; + for (j = ntokens - 1; j >= 0; j--) + { + if (BIT(rowp, j)) + actions = add_reduce(actions, ruleno, j); + } + } + return (actions); +} + + +action * +add_reduce(register action *actions, register int ruleno, register int symbol) +{ + register action *temp, *prev, *next; + + prev = 0; + for (next = actions; next && next->symbol < symbol; next = next->next) + prev = next; + + while (next && next->symbol == symbol && next->action_code == SHIFT) + { + prev = next; + next = next->next; + } + + while (next && next->symbol == symbol && + next->action_code == REDUCE && next->number < ruleno) + { + prev = next; + next = next->next; + } + + temp = NEW(action); + temp->next = next; + temp->symbol = symbol; + temp->number = ruleno; + temp->prec = rprec[ruleno]; + temp->action_code = REDUCE; + temp->assoc = rassoc[ruleno]; + + if (prev) + prev->next = temp; + else + actions = temp; + + return (actions); +} + + +void find_final_state(void) +{ + register int goal, i; + register short *to_state; + register shifts *p; + + p = shift_table[0]; + to_state = p->shift; + goal = ritem[1]; + for (i = p->nshifts - 1; i >= 0; --i) + { + final_state = to_state[i]; + if (accessing_symbol[final_state] == goal) break; + } +} + + +void unused_rules(void) +{ + register int i; + register action *p; + + rules_used = (short *) MALLOC(nrules*sizeof(short)); + if (rules_used == 0) no_space(); + + for (i = 0; i < nrules; ++i) + rules_used[i] = 0; + + for (i = 0; i < nstates; ++i) + { + for (p = parser[i]; p; p = p->next) + { + if (p->action_code == REDUCE && p->suppressed == 0) + rules_used[p->number] = 1; + } + } + + nunused = 0; + for (i = 3; i < nrules; ++i) + if (!rules_used[i]) ++nunused; + + if (nunused){ + if (nunused == 1) + fprintf(stderr, "1 rule never reduced\n"); + else + fprintf(stderr, "%d rules never reduced\n", nunused); + } +} + + +void remove_conflicts(void) +{ + register int i; + register int symbol; + register action *p, *pref; + + SRtotal = 0; + RRtotal = 0; + SRconflicts = NEW2(nstates, short); + RRconflicts = NEW2(nstates, short); + pref = NULL; + for (i = 0; i < nstates; i++) + { + SRcount = 0; + RRcount = 0; + symbol = -1; + for (p = parser[i]; p; p = p->next) + { + if (p->symbol != symbol) + { + pref = p; + symbol = p->symbol; + } + else if (i == final_state && symbol == 0) + { + SRcount++; + p->suppressed = 1; + } + else if (pref->action_code == SHIFT) + { + if (pref->prec > 0 && p->prec > 0) + { + if (pref->prec < p->prec) + { + pref->suppressed = 2; + pref = p; + } + else if (pref->prec > p->prec) + { + p->suppressed = 2; + } + else if (pref->assoc == LEFT) + { + pref->suppressed = 2; + pref = p; + } + else if (pref->assoc == RIGHT) + { + p->suppressed = 2; + } + else + { + pref->suppressed = 2; + p->suppressed = 2; + } + } + else + { + SRcount++; + p->suppressed = 1; + } + } + else + { + RRcount++; + p->suppressed = 1; + } + } + SRtotal += SRcount; + RRtotal += RRcount; + SRconflicts[i] = SRcount; + RRconflicts[i] = RRcount; + } +} + + +void total_conflicts(void) +{ + if (SRtotal == 1) + fprintf(stderr, "1 shift/reduce conflict"); + else if (SRtotal > 1) + fprintf(stderr, "%d shift/reduce conflicts", SRtotal); + + if (SRtotal && RRtotal) + fprintf(stderr, ", "); + + if (RRtotal == 1) + fprintf(stderr, "1 reduce/reduce conflict"); + else if (RRtotal > 1) + fprintf(stderr, "%d reduce/reduce conflicts", RRtotal); + + fprintf(stderr, ".\n"); +} + + +int +sole_reduction(int stateno) +{ + register int count, ruleno; + register action *p; + + count = 0; + ruleno = 0; + for (p = parser[stateno]; p; p = p->next) + { + if (p->action_code == SHIFT && p->suppressed == 0) + return (0); + else if (p->action_code == REDUCE && p->suppressed == 0) + { + if (ruleno > 0 && p->number != ruleno) + return (0); + if (p->symbol != 1) + ++count; + ruleno = p->number; + } + } + + if (count == 0) + return (0); + return (ruleno); +} + + +void defreds(void) +{ + register int i; + + defred = NEW2(nstates, short); + for (i = 0; i < nstates; i++) + defred[i] = sole_reduction(i); +} + +void free_action_row(register action *p) +{ + register action *q; + + while (p) + { + q = p->next; + FREE(p); + p = q; + } +} + +void free_parser(void) +{ + register int i; + + for (i = 0; i < nstates; i++) + free_action_row(parser[i]); + + FREE(parser); +} + diff --git a/yacc/output.c b/yacc/output.c new file mode 100644 index 0000000..924e757 --- /dev/null +++ b/yacc/output.c @@ -0,0 +1,984 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: output.c,v 1.14 2002-11-02 22:36:46 doligez Exp $ */ + +#include "defs.h" + +static int nvectors; +static int nentries; +static short **froms; +static short **tos; +static short *tally; +static short *width; +static short *state_count; +static short *order; +static short *base; +static short *pos; +static int maxtable; +static short *table; +static short *check; +static int lowzero; +static int high; + + +void free_itemsets (void); +void free_shifts (void); +void free_reductions (void); +void output_stored_text (void); +void output_transl (void); +void output_rule_data (void); +void output_yydefred (void); +void output_actions (void); +void output_debug (void); +void output_trailing_text (void); +void output_semantic_actions (void); +void output_entries (void); +void token_actions (void); +void goto_actions (void); +void sort_actions (void); +void pack_table (void); +void output_base (void); +void output_table (void); +void output_check (void); +int default_goto (int symbol); +void save_column (int symbol, int default_state); +int matching_vector (int vector); +int pack_vector (int vector); + + +void output(void) +{ + extern char *header[], *define_tables[]; + + free_itemsets(); + free_shifts(); + free_reductions(); + write_section(header); + output_stored_text(); + output_transl(); + output_rule_data(); + output_yydefred(); + output_actions(); + output_debug(); + free_parser(); + if (sflag){ + if (!rflag) ++outline; + fprintf(output_file, + "let yyact = Array.new %d (fun _ -> (failwith \"parser\" : Obj.t))\n", + ntotalrules); + }else{ + if (!rflag) outline += 2; + fprintf(output_file, + "let yyact = [|\n (fun _ -> failwith \"parser\")\n"); + } + output_semantic_actions(); + if (!sflag){ + if (!rflag) ++outline; + fprintf(output_file, "|]\n"); + } + write_section(define_tables); + output_entries(); + output_trailing_text(); +} + + +static void output_char(unsigned int n) +{ + n = n & 0xFF; + putc('\\', output_file); + putc('0' + n / 100, output_file); + putc('0' + (n / 10) % 10, output_file); + putc('0' + n % 10, output_file); +} + +static void output_short(int n) +{ + output_char(n); + output_char(n >> 8); +} + +void output_rule_data(void) +{ + register int i; + register int j; + + + fprintf(output_file, "let yylhs = \""); + output_short(symbol_value[start_symbol]); + + j = 8; + for (i = 3; i < nrules; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(symbol_value[rlhs[i]]); + } + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + + fprintf(output_file, "let yylen = \""); + output_short(2); + + j = 8; + for (i = 3; i < nrules; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + j++; + + output_short(rrhs[i + 1] - rrhs[i] - 1); + } + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); +} + + +void output_yydefred(void) +{ + register int i, j; + + fprintf(output_file, "let yydefred = \""); + output_short(defred[0] ? defred[0] - 2 : 0); + + j = 8; + for (i = 1; i < nstates; i++) + { + if (j < 8) + ++j; + else + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + + output_short(defred[i] ? defred[i] - 2 : 0); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); +} + + +void output_actions(void) +{ + nvectors = 2*nstates + nvars; + + froms = NEW2(nvectors, short *); + tos = NEW2(nvectors, short *); + tally = NEW2(nvectors, short); + width = NEW2(nvectors, short); + + token_actions(); + FREE(lookaheads); + FREE(LA); + FREE(LAruleno); + FREE(accessing_symbol); + + goto_actions(); + FREE(goto_map + ntokens); + FREE(from_state); + FREE(to_state); + + sort_actions(); + pack_table(); + output_base(); + output_table(); + output_check(); +} + + +void token_actions(void) +{ + register int i, j; + register int shiftcount, reducecount; + register int max, min; + register short *actionrow, *r, *s; + register action *p; + + actionrow = NEW2(2*ntokens, short); + for (i = 0; i < nstates; ++i) + { + if (parser[i]) + { + for (j = 0; j < 2*ntokens; ++j) + actionrow[j] = 0; + + shiftcount = 0; + reducecount = 0; + for (p = parser[i]; p; p = p->next) + { + if (p->suppressed == 0) + { + if (p->action_code == SHIFT) + { + ++shiftcount; + actionrow[p->symbol] = p->number; + } + else if (p->action_code == REDUCE && p->number != defred[i]) + { + ++reducecount; + actionrow[p->symbol + ntokens] = p->number; + } + } + } + + tally[i] = shiftcount; + tally[nstates+i] = reducecount; + width[i] = 0; + width[nstates+i] = 0; + if (shiftcount > 0) + { + froms[i] = r = NEW2(shiftcount, short); + tos[i] = s = NEW2(shiftcount, short); + min = MAXSHORT; + max = 0; + for (j = 0; j < ntokens; ++j) + { + if (actionrow[j]) + { + if (min > symbol_value[j]) + min = symbol_value[j]; + if (max < symbol_value[j]) + max = symbol_value[j]; + *r++ = symbol_value[j]; + *s++ = actionrow[j]; + } + } + width[i] = max - min + 1; + } + if (reducecount > 0) + { + froms[nstates+i] = r = NEW2(reducecount, short); + tos[nstates+i] = s = NEW2(reducecount, short); + min = MAXSHORT; + max = 0; + for (j = 0; j < ntokens; ++j) + { + if (actionrow[ntokens+j]) + { + if (min > symbol_value[j]) + min = symbol_value[j]; + if (max < symbol_value[j]) + max = symbol_value[j]; + *r++ = symbol_value[j]; + *s++ = actionrow[ntokens+j] - 2; + } + } + width[nstates+i] = max - min + 1; + } + } + } + FREE(actionrow); +} + +void goto_actions(void) +{ + register int i, j, k; + + state_count = NEW2(nstates, short); + + k = default_goto(start_symbol + 1); + fprintf(output_file, "let yydgoto = \""); + output_short(k); + + save_column(start_symbol + 1, k); + + j = 8; + for (i = start_symbol + 2; i < nsyms; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + k = default_goto(i); + output_short(k); + save_column(i, k); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + FREE(state_count); +} + +int +default_goto(int symbol) +{ + register int i; + register int m; + register int n; + register int default_state; + register int max; + + m = goto_map[symbol]; + n = goto_map[symbol + 1]; + + if (m == n) return (0); + + for (i = 0; i < nstates; i++) + state_count[i] = 0; + + for (i = m; i < n; i++) + state_count[to_state[i]]++; + + max = 0; + default_state = 0; + for (i = 0; i < nstates; i++) + { + if (state_count[i] > max) + { + max = state_count[i]; + default_state = i; + } + } + + return (default_state); +} + + + +void save_column(int symbol, int default_state) +{ + register int i; + register int m; + register int n; + register short *sp; + register short *sp1; + register short *sp2; + register int count; + register int symno; + + m = goto_map[symbol]; + n = goto_map[symbol + 1]; + + count = 0; + for (i = m; i < n; i++) + { + if (to_state[i] != default_state) + ++count; + } + if (count == 0) return; + + symno = symbol_value[symbol] + 2*nstates; + + froms[symno] = sp1 = sp = NEW2(count, short); + tos[symno] = sp2 = NEW2(count, short); + + for (i = m; i < n; i++) + { + if (to_state[i] != default_state) + { + *sp1++ = from_state[i]; + *sp2++ = to_state[i]; + } + } + + tally[symno] = count; + width[symno] = sp1[-1] - sp[0] + 1; +} + +void sort_actions(void) +{ + register int i; + register int j; + register int k; + register int t; + register int w; + + order = NEW2(nvectors, short); + nentries = 0; + + for (i = 0; i < nvectors; i++) + { + if (tally[i] > 0) + { + t = tally[i]; + w = width[i]; + j = nentries - 1; + + while (j >= 0 && (width[order[j]] < w)) + j--; + + while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) + j--; + + for (k = nentries - 1; k > j; k--) + order[k + 1] = order[k]; + + order[j + 1] = i; + nentries++; + } + } +} + + +void pack_table(void) +{ + register int i; + register int place; + register int state; + + base = NEW2(nvectors, short); + pos = NEW2(nentries, short); + + maxtable = 1000; + table = NEW2(maxtable, short); + check = NEW2(maxtable, short); + + lowzero = 0; + high = 0; + + for (i = 0; i < maxtable; i++) + check[i] = -1; + + for (i = 0; i < nentries; i++) + { + state = matching_vector(i); + + if (state < 0) + place = pack_vector(i); + else + place = base[state]; + + pos[i] = place; + base[order[i]] = place; + } + + for (i = 0; i < nvectors; i++) + { + if (froms[i]) + FREE(froms[i]); + if (tos[i]) + FREE(tos[i]); + } + + FREE(froms); + FREE(tos); + FREE(pos); +} + + +/* The function matching_vector determines if the vector specified by */ +/* the input parameter matches a previously considered vector. The */ +/* test at the start of the function checks if the vector represents */ +/* a row of shifts over terminal symbols or a row of reductions, or a */ +/* column of shifts over a nonterminal symbol. Berkeley Yacc does not */ +/* check if a column of shifts over a nonterminal symbols matches a */ +/* previously considered vector. Because of the nature of LR parsing */ +/* tables, no two columns can match. Therefore, the only possible */ +/* match would be between a row and a column. Such matches are */ +/* unlikely. Therefore, to save time, no attempt is made to see if a */ +/* column matches a previously considered vector. */ +/* */ +/* Matching_vector is poorly designed. The test could easily be made */ +/* faster. Also, it depends on the vectors being in a specific */ +/* order. */ + +int +matching_vector(int vector) +{ + register int i; + register int j; + register int k; + register int t; + register int w; + register int match; + register int prev; + + i = order[vector]; + if (i >= 2*nstates) + return (-1); + + t = tally[i]; + w = width[i]; + + for (prev = vector - 1; prev >= 0; prev--) + { + j = order[prev]; + if (width[j] != w || tally[j] != t) + return (-1); + + match = 1; + for (k = 0; match && k < t; k++) + { + if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k]) + match = 0; + } + + if (match) + return (j); + } + + return (-1); +} + + + +int +pack_vector(int vector) +{ + register int i, j, k, l; + register int t; + register int loc; + register int ok; + register short *from; + register short *to; + int newmax; + + i = order[vector]; + t = tally[i]; + assert(t); + + from = froms[i]; + to = tos[i]; + + j = lowzero - from[0]; + for (k = 1; k < t; ++k) + if (lowzero - from[k] > j) + j = lowzero - from[k]; + for (;; ++j) + { + if (j == 0) + continue; + ok = 1; + for (k = 0; ok && k < t; k++) + { + loc = j + from[k]; + if (loc >= maxtable) + { + if (loc >= MAXTABLE) + fatal("maximum table size exceeded"); + + newmax = maxtable; + do { newmax += 200; } while (newmax <= loc); + table = (short *) REALLOC(table, newmax*sizeof(short)); + if (table == 0) no_space(); + check = (short *) REALLOC(check, newmax*sizeof(short)); + if (check == 0) no_space(); + for (l = maxtable; l < newmax; ++l) + { + table[l] = 0; + check[l] = -1; + } + maxtable = newmax; + } + + if (check[loc] != -1) + ok = 0; + } + for (k = 0; ok && k < vector; k++) + { + if (pos[k] == j) + ok = 0; + } + if (ok) + { + for (k = 0; k < t; k++) + { + loc = j + from[k]; + table[loc] = to[k]; + check[loc] = from[k]; + if (loc > high) high = loc; + } + + while (lowzero < maxtable && check[lowzero] != -1) + ++lowzero; + + return (j); + } + } +} + + + +void output_base(void) +{ + register int i, j; + + fprintf(output_file, "let yysindex = \""); + output_short(base[0]); + + j = 8; + for (i = 1; i < nstates; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + + fprintf(output_file, "let yyrindex = \""); + output_short(base[nstates]); + + j = 8; + for (i = nstates + 1; i < 2*nstates; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + + fprintf(output_file, "let yygindex = \""); + output_short(base[2*nstates]); + + j = 8; + for (i = 2*nstates + 1; i < nvectors - 1; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + FREE(base); +} + + + +void output_table(void) +{ + register int i; + register int j; + + ++outline; + fprintf(code_file, "let yytablesize = %d\n", high); + fprintf(output_file, "let yytable = \""); + output_short(table[0]); + + j = 8; + for (i = 1; i <= high; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(table[i]); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + FREE(table); +} + + + +void output_check(void) +{ + register int i; + register int j; + + fprintf(output_file, "let yycheck = \""); + output_short(check[0]); + + j = 8; + for (i = 1; i <= high; i++) + { + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(check[i]); + } + + if (!rflag) outline += 2; + fprintf(output_file, "\"\n\n"); + FREE(check); +} + + +void output_transl(void) +{ + int i; + + ++outline; + fprintf(code_file, "let yytransl_const = [|\n"); + for (i = 0; i < ntokens; i++) { + if (symbol_true_token[i] && symbol_tag[i] == NULL) { + ++outline; + fprintf(code_file, " %3d (* %s *);\n", symbol_value[i], symbol_name[i]); + } + } + outline += 2; + fprintf(code_file, " 0|]\n\n"); + ++outline; + fprintf(code_file, "let yytransl_block = [|\n"); + for (i = 0; i < ntokens; i++) { + if (symbol_true_token[i] && symbol_tag[i] != NULL) { + ++outline; + fprintf(code_file, " %3d (* %s *);\n", symbol_value[i], symbol_name[i]); + } + } + outline += 2; + fprintf(code_file, " 0|]\n\n"); +} + +void output_stored_text(void) +{ + register int c; + register FILE *in, *out; + + fclose(text_file); + text_file = fopen(text_file_name, "r"); + if (text_file == NULL) + open_error(text_file_name); + in = text_file; + if ((c = getc(in)) == EOF) + return; + out = code_file; + if (c == '\n') + ++outline; + putc(c, out); + while ((c = getc(in)) != EOF) + { + if (c == '\n') + ++outline; + putc(c, out); + } + if (!lflag) + fprintf(out, line_format, ++outline + 1, code_file_name); +} + + +void output_debug(void) +{ + int i; + + ++outline; + fprintf(code_file, "let yynames_const = \"\\\n"); + for (i = 0; i < ntokens; i++) { + if (symbol_true_token[i] && symbol_tag[i] == NULL) { + ++outline; + fprintf(code_file, " %s\\000\\\n", symbol_name[i]); + } + } + outline += 2; + fprintf(code_file, " \"\n\n"); + ++outline; + fprintf(code_file, "let yynames_block = \"\\\n"); + for (i = 0; i < ntokens; i++) { + if (symbol_true_token[i] && symbol_tag[i] != NULL) { + ++outline; + fprintf(code_file, " %s\\000\\\n", symbol_name[i]); + } + } + outline += 2; + fprintf(code_file, " \"\n\n"); +} + +void output_trailing_text(void) +{ + register int c, last; + register FILE *in, *out; + + if (line == 0) + return; + + in = input_file; + out = code_file; + + ++outline; + fprintf (out, ";;\n"); + + c = *cptr; + if (c == '\n') + { + ++lineno; + if ((c = getc(in)) == EOF) + return; + if (!lflag) + { + ++outline; + fprintf(out, line_format, lineno, input_file_name); + } + if (c == '\n') + ++outline; + putc(c, out); + last = c; + } + else + { + if (!lflag) + { + ++outline; + fprintf(out, line_format, lineno, input_file_name); + } + do { putc(c, out); } while ((c = *++cptr) != '\n'); + ++outline; + putc('\n', out); + last = '\n'; + } + + + while ((c = getc(in)) != EOF) + { + if (c == '\n') + ++outline; + putc(c, out); + last = c; + } + + if (last != '\n') + { + ++outline; + putc('\n', out); + } + if (!lflag) + fprintf(out, line_format, ++outline + 1, code_file_name); +} + + +void copy_file(FILE **file, char *file_name) +{ + register int c, last; + register FILE *out = code_file; + int state = 0; + + fclose(*file); + *file = fopen(file_name, "r"); + if (*file == NULL) + open_error(file_name); + + last = '\n'; + + while ((c = getc(*file)) != EOF) + { + switch (c){ + case '\n': state = 1; break; + case '#': state = (state == 1) ? 2 : 0; break; + case ' ': state = (state == 2) ? 3 : 0; break; + case '0': + if (state == 3){ + fprintf (out, "%d \"%s", outline+2, code_file_name); + c = '"'; + } + state = 0; + break; + default: state = 0; break; + } + if (c == '\n') ++outline; + putc(c, out); + last = c; + } + + if (last != '\n') + { + ++outline; + putc('\n', out); + } + +} + +void output_semantic_actions(void) +{ + copy_file (&action_file, action_file_name); +} + +void output_entries(void) +{ + copy_file (&entry_file, entry_file_name); +} + +void free_itemsets(void) +{ + register core *cp, *next; + + FREE(state_table); + for (cp = first_state; cp; cp = next) + { + next = cp->next; + FREE(cp); + } +} + + +void free_shifts(void) +{ + register shifts *sp, *next; + + FREE(shift_table); + for (sp = first_shift; sp; sp = next) + { + next = sp->next; + FREE(sp); + } +} + + + +void free_reductions(void) +{ + register reductions *rp, *next; + + FREE(reduction_table); + for (rp = first_reduction; rp; rp = next) + { + next = rp->next; + FREE(rp); + } +} diff --git a/yacc/reader.c b/yacc/reader.c new file mode 100644 index 0000000..34ec1a3 --- /dev/null +++ b/yacc/reader.c @@ -0,0 +1,1908 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: reader.c,v 1.32 2005-10-06 06:34:51 garrigue Exp $ */ + +#include <string.h> +#include "defs.h" + +/* The line size must be a positive integer. One hundred was chosen */ +/* because few lines in Yacc input grammars exceed 100 characters. */ +/* Note that if a line exceeds LINESIZE characters, the line buffer */ +/* will be expanded to accomodate it. */ + +#define LINESIZE 100 + +char *cache; +int cinc, cache_size; + +int ntags, tagmax; +char **tag_table; + +char saw_eof, unionized; +char *cptr, *line; +int linesize; + +bucket *goal; +int prec; +int gensym; +char last_was_action; + +int maxitems; +bucket **pitem; + +int maxrules; +bucket **plhs; + +int name_pool_size; +char *name_pool; + +char line_format[] = "# %d \"%s\"\n"; + + + +void start_rule (register bucket *bp, int s_lineno); + +void cachec(int c) +{ + assert(cinc >= 0); + if (cinc >= cache_size) + { + cache_size += 256; + cache = REALLOC(cache, cache_size); + if (cache == 0) no_space(); + } + cache[cinc] = c; + ++cinc; +} + + +void get_line(void) +{ + register FILE *f = input_file; + register int c; + register int i; + + if (saw_eof || (c = getc(f)) == EOF) + { + if (line) { FREE(line); line = 0; } + cptr = 0; + saw_eof = 1; + return; + } + + if (line == 0 || linesize != (LINESIZE + 1)) + { + if (line) FREE(line); + linesize = LINESIZE + 1; + line = MALLOC(linesize); + if (line == 0) no_space(); + } + + i = 0; + ++lineno; + for (;;) + { + line[i] = c; + if (++i >= linesize) + { + linesize += LINESIZE; + line = REALLOC(line, linesize); + if (line == 0) no_space(); + } + if (c == '\n') { line[i] = '\0'; cptr = line; return; } + c = getc(f); + if (c == EOF) { saw_eof = 1; c = '\n'; } + } +} + + +char * +dup_line(void) +{ + register char *p, *s, *t; + + if (line == 0) return (0); + s = line; + while (*s != '\n') ++s; + p = MALLOC(s - line + 1); + if (p == 0) no_space(); + + s = line; + t = p; + while ((*t++ = *s++) != '\n') continue; + return (p); +} + + +void skip_comment(void) +{ + register char *s; + + int st_lineno = lineno; + char *st_line = dup_line(); + char *st_cptr = st_line + (cptr - line); + + s = cptr + 2; + for (;;) + { + if (*s == '*' && s[1] == '/') + { + cptr = s + 2; + FREE(st_line); + return; + } + if (*s == '\n') + { + get_line(); + if (line == 0) + unterminated_comment(st_lineno, st_line, st_cptr); + s = cptr; + } + else + ++s; + } +} + +char *substring (char *str, int start, int len) +{ + int i; + char *buf = MALLOC (len+1); + if (buf == NULL) return NULL; + for (i = 0; i < len; i++){ + buf[i] = str[start+i]; + } + return buf; +} + +void parse_line_directive (void) +{ + int i = 0, j = 0; + int line_number = 0; + char *file_name = NULL; + + again: + if (line == 0) return; + if (line[i] != '#') return; + ++ i; + while (line[i] == ' ' || line[i] == '\t') ++ i; + if (line[i] < '0' || line[i] > '9') return; + while (line[i] >= '0' && line[i] <= '9'){ + line_number = line_number * 10 + line[i] - '0'; + ++ i; + } + while (line[i] == ' ' || line[i] == '\t') ++ i; + if (line[i] == '"'){ + ++ i; + j = i; + while (line[j] != '"' && line[j] != '\0') ++j; + if (line[j] == '"'){ + file_name = substring (line, i, j - i); + if (file_name == NULL) no_space (); + } + } + lineno = line_number - 1; + if (file_name != NULL){ + if (virtual_input_file_name != NULL) FREE (virtual_input_file_name); + virtual_input_file_name = file_name; + } + get_line (); + goto again; +} + +int +nextc(void) +{ + register char *s; + + if (line == 0) + { + get_line(); + parse_line_directive (); + if (line == 0) + return (EOF); + } + + s = cptr; + for (;;) + { + switch (*s) + { + case '\n': + get_line(); + parse_line_directive (); + if (line == 0) return (EOF); + s = cptr; + break; + + case ' ': + case '\t': + case '\f': + case '\r': + case '\v': + case ',': + case ';': + ++s; + break; + + case '\\': + cptr = s; + return ('%'); + + case '/': + if (s[1] == '*') + { + cptr = s; + skip_comment(); + s = cptr; + break; + } + else if (s[1] == '/') + { + get_line(); + parse_line_directive (); + if (line == 0) return (EOF); + s = cptr; + break; + } + /* fall through */ + + default: + cptr = s; + return (*s); + } + } +} + + +int +keyword(void) +{ + register int c; + char *t_cptr = cptr; + + c = *++cptr; + if (isalpha(c)) + { + cinc = 0; + for (;;) + { + if (isalpha(c)) + { + if (isupper(c)) c = tolower(c); + cachec(c); + } + else if (isdigit(c) || c == '_' || c == '.' || c == '$') + cachec(c); + else + break; + c = *++cptr; + } + cachec(NUL); + + if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0) + return (TOKEN); + if (strcmp(cache, "type") == 0) + return (TYPE); + if (strcmp(cache, "left") == 0) + return (LEFT); + if (strcmp(cache, "right") == 0) + return (RIGHT); + if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0) + return (NONASSOC); + if (strcmp(cache, "start") == 0) + return (START); + if (strcmp(cache, "union") == 0) + return (UNION); + if (strcmp(cache, "ident") == 0) + return (IDENT); + } + else + { + ++cptr; + if (c == '{') + return (TEXT); + if (c == '%' || c == '\\') + return (MARK); + if (c == '<') + return (LEFT); + if (c == '>') + return (RIGHT); + if (c == '0') + return (TOKEN); + if (c == '2') + return (NONASSOC); + } + syntax_error(lineno, line, t_cptr); + /*NOTREACHED*/ + return 0; +} + + +void copy_ident(void) +{ + register int c; + register FILE *f = output_file; + + c = nextc(); + if (c == EOF) unexpected_EOF(); + if (c != '"') syntax_error(lineno, line, cptr); + ++outline; + fprintf(f, "#ident \""); + for (;;) + { + c = *++cptr; + if (c == '\n') + { + fprintf(f, "\"\n"); + return; + } + putc(c, f); + if (c == '"') + { + putc('\n', f); + ++cptr; + return; + } + } +} + + +void copy_text(void) +{ + register int c; + int quote; + register FILE *f = text_file; + int need_newline = 0; + int t_lineno = lineno; + char *t_line = dup_line(); + char *t_cptr = t_line + (cptr - line - 2); + + if (*cptr == '\n') + { + get_line(); + if (line == 0) + unterminated_text(t_lineno, t_line, t_cptr); + } + fprintf(f, line_format, lineno, input_file_name); + +loop: + c = *cptr++; + switch (c) + { + case '\n': + putc('\n', f); + need_newline = 0; + get_line(); + if (line) goto loop; + unterminated_text(t_lineno, t_line, t_cptr); + + case '"': + { + int s_lineno = lineno; + char *s_line = dup_line(); + char *s_cptr = s_line + (cptr - line - 1); + + quote = c; + putc(c, f); + for (;;) + { + c = *cptr++; + putc(c, f); + if (c == quote) + { + need_newline = 1; + FREE(s_line); + goto loop; + } + if (c == '\n') + unterminated_string(s_lineno, s_line, s_cptr); + if (c == '\\') + { + c = *cptr++; + putc(c, f); + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_string(s_lineno, s_line, s_cptr); + } + } + } + } + + case '\'': + putc(c, f); + if (cptr[0] != 0 && cptr[0] != '\\' && cptr[1] == '\'') { + fwrite(cptr, 1, 2, f); + cptr += 2; + } else + if (cptr[0] == '\\' + && isdigit((unsigned char) cptr[1]) + && isdigit((unsigned char) cptr[2]) + && isdigit((unsigned char) cptr[3]) + && cptr[4] == '\'') { + fwrite(cptr, 1, 5, f); + cptr += 5; + } else + if (cptr[0] == '\\' && cptr[2] == '\'') { + fwrite(cptr, 1, 3, f); + cptr += 3; + } + goto loop; + + case '(': + putc(c, f); + need_newline = 1; + c = *cptr; + if (c == '*') + { + int c_lineno = lineno; + char *c_line = dup_line(); + char *c_cptr = c_line + (cptr - line - 1); + + putc('*', f); + ++cptr; + for (;;) + { + c = *cptr++; + putc(c, f); + if (c == '*' && *cptr == ')') + { + putc(')', f); + ++cptr; + FREE(c_line); + goto loop; + } + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_comment(c_lineno, c_line, c_cptr); + } + } + } + need_newline = 1; + goto loop; + + case '%': + case '\\': + if (*cptr == '}') + { + if (need_newline) putc('\n', f); + ++cptr; + FREE(t_line); + return; + } + /* fall through */ + + default: + putc(c, f); + need_newline = 1; + goto loop; + } +} + + +void copy_union(void) +{ + register int c; + int quote; + int depth; + int u_lineno = lineno; + char *u_line = dup_line(); + char *u_cptr = u_line + (cptr - line - 6); + + if (unionized) over_unionized(cptr - 6); + unionized = 1; + + if (!lflag) + fprintf(text_file, line_format, lineno, input_file_name); + + fprintf(text_file, "typedef union"); + if (dflag) fprintf(union_file, "typedef union"); + + depth = 1; + cptr++; + +loop: + c = *cptr++; + putc(c, text_file); + if (dflag) putc(c, union_file); + switch (c) + { + case '\n': + get_line(); + if (line == 0) unterminated_union(u_lineno, u_line, u_cptr); + goto loop; + + case '{': + ++depth; + goto loop; + + case '}': + --depth; + if (c == '}' && depth == 0) { + fprintf(text_file, " YYSTYPE;\n"); + FREE(u_line); + return; + } + goto loop; + + case '\'': + case '"': + { + int s_lineno = lineno; + char *s_line = dup_line(); + char *s_cptr = s_line + (cptr - line - 1); + + quote = c; + for (;;) + { + c = *cptr++; + putc(c, text_file); + if (dflag) putc(c, union_file); + if (c == quote) + { + FREE(s_line); + goto loop; + } + if (c == '\n') + unterminated_string(s_lineno, s_line, s_cptr); + if (c == '\\') + { + c = *cptr++; + putc(c, text_file); + if (dflag) putc(c, union_file); + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_string(s_lineno, s_line, s_cptr); + } + } + } + } + + case '(': + c = *cptr; + if (c == '*') + { + int c_lineno = lineno; + char *c_line = dup_line(); + char *c_cptr = c_line + (cptr - line - 1); + + putc('*', text_file); + if (dflag) putc('*', union_file); + ++cptr; + for (;;) + { + c = *cptr++; + putc(c, text_file); + if (dflag) putc(c, union_file); + if (c == '*' && *cptr == ')') + { + putc(')', text_file); + if (dflag) putc(')', union_file); + ++cptr; + FREE(c_line); + goto loop; + } + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_comment(c_lineno, c_line, c_cptr); + } + } + } + goto loop; + + default: + goto loop; + } +} + + +int +hexval(int c) +{ + if (c >= '0' && c <= '9') + return (c - '0'); + if (c >= 'A' && c <= 'F') + return (c - 'A' + 10); + if (c >= 'a' && c <= 'f') + return (c - 'a' + 10); + return (-1); +} + + +bucket * +get_literal(void) +{ + register int c, quote; + register int i; + register int n; + register char *s; + register bucket *bp; + int s_lineno = lineno; + char *s_line = dup_line(); + char *s_cptr = s_line + (cptr - line); + + quote = *cptr++; + cinc = 0; + for (;;) + { + c = *cptr++; + if (c == quote) break; + if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr); + if (c == '\\') + { + char *c_cptr = cptr - 1; + + c = *cptr++; + switch (c) + { + case '\n': + get_line(); + if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); + continue; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + n = c - '0'; + c = *cptr; + if (IS_OCTAL(c)) + { + n = (n << 3) + (c - '0'); + c = *++cptr; + if (IS_OCTAL(c)) + { + n = (n << 3) + (c - '0'); + ++cptr; + } + } + if (n > MAXCHAR) illegal_character(c_cptr); + c = n; + break; + + case 'x': + c = *cptr++; + n = hexval(c); + if (n < 0 || n >= 16) + illegal_character(c_cptr); + for (;;) + { + c = *cptr; + i = hexval(c); + if (i < 0 || i >= 16) break; + ++cptr; + n = (n << 4) + i; + if (n > MAXCHAR) illegal_character(c_cptr); + } + c = n; + break; + + case 'a': c = 7; break; + case 'b': c = '\b'; break; + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + } + } + cachec(c); + } + FREE(s_line); + + n = cinc; + s = MALLOC(n); + if (s == 0) no_space(); + + for (i = 0; i < n; ++i) + s[i] = cache[i]; + + cinc = 0; + if (n == 1) + cachec('\''); + else + cachec('"'); + + for (i = 0; i < n; ++i) + { + c = ((unsigned char *)s)[i]; + if (c == '\\' || c == cache[0]) + { + cachec('\\'); + cachec(c); + } + else if (isprint(c)) + cachec(c); + else + { + cachec('\\'); + switch (c) + { + case 7: cachec('a'); break; + case '\b': cachec('b'); break; + case '\f': cachec('f'); break; + case '\n': cachec('n'); break; + case '\r': cachec('r'); break; + case '\t': cachec('t'); break; + case '\v': cachec('v'); break; + default: + cachec(((c >> 6) & 7) + '0'); + cachec(((c >> 3) & 7) + '0'); + cachec((c & 7) + '0'); + break; + } + } + } + + if (n == 1) + cachec('\''); + else + cachec('"'); + + cachec(NUL); + bp = lookup(cache); + bp->class = TERM; + if (n == 1 && bp->value == UNDEFINED) + bp->value = *(unsigned char *)s; + FREE(s); + + return (bp); +} + + +int +is_reserved(char *name) +{ + char *s; + + if (strcmp(name, ".") == 0 || + strcmp(name, "$accept") == 0 || + strcmp(name, "$end") == 0) + return (1); + + if (name[0] == '$' && name[1] == '$' && isdigit((unsigned char) name[2])) + { + s = name + 3; + while (isdigit((unsigned char) *s)) ++s; + if (*s == NUL) return (1); + } + + return (0); +} + + +bucket * +get_name(void) +{ + register int c; + + cinc = 0; + for (c = *cptr; IS_IDENT(c); c = *++cptr) + cachec(c); + cachec(NUL); + + if (is_reserved(cache)) used_reserved(cache); + + return (lookup(cache)); +} + + +int +get_number(void) +{ + register int c; + register int n; + + n = 0; + for (c = *cptr; isdigit(c); c = *++cptr) + n = 10*n + (c - '0'); + + return (n); +} + + +char * +get_tag(void) +{ + register int c; + register int i; + register char *s; + char *t_line = dup_line(); + long bracket_depth; + + cinc = 0; + bracket_depth = 0; + while (1) { + c = *++cptr; + if (c == EOF) unexpected_EOF(); + if (c == '\n') syntax_error(lineno, line, cptr); + if (c == '>' && 0 == bracket_depth && cptr[-1] != '-') break; + if (c == '[') ++ bracket_depth; + if (c == ']') -- bracket_depth; + cachec(c); + } + ++cptr; + cachec(NUL); + + for (i = 0; i < ntags; ++i) + { + if (strcmp(cache, tag_table[i]) == 0) + return (tag_table[i]); + } + + if (ntags >= tagmax) + { + tagmax += 16; + tag_table = (char **) + (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) + : MALLOC(tagmax*sizeof(char *))); + if (tag_table == 0) no_space(); + } + + s = MALLOC(cinc); + if (s == 0) no_space(); + strcpy(s, cache); + tag_table[ntags] = s; + ++ntags; + FREE(t_line); + return (s); +} + + +void declare_tokens(int assoc) +{ + register int c; + register bucket *bp; + int value; + char *tag = 0; + + if (assoc != TOKEN) ++prec; + + c = nextc(); + if (c == EOF) unexpected_EOF(); + if (c == '<') + { + tag = get_tag(); + c = nextc(); + if (c == EOF) unexpected_EOF(); + } + + for (;;) + { + if (isalpha(c) || c == '_' || c == '.' || c == '$') + bp = get_name(); + else if (c == '\'' || c == '"') + bp = get_literal(); + else + return; + + if (bp == goal) tokenized_start(bp->name); + bp->class = TERM; + + if (tag) + { + if (bp->tag && tag != bp->tag) + retyped_warning(bp->name); + bp->tag = tag; + } + + if (assoc == TOKEN) + { + bp->true_token = 1; + } + else + { + if (bp->prec && prec != bp->prec) + reprec_warning(bp->name); + bp->assoc = assoc; + bp->prec = prec; + } + + if (strcmp(bp->name, "EOF") == 0) + bp->value = 0; + + c = nextc(); + if (c == EOF) unexpected_EOF(); + value = UNDEFINED; + if (isdigit(c)) + { + value = get_number(); + if (bp->value != UNDEFINED && value != bp->value) + revalued_warning(bp->name); + bp->value = value; + c = nextc(); + if (c == EOF) unexpected_EOF(); + } + } +} + + +void declare_types(void) +{ + register int c; + register bucket *bp; + char *tag; + + c = nextc(); + if (c == EOF) unexpected_EOF(); + if (c != '<') syntax_error(lineno, line, cptr); + tag = get_tag(); + + for (;;) + { + c = nextc(); + if (isalpha(c) || c == '_' || c == '.' || c == '$') + bp = get_name(); + else if (c == '\'' || c == '"') + bp = get_literal(); + else + return; + + if (bp->tag && tag != bp->tag) + retyped_warning(bp->name); + bp->tag = tag; + } +} + + +void declare_start(void) +{ + register int c; + register bucket *bp; + static int entry_counter = 0; + + for (;;) { + c = nextc(); + if (!isalpha(c) && c != '_' && c != '.' && c != '$') return; + bp = get_name(); + + if (bp->class == TERM) + terminal_start(bp->name); + bp->entry = ++entry_counter; + if (entry_counter == 256) + too_many_entries(); + } +} + + +void read_declarations(void) +{ + register int c, k; + + cache_size = 256; + cache = MALLOC(cache_size); + if (cache == 0) no_space(); + + for (;;) + { + c = nextc(); + if (c == EOF) unexpected_EOF(); + if (c != '%') syntax_error(lineno, line, cptr); + switch (k = keyword()) + { + case MARK: + return; + + case IDENT: + copy_ident(); + break; + + case TEXT: + copy_text(); + break; + + case UNION: + copy_union(); + break; + + case TOKEN: + case LEFT: + case RIGHT: + case NONASSOC: + declare_tokens(k); + break; + + case TYPE: + declare_types(); + break; + + case START: + declare_start(); + break; + } + } +} + +void output_token_type(void) +{ + bucket * bp; + int n; + + fprintf(interface_file, "type token =\n"); + if (!rflag) ++outline; + fprintf(output_file, "type token =\n"); + n = 0; + for (bp = first_symbol; bp; bp = bp->next) { + if (bp->class == TERM && bp->true_token) { + fprintf(interface_file, " | %s", bp->name); + fprintf(output_file, " | %s", bp->name); + if (bp->tag) { + /* Print the type expression in parentheses to make sure + that the constructor is unary */ + fprintf(interface_file, " of (%s)", bp->tag); + fprintf(output_file, " of (%s)", bp->tag); + } + fprintf(interface_file, "\n"); + if (!rflag) ++outline; + fprintf(output_file, "\n"); + n++; + } + } + fprintf(interface_file, "\n"); + if (!rflag) ++outline; + fprintf(output_file, "\n"); +} + +void initialize_grammar(void) +{ + nitems = 4; + maxitems = 300; + pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *)); + if (pitem == 0) no_space(); + pitem[0] = 0; + pitem[1] = 0; + pitem[2] = 0; + pitem[3] = 0; + + nrules = 3; + maxrules = 100; + plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *)); + if (plhs == 0) no_space(); + plhs[0] = 0; + plhs[1] = 0; + plhs[2] = 0; + rprec = (short *) MALLOC(maxrules*sizeof(short)); + if (rprec == 0) no_space(); + rprec[0] = 0; + rprec[1] = 0; + rprec[2] = 0; + rassoc = (char *) MALLOC(maxrules*sizeof(char)); + if (rassoc == 0) no_space(); + rassoc[0] = TOKEN; + rassoc[1] = TOKEN; + rassoc[2] = TOKEN; +} + + +void expand_items(void) +{ + maxitems += 300; + pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *)); + if (pitem == 0) no_space(); +} + + +void expand_rules(void) +{ + maxrules += 100; + plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *)); + if (plhs == 0) no_space(); + rprec = (short *) REALLOC(rprec, maxrules*sizeof(short)); + if (rprec == 0) no_space(); + rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char)); + if (rassoc == 0) no_space(); +} + + +void advance_to_start(void) +{ + register int c; + register bucket *bp; + char *s_cptr; + int s_lineno; + + for (;;) + { + c = nextc(); + if (c != '%') break; + s_cptr = cptr; + switch (keyword()) + { + case MARK: + no_grammar(); + + case TEXT: + copy_text(); + break; + + case START: + declare_start(); + break; + + default: + syntax_error(lineno, line, s_cptr); + } + } + + c = nextc(); + if (!isalpha(c) && c != '_' && c != '.' && c != '_') + syntax_error(lineno, line, cptr); + bp = get_name(); + if (goal == 0) + { + if (bp->class == TERM) + terminal_start(bp->name); + goal = bp; + } + + s_lineno = lineno; + c = nextc(); + if (c == EOF) unexpected_EOF(); + if (c != ':') syntax_error(lineno, line, cptr); + start_rule(bp, s_lineno); + ++cptr; +} + + +int at_first; + +void start_rule(register bucket *bp, int s_lineno) +{ + if (bp->class == TERM) + terminal_lhs(s_lineno); + bp->class = NONTERM; + if (nrules >= maxrules) + expand_rules(); + plhs[nrules] = bp; + rprec[nrules] = UNDEFINED; + rassoc[nrules] = TOKEN; + at_first = 1; +} + + +void end_rule(void) +{ + if (!last_was_action) default_action_error(); + + last_was_action = 0; + if (nitems >= maxitems) expand_items(); + pitem[nitems] = 0; + ++nitems; + ++nrules; +} + + +void insert_empty_rule(void) +{ + register bucket *bp, **bpp; + + assert(cache); + sprintf(cache, "$$%d", ++gensym); + bp = make_bucket(cache); + last_symbol->next = bp; + last_symbol = bp; + bp->tag = plhs[nrules]->tag; + bp->class = NONTERM; + + if ((nitems += 2) > maxitems) + expand_items(); + bpp = pitem + nitems - 1; + *bpp-- = bp; + while ((bpp[0] = bpp[-1])) --bpp; + + if (++nrules >= maxrules) + expand_rules(); + plhs[nrules] = plhs[nrules-1]; + plhs[nrules-1] = bp; + rprec[nrules] = rprec[nrules-1]; + rprec[nrules-1] = 0; + rassoc[nrules] = rassoc[nrules-1]; + rassoc[nrules-1] = TOKEN; +} + + +void add_symbol(void) +{ + register int c; + register bucket *bp; + int s_lineno = lineno; + char *ecptr = cptr; + + c = *cptr; + if (c == '\'' || c == '"') + bp = get_literal(); + else + bp = get_name(); + + c = nextc(); + if (c == ':') + { + end_rule(); + start_rule(bp, s_lineno); + ++cptr; + return; + } + + if (last_was_action) syntax_error (lineno, line, ecptr); + last_was_action = 0; + + if (++nitems > maxitems) + expand_items(); + pitem[nitems-1] = bp; +} + + +void copy_action(void) +{ + register int c; + register int i, n; + int depth; + int quote; + bucket *item; + char *tagres; + register FILE *f = action_file; + int a_lineno = lineno; + char *a_line = dup_line(); + char *a_cptr = a_line + (cptr - line); + + if (last_was_action) syntax_error (lineno, line, cptr); + last_was_action = 1; + + /* + fprintf(f, "(* Rule %d, file %s, line %d *)\n", + nrules-2, input_file_name, lineno); + */ + if (sflag) + fprintf(f, "yyact.(%d) <- (fun __caml_parser_env ->\n", nrules-2); + else + fprintf(f, "; (fun __caml_parser_env ->\n"); + + n = 0; + for (i = nitems - 1; pitem[i]; --i) ++n; + + for (i = 1; i <= n; i++) { + item = pitem[nitems + i - n - 1]; + if (item->class == TERM && !item->tag) continue; + fprintf(f, " let _%d = ", i); + if (item->tag) + fprintf(f, "(Parsing.peek_val __caml_parser_env %d : %s) in\n", n - i, + item->tag); + else if (sflag) + fprintf(f, "Parsing.peek_val __caml_parser_env %d in\n", n - i); + else + fprintf(f, "(Parsing.peek_val __caml_parser_env %d : '%s) in\n", n - i, + item->name); + } + fprintf(f, " Obj.repr(\n"); + fprintf(f, line_format, lineno, input_file_name); + for (i = 0; i < cptr - line; i++) fputc(' ', f); + fputc ('(', f); + + depth = 1; + cptr++; + +loop: + c = *cptr; + if (c == '$') + { + if (isdigit((unsigned char) cptr[1])) + { + ++cptr; + i = get_number(); + + if (i <= 0 || i > n) + unknown_rhs(i); + item = pitem[nitems + i - n - 1]; + if (item->class == TERM && !item->tag) + illegal_token_ref(i, item->name); + fprintf(f, "_%d", i); + goto loop; + } + } + if (isalpha(c) || c == '_' || c == '$') + { + do + { + putc(c, f); + c = *++cptr; + } while (isalnum(c) || c == '_' || c == '$'); + goto loop; + } + if (c == '}' && depth == 1) { + fprintf(f, ")\n# 0\n "); + cptr++; + tagres = plhs[nrules]->tag; + if (tagres) + fprintf(f, " : %s))\n", tagres); + else if (sflag) + fprintf(f, "))\n"); + else + fprintf(f, " : '%s))\n", plhs[nrules]->name); + if (sflag) + fprintf(f, "\n"); + return; + } + putc(c, f); + ++cptr; + switch (c) + { + case '\n': + get_line(); + if (line) goto loop; + unterminated_action(a_lineno, a_line, a_cptr); + + case '{': + ++depth; + goto loop; + + case '}': + --depth; + goto loop; + + case '"': + { + int s_lineno = lineno; + char *s_line = dup_line(); + char *s_cptr = s_line + (cptr - line - 1); + + quote = c; + for (;;) + { + c = *cptr++; + putc(c, f); + if (c == quote) + { + FREE(s_line); + goto loop; + } + if (c == '\n') + unterminated_string(s_lineno, s_line, s_cptr); + if (c == '\\') + { + c = *cptr++; + putc(c, f); + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_string(s_lineno, s_line, s_cptr); + } + } + } + } + + case '\'': + if (cptr[0] != 0 && cptr[0] != '\\' && cptr[1] == '\'') { + fwrite(cptr, 1, 2, f); + cptr += 2; + } else + if (cptr[0] == '\\' + && isdigit((unsigned char) cptr[1]) + && isdigit((unsigned char) cptr[2]) + && isdigit((unsigned char) cptr[3]) + && cptr[4] == '\'') { + fwrite(cptr, 1, 5, f); + cptr += 5; + } else + if (cptr[0] == '\\' && cptr[2] == '\'') { + fwrite(cptr, 1, 3, f); + cptr += 3; + } + goto loop; + + case '(': + c = *cptr; + if (c == '*') + { + int c_lineno = lineno; + char *c_line = dup_line(); + char *c_cptr = c_line + (cptr - line - 1); + + putc('*', f); + ++cptr; + for (;;) + { + c = *cptr++; + putc(c, f); + if (c == '*' && *cptr == ')') + { + putc(')', f); + ++cptr; + FREE(c_line); + goto loop; + } + if (c == '\n') + { + get_line(); + if (line == 0) + unterminated_comment(c_lineno, c_line, c_cptr); + } + } + } + goto loop; + + default: + goto loop; + } +} + + +int +mark_symbol(void) +{ + register int c; + register bucket *bp; + + c = cptr[1]; + if (c == '%' || c == '\\') + { + cptr += 2; + return (1); + } + + if (c == '=') + cptr += 2; + else if ((c == 'p' || c == 'P') && + ((c = cptr[2]) == 'r' || c == 'R') && + ((c = cptr[3]) == 'e' || c == 'E') && + ((c = cptr[4]) == 'c' || c == 'C') && + ((c = cptr[5], !IS_IDENT(c)))) + cptr += 5; + else + syntax_error(lineno, line, cptr); + + c = nextc(); + if (isalpha(c) || c == '_' || c == '.' || c == '$') + bp = get_name(); + else if (c == '\'' || c == '"') + bp = get_literal(); + else + { + syntax_error(lineno, line, cptr); + /*NOTREACHED*/ + } + + if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules]) + prec_redeclared(); + + rprec[nrules] = bp->prec; + rassoc[nrules] = bp->assoc; + return (0); +} + + +void read_grammar(void) +{ + register int c; + + initialize_grammar(); + advance_to_start(); + + for (;;) + { + c = nextc(); + if (c == '|' && at_first){ + ++cptr; + c = nextc(); + } + at_first = 0; + if (c == EOF) break; + if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' || + c == '"') + add_symbol(); + else if (c == '{' || c == '=') + copy_action(); + else if (c == '|') + { + end_rule(); + start_rule(plhs[nrules-1], 0); + ++cptr; + } + else if (c == '%') + { + if (mark_symbol()) break; + } + else + syntax_error(lineno, line, cptr); + } + end_rule(); +} + + +void free_tags(void) +{ + register int i; + + if (tag_table == 0) return; + + for (i = 0; i < ntags; ++i) + { + assert(tag_table[i]); + FREE(tag_table[i]); + } + FREE(tag_table); +} + + +void pack_names(void) +{ + register bucket *bp; + register char *p, *s, *t; + + name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */ + for (bp = first_symbol; bp; bp = bp->next) + name_pool_size += strlen(bp->name) + 1; + name_pool = MALLOC(name_pool_size); + if (name_pool == 0) no_space(); + + strcpy(name_pool, "$accept"); + strcpy(name_pool+8, "$end"); + t = name_pool + 13; + for (bp = first_symbol; bp; bp = bp->next) + { + p = t; + s = bp->name; + while ((*t++ = *s++)) continue; + FREE(bp->name); + bp->name = p; + } +} + + +void check_symbols(void) +{ + register bucket *bp; + + if (goal->class == UNKNOWN) + undefined_goal(goal->name); + + for (bp = first_symbol; bp; bp = bp->next) + { + if (bp->class == UNKNOWN) + { + undefined_symbol(bp->name); + bp->class = TERM; + } + } +} + + +void pack_symbols(void) +{ + register bucket *bp; + register bucket **v; + register int i, j, k, n; + + nsyms = 2; + ntokens = 1; + for (bp = first_symbol; bp; bp = bp->next) + { + ++nsyms; + if (bp->class == TERM) ++ntokens; + } + start_symbol = ntokens; + nvars = nsyms - ntokens; + + symbol_name = (char **) MALLOC(nsyms*sizeof(char *)); + if (symbol_name == 0) no_space(); + symbol_value = (short *) MALLOC(nsyms*sizeof(short)); + if (symbol_value == 0) no_space(); + symbol_prec = (short *) MALLOC(nsyms*sizeof(short)); + if (symbol_prec == 0) no_space(); + symbol_assoc = MALLOC(nsyms); + if (symbol_assoc == 0) no_space(); + symbol_tag = (char **) MALLOC(nsyms*sizeof(char *)); + if (symbol_tag == 0) no_space(); + symbol_true_token = (char *) MALLOC(nsyms*sizeof(char)); + if (symbol_true_token == 0) no_space(); + + v = (bucket **) MALLOC(nsyms*sizeof(bucket *)); + if (v == 0) no_space(); + + v[0] = 0; + v[start_symbol] = 0; + + i = 1; + j = start_symbol + 1; + for (bp = first_symbol; bp; bp = bp->next) + { + if (bp->class == TERM) + v[i++] = bp; + else + v[j++] = bp; + } + assert(i == ntokens && j == nsyms); + + for (i = 1; i < ntokens; ++i) + v[i]->index = i; + + goal->index = start_symbol + 1; + k = start_symbol + 2; + while (++i < nsyms) + if (v[i] != goal) + { + v[i]->index = k; + ++k; + } + + goal->value = 0; + k = 1; + for (i = start_symbol + 1; i < nsyms; ++i) + { + if (v[i] != goal) + { + v[i]->value = k; + ++k; + } + } + + k = 0; + for (i = 1; i < ntokens; ++i) + { + n = v[i]->value; + if (n > 256) + { + for (j = k++; j > 0 && symbol_value[j-1] > n; --j) + symbol_value[j] = symbol_value[j-1]; + symbol_value[j] = n; + } + } + + if (v[1]->value == UNDEFINED) + v[1]->value = 256; + + j = 0; + n = 257; + for (i = 2; i < ntokens; ++i) + { + if (v[i]->value == UNDEFINED) + { + while (j < k && n == symbol_value[j]) + { + while (++j < k && n == symbol_value[j]) continue; + ++n; + } + v[i]->value = n; + ++n; + } + } + + symbol_name[0] = name_pool + 8; + symbol_value[0] = 0; + symbol_prec[0] = 0; + symbol_assoc[0] = TOKEN; + symbol_tag[0] = ""; + symbol_true_token[0] = 0; + for (i = 1; i < ntokens; ++i) + { + symbol_name[i] = v[i]->name; + symbol_value[i] = v[i]->value; + symbol_prec[i] = v[i]->prec; + symbol_assoc[i] = v[i]->assoc; + symbol_tag[i] = v[i]->tag; + symbol_true_token[i] = v[i]->true_token; + } + symbol_name[start_symbol] = name_pool; + symbol_value[start_symbol] = -1; + symbol_prec[start_symbol] = 0; + symbol_assoc[start_symbol] = TOKEN; + symbol_tag[start_symbol] = ""; + symbol_true_token[start_symbol] = 0; + for (++i; i < nsyms; ++i) + { + k = v[i]->index; + symbol_name[k] = v[i]->name; + symbol_value[k] = v[i]->value; + symbol_prec[k] = v[i]->prec; + symbol_assoc[k] = v[i]->assoc; + symbol_tag[i] = v[i]->tag; + symbol_true_token[i] = v[i]->true_token; + } + + FREE(v); +} + +static unsigned char caml_ident_start[32] = +"\000\000\000\000\000\000\000\000\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\377\377\177\377\377\377\177\377"; +static unsigned char caml_ident_body[32] = +"\000\000\000\000\200\000\377\003\376\377\377\207\376\377\377\007\000\000\000\000\000\000\000\000\377\377\177\377\377\377\177\377"; + +#define In_bitmap(bm,c) (bm[(unsigned char)(c) >> 3] & (1 << ((c) & 7))) + +static int is_polymorphic(char * s) +{ + while (*s != 0) { + char c = *s++; + if (c == '\'' || c == '#') return 1; + if (c == '[') { + c = *s; + while (c == ' ' || c == '\t' || c == '\r' || c == '\n') c = *++s; + if (c == '<' || c == '>') return 1; + } + if (In_bitmap(caml_ident_start, c)) { + while (In_bitmap(caml_ident_body, *s)) s++; + } + } + return 0; +} + +void make_goal(void) +{ + static char name[7] = "'\\xxx'"; + bucket * bp; + bucket * bc; + + goal = lookup("%entry%"); + ntotalrules = nrules - 2; + for(bp = first_symbol; bp != 0; bp = bp->next) { + if (bp->entry) { + start_rule(goal, 0); + if (nitems + 2> maxitems) + expand_items(); + name[2] = '0' + ((bp->entry >> 6) & 7); + name[3] = '0' + ((bp->entry >> 3) & 7); + name[4] = '0' + (bp->entry & 7); + bc = lookup(name); + bc->class = TERM; + bc->value = (unsigned char) bp->entry; + pitem[nitems++] = bc; + pitem[nitems++] = bp; + if (bp->tag == NULL) + entry_without_type(bp->name); + if (is_polymorphic(bp->tag)) + polymorphic_entry_point(bp->name); + fprintf(entry_file, + "let %s (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =\n (Parsing.yyparse yytables %d lexfun lexbuf : %s)\n", + bp->name, bp->entry, bp->tag); + fprintf(interface_file, + "val %s :\n (Lexing.lexbuf -> token) -> Lexing.lexbuf -> %s\n", + bp->name, + bp->tag); + fprintf(action_file, + "(* Entry %s *)\n", bp->name); + if (sflag) + fprintf(action_file, + "yyact.(%d) <- (fun __caml_parser_env -> raise " + "(Parsing.YYexit (Parsing.peek_val __caml_parser_env 0)))\n", + ntotalrules); + else + fprintf(action_file, + "; (fun __caml_parser_env -> raise " + "(Parsing.YYexit (Parsing.peek_val __caml_parser_env 0)))\n"); + ntotalrules++; + last_was_action = 1; + end_rule(); + } + } +} + +void pack_grammar(void) +{ + register int i, j; + int assoc, prec; + + ritem = (short *) MALLOC(nitems*sizeof(short)); + if (ritem == 0) no_space(); + rlhs = (short *) MALLOC(nrules*sizeof(short)); + if (rlhs == 0) no_space(); + rrhs = (short *) MALLOC((nrules+1)*sizeof(short)); + if (rrhs == 0) no_space(); + rprec = (short *) REALLOC(rprec, nrules*sizeof(short)); + if (rprec == 0) no_space(); + rassoc = REALLOC(rassoc, nrules); + if (rassoc == 0) no_space(); + + ritem[0] = -1; + ritem[1] = goal->index; + ritem[2] = 0; + ritem[3] = -2; + rlhs[0] = 0; + rlhs[1] = 0; + rlhs[2] = start_symbol; + rrhs[0] = 0; + rrhs[1] = 0; + rrhs[2] = 1; + + j = 4; + for (i = 3; i < nrules; ++i) + { + rlhs[i] = plhs[i]->index; + rrhs[i] = j; + assoc = TOKEN; + prec = 0; + while (pitem[j]) + { + ritem[j] = pitem[j]->index; + if (pitem[j]->class == TERM) + { + prec = pitem[j]->prec; + assoc = pitem[j]->assoc; + } + ++j; + } + ritem[j] = -i; + ++j; + if (rprec[i] == UNDEFINED) + { + rprec[i] = prec; + rassoc[i] = assoc; + } + } + rrhs[i] = j; + + FREE(plhs); + FREE(pitem); +} + + +void print_grammar(void) +{ + register int i, j, k; + int spacing = 0; + register FILE *f = verbose_file; + + if (!vflag) return; + + k = 1; + for (i = 2; i < nrules; ++i) + { + if (rlhs[i] != rlhs[i-1]) + { + if (i != 2) fprintf(f, "\n"); + fprintf(f, "%4d %s :", i - 2, symbol_name[rlhs[i]]); + spacing = strlen(symbol_name[rlhs[i]]) + 1; + } + else + { + fprintf(f, "%4d ", i - 2); + j = spacing; + while (--j >= 0) putc(' ', f); + putc('|', f); + } + + while (ritem[k] >= 0) + { + fprintf(f, " %s", symbol_name[ritem[k]]); + ++k; + } + ++k; + putc('\n', f); + } +} + + +void reader(void) +{ + virtual_input_file_name = substring (input_file_name, 0, + strlen (input_file_name)); + create_symbol_table(); + read_declarations(); + output_token_type(); + read_grammar(); + make_goal(); + free_symbol_table(); + free_tags(); + pack_names(); + check_symbols(); + pack_symbols(); + pack_grammar(); + free_symbols(); + print_grammar(); +} diff --git a/yacc/skeleton.c b/yacc/skeleton.c new file mode 100644 index 0000000..b2ae60d --- /dev/null +++ b/yacc/skeleton.c @@ -0,0 +1,58 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: skeleton.c,v 1.13 2005-08-13 20:59:37 doligez Exp $ */ + +#include "defs.h" + +char *header[] = +{ + "open Parsing;;", + 0 +}; + +char *define_tables[] = +{ + "let yytables =", + " { Parsing.actions=yyact;", + " Parsing.transl_const=yytransl_const;", + " Parsing.transl_block=yytransl_block;", + " Parsing.lhs=yylhs;", + " Parsing.len=yylen;", + " Parsing.defred=yydefred;", + " Parsing.dgoto=yydgoto;", + " Parsing.sindex=yysindex;", + " Parsing.rindex=yyrindex;", + " Parsing.gindex=yygindex;", + " Parsing.tablesize=yytablesize;", + " Parsing.table=yytable;", + " Parsing.check=yycheck;", + " Parsing.error_function=parse_error;", + " Parsing.names_const=yynames_const;", + " Parsing.names_block=yynames_block }", + 0 +}; + +void write_section(char **section) +{ + register int i; + register FILE *fp; + + fp = code_file; + for (i = 0; section[i]; ++i) + { + ++outline; + fprintf(fp, "%s\n", section[i]); + } +} diff --git a/yacc/symtab.c b/yacc/symtab.c new file mode 100644 index 0000000..28a5c2f --- /dev/null +++ b/yacc/symtab.c @@ -0,0 +1,129 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: symtab.c,v 1.8 2001-07-12 12:54:23 doligez Exp $ */ + +#include <string.h> +#include "defs.h" + + +bucket **symbol_table; +bucket *first_symbol; +bucket *last_symbol; + + +int +hash(char *name) +{ + register char *s; + register int c, k; + + assert(name && *name); + s = name; + k = *s; + while ((c = *++s)) + k = (31*k + c) & (TABLE_SIZE - 1); + + return (k); +} + + +bucket * +make_bucket(char *name) +{ + register bucket *bp; + + assert(name); + bp = (bucket *) MALLOC(sizeof(bucket)); + if (bp == 0) no_space(); + bp->link = 0; + bp->next = 0; + bp->name = MALLOC(strlen(name) + 1); + if (bp->name == 0) no_space(); + bp->tag = 0; + bp->value = UNDEFINED; + bp->index = 0; + bp->prec = 0; + bp-> class = UNKNOWN; + bp->assoc = TOKEN; + bp->entry = 0; + bp->true_token = 0; + + if (bp->name == 0) no_space(); + strcpy(bp->name, name); + + return (bp); +} + + +bucket * +lookup(char *name) +{ + register bucket *bp, **bpp; + + bpp = symbol_table + hash(name); + bp = *bpp; + + while (bp) + { + if (strcmp(name, bp->name) == 0) return (bp); + bpp = &bp->link; + bp = *bpp; + } + + *bpp = bp = make_bucket(name); + last_symbol->next = bp; + last_symbol = bp; + + return (bp); +} + + +void create_symbol_table(void) +{ + register int i; + register bucket *bp; + + symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *)); + if (symbol_table == 0) no_space(); + for (i = 0; i < TABLE_SIZE; i++) + symbol_table[i] = 0; + + bp = make_bucket("error"); + bp->index = 1; + bp->class = TERM; + + first_symbol = bp; + last_symbol = bp; + symbol_table[hash("error")] = bp; +} + + +void free_symbol_table(void) +{ + FREE(symbol_table); + symbol_table = 0; +} + + +void free_symbols(void) +{ + register bucket *p, *q; + + for (p = first_symbol; p; p = q) + { + q = p->next; + FREE(p); + } +} diff --git a/yacc/verbose.c b/yacc/verbose.c new file mode 100644 index 0000000..cb78083 --- /dev/null +++ b/yacc/verbose.c @@ -0,0 +1,350 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: verbose.c,v 1.9 2001-07-12 12:54:23 doligez Exp $ */ + + +#include "defs.h" + + +static short *null_rules; + + +void print_state (int state); +void log_unused (void); +void log_conflicts (void); +void print_conflicts (int state); +void print_core (int state); +void print_nulls (int state); +void print_actions (int stateno); +void print_shifts (register action *p); +void print_reductions (register action *p, register int defred); +void print_gotos (int stateno); + +void verbose(void) +{ + register int i; + + if (!vflag) return; + + null_rules = (short *) MALLOC(nrules*sizeof(short)); + if (null_rules == 0) no_space(); + fprintf(verbose_file, "\f\n"); + for (i = 0; i < nstates; i++) + print_state(i); + FREE(null_rules); + + if (nunused) + log_unused(); + if (SRtotal || RRtotal) + log_conflicts(); + + fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens, + nvars); + fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates); +} + + +void log_unused(void) +{ + register int i; + register short *p; + + fprintf(verbose_file, "\n\nRules never reduced:\n"); + for (i = 3; i < nrules; ++i) + { + if (!rules_used[i]) + { + fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]); + for (p = ritem + rrhs[i]; *p >= 0; ++p) + fprintf(verbose_file, " %s", symbol_name[*p]); + fprintf(verbose_file, " (%d)\n", i - 2); + } + } +} + + +void log_conflicts(void) +{ + register int i; + + fprintf(verbose_file, "\n\n"); + for (i = 0; i < nstates; i++) + { + if (SRconflicts[i] || RRconflicts[i]) + { + fprintf(verbose_file, "State %d contains ", i); + if (SRconflicts[i] == 1) + fprintf(verbose_file, "1 shift/reduce conflict"); + else if (SRconflicts[i] > 1) + fprintf(verbose_file, "%d shift/reduce conflicts", + SRconflicts[i]); + if (SRconflicts[i] && RRconflicts[i]) + fprintf(verbose_file, ", "); + if (RRconflicts[i] == 1) + fprintf(verbose_file, "1 reduce/reduce conflict"); + else if (RRconflicts[i] > 1) + fprintf(verbose_file, "%d reduce/reduce conflicts", + RRconflicts[i]); + fprintf(verbose_file, ".\n"); + } + } +} + + +void print_state(int state) +{ + if (state) + fprintf(verbose_file, "\n\n"); + if (SRconflicts[state] || RRconflicts[state]) + print_conflicts(state); + fprintf(verbose_file, "state %d\n", state); + print_core(state); + print_nulls(state); + print_actions(state); +} + + +void print_conflicts(int state) +{ + register int symbol, act, number; + register action *p; + + symbol = -1; + act = 0; + number = 0; + for (p = parser[state]; p; p = p->next) + { + if (p->suppressed == 2) + continue; + + if (p->symbol != symbol) + { + symbol = p->symbol; + number = p->number; + if (p->action_code == SHIFT) + act = SHIFT; + else + act = REDUCE; + } + else if (p->suppressed == 1) + { + if (state == final_state && symbol == 0) + { + fprintf(verbose_file, "%d: shift/reduce conflict \ +(accept, reduce %d) on $end\n", state, p->number - 2); + } + else + { + if (act == SHIFT) + { + fprintf(verbose_file, "%d: shift/reduce conflict \ +(shift %d, reduce %d) on %s\n", state, number, p->number - 2, + symbol_name[symbol]); + } + else + { + fprintf(verbose_file, "%d: reduce/reduce conflict \ +(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2, + symbol_name[symbol]); + } + } + } + } +} + + +void print_core(int state) +{ + register int i; + register int k; + register int rule; + register core *statep; + register short *sp; + register short *sp1; + + statep = state_table[state]; + k = statep->nitems; + + for (i = 0; i < k; i++) + { + sp1 = sp = ritem + statep->items[i]; + + while (*sp >= 0) ++sp; + rule = -(*sp); + fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]); + + for (sp = ritem + rrhs[rule]; sp < sp1; sp++) + fprintf(verbose_file, "%s ", symbol_name[*sp]); + + putc('.', verbose_file); + + while (*sp >= 0) + { + fprintf(verbose_file, " %s", symbol_name[*sp]); + sp++; + } + fprintf(verbose_file, " (%d)\n", -2 - *sp); + } +} + + +void print_nulls(int state) +{ + register action *p; + register int i, j, k, nnulls; + + nnulls = 0; + for (p = parser[state]; p; p = p->next) + { + if (p->action_code == REDUCE && + (p->suppressed == 0 || p->suppressed == 1)) + { + i = p->number; + if (rrhs[i] + 1 == rrhs[i+1]) + { + for (j = 0; j < nnulls && i > null_rules[j]; ++j) + continue; + + if (j == nnulls) + { + ++nnulls; + null_rules[j] = i; + } + else if (i != null_rules[j]) + { + ++nnulls; + for (k = nnulls - 1; k > j; --k) + null_rules[k] = null_rules[k-1]; + null_rules[j] = i; + } + } + } + } + + for (i = 0; i < nnulls; ++i) + { + j = null_rules[i]; + fprintf(verbose_file, "\t%s : . (%d)\n", symbol_name[rlhs[j]], + j - 2); + } + fprintf(verbose_file, "\n"); +} + + +void print_actions(int stateno) +{ + register action *p; + register shifts *sp; + register int as; + + if (stateno == final_state) + fprintf(verbose_file, "\t$end accept\n"); + + p = parser[stateno]; + if (p) + { + print_shifts(p); + print_reductions(p, defred[stateno]); + } + + sp = shift_table[stateno]; + if (sp && sp->nshifts > 0) + { + as = accessing_symbol[sp->shift[sp->nshifts - 1]]; + if (ISVAR(as)) + print_gotos(stateno); + } +} + + +void print_shifts(register action *p) +{ + register int count; + register action *q; + + count = 0; + for (q = p; q; q = q->next) + { + if (q->suppressed < 2 && q->action_code == SHIFT) + ++count; + } + + if (count > 0) + { + for (; p; p = p->next) + { + if (p->action_code == SHIFT && p->suppressed == 0) + fprintf(verbose_file, "\t%s shift %d\n", + symbol_name[p->symbol], p->number); + } + } +} + + +void print_reductions(register action *p, register int defred) +{ + register int k, anyreds; + register action *q; + + anyreds = 0; + for (q = p; q ; q = q->next) + { + if (q->action_code == REDUCE && q->suppressed < 2) + { + anyreds = 1; + break; + } + } + + if (anyreds == 0) + fprintf(verbose_file, "\t. error\n"); + else + { + for (; p; p = p->next) + { + if (p->action_code == REDUCE && p->number != defred) + { + k = p->number - 2; + if (p->suppressed == 0) + fprintf(verbose_file, "\t%s reduce %d\n", + symbol_name[p->symbol], k); + } + } + + if (defred > 0) + fprintf(verbose_file, "\t. reduce %d\n", defred - 2); + } +} + + +void print_gotos(int stateno) +{ + register int i, k; + register int as; + register short *to_state; + register shifts *sp; + + putc('\n', verbose_file); + sp = shift_table[stateno]; + to_state = sp->shift; + for (i = 0; i < sp->nshifts; ++i) + { + k = to_state[i]; + as = accessing_symbol[k]; + if (ISVAR(as)) + fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k); + } +} + diff --git a/yacc/warshall.c b/yacc/warshall.c new file mode 100644 index 0000000..f0714df --- /dev/null +++ b/yacc/warshall.c @@ -0,0 +1,96 @@ +/***********************************************************************/ +/* */ +/* Objective Caml */ +/* */ +/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ +/* */ +/* Copyright 1996 Institut National de Recherche en Informatique et */ +/* en Automatique. All rights reserved. This file is distributed */ +/* under the terms of the Q Public License version 1.0. */ +/* */ +/***********************************************************************/ + +/* Based on public-domain code from Berkeley Yacc */ + +/* $Id: warshall.c,v 1.8 2001-07-12 12:54:23 doligez Exp $ */ + +#include "defs.h" + +void transitive_closure(unsigned int *R, int n) +{ + register int rowsize; + register unsigned mask; + register unsigned *rowj; + register unsigned *rp; + register unsigned *rend; + register unsigned *ccol; + register unsigned *relend; + register unsigned *cword; + register unsigned *rowi; + + rowsize = WORDSIZE(n); + relend = R + n*rowsize; + + cword = R; + mask = 1; + rowi = R; + while (rowi < relend) + { + ccol = cword; + rowj = R; + + while (rowj < relend) + { + if (*ccol & mask) + { + rp = rowi; + rend = rowj + rowsize; + while (rowj < rend) + *rowj++ |= *rp++; + } + else + { + rowj += rowsize; + } + + ccol += rowsize; + } + + mask <<= 1; + if (mask == 0) + { + mask = 1; + cword++; + } + + rowi += rowsize; + } +} + +void reflexive_transitive_closure(unsigned int *R, int n) +{ + register int rowsize; + register unsigned mask; + register unsigned *rp; + register unsigned *relend; + + transitive_closure(R, n); + + rowsize = WORDSIZE(n); + relend = R + n*rowsize; + + mask = 1; + rp = R; + while (rp < relend) + { + *rp |= mask; + mask <<= 1; + if (mask == 0) + { + mask = 1; + rp++; + } + + rp += rowsize; + } +} -- 2.39.5